From: Dmitry Osipenko Date: Wed, 4 Mar 2026 16:50:29 +0000 (+0000) Subject: ui/sdl2: Restore original context after new context creation X-Git-Tag: v11.0.0-rc0~32^2~13 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2b0e2edc83662e6ab9d68cdaff151e232eee4d41;p=thirdparty%2Fqemu.git 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 Acked-by: Michael S. Tsirkin Tested-by: Alex Bennée Acked-by: Pierre-Eric Pelloux-Prayer Reviewed-by: Yiwei Zhang Signed-off-by: Dmitry Osipenko Message-ID: <20260303151422.977399-6-dmitry.osipenko@collabora.com> Message-ID: <20260304165043.1437519-8-alex.bennee@linaro.org> Signed-off-by: Alex Bennée --- diff --git a/ui/sdl2-gl.c b/ui/sdl2-gl.c index 5eca0248233..fbac3edbc09 100644 --- a/ui/sdl2-gl.c +++ b/ui/sdl2-gl.c @@ -139,10 +139,12 @@ QEMUGLContext sdl2_gl_create_context(DisplayGLCtx *dgc, QEMUGLParams *params) { struct sdl2_console *scon = container_of(dgc, struct sdl2_console, dgc); - SDL_GLContext ctx; + SDL_GLContext ctx, current_ctx; assert(scon->opengl); + current_ctx = SDL_GL_GetCurrentContext(); + SDL_GL_MakeCurrent(scon->real_window, scon->winctx); SDL_GL_SetAttribute(SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1); @@ -167,6 +169,9 @@ QEMUGLContext sdl2_gl_create_context(DisplayGLCtx *dgc, SDL_GL_CONTEXT_PROFILE_ES); ctx = SDL_GL_CreateContext(scon->real_window); } + + SDL_GL_MakeCurrent(scon->real_window, current_ctx); + return (QEMUGLContext)ctx; }