From f532e699df06bc0466517f2170e095712975644a Mon Sep 17 00:00:00 2001 From: Matthew Waters Date: Thu, 15 Dec 2016 00:59:45 +1100 Subject: [PATCH] gl/window: remove use of main_context_push/pop_thread_default() 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 | 32 +++++-------------- gst-libs/gst/gl/gstglwindow.h | 3 ++ .../gst/gl/wayland/gstglwindow_wayland_egl.c | 2 +- gst-libs/gst/gl/win32/gstglwindow_win32.c | 3 +- 4 files changed, 13 insertions(+), 27 deletions(-) diff --git a/gst-libs/gst/gl/gstglwindow.c b/gst-libs/gst/gl/gstglwindow.c index 5752ae2d41..1e1be6d09d 100644 --- a/gst-libs/gst/gl/gstglwindow.c +++ b/gst-libs/gst/gl/gstglwindow.c @@ -87,7 +87,6 @@ static void gst_gl_window_default_send_message_async (GstGLWindow * window, struct _GstGLWindowPrivate { - GMainContext *main_context; GMainLoop *loop; guint surface_width; @@ -168,8 +167,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); } static void @@ -294,8 +293,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); @@ -484,27 +484,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); } /** @@ -664,7 +648,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); } diff --git a/gst-libs/gst/gl/gstglwindow.h b/gst-libs/gst/gl/gstglwindow.h index 9aaef05e87..ccb19efcb2 100644 --- a/gst-libs/gst/gl/gstglwindow.h +++ b/gst-libs/gst/gl/gstglwindow.h @@ -85,6 +85,7 @@ struct _GstGLWindow { GstGLDisplay *display; GWeakRef context_ref; + /*< protected >*/ gboolean is_drawing; GstGLWindowCB draw; @@ -99,6 +100,8 @@ struct _GstGLWindow { gboolean queue_resize; + GMainContext *main_context; /* default main_context */ + /*< private >*/ GstGLWindowPrivate *priv; diff --git a/gst-libs/gst/gl/wayland/gstglwindow_wayland_egl.c b/gst-libs/gst/gl/wayland/gstglwindow_wayland_egl.c index 5d2efc956a..933ddfe41d 100644 --- a/gst-libs/gst/gl/wayland/gstglwindow_wayland_egl.c +++ b/gst-libs/gst/gl/wayland/gstglwindow_wayland_egl.c @@ -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; } diff --git a/gst-libs/gst/gl/win32/gstglwindow_win32.c b/gst-libs/gst/gl/win32/gstglwindow_win32.c index c306a6b064..dd11745444 100644 --- a/gst-libs/gst/gl/win32/gstglwindow_win32.c +++ b/gst-libs/gst/gl/win32/gstglwindow_win32.c @@ -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; }