VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Wine_new/d3d9/surface.c@ 51270

Last change on this file since 51270 was 51270, checked in by vboxsync, 11 years ago

wine: update to 1.6.2

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 14.3 KB
Line 
1/*
2 * IDirect3DSurface9 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_surface *impl_from_IDirect3DSurface9(IDirect3DSurface9 *iface)
37{
38 return CONTAINING_RECORD(iface, struct d3d9_surface, IDirect3DSurface9_iface);
39}
40
41static HRESULT WINAPI d3d9_surface_QueryInterface(IDirect3DSurface9 *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_IDirect3DSurface9)
46 || IsEqualGUID(riid, &IID_IDirect3DResource9)
47 || IsEqualGUID(riid, &IID_IUnknown))
48 {
49 IDirect3DSurface9_AddRef(iface);
50 *out = iface;
51 return S_OK;
52 }
53
54 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
55
56 *out = NULL;
57 return E_NOINTERFACE;
58}
59
60static ULONG WINAPI d3d9_surface_AddRef(IDirect3DSurface9 *iface)
61{
62 struct d3d9_surface *surface = impl_from_IDirect3DSurface9(iface);
63 ULONG refcount;
64
65 TRACE("iface %p.\n", iface);
66
67 if (surface->forwardReference)
68 {
69 TRACE("Forwarding to %p.\n", surface->forwardReference);
70 return IUnknown_AddRef(surface->forwardReference);
71 }
72
73 refcount = InterlockedIncrement(&surface->refcount);
74 TRACE("%p increasing refcount to %u.\n", iface, refcount);
75
76 if (refcount == 1)
77 {
78 if (surface->parent_device)
79 IDirect3DDevice9Ex_AddRef(surface->parent_device);
80 wined3d_mutex_lock();
81 wined3d_surface_incref(surface->wined3d_surface);
82 wined3d_mutex_unlock();
83 }
84
85 return refcount;
86}
87
88static ULONG WINAPI d3d9_surface_Release(IDirect3DSurface9 *iface)
89{
90 struct d3d9_surface *surface = impl_from_IDirect3DSurface9(iface);
91 ULONG refcount;
92
93 TRACE("iface %p.\n", iface);
94
95 if (surface->forwardReference)
96 {
97 TRACE("Forwarding to %p.\n", surface->forwardReference);
98 return IUnknown_Release(surface->forwardReference);
99 }
100
101 refcount = InterlockedDecrement(&surface->refcount);
102 TRACE("%p decreasing refcount to %u.\n", iface, refcount);
103
104 if (!refcount)
105 {
106 IDirect3DDevice9Ex *parent_device = surface->parent_device;
107
108 wined3d_mutex_lock();
109 wined3d_surface_decref(surface->wined3d_surface);
110 wined3d_mutex_unlock();
111
112 /* Release the device last, as it may cause the device to be destroyed. */
113 if (parent_device)
114 IDirect3DDevice9Ex_Release(parent_device);
115 }
116
117 return refcount;
118}
119
120static HRESULT WINAPI d3d9_surface_GetDevice(IDirect3DSurface9 *iface, IDirect3DDevice9 **device)
121{
122 struct d3d9_surface *surface = impl_from_IDirect3DSurface9(iface);
123
124 TRACE("iface %p, device %p.\n", iface, device);
125
126 if (surface->forwardReference)
127 {
128 IDirect3DResource9 *resource;
129 HRESULT hr;
130
131 hr = IUnknown_QueryInterface(surface->forwardReference, &IID_IDirect3DResource9, (void **)&resource);
132 if (SUCCEEDED(hr))
133 {
134 hr = IDirect3DResource9_GetDevice(resource, device);
135 IDirect3DResource9_Release(resource);
136
137 TRACE("Returning device %p.\n", *device);
138 }
139
140 return hr;
141 }
142
143 *device = (IDirect3DDevice9 *)surface->parent_device;
144 IDirect3DDevice9_AddRef(*device);
145
146 TRACE("Returning device %p.\n", *device);
147
148 return D3D_OK;
149}
150
151static HRESULT WINAPI d3d9_surface_SetPrivateData(IDirect3DSurface9 *iface, REFGUID guid,
152 const void *data, DWORD data_size, DWORD flags)
153{
154 struct d3d9_surface *surface = impl_from_IDirect3DSurface9(iface);
155 struct wined3d_resource *resource;
156 HRESULT hr;
157
158 TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
159 iface, debugstr_guid(guid), data, data_size, flags);
160
161 wined3d_mutex_lock();
162 resource = wined3d_surface_get_resource(surface->wined3d_surface);
163 hr = wined3d_resource_set_private_data(resource, guid, data, data_size, flags);
164 wined3d_mutex_unlock();
165
166 return hr;
167}
168
169static HRESULT WINAPI d3d9_surface_GetPrivateData(IDirect3DSurface9 *iface, REFGUID guid,
170 void *data, DWORD *data_size)
171{
172 struct d3d9_surface *surface = impl_from_IDirect3DSurface9(iface);
173 struct wined3d_resource *resource;
174 HRESULT hr;
175
176 TRACE("iface %p, guid %s, data %p, data_size %p.\n",
177 iface, debugstr_guid(guid), data, data_size);
178
179 wined3d_mutex_lock();
180 resource = wined3d_surface_get_resource(surface->wined3d_surface);
181 hr = wined3d_resource_get_private_data(resource, guid, data, data_size);
182 wined3d_mutex_unlock();
183
184 return hr;
185}
186
187static HRESULT WINAPI d3d9_surface_FreePrivateData(IDirect3DSurface9 *iface, REFGUID guid)
188{
189 struct d3d9_surface *surface = impl_from_IDirect3DSurface9(iface);
190 struct wined3d_resource *resource;
191 HRESULT hr;
192
193 TRACE("iface %p, guid %s.\n", iface, debugstr_guid(guid));
194
195 wined3d_mutex_lock();
196 resource = wined3d_surface_get_resource(surface->wined3d_surface);
197 hr = wined3d_resource_free_private_data(resource, guid);
198 wined3d_mutex_unlock();
199
200 return hr;
201}
202
203static DWORD WINAPI d3d9_surface_SetPriority(IDirect3DSurface9 *iface, DWORD priority)
204{
205 struct d3d9_surface *surface = impl_from_IDirect3DSurface9(iface);
206 DWORD ret;
207
208 TRACE("iface %p, priority %u.\n", iface, priority);
209
210 wined3d_mutex_lock();
211 ret = wined3d_surface_set_priority(surface->wined3d_surface, priority);
212 wined3d_mutex_unlock();
213
214 return ret;
215}
216
217static DWORD WINAPI d3d9_surface_GetPriority(IDirect3DSurface9 *iface)
218{
219 struct d3d9_surface *surface = impl_from_IDirect3DSurface9(iface);
220 DWORD ret;
221
222 TRACE("iface %p.\n", iface);
223
224 wined3d_mutex_lock();
225 ret = wined3d_surface_get_priority(surface->wined3d_surface);
226 wined3d_mutex_unlock();
227
228 return ret;
229}
230
231static void WINAPI d3d9_surface_PreLoad(IDirect3DSurface9 *iface)
232{
233 struct d3d9_surface *surface = impl_from_IDirect3DSurface9(iface);
234
235 TRACE("iface %p.\n", iface);
236
237 wined3d_mutex_lock();
238 wined3d_surface_preload(surface->wined3d_surface);
239 wined3d_mutex_unlock();
240}
241
242static D3DRESOURCETYPE WINAPI d3d9_surface_GetType(IDirect3DSurface9 *iface)
243{
244 TRACE("iface %p.\n", iface);
245
246 return D3DRTYPE_SURFACE;
247}
248
249static HRESULT WINAPI d3d9_surface_GetContainer(IDirect3DSurface9 *iface, REFIID riid, void **container)
250{
251 struct d3d9_surface *surface = impl_from_IDirect3DSurface9(iface);
252 HRESULT hr;
253
254 TRACE("iface %p, riid %s, container %p.\n", iface, debugstr_guid(riid), container);
255
256 if (!surface->container)
257 return E_NOINTERFACE;
258
259 hr = IUnknown_QueryInterface(surface->container, riid, container);
260
261 TRACE("Returning %p.\n", *container);
262
263 return hr;
264}
265
266static HRESULT WINAPI d3d9_surface_GetDesc(IDirect3DSurface9 *iface, D3DSURFACE_DESC *desc)
267{
268 struct d3d9_surface *surface = impl_from_IDirect3DSurface9(iface);
269 struct wined3d_resource_desc wined3d_desc;
270 struct wined3d_resource *wined3d_resource;
271
272 TRACE("iface %p, desc %p.\n", iface, desc);
273
274 wined3d_mutex_lock();
275 wined3d_resource = wined3d_surface_get_resource(surface->wined3d_surface);
276 wined3d_resource_get_desc(wined3d_resource, &wined3d_desc);
277 wined3d_mutex_unlock();
278
279 desc->Format = d3dformat_from_wined3dformat(wined3d_desc.format);
280 desc->Type = wined3d_desc.resource_type;
281 desc->Usage = wined3d_desc.usage & WINED3DUSAGE_MASK;
282 desc->Pool = wined3d_desc.pool;
283 desc->MultiSampleType = wined3d_desc.multisample_type;
284 desc->MultiSampleQuality = wined3d_desc.multisample_quality;
285 desc->Width = wined3d_desc.width;
286 desc->Height = wined3d_desc.height;
287
288 return D3D_OK;
289}
290
291static HRESULT WINAPI d3d9_surface_LockRect(IDirect3DSurface9 *iface,
292 D3DLOCKED_RECT *locked_rect, const RECT *rect, DWORD flags)
293{
294 struct d3d9_surface *surface = impl_from_IDirect3DSurface9(iface);
295 struct wined3d_map_desc map_desc;
296 HRESULT hr;
297
298 TRACE("iface %p, locked_rect %p, rect %s, flags %#x.\n",
299 iface, locked_rect, wine_dbgstr_rect(rect), flags);
300
301 wined3d_mutex_lock();
302 hr = wined3d_surface_map(surface->wined3d_surface, &map_desc, rect, flags);
303 wined3d_mutex_unlock();
304
305 if (SUCCEEDED(hr))
306 {
307 locked_rect->Pitch = map_desc.row_pitch;
308 locked_rect->pBits = map_desc.data;
309 }
310
311 return hr;
312}
313
314static HRESULT WINAPI d3d9_surface_UnlockRect(IDirect3DSurface9 *iface)
315{
316 struct d3d9_surface *surface = impl_from_IDirect3DSurface9(iface);
317 HRESULT hr;
318
319 TRACE("iface %p.\n", iface);
320
321 wined3d_mutex_lock();
322 hr = wined3d_surface_unmap(surface->wined3d_surface);
323 wined3d_mutex_unlock();
324
325 switch(hr)
326 {
327 case WINEDDERR_NOTLOCKED: return D3DERR_INVALIDCALL;
328 default: return hr;
329 }
330}
331
332static HRESULT WINAPI d3d9_surface_GetDC(IDirect3DSurface9 *iface, HDC *dc)
333{
334 struct d3d9_surface *surface = impl_from_IDirect3DSurface9(iface);
335 HRESULT hr;
336
337 TRACE("iface %p, dc %p.\n", iface, dc);
338
339 if (!surface->getdc_supported)
340 {
341 WARN("Surface does not support GetDC, returning D3DERR_INVALIDCALL\n");
342 /* Don't touch the DC */
343 return D3DERR_INVALIDCALL;
344 }
345
346 wined3d_mutex_lock();
347 hr = wined3d_surface_getdc(surface->wined3d_surface, dc);
348 wined3d_mutex_unlock();
349
350 return hr;
351}
352
353static HRESULT WINAPI d3d9_surface_ReleaseDC(IDirect3DSurface9 *iface, HDC dc)
354{
355 struct d3d9_surface *surface = impl_from_IDirect3DSurface9(iface);
356 HRESULT hr;
357
358 TRACE("iface %p, dc %p.\n", iface, dc);
359
360 wined3d_mutex_lock();
361 hr = wined3d_surface_releasedc(surface->wined3d_surface, dc);
362 wined3d_mutex_unlock();
363
364 switch (hr)
365 {
366 case WINEDDERR_NODC: return D3DERR_INVALIDCALL;
367 default: return hr;
368 }
369}
370
371static const struct IDirect3DSurface9Vtbl d3d9_surface_vtbl =
372{
373 /* IUnknown */
374 d3d9_surface_QueryInterface,
375 d3d9_surface_AddRef,
376 d3d9_surface_Release,
377 /* IDirect3DResource9 */
378 d3d9_surface_GetDevice,
379 d3d9_surface_SetPrivateData,
380 d3d9_surface_GetPrivateData,
381 d3d9_surface_FreePrivateData,
382 d3d9_surface_SetPriority,
383 d3d9_surface_GetPriority,
384 d3d9_surface_PreLoad,
385 d3d9_surface_GetType,
386 /* IDirect3DSurface9 */
387 d3d9_surface_GetContainer,
388 d3d9_surface_GetDesc,
389 d3d9_surface_LockRect,
390 d3d9_surface_UnlockRect,
391 d3d9_surface_GetDC,
392 d3d9_surface_ReleaseDC,
393};
394
395static void STDMETHODCALLTYPE surface_wined3d_object_destroyed(void *parent)
396{
397 HeapFree(GetProcessHeap(), 0, parent);
398}
399
400static const struct wined3d_parent_ops d3d9_surface_wined3d_parent_ops =
401{
402 surface_wined3d_object_destroyed,
403};
404
405HRESULT surface_init(struct d3d9_surface *surface, struct d3d9_device *device, UINT width, UINT height,
406 D3DFORMAT format, DWORD flags, DWORD usage, D3DPOOL pool, D3DMULTISAMPLE_TYPE multisample_type,
407 DWORD multisample_quality
408#ifdef VBOX_WITH_WDDM
409 , HANDLE *shared_handle
410 , void *pvClientMem
411#endif
412 )
413{
414 HRESULT hr;
415
416 surface->IDirect3DSurface9_iface.lpVtbl = &d3d9_surface_vtbl;
417 surface->refcount = 1;
418
419 switch (format)
420 {
421 case D3DFMT_A8R8G8B8:
422 case D3DFMT_X8R8G8B8:
423 case D3DFMT_R5G6B5:
424 case D3DFMT_X1R5G5B5:
425 case D3DFMT_A1R5G5B5:
426 case D3DFMT_R8G8B8:
427 surface->getdc_supported = TRUE;
428 break;
429
430 default:
431 surface->getdc_supported = FALSE;
432 break;
433 }
434
435 /* FIXME: Check MAX bounds of MultisampleQuality. */
436 if (multisample_quality > 0)
437 {
438 FIXME("Multisample quality set to %u, substituting 0.\n", multisample_quality);
439 multisample_quality = 0;
440 }
441
442 wined3d_mutex_lock();
443 hr = wined3d_surface_create(device->wined3d_device, width, height, wined3dformat_from_d3dformat(format),
444 usage & WINED3DUSAGE_MASK, (enum wined3d_pool)pool, multisample_type, multisample_quality,
445 flags, surface, &d3d9_surface_wined3d_parent_ops, &surface->wined3d_surface
446#ifdef VBOX_WITH_WDDM
447 , shared_handle
448 , pvClientMem
449#endif
450 );
451 wined3d_mutex_unlock();
452 if (FAILED(hr))
453 {
454 WARN("Failed to create wined3d surface, hr %#x.\n", hr);
455 return hr;
456 }
457
458 surface->parent_device = &device->IDirect3DDevice9Ex_iface;
459 IDirect3DDevice9Ex_AddRef(surface->parent_device);
460
461 return D3D_OK;
462}
463
464struct d3d9_surface *unsafe_impl_from_IDirect3DSurface9(IDirect3DSurface9 *iface)
465{
466 if (!iface)
467 return NULL;
468 assert(iface->lpVtbl == &d3d9_surface_vtbl);
469
470 return impl_from_IDirect3DSurface9(iface);
471}
472
473#ifdef VBOX_WITH_WDDM
474VBOXWINEEX_DECL(HRESULT) VBoxWineExD3DSurf9GetHostId(IDirect3DSurface9 *iface, uint32_t *pu32Id)
475{
476 struct d3d9_surface *surface = impl_from_IDirect3DSurface9(iface);
477 HRESULT hr;
478 wined3d_mutex_lock();
479 hr = wined3d_surface_get_host_id(surface->wined3d_surface, pu32Id);
480 wined3d_mutex_unlock();
481 return hr;
482}
483
484VBOXWINEEX_DECL(HRESULT) VBoxWineExD3DSurf9SyncToHost(IDirect3DSurface9 *iface)
485{
486 struct d3d9_surface *surface = impl_from_IDirect3DSurface9(iface);
487 HRESULT hr;
488 wined3d_mutex_lock();
489 hr = wined3d_surface_sync_to_host(surface->wined3d_surface);
490 wined3d_mutex_unlock();
491 return hr;
492}
493#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