From 4e804ef40f46136d4fe84603a8236adc172260f8 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Tue, 19 Dec 2017 18:14:47 -0500 Subject: add backend destroy event --- include/wlr/backend.h | 1 + 1 file changed, 1 insertion(+) (limited to 'include') 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; -- cgit v1.2.3 From a937016e38efe3d7ad71540755833242059e6902 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Tue, 19 Dec 2017 18:25:46 -0500 Subject: 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(-) (limited to 'include') 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); -- cgit v1.2.3 From 58e69c9ce177f3de4790bddd161e9d74dd2e512c Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Tue, 19 Dec 2017 18:49:00 -0500 Subject: multibackend remove subbackend --- backend/multi/backend.c | 31 ++++++++++++++++++++++++++++++- include/wlr/backend/multi.h | 3 +++ 2 files changed, 33 insertions(+), 1 deletion(-) (limited to 'include') 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); -- cgit v1.2.3 From ee39dff1e7de4a234f2ff39c1ce2df6bc84abb04 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Wed, 20 Dec 2017 05:51:23 -0500 Subject: 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(-) (limited to 'include') 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); -- cgit v1.2.3 From 6c8fd6017e92441e8b1702958f34fd9d88e32928 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Wed, 20 Dec 2017 05:54:41 -0500 Subject: backend add and remove events --- backend/multi/backend.c | 6 ++++++ include/backend/multi.h | 5 +++++ 2 files changed, 11 insertions(+) (limited to 'include') 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 -- cgit v1.2.3 From d1dce19253d0b4d30d99d2074a05fe7970391a61 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Thu, 21 Dec 2017 08:13:36 -0500 Subject: handle display destroy --- backend/multi/backend.c | 10 +++++++++- include/backend/multi.h | 2 ++ 2 files changed, 11 insertions(+), 1 deletion(-) (limited to 'include') 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; -- cgit v1.2.3