VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Wine_new/d3d9/volume.c@ 68890

Last change on this file since 68890 was 63024, checked in by vboxsync, 8 years ago

GA/NT/Graphics: warnings

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.6 KB
Line 
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/*
23 * Oracle LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
24 * other than GPL or LGPL is available it will apply instead, Oracle elects to use only
25 * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
26 * a choice of LGPL license versions is made available with the language indicating
27 * that LGPLv2 or any later version may be used, or where a choice of which version
28 * of the LGPL is applied is otherwise unspecified.
29 */
30
31#include "config.h"
32#include "d3d9_private.h"
33
34WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
35
36static inline struct d3d9_volume *impl_from_IDirect3DVolume9(IDirect3DVolume9 *iface)
37{
38 return CONTAINING_RECORD(iface, struct d3d9_volume, IDirect3DVolume9_iface);
39}
40
41static HRESULT WINAPI d3d9_volume_QueryInterface(IDirect3DVolume9 *iface, REFIID riid, void **out)
42{
43 TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
44
45 if (IsEqualGUID(riid, &IID_IDirect3DVolume9)
46 || IsEqualGUID(riid, &IID_IUnknown))
47 {
48 IDirect3DVolume9_AddRef(iface);
49 *out = iface;
50 return S_OK;
51 }
52
53 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
54
55 *out = NULL;
56 return E_NOINTERFACE;
57}
58
59static ULONG WINAPI d3d9_volume_AddRef(IDirect3DVolume9 *iface)
60{
61 struct d3d9_volume *volume = impl_from_IDirect3DVolume9(iface);
62 ULONG refcount;
63
64 TRACE("iface %p.\n", iface);
65
66 if (volume->forwardReference)
67 {
68 TRACE("Forwarding to %p.\n", volume->forwardReference);
69 return IUnknown_AddRef(volume->forwardReference);
70 }
71
72 refcount = InterlockedIncrement(&volume->refcount);
73 TRACE("%p increasing refcount to %u.\n", iface, refcount);
74
75 if (refcount == 1)
76 {
77 wined3d_mutex_lock();
78 wined3d_volume_incref(volume->wined3d_volume);
79 wined3d_mutex_unlock();
80 }
81
82 return refcount;
83}
84
85static ULONG WINAPI d3d9_volume_Release(IDirect3DVolume9 *iface)
86{
87 struct d3d9_volume *volume = impl_from_IDirect3DVolume9(iface);
88 ULONG refcount;
89
90 TRACE("iface %p.\n", iface);
91
92 if (volume->forwardReference)
93 {
94 TRACE("Forwarding to %p.\n", volume->forwardReference);
95 return IUnknown_Release(volume->forwardReference);
96 }
97
98 refcount = InterlockedDecrement(&volume->refcount);
99 TRACE("%p decreasing refcount to %u.\n", iface, refcount);
100
101 if (!refcount)
102 {
103 wined3d_mutex_lock();
104 wined3d_volume_decref(volume->wined3d_volume);
105 wined3d_mutex_unlock();
106 }
107
108 return refcount;
109}
110
111static HRESULT WINAPI d3d9_volume_GetDevice(IDirect3DVolume9 *iface, IDirect3DDevice9 **device)
112{
113 struct d3d9_volume *volume = impl_from_IDirect3DVolume9(iface);
114 IDirect3DResource9 *resource;
115 HRESULT hr;
116
117 TRACE("iface %p, device %p.\n", iface, device);
118
119 hr = IUnknown_QueryInterface(volume->forwardReference, &IID_IDirect3DResource9, (void **)&resource);
120 if (SUCCEEDED(hr))
121 {
122 hr = IDirect3DResource9_GetDevice(resource, device);
123 IDirect3DResource9_Release(resource);
124
125 TRACE("Returning device %p.\n", *device);
126 }
127
128 return hr;
129}
130
131static HRESULT WINAPI d3d9_volume_SetPrivateData(IDirect3DVolume9 *iface, REFGUID guid,
132 const void *data, DWORD data_size, DWORD flags)
133{
134 struct d3d9_volume *volume = impl_from_IDirect3DVolume9(iface);
135 struct wined3d_resource *resource;
136 HRESULT hr;
137
138 TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
139 iface, debugstr_guid(guid), data, data_size, flags);
140
141 wined3d_mutex_lock();
142 resource = wined3d_volume_get_resource(volume->wined3d_volume);
143 hr = wined3d_resource_set_private_data(resource, guid, data, data_size, flags);
144 wined3d_mutex_unlock();
145
146 return hr;
147}
148
149static HRESULT WINAPI d3d9_volume_GetPrivateData(IDirect3DVolume9 *iface, REFGUID guid,
150 void *data, DWORD *data_size)
151{
152 struct d3d9_volume *volume = impl_from_IDirect3DVolume9(iface);
153 struct wined3d_resource *resource;
154 HRESULT hr;
155
156 TRACE("iface %p, guid %s, data %p, data_size %p.\n",
157 iface, debugstr_guid(guid), data, data_size);
158
159 wined3d_mutex_lock();
160 resource = wined3d_volume_get_resource(volume->wined3d_volume);
161 hr = wined3d_resource_get_private_data(resource, guid, data, data_size);
162 wined3d_mutex_unlock();
163
164 return hr;
165}
166
167static HRESULT WINAPI d3d9_volume_FreePrivateData(IDirect3DVolume9 *iface, REFGUID guid)
168{
169 struct d3d9_volume *volume = impl_from_IDirect3DVolume9(iface);
170 struct wined3d_resource *resource;
171 HRESULT hr;
172
173 TRACE("iface %p, guid %s.\n", iface, debugstr_guid(guid));
174
175 wined3d_mutex_lock();
176 resource = wined3d_volume_get_resource(volume->wined3d_volume);
177 hr = wined3d_resource_free_private_data(resource, guid);
178 wined3d_mutex_unlock();
179
180 return hr;
181}
182
183static HRESULT WINAPI d3d9_volume_GetContainer(IDirect3DVolume9 *iface, REFIID riid, void **container)
184{
185 struct d3d9_volume *volume = impl_from_IDirect3DVolume9(iface);
186 HRESULT hr;
187
188 TRACE("iface %p, riid %s, container %p.\n", iface, debugstr_guid(riid), container);
189
190 if (!volume->container)
191 return E_NOINTERFACE;
192
193 hr = IUnknown_QueryInterface(volume->container, riid, container);
194
195 TRACE("Returning %p,\n", *container);
196
197 return hr;
198}
199
200static HRESULT WINAPI d3d9_volume_GetDesc(IDirect3DVolume9 *iface, D3DVOLUME_DESC *desc)
201{
202 struct d3d9_volume *volume = impl_from_IDirect3DVolume9(iface);
203 struct wined3d_resource_desc wined3d_desc;
204 struct wined3d_resource *wined3d_resource;
205
206 TRACE("iface %p, desc %p.\n", iface, desc);
207
208 wined3d_mutex_lock();
209 wined3d_resource = wined3d_volume_get_resource(volume->wined3d_volume);
210 wined3d_resource_get_desc(wined3d_resource, &wined3d_desc);
211 wined3d_mutex_unlock();
212
213 desc->Format = d3dformat_from_wined3dformat(wined3d_desc.format);
214 desc->Type = wined3d_desc.resource_type;
215 desc->Usage = wined3d_desc.usage & WINED3DUSAGE_MASK;
216 desc->Pool = wined3d_desc.pool;
217 desc->Width = wined3d_desc.width;
218 desc->Height = wined3d_desc.height;
219 desc->Depth = wined3d_desc.depth;
220
221 return D3D_OK;
222}
223
224static HRESULT WINAPI d3d9_volume_LockBox(IDirect3DVolume9 *iface,
225 D3DLOCKED_BOX *locked_box, const D3DBOX *box, DWORD flags)
226{
227 struct d3d9_volume *volume = impl_from_IDirect3DVolume9(iface);
228 struct wined3d_map_desc map_desc;
229 HRESULT hr;
230
231 TRACE("iface %p, locked_box %p, box %p, flags %#x.\n",
232 iface, locked_box, box, flags);
233
234 wined3d_mutex_lock();
235 hr = wined3d_volume_map(volume->wined3d_volume, &map_desc, (const struct wined3d_box *)box, flags);
236 wined3d_mutex_unlock();
237
238 locked_box->RowPitch = map_desc.row_pitch;
239 locked_box->SlicePitch = map_desc.slice_pitch;
240 locked_box->pBits = map_desc.data;
241
242 return hr;
243}
244
245static HRESULT WINAPI d3d9_volume_UnlockBox(IDirect3DVolume9 *iface)
246{
247 struct d3d9_volume *volume = impl_from_IDirect3DVolume9(iface);
248 HRESULT hr;
249
250 TRACE("iface %p.\n", iface);
251
252 wined3d_mutex_lock();
253 hr = wined3d_volume_unmap(volume->wined3d_volume);
254 wined3d_mutex_unlock();
255
256 return hr;
257}
258
259static const struct IDirect3DVolume9Vtbl d3d9_volume_vtbl =
260{
261 /* IUnknown */
262 d3d9_volume_QueryInterface,
263 d3d9_volume_AddRef,
264 d3d9_volume_Release,
265 /* IDirect3DVolume9 */
266 d3d9_volume_GetDevice,
267 d3d9_volume_SetPrivateData,
268 d3d9_volume_GetPrivateData,
269 d3d9_volume_FreePrivateData,
270 d3d9_volume_GetContainer,
271 d3d9_volume_GetDesc,
272 d3d9_volume_LockBox,
273 d3d9_volume_UnlockBox,
274};
275
276static void STDMETHODCALLTYPE volume_wined3d_object_destroyed(void *parent)
277{
278 HeapFree(GetProcessHeap(), 0, parent);
279}
280
281static const struct wined3d_parent_ops d3d9_volume_wined3d_parent_ops =
282{
283 volume_wined3d_object_destroyed,
284};
285
286HRESULT volume_init(struct d3d9_volume *volume, struct d3d9_device *device, UINT width, UINT height,
287 UINT depth, DWORD usage, enum wined3d_format_id format, enum wined3d_pool pool
288#ifdef VBOX_WITH_WDDM
289 , HANDLE *shared_handle
290 , void *pvClientMem
291#endif
292)
293{
294 HRESULT hr;
295
296 volume->IDirect3DVolume9_iface.lpVtbl = (struct IDirect3DVolume9Vtbl *)&d3d9_volume_vtbl;
297 volume->refcount = 1;
298
299 hr = wined3d_volume_create(device->wined3d_device, width, height, depth, usage & WINED3DUSAGE_MASK,
300 format, pool, volume, &d3d9_volume_wined3d_parent_ops, &volume->wined3d_volume
301#ifdef VBOX_WITH_WDDM
302 , shared_handle
303 , pvClientMem
304#endif
305 );
306 if (FAILED(hr))
307 {
308 WARN("Failed to create wined3d volume, hr %#x.\n", hr);
309 return hr;
310 }
311
312 return D3D_OK;
313}
314
315#ifdef VBOX_WITH_WDDM
316struct d3d9_volume *unsafe_impl_from_IDirect3DVolume9(IDirect3DVolume9 *iface)
317{
318 if (!iface)
319 return NULL;
320 assert(iface->lpVtbl == (IDirect3DVolume9Vtbl *)&d3d9_volume_vtbl);
321 return CONTAINING_RECORD(iface, struct d3d9_volume, IDirect3DVolume9_iface);
322}
323#endif
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette