Do less work in Nodes when clipping isn't needed
Summary: By default, Nodes causes views to not be clipped, unless overflow is explicitly set to hidden. Consequently, Nodes sets all the clipping bounds to negative infinity, and does some extra work (saving the canvas layer, clipping, etc) before drawing. This optimization skips the extra work when it's not needed. Reviewed By: sriramramani Differential Revision: D3161268
This commit is contained in:
parent
5d6e73d0eb
commit
cbf195e165
|
@ -13,6 +13,7 @@ import android.graphics.Canvas;
|
|||
|
||||
/* package */ abstract class AbstractClippingDrawCommand implements DrawCommand {
|
||||
|
||||
protected boolean mNeedsClipping;
|
||||
private float mClipLeft;
|
||||
private float mClipTop;
|
||||
private float mClipRight;
|
||||
|
@ -36,6 +37,7 @@ import android.graphics.Canvas;
|
|||
mClipTop = clipTop;
|
||||
mClipRight = clipRight;
|
||||
mClipBottom = clipBottom;
|
||||
mNeedsClipping = mClipLeft != Float.NEGATIVE_INFINITY;
|
||||
}
|
||||
|
||||
public final float getClipLeft() {
|
||||
|
@ -60,7 +62,7 @@ import android.graphics.Canvas;
|
|||
// shows up during screenshot testing. Note that checking one side is enough, since if one side
|
||||
// is infinite, all sides will be infinite, since we only set infinite for all sides at the
|
||||
// same time - conversely, if one side is finite, all sides will be finite.
|
||||
if (mClipLeft != Float.NEGATIVE_INFINITY) {
|
||||
if (mNeedsClipping) {
|
||||
canvas.clipRect(mClipLeft, mClipTop, mClipRight, mClipBottom);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,9 +21,13 @@ import android.graphics.Canvas;
|
|||
|
||||
@Override
|
||||
public void draw(FlatViewGroup parent, Canvas canvas) {
|
||||
canvas.save();
|
||||
applyClipping(canvas);
|
||||
parent.drawNextChild(canvas);
|
||||
canvas.restore();
|
||||
if (mNeedsClipping) {
|
||||
canvas.save();
|
||||
applyClipping(canvas);
|
||||
parent.drawNextChild(canvas);
|
||||
canvas.restore();
|
||||
} else {
|
||||
parent.drawNextChild(canvas);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue