From b899a412e3eb7be76df495883de9aa2bdb3be06f Mon Sep 17 00:00:00 2001 From: Simon Zeni Date: Thu, 7 Jan 2021 00:10:10 -0500 Subject: [PATCH] backend: remove wlr_egl from all backends --- backend/drm/renderer.c | 11 ++++++----- backend/headless/backend.c | 10 ++++++---- backend/headless/output.c | 16 ++++++++++++---- backend/wayland/backend.c | 3 +-- backend/wayland/output.c | 20 +++++++++++++++----- backend/x11/backend.c | 3 +-- backend/x11/output.c | 11 ++++++++--- include/backend/drm/renderer.h | 1 - include/backend/headless.h | 3 +-- include/backend/wayland.h | 1 - include/backend/x11.h | 1 - include/wlr/render/wlr_renderer.h | 2 +- render/gles2/renderer.c | 1 + render/wlr_renderer.c | 15 +++++++++++++-- 14 files changed, 65 insertions(+), 33 deletions(-) diff --git a/backend/drm/renderer.c b/backend/drm/renderer.c index 4c65afae..fd5d637d 100644 --- a/backend/drm/renderer.c +++ b/backend/drm/renderer.c @@ -30,8 +30,8 @@ bool init_drm_renderer(struct wlr_drm_backend *drm, return false; } - renderer->wlr_rend = wlr_renderer_autocreate(&renderer->egl, - EGL_PLATFORM_GBM_KHR, renderer->gbm); + renderer->wlr_rend = wlr_renderer_autocreate(EGL_PLATFORM_GBM_KHR, + renderer->gbm); if (!renderer->wlr_rend) { wlr_log(WLR_ERROR, "Failed to create EGL/WLR renderer"); goto error_gbm; @@ -66,7 +66,6 @@ void finish_drm_renderer(struct wlr_drm_renderer *renderer) { wlr_allocator_destroy(&renderer->allocator->base); wlr_renderer_destroy(renderer->wlr_rend); - wlr_egl_finish(&renderer->egl); gbm_device_destroy(renderer->gbm); } @@ -117,7 +116,8 @@ bool drm_surface_make_current(struct wlr_drm_surface *surf, return false; } - if (!wlr_egl_make_current(&surf->renderer->egl, EGL_NO_SURFACE, NULL)) { + struct wlr_egl *egl = wlr_gles2_renderer_get_egl(surf->renderer->wlr_rend); + if (!wlr_egl_make_current(egl, EGL_NO_SURFACE, NULL)) { return false; } if (!wlr_renderer_bind_buffer(surf->renderer->wlr_rend, surf->back_buffer)) { @@ -130,9 +130,10 @@ bool drm_surface_make_current(struct wlr_drm_surface *surf, void drm_surface_unset_current(struct wlr_drm_surface *surf) { assert(surf->back_buffer != NULL); + struct wlr_egl *egl = wlr_gles2_renderer_get_egl(surf->renderer->wlr_rend); wlr_renderer_bind_buffer(surf->renderer->wlr_rend, NULL); - wlr_egl_unset_current(&surf->renderer->egl); + wlr_egl_unset_current(egl); wlr_buffer_unlock(surf->back_buffer); surf->back_buffer = NULL; diff --git a/backend/headless/backend.c b/backend/headless/backend.c index 5e5cee6a..963773a5 100644 --- a/backend/headless/backend.c +++ b/backend/headless/backend.c @@ -71,10 +71,11 @@ static void backend_destroy(struct wlr_backend *wlr_backend) { wlr_signal_emit_safe(&wlr_backend->events.destroy, backend); free(backend->format); - if (backend->egl == &backend->priv_egl) { + + if (!backend->has_parent_renderer) { wlr_renderer_destroy(backend->renderer); - wlr_egl_finish(&backend->priv_egl); } + wlr_allocator_destroy(backend->allocator); free(backend); } @@ -114,7 +115,6 @@ static bool backend_init(struct wlr_headless_backend *backend, backend->allocator = allocator; backend->renderer = renderer; - backend->egl = wlr_gles2_renderer_get_egl(renderer); const struct wlr_drm_format_set *formats = wlr_renderer_get_dmabuf_render_formats(backend->renderer); @@ -206,7 +206,7 @@ struct wlr_backend *wlr_headless_backend_create(struct wl_display *display) { goto error_backend; } - struct wlr_renderer *renderer = wlr_renderer_autocreate(&backend->priv_egl, + struct wlr_renderer *renderer = wlr_renderer_autocreate( EGL_PLATFORM_GBM_KHR, gbm_alloc->gbm_device); if (!renderer) { wlr_log(WLR_ERROR, "Failed to create renderer"); @@ -257,6 +257,8 @@ struct wlr_backend *wlr_headless_backend_create_with_renderer( goto error_backend; } + backend->has_parent_renderer = true; + if (!backend_init(backend, display, &gbm_alloc->base, renderer)) { goto error_init; } diff --git a/backend/headless/output.c b/backend/headless/output.c index bb15c23d..ee1fd317 100644 --- a/backend/headless/output.c +++ b/backend/headless/output.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include "backend/headless.h" @@ -42,6 +43,8 @@ static bool output_attach_render(struct wlr_output *wlr_output, int *buffer_age) { struct wlr_headless_output *output = headless_output_from_output(wlr_output); + struct wlr_egl *egl = wlr_gles2_renderer_get_egl( + output->backend->renderer); wlr_buffer_unlock(output->back_buffer); output->back_buffer = wlr_swapchain_acquire(output->swapchain, buffer_age); @@ -49,7 +52,7 @@ static bool output_attach_render(struct wlr_output *wlr_output, return false; } - if (!wlr_egl_make_current(output->backend->egl, EGL_NO_SURFACE, NULL)) { + if (!wlr_egl_make_current(egl, EGL_NO_SURFACE, NULL)) { return false; } if (!wlr_renderer_bind_buffer(output->backend->renderer, @@ -97,7 +100,10 @@ static bool output_commit(struct wlr_output *wlr_output) { assert(output->back_buffer != NULL); wlr_renderer_bind_buffer(output->backend->renderer, NULL); - wlr_egl_unset_current(output->backend->egl); + + struct wlr_egl *egl = wlr_gles2_renderer_get_egl( + output->backend->renderer); + wlr_egl_unset_current(egl); buffer = output->back_buffer; output->back_buffer = NULL; @@ -122,10 +128,12 @@ static bool output_commit(struct wlr_output *wlr_output) { static void output_rollback_render(struct wlr_output *wlr_output) { struct wlr_headless_output *output = headless_output_from_output(wlr_output); - assert(wlr_egl_is_current(output->backend->egl)); + struct wlr_egl *egl = wlr_gles2_renderer_get_egl( + output->backend->renderer); + assert(wlr_egl_is_current(egl)); wlr_renderer_bind_buffer(output->backend->renderer, NULL); - wlr_egl_unset_current(output->backend->egl); + wlr_egl_unset_current(egl); wlr_buffer_unlock(output->back_buffer); output->back_buffer = NULL; diff --git a/backend/wayland/backend.c b/backend/wayland/backend.c index d562be7a..1e2d2d72 100644 --- a/backend/wayland/backend.c +++ b/backend/wayland/backend.c @@ -206,7 +206,6 @@ static void backend_destroy(struct wlr_backend *backend) { wl_event_source_remove(wl->remote_display_src); wlr_renderer_destroy(wl->renderer); - wlr_egl_finish(&wl->egl); wlr_drm_format_set_finish(&wl->linux_dmabuf_v1_formats); @@ -314,7 +313,7 @@ struct wlr_backend *wlr_wl_backend_create(struct wl_display *display, } wl_event_source_check(wl->remote_display_src); - wl->renderer = wlr_renderer_autocreate(&wl->egl, EGL_PLATFORM_WAYLAND_EXT, + wl->renderer = wlr_renderer_autocreate(EGL_PLATFORM_WAYLAND_EXT, wl->remote_display); if (!wl->renderer) { wlr_log(WLR_ERROR, "Could not create renderer"); diff --git a/backend/wayland/output.c b/backend/wayland/output.c index 633e9a59..bf2d97ca 100644 --- a/backend/wayland/output.c +++ b/backend/wayland/output.c @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -115,6 +116,8 @@ static bool output_set_custom_mode(struct wlr_output *wlr_output, static bool output_attach_render(struct wlr_output *wlr_output, int *buffer_age) { struct wlr_wl_output *output = get_wl_output_from_output(wlr_output); + struct wlr_egl *egl = wlr_gles2_renderer_get_egl( + output->backend->renderer); wlr_buffer_unlock(output->back_buffer); output->back_buffer = wlr_swapchain_acquire(output->swapchain, buffer_age); @@ -122,7 +125,7 @@ static bool output_attach_render(struct wlr_output *wlr_output, return false; } - if (!wlr_egl_make_current(&output->backend->egl, EGL_NO_SURFACE, NULL)) { + if (!wlr_egl_make_current(egl, EGL_NO_SURFACE, NULL)) { return false; } if (!wlr_renderer_bind_buffer(output->backend->renderer, @@ -309,7 +312,10 @@ static bool output_commit(struct wlr_output *wlr_output) { wlr_buffer = output->back_buffer; wlr_renderer_bind_buffer(output->backend->renderer, NULL); - wlr_egl_unset_current(&output->backend->egl); + + struct wlr_egl *egl = wlr_gles2_renderer_get_egl( + output->backend->renderer); + wlr_egl_unset_current(egl); break; case WLR_OUTPUT_STATE_BUFFER_SCANOUT:; wlr_buffer = wlr_output->pending.buffer; @@ -369,8 +375,10 @@ static bool output_commit(struct wlr_output *wlr_output) { static void output_rollback_render(struct wlr_output *wlr_output) { struct wlr_wl_output *output = get_wl_output_from_output(wlr_output); + struct wlr_egl *egl = wlr_gles2_renderer_get_egl( + output->backend->renderer); wlr_renderer_bind_buffer(output->backend->renderer, NULL); - wlr_egl_unset_current(&output->backend->egl); + wlr_egl_unset_current(egl); } static bool output_set_cursor(struct wlr_output *wlr_output, @@ -402,6 +410,8 @@ static bool output_set_cursor(struct wlr_output *wlr_output, struct wl_surface *surface = output->cursor.surface; if (texture != NULL) { + struct wlr_egl *egl = wlr_gles2_renderer_get_egl( + output->backend->renderer); int width = texture->width * wlr_output->scale / scale; int height = texture->height * wlr_output->scale / scale; @@ -423,7 +433,7 @@ static bool output_set_cursor(struct wlr_output *wlr_output, return false; } - if (!wlr_egl_make_current(&output->backend->egl, EGL_NO_SURFACE, NULL)) { + if (!wlr_egl_make_current(egl, EGL_NO_SURFACE, NULL)) { return false; } if (!wlr_renderer_bind_buffer(output->backend->renderer, wlr_buffer)) { @@ -447,7 +457,7 @@ static bool output_set_cursor(struct wlr_output *wlr_output, wlr_renderer_end(backend->renderer); wlr_renderer_bind_buffer(output->backend->renderer, NULL); - wlr_egl_unset_current(&output->backend->egl); + wlr_egl_unset_current(egl); struct wlr_wl_buffer *buffer = get_or_create_wl_buffer(output->backend, wlr_buffer); diff --git a/backend/x11/backend.c b/backend/x11/backend.c index c16191f8..e8908e5b 100644 --- a/backend/x11/backend.c +++ b/backend/x11/backend.c @@ -181,7 +181,6 @@ static void backend_destroy(struct wlr_backend *backend) { wl_list_remove(&x11->display_destroy.link); wlr_renderer_destroy(x11->renderer); - wlr_egl_finish(&x11->egl); wlr_allocator_destroy(x11->allocator); wlr_drm_format_set_finish(&x11->dri3_formats); free(x11->drm_format); @@ -535,7 +534,7 @@ struct wlr_backend *wlr_x11_backend_create(struct wl_display *display, } x11->allocator = &gbm_alloc->base; - x11->renderer = wlr_renderer_autocreate(&x11->egl, EGL_PLATFORM_GBM_KHR, + x11->renderer = wlr_renderer_autocreate(EGL_PLATFORM_GBM_KHR, gbm_alloc->gbm_device); if (x11->renderer == NULL) { wlr_log(WLR_ERROR, "Failed to create renderer"); diff --git a/backend/x11/output.c b/backend/x11/output.c index 86729ace..4d764414 100644 --- a/backend/x11/output.c +++ b/backend/x11/output.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include "backend/x11.h" @@ -97,6 +98,7 @@ static bool output_attach_render(struct wlr_output *wlr_output, int *buffer_age) { struct wlr_x11_output *output = get_x11_output_from_output(wlr_output); struct wlr_x11_backend *x11 = output->x11; + struct wlr_egl *egl = wlr_gles2_renderer_get_egl(x11->renderer); wlr_buffer_unlock(output->back_buffer); output->back_buffer = wlr_swapchain_acquire(output->swapchain, buffer_age); @@ -104,7 +106,7 @@ static bool output_attach_render(struct wlr_output *wlr_output, return false; } - if (!wlr_egl_make_current(&x11->egl, EGL_NO_SURFACE, NULL)) { + if (!wlr_egl_make_current(egl, EGL_NO_SURFACE, NULL)) { return false; } if (!wlr_renderer_bind_buffer(x11->renderer, output->back_buffer)) { @@ -204,11 +206,12 @@ static struct wlr_x11_buffer *get_or_create_x11_buffer( static bool output_commit_buffer(struct wlr_x11_output *output) { struct wlr_x11_backend *x11 = output->x11; + struct wlr_egl *egl = wlr_gles2_renderer_get_egl(x11->renderer); assert(output->back_buffer != NULL); wlr_renderer_bind_buffer(x11->renderer, NULL); - wlr_egl_unset_current(&x11->egl); + wlr_egl_unset_current(egl); struct wlr_x11_buffer *x11_buffer = get_or_create_x11_buffer(output, output->back_buffer); @@ -315,8 +318,10 @@ static bool output_commit(struct wlr_output *wlr_output) { static void output_rollback_render(struct wlr_output *wlr_output) { struct wlr_x11_output *output = get_x11_output_from_output(wlr_output); struct wlr_x11_backend *x11 = output->x11; + struct wlr_egl *egl = wlr_gles2_renderer_get_egl(x11->renderer); + wlr_renderer_bind_buffer(x11->renderer, NULL); - wlr_egl_unset_current(&x11->egl); + wlr_egl_unset_current(egl); } static const struct wlr_output_impl output_impl = { diff --git a/include/backend/drm/renderer.h b/include/backend/drm/renderer.h index a22cc56a..e422ac4b 100644 --- a/include/backend/drm/renderer.h +++ b/include/backend/drm/renderer.h @@ -15,7 +15,6 @@ struct wlr_buffer; struct wlr_drm_renderer { struct wlr_drm_backend *backend; struct gbm_device *gbm; - struct wlr_egl egl; struct wlr_renderer *wlr_rend; struct wlr_gbm_allocator *allocator; diff --git a/include/backend/headless.h b/include/backend/headless.h index 4a29b033..bf15f5c7 100644 --- a/include/backend/headless.h +++ b/include/backend/headless.h @@ -8,8 +8,6 @@ struct wlr_headless_backend { struct wlr_backend backend; - struct wlr_egl priv_egl; // may be uninitialized - struct wlr_egl *egl; struct wlr_renderer *renderer; struct wlr_allocator *allocator; struct wlr_drm_format *format; @@ -19,6 +17,7 @@ struct wlr_headless_backend { struct wl_list input_devices; struct wl_listener display_destroy; struct wl_listener renderer_destroy; + bool has_parent_renderer; bool started; }; diff --git a/include/backend/wayland.h b/include/backend/wayland.h index 1c874b35..dc9670f5 100644 --- a/include/backend/wayland.h +++ b/include/backend/wayland.h @@ -21,7 +21,6 @@ struct wlr_wl_backend { struct wl_display *local_display; struct wl_list devices; struct wl_list outputs; - struct wlr_egl egl; struct wlr_renderer *renderer; struct wlr_drm_format *format; struct wlr_allocator *allocator; diff --git a/include/backend/x11.h b/include/backend/x11.h index e952587d..db6e5870 100644 --- a/include/backend/x11.h +++ b/include/backend/x11.h @@ -77,7 +77,6 @@ struct wlr_x11_backend { struct wlr_keyboard keyboard; struct wlr_input_device keyboard_dev; - struct wlr_egl egl; struct wlr_renderer *renderer; struct wlr_drm_format_set dri3_formats; const struct wlr_x11_format *x11_format; diff --git a/include/wlr/render/wlr_renderer.h b/include/wlr/render/wlr_renderer.h index 22c37b77..c736722a 100644 --- a/include/wlr/render/wlr_renderer.h +++ b/include/wlr/render/wlr_renderer.h @@ -33,7 +33,7 @@ struct wlr_renderer { } events; }; -struct wlr_renderer *wlr_renderer_autocreate(struct wlr_egl *egl, EGLenum platform, +struct wlr_renderer *wlr_renderer_autocreate(EGLenum platform, void *remote_display); void wlr_renderer_begin(struct wlr_renderer *r, uint32_t width, uint32_t height); diff --git a/render/gles2/renderer.c b/render/gles2/renderer.c index 76114278..6ae5e843 100644 --- a/render/gles2/renderer.c +++ b/render/gles2/renderer.c @@ -674,6 +674,7 @@ static void gles2_destroy(struct wlr_renderer *wlr_renderer) { struct wlr_gles2_renderer *renderer = gles2_get_renderer(wlr_renderer); wlr_egl_make_current(renderer->egl, EGL_NO_SURFACE, NULL); + wlr_egl_finish(renderer->egl); struct wlr_gles2_buffer *buffer, *buffer_tmp; wl_list_for_each_safe(buffer, buffer_tmp, &renderer->buffers, link) { diff --git a/render/wlr_renderer.c b/render/wlr_renderer.c index e77c41d9..69cc0363 100644 --- a/render/wlr_renderer.c +++ b/render/wlr_renderer.c @@ -247,13 +247,24 @@ bool wlr_renderer_init_wl_display(struct wlr_renderer *r, return true; } -struct wlr_renderer *wlr_renderer_autocreate(struct wlr_egl *egl, - EGLenum platform, void *remote_display) { +struct wlr_renderer *wlr_renderer_autocreate(EGLenum platform, + void *remote_display) { + struct wlr_egl *egl = calloc(1, sizeof(*egl)); + if (egl == NULL) { + wlr_log_errno(WLR_ERROR, "Allocation failed"); + return NULL; + } + if (!wlr_egl_init(egl, platform, remote_display, NULL, 0)) { wlr_log(WLR_ERROR, "Could not initialize EGL"); return NULL; } + /* + * wlr_renderer becomes the owner of the previously wlr_egl, and will + * take care of freeing the allocated memory + * TODO: move the wlr_egl logic to wlr_gles2_renderer + */ struct wlr_renderer *renderer = wlr_gles2_renderer_create(egl); if (!renderer) { wlr_egl_finish(egl);