diff options
author | Chris Craik <ccraik@google.com> | 2014-05-16 00:37:28 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2014-05-16 00:37:29 +0000 |
commit | c9ee304c91b5572f0c1cd95e9bd1e4a84e28587d (patch) | |
tree | bfa9e5965d749b815ac7e55cea6b7b204db70cca /graphics | |
parent | 6c536eac59adf6e11694ba3800222ad03fe93d1f (diff) | |
parent | deeda3d337aed1eee218b89a7aba5992ced371f0 (diff) | |
download | frameworks_base-c9ee304c91b5572f0c1cd95e9bd1e4a84e28587d.zip frameworks_base-c9ee304c91b5572f0c1cd95e9bd1e4a84e28587d.tar.gz frameworks_base-c9ee304c91b5572f0c1cd95e9bd1e4a84e28587d.tar.bz2 |
Merge "Round rect outline clipping"
Diffstat (limited to 'graphics')
-rw-r--r-- | graphics/java/android/graphics/Outline.java | 50 |
1 files changed, 30 insertions, 20 deletions
diff --git a/graphics/java/android/graphics/Outline.java b/graphics/java/android/graphics/Outline.java index b5c0801..c6ba75c 100644 --- a/graphics/java/android/graphics/Outline.java +++ b/graphics/java/android/graphics/Outline.java @@ -53,8 +53,7 @@ public final class Outline { set(src); } - /** @hide */ - public void markInvalid() { + public void reset() { mRadius = 0; mRect = null; mPath = null; @@ -74,27 +73,21 @@ public final class Outline { * * @param src Source outline to copy from. */ - public void set(@Nullable Outline src) { - if (src == null) { - mRadius = 0; - mRect = null; - mPath = null; - } else { - if (src.mPath != null) { - if (mPath == null) { - mPath = new Path(); - } - mPath.set(src.mPath); - mRect = null; + public void set(@NonNull Outline src) { + if (src.mPath != null) { + if (mPath == null) { + mPath = new Path(); } - if (src.mRect != null) { - if (mRect == null) { - mRect = new Rect(); - } - mRect.set(src.mRect); + mPath.set(src.mPath); + mRect = null; + } + if (src.mRect != null) { + if (mRect == null) { + mRect = new Rect(); } - mRadius = src.mRadius; + mRect.set(src.mRect); } + mRadius = src.mRadius; } /** @@ -134,6 +127,11 @@ public final class Outline { * Sets the outline to the oval defined by input rect. */ public void setOval(int left, int top, int right, int bottom) { + if ((bottom - top) == (right - left)) { + // represent circle as round rect, for efficiency, and to enable clipping + setRoundRect(left, top, right, bottom, (bottom - top) / 2.0f); + return; + } mRect = null; if (mPath == null) mPath = new Path(); mPath.reset(); @@ -160,4 +158,16 @@ public final class Outline { mRadius = -1.0f; mPath.set(convexPath); } + + /** + * Returns whether the outline can be used to clip a View. + * + * Currently, only outlines that can be represented as a rectangle, circle, or round rect + * support clipping. + * + * @see {@link View#setClipToOutline(boolean)} + */ + public boolean canClip() { + return mRect != null; + } } |