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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "d3d9_private.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
28 /* IDirect3DSwapChain IUnknown parts follow: */
29 HRESULT WINAPI IDirect3DSwapChain9Impl_QueryInterface(LPDIRECT3DSWAPCHAIN9 iface, REFIID riid, LPVOID* ppobj)
31 IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
33 if (IsEqualGUID(riid, &IID_IUnknown)
34 || IsEqualGUID(riid, &IID_IDirect3DSwapChain9)) {
35 IUnknown_AddRef(iface);
40 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
44 ULONG WINAPI IDirect3DSwapChain9Impl_AddRef(LPDIRECT3DSWAPCHAIN9 iface) {
45 IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
46 ULONG ref = InterlockedIncrement(&This->ref);
48 TRACE("(%p) : AddRef from %ld\n", This, ref - 1);
53 ULONG WINAPI IDirect3DSwapChain9Impl_Release(LPDIRECT3DSWAPCHAIN9 iface) {
54 IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
55 ULONG ref = InterlockedDecrement(&This->ref);
57 TRACE("(%p) : ReleaseRef to %ld\n", This, ref);
60 IWineD3DSwapChain_Release(This->wineD3DSwapChain);
61 HeapFree(GetProcessHeap(), 0, This);
66 /* IDirect3DSwapChain9 parts follow: */
67 HRESULT WINAPI IDirect3DSwapChain9Impl_Present(LPDIRECT3DSWAPCHAIN9 iface, CONST RECT* pSourceRect, CONST RECT* pDestRect, HWND hDestWindowOverride, CONST RGNDATA* pDirtyRegion, DWORD dwFlags) {
68 IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
69 TRACE("(%p) Relay\n", This);
70 return IWineD3DSwapChain_Present(This->wineD3DSwapChain, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion, dwFlags);
73 HRESULT WINAPI IDirect3DSwapChain9Impl_GetFrontBufferData(LPDIRECT3DSWAPCHAIN9 iface, IDirect3DSurface9* pDestSurface) {
74 IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
75 TRACE("(%p) Relay\n", This);
76 return IWineD3DSwapChain_GetFrontBufferData(This->wineD3DSwapChain, ((IDirect3DSurface9Impl *)pDestSurface)->wineD3DSurface);
79 HRESULT WINAPI IDirect3DSwapChain9Impl_GetBackBuffer(LPDIRECT3DSWAPCHAIN9 iface, UINT iBackBuffer, D3DBACKBUFFER_TYPE Type, IDirect3DSurface9** ppBackBuffer) {
80 IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
82 IWineD3DSurface *mySurface = NULL;
84 TRACE("(%p) Relay\n", This);
86 hrc = IWineD3DSwapChain_GetBackBuffer(This->wineD3DSwapChain, iBackBuffer, Type, &mySurface);
87 if (hrc == D3D_OK && NULL != mySurface) {
88 IWineD3DSurface_GetParent(mySurface, (IUnknown **)ppBackBuffer);
89 IWineD3DSurface_Release(mySurface);
94 HRESULT WINAPI IDirect3DSwapChain9Impl_GetRasterStatus(LPDIRECT3DSWAPCHAIN9 iface, D3DRASTER_STATUS* pRasterStatus) {
95 IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
96 TRACE("(%p) Relay\n", This);
97 return IWineD3DSwapChain_GetRasterStatus(This->wineD3DSwapChain, pRasterStatus);
100 HRESULT WINAPI IDirect3DSwapChain9Impl_GetDisplayMode(LPDIRECT3DSWAPCHAIN9 iface, D3DDISPLAYMODE* pMode) {
101 IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
102 TRACE("(%p) Relay\n", This);
103 return IWineD3DSwapChain_GetDisplayMode(This->wineD3DSwapChain, pMode);
106 HRESULT WINAPI IDirect3DSwapChain9Impl_GetDevice(LPDIRECT3DSWAPCHAIN9 iface, IDirect3DDevice9** ppDevice) {
107 IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
108 HRESULT hrc = D3D_OK;
109 IWineD3DDevice *device = NULL;
111 TRACE("(%p) Relay\n", This);
113 hrc = IWineD3DSwapChain_GetDevice(This->wineD3DSwapChain, &device);
114 if (hrc == D3D_OK && NULL != device) {
115 IWineD3DDevice_GetParent(device, (IUnknown **)ppDevice);
116 IWineD3DDevice_Release(device);
121 HRESULT WINAPI IDirect3DSwapChain9Impl_GetPresentParameters(LPDIRECT3DSWAPCHAIN9 iface, D3DPRESENT_PARAMETERS* pPresentationParameters) {
122 IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
123 WINED3DPRESENT_PARAMETERS winePresentParameters;
124 TRACE("(%p)->(%p): Relay\n", This, pPresentationParameters);
125 winePresentParameters.BackBufferWidth = &pPresentationParameters->BackBufferWidth;
126 winePresentParameters.BackBufferHeight = &pPresentationParameters->BackBufferHeight;
127 winePresentParameters.BackBufferFormat = (WINED3DFORMAT *) &pPresentationParameters->BackBufferFormat;
128 winePresentParameters.BackBufferCount = &pPresentationParameters->BackBufferCount;
129 winePresentParameters.MultiSampleType = (WINED3DMULTISAMPLE_TYPE *) &pPresentationParameters->MultiSampleType;
130 winePresentParameters.MultiSampleQuality = &pPresentationParameters->MultiSampleQuality;
131 winePresentParameters.SwapEffect = (WINED3DSWAPEFFECT *)&pPresentationParameters->SwapEffect;
132 winePresentParameters.hDeviceWindow = &pPresentationParameters->hDeviceWindow;
133 winePresentParameters.Windowed = &pPresentationParameters->Windowed;
134 winePresentParameters.EnableAutoDepthStencil = &pPresentationParameters->EnableAutoDepthStencil;
135 winePresentParameters.Flags = &pPresentationParameters->Flags;
136 winePresentParameters.FullScreen_RefreshRateInHz = &pPresentationParameters->FullScreen_RefreshRateInHz;
137 winePresentParameters.PresentationInterval = &pPresentationParameters->PresentationInterval;
138 return IWineD3DSwapChain_GetPresentParameters(This->wineD3DSwapChain, &winePresentParameters);
142 const IDirect3DSwapChain9Vtbl Direct3DSwapChain9_Vtbl =
144 IDirect3DSwapChain9Impl_QueryInterface,
145 IDirect3DSwapChain9Impl_AddRef,
146 IDirect3DSwapChain9Impl_Release,
147 IDirect3DSwapChain9Impl_Present,
148 IDirect3DSwapChain9Impl_GetFrontBufferData,
149 IDirect3DSwapChain9Impl_GetBackBuffer,
150 IDirect3DSwapChain9Impl_GetRasterStatus,
151 IDirect3DSwapChain9Impl_GetDisplayMode,
152 IDirect3DSwapChain9Impl_GetDevice,
153 IDirect3DSwapChain9Impl_GetPresentParameters
157 /* IDirect3DDevice9 IDirect3DSwapChain9 Methods follow: */
158 HRESULT WINAPI IDirect3DDevice9Impl_CreateAdditionalSwapChain(LPDIRECT3DDEVICE9 iface, D3DPRESENT_PARAMETERS* pPresentationParameters, IDirect3DSwapChain9** pSwapChain) {
159 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
160 IDirect3DSwapChain9Impl* object;
161 HRESULT hrc = D3D_OK;
162 WINED3DPRESENT_PARAMETERS localParameters;
164 TRACE("(%p) Relay\n", This);
166 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
167 if (NULL == object) {
168 FIXME("Allocation of memory failed, returning D3DERR_OUTOFVIDEOMEMORY\n");
169 return D3DERR_OUTOFVIDEOMEMORY;
172 object->lpVtbl = &Direct3DSwapChain9_Vtbl;
174 /* Allocate an associated WineD3DDevice object */
175 localParameters.BackBufferWidth = &pPresentationParameters->BackBufferWidth;
176 localParameters.BackBufferHeight = &pPresentationParameters->BackBufferHeight;
177 localParameters.BackBufferFormat = (WINED3DFORMAT *)&pPresentationParameters->BackBufferFormat;
178 localParameters.BackBufferCount = &pPresentationParameters->BackBufferCount;
179 localParameters.MultiSampleType = (WINED3DMULTISAMPLE_TYPE *) &pPresentationParameters->MultiSampleType;
180 localParameters.MultiSampleQuality = &pPresentationParameters->MultiSampleQuality;
181 localParameters.SwapEffect = (WINED3DSWAPEFFECT *)&pPresentationParameters->SwapEffect;
182 localParameters.hDeviceWindow = &pPresentationParameters->hDeviceWindow;
183 localParameters.Windowed = &pPresentationParameters->Windowed;
184 localParameters.EnableAutoDepthStencil = &pPresentationParameters->EnableAutoDepthStencil;
185 localParameters.AutoDepthStencilFormat = (WINED3DFORMAT *)&pPresentationParameters->AutoDepthStencilFormat;
186 localParameters.Flags = &pPresentationParameters->Flags;
187 localParameters.FullScreen_RefreshRateInHz = &pPresentationParameters->FullScreen_RefreshRateInHz;
188 localParameters.PresentationInterval = &pPresentationParameters->PresentationInterval;
191 hrc = IWineD3DDevice_CreateAdditionalSwapChain(This->WineD3DDevice, &localParameters, &object->wineD3DSwapChain, (IUnknown*)object, D3D9CB_CreateRenderTarget, D3D9CB_CreateDepthStencilSurface);
193 FIXME("(%p) call to IWineD3DDevice_CreateAdditionalSwapChain failed\n", This);
194 HeapFree(GetProcessHeap(), 0 , object);
196 *pSwapChain = (IDirect3DSwapChain9 *)object;
197 TRACE("(%p) : Created swapchain %p\n", This, *pSwapChain);
199 TRACE("(%p) returning %p\n", This, *pSwapChain);
203 HRESULT WINAPI IDirect3DDevice9Impl_GetSwapChain(LPDIRECT3DDEVICE9 iface, UINT iSwapChain, IDirect3DSwapChain9** pSwapChain) {
204 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
205 HRESULT hrc = D3D_OK;
206 IWineD3DSwapChain *swapchain = NULL;
208 TRACE("(%p) Relay\n", This);
210 hrc = IWineD3DDevice_GetSwapChain(This->WineD3DDevice, iSwapChain, &swapchain);
211 if (hrc == D3D_OK && NULL != swapchain) {
212 IWineD3DSwapChain_GetParent(swapchain, (IUnknown **)pSwapChain);
213 IWineD3DSwapChain_Release(swapchain);
218 UINT WINAPI IDirect3DDevice9Impl_GetNumberOfSwapChains(LPDIRECT3DDEVICE9 iface) {
219 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
220 TRACE("(%p) Relay\n", This);
221 return IWineD3DDevice_GetNumberOfSwapChains(This->WineD3DDevice);