From c1b27cc499d06c0aa3d02228dd6e2905e08e2436 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Wed, 7 Jul 2021 23:02:48 +0200 Subject: [PATCH] backend/drm: stop using drm_surface_make_current in drm_surface_blit drm_surface_make_current and drm_surface_unset_current set implicit state and are an unnecessary mid-layer. Prefer to use directly wlr_renderer_begin_with_buffer, which automatically unsets the back buffer on wlr_renderer_end. I'd like to get rid of drm_surface_make_current once we stop using it for the primary swapchain. --- backend/drm/renderer.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/backend/drm/renderer.c b/backend/drm/renderer.c index d6da8606..60dd9c77 100644 --- a/backend/drm/renderer.c +++ b/backend/drm/renderer.c @@ -141,7 +141,8 @@ struct wlr_buffer *drm_surface_blit(struct wlr_drm_surface *surf, return NULL; } - if (!drm_surface_make_current(surf, NULL)) { + struct wlr_buffer *dst = wlr_swapchain_acquire(surf->swapchain, NULL); + if (!dst) { wlr_texture_destroy(tex); return NULL; } @@ -150,19 +151,20 @@ struct wlr_buffer *drm_surface_blit(struct wlr_drm_surface *surf, wlr_matrix_identity(mat); wlr_matrix_scale(mat, surf->width, surf->height); - wlr_renderer_begin(renderer, surf->width, surf->height); + if (!wlr_renderer_begin_with_buffer(renderer, dst)) { + wlr_buffer_unlock(dst); + wlr_texture_destroy(tex); + return NULL; + } + wlr_renderer_clear(renderer, (float[]){ 0.0, 0.0, 0.0, 0.0 }); wlr_render_texture_with_matrix(renderer, tex, mat, 1.0f); - wlr_renderer_end(renderer); - assert(surf->back_buffer != NULL); - struct wlr_buffer *out = wlr_buffer_lock(surf->back_buffer); - - drm_surface_unset_current(surf); + wlr_renderer_end(renderer); wlr_texture_destroy(tex); - return out; + return dst; }