1a9f9e4fc1990cb527eb6444554151f135dd6f81
[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 HeapFree(GetProcessHeap(), 0, This);
67 }
68
69 return refcount;
70 }
71
72 /* IDXGIObject methods */
73
74 static HRESULT STDMETHODCALLTYPE dxgi_output_SetPrivateData(IDXGIOutput *iface,
75 REFGUID guid, UINT data_size, const void *data)
76 {
77 FIXME("iface %p, guid %s, data_size %u, data %p stub!\n", iface, debugstr_guid(guid), data_size, data);
78
79 return E_NOTIMPL;
80 }
81
82 static HRESULT STDMETHODCALLTYPE dxgi_output_SetPrivateDataInterface(IDXGIOutput *iface,
83 REFGUID guid, const IUnknown *object)
84 {
85 FIXME("iface %p, guid %s, object %p stub!\n", iface, debugstr_guid(guid), object);
86
87 return E_NOTIMPL;
88 }
89
90 static HRESULT STDMETHODCALLTYPE dxgi_output_GetPrivateData(IDXGIOutput *iface,
91 REFGUID guid, UINT *data_size, void *data)
92 {
93 FIXME("iface %p, guid %s, data_size %p, data %p stub!\n", iface, debugstr_guid(guid), data_size, data);
94
95 return E_NOTIMPL;
96 }
97
98 static HRESULT STDMETHODCALLTYPE dxgi_output_GetParent(IDXGIOutput *iface,
99 REFIID riid, void **parent)
100 {
101 struct dxgi_output *This = impl_from_IDXGIOutput(iface);
102
103 TRACE("iface %p, riid %s, parent %p.\n", iface, debugstr_guid(riid), parent);
104
105 return IDXGIAdapter_QueryInterface((IDXGIAdapter *)This->adapter, riid, parent);
106 }
107
108 /* IDXGIOutput methods */
109
110 static HRESULT STDMETHODCALLTYPE dxgi_output_GetDesc(IDXGIOutput *iface, DXGI_OUTPUT_DESC *desc)
111 {
112 FIXME("iface %p, desc %p stub!\n", iface, desc);
113
114 return E_NOTIMPL;
115 }
116
117 static HRESULT STDMETHODCALLTYPE dxgi_output_GetDisplayModeList(IDXGIOutput *iface,
118 DXGI_FORMAT format, UINT flags, UINT *mode_count, DXGI_MODE_DESC *desc)
119 {
120 struct dxgi_output *This = impl_from_IDXGIOutput(iface);
121 enum wined3d_format_id wined3d_format;
122 struct wined3d *wined3d;
123 UINT i;
124 UINT max_count;
125
126 FIXME("iface %p, format %s, flags %#x, mode_count %p, desc %p partial stub!\n",
127 iface, debug_dxgi_format(format), flags, mode_count, desc);
128
129 if (!mode_count)
130 {
131 return S_OK;
132 }
133
134 if (format == DXGI_FORMAT_UNKNOWN)
135 {
136 *mode_count = 0;
137 return S_OK;
138 }
139
140 wined3d = IWineDXGIFactory_get_wined3d(This->adapter->parent);
141 wined3d_format = wined3dformat_from_dxgi_format(format);
142
143 EnterCriticalSection(&dxgi_cs);
144 max_count = wined3d_get_adapter_mode_count(wined3d, This->adapter->ordinal,
145 wined3d_format, WINED3D_SCANLINE_ORDERING_UNKNOWN);
146
147 if (!desc)
148 {
149 wined3d_decref(wined3d);
150 LeaveCriticalSection(&dxgi_cs);
151 *mode_count = max_count;
152 return S_OK;
153 }
154
155 *mode_count = min(*mode_count,max_count);
156
157 for (i = 0; i < *mode_count; ++i)
158 {
159 struct wined3d_display_mode mode;
160 HRESULT hr;
161
162 hr = wined3d_enum_adapter_modes(wined3d, This->adapter->ordinal, wined3d_format,
163 WINED3D_SCANLINE_ORDERING_UNKNOWN, i, &mode);
164 if (FAILED(hr))
165 {
166 WARN("EnumAdapterModes failed, hr %#x.\n", hr);
167 wined3d_decref(wined3d);
168 LeaveCriticalSection(&dxgi_cs);
169 return hr;
170 }
171
172 desc[i].Width = mode.width;
173 desc[i].Height = mode.height;
174 desc[i].RefreshRate.Numerator = mode.refresh_rate;
175 desc[i].RefreshRate.Denominator = 1;
176 desc[i].Format = format;
177 desc[i].ScanlineOrdering = mode.scanline_ordering;
178 desc[i].Scaling = DXGI_MODE_SCALING_UNSPECIFIED; /* FIXME */
179 }
180 wined3d_decref(wined3d);
181 LeaveCriticalSection(&dxgi_cs);
182
183 return S_OK;
184 }
185
186 static HRESULT STDMETHODCALLTYPE dxgi_output_FindClosestMatchingMode(IDXGIOutput *iface,
187 const DXGI_MODE_DESC *mode, DXGI_MODE_DESC *closest_match, IUnknown *device)
188 {
189 FIXME("iface %p, mode %p, closest_match %p, device %p stub!\n", iface, mode, closest_match, device);
190
191 return E_NOTIMPL;
192 }
193
194 static HRESULT STDMETHODCALLTYPE dxgi_output_WaitForVBlank(IDXGIOutput *iface)
195 {
196 FIXME("iface %p stub!\n", iface);
197
198 return E_NOTIMPL;
199 }
200
201 static HRESULT STDMETHODCALLTYPE dxgi_output_TakeOwnership(IDXGIOutput *iface, IUnknown *device, BOOL exclusive)
202 {
203 FIXME("iface %p, device %p, exclusive %d stub!\n", iface, device, exclusive);
204
205 return E_NOTIMPL;
206 }
207
208 static void STDMETHODCALLTYPE dxgi_output_ReleaseOwnership(IDXGIOutput *iface)
209 {
210 FIXME("iface %p stub!\n", iface);
211 }
212
213 static HRESULT STDMETHODCALLTYPE dxgi_output_GetGammaControlCapabilities(IDXGIOutput *iface,
214 DXGI_GAMMA_CONTROL_CAPABILITIES *gamma_caps)
215 {
216 FIXME("iface %p, gamma_caps %p stub!\n", iface, gamma_caps);
217
218 return E_NOTIMPL;
219 }
220
221 static HRESULT STDMETHODCALLTYPE dxgi_output_SetGammaControl(IDXGIOutput *iface,
222 const DXGI_GAMMA_CONTROL *gamma_control)
223 {
224 FIXME("iface %p, gamma_control %p stub!\n", iface, gamma_control);
225
226 return E_NOTIMPL;
227 }
228
229 static HRESULT STDMETHODCALLTYPE dxgi_output_GetGammaControl(IDXGIOutput *iface, DXGI_GAMMA_CONTROL *gamma_control)
230 {
231 FIXME("iface %p, gamma_control %p stub!\n", iface, gamma_control);
232
233 return E_NOTIMPL;
234 }
235
236 static HRESULT STDMETHODCALLTYPE dxgi_output_SetDisplaySurface(IDXGIOutput *iface, IDXGISurface *surface)
237 {
238 FIXME("iface %p, surface %p stub!\n", iface, surface);
239
240 return E_NOTIMPL;
241 }
242
243 static HRESULT STDMETHODCALLTYPE dxgi_output_GetDisplaySurfaceData(IDXGIOutput *iface, IDXGISurface *surface)
244 {
245 FIXME("iface %p, surface %p stub!\n", iface, surface);
246
247 return E_NOTIMPL;
248 }
249
250 static HRESULT STDMETHODCALLTYPE dxgi_output_GetFrameStatistics(IDXGIOutput *iface, DXGI_FRAME_STATISTICS *stats)
251 {
252 FIXME("iface %p, stats %p stub!\n", iface, stats);
253
254 return E_NOTIMPL;
255 }
256
257 static const struct IDXGIOutputVtbl dxgi_output_vtbl =
258 {
259 dxgi_output_QueryInterface,
260 dxgi_output_AddRef,
261 dxgi_output_Release,
262 /* IDXGIObject methods */
263 dxgi_output_SetPrivateData,
264 dxgi_output_SetPrivateDataInterface,
265 dxgi_output_GetPrivateData,
266 dxgi_output_GetParent,
267 /* IDXGIOutput methods */
268 dxgi_output_GetDesc,
269 dxgi_output_GetDisplayModeList,
270 dxgi_output_FindClosestMatchingMode,
271 dxgi_output_WaitForVBlank,
272 dxgi_output_TakeOwnership,
273 dxgi_output_ReleaseOwnership,
274 dxgi_output_GetGammaControlCapabilities,
275 dxgi_output_SetGammaControl,
276 dxgi_output_GetGammaControl,
277 dxgi_output_SetDisplaySurface,
278 dxgi_output_GetDisplaySurfaceData,
279 dxgi_output_GetFrameStatistics,
280 };
281
282 void dxgi_output_init(struct dxgi_output *output, struct dxgi_adapter *adapter)
283 {
284 output->IDXGIOutput_iface.lpVtbl = &dxgi_output_vtbl;
285 output->refcount = 1;
286 output->adapter = adapter;
287 }