From a1631dd9ee148ac2adfe664be44b0e463e29950a Mon Sep 17 00:00:00 2001 From: emersion Date: Tue, 15 May 2018 00:07:41 +0100 Subject: backend: add WLR_BACKEND env variable --- backend/backend.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'backend') diff --git a/backend/backend.c b/backend/backend.c index 20bf42b3..0ea42cf5 100644 --- a/backend/backend.c +++ b/backend/backend.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -101,6 +102,35 @@ static struct wlr_backend *attempt_x11_backend(struct wl_display *display, } #endif +static struct wlr_backend *attempt_headless_backend( + struct wl_display *display) { + struct wlr_backend *backend = wlr_headless_backend_create(display); + if (backend == NULL) { + return NULL; + } + + size_t outputs = parse_outputs_env("WLR_HEADLESS_OUTPUTS"); + for (size_t i = 0; i < outputs; ++i) { + wlr_headless_add_output(backend, 1280, 720); + } + + return backend; +} + +static struct wlr_backend *attempt_backend_by_name(struct wl_display *display, + const char *name) { + if (strcmp(name, "wayland") == 0) { + return attempt_wl_backend(display); +#ifdef WLR_HAS_X11_BACKEND + } else if (strcmp(name, "x11") == 0) { + return attempt_x11_backend(display, NULL); +#endif + } else if (strcmp(name, "headless") == 0) { + return attempt_headless_backend(display); + } + return NULL; +} + struct wlr_backend *wlr_backend_autocreate(struct wl_display *display) { struct wlr_backend *backend = wlr_multi_backend_create(display); if (!backend) { @@ -108,6 +138,18 @@ struct wlr_backend *wlr_backend_autocreate(struct wl_display *display) { return NULL; } + const char *name = getenv("WLR_BACKEND"); + if (name) { + struct wlr_backend *subbackend = attempt_backend_by_name(display, name); + if (subbackend) { + wlr_multi_backend_add(backend, subbackend); + return backend; + } else { + wlr_log(L_ERROR, "unrecognized backend '%s'", name); + return NULL; + } + } + if (getenv("WAYLAND_DISPLAY") || getenv("_WAYLAND_DISPLAY") || getenv("WAYLAND_SOCKET")) { struct wlr_backend *wl_backend = attempt_wl_backend(display); -- cgit v1.2.3 From 52bd8aa71671fbdcf091a8b68b4eb2bb200b624d Mon Sep 17 00:00:00 2001 From: emersion Date: Tue, 15 May 2018 22:08:08 +0100 Subject: backend/multi: disallow multiple renderers at the same time --- backend/multi/backend.c | 20 +++++++++++++++----- include/wlr/backend/multi.h | 2 +- 2 files changed, 16 insertions(+), 6 deletions(-) (limited to 'backend') diff --git a/backend/multi/backend.c b/backend/multi/backend.c index b70d7003..33dfc6c5 100644 --- a/backend/multi/backend.c +++ b/backend/multi/backend.c @@ -130,20 +130,29 @@ static struct subbackend_state *multi_backend_get_subbackend(struct wlr_multi_ba return NULL; } -void wlr_multi_backend_add(struct wlr_backend *_multi, +bool 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; + return true; } - struct subbackend_state *sub; - if (!(sub = calloc(1, sizeof(struct subbackend_state)))) { + struct wlr_renderer *multi_renderer = + multi_backend_get_renderer(&multi->backend); + struct wlr_renderer *backend_renderer = wlr_backend_get_renderer(backend); + if (multi_renderer != NULL && backend_renderer != NULL) { + wlr_log(L_ERROR, "Could not add backend: multiple renderers at the " + "same time aren't supported"); + return false; + } + + struct subbackend_state *sub = calloc(1, sizeof(struct subbackend_state)); + if (sub == NULL) { wlr_log(L_ERROR, "Could not add backend: allocation failed"); - return; + return false; } wl_list_insert(&multi->backends, &sub->link); @@ -160,6 +169,7 @@ void wlr_multi_backend_add(struct wlr_backend *_multi, sub->new_output.notify = new_output_reemit; wlr_signal_emit_safe(&multi->events.backend_add, backend); + return true; } void wlr_multi_backend_remove(struct wlr_backend *_multi, diff --git a/include/wlr/backend/multi.h b/include/wlr/backend/multi.h index 842eed67..1e04dba4 100644 --- a/include/wlr/backend/multi.h +++ b/include/wlr/backend/multi.h @@ -13,7 +13,7 @@ struct wlr_backend *wlr_multi_backend_create(struct wl_display *display); * Adds the given backend to the multi backend. This should be done before the * new backend is started. */ -void wlr_multi_backend_add(struct wlr_backend *multi, +bool wlr_multi_backend_add(struct wlr_backend *multi, struct wlr_backend *backend); void wlr_multi_backend_remove(struct wlr_backend *multi, -- cgit v1.2.3 From 007d83c6ee20ec4d39aa2d7a4ff3fb3158bc5fb3 Mon Sep 17 00:00:00 2001 From: emersion Date: Tue, 15 May 2018 22:10:51 +0100 Subject: backend: allow multiple backends in WLR_BACKENDS --- backend/backend.c | 33 +++++++++++++++++++++++++-------- docs/env_vars.md | 16 +++++++++++----- 2 files changed, 36 insertions(+), 13 deletions(-) (limited to 'backend') diff --git a/backend/backend.c b/backend/backend.c index 0ea42cf5..a66cb5f3 100644 --- a/backend/backend.c +++ b/backend/backend.c @@ -1,3 +1,4 @@ +#define _POSIX_C_SOURCE 200809L #include #include #include @@ -138,16 +139,32 @@ struct wlr_backend *wlr_backend_autocreate(struct wl_display *display) { return NULL; } - const char *name = getenv("WLR_BACKEND"); - if (name) { - struct wlr_backend *subbackend = attempt_backend_by_name(display, name); - if (subbackend) { - wlr_multi_backend_add(backend, subbackend); - return backend; - } else { - wlr_log(L_ERROR, "unrecognized backend '%s'", name); + char *names = getenv("WLR_BACKENDS"); + if (names) { + names = strdup(names); + if (names == NULL) { + wlr_log(L_ERROR, "allocation failed"); return NULL; } + + char *saveptr; + char *name = strtok_r(names, ",", &saveptr); + while (name != NULL) { + struct wlr_backend *subbackend = + attempt_backend_by_name(display, name); + if (subbackend == NULL) { + wlr_log(L_ERROR, "unrecognized backend '%s'", name); + return NULL; + } + + if (!wlr_multi_backend_add(backend, subbackend)) { + return NULL; + } + + name = strtok_r(NULL, ",", &saveptr); + } + + return backend; } if (getenv("WAYLAND_DISPLAY") || getenv("_WAYLAND_DISPLAY") || diff --git a/docs/env_vars.md b/docs/env_vars.md index db85d4c5..3f1926d3 100644 --- a/docs/env_vars.md +++ b/docs/env_vars.md @@ -2,20 +2,26 @@ wlroots reads these environment variables wlroots specific ---------------- -* *WLR_DRM_DEVICES*: specifies the DRM devices (as a colon separated list) instead of auto probing them. The first existing device in this list is considered the primary DRM device. -* *WLR_DRM_NO_ATOMIC*: set to 1 to use legacy DRM interface instead of atomic mode setting +* *WLR_DRM_DEVICES*: specifies the DRM devices (as a colon separated list) + instead of auto probing them. The first existing device in this list is + considered the primary DRM device. +* *WLR_DRM_NO_ATOMIC*: set to 1 to use legacy DRM interface instead of atomic + mode setting * *WLR_LIBINPUT_NO_DEVICES*: set to 1 to not fail without any input devices -* *WLR_BACKEND*: force a specific backend to be used (one of: wayland, x11, headless) +* *WLR_BACKENDS*: comma-separated list of backends to use (available backends: + wayland, x11, headless) * *WLR_WL_OUTPUTS*: when using the wayland backend specifies the number of outputs * *WLR_X11_OUTPUTS*: when using the X11 backend specifies the number of outputs rootston specific ------------------ -* *XKB_DEFAULT_RULES*, *XKB_DEFAULT_MODEL*, *XKB_DEFAULT_LAYOUT*, *XKB_DEFAULT_VARIANT*, *XKB_DEFAULT_OPTIONS*: xkb setup +* *XKB_DEFAULT_RULES*, *XKB_DEFAULT_MODEL*, *XKB_DEFAULT_LAYOUT*, + *XKB_DEFAULT_VARIANT*, *XKB_DEFAULT_OPTIONS*: xkb setup generic ------- * *DISPLAY*: if set probe X11 backend in *wlr_backend_autocreate* -* *WAYLAND_DISPLAY*, *_WAYLAND_DISPLAY*, *WAYLAND_SOCKET*: if set probe Wayland backend in *wlr_backend_autocreate* +* *WAYLAND_DISPLAY*, *_WAYLAND_DISPLAY*, *WAYLAND_SOCKET*: if set probe Wayland + backend in *wlr_backend_autocreate* * *XCURSOR_PATH*: directory where xcursors are located * *XDG_RUNTIME_DIR*: used to store non persistent temporary files -- cgit v1.2.3 From 75b10cd62177a40f14f8ca610b13292726bba169 Mon Sep 17 00:00:00 2001 From: emersion Date: Sat, 19 May 2018 09:32:08 +0100 Subject: backend: support creating DRM and libinput via WLR_BACKENDS --- backend/backend.c | 84 +++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 57 insertions(+), 27 deletions(-) (limited to 'backend') diff --git a/backend/backend.c b/backend/backend.c index a66cb5f3..b57fd424 100644 --- a/backend/backend.c +++ b/backend/backend.c @@ -118,7 +118,33 @@ static struct wlr_backend *attempt_headless_backend( return backend; } +static struct wlr_backend *attempt_drm_backend(struct wl_display *display, + struct wlr_backend *backend, struct wlr_session *session) { + int gpus[8]; + size_t num_gpus = wlr_session_find_gpus(session, 8, gpus); + struct wlr_backend *primary_drm = NULL; + wlr_log(L_INFO, "Found %zu GPUs", num_gpus); + + for (size_t i = 0; i < num_gpus; ++i) { + struct wlr_backend *drm = wlr_drm_backend_create(display, session, + gpus[i], primary_drm); + if (!drm) { + wlr_log(L_ERROR, "Failed to open DRM device %d", gpus[i]); + continue; + } + + if (!primary_drm) { + primary_drm = drm; + } + + wlr_multi_backend_add(backend, drm); + } + + return primary_drm; +} + static struct wlr_backend *attempt_backend_by_name(struct wl_display *display, + struct wlr_backend *backend, struct wlr_session **session, const char *name) { if (strcmp(name, "wayland") == 0) { return attempt_wl_backend(display); @@ -128,7 +154,22 @@ static struct wlr_backend *attempt_backend_by_name(struct wl_display *display, #endif } else if (strcmp(name, "headless") == 0) { return attempt_headless_backend(display); + } else if (strcmp(name, "drm") == 0 || strcmp(name, "libinput") == 0) { + // DRM and libinput need a session + *session = wlr_session_create(display); + if (!*session) { + wlr_log(L_ERROR, "failed to start a session"); + return NULL; + } + + if (strcmp(name, "libinput") == 0) { + return wlr_libinput_backend_create(display, *session); + } else { + return attempt_drm_backend(display, backend, *session); + } } + + wlr_log(L_ERROR, "unrecognized backend '%s'", name); return NULL; } @@ -139,11 +180,14 @@ struct wlr_backend *wlr_backend_autocreate(struct wl_display *display) { return NULL; } + struct wlr_session *session = NULL; + char *names = getenv("WLR_BACKENDS"); if (names) { names = strdup(names); if (names == NULL) { wlr_log(L_ERROR, "allocation failed"); + wlr_backend_destroy(backend); return NULL; } @@ -151,13 +195,18 @@ struct wlr_backend *wlr_backend_autocreate(struct wl_display *display) { char *name = strtok_r(names, ",", &saveptr); while (name != NULL) { struct wlr_backend *subbackend = - attempt_backend_by_name(display, name); + attempt_backend_by_name(display, backend, &session, name); if (subbackend == NULL) { - wlr_log(L_ERROR, "unrecognized backend '%s'", name); + wlr_log(L_ERROR, "failed to start backend '%s'", name); + wlr_backend_destroy(backend); + wlr_session_destroy(session); return NULL; } if (!wlr_multi_backend_add(backend, subbackend)) { + wlr_log(L_ERROR, "failed to add backend '%s'", name); + wlr_backend_destroy(backend); + wlr_session_destroy(session); return NULL; } @@ -189,7 +238,7 @@ struct wlr_backend *wlr_backend_autocreate(struct wl_display *display) { #endif // Attempt DRM+libinput - struct wlr_session *session = wlr_session_create(display); + session = wlr_session_create(display); if (!session) { wlr_log(L_ERROR, "Failed to start a DRM session"); wlr_backend_destroy(backend); @@ -197,40 +246,21 @@ struct wlr_backend *wlr_backend_autocreate(struct wl_display *display) { } struct wlr_backend *libinput = wlr_libinput_backend_create(display, session); - if (libinput) { - wlr_multi_backend_add(backend, libinput); - } else { + if (!libinput) { wlr_log(L_ERROR, "Failed to start libinput backend"); wlr_backend_destroy(backend); wlr_session_destroy(session); return NULL; } + 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; - wlr_log(L_INFO, "Found %zu GPUs", num_gpus); - - for (size_t i = 0; i < num_gpus; ++i) { - struct wlr_backend *drm = wlr_drm_backend_create(display, session, - gpus[i], primary_drm); - if (!drm) { - wlr_log(L_ERROR, "Failed to open DRM device"); - continue; - } - - if (!primary_drm) { - primary_drm = drm; - } - - wlr_multi_backend_add(backend, drm); - } - + struct wlr_backend *primary_drm = + attempt_drm_backend(display, backend, session); if (!primary_drm) { wlr_log(L_ERROR, "Failed to open any DRM device"); wlr_backend_destroy(libinput); - wlr_session_destroy(session); wlr_backend_destroy(backend); + wlr_session_destroy(session); return NULL; } -- cgit v1.2.3 From 9e3dd6b5600ac3304d33d053714530ac066237db Mon Sep 17 00:00:00 2001 From: emersion Date: Sat, 19 May 2018 09:34:16 +0100 Subject: backend/wayland: fix segfault when destroying backend before starting it --- backend/wayland/backend.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'backend') diff --git a/backend/wayland/backend.c b/backend/wayland/backend.c index dc50cf23..4e4ca077 100644 --- a/backend/wayland/backend.c +++ b/backend/wayland/backend.c @@ -87,7 +87,9 @@ static void backend_destroy(struct wlr_backend *wlr_backend) { free(backend->seat_name); - wl_event_source_remove(backend->remote_display_src); + if (backend->remote_display_src) { + wl_event_source_remove(backend->remote_display_src); + } wlr_renderer_destroy(backend->renderer); wlr_egl_finish(&backend->egl); if (backend->pointer) { -- cgit v1.2.3