From 5971f24237b9063a01b56064070853851f15b662 Mon Sep 17 00:00:00 2001 From: libretroadmin Date: Tue, 20 Jun 2023 09:37:07 +0200 Subject: [PATCH] Remove some code duplication --- gfx/common/win32_common.c | 24 +++++++++++++++++++++ gfx/display_servers/dispserv_android.c | 14 ++++++++++++ gfx/drivers_context/android_ctx.c | 17 ++------------- gfx/drivers_context/android_vk_ctx.c | 16 ++------------ gfx/drivers_context/w_vk_ctx.c | 30 ++++---------------------- gfx/drivers_context/wgl_ctx.c | 29 ++++--------------------- libretro-common/lists/file_list.c | 6 +----- 7 files changed, 51 insertions(+), 85 deletions(-) diff --git a/gfx/common/win32_common.c b/gfx/common/win32_common.c index 7ea3563524..3257d9b50e 100644 --- a/gfx/common/win32_common.c +++ b/gfx/common/win32_common.c @@ -478,6 +478,30 @@ void win32_monitor_info(void *data, void *hm_data, unsigned *mon_id) } } +void win32_get_video_size(void *data, + unsigned *width, unsigned *height) +{ + HWND window = win32_get_window(); + + if (window) + { + *width = g_win32_resize_width; + *height = g_win32_resize_height; + } + else + { + RECT mon_rect; + MONITORINFOEX current_mon; + unsigned mon_id = 0; + HMONITOR hm_to_use = NULL; + + win32_monitor_info(¤t_mon, &hm_to_use, &mon_id); + mon_rect = current_mon.rcMonitor; + *width = mon_rect.right - mon_rect.left; + *height = mon_rect.bottom - mon_rect.top; + } +} + bool win32_load_content_from_gui(const char *szFilename) { /* poll list of current cores */ diff --git a/gfx/display_servers/dispserv_android.c b/gfx/display_servers/dispserv_android.c index ed864fde4a..47f008604e 100644 --- a/gfx/display_servers/dispserv_android.c +++ b/gfx/display_servers/dispserv_android.c @@ -106,6 +106,20 @@ dpi_fallback: return true; } +bool android_display_has_focus(void *data) +{ + bool focused = false; + struct android_app *android_app = (struct android_app*)g_android; + if (!android_app) + return true; + + slock_lock(android_app->mutex); + focused = !android_app->unfocused; + slock_unlock(android_app->mutex); + + return focused; +} + const video_display_server_t dispserv_android = { android_display_server_init, android_display_server_destroy, diff --git a/gfx/drivers_context/android_ctx.c b/gfx/drivers_context/android_ctx.c index caf459c33c..b1528d9286 100644 --- a/gfx/drivers_context/android_ctx.c +++ b/gfx/drivers_context/android_ctx.c @@ -56,6 +56,7 @@ static bool g_es3 = false; /* FORWARD DECLARATION */ bool android_display_get_metrics(void *data, enum display_metric_types type, float *value); +bool android_display_has_focus(void *data); static void android_gfx_ctx_destroy(void *data) { @@ -234,20 +235,6 @@ static bool android_gfx_ctx_bind_api(void *data, return false; } -static bool android_gfx_ctx_has_focus(void *data) -{ - bool focused = false; - struct android_app *android_app = (struct android_app*)g_android; - if (!android_app) - return true; - - slock_lock(android_app->mutex); - focused = !android_app->unfocused; - slock_unlock(android_app->mutex); - - return focused; -} - static bool android_gfx_ctx_suppress_screensaver(void *data, bool enable) { return false; } static void android_gfx_ctx_swap_buffers(void *data) @@ -304,7 +291,7 @@ const gfx_ctx_driver_t gfx_ctx_android = { NULL, /* update_title */ android_gfx_ctx_check_window, android_gfx_ctx_set_resize, - android_gfx_ctx_has_focus, + android_display_has_focus, android_gfx_ctx_suppress_screensaver, false, /* has_windowed */ android_gfx_ctx_swap_buffers, diff --git a/gfx/drivers_context/android_vk_ctx.c b/gfx/drivers_context/android_vk_ctx.c index 50767b341d..c6563f954f 100644 --- a/gfx/drivers_context/android_vk_ctx.c +++ b/gfx/drivers_context/android_vk_ctx.c @@ -44,6 +44,7 @@ typedef struct /* FORWARD DECLARATION */ bool android_display_get_metrics(void *data, enum display_metric_types type, float *value); +bool android_display_has_focus(void *data); static void android_gfx_ctx_vk_destroy(void *data) { @@ -193,19 +194,6 @@ static bool android_gfx_ctx_vk_bind_api(void *data, return (api == GFX_CTX_VULKAN_API); } -static bool android_gfx_ctx_vk_has_focus(void *data) -{ - bool focused = false; - struct android_app *android_app = (struct android_app*)g_android; - if (!android_app) - return true; - - slock_lock(android_app->mutex); - focused = !android_app->unfocused; - slock_unlock(android_app->mutex); - - return focused; -} static bool android_gfx_ctx_vk_suppress_screensaver(void *data, bool enable) { return false; } @@ -278,7 +266,7 @@ const gfx_ctx_driver_t gfx_ctx_vk_android = { NULL, /* update_title */ android_gfx_ctx_vk_check_window, android_gfx_ctx_vk_set_resize, - android_gfx_ctx_vk_has_focus, + android_display_has_focus, android_gfx_ctx_vk_suppress_screensaver, false, /* has_windowed */ android_gfx_ctx_vk_swap_buffers, diff --git a/gfx/drivers_context/w_vk_ctx.c b/gfx/drivers_context/w_vk_ctx.c index bc5abb20e9..e7c1822e6c 100644 --- a/gfx/drivers_context/w_vk_ctx.c +++ b/gfx/drivers_context/w_vk_ctx.c @@ -60,6 +60,9 @@ gfx_ctx_vulkan_data_t win32_vk; static void *dinput_vk = NULL; int win32_vk_interval = 0; +/* FORWARD DECLARATIONS */ +void win32_get_video_size(void *data, unsigned *width, unsigned *height); + static void gfx_ctx_w_vk_swap_interval(void *data, int interval) { if (win32_vk_interval != interval) @@ -136,7 +139,6 @@ static bool gfx_ctx_w_vk_set_resize(void *data, static void gfx_ctx_w_vk_update_title(void *data) { char title[128]; - title[0] = '\0'; video_driver_get_window_title(title, sizeof(title)); @@ -150,30 +152,6 @@ static void gfx_ctx_w_vk_update_title(void *data) } } -static void gfx_ctx_w_vk_get_video_size(void *data, - unsigned *width, unsigned *height) -{ - HWND window = win32_get_window(); - - if (!window) - { - RECT mon_rect; - MONITORINFOEX current_mon; - unsigned mon_id = 0; - HMONITOR hm_to_use = NULL; - - win32_monitor_info(¤t_mon, &hm_to_use, &mon_id); - mon_rect = current_mon.rcMonitor; - *width = mon_rect.right - mon_rect.left; - *height = mon_rect.bottom - mon_rect.top; - } - else - { - *width = g_win32_resize_width; - *height = g_win32_resize_height; - } -} - static void gfx_ctx_w_vk_destroy(void *data) { HWND window = win32_get_window(); @@ -335,7 +313,7 @@ const gfx_ctx_driver_t gfx_ctx_w_vk = { gfx_ctx_w_vk_bind_api, gfx_ctx_w_vk_swap_interval, gfx_ctx_w_vk_set_video_mode, - gfx_ctx_w_vk_get_video_size, + win32_get_video_size, win32_get_refresh_rate, gfx_ctx_w_vk_get_video_output_size, gfx_ctx_w_vk_get_video_output_prev, diff --git a/gfx/drivers_context/wgl_ctx.c b/gfx/drivers_context/wgl_ctx.c index aa7ca4cbf4..f2519cf21e 100644 --- a/gfx/drivers_context/wgl_ctx.c +++ b/gfx/drivers_context/wgl_ctx.c @@ -123,6 +123,9 @@ typedef struct gfx_ctx_cgl_data void *empty; } gfx_ctx_wgl_data_t; +/* FORWARD DECLARATIONS */ +void win32_get_video_size(void *data, unsigned *width, unsigned *height); + static gfx_ctx_proc_t gfx_ctx_wgl_get_proc_address(const char *symbol) { #if (defined(HAVE_OPENGL) || defined(HAVE_OPENGL1) || defined(HAVE_OPENGL_CORE)) && !defined(HAVE_OPENGLES) @@ -487,30 +490,6 @@ static void gfx_ctx_wgl_update_title(void *data) } } -static void gfx_ctx_wgl_get_video_size(void *data, - unsigned *width, unsigned *height) -{ - HWND window = win32_get_window(); - - if (window) - { - *width = g_win32_resize_width; - *height = g_win32_resize_height; - } - else - { - RECT mon_rect; - MONITORINFOEX current_mon; - unsigned mon_id = 0; - HMONITOR hm_to_use = NULL; - - win32_monitor_info(¤t_mon, &hm_to_use, &mon_id); - mon_rect = current_mon.rcMonitor; - *width = mon_rect.right - mon_rect.left; - *height = mon_rect.bottom - mon_rect.top; - } -} - static void gfx_ctx_wgl_destroy(void *data) { HWND window = win32_get_window(); @@ -814,7 +793,7 @@ const gfx_ctx_driver_t gfx_ctx_wgl = { gfx_ctx_wgl_bind_api, gfx_ctx_wgl_swap_interval, gfx_ctx_wgl_set_video_mode, - gfx_ctx_wgl_get_video_size, + win32_get_video_size, win32_get_refresh_rate, gfx_ctx_wgl_get_video_output_size, gfx_ctx_wgl_get_video_output_prev, diff --git a/libretro-common/lists/file_list.c b/libretro-common/lists/file_list.c index e7a4e9cbb9..ba1bba7707 100644 --- a/libretro-common/lists/file_list.c +++ b/libretro-common/lists/file_list.c @@ -239,13 +239,9 @@ void file_list_set_alt_at_offset(file_list_t *list, size_t idx, { if (!list || !alt) return; - if (list->list[idx].alt) free(list->list[idx].alt); - list->list[idx].alt = NULL; - - if (alt) - list->list[idx].alt = strdup(alt); + list->list[idx].alt = strdup(alt); } static int file_list_alt_cmp(const void *a_, const void *b_)