1 | /*
|
---|
2 | * IDirect3DStateBlock9 implementation
|
---|
3 | *
|
---|
4 | * Copyright 2002-2003 Raphael Junqueira
|
---|
5 | * Copyright 2002-2003 Jason Edmeades
|
---|
6 | * Copyright 2005 Oliver Stieber
|
---|
7 | *
|
---|
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.
|
---|
12 | *
|
---|
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.
|
---|
17 | *
|
---|
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
|
---|
21 | */
|
---|
22 |
|
---|
23 | /*
|
---|
24 | * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
|
---|
25 | * other than GPL or LGPL is available it will apply instead, Sun elects to use only
|
---|
26 | * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
|
---|
27 | * a choice of LGPL license versions is made available with the language indicating
|
---|
28 | * that LGPLv2 or any later version may be used, or where a choice of which version
|
---|
29 | * of the LGPL is applied is otherwise unspecified.
|
---|
30 | */
|
---|
31 |
|
---|
32 | #include "config.h"
|
---|
33 | #include "d3d9_private.h"
|
---|
34 |
|
---|
35 | WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
|
---|
36 |
|
---|
37 | /* IDirect3DStateBlock9 IUnknown parts follow: */
|
---|
38 | static HRESULT WINAPI IDirect3DStateBlock9Impl_QueryInterface(LPDIRECT3DSTATEBLOCK9 iface, REFIID riid, LPVOID* ppobj) {
|
---|
39 | IDirect3DStateBlock9Impl *This = (IDirect3DStateBlock9Impl *)iface;
|
---|
40 |
|
---|
41 | TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
|
---|
42 |
|
---|
43 | if (IsEqualGUID(riid, &IID_IUnknown)
|
---|
44 | || IsEqualGUID(riid, &IID_IDirect3DStateBlock9)) {
|
---|
45 | IDirect3DStateBlock9_AddRef(iface);
|
---|
46 | *ppobj = This;
|
---|
47 | return S_OK;
|
---|
48 | }
|
---|
49 |
|
---|
50 | WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
|
---|
51 | *ppobj = NULL;
|
---|
52 | return E_NOINTERFACE;
|
---|
53 | }
|
---|
54 |
|
---|
55 | static ULONG WINAPI IDirect3DStateBlock9Impl_AddRef(LPDIRECT3DSTATEBLOCK9 iface) {
|
---|
56 | IDirect3DStateBlock9Impl *This = (IDirect3DStateBlock9Impl *)iface;
|
---|
57 | ULONG ref = InterlockedIncrement(&This->ref);
|
---|
58 |
|
---|
59 | TRACE("%p increasing refcount to %u.\n", iface, ref);
|
---|
60 |
|
---|
61 | return ref;
|
---|
62 | }
|
---|
63 |
|
---|
64 | static ULONG WINAPI IDirect3DStateBlock9Impl_Release(LPDIRECT3DSTATEBLOCK9 iface) {
|
---|
65 | IDirect3DStateBlock9Impl *This = (IDirect3DStateBlock9Impl *)iface;
|
---|
66 | ULONG ref = InterlockedDecrement(&This->ref);
|
---|
67 |
|
---|
68 | TRACE("%p decreasing refcount to %u.\n", iface, ref);
|
---|
69 |
|
---|
70 | if (ref == 0) {
|
---|
71 | wined3d_mutex_lock();
|
---|
72 | IWineD3DStateBlock_Release(This->wineD3DStateBlock);
|
---|
73 | wined3d_mutex_unlock();
|
---|
74 |
|
---|
75 | IDirect3DDevice9Ex_Release(This->parentDevice);
|
---|
76 | HeapFree(GetProcessHeap(), 0, This);
|
---|
77 | }
|
---|
78 | return ref;
|
---|
79 | }
|
---|
80 |
|
---|
81 | /* IDirect3DStateBlock9 Interface follow: */
|
---|
82 | static HRESULT WINAPI IDirect3DStateBlock9Impl_GetDevice(IDirect3DStateBlock9 *iface, IDirect3DDevice9 **device)
|
---|
83 | {
|
---|
84 | IDirect3DStateBlock9Impl *This = (IDirect3DStateBlock9Impl *)iface;
|
---|
85 |
|
---|
86 | TRACE("iface %p, device %p.\n", iface, device);
|
---|
87 |
|
---|
88 | *device = (IDirect3DDevice9 *)This->parentDevice;
|
---|
89 | IDirect3DDevice9_AddRef(*device);
|
---|
90 |
|
---|
91 | TRACE("Returning device %p.\n", *device);
|
---|
92 |
|
---|
93 | return D3D_OK;
|
---|
94 | }
|
---|
95 |
|
---|
96 | static HRESULT WINAPI IDirect3DStateBlock9Impl_Capture(LPDIRECT3DSTATEBLOCK9 iface) {
|
---|
97 | IDirect3DStateBlock9Impl *This = (IDirect3DStateBlock9Impl *)iface;
|
---|
98 | HRESULT hr;
|
---|
99 |
|
---|
100 | TRACE("iface %p.\n", iface);
|
---|
101 |
|
---|
102 | wined3d_mutex_lock();
|
---|
103 | hr = IWineD3DStateBlock_Capture(This->wineD3DStateBlock);
|
---|
104 | wined3d_mutex_unlock();
|
---|
105 |
|
---|
106 | return hr;
|
---|
107 | }
|
---|
108 |
|
---|
109 | static HRESULT WINAPI IDirect3DStateBlock9Impl_Apply(LPDIRECT3DSTATEBLOCK9 iface) {
|
---|
110 | IDirect3DStateBlock9Impl *This = (IDirect3DStateBlock9Impl *)iface;
|
---|
111 | HRESULT hr;
|
---|
112 |
|
---|
113 | TRACE("iface %p.\n", iface);
|
---|
114 |
|
---|
115 | wined3d_mutex_lock();
|
---|
116 | hr = IWineD3DStateBlock_Apply(This->wineD3DStateBlock);
|
---|
117 | wined3d_mutex_unlock();
|
---|
118 |
|
---|
119 | return hr;
|
---|
120 | }
|
---|
121 |
|
---|
122 |
|
---|
123 | static const IDirect3DStateBlock9Vtbl Direct3DStateBlock9_Vtbl =
|
---|
124 | {
|
---|
125 | /* IUnknown */
|
---|
126 | IDirect3DStateBlock9Impl_QueryInterface,
|
---|
127 | IDirect3DStateBlock9Impl_AddRef,
|
---|
128 | IDirect3DStateBlock9Impl_Release,
|
---|
129 | /* IDirect3DStateBlock9 */
|
---|
130 | IDirect3DStateBlock9Impl_GetDevice,
|
---|
131 | IDirect3DStateBlock9Impl_Capture,
|
---|
132 | IDirect3DStateBlock9Impl_Apply
|
---|
133 | };
|
---|
134 |
|
---|
135 | HRESULT stateblock_init(IDirect3DStateBlock9Impl *stateblock, IDirect3DDevice9Impl *device,
|
---|
136 | D3DSTATEBLOCKTYPE type, IWineD3DStateBlock *wined3d_stateblock)
|
---|
137 | {
|
---|
138 | HRESULT hr;
|
---|
139 |
|
---|
140 | stateblock->lpVtbl = &Direct3DStateBlock9_Vtbl;
|
---|
141 | stateblock->ref = 1;
|
---|
142 |
|
---|
143 | if (wined3d_stateblock)
|
---|
144 | {
|
---|
145 | stateblock->wineD3DStateBlock = wined3d_stateblock;
|
---|
146 | }
|
---|
147 | else
|
---|
148 | {
|
---|
149 | wined3d_mutex_lock();
|
---|
150 | hr = IWineD3DDevice_CreateStateBlock(device->WineD3DDevice, (WINED3DSTATEBLOCKTYPE)type,
|
---|
151 | &stateblock->wineD3DStateBlock, (IUnknown *)stateblock);
|
---|
152 | wined3d_mutex_unlock();
|
---|
153 | if (FAILED(hr))
|
---|
154 | {
|
---|
155 | WARN("Failed to create wined3d stateblock, hr %#x.\n", hr);
|
---|
156 | return hr;
|
---|
157 | }
|
---|
158 | }
|
---|
159 |
|
---|
160 | stateblock->parentDevice = (IDirect3DDevice9Ex *)device;
|
---|
161 | IDirect3DDevice9Ex_AddRef(stateblock->parentDevice);
|
---|
162 |
|
---|
163 | return D3D_OK;
|
---|
164 | }
|
---|