Loading graphics/java/android/graphics/PathIterator.java +15 −4 Original line number Diff line number Diff line Loading @@ -44,6 +44,8 @@ public class PathIterator implements Iterator<PathIterator.Segment> { private final Path mPath; private final int mPathGenerationId; private static final int POINT_ARRAY_SIZE = 8; private static final boolean IS_DALVIK = "dalvik".equalsIgnoreCase( System.getProperty("java.vm.name")); private static final NativeAllocationRegistry sRegistry = NativeAllocationRegistry.createMalloced( Loading Loading @@ -80,9 +82,14 @@ public class PathIterator implements Iterator<PathIterator.Segment> { mPath = path; mNativeIterator = nCreate(mPath.mNativePath); mPathGenerationId = mPath.getGenerationId(); if (IS_DALVIK) { final VMRuntime runtime = VMRuntime.getRuntime(); mPointsArray = (float[]) runtime.newNonMovableArray(float.class, POINT_ARRAY_SIZE); mPointsAddress = runtime.addressOf(mPointsArray); } else { mPointsArray = new float[POINT_ARRAY_SIZE]; mPointsAddress = 0; } sRegistry.registerNativeAllocation(this, mNativeIterator); } Loading Loading @@ -177,7 +184,8 @@ public class PathIterator implements Iterator<PathIterator.Segment> { throw new ConcurrentModificationException( "Iterator cannot be used on modified Path"); } @Verb int verb = nNext(mNativeIterator, mPointsAddress); @Verb int verb = IS_DALVIK ? nNext(mNativeIterator, mPointsAddress) : nNextHost(mNativeIterator, mPointsArray); if (verb == VERB_DONE) { mDone = true; } Loading Loading @@ -287,6 +295,9 @@ public class PathIterator implements Iterator<PathIterator.Segment> { private static native long nCreate(long nativePath); private static native long nGetFinalizer(); /* nNextHost should be used for host runtimes, e.g. LayoutLib */ private static native int nNextHost(long nativeIterator, float[] points); // ------------------ Critical JNI ------------------------ @CriticalNative Loading libs/hwui/jni/PathIterator.cpp +14 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ #include "GraphicsJNI.h" #include "SkPath.h" #include "SkPoint.h" #include "graphics_jni_helpers.h" namespace android { Loading @@ -36,6 +37,18 @@ public: return reinterpret_cast<jlong>(new SkPath::RawIter(*path)); } // A variant of 'next' (below) that is compatible with the host JVM. static jint nextHost(JNIEnv* env, jclass clazz, jlong iteratorHandle, jfloatArray pointsArray) { jfloat* points = env->GetFloatArrayElements(pointsArray, 0); #ifdef __ANDROID__ jint result = next(iteratorHandle, reinterpret_cast<jlong>(points)); #else jint result = next(env, clazz, iteratorHandle, reinterpret_cast<jlong>(points)); #endif env->ReleaseFloatArrayElements(pointsArray, points, 0); return result; } // ---------------- @CriticalNative ------------------------- static jint peek(CRITICAL_JNI_PARAMS_COMMA jlong iteratorHandle) { Loading Loading @@ -72,6 +85,7 @@ static const JNINativeMethod methods[] = { {"nPeek", "(J)I", (void*)SkPathIteratorGlue::peek}, {"nNext", "(JJ)I", (void*)SkPathIteratorGlue::next}, {"nNextHost", "(J[F)I", (void*)SkPathIteratorGlue::nextHost}, }; int register_android_graphics_PathIterator(JNIEnv* env) { Loading Loading
graphics/java/android/graphics/PathIterator.java +15 −4 Original line number Diff line number Diff line Loading @@ -44,6 +44,8 @@ public class PathIterator implements Iterator<PathIterator.Segment> { private final Path mPath; private final int mPathGenerationId; private static final int POINT_ARRAY_SIZE = 8; private static final boolean IS_DALVIK = "dalvik".equalsIgnoreCase( System.getProperty("java.vm.name")); private static final NativeAllocationRegistry sRegistry = NativeAllocationRegistry.createMalloced( Loading Loading @@ -80,9 +82,14 @@ public class PathIterator implements Iterator<PathIterator.Segment> { mPath = path; mNativeIterator = nCreate(mPath.mNativePath); mPathGenerationId = mPath.getGenerationId(); if (IS_DALVIK) { final VMRuntime runtime = VMRuntime.getRuntime(); mPointsArray = (float[]) runtime.newNonMovableArray(float.class, POINT_ARRAY_SIZE); mPointsAddress = runtime.addressOf(mPointsArray); } else { mPointsArray = new float[POINT_ARRAY_SIZE]; mPointsAddress = 0; } sRegistry.registerNativeAllocation(this, mNativeIterator); } Loading Loading @@ -177,7 +184,8 @@ public class PathIterator implements Iterator<PathIterator.Segment> { throw new ConcurrentModificationException( "Iterator cannot be used on modified Path"); } @Verb int verb = nNext(mNativeIterator, mPointsAddress); @Verb int verb = IS_DALVIK ? nNext(mNativeIterator, mPointsAddress) : nNextHost(mNativeIterator, mPointsArray); if (verb == VERB_DONE) { mDone = true; } Loading Loading @@ -287,6 +295,9 @@ public class PathIterator implements Iterator<PathIterator.Segment> { private static native long nCreate(long nativePath); private static native long nGetFinalizer(); /* nNextHost should be used for host runtimes, e.g. LayoutLib */ private static native int nNextHost(long nativeIterator, float[] points); // ------------------ Critical JNI ------------------------ @CriticalNative Loading
libs/hwui/jni/PathIterator.cpp +14 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ #include "GraphicsJNI.h" #include "SkPath.h" #include "SkPoint.h" #include "graphics_jni_helpers.h" namespace android { Loading @@ -36,6 +37,18 @@ public: return reinterpret_cast<jlong>(new SkPath::RawIter(*path)); } // A variant of 'next' (below) that is compatible with the host JVM. static jint nextHost(JNIEnv* env, jclass clazz, jlong iteratorHandle, jfloatArray pointsArray) { jfloat* points = env->GetFloatArrayElements(pointsArray, 0); #ifdef __ANDROID__ jint result = next(iteratorHandle, reinterpret_cast<jlong>(points)); #else jint result = next(env, clazz, iteratorHandle, reinterpret_cast<jlong>(points)); #endif env->ReleaseFloatArrayElements(pointsArray, points, 0); return result; } // ---------------- @CriticalNative ------------------------- static jint peek(CRITICAL_JNI_PARAMS_COMMA jlong iteratorHandle) { Loading Loading @@ -72,6 +85,7 @@ static const JNINativeMethod methods[] = { {"nPeek", "(J)I", (void*)SkPathIteratorGlue::peek}, {"nNext", "(JJ)I", (void*)SkPathIteratorGlue::next}, {"nNextHost", "(J[F)I", (void*)SkPathIteratorGlue::nextHost}, }; int register_android_graphics_PathIterator(JNIEnv* env) { Loading