comctl32/tests: Add hotspot/drag test for IImageList.
[wine] / dlls / d3d9 / volumetexture.c
1 /*
2  * IDirect3DVolumeTexture9 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 /* IDirect3DVolumeTexture9 IUnknown parts follow: */
28 static HRESULT WINAPI IDirect3DVolumeTexture9Impl_QueryInterface(LPDIRECT3DVOLUMETEXTURE9 iface, REFIID riid, LPVOID* ppobj) {
29     IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
30
31     TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
32
33     if (IsEqualGUID(riid, &IID_IUnknown)
34     || IsEqualGUID(riid, &IID_IDirect3DResource9)
35     || IsEqualGUID(riid, &IID_IDirect3DBaseTexture9)
36     || IsEqualGUID(riid, &IID_IDirect3DVolumeTexture9)) {
37         IDirect3DVolumeTexture9_AddRef(iface);
38         *ppobj = This;
39         return S_OK;
40     }
41
42     WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
43     *ppobj = NULL;
44     return E_NOINTERFACE;
45 }
46
47 static ULONG WINAPI IDirect3DVolumeTexture9Impl_AddRef(LPDIRECT3DVOLUMETEXTURE9 iface) {
48     IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
49     ULONG ref = InterlockedIncrement(&This->ref);
50
51     TRACE("%p increasing refcount to %u.\n", iface, ref);
52
53     if (ref == 1)
54     {
55         IDirect3DDevice9Ex_AddRef(This->parentDevice);
56         wined3d_mutex_lock();
57         IWineD3DVolumeTexture_AddRef(This->wineD3DVolumeTexture);
58         wined3d_mutex_unlock();
59     }
60
61     return ref;
62 }
63
64 static ULONG WINAPI IDirect3DVolumeTexture9Impl_Release(LPDIRECT3DVOLUMETEXTURE9 iface) {
65     IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
66     ULONG ref = InterlockedDecrement(&This->ref);
67
68     TRACE("%p decreasing refcount to %u.\n", iface, ref);
69
70     if (ref == 0) {
71         IDirect3DDevice9Ex *parentDevice = This->parentDevice;
72
73         wined3d_mutex_lock();
74         IWineD3DVolumeTexture_Release(This->wineD3DVolumeTexture);
75         wined3d_mutex_unlock();
76
77         /* Release the device last, as it may cause the device to be destroyed. */
78         IDirect3DDevice9Ex_Release(parentDevice);
79     }
80     return ref;
81 }
82
83 /* IDirect3DVolumeTexture9 IDirect3DResource9 Interface follow: */
84 static HRESULT WINAPI IDirect3DVolumeTexture9Impl_GetDevice(LPDIRECT3DVOLUMETEXTURE9 iface, IDirect3DDevice9** ppDevice) {
85     IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
86     IWineD3DDevice *wined3d_device;
87     HRESULT hr;
88
89     TRACE("iface %p, device %p.\n", iface, ppDevice);
90
91     wined3d_mutex_lock();
92     hr = IWineD3DStateBlock_GetDevice(This->wineD3DVolumeTexture, &wined3d_device);
93     if (SUCCEEDED(hr))
94     {
95         IWineD3DDevice_GetParent(wined3d_device, (IUnknown **)ppDevice);
96         IWineD3DDevice_Release(wined3d_device);
97     }
98     wined3d_mutex_unlock();
99
100     return hr;
101 }
102
103 static HRESULT WINAPI IDirect3DVolumeTexture9Impl_SetPrivateData(LPDIRECT3DVOLUMETEXTURE9 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
104     IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
105     HRESULT hr;
106
107     TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
108             iface, debugstr_guid(refguid), pData, SizeOfData, Flags);
109
110     wined3d_mutex_lock();
111
112     hr = IWineD3DVolumeTexture_SetPrivateData(This->wineD3DVolumeTexture, refguid, pData, SizeOfData, Flags);
113
114     wined3d_mutex_unlock();
115
116     return hr;
117 }
118
119 static HRESULT WINAPI IDirect3DVolumeTexture9Impl_GetPrivateData(LPDIRECT3DVOLUMETEXTURE9 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
120     IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
121     HRESULT hr;
122
123     TRACE("iface %p, guid %s, data %p, data_size %p.\n",
124             iface, debugstr_guid(refguid), pData, pSizeOfData);
125
126     wined3d_mutex_lock();
127
128     hr = IWineD3DVolumeTexture_GetPrivateData(This->wineD3DVolumeTexture, refguid, pData, pSizeOfData);
129
130     wined3d_mutex_unlock();
131
132     return hr;
133 }
134
135 static HRESULT WINAPI IDirect3DVolumeTexture9Impl_FreePrivateData(LPDIRECT3DVOLUMETEXTURE9 iface, REFGUID refguid) {
136     IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
137     HRESULT hr;
138
139     TRACE("iface %p, guid %s.\n", iface, debugstr_guid(refguid));
140
141     wined3d_mutex_lock();
142
143     hr = IWineD3DVolumeTexture_FreePrivateData(This->wineD3DVolumeTexture, refguid);
144
145     wined3d_mutex_unlock();
146
147     return hr;
148 }
149
150 static DWORD WINAPI IDirect3DVolumeTexture9Impl_SetPriority(LPDIRECT3DVOLUMETEXTURE9 iface, DWORD PriorityNew) {
151     IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
152     DWORD priority;
153
154     TRACE("iface %p, priority %u.\n", iface, PriorityNew);
155
156     wined3d_mutex_lock();
157
158     priority = IWineD3DVolumeTexture_SetPriority(This->wineD3DVolumeTexture, PriorityNew);
159
160     wined3d_mutex_unlock();
161
162     return priority;
163 }
164
165 static DWORD WINAPI IDirect3DVolumeTexture9Impl_GetPriority(LPDIRECT3DVOLUMETEXTURE9 iface) {
166     IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
167     DWORD priority;
168
169     TRACE("iface %p.\n", iface);
170
171     wined3d_mutex_lock();
172
173     priority = IWineD3DVolumeTexture_GetPriority(This->wineD3DVolumeTexture);
174
175     wined3d_mutex_unlock();
176
177     return priority;
178 }
179
180 static void WINAPI IDirect3DVolumeTexture9Impl_PreLoad(LPDIRECT3DVOLUMETEXTURE9 iface) {
181     IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
182
183     TRACE("iface %p.\n", iface);
184
185     wined3d_mutex_lock();
186
187     IWineD3DVolumeTexture_PreLoad(This->wineD3DVolumeTexture);
188
189     wined3d_mutex_unlock();
190 }
191
192 static D3DRESOURCETYPE WINAPI IDirect3DVolumeTexture9Impl_GetType(LPDIRECT3DVOLUMETEXTURE9 iface) {
193     IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
194     D3DRESOURCETYPE type;
195
196     TRACE("iface %p.\n", iface);
197
198     wined3d_mutex_lock();
199
200     type = IWineD3DVolumeTexture_GetType(This->wineD3DVolumeTexture);
201
202     wined3d_mutex_unlock();
203
204     return type;
205 }
206
207 /* IDirect3DVolumeTexture9 IDirect3DBaseTexture9 Interface follow: */
208 static DWORD WINAPI IDirect3DVolumeTexture9Impl_SetLOD(LPDIRECT3DVOLUMETEXTURE9 iface, DWORD LODNew) {
209     IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
210     DWORD lod;
211
212     TRACE("iface %p, lod %u.\n", iface, LODNew);
213
214     wined3d_mutex_lock();
215
216     lod = IWineD3DVolumeTexture_SetLOD(This->wineD3DVolumeTexture, LODNew);
217
218     wined3d_mutex_unlock();
219
220     return lod;
221 }
222
223 static DWORD WINAPI IDirect3DVolumeTexture9Impl_GetLOD(LPDIRECT3DVOLUMETEXTURE9 iface) {
224     IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
225     DWORD lod;
226
227     TRACE("iface %p.\n", iface);
228
229     wined3d_mutex_lock();
230
231     lod = IWineD3DVolumeTexture_GetLOD(This->wineD3DVolumeTexture);
232
233     wined3d_mutex_unlock();
234
235     return lod;
236 }
237
238 static DWORD WINAPI IDirect3DVolumeTexture9Impl_GetLevelCount(LPDIRECT3DVOLUMETEXTURE9 iface) {
239     IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
240     DWORD level_count;
241
242     TRACE("iface %p.\n", iface);
243
244     wined3d_mutex_lock();
245
246     level_count = IWineD3DVolumeTexture_GetLevelCount(This->wineD3DVolumeTexture);
247
248     wined3d_mutex_unlock();
249
250     return level_count;
251 }
252
253 static HRESULT WINAPI IDirect3DVolumeTexture9Impl_SetAutoGenFilterType(LPDIRECT3DVOLUMETEXTURE9 iface, D3DTEXTUREFILTERTYPE FilterType) {
254     IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
255     HRESULT hr;
256
257     TRACE("iface %p, filter_type %#x.\n", iface, FilterType);
258
259     wined3d_mutex_lock();
260
261     hr = IWineD3DVolumeTexture_SetAutoGenFilterType(This->wineD3DVolumeTexture, (WINED3DTEXTUREFILTERTYPE) FilterType);
262
263     wined3d_mutex_unlock();
264
265     return hr;
266 }
267
268 static D3DTEXTUREFILTERTYPE WINAPI IDirect3DVolumeTexture9Impl_GetAutoGenFilterType(LPDIRECT3DVOLUMETEXTURE9 iface) {
269     IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
270     D3DTEXTUREFILTERTYPE filter_type;
271
272     TRACE("iface %p.\n", iface);
273
274     wined3d_mutex_lock();
275
276     filter_type = (D3DTEXTUREFILTERTYPE)IWineD3DVolumeTexture_GetAutoGenFilterType(This->wineD3DVolumeTexture);
277
278     wined3d_mutex_unlock();
279
280     return filter_type;
281 }
282
283 static void WINAPI IDirect3DVolumeTexture9Impl_GenerateMipSubLevels(LPDIRECT3DVOLUMETEXTURE9 iface) {
284     IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
285
286     TRACE("iface %p.\n", iface);
287
288     wined3d_mutex_lock();
289
290     IWineD3DVolumeTexture_GenerateMipSubLevels(This->wineD3DVolumeTexture);
291
292     wined3d_mutex_unlock();
293 }
294
295 /* IDirect3DVolumeTexture9 Interface follow: */
296 static HRESULT WINAPI IDirect3DVolumeTexture9Impl_GetLevelDesc(LPDIRECT3DVOLUMETEXTURE9 iface, UINT Level, D3DVOLUME_DESC* pDesc) {
297     IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
298     WINED3DVOLUME_DESC     wined3ddesc;
299     HRESULT hr;
300
301     TRACE("iface %p, level %u, desc %p.\n", iface, Level, pDesc);
302
303     wined3d_mutex_lock();
304
305     hr = IWineD3DVolumeTexture_GetLevelDesc(This->wineD3DVolumeTexture, Level, &wined3ddesc);
306
307     wined3d_mutex_unlock();
308
309     if (SUCCEEDED(hr))
310     {
311         pDesc->Format = d3dformat_from_wined3dformat(wined3ddesc.Format);
312         pDesc->Type = wined3ddesc.Type;
313         pDesc->Usage = wined3ddesc.Usage;
314         pDesc->Pool = wined3ddesc.Pool;
315         pDesc->Width = wined3ddesc.Width;
316         pDesc->Height = wined3ddesc.Height;
317         pDesc->Depth = wined3ddesc.Depth;
318     }
319
320     return hr;
321 }
322
323 static HRESULT WINAPI IDirect3DVolumeTexture9Impl_GetVolumeLevel(LPDIRECT3DVOLUMETEXTURE9 iface, UINT Level, IDirect3DVolume9** ppVolumeLevel) {
324     IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
325     HRESULT hrc = D3D_OK;
326     IWineD3DVolume *myVolume = NULL;
327
328     TRACE("iface %p, level %u, volume %p.\n", iface, Level, ppVolumeLevel);
329
330     wined3d_mutex_lock();
331
332     hrc = IWineD3DVolumeTexture_GetVolumeLevel(This->wineD3DVolumeTexture, Level, &myVolume);
333     if (hrc == D3D_OK && NULL != ppVolumeLevel) {
334        IWineD3DVolumeTexture_GetParent(myVolume, (IUnknown **)ppVolumeLevel);
335        IWineD3DVolumeTexture_Release(myVolume);
336     }
337
338     wined3d_mutex_unlock();
339
340     return hrc;
341 }
342
343 static HRESULT WINAPI IDirect3DVolumeTexture9Impl_LockBox(LPDIRECT3DVOLUMETEXTURE9 iface, UINT Level, D3DLOCKED_BOX* pLockedVolume, CONST D3DBOX* pBox, DWORD Flags) {
344     IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
345     HRESULT hr;
346
347     TRACE("iface %p, level %u, locked_box %p, box %p, flags %#x.\n",
348             iface, Level, pLockedVolume, pBox, Flags);
349
350     wined3d_mutex_lock();
351
352     hr = IWineD3DVolumeTexture_LockBox(This->wineD3DVolumeTexture, Level, (WINED3DLOCKED_BOX *)pLockedVolume,
353             (const WINED3DBOX *)pBox, Flags);
354
355     wined3d_mutex_unlock();
356
357     return hr;
358 }
359
360 static HRESULT WINAPI IDirect3DVolumeTexture9Impl_UnlockBox(LPDIRECT3DVOLUMETEXTURE9 iface, UINT Level) {
361     IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
362     HRESULT hr;
363
364     TRACE("iface %p, level %u.\n", iface, Level);
365
366     wined3d_mutex_lock();
367
368     hr = IWineD3DVolumeTexture_UnlockBox(This->wineD3DVolumeTexture, Level);
369
370     wined3d_mutex_unlock();
371
372     return hr;
373 }
374
375 static HRESULT WINAPI IDirect3DVolumeTexture9Impl_AddDirtyBox(LPDIRECT3DVOLUMETEXTURE9 iface, CONST D3DBOX* pDirtyBox) {
376     IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
377     HRESULT hr;
378
379     TRACE("iface %p, dirty_box %p.\n", iface, pDirtyBox);
380
381     wined3d_mutex_lock();
382
383     hr = IWineD3DVolumeTexture_AddDirtyBox(This->wineD3DVolumeTexture, (CONST WINED3DBOX *)pDirtyBox);
384
385     wined3d_mutex_unlock();
386
387     return hr;
388 }
389
390
391 static const IDirect3DVolumeTexture9Vtbl Direct3DVolumeTexture9_Vtbl =
392 {
393     /* IUnknown */
394     IDirect3DVolumeTexture9Impl_QueryInterface,
395     IDirect3DVolumeTexture9Impl_AddRef,
396     IDirect3DVolumeTexture9Impl_Release,
397     /* IDirect3DResource9 */
398     IDirect3DVolumeTexture9Impl_GetDevice,
399     IDirect3DVolumeTexture9Impl_SetPrivateData,
400     IDirect3DVolumeTexture9Impl_GetPrivateData,
401     IDirect3DVolumeTexture9Impl_FreePrivateData,
402     IDirect3DVolumeTexture9Impl_SetPriority,
403     IDirect3DVolumeTexture9Impl_GetPriority,
404     IDirect3DVolumeTexture9Impl_PreLoad,
405     IDirect3DVolumeTexture9Impl_GetType,
406     /* IDirect3DBaseTexture9 */
407     IDirect3DVolumeTexture9Impl_SetLOD,
408     IDirect3DVolumeTexture9Impl_GetLOD,
409     IDirect3DVolumeTexture9Impl_GetLevelCount,
410     IDirect3DVolumeTexture9Impl_SetAutoGenFilterType,
411     IDirect3DVolumeTexture9Impl_GetAutoGenFilterType,
412     IDirect3DVolumeTexture9Impl_GenerateMipSubLevels,
413     /* IDirect3DVolumeTexture9 */
414     IDirect3DVolumeTexture9Impl_GetLevelDesc,
415     IDirect3DVolumeTexture9Impl_GetVolumeLevel,
416     IDirect3DVolumeTexture9Impl_LockBox,
417     IDirect3DVolumeTexture9Impl_UnlockBox,
418     IDirect3DVolumeTexture9Impl_AddDirtyBox
419 };
420
421 static void STDMETHODCALLTYPE volumetexture_wined3d_object_destroyed(void *parent)
422 {
423     HeapFree(GetProcessHeap(), 0, parent);
424 }
425
426 static const struct wined3d_parent_ops d3d9_volumetexture_wined3d_parent_ops =
427 {
428     volumetexture_wined3d_object_destroyed,
429 };
430
431 HRESULT volumetexture_init(IDirect3DVolumeTexture9Impl *texture, IDirect3DDevice9Impl *device,
432         UINT width, UINT height, UINT depth, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool)
433 {
434     HRESULT hr;
435
436     texture->lpVtbl = &Direct3DVolumeTexture9_Vtbl;
437     texture->ref = 1;
438
439     wined3d_mutex_lock();
440     hr = IWineD3DDevice_CreateVolumeTexture(device->WineD3DDevice, width, height, depth, levels,
441             usage & WINED3DUSAGE_MASK, wined3dformat_from_d3dformat(format), pool,
442             &texture->wineD3DVolumeTexture, (IUnknown *)texture, &d3d9_volumetexture_wined3d_parent_ops);
443     wined3d_mutex_unlock();
444     if (FAILED(hr))
445     {
446         WARN("Failed to create wined3d volume texture, hr %#x.\n", hr);
447         return hr;
448     }
449
450     texture->parentDevice = (IDirect3DDevice9Ex *)device;
451     IDirect3DDevice9Ex_AddRef(texture->parentDevice);
452
453     return D3D_OK;
454 }