[PATCH weston 04/15] compositor: add API to manage compositor instances

Giulio Camuffo giuliocamuffo at gmail.com
Thu Nov 6 12:41:23 PST 2014


---
 src/compositor-drm.c     |  2 +-
 src/compositor-wayland.c |  4 +--
 src/compositor-x11.c     |  2 +-
 src/compositor.c         | 85 +++++++++++++++++++++++++++++++-----------------
 src/compositor.h         |  9 +++--
 5 files changed, 67 insertions(+), 35 deletions(-)

diff --git a/src/compositor-drm.c b/src/compositor-drm.c
index 643bb2b..c264ac8 100644
--- a/src/compositor-drm.c
+++ b/src/compositor-drm.c
@@ -2273,7 +2273,7 @@ update_outputs(struct drm_backend *b, struct udev_device *drm_device)
 
 	/* FIXME: handle zero outputs, without terminating */	
 	if (b->connector_allocator == 0)
-		wl_display_terminate(b->compositor->wl_display);
+		weston_compositor_terminate(b->compositor);
 }
 
 static int
diff --git a/src/compositor-wayland.c b/src/compositor-wayland.c
index 56fdcdf..40d6f64 100644
--- a/src/compositor-wayland.c
+++ b/src/compositor-wayland.c
@@ -1393,7 +1393,7 @@ input_handle_button(void *data, struct wl_pointer *pointer,
 		}
 
 		if (frame_status(input->output->frame) & FRAME_STATUS_CLOSE)
-			wl_display_terminate(input->backend->compositor->wl_display);
+			weston_compositor_terminate(input->backend->compositor);
 
 		if (frame_status(input->output->frame) & FRAME_STATUS_REPAINT)
 			weston_output_schedule_repaint(&input->output->base);
@@ -1838,7 +1838,7 @@ wayland_backend_handle_event(int fd, uint32_t mask, void *data)
 	int count = 0;
 
 	if ((mask & WL_EVENT_HANGUP) || (mask & WL_EVENT_ERROR)) {
-		wl_display_terminate(b->compositor->wl_display);
+		weston_compositor_terminate(b->compositor);
 		return 0;
 	}
 
diff --git a/src/compositor-x11.c b/src/compositor-x11.c
index f8e061f..a09a502 100644
--- a/src/compositor-x11.c
+++ b/src/compositor-x11.c
@@ -935,7 +935,7 @@ x11_backend_delete_window(struct x11_backend *b, xcb_window_t window)
 	xcb_flush(b->conn);
 
 	if (wl_list_empty(&b->compositor->output_list))
-		wl_display_terminate(b->compositor->wl_display);
+		weston_compositor_terminate(b->compositor);
 }
 
 #ifdef HAVE_XCB_XKB
diff --git a/src/compositor.c b/src/compositor.c
index 2243509..633f08c 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -4016,12 +4016,9 @@ weston_environment_get_fd(const char *env)
 }
 
 WL_EXPORT int
