From 85d2d49499d8c78fc3d847168c69bf1080c770c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Tue, 26 Nov 2024 10:35:32 +0100 Subject: [PATCH] wayland/surface: Unconditionally set scanout destination rect The cogl_scanout_get_dst_rect() fell back on the buffer dimensions as the destination rectangle when nothing was explicitly set. This, however, is not necessarily correct. For example, if a buffer is larger the CRTC resolution, but the surface is scaled to exactly match the CRTC view, the expected destination size should match the CRTC resolution, not the buffer dimension, which would be the case if no explicit destination was set. In meta_wayland_try_aquire_scanout() we're in a good position to determine the destination rect in the CRTC primary plane, since we have all the prerequisits, i.e. that the surface effectively covers the whole CRTC, the actor allocation box (the non-black border part), the scale and transform of the view. This tweaks the CoglScanout API a bit to make it explicit that the dst_rect must be unconditionally provided, and removes the fallback to the buffer dimension as the destination rectangle, which sometimes resulted in a destination rectangle being larger than the primary plane itself, resulting in clipping and incorrect scaling. Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/3773 Part-of: --- cogl/cogl/cogl-scanout.c | 33 ++++++++---------------------- cogl/cogl/cogl-scanout.h | 9 +++----- src/wayland/meta-wayland-buffer.c | 4 ++-- src/wayland/meta-wayland-dma-buf.c | 4 ++-- src/wayland/meta-wayland-surface.c | 10 +-------- 5 files changed, 17 insertions(+), 43 deletions(-) diff --git a/cogl/cogl/cogl-scanout.c b/cogl/cogl/cogl-scanout.c index 94f5d5df7..5f30ce7af 100644 --- a/cogl/cogl/cogl-scanout.c +++ b/cogl/cogl/cogl-scanout.c @@ -48,7 +48,6 @@ struct _CoglScanout gboolean has_src_rect; graphene_rect_t src_rect; - gboolean has_dst_rect; MtkRectangle dst_rect; }; @@ -104,11 +103,16 @@ cogl_scanout_notify_failed (CoglScanout *scanout, } CoglScanout * -cogl_scanout_new (CoglScanoutBuffer *scanout_buffer) +cogl_scanout_new (CoglScanoutBuffer *scanout_buffer, + const MtkRectangle *dst_rect) { - CoglScanout *scanout = g_object_new (COGL_TYPE_SCANOUT, NULL); + CoglScanout *scanout; + g_return_val_if_fail (dst_rect, NULL); + + scanout = g_object_new (COGL_TYPE_SCANOUT, NULL); scanout->scanout_buffer = scanout_buffer; + scanout->dst_rect = *dst_rect; return scanout; } @@ -141,28 +145,9 @@ cogl_scanout_set_src_rect (CoglScanout *scanout, void cogl_scanout_get_dst_rect (CoglScanout *scanout, - MtkRectangle *rect) + MtkRectangle *dst_rect) { - if (scanout->has_dst_rect) - { - *rect = scanout->dst_rect; - return; - } - - rect->x = 0; - rect->y = 0; - rect->width = cogl_scanout_buffer_get_width (scanout->scanout_buffer); - rect->height = cogl_scanout_buffer_get_height (scanout->scanout_buffer); -} - -void -cogl_scanout_set_dst_rect (CoglScanout *scanout, - const MtkRectangle *rect) -{ - if (rect != NULL) - scanout->dst_rect = *rect; - - scanout->has_dst_rect = rect != NULL; + *dst_rect = scanout->dst_rect; } static void diff --git a/cogl/cogl/cogl-scanout.h b/cogl/cogl/cogl-scanout.h index a62a7d706..162e54cbb 100644 --- a/cogl/cogl/cogl-scanout.h +++ b/cogl/cogl/cogl-scanout.h @@ -81,7 +81,8 @@ void cogl_scanout_notify_failed (CoglScanout *scanout, CoglOnscreen *onscreen); COGL_EXPORT -CoglScanout * cogl_scanout_new (CoglScanoutBuffer *scanout_buffer); +CoglScanout * cogl_scanout_new (CoglScanoutBuffer *scanout_buffer, + const MtkRectangle *dst_rect); COGL_EXPORT void cogl_scanout_get_src_rect (CoglScanout *scanout, @@ -93,8 +94,4 @@ void cogl_scanout_set_src_rect (CoglScanout *scanout, COGL_EXPORT void cogl_scanout_get_dst_rect (CoglScanout *scanout, - MtkRectangle *rect); - -COGL_EXPORT -void cogl_scanout_set_dst_rect (CoglScanout *scanout, - const MtkRectangle *rect); + MtkRectangle *dst_rect); diff --git a/src/wayland/meta-wayland-buffer.c b/src/wayland/meta-wayland-buffer.c index 613a48d6f..58ef630d1 100644 --- a/src/wayland/meta-wayland-buffer.c +++ b/src/wayland/meta-wayland-buffer.c @@ -924,9 +924,9 @@ try_acquire_egl_image_scanout (MetaWaylandBuffer *buffer, return NULL; } - scanout = cogl_scanout_new (COGL_SCANOUT_BUFFER (g_steal_pointer (&fb))); + scanout = cogl_scanout_new (COGL_SCANOUT_BUFFER (g_steal_pointer (&fb)), + dst_rect); cogl_scanout_set_src_rect (scanout, src_rect); - cogl_scanout_set_dst_rect (scanout, dst_rect); if (!meta_onscreen_native_is_buffer_scanout_compatible (onscreen, scanout)) return NULL; diff --git a/src/wayland/meta-wayland-dma-buf.c b/src/wayland/meta-wayland-dma-buf.c index 8a2b0ec66..53a6ca8ca 100644 --- a/src/wayland/meta-wayland-dma-buf.c +++ b/src/wayland/meta-wayland-dma-buf.c @@ -666,9 +666,9 @@ meta_wayland_dma_buf_try_acquire_scanout (MetaWaylandBuffer *buffer, return NULL; } - scanout = cogl_scanout_new (COGL_SCANOUT_BUFFER (g_steal_pointer (&fb))); + scanout = cogl_scanout_new (COGL_SCANOUT_BUFFER (g_steal_pointer (&fb)), + dst_rect); cogl_scanout_set_src_rect (scanout, src_rect); - cogl_scanout_set_dst_rect (scanout, dst_rect); if (!meta_onscreen_native_is_buffer_scanout_compatible (onscreen, scanout)) { diff --git a/src/wayland/meta-wayland-surface.c b/src/wayland/meta-wayland-surface.c index 463dace7a..734044543 100644 --- a/src/wayland/meta-wayland-surface.c +++ b/src/wayland/meta-wayland-surface.c @@ -2409,7 +2409,6 @@ meta_wayland_surface_try_acquire_scanout (MetaWaylandSurface *surface, MetaSurfaceActor *surface_actor; MtkMonitorTransform view_transform; ClutterActorBox actor_box; - MtkRectangle *crtc_dst_rect_ptr = NULL; MtkRectangle crtc_dst_rect; graphene_rect_t *src_rect_ptr = NULL; graphene_rect_t src_rect; @@ -2465,13 +2464,6 @@ meta_wayland_surface_try_acquire_scanout (MetaWaylandSurface *surface, view_crtc_height, &crtc_dst_rect); - /* Use an implicit destination rect when possible */ - if (surface->viewport.has_dst_size || - crtc_dst_rect.x != 0 || crtc_dst_rect.y != 0 || - crtc_dst_rect.width != view_crtc_width || - crtc_dst_rect.height != view_crtc_height) - crtc_dst_rect_ptr = &crtc_dst_rect; - if (surface->viewport.has_src_rect) { src_rect = surface->viewport.src_rect; @@ -2481,7 +2473,7 @@ meta_wayland_surface_try_acquire_scanout (MetaWaylandSurface *surface, return meta_wayland_buffer_try_acquire_scanout (surface->buffer, onscreen, src_rect_ptr, - crtc_dst_rect_ptr); + &crtc_dst_rect); } MetaCrtc *