[PATCH weston v6 35/73] compositor-x11: migrate to head-based output API
Pekka Paalanen
ppaalanen at gmail.com
Fri Feb 16 14:57:20 UTC 2018
From: Pekka Paalanen <pekka.paalanen at collabora.co.uk>
Follow the standard pattern set by the headless backend which also uses
the the window output API.
Stops relying on the implicit weston_output::head.
Signed-off-by: Pekka Paalanen <pekka.paalanen at collabora.co.uk>
---
libweston/compositor-x11.c | 68 ++++++++++++++++++++++++++++++++++++----------
1 file changed, 54 insertions(+), 14 deletions(-)
diff --git a/libweston/compositor-x11.c b/libweston/compositor-x11.c
index de19fad8..78b0d7c6 100644
--- a/libweston/compositor-x11.c
+++ b/libweston/compositor-x11.c
@@ -116,6 +116,10 @@ struct x11_backend {
} atom;
};
+struct x11_head {
+ struct weston_head base;
+};
+
struct x11_output {
struct weston_output base;
@@ -142,6 +146,12 @@ struct window_delete_data {
struct gl_renderer_interface *gl_renderer;
+static inline struct x11_head *
+to_x11_head(struct weston_head *base)
+{
+ return container_of(base, struct x11_head, base);
+}
+
static inline struct x11_output *
to_x11_output(struct weston_output *base)
{
@@ -1065,7 +1075,7 @@ x11_output_set_size(struct weston_output *base, int width, int height)
{
struct x11_output *output = to_x11_output(base);
struct x11_backend *b = to_x11_backend(base->compositor);
- struct weston_head *head = &output->base.head;
+ struct weston_head *head;
xcb_screen_t *scrn = b->screen;
int output_width, output_height;
@@ -1087,6 +1097,13 @@ x11_output_set_size(struct weston_output *base, int width, int height)
return -1;
}
+ wl_list_for_each(head, &output->base.head_list, output_link) {
+ weston_head_set_monitor_strings(head, "weston-X11", "none", NULL);
+ weston_head_set_physical_size(head,
+ width * scrn->width_in_millimeters / scrn->width_in_pixels,
+ height * scrn->height_in_millimeters / scrn->height_in_pixels);
+ }
+
output_width = width * output->base.scale;
output_height = height * output->base.scale;
@@ -1104,17 +1121,11 @@ x11_output_set_size(struct weston_output *base, int width, int height)
output->base.native_mode = &output->native;
output->base.native_scale = output->base.scale;
- weston_head_set_monitor_strings(head, "weston-X11", "none", NULL);
- weston_head_set_physical_size(head,
- width * scrn->width_in_millimeters / scrn->width_in_pixels,
- height * scrn->height_in_millimeters / scrn->height_in_pixels);
-
return 0;
}
-static int
-x11_output_create(struct weston_compositor *compositor,
- const char *name)
+static struct weston_output *
+x11_output_create(struct weston_compositor *compositor, const char *name)
{
struct x11_output *output;
@@ -1122,22 +1133,46 @@ x11_output_create(struct weston_compositor *compositor,
assert(name);
output = zalloc(sizeof *output);
- if (output == NULL) {
- perror("zalloc");
- return -1;
- }
+ if (!output)
+ return NULL;
weston_output_init(&output->base, compositor, name);
output->base.destroy = x11_output_destroy;
output->base.disable = x11_output_disable;
output->base.enable = x11_output_enable;
+ output->base.attach_head = NULL;
weston_compositor_add_pending_output(&output->base, compositor);
+ return &output->base;
+}
+
+static int
+x11_head_create(struct weston_compositor *compositor, const char *name)
+{
+ struct x11_head *head;
+
+ assert(name);
+
+ head = zalloc(sizeof *head);
+ if (!head)
+ return -1;
+
+ weston_head_init(&head->base, name);
+ weston_head_set_connection_status(&head->base, true);
+ weston_compositor_add_head(compositor, &head->base);
+
return 0;
}
+static void
+x11_head_destroy(struct x11_head *head)
+{
+ weston_head_release(&head->base);
+ free(head);
+}
+
static struct x11_output *
x11_backend_find_output(struct x11_backend *b, xcb_window_t window)
{
@@ -1745,12 +1780,16 @@ static void
x11_destroy(struct weston_compositor *ec)
{
struct x11_backend *backend = to_x11_backend(ec);
+ struct weston_head *base, *next;
wl_event_source_remove(backend->xcb_source);
x11_input_destroy(backend);
weston_compositor_shutdown(ec); /* destroys outputs, too */
+ wl_list_for_each_safe(base, next, &ec->head_list, compositor_link)
+ x11_head_destroy(to_x11_head(base));
+
XCloseDisplay(backend->dpy);
free(backend);
}
@@ -1774,7 +1813,7 @@ init_gl_renderer(struct x11_backend *b)
static const struct weston_windowed_output_api api = {
x11_output_set_size,
- x11_output_create,
+ x11_head_create,
};
static struct x11_backend *
@@ -1833,6 +1872,7 @@ x11_backend_create(struct weston_compositor *compositor,
weston_log("Using %s renderer\n", config->use_pixman ? "pixman" : "gl");
b->base.destroy = x11_destroy;
+ b->base.create_output = x11_output_create;
if (x11_input_create(b, config->no_input) < 0) {
weston_log("Failed to create X11 input\n");
--
2.13.6
More information about the wayland-devel
mailing list