Skip to content

Commit

Permalink
Cut down on update_title code duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
LibretroAdmin committed Jul 16, 2023
1 parent d53b397 commit be65a13
Show file tree
Hide file tree
Showing 23 changed files with 63 additions and 151 deletions.
17 changes: 0 additions & 17 deletions gfx/common/win32_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -2510,23 +2510,6 @@ bool win32_set_video_mode(void *data,
return false;
return true;
}

void win32_update_title(void)
{
const ui_window_t *window = ui_companion_driver_get_window_ptr();
if (window)
{
static char prev_title[128];
char title[128];
title[0] = '\0';
video_driver_get_window_title(title, sizeof(title));
if (title[0] && !string_is_equal(title, prev_title))
{
window->set_title(&main_window, title);
strlcpy(prev_title, title, sizeof(prev_title));
}
}
}
#endif

bool win32_get_client_rect(RECT* rect)
Expand Down
2 changes: 0 additions & 2 deletions gfx/common/win32_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,6 @@ BOOL IsIconic(HWND hwnd);

void win32_setup_pixel_format(HDC hdc, bool supports_gl);

void win32_update_title(void);

RETRO_END_DECLS

#endif
2 changes: 1 addition & 1 deletion gfx/drivers/d3d10.c
Original file line number Diff line number Diff line change
Expand Up @@ -2537,7 +2537,7 @@ static bool d3d10_gfx_frame(
d3d10->flags &= ~D3D10_ST_FLAG_SPRITES_ENABLE;

#ifndef __WINRT__
win32_update_title();
video_driver_update_title(NULL);
#endif
DXGIPresent(d3d10->swapChain, d3d10->swap_interval, 0);

Expand Down
2 changes: 1 addition & 1 deletion gfx/drivers/d3d11.c
Original file line number Diff line number Diff line change
Expand Up @@ -3305,7 +3305,7 @@ static bool d3d11_gfx_frame(
d3d11->flags &= ~D3D11_ST_FLAG_SPRITES_ENABLE;

#if defined(_WIN32) && !defined(__WINRT__)
win32_update_title();
video_driver_update_title(NULL);
#endif

#ifdef HAVE_DXGI_HDR
Expand Down
2 changes: 1 addition & 1 deletion gfx/drivers/d3d12.c
Original file line number Diff line number Diff line change
Expand Up @@ -3826,7 +3826,7 @@ static bool d3d12_gfx_frame(
d3d12->flags &= ~D3D12_ST_FLAG_SPRITES_ENABLE;

#if defined(_WIN32) && !defined(__WINRT__)
win32_update_title();
video_driver_update_title(NULL);
#endif

#ifdef HAVE_DXGI_HDR
Expand Down
21 changes: 1 addition & 20 deletions gfx/drivers/d3d8.c
Original file line number Diff line number Diff line change
Expand Up @@ -1850,25 +1850,6 @@ static void d3d8_get_overlay_interface(void *data,
}
#endif

static void d3d8_update_title(void)
{
#ifndef _XBOX
const ui_window_t *window = ui_companion_driver_get_window_ptr();

if (window)
{
char title[128];

title[0] = '\0';

video_driver_get_window_title(title, sizeof(title));

if (title[0])
window->set_title(&main_window, title);
}
#endif
}

static bool d3d8_frame(void *data, const void *frame,
unsigned frame_width, unsigned frame_height,
uint64_t frame_count, unsigned pitch,
Expand Down Expand Up @@ -1980,7 +1961,7 @@ static bool d3d8_frame(void *data, const void *frame,
IDirect3DDevice8_EndScene(d3d->dev);
}

d3d8_update_title();
video_driver_update_title(NULL);
IDirect3DDevice8_Present(d3d->dev, NULL, NULL, NULL, NULL);

return true;
Expand Down
2 changes: 1 addition & 1 deletion gfx/drivers/d3d9cg.c
Original file line number Diff line number Diff line change
Expand Up @@ -2164,7 +2164,7 @@ static bool d3d9_cg_frame(void *data, const void *frame,
IDirect3DDevice9_EndScene(d3d->dev);
}

win32_update_title();
video_driver_update_title(NULL);
IDirect3DDevice9_Present(d3d->dev, NULL, NULL, NULL, NULL);

return true;
Expand Down
2 changes: 1 addition & 1 deletion gfx/drivers/d3d9hlsl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1754,7 +1754,7 @@ static bool d3d9_hlsl_frame(void *data, const void *frame,
IDirect3DDevice9_EndScene(d3d->dev);
}

win32_update_title();
video_driver_update_title(NULL);
IDirect3DDevice9_Present(d3d->dev, NULL, NULL, NULL, NULL);

return true;
Expand Down
15 changes: 1 addition & 14 deletions gfx/drivers/gdi_gfx.c
Original file line number Diff line number Diff line change
Expand Up @@ -344,19 +344,6 @@ font_renderer_t gdi_font = {
* VIDEO DRIVER
*/

static void gfx_ctx_gdi_update_title(void)
{
char title[128];
const ui_window_t *window = ui_companion_driver_get_window_ptr();

title[0] = '\0';

video_driver_get_window_title(title, sizeof(title));

if (window && title[0])
window->set_title(&main_window, title);
}

static void gfx_ctx_gdi_get_video_size(
unsigned *width, unsigned *height)
{
Expand Down Expand Up @@ -779,7 +766,7 @@ static bool gdi_frame(void *data, const void *frame,

InvalidateRect(hwnd, NULL, false);

gfx_ctx_gdi_update_title();
video_driver_update_title(NULL);

return true;
}
Expand Down
2 changes: 1 addition & 1 deletion gfx/drivers_context/android_vk_ctx.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ static void *android_gfx_ctx_vk_init(void *video_driver)
android_ctx_data_vk_t *and = (android_ctx_data_vk_t*)calloc(1, sizeof(*and));

if (!android_app || !and)
return false;
return NULL;

if (!vulkan_context_init(&and->vk, VULKAN_WSI_ANDROID))
{
Expand Down
2 changes: 1 addition & 1 deletion gfx/drivers_context/cocoa_gl_ctx.m
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ static bool cocoa_gl_gfx_ctx_set_resize(void *data, unsigned width, unsigned hei
cocoa_get_metrics,
NULL, /* translate_aspect */
#ifdef OSX
cocoa_update_title,
video_driver_update_title,
#else
NULL, /* update_title */
#endif
Expand Down
8 changes: 3 additions & 5 deletions gfx/drivers_context/cocoa_vk_ctx.m
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,11 @@

static uint32_t cocoa_vk_gfx_ctx_get_flags(void *data)
{
#if defined(HAVE_SLANG) && defined(HAVE_SPIRV_CROSS)
uint32_t flags = 0;
#if defined(HAVE_SLANG) && defined(HAVE_SPIRV_CROSS)
BIT32_SET(flags, GFX_CTX_FLAGS_SHADERS_SLANG);
return flags;
#else
return 0;
#endif
return flags;
}

static void cocoa_vk_gfx_ctx_set_flags(void *data, uint32_t flags) { }
Expand Down Expand Up @@ -364,7 +362,7 @@ static bool cocoa_vk_gfx_ctx_set_resize(void *data, unsigned width, unsigned hei
cocoa_get_metrics,
NULL, /* translate_aspect */
#ifdef OSX
cocoa_update_title,
video_driver_update_title,
#else
NULL, /* update_title */
#endif
Expand Down
23 changes: 10 additions & 13 deletions gfx/drivers_context/drm_ctx.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ typedef struct hdmi_timings

static enum gfx_ctx_api drm_api = GFX_CTX_NONE;
static drmModeModeInfo gfx_ctx_crt_switch_mode;
static bool switch_mode = false;
static bool switch_mode = false;

static float mode_vrefresh(drmModeModeInfo *mode)
{
Expand Down Expand Up @@ -385,7 +385,7 @@ static bool gfx_ctx_drm_load_mode(drmModeModeInfoPtr modeInfo)
settings_t *settings = config_get_ptr();
char *crt_switch_timings = settings->arrays.crt_switch_timings;

if(modeInfo && !string_is_empty(crt_switch_timings))
if (modeInfo && !string_is_empty(crt_switch_timings))
{
hdmi_timings_t timings;
int ret = sscanf(crt_switch_timings, "%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d",
Expand Down Expand Up @@ -570,8 +570,7 @@ static void gfx_ctx_drm_swap_buffers(void *data)
unsigned max_swapchain_images = settings->uints.video_max_swapchain_images;

/* Recreate the surface */
//*
if(switch_mode)
if (switch_mode)
{
RARCH_DBG("[KMS]: modeswitch detected, doing GBM and EGL stuff\n");
if (drm->gbm_surface)
Expand All @@ -593,9 +592,7 @@ static void gfx_ctx_drm_swap_buffers(void *data)
GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING);

if (!drm->gbm_surface)
{
RARCH_ERR("[KMS/EGL]: Couldn't create GBM surface.\n");
}

/* Creates an EGL surface and make it current */
egl_create_surface(&drm->egl, (EGLNativeWindowType)drm->gbm_surface);
Expand All @@ -617,8 +614,8 @@ static void gfx_ctx_drm_swap_buffers(void *data)
drm->waiting_for_flip = gfx_ctx_drm_queue_flip(drm);

/* Triple-buffered page flips */
if (max_swapchain_images >= 3 &&
gbm_surface_has_free_buffers(drm->gbm_surface))
if ( max_swapchain_images >= 3
&& gbm_surface_has_free_buffers(drm->gbm_surface))
return;

gfx_ctx_drm_wait_flip(drm, true);
Expand Down Expand Up @@ -837,28 +834,28 @@ static bool gfx_ctx_drm_set_video_mode(void *data,
/* Find desired video mode, and use that.
* If not fullscreen, we get desired windowed size,
* which is not appropriate. */
if(gfx_ctx_drm_get_mode_from_video_state(&gfx_ctx_crt_switch_mode))
if (gfx_ctx_drm_get_mode_from_video_state(&gfx_ctx_crt_switch_mode))
{
RARCH_DBG("[KMS]: New mode detected: %dx%d\n", gfx_ctx_crt_switch_mode.hdisplay, gfx_ctx_crt_switch_mode.vdisplay);
g_drm_mode = &gfx_ctx_crt_switch_mode;
g_drm_mode = &gfx_ctx_crt_switch_mode;
drm->fb_width = gfx_ctx_crt_switch_mode.hdisplay;
drm->fb_height = gfx_ctx_crt_switch_mode.vdisplay;
switch_mode = true;
switch_mode = true;
/* Let's exit, since modeswitching will happen while swapping buffers */
return true;
}
if ((width == 0 && height == 0) || !fullscreen)
{
g_drm_mode = &g_drm_connector->modes[0];
RARCH_WARN("[KMS]: Falling back to mode 0 (default)\n");
g_drm_mode = &g_drm_connector->modes[0];
}
else
{
/* check if custom HDMI timings were asked */
if (gfx_ctx_crt_switch_mode.vdisplay > 0)
{
g_drm_mode = &gfx_ctx_crt_switch_mode;
RARCH_LOG("[DRM]: custom mode requested: %s\n", gfx_ctx_crt_switch_mode.name);
g_drm_mode = &gfx_ctx_crt_switch_mode;
}
else
{
Expand Down
4 changes: 1 addition & 3 deletions gfx/drivers_context/khr_display_ctx.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,11 @@ static void gfx_ctx_khr_display_get_video_size(void *data,

static float gfx_ctx_khr_display_get_refresh_rate(void *data)
{
float refresh_rate = 0.0f;
float refresh_rate = 0.0f;
khr_display_ctx_data_t *khr = (khr_display_ctx_data_t*)data;

if (khr)
{
refresh_rate = khr->refresh_rate_x1000 / 1000.0f;
}

return refresh_rate;
}
Expand Down
25 changes: 13 additions & 12 deletions gfx/drivers_context/mali_fbdev_ctx.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ static int gfx_ctx_mali_fbdev_get_vinfo(void *data)
{
struct fb_var_screeninfo vinfo;
int fd = open("/dev/fb0", O_RDWR);

mali_ctx_data_t *mali = (mali_ctx_data_t*)data;

if (!mali || ioctl(fd, FBIOGET_VSCREENINFO, &vinfo) < 0)
Expand Down Expand Up @@ -106,25 +105,25 @@ static int gfx_ctx_mali_fbdev_get_vinfo(void *data)
}
else
{
char tmp[32];
/* 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];
int j = 0;
float k = 60.0f;
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)))
if (filestream_gets(fr, tmp, sizeof(tmp)))
{
int i;
for (i=0;i<sizeof(temp);i++)
for (i = 0; i < sizeof(tmp); i++)
{
if (*(temp+i)=='p' || *(temp+i)=='i')
j=i;
else if (*(temp+i)=='h')
*(temp+i)='\0';
if (*(tmp + i) == 'p' || *(tmp + i) == 'i')
j = i;
else if (*(tmp + i) == 'h')
*(tmp + i) = '\0';
}
k = j ? atof(temp + j + 1) : k;
k = j ? atof(tmp + j + 1) : k;
}
filestream_close(fr);
}
Expand Down Expand Up @@ -205,7 +204,9 @@ static void gfx_ctx_mali_fbdev_destroy(void *data)
}
else
{
if ((mali_flags & GFX_CTX_MALI_FBDEV_FLAG_HW_CTX_TRIGGER) || (bool)(mali_flags & GFX_CTX_MALI_FBDEV_FLAG_WAS_THREADED)!=*video_driver_get_threaded())
if ( (mali_flags & GFX_CTX_MALI_FBDEV_FLAG_HW_CTX_TRIGGER)
|| (bool)(mali_flags & GFX_CTX_MALI_FBDEV_FLAG_WAS_THREADED)
!= *video_driver_get_threaded())
{
gfx_ctx_mali_fbdev_destroy_really();
mali_flags |= GFX_CTX_MALI_FBDEV_FLAG_RESTART_PENDING;
Expand Down
8 changes: 4 additions & 4 deletions gfx/drivers_context/vc_egl_ctx.c
Original file line number Diff line number Diff line change
Expand Up @@ -394,12 +394,12 @@ static void *gfx_ctx_vc_init(void *video_driver)
* can be used to stretch video output. */

/* Calculate source and destination aspect ratios. */
float srcAspect = (float)fullscreen_x / (float)fullscreen_y;
float dstAspect = (float)vc->fb_width / (float)vc->fb_height;
float src_aspect = (float)fullscreen_x / (float)fullscreen_y;
float dst_aspect = (float)vc->fb_width / (float)vc->fb_height;

/* If source and destination aspect ratios are not equal correct source width. */
if (srcAspect != dstAspect)
vc->native_window.width = (unsigned)(fullscreen_y * dstAspect);
if (src_aspect != dst_aspect)
vc->native_window.width = (unsigned)(fullscreen_y * dst_aspect);
else
vc->native_window.width = fullscreen_x;
vc->native_window.height = fullscreen_y;
Expand Down
18 changes: 1 addition & 17 deletions gfx/drivers_context/w_vk_ctx.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,22 +136,6 @@ static bool gfx_ctx_w_vk_set_resize(void *data,
return false;
}

static void gfx_ctx_w_vk_update_title(void *data)
{
char title[128];
title[0] = '\0';

video_driver_get_window_title(title, sizeof(title));

if (title[0])
{
const ui_window_t *window = ui_companion_driver_get_window_ptr();

if (window)
window->set_title(&main_window, title);
}
}

static void gfx_ctx_w_vk_destroy(void *data)
{
HWND window = win32_get_window();
Expand Down Expand Up @@ -312,7 +296,7 @@ const gfx_ctx_driver_t gfx_ctx_w_vk = {
gfx_ctx_w_vk_get_video_output_next,
win32_get_metrics,
NULL,
gfx_ctx_w_vk_update_title,
video_driver_update_title,
gfx_ctx_w_vk_check_window,
gfx_ctx_w_vk_set_resize,
win32_has_focus,
Expand Down
Loading

0 comments on commit be65a13

Please sign in to comment.