ui, fix sdl flickering and status lines artifact issues
authorkub <derkub@gmail.com>
Wed, 7 Oct 2020 18:17:01 +0000 (20:17 +0200)
committerkub <derkub@gmail.com>
Wed, 7 Oct 2020 18:18:37 +0000 (20:18 +0200)
platform/common/emu.c
platform/common/emu.h
platform/common/menu_pico.c
platform/common/plat_sdl.c
platform/gp2x/emu.c
platform/linux/emu.c
platform/linux/io.c

index 3377d40..e492807 100644 (file)
@@ -1117,6 +1117,7 @@ static void run_events_ui(unsigned int which)
                        while (in_menu_wait_any(NULL, 50) & (PBTN_MOK | PBTN_MBACK))\r
                                ;\r
                        in_set_config_int(0, IN_CFG_BLOCKING, 0);\r
+                       plat_status_msg_clear();\r
                }\r
                if (do_it) {\r
                        plat_status_msg_busy_first((which & PEV_STATE_LOAD) ? "LOADING STATE" : "SAVING STATE");\r
@@ -1361,6 +1362,7 @@ void emu_loop(void)
        char *notice_msg = NULL;\r
        char fpsbuff[24];\r
        int fskip_cnt = 0;\r
+       int statclr_cnt = 4;\r
 \r
        fpsbuff[0] = 0;\r
 \r
@@ -1408,12 +1410,10 @@ void emu_loop(void)
                             > ms_to_ticks(STATUS_MSG_TIMEOUT) * 3)\r
                        {\r
                                notice_msg_time = 0;\r
-                               plat_status_msg_clear();\r
-#ifndef __GP2X__\r
-                               plat_video_flip();\r
-                               plat_status_msg_clear(); /* Do it again in case of double buffering */\r
-#endif\r
                                notice_msg = NULL;\r
+                               /* clear all buffers if multi buffering */\r
+                               plat_status_msg_clear();\r
+                               statclr_cnt = 4;\r
                        }\r
                        else {\r
                                int sum = noticeMsg[0] + noticeMsg[1] + noticeMsg[2];\r
@@ -1523,6 +1523,12 @@ void emu_loop(void)
                if (!skip && flip_after_sync)\r
                        plat_video_flip();\r
 \r
+               if (!skip && statclr_cnt > 0) {\r
+                       // clear stat msg area in case of multi buffering\r
+                       plat_status_msg_clear();\r
+                       statclr_cnt --;\r
+               }\r
+\r
                pprof_end(main);\r
        }\r
 \r
index 26e2159..9a12f8a 100644 (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);
 
index b96eb82..d430663 100644 (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);
-               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();
index 92da9f4..d6418a5 100644 (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) {
-                       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;
 
index 42e34ee..ef3b769 100644 (file)
@@ -436,27 +436,26 @@ void plat_status_msg_clear(void)
        int is_8bit = !is_16bit_mode();\r
        if (currentConfig.EmuOpt & EOPT_WIZ_TEAR_FIX) {\r
                /* ugh.. */\r
-               int i, u, *p;\r
+               int u, *p;\r
                if (is_8bit) {\r
-                       for (i = 0; i < 4; i++) {\r
-                               p = (int *)gp2x_screens[i] + (240-8) / 4;\r
-                               for (u = 320; u > 0; u--, p += 240/4)\r
-                                       p[0] = p[1] = 0xe0e0e0e0;\r
-                       }\r
+                       p = (int *)g_screen_ptr + (240-8) / 4;\r
+                       for (u = 320; u > 0; u--, p += 240/4)\r
+                               p[0] = p[1] = 0xe0e0e0e0;\r
                } else {\r
-                       for (i = 0; i < 4; i++) {\r
-                               p = (int *)gp2x_screens[i] + (240-8)*2 / 4;\r
-                               for (u = 320; u > 0; u--, p += 240*2/4)\r
-                                       p[0] = p[1] = p[2] = p[3] = 0;\r
-                       }\r
+                       p = (int *)g_screen_ptr + (240-8)*2 / 4;\r
+                       for (u = 320; u > 0; u--, p += 240*2/4)\r
+                               p[0] = p[1] = p[2] = p[3] = 0;\r
                }\r
                return;\r
+       } else {\r
+               if (is_8bit) {\r
+                       char *d = (char *)g_screen_ptr + 320 * (240-8);\r
+                       memset32((int *)d, 0xe0, 320 * 8 / 4);\r
+               } else {\r
+                       short *d = (short *)g_screen_ptr + 320 * (240-8);\r
+                       memset32((int *)d, 0, 2*320 * 8 / 4);\r
+               }\r
        }\r
-\r
-       if (is_8bit)\r
-               gp2x_memset_all_buffers(320*232, 0xe0, 320*8);\r
-       else\r
-               gp2x_memset_all_buffers(320*232*2, 0, 320*8*2);\r
 }\r
 \r
 void plat_status_msg_busy_next(const char *msg)\r
@@ -473,7 +472,6 @@ void plat_status_msg_busy_next(const char *msg)
 \r
 void plat_status_msg_busy_first(const char *msg)\r
 {\r
-       gp2x_memcpy_all_buffers(g_screen_ptr, 0, 320*240*2);\r
        plat_status_msg_busy_next(msg);\r
 }\r
 \r
index beeab37..ae1d025 100644 (file)
@@ -24,6 +24,7 @@ enum renderer_types { RT_16BIT, RT_8BIT_ACC, RT_8BIT_FAST, RT_COUNT };
 \r
 static int out_x, out_y;\r
 static int out_w, out_h;\r
