From fd146d04d16b7a9fddd5f83a065dc3ae52f44eb9 Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Thu, 27 Mar 2025 10:30:23 +0200 Subject: [PATCH] egl/wayland: Damage whole surface using wl_surface_damage_buffer() Most compositors work with damage in the buffer local coordinate space. This change spares the compositors some work converting the provided INT32_MAX x INT32_MAX damage region to the buffer local coordinate space. It has no significant performance impact, but it'd still be nice to use wl_surface_damage_buffer() if possible. Part-of: --- src/egl/drivers/dri2/platform_wayland.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/egl/drivers/dri2/platform_wayland.c b/src/egl/drivers/dri2/platform_wayland.c index d79b6d71933..42d6bc9a1b6 100644 --- a/src/egl/drivers/dri2/platform_wayland.c +++ b/src/egl/drivers/dri2/platform_wayland.c @@ -1638,13 +1638,19 @@ try_damage_buffer(struct dri2_egl_surface *dri2_surf, const EGLint *rects, WL_SURFACE_DAMAGE_BUFFER_SINCE_VERSION) return EGL_FALSE; - for (int i = 0; i < n_rects; i++) { - const int *rect = &rects[i * 4]; + if (n_rects == 0) { + wl_surface_damage_buffer(dri2_surf->wl_surface_wrapper, 0, 0, + INT32_MAX, INT32_MAX); + } else { + for (int i = 0; i < n_rects; i++) { + const int *rect = &rects[i * 4]; - wl_surface_damage_buffer(dri2_surf->wl_surface_wrapper, rect[0], - dri2_surf->base.Height - rect[1] - rect[3], - rect[2], rect[3]); + wl_surface_damage_buffer(dri2_surf->wl_surface_wrapper, rect[0], + dri2_surf->base.Height - rect[1] - rect[3], + rect[2], rect[3]); + } } + return EGL_TRUE; } @@ -1732,7 +1738,7 @@ dri2_wl_swap_buffers_with_damage(_EGLDisplay *disp, _EGLSurface *draw, /* If the compositor doesn't support damage_buffer, we deliberately * ignore the damage region and post maximum damage, due to * https://bugs.freedesktop.org/78190 */ - if (!n_rects || !try_damage_buffer(dri2_surf, rects, n_rects)) + if (!try_damage_buffer(dri2_surf, rects, n_rects)) wl_surface_damage(dri2_surf->wl_surface_wrapper, 0, 0, INT32_MAX, INT32_MAX); @@ -2747,7 +2753,7 @@ dri2_wl_swrast_swap_buffers_with_damage(_EGLDisplay *disp, _EGLSurface *draw, /* If the compositor doesn't support damage_buffer, we deliberately * ignore the damage region and post maximum damage, due to * https://bugs.freedesktop.org/78190 */ - if (!n_rects || !try_damage_buffer(dri2_surf, rects, n_rects)) + if (!try_damage_buffer(dri2_surf, rects, n_rects)) wl_surface_damage(dri2_surf->wl_surface_wrapper, 0, 0, INT32_MAX, INT32_MAX);