(Wayland) Fix wayland vulkan not reacting to initial resize (#13640)

(Wayland) Correct log stamps for GL or Vulkan

(Wayland) Fix style issues and sync formatting on identical code in GL and Vulkan
This commit is contained in:
Colin Kinloch 2022-02-22 07:58:46 +00:00 committed by GitHub
parent 023f427856
commit 6dec52fda7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 181 additions and 165 deletions

View File

@ -25,11 +25,6 @@
#include "../../config.h"
#endif
#ifdef HAVE_EGL
#include <wayland-egl.h>
#include "../common/egl_common.h"
#endif
#ifdef HAVE_LIBDECOR
#include <libdecor.h>
#endif
@ -49,6 +44,11 @@
/* Generated from xdg-decoration-unstable-v1.h */
#include "../common/wayland/xdg-decoration-unstable-v1.h"
#ifdef HAVE_EGL
#include <wayland-egl.h>
#include "../common/egl_common.h"
#endif
static enum gfx_ctx_api wl_api = GFX_CTX_NONE;
#ifndef EGL_OPENGL_ES3_BIT_KHR
@ -93,8 +93,6 @@ static void handle_toplevel_config_common(void *data,
if ( width > 0
&& height > 0)
{
wl->prev_width = width;
wl->prev_height = height;
wl->width = width;
wl->height = height;
}
@ -234,8 +232,8 @@ static void gfx_ctx_wl_check_window(void *data, bool *quit,
gfx_ctx_wl_get_video_size(data, &new_width, &new_height);
if ( new_width != *width * wl->last_buffer_scale ||
new_height != *height * wl->last_buffer_scale)
if ( new_width != *width * wl->last_buffer_scale
|| new_height != *height * wl->last_buffer_scale)
{
*width = new_width;
*height = new_height;
@ -322,7 +320,7 @@ static void
handle_libdecor_error(struct libdecor *context,
enum libdecor_error error, const char *message)
{
RARCH_ERR("[Wayland]: libdecor Caught error (%d): %s\n", error, message);
RARCH_ERR("[Wayland/GL]: libdecor Caught error (%d): %s\n", error, message);
}
static struct libdecor_interface libdecor_interface = {
@ -362,14 +360,13 @@ handle_libdecor_frame_configure(struct libdecor_frame *frame,
if (!libdecor_configuration_get_content_size(configuration, frame,
&width, &height))
{
width = wl->prev_width;
height = wl->prev_height;
width = wl->floating_width;
height = wl->floating_height;
}
if (width > 0 && height > 0)
if ( width > 0
&& height > 0)
{
wl->prev_width = width;
wl->prev_height = height;
wl->width = width;
wl->height = height;
}
@ -388,6 +385,11 @@ handle_libdecor_frame_configure(struct libdecor_frame *frame,
libdecor_frame_commit(frame, state, configuration);
libdecor_state_free(state);
if (libdecor_frame_is_floating(frame)) {
wl->floating_width = width;
wl->floating_height = height;
}
wl->configured = false;
}
@ -510,12 +512,12 @@ static void *gfx_ctx_wl_init(void *video_driver)
wl->input.dpy = wl_display_connect(NULL);
wl->last_buffer_scale = 1;
wl->buffer_scale = 1;
wl->width = DEFAULT_WINDOWED_WIDTH;
wl->height = DEFAULT_WINDOWED_HEIGHT;
wl->floating_width = DEFAULT_WINDOWED_WIDTH;
wl->floating_height = DEFAULT_WINDOWED_HEIGHT;
if (!wl->input.dpy)
{
RARCH_ERR("[Wayland]: Failed to connect to Wayland server.\n");
RARCH_ERR("[Wayland/GL]: Failed to connect to Wayland server.\n");
goto error;
}
@ -527,30 +529,30 @@ static void *gfx_ctx_wl_init(void *video_driver)
if (!wl->compositor)
{
RARCH_ERR("[Wayland]: Failed to create compositor.\n");
RARCH_ERR("[Wayland/GL]: Failed to create compositor.\n");
goto error;
}
if (!wl->shm)
{
RARCH_ERR("[Wayland]: Failed to create shm.\n");
RARCH_ERR("[Wayland/GL]: Failed to create shm.\n");
goto error;
}
if (!wl->xdg_shell)
{
RARCH_ERR("[Wayland]: Failed to create shell.\n");
RARCH_ERR("[Wayland/GL]: Failed to create shell.\n");
goto error;
}
if (!wl->idle_inhibit_manager)
{
RARCH_LOG("[Wayland]: Compositor doesn't support zwp_idle_inhibit_manager_v1 protocol\n");
RARCH_LOG("[Wayland/GL]: Compositor doesn't support zwp_idle_inhibit_manager_v1 protocol\n");
}
if (!wl->deco_manager)
{
RARCH_LOG("[Wayland]: Compositor doesn't support zxdg_decoration_manager_v1 protocol\n");
RARCH_LOG("[Wayland/GL]: Compositor doesn't support zxdg_decoration_manager_v1 protocol\n");
}
wl->surface = wl_compositor_create_surface(wl->compositor);
@ -565,7 +567,7 @@ static void *gfx_ctx_wl_init(void *video_driver)
wl->libdecor_frame = libdecor_decorate(wl->libdecor_context, wl->surface, &libdecor_frame_interface, wl);
if (!wl->libdecor_frame)
{
RARCH_ERR("[Wayland]: Failed to crate libdecor frame\n");
RARCH_ERR("[Wayland/GL]: Failed to crate libdecor frame\n");
goto error;
}
@ -582,7 +584,7 @@ static void *gfx_ctx_wl_init(void *video_driver)
{
if (libdecor_dispatch(wl->libdecor_context, 0) < 0)
{
RARCH_ERR("[Wayland]: libdecor failed to dispatch\n");
RARCH_ERR("[Wayland/GL]: libdecor failed to dispatch\n");
goto error;
}
}
@ -616,6 +618,8 @@ static void *gfx_ctx_wl_init(void *video_driver)
* which is usefull for HiDPI and auto selecting a display for fullscreen. */
draw_splash_screen(wl);
wl_display_roundtrip(wl->input.dpy);
wl->input.fd = wl_display_get_fd(wl->input.dpy);
#ifdef HAVE_EGL
@ -692,7 +696,7 @@ static EGLint *egl_fill_attribs(gfx_ctx_wayland_data_t *wl, EGLint *attr)
*attr++ = wl->egl.major;
*attr++ = EGL_CONTEXT_MINOR_VERSION_KHR;
*attr++ = wl->egl.minor;
/* Technically, we don't have core/compat until 3.2.
/* Technically, we don't have core/compat until 3.2
* Version 3.1 is either compat or not depending
* on GL_ARB_compatibility. */
if (version >= 3002)
@ -784,7 +788,9 @@ static bool gfx_ctx_wl_set_video_mode(void *data,
#endif
#ifdef HAVE_EGL
wl->win = wl_egl_window_create(wl->surface, wl->width * wl->buffer_scale, wl->height * wl->buffer_scale);
wl->win = wl_egl_window_create(wl->surface,
wl->width * wl->buffer_scale,
wl->height * wl->buffer_scale);
#endif
#ifdef HAVE_EGL
@ -810,20 +816,20 @@ static bool gfx_ctx_wl_set_video_mode(void *data,
{
oi = wl->current_output;
output = oi->output;
RARCH_LOG("[Wayland/Vulkan]: Auto fullscreen on display \"%s\" \"%s\"\n", oi->make, oi->model);
RARCH_LOG("[Wayland/GL]: Auto fullscreen on display \"%s\" \"%s\"\n", oi->make, oi->model);
}
else wl_list_for_each_safe(oi, tmp, &wl->all_outputs, link)
{
if (++output_i == video_monitor_index)
{
output = oi->output;
RARCH_LOG("[Wayland/Vulkan]: Fullscreen on display %i \"%s\" \"%s\"\n", output_i, oi->make, oi->model);
RARCH_LOG("[Wayland/GL]: Fullscreen on display %i \"%s\" \"%s\"\n", output_i, oi->make, oi->model);
break;
}
}
if (output == NULL)
RARCH_LOG("[Wayland/Vulkan] Failed to specify monitor for fullscreen, letting compositor decide\n");
RARCH_LOG("[Wayland/GL] Failed to specify monitor for fullscreen, letting compositor decide\n");
#ifdef HAVE_LIBDECOR
libdecor_frame_set_fullscreen(wl->libdecor_frame, output);
@ -891,13 +897,13 @@ static bool gfx_ctx_wl_suppress_screensaver(void *data, bool state)
if (state)
{
RARCH_LOG("[Wayland]: Enabling idle inhibitor\n");
RARCH_LOG("[Wayland/GL]: 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");
RARCH_LOG("[Wayland/GL]: Disabling the idle inhibitor\n");
zwp_idle_inhibitor_v1_destroy(wl->idle_inhibitor);
wl->idle_inhibitor = NULL;
}

View File

@ -29,8 +29,6 @@
#include <libdecor.h>
#endif
#include "../common/vulkan_common.h"
#include "../../frontend/frontend_driver.h"
#include "../../input/common/wayland_common.h"
#include "../../input/input_driver.h"
@ -46,6 +44,8 @@
/* Generated from xdg-decoration-unstable-v1.h */
#include "../common/wayland/xdg-decoration-unstable-v1.h"
#include "../common/vulkan_common.h"
#include <retro_timers.h>
#ifndef EGL_PLATFORM_WAYLAND_KHR
@ -83,10 +83,9 @@ static void handle_toplevel_config_common(void *data,
break;
}
}
if (width > 0 && height > 0)
if ( width > 0
&& height > 0)
{
wl->prev_width = width;
wl->prev_height = height;
wl->width = width;
wl->height = height;
}
@ -216,7 +215,8 @@ static void gfx_ctx_wl_check_window(void *data, bool *quit,
* central place, so use that to trigger swapchain reinit. */
*resize = wl->vk.need_new_swapchain;
if (new_width != *width * wl->last_buffer_scale || new_height != *height * wl->last_buffer_scale)
if ( new_width != *width * wl->last_buffer_scale
|| new_height != *height * wl->last_buffer_scale)
{
*width = new_width;
*height = new_height;
@ -247,6 +247,7 @@ static bool gfx_ctx_wl_set_resize(void *data, unsigned width, unsigned height)
wl->vk.need_new_swapchain = false;
wl_surface_set_buffer_scale(wl->surface, wl->buffer_scale);
return true;
}
@ -266,11 +267,8 @@ static void gfx_ctx_wl_update_title(void *data)
if (wl && 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);
}
#endif
@ -327,21 +325,25 @@ static void
handle_libdecor_frame_configure(struct libdecor_frame *frame,
struct libdecor_configuration *configuration, void *data)
{
struct libdecor_state *state;
int width, height;
enum libdecor_window_state window_state;
gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)data;
struct libdecor_state *state = NULL;
static const enum
libdecor_window_state tiled_states = (
LIBDECOR_WINDOW_STATE_TILED_LEFT
| LIBDECOR_WINDOW_STATE_TILED_RIGHT
| LIBDECOR_WINDOW_STATE_TILED_TOP
| LIBDECOR_WINDOW_STATE_TILED_BOTTOM
);
enum libdecor_window_state window_state;
bool focused = false;
bool tiled = false;
static const enum libdecor_window_state tiled_states = (
LIBDECOR_WINDOW_STATE_TILED_LEFT | LIBDECOR_WINDOW_STATE_TILED_RIGHT |
LIBDECOR_WINDOW_STATE_TILED_TOP | LIBDECOR_WINDOW_STATE_TILED_BOTTOM
);
wl->fullscreen = false;
wl->maximized = false;
if (libdecor_configuration_get_window_state(configuration, &window_state))
if (libdecor_configuration_get_window_state(
configuration, &window_state))
{
wl->fullscreen = (window_state & LIBDECOR_WINDOW_STATE_FULLSCREEN) != 0;
wl->maximized = (window_state & LIBDECOR_WINDOW_STATE_MAXIMIZED) != 0;
@ -352,14 +354,13 @@ handle_libdecor_frame_configure(struct libdecor_frame *frame,
if (!libdecor_configuration_get_content_size(configuration, frame,
&width, &height))
{
width = wl->prev_width;
height = wl->prev_height;
width = wl->floating_width;
height = wl->floating_height;
}
if (width > 0 && height > 0)
if ( width > 0
&& height > 0)
{
wl->prev_width = width;
wl->prev_height = height;
wl->width = width;
wl->height = height;
}
@ -368,6 +369,11 @@ handle_libdecor_frame_configure(struct libdecor_frame *frame,
libdecor_frame_commit(frame, state, configuration);
libdecor_state_free(state);
if (libdecor_frame_is_floating(frame)) {
wl->floating_width = width;
wl->floating_height = height;
}
wl->configured = false;
}
@ -409,12 +415,12 @@ static void *gfx_ctx_wl_init(void *video_driver)
wl->input.dpy = wl_display_connect(NULL);
wl->last_buffer_scale = 1;
wl->buffer_scale = 1;
wl->width = DEFAULT_WINDOWED_WIDTH;
wl->height = DEFAULT_WINDOWED_HEIGHT;
wl->floating_width = DEFAULT_WINDOWED_WIDTH;
wl->floating_height = DEFAULT_WINDOWED_HEIGHT;
if (!wl->input.dpy)
{
RARCH_ERR("[Wayland]: Failed to connect to Wayland server.\n");
RARCH_ERR("[Wayland/Vulkan]: Failed to connect to Wayland server.\n");
goto error;
}
@ -426,30 +432,30 @@ static void *gfx_ctx_wl_init(void *video_driver)
if (!wl->compositor)
{
RARCH_ERR("[Wayland]: Failed to create compositor.\n");
RARCH_ERR("[Wayland/Vulkan]: Failed to create compositor.\n");
goto error;
}
if (!wl->shm)
{
RARCH_ERR("[Wayland]: Failed to create shm.\n");
RARCH_ERR("[Wayland/Vulkan]: Failed to create shm.\n");
goto error;
}
if (!wl->xdg_shell)
{
RARCH_ERR("[Wayland]: Failed to create shell.\n");
RARCH_ERR("[Wayland/Vulkan]: Failed to create shell.\n");
goto error;
}
if (!wl->idle_inhibit_manager)
{
RARCH_LOG("[Wayland]: Compositor doesn't support zwp_idle_inhibit_manager_v1 protocol\n");
RARCH_LOG("[Wayland/Vulkan]: Compositor doesn't support zwp_idle_inhibit_manager_v1 protocol\n");
}
if (!wl->deco_manager)
{
RARCH_LOG("[Wayland]: Compositor doesn't support zxdg_decoration_manager_v1 protocol\n");
RARCH_LOG("[Wayland/Vulkan]: Compositor doesn't support zxdg_decoration_manager_v1 protocol\n");
}
wl->surface = wl_compositor_create_surface(wl->compositor);
@ -515,6 +521,8 @@ static void *gfx_ctx_wl_init(void *video_driver)
* which is usefull for HiDPI and auto selecting a display for fullscreen. */
draw_splash_screen(wl);
wl_display_roundtrip(wl->input.dpy);
wl->input.fd = wl_display_get_fd(wl->input.dpy);
if (!vulkan_context_init(&wl->vk, VULKAN_WSI_WAYLAND))
@ -598,6 +606,13 @@ static bool gfx_ctx_wl_set_video_mode(void *data,
libdecor_state_free(state);
#endif
if (!vulkan_surface_create(&wl->vk, VULKAN_WSI_WAYLAND,
wl->input.dpy, wl->surface,
wl->width * wl->buffer_scale,
wl->height * wl->buffer_scale,
wl->swap_interval))
goto error;
if (fullscreen)
{
struct wl_output *output = NULL;
@ -632,13 +647,6 @@ static bool gfx_ctx_wl_set_video_mode(void *data,
flush_wayland_fd(&wl->input);
wl_display_roundtrip(wl->input.dpy);
if (!vulkan_surface_create(&wl->vk, VULKAN_WSI_WAYLAND,
wl->input.dpy, wl->surface,
wl->width * wl->buffer_scale, wl->height * wl->buffer_scale, wl->swap_interval))
goto error;
if (fullscreen)
{
wl->cursor.visible = false;
@ -687,30 +695,32 @@ static bool gfx_ctx_wl_has_focus(void *data)
static bool gfx_ctx_wl_suppress_screensaver(void *data, bool state)
{
(void)data;
gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)data;
if (!wl->idle_inhibit_manager)
return false;
if (state == (!!wl->idle_inhibitor))
return true;
if (state)
{
RARCH_LOG("[Wayland]: Enabling idle inhibitor\n");
RARCH_LOG("[Wayland/Vulkan]: 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");
RARCH_LOG("[Wayland/Vulkan]: Disabling the idle inhibitor\n");
zwp_idle_inhibitor_v1_destroy(wl->idle_inhibitor);
wl->idle_inhibitor = NULL;
}
return true;
}
static enum gfx_ctx_api gfx_ctx_wl_get_api(void *data) { return GFX_CTX_VULKAN_API; }
static enum gfx_ctx_api gfx_ctx_wl_get_api(void *data)
{
return GFX_CTX_VULKAN_API;
}
static bool gfx_ctx_wl_bind_api(void *video_driver,
enum gfx_ctx_api api, unsigned major, unsigned minor)

View File

@ -156,10 +156,10 @@ typedef struct gfx_ctx_wayland_data
int num_active_touches;
int swap_interval;
touch_pos_t active_touch_positions[MAX_TOUCHES]; /* int32_t alignment */
unsigned prev_width;
unsigned prev_height;
unsigned width;
unsigned height;
unsigned floating_width;
unsigned floating_height;
unsigned last_buffer_scale;
unsigned buffer_scale;