regedit: Fix Dutch translation.
[wine] / dlls / dxgi / adapter.c
1 /*
2  * Copyright 2008 Henri Verbeet for CodeWeavers
3  *
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.
8  *
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.
13  *
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
17  *
18  */
19
20 #include "config.h"
21 #include "wine/port.h"
22
23 #include "dxgi_private.h"
24
25 WINE_DEFAULT_DEBUG_CHANNEL(dxgi);
26
27 /* IUnknown methods */
28
29 static HRESULT STDMETHODCALLTYPE dxgi_adapter_QueryInterface(IWineDXGIAdapter *iface, REFIID riid, void **object)
30 {
31     TRACE("iface %p, riid %s, object %p\n", iface, debugstr_guid(riid), object);
32
33     if (IsEqualGUID(riid, &IID_IUnknown)
34             || IsEqualGUID(riid, &IID_IDXGIObject)
35             || IsEqualGUID(riid, &IID_IDXGIAdapter)
36             || IsEqualGUID(riid, &IID_IWineDXGIAdapter))
37     {
38         IUnknown_AddRef(iface);
39         *object = iface;
40         return S_OK;
41     }
42
43     WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid));
44
45     *object = NULL;
46     return E_NOINTERFACE;
47 }
48
49 static ULONG STDMETHODCALLTYPE dxgi_adapter_AddRef(IWineDXGIAdapter *iface)
50 {
51     struct dxgi_adapter *This = (struct dxgi_adapter *)iface;
52     ULONG refcount = InterlockedIncrement(&This->refcount);
53
54     TRACE("%p increasing refcount to %u\n", This, refcount);
55
56     return refcount;
57 }
58
59 static ULONG STDMETHODCALLTYPE dxgi_adapter_Release(IWineDXGIAdapter *iface)
60 {
61     struct dxgi_adapter *This = (struct dxgi_adapter *)iface;
62     ULONG refcount = InterlockedDecrement(&This->refcount);
63
64     TRACE("%p decreasing refcount to %u\n", This, refcount);
65
66     if (!refcount)
67     {
68         IDXGIOutput_Release(This->output);
69         HeapFree(GetProcessHeap(), 0, This);
70     }
71
72     return refcount;
73 }
74
75 /* IDXGIObject methods */
76
77 static HRESULT STDMETHODCALLTYPE dxgi_adapter_SetPrivateData(IWineDXGIAdapter *iface,
78         REFGUID guid, UINT data_size, const void *data)
79 {
80     FIXME("iface %p, guid %s, data_size %u, data %p stub!\n", iface, debugstr_guid(guid), data_size, data);
81
82     return E_NOTIMPL;
83 }
84
85 static HRESULT STDMETHODCALLTYPE dxgi_adapter_SetPrivateDataInterface(IWineDXGIAdapter *iface,
86         REFGUID guid, const IUnknown *object)
87 {
88     FIXME("iface %p, guid %s, object %p stub!\n", iface, debugstr_guid(guid), object);
89
90     return E_NOTIMPL;
91 }
92
93 static HRESULT STDMETHODCALLTYPE dxgi_adapter_GetPrivateData(IWineDXGIAdapter *iface,
94         REFGUID guid, UINT *data_size, void *data)
95 {
96     FIXME("iface %p, guid %s, data_size %p, data %p stub!\n", iface, debugstr_guid(guid), data_size, data);
97
98     return E_NOTIMPL;
99 }
100
101 static HRESULT STDMETHODCALLTYPE dxgi_adapter_GetParent(IWineDXGIAdapter *iface, REFIID riid, void **parent)
102 {
103     struct dxgi_adapter *This = (struct dxgi_adapter *)iface;
104
105     TRACE("iface %p, riid %s, parent %p\n", iface, debugstr_guid(riid), parent);
106
107     return IWineDXGIFactory_QueryInterface(This->parent, riid, parent);
108 }
109
110 /* IDXGIAdapter methods */
111
112 static HRESULT STDMETHODCALLTYPE dxgi_adapter_EnumOutputs(IWineDXGIAdapter *iface,
113         UINT output_idx, IDXGIOutput **output)
114 {
115     struct dxgi_adapter *This = (struct dxgi_adapter *)iface;
116
117     TRACE("iface %p, output_idx %u, output %p.\n", iface, output_idx, output);
118
119     if (output_idx > 0)
120     {
121         *output = NULL;
122         return DXGI_ERROR_NOT_FOUND;
123     }
124
125     *output = This->output;
126     IDXGIOutput_AddRef(*output);
127
128     TRACE("Returning output %p.\n", output);
129
130     return S_OK;
131 }
132
133 static HRESULT STDMETHODCALLTYPE dxgi_adapter_GetDesc(IWineDXGIAdapter *iface, DXGI_ADAPTER_DESC *desc)
134 {
135     struct dxgi_adapter *This = (struct dxgi_adapter *)iface;
136     WINED3DADAPTER_IDENTIFIER adapter_id;
137     char description[128];
138     IWineD3D *wined3d;
139     HRESULT hr;
140
141     TRACE("iface %p, desc %p.\n", iface, desc);
142
143     if (!desc) return E_INVALIDARG;
144
145     wined3d = IWineDXGIFactory_get_wined3d(This->parent);
146     adapter_id.driver_size = 0;
147     adapter_id.description = description;
148     adapter_id.description_size = sizeof(description);
149     adapter_id.device_name_size = 0;
150
151     EnterCriticalSection(&dxgi_cs);
152     hr = IWineD3D_GetAdapterIdentifier(wined3d, This->ordinal, 0, &adapter_id);
153     IWineD3D_Release(wined3d);
154     LeaveCriticalSection(&dxgi_cs);
155
156     if (SUCCEEDED(hr))
157     {
158         if (!MultiByteToWideChar(CP_ACP, 0, description, -1, desc->Description, 128))
159         {
160             DWORD err = GetLastError();
161             ERR("Failed to translate description %s (%#x).\n", debugstr_a(description), err);
162             hr = E_FAIL;
163         }
164
165         desc->VendorId = adapter_id.vendor_id;
166         desc->DeviceId = adapter_id.device_id;
167         desc->SubSysId = adapter_id.subsystem_id;
168         desc->Revision = adapter_id.revision;
169         desc->DedicatedVideoMemory = adapter_id.video_memory;
170         desc->DedicatedSystemMemory = 0; /* FIXME */
171         desc->SharedSystemMemory = 0; /* FIXME */
172         memcpy(&desc->AdapterLuid, &adapter_id.adapter_luid, sizeof(desc->AdapterLuid));
173     }
174
175     return hr;
176 }
177
178 static HRESULT STDMETHODCALLTYPE dxgi_adapter_CheckInterfaceSupport(IWineDXGIAdapter *iface,
179         REFGUID guid, LARGE_INTEGER *umd_version)
180 {
181     FIXME("iface %p, guid %s, umd_version %p stub!\n", iface, debugstr_guid(guid), umd_version);
182
183     return E_NOTIMPL;
184 }
185
186 /* IWineDXGIAdapter methods */
187
188 static UINT STDMETHODCALLTYPE dxgi_adapter_get_ordinal(IWineDXGIAdapter *iface)
189 {
190     struct dxgi_adapter *This = (struct dxgi_adapter *)iface;
191
192     TRACE("iface %p, returning %u\n", iface, This->ordinal);
193
194     return This->ordinal;
195 }
196
197 static const struct IWineDXGIAdapterVtbl dxgi_adapter_vtbl =
198 {
199     /* IUnknown methods */
200     dxgi_adapter_QueryInterface,
201     dxgi_adapter_AddRef,
202     dxgi_adapter_Release,
203     /* IDXGIObject methods */
204     dxgi_adapter_SetPrivateData,
205     dxgi_adapter_SetPrivateDataInterface,
206     dxgi_adapter_GetPrivateData,
207     dxgi_adapter_GetParent,
208     /* IDXGIAdapter methods */
209     dxgi_adapter_EnumOutputs,
210     dxgi_adapter_GetDesc,
211     dxgi_adapter_CheckInterfaceSupport,
212     /* IWineDXGIAdapter methods */
213     dxgi_adapter_get_ordinal,
214 };
215
216 HRESULT dxgi_adapter_init(struct dxgi_adapter *adapter, IWineDXGIFactory *parent, UINT ordinal)
217 {
218     struct dxgi_output *output;
219
220     adapter->vtbl = &dxgi_adapter_vtbl;
221     adapter->parent = parent;
222     adapter->refcount = 1;
223     adapter->ordinal = ordinal;
224
225     output = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*output));
226     if (!output)
227     {
228         return E_OUTOFMEMORY;
229     }
230     dxgi_output_init(output, adapter);
231     adapter->output = (IDXGIOutput *)output;
232
233     return S_OK;
234 }