From fabc5305be5530e89ec351e9422918226185df89 Mon Sep 17 00:00:00 2001 From: George Kiagiadakis Date: Fri, 7 Mar 2014 17:25:00 +0200 Subject: [PATCH] waylandsink: Wait for the frame_cb to redraw and drop frames meanwhile We are not supposed to redraw until we receive a frame callback and this is especially useful to avoid allocating too many buffers while the window is not visible, because the compositor may not call wl_buffer.release until the window becomes visible (ok, this is a wayland bug, but...). --- ext/wayland/gstwaylandsink.c | 12 +++++++++++- ext/wayland/gstwaylandsink.h | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/ext/wayland/gstwaylandsink.c b/ext/wayland/gstwaylandsink.c index 16258d5..db2c2e6 100644 --- a/ext/wayland/gstwaylandsink.c +++ b/ext/wayland/gstwaylandsink.c @@ -499,7 +499,11 @@ gst_wayland_sink_preroll (GstBaseSink * bsink, GstBuffer * buffer) static void frame_redraw_callback (void *data, struct wl_callback *callback, uint32_t time) { + GstWaylandSink *sink = data; + GST_LOG ("frame_redraw_cb"); + + g_atomic_int_set (&sink->redraw_pending, FALSE); wl_callback_destroy (callback); } @@ -526,6 +530,10 @@ gst_wayland_sink_render (GstBaseSink * bsink, GstBuffer * buffer) if (sink->drawing_frozen || !sink->negotiated) goto done; + /* drop buffers until we get a frame callback */ + if (g_atomic_int_get (&sink->redraw_pending) == TRUE) + goto done; + meta = gst_buffer_get_wl_meta (buffer); if (meta && meta->pool->display == sink->display) { @@ -567,10 +575,12 @@ gst_wayland_sink_render (GstBaseSink * bsink, GstBuffer * buffer) * releases it. The release is handled internally in the pool */ gst_wayland_compositor_acquire_buffer (meta->pool, to_render); + g_atomic_int_set (&sink->redraw_pending, TRUE); + wl_surface_attach (surface, meta->wbuffer, 0, 0); wl_surface_damage (surface, 0, 0, res.w, res.h); callback = wl_surface_frame (surface); - wl_callback_add_listener (callback, &frame_callback_listener, NULL); + wl_callback_add_listener (callback, &frame_callback_listener, sink); wl_surface_commit (surface); wl_display_flush (sink->display->display); diff --git a/ext/wayland/gstwaylandsink.h b/ext/wayland/gstwaylandsink.h index 60e75e8..06c2b2c 100644 --- a/ext/wayland/gstwaylandsink.h +++ b/ext/wayland/gstwaylandsink.h @@ -61,6 +61,7 @@ struct _GstWaylandSink gchar *display_name; + gboolean redraw_pending; gboolean drawing_frozen; gboolean negotiated; GCond render_cond; -- 2.7.4