gl/window: remove use of main_context_push/pop_thread_default()
authorMatthew Waters <matthew@centricular.com>
Wed, 14 Dec 2016 13:59:45 +0000 (00:59 +1100)
committerMatthew Waters <matthew@centricular.com>
Thu, 15 Dec 2016 13:10:33 +0000 (00:10 +1100)
No-one's using/depending on it (it would have criticalled and not worked)
and it's causing more problems than it's solving.  Store the GMainContext
in the public struct instead for subclasses to optionally use instead of
relying on the push/pop state to be correct.

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

gst-libs/gst/gl/gstglwindow.c
gst-libs/gst/gl/gstglwindow.h
gst-libs/gst/gl/wayland/gstglwindow_wayland_egl.c
gst-libs/gst/gl/win32/gstglwindow_win32.c

index 7a275e4f574cf0f3374defd277a3cd830ed425e9..e037ad29312e34e33f5443e1fff064b9189444e4 100644 (file)
@@ -88,7 +88,6 @@ static gpointer gst_gl_window_navigation_thread (GstGLWindow * window);
 
 struct _GstGLWindowPrivate
 {
-  GMainContext *main_context;
   GMainLoop *loop;
 
   guint surface_width;
@@ -180,8 +179,8 @@ gst_gl_window_init (GstGLWindow * window)
   g_mutex_init (&window->priv->sync_message_lock);
   g_cond_init (&window->priv->sync_message_cond);
 
-  priv->main_context = g_main_context_new ();
-  priv->loop = g_main_loop_new (priv->main_context, FALSE);
+  window->main_context = g_main_context_new ();
+  priv->loop = g_main_loop_new (window->main_context, FALSE);
   priv->navigation_loop = NULL;
 }
 
@@ -329,8 +328,9 @@ gst_gl_window_finalize (GObject * object)
   if (priv->loop)
     g_main_loop_unref (priv->loop);
 
-  if (priv->main_context)
-    g_main_context_unref (priv->main_context);
+  if (window->main_context)
+    g_main_context_unref (window->main_context);
+  window->main_context = NULL;
 
   g_weak_ref_clear (&window->context_ref);
 
@@ -522,27 +522,11 @@ gst_gl_window_default_run (GstGLWindow * window)
 {
   GstGLWindowPrivate *priv = window->priv;
 
-  if (g_main_context_get_thread_default ()) {
-    if (priv->main_context)
-      g_main_context_unref (priv->main_context);
-    if (priv->loop)
-      g_main_loop_unref (priv->loop);
-    priv->main_context = g_main_context_ref_thread_default ();
-    priv->loop = NULL;
-    priv->alive = TRUE;
-  } else {
-    g_main_context_push_thread_default (priv->main_context);
-  }
+  g_main_context_push_thread_default (window->main_context);
 
   g_main_loop_run (priv->loop);
 
-  if (!priv->loop) {
-    priv->alive = FALSE;
-    g_main_context_unref (priv->main_context);
-    priv->main_context = NULL;
-  } else {
-    g_main_context_pop_thread_default (priv->main_context);
-  }
+  g_main_context_pop_thread_default (window->main_context);
 }
 
 /**
@@ -702,7 +686,7 @@ gst_gl_window_default_send_message_async (GstGLWindow * window,
   message->data = data;
   message->destroy = destroy;
 
-  g_main_context_invoke (priv->main_context, (GSourceFunc) _run_message_async,
+  g_main_context_invoke (window->main_context, (GSourceFunc) _run_message_async,
       message);
 }
 
index a5cc5b4b026d66c6a1760353969089517659d6a1..2aacac21d0954466cfe7dcf482d8c5396cedfcdc 100644 (file)
@@ -79,6 +79,7 @@ struct _GstGLWindow {
 
   guintptr      external_gl_context;
 
+  /*< protected >*/
   gboolean      is_drawing;
 
   GstGLWindowCB         draw;
@@ -93,6 +94,8 @@ struct _GstGLWindow {
 
   gboolean              queue_resize;
 
+  GMainContext         *main_context; /* default main_context */
+
   /*< private >*/
   GstGLWindowPrivate *priv;
 
index 6e1f0c5b8908ad3049e7431b12f705c7c396421a..338daed1dda45894a6bc460283de904e3e2f400c 100644 (file)
@@ -408,7 +408,7 @@ gst_gl_window_wayland_egl_open (GstGLWindow * window, GError ** error)
   if (!GST_GL_WINDOW_CLASS (parent_class)->open (window, error))
     return FALSE;
 
-  g_source_attach (window_egl->wl_source, g_main_context_get_thread_default ());
+  g_source_attach (window_egl->wl_source, window->main_context);
 
   return TRUE;
 }
index 2c919cd6a674b39d555cbbf4941290ef8d6f8824..8f31825d8bb323c81946f099c5b525026101d373 100644 (file)
@@ -120,8 +120,7 @@ gst_gl_window_win32_open (GstGLWindow * window, GError ** error)
   window_win32->msg_source = win32_message_source_new (window_win32);
   g_source_set_callback (window_win32->msg_source, (GSourceFunc) msg_cb,
       NULL, NULL);
-  g_source_attach (window_win32->msg_source,
-      g_main_context_get_thread_default ());
+  g_source_attach (window_win32->msg_source, window->main_context);
 
   return TRUE;
 }