2017-08-13 23:05:57 +02:00
|
|
|
#include <assert.h>
|
2017-06-13 04:22:40 +02:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <wlr/backend/interface.h>
|
2017-07-11 08:51:19 +02:00
|
|
|
#include <wlr/backend/udev.h>
|
2017-07-11 09:18:34 +02:00
|
|
|
#include <wlr/backend/session.h>
|
2017-06-21 18:10:07 +02:00
|
|
|
#include <wlr/util/log.h>
|
2017-06-13 04:22:40 +02:00
|
|
|
#include "backend/multi.h"
|
|
|
|
|
|
|
|
struct subbackend_state {
|
|
|
|
struct wlr_backend *backend;
|
|
|
|
struct wlr_backend *container;
|
|
|
|
struct wl_listener input_add;
|
|
|
|
struct wl_listener input_remove;
|
|
|
|
struct wl_listener output_add;
|
|
|
|
struct wl_listener output_remove;
|
|
|
|
};
|
|
|
|
|
2017-08-13 15:59:14 +02:00
|
|
|
static bool multi_backend_start(struct wlr_backend *_backend) {
|
2017-08-12 17:43:36 +02:00
|
|
|
struct wlr_multi_backend *backend = (struct wlr_multi_backend *)_backend;
|
|
|
|
for (size_t i = 0; i < backend->backends->length; ++i) {
|
|
|
|
struct subbackend_state *sub = backend->backends->items[i];
|
2017-08-13 15:59:14 +02:00
|
|
|
if (!wlr_backend_start(sub->backend)) {
|
2017-06-13 04:22:40 +02:00
|
|
|
wlr_log(L_ERROR, "Failed to initialize backend %zd", i);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-08-12 17:43:36 +02:00
|
|
|
static void multi_backend_destroy(struct wlr_backend *_backend) {
|
|
|
|
struct wlr_multi_backend *backend = (struct wlr_multi_backend *)_backend;
|
|
|
|
for (size_t i = 0; i < backend->backends->length; ++i) {
|
|
|
|
struct subbackend_state *sub = backend->backends->items[i];
|
2017-06-13 04:22:40 +02:00
|
|
|
wlr_backend_destroy(sub->backend);
|
|
|
|
free(sub);
|
|
|
|
}
|
2017-08-12 17:43:36 +02:00
|
|
|
list_free(backend->backends);
|
2017-08-26 01:56:43 +02:00
|
|
|
wlr_session_destroy(backend->session);
|
2017-08-12 17:43:36 +02:00
|
|
|
wlr_udev_destroy(backend->udev);
|
|
|
|
free(backend);
|
2017-06-13 04:22:40 +02:00
|
|
|
}
|
|
|
|
|
2017-08-12 17:43:36 +02:00
|
|
|
static struct wlr_egl *multi_backend_get_egl(struct wlr_backend *_backend) {
|
|
|
|
struct wlr_multi_backend *backend = (struct wlr_multi_backend *)_backend;
|
|
|
|
for (size_t i = 0; i < backend->backends->length; ++i) {
|
|
|
|
struct subbackend_state *sub = backend->backends->items[i];
|
2017-08-11 04:15:37 +02:00
|
|
|
struct wlr_egl *egl = wlr_backend_get_egl(sub->backend);
|
|
|
|
if (egl) {
|
|
|
|
return egl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-06-13 04:22:40 +02:00
|
|
|
struct wlr_backend_impl backend_impl = {
|
2017-08-13 15:59:14 +02:00
|
|
|
.start = multi_backend_start,
|
2017-08-11 04:15:37 +02:00
|
|
|
.destroy = multi_backend_destroy,
|
|
|
|
.get_egl = multi_backend_get_egl
|
2017-06-13 04:22:40 +02:00
|
|
|
};
|
|
|
|
|
2017-07-11 08:51:19 +02:00
|
|
|
struct wlr_backend *wlr_multi_backend_create(struct wlr_session *session,
|
|
|
|
struct wlr_udev *udev) {
|
2017-08-12 17:43:36 +02:00
|
|
|
struct wlr_multi_backend *backend =
|
|
|
|
calloc(1, sizeof(struct wlr_multi_backend));
|
|
|
|
if (!backend) {
|
2017-06-13 04:22:40 +02:00
|
|
|
wlr_log(L_ERROR, "Backend allocation failed");
|
|
|
|
return NULL;
|
|
|
|
}
|
2017-07-11 08:51:19 +02:00
|
|
|
|
2017-08-12 17:43:36 +02:00
|
|
|
backend->backends = list_create();
|
|
|
|
if (!backend->backends) {
|
|
|
|
free(backend);
|
2017-06-13 04:22:40 +02:00
|
|
|
wlr_log(L_ERROR, "Backend allocation failed");
|
|
|
|
return NULL;
|
|
|
|
}
|
2017-07-11 08:51:19 +02:00
|
|
|
|
2017-08-13 15:59:14 +02:00
|
|
|
wlr_backend_init(&backend->backend, &backend_impl);
|
2017-08-12 17:43:36 +02:00
|
|
|
|
|
|
|
backend->session = session;
|
|
|
|
backend->udev = udev;
|
|
|
|
return &backend->backend;
|
2017-06-13 04:22:40 +02:00
|
|
|
}
|
|
|
|
|
2017-08-06 05:08:35 +02:00
|
|
|
bool wlr_backend_is_multi(struct wlr_backend *b) {
|
|
|
|
return b->impl == &backend_impl;
|
|
|
|
}
|
|
|
|
|
2017-06-13 04:22:40 +02:00
|
|
|
static void input_add_reemit(struct wl_listener *listener, void *data) {
|
|
|
|
struct subbackend_state *state = wl_container_of(listener,
|
|
|
|
state, input_add);
|
|
|
|
wl_signal_emit(&state->container->events.input_add, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void input_remove_reemit(struct wl_listener *listener, void *data) {
|
|
|
|
struct subbackend_state *state = wl_container_of(listener,
|
|
|
|
state, input_remove);
|
|
|
|
wl_signal_emit(&state->container->events.input_remove, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void output_add_reemit(struct wl_listener *listener, void *data) {
|
|
|
|
struct subbackend_state *state = wl_container_of(listener,
|
|
|
|
state, output_add);
|
|
|
|
wl_signal_emit(&state->container->events.output_add, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void output_remove_reemit(struct wl_listener *listener, void *data) {
|
|
|
|
struct subbackend_state *state = wl_container_of(listener,
|
|
|
|
state, output_remove);
|
|
|
|
wl_signal_emit(&state->container->events.output_remove, data);
|
|
|
|
}
|
|
|
|
|
2017-08-12 17:43:36 +02:00
|
|
|
void wlr_multi_backend_add(struct wlr_backend *_multi,
|
2017-06-13 04:22:40 +02:00
|
|
|
struct wlr_backend *backend) {
|
2017-08-14 14:58:27 +02:00
|
|
|
assert(wlr_backend_is_multi(_multi));
|
2017-08-13 23:05:57 +02:00
|
|
|
|
2017-08-12 17:43:36 +02:00
|
|
|
struct wlr_multi_backend *multi = (struct wlr_multi_backend *)_multi;
|
2017-08-15 07:56:47 +02:00
|
|
|
struct subbackend_state *sub;
|
|
|
|
if (!(sub = calloc(1, sizeof(struct subbackend_state)))) {
|
|
|
|
wlr_log(L_ERROR, "Could not add backend: allocation failed");
|
|
|
|
return;
|
|
|
|
}
|
2017-08-16 09:23:21 +02:00
|
|
|
if (list_add(multi->backends, sub) == -1) {
|
|
|
|
wlr_log(L_ERROR, "Could not add backend: allocation failed");
|
|
|
|
free(sub);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-06-13 04:22:40 +02:00
|
|
|
sub->backend = backend;
|
2017-08-12 17:43:36 +02:00
|
|
|
sub->container = &multi->backend;
|
2017-06-13 04:22:40 +02:00
|
|
|
|
|
|
|
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_list_init(&sub->input_add.link);
|
|
|
|
wl_list_init(&sub->input_remove.link);
|
|
|
|
wl_list_init(&sub->output_add.link);
|
|
|
|
wl_list_init(&sub->output_remove.link);
|
|
|
|
|
|
|
|
wl_signal_add(&backend->events.input_add, &sub->input_add);
|
|
|
|
wl_signal_add(&backend->events.input_remove, &sub->input_remove);
|
|
|
|
wl_signal_add(&backend->events.output_add, &sub->output_add);
|
|
|
|
wl_signal_add(&backend->events.output_remove, &sub->output_remove);
|
|
|
|
}
|
2017-08-06 03:37:49 +02:00
|
|
|
|
2017-08-12 17:43:36 +02:00
|
|
|
struct wlr_session *wlr_multi_get_session(struct wlr_backend *_backend) {
|
2017-08-13 23:05:57 +02:00
|
|
|
assert(wlr_backend_is_multi(_backend));
|
|
|
|
|
2017-08-12 17:43:36 +02:00
|
|
|
struct wlr_multi_backend *backend = (struct wlr_multi_backend *)_backend;
|
|
|
|
return backend->session;
|
2017-08-06 03:37:49 +02:00
|
|
|
}
|