Extract rect clipping logic into AbstractClippingDrawCommand

Summary: Both DrawView and AbstractDrawCommand have clipping logic, this diff is moving out logic into a common base class. This also reverts the screenshot tests fix, which was causing issues with overflow: visible.

Reviewed By: ahmedre

Differential Revision: D2933780
This commit is contained in:
Denis Koroskin
2016-02-18 23:56:37 -08:00
committed by Ahmed El-Helw
parent f0535152ab
commit 3b63d7c3bc
3 changed files with 68 additions and 67 deletions

View File

@@ -10,44 +10,19 @@
package com.facebook.react.flat;
import android.graphics.Canvas;
import android.graphics.Rect;
/* package */ final class DrawView implements DrawCommand {
/* package */ final class DrawView extends AbstractClippingDrawCommand {
/* package */ static final DrawView INSTANCE = new DrawView(0, 0, 0, 0);
private static final Rect TMP_CLIP_RECT = new Rect();
private final float mClipLeft;
private final float mClipTop;
private final float mClipRight;
private final float mClipBottom;
public DrawView(float clipLeft, float clipTop, float clipRight, float clipBottom) {
mClipLeft = clipLeft;
mClipTop = clipTop;
mClipRight = clipRight;
mClipBottom = clipBottom;
}
public boolean clipBoundsMatch(float clipLeft, float clipTop, float clipRight, float clipBottom) {
return mClipLeft == clipLeft && mClipTop == clipTop
&& mClipRight == clipRight && mClipBottom == clipBottom;
setClipBounds(clipLeft, clipTop, clipRight, clipBottom);
}
@Override
public void draw(FlatViewGroup parent, Canvas canvas) {
// This should not be required, except that there is a bug in Canvas that only shows up in
// screenshot tests where Canvas incorrectly applies clip rect caused by integer overflows
// because software Canvas is actually using ints for bounds, not floats.
canvas.getClipBounds(TMP_CLIP_RECT);
TMP_CLIP_RECT.intersect(
Math.round(mClipLeft),
Math.round(mClipTop),
Math.round(mClipRight),
Math.round(mClipBottom));
canvas.save();
canvas.clipRect(TMP_CLIP_RECT);
applyClipping(canvas);
parent.drawNextChild(canvas);
canvas.restore();
}