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
23 #include "d3d9_private.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(d3d9
);
27 static inline struct d3d9
*impl_from_IDirect3D9Ex(IDirect3D9Ex
*iface
)
29 return CONTAINING_RECORD(iface
, struct d3d9
, IDirect3D9Ex_iface
);
32 static HRESULT WINAPI
d3d9_QueryInterface(IDirect3D9Ex
*iface
, REFIID riid
, void **out
)
34 struct d3d9
*d3d9
= impl_from_IDirect3D9Ex(iface
);
36 TRACE("iface %p, riid %s, out %p.\n", iface
, debugstr_guid(riid
), out
);
38 if (IsEqualGUID(riid
, &IID_IDirect3D9
)
39 || IsEqualGUID(riid
, &IID_IUnknown
))
41 IDirect3D9Ex_AddRef(&d3d9
->IDirect3D9Ex_iface
);
42 *out
= &d3d9
->IDirect3D9Ex_iface
;
46 if (IsEqualGUID(riid
, &IID_IDirect3D9Ex
))
50 WARN("Application asks for IDirect3D9Ex, but this instance wasn't created with Direct3DCreate9Ex.\n");
55 IDirect3D9Ex_AddRef(&d3d9
->IDirect3D9Ex_iface
);
56 *out
= &d3d9
->IDirect3D9Ex_iface
;
60 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
66 static ULONG WINAPI
d3d9_AddRef(IDirect3D9Ex
*iface
)
68 struct d3d9
*d3d9
= impl_from_IDirect3D9Ex(iface
);
69 ULONG refcount
= InterlockedIncrement(&d3d9
->refcount
);
71 TRACE("%p increasing refcount to %u.\n", iface
, refcount
);
76 static ULONG WINAPI
d3d9_Release(IDirect3D9Ex
*iface
)
78 struct d3d9
*d3d9
= impl_from_IDirect3D9Ex(iface
);
79 ULONG refcount
= InterlockedDecrement(&d3d9
->refcount
);
81 TRACE("%p decreasing refcount to %u.\n", iface
, refcount
);
86 wined3d_decref(d3d9
->wined3d
);
87 wined3d_mutex_unlock();
89 HeapFree(GetProcessHeap(), 0, d3d9
);
95 static HRESULT WINAPI
d3d9_RegisterSoftwareDevice(IDirect3D9Ex
*iface
, void *init_function
)
97 struct d3d9
*d3d9
= impl_from_IDirect3D9Ex(iface
);
100 TRACE("iface %p, init_function %p.\n", iface
, init_function
);
102 wined3d_mutex_lock();
103 hr
= wined3d_register_software_device(d3d9
->wined3d
, init_function
);
104 wined3d_mutex_unlock();
109 static UINT WINAPI
d3d9_GetAdapterCount(IDirect3D9Ex
*iface
)
111 struct d3d9
*d3d9
= impl_from_IDirect3D9Ex(iface
);
114 TRACE("iface %p.\n", iface
);
116 wined3d_mutex_lock();
117 ret
= wined3d_get_adapter_count(d3d9
->wined3d
);
118 wined3d_mutex_unlock();
123 static HRESULT WINAPI
d3d9_GetAdapterIdentifier(IDirect3D9Ex
*iface
, UINT adapter
,
124 DWORD flags
, D3DADAPTER_IDENTIFIER9
*identifier
)
126 struct d3d9
*d3d9
= impl_from_IDirect3D9Ex(iface
);
127 struct wined3d_adapter_identifier adapter_id
;
130 TRACE("iface %p, adapter %u, flags %#x, identifier %p.\n",
131 iface
, adapter
, flags
, identifier
);
133 adapter_id
.driver
= identifier
->Driver
;
134 adapter_id
.driver_size
= sizeof(identifier
->Driver
);
135 adapter_id
.description
= identifier
->Description
;
136 adapter_id
.description_size
= sizeof(identifier
->Description
);
137 adapter_id
.device_name
= identifier
->DeviceName
;
138 adapter_id
.device_name_size
= sizeof(identifier
->DeviceName
);
140 wined3d_mutex_lock();
141 hr
= wined3d_get_adapter_identifier(d3d9
->wined3d
, adapter
, flags
, &adapter_id
);
142 wined3d_mutex_unlock();
144 identifier
->DriverVersion
= adapter_id
.driver_version
;
145 identifier
->VendorId
= adapter_id
.vendor_id
;
146 identifier
->DeviceId
= adapter_id
.device_id
;
147 identifier
->SubSysId
= adapter_id
.subsystem_id
;
148 identifier
->Revision
= adapter_id
.revision
;
149 memcpy(&identifier
->DeviceIdentifier
, &adapter_id
.device_identifier
, sizeof(identifier
->DeviceIdentifier
));
150 identifier
->WHQLLevel
= adapter_id
.whql_level
;
155 static UINT WINAPI
d3d9_GetAdapterModeCount(IDirect3D9Ex
*iface
, UINT adapter
, D3DFORMAT format
)
157 struct d3d9
*d3d9
= impl_from_IDirect3D9Ex(iface
);
160 TRACE("iface %p, adapter %u, format %#x.\n", iface
, adapter
, format
);
162 /* Others than that not supported by d3d9, but reported by wined3d for ddraw. Filter them out. */
163 if (format
!= D3DFMT_X8R8G8B8
&& format
!= D3DFMT_R5G6B5
)
166 wined3d_mutex_lock();
167 ret
= wined3d_get_adapter_mode_count(d3d9
->wined3d
, adapter
,
168 wined3dformat_from_d3dformat(format
), WINED3D_SCANLINE_ORDERING_UNKNOWN
);
169 wined3d_mutex_unlock();
174 static HRESULT WINAPI
d3d9_EnumAdapterModes(IDirect3D9Ex
*iface
, UINT adapter
,
175 D3DFORMAT format
, UINT mode_idx
, D3DDISPLAYMODE
*mode
)
177 struct d3d9
*d3d9
= impl_from_IDirect3D9Ex(iface
);
178 struct wined3d_display_mode wined3d_mode
;
181 TRACE("iface %p, adapter %u, format %#x, mode_idx %u, mode %p.\n",
182 iface
, adapter
, format
, mode_idx
, mode
);
184 if (format
!= D3DFMT_X8R8G8B8
&& format
!= D3DFMT_R5G6B5
)
185 return D3DERR_INVALIDCALL
;
187 wined3d_mutex_lock();
188 hr
= wined3d_enum_adapter_modes(d3d9
->wined3d
, adapter
, wined3dformat_from_d3dformat(format
),
189 WINED3D_SCANLINE_ORDERING_UNKNOWN
, mode_idx
, &wined3d_mode
);
190 wined3d_mutex_unlock();
194 mode
->Width
= wined3d_mode
.width
;
195 mode
->Height
= wined3d_mode
.height
;
196 mode
->RefreshRate
= wined3d_mode
.refresh_rate
;
197 mode
->Format
= d3dformat_from_wined3dformat(wined3d_mode
.format_id
);
203 static HRESULT WINAPI
d3d9_GetAdapterDisplayMode(IDirect3D9Ex
*iface
, UINT adapter
, D3DDISPLAYMODE
*mode
)
205 struct d3d9
*d3d9
= impl_from_IDirect3D9Ex(iface
);
206 struct wined3d_display_mode wined3d_mode
;
209 TRACE("iface %p, adapter %u, mode %p.\n", iface
, adapter
, mode
);
211 wined3d_mutex_lock();
212 hr
= wined3d_get_adapter_display_mode(d3d9
->wined3d
, adapter
, &wined3d_mode
, NULL
);
213 wined3d_mutex_unlock();
217 mode
->Width
= wined3d_mode
.width
;
218 mode
->Height
= wined3d_mode
.height
;
219 mode
->RefreshRate
= wined3d_mode
.refresh_rate
;
220 mode
->Format
= d3dformat_from_wined3dformat(wined3d_mode
.format_id
);
226 static HRESULT WINAPI
d3d9_CheckDeviceType(IDirect3D9Ex
*iface
, UINT adapter
, D3DDEVTYPE device_type
,
227 D3DFORMAT display_format
, D3DFORMAT backbuffer_format
, BOOL windowed
)
229 struct d3d9
*d3d9
= impl_from_IDirect3D9Ex(iface
);
232 TRACE("iface %p, adapter %u, device_type %#x, display_format %#x, backbuffer_format %#x, windowed %#x.\n",
233 iface
, adapter
, device_type
, display_format
, backbuffer_format
, windowed
);
235 /* Others than that not supported by d3d9, but reported by wined3d for ddraw. Filter them out. */
236 if (!windowed
&& display_format
!= D3DFMT_X8R8G8B8
&& display_format
!= D3DFMT_R5G6B5
)
237 return WINED3DERR_NOTAVAILABLE
;
239 wined3d_mutex_lock();
240 hr
= wined3d_check_device_type(d3d9
->wined3d
, adapter
, device_type
, wined3dformat_from_d3dformat(display_format
),
241 wined3dformat_from_d3dformat(backbuffer_format
), windowed
);
242 wined3d_mutex_unlock();
247 static HRESULT WINAPI
d3d9_CheckDeviceFormat(IDirect3D9Ex
*iface
, UINT adapter
, D3DDEVTYPE device_type
,
248 D3DFORMAT adapter_format
, DWORD usage
, D3DRESOURCETYPE resource_type
, D3DFORMAT format
)
250 struct d3d9
*d3d9
= impl_from_IDirect3D9Ex(iface
);
251 enum wined3d_resource_type wined3d_rtype
;
254 TRACE("iface %p, adapter %u, device_type %#x, adapter_format %#x, usage %#x, resource_type %#x, format %#x.\n",
255 iface
, adapter
, device_type
, adapter_format
, usage
, resource_type
, format
);
257 switch (resource_type
)
259 case D3DRTYPE_VERTEXBUFFER
:
260 case D3DRTYPE_INDEXBUFFER
:
261 wined3d_rtype
= WINED3D_RTYPE_BUFFER
;
265 wined3d_rtype
= resource_type
;
269 wined3d_mutex_lock();
270 hr
= wined3d_check_device_format(d3d9
->wined3d
, adapter
, device_type
, wined3dformat_from_d3dformat(adapter_format
),
271 usage
, wined3d_rtype
, wined3dformat_from_d3dformat(format
));
272 wined3d_mutex_unlock();
277 static HRESULT WINAPI
d3d9_CheckDeviceMultiSampleType(IDirect3D9Ex
*iface
, UINT adapter
, D3DDEVTYPE device_type
,
278 D3DFORMAT format
, BOOL windowed
, D3DMULTISAMPLE_TYPE multisample_type
, DWORD
*levels
)
280 struct d3d9
*d3d9
= impl_from_IDirect3D9Ex(iface
);
283 TRACE("iface %p, adapter %u, device_type %#x, format %#x, windowed %#x, multisample_type %#x, levels %p.\n",
284 iface
, adapter
, device_type
, format
, windowed
, multisample_type
, levels
);
286 wined3d_mutex_lock();
287 hr
= wined3d_check_device_multisample_type(d3d9
->wined3d
, adapter
, device_type
,
288 wined3dformat_from_d3dformat(format
), windowed
, multisample_type
, levels
);
289 wined3d_mutex_unlock();
294 static HRESULT WINAPI
d3d9_CheckDepthStencilMatch(IDirect3D9Ex
*iface
, UINT adapter
, D3DDEVTYPE device_type
,
295 D3DFORMAT adapter_format
, D3DFORMAT rt_format
, D3DFORMAT ds_format
)
297 struct d3d9
*d3d9
= impl_from_IDirect3D9Ex(iface
);
300 TRACE("iface %p, adapter %u, device_type %#x, adapter_format %#x, rt_format %#x, ds_format %#x.\n",
301 iface
, adapter
, device_type
, adapter_format
, rt_format
, ds_format
);
303 wined3d_mutex_lock();
304 hr
= wined3d_check_depth_stencil_match(d3d9
->wined3d
, adapter
, device_type
,
305 wined3dformat_from_d3dformat(adapter_format
), wined3dformat_from_d3dformat(rt_format
),
306 wined3dformat_from_d3dformat(ds_format
));
307 wined3d_mutex_unlock();
312 static HRESULT WINAPI
d3d9_CheckDeviceFormatConversion(IDirect3D9Ex
*iface
, UINT adapter
,
313 D3DDEVTYPE device_type
, D3DFORMAT src_format
, D3DFORMAT dst_format
)
315 struct d3d9
*d3d9
= impl_from_IDirect3D9Ex(iface
);
318 TRACE("iface %p, adapter %u, device_type %#x, src_format %#x, dst_format %#x.\n",
319 iface
, adapter
, device_type
, src_format
, dst_format
);
321 wined3d_mutex_lock();
322 hr
= wined3d_check_device_format_conversion(d3d9
->wined3d
, adapter
, device_type
,
323 wined3dformat_from_d3dformat(src_format
), wined3dformat_from_d3dformat(dst_format
));
324 wined3d_mutex_unlock();
329 void filter_caps(D3DCAPS9
* pCaps
)
331 DWORD ps_minor_version
[] = {0, 4, 0, 0};
332 DWORD vs_minor_version
[] = {0, 1, 0, 0};
333 DWORD textureFilterCaps
=
334 D3DPTFILTERCAPS_MINFPOINT
| D3DPTFILTERCAPS_MINFLINEAR
| D3DPTFILTERCAPS_MINFANISOTROPIC
|
335 D3DPTFILTERCAPS_MINFPYRAMIDALQUAD
| D3DPTFILTERCAPS_MINFGAUSSIANQUAD
|
336 D3DPTFILTERCAPS_MIPFPOINT
| D3DPTFILTERCAPS_MIPFLINEAR
| D3DPTFILTERCAPS_MAGFPOINT
|
337 D3DPTFILTERCAPS_MAGFLINEAR
|D3DPTFILTERCAPS_MAGFANISOTROPIC
|D3DPTFILTERCAPS_MAGFPYRAMIDALQUAD
|
338 D3DPTFILTERCAPS_MAGFGAUSSIANQUAD
;
339 pCaps
->TextureFilterCaps
&= textureFilterCaps
;
340 pCaps
->CubeTextureFilterCaps
&= textureFilterCaps
;
341 pCaps
->VolumeTextureFilterCaps
&= textureFilterCaps
;
344 D3DDEVCAPS_EXECUTESYSTEMMEMORY
| D3DDEVCAPS_EXECUTEVIDEOMEMORY
| D3DDEVCAPS_TLVERTEXSYSTEMMEMORY
|
345 D3DDEVCAPS_TLVERTEXVIDEOMEMORY
| D3DDEVCAPS_TEXTURESYSTEMMEMORY
| D3DDEVCAPS_TEXTUREVIDEOMEMORY
|
346 D3DDEVCAPS_DRAWPRIMTLVERTEX
| D3DDEVCAPS_CANRENDERAFTERFLIP
| D3DDEVCAPS_TEXTURENONLOCALVIDMEM
|
347 D3DDEVCAPS_DRAWPRIMITIVES2
| D3DDEVCAPS_SEPARATETEXTUREMEMORIES
|
348 D3DDEVCAPS_DRAWPRIMITIVES2EX
| D3DDEVCAPS_HWTRANSFORMANDLIGHT
| D3DDEVCAPS_CANBLTSYSTONONLOCAL
|
349 D3DDEVCAPS_HWRASTERIZATION
| D3DDEVCAPS_PUREDEVICE
| D3DDEVCAPS_QUINTICRTPATCHES
|
350 D3DDEVCAPS_RTPATCHES
| D3DDEVCAPS_RTPATCHHANDLEZERO
| D3DDEVCAPS_NPATCHES
;
353 D3DPSHADECAPS_COLORGOURAUDRGB
| D3DPSHADECAPS_SPECULARGOURAUDRGB
|
354 D3DPSHADECAPS_ALPHAGOURAUDBLEND
| D3DPSHADECAPS_FOGGOURAUD
;
357 D3DPRASTERCAPS_DITHER
| D3DPRASTERCAPS_ZTEST
| D3DPRASTERCAPS_FOGVERTEX
|
358 D3DPRASTERCAPS_FOGTABLE
| D3DPRASTERCAPS_MIPMAPLODBIAS
| D3DPRASTERCAPS_ZBUFFERLESSHSR
|
359 D3DPRASTERCAPS_FOGRANGE
| D3DPRASTERCAPS_ANISOTROPY
| D3DPRASTERCAPS_WBUFFER
|
360 D3DPRASTERCAPS_WFOG
| D3DPRASTERCAPS_ZFOG
| D3DPRASTERCAPS_COLORPERSPECTIVE
|
361 D3DPRASTERCAPS_SCISSORTEST
| D3DPRASTERCAPS_SLOPESCALEDEPTHBIAS
|
362 D3DPRASTERCAPS_DEPTHBIAS
| D3DPRASTERCAPS_MULTISAMPLE_TOGGLE
;
365 D3DDEVCAPS2_STREAMOFFSET
| D3DDEVCAPS2_DMAPNPATCH
| D3DDEVCAPS2_ADAPTIVETESSRTPATCH
|
366 D3DDEVCAPS2_ADAPTIVETESSNPATCH
| D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES
|
367 D3DDEVCAPS2_PRESAMPLEDDMAPNPATCH
| D3DDEVCAPS2_VERTEXELEMENTSCANSHARESTREAMOFFSET
;
370 D3DCAPS2_FULLSCREENGAMMA
| D3DCAPS2_CANCALIBRATEGAMMA
| D3DCAPS2_RESERVED
|
371 D3DCAPS2_CANMANAGERESOURCE
| D3DCAPS2_DYNAMICTEXTURES
| D3DCAPS2_CANAUTOGENMIPMAP
;
373 pCaps
->VertexProcessingCaps
&=
374 D3DVTXPCAPS_TEXGEN
| D3DVTXPCAPS_MATERIALSOURCE7
| D3DVTXPCAPS_DIRECTIONALLIGHTS
|
375 D3DVTXPCAPS_POSITIONALLIGHTS
| D3DVTXPCAPS_LOCALVIEWER
| D3DVTXPCAPS_TWEENING
|
376 D3DVTXPCAPS_TEXGEN_SPHEREMAP
| D3DVTXPCAPS_NO_TEXGEN_NONLOCALVIEWER
;
378 pCaps
->TextureCaps
&=
379 D3DPTEXTURECAPS_PERSPECTIVE
| D3DPTEXTURECAPS_POW2
| D3DPTEXTURECAPS_ALPHA
|
380 D3DPTEXTURECAPS_SQUAREONLY
| D3DPTEXTURECAPS_TEXREPEATNOTSCALEDBYSIZE
|
381 D3DPTEXTURECAPS_ALPHAPALETTE
| D3DPTEXTURECAPS_NONPOW2CONDITIONAL
|
382 D3DPTEXTURECAPS_PROJECTED
| D3DPTEXTURECAPS_CUBEMAP
| D3DPTEXTURECAPS_VOLUMEMAP
|
383 D3DPTEXTURECAPS_MIPMAP
| D3DPTEXTURECAPS_MIPVOLUMEMAP
| D3DPTEXTURECAPS_MIPCUBEMAP
|
384 D3DPTEXTURECAPS_CUBEMAP_POW2
| D3DPTEXTURECAPS_VOLUMEMAP_POW2
| D3DPTEXTURECAPS_NOPROJECTEDBUMPENV
;
386 pCaps
->MaxVertexShaderConst
= min(D3D9_MAX_VERTEX_SHADER_CONSTANTF
, pCaps
->MaxVertexShaderConst
);
387 pCaps
->NumSimultaneousRTs
= min(D3D9_MAX_SIMULTANEOUS_RENDERTARGETS
, pCaps
->NumSimultaneousRTs
);
389 if (pCaps
->PixelShaderVersion
> 3)
390 pCaps
->PixelShaderVersion
= D3DPS_VERSION(3,0);
393 DWORD major
= pCaps
->PixelShaderVersion
;
394 pCaps
->PixelShaderVersion
= D3DPS_VERSION(major
,ps_minor_version
[major
]);
397 if (pCaps
->VertexShaderVersion
> 3)
398 pCaps
->VertexShaderVersion
= D3DVS_VERSION(3,0);
401 DWORD major
= pCaps
->VertexShaderVersion
;
402 pCaps
->VertexShaderVersion
= D3DVS_VERSION(major
,vs_minor_version
[major
]);
406 static HRESULT WINAPI
d3d9_GetDeviceCaps(IDirect3D9Ex
*iface
, UINT adapter
, D3DDEVTYPE device_type
, D3DCAPS9
*caps
)
408 struct d3d9
*d3d9
= impl_from_IDirect3D9Ex(iface
);
409 WINED3DCAPS
*wined3d_caps
;
412 TRACE("iface %p, adapter %u, device_type %#x, caps %p.\n", iface
, adapter
, device_type
, caps
);
415 return D3DERR_INVALIDCALL
;
417 if (!(wined3d_caps
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(WINED3DCAPS
))))
418 return D3DERR_INVALIDCALL
; /*well this is what MSDN says to return*/
419 memset(caps
, 0, sizeof(*caps
));
421 wined3d_mutex_lock();
422 hr
= wined3d_get_device_caps(d3d9
->wined3d
, adapter
, device_type
, wined3d_caps
);
423 wined3d_mutex_unlock();
425 WINECAPSTOD3D9CAPS(caps
, wined3d_caps
)
426 HeapFree(GetProcessHeap(), 0, wined3d_caps
);
428 /* Some functionality is implemented in d3d9.dll, not wined3d.dll. Add the needed caps */
429 caps
->DevCaps2
|= D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES
;
436 static HMONITOR WINAPI
d3d9_GetAdapterMonitor(IDirect3D9Ex
*iface
, UINT adapter
)
438 struct d3d9
*d3d9
= impl_from_IDirect3D9Ex(iface
);
441 TRACE("iface %p, adapter %u.\n", iface
, adapter
);
443 wined3d_mutex_lock();
444 ret
= wined3d_get_adapter_monitor(d3d9
->wined3d
, adapter
);
445 wined3d_mutex_unlock();
450 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d9_CreateDevice(IDirect3D9Ex
*iface
, UINT adapter
,
451 D3DDEVTYPE device_type
, HWND focus_window
, DWORD flags
, D3DPRESENT_PARAMETERS
*parameters
,
452 IDirect3DDevice9
**device
)
454 struct d3d9
*d3d9
= impl_from_IDirect3D9Ex(iface
);
455 struct d3d9_device
*object
;
458 TRACE("iface %p, adapter %u, device_type %#x, focus_window %p, flags %#x, parameters %p, device %p.\n",
459 iface
, adapter
, device_type
, focus_window
, flags
, parameters
, device
);
461 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
463 return E_OUTOFMEMORY
;
465 hr
= device_init(object
, d3d9
, d3d9
->wined3d
, adapter
, device_type
, focus_window
, flags
, parameters
, NULL
);
468 WARN("Failed to initialize device, hr %#x.\n", hr
);
469 HeapFree(GetProcessHeap(), 0, object
);
473 TRACE("Created device %p.\n", object
);
474 *device
= (IDirect3DDevice9
*)object
;
479 static UINT WINAPI
d3d9_GetAdapterModeCountEx(IDirect3D9Ex
*iface
,
480 UINT adapter
, const D3DDISPLAYMODEFILTER
*filter
)
482 struct d3d9
*d3d9
= impl_from_IDirect3D9Ex(iface
);
485 TRACE("iface %p, adapter %u, filter %p.\n", iface
, adapter
, filter
);
487 if (filter
->Format
!= D3DFMT_X8R8G8B8
&& filter
->Format
!= D3DFMT_R5G6B5
)
490 wined3d_mutex_lock();
491 ret
= wined3d_get_adapter_mode_count(d3d9
->wined3d
, adapter
,
492 wined3dformat_from_d3dformat(filter
->Format
), filter
->ScanLineOrdering
);
493 wined3d_mutex_unlock();
498 static HRESULT WINAPI
d3d9_EnumAdapterModesEx(IDirect3D9Ex
*iface
,
499 UINT adapter
, const D3DDISPLAYMODEFILTER
*filter
, UINT mode_idx
, D3DDISPLAYMODEEX
*mode
)
501 struct d3d9
*d3d9
= impl_from_IDirect3D9Ex(iface
);
502 struct wined3d_display_mode wined3d_mode
;
505 TRACE("iface %p, adapter %u, filter %p, mode_idx %u, mode %p.\n",
506 iface
, adapter
, filter
, mode_idx
, mode
);
508 if (filter
->Format
!= D3DFMT_X8R8G8B8
&& filter
->Format
!= D3DFMT_R5G6B5
)
509 return D3DERR_INVALIDCALL
;
511 wined3d_mutex_lock();
512 hr
= wined3d_enum_adapter_modes(d3d9
->wined3d
, adapter
, wined3dformat_from_d3dformat(filter
->Format
),
513 filter
->ScanLineOrdering
, mode_idx
, &wined3d_mode
);
514 wined3d_mutex_unlock();
518 mode
->Width
= wined3d_mode
.width
;
519 mode
->Height
= wined3d_mode
.height
;
520 mode
->RefreshRate
= wined3d_mode
.refresh_rate
;
521 mode
->Format
= d3dformat_from_wined3dformat(wined3d_mode
.format_id
);
522 mode
->ScanLineOrdering
= wined3d_mode
.scanline_ordering
;
528 static HRESULT WINAPI
d3d9_GetAdapterDisplayModeEx(IDirect3D9Ex
*iface
,
529 UINT adapter
, D3DDISPLAYMODEEX
*mode
, D3DDISPLAYROTATION
*rotation
)
531 struct d3d9
*d3d9
= impl_from_IDirect3D9Ex(iface
);
532 struct wined3d_display_mode wined3d_mode
;
535 TRACE("iface %p, adapter %u, mode %p, rotation %p.\n",
536 iface
, adapter
, mode
, rotation
);
538 if (mode
->Size
!= sizeof(*mode
))
539 return D3DERR_INVALIDCALL
;
541 wined3d_mutex_lock();
542 hr
= wined3d_get_adapter_display_mode(d3d9
->wined3d
, adapter
, &wined3d_mode
,
543 (enum wined3d_display_rotation
*)rotation
);
544 wined3d_mutex_unlock();
548 mode
->Width
= wined3d_mode
.width
;
549 mode
->Height
= wined3d_mode
.height
;
550 mode
->RefreshRate
= wined3d_mode
.refresh_rate
;
551 mode
->Format
= d3dformat_from_wined3dformat(wined3d_mode
.format_id
);
552 mode
->ScanLineOrdering
= wined3d_mode
.scanline_ordering
;
558 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d9_CreateDeviceEx(IDirect3D9Ex
*iface
,
559 UINT adapter
, D3DDEVTYPE device_type
, HWND focus_window
, DWORD flags
,
560 D3DPRESENT_PARAMETERS
*parameters
, D3DDISPLAYMODEEX
*mode
, IDirect3DDevice9Ex
**device
)
562 struct d3d9
*d3d9
= impl_from_IDirect3D9Ex(iface
);
563 struct d3d9_device
*object
;
566 TRACE("iface %p, adapter %u, device_type %#x, focus_window %p, flags %#x, parameters %p, mode %p, device %p.\n",
567 iface
, adapter
, device_type
, focus_window
, flags
, parameters
, mode
, device
);
569 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
571 return E_OUTOFMEMORY
;
573 hr
= device_init(object
, d3d9
, d3d9
->wined3d
, adapter
, device_type
, focus_window
, flags
, parameters
, mode
);
576 WARN("Failed to initialize device, hr %#x.\n", hr
);
577 HeapFree(GetProcessHeap(), 0, object
);
581 TRACE("Created device %p.\n", object
);
582 *device
= &object
->IDirect3DDevice9Ex_iface
;
587 static HRESULT WINAPI
d3d9_GetAdapterLUID(IDirect3D9Ex
*iface
, UINT adapter
, LUID
*luid
)
589 struct d3d9
*d3d9
= impl_from_IDirect3D9Ex(iface
);
590 struct wined3d_adapter_identifier adapter_id
;
593 TRACE("iface %p, adapter %u, luid %p.\n", iface
, adapter
, luid
);
595 adapter_id
.driver_size
= 0;
596 adapter_id
.description_size
= 0;
597 adapter_id
.device_name_size
= 0;
599 wined3d_mutex_lock();
600 hr
= wined3d_get_adapter_identifier(d3d9
->wined3d
, adapter
, 0, &adapter_id
);
601 wined3d_mutex_unlock();
603 memcpy(luid
, &adapter_id
.adapter_luid
, sizeof(*luid
));
608 static const struct IDirect3D9ExVtbl d3d9_vtbl
=
615 d3d9_RegisterSoftwareDevice
,
616 d3d9_GetAdapterCount
,
617 d3d9_GetAdapterIdentifier
,
618 d3d9_GetAdapterModeCount
,
619 d3d9_EnumAdapterModes
,
620 d3d9_GetAdapterDisplayMode
,
621 d3d9_CheckDeviceType
,
622 d3d9_CheckDeviceFormat
,
623 d3d9_CheckDeviceMultiSampleType
,
624 d3d9_CheckDepthStencilMatch
,
625 d3d9_CheckDeviceFormatConversion
,
627 d3d9_GetAdapterMonitor
,
630 d3d9_GetAdapterModeCountEx
,
631 d3d9_EnumAdapterModesEx
,
632 d3d9_GetAdapterDisplayModeEx
,
637 BOOL
d3d9_init(struct d3d9
*d3d9
, BOOL extended
)
639 DWORD flags
= WINED3D_PRESENT_CONVERSION
| WINED3D_HANDLE_RESTORE
| WINED3D_PIXEL_CENTER_INTEGER
;
642 flags
|= WINED3D_VIDMEM_ACCOUNTING
;
644 flags
|= WINED3D_RESTORE_MODE_ON_ACTIVATE
;
646 d3d9
->IDirect3D9Ex_iface
.lpVtbl
= &d3d9_vtbl
;
649 wined3d_mutex_lock();
650 d3d9
->wined3d
= wined3d_create(flags
);
651 wined3d_mutex_unlock();
654 d3d9
->extended
= extended
;