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 %lu.\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 %lu.\n", iface
, refcount
);
84 wined3d_decref(d3d9
->wined3d
);
86 free(d3d9
->wined3d_outputs
);
93 static HRESULT WINAPI
d3d9_RegisterSoftwareDevice(IDirect3D9Ex
*iface
, void *init_function
)
95 struct d3d9
*d3d9
= impl_from_IDirect3D9Ex(iface
);
98 TRACE("iface %p, init_function %p.\n", iface
, init_function
);
100 wined3d_mutex_lock();
101 hr
= wined3d_register_software_device(d3d9
->wined3d
, init_function
);
102 wined3d_mutex_unlock();
107 static UINT WINAPI
d3d9_GetAdapterCount(IDirect3D9Ex
*iface
)
109 struct d3d9
*d3d9
= impl_from_IDirect3D9Ex(iface
);
111 TRACE("iface %p.\n", iface
);
113 return d3d9
->wined3d_output_count
;
116 static HRESULT WINAPI
d3d9_GetAdapterIdentifier(IDirect3D9Ex
*iface
, UINT adapter
,
117 DWORD flags
, D3DADAPTER_IDENTIFIER9
*identifier
)
119 struct d3d9
*d3d9
= impl_from_IDirect3D9Ex(iface
);
120 struct wined3d_adapter_identifier adapter_id
;
121 struct wined3d_adapter
*wined3d_adapter
;
122 struct wined3d_output_desc output_desc
;
123 unsigned int output_idx
;
126 TRACE("iface %p, adapter %u, flags %#lx, identifier %p.\n",
127 iface
, adapter
, flags
, identifier
);
129 output_idx
= adapter
;
130 if (output_idx
>= d3d9
->wined3d_output_count
)
131 return D3DERR_INVALIDCALL
;
133 wined3d_mutex_lock();
134 if (FAILED(hr
= wined3d_output_get_desc(d3d9
->wined3d_outputs
[output_idx
], &output_desc
)))
136 wined3d_mutex_unlock();
137 WARN("Failed to get output description, hr %#lx.\n", hr
);
140 WideCharToMultiByte(CP_ACP
, 0, output_desc
.device_name
, -1, identifier
->DeviceName
,
141 sizeof(identifier
->DeviceName
), NULL
, NULL
);
143 adapter_id
.driver
= identifier
->Driver
;
144 adapter_id
.driver_size
= sizeof(identifier
->Driver
);
145 adapter_id
.description
= identifier
->Description
;
146 adapter_id
.description_size
= sizeof(identifier
->Description
);
148 wined3d_adapter
= wined3d_output_get_adapter(d3d9
->wined3d_outputs
[output_idx
]);
149 if (SUCCEEDED(hr
= wined3d_adapter_get_identifier(wined3d_adapter
, flags
, &adapter_id
)))
151 identifier
->DriverVersion
= adapter_id
.driver_version
;
152 identifier
->VendorId
= adapter_id
.vendor_id
;
153 identifier
->DeviceId
= adapter_id
.device_id
;
154 identifier
->SubSysId
= adapter_id
.subsystem_id
;
155 identifier
->Revision
= adapter_id
.revision
;
156 memcpy(&identifier
->DeviceIdentifier
, &adapter_id
.device_identifier
, sizeof(identifier
->DeviceIdentifier
));
157 identifier
->WHQLLevel
= adapter_id
.whql_level
;
159 wined3d_mutex_unlock();
164 static UINT WINAPI
d3d9_GetAdapterModeCount(IDirect3D9Ex
*iface
, UINT adapter
, D3DFORMAT format
)
166 struct d3d9
*d3d9
= impl_from_IDirect3D9Ex(iface
);
167 unsigned int output_idx
, count
;
169 TRACE("iface %p, adapter %u, format %#x.\n", iface
, adapter
, format
);
171 output_idx
= adapter
;
172 if (output_idx
>= d3d9
->wined3d_output_count
)
175 /* Others than that not supported by d3d9, but reported by wined3d for ddraw. Filter them out. */
176 if (format
!= D3DFMT_X8R8G8B8
&& format
!= D3DFMT_R5G6B5
)
179 wined3d_mutex_lock();
180 count
= wined3d_output_get_mode_count(d3d9
->wined3d_outputs
[output_idx
],
181 wined3dformat_from_d3dformat(format
), WINED3D_SCANLINE_ORDERING_UNKNOWN
, true);
182 wined3d_mutex_unlock();
187 static HRESULT WINAPI
d3d9_EnumAdapterModes(IDirect3D9Ex
*iface
, UINT adapter
,
188 D3DFORMAT format
, UINT mode_idx
, D3DDISPLAYMODE
*mode
)
190 struct d3d9
*d3d9
= impl_from_IDirect3D9Ex(iface
);
191 struct wined3d_display_mode wined3d_mode
;
192 unsigned int output_idx
;
195 TRACE("iface %p, adapter %u, format %#x, mode_idx %u, mode %p.\n",
196 iface
, adapter
, format
, mode_idx
, mode
);
198 output_idx
= adapter
;
199 if (output_idx
>= d3d9
->wined3d_output_count
)
200 return D3DERR_INVALIDCALL
;
202 if (format
!= D3DFMT_X8R8G8B8
&& format
!= D3DFMT_R5G6B5
)
203 return D3DERR_INVALIDCALL
;
205 wined3d_mutex_lock();
206 hr
= wined3d_output_get_mode(d3d9
->wined3d_outputs
[output_idx
], wined3dformat_from_d3dformat(format
),
207 WINED3D_SCANLINE_ORDERING_UNKNOWN
, mode_idx
, &wined3d_mode
, true);
208 wined3d_mutex_unlock();
212 mode
->Width
= wined3d_mode
.width
;
213 mode
->Height
= wined3d_mode
.height
;
214 mode
->RefreshRate
= wined3d_mode
.refresh_rate
;
215 mode
->Format
= d3dformat_from_wined3dformat(wined3d_mode
.format_id
);
221 static HRESULT WINAPI
d3d9_GetAdapterDisplayMode(IDirect3D9Ex
*iface
, UINT adapter
, D3DDISPLAYMODE
*mode
)
223 struct d3d9
*d3d9
= impl_from_IDirect3D9Ex(iface
);
224 struct wined3d_display_mode wined3d_mode
;
225 unsigned int output_idx
;
228 TRACE("iface %p, adapter %u, mode %p.\n", iface
, adapter
, mode
);
230 output_idx
= adapter
;
231 if (output_idx
>= d3d9
->wined3d_output_count
)
232 return D3DERR_INVALIDCALL
;
234 wined3d_mutex_lock();
235 hr
= wined3d_output_get_display_mode(d3d9
->wined3d_outputs
[output_idx
], &wined3d_mode
, NULL
);
236 wined3d_mutex_unlock();
240 mode
->Width
= wined3d_mode
.width
;
241 mode
->Height
= wined3d_mode
.height
;
242 mode
->RefreshRate
= wined3d_mode
.refresh_rate
;
243 mode
->Format
= d3dformat_from_wined3dformat(wined3d_mode
.format_id
);
249 static HRESULT WINAPI
d3d9_CheckDeviceType(IDirect3D9Ex
*iface
, UINT adapter
, D3DDEVTYPE device_type
,
250 D3DFORMAT display_format
, D3DFORMAT backbuffer_format
, BOOL windowed
)
252 struct d3d9
*d3d9
= impl_from_IDirect3D9Ex(iface
);
253 unsigned int output_idx
;
256 TRACE("iface %p, adapter %u, device_type %#x, display_format %#x, backbuffer_format %#x, windowed %#x.\n",
257 iface
, adapter
, device_type
, display_format
, backbuffer_format
, windowed
);
259 output_idx
= adapter
;
260 if (output_idx
>= d3d9
->wined3d_output_count
)
261 return D3DERR_INVALIDCALL
;
263 /* Others than that not supported by d3d9, but reported by wined3d for ddraw. Filter them out. */
264 if (!windowed
&& display_format
!= D3DFMT_X8R8G8B8
&& display_format
!= D3DFMT_R5G6B5
)
265 return WINED3DERR_NOTAVAILABLE
;
267 wined3d_mutex_lock();
268 hr
= wined3d_check_device_type(d3d9
->wined3d
, d3d9
->wined3d_outputs
[output_idx
],
269 wined3d_device_type_from_d3d(device_type
), wined3dformat_from_d3dformat(display_format
),
270 wined3dformat_from_d3dformat(backbuffer_format
), windowed
);
271 wined3d_mutex_unlock();
276 static HRESULT WINAPI
d3d9_CheckDeviceFormat(IDirect3D9Ex
*iface
, UINT adapter
, D3DDEVTYPE device_type
,
277 D3DFORMAT adapter_format
, DWORD usage
, D3DRESOURCETYPE resource_type
, D3DFORMAT format
)
279 struct d3d9
*d3d9
= impl_from_IDirect3D9Ex(iface
);
280 enum wined3d_resource_type wined3d_rtype
;
281 struct wined3d_adapter
*wined3d_adapter
;
282 unsigned int bind_flags
;
283 unsigned int output_idx
;
286 TRACE("iface %p, adapter %u, device_type %#x, adapter_format %#x, usage %#lx, resource_type %#x, format %#x.\n",
287 iface
, adapter
, device_type
, adapter_format
, usage
, resource_type
, format
);
289 output_idx
= adapter
;
290 if (output_idx
>= d3d9
->wined3d_output_count
)
291 return D3DERR_INVALIDCALL
;
293 if (adapter_format
!= D3DFMT_X8R8G8B8
&& adapter_format
!= D3DFMT_R5G6B5
294 && adapter_format
!= D3DFMT_X1R5G5B5
)
296 WARN("Invalid adapter format.\n");
297 return adapter_format
? D3DERR_NOTAVAILABLE
: D3DERR_INVALIDCALL
;
300 bind_flags
= wined3d_bind_flags_from_d3d9_usage(usage
);
301 usage
= usage
& (WINED3DUSAGE_MASK
| WINED3DUSAGE_QUERY_MASK
);
302 switch (resource_type
)
304 case D3DRTYPE_CUBETEXTURE
:
305 usage
|= WINED3DUSAGE_LEGACY_CUBEMAP
;
306 case D3DRTYPE_TEXTURE
:
307 bind_flags
|= WINED3D_BIND_SHADER_RESOURCE
;
308 case D3DRTYPE_SURFACE
:
309 wined3d_rtype
= WINED3D_RTYPE_TEXTURE_2D
;
312 case D3DRTYPE_VOLUMETEXTURE
:
313 case D3DRTYPE_VOLUME
:
314 bind_flags
|= WINED3D_BIND_SHADER_RESOURCE
;
315 wined3d_rtype
= WINED3D_RTYPE_TEXTURE_3D
;
318 case D3DRTYPE_VERTEXBUFFER
:
319 case D3DRTYPE_INDEXBUFFER
:
320 wined3d_rtype
= WINED3D_RTYPE_BUFFER
;
324 FIXME("Unhandled resource type %#x.\n", resource_type
);
325 return WINED3DERR_INVALIDCALL
;
328 wined3d_mutex_lock();
329 wined3d_adapter
= wined3d_output_get_adapter(d3d9
->wined3d_outputs
[output_idx
]);
330 if (format
== D3DFMT_RESZ
&& resource_type
== D3DRTYPE_SURFACE
&& usage
== D3DUSAGE_RENDERTARGET
)
334 hr
= wined3d_check_device_multisample_type(wined3d_adapter
, wined3d_device_type_from_d3d(device_type
),
335 WINED3DFMT_D24_UNORM_S8_UINT
, FALSE
, WINED3D_MULTISAMPLE_NON_MASKABLE
, &levels
);
336 if (SUCCEEDED(hr
) && !levels
)
337 hr
= D3DERR_NOTAVAILABLE
;
340 hr
= wined3d_check_device_format(d3d9
->wined3d
, wined3d_adapter
, wined3d_device_type_from_d3d(device_type
),
341 wined3dformat_from_d3dformat(adapter_format
), usage
, bind_flags
,
342 wined3d_rtype
, wined3dformat_from_d3dformat(format
));
343 wined3d_mutex_unlock();
348 static HRESULT WINAPI
d3d9_CheckDeviceMultiSampleType(IDirect3D9Ex
*iface
, UINT adapter
, D3DDEVTYPE device_type
,
349 D3DFORMAT format
, BOOL windowed
, D3DMULTISAMPLE_TYPE multisample_type
, DWORD
*levels
)
351 struct d3d9
*d3d9
= impl_from_IDirect3D9Ex(iface
);
352 struct wined3d_adapter
*wined3d_adapter
;
353 unsigned int output_idx
;
356 TRACE("iface %p, adapter %u, device_type %#x, format %#x, windowed %#x, multisample_type %#x, levels %p.\n",
357 iface
, adapter
, device_type
, format
, windowed
, multisample_type
, levels
);
359 output_idx
= adapter
;
360 if (output_idx
>= d3d9
->wined3d_output_count
)
361 return D3DERR_INVALIDCALL
;
363 if (multisample_type
> D3DMULTISAMPLE_16_SAMPLES
)
364 return D3DERR_INVALIDCALL
;
366 wined3d_mutex_lock();
367 wined3d_adapter
= wined3d_output_get_adapter(d3d9
->wined3d_outputs
[output_idx
]);
368 hr
= wined3d_check_device_multisample_type(wined3d_adapter
,
369 wined3d_device_type_from_d3d(device_type
), wined3dformat_from_d3dformat(format
),
370 windowed
, wined3d_multisample_type_from_d3d(multisample_type
), (unsigned int *)levels
);
371 wined3d_mutex_unlock();
372 if (hr
== WINED3DERR_NOTAVAILABLE
&& levels
)
378 static HRESULT WINAPI
d3d9_CheckDepthStencilMatch(IDirect3D9Ex
*iface
, UINT adapter
, D3DDEVTYPE device_type
,
379 D3DFORMAT adapter_format
, D3DFORMAT rt_format
, D3DFORMAT ds_format
)
381 struct d3d9
*d3d9
= impl_from_IDirect3D9Ex(iface
);
382 struct wined3d_adapter
*wined3d_adapter
;
383 unsigned int output_idx
;
386 TRACE("iface %p, adapter %u, device_type %#x, adapter_format %#x, rt_format %#x, ds_format %#x.\n",
387 iface
, adapter
, device_type
, adapter_format
, rt_format
, ds_format
);
389 output_idx
= adapter
;
390 if (output_idx
>= d3d9
->wined3d_output_count
)
391 return D3DERR_INVALIDCALL
;
393 wined3d_mutex_lock();
394 wined3d_adapter
= wined3d_output_get_adapter(d3d9
->wined3d_outputs
[output_idx
]);
395 hr
= wined3d_check_depth_stencil_match(wined3d_adapter
,
396 wined3d_device_type_from_d3d(device_type
), wined3dformat_from_d3dformat(adapter_format
),
397 wined3dformat_from_d3dformat(rt_format
), wined3dformat_from_d3dformat(ds_format
));
398 wined3d_mutex_unlock();
403 static HRESULT WINAPI
d3d9_CheckDeviceFormatConversion(IDirect3D9Ex
*iface
, UINT adapter
,
404 D3DDEVTYPE device_type
, D3DFORMAT src_format
, D3DFORMAT dst_format
)
406 struct d3d9
*d3d9
= impl_from_IDirect3D9Ex(iface
);
407 unsigned int output_idx
;
410 TRACE("iface %p, adapter %u, device_type %#x, src_format %#x, dst_format %#x.\n",
411 iface
, adapter
, device_type
, src_format
, dst_format
);
413 output_idx
= adapter
;
414 if (output_idx
>= d3d9
->wined3d_output_count
)
415 return D3DERR_INVALIDCALL
;
417 wined3d_mutex_lock();
418 hr
= wined3d_check_device_format_conversion(d3d9
->wined3d_outputs
[output_idx
],
419 wined3d_device_type_from_d3d(device_type
), wined3dformat_from_d3dformat(src_format
),
420 wined3dformat_from_d3dformat(dst_format
));
421 wined3d_mutex_unlock();
426 static HRESULT WINAPI
d3d9_GetDeviceCaps(IDirect3D9Ex
*iface
, UINT adapter
, D3DDEVTYPE device_type
, D3DCAPS9
*caps
)
428 struct d3d9
*d3d9
= impl_from_IDirect3D9Ex(iface
);
429 struct wined3d_adapter
*wined3d_adapter
;
430 struct wined3d_caps wined3d_caps
;
431 unsigned int output_idx
;
434 TRACE("iface %p, adapter %u, device_type %#x, caps %p.\n", iface
, adapter
, device_type
, caps
);
436 output_idx
= adapter
;
437 if (output_idx
>= d3d9
->wined3d_output_count
)
438 return D3DERR_INVALIDCALL
;
441 return D3DERR_INVALIDCALL
;
443 memset(caps
, 0, sizeof(*caps
));
445 wined3d_mutex_lock();
446 wined3d_adapter
= wined3d_output_get_adapter(d3d9
->wined3d_outputs
[output_idx
]);
447 hr
= wined3d_get_device_caps(wined3d_adapter
, wined3d_device_type_from_d3d(device_type
), &wined3d_caps
);
448 wined3d_mutex_unlock();
450 d3d9_caps_from_wined3dcaps(d3d9
, adapter
, caps
, &wined3d_caps
);
455 static HMONITOR WINAPI
d3d9_GetAdapterMonitor(IDirect3D9Ex
*iface
, UINT adapter
)
457 struct d3d9
*d3d9
= impl_from_IDirect3D9Ex(iface
);
458 struct wined3d_output_desc desc
;
459 unsigned int output_idx
;
462 TRACE("iface %p, adapter %u.\n", iface
, adapter
);
464 output_idx
= adapter
;
465 if (output_idx
>= d3d9
->wined3d_output_count
)
468 wined3d_mutex_lock();
469 hr
= wined3d_output_get_desc(d3d9
->wined3d_outputs
[output_idx
], &desc
);
470 wined3d_mutex_unlock();
474 WARN("Failed to get output desc, hr %#lx.\n", hr
);
481 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d9_CreateDevice(IDirect3D9Ex
*iface
, UINT adapter
,
482 D3DDEVTYPE device_type
, HWND focus_window
, DWORD flags
, D3DPRESENT_PARAMETERS
*parameters
,
483 IDirect3DDevice9
**device
)
485 struct d3d9
*d3d9
= impl_from_IDirect3D9Ex(iface
);
486 struct d3d9_device
*object
;
489 TRACE("iface %p, adapter %u, device_type %#x, focus_window %p, flags %#lx, parameters %p, device %p.\n",
490 iface
, adapter
, device_type
, focus_window
, flags
, parameters
, device
);
492 if (!(object
= calloc(1, sizeof(*object
))))
493 return E_OUTOFMEMORY
;
495 hr
= device_init(object
, d3d9
, d3d9
->wined3d
, adapter
, device_type
, focus_window
, flags
, parameters
, NULL
);
498 WARN("Failed to initialize device, hr %#lx.\n", hr
);
503 TRACE("Created device %p.\n", object
);
504 *device
= (IDirect3DDevice9
*)&object
->IDirect3DDevice9Ex_iface
;
509 static UINT WINAPI
d3d9_GetAdapterModeCountEx(IDirect3D9Ex
*iface
,
510 UINT adapter
, const D3DDISPLAYMODEFILTER
*filter
)
512 struct d3d9
*d3d9
= impl_from_IDirect3D9Ex(iface
);
513 unsigned int output_idx
, count
;
515 TRACE("iface %p, adapter %u, filter %p.\n", iface
, adapter
, filter
);
517 output_idx
= adapter
;
518 if (output_idx
>= d3d9
->wined3d_output_count
)
521 if (filter
->Format
!= D3DFMT_X8R8G8B8
&& filter
->Format
!= D3DFMT_R5G6B5
)
524 wined3d_mutex_lock();
525 count
= wined3d_output_get_mode_count(d3d9
->wined3d_outputs
[output_idx
],
526 wined3dformat_from_d3dformat(filter
->Format
), wined3d_scanline_ordering_from_d3d(filter
->ScanLineOrdering
), true);
527 wined3d_mutex_unlock();
532 static HRESULT WINAPI
d3d9_EnumAdapterModesEx(IDirect3D9Ex
*iface
,
533 UINT adapter
, const D3DDISPLAYMODEFILTER
*filter
, UINT mode_idx
, D3DDISPLAYMODEEX
*mode
)
535 struct d3d9
*d3d9
= impl_from_IDirect3D9Ex(iface
);
536 struct wined3d_display_mode wined3d_mode
;
537 unsigned int output_idx
;
540 TRACE("iface %p, adapter %u, filter %p, mode_idx %u, mode %p.\n",
541 iface
, adapter
, filter
, mode_idx
, mode
);
543 output_idx
= adapter
;
544 if (output_idx
>= d3d9
->wined3d_output_count
)
545 return D3DERR_INVALIDCALL
;
547 if (filter
->Format
!= D3DFMT_X8R8G8B8
&& filter
->Format
!= D3DFMT_R5G6B5
)
548 return D3DERR_INVALIDCALL
;
550 wined3d_mutex_lock();
551 hr
= wined3d_output_get_mode(d3d9
->wined3d_outputs
[output_idx
], wined3dformat_from_d3dformat(filter
->Format
),
552 wined3d_scanline_ordering_from_d3d(filter
->ScanLineOrdering
), mode_idx
, &wined3d_mode
, true);
553 wined3d_mutex_unlock();
557 mode
->Width
= wined3d_mode
.width
;
558 mode
->Height
= wined3d_mode
.height
;
559 mode
->RefreshRate
= wined3d_mode
.refresh_rate
;
560 mode
->Format
= d3dformat_from_wined3dformat(wined3d_mode
.format_id
);
561 mode
->ScanLineOrdering
= d3dscanlineordering_from_wined3d(wined3d_mode
.scanline_ordering
);
567 static HRESULT WINAPI
d3d9_GetAdapterDisplayModeEx(IDirect3D9Ex
*iface
,
568 UINT adapter
, D3DDISPLAYMODEEX
*mode
, D3DDISPLAYROTATION
*rotation
)
570 struct d3d9
*d3d9
= impl_from_IDirect3D9Ex(iface
);
571 struct wined3d_display_mode wined3d_mode
;
572 unsigned int output_idx
;
575 TRACE("iface %p, adapter %u, mode %p, rotation %p.\n",
576 iface
, adapter
, mode
, rotation
);
578 output_idx
= adapter
;
579 if (output_idx
>= d3d9
->wined3d_output_count
)
580 return D3DERR_INVALIDCALL
;
582 if (mode
->Size
!= sizeof(*mode
))
583 return D3DERR_INVALIDCALL
;
585 wined3d_mutex_lock();
586 hr
= wined3d_output_get_display_mode(d3d9
->wined3d_outputs
[output_idx
], &wined3d_mode
,
587 (enum wined3d_display_rotation
*)rotation
);
588 wined3d_mutex_unlock();
592 mode
->Width
= wined3d_mode
.width
;
593 mode
->Height
= wined3d_mode
.height
;
594 mode
->RefreshRate
= wined3d_mode
.refresh_rate
;
595 mode
->Format
= d3dformat_from_wined3dformat(wined3d_mode
.format_id
);
596 mode
->ScanLineOrdering
= d3dscanlineordering_from_wined3d(wined3d_mode
.scanline_ordering
);
602 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d9_CreateDeviceEx(IDirect3D9Ex
*iface
,
603 UINT adapter
, D3DDEVTYPE device_type
, HWND focus_window
, DWORD flags
,
604 D3DPRESENT_PARAMETERS
*parameters
, D3DDISPLAYMODEEX
*mode
, IDirect3DDevice9Ex
**device
)
606 struct d3d9
*d3d9
= impl_from_IDirect3D9Ex(iface
);
607 struct d3d9_device
*object
;
610 TRACE("iface %p, adapter %u, device_type %#x, focus_window %p, flags %#lx, parameters %p, mode %p, device %p.\n",
611 iface
, adapter
, device_type
, focus_window
, flags
, parameters
, mode
, device
);
613 if (!(object
= calloc(1, sizeof(*object
))))
614 return E_OUTOFMEMORY
;
616 hr
= device_init(object
, d3d9
, d3d9
->wined3d
, adapter
, device_type
, focus_window
, flags
, parameters
, mode
);
619 WARN("Failed to initialize device, hr %#lx.\n", hr
);
624 TRACE("Created device %p.\n", object
);
625 *device
= &object
->IDirect3DDevice9Ex_iface
;
630 static HRESULT WINAPI
d3d9_GetAdapterLUID(IDirect3D9Ex
*iface
, UINT adapter
, LUID
*luid
)
632 struct d3d9
*d3d9
= impl_from_IDirect3D9Ex(iface
);
633 struct wined3d_adapter_identifier adapter_id
;
634 struct wined3d_adapter
*wined3d_adapter
;
635 unsigned int output_idx
;
638 TRACE("iface %p, adapter %u, luid %p.\n", iface
, adapter
, luid
);
640 output_idx
= adapter
;
641 if (output_idx
>= d3d9
->wined3d_output_count
)
642 return D3DERR_INVALIDCALL
;
644 adapter_id
.driver_size
= 0;
645 adapter_id
.description_size
= 0;
647 wined3d_adapter
= wined3d_output_get_adapter(d3d9
->wined3d_outputs
[output_idx
]);
648 if (SUCCEEDED(hr
= wined3d_adapter_get_identifier(wined3d_adapter
, 0, &adapter_id
)))
649 *luid
= adapter_id
.adapter_luid
;
654 static const struct IDirect3D9ExVtbl d3d9_vtbl
=
661 d3d9_RegisterSoftwareDevice
,
662 d3d9_GetAdapterCount
,
663 d3d9_GetAdapterIdentifier
,
664 d3d9_GetAdapterModeCount
,
665 d3d9_EnumAdapterModes
,
666 d3d9_GetAdapterDisplayMode
,
667 d3d9_CheckDeviceType
,
668 d3d9_CheckDeviceFormat
,
669 d3d9_CheckDeviceMultiSampleType
,
670 d3d9_CheckDepthStencilMatch
,
671 d3d9_CheckDeviceFormatConversion
,
673 d3d9_GetAdapterMonitor
,
676 d3d9_GetAdapterModeCountEx
,
677 d3d9_EnumAdapterModesEx
,
678 d3d9_GetAdapterDisplayModeEx
,
683 BOOL
d3d9_init(struct d3d9
*d3d9
, BOOL extended
)
685 DWORD flags
= WINED3D_PRESENT_CONVERSION
| WINED3D_HANDLE_RESTORE
| WINED3D_PIXEL_CENTER_INTEGER
686 | WINED3D_SRGB_READ_WRITE_CONTROL
| WINED3D_LEGACY_UNBOUND_RESOURCE_COLOR
687 | WINED3D_NO_PRIMITIVE_RESTART
| WINED3D_LEGACY_CUBEMAP_FILTERING
688 | WINED3D_NORMALIZED_DEPTH_BIAS
| WINED3D_NO_DRAW_INDIRECT
;
689 unsigned int adapter_idx
, output_idx
, adapter_count
, output_count
= 0;
690 struct wined3d_adapter
*wined3d_adapter
;
693 flags
|= WINED3D_RESTORE_MODE_ON_ACTIVATE
;
695 d3d9
->IDirect3D9Ex_iface
.lpVtbl
= &d3d9_vtbl
;
698 wined3d_mutex_lock();
699 d3d9
->wined3d
= wined3d_create(flags
);
702 wined3d_mutex_unlock();
706 adapter_count
= wined3d_get_adapter_count(d3d9
->wined3d
);
707 for (adapter_idx
= 0; adapter_idx
< adapter_count
; ++adapter_idx
)
709 wined3d_adapter
= wined3d_get_adapter(d3d9
->wined3d
, adapter_idx
);
710 output_count
+= wined3d_adapter_get_output_count(wined3d_adapter
);
713 d3d9
->wined3d_outputs
= calloc(output_count
, sizeof(*d3d9
->wined3d_outputs
));
714 if (!d3d9
->wined3d_outputs
)
716 wined3d_decref(d3d9
->wined3d
);
717 wined3d_mutex_unlock();
721 d3d9
->wined3d_output_count
= 0;
722 for (adapter_idx
= 0; adapter_idx
< adapter_count
; ++adapter_idx
)
724 wined3d_adapter
= wined3d_get_adapter(d3d9
->wined3d
, adapter_idx
);
725 output_count
= wined3d_adapter_get_output_count(wined3d_adapter
);
726 for (output_idx
= 0; output_idx
< output_count
; ++output_idx
)
728 d3d9
->wined3d_outputs
[d3d9
->wined3d_output_count
] =
729 wined3d_adapter_get_output(wined3d_adapter
, output_idx
);
730 ++d3d9
->wined3d_output_count
;
734 wined3d_mutex_unlock();
735 d3d9
->extended
= extended
;