From 093432d6c4191e2521a87d6397d9c3626f49a687 Mon Sep 17 00:00:00 2001 From: Giovanni Cascione <43221199+spleen1981@users.noreply.github.com> Date: Tue, 16 Aug 2022 22:13:43 +0200 Subject: [PATCH] mali_fbdev: fix assertion failed on video threaded switch (#14316) * mali_fbdev: fix assertion failed on video thread switch * mali_fbdev: added fallback to get refresh rate currently set --- gfx/drivers_context/mali_fbdev_ctx.c | 81 ++++++++++++++++++++-------- 1 file changed, 58 insertions(+), 23 deletions(-) diff --git a/gfx/drivers_context/mali_fbdev_ctx.c b/gfx/drivers_context/mali_fbdev_ctx.c index 27f7a4d341..73665c37f4 100644 --- a/gfx/drivers_context/mali_fbdev_ctx.c +++ b/gfx/drivers_context/mali_fbdev_ctx.c @@ -38,6 +38,8 @@ #include "../../verbosity.h" #include "../../configuration.h" +#include + typedef struct { #ifdef HAVE_EGL @@ -93,7 +95,25 @@ static int gfx_ctx_mali_fbdev_get_vinfo(void *data) (vinfo.yres + vinfo.upper_margin + vinfo.lower_margin + vinfo.vsync_len) / (vinfo.xres + vinfo.left_margin + vinfo.right_margin + vinfo.hsync_len); }else{ - mali->refresh_rate = 60; + /* Workaround to retrieve current refresh rate if no info is available from IOCTL. + If this fails as well, 60Hz is assumed... */ + int j=0; + float k=60.0; + char temp[32]; + RFILE *fr = filestream_open("/sys/class/display/mode", RETRO_VFS_FILE_ACCESS_READ, RETRO_VFS_FILE_ACCESS_HINT_NONE); + if (fr){ + if (filestream_gets(fr, temp, sizeof(temp))){ + for (int i=0;irefresh_rate = k; } return 0; @@ -127,6 +147,27 @@ static void gfx_ctx_mali_fbdev_clear_screen(void) } } +static void gfx_ctx_mali_fbdev_destroy_really(void) +{ + if (gfx_ctx_mali_fbdev_global) + { +#ifdef HAVE_EGL + egl_destroy(&gfx_ctx_mali_fbdev_global->egl); +#endif + gfx_ctx_mali_fbdev_global->resize=false; + free(gfx_ctx_mali_fbdev_global); + gfx_ctx_mali_fbdev_global=NULL; + } +} + +static void gfx_ctx_mali_fbdev_maybe_restart(void) +{ + runloop_state_t *runloop_st = runloop_state_get_ptr(); + + if (!runloop_st->shutdown_initiated) + frontend_driver_set_fork(FRONTEND_FORK_RESTART); +} + /*TODO FIXME As egl_destroy does not work properly with libmali (big fps drop after destroy and initialization/creation of new context/surface), it is not used. A global pointers is initialized at startup in gfx_ctx_mali_fbdev_init, and returned each time gfx_ctx_mali_fbdev_init is called. @@ -137,31 +178,25 @@ All these workarounds should be reverted when and if egl_destroy issues in libma */ static void gfx_ctx_mali_fbdev_destroy(void *data) { -/* mali_ctx_data_t *mali = (mali_ctx_data_t*)data; - - if (mali) - { -#ifdef HAVE_EGL - egl_destroy(&mali->egl); -#endif - - mali->resize = false; - free(mali); - } -*/ runloop_state_t *runloop_st = runloop_state_get_ptr(); - if (runloop_st->shutdown_initiated && gfx_ctx_mali_fbdev_was_threaded==*video_driver_get_threaded() && !gfx_ctx_mali_fbdev_hw_ctx_trigger) + if (runloop_st->shutdown_initiated) { - gfx_ctx_mali_fbdev_clear_screen(); - }else if (gfx_ctx_mali_fbdev_hw_ctx_trigger) + if (!gfx_ctx_mali_fbdev_restart_pending) + { + gfx_ctx_mali_fbdev_destroy_really(); + gfx_ctx_mali_fbdev_clear_screen(); + } + } + else { - video_context_driver_reset(); - gfx_ctx_mali_fbdev_global=NULL; - gfx_ctx_mali_fbdev_restart_pending=true; - }else if (gfx_ctx_mali_fbdev_was_threaded!=*video_driver_get_threaded()){ - gfx_ctx_mali_fbdev_global=NULL; - command_event(CMD_EVENT_RESTART_RETROARCH,NULL); + if (gfx_ctx_mali_fbdev_hw_ctx_trigger || gfx_ctx_mali_fbdev_was_threaded!=*video_driver_get_threaded()) + { + gfx_ctx_mali_fbdev_destroy_really(); + gfx_ctx_mali_fbdev_restart_pending=true; + if (!gfx_ctx_mali_fbdev_hw_ctx_trigger) + gfx_ctx_mali_fbdev_maybe_restart(); + } } } @@ -244,7 +279,7 @@ static void gfx_ctx_mali_fbdev_check_window(void *data, bool *quit, *quit = (bool)frontend_driver_get_signal_handler_state(); if (gfx_ctx_mali_fbdev_restart_pending) - command_event(CMD_EVENT_RESTART_RETROARCH,NULL); + gfx_ctx_mali_fbdev_maybe_restart(); } static bool gfx_ctx_mali_fbdev_set_video_mode(void *data,