mmdevapi/tests: Fix test on some 2k8 and mark those errors broken.
[wine] / dlls / dxgi / swapchain.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_swapchain_QueryInterface(IDXGISwapChain *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_IDXGIDeviceSubObject)
36             || IsEqualGUID(riid, &IID_IDXGISwapChain))
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_swapchain_AddRef(IDXGISwapChain *iface)
50 {
51     struct dxgi_swapchain *This = (struct dxgi_swapchain *)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 destroy_swapchain(IWineD3DSwapChain *swapchain)
60 {
61     TRACE("swapchain %p\n", swapchain);
62
63     return IWineD3DSwapChain_Release(swapchain);
64 }
65
66 static ULONG STDMETHODCALLTYPE dxgi_swapchain_Release(IDXGISwapChain *iface)
67 {
68     struct dxgi_swapchain *This = (struct dxgi_swapchain *)iface;
69     ULONG refcount = InterlockedDecrement(&This->refcount);
70
71     TRACE("%p decreasing refcount to %u\n", This, refcount);
72
73     if (!refcount)
74     {
75         IWineD3DDevice *wined3d_device;
76         HRESULT hr;
77
78         FIXME("Only a single swapchain is supported\n");
79
80         hr = IWineD3DSwapChain_GetDevice(This->wined3d_swapchain, &wined3d_device);
81         if (FAILED(hr))
82         {
83             ERR("Failed to get the wined3d device, hr %#x\n", hr);
84         }
85         else
86         {
87             hr = IWineD3DDevice_Uninit3D(wined3d_device, destroy_swapchain);
88             IWineD3DDevice_Release(wined3d_device);
89             if (FAILED(hr))
90             {
91                 ERR("Uninit3D failed, hr %#x\n", hr);
92             }
93         }
94
95         HeapFree(GetProcessHeap(), 0, This);
96     }
97
98     return refcount;
99 }
100
101 /* IDXGIObject methods */
102
103 static HRESULT STDMETHODCALLTYPE dxgi_swapchain_SetPrivateData(IDXGISwapChain *iface,
104         REFGUID guid, UINT data_size, const void *data)
105 {
106     FIXME("iface %p, guid %s, data_size %u, data %p stub!\n", iface, debugstr_guid(guid), data_size, data);
107
108     return E_NOTIMPL;
109 }
110
111 static HRESULT STDMETHODCALLTYPE dxgi_swapchain_SetPrivateDataInterface(IDXGISwapChain *iface,
112         REFGUID guid, const IUnknown *object)
113 {
114     FIXME("iface %p, guid %s, object %p stub!\n", iface, debugstr_guid(guid), object);
115
116     return E_NOTIMPL;
117 }
118
119 static HRESULT STDMETHODCALLTYPE dxgi_swapchain_GetPrivateData(IDXGISwapChain *iface,
120         REFGUID guid, UINT *data_size, void *data)
121 {
122     FIXME("iface %p, guid %s, data_size %p, data %p stub!\n", iface, debugstr_guid(guid), data_size, data);
123
124     return E_NOTIMPL;
125 }
126
127 static HRESULT STDMETHODCALLTYPE dxgi_swapchain_GetParent(IDXGISwapChain *iface, REFIID riid, void **parent)
128 {
129     FIXME("iface %p, riid %s, parent %p stub!\n", iface, debugstr_guid(riid), parent);
130
131     return E_NOTIMPL;
132 }
133
134 /* IDXGIDeviceSubObject methods */
135
136 static HRESULT STDMETHODCALLTYPE dxgi_swapchain_GetDevice(IDXGISwapChain *iface, REFIID riid, void **device)
137 {
138     FIXME("iface %p, riid %s, device %p stub!\n", iface, debugstr_guid(riid), device);
139
140     return E_NOTIMPL;
141 }
142
143 /* IDXGISwapChain methods */
144
145 static HRESULT STDMETHODCALLTYPE dxgi_swapchain_Present(IDXGISwapChain *iface, UINT sync_interval, UINT flags)
146 {
147     struct dxgi_swapchain *This = (struct dxgi_swapchain *)iface;
148
149     TRACE("iface %p, sync_interval %u, flags %#x\n", iface, sync_interval, flags);
150
151     if (sync_interval) FIXME("Unimplemented sync interval %u\n", sync_interval);
152     if (flags) FIXME("Unimplemented flags %#x\n", flags);
153
154     return IWineD3DSwapChain_Present(This->wined3d_swapchain, NULL, NULL, NULL, NULL, 0);
155 }
156
157 static HRESULT STDMETHODCALLTYPE dxgi_swapchain_GetBuffer(IDXGISwapChain *iface,
158         UINT buffer_idx, REFIID riid, void **surface)
159 {
160     struct dxgi_swapchain *This = (struct dxgi_swapchain *)iface;
161     IWineD3DSurface *backbuffer;
162     IUnknown *parent;
163     HRESULT hr;
164
165     TRACE("iface %p, buffer_idx %u, riid %s, surface %p\n",
166             iface, buffer_idx, debugstr_guid(riid), surface);
167
168     EnterCriticalSection(&dxgi_cs);
169
170     hr = IWineD3DSwapChain_GetBackBuffer(This->wined3d_swapchain, buffer_idx, WINED3DBACKBUFFER_TYPE_MONO, &backbuffer);
171     if (FAILED(hr))
172     {
173         LeaveCriticalSection(&dxgi_cs);
174         return hr;
175     }
176
177     parent = IWineD3DSurface_GetParent(backbuffer);
178     hr = IUnknown_QueryInterface(parent, riid, surface);
179     IWineD3DSurface_Release(backbuffer);
180     LeaveCriticalSection(&dxgi_cs);
181
182     return hr;
183 }
184
185 static HRESULT STDMETHODCALLTYPE dxgi_swapchain_SetFullscreenState(IDXGISwapChain *iface,
186         BOOL fullscreen, IDXGIOutput *target)
187 {
188     FIXME("iface %p, fullscreen %u, target %p stub!\n", iface, fullscreen, target);
189
190     return E_NOTIMPL;
191 }
192
193 static HRESULT STDMETHODCALLTYPE dxgi_swapchain_GetFullscreenState(IDXGISwapChain *iface,
194         BOOL *fullscreen, IDXGIOutput **target)
195 {
196     FIXME("iface %p, fullscreen %p, target %p stub!\n", iface, fullscreen, target);
197
198     return E_NOTIMPL;
199 }
200
201 static HRESULT STDMETHODCALLTYPE dxgi_swapchain_GetDesc(IDXGISwapChain *iface, DXGI_SWAP_CHAIN_DESC *desc)
202 {
203     FIXME("iface %p, desc %p stub!\n", iface, desc);
204
205     return E_NOTIMPL;
206 }
207
208 static HRESULT STDMETHODCALLTYPE dxgi_swapchain_ResizeBuffers(IDXGISwapChain *iface,
209         UINT buffer_count, UINT width, UINT height, DXGI_FORMAT format, UINT flags)
210 {
211     FIXME("iface %p, buffer_count %u, width %u, height %u, format %s, flags %#x stub!\n",
212             iface, buffer_count, width, height, debug_dxgi_format(format), flags);
213
214     return E_NOTIMPL;
215 }
216
217 static HRESULT STDMETHODCALLTYPE dxgi_swapchain_ResizeTarget(IDXGISwapChain *iface,
218         const DXGI_MODE_DESC *target_mode_desc)
219 {
220     FIXME("iface %p, target_mode_desc %p stub!\n", iface, target_mode_desc);
221
222     return E_NOTIMPL;
223 }
224
225 static HRESULT STDMETHODCALLTYPE dxgi_swapchain_GetContainingOutput(IDXGISwapChain *iface, IDXGIOutput **output)
226 {
227     FIXME("iface %p, output %p stub!\n", iface, output);
228
229     return E_NOTIMPL;
230 }
231
232 static HRESULT STDMETHODCALLTYPE dxgi_swapchain_GetFrameStatistics(IDXGISwapChain *iface, DXGI_FRAME_STATISTICS *stats)
233 {
234     FIXME("iface %p, stats %p stub!\n", iface, stats);
235
236     return E_NOTIMPL;
237 }
238
239 static HRESULT STDMETHODCALLTYPE dxgi_swapchain_GetLastPresentCount(IDXGISwapChain *iface, UINT *last_present_count)
240 {
241     FIXME("iface %p, last_present_count %p stub!\n", iface, last_present_count);
242
243     return E_NOTIMPL;
244 }
245
246 static const struct IDXGISwapChainVtbl dxgi_swapchain_vtbl =
247 {
248     /* IUnknown methods */
249     dxgi_swapchain_QueryInterface,
250     dxgi_swapchain_AddRef,
251     dxgi_swapchain_Release,
252     /* IDXGIObject methods */
253     dxgi_swapchain_SetPrivateData,
254     dxgi_swapchain_SetPrivateDataInterface,
255     dxgi_swapchain_GetPrivateData,
256     dxgi_swapchain_GetParent,
257     /* IDXGIDeviceSubObject methods */
258     dxgi_swapchain_GetDevice,
259     /* IDXGISwapChain methods */
260     dxgi_swapchain_Present,
261     dxgi_swapchain_GetBuffer,
262     dxgi_swapchain_SetFullscreenState,
263     dxgi_swapchain_GetFullscreenState,
264     dxgi_swapchain_GetDesc,
265     dxgi_swapchain_ResizeBuffers,
266     dxgi_swapchain_ResizeTarget,
267     dxgi_swapchain_GetContainingOutput,
268     dxgi_swapchain_GetFrameStatistics,
269     dxgi_swapchain_GetLastPresentCount,
270 };
271
272 HRESULT dxgi_swapchain_init(struct dxgi_swapchain *swapchain, struct dxgi_device *device,
273         WINED3DPRESENT_PARAMETERS *present_parameters)
274 {
275     HRESULT hr;
276
277     swapchain->vtbl = &dxgi_swapchain_vtbl;
278     swapchain->refcount = 1;
279
280     hr = IWineD3DDevice_CreateSwapChain(device->wined3d_device, present_parameters,
281             SURFACE_OPENGL, swapchain, &swapchain->wined3d_swapchain);
282     if (FAILED(hr))
283     {
284         WARN("Failed to create wined3d swapchain, hr %#x.\n", hr);
285         return hr;
286     }
287
288     return S_OK;
289 }