From 880b485d76c032877d6197fdde39f2763fa3cd3f Mon Sep 17 00:00:00 2001 From: Marius Vlad Date: Sun, 7 Apr 2019 17:07:58 +0300 Subject: [PATCH] libweston: Decouple weston_debug_compositor from weston_compositor This patch allows initialization of weston-debug/log framework much earlier than weston_compositor, which in turn will provide the option start logging before weston_compositor has been created. Signed-off-by: Marius Vlad --- compositor/main.c | 9 ++++++++- include/libweston/libweston.h | 9 +++++++-- libweston/compositor.c | 7 +++++-- libweston/weston-debug.c | 36 +++++++++++++++++++++++++---------- 4 files changed, 46 insertions(+), 15 deletions(-) diff --git a/compositor/main.c b/compositor/main.c index 280211e3..090bb251 100644 --- a/compositor/main.c +++ b/compositor/main.c @@ -2918,6 +2918,7 @@ int main(int argc, char *argv[]) struct wl_listener primary_client_destroyed; struct weston_seat *seat; struct wet_compositor wet = { 0 }; + struct weston_debug_compositor *wdc = NULL; int require_input; sigset_t mask; @@ -2961,6 +2962,12 @@ int main(int argc, char *argv[]) return EXIT_SUCCESS; } + wdc = weston_debug_compositor_create(); + if (!wdc) { + fprintf(stderr, "Failed to initialize weston debug framework.\n"); + return EXIT_FAILURE; + } + weston_log_set_handler(vlog, vlog_continue); weston_log_file_open(log); @@ -3025,7 +3032,7 @@ int main(int argc, char *argv[]) backend = weston_choose_default_backend(); } - wet.compositor = weston_compositor_create(display, &wet); + wet.compositor = weston_compositor_create(display, wdc, &wet); if (wet.compositor == NULL) { weston_log("fatal: failed to create compositor\n"); goto out; diff --git a/include/libweston/libweston.h b/include/libweston/libweston.h index 18870072..eb8e6be5 100644 --- a/include/libweston/libweston.h +++ b/include/libweston/libweston.h @@ -1982,7 +1982,8 @@ weston_compositor_print_scene_graph(struct weston_compositor *ec); void weston_compositor_destroy(struct weston_compositor *ec); struct weston_compositor * -weston_compositor_create(struct wl_display *display, void *user_data); +weston_compositor_create(struct wl_display *display, + struct weston_debug_compositor *wdc, void *user_data); enum weston_compositor_backend { WESTON_BACKEND_DRM, @@ -2376,8 +2377,12 @@ int weston_compositor_enable_touch_calibrator(struct weston_compositor *compositor, weston_touch_calibration_save_func save); +struct weston_debug_compositor * +weston_debug_compositor_create(void); + int -weston_debug_compositor_create(struct weston_compositor *compositor); +weston_debug_compositor_setup(struct weston_compositor *compositor, + struct weston_debug_compositor *wdc); void weston_debug_compositor_destroy(struct weston_compositor *compositor); diff --git a/libweston/compositor.c b/libweston/compositor.c index 4dc52ec3..050f37f6 100644 --- a/libweston/compositor.c +++ b/libweston/compositor.c @@ -6782,11 +6782,14 @@ debug_scene_graph_cb(struct weston_debug_stream *stream, void *data) * * \param display The Wayland display to be used. * \param user_data A pointer to an object that can later be retrieved + * \param wdc A pointer to weston_debug_compositor * using the \ref weston_compositor_get_user_data function. * \return The compositor instance on success or NULL on failure. */ WL_EXPORT struct weston_compositor * -weston_compositor_create(struct wl_display *display, void *user_data) +weston_compositor_create(struct wl_display *display, + struct weston_debug_compositor *wdc, + void *user_data) { struct weston_compositor *ec; struct wl_event_loop *loop; @@ -6840,7 +6843,7 @@ weston_compositor_create(struct wl_display *display, void *user_data) ec, bind_presentation)) goto fail; - if (weston_debug_compositor_create(ec) < 0) + if (weston_debug_compositor_setup(ec, wdc) < 0) goto fail; if (weston_input_init(ec) != 0) diff --git a/libweston/weston-debug.c b/libweston/weston-debug.c index 0536562a..f859ca85 100644 --- a/libweston/weston-debug.c +++ b/libweston/weston-debug.c @@ -253,6 +253,28 @@ bind_weston_debug(struct wl_client *client, } } +/** + * Connect weston-compositor structure to weston-debug structure + * an vice versa. + * + * \param compositor + * \param wdc + * \return 0 on success, -1 on failure + * + */ +int +weston_debug_compositor_setup(struct weston_compositor *compositor, + struct weston_debug_compositor *wdc) +{ + if (compositor->weston_debug) + return -1; + + wdc->compositor = compositor; + compositor->weston_debug = wdc; + + return 0; +} + /** Initialize weston-debug structure * * \param compositor The libweston compositor. @@ -264,24 +286,18 @@ bind_weston_debug(struct wl_client *client, * * \internal */ -int -weston_debug_compositor_create(struct weston_compositor *compositor) +WL_EXPORT struct weston_debug_compositor * +weston_debug_compositor_create(void) { struct weston_debug_compositor *wdc; - if (compositor->weston_debug) - return -1; - wdc = zalloc(sizeof *wdc); if (!wdc) - return -1; + return NULL; - wdc->compositor = compositor; wl_list_init(&wdc->scope_list); - compositor->weston_debug = wdc; - - return 0; + return wdc; } /** Destroy weston_debug_compositor structure