ddraw: Add a separate function for execute buffer initialization.

This commit is contained in:
Henri Verbeet 2010-08-19 18:57:45 +02:00 committed by Alexandre Julliard
parent a60c493986
commit 584cb331a9
3 changed files with 45 additions and 40 deletions

View File

@ -614,8 +614,8 @@ struct IDirect3DExecuteBufferImpl
BOOL need_free;
};
/* The VTable */
extern const IDirect3DExecuteBufferVtbl IDirect3DExecuteBuffer_Vtbl DECLSPEC_HIDDEN;
HRESULT d3d_execute_buffer_init(IDirect3DExecuteBufferImpl *execute_buffer,
IDirect3DDeviceImpl *device, D3DEXECUTEBUFFERDESC *desc) DECLSPEC_HIDDEN;
/* The execute function */
void IDirect3DExecuteBufferImpl_Execute(IDirect3DExecuteBufferImpl *This,

View File

@ -712,6 +712,8 @@ IDirect3DDeviceImpl_1_CreateExecuteBuffer(IDirect3DDevice *iface,
{
IDirect3DDeviceImpl *This = device_from_device1(iface);
IDirect3DExecuteBufferImpl* object;
HRESULT hr;
TRACE("(%p)->(%p,%p,%p)!\n", This, Desc, ExecuteBuffer, UnkOuter);
if(UnkOuter)
@ -725,45 +727,13 @@ IDirect3DDeviceImpl_1_CreateExecuteBuffer(IDirect3DDevice *iface,
return DDERR_OUTOFMEMORY;
}
object->lpVtbl = &IDirect3DExecuteBuffer_Vtbl;
object->ref = 1;
object->d3ddev = This;
/* Initializes memory */
memcpy(&object->desc, Desc, Desc->dwSize);
/* No buffer given */
if ((object->desc.dwFlags & D3DDEB_LPDATA) == 0)
object->desc.lpData = NULL;
/* No buffer size given */
if ((object->desc.dwFlags & D3DDEB_BUFSIZE) == 0)
object->desc.dwBufferSize = 0;
/* Create buffer if asked */
if ((object->desc.lpData == NULL) && (object->desc.dwBufferSize > 0))
hr = d3d_execute_buffer_init(object, This, Desc);
if (FAILED(hr))
{
object->need_free = TRUE;
object->desc.lpData = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,object->desc.dwBufferSize);
if(!object->desc.lpData)
{
ERR("Out of memory when allocating the execute buffer data\n");
HeapFree(GetProcessHeap(), 0, object);
return DDERR_OUTOFMEMORY;
}
WARN("Failed to initialize execute buffer, hr %#x.\n", hr);
HeapFree(GetProcessHeap(), 0, object);
return hr;
}
else
{
object->need_free = FALSE;
}
/* No vertices for the moment */
object->vertex_data = NULL;
object->desc.dwFlags |= D3DDEB_LPDATA;
object->indices = NULL;
object->nb_indices = 0;
*ExecuteBuffer = (IDirect3DExecuteBuffer *)object;

View File

@ -825,7 +825,7 @@ IDirect3DExecuteBufferImpl_Optimize(IDirect3DExecuteBuffer *iface,
return DDERR_UNSUPPORTED; /* Unchecked */
}
const IDirect3DExecuteBufferVtbl IDirect3DExecuteBuffer_Vtbl =
static const struct IDirect3DExecuteBufferVtbl d3d_execute_buffer_vtbl =
{
IDirect3DExecuteBufferImpl_QueryInterface,
IDirect3DExecuteBufferImpl_AddRef,
@ -838,3 +838,38 @@ const IDirect3DExecuteBufferVtbl IDirect3DExecuteBuffer_Vtbl =
IDirect3DExecuteBufferImpl_Validate,
IDirect3DExecuteBufferImpl_Optimize,
};
HRESULT d3d_execute_buffer_init(IDirect3DExecuteBufferImpl *execute_buffer,
IDirect3DDeviceImpl *device, D3DEXECUTEBUFFERDESC *desc)
{
execute_buffer->lpVtbl = &d3d_execute_buffer_vtbl;
execute_buffer->ref = 1;
execute_buffer->d3ddev = device;
/* Initializes memory */
memcpy(&execute_buffer->desc, desc, desc->dwSize);
/* No buffer given */
if (!(execute_buffer->desc.dwFlags & D3DDEB_LPDATA))
execute_buffer->desc.lpData = NULL;
/* No buffer size given */
if (!(execute_buffer->desc.dwFlags & D3DDEB_BUFSIZE))
execute_buffer->desc.dwBufferSize = 0;
/* Create buffer if asked */
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)
{
ERR("Failed to allocate execute buffer data.\n");
return DDERR_OUTOFMEMORY;
}
}
execute_buffer->desc.dwFlags |= D3DDEB_LPDATA;
return D3D_OK;
}