VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/swapchain.c@ 33656

Last change on this file since 33656 was 33656, checked in by vboxsync, 14 years ago

*: rebrand Sun (L)GPL disclaimers

  • Property svn:eol-style set to native
File size: 13.1 KB
Line 
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/*
24 * Oracle LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
25 * other than GPL or LGPL is available it will apply instead, Oracle elects to use only
26 * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
27 * a choice of LGPL license versions is made available with the language indicating
28 * that LGPLv2 or any later version may be used, or where a choice of which version
29 * of the LGPL is applied is otherwise unspecified.
30 */
31
32#include "config.h"
33#include "d3d9_private.h"
34
35WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
36
37/* IDirect3DSwapChain IUnknown parts follow: */
38static HRESULT WINAPI IDirect3DSwapChain9Impl_QueryInterface(LPDIRECT3DSWAPCHAIN9 iface, REFIID riid, LPVOID* ppobj)
39{
40 IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
41
42 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
43
44 if (IsEqualGUID(riid, &IID_IUnknown)
45 || IsEqualGUID(riid, &IID_IDirect3DSwapChain9)) {
46 IDirect3DSwapChain9_AddRef(iface);
47 *ppobj = This;
48 return S_OK;
49 }
50
51 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
52 *ppobj = NULL;
53 return E_NOINTERFACE;
54}
55
56static ULONG WINAPI IDirect3DSwapChain9Impl_AddRef(LPDIRECT3DSWAPCHAIN9 iface) {
57 IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
58 ULONG ref = InterlockedIncrement(&This->ref);
59
60 TRACE("%p increasing refcount to %u.\n", iface, ref);
61
62 if(ref == 1 && This->parentDevice) IDirect3DDevice9Ex_AddRef(This->parentDevice);
63
64 return ref;
65}
66
67static ULONG WINAPI IDirect3DSwapChain9Impl_Release(LPDIRECT3DSWAPCHAIN9 iface) {
68 IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
69 ULONG ref = InterlockedDecrement(&This->ref);
70
71 TRACE("%p decreasing refcount to %u.\n", iface, ref);
72
73 if (ref == 0) {
74 IDirect3DDevice9Ex *parentDevice = This->parentDevice;
75
76 if (!This->isImplicit) {
77 wined3d_mutex_lock();
78 IWineD3DSwapChain_Destroy(This->wineD3DSwapChain);
79 wined3d_mutex_unlock();
80
81 HeapFree(GetProcessHeap(), 0, This);
82 }
83
84 /* Release the device last, as it may cause the device to be destroyed. */
85 if (parentDevice) IDirect3DDevice9Ex_Release(parentDevice);
86 }
87 return ref;
88}
89
90/* IDirect3DSwapChain9 parts follow: */
91static 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;
93 HRESULT hr;
94
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);
97
98 wined3d_mutex_lock();
99 hr = IWineD3DSwapChain_Present(This->wineD3DSwapChain, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion, dwFlags);
100 wined3d_mutex_unlock();
101
102 return hr;
103}
104
105static HRESULT WINAPI IDirect3DSwapChain9Impl_GetFrontBufferData(LPDIRECT3DSWAPCHAIN9 iface, IDirect3DSurface9* pDestSurface) {
106 IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
107 HRESULT hr;
108
109 TRACE("iface %p, surface %p.\n", iface, pDestSurface);
110
111 wined3d_mutex_lock();
112 hr = IWineD3DSwapChain_GetFrontBufferData(This->wineD3DSwapChain, ((IDirect3DSurface9Impl *)pDestSurface)->wineD3DSurface);
113 wined3d_mutex_unlock();
114
115 return hr;
116}
117
118static HRESULT WINAPI IDirect3DSwapChain9Impl_GetBackBuffer(LPDIRECT3DSWAPCHAIN9 iface, UINT iBackBuffer, D3DBACKBUFFER_TYPE Type, IDirect3DSurface9** ppBackBuffer) {
119 IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
120 HRESULT hrc = D3D_OK;
121 IWineD3DSurface *mySurface = NULL;
122
123 TRACE("iface %p, backbuffer_idx %u, backbuffer_type %#x, backbuffer %p.\n",
124 iface, iBackBuffer, Type, ppBackBuffer);
125
126 wined3d_mutex_lock();
127 hrc = IWineD3DSwapChain_GetBackBuffer(This->wineD3DSwapChain, iBackBuffer, (WINED3DBACKBUFFER_TYPE) Type, &mySurface);
128 if (hrc == D3D_OK && NULL != mySurface) {
129 IWineD3DSurface_GetParent(mySurface, (IUnknown **)ppBackBuffer);
130 IWineD3DSurface_Release(mySurface);
131 }
132 wined3d_mutex_unlock();
133
134 /* Do not touch the **ppBackBuffer pointer otherwise! (see device test) */
135 return hrc;
136}
137
138static HRESULT WINAPI IDirect3DSwapChain9Impl_GetRasterStatus(LPDIRECT3DSWAPCHAIN9 iface, D3DRASTER_STATUS* pRasterStatus) {
139 IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
140 HRESULT hr;
141
142 TRACE("iface %p, raster_status %p.\n", iface, pRasterStatus);
143
144 wined3d_mutex_lock();
145 hr = IWineD3DSwapChain_GetRasterStatus(This->wineD3DSwapChain, (WINED3DRASTER_STATUS *) pRasterStatus);
146 wined3d_mutex_unlock();
147
148 return hr;
149}
150
151static HRESULT WINAPI IDirect3DSwapChain9Impl_GetDisplayMode(LPDIRECT3DSWAPCHAIN9 iface, D3DDISPLAYMODE* pMode) {
152 IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
153 HRESULT hr;
154
155 TRACE("iface %p, mode %p.\n", iface, pMode);
156
157 wined3d_mutex_lock();
158 hr = IWineD3DSwapChain_GetDisplayMode(This->wineD3DSwapChain, (WINED3DDISPLAYMODE *) pMode);
159 wined3d_mutex_unlock();
160
161 if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format);
162
163 return hr;
164}
165
166static HRESULT WINAPI IDirect3DSwapChain9Impl_GetDevice(IDirect3DSwapChain9 *iface, IDirect3DDevice9 **device)
167{
168 IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
169
170 TRACE("iface %p, device %p.\n", iface, device);
171
172 *device = (IDirect3DDevice9 *)This->parentDevice;
173 IDirect3DDevice9_AddRef(*device);
174
175 TRACE("Returning device %p.\n", *device);
176
177 return D3D_OK;
178}
179
180static HRESULT WINAPI IDirect3DSwapChain9Impl_GetPresentParameters(LPDIRECT3DSWAPCHAIN9 iface, D3DPRESENT_PARAMETERS* pPresentationParameters) {
181 IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
182 WINED3DPRESENT_PARAMETERS winePresentParameters;
183 HRESULT hr;
184
185 TRACE("iface %p, parameters %p.\n", iface, pPresentationParameters);
186
187 wined3d_mutex_lock();
188 hr = IWineD3DSwapChain_GetPresentParameters(This->wineD3DSwapChain, &winePresentParameters);
189 wined3d_mutex_unlock();
190
191 pPresentationParameters->BackBufferWidth = winePresentParameters.BackBufferWidth;
192 pPresentationParameters->BackBufferHeight = winePresentParameters.BackBufferHeight;
193 pPresentationParameters->BackBufferFormat = d3dformat_from_wined3dformat(winePresentParameters.BackBufferFormat);
194 pPresentationParameters->BackBufferCount = winePresentParameters.BackBufferCount;
195 pPresentationParameters->MultiSampleType = winePresentParameters.MultiSampleType;
196 pPresentationParameters->MultiSampleQuality = winePresentParameters.MultiSampleQuality;
197 pPresentationParameters->SwapEffect = winePresentParameters.SwapEffect;
198 pPresentationParameters->hDeviceWindow = winePresentParameters.hDeviceWindow;
199 pPresentationParameters->Windowed = winePresentParameters.Windowed;
200 pPresentationParameters->EnableAutoDepthStencil = winePresentParameters.EnableAutoDepthStencil;
201 pPresentationParameters->AutoDepthStencilFormat = d3dformat_from_wined3dformat(winePresentParameters.AutoDepthStencilFormat);
202 pPresentationParameters->Flags = winePresentParameters.Flags;
203 pPresentationParameters->FullScreen_RefreshRateInHz = winePresentParameters.FullScreen_RefreshRateInHz;
204 pPresentationParameters->PresentationInterval = winePresentParameters.PresentationInterval;
205
206 return hr;
207}
208
209
210static const IDirect3DSwapChain9Vtbl Direct3DSwapChain9_Vtbl =
211{
212 IDirect3DSwapChain9Impl_QueryInterface,
213 IDirect3DSwapChain9Impl_AddRef,
214 IDirect3DSwapChain9Impl_Release,
215 IDirect3DSwapChain9Impl_Present,
216 IDirect3DSwapChain9Impl_GetFrontBufferData,
217 IDirect3DSwapChain9Impl_GetBackBuffer,
218 IDirect3DSwapChain9Impl_GetRasterStatus,
219 IDirect3DSwapChain9Impl_GetDisplayMode,
220 IDirect3DSwapChain9Impl_GetDevice,
221 IDirect3DSwapChain9Impl_GetPresentParameters
222};
223
224HRESULT swapchain_init(IDirect3DSwapChain9Impl *swapchain, IDirect3DDevice9Impl *device,
225 D3DPRESENT_PARAMETERS *present_parameters)
226{
227 WINED3DPRESENT_PARAMETERS wined3d_parameters;
228 HRESULT hr;
229
230 swapchain->ref = 1;
231 swapchain->lpVtbl = &Direct3DSwapChain9_Vtbl;
232
233 wined3d_parameters.BackBufferWidth = present_parameters->BackBufferWidth;
234 wined3d_parameters.BackBufferHeight = present_parameters->BackBufferHeight;
235 wined3d_parameters.BackBufferFormat = wined3dformat_from_d3dformat(present_parameters->BackBufferFormat);
236 wined3d_parameters.BackBufferCount = max(1, present_parameters->BackBufferCount);
237 wined3d_parameters.MultiSampleType = present_parameters->MultiSampleType;
238 wined3d_parameters.MultiSampleQuality = present_parameters->MultiSampleQuality;
239 wined3d_parameters.SwapEffect = present_parameters->SwapEffect;
240 wined3d_parameters.hDeviceWindow = present_parameters->hDeviceWindow;
241 wined3d_parameters.Windowed = present_parameters->Windowed;
242 wined3d_parameters.EnableAutoDepthStencil = present_parameters->EnableAutoDepthStencil;
243 wined3d_parameters.AutoDepthStencilFormat = wined3dformat_from_d3dformat(present_parameters->AutoDepthStencilFormat);
244 wined3d_parameters.Flags = present_parameters->Flags;
245 wined3d_parameters.FullScreen_RefreshRateInHz = present_parameters->FullScreen_RefreshRateInHz;
246 wined3d_parameters.PresentationInterval = present_parameters->PresentationInterval;
247 wined3d_parameters.AutoRestoreDisplayMode = TRUE;
248
249 wined3d_mutex_lock();
250 hr = IWineD3DDevice_CreateSwapChain(device->WineD3DDevice, &wined3d_parameters,
251 &swapchain->wineD3DSwapChain, (IUnknown *)swapchain, SURFACE_OPENGL);
252 wined3d_mutex_unlock();
253
254 present_parameters->BackBufferWidth = wined3d_parameters.BackBufferWidth;
255 present_parameters->BackBufferHeight = wined3d_parameters.BackBufferHeight;
256 present_parameters->BackBufferFormat = d3dformat_from_wined3dformat(wined3d_parameters.BackBufferFormat);
257 present_parameters->BackBufferCount = wined3d_parameters.BackBufferCount;
258 present_parameters->MultiSampleType = wined3d_parameters.MultiSampleType;
259 present_parameters->MultiSampleQuality = wined3d_parameters.MultiSampleQuality;
260 present_parameters->SwapEffect = wined3d_parameters.SwapEffect;
261 present_parameters->hDeviceWindow = wined3d_parameters.hDeviceWindow;
262 present_parameters->Windowed = wined3d_parameters.Windowed;
263 present_parameters->EnableAutoDepthStencil = wined3d_parameters.EnableAutoDepthStencil;
264 present_parameters->AutoDepthStencilFormat = d3dformat_from_wined3dformat(wined3d_parameters.AutoDepthStencilFormat);
265 present_parameters->Flags = wined3d_parameters.Flags;
266 present_parameters->FullScreen_RefreshRateInHz = wined3d_parameters.FullScreen_RefreshRateInHz;
267 present_parameters->PresentationInterval = wined3d_parameters.PresentationInterval;
268
269 if (FAILED(hr))
270 {
271 WARN("Failed to create wined3d swapchain, hr %#x.\n", hr);
272 return hr;
273 }
274
275 swapchain->parentDevice = (IDirect3DDevice9Ex *)device;
276 IDirect3DDevice9Ex_AddRef(swapchain->parentDevice);
277
278 return D3D_OK;
279}
280
281HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_GetSwapChain(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain, IDirect3DSwapChain9** pSwapChain) {
282 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
283 HRESULT hrc = D3D_OK;
284 IWineD3DSwapChain *swapchain = NULL;
285
286 TRACE("iface %p, swapchain_idx %u, swapchain %p.\n",
287 iface, iSwapChain, pSwapChain);
288
289 wined3d_mutex_lock();
290 hrc = IWineD3DDevice_GetSwapChain(This->WineD3DDevice, iSwapChain, &swapchain);
291 if (hrc == D3D_OK && NULL != swapchain) {
292 IWineD3DSwapChain_GetParent(swapchain, (IUnknown **)pSwapChain);
293 IWineD3DSwapChain_Release(swapchain);
294 } else {
295 *pSwapChain = NULL;
296 }
297 wined3d_mutex_unlock();
298
299 return hrc;
300}
301
302UINT WINAPI IDirect3DDevice9Impl_GetNumberOfSwapChains(LPDIRECT3DDEVICE9EX iface) {
303 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
304 UINT ret;
305
306 TRACE("iface %p.\n", iface);
307
308 wined3d_mutex_lock();
309 ret = IWineD3DDevice_GetNumberOfSwapChains(This->WineD3DDevice);
310 wined3d_mutex_unlock();
311
312 return ret;
313}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette