From 5f87cc0b65a1e6d03e1b32355ed6c9c2cbb6d74f Mon Sep 17 00:00:00 2001 From: Matthew Waters Date: Fri, 26 Feb 2016 08:34:11 +1100 Subject: [PATCH] glcontext: add a method to add a context to another share group 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 | 1 + gst-libs/gst/gl/gstglcontext.c | 29 +++++++++++++++++++++- gst-libs/gst/gl/gstglcontext.h | 1 + 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/gst-libs/gst/gl/cocoa/gstglcaopengllayer.m b/gst-libs/gst/gl/cocoa/gstglcaopengllayer.m index cc82c3c2c6..a11700d245 100644 --- a/gst-libs/gst/gl/cocoa/gstglcaopengllayer.m +++ b/gst-libs/gst/gl/cocoa/gstglcaopengllayer.m @@ -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; diff --git a/gst-libs/gst/gl/gstglcontext.c b/gst-libs/gst/gl/gstglcontext.c index 88526bde27..2c208edd09 100644 --- a/gst-libs/gst/gl/gstglcontext.c +++ b/gst-libs/gst/gl/gstglcontext.c @@ -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) { diff --git a/gst-libs/gst/gl/gstglcontext.h b/gst-libs/gst/gl/gstglcontext.h index 64464aa2c3..4d917323d4 100644 --- a/gst-libs/gst/gl/gstglcontext.h +++ b/gst-libs/gst/gl/gstglcontext.h @@ -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);