[PATCH weston v6 43/73] libweston: allow attaching heads to enabled outputs

Pekka Paalanen ppaalanen at gmail.com
Fri Feb 16 14:57:28 UTC 2018


From: Pekka Paalanen <pekka.paalanen at collabora.co.uk>

Move the responsibility of ensuring the head will work in the enabled
output to the backends.

A compositor cannot enable an output without heads, and removing the
last head from an output automatically disables the output, so attaching
a new head to an enabled output is only possible for clone mode.

Backends headless, rdp, and x11 forbid clone mode by not having an
attach_head hook implemented; fbdev and wayland explicitly deny clone
mode. Only the DRM backend is affected by this change and even that not
yet because MAX_CLONED_CONNECTORS is 1 in the DRM backend.

Also ensure a global is created for the head when attached to an enabled
output, and log it.

Signed-off-by: Pekka Paalanen <pekka.paalanen at collabora.co.uk>
---
 libweston/compositor.c | 34 +++++++++++++++++++++++++---------
 1 file changed, 25 insertions(+), 9 deletions(-)

diff --git a/libweston/compositor.c b/libweston/compositor.c
index b302f8d5..0d2af676 100644
--- a/libweston/compositor.c
+++ b/libweston/compositor.c
@@ -76,6 +76,9 @@ weston_output_transform_scale_init(struct weston_output *output,
 static void
 weston_compositor_build_view_list(struct weston_compositor *compositor);
 
+static char *
+weston_output_create_heads_string(struct weston_output *output);
+
 /** Send wl_output events for mode and scale changes
  *
  * \param head Send on all resources bound to this head.
@@ -4378,6 +4381,14 @@ bind_output(struct wl_client *client,
 		wl_output_send_done(resource);
 }
 
+static void
+weston_head_add_global(struct weston_head *head)
+{
+	head->global = wl_global_create(head->compositor->wl_display,
+					&wl_output_interface, 3,
+					head, bind_output);
+}
+
 /** Remove the global wl_output protocol object
  *
  * \param head The head whose global to remove.
@@ -4615,7 +4626,7 @@ weston_output_iterate_heads(struct weston_output *output,
 	return container_of(node, struct weston_head, output_link);
 }
 
-/** Attach a head to an inactive output
+/** Attach a head to an output
  *
  * \param output The output to attach to.
  * \param head The head that is not yet attached.
@@ -4630,7 +4641,7 @@ weston_output_iterate_heads(struct weston_output *output,
  *
  * On failure, the head remains unattached. Success of this function does not
  * guarantee the output configuration is actually valid. The final checks are
- * made on weston_output_enable().
+ * made on weston_output_enable() unless the output was already enabled.
  *
  * \memberof weston_output
  */
@@ -4638,8 +4649,7 @@ WL_EXPORT int
 weston_output_attach_head(struct weston_output *output,
 			  struct weston_head *head)
 {
-	if (output->enabled)
-		return -1;
+	char *head_names;
 
 	if (!wl_list_empty(&head->output_link))
 		return -1;
@@ -4655,6 +4665,15 @@ weston_output_attach_head(struct weston_output *output,
 	head->output = output;
 	wl_list_insert(output->head_list.prev, &head->output_link);
 
+	if (output->enabled) {
+		weston_head_add_global(head);
+
+		head_names = weston_output_create_heads_string(output);
+		weston_log("Output '%s' updated to have head(s) %s\n",
+			   output->name, head_names);
+		free(head_names);
+	}
+
 	return 0;
 }
 
@@ -5213,11 +5232,8 @@ weston_compositor_add_output(struct weston_compositor *compositor,
 	wl_list_insert(compositor->output_list.prev, &output->link);
 	output->enabled = true;
 
-	wl_list_for_each(head, &output->head_list, output_link) {
-		head->global = wl_global_create(compositor->wl_display,
-						&wl_output_interface, 3,
-						head, bind_output);
-	}
+	wl_list_for_each(head, &output->head_list, output_link)
+		weston_head_add_global(head);
 
 	wl_signal_emit(&compositor->output_created_signal, output);
 
-- 
2.13.6



More information about the wayland-devel mailing list