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