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 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), ppobj
);
34 if (IsEqualGUID(riid
, &IID_IUnknown
)
35 || IsEqualGUID(riid
, &IID_IDirect3DStateBlock9
)) {
36 IDirect3DStateBlock9_AddRef(iface
);
41 WARN("(%p)->(%s,%p),not found\n", This
, debugstr_guid(riid
), ppobj
);
46 static ULONG WINAPI
IDirect3DStateBlock9Impl_AddRef(LPDIRECT3DSTATEBLOCK9 iface
) {
47 IDirect3DStateBlock9Impl
*This
= (IDirect3DStateBlock9Impl
*)iface
;
48 ULONG ref
= InterlockedIncrement(&This
->ref
);
50 TRACE("%p increasing refcount to %u.\n", iface
, ref
);
55 static ULONG WINAPI
IDirect3DStateBlock9Impl_Release(LPDIRECT3DSTATEBLOCK9 iface
) {
56 IDirect3DStateBlock9Impl
*This
= (IDirect3DStateBlock9Impl
*)iface
;
57 ULONG ref
= InterlockedDecrement(&This
->ref
);
59 TRACE("%p decreasing refcount to %u.\n", iface
, ref
);
63 IWineD3DStateBlock_Release(This
->wineD3DStateBlock
);
64 wined3d_mutex_unlock();
66 IDirect3DDevice9Ex_Release(This
->parentDevice
);
67 HeapFree(GetProcessHeap(), 0, This
);
72 /* IDirect3DStateBlock9 Interface follow: */
73 static HRESULT WINAPI
IDirect3DStateBlock9Impl_GetDevice(IDirect3DStateBlock9
*iface
, IDirect3DDevice9
**device
)
75 IDirect3DStateBlock9Impl
*This
= (IDirect3DStateBlock9Impl
*)iface
;
77 TRACE("iface %p, device %p.\n", iface
, device
);
79 *device
= (IDirect3DDevice9
*)This
->parentDevice
;
80 IDirect3DDevice9_AddRef(*device
);
82 TRACE("Returning device %p.\n", *device
);
87 static HRESULT WINAPI
IDirect3DStateBlock9Impl_Capture(LPDIRECT3DSTATEBLOCK9 iface
) {
88 IDirect3DStateBlock9Impl
*This
= (IDirect3DStateBlock9Impl
*)iface
;
91 TRACE("iface %p.\n", iface
);
94 hr
= IWineD3DStateBlock_Capture(This
->wineD3DStateBlock
);
95 wined3d_mutex_unlock();
100 static HRESULT WINAPI
IDirect3DStateBlock9Impl_Apply(LPDIRECT3DSTATEBLOCK9 iface
) {
101 IDirect3DStateBlock9Impl
*This
= (IDirect3DStateBlock9Impl
*)iface
;
104 TRACE("iface %p.\n", iface
);
106 wined3d_mutex_lock();
107 hr
= IWineD3DStateBlock_Apply(This
->wineD3DStateBlock
);
108 wined3d_mutex_unlock();
114 static const IDirect3DStateBlock9Vtbl Direct3DStateBlock9_Vtbl
=
117 IDirect3DStateBlock9Impl_QueryInterface
,
118 IDirect3DStateBlock9Impl_AddRef
,
119 IDirect3DStateBlock9Impl_Release
,
120 /* IDirect3DStateBlock9 */
121 IDirect3DStateBlock9Impl_GetDevice
,
122 IDirect3DStateBlock9Impl_Capture
,
123 IDirect3DStateBlock9Impl_Apply
126 HRESULT
stateblock_init(IDirect3DStateBlock9Impl
*stateblock
, IDirect3DDevice9Impl
*device
,
127 D3DSTATEBLOCKTYPE type
, IWineD3DStateBlock
*wined3d_stateblock
)
131 stateblock
->lpVtbl
= &Direct3DStateBlock9_Vtbl
;
134 if (wined3d_stateblock
)
136 stateblock
->wineD3DStateBlock
= wined3d_stateblock
;
140 wined3d_mutex_lock();
141 hr
= IWineD3DDevice_CreateStateBlock(device
->WineD3DDevice
, (WINED3DSTATEBLOCKTYPE
)type
,
142 &stateblock
->wineD3DStateBlock
, (IUnknown
*)stateblock
);
143 wined3d_mutex_unlock();
146 WARN("Failed to create wined3d stateblock, hr %#x.\n", hr
);
151 stateblock
->parentDevice
= (IDirect3DDevice9Ex
*)device
;
152 IDirect3DDevice9Ex_AddRef(stateblock
->parentDevice
);