cmd: Backup echo mode before running external batch file.
[wine/multimedia.git] / dlls / d3d9 / directx.c
blob148b9b76f199d0173d25e9444dc1149a2f1354ae
1 /*
2 * IDirect3D9 implementation
4 * Copyright 2002 Jason Edmeades
5 * Copyright 2005 Oliver Stieber
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.
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.
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
22 #include "config.h"
23 #include "d3d9_private.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
27 static inline IDirect3D9Impl *impl_from_IDirect3D9Ex(IDirect3D9Ex *iface)
29 return CONTAINING_RECORD(iface, IDirect3D9Impl, IDirect3D9Ex_iface);
32 static HRESULT WINAPI IDirect3D9Impl_QueryInterface(IDirect3D9Ex *iface, REFIID riid, void **ppobj)
34 IDirect3D9Impl *This = impl_from_IDirect3D9Ex(iface);
36 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
38 if (IsEqualGUID(riid, &IID_IUnknown)
39 || IsEqualGUID(riid, &IID_IDirect3D9)) {
40 IDirect3D9Ex_AddRef(iface);
41 *ppobj = This;
42 TRACE("Returning IDirect3D9 interface at %p\n", *ppobj);
43 return S_OK;
44 } else if(IsEqualGUID(riid, &IID_IDirect3D9Ex)) {
45 if(This->extended) {
46 *ppobj = This;
47 TRACE("Returning IDirect3D9Ex interface at %p\n", *ppobj);
48 IDirect3D9Ex_AddRef((IDirect3D9Ex *)*ppobj);
49 } else {
50 WARN("Application asks for IDirect3D9Ex, but this instance wasn't created with Direct3DCreate9Ex\n");
51 WARN("Returning E_NOINTERFACE\n");
52 *ppobj = NULL;
53 return E_NOINTERFACE;
57 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
58 *ppobj = NULL;
59 return E_NOINTERFACE;
62 static ULONG WINAPI IDirect3D9Impl_AddRef(IDirect3D9Ex *iface)
64 IDirect3D9Impl *This = impl_from_IDirect3D9Ex(iface);
65 ULONG ref = InterlockedIncrement(&This->ref);
67 TRACE("%p increasing refcount to %u.\n", iface, ref);
69 return ref;
72 static ULONG WINAPI IDirect3D9Impl_Release(IDirect3D9Ex *iface)
74 IDirect3D9Impl *This = impl_from_IDirect3D9Ex(iface);
75 ULONG ref = InterlockedDecrement(&This->ref);
77 TRACE("%p decreasing refcount to %u.\n", iface, ref);
79 if (ref == 0) {
80 wined3d_mutex_lock();
81 wined3d_decref(This->WineD3D);
82 wined3d_mutex_unlock();
84 HeapFree(GetProcessHeap(), 0, This);
87 return ref;
90 /* IDirect3D9 Interface follow: */
91 static HRESULT WINAPI IDirect3D9Impl_RegisterSoftwareDevice(IDirect3D9Ex *iface,
92 void *pInitializeFunction)
94 IDirect3D9Impl *This = impl_from_IDirect3D9Ex(iface);
95 HRESULT hr;
97 TRACE("iface %p, init_function %p.\n", iface, pInitializeFunction);
99 wined3d_mutex_lock();
100 hr = wined3d_register_software_device(This->WineD3D, pInitializeFunction);
101 wined3d_mutex_unlock();
103 return hr;
106 static UINT WINAPI IDirect3D9Impl_GetAdapterCount(IDirect3D9Ex *iface)
108 IDirect3D9Impl *This = impl_from_IDirect3D9Ex(iface);
109 UINT ret;
111 TRACE("iface %p.\n", iface);
113 wined3d_mutex_lock();
114 ret = wined3d_get_adapter_count(This->WineD3D);
115 wined3d_mutex_unlock();
117 return ret;
120 static HRESULT WINAPI IDirect3D9Impl_GetAdapterIdentifier(IDirect3D9Ex *iface, UINT Adapter,
121 DWORD Flags, D3DADAPTER_IDENTIFIER9 *pIdentifier)
123 IDirect3D9Impl *This = impl_from_IDirect3D9Ex(iface);
124 WINED3DADAPTER_IDENTIFIER adapter_id;
125 HRESULT hr;
127 TRACE("iface %p, adapter %u, flags %#x, identifier %p.\n",
128 iface, Adapter, Flags, pIdentifier);
130 adapter_id.driver = pIdentifier->Driver;
131 adapter_id.driver_size = sizeof(pIdentifier->Driver);
132 adapter_id.description = pIdentifier->Description;
133 adapter_id.description_size = sizeof(pIdentifier->Description);
134 adapter_id.device_name = pIdentifier->DeviceName;
135 adapter_id.device_name_size = sizeof(pIdentifier->DeviceName);
137 wined3d_mutex_lock();
138 hr = wined3d_get_adapter_identifier(This->WineD3D, Adapter, Flags, &adapter_id);
139 wined3d_mutex_unlock();
141 pIdentifier->DriverVersion = adapter_id.driver_version;
142 pIdentifier->VendorId = adapter_id.vendor_id;
143 pIdentifier->DeviceId = adapter_id.device_id;
144 pIdentifier->SubSysId = adapter_id.subsystem_id;
145 pIdentifier->Revision = adapter_id.revision;
146 memcpy(&pIdentifier->DeviceIdentifier, &adapter_id.device_identifier, sizeof(pIdentifier->DeviceIdentifier));
147 pIdentifier->WHQLLevel = adapter_id.whql_level;
149 return hr;
152 static UINT WINAPI IDirect3D9Impl_GetAdapterModeCount(IDirect3D9Ex *iface, UINT Adapter,
153 D3DFORMAT Format)
155 IDirect3D9Impl *This = impl_from_IDirect3D9Ex(iface);
156 UINT ret;
158 TRACE("iface %p, adapter %u, format %#x.\n", iface, Adapter, Format);
160 /* Others than that not supported by d3d9, but reported by wined3d for ddraw. Filter them out */
161 if(Format != D3DFMT_X8R8G8B8 && Format != D3DFMT_R5G6B5) {
162 return 0;
165 wined3d_mutex_lock();
166 ret = wined3d_get_adapter_mode_count(This->WineD3D, Adapter, wined3dformat_from_d3dformat(Format));
167 wined3d_mutex_unlock();
169 return ret;
172 static HRESULT WINAPI IDirect3D9Impl_EnumAdapterModes(IDirect3D9Ex *iface, UINT Adapter,
173 D3DFORMAT Format, UINT Mode, D3DDISPLAYMODE *pMode)
175 IDirect3D9Impl *This = impl_from_IDirect3D9Ex(iface);
176 HRESULT hr;
178 TRACE("iface %p, adapter %u, format %#x, mode_idx %u, mode %p.\n",
179 iface, Adapter, Format, Mode, pMode);
181 /* We can't pass this to WineD3D, otherwise it'll think it came from D3D8 or DDraw.
182 It's supposed to fail anyway, so no harm returning failure. */
183 if(Format != D3DFMT_X8R8G8B8 && Format != D3DFMT_R5G6B5)
184 return D3DERR_INVALIDCALL;
186 wined3d_mutex_lock();
187 hr = wined3d_enum_adapter_modes(This->WineD3D, Adapter, wined3dformat_from_d3dformat(Format),
188 Mode, (WINED3DDISPLAYMODE *) pMode);
189 wined3d_mutex_unlock();
191 if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format);
193 return hr;
196 static HRESULT WINAPI IDirect3D9Impl_GetAdapterDisplayMode(IDirect3D9Ex *iface, UINT Adapter,
197 D3DDISPLAYMODE *pMode)
199 IDirect3D9Impl *This = impl_from_IDirect3D9Ex(iface);
200 HRESULT hr;
202 TRACE("iface %p, adapter %u, mode %p.\n", iface, Adapter, pMode);
204 wined3d_mutex_lock();
205 hr = wined3d_get_adapter_display_mode(This->WineD3D, Adapter, (WINED3DDISPLAYMODE *)pMode);
206 wined3d_mutex_unlock();
208 if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format);
210 return hr;
213 static HRESULT WINAPI IDirect3D9Impl_CheckDeviceType(IDirect3D9Ex *iface, UINT Adapter,
214 D3DDEVTYPE CheckType, D3DFORMAT DisplayFormat, D3DFORMAT BackBufferFormat, BOOL Windowed)
216 IDirect3D9Impl *This = impl_from_IDirect3D9Ex(iface);
217 HRESULT hr;
219 TRACE("iface %p, adapter %u, device_type %#x, display_format %#x, backbuffer_format %#x, windowed %#x.\n",
220 iface, Adapter, CheckType, DisplayFormat, BackBufferFormat, Windowed);
222 wined3d_mutex_lock();
223 hr = wined3d_check_device_type(This->WineD3D, Adapter, CheckType, wined3dformat_from_d3dformat(DisplayFormat),
224 wined3dformat_from_d3dformat(BackBufferFormat), Windowed);
225 wined3d_mutex_unlock();
227 return hr;
230 static HRESULT WINAPI IDirect3D9Impl_CheckDeviceFormat(IDirect3D9Ex *iface, UINT Adapter,
231 D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat, DWORD Usage, D3DRESOURCETYPE RType,
232 D3DFORMAT CheckFormat)
234 IDirect3D9Impl *This = impl_from_IDirect3D9Ex(iface);
235 HRESULT hr;
236 WINED3DRESOURCETYPE WineD3DRType;
238 TRACE("iface %p, adapter %u, device_type %#x, adapter_format %#x, usage %#x, resource_type %#x, format %#x.\n",
239 iface, Adapter, DeviceType, AdapterFormat, Usage, RType, CheckFormat);
241 /* This format is nothing special and it is supported perfectly.
242 * However, ati and nvidia driver on windows do not mark this format as
243 * supported (tested with the dxCapsViewer) and pretending to
244 * support this format uncovers a bug in Battlefield 1942 (fonts are missing)
245 * So do the same as Windows drivers and pretend not to support it on dx8 and 9
247 if(CheckFormat == D3DFMT_R8G8B8)
249 WARN("D3DFMT_R8G8B8 is not available on windows, returning D3DERR_NOTAVAILABLE\n");
250 return D3DERR_NOTAVAILABLE;
253 switch(RType) {
254 case D3DRTYPE_VERTEXBUFFER:
255 case D3DRTYPE_INDEXBUFFER:
256 WineD3DRType = WINED3DRTYPE_BUFFER;
257 break;
259 default:
260 WineD3DRType = RType;
261 break;
264 wined3d_mutex_lock();
265 hr = wined3d_check_device_format(This->WineD3D, Adapter, DeviceType, wined3dformat_from_d3dformat(AdapterFormat),
266 Usage, WineD3DRType, wined3dformat_from_d3dformat(CheckFormat), SURFACE_OPENGL);
267 wined3d_mutex_unlock();
269 return hr;
272 static HRESULT WINAPI IDirect3D9Impl_CheckDeviceMultiSampleType(IDirect3D9Ex *iface, UINT Adapter,
273 D3DDEVTYPE DeviceType, D3DFORMAT SurfaceFormat, BOOL Windowed,
274 D3DMULTISAMPLE_TYPE MultiSampleType, DWORD *pQualityLevels)
276 IDirect3D9Impl *This = impl_from_IDirect3D9Ex(iface);
277 HRESULT hr;
279 TRACE("iface %p, adapter %u, device_type %#x, format %#x, windowed %#x, multisample_type %#x, levels %p.\n",
280 iface, Adapter, DeviceType, SurfaceFormat, Windowed, MultiSampleType, pQualityLevels);
282 wined3d_mutex_lock();
283 hr = wined3d_check_device_multisample_type(This->WineD3D, Adapter, DeviceType,
284 wined3dformat_from_d3dformat(SurfaceFormat), Windowed, MultiSampleType, pQualityLevels);
285 wined3d_mutex_unlock();
287 return hr;
290 static HRESULT WINAPI IDirect3D9Impl_CheckDepthStencilMatch(IDirect3D9Ex *iface, UINT Adapter,
291 D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat, D3DFORMAT RenderTargetFormat,
292 D3DFORMAT DepthStencilFormat)
294 IDirect3D9Impl *This = impl_from_IDirect3D9Ex(iface);
295 HRESULT hr;
297 TRACE("iface %p, adapter %u, device_type %#x, adapter_format %#x, rt_format %#x, ds_format %#x.\n",
298 iface, Adapter, DeviceType, AdapterFormat, RenderTargetFormat, DepthStencilFormat);
300 wined3d_mutex_lock();
301 hr = wined3d_check_depth_stencil_match(This->WineD3D, Adapter, DeviceType,
302 wined3dformat_from_d3dformat(AdapterFormat), wined3dformat_from_d3dformat(RenderTargetFormat),
303 wined3dformat_from_d3dformat(DepthStencilFormat));
304 wined3d_mutex_unlock();
306 return hr;
309 static HRESULT WINAPI IDirect3D9Impl_CheckDeviceFormatConversion(IDirect3D9Ex *iface, UINT Adapter,
310 D3DDEVTYPE DeviceType, D3DFORMAT SourceFormat, D3DFORMAT TargetFormat)
312 IDirect3D9Impl *This = impl_from_IDirect3D9Ex(iface);
313 HRESULT hr;
315 TRACE("iface %p, adapter %u, device_type %#x, src_format %#x, dst_format %#x.\n",
316 iface, Adapter, DeviceType, SourceFormat, TargetFormat);
318 wined3d_mutex_lock();
319 hr = wined3d_check_device_format_conversion(This->WineD3D, Adapter, DeviceType,
320 wined3dformat_from_d3dformat(SourceFormat), wined3dformat_from_d3dformat(TargetFormat));
321 wined3d_mutex_unlock();
323 return hr;
326 void filter_caps(D3DCAPS9* pCaps)
329 DWORD textureFilterCaps =
330 D3DPTFILTERCAPS_MINFPOINT | D3DPTFILTERCAPS_MINFLINEAR | D3DPTFILTERCAPS_MINFANISOTROPIC |
331 D3DPTFILTERCAPS_MINFPYRAMIDALQUAD | D3DPTFILTERCAPS_MINFGAUSSIANQUAD|
332 D3DPTFILTERCAPS_MIPFPOINT | D3DPTFILTERCAPS_MIPFLINEAR | D3DPTFILTERCAPS_MAGFPOINT |
333 D3DPTFILTERCAPS_MAGFLINEAR |D3DPTFILTERCAPS_MAGFANISOTROPIC|D3DPTFILTERCAPS_MAGFPYRAMIDALQUAD|
334 D3DPTFILTERCAPS_MAGFGAUSSIANQUAD;
335 pCaps->TextureFilterCaps &= textureFilterCaps;
336 pCaps->CubeTextureFilterCaps &= textureFilterCaps;
337 pCaps->VolumeTextureFilterCaps &= textureFilterCaps;
339 pCaps->DevCaps &=
340 D3DDEVCAPS_EXECUTESYSTEMMEMORY | D3DDEVCAPS_EXECUTEVIDEOMEMORY | D3DDEVCAPS_TLVERTEXSYSTEMMEMORY |
341 D3DDEVCAPS_TLVERTEXVIDEOMEMORY | D3DDEVCAPS_TEXTURESYSTEMMEMORY| D3DDEVCAPS_TEXTUREVIDEOMEMORY |
342 D3DDEVCAPS_DRAWPRIMTLVERTEX | D3DDEVCAPS_CANRENDERAFTERFLIP | D3DDEVCAPS_TEXTURENONLOCALVIDMEM|
343 D3DDEVCAPS_DRAWPRIMITIVES2 | D3DDEVCAPS_SEPARATETEXTUREMEMORIES |
344 D3DDEVCAPS_DRAWPRIMITIVES2EX | D3DDEVCAPS_HWTRANSFORMANDLIGHT| D3DDEVCAPS_CANBLTSYSTONONLOCAL |
345 D3DDEVCAPS_HWRASTERIZATION | D3DDEVCAPS_PUREDEVICE | D3DDEVCAPS_QUINTICRTPATCHES |
346 D3DDEVCAPS_RTPATCHES | D3DDEVCAPS_RTPATCHHANDLEZERO | D3DDEVCAPS_NPATCHES;
348 pCaps->ShadeCaps &=
349 D3DPSHADECAPS_COLORGOURAUDRGB | D3DPSHADECAPS_SPECULARGOURAUDRGB |
350 D3DPSHADECAPS_ALPHAGOURAUDBLEND | D3DPSHADECAPS_FOGGOURAUD;
352 pCaps->RasterCaps &=
353 D3DPRASTERCAPS_DITHER | D3DPRASTERCAPS_ZTEST | D3DPRASTERCAPS_FOGVERTEX |
354 D3DPRASTERCAPS_FOGTABLE | D3DPRASTERCAPS_MIPMAPLODBIAS | D3DPRASTERCAPS_ZBUFFERLESSHSR |
355 D3DPRASTERCAPS_FOGRANGE | D3DPRASTERCAPS_ANISOTROPY | D3DPRASTERCAPS_WBUFFER |
356 D3DPRASTERCAPS_WFOG | D3DPRASTERCAPS_ZFOG | D3DPRASTERCAPS_COLORPERSPECTIVE |
357 D3DPRASTERCAPS_SCISSORTEST | D3DPRASTERCAPS_SLOPESCALEDEPTHBIAS |
358 D3DPRASTERCAPS_DEPTHBIAS | D3DPRASTERCAPS_MULTISAMPLE_TOGGLE;
360 pCaps->DevCaps2 &=
361 D3DDEVCAPS2_STREAMOFFSET | D3DDEVCAPS2_DMAPNPATCH | D3DDEVCAPS2_ADAPTIVETESSRTPATCH |
362 D3DDEVCAPS2_ADAPTIVETESSNPATCH | D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES |
363 D3DDEVCAPS2_PRESAMPLEDDMAPNPATCH| D3DDEVCAPS2_VERTEXELEMENTSCANSHARESTREAMOFFSET;
365 pCaps->Caps2 &=
366 D3DCAPS2_FULLSCREENGAMMA | D3DCAPS2_CANCALIBRATEGAMMA | D3DCAPS2_RESERVED |
367 D3DCAPS2_CANMANAGERESOURCE | D3DCAPS2_DYNAMICTEXTURES | D3DCAPS2_CANAUTOGENMIPMAP;
369 pCaps->VertexProcessingCaps &=
370 D3DVTXPCAPS_TEXGEN | D3DVTXPCAPS_MATERIALSOURCE7 | D3DVTXPCAPS_DIRECTIONALLIGHTS |
371 D3DVTXPCAPS_POSITIONALLIGHTS | D3DVTXPCAPS_LOCALVIEWER | D3DVTXPCAPS_TWEENING |
372 D3DVTXPCAPS_TEXGEN_SPHEREMAP | D3DVTXPCAPS_NO_TEXGEN_NONLOCALVIEWER;
374 pCaps->TextureCaps &=
375 D3DPTEXTURECAPS_PERSPECTIVE | D3DPTEXTURECAPS_POW2 | D3DPTEXTURECAPS_ALPHA |
376 D3DPTEXTURECAPS_SQUAREONLY | D3DPTEXTURECAPS_TEXREPEATNOTSCALEDBYSIZE |
377 D3DPTEXTURECAPS_ALPHAPALETTE | D3DPTEXTURECAPS_NONPOW2CONDITIONAL |
378 D3DPTEXTURECAPS_PROJECTED | D3DPTEXTURECAPS_CUBEMAP | D3DPTEXTURECAPS_VOLUMEMAP |
379 D3DPTEXTURECAPS_MIPMAP | D3DPTEXTURECAPS_MIPVOLUMEMAP | D3DPTEXTURECAPS_MIPCUBEMAP |
380 D3DPTEXTURECAPS_CUBEMAP_POW2 | D3DPTEXTURECAPS_VOLUMEMAP_POW2| D3DPTEXTURECAPS_NOPROJECTEDBUMPENV;
382 pCaps->MaxVertexShaderConst = min(D3D9_MAX_VERTEX_SHADER_CONSTANTF, pCaps->MaxVertexShaderConst);
383 pCaps->NumSimultaneousRTs = min(D3D9_MAX_SIMULTANEOUS_RENDERTARGETS, pCaps->NumSimultaneousRTs);
386 static HRESULT WINAPI IDirect3D9Impl_GetDeviceCaps(IDirect3D9Ex *iface, UINT Adapter,
387 D3DDEVTYPE DeviceType, D3DCAPS9 *pCaps)
389 IDirect3D9Impl *This = impl_from_IDirect3D9Ex(iface);
390 HRESULT hrc = D3D_OK;
391 WINED3DCAPS *pWineCaps;
393 TRACE("iface %p, adapter %u, device_type %#x, caps %p.\n", iface, Adapter, DeviceType, pCaps);
395 if(NULL == pCaps){
396 return D3DERR_INVALIDCALL;
398 pWineCaps = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WINED3DCAPS));
399 if(pWineCaps == NULL){
400 return D3DERR_INVALIDCALL; /*well this is what MSDN says to return*/
402 memset(pCaps, 0, sizeof(*pCaps));
404 wined3d_mutex_lock();
405 hrc = wined3d_get_device_caps(This->WineD3D, Adapter, DeviceType, pWineCaps);
406 wined3d_mutex_unlock();
408 WINECAPSTOD3D9CAPS(pCaps, pWineCaps)
409 HeapFree(GetProcessHeap(), 0, pWineCaps);
411 /* Some functionality is implemented in d3d9.dll, not wined3d.dll. Add the needed caps */
412 pCaps->DevCaps2 |= D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES;
414 filter_caps(pCaps);
416 TRACE("(%p) returning %p\n", This, pCaps);
417 return hrc;
420 static HMONITOR WINAPI IDirect3D9Impl_GetAdapterMonitor(IDirect3D9Ex *iface, UINT Adapter)
422 IDirect3D9Impl *This = impl_from_IDirect3D9Ex(iface);
423 HMONITOR ret;
425 TRACE("iface %p, adapter %u.\n", iface, Adapter);
427 wined3d_mutex_lock();
428 ret = wined3d_get_adapter_monitor(This->WineD3D, Adapter);
429 wined3d_mutex_unlock();
431 return ret;
434 static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3D9Impl_CreateDevice(IDirect3D9Ex *iface, UINT adapter,
435 D3DDEVTYPE device_type, HWND focus_window, DWORD flags, D3DPRESENT_PARAMETERS *parameters,
436 IDirect3DDevice9 **device)
438 IDirect3D9Impl *This = impl_from_IDirect3D9Ex(iface);
439 IDirect3DDevice9Impl *object;
440 HRESULT hr;
442 TRACE("iface %p, adapter %u, device_type %#x, focus_window %p, flags %#x, parameters %p, device %p.\n",
443 iface, adapter, device_type, focus_window, flags, parameters, device);
445 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
446 if (!object)
448 ERR("Failed to allocate device memory.\n");
449 return E_OUTOFMEMORY;
452 hr = device_init(object, This, This->WineD3D, adapter, device_type, focus_window, flags, parameters, NULL);
453 if (FAILED(hr))
455 WARN("Failed to initialize device, hr %#x.\n", hr);
456 HeapFree(GetProcessHeap(), 0, object);
457 return hr;
460 TRACE("Created device %p.\n", object);
461 *device = (IDirect3DDevice9 *)object;
463 return D3D_OK;
466 static UINT WINAPI IDirect3D9ExImpl_GetAdapterModeCountEx(IDirect3D9Ex *iface,
467 UINT adapter, const D3DDISPLAYMODEFILTER *filter)
469 FIXME("iface %p, adapter %u, filter %p stub!\n", iface, adapter, filter);
471 return 0;
474 static HRESULT WINAPI IDirect3D9ExImpl_EnumAdapterModesEx(IDirect3D9Ex *iface,
475 UINT adapter, const D3DDISPLAYMODEFILTER *filter, UINT mode_idx, D3DDISPLAYMODEEX *mode)
477 FIXME("iface %p, adapter %u, filter %p, mode_idx %u, mode %p stub!\n",
478 iface, adapter, filter, mode_idx, mode);
480 return E_NOTIMPL;
483 static HRESULT WINAPI IDirect3D9ExImpl_GetAdapterDisplayModeEx(IDirect3D9Ex *iface,
484 UINT adapter, D3DDISPLAYMODEEX *mode, D3DDISPLAYROTATION *rotation)
486 FIXME("iface %p, adapter %u, mode %p, rotation %p stub!\n",
487 iface, adapter, mode, rotation);
489 return E_NOTIMPL;
492 static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3D9ExImpl_CreateDeviceEx(IDirect3D9Ex *iface,
493 UINT adapter, D3DDEVTYPE device_type, HWND focus_window, DWORD flags,
494 D3DPRESENT_PARAMETERS *parameters, D3DDISPLAYMODEEX *mode, IDirect3DDevice9Ex **device)
496 IDirect3D9Impl *d3d9 = impl_from_IDirect3D9Ex(iface);
497 IDirect3DDevice9Impl *object;
498 HRESULT hr;
500 TRACE("iface %p, adapter %u, device_type %#x, focus_window %p, flags %#x, parameters %p, mode %p, device %p.\n",
501 iface, adapter, device_type, focus_window, flags, parameters, mode, device);
503 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
504 if (!object)
506 ERR("Failed to allocate device memory.\n");
507 return E_OUTOFMEMORY;
510 hr = device_init(object, d3d9, d3d9->WineD3D, adapter, device_type, focus_window, flags, parameters, mode);
511 if (FAILED(hr))
513 WARN("Failed to initialize device, hr %#x.\n", hr);
514 HeapFree(GetProcessHeap(), 0, object);
515 return hr;
518 TRACE("Created device %p.\n", object);
519 *device = &object->IDirect3DDevice9Ex_iface;
521 return D3D_OK;
524 static HRESULT WINAPI IDirect3D9ExImpl_GetAdapterLUID(IDirect3D9Ex *iface, UINT adapter, LUID *luid)
526 IDirect3D9Impl *This = impl_from_IDirect3D9Ex(iface);
527 WINED3DADAPTER_IDENTIFIER adapter_id;
528 HRESULT hr;
530 TRACE("iface %p, adapter %u, luid %p.\n", iface, adapter, luid);
532 adapter_id.driver_size = 0;
533 adapter_id.description_size = 0;
534 adapter_id.device_name_size = 0;
536 wined3d_mutex_lock();
537 hr = wined3d_get_adapter_identifier(This->WineD3D, adapter, 0, &adapter_id);
538 wined3d_mutex_unlock();
540 memcpy(luid, &adapter_id.adapter_luid, sizeof(*luid));
542 return hr;
546 const IDirect3D9ExVtbl Direct3D9_Vtbl =
548 /* IUnknown */
549 IDirect3D9Impl_QueryInterface,
550 IDirect3D9Impl_AddRef,
551 IDirect3D9Impl_Release,
552 /* IDirect3D9 */
553 IDirect3D9Impl_RegisterSoftwareDevice,
554 IDirect3D9Impl_GetAdapterCount,
555 IDirect3D9Impl_GetAdapterIdentifier,
556 IDirect3D9Impl_GetAdapterModeCount,
557 IDirect3D9Impl_EnumAdapterModes,
558 IDirect3D9Impl_GetAdapterDisplayMode,
559 IDirect3D9Impl_CheckDeviceType,
560 IDirect3D9Impl_CheckDeviceFormat,
561 IDirect3D9Impl_CheckDeviceMultiSampleType,
562 IDirect3D9Impl_CheckDepthStencilMatch,
563 IDirect3D9Impl_CheckDeviceFormatConversion,
564 IDirect3D9Impl_GetDeviceCaps,
565 IDirect3D9Impl_GetAdapterMonitor,
566 IDirect3D9Impl_CreateDevice,
567 /* IDirect3D9Ex */
568 IDirect3D9ExImpl_GetAdapterModeCountEx,
569 IDirect3D9ExImpl_EnumAdapterModesEx,
570 IDirect3D9ExImpl_GetAdapterDisplayModeEx,
571 IDirect3D9ExImpl_CreateDeviceEx,
572 IDirect3D9ExImpl_GetAdapterLUID