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);