1010static pthread_t t , t2 ;
1111static bool s_simulator_running , s_simulator_vol_down_pressed , s_simulator_vol_up_pressed , s_simulator_pwr_pressed ;
1212static uint32_t last_pressed_key ;
13- static JNIEnv * s_simulator_jnienv ;
13+ static JavaVM * s_simulator_jvm ;
1414static jobject s_simulator_bitmap ;
1515static jint s_simulator_h , s_simulator_w ;
1616
@@ -25,7 +25,7 @@ int droidboot_internal_get_display_width()
2525}
2626
2727JNIEXPORT void simulator_start (JNIEnv * env , jobject bitmap , jint w , jint h ) {
28- s_simulator_jnienv = env ;
28+ ( * env ) -> GetJavaVM ( env , & s_simulator_jvm ) ;
2929 s_simulator_bitmap = bitmap ;
3030 s_simulator_h = h ;
3131 s_simulator_w = w ;
@@ -42,26 +42,30 @@ JNIEXPORT void simulator_key(jint key) {
4242void droidboot_internal_fb_flush (lv_disp_drv_t * disp_drv , const lv_area_t * area , lv_color_t * color_p )
4343{
4444 if (s_simulator_bitmap != NULL ) {
45+ JNIEnv * env ;
46+ (* s_simulator_jvm )-> GetEnv (s_simulator_jvm , (void * * ) & env , JNI_VERSION_1_6 );
4547 void * addr ;
46- while (!AndroidBitmap_lockPixels (s_simulator_jnienv , s_simulator_bitmap , & addr )) {
48+ while (!AndroidBitmap_lockPixels (env , s_simulator_bitmap , & addr )) {
4749 droidboot_internal_platform_system_log ("failed locking bitmap, trying again" );
4850 usleep (10000 );
4951 }
52+ __android_log_print (ANDROID_LOG_VERBOSE , "droidboot" , "locked fb %p" , addr );
5053 int w = (area -> x2 - area -> x1 + 1 );
5154 long int location = 0 ;
5255 long int byte_location = 0 ;
5356 unsigned char bit_location = 0 ;
5457 int32_t y ;
5558 for (y = area -> y1 ; y <= area -> y2 ; y ++ ) {
56- location = (area -> x1 + 0 ) + (y + 0 ) * droidboot_internal_get_display_width ();
57- memcpy (& addr [location ], (uint32_t * ) color_p , ( area -> x2 - area -> y2 + 1 ) * 4 );
59+ location = (( area -> x1 + 0 ) + (y + 0 ) * droidboot_internal_get_display_width ()) * 4 ;
60+ memcpy (& addr [location ], (uint32_t * ) color_p , w * 4 );
5861 color_p += w ;
5962 }
6063
61- while (!AndroidBitmap_unlockPixels (s_simulator_jnienv , s_simulator_bitmap )) {
64+ while (!AndroidBitmap_unlockPixels (env , s_simulator_bitmap )) {
6265 droidboot_internal_platform_system_log ("failed unlocking bitmap, trying again" );
6366 usleep (10000 );
6467 }
68+ __android_log_print (ANDROID_LOG_VERBOSE , "droidboot" , "unlocked fb %p" , addr );
6569 }
6670 // Inform the graphics library that we are ready with the flushing
6771 lv_disp_flush_ready (disp_drv );
@@ -140,21 +144,25 @@ bool droidboot_internal_use_double_buffering()
140144//lvgl thread
141145static void * droidboot_lv_tick_inc_thread (void * arg ) {
142146 /*Handle LitlevGL tick*/
147+ (* s_simulator_jvm )-> AttachCurrentThread (s_simulator_jvm , NULL , NULL );
143148 while (s_simulator_running ) {
144149 sleep (1 );
145150 lv_tick_inc (1 );
146151 //lv_timer_handler();
147152 }
153+ (* s_simulator_jvm )-> DetachCurrentThread (s_simulator_jvm );
148154 return 0 ;
149155}
150156
151157//lvgl thread
152158static void * droidboot_lv_timer_handler_thread (void * arg ) {
153159 /*Handle LitlevGL tick*/
160+ (* s_simulator_jvm )-> AttachCurrentThread (s_simulator_jvm , NULL , NULL );
154161 while (s_simulator_running ) {
155162 sleep (1 );
156163 lv_timer_handler ();
157164 }
165+ (* s_simulator_jvm )-> DetachCurrentThread (s_simulator_jvm );
158166 return 0 ;
159167}
160168
@@ -169,8 +177,8 @@ JNIEXPORT void simulator_stop()
169177 s_simulator_running = false;
170178 pthread_join (t , NULL );
171179 pthread_join (t2 , NULL );
180+ s_simulator_jvm = NULL ;
172181 s_simulator_bitmap = NULL ;
173- s_simulator_jnienv = NULL ;
174182}
175183
176184void droidboot_internal_platform_on_screen_log (const char * buf )
0 commit comments