[PATCH weston 12/15] libweston: move globals to weston_compositor_add_output()

Pekka Paalanen ppaalanen at gmail.com
Tue Apr 4 10:58:15 UTC 2017


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

Move the wl_output global management into weston_compositor_add_output()
and weston_compositor_remove_output().

If weston_output_enable() fails, there is no need to clean up the global
and the clients will not see a wl_output come and go.

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

diff --git a/libweston/compositor.c b/libweston/compositor.c
index e2d28db..e8d5443 100644
--- a/libweston/compositor.c
+++ b/libweston/compositor.c
@@ -4467,7 +4467,8 @@ weston_output_move(struct weston_output *output, int x, int y)
  * Removes the output from the pending list and adds it
  * to the compositor's live outputs list. The output created signal is emitted.
  *
- * The output gets an internal ID assigned.
+ * The output gets an internal ID assigned, and the wl_output global is
+ * created.
  *
  * \param compositor The compositor instance.
  * \param output The output to be added.
@@ -4495,6 +4496,10 @@ weston_compositor_add_output(struct weston_compositor *compositor,
 	wl_list_insert(compositor->output_list.prev, &output->link);
 	output->enabled = true;
 
+	output->global = wl_global_create(compositor->wl_display,
+					  &wl_output_interface, 3,
+					  output, bind_output);
+
 	wl_signal_emit(&compositor->output_created_signal, output);
 
 	wl_list_for_each_safe(view, next, &compositor->view_list, link)
@@ -4537,14 +4542,11 @@ weston_output_transform_coordinate(struct weston_output *output,
  * \param output The weston_output object that needs the changes undone.
  *
  * Removes the repaint timer.
- * Destroys the Wayland global assigned to the output.
  * Destroys pixman regions allocated to the output.
  */
 static void
 weston_output_enable_undo(struct weston_output *output)
 {
-	wl_global_destroy(output->global);
-
 	pixman_region32_fini(&output->region);
 	pixman_region32_fini(&output->previous_damage);
 }
@@ -4569,7 +4571,7 @@ weston_output_enable_undo(struct weston_output *output)
  * moved to a new output by the shell, if necessary.
  *
  * - wl_output protocol objects referencing this weston_output
- * are made inert.
+ * are made inert, and the wl_output global is removed.
  *
  * - The output is put back in the pending outputs list.
  *
@@ -4600,6 +4602,8 @@ weston_compositor_remove_output(struct weston_output *output)
 	wl_signal_emit(&compositor->output_destroyed_signal, output);
 	wl_signal_emit(&output->destroy_signal, output);
 
+	wl_global_destroy(output->global);
+	output->global = NULL;
 	wl_resource_for_each(resource, &output->resource_list) {
 		wl_resource_set_destructor(resource, NULL);
 	}
@@ -4797,10 +4801,6 @@ weston_output_enable(struct weston_output *output)
 	wl_list_init(&output->resource_list);
 	wl_list_init(&output->feedback_list);
 
-	output->global =
-		wl_global_create(c->wl_display, &wl_output_interface, 3,
-				 output, bind_output);
-
 	/* Enable the output (set up the crtc or create a
 	 * window representing the output, set up the
 	 * renderer, etc)
-- 
2.10.2



More information about the wayland-devel mailing list