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_IDXGIAdapter1(IDXGIAdapter1
*iface
)
29 return CONTAINING_RECORD(iface
, struct dxgi_adapter
, IDXGIAdapter1_iface
);
32 static HRESULT STDMETHODCALLTYPE
dxgi_adapter_QueryInterface(IDXGIAdapter1
*iface
, REFIID iid
, void **out
)
34 TRACE("iface %p, iid %s, out %p.\n", iface
, debugstr_guid(iid
), out
);
36 if (IsEqualGUID(iid
, &IID_IDXGIAdapter1
)
37 || IsEqualGUID(iid
, &IID_IDXGIAdapter
)
38 || IsEqualGUID(iid
, &IID_IDXGIObject
)
39 || IsEqualGUID(iid
, &IID_IUnknown
))
41 IUnknown_AddRef(iface
);
46 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid
));
52 static ULONG STDMETHODCALLTYPE
dxgi_adapter_AddRef(IDXGIAdapter1
*iface
)
54 struct dxgi_adapter
*adapter
= impl_from_IDXGIAdapter1(iface
);
55 ULONG refcount
= InterlockedIncrement(&adapter
->refcount
);
57 TRACE("%p increasing refcount to %u.\n", iface
, refcount
);
62 static ULONG STDMETHODCALLTYPE
dxgi_adapter_Release(IDXGIAdapter1
*iface
)
64 struct dxgi_adapter
*adapter
= impl_from_IDXGIAdapter1(iface
);
65 ULONG refcount
= InterlockedDecrement(&adapter
->refcount
);
67 TRACE("%p decreasing refcount to %u.\n", iface
, refcount
);
71 IDXGIOutput_Release(adapter
->output
);
72 wined3d_private_store_cleanup(&adapter
->private_store
);
73 HeapFree(GetProcessHeap(), 0, adapter
);
79 static HRESULT STDMETHODCALLTYPE
dxgi_adapter_SetPrivateData(IDXGIAdapter1
*iface
,
80 REFGUID guid
, UINT data_size
, const void *data
)
82 struct dxgi_adapter
*adapter
= impl_from_IDXGIAdapter1(iface
);
84 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface
, debugstr_guid(guid
), data_size
, data
);
86 return dxgi_set_private_data(&adapter
->private_store
, guid
, data_size
, data
);
89 static HRESULT STDMETHODCALLTYPE
dxgi_adapter_SetPrivateDataInterface(IDXGIAdapter1
*iface
,
90 REFGUID guid
, const IUnknown
*object
)
92 struct dxgi_adapter
*adapter
= impl_from_IDXGIAdapter1(iface
);
94 TRACE("iface %p, guid %s, object %p.\n", iface
, debugstr_guid(guid
), object
);
96 return dxgi_set_private_data_interface(&adapter
->private_store
, guid
, object
);
99 static HRESULT STDMETHODCALLTYPE
dxgi_adapter_GetPrivateData(IDXGIAdapter1
*iface
,
100 REFGUID guid
, UINT
*data_size
, void *data
)
102 struct dxgi_adapter
*adapter
= impl_from_IDXGIAdapter1(iface
);
104 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface
, debugstr_guid(guid
), data_size
, data
);
106 return dxgi_get_private_data(&adapter
->private_store
, guid
, data_size
, data
);
109 static HRESULT STDMETHODCALLTYPE
dxgi_adapter_GetParent(IDXGIAdapter1
*iface
, REFIID iid
, void **parent
)
111 struct dxgi_adapter
*adapter
= impl_from_IDXGIAdapter1(iface
);
113 TRACE("iface %p, iid %s, parent %p\n", iface
, debugstr_guid(iid
), parent
);
115 return IDXGIFactory1_QueryInterface(&adapter
->parent
->IDXGIFactory1_iface
, iid
, parent
);
118 static HRESULT STDMETHODCALLTYPE
dxgi_adapter_EnumOutputs(IDXGIAdapter1
*iface
,
119 UINT output_idx
, IDXGIOutput
**output
)
121 struct dxgi_adapter
*adapter
= impl_from_IDXGIAdapter1(iface
);
123 TRACE("iface %p, output_idx %u, output %p.\n", iface
, output_idx
, output
);
128 return DXGI_ERROR_NOT_FOUND
;
131 *output
= adapter
->output
;
132 IDXGIOutput_AddRef(*output
);
134 TRACE("Returning output %p.\n", output
);
139 static HRESULT STDMETHODCALLTYPE
dxgi_adapter_GetDesc1(IDXGIAdapter1
*iface
, DXGI_ADAPTER_DESC1
*desc
)
141 struct dxgi_adapter
*adapter
= impl_from_IDXGIAdapter1(iface
);
142 struct wined3d_adapter_identifier adapter_id
;
143 char description
[128];
146 TRACE("iface %p, desc %p.\n", iface
, desc
);
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(adapter
->parent
->wined3d
, adapter
->ordinal
, 0, &adapter_id
);
158 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_GetDesc(IDXGIAdapter1
*iface
, DXGI_ADAPTER_DESC
*desc
)
185 DXGI_ADAPTER_DESC1 desc1
;
188 TRACE("iface %p, desc %p.\n", iface
, desc
);
193 if (FAILED(hr
= dxgi_adapter_GetDesc1(iface
, &desc1
)))
195 memcpy(desc
, &desc1
, sizeof(*desc
));
200 static HRESULT STDMETHODCALLTYPE
dxgi_adapter_CheckInterfaceSupport(IDXGIAdapter1
*iface
,
201 REFGUID guid
, LARGE_INTEGER
*umd_version
)
203 FIXME("iface %p, guid %s, umd_version %p stub!\n", iface
, debugstr_guid(guid
), umd_version
);
208 static const struct IDXGIAdapter1Vtbl dxgi_adapter_vtbl
=
210 dxgi_adapter_QueryInterface
,
212 dxgi_adapter_Release
,
213 dxgi_adapter_SetPrivateData
,
214 dxgi_adapter_SetPrivateDataInterface
,
215 dxgi_adapter_GetPrivateData
,
216 dxgi_adapter_GetParent
,
217 dxgi_adapter_EnumOutputs
,
218 dxgi_adapter_GetDesc
,
219 dxgi_adapter_CheckInterfaceSupport
,
220 dxgi_adapter_GetDesc1
,
223 struct dxgi_adapter
*unsafe_impl_from_IDXGIAdapter1(IDXGIAdapter1
*iface
)
227 assert(iface
->lpVtbl
== &dxgi_adapter_vtbl
);
228 return CONTAINING_RECORD(iface
, struct dxgi_adapter
, IDXGIAdapter1_iface
);
231 HRESULT
dxgi_adapter_init(struct dxgi_adapter
*adapter
, struct dxgi_factory
*parent
, UINT ordinal
)
233 struct dxgi_output
*output
;
235 adapter
->IDXGIAdapter1_iface
.lpVtbl
= &dxgi_adapter_vtbl
;
236 adapter
->parent
= parent
;
237 adapter
->refcount
= 1;
238 wined3d_private_store_init(&adapter
->private_store
);
239 adapter
->ordinal
= ordinal
;
241 if (!(output
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*output
))))
243 wined3d_private_store_cleanup(&adapter
->private_store
);
244 return E_OUTOFMEMORY
;
246 dxgi_output_init(output
, adapter
);
247 adapter
->output
= &output
->IDXGIOutput_iface
;