[Spice-devel] [PATCH spice-gtk v2 2/8] egl: check context is ready

Marc-André Lureau marcandre.lureau at gmail.com
Tue Mar 22 12:57:09 UTC 2016


Add a new GL status field to check if the GL context is ready. This
helps debugging races where GL is called before the context is ready.

Signed-off-by: Marc-André Lureau <marcandre.lureau at gmail.com>
---
 src/spice-widget-egl.c  | 10 ++++++++--
 src/spice-widget-priv.h |  1 +
 src/spice-widget.c      |  5 +++++
 3 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/src/spice-widget-egl.c b/src/spice-widget-egl.c
index a9bea52..8ac3b90 100644
--- a/src/spice-widget-egl.c
+++ b/src/spice-widget-egl.c
@@ -208,7 +208,7 @@ gboolean spice_egl_init(SpiceDisplay *display, GError **err)
         d->egl.ctx = eglGetCurrentContext();
         dpy = (EGLNativeDisplayType)gdk_wayland_display_get_wl_display(gdk_dpy);
         d->egl.display = eglGetDisplay(dpy);
-        return spice_egl_init_shaders(display, err);
+        goto end;
     }
 #endif
 #ifdef GDK_WINDOWING_X11
@@ -267,7 +267,13 @@ gboolean spice_egl_init(SpiceDisplay *display, GError **err)
     eglMakeCurrent(d->egl.display, EGL_NO_SURFACE, EGL_NO_SURFACE,
                    d->egl.ctx);
 
-    return spice_egl_init_shaders(display, err);
+end:
+    if (!spice_egl_init_shaders(display, err))
+        return FALSE;
+
+    d->egl.context_ready = TRUE;
+
+    return TRUE;
 }
 
 static gboolean spice_widget_init_egl_win(SpiceDisplay *display, GdkWindow *win,
diff --git a/src/spice-widget-priv.h b/src/spice-widget-priv.h
index 2f7e39e..bafeb7d 100644
--- a/src/spice-widget-priv.h
+++ b/src/spice-widget-priv.h
@@ -129,6 +129,7 @@ struct _SpiceDisplayPrivate {
 #endif
 #ifndef G_OS_WIN32
     struct {
+        gboolean            context_ready;
         gboolean            enabled;
         EGLSurface          surface;
         EGLDisplay          display;
diff --git a/src/spice-widget.c b/src/spice-widget.c
index c8bb72c..8518ec6 100644
--- a/src/spice-widget.c
+++ b/src/spice-widget.c
@@ -2486,6 +2486,8 @@ static void gl_scanout(SpiceDisplay *display)
     const SpiceGlScanout *scanout;
     GError *err = NULL;
 
+    g_return_if_fail(d->egl.context_ready);
+
     scanout = spice_display_get_gl_scanout(SPICE_DISPLAY_CHANNEL(d->display));
     g_return_if_fail(scanout != NULL);
 
@@ -2504,8 +2506,11 @@ static void gl_draw(SpiceDisplay *display,
     SpiceDisplayPrivate *d = display->priv;
 
     SPICE_DEBUG("%s",  __FUNCTION__);
+
     set_egl_enabled(display, true);
 
+    g_return_if_fail(d->egl.context_ready);
+
 #if GTK_CHECK_VERSION(3,16,0)
     GtkWidget *gl = gtk_stack_get_child_by_name(GTK_STACK(display), "gl-area");
 
-- 
2.5.0



More information about the Spice-devel mailing list