From 4e804ef40f46136d4fe84603a8236adc172260f8 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Tue, 19 Dec 2017 18:14:47 -0500 Subject: [PATCH 01/11] add backend destroy event --- backend/backend.c | 2 ++ include/wlr/backend.h | 1 + 2 files changed, 3 insertions(+) diff --git a/backend/backend.c b/backend/backend.c index f93dde38..58181947 100644 --- a/backend/backend.c +++ b/backend/backend.c @@ -18,6 +18,7 @@ void wlr_backend_init(struct wlr_backend *backend, const struct wlr_backend_impl *impl) { assert(backend); backend->impl = impl; + wl_signal_init(&backend->events.destroy); wl_signal_init(&backend->events.input_add); wl_signal_init(&backend->events.input_remove); wl_signal_init(&backend->events.output_add); @@ -32,6 +33,7 @@ bool wlr_backend_start(struct wlr_backend *backend) { } void wlr_backend_destroy(struct wlr_backend *backend) { + wl_signal_emit(&backend->events.destroy, backend); if (backend->impl && backend->impl->destroy) { backend->impl->destroy(backend); } else { diff --git a/include/wlr/backend.h b/include/wlr/backend.h index 2c8fd982..4632dcbf 100644 --- a/include/wlr/backend.h +++ b/include/wlr/backend.h @@ -11,6 +11,7 @@ struct wlr_backend { const struct wlr_backend_impl *impl; struct { + struct wl_signal destroy; struct wl_signal input_add; struct wl_signal input_remove; struct wl_signal output_add; From a937016e38efe3d7ad71540755833242059e6902 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Tue, 19 Dec 2017 18:25:46 -0500 Subject: [PATCH 02/11] remove session from multibackend --- backend/backend.c | 2 +- backend/drm/backend.c | 5 +++++ backend/multi/backend.c | 22 +++++++++------------- include/backend/drm/drm.h | 2 ++ include/backend/multi.h | 1 - include/wlr/backend/multi.h | 4 ++-- 6 files changed, 19 insertions(+), 17 deletions(-) diff --git a/backend/backend.c b/backend/backend.c index 58181947..7dfd6676 100644 --- a/backend/backend.c +++ b/backend/backend.c @@ -93,7 +93,7 @@ struct wlr_backend *wlr_backend_autocreate(struct wl_display *display) { return NULL; } - backend = wlr_multi_backend_create(display, session); + backend = wlr_multi_backend_create(display); if (!backend) { goto error_session; } diff --git a/backend/drm/backend.c b/backend/drm/backend.c index 6be5e5d5..112b2b61 100644 --- a/backend/drm/backend.c +++ b/backend/drm/backend.c @@ -174,3 +174,8 @@ error_fd: free(drm); return NULL; } + +struct wlr_session *wlr_drm_backend_get_session(struct wlr_backend *backend) { + struct wlr_drm_backend *drm = (struct wlr_drm_backend *)backend; + return drm->session; +} diff --git a/backend/multi/backend.c b/backend/multi/backend.c index 3815a0bc..df7c8c6d 100644 --- a/backend/multi/backend.c +++ b/backend/multi/backend.c @@ -5,6 +5,7 @@ #include #include #include "backend/multi.h" +#include "backend/drm/drm.h" struct subbackend_state { struct wlr_backend *backend; @@ -57,14 +58,7 @@ struct wlr_backend_impl backend_impl = { .get_egl = multi_backend_get_egl, }; -static void handle_display_destroy(struct wl_listener *listener, void *data) { - struct wlr_multi_backend *backend = - wl_container_of(listener, backend, display_destroy); - multi_backend_destroy(&backend->backend); -} - -struct wlr_backend *wlr_multi_backend_create(struct wl_display *display, - struct wlr_session *session) { +struct wlr_backend *wlr_multi_backend_create(struct wl_display *display) { struct wlr_multi_backend *backend = calloc(1, sizeof(struct wlr_multi_backend)); if (!backend) { @@ -72,13 +66,9 @@ struct wlr_backend *wlr_multi_backend_create(struct wl_display *display, return NULL; } - backend->session = session; wl_list_init(&backend->backends); wlr_backend_init(&backend->backend, &backend_impl); - session->display_destroy.notify = handle_display_destroy; - wl_display_add_destroy_listener(display, &session->display_destroy); - return &backend->backend; } @@ -140,5 +130,11 @@ struct wlr_session *wlr_multi_get_session(struct wlr_backend *_backend) { assert(wlr_backend_is_multi(_backend)); struct wlr_multi_backend *backend = (struct wlr_multi_backend *)_backend; - return backend->session; + struct subbackend_state *sub; + wl_list_for_each(sub, &backend->backends, link) { + if (wlr_backend_is_drm(sub->backend)) { + return wlr_drm_backend_get_session(sub->backend); + } + } + return NULL; } diff --git a/include/backend/drm/drm.h b/include/backend/drm/drm.h index 278c387c..72671f45 100644 --- a/include/backend/drm/drm.h +++ b/include/backend/drm/drm.h @@ -143,4 +143,6 @@ int wlr_drm_event(int fd, uint32_t mask, void *data); void wlr_drm_connector_start_renderer(struct wlr_drm_connector *conn); +struct wlr_session *wlr_drm_backend_get_session(struct wlr_backend *backend); + #endif diff --git a/include/backend/multi.h b/include/backend/multi.h index 2798048d..f0e50fc0 100644 --- a/include/backend/multi.h +++ b/include/backend/multi.h @@ -9,7 +9,6 @@ struct wlr_multi_backend { struct wlr_backend backend; - struct wlr_session *session; struct wl_list backends; struct wl_listener display_destroy; diff --git a/include/wlr/backend/multi.h b/include/wlr/backend/multi.h index e56b07b1..fc53f369 100644 --- a/include/wlr/backend/multi.h +++ b/include/wlr/backend/multi.h @@ -4,8 +4,8 @@ #include #include -struct wlr_backend *wlr_multi_backend_create(struct wl_display *display, - struct wlr_session *session); +struct wlr_backend *wlr_multi_backend_create(struct wl_display *display); + void wlr_multi_backend_add(struct wlr_backend *multi, struct wlr_backend *backend); From 6c75a184e7f05305fce8f693052a40047b07fc2f Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Tue, 19 Dec 2017 18:33:26 -0500 Subject: [PATCH 03/11] subbackend state destroy --- backend/multi/backend.c | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/backend/multi/backend.c b/backend/multi/backend.c index df7c8c6d..8659d8ec 100644 --- a/backend/multi/backend.c +++ b/backend/multi/backend.c @@ -14,6 +14,7 @@ struct subbackend_state { struct wl_listener input_remove; struct wl_listener output_add; struct wl_listener output_remove; + struct wl_listener backend_destroy; struct wl_list link; }; @@ -29,13 +30,23 @@ static bool multi_backend_start(struct wlr_backend *wlr_backend) { return true; } +static void subbackend_state_destroy(struct subbackend_state *sub) { + wl_list_remove(&sub->input_add.link); + wl_list_remove(&sub->input_remove.link); + wl_list_remove(&sub->output_add.link); + wl_list_remove(&sub->output_remove.link); + wl_list_remove(&sub->backend_destroy.link); + wl_list_remove(&sub->link); + free(sub); +} + static void multi_backend_destroy(struct wlr_backend *wlr_backend) { struct wlr_multi_backend *backend = (struct wlr_multi_backend *)wlr_backend; wl_list_remove(&backend->display_destroy.link); struct subbackend_state *sub, *next; wl_list_for_each_safe(sub, next, &backend->backends, link) { + // XXX do we really want to take ownership over added backends? wlr_backend_destroy(sub->backend); - free(sub); } free(backend); } @@ -100,6 +111,13 @@ static void output_remove_reemit(struct wl_listener *listener, void *data) { wl_signal_emit(&state->container->events.output_remove, data); } +static void handle_subbackend_destroy(struct wl_listener *listener, + void *data) { + struct subbackend_state *state = wl_container_of(listener, + state, backend_destroy); + subbackend_state_destroy(state); +} + void wlr_multi_backend_add(struct wlr_backend *_multi, struct wlr_backend *backend) { assert(wlr_backend_is_multi(_multi)); @@ -115,15 +133,20 @@ void wlr_multi_backend_add(struct wlr_backend *_multi, sub->backend = backend; sub->container = &multi->backend; - sub->input_add.notify = input_add_reemit; - sub->input_remove.notify = input_remove_reemit; - sub->output_add.notify = output_add_reemit; - sub->output_remove.notify = output_remove_reemit; + wl_signal_add(&backend->events.destroy, &sub->backend_destroy); + sub->backend_destroy.notify = handle_subbackend_destroy; wl_signal_add(&backend->events.input_add, &sub->input_add); + sub->input_add.notify = input_add_reemit; + wl_signal_add(&backend->events.input_remove, &sub->input_remove); + sub->input_remove.notify = input_remove_reemit; + wl_signal_add(&backend->events.output_add, &sub->output_add); + sub->output_add.notify = output_add_reemit; + wl_signal_add(&backend->events.output_remove, &sub->output_remove); + sub->output_remove.notify = output_remove_reemit; } struct wlr_session *wlr_multi_get_session(struct wlr_backend *_backend) { From 58e69c9ce177f3de4790bddd161e9d74dd2e512c Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Tue, 19 Dec 2017 18:49:00 -0500 Subject: [PATCH 04/11] multibackend remove subbackend --- backend/multi/backend.c | 31 ++++++++++++++++++++++++++++++- include/wlr/backend/multi.h | 3 +++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/backend/multi/backend.c b/backend/multi/backend.c index 8659d8ec..e6be4a20 100644 --- a/backend/multi/backend.c +++ b/backend/multi/backend.c @@ -118,11 +118,27 @@ static void handle_subbackend_destroy(struct wl_listener *listener, subbackend_state_destroy(state); } +static struct subbackend_state *multi_backend_get_subbackend(struct wlr_multi_backend *multi, + struct wlr_backend *backend) { + struct subbackend_state *sub = NULL; + wl_list_for_each(sub, &multi->backends, link) { + if (sub->backend == backend) { + return sub; + } + } + return NULL; +} + void wlr_multi_backend_add(struct wlr_backend *_multi, struct wlr_backend *backend) { assert(wlr_backend_is_multi(_multi)); - struct wlr_multi_backend *multi = (struct wlr_multi_backend *)_multi; + + if (multi_backend_get_subbackend(multi, backend)) { + // already added + return; + } + struct subbackend_state *sub; if (!(sub = calloc(1, sizeof(struct subbackend_state)))) { wlr_log(L_ERROR, "Could not add backend: allocation failed"); @@ -149,6 +165,19 @@ void wlr_multi_backend_add(struct wlr_backend *_multi, sub->output_remove.notify = output_remove_reemit; } +void wlr_multi_backend_remove(struct wlr_backend *_multi, + struct wlr_backend *backend) { + assert(wlr_backend_is_multi(_multi)); + struct wlr_multi_backend *multi = (struct wlr_multi_backend *)_multi; + + struct subbackend_state *sub = + multi_backend_get_subbackend(multi, backend); + + if (sub) { + subbackend_state_destroy(sub); + } +} + struct wlr_session *wlr_multi_get_session(struct wlr_backend *_backend) { assert(wlr_backend_is_multi(_backend)); diff --git a/include/wlr/backend/multi.h b/include/wlr/backend/multi.h index fc53f369..35f7c165 100644 --- a/include/wlr/backend/multi.h +++ b/include/wlr/backend/multi.h @@ -9,6 +9,9 @@ struct wlr_backend *wlr_multi_backend_create(struct wl_display *display); void wlr_multi_backend_add(struct wlr_backend *multi, struct wlr_backend *backend); +void wlr_multi_backend_remove(struct wlr_backend *multi, + struct wlr_backend *backend); + bool wlr_backend_is_multi(struct wlr_backend *backend); struct wlr_session *wlr_multi_get_session(struct wlr_backend *base); From ca6a0ef1bbbd611c9ebf0ace08b8fc6af3883d09 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Tue, 19 Dec 2017 19:07:33 -0500 Subject: [PATCH 05/11] always return multibakend from autocreate --- backend/backend.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/backend/backend.c b/backend/backend.c index 7dfd6676..2adc3171 100644 --- a/backend/backend.c +++ b/backend/backend.c @@ -72,30 +72,31 @@ static struct wlr_backend *attempt_wl_backend(struct wl_display *display) { } struct wlr_backend *wlr_backend_autocreate(struct wl_display *display) { - struct wlr_backend *backend; + struct wlr_backend *backend = wlr_multi_backend_create(display); + if (!backend) { + wlr_log(L_ERROR, "could not allocate multibackend"); + return NULL; + } + if (getenv("WAYLAND_DISPLAY") || getenv("_WAYLAND_DISPLAY")) { - backend = attempt_wl_backend(display); - if (backend) { - return backend; + struct wlr_backend *wl_backend = attempt_wl_backend(display); + if (wl_backend) { + wlr_multi_backend_add(backend, wl_backend); } } const char *x11_display = getenv("DISPLAY"); if (x11_display) { - return wlr_x11_backend_create(display, x11_display); + struct wlr_backend *x11_backend = + wlr_x11_backend_create(display, x11_display); + wlr_multi_backend_add(backend, x11_backend); } // Attempt DRM+libinput - struct wlr_session *session = wlr_session_create(display); if (!session) { wlr_log(L_ERROR, "Failed to start a DRM session"); - return NULL; - } - - backend = wlr_multi_backend_create(display); - if (!backend) { - goto error_session; + return backend; } struct wlr_backend *libinput = wlr_libinput_backend_create(display, session); @@ -134,9 +135,8 @@ struct wlr_backend *wlr_backend_autocreate(struct wl_display *display) { error_multi: wlr_backend_destroy(backend); -error_session: wlr_session_destroy(session); - return NULL; + return backend; } uint32_t usec_to_msec(uint64_t usec) { From ee39dff1e7de4a234f2ff39c1ce2df6bc84abb04 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Wed, 20 Dec 2017 05:51:23 -0500 Subject: [PATCH 06/11] rootston: handle backend creation failed --- backend/multi/backend.c | 7 ++++++- include/backend/multi.h | 2 -- include/wlr/backend/multi.h | 2 ++ rootston/main.c | 7 +++++++ 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/backend/multi/backend.c b/backend/multi/backend.c index e6be4a20..c000342b 100644 --- a/backend/multi/backend.c +++ b/backend/multi/backend.c @@ -42,7 +42,6 @@ static void subbackend_state_destroy(struct subbackend_state *sub) { static void multi_backend_destroy(struct wlr_backend *wlr_backend) { struct wlr_multi_backend *backend = (struct wlr_multi_backend *)wlr_backend; - wl_list_remove(&backend->display_destroy.link); struct subbackend_state *sub, *next; wl_list_for_each_safe(sub, next, &backend->backends, link) { // XXX do we really want to take ownership over added backends? @@ -190,3 +189,9 @@ struct wlr_session *wlr_multi_get_session(struct wlr_backend *_backend) { } return NULL; } + +bool wlr_multi_is_empty(struct wlr_backend *_backend) { + assert(wlr_backend_is_multi(_backend)); + struct wlr_multi_backend *backend = (struct wlr_multi_backend *)_backend; + return wl_list_length(&backend->backends) < 1; +} diff --git a/include/backend/multi.h b/include/backend/multi.h index f0e50fc0..e283139c 100644 --- a/include/backend/multi.h +++ b/include/backend/multi.h @@ -10,8 +10,6 @@ struct wlr_multi_backend { struct wlr_backend backend; struct wl_list backends; - - struct wl_listener display_destroy; }; #endif diff --git a/include/wlr/backend/multi.h b/include/wlr/backend/multi.h index 35f7c165..d9914efc 100644 --- a/include/wlr/backend/multi.h +++ b/include/wlr/backend/multi.h @@ -16,4 +16,6 @@ bool wlr_backend_is_multi(struct wlr_backend *backend); struct wlr_session *wlr_multi_get_session(struct wlr_backend *base); +bool wlr_multi_is_empty(struct wlr_backend *backend); + #endif diff --git a/rootston/main.c b/rootston/main.c index aa20dbba..2f913272 100644 --- a/rootston/main.c +++ b/rootston/main.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -32,6 +33,12 @@ int main(int argc, char **argv) { assert(server.backend = wlr_backend_autocreate(server.wl_display)); + if (wlr_multi_is_empty(server.backend)) { + wlr_log(L_ERROR, "could not start backend"); + wlr_backend_destroy(server.backend); + return 1; + } + assert(server.renderer = wlr_gles2_renderer_create(server.backend)); server.data_device_manager = wlr_data_device_manager_create(server.wl_display); From 6c8fd6017e92441e8b1702958f34fd9d88e32928 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Wed, 20 Dec 2017 05:54:41 -0500 Subject: [PATCH 07/11] backend add and remove events --- backend/multi/backend.c | 6 ++++++ include/backend/multi.h | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/backend/multi/backend.c b/backend/multi/backend.c index c000342b..0dd3c54b 100644 --- a/backend/multi/backend.c +++ b/backend/multi/backend.c @@ -79,6 +79,9 @@ struct wlr_backend *wlr_multi_backend_create(struct wl_display *display) { wl_list_init(&backend->backends); wlr_backend_init(&backend->backend, &backend_impl); + wl_signal_init(&backend->events.backend_add); + wl_signal_init(&backend->events.backend_remove); + return &backend->backend; } @@ -162,6 +165,8 @@ void wlr_multi_backend_add(struct wlr_backend *_multi, wl_signal_add(&backend->events.output_remove, &sub->output_remove); sub->output_remove.notify = output_remove_reemit; + + wl_signal_emit(&multi->events.backend_add, backend); } void wlr_multi_backend_remove(struct wlr_backend *_multi, @@ -173,6 +178,7 @@ void wlr_multi_backend_remove(struct wlr_backend *_multi, multi_backend_get_subbackend(multi, backend); if (sub) { + wl_signal_emit(&multi->events.backend_remove, backend); subbackend_state_destroy(sub); } } diff --git a/include/backend/multi.h b/include/backend/multi.h index e283139c..947464e1 100644 --- a/include/backend/multi.h +++ b/include/backend/multi.h @@ -10,6 +10,11 @@ struct wlr_multi_backend { struct wlr_backend backend; struct wl_list backends; + + struct { + struct wl_signal backend_add; + struct wl_signal backend_remove; + } events; }; #endif From d1dce19253d0b4d30d99d2074a05fe7970391a61 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Thu, 21 Dec 2017 08:13:36 -0500 Subject: [PATCH 08/11] handle display destroy --- backend/multi/backend.c | 10 +++++++++- include/backend/multi.h | 2 ++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/backend/multi/backend.c b/backend/multi/backend.c index 0dd3c54b..07e84c01 100644 --- a/backend/multi/backend.c +++ b/backend/multi/backend.c @@ -44,7 +44,6 @@ static void multi_backend_destroy(struct wlr_backend *wlr_backend) { struct wlr_multi_backend *backend = (struct wlr_multi_backend *)wlr_backend; struct subbackend_state *sub, *next; wl_list_for_each_safe(sub, next, &backend->backends, link) { - // XXX do we really want to take ownership over added backends? wlr_backend_destroy(sub->backend); } free(backend); @@ -68,6 +67,12 @@ struct wlr_backend_impl backend_impl = { .get_egl = multi_backend_get_egl, }; +static void handle_display_destroy(struct wl_listener *listener, void *data) { + struct wlr_multi_backend *backend = + wl_container_of(listener, backend, display_destroy); + multi_backend_destroy((struct wlr_backend*)backend); +} + struct wlr_backend *wlr_multi_backend_create(struct wl_display *display) { struct wlr_multi_backend *backend = calloc(1, sizeof(struct wlr_multi_backend)); @@ -82,6 +87,9 @@ struct wlr_backend *wlr_multi_backend_create(struct wl_display *display) { wl_signal_init(&backend->events.backend_add); wl_signal_init(&backend->events.backend_remove); + backend->display_destroy.notify = handle_display_destroy; + wl_display_add_destroy_listener(display, &backend->display_destroy); + return &backend->backend; } diff --git a/include/backend/multi.h b/include/backend/multi.h index 947464e1..3363c608 100644 --- a/include/backend/multi.h +++ b/include/backend/multi.h @@ -11,6 +11,8 @@ struct wlr_multi_backend { struct wl_list backends; + struct wl_listener display_destroy; + struct { struct wl_signal backend_add; struct wl_signal backend_remove; From b4159c52d5ee8bbcfdee291b19b503f9af7b24cd Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Thu, 21 Dec 2017 08:33:34 -0500 Subject: [PATCH 09/11] autocreate backend returns null instead of empty --- backend/backend.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/backend/backend.c b/backend/backend.c index 2adc3171..359ee0e5 100644 --- a/backend/backend.c +++ b/backend/backend.c @@ -96,16 +96,14 @@ struct wlr_backend *wlr_backend_autocreate(struct wl_display *display) { struct wlr_session *session = wlr_session_create(display); if (!session) { wlr_log(L_ERROR, "Failed to start a DRM session"); - return backend; + goto out; } struct wlr_backend *libinput = wlr_libinput_backend_create(display, session); - if (!libinput) { - goto error_multi; + if (libinput) { + wlr_multi_backend_add(backend, libinput); } - wlr_multi_backend_add(backend, libinput); - int gpus[8]; size_t num_gpus = wlr_session_find_gpus(session, 8, gpus); struct wlr_backend *primary_drm = NULL; @@ -128,14 +126,14 @@ struct wlr_backend *wlr_backend_autocreate(struct wl_display *display) { if (!primary_drm) { wlr_log(L_ERROR, "Failed to open any DRM device"); - goto error_multi; } - return backend; +out: + if (wlr_multi_is_empty(backend)) { + wlr_backend_destroy(backend); + return NULL; + } -error_multi: - wlr_backend_destroy(backend); - wlr_session_destroy(session); return backend; } From 9871cde60433699468e2bd30b60382904173ba55 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Thu, 21 Dec 2017 18:27:38 -0500 Subject: [PATCH 10/11] rootston: server backend check --- rootston/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rootston/main.c b/rootston/main.c index 2f913272..161824d6 100644 --- a/rootston/main.c +++ b/rootston/main.c @@ -31,9 +31,9 @@ int main(int argc, char **argv) { assert(server.wl_display = wl_display_create()); assert(server.wl_event_loop = wl_display_get_event_loop(server.wl_display)); - assert(server.backend = wlr_backend_autocreate(server.wl_display)); + server.backend = wlr_backend_autocreate(server.wl_display); - if (wlr_multi_is_empty(server.backend)) { + if (server.backend == NULL) { wlr_log(L_ERROR, "could not start backend"); wlr_backend_destroy(server.backend); return 1; From 4cec7f54e24a58fd9756395ce64a5bd73f412c9e Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Thu, 21 Dec 2017 18:38:58 -0500 Subject: [PATCH 11/11] only add first backend to multi autocreate --- backend/backend.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/backend/backend.c b/backend/backend.c index 359ee0e5..6b32bc6a 100644 --- a/backend/backend.c +++ b/backend/backend.c @@ -33,6 +33,10 @@ bool wlr_backend_start(struct wlr_backend *backend) { } void wlr_backend_destroy(struct wlr_backend *backend) { + if (!backend) { + return; + } + wl_signal_emit(&backend->events.destroy, backend); if (backend->impl && backend->impl->destroy) { backend->impl->destroy(backend); @@ -82,6 +86,7 @@ struct wlr_backend *wlr_backend_autocreate(struct wl_display *display) { struct wlr_backend *wl_backend = attempt_wl_backend(display); if (wl_backend) { wlr_multi_backend_add(backend, wl_backend); + return backend; } } @@ -90,18 +95,25 @@ struct wlr_backend *wlr_backend_autocreate(struct wl_display *display) { struct wlr_backend *x11_backend = wlr_x11_backend_create(display, x11_display); wlr_multi_backend_add(backend, x11_backend); + return backend; } // Attempt DRM+libinput struct wlr_session *session = wlr_session_create(display); if (!session) { wlr_log(L_ERROR, "Failed to start a DRM session"); - goto out; + wlr_backend_destroy(backend); + return NULL; } struct wlr_backend *libinput = wlr_libinput_backend_create(display, session); if (libinput) { wlr_multi_backend_add(backend, libinput); + } else { + wlr_log(L_ERROR, "Failed to start libinput backend"); + wlr_backend_destroy(backend); + wlr_session_destroy(session); + return NULL; } int gpus[8]; @@ -126,10 +138,8 @@ struct wlr_backend *wlr_backend_autocreate(struct wl_display *display) { if (!primary_drm) { wlr_log(L_ERROR, "Failed to open any DRM device"); - } - -out: - if (wlr_multi_is_empty(backend)) { + wlr_backend_destroy(libinput); + wlr_session_destroy(session); wlr_backend_destroy(backend); return NULL; }