push eb25bf65c4616aa55a810ed5c29198b1a080b208
[wine/hacks.git] / dlls / d3d9 / device.c
blob8a3325ffc865eef14f728afb442e2ae72632f5f6
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 static UINT vertex_count_from_primitive_count(D3DPRIMITIVETYPE primitive_type, UINT primitive_count)
160 switch(primitive_type)
162 case D3DPT_POINTLIST:
163 return primitive_count;
165 case D3DPT_LINELIST:
166 return primitive_count * 2;
168 case D3DPT_LINESTRIP:
169 return primitive_count + 1;
171 case D3DPT_TRIANGLELIST:
172 return primitive_count * 3;
174 case D3DPT_TRIANGLESTRIP:
175 case D3DPT_TRIANGLEFAN:
176 return primitive_count + 2;
178 default:
179 FIXME("Unhandled primitive type %#x\n", primitive_type);
180 return 0;
184 /* IDirect3D IUnknown parts follow: */
185 static HRESULT WINAPI IDirect3DDevice9Impl_QueryInterface(LPDIRECT3DDEVICE9EX iface, REFIID riid, LPVOID* ppobj) {
186 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
187 IDirect3D9 *d3d;
188 IDirect3D9Impl *d3dimpl;
190 if (IsEqualGUID(riid, &IID_IUnknown)
191 || IsEqualGUID(riid, &IID_IDirect3DDevice9)) {
192 IDirect3DDevice9Ex_AddRef(iface);
193 *ppobj = This;
194 TRACE("Returning IDirect3DDevice9 interface at %p\n", *ppobj);
195 return S_OK;
196 } else if(IsEqualGUID(riid, &IID_IDirect3DDevice9Ex)) {
197 /* Find out if the creating d3d9 interface was created with Direct3DCreate9Ex.
198 * It doesn't matter with which function the device was created.
200 IDirect3DDevice9_GetDirect3D(iface, &d3d);
201 d3dimpl = (IDirect3D9Impl *) d3d;
203 if(d3dimpl->extended) {
204 *ppobj = iface;
205 IDirect3DDevice9Ex_AddRef((IDirect3DDevice9Ex *) *ppobj);
206 IDirect3D9_Release(d3d);
207 TRACE("Returning IDirect3DDevice9Ex interface at %p\n", *ppobj);
208 return S_OK;
209 } else {
210 WARN("IDirect3D9 instance wasn't created with CreateDirect3D9Ex, returning E_NOINTERFACE\n");
211 IDirect3D9_Release(d3d);
212 *ppobj = NULL;
213 return E_NOINTERFACE;
217 if (IsEqualGUID(riid, &IID_IWineD3DDeviceParent))
219 IUnknown_AddRef((IUnknown *)&This->device_parent_vtbl);
220 *ppobj = &This->device_parent_vtbl;
221 return S_OK;
224 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
225 *ppobj = NULL;
226 return E_NOINTERFACE;
229 static ULONG WINAPI IDirect3DDevice9Impl_AddRef(LPDIRECT3DDEVICE9EX iface) {
230 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
231 ULONG ref = InterlockedIncrement(&This->ref);
233 TRACE("(%p) : AddRef from %d\n", This, ref - 1);
235 return ref;
238 static ULONG WINAPI IDirect3DDevice9Impl_Release(LPDIRECT3DDEVICE9EX iface) {
239 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
240 ULONG ref;
242 if (This->inDestruction) return 0;
243 ref = InterlockedDecrement(&This->ref);
245 TRACE("(%p) : ReleaseRef to %d\n", This, ref);
247 if (ref == 0) {
248 unsigned i;
249 This->inDestruction = TRUE;
251 EnterCriticalSection(&d3d9_cs);
252 for(i = 0; i < This->numConvertedDecls; i++) {
253 /* Unless Wine is buggy or the app has a bug the refcount will be 0, because decls hold a reference to the
254 * device
256 IDirect3DVertexDeclaration9Impl_Destroy(This->convertedDecls[i]);
258 HeapFree(GetProcessHeap(), 0, This->convertedDecls);
260 IWineD3DDevice_Uninit3D(This->WineD3DDevice, D3D9CB_DestroyDepthStencilSurface, D3D9CB_DestroySwapChain);
261 IWineD3DDevice_Release(This->WineD3DDevice);
262 LeaveCriticalSection(&d3d9_cs);
263 HeapFree(GetProcessHeap(), 0, This);
265 return ref;
268 /* IDirect3DDevice Interface follow: */
269 static HRESULT WINAPI IDirect3DDevice9Impl_TestCooperativeLevel(LPDIRECT3DDEVICE9EX iface) {
270 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
271 HRESULT hr;
272 TRACE("(%p)\n", This);
274 EnterCriticalSection(&d3d9_cs);
275 hr = IWineD3DDevice_TestCooperativeLevel(This->WineD3DDevice);
276 LeaveCriticalSection(&d3d9_cs);
277 if(hr == WINED3D_OK && This->notreset) {
278 TRACE("D3D9 Device is marked not reset\n");
279 hr = D3DERR_DEVICENOTRESET;
282 return hr;
285 static UINT WINAPI IDirect3DDevice9Impl_GetAvailableTextureMem(LPDIRECT3DDEVICE9EX iface) {
286 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
287 HRESULT hr;
288 TRACE("(%p) Relay\n", This);
290 EnterCriticalSection(&d3d9_cs);
291 hr = IWineD3DDevice_GetAvailableTextureMem(This->WineD3DDevice);
292 LeaveCriticalSection(&d3d9_cs);
293 return hr;
296 static HRESULT WINAPI IDirect3DDevice9Impl_EvictManagedResources(LPDIRECT3DDEVICE9EX iface) {
297 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
298 HRESULT hr;
299 TRACE("(%p) : Relay\n", This);
301 EnterCriticalSection(&d3d9_cs);
302 hr = IWineD3DDevice_EvictManagedResources(This->WineD3DDevice);
303 LeaveCriticalSection(&d3d9_cs);
304 return hr;
307 static HRESULT WINAPI IDirect3DDevice9Impl_GetDirect3D(LPDIRECT3DDEVICE9EX iface, IDirect3D9** ppD3D9) {
308 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
309 HRESULT hr = D3D_OK;
310 IWineD3D* pWineD3D;
312 TRACE("(%p) Relay\n", This);
314 if (NULL == ppD3D9) {
315 return D3DERR_INVALIDCALL;
318 EnterCriticalSection(&d3d9_cs);
319 hr = IWineD3DDevice_GetDirect3D(This->WineD3DDevice, &pWineD3D);
320 if (hr == D3D_OK && pWineD3D != NULL)
322 IWineD3D_GetParent(pWineD3D,(IUnknown **)ppD3D9);
323 IWineD3D_Release(pWineD3D);
324 } else {
325 FIXME("Call to IWineD3DDevice_GetDirect3D failed\n");
326 *ppD3D9 = NULL;
328 TRACE("(%p) returning %p\n", This, *ppD3D9);
329 LeaveCriticalSection(&d3d9_cs);
330 return hr;
333 static HRESULT WINAPI IDirect3DDevice9Impl_GetDeviceCaps(LPDIRECT3DDEVICE9EX iface, D3DCAPS9* pCaps) {
334 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
335 HRESULT hrc = D3D_OK;
336 WINED3DCAPS *pWineCaps;
338 TRACE("(%p) : Relay pCaps %p\n", This, pCaps);
339 if(NULL == pCaps){
340 return D3DERR_INVALIDCALL;
342 pWineCaps = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WINED3DCAPS));
343 if(pWineCaps == NULL){
344 return D3DERR_INVALIDCALL; /* well this is what MSDN says to return */
347 memset(pCaps, 0, sizeof(*pCaps));
348 EnterCriticalSection(&d3d9_cs);
349 hrc = IWineD3DDevice_GetDeviceCaps(This->WineD3DDevice, pWineCaps);
350 LeaveCriticalSection(&d3d9_cs);
351 WINECAPSTOD3D9CAPS(pCaps, pWineCaps)
352 HeapFree(GetProcessHeap(), 0, pWineCaps);
354 /* Some functionality is implemented in d3d9.dll, not wined3d.dll. Add the needed caps */
355 pCaps->DevCaps2 |= D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES;
357 filter_caps(pCaps);
359 TRACE("Returning %p %p\n", This, pCaps);
360 return hrc;
363 static HRESULT WINAPI IDirect3DDevice9Impl_GetDisplayMode(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain, D3DDISPLAYMODE* pMode) {
364 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
365 HRESULT hr;
366 TRACE("(%p) Relay\n", This);
368 EnterCriticalSection(&d3d9_cs);
369 hr = IWineD3DDevice_GetDisplayMode(This->WineD3DDevice, iSwapChain, (WINED3DDISPLAYMODE *) pMode);
370 LeaveCriticalSection(&d3d9_cs);
372 if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format);
374 return hr;
377 static HRESULT WINAPI IDirect3DDevice9Impl_GetCreationParameters(LPDIRECT3DDEVICE9EX iface, D3DDEVICE_CREATION_PARAMETERS *pParameters) {
378 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
379 HRESULT hr;
380 TRACE("(%p) Relay\n", This);
382 EnterCriticalSection(&d3d9_cs);
383 hr = IWineD3DDevice_GetCreationParameters(This->WineD3DDevice, (WINED3DDEVICE_CREATION_PARAMETERS *) pParameters);
384 LeaveCriticalSection(&d3d9_cs);
385 return hr;
388 static HRESULT WINAPI IDirect3DDevice9Impl_SetCursorProperties(LPDIRECT3DDEVICE9EX iface, UINT XHotSpot, UINT YHotSpot, IDirect3DSurface9* pCursorBitmap) {
389 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
390 IDirect3DSurface9Impl *pSurface = (IDirect3DSurface9Impl*)pCursorBitmap;
391 HRESULT hr;
393 TRACE("(%p) Relay\n", This);
394 if(!pCursorBitmap) {
395 WARN("No cursor bitmap, returning WINED3DERR_INVALIDCALL\n");
396 return WINED3DERR_INVALIDCALL;
399 EnterCriticalSection(&d3d9_cs);
400 hr = IWineD3DDevice_SetCursorProperties(This->WineD3DDevice, XHotSpot, YHotSpot, pSurface->wineD3DSurface);
401 LeaveCriticalSection(&d3d9_cs);
402 return hr;
405 static void WINAPI IDirect3DDevice9Impl_SetCursorPosition(LPDIRECT3DDEVICE9EX iface, int XScreenSpace, int YScreenSpace, DWORD Flags) {
406 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
407 TRACE("(%p) Relay\n", This);
409 EnterCriticalSection(&d3d9_cs);
410 IWineD3DDevice_SetCursorPosition(This->WineD3DDevice, XScreenSpace, YScreenSpace, Flags);
411 LeaveCriticalSection(&d3d9_cs);
414 static BOOL WINAPI IDirect3DDevice9Impl_ShowCursor(LPDIRECT3DDEVICE9EX iface, BOOL bShow) {
415 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
416 BOOL ret;
417 TRACE("(%p) Relay\n", This);
419 EnterCriticalSection(&d3d9_cs);
420 ret = IWineD3DDevice_ShowCursor(This->WineD3DDevice, bShow);
421 LeaveCriticalSection(&d3d9_cs);
422 return ret;
425 static HRESULT WINAPI reset_enum_callback(IWineD3DResource *resource, void *data) {
426 BOOL *resources_ok = data;
427 WINED3DRESOURCETYPE type;
428 HRESULT ret = S_OK;
429 WINED3DSURFACE_DESC surface_desc;
430 WINED3DVOLUME_DESC volume_desc;
431 WINED3DINDEXBUFFER_DESC index_desc;
432 WINED3DVERTEXBUFFER_DESC vertex_desc;
433 WINED3DFORMAT dummy_format;
434 WINED3DMULTISAMPLE_TYPE dummy_multisampletype;
435 DWORD dummy_dword;
436 WINED3DPOOL pool = WINED3DPOOL_SCRATCH; /* a harmless pool */
437 IUnknown *parent;
439 type = IWineD3DResource_GetType(resource);
440 switch(type) {
441 case WINED3DRTYPE_SURFACE:
442 surface_desc.Format = &dummy_format;
443 surface_desc.Type = &type;
444 surface_desc.Usage = &dummy_dword;
445 surface_desc.Pool = &pool;
446 surface_desc.Size = &dummy_dword;
447 surface_desc.MultiSampleType = &dummy_multisampletype;
448 surface_desc.MultiSampleQuality = &dummy_dword;
449 surface_desc.Width = &dummy_dword;
450 surface_desc.Height = &dummy_dword;
452 IWineD3DSurface_GetDesc((IWineD3DSurface *) resource, &surface_desc);
453 break;
455 case WINED3DRTYPE_VOLUME:
456 volume_desc.Format = &dummy_format;
457 volume_desc.Type = &type;
458 volume_desc.Usage = &dummy_dword;
459 volume_desc.Pool = &pool;
460 volume_desc.Size = &dummy_dword;
461 volume_desc.Width = &dummy_dword;
462 volume_desc.Height = &dummy_dword;
463 volume_desc.Depth = &dummy_dword;
464 IWineD3DVolume_GetDesc((IWineD3DVolume *) resource, &volume_desc);
465 break;
467 case WINED3DRTYPE_INDEXBUFFER:
468 IWineD3DIndexBuffer_GetDesc((IWineD3DIndexBuffer *) resource, &index_desc);
469 pool = index_desc.Pool;
470 break;
472 case WINED3DRTYPE_VERTEXBUFFER:
473 IWineD3DBuffer_GetDesc((IWineD3DBuffer *)resource, &vertex_desc);
474 pool = vertex_desc.Pool;
475 break;
477 /* No need to check for textures. If there is a D3DPOOL_DEFAULT texture, there
478 * is a D3DPOOL_DEFAULT surface or volume as well
480 default:
481 break;
484 if(pool == WINED3DPOOL_DEFAULT) {
485 IWineD3DResource_GetParent(resource, &parent);
486 if(IUnknown_Release(parent) == 0) {
487 TRACE("Parent %p is an implicit resource with ref 0\n", parent);
488 } else {
489 WARN("Resource %p(wineD3D %p) with pool D3DPOOL_DEFAULT blocks the Reset call\n", parent, resource);
490 ret = S_FALSE;
491 *resources_ok = FALSE;
494 IWineD3DResource_Release(resource);
496 return ret;
499 static HRESULT WINAPI IDirect3DDevice9Impl_Reset(LPDIRECT3DDEVICE9EX iface, D3DPRESENT_PARAMETERS* pPresentationParameters) {
500 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
501 WINED3DPRESENT_PARAMETERS localParameters;
502 HRESULT hr;
503 BOOL resources_ok = TRUE;
504 UINT i;
506 TRACE("(%p) Relay pPresentationParameters(%p)\n", This, pPresentationParameters);
508 /* Reset states that hold a COM object. WineD3D holds an internal reference to set objects, because
509 * such objects can still be used for rendering after their external d3d9 object has been destroyed.
510 * These objects must not be enumerated. Unsetting them tells WineD3D that the application will not
511 * make use of the hidden reference and destroys the objects.
513 * Unsetting them is no problem, because the states are supposed to be reset anyway. If the validation
514 * below fails, the device is considered "lost", and _Reset and _Release are the only allowed calls
516 IWineD3DDevice_SetIndices(This->WineD3DDevice, NULL);
517 for(i = 0; i < 16; i++) {
518 IWineD3DDevice_SetStreamSource(This->WineD3DDevice, i, NULL, 0, 0);
520 for(i = 0; i < 16; i++) {
521 IWineD3DDevice_SetTexture(This->WineD3DDevice, i, NULL);
524 IWineD3DDevice_EnumResources(This->WineD3DDevice, reset_enum_callback, &resources_ok);
525 if(!resources_ok) {
526 WARN("The application is holding D3DPOOL_DEFAULT resources, rejecting reset\n");
527 This->notreset = TRUE;
528 return WINED3DERR_INVALIDCALL;
531 localParameters.BackBufferWidth = pPresentationParameters->BackBufferWidth;
532 localParameters.BackBufferHeight = pPresentationParameters->BackBufferHeight;
533 localParameters.BackBufferFormat = wined3dformat_from_d3dformat(pPresentationParameters->BackBufferFormat);
534 localParameters.BackBufferCount = pPresentationParameters->BackBufferCount;
535 localParameters.MultiSampleType = pPresentationParameters->MultiSampleType;
536 localParameters.MultiSampleQuality = pPresentationParameters->MultiSampleQuality;
537 localParameters.SwapEffect = pPresentationParameters->SwapEffect;
538 localParameters.hDeviceWindow = pPresentationParameters->hDeviceWindow;
539 localParameters.Windowed = pPresentationParameters->Windowed;
540 localParameters.EnableAutoDepthStencil = pPresentationParameters->EnableAutoDepthStencil;
541 localParameters.AutoDepthStencilFormat = wined3dformat_from_d3dformat(pPresentationParameters->AutoDepthStencilFormat);
542 localParameters.Flags = pPresentationParameters->Flags;
543 localParameters.FullScreen_RefreshRateInHz = pPresentationParameters->FullScreen_RefreshRateInHz;
544 localParameters.PresentationInterval = pPresentationParameters->PresentationInterval;
545 localParameters.AutoRestoreDisplayMode = TRUE;
547 EnterCriticalSection(&d3d9_cs);
548 hr = IWineD3DDevice_Reset(This->WineD3DDevice, &localParameters);
549 LeaveCriticalSection(&d3d9_cs);
550 if(FAILED(hr)) {
551 This->notreset = TRUE;
553 pPresentationParameters->BackBufferWidth = localParameters.BackBufferWidth;
554 pPresentationParameters->BackBufferHeight = localParameters.BackBufferHeight;
555 pPresentationParameters->BackBufferFormat = d3dformat_from_wined3dformat(localParameters.BackBufferFormat);
556 pPresentationParameters->BackBufferCount = localParameters.BackBufferCount;
557 pPresentationParameters->MultiSampleType = localParameters.MultiSampleType;
558 pPresentationParameters->MultiSampleQuality = localParameters.MultiSampleQuality;
559 pPresentationParameters->SwapEffect = localParameters.SwapEffect;
560 pPresentationParameters->hDeviceWindow = localParameters.hDeviceWindow;
561 pPresentationParameters->Windowed = localParameters.Windowed;
562 pPresentationParameters->EnableAutoDepthStencil = localParameters.EnableAutoDepthStencil;
563 pPresentationParameters->AutoDepthStencilFormat = d3dformat_from_wined3dformat(localParameters.AutoDepthStencilFormat);
564 pPresentationParameters->Flags = localParameters.Flags;
565 pPresentationParameters->FullScreen_RefreshRateInHz = localParameters.FullScreen_RefreshRateInHz;
566 pPresentationParameters->PresentationInterval = localParameters.PresentationInterval;
567 } else {
568 This->notreset = FALSE;
571 return hr;
574 static HRESULT WINAPI IDirect3DDevice9Impl_Present(LPDIRECT3DDEVICE9EX iface, CONST RECT* pSourceRect,CONST RECT* pDestRect,HWND hDestWindowOverride,CONST RGNDATA*
575 pDirtyRegion) {
576 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
577 HRESULT hr;
578 TRACE("(%p) Relay\n", This);
580 EnterCriticalSection(&d3d9_cs);
581 hr = IWineD3DDevice_Present(This->WineD3DDevice, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
582 LeaveCriticalSection(&d3d9_cs);
583 return hr;
586 static HRESULT WINAPI IDirect3DDevice9Impl_GetBackBuffer(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain, UINT BackBuffer, D3DBACKBUFFER_TYPE Type, IDirect3DSurface9 ** ppBackBuffer) {
587 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
588 IWineD3DSurface *retSurface = NULL;
589 HRESULT rc = D3D_OK;
591 TRACE("(%p) Relay\n", This);
593 EnterCriticalSection(&d3d9_cs);
594 rc = IWineD3DDevice_GetBackBuffer(This->WineD3DDevice, iSwapChain, BackBuffer, (WINED3DBACKBUFFER_TYPE) Type, &retSurface);
595 if (rc == D3D_OK && NULL != retSurface && NULL != ppBackBuffer) {
596 IWineD3DSurface_GetParent(retSurface, (IUnknown **)ppBackBuffer);
597 IWineD3DSurface_Release(retSurface);
599 LeaveCriticalSection(&d3d9_cs);
600 return rc;
602 static HRESULT WINAPI IDirect3DDevice9Impl_GetRasterStatus(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain, D3DRASTER_STATUS* pRasterStatus) {
603 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
604 HRESULT hr;
605 TRACE("(%p) Relay\n", This);
607 EnterCriticalSection(&d3d9_cs);
608 hr = IWineD3DDevice_GetRasterStatus(This->WineD3DDevice, iSwapChain, (WINED3DRASTER_STATUS *) pRasterStatus);
609 LeaveCriticalSection(&d3d9_cs);
610 return hr;
613 static HRESULT WINAPI IDirect3DDevice9Impl_SetDialogBoxMode(LPDIRECT3DDEVICE9EX iface, BOOL bEnableDialogs) {
614 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
615 HRESULT hr;
616 TRACE("(%p) Relay\n", This);
618 EnterCriticalSection(&d3d9_cs);
619 hr = IWineD3DDevice_SetDialogBoxMode(This->WineD3DDevice, bEnableDialogs);
620 LeaveCriticalSection(&d3d9_cs);
621 return hr;
624 static void WINAPI IDirect3DDevice9Impl_SetGammaRamp(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain, DWORD Flags, CONST D3DGAMMARAMP* pRamp) {
626 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
627 TRACE("(%p) Relay\n", This);
629 EnterCriticalSection(&d3d9_cs);
630 /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
631 IWineD3DDevice_SetGammaRamp(This->WineD3DDevice, iSwapChain, Flags, (CONST WINED3DGAMMARAMP *)pRamp);
632 LeaveCriticalSection(&d3d9_cs);
635 static void WINAPI IDirect3DDevice9Impl_GetGammaRamp(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain, D3DGAMMARAMP* pRamp) {
636 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
637 TRACE("(%p) Relay\n", This);
639 EnterCriticalSection(&d3d9_cs);
640 /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
641 IWineD3DDevice_GetGammaRamp(This->WineD3DDevice, iSwapChain, (WINED3DGAMMARAMP *) pRamp);
642 LeaveCriticalSection(&d3d9_cs);
646 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 ) {
647 HRESULT hrc;
648 IDirect3DSurface9Impl *object;
649 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
650 TRACE("(%p) Relay\n", This);
652 if(MultisampleQuality > 0){
653 FIXME("MultisampleQuality set to %d, bstituting 0\n", MultisampleQuality);
655 MultisampleQuality
656 [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.
659 MultisampleQuality=0;
661 /*FIXME: Check MAX bounds of MultisampleQuality*/
663 /* Allocate the storage for the device */
664 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DSurface9Impl));
665 if (NULL == object) {
666 FIXME("Allocation of memory failed\n");
667 return D3DERR_OUTOFVIDEOMEMORY;
670 object->lpVtbl = &Direct3DSurface9_Vtbl;
671 object->ref = 1;
673 TRACE("(%p) : w(%d) h(%d) fmt(%d) surf@%p\n", This, Width, Height, Format, *ppSurface);
675 hrc = IWineD3DDevice_CreateSurface(This->WineD3DDevice, Width, Height, wined3dformat_from_d3dformat(Format),
676 Lockable, Discard, Level, &object->wineD3DSurface, Type, Usage & WINED3DUSAGE_MASK, (WINED3DPOOL)Pool,
677 MultiSample, MultisampleQuality, pSharedHandle, SURFACE_OPENGL, (IUnknown *)object);
679 if (hrc != D3D_OK || NULL == object->wineD3DSurface) {
681 /* free up object */
682 FIXME("(%p) call to IWineD3DDevice_CreateSurface failed\n", This);
683 HeapFree(GetProcessHeap(), 0, object);
684 } else {
685 IDirect3DDevice9Ex_AddRef(iface);
686 object->parentDevice = iface;
687 TRACE("(%p) : Created surface %p\n", This, object);
688 *ppSurface = (LPDIRECT3DSURFACE9) object;
690 return hrc;
695 static HRESULT WINAPI IDirect3DDevice9Impl_CreateRenderTarget(LPDIRECT3DDEVICE9EX iface, UINT Width, UINT Height,
696 D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample,
697 DWORD MultisampleQuality, BOOL Lockable,
698 IDirect3DSurface9 **ppSurface, HANDLE* pSharedHandle) {
699 HRESULT hr;
700 TRACE("Relay\n");
702 /* Is this correct? */
703 EnterCriticalSection(&d3d9_cs);
704 hr = IDirect3DDevice9Impl_CreateSurface(iface,Width,Height,Format,Lockable,FALSE/*Discard*/, 0/*Level*/, ppSurface,D3DRTYPE_SURFACE,D3DUSAGE_RENDERTARGET,D3DPOOL_DEFAULT,MultiSample,MultisampleQuality,pSharedHandle);
705 LeaveCriticalSection(&d3d9_cs);
706 return hr;
709 static HRESULT WINAPI IDirect3DDevice9Impl_CreateDepthStencilSurface(LPDIRECT3DDEVICE9EX iface, UINT Width, UINT Height,
710 D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample,
711 DWORD MultisampleQuality, BOOL Discard,
712 IDirect3DSurface9 **ppSurface, HANDLE* pSharedHandle) {
713 HRESULT hr;
714 TRACE("Relay\n");
716 EnterCriticalSection(&d3d9_cs);
717 hr = IDirect3DDevice9Impl_CreateSurface(iface,Width,Height,Format,TRUE/* Lockable */,Discard, 0/* Level */
718 ,ppSurface,D3DRTYPE_SURFACE,D3DUSAGE_DEPTHSTENCIL,
719 D3DPOOL_DEFAULT,MultiSample,MultisampleQuality,pSharedHandle);
720 LeaveCriticalSection(&d3d9_cs);
721 return hr;
725 static HRESULT WINAPI IDirect3DDevice9Impl_UpdateSurface(LPDIRECT3DDEVICE9EX iface, IDirect3DSurface9* pSourceSurface, CONST RECT* pSourceRect, IDirect3DSurface9* pDestinationSurface, CONST POINT* pDestPoint) {
726 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
727 HRESULT hr;
728 TRACE("(%p) Relay\n" , This);
730 EnterCriticalSection(&d3d9_cs);
731 hr = IWineD3DDevice_UpdateSurface(This->WineD3DDevice, ((IDirect3DSurface9Impl *)pSourceSurface)->wineD3DSurface, pSourceRect, ((IDirect3DSurface9Impl *)pDestinationSurface)->wineD3DSurface, pDestPoint);
732 LeaveCriticalSection(&d3d9_cs);
733 return hr;
736 static HRESULT WINAPI IDirect3DDevice9Impl_UpdateTexture(LPDIRECT3DDEVICE9EX iface, IDirect3DBaseTexture9* pSourceTexture, IDirect3DBaseTexture9* pDestinationTexture) {
737 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
738 HRESULT hr;
739 TRACE("(%p) Relay\n" , This);
741 EnterCriticalSection(&d3d9_cs);
742 hr = IWineD3DDevice_UpdateTexture(This->WineD3DDevice, ((IDirect3DBaseTexture9Impl *)pSourceTexture)->wineD3DBaseTexture, ((IDirect3DBaseTexture9Impl *)pDestinationTexture)->wineD3DBaseTexture);
743 LeaveCriticalSection(&d3d9_cs);
744 return hr;
747 static HRESULT WINAPI IDirect3DDevice9Impl_GetRenderTargetData(LPDIRECT3DDEVICE9EX iface, IDirect3DSurface9* pRenderTarget, IDirect3DSurface9* pDestSurface) {
748 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
749 IDirect3DSurface9Impl *renderTarget = (IDirect3DSurface9Impl *)pRenderTarget;
750 IDirect3DSurface9Impl *destSurface = (IDirect3DSurface9Impl *)pDestSurface;
751 HRESULT hr;
752 TRACE("(%p)->(%p,%p)\n" , This, renderTarget, destSurface);
754 EnterCriticalSection(&d3d9_cs);
755 hr = IWineD3DSurface_BltFast(destSurface->wineD3DSurface, 0, 0, renderTarget->wineD3DSurface, NULL, WINEDDBLTFAST_NOCOLORKEY);
756 LeaveCriticalSection(&d3d9_cs);
757 return hr;
760 static HRESULT WINAPI IDirect3DDevice9Impl_GetFrontBufferData(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain, IDirect3DSurface9* pDestSurface) {
761 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
762 IDirect3DSurface9Impl *destSurface = (IDirect3DSurface9Impl *)pDestSurface;
763 HRESULT hr;
764 TRACE("(%p) Relay\n" , This);
766 EnterCriticalSection(&d3d9_cs);
767 hr = IWineD3DDevice_GetFrontBufferData(This->WineD3DDevice, iSwapChain, destSurface->wineD3DSurface);
768 LeaveCriticalSection(&d3d9_cs);
769 return hr;
772 static HRESULT WINAPI IDirect3DDevice9Impl_StretchRect(LPDIRECT3DDEVICE9EX iface, IDirect3DSurface9* pSourceSurface, CONST RECT* pSourceRect, IDirect3DSurface9* pDestSurface, CONST RECT* pDestRect, D3DTEXTUREFILTERTYPE Filter) {
773 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
774 IDirect3DSurface9Impl *src = (IDirect3DSurface9Impl *) pSourceSurface;
775 IDirect3DSurface9Impl *dst = (IDirect3DSurface9Impl *) pDestSurface;
776 HRESULT hr;
778 TRACE("(%p)->(%p,%p,%p,%p,%d)\n" , This, src, pSourceRect, dst, pDestRect, Filter);
779 EnterCriticalSection(&d3d9_cs);
780 hr = IWineD3DSurface_Blt(dst->wineD3DSurface, pDestRect, src->wineD3DSurface, pSourceRect, 0, NULL, Filter);
781 LeaveCriticalSection(&d3d9_cs);
782 return hr;
785 static HRESULT WINAPI IDirect3DDevice9Impl_ColorFill(LPDIRECT3DDEVICE9EX iface, IDirect3DSurface9* pSurface, CONST RECT* pRect, D3DCOLOR color) {
786 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
787 IDirect3DSurface9Impl *surface = (IDirect3DSurface9Impl *)pSurface;
788 WINED3DPOOL pool;
789 WINED3DRESOURCETYPE restype;
790 DWORD usage;
791 WINED3DSURFACE_DESC desc;
792 HRESULT hr;
793 TRACE("(%p) Relay\n" , This);
795 memset(&desc, 0, sizeof(desc));
796 desc.Usage = &usage;
797 desc.Pool = &pool;
798 desc.Type = &restype;
799 IWineD3DSurface_GetDesc(surface->wineD3DSurface, &desc);
801 /* This method is only allowed with surfaces that are render targets, or offscreen plain surfaces
802 * in D3DPOOL_DEFAULT
804 if(!(usage & WINED3DUSAGE_RENDERTARGET) && (pool != D3DPOOL_DEFAULT || restype != D3DRTYPE_SURFACE)) {
805 WARN("Surface is not a render target, or not a stand-alone D3DPOOL_DEFAULT surface\n");
806 return D3DERR_INVALIDCALL;
809 /* Colorfill can only be used on rendertarget surfaces, or offscreen plain surfaces in D3DPOOL_DEFAULT */
810 /* Note: D3DRECT is compatible with WINED3DRECT */
811 EnterCriticalSection(&d3d9_cs);
812 hr = IWineD3DDevice_ColorFill(This->WineD3DDevice, surface->wineD3DSurface, (CONST WINED3DRECT*)pRect, color);
813 LeaveCriticalSection(&d3d9_cs);
814 return hr;
817 static HRESULT WINAPI IDirect3DDevice9Impl_CreateOffscreenPlainSurface(LPDIRECT3DDEVICE9EX iface, UINT Width, UINT Height, D3DFORMAT Format, D3DPOOL Pool, IDirect3DSurface9 **ppSurface, HANDLE* pSharedHandle) {
818 HRESULT hr;
819 TRACE("Relay\n");
820 if(Pool == D3DPOOL_MANAGED ){
821 FIXME("Attempting to create a managed offscreen plain surface\n");
822 return D3DERR_INVALIDCALL;
825 'Off-screen plain surfaces are always lockable, regardless of their pool types.'
826 but then...
827 D3DPOOL_DEFAULT is the appropriate pool for use with the IDirect3DDevice9::StretchRect and IDirect3DDevice9::ColorFill.
828 Why, their always lockable?
829 should I change the usage to dynamic?
831 EnterCriticalSection(&d3d9_cs);
832 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);
833 LeaveCriticalSection(&d3d9_cs);
834 return hr;
837 /* TODO: move to wineD3D */
838 static HRESULT WINAPI IDirect3DDevice9Impl_SetRenderTarget(LPDIRECT3DDEVICE9EX iface, DWORD RenderTargetIndex, IDirect3DSurface9* pRenderTarget) {
839 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
840 IDirect3DSurface9Impl *pSurface = (IDirect3DSurface9Impl*)pRenderTarget;
841 HRESULT hr;
842 TRACE("(%p) Relay\n" , This);
844 EnterCriticalSection(&d3d9_cs);
845 hr = IWineD3DDevice_SetRenderTarget(This->WineD3DDevice, RenderTargetIndex, pSurface ? pSurface->wineD3DSurface : NULL);
846 LeaveCriticalSection(&d3d9_cs);
847 return hr;
850 static HRESULT WINAPI IDirect3DDevice9Impl_GetRenderTarget(LPDIRECT3DDEVICE9EX iface, DWORD RenderTargetIndex, IDirect3DSurface9 **ppRenderTarget) {
851 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
852 HRESULT hr = D3D_OK;
853 IWineD3DSurface *pRenderTarget;
855 TRACE("(%p) Relay\n" , This);
857 if (ppRenderTarget == NULL) {
858 return D3DERR_INVALIDCALL;
861 EnterCriticalSection(&d3d9_cs);
862 hr=IWineD3DDevice_GetRenderTarget(This->WineD3DDevice,RenderTargetIndex,&pRenderTarget);
864 if (hr == D3D_OK && pRenderTarget != NULL) {
865 IWineD3DSurface_GetParent(pRenderTarget,(IUnknown**)ppRenderTarget);
866 IWineD3DSurface_Release(pRenderTarget);
867 } else {
868 FIXME("Call to IWineD3DDevice_GetRenderTarget failed\n");
869 *ppRenderTarget = NULL;
871 LeaveCriticalSection(&d3d9_cs);
873 return hr;
876 static HRESULT WINAPI IDirect3DDevice9Impl_SetDepthStencilSurface(LPDIRECT3DDEVICE9EX iface, IDirect3DSurface9* pZStencilSurface) {
877 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
878 IDirect3DSurface9Impl *pSurface;
879 HRESULT hr;
880 TRACE("(%p) Relay\n" , This);
882 pSurface = (IDirect3DSurface9Impl*)pZStencilSurface;
883 EnterCriticalSection(&d3d9_cs);
884 hr = IWineD3DDevice_SetDepthStencilSurface(This->WineD3DDevice, NULL==pSurface ? NULL : pSurface->wineD3DSurface);
885 LeaveCriticalSection(&d3d9_cs);
886 return hr;
889 static HRESULT WINAPI IDirect3DDevice9Impl_GetDepthStencilSurface(LPDIRECT3DDEVICE9EX iface, IDirect3DSurface9 **ppZStencilSurface) {
890 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
891 HRESULT hr = D3D_OK;
892 IWineD3DSurface *pZStencilSurface;
894 TRACE("(%p) Relay\n" , This);
895 if(ppZStencilSurface == NULL){
896 return D3DERR_INVALIDCALL;
899 EnterCriticalSection(&d3d9_cs);
900 hr = IWineD3DDevice_GetDepthStencilSurface(This->WineD3DDevice,&pZStencilSurface);
901 if (hr == WINED3D_OK) {
902 IWineD3DSurface_GetParent(pZStencilSurface,(IUnknown**)ppZStencilSurface);
903 IWineD3DSurface_Release(pZStencilSurface);
904 } else {
905 if (hr != WINED3DERR_NOTFOUND)
906 WARN("Call to IWineD3DDevice_GetDepthStencilSurface failed with 0x%08x\n", hr);
907 *ppZStencilSurface = NULL;
909 LeaveCriticalSection(&d3d9_cs);
910 return hr;
913 static HRESULT WINAPI IDirect3DDevice9Impl_BeginScene(LPDIRECT3DDEVICE9EX iface) {
914 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
915 HRESULT hr;
916 TRACE("(%p) Relay\n" , This);
918 EnterCriticalSection(&d3d9_cs);
919 hr = IWineD3DDevice_BeginScene(This->WineD3DDevice);
920 LeaveCriticalSection(&d3d9_cs);
921 return hr;
924 static HRESULT WINAPI IDirect3DDevice9Impl_EndScene(LPDIRECT3DDEVICE9EX iface) {
925 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
926 HRESULT hr;
927 TRACE("(%p) Relay\n" , This);
929 EnterCriticalSection(&d3d9_cs);
930 hr = IWineD3DDevice_EndScene(This->WineD3DDevice);
931 LeaveCriticalSection(&d3d9_cs);
932 return hr;
935 static HRESULT WINAPI IDirect3DDevice9Impl_Clear(LPDIRECT3DDEVICE9EX iface, DWORD Count, CONST D3DRECT* pRects, DWORD Flags, D3DCOLOR Color, float Z, DWORD Stencil) {
936 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
937 HRESULT hr;
938 TRACE("(%p) Relay\n" , This);
940 /* Note: D3DRECT is compatible with WINED3DRECT */
941 EnterCriticalSection(&d3d9_cs);
942 hr = IWineD3DDevice_Clear(This->WineD3DDevice, Count, (CONST WINED3DRECT*) pRects, Flags, Color, Z, Stencil);
943 LeaveCriticalSection(&d3d9_cs);
944 return hr;
947 static HRESULT WINAPI IDirect3DDevice9Impl_SetTransform(LPDIRECT3DDEVICE9EX iface, D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX* lpMatrix) {
948 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
949 HRESULT hr;
950 TRACE("(%p) Relay\n" , This);
952 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
953 EnterCriticalSection(&d3d9_cs);
954 hr = IWineD3DDevice_SetTransform(This->WineD3DDevice, State, (CONST WINED3DMATRIX*) lpMatrix);
955 LeaveCriticalSection(&d3d9_cs);
956 return hr;
959 static HRESULT WINAPI IDirect3DDevice9Impl_GetTransform(LPDIRECT3DDEVICE9EX iface, D3DTRANSFORMSTATETYPE State, D3DMATRIX* pMatrix) {
960 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
961 TRACE("(%p) Relay\n" , This);
963 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
964 return IWineD3DDevice_GetTransform(This->WineD3DDevice, State, (WINED3DMATRIX*) pMatrix);
967 static HRESULT WINAPI IDirect3DDevice9Impl_MultiplyTransform(LPDIRECT3DDEVICE9EX iface, D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX* pMatrix) {
968 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
969 HRESULT hr;
970 TRACE("(%p) Relay\n" , This);
972 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
973 EnterCriticalSection(&d3d9_cs);
974 hr = IWineD3DDevice_MultiplyTransform(This->WineD3DDevice, State, (CONST WINED3DMATRIX*) pMatrix);
975 LeaveCriticalSection(&d3d9_cs);
976 return hr;
979 static HRESULT WINAPI IDirect3DDevice9Impl_SetViewport(LPDIRECT3DDEVICE9EX iface, CONST D3DVIEWPORT9* pViewport) {
980 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
981 HRESULT hr;
982 TRACE("(%p) Relay\n" , This);
984 /* Note: D3DVIEWPORT9 is compatible with WINED3DVIEWPORT */
985 EnterCriticalSection(&d3d9_cs);
986 hr = IWineD3DDevice_SetViewport(This->WineD3DDevice, (const WINED3DVIEWPORT *)pViewport);
987 LeaveCriticalSection(&d3d9_cs);
988 return hr;
991 static HRESULT WINAPI IDirect3DDevice9Impl_GetViewport(LPDIRECT3DDEVICE9EX iface, D3DVIEWPORT9* pViewport) {
992 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
993 HRESULT hr;
994 TRACE("(%p) Relay\n" , This);
996 /* Note: D3DVIEWPORT9 is compatible with WINED3DVIEWPORT */
997 EnterCriticalSection(&d3d9_cs);
998 hr = IWineD3DDevice_GetViewport(This->WineD3DDevice, (WINED3DVIEWPORT *)pViewport);
999 LeaveCriticalSection(&d3d9_cs);
1000 return hr;
1003 static HRESULT WINAPI IDirect3DDevice9Impl_SetMaterial(LPDIRECT3DDEVICE9EX iface, CONST D3DMATERIAL9* pMaterial) {
1004 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1005 HRESULT hr;
1006 TRACE("(%p) Relay\n" , This);
1008 /* Note: D3DMATERIAL9 is compatible with WINED3DMATERIAL */
1009 EnterCriticalSection(&d3d9_cs);
1010 hr = IWineD3DDevice_SetMaterial(This->WineD3DDevice, (const WINED3DMATERIAL *)pMaterial);
1011 LeaveCriticalSection(&d3d9_cs);
1012 return hr;
1015 static HRESULT WINAPI IDirect3DDevice9Impl_GetMaterial(LPDIRECT3DDEVICE9EX iface, D3DMATERIAL9* pMaterial) {
1016 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1017 HRESULT hr;
1018 TRACE("(%p) Relay\n" , This);
1020 /* Note: D3DMATERIAL9 is compatible with WINED3DMATERIAL */
1021 EnterCriticalSection(&d3d9_cs);
1022 hr = IWineD3DDevice_GetMaterial(This->WineD3DDevice, (WINED3DMATERIAL *)pMaterial);
1023 LeaveCriticalSection(&d3d9_cs);
1024 return hr;
1027 static HRESULT WINAPI IDirect3DDevice9Impl_SetLight(LPDIRECT3DDEVICE9EX iface, DWORD Index, CONST D3DLIGHT9* pLight) {
1028 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1029 HRESULT hr;
1030 TRACE("(%p) Relay\n" , This);
1032 /* Note: D3DLIGHT9 is compatible with WINED3DLIGHT */
1033 EnterCriticalSection(&d3d9_cs);
1034 hr = IWineD3DDevice_SetLight(This->WineD3DDevice, Index, (const WINED3DLIGHT *)pLight);
1035 LeaveCriticalSection(&d3d9_cs);
1036 return hr;
1039 static HRESULT WINAPI IDirect3DDevice9Impl_GetLight(LPDIRECT3DDEVICE9EX iface, DWORD Index, D3DLIGHT9* pLight) {
1040 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1041 HRESULT hr;
1042 TRACE("(%p) Relay\n" , This);
1044 /* Note: D3DLIGHT9 is compatible with WINED3DLIGHT */
1045 EnterCriticalSection(&d3d9_cs);
1046 hr = IWineD3DDevice_GetLight(This->WineD3DDevice, Index, (WINED3DLIGHT *)pLight);
1047 LeaveCriticalSection(&d3d9_cs);
1048 return hr;
1051 static HRESULT WINAPI IDirect3DDevice9Impl_LightEnable(LPDIRECT3DDEVICE9EX iface, DWORD Index, BOOL Enable) {
1052 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1053 HRESULT hr;
1054 TRACE("(%p) Relay\n" , This);
1056 EnterCriticalSection(&d3d9_cs);
1057 hr = IWineD3DDevice_SetLightEnable(This->WineD3DDevice, Index, Enable);
1058 LeaveCriticalSection(&d3d9_cs);
1059 return hr;
1062 static HRESULT WINAPI IDirect3DDevice9Impl_GetLightEnable(LPDIRECT3DDEVICE9EX iface, DWORD Index, BOOL* pEnable) {
1063 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1064 HRESULT hr;
1065 TRACE("(%p) Relay\n" , This);
1067 EnterCriticalSection(&d3d9_cs);
1068 hr = IWineD3DDevice_GetLightEnable(This->WineD3DDevice, Index, pEnable);
1069 LeaveCriticalSection(&d3d9_cs);
1070 return hr;
1073 static HRESULT WINAPI IDirect3DDevice9Impl_SetClipPlane(LPDIRECT3DDEVICE9EX iface, DWORD Index, CONST float* pPlane) {
1074 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1075 HRESULT hr;
1076 TRACE("(%p) Relay\n" , This);
1078 EnterCriticalSection(&d3d9_cs);
1079 hr = IWineD3DDevice_SetClipPlane(This->WineD3DDevice, Index, pPlane);
1080 LeaveCriticalSection(&d3d9_cs);
1081 return hr;
1084 static HRESULT WINAPI IDirect3DDevice9Impl_GetClipPlane(LPDIRECT3DDEVICE9EX iface, DWORD Index, float* pPlane) {
1085 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1086 HRESULT hr;
1087 TRACE("(%p) Relay\n" , This);
1089 EnterCriticalSection(&d3d9_cs);
1090 hr = IWineD3DDevice_GetClipPlane(This->WineD3DDevice, Index, pPlane);
1091 LeaveCriticalSection(&d3d9_cs);
1092 return hr;
1095 static HRESULT WINAPI IDirect3DDevice9Impl_SetRenderState(LPDIRECT3DDEVICE9EX iface, D3DRENDERSTATETYPE State, DWORD Value) {
1096 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1097 HRESULT hr;
1098 TRACE("(%p) Relay\n" , This);
1100 EnterCriticalSection(&d3d9_cs);
1101 hr = IWineD3DDevice_SetRenderState(This->WineD3DDevice, State, Value);
1102 LeaveCriticalSection(&d3d9_cs);
1103 return hr;
1106 static HRESULT WINAPI IDirect3DDevice9Impl_GetRenderState(LPDIRECT3DDEVICE9EX iface, D3DRENDERSTATETYPE State, DWORD* pValue) {
1107 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1108 HRESULT hr;
1109 TRACE("(%p) Relay\n" , This);
1111 EnterCriticalSection(&d3d9_cs);
1112 hr = IWineD3DDevice_GetRenderState(This->WineD3DDevice, State, pValue);
1113 LeaveCriticalSection(&d3d9_cs);
1114 return hr;
1117 static HRESULT WINAPI IDirect3DDevice9Impl_SetClipStatus(LPDIRECT3DDEVICE9EX iface, CONST D3DCLIPSTATUS9* pClipStatus) {
1118 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1119 HRESULT hr;
1120 TRACE("(%p) Relay\n" , This);
1122 EnterCriticalSection(&d3d9_cs);
1123 hr = IWineD3DDevice_SetClipStatus(This->WineD3DDevice, (const WINED3DCLIPSTATUS *)pClipStatus);
1124 LeaveCriticalSection(&d3d9_cs);
1125 return hr;
1128 static HRESULT WINAPI IDirect3DDevice9Impl_GetClipStatus(LPDIRECT3DDEVICE9EX iface, D3DCLIPSTATUS9* pClipStatus) {
1129 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1130 HRESULT hr;
1131 TRACE("(%p) Relay\n" , This);
1133 EnterCriticalSection(&d3d9_cs);
1134 hr = IWineD3DDevice_GetClipStatus(This->WineD3DDevice, (WINED3DCLIPSTATUS *)pClipStatus);
1135 LeaveCriticalSection(&d3d9_cs);
1136 return hr;
1139 static HRESULT WINAPI IDirect3DDevice9Impl_GetTexture(LPDIRECT3DDEVICE9EX iface, DWORD Stage, IDirect3DBaseTexture9 **ppTexture) {
1140 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1141 IWineD3DBaseTexture *retTexture = NULL;
1142 HRESULT rc = D3D_OK;
1144 TRACE("(%p) Relay\n" , This);
1146 if(ppTexture == NULL){
1147 return D3DERR_INVALIDCALL;
1150 EnterCriticalSection(&d3d9_cs);
1151 rc = IWineD3DDevice_GetTexture(This->WineD3DDevice, Stage, &retTexture);
1152 if (SUCCEEDED(rc) && NULL != retTexture) {
1153 IWineD3DBaseTexture_GetParent(retTexture, (IUnknown **)ppTexture);
1154 IWineD3DBaseTexture_Release(retTexture);
1155 } else {
1156 if(FAILED(rc)) {
1157 WARN("Call to get texture (%d) failed (%p)\n", Stage, retTexture);
1159 *ppTexture = NULL;
1161 LeaveCriticalSection(&d3d9_cs);
1163 return rc;
1166 static HRESULT WINAPI IDirect3DDevice9Impl_SetTexture(LPDIRECT3DDEVICE9EX iface, DWORD Stage, IDirect3DBaseTexture9* pTexture) {
1167 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1168 HRESULT hr;
1169 TRACE("(%p) Relay %d %p\n" , This, Stage, pTexture);
1171 EnterCriticalSection(&d3d9_cs);
1172 hr = IWineD3DDevice_SetTexture(This->WineD3DDevice, Stage,
1173 pTexture==NULL ? NULL:((IDirect3DBaseTexture9Impl *)pTexture)->wineD3DBaseTexture);
1174 LeaveCriticalSection(&d3d9_cs);
1175 return hr;
1178 static const WINED3DTEXTURESTAGESTATETYPE tss_lookup[] =
1180 WINED3DTSS_FORCE_DWORD, /* 0, unused */
1181 WINED3DTSS_COLOROP, /* 1, D3DTSS_COLOROP */
1182 WINED3DTSS_COLORARG1, /* 2, D3DTSS_COLORARG1 */
1183 WINED3DTSS_COLORARG2, /* 3, D3DTSS_COLORARG2 */
1184 WINED3DTSS_ALPHAOP, /* 4, D3DTSS_ALPHAOP */
1185 WINED3DTSS_ALPHAARG1, /* 5, D3DTSS_ALPHAARG1 */
1186 WINED3DTSS_ALPHAARG2, /* 6, D3DTSS_ALPHAARG2 */
1187 WINED3DTSS_BUMPENVMAT00, /* 7, D3DTSS_BUMPENVMAT00 */
1188 WINED3DTSS_BUMPENVMAT01, /* 8, D3DTSS_BUMPENVMAT01 */
1189 WINED3DTSS_BUMPENVMAT10, /* 9, D3DTSS_BUMPENVMAT10 */
1190 WINED3DTSS_BUMPENVMAT11, /* 10, D3DTSS_BUMPENVMAT11 */
1191 WINED3DTSS_TEXCOORDINDEX, /* 11, D3DTSS_TEXCOORDINDEX */
1192 WINED3DTSS_FORCE_DWORD, /* 12, unused */
1193 WINED3DTSS_FORCE_DWORD, /* 13, unused */
1194 WINED3DTSS_FORCE_DWORD, /* 14, unused */
1195 WINED3DTSS_FORCE_DWORD, /* 15, unused */
1196 WINED3DTSS_FORCE_DWORD, /* 16, unused */
1197 WINED3DTSS_FORCE_DWORD, /* 17, unused */
1198 WINED3DTSS_FORCE_DWORD, /* 18, unused */
1199 WINED3DTSS_FORCE_DWORD, /* 19, unused */
1200 WINED3DTSS_FORCE_DWORD, /* 20, unused */
1201 WINED3DTSS_FORCE_DWORD, /* 21, unused */
1202 WINED3DTSS_BUMPENVLSCALE, /* 22, D3DTSS_BUMPENVLSCALE */
1203 WINED3DTSS_BUMPENVLOFFSET, /* 23, D3DTSS_BUMPENVLOFFSET */
1204 WINED3DTSS_TEXTURETRANSFORMFLAGS, /* 24, D3DTSS_TEXTURETRANSFORMFLAGS */
1205 WINED3DTSS_FORCE_DWORD, /* 25, unused */
1206 WINED3DTSS_COLORARG0, /* 26, D3DTSS_COLORARG0 */
1207 WINED3DTSS_ALPHAARG0, /* 27, D3DTSS_ALPHAARG0 */
1208 WINED3DTSS_RESULTARG, /* 28, D3DTSS_RESULTARG */
1209 WINED3DTSS_FORCE_DWORD, /* 29, unused */
1210 WINED3DTSS_FORCE_DWORD, /* 30, unused */
1211 WINED3DTSS_FORCE_DWORD, /* 31, unused */
1212 WINED3DTSS_CONSTANT, /* 32, D3DTSS_CONSTANT */
1215 static HRESULT WINAPI IDirect3DDevice9Impl_GetTextureStageState(LPDIRECT3DDEVICE9EX iface, DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD* pValue) {
1216 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1217 HRESULT hr;
1218 TRACE("(%p) Relay\n" , This);
1220 EnterCriticalSection(&d3d9_cs);
1221 hr = IWineD3DDevice_GetTextureStageState(This->WineD3DDevice, Stage, tss_lookup[Type], pValue);
1222 LeaveCriticalSection(&d3d9_cs);
1223 return hr;
1226 static HRESULT WINAPI IDirect3DDevice9Impl_SetTextureStageState(LPDIRECT3DDEVICE9EX iface, DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD Value) {
1227 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1228 HRESULT hr;
1229 TRACE("(%p) Relay\n" , This);
1231 EnterCriticalSection(&d3d9_cs);
1232 hr = IWineD3DDevice_SetTextureStageState(This->WineD3DDevice, Stage, tss_lookup[Type], Value);
1233 LeaveCriticalSection(&d3d9_cs);
1234 return hr;
1237 static HRESULT WINAPI IDirect3DDevice9Impl_GetSamplerState(LPDIRECT3DDEVICE9EX iface, DWORD Sampler, D3DSAMPLERSTATETYPE Type, DWORD* pValue) {
1238 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1239 HRESULT hr;
1240 TRACE("(%p) Relay\n" , This);
1242 EnterCriticalSection(&d3d9_cs);
1243 hr = IWineD3DDevice_GetSamplerState(This->WineD3DDevice, Sampler, Type, pValue);
1244 LeaveCriticalSection(&d3d9_cs);
1245 return hr;
1248 static HRESULT WINAPI IDirect3DDevice9Impl_SetSamplerState(LPDIRECT3DDEVICE9EX iface, DWORD Sampler, D3DSAMPLERSTATETYPE Type, DWORD Value) {
1249 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1250 HRESULT hr;
1251 TRACE("(%p) Relay\n" , This);
1253 EnterCriticalSection(&d3d9_cs);
1254 hr = IWineD3DDevice_SetSamplerState(This->WineD3DDevice, Sampler, Type, Value);
1255 LeaveCriticalSection(&d3d9_cs);
1256 return hr;
1259 static HRESULT WINAPI IDirect3DDevice9Impl_ValidateDevice(LPDIRECT3DDEVICE9EX iface, DWORD* pNumPasses) {
1260 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1261 HRESULT hr;
1262 TRACE("(%p) Relay\n" , This);
1264 EnterCriticalSection(&d3d9_cs);
1265 hr = IWineD3DDevice_ValidateDevice(This->WineD3DDevice, pNumPasses);
1266 LeaveCriticalSection(&d3d9_cs);
1267 return hr;
1270 static HRESULT WINAPI IDirect3DDevice9Impl_SetPaletteEntries(LPDIRECT3DDEVICE9EX iface, UINT PaletteNumber, CONST PALETTEENTRY* pEntries) {
1271 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1272 HRESULT hr;
1273 TRACE("(%p) Relay\n" , This);
1275 EnterCriticalSection(&d3d9_cs);
1276 hr = IWineD3DDevice_SetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
1277 LeaveCriticalSection(&d3d9_cs);
1278 return hr;
1281 static HRESULT WINAPI IDirect3DDevice9Impl_GetPaletteEntries(LPDIRECT3DDEVICE9EX iface, UINT PaletteNumber, PALETTEENTRY* pEntries) {
1282 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1283 HRESULT hr;
1284 TRACE("(%p) Relay\n" , This);
1286 EnterCriticalSection(&d3d9_cs);
1287 hr = IWineD3DDevice_GetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
1288 LeaveCriticalSection(&d3d9_cs);
1289 return hr;
1292 static HRESULT WINAPI IDirect3DDevice9Impl_SetCurrentTexturePalette(LPDIRECT3DDEVICE9EX iface, UINT PaletteNumber) {
1293 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1294 HRESULT hr;
1295 TRACE("(%p) Relay\n" , This);
1297 EnterCriticalSection(&d3d9_cs);
1298 hr = IWineD3DDevice_SetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
1299 LeaveCriticalSection(&d3d9_cs);
1300 return hr;
1303 static HRESULT WINAPI IDirect3DDevice9Impl_GetCurrentTexturePalette(LPDIRECT3DDEVICE9EX iface, UINT* PaletteNumber) {
1304 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1305 HRESULT hr;
1306 TRACE("(%p) Relay\n" , This);
1308 EnterCriticalSection(&d3d9_cs);
1309 hr = IWineD3DDevice_GetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
1310 LeaveCriticalSection(&d3d9_cs);
1311 return hr;
1314 static HRESULT WINAPI IDirect3DDevice9Impl_SetScissorRect(LPDIRECT3DDEVICE9EX iface, CONST RECT* pRect) {
1315 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1316 HRESULT hr;
1317 TRACE("(%p) Relay\n" , This);
1319 EnterCriticalSection(&d3d9_cs);
1320 hr = IWineD3DDevice_SetScissorRect(This->WineD3DDevice, pRect);
1321 LeaveCriticalSection(&d3d9_cs);
1322 return hr;
1325 static HRESULT WINAPI IDirect3DDevice9Impl_GetScissorRect(LPDIRECT3DDEVICE9EX iface, RECT* pRect) {
1326 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1327 HRESULT hr;
1328 TRACE("(%p) Relay\n" , This);
1330 EnterCriticalSection(&d3d9_cs);
1331 hr = IWineD3DDevice_GetScissorRect(This->WineD3DDevice, pRect);
1332 LeaveCriticalSection(&d3d9_cs);
1333 return hr;
1336 static HRESULT WINAPI IDirect3DDevice9Impl_SetSoftwareVertexProcessing(LPDIRECT3DDEVICE9EX iface, BOOL bSoftware) {
1337 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1338 HRESULT hr;
1339 TRACE("(%p) Relay\n" , This);
1341 EnterCriticalSection(&d3d9_cs);
1342 hr = IWineD3DDevice_SetSoftwareVertexProcessing(This->WineD3DDevice, bSoftware);
1343 LeaveCriticalSection(&d3d9_cs);
1344 return hr;
1347 static BOOL WINAPI IDirect3DDevice9Impl_GetSoftwareVertexProcessing(LPDIRECT3DDEVICE9EX iface) {
1348 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1349 BOOL ret;
1350 TRACE("(%p) Relay\n" , This);
1352 EnterCriticalSection(&d3d9_cs);
1353 ret = IWineD3DDevice_GetSoftwareVertexProcessing(This->WineD3DDevice);
1354 LeaveCriticalSection(&d3d9_cs);
1355 return ret;
1358 static HRESULT WINAPI IDirect3DDevice9Impl_SetNPatchMode(LPDIRECT3DDEVICE9EX iface, float nSegments) {
1359 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1360 HRESULT hr;
1361 TRACE("(%p) Relay\n" , This);
1363 EnterCriticalSection(&d3d9_cs);
1364 hr = IWineD3DDevice_SetNPatchMode(This->WineD3DDevice, nSegments);
1365 LeaveCriticalSection(&d3d9_cs);
1366 return hr;
1369 static float WINAPI IDirect3DDevice9Impl_GetNPatchMode(LPDIRECT3DDEVICE9EX iface) {
1370 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1371 float ret;
1372 TRACE("(%p) Relay\n" , This);
1374 EnterCriticalSection(&d3d9_cs);
1375 ret = IWineD3DDevice_GetNPatchMode(This->WineD3DDevice);
1376 LeaveCriticalSection(&d3d9_cs);
1377 return ret;
1380 static HRESULT WINAPI IDirect3DDevice9Impl_DrawPrimitive(LPDIRECT3DDEVICE9EX iface, D3DPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT PrimitiveCount) {
1381 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1382 HRESULT hr;
1383 TRACE("(%p) Relay\n" , This);
1385 EnterCriticalSection(&d3d9_cs);
1386 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1387 hr = IWineD3DDevice_DrawPrimitive(This->WineD3DDevice, StartVertex,
1388 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount));
1389 LeaveCriticalSection(&d3d9_cs);
1390 return hr;
1393 static HRESULT WINAPI IDirect3DDevice9Impl_DrawIndexedPrimitive(LPDIRECT3DDEVICE9EX iface, D3DPRIMITIVETYPE PrimitiveType,
1394 INT BaseVertexIndex, UINT MinVertexIndex, UINT NumVertices, UINT startIndex, UINT primCount) {
1395 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1396 HRESULT hr;
1397 TRACE("(%p) Relay\n" , This);
1399 /* D3D8 passes the baseVertexIndex in SetIndices, and due to the stateblock functions wined3d has to work that way */
1400 EnterCriticalSection(&d3d9_cs);
1401 IWineD3DDevice_SetBaseVertexIndex(This->WineD3DDevice, BaseVertexIndex);
1402 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1403 hr = IWineD3DDevice_DrawIndexedPrimitive(This->WineD3DDevice, MinVertexIndex, NumVertices,
1404 startIndex, vertex_count_from_primitive_count(PrimitiveType, primCount));
1405 LeaveCriticalSection(&d3d9_cs);
1406 return hr;
1409 static HRESULT WINAPI IDirect3DDevice9Impl_DrawPrimitiveUP(LPDIRECT3DDEVICE9EX iface, D3DPRIMITIVETYPE PrimitiveType, UINT PrimitiveCount, CONST void* pVertexStreamZeroData, UINT VertexStreamZeroStride) {
1410 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1411 HRESULT hr;
1412 TRACE("(%p) Relay\n" , This);
1414 EnterCriticalSection(&d3d9_cs);
1415 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1416 hr = IWineD3DDevice_DrawPrimitiveUP(This->WineD3DDevice,
1417 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount),
1418 pVertexStreamZeroData, VertexStreamZeroStride);
1419 LeaveCriticalSection(&d3d9_cs);
1420 return hr;
1423 static HRESULT WINAPI IDirect3DDevice9Impl_DrawIndexedPrimitiveUP(LPDIRECT3DDEVICE9EX iface, D3DPRIMITIVETYPE PrimitiveType, UINT MinVertexIndex,
1424 UINT NumVertexIndices, UINT PrimitiveCount, CONST void* pIndexData,
1425 D3DFORMAT IndexDataFormat, CONST void* pVertexStreamZeroData, UINT VertexStreamZeroStride) {
1426 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1427 HRESULT hr;
1428 TRACE("(%p) Relay\n" , This);
1430 EnterCriticalSection(&d3d9_cs);
1431 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1432 hr = IWineD3DDevice_DrawIndexedPrimitiveUP(This->WineD3DDevice, MinVertexIndex, NumVertexIndices,
1433 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount), pIndexData,
1434 wined3dformat_from_d3dformat(IndexDataFormat), pVertexStreamZeroData, VertexStreamZeroStride);
1435 LeaveCriticalSection(&d3d9_cs);
1436 return hr;
1439 static HRESULT WINAPI IDirect3DDevice9Impl_ProcessVertices(LPDIRECT3DDEVICE9EX iface, UINT SrcStartIndex, UINT DestIndex, UINT VertexCount, IDirect3DVertexBuffer9* pDestBuffer, IDirect3DVertexDeclaration9* pVertexDecl, DWORD Flags) {
1440 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1441 IDirect3DVertexDeclaration9Impl *Decl = (IDirect3DVertexDeclaration9Impl *) pVertexDecl;
1442 HRESULT hr;
1443 TRACE("(%p) Relay\n" , This);
1445 EnterCriticalSection(&d3d9_cs);
1446 hr = IWineD3DDevice_ProcessVertices(This->WineD3DDevice,SrcStartIndex, DestIndex, VertexCount, ((IDirect3DVertexBuffer9Impl *)pDestBuffer)->wineD3DVertexBuffer, Decl ? Decl->wineD3DVertexDeclaration : NULL, Flags);
1447 LeaveCriticalSection(&d3d9_cs);
1448 return hr;
1451 static IDirect3DVertexDeclaration9 *getConvertedDecl(IDirect3DDevice9Impl *This, DWORD fvf) {
1452 HRESULT hr;
1453 D3DVERTEXELEMENT9* elements = NULL;
1454 IDirect3DVertexDeclaration9* pDecl = NULL;
1455 int p, low, high; /* deliberately signed */
1456 IDirect3DVertexDeclaration9 **convertedDecls = This->convertedDecls;
1458 TRACE("Searching for declaration for fvf %08x... ", fvf);
1460 low = 0;
1461 high = This->numConvertedDecls - 1;
1462 while(low <= high) {
1463 p = (low + high) >> 1;
1464 TRACE("%d ", p);
1465 if(((IDirect3DVertexDeclaration9Impl *) convertedDecls[p])->convFVF == fvf) {
1466 TRACE("found %p\n", convertedDecls[p]);
1467 return convertedDecls[p];
1468 } else if(((IDirect3DVertexDeclaration9Impl *) convertedDecls[p])->convFVF < fvf) {
1469 low = p + 1;
1470 } else {
1471 high = p - 1;
1474 TRACE("not found. Creating and inserting at position %d.\n", low);
1476 hr = vdecl_convert_fvf(fvf, &elements);
1477 if (hr != S_OK) return NULL;
1479 hr = IDirect3DDevice9Impl_CreateVertexDeclaration((IDirect3DDevice9Ex *) This, elements, &pDecl);
1480 HeapFree(GetProcessHeap(), 0, elements); /* CreateVertexDeclaration makes a copy */
1481 if (hr != S_OK) return NULL;
1483 if(This->declArraySize == This->numConvertedDecls) {
1484 int grow = max(This->declArraySize / 2, 8);
1485 convertedDecls = HeapReAlloc(GetProcessHeap(), 0, convertedDecls,
1486 sizeof(convertedDecls[0]) * (This->numConvertedDecls + grow));
1487 if(!convertedDecls) {
1488 /* This will destroy it */
1489 IDirect3DVertexDeclaration9_Release(pDecl);
1490 return NULL;
1492 This->convertedDecls = convertedDecls;
1493 This->declArraySize += grow;
1496 memmove(convertedDecls + low + 1, convertedDecls + low, sizeof(IDirect3DVertexDeclaration9Impl *) * (This->numConvertedDecls - low));
1497 convertedDecls[low] = pDecl;
1498 This->numConvertedDecls++;
1500 /* Will prevent the decl from being destroyed */
1501 ((IDirect3DVertexDeclaration9Impl *) pDecl)->convFVF = fvf;
1502 IDirect3DVertexDeclaration9_Release(pDecl); /* Does not destroy now */
1504 TRACE("Returning %p. %d decls in array\n", pDecl, This->numConvertedDecls);
1505 return pDecl;
1508 static HRESULT WINAPI IDirect3DDevice9Impl_SetFVF(LPDIRECT3DDEVICE9EX iface, DWORD FVF) {
1509 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1510 IDirect3DVertexDeclaration9 *decl;
1511 HRESULT hr;
1513 TRACE("(%p) Relay\n" , This);
1515 if (!FVF)
1517 WARN("%#x is not a valid FVF\n", FVF);
1518 return D3D_OK;
1521 EnterCriticalSection(&d3d9_cs);
1523 decl = getConvertedDecl(This, FVF);
1524 if (!decl)
1526 /* Any situation when this should happen, except out of memory? */
1527 ERR("Failed to create a converted vertex declaration\n");
1528 LeaveCriticalSection(&d3d9_cs);
1529 return D3DERR_DRIVERINTERNALERROR;
1532 hr = IDirect3DDevice9Impl_SetVertexDeclaration(iface, decl);
1533 if (FAILED(hr)) ERR("Failed to set vertex declaration\n");
1535 LeaveCriticalSection(&d3d9_cs);
1537 return hr;
1540 static HRESULT WINAPI IDirect3DDevice9Impl_GetFVF(LPDIRECT3DDEVICE9EX iface, DWORD* pFVF) {
1541 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1542 IDirect3DVertexDeclaration9 *decl;
1543 HRESULT hr;
1544 TRACE("(%p) Relay\n" , This);
1546 hr = IDirect3DDevice9_GetVertexDeclaration(iface, &decl);
1547 if (FAILED(hr))
1549 WARN("Failed to get vertex declaration, %#x\n", hr);
1550 *pFVF = 0;
1551 return hr;
1554 if (decl)
1556 *pFVF = ((IDirect3DVertexDeclaration9Impl *)decl)->convFVF;
1557 IDirect3DVertexDeclaration9_Release(decl);
1559 else
1561 *pFVF = 0;
1564 TRACE("Returning FVF %#x\n", *pFVF);
1566 return hr;
1569 static HRESULT WINAPI IDirect3DDevice9Impl_SetStreamSource(LPDIRECT3DDEVICE9EX iface, UINT StreamNumber, IDirect3DVertexBuffer9* pStreamData, UINT OffsetInBytes, UINT Stride) {
1570 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1571 HRESULT hr;
1572 TRACE("(%p) Relay\n" , This);
1574 EnterCriticalSection(&d3d9_cs);
1575 hr = IWineD3DDevice_SetStreamSource(This->WineD3DDevice, StreamNumber,
1576 pStreamData==NULL ? NULL:((IDirect3DVertexBuffer9Impl *)pStreamData)->wineD3DVertexBuffer,
1577 OffsetInBytes, Stride);
1578 LeaveCriticalSection(&d3d9_cs);
1579 return hr;
1582 static HRESULT WINAPI IDirect3DDevice9Impl_GetStreamSource(LPDIRECT3DDEVICE9EX iface, UINT StreamNumber, IDirect3DVertexBuffer9 **pStream, UINT* OffsetInBytes, UINT* pStride) {
1583 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1584 IWineD3DBuffer *retStream = NULL;
1585 HRESULT rc = D3D_OK;
1587 TRACE("(%p) Relay\n" , This);
1589 if(pStream == NULL){
1590 return D3DERR_INVALIDCALL;
1593 EnterCriticalSection(&d3d9_cs);
1594 rc = IWineD3DDevice_GetStreamSource(This->WineD3DDevice, StreamNumber, &retStream, OffsetInBytes, pStride);
1595 if (rc == D3D_OK && NULL != retStream) {
1596 IWineD3DBuffer_GetParent(retStream, (IUnknown **)pStream);
1597 IWineD3DBuffer_Release(retStream);
1598 }else{
1599 if (rc != D3D_OK){
1600 FIXME("Call to GetStreamSource failed %p %p\n", OffsetInBytes, pStride);
1602 *pStream = NULL;
1604 LeaveCriticalSection(&d3d9_cs);
1606 return rc;
1609 static HRESULT WINAPI IDirect3DDevice9Impl_SetStreamSourceFreq(LPDIRECT3DDEVICE9EX iface, UINT StreamNumber, UINT Divider) {
1610 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1611 HRESULT hr;
1612 TRACE("(%p) Relay\n" , This);
1614 EnterCriticalSection(&d3d9_cs);
1615 hr = IWineD3DDevice_SetStreamSourceFreq(This->WineD3DDevice, StreamNumber, Divider);
1616 LeaveCriticalSection(&d3d9_cs);
1617 return hr;
1620 static HRESULT WINAPI IDirect3DDevice9Impl_GetStreamSourceFreq(LPDIRECT3DDEVICE9EX iface, UINT StreamNumber, UINT* Divider) {
1621 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1622 HRESULT hr;
1623 TRACE("(%p) Relay\n" , This);
1625 EnterCriticalSection(&d3d9_cs);
1626 hr = IWineD3DDevice_GetStreamSourceFreq(This->WineD3DDevice, StreamNumber, Divider);
1627 LeaveCriticalSection(&d3d9_cs);
1628 return hr;
1631 static HRESULT WINAPI IDirect3DDevice9Impl_SetIndices(LPDIRECT3DDEVICE9EX iface, IDirect3DIndexBuffer9* pIndexData) {
1632 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1633 HRESULT hr;
1634 TRACE("(%p) Relay\n", This);
1636 EnterCriticalSection(&d3d9_cs);
1637 hr = IWineD3DDevice_SetIndices(This->WineD3DDevice,
1638 pIndexData ? ((IDirect3DIndexBuffer9Impl *)pIndexData)->wineD3DIndexBuffer : NULL);
1639 LeaveCriticalSection(&d3d9_cs);
1640 return hr;
1643 static HRESULT WINAPI IDirect3DDevice9Impl_GetIndices(LPDIRECT3DDEVICE9EX iface, IDirect3DIndexBuffer9 **ppIndexData) {
1644 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1645 IWineD3DIndexBuffer *retIndexData = NULL;
1646 HRESULT rc = D3D_OK;
1648 TRACE("(%p) Relay\n", This);
1650 if(ppIndexData == NULL){
1651 return D3DERR_INVALIDCALL;
1654 EnterCriticalSection(&d3d9_cs);
1655 rc = IWineD3DDevice_GetIndices(This->WineD3DDevice, &retIndexData);
1656 if (SUCCEEDED(rc) && retIndexData) {
1657 IWineD3DIndexBuffer_GetParent(retIndexData, (IUnknown **)ppIndexData);
1658 IWineD3DIndexBuffer_Release(retIndexData);
1659 } else {
1660 if (FAILED(rc)) FIXME("Call to GetIndices failed\n");
1661 *ppIndexData = NULL;
1663 LeaveCriticalSection(&d3d9_cs);
1664 return rc;
1667 static HRESULT WINAPI IDirect3DDevice9Impl_DrawRectPatch(LPDIRECT3DDEVICE9EX iface, UINT Handle, CONST float* pNumSegs, CONST D3DRECTPATCH_INFO* pRectPatchInfo) {
1668 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1669 HRESULT hr;
1670 TRACE("(%p) Relay\n", This);
1672 EnterCriticalSection(&d3d9_cs);
1673 hr = IWineD3DDevice_DrawRectPatch(This->WineD3DDevice, Handle, pNumSegs, (CONST WINED3DRECTPATCH_INFO *)pRectPatchInfo);
1674 LeaveCriticalSection(&d3d9_cs);
1675 return hr;
1678 static HRESULT WINAPI IDirect3DDevice9Impl_DrawTriPatch(LPDIRECT3DDEVICE9EX iface, UINT Handle, CONST float* pNumSegs, CONST D3DTRIPATCH_INFO* pTriPatchInfo) {
1679 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1680 HRESULT hr;
1681 TRACE("(%p) Relay\n", This);
1683 EnterCriticalSection(&d3d9_cs);
1684 hr = IWineD3DDevice_DrawTriPatch(This->WineD3DDevice, Handle, pNumSegs, (CONST WINED3DTRIPATCH_INFO *)pTriPatchInfo);
1685 LeaveCriticalSection(&d3d9_cs);
1686 return hr;
1689 static HRESULT WINAPI IDirect3DDevice9Impl_DeletePatch(LPDIRECT3DDEVICE9EX iface, UINT Handle) {
1690 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1691 HRESULT hr;
1692 TRACE("(%p) Relay\n", This);
1694 EnterCriticalSection(&d3d9_cs);
1695 hr = IWineD3DDevice_DeletePatch(This->WineD3DDevice, Handle);
1696 LeaveCriticalSection(&d3d9_cs);
1697 return hr;
1700 static HRESULT WINAPI IDirect3DDevice9ExImpl_SetConvolutionMonoKernel(LPDIRECT3DDEVICE9EX iface, UINT width, UINT height, float *rows, float *columns) {
1701 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1702 FIXME("(%p)->(%d, %d, %p, %p) Stub!\n", This, width, height, rows, columns);
1703 return WINED3DERR_INVALIDCALL;
1706 static HRESULT WINAPI IDirect3DDevice9ExImpl_ComposeRects(LPDIRECT3DDEVICE9EX iface, IDirect3DSurface9 *pSrc, IDirect3DDevice9 *pDst, IDirect3DVertexBuffer9 *pSrcRectDescs, UINT NumRects, IDirect3DVertexBuffer9 *pDstRectDescs, D3DCOMPOSERECTSOP Operation, int Xoffset, int Yoffset) {
1707 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1708 FIXME("(%p)->(%p, %p, %p, %d, %p, %d, %d, %d) Stub!\n", This, pSrc, pDst, pSrcRectDescs, NumRects, pDstRectDescs, Operation, Xoffset, Yoffset);
1709 return WINED3DERR_INVALIDCALL;
1712 static HRESULT WINAPI IDirect3DDevice9ExImpl_PresentEx(LPDIRECT3DDEVICE9EX iface, CONST RECT *pSourceRect, CONST RECT *pDestRect, HWND hDestWindowOverride, CONST RGNDATA *pDirtyRegion, DWORD dwFlags) {
1713 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1714 FIXME("(%p= -> (%p), %p, %p, %p, 0x%08x) Stub!\n", This, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion, dwFlags);
1715 return WINED3DERR_INVALIDCALL;
1718 static HRESULT WINAPI IDirect3DDevice9ExImpl_GetGPUThreadPriority(LPDIRECT3DDEVICE9EX iface, INT *pPriority) {
1719 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1720 FIXME("(%p)->(%p) Stub!\n", This, pPriority);
1721 return WINED3DERR_INVALIDCALL;
1724 static HRESULT WINAPI IDirect3DDevice9ExImpl_SetGPUThreadPriority(LPDIRECT3DDEVICE9EX iface, INT Priority) {
1725 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1726 FIXME("(%p)->(%d) Stub!\n", This, Priority);
1727 return WINED3DERR_INVALIDCALL;
1730 static HRESULT WINAPI IDirect3DDevice9ExImpl_WaitForVBlank(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain) {
1731 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1732 FIXME("(%p)->(%d) Stub!\n", This, iSwapChain);
1733 return WINED3DERR_INVALIDCALL;
1736 static HRESULT WINAPI IDirect3DDevice9ExImpl_CheckresourceResidency(LPDIRECT3DDEVICE9EX iface, IDirect3DResource9 ** pResourceArray, UINT32 Numresources) {
1737 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1738 FIXME("(%p)->(%p, %d) Stub!\n", This, pResourceArray, Numresources);
1739 return WINED3DERR_INVALIDCALL;
1742 static HRESULT WINAPI IDirect3DDevice9ExImpl_SetMaximumFrameLatency(LPDIRECT3DDEVICE9EX iface, UINT MaxLatency) {
1743 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1744 FIXME("(%p)->(%d) Stub!\n", This, MaxLatency);
1745 return WINED3DERR_INVALIDCALL;
1748 static HRESULT WINAPI IDirect3DDevice9ExImpl_GetMaximumFrameLatency(LPDIRECT3DDEVICE9EX iface, UINT *pMaxLatency) {
1749 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1750 FIXME("(%p)->(%p) Stub!\n", This, pMaxLatency);
1751 *pMaxLatency = 2;
1752 return WINED3DERR_INVALIDCALL;
1755 static HRESULT WINAPI IDirect3DDevice9ExImpl_CheckdeviceState(LPDIRECT3DDEVICE9EX iface, HWND hDestinationWindow) {
1756 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1757 FIXME("(%p)->(%p) Stub!\n", This, hDestinationWindow);
1758 return WINED3DERR_INVALIDCALL;
1761 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) {
1762 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1763 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);
1764 return WINED3DERR_INVALIDCALL;
1767 static HRESULT WINAPI IDirect3DDevice9ExImpl_CreateOffscreenPlainSurfaceEx(LPDIRECT3DDEVICE9EX iface, UINT Width, UINT Height, D3DFORMAT Format, D3DPOOL Pool, IDirect3DSurface9 **ppSurface, HANDLE *pSharedHandle, DWORD Usage) {
1768 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1769 FIXME("(%p)->(%d, %d, %d, %d, %p, %p, 0x%08x) Stub!\n", This, Width, Height, Format, Pool, ppSurface, pSharedHandle, Usage);
1770 return WINED3DERR_INVALIDCALL;
1773 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) {
1774 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1775 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);
1776 return WINED3DERR_INVALIDCALL;
1779 static HRESULT WINAPI IDirect3DDevice9ExImpl_ResetEx(LPDIRECT3DDEVICE9EX iface, D3DPRESENT_PARAMETERS *pPresentationParameters, D3DDISPLAYMODEEX *pFullscreenDisplayMode) {
1780 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1781 FIXME("(%p)->(%p) Stub!\n", This, pPresentationParameters);
1782 return WINED3DERR_INVALIDCALL;
1785 static HRESULT WINAPI IDirect3DDevice9ExImpl_GetDisplayModeEx(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain, D3DDISPLAYMODEEX *pMode, D3DDISPLAYROTATION *pRotation) {
1786 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1787 FIXME("(%p)->(%d, %p, %p) Stub!\n", This, iSwapChain, pMode, pRotation);
1788 return WINED3DERR_INVALIDCALL;
1791 const IDirect3DDevice9ExVtbl Direct3DDevice9_Vtbl =
1793 /* IUnknown */
1794 IDirect3DDevice9Impl_QueryInterface,
1795 IDirect3DDevice9Impl_AddRef,
1796 IDirect3DDevice9Impl_Release,
1797 /* IDirect3DDevice9 */
1798 IDirect3DDevice9Impl_TestCooperativeLevel,
1799 IDirect3DDevice9Impl_GetAvailableTextureMem,
1800 IDirect3DDevice9Impl_EvictManagedResources,
1801 IDirect3DDevice9Impl_GetDirect3D,
1802 IDirect3DDevice9Impl_GetDeviceCaps,
1803 IDirect3DDevice9Impl_GetDisplayMode,
1804 IDirect3DDevice9Impl_GetCreationParameters,
1805 IDirect3DDevice9Impl_SetCursorProperties,
1806 IDirect3DDevice9Impl_SetCursorPosition,
1807 IDirect3DDevice9Impl_ShowCursor,
1808 IDirect3DDevice9Impl_CreateAdditionalSwapChain,
1809 IDirect3DDevice9Impl_GetSwapChain,
1810 IDirect3DDevice9Impl_GetNumberOfSwapChains,
1811 IDirect3DDevice9Impl_Reset,
1812 IDirect3DDevice9Impl_Present,
1813 IDirect3DDevice9Impl_GetBackBuffer,
1814 IDirect3DDevice9Impl_GetRasterStatus,
1815 IDirect3DDevice9Impl_SetDialogBoxMode,
1816 IDirect3DDevice9Impl_SetGammaRamp,
1817 IDirect3DDevice9Impl_GetGammaRamp,
1818 IDirect3DDevice9Impl_CreateTexture,
1819 IDirect3DDevice9Impl_CreateVolumeTexture,
1820 IDirect3DDevice9Impl_CreateCubeTexture,
1821 IDirect3DDevice9Impl_CreateVertexBuffer,
1822 IDirect3DDevice9Impl_CreateIndexBuffer,
1823 IDirect3DDevice9Impl_CreateRenderTarget,
1824 IDirect3DDevice9Impl_CreateDepthStencilSurface,
1825 IDirect3DDevice9Impl_UpdateSurface,
1826 IDirect3DDevice9Impl_UpdateTexture,
1827 IDirect3DDevice9Impl_GetRenderTargetData,
1828 IDirect3DDevice9Impl_GetFrontBufferData,
1829 IDirect3DDevice9Impl_StretchRect,
1830 IDirect3DDevice9Impl_ColorFill,
1831 IDirect3DDevice9Impl_CreateOffscreenPlainSurface,
1832 IDirect3DDevice9Impl_SetRenderTarget,
1833 IDirect3DDevice9Impl_GetRenderTarget,
1834 IDirect3DDevice9Impl_SetDepthStencilSurface,
1835 IDirect3DDevice9Impl_GetDepthStencilSurface,
1836 IDirect3DDevice9Impl_BeginScene,
1837 IDirect3DDevice9Impl_EndScene,
1838 IDirect3DDevice9Impl_Clear,
1839 IDirect3DDevice9Impl_SetTransform,
1840 IDirect3DDevice9Impl_GetTransform,
1841 IDirect3DDevice9Impl_MultiplyTransform,
1842 IDirect3DDevice9Impl_SetViewport,
1843 IDirect3DDevice9Impl_GetViewport,
1844 IDirect3DDevice9Impl_SetMaterial,
1845 IDirect3DDevice9Impl_GetMaterial,
1846 IDirect3DDevice9Impl_SetLight,
1847 IDirect3DDevice9Impl_GetLight,
1848 IDirect3DDevice9Impl_LightEnable,
1849 IDirect3DDevice9Impl_GetLightEnable,
1850 IDirect3DDevice9Impl_SetClipPlane,
1851 IDirect3DDevice9Impl_GetClipPlane,
1852 IDirect3DDevice9Impl_SetRenderState,
1853 IDirect3DDevice9Impl_GetRenderState,
1854 IDirect3DDevice9Impl_CreateStateBlock,
1855 IDirect3DDevice9Impl_BeginStateBlock,
1856 IDirect3DDevice9Impl_EndStateBlock,
1857 IDirect3DDevice9Impl_SetClipStatus,
1858 IDirect3DDevice9Impl_GetClipStatus,
1859 IDirect3DDevice9Impl_GetTexture,
1860 IDirect3DDevice9Impl_SetTexture,
1861 IDirect3DDevice9Impl_GetTextureStageState,
1862 IDirect3DDevice9Impl_SetTextureStageState,
1863 IDirect3DDevice9Impl_GetSamplerState,
1864 IDirect3DDevice9Impl_SetSamplerState,
1865 IDirect3DDevice9Impl_ValidateDevice,
1866 IDirect3DDevice9Impl_SetPaletteEntries,
1867 IDirect3DDevice9Impl_GetPaletteEntries,
1868 IDirect3DDevice9Impl_SetCurrentTexturePalette,
1869 IDirect3DDevice9Impl_GetCurrentTexturePalette,
1870 IDirect3DDevice9Impl_SetScissorRect,
1871 IDirect3DDevice9Impl_GetScissorRect,
1872 IDirect3DDevice9Impl_SetSoftwareVertexProcessing,
1873 IDirect3DDevice9Impl_GetSoftwareVertexProcessing,
1874 IDirect3DDevice9Impl_SetNPatchMode,
1875 IDirect3DDevice9Impl_GetNPatchMode,
1876 IDirect3DDevice9Impl_DrawPrimitive,
1877 IDirect3DDevice9Impl_DrawIndexedPrimitive,
1878 IDirect3DDevice9Impl_DrawPrimitiveUP,
1879 IDirect3DDevice9Impl_DrawIndexedPrimitiveUP,
1880 IDirect3DDevice9Impl_ProcessVertices,
1881 IDirect3DDevice9Impl_CreateVertexDeclaration,
1882 IDirect3DDevice9Impl_SetVertexDeclaration,
1883 IDirect3DDevice9Impl_GetVertexDeclaration,
1884 IDirect3DDevice9Impl_SetFVF,
1885 IDirect3DDevice9Impl_GetFVF,
1886 IDirect3DDevice9Impl_CreateVertexShader,
1887 IDirect3DDevice9Impl_SetVertexShader,
1888 IDirect3DDevice9Impl_GetVertexShader,
1889 IDirect3DDevice9Impl_SetVertexShaderConstantF,
1890 IDirect3DDevice9Impl_GetVertexShaderConstantF,
1891 IDirect3DDevice9Impl_SetVertexShaderConstantI,
1892 IDirect3DDevice9Impl_GetVertexShaderConstantI,
1893 IDirect3DDevice9Impl_SetVertexShaderConstantB,
1894 IDirect3DDevice9Impl_GetVertexShaderConstantB,
1895 IDirect3DDevice9Impl_SetStreamSource,
1896 IDirect3DDevice9Impl_GetStreamSource,
1897 IDirect3DDevice9Impl_SetStreamSourceFreq,
1898 IDirect3DDevice9Impl_GetStreamSourceFreq,
1899 IDirect3DDevice9Impl_SetIndices,
1900 IDirect3DDevice9Impl_GetIndices,
1901 IDirect3DDevice9Impl_CreatePixelShader,
1902 IDirect3DDevice9Impl_SetPixelShader,
1903 IDirect3DDevice9Impl_GetPixelShader,
1904 IDirect3DDevice9Impl_SetPixelShaderConstantF,
1905 IDirect3DDevice9Impl_GetPixelShaderConstantF,
1906 IDirect3DDevice9Impl_SetPixelShaderConstantI,
1907 IDirect3DDevice9Impl_GetPixelShaderConstantI,
1908 IDirect3DDevice9Impl_SetPixelShaderConstantB,
1909 IDirect3DDevice9Impl_GetPixelShaderConstantB,
1910 IDirect3DDevice9Impl_DrawRectPatch,
1911 IDirect3DDevice9Impl_DrawTriPatch,
1912 IDirect3DDevice9Impl_DeletePatch,
1913 IDirect3DDevice9Impl_CreateQuery,
1914 /* IDirect3DDevice9Ex */
1915 IDirect3DDevice9ExImpl_SetConvolutionMonoKernel,
1916 IDirect3DDevice9ExImpl_ComposeRects,
1917 IDirect3DDevice9ExImpl_PresentEx,
1918 IDirect3DDevice9ExImpl_GetGPUThreadPriority,
1919 IDirect3DDevice9ExImpl_SetGPUThreadPriority,
1920 IDirect3DDevice9ExImpl_WaitForVBlank,
1921 IDirect3DDevice9ExImpl_CheckresourceResidency,
1922 IDirect3DDevice9ExImpl_SetMaximumFrameLatency,
1923 IDirect3DDevice9ExImpl_GetMaximumFrameLatency,
1924 IDirect3DDevice9ExImpl_CheckdeviceState,
1925 IDirect3DDevice9ExImpl_CreateRenderTargetEx,
1926 IDirect3DDevice9ExImpl_CreateOffscreenPlainSurfaceEx,
1927 IDirect3DDevice9ExImpl_CreateDepthStencilSurfaceEx,
1928 IDirect3DDevice9ExImpl_ResetEx,
1929 IDirect3DDevice9ExImpl_GetDisplayModeEx
1932 ULONG WINAPI D3D9CB_DestroySurface(IWineD3DSurface *pSurface) {
1933 IDirect3DSurface9Impl* surfaceParent;
1934 TRACE("(%p) call back\n", pSurface);
1936 IWineD3DSurface_GetParent(pSurface, (IUnknown **) &surfaceParent);
1937 /* GetParent's AddRef was forwarded to an object in destruction.
1938 * Releasing it here again would cause an endless recursion. */
1939 surfaceParent->forwardReference = NULL;
1940 return IDirect3DSurface9_Release((IDirect3DSurface9*) surfaceParent);
1943 /* IWineD3DDeviceParent IUnknown methods */
1945 static inline struct IDirect3DDevice9Impl *device_from_device_parent(IWineD3DDeviceParent *iface)
1947 return (struct IDirect3DDevice9Impl *)((char*)iface
1948 - FIELD_OFFSET(struct IDirect3DDevice9Impl, device_parent_vtbl));
1951 static HRESULT STDMETHODCALLTYPE device_parent_QueryInterface(IWineD3DDeviceParent *iface, REFIID riid, void **object)
1953 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
1954 return IDirect3DDevice9Impl_QueryInterface((IDirect3DDevice9Ex *)This, riid, object);
1957 static ULONG STDMETHODCALLTYPE device_parent_AddRef(IWineD3DDeviceParent *iface)
1959 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
1960 return IDirect3DDevice9Impl_AddRef((IDirect3DDevice9Ex *)This);
1963 static ULONG STDMETHODCALLTYPE device_parent_Release(IWineD3DDeviceParent *iface)
1965 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
1966 return IDirect3DDevice9Impl_Release((IDirect3DDevice9Ex *)This);
1969 /* IWineD3DDeviceParent methods */
1971 static void STDMETHODCALLTYPE device_parent_WineD3DDeviceCreated(IWineD3DDeviceParent *iface, IWineD3DDevice *device)
1973 TRACE("iface %p, device %p\n", iface, device);
1976 static HRESULT STDMETHODCALLTYPE device_parent_CreateSurface(IWineD3DDeviceParent *iface,
1977 IUnknown *superior, UINT width, UINT height, WINED3DFORMAT format, DWORD usage,
1978 WINED3DPOOL pool, UINT level, WINED3DCUBEMAP_FACES face, IWineD3DSurface **surface)
1980 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
1981 IDirect3DSurface9Impl *d3d_surface;
1982 BOOL lockable = TRUE;
1983 HRESULT hr;
1985 TRACE("iface %p, superior %p, width %u, height %u, format %#x, usage %#x,\n"
1986 "\tpool %#x, level %u, face %u, surface %p\n",
1987 iface, superior, width, height, format, usage, pool, level, face, surface);
1989 if (pool == D3DPOOL_DEFAULT && !(usage & D3DUSAGE_DYNAMIC)) lockable = FALSE;
1991 hr = IDirect3DDevice9Impl_CreateSurface((IDirect3DDevice9Ex *)This, width, height,
1992 d3dformat_from_wined3dformat(format), lockable, FALSE /* Discard */, level,
1993 (IDirect3DSurface9 **)&d3d_surface, D3DRTYPE_SURFACE, usage, pool,
1994 D3DMULTISAMPLE_NONE, 0 /* MultisampleQuality */, NULL);
1995 if (FAILED(hr))
1997 ERR("(%p) CreateSurface failed, returning %#x\n", iface, hr);
1998 return hr;
2001 *surface = d3d_surface->wineD3DSurface;
2002 d3d_surface->container = superior;
2003 IDirect3DDevice9Ex_Release(d3d_surface->parentDevice);
2004 d3d_surface->parentDevice = NULL;
2005 d3d_surface->forwardReference = superior;
2007 return hr;
2010 static HRESULT STDMETHODCALLTYPE device_parent_CreateRenderTarget(IWineD3DDeviceParent *iface,
2011 IUnknown *superior, UINT width, UINT height, WINED3DFORMAT format, WINED3DMULTISAMPLE_TYPE multisample_type,
2012 DWORD multisample_quality, BOOL lockable, IWineD3DSurface **surface)
2014 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
2015 IDirect3DSurface9Impl *d3d_surface;
2016 HRESULT hr;
2018 TRACE("iface %p, superior %p, width %u, height %u, format %#x, multisample_type %#x,\n"
2019 "\tmultisample_quality %u, lockable %u, surface %p\n",
2020 iface, superior, width, height, format, multisample_type, multisample_quality, lockable, surface);
2022 hr = IDirect3DDevice9Impl_CreateRenderTarget((IDirect3DDevice9Ex *)This, width, height,
2023 d3dformat_from_wined3dformat(format), multisample_type, multisample_quality, lockable,
2024 (IDirect3DSurface9 **)&d3d_surface, NULL);
2025 if (FAILED(hr))
2027 ERR("(%p) CreateRenderTarget failed, returning %#x\n", iface, hr);
2028 return hr;
2031 *surface = d3d_surface->wineD3DSurface;
2032 d3d_surface->container = superior;
2033 d3d_surface->isImplicit = TRUE;
2034 /* Implicit surfaces are created with an refcount of 0 */
2035 IDirect3DSurface9_Release((IDirect3DSurface9 *)d3d_surface);
2037 return hr;
2040 static HRESULT STDMETHODCALLTYPE device_parent_CreateDepthStencilSurface(IWineD3DDeviceParent *iface,
2041 IUnknown *superior, UINT width, UINT height, WINED3DFORMAT format, WINED3DMULTISAMPLE_TYPE multisample_type,
2042 DWORD multisample_quality, BOOL discard, IWineD3DSurface **surface)
2044 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
2045 IDirect3DSurface9Impl *d3d_surface;
2046 HRESULT hr;
2048 TRACE("iface %p, superior %p, width %u, height %u, format %#x, multisample_type %#x,\n"
2049 "\tmultisample_quality %u, discard %u, surface %p\n",
2050 iface, superior, width, height, format, multisample_type, multisample_quality, discard, surface);
2052 hr = IDirect3DDevice9Impl_CreateDepthStencilSurface((IDirect3DDevice9Ex *)This, width, height,
2053 d3dformat_from_wined3dformat(format), multisample_type, multisample_quality, discard,
2054 (IDirect3DSurface9 **)&d3d_surface, NULL);
2055 if (FAILED(hr))
2057 ERR("(%p) CreateDepthStencilSurface failed, returning %#x\n", iface, hr);
2058 return hr;
2061 *surface = d3d_surface->wineD3DSurface;
2062 d3d_surface->container = (IUnknown *)This;
2063 d3d_surface->isImplicit = TRUE;
2064 /* Implicit surfaces are created with an refcount of 0 */
2065 IDirect3DSurface9_Release((IDirect3DSurface9 *)d3d_surface);
2067 return hr;
2070 static HRESULT STDMETHODCALLTYPE device_parent_CreateVolume(IWineD3DDeviceParent *iface,
2071 IUnknown *superior, UINT width, UINT height, UINT depth, WINED3DFORMAT format,
2072 WINED3DPOOL pool, DWORD usage, IWineD3DVolume **volume)
2074 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
2075 IDirect3DVolume9Impl *object;
2076 HRESULT hr;
2078 TRACE("iface %p, superior %p, width %u, height %u, depth %u, format %#x, pool %#x, usage %#x, volume %p\n",
2079 iface, superior, width, height, depth, format, pool, usage, volume);
2081 /* Allocate the storage for the device */
2082 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2083 if (!object)
2085 FIXME("Allocation of memory failed\n");
2086 *volume = NULL;
2087 return D3DERR_OUTOFVIDEOMEMORY;
2090 object->lpVtbl = &Direct3DVolume9_Vtbl;
2091 object->ref = 1;
2092 hr = IWineD3DDevice_CreateVolume(This->WineD3DDevice, width, height, depth, usage & WINED3DUSAGE_MASK,
2093 format, pool, &object->wineD3DVolume, NULL, (IUnknown *)object);
2094 if (FAILED(hr))
2096 ERR("(%p) CreateVolume failed, returning %#x\n", iface, hr);
2097 HeapFree(GetProcessHeap(), 0, object);
2098 *volume = NULL;
2099 return hr;
2102 *volume = object->wineD3DVolume;
2103 object->container = superior;
2104 object->forwardReference = superior;
2106 TRACE("(%p) Created volume %p\n", iface, *volume);
2108 return hr;
2111 static HRESULT STDMETHODCALLTYPE device_parent_CreateSwapChain(IWineD3DDeviceParent *iface,
2112 WINED3DPRESENT_PARAMETERS *present_parameters, IWineD3DSwapChain **swapchain)
2114 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
2115 IDirect3DSwapChain9Impl *d3d_swapchain;
2116 D3DPRESENT_PARAMETERS local_parameters;
2117 HRESULT hr;
2119 TRACE("iface %p, present_parameters %p, swapchain %p\n", iface, present_parameters, swapchain);
2121 /* Copy the presentation parameters */
2122 local_parameters.BackBufferWidth = present_parameters->BackBufferWidth;
2123 local_parameters.BackBufferHeight = present_parameters->BackBufferHeight;
2124 local_parameters.BackBufferFormat = d3dformat_from_wined3dformat(present_parameters->BackBufferFormat);
2125 local_parameters.BackBufferCount = present_parameters->BackBufferCount;
2126 local_parameters.MultiSampleType = present_parameters->MultiSampleType;
2127 local_parameters.MultiSampleQuality = present_parameters->MultiSampleQuality;
2128 local_parameters.SwapEffect = present_parameters->SwapEffect;
2129 local_parameters.hDeviceWindow = present_parameters->hDeviceWindow;
2130 local_parameters.Windowed = present_parameters->Windowed;
2131 local_parameters.EnableAutoDepthStencil = present_parameters->EnableAutoDepthStencil;
2132 local_parameters.AutoDepthStencilFormat = d3dformat_from_wined3dformat(present_parameters->AutoDepthStencilFormat);
2133 local_parameters.Flags = present_parameters->Flags;
2134 local_parameters.FullScreen_RefreshRateInHz = present_parameters->FullScreen_RefreshRateInHz;
2135 local_parameters.PresentationInterval = present_parameters->PresentationInterval;
2137 hr = IDirect3DDevice9Impl_CreateAdditionalSwapChain((IDirect3DDevice9Ex *)This,
2138 &local_parameters, (IDirect3DSwapChain9 **)&d3d_swapchain);
2139 if (FAILED(hr))
2141 ERR("(%p) CreateAdditionalSwapChain failed, returning %#x\n", iface, hr);
2142 *swapchain = NULL;
2143 return hr;
2146 *swapchain = d3d_swapchain->wineD3DSwapChain;
2147 d3d_swapchain->isImplicit = TRUE;
2148 /* Implicit swap chains are created with an refcount of 0 */
2149 IDirect3DSwapChain9_Release((IDirect3DSwapChain9 *)d3d_swapchain);
2151 /* Copy back the presentation parameters */
2152 present_parameters->BackBufferWidth = local_parameters.BackBufferWidth;
2153 present_parameters->BackBufferHeight = local_parameters.BackBufferHeight;
2154 present_parameters->BackBufferFormat = wined3dformat_from_d3dformat(local_parameters.BackBufferFormat);
2155 present_parameters->BackBufferCount = local_parameters.BackBufferCount;
2156 present_parameters->MultiSampleType = local_parameters.MultiSampleType;
2157 present_parameters->MultiSampleQuality = local_parameters.MultiSampleQuality;
2158 present_parameters->SwapEffect = local_parameters.SwapEffect;
2159 present_parameters->hDeviceWindow = local_parameters.hDeviceWindow;
2160 present_parameters->Windowed = local_parameters.Windowed;
2161 present_parameters->EnableAutoDepthStencil = local_parameters.EnableAutoDepthStencil;
2162 present_parameters->AutoDepthStencilFormat = wined3dformat_from_d3dformat(local_parameters.AutoDepthStencilFormat);
2163 present_parameters->Flags = local_parameters.Flags;
2164 present_parameters->FullScreen_RefreshRateInHz = local_parameters.FullScreen_RefreshRateInHz;
2165 present_parameters->PresentationInterval = local_parameters.PresentationInterval;
2167 return hr;
2170 const IWineD3DDeviceParentVtbl d3d9_wined3d_device_parent_vtbl =
2172 /* IUnknown methods */
2173 device_parent_QueryInterface,
2174 device_parent_AddRef,
2175 device_parent_Release,
2176 /* IWineD3DDeviceParent methods */
2177 device_parent_WineD3DDeviceCreated,
2178 device_parent_CreateSurface,
2179 device_parent_CreateRenderTarget,
2180 device_parent_CreateDepthStencilSurface,
2181 device_parent_CreateVolume,
2182 device_parent_CreateSwapChain,