ntdll/tests: Make sure a return value is used (LLVM/Clang).
[wine.git] / dlls / d3d9 / directx.c
blob91524bb0baf1008d20c38146b7ee246d1f3c1d57
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 /* IDirect3D9 IUnknown parts follow: */
28 static HRESULT WINAPI IDirect3D9Impl_QueryInterface(LPDIRECT3D9EX iface, REFIID riid, LPVOID* ppobj)
30 IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
32 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
34 if (IsEqualGUID(riid, &IID_IUnknown)
35 || IsEqualGUID(riid, &IID_IDirect3D9)) {
36 IDirect3D9Ex_AddRef(iface);
37 *ppobj = This;
38 TRACE("Returning IDirect3D9 interface at %p\n", *ppobj);
39 return S_OK;
40 } else if(IsEqualGUID(riid, &IID_IDirect3D9Ex)) {
41 if(This->extended) {
42 *ppobj = This;
43 TRACE("Returning IDirect3D9Ex interface at %p\n", *ppobj);
44 IDirect3D9Ex_AddRef((IDirect3D9Ex *)*ppobj);
45 } else {
46 WARN("Application asks for IDirect3D9Ex, but this instance wasn't created with Direct3DCreate9Ex\n");
47 WARN("Returning E_NOINTERFACE\n");
48 *ppobj = NULL;
49 return E_NOINTERFACE;
53 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
54 *ppobj = NULL;
55 return E_NOINTERFACE;
58 static ULONG WINAPI IDirect3D9Impl_AddRef(LPDIRECT3D9EX iface) {
59 IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
60 ULONG ref = InterlockedIncrement(&This->ref);
62 TRACE("%p increasing refcount to %u.\n", iface, ref);
64 return ref;
67 static ULONG WINAPI IDirect3D9Impl_Release(LPDIRECT3D9EX iface) {
68 IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
69 ULONG ref = InterlockedDecrement(&This->ref);
71 TRACE("%p decreasing refcount to %u.\n", iface, ref);
73 if (ref == 0) {
74 wined3d_mutex_lock();
75 wined3d_decref(This->WineD3D);
76 wined3d_mutex_unlock();
78 HeapFree(GetProcessHeap(), 0, This);
81 return ref;
84 /* IDirect3D9 Interface follow: */
85 static HRESULT WINAPI IDirect3D9Impl_RegisterSoftwareDevice(LPDIRECT3D9EX iface, void* pInitializeFunction) {
86 IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
87 HRESULT hr;
89 TRACE("iface %p, init_function %p.\n", iface, pInitializeFunction);
91 wined3d_mutex_lock();
92 hr = wined3d_register_software_device(This->WineD3D, pInitializeFunction);
93 wined3d_mutex_unlock();
95 return hr;
98 static UINT WINAPI IDirect3D9Impl_GetAdapterCount(LPDIRECT3D9EX iface) {
99 IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
100 HRESULT hr;
102 TRACE("iface %p.\n", iface);
104 wined3d_mutex_lock();
105 hr = wined3d_get_adapter_count(This->WineD3D);
106 wined3d_mutex_unlock();
108 return hr;
111 static HRESULT WINAPI IDirect3D9Impl_GetAdapterIdentifier(LPDIRECT3D9EX iface, UINT Adapter, DWORD Flags, D3DADAPTER_IDENTIFIER9* pIdentifier) {
112 IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
113 WINED3DADAPTER_IDENTIFIER adapter_id;
114 HRESULT hr;
116 TRACE("iface %p, adapter %u, flags %#x, identifier %p.\n",
117 iface, Adapter, Flags, pIdentifier);
119 adapter_id.driver = pIdentifier->Driver;
120 adapter_id.driver_size = sizeof(pIdentifier->Driver);
121 adapter_id.description = pIdentifier->Description;
122 adapter_id.description_size = sizeof(pIdentifier->Description);
123 adapter_id.device_name = pIdentifier->DeviceName;
124 adapter_id.device_name_size = sizeof(pIdentifier->DeviceName);
126 wined3d_mutex_lock();
127 hr = wined3d_get_adapter_identifier(This->WineD3D, Adapter, Flags, &adapter_id);
128 wined3d_mutex_unlock();
130 pIdentifier->DriverVersion = adapter_id.driver_version;
131 pIdentifier->VendorId = adapter_id.vendor_id;
132 pIdentifier->DeviceId = adapter_id.device_id;
133 pIdentifier->SubSysId = adapter_id.subsystem_id;
134 pIdentifier->Revision = adapter_id.revision;
135 memcpy(&pIdentifier->DeviceIdentifier, &adapter_id.device_identifier, sizeof(pIdentifier->DeviceIdentifier));
136 pIdentifier->WHQLLevel = adapter_id.whql_level;
138 return hr;
141 static UINT WINAPI IDirect3D9Impl_GetAdapterModeCount(LPDIRECT3D9EX iface, UINT Adapter, D3DFORMAT Format) {
142 IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
143 HRESULT hr;
145 TRACE("iface %p, adapter %u, format %#x.\n", iface, Adapter, Format);
147 /* Others than that not supported by d3d9, but reported by wined3d for ddraw. Filter them out */
148 if(Format != D3DFMT_X8R8G8B8 && Format != D3DFMT_R5G6B5) {
149 return 0;
152 wined3d_mutex_lock();
153 hr = wined3d_get_adapter_mode_count(This->WineD3D, Adapter, wined3dformat_from_d3dformat(Format));
154 wined3d_mutex_unlock();
156 return hr;
159 static HRESULT WINAPI IDirect3D9Impl_EnumAdapterModes(LPDIRECT3D9EX iface, UINT Adapter, D3DFORMAT Format, UINT Mode, D3DDISPLAYMODE* pMode) {
160 IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
161 HRESULT hr;
163 TRACE("iface %p, adapter %u, format %#x, mode_idx %u, mode %p.\n",
164 iface, Adapter, Format, Mode, pMode);
166 /* We can't pass this to WineD3D, otherwise it'll think it came from D3D8 or DDraw.
167 It's supposed to fail anyway, so no harm returning failure. */
168 if(Format != D3DFMT_X8R8G8B8 && Format != D3DFMT_R5G6B5)
169 return D3DERR_INVALIDCALL;
171 wined3d_mutex_lock();
172 hr = wined3d_enum_adapter_modes(This->WineD3D, Adapter, wined3dformat_from_d3dformat(Format),
173 Mode, (WINED3DDISPLAYMODE *) pMode);
174 wined3d_mutex_unlock();
176 if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format);
178 return hr;
181 static HRESULT WINAPI IDirect3D9Impl_GetAdapterDisplayMode(LPDIRECT3D9EX iface, UINT Adapter, D3DDISPLAYMODE* pMode) {
182 IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
183 HRESULT hr;
185 TRACE("iface %p, adapter %u, mode %p.\n", iface, Adapter, pMode);
187 wined3d_mutex_lock();
188 hr = wined3d_get_adapter_display_mode(This->WineD3D, Adapter, (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_CheckDeviceType(IDirect3D9Ex *iface, UINT Adapter,
197 D3DDEVTYPE CheckType, D3DFORMAT DisplayFormat, D3DFORMAT BackBufferFormat, BOOL Windowed)
199 IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
200 HRESULT hr;
202 TRACE("iface %p, adapter %u, device_type %#x, display_format %#x, backbuffer_format %#x, windowed %#x.\n",
203 iface, Adapter, CheckType, DisplayFormat, BackBufferFormat, Windowed);
205 wined3d_mutex_lock();
206 hr = wined3d_check_device_type(This->WineD3D, Adapter, CheckType, wined3dformat_from_d3dformat(DisplayFormat),
207 wined3dformat_from_d3dformat(BackBufferFormat), Windowed);
208 wined3d_mutex_unlock();
210 return hr;
213 static HRESULT WINAPI IDirect3D9Impl_CheckDeviceFormat(IDirect3D9Ex *iface, UINT Adapter, D3DDEVTYPE DeviceType,
214 D3DFORMAT AdapterFormat, DWORD Usage, D3DRESOURCETYPE RType, D3DFORMAT CheckFormat)
216 IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
217 HRESULT hr;
218 WINED3DRESOURCETYPE WineD3DRType;
220 TRACE("iface %p, adapter %u, device_type %#x, adapter_format %#x, usage %#x, resource_type %#x, format %#x.\n",
221 iface, Adapter, DeviceType, AdapterFormat, Usage, RType, CheckFormat);
223 /* This format is nothing special and it is supported perfectly.
224 * However, ati and nvidia driver on windows do not mark this format as
225 * supported (tested with the dxCapsViewer) and pretending to
226 * support this format uncovers a bug in Battlefield 1942 (fonts are missing)
227 * So do the same as Windows drivers and pretend not to support it on dx8 and 9
229 if(CheckFormat == D3DFMT_R8G8B8)
231 WARN("D3DFMT_R8G8B8 is not available on windows, returning D3DERR_NOTAVAILABLE\n");
232 return D3DERR_NOTAVAILABLE;
235 switch(RType) {
236 case D3DRTYPE_VERTEXBUFFER:
237 case D3DRTYPE_INDEXBUFFER:
238 WineD3DRType = WINED3DRTYPE_BUFFER;
239 break;
241 default:
242 WineD3DRType = RType;
243 break;
246 wined3d_mutex_lock();
247 hr = wined3d_check_device_format(This->WineD3D, Adapter, DeviceType, wined3dformat_from_d3dformat(AdapterFormat),
248 Usage, WineD3DRType, wined3dformat_from_d3dformat(CheckFormat), SURFACE_OPENGL);
249 wined3d_mutex_unlock();
251 return hr;
254 static HRESULT WINAPI IDirect3D9Impl_CheckDeviceMultiSampleType(IDirect3D9Ex *iface, UINT Adapter,
255 D3DDEVTYPE DeviceType, D3DFORMAT SurfaceFormat, BOOL Windowed, D3DMULTISAMPLE_TYPE MultiSampleType,
256 DWORD *pQualityLevels)
258 IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
259 HRESULT hr;
261 TRACE("iface %p, adapter %u, device_type %#x, format %#x, windowed %#x, multisample_type %#x, levels %p.\n",
262 iface, Adapter, DeviceType, SurfaceFormat, Windowed, MultiSampleType, pQualityLevels);
264 wined3d_mutex_lock();
265 hr = wined3d_check_device_multisample_type(This->WineD3D, Adapter, DeviceType,
266 wined3dformat_from_d3dformat(SurfaceFormat), Windowed, MultiSampleType, pQualityLevels);
267 wined3d_mutex_unlock();
269 return hr;
272 static HRESULT WINAPI IDirect3D9Impl_CheckDepthStencilMatch(IDirect3D9Ex *iface, UINT Adapter,
273 D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat, D3DFORMAT RenderTargetFormat, D3DFORMAT DepthStencilFormat)
275 IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
276 HRESULT hr;
278 TRACE("iface %p, adapter %u, device_type %#x, adapter_format %#x, rt_format %#x, ds_format %#x.\n",
279 iface, Adapter, DeviceType, AdapterFormat, RenderTargetFormat, DepthStencilFormat);
281 wined3d_mutex_lock();
282 hr = wined3d_check_depth_stencil_match(This->WineD3D, Adapter, DeviceType,
283 wined3dformat_from_d3dformat(AdapterFormat), wined3dformat_from_d3dformat(RenderTargetFormat),
284 wined3dformat_from_d3dformat(DepthStencilFormat));
285 wined3d_mutex_unlock();
287 return hr;
290 static HRESULT WINAPI IDirect3D9Impl_CheckDeviceFormatConversion(LPDIRECT3D9EX iface, UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT SourceFormat, D3DFORMAT TargetFormat) {
291 IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
292 HRESULT hr;
294 TRACE("iface %p, adapter %u, device_type %#x, src_format %#x, dst_format %#x.\n",
295 iface, Adapter, DeviceType, SourceFormat, TargetFormat);
297 wined3d_mutex_lock();
298 hr = wined3d_check_device_format_conversion(This->WineD3D, Adapter, DeviceType,
299 wined3dformat_from_d3dformat(SourceFormat), wined3dformat_from_d3dformat(TargetFormat));
300 wined3d_mutex_unlock();
302 return hr;
305 void filter_caps(D3DCAPS9* pCaps)
308 DWORD textureFilterCaps =
309 D3DPTFILTERCAPS_MINFPOINT | D3DPTFILTERCAPS_MINFLINEAR | D3DPTFILTERCAPS_MINFANISOTROPIC |
310 D3DPTFILTERCAPS_MINFPYRAMIDALQUAD | D3DPTFILTERCAPS_MINFGAUSSIANQUAD|
311 D3DPTFILTERCAPS_MIPFPOINT | D3DPTFILTERCAPS_MIPFLINEAR | D3DPTFILTERCAPS_MAGFPOINT |
312 D3DPTFILTERCAPS_MAGFLINEAR |D3DPTFILTERCAPS_MAGFANISOTROPIC|D3DPTFILTERCAPS_MAGFPYRAMIDALQUAD|
313 D3DPTFILTERCAPS_MAGFGAUSSIANQUAD;
314 pCaps->TextureFilterCaps &= textureFilterCaps;
315 pCaps->CubeTextureFilterCaps &= textureFilterCaps;
316 pCaps->VolumeTextureFilterCaps &= textureFilterCaps;
318 pCaps->DevCaps &=
319 D3DDEVCAPS_EXECUTESYSTEMMEMORY | D3DDEVCAPS_EXECUTEVIDEOMEMORY | D3DDEVCAPS_TLVERTEXSYSTEMMEMORY |
320 D3DDEVCAPS_TLVERTEXVIDEOMEMORY | D3DDEVCAPS_TEXTURESYSTEMMEMORY| D3DDEVCAPS_TEXTUREVIDEOMEMORY |
321 D3DDEVCAPS_DRAWPRIMTLVERTEX | D3DDEVCAPS_CANRENDERAFTERFLIP | D3DDEVCAPS_TEXTURENONLOCALVIDMEM|
322 D3DDEVCAPS_DRAWPRIMITIVES2 | D3DDEVCAPS_SEPARATETEXTUREMEMORIES |
323 D3DDEVCAPS_DRAWPRIMITIVES2EX | D3DDEVCAPS_HWTRANSFORMANDLIGHT| D3DDEVCAPS_CANBLTSYSTONONLOCAL |
324 D3DDEVCAPS_HWRASTERIZATION | D3DDEVCAPS_PUREDEVICE | D3DDEVCAPS_QUINTICRTPATCHES |
325 D3DDEVCAPS_RTPATCHES | D3DDEVCAPS_RTPATCHHANDLEZERO | D3DDEVCAPS_NPATCHES;
327 pCaps->ShadeCaps &=
328 D3DPSHADECAPS_COLORGOURAUDRGB | D3DPSHADECAPS_SPECULARGOURAUDRGB |
329 D3DPSHADECAPS_ALPHAGOURAUDBLEND | D3DPSHADECAPS_FOGGOURAUD;
331 pCaps->RasterCaps &=
332 D3DPRASTERCAPS_DITHER | D3DPRASTERCAPS_ZTEST | D3DPRASTERCAPS_FOGVERTEX |
333 D3DPRASTERCAPS_FOGTABLE | D3DPRASTERCAPS_MIPMAPLODBIAS | D3DPRASTERCAPS_ZBUFFERLESSHSR |
334 D3DPRASTERCAPS_FOGRANGE | D3DPRASTERCAPS_ANISOTROPY | D3DPRASTERCAPS_WBUFFER |
335 D3DPRASTERCAPS_WFOG | D3DPRASTERCAPS_ZFOG | D3DPRASTERCAPS_COLORPERSPECTIVE |
336 D3DPRASTERCAPS_SCISSORTEST | D3DPRASTERCAPS_SLOPESCALEDEPTHBIAS |
337 D3DPRASTERCAPS_DEPTHBIAS | D3DPRASTERCAPS_MULTISAMPLE_TOGGLE;
339 pCaps->DevCaps2 &=
340 D3DDEVCAPS2_STREAMOFFSET | D3DDEVCAPS2_DMAPNPATCH | D3DDEVCAPS2_ADAPTIVETESSRTPATCH |
341 D3DDEVCAPS2_ADAPTIVETESSNPATCH | D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES |
342 D3DDEVCAPS2_PRESAMPLEDDMAPNPATCH| D3DDEVCAPS2_VERTEXELEMENTSCANSHARESTREAMOFFSET;
344 pCaps->Caps2 &=
345 D3DCAPS2_FULLSCREENGAMMA | D3DCAPS2_CANCALIBRATEGAMMA | D3DCAPS2_RESERVED |
346 D3DCAPS2_CANMANAGERESOURCE | D3DCAPS2_DYNAMICTEXTURES | D3DCAPS2_CANAUTOGENMIPMAP;
348 pCaps->VertexProcessingCaps &=
349 D3DVTXPCAPS_TEXGEN | D3DVTXPCAPS_MATERIALSOURCE7 | D3DVTXPCAPS_DIRECTIONALLIGHTS |
350 D3DVTXPCAPS_POSITIONALLIGHTS | D3DVTXPCAPS_LOCALVIEWER | D3DVTXPCAPS_TWEENING |
351 D3DVTXPCAPS_TEXGEN_SPHEREMAP | D3DVTXPCAPS_NO_TEXGEN_NONLOCALVIEWER;
353 pCaps->TextureCaps &=
354 D3DPTEXTURECAPS_PERSPECTIVE | D3DPTEXTURECAPS_POW2 | D3DPTEXTURECAPS_ALPHA |
355 D3DPTEXTURECAPS_SQUAREONLY | D3DPTEXTURECAPS_TEXREPEATNOTSCALEDBYSIZE |
356 D3DPTEXTURECAPS_ALPHAPALETTE | D3DPTEXTURECAPS_NONPOW2CONDITIONAL |
357 D3DPTEXTURECAPS_PROJECTED | D3DPTEXTURECAPS_CUBEMAP | D3DPTEXTURECAPS_VOLUMEMAP |
358 D3DPTEXTURECAPS_MIPMAP | D3DPTEXTURECAPS_MIPVOLUMEMAP | D3DPTEXTURECAPS_MIPCUBEMAP |
359 D3DPTEXTURECAPS_CUBEMAP_POW2 | D3DPTEXTURECAPS_VOLUMEMAP_POW2| D3DPTEXTURECAPS_NOPROJECTEDBUMPENV;
361 pCaps->MaxVertexShaderConst = min(D3D9_MAX_VERTEX_SHADER_CONSTANTF, pCaps->MaxVertexShaderConst);
362 pCaps->NumSimultaneousRTs = min(D3D9_MAX_SIMULTANEOUS_RENDERTARGETS, pCaps->NumSimultaneousRTs);
365 static HRESULT WINAPI IDirect3D9Impl_GetDeviceCaps(LPDIRECT3D9EX iface, UINT Adapter, D3DDEVTYPE DeviceType, D3DCAPS9* pCaps) {
366 IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
367 HRESULT hrc = D3D_OK;
368 WINED3DCAPS *pWineCaps;
370 TRACE("iface %p, adapter %u, device_type %#x, caps %p.\n", iface, Adapter, DeviceType, pCaps);
372 if(NULL == pCaps){
373 return D3DERR_INVALIDCALL;
375 pWineCaps = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WINED3DCAPS));
376 if(pWineCaps == NULL){
377 return D3DERR_INVALIDCALL; /*well this is what MSDN says to return*/
379 memset(pCaps, 0, sizeof(*pCaps));
381 wined3d_mutex_lock();
382 hrc = wined3d_get_device_caps(This->WineD3D, Adapter, DeviceType, pWineCaps);
383 wined3d_mutex_unlock();
385 WINECAPSTOD3D9CAPS(pCaps, pWineCaps)
386 HeapFree(GetProcessHeap(), 0, pWineCaps);
388 /* Some functionality is implemented in d3d9.dll, not wined3d.dll. Add the needed caps */
389 pCaps->DevCaps2 |= D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES;
391 filter_caps(pCaps);
393 TRACE("(%p) returning %p\n", This, pCaps);
394 return hrc;
397 static HMONITOR WINAPI IDirect3D9Impl_GetAdapterMonitor(LPDIRECT3D9EX iface, UINT Adapter) {
398 IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
399 HMONITOR ret;
401 TRACE("iface %p, adapter %u.\n", iface, Adapter);
403 wined3d_mutex_lock();
404 ret = wined3d_get_adapter_monitor(This->WineD3D, Adapter);
405 wined3d_mutex_unlock();
407 return ret;
410 static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3D9Impl_CreateDevice(IDirect3D9Ex *iface, UINT adapter,
411 D3DDEVTYPE device_type, HWND focus_window, DWORD flags, D3DPRESENT_PARAMETERS *parameters,
412 IDirect3DDevice9 **device)
414 IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
415 IDirect3DDevice9Impl *object;
416 HRESULT hr;
418 TRACE("iface %p, adapter %u, device_type %#x, focus_window %p, flags %#x, parameters %p, device %p.\n",
419 iface, adapter, device_type, focus_window, flags, parameters, device);
421 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
422 if (!object)
424 ERR("Failed to allocate device memory.\n");
425 return E_OUTOFMEMORY;
428 hr = device_init(object, This->WineD3D, adapter, device_type, focus_window, flags, parameters, NULL);
429 if (FAILED(hr))
431 WARN("Failed to initialize device, hr %#x.\n", hr);
432 HeapFree(GetProcessHeap(), 0, object);
433 return hr;
436 TRACE("Created device %p.\n", object);
437 *device = (IDirect3DDevice9 *)object;
439 return D3D_OK;
442 static UINT WINAPI IDirect3D9ExImpl_GetAdapterModeCountEx(IDirect3D9Ex *iface,
443 UINT adapter, const D3DDISPLAYMODEFILTER *filter)
445 FIXME("iface %p, adapter %u, filter %p stub!\n", iface, adapter, filter);
447 return E_NOTIMPL;
450 static HRESULT WINAPI IDirect3D9ExImpl_EnumAdapterModesEx(IDirect3D9Ex *iface,
451 UINT adapter, const D3DDISPLAYMODEFILTER *filter, UINT mode_idx, D3DDISPLAYMODEEX *mode)
453 FIXME("iface %p, adapter %u, filter %p, mode_idx %u, mode %p stub!\n",
454 iface, adapter, filter, mode_idx, mode);
456 return E_NOTIMPL;
459 static HRESULT WINAPI IDirect3D9ExImpl_GetAdapterDisplayModeEx(IDirect3D9Ex *iface,
460 UINT adapter, D3DDISPLAYMODEEX *mode, D3DDISPLAYROTATION *rotation)
462 FIXME("iface %p, adapter %u, mode %p, rotation %p stub!\n",
463 iface, adapter, mode, rotation);
465 return E_NOTIMPL;
468 static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3D9ExImpl_CreateDeviceEx(IDirect3D9Ex *iface,
469 UINT adapter, D3DDEVTYPE device_type, HWND focus_window, DWORD flags,
470 D3DPRESENT_PARAMETERS *parameters, D3DDISPLAYMODEEX *mode, IDirect3DDevice9Ex **device)
472 IDirect3D9Impl *d3d9 = (IDirect3D9Impl *)iface;
473 IDirect3DDevice9Impl *object;
474 HRESULT hr;
476 TRACE("iface %p, adapter %u, device_type %#x, focus_window %p, flags %#x, parameters %p, mode %p, device %p.\n",
477 iface, adapter, device_type, focus_window, flags, parameters, mode, device);
479 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
480 if (!object)
482 ERR("Failed to allocate device memory.\n");
483 return E_OUTOFMEMORY;
486 hr = device_init(object, d3d9->WineD3D, adapter, device_type, focus_window, flags, parameters, mode);
487 if (FAILED(hr))
489 WARN("Failed to initialize device, hr %#x.\n", hr);
490 HeapFree(GetProcessHeap(), 0, object);
491 return hr;
494 TRACE("Created device %p.\n", object);
495 *device = (IDirect3DDevice9Ex *)object;
497 return D3D_OK;
500 static HRESULT WINAPI IDirect3D9ExImpl_GetAdapterLUID(IDirect3D9Ex *iface, UINT adapter, LUID *luid)
502 IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
503 WINED3DADAPTER_IDENTIFIER adapter_id;
504 HRESULT hr;
506 TRACE("iface %p, adapter %u, luid %p.\n", iface, adapter, luid);
508 adapter_id.driver_size = 0;
509 adapter_id.description_size = 0;
510 adapter_id.device_name_size = 0;
512 wined3d_mutex_lock();
513 hr = wined3d_get_adapter_identifier(This->WineD3D, adapter, 0, &adapter_id);
514 wined3d_mutex_unlock();
516 memcpy(luid, &adapter_id.adapter_luid, sizeof(*luid));
518 return hr;
522 const IDirect3D9ExVtbl Direct3D9_Vtbl =
524 /* IUnknown */
525 IDirect3D9Impl_QueryInterface,
526 IDirect3D9Impl_AddRef,
527 IDirect3D9Impl_Release,
528 /* IDirect3D9 */
529 IDirect3D9Impl_RegisterSoftwareDevice,
530 IDirect3D9Impl_GetAdapterCount,
531 IDirect3D9Impl_GetAdapterIdentifier,
532 IDirect3D9Impl_GetAdapterModeCount,
533 IDirect3D9Impl_EnumAdapterModes,
534 IDirect3D9Impl_GetAdapterDisplayMode,
535 IDirect3D9Impl_CheckDeviceType,
536 IDirect3D9Impl_CheckDeviceFormat,
537 IDirect3D9Impl_CheckDeviceMultiSampleType,
538 IDirect3D9Impl_CheckDepthStencilMatch,
539 IDirect3D9Impl_CheckDeviceFormatConversion,
540 IDirect3D9Impl_GetDeviceCaps,
541 IDirect3D9Impl_GetAdapterMonitor,
542 IDirect3D9Impl_CreateDevice,
543 /* IDirect3D9Ex */
544 IDirect3D9ExImpl_GetAdapterModeCountEx,
545 IDirect3D9ExImpl_EnumAdapterModesEx,
546 IDirect3D9ExImpl_GetAdapterDisplayModeEx,
547 IDirect3D9ExImpl_CreateDeviceEx,
548 IDirect3D9ExImpl_GetAdapterLUID