diff mbox series

ui/gtk: Make sure the right EGL context is currently bound

Message ID 20230628191504.17185-1-dongwon.kim@intel.com (mailing list archive)
State New, archived
Headers show
Series ui/gtk: Make sure the right EGL context is currently bound | expand

Commit Message

Kim, Dongwon June 28, 2023, 7:15 p.m. UTC
Observed a wrong context is bound when changing the scanout mode.
To prevent problem, it is needed to make sure to bind the right
context in gtk_egl_set_scanout_mode/gtk_gl_area_set_scanout_mode
as well as unbind one in the end of gd_egl_update/gd_gl_area_update.

Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Marc-André Lureau <marcandre.lureau@redhat.com>
Cc: Vivek Kasireddy <vivek.kasireddy@intel.com>
Signed-off-by: Dongwon Kim <dongwon.kim@intel.com>
---
 ui/gtk-egl.c     | 4 ++++
 ui/gtk-gl-area.c | 2 ++
 2 files changed, 6 insertions(+)

Comments

Marc-André Lureau July 4, 2023, 3:18 p.m. UTC | #1
On Wed, Jun 28, 2023 at 9:36 PM Dongwon Kim <dongwon.kim@intel.com> wrote:

> Observed a wrong context is bound when changing the scanout mode.
> To prevent problem, it is needed to make sure to bind the right
> context in gtk_egl_set_scanout_mode/gtk_gl_area_set_scanout_mode
> as well as unbind one in the end of gd_egl_update/gd_gl_area_update.
>
> Cc: Gerd Hoffmann <kraxel@redhat.com>
> Cc: Marc-André Lureau <marcandre.lureau@redhat.com>
> Cc: Vivek Kasireddy <vivek.kasireddy@intel.com>
> Signed-off-by: Dongwon Kim <dongwon.kim@intel.com>
>

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


> ---
>  ui/gtk-egl.c     | 4 ++++
>  ui/gtk-gl-area.c | 2 ++
>  2 files changed, 6 insertions(+)
>
> diff --git a/ui/gtk-egl.c b/ui/gtk-egl.c
> index 19130041bc..79f9f334f2 100644
> --- a/ui/gtk-egl.c
> +++ b/ui/gtk-egl.c
> @@ -31,6 +31,8 @@ static void gtk_egl_set_scanout_mode(VirtualConsole *vc,
> bool scanout)
>
>      vc->gfx.scanout_mode = scanout;
>      if (!vc->gfx.scanout_mode) {
> +        eglMakeCurrent(qemu_egl_display, vc->gfx.esurface,
> +                       vc->gfx.esurface, vc->gfx.ectx);
>          egl_fb_destroy(&vc->gfx.guest_fb);
>          if (vc->gfx.surface) {
>              surface_gl_destroy_texture(vc->gfx.gls, vc->gfx.ds);
> @@ -134,6 +136,8 @@ void gd_egl_update(DisplayChangeListener *dcl,
>                     vc->gfx.esurface, vc->gfx.ectx);
>      surface_gl_update_texture(vc->gfx.gls, vc->gfx.ds, x, y, w, h);
>      vc->gfx.glupdates++;
> +    eglMakeCurrent(qemu_egl_display, EGL_NO_SURFACE,
> +                   EGL_NO_SURFACE, EGL_NO_CONTEXT);
>  }
>
>  void gd_egl_refresh(DisplayChangeListener *dcl)
> diff --git a/ui/gtk-gl-area.c b/ui/gtk-gl-area.c
> index c384a1516b..285e661071 100644
> --- a/ui/gtk-gl-area.c
> +++ b/ui/gtk-gl-area.c
> @@ -26,6 +26,7 @@ static void gtk_gl_area_set_scanout_mode(VirtualConsole
> *vc, bool scanout)
>
>      vc->gfx.scanout_mode = scanout;
>      if (!vc->gfx.scanout_mode) {
> +        gtk_gl_area_make_current(GTK_GL_AREA(vc->gfx.drawing_area));
>          egl_fb_destroy(&vc->gfx.guest_fb);
>          if (vc->gfx.surface) {
>              surface_gl_destroy_texture(vc->gfx.gls, vc->gfx.ds);
> @@ -115,6 +116,7 @@ void gd_gl_area_update(DisplayChangeListener *dcl,
>      gtk_gl_area_make_current(GTK_GL_AREA(vc->gfx.drawing_area));
>      surface_gl_update_texture(vc->gfx.gls, vc->gfx.ds, x, y, w, h);
>      vc->gfx.glupdates++;
> +    gdk_gl_context_clear_current();
>  }
>
>  void gd_gl_area_refresh(DisplayChangeListener *dcl)
> --
> 2.34.1
>
>
>
diff mbox series

Patch

diff --git a/ui/gtk-egl.c b/ui/gtk-egl.c
index 19130041bc..79f9f334f2 100644
--- a/ui/gtk-egl.c
+++ b/ui/gtk-egl.c
@@ -31,6 +31,8 @@  static void gtk_egl_set_scanout_mode(VirtualConsole *vc, bool scanout)
 
     vc->gfx.scanout_mode = scanout;
     if (!vc->gfx.scanout_mode) {
+        eglMakeCurrent(qemu_egl_display, vc->gfx.esurface,
+                       vc->gfx.esurface, vc->gfx.ectx);
         egl_fb_destroy(&vc->gfx.guest_fb);
         if (vc->gfx.surface) {
             surface_gl_destroy_texture(vc->gfx.gls, vc->gfx.ds);
@@ -134,6 +136,8 @@  void gd_egl_update(DisplayChangeListener *dcl,
                    vc->gfx.esurface, vc->gfx.ectx);
     surface_gl_update_texture(vc->gfx.gls, vc->gfx.ds, x, y, w, h);
     vc->gfx.glupdates++;
+    eglMakeCurrent(qemu_egl_display, EGL_NO_SURFACE,
+                   EGL_NO_SURFACE, EGL_NO_CONTEXT);
 }
 
 void gd_egl_refresh(DisplayChangeListener *dcl)
diff --git a/ui/gtk-gl-area.c b/ui/gtk-gl-area.c
index c384a1516b..285e661071 100644
--- a/ui/gtk-gl-area.c
+++ b/ui/gtk-gl-area.c
@@ -26,6 +26,7 @@  static void gtk_gl_area_set_scanout_mode(VirtualConsole *vc, bool scanout)
 
     vc->gfx.scanout_mode = scanout;
     if (!vc->gfx.scanout_mode) {
+        gtk_gl_area_make_current(GTK_GL_AREA(vc->gfx.drawing_area));
         egl_fb_destroy(&vc->gfx.guest_fb);
         if (vc->gfx.surface) {
             surface_gl_destroy_texture(vc->gfx.gls, vc->gfx.ds);
@@ -115,6 +116,7 @@  void gd_gl_area_update(DisplayChangeListener *dcl,
     gtk_gl_area_make_current(GTK_GL_AREA(vc->gfx.drawing_area));
     surface_gl_update_texture(vc->gfx.gls, vc->gfx.ds, x, y, w, h);
     vc->gfx.glupdates++;
+    gdk_gl_context_clear_current();
 }
 
 void gd_gl_area_refresh(DisplayChangeListener *dcl)