@@ -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 );
0 commit comments