mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-11-26 06:35:58 +01:00
Merge pull request #506 from acrisci/multi-backend-fixes
[wip] multibackend fixes
This commit is contained in:
commit
0a370c5298
8 changed files with 140 additions and 39 deletions
|
@ -18,6 +18,7 @@ void wlr_backend_init(struct wlr_backend *backend,
|
||||||
const struct wlr_backend_impl *impl) {
|
const struct wlr_backend_impl *impl) {
|
||||||
assert(backend);
|
assert(backend);
|
||||||
backend->impl = impl;
|
backend->impl = impl;
|
||||||
|
wl_signal_init(&backend->events.destroy);
|
||||||
wl_signal_init(&backend->events.input_add);
|
wl_signal_init(&backend->events.input_add);
|
||||||
wl_signal_init(&backend->events.input_remove);
|
wl_signal_init(&backend->events.input_remove);
|
||||||
wl_signal_init(&backend->events.output_add);
|
wl_signal_init(&backend->events.output_add);
|
||||||
|
@ -32,6 +33,11 @@ bool wlr_backend_start(struct wlr_backend *backend) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void wlr_backend_destroy(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) {
|
if (backend->impl && backend->impl->destroy) {
|
||||||
backend->impl->destroy(backend);
|
backend->impl->destroy(backend);
|
||||||
} else {
|
} else {
|
||||||
|
@ -70,38 +76,45 @@ static struct wlr_backend *attempt_wl_backend(struct wl_display *display) {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct wlr_backend *wlr_backend_autocreate(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")) {
|
if (getenv("WAYLAND_DISPLAY") || getenv("_WAYLAND_DISPLAY")) {
|
||||||
backend = attempt_wl_backend(display);
|
struct wlr_backend *wl_backend = attempt_wl_backend(display);
|
||||||
if (backend) {
|
if (wl_backend) {
|
||||||
|
wlr_multi_backend_add(backend, wl_backend);
|
||||||
return backend;
|
return backend;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *x11_display = getenv("DISPLAY");
|
const char *x11_display = getenv("DISPLAY");
|
||||||
if (x11_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);
|
||||||
|
return backend;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attempt DRM+libinput
|
// Attempt DRM+libinput
|
||||||
|
|
||||||
struct wlr_session *session = wlr_session_create(display);
|
struct wlr_session *session = wlr_session_create(display);
|
||||||
if (!session) {
|
if (!session) {
|
||||||
wlr_log(L_ERROR, "Failed to start a DRM session");
|
wlr_log(L_ERROR, "Failed to start a DRM session");
|
||||||
|
wlr_backend_destroy(backend);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
backend = wlr_multi_backend_create(display, session);
|
|
||||||
if (!backend) {
|
|
||||||
goto error_session;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct wlr_backend *libinput = wlr_libinput_backend_create(display, session);
|
struct wlr_backend *libinput = wlr_libinput_backend_create(display, session);
|
||||||
if (!libinput) {
|
if (libinput) {
|
||||||
goto error_multi;
|
|
||||||
}
|
|
||||||
|
|
||||||
wlr_multi_backend_add(backend, 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];
|
int gpus[8];
|
||||||
size_t num_gpus = wlr_session_find_gpus(session, 8, gpus);
|
size_t num_gpus = wlr_session_find_gpus(session, 8, gpus);
|
||||||
|
@ -125,16 +138,13 @@ struct wlr_backend *wlr_backend_autocreate(struct wl_display *display) {
|
||||||
|
|
||||||
if (!primary_drm) {
|
if (!primary_drm) {
|
||||||
wlr_log(L_ERROR, "Failed to open any DRM device");
|
wlr_log(L_ERROR, "Failed to open any DRM device");
|
||||||
goto error_multi;
|
wlr_backend_destroy(libinput);
|
||||||
|
wlr_session_destroy(session);
|
||||||
|
wlr_backend_destroy(backend);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return backend;
|
return backend;
|
||||||
|
|
||||||
error_multi:
|
|
||||||
wlr_backend_destroy(backend);
|
|
||||||
error_session:
|
|
||||||
wlr_session_destroy(session);
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t usec_to_msec(uint64_t usec) {
|
uint32_t usec_to_msec(uint64_t usec) {
|
||||||
|
|
|
@ -174,3 +174,8 @@ error_fd:
|
||||||
free(drm);
|
free(drm);
|
||||||
return NULL;
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include <wlr/backend/session.h>
|
#include <wlr/backend/session.h>
|
||||||
#include <wlr/util/log.h>
|
#include <wlr/util/log.h>
|
||||||
#include "backend/multi.h"
|
#include "backend/multi.h"
|
||||||
|
#include "backend/drm/drm.h"
|
||||||
|
|
||||||
struct subbackend_state {
|
struct subbackend_state {
|
||||||
struct wlr_backend *backend;
|
struct wlr_backend *backend;
|
||||||
|
@ -13,6 +14,7 @@ struct subbackend_state {
|
||||||
struct wl_listener input_remove;
|
struct wl_listener input_remove;
|
||||||
struct wl_listener output_add;
|
struct wl_listener output_add;
|
||||||
struct wl_listener output_remove;
|
struct wl_listener output_remove;
|
||||||
|
struct wl_listener backend_destroy;
|
||||||
struct wl_list link;
|
struct wl_list link;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -28,13 +30,21 @@ static bool multi_backend_start(struct wlr_backend *wlr_backend) {
|
||||||
return true;
|
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) {
|
static void multi_backend_destroy(struct wlr_backend *wlr_backend) {
|
||||||
struct wlr_multi_backend *backend = (struct wlr_multi_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;
|
struct subbackend_state *sub, *next;
|
||||||
wl_list_for_each_safe(sub, next, &backend->backends, link) {
|
wl_list_for_each_safe(sub, next, &backend->backends, link) {
|
||||||
wlr_backend_destroy(sub->backend);
|
wlr_backend_destroy(sub->backend);
|
||||||
free(sub);
|
|
||||||
}
|
}
|
||||||
free(backend);
|
free(backend);
|
||||||
}
|
}
|
||||||
|
@ -60,11 +70,10 @@ struct wlr_backend_impl backend_impl = {
|
||||||
static void handle_display_destroy(struct wl_listener *listener, void *data) {
|
static void handle_display_destroy(struct wl_listener *listener, void *data) {
|
||||||
struct wlr_multi_backend *backend =
|
struct wlr_multi_backend *backend =
|
||||||
wl_container_of(listener, backend, display_destroy);
|
wl_container_of(listener, backend, display_destroy);
|
||||||
multi_backend_destroy(&backend->backend);
|
multi_backend_destroy((struct wlr_backend*)backend);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct wlr_backend *wlr_multi_backend_create(struct wl_display *display,
|
struct wlr_backend *wlr_multi_backend_create(struct wl_display *display) {
|
||||||
struct wlr_session *session) {
|
|
||||||
struct wlr_multi_backend *backend =
|
struct wlr_multi_backend *backend =
|
||||||
calloc(1, sizeof(struct wlr_multi_backend));
|
calloc(1, sizeof(struct wlr_multi_backend));
|
||||||
if (!backend) {
|
if (!backend) {
|
||||||
|
@ -72,12 +81,14 @@ struct wlr_backend *wlr_multi_backend_create(struct wl_display *display,
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
backend->session = session;
|
|
||||||
wl_list_init(&backend->backends);
|
wl_list_init(&backend->backends);
|
||||||
wlr_backend_init(&backend->backend, &backend_impl);
|
wlr_backend_init(&backend->backend, &backend_impl);
|
||||||
|
|
||||||
session->display_destroy.notify = handle_display_destroy;
|
wl_signal_init(&backend->events.backend_add);
|
||||||
wl_display_add_destroy_listener(display, &session->display_destroy);
|
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;
|
return &backend->backend;
|
||||||
}
|
}
|
||||||
|
@ -110,11 +121,34 @@ static void output_remove_reemit(struct wl_listener *listener, void *data) {
|
||||||
wl_signal_emit(&state->container->events.output_remove, 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
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,
|
void wlr_multi_backend_add(struct wlr_backend *_multi,
|
||||||
struct wlr_backend *backend) {
|
struct wlr_backend *backend) {
|
||||||
assert(wlr_backend_is_multi(_multi));
|
assert(wlr_backend_is_multi(_multi));
|
||||||
|
|
||||||
struct wlr_multi_backend *multi = (struct wlr_multi_backend *)_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;
|
struct subbackend_state *sub;
|
||||||
if (!(sub = calloc(1, sizeof(struct subbackend_state)))) {
|
if (!(sub = calloc(1, sizeof(struct subbackend_state)))) {
|
||||||
wlr_log(L_ERROR, "Could not add backend: allocation failed");
|
wlr_log(L_ERROR, "Could not add backend: allocation failed");
|
||||||
|
@ -125,20 +159,53 @@ void wlr_multi_backend_add(struct wlr_backend *_multi,
|
||||||
sub->backend = backend;
|
sub->backend = backend;
|
||||||
sub->container = &multi->backend;
|
sub->container = &multi->backend;
|
||||||
|
|
||||||
sub->input_add.notify = input_add_reemit;
|
wl_signal_add(&backend->events.destroy, &sub->backend_destroy);
|
||||||
sub->input_remove.notify = input_remove_reemit;
|
sub->backend_destroy.notify = handle_subbackend_destroy;
|
||||||
sub->output_add.notify = output_add_reemit;
|
|
||||||
sub->output_remove.notify = output_remove_reemit;
|
|
||||||
|
|
||||||
wl_signal_add(&backend->events.input_add, &sub->input_add);
|
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);
|
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);
|
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);
|
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,
|
||||||
|
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) {
|
||||||
|
wl_signal_emit(&multi->events.backend_remove, backend);
|
||||||
|
subbackend_state_destroy(sub);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct wlr_session *wlr_multi_get_session(struct wlr_backend *_backend) {
|
struct wlr_session *wlr_multi_get_session(struct wlr_backend *_backend) {
|
||||||
assert(wlr_backend_is_multi(_backend));
|
assert(wlr_backend_is_multi(_backend));
|
||||||
|
|
||||||
struct wlr_multi_backend *backend = (struct wlr_multi_backend *)_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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
void wlr_drm_connector_start_renderer(struct wlr_drm_connector *conn);
|
||||||
|
|
||||||
|
struct wlr_session *wlr_drm_backend_get_session(struct wlr_backend *backend);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -9,10 +9,14 @@
|
||||||
struct wlr_multi_backend {
|
struct wlr_multi_backend {
|
||||||
struct wlr_backend backend;
|
struct wlr_backend backend;
|
||||||
|
|
||||||
struct wlr_session *session;
|
|
||||||
struct wl_list backends;
|
struct wl_list backends;
|
||||||
|
|
||||||
struct wl_listener display_destroy;
|
struct wl_listener display_destroy;
|
||||||
|
|
||||||
|
struct {
|
||||||
|
struct wl_signal backend_add;
|
||||||
|
struct wl_signal backend_remove;
|
||||||
|
} events;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -11,6 +11,7 @@ struct wlr_backend {
|
||||||
const struct wlr_backend_impl *impl;
|
const struct wlr_backend_impl *impl;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
|
struct wl_signal destroy;
|
||||||
struct wl_signal input_add;
|
struct wl_signal input_add;
|
||||||
struct wl_signal input_remove;
|
struct wl_signal input_remove;
|
||||||
struct wl_signal output_add;
|
struct wl_signal output_add;
|
||||||
|
|
|
@ -4,13 +4,18 @@
|
||||||
#include <wlr/backend.h>
|
#include <wlr/backend.h>
|
||||||
#include <wlr/backend/session.h>
|
#include <wlr/backend/session.h>
|
||||||
|
|
||||||
struct wlr_backend *wlr_multi_backend_create(struct wl_display *display,
|
struct wlr_backend *wlr_multi_backend_create(struct wl_display *display);
|
||||||
struct wlr_session *session);
|
|
||||||
void wlr_multi_backend_add(struct wlr_backend *multi,
|
void wlr_multi_backend_add(struct wlr_backend *multi,
|
||||||
struct wlr_backend *backend);
|
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);
|
bool wlr_backend_is_multi(struct wlr_backend *backend);
|
||||||
|
|
||||||
struct wlr_session *wlr_multi_get_session(struct wlr_backend *base);
|
struct wlr_session *wlr_multi_get_session(struct wlr_backend *base);
|
||||||
|
|
||||||
|
bool wlr_multi_is_empty(struct wlr_backend *backend);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include <wayland-server.h>
|
#include <wayland-server.h>
|
||||||
#include <wlr/backend.h>
|
#include <wlr/backend.h>
|
||||||
#include <wlr/backend/headless.h>
|
#include <wlr/backend/headless.h>
|
||||||
|
#include <wlr/backend/multi.h>
|
||||||
#include <wlr/render.h>
|
#include <wlr/render.h>
|
||||||
#include <wlr/render/gles2.h>
|
#include <wlr/render/gles2.h>
|
||||||
#include <wlr/util/log.h>
|
#include <wlr/util/log.h>
|
||||||
|
@ -30,7 +31,13 @@ int main(int argc, char **argv) {
|
||||||
assert(server.wl_display = wl_display_create());
|
assert(server.wl_display = wl_display_create());
|
||||||
assert(server.wl_event_loop = wl_display_get_event_loop(server.wl_display));
|
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 (server.backend == NULL) {
|
||||||
|
wlr_log(L_ERROR, "could not start backend");
|
||||||
|
wlr_backend_destroy(server.backend);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
assert(server.renderer = wlr_gles2_renderer_create(server.backend));
|
assert(server.renderer = wlr_gles2_renderer_create(server.backend));
|
||||||
server.data_device_manager =
|
server.data_device_manager =
|
||||||
|
|
Loading…
Reference in a new issue