From bfb63a8634ff818f00f9ce07870bb599d0425534 Mon Sep 17 00:00:00 2001 From: Henri Verbeet Date: Sun, 17 Jan 2010 21:31:29 +0100 Subject: [PATCH] d3d9: Add a separate function for query initialization. --- dlls/d3d9/d3d9_private.h | 6 +++--- dlls/d3d9/device.c | 31 +++++++++++++++++++++++++++++ dlls/d3d9/query.c | 51 ++++++++++++------------------------------------ 3 files changed, 47 insertions(+), 41 deletions(-) diff --git a/dlls/d3d9/d3d9_private.h b/dlls/d3d9/d3d9_private.h index 7736beace67..c01da916966 100644 --- a/dlls/d3d9/d3d9_private.h +++ b/dlls/d3d9/d3d9_private.h @@ -228,9 +228,6 @@ extern HRESULT WINAPI IDirect3DDevice9Impl_SetPixelShaderConstantB(IDirect3DDevi UINT StartRegister, const BOOL *pConstantData, UINT BoolCount) DECLSPEC_HIDDEN; extern HRESULT WINAPI IDirect3DDevice9Impl_GetPixelShaderConstantB(IDirect3DDevice9Ex *iface, UINT StartRegister, BOOL *pConstantData, UINT BoolCount) DECLSPEC_HIDDEN; -extern HRESULT WINAPI IDirect3DDevice9Impl_CreateQuery(IDirect3DDevice9Ex *iface, - D3DQUERYTYPE Type, IDirect3DQuery9 **ppQuery) DECLSPEC_HIDDEN; - /* ---------------- */ /* IDirect3DVolume9 */ @@ -564,4 +561,7 @@ typedef struct IDirect3DQuery9Impl { LPDIRECT3DDEVICE9EX parentDevice; } IDirect3DQuery9Impl; +HRESULT query_init(IDirect3DQuery9Impl *query, IDirect3DDevice9Impl *device, + D3DQUERYTYPE type) DECLSPEC_HIDDEN; + #endif /* __WINE_D3D9_PRIVATE_H */ diff --git a/dlls/d3d9/device.c b/dlls/d3d9/device.c index 4d0d4bd0424..35eaf7cbd27 100644 --- a/dlls/d3d9/device.c +++ b/dlls/d3d9/device.c @@ -2178,6 +2178,37 @@ static HRESULT WINAPI IDirect3DDevice9Impl_DeletePatch(LPDIRECT3DDEVICE9EX ifa return hr; } +static HRESULT WINAPI IDirect3DDevice9Impl_CreateQuery(IDirect3DDevice9Ex *iface, + D3DQUERYTYPE type, IDirect3DQuery9 **query) +{ + IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface; + IDirect3DQuery9Impl *object; + HRESULT hr; + + TRACE("iface %p, type %#x, query %p.\n", iface, type, query); + + object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object)); + if (!object) + { + ERR("Failed to allocate query memory.\n"); + return E_OUTOFMEMORY; + } + + hr = query_init(object, This, type); + if (FAILED(hr)) + { + WARN("Failed to initialize query, hr %#x.\n", hr); + HeapFree(GetProcessHeap(), 0, object); + return hr; + } + + TRACE("Created query %p.\n", object); + if (query) *query = (IDirect3DQuery9 *)object; + else IDirect3DQuery9_Release((IDirect3DQuery9 *)object); + + return D3D_OK; +} + static HRESULT WINAPI IDirect3DDevice9ExImpl_SetConvolutionMonoKernel(IDirect3DDevice9Ex *iface, UINT width, UINT height, float *rows, float *columns) { diff --git a/dlls/d3d9/query.c b/dlls/d3d9/query.c index ecb2e718eeb..a38dc9d15fb 100644 --- a/dlls/d3d9/query.c +++ b/dlls/d3d9/query.c @@ -150,49 +150,24 @@ static const IDirect3DQuery9Vtbl Direct3DQuery9_Vtbl = IDirect3DQuery9Impl_GetData }; +HRESULT query_init(IDirect3DQuery9Impl *query, IDirect3DDevice9Impl *device, D3DQUERYTYPE type) +{ + HRESULT hr; -/* IDirect3DDevice9 IDirect3DQuery9 Methods follow: */ -HRESULT WINAPI IDirect3DDevice9Impl_CreateQuery(LPDIRECT3DDEVICE9EX iface, D3DQUERYTYPE Type, IDirect3DQuery9** ppQuery) { - IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface; - IDirect3DQuery9Impl *object = NULL; - HRESULT hr = D3D_OK; - - TRACE("iface %p, type %#x, query %p.\n", iface, Type, ppQuery); + query->lpVtbl = &Direct3DQuery9_Vtbl; + query->ref = 1; - if (!ppQuery) + wined3d_mutex_lock(); + hr = IWineD3DDevice_CreateQuery(device->WineD3DDevice, type, &query->wineD3DQuery, (IUnknown *)query); + wined3d_mutex_unlock(); + if (FAILED(hr)) { - wined3d_mutex_lock(); - hr = IWineD3DDevice_CreateQuery(This->WineD3DDevice, Type, NULL, NULL); - wined3d_mutex_unlock(); - + WARN("Failed to create wined3d query, hr %#x.\n", hr); return hr; } - /* Allocate the storage for the device */ - object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DQuery9Impl)); - if (NULL == object) { - ERR("Allocation of memory failed, returning D3DERR_OUTOFVIDEOMEMORY\n"); - return D3DERR_OUTOFVIDEOMEMORY; - } + query->parentDevice = (IDirect3DDevice9Ex *)device; + IDirect3DDevice9Ex_AddRef(query->parentDevice); - object->lpVtbl = &Direct3DQuery9_Vtbl; - object->ref = 1; - - wined3d_mutex_lock(); - hr = IWineD3DDevice_CreateQuery(This->WineD3DDevice, Type, &object->wineD3DQuery, (IUnknown *)object); - wined3d_mutex_unlock(); - - if (FAILED(hr)) { - - /* free up object */ - WARN("(%p) call to IWineD3DDevice_CreateQuery failed\n", This); - HeapFree(GetProcessHeap(), 0, object); - } else { - IDirect3DDevice9Ex_AddRef(iface); - object->parentDevice = iface; - *ppQuery = (LPDIRECT3DQUERY9) object; - TRACE("(%p) : Created query %p\n", This , object); - } - TRACE("(%p) : returning %x\n", This, hr); - return hr; + return D3D_OK; } -- 2.11.4.GIT