(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

@ -300,11 +300,11 @@ void egl_destroy(egl_ctx_data_t *egl)
* If we screw up, any TTY will not restore. * If we screw up, any TTY will not restore.
*/ */
egl->ctx = EGL_NO_CONTEXT; egl->ctx = EGL_NO_CONTEXT;
egl->hw_ctx = EGL_NO_CONTEXT; egl->hw_ctx = EGL_NO_CONTEXT;
egl->surf = EGL_NO_SURFACE; egl->surf = EGL_NO_SURFACE;
egl->dpy = EGL_NO_DISPLAY; egl->dpy = EGL_NO_DISPLAY;
egl->config = 0; egl->config = 0;
g_egl_inited = false; g_egl_inited = false;
frontend_driver_destroy_signal_handler_state(); frontend_driver_destroy_signal_handler_state();
@ -312,13 +312,12 @@ void egl_destroy(egl_ctx_data_t *egl)
void egl_bind_hw_render(egl_ctx_data_t *egl, bool enable) void egl_bind_hw_render(egl_ctx_data_t *egl, bool enable)
{ {
egl->use_hw_ctx = enable; egl->use_hw_ctx = enable;
if (egl->dpy == EGL_NO_DISPLAY) if (egl->dpy == EGL_NO_DISPLAY)
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
@ -89,7 +89,7 @@ void xdg_toplevel_handle_configure_common(gfx_ctx_wayland_data_t *wl,
int32_t width, int32_t height, struct wl_array *states) int32_t width, int32_t height, struct wl_array *states)
{ {
const uint32_t *state; const uint32_t *state;
bool floating = true; bool floating = true;
wl->fullscreen = false; wl->fullscreen = false;
wl->maximized = false; wl->maximized = false;
@ -100,23 +100,23 @@ void xdg_toplevel_handle_configure_common(gfx_ctx_wayland_data_t *wl,
{ {
case XDG_TOPLEVEL_STATE_FULLSCREEN: case XDG_TOPLEVEL_STATE_FULLSCREEN:
wl->fullscreen = true; wl->fullscreen = true;
floating = false; floating = false;
break; break;
case XDG_TOPLEVEL_STATE_MAXIMIZED: case XDG_TOPLEVEL_STATE_MAXIMIZED:
wl->maximized = true; wl->maximized = true;
floating = false; floating = false;
break; break;
case XDG_TOPLEVEL_STATE_TILED_LEFT: case XDG_TOPLEVEL_STATE_TILED_LEFT:
case XDG_TOPLEVEL_STATE_TILED_RIGHT: case XDG_TOPLEVEL_STATE_TILED_RIGHT:
case XDG_TOPLEVEL_STATE_TILED_TOP: case XDG_TOPLEVEL_STATE_TILED_TOP:
case XDG_TOPLEVEL_STATE_TILED_BOTTOM: case XDG_TOPLEVEL_STATE_TILED_BOTTOM:
floating = false; floating = false;
break; break;
case XDG_TOPLEVEL_STATE_RESIZING: case XDG_TOPLEVEL_STATE_RESIZING:
wl->resize = true; wl->resize = true;
break; break;
case XDG_TOPLEVEL_STATE_ACTIVATED: case XDG_TOPLEVEL_STATE_ACTIVATED:
wl->activated = true; wl->activated = true;
break; break;
} }
} }
@ -127,14 +127,14 @@ 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;
wl->buffer_width = wl->width * wl->buffer_scale; wl->buffer_width = wl->width * wl->buffer_scale;
wl->buffer_height = wl->height * wl->buffer_scale; wl->buffer_height = wl->height * wl->buffer_scale;
wl->resize = true; wl->resize = true;
if (wl->viewport) if (wl->viewport)
update_viewport(wl); update_viewport(wl);
} }
@ -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;
@ -361,35 +352,39 @@ void gfx_ctx_wl_destroy_resources_common(gfx_ctx_wayland_data_t *wl)
wl->wl_pointer = NULL; wl->wl_pointer = NULL;
wl->wl_keyboard = NULL; wl->wl_keyboard = NULL;
wl->width = 0; wl->width = 0;
wl->height = 0; wl->height = 0;
wl->buffer_width = 0; wl->buffer_width = 0;
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])
wl->libdecor_frame_set_title(wl->libdecor_frame, title);
}
else
#endif
{
if (wl && title[0])
{ {
if (wl->deco) if (title[0])
zxdg_toplevel_decoration_v1_set_mode(wl->deco, wl->libdecor_frame_set_title(wl->libdecor_frame, title);
ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE); }
xdg_toplevel_set_title(wl->xdg_toplevel, title); else
#endif
{
if (title[0])
{
if (wl->deco)
zxdg_toplevel_decoration_v1_set_mode(wl->deco,
ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE);
xdg_toplevel_set_title(wl->xdg_toplevel, title);
}
} }
} }
} }
@ -397,8 +392,8 @@ void gfx_ctx_wl_update_title_common(gfx_ctx_wayland_data_t *wl)
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)
{ {
@ -842,7 +838,7 @@ bool gfx_ctx_wl_set_video_mode_common_fullscreen(gfx_ctx_wayland_data_t *wl,
if (video_monitor_index <= 0 && wl->current_output != NULL) if (video_monitor_index <= 0 && wl->current_output != NULL)
{ {
oi = wl->current_output; oi = wl->current_output;
output = oi->output; output = oi->output;
RARCH_LOG("[Wayland]: Auto fullscreen on display \"%s\" \"%s\"\n", oi->make, oi->model); RARCH_LOG("[Wayland]: Auto fullscreen on display \"%s\" \"%s\"\n", oi->make, oi->model);
} }
@ -892,32 +888,31 @@ 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)
{
RARCH_LOG("[Wayland]: Enabling idle inhibitor\n");
struct zwp_idle_inhibit_manager_v1 *mgr = wl->idle_inhibit_manager;
wl->idle_inhibitor = zwp_idle_inhibit_manager_v1_create_inhibitor(mgr, wl->surface);
}
else
{
RARCH_LOG("[Wayland]: Disabling the idle inhibitor\n");
zwp_idle_inhibitor_v1_destroy(wl->idle_inhibitor);
wl->idle_inhibitor = NULL;
}
}
if (state)
{
RARCH_LOG("[Wayland]: Enabling idle inhibitor\n");
struct zwp_idle_inhibit_manager_v1 *mgr = wl->idle_inhibit_manager;
wl->idle_inhibitor = zwp_idle_inhibit_manager_v1_create_inhibitor(mgr, wl->surface);
}
else
{
RARCH_LOG("[Wayland]: Disabling the idle inhibitor\n");
zwp_idle_inhibitor_v1_destroy(wl->idle_inhibitor);
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,14 +102,14 @@ 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)
{ {
gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)data; gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)data;
wl->last_buffer_scale = wl->buffer_scale; wl->last_buffer_scale = wl->buffer_scale;
wl_surface_set_buffer_scale(wl->surface, wl->buffer_scale); wl_surface_set_buffer_scale(wl->surface, wl->buffer_scale);
#ifdef HAVE_EGL #ifdef HAVE_EGL
@ -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,
@ -155,7 +134,7 @@ libdecor_frame_handle_configure(struct libdecor_frame *frame,
wl->buffer_height, wl->buffer_height,
0, 0); 0, 0);
else else
wl->win = wl_egl_window_create( wl->win = wl_egl_window_create(
wl->surface, wl->surface,
wl->buffer_width, wl->buffer_width,
wl->buffer_height); wl->buffer_height);
@ -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
gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)data; struct wl_callback *cb;
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,