diff options
| author | Maurus Cuelenaere <mcuelenaere@gmail.com> | 2011-03-11 18:34:31 +0000 |
|---|---|---|
| committer | Maurus Cuelenaere <mcuelenaere@gmail.com> | 2011-03-11 18:34:31 +0000 |
| commit | 2e5b7aebde6426058ea7b69424b0335a844a6a18 (patch) | |
| tree | 2ce54c30eb646b1d78d38ff34ff3eb3f76955bff /firmware/target/hosted/android | |
| parent | 7228f2fa9faf587bab51f2e3c1727b7ca962b441 (diff) | |
| download | rockbox-2e5b7aebde6426058ea7b69424b0335a844a6a18.zip rockbox-2e5b7aebde6426058ea7b69424b0335a844a6a18.tar.gz rockbox-2e5b7aebde6426058ea7b69424b0335a844a6a18.tar.bz2 rockbox-2e5b7aebde6426058ea7b69424b0335a844a6a18.tar.xz | |
Android: use NewGlobalRef for references that are used globally
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29568 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/target/hosted/android')
| -rw-r--r-- | firmware/target/hosted/android/lcd-android.c | 25 | ||||
| -rw-r--r-- | firmware/target/hosted/android/pcm-android.c | 11 | ||||
| -rw-r--r-- | firmware/target/hosted/android/system-android.c | 19 |
3 files changed, 43 insertions, 12 deletions
diff --git a/firmware/target/hosted/android/lcd-android.c b/firmware/target/hosted/android/lcd-android.c index 0cde160..08a4075 100644 --- a/firmware/target/hosted/android/lcd-android.c +++ b/firmware/target/hosted/android/lcd-android.c @@ -47,8 +47,16 @@ static bool display_on; void connect_with_java(JNIEnv* env, jobject fb_instance) { JNIEnv e = *env; - static bool have_class; - RockboxFramebuffer_instance = fb_instance; + + /* Update RockboxFramebuffer_instance */ + if (!e->IsSameObject(env, RockboxFramebuffer_instance, fb_instance)) { + if (RockboxFramebuffer_instance != NULL) + e->DeleteGlobalRef(env, RockboxFramebuffer_instance); + + RockboxFramebuffer_instance = e->NewGlobalRef(env, fb_instance); + } + + static bool have_class = false; if (!have_class) { jclass fb_class = e->GetObjectClass(env, fb_instance); @@ -70,10 +78,13 @@ void connect_with_java(JNIEnv* env, jobject fb_instance) java_lcd_init = e->GetMethodID(env, fb_class, "java_lcd_init", "(IILjava/nio/ByteBuffer;)V"); - - native_buffer = e->NewDirectByteBuffer(env, + + jobject buffer = e->NewDirectByteBuffer(env, lcd_framebuffer, (jlong)sizeof(lcd_framebuffer)); + + native_buffer = e->NewGlobalRef(env, buffer); + have_class = true; } /* we need to setup parts for the java object every time */ @@ -81,6 +92,12 @@ void connect_with_java(JNIEnv* env, jobject fb_instance) (jint)LCD_WIDTH, (jint)LCD_HEIGHT, native_buffer); } +void lcd_deinit(void) +{ + (*env_ptr)->DeleteGlobalRef(env_ptr, RockboxFramebuffer_instance); + (*env_ptr)->DeleteGlobalRef(env_ptr, native_buffer); +} + /* * Do nothing here and connect with the java object later (if it isn't already) */ diff --git a/firmware/target/hosted/android/pcm-android.c b/firmware/target/hosted/android/pcm-android.c index c8bc410..f4ed4b1 100644 --- a/firmware/target/hosted/android/pcm-android.c +++ b/firmware/target/hosted/android/pcm-android.c @@ -35,7 +35,6 @@ static char *pcm_data_start; static jmethodID play_pause_method; static jmethodID stop_method; static jmethodID set_volume_method; -static jclass RockboxPCM_class; static jobject RockboxPCM_instance; @@ -155,10 +154,11 @@ void pcm_play_dma_init(void) **/ JNIEnv e = *env_ptr; /* get the class and its constructor */ - RockboxPCM_class = e->FindClass(env_ptr, "org/rockbox/RockboxPCM"); + jclass RockboxPCM_class = e->FindClass(env_ptr, "org/rockbox/RockboxPCM"); jmethodID constructor = e->GetMethodID(env_ptr, RockboxPCM_class, "<init>", "()V"); /* instance = new RockboxPCM() */ - RockboxPCM_instance = e->NewObject(env_ptr, RockboxPCM_class, constructor); + jobject PCM_instance = e->NewObject(env_ptr, RockboxPCM_class, constructor); + RockboxPCM_instance = e->NewGlobalRef(env_ptr, PCM_instance); /* cache needed methods */ play_pause_method = e->GetMethodID(env_ptr, RockboxPCM_class, "play_pause", "(Z)V"); set_volume_method = e->GetMethodID(env_ptr, RockboxPCM_class, "set_volume", "(I)V"); @@ -167,6 +167,11 @@ void pcm_play_dma_init(void) pcm_play_get_more_callback((void*)&pcm_data_start, &pcm_data_size); } +void pcm_deinit(void) +{ + (*env_ptr)->DeleteGlobalRef(env_ptr, RockboxPCM_instance); +} + void pcm_postinit(void) { } diff --git a/firmware/target/hosted/android/system-android.c b/firmware/target/hosted/android/system-android.c index 92c2d7c..66de4e0 100644 --- a/firmware/target/hosted/android/system-android.c +++ b/firmware/target/hosted/android/system-android.c @@ -36,10 +36,18 @@ uintptr_t *stackend; extern int main(void); extern void telephony_init_device(void); +extern void lcd_deinit(void); +extern void pcm_deinit(void); void system_exception_wait(void) { } void system_reboot(void) { } -void power_off(void) { } + +void power_off(void) +{ + lcd_deinit(); + pcm_deinit(); + (*env_ptr)->DeleteGlobalRef(env_ptr, RockboxService_class); +} void system_init(void) { @@ -51,18 +59,19 @@ void system_init(void) JNIEXPORT void JNICALL Java_org_rockbox_RockboxService_main(JNIEnv *env, jobject this) { + jclass class = (*env)->GetObjectClass(env, this); + /* hack!!! we can't have a valid stack pointer otherwise. * but we don't really need it anyway, thread.c only needs it * for overflow detection which doesn't apply for the main thread * (it's managed by the OS) */ - (void)env; - (void)this; volatile uintptr_t stack = 0; stackbegin = stackend = (uintptr_t*) &stack; env_ptr = env; - RockboxService_instance = this; - RockboxService_class = (*env)->GetObjectClass(env, this); + + RockboxService_instance = (*env)->NewGlobalRef(env, this); + RockboxService_class = (*env)->NewGlobalRef(env, class); main(); } |