From ab9eb432fb4d3636e3c77fab3baf47cda5b75f9f Mon Sep 17 00:00:00 2001 From: Matthew Waters Date: Tue, 21 Apr 2015 12:25:11 +1000 Subject: [PATCH] glwindow: track context activation properly We only need to deactivate/reactivate the context iff it was already active. --- gst-libs/gst/gl/gstglwindow.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/gst-libs/gst/gl/gstglwindow.c b/gst-libs/gst/gl/gstglwindow.c index f3b6ba2..42de9ab 100644 --- a/gst-libs/gst/gl/gstglwindow.c +++ b/gst-libs/gst/gl/gstglwindow.c @@ -300,12 +300,28 @@ _set_window_handle_cb (GstSetWindowHandleCb * data) { GstGLContext *context = gst_gl_window_get_context (data->window); GstGLWindowClass *window_class = GST_GL_WINDOW_GET_CLASS (data->window); + GThread *thread = NULL; + + /* deactivate if necessary */ + if (context) { + thread = gst_gl_context_get_thread (context); + if (thread) { + /* This is only thread safe iff the context thread == g_thread_self() */ + g_assert (thread == g_thread_self ()); + gst_gl_context_activate (context, FALSE); + } + } - gst_gl_context_activate (context, FALSE); window_class->set_window_handle (data->window, data->handle); - gst_gl_context_activate (context, TRUE); - gst_object_unref (context); + /* reactivate */ + if (context && thread) + gst_gl_context_activate (context, TRUE); + + if (context) + gst_object_unref (context); + if (thread) + g_thread_unref (thread); } static void -- 2.7.4