[PATCH 04/12] compositor: Add output to the compositor output list in the core

Xiong Zhang xiong.y.zhang at intel.com
Fri Mar 7 00:27:22 PST 2014


From: Ander Conselvan de Oliveira <ander.conselvan.de.oliveira at intel.com>

Previously the insertion was done by the backends, with a potential
crash in the error path. Calls to weston_output_destroy() would try
to remove the output from the compositor list before it was actually
inserted.

This patch moves the insertion to weston_output_init().

Signed-off-by: Ander Conselvan de Oliveira <ander.conselvan.de.oliveira at intel.com>
---
 src/compositor-drm.c      |  2 --
 src/compositor-fbdev.c    |  2 --
 src/compositor-headless.c |  2 --
 src/compositor-rdp.c      |  1 -
 src/compositor-rpi.c      |  2 --
 src/compositor-wayland.c  |  2 --
 src/compositor-x11.c      | 12 +++++++-----
 src/compositor.c          |  2 ++
 8 files changed, 9 insertions(+), 16 deletions(-)

diff --git a/src/compositor-drm.c b/src/compositor-drm.c
index 57064ec..6109cec 100644
--- a/src/compositor-drm.c
+++ b/src/compositor-drm.c
@@ -2049,8 +2049,6 @@ create_output_for_connector(struct drm_compositor *ec,
 		weston_log("Failed to initialize backlight\n");
 	}
 
-	wl_list_insert(ec->base.output_list.prev, &output->base.link);
-
 	find_and_parse_output_edid(ec, output, connector);
 	if (connector->connector_type == DRM_MODE_CONNECTOR_LVDS)
 		output->base.connection_internal = 1;
diff --git a/src/compositor-fbdev.c b/src/compositor-fbdev.c
index 076a9a8..3eaa57b 100644
--- a/src/compositor-fbdev.c
+++ b/src/compositor-fbdev.c
@@ -639,8 +639,6 @@ fbdev_output_create(struct fbdev_compositor *compositor,
 	output->finish_frame_timer =
 		wl_event_loop_add_timer(loop, finish_frame_handler, output);
 
-	wl_list_insert(compositor->base.output_list.prev, &output->base.link);
-
 	weston_log("fbdev output %d×%d px\n",
 	           output->mode.width, output->mode.height);
 	weston_log_continue(STAMP_SPACE "guessing %d Hz and 96 dpi\n",
diff --git a/src/compositor-headless.c b/src/compositor-headless.c
index 326c11b..a07fd49 100644
--- a/src/compositor-headless.c
+++ b/src/compositor-headless.c
@@ -126,8 +126,6 @@ headless_compositor_create_output(struct headless_compositor *c,
 	output->base.set_dpms = NULL;
 	output->base.switch_mode = NULL;
 
-	wl_list_insert(c->base.output_list.prev, &output->base.link);
-
 	return 0;
 }
 
diff --git a/src/compositor-rdp.c b/src/compositor-rdp.c
index e8e4a8d..a6c192b 100644
--- a/src/compositor-rdp.c
+++ b/src/compositor-rdp.c
@@ -506,7 +506,6 @@ rdp_compositor_create_output(struct rdp_compositor *c, int width, int height,
 	output->base.switch_mode = rdp_switch_mode;
 	c->output = output;
 
-	wl_list_insert(c->base.output_list.prev, &output->base.link);
 	return 0;
 
 out_shadow_surface:
diff --git a/src/compositor-rpi.c b/src/compositor-rpi.c
index 7312822..8dc12d1 100644
--- a/src/compositor-rpi.c
+++ b/src/compositor-rpi.c
@@ -387,8 +387,6 @@ rpi_output_create(struct rpi_compositor *compositor, uint32_t transform)
 	if (rpi_renderer_output_create(&output->base, output->display) < 0)
 		goto out_output;
 
-	wl_list_insert(compositor->base.output_list.prev, &output->base.link);
-
 	weston_log("Raspberry Pi HDMI output %dx%d px\n",
 		   output->mode.width, output->mode.height);
 	weston_log_continue(STAMP_SPACE "guessing %d Hz and 96 dpi\n",
diff --git a/src/compositor-wayland.c b/src/compositor-wayland.c
index 9e94a7b..a850dab 100644
--- a/src/compositor-wayland.c
+++ b/src/compositor-wayland.c
@@ -826,8 +826,6 @@ wayland_output_create(struct wayland_compositor *c,
 	output->base.set_dpms = NULL;
 	output->base.switch_mode = NULL;
 
-	wl_list_insert(c->base.output_list.prev, &output->base.link);
-
 	return output;
 
 err_output:
diff --git a/src/compositor-x11.c b/src/compositor-x11.c
index 01af835..6c3eb15 100644
--- a/src/compositor-x11.c
+++ b/src/compositor-x11.c
@@ -882,28 +882,30 @@ x11_compositor_create_output(struct x11_compositor *c,
 		if (x11_output_init_shm(c, output,
 					output->mode.width,
 					output->mode.height) < 0)
-			return NULL;
+			goto err_output;
 		if (pixman_renderer_output_create(&output->base) < 0) {
 			x11_output_deinit_shm(c, output);
-			return NULL;
+			goto err_output;
 		}
 	} else {
 		ret = gl_renderer->output_create(&output->base,
 						 (EGLNativeWindowType) output->window);
 		if (ret < 0)
-			return NULL;
+			goto err_output;
 	}
 
 	loop = wl_display_get_event_loop(c->base.wl_display);
 	output->finish_frame_timer =
 		wl_event_loop_add_timer(loop, finish_frame_handler, output);
 
-	wl_list_insert(c->base.output_list.prev, &output->base.link);
-
 	weston_log("x11 output %dx%d, window id %d\n",
 		   width, height, output->window);
 
 	return output;
+
+err_output:
+	weston_output_destroy(&output->base);
+	return NULL;
 }
 
 static struct x11_output *
diff --git a/src/compositor.c b/src/compositor.c
index 51f2fae..524e24a 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -3296,6 +3296,8 @@ weston_output_init(struct weston_output *output, struct weston_compositor *c,
 	output->id = ffs(~output->compositor->output_id_pool) - 1;
 	output->compositor->output_id_pool |= 1 << output->id;
 
+	wl_list_insert(c->output_list.prev, &output->link);
+
 	output->global =
 		wl_global_create(c->wl_display, &wl_output_interface, 2,
 				 output, bind_output);
-- 
1.8.3.2



More information about the wayland-devel mailing list