Each thread may have its own context (having the same context shared with several threads is wrong).
Signed-off-by: Marc-André Lureau <marcandre.lur...@redhat.com> --- hw/display/virtio-gpu-3d.c | 9 ++++++++- hw/display/virtio-gpu.c | 2 +- ui/console.c | 5 +++-- ui/gtk-egl.c | 9 ++++++--- ui/gtk-gl-area.c | 3 ++- ui/sdl2-gl.c | 7 +++++-- ui/spice-display.c | 10 +++++++--- include/ui/console.h | 6 ++++-- include/ui/gtk.h | 6 ++++-- include/ui/sdl2.h | 3 ++- 10 files changed, 42 insertions(+), 18 deletions(-) diff --git a/hw/display/virtio-gpu-3d.c b/hw/display/virtio-gpu-3d.c index 6381e78..8f068b5 100644 --- a/hw/display/virtio-gpu-3d.c +++ b/hw/display/virtio-gpu-3d.c @@ -543,11 +543,18 @@ virgl_create_context(void *opaque, int scanout_idx, VirtIOGPU *g = opaque; QEMUGLContext ctx; QEMUGLParams qparams; + bool make_current = true; qparams.major_ver = params->major_ver; qparams.minor_ver = params->minor_ver; - ctx = dpy_gl_ctx_create(g->scanout[scanout_idx].con, &qparams); + if (g->thread_ctx) { + dpy_gl_ctx_make_current(g->scanout[scanout_idx].con, g->thread_ctx); + make_current = false; + } + + ctx = dpy_gl_ctx_create(g->scanout[scanout_idx].con, + &qparams, make_current); return (virgl_renderer_gl_context)ctx; } diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c index a238090..9a768c5 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -968,7 +968,7 @@ static void virtio_gpu_gl_register(DisplayChangeListener *dcl, } if (g->iothread && !g->thread_ctx) { - g->thread_ctx = dpy_gl_ctx_create(dcl->con, &qparams); + g->thread_ctx = dpy_gl_ctx_create(dcl->con, &qparams, true); } } diff --git a/ui/console.c b/ui/console.c index a2e410e..5174a3f 100644 --- a/ui/console.c +++ b/ui/console.c @@ -1693,10 +1693,11 @@ bool dpy_gl_ctx_is_mt_safe(QemuConsole *con) } QEMUGLContext dpy_gl_ctx_create(QemuConsole *con, - struct QEMUGLParams *qparams) + struct QEMUGLParams *qparams, + bool make_current) { assert(con->gl); - return con->gl->ops->dpy_gl_ctx_create(con->gl, qparams); + return con->gl->ops->dpy_gl_ctx_create(con->gl, qparams, make_current); } void dpy_gl_ctx_destroy(QemuConsole *con, QEMUGLContext ctx) diff --git a/ui/gtk-egl.c b/ui/gtk-egl.c index 3f5d328..5bc0ef4 100644 --- a/ui/gtk-egl.c +++ b/ui/gtk-egl.c @@ -161,12 +161,15 @@ void gd_egl_switch(DisplayChangeListener *dcl, } QEMUGLContext gd_egl_create_context(DisplayChangeListener *dcl, - QEMUGLParams *params) + QEMUGLParams *params, + bool make_current) { VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl); - eglMakeCurrent(qemu_egl_display, vc->gfx.esurface, - vc->gfx.esurface, vc->gfx.ectx); + if (make_current) { + eglMakeCurrent(qemu_egl_display, vc->gfx.esurface, + vc->gfx.esurface, vc->gfx.ectx); + } return qemu_egl_create_context(dcl, params); } diff --git a/ui/gtk-gl-area.c b/ui/gtk-gl-area.c index 0df5a36..2eacd48 100644 --- a/ui/gtk-gl-area.c +++ b/ui/gtk-gl-area.c @@ -145,7 +145,8 @@ void gd_gl_area_switch(DisplayChangeListener *dcl, } QEMUGLContext gd_gl_area_create_context(DisplayChangeListener *dcl, - QEMUGLParams *params) + QEMUGLParams *params, + bool make_curent) { VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl); GdkWindow *window; diff --git a/ui/sdl2-gl.c b/ui/sdl2-gl.c index 039645d..3a744be 100644 --- a/ui/sdl2-gl.c +++ b/ui/sdl2-gl.c @@ -139,14 +139,17 @@ void sdl2_gl_redraw(struct sdl2_console *scon) } QEMUGLContext sdl2_gl_create_context(DisplayChangeListener *dcl, - QEMUGLParams *params) + QEMUGLParams *params, + bool make_current) { struct sdl2_console *scon = container_of(dcl, struct sdl2_console, dcl); SDL_GLContext ctx; assert(scon->opengl); - SDL_GL_MakeCurrent(scon->real_window, scon->winctx); + if (make_current) { + SDL_GL_MakeCurrent(scon->real_window, scon->winctx); + } SDL_GL_SetAttribute(SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1); SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, diff --git a/ui/spice-display.c b/ui/spice-display.c index 1c916dd..15a322d 100644 --- a/ui/spice-display.c +++ b/ui/spice-display.c @@ -851,10 +851,14 @@ static void qemu_spice_gl_block_timer(void *opaque) } static QEMUGLContext qemu_spice_gl_create_context(DisplayChangeListener *dcl, - QEMUGLParams *params) + QEMUGLParams *params, + bool make_current) { - eglMakeCurrent(qemu_egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, - qemu_egl_rn_ctx); + if (make_current) { + eglMakeCurrent(qemu_egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, + qemu_egl_rn_ctx); + } + return qemu_egl_create_context(dcl, params); } diff --git a/include/ui/console.h b/include/ui/console.h index ed5975f..a1891b7 100644 --- a/include/ui/console.h +++ b/include/ui/console.h @@ -208,7 +208,8 @@ typedef struct DisplayChangeListenerOps { QEMUCursor *cursor); QEMUGLContext (*dpy_gl_ctx_create)(DisplayChangeListener *dcl, - QEMUGLParams *params); + QEMUGLParams *params, + bool make_current); void (*dpy_gl_ctx_destroy)(DisplayChangeListener *dcl, QEMUGLContext ctx); int (*dpy_gl_ctx_make_current)(DisplayChangeListener *dcl, @@ -292,7 +293,8 @@ void dpy_gl_update(QemuConsole *con, uint32_t x, uint32_t y, uint32_t w, uint32_t h); QEMUGLContext dpy_gl_ctx_create(QemuConsole *con, - QEMUGLParams *params); + QEMUGLParams *params, + bool make_current); void dpy_gl_ctx_destroy(QemuConsole *con, QEMUGLContext ctx); int dpy_gl_ctx_make_current(QemuConsole *con, QEMUGLContext ctx); QEMUGLContext dpy_gl_ctx_get_current(QemuConsole *con); diff --git a/include/ui/gtk.h b/include/ui/gtk.h index 42ca0fe..c1240be 100644 --- a/include/ui/gtk.h +++ b/include/ui/gtk.h @@ -98,7 +98,8 @@ void gd_egl_refresh(DisplayChangeListener *dcl); void gd_egl_switch(DisplayChangeListener *dcl, DisplaySurface *surface); QEMUGLContext gd_egl_create_context(DisplayChangeListener *dcl, - QEMUGLParams *params); + QEMUGLParams *params, + bool make_current); void gd_egl_scanout(DisplayChangeListener *dcl, uint32_t backing_id, bool backing_y_0_top, uint32_t backing_width, uint32_t backing_height, @@ -119,7 +120,8 @@ void gd_gl_area_refresh(DisplayChangeListener *dcl); void gd_gl_area_switch(DisplayChangeListener *dcl, DisplaySurface *surface); QEMUGLContext gd_gl_area_create_context(DisplayChangeListener *dcl, - QEMUGLParams *params); + QEMUGLParams *params, + bool make_current); void gd_gl_area_destroy_context(DisplayChangeListener *dcl, QEMUGLContext ctx); void gd_gl_area_scanout(DisplayChangeListener *dcl, diff --git a/include/ui/sdl2.h b/include/ui/sdl2.h index 683bb6a..64d1b25 100644 --- a/include/ui/sdl2.h +++ b/include/ui/sdl2.h @@ -56,7 +56,8 @@ void sdl2_gl_refresh(DisplayChangeListener *dcl); void sdl2_gl_redraw(struct sdl2_console *scon); QEMUGLContext sdl2_gl_create_context(DisplayChangeListener *dcl, - QEMUGLParams *params); + QEMUGLParams *params, + bool make_current); void sdl2_gl_destroy_context(DisplayChangeListener *dcl, QEMUGLContext ctx); int sdl2_gl_make_context_current(DisplayChangeListener *dcl, QEMUGLContext ctx); -- 2.9.0