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);
58 if (!This->isImplicit)
61 IWineD3DSwapChain_AddRef(This->wineD3DSwapChain);
62 wined3d_mutex_unlock();
69 static ULONG WINAPI IDirect3DSwapChain9Impl_Release(LPDIRECT3DSWAPCHAIN9 iface) {
70 IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
71 ULONG ref = InterlockedDecrement(&This->ref);
73 TRACE("%p decreasing refcount to %u.\n", iface, ref);
76 IDirect3DDevice9Ex *parentDevice = This->parentDevice;
78 if (!This->isImplicit) {
80 IWineD3DSwapChain_Destroy(This->wineD3DSwapChain);
81 wined3d_mutex_unlock();
84 /* Release the device last, as it may cause the device to be destroyed. */
85 if (parentDevice) IDirect3DDevice9Ex_Release(parentDevice);
90 /* IDirect3DSwapChain9 parts follow: */
91 static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DSwapChain9Impl_Present(LPDIRECT3DSWAPCHAIN9 iface, CONST RECT* pSourceRect, CONST RECT* pDestRect, HWND hDestWindowOverride, CONST RGNDATA* pDirtyRegion, DWORD dwFlags) {
92 IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
95 TRACE("iface %p, src_rect %p, dst_rect %p, dst_window_override %p, dirty_region %p, flags %#x.\n",
96 iface, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion, dwFlags);
99 hr = IWineD3DSwapChain_Present(This->wineD3DSwapChain, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion, dwFlags);
100 wined3d_mutex_unlock();
105 static HRESULT WINAPI IDirect3DSwapChain9Impl_GetFrontBufferData(LPDIRECT3DSWAPCHAIN9 iface, IDirect3DSurface9* pDestSurface) {
106 IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
109 TRACE("iface %p, surface %p.\n", iface, pDestSurface);
111 wined3d_mutex_lock();
112 hr = IWineD3DSwapChain_GetFrontBufferData(This->wineD3DSwapChain, ((IDirect3DSurface9Impl *)pDestSurface)->wineD3DSurface);
113 wined3d_mutex_unlock();
118 static HRESULT WINAPI IDirect3DSwapChain9Impl_GetBackBuffer(IDirect3DSwapChain9 *iface,
119 UINT iBackBuffer, D3DBACKBUFFER_TYPE Type, IDirect3DSurface9 **ppBackBuffer)
121 IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
122 IWineD3DSurface *mySurface = NULL;
125 TRACE("iface %p, backbuffer_idx %u, backbuffer_type %#x, backbuffer %p.\n",
126 iface, iBackBuffer, Type, ppBackBuffer);
128 wined3d_mutex_lock();
129 hr = IWineD3DSwapChain_GetBackBuffer(This->wineD3DSwapChain, iBackBuffer,
130 (WINED3DBACKBUFFER_TYPE)Type, &mySurface);
131 if (SUCCEEDED(hr) && mySurface)
133 *ppBackBuffer = IWineD3DSurface_GetParent(mySurface);
134 IDirect3DSurface9_AddRef(*ppBackBuffer);
135 IWineD3DSurface_Release(mySurface);
137 wined3d_mutex_unlock();
139 /* Do not touch the **ppBackBuffer pointer otherwise! (see device test) */
143 static HRESULT WINAPI IDirect3DSwapChain9Impl_GetRasterStatus(LPDIRECT3DSWAPCHAIN9 iface, D3DRASTER_STATUS* pRasterStatus) {
144 IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
147 TRACE("iface %p, raster_status %p.\n", iface, pRasterStatus);
149 wined3d_mutex_lock();
150 hr = IWineD3DSwapChain_GetRasterStatus(This->wineD3DSwapChain, (WINED3DRASTER_STATUS *) pRasterStatus);
151 wined3d_mutex_unlock();
156 static HRESULT WINAPI IDirect3DSwapChain9Impl_GetDisplayMode(LPDIRECT3DSWAPCHAIN9 iface, D3DDISPLAYMODE* pMode) {
157 IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
160 TRACE("iface %p, mode %p.\n", iface, pMode);
162 wined3d_mutex_lock();
163 hr = IWineD3DSwapChain_GetDisplayMode(This->wineD3DSwapChain, (WINED3DDISPLAYMODE *) pMode);
164 wined3d_mutex_unlock();
166 if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format);
171 static HRESULT WINAPI IDirect3DSwapChain9Impl_GetDevice(IDirect3DSwapChain9 *iface, IDirect3DDevice9 **device)
173 IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
175 TRACE("iface %p, device %p.\n", iface, device);
177 *device = (IDirect3DDevice9 *)This->parentDevice;
178 IDirect3DDevice9_AddRef(*device);
180 TRACE("Returning device %p.\n", *device);
185 static HRESULT WINAPI IDirect3DSwapChain9Impl_GetPresentParameters(LPDIRECT3DSWAPCHAIN9 iface, D3DPRESENT_PARAMETERS* pPresentationParameters) {
186 IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
187 WINED3DPRESENT_PARAMETERS winePresentParameters;
190 TRACE("iface %p, parameters %p.\n", iface, pPresentationParameters);
192 wined3d_mutex_lock();
193 hr = IWineD3DSwapChain_GetPresentParameters(This->wineD3DSwapChain, &winePresentParameters);
194 wined3d_mutex_unlock();
196 pPresentationParameters->BackBufferWidth = winePresentParameters.BackBufferWidth;
197 pPresentationParameters->BackBufferHeight = winePresentParameters.BackBufferHeight;
198 pPresentationParameters->BackBufferFormat = d3dformat_from_wined3dformat(winePresentParameters.BackBufferFormat);
199 pPresentationParameters->BackBufferCount = winePresentParameters.BackBufferCount;
200 pPresentationParameters->MultiSampleType = winePresentParameters.MultiSampleType;
201 pPresentationParameters->MultiSampleQuality = winePresentParameters.MultiSampleQuality;
202 pPresentationParameters->SwapEffect = winePresentParameters.SwapEffect;
203 pPresentationParameters->hDeviceWindow = winePresentParameters.hDeviceWindow;
204 pPresentationParameters->Windowed = winePresentParameters.Windowed;
205 pPresentationParameters->EnableAutoDepthStencil = winePresentParameters.EnableAutoDepthStencil;
206 pPresentationParameters->AutoDepthStencilFormat = d3dformat_from_wined3dformat(winePresentParameters.AutoDepthStencilFormat);
207 pPresentationParameters->Flags = winePresentParameters.Flags;
208 pPresentationParameters->FullScreen_RefreshRateInHz = winePresentParameters.FullScreen_RefreshRateInHz;
209 pPresentationParameters->PresentationInterval = winePresentParameters.PresentationInterval;
215 static const IDirect3DSwapChain9Vtbl Direct3DSwapChain9_Vtbl =
217 IDirect3DSwapChain9Impl_QueryInterface,
218 IDirect3DSwapChain9Impl_AddRef,
219 IDirect3DSwapChain9Impl_Release,
220 IDirect3DSwapChain9Impl_Present,
221 IDirect3DSwapChain9Impl_GetFrontBufferData,
222 IDirect3DSwapChain9Impl_GetBackBuffer,
223 IDirect3DSwapChain9Impl_GetRasterStatus,
224 IDirect3DSwapChain9Impl_GetDisplayMode,
225 IDirect3DSwapChain9Impl_GetDevice,
226 IDirect3DSwapChain9Impl_GetPresentParameters
229 static void STDMETHODCALLTYPE d3d9_swapchain_wined3d_object_released(void *parent)
231 HeapFree(GetProcessHeap(), 0, parent);
234 static const struct wined3d_parent_ops d3d9_swapchain_wined3d_parent_ops =
236 d3d9_swapchain_wined3d_object_released,
239 HRESULT swapchain_init(IDirect3DSwapChain9Impl *swapchain, IDirect3DDevice9Impl *device,
240 D3DPRESENT_PARAMETERS *present_parameters)
242 WINED3DPRESENT_PARAMETERS wined3d_parameters;
246 swapchain->lpVtbl = &Direct3DSwapChain9_Vtbl;
248 wined3d_parameters.BackBufferWidth = present_parameters->BackBufferWidth;
249 wined3d_parameters.BackBufferHeight = present_parameters->BackBufferHeight;
250 wined3d_parameters.BackBufferFormat = wined3dformat_from_d3dformat(present_parameters->BackBufferFormat);
251 wined3d_parameters.BackBufferCount = max(1, present_parameters->BackBufferCount);
252 wined3d_parameters.MultiSampleType = present_parameters->MultiSampleType;
253 wined3d_parameters.MultiSampleQuality = present_parameters->MultiSampleQuality;
254 wined3d_parameters.SwapEffect = present_parameters->SwapEffect;
255 wined3d_parameters.hDeviceWindow = present_parameters->hDeviceWindow;
256 wined3d_parameters.Windowed = present_parameters->Windowed;
257 wined3d_parameters.EnableAutoDepthStencil = present_parameters->EnableAutoDepthStencil;
258 wined3d_parameters.AutoDepthStencilFormat = wined3dformat_from_d3dformat(present_parameters->AutoDepthStencilFormat);
259 wined3d_parameters.Flags = present_parameters->Flags;
260 wined3d_parameters.FullScreen_RefreshRateInHz = present_parameters->FullScreen_RefreshRateInHz;
261 wined3d_parameters.PresentationInterval = present_parameters->PresentationInterval;
262 wined3d_parameters.AutoRestoreDisplayMode = TRUE;
264 wined3d_mutex_lock();
265 hr = IWineD3DDevice_CreateSwapChain(device->WineD3DDevice, &wined3d_parameters,
266 SURFACE_OPENGL, swapchain, &d3d9_swapchain_wined3d_parent_ops,
267 &swapchain->wineD3DSwapChain);
268 wined3d_mutex_unlock();
270 present_parameters->BackBufferWidth = wined3d_parameters.BackBufferWidth;
271 present_parameters->BackBufferHeight = wined3d_parameters.BackBufferHeight;
272 present_parameters->BackBufferFormat = d3dformat_from_wined3dformat(wined3d_parameters.BackBufferFormat);
273 present_parameters->BackBufferCount = wined3d_parameters.BackBufferCount;
274 present_parameters->MultiSampleType = wined3d_parameters.MultiSampleType;
275 present_parameters->MultiSampleQuality = wined3d_parameters.MultiSampleQuality;
276 present_parameters->SwapEffect = wined3d_parameters.SwapEffect;
277 present_parameters->hDeviceWindow = wined3d_parameters.hDeviceWindow;
278 present_parameters->Windowed = wined3d_parameters.Windowed;
279 present_parameters->EnableAutoDepthStencil = wined3d_parameters.EnableAutoDepthStencil;
280 present_parameters->AutoDepthStencilFormat = d3dformat_from_wined3dformat(wined3d_parameters.AutoDepthStencilFormat);
281 present_parameters->Flags = wined3d_parameters.Flags;
282 present_parameters->FullScreen_RefreshRateInHz = wined3d_parameters.FullScreen_RefreshRateInHz;
283 present_parameters->PresentationInterval = wined3d_parameters.PresentationInterval;
287 WARN("Failed to create wined3d swapchain, hr %#x.\n", hr);
291 swapchain->parentDevice = (IDirect3DDevice9Ex *)device;
292 IDirect3DDevice9Ex_AddRef(swapchain->parentDevice);