Loading libs/hwui/jni/AnimatedImageDrawable.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -183,7 +183,7 @@ public: } ~InvokeListener() override { auto* env = get_env_or_die(mJvm); auto* env = requireEnv(mJvm); env->DeleteWeakGlobalRef(mWeakRef); } Loading libs/hwui/jni/ByteBufferStreamAdaptor.cpp +1 −19 Original line number Diff line number Diff line Loading @@ -9,24 +9,6 @@ using namespace android; static jmethodID gByteBuffer_getMethodID; static jmethodID gByteBuffer_setPositionMethodID; /** * Helper method for accessing the JNI interface pointer. * * Image decoding (which this supports) is started on a thread that is already * attached to the Java VM. But an AnimatedImageDrawable continues decoding on * the AnimatedImageThread, which is not attached. This will attach if * necessary. */ static JNIEnv* requireEnv(JavaVM* jvm) { JNIEnv* env; if (jvm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) { if (jvm->AttachCurrentThreadAsDaemon(&env, nullptr) != JNI_OK) { LOG_ALWAYS_FATAL("Failed to AttachCurrentThread!"); } } return env; } class ByteBufferStream : public SkStreamAsset { private: ByteBufferStream(JavaVM* jvm, jobject jbyteBuffer, size_t initialPosition, size_t length, Loading Loading @@ -304,7 +286,7 @@ std::unique_ptr<SkStream> CreateByteBufferStreamAdaptor(JNIEnv* env, jobject jby auto* context = new release_proc_context{jvm, jbyteBuffer}; auto releaseProc = [](const void*, void* context) { auto* c = reinterpret_cast<release_proc_context*>(context); JNIEnv* env = get_env_or_die(c->jvm); JNIEnv* env = requireEnv(c->jvm); env->DeleteGlobalRef(c->jbyteBuffer); delete c; }; Loading libs/hwui/jni/CreateJavaOutputStreamAdaptor.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -49,13 +49,13 @@ public: } ~JavaInputStreamAdaptor() override { auto* env = android::get_env_or_die(fJvm); auto* env = android::requireEnv(fJvm); env->DeleteGlobalRef(fJavaInputStream); env->DeleteGlobalRef(fJavaByteArray); } size_t read(void* buffer, size_t size) override { auto* env = android::get_env_or_die(fJvm); auto* env = android::requireEnv(fJvm); if (!fSwallowExceptions && checkException(env)) { // Just in case the caller did not clear from a previous exception. return 0; Loading libs/hwui/jni/Utils.cpp +10 −0 Original line number Diff line number Diff line Loading @@ -159,3 +159,13 @@ JNIEnv* android::get_env_or_die(JavaVM* jvm) { } return env; } JNIEnv* android::requireEnv(JavaVM* jvm) { JNIEnv* env; if (jvm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) { if (jvm->AttachCurrentThreadAsDaemon(&env, nullptr) != JNI_OK) { LOG_ALWAYS_FATAL("Failed to AttachCurrentThread!"); } } return env; } libs/hwui/jni/Utils.h +10 −0 Original line number Diff line number Diff line Loading @@ -78,6 +78,16 @@ bool isSeekable(int descriptor); JNIEnv* get_env_or_die(JavaVM* jvm); /** * Helper method for accessing the JNI interface pointer. * * Image decoding (which this supports) is started on a thread that is already * attached to the Java VM. But an AnimatedImageDrawable continues decoding on * the AnimatedImageThread, which is not attached. This will attach if * necessary. */ JNIEnv* requireEnv(JavaVM* jvm); }; // namespace android #endif // _ANDROID_GRAPHICS_UTILS_H_ Loading
libs/hwui/jni/AnimatedImageDrawable.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -183,7 +183,7 @@ public: } ~InvokeListener() override { auto* env = get_env_or_die(mJvm); auto* env = requireEnv(mJvm); env->DeleteWeakGlobalRef(mWeakRef); } Loading
libs/hwui/jni/ByteBufferStreamAdaptor.cpp +1 −19 Original line number Diff line number Diff line Loading @@ -9,24 +9,6 @@ using namespace android; static jmethodID gByteBuffer_getMethodID; static jmethodID gByteBuffer_setPositionMethodID; /** * Helper method for accessing the JNI interface pointer. * * Image decoding (which this supports) is started on a thread that is already * attached to the Java VM. But an AnimatedImageDrawable continues decoding on * the AnimatedImageThread, which is not attached. This will attach if * necessary. */ static JNIEnv* requireEnv(JavaVM* jvm) { JNIEnv* env; if (jvm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) { if (jvm->AttachCurrentThreadAsDaemon(&env, nullptr) != JNI_OK) { LOG_ALWAYS_FATAL("Failed to AttachCurrentThread!"); } } return env; } class ByteBufferStream : public SkStreamAsset { private: ByteBufferStream(JavaVM* jvm, jobject jbyteBuffer, size_t initialPosition, size_t length, Loading Loading @@ -304,7 +286,7 @@ std::unique_ptr<SkStream> CreateByteBufferStreamAdaptor(JNIEnv* env, jobject jby auto* context = new release_proc_context{jvm, jbyteBuffer}; auto releaseProc = [](const void*, void* context) { auto* c = reinterpret_cast<release_proc_context*>(context); JNIEnv* env = get_env_or_die(c->jvm); JNIEnv* env = requireEnv(c->jvm); env->DeleteGlobalRef(c->jbyteBuffer); delete c; }; Loading
libs/hwui/jni/CreateJavaOutputStreamAdaptor.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -49,13 +49,13 @@ public: } ~JavaInputStreamAdaptor() override { auto* env = android::get_env_or_die(fJvm); auto* env = android::requireEnv(fJvm); env->DeleteGlobalRef(fJavaInputStream); env->DeleteGlobalRef(fJavaByteArray); } size_t read(void* buffer, size_t size) override { auto* env = android::get_env_or_die(fJvm); auto* env = android::requireEnv(fJvm); if (!fSwallowExceptions && checkException(env)) { // Just in case the caller did not clear from a previous exception. return 0; Loading
libs/hwui/jni/Utils.cpp +10 −0 Original line number Diff line number Diff line Loading @@ -159,3 +159,13 @@ JNIEnv* android::get_env_or_die(JavaVM* jvm) { } return env; } JNIEnv* android::requireEnv(JavaVM* jvm) { JNIEnv* env; if (jvm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) { if (jvm->AttachCurrentThreadAsDaemon(&env, nullptr) != JNI_OK) { LOG_ALWAYS_FATAL("Failed to AttachCurrentThread!"); } } return env; }
libs/hwui/jni/Utils.h +10 −0 Original line number Diff line number Diff line Loading @@ -78,6 +78,16 @@ bool isSeekable(int descriptor); JNIEnv* get_env_or_die(JavaVM* jvm); /** * Helper method for accessing the JNI interface pointer. * * Image decoding (which this supports) is started on a thread that is already * attached to the Java VM. But an AnimatedImageDrawable continues decoding on * the AnimatedImageThread, which is not attached. This will attach if * necessary. */ JNIEnv* requireEnv(JavaVM* jvm); }; // namespace android #endif // _ANDROID_GRAPHICS_UTILS_H_