Remove some code duplication

This commit is contained in:
libretroadmin 2023-06-20 09:37:07 +02:00
parent 700b58a77a
commit 5971f24237
7 changed files with 51 additions and 85 deletions

View File

@ -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(&current_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 */

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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(&current_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,

View File

@ -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(&current_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,

View File

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