glcontext: store the thread current context

This commit is contained in:
Matthew Waters 2015-02-28 00:30:38 +11:00 committed by Tim-Philipp Müller
parent abe21912f5
commit d44594c622
2 changed files with 25 additions and 2 deletions

View file

@ -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 (&current_context_key, context);
} else {
context->priv->active_thread = NULL;
g_private_set (&current_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 (&current_context_key);
}
static GstGLAPI
gst_gl_wrapped_context_get_gl_api (GstGLContext * context)
{

View file

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