From cebdf84c81cb56cd7e2670e4b6564ff1e09c85ff Mon Sep 17 00:00:00 2001 From: Matthew Waters Date: Sat, 28 Feb 2015 00:30:38 +1100 Subject: [PATCH] glcontext: store the thread current context --- gst-libs/gst/gl/gstglcontext.c | 26 ++++++++++++++++++++++++-- gst-libs/gst/gl/gstglcontext.h | 1 + 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/gst-libs/gst/gl/gstglcontext.c b/gst-libs/gst/gl/gstglcontext.c index c4d02c88fe..d05169f223 100644 --- a/gst-libs/gst/gl/gstglcontext.c +++ b/gst-libs/gst/gl/gstglcontext.c @@ -66,6 +66,8 @@ #endif GST_DEBUG_CATEGORY_STATIC (gst_performance); +static GPrivate current_context_key; + static GModule *module_self; static GOnce module_self_gonce = G_ONCE_INIT; @@ -630,8 +632,13 @@ gst_gl_context_activate (GstGLContext * context, gboolean activate) GST_OBJECT_LOCK (context); result = context_class->activate (context, activate); - context->priv->active_thread = result - && activate ? context->priv->gl_thread : NULL; + if (result && activate) { + context->priv->active_thread = g_thread_self (); + g_private_set (¤t_context_key, context); + } else { + context->priv->active_thread = NULL; + g_private_set (¤t_context_key, NULL); + } GST_OBJECT_UNLOCK (context); return result; @@ -1684,6 +1691,21 @@ gst_gl_context_check_feature (GstGLContext * context, const gchar * feature) return context_class->check_feature (context, feature); } +/** + * gst_gl_context_get_current: + * + * See also gst_gl_context_activate(). + * + * Returns: the #GstGLContext active in the current thread or %NULL + * + * Since: 1.6 + */ +GstGLContext * +gst_gl_context_get_current (void) +{ + return g_private_get (¤t_context_key); +} + 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 769737c4ff..63ba3d6e14 100644 --- a/gst-libs/gst/gl/gstglcontext.h +++ b/gst-libs/gst/gl/gstglcontext.h @@ -122,6 +122,7 @@ GstGLContext * gst_gl_context_new_wrapped (GstGLDisplay *display, gboolean gst_gl_context_activate (GstGLContext *context, gboolean activate); GThread * gst_gl_context_get_thread (GstGLContext *context); +GstGLContext * gst_gl_context_get_current (void); GstGLDisplay * gst_gl_context_get_display (GstGLContext *context); gpointer gst_gl_context_get_proc_address (GstGLContext *context, const gchar *name);