wined3d: Change calls of GetDC() to GetDCEx() with DCX_CACHE so the HDC is not shared with other threads.

Ken Thomases ken at codeweavers.com
Mon Feb 15 14:48:27 CST 2016


Windows created by the app may use the CS_CLASSDC or CS_OWNDC class styles.  In
that case, GetDC() would return the same HDC to all callers.  It's not safe,
though, for multiple threads to use the same HDC without synchronization.  The
app may be using that HDC from multiple threads and using some synchronization
scheme to make that safe, but wined3d is not able to cooperate in such a scheme.

Using GetDCEx() with DCX_CACHE ensures that wined3d gets an independent HDC.

Signed-off-by: Ken Thomases <ken at codeweavers.com>
---
 dlls/wined3d/context.c   | 6 +++---
 dlls/wined3d/swapchain.c | 4 ++--
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/dlls/wined3d/context.c b/dlls/wined3d/context.c
index 664ef73..442516a 100644
--- a/dlls/wined3d/context.c
+++ b/dlls/wined3d/context.c
@@ -790,7 +790,7 @@ static BOOL context_restore_pixel_format(struct wined3d_context *ctx)
     {
         if (ctx->gl_info->supported[WGL_WINE_PIXEL_FORMAT_PASSTHROUGH])
         {
-            HDC dc = GetDC(ctx->restore_pf_win);
+            HDC dc = GetDCEx(ctx->restore_pf_win, 0, DCX_USESTYLE | DCX_CACHE);
             if (dc)
             {
                 if (!(ret = GL_EXTCALL(wglSetPixelFormatWINE(dc, ctx->restore_pf))))
@@ -966,7 +966,7 @@ static void context_update_window(struct wined3d_context *context)
     context->needs_set = 1;
     context->valid = 1;
 
-    if (!(context->hdc = GetDC(context->win_handle)))
+    if (!(context->hdc = GetDCEx(context->win_handle, 0, DCX_USESTYLE | DCX_CACHE)))
     {
         ERR("Failed to get a device context for window %p.\n", context->win_handle);
         context->valid = 0;
@@ -1526,7 +1526,7 @@ struct wined3d_context *context_create(struct wined3d_swapchain *swapchain,
         }
     }
 
-    if (!(hdc = GetDC(swapchain->win_handle)))
+    if (!(hdc = GetDCEx(swapchain->win_handle, 0, DCX_USESTYLE | DCX_CACHE)))
     {
         WARN("Failed to retrieve device context, trying swapchain backup.\n");
 
diff --git a/dlls/wined3d/swapchain.c b/dlls/wined3d/swapchain.c
index 7728cdc..ae8fffd 100644
--- a/dlls/wined3d/swapchain.c
+++ b/dlls/wined3d/swapchain.c
@@ -257,7 +257,7 @@ HRESULT CDECL wined3d_swapchain_set_gamma_ramp(const struct wined3d_swapchain *s
     if (flags)
         FIXME("Ignoring flags %#x.\n", flags);
 
-    dc = GetDC(swapchain->device_window);
+    dc = GetDCEx(swapchain->device_window, 0, DCX_USESTYLE | DCX_CACHE);
     SetDeviceGammaRamp(dc, (void *)ramp);
     ReleaseDC(swapchain->device_window, dc);
 
@@ -277,7 +277,7 @@ HRESULT CDECL wined3d_swapchain_get_gamma_ramp(const struct wined3d_swapchain *s
 
     TRACE("swapchain %p, ramp %p.\n", swapchain, ramp);
 
-    dc = GetDC(swapchain->device_window);
+    dc = GetDCEx(swapchain->device_window, 0, DCX_USESTYLE | DCX_CACHE);
     GetDeviceGammaRamp(dc, ramp);
     ReleaseDC(swapchain->device_window, dc);
 
-- 
2.6.0




More information about the wine-patches mailing list