From ba67df7a6034278dcfb5dd9e9da8449d20ba6099 Mon Sep 17 00:00:00 2001 From: Henri Verbeet Date: Wed, 11 Apr 2012 22:52:02 +0200 Subject: [PATCH] d3d9: Introduce a separate function for vertex declaration creation. --- dlls/d3d9/d3d9_private.h | 4 ++-- dlls/d3d9/device.c | 23 ++++------------------- dlls/d3d9/vertexdeclaration.c | 29 ++++++++++++++++++++++++++++- 3 files changed, 34 insertions(+), 22 deletions(-) diff --git a/dlls/d3d9/d3d9_private.h b/dlls/d3d9/d3d9_private.h index 265ecfb1a6b..6ad6eedc833 100644 --- a/dlls/d3d9/d3d9_private.h +++ b/dlls/d3d9/d3d9_private.h @@ -395,8 +395,8 @@ typedef struct IDirect3DVertexDeclaration9Impl { } IDirect3DVertexDeclaration9Impl; void IDirect3DVertexDeclaration9Impl_Destroy(LPDIRECT3DVERTEXDECLARATION9 iface) DECLSPEC_HIDDEN; -HRESULT vertexdeclaration_init(IDirect3DVertexDeclaration9Impl *declaration, - IDirect3DDevice9Impl *device, const D3DVERTEXELEMENT9 *elements) DECLSPEC_HIDDEN; +HRESULT d3d9_vertex_declaration_create(IDirect3DDevice9Impl *device, + const D3DVERTEXELEMENT9 *elements, IDirect3DVertexDeclaration9Impl **declaration) DECLSPEC_HIDDEN; /* ---------------------- */ /* IDirect3DVertexShader9 */ diff --git a/dlls/d3d9/device.c b/dlls/d3d9/device.c index a9ca1d3142a..3aeb437dbdf 100644 --- a/dlls/d3d9/device.c +++ b/dlls/d3d9/device.c @@ -2073,7 +2073,7 @@ static HRESULT WINAPI IDirect3DDevice9Impl_ProcessVertices(IDirect3DDevice9Ex *i static HRESULT WINAPI IDirect3DDevice9Impl_CreateVertexDeclaration(IDirect3DDevice9Ex *iface, const D3DVERTEXELEMENT9 *elements, IDirect3DVertexDeclaration9 **declaration) { - IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface); + IDirect3DDevice9Impl *device = impl_from_IDirect3DDevice9Ex(iface); IDirect3DVertexDeclaration9Impl *object; HRESULT hr; @@ -2085,25 +2085,10 @@ static HRESULT WINAPI IDirect3DDevice9Impl_CreateVertexDeclaration(IDirect3DDevi return D3DERR_INVALIDCALL; } - object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object)); - if (!object) - { - ERR("Failed to allocate vertex declaration memory.\n"); - return E_OUTOFMEMORY; - } + if (SUCCEEDED(hr = d3d9_vertex_declaration_create(device, elements, &object))) + *declaration = (IDirect3DVertexDeclaration9 *)object; - 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; + return hr; } static HRESULT WINAPI IDirect3DDevice9Impl_SetVertexDeclaration(IDirect3DDevice9Ex *iface, diff --git a/dlls/d3d9/vertexdeclaration.c b/dlls/d3d9/vertexdeclaration.c index 3ed9eb7a4f1..a003d885a35 100644 --- a/dlls/d3d9/vertexdeclaration.c +++ b/dlls/d3d9/vertexdeclaration.c @@ -367,7 +367,7 @@ static HRESULT convert_to_wined3d_declaration(const D3DVERTEXELEMENT9 *d3d9_elem return D3D_OK; } -HRESULT vertexdeclaration_init(IDirect3DVertexDeclaration9Impl *declaration, +static HRESULT vertexdeclaration_init(IDirect3DVertexDeclaration9Impl *declaration, IDirect3DDevice9Impl *device, const D3DVERTEXELEMENT9 *elements) { struct wined3d_vertex_element *wined3d_elements; @@ -413,3 +413,30 @@ HRESULT vertexdeclaration_init(IDirect3DVertexDeclaration9Impl *declaration, return D3D_OK; } + +HRESULT d3d9_vertex_declaration_create(IDirect3DDevice9Impl *device, + const D3DVERTEXELEMENT9 *elements, IDirect3DVertexDeclaration9Impl **declaration) +{ + IDirect3DVertexDeclaration9Impl *object; + HRESULT hr; + + 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, device, 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 = object; + + return D3D_OK; +}