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 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), ppobj
);
35 if (IsEqualGUID(riid
, &IID_IUnknown
)
36 || IsEqualGUID(riid
, &IID_IDirect3DSwapChain9
)) {
37 IDirect3DSwapChain9_AddRef(iface
);
42 WARN("(%p)->(%s,%p),not found\n", This
, debugstr_guid(riid
), ppobj
);
47 static ULONG WINAPI
IDirect3DSwapChain9Impl_AddRef(LPDIRECT3DSWAPCHAIN9 iface
) {
48 IDirect3DSwapChain9Impl
*This
= (IDirect3DSwapChain9Impl
*)iface
;
49 ULONG ref
= InterlockedIncrement(&This
->ref
);
51 TRACE("%p increasing refcount to %u.\n", iface
, ref
);
55 if (This
->parentDevice
)
56 IDirect3DDevice9Ex_AddRef(This
->parentDevice
);
59 wined3d_swapchain_incref(This
->wined3d_swapchain
);
60 wined3d_mutex_unlock();
66 static ULONG WINAPI
IDirect3DSwapChain9Impl_Release(LPDIRECT3DSWAPCHAIN9 iface
) {
67 IDirect3DSwapChain9Impl
*This
= (IDirect3DSwapChain9Impl
*)iface
;
68 ULONG ref
= InterlockedDecrement(&This
->ref
);
70 TRACE("%p decreasing refcount to %u.\n", iface
, ref
);
73 IDirect3DDevice9Ex
*parentDevice
= This
->parentDevice
;
76 wined3d_swapchain_decref(This
->wined3d_swapchain
);
77 wined3d_mutex_unlock();
79 /* Release the device last, as it may cause the device to be destroyed. */
80 if (parentDevice
) IDirect3DDevice9Ex_Release(parentDevice
);
85 /* IDirect3DSwapChain9 parts follow: */
86 static HRESULT WINAPI DECLSPEC_HOTPATCH
IDirect3DSwapChain9Impl_Present(LPDIRECT3DSWAPCHAIN9 iface
, CONST RECT
* pSourceRect
, CONST RECT
* pDestRect
, HWND hDestWindowOverride
, CONST RGNDATA
* pDirtyRegion
, DWORD dwFlags
) {
87 IDirect3DSwapChain9Impl
*This
= (IDirect3DSwapChain9Impl
*)iface
;
90 TRACE("iface %p, src_rect %p, dst_rect %p, dst_window_override %p, dirty_region %p, flags %#x.\n",
91 iface
, pSourceRect
, pDestRect
, hDestWindowOverride
, pDirtyRegion
, dwFlags
);
94 hr
= wined3d_swapchain_present(This
->wined3d_swapchain
, pSourceRect
,
95 pDestRect
, hDestWindowOverride
, pDirtyRegion
, dwFlags
);
96 wined3d_mutex_unlock();
101 static HRESULT WINAPI
IDirect3DSwapChain9Impl_GetFrontBufferData(LPDIRECT3DSWAPCHAIN9 iface
, IDirect3DSurface9
* pDestSurface
) {
102 IDirect3DSwapChain9Impl
*This
= (IDirect3DSwapChain9Impl
*)iface
;
105 TRACE("iface %p, surface %p.\n", iface
, pDestSurface
);
107 wined3d_mutex_lock();
108 hr
= wined3d_swapchain_get_front_buffer_data(This
->wined3d_swapchain
,
109 ((IDirect3DSurface9Impl
*)pDestSurface
)->wined3d_surface
);
110 wined3d_mutex_unlock();
115 static HRESULT WINAPI
IDirect3DSwapChain9Impl_GetBackBuffer(IDirect3DSwapChain9
*iface
,
116 UINT iBackBuffer
, D3DBACKBUFFER_TYPE Type
, IDirect3DSurface9
**ppBackBuffer
)
118 IDirect3DSwapChain9Impl
*This
= (IDirect3DSwapChain9Impl
*)iface
;
119 struct wined3d_surface
*wined3d_surface
= NULL
;
122 TRACE("iface %p, backbuffer_idx %u, backbuffer_type %#x, backbuffer %p.\n",
123 iface
, iBackBuffer
, Type
, ppBackBuffer
);
125 wined3d_mutex_lock();
126 hr
= wined3d_swapchain_get_back_buffer(This
->wined3d_swapchain
,
127 iBackBuffer
, (WINED3DBACKBUFFER_TYPE
)Type
, &wined3d_surface
);
128 if (SUCCEEDED(hr
) && wined3d_surface
)
130 *ppBackBuffer
= wined3d_surface_get_parent(wined3d_surface
);
131 IDirect3DSurface9_AddRef(*ppBackBuffer
);
132 wined3d_surface_decref(wined3d_surface
);
134 wined3d_mutex_unlock();
136 /* Do not touch the **ppBackBuffer pointer otherwise! (see device test) */
140 static HRESULT WINAPI
IDirect3DSwapChain9Impl_GetRasterStatus(LPDIRECT3DSWAPCHAIN9 iface
, D3DRASTER_STATUS
* pRasterStatus
) {
141 IDirect3DSwapChain9Impl
*This
= (IDirect3DSwapChain9Impl
*)iface
;
144 TRACE("iface %p, raster_status %p.\n", iface
, pRasterStatus
);
146 wined3d_mutex_lock();
147 hr
= wined3d_swapchain_get_raster_status(This
->wined3d_swapchain
, (WINED3DRASTER_STATUS
*)pRasterStatus
);
148 wined3d_mutex_unlock();
153 static HRESULT WINAPI
IDirect3DSwapChain9Impl_GetDisplayMode(LPDIRECT3DSWAPCHAIN9 iface
, D3DDISPLAYMODE
* pMode
) {
154 IDirect3DSwapChain9Impl
*This
= (IDirect3DSwapChain9Impl
*)iface
;
157 TRACE("iface %p, mode %p.\n", iface
, pMode
);
159 wined3d_mutex_lock();
160 hr
= wined3d_swapchain_get_display_mode(This
->wined3d_swapchain
, (WINED3DDISPLAYMODE
*)pMode
);
161 wined3d_mutex_unlock();
163 if (SUCCEEDED(hr
)) pMode
->Format
= d3dformat_from_wined3dformat(pMode
->Format
);
168 static HRESULT WINAPI
IDirect3DSwapChain9Impl_GetDevice(IDirect3DSwapChain9
*iface
, IDirect3DDevice9
**device
)
170 IDirect3DSwapChain9Impl
*This
= (IDirect3DSwapChain9Impl
*)iface
;
172 TRACE("iface %p, device %p.\n", iface
, device
);
174 *device
= (IDirect3DDevice9
*)This
->parentDevice
;
175 IDirect3DDevice9_AddRef(*device
);
177 TRACE("Returning device %p.\n", *device
);
182 static HRESULT WINAPI
IDirect3DSwapChain9Impl_GetPresentParameters(LPDIRECT3DSWAPCHAIN9 iface
, D3DPRESENT_PARAMETERS
* pPresentationParameters
) {
183 IDirect3DSwapChain9Impl
*This
= (IDirect3DSwapChain9Impl
*)iface
;
184 WINED3DPRESENT_PARAMETERS winePresentParameters
;
187 TRACE("iface %p, parameters %p.\n", iface
, pPresentationParameters
);
189 wined3d_mutex_lock();
190 hr
= wined3d_swapchain_get_present_parameters(This
->wined3d_swapchain
, &winePresentParameters
);
191 wined3d_mutex_unlock();
193 pPresentationParameters
->BackBufferWidth
= winePresentParameters
.BackBufferWidth
;
194 pPresentationParameters
->BackBufferHeight
= winePresentParameters
.BackBufferHeight
;
195 pPresentationParameters
->BackBufferFormat
= d3dformat_from_wined3dformat(winePresentParameters
.BackBufferFormat
);
196 pPresentationParameters
->BackBufferCount
= winePresentParameters
.BackBufferCount
;
197 pPresentationParameters
->MultiSampleType
= winePresentParameters
.MultiSampleType
;
198 pPresentationParameters
->MultiSampleQuality
= winePresentParameters
.MultiSampleQuality
;
199 pPresentationParameters
->SwapEffect
= winePresentParameters
.SwapEffect
;
200 pPresentationParameters
->hDeviceWindow
= winePresentParameters
.hDeviceWindow
;
201 pPresentationParameters
->Windowed
= winePresentParameters
.Windowed
;
202 pPresentationParameters
->EnableAutoDepthStencil
= winePresentParameters
.EnableAutoDepthStencil
;
203 pPresentationParameters
->AutoDepthStencilFormat
= d3dformat_from_wined3dformat(winePresentParameters
.AutoDepthStencilFormat
);
204 pPresentationParameters
->Flags
= winePresentParameters
.Flags
;
205 pPresentationParameters
->FullScreen_RefreshRateInHz
= winePresentParameters
.FullScreen_RefreshRateInHz
;
206 pPresentationParameters
->PresentationInterval
= winePresentParameters
.PresentationInterval
;
212 static const IDirect3DSwapChain9Vtbl Direct3DSwapChain9_Vtbl
=
214 IDirect3DSwapChain9Impl_QueryInterface
,
215 IDirect3DSwapChain9Impl_AddRef
,
216 IDirect3DSwapChain9Impl_Release
,
217 IDirect3DSwapChain9Impl_Present
,
218 IDirect3DSwapChain9Impl_GetFrontBufferData
,
219 IDirect3DSwapChain9Impl_GetBackBuffer
,
220 IDirect3DSwapChain9Impl_GetRasterStatus
,
221 IDirect3DSwapChain9Impl_GetDisplayMode
,
222 IDirect3DSwapChain9Impl_GetDevice
,
223 IDirect3DSwapChain9Impl_GetPresentParameters
226 static void STDMETHODCALLTYPE
d3d9_swapchain_wined3d_object_released(void *parent
)
228 HeapFree(GetProcessHeap(), 0, parent
);
231 static const struct wined3d_parent_ops d3d9_swapchain_wined3d_parent_ops
=
233 d3d9_swapchain_wined3d_object_released
,
236 HRESULT
swapchain_init(IDirect3DSwapChain9Impl
*swapchain
, IDirect3DDevice9Impl
*device
,
237 D3DPRESENT_PARAMETERS
*present_parameters
)
239 WINED3DPRESENT_PARAMETERS wined3d_parameters
;
243 swapchain
->lpVtbl
= &Direct3DSwapChain9_Vtbl
;
245 wined3d_parameters
.BackBufferWidth
= present_parameters
->BackBufferWidth
;
246 wined3d_parameters
.BackBufferHeight
= present_parameters
->BackBufferHeight
;
247 wined3d_parameters
.BackBufferFormat
= wined3dformat_from_d3dformat(present_parameters
->BackBufferFormat
);
248 wined3d_parameters
.BackBufferCount
= max(1, present_parameters
->BackBufferCount
);
249 wined3d_parameters
.MultiSampleType
= present_parameters
->MultiSampleType
;
250 wined3d_parameters
.MultiSampleQuality
= present_parameters
->MultiSampleQuality
;
251 wined3d_parameters
.SwapEffect
= present_parameters
->SwapEffect
;
252 wined3d_parameters
.hDeviceWindow
= present_parameters
->hDeviceWindow
;
253 wined3d_parameters
.Windowed
= present_parameters
->Windowed
;
254 wined3d_parameters
.EnableAutoDepthStencil
= present_parameters
->EnableAutoDepthStencil
;
255 wined3d_parameters
.AutoDepthStencilFormat
= wined3dformat_from_d3dformat(present_parameters
->AutoDepthStencilFormat
);
256 wined3d_parameters
.Flags
= present_parameters
->Flags
;
257 wined3d_parameters
.FullScreen_RefreshRateInHz
= present_parameters
->FullScreen_RefreshRateInHz
;
258 wined3d_parameters
.PresentationInterval
= present_parameters
->PresentationInterval
;
259 wined3d_parameters
.AutoRestoreDisplayMode
= TRUE
;
261 wined3d_mutex_lock();
262 hr
= wined3d_swapchain_create(device
->wined3d_device
, &wined3d_parameters
,
263 SURFACE_OPENGL
, swapchain
, &d3d9_swapchain_wined3d_parent_ops
,
264 &swapchain
->wined3d_swapchain
);
265 wined3d_mutex_unlock();
267 present_parameters
->BackBufferWidth
= wined3d_parameters
.BackBufferWidth
;
268 present_parameters
->BackBufferHeight
= wined3d_parameters
.BackBufferHeight
;
269 present_parameters
->BackBufferFormat
= d3dformat_from_wined3dformat(wined3d_parameters
.BackBufferFormat
);
270 present_parameters
->BackBufferCount
= wined3d_parameters
.BackBufferCount
;
271 present_parameters
->MultiSampleType
= wined3d_parameters
.MultiSampleType
;
272 present_parameters
->MultiSampleQuality
= wined3d_parameters
.MultiSampleQuality
;
273 present_parameters
->SwapEffect
= wined3d_parameters
.SwapEffect
;
274 present_parameters
->hDeviceWindow
= wined3d_parameters
.hDeviceWindow
;
275 present_parameters
->Windowed
= wined3d_parameters
.Windowed
;
276 present_parameters
->EnableAutoDepthStencil
= wined3d_parameters
.EnableAutoDepthStencil
;
277 present_parameters
->AutoDepthStencilFormat
= d3dformat_from_wined3dformat(wined3d_parameters
.AutoDepthStencilFormat
);
278 present_parameters
->Flags
= wined3d_parameters
.Flags
;
279 present_parameters
->FullScreen_RefreshRateInHz
= wined3d_parameters
.FullScreen_RefreshRateInHz
;
280 present_parameters
->PresentationInterval
= wined3d_parameters
.PresentationInterval
;
284 WARN("Failed to create wined3d swapchain, hr %#x.\n", hr
);
288 swapchain
->parentDevice
= &device
->IDirect3DDevice9Ex_iface
;
289 IDirect3DDevice9Ex_AddRef(swapchain
->parentDevice
);