Commit 9cc7c6e9 authored by Henri Verbeet's avatar Henri Verbeet Committed by Alexandre Julliard

ddraw: Use the global memory allocation helpers.

parent 529168ec
......@@ -72,7 +72,7 @@ static ULONG WINAPI ddraw_clipper_Release(IDirectDrawClipper *iface)
{
if (clipper->region)
DeleteObject(clipper->region);
HeapFree(GetProcessHeap(), 0, clipper);
heap_free(clipper);
}
return refcount;
......
......@@ -376,7 +376,7 @@ static void ddraw_destroy_swapchain(struct ddraw *ddraw)
{
wined3d_vertex_declaration_decref(ddraw->decls[i].decl);
}
HeapFree(GetProcessHeap(), 0, ddraw->decls);
heap_free(ddraw->decls);
ddraw->numConvertedDecls = 0;
if (FAILED(wined3d_device_uninit_3d(ddraw->wined3d_device)))
......@@ -442,7 +442,7 @@ static void ddraw_destroy(struct ddraw *This)
This->d3ddevice->ddraw = NULL;
/* Now free the object */
HeapFree(GetProcessHeap(), 0, This);
heap_free(This);
}
/*****************************************************************************
......@@ -600,8 +600,7 @@ static HRESULT ddraw_attach_d3d_device(struct ddraw *ddraw,
}
ddraw->declArraySize = 2;
ddraw->decls = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*ddraw->decls) * ddraw->declArraySize);
if (!ddraw->decls)
if (!(ddraw->decls = heap_alloc_zero(ddraw->declArraySize * sizeof(*ddraw->decls))))
{
ERR("Error allocating an array for the converted vertex decls.\n");
ddraw->declArraySize = 0;
......@@ -2390,8 +2389,8 @@ static HRESULT WINAPI ddraw7_EnumDisplayModes(IDirectDraw7 *iface, DWORD Flags,
if (!cb)
return DDERR_INVALIDPARAMS;
enum_modes = HeapAlloc(GetProcessHeap(), 0, sizeof(*enum_modes) * enum_mode_array_size);
if (!enum_modes) return DDERR_OUTOFMEMORY;
if (!(enum_modes = heap_alloc(enum_mode_array_size * sizeof(*enum_modes))))
return DDERR_OUTOFMEMORY;
wined3d_mutex_lock();
......@@ -2455,7 +2454,7 @@ static HRESULT WINAPI ddraw7_EnumDisplayModes(IDirectDraw7 *iface, DWORD Flags,
if(cb(&callback_sd, Context) == DDENUMRET_CANCEL)
{
TRACE("Application asked to terminate the enumeration\n");
HeapFree(GetProcessHeap(), 0, enum_modes);
heap_free(enum_modes);
wined3d_mutex_unlock();
return DD_OK;
}
......@@ -2465,11 +2464,9 @@ static HRESULT WINAPI ddraw7_EnumDisplayModes(IDirectDraw7 *iface, DWORD Flags,
struct wined3d_display_mode *new_enum_modes;
enum_mode_array_size *= 2;
new_enum_modes = HeapReAlloc(GetProcessHeap(), 0, enum_modes,
sizeof(*new_enum_modes) * enum_mode_array_size);
if (!new_enum_modes)
if (!(new_enum_modes = heap_realloc(enum_modes, enum_mode_array_size * sizeof(*new_enum_modes))))
{
HeapFree(GetProcessHeap(), 0, enum_modes);
heap_free(enum_modes);
wined3d_mutex_unlock();
return DDERR_OUTOFMEMORY;
}
......@@ -2481,7 +2478,7 @@ static HRESULT WINAPI ddraw7_EnumDisplayModes(IDirectDraw7 *iface, DWORD Flags,
}
TRACE("End of enumeration\n");
HeapFree(GetProcessHeap(), 0, enum_modes);
heap_free(enum_modes);
wined3d_mutex_unlock();
return DD_OK;
......@@ -3319,8 +3316,7 @@ HRESULT WINAPI DirectDrawCreateClipper(DWORD flags, IDirectDrawClipper **clipper
wined3d_mutex_lock();
object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
if (!object)
if (!(object = heap_alloc_zero(sizeof(*object))))
{
wined3d_mutex_unlock();
return E_OUTOFMEMORY;
......@@ -3330,7 +3326,7 @@ HRESULT WINAPI DirectDrawCreateClipper(DWORD flags, IDirectDrawClipper **clipper
if (FAILED(hr))
{
WARN("Failed to initialize clipper, hr %#x.\n", hr);
HeapFree(GetProcessHeap(), 0, object);
heap_free(object);
wined3d_mutex_unlock();
return hr;
}
......@@ -3430,8 +3426,7 @@ static HRESULT WINAPI ddraw7_CreatePalette(IDirectDraw7 *iface, DWORD Flags,
return DDERR_NOCOOPERATIVELEVELSET;
}
object = HeapAlloc(GetProcessHeap(), 0, sizeof(*object));
if (!object)
if (!(object = heap_alloc(sizeof(*object))))
{
ERR("Out of memory when allocating memory for a palette implementation\n");
wined3d_mutex_unlock();
......@@ -3442,7 +3437,7 @@ static HRESULT WINAPI ddraw7_CreatePalette(IDirectDraw7 *iface, DWORD Flags,
if (FAILED(hr))
{
WARN("Failed to initialize palette, hr %#x.\n", hr);
HeapFree(GetProcessHeap(), 0, object);
heap_free(object);
wined3d_mutex_unlock();
return hr;
}
......@@ -3838,10 +3833,10 @@ static HRESULT WINAPI d3d3_CreateLight(IDirect3D3 *iface, IDirect3DLight **light
TRACE("iface %p, light %p, outer_unknown %p.\n", iface, light, outer_unknown);
if (outer_unknown) return CLASS_E_NOAGGREGATION;
if (outer_unknown)
return CLASS_E_NOAGGREGATION;
object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
if (!object)
if (!(object = heap_alloc_zero(sizeof(*object))))
{
ERR("Failed to allocate light memory.\n");
return DDERR_OUTOFMEMORY;
......@@ -3988,8 +3983,7 @@ static HRESULT WINAPI d3d3_CreateViewport(IDirect3D3 *iface, IDirect3DViewport3
if (outer_unknown) return CLASS_E_NOAGGREGATION;
object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
if (!object)
if (!(object = heap_alloc_zero(sizeof(*object))))
{
ERR("Failed to allocate viewport memory.\n");
return DDERR_OUTOFMEMORY;
......@@ -4704,11 +4698,12 @@ struct wined3d_vertex_declaration *ddraw_find_decl(struct ddraw *This, DWORD fvf
fvf, This, &ddraw_null_wined3d_parent_ops, &pDecl);
if (hr != S_OK) return NULL;
if(This->declArraySize == This->numConvertedDecls) {
int grow = max(This->declArraySize / 2, 8);
convertedDecls = HeapReAlloc(GetProcessHeap(), 0, convertedDecls,
sizeof(convertedDecls[0]) * (This->numConvertedDecls + grow));
if (!convertedDecls)
if (This->declArraySize == This->numConvertedDecls)
{
unsigned int grow = max(This->declArraySize / 2, 8);
if (!(convertedDecls = heap_realloc(convertedDecls,
(This->numConvertedDecls + grow) * sizeof(*convertedDecls))))
{
wined3d_vertex_declaration_decref(pDecl);
return NULL;
......@@ -4824,7 +4819,7 @@ static HRESULT CDECL device_parent_surface_created(struct wined3d_device_parent
return DD_OK;
}
if (!(ddraw_surface = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*ddraw_surface))))
if (!(ddraw_surface = heap_alloc_zero(sizeof(*ddraw_surface))))
{
ERR("Failed to allocate surface memory.\n");
return DDERR_OUTOFVIDEOMEMORY;
......
......@@ -25,6 +25,7 @@
#define NONAMELESSSTRUCT
#define NONAMELESSUNION
#include "wine/debug.h"
#include "wine/heap.h"
#include "winbase.h"
#include "wingdi.h"
......
......@@ -322,7 +322,7 @@ static ULONG WINAPI d3d_device_inner_Release(IUnknown *iface)
This->ddraw->d3ddevice = NULL;
/* Now free the structure */
HeapFree(GetProcessHeap(), 0, This);
heap_free(This);
wined3d_mutex_unlock();
}
......@@ -663,8 +663,7 @@ static HRESULT WINAPI d3d_device1_CreateExecuteBuffer(IDirect3DDevice *iface,
return CLASS_E_NOAGGREGATION;
/* Allocate the new Execute Buffer */
object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
if(!object)
if (!(object = heap_alloc_zero(sizeof(*object))))
{
ERR("Failed to allocate execute buffer memory.\n");
return DDERR_OUTOFMEMORY;
......@@ -674,7 +673,7 @@ static HRESULT WINAPI d3d_device1_CreateExecuteBuffer(IDirect3DDevice *iface,
if (FAILED(hr))
{
WARN("Failed to initialize execute buffer, hr %#x.\n", hr);
HeapFree(GetProcessHeap(), 0, object);
heap_free(object);
return hr;
}
......@@ -1274,7 +1273,7 @@ static HRESULT WINAPI d3d_device1_EnumTextureFormats(IDirect3DDevice *iface,
static HRESULT WINAPI d3d_device1_CreateMatrix(IDirect3DDevice *iface, D3DMATRIXHANDLE *D3DMatHandle)
{
struct d3d_device *device = impl_from_IDirect3DDevice(iface);
D3DMATRIX *Matrix;
D3DMATRIX *matrix;
DWORD h;
TRACE("iface %p, matrix_handle %p.\n", iface, D3DMatHandle);
......@@ -1282,8 +1281,7 @@ static HRESULT WINAPI d3d_device1_CreateMatrix(IDirect3DDevice *iface, D3DMATRIX
if(!D3DMatHandle)
return DDERR_INVALIDPARAMS;
Matrix = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(D3DMATRIX));
if(!Matrix)
if (!(matrix = heap_alloc_zero(sizeof(*matrix))))
{
ERR("Out of memory when allocating a D3DMATRIX\n");
return DDERR_OUTOFMEMORY;
......@@ -1291,11 +1289,11 @@ static HRESULT WINAPI d3d_device1_CreateMatrix(IDirect3DDevice *iface, D3DMATRIX
wined3d_mutex_lock();
h = ddraw_allocate_handle(&device->handle_table, Matrix, DDRAW_HANDLE_MATRIX);
h = ddraw_allocate_handle(&device->handle_table, matrix, DDRAW_HANDLE_MATRIX);
if (h == DDRAW_INVALID_HANDLE)
{
ERR("Failed to allocate a matrix handle.\n");
HeapFree(GetProcessHeap(), 0, Matrix);
heap_free(matrix);
wined3d_mutex_unlock();
return DDERR_OUTOFMEMORY;
}
......@@ -1446,7 +1444,7 @@ static HRESULT WINAPI d3d_device1_DeleteMatrix(IDirect3DDevice *iface, D3DMATRIX
wined3d_mutex_unlock();
HeapFree(GetProcessHeap(), 0, m);
heap_free(m);
return D3D_OK;
}
......@@ -2218,11 +2216,11 @@ static HRESULT WINAPI d3d_device3_Vertex(IDirect3DDevice3 *iface, void *vertex)
device->buffer_size = device->buffer_size ? device->buffer_size * 2 : device->vertex_size * 3;
old_buffer = device->sysmem_vertex_buffer;
device->sysmem_vertex_buffer = HeapAlloc(GetProcessHeap(), 0, device->buffer_size);
device->sysmem_vertex_buffer = heap_alloc(device->buffer_size);
if (old_buffer)
{
memcpy(device->sysmem_vertex_buffer, old_buffer, device->nb_vertices * device->vertex_size);
HeapFree(GetProcessHeap(), 0, old_buffer);
heap_free(old_buffer);
}
}
......@@ -7020,8 +7018,7 @@ HRESULT d3d_device_create(struct ddraw *ddraw, struct ddraw_surface *target, IUn
return DDERR_INVALIDPARAMS;
}
object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
if (!object)
if (!(object = heap_alloc_zero(sizeof(*object))))
{
ERR("Failed to allocate device memory.\n");
return DDERR_OUTOFMEMORY;
......@@ -7030,7 +7027,7 @@ HRESULT d3d_device_create(struct ddraw *ddraw, struct ddraw_surface *target, IUn
if (FAILED(hr = d3d_device_init(object, ddraw, target, rt_iface, version, outer_unknown)))
{
WARN("Failed to initialize device, hr %#x.\n", hr);
HeapFree(GetProcessHeap(), 0, object);
heap_free(object);
return hr;
}
......
......@@ -508,7 +508,7 @@ static ULONG WINAPI d3d_execute_buffer_Release(IDirect3DExecuteBuffer *iface)
if (!ref)
{
if (buffer->need_free)
HeapFree(GetProcessHeap(), 0, buffer->desc.lpData);
heap_free(buffer->desc.lpData);
if (buffer->index_buffer)
wined3d_buffer_decref(buffer->index_buffer);
if (buffer->dst_vertex_buffer)
......@@ -516,7 +516,7 @@ static ULONG WINAPI d3d_execute_buffer_Release(IDirect3DExecuteBuffer *iface)
wined3d_buffer_decref(buffer->src_vertex_buffer);
wined3d_buffer_decref(buffer->dst_vertex_buffer);
}
HeapFree(GetProcessHeap(), 0, buffer);
heap_free(buffer);
}
return ref;
......@@ -791,8 +791,7 @@ HRESULT d3d_execute_buffer_init(struct d3d_execute_buffer *execute_buffer,
if (!execute_buffer->desc.lpData && execute_buffer->desc.dwBufferSize)
{
execute_buffer->need_free = TRUE;
execute_buffer->desc.lpData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, execute_buffer->desc.dwBufferSize);
if (!execute_buffer->desc.lpData)
if (!(execute_buffer->desc.lpData = heap_alloc_zero(execute_buffer->desc.dwBufferSize)))
{
ERR("Failed to allocate execute buffer data.\n");
return DDERR_OUTOFMEMORY;
......
......@@ -133,7 +133,7 @@ static ULONG WINAPI d3d_light_Release(IDirect3DLight *iface)
if (!ref)
{
HeapFree(GetProcessHeap(), 0, light);
heap_free(light);
return 0;
}
return ref;
......
......@@ -92,8 +92,7 @@ static void ddraw_enumerate_secondary_devices(struct wined3d *wined3d, LPDDENUMC
/* Handle table functions */
BOOL ddraw_handle_table_init(struct ddraw_handle_table *t, UINT initial_size)
{
t->entries = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, initial_size * sizeof(*t->entries));
if (!t->entries)
if (!(t->entries = heap_alloc_zero(initial_size * sizeof(*t->entries))))
{
ERR("Failed to allocate handle table memory.\n");
return FALSE;
......@@ -107,7 +106,7 @@ BOOL ddraw_handle_table_init(struct ddraw_handle_table *t, UINT initial_size)
void ddraw_handle_table_destroy(struct ddraw_handle_table *t)
{
HeapFree(GetProcessHeap(), 0, t->entries);
heap_free(t->entries);
memset(t, 0, sizeof(*t));
}
......@@ -136,9 +135,9 @@ DWORD ddraw_allocate_handle(struct ddraw_handle_table *t, void *object, enum ddr
{
/* Grow the table */
UINT new_size = t->table_size + (t->table_size >> 1);
struct ddraw_handle_entry *new_entries = HeapReAlloc(GetProcessHeap(),
0, t->entries, new_size * sizeof(*t->entries));
if (!new_entries)
struct ddraw_handle_entry *new_entries;
if (!(new_entries = heap_realloc(t->entries, new_size * sizeof(*t->entries))))
{
ERR("Failed to grow the handle table.\n");
return DDRAW_INVALID_HANDLE;
......@@ -298,8 +297,7 @@ DDRAW_Create(const GUID *guid,
flags = WINED3D_LEGACY_FFP_LIGHTING;
/* DirectDraw creation comes here */
ddraw = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*ddraw));
if (!ddraw)
if (!(ddraw = heap_alloc_zero(sizeof(*ddraw))))
{
ERR("Out of memory when creating DirectDraw\n");
return E_OUTOFMEMORY;
......@@ -309,7 +307,7 @@ DDRAW_Create(const GUID *guid,
if (FAILED(hr))
{
WARN("Failed to initialize ddraw object, hr %#x.\n", hr);
HeapFree(GetProcessHeap(), 0, ddraw);
heap_free(ddraw);
return hr;
}
......@@ -670,7 +668,7 @@ static ULONG WINAPI ddraw_class_factory_Release(IClassFactory *iface)
TRACE("%p decreasing refcount to %u.\n", factory, ref);
if (!ref)
HeapFree(GetProcessHeap(), 0, factory);
heap_free(factory);
return ref;
}
......@@ -754,8 +752,8 @@ HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, void **out)
return CLASS_E_CLASSNOTAVAILABLE;
}
factory = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*factory));
if (factory == NULL) return E_OUTOFMEMORY;
if (!(factory = heap_alloc_zero(sizeof(*factory))))
return E_OUTOFMEMORY;
factory->IClassFactory_iface.lpVtbl = &IClassFactory_Vtbl;
factory->ref = 1;
......
......@@ -150,7 +150,7 @@ static ULONG WINAPI d3d_material3_Release(IDirect3DMaterial3 *iface)
wined3d_mutex_unlock();
}
HeapFree(GetProcessHeap(), 0, material);
heap_free(material);
}
return ref;
......@@ -502,8 +502,7 @@ struct d3d_material *d3d_material_create(struct ddraw *ddraw)
{
struct d3d_material *material;
material = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*material));
if (!material)
if (!(material = heap_alloc_zero(sizeof(*material))))
return NULL;
material->IDirect3DMaterial3_iface.lpVtbl = &d3d_material3_vtbl;
......
......@@ -100,7 +100,7 @@ static ULONG WINAPI ddraw_palette_Release(IDirectDrawPalette *iface)
IUnknown_Release(palette->ifaceToRelease);
wined3d_mutex_unlock();
HeapFree(GetProcessHeap(), 0, palette);
heap_free(palette);
}
return ref;
......
......@@ -102,7 +102,7 @@ static ULONG WINAPI d3d_vertex_buffer7_Release(IDirect3DVertexBuffer7 *iface)
if (buffer->version == 7)
IDirectDraw7_Release(&buffer->ddraw->IDirectDraw7_iface);
HeapFree(GetProcessHeap(), 0, buffer);
heap_free(buffer);
}
return ref;
......@@ -451,8 +451,7 @@ HRESULT d3d_vertex_buffer_create(struct d3d_vertex_buffer **vertex_buf,
TRACE(" FVF %#x\n", desc->dwFVF);
TRACE(" dwNumVertices %u\n", desc->dwNumVertices);
buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*buffer));
if (!buffer)
if (!(buffer = heap_alloc_zero(sizeof(*buffer))))
return DDERR_OUTOFMEMORY;
buffer->IDirect3DVertexBuffer7_iface.lpVtbl = &d3d_vertex_buffer7_vtbl;
......@@ -489,7 +488,7 @@ end:
if (hr == D3D_OK)
*vertex_buf = buffer;
else
HeapFree(GetProcessHeap(), 0, buffer);
heap_free(buffer);
return hr;
}
......
......@@ -221,7 +221,7 @@ static ULONG WINAPI d3d_viewport_Release(IDirect3DViewport3 *iface)
TRACE("%p decreasing refcount to %u.\n", viewport, ref);
if (!ref)
HeapFree(GetProcessHeap(), 0, viewport);
heap_free(viewport);
return ref;
}
......
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