summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Soffke <christian.soffke@gmail.com>2024-12-26 12:11:55 +0100
committerChristian Soffke <christian.soffke@gmail.com>2024-12-26 12:24:24 +0100
commitfa8b095f292f369168741e94d7c394bc5358fec3 (patch)
tree16dcd64139751081a3334a540d35744bf0cb66a7
parent0a88b818e96b33bbb50ed7b434b761672b93a21b (diff)
downloadrockbox-fa8b095f29.tar.gz
rockbox-fa8b095f29.zip
sdl: fix: concurrent drawing on Windows
On Windows, we need to prevent the event thread from drawing at the same time as the main thread, when window is being adjusted. Change-Id: I2b4e4a50fec427e53e310593850e2a556a594b31
-rw-r--r--firmware/target/hosted/sdl/button-sdl.c6
-rw-r--r--firmware/target/hosted/sdl/lcd-sdl.c4
-rw-r--r--firmware/target/hosted/sdl/system-sdl.c2
-rw-r--r--firmware/target/hosted/sdl/window-sdl.c3
-rw-r--r--firmware/target/hosted/sdl/window-sdl.h3
5 files changed, 18 insertions, 0 deletions
diff --git a/firmware/target/hosted/sdl/button-sdl.c b/firmware/target/hosted/sdl/button-sdl.c
index 04d8cf6eae..f83f1d6693 100644
--- a/firmware/target/hosted/sdl/button-sdl.c
+++ b/firmware/target/hosted/sdl/button-sdl.c
@@ -243,7 +243,9 @@ static bool event_handler(SDL_Event *event)
sdl_app_has_input_focus = 0;
else if(event->window.event == SDL_WINDOWEVENT_RESIZED)
{
+ SDL_LockMutex(window_mutex);
sdl_window_adjustment_needed(false);
+ SDL_UnlockMutex(window_mutex);
#if !defined (__APPLE__) && !defined(__WIN32)
static unsigned long last_tick;
if (TIME_AFTER(current_tick, last_tick + HZ/20) && !button_queue_full())
@@ -354,8 +356,10 @@ static void button_event(int key, bool pressed)
case SDLK_TAB:
if (!pressed)
{
+ SDL_LockMutex(window_mutex);
background = !background;
sdl_window_adjustment_needed(true);
+ SDL_UnlockMutex(window_mutex);
#if !defined(__WIN32) && !defined (__APPLE__)
button_queue_post(SDLK_UNKNOWN, 0); /* update window on main thread */
#endif
@@ -375,12 +379,14 @@ static void button_event(int key, bool pressed)
display_zoom = 0;
return;
}
+ SDL_LockMutex(window_mutex);
if (!display_zoom)
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY,
strcmp(SDL_GetHint(SDL_HINT_RENDER_SCALE_QUALITY) ?:
"best", "best") ? "best": "nearest");
sdl_window_adjustment_needed(!display_zoom);
+ SDL_UnlockMutex(window_mutex);
#if !defined(__WIN32) && !defined (__APPLE__)
button_queue_post(SDLK_UNKNOWN, 0); /* update window on main thread */
#endif
diff --git a/firmware/target/hosted/sdl/lcd-sdl.c b/firmware/target/hosted/sdl/lcd-sdl.c
index c340dff798..0731403f87 100644
--- a/firmware/target/hosted/sdl/lcd-sdl.c
+++ b/firmware/target/hosted/sdl/lcd-sdl.c
@@ -102,6 +102,9 @@ void sdl_gui_update(SDL_Surface *surface, int x_start, int y_start, int width,
SDL_Rect dest= {ui_x + x_start, ui_y + y_start, width, height};
uint8_t alpha;
+
+ SDL_LockMutex(window_mutex);
+
if (SDL_GetSurfaceAlphaMod(surface,&alpha) == 0 && alpha < 255)
SDL_FillRect(sim_lcd_surface, NULL, 0); /* alpha needs a black background */
@@ -111,6 +114,7 @@ void sdl_gui_update(SDL_Surface *surface, int x_start, int y_start, int width,
if (!sdl_window_adjust()) /* already calls sdl_window_render itself */
sdl_window_render();
+ SDL_UnlockMutex(window_mutex);
}
/* set a range of bitmap indices to a gradient from startcolour to endcolour */
diff --git a/firmware/target/hosted/sdl/system-sdl.c b/firmware/target/hosted/sdl/system-sdl.c
index 5d3622dd80..246a6541f7 100644
--- a/firmware/target/hosted/sdl/system-sdl.c
+++ b/firmware/target/hosted/sdl/system-sdl.c
@@ -175,6 +175,8 @@ void power_off(void)
void sim_do_exit()
{
sim_kernel_shutdown();
+ SDL_UnlockMutex(window_mutex);
+ SDL_DestroyMutex(window_mutex);
SDL_Quit();
exit(EXIT_SUCCESS);
diff --git a/firmware/target/hosted/sdl/window-sdl.c b/firmware/target/hosted/sdl/window-sdl.c
index ffea4e0b10..11b3880c59 100644
--- a/firmware/target/hosted/sdl/window-sdl.c
+++ b/firmware/target/hosted/sdl/window-sdl.c
@@ -33,6 +33,8 @@ extern SDL_Surface *remote_surface;
SDL_Texture *gui_texture;
SDL_Surface *sim_lcd_surface;
+SDL_mutex *window_mutex;
+
static SDL_Window *window;
static SDL_Renderer *sdlRenderer;
static SDL_Surface *picture_surface;
@@ -220,4 +222,5 @@ void sdl_window_setup(void)
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, display_zoom == 1 ? "best" : "nearest");
display_zoom = 0; /* reset to 0 unless/until user requests a scale level change */
+ window_mutex = SDL_CreateMutex();
}
diff --git a/firmware/target/hosted/sdl/window-sdl.h b/firmware/target/hosted/sdl/window-sdl.h
index 9b2dc6b14d..9f2d920a56 100644
--- a/firmware/target/hosted/sdl/window-sdl.h
+++ b/firmware/target/hosted/sdl/window-sdl.h
@@ -26,6 +26,9 @@
extern SDL_Texture *gui_texture; /* Window content, including background */
extern SDL_Surface *sim_lcd_surface; /* LCD content */
+extern SDL_mutex *window_mutex; /* prevent concurrent drawing from event thread &
+ main thread on MS Windows */
+
/* Renders GUI texture. Sets up new texture, if necessary */
void sdl_window_render(void);