Fix RegisterWindowMessage declaration and improve debug message.
[wine/dcerpc.git] / dlls / d3d9 / swapchain.c
blobdbe23d1b172c59887cbfa7cfa4d97c292145df07
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "config.h"
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);
36 *ppobj = This;
37 return D3D_OK;
40 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
41 return E_NOINTERFACE;
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);
50 return ref;
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);
59 if (ref == 0) {
60 HeapFree(GetProcessHeap(), 0, This);
62 return ref;
65 /* IDirect3DSwapChain9 parts follow: */
66 HRESULT WINAPI IDirect3DSwapChain9Impl_Present(LPDIRECT3DSWAPCHAIN9 iface, CONST RECT* pSourceRect, CONST RECT* pDestRect, HWND hDestWindowOverride, CONST RGNDATA* pDirtyRegion, DWORD dwFlags) {
67 IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
68 TRACE("(%p) Relay\n", This);
69 return IWineD3DSwapChain_Present(This->wineD3DSwapChain, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion, dwFlags);
72 HRESULT WINAPI IDirect3DSwapChain9Impl_GetFrontBufferData(LPDIRECT3DSWAPCHAIN9 iface, IDirect3DSurface9* pDestSurface) {
73 IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
74 TRACE("(%p) Relay\n", This);
75 return IWineD3DSwapChain_GetFrontBufferData(This->wineD3DSwapChain, ((IDirect3DSurface9Impl *)pDestSurface)->wineD3DSurface);
78 HRESULT WINAPI IDirect3DSwapChain9Impl_GetBackBuffer(LPDIRECT3DSWAPCHAIN9 iface, UINT iBackBuffer, D3DBACKBUFFER_TYPE Type, IDirect3DSurface9** ppBackBuffer) {
79 IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
80 HRESULT hrc = D3D_OK;
81 IWineD3DSurface *mySurface = NULL;
83 TRACE("(%p) Relay\n", This);
85 hrc = IWineD3DSwapChain_GetBackBuffer(This->wineD3DSwapChain, iBackBuffer, Type, &mySurface);
86 if (hrc == D3D_OK && NULL != mySurface) {
87 IWineD3DSurface_GetParent(mySurface, (IUnknown **)ppBackBuffer);
88 IWineD3DSurface_Release(mySurface);
90 return hrc;
93 HRESULT WINAPI IDirect3DSwapChain9Impl_GetRasterStatus(LPDIRECT3DSWAPCHAIN9 iface, D3DRASTER_STATUS* pRasterStatus) {
94 IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
95 TRACE("(%p) Relay\n", This);
96 return IWineD3DSwapChain_GetRasterStatus(This->wineD3DSwapChain, pRasterStatus);
99 HRESULT WINAPI IDirect3DSwapChain9Impl_GetDisplayMode(LPDIRECT3DSWAPCHAIN9 iface, D3DDISPLAYMODE* pMode) {
100 IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
101 TRACE("(%p) Relay\n", This);
102 return IWineD3DSwapChain_GetDisplayMode(This->wineD3DSwapChain, pMode);
105 HRESULT WINAPI IDirect3DSwapChain9Impl_GetDevice(LPDIRECT3DSWAPCHAIN9 iface, IDirect3DDevice9** ppDevice) {
106 IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
107 HRESULT hrc = D3D_OK;
108 IWineD3DDevice *device = NULL;
110 TRACE("(%p) Relay\n", This);
112 hrc = IWineD3DSwapChain_GetDevice(This->wineD3DSwapChain, &device);
113 if (hrc == D3D_OK && NULL != device) {
114 IWineD3DDevice_GetParent(device, (IUnknown **)ppDevice);
115 IWineD3DDevice_Release(device);
117 return hrc;
120 HRESULT WINAPI IDirect3DSwapChain9Impl_GetPresentParameters(LPDIRECT3DSWAPCHAIN9 iface, D3DPRESENT_PARAMETERS* pPresentationParameters) {
121 IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
122 FIXME("(%p) : inplement using WINED3DPRESENT_PARAMERS\n", This);
123 return IWineD3DSwapChain_GetPresentParameters(This->wineD3DSwapChain, pPresentationParameters);
127 const IDirect3DSwapChain9Vtbl Direct3DSwapChain9_Vtbl =
129 IDirect3DSwapChain9Impl_QueryInterface,
130 IDirect3DSwapChain9Impl_AddRef,
131 IDirect3DSwapChain9Impl_Release,
132 IDirect3DSwapChain9Impl_Present,
133 IDirect3DSwapChain9Impl_GetFrontBufferData,
134 IDirect3DSwapChain9Impl_GetBackBuffer,
135 IDirect3DSwapChain9Impl_GetRasterStatus,
136 IDirect3DSwapChain9Impl_GetDisplayMode,
137 IDirect3DSwapChain9Impl_GetDevice,
138 IDirect3DSwapChain9Impl_GetPresentParameters
142 /* IDirect3DDevice9 IDirect3DSwapChain9 Methods follow: */
143 HRESULT WINAPI IDirect3DDevice9Impl_CreateAdditionalSwapChain(LPDIRECT3DDEVICE9 iface, D3DPRESENT_PARAMETERS* pPresentationParameters, IDirect3DSwapChain9** pSwapChain) {
144 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
145 IDirect3DSwapChain9Impl* object;
146 HRESULT hrc = D3D_OK;
147 WINED3DPRESENT_PARAMETERS localParameters;
149 TRACE("(%p) Relay\n", This);
151 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
152 if (NULL == object) {
153 FIXME("Allocation of memory failed\n");
154 *pSwapChain = NULL;
155 return D3DERR_OUTOFVIDEOMEMORY;
157 object->ref = 1;
158 object->lpVtbl = &Direct3DSwapChain9_Vtbl;
160 /* Allocate an associated WineD3DDevice object */
161 localParameters.BackBufferWidth = &pPresentationParameters->BackBufferWidth;
162 localParameters.BackBufferHeight = &pPresentationParameters->BackBufferHeight;
163 localParameters.BackBufferFormat = &pPresentationParameters->BackBufferFormat;
164 localParameters.BackBufferCount = &pPresentationParameters->BackBufferCount;
165 localParameters.MultiSampleType = &pPresentationParameters->MultiSampleType;
166 localParameters.MultiSampleQuality = &pPresentationParameters->MultiSampleQuality;
167 localParameters.SwapEffect = &pPresentationParameters->SwapEffect;
168 localParameters.hDeviceWindow = &pPresentationParameters->hDeviceWindow;
169 localParameters.Windowed = &pPresentationParameters->Windowed;
170 localParameters.EnableAutoDepthStencil = &pPresentationParameters->EnableAutoDepthStencil;
171 localParameters.AutoDepthStencilFormat = &pPresentationParameters->AutoDepthStencilFormat;
172 localParameters.Flags = &pPresentationParameters->Flags;
173 localParameters.FullScreen_RefreshRateInHz = &pPresentationParameters->FullScreen_RefreshRateInHz;
174 localParameters.PresentationInterval = &pPresentationParameters->PresentationInterval;
177 hrc = IWineD3DDevice_CreateAdditionalSwapChain(This->WineD3DDevice, &localParameters, &object->wineD3DSwapChain, (IUnknown*)object, D3D9CB_CreateRenderTarget, D3D9CB_CreateDepthStencilSurface);
178 if (hrc != D3D_OK) {
179 FIXME("(%p) call to IWineD3DDevice_CreateAdditionalSwapChain failed\n", This);
180 HeapFree(GetProcessHeap(), 0 , object);
181 *pSwapChain = NULL;
182 }else{
183 *pSwapChain = (IDirect3DSwapChain9 *)object;
185 TRACE("(%p) returning %p\n", This, *pSwapChain);
186 return D3D_OK;
189 HRESULT WINAPI IDirect3DDevice9Impl_GetSwapChain(LPDIRECT3DDEVICE9 iface, UINT iSwapChain, IDirect3DSwapChain9** pSwapChain) {
190 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
191 HRESULT hrc = D3D_OK;
192 IWineD3DSwapChain *swapchain = NULL;
194 TRACE("(%p) Relay\n", This);
196 hrc = IWineD3DDevice_GetSwapChain(This->WineD3DDevice, iSwapChain, &swapchain);
197 if (hrc == D3D_OK && NULL != swapchain) {
198 IWineD3DSwapChain_GetParent(swapchain, (IUnknown **)pSwapChain);
199 IWineD3DSwapChain_Release(swapchain);
201 return hrc;
204 UINT WINAPI IDirect3DDevice9Impl_GetNumberOfSwapChains(LPDIRECT3DDEVICE9 iface) {
205 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
206 TRACE("(%p) Relay\n", This);
207 return IWineD3DDevice_GetNumberOfSwapChains(This->WineD3DDevice);