Skip to content

Commit cc733f6

Browse files
committed
lazy buildPath.
1 parent 9c1d43c commit cc733f6

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

library/src/main/java/com/opensource/svgaplayer/SVGACanvasDrawer.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ class SVGACanvasDrawer(videoItem: SVGAVideoEntity, val dynamicItem: SVGADynamicE
181181
sharedContentTransform.preConcat(sprite.frameEntity.transform)
182182
sprite.frameEntity.shapes.forEach { shape ->
183183
sharedPath.reset()
184+
shape.buildPath()
184185
shape.shapePath?.let {
185186
sharedPath.addPath(it)
186187
}

library/src/main/java/com/opensource/svgaplayer/SVGAVideoShapeEntity.kt

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import java.util.HashMap
1616
* Created by cuiminghui on 2017/2/22.
1717
*/
1818

19+
val sharedPath = Path()
20+
1921
class SVGAVideoShapeEntity(obj: JSONObject) {
2022

2123
enum class Type {
@@ -67,7 +69,6 @@ class SVGAVideoShapeEntity(obj: JSONObject) {
6769
parseArgs(obj)
6870
parseStyles(obj)
6971
parseTransform(obj)
70-
buildPath()
7172
}
7273

7374
val isKeep: Boolean
@@ -155,10 +156,13 @@ class SVGAVideoShapeEntity(obj: JSONObject) {
155156
}
156157

157158
fun buildPath() {
158-
val aPath = Path()
159+
if (this.shapePath != null) {
160+
return
161+
}
162+
sharedPath.reset()
159163
if (this.type == SVGAVideoShapeEntity.Type.shape) {
160164
(this.args?.get("d") as? String)?.let {
161-
SVGAPath(it).buildPath(aPath)
165+
SVGAPath(it).buildPath(sharedPath)
162166
}
163167
}
164168
else if (this.type == SVGAVideoShapeEntity.Type.ellipse) {
@@ -170,7 +174,7 @@ class SVGAVideoShapeEntity(obj: JSONObject) {
170174
val y = yv.toFloat()
171175
val rx = rxv.toFloat()
172176
val ry = ryv.toFloat()
173-
aPath.addOval(RectF(x - rx, y - ry, x + rx, y + ry), Path.Direction.CW)
177+
sharedPath.addOval(RectF(x - rx, y - ry, x + rx, y + ry), Path.Direction.CW)
174178
}
175179
else if (this.type == SVGAVideoShapeEntity.Type.rect) {
176180
val xv = this.args?.get("x") as? Number ?: return
@@ -183,9 +187,10 @@ class SVGAVideoShapeEntity(obj: JSONObject) {
183187
val width = wv.toFloat()
184188
val height = hv.toFloat()
185189
val cornerRadius = crv.toFloat()
186-
aPath.addRoundRect(RectF(x, y, x + width, y + height), cornerRadius, cornerRadius, Path.Direction.CW)
190+
sharedPath.addRoundRect(RectF(x, y, x + width, y + height), cornerRadius, cornerRadius, Path.Direction.CW)
187191
}
188-
this.shapePath = aPath
192+
this.shapePath = Path()
193+
this.shapePath?.addPath(sharedPath)
189194
}
190195

191196
}

0 commit comments

Comments
 (0)