Skip to contentSkip to conversation

ui/gtk-egl: un-tab and re-tab should destroy egl surface and context

PATCH In review Dongwon Kim 2 participants 8 messages Jul 3, 2021 – Jul 16, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 ui/gtk-egl: un-tab and re-tab should destroy egl surface and context

An old esurface should be destroyed and set to be NULL when doing un-tab and re-tab so that a new esurface an context can be created for the window widget that those will be bound to.

---
 ui/gtk.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
ui/gtk.c +16 -0
index 98046f577b..bfb95f3b4b 100644
@@ -1232,6 +1232,14 @@ static gboolean gd_tab_window_close(GtkWidget *widget, GdkEvent *event,
                                     vc->tab_item, vc->label);
     gtk_widget_destroy(vc->window);
     vc->window = NULL;
+    if (vc->gfx.esurface) {
+        eglDestroySurface(qemu_egl_display, vc->gfx.esurface);
+        vc->gfx.esurface = NULL;
+    }
+    if (vc->gfx.ectx) {
+        eglDestroyContext(qemu_egl_display, vc->gfx.ectx);
+        vc->gfx.ectx = NULL;
+    }
     return TRUE;
 }
 
@@ -1261,6 +1269,14 @@ static void gd_menu_untabify(GtkMenuItem *item, void *opaque)
     if (!vc->window) {
         gtk_widget_set_sensitive(vc->menu_item, false);
         vc->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+        if (vc->gfx.esurface) {
+            eglDestroySurface(qemu_egl_display, vc->gfx.esurface);
+            vc->gfx.esurface = NULL;
+        }
+        if (vc->gfx.esurface) {
+            eglDestroyContext(qemu_egl_display, vc->gfx.ectx);
+            vc->gfx.ectx = NULL;
+        }
         gd_widget_reparent(s->notebook, vc->window, vc->tab_item);
 
         g_signal_connect(vc->window, "delete-event",
Signature · 1 line
2.17.1
#1 lore raw

PATCH 2/3 ui/gtk-egl: make sure the right context is set as the current

Making the vc->gfx.ectx current before handling textures associated with it

---
 ui/gtk-egl.c | 8 ++++++++
 1 file changed, 8 insertions(+)
ui/gtk-egl.c +8 -0
index 2a2e6d3a17..32516b806c 100644
@@ -126,6 +126,7 @@ void gd_egl_refresh(DisplayChangeListener *dcl)
         }
         vc->gfx.gls = qemu_gl_init_shader();
         if (vc->gfx.ds) {
+            surface_gl_destroy_texture(vc->gfx.gls, vc->gfx.ds);
             surface_gl_create_texture(vc->gfx.gls, vc->gfx.ds);
         }
     }
@@ -152,6 +153,8 @@ void gd_egl_switch(DisplayChangeListener *dcl,
         surface_height(vc->gfx.ds) == surface_height(surface)) {
         resized = false;
     }
+    eglMakeCurrent(qemu_egl_display, vc->gfx.esurface,
+                   vc->gfx.esurface, vc->gfx.ectx);
 
     surface_gl_destroy_texture(vc->gfx.gls, vc->gfx.ds);
     vc->gfx.ds = surface;
@@ -209,6 +212,11 @@ void gd_egl_scanout_dmabuf(DisplayChangeListener *dcl,
                            QemuDmaBuf *dmabuf)
 {
 #ifdef CONFIG_GBM
+    VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
+
+    eglMakeCurrent(qemu_egl_display, vc->gfx.esurface,
+                   vc->gfx.esurface, vc->gfx.ectx);
+
     egl_dmabuf_import_texture(dmabuf);
     if (!dmabuf->texture) {
         return;
Signature · 1 line
2.17.1
#2 lore raw

RE: [PATCH 2/3] ui/gtk-egl: make sure the right context is set as the current

Quoted 52 lines

-----Original Message-----
From: Qemu-devel <[email protected]> On Behalf Of Dongwon Kim
Sent: Friday, July 02, 2021 5:28 PM
To: [email protected]
Cc: Kim, Dongwon <[email protected]>
Subject: [PATCH 2/3] ui/gtk-egl: make sure the right context is set as the current

Making the vc->gfx.ectx current before handling textures associated with it

---
 ui/gtk-egl.c | 8 ++++++++
 1 file changed, 8 insertions(+)
ui/gtk-egl.c +8 -1
index 2a2e6d3a17..32516b806c 100644
@@ -126,6 +126,7 @@ void gd_egl_refresh(DisplayChangeListener *dcl)
         }
         vc->gfx.gls = qemu_gl_init_shader();
         if (vc->gfx.ds) {
+            surface_gl_destroy_texture(vc->gfx.gls, vc->gfx.ds);
             surface_gl_create_texture(vc->gfx.gls, vc->gfx.ds);
         }
     }
