2 * Copyright 2008 Henri Verbeet for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "wine/port.h"
23 #include "dxgi_private.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(dxgi
);
27 static inline struct dxgi_adapter
*impl_from_IWineDXGIAdapter(IWineDXGIAdapter
*iface
)
29 return CONTAINING_RECORD(iface
, struct dxgi_adapter
, IWineDXGIAdapter_iface
);
32 /* IUnknown methods */
34 static HRESULT STDMETHODCALLTYPE
dxgi_adapter_QueryInterface(IWineDXGIAdapter
*iface
, REFIID riid
, void **object
)
36 TRACE("iface %p, riid %s, object %p\n", iface
, debugstr_guid(riid
), object
);
38 if (IsEqualGUID(riid
, &IID_IUnknown
)
39 || IsEqualGUID(riid
, &IID_IDXGIObject
)
40 || IsEqualGUID(riid
, &IID_IDXGIAdapter
)
41 || IsEqualGUID(riid
, &IID_IWineDXGIAdapter
))
43 IUnknown_AddRef(iface
);
48 WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid
));
54 static ULONG STDMETHODCALLTYPE
dxgi_adapter_AddRef(IWineDXGIAdapter
*iface
)
56 struct dxgi_adapter
*This
= impl_from_IWineDXGIAdapter(iface
);
57 ULONG refcount
= InterlockedIncrement(&This
->refcount
);
59 TRACE("%p increasing refcount to %u\n", This
, refcount
);
64 static ULONG STDMETHODCALLTYPE
dxgi_adapter_Release(IWineDXGIAdapter
*iface
)
66 struct dxgi_adapter
*This
= impl_from_IWineDXGIAdapter(iface
);
67 ULONG refcount
= InterlockedDecrement(&This
->refcount
);
69 TRACE("%p decreasing refcount to %u\n", This
, refcount
);
73 IDXGIOutput_Release(This
->output
);
74 HeapFree(GetProcessHeap(), 0, This
);
80 /* IDXGIObject methods */
82 static HRESULT STDMETHODCALLTYPE
dxgi_adapter_SetPrivateData(IWineDXGIAdapter
*iface
,
83 REFGUID guid
, UINT data_size
, const void *data
)
85 FIXME("iface %p, guid %s, data_size %u, data %p stub!\n", iface
, debugstr_guid(guid
), data_size
, data
);
90 static HRESULT STDMETHODCALLTYPE
dxgi_adapter_SetPrivateDataInterface(IWineDXGIAdapter
*iface
,
91 REFGUID guid
, const IUnknown
*object
)
93 FIXME("iface %p, guid %s, object %p stub!\n", iface
, debugstr_guid(guid
), object
);
98 static HRESULT STDMETHODCALLTYPE
dxgi_adapter_GetPrivateData(IWineDXGIAdapter
*iface
,
99 REFGUID guid
, UINT
*data_size
, void *data
)
101 FIXME("iface %p, guid %s, data_size %p, data %p stub!\n", iface
, debugstr_guid(guid
), data_size
, data
);
106 static HRESULT STDMETHODCALLTYPE
dxgi_adapter_GetParent(IWineDXGIAdapter
*iface
, REFIID riid
, void **parent
)
108 struct dxgi_adapter
*This
= impl_from_IWineDXGIAdapter(iface
);
110 TRACE("iface %p, riid %s, parent %p\n", iface
, debugstr_guid(riid
), parent
);
112 return IWineDXGIFactory_QueryInterface(This
->parent
, riid
, parent
);
115 /* IDXGIAdapter methods */
117 static HRESULT STDMETHODCALLTYPE
dxgi_adapter_EnumOutputs(IWineDXGIAdapter
*iface
,
118 UINT output_idx
, IDXGIOutput
**output
)
120 struct dxgi_adapter
*This
= impl_from_IWineDXGIAdapter(iface
);
122 TRACE("iface %p, output_idx %u, output %p.\n", iface
, output_idx
, output
);
127 return DXGI_ERROR_NOT_FOUND
;
130 *output
= This
->output
;
131 IDXGIOutput_AddRef(*output
);
133 TRACE("Returning output %p.\n", output
);
138 static HRESULT STDMETHODCALLTYPE
dxgi_adapter_GetDesc(IWineDXGIAdapter
*iface
, DXGI_ADAPTER_DESC
*desc
)
140 struct dxgi_adapter
*This
= impl_from_IWineDXGIAdapter(iface
);
141 WINED3DADAPTER_IDENTIFIER adapter_id
;
142 char description
[128];
143 struct wined3d
*wined3d
;
146 TRACE("iface %p, desc %p.\n", iface
, desc
);
148 if (!desc
) return E_INVALIDARG
;
150 wined3d
= IWineDXGIFactory_get_wined3d(This
->parent
);
151 adapter_id
.driver_size
= 0;
152 adapter_id
.description
= description
;
153 adapter_id
.description_size
= sizeof(description
);
154 adapter_id
.device_name_size
= 0;
156 EnterCriticalSection(&dxgi_cs
);
157 hr
= wined3d_get_adapter_identifier(wined3d
, This
->ordinal
, 0, &adapter_id
);
158 wined3d_decref(wined3d
);
159 LeaveCriticalSection(&dxgi_cs
);
163 if (!MultiByteToWideChar(CP_ACP
, 0, description
, -1, desc
->Description
, 128))
165 DWORD err
= GetLastError();
166 ERR("Failed to translate description %s (%#x).\n", debugstr_a(description
), err
);
170 desc
->VendorId
= adapter_id
.vendor_id
;
171 desc
->DeviceId
= adapter_id
.device_id
;
172 desc
->SubSysId
= adapter_id
.subsystem_id
;
173 desc
->Revision
= adapter_id
.revision
;
174 desc
->DedicatedVideoMemory
= adapter_id
.video_memory
;
175 desc
->DedicatedSystemMemory
= 0; /* FIXME */
176 desc
->SharedSystemMemory
= 0; /* FIXME */
177 memcpy(&desc
->AdapterLuid
, &adapter_id
.adapter_luid
, sizeof(desc
->AdapterLuid
));
183 static HRESULT STDMETHODCALLTYPE
dxgi_adapter_CheckInterfaceSupport(IWineDXGIAdapter
*iface
,
184 REFGUID guid
, LARGE_INTEGER
*umd_version
)
186 FIXME("iface %p, guid %s, umd_version %p stub!\n", iface
, debugstr_guid(guid
), umd_version
);
191 /* IWineDXGIAdapter methods */
193 static UINT STDMETHODCALLTYPE
dxgi_adapter_get_ordinal(IWineDXGIAdapter
*iface
)
195 struct dxgi_adapter
*This
= impl_from_IWineDXGIAdapter(iface
);
197 TRACE("iface %p, returning %u\n", iface
, This
->ordinal
);
199 return This
->ordinal
;
202 static const struct IWineDXGIAdapterVtbl dxgi_adapter_vtbl
=
204 /* IUnknown methods */
205 dxgi_adapter_QueryInterface
,
207 dxgi_adapter_Release
,
208 /* IDXGIObject methods */
209 dxgi_adapter_SetPrivateData
,
210 dxgi_adapter_SetPrivateDataInterface
,
211 dxgi_adapter_GetPrivateData
,
212 dxgi_adapter_GetParent
,
213 /* IDXGIAdapter methods */
214 dxgi_adapter_EnumOutputs
,
215 dxgi_adapter_GetDesc
,
216 dxgi_adapter_CheckInterfaceSupport
,
217 /* IWineDXGIAdapter methods */
218 dxgi_adapter_get_ordinal
,
221 HRESULT
dxgi_adapter_init(struct dxgi_adapter
*adapter
, IWineDXGIFactory
*parent
, UINT ordinal
)
223 struct dxgi_output
*output
;
225 adapter
->IWineDXGIAdapter_iface
.lpVtbl
= &dxgi_adapter_vtbl
;
226 adapter
->parent
= parent
;
227 adapter
->refcount
= 1;
228 adapter
->ordinal
= ordinal
;
230 output
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*output
));
233 return E_OUTOFMEMORY
;
235 dxgi_output_init(output
, adapter
);
236 adapter
->output
= &output
->IDXGIOutput_iface
;