VirtualBox

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

Last change on this file since 20227 was 19678, checked in by vboxsync, 16 years ago

opengl: update wine to 1.1.21, add d3d9.dll to build list

  • Property svn:eol-style set to native
File size: 14.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 * Sun 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, Sun 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 if (IsEqualGUID(riid, &IID_IUnknown)
43 || IsEqualGUID(riid, &IID_IDirect3DSwapChain9)) {
44 IDirect3DSwapChain9_AddRef(iface);
45 *ppobj = This;
46 return S_OK;
47 }
48
49 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
50 *ppobj = NULL;
51 return E_NOINTERFACE;
52}
53
54static ULONG WINAPI IDirect3DSwapChain9Impl_AddRef(LPDIRECT3DSWAPCHAIN9 iface) {
55 IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
56 ULONG ref = InterlockedIncrement(&This->ref);
57
58 TRACE("(%p) : AddRef from %d\n", This, ref - 1);
59
60 if(ref == 1 && This->parentDevice) IDirect3DDevice9Ex_AddRef(This->parentDevice);
61
62 return ref;
63}
64
65static ULONG WINAPI IDirect3DSwapChain9Impl_Release(LPDIRECT3DSWAPCHAIN9 iface) {
66 IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
67 ULONG ref = InterlockedDecrement(&This->ref);
68
69 TRACE("(%p) : ReleaseRef to %d\n", This, ref);
70
71 if (ref == 0) {
72 if (This->parentDevice) IDirect3DDevice9Ex_Release(This->parentDevice);
73 if (!This->isImplicit) {
74 EnterCriticalSection(&d3d9_cs);
75 IWineD3DSwapChain_Destroy(This->wineD3DSwapChain, D3D9CB_DestroyRenderTarget);
76 LeaveCriticalSection(&d3d9_cs);
77 HeapFree(GetProcessHeap(), 0, This);
78 }
79 }
80 return ref;
81}
82
83/* IDirect3DSwapChain9 parts follow: */
84static HRESULT WINAPI IDirect3DSwapChain9Impl_Present(LPDIRECT3DSWAPCHAIN9 iface, CONST RECT* pSourceRect, CONST RECT* pDestRect, HWND hDestWindowOverride, CONST RGNDATA* pDirtyRegion, DWORD dwFlags) {
85 IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
86 HRESULT hr;
87
88 TRACE("(%p) Relay\n", This);
89
90 EnterCriticalSection(&d3d9_cs);
91 hr = IWineD3DSwapChain_Present(This->wineD3DSwapChain, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion, dwFlags);
92 LeaveCriticalSection(&d3d9_cs);
93
94 return hr;
95}
96
97static HRESULT WINAPI IDirect3DSwapChain9Impl_GetFrontBufferData(LPDIRECT3DSWAPCHAIN9 iface, IDirect3DSurface9* pDestSurface) {
98 IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
99 HRESULT hr;
100 TRACE("(%p) Relay\n", This);
101
102 EnterCriticalSection(&d3d9_cs);
103 hr = IWineD3DSwapChain_GetFrontBufferData(This->wineD3DSwapChain, ((IDirect3DSurface9Impl *)pDestSurface)->wineD3DSurface);
104 LeaveCriticalSection(&d3d9_cs);
105 return hr;
106}
107
108static HRESULT WINAPI IDirect3DSwapChain9Impl_GetBackBuffer(LPDIRECT3DSWAPCHAIN9 iface, UINT iBackBuffer, D3DBACKBUFFER_TYPE Type, IDirect3DSurface9** ppBackBuffer) {
109 IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
110 HRESULT hrc = D3D_OK;
111 IWineD3DSurface *mySurface = NULL;
112
113 TRACE("(%p) Relay\n", This);
114
115 EnterCriticalSection(&d3d9_cs);
116 hrc = IWineD3DSwapChain_GetBackBuffer(This->wineD3DSwapChain, iBackBuffer, (WINED3DBACKBUFFER_TYPE) Type, &mySurface);
117 if (hrc == D3D_OK && NULL != mySurface) {
118 IWineD3DSurface_GetParent(mySurface, (IUnknown **)ppBackBuffer);
119 IWineD3DSurface_Release(mySurface);
120 }
121 LeaveCriticalSection(&d3d9_cs);
122 /* Do not touch the **ppBackBuffer pointer otherwise! (see device test) */
123 return hrc;
124}
125
126static HRESULT WINAPI IDirect3DSwapChain9Impl_GetRasterStatus(LPDIRECT3DSWAPCHAIN9 iface, D3DRASTER_STATUS* pRasterStatus) {
127 IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
128 HRESULT hr;
129 TRACE("(%p) Relay\n", This);
130
131 EnterCriticalSection(&d3d9_cs);
132 hr = IWineD3DSwapChain_GetRasterStatus(This->wineD3DSwapChain, (WINED3DRASTER_STATUS *) pRasterStatus);
133 LeaveCriticalSection(&d3d9_cs);
134 return hr;
135}
136
137static HRESULT WINAPI IDirect3DSwapChain9Impl_GetDisplayMode(LPDIRECT3DSWAPCHAIN9 iface, D3DDISPLAYMODE* pMode) {
138 IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
139 HRESULT hr;
140 TRACE("(%p) Relay\n", This);
141
142 EnterCriticalSection(&d3d9_cs);
143 hr = IWineD3DSwapChain_GetDisplayMode(This->wineD3DSwapChain, (WINED3DDISPLAYMODE *) pMode);
144 LeaveCriticalSection(&d3d9_cs);
145
146 if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format);
147
148 return hr;
149}
150
151static HRESULT WINAPI IDirect3DSwapChain9Impl_GetDevice(LPDIRECT3DSWAPCHAIN9 iface, IDirect3DDevice9** ppDevice) {
152 IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
153 HRESULT hrc = D3D_OK;
154 IWineD3DDevice *device = NULL;
155
156 TRACE("(%p) Relay\n", This);
157
158 EnterCriticalSection(&d3d9_cs);
159 hrc = IWineD3DSwapChain_GetDevice(This->wineD3DSwapChain, &device);
160 if (hrc == D3D_OK && NULL != device) {
161 IWineD3DDevice_GetParent(device, (IUnknown **)ppDevice);
162 IWineD3DDevice_Release(device);
163 }
164 LeaveCriticalSection(&d3d9_cs);
165 return hrc;
166}
167
168static HRESULT WINAPI IDirect3DSwapChain9Impl_GetPresentParameters(LPDIRECT3DSWAPCHAIN9 iface, D3DPRESENT_PARAMETERS* pPresentationParameters) {
169 IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
170 WINED3DPRESENT_PARAMETERS winePresentParameters;
171 HRESULT hr;
172
173 TRACE("(%p)->(%p): Relay\n", This, pPresentationParameters);
174
175 EnterCriticalSection(&d3d9_cs);
176 hr = IWineD3DSwapChain_GetPresentParameters(This->wineD3DSwapChain, &winePresentParameters);
177 LeaveCriticalSection(&d3d9_cs);
178
179 pPresentationParameters->BackBufferWidth = winePresentParameters.BackBufferWidth;
180 pPresentationParameters->BackBufferHeight = winePresentParameters.BackBufferHeight;
181 pPresentationParameters->BackBufferFormat = d3dformat_from_wined3dformat(winePresentParameters.BackBufferFormat);
182 pPresentationParameters->BackBufferCount = winePresentParameters.BackBufferCount;
183 pPresentationParameters->MultiSampleType = winePresentParameters.MultiSampleType;
184 pPresentationParameters->MultiSampleQuality = winePresentParameters.MultiSampleQuality;
185 pPresentationParameters->SwapEffect = winePresentParameters.SwapEffect;
186 pPresentationParameters->hDeviceWindow = winePresentParameters.hDeviceWindow;
187 pPresentationParameters->Windowed = winePresentParameters.Windowed;
188 pPresentationParameters->EnableAutoDepthStencil = winePresentParameters.EnableAutoDepthStencil;
189 pPresentationParameters->AutoDepthStencilFormat = d3dformat_from_wined3dformat(winePresentParameters.AutoDepthStencilFormat);
190 pPresentationParameters->Flags = winePresentParameters.Flags;
191 pPresentationParameters->FullScreen_RefreshRateInHz = winePresentParameters.FullScreen_RefreshRateInHz;
192 pPresentationParameters->PresentationInterval = winePresentParameters.PresentationInterval;
193
194 return hr;
195}
196
197
198static const IDirect3DSwapChain9Vtbl Direct3DSwapChain9_Vtbl =
199{
200 IDirect3DSwapChain9Impl_QueryInterface,
201 IDirect3DSwapChain9Impl_AddRef,
202 IDirect3DSwapChain9Impl_Release,
203 IDirect3DSwapChain9Impl_Present,
204 IDirect3DSwapChain9Impl_GetFrontBufferData,
205 IDirect3DSwapChain9Impl_GetBackBuffer,
206 IDirect3DSwapChain9Impl_GetRasterStatus,
207 IDirect3DSwapChain9Impl_GetDisplayMode,
208 IDirect3DSwapChain9Impl_GetDevice,
209 IDirect3DSwapChain9Impl_GetPresentParameters
210};
211
212
213/* IDirect3DDevice9 IDirect3DSwapChain9 Methods follow: */
214HRESULT WINAPI IDirect3DDevice9Impl_CreateAdditionalSwapChain(LPDIRECT3DDEVICE9EX iface, D3DPRESENT_PARAMETERS* pPresentationParameters, IDirect3DSwapChain9** pSwapChain) {
215 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
216 IDirect3DSwapChain9Impl* object;
217 HRESULT hrc = D3D_OK;
218 WINED3DPRESENT_PARAMETERS localParameters;
219
220 TRACE("(%p) Relay\n", This);
221
222 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
223 if (NULL == object) {
224 FIXME("Allocation of memory failed, returning D3DERR_OUTOFVIDEOMEMORY\n");
225 return D3DERR_OUTOFVIDEOMEMORY;
226 }
227 object->ref = 1;
228 object->lpVtbl = &Direct3DSwapChain9_Vtbl;
229
230 /* The back buffer count is set to one if it's 0 */
231 if(pPresentationParameters->BackBufferCount == 0) {
232 pPresentationParameters->BackBufferCount = 1;
233 }
234
235 /* Allocate an associated WineD3DDevice object */
236 localParameters.BackBufferWidth = pPresentationParameters->BackBufferWidth;
237 localParameters.BackBufferHeight = pPresentationParameters->BackBufferHeight;
238 localParameters.BackBufferFormat = wined3dformat_from_d3dformat(pPresentationParameters->BackBufferFormat);
239 localParameters.BackBufferCount = pPresentationParameters->BackBufferCount;
240 localParameters.MultiSampleType = pPresentationParameters->MultiSampleType;
241 localParameters.MultiSampleQuality = pPresentationParameters->MultiSampleQuality;
242 localParameters.SwapEffect = pPresentationParameters->SwapEffect;
243 localParameters.hDeviceWindow = pPresentationParameters->hDeviceWindow;
244 localParameters.Windowed = pPresentationParameters->Windowed;
245 localParameters.EnableAutoDepthStencil = pPresentationParameters->EnableAutoDepthStencil;
246 localParameters.AutoDepthStencilFormat = wined3dformat_from_d3dformat(pPresentationParameters->AutoDepthStencilFormat);
247 localParameters.Flags = pPresentationParameters->Flags;
248 localParameters.FullScreen_RefreshRateInHz = pPresentationParameters->FullScreen_RefreshRateInHz;
249 localParameters.PresentationInterval = pPresentationParameters->PresentationInterval;
250 localParameters.AutoRestoreDisplayMode = TRUE;
251
252 EnterCriticalSection(&d3d9_cs);
253 hrc = IWineD3DDevice_CreateSwapChain(This->WineD3DDevice, &localParameters,
254 &object->wineD3DSwapChain, (IUnknown*)object, SURFACE_OPENGL);
255 LeaveCriticalSection(&d3d9_cs);
256
257 pPresentationParameters->BackBufferWidth = localParameters.BackBufferWidth;
258 pPresentationParameters->BackBufferHeight = localParameters.BackBufferHeight;
259 pPresentationParameters->BackBufferFormat = d3dformat_from_wined3dformat(localParameters.BackBufferFormat);
260 pPresentationParameters->BackBufferCount = localParameters.BackBufferCount;
261 pPresentationParameters->MultiSampleType = localParameters.MultiSampleType;
262 pPresentationParameters->MultiSampleQuality = localParameters.MultiSampleQuality;
263 pPresentationParameters->SwapEffect = localParameters.SwapEffect;
264 pPresentationParameters->hDeviceWindow = localParameters.hDeviceWindow;
265 pPresentationParameters->Windowed = localParameters.Windowed;
266 pPresentationParameters->EnableAutoDepthStencil = localParameters.EnableAutoDepthStencil;
267 pPresentationParameters->AutoDepthStencilFormat = d3dformat_from_wined3dformat(localParameters.AutoDepthStencilFormat);
268 pPresentationParameters->Flags = localParameters.Flags;
269 pPresentationParameters->FullScreen_RefreshRateInHz = localParameters.FullScreen_RefreshRateInHz;
270 pPresentationParameters->PresentationInterval = localParameters.PresentationInterval;
271
272 if (hrc != D3D_OK) {
273 FIXME("(%p) call to IWineD3DDevice_CreateSwapChain failed\n", This);
274 HeapFree(GetProcessHeap(), 0 , object);
275 } else {
276 IDirect3DDevice9Ex_AddRef(iface);
277 object->parentDevice = iface;
278 *pSwapChain = (IDirect3DSwapChain9 *)object;
279 TRACE("(%p) : Created swapchain %p\n", This, *pSwapChain);
280 }
281 TRACE("(%p) returning %p\n", This, *pSwapChain);
282 return hrc;
283}
284
285HRESULT WINAPI IDirect3DDevice9Impl_GetSwapChain(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain, IDirect3DSwapChain9** pSwapChain) {
286 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
287 HRESULT hrc = D3D_OK;
288 IWineD3DSwapChain *swapchain = NULL;
289
290 TRACE("(%p) Relay\n", This);
291
292 EnterCriticalSection(&d3d9_cs);
293 hrc = IWineD3DDevice_GetSwapChain(This->WineD3DDevice, iSwapChain, &swapchain);
294 if (hrc == D3D_OK && NULL != swapchain) {
295 IWineD3DSwapChain_GetParent(swapchain, (IUnknown **)pSwapChain);
296 IWineD3DSwapChain_Release(swapchain);
297 } else {
298 *pSwapChain = NULL;
299 }
300 LeaveCriticalSection(&d3d9_cs);
301 return hrc;
302}
303
304UINT WINAPI IDirect3DDevice9Impl_GetNumberOfSwapChains(LPDIRECT3DDEVICE9EX iface) {
305 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
306 UINT ret;
307 TRACE("(%p) Relay\n", This);
308
309 EnterCriticalSection(&d3d9_cs);
310 ret = IWineD3DDevice_GetNumberOfSwapChains(This->WineD3DDevice);
311 LeaveCriticalSection(&d3d9_cs);
312 return ret;
313}
Note: See TracBrowser for help on using the repository browser.

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