[PATCH] ui/gtk-egl: Check EGLSurface before doing scanout

Antonio Caggiano posted 1 patch 7 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20231013151758.1472603-1-quic._5Facaggian@quicinc.com
Maintainers: Gerd Hoffmann <kraxel@redhat.com>, "Marc-André Lureau" <marcandre.lureau@redhat.com>
There is a newer version of this series
ui/gtk-egl.c | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)
[PATCH] ui/gtk-egl: Check EGLSurface before doing scanout
Posted by Antonio Caggiano 7 months ago
The first time gd_egl_scanout_texture() is called, there's a possibility
that the GTK drawing area might not be realized yet, in which case its
associated GdkWindow is NULL. This means gd_egl_init() was also skipped
and the EGLContext and EGLSurface stored in the VirtualGfxConsole are
not valid yet.

Continuing with the scanout in this conditions would result in hitting
an assert in libepoxy: "Couldn't find current GLX or EGL context".

A possible workaround is to just ignore the scanout request, giving the
the GTK drawing area some time to finish its realization. At that point,
the gd_egl_init() will succeed and the EGLContext and EGLSurface stored
in the VirtualGfxConsole will be valid.

Signed-off-by: Antonio Caggiano <quic_acaggian@quicinc.com>
---
 ui/gtk-egl.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/ui/gtk-egl.c b/ui/gtk-egl.c
index a1060fd80f..2eefcd2cf4 100644
--- a/ui/gtk-egl.c
+++ b/ui/gtk-egl.c
@@ -243,12 +243,19 @@ void gd_egl_scanout_texture(DisplayChangeListener *dcl,
     vc->gfx.h = h;
     vc->gfx.y0_top = backing_y_0_top;
 
-    eglMakeCurrent(qemu_egl_display, vc->gfx.esurface,
-                   vc->gfx.esurface, vc->gfx.ectx);
+    if (!vc->gfx.esurface) {
+        gd_egl_init(vc);
+        if (!vc->gfx.esurface) {
+            return;
+        }
 
-    gtk_egl_set_scanout_mode(vc, true);
-    egl_fb_setup_for_tex(&vc->gfx.guest_fb, backing_width, backing_height,
-                         backing_id, false);
+        eglMakeCurrent(qemu_egl_display, vc->gfx.esurface,
+                       vc->gfx.esurface, vc->gfx.ectx);
+    
+        gtk_egl_set_scanout_mode(vc, true);
+        egl_fb_setup_for_tex(&vc->gfx.guest_fb, backing_width, backing_height,
+                             backing_id, false);
+    }
 }
 
 void gd_egl_scanout_dmabuf(DisplayChangeListener *dcl,
-- 
2.25.1
Re: [PATCH] ui/gtk-egl: Check EGLSurface before doing scanout
Posted by Marc-André Lureau 7 months ago
Hi

On Fri, Oct 13, 2023 at 7:18 PM Antonio Caggiano
<quic_acaggian@quicinc.com> wrote:
>
> The first time gd_egl_scanout_texture() is called, there's a possibility
> that the GTK drawing area might not be realized yet, in which case its
> associated GdkWindow is NULL. This means gd_egl_init() was also skipped
> and the EGLContext and EGLSurface stored in the VirtualGfxConsole are
> not valid yet.
>
> Continuing with the scanout in this conditions would result in hitting
> an assert in libepoxy: "Couldn't find current GLX or EGL context".
>
> A possible workaround is to just ignore the scanout request, giving the
> the GTK drawing area some time to finish its realization. At that point,
> the gd_egl_init() will succeed and the EGLContext and EGLSurface stored
> in the VirtualGfxConsole will be valid.
>
> Signed-off-by: Antonio Caggiano <quic_acaggian@quicinc.com>
> ---
>  ui/gtk-egl.c | 17 ++++++++++++-----
>  1 file changed, 12 insertions(+), 5 deletions(-)
>
> diff --git a/ui/gtk-egl.c b/ui/gtk-egl.c
> index a1060fd80f..2eefcd2cf4 100644
> --- a/ui/gtk-egl.c
> +++ b/ui/gtk-egl.c
> @@ -243,12 +243,19 @@ void gd_egl_scanout_texture(DisplayChangeListener *dcl,
>      vc->gfx.h = h;
>      vc->gfx.y0_top = backing_y_0_top;
>
> -    eglMakeCurrent(qemu_egl_display, vc->gfx.esurface,
> -                   vc->gfx.esurface, vc->gfx.ectx);
> +    if (!vc->gfx.esurface) {
> +        gd_egl_init(vc);
> +        if (!vc->gfx.esurface) {
> +            return;
> +        }
>
> -    gtk_egl_set_scanout_mode(vc, true);
> -    egl_fb_setup_for_tex(&vc->gfx.guest_fb, backing_width, backing_height,
> -                         backing_id, false);
> +        eglMakeCurrent(qemu_egl_display, vc->gfx.esurface,
> +                       vc->gfx.esurface, vc->gfx.ectx);
> +

trailing whitespace

> +        gtk_egl_set_scanout_mode(vc, true);
> +        egl_fb_setup_for_tex(&vc->gfx.guest_fb, backing_width, backing_height,
> +                             backing_id, false);
> +    }
>  }
>
>  void gd_egl_scanout_dmabuf(DisplayChangeListener *dcl,

otherwise, lgtm
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>

-- 
Marc-André Lureau