wined3d: Get rid of context_validate. (try 2)

Matteo Bruni matteo.mystral at gmail.com
Fri Apr 1 10:44:28 CDT 2011


Try 2 adds a limited workaround for broken GL drivers, such as Nvidia
drivers version <= 256.x
-------------- next part --------------
From e7314c046e3d4b373647433db6180caf7870af08 Mon Sep 17 00:00:00 2001
From: Matteo Bruni <mbruni at codeweavers.com>
Date: Fri, 18 Mar 2011 19:18:40 +0100
Subject: wined3d: Get rid of context_validate.

It should not be needed anymore, now the wined3d context is implicitly
validated on GL context activation. The check itself wasn't reliable
because of some threading issues and it also brought a small performance hit.
---
 dlls/wined3d/context.c |   28 ++++++++--------------------
 dlls/wined3d/device.c  |    3 +++
 2 files changed, 11 insertions(+), 20 deletions(-)

diff --git a/dlls/wined3d/context.c b/dlls/wined3d/context.c
index c3a6a5f..7d029db 100644
--- a/dlls/wined3d/context.c
+++ b/dlls/wined3d/context.c
@@ -800,6 +800,9 @@ static BOOL context_set_pixel_format(const struct wined3d_gl_info *gl_info, HDC
 
 static void context_update_window(struct wined3d_context *context)
 {
+    if (context->win_handle == context->swapchain->win_handle)
+        return;
+
     TRACE("Updating context %p window from %p to %p.\n",
             context, context->win_handle, context->swapchain->win_handle);
 
@@ -842,22 +845,6 @@ err:
 }
 
 /* Do not call while under the GL lock. */
-static void context_validate(struct wined3d_context *context)
-{
-    HWND wnd = WindowFromDC(context->hdc);
-
-    if (wnd != context->win_handle)
-    {
-        WARN("DC %p belongs to window %p instead of %p.\n",
-                context->hdc, wnd, context->win_handle);
-        context->valid = 0;
-    }
-
-    if (context->win_handle != context->swapchain->win_handle)
-        context_update_window(context);
-}
-
-/* Do not call while under the GL lock. */
 static void context_destroy_gl_resources(struct wined3d_context *context)
 {
     const struct wined3d_gl_info *gl_info = context->gl_info;
@@ -871,8 +858,9 @@ static void context_destroy_gl_resources(struct wined3d_context *context)
     restore_ctx = pwglGetCurrentContext();
     restore_dc = pwglGetCurrentDC();
 
-    context_validate(context);
-    if (context->valid && restore_ctx != context->glCtx) pwglMakeCurrent(context->hdc, context->glCtx);
+    context_update_window(context);
+    if (context->valid && restore_ctx != context->glCtx)
+        context->valid = !!pwglMakeCurrent(context->hdc, context->glCtx);
     else restore_ctx = NULL;
 
     ENTER_GL();
@@ -1900,7 +1888,7 @@ static struct wined3d_context *FindContext(IWineD3DDeviceImpl *This, IWineD3DSur
 
     if (current_context && current_context->current_rt == target)
     {
-        context_validate(current_context);
+        context_update_window(current_context);
         return current_context;
     }
 
@@ -1922,7 +1910,7 @@ static struct wined3d_context *FindContext(IWineD3DDeviceImpl *This, IWineD3DSur
             context = swapchain_get_context(This->swapchains[0]);
     }
 
-    context_validate(context);
+    context_update_window(context);
 
     return context;
 }
diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c
index 1ef9c62..2d50caa 100644
--- a/dlls/wined3d/device.c
+++ b/dlls/wined3d/device.c
@@ -2123,6 +2123,9 @@ static HRESULT WINAPI IWineD3DDeviceImpl_Uninit3D(IWineD3DDevice *iface,
 
     if(!This->d3d_initialized) return WINED3DERR_INVALIDCALL;
 
+    /* Force making the context current again, to verify it is still valid
+     * (workaround for broken drivers) */
+    context_set_current(NULL);
     /* I don't think that the interface guarantees that the device is destroyed from the same thread
      * it was created. Thus make sure a context is active for the glDelete* calls
      */
-- 
1.7.3.4


More information about the wine-patches mailing list