[PATCH weston v2 12/14] libweston: extend output->region lifetime

Pekka Paalanen ppaalanen at gmail.com
Mon Jul 24 15:08:07 UTC 2017


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

It's a little awkward to try to keep the weston_output::region and
weston_output::previous_damage allocate exactly only when the output is
enabled. There was also a leak: weston_output_move() was calling
weston_output_init_geometry() on an already allocated regions without
fini in between.

Fix both issues by allocating the regions in weston_output_init(),
always fini/init'ing them in weston_output_init_geometry(), and fini'ing
for good in weston_output_destroy().

This nicely gets rid of weston_output_enable_undo() so I do not need to
try to figure out what to do with it later.

Signed-off-by: Pekka Paalanen <pekka.paalanen at collabora.co.uk>
Reviewed-by: Armin Krezović <krezovic.armin at gmail.com>
---
 libweston/compositor.c | 32 ++++++++++----------------------
 1 file changed, 10 insertions(+), 22 deletions(-)

diff --git a/libweston/compositor.c b/libweston/compositor.c
index eda04340..296b02ee 100644
--- a/libweston/compositor.c
+++ b/libweston/compositor.c
@@ -4426,7 +4426,10 @@ weston_output_init_geometry(struct weston_output *output, int x, int y)
 	output->x = x;
 	output->y = y;
 
+	pixman_region32_fini(&output->previous_damage);
 	pixman_region32_init(&output->previous_damage);
+
+	pixman_region32_fini(&output->region);
 	pixman_region32_init_rect(&output->region, x, y,
 				  output->width,
 				  output->height);
@@ -4543,20 +4546,6 @@ weston_output_transform_coordinate(struct weston_output *output,
 	*y = p.f[1] / p.f[3];
 }
 
-/** Undoes changes to an output done by weston_output_enable()
- *
- * \param output The weston_output object that needs the changes undone.
- *
- * Removes the repaint timer.
- * Destroys pixman regions allocated to the output.
- */
-static void
-weston_output_enable_undo(struct weston_output *output)
-{
-	pixman_region32_fini(&output->region);
-	pixman_region32_fini(&output->previous_damage);
-}
-
 /** Removes output from compositor's list of enabled outputs
  *
  * \param output The weston_output object that is being removed.
@@ -4703,6 +4692,9 @@ weston_output_init(struct weston_output *output,
 	output->scale = 0;
 	/* Can't use -1 on uint32_t and 0 is valid enum value */
 	output->transform = UINT32_MAX;
+
+	pixman_region32_init(&output->previous_damage);
+	pixman_region32_init(&output->region);
 }
 
 /** Adds weston_output object to pending output list.
@@ -4811,8 +4803,6 @@ weston_output_enable(struct weston_output *output)
 	 */
 	if (output->enable(output) < 0) {
 		weston_log("Enabling output \"%s\" failed.\n", output->name);
-
-		weston_output_enable_undo(output);
 		return -1;
 	}
 
@@ -4864,10 +4854,8 @@ weston_output_disable(struct weston_output *output)
 	if (output->disable(output) < 0)
 		return;
 
-	if (output->enabled) {
+	if (output->enabled)
 		weston_compositor_remove_output(output);
-		weston_output_enable_undo(output);
-	}
 
 	output->destroying = 0;
 }
@@ -4902,11 +4890,11 @@ weston_output_destroy(struct weston_output *output)
 {
 	output->destroying = 1;
 
-	if (output->enabled) {
+	if (output->enabled)
 		weston_compositor_remove_output(output);
-		weston_output_enable_undo(output);
-	}
 
+	pixman_region32_fini(&output->region);
+	pixman_region32_fini(&output->previous_damage);
 	wl_list_remove(&output->link);
 	free(output->name);
 }
-- 
2.13.0



More information about the wayland-devel mailing list