From 28d12716e8ff04b50a443ecaa6c7b519117303a5 Mon Sep 17 00:00:00 2001 From: Derek Foreman Date: Fri, 8 Oct 2021 08:55:44 -0500 Subject: [PATCH] egl/wayland: Properly clear stale buffers on resize The following chain of events results in an incorrectly sized buffer persisting beyond its useful lifetime, and causing visual artifacts. buffer is attached at size A window is resized to size B rendering takes place for size B window is resized back to size A swapbuffers with damage is called In this scenario, update_buffers fails to recognize that the surface it's about to commit is a different size than it has rendered. The attached_width and attached_height are set incorrectly, and periodic flickering is observed. Instead, we set a boolean flag at time of resize and use this at the time we latch the window dimensions as surface dimensions to decide whether to discard stale buffers. Signed-off-by: Derek Foreman Reviewed-by: Daniel Stone Part-of: --- src/egl/drivers/dri2/egl_dri2.h | 1 + src/egl/drivers/dri2/platform_wayland.c | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/egl/drivers/dri2/egl_dri2.h b/src/egl/drivers/dri2/egl_dri2.h index 98fdc1e2e2d..9acc846687b 100644 --- a/src/egl/drivers/dri2/egl_dri2.h +++ b/src/egl/drivers/dri2/egl_dri2.h @@ -302,6 +302,7 @@ struct dri2_egl_surface struct wl_drm *wl_drm_wrapper; struct wl_callback *throttle_callback; int format; + bool resized; #endif #ifdef HAVE_DRM_PLATFORM diff --git a/src/egl/drivers/dri2/platform_wayland.c b/src/egl/drivers/dri2/platform_wayland.c index e37579995e5..e1f445e1de3 100644 --- a/src/egl/drivers/dri2/platform_wayland.c +++ b/src/egl/drivers/dri2/platform_wayland.c @@ -279,6 +279,8 @@ resize_callback(struct wl_egl_window *wl_win, void *data) dri2_surf->base.Height == wl_win->height) return; + dri2_surf->resized = true; + /* Update the surface size as soon as native window is resized; from user * pov, this makes the effect that resize is done immediately after native * window resize, without requiring to wait until the first draw. @@ -714,10 +716,9 @@ update_buffers(struct dri2_egl_surface *dri2_surf) dri2_surf->dy = dri2_surf->wl_win->dy; } - if (dri2_surf->wl_win && - (dri2_surf->base.Width != dri2_surf->wl_win->attached_width || - dri2_surf->base.Height != dri2_surf->wl_win->attached_height)) { - dri2_wl_release_buffers(dri2_surf); + if (dri2_surf->resized) { + dri2_wl_release_buffers(dri2_surf); + dri2_surf->resized = false; } if (get_back_bo(dri2_surf) < 0) {