libweston: print scene-graph into FILE

Being able to print the scene-graph straight into a FILE removes one
temporary memory allocation that used to be mandatory. That memory
allocation is now gone from the DRM-backend debug log. It has moved into
the scene-graph log scope. In the case of
weston_log_subscription_printf() it shouldn't matter, because it is only
used when new subscribers appear.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
This commit is contained in:
Pekka Paalanen 2026-03-02 12:04:04 +02:00 committed by Pekka Paalanen
parent 60567e7bd6
commit e9665ef36f
3 changed files with 20 additions and 21 deletions

View file

@ -1215,16 +1215,17 @@ drm_repaint_flush(struct weston_backend *backend)
{ {
struct drm_backend *b = container_of(backend, struct drm_backend, base); struct drm_backend *b = container_of(backend, struct drm_backend, base);
struct drm_device *device; struct drm_device *device;
FILE *dbg;
WESTON_TRACE_FUNC(); WESTON_TRACE_FUNC();
wl_list_for_each(device, &b->kms_list, link) wl_list_for_each(device, &b->kms_list, link)
drm_repaint_flush_device(device); drm_repaint_flush_device(device);
if (weston_log_scope_is_enabled(b->debug)) { dbg = weston_log_scope_stream(b->debug);
char *dbg = weston_compositor_print_scene_graph(b->compositor); if (dbg) {
drm_debug(b, "%s", dbg); weston_compositor_print_scene_graph(b->compositor, dbg);
free(dbg); fflush(dbg);
} }
} }

View file

@ -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 * Output information on how libweston is currently composing the scene
* graph. * 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 * \ingroup compositor
*/ */
WL_EXPORT char * WL_EXPORT void
weston_compositor_print_scene_graph(struct weston_compositor *ec) weston_compositor_print_scene_graph(struct weston_compositor *ec, FILE *fp)
{ {
struct weston_output *output; struct weston_output *output;
struct weston_layer *layer; struct weston_layer *layer;
struct timespec now; struct timespec now;
int layer_idx = 0; int layer_idx = 0;
FILE *fp;
char *ret; if (!fp)
size_t len; return;
int err;
WESTON_TRACE_FUNC(); WESTON_TRACE_FUNC();
fp = open_memstream(&ret, &len);
assert(fp);
weston_compositor_read_presentation_clock(ec, &now); weston_compositor_read_presentation_clock(ec, &now);
fprintf(fp, "Weston scene graph at %" PRId64 ".%09ld:\n\n", fprintf(fp, "Weston scene graph at %" PRId64 ".%09ld:\n\n",
(int64_t)now.tv_sec, now.tv_nsec); (int64_t)now.tv_sec, now.tv_nsec);
@ -9849,11 +9849,6 @@ weston_compositor_print_scene_graph(struct weston_compositor *ec)
fprintf(fp, "\n"); fprintf(fp, "\n");
} }
err = fclose(fp);
assert(err == 0);
return ret;
} }
static void static void
@ -9891,6 +9886,7 @@ static void
debug_scene_graph_cb(struct weston_log_subscription *sub, void *data) debug_scene_graph_cb(struct weston_log_subscription *sub, void *data)
{ {
struct weston_compositor *ec = data; struct weston_compositor *ec = data;
FILE *fp;
char *str; char *str;
/* If the presentation_clock is CLOCK_REALTIME, then it is /* 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) if (ec->presentation_clock == CLOCK_REALTIME)
return; 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)); weston_log_subscription_write(sub, str, strlen(str));
free(str); free(str);

View file

@ -329,8 +329,8 @@ weston_compositor_dmabuf_can_scanout(struct weston_compositor *compositor,
void void
weston_compositor_offscreen(struct weston_compositor *compositor); weston_compositor_offscreen(struct weston_compositor *compositor);
char * void
weston_compositor_print_scene_graph(struct weston_compositor *ec); weston_compositor_print_scene_graph(struct weston_compositor *ec, FILE *fp);
void void
weston_compositor_read_presentation_clock( weston_compositor_read_presentation_clock(