[PATCH weston v2 04/17] compositor: add API to manage compositor instances
Giulio Camuffo
giuliocamuffo at gmail.com
Thu Dec 4 13:01:10 PST 2014
---
src/compositor-drm.c | 2 +-
src/compositor-wayland.c | 4 +--
src/compositor-x11.c | 2 +-
src/compositor.c | 86 +++++++++++++++++++++++++++++++-----------------
src/compositor.h | 9 +++--
5 files changed, 67 insertions(+), 36 deletions(-)
diff --git a/src/compositor-drm.c b/src/compositor-drm.c
index e72fc05..f94c1b7 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 d8148a6..1c572e9 100644
--- a/src/compositor-wayland.c
+++ b/src/compositor-wayland.c
@@ -1376,7 +1376,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);
@@ -1821,7 +1821,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 9521e32..a4cf859 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 8811336..237f2dc 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -4009,12 +4009,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);
@@ -4066,6 +4063,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);
@@ -4088,21 +4110,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;
}
@@ -4140,7 +4147,7 @@ weston_compositor_exit_with_code(struct weston_compositor *compositor,
if (compositor->exit_code == EXIT_SUCCESS)
compositor->exit_code = exit_code;
- wl_display_terminate(compositor->wl_display);
+ weston_compositor_terminate(compositor);
}
WL_EXPORT void
@@ -4687,6 +4694,11 @@ weston_transform_to_string(uint32_t output_transform)
return "<illegal value>";
}
+static void
+handle_terminate(struct weston_compositor *c)
+{
+ wl_display_terminate(c->wl_display);
+}
int main(int argc, char *argv[])
{
@@ -4801,7 +4813,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;
}
@@ -4822,6 +4835,7 @@ int main(int argc, char *argv[])
ec->idle_time = idle_time;
ec->default_pointer_grab = NULL;
ec->exit_code = EXIT_SUCCESS;
+ ec->terminate = handle_terminate;
for (i = 1; i < argc; i++)
weston_log("fatal: unhandled option: %s\n", argv[i]);
@@ -4896,15 +4910,7 @@ int main(int argc, char *argv[])
ret = ec->exit_code;
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--)
@@ -4925,3 +4931,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 b5fdba4..a45fc5b 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -667,6 +667,8 @@ struct weston_compositor {
clockid_t presentation_clock;
int exit_code;
+
+ void (*terminate)(struct weston_compositor *c);
};
struct weston_buffer {
@@ -1255,9 +1257,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