Skip to content

Commit 83d2cdd

Browse files
authored
Merge pull request #61 from ChillingVan/dev
Dev release to master for v1.4.2.0
2 parents 7be1cdc + 8a04229 commit 83d2cdd

31 files changed

+526
-52
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.4.1.3'
46+
implementation 'com.github.ChillingVan:android-openGL-canvas:v1.4.2.0'
4747
}
4848
```
4949

@@ -129,6 +129,7 @@ It has sync and async modes.
129129
This is kind of heavy so I do not update call this for every drawn.
130130

131131
## Latest Update
132+
* Fix FilterGroup on drawSurfaceTexture
132133
* Fix subtle crash issue
133134
* Add OrthoBitmapMatrix as One BitmapMatrix. Default BitmapMatrix uses perspective matrix.
134135
* Fix BitmapMatrix cut by small viewport issue when Bitmap out of screen.

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ allprojects {
4848
4949
// module build.gradle
5050
dependencies {
51-
implementation 'com.github.ChillingVan:android-openGL-canvas:v1.4.1.3'
51+
implementation 'com.github.ChillingVan:android-openGL-canvas:v1.4.2.0'
5252
}
5353
```
5454

@@ -139,6 +139,7 @@ public class MyGLView extends GLView {
139139

140140

141141
## 最近更新
142+
* 修复FilterGroup无法应用在SurfaceTexture上的问题
142143
* 修复潜在的IndexOutOfBound exception
143144
* 添加OrthoBitmapMatrix以支持正交投影。 默认BitmapMatrix用的是透视投影。
144145
* 修复BitmapMatrix被过小的viewport剪切的问题。支持更大的放大倍数及离屏距离。

canvasgl/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@
2121
apply plugin: 'com.android.library'
2222
apply plugin: 'com.github.dcendents.android-maven'
2323
group='com.github.ChillingVan'
24-
def VERSION_NAME="1.4.1.3"
24+
def VERSION_NAME="1.4.2.0"
2525

2626
android {
2727
compileSdkVersion 28
2828
buildToolsVersion "28.0.3"
2929
defaultConfig {
3030
minSdkVersion 14
3131
targetSdkVersion 28
32-
versionCode 104013
32+
versionCode 104020
3333
versionName VERSION_NAME
3434
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
3535
}
@@ -52,7 +52,7 @@ android {
5252
dependencies {
5353
implementation fileTree(include: ['*.jar'], dir: 'libs')
5454
testImplementation 'junit:junit:4.12'
55-
implementation 'com.android.support:support-annotations:27.0.2'
55+
implementation 'com.android.support:support-annotations:28.0.0'
5656
}
5757

5858

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

Lines changed: 58 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,14 @@ public class CanvasGL implements ICanvasGL {
5757

5858
private Map<Bitmap, BasicTexture> bitmapTextureMap = new WeakHashMap<>();
5959
protected final GLCanvas glCanvas;
60-
protected final BasicTextureFilter basicTextureFilter;
60+
protected final BasicTextureFilter defaultTextureFilter;
6161
private float[] canvasBackgroundColor;
6262
private float[] surfaceTextureMatrix = new float[16];
6363
private int width;
6464
private int height;
65-
private BasicDrawShapeFilter basicDrawShapeFilter;
65+
private BasicDrawShapeFilter defaultDrawShapeFilter;
6666
private DrawCircleFilter drawCircleFilter = new DrawCircleFilter();
67+
private TextureFilter currentTextureFilter;
6768

6869
public CanvasGL() {
6970
this(new GLES20Canvas());
@@ -83,8 +84,8 @@ public void onPreDraw(int textureProgram, BasicTexture texture, TextureFilter te
8384
textureFilter.onPreDraw(textureProgram, texture, CanvasGL.this);
8485
}
8586
});
86-
basicTextureFilter = new BasicTextureFilter();
87-
basicDrawShapeFilter = new BasicDrawShapeFilter();
87+
defaultTextureFilter = new BasicTextureFilter();
88+
defaultDrawShapeFilter = new BasicDrawShapeFilter();
8889
canvasBackgroundColor = new float[4];
8990
}
9091

@@ -116,11 +117,16 @@ public GLCanvas getGlCanvas() {
116117

117118
@Override
118119
public void drawSurfaceTexture(BasicTexture texture, SurfaceTexture surfaceTexture, int left, int top, int right, int bottom) {
119-
drawSurfaceTexture(texture, surfaceTexture, left, top, right, bottom, basicTextureFilter);
120+
drawSurfaceTexture(texture, surfaceTexture, left, top, right, bottom, defaultTextureFilter);
120121
}
121122

122123
@Override
123-
public void drawSurfaceTexture(BasicTexture texture, SurfaceTexture surfaceTexture, int left, int top, int right, int bottom, TextureFilter basicTextureFilter) {
124+
public void drawSurfaceTexture(BasicTexture texture, final SurfaceTexture surfaceTexture, int left, int top, int right, int bottom, TextureFilter basicTextureFilter) {
125+
currentTextureFilter = basicTextureFilter;
126+
if (basicTextureFilter instanceof FilterGroup) {
127+
drawSurfaceTextureWithFilterGroup(texture, surfaceTexture, left, top, right, bottom, basicTextureFilter);
128+
return;
129+
}
124130
if (surfaceTexture == null) {
125131
glCanvas.drawTexture(texture, left, top, right - left, bottom - top, basicTextureFilter, null);
126132
} else {
@@ -129,10 +135,26 @@ public void drawSurfaceTexture(BasicTexture texture, SurfaceTexture surfaceTextu
129135
}
130136
}
131137

138+
private void drawSurfaceTextureWithFilterGroup(BasicTexture texture, final SurfaceTexture surfaceTexture, int left, int top, int right, int bottom, TextureFilter basicTextureFilter) {
139+
FilterGroup filterGroup = (FilterGroup) basicTextureFilter;
140+
texture = filterGroup.draw(texture, glCanvas, new FilterGroup.OnDrawListener() {
141+
@Override
142+
public void onDraw(BasicTexture drawTexture, TextureFilter textureFilter, boolean isFirst) {
143+
if (isFirst) {
144+
surfaceTexture.getTransformMatrix(surfaceTextureMatrix);
145+
glCanvas.drawTexture(drawTexture, surfaceTextureMatrix, 0, 0, drawTexture.getWidth(), drawTexture.getHeight(), textureFilter, null);
146+
} else {
147+
glCanvas.drawTexture(drawTexture, 0, 0, drawTexture.getWidth(), drawTexture.getHeight(), textureFilter, null);
148+
}
149+
}
150+
});
151+
glCanvas.drawTexture(texture, left, top, right - left, bottom - top, basicTextureFilter, null);
152+
}
153+
132154

133155
@Override
134156
public void drawBitmap(Bitmap bitmap, @NonNull IBitmapMatrix matrix) {
135-
drawBitmap(bitmap, matrix, basicTextureFilter);
157+
drawBitmap(bitmap, matrix, defaultTextureFilter);
136158
}
137159

138160
@Override
@@ -150,12 +172,12 @@ public float[] getMVPMatrix(int viewportW, int viewportH, float x, float y, floa
150172

151173
@Override
152174
public void drawBitmap(Bitmap bitmap, Rect src, RectF dst) {
153-
drawBitmap(bitmap, new RectF(src), dst, basicTextureFilter);
175+
drawBitmap(bitmap, new RectF(src), dst, defaultTextureFilter);
154176
}
155177

156178
@Override
157179
public void drawBitmap(Bitmap bitmap, int left, int top) {
158-
drawBitmap(bitmap, left, top, basicTextureFilter);
180+
drawBitmap(bitmap, left, top, defaultTextureFilter);
159181
}
160182

161183
@Override
@@ -180,7 +202,7 @@ public void drawBitmap(Bitmap bitmap, RectF src, RectF dst, TextureFilter textur
180202

181203
@Override
182204
public void drawBitmap(Bitmap bitmap, int left, int top, int width, int height) {
183-
drawBitmap(bitmap, left, top, width, height, basicTextureFilter);
205+
drawBitmap(bitmap, left, top, width, height, defaultTextureFilter);
184206
}
185207

186208
@Override
@@ -190,19 +212,29 @@ public void drawBitmap(Bitmap bitmap, int left, int top, int width, int height,
190212
}
191213

192214
protected BasicTexture getTexture(Bitmap bitmap, @Nullable TextureFilter textureFilter) {
215+
currentTextureFilter = textureFilter;
193216
throwIfCannotDraw(bitmap);
194217

195218
BasicTexture resultTexture = getTextureFromMap(bitmap);
196219

197220
if (textureFilter instanceof FilterGroup) {
198221
FilterGroup filterGroup = (FilterGroup) textureFilter;
199-
resultTexture = filterGroup.draw(resultTexture, glCanvas);
222+
resultTexture = filterGroup.draw(resultTexture, glCanvas, new FilterGroup.OnDrawListener() {
223+
@Override
224+
public void onDraw(BasicTexture drawTexture, TextureFilter textureFilter, boolean isFirst) {
225+
glCanvas.drawTexture(drawTexture, 0, 0, drawTexture.getWidth(), drawTexture.getHeight(), textureFilter, null);
226+
}
227+
});
200228
}
201229

202230

203231
return resultTexture;
204232
}
205233

234+
/***
235+
* Use this to the bitmap to texture. Called when your bitmap content pixels changed
236+
* @param bitmap the bitmap whose content pixels changed
237+
*/
206238
@Override
207239
public void invalidateTextureContent(Bitmap bitmap) {
208240
BasicTexture resultTexture = getTextureFromMap(bitmap);
@@ -234,7 +266,7 @@ public void drawCircle(float x, float y, float radius, GLPaint paint) {
234266

235267
@Override
236268
public void drawLine(float startX, float startY, float stopX, float stopY, GLPaint paint) {
237-
glCanvas.drawLine(startX, startY, stopX, stopY, paint, basicDrawShapeFilter);
269+
glCanvas.drawLine(startX, startY, stopX, stopY, paint, defaultDrawShapeFilter);
238270
}
239271

240272

@@ -251,9 +283,9 @@ public void drawRect(@NonNull Rect r, GLPaint paint) {
251283
@Override
252284
public void drawRect(float left, float top, float right, float bottom, GLPaint paint) {
253285
if (paint.getStyle() == Paint.Style.STROKE) {
254-
glCanvas.drawRect(left, top, right - left, bottom - top, paint, basicDrawShapeFilter);
286+
glCanvas.drawRect(left, top, right - left, bottom - top, paint, defaultDrawShapeFilter);
255287
} else {
256-
glCanvas.fillRect(left, top, right - left, bottom - top, paint.getColor(), basicDrawShapeFilter);
288+
glCanvas.fillRect(left, top, right - left, bottom - top, paint.getColor(), defaultDrawShapeFilter);
257289
}
258290
}
259291

@@ -338,6 +370,18 @@ public int getHeight() {
338370
return height;
339371
}
340372

373+
@Override
374+
public void resume() {
375+
376+
}
377+
378+
@Override
379+
public void pause() {
380+
if (currentTextureFilter != null) {
381+
currentTextureFilter.destroy();
382+
}
383+
}
384+
341385
@Override
342386
public void setAlpha(@IntRange(from = 0, to = 255) int alpha) {
343387
glCanvas.setAlpha(alpha/(float)255);

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ public interface ICanvasGL {
117117

118118
int getHeight();
119119

120+
void resume();
121+
122+
void pause();
123+
120124
/**
121125
* If used in a texture view, make sure the setOpaque(false) is called.
122126
*

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ public void onDrawFrame() {
267267
if (producedTextureTarget != GLES20.GL_TEXTURE_2D) {
268268
for (GLTexture glTexture : producedTextureList) {
269269
glTexture.getSurfaceTexture().updateTexImage();
270+
glTexture.getRawTexture().setNeedInvalidate(true);
270271
}
271272
}
272273
onGLDraw(mCanvas, producedTextureList, consumedTextures);

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public class RawTexture extends BasicTexture {
3131
private final boolean mOpaque;
3232
private boolean mIsFlipped;
3333
private int target = GL11.GL_TEXTURE_2D;
34+
protected boolean needInvalidate;
3435

3536
public RawTexture(int width, int height, boolean opaque) {
3637
this(width, height, opaque, GL11.GL_TEXTURE_2D);
@@ -88,4 +89,15 @@ public void yield() {
8889
protected int getTarget() {
8990
return target;
9091
}
92+
93+
/**
94+
* Call this when surfaceTexture calls updateTexImage
95+
*/
96+
public void setNeedInvalidate(boolean needInvalidate) {
97+
this.needInvalidate = needInvalidate;
98+
}
99+
100+
public boolean isNeedInvalidate() {
101+
return needInvalidate;
102+
}
91103
}

canvasgl/src/main/java/com/chillingvan/canvasgl/glview/GLView.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ public void restart() {
103103

104104
public void stop() {
105105
onPause();
106+
if (mCanvas != null) {
107+
mCanvas.pause();
108+
}
106109
}
107110

108111
public void destroy() {

canvasgl/src/main/java/com/chillingvan/canvasgl/glview/texture/BaseGLCanvasTextureView.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99

1010
import com.chillingvan.canvasgl.CanvasGL;
1111
import com.chillingvan.canvasgl.ICanvasGL;
12-
import com.chillingvan.canvasgl.util.Loggers;
1312
import com.chillingvan.canvasgl.OpenGLUtil;
1413
import com.chillingvan.canvasgl.glview.GLView;
14+
import com.chillingvan.canvasgl.util.Loggers;
1515

1616
/**
1717
*
@@ -46,7 +46,7 @@ protected void init() {
4646

4747
@Override
4848
public void onSurfaceCreated() {
49-
Loggers.d("BaseGLCanvasTextureView", "onSurfaceCreated: ");
49+
Loggers.d(TAG, "onSurfaceCreated: ");
5050
mCanvas = new CanvasGL();
5151
}
5252

@@ -63,6 +63,14 @@ public void onDrawFrame() {
6363
onGLDraw(mCanvas);
6464
}
6565

66+
@Override
67+
public void onPause() {
68+
super.onPause();
69+
if (mCanvas != null) {
70+
mCanvas.pause();
71+
}
72+
}
73+
6674
protected abstract void onGLDraw(ICanvasGL canvas);
6775

6876

canvasgl/src/main/java/com/chillingvan/canvasgl/glview/texture/BaseGLTextureView.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public BaseGLTextureView(Context context, AttributeSet attrs, int defStyleAttr)
8080
// TODO: 2018/3/25 This may be duplicated. onSurfaceTextureSizeChanged is doing same thing.
8181
@Override
8282
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
83-
Loggers.d("BaseGLTextureView", "onSizeChanged: ");
83+
Loggers.d(TAG, "onSizeChanged: ");
8484
super.onSizeChanged(w, h, oldw, oldh);
8585
if (mGLThread != null) {
8686
mGLThread.onWindowResize(w, h);
@@ -153,7 +153,7 @@ protected void surfaceRedrawNeeded() {
153153

154154
@Override
155155
protected void onDetachedFromWindow() {
156-
Loggers.d("BaseGLTextureView", "onDetachedFromWindow: ");
156+
Loggers.d(TAG, "onDetachedFromWindow: ");
157157
if (mGLThread != null) {
158158
mGLThread.requestExitAndWait();
159159
}
@@ -208,7 +208,7 @@ public void setRenderer(GLViewRenderer renderer) {
208208

209209
@Override
210210
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
211-
Loggers.d("BaseGLTextureView", "onSurfaceTextureAvailable: ");
211+
Loggers.d(TAG, "onSurfaceTextureAvailable: ");
212212
surfaceAvailable = true;
213213
glThreadBuilder = new GLThread.Builder();
214214
if (mGLThread == null) {
@@ -229,7 +229,7 @@ public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int hei
229229
}
230230

231231
protected void createGLThread() {
232-
Loggers.d("BaseGLTextureView", "createGLThread: ");
232+
Loggers.d(TAG, "createGLThread: ");
233233
hasCreateGLThreadCalledOnce = true;
234234
if (!surfaceAvailable) {
235235
return;
@@ -267,7 +267,7 @@ private void freshSurface(int width, int height) {
267267

268268
@Override
269269
public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
270-
Loggers.d("BaseGLTextureView", "onSurfaceTextureSizeChanged: ");
270+
Loggers.d(TAG, "onSurfaceTextureSizeChanged: ");
271271
surfaceChanged(width, height);
272272
surfaceRedrawNeeded();
273273
if (surfaceTextureListener != null) {
@@ -280,7 +280,7 @@ public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int h
280280
*/
281281
@Override
282282
public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
283-
Loggers.d("BaseGLTextureView", "onSurfaceTextureDestroyed: ");
283+
Loggers.d(TAG, "onSurfaceTextureDestroyed: ");
284284
surfaceDestroyed();
285285
if (surfaceTextureListener != null) {
286286
surfaceTextureListener.onSurfaceTextureDestroyed(surface);

0 commit comments

Comments
 (0)