From 7649e2f3abd50a6a26b3e009bf24aea26705a235 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michel=20D=C3=A4nzer?= Date: Mon, 18 Dec 2023 17:42:16 +0100 Subject: [PATCH] wayland/surface: Move buffer size check to meta_wayland_surface_commit Multiple reasons: * More consistent with the protocol spec language. * Ensures the size is checked and the protocol error sent from a protocol processing context, instead of whatever context meta_wayland_surface_commit might get called from. * The latter implies that surface->resource is guaranteed to be valid. Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/3211 Part-of: --- src/wayland/meta-wayland-surface.c | 66 +++++++++++++++--------------- 1 file changed, 34 insertions(+), 32 deletions(-) diff --git a/src/wayland/meta-wayland-surface.c b/src/wayland/meta-wayland-surface.c index b7a168192..1a7ad7e24 100644 --- a/src/wayland/meta-wayland-surface.c +++ b/src/wayland/meta-wayland-surface.c @@ -698,7 +698,6 @@ meta_wayland_surface_apply_state (MetaWaylandSurface *surface, { gboolean had_damage = FALSE; int old_width, old_height; - int surface_scale; old_width = meta_wayland_surface_get_width (surface); old_height = meta_wayland_surface_get_height (surface); @@ -746,36 +745,6 @@ meta_wayland_surface_apply_state (MetaWaylandSurface *surface, if (state->scale > 0) surface->applied_state.scale = state->scale; - surface_scale = surface->applied_state.scale; - if ((meta_wayland_surface_get_buffer_width (surface) % surface_scale != 0) || - (meta_wayland_surface_get_buffer_height (surface) % surface_scale != 0)) - { - if (surface->role && !META_IS_WAYLAND_CURSOR_SURFACE (surface->role)) - { - wl_resource_post_error (surface->resource, WL_SURFACE_ERROR_INVALID_SIZE, - "Buffer size (%dx%d) must be an integer multiple " - "of the buffer_scale (%d).", - meta_wayland_surface_get_buffer_width (surface), - meta_wayland_surface_get_buffer_height (surface), - surface_scale); - } - else - { - struct wl_resource *resource = surface->resource; - pid_t pid; - - wl_client_get_credentials (wl_resource_get_client (resource), &pid, NULL, - NULL); - - g_warning ("Bug in client with pid %ld: Cursor buffer size (%dx%d) is " - "not an integer multiple of the buffer_scale (%d).", - (long) pid, - meta_wayland_surface_get_buffer_width (surface), - meta_wayland_surface_get_buffer_height (surface), - surface_scale); - } - } - if (state->has_new_buffer_transform) surface->buffer_transform = state->buffer_transform; @@ -926,6 +895,8 @@ meta_wayland_surface_commit (MetaWaylandSurface *surface) if (buffer) { + int committed_scale = surface->committed_state.scale; + MetaMultiTexture *committed_texture; g_autoptr (GError) error = NULL; g_clear_signal_handler (&pending->buffer_destroy_handler_id, @@ -947,7 +918,38 @@ meta_wayland_surface_commit (MetaWaylandSurface *surface) return; } - pending->texture = g_object_ref (surface->committed_state.texture); + committed_texture = surface->committed_state.texture; + if ((meta_multi_texture_get_width (committed_texture) % committed_scale != 0) || + (meta_multi_texture_get_height (committed_texture) % committed_scale != 0)) + { + if (surface->role && !META_IS_WAYLAND_CURSOR_SURFACE (surface->role)) + { + wl_resource_post_error (surface->resource, WL_SURFACE_ERROR_INVALID_SIZE, + "Buffer size (%dx%d) must be an integer multiple " + "of the buffer_scale (%d).", + meta_wayland_surface_get_buffer_width (surface), + meta_wayland_surface_get_buffer_height (surface), + committed_scale); + return; + } + else + { + struct wl_resource *resource = surface->resource; + pid_t pid; + + wl_client_get_credentials (wl_resource_get_client (resource), &pid, NULL, + NULL); + + g_warning ("Bug in client with pid %ld: Cursor buffer size (%dx%d) is " + "not an integer multiple of the buffer_scale (%d).", + (long) pid, + meta_wayland_surface_get_buffer_width (surface), + meta_wayland_surface_get_buffer_height (surface), + committed_scale); + } + } + + pending->texture = g_object_ref (committed_texture); g_object_ref (buffer); meta_wayland_buffer_inc_use_count (buffer);