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:
Ahmed El-Helw 2016-04-11 12:50:35 -07:00
Родитель 5d6e73d0eb
Коммит cbf195e165
2 изменённых файлов: 11 добавлений и 5 удалений

Просмотреть файл

@ -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);
}
}
}