560b027b86ed7866b12a954eab0610ce33626cfd
[reactos.git] / reactos / dll / directx / wine / dxgi / output.c
1 /*
2 * Copyright 2009 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 #include "dxgi_private.h"
20
21 static inline struct dxgi_output *impl_from_IDXGIOutput(IDXGIOutput *iface)
22 {
23 return CONTAINING_RECORD(iface, struct dxgi_output, IDXGIOutput_iface);
24 }
25
26 /* IUnknown methods */
27
28 static HRESULT STDMETHODCALLTYPE dxgi_output_QueryInterface(IDXGIOutput *iface, REFIID riid, void **object)
29 {
30 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
31
32 if (IsEqualGUID(riid, &IID_IDXGIOutput)
33 || IsEqualGUID(riid, &IID_IDXGIObject)
34 || IsEqualGUID(riid, &IID_IUnknown))
35 {
36 IUnknown_AddRef(iface);
37 *object = iface;
38 return S_OK;
39 }
40
41 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
42
43 *object = NULL;
44 return E_NOINTERFACE;
45 }
46
47 static ULONG STDMETHODCALLTYPE dxgi_output_AddRef(IDXGIOutput *iface)
48 {
49 struct dxgi_output *This = impl_from_IDXGIOutput(iface);
50 ULONG refcount = InterlockedIncrement(&This->refcount);
51
52 TRACE("%p increasing refcount to %u.\n", This, refcount);
53
54 return refcount;
55 }
56
57 static ULONG STDMETHODCALLTYPE dxgi_output_Release(IDXGIOutput *iface)
58 {
59 struct dxgi_output *This = impl_from_IDXGIOutput(iface);
60 ULONG refcount = InterlockedDecrement(&This->refcount);
61
62 TRACE("%p decreasing refcount to %u.\n", This, refcount);
63
64 if (!refcount)
65 {
66 wined3d_private_store_cleanup(&This->private_store);
67 HeapFree(GetProcessHeap(), 0, This);
68 }
69
70 return refcount;
71 }
72
73 /* IDXGIObject methods */
74
75 static HRESULT STDMETHODCALLTYPE dxgi_output_SetPrivateData(IDXGIOutput *iface,
76 REFGUID guid, UINT data_size, const void *data)
77 {
78 struct dxgi_output *output = impl_from_IDXGIOutput(iface);
79
80 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
81
82 return dxgi_set_private_data(&output->private_store, guid, data_size, data);
83 }
84
85 static HRESULT STDMETHODCALLTYPE dxgi_output_SetPrivateDataInterface(IDXGIOutput *iface,
86 REFGUID guid, const IUnknown *object)
87 {
88 struct dxgi_output *output = impl_from_IDXGIOutput(iface);
89
90 TRACE("iface %p, guid %s, object %p.\n", iface, debugstr_guid(guid), object);
91
92 return dxgi_set_private_data_interface(&output->private_store, guid, object);
93 }
94
95 static HRESULT STDMETHODCALLTYPE dxgi_output_GetPrivateData(IDXGIOutput *iface,
96 REFGUID guid, UINT *data_size, void *data)
97 {
98 struct dxgi_output *output = impl_from_IDXGIOutput(iface);
99
100 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
101
102 return dxgi_get_private_data(&output->private_store, guid, data_size, data);
103 }
104
105 static HRESULT STDMETHODCALLTYPE dxgi_output_GetParent(IDXGIOutput *iface,
106 REFIID riid, void **parent)
107 {
108 struct dxgi_output *This = impl_from_IDXGIOutput(iface);
109
110 TRACE("iface %p, riid %s, parent %p.\n", iface, debugstr_guid(riid), parent);
111
112 return IDXGIAdapter_QueryInterface((IDXGIAdapter *)This->adapter, riid, parent);
113 }
114
115 /* IDXGIOutput methods */
116
117 static HRESULT STDMETHODCALLTYPE dxgi_output_GetDesc(IDXGIOutput *iface, DXGI_OUTPUT_DESC *desc)
118 {
119 struct dxgi_output *This = impl_from_IDXGIOutput(iface);
120 struct wined3d *wined3d;
121 MONITORINFOEXW monitor_info;
122
123 FIXME("iface %p, desc %p semi-stub!\n", iface, desc);
124
125 if (!desc)
126 return DXGI_ERROR_INVALID_CALL;
127
128 wined3d = This->adapter->parent->wined3d;
129
130 EnterCriticalSection(&dxgi_cs);
131 desc->Monitor = wined3d_get_adapter_monitor(wined3d, This->adapter->ordinal);
132 LeaveCriticalSection(&dxgi_cs);
133
134 if (!desc->Monitor)
135 return DXGI_ERROR_INVALID_CALL;
136
137 monitor_info.cbSize = sizeof(monitor_info);
138 if (!GetMonitorInfoW(desc->Monitor, (MONITORINFO *)&monitor_info))
139 return DXGI_ERROR_INVALID_CALL;
140
141 memcpy(&desc->DeviceName, &monitor_info.szDevice, sizeof(desc->DeviceName));
142 memcpy(&desc->DesktopCoordinates, &monitor_info.rcMonitor, sizeof(RECT));
143 desc->AttachedToDesktop = TRUE;
144 desc->Rotation = DXGI_MODE_ROTATION_IDENTITY;
145
146 return S_OK;
147 }
148
149 static HRESULT STDMETHODCALLTYPE dxgi_output_GetDisplayModeList(IDXGIOutput *iface,
150 DXGI_FORMAT format, UINT flags, UINT *mode_count, DXGI_MODE_DESC *desc)
151 {
152 struct dxgi_output *This = impl_from_IDXGIOutput(iface);
153 enum wined3d_format_id wined3d_format;
154 struct wined3d *wined3d;
155 UINT i;
156 UINT max_count;
157
158 FIXME("iface %p, format %s, flags %#x, mode_count %p, desc %p partial stub!\n",
159 iface, debug_dxgi_format(format), flags, mode_count, desc);
160
161 if (!mode_count)
162 return DXGI_ERROR_INVALID_CALL;
163
164 if (format == DXGI_FORMAT_UNKNOWN)
165 {
166 *mode_count = 0;
167 return S_OK;
168 }
169
170 wined3d = This->adapter->parent->wined3d;
171 wined3d_format = wined3dformat_from_dxgi_format(format);
172
173 EnterCriticalSection(&dxgi_cs);
174 max_count = wined3d_get_adapter_mode_count(wined3d, This->adapter->ordinal,
175 wined3d_format, WINED3D_SCANLINE_ORDERING_UNKNOWN);
176
177 if (!desc)
178 {
179 LeaveCriticalSection(&dxgi_cs);
180 *mode_count = max_count;
181 return S_OK;
182 }
183
184 if (max_count > *mode_count)
185 {
186 LeaveCriticalSection(&dxgi_cs);
187 return DXGI_ERROR_MORE_DATA;
188 }
189
190 *mode_count = max_count;
191
192 for (i = 0; i < *mode_count; ++i)
193 {
194 struct wined3d_display_mode mode;
195 HRESULT hr;
196
197 hr = wined3d_enum_adapter_modes(wined3d, This->adapter->ordinal, wined3d_format,
198 WINED3D_SCANLINE_ORDERING_UNKNOWN, i, &mode);
199 if (FAILED(hr))
200 {
201 WARN("EnumAdapterModes failed, hr %#x.\n", hr);
202 LeaveCriticalSection(&dxgi_cs);
203 return hr;
204 }
205
206 desc[i].Width = mode.width;
207 desc[i].Height = mode.height;
208 desc[i].RefreshRate.Numerator = mode.refresh_rate;
209 desc[i].RefreshRate.Denominator = 1;
210 desc[i].Format = format;
211 desc[i].ScanlineOrdering = mode.scanline_ordering;
212 desc[i].Scaling = DXGI_MODE_SCALING_UNSPECIFIED; /* FIXME */
213 }
214 LeaveCriticalSection(&dxgi_cs);
215
216 return S_OK;
217 }
218
219 static HRESULT STDMETHODCALLTYPE dxgi_output_FindClosestMatchingMode(IDXGIOutput *iface,
220 const DXGI_MODE_DESC *mode, DXGI_MODE_DESC *closest_match, IUnknown *device)
221 {
222 FIXME("iface %p, mode %p, closest_match %p, device %p stub!\n", iface, mode, closest_match, device);
223
224 return E_NOTIMPL;
225 }
226
227 static HRESULT STDMETHODCALLTYPE dxgi_output_WaitForVBlank(IDXGIOutput *iface)
228 {
229 FIXME("iface %p stub!\n", iface);
230
231 return E_NOTIMPL;
232 }
233
234 static HRESULT STDMETHODCALLTYPE dxgi_output_TakeOwnership(IDXGIOutput *iface, IUnknown *device, BOOL exclusive)
235 {
236 FIXME("iface %p, device %p, exclusive %d stub!\n", iface, device, exclusive);
237
238 return E_NOTIMPL;
239 }
240
241 static void STDMETHODCALLTYPE dxgi_output_ReleaseOwnership(IDXGIOutput *iface)
242 {
243 FIXME("iface %p stub!\n", iface);
244 }
245
246 static HRESULT STDMETHODCALLTYPE dxgi_output_GetGammaControlCapabilities(IDXGIOutput *iface,
247 DXGI_GAMMA_CONTROL_CAPABILITIES *gamma_caps)
248 {
249 FIXME("iface %p, gamma_caps %p stub!\n", iface, gamma_caps);
250
251 return E_NOTIMPL;
252 }
253
254 static HRESULT STDMETHODCALLTYPE dxgi_output_SetGammaControl(IDXGIOutput *iface,
255 const DXGI_GAMMA_CONTROL *gamma_control)
256 {
257 FIXME("iface %p, gamma_control %p stub!\n", iface, gamma_control);
258
259 return E_NOTIMPL;
260 }
261
262 static HRESULT STDMETHODCALLTYPE dxgi_output_GetGammaControl(IDXGIOutput *iface, DXGI_GAMMA_CONTROL *gamma_control)
263 {
264 FIXME("iface %p, gamma_control %p stub!\n", iface, gamma_control);
265
266 return E_NOTIMPL;
267 }
268
269 static HRESULT STDMETHODCALLTYPE dxgi_output_SetDisplaySurface(IDXGIOutput *iface, IDXGISurface *surface)
270 {
271 FIXME("iface %p, surface %p stub!\n", iface, surface);
272
273 return E_NOTIMPL;
274 }
275
276 static HRESULT STDMETHODCALLTYPE dxgi_output_GetDisplaySurfaceData(IDXGIOutput *iface, IDXGISurface *surface)
277 {
278 FIXME("iface %p, surface %p stub!\n", iface, surface);
279
280 return E_NOTIMPL;
281 }
282
283 static HRESULT STDMETHODCALLTYPE dxgi_output_GetFrameStatistics(IDXGIOutput *iface, DXGI_FRAME_STATISTICS *stats)
284 {
285 FIXME("iface %p, stats %p stub!\n", iface, stats);
286
287 return E_NOTIMPL;
288 }
289
290 static const struct IDXGIOutputVtbl dxgi_output_vtbl =
291 {
292 dxgi_output_QueryInterface,
293 dxgi_output_AddRef,
294 dxgi_output_Release,
295 /* IDXGIObject methods */
296 dxgi_output_SetPrivateData,
297 dxgi_output_SetPrivateDataInterface,
298 dxgi_output_GetPrivateData,
299 dxgi_output_GetParent,
300 /* IDXGIOutput methods */
301 dxgi_output_GetDesc,
302 dxgi_output_GetDisplayModeList,
303 dxgi_output_FindClosestMatchingMode,
304 dxgi_output_WaitForVBlank,
305 dxgi_output_TakeOwnership,
306 dxgi_output_ReleaseOwnership,
307 dxgi_output_GetGammaControlCapabilities,
308 dxgi_output_SetGammaControl,
309 dxgi_output_GetGammaControl,
310 dxgi_output_SetDisplaySurface,
311 dxgi_output_GetDisplaySurfaceData,
312 dxgi_output_GetFrameStatistics,
313 };
314
315 void dxgi_output_init(struct dxgi_output *output, struct dxgi_adapter *adapter)
316 {
317 output->IDXGIOutput_iface.lpVtbl = &dxgi_output_vtbl;
318 output->refcount = 1;
319 wined3d_private_store_init(&output->private_store);
320 output->adapter = adapter;
321 }