@@ -51,13 +51,9 @@ internal class SVGACanvasDrawer(videoItem: SVGAVideoEntity, val dynamicItem: SVG
5151 isMatteing = false
5252
5353 matteSprites.get(svgaDrawerSprite.matteKey)?.let {
54- val matteBitmap = Bitmap .createBitmap(canvas.width, canvas.height, Bitmap .Config .ARGB_8888 )
55- val matteCanvas = Canvas (matteBitmap)
56- val paint = Paint ()
57- paint.setXfermode(PorterDuffXfermode (PorterDuff .Mode .DST_IN ))
54+ drawSprite(it, this .sharedValues.shareMatteCanvas(canvas.width, canvas.height), frameIndex)
5855
59- drawSprite(it, matteCanvas, frameIndex)
60- canvas.drawBitmap(matteBitmap, 0f , 0f , paint)
56+ canvas.drawBitmap(this .sharedValues.sharedMatteBitmap(), 0f , 0f , this .sharedValues.shareMattePaint())
6157 canvas.restore()
6258 }
6359 }
@@ -72,13 +68,9 @@ internal class SVGACanvasDrawer(videoItem: SVGAVideoEntity, val dynamicItem: SVG
7268 // if current sprite is the last one and isMatteing
7369 if (isMatteing && index == sprites.count() - 1 ) {
7470 matteSprites.get(svgaDrawerSprite.matteKey)?.let {
75- val matteBitmap = Bitmap .createBitmap(canvas.width, canvas.height, Bitmap .Config .ARGB_8888 )
76- val matteCanvas = Canvas (matteBitmap)
77- val paint = Paint ()
78- paint.setXfermode(PorterDuffXfermode (PorterDuff .Mode .DST_IN ))
71+ drawSprite(it, this .sharedValues.shareMatteCanvas(canvas.width, canvas.height), frameIndex)
7972
80- drawSprite(it, matteCanvas, frameIndex)
81- canvas.drawBitmap(matteBitmap, 0f , 0f , paint)
73+ canvas.drawBitmap(this .sharedValues.sharedMatteBitmap(), 0f , 0f , this .sharedValues.shareMattePaint())
8274 canvas.restore()
8375 }
8476 }
@@ -344,6 +336,10 @@ internal class SVGACanvasDrawer(videoItem: SVGAVideoEntity, val dynamicItem: SVG
344336 private val sharedMatrix = Matrix ()
345337 private val sharedMatrix2 = Matrix ()
346338
339+ private val shareMattePaint = Paint ()
340+ private var shareMatteCanvas: Canvas ? = null
341+ private var sharedMatteBitmap: Bitmap ? = null
342+
347343 fun sharedPaint (): Paint {
348344 sharedPaint.reset()
349345 return sharedPaint
@@ -369,6 +365,24 @@ internal class SVGACanvasDrawer(videoItem: SVGAVideoEntity, val dynamicItem: SVG
369365 return sharedMatrix2
370366 }
371367
368+ fun shareMattePaint (): Paint {
369+ shareMattePaint.setXfermode(PorterDuffXfermode (PorterDuff .Mode .DST_IN ))
370+ return shareMattePaint
371+ }
372+
373+ fun sharedMatteBitmap (): Bitmap {
374+ return sharedMatteBitmap as Bitmap
375+ }
376+
377+ fun shareMatteCanvas (width : Int , height : Int ): Canvas {
378+ if (shareMatteCanvas == null ) {
379+ sharedMatteBitmap = Bitmap .createBitmap(width, height, Bitmap .Config .ALPHA_8 )
380+ shareMatteCanvas = Canvas (sharedMatteBitmap)
381+ }
382+ val matteCanvas = shareMatteCanvas as Canvas
383+ matteCanvas.drawColor(Color .TRANSPARENT , PorterDuff .Mode .CLEAR );
384+ return matteCanvas
385+ }
372386 }
373387
374388 class PathCache {
0 commit comments