Skip to contentSkip to conversation

ui/egl: reset framebuffer state when creating new EGL

PATCH In review [email protected] 2 participants 3 messages May 21

lore
Share & tools
lore
#0 lore raw

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

From: Dongwon Kim <[email protected]>

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 <[email protected]>
Cc Philippe Mathieu-Daudé <[email protected]>
Cc Daniel P. Berrangé <[email protected]>
---
 ui/gtk-egl.c | 6 ++++++
 1 file changed, 6 insertions(+)
ui/gtk-egl.c +6 -0
index 7c5c9b2428..fd14b391ed 100644
@@ -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);
Signature · 1 line
2.43.0
#1 lore raw

Hi

Quoted 25 lines · On Thu, May 21, 2026 at 4:48 AM <[email protected]> wrote:

From: Dongwon Kim <[email protected]>

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 <[email protected]>
Cc Philippe Mathieu-Daudé <[email protected]>
Cc Daniel P. Berrangé <[email protected]>
---
 ui/gtk-egl.c | 6 ++++++
 1 file changed, 6 insertions(+)
ui/gtk-egl.c +0 -0
index 7c5c9b2428..fd14b391ed 100644

ui/gtk-egl.c void gd_egl_refresh(DisplayChangeListener *dcl) · line 171

Quoted 9 lines
ui/gtk-egl.c +6 -0
@@ -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..

Signature · 1 line
Marc-André Lureau
#2 lore raw

Hi Marc-André,

Quoted 34 lines

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

Hi

Quoted 29 lines · On Thu, May 21, 2026 at 4:48 AM <[email protected]> wrote:

From: Dongwon Kim <[email protected]>

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 <[email protected]>
Cc Philippe Mathieu-Daudé <[email protected]>
Cc Daniel P. Berrangé <[email protected]>
---
 ui/gtk-egl.c | 6 ++++++
 1 file changed, 6 insertions(+)
ui/gtk-egl.c index 7c5c9b2428..fd14b391ed renamed from ui/gtk-egl.c +0 -0

100644

ui/gtk-egl.c +1 -0
@@ -163,6 +163,12 @@ void gd_egl_refresh(DisplayChangeListener *dcl)
             surface_gl_create_texture(vc->gfx.gls, vc->gfx.ds);
         }
 #ifdef CONFIG_GBM
+
Quoted 8 lines

ui/gtk-egl.c void gd_egl_refresh(DisplayChangeListener *dcl) · line 171

Quoted 5 lines
ui/gtk-egl.c +5 -0
+        /* 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()

Quoted 2 lines

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..)

Quoted 6 lines

--
Marc-André Lureau