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

244 lines
8.2 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 "d3d10.h"
#include "wine/test.h"
HRESULT WINAPI DXGID3D10CreateDevice(HMODULE d3d10core, IDXGIFactory *factory,
IDXGIAdapter *adapter, UINT flags, void *unknown0, void **device);
static IDXGIDevice *create_device(HMODULE d3d10core)
{
IDXGIDevice *dxgi_device = NULL;
IDXGIFactory *factory = NULL;
IDXGIAdapter *adapter = NULL;
IUnknown *device = NULL;
HRESULT hr;
hr = CreateDXGIFactory(&IID_IDXGIFactory, (void *)&factory);
if (FAILED(hr)) goto cleanup;
hr = IDXGIFactory_EnumAdapters(factory, 0, &adapter);
if (SUCCEEDED(hr))
{
hr = DXGID3D10CreateDevice(d3d10core, factory, adapter, 0, NULL, (void **)&device);
}
if (FAILED(hr))
{
HMODULE d3d10ref;
trace("Failed to create a HW device, trying REF\n");
if (adapter) IDXGIAdapter_Release(adapter);
adapter = NULL;
d3d10ref = LoadLibraryA("d3d10ref.dll");
if (!d3d10ref)
{
trace("d3d10ref.dll not available, unable to create a REF device\n");
goto cleanup;
}
hr = IDXGIFactory_CreateSoftwareAdapter(factory, d3d10ref, &adapter);
FreeLibrary(d3d10ref);
ok(SUCCEEDED(hr), "CreateSoftwareAdapter failed, hr %#x\n", hr);
if (FAILED(hr)) goto cleanup;
hr = DXGID3D10CreateDevice(d3d10core, factory, adapter, 0, NULL, (void **)&device);
ok(SUCCEEDED(hr), "Failed to create a REF device, hr %#x\n", hr);
if (FAILED(hr)) goto cleanup;
}
hr = IUnknown_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
ok(SUCCEEDED(hr), "Created device does not implement IDXGIDevice\n");
IUnknown_Release(device);
cleanup:
if (adapter) IDXGIAdapter_Release(adapter);
if (factory) IDXGIFactory_Release(factory);
return dxgi_device;
}
static void test_device_interfaces(IDXGIDevice *device)
{
IUnknown *obj;
HRESULT hr;
if (SUCCEEDED(hr = IDXGIDevice_QueryInterface(device, &IID_IUnknown, (void **)&obj)))
IUnknown_Release(obj);
ok(SUCCEEDED(hr), "IDXGIDevice does not implement IUnknown\n");
if (SUCCEEDED(hr = IDXGIDevice_QueryInterface(device, &IID_IDXGIObject, (void **)&obj)))
IUnknown_Release(obj);
ok(SUCCEEDED(hr), "IDXGIDevice does not implement IDXGIObject\n");
if (SUCCEEDED(hr = IDXGIDevice_QueryInterface(device, &IID_IDXGIDevice, (void **)&obj)))
IUnknown_Release(obj);
ok(SUCCEEDED(hr), "IDXGIDevice does not implement IDXGIDevice\n");
if (SUCCEEDED(hr = IDXGIDevice_QueryInterface(device, &IID_ID3D10Device, (void **)&obj)))
IUnknown_Release(obj);
ok(SUCCEEDED(hr), "IDXGIDevice does not implement ID3D10Device\n");
}
static void test_adapter_desc(IDXGIDevice *device)
{
DXGI_ADAPTER_DESC desc;
IDXGIAdapter *adapter;
HRESULT hr;
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);
IDXGIAdapter_Release(adapter);
}
static void test_create_surface(IDXGIDevice *device)
{
ID3D10Texture2D *texture;
IDXGISurface *surface;
DXGI_SURFACE_DESC desc;
HRESULT hr;
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");
if (SUCCEEDED(hr)) ID3D10Texture2D_Release(texture);
IDXGISurface_Release(surface);
}
static void test_parents(IDXGIDevice *device)
{
DXGI_SURFACE_DESC surface_desc;
IDXGISurface *surface;
IDXGIFactory *factory;
IDXGIAdapter *adapter;
IDXGIOutput *output;
IUnknown *parent;
HRESULT hr;
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);
}
START_TEST(device)
{
HMODULE d3d10core = LoadLibraryA("d3d10core.dll");
IDXGIDevice *device;
ULONG refcount;
if (!d3d10core)
{
win_skip("d3d10core.dll not available, skipping tests\n");
return;
}
device = create_device(d3d10core);
if (!device)
{
skip("Failed to create device, skipping tests\n");
FreeLibrary(d3d10core);
return;
}
test_adapter_desc(device);
test_device_interfaces(device);
test_create_surface(device);
test_parents(device);
refcount = IDXGIDevice_Release(device);
ok(!refcount, "Device has %u references left\n", refcount);
FreeLibrary(d3d10core);
}