~kennylevinsen/wlavu

d8ef3dba467dcc07e07f7dfb7458d86dade5cbb6 — Kenny Levinsen 7 months ago 526aec5 master
Only schedule frame callback from on_process

draw was called in the pipewire on_process callback, but this is not
safe as libpipewire runs on_process on a separate thread.

Instead, kickstart a frame callback loop if needed and let the
Wayland-side drive drawing on the main thread.
1 files changed, 10 insertions(+), 3 deletions(-)

M main.c
M main.c => main.c +10 -3
@@ 488,7 488,14 @@ static void on_process(void *userdata) {
	ctx->last_val = ctx->val;
	ctx->last_peak = ctx->peak;
	ctx->dirty = true;
	draw(ctx);

	if (!ctx->pending) {
		ctx->pending = true;
		struct wl_callback *callback = wl_surface_frame(ctx->surface);
		wl_callback_add_listener(callback, &frame_listener, ctx);
		wl_surface_commit(ctx->surface);
		wl_display_flush(ctx->display);
	}
}

static const struct pw_stream_events stream_events = {


@@ 626,8 633,8 @@ static int display_dispatch(struct pollfd *pfd, int polln, struct wl_display *di
	}

	pfd[EVENT_LOOP_WAYLAND].events = POLLOUT;
	while (wl_display_flush(display) == -1) {
		if (errno != EAGAIN && errno != EPIPE) {
	while (wl_display_flush(display) == -1 && errno != EPIPE) {
		if (errno != EAGAIN) {
			wl_display_cancel_read(display);
			return -1;
		}