@samitouri / QOSamiQemu / commits / 2b0e2edc83

ui/sdl2: Restore original context after new context creation

SDL API changes GL context to a newly created GL context, which differs from other GL providers that don't switch context. Change SDL backend to restore the original GL context. This allows Qemu's virtio-gpu to support new virglrenderer async-fencing feature for Virgl contexts, otherwise virglrenderer's vrend creates a fence-sync context on the Qemu's main-loop thread that erroneously stays in-use by the main-loop after creation, not allowing vrend's fence-sync thread switch to this new context that belongs to it. Reviewed-by: Akihiko Odaki <akihiko.odaki@daynix.com> Acked-by: Michael S. Tsirkin <mst@redhat.com> Tested-by: Alex Bennée <alex.bennee@linaro.org> Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com> Reviewed-by: Yiwei Zhang <zzyiwei@gmail.com> Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com> Message-ID: <20260303151422.977399-6-dmitry.osipenko@collabora.com> Message-ID: <20260304165043.1437519-8-alex.bennee@linaro.org> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

Dmitry Osipenko committed Mar 4, 2026 at 16:50 UTC 2b0e2edc83662e6ab9d68cdaff151e232eee4d41
1 file changed +6 -1
ui/sdl2-gl.c
+6 -1
@@ -139,10 +139,12 @@ QEMUGLContext sdl2_gl_create_context(DisplayGLCtx *dgc,
139 QEMUGLParams *params)
140 {
141 struct sdl2_console *scon = container_of(dgc, struct sdl2_console, dgc);
142 - SDL_GLContext ctx;
142 + SDL_GLContext ctx, current_ctx;
143
144 assert(scon->opengl);
145
146 + current_ctx = SDL_GL_GetCurrentContext();
147 +
148 SDL_GL_MakeCurrent(scon->real_window, scon->winctx);
149
150 SDL_GL_SetAttribute(SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1);
@@ -167,6 +169,9 @@ QEMUGLContext sdl2_gl_create_context(DisplayGLCtx *dgc,
169 SDL_GL_CONTEXT_PROFILE_ES);
170 ctx = SDL_GL_CreateContext(scon->real_window);
171 }
172 +
173 + SDL_GL_MakeCurrent(scon->real_window, current_ctx);
174 +
175 return (QEMUGLContext)ctx;
176 }
177