[PATCH v20 02/21] ui/gtk: Restore original context after new context creation

Dmitry Osipenko posted 21 patches 11 hours ago
Maintainers: Pierrick Bouvier <pierrick.bouvier@linaro.org>, "Michael S. Tsirkin" <mst@redhat.com>, "Alex Bennée" <alex.bennee@linaro.org>, Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>, Dmitry Osipenko <dmitry.osipenko@collabora.com>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>, "Daniel P. Berrangé" <berrange@redhat.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>
[PATCH v20 02/21] ui/gtk: Restore original context after new context creation
Posted by Dmitry Osipenko 11 hours ago
Get currently bound GL context when creating new GL context and restore
it after the creation for consistency with behavior expected by virglrenderer
that assumes context-creation doesn't switch context.

Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
---
 ui/gtk-egl.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/ui/gtk-egl.c b/ui/gtk-egl.c
index 0dbb429958e5..be769bcbfbb1 100644
--- a/ui/gtk-egl.c
+++ b/ui/gtk-egl.c
@@ -218,10 +218,17 @@ QEMUGLContext gd_egl_create_context(DisplayGLCtx *dgc,
                                     QEMUGLParams *params)
 {
     VirtualConsole *vc = container_of(dgc, VirtualConsole, gfx.dgc);
+    QEMUGLContext ctx, current_context = eglGetCurrentContext();
 
     eglMakeCurrent(qemu_egl_display, vc->gfx.esurface,
                    vc->gfx.esurface, vc->gfx.ectx);
-    return qemu_egl_create_context(dgc, params);
+
+    ctx = qemu_egl_create_context(dgc, params);
+
+    eglMakeCurrent(qemu_egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE,
+                   current_context);
+
+    return ctx;
 }
 
 void gd_egl_scanout_disable(DisplayChangeListener *dcl)
-- 
2.52.0
Re: [PATCH v20 02/21] ui/gtk: Restore original context after new context creation
Posted by Akihiko Odaki 2 hours ago
On 2026/03/02 5:48, Dmitry Osipenko wrote:
> Get currently bound GL context when creating new GL context and restore
> it after the creation for consistency with behavior expected by virglrenderer
> that assumes context-creation doesn't switch context.
> 
> Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
> ---
>   ui/gtk-egl.c | 9 ++++++++-
>   1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/ui/gtk-egl.c b/ui/gtk-egl.c
> index 0dbb429958e5..be769bcbfbb1 100644
> --- a/ui/gtk-egl.c
> +++ b/ui/gtk-egl.c
> @@ -218,10 +218,17 @@ QEMUGLContext gd_egl_create_context(DisplayGLCtx *dgc,
>                                       QEMUGLParams *params)
>   {
>       VirtualConsole *vc = container_of(dgc, VirtualConsole, gfx.dgc);
> +    QEMUGLContext ctx, current_context = eglGetCurrentContext();
>   
>       eglMakeCurrent(qemu_egl_display, vc->gfx.esurface,
>                      vc->gfx.esurface, vc->gfx.ectx);
> -    return qemu_egl_create_context(dgc, params);
> +
> +    ctx = qemu_egl_create_context(dgc, params);

I think it's better to change qemu_egl_create_context() not to require 
eglMakeCurrent().

Regards,
Akihiko Odaki

> +
> +    eglMakeCurrent(qemu_egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE,
> +                   current_context);
> +
> +    return ctx;
>   }
>   
>   void gd_egl_scanout_disable(DisplayChangeListener *dcl)