summaryrefslogtreecommitdiff
path: root/graphics/java/android/graphics/Outline.java
diff options
context:
space:
mode:
Diffstat (limited to 'graphics/java/android/graphics/Outline.java')
-rw-r--r--graphics/java/android/graphics/Outline.java36
1 files changed, 30 insertions, 6 deletions
diff --git a/graphics/java/android/graphics/Outline.java b/graphics/java/android/graphics/Outline.java
index aa81b9196fe1..3e59f34f6bc7 100644
--- a/graphics/java/android/graphics/Outline.java
+++ b/graphics/java/android/graphics/Outline.java
@@ -58,8 +58,12 @@ public final class Outline {
@Mode
public int mMode = MODE_EMPTY;
- /** @hide */
- public final Path mPath = new Path();
+ /**
+ * Only guaranteed to be non-null when mode == MODE_CONVEX_PATH
+ *
+ * @hide
+ */
+ public Path mPath;
/** @hide */
public final Rect mRect = new Rect();
@@ -87,8 +91,11 @@ public final class Outline {
* @see #isEmpty()
*/
public void setEmpty() {
+ if (mPath != null) {
+ // rewind here to avoid thrashing the allocations, but could alternately clear ref
+ mPath.rewind();
+ }
mMode = MODE_EMPTY;
- mPath.rewind();
mRect.setEmpty();
mRadius = RADIUS_UNDEFINED;
}
@@ -148,7 +155,12 @@ public final class Outline {
*/
public void set(@NonNull Outline src) {
mMode = src.mMode;
- mPath.set(src.mPath);
+ if (src.mMode == MODE_CONVEX_PATH) {
+ if (mPath == null) {
+ mPath = new Path();
+ }
+ mPath.set(src.mPath);
+ }
mRect.set(src.mRect);
mRadius = src.mRadius;
mAlpha = src.mAlpha;
@@ -180,10 +192,13 @@ public final class Outline {
return;
}
+ if (mMode == MODE_CONVEX_PATH) {
+ // rewind here to avoid thrashing the allocations, but could alternately clear ref
+ mPath.rewind();
+ }
mMode = MODE_ROUND_RECT;
mRect.set(left, top, right, bottom);
mRadius = radius;
- mPath.rewind();
}
/**
@@ -236,8 +251,13 @@ public final class Outline {
return;
}
+ if (mPath == null) {
+ mPath = new Path();
+ } else {
+ mPath.rewind();
+ }
+
mMode = MODE_CONVEX_PATH;
- mPath.rewind();
mPath.addOval(left, top, right, bottom, Path.Direction.CW);
mRect.setEmpty();
mRadius = RADIUS_UNDEFINED;
@@ -264,6 +284,10 @@ public final class Outline {
throw new IllegalArgumentException("path must be convex");
}
+ if (mPath == null) {
+ mPath = new Path();
+ }
+
mMode = MODE_CONVEX_PATH;
mPath.set(convexPath);
mRect.setEmpty();