diff options
author | dhewg | 2011-02-20 20:46:17 +0100 |
---|---|---|
committer | dhewg | 2011-02-24 23:18:32 +0100 |
commit | c4706733d45de09803b7cd40c3536a4e04b4f767 (patch) | |
tree | 0e62dd214b360ab0a8b85d032316d079a82b3600 /backends | |
parent | 4af28f96ab4075cb5e512d4050ac085df73a029a (diff) | |
download | scummvm-rg350-c4706733d45de09803b7cd40c3536a4e04b4f767.tar.gz scummvm-rg350-c4706733d45de09803b7cd40c3536a4e04b4f767.tar.bz2 scummvm-rg350-c4706733d45de09803b7cd40c3536a4e04b4f767.zip |
ANDROID: Move the global back reference to jni.cpp
Diffstat (limited to 'backends')
-rw-r--r-- | backends/platform/android/android.cpp | 29 | ||||
-rw-r--r-- | backends/platform/android/android.h | 8 | ||||
-rw-r--r-- | backends/platform/android/gfx.cpp | 6 | ||||
-rw-r--r-- | backends/platform/android/jni.cpp | 14 |
4 files changed, 29 insertions, 28 deletions
diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp index a0a53474e8..f2c9a7407d 100644 --- a/backends/platform/android/android.cpp +++ b/backends/platform/android/android.cpp @@ -101,7 +101,6 @@ static inline T scalef(T in, float numerator, float denominator) { OSystem_Android *g_sys = 0; OSystem_Android::OSystem_Android(jobject am) : - _back_ptr(0), _screen_changeid(0), _force_redraw(false), _game_texture(0), @@ -129,11 +128,6 @@ OSystem_Android::~OSystem_Android() { destroyScummVMSurface(); - JNIEnv *env = JNU_GetEnv(); - // see below - //env->DeleteWeakGlobalRef(_back_ptr); - env->DeleteGlobalRef(_back_ptr); - delete _savefile; delete _mixer; delete _timer; @@ -143,13 +137,8 @@ OSystem_Android::~OSystem_Android() { deleteMutex(_event_queue_lock); } -bool OSystem_Android::initJavaHooks(JNIEnv *env, jobject self) { - // weak global ref to allow class to be unloaded - // ... except dalvik implements NewWeakGlobalRef only on froyo - //_back_ptr = env->NewWeakGlobalRef(self); - _back_ptr = env->NewGlobalRef(self); - - jclass cls = env->GetObjectClass(_back_ptr); +bool OSystem_Android::initJavaHooks(JNIEnv *env) { + jclass cls = env->GetObjectClass(back_ptr); #define FIND_METHOD(name, signature) do { \ MID_ ## name = env->GetMethodID(cls, #name, signature); \ @@ -213,7 +202,7 @@ void OSystem_Android::initBackend() { gettimeofday(&_startTime, 0); - jint sample_rate = env->CallIntMethod(_back_ptr, MID_audioSampleRate); + jint sample_rate = env->CallIntMethod(back_ptr, MID_audioSampleRate); if (env->ExceptionCheck()) { warning("Error finding audio sample rate - assuming 11025HZ"); @@ -226,7 +215,7 @@ void OSystem_Android::initBackend() { _mixer = new Audio::MixerImpl(this, sample_rate); _mixer->setReady(true); - env->CallVoidMethod(_back_ptr, MID_initBackend); + env->CallVoidMethod(back_ptr, MID_initBackend); if (env->ExceptionCheck()) { error("Error in Java initBackend"); @@ -249,7 +238,7 @@ void OSystem_Android::addPluginDirectories(Common::FSList &dirs) const { JNIEnv *env = JNU_GetEnv(); jobjectArray array = - (jobjectArray)env->CallObjectMethod(_back_ptr, MID_getPluginDirectories); + (jobjectArray)env->CallObjectMethod(back_ptr, MID_getPluginDirectories); if (env->ExceptionCheck()) { warning("Error finding plugin directories"); @@ -490,7 +479,7 @@ void OSystem_Android::setWindowCaption(const char *caption) { JNIEnv *env = JNU_GetEnv(); jstring java_caption = env->NewStringUTF(caption); - env->CallVoidMethod(_back_ptr, MID_setWindowCaption, java_caption); + env->CallVoidMethod(back_ptr, MID_setWindowCaption, java_caption); if (env->ExceptionCheck()) { warning("Failed to set window caption"); @@ -508,7 +497,7 @@ void OSystem_Android::displayMessageOnOSD(const char *msg) { JNIEnv *env = JNU_GetEnv(); jstring java_msg = env->NewStringUTF(msg); - env->CallVoidMethod(_back_ptr, MID_displayMessageOnOSD, java_msg); + env->CallVoidMethod(back_ptr, MID_displayMessageOnOSD, java_msg); if (env->ExceptionCheck()) { warning("Failed to display OSD message"); @@ -525,7 +514,7 @@ void OSystem_Android::showVirtualKeyboard(bool enable) { JNIEnv *env = JNU_GetEnv(); - env->CallVoidMethod(_back_ptr, MID_showVirtualKeyboard, enable); + env->CallVoidMethod(back_ptr, MID_showVirtualKeyboard, enable); if (env->ExceptionCheck()) { error("Error trying to show virtual keyboard"); @@ -574,7 +563,7 @@ void OSystem_Android::addSysArchivesToSearchSet(Common::SearchSet &s, JNIEnv *env = JNU_GetEnv(); jobjectArray array = - (jobjectArray)env->CallObjectMethod(_back_ptr, MID_getSysArchives); + (jobjectArray)env->CallObjectMethod(back_ptr, MID_getSysArchives); if (env->ExceptionCheck()) { warning("Error finding system archive path"); diff --git a/backends/platform/android/android.h b/backends/platform/android/android.h index b31c0fd385..da487c5ceb 100644 --- a/backends/platform/android/android.h +++ b/backends/platform/android/android.h @@ -78,6 +78,9 @@ extern void checkGlError(const char *expr, const char *file, int line); #define GLCALL(x) do { (x); } while (false) #endif +// back pointer to (java) peer instance +extern jobject back_ptr; + extern JNIEnv *JNU_GetEnv(); extern void JNU_AttachThread(); extern void JNU_DetachThread(); @@ -94,9 +97,6 @@ protected: class OSystem_Android : public BaseBackend, public PaletteManager { private: - // back pointer to (java) peer instance - jobject _back_ptr; - jmethodID MID_displayMessageOnOSD; jmethodID MID_setWindowCaption; jmethodID MID_initBackend; @@ -155,7 +155,7 @@ private: public: OSystem_Android(jobject am); virtual ~OSystem_Android(); - bool initJavaHooks(JNIEnv *env, jobject self); + bool initJavaHooks(JNIEnv *env); virtual void initBackend(); void addPluginDirectories(Common::FSList &dirs) const; diff --git a/backends/platform/android/gfx.cpp b/backends/platform/android/gfx.cpp index eb5a66c6d9..2b730385e6 100644 --- a/backends/platform/android/gfx.cpp +++ b/backends/platform/android/gfx.cpp @@ -63,7 +63,7 @@ void OSystem_Android::setupScummVMSurface() { ENTER(); JNIEnv *env = JNU_GetEnv(); - env->CallVoidMethod(_back_ptr, MID_setupScummVMSurface); + env->CallVoidMethod(back_ptr, MID_setupScummVMSurface); if (env->ExceptionCheck()) return; @@ -117,7 +117,7 @@ void OSystem_Android::setupScummVMSurface() { void OSystem_Android::destroyScummVMSurface() { JNIEnv *env = JNU_GetEnv(); - env->CallVoidMethod(_back_ptr, MID_destroyScummVMSurface); + env->CallVoidMethod(back_ptr, MID_destroyScummVMSurface); // Can't use OpenGLES functions after this } @@ -262,7 +262,7 @@ void OSystem_Android::updateScreen() { GLCALL(glPopMatrix()); JNIEnv *env = JNU_GetEnv(); - if (!env->CallBooleanMethod(_back_ptr, MID_swapBuffers)) { + if (!env->CallBooleanMethod(back_ptr, MID_swapBuffers)) { // Context lost -> need to reinit GL destroyScummVMSurface(); setupScummVMSurface(); diff --git a/backends/platform/android/jni.cpp b/backends/platform/android/jni.cpp index e5d0f71f53..b81587b3ba 100644 --- a/backends/platform/android/jni.cpp +++ b/backends/platform/android/jni.cpp @@ -34,7 +34,10 @@ #undef JNIEXPORT #define JNIEXPORT __attribute__ ((visibility("default"))) +jobject back_ptr; + static JavaVM *cached_jvm; + static jfieldID FID_Event_type; static jfieldID FID_Event_synthetic; static jfieldID FID_Event_kbd_keycode; @@ -93,8 +96,13 @@ static void ScummVM_create(JNIEnv *env, jobject self, jobject am) { g_sys = new OSystem_Android(am); assert(g_sys); + // weak global ref to allow class to be unloaded + // ... except dalvik implements NewWeakGlobalRef only on froyo + //back_ptr = env->NewWeakGlobalRef(self); + back_ptr = env->NewGlobalRef(self); + // Exception already thrown by initJavaHooks? - if (!g_sys->initJavaHooks(env, self)) + if (!g_sys->initJavaHooks(env)) return; env->SetLongField(self, FID_ScummVM_nativeScummVM, (jlong)g_sys); @@ -109,6 +117,10 @@ static void ScummVM_nativeDestroy(JNIEnv *env, jobject self) { g_system = 0; g_sys = 0; delete tmp; + + // see above + //JNU_GetEnv()->DeleteWeakGlobalRef(back_ptr); + JNU_GetEnv()->DeleteGlobalRef(back_ptr); } static jint ScummVM_scummVMMain(JNIEnv *env, jobject self, jobjectArray args) { |