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