From 3ae7ba1255c62ea28932d7499189d5a8098b24bd Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 8 Jul 2025 06:05:39 +0000 Subject: [PATCH] GHOST/Wayland: use wl_surface_damage_buffer when available Also damage the entire buffer, there is no reason to clamp this to the buffer bounds. --- intern/ghost/intern/GHOST_SystemWayland.cc | 27 ++++++++++++++-------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/intern/ghost/intern/GHOST_SystemWayland.cc b/intern/ghost/intern/GHOST_SystemWayland.cc index dd71f1a44f0..d69d3506c02 100644 --- a/intern/ghost/intern/GHOST_SystemWayland.cc +++ b/intern/ghost/intern/GHOST_SystemWayland.cc @@ -2684,15 +2684,24 @@ static char *read_file_as_buffer(const int fd, const bool nil_terminate, size_t /** \name Private Cursor API * \{ */ -static void cursor_buffer_set_surface_impl(const wl_cursor_image *wl_image, - wl_buffer *buffer, - wl_surface *wl_surface) +static void cursor_buffer_set_surface_impl(wl_buffer *buffer, wl_surface *wl_surface) { - const int32_t image_size_x = int32_t(wl_image->width); - const int32_t image_size_y = int32_t(wl_image->height); - wl_surface_attach(wl_surface, buffer, 0, 0); - wl_surface_damage(wl_surface, 0, 0, image_size_x, image_size_y); + if (wl_surface_get_version(wl_surface) >= WL_SURFACE_DAMAGE_BUFFER_SINCE_VERSION) { + wl_surface_damage_buffer(wl_surface, + 0, + 0, + std::numeric_limits::max(), + std::numeric_limits::max()); + } + else { + /* Effectively deprecated according to documentation. */ + wl_surface_damage(wl_surface, + 0, + 0, + std::numeric_limits::max(), + std::numeric_limits::max()); + } wl_surface_commit(wl_surface); } @@ -2874,7 +2883,7 @@ static void gwl_seat_cursor_buffer_set(const GWL_Seat *seat, if (seat->wl.pointer) { const int32_t hotspot_x = int32_t(wl_image->hotspot_x); const int32_t hotspot_y = int32_t(wl_image->hotspot_y); - cursor_buffer_set_surface_impl(wl_image, buffer, cursor->wl.surface_cursor); + cursor_buffer_set_surface_impl(buffer, cursor->wl.surface_cursor); wl_pointer_set_cursor(seat->wl.pointer, seat->pointer.serial, visible ? cursor->wl.surface_cursor : nullptr, @@ -2889,7 +2898,7 @@ static void gwl_seat_cursor_buffer_set(const GWL_Seat *seat, for (zwp_tablet_tool_v2 *zwp_tablet_tool_v2 : seat->wp.tablet_tools) { GWL_TabletTool *tablet_tool = static_cast( zwp_tablet_tool_v2_get_user_data(zwp_tablet_tool_v2)); - cursor_buffer_set_surface_impl(wl_image, buffer, tablet_tool->wl.surface_cursor); + cursor_buffer_set_surface_impl(buffer, tablet_tool->wl.surface_cursor); zwp_tablet_tool_v2_set_cursor(zwp_tablet_tool_v2, tablet_tool->serial, visible ? tablet_tool->wl.surface_cursor : nullptr,