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 "gl-renderer.h"
#include "presentation_timing-server-protocol.h" #include "presentation_timing-server-protocol.h"
struct fbdev_compositor { struct fbdev_backend {
struct weston_compositor base; struct weston_backend base;
struct weston_compositor *compositor;
uint32_t prev_state; uint32_t prev_state;
struct udev *udev; struct udev *udev;
@ -76,7 +77,7 @@ struct fbdev_screeninfo {
}; };
struct fbdev_output { struct fbdev_output {
struct fbdev_compositor *compositor; struct fbdev_backend *backend;
struct weston_output base; struct weston_output base;
struct weston_mode mode; struct weston_mode mode;
@ -110,10 +111,10 @@ to_fbdev_output(struct weston_output *base)
return container_of(base, struct fbdev_output, base); return container_of(base, struct fbdev_output, base);
} }
static inline struct fbdev_compositor * static inline struct fbdev_backend *
to_fbdev_compositor(struct weston_compositor *base) 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 static void
@ -182,10 +183,10 @@ static int
fbdev_output_repaint(struct weston_output *base, pixman_region32_t *damage) fbdev_output_repaint(struct weston_output *base, pixman_region32_t *damage)
{ {
struct fbdev_output *output = to_fbdev_output(base); struct fbdev_output *output = to_fbdev_output(base);
struct fbdev_compositor *fbc = output->compositor; struct fbdev_backend *fbb = output->backend;
struct weston_compositor *ec = & fbc->base; struct weston_compositor *ec = fbb->compositor;
if (fbc->use_pixman) { if (fbb->use_pixman) {
fbdev_output_repaint_pixman(base,damage); fbdev_output_repaint_pixman(base,damage);
} else { } else {
ec->renderer->repaint_output(base, damage); 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 void fbdev_output_disable(struct weston_output *base);
static int static int
fbdev_output_create(struct fbdev_compositor *compositor, fbdev_output_create(struct fbdev_backend *backend,
const char *device) const char *device)
{ {
struct fbdev_output *output; struct fbdev_output *output;
@ -499,7 +500,7 @@ fbdev_output_create(struct fbdev_compositor *compositor,
if (output == NULL) if (output == NULL)
return -1; return -1;
output->compositor = compositor; output->backend = backend;
output->device = device; output->device = device;
/* Create the frame buffer. */ /* Create the frame buffer. */
@ -508,7 +509,7 @@ fbdev_output_create(struct fbdev_compositor *compositor,
weston_log("Creating frame buffer failed.\n"); weston_log("Creating frame buffer failed.\n");
goto out_free; goto out_free;
} }
if (compositor->use_pixman) { if (backend->use_pixman) {
if (fbdev_frame_buffer_map(output, fb_fd) < 0) { if (fbdev_frame_buffer_map(output, fb_fd) < 0) {
weston_log("Mapping frame buffer failed.\n"); weston_log("Mapping frame buffer failed.\n");
goto out_free; goto out_free;
@ -536,7 +537,7 @@ fbdev_output_create(struct fbdev_compositor *compositor,
output->base.model = output->fb_info.id; output->base.model = output->fb_info.id;
output->base.name = strdup("fbdev"); output->base.name = strdup("fbdev");
section = weston_config_get_section(compositor->base.config, section = weston_config_get_section(backend->compositor->config,
"output", "name", "output", "name",
output->base.name); output->base.name);
weston_config_section_get_string(section, "transform", &s, "normal"); weston_config_section_get_string(section, "transform", &s, "normal");
@ -545,7 +546,7 @@ fbdev_output_create(struct fbdev_compositor *compositor,
s, output->base.name); s, output->base.name);
free(s); free(s);
weston_output_init(&output->base, &compositor->base, weston_output_init(&output->base, backend->compositor,
0, 0, output->fb_info.width_mm, 0, 0, output->fb_info.width_mm,
output->fb_info.height_mm, output->fb_info.height_mm,
config_transform, config_transform,
@ -566,7 +567,7 @@ fbdev_output_create(struct fbdev_compositor *compositor,
goto out_hw_surface; goto out_hw_surface;
} }
if (compositor->use_pixman) { if (backend->use_pixman) {
if (pixman_renderer_output_create(&output->base) < 0) if (pixman_renderer_output_create(&output->base) < 0)
goto out_shadow_surface; goto out_shadow_surface;
} else { } 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 = output->finish_frame_timer =
wl_event_loop_add_timer(loop, finish_frame_handler, output); 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", weston_log("fbdev output %d×%d px\n",
output->mode.width, output->mode.height); output->mode.width, output->mode.height);
@ -613,14 +614,14 @@ static void
fbdev_output_destroy(struct weston_output *base) fbdev_output_destroy(struct weston_output *base)
{ {
struct fbdev_output *output = to_fbdev_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"); weston_log("Destroying fbdev output.\n");
/* Close the frame buffer. */ /* Close the frame buffer. */
fbdev_output_disable(base); fbdev_output_disable(base);
if (compositor->use_pixman) { if (backend->use_pixman) {
if (base->renderer_state != NULL) if (base->renderer_state != NULL)
pixman_renderer_output_destroy(base); pixman_renderer_output_destroy(base);
@ -661,7 +662,7 @@ compare_screen_info (const struct fbdev_screeninfo *a,
} }
static int static int
fbdev_output_reenable(struct fbdev_compositor *compositor, fbdev_output_reenable(struct fbdev_backend *backend,
struct weston_output *base) struct weston_output *base)
{ {
struct fbdev_output *output = to_fbdev_output(base); struct fbdev_output *output = to_fbdev_output(base);
@ -696,13 +697,13 @@ fbdev_output_reenable(struct fbdev_compositor *compositor,
* are re-initialised. */ * are re-initialised. */
device = output->device; device = output->device;
fbdev_output_destroy(base); fbdev_output_destroy(base);
fbdev_output_create(compositor, device); fbdev_output_create(backend, device);
return 0; return 0;
} }
/* Map the device if it has the same details as before. */ /* 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) { if (fbdev_frame_buffer_map(output, fb_fd) < 0) {
weston_log("Mapping frame buffer failed.\n"); weston_log("Mapping frame buffer failed.\n");
goto err; goto err;
@ -722,11 +723,11 @@ static void
fbdev_output_disable(struct weston_output *base) fbdev_output_disable(struct weston_output *base)
{ {
struct fbdev_output *output = to_fbdev_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"); weston_log("Disabling fbdev output.\n");
if ( ! compositor->use_pixman) return; if ( ! backend->use_pixman) return;
if (output->hw_surface != NULL) { if (output->hw_surface != NULL) {
pixman_image_unref(output->hw_surface); pixman_image_unref(output->hw_surface);
@ -737,48 +738,49 @@ fbdev_output_disable(struct weston_output *base)
} }
static void 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. */ /* Destroy the output. */
weston_compositor_shutdown(&compositor->base); weston_compositor_shutdown(base);
/* Chain up. */ /* Chain up. */
weston_launcher_destroy(compositor->base.launcher); weston_launcher_destroy(base->launcher);
free(compositor); free(backend);
} }
static void static void
session_notify(struct wl_listener *listener, void *data) 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; struct weston_output *output;
if (compositor->base.session_active) { if (compositor->session_active) {
weston_log("entering VT\n"); 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) { wl_list_for_each(output, &compositor->output_list, link) {
fbdev_output_reenable(compositor, output); 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 { } else {
weston_log("leaving VT\n"); 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); fbdev_output_disable(output);
} }
compositor->prev_state = compositor->base.state; backend->prev_state = compositor->state;
weston_compositor_offscreen(&compositor->base); weston_compositor_offscreen(compositor);
/* If we have a repaint scheduled (from the idle handler), make /* 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 * 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. */ * pending frame callbacks. */
wl_list_for_each(output, wl_list_for_each(output,
&compositor->base.output_list, link) { &compositor->output_list, link) {
output->repaint_needed = 0; 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); weston_launcher_activate_vt(compositor->launcher, key - KEY_F1 + 1);
} }
static struct weston_compositor * static struct fbdev_backend *
fbdev_compositor_create(struct wl_display *display, int *argc, char *argv[], fbdev_backend_create(struct weston_compositor *compositor, int *argc, char *argv[],
struct weston_config *config, struct weston_config *config,
struct fbdev_parameters *param) struct fbdev_parameters *param)
{ {
struct fbdev_compositor *compositor; struct fbdev_backend *backend;
const char *seat_id = default_seat; const char *seat_id = default_seat;
uint32_t key; uint32_t key;
weston_log("initializing fbdev backend\n"); weston_log("initializing fbdev backend\n");
compositor = zalloc(sizeof *compositor); backend = zalloc(sizeof *backend);
if (compositor == NULL) if (backend == NULL)
return NULL; return NULL;
if (weston_compositor_init(&compositor->base, display, argc, argv, backend->compositor = compositor;
if (weston_compositor_init(compositor, argc, argv,
config) < 0) config) < 0)
goto out_free; goto out_free;
if (weston_compositor_set_presentation_clock_software( if (weston_compositor_set_presentation_clock_software(
&compositor->base) < 0) compositor) < 0)
goto out_compositor; goto out_compositor;
compositor->udev = udev_new(); backend->udev = udev_new();
if (compositor->udev == NULL) { if (backend->udev == NULL) {
weston_log("Failed to initialize udev context.\n"); weston_log("Failed to initialize udev context.\n");
goto out_compositor; goto out_compositor;
} }
/* Set up the TTY. */ /* Set up the TTY. */
compositor->session_listener.notify = session_notify; backend->session_listener.notify = session_notify;
wl_signal_add(&compositor->base.session_signal, wl_signal_add(&compositor->session_signal,
&compositor->session_listener); &backend->session_listener);
compositor->base.launcher = weston_launcher_connect(&compositor->base, compositor->launcher =
param->tty, "seat0", weston_launcher_connect(compositor, param->tty, "seat0", false);
false); if (!compositor->launcher) {
if (!compositor->base.launcher) {
weston_log("fatal: fbdev backend should be run " weston_log("fatal: fbdev backend should be run "
"using weston-launch binary or as root\n"); "using weston-launch binary or as root\n");
goto out_udev; goto out_udev;
} }
compositor->base.destroy = fbdev_compositor_destroy; backend->base.destroy = fbdev_backend_destroy;
compositor->base.restore = fbdev_restore; backend->base.restore = fbdev_restore;
compositor->prev_state = WESTON_COMPOSITOR_ACTIVE; backend->prev_state = WESTON_COMPOSITOR_ACTIVE;
compositor->use_pixman = !param->use_gl; backend->use_pixman = !param->use_gl;
for (key = KEY_F1; key < KEY_F9; key++) 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, MODIFIER_CTRL | MODIFIER_ALT,
switch_vt_binding, switch_vt_binding,
compositor); compositor);
if (compositor->use_pixman) { if (backend->use_pixman) {
if (pixman_renderer_init(&compositor->base) < 0) if (pixman_renderer_init(compositor) < 0)
goto out_launcher; goto out_launcher;
} else { } else {
gl_renderer = weston_load_module("gl-renderer.so", 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; goto out_launcher;
} }
if (gl_renderer->create(&compositor->base, NO_EGL_PLATFORM, if (gl_renderer->create(compositor, NO_EGL_PLATFORM,
EGL_DEFAULT_DISPLAY, EGL_DEFAULT_DISPLAY,
gl_renderer->opaque_attribs, gl_renderer->opaque_attribs,
NULL, 0) < 0) { 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; 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: out_pixman:
compositor->base.renderer->destroy(&compositor->base); compositor->renderer->destroy(compositor);
out_launcher: out_launcher:
weston_launcher_destroy(compositor->base.launcher); weston_launcher_destroy(compositor->launcher);
out_udev: out_udev:
udev_unref(compositor->udev); udev_unref(backend->udev);
out_compositor: out_compositor:
weston_compositor_shutdown(&compositor->base); weston_compositor_shutdown(compositor);
out_free: out_free:
free(compositor); free(backend);
return NULL; return NULL;
} }
WL_EXPORT struct weston_compositor * WL_EXPORT int
backend_init(struct wl_display *display, int *argc, char *argv[], backend_init(struct weston_compositor *compositor, int *argc, char *argv[],
struct weston_config *config) struct weston_config *config)
{ {
struct fbdev_backend *b;
/* TODO: Ideally, available frame buffers should be enumerated using /* TODO: Ideally, available frame buffers should be enumerated using
* udev, rather than passing a device node in as a parameter. */ * udev, rather than passing a device node in as a parameter. */
struct fbdev_parameters param = { 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); 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 "pixman-renderer.h"
#include "presentation_timing-server-protocol.h" #include "presentation_timing-server-protocol.h"
struct headless_compositor { struct headless_backend {
struct weston_compositor base; struct weston_backend base;
struct weston_compositor *compositor;
struct weston_seat fake_seat; struct weston_seat fake_seat;
bool use_pixman; bool use_pixman;
}; };
@ -99,12 +100,12 @@ static void
headless_output_destroy(struct weston_output *output_base) headless_output_destroy(struct weston_output *output_base)
{ {
struct headless_output *output = (struct headless_output *) output_base; struct headless_output *output = (struct headless_output *) output_base;
struct headless_compositor *c = struct headless_backend *b =
(struct headless_compositor *) output->base.compositor; (struct headless_backend *) output->base.compositor->backend;
wl_event_source_remove(output->finish_frame_timer); wl_event_source_remove(output->finish_frame_timer);
if (c->use_pixman) { if (b->use_pixman) {
pixman_renderer_output_destroy(&output->base); pixman_renderer_output_destroy(&output->base);
pixman_image_unref(output->image); pixman_image_unref(output->image);
free(output->image_buf); free(output->image_buf);
@ -118,9 +119,10 @@ headless_output_destroy(struct weston_output *output_base)
} }
static int static int
headless_compositor_create_output(struct headless_compositor *c, headless_backend_create_output(struct headless_backend *b,
struct headless_parameters *param) struct headless_parameters *param)
{ {
struct weston_compositor *c = b->compositor;
struct headless_output *output; struct headless_output *output;
struct wl_event_loop *loop; 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); wl_list_insert(&output->base.mode_list, &output->mode.link);
output->base.current_mode = &output->mode; 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); param->height, param->transform, 1);
output->base.make = "weston"; output->base.make = "weston";
output->base.model = "headless"; 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 = output->finish_frame_timer =
wl_event_loop_add_timer(loop, finish_frame_handler, output); 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.set_dpms = NULL;
output->base.switch_mode = NULL; output->base.switch_mode = NULL;
if (c->use_pixman) { if (b->use_pixman) {
output->image_buf = malloc(param->width * param->height * 4); output->image_buf = malloc(param->width * param->height * 4);
if (!output->image_buf) if (!output->image_buf)
return -1; return -1;
@ -173,28 +175,28 @@ headless_compositor_create_output(struct headless_compositor *c,
output->image); output->image);
} }
weston_compositor_add_output(&c->base, &output->base); weston_compositor_add_output(c, &output->base);
return 0; return 0;
} }
static int 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 -1;
return 0; return 0;
} }
static void 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 static void
@ -205,68 +207,70 @@ headless_restore(struct weston_compositor *ec)
static void static void
headless_destroy(struct weston_compositor *ec) 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); weston_compositor_shutdown(ec);
free(ec); free(b);
} }
static struct weston_compositor * static struct headless_backend *
headless_compositor_create(struct wl_display *display, headless_backend_create(struct weston_compositor *compositor,
struct headless_parameters *param, struct headless_parameters *param,
const char *display_name, const char *display_name, int *argc, char *argv[],
int *argc, char *argv[], struct weston_config *config)
struct weston_config *config)
{ {
struct headless_compositor *c; struct headless_backend *b;
c = zalloc(sizeof *c); b = zalloc(sizeof *b);
if (c == NULL) if (b == NULL)
return 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; 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; goto err_free;
if (headless_input_create(c) < 0) if (headless_input_create(b) < 0)
goto err_compositor; goto err_free;
c->base.destroy = headless_destroy; b->base.destroy = headless_destroy;
c->base.restore = headless_restore; b->base.restore = headless_restore;
c->use_pixman = param->use_pixman; b->use_pixman = param->use_pixman;
if (c->use_pixman) { if (b->use_pixman) {
pixman_renderer_init(&c->base); pixman_renderer_init(compositor);
} }
if (headless_compositor_create_output(c, param) < 0) if (headless_backend_create_output(b, param) < 0)
goto err_input; 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; goto err_input;
return &c->base; compositor->backend = &b->base;
return b;
err_input: err_input:
headless_input_destroy(c); weston_compositor_shutdown(compositor);
err_compositor: headless_input_destroy(b);
weston_compositor_shutdown(&c->base);
err_free: err_free:
free(c); free(b);
return NULL; return NULL;
} }
WL_EXPORT struct weston_compositor * WL_EXPORT int
backend_init(struct wl_display *display, int *argc, char *argv[], backend_init(struct weston_compositor *compositor,
int *argc, char *argv[],
struct weston_config *config) struct weston_config *config)
{ {
int width = 1024, height = 640; int width = 1024, height = 640;
char *display_name = NULL; char *display_name = NULL;
struct headless_parameters param = { 0, }; struct headless_parameters param = { 0, };
const char *transform = "normal"; const char *transform = "normal";
struct headless_backend *b;
const struct weston_option headless_options[] = { const struct weston_option headless_options[] = {
{ WESTON_OPTION_INTEGER, "width", 0, &width }, { 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) if (weston_parse_transform(transform, &param.transform) < 0)
weston_log("Invalid transform \"%s\"\n", transform); weston_log("Invalid transform \"%s\"\n", transform);
return headless_compositor_create(display, &param, display_name, b = headless_backend_create(compositor, &param, display_name,
argc, argv, config); 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 DEFAULT_AXIS_STEP_DISTANCE wl_fixed_from_int(10)
#define RDP_MODE_FREQ 60 * 1000 #define RDP_MODE_FREQ 60 * 1000
struct rdp_compositor_config { struct rdp_backend_config {
int width; int width;
int height; int height;
char *bind_address; char *bind_address;
@ -87,8 +87,9 @@ struct rdp_compositor_config {
struct rdp_output; struct rdp_output;
struct rdp_compositor { struct rdp_backend {
struct weston_compositor base; struct weston_backend base;
struct weston_compositor *compositor;
freerdp_listener *listener; freerdp_listener *listener;
struct wl_event_source *listener_events[MAX_FREERDP_FDS]; struct wl_event_source *listener_events[MAX_FREERDP_FDS];
@ -125,7 +126,7 @@ struct rdp_output {
struct rdp_peer_context { struct rdp_peer_context {
rdpContext _p; rdpContext _p;
struct rdp_compositor *rdpCompositor; struct rdp_backend *rdpBackend;
struct wl_event_source *events[MAX_FREERDP_FDS]; struct wl_event_source *events[MAX_FREERDP_FDS];
RFX_CONTEXT *rfx_context; RFX_CONTEXT *rfx_context;
wStream *encode_stream; wStream *encode_stream;
@ -137,7 +138,7 @@ struct rdp_peer_context {
typedef struct rdp_peer_context RdpPeerContext; typedef struct rdp_peer_context RdpPeerContext;
static void static void
rdp_compositor_config_init(struct rdp_compositor_config *config) { rdp_backend_config_init(struct rdp_backend_config *config) {
config->width = 640; config->width = 640;
config->height = 480; config->height = 480;
config->bind_address = NULL; config->bind_address = NULL;
@ -323,7 +324,7 @@ static void
rdp_peer_refresh_region(pixman_region32_t *region, freerdp_peer *peer) rdp_peer_refresh_region(pixman_region32_t *region, freerdp_peer *peer)
{ {
RdpPeerContext *context = (RdpPeerContext *)peer->context; RdpPeerContext *context = (RdpPeerContext *)peer->context;
struct rdp_output *output = context->rdpCompositor->output; struct rdp_output *output = context->rdpBackend->output;
rdpSettings *settings = peer->settings; rdpSettings *settings = peer->settings;
if (settings->RemoteFxCodec) if (settings->RemoteFxCodec)
@ -467,7 +468,7 @@ rdp_switch_mode(struct weston_output *output, struct weston_mode *target_mode) {
} }
static int 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 rdp_output *output;
struct wl_event_loop *loop; 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; goto out_free_output;
output->base.current_mode = output->base.native_mode = currentMode; 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); WL_OUTPUT_TRANSFORM_NORMAL, 1);
output->base.make = "weston"; 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) if (pixman_renderer_output_create(&output->base) < 0)
goto out_shadow_surface; 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->finish_frame_timer = wl_event_loop_add_timer(loop, finish_frame_handler, output);
output->base.start_repaint_loop = rdp_output_start_repaint_loop; 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_backlight = NULL;
output->base.set_dpms = NULL; output->base.set_dpms = NULL;
output->base.switch_mode = rdp_switch_mode; 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; return 0;
out_shadow_surface: out_shadow_surface:
@ -560,7 +561,7 @@ int rdp_listener_activity(int fd, uint32_t mask, void *data) {
} }
static 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 i, fd;
int rcount = 0; int rcount = 0;
void* rfds[MAX_FREERDP_FDS]; void* rfds[MAX_FREERDP_FDS];
@ -571,15 +572,15 @@ int rdp_implant_listener(struct rdp_compositor *c, freerdp_listener* instance) {
return -1; 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++) { for (i = 0; i < rcount; i++) {
fd = (int)(long)(rfds[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); rdp_listener_activity, instance);
} }
for( ; i < MAX_FREERDP_FDS; i++) for( ; i < MAX_FREERDP_FDS; i++)
c->listener_events[i] = 0; b->listener_events[i] = 0;
return 0; return 0;
} }
@ -793,7 +794,7 @@ static BOOL
xf_peer_activate(freerdp_peer* client) xf_peer_activate(freerdp_peer* client)
{ {
RdpPeerContext *peerCtx; RdpPeerContext *peerCtx;
struct rdp_compositor *c; struct rdp_backend *b;
struct rdp_output *output; struct rdp_output *output;
rdpSettings *settings; rdpSettings *settings;
rdpPointerUpdate *pointer; rdpPointerUpdate *pointer;
@ -808,9 +809,9 @@ xf_peer_activate(freerdp_peer* client)
peerCtx = (RdpPeerContext *)client->context; peerCtx = (RdpPeerContext *)client->context;
c = peerCtx->rdpCompositor; b = peerCtx->rdpBackend;
peersItem = &peerCtx->item; peersItem = &peerCtx->item;
output = c->output; output = b->output;
settings = client->settings; settings = client->settings;
if (!settings->SurfaceCommandsEnabled) { if (!settings->SurfaceCommandsEnabled) {
@ -821,7 +822,7 @@ xf_peer_activate(freerdp_peer* client)
if (output->base.width != (int)settings->DesktopWidth || if (output->base.width != (int)settings->DesktopWidth ||
output->base.height != (int)settings->DesktopHeight) 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 */ /* RDP peers don't dictate their resolution to weston */
if (!settings->DesktopResize) { if (!settings->DesktopResize) {
/* peer does not support desktop resize */ /* peer does not support desktop resize */
@ -891,7 +892,7 @@ xf_peer_activate(freerdp_peer* client)
else else
snprintf(seat_name, sizeof(seat_name), "RDP peer @%s", settings->ClientAddress); 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_keyboard(&peersItem->seat, keymap);
weston_seat_init_pointer(&peersItem->seat); weston_seat_init_pointer(&peersItem->seat);
@ -929,7 +930,7 @@ xf_mouseEvent(rdpInput *input, UINT16 flags, UINT16 x, UINT16 y) {
uint32_t button = 0; uint32_t button = 0;
if (flags & PTR_FLAGS_MOVE) { if (flags & PTR_FLAGS_MOVE) {
output = peerContext->rdpCompositor->output; output = peerContext->rdpBackend->output;
if (x < output->base.width && y < output->base.height) { if (x < output->base.width && y < output->base.height) {
wl_x = wl_fixed_from_int((int)x); wl_x = wl_fixed_from_int((int)x);
wl_y = wl_fixed_from_int((int)y); 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; RdpPeerContext *peerContext = (RdpPeerContext *)input->context;
struct rdp_output *output; struct rdp_output *output;
output = peerContext->rdpCompositor->output; output = peerContext->rdpBackend->output;
if (x < output->base.width && y < output->base.height) { if (x < output->base.width && y < output->base.height) {
wl_x = wl_fixed_from_int((int)x); wl_x = wl_fixed_from_int((int)x);
wl_y = wl_fixed_from_int((int)y); 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; freerdp_peer *client = input->context->peer;
RdpPeerContext *peerCtx = (RdpPeerContext *)input->context; RdpPeerContext *peerCtx = (RdpPeerContext *)input->context;
struct rdp_output *output = peerCtx->rdpCompositor->output; struct rdp_output *output = peerCtx->rdpBackend->output;
pixman_box32_t box; pixman_box32_t box;
pixman_region32_t damage; pixman_region32_t damage;
@ -1071,7 +1072,7 @@ xf_suppress_output(rdpContext *context, BYTE allow, RECTANGLE_16 *area) {
} }
static int 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; int rcount = 0;
void *rfds[MAX_FREERDP_FDS]; void *rfds[MAX_FREERDP_FDS];
@ -1087,17 +1088,17 @@ rdp_peer_init(freerdp_peer *client, struct rdp_compositor *c)
freerdp_peer_context_new(client); freerdp_peer_context_new(client);
peerCtx = (RdpPeerContext *) client->context; peerCtx = (RdpPeerContext *) client->context;
peerCtx->rdpCompositor = c; peerCtx->rdpBackend = b;
client->Initialize(client); client->Initialize(client);
settings = client->settings; settings = client->settings;
/* configure security settings */ /* configure security settings */
if (c->rdp_key) if (b->rdp_key)
settings->RdpKeyFile = strdup(c->rdp_key); settings->RdpKeyFile = strdup(b->rdp_key);
if (c->tls_enabled) { if (b->tls_enabled) {
settings->CertificateFile = strdup( c->server_cert); settings->CertificateFile = strdup(b->server_cert);
settings->PrivateKeyFile = strdup(c->server_key); settings->PrivateKeyFile = strdup(b->server_key);
} else { } else {
settings->TlsSecurity = FALSE; settings->TlsSecurity = FALSE;
} }
@ -1130,7 +1131,7 @@ rdp_peer_init(freerdp_peer *client, struct rdp_compositor *c)
return -1; 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++) { for(i = 0; i < rcount; i++) {
fd = (int)(long)(rfds[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++) for ( ; i < MAX_FREERDP_FDS; i++)
peerCtx->events[i] = 0; peerCtx->events[i] = 0;
wl_list_insert(&c->output->peers, &peerCtx->item.link); wl_list_insert(&b->output->peers, &peerCtx->item.link);
return 0; return 0;
} }
@ -1148,8 +1149,8 @@ rdp_peer_init(freerdp_peer *client, struct rdp_compositor *c)
static FREERDP_CB_RET_TYPE static FREERDP_CB_RET_TYPE
rdp_incoming_peer(freerdp_listener *instance, freerdp_peer *client) rdp_incoming_peer(freerdp_listener *instance, freerdp_peer *client)
{ {
struct rdp_compositor *c = (struct rdp_compositor *)instance->param4; struct rdp_backend *b = (struct rdp_backend *)instance->param4;
if (rdp_peer_init(client, c) < 0) { if (rdp_peer_init(client, b) < 0) {
weston_log("error when treating incoming peer"); weston_log("error when treating incoming peer");
FREERDP_CB_RETURN(FALSE); FREERDP_CB_RETURN(FALSE);
} }
@ -1157,58 +1158,59 @@ rdp_incoming_peer(freerdp_listener *instance, freerdp_peer *client)
FREERDP_CB_RETURN(TRUE); FREERDP_CB_RETURN(TRUE);
} }
static struct weston_compositor * static struct rdp_backend *
rdp_compositor_create(struct wl_display *display, rdp_backend_create(struct weston_compositor *compositor,
struct rdp_compositor_config *config, struct rdp_backend_config *config,
int *argc, char *argv[], struct weston_config *wconfig) int *argc, char *argv[], struct weston_config *wconfig)
{ {
struct rdp_compositor *c; struct rdp_backend *b;
char *fd_str; char *fd_str;
int fd; int fd;
c = zalloc(sizeof *c); b = zalloc(sizeof *b);
if (c == NULL) if (b == NULL)
return 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; goto err_free;
c->base.destroy = rdp_destroy; b->base.destroy = rdp_destroy;
c->base.restore = rdp_restore; b->base.restore = rdp_restore;
c->rdp_key = config->rdp_key ? strdup(config->rdp_key) : NULL; b->rdp_key = config->rdp_key ? strdup(config->rdp_key) : NULL;
c->no_clients_resize = config->no_clients_resize; b->no_clients_resize = config->no_clients_resize;
/* activate TLS only if certificate/key are available */ /* activate TLS only if certificate/key are available */
if (config->server_cert && config->server_key) { if (config->server_cert && config->server_key) {
weston_log("TLS support activated\n"); weston_log("TLS support activated\n");
c->server_cert = strdup(config->server_cert); b->server_cert = strdup(config->server_cert);
c->server_key = strdup(config->server_key); b->server_key = strdup(config->server_key);
if (!c->server_cert || !c->server_key) if (!b->server_cert || !b->server_key)
goto err_free_strings; 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; goto err_compositor;
if (pixman_renderer_init(&c->base) < 0) if (pixman_renderer_init(compositor) < 0)
goto err_compositor; 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; goto err_compositor;
c->base.capabilities |= WESTON_CAP_ARBITRARY_MODES; compositor->capabilities |= WESTON_CAP_ARBITRARY_MODES;
if(!config->env_socket) { if(!config->env_socket) {
c->listener = freerdp_listener_new(); b->listener = freerdp_listener_new();
c->listener->PeerAccepted = rdp_incoming_peer; b->listener->PeerAccepted = rdp_incoming_peer;
c->listener->param4 = c; b->listener->param4 = b;
if (!c->listener->Open(c->listener, config->bind_address, config->port)) { if (!b->listener->Open(b->listener, config->bind_address, config->port)) {
weston_log("unable to bind rdp socket\n"); weston_log("unable to bind rdp socket\n");
goto err_listener; goto err_listener;
} }
if (rdp_implant_listener(c, c->listener) < 0) if (rdp_implant_listener(b, b->listener) < 0)
goto err_compositor; goto err_compositor;
} else { } else {
/* get the socket from RDP_FD var */ /* get the socket from RDP_FD var */
@ -1219,36 +1221,38 @@ rdp_compositor_create(struct wl_display *display,
} }
fd = strtoul(fd_str, NULL, 10); 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; goto err_output;
} }
return &c->base; compositor->backend = &b->base;
return b;
err_listener: err_listener:
freerdp_listener_free(c->listener); freerdp_listener_free(b->listener);
err_output: err_output:
weston_output_destroy(&c->output->base); weston_output_destroy(&b->output->base);
err_compositor: err_compositor:
weston_compositor_shutdown(&c->base); weston_compositor_shutdown(compositor);
err_free_strings: err_free_strings:
if (c->rdp_key) if (b->rdp_key)
free(c->rdp_key); free(b->rdp_key);
if (c->server_cert) if (b->server_cert)
free(c->server_cert); free(b->server_cert);
if (c->server_key) if (b->server_key)
free(c->server_key); free(b->server_key);
err_free: err_free:
free(c); free(b);
return NULL; return NULL;
} }
WL_EXPORT struct weston_compositor * WL_EXPORT int
backend_init(struct wl_display *display, int *argc, char *argv[], backend_init(struct weston_compositor *compositor, int *argc, char *argv[],
struct weston_config *wconfig) struct weston_config *wconfig)
{ {
struct rdp_compositor_config config; struct rdp_backend *b;
rdp_compositor_config_init(&config); struct rdp_backend_config config;
rdp_backend_config_init(&config);
int major, minor, revision; int major, minor, revision;
freerdp_get_version(&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 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) #define DBG(...) do {} while (0)
#endif #endif
struct rpi_compositor; struct rpi_backend;
struct rpi_output; struct rpi_output;
struct rpi_flippipe { struct rpi_flippipe {
@ -71,7 +71,7 @@ struct rpi_flippipe {
}; };
struct rpi_output { struct rpi_output {
struct rpi_compositor *compositor; struct rpi_backend *backend;
struct weston_output base; struct weston_output base;
int single_buffer; int single_buffer;
@ -90,8 +90,9 @@ struct rpi_seat {
char *seat_id; char *seat_id;
}; };
struct rpi_compositor { struct rpi_backend {
struct weston_compositor base; struct weston_backend base;
struct weston_compositor *compositor;
uint32_t prev_state; uint32_t prev_state;
struct udev *udev; struct udev *udev;
@ -113,10 +114,10 @@ to_rpi_seat(struct weston_seat *base)
return container_of(base, struct rpi_seat, base); return container_of(base, struct rpi_seat, base);
} }
static inline struct rpi_compositor * static inline struct rpi_backend *
to_rpi_compositor(struct weston_compositor *base) 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 static void
@ -191,9 +192,9 @@ rpi_flippipe_init(struct rpi_flippipe *flippipe, struct rpi_output *output)
flippipe->readfd = fd[0]; flippipe->readfd = fd[0];
flippipe->writefd = fd[1]; 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, flippipe->source = wl_event_loop_add_fd(loop, flippipe->readfd,
WL_EVENT_READABLE, WL_EVENT_READABLE,
rpi_flippipe_handler, output); rpi_flippipe_handler, output);
@ -229,8 +230,8 @@ static int
rpi_output_repaint(struct weston_output *base, pixman_region32_t *damage) rpi_output_repaint(struct weston_output *base, pixman_region32_t *damage)
{ {
struct rpi_output *output = to_rpi_output(base); struct rpi_output *output = to_rpi_output(base);
struct rpi_compositor *compositor = output->compositor; struct weston_compositor *compositor = output->backend->compositor;
struct weston_plane *primary_plane = &compositor->base.primary_plane; struct weston_plane *primary_plane = &compositor->primary_plane;
DISPMANX_UPDATE_HANDLE_T update; DISPMANX_UPDATE_HANDLE_T update;
DBG("frame update start\n"); 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); update = vc_dispmanx_update_start(1);
rpi_renderer_set_update_handle(&output->base, update); 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, pixman_region32_subtract(&primary_plane->damage,
&primary_plane->damage, damage); &primary_plane->damage, damage);
@ -291,7 +292,7 @@ rpi_output_destroy(struct weston_output *base)
} }
static int 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; struct rpi_output *output;
DISPMANX_MODEINFO_T modeinfo; DISPMANX_MODEINFO_T modeinfo;
@ -302,8 +303,8 @@ rpi_output_create(struct rpi_compositor *compositor, uint32_t transform)
if (output == NULL) if (output == NULL)
return -1; return -1;
output->compositor = compositor; output->backend = backend;
output->single_buffer = compositor->single_buffer; output->single_buffer = backend->single_buffer;
if (rpi_flippipe_init(&output->flippipe, output) < 0) { if (rpi_flippipe_init(&output->flippipe, output) < 0) {
weston_log("Creating message pipe failed.\n"); 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_width = modeinfo.width * (25.4f / 96.0f);
mm_height = modeinfo.height * (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), 0, 0, round(mm_width), round(mm_height),
transform, 1); transform, 1);
if (rpi_renderer_output_create(&output->base, output->display) < 0) if (rpi_renderer_output_create(&output->base, output->display) < 0)
goto out_output; 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", weston_log("Raspberry Pi HDMI output %dx%d px\n",
output->mode.width, output->mode.height); output->mode.width, output->mode.height);
@ -391,38 +392,39 @@ out_free:
} }
static void 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 */ /* 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(); bcm_host_deinit();
free(compositor); free(backend);
} }
static void static void
session_notify(struct wl_listener *listener, void *data) 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; struct weston_output *output;
if (compositor->base.session_active) { if (compositor->session_active) {
weston_log("activating session\n"); weston_log("activating session\n");
compositor->base.state = compositor->prev_state; compositor->state = backend->prev_state;
weston_compositor_damage_all(&compositor->base); weston_compositor_damage_all(compositor);
udev_input_enable(&compositor->input); udev_input_enable(&backend->input);
} else { } else {
weston_log("deactivating session\n"); weston_log("deactivating session\n");
udev_input_disable(&compositor->input); udev_input_disable(&backend->input);
compositor->prev_state = compositor->base.state; backend->prev_state = compositor->state;
weston_compositor_offscreen(&compositor->base); weston_compositor_offscreen(compositor);
/* If we have a repaint scheduled (either from a /* If we have a repaint scheduled (either from a
* pending pageflip or the idle handler), make sure we * pending pageflip or the idle handler), make sure we
@ -433,7 +435,7 @@ session_notify(struct wl_listener *listener, void *data)
* pending frame callbacks. */ * pending frame callbacks. */
wl_list_for_each(output, wl_list_for_each(output,
&compositor->base.output_list, link) { &compositor->output_list, link) {
output->repaint_needed = 0; output->repaint_needed = 0;
} }
}; };
@ -459,56 +461,56 @@ struct rpi_parameters {
uint32_t output_transform; uint32_t output_transform;
}; };
static struct weston_compositor * static struct rpi_backend *
rpi_compositor_create(struct wl_display *display, int *argc, char *argv[], rpi_backend_create(struct weston_compositor *compositor,
struct weston_config *config, struct rpi_parameters *param,
struct rpi_parameters *param) int *argc, char *argv[],
struct weston_config *config)
{ {
struct rpi_compositor *compositor; struct rpi_backend *backend;
uint32_t key; uint32_t key;
weston_log("initializing Raspberry Pi backend\n"); weston_log("initializing Raspberry Pi backend\n");
compositor = zalloc(sizeof *compositor); backend = zalloc(sizeof *backend);
if (compositor == NULL) if (backend == NULL)
return NULL; return NULL;
if (weston_compositor_init(&compositor->base, display, argc, argv, if (weston_compositor_init(compositor, argc, argv,
config) < 0) config) < 0)
goto out_free; goto out_free;
if (weston_compositor_set_presentation_clock_software( if (weston_compositor_set_presentation_clock_software(
&compositor->base) < 0) compositor) < 0)
goto out_compositor; goto out_compositor;
compositor->udev = udev_new(); backend->udev = udev_new();
if (compositor->udev == NULL) { if (backend->udev == NULL) {
weston_log("Failed to initialize udev context.\n"); weston_log("Failed to initialize udev context.\n");
goto out_compositor; goto out_compositor;
} }
compositor->session_listener.notify = session_notify; backend->session_listener.notify = session_notify;
wl_signal_add(&compositor->base.session_signal, wl_signal_add(&compositor->session_signal,
&compositor ->session_listener); &backend->session_listener);
compositor->base.launcher = weston_launcher_connect(&compositor->base, compositor->launcher =
param->tty, "seat0", weston_launcher_connect(compositor, param->tty, "seat0", false);
false); if (!compositor->launcher) {
if (!compositor->base.launcher) {
weston_log("Failed to initialize tty.\n"); weston_log("Failed to initialize tty.\n");
goto out_udev; goto out_udev;
} }
compositor->base.destroy = rpi_compositor_destroy; backend->base.destroy = rpi_backend_destroy;
compositor->base.restore = rpi_restore; backend->base.restore = rpi_restore;
compositor->prev_state = WESTON_COMPOSITOR_ACTIVE; backend->prev_state = WESTON_COMPOSITOR_ACTIVE;
compositor->single_buffer = param->renderer.single_buffer; backend->single_buffer = param->renderer.single_buffer;
weston_log("Dispmanx planes are %s buffered.\n", 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++) 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, MODIFIER_CTRL | MODIFIER_ALT,
switch_vt_binding, compositor); switch_vt_binding, compositor);
@ -521,45 +523,47 @@ rpi_compositor_create(struct wl_display *display, int *argc, char *argv[],
*/ */
bcm_host_init(); bcm_host_init();
if (rpi_renderer_create(&compositor->base, &param->renderer) < 0) if (rpi_renderer_create(compositor, &param->renderer) < 0)
goto out_launcher; goto out_launcher;
if (rpi_output_create(compositor, param->output_transform) < 0) if (rpi_output_create(backend, param->output_transform) < 0)
goto out_renderer; goto out_renderer;
if (udev_input_init(&compositor->input, if (udev_input_init(&backend->input,
&compositor->base, compositor,
compositor->udev, "seat0") != 0) { backend->udev, "seat0") != 0) {
weston_log("Failed to initialize udev input.\n"); weston_log("Failed to initialize udev input.\n");
goto out_renderer; goto out_renderer;
} }
return &compositor->base; return backend;
out_renderer: out_renderer:
compositor->base.renderer->destroy(&compositor->base); compositor->renderer->destroy(compositor);
out_launcher: out_launcher:
weston_launcher_destroy(compositor->base.launcher); weston_launcher_destroy(compositor->launcher);
out_udev: out_udev:
udev_unref(compositor->udev); udev_unref(backend->udev);
out_compositor: out_compositor:
weston_compositor_shutdown(&compositor->base); weston_compositor_shutdown(compositor);
out_free: out_free:
bcm_host_deinit(); bcm_host_deinit();
free(compositor); free(backend);
return NULL; return NULL;
} }
WL_EXPORT struct weston_compositor * WL_EXPORT int
backend_init(struct wl_display *display, int *argc, char *argv[], backend_init(struct weston_compositor *compositor,
int *argc, char *argv[],
struct weston_config *config) struct weston_config *config)
{ {
const char *transform = "normal"; const char *transform = "normal";
struct rpi_backend *b;
struct rpi_parameters param = { struct rpi_parameters param = {
.tty = 0, /* default to current tty */ .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) if (weston_parse_transform(transform, &param.output_transform) < 0)
weston_log("invalid transform \"%s\"\n", transform); 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" #define WINDOW_TITLE "Weston Compositor"
struct wayland_compositor { struct wayland_backend {
struct weston_compositor base; struct weston_backend base;
struct weston_compositor *compositor;
struct { struct {
struct wl_display *wl_display; struct wl_display *wl_display;
@ -157,7 +158,7 @@ struct wayland_shm_buffer {
struct wayland_input { struct wayland_input {
struct weston_seat base; struct weston_seat base;
struct wayland_compositor *compositor; struct wayland_backend *backend;
struct wl_list link; struct wl_list link;
struct { struct {
@ -217,9 +218,9 @@ static const struct wl_buffer_listener buffer_listener = {
static struct wayland_shm_buffer * static struct wayland_shm_buffer *
wayland_output_get_shm_buffer(struct wayland_output *output) wayland_output_get_shm_buffer(struct wayland_output *output)
{ {
struct wayland_compositor *c = struct wayland_backend *b =
(struct wayland_compositor *) output->base.compositor; (struct wayland_backend *) output->base.compositor->backend;
struct wl_shm *shm = c->parent.shm; struct wl_shm *shm = b->parent.shm;
struct wayland_shm_buffer *sb; struct wayland_shm_buffer *sb;
struct wl_shm_pool *pool; struct wl_shm_pool *pool;
@ -424,8 +425,8 @@ static void
wayland_output_start_repaint_loop(struct weston_output *output_base) wayland_output_start_repaint_loop(struct weston_output *output_base)
{ {
struct wayland_output *output = (struct wayland_output *) output_base; struct wayland_output *output = (struct wayland_output *) output_base;
struct wayland_compositor *wc = struct wayland_backend *wb =
(struct wayland_compositor *)output->base.compositor; (struct wayland_backend *)output->base.compositor->backend;
struct wl_callback *callback; struct wl_callback *callback;
/* If this is the initial frame, we need to attach a buffer so that /* 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); callback = wl_surface_frame(output->parent.surface);
wl_callback_add_listener(callback, &frame_listener, output); wl_callback_add_listener(callback, &frame_listener, output);
wl_surface_commit(output->parent.surface); wl_surface_commit(output->parent.surface);
wl_display_flush(wc->parent.wl_display); wl_display_flush(wb->parent.wl_display);
} }
static int static int
@ -557,8 +558,8 @@ wayland_output_repaint_pixman(struct weston_output *output_base,
pixman_region32_t *damage) pixman_region32_t *damage)
{ {
struct wayland_output *output = (struct wayland_output *) output_base; struct wayland_output *output = (struct wayland_output *) output_base;
struct wayland_compositor *c = struct wayland_backend *b =
(struct wayland_compositor *)output->base.compositor; (struct wayland_backend *)output->base.compositor->backend;
struct wl_callback *callback; struct wl_callback *callback;
struct wayland_shm_buffer *sb; struct wayland_shm_buffer *sb;
@ -575,21 +576,21 @@ wayland_output_repaint_pixman(struct weston_output *output_base,
wayland_output_update_shm_border(sb); wayland_output_update_shm_border(sb);
pixman_renderer_output_set_buffer(output_base, sb->pm_image); 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); wayland_shm_buffer_attach(sb);
callback = wl_surface_frame(output->parent.surface); callback = wl_surface_frame(output->parent.surface);
wl_callback_add_listener(callback, &frame_listener, output); wl_callback_add_listener(callback, &frame_listener, output);
wl_surface_commit(output->parent.surface); 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_fini(&sb->damage);
pixman_region32_init(&sb->damage); pixman_region32_init(&sb->damage);
sb->frame_damaged = 0; sb->frame_damaged = 0;
pixman_region32_subtract(&c->base.primary_plane.damage, pixman_region32_subtract(&b->compositor->primary_plane.damage,
&c->base.primary_plane.damage, damage); &b->compositor->primary_plane.damage, damage);
return 0; return 0;
} }
@ -597,10 +598,10 @@ static void
wayland_output_destroy(struct weston_output *output_base) wayland_output_destroy(struct weston_output *output_base)
{ {
struct wayland_output *output = (struct wayland_output *) output_base; struct wayland_output *output = (struct wayland_output *) output_base;
struct wayland_compositor *c = struct wayland_backend *b =
(struct wayland_compositor *) output->base.compositor; (struct wayland_backend *) output->base.compositor->backend;
if (c->use_pixman) { if (b->use_pixman) {
pixman_renderer_output_destroy(output_base); pixman_renderer_output_destroy(output_base);
} else { } else {
gl_renderer->output_destroy(output_base); gl_renderer->output_destroy(output_base);
@ -672,8 +673,8 @@ wayland_output_init_pixman_renderer(struct wayland_output *output)
static void static void
wayland_output_resize_surface(struct wayland_output *output) wayland_output_resize_surface(struct wayland_output *output)
{ {
struct wayland_compositor *c = struct wayland_backend *b =
(struct wayland_compositor *)output->base.compositor; (struct wayland_backend *)output->base.compositor->backend;
struct wayland_shm_buffer *buffer, *next; struct wayland_shm_buffer *buffer, *next;
int32_t ix, iy, iwidth, iheight; int32_t ix, iy, iwidth, iheight;
int32_t width, height; int32_t width, height;
@ -686,13 +687,13 @@ wayland_output_resize_surface(struct wayland_output *output)
frame_resize_inside(output->frame, width, height); frame_resize_inside(output->frame, width, height);
frame_input_rect(output->frame, &ix, &iy, &iwidth, &iheight); 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_region_add(region, ix, iy, iwidth, iheight);
wl_surface_set_input_region(output->parent.surface, region); wl_surface_set_input_region(output->parent.surface, region);
wl_region_destroy(region); wl_region_destroy(region);
frame_opaque_rect(output->frame, &ix, &iy, &iwidth, &iheight); 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_region_add(region, ix, iy, iwidth, iheight);
wl_surface_set_opaque_region(output->parent.surface, region); wl_surface_set_opaque_region(output->parent.surface, region);
wl_region_destroy(region); wl_region_destroy(region);
@ -700,12 +701,12 @@ wayland_output_resize_surface(struct wayland_output *output)
width = frame_width(output->frame); width = frame_width(output->frame);
height = frame_height(output->frame); height = frame_height(output->frame);
} else { } 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_region_add(region, 0, 0, width, height);
wl_surface_set_input_region(output->parent.surface, region); wl_surface_set_input_region(output->parent.surface, region);
wl_region_destroy(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_region_add(region, 0, 0, width, height);
wl_surface_set_opaque_region(output->parent.surface, region); wl_surface_set_opaque_region(output->parent.surface, region);
wl_region_destroy(region); wl_region_destroy(region);
@ -749,8 +750,8 @@ wayland_output_resize_surface(struct wayland_output *output)
static int static int
wayland_output_set_windowed(struct wayland_output *output) wayland_output_set_windowed(struct wayland_output *output)
{ {
struct wayland_compositor *c = struct wayland_backend *b =
(struct wayland_compositor *)output->base.compositor; (struct wayland_backend *)output->base.compositor->backend;
int tlen; int tlen;
char *title; char *title;
@ -768,14 +769,14 @@ wayland_output_set_windowed(struct wayland_output *output)
title = strdup(WINDOW_TITLE); title = strdup(WINDOW_TITLE);
} }
if (!c->theme) { if (!b->theme) {
c->theme = theme_create(); b->theme = theme_create();
if (!c->theme) { if (!b->theme) {
free(title); free(title);
return -1; return -1;
} }
} }
output->frame = frame_create(c->theme, 100, 100, output->frame = frame_create(b->theme, 100, 100,
FRAME_BUTTON_CLOSE, title); FRAME_BUTTON_CLOSE, title);
free(title); free(title);
if (!output->frame) if (!output->frame)
@ -796,8 +797,8 @@ wayland_output_set_fullscreen(struct wayland_output *output,
enum wl_shell_surface_fullscreen_method method, enum wl_shell_surface_fullscreen_method method,
uint32_t framerate, struct wl_output *target) uint32_t framerate, struct wl_output *target)
{ {
struct wayland_compositor *c = struct wayland_backend *b =
(struct wayland_compositor *)output->base.compositor; (struct wayland_backend *)output->base.compositor->backend;
if (output->frame) { if (output->frame) {
frame_destroy(output->frame); frame_destroy(output->frame);
@ -809,8 +810,8 @@ wayland_output_set_fullscreen(struct wayland_output *output,
if (output->parent.shell_surface) { if (output->parent.shell_surface) {
wl_shell_surface_set_fullscreen(output->parent.shell_surface, wl_shell_surface_set_fullscreen(output->parent.shell_surface,
method, framerate, target); method, framerate, target);
} else if (c->parent.fshell) { } else if (b->parent.fshell) {
_wl_fullscreen_shell_present_surface(c->parent.fshell, _wl_fullscreen_shell_present_surface(b->parent.fshell,
output->parent.surface, output->parent.surface,
method, target); method, target);
} }
@ -888,7 +889,7 @@ wayland_output_switch_mode(struct weston_output *output_base,
struct weston_mode *mode) struct weston_mode *mode)
{ {
struct wayland_output *output = (struct wayland_output *) output_base; struct wayland_output *output = (struct wayland_output *) output_base;
struct wayland_compositor *c; struct wayland_backend *b;
struct wl_surface *old_surface; struct wl_surface *old_surface;
struct weston_mode *old_mode; struct weston_mode *old_mode;
struct _wl_fullscreen_shell_mode_feedback *mode_feedback; struct _wl_fullscreen_shell_mode_feedback *mode_feedback;
@ -905,9 +906,9 @@ wayland_output_switch_mode(struct weston_output *output_base,
return -1; 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; return -1;
mode = wayland_output_choose_mode(output, mode); 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; old_surface = output->parent.surface;
output->base.current_mode = mode; output->base.current_mode = mode;
output->parent.surface = 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); wl_surface_set_user_data(output->parent.surface, output);
/* Blow the old buffers because we changed size/surfaces */ /* Blow the old buffers because we changed size/surfaces */
wayland_output_resize_surface(output); wayland_output_resize_surface(output);
mode_feedback = 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.surface,
output->parent.output, output->parent.output,
mode->refresh); mode->refresh);
@ -942,7 +943,7 @@ wayland_output_switch_mode(struct weston_output *output_base,
mode_status = MODE_STATUS_UNKNOWN; mode_status = MODE_STATUS_UNKNOWN;
while (mode_status == MODE_STATUS_UNKNOWN && ret >= 0) 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); _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; old_mode->flags &= ~WL_OUTPUT_MODE_CURRENT;
output->base.current_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); pixman_renderer_output_destroy(output_base);
if (wayland_output_init_pixman_renderer(output) < 0) if (wayland_output_init_pixman_renderer(output) < 0)
goto err_output; goto err_output;
@ -980,7 +981,7 @@ err_output:
} }
static struct wayland_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, int width, int height, const char *name, int fullscreen,
uint32_t transform, int32_t scale) 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_height = height * scale;
output->parent.surface = output->parent.surface =
wl_compositor_create_surface(c->parent.compositor); wl_compositor_create_surface(b->parent.compositor);
if (!output->parent.surface) if (!output->parent.surface)
goto err_name; goto err_name;
wl_surface_set_user_data(output->parent.surface, output); wl_surface_set_user_data(output->parent.surface, output);
output->parent.draw_initial_frame = 1; output->parent.draw_initial_frame = 1;
if (c->parent.shell) { if (b->parent.shell) {
output->parent.shell_surface = output->parent.shell_surface =
wl_shell_get_shell_surface(c->parent.shell, wl_shell_get_shell_surface(b->parent.shell,
output->parent.surface); output->parent.surface);
if (!output->parent.shell_surface) if (!output->parent.shell_surface)
goto err_surface; goto err_surface;
@ -1019,10 +1020,10 @@ wayland_output_create(struct wayland_compositor *c, int x, int y,
&shell_surface_listener, output); &shell_surface_listener, output);
} }
if (fullscreen && c->parent.shell) { if (fullscreen && b->parent.shell) {
wl_shell_surface_set_fullscreen(output->parent.shell_surface, wl_shell_surface_set_fullscreen(output->parent.shell_surface,
0, 0, NULL); 0, 0, NULL);
wl_display_roundtrip(c->parent.wl_display); wl_display_roundtrip(b->parent.wl_display);
if (!width) if (!width)
output_width = output->parent.configure_width; output_width = output->parent.configure_width;
if (!height) 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.buffers);
wl_list_init(&output->shm.free_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); transform, scale);
if (c->use_pixman) { if (b->use_pixman) {
if (wayland_output_init_pixman_renderer(output) < 0) if (wayland_output_init_pixman_renderer(output) < 0)
goto err_output; goto err_output;
output->base.repaint = wayland_output_repaint_pixman; 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.set_dpms = NULL;
output->base.switch_mode = wayland_output_switch_mode; 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; return output;
@ -1082,7 +1083,7 @@ err_name:
} }
static struct wayland_output * 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, struct weston_config_section *config_section,
int option_width, int option_height, int option_width, int option_height,
int option_scale, int32_t x, int32_t y) int option_scale, int32_t x, int32_t y)
@ -1133,7 +1134,7 @@ wayland_output_create_for_config(struct wayland_compositor *c,
t, name); t, name);
free(t); 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); transform, scale);
free(name); free(name);
@ -1141,7 +1142,7 @@ wayland_output_create_for_config(struct wayland_compositor *c,
} }
static struct wayland_output * 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_parent_output *poutput)
{ {
struct wayland_output *output; struct wayland_output *output;
@ -1160,15 +1161,15 @@ wayland_output_create_for_parent_output(struct wayland_compositor *c,
return NULL; return NULL;
} }
if (!wl_list_empty(&c->base.output_list)) { if (!wl_list_empty(&b->compositor->output_list)) {
output = container_of(c->base.output_list.prev, output = container_of(b->compositor->output_list.prev,
struct wayland_output, base.link); struct wayland_output, base.link);
x = output->base.x + output->base.current_mode->width; x = output->base.x + output->base.current_mode->width;
} else { } else {
x = 0; 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, NULL, 0,
WL_OUTPUT_TRANSFORM_NORMAL, 1); WL_OUTPUT_TRANSFORM_NORMAL, 1);
if (!output) 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_set_fullscreen(output->parent.shell_surface,
WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER, WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER,
mode->refresh, poutput->global); mode->refresh, poutput->global);
} else if (c->parent.fshell) { } else if (b->parent.fshell) {
_wl_fullscreen_shell_present_surface(c->parent.fshell, _wl_fullscreen_shell_present_surface(b->parent.fshell,
output->parent.surface, output->parent.surface,
_WL_FULLSCREEN_SHELL_PRESENT_METHOD_CENTER, _WL_FULLSCREEN_SHELL_PRESENT_METHOD_CENTER,
poutput->global); poutput->global);
_wl_fullscreen_shell_mode_feedback_destroy( _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, output->parent.surface,
poutput->global, poutput->global,
mode->refresh)); mode->refresh));
@ -1245,10 +1246,10 @@ input_set_cursor(struct wayland_input *input)
struct wl_buffer *buffer; struct wl_buffer *buffer;
struct wl_cursor_image *image; struct wl_cursor_image *image;
if (!input->compositor->cursor) if (!input->backend->cursor)
return; /* Couldn't load the cursor. Can't set it */ 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); buffer = wl_cursor_image_get_buffer(image);
if (!buffer) if (!buffer)
return; return;
@ -1402,8 +1403,8 @@ input_handle_button(void *data, struct wl_pointer *pointer,
input->output = NULL; input->output = NULL;
input->keyboard_focus = NULL; input->keyboard_focus = NULL;
if (wl_list_empty(&input->compositor->base.output_list)) if (wl_list_empty(&input->backend->compositor->output_list))
wl_display_terminate(input->compositor->base.wl_display); wl_display_terminate(input->backend->compositor->wl_display);
return; return;
} }
@ -1455,7 +1456,7 @@ input_handle_keymap(void *data, struct wl_keyboard *keyboard, uint32_t format,
goto error; 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, map_str,
XKB_KEYMAP_FORMAT_TEXT_V1, XKB_KEYMAP_FORMAT_TEXT_V1,
0); 0);
@ -1574,16 +1575,16 @@ input_handle_modifiers(void *data, struct wl_keyboard *keyboard,
uint32_t group) uint32_t group)
{ {
struct wayland_input *input = data; struct wayland_input *input = data;
struct wayland_compositor *c = input->compositor; struct wayland_backend *b = input->backend;
uint32_t serial_out; uint32_t serial_out;
/* If we get a key event followed by a modifier event with the /* If we get a key event followed by a modifier event with the
* same serial number, then we try to preserve those semantics by * same serial number, then we try to preserve those semantics by
* reusing the same serial number on the way out too. */ * reusing the same serial number on the way out too. */
if (serial_in == input->key_serial) 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 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, xkb_state_update_mask(input->base.keyboard->xkb_state.state,
mods_depressed, mods_latched, mods_depressed, mods_latched,
@ -1596,10 +1597,10 @@ input_handle_repeat_info(void *data, struct wl_keyboard *keyboard,
int32_t rate, int32_t delay) int32_t rate, int32_t delay)
{ {
struct wayland_input *input = data; struct wayland_input *input = data;
struct wayland_compositor *c = input->compositor; struct wayland_backend *b = input->backend;
c->base.kb_repeat_rate = rate; b->compositor->kb_repeat_rate = rate;
c->base.kb_repeat_delay = delay; b->compositor->kb_repeat_delay = delay;
} }
static const struct wl_keyboard_listener keyboard_listener = { static const struct wl_keyboard_listener keyboard_listener = {
@ -1651,7 +1652,7 @@ static const struct wl_seat_listener seat_listener = {
}; };
static void 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; struct wayland_input *input;
@ -1659,17 +1660,17 @@ display_add_seat(struct wayland_compositor *c, uint32_t id, uint32_t version)
if (input == NULL) if (input == NULL)
return; return;
weston_seat_init(&input->base, &c->base, "default"); weston_seat_init(&input->base, b->compositor, "default");
input->compositor = c; input->backend = b;
input->parent.seat = wl_registry_bind(c->parent.registry, id, input->parent.seat = wl_registry_bind(b->parent.registry, id,
&wl_seat_interface, MIN(version, 4)); &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_add_listener(input->parent.seat, &seat_listener, input);
wl_seat_set_user_data(input->parent.seat, input); wl_seat_set_user_data(input->parent.seat, input);
input->parent.cursor.surface = input->parent.cursor.surface =
wl_compositor_create_surface(c->parent.compositor); wl_compositor_create_surface(b->parent.compositor);
} }
static void static void
@ -1751,7 +1752,7 @@ static const struct wl_output_listener output_listener = {
}; };
static void 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; struct wayland_parent_output *output;
@ -1760,7 +1761,7 @@ wayland_compositor_register_output(struct wayland_compositor *c, uint32_t id)
return; return;
output->id = id; 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); &wl_output_interface, 1);
if (!output->global) { if (!output->global) {
free(output); free(output);
@ -1773,11 +1774,11 @@ wayland_compositor_register_output(struct wayland_compositor *c, uint32_t id)
output->transform = WL_OUTPUT_TRANSFORM_NORMAL; output->transform = WL_OUTPUT_TRANSFORM_NORMAL;
output->physical.subpixel = WL_OUTPUT_SUBPIXEL_UNKNOWN; output->physical.subpixel = WL_OUTPUT_SUBPIXEL_UNKNOWN;
wl_list_init(&output->mode_list); 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) { if (b->sprawl_across_outputs) {
wl_display_roundtrip(c->parent.wl_display); wl_display_roundtrip(b->parent.wl_display);
wayland_output_create_for_parent_output(c, output); 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, registry_handle_global(void *data, struct wl_registry *registry, uint32_t name,
const char *interface, uint32_t version) const char *interface, uint32_t version)
{ {
struct wayland_compositor *c = data; struct wayland_backend *b = data;
if (strcmp(interface, "wl_compositor") == 0) { if (strcmp(interface, "wl_compositor") == 0) {
c->parent.compositor = b->parent.compositor =
wl_registry_bind(registry, name, wl_registry_bind(registry, name,
&wl_compositor_interface, 1); &wl_compositor_interface, 1);
} else if (strcmp(interface, "wl_shell") == 0) { } else if (strcmp(interface, "wl_shell") == 0) {
c->parent.shell = b->parent.shell =
wl_registry_bind(registry, name, wl_registry_bind(registry, name,
&wl_shell_interface, 1); &wl_shell_interface, 1);
} else if (strcmp(interface, "_wl_fullscreen_shell") == 0) { } else if (strcmp(interface, "_wl_fullscreen_shell") == 0) {
c->parent.fshell = b->parent.fshell =
wl_registry_bind(registry, name, wl_registry_bind(registry, name,
&_wl_fullscreen_shell_interface, 1); &_wl_fullscreen_shell_interface, 1);
} else if (strcmp(interface, "wl_seat") == 0) { } 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) { } 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) { } else if (strcmp(interface, "wl_shm") == 0) {
c->parent.shm = b->parent.shm =
wl_registry_bind(registry, name, &wl_shm_interface, 1); 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, registry_handle_global_remove(void *data, struct wl_registry *registry,
uint32_t name) uint32_t name)
{ {
struct wayland_compositor *c = data; struct wayland_backend *b = data;
struct wayland_parent_output *output; 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) if (output->id == name)
wayland_parent_output_destroy(output); wayland_parent_output_destroy(output);
} }
@ -1845,24 +1846,24 @@ static const struct wl_registry_listener registry_listener = {
}; };
static int 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; int count = 0;
if ((mask & WL_EVENT_HANGUP) || (mask & WL_EVENT_ERROR)) { 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; return 0;
} }
if (mask & WL_EVENT_READABLE) 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) if (mask & WL_EVENT_WRITABLE)
wl_display_flush(c->parent.wl_display); wl_display_flush(b->parent.wl_display);
if (mask == 0) { if (mask == 0) {
count = wl_display_dispatch_pending(c->parent.wl_display); count = wl_display_dispatch_pending(b->parent.wl_display);
wl_display_flush(c->parent.wl_display); wl_display_flush(b->parent.wl_display);
} }
return count; return count;
@ -1876,14 +1877,14 @@ wayland_restore(struct weston_compositor *ec)
static void static void
wayland_destroy(struct weston_compositor *ec) 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); weston_compositor_shutdown(ec);
if (c->parent.shm) if (b->parent.shm)
wl_shm_destroy(c->parent.shm); wl_shm_destroy(b->parent.shm);
free(ec); free(b);
} }
static const char *left_ptrs[] = { static const char *left_ptrs[] = {
@ -1894,7 +1895,7 @@ static const char *left_ptrs[] = {
}; };
static void 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; struct weston_config_section *s;
int size; 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_string(s, "cursor-theme", &theme, NULL);
weston_config_section_get_int(s, "cursor-size", &size, 32); weston_config_section_get_int(s, "cursor-size", &size, 32);
c->cursor_theme = wl_cursor_theme_load(theme, size, c->parent.shm); b->cursor_theme = wl_cursor_theme_load(theme, size, b->parent.shm);
if (!c->cursor_theme) { if (!b->cursor_theme) {
fprintf(stderr, "could not load cursor theme\n"); fprintf(stderr, "could not load cursor theme\n");
return; return;
} }
free(theme); free(theme);
c->cursor = NULL; b->cursor = NULL;
for (i = 0; !c->cursor && i < ARRAY_LENGTH(left_ptrs); ++i) for (i = 0; !b->cursor && i < ARRAY_LENGTH(left_ptrs); ++i)
c->cursor = wl_cursor_theme_get_cursor(c->cursor_theme, b->cursor = wl_cursor_theme_get_cursor(b->cursor_theme,
left_ptrs[i]); left_ptrs[i]);
if (!c->cursor) { if (!b->cursor) {
fprintf(stderr, "could not load left cursor\n"); fprintf(stderr, "could not load left cursor\n");
return; return;
} }
@ -1927,10 +1928,10 @@ static void
fullscreen_binding(struct weston_seat *seat_base, uint32_t time, uint32_t key, fullscreen_binding(struct weston_seat *seat_base, uint32_t time, uint32_t key,
void *data) void *data)
{ {
struct wayland_compositor *c = data; struct wayland_backend *b = data;
struct wayland_input *input = NULL; 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) if (&input->base == seat_base)
break; 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); weston_output_schedule_repaint(&input->output->base);
} }
static struct wayland_compositor * static struct wayland_backend *
wayland_compositor_create(struct wl_display *display, int use_pixman, wayland_backend_create(struct weston_compositor *compositor, int use_pixman,
const char *display_name, int *argc, char *argv[], const char *display_name, int *argc, char *argv[],
struct weston_config *config) struct weston_config *config)
{ {
struct wayland_compositor *c; struct wayland_backend *b;
struct wl_event_loop *loop; struct wl_event_loop *loop;
int fd; int fd;
c = zalloc(sizeof *c); b = zalloc(sizeof *b);
if (c == NULL) if (b == NULL)
return NULL; return NULL;
if (weston_compositor_init(&c->base, display, argc, argv, b->compositor = compositor;
if (weston_compositor_init(compositor, argc, argv,
config) < 0) config) < 0)
goto err_free; 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; goto err_compositor;
c->parent.wl_display = wl_display_connect(display_name); b->parent.wl_display = wl_display_connect(display_name);
if (c->parent.wl_display == NULL) { if (b->parent.wl_display == NULL) {
weston_log("failed to create display: %m\n"); weston_log("failed to create display: %m\n");
goto err_compositor; goto err_compositor;
} }
wl_list_init(&c->parent.output_list); wl_list_init(&b->parent.output_list);
wl_list_init(&c->input_list); wl_list_init(&b->input_list);
c->parent.registry = wl_display_get_registry(c->parent.wl_display); b->parent.registry = wl_display_get_registry(b->parent.wl_display);
wl_registry_add_listener(c->parent.registry, &registry_listener, c); wl_registry_add_listener(b->parent.registry, &registry_listener, b);
wl_display_roundtrip(c->parent.wl_display); 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 (!b->use_pixman) {
if (!c->use_pixman) {
gl_renderer = weston_load_module("gl-renderer.so", gl_renderer = weston_load_module("gl-renderer.so",
"gl_renderer_interface"); "gl_renderer_interface");
if (!gl_renderer) if (!gl_renderer)
c->use_pixman = 1; b->use_pixman = 1;
} }
if (!c->use_pixman) { if (!b->use_pixman) {
if (gl_renderer->create(&c->base, if (gl_renderer->create(compositor,
EGL_PLATFORM_WAYLAND_KHR, EGL_PLATFORM_WAYLAND_KHR,
c->parent.wl_display, b->parent.wl_display,
gl_renderer->alpha_attribs, gl_renderer->alpha_attribs,
NULL, NULL,
0) < 0) { 0) < 0) {
weston_log("Failed to initialize the GL renderer; " weston_log("Failed to initialize the GL renderer; "
"falling back to pixman.\n"); "falling back to pixman.\n");
c->use_pixman = 1; b->use_pixman = 1;
} }
} }
if (c->use_pixman) { if (b->use_pixman) {
if (pixman_renderer_init(&c->base) < 0) { if (pixman_renderer_init(compositor) < 0) {
weston_log("Failed to initialize pixman renderer\n"); weston_log("Failed to initialize pixman renderer\n");
goto err_display; goto err_display;
} }
} }
c->base.destroy = wayland_destroy; b->base.destroy = wayland_destroy;
c->base.restore = wayland_restore; 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); fd = wl_display_get_fd(b->parent.wl_display);
c->parent.wl_source = b->parent.wl_source =
wl_event_loop_add_fd(loop, fd, WL_EVENT_READABLE, wl_event_loop_add_fd(loop, fd, WL_EVENT_READABLE,
wayland_compositor_handle_event, c); wayland_backend_handle_event, b);
if (c->parent.wl_source == NULL) if (b->parent.wl_source == NULL)
goto err_renderer; 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: err_renderer:
c->base.renderer->destroy(&c->base); compositor->renderer->destroy(compositor);
err_display: err_display:
wl_display_disconnect(c->parent.wl_display); wl_display_disconnect(b->parent.wl_display);
err_compositor: err_compositor:
weston_compositor_shutdown(&c->base); weston_compositor_shutdown(compositor);
err_free: err_free:
free(c); free(b);
return NULL; return NULL;
} }
static void static void
wayland_compositor_destroy(struct wayland_compositor *c) wayland_backend_destroy(struct wayland_backend *b)
{ {
struct weston_output *output, *next; 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); wayland_output_destroy(output);
c->base.renderer->destroy(&c->base); b->compositor->renderer->destroy(b->compositor);
wl_display_disconnect(c->parent.wl_display); wl_display_disconnect(b->parent.wl_display);
if (c->theme) if (b->theme)
theme_destroy(c->theme); theme_destroy(b->theme);
if (c->frame_device) if (b->frame_device)
cairo_device_destroy(c->frame_device); cairo_device_destroy(b->frame_device);
wl_cursor_theme_destroy(c->cursor_theme); wl_cursor_theme_destroy(b->cursor_theme);
weston_compositor_shutdown(&c->base); weston_compositor_shutdown(b->compositor);
free(c); free(b);
} }
WL_EXPORT struct weston_compositor * WL_EXPORT int
backend_init(struct wl_display *display, int *argc, char *argv[], backend_init(struct weston_compositor *compositor, int *argc, char *argv[],
struct weston_config *config) struct weston_config *config)
{ {
struct wayland_compositor *c; struct wayland_backend *b;
struct wayland_output *output; struct wayland_output *output;
struct wayland_parent_output *poutput; struct wayland_parent_output *poutput;
struct weston_config_section *section; struct weston_config_section *section;
@ -2091,29 +2092,29 @@ backend_init(struct wl_display *display, int *argc, char *argv[],
parse_options(wayland_options, parse_options(wayland_options,
ARRAY_LENGTH(wayland_options), argc, argv); ARRAY_LENGTH(wayland_options), argc, argv);
c = wayland_compositor_create(display, use_pixman, display_name, b = wayland_backend_create(compositor, use_pixman, display_name,
argc, argv, config); argc, argv, config);
if (!c) if (!b)
return NULL; return -1;
if (sprawl || c->parent.fshell) { if (sprawl || b->parent.fshell) {
c->sprawl_across_outputs = 1; b->sprawl_across_outputs = 1;
wl_display_roundtrip(c->parent.wl_display); wl_display_roundtrip(b->parent.wl_display);
wl_list_for_each(poutput, &c->parent.output_list, link) wl_list_for_each(poutput, &b->parent.output_list, link)
wayland_output_create_for_parent_output(c, poutput); wayland_output_create_for_parent_output(b, poutput);
return &c->base; return 0;
} }
if (fullscreen) { if (fullscreen) {
output = wayland_output_create(c, 0, 0, width, height, output = wayland_output_create(b, 0, 0, width, height,
NULL, 1, 0, 1); NULL, 1, 0, 1);
if (!output) if (!output)
goto err_outputs; goto err_outputs;
wayland_output_set_fullscreen(output, 0, 0, NULL); wayland_output_set_fullscreen(output, 0, 0, NULL);
return &c->base; return 0;
} }
section = NULL; section = NULL;
@ -2131,7 +2132,7 @@ backend_init(struct wl_display *display, int *argc, char *argv[],
} }
free(name); free(name);
output = wayland_output_create_for_config(c, section, width, output = wayland_output_create_for_config(b, section, width,
height, scale, x, 0); height, scale, x, 0);
if (!output) if (!output)
goto err_outputs; goto err_outputs;
@ -2149,7 +2150,7 @@ backend_init(struct wl_display *display, int *argc, char *argv[],
if (!scale) if (!scale)
scale = 1; scale = 1;
while (count > 0) { 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); NULL, 0, 0, scale);
if (!output) if (!output)
goto err_outputs; goto err_outputs;
@ -2160,13 +2161,13 @@ backend_init(struct wl_display *display, int *argc, char *argv[],
--count; --count;
} }
weston_compositor_add_key_binding(&c->base, KEY_F, weston_compositor_add_key_binding(compositor, KEY_F,
MODIFIER_CTRL | MODIFIER_ALT, MODIFIER_CTRL | MODIFIER_ALT,
fullscreen_binding, c); fullscreen_binding, b);
return &c->base; return 0;
err_outputs: err_outputs:
wayland_compositor_destroy(c); wayland_backend_destroy(b);
return NULL; 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 WL_EXPORT int
weston_compositor_init(struct weston_compositor *ec, weston_compositor_init(struct weston_compositor *ec,
struct wl_display *display,
int *argc, char *argv[], int *argc, char *argv[],
struct weston_config *config) struct weston_config *config)
{ {
@ -4511,7 +4510,6 @@ weston_compositor_init(struct weston_compositor *ec,
struct weston_config_section *s; struct weston_config_section *s;
ec->config = config; ec->config = config;
ec->wl_display = display;
wl_signal_init(&ec->destroy_signal); wl_signal_init(&ec->destroy_signal);
wl_signal_init(&ec->create_surface_signal); wl_signal_init(&ec->create_surface_signal);
wl_signal_init(&ec->activate_signal); wl_signal_init(&ec->activate_signal);
@ -4531,11 +4529,11 @@ weston_compositor_init(struct weston_compositor *ec,
ec->output_id_pool = 0; 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)) ec, compositor_bind))
return -1; 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)) ec, bind_subcompositor))
return -1; return -1;
@ -4584,7 +4582,7 @@ weston_compositor_init(struct weston_compositor *ec,
wl_data_device_manager_init(ec->wl_display); 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); loop = wl_display_get_event_loop(ec->wl_display);
ec->idle_source = wl_event_loop_add_timer(loop, idle_handler, ec); 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(); print_backtrace();
segv_compositor->restore(segv_compositor); segv_compositor->backend->restore(segv_compositor);
raise(SIGTRAP); raise(SIGTRAP);
} }
@ -5281,10 +5279,9 @@ int main(int argc, char *argv[])
struct weston_compositor *ec; struct weston_compositor *ec;
struct wl_event_source *signals[4]; struct wl_event_source *signals[4];
struct wl_event_loop *loop; struct wl_event_loop *loop;
struct weston_compositor int (*backend_init)(struct weston_compositor *c,
*(*backend_init)(struct wl_display *display, int *argc, char *argv[],
int *argc, char *argv[], struct weston_config *config);
struct weston_config *config);
int i, fd; int i, fd;
char *backend = NULL; char *backend = NULL;
char *shell = NULL; char *shell = NULL;
@ -5373,12 +5370,19 @@ int main(int argc, char *argv[])
if (!backend_init) if (!backend_init)
goto out_signals; goto out_signals;
ec = backend_init(display, &argc, argv, config); ec = zalloc(sizeof *ec);
if (ec == NULL) { if (ec == NULL) {
weston_log("fatal: failed to create compositor\n"); weston_log("fatal: failed to create compositor\n");
goto out_signals; 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(); catch_signals();
segv_compositor = ec; segv_compositor = ec;
@ -5466,7 +5470,8 @@ out:
weston_compositor_xkb_destroy(ec); weston_compositor_xkb_destroy(ec);
ec->destroy(ec); ec->backend->destroy(ec);
free(ec);
out_signals: out_signals:
for (i = ARRAY_LENGTH(signals) - 1; i >= 0; i--) for (i = ARRAY_LENGTH(signals) - 1; i >= 0; i--)

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

Loading…
Cancel
Save