summaryrefslogtreecommitdiffstats
path: root/graphics
diff options
context:
space:
mode:
authorChris Craik <ccraik@google.com>2014-05-05 19:09:33 -0700
committerChris Craik <ccraik@google.com>2014-05-15 16:36:12 -0700
commitdeeda3d337aed1eee218b89a7aba5992ced371f0 (patch)
tree15e13e84727baebce58b735e34ef5d198fd84389 /graphics
parentfe4c1e225d147fe9cb5d7c121b7d6d11a312844e (diff)
downloadframeworks_base-deeda3d337aed1eee218b89a7aba5992ced371f0.zip
frameworks_base-deeda3d337aed1eee218b89a7aba5992ced371f0.tar.gz
frameworks_base-deeda3d337aed1eee218b89a7aba5992ced371f0.tar.bz2
Round rect outline clipping
Change-Id: Iee9cf4f719f6f1917507b69189ad114fa365917b
Diffstat (limited to 'graphics')
-rw-r--r--graphics/java/android/graphics/Outline.java50
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;
+ }
}