Merge r55012 adding Wine3D control panel as per Amine's request.
[reactos.git] / 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 static inline IDirect3DVolume9Impl *impl_from_IDirect3DVolume9(IDirect3DVolume9 *iface)
28 {
29 return CONTAINING_RECORD(iface, IDirect3DVolume9Impl, IDirect3DVolume9_iface);
30 }
31
32 static HRESULT WINAPI IDirect3DVolume9Impl_QueryInterface(IDirect3DVolume9 *iface, REFIID riid,
33 void **ppobj)
34 {
35 IDirect3DVolume9Impl *This = impl_from_IDirect3DVolume9(iface);
36
37 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
38
39 if (IsEqualGUID(riid, &IID_IUnknown)
40 || IsEqualGUID(riid, &IID_IDirect3DVolume9)) {
41 IDirect3DVolume9_AddRef(iface);
42 *ppobj = This;
43 return S_OK;
44 }
45
46 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
47 *ppobj = NULL;
48 return E_NOINTERFACE;
49 }
50
51 static ULONG WINAPI IDirect3DVolume9Impl_AddRef(IDirect3DVolume9 *iface)
52 {
53 IDirect3DVolume9Impl *This = impl_from_IDirect3DVolume9(iface);
54
55 TRACE("iface %p.\n", iface);
56
57 if (This->forwardReference) {
58 /* Forward refcounting */
59 TRACE("(%p) : Forwarding to %p\n", This, This->forwardReference);
60 return IUnknown_AddRef(This->forwardReference);
61 } else {
62 /* No container, handle our own refcounting */
63 ULONG ref = InterlockedIncrement(&This->ref);
64
65 TRACE("%p increasing refcount to %u.\n", iface, ref);
66
67 if (ref == 1)
68 {
69 wined3d_mutex_lock();
70 wined3d_volume_incref(This->wined3d_volume);
71 wined3d_mutex_unlock();
72 }
73
74 return ref;
75 }
76 }
77
78 static ULONG WINAPI IDirect3DVolume9Impl_Release(IDirect3DVolume9 *iface)
79 {
80 IDirect3DVolume9Impl *This = impl_from_IDirect3DVolume9(iface);
81
82 TRACE("iface %p.\n", iface);
83
84 if (This->forwardReference) {
85 /* Forward refcounting */
86 TRACE("(%p) : Forwarding to %p\n", This, This->forwardReference);
87 return IUnknown_Release(This->forwardReference);
88 } else {
89 /* No container, handle our own refcounting */
90 ULONG ref = InterlockedDecrement(&This->ref);
91
92 TRACE("%p decreasing refcount to %u.\n", iface, ref);
93
94 if (ref == 0) {
95 wined3d_mutex_lock();
96 wined3d_volume_decref(This->wined3d_volume);
97 wined3d_mutex_unlock();
98 }
99
100 return ref;
101 }
102 }
103
104 static HRESULT WINAPI IDirect3DVolume9Impl_GetDevice(IDirect3DVolume9 *iface,
105 IDirect3DDevice9 **device)
106 {
107 IDirect3DVolume9Impl *This = impl_from_IDirect3DVolume9(iface);
108 IDirect3DResource9 *resource;
109 HRESULT hr;
110
111 TRACE("iface %p, device %p.\n", iface, device);
112
113 hr = IUnknown_QueryInterface(This->forwardReference, &IID_IDirect3DResource9, (void **)&resource);
114 if (SUCCEEDED(hr))
115 {
116 hr = IDirect3DResource9_GetDevice(resource, device);
117 IDirect3DResource9_Release(resource);
118
119 TRACE("Returning device %p.\n", *device);
120 }
121
122 return hr;
123 }
124
125 static HRESULT WINAPI IDirect3DVolume9Impl_SetPrivateData(IDirect3DVolume9 *iface, REFGUID refguid,
126 const void *pData, DWORD SizeOfData, DWORD Flags)
127 {
128 IDirect3DVolume9Impl *This = impl_from_IDirect3DVolume9(iface);
129 HRESULT hr;
130
131 TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
132 iface, debugstr_guid(refguid), pData, SizeOfData, Flags);
133
134 wined3d_mutex_lock();
135 hr = wined3d_volume_set_private_data(This->wined3d_volume, refguid, pData, SizeOfData, Flags);
136 wined3d_mutex_unlock();
137
138 return hr;
139 }
140
141 static HRESULT WINAPI IDirect3DVolume9Impl_GetPrivateData(IDirect3DVolume9 *iface, REFGUID refguid,
142 void *pData, DWORD *pSizeOfData)
143 {
144 IDirect3DVolume9Impl *This = impl_from_IDirect3DVolume9(iface);
145 HRESULT hr;
146
147 TRACE("iface %p, guid %s, data %p, data_size %p.\n",
148 iface, debugstr_guid(refguid), pData, pSizeOfData);
149
150 wined3d_mutex_lock();
151 hr = wined3d_volume_get_private_data(This->wined3d_volume, refguid, pData, pSizeOfData);
152 wined3d_mutex_unlock();
153
154 return hr;
155 }
156
157 static HRESULT WINAPI IDirect3DVolume9Impl_FreePrivateData(IDirect3DVolume9 *iface, REFGUID refguid)
158 {
159 IDirect3DVolume9Impl *This = impl_from_IDirect3DVolume9(iface);
160 HRESULT hr;
161
162 TRACE("iface %p, guid %s.\n", iface, debugstr_guid(refguid));
163
164 wined3d_mutex_lock();
165 hr = wined3d_volume_free_private_data(This->wined3d_volume, refguid);
166 wined3d_mutex_unlock();
167
168 return hr;
169 }
170
171 static HRESULT WINAPI IDirect3DVolume9Impl_GetContainer(IDirect3DVolume9 *iface, REFIID riid,
172 void **ppContainer)
173 {
174 IDirect3DVolume9Impl *This = impl_from_IDirect3DVolume9(iface);
175 HRESULT res;
176
177 TRACE("iface %p, riid %s, container %p.\n", iface, debugstr_guid(riid), ppContainer);
178
179 if (!This->container) return E_NOINTERFACE;
180
181 res = IUnknown_QueryInterface(This->container, riid, ppContainer);
182
183 TRACE("Returning ppContainer %p, *ppContainer %p\n", ppContainer, *ppContainer);
184
185 return res;
186 }
187
188 static HRESULT WINAPI IDirect3DVolume9Impl_GetDesc(IDirect3DVolume9 *iface, D3DVOLUME_DESC *desc)
189 {
190 IDirect3DVolume9Impl *This = impl_from_IDirect3DVolume9(iface);
191 struct wined3d_resource_desc wined3d_desc;
192 struct wined3d_resource *wined3d_resource;
193
194 TRACE("iface %p, desc %p.\n", iface, desc);
195
196 wined3d_mutex_lock();
197 wined3d_resource = wined3d_volume_get_resource(This->wined3d_volume);
198 wined3d_resource_get_desc(wined3d_resource, &wined3d_desc);
199 wined3d_mutex_unlock();
200
201 desc->Format = d3dformat_from_wined3dformat(wined3d_desc.format);
202 desc->Type = wined3d_desc.resource_type;
203 desc->Usage = wined3d_desc.usage;
204 desc->Pool = wined3d_desc.pool;
205 desc->Width = wined3d_desc.width;
206 desc->Height = wined3d_desc.height;
207 desc->Depth = wined3d_desc.depth;
208
209 return D3D_OK;
210 }
211
212 static HRESULT WINAPI IDirect3DVolume9Impl_LockBox(IDirect3DVolume9 *iface,
213 D3DLOCKED_BOX *pLockedVolume, const D3DBOX *pBox, DWORD Flags)
214 {
215 IDirect3DVolume9Impl *This = impl_from_IDirect3DVolume9(iface);
216 HRESULT hr;
217
218 TRACE("iface %p, locked_box %p, box %p, flags %#x.\n",
219 iface, pLockedVolume, pBox, Flags);
220
221 wined3d_mutex_lock();
222 hr = wined3d_volume_map(This->wined3d_volume, (WINED3DLOCKED_BOX *)pLockedVolume,
223 (const WINED3DBOX *)pBox, Flags);
224 wined3d_mutex_unlock();
225
226 return hr;
227 }
228
229 static HRESULT WINAPI IDirect3DVolume9Impl_UnlockBox(IDirect3DVolume9 *iface)
230 {
231 IDirect3DVolume9Impl *This = impl_from_IDirect3DVolume9(iface);
232 HRESULT hr;
233
234 TRACE("iface %p.\n", iface);
235
236 wined3d_mutex_lock();
237 hr = wined3d_volume_unmap(This->wined3d_volume);
238 wined3d_mutex_unlock();
239
240 return hr;
241 }
242
243 static const IDirect3DVolume9Vtbl Direct3DVolume9_Vtbl =
244 {
245 /* IUnknown */
246 IDirect3DVolume9Impl_QueryInterface,
247 IDirect3DVolume9Impl_AddRef,
248 IDirect3DVolume9Impl_Release,
249 /* IDirect3DVolume9 */
250 IDirect3DVolume9Impl_GetDevice,
251 IDirect3DVolume9Impl_SetPrivateData,
252 IDirect3DVolume9Impl_GetPrivateData,
253 IDirect3DVolume9Impl_FreePrivateData,
254 IDirect3DVolume9Impl_GetContainer,
255 IDirect3DVolume9Impl_GetDesc,
256 IDirect3DVolume9Impl_LockBox,
257 IDirect3DVolume9Impl_UnlockBox
258 };
259
260 static void STDMETHODCALLTYPE volume_wined3d_object_destroyed(void *parent)
261 {
262 HeapFree(GetProcessHeap(), 0, parent);
263 }
264
265 static const struct wined3d_parent_ops d3d9_volume_wined3d_parent_ops =
266 {
267 volume_wined3d_object_destroyed,
268 };
269
270 HRESULT volume_init(IDirect3DVolume9Impl *volume, IDirect3DDevice9Impl *device, UINT width, UINT height,
271 UINT depth, DWORD usage, enum wined3d_format_id format, WINED3DPOOL pool)
272 {
273 HRESULT hr;
274
275 volume->IDirect3DVolume9_iface.lpVtbl = &Direct3DVolume9_Vtbl;
276 volume->ref = 1;
277
278 hr = wined3d_volume_create(device->wined3d_device, width, height, depth, usage & WINED3DUSAGE_MASK,
279 format, pool, volume, &d3d9_volume_wined3d_parent_ops, &volume->wined3d_volume);
280 if (FAILED(hr))
281 {
282 WARN("Failed to create wined3d volume, hr %#x.\n", hr);
283 return hr;
284 }
285
286 return D3D_OK;
287 }