Skip to content

Commit 89a984e

Browse files
authored
Merge pull request #109 from ChillingVan/dev
Update the example for new AGP and libraries Update the library to 1.5.3
2 parents dc1829e + adc0918 commit 89a984e

File tree

83 files changed

+561
-654
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+561
-654
lines changed

README-en.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ allprojects {
4343
4444
// module build.gradle
4545
dependencies {
46-
implementation 'com.github.ChillingVan:android-openGL-canvas:v1.5.2.0'
46+
implementation 'com.github.ChillingVan:android-openGL-canvas:v1.5.3.0'
4747
}
4848
```
4949

@@ -127,6 +127,7 @@ It has sync and async modes.
127127

128128
You can use canvasGL.invalidateTextureContent(bitmap) to rebind the bitmap to texture.
129129
This is kind of heavy so I do not update call this for every drawn.
130+
* The CanvasGL doesn't support drawPath or drawText. You can try IAndroidCanvasHelper but this just uses Android canvas to generate a Bitmap. So heed the performance.
130131

131132
## Latest Update
132133
* Add record screen demo

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131

3232
## 使用要求
33-
* Android API 14 以上(OpenGL ES 2.0 以上)
33+
* Android API 14 以上(OpenGL ES 2.0 以上)。 建议21以上
3434

3535
## 用法
3636

@@ -48,7 +48,7 @@ allprojects {
4848
4949
// module build.gradle
5050
dependencies {
51-
implementation 'com.github.ChillingVan:android-openGL-canvas:v1.5.2.0'
51+
implementation 'com.github.ChillingVan:android-openGL-canvas:v1.5.3.0'
5252
}
5353
```
5454

@@ -126,10 +126,11 @@ public class MyGLView extends GLView {
126126

127127
## 注意事项和常见问题
128128
* 每一个View的onGLDraw都运行在自己的线程而非主线程。
129-
* 目前的Filter没有GPUImage里那么多,后续会陆续增加,如果有需要,参照我的代码自己实现即可,难度不高。
129+
* 目前的Filter没有GPUImage里那么多,如果有需要,参照我的代码自己实现即可,难度不高。
130130
* 为什么Bitmap修改后,再次绘制时并没更新?
131131

132132
因为没有调用canvasGL的invalidateTextureContent(bitmap)。改变了的Bitmap需要重新绑定texture。因为绑定需要耗时,所以库里面才不做成每次都重新绑定。
133+
* CanvasGL里面没有drawPath或者drawText,要实现的话本库提供了IAndroidCanvasHelper,但这个只是用安卓自己的canvas生成一个Bitmap,所以要注意性能
133134

134135
## 相关博客文章
135136
* [OpenGL绘制一张图片的流程](http://www.jianshu.com/p/40521c92ef85)

build.gradle

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,23 @@
2121
// Top-level build file where you can add configuration options common to all sub-projects/modules.
2222

2323
buildscript {
24+
ext.kotlin_version = '1.6.21'
2425
repositories {
25-
maven{url"https://maven.google.com"}
26-
jcenter()
2726
google()
27+
mavenCentral()
2828
}
2929
dependencies {
30-
classpath 'com.android.tools.build:gradle:3.4.0'
31-
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
30+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
31+
classpath 'com.android.tools.build:gradle:4.2.2'
3232
// NOTE: Do not place your application dependencies here; they belong
3333
// in the individual module build.gradle files
3434
}
3535
}
3636

3737
allprojects {
3838
repositories {
39-
maven{url"https://maven.google.com"}
40-
jcenter()
4139
google()
40+
mavenCentral()
4241
}
4342
}
4443

canvasgl/build.gradle

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,20 @@
1919
*/
2020

2121
apply plugin: 'com.android.library'
22-
apply plugin: 'com.github.dcendents.android-maven'
23-
group='com.github.ChillingVan'
24-
def VERSION_NAME="1.5.2.0"
22+
apply plugin: 'maven-publish'
23+
def NAMESPACE="com.github.ChillingVan"
24+
group = NAMESPACE
25+
def VERSION_NAME="1.5.3.0"
2526

2627
android {
27-
compileSdkVersion 28
28-
buildToolsVersion "28.0.3"
28+
namespace = NAMESPACE
29+
compileSdkVersion 32
2930
defaultConfig {
3031
minSdkVersion 14
31-
targetSdkVersion 28
32-
versionCode 105020
32+
targetSdkVersion 32
33+
versionCode 105030
3334
versionName VERSION_NAME
34-
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
35+
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
3536
}
3637
buildTypes {
3738
release {
@@ -46,13 +47,17 @@ android {
4647
// but continue the build even when errors are found:
4748
abortOnError false
4849
}
50+
compileOptions {
51+
sourceCompatibility JavaVersion.VERSION_1_8
52+
targetCompatibility JavaVersion.VERSION_1_8
53+
}
4954

5055
}
5156

5257
dependencies {
5358
implementation fileTree(include: ['*.jar'], dir: 'libs')
5459
testImplementation 'junit:junit:4.12'
55-
implementation 'com.android.support:support-annotations:28.0.0'
60+
implementation 'androidx.annotation:annotation:1.3.0'
5661
}
5762

5863

@@ -81,14 +86,18 @@ artifacts {
8186
archives javadocJar
8287
}
8388

84-
/**
85-
* Used to support other project uses mavenLocal() to refer this project which is convenient to debug
86-
*/
87-
install {
88-
repositories.mavenInstaller {
89-
pom.version = 'v' + VERSION_NAME
90-
pom.artifactId = 'android-openGL-canvas'
89+
90+
afterEvaluate {
91+
publishing {
92+
publications {
93+
// Creates a Maven publication called "release".
94+
release(MavenPublication) {
95+
from components.release
96+
groupId = NAMESPACE
97+
artifactId = 'android-openGL-canvas'
98+
version = VERSION_NAME
99+
}
100+
}
91101
}
92102
}
93103

94-

canvasgl/src/main/java/com/chillingvan/canvasgl/CanvasGL.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@
2828
import android.graphics.SurfaceTexture;
2929
import android.opengl.GLES20;
3030
import android.os.Build;
31-
import android.support.annotation.IntRange;
32-
import android.support.annotation.NonNull;
33-
import android.support.annotation.Nullable;
3431

3532
import com.chillingvan.canvasgl.glcanvas.BasicTexture;
3633
import com.chillingvan.canvasgl.glcanvas.BitmapTexture;
@@ -50,6 +47,10 @@
5047
import java.util.Map;
5148
import java.util.WeakHashMap;
5249

50+
import androidx.annotation.IntRange;
51+
import androidx.annotation.NonNull;
52+
import androidx.annotation.Nullable;
53+
5354
/**
5455
* All the depth of textures are the same. So the texture drawn after will cover the texture drawn before.
5556
*/

canvasgl/src/main/java/com/chillingvan/canvasgl/ICanvasGL.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
import android.graphics.SurfaceTexture;
2727
import android.opengl.GLES20;
2828
import android.opengl.Matrix;
29-
import android.support.annotation.IntRange;
30-
import android.support.annotation.NonNull;
31-
import android.support.annotation.Nullable;
29+
import androidx.annotation.IntRange;
30+
import androidx.annotation.NonNull;
31+
import androidx.annotation.Nullable;
3232

3333
import com.chillingvan.canvasgl.glcanvas.BasicTexture;
3434
import com.chillingvan.canvasgl.glcanvas.BitmapTexture;

canvasgl/src/main/java/com/chillingvan/canvasgl/OffScreenCanvas.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
package com.chillingvan.canvasgl;
2222

2323
import android.graphics.SurfaceTexture;
24-
import android.support.annotation.Nullable;
2524

2625
import com.chillingvan.canvasgl.glcanvas.BasicTexture;
2726
import com.chillingvan.canvasgl.glcanvas.RawTexture;
@@ -32,6 +31,8 @@
3231

3332
import java.util.List;
3433

34+
import androidx.annotation.Nullable;
35+
3536
/**
3637
* @deprecated use {@link MultiTexOffScreenCanvas} instead
3738
*/

canvasgl/src/main/java/com/chillingvan/canvasgl/glcanvas/BasicTexture.java

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,11 @@ public abstract class BasicTexture implements Texture {
5555
private boolean isRecycled;
5656

5757
protected GLCanvas mCanvasRef = null;
58-
private static WeakHashMap<BasicTexture, Object> sAllTextures
58+
private static final WeakHashMap<BasicTexture, Object> sAllTextures
5959
= new WeakHashMap<BasicTexture, Object>();
60-
private static ThreadLocal sInFinalizer = new ThreadLocal();
60+
private static final ThreadLocal sInFinalizer = new ThreadLocal();
61+
private boolean mIsFlippedVertically;
62+
private boolean mIsFlippedHorizontally;
6163

6264
protected BasicTexture(GLCanvas canvas, int id, int state) {
6365
setAssociatedCanvas(canvas);
@@ -91,10 +93,6 @@ public void setSize(int width, int height) {
9193
}
9294
}
9395

94-
public boolean isFlippedVertically() {
95-
return false;
96-
}
97-
9896
public int getId() {
9997
return mId;
10098
}
@@ -148,6 +146,29 @@ public void draw(GLCanvas canvas, int x, int y, int w, int h) {
148146
canvas.drawTexture(this, x, y, w, h, new BasicTextureFilter(), null);
149147
}
150148

149+
public boolean isFlippedVertically() {
150+
return mIsFlippedVertically;
151+
}
152+
public boolean isFlippedHorizontally() {
153+
return mIsFlippedHorizontally;
154+
}
155+
156+
/**
157+
*
158+
* @param isFlipped whether vertically flip this texture
159+
*/
160+
public void setIsFlippedVertically(boolean isFlipped) {
161+
mIsFlippedVertically = isFlipped;
162+
}
163+
164+
/**
165+
*
166+
* @param isFlipped whether horizontally flip this texture
167+
*/
168+
public void setIsFlippedHorizontally(boolean isFlipped) {
169+
mIsFlippedHorizontally = isFlipped;
170+
}
171+
151172
// onBind is called before GLCanvas binds this secondBitmap.
152173
// It should make sure the data is uploaded to GL memory.
153174
abstract protected boolean onBind(GLCanvas canvas);

canvasgl/src/main/java/com/chillingvan/canvasgl/glcanvas/GLCanvas.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import android.graphics.Bitmap;
2424
import android.graphics.Rect;
2525
import android.graphics.RectF;
26-
import android.support.annotation.Nullable;
26+
import androidx.annotation.Nullable;
2727

2828
import com.chillingvan.canvasgl.shapeFilter.DrawShapeFilter;
2929
import com.chillingvan.canvasgl.textureFilter.TextureFilter;

canvasgl/src/main/java/com/chillingvan/canvasgl/glcanvas/GLES20Canvas.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ public void restore() {
460460
@Override
461461
public void drawCircle(float x, float y, float radius, GLPaint paint, DrawShapeFilter drawShapeFilter) {
462462
setupDrawShapeFilter(drawShapeFilter);
463-
draw(GLES20.GL_TRIANGLE_STRIP, OFFSET_FILL_RECT, COUNT_FILL_VERTEX, x, y, 2*radius, 2*radius, paint.getColor(), 0f);
463+
draw(GLES20.GL_TRIANGLE_STRIP, OFFSET_FILL_RECT, COUNT_FILL_VERTEX, x, y, 2 * radius, 2 * radius, paint.getColor(), 0f);
464464
}
465465

466466
@Override
@@ -639,15 +639,22 @@ private void drawTextureRect(BasicTexture texture, float[] textureMatrix, RectF
639639
onPreDrawTextureListener.onPreDraw(texture.getTarget() == GLES20.GL_TEXTURE_2D ? mTextureProgram : mOesTextureProgram, texture, mTextureFilter);
640640
}
641641
checkError();
642-
if (texture.isFlippedVertically()) {
642+
if (texture.isFlippedVertically() || texture.isFlippedHorizontally()) {
643643
save(SAVE_FLAG_MATRIX);
644+
}
645+
if (texture.isFlippedVertically()) {
644646
translate(0, target.centerY());
645647
scale(1, -1, 1);
646648
translate(0, -target.centerY());
647649
}
650+
if (texture.isFlippedHorizontally()) {
651+
translate(target.centerX(), 0);
652+
scale(-1, 1, 1);
653+
translate(-target.centerX(), 0);
654+
}
648655
draw(params, GLES20.GL_TRIANGLE_STRIP, COUNT_FILL_VERTEX, target.left, target.top,
649656
target.width(), target.height(), customMVPMatrix);
650-
if (texture.isFlippedVertically()) {
657+
if (texture.isFlippedVertically() || texture.isFlippedHorizontally()) {
651658
restore();
652659
}
653660
mCountTextureRect++;
@@ -995,12 +1002,12 @@ public static void printMatrix(String message, float[] m, int offset) {
9951002
String format = "%.6f";
9961003
b.append(String.format(format, m[offset + i]));
9971004
b.append(", ");
998-
b.append(String.format(format, m[offset + 4+i]));
1005+
b.append(String.format(format, m[offset + 4 + i]));
9991006
b.append(", ");
1000-
b.append(String.format(format, m[offset + 8+i]));
1007+
b.append(String.format(format, m[offset + 8 + i]));
10011008
b.append(", ");
1002-
b.append(String.format(format, m[offset + 12+i]));
1003-
if (i<size-1) {
1009+
b.append(String.format(format, m[offset + 12 + i]));
1010+
if (i < size - 1) {
10041011
b.append(", ");
10051012
}
10061013
b.append('\n');

0 commit comments

Comments
 (0)