Add trailing '\n's to ok() and TRACE() calls.
[wine] / dlls / d3d9 / device.c
1 /*
2  * IDirect3DDevice9 implementation
3  *
4  * Copyright 2002-2005 Jason Edmeades
5  * Copyright 2002-2005 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
22
23 #include "config.h"
24 #include "d3d9_private.h"
25
26 WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
27
28
29 /* IDirect3D IUnknown parts follow: */
30 HRESULT WINAPI IDirect3DDevice9Impl_QueryInterface(LPDIRECT3DDEVICE9 iface, REFIID riid, LPVOID* ppobj) {
31     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
32
33     if (IsEqualGUID(riid, &IID_IUnknown)
34         || IsEqualGUID(riid, &IID_IDirect3DDevice9)) {
35         IUnknown_AddRef(iface);
36         *ppobj = This;
37         return D3D_OK;
38     }
39
40     WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
41     return E_NOINTERFACE;
42 }
43
44 ULONG WINAPI IDirect3DDevice9Impl_AddRef(LPDIRECT3DDEVICE9 iface) {
45     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
46     ULONG ref = InterlockedIncrement(&This->ref);
47
48     TRACE("(%p) : AddRef from %ld\n", This, ref - 1);
49
50     return ref;
51 }
52
53 ULONG WINAPI IDirect3DDevice9Impl_Release(LPDIRECT3DDEVICE9 iface) {
54     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
55     ULONG ref = InterlockedDecrement(&This->ref);
56
57     TRACE("(%p) : ReleaseRef to %ld\n", This, ref);
58
59     if (ref == 0) {
60       IWineD3DDevice_Release(This->WineD3DDevice);
61       HeapFree(GetProcessHeap(), 0, This);
62     }
63     return ref;
64 }
65
66 /* IDirect3DDevice Interface follow: */
67 HRESULT  WINAPI  IDirect3DDevice9Impl_TestCooperativeLevel(LPDIRECT3DDEVICE9 iface) {
68     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
69     
70     TRACE("(%p) : Relay\n", This);
71     return IWineD3DDevice_TestCooperativeLevel(This->WineD3DDevice);
72 }
73
74 UINT     WINAPI  IDirect3DDevice9Impl_GetAvailableTextureMem(LPDIRECT3DDEVICE9 iface) {
75     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
76     
77     TRACE("(%p) Relay\n", This);
78     return IWineD3DDevice_GetAvailableTextureMem(This->WineD3DDevice);    
79 }
80
81 HRESULT  WINAPI  IDirect3DDevice9Impl_EvictManagedResources(LPDIRECT3DDEVICE9 iface) {
82     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
83
84     TRACE("(%p) : Relay\n", This);
85     return IWineD3DDevice_EvictManagedResources(This->WineD3DDevice);
86 }
87
88 HRESULT  WINAPI  IDirect3DDevice9Impl_GetDirect3D(LPDIRECT3DDEVICE9 iface, IDirect3D9** ppD3D9) {
89     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
90     HRESULT hr = D3D_OK;
91     IWineD3D* pWineD3D;
92
93     TRACE("(%p) Relay\n", This);
94
95     if (NULL == ppD3D9) {
96         return D3DERR_INVALIDCALL;
97     }
98     hr = IWineD3DDevice_GetDirect3D(This->WineD3DDevice, &pWineD3D);
99     if (hr == D3D_OK && pWineD3D != NULL)
100     {
101         IWineD3DResource_GetParent((IWineD3DResource *)pWineD3D,(IUnknown **)ppD3D9);
102         IWineD3DResource_Release((IWineD3DResource *)pWineD3D);
103     } else {
104         FIXME("Call to IWineD3DDevice_GetDirect3D failed\n");
105         *ppD3D9 = NULL;
106     }
107     TRACE("(%p) returning %p\n", This, *ppD3D9);
108     return hr;
109 }
110
111 HRESULT  WINAPI  IDirect3DDevice9Impl_GetDeviceCaps(LPDIRECT3DDEVICE9 iface, D3DCAPS9* pCaps) {
112     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
113     HRESULT hrc = D3D_OK;
114     WINED3DCAPS *pWineCaps;
115
116     TRACE("(%p) : Relay pCaps %p \n", This, pCaps);
117     if(NULL == pCaps){
118         return D3DERR_INVALIDCALL;
119     }
120     pWineCaps = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WINED3DCAPS));
121     if(pWineCaps == NULL){
122         return D3DERR_INVALIDCALL; /* well this is what MSDN says to return */
123     }
124
125     D3D9CAPSTOWINECAPS(pCaps, pWineCaps)
126     hrc = IWineD3DDevice_GetDeviceCaps(This->WineD3DDevice, pWineCaps);
127     HeapFree(GetProcessHeap(), 0, pWineCaps);
128     TRACE("Returning %p %p\n", This, pCaps);
129     return hrc;
130 }
131
132 HRESULT  WINAPI  IDirect3DDevice9Impl_GetDisplayMode(LPDIRECT3DDEVICE9 iface, UINT iSwapChain, D3DDISPLAYMODE* pMode) {
133     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
134     TRACE("(%p) Relay\n", This);
135     return IWineD3DDevice_GetDisplayMode(This->WineD3DDevice, iSwapChain, pMode);
136 }
137
138 HRESULT  WINAPI  IDirect3DDevice9Impl_GetCreationParameters(LPDIRECT3DDEVICE9 iface, D3DDEVICE_CREATION_PARAMETERS *pParameters) {
139     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
140     TRACE("(%p) Relay\n", This);
141     return IWineD3DDevice_GetCreationParameters(This->WineD3DDevice, pParameters);
142 }
143
144 HRESULT  WINAPI  IDirect3DDevice9Impl_SetCursorProperties(LPDIRECT3DDEVICE9 iface, UINT XHotSpot, UINT YHotSpot, IDirect3DSurface9* pCursorBitmap) {
145     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
146     IDirect3DSurface9Impl *pSurface = (IDirect3DSurface9Impl*)pCursorBitmap;
147     TRACE("(%p) Relay\n", This);
148     return IWineD3DDevice_SetCursorProperties(This->WineD3DDevice,XHotSpot,YHotSpot,(IWineD3DSurface*)pSurface->wineD3DSurface);
149 }
150
151 void     WINAPI  IDirect3DDevice9Impl_SetCursorPosition(LPDIRECT3DDEVICE9 iface, int XScreenSpace, int YScreenSpace, DWORD Flags) {
152     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
153     TRACE("(%p) Relay\n", This);
154     return IWineD3DDevice_SetCursorPosition(This->WineD3DDevice, XScreenSpace, YScreenSpace, Flags);
155 }
156
157 BOOL     WINAPI  IDirect3DDevice9Impl_ShowCursor(LPDIRECT3DDEVICE9 iface, BOOL bShow) {
158     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
159     TRACE("(%p) Relay\n", This);
160
161     return IWineD3DDevice_ShowCursor(This->WineD3DDevice, bShow);
162 }
163
164 HRESULT  WINAPI  IDirect3DDevice9Impl_Reset(LPDIRECT3DDEVICE9 iface, D3DPRESENT_PARAMETERS* pPresentationParameters) {
165     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
166     WINED3DPRESENT_PARAMETERS localParameters;
167     TRACE("(%p) Relay pPresentationParameters(%p)\n", This, pPresentationParameters);
168         
169     localParameters.BackBufferWidth                = &pPresentationParameters->BackBufferWidth;
170     localParameters.BackBufferHeight               = &pPresentationParameters->BackBufferHeight;           
171     localParameters.BackBufferFormat               = (WINED3DFORMAT *)&pPresentationParameters->BackBufferFormat;
172     localParameters.BackBufferCount                = &pPresentationParameters->BackBufferCount;            
173     localParameters.MultiSampleType                = &pPresentationParameters->MultiSampleType;            
174     localParameters.MultiSampleQuality             = &pPresentationParameters->MultiSampleQuality;         
175     localParameters.SwapEffect                     = &pPresentationParameters->SwapEffect;                 
176     localParameters.hDeviceWindow                  = &pPresentationParameters->hDeviceWindow;              
177     localParameters.Windowed                       = &pPresentationParameters->Windowed;                   
178     localParameters.EnableAutoDepthStencil         = &pPresentationParameters->EnableAutoDepthStencil;     
179     localParameters.AutoDepthStencilFormat         = (WINED3DFORMAT *)&pPresentationParameters->AutoDepthStencilFormat;     
180     localParameters.Flags                          = &pPresentationParameters->Flags;                      
181     localParameters.FullScreen_RefreshRateInHz     = &pPresentationParameters->FullScreen_RefreshRateInHz; 
182     localParameters.PresentationInterval           = &pPresentationParameters->PresentationInterval;       
183     return IWineD3DDevice_Reset(This->WineD3DDevice, &localParameters);
184 }
185
186 HRESULT  WINAPI  IDirect3DDevice9Impl_Present(LPDIRECT3DDEVICE9 iface, CONST RECT* pSourceRect,CONST RECT* pDestRect,HWND hDestWindowOverride,CONST RGNDATA*
187  pDirtyRegion) {
188     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
189     TRACE("(%p) Relay\n", This);
190     return IWineD3DDevice_Present(This->WineD3DDevice, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
191 }
192
193 HRESULT  WINAPI  IDirect3DDevice9Impl_GetBackBuffer(LPDIRECT3DDEVICE9 iface, UINT iSwapChain, UINT BackBuffer, D3DBACKBUFFER_TYPE Type, IDirect3DSurface9 ** ppBackBuffer) {
194     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
195     IWineD3DSurface *retSurface = NULL;
196     HRESULT rc = D3D_OK;
197
198     TRACE("(%p) Relay\n", This);
199
200     rc = IWineD3DDevice_GetBackBuffer(This->WineD3DDevice, iSwapChain, BackBuffer, Type, (IWineD3DSurface **)&retSurface);
201     if (rc == D3D_OK && NULL != retSurface && NULL != ppBackBuffer) {
202         IWineD3DSurface_GetParent(retSurface, (IUnknown **)ppBackBuffer);
203         IWineD3DSurface_Release(retSurface);
204     }
205     return rc;
206 }
207 HRESULT  WINAPI  IDirect3DDevice9Impl_GetRasterStatus(LPDIRECT3DDEVICE9 iface, UINT iSwapChain, D3DRASTER_STATUS* pRasterStatus) {
208     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
209     TRACE("(%p) Relay\n", This);
210     
211     return IWineD3DDevice_GetRasterStatus(This->WineD3DDevice, iSwapChain, pRasterStatus);        
212 }
213
214 HRESULT WINAPI IDirect3DDevice9Impl_SetDialogBoxMode(LPDIRECT3DDEVICE9 iface, BOOL bEnableDialogs) {
215     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
216     TRACE("(%p) Relay\n", This);
217     
218     return IWineD3DDevice_SetDialogBoxMode(This->WineD3DDevice, bEnableDialogs);
219 }
220
221 void WINAPI IDirect3DDevice9Impl_SetGammaRamp(LPDIRECT3DDEVICE9 iface, UINT iSwapChain, DWORD Flags, CONST D3DGAMMARAMP* pRamp) {
222     
223     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
224     TRACE("(%p) Relay\n", This);
225     
226     return IWineD3DDevice_SetGammaRamp(This->WineD3DDevice, iSwapChain, Flags, pRamp);
227 }
228
229 void WINAPI IDirect3DDevice9Impl_GetGammaRamp(LPDIRECT3DDEVICE9 iface, UINT iSwapChain, D3DGAMMARAMP* pRamp) {    
230     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
231     TRACE("(%p) Relay\n", This);
232     
233     return IWineD3DDevice_GetGammaRamp(This->WineD3DDevice, iSwapChain, pRamp);
234 }
235
236
237 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 )  {
238     HRESULT hrc;
239     IDirect3DSurface9Impl *object;
240     IDirect3DDevice9Impl  *This = (IDirect3DDevice9Impl *)iface;
241     TRACE("(%p) Relay\n", This);
242     if(MultisampleQuality < 0) { 
243         FIXME("MultisampleQuality out of range %ld, substituting 0 \n", MultisampleQuality);
244     /*FIXME: Find out what windows does with a MultisampleQuality < 0 */
245         MultisampleQuality=0;
246     }
247     
248     if(MultisampleQuality > 0){
249         FIXME("MultisampleQuality set to %ld, bstituting 0  \n" , MultisampleQuality);
250     /*
251     MultisampleQuality
252  [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.
253  */
254  
255         MultisampleQuality=0;
256     }
257     /*FIXME: Check MAX bounds of MultisampleQuality*/
258
259     /* Allocate the storage for the device */
260     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DSurface9Impl));
261     if (NULL == object) {
262         FIXME("Allocation of memory failed\n");
263         *ppSurface = NULL;
264         return D3DERR_OUTOFVIDEOMEMORY;
265     }
266
267     object->lpVtbl = &Direct3DSurface9_Vtbl;
268     object->ref = 1;
269     
270     TRACE("(%p) : w(%d) h(%d) fmt(%d) surf@%p\n", This, Width, Height, Format, *ppSurface);
271            
272     hrc = IWineD3DDevice_CreateSurface(This->WineD3DDevice, Width, Height, Format, Lockable, Discard, Level,  &object->wineD3DSurface, Type, Usage, Pool,MultiSample,MultisampleQuality,pSharedHandle,(IUnknown *)object);
273     
274     if (hrc != D3D_OK || NULL == object->wineD3DSurface) {
275        /* free up object */
276         FIXME("(%p) call to IWineD3DDevice_CreateSurface failed\n", This);
277         HeapFree(GetProcessHeap(), 0, object);
278         *ppSurface = NULL;
279     } else {
280         *ppSurface = (LPDIRECT3DSURFACE9) object;
281     }  
282     return hrc;
283 }
284
285
286
287 HRESULT  WINAPI  IDirect3DDevice9Impl_CreateRenderTarget(LPDIRECT3DDEVICE9 iface, UINT Width, UINT Height, 
288                                                          D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, 
289                                                          DWORD MultisampleQuality, BOOL Lockable, 
290                                                          IDirect3DSurface9 **ppSurface, HANDLE* pSharedHandle) {
291    TRACE("Relay\n");
292    /* Is this correct? */
293    return IDirect3DDevice9Impl_CreateSurface(iface,Width,Height,Format,Lockable,FALSE/*Discard*/, 0/*Level*/, ppSurface,D3DRTYPE_SURFACE,D3DUSAGE_RENDERTARGET,D3DPOOL_DEFAULT,MultiSample,MultisampleQuality,pSharedHandle);
294      
295
296 }
297
298 HRESULT  WINAPI  IDirect3DDevice9Impl_CreateDepthStencilSurface(LPDIRECT3DDEVICE9 iface, UINT Width, UINT Height,
299                                                                 D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample,
300                                                                 DWORD MultisampleQuality, BOOL Discard,
301                                                                 IDirect3DSurface9 **ppSurface, HANDLE* pSharedHandle) {
302      TRACE("Relay\n");
303      return IDirect3DDevice9Impl_CreateSurface(iface,Width,Height,Format,TRUE/* Lockable */,Discard, 0/* Level */
304                                                ,ppSurface,D3DRTYPE_SURFACE,D3DUSAGE_DEPTHSTENCIL,
305                                                 D3DPOOL_DEFAULT,MultiSample,MultisampleQuality,pSharedHandle);
306 }
307
308
309 HRESULT  WINAPI  IDirect3DDevice9Impl_UpdateSurface(LPDIRECT3DDEVICE9 iface, IDirect3DSurface9* pSourceSurface, CONST RECT* pSourceRect, IDirect3DSurface9* pDestinationSurface, CONST POINT* pDestPoint) {
310     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;     
311     TRACE("(%p) Relay\n" , This);
312     return IWineD3DDevice_UpdateSurface(This->WineD3DDevice, ((IDirect3DSurface9Impl *)pSourceSurface)->wineD3DSurface, pSourceRect, ((IDirect3DSurface9Impl *)pDestinationSurface)->wineD3DSurface, pDestPoint);
313 }
314
315 HRESULT  WINAPI  IDirect3DDevice9Impl_UpdateTexture(LPDIRECT3DDEVICE9 iface, IDirect3DBaseTexture9* pSourceTexture, IDirect3DBaseTexture9* pDestinationTexture) {
316     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
317     TRACE("(%p) Relay\n" , This);
318     return IWineD3DDevice_UpdateTexture(This->WineD3DDevice,  ((IDirect3DBaseTexture9Impl *)pSourceTexture)->wineD3DBaseTexture, ((IDirect3DBaseTexture9Impl *)pDestinationTexture)->wineD3DBaseTexture);
319 }
320
321 /* This isn't in MSDN!
322 HRESULT  WINAPI  IDirect3DDevice9Impl_GetFrontBuffer(LPDIRECT3DDEVICE9 iface, IDirect3DSurface9* pDestSurface) {
323     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
324     FIXME("(%p) : stub\n", This);
325     return D3D_OK;
326 }
327 */
328
329 HRESULT  WINAPI  IDirect3DDevice9Impl_GetRenderTargetData(LPDIRECT3DDEVICE9 iface, IDirect3DSurface9* pRenderTarget, IDirect3DSurface9* pDestSurface) {
330     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
331     IDirect3DSurface9Impl *renderTarget = (IDirect3DSurface9Impl *)pRenderTarget;
332     IDirect3DSurface9Impl *destSurface = (IDirect3DSurface9Impl *)pDestSurface;
333     TRACE("(%p) Relay\n" , This);
334     return IWineD3DDevice_GetRenderTargetData(This->WineD3DDevice, renderTarget->wineD3DSurface, destSurface->wineD3DSurface);
335 }
336
337 HRESULT  WINAPI  IDirect3DDevice9Impl_GetFrontBufferData(LPDIRECT3DDEVICE9 iface, UINT iSwapChain, IDirect3DSurface9* pDestSurface) {
338     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
339     IDirect3DSurface9Impl *destSurface = (IDirect3DSurface9Impl *)pDestSurface;
340     TRACE("(%p) Relay\n" , This);
341     return IWineD3DDevice_GetFrontBufferData(This->WineD3DDevice, iSwapChain, destSurface->wineD3DSurface);    
342 }
343
344 HRESULT  WINAPI  IDirect3DDevice9Impl_StretchRect(LPDIRECT3DDEVICE9 iface, IDirect3DSurface9* pSourceSurface, CONST RECT* pSourceRect, IDirect3DSurface9* pDestSurface, CONST RECT* pDestRect, D3DTEXTUREFILTERTYPE Filter) {
345     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;    
346     TRACE("(%p) Relay\n" , This);
347     return IWineD3DDevice_StretchRect(This->WineD3DDevice, ((IDirect3DSurface9Impl *)pSourceSurface)->wineD3DSurface, pSourceRect, ((IDirect3DSurface9Impl *)pDestSurface)->wineD3DSurface, pDestRect, Filter);            
348 }
349
350 HRESULT  WINAPI  IDirect3DDevice9Impl_ColorFill(LPDIRECT3DDEVICE9 iface, IDirect3DSurface9* pSurface, CONST RECT* pRect, D3DCOLOR color) {
351     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
352     IDirect3DSurface9Impl *surface = (IDirect3DSurface9Impl *)pSurface;
353     TRACE("(%p) Relay\n" , This);
354     return IWineD3DDevice_ColorFill(This->WineD3DDevice, surface->wineD3DSurface, (CONST D3DRECT*)pRect, color);    
355 }
356
357 HRESULT  WINAPI  IDirect3DDevice9Impl_CreateOffscreenPlainSurface(LPDIRECT3DDEVICE9 iface, UINT Width, UINT Height, D3DFORMAT Format, D3DPOOL Pool, IDirect3DSurface9 **ppSurface, HANDLE* pSharedHandle) {
358     TRACE("Relay\n");
359     if(Pool == D3DPOOL_MANAGED ){
360         FIXME("Attempting to create a managed offscreen plain surface\n");
361         return D3DERR_INVALIDCALL;
362     }    
363         /*MSDN: D3DPOOL_SCRATCH will return a surface that has identical characteristics to a surface created by the Microsoft DirectX 8.x method CreateImageSurface.
364         
365         'Off-screen plain surfaces are always lockable, regardless of their pool types.'
366         but then...
367         D3DPOOL_DEFAULT is the appropriate pool for use with the IDirect3DDevice9::StretchRect and IDirect3DDevice9::ColorFill.
368         Why, their always lockable?
369         should I change the usage to dynamic?        
370         */
371     return IDirect3DDevice9Impl_CreateSurface(iface,Width,Height,Format,TRUE/*Loackable*/,FALSE/*Discard*/,0/*Level*/ , ppSurface,D3DRTYPE_SURFACE, 0/*Usage (undefined/none)*/,Pool,D3DMULTISAMPLE_NONE,0/*MultisampleQuality*/,pSharedHandle);
372 }
373
374 /* TODO: move to wineD3D */
375 HRESULT  WINAPI  IDirect3DDevice9Impl_SetRenderTarget(LPDIRECT3DDEVICE9 iface, DWORD RenderTargetIndex, IDirect3DSurface9* pRenderTarget) {
376     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
377     IDirect3DSurface9Impl *pSurface = (IDirect3DSurface9Impl*)pRenderTarget;
378     TRACE("(%p) Relay\n" , This);
379     return IWineD3DDevice_SetRenderTarget(This->WineD3DDevice,RenderTargetIndex,(IWineD3DSurface*)pSurface->wineD3DSurface);
380 }
381
382 HRESULT  WINAPI  IDirect3DDevice9Impl_GetRenderTarget(LPDIRECT3DDEVICE9 iface, DWORD RenderTargetIndex, IDirect3DSurface9 **ppRenderTarget) {
383     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
384     HRESULT hr = D3D_OK;
385     IWineD3DSurface *pRenderTarget;
386
387     TRACE("(%p) Relay\n" , This);
388
389     if (ppRenderTarget == NULL) {
390         return D3DERR_INVALIDCALL;
391     }
392     hr=IWineD3DDevice_GetRenderTarget(This->WineD3DDevice,RenderTargetIndex,&pRenderTarget);
393
394     if (hr == D3D_OK && pRenderTarget != NULL) {
395         IWineD3DResource_GetParent((IWineD3DResource *)pRenderTarget,(IUnknown**)ppRenderTarget);
396         IWineD3DResource_Release((IWineD3DResource *)pRenderTarget);
397     } else {
398         FIXME("Call to IWineD3DDevice_GetRenderTarget failed\n");
399         *ppRenderTarget = NULL;
400     }
401     return hr;
402 }
403
404 HRESULT  WINAPI  IDirect3DDevice9Impl_SetDepthStencilSurface(LPDIRECT3DDEVICE9 iface, IDirect3DSurface9* pZStencilSurface) {
405     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
406     IDirect3DSurface9Impl *pSurface;
407
408     TRACE("(%p) Relay\n" , This);
409
410     pSurface = (IDirect3DSurface9Impl*)pZStencilSurface;
411     return IWineD3DDevice_SetDepthStencilSurface(This->WineD3DDevice,NULL==pSurface?NULL:(IWineD3DSurface*)pSurface->wineD3DSurface);
412 }
413
414 HRESULT  WINAPI  IDirect3DDevice9Impl_GetDepthStencilSurface(LPDIRECT3DDEVICE9 iface, IDirect3DSurface9 **ppZStencilSurface) {
415     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
416     HRESULT hr = D3D_OK;
417     IWineD3DSurface *pZStencilSurface;
418
419     TRACE("(%p) Relay\n" , This);
420     if(ppZStencilSurface == NULL){
421         return D3DERR_INVALIDCALL;
422     }
423
424     hr=IWineD3DDevice_GetDepthStencilSurface(This->WineD3DDevice,&pZStencilSurface);
425     if(hr == D3D_OK && pZStencilSurface != NULL){
426         IWineD3DResource_GetParent((IWineD3DResource *)pZStencilSurface,(IUnknown**)ppZStencilSurface);
427         IWineD3DResource_Release((IWineD3DResource *)pZStencilSurface);
428     }else{
429         FIXME("Call to IWineD3DDevice_GetRenderTarget failed\n");
430         *ppZStencilSurface = NULL;
431     }
432     return D3D_OK;
433 }
434
435 HRESULT  WINAPI  IDirect3DDevice9Impl_BeginScene(LPDIRECT3DDEVICE9 iface) {
436     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
437     TRACE("(%p) Relay\n" , This);
438     return IWineD3DDevice_BeginScene(This->WineD3DDevice);
439 }
440
441 HRESULT  WINAPI  IDirect3DDevice9Impl_EndScene(LPDIRECT3DDEVICE9 iface) {
442     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
443     TRACE("(%p) Relay\n" , This);
444     return IWineD3DDevice_EndScene(This->WineD3DDevice);
445     
446 }
447
448 HRESULT  WINAPI  IDirect3DDevice9Impl_Clear(LPDIRECT3DDEVICE9 iface, DWORD Count, CONST D3DRECT* pRects, DWORD Flags, D3DCOLOR Color, float Z, DWORD Stencil) {
449     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
450     TRACE("(%p) Relay\n" , This);
451     return IWineD3DDevice_Clear(This->WineD3DDevice, Count, pRects, Flags, Color, Z, Stencil);
452 }
453
454 HRESULT  WINAPI  IDirect3DDevice9Impl_SetTransform(LPDIRECT3DDEVICE9 iface, D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX* lpMatrix) {
455     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
456     TRACE("(%p) Relay\n" , This);
457     return IWineD3DDevice_SetTransform(This->WineD3DDevice, State, lpMatrix);
458 }
459
460 HRESULT  WINAPI  IDirect3DDevice9Impl_GetTransform(LPDIRECT3DDEVICE9 iface, D3DTRANSFORMSTATETYPE State, D3DMATRIX* pMatrix) {
461     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
462     TRACE("(%p) Relay\n" , This);
463     return IWineD3DDevice_GetTransform(This->WineD3DDevice, State, pMatrix);
464 }
465
466 HRESULT  WINAPI  IDirect3DDevice9Impl_MultiplyTransform(LPDIRECT3DDEVICE9 iface, D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX* pMatrix) {
467     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
468     TRACE("(%p) Relay\n" , This);
469     return IWineD3DDevice_MultiplyTransform(This->WineD3DDevice, State, pMatrix);
470 }
471
472 HRESULT  WINAPI  IDirect3DDevice9Impl_SetViewport(LPDIRECT3DDEVICE9 iface, CONST D3DVIEWPORT9* pViewport) {
473     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
474     TRACE("(%p) Relay\n" , This);
475     return IWineD3DDevice_SetViewport(This->WineD3DDevice, (const WINED3DVIEWPORT *)pViewport);
476 }
477
478 HRESULT  WINAPI  IDirect3DDevice9Impl_GetViewport(LPDIRECT3DDEVICE9 iface, D3DVIEWPORT9* pViewport) {
479     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
480     TRACE("(%p) Relay\n" , This);
481     return IWineD3DDevice_GetViewport(This->WineD3DDevice, (WINED3DVIEWPORT *)pViewport);
482 }
483
484 HRESULT  WINAPI  IDirect3DDevice9Impl_SetMaterial(LPDIRECT3DDEVICE9 iface, CONST D3DMATERIAL9* pMaterial) {
485     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
486     TRACE("(%p) Relay\n" , This);
487     return IWineD3DDevice_SetMaterial(This->WineD3DDevice, (const WINED3DMATERIAL *)pMaterial);
488 }
489
490 HRESULT  WINAPI  IDirect3DDevice9Impl_GetMaterial(LPDIRECT3DDEVICE9 iface, D3DMATERIAL9* pMaterial) {
491     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
492     TRACE("(%p) Relay\n" , This);
493     return IWineD3DDevice_GetMaterial(This->WineD3DDevice, (WINED3DMATERIAL *)pMaterial);
494 }
495
496 HRESULT  WINAPI  IDirect3DDevice9Impl_SetLight(LPDIRECT3DDEVICE9 iface, DWORD Index, CONST D3DLIGHT9* pLight) {
497     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
498     TRACE("(%p) Relay\n" , This);
499     return IWineD3DDevice_SetLight(This->WineD3DDevice, Index, (const WINED3DLIGHT *)pLight);
500 }
501
502 HRESULT  WINAPI  IDirect3DDevice9Impl_GetLight(LPDIRECT3DDEVICE9 iface, DWORD Index, D3DLIGHT9* pLight) {
503     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
504     TRACE("(%p) Relay\n" , This);
505     return IWineD3DDevice_GetLight(This->WineD3DDevice, Index, (WINED3DLIGHT *)pLight);
506 }
507
508 HRESULT  WINAPI  IDirect3DDevice9Impl_LightEnable(LPDIRECT3DDEVICE9 iface, DWORD Index, BOOL Enable) {
509     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
510     TRACE("(%p) Relay\n" , This);
511     return IWineD3DDevice_SetLightEnable(This->WineD3DDevice, Index, Enable);
512 }
513
514 HRESULT  WINAPI  IDirect3DDevice9Impl_GetLightEnable(LPDIRECT3DDEVICE9 iface, DWORD Index, BOOL* pEnable) {
515     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
516     TRACE("(%p) Relay\n" , This);
517     return IWineD3DDevice_GetLightEnable(This->WineD3DDevice, Index, pEnable);
518 }
519
520 HRESULT  WINAPI  IDirect3DDevice9Impl_SetClipPlane(LPDIRECT3DDEVICE9 iface, DWORD Index, CONST float* pPlane) {
521     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
522     TRACE("(%p) Relay\n" , This);
523     return IWineD3DDevice_SetClipPlane(This->WineD3DDevice, Index, pPlane);
524 }
525
526 HRESULT  WINAPI  IDirect3DDevice9Impl_GetClipPlane(LPDIRECT3DDEVICE9 iface, DWORD Index, float* pPlane) {
527     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
528     TRACE("(%p) Relay\n" , This);
529     return IWineD3DDevice_GetClipPlane(This->WineD3DDevice, Index, pPlane);
530 }
531
532 HRESULT  WINAPI  IDirect3DDevice9Impl_SetRenderState(LPDIRECT3DDEVICE9 iface, D3DRENDERSTATETYPE State, DWORD Value) {
533     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
534     TRACE("(%p) Relay\n" , This);
535     return IWineD3DDevice_SetRenderState(This->WineD3DDevice, State, Value);
536 }
537
538 HRESULT  WINAPI  IDirect3DDevice9Impl_GetRenderState(LPDIRECT3DDEVICE9 iface, D3DRENDERSTATETYPE State, DWORD* pValue) {
539     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
540     TRACE("(%p) Relay\n" , This);
541     return IWineD3DDevice_GetRenderState(This->WineD3DDevice, State, pValue);
542 }
543
544 HRESULT  WINAPI  IDirect3DDevice9Impl_SetClipStatus(LPDIRECT3DDEVICE9 iface, CONST D3DCLIPSTATUS9* pClipStatus) {
545     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
546     TRACE("(%p) Relay\n" , This);
547     return IWineD3DDevice_SetClipStatus(This->WineD3DDevice, (const WINED3DCLIPSTATUS *)pClipStatus);
548 }
549
550 HRESULT  WINAPI  IDirect3DDevice9Impl_GetClipStatus(LPDIRECT3DDEVICE9 iface, D3DCLIPSTATUS9* pClipStatus) {
551     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
552     TRACE("(%p) Relay\n" , This);
553     return IWineD3DDevice_GetClipStatus(This->WineD3DDevice, (WINED3DCLIPSTATUS *)pClipStatus);
554 }
555
556 HRESULT  WINAPI  IDirect3DDevice9Impl_GetTexture(LPDIRECT3DDEVICE9 iface, DWORD Stage, IDirect3DBaseTexture9 **ppTexture) {
557     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
558     IWineD3DBaseTexture *retTexture = NULL;
559     HRESULT rc = D3D_OK;
560
561     TRACE("(%p) Relay\n" , This);
562
563     if(ppTexture == NULL){
564         return D3DERR_INVALIDCALL;
565     }
566
567     rc = IWineD3DDevice_GetTexture(This->WineD3DDevice, Stage, (IWineD3DBaseTexture **)&retTexture);
568     if (rc == D3D_OK && NULL != retTexture) {
569         IWineD3DBaseTexture_GetParent(retTexture, (IUnknown **)ppTexture);
570         IWineD3DBaseTexture_Release(retTexture);
571     }else{
572         FIXME("Call to get texture  (%ld) failed (%p) \n", Stage, retTexture);
573         *ppTexture = NULL;
574     }
575     return rc;
576 }
577
578 HRESULT  WINAPI  IDirect3DDevice9Impl_SetTexture(LPDIRECT3DDEVICE9 iface, DWORD Stage, IDirect3DBaseTexture9* pTexture) {
579     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
580     TRACE("(%p) Relay %ld %p\n" , This, Stage, pTexture);
581     return IWineD3DDevice_SetTexture(This->WineD3DDevice, Stage,
582                                      pTexture==NULL ? NULL:((IDirect3DBaseTexture9Impl *)pTexture)->wineD3DBaseTexture); 
583 }
584
585 HRESULT  WINAPI  IDirect3DDevice9Impl_GetTextureStageState(LPDIRECT3DDEVICE9 iface, DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD* pValue) {
586     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
587     TRACE("(%p) Relay\n" , This);
588     return IWineD3DDevice_GetTextureStageState(This->WineD3DDevice, Stage, Type, pValue);
589 }
590
591 HRESULT  WINAPI  IDirect3DDevice9Impl_SetTextureStageState(LPDIRECT3DDEVICE9 iface, DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD Value) {
592     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
593     TRACE("(%p) Relay\n" , This);
594     return IWineD3DDevice_SetTextureStageState(This->WineD3DDevice, Stage, Type, Value);
595 }
596
597 HRESULT  WINAPI  IDirect3DDevice9Impl_GetSamplerState(LPDIRECT3DDEVICE9 iface, DWORD Sampler, D3DSAMPLERSTATETYPE Type, DWORD* pValue) {
598     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;    
599     TRACE("(%p) Relay\n" , This);
600     return IWineD3DDevice_GetSamplerState(This->WineD3DDevice, Sampler, Type, pValue);
601 }
602
603 HRESULT  WINAPI  IDirect3DDevice9Impl_SetSamplerState(LPDIRECT3DDEVICE9 iface, DWORD Sampler, D3DSAMPLERSTATETYPE Type, DWORD Value) {
604     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
605     TRACE("(%p) Relay\n" , This);
606     return IWineD3DDevice_SetSamplerState(This->WineD3DDevice, Sampler, Type, Value);    
607 }
608
609 HRESULT  WINAPI  IDirect3DDevice9Impl_ValidateDevice(LPDIRECT3DDEVICE9 iface, DWORD* pNumPasses) {
610     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
611     TRACE("(%p) Relay\n" , This);
612     return IWineD3DDevice_ValidateDevice(This->WineD3DDevice, pNumPasses);
613 }
614
615 HRESULT  WINAPI  IDirect3DDevice9Impl_SetPaletteEntries(LPDIRECT3DDEVICE9 iface, UINT PaletteNumber, CONST PALETTEENTRY* pEntries) {
616     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;    
617     TRACE("(%p) Relay\n" , This);
618     return IWineD3DDevice_SetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
619 }
620
621 HRESULT  WINAPI  IDirect3DDevice9Impl_GetPaletteEntries(LPDIRECT3DDEVICE9 iface, UINT PaletteNumber, PALETTEENTRY* pEntries) {
622     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
623     TRACE("(%p) Relay\n" , This);
624     return IWineD3DDevice_GetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
625 }
626
627 HRESULT  WINAPI  IDirect3DDevice9Impl_SetCurrentTexturePalette(LPDIRECT3DDEVICE9 iface, UINT PaletteNumber) {
628     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
629     TRACE("(%p) Relay\n" , This);
630     return IWineD3DDevice_SetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
631 }
632
633 HRESULT  WINAPI  IDirect3DDevice9Impl_GetCurrentTexturePalette(LPDIRECT3DDEVICE9 iface, UINT* PaletteNumber) {
634     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
635     TRACE("(%p) Relay\n" , This);
636     return IWineD3DDevice_GetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
637 }
638
639 HRESULT  WINAPI  IDirect3DDevice9Impl_SetScissorRect(LPDIRECT3DDEVICE9 iface, CONST RECT* pRect) {
640     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
641     TRACE("(%p) Relay\n" , This);
642     return IWineD3DDevice_SetScissorRect(This->WineD3DDevice, pRect);    
643 }
644
645 HRESULT  WINAPI  IDirect3DDevice9Impl_GetScissorRect(LPDIRECT3DDEVICE9 iface, RECT* pRect) {
646     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
647     TRACE("(%p) Relay\n" , This);
648     return IWineD3DDevice_GetScissorRect(This->WineD3DDevice, pRect);   
649 }
650
651 HRESULT  WINAPI  IDirect3DDevice9Impl_SetSoftwareVertexProcessing(LPDIRECT3DDEVICE9 iface, BOOL bSoftware) {
652     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
653     TRACE("(%p) Relay\n" , This);
654     return IWineD3DDevice_SetSoftwareVertexProcessing(This->WineD3DDevice, bSoftware);
655 }
656
657 BOOL     WINAPI  IDirect3DDevice9Impl_GetSoftwareVertexProcessing(LPDIRECT3DDEVICE9 iface) {
658     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
659     TRACE("(%p) Relay\n" , This);
660     return IWineD3DDevice_GetSoftwareVertexProcessing(This->WineD3DDevice);
661 }
662
663 HRESULT  WINAPI  IDirect3DDevice9Impl_SetNPatchMode(LPDIRECT3DDEVICE9 iface, float nSegments) {
664     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
665     TRACE("(%p) Relay\n" , This);
666     return IWineD3DDevice_SetNPatchMode(This->WineD3DDevice, nSegments);
667 }
668
669 float    WINAPI  IDirect3DDevice9Impl_GetNPatchMode(LPDIRECT3DDEVICE9 iface) {
670     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
671     TRACE("(%p) Relay\n" , This);
672     return IWineD3DDevice_GetNPatchMode(This->WineD3DDevice);
673 }
674
675 HRESULT WINAPI IDirect3DDevice9Impl_DrawPrimitive(LPDIRECT3DDEVICE9 iface, D3DPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT PrimitiveCount) {
676     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;    
677     TRACE("(%p) Relay\n" , This);
678     return IWineD3DDevice_DrawPrimitive(This->WineD3DDevice, PrimitiveType, StartVertex, PrimitiveCount);
679 }
680
681 HRESULT  WINAPI  IDirect3DDevice9Impl_DrawIndexedPrimitive(LPDIRECT3DDEVICE9 iface, D3DPRIMITIVETYPE PrimitiveType,
682                                                            INT BaseVertexIndex, UINT MinVertexIndex, UINT NumVertices, UINT startIndex, UINT primCount) {
683     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface; 
684     TRACE("(%p) Relay\n" , This);
685     return IWineD3DDevice_DrawIndexedPrimitive(This->WineD3DDevice, PrimitiveType, BaseVertexIndex, MinVertexIndex, NumVertices, startIndex, primCount);
686 }
687
688 HRESULT  WINAPI  IDirect3DDevice9Impl_DrawPrimitiveUP(LPDIRECT3DDEVICE9 iface, D3DPRIMITIVETYPE PrimitiveType, UINT PrimitiveCount, CONST void* pVertexStreamZeroData, UINT VertexStreamZeroStride) {
689     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;    
690     TRACE("(%p) Relay\n" , This);
691     return IWineD3DDevice_DrawPrimitiveUP(This->WineD3DDevice, PrimitiveType, PrimitiveCount, pVertexStreamZeroData, VertexStreamZeroStride);
692 }
693
694 HRESULT  WINAPI  IDirect3DDevice9Impl_DrawIndexedPrimitiveUP(LPDIRECT3DDEVICE9 iface, D3DPRIMITIVETYPE PrimitiveType, UINT MinVertexIndex,
695                                                              UINT NumVertexIndices, UINT PrimitiveCount, CONST void* pIndexData,
696                                                              D3DFORMAT IndexDataFormat, CONST void* pVertexStreamZeroData, UINT VertexStreamZeroStride) {
697     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
698     TRACE("(%p) Relay\n" , This);
699     return IWineD3DDevice_DrawIndexedPrimitiveUP(This->WineD3DDevice, PrimitiveType, MinVertexIndex, NumVertexIndices, PrimitiveCount,
700                                                  pIndexData, IndexDataFormat, pVertexStreamZeroData, VertexStreamZeroStride);
701 }
702
703 HRESULT  WINAPI  IDirect3DDevice9Impl_ProcessVertices(LPDIRECT3DDEVICE9 iface, UINT SrcStartIndex, UINT DestIndex, UINT VertexCount, IDirect3DVertexBuffer9* pDestBuffer, IDirect3DVertexDeclaration9* pVertexDecl, DWORD Flags) {
704     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
705     TRACE("(%p) Relay\n" , This);
706     return IWineD3DDevice_ProcessVertices(This->WineD3DDevice,SrcStartIndex, DestIndex, VertexCount, ((IDirect3DVertexBuffer9Impl *)pDestBuffer)->wineD3DVertexBuffer, ((IDirect3DVertexBuffer9Impl *)pVertexDecl)->wineD3DVertexBuffer, Flags);       
707 }
708
709 HRESULT  WINAPI  IDirect3DDevice9Impl_SetFVF(LPDIRECT3DDEVICE9 iface, DWORD FVF) {
710     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
711     TRACE("(%p) Relay\n" , This);
712     return IWineD3DDevice_SetFVF(This->WineD3DDevice, FVF);
713 }
714
715 HRESULT  WINAPI  IDirect3DDevice9Impl_GetFVF(LPDIRECT3DDEVICE9 iface, DWORD* pFVF) {
716     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
717     TRACE("(%p) Relay\n" , This);
718     return IWineD3DDevice_GetFVF(This->WineD3DDevice, pFVF);
719 }
720
721 HRESULT  WINAPI  IDirect3DDevice9Impl_SetStreamSource(LPDIRECT3DDEVICE9 iface, UINT StreamNumber, IDirect3DVertexBuffer9* pStreamData, UINT OffsetInBytes, UINT Stride) {
722     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
723     TRACE("(%p) Relay\n" , This);
724     return IWineD3DDevice_SetStreamSource(This->WineD3DDevice, StreamNumber, 
725                                           pStreamData==NULL ? NULL:((IDirect3DVertexBuffer9Impl *)pStreamData)->wineD3DVertexBuffer, 
726                                           OffsetInBytes, Stride);
727 }
728
729 HRESULT  WINAPI  IDirect3DDevice9Impl_GetStreamSource(LPDIRECT3DDEVICE9 iface, UINT StreamNumber, IDirect3DVertexBuffer9 **pStream, UINT* OffsetInBytes, UINT* pStride) {
730     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
731     IWineD3DVertexBuffer *retStream = NULL;
732     HRESULT rc = D3D_OK;
733
734     TRACE("(%p) Relay\n" , This);
735
736     if(pStream == NULL){
737         return D3DERR_INVALIDCALL;
738     }
739
740     rc = IWineD3DDevice_GetStreamSource(This->WineD3DDevice, StreamNumber, (IWineD3DVertexBuffer **)&retStream, OffsetInBytes, pStride);
741     if (rc == D3D_OK  && NULL != retStream) {
742         IWineD3DVertexBuffer_GetParent(retStream, (IUnknown **)pStream);
743         IWineD3DVertexBuffer_Release(retStream);
744     }else{
745         FIXME("Call to GetStreamSource failed %p %p\n", OffsetInBytes, pStride);
746         *pStream = NULL;
747     }
748     return rc;
749 }
750
751 HRESULT  WINAPI  IDirect3DDevice9Impl_SetStreamSourceFreq(LPDIRECT3DDEVICE9 iface, UINT StreamNumber, UINT Divider) {
752     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;    
753     TRACE("(%p) Relay\n" , This);
754     IWineD3DDevice_SetStreamSourceFreq(This->WineD3DDevice, StreamNumber, Divider);
755     return D3D_OK;
756 }
757
758 HRESULT  WINAPI  IDirect3DDevice9Impl_GetStreamSourceFreq(LPDIRECT3DDEVICE9 iface, UINT StreamNumber, UINT* Divider) {
759     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
760     TRACE("(%p) Relay\n" , This);
761     return IWineD3DDevice_GetStreamSourceFreq(This->WineD3DDevice, StreamNumber, Divider);
762     return D3D_OK;
763 }
764
765 HRESULT  WINAPI  IDirect3DDevice9Impl_SetIndices(LPDIRECT3DDEVICE9 iface, IDirect3DIndexBuffer9* pIndexData) {
766     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
767     TRACE("(%p) Relay\n", This);
768     return IWineD3DDevice_SetIndices(This->WineD3DDevice, 
769                                      pIndexData==NULL ? NULL:((IDirect3DIndexBuffer9Impl *)pIndexData)->wineD3DIndexBuffer, 
770                                      0);
771 }
772
773 HRESULT  WINAPI  IDirect3DDevice9Impl_GetIndices(LPDIRECT3DDEVICE9 iface, IDirect3DIndexBuffer9 **ppIndexData) {
774     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
775     IWineD3DIndexBuffer *retIndexData = NULL;
776     HRESULT rc = D3D_OK;
777     UINT tmp;
778
779     TRACE("(%p) Relay\n", This);
780
781     if(ppIndexData == NULL){
782         return D3DERR_INVALIDCALL;
783     }
784
785     rc = IWineD3DDevice_GetIndices(This->WineD3DDevice, &retIndexData, &tmp);
786     if (rc == D3D_OK && NULL != retIndexData) {
787         IWineD3DVertexBuffer_GetParent(retIndexData, (IUnknown **)ppIndexData);
788         IWineD3DVertexBuffer_Release(retIndexData);
789     }else{
790         if(rc != D3D_OK)  FIXME("Call to GetIndices failed\n");
791         *ppIndexData = NULL;
792     }
793     return rc;
794 }
795
796 HRESULT  WINAPI  IDirect3DDevice9Impl_DrawRectPatch(LPDIRECT3DDEVICE9 iface, UINT Handle, CONST float* pNumSegs, CONST D3DRECTPATCH_INFO* pRectPatchInfo) {
797     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
798     TRACE("(%p) Relay\n", This);
799     return IWineD3DDevice_DrawRectPatch(This->WineD3DDevice, Handle, pNumSegs, pRectPatchInfo);
800 }
801 /*http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directx/graphics/reference/d3d/interfaces/idirect3ddevice9/DrawTriPatch.asp*/
802 HRESULT  WINAPI  IDirect3DDevice9Impl_DrawTriPatch(LPDIRECT3DDEVICE9 iface, UINT Handle, CONST float* pNumSegs, CONST D3DTRIPATCH_INFO* pTriPatchInfo) {
803     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
804     TRACE("(%p) Relay\n", This);
805     return IWineD3DDevice_DrawTriPatch(This->WineD3DDevice, Handle, pNumSegs, pTriPatchInfo);
806 }
807
808 HRESULT  WINAPI  IDirect3DDevice9Impl_DeletePatch(LPDIRECT3DDEVICE9 iface, UINT Handle) {
809     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
810     TRACE("(%p) Relay\n", This);
811     return IWineD3DDevice_DeletePatch(This->WineD3DDevice, Handle);
812 }
813
814 const IDirect3DDevice9Vtbl Direct3DDevice9_Vtbl =
815 {
816     /* IUnknown */
817     IDirect3DDevice9Impl_QueryInterface,
818     IDirect3DDevice9Impl_AddRef,
819     IDirect3DDevice9Impl_Release,
820     /* IDirect3DDevice9 */
821     IDirect3DDevice9Impl_TestCooperativeLevel,
822     IDirect3DDevice9Impl_GetAvailableTextureMem,
823     IDirect3DDevice9Impl_EvictManagedResources,
824     IDirect3DDevice9Impl_GetDirect3D,
825     IDirect3DDevice9Impl_GetDeviceCaps,
826     IDirect3DDevice9Impl_GetDisplayMode,
827     IDirect3DDevice9Impl_GetCreationParameters,
828     IDirect3DDevice9Impl_SetCursorProperties,
829     IDirect3DDevice9Impl_SetCursorPosition,
830     IDirect3DDevice9Impl_ShowCursor,
831     IDirect3DDevice9Impl_CreateAdditionalSwapChain,
832     IDirect3DDevice9Impl_GetSwapChain,
833     IDirect3DDevice9Impl_GetNumberOfSwapChains,
834     IDirect3DDevice9Impl_Reset,
835     IDirect3DDevice9Impl_Present,
836     IDirect3DDevice9Impl_GetBackBuffer,
837     IDirect3DDevice9Impl_GetRasterStatus,
838     IDirect3DDevice9Impl_SetDialogBoxMode,
839     IDirect3DDevice9Impl_SetGammaRamp,
840     IDirect3DDevice9Impl_GetGammaRamp,
841     IDirect3DDevice9Impl_CreateTexture,
842     IDirect3DDevice9Impl_CreateVolumeTexture,
843     IDirect3DDevice9Impl_CreateCubeTexture,
844     IDirect3DDevice9Impl_CreateVertexBuffer,
845     IDirect3DDevice9Impl_CreateIndexBuffer,
846     IDirect3DDevice9Impl_CreateRenderTarget,
847     IDirect3DDevice9Impl_CreateDepthStencilSurface,
848     IDirect3DDevice9Impl_UpdateSurface,
849     IDirect3DDevice9Impl_UpdateTexture,
850     IDirect3DDevice9Impl_GetRenderTargetData,
851     IDirect3DDevice9Impl_GetFrontBufferData,
852     IDirect3DDevice9Impl_StretchRect,
853     IDirect3DDevice9Impl_ColorFill,
854     IDirect3DDevice9Impl_CreateOffscreenPlainSurface,
855     IDirect3DDevice9Impl_SetRenderTarget,
856     IDirect3DDevice9Impl_GetRenderTarget,
857     IDirect3DDevice9Impl_SetDepthStencilSurface,
858     IDirect3DDevice9Impl_GetDepthStencilSurface,
859     IDirect3DDevice9Impl_BeginScene,
860     IDirect3DDevice9Impl_EndScene,
861     IDirect3DDevice9Impl_Clear,
862     IDirect3DDevice9Impl_SetTransform,
863     IDirect3DDevice9Impl_GetTransform,
864     IDirect3DDevice9Impl_MultiplyTransform,
865     IDirect3DDevice9Impl_SetViewport,
866     IDirect3DDevice9Impl_GetViewport,
867     IDirect3DDevice9Impl_SetMaterial,
868     IDirect3DDevice9Impl_GetMaterial,
869     IDirect3DDevice9Impl_SetLight,
870     IDirect3DDevice9Impl_GetLight,
871     IDirect3DDevice9Impl_LightEnable,
872     IDirect3DDevice9Impl_GetLightEnable,
873     IDirect3DDevice9Impl_SetClipPlane,
874     IDirect3DDevice9Impl_GetClipPlane,
875     IDirect3DDevice9Impl_SetRenderState,
876     IDirect3DDevice9Impl_GetRenderState,
877     IDirect3DDevice9Impl_CreateStateBlock,
878     IDirect3DDevice9Impl_BeginStateBlock,
879     IDirect3DDevice9Impl_EndStateBlock,
880     IDirect3DDevice9Impl_SetClipStatus,
881     IDirect3DDevice9Impl_GetClipStatus,
882     IDirect3DDevice9Impl_GetTexture,
883     IDirect3DDevice9Impl_SetTexture,
884     IDirect3DDevice9Impl_GetTextureStageState,
885     IDirect3DDevice9Impl_SetTextureStageState,
886     IDirect3DDevice9Impl_GetSamplerState,
887     IDirect3DDevice9Impl_SetSamplerState,
888     IDirect3DDevice9Impl_ValidateDevice,
889     IDirect3DDevice9Impl_SetPaletteEntries,
890     IDirect3DDevice9Impl_GetPaletteEntries,
891     IDirect3DDevice9Impl_SetCurrentTexturePalette,
892     IDirect3DDevice9Impl_GetCurrentTexturePalette,
893     IDirect3DDevice9Impl_SetScissorRect,
894     IDirect3DDevice9Impl_GetScissorRect,
895     IDirect3DDevice9Impl_SetSoftwareVertexProcessing,
896     IDirect3DDevice9Impl_GetSoftwareVertexProcessing,
897     IDirect3DDevice9Impl_SetNPatchMode,
898     IDirect3DDevice9Impl_GetNPatchMode,
899     IDirect3DDevice9Impl_DrawPrimitive,
900     IDirect3DDevice9Impl_DrawIndexedPrimitive,
901     IDirect3DDevice9Impl_DrawPrimitiveUP,
902     IDirect3DDevice9Impl_DrawIndexedPrimitiveUP,
903     IDirect3DDevice9Impl_ProcessVertices,
904     IDirect3DDevice9Impl_CreateVertexDeclaration,
905     IDirect3DDevice9Impl_SetVertexDeclaration,
906     IDirect3DDevice9Impl_GetVertexDeclaration,
907     IDirect3DDevice9Impl_SetFVF,
908     IDirect3DDevice9Impl_GetFVF,
909     IDirect3DDevice9Impl_CreateVertexShader,
910     IDirect3DDevice9Impl_SetVertexShader,
911     IDirect3DDevice9Impl_GetVertexShader,
912     IDirect3DDevice9Impl_SetVertexShaderConstantF,
913     IDirect3DDevice9Impl_GetVertexShaderConstantF,
914     IDirect3DDevice9Impl_SetVertexShaderConstantI,
915     IDirect3DDevice9Impl_GetVertexShaderConstantI,
916     IDirect3DDevice9Impl_SetVertexShaderConstantB,
917     IDirect3DDevice9Impl_GetVertexShaderConstantB,
918     IDirect3DDevice9Impl_SetStreamSource,
919     IDirect3DDevice9Impl_GetStreamSource,
920     IDirect3DDevice9Impl_SetStreamSourceFreq,
921     IDirect3DDevice9Impl_GetStreamSourceFreq,
922     IDirect3DDevice9Impl_SetIndices,
923     IDirect3DDevice9Impl_GetIndices,
924     IDirect3DDevice9Impl_CreatePixelShader,
925     IDirect3DDevice9Impl_SetPixelShader,
926     IDirect3DDevice9Impl_GetPixelShader,
927     IDirect3DDevice9Impl_SetPixelShaderConstantF,
928     IDirect3DDevice9Impl_GetPixelShaderConstantF,
929     IDirect3DDevice9Impl_SetPixelShaderConstantI,
930     IDirect3DDevice9Impl_GetPixelShaderConstantI,
931     IDirect3DDevice9Impl_SetPixelShaderConstantB,
932     IDirect3DDevice9Impl_GetPixelShaderConstantB,
933     IDirect3DDevice9Impl_DrawRectPatch,
934     IDirect3DDevice9Impl_DrawTriPatch,
935     IDirect3DDevice9Impl_DeletePatch,
936     IDirect3DDevice9Impl_CreateQuery
937 };
938
939
940 /* Internal function called back during the CreateDevice to create a render target  */
941 HRESULT WINAPI D3D9CB_CreateSurface(IUnknown *device, UINT Width, UINT Height, 
942                                          WINED3DFORMAT Format, DWORD Usage, D3DPOOL Pool, UINT Level,
943                                          IWineD3DSurface** ppSurface, HANDLE* pSharedHandle) {
944     
945     HRESULT res = D3D_OK;
946     IDirect3DSurface9Impl *d3dSurface = NULL;
947     BOOL Lockable = TRUE;
948     
949     if((Pool == D3DPOOL_DEFAULT &&  Usage != D3DUSAGE_DYNAMIC)) 
950         Lockable = FALSE;
951         
952     TRACE("relay\n");
953     res = IDirect3DDevice9Impl_CreateSurface((IDirect3DDevice9 *)device, Width, Height, (D3DFORMAT)Format, Lockable, FALSE/*Discard*/, Level,  (IDirect3DSurface9 **)&d3dSurface, D3DRTYPE_SURFACE, Usage, Pool, D3DMULTISAMPLE_NONE, 0 /* MultisampleQuality */, pSharedHandle);  
954
955     if (res == D3D_OK) {
956         *ppSurface = d3dSurface->wineD3DSurface;
957     }else{
958         FIXME("(%p) IDirect3DDevice9_CreateSurface failed\n", device);
959     }
960     return res;
961 }