include: Move the DDE_xxx macros to dde.rh.
[wine/multimedia.git] / dlls / d3d9 / directx.c
blobb356d13b2fcb0983fa646fdac93a04aa25f16a60
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)
328 DWORD ps_minor_version[] = {0, 4, 0, 0};
329 DWORD vs_minor_version[] = {0, 1, 0, 0};
330 DWORD textureFilterCaps =
331 D3DPTFILTERCAPS_MINFPOINT | D3DPTFILTERCAPS_MINFLINEAR | D3DPTFILTERCAPS_MINFANISOTROPIC |
332 D3DPTFILTERCAPS_MINFPYRAMIDALQUAD | D3DPTFILTERCAPS_MINFGAUSSIANQUAD|
333 D3DPTFILTERCAPS_MIPFPOINT | D3DPTFILTERCAPS_MIPFLINEAR | D3DPTFILTERCAPS_MAGFPOINT |
334 D3DPTFILTERCAPS_MAGFLINEAR |D3DPTFILTERCAPS_MAGFANISOTROPIC|D3DPTFILTERCAPS_MAGFPYRAMIDALQUAD|
335 D3DPTFILTERCAPS_MAGFGAUSSIANQUAD;
336 pCaps->TextureFilterCaps &= textureFilterCaps;
337 pCaps->CubeTextureFilterCaps &= textureFilterCaps;
338 pCaps->VolumeTextureFilterCaps &= textureFilterCaps;
340 pCaps->DevCaps &=
341 D3DDEVCAPS_EXECUTESYSTEMMEMORY | D3DDEVCAPS_EXECUTEVIDEOMEMORY | D3DDEVCAPS_TLVERTEXSYSTEMMEMORY |
342 D3DDEVCAPS_TLVERTEXVIDEOMEMORY | D3DDEVCAPS_TEXTURESYSTEMMEMORY| D3DDEVCAPS_TEXTUREVIDEOMEMORY |
343 D3DDEVCAPS_DRAWPRIMTLVERTEX | D3DDEVCAPS_CANRENDERAFTERFLIP | D3DDEVCAPS_TEXTURENONLOCALVIDMEM|
344 D3DDEVCAPS_DRAWPRIMITIVES2 | D3DDEVCAPS_SEPARATETEXTUREMEMORIES |
345 D3DDEVCAPS_DRAWPRIMITIVES2EX | D3DDEVCAPS_HWTRANSFORMANDLIGHT| D3DDEVCAPS_CANBLTSYSTONONLOCAL |
346 D3DDEVCAPS_HWRASTERIZATION | D3DDEVCAPS_PUREDEVICE | D3DDEVCAPS_QUINTICRTPATCHES |
347 D3DDEVCAPS_RTPATCHES | D3DDEVCAPS_RTPATCHHANDLEZERO | D3DDEVCAPS_NPATCHES;
349 pCaps->ShadeCaps &=
350 D3DPSHADECAPS_COLORGOURAUDRGB | D3DPSHADECAPS_SPECULARGOURAUDRGB |
351 D3DPSHADECAPS_ALPHAGOURAUDBLEND | D3DPSHADECAPS_FOGGOURAUD;
353 pCaps->RasterCaps &=
354 D3DPRASTERCAPS_DITHER | D3DPRASTERCAPS_ZTEST | D3DPRASTERCAPS_FOGVERTEX |
355 D3DPRASTERCAPS_FOGTABLE | D3DPRASTERCAPS_MIPMAPLODBIAS | D3DPRASTERCAPS_ZBUFFERLESSHSR |
356 D3DPRASTERCAPS_FOGRANGE | D3DPRASTERCAPS_ANISOTROPY | D3DPRASTERCAPS_WBUFFER |
357 D3DPRASTERCAPS_WFOG | D3DPRASTERCAPS_ZFOG | D3DPRASTERCAPS_COLORPERSPECTIVE |
358 D3DPRASTERCAPS_SCISSORTEST | D3DPRASTERCAPS_SLOPESCALEDEPTHBIAS |
359 D3DPRASTERCAPS_DEPTHBIAS | D3DPRASTERCAPS_MULTISAMPLE_TOGGLE;
361 pCaps->DevCaps2 &=
362 D3DDEVCAPS2_STREAMOFFSET | D3DDEVCAPS2_DMAPNPATCH | D3DDEVCAPS2_ADAPTIVETESSRTPATCH |
363 D3DDEVCAPS2_ADAPTIVETESSNPATCH | D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES |
364 D3DDEVCAPS2_PRESAMPLEDDMAPNPATCH| D3DDEVCAPS2_VERTEXELEMENTSCANSHARESTREAMOFFSET;
366 pCaps->Caps2 &=
367 D3DCAPS2_FULLSCREENGAMMA | D3DCAPS2_CANCALIBRATEGAMMA | D3DCAPS2_RESERVED |
368 D3DCAPS2_CANMANAGERESOURCE | D3DCAPS2_DYNAMICTEXTURES | D3DCAPS2_CANAUTOGENMIPMAP;
370 pCaps->VertexProcessingCaps &=
371 D3DVTXPCAPS_TEXGEN | D3DVTXPCAPS_MATERIALSOURCE7 | D3DVTXPCAPS_DIRECTIONALLIGHTS |
372 D3DVTXPCAPS_POSITIONALLIGHTS | D3DVTXPCAPS_LOCALVIEWER | D3DVTXPCAPS_TWEENING |
373 D3DVTXPCAPS_TEXGEN_SPHEREMAP | D3DVTXPCAPS_NO_TEXGEN_NONLOCALVIEWER;
375 pCaps->TextureCaps &=
376 D3DPTEXTURECAPS_PERSPECTIVE | D3DPTEXTURECAPS_POW2 | D3DPTEXTURECAPS_ALPHA |
377 D3DPTEXTURECAPS_SQUAREONLY | D3DPTEXTURECAPS_TEXREPEATNOTSCALEDBYSIZE |
378 D3DPTEXTURECAPS_ALPHAPALETTE | D3DPTEXTURECAPS_NONPOW2CONDITIONAL |
379 D3DPTEXTURECAPS_PROJECTED | D3DPTEXTURECAPS_CUBEMAP | D3DPTEXTURECAPS_VOLUMEMAP |
380 D3DPTEXTURECAPS_MIPMAP | D3DPTEXTURECAPS_MIPVOLUMEMAP | D3DPTEXTURECAPS_MIPCUBEMAP |
381 D3DPTEXTURECAPS_CUBEMAP_POW2 | D3DPTEXTURECAPS_VOLUMEMAP_POW2| D3DPTEXTURECAPS_NOPROJECTEDBUMPENV;
383 pCaps->MaxVertexShaderConst = min(D3D9_MAX_VERTEX_SHADER_CONSTANTF, pCaps->MaxVertexShaderConst);
384 pCaps->NumSimultaneousRTs = min(D3D9_MAX_SIMULTANEOUS_RENDERTARGETS, pCaps->NumSimultaneousRTs);
386 if (pCaps->PixelShaderVersion > 3)
387 pCaps->PixelShaderVersion = D3DPS_VERSION(3,0);
388 else
390 DWORD major = pCaps->PixelShaderVersion;
391 pCaps->PixelShaderVersion = D3DPS_VERSION(major,ps_minor_version[major]);
394 if (pCaps->VertexShaderVersion > 3)
395 pCaps->VertexShaderVersion = D3DVS_VERSION(3,0);
396 else
398 DWORD major = pCaps->VertexShaderVersion;
399 pCaps->VertexShaderVersion = D3DVS_VERSION(major,vs_minor_version[major]);
403 static HRESULT WINAPI IDirect3D9Impl_GetDeviceCaps(IDirect3D9Ex *iface, UINT Adapter,
404 D3DDEVTYPE DeviceType, D3DCAPS9 *pCaps)
406 IDirect3D9Impl *This = impl_from_IDirect3D9Ex(iface);
407 HRESULT hrc = D3D_OK;
408 WINED3DCAPS *pWineCaps;
410 TRACE("iface %p, adapter %u, device_type %#x, caps %p.\n", iface, Adapter, DeviceType, pCaps);
412 if(NULL == pCaps){
413 return D3DERR_INVALIDCALL;
415 pWineCaps = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WINED3DCAPS));
416 if(pWineCaps == NULL){
417 return D3DERR_INVALIDCALL; /*well this is what MSDN says to return*/
419 memset(pCaps, 0, sizeof(*pCaps));
421 wined3d_mutex_lock();
422 hrc = wined3d_get_device_caps(This->WineD3D, Adapter, DeviceType, pWineCaps);
423 wined3d_mutex_unlock();
425 WINECAPSTOD3D9CAPS(pCaps, pWineCaps)
426 HeapFree(GetProcessHeap(), 0, pWineCaps);
428 /* Some functionality is implemented in d3d9.dll, not wined3d.dll. Add the needed caps */
429 pCaps->DevCaps2 |= D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES;
431 filter_caps(pCaps);
433 TRACE("(%p) returning %p\n", This, pCaps);
434 return hrc;
437 static HMONITOR WINAPI IDirect3D9Impl_GetAdapterMonitor(IDirect3D9Ex *iface, UINT Adapter)
439 IDirect3D9Impl *This = impl_from_IDirect3D9Ex(iface);
440 HMONITOR ret;
442 TRACE("iface %p, adapter %u.\n", iface, Adapter);
444 wined3d_mutex_lock();
445 ret = wined3d_get_adapter_monitor(This->WineD3D, Adapter);
446 wined3d_mutex_unlock();
448 return ret;
451 static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3D9Impl_CreateDevice(IDirect3D9Ex *iface, UINT adapter,
452 D3DDEVTYPE device_type, HWND focus_window, DWORD flags, D3DPRESENT_PARAMETERS *parameters,
453 IDirect3DDevice9 **device)
455 IDirect3D9Impl *This = impl_from_IDirect3D9Ex(iface);
456 IDirect3DDevice9Impl *object;
457 HRESULT hr;
459 TRACE("iface %p, adapter %u, device_type %#x, focus_window %p, flags %#x, parameters %p, device %p.\n",
460 iface, adapter, device_type, focus_window, flags, parameters, device);
462 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
463 if (!object)
465 ERR("Failed to allocate device memory.\n");
466 return E_OUTOFMEMORY;
469 hr = device_init(object, This, This->WineD3D, adapter, device_type, focus_window, flags, parameters, NULL);
470 if (FAILED(hr))
472 WARN("Failed to initialize device, hr %#x.\n", hr);
473 HeapFree(GetProcessHeap(), 0, object);
474 return hr;
477 TRACE("Created device %p.\n", object);
478 *device = (IDirect3DDevice9 *)object;
480 return D3D_OK;
483 static UINT WINAPI IDirect3D9ExImpl_GetAdapterModeCountEx(IDirect3D9Ex *iface,
484 UINT adapter, const D3DDISPLAYMODEFILTER *filter)
486 FIXME("iface %p, adapter %u, filter %p stub!\n", iface, adapter, filter);
488 return 0;
491 static HRESULT WINAPI IDirect3D9ExImpl_EnumAdapterModesEx(IDirect3D9Ex *iface,
492 UINT adapter, const D3DDISPLAYMODEFILTER *filter, UINT mode_idx, D3DDISPLAYMODEEX *mode)
494 FIXME("iface %p, adapter %u, filter %p, mode_idx %u, mode %p stub!\n",
495 iface, adapter, filter, mode_idx, mode);
497 return E_NOTIMPL;
500 static HRESULT WINAPI IDirect3D9ExImpl_GetAdapterDisplayModeEx(IDirect3D9Ex *iface,
501 UINT adapter, D3DDISPLAYMODEEX *mode, D3DDISPLAYROTATION *rotation)
503 FIXME("iface %p, adapter %u, mode %p, rotation %p stub!\n",
504 iface, adapter, mode, rotation);
506 return E_NOTIMPL;
509 static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3D9ExImpl_CreateDeviceEx(IDirect3D9Ex *iface,
510 UINT adapter, D3DDEVTYPE device_type, HWND focus_window, DWORD flags,
511 D3DPRESENT_PARAMETERS *parameters, D3DDISPLAYMODEEX *mode, IDirect3DDevice9Ex **device)
513 IDirect3D9Impl *d3d9 = impl_from_IDirect3D9Ex(iface);
514 IDirect3DDevice9Impl *object;
515 HRESULT hr;
517 TRACE("iface %p, adapter %u, device_type %#x, focus_window %p, flags %#x, parameters %p, mode %p, device %p.\n",
518 iface, adapter, device_type, focus_window, flags, parameters, mode, device);
520 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
521 if (!object)
523 ERR("Failed to allocate device memory.\n");
524 return E_OUTOFMEMORY;
527 hr = device_init(object, d3d9, d3d9->WineD3D, adapter, device_type, focus_window, flags, parameters, mode);
528 if (FAILED(hr))
530 WARN("Failed to initialize device, hr %#x.\n", hr);
531 HeapFree(GetProcessHeap(), 0, object);
532 return hr;
535 TRACE("Created device %p.\n", object);
536 *device = &object->IDirect3DDevice9Ex_iface;
538 return D3D_OK;
541 static HRESULT WINAPI IDirect3D9ExImpl_GetAdapterLUID(IDirect3D9Ex *iface, UINT adapter, LUID *luid)
543 IDirect3D9Impl *This = impl_from_IDirect3D9Ex(iface);
544 WINED3DADAPTER_IDENTIFIER adapter_id;
545 HRESULT hr;
547 TRACE("iface %p, adapter %u, luid %p.\n", iface, adapter, luid);
549 adapter_id.driver_size = 0;
550 adapter_id.description_size = 0;
551 adapter_id.device_name_size = 0;
553 wined3d_mutex_lock();
554 hr = wined3d_get_adapter_identifier(This->WineD3D, adapter, 0, &adapter_id);
555 wined3d_mutex_unlock();
557 memcpy(luid, &adapter_id.adapter_luid, sizeof(*luid));
559 return hr;
563 const IDirect3D9ExVtbl Direct3D9_Vtbl =
565 /* IUnknown */
566 IDirect3D9Impl_QueryInterface,
567 IDirect3D9Impl_AddRef,
568 IDirect3D9Impl_Release,
569 /* IDirect3D9 */
570 IDirect3D9Impl_RegisterSoftwareDevice,
571 IDirect3D9Impl_GetAdapterCount,
572 IDirect3D9Impl_GetAdapterIdentifier,
573 IDirect3D9Impl_GetAdapterModeCount,
574 IDirect3D9Impl_EnumAdapterModes,
575 IDirect3D9Impl_GetAdapterDisplayMode,
576 IDirect3D9Impl_CheckDeviceType,
577 IDirect3D9Impl_CheckDeviceFormat,
578 IDirect3D9Impl_CheckDeviceMultiSampleType,
579 IDirect3D9Impl_CheckDepthStencilMatch,
580 IDirect3D9Impl_CheckDeviceFormatConversion,
581 IDirect3D9Impl_GetDeviceCaps,
582 IDirect3D9Impl_GetAdapterMonitor,
583 IDirect3D9Impl_CreateDevice,
584 /* IDirect3D9Ex */
585 IDirect3D9ExImpl_GetAdapterModeCountEx,
586 IDirect3D9ExImpl_EnumAdapterModesEx,
587 IDirect3D9ExImpl_GetAdapterDisplayModeEx,
588 IDirect3D9ExImpl_CreateDeviceEx,
589 IDirect3D9ExImpl_GetAdapterLUID