gdi32: Fix coordinates for row copies in mirrored vertical stretching.
[wine/multimedia.git] / dlls / d3d9 / directx.c
blob2654c1e191bb7b4d830a14a029acb031fdd0d2af
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 struct wined3d_adapter_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, (struct wined3d_display_mode *)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, (struct wined3d_display_mode *)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 enum wined3d_resource_type wined3d_rtype;
236 HRESULT hr;
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 switch(RType) {
242 case D3DRTYPE_VERTEXBUFFER:
243 case D3DRTYPE_INDEXBUFFER:
244 wined3d_rtype = WINED3D_RTYPE_BUFFER;
245 break;
247 default:
248 wined3d_rtype = RType;
249 break;
252 wined3d_mutex_lock();
253 hr = wined3d_check_device_format(This->WineD3D, Adapter, DeviceType, wined3dformat_from_d3dformat(AdapterFormat),
254 Usage, wined3d_rtype, wined3dformat_from_d3dformat(CheckFormat), WINED3D_SURFACE_TYPE_OPENGL);
255 wined3d_mutex_unlock();
257 return hr;
260 static HRESULT WINAPI IDirect3D9Impl_CheckDeviceMultiSampleType(IDirect3D9Ex *iface, UINT Adapter,
261 D3DDEVTYPE DeviceType, D3DFORMAT SurfaceFormat, BOOL Windowed,
262 D3DMULTISAMPLE_TYPE MultiSampleType, DWORD *pQualityLevels)
264 IDirect3D9Impl *This = impl_from_IDirect3D9Ex(iface);
265 HRESULT hr;
267 TRACE("iface %p, adapter %u, device_type %#x, format %#x, windowed %#x, multisample_type %#x, levels %p.\n",
268 iface, Adapter, DeviceType, SurfaceFormat, Windowed, MultiSampleType, pQualityLevels);
270 wined3d_mutex_lock();
271 hr = wined3d_check_device_multisample_type(This->WineD3D, Adapter, DeviceType,
272 wined3dformat_from_d3dformat(SurfaceFormat), Windowed, MultiSampleType, pQualityLevels);
273 wined3d_mutex_unlock();
275 return hr;
278 static HRESULT WINAPI IDirect3D9Impl_CheckDepthStencilMatch(IDirect3D9Ex *iface, UINT Adapter,
279 D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat, D3DFORMAT RenderTargetFormat,
280 D3DFORMAT DepthStencilFormat)
282 IDirect3D9Impl *This = impl_from_IDirect3D9Ex(iface);
283 HRESULT hr;
285 TRACE("iface %p, adapter %u, device_type %#x, adapter_format %#x, rt_format %#x, ds_format %#x.\n",
286 iface, Adapter, DeviceType, AdapterFormat, RenderTargetFormat, DepthStencilFormat);
288 wined3d_mutex_lock();
289 hr = wined3d_check_depth_stencil_match(This->WineD3D, Adapter, DeviceType,
290 wined3dformat_from_d3dformat(AdapterFormat), wined3dformat_from_d3dformat(RenderTargetFormat),
291 wined3dformat_from_d3dformat(DepthStencilFormat));
292 wined3d_mutex_unlock();
294 return hr;
297 static HRESULT WINAPI IDirect3D9Impl_CheckDeviceFormatConversion(IDirect3D9Ex *iface, UINT Adapter,
298 D3DDEVTYPE DeviceType, D3DFORMAT SourceFormat, D3DFORMAT TargetFormat)
300 IDirect3D9Impl *This = impl_from_IDirect3D9Ex(iface);
301 HRESULT hr;
303 TRACE("iface %p, adapter %u, device_type %#x, src_format %#x, dst_format %#x.\n",
304 iface, Adapter, DeviceType, SourceFormat, TargetFormat);
306 wined3d_mutex_lock();
307 hr = wined3d_check_device_format_conversion(This->WineD3D, Adapter, DeviceType,
308 wined3dformat_from_d3dformat(SourceFormat), wined3dformat_from_d3dformat(TargetFormat));
309 wined3d_mutex_unlock();
311 return hr;
314 void filter_caps(D3DCAPS9* pCaps)
316 DWORD ps_minor_version[] = {0, 4, 0, 0};
317 DWORD vs_minor_version[] = {0, 1, 0, 0};
318 DWORD textureFilterCaps =
319 D3DPTFILTERCAPS_MINFPOINT | D3DPTFILTERCAPS_MINFLINEAR | D3DPTFILTERCAPS_MINFANISOTROPIC |
320 D3DPTFILTERCAPS_MINFPYRAMIDALQUAD | D3DPTFILTERCAPS_MINFGAUSSIANQUAD|
321 D3DPTFILTERCAPS_MIPFPOINT | D3DPTFILTERCAPS_MIPFLINEAR | D3DPTFILTERCAPS_MAGFPOINT |
322 D3DPTFILTERCAPS_MAGFLINEAR |D3DPTFILTERCAPS_MAGFANISOTROPIC|D3DPTFILTERCAPS_MAGFPYRAMIDALQUAD|
323 D3DPTFILTERCAPS_MAGFGAUSSIANQUAD;
324 pCaps->TextureFilterCaps &= textureFilterCaps;
325 pCaps->CubeTextureFilterCaps &= textureFilterCaps;
326 pCaps->VolumeTextureFilterCaps &= textureFilterCaps;
328 pCaps->DevCaps &=
329 D3DDEVCAPS_EXECUTESYSTEMMEMORY | D3DDEVCAPS_EXECUTEVIDEOMEMORY | D3DDEVCAPS_TLVERTEXSYSTEMMEMORY |
330 D3DDEVCAPS_TLVERTEXVIDEOMEMORY | D3DDEVCAPS_TEXTURESYSTEMMEMORY| D3DDEVCAPS_TEXTUREVIDEOMEMORY |
331 D3DDEVCAPS_DRAWPRIMTLVERTEX | D3DDEVCAPS_CANRENDERAFTERFLIP | D3DDEVCAPS_TEXTURENONLOCALVIDMEM|
332 D3DDEVCAPS_DRAWPRIMITIVES2 | D3DDEVCAPS_SEPARATETEXTUREMEMORIES |
333 D3DDEVCAPS_DRAWPRIMITIVES2EX | D3DDEVCAPS_HWTRANSFORMANDLIGHT| D3DDEVCAPS_CANBLTSYSTONONLOCAL |
334 D3DDEVCAPS_HWRASTERIZATION | D3DDEVCAPS_PUREDEVICE | D3DDEVCAPS_QUINTICRTPATCHES |
335 D3DDEVCAPS_RTPATCHES | D3DDEVCAPS_RTPATCHHANDLEZERO | D3DDEVCAPS_NPATCHES;
337 pCaps->ShadeCaps &=
338 D3DPSHADECAPS_COLORGOURAUDRGB | D3DPSHADECAPS_SPECULARGOURAUDRGB |
339 D3DPSHADECAPS_ALPHAGOURAUDBLEND | D3DPSHADECAPS_FOGGOURAUD;
341 pCaps->RasterCaps &=
342 D3DPRASTERCAPS_DITHER | D3DPRASTERCAPS_ZTEST | D3DPRASTERCAPS_FOGVERTEX |
343 D3DPRASTERCAPS_FOGTABLE | D3DPRASTERCAPS_MIPMAPLODBIAS | D3DPRASTERCAPS_ZBUFFERLESSHSR |
344 D3DPRASTERCAPS_FOGRANGE | D3DPRASTERCAPS_ANISOTROPY | D3DPRASTERCAPS_WBUFFER |
345 D3DPRASTERCAPS_WFOG | D3DPRASTERCAPS_ZFOG | D3DPRASTERCAPS_COLORPERSPECTIVE |
346 D3DPRASTERCAPS_SCISSORTEST | D3DPRASTERCAPS_SLOPESCALEDEPTHBIAS |
347 D3DPRASTERCAPS_DEPTHBIAS | D3DPRASTERCAPS_MULTISAMPLE_TOGGLE;
349 pCaps->DevCaps2 &=
350 D3DDEVCAPS2_STREAMOFFSET | D3DDEVCAPS2_DMAPNPATCH | D3DDEVCAPS2_ADAPTIVETESSRTPATCH |
351 D3DDEVCAPS2_ADAPTIVETESSNPATCH | D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES |
352 D3DDEVCAPS2_PRESAMPLEDDMAPNPATCH| D3DDEVCAPS2_VERTEXELEMENTSCANSHARESTREAMOFFSET;
354 pCaps->Caps2 &=
355 D3DCAPS2_FULLSCREENGAMMA | D3DCAPS2_CANCALIBRATEGAMMA | D3DCAPS2_RESERVED |
356 D3DCAPS2_CANMANAGERESOURCE | D3DCAPS2_DYNAMICTEXTURES | D3DCAPS2_CANAUTOGENMIPMAP;
358 pCaps->VertexProcessingCaps &=
359 D3DVTXPCAPS_TEXGEN | D3DVTXPCAPS_MATERIALSOURCE7 | D3DVTXPCAPS_DIRECTIONALLIGHTS |
360 D3DVTXPCAPS_POSITIONALLIGHTS | D3DVTXPCAPS_LOCALVIEWER | D3DVTXPCAPS_TWEENING |
361 D3DVTXPCAPS_TEXGEN_SPHEREMAP | D3DVTXPCAPS_NO_TEXGEN_NONLOCALVIEWER;
363 pCaps->TextureCaps &=
364 D3DPTEXTURECAPS_PERSPECTIVE | D3DPTEXTURECAPS_POW2 | D3DPTEXTURECAPS_ALPHA |
365 D3DPTEXTURECAPS_SQUAREONLY | D3DPTEXTURECAPS_TEXREPEATNOTSCALEDBYSIZE |
366 D3DPTEXTURECAPS_ALPHAPALETTE | D3DPTEXTURECAPS_NONPOW2CONDITIONAL |
367 D3DPTEXTURECAPS_PROJECTED | D3DPTEXTURECAPS_CUBEMAP | D3DPTEXTURECAPS_VOLUMEMAP |
368 D3DPTEXTURECAPS_MIPMAP | D3DPTEXTURECAPS_MIPVOLUMEMAP | D3DPTEXTURECAPS_MIPCUBEMAP |
369 D3DPTEXTURECAPS_CUBEMAP_POW2 | D3DPTEXTURECAPS_VOLUMEMAP_POW2| D3DPTEXTURECAPS_NOPROJECTEDBUMPENV;
371 pCaps->MaxVertexShaderConst = min(D3D9_MAX_VERTEX_SHADER_CONSTANTF, pCaps->MaxVertexShaderConst);
372 pCaps->NumSimultaneousRTs = min(D3D9_MAX_SIMULTANEOUS_RENDERTARGETS, pCaps->NumSimultaneousRTs);
374 if (pCaps->PixelShaderVersion > 3)
375 pCaps->PixelShaderVersion = D3DPS_VERSION(3,0);
376 else
378 DWORD major = pCaps->PixelShaderVersion;
379 pCaps->PixelShaderVersion = D3DPS_VERSION(major,ps_minor_version[major]);
382 if (pCaps->VertexShaderVersion > 3)
383 pCaps->VertexShaderVersion = D3DVS_VERSION(3,0);
384 else
386 DWORD major = pCaps->VertexShaderVersion;
387 pCaps->VertexShaderVersion = D3DVS_VERSION(major,vs_minor_version[major]);
391 static HRESULT WINAPI IDirect3D9Impl_GetDeviceCaps(IDirect3D9Ex *iface, UINT Adapter,
392 D3DDEVTYPE DeviceType, D3DCAPS9 *pCaps)
394 IDirect3D9Impl *This = impl_from_IDirect3D9Ex(iface);
395 HRESULT hrc = D3D_OK;
396 WINED3DCAPS *pWineCaps;
398 TRACE("iface %p, adapter %u, device_type %#x, caps %p.\n", iface, Adapter, DeviceType, pCaps);
400 if(NULL == pCaps){
401 return D3DERR_INVALIDCALL;
403 pWineCaps = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WINED3DCAPS));
404 if(pWineCaps == NULL){
405 return D3DERR_INVALIDCALL; /*well this is what MSDN says to return*/
407 memset(pCaps, 0, sizeof(*pCaps));
409 wined3d_mutex_lock();
410 hrc = wined3d_get_device_caps(This->WineD3D, Adapter, DeviceType, pWineCaps);
411 wined3d_mutex_unlock();
413 WINECAPSTOD3D9CAPS(pCaps, pWineCaps)
414 HeapFree(GetProcessHeap(), 0, pWineCaps);
416 /* Some functionality is implemented in d3d9.dll, not wined3d.dll. Add the needed caps */
417 pCaps->DevCaps2 |= D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES;
419 filter_caps(pCaps);
421 TRACE("(%p) returning %p\n", This, pCaps);
422 return hrc;
425 static HMONITOR WINAPI IDirect3D9Impl_GetAdapterMonitor(IDirect3D9Ex *iface, UINT Adapter)
427 IDirect3D9Impl *This = impl_from_IDirect3D9Ex(iface);
428 HMONITOR ret;
430 TRACE("iface %p, adapter %u.\n", iface, Adapter);
432 wined3d_mutex_lock();
433 ret = wined3d_get_adapter_monitor(This->WineD3D, Adapter);
434 wined3d_mutex_unlock();
436 return ret;
439 static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3D9Impl_CreateDevice(IDirect3D9Ex *iface, UINT adapter,
440 D3DDEVTYPE device_type, HWND focus_window, DWORD flags, D3DPRESENT_PARAMETERS *parameters,
441 IDirect3DDevice9 **device)
443 IDirect3D9Impl *This = impl_from_IDirect3D9Ex(iface);
444 IDirect3DDevice9Impl *object;
445 HRESULT hr;
447 TRACE("iface %p, adapter %u, device_type %#x, focus_window %p, flags %#x, parameters %p, device %p.\n",
448 iface, adapter, device_type, focus_window, flags, parameters, device);
450 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
451 if (!object)
453 ERR("Failed to allocate device memory.\n");
454 return E_OUTOFMEMORY;
457 hr = device_init(object, This, This->WineD3D, adapter, device_type, focus_window, flags, parameters, NULL);
458 if (FAILED(hr))
460 WARN("Failed to initialize device, hr %#x.\n", hr);
461 HeapFree(GetProcessHeap(), 0, object);
462 return hr;
465 TRACE("Created device %p.\n", object);
466 *device = (IDirect3DDevice9 *)object;
468 return D3D_OK;
471 static UINT WINAPI IDirect3D9ExImpl_GetAdapterModeCountEx(IDirect3D9Ex *iface,
472 UINT adapter, const D3DDISPLAYMODEFILTER *filter)
474 FIXME("iface %p, adapter %u, filter %p stub!\n", iface, adapter, filter);
476 return 0;
479 static HRESULT WINAPI IDirect3D9ExImpl_EnumAdapterModesEx(IDirect3D9Ex *iface,
480 UINT adapter, const D3DDISPLAYMODEFILTER *filter, UINT mode_idx, D3DDISPLAYMODEEX *mode)
482 FIXME("iface %p, adapter %u, filter %p, mode_idx %u, mode %p stub!\n",
483 iface, adapter, filter, mode_idx, mode);
485 return E_NOTIMPL;
488 static HRESULT WINAPI IDirect3D9ExImpl_GetAdapterDisplayModeEx(IDirect3D9Ex *iface,
489 UINT adapter, D3DDISPLAYMODEEX *mode, D3DDISPLAYROTATION *rotation)
491 FIXME("iface %p, adapter %u, mode %p, rotation %p stub!\n",
492 iface, adapter, mode, rotation);
494 return E_NOTIMPL;
497 static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3D9ExImpl_CreateDeviceEx(IDirect3D9Ex *iface,
498 UINT adapter, D3DDEVTYPE device_type, HWND focus_window, DWORD flags,
499 D3DPRESENT_PARAMETERS *parameters, D3DDISPLAYMODEEX *mode, IDirect3DDevice9Ex **device)
501 IDirect3D9Impl *d3d9 = impl_from_IDirect3D9Ex(iface);
502 IDirect3DDevice9Impl *object;
503 HRESULT hr;
505 TRACE("iface %p, adapter %u, device_type %#x, focus_window %p, flags %#x, parameters %p, mode %p, device %p.\n",
506 iface, adapter, device_type, focus_window, flags, parameters, mode, device);
508 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
509 if (!object)
511 ERR("Failed to allocate device memory.\n");
512 return E_OUTOFMEMORY;
515 hr = device_init(object, d3d9, d3d9->WineD3D, adapter, device_type, focus_window, flags, parameters, mode);
516 if (FAILED(hr))
518 WARN("Failed to initialize device, hr %#x.\n", hr);
519 HeapFree(GetProcessHeap(), 0, object);
520 return hr;
523 TRACE("Created device %p.\n", object);
524 *device = &object->IDirect3DDevice9Ex_iface;
526 return D3D_OK;
529 static HRESULT WINAPI IDirect3D9ExImpl_GetAdapterLUID(IDirect3D9Ex *iface, UINT adapter, LUID *luid)
531 IDirect3D9Impl *This = impl_from_IDirect3D9Ex(iface);
532 struct wined3d_adapter_identifier adapter_id;
533 HRESULT hr;
535 TRACE("iface %p, adapter %u, luid %p.\n", iface, adapter, luid);
537 adapter_id.driver_size = 0;
538 adapter_id.description_size = 0;
539 adapter_id.device_name_size = 0;
541 wined3d_mutex_lock();
542 hr = wined3d_get_adapter_identifier(This->WineD3D, adapter, 0, &adapter_id);
543 wined3d_mutex_unlock();
545 memcpy(luid, &adapter_id.adapter_luid, sizeof(*luid));
547 return hr;
551 const IDirect3D9ExVtbl Direct3D9_Vtbl =
553 /* IUnknown */
554 IDirect3D9Impl_QueryInterface,
555 IDirect3D9Impl_AddRef,
556 IDirect3D9Impl_Release,
557 /* IDirect3D9 */
558 IDirect3D9Impl_RegisterSoftwareDevice,
559 IDirect3D9Impl_GetAdapterCount,
560 IDirect3D9Impl_GetAdapterIdentifier,
561 IDirect3D9Impl_GetAdapterModeCount,
562 IDirect3D9Impl_EnumAdapterModes,
563 IDirect3D9Impl_GetAdapterDisplayMode,
564 IDirect3D9Impl_CheckDeviceType,
565 IDirect3D9Impl_CheckDeviceFormat,
566 IDirect3D9Impl_CheckDeviceMultiSampleType,
567 IDirect3D9Impl_CheckDepthStencilMatch,
568 IDirect3D9Impl_CheckDeviceFormatConversion,
569 IDirect3D9Impl_GetDeviceCaps,
570 IDirect3D9Impl_GetAdapterMonitor,
571 IDirect3D9Impl_CreateDevice,
572 /* IDirect3D9Ex */
573 IDirect3D9ExImpl_GetAdapterModeCountEx,
574 IDirect3D9ExImpl_EnumAdapterModesEx,
575 IDirect3D9ExImpl_GetAdapterDisplayModeEx,
576 IDirect3D9ExImpl_CreateDeviceEx,
577 IDirect3D9ExImpl_GetAdapterLUID