[PATCH v21 04/18] ui/gdk: Restore original context after new context creation

Dmitry Osipenko posted 18 patches 1 month, 1 week ago
Maintainers: Pierrick Bouvier <pierrick.bouvier@linaro.org>, "Alex Bennée" <alex.bennee@linaro.org>, Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>, Dmitry Osipenko <dmitry.osipenko@collabora.com>, "Michael S. Tsirkin" <mst@redhat.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>
There is a newer version of this series
[PATCH v21 04/18] ui/gdk: Restore original context after new context creation
Posted by Dmitry Osipenko 1 month, 1 week 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-gl-area.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/ui/gtk-gl-area.c b/ui/gtk-gl-area.c
index c709b2ce0f63..ce49000d3f17 100644
--- a/ui/gtk-gl-area.c
+++ b/ui/gtk-gl-area.c
@@ -250,11 +250,13 @@ QEMUGLContext gd_gl_area_create_context(DisplayGLCtx *dgc,
                                         QEMUGLParams *params)
 {
     VirtualConsole *vc = container_of(dgc, VirtualConsole, gfx.dgc);
+    GdkGLContext *ctx, *current_ctx;
     GdkWindow *window;
-    GdkGLContext *ctx;
     GError *err = NULL;
     int major, minor;
 
+    current_ctx = gdk_gl_context_get_current();
+
     window = gtk_widget_get_window(vc->gfx.drawing_area);
     ctx = gdk_window_create_gl_context(window, &err);
     if (err) {
@@ -275,8 +277,12 @@ QEMUGLContext gd_gl_area_create_context(DisplayGLCtx *dgc,
 
     gdk_gl_context_make_current(ctx);
     gdk_gl_context_get_version(ctx, &major, &minor);
-    gdk_gl_context_clear_current();
-    gtk_gl_area_make_current(GTK_GL_AREA(vc->gfx.drawing_area));
+
+    if (current_ctx) {
+        gdk_gl_context_make_current(current_ctx);
+    } else {
+        gdk_gl_context_clear_current();
+    }
 
     if (gd_cmp_gl_context_version(major, minor, params) == -1) {
         /* created ctx version < requested version */
-- 
2.52.0
Re: [PATCH v21 04/18] ui/gdk: Restore original context after new context creation
Posted by Marc-André Lureau 1 month, 1 week ago
On Mon, Mar 2, 2026 at 4:04 PM Dmitry Osipenko
<dmitry.osipenko@collabora.com> 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>

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

> ---
>  ui/gtk-gl-area.c | 12 +++++++++---
>  1 file changed, 9 insertions(+), 3 deletions(-)
>
> diff --git a/ui/gtk-gl-area.c b/ui/gtk-gl-area.c
> index c709b2ce0f63..ce49000d3f17 100644
> --- a/ui/gtk-gl-area.c
> +++ b/ui/gtk-gl-area.c
> @@ -250,11 +250,13 @@ QEMUGLContext gd_gl_area_create_context(DisplayGLCtx *dgc,
>                                          QEMUGLParams *params)
>  {
>      VirtualConsole *vc = container_of(dgc, VirtualConsole, gfx.dgc);
> +    GdkGLContext *ctx, *current_ctx;
>      GdkWindow *window;
> -    GdkGLContext *ctx;
>      GError *err = NULL;
>      int major, minor;
>
> +    current_ctx = gdk_gl_context_get_current();
> +
>      window = gtk_widget_get_window(vc->gfx.drawing_area);
>      ctx = gdk_window_create_gl_context(window, &err);
>      if (err) {
> @@ -275,8 +277,12 @@ QEMUGLContext gd_gl_area_create_context(DisplayGLCtx *dgc,
>
>      gdk_gl_context_make_current(ctx);
>      gdk_gl_context_get_version(ctx, &major, &minor);
> -    gdk_gl_context_clear_current();
> -    gtk_gl_area_make_current(GTK_GL_AREA(vc->gfx.drawing_area));
> +
> +    if (current_ctx) {
> +        gdk_gl_context_make_current(current_ctx);
> +    } else {
> +        gdk_gl_context_clear_current();
> +    }
>
>      if (gd_cmp_gl_context_version(major, minor, params) == -1) {
>          /* created ctx version < requested version */
> --
> 2.52.0
>
>


-- 
Marc-André Lureau
Re: [PATCH v21 04/18] ui/gdk: Restore original context after new context creation
Posted by Dmitry Osipenko 1 month, 1 week ago
On 3/3/26 13:03, Marc-André Lureau wrote:
> On Mon, Mar 2, 2026 at 4:04 PM Dmitry Osipenko
> <dmitry.osipenko@collabora.com> 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>
> 
> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>

Thanks for the review

-- 
Best regards,
Dmitry