kernel32: Properly implement EnumSystemGeoID().
[wine.git] / dlls / dxgi / adapter.c
blobd18db852f654b9f474919e55c791f9d614163192
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_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);
45 *object = iface;
46 return S_OK;
49 WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid));
51 *object = NULL;
52 return E_NOINTERFACE;
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);
62 return 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);
72 if (!refcount)
74 IDXGIOutput_Release(This->output);
75 HeapFree(GetProcessHeap(), 0, This);
78 return refcount;
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);
88 return E_NOTIMPL;
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);
96 return E_NOTIMPL;
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);
104 return E_NOTIMPL;
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);
125 if (output_idx > 0)
127 *output = NULL;
128 return DXGI_ERROR_NOT_FOUND;
131 *output = This->output;
132 IDXGIOutput_AddRef(*output);
134 TRACE("Returning output %p.\n", output);
136 return S_OK;
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;
145 HRESULT hr;
147 TRACE("iface %p, desc %p.\n", iface, desc);
149 if (!desc)
150 return E_INVALIDARG;
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);
163 if (FAILED(hr))
164 return hr;
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);
170 hr = E_FAIL;
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));
181 desc->Flags = 0;
183 return hr;
186 static HRESULT STDMETHODCALLTYPE dxgi_adapter_GetDesc(IWineDXGIAdapter *iface, DXGI_ADAPTER_DESC *desc)
188 DXGI_ADAPTER_DESC1 desc1;
189 HRESULT hr;
191 TRACE("iface %p, desc %p.\n", iface, desc);
193 if (!desc)
194 return E_INVALIDARG;
196 if (FAILED(hr = dxgi_adapter_GetDesc1(iface, &desc1)))
197 return hr;
198 memcpy(desc, &desc1, sizeof(*desc));
200 return hr;
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);
208 return E_NOTIMPL;
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,
226 dxgi_adapter_AddRef,
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));
253 if (!output)
255 return E_OUTOFMEMORY;
257 dxgi_output_init(output, adapter);
258 adapter->output = &output->IDXGIOutput_iface;
260 return S_OK;