11#include <stdio.h>
22#include "simulator.h"
3+ #include "droidboot_main.h"
34#include <android/log.h>
45#include <unistd.h>
6+ #include <pthread.h>
7+ #include <android/bitmap.h>
8+ #include <jni.h>
59
6- void droidboot_internal_fb_flush (lv_disp_drv_t * disp_drv , const lv_area_t * area , lv_color_t * color_p )
7- {
8- // TODO
9- }
10+ static pthread_t t , t2 ;
11+ static bool s_simulator_running , s_simulator_vol_down_pressed , s_simulator_vol_up_pressed , s_simulator_pwr_pressed ;
12+ static uint32_t last_pressed_key ;
13+ static JNIEnv * s_simulator_jnienv ;
14+ static jobject s_simulator_bitmap ;
15+ static jint s_simulator_h , s_simulator_w ;
1016
1117int droidboot_internal_get_display_height ()
1218{
13- return 1920 ; // TODO
19+ return s_simulator_h ;
1420}
1521
1622int droidboot_internal_get_display_width ()
1723{
18- return 1080 ; // TODO
24+ return s_simulator_w ;
25+ }
26+
27+ JNIEXPORT void simulator_start (JNIEnv * env , jobject bitmap , jint w , jint h ) {
28+ s_simulator_jnienv = env ;
29+ s_simulator_bitmap = bitmap ;
30+ s_simulator_h = h ;
31+ s_simulator_w = w ;
32+ droidboot_init ();
33+ droidboot_show_dualboot_menu ();
1934}
2035
21- void droidboot_internal_key_read (lv_indev_drv_t * drv , lv_indev_data_t * data )
36+ JNIEXPORT void simulator_key (jint key ) {
37+ s_simulator_vol_down_pressed = key == 1 ;
38+ s_simulator_vol_up_pressed = key == 2 ;
39+ s_simulator_pwr_pressed = key == 3 ;
40+ }
41+
42+ void droidboot_internal_fb_flush (lv_disp_drv_t * disp_drv , const lv_area_t * area , lv_color_t * color_p )
2243{
23- // TODO
44+ if (s_simulator_bitmap != NULL ) {
45+ void * addr ;
46+ while (!AndroidBitmap_lockPixels (s_simulator_jnienv , s_simulator_bitmap , & addr )) {
47+ droidboot_internal_platform_system_log ("failed locking bitmap, trying again" );
48+ usleep (10000 );
49+ }
50+ int w = (area -> x2 - area -> x1 + 1 );
51+ long int location = 0 ;
52+ long int byte_location = 0 ;
53+ unsigned char bit_location = 0 ;
54+ int32_t y ;
55+ 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 );
58+ color_p += w ;
59+ }
60+
61+ while (!AndroidBitmap_unlockPixels (s_simulator_jnienv , s_simulator_bitmap )) {
62+ droidboot_internal_platform_system_log ("failed unlocking bitmap, trying again" );
63+ usleep (10000 );
64+ }
65+ }
66+ // Inform the graphics library that we are ready with the flushing
67+ lv_disp_flush_ready (disp_drv );
68+ }
69+
70+ //Read keys state
71+ void droidboot_internal_key_read (lv_indev_drv_t * drv , lv_indev_data_t * data )
72+ {
73+ if (s_simulator_vol_up_pressed ){
74+ data -> key = LV_KEY_PREV ;
75+ last_pressed_key = LV_KEY_PREV ;
76+ data -> state = LV_INDEV_STATE_PRESSED ;
77+ } else if (s_simulator_vol_down_pressed ){
78+ data -> key = LV_KEY_NEXT ;
79+ last_pressed_key = LV_KEY_NEXT ;
80+ data -> state = LV_INDEV_STATE_PRESSED ;
81+ } else if (s_simulator_pwr_pressed ){
82+ data -> key = LV_KEY_ENTER ;
83+ last_pressed_key = LV_KEY_ENTER ;
84+ data -> state = LV_INDEV_STATE_PRESSED ;
85+ } else {
86+ data -> key = last_pressed_key ;
87+ data -> state = LV_INDEV_STATE_RELEASED ;
88+ }
2489}
2590
2691droidboot_error droidboot_internal_platform_init ()
2792{
93+ s_simulator_running = true;
2894 return DROIDBOOT_EOK ;
2995}
3096
3197ssize_t dridboot_internal_sd_read_block (void * buf , uint32_t block , uint count )
3298{
99+ if (!droidboot_internal_sd_exists ())
100+ return 0 ;
33101 return 0 ; // TODO
34102}
35103
36104ssize_t dridboot_internal_sd_write_block (const void * buf , uint32_t block , uint count )
37105{
106+ if (!droidboot_internal_sd_exists ())
107+ return 0 ;
38108 return 0 ; // TODO
39109}
40110
41111uint32_t droidboot_internal_sd_blklen ()
42112{
113+ if (!droidboot_internal_sd_exists ())
114+ return 0 ;
43115 return 0 ; // TODO
44116}
45117
46118uint64_t droidboot_internal_sd_blkcnt ()
47119{
120+ if (!droidboot_internal_sd_exists ())
121+ return 0 ;
48122 return 0 ; // TODO
49123}
50124
@@ -58,21 +132,46 @@ bool droidboot_internal_have_fallback()
58132 return true;
59133}
60134
61- int droidboot_internal_get_disp_buffer_height ()
135+ bool droidboot_internal_use_double_buffering ()
62136{
137+ return true;
138+ }
139+
140+ //lvgl thread
141+ static void * droidboot_lv_tick_inc_thread (void * arg ) {
142+ /*Handle LitlevGL tick*/
143+ while (s_simulator_running ) {
144+ sleep (1 );
145+ lv_tick_inc (1 );
146+ //lv_timer_handler();
147+ }
63148 return 0 ;
64149}
65150
66- bool droidboot_internal_use_double_buffering ()
67- {
68- return true;
151+ //lvgl thread
152+ static void * droidboot_lv_timer_handler_thread (void * arg ) {
153+ /*Handle LitlevGL tick*/
154+ while (s_simulator_running ) {
155+ sleep (1 );
156+ lv_timer_handler ();
157+ }
158+ return 0 ;
69159}
70160
71161void droidboot_internal_lvgl_threads_init ()
72162{
73- // TODO
163+ pthread_create (& t , NULL , droidboot_lv_tick_inc_thread , NULL );
164+ pthread_create (& t2 , NULL , droidboot_lv_timer_handler_thread , NULL );
74165}
75166
167+ JNIEXPORT void simulator_stop ()
168+ {
169+ s_simulator_running = false;
170+ pthread_join (t , NULL );
171+ pthread_join (t2 , NULL );
172+ s_simulator_bitmap = NULL ;
173+ s_simulator_jnienv = NULL ;
174+ }
76175
77176void droidboot_internal_platform_on_screen_log (const char * buf )
78177{
@@ -86,7 +185,7 @@ void droidboot_internal_platform_system_log(const char *buf)
86185
87186void droidboot_internal_delay (unsigned int time )
88187{
89- sleep (time );
188+ usleep (time * 1000 );
90189}
91190
92191void droidboot_internal_boot_linux_from_ram (void * kernel_raw , off_t kernel_raw_size , void * ramdisk_raw , off_t ramdisk_size , void * dtb_raw , off_t dtb_raw_size , void * dtbo_raw , off_t dtbo_raw_size , char * options )
@@ -118,11 +217,14 @@ void *droidboot_internal_get_dtbo_load_addr()
118217{
119218 return NULL ;
120219}
220+
121221bool droidboot_internal_append_ramdisk_to_kernel ()
122222{
123223 return true;
124224}
125225
226+ // Nothing to do here, we have threads
126227void droidboot_internal_platform_tasks ()
127228{
128- }
229+ usleep (200000 );
230+ }
0 commit comments