From ea5958009cc2eb660952f018a6fdb1e335b8b062 Mon Sep 17 00:00:00 2001
From: Frank Praznik <[EMAIL REDACTED]>
Date: Mon, 3 Oct 2022 18:31:15 -0400
Subject: [PATCH] wayland: Set the damage buffer size when supported
The preferred method for setting the damage region on compositor protocol versions 4 and above is to use wl_surface.damage_buffer. Use this when available and only fall back to wl_surface.damage on older versions.
Bumps the highest supported version of wl_compositor to version 4.
---
src/video/wayland/SDL_waylandvideo.c | 2 +-
src/video/wayland/SDL_waylandwindow.c | 14 +++++++++++---
2 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/src/video/wayland/SDL_waylandvideo.c b/src/video/wayland/SDL_waylandvideo.c
index 97e5efbdd7a5..b9b1ce25133b 100644
--- a/src/video/wayland/SDL_waylandvideo.c
+++ b/src/video/wayland/SDL_waylandvideo.c
@@ -849,7 +849,7 @@ display_handle_global(void *data, struct wl_registry *registry, uint32_t id,
/*printf("WAYLAND INTERFACE: %s\n", interface);*/
if (SDL_strcmp(interface, "wl_compositor") == 0) {
- d->compositor = wl_registry_bind(d->registry, id, &wl_compositor_interface, SDL_min(3, version));
+ d->compositor = wl_registry_bind(d->registry, id, &wl_compositor_interface, SDL_min(4, version));
} else if (SDL_strcmp(interface, "wl_output") == 0) {
Wayland_add_display(d, id);
} else if (SDL_strcmp(interface, "wl_seat") == 0) {
diff --git a/src/video/wayland/SDL_waylandwindow.c b/src/video/wayland/SDL_waylandwindow.c
index 2abb2d54e689..a4e9f591e121 100644
--- a/src/video/wayland/SDL_waylandwindow.c
+++ b/src/video/wayland/SDL_waylandwindow.c
@@ -522,9 +522,17 @@ surface_damage_frame_done(void *data, struct wl_callback *cb, uint32_t time)
{
SDL_WindowData *wind = (SDL_WindowData *)data;
- /* Set the damage region. */
- wl_surface_damage(wind->surface, 0, 0,
- wind->window_width, wind->window_height);
+ /*
+ * wl_surface.damage_buffer is the preferred method of setting the damage region
+ * on compositor version 4 and above.
+ */
+ if (wl_compositor_get_version(wind->waylandData->compositor) >= 4) {
+ wl_surface_damage_buffer(wind->surface, 0, 0,
+ wind->drawable_width, wind->drawable_height);
+ } else {
+ wl_surface_damage(wind->surface, 0, 0,
+ wind->window_width, wind->window_height);
+ }
wl_callback_destroy(cb);
wind->surface_damage_frame_callback = wl_surface_frame(wind->surface);