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 |
|
---|
35 | WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
|
---|
36 |
|
---|
37 | /* IDirect3DSwapChain IUnknown parts follow: */
|
---|
38 | static 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 |
|
---|
54 | static 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 |
|
---|
65 | static 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: */
|
---|
84 | static 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 | TRACE("(%p) Relay\n", This);
|
---|
87 | return IWineD3DSwapChain_Present(This->wineD3DSwapChain, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion, dwFlags);
|
---|
88 | }
|
---|
89 |
|
---|
90 | static HRESULT WINAPI IDirect3DSwapChain9Impl_GetFrontBufferData(LPDIRECT3DSWAPCHAIN9 iface, IDirect3DSurface9* pDestSurface) {
|
---|
91 | IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
|
---|
92 | HRESULT hr;
|
---|
93 | TRACE("(%p) Relay\n", This);
|
---|
94 |
|
---|
95 | EnterCriticalSection(&d3d9_cs);
|
---|
96 | hr = IWineD3DSwapChain_GetFrontBufferData(This->wineD3DSwapChain, ((IDirect3DSurface9Impl *)pDestSurface)->wineD3DSurface);
|
---|
97 | LeaveCriticalSection(&d3d9_cs);
|
---|
98 | return hr;
|
---|
99 | }
|
---|
100 |
|
---|
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;
|
---|
105 |
|
---|
106 | TRACE("(%p) Relay\n", This);
|
---|
107 |
|
---|
108 | EnterCriticalSection(&d3d9_cs);
|
---|
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);
|
---|
113 | }
|
---|
114 | LeaveCriticalSection(&d3d9_cs);
|
---|
115 | /* Do not touch the **ppBackBuffer pointer otherwise! (see device test) */
|
---|
116 | return hrc;
|
---|
117 | }
|
---|
118 |
|
---|
119 | static HRESULT WINAPI IDirect3DSwapChain9Impl_GetRasterStatus(LPDIRECT3DSWAPCHAIN9 iface, D3DRASTER_STATUS* pRasterStatus) {
|
---|
120 | IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
|
---|
121 | HRESULT hr;
|
---|
122 | TRACE("(%p) Relay\n", This);
|
---|
123 |
|
---|
124 | EnterCriticalSection(&d3d9_cs);
|
---|
125 | hr = IWineD3DSwapChain_GetRasterStatus(This->wineD3DSwapChain, (WINED3DRASTER_STATUS *) pRasterStatus);
|
---|
126 | LeaveCriticalSection(&d3d9_cs);
|
---|
127 | return hr;
|
---|
128 | }
|
---|
129 |
|
---|
130 | static HRESULT WINAPI IDirect3DSwapChain9Impl_GetDisplayMode(LPDIRECT3DSWAPCHAIN9 iface, D3DDISPLAYMODE* pMode) {
|
---|
131 | IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
|
---|
132 | HRESULT hr;
|
---|
133 | TRACE("(%p) Relay\n", This);
|
---|
134 |
|
---|
135 | EnterCriticalSection(&d3d9_cs);
|
---|
136 | hr = IWineD3DSwapChain_GetDisplayMode(This->wineD3DSwapChain, (WINED3DDISPLAYMODE *) pMode);
|
---|
137 | LeaveCriticalSection(&d3d9_cs);
|
---|
138 | return hr;
|
---|
139 | }
|
---|
140 |
|
---|
141 | static HRESULT WINAPI IDirect3DSwapChain9Impl_GetDevice(LPDIRECT3DSWAPCHAIN9 iface, IDirect3DDevice9** ppDevice) {
|
---|
142 | IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
|
---|
143 | HRESULT hrc = D3D_OK;
|
---|
144 | IWineD3DDevice *device = NULL;
|
---|
145 |
|
---|
146 | TRACE("(%p) Relay\n", This);
|
---|
147 |
|
---|
148 | EnterCriticalSection(&d3d9_cs);
|
---|
149 | hrc = IWineD3DSwapChain_GetDevice(This->wineD3DSwapChain, &device);
|
---|
150 | if (hrc == D3D_OK && NULL != device) {
|
---|
151 | IWineD3DDevice_GetParent(device, (IUnknown **)ppDevice);
|
---|
152 | IWineD3DDevice_Release(device);
|
---|
153 | }
|
---|
154 | LeaveCriticalSection(&d3d9_cs);
|
---|
155 | return hrc;
|
---|
156 | }
|
---|
157 |
|
---|
158 | static HRESULT WINAPI IDirect3DSwapChain9Impl_GetPresentParameters(LPDIRECT3DSWAPCHAIN9 iface, D3DPRESENT_PARAMETERS* pPresentationParameters) {
|
---|
159 | IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
|
---|
160 | WINED3DPRESENT_PARAMETERS winePresentParameters;
|
---|
161 | HRESULT hr;
|
---|
162 |
|
---|
163 | TRACE("(%p)->(%p): Relay\n", This, pPresentationParameters);
|
---|
164 |
|
---|
165 | EnterCriticalSection(&d3d9_cs);
|
---|
166 | hr = IWineD3DSwapChain_GetPresentParameters(This->wineD3DSwapChain, &winePresentParameters);
|
---|
167 | LeaveCriticalSection(&d3d9_cs);
|
---|
168 |
|
---|
169 | pPresentationParameters->BackBufferWidth = winePresentParameters.BackBufferWidth;
|
---|
170 | pPresentationParameters->BackBufferHeight = winePresentParameters.BackBufferHeight;
|
---|
171 | pPresentationParameters->BackBufferFormat = winePresentParameters.BackBufferFormat;
|
---|
172 | pPresentationParameters->BackBufferCount = winePresentParameters.BackBufferCount;
|
---|
173 | pPresentationParameters->MultiSampleType = winePresentParameters.MultiSampleType;
|
---|
174 | pPresentationParameters->MultiSampleQuality = winePresentParameters.MultiSampleQuality;
|
---|
175 | pPresentationParameters->SwapEffect = winePresentParameters.SwapEffect;
|
---|
176 | pPresentationParameters->hDeviceWindow = winePresentParameters.hDeviceWindow;
|
---|
177 | pPresentationParameters->Windowed = winePresentParameters.Windowed;
|
---|
178 | pPresentationParameters->EnableAutoDepthStencil = winePresentParameters.EnableAutoDepthStencil;
|
---|
179 | pPresentationParameters->Flags = winePresentParameters.Flags;
|
---|
180 | pPresentationParameters->FullScreen_RefreshRateInHz = winePresentParameters.FullScreen_RefreshRateInHz;
|
---|
181 | pPresentationParameters->PresentationInterval = winePresentParameters.PresentationInterval;
|
---|
182 |
|
---|
183 | return hr;
|
---|
184 | }
|
---|
185 |
|
---|
186 |
|
---|
187 | static const IDirect3DSwapChain9Vtbl Direct3DSwapChain9_Vtbl =
|
---|
188 | {
|
---|
189 | IDirect3DSwapChain9Impl_QueryInterface,
|
---|
190 | IDirect3DSwapChain9Impl_AddRef,
|
---|
191 | IDirect3DSwapChain9Impl_Release,
|
---|
192 | IDirect3DSwapChain9Impl_Present,
|
---|
193 | IDirect3DSwapChain9Impl_GetFrontBufferData,
|
---|
194 | IDirect3DSwapChain9Impl_GetBackBuffer,
|
---|
195 | IDirect3DSwapChain9Impl_GetRasterStatus,
|
---|
196 | IDirect3DSwapChain9Impl_GetDisplayMode,
|
---|
197 | IDirect3DSwapChain9Impl_GetDevice,
|
---|
198 | IDirect3DSwapChain9Impl_GetPresentParameters
|
---|
199 | };
|
---|
200 |
|
---|
201 |
|
---|
202 | /* IDirect3DDevice9 IDirect3DSwapChain9 Methods follow: */
|
---|
203 | HRESULT WINAPI IDirect3DDevice9Impl_CreateAdditionalSwapChain(LPDIRECT3DDEVICE9EX iface, D3DPRESENT_PARAMETERS* pPresentationParameters, IDirect3DSwapChain9** pSwapChain) {
|
---|
204 | IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
|
---|
205 | IDirect3DSwapChain9Impl* object;
|
---|
206 | HRESULT hrc = D3D_OK;
|
---|
207 | WINED3DPRESENT_PARAMETERS localParameters;
|
---|
208 |
|
---|
209 | TRACE("(%p) Relay\n", This);
|
---|
210 |
|
---|
211 | object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
|
---|
212 | if (NULL == object) {
|
---|
213 | FIXME("Allocation of memory failed, returning D3DERR_OUTOFVIDEOMEMORY\n");
|
---|
214 | return D3DERR_OUTOFVIDEOMEMORY;
|
---|
215 | }
|
---|
216 | object->ref = 1;
|
---|
217 | object->lpVtbl = &Direct3DSwapChain9_Vtbl;
|
---|
218 |
|
---|
219 | /* The back buffer count is set to one if it's 0 */
|
---|
220 | if(pPresentationParameters->BackBufferCount == 0) {
|
---|
221 | pPresentationParameters->BackBufferCount = 1;
|
---|
222 | }
|
---|
223 |
|
---|
224 | /* Allocate an associated WineD3DDevice object */
|
---|
225 | localParameters.BackBufferWidth = pPresentationParameters->BackBufferWidth;
|
---|
226 | localParameters.BackBufferHeight = pPresentationParameters->BackBufferHeight;
|
---|
227 | localParameters.BackBufferFormat = pPresentationParameters->BackBufferFormat;
|
---|
228 | localParameters.BackBufferCount = pPresentationParameters->BackBufferCount;
|
---|
229 | localParameters.MultiSampleType = pPresentationParameters->MultiSampleType;
|
---|
230 | localParameters.MultiSampleQuality = pPresentationParameters->MultiSampleQuality;
|
---|
231 | localParameters.SwapEffect = pPresentationParameters->SwapEffect;
|
---|
232 | localParameters.hDeviceWindow = pPresentationParameters->hDeviceWindow;
|
---|
233 | localParameters.Windowed = pPresentationParameters->Windowed;
|
---|
234 | localParameters.EnableAutoDepthStencil = pPresentationParameters->EnableAutoDepthStencil;
|
---|
235 | localParameters.AutoDepthStencilFormat = pPresentationParameters->AutoDepthStencilFormat;
|
---|
236 | localParameters.Flags = pPresentationParameters->Flags;
|
---|
237 | localParameters.FullScreen_RefreshRateInHz = pPresentationParameters->FullScreen_RefreshRateInHz;
|
---|
238 | localParameters.PresentationInterval = pPresentationParameters->PresentationInterval;
|
---|
239 |
|
---|
240 | EnterCriticalSection(&d3d9_cs);
|
---|
241 | hrc = IWineD3DDevice_CreateSwapChain(This->WineD3DDevice, &localParameters, &object->wineD3DSwapChain, (IUnknown*)object, D3D9CB_CreateRenderTarget, D3D9CB_CreateDepthStencilSurface, SURFACE_OPENGL);
|
---|
242 | LeaveCriticalSection(&d3d9_cs);
|
---|
243 |
|
---|
244 | pPresentationParameters->BackBufferWidth = localParameters.BackBufferWidth;
|
---|
245 | pPresentationParameters->BackBufferHeight = localParameters.BackBufferHeight;
|
---|
246 | pPresentationParameters->BackBufferFormat = localParameters.BackBufferFormat;
|
---|
247 | pPresentationParameters->BackBufferCount = localParameters.BackBufferCount;
|
---|
248 | pPresentationParameters->MultiSampleType = localParameters.MultiSampleType;
|
---|
249 | pPresentationParameters->MultiSampleQuality = localParameters.MultiSampleQuality;
|
---|
250 | pPresentationParameters->SwapEffect = localParameters.SwapEffect;
|
---|
251 | pPresentationParameters->hDeviceWindow = localParameters.hDeviceWindow;
|
---|
252 | pPresentationParameters->Windowed = localParameters.Windowed;
|
---|
253 | pPresentationParameters->EnableAutoDepthStencil = localParameters.EnableAutoDepthStencil;
|
---|
254 | pPresentationParameters->AutoDepthStencilFormat = localParameters.AutoDepthStencilFormat;
|
---|
255 | pPresentationParameters->Flags = localParameters.Flags;
|
---|
256 | pPresentationParameters->FullScreen_RefreshRateInHz = localParameters.FullScreen_RefreshRateInHz;
|
---|
257 | pPresentationParameters->PresentationInterval = localParameters.PresentationInterval;
|
---|
258 |
|
---|
259 | if (hrc != D3D_OK) {
|
---|
260 | FIXME("(%p) call to IWineD3DDevice_CreateSwapChain failed\n", This);
|
---|
261 | HeapFree(GetProcessHeap(), 0 , object);
|
---|
262 | } else {
|
---|
263 | IDirect3DDevice9Ex_AddRef(iface);
|
---|
264 | object->parentDevice = iface;
|
---|
265 | *pSwapChain = (IDirect3DSwapChain9 *)object;
|
---|
266 | TRACE("(%p) : Created swapchain %p\n", This, *pSwapChain);
|
---|
267 | }
|
---|
268 | TRACE("(%p) returning %p\n", This, *pSwapChain);
|
---|
269 | return hrc;
|
---|
270 | }
|
---|
271 |
|
---|
272 | HRESULT WINAPI IDirect3DDevice9Impl_GetSwapChain(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain, IDirect3DSwapChain9** pSwapChain) {
|
---|
273 | IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
|
---|
274 | HRESULT hrc = D3D_OK;
|
---|
275 | IWineD3DSwapChain *swapchain = NULL;
|
---|
276 |
|
---|
277 | TRACE("(%p) Relay\n", This);
|
---|
278 |
|
---|
279 | EnterCriticalSection(&d3d9_cs);
|
---|
280 | hrc = IWineD3DDevice_GetSwapChain(This->WineD3DDevice, iSwapChain, &swapchain);
|
---|
281 | if (hrc == D3D_OK && NULL != swapchain) {
|
---|
282 | IWineD3DSwapChain_GetParent(swapchain, (IUnknown **)pSwapChain);
|
---|
283 | IWineD3DSwapChain_Release(swapchain);
|
---|
284 | } else {
|
---|
285 | *pSwapChain = NULL;
|
---|
286 | }
|
---|
287 | LeaveCriticalSection(&d3d9_cs);
|
---|
288 | return hrc;
|
---|
289 | }
|
---|
290 |
|
---|
291 | UINT WINAPI IDirect3DDevice9Impl_GetNumberOfSwapChains(LPDIRECT3DDEVICE9EX iface) {
|
---|
292 | IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
|
---|
293 | UINT ret;
|
---|
294 | TRACE("(%p) Relay\n", This);
|
---|
295 |
|
---|
296 | EnterCriticalSection(&d3d9_cs);
|
---|
297 | ret = IWineD3DDevice_GetNumberOfSwapChains(This->WineD3DDevice);
|
---|
298 | LeaveCriticalSection(&d3d9_cs);
|
---|
299 | return ret;
|
---|
300 | }
|
---|