From 758abbebc2bb186f4513dc53fcb6a9d196f2d0fb Mon Sep 17 00:00:00 2001 From: kub Date: Wed, 7 Oct 2020 20:17:01 +0200 Subject: [PATCH] ui, fix sdl flickering and status lines artifact issues --- platform/common/emu.c | 16 ++++++---- platform/common/emu.h | 1 + platform/common/menu_pico.c | 17 ++++++----- platform/common/plat_sdl.c | 24 ++++++++++----- platform/gp2x/emu.c | 32 ++++++++++---------- platform/linux/emu.c | 59 ++++++++++++++++++------------------- platform/linux/io.c | 2 +- 7 files changed, 81 insertions(+), 70 deletions(-) diff --git a/platform/common/emu.c b/platform/common/emu.c index 3377d40d..e4928076 100644 --- a/platform/common/emu.c +++ b/platform/common/emu.c @@ -1117,6 +1117,7 @@ static void run_events_ui(unsigned int which) while (in_menu_wait_any(NULL, 50) & (PBTN_MOK | PBTN_MBACK)) ; in_set_config_int(0, IN_CFG_BLOCKING, 0); + plat_status_msg_clear(); } if (do_it) { plat_status_msg_busy_first((which & PEV_STATE_LOAD) ? "LOADING STATE" : "SAVING STATE"); @@ -1361,6 +1362,7 @@ void emu_loop(void) char *notice_msg = NULL; char fpsbuff[24]; int fskip_cnt = 0; + int statclr_cnt = 4; fpsbuff[0] = 0; @@ -1408,12 +1410,10 @@ void emu_loop(void) > ms_to_ticks(STATUS_MSG_TIMEOUT) * 3) { notice_msg_time = 0; - plat_status_msg_clear(); -#ifndef __GP2X__ - plat_video_flip(); - plat_status_msg_clear(); /* Do it again in case of double buffering */ -#endif 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]; @@ -1523,6 +1523,12 @@ 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 26e2159b..9a12f8a7 100644 --- a/platform/common/emu.h +++ b/platform/common/emu.h @@ -172,6 +172,7 @@ void plat_status_msg_clear(void); void plat_video_toggle_renderer(int change, int menu_call); void plat_video_loop_prepare(void); +void plat_video_set_buffer(void *); void plat_update_volume(int has_changed, int is_up); diff --git a/platform/common/menu_pico.c b/platform/common/menu_pico.c index b96eb823..d4306634 100644 --- a/platform/common/menu_pico.c +++ b/platform/common/menu_pico.c @@ -168,6 +168,7 @@ static void load_progress_cb(int percent) len = g_menuscreen_w; menu_draw_begin(0, 1); + memcpy(g_menuscreen_ptr, g_menubg_ptr, g_menuscreen_w * g_menuscreen_h * 2); dst = (unsigned short *)g_menuscreen_ptr + g_menuscreen_pp * me_sfont_h * 2; for (ln = me_sfont_h - 2; ln > 0; ln--, dst += g_menuscreen_pp) memset(dst, 0xff, len * 2); @@ -182,6 +183,7 @@ static void cdload_progress_cb(const char *fname, int percent) menu_draw_begin(0, 1); dst = (unsigned short *)g_menuscreen_ptr + g_menuscreen_pp * me_sfont_h * 2; + memcpy(g_menuscreen_ptr, g_menubg_ptr, g_menuscreen_w * g_menuscreen_h * 2); menuscreen_memset_lines(dst, 0xff, me_sfont_h - 2); smalltext_out16(1, 3 * me_sfont_h, "Processing CD image / MP3s", 0xffff); @@ -201,18 +203,16 @@ static void cdload_progress_cb(const char *fname, int percent) void menu_romload_prepare(const char *rom_name) { const char *p = rom_name + strlen(rom_name); - int i; while (p > rom_name && *p != '/') p--; - /* fill all buffers, callbacks won't update in full */ - for (i = 0; i < 3; i++) { - menu_draw_begin(1, 1); - smalltext_out16(1, 1, "Loading", 0xffff); - smalltext_out16(1, me_sfont_h, p, 0xffff); - menu_draw_end(); - } + menu_draw_begin(1, 1); + smalltext_out16(1, 1, "Loading", 0xffff); + smalltext_out16(1, me_sfont_h, p, 0xffff); + /* background screen for callbacks */ + memcpy(g_menubg_ptr, g_menuscreen_ptr, g_menuscreen_w * g_menuscreen_h * 2); + menu_draw_end(); PicoCartLoadProgressCB = load_progress_cb; PicoCDLoadProgressCB = cdload_progress_cb; @@ -225,6 +225,7 @@ void menu_romload_end(void) PicoCDLoadProgressCB = NULL; menu_draw_begin(0, 1); + memcpy(g_menuscreen_ptr, g_menubg_ptr, g_menuscreen_w * g_menuscreen_h * 2); smalltext_out16(1, (cdload_called ? 6 : 3) * me_sfont_h, "Starting emulation...", 0xffff); menu_draw_end(); diff --git a/platform/common/plat_sdl.c b/platform/common/plat_sdl.c index 92da9f40..d6418a5e 100644 --- a/platform/common/plat_sdl.c +++ b/platform/common/plat_sdl.c @@ -9,6 +9,7 @@ #include #include "../libpicofe/input.h" +#include "../libpicofe/plat.h" #include "../libpicofe/plat_sdl.h" #include "../libpicofe/in_sdl.h" #include "../libpicofe/gl.h" @@ -174,13 +175,14 @@ void plat_video_flip(void) gl_flip(shadow_fb, g_screen_ppitch, g_screen_height); } else { - if (SDL_MUSTLOCK(plat_sdl_screen)) + if (SDL_MUSTLOCK(plat_sdl_screen)) { SDL_UnlockSurface(plat_sdl_screen); - SDL_Flip(plat_sdl_screen); - if (g_screen_ptr != shadow_fb) { - g_screen_ptr = plat_sdl_screen->pixels; - plat_video_toggle_renderer(0, 0); - } + SDL_Flip(plat_sdl_screen); + SDL_LockSurface(plat_sdl_screen); + } else + SDL_Flip(plat_sdl_screen); + g_screen_ptr = plat_sdl_screen->pixels; + plat_video_set_buffer(g_screen_ptr); } } @@ -190,8 +192,11 @@ void plat_video_wait_vsync(void) void plat_video_menu_enter(int is_rom_loaded) { + if (SDL_MUSTLOCK(plat_sdl_screen)) + SDL_UnlockSurface(plat_sdl_screen); plat_sdl_change_video_mode(g_menuscreen_w, g_menuscreen_h, 0); g_screen_ptr = shadow_fb; + plat_video_set_buffer(g_screen_ptr); } void plat_video_menu_begin(void) @@ -228,7 +233,6 @@ void plat_video_menu_end(void) SDL_Flip(plat_sdl_screen); } g_menuscreen_ptr = NULL; - } void plat_video_menu_leave(void) @@ -246,8 +250,8 @@ void plat_video_loop_prepare(void) if (SDL_MUSTLOCK(plat_sdl_screen)) SDL_LockSurface(plat_sdl_screen); g_screen_ptr = plat_sdl_screen->pixels; - plat_video_toggle_renderer(0, 0); } + plat_video_set_buffer(g_screen_ptr); } void plat_early_init(void) @@ -268,6 +272,10 @@ void plat_init(void) ret = plat_sdl_init(); if (ret != 0) exit(1); +#if defined(__RG350__) || defined(__GCW0__) + // opendingux on JZ47x0 may falsely report a HW overlay, fix to window + plat_target.vout_method = 0; +#endif plat_sdl_quit_cb = plat_sdl_quit; diff --git a/platform/gp2x/emu.c b/platform/gp2x/emu.c index 42e34ee3..ef3b7693 100644 --- a/platform/gp2x/emu.c +++ b/platform/gp2x/emu.c @@ -436,27 +436,26 @@ void plat_status_msg_clear(void) int is_8bit = !is_16bit_mode(); if (currentConfig.EmuOpt & EOPT_WIZ_TEAR_FIX) { /* ugh.. */ - int i, u, *p; + int u, *p; if (is_8bit) { - for (i = 0; i < 4; i++) { - p = (int *)gp2x_screens[i] + (240-8) / 4; - for (u = 320; u > 0; u--, p += 240/4) - p[0] = p[1] = 0xe0e0e0e0; - } + p = (int *)g_screen_ptr + (240-8) / 4; + for (u = 320; u > 0; u--, p += 240/4) + p[0] = p[1] = 0xe0e0e0e0; } else { - for (i = 0; i < 4; i++) { - 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; - } + 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); + } else { + short *d = (short *)g_screen_ptr + 320 * (240-8); + memset32((int *)d, 0, 2*320 * 8 / 4); + } } - - if (is_8bit) - gp2x_memset_all_buffers(320*232, 0xe0, 320*8); - else - gp2x_memset_all_buffers(320*232*2, 0, 320*8*2); } void plat_status_msg_busy_next(const char *msg) @@ -473,7 +472,6 @@ void plat_status_msg_busy_next(const char *msg) void plat_status_msg_busy_first(const char *msg) { - gp2x_memcpy_all_buffers(g_screen_ptr, 0, 320*240*2); plat_status_msg_busy_next(msg); } diff --git a/platform/linux/emu.c b/platform/linux/emu.c index beeab373..ae1d025a 100644 --- a/platform/linux/emu.c +++ b/platform/linux/emu.c @@ -24,6 +24,7 @@ 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) { @@ -45,34 +46,21 @@ static void draw_cd_leds(void) led_offs = 4; scr_offs = pitch * 2 + 4; -#if 0 - if (currentConfig.renderer != RT_16BIT) { - #define p(x) px[(x) >> 2] - // 8-bit modes - unsigned int *px = (unsigned int *)((char *)g_screen_ptr + scr_offs); - unsigned int col_g = (led_reg & 2) ? 0xc0c0c0c0 : 0xe0e0e0e0; - unsigned int col_r = (led_reg & 1) ? 0xd0d0d0d0 : 0xe0e0e0e0; - p(pitch*0) = p(pitch*1) = p(pitch*2) = col_g; - p(pitch*0 + led_offs) = p(pitch*1 + led_offs) = p(pitch*2 + led_offs) = col_r; - #undef p - } else -#endif - { - #define p(x) px[(x)*2 >> 2] = px[((x)*2 >> 2) + 1] - // 16-bit modes - unsigned int *px = (unsigned int *)((short *)g_screen_ptr + scr_offs); - unsigned int col_g = (led_reg & 2) ? 0x06000600 : 0; - unsigned int col_r = (led_reg & 1) ? 0xc000c000 : 0; - p(pitch*0) = p(pitch*1) = p(pitch*2) = col_g; - p(pitch*0 + led_offs) = p(pitch*1 + led_offs) = p(pitch*2 + led_offs) = col_r; - #undef p - } +#define p(x) px[(x)*2 >> 2] = px[((x)*2 >> 2) + 1] + // 16-bit modes + unsigned int *px = (unsigned int *)((short *)g_screen_ptr + scr_offs); + unsigned int col_g = (led_reg & 2) ? 0x06000600 : 0; + unsigned int col_r = (led_reg & 1) ? 0xc000c000 : 0; + p(pitch*0) = p(pitch*1) = p(pitch*2) = col_g; + p(pitch*0 + led_offs) = p(pitch*1 + led_offs) = p(pitch*2 + led_offs) = col_r; +#undef p } void pemu_finalize_frame(const char *fps, const char *notice) { if (currentConfig.renderer != RT_16BIT && !(PicoIn.AHW & PAHW_32X)) { - unsigned short *pd = (unsigned short *)g_screen_ptr + out_y * g_screen_ppitch + out_x; + unsigned short *pd = (unsigned short *)g_screen_ptr + + out_y * g_screen_ppitch + out_x; unsigned char *ps = Pico.est.Draw2FB + 328*out_y + 8; //+ out_x; unsigned short *pal = Pico.est.HighPal; int i, x; @@ -86,16 +74,24 @@ void pemu_finalize_frame(const char *fps, const char *notice) } } - if (notice || (currentConfig.EmuOpt & EOPT_SHOW_FPS)) { - if (notice) - emu_osd_text16(4, g_screen_height - 8, notice); - if (currentConfig.EmuOpt & EOPT_SHOW_FPS) - emu_osd_text16(g_screen_width - 60, g_screen_height - 8, fps); - } + if (notice) + emu_osd_text16(4, g_screen_height - 8, notice); + if (currentConfig.EmuOpt & EOPT_SHOW_FPS) + emu_osd_text16(g_screen_width - 60, g_screen_height - 8, fps); if ((PicoIn.AHW & PAHW_MCD) && (currentConfig.EmuOpt & EOPT_EN_CD_LEDS)) draw_cd_leds(); } +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); +} + static void apply_renderer(void) { switch (currentConfig.renderer) { @@ -156,7 +152,7 @@ void plat_status_msg_busy_next(const char *msg) void plat_status_msg_busy_first(const char *msg) { -// memset32(g_screen_ptr, 0, g_screen_ppitch * g_screen_height * 2 / 4); + clr_cnt = 4; plat_status_msg_busy_next(msg); } @@ -190,7 +186,8 @@ 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); - memset32(g_screen_ptr, 0, g_screen_ppitch * g_screen_height * 2 / 4); + clr_cnt = 4; + out_y = start_line; out_x = (is_32cols ? 32 : 0); out_h = line_count; out_w = (is_32cols ? 256:320); } diff --git a/platform/linux/io.c b/platform/linux/io.c index 57601ccc..74cf30f3 100644 --- a/platform/linux/io.c +++ b/platform/linux/io.c @@ -310,7 +310,7 @@ void plat_video_flip(void) ximage_realloc(xlib_display, DefaultVisual(xlib_display, 0)); // propagate new ponters to renderers - plat_video_toggle_renderer(0, 0); + plat_video_set_buffer(g_screen_ptr); } } -- 2.39.5