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)
{
wayland_surface->resize(m);
std::tie(width, height) = wayland_surface->get_size();
std::tie(width, height) = wayland_surface->get_size_for_metrics(m);
wl_egl_window_resize(egl_window, width, height, 0, 0);
wayland_surface->resize(m);
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()
{
return get_size_for_metrics(metrics);
}
std::tuple<int, int> WaylandSurface::get_size_for_metrics(Metrics m)
{
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)

View File

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

View File

@ -91,10 +91,7 @@ void S9xVulkanDisplayDriver::refresh()
#ifdef GDK_WINDOWING_WAYLAND
if (GDK_IS_WAYLAND_WINDOW(drawing_area->get_window()->gobj()))
{
wayland_surface->resize(get_metrics(*drawing_area));
std::tie(new_width, new_height) = wayland_surface->get_size();
}
std::tie(new_width, new_height) = wayland_surface->get_size_for_metrics(get_metrics(*drawing_area));
else
#endif
{
@ -108,6 +105,11 @@ void S9xVulkanDisplayDriver::refresh()
context->wait_idle();
current_width = new_width;
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)
return;
int width = event->size().width();
int height = event->size().height();
context->swapchain->set_vsync(config->enable_vsync);
#ifndef _WIN32
if (platform == "wayland")
{
wayland_surface->resize({ parent->x() - main_window->x(), parent->y() - main_window->y(), width, height, (int)devicePixelRatio() });
std::tie(width, height) = wayland_surface->get_size();
// On Wayland, Vulkan WSI provides the buffer for the subsurface,
// so we have to specify a width and height instead of polling the parent.
WaylandSurface::Metrics m = {
parent->x() - main_window->x(),
parent->y() - main_window->y(),
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);
wayland_surface->resize(m);
return;
}
#endif