diff options
author | Simon Zeni <simon@bl4ckb0ne.ca> | 2021-04-28 10:11:09 -0400 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2021-04-28 20:55:57 +0200 |
commit | cc1b66364cc9f29456727f9864ee04e57babe8e7 (patch) | |
tree | b560a03c1ca3e5efc973f27a64e9ce4aa784bab3 /backend/headless | |
parent | 318e3ac92cd3a172932370a7da8b2c2d24231758 (diff) |
backend: use wlr_allocator_autocreate
Diffstat (limited to 'backend/headless')
-rw-r--r-- | backend/headless/backend.c | 49 |
1 files changed, 9 insertions, 40 deletions
diff --git a/backend/headless/backend.c b/backend/headless/backend.c index 7f1e6aa4..be44a980 100644 --- a/backend/headless/backend.c +++ b/backend/headless/backend.c @@ -120,15 +120,12 @@ static void handle_renderer_destroy(struct wl_listener *listener, void *data) { } static bool backend_init(struct wlr_headless_backend *backend, - struct wl_display *display, struct wlr_allocator *allocator, - struct wlr_renderer *renderer) { + struct wl_display *display, struct wlr_renderer *renderer) { wlr_backend_init(&backend->backend, &backend_impl); backend->display = display; wl_list_init(&backend->outputs); wl_list_init(&backend->input_devices); - backend->allocator = allocator; - if (renderer == NULL) { renderer = wlr_renderer_autocreate(&backend->backend); if (!renderer) { @@ -138,6 +135,12 @@ static bool backend_init(struct wlr_headless_backend *backend, } backend->renderer = renderer; + backend->allocator = wlr_allocator_autocreate(&backend->backend, renderer); + if (!backend->allocator) { + wlr_log(WLR_ERROR, "Failed to create allocator"); + return false; + } + const struct wlr_drm_format_set *formats = wlr_renderer_get_render_formats(backend->renderer); if (formats == NULL) { @@ -219,33 +222,16 @@ struct wlr_backend *wlr_headless_backend_create(struct wl_display *display) { backend->drm_fd = open_drm_render_node(); if (backend->drm_fd < 0) { wlr_log(WLR_ERROR, "Failed to open DRM render node"); - goto error_drm_fd; - } - - int drm_fd = fcntl(backend->drm_fd, F_DUPFD_CLOEXEC, 0); - if (drm_fd < 0) { - wlr_log_errno(WLR_ERROR, "fcntl(F_DUPFD_CLOEXEC) failed"); - goto error_dup; } - struct wlr_allocator *alloc = wlr_gbm_allocator_create(drm_fd); - if (alloc == NULL) { - wlr_log(WLR_ERROR, "Failed to create GBM allocator"); - close(drm_fd); - goto error_dup; - } - - if (!backend_init(backend, display, alloc, NULL)) { + if (!backend_init(backend, display, NULL)) { goto error_init; } return &backend->backend; error_init: - wlr_allocator_destroy(alloc); -error_dup: close(backend->drm_fd); -error_drm_fd: free(backend); return NULL; } @@ -265,23 +251,9 @@ struct wlr_backend *wlr_headless_backend_create_with_renderer( backend->drm_fd = wlr_renderer_get_drm_fd(renderer); if (backend->drm_fd < 0) { wlr_log(WLR_ERROR, "Failed to get DRM device FD from renderer"); - goto error_drm_fd; - } - - int drm_fd = fcntl(backend->drm_fd, F_DUPFD_CLOEXEC, 0); - if (drm_fd < 0) { - wlr_log_errno(WLR_ERROR, "fcntl(F_DUPFD_CLOEXEC) failed"); - goto error_dup; - } - - struct wlr_allocator *alloc = wlr_gbm_allocator_create(drm_fd); - if (alloc == NULL) { - wlr_log(WLR_ERROR, "Failed to create GBM allocator"); - close(drm_fd); - goto error_dup; } - if (!backend_init(backend, display, alloc, renderer)) { + if (!backend_init(backend, display, renderer)) { goto error_init; } @@ -291,10 +263,7 @@ struct wlr_backend *wlr_headless_backend_create_with_renderer( return &backend->backend; error_init: - wlr_allocator_destroy(alloc); -error_dup: close(backend->drm_fd); -error_drm_fd: free(backend); return NULL; } |