Changes in crossover-wine-src-6.1.0 except for configure
[wine/hacks.git] / dlls / d3d9 / device.c
blob40b5e6aee4758fad9987fb22a7eff80245e1df5f
1 /*
2 * IDirect3DDevice9 implementation
4 * Copyright 2002-2005 Jason Edmeades
5 * Copyright 2002-2005 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);
29 /* IDirect3D IUnknown parts follow: */
30 static HRESULT WINAPI IDirect3DDevice9Impl_QueryInterface(LPDIRECT3DDEVICE9 iface, REFIID riid, LPVOID* ppobj) {
31 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
33 if (IsEqualGUID(riid, &IID_IUnknown)
34 || IsEqualGUID(riid, &IID_IDirect3DDevice9)) {
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 IDirect3DDevice9Impl_AddRef(LPDIRECT3DDEVICE9 iface) {
46 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
47 ULONG ref = InterlockedIncrement(&This->ref);
49 TRACE("(%p) : AddRef from %d\n", This, ref - 1);
51 return ref;
54 static ULONG WINAPI IDirect3DDevice9Impl_Release(LPDIRECT3DDEVICE9 iface) {
55 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
56 ULONG ref;
58 if (This->inDestruction) return 0;
59 ref = InterlockedDecrement(&This->ref);
61 TRACE("(%p) : ReleaseRef to %d\n", This, ref);
63 if (ref == 0) {
64 int i;
65 This->inDestruction = TRUE;
67 for(i = 0; i < This->numConvertedDecls; i++) {
68 /* Unless Wine is buggy or the app has a bug the refcount will be 0, because decls hold a reference to the
69 * device
71 IDirect3DVertexDeclaration9Impl_Destroy(This->convertedDecls[i]);
73 HeapFree(GetProcessHeap(), 0, This->convertedDecls);
75 IWineD3DDevice_Uninit3D(This->WineD3DDevice, D3D9CB_DestroyDepthStencilSurface, D3D9CB_DestroySwapChain);
76 IWineD3DDevice_Release(This->WineD3DDevice);
77 HeapFree(GetProcessHeap(), 0, This);
79 return ref;
82 /* IDirect3DDevice Interface follow: */
83 static HRESULT WINAPI IDirect3DDevice9Impl_TestCooperativeLevel(LPDIRECT3DDEVICE9 iface) {
84 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
86 TRACE("(%p) : Relay\n", This);
87 return IWineD3DDevice_TestCooperativeLevel(This->WineD3DDevice);
90 static UINT WINAPI IDirect3DDevice9Impl_GetAvailableTextureMem(LPDIRECT3DDEVICE9 iface) {
91 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
93 TRACE("(%p) Relay\n", This);
94 return IWineD3DDevice_GetAvailableTextureMem(This->WineD3DDevice);
97 static HRESULT WINAPI IDirect3DDevice9Impl_EvictManagedResources(LPDIRECT3DDEVICE9 iface) {
98 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
100 TRACE("(%p) : Relay\n", This);
101 return IWineD3DDevice_EvictManagedResources(This->WineD3DDevice);
104 HRESULT WINAPI IDirect3DDevice9Impl_GetDirect3D(LPDIRECT3DDEVICE9 iface, IDirect3D9** ppD3D9) {
105 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
106 HRESULT hr = D3D_OK;
107 IWineD3D* pWineD3D;
109 TRACE("(%p) Relay\n", This);
111 if (NULL == ppD3D9) {
112 return D3DERR_INVALIDCALL;
114 hr = IWineD3DDevice_GetDirect3D(This->WineD3DDevice, &pWineD3D);
115 if (hr == D3D_OK && pWineD3D != NULL)
117 IWineD3D_GetParent(pWineD3D,(IUnknown **)ppD3D9);
118 IWineD3D_Release(pWineD3D);
119 } else {
120 FIXME("Call to IWineD3DDevice_GetDirect3D failed\n");
121 *ppD3D9 = NULL;
123 TRACE("(%p) returning %p\n", This, *ppD3D9);
124 return hr;
127 static HRESULT WINAPI IDirect3DDevice9Impl_GetDeviceCaps(LPDIRECT3DDEVICE9 iface, D3DCAPS9* pCaps) {
128 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
129 HRESULT hrc = D3D_OK;
130 WINED3DCAPS *pWineCaps;
132 TRACE("(%p) : Relay pCaps %p\n", This, pCaps);
133 if(NULL == pCaps){
134 return D3DERR_INVALIDCALL;
136 pWineCaps = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WINED3DCAPS));
137 if(pWineCaps == NULL){
138 return D3DERR_INVALIDCALL; /* well this is what MSDN says to return */
141 D3D9CAPSTOWINECAPS(pCaps, pWineCaps)
142 hrc = IWineD3DDevice_GetDeviceCaps(This->WineD3DDevice, pWineCaps);
143 HeapFree(GetProcessHeap(), 0, pWineCaps);
144 TRACE("Returning %p %p\n", This, pCaps);
145 return hrc;
148 static HRESULT WINAPI IDirect3DDevice9Impl_GetDisplayMode(LPDIRECT3DDEVICE9 iface, UINT iSwapChain, D3DDISPLAYMODE* pMode) {
149 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
150 TRACE("(%p) Relay\n", This);
151 return IWineD3DDevice_GetDisplayMode(This->WineD3DDevice, iSwapChain, (WINED3DDISPLAYMODE *) pMode);
154 static HRESULT WINAPI IDirect3DDevice9Impl_GetCreationParameters(LPDIRECT3DDEVICE9 iface, D3DDEVICE_CREATION_PARAMETERS *pParameters) {
155 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
156 TRACE("(%p) Relay\n", This);
157 return IWineD3DDevice_GetCreationParameters(This->WineD3DDevice, (WINED3DDEVICE_CREATION_PARAMETERS *) pParameters);
160 static HRESULT WINAPI IDirect3DDevice9Impl_SetCursorProperties(LPDIRECT3DDEVICE9 iface, UINT XHotSpot, UINT YHotSpot, IDirect3DSurface9* pCursorBitmap) {
161 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
162 IDirect3DSurface9Impl *pSurface = (IDirect3DSurface9Impl*)pCursorBitmap;
163 TRACE("(%p) Relay\n", This);
164 if(!pCursorBitmap) {
165 WARN("No cursor bitmap, returning WINED3DERR_INVALIDCALL\n");
166 return WINED3DERR_INVALIDCALL;
168 return IWineD3DDevice_SetCursorProperties(This->WineD3DDevice,XHotSpot,YHotSpot,(IWineD3DSurface*)pSurface->wineD3DSurface);
171 static void WINAPI IDirect3DDevice9Impl_SetCursorPosition(LPDIRECT3DDEVICE9 iface, int XScreenSpace, int YScreenSpace, DWORD Flags) {
172 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
173 TRACE("(%p) Relay\n", This);
174 return IWineD3DDevice_SetCursorPosition(This->WineD3DDevice, XScreenSpace, YScreenSpace, Flags);
177 static BOOL WINAPI IDirect3DDevice9Impl_ShowCursor(LPDIRECT3DDEVICE9 iface, BOOL bShow) {
178 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
179 TRACE("(%p) Relay\n", This);
181 return IWineD3DDevice_ShowCursor(This->WineD3DDevice, bShow);
184 static HRESULT WINAPI IDirect3DDevice9Impl_Reset(LPDIRECT3DDEVICE9 iface, D3DPRESENT_PARAMETERS* pPresentationParameters) {
185 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
186 WINED3DPRESENT_PARAMETERS localParameters;
187 HRESULT hr;
189 TRACE("(%p) Relay pPresentationParameters(%p)\n", This, pPresentationParameters);
191 localParameters.BackBufferWidth = pPresentationParameters->BackBufferWidth;
192 localParameters.BackBufferHeight = pPresentationParameters->BackBufferHeight;
193 localParameters.BackBufferFormat = pPresentationParameters->BackBufferFormat;
194 localParameters.BackBufferCount = pPresentationParameters->BackBufferCount;
195 localParameters.MultiSampleType = pPresentationParameters->MultiSampleType;
196 localParameters.MultiSampleQuality = pPresentationParameters->MultiSampleQuality;
197 localParameters.SwapEffect = pPresentationParameters->SwapEffect;
198 localParameters.hDeviceWindow = pPresentationParameters->hDeviceWindow;
199 localParameters.Windowed = pPresentationParameters->Windowed;
200 localParameters.EnableAutoDepthStencil = pPresentationParameters->EnableAutoDepthStencil;
201 localParameters.AutoDepthStencilFormat = pPresentationParameters->AutoDepthStencilFormat;
202 localParameters.Flags = pPresentationParameters->Flags;
203 localParameters.FullScreen_RefreshRateInHz = pPresentationParameters->FullScreen_RefreshRateInHz;
204 localParameters.PresentationInterval = pPresentationParameters->PresentationInterval;
206 hr = IWineD3DDevice_Reset(This->WineD3DDevice, &localParameters);
208 pPresentationParameters->BackBufferWidth = localParameters.BackBufferWidth;
209 pPresentationParameters->BackBufferHeight = localParameters.BackBufferHeight;
210 pPresentationParameters->BackBufferFormat = localParameters.BackBufferFormat;
211 pPresentationParameters->BackBufferCount = localParameters.BackBufferCount;
212 pPresentationParameters->MultiSampleType = localParameters.MultiSampleType;
213 pPresentationParameters->MultiSampleQuality = localParameters.MultiSampleQuality;
214 pPresentationParameters->SwapEffect = localParameters.SwapEffect;
215 pPresentationParameters->hDeviceWindow = localParameters.hDeviceWindow;
216 pPresentationParameters->Windowed = localParameters.Windowed;
217 pPresentationParameters->EnableAutoDepthStencil = localParameters.EnableAutoDepthStencil;
218 pPresentationParameters->AutoDepthStencilFormat = localParameters.AutoDepthStencilFormat;
219 pPresentationParameters->Flags = localParameters.Flags;
220 pPresentationParameters->FullScreen_RefreshRateInHz = localParameters.FullScreen_RefreshRateInHz;
221 pPresentationParameters->PresentationInterval = localParameters.PresentationInterval;
223 return hr;
226 static HRESULT WINAPI IDirect3DDevice9Impl_Present(LPDIRECT3DDEVICE9 iface, CONST RECT* pSourceRect,CONST RECT* pDestRect,HWND hDestWindowOverride,CONST RGNDATA*
227 pDirtyRegion) {
228 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
229 TRACE("(%p) Relay\n", This);
230 return IWineD3DDevice_Present(This->WineD3DDevice, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
233 static HRESULT WINAPI IDirect3DDevice9Impl_GetBackBuffer(LPDIRECT3DDEVICE9 iface, UINT iSwapChain, UINT BackBuffer, D3DBACKBUFFER_TYPE Type, IDirect3DSurface9 ** ppBackBuffer) {
234 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
235 IWineD3DSurface *retSurface = NULL;
236 HRESULT rc = D3D_OK;
238 TRACE("(%p) Relay\n", This);
240 rc = IWineD3DDevice_GetBackBuffer(This->WineD3DDevice, iSwapChain, BackBuffer, (WINED3DBACKBUFFER_TYPE) Type, (IWineD3DSurface **)&retSurface);
241 if (rc == D3D_OK && NULL != retSurface && NULL != ppBackBuffer) {
242 IWineD3DSurface_GetParent(retSurface, (IUnknown **)ppBackBuffer);
243 IWineD3DSurface_Release(retSurface);
245 return rc;
247 static HRESULT WINAPI IDirect3DDevice9Impl_GetRasterStatus(LPDIRECT3DDEVICE9 iface, UINT iSwapChain, D3DRASTER_STATUS* pRasterStatus) {
248 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
249 TRACE("(%p) Relay\n", This);
251 return IWineD3DDevice_GetRasterStatus(This->WineD3DDevice, iSwapChain, (WINED3DRASTER_STATUS *) pRasterStatus);
254 static HRESULT WINAPI IDirect3DDevice9Impl_SetDialogBoxMode(LPDIRECT3DDEVICE9 iface, BOOL bEnableDialogs) {
255 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
256 TRACE("(%p) Relay\n", This);
258 return IWineD3DDevice_SetDialogBoxMode(This->WineD3DDevice, bEnableDialogs);
261 static void WINAPI IDirect3DDevice9Impl_SetGammaRamp(LPDIRECT3DDEVICE9 iface, UINT iSwapChain, DWORD Flags, CONST D3DGAMMARAMP* pRamp) {
263 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
264 TRACE("(%p) Relay\n", This);
266 /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
267 return IWineD3DDevice_SetGammaRamp(This->WineD3DDevice, iSwapChain, Flags, (CONST WINED3DGAMMARAMP *)pRamp);
270 static void WINAPI IDirect3DDevice9Impl_GetGammaRamp(LPDIRECT3DDEVICE9 iface, UINT iSwapChain, D3DGAMMARAMP* pRamp) {
271 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
272 TRACE("(%p) Relay\n", This);
274 /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
275 return IWineD3DDevice_GetGammaRamp(This->WineD3DDevice, iSwapChain, (WINED3DGAMMARAMP *) pRamp);
279 static HRESULT WINAPI IDirect3DDevice9Impl_CreateSurface(LPDIRECT3DDEVICE9 iface, UINT Width, UINT Height, D3DFORMAT Format, BOOL Lockable, BOOL Discard, UINT Level, IDirect3DSurface9 **ppSurface,D3DRESOURCETYPE Type, UINT Usage, D3DPOOL Pool, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality,HANDLE* pSharedHandle ) {
280 HRESULT hrc;
281 IDirect3DSurface9Impl *object;
282 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
283 TRACE("(%p) Relay\n", This);
284 if(MultisampleQuality < 0) {
285 FIXME("MultisampleQuality out of range %d, substituting 0\n", MultisampleQuality);
286 /*FIXME: Find out what windows does with a MultisampleQuality < 0 */
287 MultisampleQuality=0;
290 if(MultisampleQuality > 0){
291 FIXME("MultisampleQuality set to %d, bstituting 0\n", MultisampleQuality);
293 MultisampleQuality
294 [in] Quality level. The valid range is between zero and one less than the level returned by pQualityLevels used by IDirect3D9::CheckDeviceMultiSampleType. Passing a larger value returns the error D3DERR_INVALIDCALL. The MultisampleQuality values of paired render targets, depth stencil surfaces, and the MultiSample type must all match.
297 MultisampleQuality=0;
299 /*FIXME: Check MAX bounds of MultisampleQuality*/
301 /* Allocate the storage for the device */
302 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DSurface9Impl));
303 if (NULL == object) {
304 FIXME("Allocation of memory failed\n");
305 return D3DERR_OUTOFVIDEOMEMORY;
308 object->lpVtbl = &Direct3DSurface9_Vtbl;
309 object->ref = 1;
311 TRACE("(%p) : w(%d) h(%d) fmt(%d) surf@%p\n", This, Width, Height, Format, *ppSurface);
313 hrc = IWineD3DDevice_CreateSurface(This->WineD3DDevice, Width, Height, Format, Lockable, Discard, Level, &object->wineD3DSurface, Type, Usage & WINED3DUSAGE_MASK, (WINED3DPOOL) Pool,MultiSample,MultisampleQuality,pSharedHandle,SURFACE_OPENGL,(IUnknown *)object);
315 if (hrc != D3D_OK || NULL == object->wineD3DSurface) {
317 /* free up object */
318 FIXME("(%p) call to IWineD3DDevice_CreateSurface failed\n", This);
319 HeapFree(GetProcessHeap(), 0, object);
320 } else {
321 IUnknown_AddRef(iface);
322 object->parentDevice = iface;
323 TRACE("(%p) : Created surface %p\n", This, object);
324 *ppSurface = (LPDIRECT3DSURFACE9) object;
326 return hrc;
331 static HRESULT WINAPI IDirect3DDevice9Impl_CreateRenderTarget(LPDIRECT3DDEVICE9 iface, UINT Width, UINT Height,
332 D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample,
333 DWORD MultisampleQuality, BOOL Lockable,
334 IDirect3DSurface9 **ppSurface, HANDLE* pSharedHandle) {
335 TRACE("Relay\n");
336 /* Is this correct? */
337 return IDirect3DDevice9Impl_CreateSurface(iface,Width,Height,Format,Lockable,FALSE/*Discard*/, 0/*Level*/, ppSurface,D3DRTYPE_SURFACE,D3DUSAGE_RENDERTARGET,D3DPOOL_DEFAULT,MultiSample,MultisampleQuality,pSharedHandle);
342 static HRESULT WINAPI IDirect3DDevice9Impl_CreateDepthStencilSurface(LPDIRECT3DDEVICE9 iface, UINT Width, UINT Height,
343 D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample,
344 DWORD MultisampleQuality, BOOL Discard,
345 IDirect3DSurface9 **ppSurface, HANDLE* pSharedHandle) {
346 TRACE("Relay\n");
347 return IDirect3DDevice9Impl_CreateSurface(iface,Width,Height,Format,TRUE/* Lockable */,Discard, 0/* Level */
348 ,ppSurface,D3DRTYPE_SURFACE,D3DUSAGE_DEPTHSTENCIL,
349 D3DPOOL_DEFAULT,MultiSample,MultisampleQuality,pSharedHandle);
353 static HRESULT WINAPI IDirect3DDevice9Impl_UpdateSurface(LPDIRECT3DDEVICE9 iface, IDirect3DSurface9* pSourceSurface, CONST RECT* pSourceRect, IDirect3DSurface9* pDestinationSurface, CONST POINT* pDestPoint) {
354 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
355 TRACE("(%p) Relay\n" , This);
356 return IWineD3DDevice_UpdateSurface(This->WineD3DDevice, ((IDirect3DSurface9Impl *)pSourceSurface)->wineD3DSurface, pSourceRect, ((IDirect3DSurface9Impl *)pDestinationSurface)->wineD3DSurface, pDestPoint);
359 static HRESULT WINAPI IDirect3DDevice9Impl_UpdateTexture(LPDIRECT3DDEVICE9 iface, IDirect3DBaseTexture9* pSourceTexture, IDirect3DBaseTexture9* pDestinationTexture) {
360 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
361 TRACE("(%p) Relay\n" , This);
362 return IWineD3DDevice_UpdateTexture(This->WineD3DDevice, ((IDirect3DBaseTexture9Impl *)pSourceTexture)->wineD3DBaseTexture, ((IDirect3DBaseTexture9Impl *)pDestinationTexture)->wineD3DBaseTexture);
365 /* This isn't in MSDN!
366 static HRESULT WINAPI IDirect3DDevice9Impl_GetFrontBuffer(LPDIRECT3DDEVICE9 iface, IDirect3DSurface9* pDestSurface) {
367 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
368 FIXME("(%p) : stub\n", This);
369 return D3D_OK;
373 static HRESULT WINAPI IDirect3DDevice9Impl_GetRenderTargetData(LPDIRECT3DDEVICE9 iface, IDirect3DSurface9* pRenderTarget, IDirect3DSurface9* pDestSurface) {
374 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
375 IDirect3DSurface9Impl *renderTarget = (IDirect3DSurface9Impl *)pRenderTarget;
376 IDirect3DSurface9Impl *destSurface = (IDirect3DSurface9Impl *)pDestSurface;
377 TRACE("(%p)->(%p,%p)\n" , This, renderTarget, destSurface);
378 return IWineD3DSurface_BltFast(destSurface->wineD3DSurface, 0, 0, renderTarget->wineD3DSurface, NULL, DDBLTFAST_NOCOLORKEY);
381 static HRESULT WINAPI IDirect3DDevice9Impl_GetFrontBufferData(LPDIRECT3DDEVICE9 iface, UINT iSwapChain, IDirect3DSurface9* pDestSurface) {
382 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
383 IDirect3DSurface9Impl *destSurface = (IDirect3DSurface9Impl *)pDestSurface;
384 TRACE("(%p) Relay\n" , This);
385 return IWineD3DDevice_GetFrontBufferData(This->WineD3DDevice, iSwapChain, destSurface->wineD3DSurface);
388 static HRESULT WINAPI IDirect3DDevice9Impl_StretchRect(LPDIRECT3DDEVICE9 iface, IDirect3DSurface9* pSourceSurface, CONST RECT* pSourceRect, IDirect3DSurface9* pDestSurface, CONST RECT* pDestRect, D3DTEXTUREFILTERTYPE Filter) {
389 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
390 IDirect3DSurface9Impl *src = (IDirect3DSurface9Impl *) pSourceSurface;
391 IDirect3DSurface9Impl *dst = (IDirect3DSurface9Impl *) pDestSurface;
393 TRACE("(%p)->(%p,%p,%p,%p,%d)\n" , This, src, pSourceRect, dst, pDestRect, Filter);
394 if(Filter != D3DTEXF_NONE) ERR("Texture filters not supported yet\n");
395 return IWineD3DSurface_Blt(dst->wineD3DSurface, (RECT *) pDestRect, src->wineD3DSurface, (RECT *) pSourceRect, 0, NULL);
398 static HRESULT WINAPI IDirect3DDevice9Impl_ColorFill(LPDIRECT3DDEVICE9 iface, IDirect3DSurface9* pSurface, CONST RECT* pRect, D3DCOLOR color) {
399 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
400 IDirect3DSurface9Impl *surface = (IDirect3DSurface9Impl *)pSurface;
401 TRACE("(%p) Relay\n" , This);
403 /* Note: D3DRECT is compatible with WINED3DRECT */
404 return IWineD3DDevice_ColorFill(This->WineD3DDevice, surface->wineD3DSurface, (CONST WINED3DRECT*)pRect, color);
407 static HRESULT WINAPI IDirect3DDevice9Impl_CreateOffscreenPlainSurface(LPDIRECT3DDEVICE9 iface, UINT Width, UINT Height, D3DFORMAT Format, D3DPOOL Pool, IDirect3DSurface9 **ppSurface, HANDLE* pSharedHandle) {
408 TRACE("Relay\n");
409 if(Pool == D3DPOOL_MANAGED ){
410 FIXME("Attempting to create a managed offscreen plain surface\n");
411 return D3DERR_INVALIDCALL;
413 /*MSDN: D3DPOOL_SCRATCH will return a surface that has identical characteristics to a surface created by the Microsoft DirectX 8.x method CreateImageSurface.
415 'Off-screen plain surfaces are always lockable, regardless of their pool types.'
416 but then...
417 D3DPOOL_DEFAULT is the appropriate pool for use with the IDirect3DDevice9::StretchRect and IDirect3DDevice9::ColorFill.
418 Why, their always lockable?
419 should I change the usage to dynamic?
421 return IDirect3DDevice9Impl_CreateSurface(iface,Width,Height,Format,TRUE/*Loackable*/,FALSE/*Discard*/,0/*Level*/ , ppSurface,D3DRTYPE_SURFACE, 0/*Usage (undefined/none)*/,(WINED3DPOOL) Pool,D3DMULTISAMPLE_NONE,0/*MultisampleQuality*/,pSharedHandle);
424 /* TODO: move to wineD3D */
425 static HRESULT WINAPI IDirect3DDevice9Impl_SetRenderTarget(LPDIRECT3DDEVICE9 iface, DWORD RenderTargetIndex, IDirect3DSurface9* pRenderTarget) {
426 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
427 IDirect3DSurface9Impl *pSurface = (IDirect3DSurface9Impl*)pRenderTarget;
428 TRACE("(%p) Relay\n" , This);
429 return IWineD3DDevice_SetRenderTarget(This->WineD3DDevice, RenderTargetIndex, pSurface ? (IWineD3DSurface*)pSurface->wineD3DSurface : NULL);
432 static HRESULT WINAPI IDirect3DDevice9Impl_GetRenderTarget(LPDIRECT3DDEVICE9 iface, DWORD RenderTargetIndex, IDirect3DSurface9 **ppRenderTarget) {
433 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
434 HRESULT hr = D3D_OK;
435 IWineD3DSurface *pRenderTarget;
437 TRACE("(%p) Relay\n" , This);
439 if (ppRenderTarget == NULL) {
440 return D3DERR_INVALIDCALL;
442 hr=IWineD3DDevice_GetRenderTarget(This->WineD3DDevice,RenderTargetIndex,&pRenderTarget);
444 if (hr == D3D_OK && pRenderTarget != NULL) {
445 IWineD3DSurface_GetParent(pRenderTarget,(IUnknown**)ppRenderTarget);
446 IWineD3DSurface_Release(pRenderTarget);
447 } else {
448 FIXME("Call to IWineD3DDevice_GetRenderTarget failed\n");
449 *ppRenderTarget = NULL;
451 return hr;
454 static HRESULT WINAPI IDirect3DDevice9Impl_SetDepthStencilSurface(LPDIRECT3DDEVICE9 iface, IDirect3DSurface9* pZStencilSurface) {
455 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
456 IDirect3DSurface9Impl *pSurface;
458 TRACE("(%p) Relay\n" , This);
460 pSurface = (IDirect3DSurface9Impl*)pZStencilSurface;
461 return IWineD3DDevice_SetDepthStencilSurface(This->WineD3DDevice,NULL==pSurface?NULL:(IWineD3DSurface*)pSurface->wineD3DSurface);
464 static HRESULT WINAPI IDirect3DDevice9Impl_GetDepthStencilSurface(LPDIRECT3DDEVICE9 iface, IDirect3DSurface9 **ppZStencilSurface) {
465 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
466 HRESULT hr = D3D_OK;
467 IWineD3DSurface *pZStencilSurface;
469 TRACE("(%p) Relay\n" , This);
470 if(ppZStencilSurface == NULL){
471 return D3DERR_INVALIDCALL;
474 hr=IWineD3DDevice_GetDepthStencilSurface(This->WineD3DDevice,&pZStencilSurface);
475 if(hr == D3D_OK && pZStencilSurface != NULL){
476 IWineD3DSurface_GetParent(pZStencilSurface,(IUnknown**)ppZStencilSurface);
477 IWineD3DSurface_Release(pZStencilSurface);
478 }else{
479 FIXME("Call to IWineD3DDevice_GetRenderTarget failed\n");
480 *ppZStencilSurface = NULL;
482 return D3D_OK;
485 static HRESULT WINAPI IDirect3DDevice9Impl_BeginScene(LPDIRECT3DDEVICE9 iface) {
486 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
487 TRACE("(%p) Relay\n" , This);
488 return IWineD3DDevice_BeginScene(This->WineD3DDevice);
491 static HRESULT WINAPI IDirect3DDevice9Impl_EndScene(LPDIRECT3DDEVICE9 iface) {
492 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
493 TRACE("(%p) Relay\n" , This);
494 return IWineD3DDevice_EndScene(This->WineD3DDevice);
498 static HRESULT WINAPI IDirect3DDevice9Impl_Clear(LPDIRECT3DDEVICE9 iface, DWORD Count, CONST D3DRECT* pRects, DWORD Flags, D3DCOLOR Color, float Z, DWORD Stencil) {
499 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
500 TRACE("(%p) Relay\n" , This);
502 /* Note: D3DRECT is compatible with WINED3DRECT */
503 return IWineD3DDevice_Clear(This->WineD3DDevice, Count, (CONST WINED3DRECT*) pRects, Flags, Color, Z, Stencil);
506 static HRESULT WINAPI IDirect3DDevice9Impl_SetTransform(LPDIRECT3DDEVICE9 iface, D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX* lpMatrix) {
507 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
508 TRACE("(%p) Relay\n" , This);
510 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
511 return IWineD3DDevice_SetTransform(This->WineD3DDevice, State, (CONST WINED3DMATRIX*) lpMatrix);
514 static HRESULT WINAPI IDirect3DDevice9Impl_GetTransform(LPDIRECT3DDEVICE9 iface, D3DTRANSFORMSTATETYPE State, D3DMATRIX* pMatrix) {
515 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
516 TRACE("(%p) Relay\n" , This);
518 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
519 return IWineD3DDevice_GetTransform(This->WineD3DDevice, State, (WINED3DMATRIX*) pMatrix);
522 static HRESULT WINAPI IDirect3DDevice9Impl_MultiplyTransform(LPDIRECT3DDEVICE9 iface, D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX* pMatrix) {
523 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
524 TRACE("(%p) Relay\n" , This);
526 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
527 return IWineD3DDevice_MultiplyTransform(This->WineD3DDevice, State, (CONST WINED3DMATRIX*) pMatrix);
530 static HRESULT WINAPI IDirect3DDevice9Impl_SetViewport(LPDIRECT3DDEVICE9 iface, CONST D3DVIEWPORT9* pViewport) {
531 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
532 TRACE("(%p) Relay\n" , This);
534 /* Note: D3DVIEWPORT9 is compatible with WINED3DVIEWPORT */
535 return IWineD3DDevice_SetViewport(This->WineD3DDevice, (const WINED3DVIEWPORT *)pViewport);
538 static HRESULT WINAPI IDirect3DDevice9Impl_GetViewport(LPDIRECT3DDEVICE9 iface, D3DVIEWPORT9* pViewport) {
539 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
540 TRACE("(%p) Relay\n" , This);
542 /* Note: D3DVIEWPORT9 is compatible with WINED3DVIEWPORT */
543 return IWineD3DDevice_GetViewport(This->WineD3DDevice, (WINED3DVIEWPORT *)pViewport);
546 static HRESULT WINAPI IDirect3DDevice9Impl_SetMaterial(LPDIRECT3DDEVICE9 iface, CONST D3DMATERIAL9* pMaterial) {
547 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
548 TRACE("(%p) Relay\n" , This);
550 /* Note: D3DMATERIAL9 is compatible with WINED3DMATERIAL */
551 return IWineD3DDevice_SetMaterial(This->WineD3DDevice, (const WINED3DMATERIAL *)pMaterial);
554 static HRESULT WINAPI IDirect3DDevice9Impl_GetMaterial(LPDIRECT3DDEVICE9 iface, D3DMATERIAL9* pMaterial) {
555 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
556 TRACE("(%p) Relay\n" , This);
558 /* Note: D3DMATERIAL9 is compatible with WINED3DMATERIAL */
559 return IWineD3DDevice_GetMaterial(This->WineD3DDevice, (WINED3DMATERIAL *)pMaterial);
562 static HRESULT WINAPI IDirect3DDevice9Impl_SetLight(LPDIRECT3DDEVICE9 iface, DWORD Index, CONST D3DLIGHT9* pLight) {
563 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
564 TRACE("(%p) Relay\n" , This);
566 /* Note: D3DLIGHT9 is compatible with WINED3DLIGHT */
567 return IWineD3DDevice_SetLight(This->WineD3DDevice, Index, (const WINED3DLIGHT *)pLight);
570 static HRESULT WINAPI IDirect3DDevice9Impl_GetLight(LPDIRECT3DDEVICE9 iface, DWORD Index, D3DLIGHT9* pLight) {
571 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
572 TRACE("(%p) Relay\n" , This);
574 /* Note: D3DLIGHT9 is compatible with WINED3DLIGHT */
575 return IWineD3DDevice_GetLight(This->WineD3DDevice, Index, (WINED3DLIGHT *)pLight);
578 static HRESULT WINAPI IDirect3DDevice9Impl_LightEnable(LPDIRECT3DDEVICE9 iface, DWORD Index, BOOL Enable) {
579 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
580 TRACE("(%p) Relay\n" , This);
581 return IWineD3DDevice_SetLightEnable(This->WineD3DDevice, Index, Enable);
584 static HRESULT WINAPI IDirect3DDevice9Impl_GetLightEnable(LPDIRECT3DDEVICE9 iface, DWORD Index, BOOL* pEnable) {
585 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
586 TRACE("(%p) Relay\n" , This);
587 return IWineD3DDevice_GetLightEnable(This->WineD3DDevice, Index, pEnable);
590 static HRESULT WINAPI IDirect3DDevice9Impl_SetClipPlane(LPDIRECT3DDEVICE9 iface, DWORD Index, CONST float* pPlane) {
591 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
592 TRACE("(%p) Relay\n" , This);
593 return IWineD3DDevice_SetClipPlane(This->WineD3DDevice, Index, pPlane);
596 static HRESULT WINAPI IDirect3DDevice9Impl_GetClipPlane(LPDIRECT3DDEVICE9 iface, DWORD Index, float* pPlane) {
597 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
598 TRACE("(%p) Relay\n" , This);
599 return IWineD3DDevice_GetClipPlane(This->WineD3DDevice, Index, pPlane);
602 static HRESULT WINAPI IDirect3DDevice9Impl_SetRenderState(LPDIRECT3DDEVICE9 iface, D3DRENDERSTATETYPE State, DWORD Value) {
603 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
604 TRACE("(%p) Relay\n" , This);
605 return IWineD3DDevice_SetRenderState(This->WineD3DDevice, State, Value);
608 static HRESULT WINAPI IDirect3DDevice9Impl_GetRenderState(LPDIRECT3DDEVICE9 iface, D3DRENDERSTATETYPE State, DWORD* pValue) {
609 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
610 TRACE("(%p) Relay\n" , This);
611 return IWineD3DDevice_GetRenderState(This->WineD3DDevice, State, pValue);
614 static HRESULT WINAPI IDirect3DDevice9Impl_SetClipStatus(LPDIRECT3DDEVICE9 iface, CONST D3DCLIPSTATUS9* pClipStatus) {
615 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
616 TRACE("(%p) Relay\n" , This);
617 return IWineD3DDevice_SetClipStatus(This->WineD3DDevice, (const WINED3DCLIPSTATUS *)pClipStatus);
620 static HRESULT WINAPI IDirect3DDevice9Impl_GetClipStatus(LPDIRECT3DDEVICE9 iface, D3DCLIPSTATUS9* pClipStatus) {
621 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
622 TRACE("(%p) Relay\n" , This);
623 return IWineD3DDevice_GetClipStatus(This->WineD3DDevice, (WINED3DCLIPSTATUS *)pClipStatus);
626 static HRESULT WINAPI IDirect3DDevice9Impl_GetTexture(LPDIRECT3DDEVICE9 iface, DWORD Stage, IDirect3DBaseTexture9 **ppTexture) {
627 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
628 IWineD3DBaseTexture *retTexture = NULL;
629 HRESULT rc = D3D_OK;
631 TRACE("(%p) Relay\n" , This);
633 if(ppTexture == NULL){
634 return D3DERR_INVALIDCALL;
637 rc = IWineD3DDevice_GetTexture(This->WineD3DDevice, Stage, (IWineD3DBaseTexture **)&retTexture);
638 if (rc == D3D_OK && NULL != retTexture) {
639 IWineD3DBaseTexture_GetParent(retTexture, (IUnknown **)ppTexture);
640 IWineD3DBaseTexture_Release(retTexture);
641 }else{
642 FIXME("Call to get texture (%d) failed (%p)\n", Stage, retTexture);
643 *ppTexture = NULL;
645 return rc;
648 static HRESULT WINAPI IDirect3DDevice9Impl_SetTexture(LPDIRECT3DDEVICE9 iface, DWORD Stage, IDirect3DBaseTexture9* pTexture) {
649 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
650 TRACE("(%p) Relay %d %p\n" , This, Stage, pTexture);
651 return IWineD3DDevice_SetTexture(This->WineD3DDevice, Stage,
652 pTexture==NULL ? NULL:((IDirect3DBaseTexture9Impl *)pTexture)->wineD3DBaseTexture);
655 static HRESULT WINAPI IDirect3DDevice9Impl_GetTextureStageState(LPDIRECT3DDEVICE9 iface, DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD* pValue) {
656 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
657 TRACE("(%p) Relay\n" , This);
658 return IWineD3DDevice_GetTextureStageState(This->WineD3DDevice, Stage, Type, pValue);
661 static HRESULT WINAPI IDirect3DDevice9Impl_SetTextureStageState(LPDIRECT3DDEVICE9 iface, DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD Value) {
662 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
663 TRACE("(%p) Relay\n" , This);
664 return IWineD3DDevice_SetTextureStageState(This->WineD3DDevice, Stage, Type, Value);
667 static HRESULT WINAPI IDirect3DDevice9Impl_GetSamplerState(LPDIRECT3DDEVICE9 iface, DWORD Sampler, D3DSAMPLERSTATETYPE Type, DWORD* pValue) {
668 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
669 TRACE("(%p) Relay\n" , This);
670 return IWineD3DDevice_GetSamplerState(This->WineD3DDevice, Sampler, Type, pValue);
673 static HRESULT WINAPI IDirect3DDevice9Impl_SetSamplerState(LPDIRECT3DDEVICE9 iface, DWORD Sampler, D3DSAMPLERSTATETYPE Type, DWORD Value) {
674 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
675 TRACE("(%p) Relay\n" , This);
676 return IWineD3DDevice_SetSamplerState(This->WineD3DDevice, Sampler, Type, Value);
679 static HRESULT WINAPI IDirect3DDevice9Impl_ValidateDevice(LPDIRECT3DDEVICE9 iface, DWORD* pNumPasses) {
680 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
681 TRACE("(%p) Relay\n" , This);
682 return IWineD3DDevice_ValidateDevice(This->WineD3DDevice, pNumPasses);
685 static HRESULT WINAPI IDirect3DDevice9Impl_SetPaletteEntries(LPDIRECT3DDEVICE9 iface, UINT PaletteNumber, CONST PALETTEENTRY* pEntries) {
686 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
687 TRACE("(%p) Relay\n" , This);
688 return IWineD3DDevice_SetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
691 static HRESULT WINAPI IDirect3DDevice9Impl_GetPaletteEntries(LPDIRECT3DDEVICE9 iface, UINT PaletteNumber, PALETTEENTRY* pEntries) {
692 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
693 TRACE("(%p) Relay\n" , This);
694 return IWineD3DDevice_GetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
697 static HRESULT WINAPI IDirect3DDevice9Impl_SetCurrentTexturePalette(LPDIRECT3DDEVICE9 iface, UINT PaletteNumber) {
698 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
699 TRACE("(%p) Relay\n" , This);
700 return IWineD3DDevice_SetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
703 static HRESULT WINAPI IDirect3DDevice9Impl_GetCurrentTexturePalette(LPDIRECT3DDEVICE9 iface, UINT* PaletteNumber) {
704 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
705 TRACE("(%p) Relay\n" , This);
706 return IWineD3DDevice_GetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
709 static HRESULT WINAPI IDirect3DDevice9Impl_SetScissorRect(LPDIRECT3DDEVICE9 iface, CONST RECT* pRect) {
710 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
711 TRACE("(%p) Relay\n" , This);
712 return IWineD3DDevice_SetScissorRect(This->WineD3DDevice, pRect);
715 static HRESULT WINAPI IDirect3DDevice9Impl_GetScissorRect(LPDIRECT3DDEVICE9 iface, RECT* pRect) {
716 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
717 TRACE("(%p) Relay\n" , This);
718 return IWineD3DDevice_GetScissorRect(This->WineD3DDevice, pRect);
721 static HRESULT WINAPI IDirect3DDevice9Impl_SetSoftwareVertexProcessing(LPDIRECT3DDEVICE9 iface, BOOL bSoftware) {
722 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
723 TRACE("(%p) Relay\n" , This);
724 return IWineD3DDevice_SetSoftwareVertexProcessing(This->WineD3DDevice, bSoftware);
727 static BOOL WINAPI IDirect3DDevice9Impl_GetSoftwareVertexProcessing(LPDIRECT3DDEVICE9 iface) {
728 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
729 TRACE("(%p) Relay\n" , This);
730 return IWineD3DDevice_GetSoftwareVertexProcessing(This->WineD3DDevice);
733 static HRESULT WINAPI IDirect3DDevice9Impl_SetNPatchMode(LPDIRECT3DDEVICE9 iface, float nSegments) {
734 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
735 TRACE("(%p) Relay\n" , This);
736 return IWineD3DDevice_SetNPatchMode(This->WineD3DDevice, nSegments);
739 static float WINAPI IDirect3DDevice9Impl_GetNPatchMode(LPDIRECT3DDEVICE9 iface) {
740 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
741 TRACE("(%p) Relay\n" , This);
742 return IWineD3DDevice_GetNPatchMode(This->WineD3DDevice);
745 static HRESULT WINAPI IDirect3DDevice9Impl_DrawPrimitive(LPDIRECT3DDEVICE9 iface, D3DPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT PrimitiveCount) {
746 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
747 TRACE("(%p) Relay\n" , This);
748 return IWineD3DDevice_DrawPrimitive(This->WineD3DDevice, PrimitiveType, StartVertex, PrimitiveCount);
751 static HRESULT WINAPI IDirect3DDevice9Impl_DrawIndexedPrimitive(LPDIRECT3DDEVICE9 iface, D3DPRIMITIVETYPE PrimitiveType,
752 INT BaseVertexIndex, UINT MinVertexIndex, UINT NumVertices, UINT startIndex, UINT primCount) {
753 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
754 TRACE("(%p) Relay\n" , This);
756 /* D3D8 passes the baseVertexIndex in SetIndices, and due to the stateblock functions wined3d has to work that way */
757 IWineD3DDevice_SetBaseVertexIndex(This->WineD3DDevice, BaseVertexIndex);
758 return IWineD3DDevice_DrawIndexedPrimitive(This->WineD3DDevice, PrimitiveType, MinVertexIndex, NumVertices, startIndex, primCount);
761 static HRESULT WINAPI IDirect3DDevice9Impl_DrawPrimitiveUP(LPDIRECT3DDEVICE9 iface, D3DPRIMITIVETYPE PrimitiveType, UINT PrimitiveCount, CONST void* pVertexStreamZeroData, UINT VertexStreamZeroStride) {
762 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
763 TRACE("(%p) Relay\n" , This);
764 return IWineD3DDevice_DrawPrimitiveUP(This->WineD3DDevice, PrimitiveType, PrimitiveCount, pVertexStreamZeroData, VertexStreamZeroStride);
767 static HRESULT WINAPI IDirect3DDevice9Impl_DrawIndexedPrimitiveUP(LPDIRECT3DDEVICE9 iface, D3DPRIMITIVETYPE PrimitiveType, UINT MinVertexIndex,
768 UINT NumVertexIndices, UINT PrimitiveCount, CONST void* pIndexData,
769 D3DFORMAT IndexDataFormat, CONST void* pVertexStreamZeroData, UINT VertexStreamZeroStride) {
770 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
771 TRACE("(%p) Relay\n" , This);
772 return IWineD3DDevice_DrawIndexedPrimitiveUP(This->WineD3DDevice, PrimitiveType, MinVertexIndex, NumVertexIndices, PrimitiveCount,
773 pIndexData, IndexDataFormat, pVertexStreamZeroData, VertexStreamZeroStride);
776 static HRESULT WINAPI IDirect3DDevice9Impl_ProcessVertices(LPDIRECT3DDEVICE9 iface, UINT SrcStartIndex, UINT DestIndex, UINT VertexCount, IDirect3DVertexBuffer9* pDestBuffer, IDirect3DVertexDeclaration9* pVertexDecl, DWORD Flags) {
777 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
778 TRACE("(%p) Relay\n" , This);
779 return IWineD3DDevice_ProcessVertices(This->WineD3DDevice,SrcStartIndex, DestIndex, VertexCount, ((IDirect3DVertexBuffer9Impl *)pDestBuffer)->wineD3DVertexBuffer, ((IDirect3DVertexBuffer9Impl *)pVertexDecl)->wineD3DVertexBuffer, Flags);
782 IDirect3DVertexDeclaration9 *getConvertedDecl(IDirect3DDevice9Impl *This, DWORD fvf) {
783 HRESULT hr;
784 D3DVERTEXELEMENT9* elements = NULL;
785 IDirect3DVertexDeclaration9* pDecl = NULL;
786 int p, low, high; /* deliberately signed */
787 IDirect3DVertexDeclaration9 **convertedDecls = This->convertedDecls;
789 TRACE("Searching for declaration for fvf %08x... ", fvf);
791 low = 0;
792 high = This->numConvertedDecls - 1;
793 while(low <= high) {
794 p = (low + high) >> 1;
795 TRACE("%d ", p);
796 if(((IDirect3DVertexDeclaration9Impl *) convertedDecls[p])->convFVF == fvf) {
797 TRACE("found %p\n", convertedDecls[p]);
798 return convertedDecls[p];
799 } else if(((IDirect3DVertexDeclaration9Impl *) convertedDecls[p])->convFVF < fvf) {
800 low = p + 1;
801 } else {
802 high = p - 1;
805 TRACE("not found. Creating and inserting at position %d.\n", low);
807 hr = vdecl_convert_fvf(fvf, &elements);
808 if (hr != S_OK) return NULL;
810 hr = IDirect3DDevice9Impl_CreateVertexDeclaration((IDirect3DDevice9 *) This, elements, &pDecl);
811 if (hr != S_OK) return NULL;
813 if(This->declArraySize == This->numConvertedDecls) {
814 int grow = max(This->declArraySize * 0.5, 1);
815 convertedDecls = HeapReAlloc(GetProcessHeap(), 0, convertedDecls,
816 sizeof(convertedDecls[0]) * (This->numConvertedDecls + grow));
817 if(!convertedDecls) {
818 /* This will destroy it */
819 IDirect3DVertexDeclaration9_Release(pDecl);
820 return NULL;
822 This->convertedDecls = convertedDecls;
823 This->declArraySize += grow;
826 memmove(convertedDecls + low + 1, convertedDecls + low, sizeof(IDirect3DVertexDeclaration9Impl *) * (This->numConvertedDecls - low));
827 convertedDecls[low] = pDecl;
828 This->numConvertedDecls++;
830 /* Will prevent the decl from beeing destroyed */
831 ((IDirect3DVertexDeclaration9Impl *) pDecl)->convFVF = fvf;
832 IDirect3DVertexDeclaration9_Release(pDecl); /* Does not destroy now */
834 TRACE("Returning %p. %d decls in array\n", pDecl, This->numConvertedDecls);
835 return pDecl;
838 HRESULT WINAPI IDirect3DDevice9Impl_SetFVF(LPDIRECT3DDEVICE9 iface, DWORD FVF) {
839 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
840 TRACE("(%p) Relay\n" , This);
842 if (0 != FVF) {
843 HRESULT hr;
844 IDirect3DVertexDeclaration9* pDecl = getConvertedDecl(This, FVF);
846 if(!pDecl) {
847 /* Any situation when this should happen, except out of memory? */
848 ERR("Failed to create a converted vertex declaration\n");
849 return D3DERR_DRIVERINTERNALERROR;
852 hr = IDirect3DDevice9Impl_SetVertexDeclaration(iface, pDecl);
853 if (hr != S_OK) return hr;
856 return IWineD3DDevice_SetFVF(This->WineD3DDevice, FVF);
859 HRESULT WINAPI IDirect3DDevice9Impl_GetFVF(LPDIRECT3DDEVICE9 iface, DWORD* pFVF) {
860 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
861 TRACE("(%p) Relay\n" , This);
862 return IWineD3DDevice_GetFVF(This->WineD3DDevice, pFVF);
865 HRESULT WINAPI IDirect3DDevice9Impl_SetStreamSource(LPDIRECT3DDEVICE9 iface, UINT StreamNumber, IDirect3DVertexBuffer9* pStreamData, UINT OffsetInBytes, UINT Stride) {
866 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
867 TRACE("(%p) Relay\n" , This);
868 return IWineD3DDevice_SetStreamSource(This->WineD3DDevice, StreamNumber,
869 pStreamData==NULL ? NULL:((IDirect3DVertexBuffer9Impl *)pStreamData)->wineD3DVertexBuffer,
870 OffsetInBytes, Stride);
873 HRESULT WINAPI IDirect3DDevice9Impl_GetStreamSource(LPDIRECT3DDEVICE9 iface, UINT StreamNumber, IDirect3DVertexBuffer9 **pStream, UINT* OffsetInBytes, UINT* pStride) {
874 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
875 IWineD3DVertexBuffer *retStream = NULL;
876 HRESULT rc = D3D_OK;
878 TRACE("(%p) Relay\n" , This);
880 if(pStream == NULL){
881 return D3DERR_INVALIDCALL;
884 rc = IWineD3DDevice_GetStreamSource(This->WineD3DDevice, StreamNumber, (IWineD3DVertexBuffer **)&retStream, OffsetInBytes, pStride);
885 if (rc == D3D_OK && NULL != retStream) {
886 IWineD3DVertexBuffer_GetParent(retStream, (IUnknown **)pStream);
887 IWineD3DVertexBuffer_Release(retStream);
888 }else{
889 if (rc != D3D_OK){
890 FIXME("Call to GetStreamSource failed %p %p\n", OffsetInBytes, pStride);
892 *pStream = NULL;
894 return rc;
897 static HRESULT WINAPI IDirect3DDevice9Impl_SetStreamSourceFreq(LPDIRECT3DDEVICE9 iface, UINT StreamNumber, UINT Divider) {
898 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
899 TRACE("(%p) Relay\n" , This);
900 IWineD3DDevice_SetStreamSourceFreq(This->WineD3DDevice, StreamNumber, Divider);
901 return D3D_OK;
904 static HRESULT WINAPI IDirect3DDevice9Impl_GetStreamSourceFreq(LPDIRECT3DDEVICE9 iface, UINT StreamNumber, UINT* Divider) {
905 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
906 TRACE("(%p) Relay\n" , This);
907 return IWineD3DDevice_GetStreamSourceFreq(This->WineD3DDevice, StreamNumber, Divider);
910 static HRESULT WINAPI IDirect3DDevice9Impl_SetIndices(LPDIRECT3DDEVICE9 iface, IDirect3DIndexBuffer9* pIndexData) {
911 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
912 TRACE("(%p) Relay\n", This);
913 return IWineD3DDevice_SetIndices(This->WineD3DDevice,
914 pIndexData==NULL ? NULL:((IDirect3DIndexBuffer9Impl *)pIndexData)->wineD3DIndexBuffer,
918 static HRESULT WINAPI IDirect3DDevice9Impl_GetIndices(LPDIRECT3DDEVICE9 iface, IDirect3DIndexBuffer9 **ppIndexData) {
919 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
920 IWineD3DIndexBuffer *retIndexData = NULL;
921 HRESULT rc = D3D_OK;
922 UINT tmp;
924 TRACE("(%p) Relay\n", This);
926 if(ppIndexData == NULL){
927 return D3DERR_INVALIDCALL;
930 rc = IWineD3DDevice_GetIndices(This->WineD3DDevice, &retIndexData, &tmp);
931 if (rc == D3D_OK && NULL != retIndexData) {
932 IWineD3DIndexBuffer_GetParent(retIndexData, (IUnknown **)ppIndexData);
933 IWineD3DIndexBuffer_Release(retIndexData);
934 }else{
935 if(rc != D3D_OK) FIXME("Call to GetIndices failed\n");
936 *ppIndexData = NULL;
938 return rc;
941 static HRESULT WINAPI IDirect3DDevice9Impl_DrawRectPatch(LPDIRECT3DDEVICE9 iface, UINT Handle, CONST float* pNumSegs, CONST D3DRECTPATCH_INFO* pRectPatchInfo) {
942 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
943 TRACE("(%p) Relay\n", This);
944 return IWineD3DDevice_DrawRectPatch(This->WineD3DDevice, Handle, pNumSegs, (CONST WINED3DRECTPATCH_INFO *)pRectPatchInfo);
946 /*http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directx/graphics/reference/d3d/interfaces/idirect3ddevice9/DrawTriPatch.asp*/
947 static HRESULT WINAPI IDirect3DDevice9Impl_DrawTriPatch(LPDIRECT3DDEVICE9 iface, UINT Handle, CONST float* pNumSegs, CONST D3DTRIPATCH_INFO* pTriPatchInfo) {
948 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
949 TRACE("(%p) Relay\n", This);
950 return IWineD3DDevice_DrawTriPatch(This->WineD3DDevice, Handle, pNumSegs, (CONST WINED3DTRIPATCH_INFO *)pTriPatchInfo);
953 static HRESULT WINAPI IDirect3DDevice9Impl_DeletePatch(LPDIRECT3DDEVICE9 iface, UINT Handle) {
954 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
955 TRACE("(%p) Relay\n", This);
956 return IWineD3DDevice_DeletePatch(This->WineD3DDevice, Handle);
959 const IDirect3DDevice9Vtbl Direct3DDevice9_Vtbl =
961 /* IUnknown */
962 IDirect3DDevice9Impl_QueryInterface,
963 IDirect3DDevice9Impl_AddRef,
964 IDirect3DDevice9Impl_Release,
965 /* IDirect3DDevice9 */
966 IDirect3DDevice9Impl_TestCooperativeLevel,
967 IDirect3DDevice9Impl_GetAvailableTextureMem,
968 IDirect3DDevice9Impl_EvictManagedResources,
969 IDirect3DDevice9Impl_GetDirect3D,
970 IDirect3DDevice9Impl_GetDeviceCaps,
971 IDirect3DDevice9Impl_GetDisplayMode,
972 IDirect3DDevice9Impl_GetCreationParameters,
973 IDirect3DDevice9Impl_SetCursorProperties,
974 IDirect3DDevice9Impl_SetCursorPosition,
975 IDirect3DDevice9Impl_ShowCursor,
976 IDirect3DDevice9Impl_CreateAdditionalSwapChain,
977 IDirect3DDevice9Impl_GetSwapChain,
978 IDirect3DDevice9Impl_GetNumberOfSwapChains,
979 IDirect3DDevice9Impl_Reset,
980 IDirect3DDevice9Impl_Present,
981 IDirect3DDevice9Impl_GetBackBuffer,
982 IDirect3DDevice9Impl_GetRasterStatus,
983 IDirect3DDevice9Impl_SetDialogBoxMode,
984 IDirect3DDevice9Impl_SetGammaRamp,
985 IDirect3DDevice9Impl_GetGammaRamp,
986 IDirect3DDevice9Impl_CreateTexture,
987 IDirect3DDevice9Impl_CreateVolumeTexture,
988 IDirect3DDevice9Impl_CreateCubeTexture,
989 IDirect3DDevice9Impl_CreateVertexBuffer,
990 IDirect3DDevice9Impl_CreateIndexBuffer,
991 IDirect3DDevice9Impl_CreateRenderTarget,
992 IDirect3DDevice9Impl_CreateDepthStencilSurface,
993 IDirect3DDevice9Impl_UpdateSurface,
994 IDirect3DDevice9Impl_UpdateTexture,
995 IDirect3DDevice9Impl_GetRenderTargetData,
996 IDirect3DDevice9Impl_GetFrontBufferData,
997 IDirect3DDevice9Impl_StretchRect,
998 IDirect3DDevice9Impl_ColorFill,
999 IDirect3DDevice9Impl_CreateOffscreenPlainSurface,
1000 IDirect3DDevice9Impl_SetRenderTarget,
1001 IDirect3DDevice9Impl_GetRenderTarget,
1002 IDirect3DDevice9Impl_SetDepthStencilSurface,
1003 IDirect3DDevice9Impl_GetDepthStencilSurface,
1004 IDirect3DDevice9Impl_BeginScene,
1005 IDirect3DDevice9Impl_EndScene,
1006 IDirect3DDevice9Impl_Clear,
1007 IDirect3DDevice9Impl_SetTransform,
1008 IDirect3DDevice9Impl_GetTransform,
1009 IDirect3DDevice9Impl_MultiplyTransform,
1010 IDirect3DDevice9Impl_SetViewport,
1011 IDirect3DDevice9Impl_GetViewport,
1012 IDirect3DDevice9Impl_SetMaterial,
1013 IDirect3DDevice9Impl_GetMaterial,
1014 IDirect3DDevice9Impl_SetLight,
1015 IDirect3DDevice9Impl_GetLight,
1016 IDirect3DDevice9Impl_LightEnable,
1017 IDirect3DDevice9Impl_GetLightEnable,
1018 IDirect3DDevice9Impl_SetClipPlane,
1019 IDirect3DDevice9Impl_GetClipPlane,
1020 IDirect3DDevice9Impl_SetRenderState,
1021 IDirect3DDevice9Impl_GetRenderState,
1022 IDirect3DDevice9Impl_CreateStateBlock,
1023 IDirect3DDevice9Impl_BeginStateBlock,
1024 IDirect3DDevice9Impl_EndStateBlock,
1025 IDirect3DDevice9Impl_SetClipStatus,
1026 IDirect3DDevice9Impl_GetClipStatus,
1027 IDirect3DDevice9Impl_GetTexture,
1028 IDirect3DDevice9Impl_SetTexture,
1029 IDirect3DDevice9Impl_GetTextureStageState,
1030 IDirect3DDevice9Impl_SetTextureStageState,
1031 IDirect3DDevice9Impl_GetSamplerState,
1032 IDirect3DDevice9Impl_SetSamplerState,
1033 IDirect3DDevice9Impl_ValidateDevice,
1034 IDirect3DDevice9Impl_SetPaletteEntries,
1035 IDirect3DDevice9Impl_GetPaletteEntries,
1036 IDirect3DDevice9Impl_SetCurrentTexturePalette,
1037 IDirect3DDevice9Impl_GetCurrentTexturePalette,
1038 IDirect3DDevice9Impl_SetScissorRect,
1039 IDirect3DDevice9Impl_GetScissorRect,
1040 IDirect3DDevice9Impl_SetSoftwareVertexProcessing,
1041 IDirect3DDevice9Impl_GetSoftwareVertexProcessing,
1042 IDirect3DDevice9Impl_SetNPatchMode,
1043 IDirect3DDevice9Impl_GetNPatchMode,
1044 IDirect3DDevice9Impl_DrawPrimitive,
1045 IDirect3DDevice9Impl_DrawIndexedPrimitive,
1046 IDirect3DDevice9Impl_DrawPrimitiveUP,
1047 IDirect3DDevice9Impl_DrawIndexedPrimitiveUP,
1048 IDirect3DDevice9Impl_ProcessVertices,
1049 IDirect3DDevice9Impl_CreateVertexDeclaration,
1050 IDirect3DDevice9Impl_SetVertexDeclaration,
1051 IDirect3DDevice9Impl_GetVertexDeclaration,
1052 IDirect3DDevice9Impl_SetFVF,
1053 IDirect3DDevice9Impl_GetFVF,
1054 IDirect3DDevice9Impl_CreateVertexShader,
1055 IDirect3DDevice9Impl_SetVertexShader,
1056 IDirect3DDevice9Impl_GetVertexShader,
1057 IDirect3DDevice9Impl_SetVertexShaderConstantF,
1058 IDirect3DDevice9Impl_GetVertexShaderConstantF,
1059 IDirect3DDevice9Impl_SetVertexShaderConstantI,
1060 IDirect3DDevice9Impl_GetVertexShaderConstantI,
1061 IDirect3DDevice9Impl_SetVertexShaderConstantB,
1062 IDirect3DDevice9Impl_GetVertexShaderConstantB,
1063 IDirect3DDevice9Impl_SetStreamSource,
1064 IDirect3DDevice9Impl_GetStreamSource,
1065 IDirect3DDevice9Impl_SetStreamSourceFreq,
1066 IDirect3DDevice9Impl_GetStreamSourceFreq,
1067 IDirect3DDevice9Impl_SetIndices,
1068 IDirect3DDevice9Impl_GetIndices,
1069 IDirect3DDevice9Impl_CreatePixelShader,
1070 IDirect3DDevice9Impl_SetPixelShader,
1071 IDirect3DDevice9Impl_GetPixelShader,
1072 IDirect3DDevice9Impl_SetPixelShaderConstantF,
1073 IDirect3DDevice9Impl_GetPixelShaderConstantF,
1074 IDirect3DDevice9Impl_SetPixelShaderConstantI,
1075 IDirect3DDevice9Impl_GetPixelShaderConstantI,
1076 IDirect3DDevice9Impl_SetPixelShaderConstantB,
1077 IDirect3DDevice9Impl_GetPixelShaderConstantB,
1078 IDirect3DDevice9Impl_DrawRectPatch,
1079 IDirect3DDevice9Impl_DrawTriPatch,
1080 IDirect3DDevice9Impl_DeletePatch,
1081 IDirect3DDevice9Impl_CreateQuery
1085 /* Internal function called back during the CreateDevice to create a render target */
1086 HRESULT WINAPI D3D9CB_CreateSurface(IUnknown *device, IUnknown *pSuperior, UINT Width, UINT Height,
1087 WINED3DFORMAT Format, DWORD Usage, WINED3DPOOL Pool, UINT Level,
1088 IWineD3DSurface** ppSurface, HANDLE* pSharedHandle) {
1090 HRESULT res = D3D_OK;
1091 IDirect3DSurface9Impl *d3dSurface = NULL;
1092 BOOL Lockable = TRUE;
1094 if((Pool == D3DPOOL_DEFAULT && Usage != D3DUSAGE_DYNAMIC))
1095 Lockable = FALSE;
1097 TRACE("relay\n");
1098 res = IDirect3DDevice9Impl_CreateSurface((IDirect3DDevice9 *)device, Width, Height, (D3DFORMAT)Format,
1099 Lockable, FALSE/*Discard*/, Level, (IDirect3DSurface9 **)&d3dSurface, D3DRTYPE_SURFACE,
1100 Usage, (D3DPOOL) Pool, D3DMULTISAMPLE_NONE, 0 /* MultisampleQuality */, pSharedHandle);
1102 if (SUCCEEDED(res)) {
1103 *ppSurface = d3dSurface->wineD3DSurface;
1104 d3dSurface->container = pSuperior;
1105 IUnknown_Release(d3dSurface->parentDevice);
1106 d3dSurface->parentDevice = NULL;
1107 d3dSurface->forwardReference = pSuperior;
1108 } else {
1109 FIXME("(%p) IDirect3DDevice9_CreateSurface failed\n", device);
1111 return res;
1114 ULONG WINAPI D3D9CB_DestroySurface(IWineD3DSurface *pSurface) {
1115 IDirect3DSurface9Impl* surfaceParent;
1116 TRACE("(%p) call back\n", pSurface);
1118 IWineD3DSurface_GetParent(pSurface, (IUnknown **) &surfaceParent);
1119 /* GetParent's AddRef was forwarded to an object in destruction.
1120 * Releasing it here again would cause an endless recursion. */
1121 surfaceParent->forwardReference = NULL;
1122 return IDirect3DSurface9_Release((IDirect3DSurface9*) surfaceParent);