summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Chris Craik <ccraik@google.com> 2014-03-03 16:05:42 -0800
committer Chris Craik <ccraik@google.com> 2014-03-03 16:16:19 -0800
commit5be83edd15e11420287cc0af93a95d5a6dfae68f (patch)
tree535ceb96d6cb3009cb49f376b28b95ab04663653
parentadbd2ba1bcc222ce47e24d0db180bb85eefae371 (diff)
Add Path.isConvex, and force View outlines to be convex
Change-Id: Idf3f1ee44240d77f7a7ddd0da898da8aa5d41864
-rw-r--r--api/current.txt1
-rw-r--r--core/java/android/view/View.java8
-rw-r--r--core/jni/android/graphics/Path.cpp8
-rw-r--r--graphics/java/android/graphics/Path.java26
4 files changed, 36 insertions, 7 deletions
diff --git a/api/current.txt b/api/current.txt
index 23bbdbad8d07..3a72caac1866 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -9922,6 +9922,7 @@ package android.graphics {
method public void cubicTo(float, float, float, float, float, float);
method public android.graphics.Path.FillType getFillType();
method public void incReserve(int);
+ method public boolean isConvex();
method public boolean isEmpty();
method public boolean isInverseFillType();
method public boolean isRect(android.graphics.RectF);
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index 99aee29e194c..e672a836a3d0 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -10841,11 +10841,14 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* Sets the outline of the view, which defines the shape of the shadow it
* casts, and can used for clipping.
* <p>
+ * The outline path of a View must be {@link android.graphics.Path#isConvex() convex}.
+ * <p>
* If the outline is not set, or {@link Path#isEmpty()}, shadows will be
* cast from the bounds of the View, and clipToOutline will be ignored.
*
- * @param outline The new outline of the view. Must be non-null.
+ * @param outline The new outline of the view. Must be non-null, and convex.
*
+ * @see #setCastsShadow(boolean)
* @see #getOutline(Path)
* @see #getClipToOutline()
* @see #setClipToOutline(boolean)
@@ -10854,6 +10857,9 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
if (outline == null) {
throw new IllegalArgumentException("Path must be non-null");
}
+ if (!outline.isConvex()) {
+ throw new IllegalArgumentException("Path must be convex");
+ }
// always copy the path since caller may reuse
if (mOutline == null) {
mOutline = new Path(outline);
diff --git a/core/jni/android/graphics/Path.cpp b/core/jni/android/graphics/Path.cpp
index 429f177c9d9d..e580d36ac867 100644
--- a/core/jni/android/graphics/Path.cpp
+++ b/core/jni/android/graphics/Path.cpp
@@ -72,11 +72,16 @@ public:
*dst = *src;
}
+ static jboolean isConvex(JNIEnv* env, jobject clazz, jlong objHandle) {
+ SkPath* obj = reinterpret_cast<SkPath*>(objHandle);
+ return obj->isConvex();
+ }
+
static jint getFillType(JNIEnv* env, jobject clazz, jlong objHandle) {
SkPath* obj = reinterpret_cast<SkPath*>(objHandle);
return obj->getFillType();
}
-
+
static void setFillType(JNIEnv* env, jobject clazz, jlong pathHandle, jint ftHandle) {
SkPath* path = reinterpret_cast<SkPath*>(pathHandle);
SkPath::FillType ft = static_cast<SkPath::FillType>(ftHandle);
@@ -524,6 +529,7 @@ static JNINativeMethod methods[] = {
{"native_reset","(J)V", (void*) SkPathGlue::reset},
{"native_rewind","(J)V", (void*) SkPathGlue::rewind},
{"native_set","(JJ)V", (void*) SkPathGlue::assign},
+ {"native_isConvex","(J)Z", (void*) SkPathGlue::isConvex},
{"native_getFillType","(J)I", (void*) SkPathGlue::getFillType},
{"native_setFillType","(JI)V", (void*) SkPathGlue::setFillType},
{"native_isEmpty","(J)Z", (void*) SkPathGlue::isEmpty},
diff --git a/graphics/java/android/graphics/Path.java b/graphics/java/android/graphics/Path.java
index 2ce73acd12d3..c07a6dabbabc 100644
--- a/graphics/java/android/graphics/Path.java
+++ b/graphics/java/android/graphics/Path.java
@@ -168,6 +168,21 @@ public class Path {
}
/**
+ * Returns the path's convexity, as defined by the content of the path.
+ * <p>
+ * A path is convex if it has a single contour, and only ever curves in a
+ * single direction.
+ * <p>
+ * This function will calculate the convexity of the path from its control
+ * points, and cache the result.
+ *
+ * @return True if the path is convex.
+ */
+ public boolean isConvex() {
+ return native_isConvex(mNativePath);
+ }
+
+ /**
* Enum for the ways a path may be filled.
*/
public enum FillType {
@@ -224,7 +239,7 @@ public class Path {
public void setFillType(FillType ft) {
native_setFillType(mNativePath, ft.nativeInt);
}
-
+
/**
* Returns true if the filltype is one of the INVERSE variants
*
@@ -232,18 +247,18 @@ public class Path {
*/
public boolean isInverseFillType() {
final int ft = native_getFillType(mNativePath);
- return (ft & 2) != 0;
+ return (ft & FillType.INVERSE_WINDING.nativeInt) != 0;
}
-
+
/**
* Toggles the INVERSE state of the filltype
*/
public void toggleInverseFillType() {
int ft = native_getFillType(mNativePath);
- ft ^= 2;
+ ft ^= FillType.INVERSE_WINDING.nativeInt;
native_setFillType(mNativePath, ft);
}
-
+
/**
* Returns true if the path is empty (contains no lines or curves)
*
@@ -719,6 +734,7 @@ public class Path {
private static native void native_reset(long nPath);
private static native void native_rewind(long nPath);
private static native void native_set(long native_dst, long native_src);
+ private static native boolean native_isConvex(long nPath);
private static native int native_getFillType(long nPath);
private static native void native_setFillType(long nPath, int ft);
private static native boolean native_isEmpty(long nPath);