2 * IDirect3DStateBlock9 implementation
4 * Copyright 2002-2003 Raphael Junqueira
5 * Copyright 2002-2003 Jason Edmeades
6 * Copyright 2005 Oliver Stieber
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "d3d9_private.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(d3d9
);
28 /* IDirect3DStateBlock9 IUnknown parts follow: */
29 static HRESULT WINAPI
IDirect3DStateBlock9Impl_QueryInterface(LPDIRECT3DSTATEBLOCK9 iface
, REFIID riid
, LPVOID
* ppobj
) {
30 IDirect3DStateBlock9Impl
*This
= (IDirect3DStateBlock9Impl
*)iface
;
32 if (IsEqualGUID(riid
, &IID_IUnknown
)
33 || IsEqualGUID(riid
, &IID_IDirect3DStateBlock9
)) {
34 IDirect3DStateBlock9_AddRef(iface
);
39 WARN("(%p)->(%s,%p),not found\n", This
, debugstr_guid(riid
), ppobj
);
44 static ULONG WINAPI
IDirect3DStateBlock9Impl_AddRef(LPDIRECT3DSTATEBLOCK9 iface
) {
45 IDirect3DStateBlock9Impl
*This
= (IDirect3DStateBlock9Impl
*)iface
;
46 ULONG ref
= InterlockedIncrement(&This
->ref
);
48 TRACE("(%p) : AddRef from %d\n", This
, ref
- 1);
53 static ULONG WINAPI
IDirect3DStateBlock9Impl_Release(LPDIRECT3DSTATEBLOCK9 iface
) {
54 IDirect3DStateBlock9Impl
*This
= (IDirect3DStateBlock9Impl
*)iface
;
55 ULONG ref
= InterlockedDecrement(&This
->ref
);
57 TRACE("(%p) : ReleaseRef to %d\n", This
, ref
);
60 EnterCriticalSection(&d3d9_cs
);
61 IWineD3DStateBlock_Release(This
->wineD3DStateBlock
);
62 LeaveCriticalSection(&d3d9_cs
);
63 IDirect3DDevice9Ex_Release(This
->parentDevice
);
64 HeapFree(GetProcessHeap(), 0, This
);
69 /* IDirect3DStateBlock9 Interface follow: */
70 static HRESULT WINAPI
IDirect3DStateBlock9Impl_GetDevice(LPDIRECT3DSTATEBLOCK9 iface
, IDirect3DDevice9
** ppDevice
) {
71 IDirect3DStateBlock9Impl
*This
= (IDirect3DStateBlock9Impl
*)iface
;
72 IWineD3DDevice
*wined3d_device
;
74 TRACE("(%p) Relay\n", This
);
76 EnterCriticalSection(&d3d9_cs
);
77 hr
= IWineD3DStateBlock_GetDevice(This
->wineD3DStateBlock
, &wined3d_device
);
80 IWineD3DDevice_GetParent(wined3d_device
, (IUnknown
**)ppDevice
);
81 IWineD3DDevice_Release(wined3d_device
);
83 LeaveCriticalSection(&d3d9_cs
);
87 static HRESULT WINAPI
IDirect3DStateBlock9Impl_Capture(LPDIRECT3DSTATEBLOCK9 iface
) {
88 IDirect3DStateBlock9Impl
*This
= (IDirect3DStateBlock9Impl
*)iface
;
90 TRACE("(%p) Relay\n", This
);
92 EnterCriticalSection(&d3d9_cs
);
93 hr
= IWineD3DStateBlock_Capture(This
->wineD3DStateBlock
);
94 LeaveCriticalSection(&d3d9_cs
);
98 static HRESULT WINAPI
IDirect3DStateBlock9Impl_Apply(LPDIRECT3DSTATEBLOCK9 iface
) {
99 IDirect3DStateBlock9Impl
*This
= (IDirect3DStateBlock9Impl
*)iface
;
101 TRACE("(%p) Relay\n", This
);
103 EnterCriticalSection(&d3d9_cs
);
104 hr
= IWineD3DStateBlock_Apply(This
->wineD3DStateBlock
);
105 LeaveCriticalSection(&d3d9_cs
);
110 static const IDirect3DStateBlock9Vtbl Direct3DStateBlock9_Vtbl
=
113 IDirect3DStateBlock9Impl_QueryInterface
,
114 IDirect3DStateBlock9Impl_AddRef
,
115 IDirect3DStateBlock9Impl_Release
,
116 /* IDirect3DStateBlock9 */
117 IDirect3DStateBlock9Impl_GetDevice
,
118 IDirect3DStateBlock9Impl_Capture
,
119 IDirect3DStateBlock9Impl_Apply
123 /* IDirect3DDevice9 IDirect3DStateBlock9 Methods follow: */
124 HRESULT WINAPI
IDirect3DDevice9Impl_CreateStateBlock(LPDIRECT3DDEVICE9EX iface
, D3DSTATEBLOCKTYPE Type
, IDirect3DStateBlock9
** ppStateBlock
) {
125 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
126 IDirect3DStateBlock9Impl
* object
;
127 HRESULT hrc
= D3D_OK
;
129 TRACE("(%p) Relay\n", This
);
131 if(Type
!= D3DSBT_ALL
&& Type
!= D3DSBT_PIXELSTATE
&&
132 Type
!= D3DSBT_VERTEXSTATE
) {
133 WARN("Unexpected stateblock type, returning D3DERR_INVALIDCALL\n");
134 return D3DERR_INVALIDCALL
;
137 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirect3DStateBlock9Impl
));
138 if (NULL
== object
) return E_OUTOFMEMORY
;
139 object
->lpVtbl
= &Direct3DStateBlock9_Vtbl
;
142 EnterCriticalSection(&d3d9_cs
);
143 hrc
= IWineD3DDevice_CreateStateBlock(This
->WineD3DDevice
, (WINED3DSTATEBLOCKTYPE
)Type
, &object
->wineD3DStateBlock
, (IUnknown
*)object
);
144 LeaveCriticalSection(&d3d9_cs
);
146 FIXME("(%p) Call to IWineD3DDevice_CreateStateBlock failed.\n", This
);
147 HeapFree(GetProcessHeap(), 0, object
);
149 IDirect3DDevice9Ex_AddRef(iface
);
150 object
->parentDevice
= iface
;
151 *ppStateBlock
= (IDirect3DStateBlock9
*)object
;
152 TRACE("(%p) : Created stateblock %p\n", This
, object
);
154 TRACE("(%p) returning token (ptr to stateblock) of %p\n", This
, object
);
158 HRESULT WINAPI
IDirect3DDevice9Impl_BeginStateBlock(LPDIRECT3DDEVICE9EX iface
) {
159 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
161 TRACE("(%p) Relay\n", This
);
163 EnterCriticalSection(&d3d9_cs
);
164 hr
= IWineD3DDevice_BeginStateBlock(This
->WineD3DDevice
);
165 LeaveCriticalSection(&d3d9_cs
);
169 HRESULT WINAPI
IDirect3DDevice9Impl_EndStateBlock(LPDIRECT3DDEVICE9EX iface
, IDirect3DStateBlock9
** ppSB
) {
170 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
172 IWineD3DStateBlock
* wineD3DStateBlock
;
173 IDirect3DStateBlock9Impl
* object
;
175 TRACE("(%p) Relay\n", This
);
177 /* Tell wineD3D to endstateblock before anything else (in case we run out
178 * of memory later and cause locking problems)
180 EnterCriticalSection(&d3d9_cs
);
181 hr
=IWineD3DDevice_EndStateBlock(This
->WineD3DDevice
,&wineD3DStateBlock
);
182 LeaveCriticalSection(&d3d9_cs
);
184 WARN("IWineD3DDevice_EndStateBlock returned an error\n");
187 /* allocate a new IDirectD3DStateBlock */
188 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,sizeof(IDirect3DStateBlock9Impl
));
189 if (!object
) return E_OUTOFMEMORY
;
191 object
->lpVtbl
= &Direct3DStateBlock9_Vtbl
;
192 object
->wineD3DStateBlock
= wineD3DStateBlock
;
194 IDirect3DDevice9Ex_AddRef(iface
);
195 object
->parentDevice
= iface
;
196 *ppSB
=(IDirect3DStateBlock9
*)object
;
197 TRACE("(%p) Returning *ppSB %p, wineD3DStateBlock %p\n", This
, *ppSB
, wineD3DStateBlock
);