push 8724397e7ede0f147b6e05994a72142d44d4fecc
[wine/hacks.git] / dlls / d3d9 / device.c
blobd551ff6122ed55733f1ec89925705cc339eb0c86
1 /*
2 * IDirect3DDevice9 implementation
4 * Copyright 2002-2005 Jason Edmeades
5 * Copyright 2002-2005 Raphael Junqueira
6 * Copyright 2005 Oliver Stieber
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "config.h"
24 #include "d3d9_private.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
28 D3DFORMAT d3dformat_from_wined3dformat(WINED3DFORMAT format)
30 BYTE *c = (BYTE *)&format;
32 /* Don't translate FOURCC formats */
33 if (isprint(c[0]) && isprint(c[1]) && isprint(c[2]) && isprint(c[3])) return format;
35 switch(format)
37 case WINED3DFMT_UNKNOWN: return D3DFMT_UNKNOWN;
38 case WINED3DFMT_R8G8B8: return D3DFMT_R8G8B8;
39 case WINED3DFMT_A8R8G8B8: return D3DFMT_A8R8G8B8;
40 case WINED3DFMT_X8R8G8B8: return D3DFMT_X8R8G8B8;
41 case WINED3DFMT_R5G6B5: return D3DFMT_R5G6B5;
42 case WINED3DFMT_X1R5G5B5: return D3DFMT_X1R5G5B5;
43 case WINED3DFMT_A1R5G5B5: return D3DFMT_A1R5G5B5;
44 case WINED3DFMT_A4R4G4B4: return D3DFMT_A4R4G4B4;
45 case WINED3DFMT_R3G3B2: return D3DFMT_R3G3B2;
46 case WINED3DFMT_A8_UNORM: return D3DFMT_A8;
47 case WINED3DFMT_A8R3G3B2: return D3DFMT_A8R3G3B2;
48 case WINED3DFMT_X4R4G4B4: return D3DFMT_X4R4G4B4;
49 case WINED3DFMT_R10G10B10A2_UNORM: return D3DFMT_A2B10G10R10;
50 case WINED3DFMT_R8G8B8A8_UNORM: return D3DFMT_A8B8G8R8;
51 case WINED3DFMT_X8B8G8R8: return D3DFMT_X8B8G8R8;
52 case WINED3DFMT_R16G16_UNORM: return D3DFMT_G16R16;
53 case WINED3DFMT_A2R10G10B10: return D3DFMT_A2R10G10B10;
54 case WINED3DFMT_R16G16B16A16_UNORM: return D3DFMT_A16B16G16R16;
55 case WINED3DFMT_A8P8: return D3DFMT_A8P8;
56 case WINED3DFMT_P8: return D3DFMT_P8;
57 case WINED3DFMT_L8: return D3DFMT_L8;
58 case WINED3DFMT_A8L8: return D3DFMT_A8L8;
59 case WINED3DFMT_A4L4: return D3DFMT_A4L4;
60 case WINED3DFMT_R8G8_SNORM: return D3DFMT_V8U8;
61 case WINED3DFMT_L6V5U5: return D3DFMT_L6V5U5;
62 case WINED3DFMT_X8L8V8U8: return D3DFMT_X8L8V8U8;
63 case WINED3DFMT_R8G8B8A8_SNORM: return D3DFMT_Q8W8V8U8;
64 case WINED3DFMT_R16G16_SNORM: return D3DFMT_V16U16;
65 case WINED3DFMT_A2W10V10U10: return D3DFMT_A2W10V10U10;
66 case WINED3DFMT_D16_LOCKABLE: return D3DFMT_D16_LOCKABLE;
67 case WINED3DFMT_D32: return D3DFMT_D32;
68 case WINED3DFMT_D15S1: return D3DFMT_D15S1;
69 case WINED3DFMT_D24S8: return D3DFMT_D24S8;
70 case WINED3DFMT_D24X8: return D3DFMT_D24X8;
71 case WINED3DFMT_D24X4S4: return D3DFMT_D24X4S4;
72 case WINED3DFMT_D16_UNORM: return D3DFMT_D16;
73 case WINED3DFMT_L16: return D3DFMT_L16;
74 case WINED3DFMT_D32F_LOCKABLE: return D3DFMT_D32F_LOCKABLE;
75 case WINED3DFMT_D24FS8: return D3DFMT_D24FS8;
76 case WINED3DFMT_VERTEXDATA: return D3DFMT_VERTEXDATA;
77 case WINED3DFMT_R16_UINT: return D3DFMT_INDEX16;
78 case WINED3DFMT_R32_UINT: return D3DFMT_INDEX32;
79 case WINED3DFMT_R16G16B16A16_SNORM: return D3DFMT_Q16W16V16U16;
80 case WINED3DFMT_R16_FLOAT: return D3DFMT_R16F;
81 case WINED3DFMT_R16G16_FLOAT: return D3DFMT_G16R16F;
82 case WINED3DFMT_R16G16B16A16_FLOAT: return D3DFMT_A16B16G16R16F;
83 case WINED3DFMT_R32_FLOAT: return D3DFMT_R32F;
84 case WINED3DFMT_R32G32_FLOAT: return D3DFMT_G32R32F;
85 case WINED3DFMT_R32G32B32A32_FLOAT: return D3DFMT_A32B32G32R32F;
86 case WINED3DFMT_CxV8U8: return D3DFMT_CxV8U8;
87 default:
88 FIXME("Unhandled WINED3DFORMAT %#x\n", format);
89 return D3DFMT_UNKNOWN;
93 WINED3DFORMAT wined3dformat_from_d3dformat(D3DFORMAT format)
95 BYTE *c = (BYTE *)&format;
97 /* Don't translate FOURCC formats */
98 if (isprint(c[0]) && isprint(c[1]) && isprint(c[2]) && isprint(c[3])) return format;
100 switch(format)
102 case D3DFMT_UNKNOWN: return WINED3DFMT_UNKNOWN;
103 case D3DFMT_R8G8B8: return WINED3DFMT_R8G8B8;
104 case D3DFMT_A8R8G8B8: return WINED3DFMT_A8R8G8B8;
105 case D3DFMT_X8R8G8B8: return WINED3DFMT_X8R8G8B8;
106 case D3DFMT_R5G6B5: return WINED3DFMT_R5G6B5;
107 case D3DFMT_X1R5G5B5: return WINED3DFMT_X1R5G5B5;
108 case D3DFMT_A1R5G5B5: return WINED3DFMT_A1R5G5B5;
109 case D3DFMT_A4R4G4B4: return WINED3DFMT_A4R4G4B4;
110 case D3DFMT_R3G3B2: return WINED3DFMT_R3G3B2;
111 case D3DFMT_A8: return WINED3DFMT_A8_UNORM;
112 case D3DFMT_A8R3G3B2: return WINED3DFMT_A8R3G3B2;
113 case D3DFMT_X4R4G4B4: return WINED3DFMT_X4R4G4B4;
114 case D3DFMT_A2B10G10R10: return WINED3DFMT_R10G10B10A2_UNORM;
115 case D3DFMT_A8B8G8R8: return WINED3DFMT_R8G8B8A8_UNORM;
116 case D3DFMT_X8B8G8R8: return WINED3DFMT_X8B8G8R8;
117 case D3DFMT_G16R16: return WINED3DFMT_R16G16_UNORM;
118 case D3DFMT_A2R10G10B10: return WINED3DFMT_A2R10G10B10;
119 case D3DFMT_A16B16G16R16: return WINED3DFMT_R16G16B16A16_UNORM;
120 case D3DFMT_A8P8: return WINED3DFMT_A8P8;
121 case D3DFMT_P8: return WINED3DFMT_P8;
122 case D3DFMT_L8: return WINED3DFMT_L8;
123 case D3DFMT_A8L8: return WINED3DFMT_A8L8;
124 case D3DFMT_A4L4: return WINED3DFMT_A4L4;
125 case D3DFMT_V8U8: return WINED3DFMT_R8G8_SNORM;
126 case D3DFMT_L6V5U5: return WINED3DFMT_L6V5U5;
127 case D3DFMT_X8L8V8U8: return WINED3DFMT_X8L8V8U8;
128 case D3DFMT_Q8W8V8U8: return WINED3DFMT_R8G8B8A8_SNORM;
129 case D3DFMT_V16U16: return WINED3DFMT_R16G16_SNORM;
130 case D3DFMT_A2W10V10U10: return WINED3DFMT_A2W10V10U10;
131 case D3DFMT_D16_LOCKABLE: return WINED3DFMT_D16_LOCKABLE;
132 case D3DFMT_D32: return WINED3DFMT_D32;
133 case D3DFMT_D15S1: return WINED3DFMT_D15S1;
134 case D3DFMT_D24S8: return WINED3DFMT_D24S8;
135 case D3DFMT_D24X8: return WINED3DFMT_D24X8;
136 case D3DFMT_D24X4S4: return WINED3DFMT_D24X4S4;
137 case D3DFMT_D16: return WINED3DFMT_D16_UNORM;
138 case D3DFMT_L16: return WINED3DFMT_L16;
139 case D3DFMT_D32F_LOCKABLE: return WINED3DFMT_D32F_LOCKABLE;
140 case D3DFMT_D24FS8: return WINED3DFMT_D24FS8;
141 case D3DFMT_VERTEXDATA: return WINED3DFMT_VERTEXDATA;
142 case D3DFMT_INDEX16: return WINED3DFMT_R16_UINT;
143 case D3DFMT_INDEX32: return WINED3DFMT_R32_UINT;
144 case D3DFMT_Q16W16V16U16: return WINED3DFMT_R16G16B16A16_SNORM;
145 case D3DFMT_R16F: return WINED3DFMT_R16_FLOAT;
146 case D3DFMT_G16R16F: return WINED3DFMT_R16G16_FLOAT;
147 case D3DFMT_A16B16G16R16F: return WINED3DFMT_R16G16B16A16_FLOAT;
148 case D3DFMT_R32F: return WINED3DFMT_R32_FLOAT;
149 case D3DFMT_G32R32F: return WINED3DFMT_R32G32_FLOAT;
150 case D3DFMT_A32B32G32R32F: return WINED3DFMT_R32G32B32A32_FLOAT;
151 case D3DFMT_CxV8U8: return WINED3DFMT_CxV8U8;
152 default:
153 FIXME("Unhandled D3DFORMAT %#x\n", format);
154 return WINED3DFMT_UNKNOWN;
158 /* IDirect3D IUnknown parts follow: */
159 static HRESULT WINAPI IDirect3DDevice9Impl_QueryInterface(LPDIRECT3DDEVICE9EX iface, REFIID riid, LPVOID* ppobj) {
160 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
161 IDirect3D9 *d3d;
162 IDirect3D9Impl *d3dimpl;
164 if (IsEqualGUID(riid, &IID_IUnknown)
165 || IsEqualGUID(riid, &IID_IDirect3DDevice9)) {
166 IDirect3DDevice9Ex_AddRef(iface);
167 *ppobj = This;
168 TRACE("Returning IDirect3DDevice9 interface at %p\n", *ppobj);
169 return S_OK;
170 } else if(IsEqualGUID(riid, &IID_IDirect3DDevice9Ex)) {
171 /* Find out if the creating d3d9 interface was created with Direct3DCreate9Ex.
172 * It doesn't matter with which function the device was created.
174 IDirect3DDevice9_GetDirect3D(iface, &d3d);
175 d3dimpl = (IDirect3D9Impl *) d3d;
177 if(d3dimpl->extended) {
178 *ppobj = iface;
179 IDirect3DDevice9Ex_AddRef((IDirect3DDevice9Ex *) *ppobj);
180 IDirect3D9_Release(d3d);
181 TRACE("Returning IDirect3DDevice9Ex interface at %p\n", *ppobj);
182 return S_OK;
183 } else {
184 WARN("IDirect3D9 instance wasn't created with CreateDirect3D9Ex, returning E_NOINTERFACE\n");
185 IDirect3D9_Release(d3d);
186 *ppobj = NULL;
187 return E_NOINTERFACE;
191 if (IsEqualGUID(riid, &IID_IWineD3DDeviceParent))
193 IUnknown_AddRef((IUnknown *)&This->device_parent_vtbl);
194 *ppobj = &This->device_parent_vtbl;
195 return S_OK;
198 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
199 *ppobj = NULL;
200 return E_NOINTERFACE;
203 static ULONG WINAPI IDirect3DDevice9Impl_AddRef(LPDIRECT3DDEVICE9EX iface) {
204 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
205 ULONG ref = InterlockedIncrement(&This->ref);
207 TRACE("(%p) : AddRef from %d\n", This, ref - 1);
209 return ref;
212 static ULONG WINAPI IDirect3DDevice9Impl_Release(LPDIRECT3DDEVICE9EX iface) {
213 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
214 ULONG ref;
216 if (This->inDestruction) return 0;
217 ref = InterlockedDecrement(&This->ref);
219 TRACE("(%p) : ReleaseRef to %d\n", This, ref);
221 if (ref == 0) {
222 unsigned i;
223 This->inDestruction = TRUE;
225 EnterCriticalSection(&d3d9_cs);
226 for(i = 0; i < This->numConvertedDecls; i++) {
227 /* Unless Wine is buggy or the app has a bug the refcount will be 0, because decls hold a reference to the
228 * device
230 IDirect3DVertexDeclaration9Impl_Destroy(This->convertedDecls[i]);
232 HeapFree(GetProcessHeap(), 0, This->convertedDecls);
234 IWineD3DDevice_Uninit3D(This->WineD3DDevice, D3D9CB_DestroyDepthStencilSurface, D3D9CB_DestroySwapChain);
235 IWineD3DDevice_Release(This->WineD3DDevice);
236 LeaveCriticalSection(&d3d9_cs);
237 HeapFree(GetProcessHeap(), 0, This);
239 return ref;
242 /* IDirect3DDevice Interface follow: */
243 static HRESULT WINAPI IDirect3DDevice9Impl_TestCooperativeLevel(LPDIRECT3DDEVICE9EX iface) {
244 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
245 HRESULT hr;
246 TRACE("(%p)\n", This);
248 EnterCriticalSection(&d3d9_cs);
249 hr = IWineD3DDevice_TestCooperativeLevel(This->WineD3DDevice);
250 LeaveCriticalSection(&d3d9_cs);
251 if(hr == WINED3D_OK && This->notreset) {
252 TRACE("D3D9 Device is marked not reset\n");
253 hr = D3DERR_DEVICENOTRESET;
256 return hr;
259 static UINT WINAPI IDirect3DDevice9Impl_GetAvailableTextureMem(LPDIRECT3DDEVICE9EX iface) {
260 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
261 HRESULT hr;
262 TRACE("(%p) Relay\n", This);
264 EnterCriticalSection(&d3d9_cs);
265 hr = IWineD3DDevice_GetAvailableTextureMem(This->WineD3DDevice);
266 LeaveCriticalSection(&d3d9_cs);
267 return hr;
270 static HRESULT WINAPI IDirect3DDevice9Impl_EvictManagedResources(LPDIRECT3DDEVICE9EX iface) {
271 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
272 HRESULT hr;
273 TRACE("(%p) : Relay\n", This);
275 EnterCriticalSection(&d3d9_cs);
276 hr = IWineD3DDevice_EvictManagedResources(This->WineD3DDevice);
277 LeaveCriticalSection(&d3d9_cs);
278 return hr;
281 static HRESULT WINAPI IDirect3DDevice9Impl_GetDirect3D(LPDIRECT3DDEVICE9EX iface, IDirect3D9** ppD3D9) {
282 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
283 HRESULT hr = D3D_OK;
284 IWineD3D* pWineD3D;
286 TRACE("(%p) Relay\n", This);
288 if (NULL == ppD3D9) {
289 return D3DERR_INVALIDCALL;
292 EnterCriticalSection(&d3d9_cs);
293 hr = IWineD3DDevice_GetDirect3D(This->WineD3DDevice, &pWineD3D);
294 if (hr == D3D_OK && pWineD3D != NULL)
296 IWineD3D_GetParent(pWineD3D,(IUnknown **)ppD3D9);
297 IWineD3D_Release(pWineD3D);
298 } else {
299 FIXME("Call to IWineD3DDevice_GetDirect3D failed\n");
300 *ppD3D9 = NULL;
302 TRACE("(%p) returning %p\n", This, *ppD3D9);
303 LeaveCriticalSection(&d3d9_cs);
304 return hr;
307 static HRESULT WINAPI IDirect3DDevice9Impl_GetDeviceCaps(LPDIRECT3DDEVICE9EX iface, D3DCAPS9* pCaps) {
308 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
309 HRESULT hrc = D3D_OK;
310 WINED3DCAPS *pWineCaps;
312 TRACE("(%p) : Relay pCaps %p\n", This, pCaps);
313 if(NULL == pCaps){
314 return D3DERR_INVALIDCALL;
316 pWineCaps = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WINED3DCAPS));
317 if(pWineCaps == NULL){
318 return D3DERR_INVALIDCALL; /* well this is what MSDN says to return */
321 memset(pCaps, 0, sizeof(*pCaps));
322 EnterCriticalSection(&d3d9_cs);
323 hrc = IWineD3DDevice_GetDeviceCaps(This->WineD3DDevice, pWineCaps);
324 LeaveCriticalSection(&d3d9_cs);
325 WINECAPSTOD3D9CAPS(pCaps, pWineCaps)
326 HeapFree(GetProcessHeap(), 0, pWineCaps);
328 /* Some functionality is implemented in d3d9.dll, not wined3d.dll. Add the needed caps */
329 pCaps->DevCaps2 |= D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES;
331 filter_caps(pCaps);
333 TRACE("Returning %p %p\n", This, pCaps);
334 return hrc;
337 static HRESULT WINAPI IDirect3DDevice9Impl_GetDisplayMode(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain, D3DDISPLAYMODE* pMode) {
338 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
339 HRESULT hr;
340 TRACE("(%p) Relay\n", This);
342 EnterCriticalSection(&d3d9_cs);
343 hr = IWineD3DDevice_GetDisplayMode(This->WineD3DDevice, iSwapChain, (WINED3DDISPLAYMODE *) pMode);
344 LeaveCriticalSection(&d3d9_cs);
346 if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format);
348 return hr;
351 static HRESULT WINAPI IDirect3DDevice9Impl_GetCreationParameters(LPDIRECT3DDEVICE9EX iface, D3DDEVICE_CREATION_PARAMETERS *pParameters) {
352 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
353 HRESULT hr;
354 TRACE("(%p) Relay\n", This);
356 EnterCriticalSection(&d3d9_cs);
357 hr = IWineD3DDevice_GetCreationParameters(This->WineD3DDevice, (WINED3DDEVICE_CREATION_PARAMETERS *) pParameters);
358 LeaveCriticalSection(&d3d9_cs);
359 return hr;
362 static HRESULT WINAPI IDirect3DDevice9Impl_SetCursorProperties(LPDIRECT3DDEVICE9EX iface, UINT XHotSpot, UINT YHotSpot, IDirect3DSurface9* pCursorBitmap) {
363 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
364 IDirect3DSurface9Impl *pSurface = (IDirect3DSurface9Impl*)pCursorBitmap;
365 HRESULT hr;
367 TRACE("(%p) Relay\n", This);
368 if(!pCursorBitmap) {
369 WARN("No cursor bitmap, returning WINED3DERR_INVALIDCALL\n");
370 return WINED3DERR_INVALIDCALL;
373 EnterCriticalSection(&d3d9_cs);
374 hr = IWineD3DDevice_SetCursorProperties(This->WineD3DDevice, XHotSpot, YHotSpot, pSurface->wineD3DSurface);
375 LeaveCriticalSection(&d3d9_cs);
376 return hr;
379 static void WINAPI IDirect3DDevice9Impl_SetCursorPosition(LPDIRECT3DDEVICE9EX iface, int XScreenSpace, int YScreenSpace, DWORD Flags) {
380 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
381 TRACE("(%p) Relay\n", This);
383 EnterCriticalSection(&d3d9_cs);
384 IWineD3DDevice_SetCursorPosition(This->WineD3DDevice, XScreenSpace, YScreenSpace, Flags);
385 LeaveCriticalSection(&d3d9_cs);
388 static BOOL WINAPI IDirect3DDevice9Impl_ShowCursor(LPDIRECT3DDEVICE9EX iface, BOOL bShow) {
389 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
390 BOOL ret;
391 TRACE("(%p) Relay\n", This);
393 EnterCriticalSection(&d3d9_cs);
394 ret = IWineD3DDevice_ShowCursor(This->WineD3DDevice, bShow);
395 LeaveCriticalSection(&d3d9_cs);
396 return ret;
399 static HRESULT WINAPI reset_enum_callback(IWineD3DResource *resource, void *data) {
400 BOOL *resources_ok = data;
401 WINED3DRESOURCETYPE type;
402 HRESULT ret = S_OK;
403 WINED3DSURFACE_DESC surface_desc;
404 WINED3DVOLUME_DESC volume_desc;
405 WINED3DINDEXBUFFER_DESC index_desc;
406 WINED3DVERTEXBUFFER_DESC vertex_desc;
407 WINED3DFORMAT dummy_format;
408 WINED3DMULTISAMPLE_TYPE dummy_multisampletype;
409 DWORD dummy_dword;
410 WINED3DPOOL pool = WINED3DPOOL_SCRATCH; /* a harmless pool */
411 IUnknown *parent;
413 type = IWineD3DResource_GetType(resource);
414 switch(type) {
415 case WINED3DRTYPE_SURFACE:
416 surface_desc.Format = &dummy_format;
417 surface_desc.Type = &type;
418 surface_desc.Usage = &dummy_dword;
419 surface_desc.Pool = &pool;
420 surface_desc.Size = &dummy_dword;
421 surface_desc.MultiSampleType = &dummy_multisampletype;
422 surface_desc.MultiSampleQuality = &dummy_dword;
423 surface_desc.Width = &dummy_dword;
424 surface_desc.Height = &dummy_dword;
426 IWineD3DSurface_GetDesc((IWineD3DSurface *) resource, &surface_desc);
427 break;
429 case WINED3DRTYPE_VOLUME:
430 volume_desc.Format = &dummy_format;
431 volume_desc.Type = &type;
432 volume_desc.Usage = &dummy_dword;
433 volume_desc.Pool = &pool;
434 volume_desc.Size = &dummy_dword;
435 volume_desc.Width = &dummy_dword;
436 volume_desc.Height = &dummy_dword;
437 volume_desc.Depth = &dummy_dword;
438 IWineD3DVolume_GetDesc((IWineD3DVolume *) resource, &volume_desc);
439 break;
441 case WINED3DRTYPE_INDEXBUFFER:
442 IWineD3DIndexBuffer_GetDesc((IWineD3DIndexBuffer *) resource, &index_desc);
443 pool = index_desc.Pool;
444 break;
446 case WINED3DRTYPE_VERTEXBUFFER:
447 IWineD3DVertexBuffer_GetDesc((IWineD3DVertexBuffer *) resource, &vertex_desc);
448 pool = vertex_desc.Pool;
449 break;
451 /* No need to check for textures. If there is a D3DPOOL_DEFAULT texture, there
452 * is a D3DPOOL_DEFAULT surface or volume as well
454 default:
455 break;
458 if(pool == WINED3DPOOL_DEFAULT) {
459 IWineD3DResource_GetParent(resource, &parent);
460 if(IUnknown_Release(parent) == 0) {
461 TRACE("Parent %p is an implicit resource with ref 0\n", parent);
462 } else {
463 WARN("Resource %p(wineD3D %p) with pool D3DPOOL_DEFAULT blocks the Reset call\n", parent, resource);
464 ret = S_FALSE;
465 *resources_ok = FALSE;
468 IWineD3DResource_Release(resource);
470 return ret;
473 static HRESULT WINAPI IDirect3DDevice9Impl_Reset(LPDIRECT3DDEVICE9EX iface, D3DPRESENT_PARAMETERS* pPresentationParameters) {
474 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
475 WINED3DPRESENT_PARAMETERS localParameters;
476 HRESULT hr;
477 BOOL resources_ok = TRUE;
478 UINT i;
480 TRACE("(%p) Relay pPresentationParameters(%p)\n", This, pPresentationParameters);
482 /* Reset states that hold a COM object. WineD3D holds an internal reference to set objects, because
483 * such objects can still be used for rendering after their external d3d9 object has been destroyed.
484 * These objects must not be enumerated. Unsetting them tells WineD3D that the application will not
485 * make use of the hidden reference and destroys the objects.
487 * Unsetting them is no problem, because the states are supposed to be reset anyway. If the validation
488 * below fails, the device is considered "lost", and _Reset and _Release are the only allowed calls
490 IWineD3DDevice_SetIndices(This->WineD3DDevice, NULL);
491 for(i = 0; i < 16; i++) {
492 IWineD3DDevice_SetStreamSource(This->WineD3DDevice, i, NULL, 0, 0);
494 for(i = 0; i < 16; i++) {
495 IWineD3DDevice_SetTexture(This->WineD3DDevice, i, NULL);
498 IWineD3DDevice_EnumResources(This->WineD3DDevice, reset_enum_callback, &resources_ok);
499 if(!resources_ok) {
500 WARN("The application is holding D3DPOOL_DEFAULT resources, rejecting reset\n");
501 This->notreset = TRUE;
502 return WINED3DERR_INVALIDCALL;
505 localParameters.BackBufferWidth = pPresentationParameters->BackBufferWidth;
506 localParameters.BackBufferHeight = pPresentationParameters->BackBufferHeight;
507 localParameters.BackBufferFormat = wined3dformat_from_d3dformat(pPresentationParameters->BackBufferFormat);
508 localParameters.BackBufferCount = pPresentationParameters->BackBufferCount;
509 localParameters.MultiSampleType = pPresentationParameters->MultiSampleType;
510 localParameters.MultiSampleQuality = pPresentationParameters->MultiSampleQuality;
511 localParameters.SwapEffect = pPresentationParameters->SwapEffect;
512 localParameters.hDeviceWindow = pPresentationParameters->hDeviceWindow;
513 localParameters.Windowed = pPresentationParameters->Windowed;
514 localParameters.EnableAutoDepthStencil = pPresentationParameters->EnableAutoDepthStencil;
515 localParameters.AutoDepthStencilFormat = wined3dformat_from_d3dformat(pPresentationParameters->AutoDepthStencilFormat);
516 localParameters.Flags = pPresentationParameters->Flags;
517 localParameters.FullScreen_RefreshRateInHz = pPresentationParameters->FullScreen_RefreshRateInHz;
518 localParameters.PresentationInterval = pPresentationParameters->PresentationInterval;
519 localParameters.AutoRestoreDisplayMode = TRUE;
521 EnterCriticalSection(&d3d9_cs);
522 hr = IWineD3DDevice_Reset(This->WineD3DDevice, &localParameters);
523 LeaveCriticalSection(&d3d9_cs);
524 if(FAILED(hr)) {
525 This->notreset = TRUE;
527 pPresentationParameters->BackBufferWidth = localParameters.BackBufferWidth;
528 pPresentationParameters->BackBufferHeight = localParameters.BackBufferHeight;
529 pPresentationParameters->BackBufferFormat = d3dformat_from_wined3dformat(localParameters.BackBufferFormat);
530 pPresentationParameters->BackBufferCount = localParameters.BackBufferCount;
531 pPresentationParameters->MultiSampleType = localParameters.MultiSampleType;
532 pPresentationParameters->MultiSampleQuality = localParameters.MultiSampleQuality;
533 pPresentationParameters->SwapEffect = localParameters.SwapEffect;
534 pPresentationParameters->hDeviceWindow = localParameters.hDeviceWindow;
535 pPresentationParameters->Windowed = localParameters.Windowed;
536 pPresentationParameters->EnableAutoDepthStencil = localParameters.EnableAutoDepthStencil;
537 pPresentationParameters->AutoDepthStencilFormat = d3dformat_from_wined3dformat(localParameters.AutoDepthStencilFormat);
538 pPresentationParameters->Flags = localParameters.Flags;
539 pPresentationParameters->FullScreen_RefreshRateInHz = localParameters.FullScreen_RefreshRateInHz;
540 pPresentationParameters->PresentationInterval = localParameters.PresentationInterval;
541 } else {
542 This->notreset = FALSE;
545 return hr;
548 static HRESULT WINAPI IDirect3DDevice9Impl_Present(LPDIRECT3DDEVICE9EX iface, CONST RECT* pSourceRect,CONST RECT* pDestRect,HWND hDestWindowOverride,CONST RGNDATA*
549 pDirtyRegion) {
550 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
551 HRESULT hr;
552 TRACE("(%p) Relay\n", This);
554 EnterCriticalSection(&d3d9_cs);
555 hr = IWineD3DDevice_Present(This->WineD3DDevice, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
556 LeaveCriticalSection(&d3d9_cs);
557 return hr;
560 static HRESULT WINAPI IDirect3DDevice9Impl_GetBackBuffer(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain, UINT BackBuffer, D3DBACKBUFFER_TYPE Type, IDirect3DSurface9 ** ppBackBuffer) {
561 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
562 IWineD3DSurface *retSurface = NULL;
563 HRESULT rc = D3D_OK;
565 TRACE("(%p) Relay\n", This);
567 EnterCriticalSection(&d3d9_cs);
568 rc = IWineD3DDevice_GetBackBuffer(This->WineD3DDevice, iSwapChain, BackBuffer, (WINED3DBACKBUFFER_TYPE) Type, &retSurface);
569 if (rc == D3D_OK && NULL != retSurface && NULL != ppBackBuffer) {
570 IWineD3DSurface_GetParent(retSurface, (IUnknown **)ppBackBuffer);
571 IWineD3DSurface_Release(retSurface);
573 LeaveCriticalSection(&d3d9_cs);
574 return rc;
576 static HRESULT WINAPI IDirect3DDevice9Impl_GetRasterStatus(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain, D3DRASTER_STATUS* pRasterStatus) {
577 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
578 HRESULT hr;
579 TRACE("(%p) Relay\n", This);
581 EnterCriticalSection(&d3d9_cs);
582 hr = IWineD3DDevice_GetRasterStatus(This->WineD3DDevice, iSwapChain, (WINED3DRASTER_STATUS *) pRasterStatus);
583 LeaveCriticalSection(&d3d9_cs);
584 return hr;
587 static HRESULT WINAPI IDirect3DDevice9Impl_SetDialogBoxMode(LPDIRECT3DDEVICE9EX iface, BOOL bEnableDialogs) {
588 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
589 HRESULT hr;
590 TRACE("(%p) Relay\n", This);
592 EnterCriticalSection(&d3d9_cs);
593 hr = IWineD3DDevice_SetDialogBoxMode(This->WineD3DDevice, bEnableDialogs);
594 LeaveCriticalSection(&d3d9_cs);
595 return hr;
598 static void WINAPI IDirect3DDevice9Impl_SetGammaRamp(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain, DWORD Flags, CONST D3DGAMMARAMP* pRamp) {
600 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
601 TRACE("(%p) Relay\n", This);
603 EnterCriticalSection(&d3d9_cs);
604 /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
605 IWineD3DDevice_SetGammaRamp(This->WineD3DDevice, iSwapChain, Flags, (CONST WINED3DGAMMARAMP *)pRamp);
606 LeaveCriticalSection(&d3d9_cs);
609 static void WINAPI IDirect3DDevice9Impl_GetGammaRamp(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain, D3DGAMMARAMP* pRamp) {
610 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
611 TRACE("(%p) Relay\n", This);
613 EnterCriticalSection(&d3d9_cs);
614 /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
615 IWineD3DDevice_GetGammaRamp(This->WineD3DDevice, iSwapChain, (WINED3DGAMMARAMP *) pRamp);
616 LeaveCriticalSection(&d3d9_cs);
620 static HRESULT IDirect3DDevice9Impl_CreateSurface(LPDIRECT3DDEVICE9EX iface, UINT Width, UINT Height, D3DFORMAT Format, BOOL Lockable, BOOL Discard, UINT Level, IDirect3DSurface9 **ppSurface,D3DRESOURCETYPE Type, UINT Usage, D3DPOOL Pool, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality,HANDLE* pSharedHandle ) {
621 HRESULT hrc;
622 IDirect3DSurface9Impl *object;
623 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
624 TRACE("(%p) Relay\n", This);
626 if(MultisampleQuality > 0){
627 FIXME("MultisampleQuality set to %d, bstituting 0\n", MultisampleQuality);
629 MultisampleQuality
630 [in] Quality level. The valid range is between zero and one less than the level returned by pQualityLevels used by IDirect3D9::CheckDeviceMultiSampleType. Passing a larger value returns the error D3DERR_INVALIDCALL. The MultisampleQuality values of paired render targets, depth stencil surfaces, and the MultiSample type must all match.
633 MultisampleQuality=0;
635 /*FIXME: Check MAX bounds of MultisampleQuality*/
637 /* Allocate the storage for the device */
638 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DSurface9Impl));
639 if (NULL == object) {
640 FIXME("Allocation of memory failed\n");
641 return D3DERR_OUTOFVIDEOMEMORY;
644 object->lpVtbl = &Direct3DSurface9_Vtbl;
645 object->ref = 1;
647 TRACE("(%p) : w(%d) h(%d) fmt(%d) surf@%p\n", This, Width, Height, Format, *ppSurface);
649 hrc = IWineD3DDevice_CreateSurface(This->WineD3DDevice, Width, Height, wined3dformat_from_d3dformat(Format),
650 Lockable, Discard, Level, &object->wineD3DSurface, Type, Usage & WINED3DUSAGE_MASK, (WINED3DPOOL)Pool,
651 MultiSample, MultisampleQuality, pSharedHandle, SURFACE_OPENGL, (IUnknown *)object);
653 if (hrc != D3D_OK || NULL == object->wineD3DSurface) {
655 /* free up object */
656 FIXME("(%p) call to IWineD3DDevice_CreateSurface failed\n", This);
657 HeapFree(GetProcessHeap(), 0, object);
658 } else {
659 IDirect3DDevice9Ex_AddRef(iface);
660 object->parentDevice = iface;
661 TRACE("(%p) : Created surface %p\n", This, object);
662 *ppSurface = (LPDIRECT3DSURFACE9) object;
664 return hrc;
669 static HRESULT WINAPI IDirect3DDevice9Impl_CreateRenderTarget(LPDIRECT3DDEVICE9EX iface, UINT Width, UINT Height,
670 D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample,
671 DWORD MultisampleQuality, BOOL Lockable,
672 IDirect3DSurface9 **ppSurface, HANDLE* pSharedHandle) {
673 HRESULT hr;
674 TRACE("Relay\n");
676 /* Is this correct? */
677 EnterCriticalSection(&d3d9_cs);
678 hr = IDirect3DDevice9Impl_CreateSurface(iface,Width,Height,Format,Lockable,FALSE/*Discard*/, 0/*Level*/, ppSurface,D3DRTYPE_SURFACE,D3DUSAGE_RENDERTARGET,D3DPOOL_DEFAULT,MultiSample,MultisampleQuality,pSharedHandle);
679 LeaveCriticalSection(&d3d9_cs);
680 return hr;
683 static HRESULT WINAPI IDirect3DDevice9Impl_CreateDepthStencilSurface(LPDIRECT3DDEVICE9EX iface, UINT Width, UINT Height,
684 D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample,
685 DWORD MultisampleQuality, BOOL Discard,
686 IDirect3DSurface9 **ppSurface, HANDLE* pSharedHandle) {
687 HRESULT hr;
688 TRACE("Relay\n");
690 EnterCriticalSection(&d3d9_cs);
691 hr = IDirect3DDevice9Impl_CreateSurface(iface,Width,Height,Format,TRUE/* Lockable */,Discard, 0/* Level */
692 ,ppSurface,D3DRTYPE_SURFACE,D3DUSAGE_DEPTHSTENCIL,
693 D3DPOOL_DEFAULT,MultiSample,MultisampleQuality,pSharedHandle);
694 LeaveCriticalSection(&d3d9_cs);
695 return hr;
699 static HRESULT WINAPI IDirect3DDevice9Impl_UpdateSurface(LPDIRECT3DDEVICE9EX iface, IDirect3DSurface9* pSourceSurface, CONST RECT* pSourceRect, IDirect3DSurface9* pDestinationSurface, CONST POINT* pDestPoint) {
700 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
701 HRESULT hr;
702 TRACE("(%p) Relay\n" , This);
704 EnterCriticalSection(&d3d9_cs);
705 hr = IWineD3DDevice_UpdateSurface(This->WineD3DDevice, ((IDirect3DSurface9Impl *)pSourceSurface)->wineD3DSurface, pSourceRect, ((IDirect3DSurface9Impl *)pDestinationSurface)->wineD3DSurface, pDestPoint);
706 LeaveCriticalSection(&d3d9_cs);
707 return hr;
710 static HRESULT WINAPI IDirect3DDevice9Impl_UpdateTexture(LPDIRECT3DDEVICE9EX iface, IDirect3DBaseTexture9* pSourceTexture, IDirect3DBaseTexture9* pDestinationTexture) {
711 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
712 HRESULT hr;
713 TRACE("(%p) Relay\n" , This);
715 EnterCriticalSection(&d3d9_cs);
716 hr = IWineD3DDevice_UpdateTexture(This->WineD3DDevice, ((IDirect3DBaseTexture9Impl *)pSourceTexture)->wineD3DBaseTexture, ((IDirect3DBaseTexture9Impl *)pDestinationTexture)->wineD3DBaseTexture);
717 LeaveCriticalSection(&d3d9_cs);
718 return hr;
721 static HRESULT WINAPI IDirect3DDevice9Impl_GetRenderTargetData(LPDIRECT3DDEVICE9EX iface, IDirect3DSurface9* pRenderTarget, IDirect3DSurface9* pDestSurface) {
722 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
723 IDirect3DSurface9Impl *renderTarget = (IDirect3DSurface9Impl *)pRenderTarget;
724 IDirect3DSurface9Impl *destSurface = (IDirect3DSurface9Impl *)pDestSurface;
725 HRESULT hr;
726 TRACE("(%p)->(%p,%p)\n" , This, renderTarget, destSurface);
728 EnterCriticalSection(&d3d9_cs);
729 hr = IWineD3DSurface_BltFast(destSurface->wineD3DSurface, 0, 0, renderTarget->wineD3DSurface, NULL, WINEDDBLTFAST_NOCOLORKEY);
730 LeaveCriticalSection(&d3d9_cs);
731 return hr;
734 static HRESULT WINAPI IDirect3DDevice9Impl_GetFrontBufferData(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain, IDirect3DSurface9* pDestSurface) {
735 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
736 IDirect3DSurface9Impl *destSurface = (IDirect3DSurface9Impl *)pDestSurface;
737 HRESULT hr;
738 TRACE("(%p) Relay\n" , This);
740 EnterCriticalSection(&d3d9_cs);
741 hr = IWineD3DDevice_GetFrontBufferData(This->WineD3DDevice, iSwapChain, destSurface->wineD3DSurface);
742 LeaveCriticalSection(&d3d9_cs);
743 return hr;
746 static HRESULT WINAPI IDirect3DDevice9Impl_StretchRect(LPDIRECT3DDEVICE9EX iface, IDirect3DSurface9* pSourceSurface, CONST RECT* pSourceRect, IDirect3DSurface9* pDestSurface, CONST RECT* pDestRect, D3DTEXTUREFILTERTYPE Filter) {
747 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
748 IDirect3DSurface9Impl *src = (IDirect3DSurface9Impl *) pSourceSurface;
749 IDirect3DSurface9Impl *dst = (IDirect3DSurface9Impl *) pDestSurface;
750 HRESULT hr;
752 TRACE("(%p)->(%p,%p,%p,%p,%d)\n" , This, src, pSourceRect, dst, pDestRect, Filter);
753 EnterCriticalSection(&d3d9_cs);
754 hr = IWineD3DSurface_Blt(dst->wineD3DSurface, pDestRect, src->wineD3DSurface, pSourceRect, 0, NULL, Filter);
755 LeaveCriticalSection(&d3d9_cs);
756 return hr;
759 static HRESULT WINAPI IDirect3DDevice9Impl_ColorFill(LPDIRECT3DDEVICE9EX iface, IDirect3DSurface9* pSurface, CONST RECT* pRect, D3DCOLOR color) {
760 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
761 IDirect3DSurface9Impl *surface = (IDirect3DSurface9Impl *)pSurface;
762 WINED3DPOOL pool;
763 WINED3DRESOURCETYPE restype;
764 DWORD usage;
765 WINED3DSURFACE_DESC desc;
766 HRESULT hr;
767 TRACE("(%p) Relay\n" , This);
769 memset(&desc, 0, sizeof(desc));
770 desc.Usage = &usage;
771 desc.Pool = &pool;
772 desc.Type = &restype;
773 IWineD3DSurface_GetDesc(surface->wineD3DSurface, &desc);
775 /* This method is only allowed with surfaces that are render targets, or offscreen plain surfaces
776 * in D3DPOOL_DEFAULT
778 if(!(usage & WINED3DUSAGE_RENDERTARGET) && (pool != D3DPOOL_DEFAULT || restype != D3DRTYPE_SURFACE)) {
779 WARN("Surface is not a render target, or not a stand-alone D3DPOOL_DEFAULT surface\n");
780 return D3DERR_INVALIDCALL;
783 /* Colorfill can only be used on rendertarget surfaces, or offscreen plain surfaces in D3DPOOL_DEFAULT */
784 /* Note: D3DRECT is compatible with WINED3DRECT */
785 EnterCriticalSection(&d3d9_cs);
786 hr = IWineD3DDevice_ColorFill(This->WineD3DDevice, surface->wineD3DSurface, (CONST WINED3DRECT*)pRect, color);
787 LeaveCriticalSection(&d3d9_cs);
788 return hr;
791 static HRESULT WINAPI IDirect3DDevice9Impl_CreateOffscreenPlainSurface(LPDIRECT3DDEVICE9EX iface, UINT Width, UINT Height, D3DFORMAT Format, D3DPOOL Pool, IDirect3DSurface9 **ppSurface, HANDLE* pSharedHandle) {
792 HRESULT hr;
793 TRACE("Relay\n");
794 if(Pool == D3DPOOL_MANAGED ){
795 FIXME("Attempting to create a managed offscreen plain surface\n");
796 return D3DERR_INVALIDCALL;
799 'Off-screen plain surfaces are always lockable, regardless of their pool types.'
800 but then...
801 D3DPOOL_DEFAULT is the appropriate pool for use with the IDirect3DDevice9::StretchRect and IDirect3DDevice9::ColorFill.
802 Why, their always lockable?
803 should I change the usage to dynamic?
805 EnterCriticalSection(&d3d9_cs);
806 hr = IDirect3DDevice9Impl_CreateSurface(iface,Width,Height,Format,TRUE/*Loackable*/,FALSE/*Discard*/,0/*Level*/ , ppSurface,D3DRTYPE_SURFACE, 0/*Usage (undefined/none)*/,(WINED3DPOOL) Pool,D3DMULTISAMPLE_NONE,0/*MultisampleQuality*/,pSharedHandle);
807 LeaveCriticalSection(&d3d9_cs);
808 return hr;
811 /* TODO: move to wineD3D */
812 static HRESULT WINAPI IDirect3DDevice9Impl_SetRenderTarget(LPDIRECT3DDEVICE9EX iface, DWORD RenderTargetIndex, IDirect3DSurface9* pRenderTarget) {
813 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
814 IDirect3DSurface9Impl *pSurface = (IDirect3DSurface9Impl*)pRenderTarget;
815 HRESULT hr;
816 TRACE("(%p) Relay\n" , This);
818 EnterCriticalSection(&d3d9_cs);
819 hr = IWineD3DDevice_SetRenderTarget(This->WineD3DDevice, RenderTargetIndex, pSurface ? pSurface->wineD3DSurface : NULL);
820 LeaveCriticalSection(&d3d9_cs);
821 return hr;
824 static HRESULT WINAPI IDirect3DDevice9Impl_GetRenderTarget(LPDIRECT3DDEVICE9EX iface, DWORD RenderTargetIndex, IDirect3DSurface9 **ppRenderTarget) {
825 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
826 HRESULT hr = D3D_OK;
827 IWineD3DSurface *pRenderTarget;
829 TRACE("(%p) Relay\n" , This);
831 if (ppRenderTarget == NULL) {
832 return D3DERR_INVALIDCALL;
835 EnterCriticalSection(&d3d9_cs);
836 hr=IWineD3DDevice_GetRenderTarget(This->WineD3DDevice,RenderTargetIndex,&pRenderTarget);
838 if (hr == D3D_OK && pRenderTarget != NULL) {
839 IWineD3DSurface_GetParent(pRenderTarget,(IUnknown**)ppRenderTarget);
840 IWineD3DSurface_Release(pRenderTarget);
841 } else {
842 FIXME("Call to IWineD3DDevice_GetRenderTarget failed\n");
843 *ppRenderTarget = NULL;
845 LeaveCriticalSection(&d3d9_cs);
847 return hr;
850 static HRESULT WINAPI IDirect3DDevice9Impl_SetDepthStencilSurface(LPDIRECT3DDEVICE9EX iface, IDirect3DSurface9* pZStencilSurface) {
851 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
852 IDirect3DSurface9Impl *pSurface;
853 HRESULT hr;
854 TRACE("(%p) Relay\n" , This);
856 pSurface = (IDirect3DSurface9Impl*)pZStencilSurface;
857 EnterCriticalSection(&d3d9_cs);
858 hr = IWineD3DDevice_SetDepthStencilSurface(This->WineD3DDevice, NULL==pSurface ? NULL : pSurface->wineD3DSurface);
859 LeaveCriticalSection(&d3d9_cs);
860 return hr;
863 static HRESULT WINAPI IDirect3DDevice9Impl_GetDepthStencilSurface(LPDIRECT3DDEVICE9EX iface, IDirect3DSurface9 **ppZStencilSurface) {
864 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
865 HRESULT hr = D3D_OK;
866 IWineD3DSurface *pZStencilSurface;
868 TRACE("(%p) Relay\n" , This);
869 if(ppZStencilSurface == NULL){
870 return D3DERR_INVALIDCALL;
873 EnterCriticalSection(&d3d9_cs);
874 hr = IWineD3DDevice_GetDepthStencilSurface(This->WineD3DDevice,&pZStencilSurface);
875 if (hr == WINED3D_OK) {
876 IWineD3DSurface_GetParent(pZStencilSurface,(IUnknown**)ppZStencilSurface);
877 IWineD3DSurface_Release(pZStencilSurface);
878 } else {
879 if (hr != WINED3DERR_NOTFOUND)
880 WARN("Call to IWineD3DDevice_GetDepthStencilSurface failed with 0x%08x\n", hr);
881 *ppZStencilSurface = NULL;
883 LeaveCriticalSection(&d3d9_cs);
884 return hr;
887 static HRESULT WINAPI IDirect3DDevice9Impl_BeginScene(LPDIRECT3DDEVICE9EX iface) {
888 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
889 HRESULT hr;
890 TRACE("(%p) Relay\n" , This);
892 EnterCriticalSection(&d3d9_cs);
893 hr = IWineD3DDevice_BeginScene(This->WineD3DDevice);
894 LeaveCriticalSection(&d3d9_cs);
895 return hr;
898 static HRESULT WINAPI IDirect3DDevice9Impl_EndScene(LPDIRECT3DDEVICE9EX iface) {
899 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
900 HRESULT hr;
901 TRACE("(%p) Relay\n" , This);
903 EnterCriticalSection(&d3d9_cs);
904 hr = IWineD3DDevice_EndScene(This->WineD3DDevice);
905 LeaveCriticalSection(&d3d9_cs);
906 return hr;
909 static HRESULT WINAPI IDirect3DDevice9Impl_Clear(LPDIRECT3DDEVICE9EX iface, DWORD Count, CONST D3DRECT* pRects, DWORD Flags, D3DCOLOR Color, float Z, DWORD Stencil) {
910 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
911 HRESULT hr;
912 TRACE("(%p) Relay\n" , This);
914 /* Note: D3DRECT is compatible with WINED3DRECT */
915 EnterCriticalSection(&d3d9_cs);
916 hr = IWineD3DDevice_Clear(This->WineD3DDevice, Count, (CONST WINED3DRECT*) pRects, Flags, Color, Z, Stencil);
917 LeaveCriticalSection(&d3d9_cs);
918 return hr;
921 static HRESULT WINAPI IDirect3DDevice9Impl_SetTransform(LPDIRECT3DDEVICE9EX iface, D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX* lpMatrix) {
922 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
923 HRESULT hr;
924 TRACE("(%p) Relay\n" , This);
926 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
927 EnterCriticalSection(&d3d9_cs);
928 hr = IWineD3DDevice_SetTransform(This->WineD3DDevice, State, (CONST WINED3DMATRIX*) lpMatrix);
929 LeaveCriticalSection(&d3d9_cs);
930 return hr;
933 static HRESULT WINAPI IDirect3DDevice9Impl_GetTransform(LPDIRECT3DDEVICE9EX iface, D3DTRANSFORMSTATETYPE State, D3DMATRIX* pMatrix) {
934 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
935 TRACE("(%p) Relay\n" , This);
937 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
938 return IWineD3DDevice_GetTransform(This->WineD3DDevice, State, (WINED3DMATRIX*) pMatrix);
941 static HRESULT WINAPI IDirect3DDevice9Impl_MultiplyTransform(LPDIRECT3DDEVICE9EX iface, D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX* pMatrix) {
942 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
943 HRESULT hr;
944 TRACE("(%p) Relay\n" , This);
946 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
947 EnterCriticalSection(&d3d9_cs);
948 hr = IWineD3DDevice_MultiplyTransform(This->WineD3DDevice, State, (CONST WINED3DMATRIX*) pMatrix);
949 LeaveCriticalSection(&d3d9_cs);
950 return hr;
953 static HRESULT WINAPI IDirect3DDevice9Impl_SetViewport(LPDIRECT3DDEVICE9EX iface, CONST D3DVIEWPORT9* pViewport) {
954 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
955 HRESULT hr;
956 TRACE("(%p) Relay\n" , This);
958 /* Note: D3DVIEWPORT9 is compatible with WINED3DVIEWPORT */
959 EnterCriticalSection(&d3d9_cs);
960 hr = IWineD3DDevice_SetViewport(This->WineD3DDevice, (const WINED3DVIEWPORT *)pViewport);
961 LeaveCriticalSection(&d3d9_cs);
962 return hr;
965 static HRESULT WINAPI IDirect3DDevice9Impl_GetViewport(LPDIRECT3DDEVICE9EX iface, D3DVIEWPORT9* pViewport) {
966 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
967 HRESULT hr;
968 TRACE("(%p) Relay\n" , This);
970 /* Note: D3DVIEWPORT9 is compatible with WINED3DVIEWPORT */
971 EnterCriticalSection(&d3d9_cs);
972 hr = IWineD3DDevice_GetViewport(This->WineD3DDevice, (WINED3DVIEWPORT *)pViewport);
973 LeaveCriticalSection(&d3d9_cs);
974 return hr;
977 static HRESULT WINAPI IDirect3DDevice9Impl_SetMaterial(LPDIRECT3DDEVICE9EX iface, CONST D3DMATERIAL9* pMaterial) {
978 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
979 HRESULT hr;
980 TRACE("(%p) Relay\n" , This);
982 /* Note: D3DMATERIAL9 is compatible with WINED3DMATERIAL */
983 EnterCriticalSection(&d3d9_cs);
984 hr = IWineD3DDevice_SetMaterial(This->WineD3DDevice, (const WINED3DMATERIAL *)pMaterial);
985 LeaveCriticalSection(&d3d9_cs);
986 return hr;
989 static HRESULT WINAPI IDirect3DDevice9Impl_GetMaterial(LPDIRECT3DDEVICE9EX iface, D3DMATERIAL9* pMaterial) {
990 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
991 HRESULT hr;
992 TRACE("(%p) Relay\n" , This);
994 /* Note: D3DMATERIAL9 is compatible with WINED3DMATERIAL */
995 EnterCriticalSection(&d3d9_cs);
996 hr = IWineD3DDevice_GetMaterial(This->WineD3DDevice, (WINED3DMATERIAL *)pMaterial);
997 LeaveCriticalSection(&d3d9_cs);
998 return hr;
1001 static HRESULT WINAPI IDirect3DDevice9Impl_SetLight(LPDIRECT3DDEVICE9EX iface, DWORD Index, CONST D3DLIGHT9* pLight) {
1002 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1003 HRESULT hr;
1004 TRACE("(%p) Relay\n" , This);
1006 /* Note: D3DLIGHT9 is compatible with WINED3DLIGHT */
1007 EnterCriticalSection(&d3d9_cs);
1008 hr = IWineD3DDevice_SetLight(This->WineD3DDevice, Index, (const WINED3DLIGHT *)pLight);
1009 LeaveCriticalSection(&d3d9_cs);
1010 return hr;
1013 static HRESULT WINAPI IDirect3DDevice9Impl_GetLight(LPDIRECT3DDEVICE9EX iface, DWORD Index, D3DLIGHT9* pLight) {
1014 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1015 HRESULT hr;
1016 TRACE("(%p) Relay\n" , This);
1018 /* Note: D3DLIGHT9 is compatible with WINED3DLIGHT */
1019 EnterCriticalSection(&d3d9_cs);
1020 hr = IWineD3DDevice_GetLight(This->WineD3DDevice, Index, (WINED3DLIGHT *)pLight);
1021 LeaveCriticalSection(&d3d9_cs);
1022 return hr;
1025 static HRESULT WINAPI IDirect3DDevice9Impl_LightEnable(LPDIRECT3DDEVICE9EX iface, DWORD Index, BOOL Enable) {
1026 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1027 HRESULT hr;
1028 TRACE("(%p) Relay\n" , This);
1030 EnterCriticalSection(&d3d9_cs);
1031 hr = IWineD3DDevice_SetLightEnable(This->WineD3DDevice, Index, Enable);
1032 LeaveCriticalSection(&d3d9_cs);
1033 return hr;
1036 static HRESULT WINAPI IDirect3DDevice9Impl_GetLightEnable(LPDIRECT3DDEVICE9EX iface, DWORD Index, BOOL* pEnable) {
1037 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1038 HRESULT hr;
1039 TRACE("(%p) Relay\n" , This);
1041 EnterCriticalSection(&d3d9_cs);
1042 hr = IWineD3DDevice_GetLightEnable(This->WineD3DDevice, Index, pEnable);
1043 LeaveCriticalSection(&d3d9_cs);
1044 return hr;
1047 static HRESULT WINAPI IDirect3DDevice9Impl_SetClipPlane(LPDIRECT3DDEVICE9EX iface, DWORD Index, CONST float* pPlane) {
1048 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1049 HRESULT hr;
1050 TRACE("(%p) Relay\n" , This);
1052 EnterCriticalSection(&d3d9_cs);
1053 hr = IWineD3DDevice_SetClipPlane(This->WineD3DDevice, Index, pPlane);
1054 LeaveCriticalSection(&d3d9_cs);
1055 return hr;
1058 static HRESULT WINAPI IDirect3DDevice9Impl_GetClipPlane(LPDIRECT3DDEVICE9EX iface, DWORD Index, float* pPlane) {
1059 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1060 HRESULT hr;
1061 TRACE("(%p) Relay\n" , This);
1063 EnterCriticalSection(&d3d9_cs);
1064 hr = IWineD3DDevice_GetClipPlane(This->WineD3DDevice, Index, pPlane);
1065 LeaveCriticalSection(&d3d9_cs);
1066 return hr;
1069 static HRESULT WINAPI IDirect3DDevice9Impl_SetRenderState(LPDIRECT3DDEVICE9EX iface, D3DRENDERSTATETYPE State, DWORD Value) {
1070 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1071 HRESULT hr;
1072 TRACE("(%p) Relay\n" , This);
1074 EnterCriticalSection(&d3d9_cs);
1075 hr = IWineD3DDevice_SetRenderState(This->WineD3DDevice, State, Value);
1076 LeaveCriticalSection(&d3d9_cs);
1077 return hr;
1080 static HRESULT WINAPI IDirect3DDevice9Impl_GetRenderState(LPDIRECT3DDEVICE9EX iface, D3DRENDERSTATETYPE State, DWORD* pValue) {
1081 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1082 HRESULT hr;
1083 TRACE("(%p) Relay\n" , This);
1085 EnterCriticalSection(&d3d9_cs);
1086 hr = IWineD3DDevice_GetRenderState(This->WineD3DDevice, State, pValue);
1087 LeaveCriticalSection(&d3d9_cs);
1088 return hr;
1091 static HRESULT WINAPI IDirect3DDevice9Impl_SetClipStatus(LPDIRECT3DDEVICE9EX iface, CONST D3DCLIPSTATUS9* pClipStatus) {
1092 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1093 HRESULT hr;
1094 TRACE("(%p) Relay\n" , This);
1096 EnterCriticalSection(&d3d9_cs);
1097 hr = IWineD3DDevice_SetClipStatus(This->WineD3DDevice, (const WINED3DCLIPSTATUS *)pClipStatus);
1098 LeaveCriticalSection(&d3d9_cs);
1099 return hr;
1102 static HRESULT WINAPI IDirect3DDevice9Impl_GetClipStatus(LPDIRECT3DDEVICE9EX iface, D3DCLIPSTATUS9* pClipStatus) {
1103 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1104 HRESULT hr;
1105 TRACE("(%p) Relay\n" , This);
1107 EnterCriticalSection(&d3d9_cs);
1108 hr = IWineD3DDevice_GetClipStatus(This->WineD3DDevice, (WINED3DCLIPSTATUS *)pClipStatus);
1109 LeaveCriticalSection(&d3d9_cs);
1110 return hr;
1113 static HRESULT WINAPI IDirect3DDevice9Impl_GetTexture(LPDIRECT3DDEVICE9EX iface, DWORD Stage, IDirect3DBaseTexture9 **ppTexture) {
1114 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1115 IWineD3DBaseTexture *retTexture = NULL;
1116 HRESULT rc = D3D_OK;
1118 TRACE("(%p) Relay\n" , This);
1120 if(ppTexture == NULL){
1121 return D3DERR_INVALIDCALL;
1124 EnterCriticalSection(&d3d9_cs);
1125 rc = IWineD3DDevice_GetTexture(This->WineD3DDevice, Stage, &retTexture);
1126 if (SUCCEEDED(rc) && NULL != retTexture) {
1127 IWineD3DBaseTexture_GetParent(retTexture, (IUnknown **)ppTexture);
1128 IWineD3DBaseTexture_Release(retTexture);
1129 } else {
1130 if(FAILED(rc)) {
1131 WARN("Call to get texture (%d) failed (%p)\n", Stage, retTexture);
1133 *ppTexture = NULL;
1135 LeaveCriticalSection(&d3d9_cs);
1137 return rc;
1140 static HRESULT WINAPI IDirect3DDevice9Impl_SetTexture(LPDIRECT3DDEVICE9EX iface, DWORD Stage, IDirect3DBaseTexture9* pTexture) {
1141 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1142 HRESULT hr;
1143 TRACE("(%p) Relay %d %p\n" , This, Stage, pTexture);
1145 EnterCriticalSection(&d3d9_cs);
1146 hr = IWineD3DDevice_SetTexture(This->WineD3DDevice, Stage,
1147 pTexture==NULL ? NULL:((IDirect3DBaseTexture9Impl *)pTexture)->wineD3DBaseTexture);
1148 LeaveCriticalSection(&d3d9_cs);
1149 return hr;
1152 static const WINED3DTEXTURESTAGESTATETYPE tss_lookup[] =
1154 WINED3DTSS_FORCE_DWORD, /* 0, unused */
1155 WINED3DTSS_COLOROP, /* 1, D3DTSS_COLOROP */
1156 WINED3DTSS_COLORARG1, /* 2, D3DTSS_COLORARG1 */
1157 WINED3DTSS_COLORARG2, /* 3, D3DTSS_COLORARG2 */
1158 WINED3DTSS_ALPHAOP, /* 4, D3DTSS_ALPHAOP */
1159 WINED3DTSS_ALPHAARG1, /* 5, D3DTSS_ALPHAARG1 */
1160 WINED3DTSS_ALPHAARG2, /* 6, D3DTSS_ALPHAARG2 */
1161 WINED3DTSS_BUMPENVMAT00, /* 7, D3DTSS_BUMPENVMAT00 */
1162 WINED3DTSS_BUMPENVMAT01, /* 8, D3DTSS_BUMPENVMAT01 */
1163 WINED3DTSS_BUMPENVMAT10, /* 9, D3DTSS_BUMPENVMAT10 */
1164 WINED3DTSS_BUMPENVMAT11, /* 10, D3DTSS_BUMPENVMAT11 */
1165 WINED3DTSS_TEXCOORDINDEX, /* 11, D3DTSS_TEXCOORDINDEX */
1166 WINED3DTSS_FORCE_DWORD, /* 12, unused */
1167 WINED3DTSS_FORCE_DWORD, /* 13, unused */
1168 WINED3DTSS_FORCE_DWORD, /* 14, unused */
1169 WINED3DTSS_FORCE_DWORD, /* 15, unused */
1170 WINED3DTSS_FORCE_DWORD, /* 16, unused */
1171 WINED3DTSS_FORCE_DWORD, /* 17, unused */
1172 WINED3DTSS_FORCE_DWORD, /* 18, unused */
1173 WINED3DTSS_FORCE_DWORD, /* 19, unused */
1174 WINED3DTSS_FORCE_DWORD, /* 20, unused */
1175 WINED3DTSS_FORCE_DWORD, /* 21, unused */
1176 WINED3DTSS_BUMPENVLSCALE, /* 22, D3DTSS_BUMPENVLSCALE */
1177 WINED3DTSS_BUMPENVLOFFSET, /* 23, D3DTSS_BUMPENVLOFFSET */
1178 WINED3DTSS_TEXTURETRANSFORMFLAGS, /* 24, D3DTSS_TEXTURETRANSFORMFLAGS */
1179 WINED3DTSS_FORCE_DWORD, /* 25, unused */
1180 WINED3DTSS_COLORARG0, /* 26, D3DTSS_COLORARG0 */
1181 WINED3DTSS_ALPHAARG0, /* 27, D3DTSS_ALPHAARG0 */
1182 WINED3DTSS_RESULTARG, /* 28, D3DTSS_RESULTARG */
1183 WINED3DTSS_FORCE_DWORD, /* 29, unused */
1184 WINED3DTSS_FORCE_DWORD, /* 30, unused */
1185 WINED3DTSS_FORCE_DWORD, /* 31, unused */
1186 WINED3DTSS_CONSTANT, /* 32, D3DTSS_CONSTANT */
1189 static HRESULT WINAPI IDirect3DDevice9Impl_GetTextureStageState(LPDIRECT3DDEVICE9EX iface, DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD* pValue) {
1190 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1191 HRESULT hr;
1192 TRACE("(%p) Relay\n" , This);
1194 EnterCriticalSection(&d3d9_cs);
1195 hr = IWineD3DDevice_GetTextureStageState(This->WineD3DDevice, Stage, tss_lookup[Type], pValue);
1196 LeaveCriticalSection(&d3d9_cs);
1197 return hr;
1200 static HRESULT WINAPI IDirect3DDevice9Impl_SetTextureStageState(LPDIRECT3DDEVICE9EX iface, DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD Value) {
1201 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1202 HRESULT hr;
1203 TRACE("(%p) Relay\n" , This);
1205 EnterCriticalSection(&d3d9_cs);
1206 hr = IWineD3DDevice_SetTextureStageState(This->WineD3DDevice, Stage, tss_lookup[Type], Value);
1207 LeaveCriticalSection(&d3d9_cs);
1208 return hr;
1211 static HRESULT WINAPI IDirect3DDevice9Impl_GetSamplerState(LPDIRECT3DDEVICE9EX iface, DWORD Sampler, D3DSAMPLERSTATETYPE Type, DWORD* pValue) {
1212 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1213 HRESULT hr;
1214 TRACE("(%p) Relay\n" , This);
1216 EnterCriticalSection(&d3d9_cs);
1217 hr = IWineD3DDevice_GetSamplerState(This->WineD3DDevice, Sampler, Type, pValue);
1218 LeaveCriticalSection(&d3d9_cs);
1219 return hr;
1222 static HRESULT WINAPI IDirect3DDevice9Impl_SetSamplerState(LPDIRECT3DDEVICE9EX iface, DWORD Sampler, D3DSAMPLERSTATETYPE Type, DWORD Value) {
1223 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1224 HRESULT hr;
1225 TRACE("(%p) Relay\n" , This);
1227 EnterCriticalSection(&d3d9_cs);
1228 hr = IWineD3DDevice_SetSamplerState(This->WineD3DDevice, Sampler, Type, Value);
1229 LeaveCriticalSection(&d3d9_cs);
1230 return hr;
1233 static HRESULT WINAPI IDirect3DDevice9Impl_ValidateDevice(LPDIRECT3DDEVICE9EX iface, DWORD* pNumPasses) {
1234 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1235 HRESULT hr;
1236 TRACE("(%p) Relay\n" , This);
1238 EnterCriticalSection(&d3d9_cs);
1239 hr = IWineD3DDevice_ValidateDevice(This->WineD3DDevice, pNumPasses);
1240 LeaveCriticalSection(&d3d9_cs);
1241 return hr;
1244 static HRESULT WINAPI IDirect3DDevice9Impl_SetPaletteEntries(LPDIRECT3DDEVICE9EX iface, UINT PaletteNumber, CONST PALETTEENTRY* pEntries) {
1245 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1246 HRESULT hr;
1247 TRACE("(%p) Relay\n" , This);
1249 EnterCriticalSection(&d3d9_cs);
1250 hr = IWineD3DDevice_SetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
1251 LeaveCriticalSection(&d3d9_cs);
1252 return hr;
1255 static HRESULT WINAPI IDirect3DDevice9Impl_GetPaletteEntries(LPDIRECT3DDEVICE9EX iface, UINT PaletteNumber, PALETTEENTRY* pEntries) {
1256 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1257 HRESULT hr;
1258 TRACE("(%p) Relay\n" , This);
1260 EnterCriticalSection(&d3d9_cs);
1261 hr = IWineD3DDevice_GetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
1262 LeaveCriticalSection(&d3d9_cs);
1263 return hr;
1266 static HRESULT WINAPI IDirect3DDevice9Impl_SetCurrentTexturePalette(LPDIRECT3DDEVICE9EX iface, UINT PaletteNumber) {
1267 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1268 HRESULT hr;
1269 TRACE("(%p) Relay\n" , This);
1271 EnterCriticalSection(&d3d9_cs);
1272 hr = IWineD3DDevice_SetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
1273 LeaveCriticalSection(&d3d9_cs);
1274 return hr;
1277 static HRESULT WINAPI IDirect3DDevice9Impl_GetCurrentTexturePalette(LPDIRECT3DDEVICE9EX iface, UINT* PaletteNumber) {
1278 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1279 HRESULT hr;
1280 TRACE("(%p) Relay\n" , This);
1282 EnterCriticalSection(&d3d9_cs);
1283 hr = IWineD3DDevice_GetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
1284 LeaveCriticalSection(&d3d9_cs);
1285 return hr;
1288 static HRESULT WINAPI IDirect3DDevice9Impl_SetScissorRect(LPDIRECT3DDEVICE9EX iface, CONST RECT* pRect) {
1289 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1290 HRESULT hr;
1291 TRACE("(%p) Relay\n" , This);
1293 EnterCriticalSection(&d3d9_cs);
1294 hr = IWineD3DDevice_SetScissorRect(This->WineD3DDevice, pRect);
1295 LeaveCriticalSection(&d3d9_cs);
1296 return hr;
1299 static HRESULT WINAPI IDirect3DDevice9Impl_GetScissorRect(LPDIRECT3DDEVICE9EX iface, RECT* pRect) {
1300 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1301 HRESULT hr;
1302 TRACE("(%p) Relay\n" , This);
1304 EnterCriticalSection(&d3d9_cs);
1305 hr = IWineD3DDevice_GetScissorRect(This->WineD3DDevice, pRect);
1306 LeaveCriticalSection(&d3d9_cs);
1307 return hr;
1310 static HRESULT WINAPI IDirect3DDevice9Impl_SetSoftwareVertexProcessing(LPDIRECT3DDEVICE9EX iface, BOOL bSoftware) {
1311 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1312 HRESULT hr;
1313 TRACE("(%p) Relay\n" , This);
1315 EnterCriticalSection(&d3d9_cs);
1316 hr = IWineD3DDevice_SetSoftwareVertexProcessing(This->WineD3DDevice, bSoftware);
1317 LeaveCriticalSection(&d3d9_cs);
1318 return hr;
1321 static BOOL WINAPI IDirect3DDevice9Impl_GetSoftwareVertexProcessing(LPDIRECT3DDEVICE9EX iface) {
1322 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1323 BOOL ret;
1324 TRACE("(%p) Relay\n" , This);
1326 EnterCriticalSection(&d3d9_cs);
1327 ret = IWineD3DDevice_GetSoftwareVertexProcessing(This->WineD3DDevice);
1328 LeaveCriticalSection(&d3d9_cs);
1329 return ret;
1332 static HRESULT WINAPI IDirect3DDevice9Impl_SetNPatchMode(LPDIRECT3DDEVICE9EX iface, float nSegments) {
1333 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1334 HRESULT hr;
1335 TRACE("(%p) Relay\n" , This);
1337 EnterCriticalSection(&d3d9_cs);
1338 hr = IWineD3DDevice_SetNPatchMode(This->WineD3DDevice, nSegments);
1339 LeaveCriticalSection(&d3d9_cs);
1340 return hr;
1343 static float WINAPI IDirect3DDevice9Impl_GetNPatchMode(LPDIRECT3DDEVICE9EX iface) {
1344 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1345 float ret;
1346 TRACE("(%p) Relay\n" , This);
1348 EnterCriticalSection(&d3d9_cs);
1349 ret = IWineD3DDevice_GetNPatchMode(This->WineD3DDevice);
1350 LeaveCriticalSection(&d3d9_cs);
1351 return ret;
1354 static HRESULT WINAPI IDirect3DDevice9Impl_DrawPrimitive(LPDIRECT3DDEVICE9EX iface, D3DPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT PrimitiveCount) {
1355 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1356 HRESULT hr;
1357 TRACE("(%p) Relay\n" , This);
1359 EnterCriticalSection(&d3d9_cs);
1360 hr = IWineD3DDevice_DrawPrimitive(This->WineD3DDevice, PrimitiveType, StartVertex, PrimitiveCount);
1361 LeaveCriticalSection(&d3d9_cs);
1362 return hr;
1365 static HRESULT WINAPI IDirect3DDevice9Impl_DrawIndexedPrimitive(LPDIRECT3DDEVICE9EX iface, D3DPRIMITIVETYPE PrimitiveType,
1366 INT BaseVertexIndex, UINT MinVertexIndex, UINT NumVertices, UINT startIndex, UINT primCount) {
1367 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1368 HRESULT hr;
1369 TRACE("(%p) Relay\n" , This);
1371 /* D3D8 passes the baseVertexIndex in SetIndices, and due to the stateblock functions wined3d has to work that way */
1372 EnterCriticalSection(&d3d9_cs);
1373 IWineD3DDevice_SetBaseVertexIndex(This->WineD3DDevice, BaseVertexIndex);
1374 hr = IWineD3DDevice_DrawIndexedPrimitive(This->WineD3DDevice, PrimitiveType, MinVertexIndex, NumVertices, startIndex, primCount);
1375 LeaveCriticalSection(&d3d9_cs);
1376 return hr;
1379 static HRESULT WINAPI IDirect3DDevice9Impl_DrawPrimitiveUP(LPDIRECT3DDEVICE9EX iface, D3DPRIMITIVETYPE PrimitiveType, UINT PrimitiveCount, CONST void* pVertexStreamZeroData, UINT VertexStreamZeroStride) {
1380 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1381 HRESULT hr;
1382 TRACE("(%p) Relay\n" , This);
1384 EnterCriticalSection(&d3d9_cs);
1385 hr = IWineD3DDevice_DrawPrimitiveUP(This->WineD3DDevice, PrimitiveType, PrimitiveCount, pVertexStreamZeroData, VertexStreamZeroStride);
1386 LeaveCriticalSection(&d3d9_cs);
1387 return hr;
1390 static HRESULT WINAPI IDirect3DDevice9Impl_DrawIndexedPrimitiveUP(LPDIRECT3DDEVICE9EX iface, D3DPRIMITIVETYPE PrimitiveType, UINT MinVertexIndex,
1391 UINT NumVertexIndices, UINT PrimitiveCount, CONST void* pIndexData,
1392 D3DFORMAT IndexDataFormat, CONST void* pVertexStreamZeroData, UINT VertexStreamZeroStride) {
1393 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1394 HRESULT hr;
1395 TRACE("(%p) Relay\n" , This);
1397 EnterCriticalSection(&d3d9_cs);
1398 hr = IWineD3DDevice_DrawIndexedPrimitiveUP(This->WineD3DDevice, PrimitiveType, MinVertexIndex,
1399 NumVertexIndices, PrimitiveCount, pIndexData, wined3dformat_from_d3dformat(IndexDataFormat),
1400 pVertexStreamZeroData, VertexStreamZeroStride);
1401 LeaveCriticalSection(&d3d9_cs);
1402 return hr;
1405 static HRESULT WINAPI IDirect3DDevice9Impl_ProcessVertices(LPDIRECT3DDEVICE9EX iface, UINT SrcStartIndex, UINT DestIndex, UINT VertexCount, IDirect3DVertexBuffer9* pDestBuffer, IDirect3DVertexDeclaration9* pVertexDecl, DWORD Flags) {
1406 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1407 IDirect3DVertexDeclaration9Impl *Decl = (IDirect3DVertexDeclaration9Impl *) pVertexDecl;
1408 HRESULT hr;
1409 TRACE("(%p) Relay\n" , This);
1411 EnterCriticalSection(&d3d9_cs);
1412 hr = IWineD3DDevice_ProcessVertices(This->WineD3DDevice,SrcStartIndex, DestIndex, VertexCount, ((IDirect3DVertexBuffer9Impl *)pDestBuffer)->wineD3DVertexBuffer, Decl ? Decl->wineD3DVertexDeclaration : NULL, Flags);
1413 LeaveCriticalSection(&d3d9_cs);
1414 return hr;
1417 static IDirect3DVertexDeclaration9 *getConvertedDecl(IDirect3DDevice9Impl *This, DWORD fvf) {
1418 HRESULT hr;
1419 D3DVERTEXELEMENT9* elements = NULL;
1420 IDirect3DVertexDeclaration9* pDecl = NULL;
1421 int p, low, high; /* deliberately signed */
1422 IDirect3DVertexDeclaration9 **convertedDecls = This->convertedDecls;
1424 TRACE("Searching for declaration for fvf %08x... ", fvf);
1426 low = 0;
1427 high = This->numConvertedDecls - 1;
1428 while(low <= high) {
1429 p = (low + high) >> 1;
1430 TRACE("%d ", p);
1431 if(((IDirect3DVertexDeclaration9Impl *) convertedDecls[p])->convFVF == fvf) {
1432 TRACE("found %p\n", convertedDecls[p]);
1433 return convertedDecls[p];
1434 } else if(((IDirect3DVertexDeclaration9Impl *) convertedDecls[p])->convFVF < fvf) {
1435 low = p + 1;
1436 } else {
1437 high = p - 1;
1440 TRACE("not found. Creating and inserting at position %d.\n", low);
1442 hr = vdecl_convert_fvf(fvf, &elements);
1443 if (hr != S_OK) return NULL;
1445 hr = IDirect3DDevice9Impl_CreateVertexDeclaration((IDirect3DDevice9Ex *) This, elements, &pDecl);
1446 HeapFree(GetProcessHeap(), 0, elements); /* CreateVertexDeclaration makes a copy */
1447 if (hr != S_OK) return NULL;
1449 if(This->declArraySize == This->numConvertedDecls) {
1450 int grow = max(This->declArraySize / 2, 8);
1451 convertedDecls = HeapReAlloc(GetProcessHeap(), 0, convertedDecls,
1452 sizeof(convertedDecls[0]) * (This->numConvertedDecls + grow));
1453 if(!convertedDecls) {
1454 /* This will destroy it */
1455 IDirect3DVertexDeclaration9_Release(pDecl);
1456 return NULL;
1458 This->convertedDecls = convertedDecls;
1459 This->declArraySize += grow;
1462 memmove(convertedDecls + low + 1, convertedDecls + low, sizeof(IDirect3DVertexDeclaration9Impl *) * (This->numConvertedDecls - low));
1463 convertedDecls[low] = pDecl;
1464 This->numConvertedDecls++;
1466 /* Will prevent the decl from being destroyed */
1467 ((IDirect3DVertexDeclaration9Impl *) pDecl)->convFVF = fvf;
1468 IDirect3DVertexDeclaration9_Release(pDecl); /* Does not destroy now */
1470 TRACE("Returning %p. %d decls in array\n", pDecl, This->numConvertedDecls);
1471 return pDecl;
1474 static HRESULT WINAPI IDirect3DDevice9Impl_SetFVF(LPDIRECT3DDEVICE9EX iface, DWORD FVF) {
1475 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1476 HRESULT hr = S_OK;
1477 TRACE("(%p) Relay\n" , This);
1479 EnterCriticalSection(&d3d9_cs);
1480 if (0 != FVF) {
1481 IDirect3DVertexDeclaration9* pDecl = getConvertedDecl(This, FVF);
1483 if(!pDecl) {
1484 /* Any situation when this should happen, except out of memory? */
1485 ERR("Failed to create a converted vertex declaration\n");
1486 LeaveCriticalSection(&d3d9_cs);
1487 return D3DERR_DRIVERINTERNALERROR;
1490 hr = IDirect3DDevice9Impl_SetVertexDeclaration(iface, pDecl);
1491 if (hr != S_OK) {
1492 LeaveCriticalSection(&d3d9_cs);
1493 return hr;
1496 LeaveCriticalSection(&d3d9_cs);
1498 return hr;
1501 static HRESULT WINAPI IDirect3DDevice9Impl_GetFVF(LPDIRECT3DDEVICE9EX iface, DWORD* pFVF) {
1502 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1503 IDirect3DVertexDeclaration9 *decl;
1504 HRESULT hr;
1505 TRACE("(%p) Relay\n" , This);
1507 hr = IDirect3DDevice9_GetVertexDeclaration(iface, &decl);
1508 if (FAILED(hr))
1510 WARN("Failed to get vertex declaration, %#x\n", hr);
1511 *pFVF = 0;
1512 return hr;
1515 if (decl)
1517 *pFVF = ((IDirect3DVertexDeclaration9Impl *)decl)->convFVF;
1518 IDirect3DVertexDeclaration9_Release(decl);
1520 else
1522 *pFVF = 0;
1525 TRACE("Returning FVF %#x\n", *pFVF);
1527 return hr;
1530 static HRESULT WINAPI IDirect3DDevice9Impl_SetStreamSource(LPDIRECT3DDEVICE9EX iface, UINT StreamNumber, IDirect3DVertexBuffer9* pStreamData, UINT OffsetInBytes, UINT Stride) {
1531 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1532 HRESULT hr;
1533 TRACE("(%p) Relay\n" , This);
1535 EnterCriticalSection(&d3d9_cs);
1536 hr = IWineD3DDevice_SetStreamSource(This->WineD3DDevice, StreamNumber,
1537 pStreamData==NULL ? NULL:((IDirect3DVertexBuffer9Impl *)pStreamData)->wineD3DVertexBuffer,
1538 OffsetInBytes, Stride);
1539 LeaveCriticalSection(&d3d9_cs);
1540 return hr;
1543 static HRESULT WINAPI IDirect3DDevice9Impl_GetStreamSource(LPDIRECT3DDEVICE9EX iface, UINT StreamNumber, IDirect3DVertexBuffer9 **pStream, UINT* OffsetInBytes, UINT* pStride) {
1544 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1545 IWineD3DVertexBuffer *retStream = NULL;
1546 HRESULT rc = D3D_OK;
1548 TRACE("(%p) Relay\n" , This);
1550 if(pStream == NULL){
1551 return D3DERR_INVALIDCALL;
1554 EnterCriticalSection(&d3d9_cs);
1555 rc = IWineD3DDevice_GetStreamSource(This->WineD3DDevice, StreamNumber, &retStream, OffsetInBytes, pStride);
1556 if (rc == D3D_OK && NULL != retStream) {
1557 IWineD3DVertexBuffer_GetParent(retStream, (IUnknown **)pStream);
1558 IWineD3DVertexBuffer_Release(retStream);
1559 }else{
1560 if (rc != D3D_OK){
1561 FIXME("Call to GetStreamSource failed %p %p\n", OffsetInBytes, pStride);
1563 *pStream = NULL;
1565 LeaveCriticalSection(&d3d9_cs);
1567 return rc;
1570 static HRESULT WINAPI IDirect3DDevice9Impl_SetStreamSourceFreq(LPDIRECT3DDEVICE9EX iface, UINT StreamNumber, UINT Divider) {
1571 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1572 HRESULT hr;
1573 TRACE("(%p) Relay\n" , This);
1575 EnterCriticalSection(&d3d9_cs);
1576 hr = IWineD3DDevice_SetStreamSourceFreq(This->WineD3DDevice, StreamNumber, Divider);
1577 LeaveCriticalSection(&d3d9_cs);
1578 return hr;
1581 static HRESULT WINAPI IDirect3DDevice9Impl_GetStreamSourceFreq(LPDIRECT3DDEVICE9EX iface, UINT StreamNumber, UINT* Divider) {
1582 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1583 HRESULT hr;
1584 TRACE("(%p) Relay\n" , This);
1586 EnterCriticalSection(&d3d9_cs);
1587 hr = IWineD3DDevice_GetStreamSourceFreq(This->WineD3DDevice, StreamNumber, Divider);
1588 LeaveCriticalSection(&d3d9_cs);
1589 return hr;
1592 static HRESULT WINAPI IDirect3DDevice9Impl_SetIndices(LPDIRECT3DDEVICE9EX iface, IDirect3DIndexBuffer9* pIndexData) {
1593 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1594 HRESULT hr;
1595 TRACE("(%p) Relay\n", This);
1597 EnterCriticalSection(&d3d9_cs);
1598 hr = IWineD3DDevice_SetIndices(This->WineD3DDevice,
1599 pIndexData ? ((IDirect3DIndexBuffer9Impl *)pIndexData)->wineD3DIndexBuffer : NULL);
1600 LeaveCriticalSection(&d3d9_cs);
1601 return hr;
1604 static HRESULT WINAPI IDirect3DDevice9Impl_GetIndices(LPDIRECT3DDEVICE9EX iface, IDirect3DIndexBuffer9 **ppIndexData) {
1605 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1606 IWineD3DIndexBuffer *retIndexData = NULL;
1607 HRESULT rc = D3D_OK;
1609 TRACE("(%p) Relay\n", This);
1611 if(ppIndexData == NULL){
1612 return D3DERR_INVALIDCALL;
1615 EnterCriticalSection(&d3d9_cs);
1616 rc = IWineD3DDevice_GetIndices(This->WineD3DDevice, &retIndexData);
1617 if (SUCCEEDED(rc) && retIndexData) {
1618 IWineD3DIndexBuffer_GetParent(retIndexData, (IUnknown **)ppIndexData);
1619 IWineD3DIndexBuffer_Release(retIndexData);
1620 } else {
1621 if (FAILED(rc)) FIXME("Call to GetIndices failed\n");
1622 *ppIndexData = NULL;
1624 LeaveCriticalSection(&d3d9_cs);
1625 return rc;
1628 static HRESULT WINAPI IDirect3DDevice9Impl_DrawRectPatch(LPDIRECT3DDEVICE9EX iface, UINT Handle, CONST float* pNumSegs, CONST D3DRECTPATCH_INFO* pRectPatchInfo) {
1629 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1630 HRESULT hr;
1631 TRACE("(%p) Relay\n", This);
1633 EnterCriticalSection(&d3d9_cs);
1634 hr = IWineD3DDevice_DrawRectPatch(This->WineD3DDevice, Handle, pNumSegs, (CONST WINED3DRECTPATCH_INFO *)pRectPatchInfo);
1635 LeaveCriticalSection(&d3d9_cs);
1636 return hr;
1639 static HRESULT WINAPI IDirect3DDevice9Impl_DrawTriPatch(LPDIRECT3DDEVICE9EX iface, UINT Handle, CONST float* pNumSegs, CONST D3DTRIPATCH_INFO* pTriPatchInfo) {
1640 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1641 HRESULT hr;
1642 TRACE("(%p) Relay\n", This);
1644 EnterCriticalSection(&d3d9_cs);
1645 hr = IWineD3DDevice_DrawTriPatch(This->WineD3DDevice, Handle, pNumSegs, (CONST WINED3DTRIPATCH_INFO *)pTriPatchInfo);
1646 LeaveCriticalSection(&d3d9_cs);
1647 return hr;
1650 static HRESULT WINAPI IDirect3DDevice9Impl_DeletePatch(LPDIRECT3DDEVICE9EX iface, UINT Handle) {
1651 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1652 HRESULT hr;
1653 TRACE("(%p) Relay\n", This);
1655 EnterCriticalSection(&d3d9_cs);
1656 hr = IWineD3DDevice_DeletePatch(This->WineD3DDevice, Handle);
1657 LeaveCriticalSection(&d3d9_cs);
1658 return hr;
1661 static HRESULT WINAPI IDirect3DDevice9ExImpl_SetConvolutionMonoKernel(LPDIRECT3DDEVICE9EX iface, UINT width, UINT height, float *rows, float *columns) {
1662 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1663 FIXME("(%p)->(%d, %d, %p, %p) Stub!\n", This, width, height, rows, columns);
1664 return WINED3DERR_INVALIDCALL;
1667 static HRESULT WINAPI IDirect3DDevice9ExImpl_ComposeRects(LPDIRECT3DDEVICE9EX iface, IDirect3DSurface9 *pSrc, IDirect3DDevice9 *pDst, IDirect3DVertexBuffer9 *pSrcRectDescs, UINT NumRects, IDirect3DVertexBuffer9 *pDstRectDescs, D3DCOMPOSERECTSOP Operation, int Xoffset, int Yoffset) {
1668 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1669 FIXME("(%p)->(%p, %p, %p, %d, %p, %d, %d, %d) Stub!\n", This, pSrc, pDst, pSrcRectDescs, NumRects, pDstRectDescs, Operation, Xoffset, Yoffset);
1670 return WINED3DERR_INVALIDCALL;
1673 static HRESULT WINAPI IDirect3DDevice9ExImpl_PresentEx(LPDIRECT3DDEVICE9EX iface, CONST RECT *pSourceRect, CONST RECT *pDestRect, HWND hDestWindowOverride, CONST RGNDATA *pDirtyRegion, DWORD dwFlags) {
1674 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1675 FIXME("(%p= -> (%p), %p, %p, %p, 0x%08x) Stub!\n", This, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion, dwFlags);
1676 return WINED3DERR_INVALIDCALL;
1679 static HRESULT WINAPI IDirect3DDevice9ExImpl_GetGPUThreadPriority(LPDIRECT3DDEVICE9EX iface, INT *pPriority) {
1680 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1681 FIXME("(%p)->(%p) Stub!\n", This, pPriority);
1682 return WINED3DERR_INVALIDCALL;
1685 static HRESULT WINAPI IDirect3DDevice9ExImpl_SetGPUThreadPriority(LPDIRECT3DDEVICE9EX iface, INT Priority) {
1686 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1687 FIXME("(%p)->(%d) Stub!\n", This, Priority);
1688 return WINED3DERR_INVALIDCALL;
1691 static HRESULT WINAPI IDirect3DDevice9ExImpl_WaitForVBlank(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain) {
1692 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1693 FIXME("(%p)->(%d) Stub!\n", This, iSwapChain);
1694 return WINED3DERR_INVALIDCALL;
1697 static HRESULT WINAPI IDirect3DDevice9ExImpl_CheckresourceResidency(LPDIRECT3DDEVICE9EX iface, IDirect3DResource9 ** pResourceArray, UINT32 Numresources) {
1698 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1699 FIXME("(%p)->(%p, %d) Stub!\n", This, pResourceArray, Numresources);
1700 return WINED3DERR_INVALIDCALL;
1703 static HRESULT WINAPI IDirect3DDevice9ExImpl_SetMaximumFrameLatency(LPDIRECT3DDEVICE9EX iface, UINT MaxLatency) {
1704 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1705 FIXME("(%p)->(%d) Stub!\n", This, MaxLatency);
1706 return WINED3DERR_INVALIDCALL;
1709 static HRESULT WINAPI IDirect3DDevice9ExImpl_GetMaximumFrameLatency(LPDIRECT3DDEVICE9EX iface, UINT *pMaxLatency) {
1710 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1711 FIXME("(%p)->(%p) Stub!\n", This, pMaxLatency);
1712 *pMaxLatency = 2;
1713 return WINED3DERR_INVALIDCALL;
1716 static HRESULT WINAPI IDirect3DDevice9ExImpl_CheckdeviceState(LPDIRECT3DDEVICE9EX iface, HWND hDestinationWindow) {
1717 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1718 FIXME("(%p)->(%p) Stub!\n", This, hDestinationWindow);
1719 return WINED3DERR_INVALIDCALL;
1722 static HRESULT WINAPI IDirect3DDevice9ExImpl_CreateRenderTargetEx(LPDIRECT3DDEVICE9EX iface, UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultiSampleQuality, BOOL Lockable, IDirect3DSurface9 ** ppSurface, HANDLE *pSharedHandle, DWORD Usage) {
1723 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1724 FIXME("(%p)->(%d, %d, %d, %d, %d, %s, %p, %p, 0x%08x) Stub!\n", This, Width, Height, Format, MultiSample, MultiSampleQuality, Lockable ? "true" : "false", ppSurface, pSharedHandle, Usage);
1725 return WINED3DERR_INVALIDCALL;
1728 static HRESULT WINAPI IDirect3DDevice9ExImpl_CreateOffscreenPlainSurfaceEx(LPDIRECT3DDEVICE9EX iface, UINT Width, UINT Height, D3DFORMAT Format, D3DPOOL Pool, IDirect3DSurface9 **ppSurface, HANDLE *pSharedHandle, DWORD Usage) {
1729 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1730 FIXME("(%p)->(%d, %d, %d, %d, %p, %p, 0x%08x) Stub!\n", This, Width, Height, Format, Pool, ppSurface, pSharedHandle, Usage);
1731 return WINED3DERR_INVALIDCALL;
1734 static HRESULT WINAPI IDirect3DDevice9ExImpl_CreateDepthStencilSurfaceEx(LPDIRECT3DDEVICE9EX iface, UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultiSampleQuality, BOOL Discard, IDirect3DSurface9 **ppSurface, HANDLE *pSharedHandle, DWORD Usage) {
1735 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1736 FIXME("(%p)->(%d, %d, %d, %d, %d, %s, %p, %p, 0x%08x) Stub!\n", This, Width, Height, Format, MultiSample, MultiSampleQuality, Discard ? "true" : "false", ppSurface, pSharedHandle, Usage);
1737 return WINED3DERR_INVALIDCALL;
1740 static HRESULT WINAPI IDirect3DDevice9ExImpl_ResetEx(LPDIRECT3DDEVICE9EX iface, D3DPRESENT_PARAMETERS *pPresentationParameters, D3DDISPLAYMODEEX *pFullscreenDisplayMode) {
1741 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1742 FIXME("(%p)->(%p) Stub!\n", This, pPresentationParameters);
1743 return WINED3DERR_INVALIDCALL;
1746 static HRESULT WINAPI IDirect3DDevice9ExImpl_GetDisplayModeEx(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain, D3DDISPLAYMODEEX *pMode, D3DDISPLAYROTATION *pRotation) {
1747 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1748 FIXME("(%p)->(%d, %p, %p) Stub!\n", This, iSwapChain, pMode, pRotation);
1749 return WINED3DERR_INVALIDCALL;
1752 const IDirect3DDevice9ExVtbl Direct3DDevice9_Vtbl =
1754 /* IUnknown */
1755 IDirect3DDevice9Impl_QueryInterface,
1756 IDirect3DDevice9Impl_AddRef,
1757 IDirect3DDevice9Impl_Release,
1758 /* IDirect3DDevice9 */
1759 IDirect3DDevice9Impl_TestCooperativeLevel,
1760 IDirect3DDevice9Impl_GetAvailableTextureMem,
1761 IDirect3DDevice9Impl_EvictManagedResources,
1762 IDirect3DDevice9Impl_GetDirect3D,
1763 IDirect3DDevice9Impl_GetDeviceCaps,
1764 IDirect3DDevice9Impl_GetDisplayMode,
1765 IDirect3DDevice9Impl_GetCreationParameters,
1766 IDirect3DDevice9Impl_SetCursorProperties,
1767 IDirect3DDevice9Impl_SetCursorPosition,
1768 IDirect3DDevice9Impl_ShowCursor,
1769 IDirect3DDevice9Impl_CreateAdditionalSwapChain,
1770 IDirect3DDevice9Impl_GetSwapChain,
1771 IDirect3DDevice9Impl_GetNumberOfSwapChains,
1772 IDirect3DDevice9Impl_Reset,
1773 IDirect3DDevice9Impl_Present,
1774 IDirect3DDevice9Impl_GetBackBuffer,
1775 IDirect3DDevice9Impl_GetRasterStatus,
1776 IDirect3DDevice9Impl_SetDialogBoxMode,
1777 IDirect3DDevice9Impl_SetGammaRamp,
1778 IDirect3DDevice9Impl_GetGammaRamp,
1779 IDirect3DDevice9Impl_CreateTexture,
1780 IDirect3DDevice9Impl_CreateVolumeTexture,
1781 IDirect3DDevice9Impl_CreateCubeTexture,
1782 IDirect3DDevice9Impl_CreateVertexBuffer,
1783 IDirect3DDevice9Impl_CreateIndexBuffer,
1784 IDirect3DDevice9Impl_CreateRenderTarget,
1785 IDirect3DDevice9Impl_CreateDepthStencilSurface,
1786 IDirect3DDevice9Impl_UpdateSurface,
1787 IDirect3DDevice9Impl_UpdateTexture,
1788 IDirect3DDevice9Impl_GetRenderTargetData,
1789 IDirect3DDevice9Impl_GetFrontBufferData,
1790 IDirect3DDevice9Impl_StretchRect,
1791 IDirect3DDevice9Impl_ColorFill,
1792 IDirect3DDevice9Impl_CreateOffscreenPlainSurface,
1793 IDirect3DDevice9Impl_SetRenderTarget,
1794 IDirect3DDevice9Impl_GetRenderTarget,
1795 IDirect3DDevice9Impl_SetDepthStencilSurface,
1796 IDirect3DDevice9Impl_GetDepthStencilSurface,
1797 IDirect3DDevice9Impl_BeginScene,
1798 IDirect3DDevice9Impl_EndScene,
1799 IDirect3DDevice9Impl_Clear,
1800 IDirect3DDevice9Impl_SetTransform,
1801 IDirect3DDevice9Impl_GetTransform,
1802 IDirect3DDevice9Impl_MultiplyTransform,
1803 IDirect3DDevice9Impl_SetViewport,
1804 IDirect3DDevice9Impl_GetViewport,
1805 IDirect3DDevice9Impl_SetMaterial,
1806 IDirect3DDevice9Impl_GetMaterial,
1807 IDirect3DDevice9Impl_SetLight,
1808 IDirect3DDevice9Impl_GetLight,
1809 IDirect3DDevice9Impl_LightEnable,
1810 IDirect3DDevice9Impl_GetLightEnable,
1811 IDirect3DDevice9Impl_SetClipPlane,
1812 IDirect3DDevice9Impl_GetClipPlane,
1813 IDirect3DDevice9Impl_SetRenderState,
1814 IDirect3DDevice9Impl_GetRenderState,
1815 IDirect3DDevice9Impl_CreateStateBlock,
1816 IDirect3DDevice9Impl_BeginStateBlock,
1817 IDirect3DDevice9Impl_EndStateBlock,
1818 IDirect3DDevice9Impl_SetClipStatus,
1819 IDirect3DDevice9Impl_GetClipStatus,
1820 IDirect3DDevice9Impl_GetTexture,
1821 IDirect3DDevice9Impl_SetTexture,
1822 IDirect3DDevice9Impl_GetTextureStageState,
1823 IDirect3DDevice9Impl_SetTextureStageState,
1824 IDirect3DDevice9Impl_GetSamplerState,
1825 IDirect3DDevice9Impl_SetSamplerState,
1826 IDirect3DDevice9Impl_ValidateDevice,
1827 IDirect3DDevice9Impl_SetPaletteEntries,
1828 IDirect3DDevice9Impl_GetPaletteEntries,
1829 IDirect3DDevice9Impl_SetCurrentTexturePalette,
1830 IDirect3DDevice9Impl_GetCurrentTexturePalette,
1831 IDirect3DDevice9Impl_SetScissorRect,
1832 IDirect3DDevice9Impl_GetScissorRect,
1833 IDirect3DDevice9Impl_SetSoftwareVertexProcessing,
1834 IDirect3DDevice9Impl_GetSoftwareVertexProcessing,
1835 IDirect3DDevice9Impl_SetNPatchMode,
1836 IDirect3DDevice9Impl_GetNPatchMode,
1837 IDirect3DDevice9Impl_DrawPrimitive,
1838 IDirect3DDevice9Impl_DrawIndexedPrimitive,
1839 IDirect3DDevice9Impl_DrawPrimitiveUP,
1840 IDirect3DDevice9Impl_DrawIndexedPrimitiveUP,
1841 IDirect3DDevice9Impl_ProcessVertices,
1842 IDirect3DDevice9Impl_CreateVertexDeclaration,
1843 IDirect3DDevice9Impl_SetVertexDeclaration,
1844 IDirect3DDevice9Impl_GetVertexDeclaration,
1845 IDirect3DDevice9Impl_SetFVF,
1846 IDirect3DDevice9Impl_GetFVF,
1847 IDirect3DDevice9Impl_CreateVertexShader,
1848 IDirect3DDevice9Impl_SetVertexShader,
1849 IDirect3DDevice9Impl_GetVertexShader,
1850 IDirect3DDevice9Impl_SetVertexShaderConstantF,
1851 IDirect3DDevice9Impl_GetVertexShaderConstantF,
1852 IDirect3DDevice9Impl_SetVertexShaderConstantI,
1853 IDirect3DDevice9Impl_GetVertexShaderConstantI,
1854 IDirect3DDevice9Impl_SetVertexShaderConstantB,
1855 IDirect3DDevice9Impl_GetVertexShaderConstantB,
1856 IDirect3DDevice9Impl_SetStreamSource,
1857 IDirect3DDevice9Impl_GetStreamSource,
1858 IDirect3DDevice9Impl_SetStreamSourceFreq,
1859 IDirect3DDevice9Impl_GetStreamSourceFreq,
1860 IDirect3DDevice9Impl_SetIndices,
1861 IDirect3DDevice9Impl_GetIndices,
1862 IDirect3DDevice9Impl_CreatePixelShader,
1863 IDirect3DDevice9Impl_SetPixelShader,
1864 IDirect3DDevice9Impl_GetPixelShader,
1865 IDirect3DDevice9Impl_SetPixelShaderConstantF,
1866 IDirect3DDevice9Impl_GetPixelShaderConstantF,
1867 IDirect3DDevice9Impl_SetPixelShaderConstantI,
1868 IDirect3DDevice9Impl_GetPixelShaderConstantI,
1869 IDirect3DDevice9Impl_SetPixelShaderConstantB,
1870 IDirect3DDevice9Impl_GetPixelShaderConstantB,
1871 IDirect3DDevice9Impl_DrawRectPatch,
1872 IDirect3DDevice9Impl_DrawTriPatch,
1873 IDirect3DDevice9Impl_DeletePatch,
1874 IDirect3DDevice9Impl_CreateQuery,
1875 /* IDirect3DDevice9Ex */
1876 IDirect3DDevice9ExImpl_SetConvolutionMonoKernel,
1877 IDirect3DDevice9ExImpl_ComposeRects,
1878 IDirect3DDevice9ExImpl_PresentEx,
1879 IDirect3DDevice9ExImpl_GetGPUThreadPriority,
1880 IDirect3DDevice9ExImpl_SetGPUThreadPriority,
1881 IDirect3DDevice9ExImpl_WaitForVBlank,
1882 IDirect3DDevice9ExImpl_CheckresourceResidency,
1883 IDirect3DDevice9ExImpl_SetMaximumFrameLatency,
1884 IDirect3DDevice9ExImpl_GetMaximumFrameLatency,
1885 IDirect3DDevice9ExImpl_CheckdeviceState,
1886 IDirect3DDevice9ExImpl_CreateRenderTargetEx,
1887 IDirect3DDevice9ExImpl_CreateOffscreenPlainSurfaceEx,
1888 IDirect3DDevice9ExImpl_CreateDepthStencilSurfaceEx,
1889 IDirect3DDevice9ExImpl_ResetEx,
1890 IDirect3DDevice9ExImpl_GetDisplayModeEx
1893 ULONG WINAPI D3D9CB_DestroySurface(IWineD3DSurface *pSurface) {
1894 IDirect3DSurface9Impl* surfaceParent;
1895 TRACE("(%p) call back\n", pSurface);
1897 IWineD3DSurface_GetParent(pSurface, (IUnknown **) &surfaceParent);
1898 /* GetParent's AddRef was forwarded to an object in destruction.
1899 * Releasing it here again would cause an endless recursion. */
1900 surfaceParent->forwardReference = NULL;
1901 return IDirect3DSurface9_Release((IDirect3DSurface9*) surfaceParent);
1904 /* IWineD3DDeviceParent IUnknown methods */
1906 static inline struct IDirect3DDevice9Impl *device_from_device_parent(IWineD3DDeviceParent *iface)
1908 return (struct IDirect3DDevice9Impl *)((char*)iface
1909 - FIELD_OFFSET(struct IDirect3DDevice9Impl, device_parent_vtbl));
1912 static HRESULT STDMETHODCALLTYPE device_parent_QueryInterface(IWineD3DDeviceParent *iface, REFIID riid, void **object)
1914 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
1915 return IDirect3DDevice9Impl_QueryInterface((IDirect3DDevice9Ex *)This, riid, object);
1918 static ULONG STDMETHODCALLTYPE device_parent_AddRef(IWineD3DDeviceParent *iface)
1920 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
1921 return IDirect3DDevice9Impl_AddRef((IDirect3DDevice9Ex *)This);
1924 static ULONG STDMETHODCALLTYPE device_parent_Release(IWineD3DDeviceParent *iface)
1926 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
1927 return IDirect3DDevice9Impl_Release((IDirect3DDevice9Ex *)This);
1930 /* IWineD3DDeviceParent methods */
1932 static void STDMETHODCALLTYPE device_parent_WineD3DDeviceCreated(IWineD3DDeviceParent *iface, IWineD3DDevice *device)
1934 TRACE("iface %p, device %p\n", iface, device);
1937 static HRESULT STDMETHODCALLTYPE device_parent_CreateSurface(IWineD3DDeviceParent *iface,
1938 IUnknown *superior, UINT width, UINT height, WINED3DFORMAT format, DWORD usage,
1939 WINED3DPOOL pool, UINT level, WINED3DCUBEMAP_FACES face, IWineD3DSurface **surface)
1941 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
1942 IDirect3DSurface9Impl *d3d_surface;
1943 BOOL lockable = TRUE;
1944 HRESULT hr;
1946 TRACE("iface %p, superior %p, width %u, height %u, format %#x, usage %#x,\n"
1947 "\tpool %#x, level %u, face %u, surface %p\n",
1948 iface, superior, width, height, format, usage, pool, level, face, surface);
1950 if (pool == D3DPOOL_DEFAULT && !(usage & D3DUSAGE_DYNAMIC)) lockable = FALSE;
1952 hr = IDirect3DDevice9Impl_CreateSurface((IDirect3DDevice9Ex *)This, width, height,
1953 d3dformat_from_wined3dformat(format), lockable, FALSE /* Discard */, level,
1954 (IDirect3DSurface9 **)&d3d_surface, D3DRTYPE_SURFACE, usage, pool,
1955 D3DMULTISAMPLE_NONE, 0 /* MultisampleQuality */, NULL);
1956 if (FAILED(hr))
1958 ERR("(%p) CreateSurface failed, returning %#x\n", iface, hr);
1959 return hr;
1962 *surface = d3d_surface->wineD3DSurface;
1963 d3d_surface->container = superior;
1964 IDirect3DDevice9Ex_Release(d3d_surface->parentDevice);
1965 d3d_surface->parentDevice = NULL;
1966 d3d_surface->forwardReference = superior;
1968 return hr;
1971 static HRESULT STDMETHODCALLTYPE device_parent_CreateRenderTarget(IWineD3DDeviceParent *iface,
1972 IUnknown *superior, UINT width, UINT height, WINED3DFORMAT format, WINED3DMULTISAMPLE_TYPE multisample_type,
1973 DWORD multisample_quality, BOOL lockable, IWineD3DSurface **surface)
1975 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
1976 IDirect3DSurface9Impl *d3d_surface;
1977 HRESULT hr;
1979 TRACE("iface %p, superior %p, width %u, height %u, format %#x, multisample_type %#x,\n"
1980 "\tmultisample_quality %u, lockable %u, surface %p\n",
1981 iface, superior, width, height, format, multisample_type, multisample_quality, lockable, surface);
1983 hr = IDirect3DDevice9Impl_CreateRenderTarget((IDirect3DDevice9Ex *)This, width, height,
1984 d3dformat_from_wined3dformat(format), multisample_type, multisample_quality, lockable,
1985 (IDirect3DSurface9 **)&d3d_surface, NULL);
1986 if (FAILED(hr))
1988 ERR("(%p) CreateRenderTarget failed, returning %#x\n", iface, hr);
1989 return hr;
1992 *surface = d3d_surface->wineD3DSurface;
1993 d3d_surface->container = superior;
1994 d3d_surface->isImplicit = TRUE;
1995 /* Implicit surfaces are created with an refcount of 0 */
1996 IDirect3DSurface9_Release((IDirect3DSurface9 *)d3d_surface);
1998 return hr;
2001 static HRESULT STDMETHODCALLTYPE device_parent_CreateDepthStencilSurface(IWineD3DDeviceParent *iface,
2002 IUnknown *superior, UINT width, UINT height, WINED3DFORMAT format, WINED3DMULTISAMPLE_TYPE multisample_type,
2003 DWORD multisample_quality, BOOL discard, IWineD3DSurface **surface)
2005 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
2006 IDirect3DSurface9Impl *d3d_surface;
2007 HRESULT hr;
2009 TRACE("iface %p, superior %p, width %u, height %u, format %#x, multisample_type %#x,\n"
2010 "\tmultisample_quality %u, discard %u, surface %p\n",
2011 iface, superior, width, height, format, multisample_type, multisample_quality, discard, surface);
2013 hr = IDirect3DDevice9Impl_CreateDepthStencilSurface((IDirect3DDevice9Ex *)This, width, height,
2014 d3dformat_from_wined3dformat(format), multisample_type, multisample_quality, discard,
2015 (IDirect3DSurface9 **)&d3d_surface, NULL);
2016 if (FAILED(hr))
2018 ERR("(%p) CreateDepthStencilSurface failed, returning %#x\n", iface, hr);
2019 return hr;
2022 *surface = d3d_surface->wineD3DSurface;
2023 d3d_surface->container = (IUnknown *)This;
2024 d3d_surface->isImplicit = TRUE;
2025 /* Implicit surfaces are created with an refcount of 0 */
2026 IDirect3DSurface9_Release((IDirect3DSurface9 *)d3d_surface);
2028 return hr;
2031 static HRESULT STDMETHODCALLTYPE device_parent_CreateVolume(IWineD3DDeviceParent *iface,
2032 IUnknown *superior, UINT width, UINT height, UINT depth, WINED3DFORMAT format,
2033 WINED3DPOOL pool, DWORD usage, IWineD3DVolume **volume)
2035 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
2036 IDirect3DVolume9Impl *object;
2037 HRESULT hr;
2039 TRACE("iface %p, superior %p, width %u, height %u, depth %u, format %#x, pool %#x, usage %#x, volume %p\n",
2040 iface, superior, width, height, depth, format, pool, usage, volume);
2042 /* Allocate the storage for the device */
2043 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2044 if (!object)
2046 FIXME("Allocation of memory failed\n");
2047 *volume = NULL;
2048 return D3DERR_OUTOFVIDEOMEMORY;
2051 object->lpVtbl = &Direct3DVolume9_Vtbl;
2052 object->ref = 1;
2053 hr = IWineD3DDevice_CreateVolume(This->WineD3DDevice, width, height, depth, usage & WINED3DUSAGE_MASK,
2054 format, pool, &object->wineD3DVolume, NULL, (IUnknown *)object);
2055 if (FAILED(hr))
2057 ERR("(%p) CreateVolume failed, returning %#x\n", iface, hr);
2058 HeapFree(GetProcessHeap(), 0, object);
2059 *volume = NULL;
2060 return hr;
2063 *volume = object->wineD3DVolume;
2064 object->container = superior;
2065 object->forwardReference = superior;
2067 TRACE("(%p) Created volume %p\n", iface, *volume);
2069 return hr;
2072 static HRESULT STDMETHODCALLTYPE device_parent_CreateSwapChain(IWineD3DDeviceParent *iface,
2073 WINED3DPRESENT_PARAMETERS *present_parameters, IWineD3DSwapChain **swapchain)
2075 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
2076 IDirect3DSwapChain9Impl *d3d_swapchain;
2077 D3DPRESENT_PARAMETERS local_parameters;
2078 HRESULT hr;
2080 TRACE("iface %p, present_parameters %p, swapchain %p\n", iface, present_parameters, swapchain);
2082 /* Copy the presentation parameters */
2083 local_parameters.BackBufferWidth = present_parameters->BackBufferWidth;
2084 local_parameters.BackBufferHeight = present_parameters->BackBufferHeight;
2085 local_parameters.BackBufferFormat = d3dformat_from_wined3dformat(present_parameters->BackBufferFormat);
2086 local_parameters.BackBufferCount = present_parameters->BackBufferCount;
2087 local_parameters.MultiSampleType = present_parameters->MultiSampleType;
2088 local_parameters.MultiSampleQuality = present_parameters->MultiSampleQuality;
2089 local_parameters.SwapEffect = present_parameters->SwapEffect;
2090 local_parameters.hDeviceWindow = present_parameters->hDeviceWindow;
2091 local_parameters.Windowed = present_parameters->Windowed;
2092 local_parameters.EnableAutoDepthStencil = present_parameters->EnableAutoDepthStencil;
2093 local_parameters.AutoDepthStencilFormat = d3dformat_from_wined3dformat(present_parameters->AutoDepthStencilFormat);
2094 local_parameters.Flags = present_parameters->Flags;
2095 local_parameters.FullScreen_RefreshRateInHz = present_parameters->FullScreen_RefreshRateInHz;
2096 local_parameters.PresentationInterval = present_parameters->PresentationInterval;
2098 hr = IDirect3DDevice9Impl_CreateAdditionalSwapChain((IDirect3DDevice9Ex *)This,
2099 &local_parameters, (IDirect3DSwapChain9 **)&d3d_swapchain);
2100 if (FAILED(hr))
2102 ERR("(%p) CreateAdditionalSwapChain failed, returning %#x\n", iface, hr);
2103 *swapchain = NULL;
2104 return hr;
2107 *swapchain = d3d_swapchain->wineD3DSwapChain;
2108 d3d_swapchain->isImplicit = TRUE;
2109 /* Implicit swap chains are created with an refcount of 0 */
2110 IDirect3DSwapChain9_Release((IDirect3DSwapChain9 *)d3d_swapchain);
2112 /* Copy back the presentation parameters */
2113 present_parameters->BackBufferWidth = local_parameters.BackBufferWidth;
2114 present_parameters->BackBufferHeight = local_parameters.BackBufferHeight;
2115 present_parameters->BackBufferFormat = wined3dformat_from_d3dformat(local_parameters.BackBufferFormat);
2116 present_parameters->BackBufferCount = local_parameters.BackBufferCount;
2117 present_parameters->MultiSampleType = local_parameters.MultiSampleType;
2118 present_parameters->MultiSampleQuality = local_parameters.MultiSampleQuality;
2119 present_parameters->SwapEffect = local_parameters.SwapEffect;
2120 present_parameters->hDeviceWindow = local_parameters.hDeviceWindow;
2121 present_parameters->Windowed = local_parameters.Windowed;
2122 present_parameters->EnableAutoDepthStencil = local_parameters.EnableAutoDepthStencil;
2123 present_parameters->AutoDepthStencilFormat = wined3dformat_from_d3dformat(local_parameters.AutoDepthStencilFormat);
2124 present_parameters->Flags = local_parameters.Flags;
2125 present_parameters->FullScreen_RefreshRateInHz = local_parameters.FullScreen_RefreshRateInHz;
2126 present_parameters->PresentationInterval = local_parameters.PresentationInterval;
2128 return hr;
2131 const IWineD3DDeviceParentVtbl d3d9_wined3d_device_parent_vtbl =
2133 /* IUnknown methods */
2134 device_parent_QueryInterface,
2135 device_parent_AddRef,
2136 device_parent_Release,
2137 /* IWineD3DDeviceParent methods */
2138 device_parent_WineD3DDeviceCreated,
2139 device_parent_CreateSurface,
2140 device_parent_CreateRenderTarget,
2141 device_parent_CreateDepthStencilSurface,
2142 device_parent_CreateVolume,
2143 device_parent_CreateSwapChain,