-weston_compositor_init(struct weston_compositor *ec,
-		       struct weston_config *config)
+weston_compositor_init(struct weston_compositor *ec)
 {
 	struct wl_event_loop *loop;
-	struct xkb_rule_names xkb_names;
-	struct weston_config_section *s;
 
 	wl_signal_init(&ec->destroy_signal);
 	wl_signal_init(&ec->create_surface_signal);
@@ -4073,6 +4070,31 @@ weston_compositor_init(struct weston_compositor *ec,
 	weston_plane_init(&ec->primary_plane, ec, 0, 0);
 	weston_compositor_stack_plane(ec, &ec->primary_plane, NULL);
 
+	wl_data_device_manager_init(ec->wl_display);
+
+	wl_display_init_shm(ec->wl_display);
+
+	loop = wl_display_get_event_loop(ec->wl_display);
+	ec->idle_source = wl_event_loop_add_timer(loop, idle_handler, ec);
+	wl_event_source_timer_update(ec->idle_source, ec->idle_time * 1000);
+
+	ec->input_loop = wl_event_loop_create();
+
+	weston_layer_init(&ec->fade_layer, &ec->layer_list);
+	weston_layer_init(&ec->cursor_layer, &ec->fade_layer.link);
+
+	weston_compositor_schedule_repaint(ec);
+
+	return 0;
+}
+
+static int
+weston_compositor_init_config(struct weston_compositor *ec,
+			      struct weston_config *config)
+{
+	struct xkb_rule_names xkb_names;
+	struct weston_config_section *s;
+
 	s = weston_config_get_section(config, "keyboard", NULL, NULL);
 	weston_config_section_get_string(s, "keymap_rules",
 					 (char **) &xkb_names.rules, NULL);
@@ -4095,21 +4117,6 @@ weston_compositor_init(struct weston_compositor *ec,
 
 	text_backend_init(ec, config);
 
-	wl_data_device_manager_init(ec->wl_display);
-
-	wl_display_init_shm(ec->wl_display);
-
-	loop = wl_display_get_event_loop(ec->wl_display);
-	ec->idle_source = wl_event_loop_add_timer(loop, idle_handler, ec);
-	wl_event_source_timer_update(ec->idle_source, ec->idle_time * 1000);
-
-	ec->input_loop = wl_event_loop_create();
-
-	weston_layer_init(&ec->fade_layer, &ec->layer_list);
-	weston_layer_init(&ec->cursor_layer, &ec->fade_layer.link);
-
-	weston_compositor_schedule_repaint(ec);
-
 	return 0;
 }
 
@@ -4612,6 +4619,12 @@ weston_create_listening_socket(struct wl_display *display, const char *socket_na
 	return 0;
 }
 
+static void
+handle_terminate(struct weston_compositor *c)
+{
+	wl_display_terminate(c->wl_display);
+}
+
 int main(int argc, char *argv[])
 {
 	int ret = EXIT_SUCCESS;
@@ -4725,7 +4738,8 @@ int main(int argc, char *argv[])
 	}
 
 	ec->wl_display = display;
-	if (weston_compositor_init(ec, config) < 0) {
+	if (weston_compositor_init(ec) < 0 ||
+	    weston_compositor_init_config(ec, config) < 0) {
 		ret = EXIT_FAILURE;
 		goto out_signals;
 	}
@@ -4741,6 +4755,7 @@ int main(int argc, char *argv[])
 
 	ec->idle_time = idle_time;
 	ec->default_pointer_grab = NULL;
+	ec->terminate = handle_terminate;
 
 	for (i = 1; i < argc; i++)
 		weston_log("fatal: unhandled option: %s\n", argv[i]);
@@ -4807,15 +4822,7 @@ int main(int argc, char *argv[])
 	wl_display_run(display);
 
 out:
-	/* prevent further rendering while shutting down */
-	ec->state = WESTON_COMPOSITOR_OFFSCREEN;
-
-	wl_signal_emit(&ec->destroy_signal, ec);
-
-	weston_compositor_xkb_destroy(ec);
-
-	ec->backend->destroy(ec);
-	free(ec);
+	weston_compositor_destroy(ec);
 
 out_signals:
 	for (i = ARRAY_LENGTH(signals) - 1; i >= 0; i--)
@@ -4836,3 +4843,23 @@ out_signals:
 
 	return ret;
 }
+
+WL_EXPORT void
+weston_compositor_destroy(struct weston_compositor *ec)
+{
+	/* prevent further rendering while shutting down */
+	ec->state = WESTON_COMPOSITOR_OFFSCREEN;
+
+	wl_signal_emit(&ec->destroy_signal, ec);
+
+	weston_compositor_xkb_destroy(ec);
+
+	ec->backend->destroy(ec);
+	free(ec);
+}
+
+WL_EXPORT void
+weston_compositor_terminate(struct weston_compositor *ec)
+{
+	ec->terminate(ec);
+}
diff --git a/src/compositor.h b/src/compositor.h
index 75e3961..3fc8eaa 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -665,6 +665,8 @@ struct weston_compositor {
 	int32_t kb_repeat_delay;
 
 	clockid_t presentation_clock;
+
+	void (*terminate)(struct weston_compositor *c);
 };
 
 struct weston_buffer {
@@ -1253,9 +1255,12 @@ weston_buffer_reference(struct weston_buffer_reference *ref,
 uint32_t
 weston_compositor_get_time(void);
 
+void
+weston_compositor_destroy(struct weston_compositor *ec);
 int
-weston_compositor_init(struct weston_compositor *ec,
-		       struct weston_config *config);
+weston_compositor_init(struct weston_compositor *ec);
+void
+weston_compositor_terminate(struct weston_compositor *ec);
 int
 weston_compositor_set_presentation_clock(struct weston_compositor *compositor,
 					 clockid_t clk_id);
-- 
2.1.3



More information about the wayland-devel mailing list