Module: wine Branch: master Commit: 4d4fce7e3313bb8d2d76993361004c5a4b4dd63b URL: http://source.winehq.org/git/wine.git/?a=commit;h=4d4fce7e3313bb8d2d76993361...
Author: Stefan Dösinger stefan@codeweavers.com Date: Mon Oct 22 13:02:03 2007 +0200
wined3d: Disconnect allocatedMemory and Heap allocation.
---
dlls/wined3d/device.c | 5 +++-- dlls/wined3d/resource.c | 3 ++- dlls/wined3d/surface.c | 17 ++++++++++++----- dlls/wined3d/surface_base.c | 4 ++-- dlls/wined3d/surface_gdi.c | 10 +++++++++- dlls/wined3d/swapchain.c | 4 ++++ dlls/wined3d/wined3d_private.h | 3 ++- 7 files changed, 34 insertions(+), 12 deletions(-)
diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c index 17aeea2..db7a4e3 100644 --- a/dlls/wined3d/device.c +++ b/dlls/wined3d/device.c @@ -101,13 +101,14 @@ static void WINAPI IWineD3DDeviceImpl_AddResource(IWineD3DDevice *iface, IWineD3 } \ WineD3DAdapterChangeGLRam(This, _size); \ } \ - object->resource.allocatedMemory = (0 == _size ? NULL : HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, _size + 4)); \ - if (object->resource.allocatedMemory == NULL && _size != 0) { \ + object->resource.heapMemory = (0 == _size ? NULL : HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, _size + 4)); \ + if (object->resource.heapMemory == NULL && _size != 0) { \ FIXME("Out of memory!\n"); \ HeapFree(GetProcessHeap(), 0, object); \ *pp##type = NULL; \ return WINED3DERR_OUTOFVIDEOMEMORY; \ } \ + object->resource.allocatedMemory = object->resource.heapMemory; \ *pp##type = (IWineD3D##type *) object; \ IWineD3DDeviceImpl_AddResource(iface, (IWineD3DResource *)object) ;\ TRACE("(%p) : Created resource %p\n", This, object); \ diff --git a/dlls/wined3d/resource.c b/dlls/wined3d/resource.c index 4a620f6..9faaea5 100644 --- a/dlls/wined3d/resource.c +++ b/dlls/wined3d/resource.c @@ -82,8 +82,9 @@ void IWineD3DResourceImpl_CleanUp(IWineD3DResource *iface){ } }
- HeapFree(GetProcessHeap(), 0, This->resource.allocatedMemory); + HeapFree(GetProcessHeap(), 0, This->resource.heapMemory); This->resource.allocatedMemory = 0; + This->resource.heapMemory = 0;
if (This->resource.wineD3DDevice != NULL) { IWineD3DDevice_ResourceReleased((IWineD3DDevice *)This->resource.wineD3DDevice, iface); diff --git a/dlls/wined3d/surface.c b/dlls/wined3d/surface.c index 07501f2..6637539 100644 --- a/dlls/wined3d/surface.c +++ b/dlls/wined3d/surface.c @@ -668,15 +668,17 @@ static void surface_prepare_system_memory(IWineD3DSurfaceImpl *This) { checkGLcall("glBindBufferARB");
/* We don't need the system memory anymore and we can't even use it for PBOs */ - HeapFree(GetProcessHeap(), 0, This->resource.allocatedMemory); + HeapFree(GetProcessHeap(), 0, This->resource.heapMemory); This->resource.allocatedMemory = NULL; + This->resource.heapMemory = NULL; This->Flags |= SFLAG_PBO; LEAVE_GL(); } else if(!(This->resource.allocatedMemory || This->Flags & SFLAG_PBO)) { /* Whatever surface we have, make sure that there is memory allocated for the downloaded copy, * or a pbo to map */ - This->resource.allocatedMemory = HeapAlloc(GetProcessHeap() ,0 , This->resource.size + 4); + This->resource.heapMemory = HeapAlloc(GetProcessHeap() ,0 , This->resource.size + 4); + This->resource.allocatedMemory = This->resource.heapMemory; if(This->Flags & SFLAG_INSYSMEM) { ERR("Surface without memory or pbo has SFLAG_INSYSMEM set!\n"); } @@ -2024,8 +2026,9 @@ static HRESULT WINAPI IWineD3DSurfaceImpl_LoadTexture(IWineD3DSurface *iface, BO #endif
if (!(This->Flags & SFLAG_DONOTFREE)) { - HeapFree(GetProcessHeap(), 0, This->resource.allocatedMemory); + HeapFree(GetProcessHeap(), 0, This->resource.heapMemory); This->resource.allocatedMemory = NULL; + This->resource.heapMemory = NULL; IWineD3DSurface_ModifyLocation(iface, SFLAG_INSYSMEM, FALSE); }
@@ -2257,7 +2260,8 @@ HRESULT WINAPI IWineD3DSurfaceImpl_SetMem(IWineD3DSurface *iface, void *Mem) { This->hDC = NULL; This->Flags &= ~SFLAG_DIBSECTION; } else if(!(This->Flags & SFLAG_USERPTR)) { - release = This->resource.allocatedMemory; + release = This->resource.heapMemory; + This->resource.heapMemory = NULL; } This->resource.allocatedMemory = Mem; This->Flags |= SFLAG_USERPTR | SFLAG_INSYSMEM; @@ -2277,6 +2281,8 @@ HRESULT WINAPI IWineD3DSurfaceImpl_SetMem(IWineD3DSurface *iface, void *Mem) { } else if(This->Flags & SFLAG_USERPTR) { /* Lockrect and GetDC will re-create the dib section and allocated memory */ This->resource.allocatedMemory = NULL; + /* HeapMemory should be NULL already */ + if(This->resource.heapMemory != NULL) ERR("User pointer surface has heap memory allocated\n"); This->Flags &= ~SFLAG_USERPTR;
if(This->Flags & SFLAG_CLIENT) { @@ -2839,8 +2845,9 @@ static HRESULT IWineD3DSurfaceImpl_BltOverride(IWineD3DSurfaceImpl *This, RECT * }
if(!(This->Flags & SFLAG_DONOTFREE)) { - HeapFree(GetProcessHeap(), 0, This->resource.allocatedMemory); + HeapFree(GetProcessHeap(), 0, This->resource.heapMemory); This->resource.allocatedMemory = NULL; + This->resource.heapMemory = NULL; } else { This->Flags &= ~SFLAG_INSYSMEM; } diff --git a/dlls/wined3d/surface_base.c b/dlls/wined3d/surface_base.c index a9c5a07..6b9c631 100644 --- a/dlls/wined3d/surface_base.c +++ b/dlls/wined3d/surface_base.c @@ -483,7 +483,6 @@ HRESULT IWineD3DBaseSurfaceImpl_CreateDIBSection(IWineD3DSurface *iface) { IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface; int extraline = 0; SYSTEM_INFO sysInfo; - void *oldmem = This->resource.allocatedMemory; BITMAPINFO* b_info; HDC ddc; DWORD *masks; @@ -609,7 +608,8 @@ HRESULT IWineD3DBaseSurfaceImpl_CreateDIBSection(IWineD3DSurface *iface) {
This->Flags |= SFLAG_DIBSECTION;
- HeapFree(GetProcessHeap(), 0, oldmem); + HeapFree(GetProcessHeap(), 0, This->resource.heapMemory); + This->resource.heapMemory = NULL;
return WINED3D_OK; } diff --git a/dlls/wined3d/surface_gdi.c b/dlls/wined3d/surface_gdi.c index d3cb89d..a5ca3db 100644 --- a/dlls/wined3d/surface_gdi.c +++ b/dlls/wined3d/surface_gdi.c @@ -329,6 +329,13 @@ IWineGDISurfaceImpl_Flip(IWineD3DSurface *iface, tmp = This->resource.allocatedMemory; This->resource.allocatedMemory = Target->resource.allocatedMemory; Target->resource.allocatedMemory = tmp; + + if(This->resource.heapMemory) { + ERR("GDI Surface %p has heap memory allocated\n", This); + } + if(Target->resource.heapMemory) { + ERR("GDI Surface %p has heap memory allocated\n", Target); + } }
/* client_memory should not be different, but just in case */ @@ -630,8 +637,9 @@ IWineGDISurfaceImpl_PrivateSetup(IWineD3DSurface *iface) /* Sysmem textures have memory already allocated - * release it, this avoids an unnecessary memcpy */ - HeapFree(GetProcessHeap(), 0, This->resource.allocatedMemory); + HeapFree(GetProcessHeap(), 0, This->resource.heapMemory); This->resource.allocatedMemory = NULL; + This->resource.heapMemory = NULL;
/* We don't mind the nonpow2 stuff in GDI */ This->pow2Width = This->currentDesc.Width; diff --git a/dlls/wined3d/swapchain.c b/dlls/wined3d/swapchain.c index 330f928..501c7cd 100644 --- a/dlls/wined3d/swapchain.c +++ b/dlls/wined3d/swapchain.c @@ -322,6 +322,10 @@ static HRESULT WINAPI IWineD3DSwapChainImpl_Present(IWineD3DSwapChain *iface, CO tmp = front->resource.allocatedMemory; front->resource.allocatedMemory = back->resource.allocatedMemory; back->resource.allocatedMemory = tmp; + + tmp = front->resource.heapMemory; + front->resource.heapMemory = back->resource.heapMemory; + back->resource.heapMemory = tmp; }
/* Flip the PBO */ diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index 8362aa1..fdfd43f 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -817,7 +817,8 @@ typedef struct IWineD3DResourceClass UINT size; DWORD usage; WINED3DFORMAT format; - BYTE *allocatedMemory; + BYTE *allocatedMemory; /* Pointer to the real data location */ + BYTE *heapMemory; /* Pointer to the HeapAlloced block of memory */ struct list privateData;
} IWineD3DResourceClass;