[PATCH] wined3d: IWineGDISwapChainImpl_Present make this function

Pavel Prochazka prochapa at inf.upol.cz
Thu May 28 05:58:19 CDT 2009


Removed possibility of loosing surfaces when swapping more
bacbuffers it is now general for issues when we have only 1
backbuffer.
It is fixing my yeasterday patch
Tested with some games with nice results
---
 dlls/wined3d/swapchain_gdi.c |  170 +++++++++++++++---------------------------
 1 files changed, 60 insertions(+), 110 deletions(-)

diff --git a/dlls/wined3d/swapchain_gdi.c b/dlls/wined3d/swapchain_gdi.c
index 2c3fc25..d0b912f 100644
--- a/dlls/wined3d/swapchain_gdi.c
+++ b/dlls/wined3d/swapchain_gdi.c
@@ -166,130 +166,80 @@ static HRESULT WINAPI IWineGDISwapChainImpl_SetDestWindowOverride(IWineD3DSwapCh
 
 static HRESULT WINAPI IWineGDISwapChainImpl_Present(IWineD3DSwapChain *iface, CONST RECT *pSourceRect, CONST RECT *pDestRect, HWND hDestWindowOverride, CONST RGNDATA *pDirtyRegion, DWORD dwFlags) {
     IWineD3DSwapChainImpl *This = (IWineD3DSwapChainImpl *) iface;
-    IWineD3DSurfaceImpl *front, *back,*hlp1,*hlp2;;
-
+    IWineD3DSurfaceImpl *front,*hlp1,*hlp2;
+	IWineD3DSurfaceImpl back; //must be copy of struct
+	int i;
+	
     if(!This->backBuffer) {
         WARN("Swapchain doesn't have a backbuffer, returning WINED3DERR_INVALIDCALL\n");
         return WINED3DERR_INVALIDCALL;
     }
     front = (IWineD3DSurfaceImpl *) This->frontBuffer;
-    back = (IWineD3DSurfaceImpl *) This->backBuffer[0];
+    back  = *((IWineD3DSurfaceImpl *)This->backBuffer[0]); //this value can not be pointer
+
+
+	/*it moves all backbuffers by 1 to left form id = 1,
+	the backbuffer swap to frontbuffer and frontbuffer swaps to the end of chain
+	Something like this:
+						      ^-------------^-----------^		
+							  |				|			|
+	|FrontBuffer|        |BackBuffer0|BackBuffer1|Backbuffer2|....|BackbufferN|
+		       															^
+		|---------------------------------------------------------------|
+		^
+		|---------------------|
+										
+	*/
+
+	//moves data from backbuffers to left - no pointers!
+	for(i=0;i<This->presentParms.BackBufferCount-1;i++) 
+	{
+		hlp1 = (IWineD3DSurfaceImpl *)This->backBuffer[i];
+		hlp2 = (IWineD3DSurfaceImpl *)This->backBuffer[i+1];
+		hlp1->hDC = hlp2->hDC;
+		hlp1->dib.DIBsection = hlp2->dib.DIBsection;
+		hlp1->dib.bitmap_data = hlp2->dib.bitmap_data;
+		hlp1->resource.allocatedMemory = hlp2->resource.allocatedMemory;
+		hlp1->dib.client_memory = hlp2->dib.client_memory;
+	}
+
+	//this places data from front buffer to end of backBuffer[]
+	hlp1 = (IWineD3DSurfaceImpl *)This->backBuffer[i];
+	hlp1->hDC = front->hDC;
+	hlp1->dib.DIBsection = front->dib.DIBsection;
+	hlp1->dib.bitmap_data = front->dib.bitmap_data;
+	hlp1->resource.allocatedMemory = front->resource.allocatedMemory;
+	hlp1->dib.client_memory = front->dib.client_memory;
 
-	if(This->presentParms.BackBufferCount > 1) // I hope that will not have speed slowdowns
+	/* Flip the DC */
 	{
-		int i=1;
-
-		/*it moves all backbuffers by 1 to left form id = 1,
-		the backbuffer swap to frontbuffer and frontbuffer swaps to the end of chain
-		Something like this:
-												------------^		
-												|			|
-		|FrontBuffer|        |BackBuffer0|BackBuffer1|Backbuffer2|....|BackbufferN|
-			       															^
-			|---------------------------------------------------------------|
-			^
-			|---------------------|
-
-											
-		*/
-
-		for(;i<This->presentParms.BackBufferCount-1;i++) 
-		{
-			hlp1 = (IWineD3DSurfaceImpl *)This->backBuffer[i];
-			hlp2 = (IWineD3DSurfaceImpl *)This->backBuffer[i+1];
-			hlp1->hDC = hlp2->hDC;
-			hlp1->dib.DIBsection = hlp2->dib.DIBsection;
-			hlp1->dib.bitmap_data = hlp2->dib.bitmap_data;
-			hlp1->resource.allocatedMemory = hlp2->resource.allocatedMemory;
-			hlp1->dib.client_memory = hlp2->dib.client_memory;
-		}
+	    front->hDC = back.hDC;
+	}
 
-	
-		//this places data from front buffer to end of backBuffer[]
-		hlp1 = (IWineD3DSurfaceImpl *)This->backBuffer[i];
-		hlp1->hDC = front->hDC;
-		hlp1->dib.DIBsection = front->dib.DIBsection;
-		hlp1->dib.bitmap_data = front->dib.bitmap_data;
-		hlp1->resource.allocatedMemory = front->resource.allocatedMemory;
-		hlp1->dib.client_memory = front->dib.client_memory;
-	
-	   	//i don't know if this part is not too redundantive
-		/* Flip the DC */
-		{        
-		    front->hDC = back->hDC;
-		}
-
-		/* Flip the DIBsection */
-		{
-		    front->dib.DIBsection = back->dib.DIBsection;
-		}
-
-		/* Flip the surface data */
-		{
-		    front->dib.bitmap_data = back->dib.bitmap_data;
-		    
-		    front->resource.allocatedMemory = back->resource.allocatedMemory;
-		   
-		    if(front->resource.heapMemory) {
-		        ERR("GDI Surface %p has heap memory allocated\n", front);
-		    }
-		    if(back->resource.heapMemory) {
-		        ERR("GDI Surface %p has heap memory allocated\n", back);
-		    }
-		}
-
-		/* client_memory should not be different, but just in case */
-		{
-		    front->dib.client_memory = back->dib.client_memory;
-		}
+	/* Flip the DIBsection */
+	{
+	    front->dib.DIBsection = back.dib.DIBsection;
 	}
-	else //when we have only 1 backbuffer
+
+	/* Flip the surface data */
 	{
-		/* Flip the DC */
-		{
-		    HDC tmp;
-		    tmp = front->hDC;
-		    front->hDC = back->hDC;
-		    back->hDC = tmp;
-		}
-
-		/* Flip the DIBsection */
-		{
-		    HBITMAP tmp;
-		    tmp = front->dib.DIBsection;
-		    front->dib.DIBsection = back->dib.DIBsection;
-		    back->dib.DIBsection = tmp;
-		}
-
-		/* Flip the surface data */
-		{
-		    void* tmp;
-
-		    tmp = front->dib.bitmap_data;
-		    front->dib.bitmap_data = back->dib.bitmap_data;
-		    back->dib.bitmap_data = tmp;
-
-		    tmp = front->resource.allocatedMemory;
-		    front->resource.allocatedMemory = back->resource.allocatedMemory;
-		    back->resource.allocatedMemory = tmp;
-
-		    if(front->resource.heapMemory) {
-		        ERR("GDI Surface %p has heap memory allocated\n", front);
-		    }
-		    if(back->resource.heapMemory) {
-		        ERR("GDI Surface %p has heap memory allocated\n", back);
-		    }
-		}
-
-		/* client_memory should not be different, but just in case */
-		{
-		    BOOL tmp;
-		    tmp = front->dib.client_memory;
-		    front->dib.client_memory = back->dib.client_memory;
-		    back->dib.client_memory = tmp;
-		}
+	    front->dib.bitmap_data = back.dib.bitmap_data;
+	  
+	    front->resource.allocatedMemory = back.resource.allocatedMemory;
+	   
+	    if(front->resource.heapMemory) {
+	        ERR("GDI Surface %p has heap memory allocated\n", front);
+	    }
+	    if(back.resource.heapMemory) {
+	        ERR("GDI Surface %p has heap memory allocated\n", &back);
+	    }
 	}
 
+	/* client_memory should not be different, but just in case */
+	{
+	    front->dib.client_memory = back.dib.client_memory;
+	}	
+
     /* FPS support */
     if (TRACE_ON(fps))
     {
-- 
1.6.0.4


--------------040505040700080306030308--



More information about the wine-patches mailing list