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
This commit is contained in:
Matthew Waters 2016-12-15 00:59:45 +11:00
parent b1fd1d34bd
commit f58eb98440
4 changed files with 13 additions and 27 deletions

View file

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

View file

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

View 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;
}

View 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;
}