d3d9: Add a separate function for volume initialization.
[wine/multimedia.git] / dlls / d3d9 / device.c
blob156490ad770d35fcae2dcbbe4253eebfcc20b0ea
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 wined3d_mutex_lock();
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_DestroySwapChain);
261 IWineD3DDevice_Release(This->WineD3DDevice);
262 wined3d_mutex_unlock();
264 HeapFree(GetProcessHeap(), 0, This);
266 return ref;
269 /* IDirect3DDevice Interface follow: */
270 static HRESULT WINAPI IDirect3DDevice9Impl_TestCooperativeLevel(LPDIRECT3DDEVICE9EX iface) {
271 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
272 HRESULT hr;
273 TRACE("(%p)\n", This);
275 wined3d_mutex_lock();
276 hr = IWineD3DDevice_TestCooperativeLevel(This->WineD3DDevice);
277 wined3d_mutex_unlock();
279 if(hr == WINED3D_OK && This->notreset) {
280 TRACE("D3D9 Device is marked not reset\n");
281 hr = D3DERR_DEVICENOTRESET;
284 return hr;
287 static UINT WINAPI IDirect3DDevice9Impl_GetAvailableTextureMem(LPDIRECT3DDEVICE9EX iface) {
288 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
289 HRESULT hr;
290 TRACE("(%p) Relay\n", This);
292 wined3d_mutex_lock();
293 hr = IWineD3DDevice_GetAvailableTextureMem(This->WineD3DDevice);
294 wined3d_mutex_unlock();
296 return hr;
299 static HRESULT WINAPI IDirect3DDevice9Impl_EvictManagedResources(LPDIRECT3DDEVICE9EX iface) {
300 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
301 HRESULT hr;
302 TRACE("(%p) : Relay\n", This);
304 wined3d_mutex_lock();
305 hr = IWineD3DDevice_EvictManagedResources(This->WineD3DDevice);
306 wined3d_mutex_unlock();
308 return hr;
311 static HRESULT WINAPI IDirect3DDevice9Impl_GetDirect3D(LPDIRECT3DDEVICE9EX iface, IDirect3D9** ppD3D9) {
312 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
313 HRESULT hr = D3D_OK;
314 IWineD3D* pWineD3D;
316 TRACE("(%p) Relay\n", This);
318 if (NULL == ppD3D9) {
319 return D3DERR_INVALIDCALL;
322 wined3d_mutex_lock();
323 hr = IWineD3DDevice_GetDirect3D(This->WineD3DDevice, &pWineD3D);
324 if (hr == D3D_OK && pWineD3D != NULL)
326 IWineD3D_GetParent(pWineD3D,(IUnknown **)ppD3D9);
327 IWineD3D_Release(pWineD3D);
328 } else {
329 FIXME("Call to IWineD3DDevice_GetDirect3D failed\n");
330 *ppD3D9 = NULL;
332 TRACE("(%p) returning %p\n", This, *ppD3D9);
333 wined3d_mutex_unlock();
335 return hr;
338 static HRESULT WINAPI IDirect3DDevice9Impl_GetDeviceCaps(LPDIRECT3DDEVICE9EX iface, D3DCAPS9* pCaps) {
339 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
340 HRESULT hrc = D3D_OK;
341 WINED3DCAPS *pWineCaps;
343 TRACE("(%p) : Relay pCaps %p\n", This, pCaps);
344 if(NULL == pCaps){
345 return D3DERR_INVALIDCALL;
347 pWineCaps = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WINED3DCAPS));
348 if(pWineCaps == NULL){
349 return D3DERR_INVALIDCALL; /* well this is what MSDN says to return */
352 memset(pCaps, 0, sizeof(*pCaps));
354 wined3d_mutex_lock();
355 hrc = IWineD3DDevice_GetDeviceCaps(This->WineD3DDevice, pWineCaps);
356 wined3d_mutex_unlock();
358 WINECAPSTOD3D9CAPS(pCaps, pWineCaps)
359 HeapFree(GetProcessHeap(), 0, pWineCaps);
361 /* Some functionality is implemented in d3d9.dll, not wined3d.dll. Add the needed caps */
362 pCaps->DevCaps2 |= D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES;
364 filter_caps(pCaps);
366 TRACE("Returning %p %p\n", This, pCaps);
367 return hrc;
370 static HRESULT WINAPI IDirect3DDevice9Impl_GetDisplayMode(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain, D3DDISPLAYMODE* pMode) {
371 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
372 HRESULT hr;
373 TRACE("(%p) Relay\n", This);
375 wined3d_mutex_lock();
376 hr = IWineD3DDevice_GetDisplayMode(This->WineD3DDevice, iSwapChain, (WINED3DDISPLAYMODE *) pMode);
377 wined3d_mutex_unlock();
379 if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format);
381 return hr;
384 static HRESULT WINAPI IDirect3DDevice9Impl_GetCreationParameters(LPDIRECT3DDEVICE9EX iface, D3DDEVICE_CREATION_PARAMETERS *pParameters) {
385 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
386 HRESULT hr;
387 TRACE("(%p) Relay\n", This);
389 wined3d_mutex_lock();
390 hr = IWineD3DDevice_GetCreationParameters(This->WineD3DDevice, (WINED3DDEVICE_CREATION_PARAMETERS *) pParameters);
391 wined3d_mutex_unlock();
393 return hr;
396 static HRESULT WINAPI IDirect3DDevice9Impl_SetCursorProperties(LPDIRECT3DDEVICE9EX iface, UINT XHotSpot, UINT YHotSpot, IDirect3DSurface9* pCursorBitmap) {
397 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
398 IDirect3DSurface9Impl *pSurface = (IDirect3DSurface9Impl*)pCursorBitmap;
399 HRESULT hr;
401 TRACE("(%p) Relay\n", This);
402 if(!pCursorBitmap) {
403 WARN("No cursor bitmap, returning WINED3DERR_INVALIDCALL\n");
404 return WINED3DERR_INVALIDCALL;
407 wined3d_mutex_lock();
408 hr = IWineD3DDevice_SetCursorProperties(This->WineD3DDevice, XHotSpot, YHotSpot, pSurface->wineD3DSurface);
409 wined3d_mutex_unlock();
411 return hr;
414 static void WINAPI IDirect3DDevice9Impl_SetCursorPosition(LPDIRECT3DDEVICE9EX iface, int XScreenSpace, int YScreenSpace, DWORD Flags) {
415 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
416 TRACE("(%p) Relay\n", This);
418 wined3d_mutex_lock();
419 IWineD3DDevice_SetCursorPosition(This->WineD3DDevice, XScreenSpace, YScreenSpace, Flags);
420 wined3d_mutex_unlock();
423 static BOOL WINAPI IDirect3DDevice9Impl_ShowCursor(LPDIRECT3DDEVICE9EX iface, BOOL bShow) {
424 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
425 BOOL ret;
426 TRACE("(%p) Relay\n", This);
428 wined3d_mutex_lock();
429 ret = IWineD3DDevice_ShowCursor(This->WineD3DDevice, bShow);
430 wined3d_mutex_unlock();
432 return ret;
435 static HRESULT WINAPI reset_enum_callback(IWineD3DResource *resource, void *data) {
436 BOOL *resources_ok = data;
437 D3DRESOURCETYPE type;
438 HRESULT ret = S_OK;
439 WINED3DSURFACE_DESC surface_desc;
440 WINED3DVOLUME_DESC volume_desc;
441 D3DINDEXBUFFER_DESC index_desc;
442 D3DVERTEXBUFFER_DESC vertex_desc;
443 WINED3DPOOL pool;
444 IDirect3DResource9 *parent;
446 IWineD3DResource_GetParent(resource, (IUnknown **) &parent);
447 type = IDirect3DResource9_GetType(parent);
448 switch(type) {
449 case D3DRTYPE_SURFACE:
450 IWineD3DSurface_GetDesc((IWineD3DSurface *) resource, &surface_desc);
451 pool = surface_desc.pool;
452 break;
454 case D3DRTYPE_VOLUME:
455 IWineD3DVolume_GetDesc((IWineD3DVolume *) resource, &volume_desc);
456 pool = volume_desc.Pool;
457 break;
459 case D3DRTYPE_INDEXBUFFER:
460 IDirect3DIndexBuffer9_GetDesc((IDirect3DIndexBuffer9 *) parent, &index_desc);
461 pool = index_desc.Pool;
462 break;
464 case D3DRTYPE_VERTEXBUFFER:
465 IDirect3DVertexBuffer9_GetDesc((IDirect3DVertexBuffer9 *)parent, &vertex_desc);
466 pool = vertex_desc.Pool;
467 break;
469 /* No need to check for textures. If there is a D3DPOOL_DEFAULT texture, there
470 * is a D3DPOOL_DEFAULT surface or volume as well
472 default:
473 pool = WINED3DPOOL_SCRATCH; /* a harmless pool */
474 break;
477 if(pool == WINED3DPOOL_DEFAULT) {
478 if(IUnknown_Release(parent) == 0) {
479 TRACE("Parent %p is an implicit resource with ref 0\n", parent);
480 } else {
481 WARN("Resource %p(wineD3D %p) with pool D3DPOOL_DEFAULT blocks the Reset call\n", parent, resource);
482 ret = S_FALSE;
483 *resources_ok = FALSE;
485 } else {
486 IUnknown_Release(parent);
488 IWineD3DResource_Release(resource);
490 return ret;
493 static HRESULT WINAPI IDirect3DDevice9Impl_Reset(LPDIRECT3DDEVICE9EX iface, D3DPRESENT_PARAMETERS* pPresentationParameters) {
494 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
495 WINED3DPRESENT_PARAMETERS localParameters;
496 HRESULT hr;
497 BOOL resources_ok = TRUE;
498 UINT i;
500 TRACE("(%p) Relay pPresentationParameters(%p)\n", This, pPresentationParameters);
502 /* Reset states that hold a COM object. WineD3D holds an internal reference to set objects, because
503 * such objects can still be used for rendering after their external d3d9 object has been destroyed.
504 * These objects must not be enumerated. Unsetting them tells WineD3D that the application will not
505 * make use of the hidden reference and destroys the objects.
507 * Unsetting them is no problem, because the states are supposed to be reset anyway. If the validation
508 * below fails, the device is considered "lost", and _Reset and _Release are the only allowed calls
510 wined3d_mutex_lock();
511 IWineD3DDevice_SetIndices(This->WineD3DDevice, NULL, WINED3DFMT_UNKNOWN);
512 for(i = 0; i < 16; i++) {
513 IWineD3DDevice_SetStreamSource(This->WineD3DDevice, i, NULL, 0, 0);
515 for(i = 0; i < 16; i++) {
516 IWineD3DDevice_SetTexture(This->WineD3DDevice, i, NULL);
519 IWineD3DDevice_EnumResources(This->WineD3DDevice, reset_enum_callback, &resources_ok);
520 if(!resources_ok) {
521 WARN("The application is holding D3DPOOL_DEFAULT resources, rejecting reset\n");
522 This->notreset = TRUE;
523 wined3d_mutex_unlock();
525 return WINED3DERR_INVALIDCALL;
528 localParameters.BackBufferWidth = pPresentationParameters->BackBufferWidth;
529 localParameters.BackBufferHeight = pPresentationParameters->BackBufferHeight;
530 localParameters.BackBufferFormat = wined3dformat_from_d3dformat(pPresentationParameters->BackBufferFormat);
531 localParameters.BackBufferCount = pPresentationParameters->BackBufferCount;
532 localParameters.MultiSampleType = pPresentationParameters->MultiSampleType;
533 localParameters.MultiSampleQuality = pPresentationParameters->MultiSampleQuality;
534 localParameters.SwapEffect = pPresentationParameters->SwapEffect;
535 localParameters.hDeviceWindow = pPresentationParameters->hDeviceWindow;
536 localParameters.Windowed = pPresentationParameters->Windowed;
537 localParameters.EnableAutoDepthStencil = pPresentationParameters->EnableAutoDepthStencil;
538 localParameters.AutoDepthStencilFormat = wined3dformat_from_d3dformat(pPresentationParameters->AutoDepthStencilFormat);
539 localParameters.Flags = pPresentationParameters->Flags;
540 localParameters.FullScreen_RefreshRateInHz = pPresentationParameters->FullScreen_RefreshRateInHz;
541 localParameters.PresentationInterval = pPresentationParameters->PresentationInterval;
542 localParameters.AutoRestoreDisplayMode = TRUE;
544 hr = IWineD3DDevice_Reset(This->WineD3DDevice, &localParameters);
545 if(FAILED(hr)) {
546 This->notreset = TRUE;
548 pPresentationParameters->BackBufferWidth = localParameters.BackBufferWidth;
549 pPresentationParameters->BackBufferHeight = localParameters.BackBufferHeight;
550 pPresentationParameters->BackBufferFormat = d3dformat_from_wined3dformat(localParameters.BackBufferFormat);
551 pPresentationParameters->BackBufferCount = localParameters.BackBufferCount;
552 pPresentationParameters->MultiSampleType = localParameters.MultiSampleType;
553 pPresentationParameters->MultiSampleQuality = localParameters.MultiSampleQuality;
554 pPresentationParameters->SwapEffect = localParameters.SwapEffect;
555 pPresentationParameters->hDeviceWindow = localParameters.hDeviceWindow;
556 pPresentationParameters->Windowed = localParameters.Windowed;
557 pPresentationParameters->EnableAutoDepthStencil = localParameters.EnableAutoDepthStencil;
558 pPresentationParameters->AutoDepthStencilFormat = d3dformat_from_wined3dformat(localParameters.AutoDepthStencilFormat);
559 pPresentationParameters->Flags = localParameters.Flags;
560 pPresentationParameters->FullScreen_RefreshRateInHz = localParameters.FullScreen_RefreshRateInHz;
561 pPresentationParameters->PresentationInterval = localParameters.PresentationInterval;
562 } else {
563 This->notreset = FALSE;
566 wined3d_mutex_unlock();
568 return hr;
571 static HRESULT WINAPI IDirect3DDevice9Impl_Present(LPDIRECT3DDEVICE9EX iface, CONST RECT* pSourceRect,CONST RECT* pDestRect,HWND hDestWindowOverride,CONST RGNDATA*
572 pDirtyRegion) {
573 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
574 HRESULT hr;
575 TRACE("(%p) Relay\n", This);
577 wined3d_mutex_lock();
578 hr = IWineD3DDevice_Present(This->WineD3DDevice, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
579 wined3d_mutex_unlock();
581 return hr;
584 static HRESULT WINAPI IDirect3DDevice9Impl_GetBackBuffer(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain, UINT BackBuffer, D3DBACKBUFFER_TYPE Type, IDirect3DSurface9 ** ppBackBuffer) {
585 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
586 IWineD3DSurface *retSurface = NULL;
587 HRESULT rc = D3D_OK;
589 TRACE("(%p) Relay\n", This);
591 wined3d_mutex_lock();
592 rc = IWineD3DDevice_GetBackBuffer(This->WineD3DDevice, iSwapChain, BackBuffer, (WINED3DBACKBUFFER_TYPE) Type, &retSurface);
593 if (rc == D3D_OK && NULL != retSurface && NULL != ppBackBuffer) {
594 IWineD3DSurface_GetParent(retSurface, (IUnknown **)ppBackBuffer);
595 IWineD3DSurface_Release(retSurface);
597 wined3d_mutex_unlock();
599 return rc;
601 static HRESULT WINAPI IDirect3DDevice9Impl_GetRasterStatus(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain, D3DRASTER_STATUS* pRasterStatus) {
602 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
603 HRESULT hr;
604 TRACE("(%p) Relay\n", This);
606 wined3d_mutex_lock();
607 hr = IWineD3DDevice_GetRasterStatus(This->WineD3DDevice, iSwapChain, (WINED3DRASTER_STATUS *) pRasterStatus);
608 wined3d_mutex_unlock();
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 wined3d_mutex_lock();
619 hr = IWineD3DDevice_SetDialogBoxMode(This->WineD3DDevice, bEnableDialogs);
620 wined3d_mutex_unlock();
622 return hr;
625 static void WINAPI IDirect3DDevice9Impl_SetGammaRamp(IDirect3DDevice9Ex *iface, UINT iSwapChain,
626 DWORD Flags, const D3DGAMMARAMP *pRamp)
628 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
629 TRACE("(%p) Relay\n", This);
631 /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
632 wined3d_mutex_lock();
633 IWineD3DDevice_SetGammaRamp(This->WineD3DDevice, iSwapChain, Flags, (CONST WINED3DGAMMARAMP *)pRamp);
634 wined3d_mutex_unlock();
637 static void WINAPI IDirect3DDevice9Impl_GetGammaRamp(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain, D3DGAMMARAMP* pRamp) {
638 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
639 TRACE("(%p) Relay\n", This);
641 /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
642 wined3d_mutex_lock();
643 IWineD3DDevice_GetGammaRamp(This->WineD3DDevice, iSwapChain, (WINED3DGAMMARAMP *) pRamp);
644 wined3d_mutex_unlock();
647 static HRESULT IDirect3DDevice9Impl_CreateSurface(LPDIRECT3DDEVICE9EX iface, UINT Width, UINT Height,
648 D3DFORMAT Format, BOOL Lockable, BOOL Discard, UINT Level, IDirect3DSurface9 **ppSurface,
649 UINT Usage, D3DPOOL Pool, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality)
651 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
652 IDirect3DSurface9Impl *object;
653 HRESULT hr;
655 TRACE("(%p) : w(%d) h(%d) fmt(%d) surf@%p\n", This, Width, Height, Format, *ppSurface);
657 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DSurface9Impl));
658 if (!object)
660 FIXME("Failed to allocate surface memory.\n");
661 return D3DERR_OUTOFVIDEOMEMORY;
664 hr = surface_init(object, This, Width, Height, Format, Lockable, Discard,
665 Level, Usage, Pool, MultiSample, MultisampleQuality);
666 if (FAILED(hr))
668 WARN("Failed to initialize surface, hr %#x.\n", hr);
669 HeapFree(GetProcessHeap(), 0, object);
670 return hr;
673 TRACE("Created surface %p.\n", object);
674 *ppSurface = (IDirect3DSurface9 *)object;
676 return D3D_OK;
679 static HRESULT WINAPI IDirect3DDevice9Impl_CreateRenderTarget(IDirect3DDevice9Ex *iface, UINT Width, UINT Height,
680 D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality, BOOL Lockable,
681 IDirect3DSurface9 **ppSurface, HANDLE *pSharedHandle)
683 HRESULT hr;
684 TRACE("Relay\n");
686 hr = IDirect3DDevice9Impl_CreateSurface(iface, Width, Height, Format, Lockable, FALSE /* Discard */,
687 0 /* Level */, ppSurface, D3DUSAGE_RENDERTARGET, D3DPOOL_DEFAULT, MultiSample, MultisampleQuality);
689 return hr;
692 static HRESULT WINAPI IDirect3DDevice9Impl_CreateDepthStencilSurface(LPDIRECT3DDEVICE9EX iface, UINT Width, UINT Height,
693 D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample,
694 DWORD MultisampleQuality, BOOL Discard,
695 IDirect3DSurface9 **ppSurface, HANDLE* pSharedHandle) {
696 HRESULT hr;
697 TRACE("Relay\n");
699 hr = IDirect3DDevice9Impl_CreateSurface(iface, Width, Height, Format, TRUE /* Lockable */, Discard,
700 0 /* Level */, ppSurface, D3DUSAGE_DEPTHSTENCIL, D3DPOOL_DEFAULT, MultiSample, MultisampleQuality);
702 return hr;
706 static HRESULT WINAPI IDirect3DDevice9Impl_UpdateSurface(LPDIRECT3DDEVICE9EX iface, IDirect3DSurface9* pSourceSurface, CONST RECT* pSourceRect, IDirect3DSurface9* pDestinationSurface, CONST POINT* pDestPoint) {
707 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
708 HRESULT hr;
709 TRACE("(%p) Relay\n" , This);
711 wined3d_mutex_lock();
712 hr = IWineD3DDevice_UpdateSurface(This->WineD3DDevice, ((IDirect3DSurface9Impl *)pSourceSurface)->wineD3DSurface, pSourceRect, ((IDirect3DSurface9Impl *)pDestinationSurface)->wineD3DSurface, pDestPoint);
713 wined3d_mutex_unlock();
715 return hr;
718 static HRESULT WINAPI IDirect3DDevice9Impl_UpdateTexture(LPDIRECT3DDEVICE9EX iface, IDirect3DBaseTexture9* pSourceTexture, IDirect3DBaseTexture9* pDestinationTexture) {
719 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
720 HRESULT hr;
721 TRACE("(%p) Relay\n" , This);
723 wined3d_mutex_lock();
724 hr = IWineD3DDevice_UpdateTexture(This->WineD3DDevice, ((IDirect3DBaseTexture9Impl *)pSourceTexture)->wineD3DBaseTexture, ((IDirect3DBaseTexture9Impl *)pDestinationTexture)->wineD3DBaseTexture);
725 wined3d_mutex_unlock();
727 return hr;
730 static HRESULT WINAPI IDirect3DDevice9Impl_GetRenderTargetData(LPDIRECT3DDEVICE9EX iface, IDirect3DSurface9* pRenderTarget, IDirect3DSurface9* pDestSurface) {
731 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
732 IDirect3DSurface9Impl *renderTarget = (IDirect3DSurface9Impl *)pRenderTarget;
733 IDirect3DSurface9Impl *destSurface = (IDirect3DSurface9Impl *)pDestSurface;
734 HRESULT hr;
735 TRACE("(%p)->(%p,%p)\n" , This, renderTarget, destSurface);
737 wined3d_mutex_lock();
738 hr = IWineD3DSurface_BltFast(destSurface->wineD3DSurface, 0, 0, renderTarget->wineD3DSurface, NULL, WINEDDBLTFAST_NOCOLORKEY);
739 wined3d_mutex_unlock();
741 return hr;
744 static HRESULT WINAPI IDirect3DDevice9Impl_GetFrontBufferData(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain, IDirect3DSurface9* pDestSurface) {
745 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
746 IDirect3DSurface9Impl *destSurface = (IDirect3DSurface9Impl *)pDestSurface;
747 HRESULT hr;
748 TRACE("(%p) Relay\n" , This);
750 wined3d_mutex_lock();
751 hr = IWineD3DDevice_GetFrontBufferData(This->WineD3DDevice, iSwapChain, destSurface->wineD3DSurface);
752 wined3d_mutex_unlock();
754 return hr;
757 static HRESULT WINAPI IDirect3DDevice9Impl_StretchRect(LPDIRECT3DDEVICE9EX iface, IDirect3DSurface9* pSourceSurface, CONST RECT* pSourceRect, IDirect3DSurface9* pDestSurface, CONST RECT* pDestRect, D3DTEXTUREFILTERTYPE Filter) {
758 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
759 IDirect3DSurface9Impl *src = (IDirect3DSurface9Impl *) pSourceSurface;
760 IDirect3DSurface9Impl *dst = (IDirect3DSurface9Impl *) pDestSurface;
761 HRESULT hr;
763 TRACE("(%p)->(%p,%p,%p,%p,%d)\n" , This, src, pSourceRect, dst, pDestRect, Filter);
765 wined3d_mutex_lock();
766 hr = IWineD3DSurface_Blt(dst->wineD3DSurface, pDestRect, src->wineD3DSurface, pSourceRect, 0, NULL, Filter);
767 wined3d_mutex_unlock();
769 return hr;
772 static HRESULT WINAPI IDirect3DDevice9Impl_ColorFill(LPDIRECT3DDEVICE9EX iface, IDirect3DSurface9* pSurface, CONST RECT* pRect, D3DCOLOR color) {
773 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
774 IDirect3DSurface9Impl *surface = (IDirect3DSurface9Impl *)pSurface;
775 WINED3DPOOL pool;
776 WINED3DRESOURCETYPE restype;
777 DWORD usage;
778 WINED3DSURFACE_DESC desc;
779 HRESULT hr;
780 TRACE("(%p) Relay\n" , This);
782 wined3d_mutex_lock();
784 IWineD3DSurface_GetDesc(surface->wineD3DSurface, &desc);
785 usage = desc.usage;
786 pool = desc.pool;
787 restype = desc.resource_type;
789 /* This method is only allowed with surfaces that are render targets, or offscreen plain surfaces
790 * in D3DPOOL_DEFAULT
792 if(!(usage & WINED3DUSAGE_RENDERTARGET) && (pool != WINED3DPOOL_DEFAULT || restype != WINED3DRTYPE_SURFACE)) {
793 wined3d_mutex_unlock();
794 WARN("Surface is not a render target, or not a stand-alone D3DPOOL_DEFAULT surface\n");
795 return D3DERR_INVALIDCALL;
798 /* Colorfill can only be used on rendertarget surfaces, or offscreen plain surfaces in D3DPOOL_DEFAULT */
799 /* Note: D3DRECT is compatible with WINED3DRECT */
800 hr = IWineD3DDevice_ColorFill(This->WineD3DDevice, surface->wineD3DSurface, (CONST WINED3DRECT*)pRect, color);
802 wined3d_mutex_unlock();
804 return hr;
807 static HRESULT WINAPI IDirect3DDevice9Impl_CreateOffscreenPlainSurface(LPDIRECT3DDEVICE9EX iface, UINT Width, UINT Height, D3DFORMAT Format, D3DPOOL Pool, IDirect3DSurface9 **ppSurface, HANDLE* pSharedHandle) {
808 HRESULT hr;
809 TRACE("Relay\n");
810 if(Pool == D3DPOOL_MANAGED ){
811 FIXME("Attempting to create a managed offscreen plain surface\n");
812 return D3DERR_INVALIDCALL;
815 'Off-screen plain surfaces are always lockable, regardless of their pool types.'
816 but then...
817 D3DPOOL_DEFAULT is the appropriate pool for use with the IDirect3DDevice9::StretchRect and IDirect3DDevice9::ColorFill.
818 Why, their always lockable?
819 should I change the usage to dynamic?
821 hr = IDirect3DDevice9Impl_CreateSurface(iface, Width, Height, Format, TRUE /* Lockable */, FALSE /* Discard */,
822 0 /* Level */, ppSurface, 0 /* Usage (undefined/none) */, (WINED3DPOOL)Pool, D3DMULTISAMPLE_NONE,
823 0 /* MultisampleQuality */);
825 return hr;
828 /* TODO: move to wineD3D */
829 static HRESULT WINAPI IDirect3DDevice9Impl_SetRenderTarget(LPDIRECT3DDEVICE9EX iface, DWORD RenderTargetIndex, IDirect3DSurface9* pRenderTarget) {
830 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
831 IDirect3DSurface9Impl *pSurface = (IDirect3DSurface9Impl*)pRenderTarget;
832 HRESULT hr;
833 TRACE("(%p) Relay\n" , This);
835 wined3d_mutex_lock();
836 hr = IWineD3DDevice_SetRenderTarget(This->WineD3DDevice, RenderTargetIndex, pSurface ? pSurface->wineD3DSurface : NULL);
837 wined3d_mutex_unlock();
839 return hr;
842 static HRESULT WINAPI IDirect3DDevice9Impl_GetRenderTarget(LPDIRECT3DDEVICE9EX iface, DWORD RenderTargetIndex, IDirect3DSurface9 **ppRenderTarget) {
843 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
844 IWineD3DSurface *pRenderTarget;
845 HRESULT hr;
847 TRACE("(%p) Relay\n" , This);
849 if (ppRenderTarget == NULL) {
850 return D3DERR_INVALIDCALL;
853 wined3d_mutex_lock();
855 hr=IWineD3DDevice_GetRenderTarget(This->WineD3DDevice,RenderTargetIndex,&pRenderTarget);
857 if (FAILED(hr))
859 FIXME("Call to IWineD3DDevice_GetRenderTarget failed, hr %#x\n", hr);
861 else if (!pRenderTarget)
863 *ppRenderTarget = NULL;
865 else
867 IWineD3DSurface_GetParent(pRenderTarget, (IUnknown **)ppRenderTarget);
868 IWineD3DSurface_Release(pRenderTarget);
871 wined3d_mutex_unlock();
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;
884 wined3d_mutex_lock();
885 hr = IWineD3DDevice_SetDepthStencilSurface(This->WineD3DDevice, NULL==pSurface ? NULL : pSurface->wineD3DSurface);
886 wined3d_mutex_unlock();
888 return hr;
891 static HRESULT WINAPI IDirect3DDevice9Impl_GetDepthStencilSurface(LPDIRECT3DDEVICE9EX iface, IDirect3DSurface9 **ppZStencilSurface) {
892 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
893 HRESULT hr = D3D_OK;
894 IWineD3DSurface *pZStencilSurface;
896 TRACE("(%p) Relay\n" , This);
897 if(ppZStencilSurface == NULL){
898 return D3DERR_INVALIDCALL;
901 wined3d_mutex_lock();
902 hr = IWineD3DDevice_GetDepthStencilSurface(This->WineD3DDevice,&pZStencilSurface);
903 if (hr == WINED3D_OK) {
904 IWineD3DSurface_GetParent(pZStencilSurface,(IUnknown**)ppZStencilSurface);
905 IWineD3DSurface_Release(pZStencilSurface);
906 } else {
907 if (hr != WINED3DERR_NOTFOUND)
908 WARN("Call to IWineD3DDevice_GetDepthStencilSurface failed with 0x%08x\n", hr);
909 *ppZStencilSurface = NULL;
911 wined3d_mutex_unlock();
913 return hr;
916 static HRESULT WINAPI IDirect3DDevice9Impl_BeginScene(LPDIRECT3DDEVICE9EX iface) {
917 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
918 HRESULT hr;
919 TRACE("(%p) Relay\n" , This);
921 wined3d_mutex_lock();
922 hr = IWineD3DDevice_BeginScene(This->WineD3DDevice);
923 wined3d_mutex_unlock();
925 return hr;
928 static HRESULT WINAPI IDirect3DDevice9Impl_EndScene(LPDIRECT3DDEVICE9EX iface) {
929 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
930 HRESULT hr;
931 TRACE("(%p) Relay\n" , This);
933 wined3d_mutex_lock();
934 hr = IWineD3DDevice_EndScene(This->WineD3DDevice);
935 wined3d_mutex_unlock();
937 return hr;
940 static HRESULT WINAPI IDirect3DDevice9Impl_Clear(LPDIRECT3DDEVICE9EX iface, DWORD Count, CONST D3DRECT* pRects, DWORD Flags, D3DCOLOR Color, float Z, DWORD Stencil) {
941 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
942 HRESULT hr;
943 TRACE("(%p) Relay\n" , This);
945 /* Note: D3DRECT is compatible with WINED3DRECT */
946 wined3d_mutex_lock();
947 hr = IWineD3DDevice_Clear(This->WineD3DDevice, Count, (CONST WINED3DRECT*) pRects, Flags, Color, Z, Stencil);
948 wined3d_mutex_unlock();
950 return hr;
953 static HRESULT WINAPI IDirect3DDevice9Impl_SetTransform(LPDIRECT3DDEVICE9EX iface, D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX* lpMatrix) {
954 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
955 HRESULT hr;
956 TRACE("(%p) Relay\n" , This);
958 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
959 wined3d_mutex_lock();
960 hr = IWineD3DDevice_SetTransform(This->WineD3DDevice, State, (CONST WINED3DMATRIX*) lpMatrix);
961 wined3d_mutex_unlock();
963 return hr;
966 static HRESULT WINAPI IDirect3DDevice9Impl_GetTransform(LPDIRECT3DDEVICE9EX iface, D3DTRANSFORMSTATETYPE State, D3DMATRIX* pMatrix) {
967 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
968 HRESULT hr;
970 TRACE("(%p) Relay\n" , This);
972 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
973 wined3d_mutex_lock();
974 hr = IWineD3DDevice_GetTransform(This->WineD3DDevice, State, (WINED3DMATRIX*) pMatrix);
975 wined3d_mutex_unlock();
977 return hr;
980 static HRESULT WINAPI IDirect3DDevice9Impl_MultiplyTransform(LPDIRECT3DDEVICE9EX iface, D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX* pMatrix) {
981 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
982 HRESULT hr;
983 TRACE("(%p) Relay\n" , This);
985 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
986 wined3d_mutex_lock();
987 hr = IWineD3DDevice_MultiplyTransform(This->WineD3DDevice, State, (CONST WINED3DMATRIX*) pMatrix);
988 wined3d_mutex_unlock();
990 return hr;
993 static HRESULT WINAPI IDirect3DDevice9Impl_SetViewport(LPDIRECT3DDEVICE9EX iface, CONST D3DVIEWPORT9* pViewport) {
994 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
995 HRESULT hr;
996 TRACE("(%p) Relay\n" , This);
998 /* Note: D3DVIEWPORT9 is compatible with WINED3DVIEWPORT */
999 wined3d_mutex_lock();
1000 hr = IWineD3DDevice_SetViewport(This->WineD3DDevice, (const WINED3DVIEWPORT *)pViewport);
1001 wined3d_mutex_unlock();
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 wined3d_mutex_lock();
1013 hr = IWineD3DDevice_GetViewport(This->WineD3DDevice, (WINED3DVIEWPORT *)pViewport);
1014 wined3d_mutex_unlock();
1016 return hr;
1019 static HRESULT WINAPI IDirect3DDevice9Impl_SetMaterial(LPDIRECT3DDEVICE9EX iface, CONST D3DMATERIAL9* pMaterial) {
1020 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1021 HRESULT hr;
1022 TRACE("(%p) Relay\n" , This);
1024 /* Note: D3DMATERIAL9 is compatible with WINED3DMATERIAL */
1025 wined3d_mutex_lock();
1026 hr = IWineD3DDevice_SetMaterial(This->WineD3DDevice, (const WINED3DMATERIAL *)pMaterial);
1027 wined3d_mutex_unlock();
1029 return hr;
1032 static HRESULT WINAPI IDirect3DDevice9Impl_GetMaterial(LPDIRECT3DDEVICE9EX iface, D3DMATERIAL9* pMaterial) {
1033 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1034 HRESULT hr;
1035 TRACE("(%p) Relay\n" , This);
1037 /* Note: D3DMATERIAL9 is compatible with WINED3DMATERIAL */
1038 wined3d_mutex_lock();
1039 hr = IWineD3DDevice_GetMaterial(This->WineD3DDevice, (WINED3DMATERIAL *)pMaterial);
1040 wined3d_mutex_unlock();
1042 return hr;
1045 static HRESULT WINAPI IDirect3DDevice9Impl_SetLight(LPDIRECT3DDEVICE9EX iface, DWORD Index, CONST D3DLIGHT9* pLight) {
1046 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1047 HRESULT hr;
1048 TRACE("(%p) Relay\n" , This);
1050 /* Note: D3DLIGHT9 is compatible with WINED3DLIGHT */
1051 wined3d_mutex_lock();
1052 hr = IWineD3DDevice_SetLight(This->WineD3DDevice, Index, (const WINED3DLIGHT *)pLight);
1053 wined3d_mutex_unlock();
1055 return hr;
1058 static HRESULT WINAPI IDirect3DDevice9Impl_GetLight(LPDIRECT3DDEVICE9EX iface, DWORD Index, D3DLIGHT9* pLight) {
1059 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1060 HRESULT hr;
1061 TRACE("(%p) Relay\n" , This);
1063 /* Note: D3DLIGHT9 is compatible with WINED3DLIGHT */
1064 wined3d_mutex_lock();
1065 hr = IWineD3DDevice_GetLight(This->WineD3DDevice, Index, (WINED3DLIGHT *)pLight);
1066 wined3d_mutex_unlock();
1068 return hr;
1071 static HRESULT WINAPI IDirect3DDevice9Impl_LightEnable(LPDIRECT3DDEVICE9EX iface, DWORD Index, BOOL Enable) {
1072 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1073 HRESULT hr;
1074 TRACE("(%p) Relay\n" , This);
1076 wined3d_mutex_lock();
1077 hr = IWineD3DDevice_SetLightEnable(This->WineD3DDevice, Index, Enable);
1078 wined3d_mutex_unlock();
1080 return hr;
1083 static HRESULT WINAPI IDirect3DDevice9Impl_GetLightEnable(LPDIRECT3DDEVICE9EX iface, DWORD Index, BOOL* pEnable) {
1084 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1085 HRESULT hr;
1086 TRACE("(%p) Relay\n" , This);
1088 wined3d_mutex_lock();
1089 hr = IWineD3DDevice_GetLightEnable(This->WineD3DDevice, Index, pEnable);
1090 wined3d_mutex_unlock();
1092 return hr;
1095 static HRESULT WINAPI IDirect3DDevice9Impl_SetClipPlane(LPDIRECT3DDEVICE9EX iface, DWORD Index, CONST float* pPlane) {
1096 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1097 HRESULT hr;
1098 TRACE("(%p) Relay\n" , This);
1100 wined3d_mutex_lock();
1101 hr = IWineD3DDevice_SetClipPlane(This->WineD3DDevice, Index, pPlane);
1102 wined3d_mutex_unlock();
1104 return hr;
1107 static HRESULT WINAPI IDirect3DDevice9Impl_GetClipPlane(LPDIRECT3DDEVICE9EX iface, DWORD Index, float* pPlane) {
1108 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1109 HRESULT hr;
1110 TRACE("(%p) Relay\n" , This);
1112 wined3d_mutex_lock();
1113 hr = IWineD3DDevice_GetClipPlane(This->WineD3DDevice, Index, pPlane);
1114 wined3d_mutex_unlock();
1116 return hr;
1119 static HRESULT WINAPI IDirect3DDevice9Impl_SetRenderState(LPDIRECT3DDEVICE9EX iface, D3DRENDERSTATETYPE State, DWORD Value) {
1120 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1121 HRESULT hr;
1122 TRACE("(%p) Relay\n" , This);
1124 wined3d_mutex_lock();
1125 hr = IWineD3DDevice_SetRenderState(This->WineD3DDevice, State, Value);
1126 wined3d_mutex_unlock();
1128 return hr;
1131 static HRESULT WINAPI IDirect3DDevice9Impl_GetRenderState(LPDIRECT3DDEVICE9EX iface, D3DRENDERSTATETYPE State, DWORD* pValue) {
1132 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1133 HRESULT hr;
1134 TRACE("(%p) Relay\n" , This);
1136 wined3d_mutex_lock();
1137 hr = IWineD3DDevice_GetRenderState(This->WineD3DDevice, State, pValue);
1138 wined3d_mutex_unlock();
1140 return hr;
1143 static HRESULT WINAPI IDirect3DDevice9Impl_SetClipStatus(LPDIRECT3DDEVICE9EX iface, CONST D3DCLIPSTATUS9* pClipStatus) {
1144 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1145 HRESULT hr;
1146 TRACE("(%p) Relay\n" , This);
1148 wined3d_mutex_lock();
1149 hr = IWineD3DDevice_SetClipStatus(This->WineD3DDevice, (const WINED3DCLIPSTATUS *)pClipStatus);
1150 wined3d_mutex_unlock();
1152 return hr;
1155 static HRESULT WINAPI IDirect3DDevice9Impl_GetClipStatus(LPDIRECT3DDEVICE9EX iface, D3DCLIPSTATUS9* pClipStatus) {
1156 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1157 HRESULT hr;
1158 TRACE("(%p) Relay\n" , This);
1160 wined3d_mutex_lock();
1161 hr = IWineD3DDevice_GetClipStatus(This->WineD3DDevice, (WINED3DCLIPSTATUS *)pClipStatus);
1162 wined3d_mutex_unlock();
1164 return hr;
1167 static HRESULT WINAPI IDirect3DDevice9Impl_GetTexture(LPDIRECT3DDEVICE9EX iface, DWORD Stage, IDirect3DBaseTexture9 **ppTexture) {
1168 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1169 IWineD3DBaseTexture *retTexture = NULL;
1170 HRESULT rc = D3D_OK;
1172 TRACE("(%p) Relay\n" , This);
1174 if(ppTexture == NULL){
1175 return D3DERR_INVALIDCALL;
1178 wined3d_mutex_lock();
1179 rc = IWineD3DDevice_GetTexture(This->WineD3DDevice, Stage, &retTexture);
1180 if (SUCCEEDED(rc) && NULL != retTexture) {
1181 IWineD3DBaseTexture_GetParent(retTexture, (IUnknown **)ppTexture);
1182 IWineD3DBaseTexture_Release(retTexture);
1183 } else {
1184 if(FAILED(rc)) {
1185 WARN("Call to get texture (%d) failed (%p)\n", Stage, retTexture);
1187 *ppTexture = NULL;
1189 wined3d_mutex_unlock();
1191 return rc;
1194 static HRESULT WINAPI IDirect3DDevice9Impl_SetTexture(LPDIRECT3DDEVICE9EX iface, DWORD Stage, IDirect3DBaseTexture9* pTexture) {
1195 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1196 HRESULT hr;
1197 TRACE("(%p) Relay %d %p\n" , This, Stage, pTexture);
1199 wined3d_mutex_lock();
1200 hr = IWineD3DDevice_SetTexture(This->WineD3DDevice, Stage,
1201 pTexture==NULL ? NULL:((IDirect3DBaseTexture9Impl *)pTexture)->wineD3DBaseTexture);
1202 wined3d_mutex_unlock();
1204 return hr;
1207 static const WINED3DTEXTURESTAGESTATETYPE tss_lookup[] =
1209 WINED3DTSS_FORCE_DWORD, /* 0, unused */
1210 WINED3DTSS_COLOROP, /* 1, D3DTSS_COLOROP */
1211 WINED3DTSS_COLORARG1, /* 2, D3DTSS_COLORARG1 */
1212 WINED3DTSS_COLORARG2, /* 3, D3DTSS_COLORARG2 */
1213 WINED3DTSS_ALPHAOP, /* 4, D3DTSS_ALPHAOP */
1214 WINED3DTSS_ALPHAARG1, /* 5, D3DTSS_ALPHAARG1 */
1215 WINED3DTSS_ALPHAARG2, /* 6, D3DTSS_ALPHAARG2 */
1216 WINED3DTSS_BUMPENVMAT00, /* 7, D3DTSS_BUMPENVMAT00 */
1217 WINED3DTSS_BUMPENVMAT01, /* 8, D3DTSS_BUMPENVMAT01 */
1218 WINED3DTSS_BUMPENVMAT10, /* 9, D3DTSS_BUMPENVMAT10 */
1219 WINED3DTSS_BUMPENVMAT11, /* 10, D3DTSS_BUMPENVMAT11 */
1220 WINED3DTSS_TEXCOORDINDEX, /* 11, D3DTSS_TEXCOORDINDEX */
1221 WINED3DTSS_FORCE_DWORD, /* 12, unused */
1222 WINED3DTSS_FORCE_DWORD, /* 13, unused */
1223 WINED3DTSS_FORCE_DWORD, /* 14, unused */
1224 WINED3DTSS_FORCE_DWORD, /* 15, unused */
1225 WINED3DTSS_FORCE_DWORD, /* 16, unused */
1226 WINED3DTSS_FORCE_DWORD, /* 17, unused */
1227 WINED3DTSS_FORCE_DWORD, /* 18, unused */
1228 WINED3DTSS_FORCE_DWORD, /* 19, unused */
1229 WINED3DTSS_FORCE_DWORD, /* 20, unused */
1230 WINED3DTSS_FORCE_DWORD, /* 21, unused */
1231 WINED3DTSS_BUMPENVLSCALE, /* 22, D3DTSS_BUMPENVLSCALE */
1232 WINED3DTSS_BUMPENVLOFFSET, /* 23, D3DTSS_BUMPENVLOFFSET */
1233 WINED3DTSS_TEXTURETRANSFORMFLAGS, /* 24, D3DTSS_TEXTURETRANSFORMFLAGS */
1234 WINED3DTSS_FORCE_DWORD, /* 25, unused */
1235 WINED3DTSS_COLORARG0, /* 26, D3DTSS_COLORARG0 */
1236 WINED3DTSS_ALPHAARG0, /* 27, D3DTSS_ALPHAARG0 */
1237 WINED3DTSS_RESULTARG, /* 28, D3DTSS_RESULTARG */
1238 WINED3DTSS_FORCE_DWORD, /* 29, unused */
1239 WINED3DTSS_FORCE_DWORD, /* 30, unused */
1240 WINED3DTSS_FORCE_DWORD, /* 31, unused */
1241 WINED3DTSS_CONSTANT, /* 32, D3DTSS_CONSTANT */
1244 static HRESULT WINAPI IDirect3DDevice9Impl_GetTextureStageState(LPDIRECT3DDEVICE9EX iface, DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD* pValue) {
1245 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1246 HRESULT hr;
1247 TRACE("(%p) Relay\n" , This);
1249 wined3d_mutex_lock();
1250 hr = IWineD3DDevice_GetTextureStageState(This->WineD3DDevice, Stage, tss_lookup[Type], pValue);
1251 wined3d_mutex_unlock();
1253 return hr;
1256 static HRESULT WINAPI IDirect3DDevice9Impl_SetTextureStageState(LPDIRECT3DDEVICE9EX iface, DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD Value) {
1257 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1258 HRESULT hr;
1259 TRACE("(%p) Relay\n" , This);
1261 wined3d_mutex_lock();
1262 hr = IWineD3DDevice_SetTextureStageState(This->WineD3DDevice, Stage, tss_lookup[Type], Value);
1263 wined3d_mutex_unlock();
1265 return hr;
1268 static HRESULT WINAPI IDirect3DDevice9Impl_GetSamplerState(IDirect3DDevice9Ex *iface, DWORD Sampler,
1269 D3DSAMPLERSTATETYPE Type, DWORD *pValue)
1271 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1272 HRESULT hr;
1273 TRACE("(%p) Relay\n" , This);
1275 wined3d_mutex_lock();
1276 hr = IWineD3DDevice_GetSamplerState(This->WineD3DDevice, Sampler, Type, pValue);
1277 wined3d_mutex_unlock();
1279 return hr;
1282 static HRESULT WINAPI IDirect3DDevice9Impl_SetSamplerState(LPDIRECT3DDEVICE9EX iface, DWORD Sampler, D3DSAMPLERSTATETYPE Type, DWORD Value) {
1283 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1284 HRESULT hr;
1285 TRACE("(%p) Relay\n" , This);
1287 wined3d_mutex_lock();
1288 hr = IWineD3DDevice_SetSamplerState(This->WineD3DDevice, Sampler, Type, Value);
1289 wined3d_mutex_unlock();
1291 return hr;
1294 static HRESULT WINAPI IDirect3DDevice9Impl_ValidateDevice(LPDIRECT3DDEVICE9EX iface, DWORD* pNumPasses) {
1295 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1296 HRESULT hr;
1297 TRACE("(%p) Relay\n" , This);
1299 wined3d_mutex_lock();
1300 hr = IWineD3DDevice_ValidateDevice(This->WineD3DDevice, pNumPasses);
1301 wined3d_mutex_unlock();
1303 return hr;
1306 static HRESULT WINAPI IDirect3DDevice9Impl_SetPaletteEntries(IDirect3DDevice9Ex *iface, UINT PaletteNumber,
1307 const PALETTEENTRY *pEntries)
1309 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1310 HRESULT hr;
1311 TRACE("(%p) Relay\n" , This);
1313 wined3d_mutex_lock();
1314 hr = IWineD3DDevice_SetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
1315 wined3d_mutex_unlock();
1317 return hr;
1320 static HRESULT WINAPI IDirect3DDevice9Impl_GetPaletteEntries(LPDIRECT3DDEVICE9EX iface, UINT PaletteNumber, PALETTEENTRY* pEntries) {
1321 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1322 HRESULT hr;
1323 TRACE("(%p) Relay\n" , This);
1325 wined3d_mutex_lock();
1326 hr = IWineD3DDevice_GetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
1327 wined3d_mutex_unlock();
1329 return hr;
1332 static HRESULT WINAPI IDirect3DDevice9Impl_SetCurrentTexturePalette(LPDIRECT3DDEVICE9EX iface, UINT PaletteNumber) {
1333 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1334 HRESULT hr;
1335 TRACE("(%p) Relay\n" , This);
1337 wined3d_mutex_lock();
1338 hr = IWineD3DDevice_SetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
1339 wined3d_mutex_unlock();
1341 return hr;
1344 static HRESULT WINAPI IDirect3DDevice9Impl_GetCurrentTexturePalette(LPDIRECT3DDEVICE9EX iface, UINT* PaletteNumber) {
1345 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1346 HRESULT hr;
1347 TRACE("(%p) Relay\n" , This);
1349 wined3d_mutex_lock();
1350 hr = IWineD3DDevice_GetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
1351 wined3d_mutex_unlock();
1353 return hr;
1356 static HRESULT WINAPI IDirect3DDevice9Impl_SetScissorRect(LPDIRECT3DDEVICE9EX iface, CONST RECT* pRect) {
1357 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1358 HRESULT hr;
1359 TRACE("(%p) Relay\n" , This);
1361 wined3d_mutex_lock();
1362 hr = IWineD3DDevice_SetScissorRect(This->WineD3DDevice, pRect);
1363 wined3d_mutex_unlock();
1365 return hr;
1368 static HRESULT WINAPI IDirect3DDevice9Impl_GetScissorRect(LPDIRECT3DDEVICE9EX iface, RECT* pRect) {
1369 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1370 HRESULT hr;
1371 TRACE("(%p) Relay\n" , This);
1373 wined3d_mutex_lock();
1374 hr = IWineD3DDevice_GetScissorRect(This->WineD3DDevice, pRect);
1375 wined3d_mutex_unlock();
1377 return hr;
1380 static HRESULT WINAPI IDirect3DDevice9Impl_SetSoftwareVertexProcessing(LPDIRECT3DDEVICE9EX iface, BOOL bSoftware) {
1381 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1382 HRESULT hr;
1383 TRACE("(%p) Relay\n" , This);
1385 wined3d_mutex_lock();
1386 hr = IWineD3DDevice_SetSoftwareVertexProcessing(This->WineD3DDevice, bSoftware);
1387 wined3d_mutex_unlock();
1389 return hr;
1392 static BOOL WINAPI IDirect3DDevice9Impl_GetSoftwareVertexProcessing(LPDIRECT3DDEVICE9EX iface) {
1393 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1394 BOOL ret;
1395 TRACE("(%p) Relay\n" , This);
1397 wined3d_mutex_lock();
1398 ret = IWineD3DDevice_GetSoftwareVertexProcessing(This->WineD3DDevice);
1399 wined3d_mutex_unlock();
1401 return ret;
1404 static HRESULT WINAPI IDirect3DDevice9Impl_SetNPatchMode(LPDIRECT3DDEVICE9EX iface, float nSegments) {
1405 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1406 HRESULT hr;
1407 TRACE("(%p) Relay\n" , This);
1409 wined3d_mutex_lock();
1410 hr = IWineD3DDevice_SetNPatchMode(This->WineD3DDevice, nSegments);
1411 wined3d_mutex_unlock();
1413 return hr;
1416 static float WINAPI IDirect3DDevice9Impl_GetNPatchMode(LPDIRECT3DDEVICE9EX iface) {
1417 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1418 float ret;
1419 TRACE("(%p) Relay\n" , This);
1421 wined3d_mutex_lock();
1422 ret = IWineD3DDevice_GetNPatchMode(This->WineD3DDevice);
1423 wined3d_mutex_unlock();
1425 return ret;
1428 static HRESULT WINAPI IDirect3DDevice9Impl_DrawPrimitive(IDirect3DDevice9Ex *iface, D3DPRIMITIVETYPE PrimitiveType,
1429 UINT StartVertex, UINT PrimitiveCount)
1431 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1432 HRESULT hr;
1433 TRACE("(%p) Relay\n" , This);
1435 wined3d_mutex_lock();
1436 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1437 hr = IWineD3DDevice_DrawPrimitive(This->WineD3DDevice, StartVertex,
1438 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount));
1439 wined3d_mutex_unlock();
1441 return hr;
1444 static HRESULT WINAPI IDirect3DDevice9Impl_DrawIndexedPrimitive(LPDIRECT3DDEVICE9EX iface, D3DPRIMITIVETYPE PrimitiveType,
1445 INT BaseVertexIndex, UINT MinVertexIndex, UINT NumVertices, UINT startIndex, UINT primCount) {
1446 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1447 HRESULT hr;
1448 TRACE("(%p) Relay\n" , This);
1450 /* D3D8 passes the baseVertexIndex in SetIndices, and due to the stateblock functions wined3d has to work that way */
1451 wined3d_mutex_lock();
1452 IWineD3DDevice_SetBaseVertexIndex(This->WineD3DDevice, BaseVertexIndex);
1453 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1454 hr = IWineD3DDevice_DrawIndexedPrimitive(This->WineD3DDevice, startIndex,
1455 vertex_count_from_primitive_count(PrimitiveType, primCount));
1456 wined3d_mutex_unlock();
1458 return hr;
1461 static HRESULT WINAPI IDirect3DDevice9Impl_DrawPrimitiveUP(IDirect3DDevice9Ex *iface, D3DPRIMITIVETYPE PrimitiveType,
1462 UINT PrimitiveCount, const void *pVertexStreamZeroData, UINT VertexStreamZeroStride)
1464 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1465 HRESULT hr;
1466 TRACE("(%p) Relay\n" , This);
1468 wined3d_mutex_lock();
1469 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1470 hr = IWineD3DDevice_DrawPrimitiveUP(This->WineD3DDevice,
1471 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount),
1472 pVertexStreamZeroData, VertexStreamZeroStride);
1473 wined3d_mutex_unlock();
1475 return hr;
1478 static HRESULT WINAPI IDirect3DDevice9Impl_DrawIndexedPrimitiveUP(LPDIRECT3DDEVICE9EX iface, D3DPRIMITIVETYPE PrimitiveType, UINT MinVertexIndex,
1479 UINT NumVertexIndices, UINT PrimitiveCount, CONST void* pIndexData,
1480 D3DFORMAT IndexDataFormat, CONST void* pVertexStreamZeroData, UINT VertexStreamZeroStride) {
1481 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1482 HRESULT hr;
1483 TRACE("(%p) Relay\n" , This);
1485 wined3d_mutex_lock();
1486 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1487 hr = IWineD3DDevice_DrawIndexedPrimitiveUP(This->WineD3DDevice,
1488 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount), pIndexData,
1489 wined3dformat_from_d3dformat(IndexDataFormat), pVertexStreamZeroData, VertexStreamZeroStride);
1490 wined3d_mutex_unlock();
1492 return hr;
1495 static HRESULT WINAPI IDirect3DDevice9Impl_ProcessVertices(LPDIRECT3DDEVICE9EX iface, UINT SrcStartIndex, UINT DestIndex, UINT VertexCount, IDirect3DVertexBuffer9* pDestBuffer, IDirect3DVertexDeclaration9* pVertexDecl, DWORD Flags) {
1496 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1497 IDirect3DVertexDeclaration9Impl *Decl = (IDirect3DVertexDeclaration9Impl *) pVertexDecl;
1498 HRESULT hr;
1499 IDirect3DVertexBuffer9Impl *dest = (IDirect3DVertexBuffer9Impl *) pDestBuffer;
1500 TRACE("(%p) Relay\n" , This);
1502 wined3d_mutex_lock();
1503 hr = IWineD3DDevice_ProcessVertices(This->WineD3DDevice,SrcStartIndex, DestIndex, VertexCount, dest->wineD3DVertexBuffer, Decl ? Decl->wineD3DVertexDeclaration : NULL, Flags, dest->fvf);
1504 wined3d_mutex_unlock();
1506 return hr;
1509 static IDirect3DVertexDeclaration9 *getConvertedDecl(IDirect3DDevice9Impl *This, DWORD fvf) {
1510 HRESULT hr;
1511 D3DVERTEXELEMENT9* elements = NULL;
1512 IDirect3DVertexDeclaration9* pDecl = NULL;
1513 int p, low, high; /* deliberately signed */
1514 IDirect3DVertexDeclaration9 **convertedDecls = This->convertedDecls;
1516 TRACE("Searching for declaration for fvf %08x... ", fvf);
1518 low = 0;
1519 high = This->numConvertedDecls - 1;
1520 while(low <= high) {
1521 p = (low + high) >> 1;
1522 TRACE("%d ", p);
1523 if(((IDirect3DVertexDeclaration9Impl *) convertedDecls[p])->convFVF == fvf) {
1524 TRACE("found %p\n", convertedDecls[p]);
1525 return convertedDecls[p];
1526 } else if(((IDirect3DVertexDeclaration9Impl *) convertedDecls[p])->convFVF < fvf) {
1527 low = p + 1;
1528 } else {
1529 high = p - 1;
1532 TRACE("not found. Creating and inserting at position %d.\n", low);
1534 hr = vdecl_convert_fvf(fvf, &elements);
1535 if (hr != S_OK) return NULL;
1537 hr = IDirect3DDevice9Impl_CreateVertexDeclaration((IDirect3DDevice9Ex *) This, elements, &pDecl);
1538 HeapFree(GetProcessHeap(), 0, elements); /* CreateVertexDeclaration makes a copy */
1539 if (hr != S_OK) return NULL;
1541 if(This->declArraySize == This->numConvertedDecls) {
1542 int grow = max(This->declArraySize / 2, 8);
1543 convertedDecls = HeapReAlloc(GetProcessHeap(), 0, convertedDecls,
1544 sizeof(convertedDecls[0]) * (This->numConvertedDecls + grow));
1545 if(!convertedDecls) {
1546 /* This will destroy it */
1547 IDirect3DVertexDeclaration9_Release(pDecl);
1548 return NULL;
1550 This->convertedDecls = convertedDecls;
1551 This->declArraySize += grow;
1554 memmove(convertedDecls + low + 1, convertedDecls + low, sizeof(IDirect3DVertexDeclaration9Impl *) * (This->numConvertedDecls - low));
1555 convertedDecls[low] = pDecl;
1556 This->numConvertedDecls++;
1558 /* Will prevent the decl from being destroyed */
1559 ((IDirect3DVertexDeclaration9Impl *) pDecl)->convFVF = fvf;
1560 IDirect3DVertexDeclaration9_Release(pDecl); /* Does not destroy now */
1562 TRACE("Returning %p. %d decls in array\n", pDecl, This->numConvertedDecls);
1563 return pDecl;
1566 static HRESULT WINAPI IDirect3DDevice9Impl_SetFVF(LPDIRECT3DDEVICE9EX iface, DWORD FVF) {
1567 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1568 IDirect3DVertexDeclaration9 *decl;
1569 HRESULT hr;
1571 TRACE("(%p) Relay\n" , This);
1573 if (!FVF)
1575 WARN("%#x is not a valid FVF\n", FVF);
1576 return D3D_OK;
1579 wined3d_mutex_lock();
1580 decl = getConvertedDecl(This, FVF);
1581 wined3d_mutex_unlock();
1583 if (!decl)
1585 /* Any situation when this should happen, except out of memory? */
1586 ERR("Failed to create a converted vertex declaration\n");
1587 return D3DERR_DRIVERINTERNALERROR;
1590 hr = IDirect3DDevice9Impl_SetVertexDeclaration(iface, decl);
1591 if (FAILED(hr)) ERR("Failed to set vertex declaration\n");
1593 return hr;
1596 static HRESULT WINAPI IDirect3DDevice9Impl_GetFVF(LPDIRECT3DDEVICE9EX iface, DWORD* pFVF) {
1597 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1598 IDirect3DVertexDeclaration9 *decl;
1599 HRESULT hr;
1600 TRACE("(%p) Relay\n" , This);
1602 hr = IDirect3DDevice9_GetVertexDeclaration(iface, &decl);
1603 if (FAILED(hr))
1605 WARN("Failed to get vertex declaration, %#x\n", hr);
1606 *pFVF = 0;
1607 return hr;
1610 if (decl)
1612 *pFVF = ((IDirect3DVertexDeclaration9Impl *)decl)->convFVF;
1613 IDirect3DVertexDeclaration9_Release(decl);
1615 else
1617 *pFVF = 0;
1620 TRACE("Returning FVF %#x\n", *pFVF);
1622 return hr;
1625 static HRESULT WINAPI IDirect3DDevice9Impl_SetStreamSource(LPDIRECT3DDEVICE9EX iface, UINT StreamNumber, IDirect3DVertexBuffer9* pStreamData, UINT OffsetInBytes, UINT Stride) {
1626 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1627 HRESULT hr;
1628 TRACE("(%p) Relay\n" , This);
1630 wined3d_mutex_lock();
1631 hr = IWineD3DDevice_SetStreamSource(This->WineD3DDevice, StreamNumber,
1632 pStreamData ? ((IDirect3DVertexBuffer9Impl *)pStreamData)->wineD3DVertexBuffer : NULL,
1633 OffsetInBytes, Stride);
1634 wined3d_mutex_unlock();
1636 return hr;
1639 static HRESULT WINAPI IDirect3DDevice9Impl_GetStreamSource(LPDIRECT3DDEVICE9EX iface, UINT StreamNumber, IDirect3DVertexBuffer9 **pStream, UINT* OffsetInBytes, UINT* pStride) {
1640 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1641 IWineD3DBuffer *retStream = NULL;
1642 HRESULT rc = D3D_OK;
1644 TRACE("(%p) Relay\n" , This);
1646 if(pStream == NULL){
1647 return D3DERR_INVALIDCALL;
1650 wined3d_mutex_lock();
1651 rc = IWineD3DDevice_GetStreamSource(This->WineD3DDevice, StreamNumber, &retStream, OffsetInBytes, pStride);
1652 if (rc == D3D_OK && NULL != retStream) {
1653 IWineD3DBuffer_GetParent(retStream, (IUnknown **)pStream);
1654 IWineD3DBuffer_Release(retStream);
1655 }else{
1656 if (rc != D3D_OK){
1657 FIXME("Call to GetStreamSource failed %p %p\n", OffsetInBytes, pStride);
1659 *pStream = NULL;
1661 wined3d_mutex_unlock();
1663 return rc;
1666 static HRESULT WINAPI IDirect3DDevice9Impl_SetStreamSourceFreq(IDirect3DDevice9Ex *iface, UINT StreamNumber,
1667 UINT Divider)
1669 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1670 HRESULT hr;
1671 TRACE("(%p) Relay\n" , This);
1673 wined3d_mutex_lock();
1674 hr = IWineD3DDevice_SetStreamSourceFreq(This->WineD3DDevice, StreamNumber, Divider);
1675 wined3d_mutex_unlock();
1677 return hr;
1680 static HRESULT WINAPI IDirect3DDevice9Impl_GetStreamSourceFreq(LPDIRECT3DDEVICE9EX iface, UINT StreamNumber, UINT* Divider) {
1681 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1682 HRESULT hr;
1683 TRACE("(%p) Relay\n" , This);
1685 wined3d_mutex_lock();
1686 hr = IWineD3DDevice_GetStreamSourceFreq(This->WineD3DDevice, StreamNumber, Divider);
1687 wined3d_mutex_unlock();
1689 return hr;
1692 static HRESULT WINAPI IDirect3DDevice9Impl_SetIndices(LPDIRECT3DDEVICE9EX iface, IDirect3DIndexBuffer9* pIndexData) {
1693 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1694 HRESULT hr;
1695 IDirect3DIndexBuffer9Impl *ib = (IDirect3DIndexBuffer9Impl *) pIndexData;
1696 TRACE("(%p) Relay\n", This);
1698 wined3d_mutex_lock();
1699 hr = IWineD3DDevice_SetIndices(This->WineD3DDevice,
1700 ib ? ib->wineD3DIndexBuffer : NULL,
1701 ib ? ib->format : WINED3DFMT_UNKNOWN);
1702 wined3d_mutex_unlock();
1704 return hr;
1707 static HRESULT WINAPI IDirect3DDevice9Impl_GetIndices(LPDIRECT3DDEVICE9EX iface, IDirect3DIndexBuffer9 **ppIndexData) {
1708 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1709 IWineD3DBuffer *retIndexData = NULL;
1710 HRESULT rc = D3D_OK;
1712 TRACE("(%p) Relay\n", This);
1714 if(ppIndexData == NULL){
1715 return D3DERR_INVALIDCALL;
1718 wined3d_mutex_lock();
1719 rc = IWineD3DDevice_GetIndices(This->WineD3DDevice, &retIndexData);
1720 if (SUCCEEDED(rc) && retIndexData) {
1721 IWineD3DBuffer_GetParent(retIndexData, (IUnknown **)ppIndexData);
1722 IWineD3DBuffer_Release(retIndexData);
1723 } else {
1724 if (FAILED(rc)) FIXME("Call to GetIndices failed\n");
1725 *ppIndexData = NULL;
1727 wined3d_mutex_unlock();
1729 return rc;
1732 static HRESULT WINAPI IDirect3DDevice9Impl_DrawRectPatch(LPDIRECT3DDEVICE9EX iface, UINT Handle, CONST float* pNumSegs, CONST D3DRECTPATCH_INFO* pRectPatchInfo) {
1733 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1734 HRESULT hr;
1735 TRACE("(%p) Relay\n", This);
1737 wined3d_mutex_lock();
1738 hr = IWineD3DDevice_DrawRectPatch(This->WineD3DDevice, Handle, pNumSegs, (CONST WINED3DRECTPATCH_INFO *)pRectPatchInfo);
1739 wined3d_mutex_unlock();
1741 return hr;
1744 static HRESULT WINAPI IDirect3DDevice9Impl_DrawTriPatch(LPDIRECT3DDEVICE9EX iface, UINT Handle, CONST float* pNumSegs, CONST D3DTRIPATCH_INFO* pTriPatchInfo) {
1745 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1746 HRESULT hr;
1747 TRACE("(%p) Relay\n", This);
1749 wined3d_mutex_lock();
1750 hr = IWineD3DDevice_DrawTriPatch(This->WineD3DDevice, Handle, pNumSegs, (CONST WINED3DTRIPATCH_INFO *)pTriPatchInfo);
1751 wined3d_mutex_unlock();
1753 return hr;
1756 static HRESULT WINAPI IDirect3DDevice9Impl_DeletePatch(LPDIRECT3DDEVICE9EX iface, UINT Handle) {
1757 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1758 HRESULT hr;
1759 TRACE("(%p) Relay\n", This);
1761 wined3d_mutex_lock();
1762 hr = IWineD3DDevice_DeletePatch(This->WineD3DDevice, Handle);
1763 wined3d_mutex_unlock();
1765 return hr;
1768 static HRESULT WINAPI IDirect3DDevice9ExImpl_SetConvolutionMonoKernel(LPDIRECT3DDEVICE9EX iface, UINT width, UINT height, float *rows, float *columns) {
1769 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1770 FIXME("(%p)->(%d, %d, %p, %p) Stub!\n", This, width, height, rows, columns);
1771 return WINED3DERR_INVALIDCALL;
1774 static HRESULT WINAPI IDirect3DDevice9ExImpl_ComposeRects(LPDIRECT3DDEVICE9EX iface, IDirect3DSurface9 *pSrc, IDirect3DDevice9 *pDst, IDirect3DVertexBuffer9 *pSrcRectDescs, UINT NumRects, IDirect3DVertexBuffer9 *pDstRectDescs, D3DCOMPOSERECTSOP Operation, int Xoffset, int Yoffset) {
1775 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1776 FIXME("(%p)->(%p, %p, %p, %d, %p, %d, %d, %d) Stub!\n", This, pSrc, pDst, pSrcRectDescs, NumRects, pDstRectDescs, Operation, Xoffset, Yoffset);
1777 return WINED3DERR_INVALIDCALL;
1780 static HRESULT WINAPI IDirect3DDevice9ExImpl_PresentEx(LPDIRECT3DDEVICE9EX iface, CONST RECT *pSourceRect, CONST RECT *pDestRect, HWND hDestWindowOverride, CONST RGNDATA *pDirtyRegion, DWORD dwFlags) {
1781 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1782 FIXME("(%p= -> (%p), %p, %p, %p, 0x%08x) Stub!\n", This, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion, dwFlags);
1783 return WINED3DERR_INVALIDCALL;
1786 static HRESULT WINAPI IDirect3DDevice9ExImpl_GetGPUThreadPriority(LPDIRECT3DDEVICE9EX iface, INT *pPriority) {
1787 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1788 FIXME("(%p)->(%p) Stub!\n", This, pPriority);
1789 return WINED3DERR_INVALIDCALL;
1792 static HRESULT WINAPI IDirect3DDevice9ExImpl_SetGPUThreadPriority(LPDIRECT3DDEVICE9EX iface, INT Priority) {
1793 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1794 FIXME("(%p)->(%d) Stub!\n", This, Priority);
1795 return WINED3DERR_INVALIDCALL;
1798 static HRESULT WINAPI IDirect3DDevice9ExImpl_WaitForVBlank(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain) {
1799 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1800 FIXME("(%p)->(%d) Stub!\n", This, iSwapChain);
1801 return WINED3DERR_INVALIDCALL;
1804 static HRESULT WINAPI IDirect3DDevice9ExImpl_CheckresourceResidency(LPDIRECT3DDEVICE9EX iface, IDirect3DResource9 ** pResourceArray, UINT32 Numresources) {
1805 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1806 FIXME("(%p)->(%p, %d) Stub!\n", This, pResourceArray, Numresources);
1807 return WINED3DERR_INVALIDCALL;
1810 static HRESULT WINAPI IDirect3DDevice9ExImpl_SetMaximumFrameLatency(LPDIRECT3DDEVICE9EX iface, UINT MaxLatency) {
1811 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1812 FIXME("(%p)->(%d) Stub!\n", This, MaxLatency);
1813 return WINED3DERR_INVALIDCALL;
1816 static HRESULT WINAPI IDirect3DDevice9ExImpl_GetMaximumFrameLatency(LPDIRECT3DDEVICE9EX iface, UINT *pMaxLatency) {
1817 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1818 FIXME("(%p)->(%p) Stub!\n", This, pMaxLatency);
1819 *pMaxLatency = 2;
1820 return WINED3DERR_INVALIDCALL;
1823 static HRESULT WINAPI IDirect3DDevice9ExImpl_CheckdeviceState(LPDIRECT3DDEVICE9EX iface, HWND hDestinationWindow) {
1824 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1825 FIXME("(%p)->(%p) Stub!\n", This, hDestinationWindow);
1826 return WINED3DERR_INVALIDCALL;
1829 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) {
1830 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1831 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);
1832 return WINED3DERR_INVALIDCALL;
1835 static HRESULT WINAPI IDirect3DDevice9ExImpl_CreateOffscreenPlainSurfaceEx(LPDIRECT3DDEVICE9EX iface, UINT Width, UINT Height, D3DFORMAT Format, D3DPOOL Pool, IDirect3DSurface9 **ppSurface, HANDLE *pSharedHandle, DWORD Usage) {
1836 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1837 FIXME("(%p)->(%d, %d, %d, %d, %p, %p, 0x%08x) Stub!\n", This, Width, Height, Format, Pool, ppSurface, pSharedHandle, Usage);
1838 return WINED3DERR_INVALIDCALL;
1841 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) {
1842 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1843 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);
1844 return WINED3DERR_INVALIDCALL;
1847 static HRESULT WINAPI IDirect3DDevice9ExImpl_ResetEx(LPDIRECT3DDEVICE9EX iface, D3DPRESENT_PARAMETERS *pPresentationParameters, D3DDISPLAYMODEEX *pFullscreenDisplayMode) {
1848 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1849 FIXME("(%p)->(%p) Stub!\n", This, pPresentationParameters);
1850 return WINED3DERR_INVALIDCALL;
1853 static HRESULT WINAPI IDirect3DDevice9ExImpl_GetDisplayModeEx(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain, D3DDISPLAYMODEEX *pMode, D3DDISPLAYROTATION *pRotation) {
1854 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1855 FIXME("(%p)->(%d, %p, %p) Stub!\n", This, iSwapChain, pMode, pRotation);
1856 return WINED3DERR_INVALIDCALL;
1859 const IDirect3DDevice9ExVtbl Direct3DDevice9_Vtbl =
1861 /* IUnknown */
1862 IDirect3DDevice9Impl_QueryInterface,
1863 IDirect3DDevice9Impl_AddRef,
1864 IDirect3DDevice9Impl_Release,
1865 /* IDirect3DDevice9 */
1866 IDirect3DDevice9Impl_TestCooperativeLevel,
1867 IDirect3DDevice9Impl_GetAvailableTextureMem,
1868 IDirect3DDevice9Impl_EvictManagedResources,
1869 IDirect3DDevice9Impl_GetDirect3D,
1870 IDirect3DDevice9Impl_GetDeviceCaps,
1871 IDirect3DDevice9Impl_GetDisplayMode,
1872 IDirect3DDevice9Impl_GetCreationParameters,
1873 IDirect3DDevice9Impl_SetCursorProperties,
1874 IDirect3DDevice9Impl_SetCursorPosition,
1875 IDirect3DDevice9Impl_ShowCursor,
1876 IDirect3DDevice9Impl_CreateAdditionalSwapChain,
1877 IDirect3DDevice9Impl_GetSwapChain,
1878 IDirect3DDevice9Impl_GetNumberOfSwapChains,
1879 IDirect3DDevice9Impl_Reset,
1880 IDirect3DDevice9Impl_Present,
1881 IDirect3DDevice9Impl_GetBackBuffer,
1882 IDirect3DDevice9Impl_GetRasterStatus,
1883 IDirect3DDevice9Impl_SetDialogBoxMode,
1884 IDirect3DDevice9Impl_SetGammaRamp,
1885 IDirect3DDevice9Impl_GetGammaRamp,
1886 IDirect3DDevice9Impl_CreateTexture,
1887 IDirect3DDevice9Impl_CreateVolumeTexture,
1888 IDirect3DDevice9Impl_CreateCubeTexture,
1889 IDirect3DDevice9Impl_CreateVertexBuffer,
1890 IDirect3DDevice9Impl_CreateIndexBuffer,
1891 IDirect3DDevice9Impl_CreateRenderTarget,
1892 IDirect3DDevice9Impl_CreateDepthStencilSurface,
1893 IDirect3DDevice9Impl_UpdateSurface,
1894 IDirect3DDevice9Impl_UpdateTexture,
1895 IDirect3DDevice9Impl_GetRenderTargetData,
1896 IDirect3DDevice9Impl_GetFrontBufferData,
1897 IDirect3DDevice9Impl_StretchRect,
1898 IDirect3DDevice9Impl_ColorFill,
1899 IDirect3DDevice9Impl_CreateOffscreenPlainSurface,
1900 IDirect3DDevice9Impl_SetRenderTarget,
1901 IDirect3DDevice9Impl_GetRenderTarget,
1902 IDirect3DDevice9Impl_SetDepthStencilSurface,
1903 IDirect3DDevice9Impl_GetDepthStencilSurface,
1904 IDirect3DDevice9Impl_BeginScene,
1905 IDirect3DDevice9Impl_EndScene,
1906 IDirect3DDevice9Impl_Clear,
1907 IDirect3DDevice9Impl_SetTransform,
1908 IDirect3DDevice9Impl_GetTransform,
1909 IDirect3DDevice9Impl_MultiplyTransform,
1910 IDirect3DDevice9Impl_SetViewport,
1911 IDirect3DDevice9Impl_GetViewport,
1912 IDirect3DDevice9Impl_SetMaterial,
1913 IDirect3DDevice9Impl_GetMaterial,
1914 IDirect3DDevice9Impl_SetLight,
1915 IDirect3DDevice9Impl_GetLight,
1916 IDirect3DDevice9Impl_LightEnable,
1917 IDirect3DDevice9Impl_GetLightEnable,
1918 IDirect3DDevice9Impl_SetClipPlane,
1919 IDirect3DDevice9Impl_GetClipPlane,
1920 IDirect3DDevice9Impl_SetRenderState,
1921 IDirect3DDevice9Impl_GetRenderState,
1922 IDirect3DDevice9Impl_CreateStateBlock,
1923 IDirect3DDevice9Impl_BeginStateBlock,
1924 IDirect3DDevice9Impl_EndStateBlock,
1925 IDirect3DDevice9Impl_SetClipStatus,
1926 IDirect3DDevice9Impl_GetClipStatus,
1927 IDirect3DDevice9Impl_GetTexture,
1928 IDirect3DDevice9Impl_SetTexture,
1929 IDirect3DDevice9Impl_GetTextureStageState,
1930 IDirect3DDevice9Impl_SetTextureStageState,
1931 IDirect3DDevice9Impl_GetSamplerState,
1932 IDirect3DDevice9Impl_SetSamplerState,
1933 IDirect3DDevice9Impl_ValidateDevice,
1934 IDirect3DDevice9Impl_SetPaletteEntries,
1935 IDirect3DDevice9Impl_GetPaletteEntries,
1936 IDirect3DDevice9Impl_SetCurrentTexturePalette,
1937 IDirect3DDevice9Impl_GetCurrentTexturePalette,
1938 IDirect3DDevice9Impl_SetScissorRect,
1939 IDirect3DDevice9Impl_GetScissorRect,
1940 IDirect3DDevice9Impl_SetSoftwareVertexProcessing,
1941 IDirect3DDevice9Impl_GetSoftwareVertexProcessing,
1942 IDirect3DDevice9Impl_SetNPatchMode,
1943 IDirect3DDevice9Impl_GetNPatchMode,
1944 IDirect3DDevice9Impl_DrawPrimitive,
1945 IDirect3DDevice9Impl_DrawIndexedPrimitive,
1946 IDirect3DDevice9Impl_DrawPrimitiveUP,
1947 IDirect3DDevice9Impl_DrawIndexedPrimitiveUP,
1948 IDirect3DDevice9Impl_ProcessVertices,
1949 IDirect3DDevice9Impl_CreateVertexDeclaration,
1950 IDirect3DDevice9Impl_SetVertexDeclaration,
1951 IDirect3DDevice9Impl_GetVertexDeclaration,
1952 IDirect3DDevice9Impl_SetFVF,
1953 IDirect3DDevice9Impl_GetFVF,
1954 IDirect3DDevice9Impl_CreateVertexShader,
1955 IDirect3DDevice9Impl_SetVertexShader,
1956 IDirect3DDevice9Impl_GetVertexShader,
1957 IDirect3DDevice9Impl_SetVertexShaderConstantF,
1958 IDirect3DDevice9Impl_GetVertexShaderConstantF,
1959 IDirect3DDevice9Impl_SetVertexShaderConstantI,
1960 IDirect3DDevice9Impl_GetVertexShaderConstantI,
1961 IDirect3DDevice9Impl_SetVertexShaderConstantB,
1962 IDirect3DDevice9Impl_GetVertexShaderConstantB,
1963 IDirect3DDevice9Impl_SetStreamSource,
1964 IDirect3DDevice9Impl_GetStreamSource,
1965 IDirect3DDevice9Impl_SetStreamSourceFreq,
1966 IDirect3DDevice9Impl_GetStreamSourceFreq,
1967 IDirect3DDevice9Impl_SetIndices,
1968 IDirect3DDevice9Impl_GetIndices,
1969 IDirect3DDevice9Impl_CreatePixelShader,
1970 IDirect3DDevice9Impl_SetPixelShader,
1971 IDirect3DDevice9Impl_GetPixelShader,
1972 IDirect3DDevice9Impl_SetPixelShaderConstantF,
1973 IDirect3DDevice9Impl_GetPixelShaderConstantF,
1974 IDirect3DDevice9Impl_SetPixelShaderConstantI,
1975 IDirect3DDevice9Impl_GetPixelShaderConstantI,
1976 IDirect3DDevice9Impl_SetPixelShaderConstantB,
1977 IDirect3DDevice9Impl_GetPixelShaderConstantB,
1978 IDirect3DDevice9Impl_DrawRectPatch,
1979 IDirect3DDevice9Impl_DrawTriPatch,
1980 IDirect3DDevice9Impl_DeletePatch,
1981 IDirect3DDevice9Impl_CreateQuery,
1982 /* IDirect3DDevice9Ex */
1983 IDirect3DDevice9ExImpl_SetConvolutionMonoKernel,
1984 IDirect3DDevice9ExImpl_ComposeRects,
1985 IDirect3DDevice9ExImpl_PresentEx,
1986 IDirect3DDevice9ExImpl_GetGPUThreadPriority,
1987 IDirect3DDevice9ExImpl_SetGPUThreadPriority,
1988 IDirect3DDevice9ExImpl_WaitForVBlank,
1989 IDirect3DDevice9ExImpl_CheckresourceResidency,
1990 IDirect3DDevice9ExImpl_SetMaximumFrameLatency,
1991 IDirect3DDevice9ExImpl_GetMaximumFrameLatency,
1992 IDirect3DDevice9ExImpl_CheckdeviceState,
1993 IDirect3DDevice9ExImpl_CreateRenderTargetEx,
1994 IDirect3DDevice9ExImpl_CreateOffscreenPlainSurfaceEx,
1995 IDirect3DDevice9ExImpl_CreateDepthStencilSurfaceEx,
1996 IDirect3DDevice9ExImpl_ResetEx,
1997 IDirect3DDevice9ExImpl_GetDisplayModeEx
2000 /* IWineD3DDeviceParent IUnknown methods */
2002 static inline struct IDirect3DDevice9Impl *device_from_device_parent(IWineD3DDeviceParent *iface)
2004 return (struct IDirect3DDevice9Impl *)((char*)iface
2005 - FIELD_OFFSET(struct IDirect3DDevice9Impl, device_parent_vtbl));
2008 static HRESULT STDMETHODCALLTYPE device_parent_QueryInterface(IWineD3DDeviceParent *iface, REFIID riid, void **object)
2010 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
2011 return IDirect3DDevice9Impl_QueryInterface((IDirect3DDevice9Ex *)This, riid, object);
2014 static ULONG STDMETHODCALLTYPE device_parent_AddRef(IWineD3DDeviceParent *iface)
2016 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
2017 return IDirect3DDevice9Impl_AddRef((IDirect3DDevice9Ex *)This);
2020 static ULONG STDMETHODCALLTYPE device_parent_Release(IWineD3DDeviceParent *iface)
2022 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
2023 return IDirect3DDevice9Impl_Release((IDirect3DDevice9Ex *)This);
2026 /* IWineD3DDeviceParent methods */
2028 static void STDMETHODCALLTYPE device_parent_WineD3DDeviceCreated(IWineD3DDeviceParent *iface, IWineD3DDevice *device)
2030 TRACE("iface %p, device %p\n", iface, device);
2033 static HRESULT STDMETHODCALLTYPE device_parent_CreateSurface(IWineD3DDeviceParent *iface,
2034 IUnknown *superior, UINT width, UINT height, WINED3DFORMAT format, DWORD usage,
2035 WINED3DPOOL pool, UINT level, WINED3DCUBEMAP_FACES face, IWineD3DSurface **surface)
2037 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
2038 IDirect3DSurface9Impl *d3d_surface;
2039 BOOL lockable = TRUE;
2040 HRESULT hr;
2042 TRACE("iface %p, superior %p, width %u, height %u, format %#x, usage %#x,\n"
2043 "\tpool %#x, level %u, face %u, surface %p\n",
2044 iface, superior, width, height, format, usage, pool, level, face, surface);
2046 if (pool == WINED3DPOOL_DEFAULT && !(usage & D3DUSAGE_DYNAMIC))
2047 lockable = FALSE;
2049 hr = IDirect3DDevice9Impl_CreateSurface((IDirect3DDevice9Ex *)This, width, height,
2050 d3dformat_from_wined3dformat(format), lockable, FALSE /* Discard */, level,
2051 (IDirect3DSurface9 **)&d3d_surface, usage, pool, D3DMULTISAMPLE_NONE, 0 /* MultisampleQuality */);
2052 if (FAILED(hr))
2054 ERR("(%p) CreateSurface failed, returning %#x\n", iface, hr);
2055 return hr;
2058 *surface = d3d_surface->wineD3DSurface;
2059 IWineD3DSurface_AddRef(*surface);
2061 d3d_surface->container = superior;
2062 IDirect3DDevice9Ex_Release(d3d_surface->parentDevice);
2063 d3d_surface->parentDevice = NULL;
2065 IDirect3DSurface9_Release((IDirect3DSurface9 *)d3d_surface);
2066 d3d_surface->forwardReference = superior;
2068 return hr;
2071 static HRESULT STDMETHODCALLTYPE device_parent_CreateRenderTarget(IWineD3DDeviceParent *iface,
2072 IUnknown *superior, UINT width, UINT height, WINED3DFORMAT format, WINED3DMULTISAMPLE_TYPE multisample_type,
2073 DWORD multisample_quality, BOOL lockable, IWineD3DSurface **surface)
2075 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
2076 IDirect3DSurface9Impl *d3d_surface;
2077 HRESULT hr;
2079 TRACE("iface %p, superior %p, width %u, height %u, format %#x, multisample_type %#x,\n"
2080 "\tmultisample_quality %u, lockable %u, surface %p\n",
2081 iface, superior, width, height, format, multisample_type, multisample_quality, lockable, surface);
2083 hr = IDirect3DDevice9Impl_CreateRenderTarget((IDirect3DDevice9Ex *)This, width, height,
2084 d3dformat_from_wined3dformat(format), multisample_type, multisample_quality, lockable,
2085 (IDirect3DSurface9 **)&d3d_surface, NULL);
2086 if (FAILED(hr))
2088 ERR("(%p) CreateRenderTarget failed, returning %#x\n", iface, hr);
2089 return hr;
2092 *surface = d3d_surface->wineD3DSurface;
2093 IWineD3DSurface_AddRef(*surface);
2095 d3d_surface->container = superior;
2096 /* Implicit surfaces are created with an refcount of 0 */
2097 IDirect3DSurface9_Release((IDirect3DSurface9 *)d3d_surface);
2099 return hr;
2102 static HRESULT STDMETHODCALLTYPE device_parent_CreateDepthStencilSurface(IWineD3DDeviceParent *iface,
2103 IUnknown *superior, UINT width, UINT height, WINED3DFORMAT format, WINED3DMULTISAMPLE_TYPE multisample_type,
2104 DWORD multisample_quality, BOOL discard, IWineD3DSurface **surface)
2106 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
2107 IDirect3DSurface9Impl *d3d_surface;
2108 HRESULT hr;
2110 TRACE("iface %p, superior %p, width %u, height %u, format %#x, multisample_type %#x,\n"
2111 "\tmultisample_quality %u, discard %u, surface %p\n",
2112 iface, superior, width, height, format, multisample_type, multisample_quality, discard, surface);
2114 hr = IDirect3DDevice9Impl_CreateDepthStencilSurface((IDirect3DDevice9Ex *)This, width, height,
2115 d3dformat_from_wined3dformat(format), multisample_type, multisample_quality, discard,
2116 (IDirect3DSurface9 **)&d3d_surface, NULL);
2117 if (FAILED(hr))
2119 ERR("(%p) CreateDepthStencilSurface failed, returning %#x\n", iface, hr);
2120 return hr;
2123 *surface = d3d_surface->wineD3DSurface;
2124 IWineD3DSurface_AddRef(*surface);
2125 d3d_surface->container = (IUnknown *)This;
2126 /* Implicit surfaces are created with an refcount of 0 */
2127 IDirect3DSurface9_Release((IDirect3DSurface9 *)d3d_surface);
2129 return hr;
2132 static HRESULT STDMETHODCALLTYPE device_parent_CreateVolume(IWineD3DDeviceParent *iface,
2133 IUnknown *superior, UINT width, UINT height, UINT depth, WINED3DFORMAT format,
2134 WINED3DPOOL pool, DWORD usage, IWineD3DVolume **volume)
2136 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
2137 IDirect3DVolume9Impl *object;
2138 HRESULT hr;
2140 TRACE("iface %p, superior %p, width %u, height %u, depth %u, format %#x, pool %#x, usage %#x, volume %p\n",
2141 iface, superior, width, height, depth, format, pool, usage, volume);
2143 /* Allocate the storage for the device */
2144 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2145 if (!object)
2147 FIXME("Allocation of memory failed\n");
2148 *volume = NULL;
2149 return D3DERR_OUTOFVIDEOMEMORY;
2152 hr = volume_init(object, This, width, height, depth, usage, format, pool);
2153 if (FAILED(hr))
2155 WARN("Failed to initialize volume, hr %#x.\n", hr);
2156 HeapFree(GetProcessHeap(), 0, object);
2157 return hr;
2160 *volume = object->wineD3DVolume;
2161 object->container = superior;
2162 object->forwardReference = superior;
2164 TRACE("(%p) Created volume %p\n", iface, object);
2166 return hr;
2169 static HRESULT STDMETHODCALLTYPE device_parent_CreateSwapChain(IWineD3DDeviceParent *iface,
2170 WINED3DPRESENT_PARAMETERS *present_parameters, IWineD3DSwapChain **swapchain)
2172 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
2173 IDirect3DSwapChain9Impl *d3d_swapchain;
2174 D3DPRESENT_PARAMETERS local_parameters;
2175 HRESULT hr;
2177 TRACE("iface %p, present_parameters %p, swapchain %p\n", iface, present_parameters, swapchain);
2179 /* Copy the presentation parameters */
2180 local_parameters.BackBufferWidth = present_parameters->BackBufferWidth;
2181 local_parameters.BackBufferHeight = present_parameters->BackBufferHeight;
2182 local_parameters.BackBufferFormat = d3dformat_from_wined3dformat(present_parameters->BackBufferFormat);
2183 local_parameters.BackBufferCount = present_parameters->BackBufferCount;
2184 local_parameters.MultiSampleType = present_parameters->MultiSampleType;
2185 local_parameters.MultiSampleQuality = present_parameters->MultiSampleQuality;
2186 local_parameters.SwapEffect = present_parameters->SwapEffect;
2187 local_parameters.hDeviceWindow = present_parameters->hDeviceWindow;
2188 local_parameters.Windowed = present_parameters->Windowed;
2189 local_parameters.EnableAutoDepthStencil = present_parameters->EnableAutoDepthStencil;
2190 local_parameters.AutoDepthStencilFormat = d3dformat_from_wined3dformat(present_parameters->AutoDepthStencilFormat);
2191 local_parameters.Flags = present_parameters->Flags;
2192 local_parameters.FullScreen_RefreshRateInHz = present_parameters->FullScreen_RefreshRateInHz;
2193 local_parameters.PresentationInterval = present_parameters->PresentationInterval;
2195 hr = IDirect3DDevice9Impl_CreateAdditionalSwapChain((IDirect3DDevice9Ex *)This,
2196 &local_parameters, (IDirect3DSwapChain9 **)&d3d_swapchain);
2197 if (FAILED(hr))
2199 ERR("(%p) CreateAdditionalSwapChain failed, returning %#x\n", iface, hr);
2200 *swapchain = NULL;
2201 return hr;
2204 *swapchain = d3d_swapchain->wineD3DSwapChain;
2205 d3d_swapchain->isImplicit = TRUE;
2206 /* Implicit swap chains are created with an refcount of 0 */
2207 IDirect3DSwapChain9_Release((IDirect3DSwapChain9 *)d3d_swapchain);
2209 /* Copy back the presentation parameters */
2210 present_parameters->BackBufferWidth = local_parameters.BackBufferWidth;
2211 present_parameters->BackBufferHeight = local_parameters.BackBufferHeight;
2212 present_parameters->BackBufferFormat = wined3dformat_from_d3dformat(local_parameters.BackBufferFormat);
2213 present_parameters->BackBufferCount = local_parameters.BackBufferCount;
2214 present_parameters->MultiSampleType = local_parameters.MultiSampleType;
2215 present_parameters->MultiSampleQuality = local_parameters.MultiSampleQuality;
2216 present_parameters->SwapEffect = local_parameters.SwapEffect;
2217 present_parameters->hDeviceWindow = local_parameters.hDeviceWindow;
2218 present_parameters->Windowed = local_parameters.Windowed;
2219 present_parameters->EnableAutoDepthStencil = local_parameters.EnableAutoDepthStencil;
2220 present_parameters->AutoDepthStencilFormat = wined3dformat_from_d3dformat(local_parameters.AutoDepthStencilFormat);
2221 present_parameters->Flags = local_parameters.Flags;
2222 present_parameters->FullScreen_RefreshRateInHz = local_parameters.FullScreen_RefreshRateInHz;
2223 present_parameters->PresentationInterval = local_parameters.PresentationInterval;
2225 return hr;
2228 const IWineD3DDeviceParentVtbl d3d9_wined3d_device_parent_vtbl =
2230 /* IUnknown methods */
2231 device_parent_QueryInterface,
2232 device_parent_AddRef,
2233 device_parent_Release,
2234 /* IWineD3DDeviceParent methods */
2235 device_parent_WineD3DDeviceCreated,
2236 device_parent_CreateSurface,
2237 device_parent_CreateRenderTarget,
2238 device_parent_CreateDepthStencilSurface,
2239 device_parent_CreateVolume,
2240 device_parent_CreateSwapChain,