Sweden-Number/dlls/dxgi/tests/device.c

1228 lines
59 KiB
C

/*
* Copyright 2008 Henri Verbeet for CodeWeavers
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#define COBJMACROS
#include "initguid.h"
#include "d3d11.h"
#include "wine/test.h"
static DEVMODEW registry_mode;
static HRESULT (WINAPI *pCreateDXGIFactory1)(REFIID iid, void **factory);
static ULONG get_refcount(IUnknown *iface)
{
IUnknown_AddRef(iface);
return IUnknown_Release(iface);
}
static IDXGIDevice *create_device(void)
{
IDXGIDevice *dxgi_device;
ID3D10Device *device;
HRESULT hr;
if (SUCCEEDED(D3D10CreateDevice(NULL, D3D10_DRIVER_TYPE_HARDWARE, NULL, 0, D3D10_SDK_VERSION, &device)))
goto success;
if (SUCCEEDED(D3D10CreateDevice(NULL, D3D10_DRIVER_TYPE_WARP, NULL, 0, D3D10_SDK_VERSION, &device)))
goto success;
if (SUCCEEDED(D3D10CreateDevice(NULL, D3D10_DRIVER_TYPE_REFERENCE, NULL, 0, D3D10_SDK_VERSION, &device)))
goto success;
return NULL;
success:
hr = ID3D10Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
ok(SUCCEEDED(hr), "Created device does not implement IDXGIDevice\n");
ID3D10Device_Release(device);
return dxgi_device;
}
static void test_device_interfaces(void)
{
IDXGIDevice *device;
IUnknown *iface;
ULONG refcount;
HRESULT hr;
if (!(device = create_device()))
{
skip("Failed to create device, skipping tests.\n");
return;
}
hr = IDXGIDevice_QueryInterface(device, &IID_IUnknown, (void **)&iface);
ok(SUCCEEDED(hr), "Failed to query IUnknown interface, hr %#x.\n", hr);
IUnknown_Release(iface);
hr = IDXGIDevice_QueryInterface(device, &IID_IDXGIObject, (void **)&iface);
ok(SUCCEEDED(hr), "Failed to query IDXGIObject interface, hr %#x.\n", hr);
IUnknown_Release(iface);
hr = IDXGIDevice_QueryInterface(device, &IID_IDXGIDevice, (void **)&iface);
ok(SUCCEEDED(hr), "Failed to query IDXGIDevice interface, hr %#x.\n", hr);
IUnknown_Release(iface);
hr = IDXGIDevice_QueryInterface(device, &IID_ID3D10Device, (void **)&iface);
ok(SUCCEEDED(hr), "Failed to query ID3D10Device interface, hr %#x.\n", hr);
IUnknown_Release(iface);
hr = IDXGIDevice_QueryInterface(device, &IID_ID3D10Multithread, (void **)&iface);
ok(SUCCEEDED(hr), "Failed to query ID3D10Multithread interface, hr %#x.\n", hr);
IUnknown_Release(iface);
if (SUCCEEDED(hr = IDXGIDevice_QueryInterface(device, &IID_ID3D10Device1, (void **)&iface)))
IUnknown_Release(iface);
ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
"Failed to query ID3D10Device1 interface, hr %#x.\n", hr);
if (SUCCEEDED(hr = IDXGIDevice_QueryInterface(device, &IID_ID3D11Device, (void **)&iface)))
IUnknown_Release(iface);
ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
"Failed to query ID3D11Device interface, hr %#x.\n", hr);
refcount = IDXGIDevice_Release(device);
ok(!refcount, "Device has %u references left.\n", refcount);
}
static void test_adapter_desc(void)
{
DXGI_ADAPTER_DESC1 desc1;
IDXGIAdapter1 *adapter1;
DXGI_ADAPTER_DESC desc;
IDXGIAdapter *adapter;
IDXGIDevice *device;
ULONG refcount;
HRESULT hr;
if (!(device = create_device()))
{
skip("Failed to create device, skipping tests.\n");
return;
}
hr = IDXGIDevice_GetAdapter(device, &adapter);
ok(SUCCEEDED(hr), "GetAdapter failed, hr %#x.\n", hr);
hr = IDXGIAdapter_GetDesc(adapter, NULL);
ok(hr == E_INVALIDARG, "GetDesc returned %#x, expected %#x.\n",
hr, E_INVALIDARG);
hr = IDXGIAdapter_GetDesc(adapter, &desc);
ok(SUCCEEDED(hr), "GetDesc failed, hr %#x.\n", hr);
trace("%s.\n", wine_dbgstr_w(desc.Description));
trace("%04x: %04x:%04x (rev %02x).\n",
desc.SubSysId, desc.VendorId, desc.DeviceId, desc.Revision);
trace("Dedicated video memory: %lu (%lu MB).\n",
desc.DedicatedVideoMemory, desc.DedicatedVideoMemory / (1024 * 1024));
trace("Dedicated system memory: %lu (%lu MB).\n",
desc.DedicatedSystemMemory, desc.DedicatedSystemMemory / (1024 * 1024));
trace("Shared system memory: %lu (%lu MB).\n",
desc.SharedSystemMemory, desc.SharedSystemMemory / (1024 * 1024));
trace("LUID: %08x:%08x.\n", desc.AdapterLuid.HighPart, desc.AdapterLuid.LowPart);
hr = IDXGIAdapter_QueryInterface(adapter, &IID_IDXGIAdapter1, (void **)&adapter1);
ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE), "Got unexpected hr %#x.\n", hr);
if (hr == E_NOINTERFACE)
goto done;
hr = IDXGIAdapter1_GetDesc1(adapter1, &desc1);
ok(SUCCEEDED(hr), "GetDesc1 failed, hr %#x.\n", hr);
ok(!lstrcmpW(desc.Description, desc1.Description),
"Got unexpected description %s.\n", wine_dbgstr_w(desc1.Description));
ok(desc1.VendorId == desc.VendorId, "Got unexpected vendor ID %04x.\n", desc1.VendorId);
ok(desc1.DeviceId == desc.DeviceId, "Got unexpected device ID %04x.\n", desc1.DeviceId);
ok(desc1.SubSysId == desc.SubSysId, "Got unexpected sub system ID %04x.\n", desc1.SubSysId);
ok(desc1.Revision == desc.Revision, "Got unexpected revision %02x.\n", desc1.Revision);
ok(desc1.DedicatedVideoMemory == desc.DedicatedVideoMemory,
"Got unexpected dedicated video memory %lu.\n", desc1.DedicatedVideoMemory);
ok(desc1.DedicatedSystemMemory == desc.DedicatedSystemMemory,
"Got unexpected dedicated system memory %lu.\n", desc1.DedicatedSystemMemory);
ok(desc1.SharedSystemMemory == desc.SharedSystemMemory,
"Got unexpected shared system memory %lu.\n", desc1.SharedSystemMemory);
ok(!memcmp(&desc.AdapterLuid, &desc1.AdapterLuid, sizeof(desc.AdapterLuid)),
"Got unexpected adapter LUID %08x:%08x.\n", desc1.AdapterLuid.HighPart, desc1.AdapterLuid.LowPart);
trace("Flags: %08x.\n", desc1.Flags);
IDXGIAdapter1_Release(adapter1);
done:
IDXGIAdapter_Release(adapter);
refcount = IDXGIDevice_Release(device);
ok(!refcount, "Device has %u references left.\n", refcount);
}
static void test_create_surface(void)
{
DXGI_SURFACE_DESC desc;
IDXGISurface *surface;
IDXGIDevice *device;
IUnknown *texture;
ULONG refcount;
HRESULT hr;
if (!(device = create_device()))
{
skip("Failed to create device, skipping tests.\n");
return;
}
desc.Width = 512;
desc.Height = 512;
desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
desc.SampleDesc.Count = 1;
desc.SampleDesc.Quality = 0;
hr = IDXGIDevice_CreateSurface(device, &desc, 1, DXGI_USAGE_RENDER_TARGET_OUTPUT, NULL, &surface);
ok(SUCCEEDED(hr), "Failed to create a dxgi surface, hr %#x\n", hr);
hr = IDXGISurface_QueryInterface(surface, &IID_ID3D10Texture2D, (void **)&texture);
ok(SUCCEEDED(hr), "Surface should implement ID3D10Texture2D\n");
IUnknown_Release(texture);
hr = IDXGISurface_QueryInterface(surface, &IID_ID3D11Texture2D, (void **)&texture);
ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
"Surface should implement ID3D11Texture2D.\n");
if (SUCCEEDED(hr)) IUnknown_Release(texture);
IDXGISurface_Release(surface);
refcount = IDXGIDevice_Release(device);
ok(!refcount, "Device has %u references left.\n", refcount);
}
static void test_parents(void)
{
DXGI_SURFACE_DESC surface_desc;
IDXGISurface *surface;
IDXGIFactory *factory;
IDXGIAdapter *adapter;
IDXGIDevice *device;
IDXGIOutput *output;
IUnknown *parent;
ULONG refcount;
HRESULT hr;
if (!(device = create_device()))
{
skip("Failed to create device, skipping tests.\n");
return;
}
surface_desc.Width = 512;
surface_desc.Height = 512;
surface_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
surface_desc.SampleDesc.Count = 1;
surface_desc.SampleDesc.Quality = 0;
hr = IDXGIDevice_CreateSurface(device, &surface_desc, 1, DXGI_USAGE_RENDER_TARGET_OUTPUT, NULL, &surface);
ok(SUCCEEDED(hr), "Failed to create a dxgi surface, hr %#x\n", hr);
hr = IDXGISurface_GetParent(surface, &IID_IDXGIDevice, (void **)&parent);
IDXGISurface_Release(surface);
ok(SUCCEEDED(hr), "GetParent failed, hr %#x.\n", hr);
ok(parent == (IUnknown *)device, "Got parent %p, expected %p.\n", parent, device);
IUnknown_Release(parent);
hr = IDXGIDevice_GetAdapter(device, &adapter);
ok(SUCCEEDED(hr), "GetAdapter failed, hr %#x.\n", hr);
hr = IDXGIAdapter_EnumOutputs(adapter, 0, &output);
if (hr == DXGI_ERROR_NOT_FOUND)
{
skip("Adapter has not outputs, skipping output tests.\n");
}
else
{
ok(SUCCEEDED(hr), "EnumOutputs failed, hr %#x.\n", hr);
hr = IDXGIOutput_GetParent(output, &IID_IDXGIAdapter, (void **)&parent);
IDXGIOutput_Release(output);
ok(SUCCEEDED(hr), "GetParent failed, hr %#x.\n", hr);
ok(parent == (IUnknown *)adapter, "Got parent %p, expected %p.\n", parent, adapter);
IUnknown_Release(parent);
}
hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
ok(SUCCEEDED(hr), "GetParent failed, hr %#x.\n", hr);
hr = IDXGIFactory_GetParent(factory, &IID_IUnknown, (void **)&parent);
ok(hr == E_NOINTERFACE, "GetParent returned %#x, expected %#x.\n", hr, E_NOINTERFACE);
ok(parent == NULL, "Got parent %p, expected %p.\n", parent, NULL);
IDXGIFactory_Release(factory);
hr = IDXGIDevice_GetParent(device, &IID_IDXGIAdapter, (void **)&parent);
ok(SUCCEEDED(hr), "GetParent failed, hr %#x.\n", hr);
ok(parent == (IUnknown *)adapter, "Got parent %p, expected %p.\n", parent, adapter);
IUnknown_Release(parent);
IDXGIAdapter_Release(adapter);
refcount = IDXGIDevice_Release(device);
ok(!refcount, "Device has %u references left.\n", refcount);
}
static void test_output(void)
{
IDXGIAdapter *adapter;
IDXGIDevice *device;
HRESULT hr;
IDXGIOutput *output;
ULONG refcount;
UINT mode_count, mode_count_comp, i;
DXGI_MODE_DESC *modes;
if (!(device = create_device()))
{
skip("Failed to create device, skipping tests.\n");
return;
}
hr = IDXGIDevice_GetAdapter(device, &adapter);
ok(SUCCEEDED(hr), "GetAdapter failed, hr %#x.\n", hr);
hr = IDXGIAdapter_EnumOutputs(adapter, 0, &output);
if (hr == DXGI_ERROR_NOT_FOUND)
{
skip("Adapter doesn't have any outputs, skipping tests.\n");
IDXGIAdapter_Release(adapter);
IDXGIDevice_Release(device);
return;
}
ok(SUCCEEDED(hr), "EnumOutputs failed, hr %#x.\n", hr);
hr = IDXGIOutput_GetDisplayModeList(output, DXGI_FORMAT_R8G8B8A8_UNORM, 0, NULL, NULL);
ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
hr = IDXGIOutput_GetDisplayModeList(output, DXGI_FORMAT_R8G8B8A8_UNORM, 0, &mode_count, NULL);
ok(SUCCEEDED(hr)
|| broken(hr == DXGI_ERROR_NOT_CURRENTLY_AVAILABLE), /* Remote Desktop Services / Win 7 testbot */
"Failed to list modes, hr %#x.\n", hr);
if (hr == DXGI_ERROR_NOT_CURRENTLY_AVAILABLE)
{
skip("GetDisplayModeList() not supported, skipping tests.\n");
IDXGIOutput_Release(output);
IDXGIAdapter_Release(adapter);
IDXGIDevice_Release(device);
return;
}
mode_count_comp = mode_count;
hr = IDXGIOutput_GetDisplayModeList(output, 0, 0, &mode_count, NULL);
ok(SUCCEEDED(hr), "Failed to list modes, hr %#x.\n", hr);
ok(!mode_count, "Got unexpected mode_count %u.\n", mode_count);
hr = IDXGIOutput_GetDisplayModeList(output, DXGI_FORMAT_R8G8B8A8_UNORM,
DXGI_ENUM_MODES_SCALING, &mode_count, NULL);
ok(SUCCEEDED(hr), "Failed to list modes, hr %#x.\n", hr);
ok(mode_count >= mode_count_comp, "Got unexpected mode_count %u, expected >= %u.\n", mode_count, mode_count_comp);
mode_count_comp = mode_count;
modes = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*modes) * (mode_count + 10));
hr = IDXGIOutput_GetDisplayModeList(output, DXGI_FORMAT_R8G8B8A8_UNORM,
DXGI_ENUM_MODES_SCALING, NULL, modes);
ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
ok(!modes[0].Height, "No output was expected.\n");
mode_count = 0;
hr = IDXGIOutput_GetDisplayModeList(output, DXGI_FORMAT_R8G8B8A8_UNORM,
DXGI_ENUM_MODES_SCALING, &mode_count, modes);
ok(hr == DXGI_ERROR_MORE_DATA, "Got unexpected hr %#x.\n", hr);
ok(!modes[0].Height, "No output was expected.\n");
mode_count = mode_count_comp;
hr = IDXGIOutput_GetDisplayModeList(output, DXGI_FORMAT_R8G8B8A8_UNORM,
DXGI_ENUM_MODES_SCALING, &mode_count, modes);
ok(SUCCEEDED(hr), "Failed to list modes, hr %#x.\n", hr);
ok(mode_count == mode_count_comp, "Got unexpected mode_count %u, expected %u.\n", mode_count, mode_count_comp);
for (i = 0; i < mode_count; i++)
{
ok(modes[i].Height && modes[i].Width, "Proper mode was expected\n");
}
mode_count += 5;
hr = IDXGIOutput_GetDisplayModeList(output, DXGI_FORMAT_R8G8B8A8_UNORM,
DXGI_ENUM_MODES_SCALING, &mode_count, modes);
ok(SUCCEEDED(hr), "Failed to list modes, hr %#x.\n", hr);
ok(mode_count == mode_count_comp, "Got unexpected mode_count %u, expected %u.\n", mode_count, mode_count_comp);
if (mode_count_comp)
{
mode_count = mode_count_comp - 1;
hr = IDXGIOutput_GetDisplayModeList(output, DXGI_FORMAT_R8G8B8A8_UNORM,
DXGI_ENUM_MODES_SCALING, &mode_count, modes);
ok(hr == DXGI_ERROR_MORE_DATA, "Got unexpected hr %#x.\n", hr);
ok(mode_count == mode_count_comp - 1, "Got unexpected mode_count %u, expected %u.\n",
mode_count, mode_count_comp - 1);
}
else
{
skip("Not enough modes for test, skipping.\n");
}
HeapFree(GetProcessHeap(), 0, modes);
IDXGIOutput_Release(output);
IDXGIAdapter_Release(adapter);
refcount = IDXGIDevice_Release(device);
ok(!refcount, "Device has %u references left.\n", refcount);
}
struct refresh_rates
{
UINT numerator;
UINT denominator;
BOOL numerator_should_pass;
BOOL denominator_should_pass;
};
static void test_createswapchain(void)
{
IUnknown *obj;
IDXGIAdapter *adapter;
IDXGIFactory *factory;
IDXGIDevice *device;
ULONG refcount;
IDXGISwapChain *swapchain;
DXGI_SWAP_CHAIN_DESC creation_desc, result_desc;
HRESULT hr;
UINT i;
const struct refresh_rates refresh_list[] =
{
{60, 60, FALSE, FALSE},
{60, 0, TRUE, FALSE},
{60, 1, TRUE, TRUE},
{ 0, 60, TRUE, FALSE},
{ 0, 0, TRUE, FALSE},
};
if (!(device = create_device()))
{
skip("Failed to create device, skipping tests.\n");
return;
}
creation_desc.OutputWindow = 0;
creation_desc.BufferDesc.Width = 800;
creation_desc.BufferDesc.Height = 600;
creation_desc.BufferDesc.RefreshRate.Numerator = 60;
creation_desc.BufferDesc.RefreshRate.Denominator = 60;
creation_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
creation_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
creation_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
creation_desc.SampleDesc.Count = 1;
creation_desc.SampleDesc.Quality = 0;
creation_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
creation_desc.BufferCount = 1;
creation_desc.OutputWindow = CreateWindowA("static", "dxgi_test", 0, 0, 0, 0, 0, 0, 0, 0, 0);
creation_desc.Windowed = TRUE;
creation_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
creation_desc.Flags = 0;
hr = IDXGIDevice_QueryInterface(device, &IID_IUnknown, (void **)&obj);
ok(SUCCEEDED(hr), "IDXGIDevice does not implement IUnknown\n");
hr = IDXGIDevice_GetAdapter(device, &adapter);
ok(SUCCEEDED(hr), "GetAdapter failed, hr %#x.\n", hr);
hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
ok(SUCCEEDED(hr), "GetParent failed, hr %#x.\n", hr);
hr = IDXGIFactory_CreateSwapChain(factory, obj, &creation_desc, &swapchain);
ok(SUCCEEDED(hr), "CreateSwapChain failed, hr %#x.\n", hr);
hr = IDXGISwapChain_GetDesc(swapchain, NULL);
ok(hr == E_INVALIDARG, "GetDesc unexpectedly returned %#x.\n", hr);
IDXGISwapChain_Release(swapchain);
for (i = 0; i < sizeof(refresh_list)/sizeof(refresh_list[0]); i++)
{
creation_desc.BufferDesc.RefreshRate.Numerator = refresh_list[i].numerator;
creation_desc.BufferDesc.RefreshRate.Denominator = refresh_list[i].denominator;
hr = IDXGIFactory_CreateSwapChain(factory, obj, &creation_desc, &swapchain);
ok(SUCCEEDED(hr), "CreateSwapChain failed, hr %#x.\n", hr);
hr = IDXGISwapChain_GetDesc(swapchain, &result_desc);
ok(SUCCEEDED(hr), "GetDesc failed, hr %#x.\n", hr);
if (refresh_list[i].numerator_should_pass)
ok(result_desc.BufferDesc.RefreshRate.Numerator == refresh_list[i].numerator,
"Numerator %u is %u.\n", i, result_desc.BufferDesc.RefreshRate.Numerator);
else
todo_wine ok(result_desc.BufferDesc.RefreshRate.Numerator == refresh_list[i].numerator,
"Numerator %u is %u.\n", i, result_desc.BufferDesc.RefreshRate.Numerator);
if (refresh_list[i].denominator_should_pass)
ok(result_desc.BufferDesc.RefreshRate.Denominator == refresh_list[i].denominator,
"Denominator %u is %u.\n", i ,result_desc.BufferDesc.RefreshRate.Denominator);
else
todo_wine ok(result_desc.BufferDesc.RefreshRate.Denominator == refresh_list[i].denominator,
"Denominator %u is %u.\n", i, result_desc.BufferDesc.RefreshRate.Denominator);
IDXGISwapChain_Release(swapchain);
}
creation_desc.Windowed = FALSE;
for (i = 0; i < sizeof(refresh_list)/sizeof(refresh_list[0]); i++)
{
creation_desc.BufferDesc.RefreshRate.Numerator = refresh_list[i].numerator;
creation_desc.BufferDesc.RefreshRate.Denominator = refresh_list[i].denominator;
hr = IDXGIFactory_CreateSwapChain(factory, obj, &creation_desc, &swapchain);
ok(SUCCEEDED(hr), "CreateSwapChain failed, hr %#x.\n", hr);
hr = IDXGISwapChain_GetDesc(swapchain, &result_desc);
ok(SUCCEEDED(hr), "GetDesc failed, hr %#x.\n", hr);
if (refresh_list[i].numerator_should_pass)
ok(result_desc.BufferDesc.RefreshRate.Numerator == refresh_list[i].numerator,
"Numerator %u is %u.\n", i, result_desc.BufferDesc.RefreshRate.Numerator);
else
todo_wine ok(result_desc.BufferDesc.RefreshRate.Numerator == refresh_list[i].numerator,
"Numerator %u is %u.\n", i, result_desc.BufferDesc.RefreshRate.Numerator);
if (refresh_list[i].denominator_should_pass)
ok(result_desc.BufferDesc.RefreshRate.Denominator == refresh_list[i].denominator,
"Denominator %u is %u.\n", i ,result_desc.BufferDesc.RefreshRate.Denominator);
else
todo_wine ok(result_desc.BufferDesc.RefreshRate.Denominator == refresh_list[i].denominator,
"Denominator %u is %u.\n", i, result_desc.BufferDesc.RefreshRate.Denominator);
hr = IDXGISwapChain_SetFullscreenState(swapchain, FALSE, NULL);
todo_wine ok(SUCCEEDED(hr), "SetFullscreenState failed, hr %#x.\n", hr);
IDXGISwapChain_Release(swapchain);
}
IDXGIFactory_Release(factory);
IDXGIAdapter_Release(adapter);
IUnknown_Release(obj);
refcount = IDXGIDevice_Release(device);
ok(!refcount, "Device has %u references left.\n", refcount);
DestroyWindow(creation_desc.OutputWindow);
}
static void test_create_factory(void)
{
IDXGIFactory1 *factory;
IUnknown *iface;
HRESULT hr;
iface = (void *)0xdeadbeef;
hr = CreateDXGIFactory(&IID_IDXGIDevice, (void **)&iface);
ok(hr == E_NOINTERFACE, "Got unexpected hr %#x.\n", hr);
ok(!iface, "Got unexpected iface %p.\n", iface);
hr = CreateDXGIFactory(&IID_IUnknown, (void **)&iface);
ok(SUCCEEDED(hr), "Failed to create factory with IID_IUnknown, hr %#x.\n", hr);
IUnknown_Release(iface);
hr = CreateDXGIFactory(&IID_IDXGIObject, (void **)&iface);
ok(SUCCEEDED(hr), "Failed to create factory with IID_IDXGIObject, hr %#x.\n", hr);
IUnknown_Release(iface);
factory = (void *)0xdeadbeef;
hr = CreateDXGIFactory(&IID_IDXGIFactory, (void **)&iface);
ok(SUCCEEDED(hr), "Failed to create factory with IID_IDXGIFactory, hr %#x.\n", hr);
hr = IUnknown_QueryInterface(iface, &IID_IDXGIFactory1, (void **)&factory);
ok(hr == E_NOINTERFACE, "Got unexpected hr %#x.\n", hr);
ok(!factory, "Got unexpected factory %p.\n", factory);
IUnknown_Release(iface);
iface = (void *)0xdeadbeef;
hr = CreateDXGIFactory(&IID_IDXGIFactory1, (void **)&iface);
ok(hr == E_NOINTERFACE, "Got unexpected hr %#x.\n", hr);
ok(!iface, "Got unexpected iface %p.\n", iface);
if (!pCreateDXGIFactory1)
{
win_skip("CreateDXGIFactory1 not available, skipping tests.\n");
return;
}
iface = (void *)0xdeadbeef;
hr = pCreateDXGIFactory1(&IID_IDXGIDevice, (void **)&iface);
ok(hr == E_NOINTERFACE, "Got unexpected hr %#x.\n", hr);
ok(!iface, "Got unexpected iface %p.\n", iface);
hr = pCreateDXGIFactory1(&IID_IUnknown, (void **)&iface);
ok(SUCCEEDED(hr), "Failed to create factory with IID_IUnknown, hr %#x.\n", hr);
IUnknown_Release(iface);
hr = pCreateDXGIFactory1(&IID_IDXGIObject, (void **)&iface);
ok(SUCCEEDED(hr), "Failed to create factory with IID_IDXGIObject, hr %#x.\n", hr);
IUnknown_Release(iface);
hr = pCreateDXGIFactory1(&IID_IDXGIFactory, (void **)&iface);
ok(SUCCEEDED(hr), "Failed to create factory with IID_IDXGIFactory, hr %#x.\n", hr);
hr = IUnknown_QueryInterface(iface, &IID_IDXGIFactory1, (void **)&factory);
ok(SUCCEEDED(hr), "Failed to query IDXGIFactory1 interface, hr %#x.\n", hr);
IDXGIFactory1_Release(factory);
IUnknown_Release(iface);
hr = pCreateDXGIFactory1(&IID_IDXGIFactory1, (void **)&iface);
ok(SUCCEEDED(hr), "Failed to create factory with IID_IDXGIFactory1, hr %#x.\n", hr);
IUnknown_Release(iface);
}
static void test_private_data(void)
{
ULONG refcount, expected_refcount;
IDXGIDevice *device;
HRESULT hr;
IDXGIDevice *test_object;
IUnknown *ptr;
static const DWORD data[] = {1, 2, 3, 4};
UINT size;
static const GUID dxgi_private_data_test_guid =
{
0xfdb37466,
0x428f,
0x4edf,
{0xa3, 0x7f, 0x9b, 0x1d, 0xf4, 0x88, 0xc5, 0xfc}
};
static const GUID dxgi_private_data_test_guid2 =
{
0x2e5afac2,
0x87b5,
0x4c10,
{0x9b, 0x4b, 0x89, 0xd7, 0xd1, 0x12, 0xe7, 0x2b}
};
if (!(device = create_device()))
{
skip("Failed to create device, skipping tests.\n");
return;
}
test_object = create_device();
/* SetPrivateData with a pointer of NULL has the purpose of FreePrivateData in previous
* d3d versions. A successful clear returns S_OK. A redundant clear S_FALSE. Setting a
* NULL interface is not considered a clear but as setting an interface pointer that
* happens to be NULL. */
hr = IDXGIDevice_SetPrivateData(device, &dxgi_private_data_test_guid, 0, NULL);
ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
hr = IDXGIDevice_SetPrivateDataInterface(device, &dxgi_private_data_test_guid, NULL);
ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
hr = IDXGIDevice_SetPrivateData(device, &dxgi_private_data_test_guid, ~0U, NULL);
ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
hr = IDXGIDevice_SetPrivateData(device, &dxgi_private_data_test_guid, ~0U, NULL);
ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
hr = IDXGIDevice_SetPrivateDataInterface(device, &dxgi_private_data_test_guid, NULL);
ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
size = sizeof(ptr) * 2;
ptr = (IUnknown *)0xdeadbeef;
hr = IDXGIDevice_GetPrivateData(device, &dxgi_private_data_test_guid, &size, &ptr);
ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
ok(!ptr, "Got unexpected pointer %p.\n", ptr);
ok(size == sizeof(IUnknown *), "Got unexpected size %u.\n", size);
refcount = get_refcount((IUnknown *)test_object);
hr = IDXGIDevice_SetPrivateDataInterface(device, &dxgi_private_data_test_guid,
(IUnknown *)test_object);
ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
expected_refcount = refcount + 1;
refcount = get_refcount((IUnknown *)test_object);
ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
hr = IDXGIDevice_SetPrivateDataInterface(device, &dxgi_private_data_test_guid,
(IUnknown *)test_object);
ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
refcount = get_refcount((IUnknown *)test_object);
ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
hr = IDXGIDevice_SetPrivateDataInterface(device, &dxgi_private_data_test_guid, NULL);
ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
expected_refcount--;
refcount = get_refcount((IUnknown *)test_object);
ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
hr = IDXGIDevice_SetPrivateDataInterface(device, &dxgi_private_data_test_guid,
(IUnknown *)test_object);
ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
size = sizeof(data);
hr = IDXGIDevice_SetPrivateData(device, &dxgi_private_data_test_guid, size, data);
ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
refcount = get_refcount((IUnknown *)test_object);
ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
hr = IDXGIDevice_SetPrivateData(device, &dxgi_private_data_test_guid, 42, NULL);
ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
hr = IDXGIDevice_SetPrivateData(device, &dxgi_private_data_test_guid, 42, NULL);
ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
hr = IDXGIDevice_SetPrivateDataInterface(device, &dxgi_private_data_test_guid,
(IUnknown *)test_object);
ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
expected_refcount++;
size = 2 * sizeof(ptr);
ptr = NULL;
hr = IDXGIDevice_GetPrivateData(device, &dxgi_private_data_test_guid, &size, &ptr);
ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
ok(size == sizeof(test_object), "Got unexpected size %u.\n", size);
expected_refcount++;
refcount = get_refcount((IUnknown *)test_object);
ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
if (ptr)
IUnknown_Release(ptr);
expected_refcount--;
ptr = (IUnknown *)0xdeadbeef;
size = 1;
hr = IDXGIDevice_GetPrivateData(device, &dxgi_private_data_test_guid, &size, NULL);
ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
ok(size == sizeof(device), "Got unexpected size %u.\n", size);
size = 2 * sizeof(ptr);
hr = IDXGIDevice_GetPrivateData(device, &dxgi_private_data_test_guid, &size, NULL);
ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
ok(size == sizeof(device), "Got unexpected size %u.\n", size);
refcount = get_refcount((IUnknown *)test_object);
ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
size = 1;
hr = IDXGIDevice_GetPrivateData(device, &dxgi_private_data_test_guid, &size, &ptr);
ok(hr == DXGI_ERROR_MORE_DATA, "Got unexpected hr %#x.\n", hr);
ok(size == sizeof(device), "Got unexpected size %u.\n", size);
ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
hr = IDXGIDevice_GetPrivateData(device, &dxgi_private_data_test_guid2, NULL, NULL);
ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
size = 0xdeadbabe;
hr = IDXGIDevice_GetPrivateData(device, &dxgi_private_data_test_guid2, &size, &ptr);
ok(hr == DXGI_ERROR_NOT_FOUND, "Got unexpected hr %#x.\n", hr);
ok(size == 0, "Got unexpected size %u.\n", size);
ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
hr = IDXGIDevice_GetPrivateData(device, &dxgi_private_data_test_guid, NULL, &ptr);
ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
refcount = IDXGIDevice_Release(device);
ok(!refcount, "Device has %u references left.\n", refcount);
refcount = IDXGIDevice_Release(test_object);
ok(!refcount, "Test object has %u references left.\n", refcount);
}
static void test_swapchain_resize(void)
{
DXGI_SWAP_CHAIN_DESC swapchain_desc;
D3D10_TEXTURE2D_DESC texture_desc;
DXGI_SURFACE_DESC surface_desc;
IDXGISwapChain *swapchain;
ID3D10Texture2D *texture;
IDXGISurface *surface;
IDXGIAdapter *adapter;
IDXGIFactory *factory;
IDXGIDevice *device;
RECT client_rect, r;
ULONG refcount;
HWND window;
HRESULT hr;
BOOL ret;
if (!(device = create_device()))
{
skip("Failed to create device, skipping tests.\n");
return;
}
window = CreateWindowA("static", "dxgi_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
0, 0, 640, 480, NULL, NULL, NULL, NULL);
ret = GetClientRect(window, &client_rect);
ok(ret, "Failed to get client rect.\n");
hr = IDXGIDevice_GetAdapter(device, &adapter);
ok(SUCCEEDED(hr), "Failed to get adapter, hr %#x.\n", hr);
hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
ok(SUCCEEDED(hr), "Failed to get factory, hr %#x.\n", hr);
IDXGIAdapter_Release(adapter);
swapchain_desc.BufferDesc.Width = 640;
swapchain_desc.BufferDesc.Height = 480;
swapchain_desc.BufferDesc.RefreshRate.Numerator = 60;
swapchain_desc.BufferDesc.RefreshRate.Denominator = 1;
swapchain_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
swapchain_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
swapchain_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
swapchain_desc.SampleDesc.Count = 1;
swapchain_desc.SampleDesc.Quality = 0;
swapchain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
swapchain_desc.BufferCount = 1;
swapchain_desc.OutputWindow = window;
swapchain_desc.Windowed = TRUE;
swapchain_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
swapchain_desc.Flags = 0;
hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &swapchain_desc, &swapchain);
ok(SUCCEEDED(hr), "Failed to create swapchain, hr %#x.\n", hr);
IDXGIFactory_Release(factory);
hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_IDXGISurface, (void **)&surface);
ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_ID3D10Texture2D, (void **)&texture);
ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
ret = GetClientRect(window, &r);
ok(ret, "Failed to get client rect.\n");
ok(EqualRect(&r, &client_rect), "Got unexpected rect {%d, %d, %d, %d}, expected {%d, %d, %d, %d}.\n",
r.left, r.top, r.right, r.bottom,
client_rect.left, client_rect.top, client_rect.right, client_rect.bottom);
hr = IDXGISwapChain_GetDesc(swapchain, &swapchain_desc);
ok(SUCCEEDED(hr), "Failed to get swapchain desc, hr %#x.\n", hr);
ok(swapchain_desc.BufferDesc.Width == 640,
"Got unexpected BufferDesc.Width %u.\n", swapchain_desc.BufferDesc.Width);
ok(swapchain_desc.BufferDesc.Height == 480,
"Got unexpected bufferDesc.Height %u.\n", swapchain_desc.BufferDesc.Height);
ok(swapchain_desc.BufferDesc.RefreshRate.Numerator == 60,
"Got unexpected BufferDesc.RefreshRate.Numerator %u.\n",
swapchain_desc.BufferDesc.RefreshRate.Numerator);
ok(swapchain_desc.BufferDesc.RefreshRate.Denominator == 1,
"Got unexpected BufferDesc.RefreshRate.Denominator %u.\n",
swapchain_desc.BufferDesc.RefreshRate.Denominator);
ok(swapchain_desc.BufferDesc.Format == DXGI_FORMAT_R8G8B8A8_UNORM,
"Got unexpected BufferDesc.Format %#x.\n", swapchain_desc.BufferDesc.Format);
ok(swapchain_desc.BufferDesc.ScanlineOrdering == DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED,
"Got unexpected BufferDesc.ScanlineOrdering %#x.\n", swapchain_desc.BufferDesc.ScanlineOrdering);
ok(swapchain_desc.BufferDesc.Scaling == DXGI_MODE_SCALING_UNSPECIFIED,
"Got unexpected BufferDesc.Scaling %#x.\n", swapchain_desc.BufferDesc.Scaling);
ok(swapchain_desc.SampleDesc.Count == 1,
"Got unexpected SampleDesc.Count %u.\n", swapchain_desc.SampleDesc.Count);
ok(!swapchain_desc.SampleDesc.Quality,
"Got unexpected SampleDesc.Quality %u.\n", swapchain_desc.SampleDesc.Quality);
ok(swapchain_desc.BufferUsage == DXGI_USAGE_RENDER_TARGET_OUTPUT,
"Got unexpected BufferUsage %#x.\n", swapchain_desc.BufferUsage);
ok(swapchain_desc.BufferCount == 1,
"Got unexpected BufferCount %u.\n", swapchain_desc.BufferCount);
ok(swapchain_desc.OutputWindow == window,
"Got unexpected OutputWindow %p, expected %p.\n", swapchain_desc.OutputWindow, window);
ok(swapchain_desc.Windowed,
"Got unexpected Windowed %#x.\n", swapchain_desc.Windowed);
ok(swapchain_desc.SwapEffect == DXGI_SWAP_EFFECT_DISCARD,
"Got unexpected SwapEffect %#x.\n", swapchain_desc.SwapEffect);
ok(!swapchain_desc.Flags,
"Got unexpected Flags %#x.\n", swapchain_desc.Flags);
hr = IDXGISurface_GetDesc(surface, &surface_desc);
ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
ok(surface_desc.Width == 640, "Got unexpected Width %u.\n", surface_desc.Width);
ok(surface_desc.Height == 480, "Got unexpected Height %u.\n", surface_desc.Height);
ok(surface_desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", surface_desc.Format);
ok(surface_desc.SampleDesc.Count == 1, "Got unexpected SampleDesc.Count %u.\n", surface_desc.SampleDesc.Count);
ok(!surface_desc.SampleDesc.Quality, "Got unexpected SampleDesc.Quality %u.\n", surface_desc.SampleDesc.Quality);
ID3D10Texture2D_GetDesc(texture, &texture_desc);
ok(texture_desc.Width == 640, "Got unexpected Width %u.\n", texture_desc.Width);
ok(texture_desc.Height == 480, "Got unexpected Height %u.\n", texture_desc.Height);
ok(texture_desc.MipLevels == 1, "Got unexpected MipLevels %u.\n", texture_desc.MipLevels);
ok(texture_desc.ArraySize == 1, "Got unexpected ArraySize %u.\n", texture_desc.ArraySize);
ok(texture_desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", texture_desc.Format);
ok(texture_desc.SampleDesc.Count == 1, "Got unexpected SampleDesc.Count %u.\n", texture_desc.SampleDesc.Count);
ok(!texture_desc.SampleDesc.Quality, "Got unexpected SampleDesc.Quality %u.\n", texture_desc.SampleDesc.Quality);
ok(texture_desc.Usage == D3D10_USAGE_DEFAULT, "Got unexpected Usage %#x.\n", texture_desc.Usage);
ok(texture_desc.BindFlags == D3D10_BIND_RENDER_TARGET, "Got unexpected BindFlags %#x.\n", texture_desc.BindFlags);
ok(!texture_desc.CPUAccessFlags, "Got unexpected CPUAccessFlags %#x.\n", texture_desc.CPUAccessFlags);
ok(!texture_desc.MiscFlags, "Got unexpected MiscFlags %#x.\n", texture_desc.MiscFlags);
hr = IDXGISwapChain_ResizeBuffers(swapchain, 1, 320, 240, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, 0);
ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
ret = GetClientRect(window, &r);
ok(ret, "Failed to get client rect.\n");
ok(EqualRect(&r, &client_rect), "Got unexpected rect {%d, %d, %d, %d}, expected {%d, %d, %d, %d}.\n",
r.left, r.top, r.right, r.bottom,
client_rect.left, client_rect.top, client_rect.right, client_rect.bottom);
hr = IDXGISwapChain_GetDesc(swapchain, &swapchain_desc);
ok(SUCCEEDED(hr), "Failed to get swapchain desc, hr %#x.\n", hr);
ok(swapchain_desc.BufferDesc.Width == 640,
"Got unexpected BufferDesc.Width %u.\n", swapchain_desc.BufferDesc.Width);
ok(swapchain_desc.BufferDesc.Height == 480,
"Got unexpected bufferDesc.Height %u.\n", swapchain_desc.BufferDesc.Height);
ok(swapchain_desc.BufferDesc.RefreshRate.Numerator == 60,
"Got unexpected BufferDesc.RefreshRate.Numerator %u.\n",
swapchain_desc.BufferDesc.RefreshRate.Numerator);
ok(swapchain_desc.BufferDesc.RefreshRate.Denominator == 1,
"Got unexpected BufferDesc.RefreshRate.Denominator %u.\n",
swapchain_desc.BufferDesc.RefreshRate.Denominator);
ok(swapchain_desc.BufferDesc.Format == DXGI_FORMAT_R8G8B8A8_UNORM,
"Got unexpected BufferDesc.Format %#x.\n", swapchain_desc.BufferDesc.Format);
ok(swapchain_desc.BufferDesc.ScanlineOrdering == DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED,
"Got unexpected BufferDesc.ScanlineOrdering %#x.\n", swapchain_desc.BufferDesc.ScanlineOrdering);
ok(swapchain_desc.BufferDesc.Scaling == DXGI_MODE_SCALING_UNSPECIFIED,
"Got unexpected BufferDesc.Scaling %#x.\n", swapchain_desc.BufferDesc.Scaling);
ok(swapchain_desc.SampleDesc.Count == 1,
"Got unexpected SampleDesc.Count %u.\n", swapchain_desc.SampleDesc.Count);
ok(!swapchain_desc.SampleDesc.Quality,
"Got unexpected SampleDesc.Quality %u.\n", swapchain_desc.SampleDesc.Quality);
ok(swapchain_desc.BufferUsage == DXGI_USAGE_RENDER_TARGET_OUTPUT,
"Got unexpected BufferUsage %#x.\n", swapchain_desc.BufferUsage);
ok(swapchain_desc.BufferCount == 1,
"Got unexpected BufferCount %u.\n", swapchain_desc.BufferCount);
ok(swapchain_desc.OutputWindow == window,
"Got unexpected OutputWindow %p, expected %p.\n", swapchain_desc.OutputWindow, window);
ok(swapchain_desc.Windowed,
"Got unexpected Windowed %#x.\n", swapchain_desc.Windowed);
ok(swapchain_desc.SwapEffect == DXGI_SWAP_EFFECT_DISCARD,
"Got unexpected SwapEffect %#x.\n", swapchain_desc.SwapEffect);
ok(!swapchain_desc.Flags,
"Got unexpected Flags %#x.\n", swapchain_desc.Flags);
hr = IDXGISurface_GetDesc(surface, &surface_desc);
ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
ok(surface_desc.Width == 640, "Got unexpected Width %u.\n", surface_desc.Width);
ok(surface_desc.Height == 480, "Got unexpected Height %u.\n", surface_desc.Height);
ok(surface_desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", surface_desc.Format);
ok(surface_desc.SampleDesc.Count == 1, "Got unexpected SampleDesc.Count %u.\n", surface_desc.SampleDesc.Count);
ok(!surface_desc.SampleDesc.Quality, "Got unexpected SampleDesc.Quality %u.\n", surface_desc.SampleDesc.Quality);
ID3D10Texture2D_GetDesc(texture, &texture_desc);
ok(texture_desc.Width == 640, "Got unexpected Width %u.\n", texture_desc.Width);
ok(texture_desc.Height == 480, "Got unexpected Height %u.\n", texture_desc.Height);
ok(texture_desc.MipLevels == 1, "Got unexpected MipLevels %u.\n", texture_desc.MipLevels);
ok(texture_desc.ArraySize == 1, "Got unexpected ArraySize %u.\n", texture_desc.ArraySize);
ok(texture_desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", texture_desc.Format);
ok(texture_desc.SampleDesc.Count == 1, "Got unexpected SampleDesc.Count %u.\n", texture_desc.SampleDesc.Count);
ok(!texture_desc.SampleDesc.Quality, "Got unexpected SampleDesc.Quality %u.\n", texture_desc.SampleDesc.Quality);
ok(texture_desc.Usage == D3D10_USAGE_DEFAULT, "Got unexpected Usage %#x.\n", texture_desc.Usage);
ok(texture_desc.BindFlags == D3D10_BIND_RENDER_TARGET, "Got unexpected BindFlags %#x.\n", texture_desc.BindFlags);
ok(!texture_desc.CPUAccessFlags, "Got unexpected CPUAccessFlags %#x.\n", texture_desc.CPUAccessFlags);
ok(!texture_desc.MiscFlags, "Got unexpected MiscFlags %#x.\n", texture_desc.MiscFlags);
ID3D10Texture2D_Release(texture);
IDXGISurface_Release(surface);
hr = IDXGISwapChain_ResizeBuffers(swapchain, 1, 320, 240, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, 0);
ok(SUCCEEDED(hr), "Failed to resize buffers, hr %#x.\n", hr);
hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_IDXGISurface, (void **)&surface);
ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_ID3D10Texture2D, (void **)&texture);
ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
ret = GetClientRect(window, &r);
ok(ret, "Failed to get client rect.\n");
ok(EqualRect(&r, &client_rect), "Got unexpected rect {%d, %d, %d, %d}, expected {%d, %d, %d, %d}.\n",
r.left, r.top, r.right, r.bottom,
client_rect.left, client_rect.top, client_rect.right, client_rect.bottom);
hr = IDXGISwapChain_GetDesc(swapchain, &swapchain_desc);
ok(SUCCEEDED(hr), "Failed to get swapchain desc, hr %#x.\n", hr);
ok(swapchain_desc.BufferDesc.Width == 320,
"Got unexpected BufferDesc.Width %u.\n", swapchain_desc.BufferDesc.Width);
ok(swapchain_desc.BufferDesc.Height == 240,
"Got unexpected bufferDesc.Height %u.\n", swapchain_desc.BufferDesc.Height);
ok(swapchain_desc.BufferDesc.RefreshRate.Numerator == 60,
"Got unexpected BufferDesc.RefreshRate.Numerator %u.\n",
swapchain_desc.BufferDesc.RefreshRate.Numerator);
ok(swapchain_desc.BufferDesc.RefreshRate.Denominator == 1,
"Got unexpected BufferDesc.RefreshRate.Denominator %u.\n",
swapchain_desc.BufferDesc.RefreshRate.Denominator);
ok(swapchain_desc.BufferDesc.Format == DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
"Got unexpected BufferDesc.Format %#x.\n", swapchain_desc.BufferDesc.Format);
ok(swapchain_desc.BufferDesc.ScanlineOrdering == DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED,
"Got unexpected BufferDesc.ScanlineOrdering %#x.\n", swapchain_desc.BufferDesc.ScanlineOrdering);
ok(swapchain_desc.BufferDesc.Scaling == DXGI_MODE_SCALING_UNSPECIFIED,
"Got unexpected BufferDesc.Scaling %#x.\n", swapchain_desc.BufferDesc.Scaling);
ok(swapchain_desc.SampleDesc.Count == 1,
"Got unexpected SampleDesc.Count %u.\n", swapchain_desc.SampleDesc.Count);
ok(!swapchain_desc.SampleDesc.Quality,
"Got unexpected SampleDesc.Quality %u.\n", swapchain_desc.SampleDesc.Quality);
ok(swapchain_desc.BufferUsage == DXGI_USAGE_RENDER_TARGET_OUTPUT,
"Got unexpected BufferUsage %#x.\n", swapchain_desc.BufferUsage);
ok(swapchain_desc.BufferCount == 1,
"Got unexpected BufferCount %u.\n", swapchain_desc.BufferCount);
ok(swapchain_desc.OutputWindow == window,
"Got unexpected OutputWindow %p, expected %p.\n", swapchain_desc.OutputWindow, window);
ok(swapchain_desc.Windowed,
"Got unexpected Windowed %#x.\n", swapchain_desc.Windowed);
ok(swapchain_desc.SwapEffect == DXGI_SWAP_EFFECT_DISCARD,
"Got unexpected SwapEffect %#x.\n", swapchain_desc.SwapEffect);
ok(!swapchain_desc.Flags,
"Got unexpected Flags %#x.\n", swapchain_desc.Flags);
hr = IDXGISurface_GetDesc(surface, &surface_desc);
ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
ok(surface_desc.Width == 320, "Got unexpected Width %u.\n", surface_desc.Width);
ok(surface_desc.Height == 240, "Got unexpected Height %u.\n", surface_desc.Height);
ok(surface_desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, "Got unexpected Format %#x.\n", surface_desc.Format);
ok(surface_desc.SampleDesc.Count == 1, "Got unexpected SampleDesc.Count %u.\n", surface_desc.SampleDesc.Count);
ok(!surface_desc.SampleDesc.Quality, "Got unexpected SampleDesc.Quality %u.\n", surface_desc.SampleDesc.Quality);
ID3D10Texture2D_GetDesc(texture, &texture_desc);
ok(texture_desc.Width == 320, "Got unexpected Width %u.\n", texture_desc.Width);
ok(texture_desc.Height == 240, "Got unexpected Height %u.\n", texture_desc.Height);
ok(texture_desc.MipLevels == 1, "Got unexpected MipLevels %u.\n", texture_desc.MipLevels);
ok(texture_desc.ArraySize == 1, "Got unexpected ArraySize %u.\n", texture_desc.ArraySize);
ok(texture_desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, "Got unexpected Format %#x.\n", texture_desc.Format);
ok(texture_desc.SampleDesc.Count == 1, "Got unexpected SampleDesc.Count %u.\n", texture_desc.SampleDesc.Count);
ok(!texture_desc.SampleDesc.Quality, "Got unexpected SampleDesc.Quality %u.\n", texture_desc.SampleDesc.Quality);
ok(texture_desc.Usage == D3D10_USAGE_DEFAULT, "Got unexpected Usage %#x.\n", texture_desc.Usage);
ok(texture_desc.BindFlags == D3D10_BIND_RENDER_TARGET, "Got unexpected BindFlags %#x.\n", texture_desc.BindFlags);
ok(!texture_desc.CPUAccessFlags, "Got unexpected CPUAccessFlags %#x.\n", texture_desc.CPUAccessFlags);
ok(!texture_desc.MiscFlags, "Got unexpected MiscFlags %#x.\n", texture_desc.MiscFlags);
ID3D10Texture2D_Release(texture);
IDXGISurface_Release(surface);
hr = IDXGISwapChain_ResizeBuffers(swapchain, 0, 0, 0, DXGI_FORMAT_UNKNOWN, 0);
ok(SUCCEEDED(hr), "Failed to resize buffers, hr %#x.\n", hr);
hr = IDXGISwapChain_GetDesc(swapchain, &swapchain_desc);
ok(SUCCEEDED(hr), "Failed to get swapchain desc, hr %#x.\n", hr);
ok(swapchain_desc.BufferDesc.Width == client_rect.right - client_rect.left,
"Got unexpected BufferDesc.Width %u, expected %u.\n",
swapchain_desc.BufferDesc.Width, client_rect.right - client_rect.left);
ok(swapchain_desc.BufferDesc.Height == client_rect.bottom - client_rect.top,
"Got unexpected bufferDesc.Height %u, expected %u.\n",
swapchain_desc.BufferDesc.Height, client_rect.bottom - client_rect.top);
ok(swapchain_desc.BufferDesc.RefreshRate.Numerator == 60,
"Got unexpected BufferDesc.RefreshRate.Numerator %u.\n",
swapchain_desc.BufferDesc.RefreshRate.Numerator);
ok(swapchain_desc.BufferDesc.RefreshRate.Denominator == 1,
"Got unexpected BufferDesc.RefreshRate.Denominator %u.\n",
swapchain_desc.BufferDesc.RefreshRate.Denominator);
ok(swapchain_desc.BufferDesc.Format == DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
"Got unexpected BufferDesc.Format %#x.\n", swapchain_desc.BufferDesc.Format);
ok(swapchain_desc.BufferDesc.ScanlineOrdering == DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED,
"Got unexpected BufferDesc.ScanlineOrdering %#x.\n", swapchain_desc.BufferDesc.ScanlineOrdering);
ok(swapchain_desc.BufferDesc.Scaling == DXGI_MODE_SCALING_UNSPECIFIED,
"Got unexpected BufferDesc.Scaling %#x.\n", swapchain_desc.BufferDesc.Scaling);
ok(swapchain_desc.SampleDesc.Count == 1,
"Got unexpected SampleDesc.Count %u.\n", swapchain_desc.SampleDesc.Count);
ok(!swapchain_desc.SampleDesc.Quality,
"Got unexpected SampleDesc.Quality %u.\n", swapchain_desc.SampleDesc.Quality);
ok(swapchain_desc.BufferUsage == DXGI_USAGE_RENDER_TARGET_OUTPUT,
"Got unexpected BufferUsage %#x.\n", swapchain_desc.BufferUsage);
ok(swapchain_desc.BufferCount == 1,
"Got unexpected BufferCount %u.\n", swapchain_desc.BufferCount);
ok(swapchain_desc.OutputWindow == window,
"Got unexpected OutputWindow %p, expected %p.\n", swapchain_desc.OutputWindow, window);
ok(swapchain_desc.Windowed,
"Got unexpected Windowed %#x.\n", swapchain_desc.Windowed);
ok(swapchain_desc.SwapEffect == DXGI_SWAP_EFFECT_DISCARD,
"Got unexpected SwapEffect %#x.\n", swapchain_desc.SwapEffect);
ok(!swapchain_desc.Flags,
"Got unexpected Flags %#x.\n", swapchain_desc.Flags);
IDXGISwapChain_Release(swapchain);
refcount = IDXGIDevice_Release(device);
ok(!refcount, "Device has %u references left.\n", refcount);
DestroyWindow(window);
}
static void test_swapchain_parameters(void)
{
IDXGISwapChain *swapchain;
IUnknown *obj;
IDXGIAdapter *adapter;
IDXGIFactory *factory;
IDXGIDevice *device;
IDXGIResource *resource;
DXGI_SWAP_CHAIN_DESC desc;
HRESULT hr;
unsigned int i, j;
ULONG refcount;
DXGI_USAGE usage, expected_usage;
HWND window;
static const struct
{
BOOL windowed;
UINT buffer_count;
DXGI_SWAP_EFFECT swap_effect;
HRESULT hr, vista_hr;
UINT highest_accessible_buffer;
}
tests[] =
{
{TRUE, 0, DXGI_SWAP_EFFECT_DISCARD, DXGI_ERROR_INVALID_CALL, DXGI_ERROR_INVALID_CALL, 0},
{TRUE, 1, DXGI_SWAP_EFFECT_DISCARD, S_OK, S_OK, 0},
{TRUE, 2, DXGI_SWAP_EFFECT_DISCARD, S_OK, S_OK, 0},
{TRUE, 0, DXGI_SWAP_EFFECT_SEQUENTIAL, DXGI_ERROR_INVALID_CALL, DXGI_ERROR_INVALID_CALL, 0},
{TRUE, 1, DXGI_SWAP_EFFECT_SEQUENTIAL, S_OK, S_OK, 0},
{TRUE, 2, DXGI_SWAP_EFFECT_SEQUENTIAL, S_OK, S_OK, 1},
{TRUE, 3, DXGI_SWAP_EFFECT_SEQUENTIAL, S_OK, S_OK, 2},
{TRUE, 0, 2 /* undefined */, DXGI_ERROR_INVALID_CALL, DXGI_ERROR_INVALID_CALL, 0},
{TRUE, 1, 2 /* undefined */, DXGI_ERROR_INVALID_CALL, DXGI_ERROR_INVALID_CALL, 0},
{TRUE, 2, 2 /* undefined */, DXGI_ERROR_INVALID_CALL, DXGI_ERROR_INVALID_CALL, 0},
{TRUE, 0, DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL, DXGI_ERROR_INVALID_CALL, DXGI_ERROR_INVALID_CALL, 0},
{TRUE, 1, DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL, DXGI_ERROR_INVALID_CALL, DXGI_ERROR_INVALID_CALL, 0},
{TRUE, 2, DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL, S_OK, DXGI_ERROR_INVALID_CALL, 1},
{TRUE, 3, DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL, S_OK, DXGI_ERROR_INVALID_CALL, 2},
{TRUE, 0, 4 /* undefined */, DXGI_ERROR_INVALID_CALL, DXGI_ERROR_INVALID_CALL, 0},
{TRUE, 1, 4 /* undefined */, DXGI_ERROR_INVALID_CALL, DXGI_ERROR_INVALID_CALL, 0},
{TRUE, 2, 4 /* undefined */, DXGI_ERROR_INVALID_CALL, DXGI_ERROR_INVALID_CALL, 0},
{TRUE, 16, DXGI_SWAP_EFFECT_DISCARD, S_OK, S_OK, 0},
{TRUE, 16, DXGI_SWAP_EFFECT_SEQUENTIAL, S_OK, S_OK, 15},
{TRUE, 16, DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL, S_OK, DXGI_ERROR_INVALID_CALL, 15},
{TRUE, 17, DXGI_SWAP_EFFECT_DISCARD, DXGI_ERROR_INVALID_CALL, DXGI_ERROR_INVALID_CALL, 0},
{TRUE, 17, DXGI_SWAP_EFFECT_SEQUENTIAL, DXGI_ERROR_INVALID_CALL, DXGI_ERROR_INVALID_CALL, 0},
{TRUE, 17, DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL, DXGI_ERROR_INVALID_CALL, DXGI_ERROR_INVALID_CALL, 0},
{FALSE, 0, DXGI_SWAP_EFFECT_DISCARD, DXGI_ERROR_INVALID_CALL, DXGI_ERROR_INVALID_CALL, 0},
{FALSE, 1, DXGI_SWAP_EFFECT_DISCARD, S_OK, S_OK, 0},
{FALSE, 2, DXGI_SWAP_EFFECT_DISCARD, S_OK, S_OK, 0},
{FALSE, 0, DXGI_SWAP_EFFECT_SEQUENTIAL, DXGI_ERROR_INVALID_CALL, DXGI_ERROR_INVALID_CALL, 0},
{FALSE, 1, DXGI_SWAP_EFFECT_SEQUENTIAL, S_OK, S_OK, 0},
{FALSE, 2, DXGI_SWAP_EFFECT_SEQUENTIAL, S_OK, S_OK, 1},
{FALSE, 3, DXGI_SWAP_EFFECT_SEQUENTIAL, S_OK, S_OK, 2},
{FALSE, 0, 2 /* undefined */, DXGI_ERROR_INVALID_CALL, DXGI_ERROR_INVALID_CALL, 0},
{FALSE, 1, 2 /* undefined */, DXGI_ERROR_INVALID_CALL, DXGI_ERROR_INVALID_CALL, 0},
{FALSE, 2, 2 /* undefined */, DXGI_ERROR_INVALID_CALL, DXGI_ERROR_INVALID_CALL, 0},
{FALSE, 0, DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL, DXGI_ERROR_INVALID_CALL, DXGI_ERROR_INVALID_CALL, 0},
{FALSE, 1, DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL, DXGI_ERROR_INVALID_CALL, DXGI_ERROR_INVALID_CALL, 0},
{FALSE, 2, DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL, S_OK, DXGI_ERROR_INVALID_CALL, 1},
{FALSE, 3, DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL, S_OK, DXGI_ERROR_INVALID_CALL, 2},
{FALSE, 0, 4 /* undefined */, DXGI_ERROR_INVALID_CALL, DXGI_ERROR_INVALID_CALL, 0},
{FALSE, 1, 4 /* undefined */, DXGI_ERROR_INVALID_CALL, DXGI_ERROR_INVALID_CALL, 0},
{FALSE, 2, 4 /* undefined */, DXGI_ERROR_INVALID_CALL, DXGI_ERROR_INVALID_CALL, 0},
{FALSE, 16, DXGI_SWAP_EFFECT_DISCARD, S_OK, S_OK, 0},
{FALSE, 16, DXGI_SWAP_EFFECT_SEQUENTIAL, S_OK, S_OK, 15},
{FALSE, 16, DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL, S_OK, DXGI_ERROR_INVALID_CALL, 15},
{FALSE, 17, DXGI_SWAP_EFFECT_DISCARD, DXGI_ERROR_INVALID_CALL, DXGI_ERROR_INVALID_CALL, 0},
{FALSE, 17, DXGI_SWAP_EFFECT_SEQUENTIAL, DXGI_ERROR_INVALID_CALL, DXGI_ERROR_INVALID_CALL, 0},
{FALSE, 17, DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL, DXGI_ERROR_INVALID_CALL, DXGI_ERROR_INVALID_CALL, 0},
};
if (!(device = create_device()))
{
skip("Failed to create device, skipping tests.\n");
return;
}
window = CreateWindowA("static", "dxgi_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
0, 0, 640, 480, 0, 0, 0, 0);
hr = IDXGIDevice_QueryInterface(device, &IID_IUnknown, (void **)&obj);
ok(SUCCEEDED(hr), "IDXGIDevice does not implement IUnknown\n");
hr = IDXGIDevice_GetAdapter(device, &adapter);
ok(SUCCEEDED(hr), "GetAdapter failed, hr %#x.\n", hr);
hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
ok(SUCCEEDED(hr), "GetParent failed, hr %#x.\n", hr);
for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
{
memset(&desc, 0, sizeof(desc));
desc.BufferDesc.Width = registry_mode.dmPelsWidth;
desc.BufferDesc.Height = registry_mode.dmPelsHeight;
desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
desc.SampleDesc.Count = 1;
desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
desc.OutputWindow = window;
desc.Windowed = tests[i].windowed;
desc.BufferCount = tests[i].buffer_count;
desc.SwapEffect = tests[i].swap_effect;
hr = IDXGIFactory_CreateSwapChain(factory, obj, &desc, &swapchain);
ok(hr == tests[i].hr || broken(hr == tests[i].vista_hr)
|| (SUCCEEDED(tests[i].hr) && hr == DXGI_STATUS_OCCLUDED),
"Got unexpected hr %#x, test %u.\n", hr, i);
if (FAILED(hr))
continue;
hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_IDXGIResource, (void **)&resource);
todo_wine ok(SUCCEEDED(hr), "GetBuffer(0) failed, hr %#x, test %u.\n", hr, i);
if (FAILED(hr))
{
hr = IDXGISwapChain_SetFullscreenState(swapchain, FALSE, NULL);
todo_wine ok(SUCCEEDED(hr), "SetFullscreenState failed, hr %#x.\n", hr);
IDXGISwapChain_Release(swapchain);
continue;
}
expected_usage = DXGI_USAGE_RENDER_TARGET_OUTPUT | DXGI_USAGE_BACK_BUFFER;
if (tests[i].swap_effect == DXGI_SWAP_EFFECT_DISCARD)
expected_usage |= DXGI_USAGE_DISCARD_ON_PRESENT;
hr = IDXGIResource_GetUsage(resource, &usage);
ok(SUCCEEDED(hr), "Failed to get resource usage, hr %#x, test %u.\n", hr, i);
ok(usage == expected_usage, "Got usage %x, expected %x, test %u.\n", usage, expected_usage, i);
IDXGIResource_Release(resource);
hr = IDXGISwapChain_GetDesc(swapchain, &desc);
ok(SUCCEEDED(hr), "Failed to get swapchain desc, hr %#x.\n", hr);
for (j = 1; j <= tests[i].highest_accessible_buffer; j++)
{
hr = IDXGISwapChain_GetBuffer(swapchain, j, &IID_IDXGIResource, (void **)&resource);
ok(SUCCEEDED(hr), "GetBuffer(%u) failed, hr %#x, test %u.\n", hr, i, j);
expected_usage = DXGI_USAGE_RENDER_TARGET_OUTPUT | DXGI_USAGE_BACK_BUFFER;
/* Buffers > 0 are supposed to be read only. This is the case except that in
* fullscreen mode the last backbuffer (BufferCount - 1) is writeable. This
* is not the case if an unsupported refresh rate is passed for some reason,
* probably because the invalid refresh rate triggers a kinda-sorta windowed
* mode.
*
* This last buffer acts as a shadow frontbuffer. Writing to it doesn't show
* the draw on the screen right away (Aero on or off doesn't matter), but
* Present with DXGI_PRESENT_DO_NOT_SEQUENCE will show the modifications.
*
* Note that if the application doesn't have focused creating a fullscreen
* swapchain returns DXGI_STATUS_OCCLUDED and we get a windowed swapchain,
* so use the Windowed property of the swapchain that was actually created. */
if (desc.Windowed || j < tests[i].highest_accessible_buffer)
expected_usage |= DXGI_USAGE_READ_ONLY;
hr = IDXGIResource_GetUsage(resource, &usage);
ok(SUCCEEDED(hr), "Failed to get resource usage, hr %#x, test %u, buffer %u.\n", hr, i, j);
ok(usage == expected_usage, "Got usage %x, expected %x, test %u, buffer %u.\n",
usage, expected_usage, i, j);
IDXGIResource_Release(resource);
}
hr = IDXGISwapChain_GetBuffer(swapchain, j, &IID_IDXGIResource, (void **)&resource);
ok(hr == DXGI_ERROR_INVALID_CALL, "GetBuffer(%u) returned unexpected hr %#x, test %u.\n", j, hr, i);
hr = IDXGISwapChain_SetFullscreenState(swapchain, FALSE, NULL);
todo_wine ok(SUCCEEDED(hr), "SetFullscreenState failed, hr %#x.\n", hr);
IDXGISwapChain_Release(swapchain);
}
IDXGIFactory_Release(factory);
IDXGIAdapter_Release(adapter);
IUnknown_Release(obj);
refcount = IDXGIDevice_Release(device);
ok(!refcount, "Device has %u references left.\n", refcount);
DestroyWindow(window);
}
START_TEST(device)
{
pCreateDXGIFactory1 = (void *)GetProcAddress(GetModuleHandleA("dxgi.dll"), "CreateDXGIFactory1");
registry_mode.dmSize = sizeof(registry_mode);
ok(EnumDisplaySettingsW(NULL, ENUM_REGISTRY_SETTINGS, &registry_mode), "Failed to get display mode.\n");
test_adapter_desc();
test_device_interfaces();
test_create_surface();
test_parents();
test_output();
test_createswapchain();
test_create_factory();
test_private_data();
test_swapchain_resize();
test_swapchain_parameters();
}