VirtualBox

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

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

header fixes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 23.5 KB
Line 
1/*
2 * IDirect3D9 implementation
3 *
4 * Copyright 2002 Jason Edmeades
5 * Copyright 2005 Oliver Stieber
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 *impl_from_IDirect3D9Ex(IDirect3D9Ex *iface)
37{
38 return CONTAINING_RECORD(iface, struct d3d9, IDirect3D9Ex_iface);
39}
40
41static HRESULT WINAPI d3d9_QueryInterface(IDirect3D9Ex *iface, REFIID riid, void **out)
42{
43 struct d3d9 *d3d9 = impl_from_IDirect3D9Ex(iface);
44
45 TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
46
47 if (IsEqualGUID(riid, &IID_IDirect3D9)
48 || IsEqualGUID(riid, &IID_IUnknown))
49 {
50 IDirect3D9Ex_AddRef(&d3d9->IDirect3D9Ex_iface);
51 *out = &d3d9->IDirect3D9Ex_iface;
52 return S_OK;
53 }
54
55 if (IsEqualGUID(riid, &IID_IDirect3D9Ex))
56 {
57 if (!d3d9->extended)
58 {
59 WARN("Application asks for IDirect3D9Ex, but this instance wasn't created with Direct3DCreate9Ex.\n");
60 *out = NULL;
61 return E_NOINTERFACE;
62 }
63
64 IDirect3D9Ex_AddRef(&d3d9->IDirect3D9Ex_iface);
65 *out = &d3d9->IDirect3D9Ex_iface;
66 return S_OK;
67 }
68
69 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
70
71 *out = NULL;
72 return E_NOINTERFACE;
73}
74
75static ULONG WINAPI d3d9_AddRef(IDirect3D9Ex *iface)
76{
77 struct d3d9 *d3d9 = impl_from_IDirect3D9Ex(iface);
78 ULONG refcount = InterlockedIncrement(&d3d9->refcount);
79
80 TRACE("%p increasing refcount to %u.\n", iface, refcount);
81
82 return refcount;
83}
84
85static ULONG WINAPI d3d9_Release(IDirect3D9Ex *iface)
86{
87 struct d3d9 *d3d9 = impl_from_IDirect3D9Ex(iface);
88 ULONG refcount = InterlockedDecrement(&d3d9->refcount);
89
90 TRACE("%p decreasing refcount to %u.\n", iface, refcount);
91
92 if (!refcount)
93 {
94 wined3d_mutex_lock();
95 wined3d_decref(d3d9->wined3d);
96 wined3d_mutex_unlock();
97
98 HeapFree(GetProcessHeap(), 0, d3d9);
99 }
100
101 return refcount;
102}
103
104static HRESULT WINAPI d3d9_RegisterSoftwareDevice(IDirect3D9Ex *iface, void *init_function)
105{
106 struct d3d9 *d3d9 = impl_from_IDirect3D9Ex(iface);
107 HRESULT hr;
108
109 TRACE("iface %p, init_function %p.\n", iface, init_function);
110
111 wined3d_mutex_lock();
112 hr = wined3d_register_software_device(d3d9->wined3d, init_function);
113 wined3d_mutex_unlock();
114
115 return hr;
116}
117
118static UINT WINAPI d3d9_GetAdapterCount(IDirect3D9Ex *iface)
119{
120 struct d3d9 *d3d9 = impl_from_IDirect3D9Ex(iface);
121 UINT ret;
122
123 TRACE("iface %p.\n", iface);
124
125 wined3d_mutex_lock();
126 ret = wined3d_get_adapter_count(d3d9->wined3d);
127 wined3d_mutex_unlock();
128
129 return ret;
130}
131
132static HRESULT WINAPI d3d9_GetAdapterIdentifier(IDirect3D9Ex *iface, UINT adapter,
133 DWORD flags, D3DADAPTER_IDENTIFIER9 *identifier)
134{
135 struct d3d9 *d3d9 = impl_from_IDirect3D9Ex(iface);
136 struct wined3d_adapter_identifier adapter_id;
137 HRESULT hr;
138
139 TRACE("iface %p, adapter %u, flags %#x, identifier %p.\n",
140 iface, adapter, flags, identifier);
141
142 adapter_id.driver = identifier->Driver;
143 adapter_id.driver_size = sizeof(identifier->Driver);
144 adapter_id.description = identifier->Description;
145 adapter_id.description_size = sizeof(identifier->Description);
146 adapter_id.device_name = identifier->DeviceName;
147 adapter_id.device_name_size = sizeof(identifier->DeviceName);
148
149 wined3d_mutex_lock();
150 hr = wined3d_get_adapter_identifier(d3d9->wined3d, adapter, flags, &adapter_id);
151 wined3d_mutex_unlock();
152
153 identifier->DriverVersion = adapter_id.driver_version;
154 identifier->VendorId = adapter_id.vendor_id;
155 identifier->DeviceId = adapter_id.device_id;
156 identifier->SubSysId = adapter_id.subsystem_id;
157 identifier->Revision = adapter_id.revision;
158 memcpy(&identifier->DeviceIdentifier, &adapter_id.device_identifier, sizeof(identifier->DeviceIdentifier));
159 identifier->WHQLLevel = adapter_id.whql_level;
160
161 return hr;
162}
163
164static UINT WINAPI d3d9_GetAdapterModeCount(IDirect3D9Ex *iface, UINT adapter, D3DFORMAT format)
165{
166 struct d3d9 *d3d9 = impl_from_IDirect3D9Ex(iface);
167 UINT ret;
168
169 TRACE("iface %p, adapter %u, format %#x.\n", iface, adapter, format);
170
171 /* Others than that not supported by d3d9, but reported by wined3d for ddraw. Filter them out. */
172 if (format != D3DFMT_X8R8G8B8 && format != D3DFMT_R5G6B5)
173 return 0;
174
175 wined3d_mutex_lock();
176 ret = wined3d_get_adapter_mode_count(d3d9->wined3d, adapter,
177 wined3dformat_from_d3dformat(format), WINED3D_SCANLINE_ORDERING_UNKNOWN);
178 wined3d_mutex_unlock();
179
180 return ret;
181}
182
183static HRESULT WINAPI d3d9_EnumAdapterModes(IDirect3D9Ex *iface, UINT adapter,
184 D3DFORMAT format, UINT mode_idx, D3DDISPLAYMODE *mode)
185{
186 struct d3d9 *d3d9 = impl_from_IDirect3D9Ex(iface);
187 struct wined3d_display_mode wined3d_mode;
188 HRESULT hr;
189
190 TRACE("iface %p, adapter %u, format %#x, mode_idx %u, mode %p.\n",
191 iface, adapter, format, mode_idx, mode);
192
193 if (format != D3DFMT_X8R8G8B8 && format != D3DFMT_R5G6B5)
194 return D3DERR_INVALIDCALL;
195
196 wined3d_mutex_lock();
197 hr = wined3d_enum_adapter_modes(d3d9->wined3d, adapter, wined3dformat_from_d3dformat(format),
198 WINED3D_SCANLINE_ORDERING_UNKNOWN, mode_idx, &wined3d_mode);
199 wined3d_mutex_unlock();
200
201 if (SUCCEEDED(hr))
202 {
203 mode->Width = wined3d_mode.width;
204 mode->Height = wined3d_mode.height;
205 mode->RefreshRate = wined3d_mode.refresh_rate;
206 mode->Format = d3dformat_from_wined3dformat(wined3d_mode.format_id);
207 }
208
209 return hr;
210}
211
212static HRESULT WINAPI d3d9_GetAdapterDisplayMode(IDirect3D9Ex *iface, UINT adapter, D3DDISPLAYMODE *mode)
213{
214 struct d3d9 *d3d9 = impl_from_IDirect3D9Ex(iface);
215 struct wined3d_display_mode wined3d_mode;
216 HRESULT hr;
217
218 TRACE("iface %p, adapter %u, mode %p.\n", iface, adapter, mode);
219
220 wined3d_mutex_lock();
221 hr = wined3d_get_adapter_display_mode(d3d9->wined3d, adapter, &wined3d_mode, NULL);
222 wined3d_mutex_unlock();
223
224 if (SUCCEEDED(hr))
225 {
226 mode->Width = wined3d_mode.width;
227 mode->Height = wined3d_mode.height;
228 mode->RefreshRate = wined3d_mode.refresh_rate;
229 mode->Format = d3dformat_from_wined3dformat(wined3d_mode.format_id);
230 }
231
232 return hr;
233}
234
235static HRESULT WINAPI d3d9_CheckDeviceType(IDirect3D9Ex *iface, UINT adapter, D3DDEVTYPE device_type,
236 D3DFORMAT display_format, D3DFORMAT backbuffer_format, BOOL windowed)
237{
238 struct d3d9 *d3d9 = impl_from_IDirect3D9Ex(iface);
239 HRESULT hr;
240
241 TRACE("iface %p, adapter %u, device_type %#x, display_format %#x, backbuffer_format %#x, windowed %#x.\n",
242 iface, adapter, device_type, display_format, backbuffer_format, windowed);
243
244 wined3d_mutex_lock();
245 hr = wined3d_check_device_type(d3d9->wined3d, adapter, device_type, wined3dformat_from_d3dformat(display_format),
246 wined3dformat_from_d3dformat(backbuffer_format), windowed);
247 wined3d_mutex_unlock();
248
249 return hr;
250}
251
252static HRESULT WINAPI d3d9_CheckDeviceFormat(IDirect3D9Ex *iface, UINT adapter, D3DDEVTYPE device_type,
253 D3DFORMAT adapter_format, DWORD usage, D3DRESOURCETYPE resource_type, D3DFORMAT format)
254{
255 struct d3d9 *d3d9 = impl_from_IDirect3D9Ex(iface);
256 enum wined3d_resource_type wined3d_rtype;
257 HRESULT hr;
258
259 TRACE("iface %p, adapter %u, device_type %#x, adapter_format %#x, usage %#x, resource_type %#x, format %#x.\n",
260 iface, adapter, device_type, adapter_format, usage, resource_type, format);
261
262 switch (resource_type)
263 {
264 case D3DRTYPE_VERTEXBUFFER:
265 case D3DRTYPE_INDEXBUFFER:
266 wined3d_rtype = WINED3D_RTYPE_BUFFER;
267 break;
268
269 default:
270 wined3d_rtype = resource_type;
271 break;
272 }
273
274 wined3d_mutex_lock();
275 hr = wined3d_check_device_format(d3d9->wined3d, adapter, device_type, wined3dformat_from_d3dformat(adapter_format),
276 usage, wined3d_rtype, wined3dformat_from_d3dformat(format));
277 wined3d_mutex_unlock();
278
279 return hr;
280}
281
282static HRESULT WINAPI d3d9_CheckDeviceMultiSampleType(IDirect3D9Ex *iface, UINT adapter, D3DDEVTYPE device_type,
283 D3DFORMAT format, BOOL windowed, D3DMULTISAMPLE_TYPE multisample_type, DWORD *levels)
284{
285 struct d3d9 *d3d9 = impl_from_IDirect3D9Ex(iface);
286 HRESULT hr;
287
288 TRACE("iface %p, adapter %u, device_type %#x, format %#x, windowed %#x, multisample_type %#x, levels %p.\n",
289 iface, adapter, device_type, format, windowed, multisample_type, levels);
290
291 wined3d_mutex_lock();
292 hr = wined3d_check_device_multisample_type(d3d9->wined3d, adapter, device_type,
293 wined3dformat_from_d3dformat(format), windowed, multisample_type, levels);
294 wined3d_mutex_unlock();
295
296 return hr;
297}
298
299static HRESULT WINAPI d3d9_CheckDepthStencilMatch(IDirect3D9Ex *iface, UINT adapter, D3DDEVTYPE device_type,
300 D3DFORMAT adapter_format, D3DFORMAT rt_format, D3DFORMAT ds_format)
301{
302 struct d3d9 *d3d9 = impl_from_IDirect3D9Ex(iface);
303 HRESULT hr;
304
305 TRACE("iface %p, adapter %u, device_type %#x, adapter_format %#x, rt_format %#x, ds_format %#x.\n",
306 iface, adapter, device_type, adapter_format, rt_format, ds_format);
307
308 wined3d_mutex_lock();
309 hr = wined3d_check_depth_stencil_match(d3d9->wined3d, adapter, device_type,
310 wined3dformat_from_d3dformat(adapter_format), wined3dformat_from_d3dformat(rt_format),
311 wined3dformat_from_d3dformat(ds_format));
312 wined3d_mutex_unlock();
313
314 return hr;
315}
316
317static HRESULT WINAPI d3d9_CheckDeviceFormatConversion(IDirect3D9Ex *iface, UINT adapter,
318 D3DDEVTYPE device_type, D3DFORMAT src_format, D3DFORMAT dst_format)
319{
320 struct d3d9 *d3d9 = impl_from_IDirect3D9Ex(iface);
321 HRESULT hr;
322
323 TRACE("iface %p, adapter %u, device_type %#x, src_format %#x, dst_format %#x.\n",
324 iface, adapter, device_type, src_format, dst_format);
325
326 wined3d_mutex_lock();
327 hr = wined3d_check_device_format_conversion(d3d9->wined3d, adapter, device_type,
328 wined3dformat_from_d3dformat(src_format), wined3dformat_from_d3dformat(dst_format));
329 wined3d_mutex_unlock();
330
331 return hr;
332}
333
334void filter_caps(D3DCAPS9* pCaps)
335{
336 DWORD ps_minor_version[] = {0, 4, 0, 0};
337 DWORD vs_minor_version[] = {0, 1, 0, 0};
338 DWORD textureFilterCaps =
339 D3DPTFILTERCAPS_MINFPOINT | D3DPTFILTERCAPS_MINFLINEAR | D3DPTFILTERCAPS_MINFANISOTROPIC |
340 D3DPTFILTERCAPS_MINFPYRAMIDALQUAD | D3DPTFILTERCAPS_MINFGAUSSIANQUAD|
341 D3DPTFILTERCAPS_MIPFPOINT | D3DPTFILTERCAPS_MIPFLINEAR | D3DPTFILTERCAPS_MAGFPOINT |
342 D3DPTFILTERCAPS_MAGFLINEAR |D3DPTFILTERCAPS_MAGFANISOTROPIC|D3DPTFILTERCAPS_MAGFPYRAMIDALQUAD|
343 D3DPTFILTERCAPS_MAGFGAUSSIANQUAD;
344 pCaps->TextureFilterCaps &= textureFilterCaps;
345 pCaps->CubeTextureFilterCaps &= textureFilterCaps;
346 pCaps->VolumeTextureFilterCaps &= textureFilterCaps;
347
348 pCaps->DevCaps &=
349 D3DDEVCAPS_EXECUTESYSTEMMEMORY | D3DDEVCAPS_EXECUTEVIDEOMEMORY | D3DDEVCAPS_TLVERTEXSYSTEMMEMORY |
350 D3DDEVCAPS_TLVERTEXVIDEOMEMORY | D3DDEVCAPS_TEXTURESYSTEMMEMORY| D3DDEVCAPS_TEXTUREVIDEOMEMORY |
351 D3DDEVCAPS_DRAWPRIMTLVERTEX | D3DDEVCAPS_CANRENDERAFTERFLIP | D3DDEVCAPS_TEXTURENONLOCALVIDMEM|
352 D3DDEVCAPS_DRAWPRIMITIVES2 | D3DDEVCAPS_SEPARATETEXTUREMEMORIES |
353 D3DDEVCAPS_DRAWPRIMITIVES2EX | D3DDEVCAPS_HWTRANSFORMANDLIGHT| D3DDEVCAPS_CANBLTSYSTONONLOCAL |
354 D3DDEVCAPS_HWRASTERIZATION | D3DDEVCAPS_PUREDEVICE | D3DDEVCAPS_QUINTICRTPATCHES |
355 D3DDEVCAPS_RTPATCHES | D3DDEVCAPS_RTPATCHHANDLEZERO | D3DDEVCAPS_NPATCHES;
356
357 pCaps->ShadeCaps &=
358 D3DPSHADECAPS_COLORGOURAUDRGB | D3DPSHADECAPS_SPECULARGOURAUDRGB |
359 D3DPSHADECAPS_ALPHAGOURAUDBLEND | D3DPSHADECAPS_FOGGOURAUD;
360
361 pCaps->RasterCaps &=
362 D3DPRASTERCAPS_DITHER | D3DPRASTERCAPS_ZTEST | D3DPRASTERCAPS_FOGVERTEX |
363 D3DPRASTERCAPS_FOGTABLE | D3DPRASTERCAPS_MIPMAPLODBIAS | D3DPRASTERCAPS_ZBUFFERLESSHSR |
364 D3DPRASTERCAPS_FOGRANGE | D3DPRASTERCAPS_ANISOTROPY | D3DPRASTERCAPS_WBUFFER |
365 D3DPRASTERCAPS_WFOG | D3DPRASTERCAPS_ZFOG | D3DPRASTERCAPS_COLORPERSPECTIVE |
366 D3DPRASTERCAPS_SCISSORTEST | D3DPRASTERCAPS_SLOPESCALEDEPTHBIAS |
367 D3DPRASTERCAPS_DEPTHBIAS | D3DPRASTERCAPS_MULTISAMPLE_TOGGLE;
368
369 pCaps->DevCaps2 &=
370 D3DDEVCAPS2_STREAMOFFSET | D3DDEVCAPS2_DMAPNPATCH | D3DDEVCAPS2_ADAPTIVETESSRTPATCH |
371 D3DDEVCAPS2_ADAPTIVETESSNPATCH | D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES |
372 D3DDEVCAPS2_PRESAMPLEDDMAPNPATCH| D3DDEVCAPS2_VERTEXELEMENTSCANSHARESTREAMOFFSET;
373
374 pCaps->Caps2 &=
375 D3DCAPS2_FULLSCREENGAMMA | D3DCAPS2_CANCALIBRATEGAMMA | D3DCAPS2_RESERVED |
376 D3DCAPS2_CANMANAGERESOURCE | D3DCAPS2_DYNAMICTEXTURES | D3DCAPS2_CANAUTOGENMIPMAP;
377
378 pCaps->VertexProcessingCaps &=
379 D3DVTXPCAPS_TEXGEN | D3DVTXPCAPS_MATERIALSOURCE7 | D3DVTXPCAPS_DIRECTIONALLIGHTS |
380 D3DVTXPCAPS_POSITIONALLIGHTS | D3DVTXPCAPS_LOCALVIEWER | D3DVTXPCAPS_TWEENING |
381 D3DVTXPCAPS_TEXGEN_SPHEREMAP | D3DVTXPCAPS_NO_TEXGEN_NONLOCALVIEWER;
382
383 pCaps->TextureCaps &=
384 D3DPTEXTURECAPS_PERSPECTIVE | D3DPTEXTURECAPS_POW2 | D3DPTEXTURECAPS_ALPHA |
385 D3DPTEXTURECAPS_SQUAREONLY | D3DPTEXTURECAPS_TEXREPEATNOTSCALEDBYSIZE |
386 D3DPTEXTURECAPS_ALPHAPALETTE | D3DPTEXTURECAPS_NONPOW2CONDITIONAL |
387 D3DPTEXTURECAPS_PROJECTED | D3DPTEXTURECAPS_CUBEMAP | D3DPTEXTURECAPS_VOLUMEMAP |
388 D3DPTEXTURECAPS_MIPMAP | D3DPTEXTURECAPS_MIPVOLUMEMAP | D3DPTEXTURECAPS_MIPCUBEMAP |
389 D3DPTEXTURECAPS_CUBEMAP_POW2 | D3DPTEXTURECAPS_VOLUMEMAP_POW2| D3DPTEXTURECAPS_NOPROJECTEDBUMPENV;
390
391 pCaps->MaxVertexShaderConst = min(D3D9_MAX_VERTEX_SHADER_CONSTANTF, pCaps->MaxVertexShaderConst);
392 pCaps->NumSimultaneousRTs = min(D3D9_MAX_SIMULTANEOUS_RENDERTARGETS, pCaps->NumSimultaneousRTs);
393
394 if (pCaps->PixelShaderVersion > 3)
395 pCaps->PixelShaderVersion = D3DPS_VERSION(3,0);
396 else
397 {
398 DWORD major = pCaps->PixelShaderVersion;
399 pCaps->PixelShaderVersion = D3DPS_VERSION(major,ps_minor_version[major]);
400 }
401
402 if (pCaps->VertexShaderVersion > 3)
403 pCaps->VertexShaderVersion = D3DVS_VERSION(3,0);
404 else
405 {
406 DWORD major = pCaps->VertexShaderVersion;
407 pCaps->VertexShaderVersion = D3DVS_VERSION(major,vs_minor_version[major]);
408 }
409}
410
411static HRESULT WINAPI d3d9_GetDeviceCaps(IDirect3D9Ex *iface, UINT adapter, D3DDEVTYPE device_type, D3DCAPS9 *caps)
412{
413 struct d3d9 *d3d9 = impl_from_IDirect3D9Ex(iface);
414 WINED3DCAPS *wined3d_caps;
415 HRESULT hr;
416
417 TRACE("iface %p, adapter %u, device_type %#x, caps %p.\n", iface, adapter, device_type, caps);
418
419 if (!caps)
420 return D3DERR_INVALIDCALL;
421
422 if (!(wined3d_caps = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WINED3DCAPS))))
423 return D3DERR_INVALIDCALL; /*well this is what MSDN says to return*/
424 memset(caps, 0, sizeof(*caps));
425
426 wined3d_mutex_lock();
427 hr = wined3d_get_device_caps(d3d9->wined3d, adapter, device_type, wined3d_caps);
428 wined3d_mutex_unlock();
429
430 WINECAPSTOD3D9CAPS(caps, wined3d_caps)
431 HeapFree(GetProcessHeap(), 0, wined3d_caps);
432
433 /* Some functionality is implemented in d3d9.dll, not wined3d.dll. Add the needed caps */
434 caps->DevCaps2 |= D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES;
435
436 filter_caps(caps);
437
438 return hr;
439}
440
441static HMONITOR WINAPI d3d9_GetAdapterMonitor(IDirect3D9Ex *iface, UINT adapter)
442{
443 struct d3d9 *d3d9 = impl_from_IDirect3D9Ex(iface);
444 HMONITOR ret;
445
446 TRACE("iface %p, adapter %u.\n", iface, adapter);
447
448 wined3d_mutex_lock();
449 ret = wined3d_get_adapter_monitor(d3d9->wined3d, adapter);
450 wined3d_mutex_unlock();
451
452 return ret;
453}
454
455static HRESULT WINAPI DECLSPEC_HOTPATCH d3d9_CreateDevice(IDirect3D9Ex *iface, UINT adapter,
456 D3DDEVTYPE device_type, HWND focus_window, DWORD flags, D3DPRESENT_PARAMETERS *parameters,
457 IDirect3DDevice9 **device)
458{
459 struct d3d9 *d3d9 = impl_from_IDirect3D9Ex(iface);
460 struct d3d9_device *object;
461 HRESULT hr;
462
463 TRACE("iface %p, adapter %u, device_type %#x, focus_window %p, flags %#x, parameters %p, device %p.\n",
464 iface, adapter, device_type, focus_window, flags, parameters, device);
465
466 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
467 if (!object)
468 return E_OUTOFMEMORY;
469
470 hr = device_init(object, d3d9, d3d9->wined3d, adapter, device_type, focus_window, flags,
471#ifdef VBOX_WITH_WDDM
472 (VBOXWINEEX_D3DPRESENT_PARAMETERS *)
473#endif
474 parameters, NULL);
475 if (FAILED(hr))
476 {
477 WARN("Failed to initialize device, hr %#x.\n", hr);
478 HeapFree(GetProcessHeap(), 0, object);
479 return hr;
480 }
481
482 TRACE("Created device %p.\n", object);
483 *device = (IDirect3DDevice9 *)object;
484
485 return D3D_OK;
486}
487
488static UINT WINAPI d3d9_GetAdapterModeCountEx(IDirect3D9Ex *iface,
489 UINT adapter, const D3DDISPLAYMODEFILTER *filter)
490{
491 struct d3d9 *d3d9 = impl_from_IDirect3D9Ex(iface);
492 UINT ret;
493
494 TRACE("iface %p, adapter %u, filter %p.\n", iface, adapter, filter);
495
496 if (filter->Format != D3DFMT_X8R8G8B8 && filter->Format != D3DFMT_R5G6B5)
497 return 0;
498
499 wined3d_mutex_lock();
500 ret = wined3d_get_adapter_mode_count(d3d9->wined3d, adapter,
501 wined3dformat_from_d3dformat(filter->Format), filter->ScanLineOrdering);
502 wined3d_mutex_unlock();
503
504 return ret;
505}
506
507static HRESULT WINAPI d3d9_EnumAdapterModesEx(IDirect3D9Ex *iface,
508 UINT adapter, const D3DDISPLAYMODEFILTER *filter, UINT mode_idx, D3DDISPLAYMODEEX *mode)
509{
510 struct d3d9 *d3d9 = impl_from_IDirect3D9Ex(iface);
511 struct wined3d_display_mode wined3d_mode;
512 HRESULT hr;
513
514 TRACE("iface %p, adapter %u, filter %p, mode_idx %u, mode %p.\n",
515 iface, adapter, filter, mode_idx, mode);
516
517 if (filter->Format != D3DFMT_X8R8G8B8 && filter->Format != D3DFMT_R5G6B5)
518 return D3DERR_INVALIDCALL;
519
520 wined3d_mutex_lock();
521 hr = wined3d_enum_adapter_modes(d3d9->wined3d, adapter, wined3dformat_from_d3dformat(filter->Format),
522 filter->ScanLineOrdering, mode_idx, &wined3d_mode);
523 wined3d_mutex_unlock();
524
525 if (SUCCEEDED(hr))
526 {
527 mode->Width = wined3d_mode.width;
528 mode->Height = wined3d_mode.height;
529 mode->RefreshRate = wined3d_mode.refresh_rate;
530 mode->Format = d3dformat_from_wined3dformat(wined3d_mode.format_id);
531 mode->ScanLineOrdering = wined3d_mode.scanline_ordering;
532 }
533
534 return hr;
535}
536
537static HRESULT WINAPI d3d9_GetAdapterDisplayModeEx(IDirect3D9Ex *iface,
538 UINT adapter, D3DDISPLAYMODEEX *mode, D3DDISPLAYROTATION *rotation)
539{
540 struct d3d9 *d3d9 = impl_from_IDirect3D9Ex(iface);
541 struct wined3d_display_mode wined3d_mode;
542 HRESULT hr;
543
544 TRACE("iface %p, adapter %u, mode %p, rotation %p.\n",
545 iface, adapter, mode, rotation);
546
547 if (mode->Size != sizeof(*mode))
548 return D3DERR_INVALIDCALL;
549
550 wined3d_mutex_lock();
551 hr = wined3d_get_adapter_display_mode(d3d9->wined3d, adapter, &wined3d_mode,
552 (enum wined3d_display_rotation *)rotation);
553 wined3d_mutex_unlock();
554
555 if (SUCCEEDED(hr))
556 {
557 mode->Width = wined3d_mode.width;
558 mode->Height = wined3d_mode.height;
559 mode->RefreshRate = wined3d_mode.refresh_rate;
560 mode->Format = d3dformat_from_wined3dformat(wined3d_mode.format_id);
561 mode->ScanLineOrdering = wined3d_mode.scanline_ordering;
562 }
563
564 return hr;
565}
566
567static HRESULT WINAPI DECLSPEC_HOTPATCH d3d9_CreateDeviceEx(IDirect3D9Ex *iface,
568 UINT adapter, D3DDEVTYPE device_type, HWND focus_window, DWORD flags,
569 D3DPRESENT_PARAMETERS *parameters, D3DDISPLAYMODEEX *mode, IDirect3DDevice9Ex **device)
570{
571 struct d3d9 *d3d9 = impl_from_IDirect3D9Ex(iface);
572 struct d3d9_device *object;
573 HRESULT hr;
574
575 TRACE("iface %p, adapter %u, device_type %#x, focus_window %p, flags %#x, parameters %p, mode %p, device %p.\n",
576 iface, adapter, device_type, focus_window, flags, parameters, mode, device);
577
578 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
579 if (!object)
580 return E_OUTOFMEMORY;
581
582 hr = device_init(object, d3d9, d3d9->wined3d, adapter, device_type, focus_window, flags,
583#ifdef VBOX_WITH_WDDM
584 (VBOXWINEEX_D3DPRESENT_PARAMETERS *)
585#endif
586 parameters, mode);
587 if (FAILED(hr))
588 {
589 WARN("Failed to initialize device, hr %#x.\n", hr);
590 HeapFree(GetProcessHeap(), 0, object);
591 return hr;
592 }
593
594 TRACE("Created device %p.\n", object);
595 *device = &object->IDirect3DDevice9Ex_iface;
596
597 return D3D_OK;
598}
599
600static HRESULT WINAPI d3d9_GetAdapterLUID(IDirect3D9Ex *iface, UINT adapter, LUID *luid)
601{
602 struct d3d9 *d3d9 = impl_from_IDirect3D9Ex(iface);
603 struct wined3d_adapter_identifier adapter_id;
604 HRESULT hr;
605
606 TRACE("iface %p, adapter %u, luid %p.\n", iface, adapter, luid);
607
608 adapter_id.driver_size = 0;
609 adapter_id.description_size = 0;
610 adapter_id.device_name_size = 0;
611
612 wined3d_mutex_lock();
613 hr = wined3d_get_adapter_identifier(d3d9->wined3d, adapter, 0, &adapter_id);
614 wined3d_mutex_unlock();
615
616 memcpy(luid, &adapter_id.adapter_luid, sizeof(*luid));
617
618 return hr;
619}
620
621static const struct IDirect3D9ExVtbl d3d9_vtbl =
622{
623 /* IUnknown */
624 d3d9_QueryInterface,
625 d3d9_AddRef,
626 d3d9_Release,
627 /* IDirect3D9 */
628 d3d9_RegisterSoftwareDevice,
629 d3d9_GetAdapterCount,
630 d3d9_GetAdapterIdentifier,
631 d3d9_GetAdapterModeCount,
632 d3d9_EnumAdapterModes,
633 d3d9_GetAdapterDisplayMode,
634 d3d9_CheckDeviceType,
635 d3d9_CheckDeviceFormat,
636 d3d9_CheckDeviceMultiSampleType,
637 d3d9_CheckDepthStencilMatch,
638 d3d9_CheckDeviceFormatConversion,
639 d3d9_GetDeviceCaps,
640 d3d9_GetAdapterMonitor,
641 d3d9_CreateDevice,
642 /* IDirect3D9Ex */
643 d3d9_GetAdapterModeCountEx,
644 d3d9_EnumAdapterModesEx,
645 d3d9_GetAdapterDisplayModeEx,
646 d3d9_CreateDeviceEx,
647 d3d9_GetAdapterLUID,
648};
649
650BOOL d3d9_init(struct d3d9 *d3d9, BOOL extended)
651{
652 DWORD flags = extended ? 0 : WINED3D_VIDMEM_ACCOUNTING;
653 d3d9->IDirect3D9Ex_iface.lpVtbl = &d3d9_vtbl;
654 d3d9->refcount = 1;
655
656 wined3d_mutex_lock();
657 d3d9->wined3d = wined3d_create(9, flags);
658 wined3d_mutex_unlock();
659 if (!d3d9->wined3d)
660 return FALSE;
661 d3d9->extended = extended;
662
663 return TRUE;
664}
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