(Wayland) Cleanups

This commit is contained in:
libretroadmin 2023-06-20 07:08:14 +02:00
parent 103982f41d
commit 6a147370d0
4 changed files with 86 additions and 114 deletions

View File

@ -318,7 +318,6 @@ void egl_bind_hw_render(egl_ctx_data_t *egl, bool enable)
return; return;
if (egl->surf == EGL_NO_SURFACE) if (egl->surf == EGL_NO_SURFACE)
return; return;
_egl_make_current(egl->dpy, egl->surf, _egl_make_current(egl->dpy, egl->surf,
egl->surf, egl->surf,
enable ? egl->hw_ctx : egl->ctx); enable ? egl->hw_ctx : egl->ctx);

View File

@ -40,7 +40,7 @@
#define DEFAULT_WINDOWED_WIDTH 640 #define DEFAULT_WINDOWED_WIDTH 640
#define DEFAULT_WINDOWED_HEIGHT 480 #define DEFAULT_WINDOWED_HEIGHT 480
// Icon is 16x15 scaled by 16 /* Icon is 16x15 scaled by 16 */
#define SPLASH_WINDOW_WIDTH 240 #define SPLASH_WINDOW_WIDTH 240
#define SPLASH_WINDOW_HEIGHT 256 #define SPLASH_WINDOW_HEIGHT 256
@ -127,8 +127,8 @@ void xdg_toplevel_handle_configure_common(gfx_ctx_wayland_data_t *wl,
height = wl->floating_height; height = wl->floating_height;
} }
if ( width > 0 if ( (width > 0)
&& height > 0) && (height > 0))
{ {
wl->width = width; wl->width = width;
wl->height = height; wl->height = height;
@ -147,11 +147,7 @@ void xdg_toplevel_handle_configure_common(gfx_ctx_wayland_data_t *wl,
} }
void xdg_toplevel_handle_close(void *data, void xdg_toplevel_handle_close(void *data,
struct xdg_toplevel *xdg_toplevel) struct xdg_toplevel *xdg_toplevel) { command_event(CMD_EVENT_QUIT, NULL); }
{
gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)data;
command_event(CMD_EVENT_QUIT, NULL);
}
#ifdef HAVE_LIBDECOR_H #ifdef HAVE_LIBDECOR_H
void libdecor_frame_handle_configure_common(struct libdecor_frame *frame, void libdecor_frame_handle_configure_common(struct libdecor_frame *frame,
@ -218,23 +214,18 @@ void libdecor_frame_handle_configure_common(struct libdecor_frame *frame,
} }
void libdecor_frame_handle_close(struct libdecor_frame *frame, void libdecor_frame_handle_close(struct libdecor_frame *frame,
void *data) void *data) { command_event(CMD_EVENT_QUIT, NULL); }
{
gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)data;
command_event(CMD_EVENT_QUIT, NULL);
}
void libdecor_frame_handle_commit(struct libdecor_frame *frame, void libdecor_frame_handle_commit(struct libdecor_frame *frame,
void *data) void *data) { }
{
gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)data;
}
#endif #endif
void gfx_ctx_wl_get_video_size_common(gfx_ctx_wayland_data_t *wl, void gfx_ctx_wl_get_video_size_common(void *data,
unsigned *width, unsigned *height) unsigned *width, unsigned *height)
{ {
gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)data;
if (!wl)
return;
if (!wl->reported_display_size) if (!wl->reported_display_size)
{ {
display_output_t *od; display_output_t *od;
@ -367,24 +358,27 @@ void gfx_ctx_wl_destroy_resources_common(gfx_ctx_wayland_data_t *wl)
wl->buffer_height = 0; wl->buffer_height = 0;
} }
void gfx_ctx_wl_update_title_common(gfx_ctx_wayland_data_t *wl) void gfx_ctx_wl_update_title_common(void *data)
{ {
char title[128]; char title[128];
gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)data;
title[0] = '\0'; title[0] = '\0';
video_driver_get_window_title(title, sizeof(title)); video_driver_get_window_title(title, sizeof(title));
if (wl)
{
#ifdef HAVE_LIBDECOR_H #ifdef HAVE_LIBDECOR_H
if (wl->libdecor) if (wl->libdecor)
{ {
if (wl && title[0]) if (title[0])
wl->libdecor_frame_set_title(wl->libdecor_frame, title); wl->libdecor_frame_set_title(wl->libdecor_frame, title);
} }
else else
#endif #endif
{ {
if (wl && title[0]) if (title[0])
{ {
if (wl->deco) if (wl->deco)
zxdg_toplevel_decoration_v1_set_mode(wl->deco, zxdg_toplevel_decoration_v1_set_mode(wl->deco,
@ -392,13 +386,14 @@ void gfx_ctx_wl_update_title_common(gfx_ctx_wayland_data_t *wl)
xdg_toplevel_set_title(wl->xdg_toplevel, title); xdg_toplevel_set_title(wl->xdg_toplevel, title);
} }
} }
}
} }
bool gfx_ctx_wl_get_metrics_common(void *data, bool gfx_ctx_wl_get_metrics_common(void *data,
enum display_metric_types type, float *value) enum display_metric_types type, float *value)
{ {
gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)data;
display_output_t *od; display_output_t *od;
gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)data;
output_info_t *oi = wl ? wl->current_output : NULL; output_info_t *oi = wl ? wl->current_output : NULL;
if (!oi) if (!oi)
@ -419,8 +414,8 @@ bool gfx_ctx_wl_get_metrics_common(void *data,
break; break;
case DISPLAY_METRIC_DPI: case DISPLAY_METRIC_DPI:
*value = (float)oi->width * 25.4f / *value = (float)oi->width * 25.4f
(float)oi->physical_width; / (float)oi->physical_width;
break; break;
default: default:
@ -745,11 +740,12 @@ bool gfx_ctx_wl_init_common(
/* Bind SHM based wl_buffer to wl_surface until the vulkan surface is ready. /* Bind SHM based wl_buffer to wl_surface until the vulkan surface is ready.
* This shows the window which assigns us a display (wl_output) * This shows the window which assigns us a display (wl_output)
* which is usefull for HiDPI and auto selecting a display for fullscreen. */ * which is usefull for HiDPI and auto selecting a display for fullscreen. */
if (video_monitor_index == 0 && wl_list_length (&wl->all_outputs) > 1) { if (video_monitor_index == 0 && wl_list_length (&wl->all_outputs) > 1)
{
if (!wl_draw_splash_screen(wl)) if (!wl_draw_splash_screen(wl))
RARCH_ERR("[Wayland]: Failed to draw splash screen\n"); RARCH_ERR("[Wayland]: Failed to draw splash screen\n");
// Make sure splash screen is on screen and sized /* Make sure splash screen is on screen and sized */
#ifdef HAVE_LIBDECOR_H #ifdef HAVE_LIBDECOR_H
if (wl->libdecor) if (wl->libdecor)
{ {
@ -892,9 +888,8 @@ bool gfx_ctx_wl_suppress_screensaver(void *data, bool state)
if (!wl->idle_inhibit_manager) if (!wl->idle_inhibit_manager)
return false; return false;
if (state == (!!wl->idle_inhibitor)) if (state != (!!wl->idle_inhibitor))
return true; {
if (state) if (state)
{ {
RARCH_LOG("[Wayland]: Enabling idle inhibitor\n"); RARCH_LOG("[Wayland]: Enabling idle inhibitor\n");
@ -907,17 +902,17 @@ bool gfx_ctx_wl_suppress_screensaver(void *data, bool state)
zwp_idle_inhibitor_v1_destroy(wl->idle_inhibitor); zwp_idle_inhibitor_v1_destroy(wl->idle_inhibitor);
wl->idle_inhibitor = NULL; wl->idle_inhibitor = NULL;
} }
}
return true; return true;
} }
float gfx_ctx_wl_get_refresh_rate(void *data) float gfx_ctx_wl_get_refresh_rate(void *data)
{ {
gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)data; gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)data;
if (!wl || !wl->current_output) if (!wl || !wl->current_output)
return false; return false;
return (float)wl->current_output->refresh_rate / 1000.0f;
return (float) wl->current_output->refresh_rate / 1000.0f;
} }
bool gfx_ctx_wl_has_focus(void *data) bool gfx_ctx_wl_has_focus(void *data)
@ -961,8 +956,8 @@ static void shm_buffer_handle_release(void *data,
} }
#if 0 #if 0
static void xdg_surface_handle_configure(void *data, struct xdg_surface *surface, static void xdg_surface_handle_configure(void *data,
uint32_t serial) struct xdg_surface *surface, uint32_t serial)
{ {
xdg_surface_ack_configure(surface, serial); xdg_surface_ack_configure(surface, serial);
} }

View File

@ -53,12 +53,12 @@ void libdecor_frame_handle_commit(struct libdecor_frame *frame,
void *data); void *data);
#endif #endif
void gfx_ctx_wl_get_video_size_common(gfx_ctx_wayland_data_t *wl, void gfx_ctx_wl_get_video_size_common(void *data, unsigned *width,
unsigned *width, unsigned *height); unsigned *height);
void gfx_ctx_wl_destroy_resources_common(gfx_ctx_wayland_data_t *wl); void gfx_ctx_wl_destroy_resources_common(gfx_ctx_wayland_data_t *wl);
void gfx_ctx_wl_update_title_common(gfx_ctx_wayland_data_t *wl); void gfx_ctx_wl_update_title_common(void *data);
bool gfx_ctx_wl_get_metrics_common(void *data, bool gfx_ctx_wl_get_metrics_common(void *data,
enum display_metric_types type, float *value); enum display_metric_types type, float *value);

View File

@ -79,14 +79,6 @@ static void xdg_toplevel_handle_configure(void *data,
wl->configured = false; wl->configured = false;
} }
static void gfx_ctx_wl_get_video_size(void *data,
unsigned *width, unsigned *height)
{
gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)data;
gfx_ctx_wl_get_video_size_common(wl, width, height);
}
static void gfx_ctx_wl_destroy_resources(gfx_ctx_wayland_data_t *wl) static void gfx_ctx_wl_destroy_resources(gfx_ctx_wayland_data_t *wl)
{ {
if (!wl) if (!wl)
@ -110,7 +102,7 @@ static void gfx_ctx_wl_check_window(void *data, bool *quit,
bool *resize, unsigned *width, unsigned *height) bool *resize, unsigned *width, unsigned *height)
{ {
gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)data; gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)data;
gfx_ctx_wl_check_window_common(wl, gfx_ctx_wl_get_video_size, quit, resize, width, height); gfx_ctx_wl_check_window_common(wl, gfx_ctx_wl_get_video_size_common, quit, resize, width, height);
} }
static bool gfx_ctx_wl_set_resize(void *data, unsigned width, unsigned height) static bool gfx_ctx_wl_set_resize(void *data, unsigned width, unsigned height)
@ -127,19 +119,6 @@ static bool gfx_ctx_wl_set_resize(void *data, unsigned width, unsigned height)
return true; return true;
} }
static void gfx_ctx_wl_update_title(void *data)
{
gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)data;
gfx_ctx_wl_update_title_common(wl);
}
static bool gfx_ctx_wl_get_metrics(void *data,
enum display_metric_types type, float *value)
{
gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)data;
return gfx_ctx_wl_get_metrics_common(wl, type, value);
}
#ifdef HAVE_LIBDECOR_H #ifdef HAVE_LIBDECOR_H
static void static void
libdecor_frame_handle_configure(struct libdecor_frame *frame, libdecor_frame_handle_configure(struct libdecor_frame *frame,
@ -474,7 +453,7 @@ static bool gfx_ctx_wl_bind_api(void *data,
#ifdef HAVE_OPENGL #ifdef HAVE_OPENGL
#ifndef EGL_KHR_create_context #ifndef EGL_KHR_create_context
if ((major * 1000 + minor) >= 3001) if ((major * 1000 + minor) >= 3001)
return false; break;
#endif #endif
#ifdef HAVE_EGL #ifdef HAVE_EGL
if (egl_bind_api(EGL_OPENGL_API)) if (egl_bind_api(EGL_OPENGL_API))
@ -486,7 +465,7 @@ static bool gfx_ctx_wl_bind_api(void *data,
#ifdef HAVE_OPENGLES #ifdef HAVE_OPENGLES
#ifndef EGL_KHR_create_context #ifndef EGL_KHR_create_context
if (major >= 3) if (major >= 3)
return false; break;
#endif #endif
#ifdef HAVE_EGL #ifdef HAVE_EGL
if (egl_bind_api(EGL_OPENGL_ES_API)) if (egl_bind_api(EGL_OPENGL_ES_API))
@ -527,11 +506,10 @@ static const struct wl_callback_listener wl_surface_frame_listener = {
static void gfx_ctx_wl_swap_buffers(void *data) static void gfx_ctx_wl_swap_buffers(void *data)
{ {
#ifdef HAVE_EGL #ifdef HAVE_EGL
struct wl_callback *cb;
gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)data; gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)data;
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
unsigned max_swapchain_images = settings->uints.video_max_swapchain_images; unsigned max_swapchain_images = settings->uints.video_max_swapchain_images;
struct wl_callback *cb;
if (max_swapchain_images <= 2) if (max_swapchain_images <= 2)
{ {
@ -628,14 +606,14 @@ const gfx_ctx_driver_t gfx_ctx_wayland = {
gfx_ctx_wl_bind_api, gfx_ctx_wl_bind_api,
gfx_ctx_wl_set_swap_interval, gfx_ctx_wl_set_swap_interval,
gfx_ctx_wl_set_video_mode, gfx_ctx_wl_set_video_mode,
gfx_ctx_wl_get_video_size, gfx_ctx_wl_get_video_size_common,
gfx_ctx_wl_get_refresh_rate, gfx_ctx_wl_get_refresh_rate,
NULL, /* get_video_output_size */ NULL, /* get_video_output_size */
NULL, /* get_video_output_prev */ NULL, /* get_video_output_prev */
NULL, /* get_video_output_next */ NULL, /* get_video_output_next */
gfx_ctx_wl_get_metrics, gfx_ctx_wl_get_metrics_common,
NULL, NULL,
gfx_ctx_wl_update_title, gfx_ctx_wl_update_title_common,
gfx_ctx_wl_check_window, gfx_ctx_wl_check_window,
gfx_ctx_wl_set_resize, gfx_ctx_wl_set_resize,
gfx_ctx_wl_has_focus, gfx_ctx_wl_has_focus,