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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
diff --git a/src/video/wayland/SDL_waylandvideo.c b/src/video/wayland/SDL_waylandvideo.c
index 97e5efb..b9b1ce2 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 2abb2d5..a4e9f59 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);