waylandsink: Wait for the frame_cb to redraw and drop frames meanwhile
authorGeorge Kiagiadakis <george.kiagiadakis@collabora.com>
Fri, 7 Mar 2014 15:25:00 +0000 (17:25 +0200)
committerGeorge Kiagiadakis <george.kiagiadakis@collabora.com>
Tue, 17 Jun 2014 11:51:24 +0000 (13:51 +0200)
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
ext/wayland/gstwaylandsink.h

index 16258d5..db2c2e6 100644 (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);
 
index 60e75e8..06c2b2c 100644 (file)
@@ -61,6 +61,7 @@ struct _GstWaylandSink
 
   gchar *display_name;
 
+  gboolean redraw_pending;
   gboolean drawing_frozen;
   gboolean negotiated;
   GCond render_cond;