From 72b6c7096d0abee8d70b616dd2cece2a623d66e0 Mon Sep 17 00:00:00 2001 From: Mariusz Bialonczyk Date: Tue, 2 Jan 2024 14:02:51 +0100 Subject: [PATCH] [uwac] scaling: fix damage surface Some detailed overview of this change: I was trying to use the wl_surface_damage_buffer() [1] function, like in this [2] code, but there were some problems with calling it; even more, we also need to check the compositor version before calling it. Next approach was using full damage like described here [3]. This was working fine, but it was of course suboptimal. Finally: looking at chromium/ozone code [4] I ended up with correctly calculating the damage region within surface coordinates. Refs: [1] https://wayland-client-d.dpldocs.info/wayland.client.protocol.wl_surface_damage_buffer.html [2] https://github.com/OpenInkpot/weston/blob/b01c31b24f7503322a3328a6045d98423cc8ee7c/clients/simple-damage.c#L585 [3] https://bugzilla.mozilla.org/show_bug.cgi?id=1648872#c21 [4] https://chromium.googlesource.com/chromium/src/+/6763b7710c87467d05aaee4523ca228ed8e4b285/ui/ozone/platform/wayland/host/wayland_surface.cc#118 --- uwac/libuwac/uwac-window.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/uwac/libuwac/uwac-window.c b/uwac/libuwac/uwac-window.c index bea2c3a1d..2e952cd17 100644 --- a/uwac/libuwac/uwac-window.c +++ b/uwac/libuwac/uwac-window.c @@ -677,26 +677,26 @@ static void frame_done_cb(void* data, struct wl_callback* callback, uint32_t tim static const struct wl_callback_listener frame_listener = { frame_done_cb }; #ifdef UWAC_HAVE_PIXMAN_REGION -static void damage_surface(UwacWindow* window, UwacBuffer* buffer) +static void damage_surface(UwacWindow* window, UwacBuffer* buffer, int scale) { int nrects, i; const pixman_box32_t* box = pixman_region32_rectangles(&buffer->damage, &nrects); for (i = 0; i < nrects; i++, box++) - wl_surface_damage(window->surface, box->x1, box->y1, (box->x2 - box->x1), - (box->y2 - box->y1)); + wl_surface_damage(window->surface, box->x1 / scale, box->y1 / scale, + (box->x2 - box->x1) / scale, (box->y2 - box->y1) / scale); pixman_region32_clear(&buffer->damage); } #else -static void damage_surface(UwacWindow* window, UwacBuffer* buffer) +static void damage_surface(UwacWindow* window, UwacBuffer* buffer, int scale) { uint32_t nrects, i; const RECTANGLE_16* box = region16_rects(&buffer->damage, &nrects); for (i = 0; i < nrects; i++, box++) - wl_surface_damage(window->surface, box->left, box->top, (box->right - box->left), - (box->bottom - box->top)); + wl_surface_damage(window->surface, box->left / scale, box->top / scale, + (box->right - box->left) / scale, (box->bottom - box->top) / scale); region16_clear(&buffer->damage); } @@ -706,7 +706,8 @@ static void UwacSubmitBufferPtr(UwacWindow* window, UwacBuffer* buffer) { wl_surface_attach(window->surface, buffer->wayland_buffer, 0, 0); - damage_surface(window, buffer); + int scale = window->display->actual_scale; + damage_surface(window, buffer, scale); struct wl_callback* frame_callback = wl_surface_frame(window->surface); wl_callback_add_listener(frame_callback, &frame_listener, window);