msvcrt/tests: Remove a space before a '\n'.
[wine/gsoc-2012-control.git] / dlls / d3d9 / swapchain.c
blobc14cc6d1156d64e287a81051ab56f5707914bfe2
1 /*
2 * IDirect3DSwapChain9 implementation
4 * Copyright 2002-2003 Jason Edmeades
5 * Raphael Junqueira
6 * Copyright 2005 Oliver Stieber
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.
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.
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
23 #include "config.h"
24 #include "d3d9_private.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
28 /* IDirect3DSwapChain IUnknown parts follow: */
29 static HRESULT WINAPI IDirect3DSwapChain9Impl_QueryInterface(LPDIRECT3DSWAPCHAIN9 iface, REFIID riid, LPVOID* ppobj)
31 IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
33 if (IsEqualGUID(riid, &IID_IUnknown)
34 || IsEqualGUID(riid, &IID_IDirect3DSwapChain9)) {
35 IDirect3DSwapChain9_AddRef(iface);
36 *ppobj = This;
37 return S_OK;
40 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
41 *ppobj = NULL;
42 return E_NOINTERFACE;
45 static ULONG WINAPI IDirect3DSwapChain9Impl_AddRef(LPDIRECT3DSWAPCHAIN9 iface) {
46 IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
47 ULONG ref = InterlockedIncrement(&This->ref);
49 TRACE("(%p) : AddRef from %d\n", This, ref - 1);
51 if(ref == 1 && This->parentDevice) IDirect3DDevice9Ex_AddRef(This->parentDevice);
53 return ref;
56 static ULONG WINAPI IDirect3DSwapChain9Impl_Release(LPDIRECT3DSWAPCHAIN9 iface) {
57 IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
58 ULONG ref = InterlockedDecrement(&This->ref);
60 TRACE("(%p) : ReleaseRef to %d\n", This, ref);
62 if (ref == 0) {
63 if (This->parentDevice) IDirect3DDevice9Ex_Release(This->parentDevice);
64 if (!This->isImplicit) {
65 EnterCriticalSection(&d3d9_cs);
66 IWineD3DSwapChain_Destroy(This->wineD3DSwapChain, D3D9CB_DestroyRenderTarget);
67 LeaveCriticalSection(&d3d9_cs);
68 HeapFree(GetProcessHeap(), 0, This);
71 return ref;
74 /* IDirect3DSwapChain9 parts follow: */
75 static HRESULT WINAPI IDirect3DSwapChain9Impl_Present(LPDIRECT3DSWAPCHAIN9 iface, CONST RECT* pSourceRect, CONST RECT* pDestRect, HWND hDestWindowOverride, CONST RGNDATA* pDirtyRegion, DWORD dwFlags) {
76 IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
77 TRACE("(%p) Relay\n", This);
78 return IWineD3DSwapChain_Present(This->wineD3DSwapChain, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion, dwFlags);
81 static HRESULT WINAPI IDirect3DSwapChain9Impl_GetFrontBufferData(LPDIRECT3DSWAPCHAIN9 iface, IDirect3DSurface9* pDestSurface) {
82 IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
83 HRESULT hr;
84 TRACE("(%p) Relay\n", This);
86 EnterCriticalSection(&d3d9_cs);
87 hr = IWineD3DSwapChain_GetFrontBufferData(This->wineD3DSwapChain, ((IDirect3DSurface9Impl *)pDestSurface)->wineD3DSurface);
88 LeaveCriticalSection(&d3d9_cs);
89 return hr;
92 static HRESULT WINAPI IDirect3DSwapChain9Impl_GetBackBuffer(LPDIRECT3DSWAPCHAIN9 iface, UINT iBackBuffer, D3DBACKBUFFER_TYPE Type, IDirect3DSurface9** ppBackBuffer) {
93 IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
94 HRESULT hrc = D3D_OK;
95 IWineD3DSurface *mySurface = NULL;
97 TRACE("(%p) Relay\n", This);
99 EnterCriticalSection(&d3d9_cs);
100 hrc = IWineD3DSwapChain_GetBackBuffer(This->wineD3DSwapChain, iBackBuffer, (WINED3DBACKBUFFER_TYPE) Type, &mySurface);
101 if (hrc == D3D_OK && NULL != mySurface) {
102 IWineD3DSurface_GetParent(mySurface, (IUnknown **)ppBackBuffer);
103 IWineD3DSurface_Release(mySurface);
105 LeaveCriticalSection(&d3d9_cs);
106 /* Do not touch the **ppBackBuffer pointer otherwise! (see device test) */
107 return hrc;
110 static HRESULT WINAPI IDirect3DSwapChain9Impl_GetRasterStatus(LPDIRECT3DSWAPCHAIN9 iface, D3DRASTER_STATUS* pRasterStatus) {
111 IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
112 HRESULT hr;
113 TRACE("(%p) Relay\n", This);
115 EnterCriticalSection(&d3d9_cs);
116 hr = IWineD3DSwapChain_GetRasterStatus(This->wineD3DSwapChain, (WINED3DRASTER_STATUS *) pRasterStatus);
117 LeaveCriticalSection(&d3d9_cs);
118 return hr;
121 static HRESULT WINAPI IDirect3DSwapChain9Impl_GetDisplayMode(LPDIRECT3DSWAPCHAIN9 iface, D3DDISPLAYMODE* pMode) {
122 IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
123 HRESULT hr;
124 TRACE("(%p) Relay\n", This);
126 EnterCriticalSection(&d3d9_cs);
127 hr = IWineD3DSwapChain_GetDisplayMode(This->wineD3DSwapChain, (WINED3DDISPLAYMODE *) pMode);
128 LeaveCriticalSection(&d3d9_cs);
129 return hr;
132 static HRESULT WINAPI IDirect3DSwapChain9Impl_GetDevice(LPDIRECT3DSWAPCHAIN9 iface, IDirect3DDevice9** ppDevice) {
133 IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
134 HRESULT hrc = D3D_OK;
135 IWineD3DDevice *device = NULL;
137 TRACE("(%p) Relay\n", This);
139 EnterCriticalSection(&d3d9_cs);
140 hrc = IWineD3DSwapChain_GetDevice(This->wineD3DSwapChain, &device);
141 if (hrc == D3D_OK && NULL != device) {
142 IWineD3DDevice_GetParent(device, (IUnknown **)ppDevice);
143 IWineD3DDevice_Release(device);
145 LeaveCriticalSection(&d3d9_cs);
146 return hrc;
149 static HRESULT WINAPI IDirect3DSwapChain9Impl_GetPresentParameters(LPDIRECT3DSWAPCHAIN9 iface, D3DPRESENT_PARAMETERS* pPresentationParameters) {
150 IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
151 WINED3DPRESENT_PARAMETERS winePresentParameters;
152 HRESULT hr;
154 TRACE("(%p)->(%p): Relay\n", This, pPresentationParameters);
156 EnterCriticalSection(&d3d9_cs);
157 hr = IWineD3DSwapChain_GetPresentParameters(This->wineD3DSwapChain, &winePresentParameters);
158 LeaveCriticalSection(&d3d9_cs);
160 pPresentationParameters->BackBufferWidth = winePresentParameters.BackBufferWidth;
161 pPresentationParameters->BackBufferHeight = winePresentParameters.BackBufferHeight;
162 pPresentationParameters->BackBufferFormat = winePresentParameters.BackBufferFormat;
163 pPresentationParameters->BackBufferCount = winePresentParameters.BackBufferCount;
164 pPresentationParameters->MultiSampleType = winePresentParameters.MultiSampleType;
165 pPresentationParameters->MultiSampleQuality = winePresentParameters.MultiSampleQuality;
166 pPresentationParameters->SwapEffect = winePresentParameters.SwapEffect;
167 pPresentationParameters->hDeviceWindow = winePresentParameters.hDeviceWindow;
168 pPresentationParameters->Windowed = winePresentParameters.Windowed;
169 pPresentationParameters->EnableAutoDepthStencil = winePresentParameters.EnableAutoDepthStencil;
170 pPresentationParameters->Flags = winePresentParameters.Flags;
171 pPresentationParameters->FullScreen_RefreshRateInHz = winePresentParameters.FullScreen_RefreshRateInHz;
172 pPresentationParameters->PresentationInterval = winePresentParameters.PresentationInterval;
174 return hr;
178 static const IDirect3DSwapChain9Vtbl Direct3DSwapChain9_Vtbl =
180 IDirect3DSwapChain9Impl_QueryInterface,
181 IDirect3DSwapChain9Impl_AddRef,
182 IDirect3DSwapChain9Impl_Release,
183 IDirect3DSwapChain9Impl_Present,
184 IDirect3DSwapChain9Impl_GetFrontBufferData,
185 IDirect3DSwapChain9Impl_GetBackBuffer,
186 IDirect3DSwapChain9Impl_GetRasterStatus,
187 IDirect3DSwapChain9Impl_GetDisplayMode,
188 IDirect3DSwapChain9Impl_GetDevice,
189 IDirect3DSwapChain9Impl_GetPresentParameters
193 /* IDirect3DDevice9 IDirect3DSwapChain9 Methods follow: */
194 HRESULT WINAPI IDirect3DDevice9Impl_CreateAdditionalSwapChain(LPDIRECT3DDEVICE9EX iface, D3DPRESENT_PARAMETERS* pPresentationParameters, IDirect3DSwapChain9** pSwapChain) {
195 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
196 IDirect3DSwapChain9Impl* object;
197 HRESULT hrc = D3D_OK;
198 WINED3DPRESENT_PARAMETERS localParameters;
200 TRACE("(%p) Relay\n", This);
202 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
203 if (NULL == object) {
204 FIXME("Allocation of memory failed, returning D3DERR_OUTOFVIDEOMEMORY\n");
205 return D3DERR_OUTOFVIDEOMEMORY;
207 object->ref = 1;
208 object->lpVtbl = &Direct3DSwapChain9_Vtbl;
210 /* The back buffer count is set to one if it's 0 */
211 if(pPresentationParameters->BackBufferCount == 0) {
212 pPresentationParameters->BackBufferCount = 1;
215 /* Allocate an associated WineD3DDevice object */
216 localParameters.BackBufferWidth = pPresentationParameters->BackBufferWidth;
217 localParameters.BackBufferHeight = pPresentationParameters->BackBufferHeight;
218 localParameters.BackBufferFormat = pPresentationParameters->BackBufferFormat;
219 localParameters.BackBufferCount = pPresentationParameters->BackBufferCount;
220 localParameters.MultiSampleType = pPresentationParameters->MultiSampleType;
221 localParameters.MultiSampleQuality = pPresentationParameters->MultiSampleQuality;
222 localParameters.SwapEffect = pPresentationParameters->SwapEffect;
223 localParameters.hDeviceWindow = pPresentationParameters->hDeviceWindow;
224 localParameters.Windowed = pPresentationParameters->Windowed;
225 localParameters.EnableAutoDepthStencil = pPresentationParameters->EnableAutoDepthStencil;
226 localParameters.AutoDepthStencilFormat = pPresentationParameters->AutoDepthStencilFormat;
227 localParameters.Flags = pPresentationParameters->Flags;
228 localParameters.FullScreen_RefreshRateInHz = pPresentationParameters->FullScreen_RefreshRateInHz;
229 localParameters.PresentationInterval = pPresentationParameters->PresentationInterval;
230 localParameters.AutoRestoreDisplayMode = TRUE;
232 EnterCriticalSection(&d3d9_cs);
233 hrc = IWineD3DDevice_CreateSwapChain(This->WineD3DDevice, &localParameters,
234 &object->wineD3DSwapChain, (IUnknown*)object, SURFACE_OPENGL);
235 LeaveCriticalSection(&d3d9_cs);
237 pPresentationParameters->BackBufferWidth = localParameters.BackBufferWidth;
238 pPresentationParameters->BackBufferHeight = localParameters.BackBufferHeight;
239 pPresentationParameters->BackBufferFormat = localParameters.BackBufferFormat;
240 pPresentationParameters->BackBufferCount = localParameters.BackBufferCount;
241 pPresentationParameters->MultiSampleType = localParameters.MultiSampleType;
242 pPresentationParameters->MultiSampleQuality = localParameters.MultiSampleQuality;
243 pPresentationParameters->SwapEffect = localParameters.SwapEffect;
244 pPresentationParameters->hDeviceWindow = localParameters.hDeviceWindow;
245 pPresentationParameters->Windowed = localParameters.Windowed;
246 pPresentationParameters->EnableAutoDepthStencil = localParameters.EnableAutoDepthStencil;
247 pPresentationParameters->AutoDepthStencilFormat = localParameters.AutoDepthStencilFormat;
248 pPresentationParameters->Flags = localParameters.Flags;
249 pPresentationParameters->FullScreen_RefreshRateInHz = localParameters.FullScreen_RefreshRateInHz;
250 pPresentationParameters->PresentationInterval = localParameters.PresentationInterval;
252 if (hrc != D3D_OK) {
253 FIXME("(%p) call to IWineD3DDevice_CreateSwapChain failed\n", This);
254 HeapFree(GetProcessHeap(), 0 , object);
255 } else {
256 IDirect3DDevice9Ex_AddRef(iface);
257 object->parentDevice = iface;
258 *pSwapChain = (IDirect3DSwapChain9 *)object;
259 TRACE("(%p) : Created swapchain %p\n", This, *pSwapChain);
261 TRACE("(%p) returning %p\n", This, *pSwapChain);
262 return hrc;
265 HRESULT WINAPI IDirect3DDevice9Impl_GetSwapChain(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain, IDirect3DSwapChain9** pSwapChain) {
266 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
267 HRESULT hrc = D3D_OK;
268 IWineD3DSwapChain *swapchain = NULL;
270 TRACE("(%p) Relay\n", This);
272 EnterCriticalSection(&d3d9_cs);
273 hrc = IWineD3DDevice_GetSwapChain(This->WineD3DDevice, iSwapChain, &swapchain);
274 if (hrc == D3D_OK && NULL != swapchain) {
275 IWineD3DSwapChain_GetParent(swapchain, (IUnknown **)pSwapChain);
276 IWineD3DSwapChain_Release(swapchain);
277 } else {
278 *pSwapChain = NULL;
280 LeaveCriticalSection(&d3d9_cs);
281 return hrc;
284 UINT WINAPI IDirect3DDevice9Impl_GetNumberOfSwapChains(LPDIRECT3DDEVICE9EX iface) {
285 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
286 UINT ret;
287 TRACE("(%p) Relay\n", This);
289 EnterCriticalSection(&d3d9_cs);
290 ret = IWineD3DDevice_GetNumberOfSwapChains(This->WineD3DDevice);
291 LeaveCriticalSection(&d3d9_cs);
292 return ret;