From 69b7b2641bcca4503854bab87f784e514a731616 Mon Sep 17 00:00:00 2001 From: kub Date: Thu, 12 Nov 2020 21:51:35 +0100 Subject: [PATCH] ui, revise status line handling --- platform/common/emu.c | 9 -------- platform/common/emu.h | 4 ++++ platform/common/plat_sdl.c | 27 ++++++++++++++++++++++++ platform/gp2x/emu.c | 42 ++++++++++++++++++++------------------ platform/linux/emu.c | 14 +++---------- 5 files changed, 56 insertions(+), 40 deletions(-) diff --git a/platform/common/emu.c b/platform/common/emu.c index b46a9bf4..55f01467 100644 --- a/platform/common/emu.c +++ b/platform/common/emu.c @@ -1366,7 +1366,6 @@ void emu_loop(void) char *notice_msg = NULL; char fpsbuff[24]; int fskip_cnt = 0; - int statclr_cnt = 4; fpsbuff[0] = 0; @@ -1415,9 +1414,7 @@ void emu_loop(void) { notice_msg_time = 0; notice_msg = NULL; - /* clear all buffers if multi buffering */ plat_status_msg_clear(); - statclr_cnt = 4; } else { int sum = noticeMsg[0] + noticeMsg[1] + noticeMsg[2]; @@ -1527,12 +1524,6 @@ void emu_loop(void) if (!skip && flip_after_sync) plat_video_flip(); - if (!skip && statclr_cnt > 0) { - // clear stat msg area in case of multi buffering - plat_status_msg_clear(); - statclr_cnt --; - } - pprof_end(main); } diff --git a/platform/common/emu.h b/platform/common/emu.h index 9a12f8a7..af857bc1 100644 --- a/platform/common/emu.h +++ b/platform/common/emu.h @@ -176,6 +176,10 @@ void plat_video_set_buffer(void *); void plat_update_volume(int has_changed, int is_up); +/* should be in libpicofe/plat.h */ +void plat_video_clear_status(void); +void plat_video_clear_buffers(void); + #ifdef __cplusplus } // extern "C" #endif diff --git a/platform/common/plat_sdl.c b/platform/common/plat_sdl.c index d6418a5e..7a12fa92 100644 --- a/platform/common/plat_sdl.c +++ b/platform/common/plat_sdl.c @@ -159,6 +159,8 @@ void rgb565_to_uyvy(void *d, const void *s, int pixels) } } +static int clear_buf_cnt, clear_stat_cnt; + void plat_video_flip(void) { if (plat_sdl_overlay != NULL) { @@ -183,6 +185,16 @@ void plat_video_flip(void) SDL_Flip(plat_sdl_screen); g_screen_ptr = plat_sdl_screen->pixels; plat_video_set_buffer(g_screen_ptr); + if (clear_buf_cnt) { + memset(g_screen_ptr, 0, plat_sdl_screen->w*plat_sdl_screen->h * 2); + clear_buf_cnt--; + } + } + if (clear_stat_cnt) { + unsigned short *d = (unsigned short *)g_screen_ptr + g_screen_ppitch * g_screen_height; + int l = g_screen_ppitch * 8; + memset((int *)(d - l), 0, l * 2); + clear_stat_cnt--; } } @@ -190,6 +202,21 @@ void plat_video_wait_vsync(void) { } +void plat_video_clear_status(void) +{ + clear_stat_cnt = 3; // do it thrice in case of triple buffering +} + +void plat_video_clear_buffers(void) +{ + if (plat_sdl_overlay != NULL || plat_sdl_gl_active) + memset(shadow_fb, 0, plat_sdl_screen->w*plat_sdl_screen->h * 2); + else { + memset(g_screen_ptr, 0, plat_sdl_screen->w*plat_sdl_screen->h * 2); + clear_buf_cnt = 3; // do it thrice in case of triple buffering + } +} + void plat_video_menu_enter(int is_rom_loaded) { if (SDL_MUSTLOCK(plat_sdl_screen)) diff --git a/platform/gp2x/emu.c b/platform/gp2x/emu.c index ef3b7693..9dd7d154 100644 --- a/platform/gp2x/emu.c +++ b/platform/gp2x/emu.c @@ -433,27 +433,29 @@ void plat_video_wait_vsync(void) void plat_status_msg_clear(void) { - int is_8bit = !is_16bit_mode(); - if (currentConfig.EmuOpt & EOPT_WIZ_TEAR_FIX) { - /* ugh.. */ - int u, *p; - if (is_8bit) { - p = (int *)g_screen_ptr + (240-8) / 4; - for (u = 320; u > 0; u--, p += 240/4) - p[0] = p[1] = 0xe0e0e0e0; - } else { - p = (int *)g_screen_ptr + (240-8)*2 / 4; - for (u = 320; u > 0; u--, p += 240*2/4) - p[0] = p[1] = p[2] = p[3] = 0; - } - return; - } else { - if (is_8bit) { - char *d = (char *)g_screen_ptr + 320 * (240-8); - memset32((int *)d, 0xe0, 320 * 8 / 4); + int i, is_8bit = !is_16bit_mode(); + + for (i = 0; i < 4; i++) { + if (currentConfig.EmuOpt & EOPT_WIZ_TEAR_FIX) { + /* ugh.. */ + int u, *p; + if (is_8bit) { + p = (int *)gp2x_screens[i] + (240-8) / 4; + for (u = 320; u > 0; u--, p += 240/4) + p[0] = p[1] = 0xe0e0e0e0; + } else { + p = (int *)gp2x_screens[i] + (240-8)*2 / 4; + for (u = 320; u > 0; u--, p += 240*2/4) + p[0] = p[1] = p[2] = p[3] = 0; + } } else { - short *d = (short *)g_screen_ptr + 320 * (240-8); - memset32((int *)d, 0, 2*320 * 8 / 4); + if (is_8bit) { + char *d = (char *)gp2x_screens[i] + 320 * (240-8); + memset32((int *)d, 0xe0, 320 * 8 / 4); + } else { + char *d = (char *)gp2x_screens[i] + 320*2 * (240-8); + memset32((int *)d, 0, 2*320 * 8 / 4); + } } } } diff --git a/platform/linux/emu.c b/platform/linux/emu.c index 798d2e76..286bff70 100644 --- a/platform/linux/emu.c +++ b/platform/linux/emu.c @@ -24,7 +24,6 @@ enum renderer_types { RT_16BIT, RT_8BIT_ACC, RT_8BIT_FAST, RT_COUNT }; static int out_x, out_y; static int out_w, out_h; -static int clr_cnt; void pemu_prep_defconfig(void) { @@ -84,10 +83,6 @@ void pemu_finalize_frame(const char *fps, const char *notice) void plat_video_set_buffer(void *buf) { - if (clr_cnt > 0) { - memset32(g_screen_ptr, 0, g_screen_ppitch*g_screen_height*2 / 4); - clr_cnt --; - } if (currentConfig.renderer == RT_16BIT || (PicoIn.AHW & PAHW_32X)) PicoDrawSetOutBuf(g_screen_ptr, g_screen_ppitch * 2); } @@ -118,7 +113,6 @@ static void apply_renderer(void) PicoDrawSetOutBuf(g_screen_ptr, g_screen_ppitch * 2); Pico.m.dirtyPal = 1; - clr_cnt = 4; } void plat_video_toggle_renderer(int change, int is_menu) @@ -137,9 +131,7 @@ void plat_video_toggle_renderer(int change, int is_menu) void plat_status_msg_clear(void) { - unsigned short *d = (unsigned short *)g_screen_ptr + g_screen_ppitch * g_screen_height; - int l = g_screen_ppitch * 8; - memset32((int *)(d - l), 0, l * 2 / 4); + plat_video_clear_status(); } void plat_status_msg_busy_next(const char *msg) @@ -153,7 +145,6 @@ void plat_status_msg_busy_next(const char *msg) void plat_status_msg_busy_first(const char *msg) { - clr_cnt = 4; plat_status_msg_busy_next(msg); } @@ -187,7 +178,7 @@ void emu_video_mode_change(int start_line, int line_count, int is_32cols) // clear whole screen in all buffers if (currentConfig.renderer != RT_16BIT && !(PicoIn.AHW & PAHW_32X)) memset32(Pico.est.Draw2FB, 0xe0e0e0e0, (320+8) * (8+240+8) / 4); - clr_cnt = 4; + plat_video_clear_buffers(); out_y = start_line; out_x = (is_32cols ? 32 : 0); out_h = line_count; out_w = (is_32cols ? 256:320); @@ -196,6 +187,7 @@ void emu_video_mode_change(int start_line, int line_count, int is_32cols) void pemu_loop_prep(void) { apply_renderer(); + plat_video_clear_buffers(); } void pemu_loop_end(void) -- 2.39.5