makefiles: Add resource files to the standard object files list.
[wine.git] / dlls / d3d9 / device.c
blob8f95ad11114ffc7525a1930013d31293f2967fb4
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 D3DINDEXBUFFER_DESC index_desc;
432 D3DVERTEXBUFFER_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 IDirect3DResource9 *parent;
439 IWineD3DResource_GetParent(resource, (IUnknown **) &parent);
440 type = IDirect3DResource9_GetType(parent);
441 switch(type) {
442 case D3DRTYPE_SURFACE:
443 surface_desc.Format = &dummy_format;
444 surface_desc.Type = &type;
445 surface_desc.Usage = &dummy_dword;
446 surface_desc.Pool = &pool;
447 surface_desc.Size = &dummy_dword;
448 surface_desc.MultiSampleType = &dummy_multisampletype;
449 surface_desc.MultiSampleQuality = &dummy_dword;
450 surface_desc.Width = &dummy_dword;
451 surface_desc.Height = &dummy_dword;
453 IWineD3DSurface_GetDesc((IWineD3DSurface *) resource, &surface_desc);
454 break;
456 case D3DRTYPE_VOLUME:
457 volume_desc.Format = &dummy_format;
458 volume_desc.Type = &type;
459 volume_desc.Usage = &dummy_dword;
460 volume_desc.Pool = &pool;
461 volume_desc.Size = &dummy_dword;
462 volume_desc.Width = &dummy_dword;
463 volume_desc.Height = &dummy_dword;
464 volume_desc.Depth = &dummy_dword;
465 IWineD3DVolume_GetDesc((IWineD3DVolume *) resource, &volume_desc);
466 break;
468 case D3DRTYPE_INDEXBUFFER:
469 IDirect3DIndexBuffer9_GetDesc((IDirect3DIndexBuffer9 *) parent, &index_desc);
470 pool = index_desc.Pool;
471 break;
473 case D3DRTYPE_VERTEXBUFFER:
474 IDirect3DVertexBuffer9_GetDesc((IDirect3DVertexBuffer9 *)parent, &vertex_desc);
475 pool = vertex_desc.Pool;
476 break;
478 /* No need to check for textures. If there is a D3DPOOL_DEFAULT texture, there
479 * is a D3DPOOL_DEFAULT surface or volume as well
481 default:
482 break;
485 if(pool == WINED3DPOOL_DEFAULT) {
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;
493 } else {
494 IUnknown_Release(parent);
496 IWineD3DResource_Release(resource);
498 return ret;
501 static HRESULT WINAPI IDirect3DDevice9Impl_Reset(LPDIRECT3DDEVICE9EX iface, D3DPRESENT_PARAMETERS* pPresentationParameters) {
502 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
503 WINED3DPRESENT_PARAMETERS localParameters;
504 HRESULT hr;
505 BOOL resources_ok = TRUE;
506 UINT i;
508 TRACE("(%p) Relay pPresentationParameters(%p)\n", This, pPresentationParameters);
510 /* Reset states that hold a COM object. WineD3D holds an internal reference to set objects, because
511 * such objects can still be used for rendering after their external d3d9 object has been destroyed.
512 * These objects must not be enumerated. Unsetting them tells WineD3D that the application will not
513 * make use of the hidden reference and destroys the objects.
515 * Unsetting them is no problem, because the states are supposed to be reset anyway. If the validation
516 * below fails, the device is considered "lost", and _Reset and _Release are the only allowed calls
518 EnterCriticalSection(&d3d9_cs);
519 IWineD3DDevice_SetIndices(This->WineD3DDevice, NULL, WINED3DFMT_UNKNOWN);
520 for(i = 0; i < 16; i++) {
521 IWineD3DDevice_SetStreamSource(This->WineD3DDevice, i, NULL, 0, 0);
523 for(i = 0; i < 16; i++) {
524 IWineD3DDevice_SetTexture(This->WineD3DDevice, i, NULL);
527 IWineD3DDevice_EnumResources(This->WineD3DDevice, reset_enum_callback, &resources_ok);
528 if(!resources_ok) {
529 WARN("The application is holding D3DPOOL_DEFAULT resources, rejecting reset\n");
530 This->notreset = TRUE;
531 LeaveCriticalSection(&d3d9_cs);
532 return WINED3DERR_INVALIDCALL;
535 localParameters.BackBufferWidth = pPresentationParameters->BackBufferWidth;
536 localParameters.BackBufferHeight = pPresentationParameters->BackBufferHeight;
537 localParameters.BackBufferFormat = wined3dformat_from_d3dformat(pPresentationParameters->BackBufferFormat);
538 localParameters.BackBufferCount = pPresentationParameters->BackBufferCount;
539 localParameters.MultiSampleType = pPresentationParameters->MultiSampleType;
540 localParameters.MultiSampleQuality = pPresentationParameters->MultiSampleQuality;
541 localParameters.SwapEffect = pPresentationParameters->SwapEffect;
542 localParameters.hDeviceWindow = pPresentationParameters->hDeviceWindow;
543 localParameters.Windowed = pPresentationParameters->Windowed;
544 localParameters.EnableAutoDepthStencil = pPresentationParameters->EnableAutoDepthStencil;
545 localParameters.AutoDepthStencilFormat = wined3dformat_from_d3dformat(pPresentationParameters->AutoDepthStencilFormat);
546 localParameters.Flags = pPresentationParameters->Flags;
547 localParameters.FullScreen_RefreshRateInHz = pPresentationParameters->FullScreen_RefreshRateInHz;
548 localParameters.PresentationInterval = pPresentationParameters->PresentationInterval;
549 localParameters.AutoRestoreDisplayMode = TRUE;
551 hr = IWineD3DDevice_Reset(This->WineD3DDevice, &localParameters);
552 if(FAILED(hr)) {
553 This->notreset = TRUE;
555 pPresentationParameters->BackBufferWidth = localParameters.BackBufferWidth;
556 pPresentationParameters->BackBufferHeight = localParameters.BackBufferHeight;
557 pPresentationParameters->BackBufferFormat = d3dformat_from_wined3dformat(localParameters.BackBufferFormat);
558 pPresentationParameters->BackBufferCount = localParameters.BackBufferCount;
559 pPresentationParameters->MultiSampleType = localParameters.MultiSampleType;
560 pPresentationParameters->MultiSampleQuality = localParameters.MultiSampleQuality;
561 pPresentationParameters->SwapEffect = localParameters.SwapEffect;
562 pPresentationParameters->hDeviceWindow = localParameters.hDeviceWindow;
563 pPresentationParameters->Windowed = localParameters.Windowed;
564 pPresentationParameters->EnableAutoDepthStencil = localParameters.EnableAutoDepthStencil;
565 pPresentationParameters->AutoDepthStencilFormat = d3dformat_from_wined3dformat(localParameters.AutoDepthStencilFormat);
566 pPresentationParameters->Flags = localParameters.Flags;
567 pPresentationParameters->FullScreen_RefreshRateInHz = localParameters.FullScreen_RefreshRateInHz;
568 pPresentationParameters->PresentationInterval = localParameters.PresentationInterval;
569 } else {
570 This->notreset = FALSE;
573 LeaveCriticalSection(&d3d9_cs);
575 return hr;
578 static HRESULT WINAPI IDirect3DDevice9Impl_Present(LPDIRECT3DDEVICE9EX iface, CONST RECT* pSourceRect,CONST RECT* pDestRect,HWND hDestWindowOverride,CONST RGNDATA*
579 pDirtyRegion) {
580 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
581 HRESULT hr;
582 TRACE("(%p) Relay\n", This);
584 EnterCriticalSection(&d3d9_cs);
585 hr = IWineD3DDevice_Present(This->WineD3DDevice, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
586 LeaveCriticalSection(&d3d9_cs);
587 return hr;
590 static HRESULT WINAPI IDirect3DDevice9Impl_GetBackBuffer(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain, UINT BackBuffer, D3DBACKBUFFER_TYPE Type, IDirect3DSurface9 ** ppBackBuffer) {
591 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
592 IWineD3DSurface *retSurface = NULL;
593 HRESULT rc = D3D_OK;
595 TRACE("(%p) Relay\n", This);
597 EnterCriticalSection(&d3d9_cs);
598 rc = IWineD3DDevice_GetBackBuffer(This->WineD3DDevice, iSwapChain, BackBuffer, (WINED3DBACKBUFFER_TYPE) Type, &retSurface);
599 if (rc == D3D_OK && NULL != retSurface && NULL != ppBackBuffer) {
600 IWineD3DSurface_GetParent(retSurface, (IUnknown **)ppBackBuffer);
601 IWineD3DSurface_Release(retSurface);
603 LeaveCriticalSection(&d3d9_cs);
604 return rc;
606 static HRESULT WINAPI IDirect3DDevice9Impl_GetRasterStatus(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain, D3DRASTER_STATUS* pRasterStatus) {
607 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
608 HRESULT hr;
609 TRACE("(%p) Relay\n", This);
611 EnterCriticalSection(&d3d9_cs);
612 hr = IWineD3DDevice_GetRasterStatus(This->WineD3DDevice, iSwapChain, (WINED3DRASTER_STATUS *) pRasterStatus);
613 LeaveCriticalSection(&d3d9_cs);
614 return hr;
617 static HRESULT WINAPI IDirect3DDevice9Impl_SetDialogBoxMode(LPDIRECT3DDEVICE9EX iface, BOOL bEnableDialogs) {
618 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
619 HRESULT hr;
620 TRACE("(%p) Relay\n", This);
622 EnterCriticalSection(&d3d9_cs);
623 hr = IWineD3DDevice_SetDialogBoxMode(This->WineD3DDevice, bEnableDialogs);
624 LeaveCriticalSection(&d3d9_cs);
625 return hr;
628 static void WINAPI IDirect3DDevice9Impl_SetGammaRamp(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain, DWORD Flags, CONST D3DGAMMARAMP* pRamp) {
630 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
631 TRACE("(%p) Relay\n", This);
633 EnterCriticalSection(&d3d9_cs);
634 /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
635 IWineD3DDevice_SetGammaRamp(This->WineD3DDevice, iSwapChain, Flags, (CONST WINED3DGAMMARAMP *)pRamp);
636 LeaveCriticalSection(&d3d9_cs);
639 static void WINAPI IDirect3DDevice9Impl_GetGammaRamp(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain, D3DGAMMARAMP* pRamp) {
640 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
641 TRACE("(%p) Relay\n", This);
643 EnterCriticalSection(&d3d9_cs);
644 /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
645 IWineD3DDevice_GetGammaRamp(This->WineD3DDevice, iSwapChain, (WINED3DGAMMARAMP *) pRamp);
646 LeaveCriticalSection(&d3d9_cs);
650 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 ) {
651 HRESULT hrc;
652 IDirect3DSurface9Impl *object;
653 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
654 TRACE("(%p) Relay\n", This);
656 if(MultisampleQuality > 0){
657 FIXME("MultisampleQuality set to %d, bstituting 0\n", MultisampleQuality);
659 MultisampleQuality
660 [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.
663 MultisampleQuality=0;
665 /*FIXME: Check MAX bounds of MultisampleQuality*/
667 /* Allocate the storage for the device */
668 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DSurface9Impl));
669 if (NULL == object) {
670 FIXME("Allocation of memory failed\n");
671 return D3DERR_OUTOFVIDEOMEMORY;
674 object->lpVtbl = &Direct3DSurface9_Vtbl;
675 object->ref = 1;
677 TRACE("(%p) : w(%d) h(%d) fmt(%d) surf@%p\n", This, Width, Height, Format, *ppSurface);
679 EnterCriticalSection(&d3d9_cs);
680 hrc = IWineD3DDevice_CreateSurface(This->WineD3DDevice, Width, Height, wined3dformat_from_d3dformat(Format),
681 Lockable, Discard, Level, &object->wineD3DSurface, Type, Usage & WINED3DUSAGE_MASK,
682 (WINED3DPOOL)Pool, MultiSample, MultisampleQuality, SURFACE_OPENGL, (IUnknown *)object);
683 LeaveCriticalSection(&d3d9_cs);
685 if (hrc != D3D_OK || NULL == object->wineD3DSurface) {
687 /* free up object */
688 FIXME("(%p) call to IWineD3DDevice_CreateSurface failed\n", This);
689 HeapFree(GetProcessHeap(), 0, object);
690 } else {
691 IDirect3DDevice9Ex_AddRef(iface);
692 object->parentDevice = iface;
693 TRACE("(%p) : Created surface %p\n", This, object);
694 *ppSurface = (LPDIRECT3DSURFACE9) object;
696 return hrc;
701 static HRESULT WINAPI IDirect3DDevice9Impl_CreateRenderTarget(LPDIRECT3DDEVICE9EX iface, UINT Width, UINT Height,
702 D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample,
703 DWORD MultisampleQuality, BOOL Lockable,
704 IDirect3DSurface9 **ppSurface, HANDLE* pSharedHandle) {
705 HRESULT hr;
706 TRACE("Relay\n");
708 hr = IDirect3DDevice9Impl_CreateSurface(iface,Width,Height,Format,Lockable,FALSE/*Discard*/, 0/*Level*/, ppSurface,D3DRTYPE_SURFACE,D3DUSAGE_RENDERTARGET,D3DPOOL_DEFAULT,MultiSample,MultisampleQuality,pSharedHandle);
709 return hr;
712 static HRESULT WINAPI IDirect3DDevice9Impl_CreateDepthStencilSurface(LPDIRECT3DDEVICE9EX iface, UINT Width, UINT Height,
713 D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample,
714 DWORD MultisampleQuality, BOOL Discard,
715 IDirect3DSurface9 **ppSurface, HANDLE* pSharedHandle) {
716 HRESULT hr;
717 TRACE("Relay\n");
719 hr = IDirect3DDevice9Impl_CreateSurface(iface,Width,Height,Format,TRUE/* Lockable */,Discard, 0/* Level */
720 ,ppSurface,D3DRTYPE_SURFACE,D3DUSAGE_DEPTHSTENCIL,
721 D3DPOOL_DEFAULT,MultiSample,MultisampleQuality,pSharedHandle);
722 return hr;
726 static HRESULT WINAPI IDirect3DDevice9Impl_UpdateSurface(LPDIRECT3DDEVICE9EX iface, IDirect3DSurface9* pSourceSurface, CONST RECT* pSourceRect, IDirect3DSurface9* pDestinationSurface, CONST POINT* pDestPoint) {
727 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
728 HRESULT hr;
729 TRACE("(%p) Relay\n" , This);
731 EnterCriticalSection(&d3d9_cs);
732 hr = IWineD3DDevice_UpdateSurface(This->WineD3DDevice, ((IDirect3DSurface9Impl *)pSourceSurface)->wineD3DSurface, pSourceRect, ((IDirect3DSurface9Impl *)pDestinationSurface)->wineD3DSurface, pDestPoint);
733 LeaveCriticalSection(&d3d9_cs);
734 return hr;
737 static HRESULT WINAPI IDirect3DDevice9Impl_UpdateTexture(LPDIRECT3DDEVICE9EX iface, IDirect3DBaseTexture9* pSourceTexture, IDirect3DBaseTexture9* pDestinationTexture) {
738 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
739 HRESULT hr;
740 TRACE("(%p) Relay\n" , This);
742 EnterCriticalSection(&d3d9_cs);
743 hr = IWineD3DDevice_UpdateTexture(This->WineD3DDevice, ((IDirect3DBaseTexture9Impl *)pSourceTexture)->wineD3DBaseTexture, ((IDirect3DBaseTexture9Impl *)pDestinationTexture)->wineD3DBaseTexture);
744 LeaveCriticalSection(&d3d9_cs);
745 return hr;
748 static HRESULT WINAPI IDirect3DDevice9Impl_GetRenderTargetData(LPDIRECT3DDEVICE9EX iface, IDirect3DSurface9* pRenderTarget, IDirect3DSurface9* pDestSurface) {
749 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
750 IDirect3DSurface9Impl *renderTarget = (IDirect3DSurface9Impl *)pRenderTarget;
751 IDirect3DSurface9Impl *destSurface = (IDirect3DSurface9Impl *)pDestSurface;
752 HRESULT hr;
753 TRACE("(%p)->(%p,%p)\n" , This, renderTarget, destSurface);
755 EnterCriticalSection(&d3d9_cs);
756 hr = IWineD3DSurface_BltFast(destSurface->wineD3DSurface, 0, 0, renderTarget->wineD3DSurface, NULL, WINEDDBLTFAST_NOCOLORKEY);
757 LeaveCriticalSection(&d3d9_cs);
758 return hr;
761 static HRESULT WINAPI IDirect3DDevice9Impl_GetFrontBufferData(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain, IDirect3DSurface9* pDestSurface) {
762 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
763 IDirect3DSurface9Impl *destSurface = (IDirect3DSurface9Impl *)pDestSurface;
764 HRESULT hr;
765 TRACE("(%p) Relay\n" , This);
767 EnterCriticalSection(&d3d9_cs);
768 hr = IWineD3DDevice_GetFrontBufferData(This->WineD3DDevice, iSwapChain, destSurface->wineD3DSurface);
769 LeaveCriticalSection(&d3d9_cs);
770 return hr;
773 static HRESULT WINAPI IDirect3DDevice9Impl_StretchRect(LPDIRECT3DDEVICE9EX iface, IDirect3DSurface9* pSourceSurface, CONST RECT* pSourceRect, IDirect3DSurface9* pDestSurface, CONST RECT* pDestRect, D3DTEXTUREFILTERTYPE Filter) {
774 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
775 IDirect3DSurface9Impl *src = (IDirect3DSurface9Impl *) pSourceSurface;
776 IDirect3DSurface9Impl *dst = (IDirect3DSurface9Impl *) pDestSurface;
777 HRESULT hr;
779 TRACE("(%p)->(%p,%p,%p,%p,%d)\n" , This, src, pSourceRect, dst, pDestRect, Filter);
780 EnterCriticalSection(&d3d9_cs);
781 hr = IWineD3DSurface_Blt(dst->wineD3DSurface, pDestRect, src->wineD3DSurface, pSourceRect, 0, NULL, Filter);
782 LeaveCriticalSection(&d3d9_cs);
783 return hr;
786 static HRESULT WINAPI IDirect3DDevice9Impl_ColorFill(LPDIRECT3DDEVICE9EX iface, IDirect3DSurface9* pSurface, CONST RECT* pRect, D3DCOLOR color) {
787 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
788 IDirect3DSurface9Impl *surface = (IDirect3DSurface9Impl *)pSurface;
789 WINED3DPOOL pool;
790 WINED3DRESOURCETYPE restype;
791 DWORD usage;
792 WINED3DSURFACE_DESC desc;
793 HRESULT hr;
794 TRACE("(%p) Relay\n" , This);
796 memset(&desc, 0, sizeof(desc));
797 desc.Usage = &usage;
798 desc.Pool = &pool;
799 desc.Type = &restype;
801 EnterCriticalSection(&d3d9_cs);
802 IWineD3DSurface_GetDesc(surface->wineD3DSurface, &desc);
804 /* This method is only allowed with surfaces that are render targets, or offscreen plain surfaces
805 * in D3DPOOL_DEFAULT
807 if(!(usage & WINED3DUSAGE_RENDERTARGET) && (pool != D3DPOOL_DEFAULT || restype != D3DRTYPE_SURFACE)) {
808 LeaveCriticalSection(&d3d9_cs);
809 WARN("Surface is not a render target, or not a stand-alone D3DPOOL_DEFAULT surface\n");
810 return D3DERR_INVALIDCALL;
813 /* Colorfill can only be used on rendertarget surfaces, or offscreen plain surfaces in D3DPOOL_DEFAULT */
814 /* Note: D3DRECT is compatible with WINED3DRECT */
815 hr = IWineD3DDevice_ColorFill(This->WineD3DDevice, surface->wineD3DSurface, (CONST WINED3DRECT*)pRect, color);
816 LeaveCriticalSection(&d3d9_cs);
817 return hr;
820 static HRESULT WINAPI IDirect3DDevice9Impl_CreateOffscreenPlainSurface(LPDIRECT3DDEVICE9EX iface, UINT Width, UINT Height, D3DFORMAT Format, D3DPOOL Pool, IDirect3DSurface9 **ppSurface, HANDLE* pSharedHandle) {
821 HRESULT hr;
822 TRACE("Relay\n");
823 if(Pool == D3DPOOL_MANAGED ){
824 FIXME("Attempting to create a managed offscreen plain surface\n");
825 return D3DERR_INVALIDCALL;
828 'Off-screen plain surfaces are always lockable, regardless of their pool types.'
829 but then...
830 D3DPOOL_DEFAULT is the appropriate pool for use with the IDirect3DDevice9::StretchRect and IDirect3DDevice9::ColorFill.
831 Why, their always lockable?
832 should I change the usage to dynamic?
834 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);
836 return hr;
839 /* TODO: move to wineD3D */
840 static HRESULT WINAPI IDirect3DDevice9Impl_SetRenderTarget(LPDIRECT3DDEVICE9EX iface, DWORD RenderTargetIndex, IDirect3DSurface9* pRenderTarget) {
841 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
842 IDirect3DSurface9Impl *pSurface = (IDirect3DSurface9Impl*)pRenderTarget;
843 HRESULT hr;
844 TRACE("(%p) Relay\n" , This);
846 EnterCriticalSection(&d3d9_cs);
847 hr = IWineD3DDevice_SetRenderTarget(This->WineD3DDevice, RenderTargetIndex, pSurface ? pSurface->wineD3DSurface : NULL);
848 LeaveCriticalSection(&d3d9_cs);
849 return hr;
852 static HRESULT WINAPI IDirect3DDevice9Impl_GetRenderTarget(LPDIRECT3DDEVICE9EX iface, DWORD RenderTargetIndex, IDirect3DSurface9 **ppRenderTarget) {
853 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
854 IWineD3DSurface *pRenderTarget;
855 HRESULT hr;
857 TRACE("(%p) Relay\n" , This);
859 if (ppRenderTarget == NULL) {
860 return D3DERR_INVALIDCALL;
863 EnterCriticalSection(&d3d9_cs);
864 hr=IWineD3DDevice_GetRenderTarget(This->WineD3DDevice,RenderTargetIndex,&pRenderTarget);
866 if (FAILED(hr))
868 FIXME("Call to IWineD3DDevice_GetRenderTarget failed, hr %#x\n", hr);
870 else if (!pRenderTarget)
872 *ppRenderTarget = NULL;
874 else
876 IWineD3DSurface_GetParent(pRenderTarget, (IUnknown **)ppRenderTarget);
877 IWineD3DSurface_Release(pRenderTarget);
880 LeaveCriticalSection(&d3d9_cs);
882 return hr;
885 static HRESULT WINAPI IDirect3DDevice9Impl_SetDepthStencilSurface(LPDIRECT3DDEVICE9EX iface, IDirect3DSurface9* pZStencilSurface) {
886 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
887 IDirect3DSurface9Impl *pSurface;
888 HRESULT hr;
889 TRACE("(%p) Relay\n" , This);
891 pSurface = (IDirect3DSurface9Impl*)pZStencilSurface;
892 EnterCriticalSection(&d3d9_cs);
893 hr = IWineD3DDevice_SetDepthStencilSurface(This->WineD3DDevice, NULL==pSurface ? NULL : pSurface->wineD3DSurface);
894 LeaveCriticalSection(&d3d9_cs);
895 return hr;
898 static HRESULT WINAPI IDirect3DDevice9Impl_GetDepthStencilSurface(LPDIRECT3DDEVICE9EX iface, IDirect3DSurface9 **ppZStencilSurface) {
899 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
900 HRESULT hr = D3D_OK;
901 IWineD3DSurface *pZStencilSurface;
903 TRACE("(%p) Relay\n" , This);
904 if(ppZStencilSurface == NULL){
905 return D3DERR_INVALIDCALL;
908 EnterCriticalSection(&d3d9_cs);
909 hr = IWineD3DDevice_GetDepthStencilSurface(This->WineD3DDevice,&pZStencilSurface);
910 if (hr == WINED3D_OK) {
911 IWineD3DSurface_GetParent(pZStencilSurface,(IUnknown**)ppZStencilSurface);
912 IWineD3DSurface_Release(pZStencilSurface);
913 } else {
914 if (hr != WINED3DERR_NOTFOUND)
915 WARN("Call to IWineD3DDevice_GetDepthStencilSurface failed with 0x%08x\n", hr);
916 *ppZStencilSurface = NULL;
918 LeaveCriticalSection(&d3d9_cs);
919 return hr;
922 static HRESULT WINAPI IDirect3DDevice9Impl_BeginScene(LPDIRECT3DDEVICE9EX iface) {
923 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
924 HRESULT hr;
925 TRACE("(%p) Relay\n" , This);
927 EnterCriticalSection(&d3d9_cs);
928 hr = IWineD3DDevice_BeginScene(This->WineD3DDevice);
929 LeaveCriticalSection(&d3d9_cs);
930 return hr;
933 static HRESULT WINAPI IDirect3DDevice9Impl_EndScene(LPDIRECT3DDEVICE9EX iface) {
934 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
935 HRESULT hr;
936 TRACE("(%p) Relay\n" , This);
938 EnterCriticalSection(&d3d9_cs);
939 hr = IWineD3DDevice_EndScene(This->WineD3DDevice);
940 LeaveCriticalSection(&d3d9_cs);
941 return hr;
944 static HRESULT WINAPI IDirect3DDevice9Impl_Clear(LPDIRECT3DDEVICE9EX iface, DWORD Count, CONST D3DRECT* pRects, DWORD Flags, D3DCOLOR Color, float Z, DWORD Stencil) {
945 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
946 HRESULT hr;
947 TRACE("(%p) Relay\n" , This);
949 /* Note: D3DRECT is compatible with WINED3DRECT */
950 EnterCriticalSection(&d3d9_cs);
951 hr = IWineD3DDevice_Clear(This->WineD3DDevice, Count, (CONST WINED3DRECT*) pRects, Flags, Color, Z, Stencil);
952 LeaveCriticalSection(&d3d9_cs);
953 return hr;
956 static HRESULT WINAPI IDirect3DDevice9Impl_SetTransform(LPDIRECT3DDEVICE9EX iface, D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX* lpMatrix) {
957 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
958 HRESULT hr;
959 TRACE("(%p) Relay\n" , This);
961 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
962 EnterCriticalSection(&d3d9_cs);
963 hr = IWineD3DDevice_SetTransform(This->WineD3DDevice, State, (CONST WINED3DMATRIX*) lpMatrix);
964 LeaveCriticalSection(&d3d9_cs);
965 return hr;
968 static HRESULT WINAPI IDirect3DDevice9Impl_GetTransform(LPDIRECT3DDEVICE9EX iface, D3DTRANSFORMSTATETYPE State, D3DMATRIX* pMatrix) {
969 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
970 HRESULT hr;
972 TRACE("(%p) Relay\n" , This);
974 EnterCriticalSection(&d3d9_cs);
975 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
976 hr = IWineD3DDevice_GetTransform(This->WineD3DDevice, State, (WINED3DMATRIX*) pMatrix);
977 LeaveCriticalSection(&d3d9_cs);
979 return hr;
982 static HRESULT WINAPI IDirect3DDevice9Impl_MultiplyTransform(LPDIRECT3DDEVICE9EX iface, D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX* pMatrix) {
983 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
984 HRESULT hr;
985 TRACE("(%p) Relay\n" , This);
987 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
988 EnterCriticalSection(&d3d9_cs);
989 hr = IWineD3DDevice_MultiplyTransform(This->WineD3DDevice, State, (CONST WINED3DMATRIX*) pMatrix);
990 LeaveCriticalSection(&d3d9_cs);
991 return hr;
994 static HRESULT WINAPI IDirect3DDevice9Impl_SetViewport(LPDIRECT3DDEVICE9EX iface, CONST D3DVIEWPORT9* pViewport) {
995 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
996 HRESULT hr;
997 TRACE("(%p) Relay\n" , This);
999 /* Note: D3DVIEWPORT9 is compatible with WINED3DVIEWPORT */
1000 EnterCriticalSection(&d3d9_cs);
1001 hr = IWineD3DDevice_SetViewport(This->WineD3DDevice, (const WINED3DVIEWPORT *)pViewport);
1002 LeaveCriticalSection(&d3d9_cs);
1003 return hr;
1006 static HRESULT WINAPI IDirect3DDevice9Impl_GetViewport(LPDIRECT3DDEVICE9EX iface, D3DVIEWPORT9* pViewport) {
1007 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1008 HRESULT hr;
1009 TRACE("(%p) Relay\n" , This);
1011 /* Note: D3DVIEWPORT9 is compatible with WINED3DVIEWPORT */
1012 EnterCriticalSection(&d3d9_cs);
1013 hr = IWineD3DDevice_GetViewport(This->WineD3DDevice, (WINED3DVIEWPORT *)pViewport);
1014 LeaveCriticalSection(&d3d9_cs);
1015 return hr;
1018 static HRESULT WINAPI IDirect3DDevice9Impl_SetMaterial(LPDIRECT3DDEVICE9EX iface, CONST D3DMATERIAL9* pMaterial) {
1019 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1020 HRESULT hr;
1021 TRACE("(%p) Relay\n" , This);
1023 /* Note: D3DMATERIAL9 is compatible with WINED3DMATERIAL */
1024 EnterCriticalSection(&d3d9_cs);
1025 hr = IWineD3DDevice_SetMaterial(This->WineD3DDevice, (const WINED3DMATERIAL *)pMaterial);
1026 LeaveCriticalSection(&d3d9_cs);
1027 return hr;
1030 static HRESULT WINAPI IDirect3DDevice9Impl_GetMaterial(LPDIRECT3DDEVICE9EX iface, D3DMATERIAL9* pMaterial) {
1031 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1032 HRESULT hr;
1033 TRACE("(%p) Relay\n" , This);
1035 /* Note: D3DMATERIAL9 is compatible with WINED3DMATERIAL */
1036 EnterCriticalSection(&d3d9_cs);
1037 hr = IWineD3DDevice_GetMaterial(This->WineD3DDevice, (WINED3DMATERIAL *)pMaterial);
1038 LeaveCriticalSection(&d3d9_cs);
1039 return hr;
1042 static HRESULT WINAPI IDirect3DDevice9Impl_SetLight(LPDIRECT3DDEVICE9EX iface, DWORD Index, CONST D3DLIGHT9* pLight) {
1043 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1044 HRESULT hr;
1045 TRACE("(%p) Relay\n" , This);
1047 /* Note: D3DLIGHT9 is compatible with WINED3DLIGHT */
1048 EnterCriticalSection(&d3d9_cs);
1049 hr = IWineD3DDevice_SetLight(This->WineD3DDevice, Index, (const WINED3DLIGHT *)pLight);
1050 LeaveCriticalSection(&d3d9_cs);
1051 return hr;
1054 static HRESULT WINAPI IDirect3DDevice9Impl_GetLight(LPDIRECT3DDEVICE9EX iface, DWORD Index, D3DLIGHT9* pLight) {
1055 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1056 HRESULT hr;
1057 TRACE("(%p) Relay\n" , This);
1059 /* Note: D3DLIGHT9 is compatible with WINED3DLIGHT */
1060 EnterCriticalSection(&d3d9_cs);
1061 hr = IWineD3DDevice_GetLight(This->WineD3DDevice, Index, (WINED3DLIGHT *)pLight);
1062 LeaveCriticalSection(&d3d9_cs);
1063 return hr;
1066 static HRESULT WINAPI IDirect3DDevice9Impl_LightEnable(LPDIRECT3DDEVICE9EX iface, DWORD Index, BOOL Enable) {
1067 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1068 HRESULT hr;
1069 TRACE("(%p) Relay\n" , This);
1071 EnterCriticalSection(&d3d9_cs);
1072 hr = IWineD3DDevice_SetLightEnable(This->WineD3DDevice, Index, Enable);
1073 LeaveCriticalSection(&d3d9_cs);
1074 return hr;
1077 static HRESULT WINAPI IDirect3DDevice9Impl_GetLightEnable(LPDIRECT3DDEVICE9EX iface, DWORD Index, BOOL* pEnable) {
1078 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1079 HRESULT hr;
1080 TRACE("(%p) Relay\n" , This);
1082 EnterCriticalSection(&d3d9_cs);
1083 hr = IWineD3DDevice_GetLightEnable(This->WineD3DDevice, Index, pEnable);
1084 LeaveCriticalSection(&d3d9_cs);
1085 return hr;
1088 static HRESULT WINAPI IDirect3DDevice9Impl_SetClipPlane(LPDIRECT3DDEVICE9EX iface, DWORD Index, CONST float* pPlane) {
1089 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1090 HRESULT hr;
1091 TRACE("(%p) Relay\n" , This);
1093 EnterCriticalSection(&d3d9_cs);
1094 hr = IWineD3DDevice_SetClipPlane(This->WineD3DDevice, Index, pPlane);
1095 LeaveCriticalSection(&d3d9_cs);
1096 return hr;
1099 static HRESULT WINAPI IDirect3DDevice9Impl_GetClipPlane(LPDIRECT3DDEVICE9EX iface, DWORD Index, float* pPlane) {
1100 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1101 HRESULT hr;
1102 TRACE("(%p) Relay\n" , This);
1104 EnterCriticalSection(&d3d9_cs);
1105 hr = IWineD3DDevice_GetClipPlane(This->WineD3DDevice, Index, pPlane);
1106 LeaveCriticalSection(&d3d9_cs);
1107 return hr;
1110 static HRESULT WINAPI IDirect3DDevice9Impl_SetRenderState(LPDIRECT3DDEVICE9EX iface, D3DRENDERSTATETYPE State, DWORD Value) {
1111 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1112 HRESULT hr;
1113 TRACE("(%p) Relay\n" , This);
1115 EnterCriticalSection(&d3d9_cs);
1116 hr = IWineD3DDevice_SetRenderState(This->WineD3DDevice, State, Value);
1117 LeaveCriticalSection(&d3d9_cs);
1118 return hr;
1121 static HRESULT WINAPI IDirect3DDevice9Impl_GetRenderState(LPDIRECT3DDEVICE9EX iface, D3DRENDERSTATETYPE State, DWORD* pValue) {
1122 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1123 HRESULT hr;
1124 TRACE("(%p) Relay\n" , This);
1126 EnterCriticalSection(&d3d9_cs);
1127 hr = IWineD3DDevice_GetRenderState(This->WineD3DDevice, State, pValue);
1128 LeaveCriticalSection(&d3d9_cs);
1129 return hr;
1132 static HRESULT WINAPI IDirect3DDevice9Impl_SetClipStatus(LPDIRECT3DDEVICE9EX iface, CONST D3DCLIPSTATUS9* pClipStatus) {
1133 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1134 HRESULT hr;
1135 TRACE("(%p) Relay\n" , This);
1137 EnterCriticalSection(&d3d9_cs);
1138 hr = IWineD3DDevice_SetClipStatus(This->WineD3DDevice, (const WINED3DCLIPSTATUS *)pClipStatus);
1139 LeaveCriticalSection(&d3d9_cs);
1140 return hr;
1143 static HRESULT WINAPI IDirect3DDevice9Impl_GetClipStatus(LPDIRECT3DDEVICE9EX iface, D3DCLIPSTATUS9* pClipStatus) {
1144 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1145 HRESULT hr;
1146 TRACE("(%p) Relay\n" , This);
1148 EnterCriticalSection(&d3d9_cs);
1149 hr = IWineD3DDevice_GetClipStatus(This->WineD3DDevice, (WINED3DCLIPSTATUS *)pClipStatus);
1150 LeaveCriticalSection(&d3d9_cs);
1151 return hr;
1154 static HRESULT WINAPI IDirect3DDevice9Impl_GetTexture(LPDIRECT3DDEVICE9EX iface, DWORD Stage, IDirect3DBaseTexture9 **ppTexture) {
1155 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1156 IWineD3DBaseTexture *retTexture = NULL;
1157 HRESULT rc = D3D_OK;
1159 TRACE("(%p) Relay\n" , This);
1161 if(ppTexture == NULL){
1162 return D3DERR_INVALIDCALL;
1165 EnterCriticalSection(&d3d9_cs);
1166 rc = IWineD3DDevice_GetTexture(This->WineD3DDevice, Stage, &retTexture);
1167 if (SUCCEEDED(rc) && NULL != retTexture) {
1168 IWineD3DBaseTexture_GetParent(retTexture, (IUnknown **)ppTexture);
1169 IWineD3DBaseTexture_Release(retTexture);
1170 } else {
1171 if(FAILED(rc)) {
1172 WARN("Call to get texture (%d) failed (%p)\n", Stage, retTexture);
1174 *ppTexture = NULL;
1176 LeaveCriticalSection(&d3d9_cs);
1178 return rc;
1181 static HRESULT WINAPI IDirect3DDevice9Impl_SetTexture(LPDIRECT3DDEVICE9EX iface, DWORD Stage, IDirect3DBaseTexture9* pTexture) {
1182 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1183 HRESULT hr;
1184 TRACE("(%p) Relay %d %p\n" , This, Stage, pTexture);
1186 EnterCriticalSection(&d3d9_cs);
1187 hr = IWineD3DDevice_SetTexture(This->WineD3DDevice, Stage,
1188 pTexture==NULL ? NULL:((IDirect3DBaseTexture9Impl *)pTexture)->wineD3DBaseTexture);
1189 LeaveCriticalSection(&d3d9_cs);
1190 return hr;
1193 static const WINED3DTEXTURESTAGESTATETYPE tss_lookup[] =
1195 WINED3DTSS_FORCE_DWORD, /* 0, unused */
1196 WINED3DTSS_COLOROP, /* 1, D3DTSS_COLOROP */
1197 WINED3DTSS_COLORARG1, /* 2, D3DTSS_COLORARG1 */
1198 WINED3DTSS_COLORARG2, /* 3, D3DTSS_COLORARG2 */
1199 WINED3DTSS_ALPHAOP, /* 4, D3DTSS_ALPHAOP */
1200 WINED3DTSS_ALPHAARG1, /* 5, D3DTSS_ALPHAARG1 */
1201 WINED3DTSS_ALPHAARG2, /* 6, D3DTSS_ALPHAARG2 */
1202 WINED3DTSS_BUMPENVMAT00, /* 7, D3DTSS_BUMPENVMAT00 */
1203 WINED3DTSS_BUMPENVMAT01, /* 8, D3DTSS_BUMPENVMAT01 */
1204 WINED3DTSS_BUMPENVMAT10, /* 9, D3DTSS_BUMPENVMAT10 */
1205 WINED3DTSS_BUMPENVMAT11, /* 10, D3DTSS_BUMPENVMAT11 */
1206 WINED3DTSS_TEXCOORDINDEX, /* 11, D3DTSS_TEXCOORDINDEX */
1207 WINED3DTSS_FORCE_DWORD, /* 12, unused */
1208 WINED3DTSS_FORCE_DWORD, /* 13, unused */
1209 WINED3DTSS_FORCE_DWORD, /* 14, unused */
1210 WINED3DTSS_FORCE_DWORD, /* 15, unused */
1211 WINED3DTSS_FORCE_DWORD, /* 16, unused */
1212 WINED3DTSS_FORCE_DWORD, /* 17, unused */
1213 WINED3DTSS_FORCE_DWORD, /* 18, unused */
1214 WINED3DTSS_FORCE_DWORD, /* 19, unused */
1215 WINED3DTSS_FORCE_DWORD, /* 20, unused */
1216 WINED3DTSS_FORCE_DWORD, /* 21, unused */
1217 WINED3DTSS_BUMPENVLSCALE, /* 22, D3DTSS_BUMPENVLSCALE */
1218 WINED3DTSS_BUMPENVLOFFSET, /* 23, D3DTSS_BUMPENVLOFFSET */
1219 WINED3DTSS_TEXTURETRANSFORMFLAGS, /* 24, D3DTSS_TEXTURETRANSFORMFLAGS */
1220 WINED3DTSS_FORCE_DWORD, /* 25, unused */
1221 WINED3DTSS_COLORARG0, /* 26, D3DTSS_COLORARG0 */
1222 WINED3DTSS_ALPHAARG0, /* 27, D3DTSS_ALPHAARG0 */
1223 WINED3DTSS_RESULTARG, /* 28, D3DTSS_RESULTARG */
1224 WINED3DTSS_FORCE_DWORD, /* 29, unused */
1225 WINED3DTSS_FORCE_DWORD, /* 30, unused */
1226 WINED3DTSS_FORCE_DWORD, /* 31, unused */
1227 WINED3DTSS_CONSTANT, /* 32, D3DTSS_CONSTANT */
1230 static HRESULT WINAPI IDirect3DDevice9Impl_GetTextureStageState(LPDIRECT3DDEVICE9EX iface, DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD* pValue) {
1231 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1232 HRESULT hr;
1233 TRACE("(%p) Relay\n" , This);
1235 EnterCriticalSection(&d3d9_cs);
1236 hr = IWineD3DDevice_GetTextureStageState(This->WineD3DDevice, Stage, tss_lookup[Type], pValue);
1237 LeaveCriticalSection(&d3d9_cs);
1238 return hr;
1241 static HRESULT WINAPI IDirect3DDevice9Impl_SetTextureStageState(LPDIRECT3DDEVICE9EX iface, DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD Value) {
1242 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1243 HRESULT hr;
1244 TRACE("(%p) Relay\n" , This);
1246 EnterCriticalSection(&d3d9_cs);
1247 hr = IWineD3DDevice_SetTextureStageState(This->WineD3DDevice, Stage, tss_lookup[Type], Value);
1248 LeaveCriticalSection(&d3d9_cs);
1249 return hr;
1252 static HRESULT WINAPI IDirect3DDevice9Impl_GetSamplerState(LPDIRECT3DDEVICE9EX iface, DWORD Sampler, D3DSAMPLERSTATETYPE Type, DWORD* pValue) {
1253 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1254 HRESULT hr;
1255 TRACE("(%p) Relay\n" , This);
1257 EnterCriticalSection(&d3d9_cs);
1258 hr = IWineD3DDevice_GetSamplerState(This->WineD3DDevice, Sampler, Type, pValue);
1259 LeaveCriticalSection(&d3d9_cs);
1260 return hr;
1263 static HRESULT WINAPI IDirect3DDevice9Impl_SetSamplerState(LPDIRECT3DDEVICE9EX iface, DWORD Sampler, D3DSAMPLERSTATETYPE Type, DWORD Value) {
1264 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1265 HRESULT hr;
1266 TRACE("(%p) Relay\n" , This);
1268 EnterCriticalSection(&d3d9_cs);
1269 hr = IWineD3DDevice_SetSamplerState(This->WineD3DDevice, Sampler, Type, Value);
1270 LeaveCriticalSection(&d3d9_cs);
1271 return hr;
1274 static HRESULT WINAPI IDirect3DDevice9Impl_ValidateDevice(LPDIRECT3DDEVICE9EX iface, DWORD* pNumPasses) {
1275 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1276 HRESULT hr;
1277 TRACE("(%p) Relay\n" , This);
1279 EnterCriticalSection(&d3d9_cs);
1280 hr = IWineD3DDevice_ValidateDevice(This->WineD3DDevice, pNumPasses);
1281 LeaveCriticalSection(&d3d9_cs);
1282 return hr;
1285 static HRESULT WINAPI IDirect3DDevice9Impl_SetPaletteEntries(LPDIRECT3DDEVICE9EX iface, UINT PaletteNumber, CONST PALETTEENTRY* pEntries) {
1286 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1287 HRESULT hr;
1288 TRACE("(%p) Relay\n" , This);
1290 EnterCriticalSection(&d3d9_cs);
1291 hr = IWineD3DDevice_SetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
1292 LeaveCriticalSection(&d3d9_cs);
1293 return hr;
1296 static HRESULT WINAPI IDirect3DDevice9Impl_GetPaletteEntries(LPDIRECT3DDEVICE9EX iface, UINT PaletteNumber, PALETTEENTRY* pEntries) {
1297 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1298 HRESULT hr;
1299 TRACE("(%p) Relay\n" , This);
1301 EnterCriticalSection(&d3d9_cs);
1302 hr = IWineD3DDevice_GetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
1303 LeaveCriticalSection(&d3d9_cs);
1304 return hr;
1307 static HRESULT WINAPI IDirect3DDevice9Impl_SetCurrentTexturePalette(LPDIRECT3DDEVICE9EX iface, UINT PaletteNumber) {
1308 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1309 HRESULT hr;
1310 TRACE("(%p) Relay\n" , This);
1312 EnterCriticalSection(&d3d9_cs);
1313 hr = IWineD3DDevice_SetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
1314 LeaveCriticalSection(&d3d9_cs);
1315 return hr;
1318 static HRESULT WINAPI IDirect3DDevice9Impl_GetCurrentTexturePalette(LPDIRECT3DDEVICE9EX iface, UINT* PaletteNumber) {
1319 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1320 HRESULT hr;
1321 TRACE("(%p) Relay\n" , This);
1323 EnterCriticalSection(&d3d9_cs);
1324 hr = IWineD3DDevice_GetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
1325 LeaveCriticalSection(&d3d9_cs);
1326 return hr;
1329 static HRESULT WINAPI IDirect3DDevice9Impl_SetScissorRect(LPDIRECT3DDEVICE9EX iface, CONST RECT* pRect) {
1330 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1331 HRESULT hr;
1332 TRACE("(%p) Relay\n" , This);
1334 EnterCriticalSection(&d3d9_cs);
1335 hr = IWineD3DDevice_SetScissorRect(This->WineD3DDevice, pRect);
1336 LeaveCriticalSection(&d3d9_cs);
1337 return hr;
1340 static HRESULT WINAPI IDirect3DDevice9Impl_GetScissorRect(LPDIRECT3DDEVICE9EX iface, RECT* pRect) {
1341 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1342 HRESULT hr;
1343 TRACE("(%p) Relay\n" , This);
1345 EnterCriticalSection(&d3d9_cs);
1346 hr = IWineD3DDevice_GetScissorRect(This->WineD3DDevice, pRect);
1347 LeaveCriticalSection(&d3d9_cs);
1348 return hr;
1351 static HRESULT WINAPI IDirect3DDevice9Impl_SetSoftwareVertexProcessing(LPDIRECT3DDEVICE9EX iface, BOOL bSoftware) {
1352 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1353 HRESULT hr;
1354 TRACE("(%p) Relay\n" , This);
1356 EnterCriticalSection(&d3d9_cs);
1357 hr = IWineD3DDevice_SetSoftwareVertexProcessing(This->WineD3DDevice, bSoftware);
1358 LeaveCriticalSection(&d3d9_cs);
1359 return hr;
1362 static BOOL WINAPI IDirect3DDevice9Impl_GetSoftwareVertexProcessing(LPDIRECT3DDEVICE9EX iface) {
1363 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1364 BOOL ret;
1365 TRACE("(%p) Relay\n" , This);
1367 EnterCriticalSection(&d3d9_cs);
1368 ret = IWineD3DDevice_GetSoftwareVertexProcessing(This->WineD3DDevice);
1369 LeaveCriticalSection(&d3d9_cs);
1370 return ret;
1373 static HRESULT WINAPI IDirect3DDevice9Impl_SetNPatchMode(LPDIRECT3DDEVICE9EX iface, float nSegments) {
1374 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1375 HRESULT hr;
1376 TRACE("(%p) Relay\n" , This);
1378 EnterCriticalSection(&d3d9_cs);
1379 hr = IWineD3DDevice_SetNPatchMode(This->WineD3DDevice, nSegments);
1380 LeaveCriticalSection(&d3d9_cs);
1381 return hr;
1384 static float WINAPI IDirect3DDevice9Impl_GetNPatchMode(LPDIRECT3DDEVICE9EX iface) {
1385 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1386 float ret;
1387 TRACE("(%p) Relay\n" , This);
1389 EnterCriticalSection(&d3d9_cs);
1390 ret = IWineD3DDevice_GetNPatchMode(This->WineD3DDevice);
1391 LeaveCriticalSection(&d3d9_cs);
1392 return ret;
1395 static HRESULT WINAPI IDirect3DDevice9Impl_DrawPrimitive(LPDIRECT3DDEVICE9EX iface, D3DPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT PrimitiveCount) {
1396 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1397 HRESULT hr;
1398 TRACE("(%p) Relay\n" , This);
1400 EnterCriticalSection(&d3d9_cs);
1401 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1402 hr = IWineD3DDevice_DrawPrimitive(This->WineD3DDevice, StartVertex,
1403 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount));
1404 LeaveCriticalSection(&d3d9_cs);
1405 return hr;
1408 static HRESULT WINAPI IDirect3DDevice9Impl_DrawIndexedPrimitive(LPDIRECT3DDEVICE9EX iface, D3DPRIMITIVETYPE PrimitiveType,
1409 INT BaseVertexIndex, UINT MinVertexIndex, UINT NumVertices, UINT startIndex, UINT primCount) {
1410 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1411 HRESULT hr;
1412 TRACE("(%p) Relay\n" , This);
1414 /* D3D8 passes the baseVertexIndex in SetIndices, and due to the stateblock functions wined3d has to work that way */
1415 EnterCriticalSection(&d3d9_cs);
1416 IWineD3DDevice_SetBaseVertexIndex(This->WineD3DDevice, BaseVertexIndex);
1417 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1418 hr = IWineD3DDevice_DrawIndexedPrimitive(This->WineD3DDevice, MinVertexIndex, NumVertices,
1419 startIndex, vertex_count_from_primitive_count(PrimitiveType, primCount));
1420 LeaveCriticalSection(&d3d9_cs);
1421 return hr;
1424 static HRESULT WINAPI IDirect3DDevice9Impl_DrawPrimitiveUP(LPDIRECT3DDEVICE9EX iface, D3DPRIMITIVETYPE PrimitiveType, UINT PrimitiveCount, CONST void* pVertexStreamZeroData, UINT VertexStreamZeroStride) {
1425 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1426 HRESULT hr;
1427 TRACE("(%p) Relay\n" , This);
1429 EnterCriticalSection(&d3d9_cs);
1430 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1431 hr = IWineD3DDevice_DrawPrimitiveUP(This->WineD3DDevice,
1432 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount),
1433 pVertexStreamZeroData, VertexStreamZeroStride);
1434 LeaveCriticalSection(&d3d9_cs);
1435 return hr;
1438 static HRESULT WINAPI IDirect3DDevice9Impl_DrawIndexedPrimitiveUP(LPDIRECT3DDEVICE9EX iface, D3DPRIMITIVETYPE PrimitiveType, UINT MinVertexIndex,
1439 UINT NumVertexIndices, UINT PrimitiveCount, CONST void* pIndexData,
1440 D3DFORMAT IndexDataFormat, CONST void* pVertexStreamZeroData, UINT VertexStreamZeroStride) {
1441 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1442 HRESULT hr;
1443 TRACE("(%p) Relay\n" , This);
1445 EnterCriticalSection(&d3d9_cs);
1446 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1447 hr = IWineD3DDevice_DrawIndexedPrimitiveUP(This->WineD3DDevice, MinVertexIndex, NumVertexIndices,
1448 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount), pIndexData,
1449 wined3dformat_from_d3dformat(IndexDataFormat), pVertexStreamZeroData, VertexStreamZeroStride);
1450 LeaveCriticalSection(&d3d9_cs);
1451 return hr;
1454 static HRESULT WINAPI IDirect3DDevice9Impl_ProcessVertices(LPDIRECT3DDEVICE9EX iface, UINT SrcStartIndex, UINT DestIndex, UINT VertexCount, IDirect3DVertexBuffer9* pDestBuffer, IDirect3DVertexDeclaration9* pVertexDecl, DWORD Flags) {
1455 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1456 IDirect3DVertexDeclaration9Impl *Decl = (IDirect3DVertexDeclaration9Impl *) pVertexDecl;
1457 HRESULT hr;
1458 IDirect3DVertexBuffer9Impl *dest = (IDirect3DVertexBuffer9Impl *) pDestBuffer;
1459 TRACE("(%p) Relay\n" , This);
1461 EnterCriticalSection(&d3d9_cs);
1462 hr = IWineD3DDevice_ProcessVertices(This->WineD3DDevice,SrcStartIndex, DestIndex, VertexCount, dest->wineD3DVertexBuffer, Decl ? Decl->wineD3DVertexDeclaration : NULL, Flags, dest->fvf);
1463 LeaveCriticalSection(&d3d9_cs);
1464 return hr;
1467 static IDirect3DVertexDeclaration9 *getConvertedDecl(IDirect3DDevice9Impl *This, DWORD fvf) {
1468 HRESULT hr;
1469 D3DVERTEXELEMENT9* elements = NULL;
1470 IDirect3DVertexDeclaration9* pDecl = NULL;
1471 int p, low, high; /* deliberately signed */
1472 IDirect3DVertexDeclaration9 **convertedDecls = This->convertedDecls;
1474 TRACE("Searching for declaration for fvf %08x... ", fvf);
1476 low = 0;
1477 high = This->numConvertedDecls - 1;
1478 while(low <= high) {
1479 p = (low + high) >> 1;
1480 TRACE("%d ", p);
1481 if(((IDirect3DVertexDeclaration9Impl *) convertedDecls[p])->convFVF == fvf) {
1482 TRACE("found %p\n", convertedDecls[p]);
1483 return convertedDecls[p];
1484 } else if(((IDirect3DVertexDeclaration9Impl *) convertedDecls[p])->convFVF < fvf) {
1485 low = p + 1;
1486 } else {
1487 high = p - 1;
1490 TRACE("not found. Creating and inserting at position %d.\n", low);
1492 hr = vdecl_convert_fvf(fvf, &elements);
1493 if (hr != S_OK) return NULL;
1495 hr = IDirect3DDevice9Impl_CreateVertexDeclaration((IDirect3DDevice9Ex *) This, elements, &pDecl);
1496 HeapFree(GetProcessHeap(), 0, elements); /* CreateVertexDeclaration makes a copy */
1497 if (hr != S_OK) return NULL;
1499 if(This->declArraySize == This->numConvertedDecls) {
1500 int grow = max(This->declArraySize / 2, 8);
1501 convertedDecls = HeapReAlloc(GetProcessHeap(), 0, convertedDecls,
1502 sizeof(convertedDecls[0]) * (This->numConvertedDecls + grow));
1503 if(!convertedDecls) {
1504 /* This will destroy it */
1505 IDirect3DVertexDeclaration9_Release(pDecl);
1506 return NULL;
1508 This->convertedDecls = convertedDecls;
1509 This->declArraySize += grow;
1512 memmove(convertedDecls + low + 1, convertedDecls + low, sizeof(IDirect3DVertexDeclaration9Impl *) * (This->numConvertedDecls - low));
1513 convertedDecls[low] = pDecl;
1514 This->numConvertedDecls++;
1516 /* Will prevent the decl from being destroyed */
1517 ((IDirect3DVertexDeclaration9Impl *) pDecl)->convFVF = fvf;
1518 IDirect3DVertexDeclaration9_Release(pDecl); /* Does not destroy now */
1520 TRACE("Returning %p. %d decls in array\n", pDecl, This->numConvertedDecls);
1521 return pDecl;
1524 static HRESULT WINAPI IDirect3DDevice9Impl_SetFVF(LPDIRECT3DDEVICE9EX iface, DWORD FVF) {
1525 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1526 IDirect3DVertexDeclaration9 *decl;
1527 HRESULT hr;
1529 TRACE("(%p) Relay\n" , This);
1531 if (!FVF)
1533 WARN("%#x is not a valid FVF\n", FVF);
1534 return D3D_OK;
1537 EnterCriticalSection(&d3d9_cs);
1538 decl = getConvertedDecl(This, FVF);
1539 LeaveCriticalSection(&d3d9_cs);
1541 if (!decl)
1543 /* Any situation when this should happen, except out of memory? */
1544 ERR("Failed to create a converted vertex declaration\n");
1545 return D3DERR_DRIVERINTERNALERROR;
1548 hr = IDirect3DDevice9Impl_SetVertexDeclaration(iface, decl);
1549 if (FAILED(hr)) ERR("Failed to set vertex declaration\n");
1551 return hr;
1554 static HRESULT WINAPI IDirect3DDevice9Impl_GetFVF(LPDIRECT3DDEVICE9EX iface, DWORD* pFVF) {
1555 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1556 IDirect3DVertexDeclaration9 *decl;
1557 HRESULT hr;
1558 TRACE("(%p) Relay\n" , This);
1560 hr = IDirect3DDevice9_GetVertexDeclaration(iface, &decl);
1561 if (FAILED(hr))
1563 WARN("Failed to get vertex declaration, %#x\n", hr);
1564 *pFVF = 0;
1565 return hr;
1568 if (decl)
1570 *pFVF = ((IDirect3DVertexDeclaration9Impl *)decl)->convFVF;
1571 IDirect3DVertexDeclaration9_Release(decl);
1573 else
1575 *pFVF = 0;
1578 TRACE("Returning FVF %#x\n", *pFVF);
1580 return hr;
1583 static HRESULT WINAPI IDirect3DDevice9Impl_SetStreamSource(LPDIRECT3DDEVICE9EX iface, UINT StreamNumber, IDirect3DVertexBuffer9* pStreamData, UINT OffsetInBytes, UINT Stride) {
1584 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1585 HRESULT hr;
1586 TRACE("(%p) Relay\n" , This);
1588 EnterCriticalSection(&d3d9_cs);
1589 hr = IWineD3DDevice_SetStreamSource(This->WineD3DDevice, StreamNumber,
1590 pStreamData==NULL ? NULL:((IDirect3DVertexBuffer9Impl *)pStreamData)->wineD3DVertexBuffer,
1591 OffsetInBytes, Stride);
1592 LeaveCriticalSection(&d3d9_cs);
1593 return hr;
1596 static HRESULT WINAPI IDirect3DDevice9Impl_GetStreamSource(LPDIRECT3DDEVICE9EX iface, UINT StreamNumber, IDirect3DVertexBuffer9 **pStream, UINT* OffsetInBytes, UINT* pStride) {
1597 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1598 IWineD3DBuffer *retStream = NULL;
1599 HRESULT rc = D3D_OK;
1601 TRACE("(%p) Relay\n" , This);
1603 if(pStream == NULL){
1604 return D3DERR_INVALIDCALL;
1607 EnterCriticalSection(&d3d9_cs);
1608 rc = IWineD3DDevice_GetStreamSource(This->WineD3DDevice, StreamNumber, &retStream, OffsetInBytes, pStride);
1609 if (rc == D3D_OK && NULL != retStream) {
1610 IWineD3DBuffer_GetParent(retStream, (IUnknown **)pStream);
1611 IWineD3DBuffer_Release(retStream);
1612 }else{
1613 if (rc != D3D_OK){
1614 FIXME("Call to GetStreamSource failed %p %p\n", OffsetInBytes, pStride);
1616 *pStream = NULL;
1618 LeaveCriticalSection(&d3d9_cs);
1620 return rc;
1623 static HRESULT WINAPI IDirect3DDevice9Impl_SetStreamSourceFreq(LPDIRECT3DDEVICE9EX iface, UINT StreamNumber, UINT Divider) {
1624 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1625 HRESULT hr;
1626 TRACE("(%p) Relay\n" , This);
1628 EnterCriticalSection(&d3d9_cs);
1629 hr = IWineD3DDevice_SetStreamSourceFreq(This->WineD3DDevice, StreamNumber, Divider);
1630 LeaveCriticalSection(&d3d9_cs);
1631 return hr;
1634 static HRESULT WINAPI IDirect3DDevice9Impl_GetStreamSourceFreq(LPDIRECT3DDEVICE9EX iface, UINT StreamNumber, UINT* Divider) {
1635 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1636 HRESULT hr;
1637 TRACE("(%p) Relay\n" , This);
1639 EnterCriticalSection(&d3d9_cs);
1640 hr = IWineD3DDevice_GetStreamSourceFreq(This->WineD3DDevice, StreamNumber, Divider);
1641 LeaveCriticalSection(&d3d9_cs);
1642 return hr;
1645 static HRESULT WINAPI IDirect3DDevice9Impl_SetIndices(LPDIRECT3DDEVICE9EX iface, IDirect3DIndexBuffer9* pIndexData) {
1646 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1647 HRESULT hr;
1648 IDirect3DIndexBuffer9Impl *ib = (IDirect3DIndexBuffer9Impl *) pIndexData;
1649 TRACE("(%p) Relay\n", This);
1651 EnterCriticalSection(&d3d9_cs);
1652 hr = IWineD3DDevice_SetIndices(This->WineD3DDevice,
1653 ib ? ib->wineD3DIndexBuffer : NULL,
1654 ib ? ib->format : WINED3DFMT_UNKNOWN);
1655 LeaveCriticalSection(&d3d9_cs);
1656 return hr;
1659 static HRESULT WINAPI IDirect3DDevice9Impl_GetIndices(LPDIRECT3DDEVICE9EX iface, IDirect3DIndexBuffer9 **ppIndexData) {
1660 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1661 IWineD3DBuffer *retIndexData = NULL;
1662 HRESULT rc = D3D_OK;
1664 TRACE("(%p) Relay\n", This);
1666 if(ppIndexData == NULL){
1667 return D3DERR_INVALIDCALL;
1670 EnterCriticalSection(&d3d9_cs);
1671 rc = IWineD3DDevice_GetIndices(This->WineD3DDevice, &retIndexData);
1672 if (SUCCEEDED(rc) && retIndexData) {
1673 IWineD3DBuffer_GetParent(retIndexData, (IUnknown **)ppIndexData);
1674 IWineD3DBuffer_Release(retIndexData);
1675 } else {
1676 if (FAILED(rc)) FIXME("Call to GetIndices failed\n");
1677 *ppIndexData = NULL;
1679 LeaveCriticalSection(&d3d9_cs);
1680 return rc;
1683 static HRESULT WINAPI IDirect3DDevice9Impl_DrawRectPatch(LPDIRECT3DDEVICE9EX iface, UINT Handle, CONST float* pNumSegs, CONST D3DRECTPATCH_INFO* pRectPatchInfo) {
1684 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1685 HRESULT hr;
1686 TRACE("(%p) Relay\n", This);
1688 EnterCriticalSection(&d3d9_cs);
1689 hr = IWineD3DDevice_DrawRectPatch(This->WineD3DDevice, Handle, pNumSegs, (CONST WINED3DRECTPATCH_INFO *)pRectPatchInfo);
1690 LeaveCriticalSection(&d3d9_cs);
1691 return hr;
1694 static HRESULT WINAPI IDirect3DDevice9Impl_DrawTriPatch(LPDIRECT3DDEVICE9EX iface, UINT Handle, CONST float* pNumSegs, CONST D3DTRIPATCH_INFO* pTriPatchInfo) {
1695 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1696 HRESULT hr;
1697 TRACE("(%p) Relay\n", This);
1699 EnterCriticalSection(&d3d9_cs);
1700 hr = IWineD3DDevice_DrawTriPatch(This->WineD3DDevice, Handle, pNumSegs, (CONST WINED3DTRIPATCH_INFO *)pTriPatchInfo);
1701 LeaveCriticalSection(&d3d9_cs);
1702 return hr;
1705 static HRESULT WINAPI IDirect3DDevice9Impl_DeletePatch(LPDIRECT3DDEVICE9EX iface, UINT Handle) {
1706 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1707 HRESULT hr;
1708 TRACE("(%p) Relay\n", This);
1710 EnterCriticalSection(&d3d9_cs);
1711 hr = IWineD3DDevice_DeletePatch(This->WineD3DDevice, Handle);
1712 LeaveCriticalSection(&d3d9_cs);
1713 return hr;
1716 static HRESULT WINAPI IDirect3DDevice9ExImpl_SetConvolutionMonoKernel(LPDIRECT3DDEVICE9EX iface, UINT width, UINT height, float *rows, float *columns) {
1717 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1718 FIXME("(%p)->(%d, %d, %p, %p) Stub!\n", This, width, height, rows, columns);
1719 return WINED3DERR_INVALIDCALL;
1722 static HRESULT WINAPI IDirect3DDevice9ExImpl_ComposeRects(LPDIRECT3DDEVICE9EX iface, IDirect3DSurface9 *pSrc, IDirect3DDevice9 *pDst, IDirect3DVertexBuffer9 *pSrcRectDescs, UINT NumRects, IDirect3DVertexBuffer9 *pDstRectDescs, D3DCOMPOSERECTSOP Operation, int Xoffset, int Yoffset) {
1723 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1724 FIXME("(%p)->(%p, %p, %p, %d, %p, %d, %d, %d) Stub!\n", This, pSrc, pDst, pSrcRectDescs, NumRects, pDstRectDescs, Operation, Xoffset, Yoffset);
1725 return WINED3DERR_INVALIDCALL;
1728 static HRESULT WINAPI IDirect3DDevice9ExImpl_PresentEx(LPDIRECT3DDEVICE9EX iface, CONST RECT *pSourceRect, CONST RECT *pDestRect, HWND hDestWindowOverride, CONST RGNDATA *pDirtyRegion, DWORD dwFlags) {
1729 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1730 FIXME("(%p= -> (%p), %p, %p, %p, 0x%08x) Stub!\n", This, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion, dwFlags);
1731 return WINED3DERR_INVALIDCALL;
1734 static HRESULT WINAPI IDirect3DDevice9ExImpl_GetGPUThreadPriority(LPDIRECT3DDEVICE9EX iface, INT *pPriority) {
1735 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1736 FIXME("(%p)->(%p) Stub!\n", This, pPriority);
1737 return WINED3DERR_INVALIDCALL;
1740 static HRESULT WINAPI IDirect3DDevice9ExImpl_SetGPUThreadPriority(LPDIRECT3DDEVICE9EX iface, INT Priority) {
1741 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1742 FIXME("(%p)->(%d) Stub!\n", This, Priority);
1743 return WINED3DERR_INVALIDCALL;
1746 static HRESULT WINAPI IDirect3DDevice9ExImpl_WaitForVBlank(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain) {
1747 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1748 FIXME("(%p)->(%d) Stub!\n", This, iSwapChain);
1749 return WINED3DERR_INVALIDCALL;
1752 static HRESULT WINAPI IDirect3DDevice9ExImpl_CheckresourceResidency(LPDIRECT3DDEVICE9EX iface, IDirect3DResource9 ** pResourceArray, UINT32 Numresources) {
1753 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1754 FIXME("(%p)->(%p, %d) Stub!\n", This, pResourceArray, Numresources);
1755 return WINED3DERR_INVALIDCALL;
1758 static HRESULT WINAPI IDirect3DDevice9ExImpl_SetMaximumFrameLatency(LPDIRECT3DDEVICE9EX iface, UINT MaxLatency) {
1759 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1760 FIXME("(%p)->(%d) Stub!\n", This, MaxLatency);
1761 return WINED3DERR_INVALIDCALL;
1764 static HRESULT WINAPI IDirect3DDevice9ExImpl_GetMaximumFrameLatency(LPDIRECT3DDEVICE9EX iface, UINT *pMaxLatency) {
1765 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1766 FIXME("(%p)->(%p) Stub!\n", This, pMaxLatency);
1767 *pMaxLatency = 2;
1768 return WINED3DERR_INVALIDCALL;
1771 static HRESULT WINAPI IDirect3DDevice9ExImpl_CheckdeviceState(LPDIRECT3DDEVICE9EX iface, HWND hDestinationWindow) {
1772 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1773 FIXME("(%p)->(%p) Stub!\n", This, hDestinationWindow);
1774 return WINED3DERR_INVALIDCALL;
1777 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) {
1778 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1779 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);
1780 return WINED3DERR_INVALIDCALL;
1783 static HRESULT WINAPI IDirect3DDevice9ExImpl_CreateOffscreenPlainSurfaceEx(LPDIRECT3DDEVICE9EX iface, UINT Width, UINT Height, D3DFORMAT Format, D3DPOOL Pool, IDirect3DSurface9 **ppSurface, HANDLE *pSharedHandle, DWORD Usage) {
1784 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1785 FIXME("(%p)->(%d, %d, %d, %d, %p, %p, 0x%08x) Stub!\n", This, Width, Height, Format, Pool, ppSurface, pSharedHandle, Usage);
1786 return WINED3DERR_INVALIDCALL;
1789 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) {
1790 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1791 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);
1792 return WINED3DERR_INVALIDCALL;
1795 static HRESULT WINAPI IDirect3DDevice9ExImpl_ResetEx(LPDIRECT3DDEVICE9EX iface, D3DPRESENT_PARAMETERS *pPresentationParameters, D3DDISPLAYMODEEX *pFullscreenDisplayMode) {
1796 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1797 FIXME("(%p)->(%p) Stub!\n", This, pPresentationParameters);
1798 return WINED3DERR_INVALIDCALL;
1801 static HRESULT WINAPI IDirect3DDevice9ExImpl_GetDisplayModeEx(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain, D3DDISPLAYMODEEX *pMode, D3DDISPLAYROTATION *pRotation) {
1802 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1803 FIXME("(%p)->(%d, %p, %p) Stub!\n", This, iSwapChain, pMode, pRotation);
1804 return WINED3DERR_INVALIDCALL;
1807 const IDirect3DDevice9ExVtbl Direct3DDevice9_Vtbl =
1809 /* IUnknown */
1810 IDirect3DDevice9Impl_QueryInterface,
1811 IDirect3DDevice9Impl_AddRef,
1812 IDirect3DDevice9Impl_Release,
1813 /* IDirect3DDevice9 */
1814 IDirect3DDevice9Impl_TestCooperativeLevel,
1815 IDirect3DDevice9Impl_GetAvailableTextureMem,
1816 IDirect3DDevice9Impl_EvictManagedResources,
1817 IDirect3DDevice9Impl_GetDirect3D,
1818 IDirect3DDevice9Impl_GetDeviceCaps,
1819 IDirect3DDevice9Impl_GetDisplayMode,
1820 IDirect3DDevice9Impl_GetCreationParameters,
1821 IDirect3DDevice9Impl_SetCursorProperties,
1822 IDirect3DDevice9Impl_SetCursorPosition,
1823 IDirect3DDevice9Impl_ShowCursor,
1824 IDirect3DDevice9Impl_CreateAdditionalSwapChain,
1825 IDirect3DDevice9Impl_GetSwapChain,
1826 IDirect3DDevice9Impl_GetNumberOfSwapChains,
1827 IDirect3DDevice9Impl_Reset,
1828 IDirect3DDevice9Impl_Present,
1829 IDirect3DDevice9Impl_GetBackBuffer,
1830 IDirect3DDevice9Impl_GetRasterStatus,
1831 IDirect3DDevice9Impl_SetDialogBoxMode,
1832 IDirect3DDevice9Impl_SetGammaRamp,
1833 IDirect3DDevice9Impl_GetGammaRamp,
1834 IDirect3DDevice9Impl_CreateTexture,
1835 IDirect3DDevice9Impl_CreateVolumeTexture,
1836 IDirect3DDevice9Impl_CreateCubeTexture,
1837 IDirect3DDevice9Impl_CreateVertexBuffer,
1838 IDirect3DDevice9Impl_CreateIndexBuffer,
1839 IDirect3DDevice9Impl_CreateRenderTarget,
1840 IDirect3DDevice9Impl_CreateDepthStencilSurface,
1841 IDirect3DDevice9Impl_UpdateSurface,
1842 IDirect3DDevice9Impl_UpdateTexture,
1843 IDirect3DDevice9Impl_GetRenderTargetData,
1844 IDirect3DDevice9Impl_GetFrontBufferData,
1845 IDirect3DDevice9Impl_StretchRect,
1846 IDirect3DDevice9Impl_ColorFill,
1847 IDirect3DDevice9Impl_CreateOffscreenPlainSurface,
1848 IDirect3DDevice9Impl_SetRenderTarget,
1849 IDirect3DDevice9Impl_GetRenderTarget,
1850 IDirect3DDevice9Impl_SetDepthStencilSurface,
1851 IDirect3DDevice9Impl_GetDepthStencilSurface,
1852 IDirect3DDevice9Impl_BeginScene,
1853 IDirect3DDevice9Impl_EndScene,
1854 IDirect3DDevice9Impl_Clear,
1855 IDirect3DDevice9Impl_SetTransform,
1856 IDirect3DDevice9Impl_GetTransform,
1857 IDirect3DDevice9Impl_MultiplyTransform,
1858 IDirect3DDevice9Impl_SetViewport,
1859 IDirect3DDevice9Impl_GetViewport,
1860 IDirect3DDevice9Impl_SetMaterial,
1861 IDirect3DDevice9Impl_GetMaterial,
1862 IDirect3DDevice9Impl_SetLight,
1863 IDirect3DDevice9Impl_GetLight,
1864 IDirect3DDevice9Impl_LightEnable,
1865 IDirect3DDevice9Impl_GetLightEnable,
1866 IDirect3DDevice9Impl_SetClipPlane,
1867 IDirect3DDevice9Impl_GetClipPlane,
1868 IDirect3DDevice9Impl_SetRenderState,
1869 IDirect3DDevice9Impl_GetRenderState,
1870 IDirect3DDevice9Impl_CreateStateBlock,
1871 IDirect3DDevice9Impl_BeginStateBlock,
1872 IDirect3DDevice9Impl_EndStateBlock,
1873 IDirect3DDevice9Impl_SetClipStatus,
1874 IDirect3DDevice9Impl_GetClipStatus,
1875 IDirect3DDevice9Impl_GetTexture,
1876 IDirect3DDevice9Impl_SetTexture,
1877 IDirect3DDevice9Impl_GetTextureStageState,
1878 IDirect3DDevice9Impl_SetTextureStageState,
1879 IDirect3DDevice9Impl_GetSamplerState,
1880 IDirect3DDevice9Impl_SetSamplerState,
1881 IDirect3DDevice9Impl_ValidateDevice,
1882 IDirect3DDevice9Impl_SetPaletteEntries,
1883 IDirect3DDevice9Impl_GetPaletteEntries,
1884 IDirect3DDevice9Impl_SetCurrentTexturePalette,
1885 IDirect3DDevice9Impl_GetCurrentTexturePalette,
1886 IDirect3DDevice9Impl_SetScissorRect,
1887 IDirect3DDevice9Impl_GetScissorRect,
1888 IDirect3DDevice9Impl_SetSoftwareVertexProcessing,
1889 IDirect3DDevice9Impl_GetSoftwareVertexProcessing,
1890 IDirect3DDevice9Impl_SetNPatchMode,
1891 IDirect3DDevice9Impl_GetNPatchMode,
1892 IDirect3DDevice9Impl_DrawPrimitive,
1893 IDirect3DDevice9Impl_DrawIndexedPrimitive,
1894 IDirect3DDevice9Impl_DrawPrimitiveUP,
1895 IDirect3DDevice9Impl_DrawIndexedPrimitiveUP,
1896 IDirect3DDevice9Impl_ProcessVertices,
1897 IDirect3DDevice9Impl_CreateVertexDeclaration,
1898 IDirect3DDevice9Impl_SetVertexDeclaration,
1899 IDirect3DDevice9Impl_GetVertexDeclaration,
1900 IDirect3DDevice9Impl_SetFVF,
1901 IDirect3DDevice9Impl_GetFVF,
1902 IDirect3DDevice9Impl_CreateVertexShader,
1903 IDirect3DDevice9Impl_SetVertexShader,
1904 IDirect3DDevice9Impl_GetVertexShader,
1905 IDirect3DDevice9Impl_SetVertexShaderConstantF,
1906 IDirect3DDevice9Impl_GetVertexShaderConstantF,
1907 IDirect3DDevice9Impl_SetVertexShaderConstantI,
1908 IDirect3DDevice9Impl_GetVertexShaderConstantI,
1909 IDirect3DDevice9Impl_SetVertexShaderConstantB,
1910 IDirect3DDevice9Impl_GetVertexShaderConstantB,
1911 IDirect3DDevice9Impl_SetStreamSource,
1912 IDirect3DDevice9Impl_GetStreamSource,
1913 IDirect3DDevice9Impl_SetStreamSourceFreq,
1914 IDirect3DDevice9Impl_GetStreamSourceFreq,
1915 IDirect3DDevice9Impl_SetIndices,
1916 IDirect3DDevice9Impl_GetIndices,
1917 IDirect3DDevice9Impl_CreatePixelShader,
1918 IDirect3DDevice9Impl_SetPixelShader,
1919 IDirect3DDevice9Impl_GetPixelShader,
1920 IDirect3DDevice9Impl_SetPixelShaderConstantF,
1921 IDirect3DDevice9Impl_GetPixelShaderConstantF,
1922 IDirect3DDevice9Impl_SetPixelShaderConstantI,
1923 IDirect3DDevice9Impl_GetPixelShaderConstantI,
1924 IDirect3DDevice9Impl_SetPixelShaderConstantB,
1925 IDirect3DDevice9Impl_GetPixelShaderConstantB,
1926 IDirect3DDevice9Impl_DrawRectPatch,
1927 IDirect3DDevice9Impl_DrawTriPatch,
1928 IDirect3DDevice9Impl_DeletePatch,
1929 IDirect3DDevice9Impl_CreateQuery,
1930 /* IDirect3DDevice9Ex */
1931 IDirect3DDevice9ExImpl_SetConvolutionMonoKernel,
1932 IDirect3DDevice9ExImpl_ComposeRects,
1933 IDirect3DDevice9ExImpl_PresentEx,
1934 IDirect3DDevice9ExImpl_GetGPUThreadPriority,
1935 IDirect3DDevice9ExImpl_SetGPUThreadPriority,
1936 IDirect3DDevice9ExImpl_WaitForVBlank,
1937 IDirect3DDevice9ExImpl_CheckresourceResidency,
1938 IDirect3DDevice9ExImpl_SetMaximumFrameLatency,
1939 IDirect3DDevice9ExImpl_GetMaximumFrameLatency,
1940 IDirect3DDevice9ExImpl_CheckdeviceState,
1941 IDirect3DDevice9ExImpl_CreateRenderTargetEx,
1942 IDirect3DDevice9ExImpl_CreateOffscreenPlainSurfaceEx,
1943 IDirect3DDevice9ExImpl_CreateDepthStencilSurfaceEx,
1944 IDirect3DDevice9ExImpl_ResetEx,
1945 IDirect3DDevice9ExImpl_GetDisplayModeEx
1948 ULONG WINAPI D3D9CB_DestroySurface(IWineD3DSurface *pSurface) {
1949 IDirect3DSurface9Impl* surfaceParent;
1950 TRACE("(%p) call back\n", pSurface);
1952 IWineD3DSurface_GetParent(pSurface, (IUnknown **) &surfaceParent);
1953 /* GetParent's AddRef was forwarded to an object in destruction.
1954 * Releasing it here again would cause an endless recursion. */
1955 surfaceParent->forwardReference = NULL;
1956 return IDirect3DSurface9_Release((IDirect3DSurface9*) surfaceParent);
1959 /* IWineD3DDeviceParent IUnknown methods */
1961 static inline struct IDirect3DDevice9Impl *device_from_device_parent(IWineD3DDeviceParent *iface)
1963 return (struct IDirect3DDevice9Impl *)((char*)iface
1964 - FIELD_OFFSET(struct IDirect3DDevice9Impl, device_parent_vtbl));
1967 static HRESULT STDMETHODCALLTYPE device_parent_QueryInterface(IWineD3DDeviceParent *iface, REFIID riid, void **object)
1969 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
1970 return IDirect3DDevice9Impl_QueryInterface((IDirect3DDevice9Ex *)This, riid, object);
1973 static ULONG STDMETHODCALLTYPE device_parent_AddRef(IWineD3DDeviceParent *iface)
1975 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
1976 return IDirect3DDevice9Impl_AddRef((IDirect3DDevice9Ex *)This);
1979 static ULONG STDMETHODCALLTYPE device_parent_Release(IWineD3DDeviceParent *iface)
1981 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
1982 return IDirect3DDevice9Impl_Release((IDirect3DDevice9Ex *)This);
1985 /* IWineD3DDeviceParent methods */
1987 static void STDMETHODCALLTYPE device_parent_WineD3DDeviceCreated(IWineD3DDeviceParent *iface, IWineD3DDevice *device)
1989 TRACE("iface %p, device %p\n", iface, device);
1992 static HRESULT STDMETHODCALLTYPE device_parent_CreateSurface(IWineD3DDeviceParent *iface,
1993 IUnknown *superior, UINT width, UINT height, WINED3DFORMAT format, DWORD usage,
1994 WINED3DPOOL pool, UINT level, WINED3DCUBEMAP_FACES face, IWineD3DSurface **surface)
1996 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
1997 IDirect3DSurface9Impl *d3d_surface;
1998 BOOL lockable = TRUE;
1999 HRESULT hr;
2001 TRACE("iface %p, superior %p, width %u, height %u, format %#x, usage %#x,\n"
2002 "\tpool %#x, level %u, face %u, surface %p\n",
2003 iface, superior, width, height, format, usage, pool, level, face, surface);
2005 if (pool == WINED3DPOOL_DEFAULT && !(usage & D3DUSAGE_DYNAMIC))
2006 lockable = FALSE;
2008 hr = IDirect3DDevice9Impl_CreateSurface((IDirect3DDevice9Ex *)This, width, height,
2009 d3dformat_from_wined3dformat(format), lockable, FALSE /* Discard */, level,
2010 (IDirect3DSurface9 **)&d3d_surface, D3DRTYPE_SURFACE, usage, pool,
2011 D3DMULTISAMPLE_NONE, 0 /* MultisampleQuality */, NULL);
2012 if (FAILED(hr))
2014 ERR("(%p) CreateSurface failed, returning %#x\n", iface, hr);
2015 return hr;
2018 *surface = d3d_surface->wineD3DSurface;
2019 d3d_surface->container = superior;
2020 IDirect3DDevice9Ex_Release(d3d_surface->parentDevice);
2021 d3d_surface->parentDevice = NULL;
2022 d3d_surface->forwardReference = superior;
2024 return hr;
2027 static HRESULT STDMETHODCALLTYPE device_parent_CreateRenderTarget(IWineD3DDeviceParent *iface,
2028 IUnknown *superior, UINT width, UINT height, WINED3DFORMAT format, WINED3DMULTISAMPLE_TYPE multisample_type,
2029 DWORD multisample_quality, BOOL lockable, IWineD3DSurface **surface)
2031 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
2032 IDirect3DSurface9Impl *d3d_surface;
2033 HRESULT hr;
2035 TRACE("iface %p, superior %p, width %u, height %u, format %#x, multisample_type %#x,\n"
2036 "\tmultisample_quality %u, lockable %u, surface %p\n",
2037 iface, superior, width, height, format, multisample_type, multisample_quality, lockable, surface);
2039 hr = IDirect3DDevice9Impl_CreateRenderTarget((IDirect3DDevice9Ex *)This, width, height,
2040 d3dformat_from_wined3dformat(format), multisample_type, multisample_quality, lockable,
2041 (IDirect3DSurface9 **)&d3d_surface, NULL);
2042 if (FAILED(hr))
2044 ERR("(%p) CreateRenderTarget failed, returning %#x\n", iface, hr);
2045 return hr;
2048 *surface = d3d_surface->wineD3DSurface;
2049 d3d_surface->container = superior;
2050 d3d_surface->isImplicit = TRUE;
2051 /* Implicit surfaces are created with an refcount of 0 */
2052 IDirect3DSurface9_Release((IDirect3DSurface9 *)d3d_surface);
2054 return hr;
2057 static HRESULT STDMETHODCALLTYPE device_parent_CreateDepthStencilSurface(IWineD3DDeviceParent *iface,
2058 IUnknown *superior, UINT width, UINT height, WINED3DFORMAT format, WINED3DMULTISAMPLE_TYPE multisample_type,
2059 DWORD multisample_quality, BOOL discard, IWineD3DSurface **surface)
2061 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
2062 IDirect3DSurface9Impl *d3d_surface;
2063 HRESULT hr;
2065 TRACE("iface %p, superior %p, width %u, height %u, format %#x, multisample_type %#x,\n"
2066 "\tmultisample_quality %u, discard %u, surface %p\n",
2067 iface, superior, width, height, format, multisample_type, multisample_quality, discard, surface);
2069 hr = IDirect3DDevice9Impl_CreateDepthStencilSurface((IDirect3DDevice9Ex *)This, width, height,
2070 d3dformat_from_wined3dformat(format), multisample_type, multisample_quality, discard,
2071 (IDirect3DSurface9 **)&d3d_surface, NULL);
2072 if (FAILED(hr))
2074 ERR("(%p) CreateDepthStencilSurface failed, returning %#x\n", iface, hr);
2075 return hr;
2078 *surface = d3d_surface->wineD3DSurface;
2079 d3d_surface->container = (IUnknown *)This;
2080 d3d_surface->isImplicit = TRUE;
2081 /* Implicit surfaces are created with an refcount of 0 */
2082 IDirect3DSurface9_Release((IDirect3DSurface9 *)d3d_surface);
2084 return hr;
2087 static HRESULT STDMETHODCALLTYPE device_parent_CreateVolume(IWineD3DDeviceParent *iface,
2088 IUnknown *superior, UINT width, UINT height, UINT depth, WINED3DFORMAT format,
2089 WINED3DPOOL pool, DWORD usage, IWineD3DVolume **volume)
2091 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
2092 IDirect3DVolume9Impl *object;
2093 HRESULT hr;
2095 TRACE("iface %p, superior %p, width %u, height %u, depth %u, format %#x, pool %#x, usage %#x, volume %p\n",
2096 iface, superior, width, height, depth, format, pool, usage, volume);
2098 /* Allocate the storage for the device */
2099 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2100 if (!object)
2102 FIXME("Allocation of memory failed\n");
2103 *volume = NULL;
2104 return D3DERR_OUTOFVIDEOMEMORY;
2107 object->lpVtbl = &Direct3DVolume9_Vtbl;
2108 object->ref = 1;
2109 hr = IWineD3DDevice_CreateVolume(This->WineD3DDevice, width, height, depth, usage & WINED3DUSAGE_MASK,
2110 format, pool, &object->wineD3DVolume, (IUnknown *)object);
2111 if (FAILED(hr))
2113 ERR("(%p) CreateVolume failed, returning %#x\n", iface, hr);
2114 HeapFree(GetProcessHeap(), 0, object);
2115 *volume = NULL;
2116 return hr;
2119 *volume = object->wineD3DVolume;
2120 object->container = superior;
2121 object->forwardReference = superior;
2123 TRACE("(%p) Created volume %p\n", iface, *volume);
2125 return hr;
2128 static HRESULT STDMETHODCALLTYPE device_parent_CreateSwapChain(IWineD3DDeviceParent *iface,
2129 WINED3DPRESENT_PARAMETERS *present_parameters, IWineD3DSwapChain **swapchain)
2131 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
2132 IDirect3DSwapChain9Impl *d3d_swapchain;
2133 D3DPRESENT_PARAMETERS local_parameters;
2134 HRESULT hr;
2136 TRACE("iface %p, present_parameters %p, swapchain %p\n", iface, present_parameters, swapchain);
2138 /* Copy the presentation parameters */
2139 local_parameters.BackBufferWidth = present_parameters->BackBufferWidth;
2140 local_parameters.BackBufferHeight = present_parameters->BackBufferHeight;
2141 local_parameters.BackBufferFormat = d3dformat_from_wined3dformat(present_parameters->BackBufferFormat);
2142 local_parameters.BackBufferCount = present_parameters->BackBufferCount;
2143 local_parameters.MultiSampleType = present_parameters->MultiSampleType;
2144 local_parameters.MultiSampleQuality = present_parameters->MultiSampleQuality;
2145 local_parameters.SwapEffect = present_parameters->SwapEffect;
2146 local_parameters.hDeviceWindow = present_parameters->hDeviceWindow;
2147 local_parameters.Windowed = present_parameters->Windowed;
2148 local_parameters.EnableAutoDepthStencil = present_parameters->EnableAutoDepthStencil;
2149 local_parameters.AutoDepthStencilFormat = d3dformat_from_wined3dformat(present_parameters->AutoDepthStencilFormat);
2150 local_parameters.Flags = present_parameters->Flags;
2151 local_parameters.FullScreen_RefreshRateInHz = present_parameters->FullScreen_RefreshRateInHz;
2152 local_parameters.PresentationInterval = present_parameters->PresentationInterval;
2154 hr = IDirect3DDevice9Impl_CreateAdditionalSwapChain((IDirect3DDevice9Ex *)This,
2155 &local_parameters, (IDirect3DSwapChain9 **)&d3d_swapchain);
2156 if (FAILED(hr))
2158 ERR("(%p) CreateAdditionalSwapChain failed, returning %#x\n", iface, hr);
2159 *swapchain = NULL;
2160 return hr;
2163 *swapchain = d3d_swapchain->wineD3DSwapChain;
2164 d3d_swapchain->isImplicit = TRUE;
2165 /* Implicit swap chains are created with an refcount of 0 */
2166 IDirect3DSwapChain9_Release((IDirect3DSwapChain9 *)d3d_swapchain);
2168 /* Copy back the presentation parameters */
2169 present_parameters->BackBufferWidth = local_parameters.BackBufferWidth;
2170 present_parameters->BackBufferHeight = local_parameters.BackBufferHeight;
2171 present_parameters->BackBufferFormat = wined3dformat_from_d3dformat(local_parameters.BackBufferFormat);
2172 present_parameters->BackBufferCount = local_parameters.BackBufferCount;
2173 present_parameters->MultiSampleType = local_parameters.MultiSampleType;
2174 present_parameters->MultiSampleQuality = local_parameters.MultiSampleQuality;
2175 present_parameters->SwapEffect = local_parameters.SwapEffect;
2176 present_parameters->hDeviceWindow = local_parameters.hDeviceWindow;
2177 present_parameters->Windowed = local_parameters.Windowed;
2178 present_parameters->EnableAutoDepthStencil = local_parameters.EnableAutoDepthStencil;
2179 present_parameters->AutoDepthStencilFormat = wined3dformat_from_d3dformat(local_parameters.AutoDepthStencilFormat);
2180 present_parameters->Flags = local_parameters.Flags;
2181 present_parameters->FullScreen_RefreshRateInHz = local_parameters.FullScreen_RefreshRateInHz;
2182 present_parameters->PresentationInterval = local_parameters.PresentationInterval;
2184 return hr;
2187 const IWineD3DDeviceParentVtbl d3d9_wined3d_device_parent_vtbl =
2189 /* IUnknown methods */
2190 device_parent_QueryInterface,
2191 device_parent_AddRef,
2192 device_parent_Release,
2193 /* IWineD3DDeviceParent methods */
2194 device_parent_WineD3DDeviceCreated,
2195 device_parent_CreateSurface,
2196 device_parent_CreateRenderTarget,
2197 device_parent_CreateDepthStencilSurface,
2198 device_parent_CreateVolume,
2199 device_parent_CreateSwapChain,