[PATCH weston v3 34/36] compositor-x11: migrate to head-based output API

Pekka Paalanen ppaalanen at gmail.com
Tue Oct 31 11:48:44 UTC 2017


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 6a686f91..7ef0dbc9 100644
--- a/libweston/compositor-x11.c
+++ b/libweston/compositor-x11.c
@@ -108,6 +108,10 @@ struct x11_backend {
 	} atom;
 };
 
+struct x11_head {
+	struct weston_head	base;
+};
+
 struct x11_output {
 	struct weston_output	base;
 
@@ -131,6 +135,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)
 {
@@ -969,7 +979,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;
 
@@ -991,6 +1001,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;
 
@@ -1005,17 +1022,11 @@ x11_output_set_size(struct weston_output *base, int width, int height)
 
 	output->base.current_mode = &output->mode;
 
-	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;
 
@@ -1023,22 +1034,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)
 {
@@ -1621,12 +1656,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);
 }
@@ -1650,7 +1689,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 *
@@ -1710,6 +1749,7 @@ x11_backend_create(struct weston_compositor *compositor,
 
 	b->base.destroy = x11_destroy;
 	b->base.restore = x11_restore;
+	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