Skip to content
This repository has been archived by the owner on Nov 1, 2021. It is now read-only.

Commit

Permalink
backend: create renderer and allocator in wlr_backend_autocreate
Browse files Browse the repository at this point in the history
Instead of ensuring the renderer and allocator are initialized in each
backend, do it in wlr_backend_autocreate. This allows compositors to
create backends without any renderer/allocator if they side-step
wlr_backend_autocreate.

Since the wlr_backend_get_renderer and backend_get_allocator end up
calling wlr_renderer_autocreate and wlr_allocator_autocreate, it sounds
like a good idea to centralize all of the opimionated bits in one place.
  • Loading branch information
emersion authored and bl4ckb0ne committed Sep 30, 2021
1 parent 20d9448 commit 3d0848d
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 35 deletions.
23 changes: 19 additions & 4 deletions backend/backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,21 @@ static size_t parse_outputs_env(const char *name) {
return outputs;
}

static struct wlr_backend *ensure_backend_renderer_and_allocator(
struct wlr_backend *backend) {
struct wlr_renderer *renderer = wlr_backend_get_renderer(backend);
if (renderer == NULL) {
wlr_backend_destroy(backend);
return NULL;
}
struct wlr_allocator *allocator = backend_get_allocator(backend);
if (allocator == NULL) {
wlr_backend_destroy(backend);
return NULL;
}
return backend;
}

static struct wlr_backend *attempt_wl_backend(struct wl_display *display) {
struct wlr_backend *backend = wlr_wl_backend_create(display, NULL);
if (backend == NULL) {
Expand All @@ -220,7 +235,7 @@ static struct wlr_backend *attempt_wl_backend(struct wl_display *display) {
wlr_wl_output_create(backend);
}

return backend;
return ensure_backend_renderer_and_allocator(backend);
}

#if WLR_HAS_X11_BACKEND
Expand All @@ -236,7 +251,7 @@ static struct wlr_backend *attempt_x11_backend(struct wl_display *display,
wlr_x11_output_create(backend);
}

return backend;
return ensure_backend_renderer_and_allocator(backend);
}
#endif

Expand All @@ -252,7 +267,7 @@ static struct wlr_backend *attempt_headless_backend(
wlr_headless_add_output(backend, 1280, 720);
}

return backend;
return ensure_backend_renderer_and_allocator(backend);
}

static struct wlr_backend *attempt_noop_backend(struct wl_display *display) {
Expand Down Expand Up @@ -297,7 +312,7 @@ static struct wlr_backend *attempt_drm_backend(struct wl_display *display,
wlr_multi_backend_add(backend, drm);
}

return primary_drm;
return ensure_backend_renderer_and_allocator(primary_drm);
}
#endif

Expand Down
7 changes: 0 additions & 7 deletions backend/drm/backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include <wlr/interfaces/wlr_output.h>
#include <wlr/util/log.h>
#include <xf86drm.h>
#include "backend/backend.h"
#include "backend/drm/drm.h"
#include "util/signal.h"

Expand Down Expand Up @@ -258,12 +257,6 @@ struct wlr_backend *wlr_drm_backend_create(struct wl_display *display,
}
}

struct wlr_renderer *renderer = wlr_backend_get_renderer(&drm->backend);
struct wlr_allocator *allocator = backend_get_allocator(&drm->backend);
if (renderer == NULL || allocator == NULL) {
goto error_mgpu_renderer;
}

drm->session_destroy.notify = handle_session_destroy;
wl_signal_add(&session->events.destroy, &drm->session_destroy);

Expand Down
7 changes: 0 additions & 7 deletions backend/headless/backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@
#include <wlr/render/wlr_renderer.h>
#include <wlr/util/log.h>
#include <xf86drm.h>
#include "backend/backend.h"
#include "backend/headless.h"
#include "render/drm_format_set.h"
#include "render/wlr_renderer.h"
#include "util/signal.h"

struct wlr_headless_backend *headless_backend_from_backend(
Expand Down Expand Up @@ -137,11 +135,6 @@ static bool backend_init(struct wlr_headless_backend *backend,
wl_signal_add(&renderer->events.destroy, &backend->parent_renderer_destroy);
}

if (backend_get_allocator(&backend->backend) == NULL) {
wlr_log(WLR_ERROR, "Failed to create allocator");
return false;
}

backend->display_destroy.notify = handle_display_destroy;
wl_display_add_destroy_listener(display, &backend->display_destroy);

Expand Down
10 changes: 0 additions & 10 deletions backend/wayland/backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@
#include <wlr/interfaces/wlr_output.h>
#include <wlr/util/log.h>

#include "backend/backend.h"
#include "backend/wayland.h"
#include "render/drm_format_set.h"
#include "render/pixel_format.h"
#include "render/wlr_renderer.h"
#include "util/signal.h"

#include "drm-client-protocol.h"
Expand Down Expand Up @@ -444,19 +442,11 @@ struct wlr_backend *wlr_wl_backend_create(struct wl_display *display,
wl->drm_fd = -1;
}

struct wlr_renderer *renderer = wlr_backend_get_renderer(&wl->backend);
struct wlr_allocator *allocator = backend_get_allocator(&wl->backend);
if (renderer == NULL || allocator == NULL) {
goto error_drm_fd;
}

wl->local_display_destroy.notify = handle_display_destroy;
wl_display_add_destroy_listener(display, &wl->local_display_destroy);

return &wl->backend;

error_drm_fd:
close(wl->drm_fd);
error_remote_display_src:
wl_event_source_remove(wl->remote_display_src);
error_registry:
Expand Down
7 changes: 0 additions & 7 deletions backend/x11/backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include <wlr/interfaces/wlr_pointer.h>
#include <wlr/util/log.h>

#include "backend/backend.h"
#include "backend/x11.h"
#include "render/drm_format_set.h"
#include "util/signal.h"
Expand Down Expand Up @@ -611,12 +610,6 @@ struct wlr_backend *wlr_x11_backend_create(struct wl_display *display,
}
}

struct wlr_renderer *renderer = wlr_backend_get_renderer(&x11->backend);
struct wlr_allocator *allocator = backend_get_allocator(&x11->backend);
if (renderer == NULL || allocator == NULL) {
goto error_event;
}

// Windows can only display buffers with the depth they were created with
// TODO: look into changing the window's depth at runtime
const struct wlr_drm_format *dri3_format =
Expand Down

0 comments on commit 3d0848d

Please sign in to comment.