Add directional clipping command manager.

Summary: Add directional aware clipping to DrawCommandManager.  Currently not attached to FlatViewGroup logic, with the plan to keep this unattached until we are clipping the way we want to in the final state.

Reviewed By: ahmedre

Differential Revision: D3622253
This commit is contained in:
Seth Kirby
2016-08-01 12:26:50 -07:00
committed by Ahmed El-Helw
parent f850e61fdb
commit e96f6fa585
10 changed files with 391 additions and 43 deletions

View File

@@ -36,6 +36,14 @@ import android.graphics.RectF;
// the path to clip against if we're doing path clipping for rounded borders.
@Nullable private Path mPath;
// These should only ever be set from within the DrawView, their only purpose is to prevent
// excessive rounding on the UI thread in FlatViewGroup, and they are left package protected to
// speed up direct access.
/* package */ int mLogicalLeft;
/* package */ int mLogicalTop;
/* package */ int mLogicalRight;
/* package */ int mLogicalBottom;
public DrawView(int reactTag) {
this.reactTag = reactTag;
}
@@ -52,6 +60,10 @@ import android.graphics.RectF;
float top,
float right,
float bottom,
int logicalLeft,
int logicalTop,
int logicalRight,
int logicalBottom,
float clipLeft,
float clipTop,
float clipRight,
@@ -68,7 +80,9 @@ import android.graphics.RectF;
clipRight,
clipBottom);
boolean clipRadiusChanged = Math.abs(mClipRadius - clipRadius) > 0.001f;
if (clipRadiusChanged && drawView == this) {
boolean logicalBoundsChanged =
!logicalBoundsMatch(logicalLeft, logicalTop, logicalRight, logicalBottom);
if (drawView == this && (clipRadiusChanged || logicalBoundsChanged)) {
// everything matches except the clip radius, so we clone the old one so that we can update
// the clip radius in the block below.
try {
@@ -88,6 +102,10 @@ import android.graphics.RectF;
drawView.mPath = null;
}
if (logicalBoundsChanged) {
drawView.setLogicalBounds(logicalLeft, logicalTop, logicalRight, logicalBottom);
}
// It is very important that we unset this, as our spec is that newly created DrawViews are
// handled differently by the FlatViewGroup. This is needed because updateBoundsAndFreeze
// uses .clone(), so we maintain the previous state.
@@ -96,6 +114,19 @@ import android.graphics.RectF;
return drawView;
}
private boolean logicalBoundsMatch(int left, int top, int right, int bottom) {
return left == mLogicalLeft && top == mLogicalTop &&
right == mLogicalRight && bottom == mLogicalBottom;
}
private void setLogicalBounds(int left, int top, int right, int bottom) {
// Do rounding up front and off of the UI thread.
mLogicalLeft = left;
mLogicalTop = top;
mLogicalRight = right;
mLogicalBottom = bottom;
}
@Override
public void draw(FlatViewGroup parent, Canvas canvas) {
onPreDraw(parent, canvas);