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 static inline IDirect3DStateBlock9Impl *impl_from_IDirect3DStateBlock9(IDirect3DStateBlock9 *iface)
30 return CONTAINING_RECORD(iface, IDirect3DStateBlock9Impl, IDirect3DStateBlock9_iface);
33 static HRESULT WINAPI IDirect3DStateBlock9Impl_QueryInterface(IDirect3DStateBlock9 *iface,
34 REFIID riid, void **ppobj)
36 IDirect3DStateBlock9Impl *This = impl_from_IDirect3DStateBlock9(iface);
38 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
40 if (IsEqualGUID(riid, &IID_IUnknown)
41 || IsEqualGUID(riid, &IID_IDirect3DStateBlock9)) {
42 IDirect3DStateBlock9_AddRef(iface);
47 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
52 static ULONG WINAPI IDirect3DStateBlock9Impl_AddRef(IDirect3DStateBlock9 *iface)
54 IDirect3DStateBlock9Impl *This = impl_from_IDirect3DStateBlock9(iface);
55 ULONG ref = InterlockedIncrement(&This->ref);
57 TRACE("%p increasing refcount to %u.\n", iface, ref);
62 static ULONG WINAPI IDirect3DStateBlock9Impl_Release(IDirect3DStateBlock9 *iface)
64 IDirect3DStateBlock9Impl *This = impl_from_IDirect3DStateBlock9(iface);
65 ULONG ref = InterlockedDecrement(&This->ref);
67 TRACE("%p decreasing refcount to %u.\n", iface, ref);
71 wined3d_stateblock_decref(This->wined3d_stateblock);
72 wined3d_mutex_unlock();
74 IDirect3DDevice9Ex_Release(This->parentDevice);
75 HeapFree(GetProcessHeap(), 0, This);
80 /* IDirect3DStateBlock9 Interface follow: */
81 static HRESULT WINAPI IDirect3DStateBlock9Impl_GetDevice(IDirect3DStateBlock9 *iface,
82 IDirect3DDevice9 **device)
84 IDirect3DStateBlock9Impl *This = impl_from_IDirect3DStateBlock9(iface);
86 TRACE("iface %p, device %p.\n", iface, device);
88 *device = (IDirect3DDevice9 *)This->parentDevice;
89 IDirect3DDevice9_AddRef(*device);
91 TRACE("Returning device %p.\n", *device);
96 static HRESULT WINAPI IDirect3DStateBlock9Impl_Capture(IDirect3DStateBlock9 *iface)
98 IDirect3DStateBlock9Impl *This = impl_from_IDirect3DStateBlock9(iface);
101 TRACE("iface %p.\n", iface);
103 wined3d_mutex_lock();
104 hr = wined3d_stateblock_capture(This->wined3d_stateblock);
105 wined3d_mutex_unlock();
110 static HRESULT WINAPI IDirect3DStateBlock9Impl_Apply(IDirect3DStateBlock9 *iface)
112 IDirect3DStateBlock9Impl *This = impl_from_IDirect3DStateBlock9(iface);
115 TRACE("iface %p.\n", iface);
117 wined3d_mutex_lock();
118 hr = wined3d_stateblock_apply(This->wined3d_stateblock);
119 wined3d_mutex_unlock();
125 static const IDirect3DStateBlock9Vtbl Direct3DStateBlock9_Vtbl =
128 IDirect3DStateBlock9Impl_QueryInterface,
129 IDirect3DStateBlock9Impl_AddRef,
130 IDirect3DStateBlock9Impl_Release,
131 /* IDirect3DStateBlock9 */
132 IDirect3DStateBlock9Impl_GetDevice,
133 IDirect3DStateBlock9Impl_Capture,
134 IDirect3DStateBlock9Impl_Apply
137 HRESULT stateblock_init(IDirect3DStateBlock9Impl *stateblock, IDirect3DDevice9Impl *device,
138 D3DSTATEBLOCKTYPE type, struct wined3d_stateblock *wined3d_stateblock)
142 stateblock->IDirect3DStateBlock9_iface.lpVtbl = &Direct3DStateBlock9_Vtbl;
145 if (wined3d_stateblock)
147 stateblock->wined3d_stateblock = wined3d_stateblock;
151 wined3d_mutex_lock();
152 hr = wined3d_stateblock_create(device->wined3d_device,
153 (WINED3DSTATEBLOCKTYPE)type, &stateblock->wined3d_stateblock);
154 wined3d_mutex_unlock();
157 WARN("Failed to create wined3d stateblock, hr %#x.\n", hr);
162 stateblock->parentDevice = &device->IDirect3DDevice9Ex_iface;
163 IDirect3DDevice9Ex_AddRef(stateblock->parentDevice);