diff options
| -rw-r--r-- | core/jni/android/graphics/Path.cpp | 23 | ||||
| -rw-r--r-- | graphics/java/android/graphics/Path.java | 23 |
2 files changed, 25 insertions, 21 deletions
diff --git a/core/jni/android/graphics/Path.cpp b/core/jni/android/graphics/Path.cpp index d3d68826affe..97abd82eaac5 100644 --- a/core/jni/android/graphics/Path.cpp +++ b/core/jni/android/graphics/Path.cpp @@ -37,6 +37,14 @@ namespace android { class SkPathGlue { public: + static void finalizer(SkPath* obj) { + // Purge entries from the HWUI path cache if this path's data is unique + if (obj->unique() && android::uirenderer::Caches::hasInstance()) { + android::uirenderer::Caches::getInstance().pathCache.removeDeferred(obj); + } + delete obj; + } + // ---------------- Regular JNI ----------------------------- static jlong init(JNIEnv* env, jclass clazz) { @@ -48,13 +56,8 @@ public: return reinterpret_cast<jlong>(new SkPath(*val)); } - static void finalize(JNIEnv* env, jclass clazz, jlong objHandle) { - SkPath* obj = reinterpret_cast<SkPath*>(objHandle); - // Purge entries from the HWUI path cache if this path's data is unique - if (obj->unique() && android::uirenderer::Caches::hasInstance()) { - android::uirenderer::Caches::getInstance().pathCache.removeDeferred(obj); - } - delete obj; + static jlong getFinalizer(JNIEnv* env, jclass clazz) { + return static_cast<jlong>(reinterpret_cast<uintptr_t>(&finalizer)); } static void set(JNIEnv* env, jclass clazz, jlong dstHandle, jlong srcHandle) { @@ -469,7 +472,9 @@ public: SkRect rect; SkPath* obj = reinterpret_cast<SkPath*>(objHandle); jboolean result = obj->isRect(&rect); - GraphicsJNI::rect_to_jrectf(rect, env, jrect); + if (jrect) { + GraphicsJNI::rect_to_jrectf(rect, env, jrect); + } return result; } @@ -510,7 +515,7 @@ public: static const JNINativeMethod methods[] = { {"nInit","()J", (void*) SkPathGlue::init}, {"nInit","(J)J", (void*) SkPathGlue::init_Path}, - {"nFinalize", "(J)V", (void*) SkPathGlue::finalize}, + {"nGetFinalizer", "()J", (void*) SkPathGlue::getFinalizer}, {"nSet","(JJ)V", (void*) SkPathGlue::set}, {"nComputeBounds","(JLandroid/graphics/RectF;)V", (void*) SkPathGlue::computeBounds}, {"nIncReserve","(JI)V", (void*) SkPathGlue::incReserve}, diff --git a/graphics/java/android/graphics/Path.java b/graphics/java/android/graphics/Path.java index 098cdc67555d..cd0862cd13fe 100644 --- a/graphics/java/android/graphics/Path.java +++ b/graphics/java/android/graphics/Path.java @@ -24,6 +24,8 @@ import android.annotation.Size; import dalvik.annotation.optimization.CriticalNative; import dalvik.annotation.optimization.FastNative; +import libcore.util.NativeAllocationRegistry; + /** * The Path class encapsulates compound (multiple contour) geometric paths * consisting of straight line segments, quadratic curves, and cubic curves. @@ -32,10 +34,14 @@ import dalvik.annotation.optimization.FastNative; * text on a path. */ public class Path { + + private static final NativeAllocationRegistry sRegistry = new NativeAllocationRegistry( + Path.class.getClassLoader(), nGetFinalizer(), 48 /* dummy size */); + /** * @hide */ - public long mNativePath; + public final long mNativePath; /** * @hide @@ -52,6 +58,7 @@ public class Path { */ public Path() { mNativePath = nInit(); + sRegistry.registerNativeAllocation(this, mNativePath); } /** @@ -69,6 +76,7 @@ public class Path { } } mNativePath = nInit(valNative); + sRegistry.registerNativeAllocation(this, mNativePath); } /** @@ -297,7 +305,7 @@ public class Path { * a rectangle * @return true if the path specifies a rectangle */ - public boolean isRect(RectF rect) { + public boolean isRect(@Nullable RectF rect) { return nIsRect(mNativePath, rect); } @@ -771,15 +779,6 @@ public class Path { nTransform(mNativePath, matrix.native_instance); } - protected void finalize() throws Throwable { - try { - nFinalize(mNativePath); - mNativePath = 0; // Other finalizers can still call us. - } finally { - super.finalize(); - } - } - /** @hide */ public final long readOnlyNI() { return mNativePath; @@ -820,7 +819,7 @@ public class Path { private static native long nInit(); private static native long nInit(long nPath); - private static native void nFinalize(long nPath); + private static native long nGetFinalizer(); private static native void nSet(long native_dst, long nSrc); private static native void nComputeBounds(long nPath, RectF bounds); private static native void nIncReserve(long nPath, int extraPtCount); |