2008-10-21 15:06:58 +02:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2008-11-17 12:16:04 +01:00
|
|
|
#define DXGI_INIT_GUID
|
2008-10-21 15:06:58 +02:00
|
|
|
#include "dxgi_private.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(dxgi);
|
|
|
|
|
2008-11-14 13:57:06 +01:00
|
|
|
struct dxgi_main
|
|
|
|
{
|
2008-11-14 13:57:06 +01:00
|
|
|
HMODULE d3d10core;
|
2008-11-14 13:57:06 +01:00
|
|
|
struct dxgi_device_layer *device_layers;
|
|
|
|
UINT layer_count;
|
|
|
|
};
|
|
|
|
static struct dxgi_main dxgi_main;
|
|
|
|
|
|
|
|
static void dxgi_main_cleanup(void)
|
|
|
|
{
|
2018-02-06 00:34:19 +01:00
|
|
|
heap_free(dxgi_main.device_layers);
|
2008-11-14 13:57:06 +01:00
|
|
|
FreeLibrary(dxgi_main.d3d10core);
|
2008-11-14 13:57:06 +01:00
|
|
|
}
|
|
|
|
|
2013-09-16 10:57:28 +02:00
|
|
|
BOOL WINAPI DllMain(HINSTANCE inst, DWORD reason, void *reserved)
|
2008-10-21 15:06:58 +02:00
|
|
|
{
|
2013-09-16 10:57:28 +02:00
|
|
|
switch (reason)
|
2008-10-21 15:06:58 +02:00
|
|
|
{
|
|
|
|
case DLL_PROCESS_ATTACH:
|
2013-09-16 10:57:28 +02:00
|
|
|
DisableThreadLibraryCalls(inst);
|
2008-11-14 13:57:06 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DLL_PROCESS_DETACH:
|
2013-09-16 10:57:28 +02:00
|
|
|
if (!reserved)
|
|
|
|
dxgi_main_cleanup();
|
2008-10-21 15:06:58 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2008-10-21 15:06:58 +02:00
|
|
|
|
2018-01-19 13:30:17 +01:00
|
|
|
HRESULT WINAPI CreateDXGIFactory2(UINT flags, REFIID iid, void **factory)
|
2008-10-21 15:06:58 +02:00
|
|
|
{
|
2018-01-19 13:30:17 +01:00
|
|
|
TRACE("flags %#x, iid %s, factory %p.\n", flags, debugstr_guid(iid), factory);
|
2008-10-21 15:06:58 +02:00
|
|
|
|
2018-01-19 13:30:17 +01:00
|
|
|
if (flags)
|
|
|
|
FIXME("Ignoring flags %#x.\n", flags);
|
|
|
|
|
|
|
|
return dxgi_factory_create(iid, factory, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI CreateDXGIFactory1(REFIID iid, void **factory)
|
|
|
|
{
|
|
|
|
TRACE("iid %s, factory %p.\n", debugstr_guid(iid), factory);
|
|
|
|
|
|
|
|
return dxgi_factory_create(iid, factory, TRUE);
|
2014-02-11 11:42:20 +01:00
|
|
|
}
|
2008-10-21 15:06:58 +02:00
|
|
|
|
2018-01-19 13:30:17 +01:00
|
|
|
HRESULT WINAPI CreateDXGIFactory(REFIID iid, void **factory)
|
2014-02-11 11:42:20 +01:00
|
|
|
{
|
2018-01-19 13:30:17 +01:00
|
|
|
TRACE("iid %s, factory %p.\n", debugstr_guid(iid), factory);
|
2008-10-21 15:06:58 +02:00
|
|
|
|
2018-01-19 13:30:17 +01:00
|
|
|
return dxgi_factory_create(iid, factory, FALSE);
|
2008-10-21 15:06:58 +02:00
|
|
|
}
|
2008-11-12 15:43:46 +01:00
|
|
|
|
2008-11-14 13:57:06 +01:00
|
|
|
static BOOL get_layer(enum dxgi_device_layer_id id, struct dxgi_device_layer *layer)
|
|
|
|
{
|
|
|
|
UINT i;
|
|
|
|
|
2015-09-17 01:10:13 +02:00
|
|
|
wined3d_mutex_lock();
|
2008-11-14 13:57:06 +01:00
|
|
|
|
|
|
|
for (i = 0; i < dxgi_main.layer_count; ++i)
|
|
|
|
{
|
|
|
|
if (dxgi_main.device_layers[i].id == id)
|
|
|
|
{
|
|
|
|
*layer = dxgi_main.device_layers[i];
|
2015-09-17 01:10:13 +02:00
|
|
|
wined3d_mutex_unlock();
|
2008-11-14 13:57:06 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-17 01:10:13 +02:00
|
|
|
wined3d_mutex_unlock();
|
2008-11-14 13:57:06 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT register_d3d10core_layers(HMODULE d3d10core)
|
|
|
|
{
|
2015-09-17 01:10:13 +02:00
|
|
|
wined3d_mutex_lock();
|
2008-11-14 13:57:06 +01:00
|
|
|
|
|
|
|
if (!dxgi_main.d3d10core)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
2015-08-21 00:07:53 +02:00
|
|
|
HRESULT (WINAPI *d3d11core_register_layers)(void);
|
2008-11-14 13:57:06 +01:00
|
|
|
HMODULE mod;
|
|
|
|
BOOL ret;
|
|
|
|
|
2013-09-16 10:57:27 +02:00
|
|
|
if (!(ret = GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (const char *)d3d10core, &mod)))
|
2008-11-14 13:57:06 +01:00
|
|
|
{
|
2015-09-17 01:10:13 +02:00
|
|
|
wined3d_mutex_unlock();
|
2008-11-14 13:57:06 +01:00
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2015-08-21 00:07:53 +02:00
|
|
|
d3d11core_register_layers = (void *)GetProcAddress(mod, "D3D11CoreRegisterLayers");
|
|
|
|
hr = d3d11core_register_layers();
|
2008-11-14 13:57:06 +01:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2017-04-28 09:42:53 +02:00
|
|
|
ERR("Failed to register d3d11 layers, returning %#x.\n", hr);
|
|
|
|
FreeLibrary(mod);
|
2015-09-17 01:10:13 +02:00
|
|
|
wined3d_mutex_unlock();
|
2008-11-14 13:57:06 +01:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
dxgi_main.d3d10core = mod;
|
|
|
|
}
|
|
|
|
|
2015-09-17 01:10:13 +02:00
|
|
|
wined3d_mutex_unlock();
|
2008-11-14 13:57:06 +01:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI DXGID3D10CreateDevice(HMODULE d3d10core, IDXGIFactory *factory, IDXGIAdapter *adapter,
|
2016-03-09 23:19:19 +01:00
|
|
|
unsigned int flags, const D3D_FEATURE_LEVEL *feature_levels, unsigned int level_count, void **device)
|
2008-11-14 13:57:06 +01:00
|
|
|
{
|
|
|
|
struct layer_get_size_args get_size_args;
|
|
|
|
struct dxgi_device_layer d3d10_layer;
|
2016-04-22 11:18:42 +02:00
|
|
|
struct dxgi_device *dxgi_device;
|
2008-11-14 13:57:06 +01:00
|
|
|
UINT device_size;
|
|
|
|
DWORD count;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2016-03-09 23:19:19 +01:00
|
|
|
TRACE("d3d10core %p, factory %p, adapter %p, flags %#x, feature_levels %p, level_count %u, device %p.\n",
|
|
|
|
d3d10core, factory, adapter, flags, feature_levels, level_count, device);
|
|
|
|
|
2016-04-22 11:18:42 +02:00
|
|
|
if (flags)
|
|
|
|
FIXME("Ignoring flags %#x.\n", flags);
|
|
|
|
|
|
|
|
if (TRACE_ON(dxgi))
|
|
|
|
dump_feature_levels(feature_levels, level_count);
|
2008-11-14 13:57:06 +01:00
|
|
|
|
|
|
|
hr = register_d3d10core_layers(d3d10core);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2016-04-22 11:18:42 +02:00
|
|
|
ERR("Failed to register d3d10core layers, returning %#x.\n", hr);
|
2008-11-14 13:57:06 +01:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!get_layer(DXGI_DEVICE_LAYER_D3D10_DEVICE, &d3d10_layer))
|
|
|
|
{
|
2016-04-22 11:18:42 +02:00
|
|
|
ERR("Failed to get D3D10 device layer.\n");
|
2008-11-14 13:57:06 +01:00
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
count = 0;
|
|
|
|
hr = d3d10_layer.init(d3d10_layer.id, &count, NULL);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2016-04-22 11:18:42 +02:00
|
|
|
WARN("Failed to initialize D3D10 device layer.\n");
|
2008-11-14 13:57:06 +01:00
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
get_size_args.unknown0 = 0;
|
|
|
|
get_size_args.unknown1 = 0;
|
|
|
|
get_size_args.unknown2 = NULL;
|
|
|
|
get_size_args.unknown3 = NULL;
|
|
|
|
get_size_args.adapter = adapter;
|
|
|
|
get_size_args.interface_major = 10;
|
|
|
|
get_size_args.interface_minor = 1;
|
|
|
|
get_size_args.version_build = 4;
|
|
|
|
get_size_args.version_revision = 6000;
|
|
|
|
|
|
|
|
device_size = d3d10_layer.get_size(d3d10_layer.id, &get_size_args, 0);
|
|
|
|
device_size += sizeof(*dxgi_device);
|
|
|
|
|
2018-02-06 00:34:19 +01:00
|
|
|
if (!(dxgi_device = heap_alloc_zero(device_size)))
|
2008-11-14 13:57:06 +01:00
|
|
|
{
|
2016-04-22 11:18:42 +02:00
|
|
|
ERR("Failed to allocate device memory.\n");
|
2008-11-14 13:57:06 +01:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
2016-03-09 23:19:19 +01:00
|
|
|
hr = dxgi_device_init(dxgi_device, &d3d10_layer, factory, adapter, feature_levels, level_count);
|
2008-11-17 12:16:04 +01:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2009-11-19 11:41:25 +01:00
|
|
|
WARN("Failed to initialize device, hr %#x.\n", hr);
|
2018-02-06 00:34:19 +01:00
|
|
|
heap_free(dxgi_device);
|
2009-11-19 11:41:25 +01:00
|
|
|
*device = NULL;
|
|
|
|
return hr;
|
2008-11-14 13:57:06 +01:00
|
|
|
}
|
|
|
|
|
2009-11-19 11:41:25 +01:00
|
|
|
TRACE("Created device %p.\n", dxgi_device);
|
2017-04-28 09:42:54 +02:00
|
|
|
*device = &dxgi_device->IWineDXGIDevice_iface;
|
2008-11-14 13:57:06 +01:00
|
|
|
|
2009-11-19 11:41:25 +01:00
|
|
|
return S_OK;
|
2008-11-14 13:57:06 +01:00
|
|
|
}
|
|
|
|
|
2008-11-12 15:43:46 +01:00
|
|
|
HRESULT WINAPI DXGID3D10RegisterLayers(const struct dxgi_device_layer *layers, UINT layer_count)
|
|
|
|
{
|
2008-11-14 13:57:06 +01:00
|
|
|
UINT i;
|
|
|
|
struct dxgi_device_layer *new_layers;
|
|
|
|
|
|
|
|
TRACE("layers %p, layer_count %u\n", layers, layer_count);
|
|
|
|
|
2015-09-17 01:10:13 +02:00
|
|
|
wined3d_mutex_lock();
|
2008-11-14 13:57:06 +01:00
|
|
|
|
|
|
|
if (!dxgi_main.layer_count)
|
2018-02-06 00:34:19 +01:00
|
|
|
new_layers = heap_alloc(layer_count * sizeof(*new_layers));
|
2008-11-14 13:57:06 +01:00
|
|
|
else
|
2018-02-06 00:34:19 +01:00
|
|
|
new_layers = heap_realloc(dxgi_main.device_layers,
|
2008-11-14 13:57:06 +01:00
|
|
|
(dxgi_main.layer_count + layer_count) * sizeof(*new_layers));
|
|
|
|
|
|
|
|
if (!new_layers)
|
|
|
|
{
|
2015-09-17 01:10:13 +02:00
|
|
|
wined3d_mutex_unlock();
|
2008-11-14 13:57:06 +01:00
|
|
|
ERR("Failed to allocate layer memory\n");
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < layer_count; ++i)
|
|
|
|
{
|
|
|
|
const struct dxgi_device_layer *layer = &layers[i];
|
|
|
|
|
|
|
|
TRACE("layer %d: id %#x, init %p, get_size %p, create %p\n",
|
|
|
|
i, layer->id, layer->init, layer->get_size, layer->create);
|
|
|
|
|
|
|
|
new_layers[dxgi_main.layer_count + i] = *layer;
|
|
|
|
}
|
|
|
|
|
|
|
|
dxgi_main.device_layers = new_layers;
|
|
|
|
dxgi_main.layer_count += layer_count;
|
|
|
|
|
2015-09-17 01:10:13 +02:00
|
|
|
wined3d_mutex_unlock();
|
2008-11-12 15:43:46 +01:00
|
|
|
|
2008-11-14 13:57:06 +01:00
|
|
|
return S_OK;
|
2008-11-12 15:43:46 +01:00
|
|
|
}
|
2018-08-08 16:11:32 +02:00
|
|
|
|
|
|
|
HRESULT WINAPI DXGIGetDebugInterface1(UINT flags, REFIID iid, void **debug)
|
|
|
|
{
|
|
|
|
TRACE("flags %#x, iid %s, debug %p.\n", flags, debugstr_guid(iid), debug);
|
|
|
|
|
2018-08-15 12:03:23 +02:00
|
|
|
WARN("Returning DXGI_ERROR_SDK_COMPONENT_MISSING.\n");
|
|
|
|
return DXGI_ERROR_SDK_COMPONENT_MISSING;
|
2018-08-08 16:11:32 +02:00
|
|
|
}
|