Skip to content

Commit

Permalink
Remove some code duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
LibretroAdmin committed Jun 20, 2023
1 parent 700b58a commit 5971f24
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 85 deletions.
24 changes: 24 additions & 0 deletions gfx/common/win32_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
14 changes: 14 additions & 0 deletions gfx/display_servers/dispserv_android.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,20 @@ bool android_display_get_metrics(void *data,
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,
Expand Down
17 changes: 2 additions & 15 deletions gfx/drivers_context/android_ctx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down
16 changes: 2 additions & 14 deletions gfx/drivers_context/android_vk_ctx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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; }

Expand Down Expand Up @@ -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,
Expand Down
30 changes: 4 additions & 26 deletions gfx/drivers_context/w_vk_ctx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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));
Expand All @@ -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();
Expand Down Expand Up @@ -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,
Expand Down
29 changes: 4 additions & 25 deletions gfx/drivers_context/wgl_ctx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 1 addition & 5 deletions libretro-common/lists/file_list.c
Original file line number Diff line number Diff line change
Expand Up @@ -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_)
Expand Down

0 comments on commit 5971f24

Please sign in to comment.