msvcirt: Implement stdiostream constructors.
[wine.git] / dlls / dxgi / adapter.c
blob7564d37d32b74a88d26528c73f4b4e0dbca172b2
1 /*
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
20 #include "config.h"
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);
42 *out = iface;
43 return S_OK;
46 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid));
48 *out = NULL;
49 return E_NOINTERFACE;
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);
59 return 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);
69 if (!refcount)
71 wined3d_private_store_cleanup(&adapter->private_store);
72 IDXGIFactory1_Release(&adapter->factory->IDXGIFactory1_iface);
73 HeapFree(GetProcessHeap(), 0, adapter);
76 return refcount;
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->factory->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);
122 struct dxgi_output *output_object;
123 HRESULT hr;
125 TRACE("iface %p, output_idx %u, output %p.\n", iface, output_idx, output);
127 if (output_idx > 0)
129 *output = NULL;
130 return DXGI_ERROR_NOT_FOUND;
133 if (FAILED(hr = dxgi_output_create(adapter, &output_object)))
135 *output = NULL;
136 return hr;
139 *output = &output_object->IDXGIOutput_iface;
141 TRACE("Returning output %p.\n", *output);
143 return S_OK;
146 static HRESULT STDMETHODCALLTYPE dxgi_adapter_GetDesc1(IDXGIAdapter1 *iface, DXGI_ADAPTER_DESC1 *desc)
148 struct dxgi_adapter *adapter = impl_from_IDXGIAdapter1(iface);
149 struct wined3d_adapter_identifier adapter_id;
150 char description[128];
151 HRESULT hr;
153 TRACE("iface %p, desc %p.\n", iface, desc);
155 if (!desc)
156 return E_INVALIDARG;
158 adapter_id.driver_size = 0;
159 adapter_id.description = description;
160 adapter_id.description_size = sizeof(description);
161 adapter_id.device_name_size = 0;
163 wined3d_mutex_lock();
164 hr = wined3d_get_adapter_identifier(adapter->factory->wined3d, adapter->ordinal, 0, &adapter_id);
165 wined3d_mutex_unlock();
167 if (FAILED(hr))
168 return hr;
170 if (!MultiByteToWideChar(CP_ACP, 0, description, -1, desc->Description, 128))
172 DWORD err = GetLastError();
173 ERR("Failed to translate description %s (%#x).\n", debugstr_a(description), err);
174 hr = E_FAIL;
177 desc->VendorId = adapter_id.vendor_id;
178 desc->DeviceId = adapter_id.device_id;
179 desc->SubSysId = adapter_id.subsystem_id;
180 desc->Revision = adapter_id.revision;
181 desc->DedicatedVideoMemory = adapter_id.video_memory;
182 desc->DedicatedSystemMemory = 0; /* FIXME */
183 desc->SharedSystemMemory = 0; /* FIXME */
184 memcpy(&desc->AdapterLuid, &adapter_id.adapter_luid, sizeof(desc->AdapterLuid));
185 desc->Flags = 0;
187 return hr;
190 static HRESULT STDMETHODCALLTYPE dxgi_adapter_GetDesc(IDXGIAdapter1 *iface, DXGI_ADAPTER_DESC *desc)
192 DXGI_ADAPTER_DESC1 desc1;
193 HRESULT hr;
195 TRACE("iface %p, desc %p.\n", iface, desc);
197 if (!desc)
198 return E_INVALIDARG;
200 if (FAILED(hr = dxgi_adapter_GetDesc1(iface, &desc1)))
201 return hr;
202 memcpy(desc, &desc1, sizeof(*desc));
204 return hr;
207 static HRESULT STDMETHODCALLTYPE dxgi_adapter_CheckInterfaceSupport(IDXGIAdapter1 *iface,
208 REFGUID guid, LARGE_INTEGER *umd_version)
210 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_10_0;
211 struct dxgi_adapter *adapter = impl_from_IDXGIAdapter1(iface);
212 struct wined3d_adapter_identifier adapter_id;
213 HRESULT hr;
215 TRACE("iface %p, guid %s, umd_version %p.\n", iface, debugstr_guid(guid), umd_version);
217 /* This method works only for D3D10 interfaces. */
218 if (!(IsEqualGUID(guid, &IID_ID3D10Device)
219 || IsEqualGUID(guid, &IID_ID3D10Device1)))
221 WARN("Returning DXGI_ERROR_UNSUPPORTED for %s.\n", debugstr_guid(guid));
222 return DXGI_ERROR_UNSUPPORTED;
225 if (!dxgi_check_feature_level_support(adapter->factory, adapter, &feature_level, 1))
226 return DXGI_ERROR_UNSUPPORTED;
228 if (umd_version)
230 adapter_id.driver_size = 0;
231 adapter_id.description_size = 0;
232 adapter_id.device_name_size = 0;
234 wined3d_mutex_lock();
235 hr = wined3d_get_adapter_identifier(adapter->factory->wined3d, adapter->ordinal, 0, &adapter_id);
236 wined3d_mutex_unlock();
237 if (FAILED(hr))
238 return hr;
240 *umd_version = adapter_id.driver_version;
243 return S_OK;
246 static const struct IDXGIAdapter1Vtbl dxgi_adapter_vtbl =
248 dxgi_adapter_QueryInterface,
249 dxgi_adapter_AddRef,
250 dxgi_adapter_Release,
251 dxgi_adapter_SetPrivateData,
252 dxgi_adapter_SetPrivateDataInterface,
253 dxgi_adapter_GetPrivateData,
254 dxgi_adapter_GetParent,
255 dxgi_adapter_EnumOutputs,
256 dxgi_adapter_GetDesc,
257 dxgi_adapter_CheckInterfaceSupport,
258 dxgi_adapter_GetDesc1,
261 struct dxgi_adapter *unsafe_impl_from_IDXGIAdapter1(IDXGIAdapter1 *iface)
263 if (!iface)
264 return NULL;
265 assert(iface->lpVtbl == &dxgi_adapter_vtbl);
266 return CONTAINING_RECORD(iface, struct dxgi_adapter, IDXGIAdapter1_iface);
269 static void dxgi_adapter_init(struct dxgi_adapter *adapter, struct dxgi_factory *factory, UINT ordinal)
271 adapter->IDXGIAdapter1_iface.lpVtbl = &dxgi_adapter_vtbl;
272 adapter->refcount = 1;
273 wined3d_private_store_init(&adapter->private_store);
274 adapter->ordinal = ordinal;
275 adapter->factory = factory;
276 IDXGIFactory1_AddRef(&adapter->factory->IDXGIFactory1_iface);
279 HRESULT dxgi_adapter_create(struct dxgi_factory *factory, UINT ordinal, struct dxgi_adapter **adapter)
281 if (!(*adapter = HeapAlloc(GetProcessHeap(), 0, sizeof(**adapter))))
282 return E_OUTOFMEMORY;
284 dxgi_adapter_init(*adapter, factory, ordinal);
285 return S_OK;