diff --git a/libweston/backend-drm/drm.c b/libweston/backend-drm/drm.c index 8f58e4618..17013edfb 100644 --- a/libweston/backend-drm/drm.c +++ b/libweston/backend-drm/drm.c @@ -1215,16 +1215,17 @@ drm_repaint_flush(struct weston_backend *backend) { struct drm_backend *b = container_of(backend, struct drm_backend, base); struct drm_device *device; + FILE *dbg; WESTON_TRACE_FUNC(); wl_list_for_each(device, &b->kms_list, link) drm_repaint_flush_device(device); - if (weston_log_scope_is_enabled(b->debug)) { - char *dbg = weston_compositor_print_scene_graph(b->compositor); - drm_debug(b, "%s", dbg); - free(dbg); + dbg = weston_log_scope_stream(b->debug); + if (dbg) { + weston_compositor_print_scene_graph(b->compositor, dbg); + fflush(dbg); } } diff --git a/libweston/compositor.c b/libweston/compositor.c index 2f198f03c..8a4d84054 100644 --- a/libweston/compositor.c +++ b/libweston/compositor.c @@ -9759,25 +9759,25 @@ debug_scene_view_print_tree(struct weston_view *view, FILE *fp) * Output information on how libweston is currently composing the scene * graph. * + * \param ec The compositor has a single scene-graph. + * \param fp A writable stream where the scene-graph is printed. + * Can also be NULL to skip printing. + * * \ingroup compositor */ -WL_EXPORT char * -weston_compositor_print_scene_graph(struct weston_compositor *ec) +WL_EXPORT void +weston_compositor_print_scene_graph(struct weston_compositor *ec, FILE *fp) { struct weston_output *output; struct weston_layer *layer; struct timespec now; int layer_idx = 0; - FILE *fp; - char *ret; - size_t len; - int err; + + if (!fp) + return; WESTON_TRACE_FUNC(); - fp = open_memstream(&ret, &len); - assert(fp); - weston_compositor_read_presentation_clock(ec, &now); fprintf(fp, "Weston scene graph at %" PRId64 ".%09ld:\n\n", (int64_t)now.tv_sec, now.tv_nsec); @@ -9849,11 +9849,6 @@ weston_compositor_print_scene_graph(struct weston_compositor *ec) fprintf(fp, "\n"); } - - err = fclose(fp); - assert(err == 0); - - return ret; } static void @@ -9891,6 +9886,7 @@ static void debug_scene_graph_cb(struct weston_log_subscription *sub, void *data) { struct weston_compositor *ec = data; + FILE *fp; char *str; /* If the presentation_clock is CLOCK_REALTIME, then it is @@ -9899,7 +9895,9 @@ debug_scene_graph_cb(struct weston_log_subscription *sub, void *data) if (ec->presentation_clock == CLOCK_REALTIME) return; - str = weston_compositor_print_scene_graph(ec); + fp = open_memstream(&str, NULL); + weston_compositor_print_scene_graph(ec, fp); + fclose(fp); weston_log_subscription_write(sub, str, strlen(str)); free(str); diff --git a/libweston/libweston-internal.h b/libweston/libweston-internal.h index ebd1cbed9..7e0ebb049 100644 --- a/libweston/libweston-internal.h +++ b/libweston/libweston-internal.h @@ -329,8 +329,8 @@ weston_compositor_dmabuf_can_scanout(struct weston_compositor *compositor, void weston_compositor_offscreen(struct weston_compositor *compositor); -char * -weston_compositor_print_scene_graph(struct weston_compositor *ec); +void +weston_compositor_print_scene_graph(struct weston_compositor *ec, FILE *fp); void weston_compositor_read_presentation_clock(