glcontext: add a method to add a context to another share group
authorMatthew Waters <matthew@centricular.com>
Thu, 25 Feb 2016 21:34:11 +0000 (08:34 +1100)
committerMatthew Waters <matthew@centricular.com>
Thu, 25 Feb 2016 23:59:04 +0000 (10:59 +1100)
Intended for use with wrapped contexts that are created shared with gst's
gl contexts in order to manage the internal sharegroup state correctly.

e.g. with caopengllayer (which is used in glimagesink and caopengllayersink
on OS X), we create a CGL context from the gst context and the sharing state
was not being correctly set on either GL context and gst_gl_context_is_shared()
was always returning FALSE.

With 11fb4fff80b63b9d67a731d4bb238b6c0a29d774 only flushing with multiple
shared contexts, the required flush was not occuring causing screen
corruption or stuttering.

Note: this didn't affect GST_GL_API=opengl pipelines

https://bugzilla.gnome.org/show_bug.cgi?id=762620

gst-libs/gst/gl/cocoa/gstglcaopengllayer.m
gst-libs/gst/gl/gstglcontext.c
gst-libs/gst/gl/gstglcontext.h

index cc82c3c..a11700d 100644 (file)
@@ -126,6 +126,7 @@ _context_ready (gpointer data)
   }
 
   gst_gl_context_activate (self->draw_context, TRUE);
+  gst_gl_context_set_shared_with (self->draw_context, self->gst_gl_context);
   if (!gst_gl_context_fill_info (self->draw_context, &error)) {
     GST_ERROR ("failed to fill wrapped context information: %s", error->message);
     return NULL;
index 88526bd..2c208ed 100644 (file)
@@ -1617,11 +1617,38 @@ gboolean
 gst_gl_context_is_shared (GstGLContext * context)
 {
   g_return_val_if_fail (GST_IS_GL_CONTEXT (context), FALSE);
-  g_return_val_if_fail (context->priv->alive, FALSE);
+  if (GST_IS_GL_WRAPPED_CONTEXT (context))
+    g_return_val_if_fail (context->priv->active_thread, FALSE);
+  else
+    g_return_val_if_fail (context->priv->alive, FALSE);
 
   return _context_share_group_is_shared (context->priv->sharegroup);
 }
 
+/**
+ * gst_gl_context_set_shared_with:
+ * @context: a wrapped #GstGLContext
+ * @share: another #GstGLContext
+ *
+ * Will internally set @context as shared with @share
+ *
+ * Since: 1.8
+ */
+void
+gst_gl_context_set_shared_with (GstGLContext * context, GstGLContext * share)
+{
+  g_return_if_fail (GST_IS_GL_CONTEXT (context));
+  g_return_if_fail (GST_IS_GL_CONTEXT (share));
+  g_return_if_fail (!gst_gl_context_is_shared (context));
+  /* XXX: may be a little too strict */
+  g_return_if_fail (GST_IS_GL_WRAPPED_CONTEXT (context));
+
+  if (context->priv->sharegroup)
+    _context_share_group_unref (context->priv->sharegroup);
+  context->priv->sharegroup =
+      _context_share_group_ref (share->priv->sharegroup);
+}
+
 static GstGLAPI
 gst_gl_wrapped_context_get_gl_api (GstGLContext * context)
 {
index 64464aa..4d91732 100644 (file)
@@ -149,6 +149,7 @@ guintptr      gst_gl_context_get_current_gl_context     (GstGLPlatform platform)
 GstGLAPI      gst_gl_context_get_current_gl_api         (GstGLPlatform platform, guint *major, guint *minor);
 
 gboolean      gst_gl_context_is_shared                  (GstGLContext * context);
+void          gst_gl_context_set_shared_with            (GstGLContext * context, GstGLContext * share);
 
 gboolean gst_gl_context_fill_info (GstGLContext * context, GError ** error);