jscript: Added Object function invocation implementation.
[wine] / dlls / d3d8 / device.c
1 /*
2  * IDirect3DDevice8 implementation
3  *
4  * Copyright 2002-2004 Jason Edmeades
5  * Copyright 2004 Christian Costa
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20  */
21
22 #include "config.h"
23
24 #include <math.h>
25 #include <stdarg.h>
26
27 #define NONAMELESSUNION
28 #define NONAMELESSSTRUCT
29 #include "windef.h"
30 #include "winbase.h"
31 #include "winuser.h"
32 #include "wingdi.h"
33 #include "wine/debug.h"
34
35 #include "d3d8_private.h"
36
37 WINE_DEFAULT_DEBUG_CHANNEL(d3d8);
38
39 D3DFORMAT d3dformat_from_wined3dformat(WINED3DFORMAT format)
40 {
41     BYTE *c = (BYTE *)&format;
42
43     /* Don't translate FOURCC formats */
44     if (isprint(c[0]) && isprint(c[1]) && isprint(c[2]) && isprint(c[3])) return format;
45
46     switch(format)
47     {
48         case WINED3DFMT_UNKNOWN: return D3DFMT_UNKNOWN;
49         case WINED3DFMT_R8G8B8: return D3DFMT_R8G8B8;
50         case WINED3DFMT_A8R8G8B8: return D3DFMT_A8R8G8B8;
51         case WINED3DFMT_X8R8G8B8: return D3DFMT_X8R8G8B8;
52         case WINED3DFMT_R5G6B5: return D3DFMT_R5G6B5;
53         case WINED3DFMT_X1R5G5B5: return D3DFMT_X1R5G5B5;
54         case WINED3DFMT_A1R5G5B5: return D3DFMT_A1R5G5B5;
55         case WINED3DFMT_A4R4G4B4: return D3DFMT_A4R4G4B4;
56         case WINED3DFMT_R3G3B2: return D3DFMT_R3G3B2;
57         case WINED3DFMT_A8_UNORM: return D3DFMT_A8;
58         case WINED3DFMT_A8R3G3B2: return D3DFMT_A8R3G3B2;
59         case WINED3DFMT_X4R4G4B4: return D3DFMT_X4R4G4B4;
60         case WINED3DFMT_R10G10B10A2_UNORM: return D3DFMT_A2B10G10R10;
61         case WINED3DFMT_R16G16_UNORM: return D3DFMT_G16R16;
62         case WINED3DFMT_A8P8: return D3DFMT_A8P8;
63         case WINED3DFMT_P8: return D3DFMT_P8;
64         case WINED3DFMT_L8: return D3DFMT_L8;
65         case WINED3DFMT_A8L8: return D3DFMT_A8L8;
66         case WINED3DFMT_A4L4: return D3DFMT_A4L4;
67         case WINED3DFMT_R8G8_SNORM: return D3DFMT_V8U8;
68         case WINED3DFMT_L6V5U5: return D3DFMT_L6V5U5;
69         case WINED3DFMT_X8L8V8U8: return D3DFMT_X8L8V8U8;
70         case WINED3DFMT_R8G8B8A8_SNORM: return D3DFMT_Q8W8V8U8;
71         case WINED3DFMT_R16G16_SNORM: return D3DFMT_V16U16;
72         case WINED3DFMT_W11V11U10: return D3DFMT_W11V11U10;
73         case WINED3DFMT_A2W10V10U10: return D3DFMT_A2W10V10U10;
74         case WINED3DFMT_D16_LOCKABLE: return D3DFMT_D16_LOCKABLE;
75         case WINED3DFMT_D32: return D3DFMT_D32;
76         case WINED3DFMT_D15S1: return D3DFMT_D15S1;
77         case WINED3DFMT_D24S8: return D3DFMT_D24S8;
78         case WINED3DFMT_D24X8: return D3DFMT_D24X8;
79         case WINED3DFMT_D24X4S4: return D3DFMT_D24X4S4;
80         case WINED3DFMT_D16_UNORM: return D3DFMT_D16;
81         case WINED3DFMT_VERTEXDATA: return D3DFMT_VERTEXDATA;
82         case WINED3DFMT_R16_UINT: return D3DFMT_INDEX16;
83         case WINED3DFMT_R32_UINT: return D3DFMT_INDEX32;
84         default:
85             FIXME("Unhandled WINED3DFORMAT %#x\n", format);
86             return D3DFMT_UNKNOWN;
87     }
88 }
89
90 WINED3DFORMAT wined3dformat_from_d3dformat(D3DFORMAT format)
91 {
92     BYTE *c = (BYTE *)&format;
93
94     /* Don't translate FOURCC formats */
95     if (isprint(c[0]) && isprint(c[1]) && isprint(c[2]) && isprint(c[3])) return format;
96
97     switch(format)
98     {
99         case D3DFMT_UNKNOWN: return WINED3DFMT_UNKNOWN;
100         case D3DFMT_R8G8B8: return WINED3DFMT_R8G8B8;
101         case D3DFMT_A8R8G8B8: return WINED3DFMT_A8R8G8B8;
102         case D3DFMT_X8R8G8B8: return WINED3DFMT_X8R8G8B8;
103         case D3DFMT_R5G6B5: return WINED3DFMT_R5G6B5;
104         case D3DFMT_X1R5G5B5: return WINED3DFMT_X1R5G5B5;
105         case D3DFMT_A1R5G5B5: return WINED3DFMT_A1R5G5B5;
106         case D3DFMT_A4R4G4B4: return WINED3DFMT_A4R4G4B4;
107         case D3DFMT_R3G3B2: return WINED3DFMT_R3G3B2;
108         case D3DFMT_A8: return WINED3DFMT_A8_UNORM;
109         case D3DFMT_A8R3G3B2: return WINED3DFMT_A8R3G3B2;
110         case D3DFMT_X4R4G4B4: return WINED3DFMT_X4R4G4B4;
111         case D3DFMT_A2B10G10R10: return WINED3DFMT_R10G10B10A2_UNORM;
112         case D3DFMT_G16R16: return WINED3DFMT_R16G16_UNORM;
113         case D3DFMT_A8P8: return WINED3DFMT_A8P8;
114         case D3DFMT_P8: return WINED3DFMT_P8;
115         case D3DFMT_L8: return WINED3DFMT_L8;
116         case D3DFMT_A8L8: return WINED3DFMT_A8L8;
117         case D3DFMT_A4L4: return WINED3DFMT_A4L4;
118         case D3DFMT_V8U8: return WINED3DFMT_R8G8_SNORM;
119         case D3DFMT_L6V5U5: return WINED3DFMT_L6V5U5;
120         case D3DFMT_X8L8V8U8: return WINED3DFMT_X8L8V8U8;
121         case D3DFMT_Q8W8V8U8: return WINED3DFMT_R8G8B8A8_SNORM;
122         case D3DFMT_V16U16: return WINED3DFMT_R16G16_SNORM;
123         case D3DFMT_W11V11U10: return WINED3DFMT_W11V11U10;
124         case D3DFMT_A2W10V10U10: return WINED3DFMT_A2W10V10U10;
125         case D3DFMT_D16_LOCKABLE: return WINED3DFMT_D16_LOCKABLE;
126         case D3DFMT_D32: return WINED3DFMT_D32;
127         case D3DFMT_D15S1: return WINED3DFMT_D15S1;
128         case D3DFMT_D24S8: return WINED3DFMT_D24S8;
129         case D3DFMT_D24X8: return WINED3DFMT_D24X8;
130         case D3DFMT_D24X4S4: return WINED3DFMT_D24X4S4;
131         case D3DFMT_D16: return WINED3DFMT_D16_UNORM;
132         case D3DFMT_VERTEXDATA: return WINED3DFMT_VERTEXDATA;
133         case D3DFMT_INDEX16: return WINED3DFMT_R16_UINT;
134         case D3DFMT_INDEX32: return WINED3DFMT_R32_UINT;
135         default:
136             FIXME("Unhandled D3DFORMAT %#x\n", format);
137             return WINED3DFMT_UNKNOWN;
138     }
139 }
140
141 static UINT vertex_count_from_primitive_count(D3DPRIMITIVETYPE primitive_type, UINT primitive_count)
142 {
143     switch(primitive_type)
144     {
145         case D3DPT_POINTLIST:
146             return primitive_count;
147
148         case D3DPT_LINELIST:
149             return primitive_count * 2;
150
151         case D3DPT_LINESTRIP:
152             return primitive_count + 1;
153
154         case D3DPT_TRIANGLELIST:
155             return primitive_count * 3;
156
157         case D3DPT_TRIANGLESTRIP:
158         case D3DPT_TRIANGLEFAN:
159             return primitive_count + 2;
160
161         default:
162             FIXME("Unhandled primitive type %#x\n", primitive_type);
163             return 0;
164     }
165 }
166
167 /* Handle table functions */
168 static DWORD d3d8_allocate_handle(struct d3d8_handle_table *t, void *object, enum d3d8_handle_type type)
169 {
170     struct d3d8_handle_entry *entry;
171
172     if (t->free_entries)
173     {
174         /* Use a free handle */
175         entry = t->free_entries;
176         if (entry->type != D3D8_HANDLE_FREE)
177         {
178             ERR("Handle %u(%p) is in the free list, but has type %#x.\n", (entry - t->entries), entry, entry->type);
179             return D3D8_INVALID_HANDLE;
180         }
181         t->free_entries = entry->object;
182         entry->object = object;
183         entry->type = type;
184
185         return entry - t->entries;
186     }
187
188     if (!(t->entry_count < t->table_size))
189     {
190         /* Grow the table */
191         UINT new_size = t->table_size + (t->table_size >> 1);
192         struct d3d8_handle_entry *new_entries = HeapReAlloc(GetProcessHeap(),
193                 0, t->entries, new_size * sizeof(*t->entries));
194         if (!new_entries)
195         {
196             ERR("Failed to grow the handle table.\n");
197             return D3D8_INVALID_HANDLE;
198         }
199         t->entries = new_entries;
200         t->table_size = new_size;
201     }
202
203     entry = &t->entries[t->entry_count];
204     entry->object = object;
205     entry->type = type;
206
207     return t->entry_count++;
208 }
209
210 static void *d3d8_free_handle(struct d3d8_handle_table *t, DWORD handle, enum d3d8_handle_type type)
211 {
212     struct d3d8_handle_entry *entry;
213     void *object;
214
215     if (handle == D3D8_INVALID_HANDLE || handle >= t->entry_count)
216     {
217         WARN("Invalid handle %u passed.\n", handle);
218         return NULL;
219     }
220
221     entry = &t->entries[handle];
222     if (entry->type != type)
223     {
224         WARN("Handle %u(%p) is not of type %#x.\n", handle, entry, type);
225         return NULL;
226     }
227
228     object = entry->object;
229     entry->object = t->free_entries;
230     entry->type = D3D8_HANDLE_FREE;
231     t->free_entries = entry;
232
233     return object;
234 }
235
236 static void *d3d8_get_object(struct d3d8_handle_table *t, DWORD handle, enum d3d8_handle_type type)
237 {
238     struct d3d8_handle_entry *entry;
239
240     if (handle == D3D8_INVALID_HANDLE || handle >= t->entry_count)
241     {
242         WARN("Invalid handle %u passed.\n", handle);
243         return NULL;
244     }
245
246     entry = &t->entries[handle];
247     if (entry->type != type)
248     {
249         WARN("Handle %u(%p) is not of type %#x.\n", handle, entry, type);
250         return NULL;
251     }
252
253     return entry->object;
254 }
255
256 /* IDirect3D IUnknown parts follow: */
257 static HRESULT WINAPI IDirect3DDevice8Impl_QueryInterface(LPDIRECT3DDEVICE8 iface,REFIID riid,LPVOID *ppobj)
258 {
259     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
260
261     if (IsEqualGUID(riid, &IID_IUnknown)
262         || IsEqualGUID(riid, &IID_IDirect3DDevice8)) {
263         IUnknown_AddRef(iface);
264         *ppobj = This;
265         return S_OK;
266     }
267
268     if (IsEqualGUID(riid, &IID_IWineD3DDeviceParent))
269     {
270         IUnknown_AddRef((IUnknown *)&This->device_parent_vtbl);
271         *ppobj = &This->device_parent_vtbl;
272         return S_OK;
273     }
274
275     WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
276     *ppobj = NULL;
277     return E_NOINTERFACE;
278 }
279
280 static ULONG WINAPI IDirect3DDevice8Impl_AddRef(LPDIRECT3DDEVICE8 iface) {
281     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
282     ULONG ref = InterlockedIncrement(&This->ref);
283
284     TRACE("(%p) : AddRef from %d\n", This, ref - 1);
285
286     return ref;
287 }
288
289 static ULONG WINAPI IDirect3DDevice8Impl_Release(LPDIRECT3DDEVICE8 iface) {
290     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
291     ULONG ref;
292
293     if (This->inDestruction) return 0;
294     ref = InterlockedDecrement(&This->ref);
295
296     TRACE("(%p) : ReleaseRef to %d\n", This, ref);
297
298     if (ref == 0) {
299         unsigned i;
300
301         TRACE("Releasing wined3d device %p\n", This->WineD3DDevice);
302
303         wined3d_mutex_lock();
304
305         This->inDestruction = TRUE;
306
307         for(i = 0; i < This->numConvertedDecls; i++) {
308             IDirect3DVertexDeclaration8_Release(This->decls[i].decl);
309         }
310         HeapFree(GetProcessHeap(), 0, This->decls);
311
312         IWineD3DDevice_Uninit3D(This->WineD3DDevice, D3D8CB_DestroySwapChain);
313         IWineD3DDevice_Release(This->WineD3DDevice);
314         HeapFree(GetProcessHeap(), 0, This->handle_table.entries);
315         HeapFree(GetProcessHeap(), 0, This);
316
317         wined3d_mutex_unlock();
318     }
319     return ref;
320 }
321
322 /* IDirect3DDevice Interface follow: */
323 static HRESULT WINAPI IDirect3DDevice8Impl_TestCooperativeLevel(LPDIRECT3DDEVICE8 iface) {
324     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
325     HRESULT hr;
326
327     TRACE("(%p) : Relay\n", This);
328
329     wined3d_mutex_lock();
330     hr = IWineD3DDevice_TestCooperativeLevel(This->WineD3DDevice);
331     wined3d_mutex_unlock();
332
333     return hr;
334 }
335
336 static UINT WINAPI  IDirect3DDevice8Impl_GetAvailableTextureMem(LPDIRECT3DDEVICE8 iface) {
337     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
338     HRESULT hr;
339
340     TRACE("(%p) Relay\n", This);
341
342     wined3d_mutex_lock();
343     hr = IWineD3DDevice_GetAvailableTextureMem(This->WineD3DDevice);
344     wined3d_mutex_unlock();
345
346     return hr;
347 }
348
349 static HRESULT WINAPI IDirect3DDevice8Impl_ResourceManagerDiscardBytes(LPDIRECT3DDEVICE8 iface, DWORD Bytes) {
350     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
351     HRESULT hr;
352
353     TRACE("(%p) : Relay bytes(%d)\n", This, Bytes);
354
355     wined3d_mutex_lock();
356     hr = IWineD3DDevice_EvictManagedResources(This->WineD3DDevice);
357     wined3d_mutex_unlock();
358
359     return hr;
360 }
361
362 static HRESULT WINAPI IDirect3DDevice8Impl_GetDirect3D(LPDIRECT3DDEVICE8 iface, IDirect3D8** ppD3D8) {
363     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
364     HRESULT hr = D3D_OK;
365     IWineD3D* pWineD3D;
366
367     TRACE("(%p) Relay\n", This);
368
369     if (NULL == ppD3D8) {
370         return D3DERR_INVALIDCALL;
371     }
372
373     wined3d_mutex_lock();
374     hr = IWineD3DDevice_GetDirect3D(This->WineD3DDevice, &pWineD3D);
375     if (hr == D3D_OK && pWineD3D != NULL)
376     {
377         IWineD3D_GetParent(pWineD3D,(IUnknown **)ppD3D8);
378         IWineD3D_Release(pWineD3D);
379     } else {
380         FIXME("Call to IWineD3DDevice_GetDirect3D failed\n");
381         *ppD3D8 = NULL;
382     }
383     wined3d_mutex_unlock();
384
385     TRACE("(%p) returning %p\n",This , *ppD3D8);
386
387     return hr;
388 }
389
390 static HRESULT WINAPI IDirect3DDevice8Impl_GetDeviceCaps(LPDIRECT3DDEVICE8 iface, D3DCAPS8* pCaps) {
391     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
392     HRESULT hrc = D3D_OK;
393     WINED3DCAPS *pWineCaps;
394
395     TRACE("(%p) : Relay pCaps %p\n", This, pCaps);
396     if(NULL == pCaps){
397         return D3DERR_INVALIDCALL;
398     }
399     pWineCaps = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WINED3DCAPS));
400     if(pWineCaps == NULL){
401         return D3DERR_INVALIDCALL; /* well this is what MSDN says to return */
402     }
403
404     wined3d_mutex_lock();
405     hrc = IWineD3DDevice_GetDeviceCaps(This->WineD3DDevice, pWineCaps);
406     wined3d_mutex_unlock();
407
408     fixup_caps(pWineCaps);
409     WINECAPSTOD3D8CAPS(pCaps, pWineCaps)
410     HeapFree(GetProcessHeap(), 0, pWineCaps);
411
412     TRACE("Returning %p %p\n", This, pCaps);
413     return hrc;
414 }
415
416 static HRESULT WINAPI IDirect3DDevice8Impl_GetDisplayMode(LPDIRECT3DDEVICE8 iface, D3DDISPLAYMODE* pMode) {
417     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
418     HRESULT hr;
419     TRACE("(%p) Relay\n", This);
420
421     wined3d_mutex_lock();
422     hr = IWineD3DDevice_GetDisplayMode(This->WineD3DDevice, 0, (WINED3DDISPLAYMODE *) pMode);
423     wined3d_mutex_unlock();
424
425     if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format);
426
427     return hr;
428 }
429
430 static HRESULT WINAPI IDirect3DDevice8Impl_GetCreationParameters(LPDIRECT3DDEVICE8 iface, D3DDEVICE_CREATION_PARAMETERS *pParameters) {
431     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
432     HRESULT hr;
433     TRACE("(%p) Relay\n", This);
434
435     wined3d_mutex_lock();
436     hr = IWineD3DDevice_GetCreationParameters(This->WineD3DDevice, (WINED3DDEVICE_CREATION_PARAMETERS *) pParameters);
437     wined3d_mutex_unlock();
438
439     return hr;
440 }
441
442 static HRESULT WINAPI IDirect3DDevice8Impl_SetCursorProperties(LPDIRECT3DDEVICE8 iface, UINT XHotSpot, UINT YHotSpot, IDirect3DSurface8* pCursorBitmap) {
443     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
444     IDirect3DSurface8Impl *pSurface = (IDirect3DSurface8Impl*)pCursorBitmap;
445     HRESULT hr;
446     TRACE("(%p) Relay\n", This);
447     if(!pCursorBitmap) {
448         WARN("No cursor bitmap, returning WINED3DERR_INVALIDCALL\n");
449         return WINED3DERR_INVALIDCALL;
450     }
451
452     wined3d_mutex_lock();
453     hr = IWineD3DDevice_SetCursorProperties(This->WineD3DDevice,XHotSpot,YHotSpot,pSurface->wineD3DSurface);
454     wined3d_mutex_unlock();
455
456     return hr;
457 }
458
459 static void WINAPI IDirect3DDevice8Impl_SetCursorPosition(LPDIRECT3DDEVICE8 iface, UINT XScreenSpace, UINT YScreenSpace, DWORD Flags) {
460     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
461     TRACE("(%p) Relay\n", This);
462
463     wined3d_mutex_lock();
464     IWineD3DDevice_SetCursorPosition(This->WineD3DDevice, XScreenSpace, YScreenSpace, Flags);
465     wined3d_mutex_unlock();
466 }
467
468 static BOOL WINAPI IDirect3DDevice8Impl_ShowCursor(LPDIRECT3DDEVICE8 iface, BOOL bShow) {
469     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
470     BOOL ret;
471     TRACE("(%p) Relay\n", This);
472
473     wined3d_mutex_lock();
474     ret = IWineD3DDevice_ShowCursor(This->WineD3DDevice, bShow);
475     wined3d_mutex_unlock();
476
477     return ret;
478 }
479
480 static HRESULT WINAPI IDirect3DDevice8Impl_CreateAdditionalSwapChain(LPDIRECT3DDEVICE8 iface, D3DPRESENT_PARAMETERS* pPresentationParameters, IDirect3DSwapChain8** pSwapChain) {
481     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
482     IDirect3DSwapChain8Impl* object;
483     HRESULT hrc = D3D_OK;
484     WINED3DPRESENT_PARAMETERS localParameters;
485
486     TRACE("(%p) Relay\n", This);
487
488     /* Fix the back buffer count */
489     if(pPresentationParameters->BackBufferCount == 0) {
490         pPresentationParameters->BackBufferCount = 1;
491     }
492
493     object = HeapAlloc(GetProcessHeap(),  HEAP_ZERO_MEMORY, sizeof(*object));
494     if (NULL == object) {
495         FIXME("Allocation of memory failed\n");
496         *pSwapChain = NULL;
497         return D3DERR_OUTOFVIDEOMEMORY;
498     }
499     object->ref = 1;
500     object->lpVtbl = &Direct3DSwapChain8_Vtbl;
501
502     /* Allocate an associated WineD3DDevice object */
503     localParameters.BackBufferWidth                             = pPresentationParameters->BackBufferWidth;
504     localParameters.BackBufferHeight                            = pPresentationParameters->BackBufferHeight;
505     localParameters.BackBufferFormat                            = wined3dformat_from_d3dformat(pPresentationParameters->BackBufferFormat);
506     localParameters.BackBufferCount                             = pPresentationParameters->BackBufferCount;
507     localParameters.MultiSampleType                             = pPresentationParameters->MultiSampleType;
508     localParameters.MultiSampleQuality                          = 0; /* d3d9 only */
509     localParameters.SwapEffect                                  = pPresentationParameters->SwapEffect;
510     localParameters.hDeviceWindow                               = pPresentationParameters->hDeviceWindow;
511     localParameters.Windowed                                    = pPresentationParameters->Windowed;
512     localParameters.EnableAutoDepthStencil                      = pPresentationParameters->EnableAutoDepthStencil;
513     localParameters.AutoDepthStencilFormat                      = wined3dformat_from_d3dformat(pPresentationParameters->AutoDepthStencilFormat);
514     localParameters.Flags                                       = pPresentationParameters->Flags;
515     localParameters.FullScreen_RefreshRateInHz                  = pPresentationParameters->FullScreen_RefreshRateInHz;
516     localParameters.PresentationInterval                        = pPresentationParameters->FullScreen_PresentationInterval;
517     localParameters.AutoRestoreDisplayMode                      = TRUE;
518
519     wined3d_mutex_lock();
520     hrc = IWineD3DDevice_CreateSwapChain(This->WineD3DDevice, &localParameters,
521             &object->wineD3DSwapChain, (IUnknown *)object, SURFACE_OPENGL);
522     wined3d_mutex_unlock();
523
524     pPresentationParameters->BackBufferWidth                    = localParameters.BackBufferWidth;
525     pPresentationParameters->BackBufferHeight                   = localParameters.BackBufferHeight;
526     pPresentationParameters->BackBufferFormat                   = d3dformat_from_wined3dformat(localParameters.BackBufferFormat);
527     pPresentationParameters->BackBufferCount                    = localParameters.BackBufferCount;
528     pPresentationParameters->MultiSampleType                    = localParameters.MultiSampleType;
529     pPresentationParameters->SwapEffect                         = localParameters.SwapEffect;
530     pPresentationParameters->hDeviceWindow                      = localParameters.hDeviceWindow;
531     pPresentationParameters->Windowed                           = localParameters.Windowed;
532     pPresentationParameters->EnableAutoDepthStencil             = localParameters.EnableAutoDepthStencil;
533     pPresentationParameters->AutoDepthStencilFormat             = d3dformat_from_wined3dformat(localParameters.AutoDepthStencilFormat);
534     pPresentationParameters->Flags                              = localParameters.Flags;
535     pPresentationParameters->FullScreen_RefreshRateInHz         = localParameters.FullScreen_RefreshRateInHz;
536     pPresentationParameters->FullScreen_PresentationInterval    = localParameters.PresentationInterval;
537
538     if (hrc != D3D_OK) {
539         FIXME("(%p) call to IWineD3DDevice_CreateSwapChain failed\n", This);
540         HeapFree(GetProcessHeap(), 0 , object);
541         *pSwapChain = NULL;
542     }else{
543         IUnknown_AddRef(iface);
544         object->parentDevice = iface;
545         *pSwapChain = (IDirect3DSwapChain8 *)object;
546     }
547     TRACE("(%p) returning %p\n", This, *pSwapChain);
548     return hrc;
549 }
550
551 static HRESULT WINAPI IDirect3DDevice8Impl_Reset(LPDIRECT3DDEVICE8 iface, D3DPRESENT_PARAMETERS* pPresentationParameters) {
552     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
553     WINED3DPRESENT_PARAMETERS localParameters;
554     HRESULT hr;
555
556     TRACE("(%p) Relay pPresentationParameters(%p)\n", This, pPresentationParameters);
557
558     localParameters.BackBufferWidth                             = pPresentationParameters->BackBufferWidth;
559     localParameters.BackBufferHeight                            = pPresentationParameters->BackBufferHeight;
560     localParameters.BackBufferFormat                            = wined3dformat_from_d3dformat(pPresentationParameters->BackBufferFormat);
561     localParameters.BackBufferCount                             = pPresentationParameters->BackBufferCount;
562     localParameters.MultiSampleType                             = pPresentationParameters->MultiSampleType;
563     localParameters.MultiSampleQuality                          = 0; /* d3d9 only */
564     localParameters.SwapEffect                                  = pPresentationParameters->SwapEffect;
565     localParameters.hDeviceWindow                               = pPresentationParameters->hDeviceWindow;
566     localParameters.Windowed                                    = pPresentationParameters->Windowed;
567     localParameters.EnableAutoDepthStencil                      = pPresentationParameters->EnableAutoDepthStencil;
568     localParameters.AutoDepthStencilFormat                      = wined3dformat_from_d3dformat(pPresentationParameters->AutoDepthStencilFormat);
569     localParameters.Flags                                       = pPresentationParameters->Flags;
570     localParameters.FullScreen_RefreshRateInHz                  = pPresentationParameters->FullScreen_RefreshRateInHz;
571     localParameters.PresentationInterval                        = pPresentationParameters->FullScreen_PresentationInterval;
572     localParameters.AutoRestoreDisplayMode                      = TRUE;
573
574     wined3d_mutex_lock();
575     hr = IWineD3DDevice_Reset(This->WineD3DDevice, &localParameters);
576     wined3d_mutex_unlock();
577
578     pPresentationParameters->BackBufferWidth                    = localParameters.BackBufferWidth;
579     pPresentationParameters->BackBufferHeight                   = localParameters.BackBufferHeight;
580     pPresentationParameters->BackBufferFormat                   = d3dformat_from_wined3dformat(localParameters.BackBufferFormat);
581     pPresentationParameters->BackBufferCount                    = localParameters.BackBufferCount;
582     pPresentationParameters->MultiSampleType                    = localParameters.MultiSampleType;
583     pPresentationParameters->SwapEffect                         = localParameters.SwapEffect;
584     pPresentationParameters->hDeviceWindow                      = localParameters.hDeviceWindow;
585     pPresentationParameters->Windowed                           = localParameters.Windowed;
586     pPresentationParameters->EnableAutoDepthStencil             = localParameters.EnableAutoDepthStencil;
587     pPresentationParameters->AutoDepthStencilFormat             = d3dformat_from_wined3dformat(localParameters.AutoDepthStencilFormat);
588     pPresentationParameters->Flags                              = localParameters.Flags;
589     pPresentationParameters->FullScreen_RefreshRateInHz         = localParameters.FullScreen_RefreshRateInHz;
590     pPresentationParameters->FullScreen_PresentationInterval    = localParameters.PresentationInterval;
591
592     return hr;
593 }
594
595 static HRESULT WINAPI IDirect3DDevice8Impl_Present(LPDIRECT3DDEVICE8 iface, CONST RECT* pSourceRect,CONST RECT* pDestRect,HWND hDestWindowOverride,CONST RGNDATA* pDirtyRegion) {
596     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
597     HRESULT hr;
598     TRACE("(%p) Relay\n", This);
599
600     wined3d_mutex_lock();
601     hr = IWineD3DDevice_Present(This->WineD3DDevice, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
602     wined3d_mutex_unlock();
603
604     return hr;
605 }
606
607 static HRESULT WINAPI IDirect3DDevice8Impl_GetBackBuffer(LPDIRECT3DDEVICE8 iface, UINT BackBuffer, D3DBACKBUFFER_TYPE Type, IDirect3DSurface8** ppBackBuffer) {
608     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
609     IWineD3DSurface *retSurface = NULL;
610     HRESULT rc = D3D_OK;
611
612     TRACE("(%p) Relay\n", This);
613
614     wined3d_mutex_lock();
615     rc = IWineD3DDevice_GetBackBuffer(This->WineD3DDevice, 0, BackBuffer, (WINED3DBACKBUFFER_TYPE) Type, &retSurface);
616     if (rc == D3D_OK && NULL != retSurface && NULL != ppBackBuffer) {
617         IWineD3DSurface_GetParent(retSurface, (IUnknown **)ppBackBuffer);
618         IWineD3DSurface_Release(retSurface);
619     }
620     wined3d_mutex_unlock();
621
622     return rc;
623 }
624
625 static HRESULT WINAPI IDirect3DDevice8Impl_GetRasterStatus(LPDIRECT3DDEVICE8 iface, D3DRASTER_STATUS* pRasterStatus) {
626     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
627     HRESULT hr;
628     TRACE("(%p) Relay\n", This);
629
630     wined3d_mutex_lock();
631     hr = IWineD3DDevice_GetRasterStatus(This->WineD3DDevice, 0, (WINED3DRASTER_STATUS *) pRasterStatus);
632     wined3d_mutex_unlock();
633
634     return hr;
635 }
636
637 static void WINAPI IDirect3DDevice8Impl_SetGammaRamp(LPDIRECT3DDEVICE8 iface, DWORD Flags, CONST D3DGAMMARAMP* pRamp) {
638     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
639     TRACE("(%p) Relay\n", This);
640
641     /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
642     wined3d_mutex_lock();
643     IWineD3DDevice_SetGammaRamp(This->WineD3DDevice, 0, Flags, (CONST WINED3DGAMMARAMP *) pRamp);
644     wined3d_mutex_unlock();
645 }
646
647 static void WINAPI IDirect3DDevice8Impl_GetGammaRamp(LPDIRECT3DDEVICE8 iface, D3DGAMMARAMP* pRamp) {
648     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
649     TRACE("(%p) Relay\n", This);
650
651     /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
652     wined3d_mutex_lock();
653     IWineD3DDevice_GetGammaRamp(This->WineD3DDevice, 0, (WINED3DGAMMARAMP *) pRamp);
654     wined3d_mutex_unlock();
655 }
656
657 static HRESULT WINAPI IDirect3DDevice8Impl_CreateTexture(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height, UINT Levels, DWORD Usage,
658                                                     D3DFORMAT Format, D3DPOOL Pool, IDirect3DTexture8 **ppTexture) {
659     IDirect3DTexture8Impl *object;
660     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
661     HRESULT hrc = D3D_OK;
662
663     TRACE("(%p) : W(%d) H(%d), Lvl(%d) d(%d), Fmt(%u), Pool(%d)\n", This, Width, Height, Levels, Usage, Format,  Pool);
664
665     /* Allocate the storage for the device */
666     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DTexture8Impl));
667
668     if (NULL == object) {
669         FIXME("Allocation of memory failed\n");
670 /*        *ppTexture = NULL; */
671         return D3DERR_OUTOFVIDEOMEMORY;
672     }
673
674     object->lpVtbl = &Direct3DTexture8_Vtbl;
675     object->ref = 1;
676
677     wined3d_mutex_lock();
678     hrc = IWineD3DDevice_CreateTexture(This->WineD3DDevice, Width, Height, Levels, Usage & WINED3DUSAGE_MASK,
679             wined3dformat_from_d3dformat(Format), Pool, &object->wineD3DTexture, (IUnknown *)object);
680     wined3d_mutex_unlock();
681
682     if (FAILED(hrc)) {
683         /* free up object */
684         FIXME("(%p) call to IWineD3DDevice_CreateTexture failed\n", This);
685         HeapFree(GetProcessHeap(), 0, object);
686 /*      *ppTexture = NULL; */
687    } else {
688         IUnknown_AddRef(iface);
689         object->parentDevice = iface;
690         *ppTexture = (LPDIRECT3DTEXTURE8) object;
691         TRACE("(%p) Created Texture %p, %p\n",This,object,object->wineD3DTexture);
692    }
693
694    return hrc;
695 }
696
697 static HRESULT WINAPI IDirect3DDevice8Impl_CreateVolumeTexture(IDirect3DDevice8 *iface,
698         UINT width, UINT height, UINT depth, UINT levels, DWORD usage, D3DFORMAT format,
699         D3DPOOL pool, IDirect3DVolumeTexture8 **texture)
700 {
701     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
702     IDirect3DVolumeTexture8Impl *object;
703     HRESULT hr;
704
705     TRACE("iface %p, width %u, height %u, depth %u, levels %u, usage %#x, format %#x, pool %#x, texture %p.\n",
706             iface, width, height, depth, levels, usage, format, pool, texture);
707
708     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
709     if (!object)
710     {
711         ERR("Failed to allocate volume texture memory.\n");
712         return D3DERR_OUTOFVIDEOMEMORY;
713     }
714
715     hr = volumetexture_init(object, This, width, height, depth, levels, usage, format, pool);
716     if (FAILED(hr))
717     {
718         WARN("Failed to initialize volume texture, hr %#x.\n", hr);
719         HeapFree(GetProcessHeap(), 0, object);
720         return hr;
721     }
722
723     TRACE("Created volume texture %p.\n", object);
724     *texture = (IDirect3DVolumeTexture8 *)object;
725
726     return D3D_OK;
727 }
728
729 static HRESULT WINAPI IDirect3DDevice8Impl_CreateCubeTexture(IDirect3DDevice8 *iface, UINT EdgeLength,
730         UINT Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IDirect3DCubeTexture8 **ppCubeTexture)
731 {
732     IDirect3DCubeTexture8Impl *object;
733     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
734     HRESULT hr = D3D_OK;
735
736     TRACE("(%p) : ELen(%d) Lvl(%d) Usage(%d) fmt(%u), Pool(%d)\n" , This, EdgeLength, Levels, Usage, Format, Pool);
737
738     /* Allocate the storage for the device */
739     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
740
741     if (NULL == object) {
742         FIXME("(%p) allocation of CubeTexture failed\n", This);
743         *ppCubeTexture = NULL;
744         return D3DERR_OUTOFVIDEOMEMORY;
745     }
746
747     object->lpVtbl = &Direct3DCubeTexture8_Vtbl;
748     object->ref = 1;
749
750     wined3d_mutex_lock();
751     hr = IWineD3DDevice_CreateCubeTexture(This->WineD3DDevice, EdgeLength, Levels, Usage & WINED3DUSAGE_MASK,
752             wined3dformat_from_d3dformat(Format), Pool, &object->wineD3DCubeTexture, (IUnknown *)object);
753     wined3d_mutex_unlock();
754
755     if (hr != D3D_OK){
756
757         /* free up object */
758         FIXME("(%p) call to IWineD3DDevice_CreateCubeTexture failed\n", This);
759         HeapFree(GetProcessHeap(), 0, object);
760         *ppCubeTexture = NULL;
761     } else {
762         IUnknown_AddRef(iface);
763         object->parentDevice = iface;
764         *ppCubeTexture = (LPDIRECT3DCUBETEXTURE8) object;
765     }
766
767     TRACE("(%p) returning %p\n",This, *ppCubeTexture);
768     return hr;
769 }
770
771 static HRESULT WINAPI IDirect3DDevice8Impl_CreateVertexBuffer(LPDIRECT3DDEVICE8 iface, UINT Size, DWORD Usage, DWORD FVF, D3DPOOL Pool, IDirect3DVertexBuffer8** ppVertexBuffer) {
772     IDirect3DVertexBuffer8Impl *object;
773     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
774     HRESULT hrc = D3D_OK;
775
776     TRACE("(%p) Relay\n", This);
777     /* Allocate the storage for the device */
778     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DVertexBuffer8Impl));
779     if (NULL == object) {
780         FIXME("Allocation of memory failed\n");
781         *ppVertexBuffer = NULL;
782         return D3DERR_OUTOFVIDEOMEMORY;
783     }
784
785     object->lpVtbl = &Direct3DVertexBuffer8_Vtbl;
786     object->ref = 1;
787
788     wined3d_mutex_lock();
789     hrc = IWineD3DDevice_CreateVertexBuffer(This->WineD3DDevice, Size, Usage & WINED3DUSAGE_MASK,
790             0 /* fvf for ddraw only */, (WINED3DPOOL)Pool, &object->wineD3DVertexBuffer, (IUnknown *)object);
791     wined3d_mutex_unlock();
792
793     object->fvf = FVF;
794
795     if (D3D_OK != hrc) {
796
797         /* free up object */
798         FIXME("(%p) call to IWineD3DDevice_CreateVertexBuffer failed\n", This);
799         HeapFree(GetProcessHeap(), 0, object);
800         *ppVertexBuffer = NULL;
801     } else {
802         IUnknown_AddRef(iface);
803         object->parentDevice = iface;
804         *ppVertexBuffer = (LPDIRECT3DVERTEXBUFFER8) object;
805     }
806     return hrc;
807 }
808
809 static HRESULT WINAPI IDirect3DDevice8Impl_CreateIndexBuffer(LPDIRECT3DDEVICE8 iface, UINT Length, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IDirect3DIndexBuffer8** ppIndexBuffer) {
810     IDirect3DIndexBuffer8Impl *object;
811     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
812     HRESULT hrc = D3D_OK;
813
814     TRACE("(%p) Relay\n", This);
815     /* Allocate the storage for the device */
816     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
817     if (NULL == object) {
818         FIXME("Allocation of memory failed\n");
819         *ppIndexBuffer = NULL;
820         return D3DERR_OUTOFVIDEOMEMORY;
821     }
822
823     object->lpVtbl = &Direct3DIndexBuffer8_Vtbl;
824     object->ref = 1;
825     object->format = wined3dformat_from_d3dformat(Format);
826     TRACE("Calling wined3d create index buffer\n");
827
828     wined3d_mutex_lock();
829     hrc = IWineD3DDevice_CreateIndexBuffer(This->WineD3DDevice, Length, Usage & WINED3DUSAGE_MASK,
830             (WINED3DPOOL)Pool, &object->wineD3DIndexBuffer, (IUnknown *)object);
831     wined3d_mutex_unlock();
832
833     if (D3D_OK != hrc) {
834
835         /* free up object */
836         FIXME("(%p) call to IWineD3DDevice_CreateIndexBuffer failed\n", This);
837         HeapFree(GetProcessHeap(), 0, object);
838         *ppIndexBuffer = NULL;
839     } else {
840         IUnknown_AddRef(iface);
841         object->parentDevice = iface;
842         *ppIndexBuffer = (LPDIRECT3DINDEXBUFFER8)object;
843     }
844     return hrc;
845 }
846
847 static HRESULT IDirect3DDevice8Impl_CreateSurface(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height,
848         D3DFORMAT Format, BOOL Lockable, BOOL Discard, UINT Level, IDirect3DSurface8 **ppSurface,
849         UINT Usage, D3DPOOL Pool, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality)
850 {
851     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
852     IDirect3DSurface8Impl *object;
853     HRESULT hr;
854
855     TRACE("(%p) : w(%d) h(%d) fmt(%d) surf@%p\n", This, Width, Height, Format, *ppSurface);
856
857     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DSurface8Impl));
858     if (!object)
859     {
860         FIXME("Failed to allocate surface memory.\n");
861         return D3DERR_OUTOFVIDEOMEMORY;
862     }
863
864     hr = surface_init(object, This, Width, Height, Format, Lockable, Discard,
865             Level, Usage, Pool, MultiSample, MultisampleQuality);
866     if (FAILED(hr))
867     {
868         WARN("Failed to initialize surface, hr %#x.\n", hr);
869         HeapFree(GetProcessHeap(), 0, object);
870         return hr;
871     }
872
873     TRACE("Created surface %p.\n", object);
874     *ppSurface = (IDirect3DSurface8 *)object;
875
876     return D3D_OK;
877 }
878
879 static HRESULT WINAPI IDirect3DDevice8Impl_CreateRenderTarget(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, BOOL Lockable, IDirect3DSurface8** ppSurface) {
880     HRESULT hr;
881     TRACE("Relay\n");
882
883     hr = IDirect3DDevice8Impl_CreateSurface(iface, Width, Height, Format, Lockable, FALSE /* Discard */,
884             0 /* Level */, ppSurface, D3DUSAGE_RENDERTARGET, D3DPOOL_DEFAULT, MultiSample, 0);
885
886     return hr;
887 }
888
889 static HRESULT WINAPI IDirect3DDevice8Impl_CreateDepthStencilSurface(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, IDirect3DSurface8** ppSurface) {
890     HRESULT hr;
891     TRACE("Relay\n");
892
893     /* TODO: Verify that Discard is false */
894     hr = IDirect3DDevice8Impl_CreateSurface(iface, Width, Height, Format, TRUE /* Lockable */, FALSE,
895             0 /* Level */, ppSurface, D3DUSAGE_DEPTHSTENCIL, D3DPOOL_DEFAULT, MultiSample, 0);
896
897     return hr;
898 }
899
900 /*  IDirect3DDevice8Impl::CreateImageSurface returns surface with pool type SYSTEMMEM */
901 static HRESULT WINAPI IDirect3DDevice8Impl_CreateImageSurface(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height, D3DFORMAT Format, IDirect3DSurface8** ppSurface) {
902     HRESULT hr;
903     TRACE("Relay\n");
904
905     hr = IDirect3DDevice8Impl_CreateSurface(iface, Width, Height, Format, TRUE /* Lockable */, FALSE /* Discard */,
906             0 /* Level */, ppSurface, 0 /* Usage (undefined/none) */, D3DPOOL_SYSTEMMEM, D3DMULTISAMPLE_NONE,
907             0 /* MultisampleQuality */);
908
909     return hr;
910 }
911
912 static HRESULT WINAPI IDirect3DDevice8Impl_CopyRects(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8 *pSourceSurface, CONST RECT *pSourceRects, UINT cRects, IDirect3DSurface8 *pDestinationSurface, CONST POINT *pDestPoints) {
913     IDirect3DSurface8Impl *Source = (IDirect3DSurface8Impl *) pSourceSurface;
914     IDirect3DSurface8Impl *Dest = (IDirect3DSurface8Impl *) pDestinationSurface;
915
916     HRESULT              hr = WINED3D_OK;
917     WINED3DFORMAT        srcFormat, destFormat;
918     UINT                 srcWidth,  destWidth;
919     UINT                 srcHeight, destHeight;
920     UINT                 srcSize;
921     WINED3DSURFACE_DESC  winedesc;
922
923     TRACE("(%p) pSrcSur=%p, pSourceRects=%p, cRects=%d, pDstSur=%p, pDestPtsArr=%p\n", iface,
924           pSourceSurface, pSourceRects, cRects, pDestinationSurface, pDestPoints);
925
926
927     /* Check that the source texture is in WINED3DPOOL_SYSTEMMEM and the destination texture is in WINED3DPOOL_DEFAULT */
928
929     wined3d_mutex_lock();
930     IWineD3DSurface_GetDesc(Source->wineD3DSurface, &winedesc);
931     srcFormat = winedesc.format;
932     srcWidth = winedesc.width;
933     srcHeight = winedesc.height;
934     srcSize = winedesc.size;
935
936     IWineD3DSurface_GetDesc(Dest->wineD3DSurface, &winedesc);
937     destFormat = winedesc.format;
938     destWidth = winedesc.width;
939     destHeight = winedesc.height;
940
941     /* Check that the source and destination formats match */
942     if (srcFormat != destFormat && WINED3DFMT_UNKNOWN != destFormat) {
943         WARN("(%p) source %p format must match the dest %p format, returning WINED3DERR_INVALIDCALL\n", iface, pSourceSurface, pDestinationSurface);
944         wined3d_mutex_unlock();
945         return WINED3DERR_INVALIDCALL;
946     } else if (WINED3DFMT_UNKNOWN == destFormat) {
947         TRACE("(%p) : Converting destination surface from WINED3DFMT_UNKNOWN to the source format\n", iface);
948         IWineD3DSurface_SetFormat(Dest->wineD3DSurface, srcFormat);
949         destFormat = srcFormat;
950     }
951
952     /* Quick if complete copy ... */
953     if (cRects == 0 && pSourceRects == NULL && pDestPoints == NULL) {
954         IWineD3DSurface_BltFast(Dest->wineD3DSurface, 0, 0, Source->wineD3DSurface, NULL, WINEDDBLTFAST_NOCOLORKEY);
955     } else {
956         unsigned int i;
957         /* Copy rect by rect */
958         if (NULL != pSourceRects && NULL != pDestPoints) {
959             for (i = 0; i < cRects; ++i) {
960                 IWineD3DSurface_BltFast(Dest->wineD3DSurface, pDestPoints[i].x, pDestPoints[i].y, Source->wineD3DSurface, &pSourceRects[i], WINEDDBLTFAST_NOCOLORKEY);
961             }
962         } else {
963             for (i = 0; i < cRects; ++i) {
964                 IWineD3DSurface_BltFast(Dest->wineD3DSurface, 0, 0, Source->wineD3DSurface, &pSourceRects[i], WINEDDBLTFAST_NOCOLORKEY);
965             }
966         }
967     }
968     wined3d_mutex_unlock();
969
970     return hr;
971 }
972
973 static HRESULT WINAPI IDirect3DDevice8Impl_UpdateTexture(LPDIRECT3DDEVICE8 iface, IDirect3DBaseTexture8* pSourceTexture, IDirect3DBaseTexture8* pDestinationTexture) {
974     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
975     HRESULT hr;
976     TRACE("(%p) Relay\n" , This);
977
978     wined3d_mutex_lock();
979     hr = IWineD3DDevice_UpdateTexture(This->WineD3DDevice,  ((IDirect3DBaseTexture8Impl *)pSourceTexture)->wineD3DBaseTexture, ((IDirect3DBaseTexture8Impl *)pDestinationTexture)->wineD3DBaseTexture);
980     wined3d_mutex_unlock();
981
982     return hr;
983 }
984
985 static HRESULT WINAPI IDirect3DDevice8Impl_GetFrontBuffer(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8* pDestSurface) {
986     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
987     IDirect3DSurface8Impl *destSurface = (IDirect3DSurface8Impl *)pDestSurface;
988     HRESULT hr;
989
990     TRACE("(%p) Relay\n" , This);
991
992     if (pDestSurface == NULL) {
993         WARN("(%p) : Caller passed NULL as pDestSurface returning D3DERR_INVALIDCALL\n", This);
994         return D3DERR_INVALIDCALL;
995     }
996
997     wined3d_mutex_lock();
998     hr = IWineD3DDevice_GetFrontBufferData(This->WineD3DDevice, 0, destSurface->wineD3DSurface);
999     wined3d_mutex_unlock();
1000
1001     return hr;
1002 }
1003
1004 static HRESULT WINAPI IDirect3DDevice8Impl_SetRenderTarget(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8* pRenderTarget, IDirect3DSurface8* pNewZStencil) {
1005     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1006     IDirect3DSurface8Impl *pSurface = (IDirect3DSurface8Impl *)pRenderTarget;
1007     IDirect3DSurface8Impl *pZSurface = (IDirect3DSurface8Impl *)pNewZStencil;
1008     IWineD3DSurface *original_ds = NULL;
1009     HRESULT hr;
1010     TRACE("(%p) Relay\n" , This);
1011
1012     wined3d_mutex_lock();
1013
1014     hr = IWineD3DDevice_GetDepthStencilSurface(This->WineD3DDevice, &original_ds);
1015     if (hr == WINED3D_OK || hr == WINED3DERR_NOTFOUND)
1016     {
1017         hr = IWineD3DDevice_SetDepthStencilSurface(This->WineD3DDevice, pZSurface ? pZSurface->wineD3DSurface : NULL);
1018         if (SUCCEEDED(hr) && pSurface)
1019             hr = IWineD3DDevice_SetRenderTarget(This->WineD3DDevice, 0, pSurface->wineD3DSurface);
1020         if (FAILED(hr)) IWineD3DDevice_SetDepthStencilSurface(This->WineD3DDevice, original_ds);
1021     }
1022     if (original_ds) IWineD3DSurface_Release(original_ds);
1023
1024     wined3d_mutex_unlock();
1025
1026     return hr;
1027 }
1028
1029 static HRESULT  WINAPI  IDirect3DDevice8Impl_GetRenderTarget(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8** ppRenderTarget) {
1030     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1031     HRESULT hr = D3D_OK;
1032     IWineD3DSurface *pRenderTarget;
1033
1034     TRACE("(%p) Relay\n" , This);
1035
1036     if (ppRenderTarget == NULL) {
1037         return D3DERR_INVALIDCALL;
1038     }
1039
1040     wined3d_mutex_lock();
1041     hr = IWineD3DDevice_GetRenderTarget(This->WineD3DDevice, 0, &pRenderTarget);
1042
1043     if (hr == D3D_OK && pRenderTarget != NULL) {
1044         IWineD3DSurface_GetParent(pRenderTarget,(IUnknown**)ppRenderTarget);
1045         IWineD3DSurface_Release(pRenderTarget);
1046     } else {
1047         FIXME("Call to IWineD3DDevice_GetRenderTarget failed\n");
1048         *ppRenderTarget = NULL;
1049     }
1050     wined3d_mutex_unlock();
1051
1052     return hr;
1053 }
1054
1055 static HRESULT  WINAPI  IDirect3DDevice8Impl_GetDepthStencilSurface(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8** ppZStencilSurface) {
1056     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1057     HRESULT hr = D3D_OK;
1058     IWineD3DSurface *pZStencilSurface;
1059
1060     TRACE("(%p) Relay\n" , This);
1061     if(ppZStencilSurface == NULL){
1062         return D3DERR_INVALIDCALL;
1063     }
1064
1065     wined3d_mutex_lock();
1066     hr=IWineD3DDevice_GetDepthStencilSurface(This->WineD3DDevice,&pZStencilSurface);
1067     if (hr == WINED3D_OK) {
1068         IWineD3DSurface_GetParent(pZStencilSurface,(IUnknown**)ppZStencilSurface);
1069         IWineD3DSurface_Release(pZStencilSurface);
1070     }else{
1071         if (hr != WINED3DERR_NOTFOUND)
1072                 FIXME("Call to IWineD3DDevice_GetDepthStencilSurface failed with 0x%08x\n", hr);
1073         *ppZStencilSurface = NULL;
1074     }
1075     wined3d_mutex_unlock();
1076
1077     return hr;
1078 }
1079
1080 static HRESULT WINAPI IDirect3DDevice8Impl_BeginScene(LPDIRECT3DDEVICE8 iface) {
1081     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1082     HRESULT hr;
1083     TRACE("(%p) Relay\n" , This);
1084
1085     wined3d_mutex_lock();
1086     hr = IWineD3DDevice_BeginScene(This->WineD3DDevice);
1087     wined3d_mutex_unlock();
1088
1089     return hr;
1090 }
1091
1092 static HRESULT WINAPI IDirect3DDevice8Impl_EndScene(LPDIRECT3DDEVICE8 iface) {
1093     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1094     HRESULT hr;
1095     TRACE("(%p) Relay\n" , This);
1096
1097     wined3d_mutex_lock();
1098     hr = IWineD3DDevice_EndScene(This->WineD3DDevice);
1099     wined3d_mutex_unlock();
1100
1101     return hr;
1102 }
1103
1104 static HRESULT WINAPI IDirect3DDevice8Impl_Clear(LPDIRECT3DDEVICE8 iface, DWORD Count, CONST D3DRECT* pRects, DWORD Flags, D3DCOLOR Color, float Z, DWORD Stencil) {
1105     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1106     HRESULT hr;
1107     TRACE("(%p) Relay\n" , This);
1108
1109     /* Note: D3DRECT is compatible with WINED3DRECT */
1110     wined3d_mutex_lock();
1111     hr = IWineD3DDevice_Clear(This->WineD3DDevice, Count, (CONST WINED3DRECT*) pRects, Flags, Color, Z, Stencil);
1112     wined3d_mutex_unlock();
1113
1114     return hr;
1115 }
1116
1117 static HRESULT WINAPI IDirect3DDevice8Impl_SetTransform(LPDIRECT3DDEVICE8 iface, D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX* lpMatrix) {
1118     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1119     HRESULT hr;
1120     TRACE("(%p) Relay\n" , This);
1121
1122     /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1123     wined3d_mutex_lock();
1124     hr = IWineD3DDevice_SetTransform(This->WineD3DDevice, State, (CONST WINED3DMATRIX*) lpMatrix);
1125     wined3d_mutex_unlock();
1126
1127     return hr;
1128 }
1129
1130 static HRESULT WINAPI IDirect3DDevice8Impl_GetTransform(LPDIRECT3DDEVICE8 iface, D3DTRANSFORMSTATETYPE State,D3DMATRIX* pMatrix) {
1131     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1132     HRESULT hr;
1133     TRACE("(%p) Relay\n" , This);
1134
1135     /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1136     wined3d_mutex_lock();
1137     hr = IWineD3DDevice_GetTransform(This->WineD3DDevice, State, (WINED3DMATRIX*) pMatrix);
1138     wined3d_mutex_unlock();
1139
1140     return hr;
1141 }
1142
1143 static HRESULT WINAPI IDirect3DDevice8Impl_MultiplyTransform(LPDIRECT3DDEVICE8 iface, D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX* pMatrix) {
1144     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1145     HRESULT hr;
1146     TRACE("(%p) Relay\n" , This);
1147
1148     /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1149     wined3d_mutex_lock();
1150     hr = IWineD3DDevice_MultiplyTransform(This->WineD3DDevice, State, (CONST WINED3DMATRIX*) pMatrix);
1151     wined3d_mutex_unlock();
1152
1153     return hr;
1154 }
1155
1156 static HRESULT WINAPI IDirect3DDevice8Impl_SetViewport(LPDIRECT3DDEVICE8 iface, CONST D3DVIEWPORT8* pViewport) {
1157     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1158     HRESULT hr;
1159     TRACE("(%p) Relay\n" , This);
1160
1161     /* Note: D3DVIEWPORT8 is compatible with WINED3DVIEWPORT */
1162     wined3d_mutex_lock();
1163     hr = IWineD3DDevice_SetViewport(This->WineD3DDevice, (const WINED3DVIEWPORT *)pViewport);
1164     wined3d_mutex_unlock();
1165
1166     return hr;
1167 }
1168
1169 static HRESULT WINAPI IDirect3DDevice8Impl_GetViewport(LPDIRECT3DDEVICE8 iface, D3DVIEWPORT8* pViewport) {
1170     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1171     HRESULT hr;
1172     TRACE("(%p) Relay\n" , This);
1173
1174     /* Note: D3DVIEWPORT8 is compatible with WINED3DVIEWPORT */
1175     wined3d_mutex_lock();
1176     hr = IWineD3DDevice_GetViewport(This->WineD3DDevice, (WINED3DVIEWPORT *)pViewport);
1177     wined3d_mutex_unlock();
1178
1179     return hr;
1180 }
1181
1182 static HRESULT WINAPI IDirect3DDevice8Impl_SetMaterial(LPDIRECT3DDEVICE8 iface, CONST D3DMATERIAL8* pMaterial) {
1183     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1184     HRESULT hr;
1185     TRACE("(%p) Relay\n" , This);
1186
1187     /* Note: D3DMATERIAL8 is compatible with WINED3DMATERIAL */
1188     wined3d_mutex_lock();
1189     hr = IWineD3DDevice_SetMaterial(This->WineD3DDevice, (const WINED3DMATERIAL *)pMaterial);
1190     wined3d_mutex_unlock();
1191
1192     return hr;
1193 }
1194
1195 static HRESULT WINAPI IDirect3DDevice8Impl_GetMaterial(LPDIRECT3DDEVICE8 iface, D3DMATERIAL8* pMaterial) {
1196     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1197     HRESULT hr;
1198     TRACE("(%p) Relay\n" , This);
1199
1200     /* Note: D3DMATERIAL8 is compatible with WINED3DMATERIAL */
1201     wined3d_mutex_lock();
1202     hr = IWineD3DDevice_GetMaterial(This->WineD3DDevice, (WINED3DMATERIAL *)pMaterial);
1203     wined3d_mutex_unlock();
1204
1205     return hr;
1206 }
1207
1208 static HRESULT WINAPI IDirect3DDevice8Impl_SetLight(LPDIRECT3DDEVICE8 iface, DWORD Index, CONST D3DLIGHT8* pLight) {
1209     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1210     HRESULT hr;
1211     TRACE("(%p) Relay\n" , This);
1212
1213     /* Note: D3DLIGHT8 is compatible with WINED3DLIGHT */
1214     wined3d_mutex_lock();
1215     hr = IWineD3DDevice_SetLight(This->WineD3DDevice, Index, (const WINED3DLIGHT *)pLight);
1216     wined3d_mutex_unlock();
1217
1218     return hr;
1219 }
1220
1221 static HRESULT WINAPI IDirect3DDevice8Impl_GetLight(LPDIRECT3DDEVICE8 iface, DWORD Index,D3DLIGHT8* pLight) {
1222     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1223     HRESULT hr;
1224     TRACE("(%p) Relay\n" , This);
1225
1226     /* Note: D3DLIGHT8 is compatible with WINED3DLIGHT */
1227     wined3d_mutex_lock();
1228     hr = IWineD3DDevice_GetLight(This->WineD3DDevice, Index, (WINED3DLIGHT *)pLight);
1229     wined3d_mutex_unlock();
1230
1231     return hr;
1232 }
1233
1234 static HRESULT WINAPI IDirect3DDevice8Impl_LightEnable(LPDIRECT3DDEVICE8 iface, DWORD Index,BOOL Enable) {
1235     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1236     HRESULT hr;
1237     TRACE("(%p) Relay\n" , This);
1238
1239     wined3d_mutex_lock();
1240     hr = IWineD3DDevice_SetLightEnable(This->WineD3DDevice, Index, Enable);
1241     wined3d_mutex_unlock();
1242
1243     return hr;
1244 }
1245
1246 static HRESULT WINAPI IDirect3DDevice8Impl_GetLightEnable(LPDIRECT3DDEVICE8 iface, DWORD Index,BOOL* pEnable) {
1247     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1248     HRESULT hr;
1249     TRACE("(%p) Relay\n" , This);
1250
1251     wined3d_mutex_lock();
1252     hr = IWineD3DDevice_GetLightEnable(This->WineD3DDevice, Index, pEnable);
1253     wined3d_mutex_unlock();
1254
1255     return hr;
1256 }
1257
1258 static HRESULT WINAPI IDirect3DDevice8Impl_SetClipPlane(LPDIRECT3DDEVICE8 iface, DWORD Index,CONST float* pPlane) {
1259     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1260     HRESULT hr;
1261     TRACE("(%p) Relay\n" , This);
1262
1263     wined3d_mutex_lock();
1264     hr = IWineD3DDevice_SetClipPlane(This->WineD3DDevice, Index, pPlane);
1265     wined3d_mutex_unlock();
1266
1267     return hr;
1268 }
1269
1270 static HRESULT WINAPI IDirect3DDevice8Impl_GetClipPlane(LPDIRECT3DDEVICE8 iface, DWORD Index,float* pPlane) {
1271     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1272     HRESULT hr;
1273     TRACE("(%p) Relay\n" , This);
1274
1275     wined3d_mutex_lock();
1276     hr = IWineD3DDevice_GetClipPlane(This->WineD3DDevice, Index, pPlane);
1277     wined3d_mutex_unlock();
1278
1279     return hr;
1280 }
1281
1282 static HRESULT WINAPI IDirect3DDevice8Impl_SetRenderState(LPDIRECT3DDEVICE8 iface, D3DRENDERSTATETYPE State,DWORD Value) {
1283     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1284     HRESULT hr;
1285     TRACE("(%p) Relay\n" , This);
1286
1287     wined3d_mutex_lock();
1288     hr = IWineD3DDevice_SetRenderState(This->WineD3DDevice, State, Value);
1289     wined3d_mutex_unlock();
1290
1291     return hr;
1292 }
1293
1294 static HRESULT WINAPI IDirect3DDevice8Impl_GetRenderState(LPDIRECT3DDEVICE8 iface, D3DRENDERSTATETYPE State,DWORD* pValue) {
1295     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1296     HRESULT hr;
1297     TRACE("(%p) Relay\n" , This);
1298
1299     wined3d_mutex_lock();
1300     hr = IWineD3DDevice_GetRenderState(This->WineD3DDevice, State, pValue);
1301     wined3d_mutex_unlock();
1302
1303     return hr;
1304 }
1305
1306 static HRESULT WINAPI IDirect3DDevice8Impl_BeginStateBlock(LPDIRECT3DDEVICE8 iface) {
1307     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1308     HRESULT hr;
1309     TRACE("(%p)\n", This);
1310
1311     wined3d_mutex_lock();
1312     hr = IWineD3DDevice_BeginStateBlock(This->WineD3DDevice);
1313     wined3d_mutex_unlock();
1314
1315     return hr;
1316 }
1317
1318 static HRESULT WINAPI IDirect3DDevice8Impl_EndStateBlock(LPDIRECT3DDEVICE8 iface, DWORD* pToken) {
1319     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1320     HRESULT hr;
1321     IWineD3DStateBlock* wineD3DStateBlock;
1322     IDirect3DStateBlock8Impl* object;
1323
1324     TRACE("(%p) Relay\n", This);
1325
1326     /* Tell wineD3D to endstateblock before anything else (in case we run out
1327      * of memory later and cause locking problems)
1328      */
1329     wined3d_mutex_lock();
1330     hr = IWineD3DDevice_EndStateBlock(This->WineD3DDevice , &wineD3DStateBlock);
1331     if (hr != D3D_OK) {
1332         WARN("IWineD3DDevice_EndStateBlock returned an error\n");
1333         wined3d_mutex_unlock();
1334         return hr;
1335     }
1336
1337     /* allocate a new IDirectD3DStateBlock */
1338     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY ,sizeof(IDirect3DStateBlock8Impl));
1339     object->ref = 1;
1340     object->lpVtbl = &Direct3DStateBlock8_Vtbl;
1341
1342     object->wineD3DStateBlock = wineD3DStateBlock;
1343
1344     *pToken = d3d8_allocate_handle(&This->handle_table, object, D3D8_HANDLE_SB);
1345     wined3d_mutex_unlock();
1346
1347     if (*pToken == D3D8_INVALID_HANDLE)
1348     {
1349         ERR("Failed to create a handle\n");
1350         IDirect3DStateBlock8_Release((IDirect3DStateBlock8 *)object);
1351         return E_FAIL;
1352     }
1353     ++*pToken;
1354
1355     TRACE("Returning %#x (%p).\n", *pToken, object);
1356
1357     return hr;
1358 }
1359
1360 static HRESULT WINAPI IDirect3DDevice8Impl_ApplyStateBlock(LPDIRECT3DDEVICE8 iface, DWORD Token) {
1361     IDirect3DDevice8Impl     *This = (IDirect3DDevice8Impl *)iface;
1362     IDirect3DStateBlock8Impl *pSB;
1363     HRESULT hr;
1364
1365     TRACE("(%p) %#x Relay\n", This, Token);
1366
1367     wined3d_mutex_lock();
1368     pSB = d3d8_get_object(&This->handle_table, Token - 1, D3D8_HANDLE_SB);
1369     if (!pSB)
1370     {
1371         WARN("Invalid handle (%#x) passed.\n", Token);
1372         wined3d_mutex_unlock();
1373         return D3DERR_INVALIDCALL;
1374     }
1375     hr = IWineD3DStateBlock_Apply(pSB->wineD3DStateBlock);
1376     wined3d_mutex_unlock();
1377
1378     return hr;
1379 }
1380
1381 static HRESULT WINAPI IDirect3DDevice8Impl_CaptureStateBlock(LPDIRECT3DDEVICE8 iface, DWORD Token) {
1382     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1383     IDirect3DStateBlock8Impl *pSB;
1384     HRESULT hr;
1385
1386     TRACE("(%p) %#x Relay\n", This, Token);
1387
1388     wined3d_mutex_lock();
1389     pSB = d3d8_get_object(&This->handle_table, Token - 1, D3D8_HANDLE_SB);
1390     if (!pSB)
1391     {
1392         WARN("Invalid handle (%#x) passed.\n", Token);
1393         wined3d_mutex_unlock();
1394         return D3DERR_INVALIDCALL;
1395     }
1396     hr = IWineD3DStateBlock_Capture(pSB->wineD3DStateBlock);
1397     wined3d_mutex_unlock();
1398
1399     return hr;
1400 }
1401
1402 static HRESULT WINAPI IDirect3DDevice8Impl_DeleteStateBlock(LPDIRECT3DDEVICE8 iface, DWORD Token) {
1403     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1404     IDirect3DStateBlock8Impl *pSB;
1405
1406     TRACE("(%p) Relay\n", This);
1407
1408     wined3d_mutex_lock();
1409     pSB = d3d8_free_handle(&This->handle_table, Token - 1, D3D8_HANDLE_SB);
1410     wined3d_mutex_unlock();
1411
1412     if (!pSB)
1413     {
1414         WARN("Invalid handle (%#x) passed.\n", Token);
1415         return D3DERR_INVALIDCALL;
1416     }
1417
1418     if (IUnknown_Release((IUnknown *)pSB))
1419     {
1420         ERR("Stateblock %p has references left, this shouldn't happen.\n", pSB);
1421     }
1422
1423     return D3D_OK;
1424 }
1425
1426 static HRESULT WINAPI IDirect3DDevice8Impl_CreateStateBlock(IDirect3DDevice8 *iface,
1427         D3DSTATEBLOCKTYPE Type, DWORD *handle)
1428 {
1429     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1430     IDirect3DStateBlock8Impl *object;
1431     HRESULT hr;
1432
1433     TRACE("(%p) Relay\n", This);
1434
1435     if (Type != D3DSBT_ALL
1436             && Type != D3DSBT_PIXELSTATE
1437             && Type != D3DSBT_VERTEXSTATE)
1438     {
1439         WARN("Unexpected stateblock type, returning D3DERR_INVALIDCALL\n");
1440         return D3DERR_INVALIDCALL;
1441     }
1442
1443     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DStateBlock8Impl));
1444     if (!object)
1445     {
1446         ERR("Failed to allocate memory.\n");
1447         return E_OUTOFMEMORY;
1448     }
1449
1450     object->lpVtbl = &Direct3DStateBlock8_Vtbl;
1451     object->ref = 1;
1452
1453     wined3d_mutex_lock();
1454     hr = IWineD3DDevice_CreateStateBlock(This->WineD3DDevice, (WINED3DSTATEBLOCKTYPE)Type,
1455             &object->wineD3DStateBlock, (IUnknown *)object);
1456     if (FAILED(hr))
1457     {
1458         wined3d_mutex_unlock();
1459         ERR("IWineD3DDevice_CreateStateBlock failed, hr %#x\n", hr);
1460         HeapFree(GetProcessHeap(), 0, object);
1461         return hr;
1462     }
1463
1464     *handle = d3d8_allocate_handle(&This->handle_table, object, D3D8_HANDLE_SB);
1465     wined3d_mutex_unlock();
1466
1467     if (*handle == D3D8_INVALID_HANDLE)
1468     {
1469         ERR("Failed to allocate a handle.\n");
1470         IDirect3DStateBlock8_Release((IDirect3DStateBlock8 *)object);
1471         return E_FAIL;
1472     }
1473     ++*handle;
1474
1475     TRACE("Returning %#x (%p).\n", *handle, object);
1476
1477     return hr;
1478 }
1479
1480 static HRESULT WINAPI IDirect3DDevice8Impl_SetClipStatus(LPDIRECT3DDEVICE8 iface, CONST D3DCLIPSTATUS8* pClipStatus) {
1481     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1482     HRESULT hr;
1483     TRACE("(%p) Relay\n" , This);
1484 /* FIXME: Verify that D3DCLIPSTATUS8 ~= WINED3DCLIPSTATUS */
1485
1486     wined3d_mutex_lock();
1487     hr = IWineD3DDevice_SetClipStatus(This->WineD3DDevice, (const WINED3DCLIPSTATUS *)pClipStatus);
1488     wined3d_mutex_unlock();
1489
1490     return hr;
1491 }
1492
1493 static HRESULT WINAPI IDirect3DDevice8Impl_GetClipStatus(LPDIRECT3DDEVICE8 iface, D3DCLIPSTATUS8* pClipStatus) {
1494     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1495     HRESULT hr;
1496     TRACE("(%p) Relay\n" , This);
1497
1498     wined3d_mutex_lock();
1499     hr = IWineD3DDevice_GetClipStatus(This->WineD3DDevice, (WINED3DCLIPSTATUS *)pClipStatus);
1500     wined3d_mutex_unlock();
1501
1502     return hr;
1503 }
1504
1505 static HRESULT WINAPI IDirect3DDevice8Impl_GetTexture(LPDIRECT3DDEVICE8 iface, DWORD Stage,IDirect3DBaseTexture8** ppTexture) {
1506     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1507     IWineD3DBaseTexture *retTexture = NULL;
1508     HRESULT rc = D3D_OK;
1509
1510     TRACE("(%p) Relay\n" , This);
1511
1512     if(ppTexture == NULL){
1513         return D3DERR_INVALIDCALL;
1514     }
1515
1516     wined3d_mutex_lock();
1517     rc = IWineD3DDevice_GetTexture(This->WineD3DDevice, Stage, &retTexture);
1518     if (rc == D3D_OK && NULL != retTexture) {
1519         IWineD3DBaseTexture_GetParent(retTexture, (IUnknown **)ppTexture);
1520         IWineD3DBaseTexture_Release(retTexture);
1521     } else {
1522         FIXME("Call to get texture  (%d) failed (%p)\n", Stage, retTexture);
1523         *ppTexture = NULL;
1524     }
1525     wined3d_mutex_unlock();
1526
1527     return rc;
1528 }
1529
1530 static HRESULT WINAPI IDirect3DDevice8Impl_SetTexture(LPDIRECT3DDEVICE8 iface, DWORD Stage, IDirect3DBaseTexture8* pTexture) {
1531     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1532     HRESULT hr;
1533     TRACE("(%p) Relay %d %p\n" , This, Stage, pTexture);
1534
1535     wined3d_mutex_lock();
1536     hr = IWineD3DDevice_SetTexture(This->WineD3DDevice, Stage,
1537                                    pTexture==NULL ? NULL : ((IDirect3DBaseTexture8Impl *)pTexture)->wineD3DBaseTexture);
1538     wined3d_mutex_unlock();
1539
1540     return hr;
1541 }
1542
1543 static const struct tss_lookup
1544 {
1545     BOOL sampler_state;
1546     DWORD state;
1547 }
1548 tss_lookup[] =
1549 {
1550     {FALSE, WINED3DTSS_FORCE_DWORD},            /*  0, unused */
1551     {FALSE, WINED3DTSS_COLOROP},                /*  1, D3DTSS_COLOROP */
1552     {FALSE, WINED3DTSS_COLORARG1},              /*  2, D3DTSS_COLORARG1 */
1553     {FALSE, WINED3DTSS_COLORARG2},              /*  3, D3DTSS_COLORARG2 */
1554     {FALSE, WINED3DTSS_ALPHAOP},                /*  4, D3DTSS_ALPHAOP */
1555     {FALSE, WINED3DTSS_ALPHAARG1},              /*  5, D3DTSS_ALPHAARG1 */
1556     {FALSE, WINED3DTSS_ALPHAARG2},              /*  6, D3DTSS_ALPHAARG2 */
1557     {FALSE, WINED3DTSS_BUMPENVMAT00},           /*  7, D3DTSS_BUMPENVMAT00 */
1558     {FALSE, WINED3DTSS_BUMPENVMAT01},           /*  8, D3DTSS_BUMPENVMAT01 */
1559     {FALSE, WINED3DTSS_BUMPENVMAT10},           /*  9, D3DTSS_BUMPENVMAT10 */
1560     {FALSE, WINED3DTSS_BUMPENVMAT11},           /* 10, D3DTSS_BUMPENVMAT11 */
1561     {FALSE, WINED3DTSS_TEXCOORDINDEX},          /* 11, D3DTSS_TEXCOORDINDEX */
1562     {FALSE, WINED3DTSS_FORCE_DWORD},            /* 12, unused */
1563     {TRUE,  WINED3DSAMP_ADDRESSU},              /* 13, D3DTSS_ADDRESSU */
1564     {TRUE,  WINED3DSAMP_ADDRESSV},              /* 14, D3DTSS_ADDRESSV */
1565     {TRUE,  WINED3DSAMP_BORDERCOLOR},           /* 15, D3DTSS_BORDERCOLOR */
1566     {TRUE,  WINED3DSAMP_MAGFILTER},             /* 16, D3DTSS_MAGFILTER */
1567     {TRUE,  WINED3DSAMP_MINFILTER},             /* 17, D3DTSS_MINFILTER */
1568     {TRUE,  WINED3DSAMP_MIPFILTER},             /* 18, D3DTSS_MIPFILTER */
1569     {TRUE,  WINED3DSAMP_MIPMAPLODBIAS},         /* 19, D3DTSS_MIPMAPLODBIAS */
1570     {TRUE,  WINED3DSAMP_MAXMIPLEVEL},           /* 20, D3DTSS_MAXMIPLEVEL */
1571     {TRUE,  WINED3DSAMP_MAXANISOTROPY},         /* 21, D3DTSS_MAXANISOTROPY */
1572     {FALSE, WINED3DTSS_BUMPENVLSCALE},          /* 22, D3DTSS_BUMPENVLSCALE */
1573     {FALSE, WINED3DTSS_BUMPENVLOFFSET},         /* 23, D3DTSS_BUMPENVLOFFSET */
1574     {FALSE, WINED3DTSS_TEXTURETRANSFORMFLAGS},  /* 24, D3DTSS_TEXTURETRANSFORMFLAGS */
1575     {TRUE,  WINED3DSAMP_ADDRESSW},              /* 25, D3DTSS_ADDRESSW */
1576     {FALSE, WINED3DTSS_COLORARG0},              /* 26, D3DTSS_COLORARG0 */
1577     {FALSE, WINED3DTSS_ALPHAARG0},              /* 27, D3DTSS_ALPHAARG0 */
1578     {FALSE, WINED3DTSS_RESULTARG},              /* 28, D3DTSS_RESULTARG */
1579 };
1580
1581 static HRESULT  WINAPI  IDirect3DDevice8Impl_GetTextureStageState(LPDIRECT3DDEVICE8 iface, DWORD Stage,D3DTEXTURESTAGESTATETYPE Type,DWORD* pValue) {
1582     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1583     const struct tss_lookup *l = &tss_lookup[Type];
1584     HRESULT hr;
1585     TRACE("(%p) Relay\n" , This);
1586
1587     wined3d_mutex_lock();
1588     if (l->sampler_state) hr = IWineD3DDevice_GetSamplerState(This->WineD3DDevice, Stage, l->state, pValue);
1589     else hr = IWineD3DDevice_GetTextureStageState(This->WineD3DDevice, Stage, l->state, pValue);
1590     wined3d_mutex_unlock();
1591
1592     return hr;
1593 }
1594
1595 static HRESULT WINAPI IDirect3DDevice8Impl_SetTextureStageState(LPDIRECT3DDEVICE8 iface, DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD Value) {
1596     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1597     const struct tss_lookup *l = &tss_lookup[Type];
1598     HRESULT hr;
1599     TRACE("(%p) Relay\n" , This);
1600
1601     wined3d_mutex_lock();
1602     if (l->sampler_state) hr = IWineD3DDevice_SetSamplerState(This->WineD3DDevice, Stage, l->state, Value);
1603     else hr = IWineD3DDevice_SetTextureStageState(This->WineD3DDevice, Stage, l->state, Value);
1604     wined3d_mutex_unlock();
1605
1606     return hr;
1607 }
1608
1609 static HRESULT WINAPI IDirect3DDevice8Impl_ValidateDevice(LPDIRECT3DDEVICE8 iface, DWORD* pNumPasses) {
1610     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1611     HRESULT hr;
1612     TRACE("(%p) Relay\n" , This);
1613
1614     wined3d_mutex_lock();
1615     hr = IWineD3DDevice_ValidateDevice(This->WineD3DDevice, pNumPasses);
1616     wined3d_mutex_unlock();
1617
1618     return hr;
1619 }
1620
1621 static HRESULT WINAPI IDirect3DDevice8Impl_GetInfo(LPDIRECT3DDEVICE8 iface, DWORD DevInfoID, void* pDevInfoStruct, DWORD DevInfoStructSize) {
1622     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1623     FIXME("(%p) : stub\n", This);
1624     return D3D_OK;
1625 }
1626
1627 static HRESULT WINAPI IDirect3DDevice8Impl_SetPaletteEntries(LPDIRECT3DDEVICE8 iface, UINT PaletteNumber, CONST PALETTEENTRY* pEntries) {
1628     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1629     HRESULT hr;
1630     TRACE("(%p) Relay\n" , This);
1631
1632     wined3d_mutex_lock();
1633     hr = IWineD3DDevice_SetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
1634     wined3d_mutex_unlock();
1635
1636     return hr;
1637 }
1638
1639 static HRESULT WINAPI IDirect3DDevice8Impl_GetPaletteEntries(LPDIRECT3DDEVICE8 iface, UINT PaletteNumber, PALETTEENTRY* pEntries) {
1640     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1641     HRESULT hr;
1642     TRACE("(%p) Relay\n" , This);
1643
1644     wined3d_mutex_lock();
1645     hr = IWineD3DDevice_GetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
1646     wined3d_mutex_unlock();
1647
1648     return hr;
1649 }
1650
1651 static HRESULT WINAPI IDirect3DDevice8Impl_SetCurrentTexturePalette(LPDIRECT3DDEVICE8 iface, UINT PaletteNumber) {
1652     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1653     HRESULT hr;
1654     TRACE("(%p) Relay\n" , This);
1655
1656     wined3d_mutex_lock();
1657     hr = IWineD3DDevice_SetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
1658     wined3d_mutex_unlock();
1659
1660     return hr;
1661 }
1662
1663 static HRESULT  WINAPI  IDirect3DDevice8Impl_GetCurrentTexturePalette(LPDIRECT3DDEVICE8 iface, UINT *PaletteNumber) {
1664     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1665     HRESULT hr;
1666     TRACE("(%p) Relay\n" , This);
1667
1668     wined3d_mutex_lock();
1669     hr = IWineD3DDevice_GetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
1670     wined3d_mutex_unlock();
1671
1672     return hr;
1673 }
1674
1675 static HRESULT WINAPI IDirect3DDevice8Impl_DrawPrimitive(IDirect3DDevice8 *iface, D3DPRIMITIVETYPE PrimitiveType,
1676         UINT StartVertex, UINT PrimitiveCount)
1677 {
1678     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1679     HRESULT hr;
1680     TRACE("(%p) Relay\n" , This);
1681
1682     wined3d_mutex_lock();
1683     IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1684     hr = IWineD3DDevice_DrawPrimitive(This->WineD3DDevice, StartVertex,
1685             vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount));
1686     wined3d_mutex_unlock();
1687
1688     return hr;
1689 }
1690
1691 static HRESULT WINAPI IDirect3DDevice8Impl_DrawIndexedPrimitive(LPDIRECT3DDEVICE8 iface, D3DPRIMITIVETYPE PrimitiveType,
1692                                                            UINT MinVertexIndex,UINT NumVertices,UINT startIndex,UINT primCount) {
1693     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1694     HRESULT hr;
1695     TRACE("(%p) Relay\n" , This);
1696
1697     wined3d_mutex_lock();
1698     IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1699     hr = IWineD3DDevice_DrawIndexedPrimitive(This->WineD3DDevice, startIndex,
1700             vertex_count_from_primitive_count(PrimitiveType, primCount));
1701     wined3d_mutex_unlock();
1702
1703     return hr;
1704 }
1705
1706 static HRESULT WINAPI IDirect3DDevice8Impl_DrawPrimitiveUP(LPDIRECT3DDEVICE8 iface, D3DPRIMITIVETYPE PrimitiveType,UINT PrimitiveCount,CONST void* pVertexStreamZeroData,UINT VertexStreamZeroStride) {
1707     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1708     HRESULT hr;
1709     TRACE("(%p) Relay\n" , This);
1710
1711     wined3d_mutex_lock();
1712     IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1713     hr = IWineD3DDevice_DrawPrimitiveUP(This->WineD3DDevice,
1714             vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount),
1715             pVertexStreamZeroData, VertexStreamZeroStride);
1716     wined3d_mutex_unlock();
1717
1718     return hr;
1719 }
1720
1721 static HRESULT WINAPI IDirect3DDevice8Impl_DrawIndexedPrimitiveUP(LPDIRECT3DDEVICE8 iface, D3DPRIMITIVETYPE PrimitiveType,UINT MinVertexIndex,
1722                                                              UINT NumVertexIndices,UINT PrimitiveCount,CONST void* pIndexData,
1723                                                              D3DFORMAT IndexDataFormat,CONST void* pVertexStreamZeroData,
1724                                                              UINT VertexStreamZeroStride) {
1725     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1726     HRESULT hr;
1727     TRACE("(%p) Relay\n" , This);
1728
1729     wined3d_mutex_lock();
1730     IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1731     hr = IWineD3DDevice_DrawIndexedPrimitiveUP(This->WineD3DDevice,
1732             vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount), pIndexData,
1733             wined3dformat_from_d3dformat(IndexDataFormat), pVertexStreamZeroData, VertexStreamZeroStride);
1734     wined3d_mutex_unlock();
1735
1736     return hr;
1737 }
1738
1739 static HRESULT WINAPI IDirect3DDevice8Impl_ProcessVertices(LPDIRECT3DDEVICE8 iface, UINT SrcStartIndex,UINT DestIndex,UINT VertexCount,IDirect3DVertexBuffer8* pDestBuffer,DWORD Flags) {
1740     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1741     HRESULT hr;
1742     IDirect3DVertexBuffer8Impl *dest = (IDirect3DVertexBuffer8Impl *) pDestBuffer;
1743     TRACE("(%p) Relay\n" , This);
1744
1745     wined3d_mutex_lock();
1746     hr = IWineD3DDevice_ProcessVertices(This->WineD3DDevice,SrcStartIndex, DestIndex, VertexCount, dest->wineD3DVertexBuffer, NULL, Flags, dest->fvf);
1747     wined3d_mutex_unlock();
1748
1749     return hr;
1750 }
1751
1752 static HRESULT IDirect3DDevice8Impl_CreateVertexDeclaration(IDirect3DDevice8 *iface, CONST DWORD *declaration, IDirect3DVertexDeclaration8 **decl_ptr) {
1753     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1754     IDirect3DVertexDeclaration8Impl *object;
1755     WINED3DVERTEXELEMENT *wined3d_elements;
1756     UINT wined3d_element_count;
1757     HRESULT hr = D3D_OK;
1758
1759     TRACE("(%p) : declaration %p\n", This, declaration);
1760
1761     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1762     if (!object) {
1763         ERR("Memory allocation failed\n");
1764         *decl_ptr = NULL;
1765         return D3DERR_OUTOFVIDEOMEMORY;
1766     }
1767
1768     object->ref_count = 1;
1769     object->lpVtbl = &Direct3DVertexDeclaration8_Vtbl;
1770
1771     wined3d_element_count = convert_to_wined3d_declaration(declaration, &object->elements_size, &wined3d_elements);
1772     object->elements = HeapAlloc(GetProcessHeap(), 0, object->elements_size);
1773     if (!object->elements) {
1774         ERR("Memory allocation failed\n");
1775         HeapFree(GetProcessHeap(), 0, wined3d_elements);
1776         HeapFree(GetProcessHeap(), 0, object);
1777         *decl_ptr = NULL;
1778         return D3DERR_OUTOFVIDEOMEMORY;
1779     }
1780
1781     CopyMemory(object->elements, declaration, object->elements_size);
1782
1783     wined3d_mutex_lock();
1784     hr = IWineD3DDevice_CreateVertexDeclaration(This->WineD3DDevice, &object->wined3d_vertex_declaration,
1785             (IUnknown *)object, wined3d_elements, wined3d_element_count);
1786     wined3d_mutex_unlock();
1787
1788     HeapFree(GetProcessHeap(), 0, wined3d_elements);
1789
1790     if (FAILED(hr)) {
1791         ERR("(%p) : IWineD3DDevice_CreateVertexDeclaration call failed\n", This);
1792         HeapFree(GetProcessHeap(), 0, object->elements);
1793         HeapFree(GetProcessHeap(), 0, object);
1794     } else {
1795         *decl_ptr = (IDirect3DVertexDeclaration8 *)object;
1796         TRACE("(%p) : Created vertex declaration %p\n", This, object);
1797     }
1798
1799     return hr;
1800 }
1801
1802 static HRESULT WINAPI IDirect3DDevice8Impl_CreateVertexShader(LPDIRECT3DDEVICE8 iface, CONST DWORD* pDeclaration, CONST DWORD* pFunction, DWORD* ppShader, DWORD Usage) {
1803     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1804     HRESULT hrc = D3D_OK;
1805     IDirect3DVertexShader8Impl *object;
1806     const DWORD *token = pDeclaration;
1807     DWORD handle;
1808
1809     /* Test if the vertex declaration is valid */
1810     while (D3DVSD_END() != *token) {
1811         D3DVSD_TOKENTYPE token_type = ((*token & D3DVSD_TOKENTYPEMASK) >> D3DVSD_TOKENTYPESHIFT);
1812
1813         if (token_type == D3DVSD_TOKEN_STREAMDATA && !(token_type & 0x10000000)) {
1814             DWORD type = ((*token & D3DVSD_DATATYPEMASK) >> D3DVSD_DATATYPESHIFT);
1815             DWORD reg  = ((*token & D3DVSD_VERTEXREGMASK) >> D3DVSD_VERTEXREGSHIFT);
1816
1817             if(reg == D3DVSDE_NORMAL && type != D3DVSDT_FLOAT3 && !pFunction) {
1818                 WARN("Attempt to use a non-FLOAT3 normal with the fixed function function\n");
1819                 return D3DERR_INVALIDCALL;
1820             }
1821         }
1822         token += parse_token(token);
1823     }
1824
1825     /* Setup a stub object for now */
1826     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1827     TRACE("(%p) : pFunction(%p), ppShader(%p)\n", This, pFunction, ppShader);
1828     if (NULL == object) {
1829         FIXME("Allocation of memory failed\n");
1830         *ppShader = 0;
1831         return D3DERR_OUTOFVIDEOMEMORY;
1832     }
1833
1834     object->ref = 1;
1835     object->lpVtbl = &Direct3DVertexShader8_Vtbl;
1836
1837     hrc = IDirect3DDevice8Impl_CreateVertexDeclaration(iface, pDeclaration, &object->vertex_declaration);
1838     if (FAILED(hrc)) {
1839         ERR("(%p) : IDirect3DDeviceImpl_CreateVertexDeclaration call failed\n", This);
1840         HeapFree(GetProcessHeap(), 0, object);
1841         *ppShader = 0;
1842         return D3DERR_INVALIDCALL;
1843     }
1844
1845     wined3d_mutex_lock();
1846     handle = d3d8_allocate_handle(&This->handle_table, object, D3D8_HANDLE_VS);
1847     if (handle == D3D8_INVALID_HANDLE)
1848     {
1849         ERR("Failed to allocate shader handle\n");
1850         wined3d_mutex_unlock();
1851         IDirect3DVertexDeclaration8_Release(object->vertex_declaration);
1852         HeapFree(GetProcessHeap(), 0, object);
1853         *ppShader = 0;
1854         return E_OUTOFMEMORY;
1855     }
1856     else
1857     {
1858         DWORD shader_handle = handle + VS_HIGHESTFIXEDFXF + 1;
1859         *ppShader = ((IDirect3DVertexDeclaration8Impl *)object->vertex_declaration)->shader_handle = shader_handle;
1860     }
1861
1862     if (pFunction)
1863     {
1864         /* Usage is missing ... Use SetRenderState to set the sw vp render state in SetVertexShader */
1865         hrc = IWineD3DDevice_CreateVertexShader(This->WineD3DDevice, pFunction,
1866                 NULL /* output signature */, &object->wineD3DVertexShader, (IUnknown *)object);
1867
1868         if (FAILED(hrc))
1869         {
1870             /* free up object */
1871             FIXME("Call to IWineD3DDevice_CreateVertexShader failed\n");
1872             d3d8_free_handle(&This->handle_table, handle, D3D8_HANDLE_VS);
1873             IDirect3DVertexDeclaration8_Release(object->vertex_declaration);
1874             HeapFree(GetProcessHeap(), 0, object);
1875             *ppShader = 0;
1876         }
1877         else
1878         {
1879             load_local_constants(pDeclaration, object->wineD3DVertexShader);
1880             TRACE("(%p) : returning %p (handle %#x)\n", This, object, *ppShader);
1881         }
1882     }
1883
1884     wined3d_mutex_unlock();
1885
1886     return hrc;
1887 }
1888
1889 static IDirect3DVertexDeclaration8Impl *IDirect3DDevice8Impl_FindDecl(IDirect3DDevice8Impl *This, DWORD fvf)
1890 {
1891     IDirect3DVertexDeclaration8Impl *d3d8_declaration;
1892     HRESULT hr;
1893     int p, low, high; /* deliberately signed */
1894     struct FvfToDecl *convertedDecls = This->decls;
1895
1896     TRACE("Searching for declaration for fvf %08x... ", fvf);
1897
1898     low = 0;
1899     high = This->numConvertedDecls - 1;
1900     while(low <= high) {
1901         p = (low + high) >> 1;
1902         TRACE("%d ", p);
1903         if(convertedDecls[p].fvf == fvf) {
1904             TRACE("found %p\n", convertedDecls[p].decl);
1905             return (IDirect3DVertexDeclaration8Impl *)convertedDecls[p].decl;
1906         } else if(convertedDecls[p].fvf < fvf) {
1907             low = p + 1;
1908         } else {
1909             high = p - 1;
1910         }
1911     }
1912     TRACE("not found. Creating and inserting at position %d.\n", low);
1913
1914     d3d8_declaration = HeapAlloc(GetProcessHeap(), 0, sizeof(*d3d8_declaration));
1915     if (!d3d8_declaration)
1916     {
1917         ERR("Memory allocation failed.\n");
1918         return NULL;
1919     }
1920
1921     d3d8_declaration->ref_count = 1;
1922     d3d8_declaration->lpVtbl = &Direct3DVertexDeclaration8_Vtbl;
1923     d3d8_declaration->elements = NULL;
1924     d3d8_declaration->elements_size = 0;
1925     d3d8_declaration->shader_handle = fvf;
1926
1927     hr = IWineD3DDevice_CreateVertexDeclarationFromFVF(This->WineD3DDevice,
1928             &d3d8_declaration->wined3d_vertex_declaration, (IUnknown *)d3d8_declaration, fvf);
1929     if (FAILED(hr))
1930     {
1931         ERR("Failed to create wined3d vertex declaration.\n");
1932         HeapFree(GetProcessHeap(), 0, d3d8_declaration);
1933         return NULL;
1934     }
1935
1936     if(This->declArraySize == This->numConvertedDecls) {
1937         int grow = This->declArraySize / 2;
1938         convertedDecls = HeapReAlloc(GetProcessHeap(), 0, convertedDecls,
1939                                      sizeof(convertedDecls[0]) * (This->numConvertedDecls + grow));
1940         if(!convertedDecls) {
1941             /* This will destroy it */
1942             IDirect3DVertexDeclaration8_Release((IDirect3DVertexDeclaration8 *)d3d8_declaration);
1943             return NULL;
1944         }
1945         This->decls = convertedDecls;
1946         This->declArraySize += grow;
1947     }
1948
1949     memmove(convertedDecls + low + 1, convertedDecls + low, sizeof(convertedDecls[0]) * (This->numConvertedDecls - low));
1950     convertedDecls[low].decl = (IDirect3DVertexDeclaration8 *)d3d8_declaration;
1951     convertedDecls[low].fvf = fvf;
1952     This->numConvertedDecls++;
1953
1954     TRACE("Returning %p. %u decls in array\n", d3d8_declaration, This->numConvertedDecls);
1955     return d3d8_declaration;
1956 }
1957
1958 static HRESULT WINAPI IDirect3DDevice8Impl_SetVertexShader(LPDIRECT3DDEVICE8 iface, DWORD pShader) {
1959     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1960     IDirect3DVertexShader8Impl *shader;
1961     HRESULT hr;
1962
1963     TRACE("(%p) : Relay\n", This);
1964
1965     if (VS_HIGHESTFIXEDFXF >= pShader) {
1966         TRACE("Setting FVF, %#x\n", pShader);
1967
1968         wined3d_mutex_lock();
1969         IWineD3DDevice_SetVertexDeclaration(This->WineD3DDevice,
1970                 IDirect3DDevice8Impl_FindDecl(This, pShader)->wined3d_vertex_declaration);
1971         IWineD3DDevice_SetVertexShader(This->WineD3DDevice, NULL);
1972         wined3d_mutex_unlock();
1973
1974         return D3D_OK;
1975     }
1976
1977     TRACE("Setting shader\n");
1978
1979     wined3d_mutex_lock();
1980     shader = d3d8_get_object(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS);
1981     if (!shader)
1982     {
1983         WARN("Invalid handle (%#x) passed.\n", pShader);
1984         wined3d_mutex_unlock();
1985
1986         return D3DERR_INVALIDCALL;
1987     }
1988
1989     hr = IWineD3DDevice_SetVertexDeclaration(This->WineD3DDevice,
1990             ((IDirect3DVertexDeclaration8Impl *)shader->vertex_declaration)->wined3d_vertex_declaration);
1991     if (SUCCEEDED(hr)) hr = IWineD3DDevice_SetVertexShader(This->WineD3DDevice, shader->wineD3DVertexShader);
1992     wined3d_mutex_unlock();
1993
1994     TRACE("Returning hr %#x\n", hr);
1995
1996     return hr;
1997 }
1998
1999 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShader(LPDIRECT3DDEVICE8 iface, DWORD* ppShader) {
2000     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2001     IWineD3DVertexDeclaration *wined3d_declaration;
2002     IDirect3DVertexDeclaration8 *d3d8_declaration;
2003     HRESULT hrc;
2004
2005     TRACE("(%p) : Relay  device@%p\n", This, This->WineD3DDevice);
2006
2007     wined3d_mutex_lock();
2008     hrc = IWineD3DDevice_GetVertexDeclaration(This->WineD3DDevice, &wined3d_declaration);
2009     if (FAILED(hrc))
2010     {
2011         wined3d_mutex_unlock();
2012         WARN("(%p) : Call to IWineD3DDevice_GetVertexDeclaration failed %#x (device %p)\n",
2013                 This, hrc, This->WineD3DDevice);
2014         return hrc;
2015     }
2016
2017     if (!wined3d_declaration)
2018     {
2019         wined3d_mutex_unlock();
2020         *ppShader = 0;
2021         return D3D_OK;
2022     }
2023
2024     hrc = IWineD3DVertexDeclaration_GetParent(wined3d_declaration, (IUnknown **)&d3d8_declaration);
2025     IWineD3DVertexDeclaration_Release(wined3d_declaration);
2026     wined3d_mutex_unlock();
2027     if (SUCCEEDED(hrc))
2028     {
2029         *ppShader = ((IDirect3DVertexDeclaration8Impl *)d3d8_declaration)->shader_handle;
2030         IDirect3DVertexDeclaration8_Release(d3d8_declaration);
2031     }
2032
2033     TRACE("(%p) : returning %#x\n", This, *ppShader);
2034
2035     return hrc;
2036 }
2037
2038 static HRESULT  WINAPI  IDirect3DDevice8Impl_DeleteVertexShader(LPDIRECT3DDEVICE8 iface, DWORD pShader) {
2039     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2040     IDirect3DVertexShader8Impl *shader;
2041     IWineD3DVertexShader *cur = NULL;
2042
2043     TRACE("(%p) : pShader %#x\n", This, pShader);
2044
2045     wined3d_mutex_lock();
2046     shader = d3d8_free_handle(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS);
2047     if (!shader)
2048     {
2049         WARN("Invalid handle (%#x) passed.\n", pShader);
2050         wined3d_mutex_unlock();
2051
2052         return D3DERR_INVALIDCALL;
2053     }
2054
2055     IWineD3DDevice_GetVertexShader(This->WineD3DDevice, &cur);
2056
2057     if (cur)
2058     {
2059         if (cur == shader->wineD3DVertexShader) IDirect3DDevice8_SetVertexShader(iface, 0);
2060         IWineD3DVertexShader_Release(cur);
2061     }
2062
2063     wined3d_mutex_unlock();
2064
2065     if (IUnknown_Release((IUnknown *)shader))
2066     {
2067         ERR("Shader %p has references left, this shouldn't happen.\n", shader);
2068     }
2069
2070     return D3D_OK;
2071 }
2072
2073 static HRESULT WINAPI IDirect3DDevice8Impl_SetVertexShaderConstant(LPDIRECT3DDEVICE8 iface, DWORD Register, CONST void* pConstantData, DWORD ConstantCount) {
2074     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2075     HRESULT hr;
2076     TRACE("(%p) : Relay\n", This);
2077
2078     if(Register + ConstantCount > D3D8_MAX_VERTEX_SHADER_CONSTANTF) {
2079         WARN("Trying to access %u constants, but d3d8 only supports %u\n",
2080              Register + ConstantCount, D3D8_MAX_VERTEX_SHADER_CONSTANTF);
2081         return D3DERR_INVALIDCALL;
2082     }
2083
2084     wined3d_mutex_lock();
2085     hr = IWineD3DDevice_SetVertexShaderConstantF(This->WineD3DDevice, Register, pConstantData, ConstantCount);
2086     wined3d_mutex_unlock();
2087
2088     return hr;
2089 }
2090
2091 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShaderConstant(LPDIRECT3DDEVICE8 iface, DWORD Register, void* pConstantData, DWORD ConstantCount) {
2092     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2093     HRESULT hr;
2094     TRACE("(%p) : Relay\n", This);
2095
2096     if(Register + ConstantCount > D3D8_MAX_VERTEX_SHADER_CONSTANTF) {
2097         WARN("Trying to access %u constants, but d3d8 only supports %u\n",
2098              Register + ConstantCount, D3D8_MAX_VERTEX_SHADER_CONSTANTF);
2099         return D3DERR_INVALIDCALL;
2100     }
2101
2102     wined3d_mutex_lock();
2103     hr = IWineD3DDevice_GetVertexShaderConstantF(This->WineD3DDevice, Register, pConstantData, ConstantCount);
2104     wined3d_mutex_unlock();
2105
2106     return hr;
2107 }
2108
2109 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShaderDeclaration(LPDIRECT3DDEVICE8 iface, DWORD pVertexShader, void* pData, DWORD* pSizeOfData) {
2110     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2111     IDirect3DVertexDeclaration8Impl *declaration;
2112     IDirect3DVertexShader8Impl *shader;
2113
2114     TRACE("(%p) : pVertexShader 0x%08x, pData %p, *pSizeOfData %u\n", This, pVertexShader, pData, *pSizeOfData);
2115
2116     wined3d_mutex_lock();
2117     shader = d3d8_get_object(&This->handle_table, pVertexShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS);
2118     wined3d_mutex_unlock();
2119
2120     if (!shader)
2121     {
2122         WARN("Invalid handle (%#x) passed.\n", pVertexShader);
2123         return D3DERR_INVALIDCALL;
2124     }
2125     declaration = (IDirect3DVertexDeclaration8Impl *)shader->vertex_declaration;
2126
2127     /* If pData is NULL, we just return the required size of the buffer. */
2128     if (!pData) {
2129         *pSizeOfData = declaration->elements_size;
2130         return D3D_OK;
2131     }
2132
2133     /* MSDN claims that if *pSizeOfData is smaller than the required size
2134      * we should write the required size and return D3DERR_MOREDATA.
2135      * That's not actually true. */
2136     if (*pSizeOfData < declaration->elements_size) {
2137         return D3DERR_INVALIDCALL;
2138     }
2139
2140     CopyMemory(pData, declaration->elements, declaration->elements_size);
2141
2142     return D3D_OK;
2143 }
2144
2145 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShaderFunction(LPDIRECT3DDEVICE8 iface, DWORD pVertexShader, void* pData, DWORD* pSizeOfData) {
2146     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2147     IDirect3DVertexShader8Impl *shader = NULL;
2148     HRESULT hr;
2149
2150     TRACE("(%p) : pVertexShader %#x, pData %p, pSizeOfData %p\n", This, pVertexShader, pData, pSizeOfData);
2151
2152     wined3d_mutex_lock();
2153     shader = d3d8_get_object(&This->handle_table, pVertexShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS);
2154     if (!shader)
2155     {
2156         WARN("Invalid handle (%#x) passed.\n", pVertexShader);
2157         wined3d_mutex_unlock();
2158
2159         return D3DERR_INVALIDCALL;
2160     }
2161
2162     if (!shader->wineD3DVertexShader)
2163     {
2164         wined3d_mutex_unlock();
2165         *pSizeOfData = 0;
2166         return D3D_OK;
2167     }
2168
2169     hr = IWineD3DVertexShader_GetFunction(shader->wineD3DVertexShader, pData, pSizeOfData);
2170     wined3d_mutex_unlock();
2171
2172     return hr;
2173 }
2174
2175 static HRESULT WINAPI IDirect3DDevice8Impl_SetIndices(LPDIRECT3DDEVICE8 iface, IDirect3DIndexBuffer8* pIndexData, UINT baseVertexIndex) {
2176     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2177     HRESULT hr;
2178     IDirect3DIndexBuffer8Impl *ib = (IDirect3DIndexBuffer8Impl *)pIndexData;
2179     TRACE("(%p) Relay\n", This);
2180
2181     /* WineD3D takes an INT(due to d3d9), but d3d8 uses UINTs. Do I have to add a check here that
2182      * the UINT doesn't cause an overflow in the INT? It seems rather unlikely because such large
2183      * vertex buffers can't be created to address them with an index that requires the 32nd bit
2184      * (4 Byte minimum vertex size * 2^31-1 -> 8 gb buffer. The index sign would be the least
2185      * problem)
2186      */
2187     wined3d_mutex_lock();
2188     IWineD3DDevice_SetBaseVertexIndex(This->WineD3DDevice, baseVertexIndex);
2189     hr = IWineD3DDevice_SetIndices(This->WineD3DDevice,
2190             ib ? ib->wineD3DIndexBuffer : NULL,
2191             ib ? ib->format : WINED3DFMT_UNKNOWN);
2192     wined3d_mutex_unlock();
2193
2194     return hr;
2195 }
2196
2197 static HRESULT WINAPI IDirect3DDevice8Impl_GetIndices(LPDIRECT3DDEVICE8 iface, IDirect3DIndexBuffer8** ppIndexData,UINT* pBaseVertexIndex) {
2198     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2199     IWineD3DBuffer *retIndexData = NULL;
2200     HRESULT rc = D3D_OK;
2201
2202     TRACE("(%p) Relay\n", This);
2203
2204     if(ppIndexData == NULL){
2205         return D3DERR_INVALIDCALL;
2206     }
2207
2208     /* The case from UINT to INT is safe because d3d8 will never set negative values */
2209     wined3d_mutex_lock();
2210     IWineD3DDevice_GetBaseVertexIndex(This->WineD3DDevice, (INT *) pBaseVertexIndex);
2211     rc = IWineD3DDevice_GetIndices(This->WineD3DDevice, &retIndexData);
2212     if (SUCCEEDED(rc) && retIndexData) {
2213         IWineD3DBuffer_GetParent(retIndexData, (IUnknown **)ppIndexData);
2214         IWineD3DBuffer_Release(retIndexData);
2215     } else {
2216         if (FAILED(rc)) FIXME("Call to GetIndices failed\n");
2217         *ppIndexData = NULL;
2218     }
2219     wined3d_mutex_unlock();
2220
2221     return rc;
2222 }
2223 static HRESULT WINAPI IDirect3DDevice8Impl_CreatePixelShader(LPDIRECT3DDEVICE8 iface, CONST DWORD* pFunction, DWORD* ppShader) {
2224     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2225     IDirect3DPixelShader8Impl *object;
2226     DWORD handle;
2227     HRESULT hr;
2228
2229     TRACE("(%p) : pFunction(%p), ppShader(%p)\n", This, pFunction, ppShader);
2230
2231     if (NULL == ppShader) {
2232         TRACE("(%p) Invalid call\n", This);
2233         return D3DERR_INVALIDCALL;
2234     }
2235
2236     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2237     if (!object)
2238     {
2239         ERR("Failed to allocate memmory.\n");
2240         return E_OUTOFMEMORY;
2241     }
2242
2243     object->ref    = 1;
2244     object->lpVtbl = &Direct3DPixelShader8_Vtbl;
2245
2246     wined3d_mutex_lock();
2247     hr = IWineD3DDevice_CreatePixelShader(This->WineD3DDevice, pFunction,
2248             NULL, &object->wineD3DPixelShader, (IUnknown *)object);
2249     if (FAILED(hr))
2250     {
2251         wined3d_mutex_unlock();
2252         FIXME("(%p) call to IWineD3DDevice_CreatePixelShader failed\n", This);
2253         HeapFree(GetProcessHeap(), 0 , object);
2254         *ppShader = 0;
2255         return hr;
2256     }
2257
2258     handle = d3d8_allocate_handle(&This->handle_table, object, D3D8_HANDLE_PS);
2259     wined3d_mutex_unlock();
2260
2261     if (handle == D3D8_INVALID_HANDLE)
2262     {
2263         ERR("Failed to allocate shader handle\n");
2264         IDirect3DVertexShader8_Release((IUnknown *)object);
2265         return E_OUTOFMEMORY;
2266     }
2267
2268     *ppShader = object->handle = handle + VS_HIGHESTFIXEDFXF + 1;
2269     TRACE("(%p) : returning %p (handle %#x)\n", This, object, *ppShader);
2270
2271     return hr;
2272 }
2273
2274 static HRESULT WINAPI IDirect3DDevice8Impl_SetPixelShader(LPDIRECT3DDEVICE8 iface, DWORD pShader) {
2275     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2276     IDirect3DPixelShader8Impl *shader;
2277     HRESULT hr;
2278
2279     TRACE("(%p) : pShader %#x\n", This, pShader);
2280
2281     wined3d_mutex_lock();
2282
2283     if (!pShader)
2284     {
2285         hr = IWineD3DDevice_SetPixelShader(This->WineD3DDevice, NULL);
2286         wined3d_mutex_unlock();
2287         return hr;
2288     }
2289
2290     shader = d3d8_get_object(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_PS);
2291     if (!shader)
2292     {
2293         WARN("Invalid handle (%#x) passed.\n", pShader);
2294         wined3d_mutex_unlock();
2295         return D3DERR_INVALIDCALL;
2296     }
2297
2298     TRACE("(%p) : Setting shader %p\n", This, shader);
2299     hr = IWineD3DDevice_SetPixelShader(This->WineD3DDevice, shader->wineD3DPixelShader);
2300     wined3d_mutex_unlock();
2301
2302     return hr;
2303 }
2304
2305 static HRESULT WINAPI IDirect3DDevice8Impl_GetPixelShader(LPDIRECT3DDEVICE8 iface, DWORD* ppShader) {
2306     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2307     IWineD3DPixelShader *object;
2308
2309     HRESULT hrc = D3D_OK;
2310     TRACE("(%p) Relay\n", This);
2311     if (NULL == ppShader) {
2312         TRACE("(%p) Invalid call\n", This);
2313         return D3DERR_INVALIDCALL;
2314     }
2315
2316     wined3d_mutex_lock();
2317     hrc = IWineD3DDevice_GetPixelShader(This->WineD3DDevice, &object);
2318     if (D3D_OK == hrc && NULL != object) {
2319         IDirect3DPixelShader8Impl *d3d8_shader;
2320         hrc = IWineD3DPixelShader_GetParent(object, (IUnknown **)&d3d8_shader);
2321         IWineD3DPixelShader_Release(object);
2322         *ppShader = d3d8_shader->handle;
2323         IDirect3DPixelShader8_Release((IDirect3DPixelShader8 *)d3d8_shader);
2324     } else {
2325         *ppShader = 0;
2326     }
2327     wined3d_mutex_unlock();
2328
2329     TRACE("(%p) : returning %#x\n", This, *ppShader);
2330
2331     return hrc;
2332 }
2333
2334 static HRESULT WINAPI IDirect3DDevice8Impl_DeletePixelShader(LPDIRECT3DDEVICE8 iface, DWORD pShader) {
2335     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2336     IDirect3DPixelShader8Impl *shader;
2337     IWineD3DPixelShader *cur = NULL;
2338
2339     TRACE("(%p) : pShader %#x\n", This, pShader);
2340
2341     wined3d_mutex_lock();
2342
2343     shader = d3d8_free_handle(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_PS);
2344     if (!shader)
2345     {
2346         WARN("Invalid handle (%#x) passed.\n", pShader);
2347         wined3d_mutex_unlock();
2348         return D3D_OK;
2349     }
2350
2351     IWineD3DDevice_GetPixelShader(This->WineD3DDevice, &cur);
2352
2353     if (cur)
2354     {
2355         if (cur == shader->wineD3DPixelShader) IDirect3DDevice8_SetPixelShader(iface, 0);
2356         IWineD3DPixelShader_Release(cur);
2357     }
2358
2359     wined3d_mutex_unlock();
2360
2361     if (IUnknown_Release((IUnknown *)shader))
2362     {
2363         ERR("Shader %p has references left, this shouldn't happen.\n", shader);
2364     }
2365
2366     return D3D_OK;
2367 }
2368
2369 static HRESULT  WINAPI  IDirect3DDevice8Impl_SetPixelShaderConstant(LPDIRECT3DDEVICE8 iface, DWORD Register, CONST void* pConstantData, DWORD ConstantCount) {
2370     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2371     HRESULT hr;
2372     TRACE("(%p) Relay\n", This);
2373
2374     wined3d_mutex_lock();
2375     hr = IWineD3DDevice_SetPixelShaderConstantF(This->WineD3DDevice, Register, pConstantData, ConstantCount);
2376     wined3d_mutex_unlock();
2377
2378     return hr;
2379 }
2380
2381 static HRESULT WINAPI IDirect3DDevice8Impl_GetPixelShaderConstant(LPDIRECT3DDEVICE8 iface, DWORD Register, void* pConstantData, DWORD ConstantCount) {
2382     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2383     HRESULT hr;
2384     TRACE("(%p) Relay\n", This);
2385
2386     wined3d_mutex_lock();
2387     hr = IWineD3DDevice_GetPixelShaderConstantF(This->WineD3DDevice, Register, pConstantData, ConstantCount);
2388     wined3d_mutex_unlock();
2389
2390     return hr;
2391 }
2392
2393 static HRESULT WINAPI IDirect3DDevice8Impl_GetPixelShaderFunction(LPDIRECT3DDEVICE8 iface, DWORD pPixelShader, void* pData, DWORD* pSizeOfData) {
2394     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2395     IDirect3DPixelShader8Impl *shader = NULL;
2396     HRESULT hr;
2397
2398     TRACE("(%p) : pPixelShader %#x, pData %p, pSizeOfData %p\n", This, pPixelShader, pData, pSizeOfData);
2399
2400     wined3d_mutex_lock();
2401     shader = d3d8_get_object(&This->handle_table, pPixelShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_PS);
2402     if (!shader)
2403     {
2404         WARN("Invalid handle (%#x) passed.\n", pPixelShader);
2405         wined3d_mutex_unlock();
2406
2407         return D3DERR_INVALIDCALL;
2408     }
2409
2410     hr = IWineD3DPixelShader_GetFunction(shader->wineD3DPixelShader, pData, pSizeOfData);
2411     wined3d_mutex_unlock();
2412
2413     return hr;
2414 }
2415
2416 static HRESULT WINAPI IDirect3DDevice8Impl_DrawRectPatch(LPDIRECT3DDEVICE8 iface, UINT Handle,CONST float* pNumSegs,CONST D3DRECTPATCH_INFO* pRectPatchInfo) {
2417     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2418     HRESULT hr;
2419     TRACE("(%p) Relay\n", This);
2420
2421     wined3d_mutex_lock();
2422     hr = IWineD3DDevice_DrawRectPatch(This->WineD3DDevice, Handle, pNumSegs, (CONST WINED3DRECTPATCH_INFO *)pRectPatchInfo);
2423     wined3d_mutex_unlock();
2424
2425     return hr;
2426 }
2427
2428 static HRESULT WINAPI IDirect3DDevice8Impl_DrawTriPatch(LPDIRECT3DDEVICE8 iface, UINT Handle,CONST float* pNumSegs,CONST D3DTRIPATCH_INFO* pTriPatchInfo) {
2429     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2430     HRESULT hr;
2431     TRACE("(%p) Relay\n", This);
2432
2433     wined3d_mutex_lock();
2434     hr = IWineD3DDevice_DrawTriPatch(This->WineD3DDevice, Handle, pNumSegs, (CONST WINED3DTRIPATCH_INFO *)pTriPatchInfo);
2435     wined3d_mutex_unlock();
2436
2437     return hr;
2438 }
2439
2440 static HRESULT WINAPI IDirect3DDevice8Impl_DeletePatch(LPDIRECT3DDEVICE8 iface, UINT Handle) {
2441     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2442     HRESULT hr;
2443     TRACE("(%p) Relay\n", This);
2444
2445     wined3d_mutex_lock();
2446     hr = IWineD3DDevice_DeletePatch(This->WineD3DDevice, Handle);
2447     wined3d_mutex_unlock();
2448
2449     return hr;
2450 }
2451
2452 static HRESULT WINAPI IDirect3DDevice8Impl_SetStreamSource(LPDIRECT3DDEVICE8 iface, UINT StreamNumber,IDirect3DVertexBuffer8* pStreamData,UINT Stride) {
2453     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2454     HRESULT hr;
2455     TRACE("(%p) Relay\n" , This);
2456
2457     wined3d_mutex_lock();
2458     hr = IWineD3DDevice_SetStreamSource(This->WineD3DDevice, StreamNumber,
2459                                         NULL == pStreamData ? NULL : ((IDirect3DVertexBuffer8Impl *)pStreamData)->wineD3DVertexBuffer,
2460                                         0/* Offset in bytes */, Stride);
2461     wined3d_mutex_unlock();
2462
2463     return hr;
2464 }
2465
2466 static HRESULT WINAPI IDirect3DDevice8Impl_GetStreamSource(LPDIRECT3DDEVICE8 iface, UINT StreamNumber,IDirect3DVertexBuffer8** pStream,UINT* pStride) {
2467     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2468     IWineD3DBuffer *retStream = NULL;
2469     HRESULT rc = D3D_OK;
2470
2471     TRACE("(%p) Relay\n" , This);
2472
2473     if(pStream == NULL){
2474         return D3DERR_INVALIDCALL;
2475     }
2476
2477     wined3d_mutex_lock();
2478     rc = IWineD3DDevice_GetStreamSource(This->WineD3DDevice, StreamNumber, &retStream, 0 /* Offset in bytes */, pStride);
2479     if (rc == D3D_OK  && NULL != retStream) {
2480         IWineD3DBuffer_GetParent(retStream, (IUnknown **)pStream);
2481         IWineD3DBuffer_Release(retStream);
2482     }else{
2483         if (rc != D3D_OK){
2484             FIXME("Call to GetStreamSource failed %p\n",  pStride);
2485         }
2486         *pStream = NULL;
2487     }
2488     wined3d_mutex_unlock();
2489
2490     return rc;
2491 }
2492
2493
2494 const IDirect3DDevice8Vtbl Direct3DDevice8_Vtbl =
2495 {
2496     IDirect3DDevice8Impl_QueryInterface,
2497     IDirect3DDevice8Impl_AddRef,
2498     IDirect3DDevice8Impl_Release,
2499     IDirect3DDevice8Impl_TestCooperativeLevel,
2500     IDirect3DDevice8Impl_GetAvailableTextureMem,
2501     IDirect3DDevice8Impl_ResourceManagerDiscardBytes,
2502     IDirect3DDevice8Impl_GetDirect3D,
2503     IDirect3DDevice8Impl_GetDeviceCaps,
2504     IDirect3DDevice8Impl_GetDisplayMode,
2505     IDirect3DDevice8Impl_GetCreationParameters,
2506     IDirect3DDevice8Impl_SetCursorProperties,
2507     IDirect3DDevice8Impl_SetCursorPosition,
2508     IDirect3DDevice8Impl_ShowCursor,
2509     IDirect3DDevice8Impl_CreateAdditionalSwapChain,
2510     IDirect3DDevice8Impl_Reset,
2511     IDirect3DDevice8Impl_Present,
2512     IDirect3DDevice8Impl_GetBackBuffer,
2513     IDirect3DDevice8Impl_GetRasterStatus,
2514     IDirect3DDevice8Impl_SetGammaRamp,
2515     IDirect3DDevice8Impl_GetGammaRamp,
2516     IDirect3DDevice8Impl_CreateTexture,
2517     IDirect3DDevice8Impl_CreateVolumeTexture,
2518     IDirect3DDevice8Impl_CreateCubeTexture,
2519     IDirect3DDevice8Impl_CreateVertexBuffer,
2520     IDirect3DDevice8Impl_CreateIndexBuffer,
2521     IDirect3DDevice8Impl_CreateRenderTarget,
2522     IDirect3DDevice8Impl_CreateDepthStencilSurface,
2523     IDirect3DDevice8Impl_CreateImageSurface,
2524     IDirect3DDevice8Impl_CopyRects,
2525     IDirect3DDevice8Impl_UpdateTexture,
2526     IDirect3DDevice8Impl_GetFrontBuffer,
2527     IDirect3DDevice8Impl_SetRenderTarget,
2528     IDirect3DDevice8Impl_GetRenderTarget,
2529     IDirect3DDevice8Impl_GetDepthStencilSurface,
2530     IDirect3DDevice8Impl_BeginScene,
2531     IDirect3DDevice8Impl_EndScene,
2532     IDirect3DDevice8Impl_Clear,
2533     IDirect3DDevice8Impl_SetTransform,
2534     IDirect3DDevice8Impl_GetTransform,
2535     IDirect3DDevice8Impl_MultiplyTransform,
2536     IDirect3DDevice8Impl_SetViewport,
2537     IDirect3DDevice8Impl_GetViewport,
2538     IDirect3DDevice8Impl_SetMaterial,
2539     IDirect3DDevice8Impl_GetMaterial,
2540     IDirect3DDevice8Impl_SetLight,
2541     IDirect3DDevice8Impl_GetLight,
2542     IDirect3DDevice8Impl_LightEnable,
2543     IDirect3DDevice8Impl_GetLightEnable,
2544     IDirect3DDevice8Impl_SetClipPlane,
2545     IDirect3DDevice8Impl_GetClipPlane,
2546     IDirect3DDevice8Impl_SetRenderState,
2547     IDirect3DDevice8Impl_GetRenderState,
2548     IDirect3DDevice8Impl_BeginStateBlock,
2549     IDirect3DDevice8Impl_EndStateBlock,
2550     IDirect3DDevice8Impl_ApplyStateBlock,
2551     IDirect3DDevice8Impl_CaptureStateBlock,
2552     IDirect3DDevice8Impl_DeleteStateBlock,
2553     IDirect3DDevice8Impl_CreateStateBlock,
2554     IDirect3DDevice8Impl_SetClipStatus,
2555     IDirect3DDevice8Impl_GetClipStatus,
2556     IDirect3DDevice8Impl_GetTexture,
2557     IDirect3DDevice8Impl_SetTexture,
2558     IDirect3DDevice8Impl_GetTextureStageState,
2559     IDirect3DDevice8Impl_SetTextureStageState,
2560     IDirect3DDevice8Impl_ValidateDevice,
2561     IDirect3DDevice8Impl_GetInfo,
2562     IDirect3DDevice8Impl_SetPaletteEntries,
2563     IDirect3DDevice8Impl_GetPaletteEntries,
2564     IDirect3DDevice8Impl_SetCurrentTexturePalette,
2565     IDirect3DDevice8Impl_GetCurrentTexturePalette,
2566     IDirect3DDevice8Impl_DrawPrimitive,
2567     IDirect3DDevice8Impl_DrawIndexedPrimitive,
2568     IDirect3DDevice8Impl_DrawPrimitiveUP,
2569     IDirect3DDevice8Impl_DrawIndexedPrimitiveUP,
2570     IDirect3DDevice8Impl_ProcessVertices,
2571     IDirect3DDevice8Impl_CreateVertexShader,
2572     IDirect3DDevice8Impl_SetVertexShader,
2573     IDirect3DDevice8Impl_GetVertexShader,
2574     IDirect3DDevice8Impl_DeleteVertexShader,
2575     IDirect3DDevice8Impl_SetVertexShaderConstant,
2576     IDirect3DDevice8Impl_GetVertexShaderConstant,
2577     IDirect3DDevice8Impl_GetVertexShaderDeclaration,
2578     IDirect3DDevice8Impl_GetVertexShaderFunction,
2579     IDirect3DDevice8Impl_SetStreamSource,
2580     IDirect3DDevice8Impl_GetStreamSource,
2581     IDirect3DDevice8Impl_SetIndices,
2582     IDirect3DDevice8Impl_GetIndices,
2583     IDirect3DDevice8Impl_CreatePixelShader,
2584     IDirect3DDevice8Impl_SetPixelShader,
2585     IDirect3DDevice8Impl_GetPixelShader,
2586     IDirect3DDevice8Impl_DeletePixelShader,
2587     IDirect3DDevice8Impl_SetPixelShaderConstant,
2588     IDirect3DDevice8Impl_GetPixelShaderConstant,
2589     IDirect3DDevice8Impl_GetPixelShaderFunction,
2590     IDirect3DDevice8Impl_DrawRectPatch,
2591     IDirect3DDevice8Impl_DrawTriPatch,
2592     IDirect3DDevice8Impl_DeletePatch
2593 };
2594
2595 /* IWineD3DDeviceParent IUnknown methods */
2596
2597 static inline struct IDirect3DDevice8Impl *device_from_device_parent(IWineD3DDeviceParent *iface)
2598 {
2599     return (struct IDirect3DDevice8Impl *)((char*)iface
2600             - FIELD_OFFSET(struct IDirect3DDevice8Impl, device_parent_vtbl));
2601 }
2602
2603 static HRESULT STDMETHODCALLTYPE device_parent_QueryInterface(IWineD3DDeviceParent *iface, REFIID riid, void **object)
2604 {
2605     struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2606     return IDirect3DDevice8Impl_QueryInterface((IDirect3DDevice8 *)This, riid, object);
2607 }
2608
2609 static ULONG STDMETHODCALLTYPE device_parent_AddRef(IWineD3DDeviceParent *iface)
2610 {
2611     struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2612     return IDirect3DDevice8Impl_AddRef((IDirect3DDevice8 *)This);
2613 }
2614
2615 static ULONG STDMETHODCALLTYPE device_parent_Release(IWineD3DDeviceParent *iface)
2616 {
2617     struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2618     return IDirect3DDevice8Impl_Release((IDirect3DDevice8 *)This);
2619 }
2620
2621 /* IWineD3DDeviceParent methods */
2622
2623 static void STDMETHODCALLTYPE device_parent_WineD3DDeviceCreated(IWineD3DDeviceParent *iface, IWineD3DDevice *device)
2624 {
2625     TRACE("iface %p, device %p\n", iface, device);
2626 }
2627
2628 static HRESULT STDMETHODCALLTYPE device_parent_CreateSurface(IWineD3DDeviceParent *iface,
2629         IUnknown *superior, UINT width, UINT height, WINED3DFORMAT format, DWORD usage,
2630         WINED3DPOOL pool, UINT level, WINED3DCUBEMAP_FACES face, IWineD3DSurface **surface)
2631 {
2632     struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2633     IDirect3DSurface8Impl *d3d_surface;
2634     BOOL lockable = TRUE;
2635     HRESULT hr;
2636
2637     TRACE("iface %p, superior %p, width %u, height %u, format %#x, usage %#x,\n"
2638             "\tpool %#x, level %u, face %u, surface %p\n",
2639             iface, superior, width, height, format, usage, pool, level, face, surface);
2640
2641
2642     if (pool == WINED3DPOOL_DEFAULT && !(usage & WINED3DUSAGE_DYNAMIC)) lockable = FALSE;
2643
2644     hr = IDirect3DDevice8Impl_CreateSurface((IDirect3DDevice8 *)This, width, height,
2645             d3dformat_from_wined3dformat(format), lockable, FALSE /* Discard */, level,
2646             (IDirect3DSurface8 **)&d3d_surface, usage, pool, D3DMULTISAMPLE_NONE, 0 /* MultisampleQuality */);
2647     if (FAILED(hr))
2648     {
2649         ERR("(%p) CreateSurface failed, returning %#x\n", iface, hr);
2650         return hr;
2651     }
2652
2653     *surface = d3d_surface->wineD3DSurface;
2654     IWineD3DSurface_AddRef(*surface);
2655
2656     d3d_surface->container = superior;
2657     IUnknown_Release(d3d_surface->parentDevice);
2658     d3d_surface->parentDevice = NULL;
2659
2660     IDirect3DSurface8_Release((IDirect3DSurface8 *)d3d_surface);
2661     d3d_surface->forwardReference = superior;
2662
2663     return hr;
2664 }
2665
2666 static HRESULT STDMETHODCALLTYPE device_parent_CreateRenderTarget(IWineD3DDeviceParent *iface,
2667         IUnknown *superior, UINT width, UINT height, WINED3DFORMAT format, WINED3DMULTISAMPLE_TYPE multisample_type,
2668         DWORD multisample_quality, BOOL lockable, IWineD3DSurface **surface)
2669 {
2670     struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2671     IDirect3DSurface8Impl *d3d_surface;
2672     HRESULT hr;
2673
2674     TRACE("iface %p, superior %p, width %u, height %u, format %#x, multisample_type %#x,\n"
2675             "\tmultisample_quality %u, lockable %u, surface %p\n",
2676             iface, superior, width, height, format, multisample_type, multisample_quality, lockable, surface);
2677
2678     hr = IDirect3DDevice8_CreateRenderTarget((IDirect3DDevice8 *)This, width, height,
2679             d3dformat_from_wined3dformat(format), multisample_type, lockable, (IDirect3DSurface8 **)&d3d_surface);
2680     if (FAILED(hr))
2681     {
2682         ERR("(%p) CreateRenderTarget failed, returning %#x\n", iface, hr);
2683         return hr;
2684     }
2685
2686     *surface = d3d_surface->wineD3DSurface;
2687     IWineD3DSurface_AddRef(*surface);
2688
2689     d3d_surface->container = (IUnknown *)This;
2690     /* Implicit surfaces are created with an refcount of 0 */
2691     IUnknown_Release((IUnknown *)d3d_surface);
2692
2693     return hr;
2694 }
2695
2696 static HRESULT STDMETHODCALLTYPE device_parent_CreateDepthStencilSurface(IWineD3DDeviceParent *iface,
2697         IUnknown *superior, UINT width, UINT height, WINED3DFORMAT format, WINED3DMULTISAMPLE_TYPE multisample_type,
2698         DWORD multisample_quality, BOOL discard, IWineD3DSurface **surface)
2699 {
2700     struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2701     IDirect3DSurface8Impl *d3d_surface;
2702     HRESULT hr;
2703
2704     TRACE("iface %p, superior %p, width %u, height %u, format %#x, multisample_type %#x,\n"
2705             "\tmultisample_quality %u, discard %u, surface %p\n",
2706             iface, superior, width, height, format, multisample_type, multisample_quality, discard, surface);
2707
2708     hr = IDirect3DDevice8_CreateDepthStencilSurface((IDirect3DDevice8 *)This, width, height,
2709             d3dformat_from_wined3dformat(format), multisample_type, (IDirect3DSurface8 **)&d3d_surface);
2710     if (FAILED(hr))
2711     {
2712         ERR("(%p) CreateDepthStencilSurface failed, returning %#x\n", iface, hr);
2713         return hr;
2714     }
2715
2716     *surface = d3d_surface->wineD3DSurface;
2717     IWineD3DSurface_AddRef(*surface);
2718
2719     d3d_surface->container = (IUnknown *)This;
2720     /* Implicit surfaces are created with an refcount of 0 */
2721     IUnknown_Release((IUnknown *)d3d_surface);
2722
2723     return hr;
2724 }
2725
2726 static HRESULT STDMETHODCALLTYPE device_parent_CreateVolume(IWineD3DDeviceParent *iface,
2727         IUnknown *superior, UINT width, UINT height, UINT depth, WINED3DFORMAT format,
2728         WINED3DPOOL pool, DWORD usage, IWineD3DVolume **volume)
2729 {
2730     struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2731     IDirect3DVolume8Impl *object;
2732     HRESULT hr;
2733
2734     TRACE("iface %p, superior %p, width %u, height %u, depth %u, format %#x, pool %#x, usage %#x, volume %p\n",
2735             iface, superior, width, height, depth, format, pool, usage, volume);
2736
2737     /* Allocate the storage for the device */
2738     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2739     if (!object)
2740     {
2741         FIXME("Allocation of memory failed\n");
2742         *volume = NULL;
2743         return D3DERR_OUTOFVIDEOMEMORY;
2744     }
2745
2746     hr = volume_init(object, This, width, height, depth, usage, format, pool);
2747     if (FAILED(hr))
2748     {
2749         WARN("Failed to initialize volume, hr %#x.\n", hr);
2750         HeapFree(GetProcessHeap(), 0, object);
2751         return hr;
2752     }
2753
2754     *volume = object->wineD3DVolume;
2755     IWineD3DVolume_AddRef(*volume);
2756     IDirect3DVolume8_Release((IDirect3DVolume8 *)object);
2757
2758     object->container = superior;
2759     object->forwardReference = superior;
2760
2761     TRACE("(%p) Created volume %p\n", iface, object);
2762
2763     return hr;
2764 }
2765
2766 static HRESULT STDMETHODCALLTYPE device_parent_CreateSwapChain(IWineD3DDeviceParent *iface,
2767         WINED3DPRESENT_PARAMETERS *present_parameters, IWineD3DSwapChain **swapchain)
2768 {
2769     struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2770     IDirect3DSwapChain8Impl *d3d_swapchain;
2771     D3DPRESENT_PARAMETERS local_parameters;
2772     HRESULT hr;
2773
2774     TRACE("iface %p, present_parameters %p, swapchain %p\n", iface, present_parameters, swapchain);
2775
2776     /* Copy the presentation parameters */
2777     local_parameters.BackBufferWidth = present_parameters->BackBufferWidth;
2778     local_parameters.BackBufferHeight = present_parameters->BackBufferHeight;
2779     local_parameters.BackBufferFormat = d3dformat_from_wined3dformat(present_parameters->BackBufferFormat);
2780     local_parameters.BackBufferCount = present_parameters->BackBufferCount;
2781     local_parameters.MultiSampleType = present_parameters->MultiSampleType;
2782     local_parameters.SwapEffect = present_parameters->SwapEffect;
2783     local_parameters.hDeviceWindow = present_parameters->hDeviceWindow;
2784     local_parameters.Windowed = present_parameters->Windowed;
2785     local_parameters.EnableAutoDepthStencil = present_parameters->EnableAutoDepthStencil;
2786     local_parameters.AutoDepthStencilFormat = d3dformat_from_wined3dformat(present_parameters->AutoDepthStencilFormat);
2787     local_parameters.Flags = present_parameters->Flags;
2788     local_parameters.FullScreen_RefreshRateInHz = present_parameters->FullScreen_RefreshRateInHz;
2789     local_parameters.FullScreen_PresentationInterval = present_parameters->PresentationInterval;
2790
2791     hr = IDirect3DDevice8_CreateAdditionalSwapChain((IDirect3DDevice8 *)This,
2792             &local_parameters, (IDirect3DSwapChain8 **)&d3d_swapchain);
2793     if (FAILED(hr))
2794     {
2795         ERR("(%p) CreateAdditionalSwapChain failed, returning %#x\n", iface, hr);
2796         *swapchain = NULL;
2797         return hr;
2798     }
2799
2800     *swapchain = d3d_swapchain->wineD3DSwapChain;
2801     IUnknown_Release(d3d_swapchain->parentDevice);
2802     d3d_swapchain->parentDevice = NULL;
2803
2804     /* Copy back the presentation parameters */
2805     present_parameters->BackBufferWidth = local_parameters.BackBufferWidth;
2806     present_parameters->BackBufferHeight = local_parameters.BackBufferHeight;
2807     present_parameters->BackBufferFormat = wined3dformat_from_d3dformat(local_parameters.BackBufferFormat);
2808     present_parameters->BackBufferCount = local_parameters.BackBufferCount;
2809     present_parameters->MultiSampleType = local_parameters.MultiSampleType;
2810     present_parameters->SwapEffect = local_parameters.SwapEffect;
2811     present_parameters->hDeviceWindow = local_parameters.hDeviceWindow;
2812     present_parameters->Windowed = local_parameters.Windowed;
2813     present_parameters->EnableAutoDepthStencil = local_parameters.EnableAutoDepthStencil;
2814     present_parameters->AutoDepthStencilFormat = wined3dformat_from_d3dformat(local_parameters.AutoDepthStencilFormat);
2815     present_parameters->Flags = local_parameters.Flags;
2816     present_parameters->FullScreen_RefreshRateInHz = local_parameters.FullScreen_RefreshRateInHz;
2817     present_parameters->PresentationInterval = local_parameters.FullScreen_PresentationInterval;
2818
2819     return hr;
2820 }
2821
2822 const IWineD3DDeviceParentVtbl d3d8_wined3d_device_parent_vtbl =
2823 {
2824     /* IUnknown methods */
2825     device_parent_QueryInterface,
2826     device_parent_AddRef,
2827     device_parent_Release,
2828     /* IWineD3DDeviceParent methods */
2829     device_parent_WineD3DDeviceCreated,
2830     device_parent_CreateSurface,
2831     device_parent_CreateRenderTarget,
2832     device_parent_CreateDepthStencilSurface,
2833     device_parent_CreateVolume,
2834     device_parent_CreateSwapChain,
2835 };