Wayland: Reorder resizing operations

Ensure a buffer is in place before calling viewporter.
This commit is contained in:
BearOso 2024-01-09 10:31:49 -06:00
parent 9b77335345
commit f0001ab428
5 changed files with 27 additions and 17 deletions

View File

@ -119,11 +119,9 @@ bool WaylandEGLContext::create_context()
void WaylandEGLContext::resize(WaylandSurface::Metrics m) void WaylandEGLContext::resize(WaylandSurface::Metrics m)
{ {
wayland_surface->resize(m); std::tie(width, height) = wayland_surface->get_size_for_metrics(m);
std::tie(width, height) = wayland_surface->get_size();
wl_egl_window_resize(egl_window, width, height, 0, 0); wl_egl_window_resize(egl_window, width, height, 0, 0);
wayland_surface->resize(m);
make_current(); make_current();
} }

View File

@ -147,13 +147,18 @@ bool WaylandSurface::attach(wl_display *display, wl_surface *surface, Metrics m)
} }
std::tuple<int, int> WaylandSurface::get_size() std::tuple<int, int> WaylandSurface::get_size()
{
return get_size_for_metrics(metrics);
}
std::tuple<int, int> WaylandSurface::get_size_for_metrics(Metrics m)
{ {
if (actual_scale == 0.0) if (actual_scale == 0.0)
{ {
return { metrics.width * metrics.scale, metrics.height * metrics.scale }; return { m.width * m.scale, m.height * m.scale };
} }
return { round(metrics.width * actual_scale), round(metrics.height * actual_scale) }; return { round(m.width * actual_scale), round(m.height * actual_scale) };
} }
void WaylandSurface::resize(Metrics m) void WaylandSurface::resize(Metrics m)

View File

@ -23,6 +23,7 @@ class WaylandSurface
bool attach(wl_display *display, wl_surface *surface, Metrics source_metrics); bool attach(wl_display *display, wl_surface *surface, Metrics source_metrics);
void resize(Metrics new_metrics); void resize(Metrics new_metrics);
std::tuple<int, int> get_size(); std::tuple<int, int> get_size();
std::tuple<int, int> get_size_for_metrics(Metrics m);
struct wl_display *display; struct wl_display *display;
struct wl_registry *registry; struct wl_registry *registry;

View File

@ -91,10 +91,7 @@ void S9xVulkanDisplayDriver::refresh()
#ifdef GDK_WINDOWING_WAYLAND #ifdef GDK_WINDOWING_WAYLAND
if (GDK_IS_WAYLAND_WINDOW(drawing_area->get_window()->gobj())) if (GDK_IS_WAYLAND_WINDOW(drawing_area->get_window()->gobj()))
{ std::tie(new_width, new_height) = wayland_surface->get_size_for_metrics(get_metrics(*drawing_area));
wayland_surface->resize(get_metrics(*drawing_area));
std::tie(new_width, new_height) = wayland_surface->get_size();
}
else else
#endif #endif
{ {
@ -108,6 +105,11 @@ void S9xVulkanDisplayDriver::refresh()
context->wait_idle(); context->wait_idle();
current_width = new_width; current_width = new_width;
current_height = new_height; current_height = new_height;
#ifdef GDK_WINDOWING_WAYLAND
if (GDK_IS_WAYLAND_WINDOW(drawing_area->get_window()->gobj()))
wayland_surface->resize(get_metrics(*drawing_area));
#endif
} }
} }

View File

@ -220,19 +220,23 @@ void EmuCanvasVulkan::resizeEvent(QResizeEvent *event)
if (!context) if (!context)
return; return;
int width = event->size().width();
int height = event->size().height();
context->swapchain->set_vsync(config->enable_vsync); context->swapchain->set_vsync(config->enable_vsync);
#ifndef _WIN32 #ifndef _WIN32
if (platform == "wayland") if (platform == "wayland")
{ {
wayland_surface->resize({ parent->x() - main_window->x(), parent->y() - main_window->y(), width, height, (int)devicePixelRatio() }); WaylandSurface::Metrics m = {
std::tie(width, height) = wayland_surface->get_size(); parent->x() - main_window->x(),
// On Wayland, Vulkan WSI provides the buffer for the subsurface, parent->y() - main_window->y(),
// so we have to specify a width and height instead of polling the parent. event->size().width(),
event->size().height(),
(int)devicePixelRatio()
};
auto [width, height] = wayland_surface->get_size_for_metrics(m);
context->swapchain->check_and_resize(width, height); context->swapchain->check_and_resize(width, height);
wayland_surface->resize(m);
return; return;
} }
#endif #endif