Skip to content

Commit 9a92a53

Browse files
committed
simulator mvp
1 parent 61b80f0 commit 9a92a53

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

simulator/simulator.c

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ int droidboot_internal_get_display_width()
2626

2727
JNIEXPORT void simulator_start(JNIEnv* env, jobject bitmap, jint w, jint h) {
2828
(*env)->GetJavaVM(env, &s_simulator_jvm);
29-
s_simulator_bitmap = bitmap;
29+
s_simulator_bitmap = (*env)->NewGlobalRef(env, bitmap);
3030
s_simulator_h = h;
3131
s_simulator_w = w;
3232
droidboot_init();
@@ -47,26 +47,24 @@ void droidboot_internal_fb_flush(lv_disp_drv_t * disp_drv, const lv_area_t * are
4747
if ((ret = (*s_simulator_jvm)->GetEnv(s_simulator_jvm, (void **) &env, JNI_VERSION_1_6)) != JNI_OK) {
4848
__android_log_print(ANDROID_LOG_ERROR, "droidboot", "failed to get jni env: %d", ret);
4949
}
50-
void *addr;
51-
while (!(ret = AndroidBitmap_lockPixels(env, s_simulator_bitmap, &addr))) {
50+
uint32_t *addr;
51+
while ((ret = AndroidBitmap_lockPixels(env, s_simulator_bitmap, (void **) &addr)) != ANDROID_BITMAP_RESULT_SUCCESS) {
5252
__android_log_print(ANDROID_LOG_ERROR, "droidboot", "failed to lock bitmap (%d), trying again", ret);
5353
usleep(10000);
5454
}
55-
__android_log_print(ANDROID_LOG_VERBOSE, "droidboot", "locked fb %p", addr);
56-
int w = area->x2 - area->x1 + 1;
57-
long int location = 0;
58-
// TODO fix segv :)
59-
for(int32_t y = area->y1; y <= area->y2; y++) {
60-
location = (area->x1 + 0) + (y + 0) * s_simulator_w;
61-
//memcpy(&addr[location], color_p, w);
62-
color_p += w;
55+
//__android_log_print(ANDROID_LOG_VERBOSE, "droidboot", "locked fb %p", addr);
56+
for (uint32_t y = area->y1; y <= area->y2; y++) {
57+
for (uint32_t x = area->x1; x <= area->x2; x++) {
58+
addr[(y*s_simulator_w)+x] = 0xff << 24 | color_p->ch.blue << 16 | color_p->ch.green << 8 | color_p->ch.red;
59+
color_p++;
60+
}
6361
}
6462

65-
while (!(ret = AndroidBitmap_unlockPixels(env, s_simulator_bitmap))) {
63+
while ((ret = AndroidBitmap_unlockPixels(env, s_simulator_bitmap)) != ANDROID_BITMAP_RESULT_SUCCESS) {
6664
__android_log_print(ANDROID_LOG_ERROR, "droidboot", "failed to unlock bitmap (%d), trying again", ret);
6765
usleep(10000);
6866
}
69-
__android_log_print(ANDROID_LOG_VERBOSE, "droidboot", "unlocked fb %p", addr);
67+
//__android_log_print(ANDROID_LOG_VERBOSE, "droidboot", "unlocked fb %p", addr);
7068
}
7169
// Inform the graphics library that we are ready with the flushing
7270
lv_disp_flush_ready(disp_drv);
@@ -129,7 +127,7 @@ uint64_t droidboot_internal_sd_blkcnt()
129127

130128
bool droidboot_internal_sd_exists()
131129
{
132-
return false; // TODO
130+
return true;
133131
}
134132

135133
bool droidboot_internal_have_fallback()
@@ -148,6 +146,7 @@ static void* droidboot_lv_tick_inc_thread(void * arg) {
148146
JavaVMAttachArgs args;
149147
args.version = JNI_VERSION_1_6;
150148
args.name = "lv_tick_inc_thread";
149+
args.group = NULL;
151150
JNIEnv* env;
152151
(*s_simulator_jvm)->AttachCurrentThread(s_simulator_jvm, &env, &args);
153152
while (s_simulator_running) {
@@ -165,6 +164,7 @@ static void* droidboot_lv_timer_handler_thread(void * arg) {
165164
JavaVMAttachArgs args;
166165
args.version = JNI_VERSION_1_6;
167166
args.name = "lv_timer_handler_thread";
167+
args.group = NULL;
168168
JNIEnv* env;
169169
(*s_simulator_jvm)->AttachCurrentThread(s_simulator_jvm, &env, &args);
170170
while (s_simulator_running) {
@@ -181,12 +181,13 @@ void droidboot_internal_lvgl_threads_init()
181181
pthread_create(&t2, NULL, droidboot_lv_timer_handler_thread, NULL);
182182
}
183183

184-
JNIEXPORT void simulator_stop()
184+
JNIEXPORT void simulator_stop(JNIEnv* env)
185185
{
186186
s_simulator_running = false;
187187
pthread_join(t, NULL);
188188
pthread_join(t2, NULL);
189189
s_simulator_jvm = NULL;
190+
(*env)->DeleteGlobalRef(env, s_simulator_bitmap);
190191
s_simulator_bitmap = NULL;
191192
}
192193

0 commit comments

Comments
 (0)