Sync ddraw, d3d8 and d3d9 + wined3d to wine 1.1.28
[reactos.git] / reactos / dll / directx / wine / d3d9 / volume.c
1 /*
2 * IDirect3DVolume9 implementation
3 *
4 * Copyright 2002-2005 Jason Edmeades
5 * Raphael Junqueira
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 */
21
22 #include "config.h"
23 #include "d3d9_private.h"
24
25 WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
26
27 /* IDirect3DVolume9 IUnknown parts follow: */
28 static HRESULT WINAPI IDirect3DVolume9Impl_QueryInterface(LPDIRECT3DVOLUME9 iface, REFIID riid, LPVOID* ppobj) {
29 IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
30
31 if (IsEqualGUID(riid, &IID_IUnknown)
32 || IsEqualGUID(riid, &IID_IDirect3DVolume9)) {
33 IDirect3DVolume9_AddRef(iface);
34 *ppobj = This;
35 return S_OK;
36 }
37
38 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
39 *ppobj = NULL;
40 return E_NOINTERFACE;
41 }
42
43 static ULONG WINAPI IDirect3DVolume9Impl_AddRef(LPDIRECT3DVOLUME9 iface) {
44 IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
45
46 TRACE("(%p)\n", This);
47
48 if (This->forwardReference) {
49 /* Forward refcounting */
50 TRACE("(%p) : Forwarding to %p\n", This, This->forwardReference);
51 return IUnknown_AddRef(This->forwardReference);
52 } else {
53 /* No container, handle our own refcounting */
54 ULONG ref = InterlockedIncrement(&This->ref);
55 TRACE("(%p) : AddRef from %d\n", This, ref - 1);
56 return ref;
57 }
58 }
59
60 static ULONG WINAPI IDirect3DVolume9Impl_Release(LPDIRECT3DVOLUME9 iface) {
61 IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
62
63 TRACE("(%p)\n", This);
64
65 if (This->forwardReference) {
66 /* Forward refcounting */
67 TRACE("(%p) : Forwarding to %p\n", This, This->forwardReference);
68 return IUnknown_Release(This->forwardReference);
69 } else {
70 /* No container, handle our own refcounting */
71 ULONG ref = InterlockedDecrement(&This->ref);
72 TRACE("(%p) : ReleaseRef to %d\n", This, ref);
73
74 if (ref == 0) {
75 wined3d_mutex_lock();
76 IWineD3DVolume_Release(This->wineD3DVolume);
77 wined3d_mutex_unlock();
78
79 HeapFree(GetProcessHeap(), 0, This);
80 }
81
82 return ref;
83 }
84 }
85
86 /* IDirect3DVolume9 Interface follow: */
87 static HRESULT WINAPI IDirect3DVolume9Impl_GetDevice(LPDIRECT3DVOLUME9 iface, IDirect3DDevice9** ppDevice) {
88 IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
89 IWineD3DDevice *myDevice = NULL;
90
91 TRACE("iface %p, ppDevice %p\n", iface, ppDevice);
92
93 wined3d_mutex_lock();
94
95 IWineD3DVolume_GetDevice(This->wineD3DVolume, &myDevice);
96 IWineD3DDevice_GetParent(myDevice, (IUnknown **)ppDevice);
97 IWineD3DDevice_Release(myDevice);
98
99 wined3d_mutex_unlock();
100
101 return D3D_OK;
102 }
103
104 static HRESULT WINAPI IDirect3DVolume9Impl_SetPrivateData(LPDIRECT3DVOLUME9 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
105 IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
106 HRESULT hr;
107
108 TRACE("(%p) Relay\n", This);
109
110 wined3d_mutex_lock();
111
112 hr = IWineD3DVolume_SetPrivateData(This->wineD3DVolume, refguid, pData, SizeOfData, Flags);
113
114 wined3d_mutex_unlock();
115
116 return hr;
117 }
118
119 static HRESULT WINAPI IDirect3DVolume9Impl_GetPrivateData(LPDIRECT3DVOLUME9 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
120 IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
121 HRESULT hr;
122
123 TRACE("(%p) Relay\n", This);
124
125 wined3d_mutex_lock();
126
127 hr = IWineD3DVolume_GetPrivateData(This->wineD3DVolume, refguid, pData, pSizeOfData);
128
129 wined3d_mutex_unlock();
130
131 return hr;
132 }
133
134 static HRESULT WINAPI IDirect3DVolume9Impl_FreePrivateData(LPDIRECT3DVOLUME9 iface, REFGUID refguid) {
135 IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
136 HRESULT hr;
137
138 TRACE("(%p) Relay\n", This);
139
140 wined3d_mutex_lock();
141
142 hr = IWineD3DVolume_FreePrivateData(This->wineD3DVolume, refguid);
143
144 wined3d_mutex_unlock();
145
146 return hr;
147 }
148
149 static HRESULT WINAPI IDirect3DVolume9Impl_GetContainer(LPDIRECT3DVOLUME9 iface, REFIID riid, void** ppContainer) {
150 IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
151 HRESULT res;
152
153 TRACE("(This %p, riid %s, ppContainer %p)\n", This, debugstr_guid(riid), ppContainer);
154
155 if (!This->container) return E_NOINTERFACE;
156
157 if (!ppContainer) {
158 ERR("Called without a valid ppContainer.\n");
159 }
160
161 res = IUnknown_QueryInterface(This->container, riid, ppContainer);
162
163 TRACE("Returning ppContainer %p, *ppContainer %p\n", ppContainer, *ppContainer);
164
165 return res;
166 }
167
168 static HRESULT WINAPI IDirect3DVolume9Impl_GetDesc(LPDIRECT3DVOLUME9 iface, D3DVOLUME_DESC* pDesc) {
169 IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
170 WINED3DVOLUME_DESC wined3ddesc;
171 HRESULT hr;
172
173 TRACE("(%p) Relay\n", This);
174
175 wined3d_mutex_lock();
176
177 hr = IWineD3DVolume_GetDesc(This->wineD3DVolume, &wined3ddesc);
178
179 wined3d_mutex_unlock();
180
181 if (SUCCEEDED(hr))
182 {
183 pDesc->Format = d3dformat_from_wined3dformat(wined3ddesc.Format);
184 pDesc->Type = wined3ddesc.Type;
185 pDesc->Usage = wined3ddesc.Usage;
186 pDesc->Pool = wined3ddesc.Pool;
187 pDesc->Width = wined3ddesc.Width;
188 pDesc->Height = wined3ddesc.Height;
189 pDesc->Depth = wined3ddesc.Depth;
190 }
191
192 return hr;
193 }
194
195 static HRESULT WINAPI IDirect3DVolume9Impl_LockBox(LPDIRECT3DVOLUME9 iface, D3DLOCKED_BOX* pLockedVolume, CONST D3DBOX* pBox, DWORD Flags) {
196 IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
197 HRESULT hr;
198
199 TRACE("(%p) relay %p %p %p %d\n", This, This->wineD3DVolume, pLockedVolume, pBox, Flags);
200
201 wined3d_mutex_lock();
202
203 hr = IWineD3DVolume_LockBox(This->wineD3DVolume, (WINED3DLOCKED_BOX *)pLockedVolume,
204 (const WINED3DBOX *)pBox, Flags);
205
206 wined3d_mutex_unlock();
207
208 return hr;
209 }
210
211 static HRESULT WINAPI IDirect3DVolume9Impl_UnlockBox(LPDIRECT3DVOLUME9 iface) {
212 IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
213 HRESULT hr;
214
215 TRACE("(%p) relay %p\n", This, This->wineD3DVolume);
216
217 wined3d_mutex_lock();
218
219 hr = IWineD3DVolume_UnlockBox(This->wineD3DVolume);
220
221 wined3d_mutex_unlock();
222
223 return hr;
224 }
225
226 const IDirect3DVolume9Vtbl Direct3DVolume9_Vtbl =
227 {
228 /* IUnknown */
229 IDirect3DVolume9Impl_QueryInterface,
230 IDirect3DVolume9Impl_AddRef,
231 IDirect3DVolume9Impl_Release,
232 /* IDirect3DVolume9 */
233 IDirect3DVolume9Impl_GetDevice,
234 IDirect3DVolume9Impl_SetPrivateData,
235 IDirect3DVolume9Impl_GetPrivateData,
236 IDirect3DVolume9Impl_FreePrivateData,
237 IDirect3DVolume9Impl_GetContainer,
238 IDirect3DVolume9Impl_GetDesc,
239 IDirect3DVolume9Impl_LockBox,
240 IDirect3DVolume9Impl_UnlockBox
241 };
242
243 ULONG WINAPI D3D9CB_DestroyVolume(IWineD3DVolume *pVolume) {
244 IDirect3DVolume9Impl* volumeParent;
245
246 IWineD3DVolume_GetParent(pVolume, (IUnknown **) &volumeParent);
247 /* GetParent's AddRef was forwarded to an object in destruction.
248 * Releasing it here again would cause an endless recursion. */
249 volumeParent->forwardReference = NULL;
250 return IDirect3DVolume9_Release((IDirect3DVolume9*) volumeParent);
251 }