[PATCH 3/5] wined3d: Make context_resource_released() responsible for activating a different GL context.

Henri Verbeet hverbeet at codeweavers.com
Thu Jun 25 03:24:56 CDT 2009


In case lastActiveRenderTarget is destroyed.
---
 dlls/wined3d/context.c |   47 +++++++++++++++++++++++++++++++++++++++++++++++
 dlls/wined3d/device.c  |   35 ++---------------------------------
 2 files changed, 49 insertions(+), 33 deletions(-)

diff --git a/dlls/wined3d/context.c b/dlls/wined3d/context.c
index 81bddb1..5b3cecb 100644
--- a/dlls/wined3d/context.c
+++ b/dlls/wined3d/context.c
@@ -426,6 +426,53 @@ void context_resource_released(IWineD3DDevice *iface, IWineD3DResource *resource
     {
         case WINED3DRTYPE_SURFACE:
         {
+            if ((IWineD3DSurface *)resource == This->lastActiveRenderTarget)
+            {
+                IWineD3DSwapChainImpl *swapchain;
+
+                TRACE("Last active render target destroyed.\n");
+
+                /* Find a replacement surface for the currently active back
+                 * buffer. The context manager does not do NULL checks, so
+                 * switch to a valid target as long as the currently set
+                 * surface is still valid. Use the surface of the implicit
+                 * swpchain. If that is the same as the destroyed surface the
+                 * device is destroyed and the lastActiveRenderTarget member
+                 * shouldn't matter. */
+                swapchain = This->swapchains ? (IWineD3DSwapChainImpl *)This->swapchains[0] : NULL;
+                if (swapchain)
+                {
+                    if (swapchain->backBuffer && swapchain->backBuffer[0] != (IWineD3DSurface *)resource)
+                    {
+                        TRACE("Activating primary back buffer.\n");
+                        ActivateContext(This, swapchain->backBuffer[0], CTXUSAGE_RESOURCELOAD);
+                    }
+                    else if (!swapchain->backBuffer && swapchain->frontBuffer != (IWineD3DSurface *)resource)
+                    {
+                        /* Single buffering environment */
+                        TRACE("Activating primary front buffer.\n");
+
+                        ActivateContext(This, swapchain->frontBuffer, CTXUSAGE_RESOURCELOAD);
+                    }
+                    else
+                    {
+                        /* Implicit render target destroyed, that means the
+                         * device is being destroyed whatever we set here, it
+                         * shouldn't matter. */
+                        TRACE("Device is being destroyed, setting lastActiveRenderTarget to 0xdeadbabe.\n");
+
+                        This->lastActiveRenderTarget = (IWineD3DSurface *) 0xdeadbabe;
+                    }
+                }
+                else
+                {
+                    WARN("Render target set, but swapchain does not exist!\n");
+
+                    /* May happen during ddraw uninitialization. */
+                    This->lastActiveRenderTarget = (IWineD3DSurface *)0xdeadcafe;
+                }
+            }
+
             for (i = 0; i < This->numContexts; ++i)
             {
                 WineD3DContext *context = This->contexts[i];
diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c
index 48d49a8..3ad0625 100644
--- a/dlls/wined3d/device.c
+++ b/dlls/wined3d/device.c
@@ -7327,39 +7327,8 @@ void device_resource_released(IWineD3DDeviceImpl *This, IWineD3DResource *resour
         case WINED3DRTYPE_SURFACE: {
             unsigned int i;
 
-            /* Cleanup any FBO attachments if d3d is enabled */
-            if(This->d3d_initialized) {
-                if((IWineD3DSurface *)resource == This->lastActiveRenderTarget) {
-                    IWineD3DSwapChainImpl *swapchain = This->swapchains ? (IWineD3DSwapChainImpl *) This->swapchains[0] : NULL;
-
-                    TRACE("Last active render target destroyed\n");
-                    /* Find a replacement surface for the currently active back buffer. The context manager does not do NULL
-                     * checks, so switch to a valid target as long as the currently set surface is still valid. Use the
-                     * surface of the implicit swpchain. If that is the same as the destroyed surface the device is destroyed
-                     * and the lastActiveRenderTarget member shouldn't matter
-                     */
-                    if(swapchain) {
-                        if(swapchain->backBuffer && swapchain->backBuffer[0] != (IWineD3DSurface *)resource) {
-                            TRACE("Activating primary back buffer\n");
-                            ActivateContext(This, swapchain->backBuffer[0], CTXUSAGE_RESOURCELOAD);
-                        } else if(!swapchain->backBuffer && swapchain->frontBuffer != (IWineD3DSurface *)resource) {
-                            /* Single buffering environment */
-                            TRACE("Activating primary front buffer\n");
-                            ActivateContext(This, swapchain->frontBuffer, CTXUSAGE_RESOURCELOAD);
-                        } else {
-                            TRACE("Device is being destroyed, setting lastActiveRenderTarget = 0xdeadbabe\n");
-                            /* Implicit render target destroyed, that means the device is being destroyed
-                             * whatever we set here, it shouldn't matter
-                             */
-                            This->lastActiveRenderTarget = (IWineD3DSurface *) 0xdeadbabe;
-                        }
-                    } else {
-                        /* May happen during ddraw uninitialization */
-                        TRACE("Render target set, but swapchain does not exist!\n");
-                        This->lastActiveRenderTarget = (IWineD3DSurface *) 0xdeadcafe;
-                    }
-                }
-
+            if (This->d3d_initialized)
+            {
                 for (i = 0; i < GL_LIMITS(buffers); ++i) {
                     if (This->render_targets[i] == (IWineD3DSurface *)resource) {
                         This->render_targets[i] = NULL;
-- 
1.6.0.6




More information about the wine-patches mailing list