wined3d: Simplify shader interface matching for SM4+ vertex shaders.
[wine.git] / dlls / dxgi / output.c
blobcfd08fe2ba5edf7c491bea0702e1f080a764cb43
1 /*
2 * Copyright 2009 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
19 #include "config.h"
20 #include "wine/port.h"
22 #include "dxgi_private.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(dxgi);
26 static inline struct dxgi_output *impl_from_IDXGIOutput(IDXGIOutput *iface)
28 return CONTAINING_RECORD(iface, struct dxgi_output, IDXGIOutput_iface);
31 /* IUnknown methods */
33 static HRESULT STDMETHODCALLTYPE dxgi_output_QueryInterface(IDXGIOutput *iface, REFIID riid, void **object)
35 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
37 if (IsEqualGUID(riid, &IID_IDXGIOutput)
38 || IsEqualGUID(riid, &IID_IDXGIObject)
39 || IsEqualGUID(riid, &IID_IUnknown))
41 IUnknown_AddRef(iface);
42 *object = iface;
43 return S_OK;
46 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
48 *object = NULL;
49 return E_NOINTERFACE;
52 static ULONG STDMETHODCALLTYPE dxgi_output_AddRef(IDXGIOutput *iface)
54 struct dxgi_output *This = impl_from_IDXGIOutput(iface);
55 ULONG refcount = InterlockedIncrement(&This->refcount);
57 TRACE("%p increasing refcount to %u.\n", This, refcount);
59 return refcount;
62 static ULONG STDMETHODCALLTYPE dxgi_output_Release(IDXGIOutput *iface)
64 struct dxgi_output *output = impl_from_IDXGIOutput(iface);
65 ULONG refcount = InterlockedDecrement(&output->refcount);
67 TRACE("%p decreasing refcount to %u.\n", output, refcount);
69 if (!refcount)
71 wined3d_private_store_cleanup(&output->private_store);
72 IDXGIAdapter1_Release(&output->adapter->IDXGIAdapter1_iface);
73 HeapFree(GetProcessHeap(), 0, output);
76 return refcount;
79 /* IDXGIObject methods */
81 static HRESULT STDMETHODCALLTYPE dxgi_output_SetPrivateData(IDXGIOutput *iface,
82 REFGUID guid, UINT data_size, const void *data)
84 struct dxgi_output *output = impl_from_IDXGIOutput(iface);
86 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
88 return dxgi_set_private_data(&output->private_store, guid, data_size, data);
91 static HRESULT STDMETHODCALLTYPE dxgi_output_SetPrivateDataInterface(IDXGIOutput *iface,
92 REFGUID guid, const IUnknown *object)
94 struct dxgi_output *output = impl_from_IDXGIOutput(iface);
96 TRACE("iface %p, guid %s, object %p.\n", iface, debugstr_guid(guid), object);
98 return dxgi_set_private_data_interface(&output->private_store, guid, object);
101 static HRESULT STDMETHODCALLTYPE dxgi_output_GetPrivateData(IDXGIOutput *iface,
102 REFGUID guid, UINT *data_size, void *data)
104 struct dxgi_output *output = impl_from_IDXGIOutput(iface);
106 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
108 return dxgi_get_private_data(&output->private_store, guid, data_size, data);
111 static HRESULT STDMETHODCALLTYPE dxgi_output_GetParent(IDXGIOutput *iface,
112 REFIID riid, void **parent)
114 struct dxgi_output *output = impl_from_IDXGIOutput(iface);
116 TRACE("iface %p, riid %s, parent %p.\n", iface, debugstr_guid(riid), parent);
118 return IDXGIAdapter1_QueryInterface(&output->adapter->IDXGIAdapter1_iface, riid, parent);
121 /* IDXGIOutput methods */
123 static HRESULT STDMETHODCALLTYPE dxgi_output_GetDesc(IDXGIOutput *iface, DXGI_OUTPUT_DESC *desc)
125 struct dxgi_output *output = impl_from_IDXGIOutput(iface);
126 struct wined3d_output_desc wined3d_desc;
127 HRESULT hr;
129 TRACE("iface %p, desc %p.\n", iface, desc);
131 if (!desc)
132 return E_INVALIDARG;
134 wined3d_mutex_lock();
135 hr = wined3d_get_output_desc(output->adapter->factory->wined3d,
136 output->adapter->ordinal, &wined3d_desc);
137 wined3d_mutex_unlock();
139 if (FAILED(hr))
141 WARN("Failed to get output desc, hr %#x.\n", hr);
142 return hr;
145 memcpy(desc->DeviceName, wined3d_desc.device_name, sizeof(desc->DeviceName));
146 desc->DesktopCoordinates = wined3d_desc.desktop_rect;
147 desc->AttachedToDesktop = wined3d_desc.attached_to_desktop;
148 desc->Rotation = wined3d_desc.rotation;
149 desc->Monitor = wined3d_desc.monitor;
151 return S_OK;
154 static HRESULT STDMETHODCALLTYPE dxgi_output_GetDisplayModeList(IDXGIOutput *iface,
155 DXGI_FORMAT format, UINT flags, UINT *mode_count, DXGI_MODE_DESC *desc)
157 struct dxgi_output *This = impl_from_IDXGIOutput(iface);
158 enum wined3d_format_id wined3d_format;
159 struct wined3d *wined3d;
160 UINT i;
161 UINT max_count;
163 FIXME("iface %p, format %s, flags %#x, mode_count %p, desc %p partial stub!\n",
164 iface, debug_dxgi_format(format), flags, mode_count, desc);
166 if (!mode_count)
167 return DXGI_ERROR_INVALID_CALL;
169 if (format == DXGI_FORMAT_UNKNOWN)
171 *mode_count = 0;
172 return S_OK;
175 wined3d = This->adapter->factory->wined3d;
176 wined3d_format = wined3dformat_from_dxgi_format(format);
178 wined3d_mutex_lock();
179 max_count = wined3d_get_adapter_mode_count(wined3d, This->adapter->ordinal,
180 wined3d_format, WINED3D_SCANLINE_ORDERING_UNKNOWN);
182 if (!desc)
184 wined3d_mutex_unlock();
185 *mode_count = max_count;
186 return S_OK;
189 if (max_count > *mode_count)
191 wined3d_mutex_unlock();
192 return DXGI_ERROR_MORE_DATA;
195 *mode_count = max_count;
197 for (i = 0; i < *mode_count; ++i)
199 struct wined3d_display_mode mode;
200 HRESULT hr;
202 hr = wined3d_enum_adapter_modes(wined3d, This->adapter->ordinal, wined3d_format,
203 WINED3D_SCANLINE_ORDERING_UNKNOWN, i, &mode);
204 if (FAILED(hr))
206 WARN("EnumAdapterModes failed, hr %#x.\n", hr);
207 wined3d_mutex_unlock();
208 return hr;
211 desc[i].Width = mode.width;
212 desc[i].Height = mode.height;
213 desc[i].RefreshRate.Numerator = mode.refresh_rate;
214 desc[i].RefreshRate.Denominator = 1;
215 desc[i].Format = format;
216 desc[i].ScanlineOrdering = mode.scanline_ordering;
217 desc[i].Scaling = DXGI_MODE_SCALING_UNSPECIFIED; /* FIXME */
219 wined3d_mutex_unlock();
221 return S_OK;
224 static HRESULT STDMETHODCALLTYPE dxgi_output_FindClosestMatchingMode(IDXGIOutput *iface,
225 const DXGI_MODE_DESC *mode, DXGI_MODE_DESC *closest_match, IUnknown *device)
227 FIXME("iface %p, mode %p, closest_match %p, device %p stub!\n", iface, mode, closest_match, device);
229 return E_NOTIMPL;
232 static HRESULT STDMETHODCALLTYPE dxgi_output_WaitForVBlank(IDXGIOutput *iface)
234 FIXME("iface %p stub!\n", iface);
236 return E_NOTIMPL;
239 static HRESULT STDMETHODCALLTYPE dxgi_output_TakeOwnership(IDXGIOutput *iface, IUnknown *device, BOOL exclusive)
241 FIXME("iface %p, device %p, exclusive %d stub!\n", iface, device, exclusive);
243 return E_NOTIMPL;
246 static void STDMETHODCALLTYPE dxgi_output_ReleaseOwnership(IDXGIOutput *iface)
248 FIXME("iface %p stub!\n", iface);
251 static HRESULT STDMETHODCALLTYPE dxgi_output_GetGammaControlCapabilities(IDXGIOutput *iface,
252 DXGI_GAMMA_CONTROL_CAPABILITIES *gamma_caps)
254 FIXME("iface %p, gamma_caps %p stub!\n", iface, gamma_caps);
256 return E_NOTIMPL;
259 static HRESULT STDMETHODCALLTYPE dxgi_output_SetGammaControl(IDXGIOutput *iface,
260 const DXGI_GAMMA_CONTROL *gamma_control)
262 FIXME("iface %p, gamma_control %p stub!\n", iface, gamma_control);
264 return E_NOTIMPL;
267 static HRESULT STDMETHODCALLTYPE dxgi_output_GetGammaControl(IDXGIOutput *iface, DXGI_GAMMA_CONTROL *gamma_control)
269 FIXME("iface %p, gamma_control %p stub!\n", iface, gamma_control);
271 return E_NOTIMPL;
274 static HRESULT STDMETHODCALLTYPE dxgi_output_SetDisplaySurface(IDXGIOutput *iface, IDXGISurface *surface)
276 FIXME("iface %p, surface %p stub!\n", iface, surface);
278 return E_NOTIMPL;
281 static HRESULT STDMETHODCALLTYPE dxgi_output_GetDisplaySurfaceData(IDXGIOutput *iface, IDXGISurface *surface)
283 FIXME("iface %p, surface %p stub!\n", iface, surface);
285 return E_NOTIMPL;
288 static HRESULT STDMETHODCALLTYPE dxgi_output_GetFrameStatistics(IDXGIOutput *iface, DXGI_FRAME_STATISTICS *stats)
290 FIXME("iface %p, stats %p stub!\n", iface, stats);
292 return E_NOTIMPL;
295 static const struct IDXGIOutputVtbl dxgi_output_vtbl =
297 dxgi_output_QueryInterface,
298 dxgi_output_AddRef,
299 dxgi_output_Release,
300 /* IDXGIObject methods */
301 dxgi_output_SetPrivateData,
302 dxgi_output_SetPrivateDataInterface,
303 dxgi_output_GetPrivateData,
304 dxgi_output_GetParent,
305 /* IDXGIOutput methods */
306 dxgi_output_GetDesc,
307 dxgi_output_GetDisplayModeList,
308 dxgi_output_FindClosestMatchingMode,
309 dxgi_output_WaitForVBlank,
310 dxgi_output_TakeOwnership,
311 dxgi_output_ReleaseOwnership,
312 dxgi_output_GetGammaControlCapabilities,
313 dxgi_output_SetGammaControl,
314 dxgi_output_GetGammaControl,
315 dxgi_output_SetDisplaySurface,
316 dxgi_output_GetDisplaySurfaceData,
317 dxgi_output_GetFrameStatistics,
320 static void dxgi_output_init(struct dxgi_output *output, struct dxgi_adapter *adapter)
322 output->IDXGIOutput_iface.lpVtbl = &dxgi_output_vtbl;
323 output->refcount = 1;
324 wined3d_private_store_init(&output->private_store);
325 output->adapter = adapter;
326 IDXGIAdapter1_AddRef(&output->adapter->IDXGIAdapter1_iface);
329 HRESULT dxgi_output_create(struct dxgi_adapter *adapter, struct dxgi_output **output)
331 if (!(*output = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(**output))))
332 return E_OUTOFMEMORY;
334 dxgi_output_init(*output, adapter);
335 return S_OK;