Sweden-Number/dlls/dxgi/adapter.c

282 lines
8.7 KiB
C
Raw Normal View History

2008-10-29 09:00:26 +01: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"
#include "wine/port.h"
#include "dxgi_private.h"
WINE_DEFAULT_DEBUG_CHANNEL(dxgi);
2014-09-15 11:03:34 +02:00
static inline struct dxgi_adapter *impl_from_IDXGIAdapter1(IDXGIAdapter1 *iface)
{
2014-09-15 11:03:34 +02:00
return CONTAINING_RECORD(iface, struct dxgi_adapter, IDXGIAdapter1_iface);
}
2014-09-15 11:03:34 +02:00
static HRESULT STDMETHODCALLTYPE dxgi_adapter_QueryInterface(IDXGIAdapter1 *iface, REFIID iid, void **out)
2008-10-29 09:00:26 +01:00
{
2014-09-15 11:03:34 +02:00
TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
2008-10-29 09:00:26 +01:00
2014-09-15 11:03:34 +02:00
if (IsEqualGUID(iid, &IID_IDXGIAdapter1)
|| IsEqualGUID(iid, &IID_IDXGIAdapter)
|| IsEqualGUID(iid, &IID_IDXGIObject)
|| IsEqualGUID(iid, &IID_IUnknown))
2008-10-29 09:00:26 +01:00
{
IUnknown_AddRef(iface);
2014-09-15 11:03:34 +02:00
*out = iface;
2008-10-29 09:00:26 +01:00
return S_OK;
}
2014-09-15 11:03:34 +02:00
WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid));
2008-10-29 09:00:26 +01:00
2014-09-15 11:03:34 +02:00
*out = NULL;
2008-10-29 09:00:26 +01:00
return E_NOINTERFACE;
}
2014-09-15 11:03:34 +02:00
static ULONG STDMETHODCALLTYPE dxgi_adapter_AddRef(IDXGIAdapter1 *iface)
2008-10-29 09:00:26 +01:00
{
2014-09-15 11:03:34 +02:00
struct dxgi_adapter *adapter = impl_from_IDXGIAdapter1(iface);
ULONG refcount = InterlockedIncrement(&adapter->refcount);
2008-10-29 09:00:26 +01:00
2014-09-15 11:03:34 +02:00
TRACE("%p increasing refcount to %u.\n", iface, refcount);
2008-10-29 09:00:26 +01:00
return refcount;
}
2014-09-15 11:03:34 +02:00
static ULONG STDMETHODCALLTYPE dxgi_adapter_Release(IDXGIAdapter1 *iface)
2008-10-29 09:00:26 +01:00
{
2014-09-15 11:03:34 +02:00
struct dxgi_adapter *adapter = impl_from_IDXGIAdapter1(iface);
ULONG refcount = InterlockedDecrement(&adapter->refcount);
2008-10-29 09:00:26 +01:00
2014-09-15 11:03:34 +02:00
TRACE("%p decreasing refcount to %u.\n", iface, refcount);
2008-10-29 09:00:26 +01:00
if (!refcount)
{
2014-09-15 11:03:34 +02:00
IDXGIOutput_Release(adapter->output);
wined3d_private_store_cleanup(&adapter->private_store);
2014-09-15 11:03:34 +02:00
HeapFree(GetProcessHeap(), 0, adapter);
2008-10-29 09:00:26 +01:00
}
return refcount;
}
2014-09-15 11:03:34 +02:00
static HRESULT STDMETHODCALLTYPE dxgi_adapter_SetPrivateData(IDXGIAdapter1 *iface,
2008-10-29 09:00:26 +01:00
REFGUID guid, UINT data_size, const void *data)
{
struct dxgi_adapter *adapter = impl_from_IDXGIAdapter1(iface);
2008-10-29 09:00:26 +01:00
TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
return dxgi_set_private_data(&adapter->private_store, guid, data_size, data);
2008-10-29 09:00:26 +01:00
}
2014-09-15 11:03:34 +02:00
static HRESULT STDMETHODCALLTYPE dxgi_adapter_SetPrivateDataInterface(IDXGIAdapter1 *iface,
2008-10-29 09:00:26 +01:00
REFGUID guid, const IUnknown *object)
{
struct dxgi_adapter *adapter = impl_from_IDXGIAdapter1(iface);
2008-10-29 09:00:26 +01:00
TRACE("iface %p, guid %s, object %p.\n", iface, debugstr_guid(guid), object);
return dxgi_set_private_data_interface(&adapter->private_store, guid, object);
2008-10-29 09:00:26 +01:00
}
2014-09-15 11:03:34 +02:00
static HRESULT STDMETHODCALLTYPE dxgi_adapter_GetPrivateData(IDXGIAdapter1 *iface,
2008-10-29 09:00:26 +01:00
REFGUID guid, UINT *data_size, void *data)
{
struct dxgi_adapter *adapter = impl_from_IDXGIAdapter1(iface);
TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
2008-10-29 09:00:26 +01:00
return dxgi_get_private_data(&adapter->private_store, guid, data_size, data);
2008-10-29 09:00:26 +01:00
}
2014-09-15 11:03:34 +02:00
static HRESULT STDMETHODCALLTYPE dxgi_adapter_GetParent(IDXGIAdapter1 *iface, REFIID iid, void **parent)
2008-10-29 09:00:26 +01:00
{
2014-09-15 11:03:34 +02:00
struct dxgi_adapter *adapter = impl_from_IDXGIAdapter1(iface);
2008-10-29 09:00:26 +01:00
2014-09-15 11:03:34 +02:00
TRACE("iface %p, iid %s, parent %p\n", iface, debugstr_guid(iid), parent);
2014-09-15 11:03:35 +02:00
return IDXGIFactory1_QueryInterface(&adapter->parent->IDXGIFactory1_iface, iid, parent);
2008-10-29 09:00:26 +01:00
}
2014-09-15 11:03:34 +02:00
static HRESULT STDMETHODCALLTYPE dxgi_adapter_EnumOutputs(IDXGIAdapter1 *iface,
UINT output_idx, IDXGIOutput **output)
2008-10-29 09:00:26 +01:00
{
2014-09-15 11:03:34 +02:00
struct dxgi_adapter *adapter = impl_from_IDXGIAdapter1(iface);
2008-10-29 09:00:26 +01:00
TRACE("iface %p, output_idx %u, output %p.\n", iface, output_idx, output);
if (output_idx > 0)
{
*output = NULL;
return DXGI_ERROR_NOT_FOUND;
}
2014-09-15 11:03:34 +02:00
*output = adapter->output;
IDXGIOutput_AddRef(*output);
TRACE("Returning output %p.\n", output);
return S_OK;
2008-10-29 09:00:26 +01:00
}
2014-09-15 11:03:34 +02:00
static HRESULT STDMETHODCALLTYPE dxgi_adapter_GetDesc1(IDXGIAdapter1 *iface, DXGI_ADAPTER_DESC1 *desc)
2008-10-29 09:00:26 +01:00
{
2014-09-15 11:03:34 +02:00
struct dxgi_adapter *adapter = impl_from_IDXGIAdapter1(iface);
struct wined3d_adapter_identifier adapter_id;
char description[128];
HRESULT hr;
2008-10-29 09:00:26 +01:00
TRACE("iface %p, desc %p.\n", iface, desc);
2014-01-28 10:09:25 +01:00
if (!desc)
return E_INVALIDARG;
adapter_id.driver_size = 0;
adapter_id.description = description;
adapter_id.description_size = sizeof(description);
adapter_id.device_name_size = 0;
wined3d_mutex_lock();
2014-09-15 11:03:35 +02:00
hr = wined3d_get_adapter_identifier(adapter->parent->wined3d, adapter->ordinal, 0, &adapter_id);
wined3d_mutex_unlock();
2014-01-28 10:09:25 +01:00
if (FAILED(hr))
return hr;
if (!MultiByteToWideChar(CP_ACP, 0, description, -1, desc->Description, 128))
{
2014-01-28 10:09:25 +01:00
DWORD err = GetLastError();
ERR("Failed to translate description %s (%#x).\n", debugstr_a(description), err);
hr = E_FAIL;
}
2014-01-28 10:09:25 +01:00
desc->VendorId = adapter_id.vendor_id;
desc->DeviceId = adapter_id.device_id;
desc->SubSysId = adapter_id.subsystem_id;
desc->Revision = adapter_id.revision;
desc->DedicatedVideoMemory = adapter_id.video_memory;
desc->DedicatedSystemMemory = 0; /* FIXME */
desc->SharedSystemMemory = 0; /* FIXME */
memcpy(&desc->AdapterLuid, &adapter_id.adapter_luid, sizeof(desc->AdapterLuid));
desc->Flags = 0;
return hr;
}
2014-09-15 11:03:34 +02:00
static HRESULT STDMETHODCALLTYPE dxgi_adapter_GetDesc(IDXGIAdapter1 *iface, DXGI_ADAPTER_DESC *desc)
2014-01-28 10:09:25 +01:00
{
DXGI_ADAPTER_DESC1 desc1;
HRESULT hr;
TRACE("iface %p, desc %p.\n", iface, desc);
if (!desc)
return E_INVALIDARG;
if (FAILED(hr = dxgi_adapter_GetDesc1(iface, &desc1)))
return hr;
memcpy(desc, &desc1, sizeof(*desc));
return hr;
2008-10-29 09:00:26 +01:00
}
2014-09-15 11:03:34 +02:00
static HRESULT STDMETHODCALLTYPE dxgi_adapter_CheckInterfaceSupport(IDXGIAdapter1 *iface,
2008-10-29 09:00:26 +01:00
REFGUID guid, LARGE_INTEGER *umd_version)
{
static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_10_0;
struct dxgi_adapter *adapter = impl_from_IDXGIAdapter1(iface);
struct wined3d_adapter_identifier adapter_id;
HRESULT hr;
TRACE("iface %p, guid %s, umd_version %p.\n", iface, debugstr_guid(guid), umd_version);
/* This method works only for D3D10 interfaces. */
if (!(IsEqualGUID(guid, &IID_ID3D10Device)
|| IsEqualGUID(guid, &IID_ID3D10Device1)))
{
WARN("Returning DXGI_ERROR_UNSUPPORTED for %s.\n", debugstr_guid(guid));
return DXGI_ERROR_UNSUPPORTED;
}
2008-10-29 09:00:26 +01:00
if (!dxgi_check_feature_level_support(adapter->parent, adapter, &feature_level, 1))
return DXGI_ERROR_UNSUPPORTED;
if (umd_version)
{
adapter_id.driver_size = 0;
adapter_id.description_size = 0;
adapter_id.device_name_size = 0;
wined3d_mutex_lock();
hr = wined3d_get_adapter_identifier(adapter->parent->wined3d, adapter->ordinal, 0, &adapter_id);
wined3d_mutex_unlock();
if (FAILED(hr))
return hr;
*umd_version = adapter_id.driver_version;
}
return S_OK;
2008-10-29 09:00:26 +01:00
}
2014-09-15 11:03:34 +02:00
static const struct IDXGIAdapter1Vtbl dxgi_adapter_vtbl =
2008-10-29 09:00:26 +01:00
{
dxgi_adapter_QueryInterface,
dxgi_adapter_AddRef,
dxgi_adapter_Release,
dxgi_adapter_SetPrivateData,
dxgi_adapter_SetPrivateDataInterface,
dxgi_adapter_GetPrivateData,
dxgi_adapter_GetParent,
dxgi_adapter_EnumOutputs,
dxgi_adapter_GetDesc,
dxgi_adapter_CheckInterfaceSupport,
2014-01-28 10:09:25 +01:00
dxgi_adapter_GetDesc1,
2008-10-29 09:00:26 +01:00
};
2014-09-15 11:03:34 +02:00
struct dxgi_adapter *unsafe_impl_from_IDXGIAdapter1(IDXGIAdapter1 *iface)
{
if (!iface)
return NULL;
assert(iface->lpVtbl == &dxgi_adapter_vtbl);
return CONTAINING_RECORD(iface, struct dxgi_adapter, IDXGIAdapter1_iface);
}
2014-09-15 11:03:35 +02:00
HRESULT dxgi_adapter_init(struct dxgi_adapter *adapter, struct dxgi_factory *parent, UINT ordinal)
{
struct dxgi_output *output;
2014-09-15 11:03:34 +02:00
adapter->IDXGIAdapter1_iface.lpVtbl = &dxgi_adapter_vtbl;
adapter->parent = parent;
adapter->refcount = 1;
wined3d_private_store_init(&adapter->private_store);
adapter->ordinal = ordinal;
if (!(output = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*output))))
{
wined3d_private_store_cleanup(&adapter->private_store);
return E_OUTOFMEMORY;
}
dxgi_output_init(output, adapter);
adapter->output = &output->IDXGIOutput_iface;
return S_OK;
}