[PATCH] ui/egl: reset framebuffer state when creating new EGL

dongwon.kim@intel.com posted 1 patch 1 week, 2 days ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20260521004226.1914121-1-dongwon.kim@intel.com
Maintainers: "Marc-André Lureau" <marcandre.lureau@redhat.com>
ui/gtk-egl.c | 6 ++++++
1 file changed, 6 insertions(+)
[PATCH] ui/egl: reset framebuffer state when creating new EGL
Posted by dongwon.kim@intel.com 1 week, 2 days ago
From: Dongwon Kim <dongwon.kim@intel.com>

When an old EGL context is destroyed, its associated OpenGL textures 
and framebuffer resource IDs are already implicitly freed by the 
driver. However, the cached IDs and geometry attributes stored within 
the egl_fb structures remain stale and invalid for the new context.

Call egl_fb_destroy() on the guest, cursor, and window framebuffers 
in gd_egl_refresh() to safely clear these stale fields back to zero 
before they are re-initialized under the new current context.

Cc: Marc-André Lureau <marcandre.lureau@redhat.com>
Cc: Philippe Mathieu-Daudé <philmd@linaro.org>
Cc: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Dongwon Kim <dongwon.kim@intel.com>
---
 ui/gtk-egl.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/ui/gtk-egl.c b/ui/gtk-egl.c
index 7c5c9b2428..fd14b391ed 100644
--- a/ui/gtk-egl.c
+++ b/ui/gtk-egl.c
@@ -163,6 +163,12 @@ void gd_egl_refresh(DisplayChangeListener *dcl)
             surface_gl_create_texture(vc->gfx.gls, vc->gfx.ds);
         }
 #ifdef CONFIG_GBM
+
+        /* resetting old ids to 0 for new egl context */
+        egl_fb_destroy(&vc->gfx.guest_fb);
+        egl_fb_destroy(&vc->gfx.cursor_fb);
+        egl_fb_destroy(&vc->gfx.win_fb);
+
         if (vc->gfx.guest_fb.dmabuf) {
             egl_dmabuf_release_texture(vc->gfx.guest_fb.dmabuf);
             gd_egl_scanout_dmabuf(dcl, vc->gfx.guest_fb.dmabuf);
-- 
2.43.0


Re: [PATCH] ui/egl: reset framebuffer state when creating new EGL
Posted by Marc-André Lureau 1 week, 2 days ago
Hi

On Thu, May 21, 2026 at 4:48 AM <dongwon.kim@intel.com> wrote:
>
> From: Dongwon Kim <dongwon.kim@intel.com>
>
> When an old EGL context is destroyed, its associated OpenGL textures
> and framebuffer resource IDs are already implicitly freed by the
> driver. However, the cached IDs and geometry attributes stored within
> the egl_fb structures remain stale and invalid for the new context.
>
> Call egl_fb_destroy() on the guest, cursor, and window framebuffers
> in gd_egl_refresh() to safely clear these stale fields back to zero
> before they are re-initialized under the new current context.
>
> Cc: Marc-André Lureau <marcandre.lureau@redhat.com>
> Cc: Philippe Mathieu-Daudé <philmd@linaro.org>
> Cc: Daniel P. Berrangé <berrange@redhat.com>
> Signed-off-by: Dongwon Kim <dongwon.kim@intel.com>
> ---
>  ui/gtk-egl.c | 6 ++++++
>  1 file changed, 6 insertions(+)
>
> diff --git a/ui/gtk-egl.c b/ui/gtk-egl.c
> index 7c5c9b2428..fd14b391ed 100644
> --- a/ui/gtk-egl.c
> +++ b/ui/gtk-egl.c
> @@ -163,6 +163,12 @@ void gd_egl_refresh(DisplayChangeListener *dcl)
>              surface_gl_create_texture(vc->gfx.gls, vc->gfx.ds);
>          }
>  #ifdef CONFIG_GBM
> +
> +        /* resetting old ids to 0 for new egl context */
> +        egl_fb_destroy(&vc->gfx.guest_fb);
> +        egl_fb_destroy(&vc->gfx.cursor_fb);
> +        egl_fb_destroy(&vc->gfx.win_fb);
> +

Hmm.. It looks like the whole block is flawed.. All the destruction
should be done before the new context is created in gd_egl_init(). Or
was gd_egl_init() intended to be called only once? Tbh, this is X11
stuff I think we should get rid of..




-- 
Marc-André Lureau
RE: [PATCH] ui/egl: reset framebuffer state when creating new EGL
Posted by Kim, Dongwon 1 week, 1 day ago
Hi Marc-André,

> Subject: Re: [PATCH] ui/egl: reset framebuffer state when creating new EGL
> 
> Hi
> 
> On Thu, May 21, 2026 at 4:48 AM <dongwon.kim@intel.com> wrote:
> >
> > From: Dongwon Kim <dongwon.kim@intel.com>
> >
> > When an old EGL context is destroyed, its associated OpenGL textures
> > and framebuffer resource IDs are already implicitly freed by the
> > driver. However, the cached IDs and geometry attributes stored within
> > the egl_fb structures remain stale and invalid for the new context.
> >
> > Call egl_fb_destroy() on the guest, cursor, and window framebuffers in
> > gd_egl_refresh() to safely clear these stale fields back to zero
> > before they are re-initialized under the new current context.
> >
> > Cc: Marc-André Lureau <marcandre.lureau@redhat.com>
> > Cc: Philippe Mathieu-Daudé <philmd@linaro.org>
> > Cc: Daniel P. Berrangé <berrange@redhat.com>
> > Signed-off-by: Dongwon Kim <dongwon.kim@intel.com>
> > ---
> >  ui/gtk-egl.c | 6 ++++++
> >  1 file changed, 6 insertions(+)
> >
> > diff --git a/ui/gtk-egl.c b/ui/gtk-egl.c index 7c5c9b2428..fd14b391ed
> > 100644
> > --- a/ui/gtk-egl.c
> > +++ b/ui/gtk-egl.c
> > @@ -163,6 +163,12 @@ void gd_egl_refresh(DisplayChangeListener *dcl)
> >              surface_gl_create_texture(vc->gfx.gls, vc->gfx.ds);
> >          }
> >  #ifdef CONFIG_GBM
> > +
> > +        /* resetting old ids to 0 for new egl context */
> > +        egl_fb_destroy(&vc->gfx.guest_fb);
> > +        egl_fb_destroy(&vc->gfx.cursor_fb);
> > +        egl_fb_destroy(&vc->gfx.win_fb);
> > +
> 
> Hmm.. It looks like the whole block is flawed.. All the destruction should be
> done before the new context is created in gd_egl_init().

Yeah the best thing is to destroy and reset all egl/gl references before destroying
EGL Context. Then we will introduce a new function that cleans up and call it
from gtk.c where eglDestroyContext are called. We can go with this route.

 Or was gd_egl_init()
> intended to be called only once? Tbh, this is X11 stuff I think we should get rid
> of..

gd_egl_init is designed to be called after whenever gtk window is closed or created
(when context is destroyed..) 

> 
> 
> 
> 
> --
> Marc-André Lureau