From 7f4bfa96d1be730cfe32b02f9208540f6af16e41 Mon Sep 17 00:00:00 2001 From: kub Date: Tue, 10 Sep 2024 22:58:16 +0200 Subject: [PATCH] sdl, improve window resize handling --- platform/common/menu_pico.c | 2 ++ platform/common/plat_sdl.c | 22 ++++++++++++++++------ platform/gp2x/plat.c | 5 +++++ platform/libpicofe | 2 +- platform/linux/emu.c | 7 ++++--- platform/pandora/plat.c | 4 ++++ platform/ps2/emu.c | 6 ++++++ platform/psp/plat.c | 6 ++++++ 8 files changed, 44 insertions(+), 10 deletions(-) diff --git a/platform/common/menu_pico.c b/platform/common/menu_pico.c index 415e1b5f..5bf67b7f 100644 --- a/platform/common/menu_pico.c +++ b/platform/common/menu_pico.c @@ -156,6 +156,8 @@ static void copy_bg(int dir) static void menu_draw_prep(void) { + plat_video_menu_update(); + if (menu_w == g_menuscreen_w && menu_h == g_menuscreen_h) return; menu_w = g_menuscreen_w, menu_h = g_menuscreen_h; diff --git a/platform/common/plat_sdl.c b/platform/common/plat_sdl.c index d1e833f3..cdcaee7a 100644 --- a/platform/common/plat_sdl.c +++ b/platform/common/plat_sdl.c @@ -285,6 +285,19 @@ void plat_video_clear_buffers(void) } } +void plat_video_menu_update(void) +{ + // w/h might have changed due to resizing + plat_sdl_change_video_mode(g_menuscreen_w, g_menuscreen_h, 1); + resize_buffers(); + + // update pitch as it is needed by the menu bg scaler + if (plat_sdl_overlay || plat_sdl_gl_active) + g_menuscreen_pp = g_menuscreen_w; + else + g_menuscreen_pp = plat_sdl_screen->pitch / 2; +} + void plat_video_menu_enter(int is_rom_loaded) { if (SDL_MUSTLOCK(plat_sdl_screen)) @@ -293,16 +306,13 @@ void plat_video_menu_enter(int is_rom_loaded) void plat_video_menu_begin(void) { - plat_sdl_change_video_mode(g_menuscreen_w, g_menuscreen_h, 1); - resize_buffers(); - if (plat_sdl_overlay || plat_sdl_gl_active) { - g_menuscreen_pp = g_menuscreen_w; + plat_video_menu_update(); // just in case + + if (plat_sdl_overlay || plat_sdl_gl_active) g_menuscreen_ptr = shadow_fb; - } else { if (SDL_MUSTLOCK(plat_sdl_screen)) SDL_LockSurface(plat_sdl_screen); - g_menuscreen_pp = plat_sdl_screen->pitch / 2; g_menuscreen_ptr = plat_sdl_screen->pixels; } } diff --git a/platform/gp2x/plat.c b/platform/gp2x/plat.c index 96e9be09..422b4ddc 100644 --- a/platform/gp2x/plat.c +++ b/platform/gp2x/plat.c @@ -147,6 +147,11 @@ void gp2x_make_fb_bufferable(int yes) } /* common */ +void plat_video_menu_update(void) +{ + // surface is always the screen +} + void plat_video_menu_enter(int is_rom_loaded) { if (gp2x_current_bpp != 16 || gp2x_dev_id == GP2X_DEV_WIZ) { diff --git a/platform/libpicofe b/platform/libpicofe index 9fba90ac..fbbf5e3f 160000 --- a/platform/libpicofe +++ b/platform/libpicofe @@ -1 +1 @@ -Subproject commit 9fba90ac323df5d2ad87735f6033ae720e5cb892 +Subproject commit fbbf5e3fc0aff858e206dd98ce4605b960d397cb diff --git a/platform/linux/emu.c b/platform/linux/emu.c index 736fbb1c..9c9d16cb 100644 --- a/platform/linux/emu.c +++ b/platform/linux/emu.c @@ -341,6 +341,10 @@ void pemu_forced_frame(int no_scale, int do_emu) g_menubg_src_ptr = realloc(g_menubg_src_ptr, g_screen_height * g_screen_ppitch * 2); memcpy(g_menubg_src_ptr, g_screen_ptr, g_screen_height * g_screen_ppitch * 2); + g_menubg_src_w = g_screen_width; + g_menubg_src_h = g_screen_height; + g_menubg_src_pp = g_screen_ppitch; + currentConfig.scaling = hs, currentConfig.vscaling = vs; } @@ -480,9 +484,6 @@ void pemu_loop_end(void) /* do one more frame for menu bg */ plat_video_set_shadow(320, 240); pemu_forced_frame(0, 1); - g_menubg_src_w = g_screen_width; - g_menubg_src_h = g_screen_height; - g_menubg_src_pp = g_screen_ppitch; if (ghost_buf) { free(ghost_buf); ghost_buf = NULL; diff --git a/platform/pandora/plat.c b/platform/pandora/plat.c index bb7774f2..1f056c87 100644 --- a/platform/pandora/plat.c +++ b/platform/pandora/plat.c @@ -199,6 +199,10 @@ void plat_video_toggle_renderer(int change, int is_menu) PicoDrawSetOutFormat(PDF_RGB555, 0); } +void plat_video_menu_update(void) +{ +} + void plat_video_menu_enter(int is_rom_loaded) { } diff --git a/platform/ps2/emu.c b/platform/ps2/emu.c index 09e13d25..cab389cb 100644 --- a/platform/ps2/emu.c +++ b/platform/ps2/emu.c @@ -868,6 +868,12 @@ void plat_video_wait_vsync(void) gsKit_sync(gsGlobal); } +/* update surface data */ +void plat_video_menu_update(void) +{ + // surface is always the screen +} + /* switch from emulation display to menu display */ void plat_video_menu_enter(int is_rom_loaded) { diff --git a/platform/psp/plat.c b/platform/psp/plat.c index 53e13616..05482786 100644 --- a/platform/psp/plat.c +++ b/platform/psp/plat.c @@ -98,6 +98,12 @@ void plat_video_wait_vsync(void) sceDisplayWaitVblankStart(); } +/* update surface data */ +void plat_video_menu_update(void) +{ + // surface is always the screen +} + /* switch from emulation display to menu display */ void plat_video_menu_enter(int is_rom_loaded) { -- 2.39.5