[Spice-devel] [PATCH v3 2/9] egl: check context is ready

Marc-André Lureau marcandre.lureau at gmail.com
Thu Mar 24 11:32:36 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>
Acked-by: Pavel Grunt <pgrunt at redhat.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 3bdc806..151970c 100644
--- a/src/spice-widget-egl.c
+++ b/src/spice-widget-egl.c
@@ -207,7 +207,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
@@ -266,7 +266,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 2a64443..f8bc160 100644
--- a/src/spice-widget.c
+++ b/src/spice-widget.c
@@ -2500,6 +2500,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);
 
@@ -2518,8 +2520,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.5



More information about the Spice-devel mailing list