[Spice-devel] [spice-gtk PATCH v2] spice-widget: init egl only after first gl_scanout

Lukas Venhoda lvenhoda at redhat.com
Wed Jul 27 13:44:53 UTC 2016


When using GtkDrawingArea and EGL was not used, it was still initialized.
This produced warning messages on systems where EGL is not supported.

Move spice_egl_init from drawing_area_realize to gl_scanout.
Drawing_area_realize is no longer needed.
---
Changes since v1:
 - changed from recursive call to if check
 - moved set_egl_enabled(display, true); after initialisation is finished
---
 src/spice-widget.c | 42 +++++++++++++++++++-----------------------
 1 file changed, 19 insertions(+), 23 deletions(-)

diff --git a/src/spice-widget.c b/src/spice-widget.c
index c7dd553..feb2bcc 100644
--- a/src/spice-widget.c
+++ b/src/spice-widget.c
@@ -563,28 +563,6 @@ gl_area_realize(GtkGLArea *area, gpointer user_data)
 #endif
 #endif
 
-static void
-drawing_area_realize(GtkWidget *area, gpointer user_data)
-{
-#ifdef GDK_WINDOWING_X11
-    SpiceDisplay *display = SPICE_DISPLAY(user_data);
-    GError *err = NULL;
-
-    if (!GDK_IS_X11_DISPLAY(gdk_display_get_default()))
-        return;
-
-    if (!spice_egl_init(display, &err)) {
-        g_critical("egl init failed: %s", err->message);
-        g_clear_error(&err);
-    }
-
-    if (!spice_egl_realize_display(display, gtk_widget_get_window(area), &err)) {
-        g_critical("egl realize failed: %s", err->message);
-        g_clear_error(&err);
-    }
-#endif
-}
-
 static void spice_display_init(SpiceDisplay *display)
 {
     GtkWidget *widget = GTK_WIDGET(display);
@@ -599,7 +577,6 @@ static void spice_display_init(SpiceDisplay *display)
 
     g_object_connect(area,
                      "signal::draw", draw_event, display,
-                     "signal::realize", drawing_area_realize, display,
                      NULL);
     gtk_stack_add_named(d->stack, area, "draw-area");
     gtk_widget_set_double_buffered(area, true);
@@ -2633,8 +2610,27 @@ G_GNUC_INTERNAL
 void spice_display_widget_gl_scanout(SpiceDisplay *display)
 {
     SpiceDisplayPrivate *d = display->priv;
+    GError *err = NULL;
 
     SPICE_DEBUG("%s: got scanout",  __FUNCTION__);
+
+    if (!d->egl.context_ready) {
+        if (!spice_egl_init(display, &err)) {
+            g_critical("egl init failed: %s", err->message);
+            g_clear_error(&err);
+        }
+    
+#ifdef GDK_WINDOWING_X11
+        if (GDK_IS_X11_DISPLAY(gdk_display_get_default())) {
+            GtkWidget *area = gtk_stack_get_child_by_name(d->stack, "draw-area");
+            if (!spice_egl_realize_display(display, gtk_widget_get_window(area), &err)) {
+                g_critical("egl realize failed: %s", err->message);
+                g_clear_error(&err);
+            }
+        }
+#endif
+    }
+
     set_egl_enabled(display, true);
 
     if (d->egl.context_ready) {
-- 
2.7.4



More information about the Spice-devel mailing list