ui, fix sdl flickering and status lines artifact issues

This commit is contained in:
kub 2020-10-07 20:17:01 +02:00
parent 3618d636d2
commit 758abbebc2
7 changed files with 81 additions and 70 deletions

View file

@ -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);
}

View file

@ -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);

View file

@ -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);
/* 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();

View file

@ -9,6 +9,7 @@
#include <stdio.h>
#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) {
SDL_LockSurface(plat_sdl_screen);
} else
SDL_Flip(plat_sdl_screen);
g_screen_ptr = plat_sdl_screen->pixels;
plat_video_toggle_renderer(0, 0);
}
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;

View file

@ -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;
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;
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);
}

View file

@ -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,19 +46,6 @@ 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);
@ -67,12 +55,12 @@ static void draw_cd_leds(void)
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 ((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);
}

View file

@ -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);
}
}