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