@@ -152,6 +153,8 @@ void gd_egl_switch(DisplayChangeListener *dcl,
         surface_height(vc->gfx.ds) == surface_height(surface)) {
         resized = false;
     }
+    eglMakeCurrent(qemu_egl_display, vc->gfx.esurface,
+                   vc->gfx.esurface, vc->gfx.ectx);
 
     surface_gl_destroy_texture(vc->gfx.gls, vc->gfx.ds);
     vc->gfx.ds = surface;
@@ -209,6 +212,11 @@ void gd_egl_scanout_dmabuf(DisplayChangeListener *dcl,
                            QemuDmaBuf *dmabuf)
 {
 #ifdef CONFIG_GBM
+    VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
+
+    eglMakeCurrent(qemu_egl_display, vc->gfx.esurface,
+                   vc->gfx.esurface, vc->gfx.ectx);
+
     egl_dmabuf_import_texture(dmabuf);
     if (!dmabuf->texture) {
         return;
--

2.17.1

#3 lore raw

PATCH 3/3 ui/gtk: gd_draw_event returns FALSE when no cairo surface is bound

In reply to Dongwon Kim

gd_draw_event shouldn't try to repaint if surface does not exist for the VC.

---
 ui/gtk.c | 3 +++
 1 file changed, 3 insertions(+)
ui/gtk.c +3 -0
index bfb95f3b4b..0a38deedc7 100644
@@ -756,6 +756,9 @@ static gboolean gd_draw_event(GtkWidget *widget, cairo_t *cr, void *opaque)
     if (!vc->gfx.ds) {
         return FALSE;
     }
+    if (!vc->gfx.surface) {
+        return FALSE;
+    }
 
     vc->gfx.dcl.update_interval =
         gd_monitor_update_interval(vc->window ? vc->window : s->window);
Signature · 1 line
2.17.1
#4 lore raw

PATCH 4/4 ui/gtk-egl: guest fb texture needs to be regenerated when reinitializing egl

If guest fb is backed by dmabuf (blob-resource), the texture bound to the old context needs to be recreated in case the egl is re-initialized (e.g. new window for vc is created in case of detaching/reattaching of the tab)

---
 ui/gtk-egl.c | 4 ++++
 1 file changed, 4 insertions(+)
ui/gtk-egl.c +4 -0
index 32516b806c..5dd7c7e1f5 100644
@@ -129,6 +129,10 @@ void gd_egl_refresh(DisplayChangeListener *dcl)
             surface_gl_destroy_texture(vc->gfx.gls, vc->gfx.ds);
             surface_gl_create_texture(vc->gfx.gls, vc->gfx.ds);
         }
+        if (vc->gfx.guest_fb.dmabuf) {
+            vc->gfx.guest_fb.dmabuf->texture = 0;
+            gd_egl_scanout_dmabuf(dcl, vc->gfx.guest_fb.dmabuf);
+        }
     }
 
     graphic_hw_update(dcl->con);
Signature · 1 line
2.17.1
#5 lore raw

RE: [PATCH 4/4] ui/gtk-egl: guest fb texture needs to be regenerated when reinitializing egl

Quoted 14 lines

If guest fb is backed by dmabuf (blob-resource), the texture bound to the old context needs to be recreated in case the egl is re-initialized (e.g.
new window for vc is created in case of detaching/reattaching of the tab)

---
 ui/gtk-egl.c | 4 ++++
 1 file changed, 4 insertions(+)

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

