Module: wine Branch: master Commit: 0241fefa94c1153ea1555d3c49026df3f5bff44a URL: http://source.winehq.org/git/wine.git/?a=commit;h=0241fefa94c1153ea1555d3c49...
Author: Henri Verbeet hverbeet@codeweavers.com Date: Wed Sep 23 10:05:49 2009 +0200
d3d9: Add a separate function for vertex declaration initialization.
---
dlls/d3d9/d3d9_private.h | 4 +- dlls/d3d9/device.c | 36 +++++++++++++++++++++ dlls/d3d9/vertexdeclaration.c | 70 ++++++++++++++--------------------------- 3 files changed, 62 insertions(+), 48 deletions(-)
diff --git a/dlls/d3d9/d3d9_private.h b/dlls/d3d9/d3d9_private.h index c9b3581..ebbdcdd 100644 --- a/dlls/d3d9/d3d9_private.h +++ b/dlls/d3d9/d3d9_private.h @@ -202,8 +202,6 @@ extern HRESULT WINAPI IDirect3DDevice9Impl_CreateStateBlock(IDirect3DDevice9Ex * extern HRESULT WINAPI IDirect3DDevice9Impl_BeginStateBlock(IDirect3DDevice9Ex *iface) DECLSPEC_HIDDEN; extern HRESULT WINAPI IDirect3DDevice9Impl_EndStateBlock(IDirect3DDevice9Ex *iface, IDirect3DStateBlock9 **ppSB) DECLSPEC_HIDDEN; -extern HRESULT WINAPI IDirect3DDevice9Impl_CreateVertexDeclaration(IDirect3DDevice9Ex *iface, - const D3DVERTEXELEMENT9 *pVertexElements, IDirect3DVertexDeclaration9 **ppDecl) DECLSPEC_HIDDEN; extern HRESULT WINAPI IDirect3DDevice9Impl_SetVertexDeclaration(IDirect3DDevice9Ex *iface, IDirect3DVertexDeclaration9 *pDecl) DECLSPEC_HIDDEN; extern HRESULT WINAPI IDirect3DDevice9Impl_GetVertexDeclaration(IDirect3DDevice9Ex *iface, @@ -508,6 +506,8 @@ typedef struct IDirect3DVertexDeclaration9Impl { } IDirect3DVertexDeclaration9Impl;
void IDirect3DVertexDeclaration9Impl_Destroy(LPDIRECT3DVERTEXDECLARATION9 iface) DECLSPEC_HIDDEN; +HRESULT vertexdeclaration_init(IDirect3DVertexDeclaration9Impl *declaration, + IDirect3DDevice9Impl *device, const D3DVERTEXELEMENT9 *elements) DECLSPEC_HIDDEN;
/* ---------------------- */ /* IDirect3DVertexShader9 */ diff --git a/dlls/d3d9/device.c b/dlls/d3d9/device.c index f3b2e5e..19bdcba 100644 --- a/dlls/d3d9/device.c +++ b/dlls/d3d9/device.c @@ -1678,6 +1678,42 @@ static HRESULT WINAPI IDirect3DDevice9Impl_ProcessVertices(LPDIRECT3DDEVICE9EX return hr; }
+static HRESULT WINAPI IDirect3DDevice9Impl_CreateVertexDeclaration(IDirect3DDevice9Ex *iface, + const D3DVERTEXELEMENT9 *elements, IDirect3DVertexDeclaration9 **declaration) +{ + IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface; + IDirect3DVertexDeclaration9Impl *object; + HRESULT hr; + + TRACE("iface %p, elements %p, declaration %p.\n", iface, elements, declaration); + + if (!declaration) + { + WARN("Caller passed a NULL declaration, returning D3DERR_INVALIDCALL.\n"); + return D3DERR_INVALIDCALL; + } + + object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object)); + if (!object) + { + ERR("Failed to allocate vertex declaration memory.\n"); + return E_OUTOFMEMORY; + } + + hr = vertexdeclaration_init(object, This, elements); + if (FAILED(hr)) + { + WARN("Failed to initialize vertex declaration, hr %#x.\n", hr); + HeapFree(GetProcessHeap(), 0, object); + return hr; + } + + TRACE("Created vertex declaration %p.\n", object); + *declaration = (IDirect3DVertexDeclaration9 *)object; + + return D3D_OK; +} + static IDirect3DVertexDeclaration9 *getConvertedDecl(IDirect3DDevice9Impl *This, DWORD fvf) { HRESULT hr; D3DVERTEXELEMENT9* elements = NULL; diff --git a/dlls/d3d9/vertexdeclaration.c b/dlls/d3d9/vertexdeclaration.c index e6dc0a3..fc00f41 100644 --- a/dlls/d3d9/vertexdeclaration.c +++ b/dlls/d3d9/vertexdeclaration.c @@ -349,72 +349,50 @@ static HRESULT convert_to_wined3d_declaration(const D3DVERTEXELEMENT9* d3d9_elem return D3D_OK; }
-/* IDirect3DDevice9 IDirect3DVertexDeclaration9 Methods follow: */ -HRESULT WINAPI IDirect3DDevice9Impl_CreateVertexDeclaration(IDirect3DDevice9Ex *iface, - const D3DVERTEXELEMENT9 *pVertexElements, IDirect3DVertexDeclaration9 **ppDecl) +HRESULT vertexdeclaration_init(IDirect3DVertexDeclaration9Impl *declaration, + IDirect3DDevice9Impl *device, const D3DVERTEXELEMENT9 *elements) { - IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface; - IDirect3DVertexDeclaration9Impl *object = NULL; - WINED3DVERTEXELEMENT* wined3d_elements; + WINED3DVERTEXELEMENT *wined3d_elements; UINT wined3d_element_count; UINT element_count; HRESULT hr;
- TRACE("(%p) : Relay\n", iface); - if (NULL == ppDecl) { - WARN("(%p) : Caller passed NULL As ppDecl, returning D3DERR_INVALIDCALL\n",This); - return D3DERR_INVALIDCALL; - } - - hr = convert_to_wined3d_declaration(pVertexElements, &wined3d_elements, &wined3d_element_count); + hr = convert_to_wined3d_declaration(elements, &wined3d_elements, &wined3d_element_count); if (FAILED(hr)) { - WARN("(%p) : Error parsing vertex declaration\n", This); + WARN("Failed to create wined3d vertex declaration elements, hr %#x.\n", hr); return hr; }
- /* Allocate the storage for the device */ - object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DVertexDeclaration9Impl)); - if (NULL == object) { - HeapFree(GetProcessHeap(), 0, wined3d_elements); - FIXME("Allocation of memory failed, returning D3DERR_OUTOFVIDEOMEMORY\n"); - return D3DERR_OUTOFVIDEOMEMORY; - } - - object->lpVtbl = &Direct3DVertexDeclaration9_Vtbl; - object->ref = 0; + declaration->lpVtbl = &Direct3DVertexDeclaration9_Vtbl; + declaration->ref = 1;
element_count = wined3d_element_count + 1; - object->elements = HeapAlloc(GetProcessHeap(), 0, element_count * sizeof(D3DVERTEXELEMENT9)); - if (!object->elements) { + declaration->elements = HeapAlloc(GetProcessHeap(), 0, element_count * sizeof(*declaration->elements)); + if (!declaration->elements) + { HeapFree(GetProcessHeap(), 0, wined3d_elements); - HeapFree(GetProcessHeap(), 0, object); - ERR("Memory allocation failed\n"); + ERR("Failed to allocate vertex declaration elements memory.\n"); return D3DERR_OUTOFVIDEOMEMORY; } - CopyMemory(object->elements, pVertexElements, element_count * sizeof(D3DVERTEXELEMENT9)); - object->element_count = element_count; + memcpy(declaration->elements, elements, element_count * sizeof(*elements)); + declaration->element_count = element_count;
wined3d_mutex_lock(); - hr = IWineD3DDevice_CreateVertexDeclaration(This->WineD3DDevice, &object->wineD3DVertexDeclaration, - (IUnknown *)object, wined3d_elements, wined3d_element_count); + hr = IWineD3DDevice_CreateVertexDeclaration(device->WineD3DDevice, &declaration->wineD3DVertexDeclaration, + (IUnknown *)declaration, wined3d_elements, wined3d_element_count); wined3d_mutex_unlock(); - HeapFree(GetProcessHeap(), 0, wined3d_elements); + if (FAILED(hr)) + { + WARN("Failed to create wined3d vertex declaration, hr %#x.\n", hr); + return hr; + }
- if (FAILED(hr)) { + declaration->parentDevice = (IDirect3DDevice9Ex *)device; + IDirect3DDevice9Ex_AddRef(declaration->parentDevice);
- /* free up object */ - WARN("(%p) call to IWineD3DDevice_CreateVertexDeclaration failed\n", This); - HeapFree(GetProcessHeap(), 0, object->elements); - HeapFree(GetProcessHeap(), 0, object); - } else { - object->parentDevice = iface; - *ppDecl = (LPDIRECT3DVERTEXDECLARATION9) object; - IDirect3DVertexDeclaration9_AddRef(*ppDecl); - TRACE("(%p) : Created vertex declaration %p\n", This, object); - } - return hr; + return D3D_OK; }
HRESULT WINAPI IDirect3DDevice9Impl_SetVertexDeclaration(LPDIRECT3DDEVICE9EX iface, IDirect3DVertexDeclaration9* pDecl) {