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);
|
|
|
|
|
2011-06-07 10:09:02 +02:00
|
|
|
static inline struct dxgi_adapter *impl_from_IWineDXGIAdapter(IWineDXGIAdapter *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, struct dxgi_adapter, IWineDXGIAdapter_iface);
|
|
|
|
}
|
|
|
|
|
2008-10-29 09:00:26 +01:00
|
|
|
/* IUnknown methods */
|
|
|
|
|
2008-11-17 12:16:04 +01:00
|
|
|
static HRESULT STDMETHODCALLTYPE dxgi_adapter_QueryInterface(IWineDXGIAdapter *iface, REFIID riid, void **object)
|
2008-10-29 09:00:26 +01:00
|
|
|
{
|
|
|
|
TRACE("iface %p, riid %s, object %p\n", iface, debugstr_guid(riid), object);
|
|
|
|
|
|
|
|
if (IsEqualGUID(riid, &IID_IUnknown)
|
|
|
|
|| IsEqualGUID(riid, &IID_IDXGIObject)
|
2008-11-17 12:16:04 +01:00
|
|
|
|| IsEqualGUID(riid, &IID_IDXGIAdapter)
|
|
|
|
|| IsEqualGUID(riid, &IID_IWineDXGIAdapter))
|
2008-10-29 09:00:26 +01:00
|
|
|
{
|
|
|
|
IUnknown_AddRef(iface);
|
|
|
|
*object = iface;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid));
|
|
|
|
|
|
|
|
*object = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
2008-11-17 12:16:04 +01:00
|
|
|
static ULONG STDMETHODCALLTYPE dxgi_adapter_AddRef(IWineDXGIAdapter *iface)
|
2008-10-29 09:00:26 +01:00
|
|
|
{
|
2011-06-07 10:09:02 +02:00
|
|
|
struct dxgi_adapter *This = impl_from_IWineDXGIAdapter(iface);
|
2008-10-29 09:00:26 +01:00
|
|
|
ULONG refcount = InterlockedIncrement(&This->refcount);
|
|
|
|
|
|
|
|
TRACE("%p increasing refcount to %u\n", This, refcount);
|
|
|
|
|
|
|
|
return refcount;
|
|
|
|
}
|
|
|
|
|
2008-11-17 12:16:04 +01:00
|
|
|
static ULONG STDMETHODCALLTYPE dxgi_adapter_Release(IWineDXGIAdapter *iface)
|
2008-10-29 09:00:26 +01:00
|
|
|
{
|
2011-06-07 10:09:02 +02:00
|
|
|
struct dxgi_adapter *This = impl_from_IWineDXGIAdapter(iface);
|
2008-10-29 09:00:26 +01:00
|
|
|
ULONG refcount = InterlockedDecrement(&This->refcount);
|
|
|
|
|
|
|
|
TRACE("%p decreasing refcount to %u\n", This, refcount);
|
|
|
|
|
|
|
|
if (!refcount)
|
|
|
|
{
|
2009-09-11 19:01:14 +02:00
|
|
|
IDXGIOutput_Release(This->output);
|
2008-10-29 09:00:26 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
}
|
|
|
|
|
|
|
|
return refcount;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* IDXGIObject methods */
|
|
|
|
|
2008-11-17 12:16:04 +01:00
|
|
|
static HRESULT STDMETHODCALLTYPE dxgi_adapter_SetPrivateData(IWineDXGIAdapter *iface,
|
2008-10-29 09:00:26 +01:00
|
|
|
REFGUID guid, UINT data_size, const void *data)
|
|
|
|
{
|
|
|
|
FIXME("iface %p, guid %s, data_size %u, data %p stub!\n", iface, debugstr_guid(guid), data_size, data);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2008-11-17 12:16:04 +01:00
|
|
|
static HRESULT STDMETHODCALLTYPE dxgi_adapter_SetPrivateDataInterface(IWineDXGIAdapter *iface,
|
2008-10-29 09:00:26 +01:00
|
|
|
REFGUID guid, const IUnknown *object)
|
|
|
|
{
|
|
|
|
FIXME("iface %p, guid %s, object %p stub!\n", iface, debugstr_guid(guid), object);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2008-11-17 12:16:04 +01:00
|
|
|
static HRESULT STDMETHODCALLTYPE dxgi_adapter_GetPrivateData(IWineDXGIAdapter *iface,
|
2008-10-29 09:00:26 +01:00
|
|
|
REFGUID guid, UINT *data_size, void *data)
|
|
|
|
{
|
|
|
|
FIXME("iface %p, guid %s, data_size %p, data %p stub!\n", iface, debugstr_guid(guid), data_size, data);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2008-11-17 12:16:04 +01:00
|
|
|
static HRESULT STDMETHODCALLTYPE dxgi_adapter_GetParent(IWineDXGIAdapter *iface, REFIID riid, void **parent)
|
2008-10-29 09:00:26 +01:00
|
|
|
{
|
2011-06-07 10:09:02 +02:00
|
|
|
struct dxgi_adapter *This = impl_from_IWineDXGIAdapter(iface);
|
2008-10-29 09:00:26 +01:00
|
|
|
|
2008-11-20 13:32:00 +01:00
|
|
|
TRACE("iface %p, riid %s, parent %p\n", iface, debugstr_guid(riid), parent);
|
|
|
|
|
2009-12-04 11:50:49 +01:00
|
|
|
return IWineDXGIFactory_QueryInterface(This->parent, riid, parent);
|
2008-10-29 09:00:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* IDXGIAdapter methods */
|
|
|
|
|
2008-11-17 12:16:04 +01:00
|
|
|
static HRESULT STDMETHODCALLTYPE dxgi_adapter_EnumOutputs(IWineDXGIAdapter *iface,
|
|
|
|
UINT output_idx, IDXGIOutput **output)
|
2008-10-29 09:00:26 +01:00
|
|
|
{
|
2011-06-07 10:09:02 +02:00
|
|
|
struct dxgi_adapter *This = impl_from_IWineDXGIAdapter(iface);
|
2008-10-29 09:00:26 +01:00
|
|
|
|
2009-09-11 19:01:14 +02: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;
|
|
|
|
}
|
|
|
|
|
|
|
|
*output = This->output;
|
|
|
|
IDXGIOutput_AddRef(*output);
|
|
|
|
|
|
|
|
TRACE("Returning output %p.\n", output);
|
|
|
|
|
|
|
|
return S_OK;
|
2008-10-29 09:00:26 +01:00
|
|
|
}
|
|
|
|
|
2008-11-17 12:16:04 +01:00
|
|
|
static HRESULT STDMETHODCALLTYPE dxgi_adapter_GetDesc(IWineDXGIAdapter *iface, DXGI_ADAPTER_DESC *desc)
|
2008-10-29 09:00:26 +01:00
|
|
|
{
|
2011-06-07 10:09:02 +02:00
|
|
|
struct dxgi_adapter *This = impl_from_IWineDXGIAdapter(iface);
|
2009-12-04 11:50:49 +01:00
|
|
|
WINED3DADAPTER_IDENTIFIER adapter_id;
|
|
|
|
char description[128];
|
2011-02-01 19:39:53 +01:00
|
|
|
struct wined3d *wined3d;
|
2009-12-04 11:50:49 +01:00
|
|
|
HRESULT hr;
|
2008-10-29 09:00:26 +01:00
|
|
|
|
2009-12-04 11:50:49 +01:00
|
|
|
TRACE("iface %p, desc %p.\n", iface, desc);
|
|
|
|
|
|
|
|
if (!desc) return E_INVALIDARG;
|
|
|
|
|
|
|
|
wined3d = IWineDXGIFactory_get_wined3d(This->parent);
|
|
|
|
adapter_id.driver_size = 0;
|
|
|
|
adapter_id.description = description;
|
|
|
|
adapter_id.description_size = sizeof(description);
|
|
|
|
adapter_id.device_name_size = 0;
|
|
|
|
|
|
|
|
EnterCriticalSection(&dxgi_cs);
|
2011-02-01 19:39:53 +01:00
|
|
|
hr = wined3d_get_adapter_identifier(wined3d, This->ordinal, 0, &adapter_id);
|
|
|
|
wined3d_decref(wined3d);
|
2009-12-04 11:50:49 +01:00
|
|
|
LeaveCriticalSection(&dxgi_cs);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
if (!MultiByteToWideChar(CP_ACP, 0, description, -1, desc->Description, 128))
|
|
|
|
{
|
|
|
|
DWORD err = GetLastError();
|
|
|
|
ERR("Failed to translate description %s (%#x).\n", debugstr_a(description), err);
|
|
|
|
hr = E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
2008-10-29 09:00:26 +01:00
|
|
|
}
|
|
|
|
|
2008-11-17 12:16:04 +01:00
|
|
|
static HRESULT STDMETHODCALLTYPE dxgi_adapter_CheckInterfaceSupport(IWineDXGIAdapter *iface,
|
2008-10-29 09:00:26 +01:00
|
|
|
REFGUID guid, LARGE_INTEGER *umd_version)
|
|
|
|
{
|
|
|
|
FIXME("iface %p, guid %s, umd_version %p stub!\n", iface, debugstr_guid(guid), umd_version);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2008-11-17 12:16:04 +01:00
|
|
|
/* IWineDXGIAdapter methods */
|
|
|
|
|
|
|
|
static UINT STDMETHODCALLTYPE dxgi_adapter_get_ordinal(IWineDXGIAdapter *iface)
|
|
|
|
{
|
2011-06-07 10:09:02 +02:00
|
|
|
struct dxgi_adapter *This = impl_from_IWineDXGIAdapter(iface);
|
2008-11-17 12:16:04 +01:00
|
|
|
|
|
|
|
TRACE("iface %p, returning %u\n", iface, This->ordinal);
|
|
|
|
|
|
|
|
return This->ordinal;
|
|
|
|
}
|
|
|
|
|
2009-09-10 16:57:19 +02:00
|
|
|
static const struct IWineDXGIAdapterVtbl dxgi_adapter_vtbl =
|
2008-10-29 09:00:26 +01:00
|
|
|
{
|
|
|
|
/* IUnknown methods */
|
|
|
|
dxgi_adapter_QueryInterface,
|
|
|
|
dxgi_adapter_AddRef,
|
|
|
|
dxgi_adapter_Release,
|
|
|
|
/* IDXGIObject methods */
|
|
|
|
dxgi_adapter_SetPrivateData,
|
|
|
|
dxgi_adapter_SetPrivateDataInterface,
|
|
|
|
dxgi_adapter_GetPrivateData,
|
|
|
|
dxgi_adapter_GetParent,
|
|
|
|
/* IDXGIAdapter methods */
|
|
|
|
dxgi_adapter_EnumOutputs,
|
|
|
|
dxgi_adapter_GetDesc,
|
|
|
|
dxgi_adapter_CheckInterfaceSupport,
|
2008-11-17 12:16:04 +01:00
|
|
|
/* IWineDXGIAdapter methods */
|
|
|
|
dxgi_adapter_get_ordinal,
|
2008-10-29 09:00:26 +01:00
|
|
|
};
|
2009-09-10 16:57:19 +02:00
|
|
|
|
2009-12-04 11:50:49 +01:00
|
|
|
HRESULT dxgi_adapter_init(struct dxgi_adapter *adapter, IWineDXGIFactory *parent, UINT ordinal)
|
2009-09-10 16:57:19 +02:00
|
|
|
{
|
2009-09-11 19:01:14 +02:00
|
|
|
struct dxgi_output *output;
|
|
|
|
|
2011-06-07 10:09:02 +02:00
|
|
|
adapter->IWineDXGIAdapter_iface.lpVtbl = &dxgi_adapter_vtbl;
|
2009-09-10 16:57:19 +02:00
|
|
|
adapter->parent = parent;
|
|
|
|
adapter->refcount = 1;
|
|
|
|
adapter->ordinal = ordinal;
|
2009-09-11 19:01:14 +02:00
|
|
|
|
|
|
|
output = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*output));
|
|
|
|
if (!output)
|
|
|
|
{
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
2009-12-03 11:38:19 +01:00
|
|
|
dxgi_output_init(output, adapter);
|
2011-06-06 10:21:49 +02:00
|
|
|
adapter->output = &output->IDXGIOutput_iface;
|
2009-09-11 19:01:14 +02:00
|
|
|
|
|
|
|
return S_OK;
|
2009-09-10 16:57:19 +02:00
|
|
|
}
|