Quoted 5 lines
ui/gtk-egl.c +2 -0
@@ -129,6 +129,10 @@ void gd_egl_refresh(DisplayChangeListener *dcl)
             surface_gl_destroy_texture(vc->gfx.gls, vc->gfx.ds);
             surface_gl_create_texture(vc->gfx.gls, vc->gfx.ds);
         }
+        if (vc->gfx.guest_fb.dmabuf) {
+            vc->gfx.guest_fb.dmabuf->texture = 0;

[Kasireddy, Vivek] Shouldn't you call egl_dmabuf_release_texture() instead?

Thanks,
Vivek

Quoted 8 lines
ui/gtk-egl.c +2 -1
+            gd_egl_scanout_dmabuf(dcl, vc->gfx.guest_fb.dmabuf);
+        }
     }
 
     graphic_hw_update(dcl->con);
--

2.17.1

Reviewed-by on v1 3/3
#6 lore raw

RE: [PATCH 3/3] ui/gtk: gd_draw_event returns FALSE when no cairo surface is bound

In reply to Dongwon Kim
Quoted 35 lines

-----Original Message-----
From: Qemu-devel <[email protected]> On Behalf Of Dongwon Kim
Sent: Friday, July 02, 2021 5:28 PM
To: [email protected]
Cc: Kim, Dongwon <[email protected]>
Subject: [PATCH 3/3] ui/gtk: gd_draw_event returns FALSE when no cairo surface is bound

gd_draw_event shouldn't try to repaint if surface does not exist for the VC.

---
 ui/gtk.c | 3 +++
 1 file changed, 3 insertions(+)
ui/gtk.c +3 -0
index bfb95f3b4b..0a38deedc7 100644
@@ -756,6 +756,9 @@ static gboolean gd_draw_event(GtkWidget *widget, cairo_t *cr,
 void *opaque)
     if (!vc->gfx.ds) {
         return FALSE;
     }
+    if (!vc->gfx.surface) {
+        return FALSE;
+    }
 
     vc->gfx.dcl.update_interval =
         gd_monitor_update_interval(vc->window ? vc->window : s->window);

--
2.17.1

Reviewed-by on v1 1/3
#7 lore raw
In reply to Dongwon Kim
Quoted 58 lines

-----Original Message-----
From: Qemu-devel <[email protected]> On Behalf Of Dongwon Kim
Sent: Friday, July 02, 2021 5:28 PM
To: [email protected]
Cc: Romli, Khairul Anuar <[email protected]>; Kim, Dongwon <[email protected]>
Subject: [PATCH 1/3] ui/gtk-egl: un-tab and re-tab should destroy egl surface and context

An old esurface should be destroyed and set to be NULL when doing un-tab and re-tab so that a new esurface an context can be created for the window widget that those will be bound to.

---
 ui/gtk.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
ui/gtk.c +16 -0
index 98046f577b..bfb95f3b4b 100644
@@ -1232,6 +1232,14 @@ static gboolean gd_tab_window_close(GtkWidget *widget,
 GdkEvent *event,
                                     vc->tab_item, vc->label);
     gtk_widget_destroy(vc->window);
     vc->window = NULL;
+    if (vc->gfx.esurface) {
+        eglDestroySurface(qemu_egl_display, vc->gfx.esurface);
+        vc->gfx.esurface = NULL;
+    }
+    if (vc->gfx.ectx) {
+        eglDestroyContext(qemu_egl_display, vc->gfx.ectx);
+        vc->gfx.ectx = NULL;
+    }
     return TRUE;
 }
@@ -1261,6 +1269,14 @@ static void gd_menu_untabify(GtkMenuItem *item, void
 *opaque)
     if (!vc->window) {
         gtk_widget_set_sensitive(vc->menu_item, false);
         vc->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+        if (vc->gfx.esurface) {
+            eglDestroySurface(qemu_egl_display, vc->gfx.esurface);
+            vc->gfx.esurface = NULL;
+        }
+        if (vc->gfx.esurface) {
+            eglDestroyContext(qemu_egl_display, vc->gfx.ectx);
+            vc->gfx.ectx = NULL;
+        }
         gd_widget_reparent(s->notebook, vc->window, vc->tab_item);
 
         g_signal_connect(vc->window, "delete-event",

--
2.17.1