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 "d3d9_private.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(d3d9
);
26 static inline struct d3d9
*impl_from_IDirect3D9Ex(IDirect3D9Ex
*iface
)
28 return CONTAINING_RECORD(iface
, struct d3d9
, IDirect3D9Ex_iface
);
31 static HRESULT WINAPI
d3d9_QueryInterface(IDirect3D9Ex
*iface
, REFIID riid
, void **out
)
33 struct d3d9
*d3d9
= impl_from_IDirect3D9Ex(iface
);
35 TRACE("iface %p, riid %s, out %p.\n", iface
, debugstr_guid(riid
), out
);
37 if (IsEqualGUID(riid
, &IID_IDirect3D9
)
38 || IsEqualGUID(riid
, &IID_IUnknown
))
40 IDirect3D9Ex_AddRef(&d3d9
->IDirect3D9Ex_iface
);
41 *out
= &d3d9
->IDirect3D9Ex_iface
;
45 if (IsEqualGUID(riid
, &IID_IDirect3D9Ex
))
49 WARN("Application asks for IDirect3D9Ex, but this instance wasn't created with Direct3DCreate9Ex.\n");
54 IDirect3D9Ex_AddRef(&d3d9
->IDirect3D9Ex_iface
);
55 *out
= &d3d9
->IDirect3D9Ex_iface
;
59 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
65 static ULONG WINAPI
d3d9_AddRef(IDirect3D9Ex
*iface
)
67 struct d3d9
*d3d9
= impl_from_IDirect3D9Ex(iface
);
68 ULONG refcount
= InterlockedIncrement(&d3d9
->refcount
);
70 TRACE("%p increasing refcount to %u.\n", iface
, refcount
);
75 static ULONG WINAPI
d3d9_Release(IDirect3D9Ex
*iface
)
77 struct d3d9
*d3d9
= impl_from_IDirect3D9Ex(iface
);
78 ULONG refcount
= InterlockedDecrement(&d3d9
->refcount
);
80 TRACE("%p decreasing refcount to %u.\n", iface
, refcount
);
85 wined3d_decref(d3d9
->wined3d
);
86 wined3d_mutex_unlock();
88 heap_free(d3d9
->wined3d_outputs
);
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
);
113 TRACE("iface %p.\n", iface
);
115 return d3d9
->wined3d_output_count
;
118 static HRESULT WINAPI
d3d9_GetAdapterIdentifier(IDirect3D9Ex
*iface
, UINT adapter
,
119 DWORD flags
, D3DADAPTER_IDENTIFIER9
*identifier
)
121 struct d3d9
*d3d9
= impl_from_IDirect3D9Ex(iface
);
122 struct wined3d_adapter_identifier adapter_id
;
123 struct wined3d_adapter
*wined3d_adapter
;
124 struct wined3d_output_desc output_desc
;
125 unsigned int output_idx
;
128 TRACE("iface %p, adapter %u, flags %#x, identifier %p.\n",
129 iface
, adapter
, flags
, identifier
);
131 output_idx
= adapter
;
132 if (output_idx
>= d3d9
->wined3d_output_count
)
133 return D3DERR_INVALIDCALL
;
135 wined3d_mutex_lock();
136 if (FAILED(hr
= wined3d_output_get_desc(d3d9
->wined3d_outputs
[output_idx
], &output_desc
)))
138 wined3d_mutex_unlock();
139 WARN("Failed to get output description, hr %#x.\n", hr
);
142 WideCharToMultiByte(CP_ACP
, 0, output_desc
.device_name
, -1, identifier
->DeviceName
,
143 sizeof(identifier
->DeviceName
), NULL
, NULL
);
145 adapter_id
.driver
= identifier
->Driver
;
146 adapter_id
.driver_size
= sizeof(identifier
->Driver
);
147 adapter_id
.description
= identifier
->Description
;
148 adapter_id
.description_size
= sizeof(identifier
->Description
);
150 wined3d_adapter
= wined3d_output_get_adapter(d3d9
->wined3d_outputs
[output_idx
]);
151 if (SUCCEEDED(hr
= wined3d_adapter_get_identifier(wined3d_adapter
, flags
, &adapter_id
)))
153 identifier
->DriverVersion
= adapter_id
.driver_version
;
154 identifier
->VendorId
= adapter_id
.vendor_id
;
155 identifier
->DeviceId
= adapter_id
.device_id
;
156 identifier
->SubSysId
= adapter_id
.subsystem_id
;
157 identifier
->Revision
= adapter_id
.revision
;
158 memcpy(&identifier
->DeviceIdentifier
, &adapter_id
.device_identifier
, sizeof(identifier
->DeviceIdentifier
));
159 identifier
->WHQLLevel
= adapter_id
.whql_level
;
161 wined3d_mutex_unlock();
166 static UINT WINAPI
d3d9_GetAdapterModeCount(IDirect3D9Ex
*iface
, UINT adapter
, D3DFORMAT format
)
168 struct d3d9
*d3d9
= impl_from_IDirect3D9Ex(iface
);
169 unsigned int output_idx
, count
;
171 TRACE("iface %p, adapter %u, format %#x.\n", iface
, adapter
, format
);
173 output_idx
= adapter
;
174 if (output_idx
>= d3d9
->wined3d_output_count
)
177 /* Others than that not supported by d3d9, but reported by wined3d for ddraw. Filter them out. */
178 if (format
!= D3DFMT_X8R8G8B8
&& format
!= D3DFMT_R5G6B5
)
181 wined3d_mutex_lock();
182 count
= wined3d_output_get_mode_count(d3d9
->wined3d_outputs
[output_idx
],
183 wined3dformat_from_d3dformat(format
), WINED3D_SCANLINE_ORDERING_UNKNOWN
);
184 wined3d_mutex_unlock();
189 static HRESULT WINAPI
d3d9_EnumAdapterModes(IDirect3D9Ex
*iface
, UINT adapter
,
190 D3DFORMAT format
, UINT mode_idx
, D3DDISPLAYMODE
*mode
)
192 struct d3d9
*d3d9
= impl_from_IDirect3D9Ex(iface
);
193 struct wined3d_display_mode wined3d_mode
;
194 unsigned int output_idx
;
197 TRACE("iface %p, adapter %u, format %#x, mode_idx %u, mode %p.\n",
198 iface
, adapter
, format
, mode_idx
, mode
);
200 output_idx
= adapter
;
201 if (output_idx
>= d3d9
->wined3d_output_count
)
202 return D3DERR_INVALIDCALL
;
204 if (format
!= D3DFMT_X8R8G8B8
&& format
!= D3DFMT_R5G6B5
)
205 return D3DERR_INVALIDCALL
;
207 wined3d_mutex_lock();
208 hr
= wined3d_output_get_mode(d3d9
->wined3d_outputs
[output_idx
],
209 wined3dformat_from_d3dformat(format
), WINED3D_SCANLINE_ORDERING_UNKNOWN
, mode_idx
,
211 wined3d_mutex_unlock();
215 mode
->Width
= wined3d_mode
.width
;
216 mode
->Height
= wined3d_mode
.height
;
217 mode
->RefreshRate
= wined3d_mode
.refresh_rate
;
218 mode
->Format
= d3dformat_from_wined3dformat(wined3d_mode
.format_id
);
224 static HRESULT WINAPI
d3d9_GetAdapterDisplayMode(IDirect3D9Ex
*iface
, UINT adapter
, D3DDISPLAYMODE
*mode
)
226 struct d3d9
*d3d9
= impl_from_IDirect3D9Ex(iface
);
227 struct wined3d_display_mode wined3d_mode
;
228 unsigned int output_idx
;
231 TRACE("iface %p, adapter %u, mode %p.\n", iface
, adapter
, mode
);
233 output_idx
= adapter
;
234 if (output_idx
>= d3d9
->wined3d_output_count
)
235 return D3DERR_INVALIDCALL
;
237 wined3d_mutex_lock();
238 hr
= wined3d_output_get_display_mode(d3d9
->wined3d_outputs
[output_idx
], &wined3d_mode
, NULL
);
239 wined3d_mutex_unlock();
243 mode
->Width
= wined3d_mode
.width
;
244 mode
->Height
= wined3d_mode
.height
;
245 mode
->RefreshRate
= wined3d_mode
.refresh_rate
;
246 mode
->Format
= d3dformat_from_wined3dformat(wined3d_mode
.format_id
);
252 static HRESULT WINAPI
d3d9_CheckDeviceType(IDirect3D9Ex
*iface
, UINT adapter
, D3DDEVTYPE device_type
,
253 D3DFORMAT display_format
, D3DFORMAT backbuffer_format
, BOOL windowed
)
255 struct d3d9
*d3d9
= impl_from_IDirect3D9Ex(iface
);
256 unsigned int output_idx
;
259 TRACE("iface %p, adapter %u, device_type %#x, display_format %#x, backbuffer_format %#x, windowed %#x.\n",
260 iface
, adapter
, device_type
, display_format
, backbuffer_format
, windowed
);
262 output_idx
= adapter
;
263 if (output_idx
>= d3d9
->wined3d_output_count
)
264 return D3DERR_INVALIDCALL
;
266 /* Others than that not supported by d3d9, but reported by wined3d for ddraw. Filter them out. */
267 if (!windowed
&& display_format
!= D3DFMT_X8R8G8B8
&& display_format
!= D3DFMT_R5G6B5
)
268 return WINED3DERR_NOTAVAILABLE
;
270 wined3d_mutex_lock();
271 hr
= wined3d_check_device_type(d3d9
->wined3d
, d3d9
->wined3d_outputs
[output_idx
],
272 wined3d_device_type_from_d3d(device_type
), wined3dformat_from_d3dformat(display_format
),
273 wined3dformat_from_d3dformat(backbuffer_format
), windowed
);
274 wined3d_mutex_unlock();
279 static HRESULT WINAPI
d3d9_CheckDeviceFormat(IDirect3D9Ex
*iface
, UINT adapter
, D3DDEVTYPE device_type
,
280 D3DFORMAT adapter_format
, DWORD usage
, D3DRESOURCETYPE resource_type
, D3DFORMAT format
)
282 struct d3d9
*d3d9
= impl_from_IDirect3D9Ex(iface
);
283 enum wined3d_resource_type wined3d_rtype
;
284 struct wined3d_adapter
*wined3d_adapter
;
285 unsigned int bind_flags
;
286 unsigned int output_idx
;
289 TRACE("iface %p, adapter %u, device_type %#x, adapter_format %#x, usage %#x, resource_type %#x, format %#x.\n",
290 iface
, adapter
, device_type
, adapter_format
, usage
, resource_type
, format
);
292 output_idx
= adapter
;
293 if (output_idx
>= d3d9
->wined3d_output_count
)
294 return D3DERR_INVALIDCALL
;
296 if (adapter_format
!= D3DFMT_X8R8G8B8
&& adapter_format
!= D3DFMT_R5G6B5
297 && adapter_format
!= D3DFMT_X1R5G5B5
)
299 WARN("Invalid adapter format.\n");
300 return adapter_format
? D3DERR_NOTAVAILABLE
: D3DERR_INVALIDCALL
;
303 bind_flags
= wined3d_bind_flags_from_d3d9_usage(usage
);
304 usage
= usage
& (WINED3DUSAGE_MASK
| WINED3DUSAGE_QUERY_MASK
);
305 switch (resource_type
)
307 case D3DRTYPE_CUBETEXTURE
:
308 usage
|= WINED3DUSAGE_LEGACY_CUBEMAP
;
309 case D3DRTYPE_TEXTURE
:
310 bind_flags
|= WINED3D_BIND_SHADER_RESOURCE
;
311 case D3DRTYPE_SURFACE
:
312 wined3d_rtype
= WINED3D_RTYPE_TEXTURE_2D
;
315 case D3DRTYPE_VOLUMETEXTURE
:
316 case D3DRTYPE_VOLUME
:
317 bind_flags
|= WINED3D_BIND_SHADER_RESOURCE
;
318 wined3d_rtype
= WINED3D_RTYPE_TEXTURE_3D
;
321 case D3DRTYPE_VERTEXBUFFER
:
322 case D3DRTYPE_INDEXBUFFER
:
323 wined3d_rtype
= WINED3D_RTYPE_BUFFER
;
327 FIXME("Unhandled resource type %#x.\n", resource_type
);
328 return WINED3DERR_INVALIDCALL
;
331 wined3d_mutex_lock();
332 wined3d_adapter
= wined3d_output_get_adapter(d3d9
->wined3d_outputs
[output_idx
]);
333 if (format
== D3DFMT_RESZ
&& resource_type
== D3DRTYPE_SURFACE
&& usage
== D3DUSAGE_RENDERTARGET
)
337 hr
= wined3d_check_device_multisample_type(wined3d_adapter
, wined3d_device_type_from_d3d(device_type
),
338 WINED3DFMT_D24_UNORM_S8_UINT
, FALSE
, WINED3D_MULTISAMPLE_NON_MASKABLE
, &levels
);
339 if (SUCCEEDED(hr
) && !levels
)
340 hr
= D3DERR_NOTAVAILABLE
;
343 hr
= wined3d_check_device_format(d3d9
->wined3d
, wined3d_adapter
, wined3d_device_type_from_d3d(device_type
),
344 wined3dformat_from_d3dformat(adapter_format
), usage
, bind_flags
,
345 wined3d_rtype
, wined3dformat_from_d3dformat(format
));
346 wined3d_mutex_unlock();
351 static HRESULT WINAPI
d3d9_CheckDeviceMultiSampleType(IDirect3D9Ex
*iface
, UINT adapter
, D3DDEVTYPE device_type
,
352 D3DFORMAT format
, BOOL windowed
, D3DMULTISAMPLE_TYPE multisample_type
, DWORD
*levels
)
354 struct d3d9
*d3d9
= impl_from_IDirect3D9Ex(iface
);
355 struct wined3d_adapter
*wined3d_adapter
;
356 unsigned int output_idx
;
359 TRACE("iface %p, adapter %u, device_type %#x, format %#x, windowed %#x, multisample_type %#x, levels %p.\n",
360 iface
, adapter
, device_type
, format
, windowed
, multisample_type
, levels
);
362 output_idx
= adapter
;
363 if (output_idx
>= d3d9
->wined3d_output_count
)
364 return D3DERR_INVALIDCALL
;
366 if (multisample_type
> D3DMULTISAMPLE_16_SAMPLES
)
367 return D3DERR_INVALIDCALL
;
369 wined3d_mutex_lock();
370 wined3d_adapter
= wined3d_output_get_adapter(d3d9
->wined3d_outputs
[output_idx
]);
371 hr
= wined3d_check_device_multisample_type(wined3d_adapter
,
372 wined3d_device_type_from_d3d(device_type
), wined3dformat_from_d3dformat(format
),
373 windowed
, wined3d_multisample_type_from_d3d(multisample_type
), levels
);
374 wined3d_mutex_unlock();
375 if (hr
== WINED3DERR_NOTAVAILABLE
&& levels
)
381 static HRESULT WINAPI
d3d9_CheckDepthStencilMatch(IDirect3D9Ex
*iface
, UINT adapter
, D3DDEVTYPE device_type
,
382 D3DFORMAT adapter_format
, D3DFORMAT rt_format
, D3DFORMAT ds_format
)
384 struct d3d9
*d3d9
= impl_from_IDirect3D9Ex(iface
);
385 struct wined3d_adapter
*wined3d_adapter
;
386 unsigned int output_idx
;
389 TRACE("iface %p, adapter %u, device_type %#x, adapter_format %#x, rt_format %#x, ds_format %#x.\n",
390 iface
, adapter
, device_type
, adapter_format
, rt_format
, ds_format
);
392 output_idx
= adapter
;
393 if (output_idx
>= d3d9
->wined3d_output_count
)
394 return D3DERR_INVALIDCALL
;
396 wined3d_mutex_lock();
397 wined3d_adapter
= wined3d_output_get_adapter(d3d9
->wined3d_outputs
[output_idx
]);
398 hr
= wined3d_check_depth_stencil_match(wined3d_adapter
,
399 wined3d_device_type_from_d3d(device_type
), wined3dformat_from_d3dformat(adapter_format
),
400 wined3dformat_from_d3dformat(rt_format
), wined3dformat_from_d3dformat(ds_format
));
401 wined3d_mutex_unlock();
406 static HRESULT WINAPI
d3d9_CheckDeviceFormatConversion(IDirect3D9Ex
*iface
, UINT adapter
,
407 D3DDEVTYPE device_type
, D3DFORMAT src_format
, D3DFORMAT dst_format
)
409 struct d3d9
*d3d9
= impl_from_IDirect3D9Ex(iface
);
410 unsigned int output_idx
;
413 TRACE("iface %p, adapter %u, device_type %#x, src_format %#x, dst_format %#x.\n",
414 iface
, adapter
, device_type
, src_format
, dst_format
);
416 output_idx
= adapter
;
417 if (output_idx
>= d3d9
->wined3d_output_count
)
418 return D3DERR_INVALIDCALL
;
420 wined3d_mutex_lock();
421 hr
= wined3d_check_device_format_conversion(d3d9
->wined3d_outputs
[output_idx
],
422 wined3d_device_type_from_d3d(device_type
), wined3dformat_from_d3dformat(src_format
),
423 wined3dformat_from_d3dformat(dst_format
));
424 wined3d_mutex_unlock();
429 static HRESULT WINAPI
d3d9_GetDeviceCaps(IDirect3D9Ex
*iface
, UINT adapter
, D3DDEVTYPE device_type
, D3DCAPS9
*caps
)
431 struct d3d9
*d3d9
= impl_from_IDirect3D9Ex(iface
);
432 struct wined3d_adapter
*wined3d_adapter
;
433 struct wined3d_caps wined3d_caps
;
434 unsigned int output_idx
;
437 TRACE("iface %p, adapter %u, device_type %#x, caps %p.\n", iface
, adapter
, device_type
, caps
);
439 output_idx
= adapter
;
440 if (output_idx
>= d3d9
->wined3d_output_count
)
441 return D3DERR_INVALIDCALL
;
444 return D3DERR_INVALIDCALL
;
446 memset(caps
, 0, sizeof(*caps
));
448 wined3d_mutex_lock();
449 wined3d_adapter
= wined3d_output_get_adapter(d3d9
->wined3d_outputs
[output_idx
]);
450 hr
= wined3d_get_device_caps(wined3d_adapter
, wined3d_device_type_from_d3d(device_type
), &wined3d_caps
);
451 wined3d_mutex_unlock();
453 d3d9_caps_from_wined3dcaps(d3d9
, adapter
, caps
, &wined3d_caps
);
458 static HMONITOR WINAPI
d3d9_GetAdapterMonitor(IDirect3D9Ex
*iface
, UINT adapter
)
460 struct d3d9
*d3d9
= impl_from_IDirect3D9Ex(iface
);
461 struct wined3d_output_desc desc
;
462 unsigned int output_idx
;
465 TRACE("iface %p, adapter %u.\n", iface
, adapter
);
467 output_idx
= adapter
;
468 if (output_idx
>= d3d9
->wined3d_output_count
)
471 wined3d_mutex_lock();
472 hr
= wined3d_output_get_desc(d3d9
->wined3d_outputs
[output_idx
], &desc
);
473 wined3d_mutex_unlock();
477 WARN("Failed to get output desc, hr %#x.\n", hr
);
484 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d9_CreateDevice(IDirect3D9Ex
*iface
, UINT adapter
,
485 D3DDEVTYPE device_type
, HWND focus_window
, DWORD flags
, D3DPRESENT_PARAMETERS
*parameters
,
486 IDirect3DDevice9
**device
)
488 struct d3d9
*d3d9
= impl_from_IDirect3D9Ex(iface
);
489 struct d3d9_device
*object
;
492 TRACE("iface %p, adapter %u, device_type %#x, focus_window %p, flags %#x, parameters %p, device %p.\n",
493 iface
, adapter
, device_type
, focus_window
, flags
, parameters
, device
);
495 if (!(object
= heap_alloc_zero(sizeof(*object
))))
496 return E_OUTOFMEMORY
;
498 hr
= device_init(object
, d3d9
, d3d9
->wined3d
, adapter
, device_type
, focus_window
, flags
, parameters
, NULL
);
501 WARN("Failed to initialize device, hr %#x.\n", hr
);
506 TRACE("Created device %p.\n", object
);
507 *device
= (IDirect3DDevice9
*)&object
->IDirect3DDevice9Ex_iface
;
512 static UINT WINAPI
d3d9_GetAdapterModeCountEx(IDirect3D9Ex
*iface
,
513 UINT adapter
, const D3DDISPLAYMODEFILTER
*filter
)
515 struct d3d9
*d3d9
= impl_from_IDirect3D9Ex(iface
);
516 unsigned int output_idx
, count
;
518 TRACE("iface %p, adapter %u, filter %p.\n", iface
, adapter
, filter
);
520 output_idx
= adapter
;
521 if (output_idx
>= d3d9
->wined3d_output_count
)
524 if (filter
->Format
!= D3DFMT_X8R8G8B8
&& filter
->Format
!= D3DFMT_R5G6B5
)
527 wined3d_mutex_lock();
528 count
= wined3d_output_get_mode_count(d3d9
->wined3d_outputs
[output_idx
],
529 wined3dformat_from_d3dformat(filter
->Format
), wined3d_scanline_ordering_from_d3d(filter
->ScanLineOrdering
));
530 wined3d_mutex_unlock();
535 static HRESULT WINAPI
d3d9_EnumAdapterModesEx(IDirect3D9Ex
*iface
,
536 UINT adapter
, const D3DDISPLAYMODEFILTER
*filter
, UINT mode_idx
, D3DDISPLAYMODEEX
*mode
)
538 struct d3d9
*d3d9
= impl_from_IDirect3D9Ex(iface
);
539 struct wined3d_display_mode wined3d_mode
;
540 unsigned int output_idx
;
543 TRACE("iface %p, adapter %u, filter %p, mode_idx %u, mode %p.\n",
544 iface
, adapter
, filter
, mode_idx
, mode
);
546 output_idx
= adapter
;
547 if (output_idx
>= d3d9
->wined3d_output_count
)
548 return D3DERR_INVALIDCALL
;
550 if (filter
->Format
!= D3DFMT_X8R8G8B8
&& filter
->Format
!= D3DFMT_R5G6B5
)
551 return D3DERR_INVALIDCALL
;
553 wined3d_mutex_lock();
554 hr
= wined3d_output_get_mode(d3d9
->wined3d_outputs
[output_idx
], wined3dformat_from_d3dformat(filter
->Format
),
555 wined3d_scanline_ordering_from_d3d(filter
->ScanLineOrdering
), mode_idx
, &wined3d_mode
);
556 wined3d_mutex_unlock();
560 mode
->Width
= wined3d_mode
.width
;
561 mode
->Height
= wined3d_mode
.height
;
562 mode
->RefreshRate
= wined3d_mode
.refresh_rate
;
563 mode
->Format
= d3dformat_from_wined3dformat(wined3d_mode
.format_id
);
564 mode
->ScanLineOrdering
= d3dscanlineordering_from_wined3d(wined3d_mode
.scanline_ordering
);
570 static HRESULT WINAPI
d3d9_GetAdapterDisplayModeEx(IDirect3D9Ex
*iface
,
571 UINT adapter
, D3DDISPLAYMODEEX
*mode
, D3DDISPLAYROTATION
*rotation
)
573 struct d3d9
*d3d9
= impl_from_IDirect3D9Ex(iface
);
574 struct wined3d_display_mode wined3d_mode
;
575 unsigned int output_idx
;
578 TRACE("iface %p, adapter %u, mode %p, rotation %p.\n",
579 iface
, adapter
, mode
, rotation
);
581 output_idx
= adapter
;
582 if (output_idx
>= d3d9
->wined3d_output_count
)
583 return D3DERR_INVALIDCALL
;
585 if (mode
->Size
!= sizeof(*mode
))
586 return D3DERR_INVALIDCALL
;
588 wined3d_mutex_lock();
589 hr
= wined3d_output_get_display_mode(d3d9
->wined3d_outputs
[output_idx
], &wined3d_mode
,
590 (enum wined3d_display_rotation
*)rotation
);
591 wined3d_mutex_unlock();
595 mode
->Width
= wined3d_mode
.width
;
596 mode
->Height
= wined3d_mode
.height
;
597 mode
->RefreshRate
= wined3d_mode
.refresh_rate
;
598 mode
->Format
= d3dformat_from_wined3dformat(wined3d_mode
.format_id
);
599 mode
->ScanLineOrdering
= d3dscanlineordering_from_wined3d(wined3d_mode
.scanline_ordering
);
605 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d9_CreateDeviceEx(IDirect3D9Ex
*iface
,
606 UINT adapter
, D3DDEVTYPE device_type
, HWND focus_window
, DWORD flags
,
607 D3DPRESENT_PARAMETERS
*parameters
, D3DDISPLAYMODEEX
*mode
, IDirect3DDevice9Ex
**device
)
609 struct d3d9
*d3d9
= impl_from_IDirect3D9Ex(iface
);
610 struct d3d9_device
*object
;
613 TRACE("iface %p, adapter %u, device_type %#x, focus_window %p, flags %#x, parameters %p, mode %p, device %p.\n",
614 iface
, adapter
, device_type
, focus_window
, flags
, parameters
, mode
, device
);
616 if (!(object
= heap_alloc_zero(sizeof(*object
))))
617 return E_OUTOFMEMORY
;
619 hr
= device_init(object
, d3d9
, d3d9
->wined3d
, adapter
, device_type
, focus_window
, flags
, parameters
, mode
);
622 WARN("Failed to initialize device, hr %#x.\n", hr
);
627 TRACE("Created device %p.\n", object
);
628 *device
= &object
->IDirect3DDevice9Ex_iface
;
633 static HRESULT WINAPI
d3d9_GetAdapterLUID(IDirect3D9Ex
*iface
, UINT adapter
, LUID
*luid
)
635 struct d3d9
*d3d9
= impl_from_IDirect3D9Ex(iface
);
636 struct wined3d_adapter_identifier adapter_id
;
637 struct wined3d_adapter
*wined3d_adapter
;
638 unsigned int output_idx
;
641 TRACE("iface %p, adapter %u, luid %p.\n", iface
, adapter
, luid
);
643 output_idx
= adapter
;
644 if (output_idx
>= d3d9
->wined3d_output_count
)
645 return D3DERR_INVALIDCALL
;
647 adapter_id
.driver_size
= 0;
648 adapter_id
.description_size
= 0;
650 wined3d_adapter
= wined3d_output_get_adapter(d3d9
->wined3d_outputs
[output_idx
]);
651 if (SUCCEEDED(hr
= wined3d_adapter_get_identifier(wined3d_adapter
, 0, &adapter_id
)))
652 *luid
= adapter_id
.adapter_luid
;
657 static const struct IDirect3D9ExVtbl d3d9_vtbl
=
664 d3d9_RegisterSoftwareDevice
,
665 d3d9_GetAdapterCount
,
666 d3d9_GetAdapterIdentifier
,
667 d3d9_GetAdapterModeCount
,
668 d3d9_EnumAdapterModes
,
669 d3d9_GetAdapterDisplayMode
,
670 d3d9_CheckDeviceType
,
671 d3d9_CheckDeviceFormat
,
672 d3d9_CheckDeviceMultiSampleType
,
673 d3d9_CheckDepthStencilMatch
,
674 d3d9_CheckDeviceFormatConversion
,
676 d3d9_GetAdapterMonitor
,
679 d3d9_GetAdapterModeCountEx
,
680 d3d9_EnumAdapterModesEx
,
681 d3d9_GetAdapterDisplayModeEx
,
686 BOOL
d3d9_init(struct d3d9
*d3d9
, BOOL extended
)
688 DWORD flags
= WINED3D_PRESENT_CONVERSION
| WINED3D_HANDLE_RESTORE
| WINED3D_PIXEL_CENTER_INTEGER
689 | WINED3D_SRGB_READ_WRITE_CONTROL
| WINED3D_LEGACY_UNBOUND_RESOURCE_COLOR
690 | WINED3D_NO_PRIMITIVE_RESTART
| WINED3D_LEGACY_CUBEMAP_FILTERING
691 | WINED3D_NORMALIZED_DEPTH_BIAS
;
692 unsigned int adapter_idx
, output_idx
, adapter_count
, output_count
= 0;
693 struct wined3d_adapter
*wined3d_adapter
;
696 flags
|= WINED3D_VIDMEM_ACCOUNTING
;
698 flags
|= WINED3D_RESTORE_MODE_ON_ACTIVATE
;
700 d3d9
->IDirect3D9Ex_iface
.lpVtbl
= &d3d9_vtbl
;
703 wined3d_mutex_lock();
704 d3d9
->wined3d
= wined3d_create(flags
);
707 wined3d_mutex_unlock();
711 adapter_count
= wined3d_get_adapter_count(d3d9
->wined3d
);
712 for (adapter_idx
= 0; adapter_idx
< adapter_count
; ++adapter_idx
)
714 wined3d_adapter
= wined3d_get_adapter(d3d9
->wined3d
, adapter_idx
);
715 output_count
+= wined3d_adapter_get_output_count(wined3d_adapter
);
718 d3d9
->wined3d_outputs
= heap_calloc(output_count
, sizeof(*d3d9
->wined3d_outputs
));
719 if (!d3d9
->wined3d_outputs
)
721 wined3d_decref(d3d9
->wined3d
);
722 wined3d_mutex_unlock();
726 d3d9
->wined3d_output_count
= 0;
727 for (adapter_idx
= 0; adapter_idx
< adapter_count
; ++adapter_idx
)
729 wined3d_adapter
= wined3d_get_adapter(d3d9
->wined3d
, adapter_idx
);
730 output_count
= wined3d_adapter_get_output_count(wined3d_adapter
);
731 for (output_idx
= 0; output_idx
< output_count
; ++output_idx
)
733 d3d9
->wined3d_outputs
[d3d9
->wined3d_output_count
] =
734 wined3d_adapter_get_output(wined3d_adapter
, output_idx
);
735 ++d3d9
->wined3d_output_count
;
739 wined3d_mutex_unlock();
740 d3d9
->extended
= extended
;