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...).
This commit is contained in:
George Kiagiadakis 2014-03-07 17:25:00 +02:00
parent 51a2c694ad
commit fabc5305be
2 changed files with 12 additions and 1 deletions

View file

@ -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);

View file

@ -61,6 +61,7 @@ struct _GstWaylandSink
gchar *display_name;
gboolean redraw_pending;
gboolean drawing_frozen;
gboolean negotiated;
GCond render_cond;