crypt32: Add basic flags tests flags for CertFindCRLInStore with find type CRL_FIND_I...
[wine] / dlls / d3d9 / swapchain.c
1 /*
2  * IDirect3DSwapChain9 implementation
3  *
4  * Copyright 2002-2003 Jason Edmeades
5  *                     Raphael Junqueira
6  * Copyright 2005 Oliver Stieber
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21  */
22
23 #include "config.h"
24 #include "d3d9_private.h"
25
26 WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
27
28 /* IDirect3DSwapChain IUnknown parts follow: */
29 static HRESULT WINAPI IDirect3DSwapChain9Impl_QueryInterface(LPDIRECT3DSWAPCHAIN9 iface, REFIID riid, LPVOID* ppobj)
30 {
31     IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
32
33     TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
34
35     if (IsEqualGUID(riid, &IID_IUnknown)
36         || IsEqualGUID(riid, &IID_IDirect3DSwapChain9)) {
37         IDirect3DSwapChain9_AddRef(iface);
38         *ppobj = This;
39         return S_OK;
40     }
41
42     WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
43     *ppobj = NULL;
44     return E_NOINTERFACE;
45 }
46
47 static ULONG WINAPI IDirect3DSwapChain9Impl_AddRef(LPDIRECT3DSWAPCHAIN9 iface) {
48     IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
49     ULONG ref = InterlockedIncrement(&This->ref);
50
51     TRACE("%p increasing refcount to %u.\n", iface, ref);
52
53     if(ref == 1 && This->parentDevice) IDirect3DDevice9Ex_AddRef(This->parentDevice);
54
55     return ref;
56 }
57
58 static ULONG WINAPI IDirect3DSwapChain9Impl_Release(LPDIRECT3DSWAPCHAIN9 iface) {
59     IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
60     ULONG ref = InterlockedDecrement(&This->ref);
61
62     TRACE("%p decreasing refcount to %u.\n", iface, ref);
63
64     if (ref == 0) {
65         IDirect3DDevice9Ex *parentDevice = This->parentDevice;
66
67         if (!This->isImplicit) {
68             wined3d_mutex_lock();
69             IWineD3DSwapChain_Destroy(This->wineD3DSwapChain);
70             wined3d_mutex_unlock();
71
72             HeapFree(GetProcessHeap(), 0, This);
73         }
74
75         /* Release the device last, as it may cause the device to be destroyed. */
76         if (parentDevice) IDirect3DDevice9Ex_Release(parentDevice);
77     }
78     return ref;
79 }
80
81 /* IDirect3DSwapChain9 parts follow: */
82 static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DSwapChain9Impl_Present(LPDIRECT3DSWAPCHAIN9 iface, CONST RECT* pSourceRect, CONST RECT* pDestRect, HWND hDestWindowOverride, CONST RGNDATA* pDirtyRegion, DWORD dwFlags) {
83     IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
84     HRESULT hr;
85
86     TRACE("iface %p, src_rect %p, dst_rect %p, dst_window_override %p, dirty_region %p, flags %#x.\n",
87             iface, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion, dwFlags);
88
89     wined3d_mutex_lock();
90     hr = IWineD3DSwapChain_Present(This->wineD3DSwapChain, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion, dwFlags);
91     wined3d_mutex_unlock();
92
93     return hr;
94 }
95
96 static HRESULT WINAPI IDirect3DSwapChain9Impl_GetFrontBufferData(LPDIRECT3DSWAPCHAIN9 iface, IDirect3DSurface9* pDestSurface) {
97     IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
98     HRESULT hr;
99
100     TRACE("iface %p, surface %p.\n", iface, pDestSurface);
101
102     wined3d_mutex_lock();
103     hr = IWineD3DSwapChain_GetFrontBufferData(This->wineD3DSwapChain,  ((IDirect3DSurface9Impl *)pDestSurface)->wineD3DSurface);
104     wined3d_mutex_unlock();
105
106     return hr;
107 }
108
109 static HRESULT WINAPI IDirect3DSwapChain9Impl_GetBackBuffer(LPDIRECT3DSWAPCHAIN9 iface, UINT iBackBuffer, D3DBACKBUFFER_TYPE Type, IDirect3DSurface9** ppBackBuffer) {
110     IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
111     HRESULT hrc = D3D_OK;
112     IWineD3DSurface *mySurface = NULL;
113
114     TRACE("iface %p, backbuffer_idx %u, backbuffer_type %#x, backbuffer %p.\n",
115             iface, iBackBuffer, Type, ppBackBuffer);
116
117     wined3d_mutex_lock();
118     hrc = IWineD3DSwapChain_GetBackBuffer(This->wineD3DSwapChain, iBackBuffer, (WINED3DBACKBUFFER_TYPE) Type, &mySurface);
119     if (hrc == D3D_OK && NULL != mySurface) {
120        IWineD3DSurface_GetParent(mySurface, (IUnknown **)ppBackBuffer);
121        IWineD3DSurface_Release(mySurface);
122     }
123     wined3d_mutex_unlock();
124
125     /* Do not touch the **ppBackBuffer pointer otherwise! (see device test) */
126     return hrc;
127 }
128
129 static HRESULT WINAPI IDirect3DSwapChain9Impl_GetRasterStatus(LPDIRECT3DSWAPCHAIN9 iface, D3DRASTER_STATUS* pRasterStatus) {
130     IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
131     HRESULT hr;
132
133     TRACE("iface %p, raster_status %p.\n", iface, pRasterStatus);
134
135     wined3d_mutex_lock();
136     hr = IWineD3DSwapChain_GetRasterStatus(This->wineD3DSwapChain, (WINED3DRASTER_STATUS *) pRasterStatus);
137     wined3d_mutex_unlock();
138
139     return hr;
140 }
141
142 static HRESULT WINAPI IDirect3DSwapChain9Impl_GetDisplayMode(LPDIRECT3DSWAPCHAIN9 iface, D3DDISPLAYMODE* pMode) {
143     IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
144     HRESULT hr;
145
146     TRACE("iface %p, mode %p.\n", iface, pMode);
147
148     wined3d_mutex_lock();
149     hr = IWineD3DSwapChain_GetDisplayMode(This->wineD3DSwapChain, (WINED3DDISPLAYMODE *) pMode);
150     wined3d_mutex_unlock();
151
152     if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format);
153
154     return hr;
155 }
156
157 static HRESULT WINAPI IDirect3DSwapChain9Impl_GetDevice(LPDIRECT3DSWAPCHAIN9 iface, IDirect3DDevice9** ppDevice) {
158     IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
159     HRESULT hrc = D3D_OK;
160     IWineD3DDevice *device = NULL;
161
162     TRACE("iface %p, device %p.\n", iface, ppDevice);
163
164     wined3d_mutex_lock();
165     hrc = IWineD3DSwapChain_GetDevice(This->wineD3DSwapChain, &device);
166     if (hrc == D3D_OK && NULL != device) {
167        IWineD3DDevice_GetParent(device, (IUnknown **)ppDevice);
168        IWineD3DDevice_Release(device);
169     }
170     wined3d_mutex_unlock();
171
172     return hrc;
173 }
174
175 static HRESULT WINAPI IDirect3DSwapChain9Impl_GetPresentParameters(LPDIRECT3DSWAPCHAIN9 iface, D3DPRESENT_PARAMETERS* pPresentationParameters) {
176     IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
177     WINED3DPRESENT_PARAMETERS winePresentParameters;
178     HRESULT hr;
179
180     TRACE("iface %p, parameters %p.\n", iface, pPresentationParameters);
181
182     wined3d_mutex_lock();
183     hr = IWineD3DSwapChain_GetPresentParameters(This->wineD3DSwapChain, &winePresentParameters);
184     wined3d_mutex_unlock();
185
186     pPresentationParameters->BackBufferWidth            = winePresentParameters.BackBufferWidth;
187     pPresentationParameters->BackBufferHeight           = winePresentParameters.BackBufferHeight;
188     pPresentationParameters->BackBufferFormat           = d3dformat_from_wined3dformat(winePresentParameters.BackBufferFormat);
189     pPresentationParameters->BackBufferCount            = winePresentParameters.BackBufferCount;
190     pPresentationParameters->MultiSampleType            = winePresentParameters.MultiSampleType;
191     pPresentationParameters->MultiSampleQuality         = winePresentParameters.MultiSampleQuality;
192     pPresentationParameters->SwapEffect                 = winePresentParameters.SwapEffect;
193     pPresentationParameters->hDeviceWindow              = winePresentParameters.hDeviceWindow;
194     pPresentationParameters->Windowed                   = winePresentParameters.Windowed;
195     pPresentationParameters->EnableAutoDepthStencil     = winePresentParameters.EnableAutoDepthStencil;
196     pPresentationParameters->AutoDepthStencilFormat     = d3dformat_from_wined3dformat(winePresentParameters.AutoDepthStencilFormat);
197     pPresentationParameters->Flags                      = winePresentParameters.Flags;
198     pPresentationParameters->FullScreen_RefreshRateInHz = winePresentParameters.FullScreen_RefreshRateInHz;
199     pPresentationParameters->PresentationInterval       = winePresentParameters.PresentationInterval;
200
201     return hr;
202 }
203
204
205 static const IDirect3DSwapChain9Vtbl Direct3DSwapChain9_Vtbl =
206 {
207     IDirect3DSwapChain9Impl_QueryInterface,
208     IDirect3DSwapChain9Impl_AddRef,
209     IDirect3DSwapChain9Impl_Release,
210     IDirect3DSwapChain9Impl_Present,
211     IDirect3DSwapChain9Impl_GetFrontBufferData,
212     IDirect3DSwapChain9Impl_GetBackBuffer,
213     IDirect3DSwapChain9Impl_GetRasterStatus,
214     IDirect3DSwapChain9Impl_GetDisplayMode,
215     IDirect3DSwapChain9Impl_GetDevice,
216     IDirect3DSwapChain9Impl_GetPresentParameters
217 };
218
219
220 /* IDirect3DDevice9 IDirect3DSwapChain9 Methods follow: */
221 HRESULT  WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_CreateAdditionalSwapChain(LPDIRECT3DDEVICE9EX iface, D3DPRESENT_PARAMETERS* pPresentationParameters, IDirect3DSwapChain9** pSwapChain) {
222     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
223     IDirect3DSwapChain9Impl* object;
224     HRESULT hrc = D3D_OK;
225     WINED3DPRESENT_PARAMETERS localParameters;
226
227     TRACE("iface %p, parameters %p, swapchain %p.\n",
228             iface, pPresentationParameters, pSwapChain);
229
230     object = HeapAlloc(GetProcessHeap(),  HEAP_ZERO_MEMORY, sizeof(*object));
231     if (NULL == object) {
232         FIXME("Allocation of memory failed, returning D3DERR_OUTOFVIDEOMEMORY\n");
233         return D3DERR_OUTOFVIDEOMEMORY;
234     }
235     object->ref = 1;
236     object->lpVtbl = &Direct3DSwapChain9_Vtbl;
237
238     /* The back buffer count is set to one if it's 0 */
239     if(pPresentationParameters->BackBufferCount == 0) {
240         pPresentationParameters->BackBufferCount = 1;
241     }
242
243     /* Allocate an associated WineD3DDevice object */
244     localParameters.BackBufferWidth                     = pPresentationParameters->BackBufferWidth;
245     localParameters.BackBufferHeight                    = pPresentationParameters->BackBufferHeight;
246     localParameters.BackBufferFormat                    = wined3dformat_from_d3dformat(pPresentationParameters->BackBufferFormat);
247     localParameters.BackBufferCount                     = pPresentationParameters->BackBufferCount;
248     localParameters.MultiSampleType                     = pPresentationParameters->MultiSampleType;
249     localParameters.MultiSampleQuality                  = pPresentationParameters->MultiSampleQuality;
250     localParameters.SwapEffect                          = pPresentationParameters->SwapEffect;
251     localParameters.hDeviceWindow                       = pPresentationParameters->hDeviceWindow;
252     localParameters.Windowed                            = pPresentationParameters->Windowed;
253     localParameters.EnableAutoDepthStencil              = pPresentationParameters->EnableAutoDepthStencil;
254     localParameters.AutoDepthStencilFormat              = wined3dformat_from_d3dformat(pPresentationParameters->AutoDepthStencilFormat);
255     localParameters.Flags                               = pPresentationParameters->Flags;
256     localParameters.FullScreen_RefreshRateInHz          = pPresentationParameters->FullScreen_RefreshRateInHz;
257     localParameters.PresentationInterval                = pPresentationParameters->PresentationInterval;
258     localParameters.AutoRestoreDisplayMode              = TRUE;
259
260     wined3d_mutex_lock();
261     hrc = IWineD3DDevice_CreateSwapChain(This->WineD3DDevice, &localParameters,
262             &object->wineD3DSwapChain, (IUnknown*)object, SURFACE_OPENGL);
263     wined3d_mutex_unlock();
264
265     pPresentationParameters->BackBufferWidth            = localParameters.BackBufferWidth;
266     pPresentationParameters->BackBufferHeight           = localParameters.BackBufferHeight;
267     pPresentationParameters->BackBufferFormat           = d3dformat_from_wined3dformat(localParameters.BackBufferFormat);
268     pPresentationParameters->BackBufferCount            = localParameters.BackBufferCount;
269     pPresentationParameters->MultiSampleType            = localParameters.MultiSampleType;
270     pPresentationParameters->MultiSampleQuality         = localParameters.MultiSampleQuality;
271     pPresentationParameters->SwapEffect                 = localParameters.SwapEffect;
272     pPresentationParameters->hDeviceWindow              = localParameters.hDeviceWindow;
273     pPresentationParameters->Windowed                   = localParameters.Windowed;
274     pPresentationParameters->EnableAutoDepthStencil     = localParameters.EnableAutoDepthStencil;
275     pPresentationParameters->AutoDepthStencilFormat     = d3dformat_from_wined3dformat(localParameters.AutoDepthStencilFormat);
276     pPresentationParameters->Flags                      = localParameters.Flags;
277     pPresentationParameters->FullScreen_RefreshRateInHz = localParameters.FullScreen_RefreshRateInHz;
278     pPresentationParameters->PresentationInterval       = localParameters.PresentationInterval;
279
280     if (hrc != D3D_OK) {
281         FIXME("(%p) call to IWineD3DDevice_CreateSwapChain failed\n", This);
282         HeapFree(GetProcessHeap(), 0 , object);
283     } else {
284         IDirect3DDevice9Ex_AddRef(iface);
285         object->parentDevice = iface;
286         *pSwapChain = (IDirect3DSwapChain9 *)object;
287         TRACE("(%p) : Created swapchain %p\n", This, *pSwapChain);
288     }
289     TRACE("(%p) returning %p\n", This, *pSwapChain);
290     return hrc;
291 }
292
293 HRESULT  WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_GetSwapChain(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain, IDirect3DSwapChain9** pSwapChain) {
294     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
295     HRESULT hrc = D3D_OK;
296     IWineD3DSwapChain *swapchain = NULL;
297
298     TRACE("iface %p, swapchain_idx %u, swapchain %p.\n",
299             iface, iSwapChain, pSwapChain);
300
301     wined3d_mutex_lock();
302     hrc = IWineD3DDevice_GetSwapChain(This->WineD3DDevice, iSwapChain, &swapchain);
303     if (hrc == D3D_OK && NULL != swapchain) {
304        IWineD3DSwapChain_GetParent(swapchain, (IUnknown **)pSwapChain);
305        IWineD3DSwapChain_Release(swapchain);
306     } else {
307         *pSwapChain = NULL;
308     }
309     wined3d_mutex_unlock();
310
311     return hrc;
312 }
313
314 UINT     WINAPI  IDirect3DDevice9Impl_GetNumberOfSwapChains(LPDIRECT3DDEVICE9EX iface) {
315     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
316     UINT ret;
317
318     TRACE("iface %p.\n", iface);
319
320     wined3d_mutex_lock();
321     ret = IWineD3DDevice_GetNumberOfSwapChains(This->WineD3DDevice);
322     wined3d_mutex_unlock();
323
324     return ret;
325 }