@@ -10,7 +10,8 @@ import android.widget.ImageView
10
10
11
11
class SVGACanvasDrawer (videoItem : SVGAVideoEntity , val dynamicItem : SVGADynamicEntity ) : SGVADrawer(videoItem) {
12
12
13
- private val scaleEntity = ScaleEntity ()
13
+ private val canvasW = 0
14
+ private val canvasH = 0
14
15
private val sharedPaint = Paint ()
15
16
private val sharedPath = Path ()
16
17
private val sharedPath2 = Path ()
@@ -19,46 +20,41 @@ class SVGACanvasDrawer(videoItem: SVGAVideoEntity, val dynamicItem: SVGADynamicE
19
20
20
21
override fun drawFrame (canvas : Canvas , frameIndex : Int , scaleType : ImageView .ScaleType ) {
21
22
super .drawFrame(canvas,frameIndex, scaleType)
22
- performScaleType(scaleType)
23
- resetCachePath()
23
+ resetCachePath(canvas)
24
24
25
25
val sprites = requestFrameSprites(frameIndex)
26
26
sprites.forEach {
27
- drawSprite(it)
27
+ drawSprite(it,canvas )
28
28
}
29
29
}
30
30
31
- private fun resetCachePath (){
32
- if (canvasSizeChange ){
31
+ private fun resetCachePath (canvas : Canvas ){
32
+ if (canvasW != canvas.width || canvasH != canvas.height ){
33
33
sharedPathMap.clear()
34
34
}
35
35
}
36
36
37
- private fun enableScaleEntity ( ){
37
+ private fun resetShareMatrix ( transform : Matrix ){
38
38
sharedContentTransform.reset()
39
39
sharedContentTransform.postScale(scaleEntity.scaleFx, scaleEntity.scaleFy)
40
40
sharedContentTransform.postTranslate(scaleEntity.tranFx, scaleEntity.tranFy)
41
+ sharedContentTransform.preConcat(transform)
41
42
}
42
43
43
- private fun performScaleType ( scaleType : ImageView . ScaleType ) {
44
- val canvas = this .canvas ? : return
45
- scaleEntity.performScaleType(canvas.width.toFloat(), canvas.height.toFloat(),videoItem.videoSize.width.toFloat(),videoItem.videoSize.height.toFloat(),scaleType )
44
+ private fun drawSprite ( sprite : SVGADrawerSprite , canvas : Canvas ) {
45
+ drawImage(sprite, canvas)
46
+ drawShape(sprite, canvas)
46
47
}
47
48
48
- private fun drawSprite (sprite : SVGADrawerSprite ) {
49
- drawImage(sprite)
50
- drawShape(sprite)
51
- }
52
-
53
- private fun drawImage (sprite : SVGADrawerSprite ) {
54
- val canvas = this .canvas ? : return
49
+ private fun drawImage (sprite : SVGADrawerSprite , canvas : Canvas ) {
55
50
(dynamicItem.dynamicImage[sprite.imageKey] ? : videoItem.images[sprite.imageKey])?.let {
51
+ resetShareMatrix(sprite.frameEntity.transform)
52
+
56
53
sharedPaint.reset()
57
54
sharedPaint.isAntiAlias = videoItem.antiAlias
58
55
sharedPaint.isFilterBitmap = videoItem.antiAlias
59
56
sharedPaint.alpha = (sprite.frameEntity.alpha * 255 ).toInt()
60
- enableScaleEntity()
61
- sharedContentTransform.preConcat(sprite.frameEntity.transform)
57
+
62
58
if (sprite.frameEntity.maskPath != null ) {
63
59
val maskPath = sprite.frameEntity.maskPath ? : return @let
64
60
canvas.save()
@@ -74,12 +70,11 @@ class SVGACanvasDrawer(videoItem: SVGAVideoEntity, val dynamicItem: SVGADynamicE
74
70
sharedContentTransform.preScale((sprite.frameEntity.layout.width / it.width).toFloat(), (sprite.frameEntity.layout.width / it.width).toFloat())
75
71
canvas.drawBitmap(it, sharedContentTransform, sharedPaint)
76
72
}
77
- drawText(it, sprite)
73
+ drawText(canvas, it, sprite)
78
74
}
79
75
}
80
76
81
- private fun drawText (drawingBitmap : Bitmap , sprite : SVGADrawerSprite ) {
82
- val canvas = this .canvas ? : return
77
+ private fun drawText (canvas : Canvas , drawingBitmap : Bitmap , sprite : SVGADrawerSprite ) {
83
78
dynamicItem.dynamicText[sprite.imageKey]?.let { drawingText ->
84
79
dynamicItem.dynamicTextPaint[sprite.imageKey]?.let { drawingTextPaint ->
85
80
val textBitmap = Bitmap .createBitmap(drawingBitmap.width, drawingBitmap.height, Bitmap .Config .ARGB_8888 )
@@ -115,11 +110,8 @@ class SVGACanvasDrawer(videoItem: SVGAVideoEntity, val dynamicItem: SVGADynamicE
115
110
}
116
111
}
117
112
118
- private fun drawShape (sprite : SVGADrawerSprite ) {
119
- val canvas = this .canvas ? : return
120
- enableScaleEntity()
121
- sharedContentTransform.preConcat(sprite.frameEntity.transform)
122
-
113
+ private fun drawShape (sprite : SVGADrawerSprite , canvas : Canvas ) {
114
+ resetShareMatrix(sprite.frameEntity.transform)
123
115
sprite.frameEntity.shapes.forEach { shape ->
124
116
shape.buildPath()
125
117
shape.shapePath?.let {
0 commit comments