+static int clr_cnt;\r
 \r
 void pemu_prep_defconfig(void)\r
 {\r
@@ -45,34 +46,21 @@ static void draw_cd_leds(void)
        led_offs = 4;\r
        scr_offs = pitch * 2 + 4;\r
 \r
-#if 0\r
-       if (currentConfig.renderer != RT_16BIT) {\r
-       #define p(x) px[(x) >> 2]\r
-               // 8-bit modes\r
-               unsigned int *px = (unsigned int *)((char *)g_screen_ptr + scr_offs);\r
-               unsigned int col_g = (led_reg & 2) ? 0xc0c0c0c0 : 0xe0e0e0e0;\r
-               unsigned int col_r = (led_reg & 1) ? 0xd0d0d0d0 : 0xe0e0e0e0;\r
-               p(pitch*0) = p(pitch*1) = p(pitch*2) = col_g;\r
-               p(pitch*0 + led_offs) = p(pitch*1 + led_offs) = p(pitch*2 + led_offs) = col_r;\r
-       #undef p\r
-       } else\r
-#endif\r
-       {\r
-       #define p(x) px[(x)*2 >> 2] = px[((x)*2 >> 2) + 1]\r
-               // 16-bit modes\r
-               unsigned int *px = (unsigned int *)((short *)g_screen_ptr + scr_offs);\r
-               unsigned int col_g = (led_reg & 2) ? 0x06000600 : 0;\r
-               unsigned int col_r = (led_reg & 1) ? 0xc000c000 : 0;\r
-               p(pitch*0) = p(pitch*1) = p(pitch*2) = col_g;\r
-               p(pitch*0 + led_offs) = p(pitch*1 + led_offs) = p(pitch*2 + led_offs) = col_r;\r
-       #undef p\r
-       }\r
+#define p(x) px[(x)*2 >> 2] = px[((x)*2 >> 2) + 1]\r
+       // 16-bit modes\r
+       unsigned int *px = (unsigned int *)((short *)g_screen_ptr + scr_offs);\r
+       unsigned int col_g = (led_reg & 2) ? 0x06000600 : 0;\r
+       unsigned int col_r = (led_reg & 1) ? 0xc000c000 : 0;\r
+       p(pitch*0) = p(pitch*1) = p(pitch*2) = col_g;\r
+       p(pitch*0 + led_offs) = p(pitch*1 + led_offs) = p(pitch*2 + led_offs) = col_r;\r
+#undef p\r
 }\r
 \r
 void pemu_finalize_frame(const char *fps, const char *notice)\r
 {\r
        if (currentConfig.renderer != RT_16BIT && !(PicoIn.AHW & PAHW_32X)) {\r
-               unsigned short *pd = (unsigned short *)g_screen_ptr + out_y * g_screen_ppitch + out_x;\r
+               unsigned short *pd = (unsigned short *)g_screen_ptr +\r
+                                       out_y * g_screen_ppitch + out_x;\r
                unsigned char *ps = Pico.est.Draw2FB + 328*out_y + 8; //+ out_x;\r
                unsigned short *pal = Pico.est.HighPal;\r
                int i, x;\r
@@ -86,16 +74,24 @@ void pemu_finalize_frame(const char *fps, const char *notice)
                }\r
        }\r
 \r
-       if (notice || (currentConfig.EmuOpt & EOPT_SHOW_FPS)) {\r
-               if (notice)\r
-                       emu_osd_text16(4, g_screen_height - 8, notice);\r
-               if (currentConfig.EmuOpt & EOPT_SHOW_FPS)\r
-                       emu_osd_text16(g_screen_width - 60, g_screen_height - 8, fps);\r
-       }\r
+       if (notice)\r
+               emu_osd_text16(4, g_screen_height - 8, notice);\r
+       if (currentConfig.EmuOpt & EOPT_SHOW_FPS)\r
+               emu_osd_text16(g_screen_width - 60, g_screen_height - 8, fps);\r
        if ((PicoIn.AHW & PAHW_MCD) && (currentConfig.EmuOpt & EOPT_EN_CD_LEDS))\r
                draw_cd_leds();\r
 }\r
 \r
+void plat_video_set_buffer(void *buf)\r
+{\r
+       if (clr_cnt > 0) {\r
+               memset32(g_screen_ptr, 0, g_screen_ppitch*g_screen_height*2 / 4);\r
+               clr_cnt --;\r
+       }\r
+       if (currentConfig.renderer == RT_16BIT || (PicoIn.AHW & PAHW_32X))\r
+               PicoDrawSetOutBuf(g_screen_ptr, g_screen_ppitch * 2);\r
+}\r
+\r
 static void apply_renderer(void)\r
 {\r
        switch (currentConfig.renderer) {\r
@@ -156,7 +152,7 @@ void plat_status_msg_busy_next(const char *msg)
 \r
 void plat_status_msg_busy_first(const char *msg)\r
 {\r
-//     memset32(g_screen_ptr, 0, g_screen_ppitch * g_screen_height * 2 / 4);\r
+       clr_cnt = 4;\r
        plat_status_msg_busy_next(msg);\r
 }\r
 \r
@@ -190,7 +186,8 @@ void emu_video_mode_change(int start_line, int line_count, int is_32cols)
        // clear whole screen in all buffers\r
        if (currentConfig.renderer != RT_16BIT && !(PicoIn.AHW & PAHW_32X))\r
                memset32(Pico.est.Draw2FB, 0xe0e0e0e0, (320+8) * (8+240+8) / 4);\r
-       memset32(g_screen_ptr, 0, g_screen_ppitch * g_screen_height * 2 / 4);\r
+       clr_cnt = 4;\r
+\r
        out_y = start_line; out_x = (is_32cols ? 32 : 0);\r
        out_h = line_count; out_w = (is_32cols ? 256:320);\r
 }\r
index 57601cc..74cf30f 100644 (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);
        }
 }