d3d10: Validate SDK version.

Signed-off-by: Józef Kucia <jkucia@codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Józef Kucia 2017-05-05 11:59:23 +02:00 committed by Alexandre Julliard
parent 06d3244d24
commit 1a86bc9d75
2 changed files with 41 additions and 12 deletions

View File

@ -33,16 +33,22 @@ HRESULT WINAPI D3D10CreateDevice(IDXGIAdapter *adapter, D3D10_DRIVER_TYPE driver
IDXGIFactory *factory; IDXGIFactory *factory;
HRESULT hr; HRESULT hr;
TRACE("adapter %p, driver_type %s, swrast %p, flags %#x, sdk_version %d, device %p\n", TRACE("adapter %p, driver_type %s, swrast %p, flags %#x, sdk_version %#x, device %p.\n",
adapter, debug_d3d10_driver_type(driver_type), swrast, flags, sdk_version, device); adapter, debug_d3d10_driver_type(driver_type), swrast, flags, sdk_version, device);
if (sdk_version != D3D10_SDK_VERSION)
{
WARN("Invalid SDK version %#x.\n", sdk_version);
return E_INVALIDARG;
}
if (adapter) if (adapter)
{ {
IDXGIAdapter_AddRef(adapter); IDXGIAdapter_AddRef(adapter);
hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory); hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
if (FAILED(hr)) if (FAILED(hr))
{ {
WARN("Failed to get dxgi factory, returning %#x\n", hr); WARN("Failed to get dxgi factory, returning %#x.\n", hr);
return hr; return hr;
} }
} }
@ -51,18 +57,18 @@ HRESULT WINAPI D3D10CreateDevice(IDXGIAdapter *adapter, D3D10_DRIVER_TYPE driver
hr = CreateDXGIFactory(&IID_IDXGIFactory, (void **)&factory); hr = CreateDXGIFactory(&IID_IDXGIFactory, (void **)&factory);
if (FAILED(hr)) if (FAILED(hr))
{ {
WARN("Failed to create dxgi factory, returning %#x\n", hr); WARN("Failed to create dxgi factory, returning %#x.\n", hr);
return hr; return hr;
} }
switch(driver_type) switch (driver_type)
{ {
case D3D10_DRIVER_TYPE_HARDWARE: case D3D10_DRIVER_TYPE_HARDWARE:
{ {
hr = IDXGIFactory_EnumAdapters(factory, 0, &adapter); hr = IDXGIFactory_EnumAdapters(factory, 0, &adapter);
if (FAILED(hr)) if (FAILED(hr))
{ {
WARN("No adapters found, returning %#x\n", hr); WARN("No adapters found, returning %#x.\n", hr);
IDXGIFactory_Release(factory); IDXGIFactory_Release(factory);
return hr; return hr;
} }
@ -70,14 +76,14 @@ HRESULT WINAPI D3D10CreateDevice(IDXGIAdapter *adapter, D3D10_DRIVER_TYPE driver
} }
case D3D10_DRIVER_TYPE_NULL: case D3D10_DRIVER_TYPE_NULL:
FIXME("NULL device not implemented, falling back to refrast\n"); FIXME("NULL device not implemented, falling back to refrast.\n");
/* fall through, for now */ /* fall through, for now */
case D3D10_DRIVER_TYPE_REFERENCE: case D3D10_DRIVER_TYPE_REFERENCE:
{ {
HMODULE refrast = LoadLibraryA("d3d10ref.dll"); HMODULE refrast = LoadLibraryA("d3d10ref.dll");
if (!refrast) if (!refrast)
{ {
WARN("Failed to load refrast, returning E_FAIL\n"); WARN("Failed to load refrast, returning E_FAIL.\n");
IDXGIFactory_Release(factory); IDXGIFactory_Release(factory);
return E_FAIL; return E_FAIL;
} }
@ -85,7 +91,7 @@ HRESULT WINAPI D3D10CreateDevice(IDXGIAdapter *adapter, D3D10_DRIVER_TYPE driver
FreeLibrary(refrast); FreeLibrary(refrast);
if (FAILED(hr)) if (FAILED(hr))
{ {
WARN("Failed to create a software adapter, returning %#x\n", hr); WARN("Failed to create a software adapter, returning %#x.\n", hr);
IDXGIFactory_Release(factory); IDXGIFactory_Release(factory);
return hr; return hr;
} }
@ -96,14 +102,14 @@ HRESULT WINAPI D3D10CreateDevice(IDXGIAdapter *adapter, D3D10_DRIVER_TYPE driver
{ {
if (!swrast) if (!swrast)
{ {
WARN("Software device requested, but NULL swrast passed, returning E_FAIL\n"); WARN("Software device requested, but NULL swrast passed, returning E_FAIL.\n");
IDXGIFactory_Release(factory); IDXGIFactory_Release(factory);
return E_FAIL; return E_FAIL;
} }
hr = IDXGIFactory_CreateSoftwareAdapter(factory, swrast, &adapter); hr = IDXGIFactory_CreateSoftwareAdapter(factory, swrast, &adapter);
if (FAILED(hr)) if (FAILED(hr))
{ {
WARN("Failed to create a software adapter, returning %#x\n", hr); WARN("Failed to create a software adapter, returning %#x.\n", hr);
IDXGIFactory_Release(factory); IDXGIFactory_Release(factory);
return hr; return hr;
} }
@ -122,11 +128,11 @@ HRESULT WINAPI D3D10CreateDevice(IDXGIAdapter *adapter, D3D10_DRIVER_TYPE driver
IDXGIFactory_Release(factory); IDXGIFactory_Release(factory);
if (FAILED(hr)) if (FAILED(hr))
{ {
WARN("Failed to create a device, returning %#x\n", hr); WARN("Failed to create a device, returning %#x.\n", hr);
return hr; return hr;
} }
TRACE("Created ID3D10Device %p\n", *device); TRACE("Created ID3D10Device %p.\n", *device);
return hr; return hr;
} }

View File

@ -21,6 +21,28 @@
#include "d3d10.h" #include "d3d10.h"
#include "wine/test.h" #include "wine/test.h"
static void test_create_device(void)
{
ID3D10Device *device;
unsigned int i;
HRESULT hr;
if (FAILED(hr = D3D10CreateDevice(NULL, D3D10_DRIVER_TYPE_HARDWARE, NULL, 0, D3D10_SDK_VERSION, &device)))
{
skip("Failed to create HAL device.\n");
return;
}
ID3D10Device_Release(device);
for (i = 0; i < 100; ++i)
{
if (i == D3D10_SDK_VERSION)
continue;
hr = D3D10CreateDevice(NULL, D3D10_DRIVER_TYPE_HARDWARE, NULL, 0, i, &device);
ok(hr == E_INVALIDARG, "Got unexpected hr %#x for SDK version %#x.\n", hr, i);
}
}
static void test_stateblock_mask(void) static void test_stateblock_mask(void)
{ {
static const struct static const struct
@ -181,5 +203,6 @@ static void test_stateblock_mask(void)
START_TEST(device) START_TEST(device)
{ {
test_create_device();
test_stateblock_mask(); test_stateblock_mask();
} }