Henri Verbeet : wined3d: Try to reuse the thread' s current context in FindContext().

Alexandre Julliard julliard at winehq.org
Wed Jul 22 09:35:43 CDT 2009


Module: wine
Branch: master
Commit: e5d621c0813e795cd63755f90dcfbb8579a77006
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=e5d621c0813e795cd63755f90dcfbb8579a77006

Author: Henri Verbeet <hverbeet at codeweavers.com>
Date:   Wed Jul 22 10:41:10 2009 +0200

wined3d: Try to reuse the thread's current context in FindContext().

---

 dlls/wined3d/context.c |   47 +++++++++++++++++++++++++++++++++--------------
 1 files changed, 33 insertions(+), 14 deletions(-)

diff --git a/dlls/wined3d/context.c b/dlls/wined3d/context.c
index 2c61268..d82d2dc 100644
--- a/dlls/wined3d/context.c
+++ b/dlls/wined3d/context.c
@@ -1603,16 +1603,30 @@ static WineD3DContext *findThreadContextForSwapChain(IWineD3DSwapChain *swapchai
 static inline WineD3DContext *FindContext(IWineD3DDeviceImpl *This, IWineD3DSurface *target, DWORD tid) {
     IWineD3DSwapChain *swapchain = NULL;
     BOOL readTexture = wined3d_settings.offscreen_rendering_mode != ORM_FBO && This->render_offscreen;
+    struct WineD3DContext *current_context = context_get_current();
     BOOL oldRenderOffscreen = This->render_offscreen;
     const struct StateEntry *StateTable = This->StateTable;
     const struct GlPixelFormatDesc *old, *new;
     struct WineD3DContext *context;
 
-    if (!target) target = This->activeContext->current_rt;
+    if (!target)
+    {
+        if (current_context
+                && ((IWineD3DSurfaceImpl *)current_context->surface)->resource.wineD3DDevice == This)
+        {
+            target = current_context->current_rt;
+        }
+        else
+        {
+            IWineD3DSwapChainImpl *swapchain = (IWineD3DSwapChainImpl *)This->swapchains[0];
+            if (swapchain->backBuffer) target = swapchain->backBuffer[0];
+            else target = swapchain->frontBuffer;
+        }
+    }
 
-    if (This->activeContext->current_rt == target && This->activeContext->tid == tid)
+    if (current_context && current_context->current_rt == target)
     {
-        return This->activeContext;
+        return current_context;
     }
 
     if (SUCCEEDED(IWineD3DSurface_GetContainer(target, &IID_IWineD3DSwapChain, (void **)&swapchain))) {
@@ -1678,9 +1692,10 @@ retry:
         else
         {
             /* Stay with the currently active context. */
-            if (This->activeContext && This->activeContext->tid == tid)
+            if (current_context
+                    && ((IWineD3DSurfaceImpl *)current_context->surface)->resource.wineD3DDevice == This)
             {
-                context = This->activeContext;
+                context = current_context;
             }
             else
             {
@@ -1835,6 +1850,7 @@ static void apply_draw_buffer(IWineD3DDeviceImpl *This, IWineD3DSurface *target,
  *
  *****************************************************************************/
 void ActivateContext(IWineD3DDeviceImpl *This, IWineD3DSurface *target, ContextUsage usage) {
+    struct WineD3DContext *current_context = context_get_current();
     DWORD                         tid = GetCurrentThreadId();
     DWORD                         i, dirtyState, idx;
     BYTE                          shift;
@@ -1849,23 +1865,26 @@ void ActivateContext(IWineD3DDeviceImpl *This, IWineD3DSurface *target, ContextU
     gl_info = context->gl_info;
 
     /* Activate the opengl context */
-    if(last_device != This || context != This->activeContext) {
+    if (context != current_context)
+    {
         if (!context_set_current(context)) ERR("Failed to activate the new context.\n");
         else This->frag_pipe->enable_extension((IWineD3DDevice *)This, !context->last_was_blit);
 
-        if(This->activeContext->vshader_const_dirty) {
-            memset(This->activeContext->vshader_const_dirty, 1,
-                   sizeof(*This->activeContext->vshader_const_dirty) * GL_LIMITS(vshader_constantsF));
+        if (context->vshader_const_dirty)
+        {
+            memset(context->vshader_const_dirty, 1,
+                    sizeof(*context->vshader_const_dirty) * GL_LIMITS(vshader_constantsF));
             This->highest_dirty_vs_const = GL_LIMITS(vshader_constantsF);
         }
-        if(This->activeContext->pshader_const_dirty) {
-            memset(This->activeContext->pshader_const_dirty, 1,
-                   sizeof(*This->activeContext->pshader_const_dirty) * GL_LIMITS(pshader_constantsF));
+        if (context->pshader_const_dirty)
+        {
+            memset(context->pshader_const_dirty, 1,
+                   sizeof(*context->pshader_const_dirty) * GL_LIMITS(pshader_constantsF));
             This->highest_dirty_ps_const = GL_LIMITS(pshader_constantsF);
         }
-        This->activeContext = context;
-        context_set_last_device(This);
     }
+    This->activeContext = context;
+    context_set_last_device(This);
 
     switch (usage) {
         case CTXUSAGE_CLEAR:




More information about the wine-cvs mailing list