compositor: introduce struct weston_backend

This is a preliminary change for libweston, with no functional modifications.
Separate the backends and the core weston_compositor struct, by creating
the weston_compositor in the main(), and having the various backends extend
the weston_backend struct, an instance of which is returned by the backend
entry point.
This enable us to logically separate the compositor core from the backend,
allowing the core to be extended without messing with the backends.

Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
dev
Giulio Camuffo 10 years ago committed by Pekka Paalanen
parent 5a75a41d07
commit 954f183e2f
  1. 654
      src/compositor-drm.c
  2. 165
      src/compositor-fbdev.c
  3. 107
      src/compositor-headless.c
  4. 159
      src/compositor-rdp.c
  5. 147
      src/compositor-rpi.c
  6. 371
      src/compositor-wayland.c
  7. 554
      src/compositor-x11.c
  8. 29
      src/compositor.c
  9. 16
      src/compositor.h

File diff suppressed because it is too large Load Diff

@ -50,8 +50,9 @@
#include "gl-renderer.h"
#include "presentation_timing-server-protocol.h"
struct fbdev_compositor {
struct weston_compositor base;
struct fbdev_backend {
struct weston_backend base;
struct weston_compositor *compositor;
uint32_t prev_state;
struct udev *udev;
@ -76,7 +77,7 @@ struct fbdev_screeninfo {
};
struct fbdev_output {
struct fbdev_compositor *compositor;
struct fbdev_backend *backend;
struct weston_output base;
struct weston_mode mode;
@ -110,10 +111,10 @@ to_fbdev_output(struct weston_output *base)
return container_of(base, struct fbdev_output, base);
}
static inline struct fbdev_compositor *
to_fbdev_compositor(struct weston_compositor *base)
static inline struct fbdev_backend *
to_fbdev_backend(struct weston_compositor *base)
{
return container_of(base, struct fbdev_compositor, base);
return container_of(base->backend, struct fbdev_backend, base);
}
static void
@ -182,10 +183,10 @@ static int
fbdev_output_repaint(struct weston_output *base, pixman_region32_t *damage)
{
struct fbdev_output *output = to_fbdev_output(base);
struct fbdev_compositor *fbc = output->compositor;
struct weston_compositor *ec = & fbc->base;
struct fbdev_backend *fbb = output->backend;
struct weston_compositor *ec = fbb->compositor;
if (fbc->use_pixman) {
if (fbb->use_pixman) {
fbdev_output_repaint_pixman(base,damage);
} else {
ec->renderer->repaint_output(base, damage);
@ -481,7 +482,7 @@ static void fbdev_output_destroy(struct weston_output *base);
static void fbdev_output_disable(struct weston_output *base);
static int
fbdev_output_create(struct fbdev_compositor *compositor,
fbdev_output_create(struct fbdev_backend *backend,
const char *device)
{
struct fbdev_output *output;
@ -499,7 +500,7 @@ fbdev_output_create(struct fbdev_compositor *compositor,
if (output == NULL)
return -1;
output->compositor = compositor;
output->backend = backend;
output->device = device;
/* Create the frame buffer. */
@ -508,7 +509,7 @@ fbdev_output_create(struct fbdev_compositor *compositor,
weston_log("Creating frame buffer failed.\n");
goto out_free;
}
if (compositor->use_pixman) {
if (backend->use_pixman) {
if (fbdev_frame_buffer_map(output, fb_fd) < 0) {
weston_log("Mapping frame buffer failed.\n");
goto out_free;
@ -536,7 +537,7 @@ fbdev_output_create(struct fbdev_compositor *compositor,
output->base.model = output->fb_info.id;
output->base.name = strdup("fbdev");
section = weston_config_get_section(compositor->base.config,
section = weston_config_get_section(backend->compositor->config,
"output", "name",
output->base.name);
weston_config_section_get_string(section, "transform", &s, "normal");
@ -545,7 +546,7 @@ fbdev_output_create(struct fbdev_compositor *compositor,
s, output->base.name);
free(s);
weston_output_init(&output->base, &compositor->base,
weston_output_init(&output->base, backend->compositor,
0, 0, output->fb_info.width_mm,
output->fb_info.height_mm,
config_transform,
@ -566,7 +567,7 @@ fbdev_output_create(struct fbdev_compositor *compositor,
goto out_hw_surface;
}
if (compositor->use_pixman) {
if (backend->use_pixman) {
if (pixman_renderer_output_create(&output->base) < 0)
goto out_shadow_surface;
} else {
@ -581,11 +582,11 @@ fbdev_output_create(struct fbdev_compositor *compositor,
}
loop = wl_display_get_event_loop(compositor->base.wl_display);
loop = wl_display_get_event_loop(backend->compositor->wl_display);
output->finish_frame_timer =
wl_event_loop_add_timer(loop, finish_frame_handler, output);
weston_compositor_add_output(&compositor->base, &output->base);
weston_compositor_add_output(backend->compositor, &output->base);
weston_log("fbdev output %d×%d px\n",
output->mode.width, output->mode.height);
@ -613,14 +614,14 @@ static void
fbdev_output_destroy(struct weston_output *base)
{
struct fbdev_output *output = to_fbdev_output(base);
struct fbdev_compositor *compositor = output->compositor;
struct fbdev_backend *backend = output->backend;
weston_log("Destroying fbdev output.\n");
/* Close the frame buffer. */
fbdev_output_disable(base);
if (compositor->use_pixman) {
if (backend->use_pixman) {
if (base->renderer_state != NULL)
pixman_renderer_output_destroy(base);
@ -661,7 +662,7 @@ compare_screen_info (const struct fbdev_screeninfo *a,
}
static int
fbdev_output_reenable(struct fbdev_compositor *compositor,
fbdev_output_reenable(struct fbdev_backend *backend,
struct weston_output *base)
{
struct fbdev_output *output = to_fbdev_output(base);
@ -696,13 +697,13 @@ fbdev_output_reenable(struct fbdev_compositor *compositor,
* are re-initialised. */
device = output->device;
fbdev_output_destroy(base);
fbdev_output_create(compositor, device);
fbdev_output_create(backend, device);
return 0;
}
/* Map the device if it has the same details as before. */
if (compositor->use_pixman) {
if (backend->use_pixman) {
if (fbdev_frame_buffer_map(output, fb_fd) < 0) {
weston_log("Mapping frame buffer failed.\n");
goto err;
@ -722,11 +723,11 @@ static void
fbdev_output_disable(struct weston_output *base)
{
struct fbdev_output *output = to_fbdev_output(base);
struct fbdev_compositor *compositor = output->compositor;
struct fbdev_backend *backend = output->backend;
weston_log("Disabling fbdev output.\n");
if ( ! compositor->use_pixman) return;
if ( ! backend->use_pixman) return;
if (output->hw_surface != NULL) {
pixman_image_unref(output->hw_surface);
@ -737,48 +738,49 @@ fbdev_output_disable(struct weston_output *base)
}
static void
fbdev_compositor_destroy(struct weston_compositor *base)
fbdev_backend_destroy(struct weston_compositor *base)
{
struct fbdev_compositor *compositor = to_fbdev_compositor(base);
struct fbdev_backend *backend = to_fbdev_backend(base);
udev_input_destroy(&compositor->input);
udev_input_destroy(&backend->input);
/* Destroy the output. */
weston_compositor_shutdown(&compositor->base);
weston_compositor_shutdown(base);
/* Chain up. */
weston_launcher_destroy(compositor->base.launcher);
weston_launcher_destroy(base->launcher);
free(compositor);
free(backend);
}
static void
session_notify(struct wl_listener *listener, void *data)
{
struct fbdev_compositor *compositor = data;
struct fbdev_backend *backend = data;
struct weston_compositor *compositor = backend->compositor;
struct weston_output *output;
if (compositor->base.session_active) {
if (compositor->session_active) {
weston_log("entering VT\n");
compositor->base.state = compositor->prev_state;
compositor->state = backend->prev_state;
wl_list_for_each(output, &compositor->base.output_list, link) {
fbdev_output_reenable(compositor, output);
wl_list_for_each(output, &compositor->output_list, link) {
fbdev_output_reenable(backend, output);
}
weston_compositor_damage_all(&compositor->base);
weston_compositor_damage_all(compositor);
udev_input_enable(&compositor->input);
udev_input_enable(&backend->input);
} else {
weston_log("leaving VT\n");
udev_input_disable(&compositor->input);
udev_input_disable(&backend->input);
wl_list_for_each(output, &compositor->base.output_list, link) {
wl_list_for_each(output, &compositor->output_list, link) {
fbdev_output_disable(output);
}
compositor->prev_state = compositor->base.state;
weston_compositor_offscreen(&compositor->base);
backend->prev_state = compositor->state;
weston_compositor_offscreen(compositor);
/* If we have a repaint scheduled (from the idle handler), make
* sure we cancel that so we don't try to pageflip when we're
@ -788,7 +790,7 @@ session_notify(struct wl_listener *listener, void *data)
* pending frame callbacks. */
wl_list_for_each(output,
&compositor->base.output_list, link) {
&compositor->output_list, link) {
output->repaint_needed = 0;
}
}
@ -808,61 +810,61 @@ switch_vt_binding(struct weston_seat *seat, uint32_t time, uint32_t key, void *d
weston_launcher_activate_vt(compositor->launcher, key - KEY_F1 + 1);
}
static struct weston_compositor *
fbdev_compositor_create(struct wl_display *display, int *argc, char *argv[],
struct weston_config *config,
struct fbdev_parameters *param)
static struct fbdev_backend *
fbdev_backend_create(struct weston_compositor *compositor, int *argc, char *argv[],
struct weston_config *config,
struct fbdev_parameters *param)
{
struct fbdev_compositor *compositor;
struct fbdev_backend *backend;
const char *seat_id = default_seat;
uint32_t key;
weston_log("initializing fbdev backend\n");
compositor = zalloc(sizeof *compositor);
if (compositor == NULL)
backend = zalloc(sizeof *backend);
if (backend == NULL)
return NULL;
if (weston_compositor_init(&compositor->base, display, argc, argv,
backend->compositor = compositor;
if (weston_compositor_init(compositor, argc, argv,
config) < 0)
goto out_free;
if (weston_compositor_set_presentation_clock_software(
&compositor->base) < 0)
compositor) < 0)
goto out_compositor;
compositor->udev = udev_new();
if (compositor->udev == NULL) {
backend->udev = udev_new();
if (backend->udev == NULL) {
weston_log("Failed to initialize udev context.\n");
goto out_compositor;
}
/* Set up the TTY. */
compositor->session_listener.notify = session_notify;
wl_signal_add(&compositor->base.session_signal,
&compositor->session_listener);
compositor->base.launcher = weston_launcher_connect(&compositor->base,
param->tty, "seat0",
false);
if (!compositor->base.launcher) {
backend->session_listener.notify = session_notify;
wl_signal_add(&compositor->session_signal,
&backend->session_listener);
compositor->launcher =
weston_launcher_connect(compositor, param->tty, "seat0", false);
if (!compositor->launcher) {
weston_log("fatal: fbdev backend should be run "
"using weston-launch binary or as root\n");
goto out_udev;
}
compositor->base.destroy = fbdev_compositor_destroy;
compositor->base.restore = fbdev_restore;
backend->base.destroy = fbdev_backend_destroy;
backend->base.restore = fbdev_restore;
compositor->prev_state = WESTON_COMPOSITOR_ACTIVE;
compositor->use_pixman = !param->use_gl;
backend->prev_state = WESTON_COMPOSITOR_ACTIVE;
backend->use_pixman = !param->use_gl;
for (key = KEY_F1; key < KEY_F9; key++)
weston_compositor_add_key_binding(&compositor->base, key,
weston_compositor_add_key_binding(compositor, key,
MODIFIER_CTRL | MODIFIER_ALT,
switch_vt_binding,
compositor);
if (compositor->use_pixman) {
if (pixman_renderer_init(&compositor->base) < 0)
if (backend->use_pixman) {
if (pixman_renderer_init(compositor) < 0)
goto out_launcher;
} else {
gl_renderer = weston_load_module("gl-renderer.so",
@ -872,7 +874,7 @@ fbdev_compositor_create(struct wl_display *display, int *argc, char *argv[],
goto out_launcher;
}
if (gl_renderer->create(&compositor->base, NO_EGL_PLATFORM,
if (gl_renderer->create(compositor, NO_EGL_PLATFORM,
EGL_DEFAULT_DISPLAY,
gl_renderer->opaque_attribs,
NULL, 0) < 0) {
@ -881,35 +883,37 @@ fbdev_compositor_create(struct wl_display *display, int *argc, char *argv[],
}
}
if (fbdev_output_create(compositor, param->device) < 0)
if (fbdev_output_create(backend, param->device) < 0)
goto out_pixman;
udev_input_init(&compositor->input, &compositor->base, compositor->udev, seat_id);
udev_input_init(&backend->input, compositor, backend->udev, seat_id);
return &compositor->base;
compositor->backend = &backend->base;
return backend;
out_pixman:
compositor->base.renderer->destroy(&compositor->base);
compositor->renderer->destroy(compositor);
out_launcher:
weston_launcher_destroy(compositor->base.launcher);
weston_launcher_destroy(compositor->launcher);
out_udev:
udev_unref(compositor->udev);
udev_unref(backend->udev);
out_compositor:
weston_compositor_shutdown(&compositor->base);
weston_compositor_shutdown(compositor);
out_free:
free(compositor);
free(backend);
return NULL;
}
WL_EXPORT struct weston_compositor *
backend_init(struct wl_display *display, int *argc, char *argv[],
WL_EXPORT int
backend_init(struct weston_compositor *compositor, int *argc, char *argv[],
struct weston_config *config)
{
struct fbdev_backend *b;
/* TODO: Ideally, available frame buffers should be enumerated using
* udev, rather than passing a device node in as a parameter. */
struct fbdev_parameters param = {
@ -926,5 +930,8 @@ backend_init(struct wl_display *display, int *argc, char *argv[],
parse_options(fbdev_options, ARRAY_LENGTH(fbdev_options), argc, argv);
return fbdev_compositor_create(display, argc, argv, config, &param);
b = fbdev_backend_create(compositor, argc, argv, config, &param);
if (b == NULL)
return -1;
return 0;
}

@ -36,8 +36,9 @@
#include "pixman-renderer.h"
#include "presentation_timing-server-protocol.h"
struct headless_compositor {
struct weston_compositor base;
struct headless_backend {
struct weston_backend base;
struct weston_compositor *compositor;
struct weston_seat fake_seat;
bool use_pixman;
};
@ -99,12 +100,12 @@ static void
headless_output_destroy(struct weston_output *output_base)
{
struct headless_output *output = (struct headless_output *) output_base;
struct headless_compositor *c =
(struct headless_compositor *) output->base.compositor;
struct headless_backend *b =
(struct headless_backend *) output->base.compositor->backend;
wl_event_source_remove(output->finish_frame_timer);
if (c->use_pixman) {
if (b->use_pixman) {
pixman_renderer_output_destroy(&output->base);
pixman_image_unref(output->image);
free(output->image_buf);
@ -118,9 +119,10 @@ headless_output_destroy(struct weston_output *output_base)
}
static int
headless_compositor_create_output(struct headless_compositor *c,
struct headless_parameters *param)
headless_backend_create_output(struct headless_backend *b,
struct headless_parameters *param)
{
struct weston_compositor *c = b->compositor;
struct headless_output *output;
struct wl_event_loop *loop;
@ -137,13 +139,13 @@ headless_compositor_create_output(struct headless_compositor *c,
wl_list_insert(&output->base.mode_list, &output->mode.link);
output->base.current_mode = &output->mode;
weston_output_init(&output->base, &c->base, 0, 0, param->width,
weston_output_init(&output->base, c, 0, 0, param->width,
param->height, param->transform, 1);
output->base.make = "weston";
output->base.model = "headless";
loop = wl_display_get_event_loop(c->base.wl_display);
loop = wl_display_get_event_loop(c->wl_display);
output->finish_frame_timer =
wl_event_loop_add_timer(loop, finish_frame_handler, output);
@ -155,7 +157,7 @@ headless_compositor_create_output(struct headless_compositor *c,
output->base.set_dpms = NULL;
output->base.switch_mode = NULL;
if (c->use_pixman) {
if (b->use_pixman) {
output->image_buf = malloc(param->width * param->height * 4);
if (!output->image_buf)
return -1;
@ -173,28 +175,28 @@ headless_compositor_create_output(struct headless_compositor *c,
output->image);
}
weston_compositor_add_output(&c->base, &output->base);
weston_compositor_add_output(c, &output->base);
return 0;
}
static int
headless_input_create(struct headless_compositor *c)
headless_input_create(struct headless_backend *b)
{
weston_seat_init(&c->fake_seat, &c->base, "default");
weston_seat_init(&b->fake_seat, b->compositor, "default");
weston_seat_init_pointer(&c->fake_seat);
weston_seat_init_pointer(&b->fake_seat);
if (weston_seat_init_keyboard(&c->fake_seat, NULL) < 0)
if (weston_seat_init_keyboard(&b->fake_seat, NULL) < 0)
return -1;
return 0;
}
static void
headless_input_destroy(struct headless_compositor *c)
headless_input_destroy(struct headless_backend *b)
{
weston_seat_release(&c->fake_seat);
weston_seat_release(&b->fake_seat);
}
static void
@ -205,68 +207,70 @@ headless_restore(struct weston_compositor *ec)
static void
headless_destroy(struct weston_compositor *ec)
{
struct headless_compositor *c = (struct headless_compositor *) ec;
struct headless_backend *b = (struct headless_backend *) ec->backend;
headless_input_destroy(c);
headless_input_destroy(b);
weston_compositor_shutdown(ec);
free(ec);
free(b);
}
static struct weston_compositor *
headless_compositor_create(struct wl_display *display,
struct headless_parameters *param,
const char *display_name,
int *argc, char *argv[],
struct weston_config *config)
static struct headless_backend *
headless_backend_create(struct weston_compositor *compositor,
struct headless_parameters *param,
const char *display_name, int *argc, char *argv[],
struct weston_config *config)
{
struct headless_compositor *c;
struct headless_backend *b;
c = zalloc(sizeof *c);
if (c == NULL)
b = zalloc(sizeof *b);
if (b == NULL)
return NULL;
if (weston_compositor_init(&c->base, display, argc, argv, config) < 0)
b->compositor = compositor;
if (weston_compositor_init(compositor, argc, argv, config) < 0)
goto err_free;
if (weston_compositor_set_presentation_clock_software(&c->base) < 0)
goto err_compositor;
if (weston_compositor_set_presentation_clock_software(compositor) < 0)
goto err_free;
if (headless_input_create(c) < 0)
goto err_compositor;
if (headless_input_create(b) < 0)
goto err_free;
c->base.destroy = headless_destroy;
c->base.restore = headless_restore;
b->base.destroy = headless_destroy;
b->base.restore = headless_restore;
c->use_pixman = param->use_pixman;
if (c->use_pixman) {
pixman_renderer_init(&c->base);
b->use_pixman = param->use_pixman;
if (b->use_pixman) {
pixman_renderer_init(compositor);
}
if (headless_compositor_create_output(c, param) < 0)
if (headless_backend_create_output(b, param) < 0)
goto err_input;
if (!c->use_pixman && noop_renderer_init(&c->base) < 0)
if (!b->use_pixman && noop_renderer_init(compositor) < 0)
goto err_input;
return &c->base;
compositor->backend = &b->base;
return b;
err_input:
headless_input_destroy(c);
err_compositor:
weston_compositor_shutdown(&c->base);
weston_compositor_shutdown(compositor);
headless_input_destroy(b);
err_free:
free(c);
free(b);
return NULL;
}
WL_EXPORT struct weston_compositor *
backend_init(struct wl_display *display, int *argc, char *argv[],
WL_EXPORT int
backend_init(struct weston_compositor *compositor,
int *argc, char *argv[],
struct weston_config *config)
{
int width = 1024, height = 640;
char *display_name = NULL;
struct headless_parameters param = { 0, };
const char *transform = "normal";
struct headless_backend *b;
const struct weston_option headless_options[] = {
{ WESTON_OPTION_INTEGER, "width", 0, &width },
@ -284,6 +288,9 @@ backend_init(struct wl_display *display, int *argc, char *argv[],
if (weston_parse_transform(transform, &param.transform) < 0)
weston_log("Invalid transform \"%s\"\n", transform);
return headless_compositor_create(display, &param, display_name,
argc, argv, config);
b = headless_backend_create(compositor, &param, display_name,
argc, argv, config);
if (b == NULL)
return -1;
return 0;
}

@ -73,7 +73,7 @@
#define DEFAULT_AXIS_STEP_DISTANCE wl_fixed_from_int(10)
#define RDP_MODE_FREQ 60 * 1000
struct rdp_compositor_config {
struct rdp_backend_config {
int width;
int height;
char *bind_address;
@ -87,8 +87,9 @@ struct rdp_compositor_config {
struct rdp_output;
struct rdp_compositor {
struct weston_compositor base;
struct rdp_backend {
struct weston_backend base;
struct weston_compositor *compositor;
freerdp_listener *listener;
struct wl_event_source *listener_events[MAX_FREERDP_FDS];
@ -125,7 +126,7 @@ struct rdp_output {
struct rdp_peer_context {
rdpContext _p;
struct rdp_compositor *rdpCompositor;
struct rdp_backend *rdpBackend;
struct wl_event_source *events[MAX_FREERDP_FDS];
RFX_CONTEXT *rfx_context;
wStream *encode_stream;
@ -137,7 +138,7 @@ struct rdp_peer_context {
typedef struct rdp_peer_context RdpPeerContext;
static void
rdp_compositor_config_init(struct rdp_compositor_config *config) {
rdp_backend_config_init(struct rdp_backend_config *config) {
config->width = 640;
config->height = 480;
config->bind_address = NULL;
@ -323,7 +324,7 @@ static void
rdp_peer_refresh_region(pixman_region32_t *region, freerdp_peer *peer)
{
RdpPeerContext *context = (RdpPeerContext *)peer->context;
struct rdp_output *output = context->rdpCompositor->output;
struct rdp_output *output = context->rdpBackend->output;
rdpSettings *settings = peer->settings;
if (settings->RemoteFxCodec)
@ -467,7 +468,7 @@ rdp_switch_mode(struct weston_output *output, struct weston_mode *target_mode) {
}
static int
rdp_compositor_create_output(struct rdp_compositor *c, int width, int height)
rdp_backend_create_output(struct rdp_backend *b, int width, int height)
{
struct rdp_output *output;
struct wl_event_loop *loop;
@ -491,7 +492,7 @@ rdp_compositor_create_output(struct rdp_compositor *c, int width, int height)
goto out_free_output;
output->base.current_mode = output->base.native_mode = currentMode;
weston_output_init(&output->base, &c->base, 0, 0, width, height,
weston_output_init(&output->base, b->compositor, 0, 0, width, height,
WL_OUTPUT_TRANSFORM_NORMAL, 1);
output->base.make = "weston";
@ -508,7 +509,7 @@ rdp_compositor_create_output(struct rdp_compositor *c, int width, int height)
if (pixman_renderer_output_create(&output->base) < 0)
goto out_shadow_surface;
loop = wl_display_get_event_loop(c->base.wl_display);
loop = wl_display_get_event_loop(b->compositor->wl_display);
output->finish_frame_timer = wl_event_loop_add_timer(loop, finish_frame_handler, output);
output->base.start_repaint_loop = rdp_output_start_repaint_loop;
@ -518,9 +519,9 @@ rdp_compositor_create_output(struct rdp_compositor *c, int width, int height)
output->base.set_backlight = NULL;
output->base.set_dpms = NULL;
output->base.switch_mode = rdp_switch_mode;
c->output = output;
b->output = output;
weston_compositor_add_output(&c->base, &output->base);
weston_compositor_add_output(b->compositor, &output->base);
return 0;
out_shadow_surface:
@ -560,7 +561,7 @@ int rdp_listener_activity(int fd, uint32_t mask, void *data) {
}
static
int rdp_implant_listener(struct rdp_compositor *c, freerdp_listener* instance) {
int rdp_implant_listener(struct rdp_backend *b, freerdp_listener* instance) {
int i, fd;
int rcount = 0;
void* rfds[MAX_FREERDP_FDS];
@ -571,15 +572,15 @@ int rdp_implant_listener(struct rdp_compositor *c, freerdp_listener* instance) {
return -1;
}
loop = wl_display_get_event_loop(c->base.wl_display);
loop = wl_display_get_event_loop(b->compositor->wl_display);
for (i = 0; i < rcount; i++) {
fd = (int)(long)(rfds[i]);
c->listener_events[i] = wl_event_loop_add_fd(loop, fd, WL_EVENT_READABLE,
b->listener_events[i] = wl_event_loop_add_fd(loop, fd, WL_EVENT_READABLE,
rdp_listener_activity, instance);
}
for( ; i < MAX_FREERDP_FDS; i++)
c->listener_events[i] = 0;
b->listener_events[i] = 0;
return 0;
}
@ -793,7 +794,7 @@ static BOOL
xf_peer_activate(freerdp_peer* client)
{
RdpPeerContext *peerCtx;
struct rdp_compositor *c;
struct rdp_backend *b;
struct rdp_output *output;
rdpSettings *settings;
rdpPointerUpdate *pointer;
@ -808,9 +809,9 @@ xf_peer_activate(freerdp_peer* client)
peerCtx = (RdpPeerContext *)client->context;
c = peerCtx->rdpCompositor;
b = peerCtx->rdpBackend;
peersItem = &peerCtx->item;
output = c->output;
output = b->output;
settings = client->settings;
if (!settings->SurfaceCommandsEnabled) {
@ -821,7 +822,7 @@ xf_peer_activate(freerdp_peer* client)
if (output->base.width != (int)settings->DesktopWidth ||
output->base.height != (int)settings->DesktopHeight)
{
if (c->no_clients_resize) {
if (b->no_clients_resize) {
/* RDP peers don't dictate their resolution to weston */
if (!settings->DesktopResize) {
/* peer does not support desktop resize */
@ -891,7 +892,7 @@ xf_peer_activate(freerdp_peer* client)
else
snprintf(seat_name, sizeof(seat_name), "RDP peer @%s", settings->ClientAddress);
weston_seat_init(&peersItem->seat, &c->base, seat_name);
weston_seat_init(&peersItem->seat, b->compositor, seat_name);
weston_seat_init_keyboard(&peersItem->seat, keymap);
weston_seat_init_pointer(&peersItem->seat);
@ -929,7 +930,7 @@ xf_mouseEvent(rdpInput *input, UINT16 flags, UINT16 x, UINT16 y) {
uint32_t button = 0;
if (flags & PTR_FLAGS_MOVE) {
output = peerContext->rdpCompositor->output;
output = peerContext->rdpBackend->output;
if (x < output->base.width && y < output->base.height) {
wl_x = wl_fixed_from_int((int)x);
wl_y = wl_fixed_from_int((int)y);
@ -976,7 +977,7 @@ xf_extendedMouseEvent(rdpInput *input, UINT16 flags, UINT16 x, UINT16 y) {
RdpPeerContext *peerContext = (RdpPeerContext *)input->context;
struct rdp_output *output;
output = peerContext->rdpCompositor->output;
output = peerContext->rdpBackend->output;
if (x < output->base.width && y < output->base.height) {
wl_x = wl_fixed_from_int((int)x);
wl_y = wl_fixed_from_int((int)y);
@ -993,7 +994,7 @@ xf_input_synchronize_event(rdpInput *input, UINT32 flags)
{
freerdp_peer *client = input->context->peer;
RdpPeerContext *peerCtx = (RdpPeerContext *)input->context;
struct rdp_output *output = peerCtx->rdpCompositor->output;
struct rdp_output *output = peerCtx->rdpBackend->output;
pixman_box32_t box;
pixman_region32_t damage;
@ -1071,7 +1072,7 @@ xf_suppress_output(rdpContext *context, BYTE allow, RECTANGLE_16 *area) {
}
static int
rdp_peer_init(freerdp_peer *client, struct rdp_compositor *c)
rdp_peer_init(freerdp_peer *client, struct rdp_backend *b)
{
int rcount = 0;
void *rfds[MAX_FREERDP_FDS];
@ -1087,17 +1088,17 @@ rdp_peer_init(freerdp_peer *client, struct rdp_compositor *c)
freerdp_peer_context_new(client);
peerCtx = (RdpPeerContext *) client->context;
peerCtx->rdpCompositor = c;
peerCtx->rdpBackend = b;
client->Initialize(client);
settings = client->settings;
/* configure security settings */
if (c->rdp_key)
settings->RdpKeyFile = strdup(c->rdp_key);
if (c->tls_enabled) {
settings->CertificateFile = strdup( c->server_cert);
settings->PrivateKeyFile = strdup(c->server_key);
if (b->rdp_key)
settings->RdpKeyFile = strdup(b->rdp_key);
if (b->tls_enabled) {
settings->CertificateFile = strdup(b->server_cert);
settings->PrivateKeyFile = strdup(b->server_key);
} else {
settings->TlsSecurity = FALSE;
}
@ -1130,7 +1131,7 @@ rdp_peer_init(freerdp_peer *client, struct rdp_compositor *c)
return -1;
}
loop = wl_display_get_event_loop(c->base.wl_display);
loop = wl_display_get_event_loop(b->compositor->wl_display);
for(i = 0; i < rcount; i++) {
fd = (int)(long)(rfds[i]);
@ -1140,7 +1141,7 @@ rdp_peer_init(freerdp_peer *client, struct rdp_compositor *c)
for ( ; i < MAX_FREERDP_FDS; i++)
peerCtx->events[i] = 0;
wl_list_insert(&c->output->peers, &peerCtx->item.link);
wl_list_insert(&b->output->peers, &peerCtx->item.link);
return 0;
}
@ -1148,8 +1149,8 @@ rdp_peer_init(freerdp_peer *client, struct rdp_compositor *c)
static FREERDP_CB_RET_TYPE
rdp_incoming_peer(freerdp_listener *instance, freerdp_peer *client)
{
struct rdp_compositor *c = (struct rdp_compositor *)instance->param4;
if (rdp_peer_init(client, c) < 0) {
struct rdp_backend *b = (struct rdp_backend *)instance->param4;
if (rdp_peer_init(client, b) < 0) {
weston_log("error when treating incoming peer");
FREERDP_CB_RETURN(FALSE);
}
@ -1157,58 +1158,59 @@ rdp_incoming_peer(freerdp_listener *instance, freerdp_peer *client)
FREERDP_CB_RETURN(TRUE);
}
static struct weston_compositor *
rdp_compositor_create(struct wl_display *display,
struct rdp_compositor_config *config,
int *argc, char *argv[], struct weston_config *wconfig)
static struct rdp_backend *
rdp_backend_create(struct weston_compositor *compositor,
struct rdp_backend_config *config,
int *argc, char *argv[], struct weston_config *wconfig)
{
struct rdp_compositor *c;
struct rdp_backend *b;
char *fd_str;
int fd;
c = zalloc(sizeof *c);
if (c == NULL)
b = zalloc(sizeof *b);
if (b == NULL)
return NULL;
if (weston_compositor_init(&c->base, display, argc, argv, wconfig) < 0)
b->compositor = compositor;
if (weston_compositor_init(compositor, argc, argv, wconfig) < 0)
goto err_free;
c->base.destroy = rdp_destroy;
c->base.restore = rdp_restore;
c->rdp_key = config->rdp_key ? strdup(config->rdp_key) : NULL;
c->no_clients_resize = config->no_clients_resize;
b->base.destroy = rdp_destroy;
b->base.restore = rdp_restore;
b->rdp_key = config->rdp_key ? strdup(config->rdp_key) : NULL;
b->no_clients_resize = config->no_clients_resize;
/* activate TLS only if certificate/key are available */
if (config->server_cert && config->server_key) {
weston_log("TLS support activated\n");
c->server_cert = strdup(config->server_cert);
c->server_key = strdup(config->server_key);
if (!c->server_cert || !c->server_key)
b->server_cert = strdup(config->server_cert);
b->server_key = strdup(config->server_key);
if (!b->server_cert || !b->server_key)
goto err_free_strings;
c->tls_enabled = 1;
b->tls_enabled = 1;
}
if (weston_compositor_set_presentation_clock_software(&c->base) < 0)
if (weston_compositor_set_presentation_clock_software(compositor) < 0)
goto err_compositor;
if (pixman_renderer_init(&c->base) < 0)
if (pixman_renderer_init(compositor) < 0)
goto err_compositor;
if (rdp_compositor_create_output(c, config->width, config->height) < 0)
if (rdp_backend_create_output(b, config->width, config->height) < 0)
goto err_compositor;
c->base.capabilities |= WESTON_CAP_ARBITRARY_MODES;
compositor->capabilities |= WESTON_CAP_ARBITRARY_MODES;
if(!config->env_socket) {
c->listener = freerdp_listener_new();
c->listener->PeerAccepted = rdp_incoming_peer;
c->listener->param4 = c;
if (!c->listener->Open(c->listener, config->bind_address, config->port)) {
b->listener = freerdp_listener_new();
b->listener->PeerAccepted = rdp_incoming_peer;
b->listener->param4 = b;
if (!b->listener->Open(b->listener, config->bind_address, config->port)) {
weston_log("unable to bind rdp socket\n");
goto err_listener;
}
if (rdp_implant_listener(c, c->listener) < 0)
if (rdp_implant_listener(b, b->listener) < 0)
goto err_compositor;
} else {
/* get the socket from RDP_FD var */
@ -1219,36 +1221,38 @@ rdp_compositor_create(struct wl_display *display,
}
fd = strtoul(fd_str, NULL, 10);
if (rdp_peer_init(freerdp_peer_new(fd), c))
if (rdp_peer_init(freerdp_peer_new(fd), b))
goto err_output;
}
return &c->base;
compositor->backend = &b->base;
return b;
err_listener:
freerdp_listener_free(c->listener);
freerdp_listener_free(b->listener);
err_output:
weston_output_destroy(&c->output->base);
weston_output_destroy(&b->output->base);
err_compositor:
weston_compositor_shutdown(&c->base);
weston_compositor_shutdown(compositor);
err_free_strings:
if (c->rdp_key)
free(c->rdp_key);
if (c->server_cert)
free(c->server_cert);
if (c->server_key)
free(c->server_key);
if (b->rdp_key)
free(b->rdp_key);
if (b->server_cert)
free(b->server_cert);
if (b->server_key)
free(b->server_key);
err_free:
free(c);
free(b);
return NULL;
}
WL_EXPORT struct weston_compositor *
backend_init(struct wl_display *display, int *argc, char *argv[],
WL_EXPORT int
backend_init(struct weston_compositor *compositor, int *argc, char *argv[],
struct weston_config *wconfig)
{
struct rdp_compositor_config config;
rdp_compositor_config_init(&config);
struct rdp_backend *b;
struct rdp_backend_config config;
rdp_backend_config_init(&config);
int major, minor, revision;
freerdp_get_version(&major, &minor, &revision);
@ -1273,5 +1277,8 @@ backend_init(struct wl_display *display, int *argc, char *argv[],
return NULL;
}
return rdp_compositor_create(display, &config, argc, argv, wconfig);
b = rdp_backend_create(compositor, &config, argc, argv, wconfig);
if (b == NULL)
return -1;
return 0;
}

@ -60,7 +60,7 @@
#define DBG(...) do {} while (0)
#endif
struct rpi_compositor;
struct rpi_backend;
struct rpi_output;
struct rpi_flippipe {
@ -71,7 +71,7 @@ struct rpi_flippipe {
};
struct rpi_output {
struct rpi_compositor *compositor;
struct rpi_backend *backend;
struct weston_output base;
int single_buffer;
@ -90,8 +90,9 @@ struct rpi_seat {
char *seat_id;
};
struct rpi_compositor {
struct weston_compositor base;
struct rpi_backend {
struct weston_backend base;
struct weston_compositor *compositor;
uint32_t prev_state;
struct udev *udev;
@ -113,10 +114,10 @@ to_rpi_seat(struct weston_seat *base)
return container_of(base, struct rpi_seat, base);
}
static inline struct rpi_compositor *
to_rpi_compositor(struct weston_compositor *base)
static inline struct rpi_backend *
to_rpi_backend(struct weston_compositor *c)
{
return container_of(base, struct rpi_compositor, base);
return container_of(c->backend, struct rpi_backend, base);
}
static void
@ -191,9 +192,9 @@ rpi_flippipe_init(struct rpi_flippipe *flippipe, struct rpi_output *output)
flippipe->readfd = fd[0];
flippipe->writefd = fd[1];
flippipe->clk_id = output->compositor->base.presentation_clock;
flippipe->clk_id = output->base.compositor->presentation_clock;
loop = wl_display_get_event_loop(output->compositor->base.wl_display);
loop = wl_display_get_event_loop(output->base.compositor->wl_display);
flippipe->source = wl_event_loop_add_fd(loop, flippipe->readfd,
WL_EVENT_READABLE,
rpi_flippipe_handler, output);
@ -229,8 +230,8 @@ static int
rpi_output_repaint(struct weston_output *base, pixman_region32_t *damage)
{
struct rpi_output *output = to_rpi_output(base);
struct rpi_compositor *compositor = output->compositor;
struct weston_plane *primary_plane = &compositor->base.primary_plane;
struct weston_compositor *compositor = output->backend->compositor;
struct weston_plane *primary_plane = &compositor->primary_plane;
DISPMANX_UPDATE_HANDLE_T update;
DBG("frame update start\n");
@ -241,7 +242,7 @@ rpi_output_repaint(struct weston_output *base, pixman_region32_t *damage)
update = vc_dispmanx_update_start(1);
rpi_renderer_set_update_handle(&output->base, update);
compositor->base.renderer->repaint_output(&output->base, damage);
compositor->renderer->repaint_output(&output->base, damage);
pixman_region32_subtract(&primary_plane->damage,
&primary_plane->damage, damage);
@ -291,7 +292,7 @@ rpi_output_destroy(struct weston_output *base)
}
static int
rpi_output_create(struct rpi_compositor *compositor, uint32_t transform)
rpi_output_create(struct rpi_backend *backend, uint32_t transform)
{
struct rpi_output *output;
DISPMANX_MODEINFO_T modeinfo;
@ -302,8 +303,8 @@ rpi_output_create(struct rpi_compositor *compositor, uint32_t transform)
if (output == NULL)
return -1;
output->compositor = compositor;
output->single_buffer = compositor->single_buffer;
output->backend = backend;
output->single_buffer = backend->single_buffer;
if (rpi_flippipe_init(&output->flippipe, output) < 0) {
weston_log("Creating message pipe failed.\n");
@ -354,14 +355,14 @@ rpi_output_create(struct rpi_compositor *compositor, uint32_t transform)
mm_width = modeinfo.width * (25.4f / 96.0f);
mm_height = modeinfo.height * (25.4f / 96.0f);
weston_output_init(&output->base, &compositor->base,
weston_output_init(&output->base, backend->compositor,
0, 0, round(mm_width), round(mm_height),
transform, 1);
if (rpi_renderer_output_create(&output->base, output->display) < 0)
goto out_output;
weston_compositor_add_output(&compositor->base, &output->base);
weston_compositor_add_output(backend->compositor, &output->base);
weston_log("Raspberry Pi HDMI output %dx%d px\n",
output->mode.width, output->mode.height);
@ -391,38 +392,39 @@ out_free:
}
static void
rpi_compositor_destroy(struct weston_compositor *base)
rpi_backend_destroy(struct weston_compositor *base)
{
struct rpi_compositor *compositor = to_rpi_compositor(base);
struct rpi_backend *backend = to_rpi_backend(base);
udev_input_destroy(&compositor->input);
udev_input_destroy(&backend->input);
/* destroys outputs, too */
weston_compositor_shutdown(&compositor->base);
weston_compositor_shutdown(base);
weston_launcher_destroy(compositor->base.launcher);
weston_launcher_destroy(base->launcher);
bcm_host_deinit();
free(compositor);
free(backend);
}
static void
session_notify(struct wl_listener *listener, void *data)
{
struct rpi_compositor *compositor = data;
struct weston_compositor *compositor = data;
struct rpi_backend *backend = to_rpi_backend(compositor);
struct weston_output *output;
if (compositor->base.session_active) {
if (compositor->session_active) {
weston_log("activating session\n");
compositor->base.state = compositor->prev_state;
weston_compositor_damage_all(&compositor->base);
udev_input_enable(&compositor->input);
compositor->state = backend->prev_state;
weston_compositor_damage_all(compositor);
udev_input_enable(&backend->input);
} else {
weston_log("deactivating session\n");
udev_input_disable(&compositor->input);
udev_input_disable(&backend->input);
compositor->prev_state = compositor->base.state;
weston_compositor_offscreen(&compositor->base);
backend->prev_state = compositor->state;
weston_compositor_offscreen(compositor);
/* If we have a repaint scheduled (either from a
* pending pageflip or the idle handler), make sure we
@ -433,7 +435,7 @@ session_notify(struct wl_listener *listener, void *data)
* pending frame callbacks. */
wl_list_for_each(output,
&compositor->base.output_list, link) {
&compositor->output_list, link) {
output->repaint_needed = 0;
}
};
@ -459,56 +461,56 @@ struct rpi_parameters {
uint32_t output_transform;
};
static struct weston_compositor *
rpi_compositor_create(struct wl_display *display, int *argc, char *argv[],
struct weston_config *config,
struct rpi_parameters *param)
static struct rpi_backend *
rpi_backend_create(struct weston_compositor *compositor,
struct rpi_parameters *param,
int *argc, char *argv[],
struct weston_config *config)
{
struct rpi_compositor *compositor;
struct rpi_backend *backend;
uint32_t key;
weston_log("initializing Raspberry Pi backend\n");
compositor = zalloc(sizeof *compositor);
if (compositor == NULL)
backend = zalloc(sizeof *backend);
if (backend == NULL)
return NULL;
if (weston_compositor_init(&compositor->base, display, argc, argv,
if (weston_compositor_init(compositor, argc, argv,
config) < 0)
goto out_free;
if (weston_compositor_set_presentation_clock_software(
&compositor->base) < 0)
compositor) < 0)
goto out_compositor;
compositor->udev = udev_new();
if (compositor->udev == NULL) {
backend->udev = udev_new();
if (backend->udev == NULL) {
weston_log("Failed to initialize udev context.\n");
goto out_compositor;
}
compositor->session_listener.notify = session_notify;
wl_signal_add(&compositor->base.session_signal,
&compositor ->session_listener);
compositor->base.launcher = weston_launcher_connect(&compositor->base,
param->tty, "seat0",
false);
if (!compositor->base.launcher) {
backend->session_listener.notify = session_notify;
wl_signal_add(&compositor->session_signal,
&backend->session_listener);
compositor->launcher =
weston_launcher_connect(compositor, param->tty, "seat0", false);
if (!compositor->launcher) {
weston_log("Failed to initialize tty.\n");
goto out_udev;
}
compositor->base.destroy = rpi_compositor_destroy;
compositor->base.restore = rpi_restore;
backend->base.destroy = rpi_backend_destroy;
backend->base.restore = rpi_restore;
compositor->prev_state = WESTON_COMPOSITOR_ACTIVE;
compositor->single_buffer = param->renderer.single_buffer;
backend->prev_state = WESTON_COMPOSITOR_ACTIVE;
backend->single_buffer = param->renderer.single_buffer;
weston_log("Dispmanx planes are %s buffered.\n",
compositor->single_buffer ? "single" : "double");
backend->single_buffer ? "single" : "double");
for (key = KEY_F1; key < KEY_F9; key++)
weston_compositor_add_key_binding(&compositor->base, key,
weston_compositor_add_key_binding(compositor, key,
MODIFIER_CTRL | MODIFIER_ALT,
switch_vt_binding, compositor);
@ -521,45 +523,47 @@ rpi_compositor_create(struct wl_display *display, int *argc, char *argv[],
*/
bcm_host_init();
if (rpi_renderer_create(&compositor->base, &param->renderer) < 0)
if (rpi_renderer_create(compositor, &param->renderer) < 0)
goto out_launcher;
if (rpi_output_create(compositor, param->output_transform) < 0)
if (rpi_output_create(backend, param->output_transform) < 0)
goto out_renderer;
if (udev_input_init(&compositor->input,
&compositor->base,
compositor->udev, "seat0") != 0) {
if (udev_input_init(&backend->input,
compositor,
backend->udev, "seat0") != 0) {
weston_log("Failed to initialize udev input.\n");
goto out_renderer;
}
return &compositor->base;
return backend;
out_renderer:
compositor->base.renderer->destroy(&compositor->base);
compositor->renderer->destroy(compositor);
out_launcher:
weston_launcher_destroy(compositor->base.launcher);
weston_launcher_destroy(compositor->launcher);
out_udev:
udev_unref(compositor->udev);
udev_unref(backend->udev);
out_compositor:
weston_compositor_shutdown(&compositor->base);
weston_compositor_shutdown(compositor);
out_free:
bcm_host_deinit();
free(compositor);
free(backend);
return NULL;
}
WL_EXPORT struct weston_compositor *
backend_init(struct wl_display *display, int *argc, char *argv[],
WL_EXPORT int
backend_init(struct weston_compositor *compositor,
int *argc, char *argv[],
struct weston_config *config)
{
const char *transform = "normal";
struct rpi_backend *b;
struct rpi_parameters param = {
.tty = 0, /* default to current tty */
@ -582,5 +586,8 @@ backend_init(struct wl_display *display, int *argc, char *argv[],
if (weston_parse_transform(transform, &param.output_transform) < 0)
weston_log("invalid transform \"%s\"\n", transform);
return rpi_compositor_create(display, argc, argv, config, &param);
b = rpi_backend_create(compositor, &param, argc, argv, config);
if (b == NULL)
return -1;
return 0;
}

@ -51,8 +51,9 @@
#define WINDOW_TITLE "Weston Compositor"
struct wayland_compositor {
struct weston_compositor base;
struct wayland_backend {
struct weston_backend base;
struct weston_compositor *compositor;
struct {
struct wl_display *wl_display;
@ -157,7 +158,7 @@ struct wayland_shm_buffer {
struct wayland_input {
struct weston_seat base;
struct wayland_compositor *compositor;
struct wayland_backend *backend;
struct wl_list link;
struct {
@ -217,9 +218,9 @@ static const struct wl_buffer_listener buffer_listener = {
static struct wayland_shm_buffer *
wayland_output_get_shm_buffer(struct wayland_output *output)
{
struct wayland_compositor *c =
(struct wayland_compositor *) output->base.compositor;
struct wl_shm *shm = c->parent.shm;
struct wayland_backend *b =
(struct wayland_backend *) output->base.compositor->backend;
struct wl_shm *shm = b->parent.shm;
struct wayland_shm_buffer *sb;
struct wl_shm_pool *pool;
@ -424,8 +425,8 @@ static void
wayland_output_start_repaint_loop(struct weston_output *output_base)
{
struct wayland_output *output = (struct wayland_output *) output_base;
struct wayland_compositor *wc =
(struct wayland_compositor *)output->base.compositor;
struct wayland_backend *wb =
(struct wayland_backend *)output->base.compositor->backend;
struct wl_callback *callback;
/* If this is the initial frame, we need to attach a buffer so that
@ -442,7 +443,7 @@ wayland_output_start_repaint_loop(struct weston_output *output_base)
callback = wl_surface_frame(output->parent.surface);
wl_callback_add_listener(callback, &frame_listener, output);
wl_surface_commit(output->parent.surface);
wl_display_flush(wc->parent.wl_display);
wl_display_flush(wb->parent.wl_display);
}
static int
@ -557,8 +558,8 @@ wayland_output_repaint_pixman(struct weston_output *output_base,
pixman_region32_t *damage)
{
struct wayland_output *output = (struct wayland_output *) output_base;
struct wayland_compositor *c =
(struct wayland_compositor *)output->base.compositor;
struct wayland_backend *b =
(struct wayland_backend *)output->base.compositor->backend;
struct wl_callback *callback;
struct wayland_shm_buffer *sb;
@ -575,21 +576,21 @@ wayland_output_repaint_pixman(struct weston_output *output_base,
wayland_output_update_shm_border(sb);
pixman_renderer_output_set_buffer(output_base, sb->pm_image);
c->base.renderer->repaint_output(output_base, &sb->damage);
b->compositor->renderer->repaint_output(output_base, &sb->damage);
wayland_shm_buffer_attach(sb);
callback = wl_surface_frame(output->parent.surface);
wl_callback_add_listener(callback, &frame_listener, output);
wl_surface_commit(output->parent.surface);
wl_display_flush(c->parent.wl_display);
wl_display_flush(b->parent.wl_display);
pixman_region32_fini(&sb->damage);
pixman_region32_init(&sb->damage);
sb->frame_damaged = 0;
pixman_region32_subtract(&c->base.primary_plane.damage,
&c->base.primary_plane.damage, damage);
pixman_region32_subtract(&b->compositor->primary_plane.damage,
&b->compositor->primary_plane.damage, damage);
return 0;
}
@ -597,10 +598,10 @@ static void
wayland_output_destroy(struct weston_output *output_base)
{
struct wayland_output *output = (struct wayland_output *) output_base;
struct wayland_compositor *c =
(struct wayland_compositor *) output->base.compositor;
struct wayland_backend *b =
(struct wayland_backend *) output->base.compositor->backend;
if (c->use_pixman) {
if (b->use_pixman) {
pixman_renderer_output_destroy(output_base);
} else {
gl_renderer->output_destroy(output_base);
@ -672,8 +673,8 @@ wayland_output_init_pixman_renderer(struct wayland_output *output)
static void
wayland_output_resize_surface(struct wayland_output *output)
{
struct wayland_compositor *c =
(struct wayland_compositor *)output->base.compositor;
struct wayland_backend *b =
(struct wayland_backend *)output->base.compositor->backend;
struct wayland_shm_buffer *buffer, *next;
int32_t ix, iy, iwidth, iheight;
int32_t width, height;
@ -686,13 +687,13 @@ wayland_output_resize_surface(struct wayland_output *output)
frame_resize_inside(output->frame, width, height);
frame_input_rect(output->frame, &ix, &iy, &iwidth, &iheight);
region = wl_compositor_create_region(c->parent.compositor);
region = wl_compositor_create_region(b->parent.compositor);
wl_region_add(region, ix, iy, iwidth, iheight);
wl_surface_set_input_region(output->parent.surface, region);
wl_region_destroy(region);
frame_opaque_rect(output->frame, &ix, &iy, &iwidth, &iheight);
region = wl_compositor_create_region(c->parent.compositor);
region = wl_compositor_create_region(b->parent.compositor);
wl_region_add(region, ix, iy, iwidth, iheight);
wl_surface_set_opaque_region(output->parent.surface, region);
wl_region_destroy(region);
@ -700,12 +701,12 @@ wayland_output_resize_surface(struct wayland_output *output)
width = frame_width(output->frame);
height = frame_height(output->frame);
} else {
region = wl_compositor_create_region(c->parent.compositor);
region = wl_compositor_create_region(b->parent.compositor);
wl_region_add(region, 0, 0, width, height);
wl_surface_set_input_region(output->parent.surface, region);
wl_region_destroy(region);
region = wl_compositor_create_region(c->parent.compositor);
region = wl_compositor_create_region(b->parent.compositor);
wl_region_add(region, 0, 0, width, height);
wl_surface_set_opaque_region(output->parent.surface, region);
wl_region_destroy(region);
@ -749,8 +750,8 @@ wayland_output_resize_surface(struct wayland_output *output)
static int
wayland_output_set_windowed(struct wayland_output *output)
{
struct wayland_compositor *c =
(struct wayland_compositor *)output->base.compositor;
struct wayland_backend *b =
(struct wayland_backend *)output->base.compositor->backend;
int tlen;
char *title;
@ -768,14 +769,14 @@ wayland_output_set_windowed(struct wayland_output *output)
title = strdup(WINDOW_TITLE);
}
if (!c->theme) {
c->theme = theme_create();
if (!c->theme) {
if (!b->theme) {
b->theme = theme_create();
if (!b->theme) {
free(title);
return -1;
}
}
output->frame = frame_create(c->theme, 100, 100,
output->frame = frame_create(b->theme, 100, 100,
FRAME_BUTTON_CLOSE, title);
free(title);
if (!output->frame)
@ -796,8 +797,8 @@ wayland_output_set_fullscreen(struct wayland_output *output,
enum wl_shell_surface_fullscreen_method method,
uint32_t framerate, struct wl_output *target)
{
struct wayland_compositor *c =
(struct wayland_compositor *)output->base.compositor;
struct wayland_backend *b =
(struct wayland_backend *)output->base.compositor->backend;
if (output->frame) {
frame_destroy(output->frame);
@ -809,8 +810,8 @@ wayland_output_set_fullscreen(struct wayland_output *output,
if (output->parent.shell_surface) {
wl_shell_surface_set_fullscreen(output->parent.shell_surface,
method, framerate, target);
} else if (c->parent.fshell) {
_wl_fullscreen_shell_present_surface(c->parent.fshell,
} else if (b->parent.fshell) {
_wl_fullscreen_shell_present_surface(b->parent.fshell,
output->parent.surface,
method, target);
}
@ -888,7 +889,7 @@ wayland_output_switch_mode(struct weston_output *output_base,
struct weston_mode *mode)
{
struct wayland_output *output = (struct wayland_output *) output_base;
struct wayland_compositor *c;
struct wayland_backend *b;
struct wl_surface *old_surface;
struct weston_mode *old_mode;
struct _wl_fullscreen_shell_mode_feedback *mode_feedback;
@ -905,9 +906,9 @@ wayland_output_switch_mode(struct weston_output *output_base,
return -1;
}
c = (struct wayland_compositor *)output_base->compositor;
b = (struct wayland_backend *)output_base->compositor->backend;
if (output->parent.shell_surface || !c->parent.fshell)
if (output->parent.shell_surface || !b->parent.fshell)
return -1;
mode = wayland_output_choose_mode(output, mode);
@ -921,14 +922,14 @@ wayland_output_switch_mode(struct weston_output *output_base,
old_surface = output->parent.surface;
output->base.current_mode = mode;
output->parent.surface =
wl_compositor_create_surface(c->parent.compositor);
wl_compositor_create_surface(b->parent.compositor);
wl_surface_set_user_data(output->parent.surface, output);
/* Blow the old buffers because we changed size/surfaces */
wayland_output_resize_surface(output);
mode_feedback =
_wl_fullscreen_shell_present_surface_for_mode(c->parent.fshell,
_wl_fullscreen_shell_present_surface_for_mode(b->parent.fshell,
output->parent.surface,
output->parent.output,
mode->refresh);
@ -942,7 +943,7 @@ wayland_output_switch_mode(struct weston_output *output_base,
mode_status = MODE_STATUS_UNKNOWN;
while (mode_status == MODE_STATUS_UNKNOWN && ret >= 0)
ret = wl_display_dispatch(c->parent.wl_display);
ret = wl_display_dispatch(b->parent.wl_display);
_wl_fullscreen_shell_mode_feedback_destroy(mode_feedback);
@ -958,7 +959,7 @@ wayland_output_switch_mode(struct weston_output *output_base,
old_mode->flags &= ~WL_OUTPUT_MODE_CURRENT;
output->base.current_mode->flags |= WL_OUTPUT_MODE_CURRENT;
if (c->use_pixman) {
if (b->use_pixman) {
pixman_renderer_output_destroy(output_base);
if (wayland_output_init_pixman_renderer(output) < 0)
goto err_output;
@ -980,7 +981,7 @@ err_output:
}
static struct wayland_output *
wayland_output_create(struct wayland_compositor *c, int x, int y,
wayland_output_create(struct wayland_backend *b, int x, int y,
int width, int height, const char *name, int fullscreen,
uint32_t transform, int32_t scale)
{
@ -1002,16 +1003,16 @@ wayland_output_create(struct wayland_compositor *c, int x, int y,
output_height = height * scale;
output->parent.surface =
wl_compositor_create_surface(c->parent.compositor);
wl_compositor_create_surface(b->parent.compositor);
if (!output->parent.surface)
goto err_name;
wl_surface_set_user_data(output->parent.surface, output);
output->parent.draw_initial_frame = 1;
if (c->parent.shell) {
if (b->parent.shell) {
output->parent.shell_surface =
wl_shell_get_shell_surface(c->parent.shell,
wl_shell_get_shell_surface(b->parent.shell,
output->parent.surface);
if (!output->parent.shell_surface)
goto err_surface;
@ -1019,10 +1020,10 @@ wayland_output_create(struct wayland_compositor *c, int x, int y,
&shell_surface_listener, output);
}
if (fullscreen && c->parent.shell) {
if (fullscreen && b->parent.shell) {
wl_shell_surface_set_fullscreen(output->parent.shell_surface,
0, 0, NULL);
wl_display_roundtrip(c->parent.wl_display);
wl_display_roundtrip(b->parent.wl_display);
if (!width)
output_width = output->parent.configure_width;
if (!height)
@ -1042,10 +1043,10 @@ wayland_output_create(struct wayland_compositor *c, int x, int y,
wl_list_init(&output->shm.buffers);
wl_list_init(&output->shm.free_buffers);
weston_output_init(&output->base, &c->base, x, y, width, height,
weston_output_init(&output->base, b->compositor, x, y, width, height,
transform, scale);
if (c->use_pixman) {
if (b->use_pixman) {
if (wayland_output_init_pixman_renderer(output) < 0)
goto err_output;
output->base.repaint = wayland_output_repaint_pixman;
@ -1062,7 +1063,7 @@ wayland_output_create(struct wayland_compositor *c, int x, int y,
output->base.set_dpms = NULL;
output->base.switch_mode = wayland_output_switch_mode;
weston_compositor_add_output(&c->base, &output->base);
weston_compositor_add_output(b->compositor, &output->base);
return output;
@ -1082,7 +1083,7 @@ err_name:
}
static struct wayland_output *
wayland_output_create_for_config(struct wayland_compositor *c,
wayland_output_create_for_config(struct wayland_backend *b,
struct weston_config_section *config_section,
int option_width, int option_height,
int option_scale, int32_t x, int32_t y)
@ -1133,7 +1134,7 @@ wayland_output_create_for_config(struct wayland_compositor *c,
t, name);
free(t);
output = wayland_output_create(c, x, y, width, height, name, 0,
output = wayland_output_create(b, x, y, width, height, name, 0,
transform, scale);
free(name);
@ -1141,7 +1142,7 @@ wayland_output_create_for_config(struct wayland_compositor *c,
}
static struct wayland_output *
wayland_output_create_for_parent_output(struct wayland_compositor *c,
wayland_output_create_for_parent_output(struct wayland_backend *b,
struct wayland_parent_output *poutput)
{
struct wayland_output *output;
@ -1160,15 +1161,15 @@ wayland_output_create_for_parent_output(struct wayland_compositor *c,
return NULL;
}
if (!wl_list_empty(&c->base.output_list)) {
output = container_of(c->base.output_list.prev,
if (!wl_list_empty(&b->compositor->output_list)) {
output = container_of(b->compositor->output_list.prev,
struct wayland_output, base.link);
x = output->base.x + output->base.current_mode->width;
} else {
x = 0;
}
output = wayland_output_create(c, x, 0, mode->width, mode->height,
output = wayland_output_create(b, x, 0, mode->width, mode->height,
NULL, 0,
WL_OUTPUT_TRANSFORM_NORMAL, 1);
if (!output)
@ -1190,13 +1191,13 @@ wayland_output_create_for_parent_output(struct wayland_compositor *c,
wl_shell_surface_set_fullscreen(output->parent.shell_surface,
WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER,
mode->refresh, poutput->global);
} else if (c->parent.fshell) {
_wl_fullscreen_shell_present_surface(c->parent.fshell,
} else if (b->parent.fshell) {
_wl_fullscreen_shell_present_surface(b->parent.fshell,
output->parent.surface,
_WL_FULLSCREEN_SHELL_PRESENT_METHOD_CENTER,
poutput->global);
_wl_fullscreen_shell_mode_feedback_destroy(
_wl_fullscreen_shell_present_surface_for_mode(c->parent.fshell,
_wl_fullscreen_shell_present_surface_for_mode(b->parent.fshell,
output->parent.surface,
poutput->global,
mode->refresh));
@ -1245,10 +1246,10 @@ input_set_cursor(struct wayland_input *input)
struct wl_buffer *buffer;
struct wl_cursor_image *image;
if (!input->compositor->cursor)
if (!input->backend->cursor)
return; /* Couldn't load the cursor. Can't set it */
image = input->compositor->cursor->images[0];
image = input->backend->cursor->images[0];
buffer = wl_cursor_image_get_buffer(image);
if (!buffer)
return;
@ -1402,8 +1403,8 @@ input_handle_button(void *data, struct wl_pointer *pointer,
input->output = NULL;
input->keyboard_focus = NULL;
if (wl_list_empty(&input->compositor->base.output_list))
wl_display_terminate(input->compositor->base.wl_display);
if (wl_list_empty(&input->backend->compositor->output_list))
wl_display_terminate(input->backend->compositor->wl_display);
return;
}
@ -1455,7 +1456,7 @@ input_handle_keymap(void *data, struct wl_keyboard *keyboard, uint32_t format,
goto error;
}
keymap = xkb_keymap_new_from_string(input->compositor->base.xkb_context,
keymap = xkb_keymap_new_from_string(input->backend->compositor->xkb_context,
map_str,
XKB_KEYMAP_FORMAT_TEXT_V1,
0);
@ -1574,16 +1575,16 @@ input_handle_modifiers(void *data, struct wl_keyboard *keyboard,
uint32_t group)
{
struct wayland_input *input = data;
struct wayland_compositor *c = input->compositor;
struct wayland_backend *b = input->backend;
uint32_t serial_out;
/* If we get a key event followed by a modifier event with the
* same serial number, then we try to preserve those semantics by
* reusing the same serial number on the way out too. */
if (serial_in == input->key_serial)
serial_out = wl_display_get_serial(c->base.wl_display);
serial_out = wl_display_get_serial(b->compositor->wl_display);
else
serial_out = wl_display_next_serial(c->base.wl_display);
serial_out = wl_display_next_serial(b->compositor->wl_display);
xkb_state_update_mask(input->base.keyboard->xkb_state.state,
mods_depressed, mods_latched,
@ -1596,10 +1597,10 @@ input_handle_repeat_info(void *data, struct wl_keyboard *keyboard,
int32_t rate, int32_t delay)
{
struct wayland_input *input = data;
struct wayland_compositor *c = input->compositor;
struct wayland_backend *b = input->backend;
c->base.kb_repeat_rate = rate;
c->base.kb_repeat_delay = delay;
b->compositor->kb_repeat_rate = rate;
b->compositor->kb_repeat_delay = delay;
}
static const struct wl_keyboard_listener keyboard_listener = {
@ -1651,7 +1652,7 @@ static const struct wl_seat_listener seat_listener = {
};
static void
display_add_seat(struct wayland_compositor *c, uint32_t id, uint32_t version)
display_add_seat(struct wayland_backend *b, uint32_t id, uint32_t version)
{
struct wayland_input *input;
@ -1659,17 +1660,17 @@ display_add_seat(struct wayland_compositor *c, uint32_t id, uint32_t version)
if (input == NULL)
return;
weston_seat_init(&input->base, &c->base, "default");
input->compositor = c;
input->parent.seat = wl_registry_bind(c->parent.registry, id,
weston_seat_init(&input->base, b->compositor, "default");
input->backend = b;
input->parent.seat = wl_registry_bind(b->parent.registry, id,
&wl_seat_interface, MIN(version, 4));
wl_list_insert(c->input_list.prev, &input->link);
wl_list_insert(b->input_list.prev, &input->link);
wl_seat_add_listener(input->parent.seat, &seat_listener, input);
wl_seat_set_user_data(input->parent.seat, input);
input->parent.cursor.surface =
wl_compositor_create_surface(c->parent.compositor);
wl_compositor_create_surface(b->parent.compositor);
}
static void
@ -1751,7 +1752,7 @@ static const struct wl_output_listener output_listener = {
};
static void
wayland_compositor_register_output(struct wayland_compositor *c, uint32_t id)
wayland_backend_register_output(struct wayland_backend *b, uint32_t id)
{
struct wayland_parent_output *output;
@ -1760,7 +1761,7 @@ wayland_compositor_register_output(struct wayland_compositor *c, uint32_t id)
return;
output->id = id;
output->global = wl_registry_bind(c->parent.registry, id,
output->global = wl_registry_bind(b->parent.registry, id,
&wl_output_interface, 1);
if (!output->global) {
free(output);
@ -1773,11 +1774,11 @@ wayland_compositor_register_output(struct wayland_compositor *c, uint32_t id)
output->transform = WL_OUTPUT_TRANSFORM_NORMAL;
output->physical.subpixel = WL_OUTPUT_SUBPIXEL_UNKNOWN;
wl_list_init(&output->mode_list);
wl_list_insert(&c->parent.output_list, &output->link);
wl_list_insert(&b->parent.output_list, &output->link);
if (c->sprawl_across_outputs) {
wl_display_roundtrip(c->parent.wl_display);
wayland_output_create_for_parent_output(c, output);
if (b->sprawl_across_outputs) {
wl_display_roundtrip(b->parent.wl_display);
wayland_output_create_for_parent_output(b, output);
}
}
@ -1803,26 +1804,26 @@ static void
registry_handle_global(void *data, struct wl_registry *registry, uint32_t name,
const char *interface, uint32_t version)
{
struct wayland_compositor *c = data;
struct wayland_backend *b = data;
if (strcmp(interface, "wl_compositor") == 0) {
c->parent.compositor =
b->parent.compositor =
wl_registry_bind(registry, name,
&wl_compositor_interface, 1);
} else if (strcmp(interface, "wl_shell") == 0) {
c->parent.shell =
b->parent.shell =
wl_registry_bind(registry, name,
&wl_shell_interface, 1);
} else if (strcmp(interface, "_wl_fullscreen_shell") == 0) {
c->parent.fshell =
b->parent.fshell =
wl_registry_bind(registry, name,
&_wl_fullscreen_shell_interface, 1);
} else if (strcmp(interface, "wl_seat") == 0) {
display_add_seat(c, name, version);
display_add_seat(b, name, version);
} else if (strcmp(interface, "wl_output") == 0) {
wayland_compositor_register_output(c, name);
wayland_backend_register_output(b, name);
} else if (strcmp(interface, "wl_shm") == 0) {
c->parent.shm =
b->parent.shm =
wl_registry_bind(registry, name, &wl_shm_interface, 1);
}
}
@ -1831,10 +1832,10 @@ static void
registry_handle_global_remove(void *data, struct wl_registry *registry,
uint32_t name)
{
struct wayland_compositor *c = data;
struct wayland_backend *b = data;
struct wayland_parent_output *output;
wl_list_for_each(output, &c->parent.output_list, link)
wl_list_for_each(output, &b->parent.output_list, link)
if (output->id == name)
wayland_parent_output_destroy(output);
}
@ -1845,24 +1846,24 @@ static const struct wl_registry_listener registry_listener = {
};
static int
wayland_compositor_handle_event(int fd, uint32_t mask, void *data)
wayland_backend_handle_event(int fd, uint32_t mask, void *data)
{
struct wayland_compositor *c = data;
struct wayland_backend *b = data;
int count = 0;
if ((mask & WL_EVENT_HANGUP) || (mask & WL_EVENT_ERROR)) {
wl_display_terminate(c->base.wl_display);
wl_display_terminate(b->compositor->wl_display);
return 0;
}
if (mask & WL_EVENT_READABLE)
count = wl_display_dispatch(c->parent.wl_display);
count = wl_display_dispatch(b->parent.wl_display);
if (mask & WL_EVENT_WRITABLE)
wl_display_flush(c->parent.wl_display);
wl_display_flush(b->parent.wl_display);
if (mask == 0) {
count = wl_display_dispatch_pending(c->parent.wl_display);
wl_display_flush(c->parent.wl_display);
count = wl_display_dispatch_pending(b->parent.wl_display);
wl_display_flush(b->parent.wl_display);
}
return count;
@ -1876,14 +1877,14 @@ wayland_restore(struct weston_compositor *ec)
static void
wayland_destroy(struct weston_compositor *ec)
{
struct wayland_compositor *c = (struct wayland_compositor *) ec;
struct wayland_backend *b = (struct wayland_backend *) ec->backend;
weston_compositor_shutdown(ec);
if (c->parent.shm)
wl_shm_destroy(c->parent.shm);
if (b->parent.shm)
wl_shm_destroy(b->parent.shm);
free(ec);
free(b);
}
static const char *left_ptrs[] = {
@ -1894,7 +1895,7 @@ static const char *left_ptrs[] = {
};
static void
create_cursor(struct wayland_compositor *c, struct weston_config *config)
create_cursor(struct wayland_backend *b, struct weston_config *config)
{
struct weston_config_section *s;
int size;
@ -1905,19 +1906,19 @@ create_cursor(struct wayland_compositor *c, struct weston_config *config)
weston_config_section_get_string(s, "cursor-theme", &theme, NULL);
weston_config_section_get_int(s, "cursor-size", &size, 32);
c->cursor_theme = wl_cursor_theme_load(theme, size, c->parent.shm);
if (!c->cursor_theme) {
b->cursor_theme = wl_cursor_theme_load(theme, size, b->parent.shm);
if (!b->cursor_theme) {
fprintf(stderr, "could not load cursor theme\n");
return;
}
free(theme);
c->cursor = NULL;
for (i = 0; !c->cursor && i < ARRAY_LENGTH(left_ptrs); ++i)
c->cursor = wl_cursor_theme_get_cursor(c->cursor_theme,
b->cursor = NULL;
for (i = 0; !b->cursor && i < ARRAY_LENGTH(left_ptrs); ++i)
b->cursor = wl_cursor_theme_get_cursor(b->cursor_theme,
left_ptrs[i]);
if (!c->cursor) {
if (!b->cursor) {
fprintf(stderr, "could not load left cursor\n");
return;
}
@ -1927,10 +1928,10 @@ static void
fullscreen_binding(struct weston_seat *seat_base, uint32_t time, uint32_t key,
void *data)
{
struct wayland_compositor *c = data;
struct wayland_backend *b = data;
struct wayland_input *input = NULL;
wl_list_for_each(input, &c->input_list, link)
wl_list_for_each(input, &b->input_list, link)
if (&input->base == seat_base)
break;
@ -1945,123 +1946,123 @@ fullscreen_binding(struct weston_seat *seat_base, uint32_t time, uint32_t key,
weston_output_schedule_repaint(&input->output->base);
}
static struct wayland_compositor *
wayland_compositor_create(struct wl_display *display, int use_pixman,
const char *display_name, int *argc, char *argv[],
struct weston_config *config)
static struct wayland_backend *
wayland_backend_create(struct weston_compositor *compositor, int use_pixman,
const char *display_name, int *argc, char *argv[],
struct weston_config *config)
{
struct wayland_compositor *c;
struct wayland_backend *b;
struct wl_event_loop *loop;
int fd;
c = zalloc(sizeof *c);
if (c == NULL)
b = zalloc(sizeof *b);
if (b == NULL)
return NULL;
if (weston_compositor_init(&c->base, display, argc, argv,
b->compositor = compositor;
if (weston_compositor_init(compositor, argc, argv,
config) < 0)
goto err_free;
if (weston_compositor_set_presentation_clock_software(&c->base) < 0)
if (weston_compositor_set_presentation_clock_software(compositor) < 0)
goto err_compositor;
c->parent.wl_display = wl_display_connect(display_name);
if (c->parent.wl_display == NULL) {
b->parent.wl_display = wl_display_connect(display_name);
if (b->parent.wl_display == NULL) {
weston_log("failed to create display: %m\n");
goto err_compositor;
}
wl_list_init(&c->parent.output_list);
wl_list_init(&c->input_list);
c->parent.registry = wl_display_get_registry(c->parent.wl_display);
wl_registry_add_listener(c->parent.registry, &registry_listener, c);
wl_display_roundtrip(c->parent.wl_display);
wl_list_init(&b->parent.output_list);
wl_list_init(&b->input_list);
b->parent.registry = wl_display_get_registry(b->parent.wl_display);
wl_registry_add_listener(b->parent.registry, &registry_listener, b);
wl_display_roundtrip(b->parent.wl_display);
create_cursor(c, config);
create_cursor(b, config);
c->base.wl_display = display;
b->use_pixman = use_pixman;
c->use_pixman = use_pixman;
if (!c->use_pixman) {
if (!b->use_pixman) {
gl_renderer = weston_load_module("gl-renderer.so",
"gl_renderer_interface");
if (!gl_renderer)
c->use_pixman = 1;
b->use_pixman = 1;
}
if (!c->use_pixman) {
if (gl_renderer->create(&c->base,
if (!b->use_pixman) {
if (gl_renderer->create(compositor,
EGL_PLATFORM_WAYLAND_KHR,
c->parent.wl_display,
b->parent.wl_display,
gl_renderer->alpha_attribs,
NULL,
0) < 0) {
weston_log("Failed to initialize the GL renderer; "
"falling back to pixman.\n");
c->use_pixman = 1;
b->use_pixman = 1;
}
}
if (c->use_pixman) {
if (pixman_renderer_init(&c->base) < 0) {
if (b->use_pixman) {
if (pixman_renderer_init(compositor) < 0) {
weston_log("Failed to initialize pixman renderer\n");
goto err_display;
}
}
c->base.destroy = wayland_destroy;
c->base.restore = wayland_restore;
b->base.destroy = wayland_destroy;
b->base.restore = wayland_restore;
loop = wl_display_get_event_loop(c->base.wl_display);
loop = wl_display_get_event_loop(compositor->wl_display);
fd = wl_display_get_fd(c->parent.wl_display);
c->parent.wl_source =
fd = wl_display_get_fd(b->parent.wl_display);
b->parent.wl_source =
wl_event_loop_add_fd(loop, fd, WL_EVENT_READABLE,
wayland_compositor_handle_event, c);
if (c->parent.wl_source == NULL)
wayland_backend_handle_event, b);
if (b->parent.wl_source == NULL)
goto err_renderer;
wl_event_source_check(c->parent.wl_source);
wl_event_source_check(b->parent.wl_source);
return c;
compositor->backend = &b->base;
return b;
err_renderer:
c->base.renderer->destroy(&c->base);
compositor->renderer->destroy(compositor);
err_display:
wl_display_disconnect(c->parent.wl_display);
wl_display_disconnect(b->parent.wl_display);
err_compositor:
weston_compositor_shutdown(&c->base);
weston_compositor_shutdown(compositor);
err_free:
free(c);
free(b);
return NULL;
}
static void
wayland_compositor_destroy(struct wayland_compositor *c)
wayland_backend_destroy(struct wayland_backend *b)
{
struct weston_output *output, *next;
wl_list_for_each_safe(output, next, &c->base.output_list, link)
wl_list_for_each_safe(output, next, &b->compositor->output_list, link)
wayland_output_destroy(output);
c->base.renderer->destroy(&c->base);
wl_display_disconnect(c->parent.wl_display);
b->compositor->renderer->destroy(b->compositor);
wl_display_disconnect(b->parent.wl_display);
if (c->theme)
theme_destroy(c->theme);
if (c->frame_device)
cairo_device_destroy(c->frame_device);
wl_cursor_theme_destroy(c->cursor_theme);
if (b->theme)
theme_destroy(b->theme);
if (b->frame_device)
cairo_device_destroy(b->frame_device);
wl_cursor_theme_destroy(b->cursor_theme);
weston_compositor_shutdown(&c->base);
free(c);
weston_compositor_shutdown(b->compositor);
free(b);
}
WL_EXPORT struct weston_compositor *
backend_init(struct wl_display *display, int *argc, char *argv[],
WL_EXPORT int
backend_init(struct weston_compositor *compositor, int *argc, char *argv[],
struct weston_config *config)
{
struct wayland_compositor *c;
struct wayland_backend *b;
struct wayland_output *output;
struct wayland_parent_output *poutput;
struct weston_config_section *section;
@ -2091,29 +2092,29 @@ backend_init(struct wl_display *display, int *argc, char *argv[],
parse_options(wayland_options,
ARRAY_LENGTH(wayland_options), argc, argv);
c = wayland_compositor_create(display, use_pixman, display_name,
argc, argv, config);
if (!c)
return NULL;
b = wayland_backend_create(compositor, use_pixman, display_name,
argc, argv, config);
if (!b)
return -1;
if (sprawl || c->parent.fshell) {
c->sprawl_across_outputs = 1;
wl_display_roundtrip(c->parent.wl_display);
if (sprawl || b->parent.fshell) {
b->sprawl_across_outputs = 1;
wl_display_roundtrip(b->parent.wl_display);
wl_list_for_each(poutput, &c->parent.output_list, link)
wayland_output_create_for_parent_output(c, poutput);
wl_list_for_each(poutput, &b->parent.output_list, link)
wayland_output_create_for_parent_output(b, poutput);
return &c->base;
return 0;
}
if (fullscreen) {
output = wayland_output_create(c, 0, 0, width, height,
output = wayland_output_create(b, 0, 0, width, height,
NULL, 1, 0, 1);
if (!output)
goto err_outputs;
wayland_output_set_fullscreen(output, 0, 0, NULL);
return &c->base;
return 0;
}
section = NULL;
@ -2131,7 +2132,7 @@ backend_init(struct wl_display *display, int *argc, char *argv[],
}
free(name);
output = wayland_output_create_for_config(c, section, width,
output = wayland_output_create_for_config(b, section, width,
height, scale, x, 0);
if (!output)
goto err_outputs;
@ -2149,7 +2150,7 @@ backend_init(struct wl_display *display, int *argc, char *argv[],
if (!scale)
scale = 1;
while (count > 0) {
output = wayland_output_create(c, x, 0, width, height,
output = wayland_output_create(b, x, 0, width, height,
NULL, 0, 0, scale);
if (!output)
goto err_outputs;
@ -2160,13 +2161,13 @@ backend_init(struct wl_display *display, int *argc, char *argv[],
--count;
}
weston_compositor_add_key_binding(&c->base, KEY_F,
weston_compositor_add_key_binding(compositor, KEY_F,
MODIFIER_CTRL | MODIFIER_ALT,
fullscreen_binding, c);
fullscreen_binding, b);
return &c->base;
return 0;
err_outputs:
wayland_compositor_destroy(c);
return NULL;
wayland_backend_destroy(b);
return -1;
}

File diff suppressed because it is too large Load Diff

@ -4502,7 +4502,6 @@ timeline_key_binding_handler(struct weston_seat *seat, uint32_t time,
WL_EXPORT int
weston_compositor_init(struct weston_compositor *ec,
struct wl_display *display,
int *argc, char *argv[],
struct weston_config *config)
{
@ -4511,7 +4510,6 @@ weston_compositor_init(struct weston_compositor *ec,
struct weston_config_section *s;
ec->config = config;
ec->wl_display = display;
wl_signal_init(&ec->destroy_signal);
wl_signal_init(&ec->create_surface_signal);
wl_signal_init(&ec->activate_signal);
@ -4531,11 +4529,11 @@ weston_compositor_init(struct weston_compositor *ec,
ec->output_id_pool = 0;
if (!wl_global_create(display, &wl_compositor_interface, 3,
if (!wl_global_create(ec->wl_display, &wl_compositor_interface, 3,
ec, compositor_bind))
return -1;
if (!wl_global_create(display, &wl_subcompositor_interface, 1,
if (!wl_global_create(ec->wl_display, &wl_subcompositor_interface, 1,
ec, bind_subcompositor))
return -1;
@ -4584,7 +4582,7 @@ weston_compositor_init(struct weston_compositor *ec,
wl_data_device_manager_init(ec->wl_display);
wl_display_init_shm(display);
wl_display_init_shm(ec->wl_display);
loop = wl_display_get_event_loop(ec->wl_display);
ec->idle_source = wl_event_loop_add_timer(loop, idle_handler, ec);
@ -4900,7 +4898,7 @@ on_caught_signal(int s, siginfo_t *siginfo, void *context)
print_backtrace();
segv_compositor->restore(segv_compositor);
segv_compositor->backend->restore(segv_compositor);
raise(SIGTRAP);
}
@ -5281,10 +5279,9 @@ int main(int argc, char *argv[])
struct weston_compositor *ec;
struct wl_event_source *signals[4];
struct wl_event_loop *loop;
struct weston_compositor
*(*backend_init)(struct wl_display *display,
int *argc, char *argv[],
struct weston_config *config);
int (*backend_init)(struct weston_compositor *c,
int *argc, char *argv[],
struct weston_config *config);
int i, fd;
char *backend = NULL;
char *shell = NULL;
@ -5373,12 +5370,19 @@ int main(int argc, char *argv[])
if (!backend_init)
goto out_signals;
ec = backend_init(display, &argc, argv, config);
ec = zalloc(sizeof *ec);
if (ec == NULL) {
weston_log("fatal: failed to create compositor\n");
goto out_signals;
}
ec->wl_display = display;
if (backend_init(ec, &argc, argv, config) < 0) {
weston_log("fatal: failed to create compositor backend\n");
ret = EXIT_FAILURE;
goto out_signals;
}
catch_signals();
segv_compositor = ec;
@ -5466,7 +5470,8 @@ out:
weston_compositor_xkb_destroy(ec);
ec->destroy(ec);
ec->backend->destroy(ec);
free(ec);
out_signals:
for (i = ARRAY_LENGTH(signals) - 1; i >= 0; i--)

@ -603,6 +603,11 @@ enum weston_capability {
WESTON_CAP_VIEW_CLIP_MASK = 0x0010,
};
struct weston_backend {
void (*destroy)(struct weston_compositor *ec);
void (*restore)(struct weston_compositor *ec);
};
struct weston_compositor {
struct wl_signal destroy_signal;
@ -664,8 +669,7 @@ struct weston_compositor {
pixman_format_code_t read_format;
void (*destroy)(struct weston_compositor *ec);
void (*restore)(struct weston_compositor *ec);
struct weston_backend *backend;
struct weston_launcher *launcher;
@ -1334,7 +1338,7 @@ uint32_t
weston_compositor_get_time(void);
int
weston_compositor_init(struct weston_compositor *ec, struct wl_display *display,
weston_compositor_init(struct weston_compositor *ec,
int *argc, char *argv[], struct weston_config *config);
int
weston_compositor_set_presentation_clock(struct weston_compositor *compositor,
@ -1539,10 +1543,10 @@ weston_output_mode_switch_to_native(struct weston_output *output);
int
noop_renderer_init(struct weston_compositor *ec);
struct weston_compositor *
backend_init(struct wl_display *display, int *argc, char *argv[],
int
backend_init(struct weston_compositor *c,
int *argc, char *argv[],
struct weston_config *config);
int
module_init(struct weston_compositor *compositor,
int *argc, char *argv[]);

Loading…
Cancel
Save