From e128e6c08dc0a735b1a8c6cc61097eaf0f61fb83 Mon Sep 17 00:00:00 2001 From: Simon Zeni Date: Wed, 13 Jan 2021 22:49:07 -0500 Subject: [PATCH] render: drop egl parameters from wlr_renderer_autocreate --- backend/drm/renderer.c | 3 +-- backend/headless/backend.c | 3 +-- backend/wayland/backend.c | 3 +-- backend/x11/backend.c | 3 +-- include/wlr/render/egl.h | 1 + include/wlr/render/wlr_renderer.h | 4 ++-- render/egl.c | 5 +++++ render/wlr_renderer.c | 24 +++++++++++++++++++++--- 8 files changed, 33 insertions(+), 13 deletions(-) diff --git a/backend/drm/renderer.c b/backend/drm/renderer.c index f2d7677c..783fec74 100644 --- a/backend/drm/renderer.c +++ b/backend/drm/renderer.c @@ -29,8 +29,7 @@ bool init_drm_renderer(struct wlr_drm_backend *drm, return false; } - renderer->wlr_rend = wlr_renderer_autocreate(EGL_PLATFORM_GBM_KHR, - renderer->gbm); + renderer->wlr_rend = wlr_renderer_autocreate(&drm->backend); if (!renderer->wlr_rend) { wlr_log(WLR_ERROR, "Failed to create EGL/WLR renderer"); goto error_gbm; diff --git a/backend/headless/backend.c b/backend/headless/backend.c index d48c4953..02e3774a 100644 --- a/backend/headless/backend.c +++ b/backend/headless/backend.c @@ -219,8 +219,7 @@ struct wlr_backend *wlr_headless_backend_create(struct wl_display *display) { goto error_dup; } - struct wlr_renderer *renderer = wlr_renderer_autocreate( - EGL_PLATFORM_GBM_KHR, gbm_alloc->gbm_device); + struct wlr_renderer *renderer = wlr_renderer_autocreate(&backend->backend); if (!renderer) { wlr_log(WLR_ERROR, "Failed to create renderer"); goto error_renderer; diff --git a/backend/wayland/backend.c b/backend/wayland/backend.c index a1e0f970..f2ce6947 100644 --- a/backend/wayland/backend.c +++ b/backend/wayland/backend.c @@ -437,8 +437,7 @@ struct wlr_backend *wlr_wl_backend_create(struct wl_display *display, } wl->allocator = &gbm_alloc->base; - wl->renderer = wlr_renderer_autocreate(EGL_PLATFORM_GBM_KHR, - gbm_alloc->gbm_device); + wl->renderer = wlr_renderer_autocreate(&wl->backend); if (wl->renderer == NULL) { wlr_log(WLR_ERROR, "Failed to create renderer"); goto error_allocator; diff --git a/backend/x11/backend.c b/backend/x11/backend.c index 84938de3..9da474f5 100644 --- a/backend/x11/backend.c +++ b/backend/x11/backend.c @@ -547,8 +547,7 @@ struct wlr_backend *wlr_x11_backend_create(struct wl_display *display, } x11->allocator = &gbm_alloc->base; - x11->renderer = wlr_renderer_autocreate(EGL_PLATFORM_GBM_KHR, - gbm_alloc->gbm_device); + x11->renderer = wlr_renderer_autocreate(&x11->backend); if (x11->renderer == NULL) { wlr_log(WLR_ERROR, "Failed to create renderer"); goto error_event; diff --git a/include/wlr/render/egl.h b/include/wlr/render/egl.h index 845cc388..82aa9505 100644 --- a/include/wlr/render/egl.h +++ b/include/wlr/render/egl.h @@ -41,6 +41,7 @@ struct wlr_egl { EGLConfig config; // may be EGL_NO_CONFIG EGLContext context; EGLDeviceEXT device; // may be EGL_NO_DEVICE_EXT + struct gbm_device *gbm_device; struct { // Display extensions diff --git a/include/wlr/render/wlr_renderer.h b/include/wlr/render/wlr_renderer.h index c736722a..1b2c3d6e 100644 --- a/include/wlr/render/wlr_renderer.h +++ b/include/wlr/render/wlr_renderer.h @@ -11,6 +11,7 @@ #include #include +#include #include #include #include @@ -33,8 +34,7 @@ struct wlr_renderer { } events; }; -struct wlr_renderer *wlr_renderer_autocreate(EGLenum platform, - void *remote_display); +struct wlr_renderer *wlr_renderer_autocreate(struct wlr_backend *backend); void wlr_renderer_begin(struct wlr_renderer *r, uint32_t width, uint32_t height); void wlr_renderer_end(struct wlr_renderer *r); diff --git a/render/egl.c b/render/egl.c index 1c986e47..9fa1068f 100644 --- a/render/egl.c +++ b/render/egl.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -362,6 +363,10 @@ void wlr_egl_destroy(struct wlr_egl *egl) { return; } + if (egl->gbm_device) { + gbm_device_destroy(egl->gbm_device); + } + wlr_drm_format_set_finish(&egl->dmabuf_render_formats); wlr_drm_format_set_finish(&egl->dmabuf_texture_formats); diff --git a/render/wlr_renderer.c b/render/wlr_renderer.c index 377b795e..3c757430 100644 --- a/render/wlr_renderer.c +++ b/render/wlr_renderer.c @@ -1,6 +1,8 @@ #include #include #include +#include +#include #include #include #include @@ -8,6 +10,7 @@ #include #include "util/signal.h" #include "render/wlr_renderer.h" +#include "backend/backend.h" void wlr_renderer_init(struct wlr_renderer *renderer, const struct wlr_renderer_impl *impl) { @@ -247,14 +250,29 @@ bool wlr_renderer_init_wl_display(struct wlr_renderer *r, return true; } -struct wlr_renderer *wlr_renderer_autocreate(EGLenum platform, - void *remote_display) { - struct wlr_egl *egl = wlr_egl_create(platform, remote_display, NULL); +struct wlr_renderer *wlr_renderer_autocreate(struct wlr_backend *backend) { + int fd = backend_get_drm_fd(backend); + if (fd < 0) { + wlr_log(WLR_ERROR, "Failed to get DRM FD from backend"); + return NULL; + } + + struct gbm_device *gbm_device = gbm_create_device(fd); + if (!gbm_device) { + wlr_log(WLR_ERROR, "Failed to create GBM device"); + return NULL; + } + + struct wlr_egl *egl = wlr_egl_create(EGL_PLATFORM_GBM_KHR, gbm_device, + NULL); if (egl == NULL) { wlr_log(WLR_ERROR, "Could not initialize EGL"); + gbm_device_destroy(gbm_device); return NULL; } + egl->gbm_device = gbm_device; + struct wlr_renderer *renderer = wlr_gles2_renderer_create(egl); if (!renderer) { wlr_log(WLR_ERROR, "Failed to create GLES2 renderer");