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_IDXGIAdapter1
)
42 || IsEqualGUID(riid
, &IID_IWineDXGIAdapter
))
44 IUnknown_AddRef(iface
);
49 WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid
));
55 static ULONG STDMETHODCALLTYPE
dxgi_adapter_AddRef(IWineDXGIAdapter
*iface
)
57 struct dxgi_adapter
*This
= impl_from_IWineDXGIAdapter(iface
);
58 ULONG refcount
= InterlockedIncrement(&This
->refcount
);
60 TRACE("%p increasing refcount to %u\n", This
, refcount
);
65 static ULONG STDMETHODCALLTYPE
dxgi_adapter_Release(IWineDXGIAdapter
*iface
)
67 struct dxgi_adapter
*This
= impl_from_IWineDXGIAdapter(iface
);
68 ULONG refcount
= InterlockedDecrement(&This
->refcount
);
70 TRACE("%p decreasing refcount to %u\n", This
, refcount
);
74 IDXGIOutput_Release(This
->output
);
75 HeapFree(GetProcessHeap(), 0, This
);
81 /* IDXGIObject methods */
83 static HRESULT STDMETHODCALLTYPE
dxgi_adapter_SetPrivateData(IWineDXGIAdapter
*iface
,
84 REFGUID guid
, UINT data_size
, const void *data
)
86 FIXME("iface %p, guid %s, data_size %u, data %p stub!\n", iface
, debugstr_guid(guid
), data_size
, data
);
91 static HRESULT STDMETHODCALLTYPE
dxgi_adapter_SetPrivateDataInterface(IWineDXGIAdapter
*iface
,
92 REFGUID guid
, const IUnknown
*object
)
94 FIXME("iface %p, guid %s, object %p stub!\n", iface
, debugstr_guid(guid
), object
);
99 static HRESULT STDMETHODCALLTYPE
dxgi_adapter_GetPrivateData(IWineDXGIAdapter
*iface
,
100 REFGUID guid
, UINT
*data_size
, void *data
)
102 FIXME("iface %p, guid %s, data_size %p, data %p stub!\n", iface
, debugstr_guid(guid
), data_size
, data
);
107 static HRESULT STDMETHODCALLTYPE
dxgi_adapter_GetParent(IWineDXGIAdapter
*iface
, REFIID riid
, void **parent
)
109 struct dxgi_adapter
*This
= impl_from_IWineDXGIAdapter(iface
);
111 TRACE("iface %p, riid %s, parent %p\n", iface
, debugstr_guid(riid
), parent
);
113 return IWineDXGIFactory_QueryInterface(This
->parent
, riid
, parent
);
116 /* IDXGIAdapter methods */
118 static HRESULT STDMETHODCALLTYPE
dxgi_adapter_EnumOutputs(IWineDXGIAdapter
*iface
,
119 UINT output_idx
, IDXGIOutput
**output
)
121 struct dxgi_adapter
*This
= impl_from_IWineDXGIAdapter(iface
);
123 TRACE("iface %p, output_idx %u, output %p.\n", iface
, output_idx
, output
);
128 return DXGI_ERROR_NOT_FOUND
;
131 *output
= This
->output
;
132 IDXGIOutput_AddRef(*output
);
134 TRACE("Returning output %p.\n", output
);
139 static HRESULT STDMETHODCALLTYPE
dxgi_adapter_GetDesc1(IWineDXGIAdapter
*iface
, DXGI_ADAPTER_DESC1
*desc
)
141 struct dxgi_adapter
*adapter
= impl_from_IWineDXGIAdapter(iface
);
142 struct wined3d_adapter_identifier adapter_id
;
143 char description
[128];
144 struct wined3d
*wined3d
;
147 TRACE("iface %p, desc %p.\n", iface
, desc
);
152 wined3d
= IWineDXGIFactory_get_wined3d(adapter
->parent
);
153 adapter_id
.driver_size
= 0;
154 adapter_id
.description
= description
;
155 adapter_id
.description_size
= sizeof(description
);
156 adapter_id
.device_name_size
= 0;
158 EnterCriticalSection(&dxgi_cs
);
159 hr
= wined3d_get_adapter_identifier(wined3d
, adapter
->ordinal
, 0, &adapter_id
);
160 wined3d_decref(wined3d
);
161 LeaveCriticalSection(&dxgi_cs
);
166 if (!MultiByteToWideChar(CP_ACP
, 0, description
, -1, desc
->Description
, 128))
168 DWORD err
= GetLastError();
169 ERR("Failed to translate description %s (%#x).\n", debugstr_a(description
), err
);
173 desc
->VendorId
= adapter_id
.vendor_id
;
174 desc
->DeviceId
= adapter_id
.device_id
;
175 desc
->SubSysId
= adapter_id
.subsystem_id
;
176 desc
->Revision
= adapter_id
.revision
;
177 desc
->DedicatedVideoMemory
= adapter_id
.video_memory
;
178 desc
->DedicatedSystemMemory
= 0; /* FIXME */
179 desc
->SharedSystemMemory
= 0; /* FIXME */
180 memcpy(&desc
->AdapterLuid
, &adapter_id
.adapter_luid
, sizeof(desc
->AdapterLuid
));
186 static HRESULT STDMETHODCALLTYPE
dxgi_adapter_GetDesc(IWineDXGIAdapter
*iface
, DXGI_ADAPTER_DESC
*desc
)
188 DXGI_ADAPTER_DESC1 desc1
;
191 TRACE("iface %p, desc %p.\n", iface
, desc
);
196 if (FAILED(hr
= dxgi_adapter_GetDesc1(iface
, &desc1
)))
198 memcpy(desc
, &desc1
, sizeof(*desc
));
203 static HRESULT STDMETHODCALLTYPE
dxgi_adapter_CheckInterfaceSupport(IWineDXGIAdapter
*iface
,
204 REFGUID guid
, LARGE_INTEGER
*umd_version
)
206 FIXME("iface %p, guid %s, umd_version %p stub!\n", iface
, debugstr_guid(guid
), umd_version
);
211 /* IWineDXGIAdapter methods */
213 static UINT STDMETHODCALLTYPE
dxgi_adapter_get_ordinal(IWineDXGIAdapter
*iface
)
215 struct dxgi_adapter
*This
= impl_from_IWineDXGIAdapter(iface
);
217 TRACE("iface %p, returning %u\n", iface
, This
->ordinal
);
219 return This
->ordinal
;
222 static const struct IWineDXGIAdapterVtbl dxgi_adapter_vtbl
=
224 /* IUnknown methods */
225 dxgi_adapter_QueryInterface
,
227 dxgi_adapter_Release
,
228 /* IDXGIObject methods */
229 dxgi_adapter_SetPrivateData
,
230 dxgi_adapter_SetPrivateDataInterface
,
231 dxgi_adapter_GetPrivateData
,
232 dxgi_adapter_GetParent
,
233 /* IDXGIAdapter methods */
234 dxgi_adapter_EnumOutputs
,
235 dxgi_adapter_GetDesc
,
236 dxgi_adapter_CheckInterfaceSupport
,
237 /* IDXGIAdapter1 methods */
238 dxgi_adapter_GetDesc1
,
239 /* IWineDXGIAdapter methods */
240 dxgi_adapter_get_ordinal
,
243 HRESULT
dxgi_adapter_init(struct dxgi_adapter
*adapter
, IWineDXGIFactory
*parent
, UINT ordinal
)
245 struct dxgi_output
*output
;
247 adapter
->IWineDXGIAdapter_iface
.lpVtbl
= &dxgi_adapter_vtbl
;
248 adapter
->parent
= parent
;
249 adapter
->refcount
= 1;
250 adapter
->ordinal
= ordinal
;
252 output
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*output
));
255 return E_OUTOFMEMORY
;
257 dxgi_output_init(output
, adapter
);
258 adapter
->output
= &output
->IDXGIOutput_iface
;