2 * Copyright 2008 Henri Verbeet for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "wine/test.h"
24 static HRESULT (WINAPI
*pCreateDXGIFactory1
)(REFIID iid
, void **factory
);
26 static ULONG
get_refcount(IUnknown
*iface
)
28 IUnknown_AddRef(iface
);
29 return IUnknown_Release(iface
);
32 static IDXGIDevice
*create_device(void)
34 IDXGIDevice
*dxgi_device
;
38 if (SUCCEEDED(D3D10CreateDevice(NULL
, D3D10_DRIVER_TYPE_HARDWARE
, NULL
, 0, D3D10_SDK_VERSION
, &device
)))
40 if (SUCCEEDED(D3D10CreateDevice(NULL
, D3D10_DRIVER_TYPE_WARP
, NULL
, 0, D3D10_SDK_VERSION
, &device
)))
42 if (SUCCEEDED(D3D10CreateDevice(NULL
, D3D10_DRIVER_TYPE_REFERENCE
, NULL
, 0, D3D10_SDK_VERSION
, &device
)))
48 hr
= ID3D10Device_QueryInterface(device
, &IID_IDXGIDevice
, (void **)&dxgi_device
);
49 ok(SUCCEEDED(hr
), "Created device does not implement IDXGIDevice\n");
50 ID3D10Device_Release(device
);
55 static void test_device_interfaces(void)
62 if (!(device
= create_device()))
64 skip("Failed to create device, skipping tests.\n");
68 hr
= IDXGIDevice_QueryInterface(device
, &IID_IUnknown
, (void **)&iface
);
69 ok(SUCCEEDED(hr
), "Failed to query IUnknown interface, hr %#x.\n", hr
);
70 IUnknown_Release(iface
);
72 hr
= IDXGIDevice_QueryInterface(device
, &IID_IDXGIObject
, (void **)&iface
);
73 ok(SUCCEEDED(hr
), "Failed to query IDXGIObject interface, hr %#x.\n", hr
);
74 IUnknown_Release(iface
);
76 hr
= IDXGIDevice_QueryInterface(device
, &IID_IDXGIDevice
, (void **)&iface
);
77 ok(SUCCEEDED(hr
), "Failed to query IDXGIDevice interface, hr %#x.\n", hr
);
78 IUnknown_Release(iface
);
80 hr
= IDXGIDevice_QueryInterface(device
, &IID_ID3D10Device
, (void **)&iface
);
81 ok(SUCCEEDED(hr
), "Failed to query ID3D10Device interface, hr %#x.\n", hr
);
82 IUnknown_Release(iface
);
84 hr
= IDXGIDevice_QueryInterface(device
, &IID_ID3D10Multithread
, (void **)&iface
);
85 ok(SUCCEEDED(hr
), "Failed to query ID3D10Multithread interface, hr %#x.\n", hr
);
86 IUnknown_Release(iface
);
88 if (SUCCEEDED(hr
= IDXGIDevice_QueryInterface(device
, &IID_ID3D10Device1
, (void **)&iface
)))
89 IUnknown_Release(iface
);
90 ok(SUCCEEDED(hr
) || broken(hr
== E_NOINTERFACE
) /* Not available on all Windows versions. */,
91 "Failed to query ID3D10Device1 interface, hr %#x.\n", hr
);
93 if (SUCCEEDED(hr
= IDXGIDevice_QueryInterface(device
, &IID_ID3D11Device
, (void **)&iface
)))
94 IUnknown_Release(iface
);
95 todo_wine
ok(SUCCEEDED(hr
) || broken(hr
== E_NOINTERFACE
) /* Not available on all Windows versions. */,
96 "Failed to query ID3D11Device interface, hr %#x.\n", hr
);
98 refcount
= IDXGIDevice_Release(device
);
99 ok(!refcount
, "Device has %u references left.\n", refcount
);
102 static void test_adapter_desc(void)
104 DXGI_ADAPTER_DESC1 desc1
;
105 IDXGIAdapter1
*adapter1
;
106 DXGI_ADAPTER_DESC desc
;
107 IDXGIAdapter
*adapter
;
112 if (!(device
= create_device()))
114 skip("Failed to create device, skipping tests.\n");
118 hr
= IDXGIDevice_GetAdapter(device
, &adapter
);
119 ok(SUCCEEDED(hr
), "GetAdapter failed, hr %#x.\n", hr
);
121 hr
= IDXGIAdapter_GetDesc(adapter
, NULL
);
122 ok(hr
== E_INVALIDARG
, "GetDesc returned %#x, expected %#x.\n",
125 hr
= IDXGIAdapter_GetDesc(adapter
, &desc
);
126 ok(SUCCEEDED(hr
), "GetDesc failed, hr %#x.\n", hr
);
128 trace("%s.\n", wine_dbgstr_w(desc
.Description
));
129 trace("%04x: %04x:%04x (rev %02x).\n",
130 desc
.SubSysId
, desc
.VendorId
, desc
.DeviceId
, desc
.Revision
);
131 trace("Dedicated video memory: %lu (%lu MB).\n",
132 desc
.DedicatedVideoMemory
, desc
.DedicatedVideoMemory
/ (1024 * 1024));
133 trace("Dedicated system memory: %lu (%lu MB).\n",
134 desc
.DedicatedSystemMemory
, desc
.DedicatedSystemMemory
/ (1024 * 1024));
135 trace("Shared system memory: %lu (%lu MB).\n",
136 desc
.SharedSystemMemory
, desc
.SharedSystemMemory
/ (1024 * 1024));
137 trace("LUID: %08x:%08x.\n", desc
.AdapterLuid
.HighPart
, desc
.AdapterLuid
.LowPart
);
139 hr
= IDXGIAdapter_QueryInterface(adapter
, &IID_IDXGIAdapter1
, (void **)&adapter1
);
140 ok(SUCCEEDED(hr
) || broken(hr
== E_NOINTERFACE
), "Got unexpected hr %#x.\n", hr
);
141 if (hr
== E_NOINTERFACE
)
144 hr
= IDXGIAdapter1_GetDesc1(adapter1
, &desc1
);
145 ok(SUCCEEDED(hr
), "GetDesc1 failed, hr %#x.\n", hr
);
147 ok(!lstrcmpW(desc
.Description
, desc1
.Description
),
148 "Got unexpected description %s.\n", wine_dbgstr_w(desc1
.Description
));
149 ok(desc1
.VendorId
== desc
.VendorId
, "Got unexpected vendor ID %04x.\n", desc1
.VendorId
);
150 ok(desc1
.DeviceId
== desc
.DeviceId
, "Got unexpected device ID %04x.\n", desc1
.DeviceId
);
151 ok(desc1
.SubSysId
== desc
.SubSysId
, "Got unexpected sub system ID %04x.\n", desc1
.SubSysId
);
152 ok(desc1
.Revision
== desc
.Revision
, "Got unexpected revision %02x.\n", desc1
.Revision
);
153 ok(desc1
.DedicatedVideoMemory
== desc
.DedicatedVideoMemory
,
154 "Got unexpected dedicated video memory %lu.\n", desc1
.DedicatedVideoMemory
);
155 ok(desc1
.DedicatedSystemMemory
== desc
.DedicatedSystemMemory
,
156 "Got unexpected dedicated system memory %lu.\n", desc1
.DedicatedSystemMemory
);
157 ok(desc1
.SharedSystemMemory
== desc
.SharedSystemMemory
,
158 "Got unexpected shared system memory %lu.\n", desc1
.SharedSystemMemory
);
159 ok(!memcmp(&desc
.AdapterLuid
, &desc1
.AdapterLuid
, sizeof(desc
.AdapterLuid
)),
160 "Got unexpected adapter LUID %08x:%08x.\n", desc1
.AdapterLuid
.HighPart
, desc1
.AdapterLuid
.LowPart
);
161 trace("Flags: %08x.\n", desc1
.Flags
);
163 IDXGIAdapter1_Release(adapter1
);
166 IDXGIAdapter_Release(adapter
);
167 refcount
= IDXGIDevice_Release(device
);
168 ok(!refcount
, "Device has %u references left.\n", refcount
);
171 static void test_create_surface(void)
173 ID3D10Texture2D
*texture
;
174 IDXGISurface
*surface
;
175 DXGI_SURFACE_DESC desc
;
180 if (!(device
= create_device()))
182 skip("Failed to create device, skipping tests.\n");
188 desc
.Format
= DXGI_FORMAT_R8G8B8A8_UNORM
;
189 desc
.SampleDesc
.Count
= 1;
190 desc
.SampleDesc
.Quality
= 0;
192 hr
= IDXGIDevice_CreateSurface(device
, &desc
, 1, DXGI_USAGE_RENDER_TARGET_OUTPUT
, NULL
, &surface
);
193 ok(SUCCEEDED(hr
), "Failed to create a dxgi surface, hr %#x\n", hr
);
195 hr
= IDXGISurface_QueryInterface(surface
, &IID_ID3D10Texture2D
, (void **)&texture
);
196 ok(SUCCEEDED(hr
), "Surface should implement ID3D10Texture2D\n");
197 if (SUCCEEDED(hr
)) ID3D10Texture2D_Release(texture
);
199 IDXGISurface_Release(surface
);
200 refcount
= IDXGIDevice_Release(device
);
201 ok(!refcount
, "Device has %u references left.\n", refcount
);
204 static void test_parents(void)
206 DXGI_SURFACE_DESC surface_desc
;
207 IDXGISurface
*surface
;
208 IDXGIFactory
*factory
;
209 IDXGIAdapter
*adapter
;
216 if (!(device
= create_device()))
218 skip("Failed to create device, skipping tests.\n");
222 surface_desc
.Width
= 512;
223 surface_desc
.Height
= 512;
224 surface_desc
.Format
= DXGI_FORMAT_R8G8B8A8_UNORM
;
225 surface_desc
.SampleDesc
.Count
= 1;
226 surface_desc
.SampleDesc
.Quality
= 0;
228 hr
= IDXGIDevice_CreateSurface(device
, &surface_desc
, 1, DXGI_USAGE_RENDER_TARGET_OUTPUT
, NULL
, &surface
);
229 ok(SUCCEEDED(hr
), "Failed to create a dxgi surface, hr %#x\n", hr
);
231 hr
= IDXGISurface_GetParent(surface
, &IID_IDXGIDevice
, (void **)&parent
);
232 IDXGISurface_Release(surface
);
233 ok(SUCCEEDED(hr
), "GetParent failed, hr %#x.\n", hr
);
234 ok(parent
== (IUnknown
*)device
, "Got parent %p, expected %p.\n", parent
, device
);
235 IUnknown_Release(parent
);
237 hr
= IDXGIDevice_GetAdapter(device
, &adapter
);
238 ok(SUCCEEDED(hr
), "GetAdapter failed, hr %#x.\n", hr
);
240 hr
= IDXGIAdapter_EnumOutputs(adapter
, 0, &output
);
241 if (hr
== DXGI_ERROR_NOT_FOUND
)
243 skip("Adapter has not outputs, skipping output tests.\n");
247 ok(SUCCEEDED(hr
), "EnumOutputs failed, hr %#x.\n", hr
);
249 hr
= IDXGIOutput_GetParent(output
, &IID_IDXGIAdapter
, (void **)&parent
);
250 IDXGIOutput_Release(output
);
251 ok(SUCCEEDED(hr
), "GetParent failed, hr %#x.\n", hr
);
252 ok(parent
== (IUnknown
*)adapter
, "Got parent %p, expected %p.\n", parent
, adapter
);
253 IUnknown_Release(parent
);
256 hr
= IDXGIAdapter_GetParent(adapter
, &IID_IDXGIFactory
, (void **)&factory
);
257 ok(SUCCEEDED(hr
), "GetParent failed, hr %#x.\n", hr
);
259 hr
= IDXGIFactory_GetParent(factory
, &IID_IUnknown
, (void **)&parent
);
260 ok(hr
== E_NOINTERFACE
, "GetParent returned %#x, expected %#x.\n", hr
, E_NOINTERFACE
);
261 ok(parent
== NULL
, "Got parent %p, expected %p.\n", parent
, NULL
);
262 IDXGIFactory_Release(factory
);
264 hr
= IDXGIDevice_GetParent(device
, &IID_IDXGIAdapter
, (void **)&parent
);
265 ok(SUCCEEDED(hr
), "GetParent failed, hr %#x.\n", hr
);
266 ok(parent
== (IUnknown
*)adapter
, "Got parent %p, expected %p.\n", parent
, adapter
);
267 IUnknown_Release(parent
);
269 IDXGIAdapter_Release(adapter
);
270 refcount
= IDXGIDevice_Release(device
);
271 ok(!refcount
, "Device has %u references left.\n", refcount
);
274 static void test_output(void)
276 IDXGIAdapter
*adapter
;
281 UINT mode_count
, mode_count_comp
, i
;
282 DXGI_MODE_DESC
*modes
;
284 if (!(device
= create_device()))
286 skip("Failed to create device, skipping tests.\n");
290 hr
= IDXGIDevice_GetAdapter(device
, &adapter
);
291 ok(SUCCEEDED(hr
), "GetAdapter failed, hr %#x.\n", hr
);
293 hr
= IDXGIAdapter_EnumOutputs(adapter
, 0, &output
);
294 if (hr
== DXGI_ERROR_NOT_FOUND
)
296 skip("Adapter doesn't have any outputs, skipping tests.\n");
297 IDXGIAdapter_Release(adapter
);
298 IDXGIDevice_Release(device
);
301 ok(SUCCEEDED(hr
), "EnumOutputs failed, hr %#x.\n", hr
);
303 hr
= IDXGIOutput_GetDisplayModeList(output
, DXGI_FORMAT_R8G8B8A8_UNORM
, 0, NULL
, NULL
);
304 ok(hr
== DXGI_ERROR_INVALID_CALL
, "Got unexpected hr %#x.\n", hr
);
306 hr
= IDXGIOutput_GetDisplayModeList(output
, DXGI_FORMAT_R8G8B8A8_UNORM
, 0, &mode_count
, NULL
);
308 || broken(hr
== DXGI_ERROR_NOT_CURRENTLY_AVAILABLE
), /* Remote Desktop Services / Win 7 testbot */
309 "Failed to list modes, hr %#x.\n", hr
);
310 if (hr
== DXGI_ERROR_NOT_CURRENTLY_AVAILABLE
)
312 skip("GetDisplayModeList() not supported, skipping tests.\n");
313 IDXGIOutput_Release(output
);
314 IDXGIAdapter_Release(adapter
);
315 IDXGIDevice_Release(device
);
318 mode_count_comp
= mode_count
;
320 hr
= IDXGIOutput_GetDisplayModeList(output
, 0, 0, &mode_count
, NULL
);
321 ok(SUCCEEDED(hr
), "Failed to list modes, hr %#x.\n", hr
);
322 ok(!mode_count
, "Got unexpected mode_count %u.\n", mode_count
);
324 hr
= IDXGIOutput_GetDisplayModeList(output
, DXGI_FORMAT_R8G8B8A8_UNORM
,
325 DXGI_ENUM_MODES_SCALING
, &mode_count
, NULL
);
326 ok(SUCCEEDED(hr
), "Failed to list modes, hr %#x.\n", hr
);
327 ok(mode_count
>= mode_count_comp
, "Got unexpected mode_count %u, expected >= %u.\n", mode_count
, mode_count_comp
);
328 mode_count_comp
= mode_count
;
330 modes
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*modes
) * (mode_count
+ 10));
332 hr
= IDXGIOutput_GetDisplayModeList(output
, DXGI_FORMAT_R8G8B8A8_UNORM
,
333 DXGI_ENUM_MODES_SCALING
, NULL
, modes
);
334 ok(hr
== DXGI_ERROR_INVALID_CALL
, "Got unexpected hr %#x.\n", hr
);
335 ok(!modes
[0].Height
, "No output was expected.\n");
338 hr
= IDXGIOutput_GetDisplayModeList(output
, DXGI_FORMAT_R8G8B8A8_UNORM
,
339 DXGI_ENUM_MODES_SCALING
, &mode_count
, modes
);
340 ok(hr
== DXGI_ERROR_MORE_DATA
, "Got unexpected hr %#x.\n", hr
);
341 ok(!modes
[0].Height
, "No output was expected.\n");
343 mode_count
= mode_count_comp
;
344 hr
= IDXGIOutput_GetDisplayModeList(output
, DXGI_FORMAT_R8G8B8A8_UNORM
,
345 DXGI_ENUM_MODES_SCALING
, &mode_count
, modes
);
346 ok(SUCCEEDED(hr
), "Failed to list modes, hr %#x.\n", hr
);
347 ok(mode_count
== mode_count_comp
, "Got unexpected mode_count %u, expected %u.\n", mode_count
, mode_count_comp
);
349 for (i
= 0; i
< mode_count
; i
++)
351 ok(modes
[i
].Height
&& modes
[i
].Width
, "Proper mode was expected\n");
355 hr
= IDXGIOutput_GetDisplayModeList(output
, DXGI_FORMAT_R8G8B8A8_UNORM
,
356 DXGI_ENUM_MODES_SCALING
, &mode_count
, modes
);
357 ok(SUCCEEDED(hr
), "Failed to list modes, hr %#x.\n", hr
);
358 ok(mode_count
== mode_count_comp
, "Got unexpected mode_count %u, expected %u.\n", mode_count
, mode_count_comp
);
362 mode_count
= mode_count_comp
- 1;
363 hr
= IDXGIOutput_GetDisplayModeList(output
, DXGI_FORMAT_R8G8B8A8_UNORM
,
364 DXGI_ENUM_MODES_SCALING
, &mode_count
, modes
);
365 ok(hr
== DXGI_ERROR_MORE_DATA
, "Got unexpected hr %#x.\n", hr
);
366 ok(mode_count
== mode_count_comp
- 1, "Got unexpected mode_count %u, expected %u.\n",
367 mode_count
, mode_count_comp
- 1);
371 skip("Not enough modes for test, skipping.\n");
374 HeapFree(GetProcessHeap(), 0, modes
);
375 IDXGIOutput_Release(output
);
376 IDXGIAdapter_Release(adapter
);
377 refcount
= IDXGIDevice_Release(device
);
378 ok(!refcount
, "Device has %u references left.\n", refcount
);
385 BOOL numerator_should_pass
;
386 BOOL denominator_should_pass
;
389 static void test_createswapchain(void)
392 IDXGIAdapter
*adapter
;
393 IDXGIFactory
*factory
;
396 IDXGISwapChain
*swapchain
;
397 DXGI_SWAP_CHAIN_DESC creation_desc
, result_desc
;
402 const struct refresh_rates refresh_list
[] =
404 {60, 60, FALSE
, FALSE
},
405 {60, 0, TRUE
, FALSE
},
407 { 0, 60, TRUE
, FALSE
},
408 { 0, 0, TRUE
, FALSE
},
411 if (!(device
= create_device()))
413 skip("Failed to create device, skipping tests.\n");
417 wc
.lpfnWndProc
= DefWindowProcA
;
418 wc
.lpszClassName
= "dxgi_test_wc";
422 creation_desc
.OutputWindow
= 0;
423 creation_desc
.BufferDesc
.Width
= 800;
424 creation_desc
.BufferDesc
.Height
= 600;
425 creation_desc
.BufferDesc
.RefreshRate
.Numerator
= 60;
426 creation_desc
.BufferDesc
.RefreshRate
.Denominator
= 60;
427 creation_desc
.BufferDesc
.Format
= DXGI_FORMAT_R8G8B8A8_UNORM
;
428 creation_desc
.BufferDesc
.ScanlineOrdering
= DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED
;
429 creation_desc
.BufferDesc
.Scaling
= DXGI_MODE_SCALING_UNSPECIFIED
;
430 creation_desc
.SampleDesc
.Count
= 1;
431 creation_desc
.SampleDesc
.Quality
= 0;
432 creation_desc
.BufferUsage
= DXGI_USAGE_RENDER_TARGET_OUTPUT
;
433 creation_desc
.BufferCount
= 1;
434 creation_desc
.OutputWindow
= CreateWindowA("dxgi_test_wc", "dxgi_test", 0, 0, 0, 0, 0, 0, 0, 0, 0);
435 creation_desc
.Windowed
= TRUE
;
436 creation_desc
.SwapEffect
= DXGI_SWAP_EFFECT_DISCARD
;
437 creation_desc
.Flags
= 0;
439 hr
= IDXGIDevice_QueryInterface(device
, &IID_IUnknown
, (void **)&obj
);
440 ok(SUCCEEDED(hr
), "IDXGIDevice does not implement IUnknown\n");
442 hr
= IDXGIDevice_GetAdapter(device
, &adapter
);
443 ok(SUCCEEDED(hr
), "GetAdapter failed, hr %#x.\n", hr
);
445 hr
= IDXGIAdapter_GetParent(adapter
, &IID_IDXGIFactory
, (void **)&factory
);
446 ok(SUCCEEDED(hr
), "GetParent failed, hr %#x.\n", hr
);
448 hr
= IDXGIFactory_CreateSwapChain(factory
, obj
, &creation_desc
, &swapchain
);
449 ok(SUCCEEDED(hr
), "CreateSwapChain failed, hr %#x.\n", hr
);
451 hr
= IDXGISwapChain_GetDesc(swapchain
, NULL
);
452 ok(hr
== E_INVALIDARG
, "GetDesc unexpectedly returned %#x.\n", hr
);
454 IDXGISwapChain_Release(swapchain
);
456 for (i
= 0; i
< sizeof(refresh_list
)/sizeof(refresh_list
[0]); i
++)
458 creation_desc
.BufferDesc
.RefreshRate
.Numerator
= refresh_list
[i
].numerator
;
459 creation_desc
.BufferDesc
.RefreshRate
.Denominator
= refresh_list
[i
].denominator
;
461 hr
= IDXGIFactory_CreateSwapChain(factory
, obj
, &creation_desc
, &swapchain
);
462 ok(SUCCEEDED(hr
), "CreateSwapChain failed, hr %#x.\n", hr
);
464 hr
= IDXGISwapChain_GetDesc(swapchain
, &result_desc
);
465 ok(SUCCEEDED(hr
), "GetDesc failed, hr %#x.\n", hr
);
467 if (refresh_list
[i
].numerator_should_pass
)
468 ok(result_desc
.BufferDesc
.RefreshRate
.Numerator
== refresh_list
[i
].numerator
,
469 "Numerator %u is %u.\n", i
, result_desc
.BufferDesc
.RefreshRate
.Numerator
);
471 todo_wine
ok(result_desc
.BufferDesc
.RefreshRate
.Numerator
== refresh_list
[i
].numerator
,
472 "Numerator %u is %u.\n", i
, result_desc
.BufferDesc
.RefreshRate
.Numerator
);
474 if (refresh_list
[i
].denominator_should_pass
)
475 ok(result_desc
.BufferDesc
.RefreshRate
.Denominator
== refresh_list
[i
].denominator
,
476 "Denominator %u is %u.\n", i
,result_desc
.BufferDesc
.RefreshRate
.Denominator
);
478 todo_wine
ok(result_desc
.BufferDesc
.RefreshRate
.Denominator
== refresh_list
[i
].denominator
,
479 "Denominator %u is %u.\n", i
, result_desc
.BufferDesc
.RefreshRate
.Denominator
);
481 IDXGISwapChain_Release(swapchain
);
484 creation_desc
.Windowed
= FALSE
;
486 for (i
= 0; i
< sizeof(refresh_list
)/sizeof(refresh_list
[0]); i
++)
488 creation_desc
.BufferDesc
.RefreshRate
.Numerator
= refresh_list
[i
].numerator
;
489 creation_desc
.BufferDesc
.RefreshRate
.Denominator
= refresh_list
[i
].denominator
;
491 hr
= IDXGIFactory_CreateSwapChain(factory
, obj
, &creation_desc
, &swapchain
);
492 ok(SUCCEEDED(hr
), "CreateSwapChain failed, hr %#x.\n", hr
);
494 hr
= IDXGISwapChain_GetDesc(swapchain
, &result_desc
);
495 ok(SUCCEEDED(hr
), "GetDesc failed, hr %#x.\n", hr
);
497 if (refresh_list
[i
].numerator_should_pass
)
498 ok(result_desc
.BufferDesc
.RefreshRate
.Numerator
== refresh_list
[i
].numerator
,
499 "Numerator %u is %u.\n", i
, result_desc
.BufferDesc
.RefreshRate
.Numerator
);
501 todo_wine
ok(result_desc
.BufferDesc
.RefreshRate
.Numerator
== refresh_list
[i
].numerator
,
502 "Numerator %u is %u.\n", i
, result_desc
.BufferDesc
.RefreshRate
.Numerator
);
504 if (refresh_list
[i
].denominator_should_pass
)
505 ok(result_desc
.BufferDesc
.RefreshRate
.Denominator
== refresh_list
[i
].denominator
,
506 "Denominator %u is %u.\n", i
,result_desc
.BufferDesc
.RefreshRate
.Denominator
);
508 todo_wine
ok(result_desc
.BufferDesc
.RefreshRate
.Denominator
== refresh_list
[i
].denominator
,
509 "Denominator %u is %u.\n", i
, result_desc
.BufferDesc
.RefreshRate
.Denominator
);
511 hr
= IDXGISwapChain_SetFullscreenState(swapchain
, FALSE
, NULL
);
512 todo_wine
ok(SUCCEEDED(hr
), "SetFullscreenState failed, hr %#x.\n", hr
);
514 IDXGISwapChain_Release(swapchain
);
517 IDXGIFactory_Release(factory
);
518 IDXGIAdapter_Release(adapter
);
519 IUnknown_Release(obj
);
520 refcount
= IDXGIDevice_Release(device
);
521 ok(!refcount
, "Device has %u references left.\n", refcount
);
524 static void test_create_factory(void)
526 IDXGIFactory1
*factory
;
530 iface
= (void *)0xdeadbeef;
531 hr
= CreateDXGIFactory(&IID_IDXGIDevice
, (void **)&iface
);
532 ok(hr
== E_NOINTERFACE
, "Got unexpected hr %#x.\n", hr
);
533 ok(!iface
, "Got unexpected iface %p.\n", iface
);
535 hr
= CreateDXGIFactory(&IID_IUnknown
, (void **)&iface
);
536 ok(SUCCEEDED(hr
), "Failed to create factory with IID_IUnknown, hr %#x.\n", hr
);
537 IUnknown_Release(iface
);
539 hr
= CreateDXGIFactory(&IID_IDXGIObject
, (void **)&iface
);
540 ok(SUCCEEDED(hr
), "Failed to create factory with IID_IDXGIObject, hr %#x.\n", hr
);
541 IUnknown_Release(iface
);
543 factory
= (void *)0xdeadbeef;
544 hr
= CreateDXGIFactory(&IID_IDXGIFactory
, (void **)&iface
);
545 ok(SUCCEEDED(hr
), "Failed to create factory with IID_IDXGIFactory, hr %#x.\n", hr
);
546 hr
= IUnknown_QueryInterface(iface
, &IID_IDXGIFactory1
, (void **)&factory
);
547 ok(hr
== E_NOINTERFACE
, "Got unexpected hr %#x.\n", hr
);
548 ok(!factory
, "Got unexpected factory %p.\n", factory
);
549 IUnknown_Release(iface
);
551 iface
= (void *)0xdeadbeef;
552 hr
= CreateDXGIFactory(&IID_IDXGIFactory1
, (void **)&iface
);
553 ok(hr
== E_NOINTERFACE
, "Got unexpected hr %#x.\n", hr
);
554 ok(!iface
, "Got unexpected iface %p.\n", iface
);
556 if (!pCreateDXGIFactory1
)
558 win_skip("CreateDXGIFactory1 not available, skipping tests.\n");
562 iface
= (void *)0xdeadbeef;
563 hr
= pCreateDXGIFactory1(&IID_IDXGIDevice
, (void **)&iface
);
564 ok(hr
== E_NOINTERFACE
, "Got unexpected hr %#x.\n", hr
);
565 ok(!iface
, "Got unexpected iface %p.\n", iface
);
567 hr
= pCreateDXGIFactory1(&IID_IUnknown
, (void **)&iface
);
568 ok(SUCCEEDED(hr
), "Failed to create factory with IID_IUnknown, hr %#x.\n", hr
);
569 IUnknown_Release(iface
);
571 hr
= pCreateDXGIFactory1(&IID_IDXGIObject
, (void **)&iface
);
572 ok(SUCCEEDED(hr
), "Failed to create factory with IID_IDXGIObject, hr %#x.\n", hr
);
573 IUnknown_Release(iface
);
575 hr
= pCreateDXGIFactory1(&IID_IDXGIFactory
, (void **)&iface
);
576 ok(SUCCEEDED(hr
), "Failed to create factory with IID_IDXGIFactory, hr %#x.\n", hr
);
577 hr
= IUnknown_QueryInterface(iface
, &IID_IDXGIFactory1
, (void **)&factory
);
578 ok(SUCCEEDED(hr
), "Failed to query IDXGIFactory1 interface, hr %#x.\n", hr
);
579 IDXGIFactory1_Release(factory
);
580 IUnknown_Release(iface
);
582 hr
= pCreateDXGIFactory1(&IID_IDXGIFactory1
, (void **)&iface
);
583 ok(SUCCEEDED(hr
), "Failed to create factory with IID_IDXGIFactory1, hr %#x.\n", hr
);
584 IUnknown_Release(iface
);
587 static void test_private_data(void)
589 ULONG refcount
, expected_refcount
;
592 IDXGIDevice
*test_object
;
594 static const DWORD data
[] = {1, 2, 3, 4};
596 static const GUID dxgi_private_data_test_guid
=
601 {0xa3, 0x7f, 0x9b, 0x1d, 0xf4, 0x88, 0xc5, 0xfc}
603 static const GUID dxgi_private_data_test_guid2
=
608 {0x9b, 0x4b, 0x89, 0xd7, 0xd1, 0x12, 0xe7, 0x2b}
611 if (!(device
= create_device()))
613 skip("Failed to create device, skipping tests.\n");
617 test_object
= create_device();
619 /* SetPrivateData with a pointer of NULL has the purpose of FreePrivateData in previous
620 * d3d versions. A successful clear returns S_OK. A redundant clear S_FALSE. Setting a
621 * NULL interface is not considered a clear but as setting an interface pointer that
622 * happens to be NULL. */
623 hr
= IDXGIDevice_SetPrivateData(device
, &dxgi_private_data_test_guid
, 0, NULL
);
624 ok(hr
== S_FALSE
, "Got unexpected hr %#x.\n", hr
);
625 hr
= IDXGIDevice_SetPrivateDataInterface(device
, &dxgi_private_data_test_guid
, NULL
);
626 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
627 hr
= IDXGIDevice_SetPrivateData(device
, &dxgi_private_data_test_guid
, ~0U, NULL
);
628 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
629 hr
= IDXGIDevice_SetPrivateData(device
, &dxgi_private_data_test_guid
, ~0U, NULL
);
630 ok(hr
== S_FALSE
, "Got unexpected hr %#x.\n", hr
);
632 hr
= IDXGIDevice_SetPrivateDataInterface(device
, &dxgi_private_data_test_guid
, NULL
);
633 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
634 size
= sizeof(ptr
) * 2;
635 ptr
= (IUnknown
*)0xdeadbeef;
636 hr
= IDXGIDevice_GetPrivateData(device
, &dxgi_private_data_test_guid
, &size
, &ptr
);
637 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
638 ok(!ptr
, "Got unexpected pointer %p.\n", ptr
);
639 ok(size
== sizeof(IUnknown
*), "Got unexpected size %u.\n", size
);
641 refcount
= get_refcount((IUnknown
*)test_object
);
642 hr
= IDXGIDevice_SetPrivateDataInterface(device
, &dxgi_private_data_test_guid
,
643 (IUnknown
*)test_object
);
644 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
645 expected_refcount
= refcount
+ 1;
646 refcount
= get_refcount((IUnknown
*)test_object
);
647 ok(refcount
== expected_refcount
, "Got unexpected refcount %u, expected %u.\n", refcount
, expected_refcount
);
648 hr
= IDXGIDevice_SetPrivateDataInterface(device
, &dxgi_private_data_test_guid
,
649 (IUnknown
*)test_object
);
650 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
651 refcount
= get_refcount((IUnknown
*)test_object
);
652 ok(refcount
== expected_refcount
, "Got unexpected refcount %u, expected %u.\n", refcount
, expected_refcount
);
654 hr
= IDXGIDevice_SetPrivateDataInterface(device
, &dxgi_private_data_test_guid
, NULL
);
655 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
657 refcount
= get_refcount((IUnknown
*)test_object
);
658 ok(refcount
== expected_refcount
, "Got unexpected refcount %u, expected %u.\n", refcount
, expected_refcount
);
660 hr
= IDXGIDevice_SetPrivateDataInterface(device
, &dxgi_private_data_test_guid
,
661 (IUnknown
*)test_object
);
662 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
664 hr
= IDXGIDevice_SetPrivateData(device
, &dxgi_private_data_test_guid
, size
, data
);
665 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
666 refcount
= get_refcount((IUnknown
*)test_object
);
667 ok(refcount
== expected_refcount
, "Got unexpected refcount %u, expected %u.\n", refcount
, expected_refcount
);
668 hr
= IDXGIDevice_SetPrivateData(device
, &dxgi_private_data_test_guid
, 42, NULL
);
669 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
670 hr
= IDXGIDevice_SetPrivateData(device
, &dxgi_private_data_test_guid
, 42, NULL
);
671 ok(hr
== S_FALSE
, "Got unexpected hr %#x.\n", hr
);
673 hr
= IDXGIDevice_SetPrivateDataInterface(device
, &dxgi_private_data_test_guid
,
674 (IUnknown
*)test_object
);
675 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
677 size
= 2 * sizeof(ptr
);
679 hr
= IDXGIDevice_GetPrivateData(device
, &dxgi_private_data_test_guid
, &size
, &ptr
);
680 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
681 ok(size
== sizeof(test_object
), "Got unexpected size %u.\n", size
);
683 refcount
= get_refcount((IUnknown
*)test_object
);
684 ok(refcount
== expected_refcount
, "Got unexpected refcount %u, expected %u.\n", refcount
, expected_refcount
);
686 IUnknown_Release(ptr
);
689 ptr
= (IUnknown
*)0xdeadbeef;
691 hr
= IDXGIDevice_GetPrivateData(device
, &dxgi_private_data_test_guid
, &size
, NULL
);
692 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
693 ok(size
== sizeof(device
), "Got unexpected size %u.\n", size
);
694 size
= 2 * sizeof(ptr
);
695 hr
= IDXGIDevice_GetPrivateData(device
, &dxgi_private_data_test_guid
, &size
, NULL
);
696 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
697 ok(size
== sizeof(device
), "Got unexpected size %u.\n", size
);
698 refcount
= get_refcount((IUnknown
*)test_object
);
699 ok(refcount
== expected_refcount
, "Got unexpected refcount %u, expected %u.\n", refcount
, expected_refcount
);
702 hr
= IDXGIDevice_GetPrivateData(device
, &dxgi_private_data_test_guid
, &size
, &ptr
);
703 ok(hr
== DXGI_ERROR_MORE_DATA
, "Got unexpected hr %#x.\n", hr
);
704 ok(size
== sizeof(device
), "Got unexpected size %u.\n", size
);
705 ok(ptr
== (IUnknown
*)0xdeadbeef, "Got unexpected pointer %p.\n", ptr
);
706 hr
= IDXGIDevice_GetPrivateData(device
, &dxgi_private_data_test_guid2
, NULL
, NULL
);
707 ok(hr
== E_INVALIDARG
, "Got unexpected hr %#x.\n", hr
);
709 hr
= IDXGIDevice_GetPrivateData(device
, &dxgi_private_data_test_guid2
, &size
, &ptr
);
710 ok(hr
== DXGI_ERROR_NOT_FOUND
, "Got unexpected hr %#x.\n", hr
);
711 ok(size
== 0, "Got unexpected size %u.\n", size
);
712 ok(ptr
== (IUnknown
*)0xdeadbeef, "Got unexpected pointer %p.\n", ptr
);
713 hr
= IDXGIDevice_GetPrivateData(device
, &dxgi_private_data_test_guid
, NULL
, &ptr
);
714 ok(hr
== E_INVALIDARG
, "Got unexpected hr %#x.\n", hr
);
715 ok(ptr
== (IUnknown
*)0xdeadbeef, "Got unexpected pointer %p.\n", ptr
);
717 refcount
= IDXGIDevice_Release(device
);
718 ok(!refcount
, "Device has %u references left.\n", refcount
);
719 refcount
= IDXGIDevice_Release(test_object
);
720 ok(!refcount
, "Test object has %u references left.\n", refcount
);
725 pCreateDXGIFactory1
= (void *)GetProcAddress(GetModuleHandleA("dxgi.dll"), "CreateDXGIFactory1");
728 test_device_interfaces();
729 test_create_surface();
732 test_createswapchain();
733 test_create_factory();