Lazily construct hitTest Region on demand.

This commit is contained in:
Mikael Sand
2018-02-23 00:49:14 +02:00
parent cd43fc151e
commit 14c3b4f867
2 changed files with 9 additions and 15 deletions
@@ -208,19 +208,6 @@ abstract public class RenderableShadowNode extends VirtualNode {
if (mPath == null) {
mPath = getPath(canvas, paint);
mPath.setFillType(mFillRule);
mBox = new RectF();
mPath.computeBounds(mBox, true);
mRegion = new Region();
mRegion.setPath(mPath,
new Region(
(int) Math.floor(mBox.left),
(int) Math.floor(mBox.top),
(int) Math.ceil(mBox.right),
(int) Math.ceil(mBox.bottom)
)
);
}
clip(canvas, paint);
@@ -292,6 +279,10 @@ abstract public class RenderableShadowNode extends VirtualNode {
} else if (colorType == 1) {
Brush brush = getSvgShadowNode().getDefinedBrush(colors.getString(1));
if (brush != null) {
if (mBox == null) {
mBox = new RectF();
mPath.computeBounds(mBox, true);
}
brush.setupPaint(paint, mBox, mScale, opacity);
}
}
@@ -311,6 +302,9 @@ abstract public class RenderableShadowNode extends VirtualNode {
int x = Math.round(dst[0]);
int y = Math.round(dst[1]);
if (mRegion == null) {
mRegion = getRegion(mPath);
}
if (!mRegion.contains(x, y)) {
return -1;
}
@@ -69,8 +69,8 @@ abstract class VirtualNode extends LayoutShadowNode {
Path mPath;
RectF mBox;
Region mRegion;
Path mClipRegionPath;
Region mClipRegion;
Path mClipRegionPath;
VirtualNode() {
setIsLayoutOnly(true);
@@ -90,9 +90,9 @@ abstract class VirtualNode extends LayoutShadowNode {
@Override
public void markUpdated() {
super.markUpdated();
mRegion = null;
mPath = null;
mBox = null;
mRegion = null;
}
@Nullable