[Spice-devel] [spice-gtk PATCH v2] spice-widget: init egl only after first gl_scanout
Lukas Venhoda
lvenhoda at redhat.com
Thu Jul 28 12:39:35 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.
---
Changes since v2:
- added drawing_area_realized variable
- only enable egl after spice-widget is fully realized
- moved more of the code inside GDK_WINDOWING_X11 guard
Changes since v1:
- changed from recursive call to if check
- moved set_egl_enabled(display, true); after initialisation is finished
---
src/spice-widget-priv.h | 3 +++
src/spice-widget.c | 34 +++++++++++++++++++++-------------
2 files changed, 24 insertions(+), 13 deletions(-)
diff --git a/src/spice-widget-priv.h b/src/spice-widget-priv.h
index e36baf3..4b905f1 100644
--- a/src/spice-widget-priv.h
+++ b/src/spice-widget-priv.h
@@ -129,6 +129,9 @@ struct _SpiceDisplayPrivate {
#endif
#ifndef G_OS_WIN32
struct {
+#ifdef GDK_WINDOWING_X11
+ gboolean drawing_area_realized;
+#endif
gboolean context_ready;
gboolean enabled;
EGLSurface surface;
diff --git a/src/spice-widget.c b/src/spice-widget.c
index 9020b07..adbbfd2 100644
--- a/src/spice-widget.c
+++ b/src/spice-widget.c
@@ -568,20 +568,9 @@ 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);
- }
+ if (GDK_IS_X11_DISPLAY(gdk_display_get_default()))
+ display->priv->egl.drawing_area_realized = TRUE;
#endif
}
@@ -2662,8 +2651,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__);
+
+#ifdef GDK_WINDOWING_X11
+ if (GDK_IS_X11_DISPLAY(gdk_display_get_default()) &&
+ !d->egl.context_ready &&
+ d->egl.drawing_area_realized) {
+ if (!spice_egl_init(display, &err)) {
+ g_critical("egl init failed: %s", err->message);
+ g_clear_error(&err);
+ }
+
+ 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