mshtml: Reimplement editor mode right key using command controller.
[wine/wine-kai.git] / dlls / d3d9 / swapchain.c
blobc02a7f107668c8ab847db4386293746e52457206
1 /*
2 * IDirect3DSwapChain9 implementation
4 * Copyright 2002-2003 Jason Edmeades
5 * Raphael Junqueira
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
23 #include "config.h"
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 if (IsEqualGUID(riid, &IID_IUnknown)
34 || IsEqualGUID(riid, &IID_IDirect3DSwapChain9)) {
35 IUnknown_AddRef(iface);
36 *ppobj = This;
37 return S_OK;
40 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
41 *ppobj = NULL;
42 return E_NOINTERFACE;
45 static ULONG WINAPI IDirect3DSwapChain9Impl_AddRef(LPDIRECT3DSWAPCHAIN9 iface) {
46 IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
47 ULONG ref = InterlockedIncrement(&This->ref);
49 TRACE("(%p) : AddRef from %d\n", This, ref - 1);
51 if(ref == 1 && This->parentDevice) IUnknown_AddRef(This->parentDevice);
53 return ref;
56 static ULONG WINAPI IDirect3DSwapChain9Impl_Release(LPDIRECT3DSWAPCHAIN9 iface) {
57 IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
58 ULONG ref = InterlockedDecrement(&This->ref);
60 TRACE("(%p) : ReleaseRef to %d\n", This, ref);
62 if (ref == 0) {
63 if (This->parentDevice) IUnknown_Release(This->parentDevice);
64 if (!This->isImplicit) {
65 IWineD3DSwapChain_Destroy(This->wineD3DSwapChain, D3D9CB_DestroyRenderTarget);
66 HeapFree(GetProcessHeap(), 0, This);
69 return ref;
72 /* IDirect3DSwapChain9 parts follow: */
73 static HRESULT WINAPI IDirect3DSwapChain9Impl_Present(LPDIRECT3DSWAPCHAIN9 iface, CONST RECT* pSourceRect, CONST RECT* pDestRect, HWND hDestWindowOverride, CONST RGNDATA* pDirtyRegion, DWORD dwFlags) {
74 IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
75 TRACE("(%p) Relay\n", This);
76 return IWineD3DSwapChain_Present(This->wineD3DSwapChain, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion, dwFlags);
79 static HRESULT WINAPI IDirect3DSwapChain9Impl_GetFrontBufferData(LPDIRECT3DSWAPCHAIN9 iface, IDirect3DSurface9* pDestSurface) {
80 IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
81 TRACE("(%p) Relay\n", This);
82 return IWineD3DSwapChain_GetFrontBufferData(This->wineD3DSwapChain, ((IDirect3DSurface9Impl *)pDestSurface)->wineD3DSurface);
85 static HRESULT WINAPI IDirect3DSwapChain9Impl_GetBackBuffer(LPDIRECT3DSWAPCHAIN9 iface, UINT iBackBuffer, D3DBACKBUFFER_TYPE Type, IDirect3DSurface9** ppBackBuffer) {
86 IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
87 HRESULT hrc = D3D_OK;
88 IWineD3DSurface *mySurface = NULL;
90 TRACE("(%p) Relay\n", This);
92 hrc = IWineD3DSwapChain_GetBackBuffer(This->wineD3DSwapChain, iBackBuffer, (WINED3DBACKBUFFER_TYPE) Type, &mySurface);
93 if (hrc == D3D_OK && NULL != mySurface) {
94 IWineD3DSurface_GetParent(mySurface, (IUnknown **)ppBackBuffer);
95 IWineD3DSurface_Release(mySurface);
97 /* Do not touch the **ppBackBuffer pointer otherwise! (see device test) */
98 return hrc;
101 static HRESULT WINAPI IDirect3DSwapChain9Impl_GetRasterStatus(LPDIRECT3DSWAPCHAIN9 iface, D3DRASTER_STATUS* pRasterStatus) {
102 IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
103 TRACE("(%p) Relay\n", This);
104 return IWineD3DSwapChain_GetRasterStatus(This->wineD3DSwapChain, (WINED3DRASTER_STATUS *) pRasterStatus);
107 static HRESULT WINAPI IDirect3DSwapChain9Impl_GetDisplayMode(LPDIRECT3DSWAPCHAIN9 iface, D3DDISPLAYMODE* pMode) {
108 IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
109 TRACE("(%p) Relay\n", This);
110 return IWineD3DSwapChain_GetDisplayMode(This->wineD3DSwapChain, (WINED3DDISPLAYMODE *) pMode);
113 static HRESULT WINAPI IDirect3DSwapChain9Impl_GetDevice(LPDIRECT3DSWAPCHAIN9 iface, IDirect3DDevice9** ppDevice) {
114 IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
115 HRESULT hrc = D3D_OK;
116 IWineD3DDevice *device = NULL;
118 TRACE("(%p) Relay\n", This);
120 hrc = IWineD3DSwapChain_GetDevice(This->wineD3DSwapChain, &device);
121 if (hrc == D3D_OK && NULL != device) {
122 IWineD3DDevice_GetParent(device, (IUnknown **)ppDevice);
123 IWineD3DDevice_Release(device);
125 return hrc;
128 static HRESULT WINAPI IDirect3DSwapChain9Impl_GetPresentParameters(LPDIRECT3DSWAPCHAIN9 iface, D3DPRESENT_PARAMETERS* pPresentationParameters) {
129 IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
130 WINED3DPRESENT_PARAMETERS winePresentParameters;
131 HRESULT hr;
133 TRACE("(%p)->(%p): Relay\n", This, pPresentationParameters);
135 hr = IWineD3DSwapChain_GetPresentParameters(This->wineD3DSwapChain, &winePresentParameters);
137 pPresentationParameters->BackBufferWidth = winePresentParameters.BackBufferWidth;
138 pPresentationParameters->BackBufferHeight = winePresentParameters.BackBufferHeight;
139 pPresentationParameters->BackBufferFormat = winePresentParameters.BackBufferFormat;
140 pPresentationParameters->BackBufferCount = winePresentParameters.BackBufferCount;
141 pPresentationParameters->MultiSampleType = winePresentParameters.MultiSampleType;
142 pPresentationParameters->MultiSampleQuality = winePresentParameters.MultiSampleQuality;
143 pPresentationParameters->SwapEffect = winePresentParameters.SwapEffect;
144 pPresentationParameters->hDeviceWindow = winePresentParameters.hDeviceWindow;
145 pPresentationParameters->Windowed = winePresentParameters.Windowed;
146 pPresentationParameters->EnableAutoDepthStencil = winePresentParameters.EnableAutoDepthStencil;
147 pPresentationParameters->Flags = winePresentParameters.Flags;
148 pPresentationParameters->FullScreen_RefreshRateInHz = winePresentParameters.FullScreen_RefreshRateInHz;
149 pPresentationParameters->PresentationInterval = winePresentParameters.PresentationInterval;
151 return hr;
155 static const IDirect3DSwapChain9Vtbl Direct3DSwapChain9_Vtbl =
157 IDirect3DSwapChain9Impl_QueryInterface,
158 IDirect3DSwapChain9Impl_AddRef,
159 IDirect3DSwapChain9Impl_Release,
160 IDirect3DSwapChain9Impl_Present,
161 IDirect3DSwapChain9Impl_GetFrontBufferData,
162 IDirect3DSwapChain9Impl_GetBackBuffer,
163 IDirect3DSwapChain9Impl_GetRasterStatus,
164 IDirect3DSwapChain9Impl_GetDisplayMode,
165 IDirect3DSwapChain9Impl_GetDevice,
166 IDirect3DSwapChain9Impl_GetPresentParameters
170 /* IDirect3DDevice9 IDirect3DSwapChain9 Methods follow: */
171 HRESULT WINAPI IDirect3DDevice9Impl_CreateAdditionalSwapChain(LPDIRECT3DDEVICE9 iface, D3DPRESENT_PARAMETERS* pPresentationParameters, IDirect3DSwapChain9** pSwapChain) {
172 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
173 IDirect3DSwapChain9Impl* object;
174 HRESULT hrc = D3D_OK;
175 WINED3DPRESENT_PARAMETERS localParameters;
177 TRACE("(%p) Relay\n", This);
179 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
180 if (NULL == object) {
181 FIXME("Allocation of memory failed, returning D3DERR_OUTOFVIDEOMEMORY\n");
182 return D3DERR_OUTOFVIDEOMEMORY;
184 object->ref = 1;
185 object->lpVtbl = &Direct3DSwapChain9_Vtbl;
187 /* The back buffer count is set to one if it's 0 */
188 if(pPresentationParameters->BackBufferCount == 0) {
189 pPresentationParameters->BackBufferCount = 1;
192 /* Allocate an associated WineD3DDevice object */
193 localParameters.BackBufferWidth = pPresentationParameters->BackBufferWidth;
194 localParameters.BackBufferHeight = pPresentationParameters->BackBufferHeight;
195 localParameters.BackBufferFormat = pPresentationParameters->BackBufferFormat;
196 localParameters.BackBufferCount = pPresentationParameters->BackBufferCount;
197 localParameters.MultiSampleType = pPresentationParameters->MultiSampleType;
198 localParameters.MultiSampleQuality = pPresentationParameters->MultiSampleQuality;
199 localParameters.SwapEffect = pPresentationParameters->SwapEffect;
200 localParameters.hDeviceWindow = pPresentationParameters->hDeviceWindow;
201 localParameters.Windowed = pPresentationParameters->Windowed;
202 localParameters.EnableAutoDepthStencil = pPresentationParameters->EnableAutoDepthStencil;
203 localParameters.AutoDepthStencilFormat = pPresentationParameters->AutoDepthStencilFormat;
204 localParameters.Flags = pPresentationParameters->Flags;
205 localParameters.FullScreen_RefreshRateInHz = pPresentationParameters->FullScreen_RefreshRateInHz;
206 localParameters.PresentationInterval = pPresentationParameters->PresentationInterval;
208 hrc = IWineD3DDevice_CreateAdditionalSwapChain(This->WineD3DDevice, &localParameters, &object->wineD3DSwapChain, (IUnknown*)object, D3D9CB_CreateRenderTarget, D3D9CB_CreateDepthStencilSurface);
210 pPresentationParameters->BackBufferWidth = localParameters.BackBufferWidth;
211 pPresentationParameters->BackBufferHeight = localParameters.BackBufferHeight;
212 pPresentationParameters->BackBufferFormat = localParameters.BackBufferFormat;
213 pPresentationParameters->BackBufferCount = localParameters.BackBufferCount;
214 pPresentationParameters->MultiSampleType = localParameters.MultiSampleType;
215 pPresentationParameters->MultiSampleQuality = localParameters.MultiSampleQuality;
216 pPresentationParameters->SwapEffect = localParameters.SwapEffect;
217 pPresentationParameters->hDeviceWindow = localParameters.hDeviceWindow;
218 pPresentationParameters->Windowed = localParameters.Windowed;
219 pPresentationParameters->EnableAutoDepthStencil = localParameters.EnableAutoDepthStencil;
220 pPresentationParameters->AutoDepthStencilFormat = localParameters.AutoDepthStencilFormat;
221 pPresentationParameters->Flags = localParameters.Flags;
222 pPresentationParameters->FullScreen_RefreshRateInHz = localParameters.FullScreen_RefreshRateInHz;
223 pPresentationParameters->PresentationInterval = localParameters.PresentationInterval;
225 if (hrc != D3D_OK) {
226 FIXME("(%p) call to IWineD3DDevice_CreateAdditionalSwapChain failed\n", This);
227 HeapFree(GetProcessHeap(), 0 , object);
228 } else {
229 IUnknown_AddRef(iface);
230 object->parentDevice = iface;
231 *pSwapChain = (IDirect3DSwapChain9 *)object;
232 TRACE("(%p) : Created swapchain %p\n", This, *pSwapChain);
234 TRACE("(%p) returning %p\n", This, *pSwapChain);
235 return hrc;
238 HRESULT WINAPI IDirect3DDevice9Impl_GetSwapChain(LPDIRECT3DDEVICE9 iface, UINT iSwapChain, IDirect3DSwapChain9** pSwapChain) {
239 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
240 HRESULT hrc = D3D_OK;
241 IWineD3DSwapChain *swapchain = NULL;
243 TRACE("(%p) Relay\n", This);
245 hrc = IWineD3DDevice_GetSwapChain(This->WineD3DDevice, iSwapChain, &swapchain);
246 if (hrc == D3D_OK && NULL != swapchain) {
247 IWineD3DSwapChain_GetParent(swapchain, (IUnknown **)pSwapChain);
248 IWineD3DSwapChain_Release(swapchain);
249 } else {
250 *pSwapChain = NULL;
252 return hrc;
255 UINT WINAPI IDirect3DDevice9Impl_GetNumberOfSwapChains(LPDIRECT3DDEVICE9 iface) {
256 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
257 TRACE("(%p) Relay\n", This);
258 return IWineD3DDevice_GetNumberOfSwapChains(This->WineD3DDevice);