diff options
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/target/hosted/android/button-android.c | 8 | ||||
-rw-r--r-- | firmware/target/hosted/android/lcd-android.c | 99 |
2 files changed, 54 insertions, 53 deletions
diff --git a/firmware/target/hosted/android/button-android.c b/firmware/target/hosted/android/button-android.c index 832eef54f3..ed1e125223 100644 --- a/firmware/target/hosted/android/button-android.c +++ b/firmware/target/hosted/android/button-android.c | |||
@@ -29,6 +29,7 @@ | |||
29 | #include "system.h" | 29 | #include "system.h" |
30 | #include "touchscreen.h" | 30 | #include "touchscreen.h" |
31 | 31 | ||
32 | extern JNIEnv *env_ptr; | ||
32 | static int last_y, last_x; | 33 | static int last_y, last_x; |
33 | static int last_btns; | 34 | static int last_btns; |
34 | 35 | ||
@@ -61,11 +62,11 @@ Java_org_rockbox_RockboxFramebuffer_touchHandler(JNIEnv*env, jobject this, | |||
61 | * this writes in an interrupt-like fashion the button events that the user | 62 | * this writes in an interrupt-like fashion the button events that the user |
62 | * generated by pressing/releasing them to a variable */ | 63 | * generated by pressing/releasing them to a variable */ |
63 | JNIEXPORT bool JNICALL | 64 | JNIEXPORT bool JNICALL |
64 | Java_org_rockbox_RockboxFramebuffer_buttonHandler(JNIEnv*env, jclass this, | 65 | Java_org_rockbox_RockboxFramebuffer_buttonHandler(JNIEnv*env, jclass class, |
65 | jint keycode, jboolean state) | 66 | jint keycode, jboolean state) |
66 | { | 67 | { |
67 | (void)env; | 68 | (void)env; |
68 | (void)this; | 69 | (void)class; |
69 | 70 | ||
70 | unsigned button = 0; | 71 | unsigned button = 0; |
71 | 72 | ||
@@ -75,7 +76,10 @@ Java_org_rockbox_RockboxFramebuffer_buttonHandler(JNIEnv*env, jclass this, | |||
75 | if (!button) | 76 | if (!button) |
76 | button = dpad_to_button((int)keycode); | 77 | button = dpad_to_button((int)keycode); |
77 | if (button) | 78 | if (button) |
79 | { | ||
78 | queue_post(&button_queue, button, 0); | 80 | queue_post(&button_queue, button, 0); |
81 | return true; | ||
82 | } | ||
79 | } | 83 | } |
80 | 84 | ||
81 | if (!button) | 85 | if (!button) |
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 */ |