[PATCH weston v3 35/36] compositor-wayland: strict surface create/destroy

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


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

Add safeguards to make it painfully obvious if we ever get the pairing
of wayland_backend_create_output_surface() and
wayland_backend_destroy_output_surface() wrong. Helps catching bugs.

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

diff --git a/libweston/compositor-wayland.c b/libweston/compositor-wayland.c
index 222d3977..b2e96d0e 100644
--- a/libweston/compositor-wayland.c
+++ b/libweston/compositor-wayland.c
@@ -644,16 +644,25 @@ wayland_output_repaint_pixman(struct weston_output *output_base,
 static void
 wayland_backend_destroy_output_surface(struct wayland_output *output)
 {
-	if (output->parent.xdg_toplevel)
+	assert(output->parent.surface);
+
+	if (output->parent.xdg_toplevel) {
 		zxdg_toplevel_v6_destroy(output->parent.xdg_toplevel);
+		output->parent.xdg_toplevel = NULL;
+	}
 
-	if (output->parent.xdg_surface)
+	if (output->parent.xdg_surface) {
 		zxdg_surface_v6_destroy(output->parent.xdg_surface);
+		output->parent.xdg_surface = NULL;
+	}
 
-	if (output->parent.shell_surface)
+	if (output->parent.shell_surface) {
 		wl_shell_surface_destroy(output->parent.shell_surface);
+		output->parent.shell_surface = NULL;
+	}
 
 	wl_surface_destroy(output->parent.surface);
+	output->parent.surface = NULL;
 }
 
 static void
@@ -1138,6 +1147,8 @@ wayland_backend_create_output_surface(struct wayland_output *output)
 {
 	struct wayland_backend *b = to_wayland_backend(output->base.compositor);
 
+	assert(!output->parent.surface);
+
 	output->parent.surface =
 		wl_compositor_create_surface(b->parent.compositor);
 	if (!output->parent.surface)
-- 
2.13.6



More information about the wayland-devel mailing list