pdh/tests: Add test for size > 0 but no buffer.
[wine] / dlls / d3d8 / directx.c
1 /*
2  * IDirect3D8 implementation
3  *
4  * Copyright 2002-2004 Jason Edmeades
5  * Copyright 2003-2004 Raphael Junqueira
6  * Copyright 2004 Christian Costa
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21  */
22
23 #include "config.h"
24
25 #include <stdarg.h>
26
27 #define NONAMELESSUNION
28 #define NONAMELESSSTRUCT
29 #include "windef.h"
30 #include "winbase.h"
31 #include "wingdi.h"
32 #include "winuser.h"
33 #include "wine/debug.h"
34 #include "wine/unicode.h"
35
36 #include "d3d8_private.h"
37
38 WINE_DEFAULT_DEBUG_CHANNEL(d3d8);
39
40 /* IDirect3D IUnknown parts follow: */
41 static HRESULT WINAPI IDirect3D8Impl_QueryInterface(LPDIRECT3D8 iface, REFIID riid,LPVOID *ppobj)
42 {
43     IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
44
45     if (IsEqualGUID(riid, &IID_IUnknown)
46         || IsEqualGUID(riid, &IID_IDirect3D8)) {
47         IUnknown_AddRef(iface);
48         *ppobj = This;
49         return S_OK;
50     }
51
52     WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid),ppobj);
53     *ppobj = NULL;
54     return E_NOINTERFACE;
55 }
56
57 static ULONG WINAPI IDirect3D8Impl_AddRef(LPDIRECT3D8 iface) {
58     IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
59     ULONG ref = InterlockedIncrement(&This->ref);
60
61     TRACE("(%p) : AddRef from %d\n", This, ref - 1);
62
63     return ref;
64 }
65
66 static ULONG WINAPI IDirect3D8Impl_Release(LPDIRECT3D8 iface) {
67     IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
68     ULONG ref = InterlockedDecrement(&This->ref);
69
70     TRACE("(%p) : ReleaseRef to %d\n", This, ref);
71
72     if (ref == 0) {
73         TRACE("Releasing wined3d %p\n", This->WineD3D);
74         IWineD3D_Release(This->WineD3D);
75         HeapFree(GetProcessHeap(), 0, This);
76     }
77
78     return ref;
79 }
80
81 /* IDirect3D8 Interface follow: */
82 static HRESULT WINAPI IDirect3D8Impl_RegisterSoftwareDevice (LPDIRECT3D8 iface, void* pInitializeFunction) {
83     IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
84     HRESULT hr;
85     TRACE("(%p)->(%p)\n", This, pInitializeFunction);
86
87     EnterCriticalSection(&d3d8_cs);
88     hr = IWineD3D_RegisterSoftwareDevice(This->WineD3D, pInitializeFunction);
89     LeaveCriticalSection(&d3d8_cs);
90     return hr;
91 }
92
93 static UINT WINAPI IDirect3D8Impl_GetAdapterCount (LPDIRECT3D8 iface) {
94     IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
95     HRESULT hr;
96     TRACE("(%p)\n", This);
97
98     EnterCriticalSection(&d3d8_cs);
99     hr = IWineD3D_GetAdapterCount(This->WineD3D);
100     LeaveCriticalSection(&d3d8_cs);
101     return hr;
102 }
103
104 static HRESULT  WINAPI  IDirect3D8Impl_GetAdapterIdentifier       (LPDIRECT3D8 iface,
105                                                             UINT Adapter, DWORD Flags, D3DADAPTER_IDENTIFIER8* pIdentifier) {
106     IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
107     WINED3DADAPTER_IDENTIFIER adapter_id;
108     HRESULT hr;
109
110     TRACE("(%p)->(%d,%08x, %p\n", This, Adapter, Flags, pIdentifier);
111     EnterCriticalSection(&d3d8_cs);
112     /* dx8 and dx9 have different structures to be filled in, with incompatible 
113        layouts so pass in pointers to the places to be filled via an internal 
114        structure                                                                */
115     adapter_id.Driver           = pIdentifier->Driver;
116     adapter_id.Description      = pIdentifier->Description;
117     adapter_id.DeviceName       = NULL; /* d3d9 only */
118     adapter_id.DriverVersion    = &pIdentifier->DriverVersion;
119     adapter_id.VendorId         = &pIdentifier->VendorId;
120     adapter_id.DeviceId         = &pIdentifier->DeviceId;
121     adapter_id.SubSysId         = &pIdentifier->SubSysId;
122     adapter_id.Revision         = &pIdentifier->Revision;
123     adapter_id.DeviceIdentifier = &pIdentifier->DeviceIdentifier;
124     adapter_id.WHQLLevel        = &pIdentifier->WHQLLevel;
125
126     hr = IWineD3D_GetAdapterIdentifier(This->WineD3D, Adapter, Flags, &adapter_id);
127     LeaveCriticalSection(&d3d8_cs);
128     return hr;
129 }
130
131 static UINT WINAPI IDirect3D8Impl_GetAdapterModeCount (LPDIRECT3D8 iface,UINT Adapter) {
132     IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
133     HRESULT hr;
134     TRACE("(%p)->(%d)\n", This, Adapter);
135
136     EnterCriticalSection(&d3d8_cs);
137     hr = IWineD3D_GetAdapterModeCount(This->WineD3D, Adapter, 0 /* format */);
138     LeaveCriticalSection(&d3d8_cs);
139     return hr;
140 }
141
142 static HRESULT WINAPI IDirect3D8Impl_EnumAdapterModes (LPDIRECT3D8 iface, UINT Adapter, UINT Mode, D3DDISPLAYMODE* pMode) {
143     IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
144     HRESULT hr;
145     TRACE("(%p)->(%d, %d, %p)\n", This, Adapter, Mode, pMode);
146
147     EnterCriticalSection(&d3d8_cs);
148     hr = IWineD3D_EnumAdapterModes(This->WineD3D, Adapter, WINED3DFMT_UNKNOWN, Mode, (WINED3DDISPLAYMODE *) pMode);
149     LeaveCriticalSection(&d3d8_cs);
150     return hr;
151 }
152
153 static HRESULT WINAPI IDirect3D8Impl_GetAdapterDisplayMode (LPDIRECT3D8 iface, UINT Adapter, D3DDISPLAYMODE* pMode) {
154     IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
155     HRESULT hr;
156     TRACE("(%p)->(%d,%p)\n", This, Adapter, pMode);
157
158     EnterCriticalSection(&d3d8_cs);
159     hr = IWineD3D_GetAdapterDisplayMode(This->WineD3D, Adapter, (WINED3DDISPLAYMODE *) pMode);
160     LeaveCriticalSection(&d3d8_cs);
161     return hr;
162 }
163
164 static HRESULT  WINAPI  IDirect3D8Impl_CheckDeviceType            (LPDIRECT3D8 iface,
165                                                             UINT Adapter, D3DDEVTYPE CheckType, D3DFORMAT DisplayFormat,
166                                                             D3DFORMAT BackBufferFormat, BOOL Windowed) {
167     IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
168     HRESULT hr;
169     TRACE("(%p)->(%d, %d, %d, %d, %s)\n", This, Adapter, CheckType, DisplayFormat, BackBufferFormat, Windowed ? "true" : "false");
170
171     EnterCriticalSection(&d3d8_cs);
172     hr = IWineD3D_CheckDeviceType(This->WineD3D, Adapter, CheckType, DisplayFormat,
173                                     BackBufferFormat, Windowed);
174     LeaveCriticalSection(&d3d8_cs);
175     return hr;
176 }
177
178 static HRESULT  WINAPI  IDirect3D8Impl_CheckDeviceFormat          (LPDIRECT3D8 iface,
179                                                             UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat,
180                                                             DWORD Usage, D3DRESOURCETYPE RType, D3DFORMAT CheckFormat) {
181     IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
182     HRESULT hr;
183     TRACE("(%p)->(%d, %d, %d, %08x, %d, %d)\n", This, Adapter, DeviceType, AdapterFormat, Usage, RType, CheckFormat);
184
185     EnterCriticalSection(&d3d8_cs);
186     hr = IWineD3D_CheckDeviceFormat(This->WineD3D, Adapter, DeviceType, AdapterFormat,
187                                     Usage, RType, CheckFormat);
188     LeaveCriticalSection(&d3d8_cs);
189     return hr;
190 }
191
192 static HRESULT  WINAPI  IDirect3D8Impl_CheckDeviceMultiSampleType(LPDIRECT3D8 iface,
193                                                            UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT SurfaceFormat,
194                                                            BOOL Windowed, D3DMULTISAMPLE_TYPE MultiSampleType) {
195     IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
196     HRESULT hr;
197     TRACE("(%p)-<(%d, %d, %d, %s, %d)\n", This, Adapter, DeviceType, SurfaceFormat, Windowed ? "true" : "false", MultiSampleType);
198
199     EnterCriticalSection(&d3d8_cs);
200     hr = IWineD3D_CheckDeviceMultiSampleType(This->WineD3D, Adapter, DeviceType, SurfaceFormat,
201                                                Windowed, (WINED3DMULTISAMPLE_TYPE) MultiSampleType, NULL);
202     LeaveCriticalSection(&d3d8_cs);
203     return hr;
204 }
205
206 static HRESULT  WINAPI  IDirect3D8Impl_CheckDepthStencilMatch(LPDIRECT3D8 iface, 
207                                                        UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat,
208                                                        D3DFORMAT RenderTargetFormat, D3DFORMAT DepthStencilFormat) {
209     IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
210     HRESULT hr;
211     TRACE("(%p)-<(%d, %d, %d, %d, %d)\n", This, Adapter, DeviceType, AdapterFormat, RenderTargetFormat, DepthStencilFormat);
212
213     EnterCriticalSection(&d3d8_cs);
214     hr = IWineD3D_CheckDepthStencilMatch(This->WineD3D, Adapter, DeviceType, AdapterFormat,
215                                            RenderTargetFormat, DepthStencilFormat);
216     LeaveCriticalSection(&d3d8_cs);
217     return hr;
218 }
219
220 static HRESULT  WINAPI  IDirect3D8Impl_GetDeviceCaps(LPDIRECT3D8 iface, UINT Adapter, D3DDEVTYPE DeviceType, D3DCAPS8* pCaps) {
221     IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
222     HRESULT hrc = D3D_OK;
223     WINED3DCAPS *pWineCaps;
224
225     TRACE("(%p) Relay %d %u %p\n", This, Adapter, DeviceType, pCaps);
226
227     if(NULL == pCaps){
228         return D3DERR_INVALIDCALL;
229     }
230     pWineCaps = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WINED3DCAPS));
231     if(pWineCaps == NULL){
232         return D3DERR_INVALIDCALL; /*well this is what MSDN says to return*/
233     }
234     D3D8CAPSTOWINECAPS(pCaps, pWineCaps)
235     EnterCriticalSection(&d3d8_cs);
236     hrc = IWineD3D_GetDeviceCaps(This->WineD3D, Adapter, DeviceType, pWineCaps);
237     LeaveCriticalSection(&d3d8_cs);
238     HeapFree(GetProcessHeap(), 0, pWineCaps);
239
240     /* D3D8 doesn't support SM 2.0 or higher, so clamp to 1.x */
241     if(pCaps->PixelShaderVersion > D3DPS_VERSION(1,4)){
242         pCaps->PixelShaderVersion = D3DPS_VERSION(1,4);
243     }
244     if(pCaps->VertexShaderVersion > D3DVS_VERSION(1,1)){
245         pCaps->VertexShaderVersion = D3DVS_VERSION(1,1);
246     }
247
248     TRACE("(%p) returning %p\n", This, pCaps);
249     return hrc;
250 }
251
252 static HMONITOR WINAPI  IDirect3D8Impl_GetAdapterMonitor(LPDIRECT3D8 iface, UINT Adapter) {
253     IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
254     HMONITOR ret;
255     TRACE("(%p)->(%d)\n", This, Adapter);
256
257     EnterCriticalSection(&d3d8_cs);
258     ret = IWineD3D_GetAdapterMonitor(This->WineD3D, Adapter);
259     LeaveCriticalSection(&d3d8_cs);
260     return ret;
261 }
262
263 /* Internal function called back during the CreateDevice to create a render target */
264 HRESULT WINAPI D3D8CB_CreateRenderTarget(IUnknown *device, IUnknown *pSuperior, UINT Width, UINT Height,
265                                          WINED3DFORMAT Format, WINED3DMULTISAMPLE_TYPE MultiSample,
266                                          DWORD MultisampleQuality, BOOL Lockable,
267                                          IWineD3DSurface** ppSurface, HANDLE* pSharedHandle) {
268     HRESULT res = D3D_OK;
269     IDirect3DSurface8Impl *d3dSurface = NULL;
270
271     TRACE("(%p) call back\n", device);
272     res = IDirect3DDevice8_CreateRenderTarget((IDirect3DDevice8 *)device, Width, Height, 
273                                          (D3DFORMAT)Format, MultiSample, Lockable, 
274                                          (IDirect3DSurface8 **)&d3dSurface);
275
276     if (SUCCEEDED(res)) {
277         *ppSurface = d3dSurface->wineD3DSurface;
278         d3dSurface->container = device;
279         d3dSurface->isImplicit = TRUE;
280         /* Implicit surfaces are created with an refcount of 0 */
281         IUnknown_Release((IUnknown *)d3dSurface);
282     } else {
283         *ppSurface = NULL;
284     }
285     return res;
286 }
287
288 ULONG WINAPI D3D8CB_DestroyRenderTarget(IWineD3DSurface *pSurface) {
289     IDirect3DSurface8Impl* surfaceParent;
290     TRACE("(%p) call back\n", pSurface);
291
292     IWineD3DSurface_GetParent(pSurface, (IUnknown **) &surfaceParent);
293     surfaceParent->isImplicit = FALSE;
294     /* Surface had refcount of 0 GetParent addrefed to 1, so 1 Release is enough */
295     return IDirect3DSurface8_Release((IDirect3DSurface8*) surfaceParent);
296 }
297
298 /* Callback for creating the inplicite swapchain when the device is created */
299 static HRESULT WINAPI D3D8CB_CreateAdditionalSwapChain(IUnknown *device,
300                                                 WINED3DPRESENT_PARAMETERS* pPresentationParameters,
301                                                 IWineD3DSwapChain ** ppSwapChain){
302     HRESULT res = D3D_OK;
303     IDirect3DSwapChain8Impl *d3dSwapChain = NULL;
304     D3DPRESENT_PARAMETERS localParameters;
305     TRACE("(%p) call back\n", device);
306
307     /* Copy the presentation parameters */
308     localParameters.BackBufferWidth                             = pPresentationParameters->BackBufferWidth;
309     localParameters.BackBufferHeight                            = pPresentationParameters->BackBufferHeight;
310     localParameters.BackBufferFormat                            = pPresentationParameters->BackBufferFormat;
311     localParameters.BackBufferCount                             = pPresentationParameters->BackBufferCount;
312     localParameters.MultiSampleType                             = pPresentationParameters->MultiSampleType;
313     localParameters.SwapEffect                                  = pPresentationParameters->SwapEffect;
314     localParameters.hDeviceWindow                               = pPresentationParameters->hDeviceWindow;
315     localParameters.Windowed                                    = pPresentationParameters->Windowed;
316     localParameters.EnableAutoDepthStencil                      = pPresentationParameters->EnableAutoDepthStencil;
317     localParameters.AutoDepthStencilFormat                      = pPresentationParameters->AutoDepthStencilFormat;
318     localParameters.Flags                                       = pPresentationParameters->Flags;
319     localParameters.FullScreen_RefreshRateInHz                  = pPresentationParameters->FullScreen_RefreshRateInHz;
320     localParameters.FullScreen_PresentationInterval             = pPresentationParameters->PresentationInterval;
321
322     res = IDirect3DDevice8_CreateAdditionalSwapChain((IDirect3DDevice8 *)device, &localParameters, (IDirect3DSwapChain8 **)&d3dSwapChain);
323
324     /* Copy back the presentation parameters */
325     pPresentationParameters->BackBufferWidth                    = localParameters.BackBufferWidth;
326     pPresentationParameters->BackBufferHeight                   = localParameters.BackBufferHeight;
327     pPresentationParameters->BackBufferFormat                   = localParameters.BackBufferFormat;
328     pPresentationParameters->BackBufferCount                    = localParameters.BackBufferCount;
329     pPresentationParameters->MultiSampleType                    = localParameters.MultiSampleType;
330     pPresentationParameters->SwapEffect                         = localParameters.SwapEffect;
331     pPresentationParameters->hDeviceWindow                      = localParameters.hDeviceWindow;
332     pPresentationParameters->Windowed                           = localParameters.Windowed;
333     pPresentationParameters->EnableAutoDepthStencil             = localParameters.EnableAutoDepthStencil;
334     pPresentationParameters->AutoDepthStencilFormat             = localParameters.AutoDepthStencilFormat;
335     pPresentationParameters->Flags                              = localParameters.Flags;
336     pPresentationParameters->FullScreen_RefreshRateInHz         = localParameters.FullScreen_RefreshRateInHz;
337     pPresentationParameters->PresentationInterval               = localParameters.FullScreen_PresentationInterval;
338
339     if (SUCCEEDED(res)) {
340         *ppSwapChain = d3dSwapChain->wineD3DSwapChain;
341         IUnknown_Release(d3dSwapChain->parentDevice);
342         d3dSwapChain->parentDevice = NULL;
343     } else {
344         *ppSwapChain = NULL;
345     }
346
347     return res;
348 }
349
350 ULONG WINAPI D3D8CB_DestroySwapChain(IWineD3DSwapChain *pSwapChain) {
351     IUnknown* swapChainParent;
352     TRACE("(%p) call back\n", pSwapChain);
353
354     IWineD3DSwapChain_GetParent(pSwapChain, &swapChainParent);
355     IUnknown_Release(swapChainParent);
356     return IUnknown_Release(swapChainParent);
357 }
358
359 /* Internal function called back during the CreateDevice to create a render target */
360 HRESULT WINAPI D3D8CB_CreateDepthStencilSurface(IUnknown *device, IUnknown *pSuperior, UINT Width, UINT Height,
361                                          WINED3DFORMAT Format, WINED3DMULTISAMPLE_TYPE MultiSample,
362                                          DWORD MultisampleQuality, BOOL Discard,
363                                          IWineD3DSurface** ppSurface, HANDLE* pSharedHandle) {
364     HRESULT res = D3D_OK;
365     IDirect3DSurface8Impl *d3dSurface = NULL;
366     TRACE("(%p) call back\n", device);
367
368     res = IDirect3DDevice8_CreateDepthStencilSurface((IDirect3DDevice8 *)device, Width, Height, 
369                                          (D3DFORMAT)Format, MultiSample, (IDirect3DSurface8 **)&d3dSurface);
370     if (SUCCEEDED(res)) {
371         *ppSurface = d3dSurface->wineD3DSurface;
372         d3dSurface->container = device;
373         d3dSurface->isImplicit = TRUE;
374         /* Implicit surfaces are created with an refcount of 0 */
375         IUnknown_Release((IUnknown *)d3dSurface);
376     }
377     return res;
378 }
379
380 ULONG WINAPI D3D8CB_DestroyDepthStencilSurface(IWineD3DSurface *pSurface) {
381     IDirect3DSurface8Impl* surfaceParent;
382     TRACE("(%p) call back\n", pSurface);
383
384     IWineD3DSurface_GetParent(pSurface, (IUnknown **) &surfaceParent);
385     surfaceParent->isImplicit = FALSE;
386     /* Surface had refcount of 0 GetParent addrefed to 1, so 1 Release is enough */
387     return IDirect3DSurface8_Release((IDirect3DSurface8*) surfaceParent);
388 }
389
390 static HRESULT WINAPI IDirect3D8Impl_CreateDevice(LPDIRECT3D8 iface, UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow,
391                                             DWORD BehaviourFlags, D3DPRESENT_PARAMETERS* pPresentationParameters,
392                                             IDirect3DDevice8** ppReturnedDeviceInterface) {
393
394     IDirect3D8Impl       *This   = (IDirect3D8Impl *)iface;
395     IDirect3DDevice8Impl *object = NULL;
396     WINED3DPRESENT_PARAMETERS localParameters;
397     HRESULT hr;
398     TRACE("(%p) Relay\n", This);
399
400     /* Check the validity range of the adapter parameter */
401     if (Adapter >= IDirect3D8Impl_GetAdapterCount(iface)) {
402         *ppReturnedDeviceInterface = NULL;
403         return D3DERR_INVALIDCALL;
404     }
405
406     /* Allocate the storage for the device object */
407     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DDevice8Impl));
408     if (NULL == object) {
409         FIXME("Allocation of memory failed\n");
410         *ppReturnedDeviceInterface = NULL;
411         return D3DERR_OUTOFVIDEOMEMORY;
412     }
413
414     object->lpVtbl = &Direct3DDevice8_Vtbl;
415     object->ref = 1;
416     object->shader_handles = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, INITIAL_SHADER_HANDLE_TABLE_SIZE * sizeof(shader_handle));
417     object->shader_handle_table_size = INITIAL_SHADER_HANDLE_TABLE_SIZE;
418     *ppReturnedDeviceInterface = (IDirect3DDevice8 *)object;
419
420     /* Allocate an associated WineD3DDevice object */
421     EnterCriticalSection(&d3d8_cs);
422     hr =IWineD3D_CreateDevice(This->WineD3D, Adapter, DeviceType, hFocusWindow, BehaviourFlags, &object->WineD3DDevice, (IUnknown *)object);
423
424     if (hr != D3D_OK) {
425         HeapFree(GetProcessHeap(), 0, object);
426         *ppReturnedDeviceInterface = NULL;
427         LeaveCriticalSection(&d3d8_cs);
428         return hr;
429     }
430
431     TRACE("(%p) : Created Device %p\n", This, object);
432
433     localParameters.BackBufferWidth                             = pPresentationParameters->BackBufferWidth;
434     localParameters.BackBufferHeight                            = pPresentationParameters->BackBufferHeight;
435     localParameters.BackBufferFormat                            = pPresentationParameters->BackBufferFormat;
436     localParameters.BackBufferCount                             = pPresentationParameters->BackBufferCount;
437     localParameters.MultiSampleType                             = pPresentationParameters->MultiSampleType;
438     localParameters.MultiSampleQuality                          = 0; /* d3d9 only */
439     localParameters.SwapEffect                                  = pPresentationParameters->SwapEffect;
440     localParameters.hDeviceWindow                               = pPresentationParameters->hDeviceWindow;
441     localParameters.Windowed                                    = pPresentationParameters->Windowed;
442     localParameters.EnableAutoDepthStencil                      = pPresentationParameters->EnableAutoDepthStencil;
443     localParameters.AutoDepthStencilFormat                      = pPresentationParameters->AutoDepthStencilFormat;
444     localParameters.Flags                                       = pPresentationParameters->Flags;
445     localParameters.FullScreen_RefreshRateInHz                  = pPresentationParameters->FullScreen_RefreshRateInHz;
446     localParameters.PresentationInterval                        = pPresentationParameters->FullScreen_PresentationInterval;
447
448     if(BehaviourFlags & D3DCREATE_MULTITHREADED) {
449         IWineD3DDevice_SetMultithreaded(object->WineD3DDevice);
450     }
451
452     hr = IWineD3DDevice_Init3D(object->WineD3DDevice, &localParameters, D3D8CB_CreateAdditionalSwapChain);
453     LeaveCriticalSection(&d3d8_cs);
454
455     pPresentationParameters->BackBufferWidth                    = localParameters.BackBufferWidth;
456     pPresentationParameters->BackBufferHeight                   = localParameters.BackBufferHeight;
457     pPresentationParameters->BackBufferFormat                   = localParameters.BackBufferFormat;
458     pPresentationParameters->BackBufferCount                    = localParameters.BackBufferCount;
459     pPresentationParameters->MultiSampleType                    = localParameters.MultiSampleType;
460     pPresentationParameters->SwapEffect                         = localParameters.SwapEffect;
461     pPresentationParameters->hDeviceWindow                      = localParameters.hDeviceWindow;
462     pPresentationParameters->Windowed                           = localParameters.Windowed;
463     pPresentationParameters->EnableAutoDepthStencil             = localParameters.EnableAutoDepthStencil;
464     pPresentationParameters->AutoDepthStencilFormat             = localParameters.AutoDepthStencilFormat;
465     pPresentationParameters->Flags                              = localParameters.Flags;
466     pPresentationParameters->FullScreen_RefreshRateInHz         = localParameters.FullScreen_RefreshRateInHz;
467     pPresentationParameters->FullScreen_PresentationInterval    = localParameters.PresentationInterval;
468
469     if (hr != D3D_OK) {
470         FIXME("(%p) D3D Initialization failed for WineD3DDevice %p\n", This, object->WineD3DDevice);
471         HeapFree(GetProcessHeap(), 0, object);
472         *ppReturnedDeviceInterface = NULL;
473     }
474
475     object->declArraySize = 16;
476     object->decls = HeapAlloc(GetProcessHeap(), 0, object->declArraySize * sizeof(*object->decls));
477     if(!object->decls) {
478         ERR("Out of memory\n");
479         IWineD3DDevice_Release(object->WineD3DDevice);
480         HeapFree(GetProcessHeap(), 0, object);
481         *ppReturnedDeviceInterface = NULL;
482         hr = E_OUTOFMEMORY;
483     }
484     return hr;
485 }
486
487 const IDirect3D8Vtbl Direct3D8_Vtbl =
488 {
489     /* IUnknown */
490     IDirect3D8Impl_QueryInterface,
491     IDirect3D8Impl_AddRef,
492     IDirect3D8Impl_Release,
493     /* IDirect3D8 */
494     IDirect3D8Impl_RegisterSoftwareDevice,
495     IDirect3D8Impl_GetAdapterCount,
496     IDirect3D8Impl_GetAdapterIdentifier,
497     IDirect3D8Impl_GetAdapterModeCount,
498     IDirect3D8Impl_EnumAdapterModes,
499     IDirect3D8Impl_GetAdapterDisplayMode,
500     IDirect3D8Impl_CheckDeviceType,
501     IDirect3D8Impl_CheckDeviceFormat,
502     IDirect3D8Impl_CheckDeviceMultiSampleType,
503     IDirect3D8Impl_CheckDepthStencilMatch,
504     IDirect3D8Impl_GetDeviceCaps,
505     IDirect3D8Impl_GetAdapterMonitor,
506     IDirect3D8Impl_CreateDevice
507 };