d3d8: Use a wined3d cs for wined3d locking.
[wine] / dlls / d3d8 / volumetexture.c
1 /*
2  * IDirect3DVolumeTexture8 implementation
3  *
4  * Copyright 2005 Oliver Stieber
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #include "config.h"
22 #include "d3d8_private.h"
23
24 WINE_DEFAULT_DEBUG_CHANNEL(d3d8);
25
26 /* IDirect3DVolumeTexture8 IUnknown parts follow: */
27 static HRESULT WINAPI IDirect3DVolumeTexture8Impl_QueryInterface(LPDIRECT3DVOLUMETEXTURE8 iface, REFIID riid, LPVOID *ppobj) {
28     IDirect3DVolumeTexture8Impl *This = (IDirect3DVolumeTexture8Impl *)iface;
29
30     if (IsEqualGUID(riid, &IID_IUnknown)
31     || IsEqualGUID(riid, &IID_IDirect3DResource8)
32     || IsEqualGUID(riid, &IID_IDirect3DBaseTexture8)
33     || IsEqualGUID(riid, &IID_IDirect3DVolumeTexture8)) {
34         IUnknown_AddRef(iface);
35         *ppobj = This;
36         return S_OK;
37     }
38
39     WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
40     *ppobj = NULL;
41     return E_NOINTERFACE;
42 }
43
44 static ULONG WINAPI IDirect3DVolumeTexture8Impl_AddRef(LPDIRECT3DVOLUMETEXTURE8 iface) {
45     IDirect3DVolumeTexture8Impl *This = (IDirect3DVolumeTexture8Impl *)iface;
46     ULONG ref = InterlockedIncrement(&This->ref);
47
48     TRACE("(%p) : AddRef from %d\n", This, ref - 1);
49
50     return ref;
51 }
52
53 static ULONG WINAPI IDirect3DVolumeTexture8Impl_Release(LPDIRECT3DVOLUMETEXTURE8 iface) {
54     IDirect3DVolumeTexture8Impl *This = (IDirect3DVolumeTexture8Impl *)iface;
55     ULONG ref = InterlockedDecrement(&This->ref);
56
57     TRACE("(%p) : ReleaseRef to %d\n", This, ref);
58
59     if (ref == 0) {
60         wined3d_mutex_lock();
61         IWineD3DVolumeTexture_Destroy(This->wineD3DVolumeTexture, D3D8CB_DestroyVolume);
62         wined3d_mutex_unlock();
63
64         IUnknown_Release(This->parentDevice);
65         HeapFree(GetProcessHeap(), 0, This);
66     }
67     return ref;
68 }
69
70 /* IDirect3DVolumeTexture8 IDirect3DResource8 Interface follow: */
71 static HRESULT WINAPI IDirect3DVolumeTexture8Impl_GetDevice(LPDIRECT3DVOLUMETEXTURE8 iface, IDirect3DDevice8 **ppDevice) {
72     IDirect3DVolumeTexture8Impl *This = (IDirect3DVolumeTexture8Impl *)iface;
73     IWineD3DDevice *wined3d_device;
74     HRESULT hr;
75     TRACE("(%p) Relay\n", This);
76
77     wined3d_mutex_lock();
78     hr = IWineD3DVolumeTexture_GetDevice(This->wineD3DVolumeTexture, &wined3d_device);
79     if (SUCCEEDED(hr))
80     {
81         IWineD3DDevice_GetParent(wined3d_device, (IUnknown **)ppDevice);
82         IWineD3DDevice_Release(wined3d_device);
83     }
84     wined3d_mutex_unlock();
85
86     return hr;
87 }
88
89 static HRESULT WINAPI IDirect3DVolumeTexture8Impl_SetPrivateData(LPDIRECT3DVOLUMETEXTURE8 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
90     IDirect3DVolumeTexture8Impl *This = (IDirect3DVolumeTexture8Impl *)iface;
91     HRESULT hr;
92     TRACE("(%p) Relay\n", This);
93
94     wined3d_mutex_lock();
95     hr = IWineD3DVolumeTexture_SetPrivateData(This->wineD3DVolumeTexture, refguid, pData, SizeOfData, Flags);
96     wined3d_mutex_unlock();
97
98     return hr;
99 }
100
101 static HRESULT WINAPI IDirect3DVolumeTexture8Impl_GetPrivateData(LPDIRECT3DVOLUMETEXTURE8 iface, REFGUID refguid, void *pData, DWORD *pSizeOfData) {
102     IDirect3DVolumeTexture8Impl *This = (IDirect3DVolumeTexture8Impl *)iface;
103     HRESULT hr;
104     TRACE("(%p) Relay\n", This);
105
106     wined3d_mutex_lock();
107     hr = IWineD3DVolumeTexture_GetPrivateData(This->wineD3DVolumeTexture, refguid, pData, pSizeOfData);
108     wined3d_mutex_unlock();
109
110     return hr;
111 }
112
113 static HRESULT WINAPI IDirect3DVolumeTexture8Impl_FreePrivateData(LPDIRECT3DVOLUMETEXTURE8 iface, REFGUID refguid) {
114     IDirect3DVolumeTexture8Impl *This = (IDirect3DVolumeTexture8Impl *)iface;
115     HRESULT hr;
116     TRACE("(%p) Relay\n", This);
117
118     wined3d_mutex_lock();
119     hr = IWineD3DVolumeTexture_FreePrivateData(This->wineD3DVolumeTexture, refguid);
120     wined3d_mutex_unlock();
121
122     return hr;
123 }
124
125 static DWORD WINAPI IDirect3DVolumeTexture8Impl_SetPriority(LPDIRECT3DVOLUMETEXTURE8 iface, DWORD PriorityNew) {
126     IDirect3DVolumeTexture8Impl *This = (IDirect3DVolumeTexture8Impl *)iface;
127     DWORD ret;
128     TRACE("(%p) Relay\n", This);
129
130     wined3d_mutex_lock();
131     ret = IWineD3DVolumeTexture_SetPriority(This->wineD3DVolumeTexture, PriorityNew);
132     wined3d_mutex_unlock();
133
134     return ret;
135 }
136
137 static DWORD WINAPI IDirect3DVolumeTexture8Impl_GetPriority(LPDIRECT3DVOLUMETEXTURE8 iface) {
138     IDirect3DVolumeTexture8Impl *This = (IDirect3DVolumeTexture8Impl *)iface;
139     DWORD ret;
140     TRACE("(%p) Relay\n", This);
141
142     wined3d_mutex_lock();
143     ret = IWineD3DVolumeTexture_GetPriority(This->wineD3DVolumeTexture);
144     wined3d_mutex_unlock();
145
146     return ret;
147 }
148
149 static void WINAPI IDirect3DVolumeTexture8Impl_PreLoad(LPDIRECT3DVOLUMETEXTURE8 iface) {
150     IDirect3DVolumeTexture8Impl *This = (IDirect3DVolumeTexture8Impl *)iface;
151     TRACE("(%p) Relay\n", This);
152
153     wined3d_mutex_lock();
154     IWineD3DVolumeTexture_PreLoad(This->wineD3DVolumeTexture);
155     wined3d_mutex_unlock();
156 }
157
158 static D3DRESOURCETYPE WINAPI IDirect3DVolumeTexture8Impl_GetType(LPDIRECT3DVOLUMETEXTURE8 iface) {
159     IDirect3DVolumeTexture8Impl *This = (IDirect3DVolumeTexture8Impl *)iface;
160     D3DRESOURCETYPE type;
161     TRACE("(%p) Relay\n", This);
162
163     wined3d_mutex_lock();
164     type = IWineD3DVolumeTexture_GetType(This->wineD3DVolumeTexture);
165     wined3d_mutex_unlock();
166
167     return type;
168 }
169
170 /* IDirect3DVolumeTexture8 IDirect3DBaseTexture8 Interface follow: */
171 static DWORD WINAPI IDirect3DVolumeTexture8Impl_SetLOD(LPDIRECT3DVOLUMETEXTURE8 iface, DWORD LODNew) {
172     IDirect3DVolumeTexture8Impl *This = (IDirect3DVolumeTexture8Impl *)iface;
173     DWORD ret;
174     TRACE("(%p) Relay\n", This);
175
176     wined3d_mutex_lock();
177     ret = IWineD3DVolumeTexture_SetLOD(This->wineD3DVolumeTexture, LODNew);
178     wined3d_mutex_unlock();
179
180     return ret;
181 }
182
183 static DWORD WINAPI IDirect3DVolumeTexture8Impl_GetLOD(LPDIRECT3DVOLUMETEXTURE8 iface) {
184     IDirect3DVolumeTexture8Impl *This = (IDirect3DVolumeTexture8Impl *)iface;
185     DWORD ret;
186     TRACE("(%p) Relay\n", This);
187
188     wined3d_mutex_lock();
189     ret = IWineD3DVolumeTexture_GetLOD(This->wineD3DVolumeTexture);
190     wined3d_mutex_unlock();
191
192     return ret;
193 }
194
195 static DWORD WINAPI IDirect3DVolumeTexture8Impl_GetLevelCount(LPDIRECT3DVOLUMETEXTURE8 iface) {
196     IDirect3DVolumeTexture8Impl *This = (IDirect3DVolumeTexture8Impl *)iface;
197     DWORD ret;
198     TRACE("(%p) Relay\n", This);
199
200     wined3d_mutex_lock();
201     ret = IWineD3DVolumeTexture_GetLevelCount(This->wineD3DVolumeTexture);
202     wined3d_mutex_unlock();
203
204     return ret;
205 }
206
207 /* IDirect3DVolumeTexture8 Interface follow: */
208 static HRESULT WINAPI IDirect3DVolumeTexture8Impl_GetLevelDesc(LPDIRECT3DVOLUMETEXTURE8 iface, UINT Level, D3DVOLUME_DESC* pDesc) {
209     IDirect3DVolumeTexture8Impl *This = (IDirect3DVolumeTexture8Impl *)iface;
210     WINED3DVOLUME_DESC     wined3ddesc;
211     HRESULT hr;
212
213     TRACE("(%p) Relay\n", This);
214
215     wined3d_mutex_lock();
216     hr = IWineD3DVolumeTexture_GetLevelDesc(This->wineD3DVolumeTexture, Level, &wined3ddesc);
217     wined3d_mutex_unlock();
218
219     if (SUCCEEDED(hr))
220     {
221         pDesc->Format = d3dformat_from_wined3dformat(wined3ddesc.Format);
222         pDesc->Type = wined3ddesc.Type;
223         pDesc->Usage = wined3ddesc.Usage;
224         pDesc->Pool = wined3ddesc.Pool;
225         pDesc->Size = wined3ddesc.Size;
226         pDesc->Width = wined3ddesc.Width;
227         pDesc->Height = wined3ddesc.Height;
228         pDesc->Depth = wined3ddesc.Depth;
229     }
230
231     return hr;
232 }
233
234 static HRESULT WINAPI IDirect3DVolumeTexture8Impl_GetVolumeLevel(LPDIRECT3DVOLUMETEXTURE8 iface, UINT Level, IDirect3DVolume8 **ppVolumeLevel) {
235     IDirect3DVolumeTexture8Impl *This = (IDirect3DVolumeTexture8Impl *)iface;
236     HRESULT hrc = D3D_OK;
237     IWineD3DVolume *myVolume = NULL;
238
239     TRACE("(%p) Relay\n", This);
240
241     wined3d_mutex_lock();
242     hrc = IWineD3DVolumeTexture_GetVolumeLevel(This->wineD3DVolumeTexture, Level, &myVolume);
243     if (hrc == D3D_OK && NULL != ppVolumeLevel) {
244        IWineD3DVolumeTexture_GetParent(myVolume, (IUnknown **)ppVolumeLevel);
245        IWineD3DVolumeTexture_Release(myVolume);
246     }
247     wined3d_mutex_unlock();
248
249     return hrc;
250 }
251
252 static HRESULT WINAPI IDirect3DVolumeTexture8Impl_LockBox(LPDIRECT3DVOLUMETEXTURE8 iface, UINT Level, D3DLOCKED_BOX *pLockedVolume, CONST D3DBOX *pBox, DWORD Flags) {
253     IDirect3DVolumeTexture8Impl *This = (IDirect3DVolumeTexture8Impl *)iface;
254     HRESULT hr;
255     TRACE("(%p) Relay %p %p %p %d\n", This, This->wineD3DVolumeTexture, pLockedVolume, pBox,Flags);
256
257     wined3d_mutex_lock();
258     hr = IWineD3DVolumeTexture_LockBox(This->wineD3DVolumeTexture, Level, (WINED3DLOCKED_BOX *) pLockedVolume, (CONST WINED3DBOX *) pBox, Flags);
259     wined3d_mutex_unlock();
260
261     return hr;
262 }
263
264 static HRESULT WINAPI IDirect3DVolumeTexture8Impl_UnlockBox(LPDIRECT3DVOLUMETEXTURE8 iface, UINT Level) {
265     IDirect3DVolumeTexture8Impl *This = (IDirect3DVolumeTexture8Impl *)iface;
266     HRESULT hr;
267     TRACE("(%p) Relay %p %d\n", This, This->wineD3DVolumeTexture, Level);
268
269     wined3d_mutex_lock();
270     hr = IWineD3DVolumeTexture_UnlockBox(This->wineD3DVolumeTexture, Level);
271     wined3d_mutex_unlock();
272
273     return hr;
274 }
275
276 static HRESULT WINAPI IDirect3DVolumeTexture8Impl_AddDirtyBox(LPDIRECT3DVOLUMETEXTURE8 iface, CONST D3DBOX *pDirtyBox) {
277     IDirect3DVolumeTexture8Impl *This = (IDirect3DVolumeTexture8Impl *)iface;
278     HRESULT hr;
279     TRACE("(%p) Relay\n", This);
280
281     wined3d_mutex_lock();
282     hr = IWineD3DVolumeTexture_AddDirtyBox(This->wineD3DVolumeTexture, (CONST WINED3DBOX *) pDirtyBox);
283     wined3d_mutex_unlock();
284
285     return hr;
286 }
287
288
289 const IDirect3DVolumeTexture8Vtbl Direct3DVolumeTexture8_Vtbl =
290 {
291     /* IUnknown */
292     IDirect3DVolumeTexture8Impl_QueryInterface,
293     IDirect3DVolumeTexture8Impl_AddRef,
294     IDirect3DVolumeTexture8Impl_Release,
295     /* IDirect3DResource8 */
296     IDirect3DVolumeTexture8Impl_GetDevice,
297     IDirect3DVolumeTexture8Impl_SetPrivateData,
298     IDirect3DVolumeTexture8Impl_GetPrivateData,
299     IDirect3DVolumeTexture8Impl_FreePrivateData,
300     IDirect3DVolumeTexture8Impl_SetPriority,
301     IDirect3DVolumeTexture8Impl_GetPriority,
302     IDirect3DVolumeTexture8Impl_PreLoad,
303     IDirect3DVolumeTexture8Impl_GetType,
304     /* IDirect3DBaseTexture8 */
305     IDirect3DVolumeTexture8Impl_SetLOD,
306     IDirect3DVolumeTexture8Impl_GetLOD,
307     IDirect3DVolumeTexture8Impl_GetLevelCount,
308     /* IDirect3DVolumeTexture8 */
309     IDirect3DVolumeTexture8Impl_GetLevelDesc,
310     IDirect3DVolumeTexture8Impl_GetVolumeLevel,
311     IDirect3DVolumeTexture8Impl_LockBox,
312     IDirect3DVolumeTexture8Impl_UnlockBox,
313     IDirect3DVolumeTexture8Impl_AddDirtyBox
314 };