diff options
Diffstat (limited to 'backend/backend.c')
-rw-r--r-- | backend/backend.c | 49 |
1 files changed, 33 insertions, 16 deletions
diff --git a/backend/backend.c b/backend/backend.c index 78b90007..c5dcdb48 100644 --- a/backend/backend.c +++ b/backend/backend.c @@ -15,6 +15,7 @@ #include <wlr/backend/wayland.h> #include <wlr/config.h> #include <wlr/util/log.h> +#include "backend/multi.h" /* WLR_HAS_X11_BACKEND needs to be after wlr/config.h */ #ifdef WLR_HAS_X11_BACKEND @@ -56,6 +57,20 @@ struct wlr_renderer *wlr_backend_get_renderer(struct wlr_backend *backend) { return NULL; } +struct wlr_session *wlr_backend_get_session(struct wlr_backend *backend) { + if (backend->impl->get_session) { + return backend->impl->get_session(backend); + } + return NULL; +} + +clockid_t wlr_backend_get_presentation_clock(struct wlr_backend *backend) { + if (backend->impl->get_presentation_clock) { + return backend->impl->get_presentation_clock(backend); + } + return CLOCK_MONOTONIC; +} + static size_t parse_outputs_env(const char *name) { const char *outputs_str = getenv(name); if (outputs_str == NULL) { @@ -158,10 +173,12 @@ static struct wlr_backend *attempt_backend_by_name(struct wl_display *display, return attempt_headless_backend(display, create_renderer_func); } 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(WLR_ERROR, "failed to start a session"); - return NULL; + *session = wlr_session_create(display); + if (!*session) { + wlr_log(WLR_ERROR, "failed to start a session"); + return NULL; + } } if (strcmp(name, "libinput") == 0) { @@ -178,13 +195,12 @@ static struct wlr_backend *attempt_backend_by_name(struct wl_display *display, struct wlr_backend *wlr_backend_autocreate(struct wl_display *display, wlr_renderer_create_func_t create_renderer_func) { struct wlr_backend *backend = wlr_multi_backend_create(display); + struct wlr_multi_backend *multi = (struct wlr_multi_backend *)backend; if (!backend) { wlr_log(WLR_ERROR, "could not allocate multibackend"); return NULL; } - struct wlr_session *session = NULL; - char *names = getenv("WLR_BACKENDS"); if (names) { names = strdup(names); @@ -197,20 +213,20 @@ struct wlr_backend *wlr_backend_autocreate(struct wl_display *display, char *saveptr; char *name = strtok_r(names, ",", &saveptr); while (name != NULL) { - struct wlr_backend *subbackend = - attempt_backend_by_name(display, backend, &session, name, create_renderer_func); + struct wlr_backend *subbackend = attempt_backend_by_name(display, + backend, &multi->session, name, create_renderer_func); if (subbackend == NULL) { wlr_log(WLR_ERROR, "failed to start backend '%s'", name); + wlr_session_destroy(multi->session); wlr_backend_destroy(backend); - wlr_session_destroy(session); free(names); return NULL; } if (!wlr_multi_backend_add(backend, subbackend)) { wlr_log(WLR_ERROR, "failed to add backend '%s'", name); + wlr_session_destroy(multi->session); wlr_backend_destroy(backend); - wlr_session_destroy(session); free(names); return NULL; } @@ -245,29 +261,30 @@ struct wlr_backend *wlr_backend_autocreate(struct wl_display *display, #endif // Attempt DRM+libinput - session = wlr_session_create(display); - if (!session) { + multi->session = wlr_session_create(display); + if (!multi->session) { wlr_log(WLR_ERROR, "Failed to start a DRM session"); wlr_backend_destroy(backend); return NULL; } - struct wlr_backend *libinput = wlr_libinput_backend_create(display, session); + struct wlr_backend *libinput = wlr_libinput_backend_create(display, + multi->session); if (!libinput) { wlr_log(WLR_ERROR, "Failed to start libinput backend"); + wlr_session_destroy(multi->session); wlr_backend_destroy(backend); - wlr_session_destroy(session); return NULL; } wlr_multi_backend_add(backend, libinput); - struct wlr_backend *primary_drm = - attempt_drm_backend(display, backend, session, create_renderer_func); + struct wlr_backend *primary_drm = attempt_drm_backend(display, backend, + multi->session, create_renderer_func); if (!primary_drm) { wlr_log(WLR_ERROR, "Failed to open any DRM device"); wlr_backend_destroy(libinput); + wlr_session_destroy(multi->session); wlr_backend_destroy(backend); - wlr_session_destroy(session); return NULL; } |