Improve path caching on android

This commit is contained in:
Mikael Sand
2018-02-22 02:24:11 +02:00
parent aed804776a
commit 149f460108
3 changed files with 19 additions and 8 deletions
@@ -67,8 +67,6 @@ abstract public class RenderableShadowNode extends VirtualNode {
public float mFillOpacity = 1; public float mFillOpacity = 1;
public Path.FillType mFillRule = Path.FillType.WINDING; public Path.FillType mFillRule = Path.FillType.WINDING;
protected Path mPath;
private @Nullable ReadableArray mLastMergedList; private @Nullable ReadableArray mLastMergedList;
private @Nullable ArrayList<Object> mOriginProperties; private @Nullable ArrayList<Object> mOriginProperties;
protected @Nullable ReadableArray mPropList; protected @Nullable ReadableArray mPropList;
@@ -204,10 +202,13 @@ abstract public class RenderableShadowNode extends VirtualNode {
opacity *= mOpacity; opacity *= mOpacity;
if (opacity > MIN_OPACITY_FOR_DRAW) { if (opacity > MIN_OPACITY_FOR_DRAW) {
mPath = getPath(canvas, paint); if (mPath == null) {
mPath.setFillType(mFillRule); mPath = getPath(canvas, paint);
mPath.setFillType(mFillRule);
}
clip(canvas, paint); clip(canvas, paint);
if (setupFillPaint(paint, opacity * mFillOpacity)) { if (setupFillPaint(paint, opacity * mFillOpacity)) {
canvas.drawPath(mPath, paint); canvas.drawPath(mPath, paint);
} }
@@ -106,13 +106,14 @@ public class SvgView extends ViewGroup {
@Override @Override
protected void onLayout(boolean changed, int l, int t, int r, int b) { protected void onLayout(boolean changed, int l, int t, int r, int b) {
ReactShadowNodeImpl node = getShadowNode();
for (int i = 0; i < this.getChildCount(); i++) { for (int i = 0; i < this.getChildCount(); i++) {
View child = this.getChildAt(i); View child = this.getChildAt(i);
if (child instanceof ReactViewGroup) { if (child instanceof ReactViewGroup) {
ReactShadowNodeImpl node = getShadowNode(); int id = child.getId();
for (int j = 0; j < node.getChildCount(); j++) { for (int j = 0; j < node.getChildCount(); j++) {
ReactShadowNodeImpl nodeChild = node.getChildAt(j); ReactShadowNodeImpl nodeChild = node.getChildAt(j);
if (nodeChild.getReactTag() != child.getId()) { if (nodeChild.getReactTag() != id) {
continue; continue;
} }
@@ -63,6 +63,8 @@ abstract class VirtualNode extends LayoutShadowNode {
private float canvasWidth = -1; private float canvasWidth = -1;
private GlyphContext glyphContext; private GlyphContext glyphContext;
Path mPath;
VirtualNode() { VirtualNode() {
setIsLayoutOnly(true); setIsLayoutOnly(true);
mScale = DisplayMetricsHolder.getScreenDisplayMetrics().density; mScale = DisplayMetricsHolder.getScreenDisplayMetrics().density;
@@ -78,6 +80,12 @@ abstract class VirtualNode extends LayoutShadowNode {
return true; return true;
} }
@Override
public void markUpdated() {
super.markUpdated();
mPath = null;
}
@Nullable @Nullable
GroupShadowNode getTextRoot() { GroupShadowNode getTextRoot() {
VirtualNode node = this; VirtualNode node = this;
@@ -161,6 +169,7 @@ abstract class VirtualNode extends LayoutShadowNode {
@ReactProp(name = "clipPath") @ReactProp(name = "clipPath")
public void setClipPath(String clipPath) { public void setClipPath(String clipPath) {
mCachedClipPath = null;
mClipPath = clipPath; mClipPath = clipPath;
markUpdated(); markUpdated();
} }
@@ -193,7 +202,7 @@ abstract class VirtualNode extends LayoutShadowNode {
mMatrix = null; mMatrix = null;
} }
markUpdated(); super.markUpdated();
} }
@ReactProp(name = "responsible") @ReactProp(name = "responsible")
@@ -207,7 +216,7 @@ abstract class VirtualNode extends LayoutShadowNode {
} }
@Nullable Path getClipPath(Canvas canvas, Paint paint) { @Nullable Path getClipPath(Canvas canvas, Paint paint) {
if (mClipPath != null) { if (mClipPath != null && mCachedClipPath == null) {
VirtualNode node = getSvgShadowNode().getDefinedClipPath(mClipPath); VirtualNode node = getSvgShadowNode().getDefinedClipPath(mClipPath);
if (node != null) { if (node != null) {