Module: wine Branch: master Commit: 7f8ccf03426b7558852ade31744bafb5a549beca URL: http://source.winehq.org/git/wine.git/?a=commit;h=7f8ccf03426b7558852ade3174...
Author: Henri Verbeet hverbeet@codeweavers.com Date: Tue Jan 19 23:52:29 2010 +0100
d3d9: Add a separate function for stateblock initialization.
---
dlls/d3d9/d3d9_private.h | 7 +-- dlls/d3d9/device.c | 91 ++++++++++++++++++++++++++++++++++++++++++ dlls/d3d9/stateblock.c | 98 ++++++++++----------------------------------- 3 files changed, 115 insertions(+), 81 deletions(-)
diff --git a/dlls/d3d9/d3d9_private.h b/dlls/d3d9/d3d9_private.h index c01da91..eb3a032 100644 --- a/dlls/d3d9/d3d9_private.h +++ b/dlls/d3d9/d3d9_private.h @@ -187,11 +187,6 @@ HRESULT device_init(IDirect3DDevice9Impl *device, IWineD3D *wined3d, UINT adapte extern HRESULT WINAPI IDirect3DDevice9Impl_GetSwapChain(IDirect3DDevice9Ex *iface, UINT iSwapChain, IDirect3DSwapChain9 **pSwapChain) DECLSPEC_HIDDEN; extern UINT WINAPI IDirect3DDevice9Impl_GetNumberOfSwapChains(IDirect3DDevice9Ex *iface) DECLSPEC_HIDDEN; -extern HRESULT WINAPI IDirect3DDevice9Impl_CreateStateBlock(IDirect3DDevice9Ex *iface, - D3DSTATEBLOCKTYPE Type, IDirect3DStateBlock9 **ppSB) DECLSPEC_HIDDEN; -extern HRESULT WINAPI IDirect3DDevice9Impl_BeginStateBlock(IDirect3DDevice9Ex *iface) DECLSPEC_HIDDEN; -extern HRESULT WINAPI IDirect3DDevice9Impl_EndStateBlock(IDirect3DDevice9Ex *iface, - IDirect3DStateBlock9 **ppSB) DECLSPEC_HIDDEN; extern HRESULT WINAPI IDirect3DDevice9Impl_SetVertexDeclaration(IDirect3DDevice9Ex *iface, IDirect3DVertexDeclaration9 *pDecl) DECLSPEC_HIDDEN; extern HRESULT WINAPI IDirect3DDevice9Impl_GetVertexDeclaration(IDirect3DDevice9Ex *iface, @@ -467,6 +462,8 @@ typedef struct IDirect3DStateBlock9Impl { LPDIRECT3DDEVICE9EX parentDevice; } IDirect3DStateBlock9Impl;
+HRESULT stateblock_init(IDirect3DStateBlock9Impl *stateblock, IDirect3DDevice9Impl *device, + D3DSTATEBLOCKTYPE type, IWineD3DStateBlock *wined3d_stateblock) DECLSPEC_HIDDEN;
/* --------------------------- */ /* IDirect3DVertexDeclaration9 */ diff --git a/dlls/d3d9/device.c b/dlls/d3d9/device.c index 35eaf7c..79a9ba0 100644 --- a/dlls/d3d9/device.c +++ b/dlls/d3d9/device.c @@ -1414,6 +1414,97 @@ static HRESULT WINAPI IDirect3DDevice9Impl_GetRenderState(LPDIRECT3DDEVICE9EX return hr; }
+static HRESULT WINAPI IDirect3DDevice9Impl_CreateStateBlock(IDirect3DDevice9Ex *iface, + D3DSTATEBLOCKTYPE type, IDirect3DStateBlock9 **stateblock) +{ + IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface; + IDirect3DStateBlock9Impl *object; + HRESULT hr; + + TRACE("iface %p, type %#x, stateblock %p.\n", iface, type, stateblock); + + if (type != D3DSBT_ALL && type != D3DSBT_PIXELSTATE && type != D3DSBT_VERTEXSTATE) + { + WARN("Unexpected stateblock type, returning D3DERR_INVALIDCALL.\n"); + return D3DERR_INVALIDCALL; + } + + object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object)); + if (!object) + { + ERR("Failed to allocate stateblock memory.\n"); + return E_OUTOFMEMORY; + } + + hr = stateblock_init(object, This, type, NULL); + if (FAILED(hr)) + { + WARN("Failed to initialize stateblock, hr %#x.\n", hr); + HeapFree(GetProcessHeap(), 0, object); + return hr; + } + + TRACE("Created stateblock %p.\n", object); + *stateblock = (IDirect3DStateBlock9 *)object; + + return D3D_OK; +} + +static HRESULT WINAPI IDirect3DDevice9Impl_BeginStateBlock(IDirect3DDevice9Ex *iface) +{ + IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface; + HRESULT hr; + + TRACE("iface %p.\n", iface); + + wined3d_mutex_lock(); + hr = IWineD3DDevice_BeginStateBlock(This->WineD3DDevice); + wined3d_mutex_unlock(); + + return hr; +} + +static HRESULT WINAPI IDirect3DDevice9Impl_EndStateBlock(IDirect3DDevice9Ex *iface, IDirect3DStateBlock9 **stateblock) +{ + IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface; + IWineD3DStateBlock *wined3d_stateblock; + IDirect3DStateBlock9Impl *object; + HRESULT hr; + + TRACE("iface %p, stateblock %p.\n", iface, stateblock); + + wined3d_mutex_lock(); + hr = IWineD3DDevice_EndStateBlock(This->WineD3DDevice, &wined3d_stateblock); + wined3d_mutex_unlock(); + if (FAILED(hr)) + { + WARN("IWineD3DDevice_EndStateBlock() failed, hr %#x.\n", hr); + return hr; + } + + object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object)); + if (!object) + { + ERR("Failed to allocate stateblock memory.\n"); + IWineD3DStateBlock_Release(wined3d_stateblock); + return E_OUTOFMEMORY; + } + + hr = stateblock_init(object, This, 0, wined3d_stateblock); + if (FAILED(hr)) + { + WARN("Failed to initialize stateblock, hr %#x.\n", hr); + IWineD3DStateBlock_Release(wined3d_stateblock); + HeapFree(GetProcessHeap(), 0, object); + return hr; + } + + TRACE("Created stateblock %p.\n", object); + *stateblock = (IDirect3DStateBlock9 *)object; + + return D3D_OK; +} + static HRESULT WINAPI IDirect3DDevice9Impl_SetClipStatus(LPDIRECT3DDEVICE9EX iface, CONST D3DCLIPSTATUS9* pClipStatus) { IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface; HRESULT hr; diff --git a/dlls/d3d9/stateblock.c b/dlls/d3d9/stateblock.c index 7cd3ba6..c4941db 100644 --- a/dlls/d3d9/stateblock.c +++ b/dlls/d3d9/stateblock.c @@ -123,87 +123,33 @@ static const IDirect3DStateBlock9Vtbl Direct3DStateBlock9_Vtbl = IDirect3DStateBlock9Impl_Apply };
- -/* IDirect3DDevice9 IDirect3DStateBlock9 Methods follow: */ -HRESULT WINAPI IDirect3DDevice9Impl_CreateStateBlock(LPDIRECT3DDEVICE9EX iface, D3DSTATEBLOCKTYPE Type, IDirect3DStateBlock9** ppStateBlock) { - IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface; - IDirect3DStateBlock9Impl* object; - HRESULT hrc = D3D_OK; - - TRACE("iface %p, type %#x, stateblock %p.\n", iface, Type, ppStateBlock); - - if(Type != D3DSBT_ALL && Type != D3DSBT_PIXELSTATE && - Type != D3DSBT_VERTEXSTATE ) { - WARN("Unexpected stateblock type, returning D3DERR_INVALIDCALL\n"); - return D3DERR_INVALIDCALL; - } - - object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DStateBlock9Impl)); - if (NULL == object) return E_OUTOFMEMORY; - object->lpVtbl = &Direct3DStateBlock9_Vtbl; - object->ref = 1; - - wined3d_mutex_lock(); - hrc = IWineD3DDevice_CreateStateBlock(This->WineD3DDevice, (WINED3DSTATEBLOCKTYPE)Type, &object->wineD3DStateBlock, (IUnknown*)object); - wined3d_mutex_unlock(); - - if(hrc != D3D_OK){ - FIXME("(%p) Call to IWineD3DDevice_CreateStateBlock failed.\n", This); - HeapFree(GetProcessHeap(), 0, object); - } else { - IDirect3DDevice9Ex_AddRef(iface); - object->parentDevice = iface; - *ppStateBlock = (IDirect3DStateBlock9*)object; - TRACE("(%p) : Created stateblock %p\n", This, object); - } - TRACE("(%p) returning token (ptr to stateblock) of %p\n", This, object); - return hrc; -} - -HRESULT WINAPI IDirect3DDevice9Impl_BeginStateBlock(IDirect3DDevice9Ex *iface) +HRESULT stateblock_init(IDirect3DStateBlock9Impl *stateblock, IDirect3DDevice9Impl *device, + D3DSTATEBLOCKTYPE type, IWineD3DStateBlock *wined3d_stateblock) { - IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface; HRESULT hr;
- TRACE("iface %p.\n", iface); - - wined3d_mutex_lock(); - hr = IWineD3DDevice_BeginStateBlock(This->WineD3DDevice); - wined3d_mutex_unlock(); - - return hr; -} + stateblock->lpVtbl = &Direct3DStateBlock9_Vtbl; + stateblock->ref = 1;
-HRESULT WINAPI IDirect3DDevice9Impl_EndStateBlock(IDirect3DDevice9Ex *iface, IDirect3DStateBlock9 **ppSB) -{ - IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface; - IWineD3DStateBlock *wineD3DStateBlock; - IDirect3DStateBlock9Impl *object; - HRESULT hr; - - TRACE("iface %p, stateblock %p.\n", iface, ppSB); - - /* Tell wineD3D to endstateblock before anything else (in case we run out - * of memory later and cause locking problems) */ - wined3d_mutex_lock(); - hr=IWineD3DDevice_EndStateBlock(This->WineD3DDevice,&wineD3DStateBlock); - wined3d_mutex_unlock(); - - if (hr!= D3D_OK) + if (wined3d_stateblock) { - WARN("IWineD3DDevice_EndStateBlock returned an error\n"); - return hr; + stateblock->wineD3DStateBlock = wined3d_stateblock; } - /* allocate a new IDirectD3DStateBlock */ - object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DStateBlock9Impl)); - if (!object) return E_OUTOFMEMORY; - object->ref = 1; - object->lpVtbl = &Direct3DStateBlock9_Vtbl; - object->wineD3DStateBlock = wineD3DStateBlock; - - IDirect3DDevice9Ex_AddRef(iface); - object->parentDevice = iface; - *ppSB=(IDirect3DStateBlock9*)object; - TRACE("(%p) Returning *ppSB %p, wineD3DStateBlock %p\n", This, *ppSB, wineD3DStateBlock); + else + { + wined3d_mutex_lock(); + hr = IWineD3DDevice_CreateStateBlock(device->WineD3DDevice, (WINED3DSTATEBLOCKTYPE)type, + &stateblock->wineD3DStateBlock, (IUnknown *)stateblock); + wined3d_mutex_unlock(); + if (FAILED(hr)) + { + WARN("Failed to create wined3d stateblock, hr %#x.\n", hr); + return hr; + } + } + + stateblock->parentDevice = (IDirect3DDevice9Ex *)device; + IDirect3DDevice9Ex_AddRef(stateblock->parentDevice); + return D3D_OK; }