From 0f13cd0eee47b34d41abc72f603c12fcc934535c Mon Sep 17 00:00:00 2001 From: Wei Zhao Date: Fri, 24 Apr 2026 13:55:45 +0800 Subject: [PATCH] backend-drm: destroy scanout fb in GPU recovery The GBM BO (Graphics Buffer Manager Buffer Object) associated with the scanout fb will be destroyed by eglDestroySurface in GPU recovery regardless of its reference count. Therefore, we need to manually destroy the corresponding scanout fb as well. Signed-off-by: Wei Zhao --- libweston/backend-drm/drm-gbm.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/libweston/backend-drm/drm-gbm.c b/libweston/backend-drm/drm-gbm.c index b9344d85c..3bf196bd0 100644 --- a/libweston/backend-drm/drm-gbm.c +++ b/libweston/backend-drm/drm-gbm.c @@ -805,8 +805,25 @@ drm_handle_gl_renderer_error(struct weston_compositor *compositor, int err) renderer->gl->set_recovering(compositor, true); /* 1, Destroy the renderer outputs */ - wl_list_for_each(output, &compositor->output_list, link) + wl_list_for_each(output, &compositor->output_list, link) { + struct drm_output *drm = to_drm_output(output); + struct drm_plane *scanout = drm->scanout_handle->plane; + + /* + * When the output is destroyed, its associated + * EGLSurface will also be destroyed. Consequently, the + * GBM BOs backing this surface will be freed. Mesa will + * destroy the GBM BO user_data (fb) regardless of + * refcount, so ensure we destroy them here before + * invoking output_destroy. + */ + if (scanout && scanout->state_cur && + scanout->state_cur->fb && + scanout->state_cur->fb->type == BUFFER_GBM_SURFACE) + drm_plane_reset_state(scanout); + renderer->gl->output_destroy(output); + } /* 2, Destroy the renderer */ renderer->destroy(compositor);