1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (c) 2010 Thomas Martitz
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
31 extern JNIEnv
*env_ptr
;
32 extern jobject RockboxService_instance
;
34 static jobject RockboxFramebuffer_instance
;
35 static jmethodID java_lcd_update
;
36 static jmethodID java_lcd_update_rect
;
37 static jmethodID java_lcd_init
;
40 static int scroll_threshold
;
41 static bool display_on
;
43 /* this might actually be called before lcd_init_device() or even main(), so
44 * be sure to only access static storage initalized at library loading,
46 void connect_with_java(JNIEnv
* env
, jobject fb_instance
)
49 static bool have_class
;
53 jclass fb_class
= e
->GetObjectClass(env
, fb_instance
);
54 /* cache update functions */
55 java_lcd_update
= e
->GetMethodID(env
, fb_class
,
58 java_lcd_update_rect
= e
->GetMethodID(env
, fb_class
,
59 "java_lcd_update_rect",
61 jmethodID get_dpi
= e
->GetMethodID(env
, fb_class
,
63 jmethodID thresh
= e
->GetMethodID(env
, fb_class
,
64 "getScrollThreshold", "()I");
65 /* these don't change with new instances so call them now */
66 dpi
= e
->CallIntMethod(env
, fb_instance
, get_dpi
);
67 scroll_threshold
= e
->CallIntMethod(env
, fb_instance
, thresh
);
69 java_lcd_init
= e
->GetMethodID(env
, fb_class
,
71 "(IILjava/nio/ByteBuffer;)V");
76 /* Create native_buffer */
77 jobject buffer
= (*env
)->NewDirectByteBuffer(env
, lcd_framebuffer
,
78 (jlong
) FRAMEBUFFER_SIZE
);
80 /* we need to setup parts for the java object every time */
81 (*env
)->CallVoidMethod(env
, fb_instance
, java_lcd_init
,
82 (jint
)LCD_WIDTH
, (jint
)LCD_HEIGHT
, buffer
);
86 * Do nothing here and connect with the java object later (if it isn't already)
88 void lcd_init_device(void)
95 (*env_ptr
)->CallVoidMethod(env_ptr
, RockboxFramebuffer_instance
,
99 void lcd_update_rect(int x
, int y
, int width
, int height
)
102 (*env_ptr
)->CallVoidMethod(env_ptr
, RockboxFramebuffer_instance
,
103 java_lcd_update_rect
, x
, y
, width
, height
);
107 * this is called when the surface is created, which called is everytime
108 * the activity is brought in front and the RockboxFramebuffer gains focus
110 * Note this is considered interrupt context
112 JNIEXPORT
void JNICALL
113 Java_org_rockbox_RockboxFramebuffer_surfaceCreated(JNIEnv
*env
, jobject
this,
114 jobject surfaceholder
)
118 /* Update RockboxFramebuffer_instance */
119 RockboxFramebuffer_instance
= (*env
)->NewGlobalRef(env
, this);
121 /* possibly a new instance - reconnect */
122 connect_with_java(env
, this);
125 /* need to wait for button_queue to be valid to post to */
126 wait_rockbox_ready();
128 send_event(LCD_EVENT_ACTIVATION
, NULL
);
129 /* Force an update, since the newly created surface is initially black
130 * waiting for the next normal update results in a longish black screen */
131 queue_post(&button_queue
, BUTTON_FORCE_REDRAW
, 0);
135 * the surface is destroyed everytime the RockboxFramebuffer loses focus and
138 JNIEXPORT
void JNICALL
139 Java_org_rockbox_RockboxFramebuffer_surfaceDestroyed(JNIEnv
*e
, jobject
this,
140 jobject surfaceholder
)
142 (void)this; (void)surfaceholder
;
146 (*e
)->DeleteGlobalRef(e
, RockboxFramebuffer_instance
);
147 RockboxFramebuffer_instance
= NULL
;
150 bool lcd_active(void)
155 int lcd_get_dpi(void)
160 int touchscreen_get_scroll_threshold(void)
162 return scroll_threshold
;