From: Matteo Bruni <mbruni@codeweavers.com> Checking every time the GL context is acquired is a lot. We could do something more fancy (e.g. checking in TestCooperativeLevel() and such) but I don't think it's worth it. This avoids frequent GetDC() calls, which introduce significant locking overhead. --- dlls/wined3d/context_gl.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/dlls/wined3d/context_gl.c b/dlls/wined3d/context_gl.c index ee0335ca3c4..52ff74061b9 100644 --- a/dlls/wined3d/context_gl.c +++ b/dlls/wined3d/context_gl.c @@ -1608,11 +1608,11 @@ void wined3d_context_gl_release(struct wined3d_context_gl *context_gl) } } -static void wined3d_context_gl_enter(struct wined3d_context_gl *context_gl) +static void wined3d_context_gl_enter(struct wined3d_context_gl *context_gl, bool check_context) { TRACE("Entering context %p, level %u.\n", context_gl, context_gl->level + 1); - if (!context_gl->level++) + if (!context_gl->level++ && check_context) { const struct wined3d_context_gl *current_context = wined3d_context_gl_get_current(); HGLRC current_gl = wglGetCurrentContext(); @@ -1913,7 +1913,7 @@ static BOOL wined3d_context_gl_create_wgl_ctx(struct wined3d_context_gl *context return FALSE; } - wined3d_context_gl_enter(context_gl); + wined3d_context_gl_enter(context_gl, true); if (!wined3d_context_gl_set_pixel_format(context_gl)) { @@ -4246,9 +4246,9 @@ static void wined3d_context_gl_setup_target(struct wined3d_context_gl *context_g } static void wined3d_context_gl_activate(struct wined3d_context_gl *context_gl, - struct wined3d_texture *texture, unsigned int sub_resource_idx) + struct wined3d_texture *texture, unsigned int sub_resource_idx, bool check_context) { - wined3d_context_gl_enter(context_gl); + wined3d_context_gl_enter(context_gl, check_context); if (texture && texture->swapchain && texture->swapchain != context_gl->c.swapchain) { TRACE("Switching context_gl %p from swapchain %p to swapchain %p.\n", @@ -4276,6 +4276,7 @@ struct wined3d_context *wined3d_context_gl_acquire(const struct wined3d_device * { struct wined3d_context_gl *current_context = wined3d_context_gl_get_current(); struct wined3d_context_gl *context_gl; + bool check_context = false; TRACE("device %p, texture %p, sub_resource_idx %u.\n", device, texture, sub_resource_idx); @@ -4312,6 +4313,7 @@ struct wined3d_context *wined3d_context_gl_acquire(const struct wined3d_device * if (!(context_gl = wined3d_swapchain_gl_get_context(wined3d_swapchain_gl(texture->swapchain)))) return NULL; + check_context = true; } else { @@ -4325,7 +4327,7 @@ struct wined3d_context *wined3d_context_gl_acquire(const struct wined3d_device * return NULL; } - wined3d_context_gl_activate(context_gl, texture, sub_resource_idx); + wined3d_context_gl_activate(context_gl, texture, sub_resource_idx, check_context); return &context_gl->c; } @@ -4344,7 +4346,7 @@ struct wined3d_context_gl *wined3d_context_gl_reacquire(struct wined3d_context_g if (context_gl->c.current_rt.texture) { wined3d_context_gl_activate(context_gl, context_gl->c.current_rt.texture, - context_gl->c.current_rt.sub_resource_idx); + context_gl->c.current_rt.sub_resource_idx, false); return context_gl; } -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/9812