Commit 4d4fce7e authored by Stefan Dösinger's avatar Stefan Dösinger Committed by Alexandre Julliard

wined3d: Disconnect allocatedMemory and Heap allocation.

parent f1f84a36
......@@ -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); \
......
......@@ -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);
......
......@@ -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;
}
......
......@@ -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;
}
......
......@@ -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;
......
......@@ -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 */
......
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment