diff options
author | Jamie Gennis <jgennis@google.com> | 2011-06-20 11:54:34 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2011-06-20 11:54:34 -0700 |
commit | fd0ffd2a4e883074c56f519906f3e2c720de6da8 (patch) | |
tree | cc304e919cf7fa32b75448a791bc4c451c06fe1c | |
parent | 466ebb1d8ab37b4d84a7fe1cbef2c11191ae37c0 (diff) | |
parent | 84293fb9625a3ab7d7d302436bea05441b8d7316 (diff) | |
download | frameworks_base-fd0ffd2a4e883074c56f519906f3e2c720de6da8.zip frameworks_base-fd0ffd2a4e883074c56f519906f3e2c720de6da8.tar.gz frameworks_base-fd0ffd2a4e883074c56f519906f3e2c720de6da8.tar.bz2 |
Merge "SurfaceTexture: attach to Dalvik when needed."
-rw-r--r-- | core/jni/android/graphics/SurfaceTexture.cpp | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/core/jni/android/graphics/SurfaceTexture.cpp b/core/jni/android/graphics/SurfaceTexture.cpp index 3f922f6..0d28cb1 100644 --- a/core/jni/android/graphics/SurfaceTexture.cpp +++ b/core/jni/android/graphics/SurfaceTexture.cpp @@ -91,6 +91,8 @@ public: virtual void onFrameAvailable(); private: + static JNIEnv* getJNIEnv(); + jobject mWeakThiz; jclass mClazz; }; @@ -101,17 +103,37 @@ JNISurfaceTextureContext::JNISurfaceTextureContext(JNIEnv* env, mClazz((jclass)env->NewGlobalRef(clazz)) {} +JNIEnv* JNISurfaceTextureContext::getJNIEnv() { + JNIEnv* env; + JavaVMAttachArgs args = {JNI_VERSION_1_4, NULL, NULL}; + JavaVM* vm = AndroidRuntime::getJavaVM(); + int result = vm->AttachCurrentThread(&env, (void*) &args); + if (result != JNI_OK) { + LOGE("thread attach failed: %#x", result); + return NULL; + } + return env; +} + JNISurfaceTextureContext::~JNISurfaceTextureContext() { - JNIEnv *env = AndroidRuntime::getJNIEnv(); - env->DeleteGlobalRef(mWeakThiz); - env->DeleteGlobalRef(mClazz); + JNIEnv* env = getJNIEnv(); + if (env != NULL) { + env->DeleteGlobalRef(mWeakThiz); + env->DeleteGlobalRef(mClazz); + } else { + LOGW("leaking JNI object references"); + } } void JNISurfaceTextureContext::onFrameAvailable() { - JNIEnv *env = AndroidRuntime::getJNIEnv(); - env->CallStaticVoidMethod(mClazz, fields.postEvent, mWeakThiz); + JNIEnv *env = getJNIEnv(); + if (env != NULL) { + env->CallStaticVoidMethod(mClazz, fields.postEvent, mWeakThiz); + } else { + LOGW("onFrameAvailable event will not posted"); + } } // ---------------------------------------------------------------------------- |