[PATCH 5/5] d3d8: Directly store a wined3d stateblock in the stateblock handle.
Henri Verbeet
hverbeet at codeweavers.com
Thu Dec 3 04:38:23 CST 2009
IDirect3DStateBlock8Impl doesn't actually do anything useful.
---
dlls/d3d8/Makefile.in | 1 -
dlls/d3d8/d3d8_private.h | 61 ----------------------
dlls/d3d8/device.c | 72 ++++++++++---------------
dlls/d3d8/stateblock.c | 128 ----------------------------------------------
4 files changed, 29 insertions(+), 233 deletions(-)
delete mode 100644 dlls/d3d8/stateblock.c
diff --git a/dlls/d3d8/Makefile.in b/dlls/d3d8/Makefile.in
index 3a09256..84b477c 100644
--- a/dlls/d3d8/Makefile.in
+++ b/dlls/d3d8/Makefile.in
@@ -13,7 +13,6 @@ C_SRCS = \
directx.c \
indexbuffer.c \
pixelshader.c \
- stateblock.c \
surface.c \
swapchain.c \
texture.c \
diff --git a/dlls/d3d8/d3d8_private.h b/dlls/d3d8/d3d8_private.h
index f6ceeed..b357282 100644
--- a/dlls/d3d8/d3d8_private.h
+++ b/dlls/d3d8/d3d8_private.h
@@ -112,14 +112,6 @@ typedef struct IDirect3DSwapChain8Impl IDirect3DSwapChain8Impl;
typedef struct IDirect3DResource8Impl IDirect3DResource8Impl;
typedef struct IDirect3DVolume8Impl IDirect3DVolume8Impl;
typedef struct IDirect3DVertexBuffer8Impl IDirect3DVertexBuffer8Impl;
-
-/** Private Interfaces: */
-typedef struct IDirect3DStateBlockImpl IDirect3DStateBlockImpl;
-typedef struct IDirect3DVertexShaderImpl IDirect3DVertexShaderImpl;
-typedef struct IDirect3DPixelShaderImpl IDirect3DPixelShaderImpl;
-typedef struct IDirect3DVertexShaderDeclarationImpl IDirect3DVertexShaderDeclarationImpl;
-
-/* Advance declaration of structures to satisfy compiler */
typedef struct IDirect3DVertexShader8Impl IDirect3DVertexShader8Impl;
/* ===========================================================================
@@ -443,15 +435,6 @@ struct IDirect3DVolumeTexture8Impl
HRESULT volumetexture_init(IDirect3DVolumeTexture8Impl *texture, IDirect3DDevice8Impl *device,
UINT width, UINT height, UINT depth, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool) DECLSPEC_HIDDEN;
-/* ----------------------- */
-/* IDirect3DStateBlockImpl */
-/* ----------------------- */
-
-/* TODO: Generate a valid GUIDs */
-/* {83B073CE-6F30-11d9-C687-00046142C14F} */
-DEFINE_GUID(IID_IDirect3DStateBlock8,
-0x83b073ce, 0x6f30, 0x11d9, 0xc6, 0x87, 0x0, 0x4, 0x61, 0x42, 0xc1, 0x4f);
-
DEFINE_GUID(IID_IDirect3DVertexDeclaration8,
0x5dd7478d, 0xcbf3, 0x41a6, 0x8c, 0xfd, 0xfd, 0x19, 0x2b, 0x11, 0xc7, 0x90);
@@ -461,50 +444,6 @@ DEFINE_GUID(IID_IDirect3DVertexShader8,
DEFINE_GUID(IID_IDirect3DPixelShader8,
0x6d3bdbdc, 0x5b02, 0x4415, 0xb8, 0x52, 0xce, 0x5e, 0x8b, 0xcc, 0xb2, 0x89);
-
-/*****************************************************************************
- * IDirect3DStateBlock8 interface
- */
-#define INTERFACE IDirect3DStateBlock8
-DECLARE_INTERFACE_(IDirect3DStateBlock8, IUnknown)
-{
- /*** IUnknown methods ***/
- STDMETHOD_(HRESULT,QueryInterface)(THIS_ REFIID riid, void** ppvObject) PURE;
- STDMETHOD_(ULONG,AddRef)(THIS) PURE;
- STDMETHOD_(ULONG,Release)(THIS) PURE;
- /*** IDirect3DStateBlock9 methods ***/
- STDMETHOD(GetDevice)(THIS_ struct IDirect3DDevice8** ppDevice) PURE;
- STDMETHOD(Capture)(THIS) PURE;
- STDMETHOD(Apply)(THIS) PURE;
-};
-#undef INTERFACE
-
-/*** IUnknown methods ***/
-#define IDirect3DStateBlock8_QueryInterface(p,a,b) (p)->lpVtbl->QueryInterface(p,a,b)
-#define IDirect3DStateBlock8_AddRef(p) (p)->lpVtbl->AddRef(p)
-#define IDirect3DStateBlock8_Release(p) (p)->lpVtbl->Release(p)
-/*** IDirect3DStateBlock9 methods ***/
-#define IDirect3DStateBlock8_GetDevice(p,a) (p)->lpVtbl->GetDevice(p,a)
-#define IDirect3DStateBlock8_Capture(p) (p)->lpVtbl->Capture(p)
-#define IDirect3DStateBlock8_Apply(p) (p)->lpVtbl->Apply(p)
-
-/*****************************************************************************
- * Predeclare the interface implementation structures
- */
-extern const IDirect3DStateBlock8Vtbl Direct3DStateBlock8_Vtbl DECLSPEC_HIDDEN;
-
-/*****************************************************************************
- * IDirect3DStateBlock implementation structure
- */
-typedef struct IDirect3DStateBlock8Impl {
- /* IUnknown fields */
- const IDirect3DStateBlock8Vtbl *lpVtbl;
- LONG ref;
-
- /* IDirect3DResource8 fields */
- IWineD3DStateBlock *wineD3DStateBlock;
-} IDirect3DStateBlock8Impl;
-
/*****************************************************************************
* IDirect3DVertexDeclaration8 interface
*/
diff --git a/dlls/d3d8/device.c b/dlls/d3d8/device.c
index f390691..85b758c 100644
--- a/dlls/d3d8/device.c
+++ b/dlls/d3d8/device.c
@@ -1335,9 +1335,8 @@ static HRESULT WINAPI IDirect3DDevice8Impl_BeginStateBlock(LPDIRECT3DDEVICE8 ifa
static HRESULT WINAPI IDirect3DDevice8Impl_EndStateBlock(LPDIRECT3DDEVICE8 iface, DWORD* pToken) {
IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
+ IWineD3DStateBlock *stateblock;
HRESULT hr;
- IWineD3DStateBlock* wineD3DStateBlock;
- IDirect3DStateBlock8Impl* object;
TRACE("iface %p, token %p.\n", iface, pToken);
@@ -1345,52 +1344,47 @@ static HRESULT WINAPI IDirect3DDevice8Impl_EndStateBlock(LPDIRECT3DDEVICE8 iface
* of memory later and cause locking problems)
*/
wined3d_mutex_lock();
- hr = IWineD3DDevice_EndStateBlock(This->WineD3DDevice , &wineD3DStateBlock);
+ hr = IWineD3DDevice_EndStateBlock(This->WineD3DDevice , &stateblock);
if (hr != D3D_OK) {
WARN("IWineD3DDevice_EndStateBlock returned an error\n");
wined3d_mutex_unlock();
return hr;
}
- /* allocate a new IDirectD3DStateBlock */
- object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY ,sizeof(IDirect3DStateBlock8Impl));
- object->ref = 1;
- object->lpVtbl = &Direct3DStateBlock8_Vtbl;
-
- object->wineD3DStateBlock = wineD3DStateBlock;
-
- *pToken = d3d8_allocate_handle(&This->handle_table, object, D3D8_HANDLE_SB);
+ *pToken = d3d8_allocate_handle(&This->handle_table, stateblock, D3D8_HANDLE_SB);
wined3d_mutex_unlock();
if (*pToken == D3D8_INVALID_HANDLE)
{
ERR("Failed to create a handle\n");
- IDirect3DStateBlock8_Release((IDirect3DStateBlock8 *)object);
+ wined3d_mutex_lock();
+ IWineD3DStateBlock_Release(stateblock);
+ wined3d_mutex_unlock();
return E_FAIL;
}
++*pToken;
- TRACE("Returning %#x (%p).\n", *pToken, object);
+ TRACE("Returning %#x (%p).\n", *pToken, stateblock);
return hr;
}
static HRESULT WINAPI IDirect3DDevice8Impl_ApplyStateBlock(LPDIRECT3DDEVICE8 iface, DWORD Token) {
IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
- IDirect3DStateBlock8Impl *pSB;
+ IWineD3DStateBlock *stateblock;
HRESULT hr;
TRACE("iface %p, token %#x.\n", iface, Token);
wined3d_mutex_lock();
- pSB = d3d8_get_object(&This->handle_table, Token - 1, D3D8_HANDLE_SB);
- if (!pSB)
+ stateblock = d3d8_get_object(&This->handle_table, Token - 1, D3D8_HANDLE_SB);
+ if (!stateblock)
{
WARN("Invalid handle (%#x) passed.\n", Token);
wined3d_mutex_unlock();
return D3DERR_INVALIDCALL;
}
- hr = IWineD3DStateBlock_Apply(pSB->wineD3DStateBlock);
+ hr = IWineD3DStateBlock_Apply(stateblock);
wined3d_mutex_unlock();
return hr;
@@ -1398,20 +1392,20 @@ static HRESULT WINAPI IDirect3DDevice8Impl_ApplyStateBlock(LPDIRECT3DDEVICE8 ifa
static HRESULT WINAPI IDirect3DDevice8Impl_CaptureStateBlock(LPDIRECT3DDEVICE8 iface, DWORD Token) {
IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
- IDirect3DStateBlock8Impl *pSB;
+ IWineD3DStateBlock *stateblock;
HRESULT hr;
TRACE("iface %p, token %#x.\n", iface, Token);
wined3d_mutex_lock();
- pSB = d3d8_get_object(&This->handle_table, Token - 1, D3D8_HANDLE_SB);
- if (!pSB)
+ stateblock = d3d8_get_object(&This->handle_table, Token - 1, D3D8_HANDLE_SB);
+ if (!stateblock)
{
WARN("Invalid handle (%#x) passed.\n", Token);
wined3d_mutex_unlock();
return D3DERR_INVALIDCALL;
}
- hr = IWineD3DStateBlock_Capture(pSB->wineD3DStateBlock);
+ hr = IWineD3DStateBlock_Capture(stateblock);
wined3d_mutex_unlock();
return hr;
@@ -1419,24 +1413,25 @@ static HRESULT WINAPI IDirect3DDevice8Impl_CaptureStateBlock(LPDIRECT3DDEVICE8 i
static HRESULT WINAPI IDirect3DDevice8Impl_DeleteStateBlock(LPDIRECT3DDEVICE8 iface, DWORD Token) {
IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
- IDirect3DStateBlock8Impl *pSB;
+ IWineD3DStateBlock *stateblock;
TRACE("iface %p, token %#x.\n", iface, Token);
wined3d_mutex_lock();
- pSB = d3d8_free_handle(&This->handle_table, Token - 1, D3D8_HANDLE_SB);
- wined3d_mutex_unlock();
+ stateblock = d3d8_free_handle(&This->handle_table, Token - 1, D3D8_HANDLE_SB);
- if (!pSB)
+ if (!stateblock)
{
WARN("Invalid handle (%#x) passed.\n", Token);
+ wined3d_mutex_unlock();
return D3DERR_INVALIDCALL;
}
- if (IUnknown_Release((IUnknown *)pSB))
+ if (IWineD3DStateBlock_Release((IUnknown *)stateblock))
{
- ERR("Stateblock %p has references left, this shouldn't happen.\n", pSB);
+ ERR("Stateblock %p has references left, this shouldn't happen.\n", stateblock);
}
+ wined3d_mutex_unlock();
return D3D_OK;
}
@@ -1445,7 +1440,7 @@ static HRESULT WINAPI IDirect3DDevice8Impl_CreateStateBlock(IDirect3DDevice8 *if
D3DSTATEBLOCKTYPE Type, DWORD *handle)
{
IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
- IDirect3DStateBlock8Impl *object;
+ IWineD3DStateBlock *stateblock;
HRESULT hr;
TRACE("iface %p, type %#x, handle %p.\n", iface, Type, handle);
@@ -1458,39 +1453,30 @@ static HRESULT WINAPI IDirect3DDevice8Impl_CreateStateBlock(IDirect3DDevice8 *if
return D3DERR_INVALIDCALL;
}
- object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DStateBlock8Impl));
- if (!object)
- {
- ERR("Failed to allocate memory.\n");
- return E_OUTOFMEMORY;
- }
-
- object->lpVtbl = &Direct3DStateBlock8_Vtbl;
- object->ref = 1;
-
wined3d_mutex_lock();
hr = IWineD3DDevice_CreateStateBlock(This->WineD3DDevice, (WINED3DSTATEBLOCKTYPE)Type,
- &object->wineD3DStateBlock, (IUnknown *)object);
+ &stateblock, NULL);
if (FAILED(hr))
{
wined3d_mutex_unlock();
ERR("IWineD3DDevice_CreateStateBlock failed, hr %#x\n", hr);
- HeapFree(GetProcessHeap(), 0, object);
return hr;
}
- *handle = d3d8_allocate_handle(&This->handle_table, object, D3D8_HANDLE_SB);
+ *handle = d3d8_allocate_handle(&This->handle_table, stateblock, D3D8_HANDLE_SB);
wined3d_mutex_unlock();
if (*handle == D3D8_INVALID_HANDLE)
{
ERR("Failed to allocate a handle.\n");
- IDirect3DStateBlock8_Release((IDirect3DStateBlock8 *)object);
+ wined3d_mutex_lock();
+ IWineD3DStateBlock_Release(stateblock);
+ wined3d_mutex_unlock();
return E_FAIL;
}
++*handle;
- TRACE("Returning %#x (%p).\n", *handle, object);
+ TRACE("Returning %#x (%p).\n", *handle, stateblock);
return hr;
}
diff --git a/dlls/d3d8/stateblock.c b/dlls/d3d8/stateblock.c
deleted file mode 100644
index 75ab487..0000000
--- a/dlls/d3d8/stateblock.c
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * IDirect3DStateBlock8 implementation
- *
- * Copyright 2002-2003 Raphael Junqueira
- * Copyright 2002-2003 Jason Edmeades
- * Copyright 2005 Oliver Stieber
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
- */
-
-#include "config.h"
-#include "d3d8_private.h"
-
-WINE_DEFAULT_DEBUG_CHANNEL(d3d8);
-
-/* NOTE: DirectX8 doesn't export an IDirect3DStateBlock8, the interface is used internally to keep d3d8 and d3d9 as similar as possible */
-/* IDirect3DStateBlock8 IUnknown parts follow: */
-static HRESULT WINAPI IDirect3DStateBlock8Impl_QueryInterface(IDirect3DStateBlock8 *iface, REFIID riid, LPVOID *ppobj) {
- IDirect3DStateBlock8Impl *This = (IDirect3DStateBlock8Impl *)iface;
-
- TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
-
- if (IsEqualGUID(riid, &IID_IUnknown)
- || IsEqualGUID(riid, &IID_IDirect3DStateBlock8)) {
- IUnknown_AddRef(iface);
- *ppobj = This;
- return S_OK;
- }
-
- WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
- *ppobj = NULL;
- return E_NOINTERFACE;
-}
-
-static ULONG WINAPI IDirect3DStateBlock8Impl_AddRef(IDirect3DStateBlock8 *iface) {
- IDirect3DStateBlock8Impl *This = (IDirect3DStateBlock8Impl *)iface;
- ULONG ref = InterlockedIncrement(&This->ref);
-
- TRACE("%p increasing refcount to %u.\n", iface, ref);
-
- return ref;
-}
-
-static ULONG WINAPI IDirect3DStateBlock8Impl_Release(IDirect3DStateBlock8 *iface) {
- IDirect3DStateBlock8Impl *This = (IDirect3DStateBlock8Impl *)iface;
- ULONG ref = InterlockedDecrement(&This->ref);
-
- TRACE("%p decreasing refcount to %u.\n", iface, ref);
-
- if (ref == 0) {
- wined3d_mutex_lock();
- IWineD3DStateBlock_Release(This->wineD3DStateBlock);
- wined3d_mutex_unlock();
-
- HeapFree(GetProcessHeap(), 0, This);
- }
- return ref;
-}
-
-/* IDirect3DStateBlock8 Interface follow: */
-static HRESULT WINAPI IDirect3DStateBlock8Impl_GetDevice(IDirect3DStateBlock8 *iface, IDirect3DDevice8 **ppDevice) {
- IDirect3DStateBlock8Impl *This = (IDirect3DStateBlock8Impl *)iface;
- IWineD3DDevice *wined3d_device;
- HRESULT hr;
-
- TRACE("iface %p, device %p.\n", iface, ppDevice);
-
- wined3d_mutex_lock();
- hr = IWineD3DStateBlock_GetDevice(This->wineD3DStateBlock, &wined3d_device);
- if (SUCCEEDED(hr))
- {
- IWineD3DDevice_GetParent(wined3d_device, (IUnknown **)ppDevice);
- IWineD3DDevice_Release(wined3d_device);
- }
- wined3d_mutex_unlock();
-
- return hr;
-}
-
-static HRESULT WINAPI IDirect3DStateBlock8Impl_Capture(IDirect3DStateBlock8 *iface) {
- IDirect3DStateBlock8Impl *This = (IDirect3DStateBlock8Impl *)iface;
- HRESULT hr;
-
- TRACE("iface %p.\n", iface);
-
- wined3d_mutex_lock();
- hr = IWineD3DStateBlock_Capture(This->wineD3DStateBlock);
- wined3d_mutex_unlock();
-
- return hr;
-}
-
-static HRESULT WINAPI IDirect3DStateBlock8Impl_Apply(IDirect3DStateBlock8 *iface) {
- IDirect3DStateBlock8Impl *This = (IDirect3DStateBlock8Impl *)iface;
- HRESULT hr;
-
- TRACE("iface %p.\n", iface);
-
- wined3d_mutex_lock();
- hr = IWineD3DStateBlock_Apply(This->wineD3DStateBlock);
- wined3d_mutex_unlock();
-
- return hr;
-}
-
-const IDirect3DStateBlock8Vtbl Direct3DStateBlock8_Vtbl =
-{
- /* IUnknown */
- IDirect3DStateBlock8Impl_QueryInterface,
- IDirect3DStateBlock8Impl_AddRef,
- IDirect3DStateBlock8Impl_Release,
- /* IDirect3DStateBlock8 */
- IDirect3DStateBlock8Impl_GetDevice,
- IDirect3DStateBlock8Impl_Capture,
- IDirect3DStateBlock8Impl_Apply
-};
--
1.6.4.4
More information about the wine-patches
mailing list