diff options
author | Thomas Martitz <kugel@rockbox.org> | 2011-02-23 01:10:54 +0000 |
---|---|---|
committer | Thomas Martitz <kugel@rockbox.org> | 2011-02-23 01:10:54 +0000 |
commit | 95e24dd7a54256e8df56e347c0f43133087a1df2 (patch) | |
tree | 677d66d4e72fedfe134bca103ed98b5792da1440 /firmware/target/hosted/android/lcd-android.c | |
parent | da3417706d927c7da0b59351fa8cc010d63d7928 (diff) | |
download | rockbox-95e24dd7a54256e8df56e347c0f43133087a1df2.tar.gz rockbox-95e24dd7a54256e8df56e347c0f43133087a1df2.zip |
Android:
* Re-create RockboxFramebuffer instance with every time there's a new Activity.
* Also, allow Rockbox to be started via multimedia buttons, immediately starting playback if wanted.
We don't need to keep the fb instance around when it backround, and it makes us less depending on it and the activity (less race conditions). And this is how you usually do it in Android apps.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29384 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/target/hosted/android/lcd-android.c')
-rw-r--r-- | firmware/target/hosted/android/lcd-android.c | 99 |
1 files changed, 48 insertions, 51 deletions
diff --git a/firmware/target/hosted/android/lcd-android.c b/firmware/target/hosted/android/lcd-android.c index f719329819..c9bd0a1254 100644 --- a/firmware/target/hosted/android/lcd-android.c +++ b/firmware/target/hosted/android/lcd-android.c | |||
@@ -29,68 +29,63 @@ | |||
29 | #include "button.h" | 29 | #include "button.h" |
30 | 30 | ||
31 | extern JNIEnv *env_ptr; | 31 | extern JNIEnv *env_ptr; |
32 | extern jclass RockboxService_class; | ||
33 | extern jobject RockboxService_instance; | 32 | extern jobject RockboxService_instance; |
34 | 33 | ||
35 | static jclass RockboxFramebuffer_class; | ||
36 | static jobject RockboxFramebuffer_instance; | 34 | static jobject RockboxFramebuffer_instance; |
37 | static jmethodID java_lcd_update; | 35 | static jmethodID java_lcd_update; |
38 | static jmethodID java_lcd_update_rect; | 36 | static jmethodID java_lcd_update_rect; |
37 | static jmethodID java_lcd_init; | ||
38 | static jobject native_buffer; | ||
39 | 39 | ||
40 | static int dpi; | 40 | static int dpi; |
41 | static int scroll_threshold; | 41 | static int scroll_threshold; |
42 | static bool display_on; | 42 | static bool display_on; |
43 | 43 | ||
44 | void lcd_init_device(void) | 44 | /* this might actually be called before lcd_init_device() or even main(), so |
45 | * be sure to only access static storage initalized at library loading, | ||
46 | * and not more */ | ||
47 | void connect_with_java(JNIEnv* env, jobject fb_instance) | ||
45 | { | 48 | { |
46 | JNIEnv e = *env_ptr; | 49 | JNIEnv e = *env; |
47 | /* get existing instance from the Service */ | 50 | static bool have_class; |
48 | jmethodID get_fb = e->GetMethodID(env_ptr, RockboxService_class, "get_fb", | 51 | RockboxFramebuffer_instance = fb_instance; |
49 | "()Lorg/rockbox/RockboxFramebuffer;"); | 52 | if (!have_class) |
50 | RockboxFramebuffer_instance = e->CallObjectMethod(env_ptr, | 53 | { |
51 | RockboxService_instance, | 54 | jclass fb_class = e->GetObjectClass(env, fb_instance); |
52 | get_fb); | 55 | /* cache update functions */ |
53 | RockboxFramebuffer_class = (*env_ptr)->GetObjectClass(env_ptr, | 56 | java_lcd_update = e->GetMethodID(env, fb_class, |
54 | RockboxFramebuffer_instance); | 57 | "java_lcd_update", |
55 | 58 | "()V"); | |
56 | /* Get init function and set up what's left from the constructor */ | 59 | java_lcd_update_rect = e->GetMethodID(env, fb_class, |
57 | jmethodID java_lcd_init = (*env_ptr)->GetMethodID(env_ptr, | 60 | "java_lcd_update_rect", |
58 | RockboxFramebuffer_class, | 61 | "(IIII)V"); |
59 | "java_lcd_init", | 62 | jmethodID get_dpi = e->GetMethodID(env, fb_class, |
60 | "(IILjava/nio/ByteBuffer;)V"); | 63 | "getDpi", "()I"); |
61 | 64 | jmethodID thresh = e->GetMethodID(env, fb_class, | |
62 | jobject buf = e->NewDirectByteBuffer(env_ptr, | 65 | "getScrollThreshold", "()I"); |
66 | /* these don't change with new instances so call them now */ | ||
67 | dpi = e->CallIntMethod(env, fb_instance, get_dpi); | ||
68 | scroll_threshold = e->CallIntMethod(env, fb_instance, thresh); | ||
69 | |||
70 | java_lcd_init = e->GetMethodID(env, fb_class, | ||
71 | "java_lcd_init", | ||
72 | "(IILjava/nio/ByteBuffer;)V"); | ||
73 | |||
74 | native_buffer = e->NewDirectByteBuffer(env, | ||
63 | lcd_framebuffer, | 75 | lcd_framebuffer, |
64 | (jlong)sizeof(lcd_framebuffer)); | 76 | (jlong)sizeof(lcd_framebuffer)); |
77 | have_class = true; | ||
78 | } | ||
79 | /* we need to setup parts for the java object every time */ | ||
80 | (*env)->CallVoidMethod(env, fb_instance, java_lcd_init, | ||
81 | (jint)LCD_WIDTH, (jint)LCD_HEIGHT, native_buffer); | ||
82 | } | ||
65 | 83 | ||
66 | e->CallVoidMethod(env_ptr, RockboxFramebuffer_instance, java_lcd_init, | 84 | /* |
67 | (jint)LCD_WIDTH, | 85 | * Do nothing here and connect with the java object later (if it isn't already) |
68 | (jint)LCD_HEIGHT, | 86 | */ |
69 | buf); | 87 | void lcd_init_device(void) |
70 | 88 | { | |
71 | /* cache update functions */ | ||
72 | java_lcd_update = (*env_ptr)->GetMethodID(env_ptr, | ||
73 | RockboxFramebuffer_class, | ||
74 | "java_lcd_update", | ||
75 | "()V"); | ||
76 | java_lcd_update_rect = (*env_ptr)->GetMethodID(env_ptr, | ||
77 | RockboxFramebuffer_class, | ||
78 | "java_lcd_update_rect", | ||
79 | "(IIII)V"); | ||
80 | |||
81 | jmethodID get_dpi = e->GetMethodID(env_ptr, | ||
82 | RockboxFramebuffer_class, | ||
83 | "getDpi", "()I"); | ||
84 | |||
85 | jmethodID get_scroll_threshold | ||
86 | = e->GetMethodID(env_ptr, | ||
87 | RockboxFramebuffer_class, | ||
88 | "getScrollThreshold", "()I"); | ||
89 | |||
90 | dpi = e->CallIntMethod(env_ptr, RockboxFramebuffer_instance, | ||
91 | get_dpi); | ||
92 | scroll_threshold = e->CallIntMethod(env_ptr, RockboxFramebuffer_instance, | ||
93 | get_scroll_threshold); | ||
94 | /* must not draw until surface is created */ | 89 | /* must not draw until surface is created */ |
95 | display_on = false; | 90 | display_on = false; |
96 | } | 91 | } |
@@ -116,12 +111,14 @@ void lcd_update_rect(int x, int y, int width, int height) | |||
116 | * Note this is considered interrupt context | 111 | * Note this is considered interrupt context |
117 | */ | 112 | */ |
118 | JNIEXPORT void JNICALL | 113 | JNIEXPORT void JNICALL |
119 | Java_org_rockbox_RockboxFramebuffer_surfaceCreated(JNIEnv *e, jobject this, | 114 | Java_org_rockbox_RockboxFramebuffer_surfaceCreated(JNIEnv *env, jobject this, |
120 | jobject surfaceholder) | 115 | jobject surfaceholder) |
121 | { | 116 | { |
122 | (void)e; (void)this; (void)surfaceholder; | 117 | (void)surfaceholder; |
123 | 118 | /* possibly a new instance - reconnect */ | |
119 | connect_with_java(env, this); | ||
124 | display_on = true; | 120 | display_on = true; |
121 | |||
125 | send_event(LCD_EVENT_ACTIVATION, NULL); | 122 | send_event(LCD_EVENT_ACTIVATION, NULL); |
126 | /* Force an update, since the newly created surface is initially black | 123 | /* Force an update, since the newly created surface is initially black |
127 | * waiting for the next normal update results in a longish black screen */ | 124 | * waiting for the next normal update results in a longish black screen */ |