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

Lukas Venhoda lvenhoda at redhat.com
Fri Jul 22 14:52:05 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.
---
Not needed for GtkGLArea, because it only supports egl.
---
 src/spice-widget.c | 41 ++++++++++++++++++-----------------------
 1 file changed, 18 insertions(+), 23 deletions(-)

diff --git a/src/spice-widget.c b/src/spice-widget.c
index c7dd553..aa61de8 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,6 +2610,7 @@ G_GNUC_INTERNAL
 void spice_display_widget_gl_scanout(SpiceDisplay *display)
 {
     SpiceDisplayPrivate *d = display->priv;
+    GError *err = NULL;
 
     SPICE_DEBUG("%s: got scanout",  __FUNCTION__);
     set_egl_enabled(display, true);
@@ -2649,6 +2627,23 @@ void spice_display_widget_gl_scanout(SpiceDisplay *display)
             g_critical("update scanout failed: %s", err->message);
             g_clear_error(&err);
         }
+    } else {
+        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
+
+    spice_display_widget_gl_scanout (display);
     }
 }
 
-- 
2.7.4



More information about the Spice-devel mailing list