summaryrefslogtreecommitdiff
path: root/firmware/target/hosted
diff options
context:
space:
mode:
authorMaurus Cuelenaere <mcuelenaere@gmail.com>2011-03-11 18:34:31 +0000
committerMaurus Cuelenaere <mcuelenaere@gmail.com>2011-03-11 18:34:31 +0000
commit2e5b7aebde6426058ea7b69424b0335a844a6a18 (patch)
tree2ce54c30eb646b1d78d38ff34ff3eb3f76955bff /firmware/target/hosted
parent7228f2fa9faf587bab51f2e3c1727b7ca962b441 (diff)
downloadrockbox-2e5b7aebde6426058ea7b69424b0335a844a6a18.tar.gz
rockbox-2e5b7aebde6426058ea7b69424b0335a844a6a18.zip
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')
-rw-r--r--firmware/target/hosted/android/lcd-android.c25
-rw-r--r--firmware/target/hosted/android/pcm-android.c11
-rw-r--r--firmware/target/hosted/android/system-android.c19
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 0cde160e65..08a4075795 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;
47void connect_with_java(JNIEnv* env, jobject fb_instance) 47void connect_with_java(JNIEnv* env, jobject fb_instance)
48{ 48{
49 JNIEnv e = *env; 49 JNIEnv e = *env;
50 static bool have_class; 50
51 RockboxFramebuffer_instance = fb_instance; 51 /* Update RockboxFramebuffer_instance */
52 if (!e->IsSameObject(env, RockboxFramebuffer_instance, fb_instance)) {
53 if (RockboxFramebuffer_instance != NULL)
54 e->DeleteGlobalRef(env, RockboxFramebuffer_instance);
55
56 RockboxFramebuffer_instance = e->NewGlobalRef(env, fb_instance);
57 }
58
59 static bool have_class = false;
52 if (!have_class) 60 if (!have_class)
53 { 61 {
54 jclass fb_class = e->GetObjectClass(env, fb_instance); 62 jclass fb_class = e->GetObjectClass(env, fb_instance);
@@ -70,10 +78,13 @@ void connect_with_java(JNIEnv* env, jobject fb_instance)
70 java_lcd_init = e->GetMethodID(env, fb_class, 78 java_lcd_init = e->GetMethodID(env, fb_class,
71 "java_lcd_init", 79 "java_lcd_init",
72 "(IILjava/nio/ByteBuffer;)V"); 80 "(IILjava/nio/ByteBuffer;)V");
73 81
74 native_buffer = e->NewDirectByteBuffer(env, 82 jobject buffer = e->NewDirectByteBuffer(env,
75 lcd_framebuffer, 83 lcd_framebuffer,
76 (jlong)sizeof(lcd_framebuffer)); 84 (jlong)sizeof(lcd_framebuffer));
85
86 native_buffer = e->NewGlobalRef(env, buffer);
87
77 have_class = true; 88 have_class = true;
78 } 89 }
79 /* we need to setup parts for the java object every time */ 90 /* we need to setup parts for the java object every time */
@@ -81,6 +92,12 @@ void connect_with_java(JNIEnv* env, jobject fb_instance)
81 (jint)LCD_WIDTH, (jint)LCD_HEIGHT, native_buffer); 92 (jint)LCD_WIDTH, (jint)LCD_HEIGHT, native_buffer);
82} 93}
83 94
95void lcd_deinit(void)
96{
97 (*env_ptr)->DeleteGlobalRef(env_ptr, RockboxFramebuffer_instance);
98 (*env_ptr)->DeleteGlobalRef(env_ptr, native_buffer);
99}
100
84/* 101/*
85 * Do nothing here and connect with the java object later (if it isn't already) 102 * Do nothing here and connect with the java object later (if it isn't already)
86 */ 103 */
diff --git a/firmware/target/hosted/android/pcm-android.c b/firmware/target/hosted/android/pcm-android.c
index c8bc410a54..f4ed4b1b33 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;
35static jmethodID play_pause_method; 35static jmethodID play_pause_method;
36static jmethodID stop_method; 36static jmethodID stop_method;
37static jmethodID set_volume_method; 37static jmethodID set_volume_method;
38static jclass RockboxPCM_class;
39static jobject RockboxPCM_instance; 38static jobject RockboxPCM_instance;
40 39
41 40
@@ -155,10 +154,11 @@ void pcm_play_dma_init(void)
155 **/ 154 **/
156 JNIEnv e = *env_ptr; 155 JNIEnv e = *env_ptr;
157 /* get the class and its constructor */ 156 /* get the class and its constructor */
158 RockboxPCM_class = e->FindClass(env_ptr, "org/rockbox/RockboxPCM"); 157 jclass RockboxPCM_class = e->FindClass(env_ptr, "org/rockbox/RockboxPCM");
159 jmethodID constructor = e->GetMethodID(env_ptr, RockboxPCM_class, "<init>", "()V"); 158 jmethodID constructor = e->GetMethodID(env_ptr, RockboxPCM_class, "<init>", "()V");
160 /* instance = new RockboxPCM() */ 159 /* instance = new RockboxPCM() */
161 RockboxPCM_instance = e->NewObject(env_ptr, RockboxPCM_class, constructor); 160 jobject PCM_instance = e->NewObject(env_ptr, RockboxPCM_class, constructor);
161 RockboxPCM_instance = e->NewGlobalRef(env_ptr, PCM_instance);
162 /* cache needed methods */ 162 /* cache needed methods */
163 play_pause_method = e->GetMethodID(env_ptr, RockboxPCM_class, "play_pause", "(Z)V"); 163 play_pause_method = e->GetMethodID(env_ptr, RockboxPCM_class, "play_pause", "(Z)V");
164 set_volume_method = e->GetMethodID(env_ptr, RockboxPCM_class, "set_volume", "(I)V"); 164 set_volume_method = e->GetMethodID(env_ptr, RockboxPCM_class, "set_volume", "(I)V");
@@ -167,6 +167,11 @@ void pcm_play_dma_init(void)
167 pcm_play_get_more_callback((void*)&pcm_data_start, &pcm_data_size); 167 pcm_play_get_more_callback((void*)&pcm_data_start, &pcm_data_size);
168} 168}
169 169
170void pcm_deinit(void)
171{
172 (*env_ptr)->DeleteGlobalRef(env_ptr, RockboxPCM_instance);
173}
174
170void pcm_postinit(void) 175void pcm_postinit(void)
171{ 176{
172} 177}
diff --git a/firmware/target/hosted/android/system-android.c b/firmware/target/hosted/android/system-android.c
index 92c2d7cf5d..66de4e0ebb 100644
--- a/firmware/target/hosted/android/system-android.c
+++ b/firmware/target/hosted/android/system-android.c
@@ -36,10 +36,18 @@ uintptr_t *stackend;
36 36
37extern int main(void); 37extern int main(void);
38extern void telephony_init_device(void); 38extern void telephony_init_device(void);
39extern void lcd_deinit(void);
40extern void pcm_deinit(void);
39 41
40void system_exception_wait(void) { } 42void system_exception_wait(void) { }
41void system_reboot(void) { } 43void system_reboot(void) { }
42void power_off(void) { } 44
45void power_off(void)
46{
47 lcd_deinit();
48 pcm_deinit();
49 (*env_ptr)->DeleteGlobalRef(env_ptr, RockboxService_class);
50}
43 51
44void system_init(void) 52void system_init(void)
45{ 53{
@@ -51,18 +59,19 @@ void system_init(void)
51JNIEXPORT void JNICALL 59JNIEXPORT void JNICALL
52Java_org_rockbox_RockboxService_main(JNIEnv *env, jobject this) 60Java_org_rockbox_RockboxService_main(JNIEnv *env, jobject this)
53{ 61{
62 jclass class = (*env)->GetObjectClass(env, this);
63
54 /* hack!!! we can't have a valid stack pointer otherwise. 64 /* hack!!! we can't have a valid stack pointer otherwise.
55 * but we don't really need it anyway, thread.c only needs it 65 * but we don't really need it anyway, thread.c only needs it
56 * for overflow detection which doesn't apply for the main thread 66 * for overflow detection which doesn't apply for the main thread
57 * (it's managed by the OS) */ 67 * (it's managed by the OS) */
58 68
59 (void)env;
60 (void)this;
61 volatile uintptr_t stack = 0; 69 volatile uintptr_t stack = 0;
62 stackbegin = stackend = (uintptr_t*) &stack; 70 stackbegin = stackend = (uintptr_t*) &stack;
63 env_ptr = env; 71 env_ptr = env;
64 RockboxService_instance = this; 72
65 RockboxService_class = (*env)->GetObjectClass(env, this); 73 RockboxService_instance = (*env)->NewGlobalRef(env, this);
74 RockboxService_class = (*env)->NewGlobalRef(env, class);
66 75
67 main(); 76 main();
68} 77}