2 * IDirect3DSwapChain9 implementation
4 * Copyright 2002-2003 Jason Edmeades
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
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
);
40 WARN("(%p)->(%s,%p),not found\n", This
, debugstr_guid(riid
), ppobj
);
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
);
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
);
63 if (This
->parentDevice
) IDirect3DDevice9Ex_Release(This
->parentDevice
);
64 if (!This
->isImplicit
) {
66 IWineD3DSwapChain_Destroy(This
->wineD3DSwapChain
, D3D9CB_DestroyRenderTarget
);
67 wined3d_mutex_unlock();
69 HeapFree(GetProcessHeap(), 0, This
);
75 /* IDirect3DSwapChain9 parts follow: */
76 static HRESULT WINAPI
IDirect3DSwapChain9Impl_Present(LPDIRECT3DSWAPCHAIN9 iface
, CONST RECT
* pSourceRect
, CONST RECT
* pDestRect
, HWND hDestWindowOverride
, CONST RGNDATA
* pDirtyRegion
, DWORD dwFlags
) {
77 IDirect3DSwapChain9Impl
*This
= (IDirect3DSwapChain9Impl
*)iface
;
80 TRACE("(%p) Relay\n", This
);
83 hr
= IWineD3DSwapChain_Present(This
->wineD3DSwapChain
, pSourceRect
, pDestRect
, hDestWindowOverride
, pDirtyRegion
, dwFlags
);
84 wined3d_mutex_unlock();
89 static HRESULT WINAPI
IDirect3DSwapChain9Impl_GetFrontBufferData(LPDIRECT3DSWAPCHAIN9 iface
, IDirect3DSurface9
* pDestSurface
) {
90 IDirect3DSwapChain9Impl
*This
= (IDirect3DSwapChain9Impl
*)iface
;
92 TRACE("(%p) Relay\n", This
);
95 hr
= IWineD3DSwapChain_GetFrontBufferData(This
->wineD3DSwapChain
, ((IDirect3DSurface9Impl
*)pDestSurface
)->wineD3DSurface
);
96 wined3d_mutex_unlock();
101 static HRESULT WINAPI
IDirect3DSwapChain9Impl_GetBackBuffer(LPDIRECT3DSWAPCHAIN9 iface
, UINT iBackBuffer
, D3DBACKBUFFER_TYPE Type
, IDirect3DSurface9
** ppBackBuffer
) {
102 IDirect3DSwapChain9Impl
*This
= (IDirect3DSwapChain9Impl
*)iface
;
103 HRESULT hrc
= D3D_OK
;
104 IWineD3DSurface
*mySurface
= NULL
;
106 TRACE("(%p) Relay\n", This
);
108 wined3d_mutex_lock();
109 hrc
= IWineD3DSwapChain_GetBackBuffer(This
->wineD3DSwapChain
, iBackBuffer
, (WINED3DBACKBUFFER_TYPE
) Type
, &mySurface
);
110 if (hrc
== D3D_OK
&& NULL
!= mySurface
) {
111 IWineD3DSurface_GetParent(mySurface
, (IUnknown
**)ppBackBuffer
);
112 IWineD3DSurface_Release(mySurface
);
114 wined3d_mutex_unlock();
116 /* Do not touch the **ppBackBuffer pointer otherwise! (see device test) */
120 static HRESULT WINAPI
IDirect3DSwapChain9Impl_GetRasterStatus(LPDIRECT3DSWAPCHAIN9 iface
, D3DRASTER_STATUS
* pRasterStatus
) {
121 IDirect3DSwapChain9Impl
*This
= (IDirect3DSwapChain9Impl
*)iface
;
123 TRACE("(%p) Relay\n", This
);
125 wined3d_mutex_lock();
126 hr
= IWineD3DSwapChain_GetRasterStatus(This
->wineD3DSwapChain
, (WINED3DRASTER_STATUS
*) pRasterStatus
);
127 wined3d_mutex_unlock();
132 static HRESULT WINAPI
IDirect3DSwapChain9Impl_GetDisplayMode(LPDIRECT3DSWAPCHAIN9 iface
, D3DDISPLAYMODE
* pMode
) {
133 IDirect3DSwapChain9Impl
*This
= (IDirect3DSwapChain9Impl
*)iface
;
135 TRACE("(%p) Relay\n", This
);
137 wined3d_mutex_lock();
138 hr
= IWineD3DSwapChain_GetDisplayMode(This
->wineD3DSwapChain
, (WINED3DDISPLAYMODE
*) pMode
);
139 wined3d_mutex_unlock();
141 if (SUCCEEDED(hr
)) pMode
->Format
= d3dformat_from_wined3dformat(pMode
->Format
);
146 static HRESULT WINAPI
IDirect3DSwapChain9Impl_GetDevice(LPDIRECT3DSWAPCHAIN9 iface
, IDirect3DDevice9
** ppDevice
) {
147 IDirect3DSwapChain9Impl
*This
= (IDirect3DSwapChain9Impl
*)iface
;
148 HRESULT hrc
= D3D_OK
;
149 IWineD3DDevice
*device
= NULL
;
151 TRACE("(%p) Relay\n", This
);
153 wined3d_mutex_lock();
154 hrc
= IWineD3DSwapChain_GetDevice(This
->wineD3DSwapChain
, &device
);
155 if (hrc
== D3D_OK
&& NULL
!= device
) {
156 IWineD3DDevice_GetParent(device
, (IUnknown
**)ppDevice
);
157 IWineD3DDevice_Release(device
);
159 wined3d_mutex_unlock();
164 static HRESULT WINAPI
IDirect3DSwapChain9Impl_GetPresentParameters(LPDIRECT3DSWAPCHAIN9 iface
, D3DPRESENT_PARAMETERS
* pPresentationParameters
) {
165 IDirect3DSwapChain9Impl
*This
= (IDirect3DSwapChain9Impl
*)iface
;
166 WINED3DPRESENT_PARAMETERS winePresentParameters
;
169 TRACE("(%p)->(%p): Relay\n", This
, pPresentationParameters
);
171 wined3d_mutex_lock();
172 hr
= IWineD3DSwapChain_GetPresentParameters(This
->wineD3DSwapChain
, &winePresentParameters
);
173 wined3d_mutex_unlock();
175 pPresentationParameters
->BackBufferWidth
= winePresentParameters
.BackBufferWidth
;
176 pPresentationParameters
->BackBufferHeight
= winePresentParameters
.BackBufferHeight
;
177 pPresentationParameters
->BackBufferFormat
= d3dformat_from_wined3dformat(winePresentParameters
.BackBufferFormat
);
178 pPresentationParameters
->BackBufferCount
= winePresentParameters
.BackBufferCount
;
179 pPresentationParameters
->MultiSampleType
= winePresentParameters
.MultiSampleType
;
180 pPresentationParameters
->MultiSampleQuality
= winePresentParameters
.MultiSampleQuality
;
181 pPresentationParameters
->SwapEffect
= winePresentParameters
.SwapEffect
;
182 pPresentationParameters
->hDeviceWindow
= winePresentParameters
.hDeviceWindow
;
183 pPresentationParameters
->Windowed
= winePresentParameters
.Windowed
;
184 pPresentationParameters
->EnableAutoDepthStencil
= winePresentParameters
.EnableAutoDepthStencil
;
185 pPresentationParameters
->AutoDepthStencilFormat
= d3dformat_from_wined3dformat(winePresentParameters
.AutoDepthStencilFormat
);
186 pPresentationParameters
->Flags
= winePresentParameters
.Flags
;
187 pPresentationParameters
->FullScreen_RefreshRateInHz
= winePresentParameters
.FullScreen_RefreshRateInHz
;
188 pPresentationParameters
->PresentationInterval
= winePresentParameters
.PresentationInterval
;
194 static const IDirect3DSwapChain9Vtbl Direct3DSwapChain9_Vtbl
=
196 IDirect3DSwapChain9Impl_QueryInterface
,
197 IDirect3DSwapChain9Impl_AddRef
,
198 IDirect3DSwapChain9Impl_Release
,
199 IDirect3DSwapChain9Impl_Present
,
200 IDirect3DSwapChain9Impl_GetFrontBufferData
,
201 IDirect3DSwapChain9Impl_GetBackBuffer
,
202 IDirect3DSwapChain9Impl_GetRasterStatus
,
203 IDirect3DSwapChain9Impl_GetDisplayMode
,
204 IDirect3DSwapChain9Impl_GetDevice
,
205 IDirect3DSwapChain9Impl_GetPresentParameters
209 /* IDirect3DDevice9 IDirect3DSwapChain9 Methods follow: */
210 HRESULT WINAPI
IDirect3DDevice9Impl_CreateAdditionalSwapChain(LPDIRECT3DDEVICE9EX iface
, D3DPRESENT_PARAMETERS
* pPresentationParameters
, IDirect3DSwapChain9
** pSwapChain
) {
211 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
212 IDirect3DSwapChain9Impl
* object
;
213 HRESULT hrc
= D3D_OK
;
214 WINED3DPRESENT_PARAMETERS localParameters
;
216 TRACE("(%p) Relay\n", This
);
218 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
219 if (NULL
== object
) {
220 FIXME("Allocation of memory failed, returning D3DERR_OUTOFVIDEOMEMORY\n");
221 return D3DERR_OUTOFVIDEOMEMORY
;
224 object
->lpVtbl
= &Direct3DSwapChain9_Vtbl
;
226 /* The back buffer count is set to one if it's 0 */
227 if(pPresentationParameters
->BackBufferCount
== 0) {
228 pPresentationParameters
->BackBufferCount
= 1;
231 /* Allocate an associated WineD3DDevice object */
232 localParameters
.BackBufferWidth
= pPresentationParameters
->BackBufferWidth
;
233 localParameters
.BackBufferHeight
= pPresentationParameters
->BackBufferHeight
;
234 localParameters
.BackBufferFormat
= wined3dformat_from_d3dformat(pPresentationParameters
->BackBufferFormat
);
235 localParameters
.BackBufferCount
= pPresentationParameters
->BackBufferCount
;
236 localParameters
.MultiSampleType
= pPresentationParameters
->MultiSampleType
;
237 localParameters
.MultiSampleQuality
= pPresentationParameters
->MultiSampleQuality
;
238 localParameters
.SwapEffect
= pPresentationParameters
->SwapEffect
;
239 localParameters
.hDeviceWindow
= pPresentationParameters
->hDeviceWindow
;
240 localParameters
.Windowed
= pPresentationParameters
->Windowed
;
241 localParameters
.EnableAutoDepthStencil
= pPresentationParameters
->EnableAutoDepthStencil
;
242 localParameters
.AutoDepthStencilFormat
= wined3dformat_from_d3dformat(pPresentationParameters
->AutoDepthStencilFormat
);
243 localParameters
.Flags
= pPresentationParameters
->Flags
;
244 localParameters
.FullScreen_RefreshRateInHz
= pPresentationParameters
->FullScreen_RefreshRateInHz
;
245 localParameters
.PresentationInterval
= pPresentationParameters
->PresentationInterval
;
246 localParameters
.AutoRestoreDisplayMode
= TRUE
;
248 wined3d_mutex_lock();
249 hrc
= IWineD3DDevice_CreateSwapChain(This
->WineD3DDevice
, &localParameters
,
250 &object
->wineD3DSwapChain
, (IUnknown
*)object
, SURFACE_OPENGL
);
251 wined3d_mutex_unlock();
253 pPresentationParameters
->BackBufferWidth
= localParameters
.BackBufferWidth
;
254 pPresentationParameters
->BackBufferHeight
= localParameters
.BackBufferHeight
;
255 pPresentationParameters
->BackBufferFormat
= d3dformat_from_wined3dformat(localParameters
.BackBufferFormat
);
256 pPresentationParameters
->BackBufferCount
= localParameters
.BackBufferCount
;
257 pPresentationParameters
->MultiSampleType
= localParameters
.MultiSampleType
;
258 pPresentationParameters
->MultiSampleQuality
= localParameters
.MultiSampleQuality
;
259 pPresentationParameters
->SwapEffect
= localParameters
.SwapEffect
;
260 pPresentationParameters
->hDeviceWindow
= localParameters
.hDeviceWindow
;
261 pPresentationParameters
->Windowed
= localParameters
.Windowed
;
262 pPresentationParameters
->EnableAutoDepthStencil
= localParameters
.EnableAutoDepthStencil
;
263 pPresentationParameters
->AutoDepthStencilFormat
= d3dformat_from_wined3dformat(localParameters
.AutoDepthStencilFormat
);
264 pPresentationParameters
->Flags
= localParameters
.Flags
;
265 pPresentationParameters
->FullScreen_RefreshRateInHz
= localParameters
.FullScreen_RefreshRateInHz
;
266 pPresentationParameters
->PresentationInterval
= localParameters
.PresentationInterval
;
269 FIXME("(%p) call to IWineD3DDevice_CreateSwapChain failed\n", This
);
270 HeapFree(GetProcessHeap(), 0 , object
);
272 IDirect3DDevice9Ex_AddRef(iface
);
273 object
->parentDevice
= iface
;
274 *pSwapChain
= (IDirect3DSwapChain9
*)object
;
275 TRACE("(%p) : Created swapchain %p\n", This
, *pSwapChain
);
277 TRACE("(%p) returning %p\n", This
, *pSwapChain
);
281 HRESULT WINAPI
IDirect3DDevice9Impl_GetSwapChain(LPDIRECT3DDEVICE9EX iface
, UINT iSwapChain
, IDirect3DSwapChain9
** pSwapChain
) {
282 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
283 HRESULT hrc
= D3D_OK
;
284 IWineD3DSwapChain
*swapchain
= NULL
;
286 TRACE("(%p) Relay\n", This
);
288 wined3d_mutex_lock();
289 hrc
= IWineD3DDevice_GetSwapChain(This
->WineD3DDevice
, iSwapChain
, &swapchain
);
290 if (hrc
== D3D_OK
&& NULL
!= swapchain
) {
291 IWineD3DSwapChain_GetParent(swapchain
, (IUnknown
**)pSwapChain
);
292 IWineD3DSwapChain_Release(swapchain
);
296 wined3d_mutex_unlock();
301 UINT WINAPI
IDirect3DDevice9Impl_GetNumberOfSwapChains(LPDIRECT3DDEVICE9EX iface
) {
302 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
304 TRACE("(%p) Relay\n", This
);
306 wined3d_mutex_lock();
307 ret
= IWineD3DDevice_GetNumberOfSwapChains(This
->WineD3DDevice
);
308 wined3d_mutex_unlock();