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
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;
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;
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;
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;
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;
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;
179 FIXME("Unhandled primitive type %#x\n", primitive_type);
184 /* IDirect3D IUnknown parts follow: */
185 static HRESULT WINAPI IDirect3DDevice9Impl_QueryInterface(LPDIRECT3DDEVICE9EX iface, REFIID riid, LPVOID* ppobj) {
186 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
188 IDirect3D9Impl *d3dimpl;
190 if (IsEqualGUID(riid, &IID_IUnknown)
191 || IsEqualGUID(riid, &IID_IDirect3DDevice9)) {
192 IDirect3DDevice9Ex_AddRef(iface);
194 TRACE("Returning IDirect3DDevice9 interface at %p\n", *ppobj);
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) {
205 IDirect3DDevice9Ex_AddRef((IDirect3DDevice9Ex *) *ppobj);
206 IDirect3D9_Release(d3d);
207 TRACE("Returning IDirect3DDevice9Ex interface at %p\n", *ppobj);
210 WARN("IDirect3D9 instance wasn't created with CreateDirect3D9Ex, returning E_NOINTERFACE\n");
211 IDirect3D9_Release(d3d);
213 return E_NOINTERFACE;
217 if (IsEqualGUID(riid, &IID_IWineD3DDeviceParent))
219 IUnknown_AddRef((IUnknown *)&This->device_parent_vtbl);
220 *ppobj = &This->device_parent_vtbl;
224 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
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);
238 static ULONG WINAPI IDirect3DDevice9Impl_Release(LPDIRECT3DDEVICE9EX iface) {
239 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
242 if (This->inDestruction) return 0;
243 ref = InterlockedDecrement(&This->ref);
245 TRACE("(%p) : ReleaseRef to %d\n", This, ref);
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
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);
269 /* IDirect3DDevice Interface follow: */
270 static HRESULT WINAPI IDirect3DDevice9Impl_TestCooperativeLevel(LPDIRECT3DDEVICE9EX iface) {
271 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
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;
287 static UINT WINAPI IDirect3DDevice9Impl_GetAvailableTextureMem(LPDIRECT3DDEVICE9EX iface) {
288 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
290 TRACE("(%p) Relay\n", This);
292 wined3d_mutex_lock();
293 hr = IWineD3DDevice_GetAvailableTextureMem(This->WineD3DDevice);
294 wined3d_mutex_unlock();
299 static HRESULT WINAPI IDirect3DDevice9Impl_EvictManagedResources(LPDIRECT3DDEVICE9EX iface) {
300 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
302 TRACE("(%p) : Relay\n", This);
304 wined3d_mutex_lock();
305 hr = IWineD3DDevice_EvictManagedResources(This->WineD3DDevice);
306 wined3d_mutex_unlock();
311 static HRESULT WINAPI IDirect3DDevice9Impl_GetDirect3D(LPDIRECT3DDEVICE9EX iface, IDirect3D9** ppD3D9) {
312 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
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);
329 FIXME("Call to IWineD3DDevice_GetDirect3D failed\n");
332 TRACE("(%p) returning %p\n", This, *ppD3D9);
333 wined3d_mutex_unlock();
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);
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;
366 TRACE("Returning %p %p\n", This, pCaps);
370 static HRESULT WINAPI IDirect3DDevice9Impl_GetDisplayMode(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain, D3DDISPLAYMODE* pMode) {
371 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
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);
384 static HRESULT WINAPI IDirect3DDevice9Impl_GetCreationParameters(LPDIRECT3DDEVICE9EX iface, D3DDEVICE_CREATION_PARAMETERS *pParameters) {
385 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
387 TRACE("(%p) Relay\n", This);
389 wined3d_mutex_lock();
390 hr = IWineD3DDevice_GetCreationParameters(This->WineD3DDevice, (WINED3DDEVICE_CREATION_PARAMETERS *) pParameters);
391 wined3d_mutex_unlock();
396 static HRESULT WINAPI IDirect3DDevice9Impl_SetCursorProperties(LPDIRECT3DDEVICE9EX iface, UINT XHotSpot, UINT YHotSpot, IDirect3DSurface9* pCursorBitmap) {
397 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
398 IDirect3DSurface9Impl *pSurface = (IDirect3DSurface9Impl*)pCursorBitmap;
401 TRACE("(%p) Relay\n", This);
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();
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;
426 TRACE("(%p) Relay\n", This);
428 wined3d_mutex_lock();
429 ret = IWineD3DDevice_ShowCursor(This->WineD3DDevice, bShow);
430 wined3d_mutex_unlock();
435 static HRESULT WINAPI reset_enum_callback(IWineD3DResource *resource, void *data) {
436 BOOL *resources_ok = data;
437 D3DRESOURCETYPE type;
439 WINED3DSURFACE_DESC surface_desc;
440 WINED3DVOLUME_DESC volume_desc;
441 D3DINDEXBUFFER_DESC index_desc;
442 D3DVERTEXBUFFER_DESC vertex_desc;
444 IDirect3DResource9 *parent;
446 IWineD3DResource_GetParent(resource, (IUnknown **) &parent);
447 type = IDirect3DResource9_GetType(parent);
449 case D3DRTYPE_SURFACE:
450 IWineD3DSurface_GetDesc((IWineD3DSurface *) resource, &surface_desc);
451 pool = surface_desc.pool;
454 case D3DRTYPE_VOLUME:
455 IWineD3DVolume_GetDesc((IWineD3DVolume *) resource, &volume_desc);
456 pool = volume_desc.Pool;
459 case D3DRTYPE_INDEXBUFFER:
460 IDirect3DIndexBuffer9_GetDesc((IDirect3DIndexBuffer9 *) parent, &index_desc);
461 pool = index_desc.Pool;
464 case D3DRTYPE_VERTEXBUFFER:
465 IDirect3DVertexBuffer9_GetDesc((IDirect3DVertexBuffer9 *)parent, &vertex_desc);
466 pool = vertex_desc.Pool;
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
473 pool = WINED3DPOOL_SCRATCH; /* a harmless pool */
477 if(pool == WINED3DPOOL_DEFAULT) {
478 if(IUnknown_Release(parent) == 0) {
479 TRACE("Parent %p is an implicit resource with ref 0\n", parent);
481 WARN("Resource %p(wineD3D %p) with pool D3DPOOL_DEFAULT blocks the Reset call\n", parent, resource);
483 *resources_ok = FALSE;
486 IUnknown_Release(parent);
488 IWineD3DResource_Release(resource);
493 static HRESULT WINAPI IDirect3DDevice9Impl_Reset(LPDIRECT3DDEVICE9EX iface, D3DPRESENT_PARAMETERS* pPresentationParameters) {
494 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
495 WINED3DPRESENT_PARAMETERS localParameters;
497 BOOL resources_ok = TRUE;
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);
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);
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;
563 This->notreset = FALSE;
566 wined3d_mutex_unlock();
571 static HRESULT WINAPI IDirect3DDevice9Impl_Present(LPDIRECT3DDEVICE9EX iface, CONST RECT* pSourceRect,CONST RECT* pDestRect,HWND hDestWindowOverride,CONST RGNDATA*
573 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
575 TRACE("(%p) Relay\n", This);
577 wined3d_mutex_lock();
578 hr = IWineD3DDevice_Present(This->WineD3DDevice, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
579 wined3d_mutex_unlock();
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;
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();
601 static HRESULT WINAPI IDirect3DDevice9Impl_GetRasterStatus(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain, D3DRASTER_STATUS* pRasterStatus) {
602 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
604 TRACE("(%p) Relay\n", This);
606 wined3d_mutex_lock();
607 hr = IWineD3DDevice_GetRasterStatus(This->WineD3DDevice, iSwapChain, (WINED3DRASTER_STATUS *) pRasterStatus);
608 wined3d_mutex_unlock();
613 static HRESULT WINAPI IDirect3DDevice9Impl_SetDialogBoxMode(LPDIRECT3DDEVICE9EX iface, BOOL bEnableDialogs) {
614 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
616 TRACE("(%p) Relay\n", This);
618 wined3d_mutex_lock();
619 hr = IWineD3DDevice_SetDialogBoxMode(This->WineD3DDevice, bEnableDialogs);
620 wined3d_mutex_unlock();
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 WINAPI IDirect3DDevice9Impl_CreateVolumeTexture(IDirect3DDevice9Ex *iface,
648 UINT width, UINT height, UINT depth, UINT levels, DWORD usage, D3DFORMAT format,
649 D3DPOOL pool, IDirect3DVolumeTexture9 **texture, HANDLE *shared_handle)
651 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
652 IDirect3DVolumeTexture9Impl *object;
655 TRACE("iface %p, width %u, height %u, depth %u, levels %u\n",
656 iface, width, height, depth, levels);
657 TRACE("usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n",
658 usage, format, pool, texture, shared_handle);
660 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
663 ERR("Failed to allocate volume texture memory.\n");
664 return D3DERR_OUTOFVIDEOMEMORY;
667 hr = volumetexture_init(object, This, width, height, depth, levels, usage, format, pool);
670 WARN("Failed to initialize volume texture, hr %#x.\n", hr);
671 HeapFree(GetProcessHeap(), 0, object);
675 TRACE("Created volume texture %p.\n", object);
676 *texture = (IDirect3DVolumeTexture9 *)object;
681 static HRESULT IDirect3DDevice9Impl_CreateSurface(LPDIRECT3DDEVICE9EX iface, UINT Width, UINT Height,
682 D3DFORMAT Format, BOOL Lockable, BOOL Discard, UINT Level, IDirect3DSurface9 **ppSurface,
683 UINT Usage, D3DPOOL Pool, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality)
685 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
686 IDirect3DSurface9Impl *object;
689 TRACE("(%p) : w(%d) h(%d) fmt(%d) surf@%p\n", This, Width, Height, Format, *ppSurface);
691 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DSurface9Impl));
694 FIXME("Failed to allocate surface memory.\n");
695 return D3DERR_OUTOFVIDEOMEMORY;
698 hr = surface_init(object, This, Width, Height, Format, Lockable, Discard,
699 Level, Usage, Pool, MultiSample, MultisampleQuality);
702 WARN("Failed to initialize surface, hr %#x.\n", hr);
703 HeapFree(GetProcessHeap(), 0, object);
707 TRACE("Created surface %p.\n", object);
708 *ppSurface = (IDirect3DSurface9 *)object;
713 static HRESULT WINAPI IDirect3DDevice9Impl_CreateRenderTarget(IDirect3DDevice9Ex *iface, UINT Width, UINT Height,
714 D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality, BOOL Lockable,
715 IDirect3DSurface9 **ppSurface, HANDLE *pSharedHandle)
720 hr = IDirect3DDevice9Impl_CreateSurface(iface, Width, Height, Format, Lockable, FALSE /* Discard */,
721 0 /* Level */, ppSurface, D3DUSAGE_RENDERTARGET, D3DPOOL_DEFAULT, MultiSample, MultisampleQuality);
726 static HRESULT WINAPI IDirect3DDevice9Impl_CreateDepthStencilSurface(LPDIRECT3DDEVICE9EX iface, UINT Width, UINT Height,
727 D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample,
728 DWORD MultisampleQuality, BOOL Discard,
729 IDirect3DSurface9 **ppSurface, HANDLE* pSharedHandle) {
733 hr = IDirect3DDevice9Impl_CreateSurface(iface, Width, Height, Format, TRUE /* Lockable */, Discard,
734 0 /* Level */, ppSurface, D3DUSAGE_DEPTHSTENCIL, D3DPOOL_DEFAULT, MultiSample, MultisampleQuality);
740 static HRESULT WINAPI IDirect3DDevice9Impl_UpdateSurface(LPDIRECT3DDEVICE9EX iface, IDirect3DSurface9* pSourceSurface, CONST RECT* pSourceRect, IDirect3DSurface9* pDestinationSurface, CONST POINT* pDestPoint) {
741 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
743 TRACE("(%p) Relay\n" , This);
745 wined3d_mutex_lock();
746 hr = IWineD3DDevice_UpdateSurface(This->WineD3DDevice, ((IDirect3DSurface9Impl *)pSourceSurface)->wineD3DSurface, pSourceRect, ((IDirect3DSurface9Impl *)pDestinationSurface)->wineD3DSurface, pDestPoint);
747 wined3d_mutex_unlock();
752 static HRESULT WINAPI IDirect3DDevice9Impl_UpdateTexture(LPDIRECT3DDEVICE9EX iface, IDirect3DBaseTexture9* pSourceTexture, IDirect3DBaseTexture9* pDestinationTexture) {
753 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
755 TRACE("(%p) Relay\n" , This);
757 wined3d_mutex_lock();
758 hr = IWineD3DDevice_UpdateTexture(This->WineD3DDevice, ((IDirect3DBaseTexture9Impl *)pSourceTexture)->wineD3DBaseTexture, ((IDirect3DBaseTexture9Impl *)pDestinationTexture)->wineD3DBaseTexture);
759 wined3d_mutex_unlock();
764 static HRESULT WINAPI IDirect3DDevice9Impl_GetRenderTargetData(LPDIRECT3DDEVICE9EX iface, IDirect3DSurface9* pRenderTarget, IDirect3DSurface9* pDestSurface) {
765 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
766 IDirect3DSurface9Impl *renderTarget = (IDirect3DSurface9Impl *)pRenderTarget;
767 IDirect3DSurface9Impl *destSurface = (IDirect3DSurface9Impl *)pDestSurface;
769 TRACE("(%p)->(%p,%p)\n" , This, renderTarget, destSurface);
771 wined3d_mutex_lock();
772 hr = IWineD3DSurface_BltFast(destSurface->wineD3DSurface, 0, 0, renderTarget->wineD3DSurface, NULL, WINEDDBLTFAST_NOCOLORKEY);
773 wined3d_mutex_unlock();
778 static HRESULT WINAPI IDirect3DDevice9Impl_GetFrontBufferData(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain, IDirect3DSurface9* pDestSurface) {
779 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
780 IDirect3DSurface9Impl *destSurface = (IDirect3DSurface9Impl *)pDestSurface;
782 TRACE("(%p) Relay\n" , This);
784 wined3d_mutex_lock();
785 hr = IWineD3DDevice_GetFrontBufferData(This->WineD3DDevice, iSwapChain, destSurface->wineD3DSurface);
786 wined3d_mutex_unlock();
791 static HRESULT WINAPI IDirect3DDevice9Impl_StretchRect(LPDIRECT3DDEVICE9EX iface, IDirect3DSurface9* pSourceSurface, CONST RECT* pSourceRect, IDirect3DSurface9* pDestSurface, CONST RECT* pDestRect, D3DTEXTUREFILTERTYPE Filter) {
792 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
793 IDirect3DSurface9Impl *src = (IDirect3DSurface9Impl *) pSourceSurface;
794 IDirect3DSurface9Impl *dst = (IDirect3DSurface9Impl *) pDestSurface;
797 TRACE("(%p)->(%p,%p,%p,%p,%d)\n" , This, src, pSourceRect, dst, pDestRect, Filter);
799 wined3d_mutex_lock();
800 hr = IWineD3DSurface_Blt(dst->wineD3DSurface, pDestRect, src->wineD3DSurface, pSourceRect, 0, NULL, Filter);
801 wined3d_mutex_unlock();
806 static HRESULT WINAPI IDirect3DDevice9Impl_ColorFill(LPDIRECT3DDEVICE9EX iface, IDirect3DSurface9* pSurface, CONST RECT* pRect, D3DCOLOR color) {
807 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
808 IDirect3DSurface9Impl *surface = (IDirect3DSurface9Impl *)pSurface;
810 WINED3DRESOURCETYPE restype;
812 WINED3DSURFACE_DESC desc;
814 TRACE("(%p) Relay\n" , This);
816 wined3d_mutex_lock();
818 IWineD3DSurface_GetDesc(surface->wineD3DSurface, &desc);
821 restype = desc.resource_type;
823 /* This method is only allowed with surfaces that are render targets, or offscreen plain surfaces
826 if(!(usage & WINED3DUSAGE_RENDERTARGET) && (pool != WINED3DPOOL_DEFAULT || restype != WINED3DRTYPE_SURFACE)) {
827 wined3d_mutex_unlock();
828 WARN("Surface is not a render target, or not a stand-alone D3DPOOL_DEFAULT surface\n");
829 return D3DERR_INVALIDCALL;
832 /* Colorfill can only be used on rendertarget surfaces, or offscreen plain surfaces in D3DPOOL_DEFAULT */
833 /* Note: D3DRECT is compatible with WINED3DRECT */
834 hr = IWineD3DDevice_ColorFill(This->WineD3DDevice, surface->wineD3DSurface, (CONST WINED3DRECT*)pRect, color);
836 wined3d_mutex_unlock();
841 static HRESULT WINAPI IDirect3DDevice9Impl_CreateOffscreenPlainSurface(LPDIRECT3DDEVICE9EX iface, UINT Width, UINT Height, D3DFORMAT Format, D3DPOOL Pool, IDirect3DSurface9 **ppSurface, HANDLE* pSharedHandle) {
844 if(Pool == D3DPOOL_MANAGED ){
845 FIXME("Attempting to create a managed offscreen plain surface\n");
846 return D3DERR_INVALIDCALL;
849 'Off-screen plain surfaces are always lockable, regardless of their pool types.'
851 D3DPOOL_DEFAULT is the appropriate pool for use with the IDirect3DDevice9::StretchRect and IDirect3DDevice9::ColorFill.
852 Why, their always lockable?
853 should I change the usage to dynamic?
855 hr = IDirect3DDevice9Impl_CreateSurface(iface, Width, Height, Format, TRUE /* Lockable */, FALSE /* Discard */,
856 0 /* Level */, ppSurface, 0 /* Usage (undefined/none) */, (WINED3DPOOL)Pool, D3DMULTISAMPLE_NONE,
857 0 /* MultisampleQuality */);
862 /* TODO: move to wineD3D */
863 static HRESULT WINAPI IDirect3DDevice9Impl_SetRenderTarget(LPDIRECT3DDEVICE9EX iface, DWORD RenderTargetIndex, IDirect3DSurface9* pRenderTarget) {
864 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
865 IDirect3DSurface9Impl *pSurface = (IDirect3DSurface9Impl*)pRenderTarget;
867 TRACE("(%p) Relay\n" , This);
869 wined3d_mutex_lock();
870 hr = IWineD3DDevice_SetRenderTarget(This->WineD3DDevice, RenderTargetIndex, pSurface ? pSurface->wineD3DSurface : NULL);
871 wined3d_mutex_unlock();
876 static HRESULT WINAPI IDirect3DDevice9Impl_GetRenderTarget(LPDIRECT3DDEVICE9EX iface, DWORD RenderTargetIndex, IDirect3DSurface9 **ppRenderTarget) {
877 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
878 IWineD3DSurface *pRenderTarget;
881 TRACE("(%p) Relay\n" , This);
883 if (ppRenderTarget == NULL) {
884 return D3DERR_INVALIDCALL;
887 wined3d_mutex_lock();
889 hr=IWineD3DDevice_GetRenderTarget(This->WineD3DDevice,RenderTargetIndex,&pRenderTarget);
893 FIXME("Call to IWineD3DDevice_GetRenderTarget failed, hr %#x\n", hr);
895 else if (!pRenderTarget)
897 *ppRenderTarget = NULL;
901 IWineD3DSurface_GetParent(pRenderTarget, (IUnknown **)ppRenderTarget);
902 IWineD3DSurface_Release(pRenderTarget);
905 wined3d_mutex_unlock();
910 static HRESULT WINAPI IDirect3DDevice9Impl_SetDepthStencilSurface(LPDIRECT3DDEVICE9EX iface, IDirect3DSurface9* pZStencilSurface) {
911 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
912 IDirect3DSurface9Impl *pSurface;
914 TRACE("(%p) Relay\n" , This);
916 pSurface = (IDirect3DSurface9Impl*)pZStencilSurface;
918 wined3d_mutex_lock();
919 hr = IWineD3DDevice_SetDepthStencilSurface(This->WineD3DDevice, NULL==pSurface ? NULL : pSurface->wineD3DSurface);
920 wined3d_mutex_unlock();
925 static HRESULT WINAPI IDirect3DDevice9Impl_GetDepthStencilSurface(LPDIRECT3DDEVICE9EX iface, IDirect3DSurface9 **ppZStencilSurface) {
926 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
928 IWineD3DSurface *pZStencilSurface;
930 TRACE("(%p) Relay\n" , This);
931 if(ppZStencilSurface == NULL){
932 return D3DERR_INVALIDCALL;
935 wined3d_mutex_lock();
936 hr = IWineD3DDevice_GetDepthStencilSurface(This->WineD3DDevice,&pZStencilSurface);
937 if (hr == WINED3D_OK) {
938 IWineD3DSurface_GetParent(pZStencilSurface,(IUnknown**)ppZStencilSurface);
939 IWineD3DSurface_Release(pZStencilSurface);
941 if (hr != WINED3DERR_NOTFOUND)
942 WARN("Call to IWineD3DDevice_GetDepthStencilSurface failed with 0x%08x\n", hr);
943 *ppZStencilSurface = NULL;
945 wined3d_mutex_unlock();
950 static HRESULT WINAPI IDirect3DDevice9Impl_BeginScene(LPDIRECT3DDEVICE9EX iface) {
951 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
953 TRACE("(%p) Relay\n" , This);
955 wined3d_mutex_lock();
956 hr = IWineD3DDevice_BeginScene(This->WineD3DDevice);
957 wined3d_mutex_unlock();
962 static HRESULT WINAPI IDirect3DDevice9Impl_EndScene(LPDIRECT3DDEVICE9EX iface) {
963 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
965 TRACE("(%p) Relay\n" , This);
967 wined3d_mutex_lock();
968 hr = IWineD3DDevice_EndScene(This->WineD3DDevice);
969 wined3d_mutex_unlock();
974 static HRESULT WINAPI IDirect3DDevice9Impl_Clear(LPDIRECT3DDEVICE9EX iface, DWORD Count, CONST D3DRECT* pRects, DWORD Flags, D3DCOLOR Color, float Z, DWORD Stencil) {
975 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
977 TRACE("(%p) Relay\n" , This);
979 /* Note: D3DRECT is compatible with WINED3DRECT */
980 wined3d_mutex_lock();
981 hr = IWineD3DDevice_Clear(This->WineD3DDevice, Count, (CONST WINED3DRECT*) pRects, Flags, Color, Z, Stencil);
982 wined3d_mutex_unlock();
987 static HRESULT WINAPI IDirect3DDevice9Impl_SetTransform(LPDIRECT3DDEVICE9EX iface, D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX* lpMatrix) {
988 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
990 TRACE("(%p) Relay\n" , This);
992 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
993 wined3d_mutex_lock();
994 hr = IWineD3DDevice_SetTransform(This->WineD3DDevice, State, (CONST WINED3DMATRIX*) lpMatrix);
995 wined3d_mutex_unlock();
1000 static HRESULT WINAPI IDirect3DDevice9Impl_GetTransform(LPDIRECT3DDEVICE9EX iface, D3DTRANSFORMSTATETYPE State, D3DMATRIX* pMatrix) {
1001 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1004 TRACE("(%p) Relay\n" , This);
1006 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1007 wined3d_mutex_lock();
1008 hr = IWineD3DDevice_GetTransform(This->WineD3DDevice, State, (WINED3DMATRIX*) pMatrix);
1009 wined3d_mutex_unlock();
1014 static HRESULT WINAPI IDirect3DDevice9Impl_MultiplyTransform(LPDIRECT3DDEVICE9EX iface, D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX* pMatrix) {
1015 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1017 TRACE("(%p) Relay\n" , This);
1019 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1020 wined3d_mutex_lock();
1021 hr = IWineD3DDevice_MultiplyTransform(This->WineD3DDevice, State, (CONST WINED3DMATRIX*) pMatrix);
1022 wined3d_mutex_unlock();
1027 static HRESULT WINAPI IDirect3DDevice9Impl_SetViewport(LPDIRECT3DDEVICE9EX iface, CONST D3DVIEWPORT9* pViewport) {
1028 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1030 TRACE("(%p) Relay\n" , This);
1032 /* Note: D3DVIEWPORT9 is compatible with WINED3DVIEWPORT */
1033 wined3d_mutex_lock();
1034 hr = IWineD3DDevice_SetViewport(This->WineD3DDevice, (const WINED3DVIEWPORT *)pViewport);
1035 wined3d_mutex_unlock();
1040 static HRESULT WINAPI IDirect3DDevice9Impl_GetViewport(LPDIRECT3DDEVICE9EX iface, D3DVIEWPORT9* pViewport) {
1041 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1043 TRACE("(%p) Relay\n" , This);
1045 /* Note: D3DVIEWPORT9 is compatible with WINED3DVIEWPORT */
1046 wined3d_mutex_lock();
1047 hr = IWineD3DDevice_GetViewport(This->WineD3DDevice, (WINED3DVIEWPORT *)pViewport);
1048 wined3d_mutex_unlock();
1053 static HRESULT WINAPI IDirect3DDevice9Impl_SetMaterial(LPDIRECT3DDEVICE9EX iface, CONST D3DMATERIAL9* pMaterial) {
1054 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1056 TRACE("(%p) Relay\n" , This);
1058 /* Note: D3DMATERIAL9 is compatible with WINED3DMATERIAL */
1059 wined3d_mutex_lock();
1060 hr = IWineD3DDevice_SetMaterial(This->WineD3DDevice, (const WINED3DMATERIAL *)pMaterial);
1061 wined3d_mutex_unlock();
1066 static HRESULT WINAPI IDirect3DDevice9Impl_GetMaterial(LPDIRECT3DDEVICE9EX iface, D3DMATERIAL9* pMaterial) {
1067 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1069 TRACE("(%p) Relay\n" , This);
1071 /* Note: D3DMATERIAL9 is compatible with WINED3DMATERIAL */
1072 wined3d_mutex_lock();
1073 hr = IWineD3DDevice_GetMaterial(This->WineD3DDevice, (WINED3DMATERIAL *)pMaterial);
1074 wined3d_mutex_unlock();
1079 static HRESULT WINAPI IDirect3DDevice9Impl_SetLight(LPDIRECT3DDEVICE9EX iface, DWORD Index, CONST D3DLIGHT9* pLight) {
1080 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1082 TRACE("(%p) Relay\n" , This);
1084 /* Note: D3DLIGHT9 is compatible with WINED3DLIGHT */
1085 wined3d_mutex_lock();
1086 hr = IWineD3DDevice_SetLight(This->WineD3DDevice, Index, (const WINED3DLIGHT *)pLight);
1087 wined3d_mutex_unlock();
1092 static HRESULT WINAPI IDirect3DDevice9Impl_GetLight(LPDIRECT3DDEVICE9EX iface, DWORD Index, D3DLIGHT9* pLight) {
1093 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1095 TRACE("(%p) Relay\n" , This);
1097 /* Note: D3DLIGHT9 is compatible with WINED3DLIGHT */
1098 wined3d_mutex_lock();
1099 hr = IWineD3DDevice_GetLight(This->WineD3DDevice, Index, (WINED3DLIGHT *)pLight);
1100 wined3d_mutex_unlock();
1105 static HRESULT WINAPI IDirect3DDevice9Impl_LightEnable(LPDIRECT3DDEVICE9EX iface, DWORD Index, BOOL Enable) {
1106 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1108 TRACE("(%p) Relay\n" , This);
1110 wined3d_mutex_lock();
1111 hr = IWineD3DDevice_SetLightEnable(This->WineD3DDevice, Index, Enable);
1112 wined3d_mutex_unlock();
1117 static HRESULT WINAPI IDirect3DDevice9Impl_GetLightEnable(LPDIRECT3DDEVICE9EX iface, DWORD Index, BOOL* pEnable) {
1118 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1120 TRACE("(%p) Relay\n" , This);
1122 wined3d_mutex_lock();
1123 hr = IWineD3DDevice_GetLightEnable(This->WineD3DDevice, Index, pEnable);
1124 wined3d_mutex_unlock();
1129 static HRESULT WINAPI IDirect3DDevice9Impl_SetClipPlane(LPDIRECT3DDEVICE9EX iface, DWORD Index, CONST float* pPlane) {
1130 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1132 TRACE("(%p) Relay\n" , This);
1134 wined3d_mutex_lock();
1135 hr = IWineD3DDevice_SetClipPlane(This->WineD3DDevice, Index, pPlane);
1136 wined3d_mutex_unlock();
1141 static HRESULT WINAPI IDirect3DDevice9Impl_GetClipPlane(LPDIRECT3DDEVICE9EX iface, DWORD Index, float* pPlane) {
1142 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1144 TRACE("(%p) Relay\n" , This);
1146 wined3d_mutex_lock();
1147 hr = IWineD3DDevice_GetClipPlane(This->WineD3DDevice, Index, pPlane);
1148 wined3d_mutex_unlock();
1153 static HRESULT WINAPI IDirect3DDevice9Impl_SetRenderState(LPDIRECT3DDEVICE9EX iface, D3DRENDERSTATETYPE State, DWORD Value) {
1154 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1156 TRACE("(%p) Relay\n" , This);
1158 wined3d_mutex_lock();
1159 hr = IWineD3DDevice_SetRenderState(This->WineD3DDevice, State, Value);
1160 wined3d_mutex_unlock();
1165 static HRESULT WINAPI IDirect3DDevice9Impl_GetRenderState(LPDIRECT3DDEVICE9EX iface, D3DRENDERSTATETYPE State, DWORD* pValue) {
1166 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1168 TRACE("(%p) Relay\n" , This);
1170 wined3d_mutex_lock();
1171 hr = IWineD3DDevice_GetRenderState(This->WineD3DDevice, State, pValue);
1172 wined3d_mutex_unlock();
1177 static HRESULT WINAPI IDirect3DDevice9Impl_SetClipStatus(LPDIRECT3DDEVICE9EX iface, CONST D3DCLIPSTATUS9* pClipStatus) {
1178 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1180 TRACE("(%p) Relay\n" , This);
1182 wined3d_mutex_lock();
1183 hr = IWineD3DDevice_SetClipStatus(This->WineD3DDevice, (const WINED3DCLIPSTATUS *)pClipStatus);
1184 wined3d_mutex_unlock();
1189 static HRESULT WINAPI IDirect3DDevice9Impl_GetClipStatus(LPDIRECT3DDEVICE9EX iface, D3DCLIPSTATUS9* pClipStatus) {
1190 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1192 TRACE("(%p) Relay\n" , This);
1194 wined3d_mutex_lock();
1195 hr = IWineD3DDevice_GetClipStatus(This->WineD3DDevice, (WINED3DCLIPSTATUS *)pClipStatus);
1196 wined3d_mutex_unlock();
1201 static HRESULT WINAPI IDirect3DDevice9Impl_GetTexture(LPDIRECT3DDEVICE9EX iface, DWORD Stage, IDirect3DBaseTexture9 **ppTexture) {
1202 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1203 IWineD3DBaseTexture *retTexture = NULL;
1204 HRESULT rc = D3D_OK;
1206 TRACE("(%p) Relay\n" , This);
1208 if(ppTexture == NULL){
1209 return D3DERR_INVALIDCALL;
1212 wined3d_mutex_lock();
1213 rc = IWineD3DDevice_GetTexture(This->WineD3DDevice, Stage, &retTexture);
1214 if (SUCCEEDED(rc) && NULL != retTexture) {
1215 IWineD3DBaseTexture_GetParent(retTexture, (IUnknown **)ppTexture);
1216 IWineD3DBaseTexture_Release(retTexture);
1219 WARN("Call to get texture (%d) failed (%p)\n", Stage, retTexture);
1223 wined3d_mutex_unlock();
1228 static HRESULT WINAPI IDirect3DDevice9Impl_SetTexture(LPDIRECT3DDEVICE9EX iface, DWORD Stage, IDirect3DBaseTexture9* pTexture) {
1229 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1231 TRACE("(%p) Relay %d %p\n" , This, Stage, pTexture);
1233 wined3d_mutex_lock();
1234 hr = IWineD3DDevice_SetTexture(This->WineD3DDevice, Stage,
1235 pTexture==NULL ? NULL:((IDirect3DBaseTexture9Impl *)pTexture)->wineD3DBaseTexture);
1236 wined3d_mutex_unlock();
1241 static const WINED3DTEXTURESTAGESTATETYPE tss_lookup[] =
1243 WINED3DTSS_FORCE_DWORD, /* 0, unused */
1244 WINED3DTSS_COLOROP, /* 1, D3DTSS_COLOROP */
1245 WINED3DTSS_COLORARG1, /* 2, D3DTSS_COLORARG1 */
1246 WINED3DTSS_COLORARG2, /* 3, D3DTSS_COLORARG2 */
1247 WINED3DTSS_ALPHAOP, /* 4, D3DTSS_ALPHAOP */
1248 WINED3DTSS_ALPHAARG1, /* 5, D3DTSS_ALPHAARG1 */
1249 WINED3DTSS_ALPHAARG2, /* 6, D3DTSS_ALPHAARG2 */
1250 WINED3DTSS_BUMPENVMAT00, /* 7, D3DTSS_BUMPENVMAT00 */
1251 WINED3DTSS_BUMPENVMAT01, /* 8, D3DTSS_BUMPENVMAT01 */
1252 WINED3DTSS_BUMPENVMAT10, /* 9, D3DTSS_BUMPENVMAT10 */
1253 WINED3DTSS_BUMPENVMAT11, /* 10, D3DTSS_BUMPENVMAT11 */
1254 WINED3DTSS_TEXCOORDINDEX, /* 11, D3DTSS_TEXCOORDINDEX */
1255 WINED3DTSS_FORCE_DWORD, /* 12, unused */
1256 WINED3DTSS_FORCE_DWORD, /* 13, unused */
1257 WINED3DTSS_FORCE_DWORD, /* 14, unused */
1258 WINED3DTSS_FORCE_DWORD, /* 15, unused */
1259 WINED3DTSS_FORCE_DWORD, /* 16, unused */
1260 WINED3DTSS_FORCE_DWORD, /* 17, unused */
1261 WINED3DTSS_FORCE_DWORD, /* 18, unused */
1262 WINED3DTSS_FORCE_DWORD, /* 19, unused */
1263 WINED3DTSS_FORCE_DWORD, /* 20, unused */
1264 WINED3DTSS_FORCE_DWORD, /* 21, unused */
1265 WINED3DTSS_BUMPENVLSCALE, /* 22, D3DTSS_BUMPENVLSCALE */
1266 WINED3DTSS_BUMPENVLOFFSET, /* 23, D3DTSS_BUMPENVLOFFSET */
1267 WINED3DTSS_TEXTURETRANSFORMFLAGS, /* 24, D3DTSS_TEXTURETRANSFORMFLAGS */
1268 WINED3DTSS_FORCE_DWORD, /* 25, unused */
1269 WINED3DTSS_COLORARG0, /* 26, D3DTSS_COLORARG0 */
1270 WINED3DTSS_ALPHAARG0, /* 27, D3DTSS_ALPHAARG0 */
1271 WINED3DTSS_RESULTARG, /* 28, D3DTSS_RESULTARG */
1272 WINED3DTSS_FORCE_DWORD, /* 29, unused */
1273 WINED3DTSS_FORCE_DWORD, /* 30, unused */
1274 WINED3DTSS_FORCE_DWORD, /* 31, unused */
1275 WINED3DTSS_CONSTANT, /* 32, D3DTSS_CONSTANT */
1278 static HRESULT WINAPI IDirect3DDevice9Impl_GetTextureStageState(LPDIRECT3DDEVICE9EX iface, DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD* pValue) {
1279 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1281 TRACE("(%p) Relay\n" , This);
1283 wined3d_mutex_lock();
1284 hr = IWineD3DDevice_GetTextureStageState(This->WineD3DDevice, Stage, tss_lookup[Type], pValue);
1285 wined3d_mutex_unlock();
1290 static HRESULT WINAPI IDirect3DDevice9Impl_SetTextureStageState(LPDIRECT3DDEVICE9EX iface, DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD Value) {
1291 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1293 TRACE("(%p) Relay\n" , This);
1295 wined3d_mutex_lock();
1296 hr = IWineD3DDevice_SetTextureStageState(This->WineD3DDevice, Stage, tss_lookup[Type], Value);
1297 wined3d_mutex_unlock();
1302 static HRESULT WINAPI IDirect3DDevice9Impl_GetSamplerState(IDirect3DDevice9Ex *iface, DWORD Sampler,
1303 D3DSAMPLERSTATETYPE Type, DWORD *pValue)
1305 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1307 TRACE("(%p) Relay\n" , This);
1309 wined3d_mutex_lock();
1310 hr = IWineD3DDevice_GetSamplerState(This->WineD3DDevice, Sampler, Type, pValue);
1311 wined3d_mutex_unlock();
1316 static HRESULT WINAPI IDirect3DDevice9Impl_SetSamplerState(LPDIRECT3DDEVICE9EX iface, DWORD Sampler, D3DSAMPLERSTATETYPE Type, DWORD Value) {
1317 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1319 TRACE("(%p) Relay\n" , This);
1321 wined3d_mutex_lock();
1322 hr = IWineD3DDevice_SetSamplerState(This->WineD3DDevice, Sampler, Type, Value);
1323 wined3d_mutex_unlock();
1328 static HRESULT WINAPI IDirect3DDevice9Impl_ValidateDevice(LPDIRECT3DDEVICE9EX iface, DWORD* pNumPasses) {
1329 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1331 TRACE("(%p) Relay\n" , This);
1333 wined3d_mutex_lock();
1334 hr = IWineD3DDevice_ValidateDevice(This->WineD3DDevice, pNumPasses);
1335 wined3d_mutex_unlock();
1340 static HRESULT WINAPI IDirect3DDevice9Impl_SetPaletteEntries(IDirect3DDevice9Ex *iface, UINT PaletteNumber,
1341 const PALETTEENTRY *pEntries)
1343 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1345 TRACE("(%p) Relay\n" , This);
1347 wined3d_mutex_lock();
1348 hr = IWineD3DDevice_SetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
1349 wined3d_mutex_unlock();
1354 static HRESULT WINAPI IDirect3DDevice9Impl_GetPaletteEntries(LPDIRECT3DDEVICE9EX iface, UINT PaletteNumber, PALETTEENTRY* pEntries) {
1355 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1357 TRACE("(%p) Relay\n" , This);
1359 wined3d_mutex_lock();
1360 hr = IWineD3DDevice_GetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
1361 wined3d_mutex_unlock();
1366 static HRESULT WINAPI IDirect3DDevice9Impl_SetCurrentTexturePalette(LPDIRECT3DDEVICE9EX iface, UINT PaletteNumber) {
1367 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1369 TRACE("(%p) Relay\n" , This);
1371 wined3d_mutex_lock();
1372 hr = IWineD3DDevice_SetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
1373 wined3d_mutex_unlock();
1378 static HRESULT WINAPI IDirect3DDevice9Impl_GetCurrentTexturePalette(LPDIRECT3DDEVICE9EX iface, UINT* PaletteNumber) {
1379 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1381 TRACE("(%p) Relay\n" , This);
1383 wined3d_mutex_lock();
1384 hr = IWineD3DDevice_GetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
1385 wined3d_mutex_unlock();
1390 static HRESULT WINAPI IDirect3DDevice9Impl_SetScissorRect(LPDIRECT3DDEVICE9EX iface, CONST RECT* pRect) {
1391 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1393 TRACE("(%p) Relay\n" , This);
1395 wined3d_mutex_lock();
1396 hr = IWineD3DDevice_SetScissorRect(This->WineD3DDevice, pRect);
1397 wined3d_mutex_unlock();
1402 static HRESULT WINAPI IDirect3DDevice9Impl_GetScissorRect(LPDIRECT3DDEVICE9EX iface, RECT* pRect) {
1403 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1405 TRACE("(%p) Relay\n" , This);
1407 wined3d_mutex_lock();
1408 hr = IWineD3DDevice_GetScissorRect(This->WineD3DDevice, pRect);
1409 wined3d_mutex_unlock();
1414 static HRESULT WINAPI IDirect3DDevice9Impl_SetSoftwareVertexProcessing(LPDIRECT3DDEVICE9EX iface, BOOL bSoftware) {
1415 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1417 TRACE("(%p) Relay\n" , This);
1419 wined3d_mutex_lock();
1420 hr = IWineD3DDevice_SetSoftwareVertexProcessing(This->WineD3DDevice, bSoftware);
1421 wined3d_mutex_unlock();
1426 static BOOL WINAPI IDirect3DDevice9Impl_GetSoftwareVertexProcessing(LPDIRECT3DDEVICE9EX iface) {
1427 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1429 TRACE("(%p) Relay\n" , This);
1431 wined3d_mutex_lock();
1432 ret = IWineD3DDevice_GetSoftwareVertexProcessing(This->WineD3DDevice);
1433 wined3d_mutex_unlock();
1438 static HRESULT WINAPI IDirect3DDevice9Impl_SetNPatchMode(LPDIRECT3DDEVICE9EX iface, float nSegments) {
1439 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1441 TRACE("(%p) Relay\n" , This);
1443 wined3d_mutex_lock();
1444 hr = IWineD3DDevice_SetNPatchMode(This->WineD3DDevice, nSegments);
1445 wined3d_mutex_unlock();
1450 static float WINAPI IDirect3DDevice9Impl_GetNPatchMode(LPDIRECT3DDEVICE9EX iface) {
1451 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1453 TRACE("(%p) Relay\n" , This);
1455 wined3d_mutex_lock();
1456 ret = IWineD3DDevice_GetNPatchMode(This->WineD3DDevice);
1457 wined3d_mutex_unlock();
1462 static HRESULT WINAPI IDirect3DDevice9Impl_DrawPrimitive(IDirect3DDevice9Ex *iface, D3DPRIMITIVETYPE PrimitiveType,
1463 UINT StartVertex, UINT PrimitiveCount)
1465 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1467 TRACE("(%p) Relay\n" , This);
1469 wined3d_mutex_lock();
1470 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1471 hr = IWineD3DDevice_DrawPrimitive(This->WineD3DDevice, StartVertex,
1472 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount));
1473 wined3d_mutex_unlock();
1478 static HRESULT WINAPI IDirect3DDevice9Impl_DrawIndexedPrimitive(LPDIRECT3DDEVICE9EX iface, D3DPRIMITIVETYPE PrimitiveType,
1479 INT BaseVertexIndex, UINT MinVertexIndex, UINT NumVertices, UINT startIndex, UINT primCount) {
1480 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1482 TRACE("(%p) Relay\n" , This);
1484 /* D3D8 passes the baseVertexIndex in SetIndices, and due to the stateblock functions wined3d has to work that way */
1485 wined3d_mutex_lock();
1486 IWineD3DDevice_SetBaseVertexIndex(This->WineD3DDevice, BaseVertexIndex);
1487 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1488 hr = IWineD3DDevice_DrawIndexedPrimitive(This->WineD3DDevice, startIndex,
1489 vertex_count_from_primitive_count(PrimitiveType, primCount));
1490 wined3d_mutex_unlock();
1495 static HRESULT WINAPI IDirect3DDevice9Impl_DrawPrimitiveUP(IDirect3DDevice9Ex *iface, D3DPRIMITIVETYPE PrimitiveType,
1496 UINT PrimitiveCount, const void *pVertexStreamZeroData, UINT VertexStreamZeroStride)
1498 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1500 TRACE("(%p) Relay\n" , This);
1502 wined3d_mutex_lock();
1503 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1504 hr = IWineD3DDevice_DrawPrimitiveUP(This->WineD3DDevice,
1505 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount),
1506 pVertexStreamZeroData, VertexStreamZeroStride);
1507 wined3d_mutex_unlock();
1512 static HRESULT WINAPI IDirect3DDevice9Impl_DrawIndexedPrimitiveUP(LPDIRECT3DDEVICE9EX iface, D3DPRIMITIVETYPE PrimitiveType, UINT MinVertexIndex,
1513 UINT NumVertexIndices, UINT PrimitiveCount, CONST void* pIndexData,
1514 D3DFORMAT IndexDataFormat, CONST void* pVertexStreamZeroData, UINT VertexStreamZeroStride) {
1515 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1517 TRACE("(%p) Relay\n" , This);
1519 wined3d_mutex_lock();
1520 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1521 hr = IWineD3DDevice_DrawIndexedPrimitiveUP(This->WineD3DDevice,
1522 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount), pIndexData,
1523 wined3dformat_from_d3dformat(IndexDataFormat), pVertexStreamZeroData, VertexStreamZeroStride);
1524 wined3d_mutex_unlock();
1529 static HRESULT WINAPI IDirect3DDevice9Impl_ProcessVertices(LPDIRECT3DDEVICE9EX iface, UINT SrcStartIndex, UINT DestIndex, UINT VertexCount, IDirect3DVertexBuffer9* pDestBuffer, IDirect3DVertexDeclaration9* pVertexDecl, DWORD Flags) {
1530 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1531 IDirect3DVertexDeclaration9Impl *Decl = (IDirect3DVertexDeclaration9Impl *) pVertexDecl;
1533 IDirect3DVertexBuffer9Impl *dest = (IDirect3DVertexBuffer9Impl *) pDestBuffer;
1534 TRACE("(%p) Relay\n" , This);
1536 wined3d_mutex_lock();
1537 hr = IWineD3DDevice_ProcessVertices(This->WineD3DDevice,SrcStartIndex, DestIndex, VertexCount, dest->wineD3DVertexBuffer, Decl ? Decl->wineD3DVertexDeclaration : NULL, Flags, dest->fvf);
1538 wined3d_mutex_unlock();
1543 static IDirect3DVertexDeclaration9 *getConvertedDecl(IDirect3DDevice9Impl *This, DWORD fvf) {
1545 D3DVERTEXELEMENT9* elements = NULL;
1546 IDirect3DVertexDeclaration9* pDecl = NULL;
1547 int p, low, high; /* deliberately signed */
1548 IDirect3DVertexDeclaration9 **convertedDecls = This->convertedDecls;
1550 TRACE("Searching for declaration for fvf %08x... ", fvf);
1553 high = This->numConvertedDecls - 1;
1554 while(low <= high) {
1555 p = (low + high) >> 1;
1557 if(((IDirect3DVertexDeclaration9Impl *) convertedDecls[p])->convFVF == fvf) {
1558 TRACE("found %p\n", convertedDecls[p]);
1559 return convertedDecls[p];
1560 } else if(((IDirect3DVertexDeclaration9Impl *) convertedDecls[p])->convFVF < fvf) {
1566 TRACE("not found. Creating and inserting at position %d.\n", low);
1568 hr = vdecl_convert_fvf(fvf, &elements);
1569 if (hr != S_OK) return NULL;
1571 hr = IDirect3DDevice9Impl_CreateVertexDeclaration((IDirect3DDevice9Ex *) This, elements, &pDecl);
1572 HeapFree(GetProcessHeap(), 0, elements); /* CreateVertexDeclaration makes a copy */
1573 if (hr != S_OK) return NULL;
1575 if(This->declArraySize == This->numConvertedDecls) {
1576 int grow = max(This->declArraySize / 2, 8);
1577 convertedDecls = HeapReAlloc(GetProcessHeap(), 0, convertedDecls,
1578 sizeof(convertedDecls[0]) * (This->numConvertedDecls + grow));
1579 if(!convertedDecls) {
1580 /* This will destroy it */
1581 IDirect3DVertexDeclaration9_Release(pDecl);
1584 This->convertedDecls = convertedDecls;
1585 This->declArraySize += grow;
1588 memmove(convertedDecls + low + 1, convertedDecls + low, sizeof(IDirect3DVertexDeclaration9Impl *) * (This->numConvertedDecls - low));
1589 convertedDecls[low] = pDecl;
1590 This->numConvertedDecls++;
1592 /* Will prevent the decl from being destroyed */
1593 ((IDirect3DVertexDeclaration9Impl *) pDecl)->convFVF = fvf;
1594 IDirect3DVertexDeclaration9_Release(pDecl); /* Does not destroy now */
1596 TRACE("Returning %p. %d decls in array\n", pDecl, This->numConvertedDecls);
1600 static HRESULT WINAPI IDirect3DDevice9Impl_SetFVF(LPDIRECT3DDEVICE9EX iface, DWORD FVF) {
1601 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1602 IDirect3DVertexDeclaration9 *decl;
1605 TRACE("(%p) Relay\n" , This);
1609 WARN("%#x is not a valid FVF\n", FVF);
1613 wined3d_mutex_lock();
1614 decl = getConvertedDecl(This, FVF);
1615 wined3d_mutex_unlock();
1619 /* Any situation when this should happen, except out of memory? */
1620 ERR("Failed to create a converted vertex declaration\n");
1621 return D3DERR_DRIVERINTERNALERROR;
1624 hr = IDirect3DDevice9Impl_SetVertexDeclaration(iface, decl);
1625 if (FAILED(hr)) ERR("Failed to set vertex declaration\n");
1630 static HRESULT WINAPI IDirect3DDevice9Impl_GetFVF(LPDIRECT3DDEVICE9EX iface, DWORD* pFVF) {
1631 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1632 IDirect3DVertexDeclaration9 *decl;
1634 TRACE("(%p) Relay\n" , This);
1636 hr = IDirect3DDevice9_GetVertexDeclaration(iface, &decl);
1639 WARN("Failed to get vertex declaration, %#x\n", hr);
1646 *pFVF = ((IDirect3DVertexDeclaration9Impl *)decl)->convFVF;
1647 IDirect3DVertexDeclaration9_Release(decl);
1654 TRACE("Returning FVF %#x\n", *pFVF);
1659 static HRESULT WINAPI IDirect3DDevice9Impl_SetStreamSource(LPDIRECT3DDEVICE9EX iface, UINT StreamNumber, IDirect3DVertexBuffer9* pStreamData, UINT OffsetInBytes, UINT Stride) {
1660 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1662 TRACE("(%p) Relay\n" , This);
1664 wined3d_mutex_lock();
1665 hr = IWineD3DDevice_SetStreamSource(This->WineD3DDevice, StreamNumber,
1666 pStreamData ? ((IDirect3DVertexBuffer9Impl *)pStreamData)->wineD3DVertexBuffer : NULL,
1667 OffsetInBytes, Stride);
1668 wined3d_mutex_unlock();
1673 static HRESULT WINAPI IDirect3DDevice9Impl_GetStreamSource(LPDIRECT3DDEVICE9EX iface, UINT StreamNumber, IDirect3DVertexBuffer9 **pStream, UINT* OffsetInBytes, UINT* pStride) {
1674 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1675 IWineD3DBuffer *retStream = NULL;
1676 HRESULT rc = D3D_OK;
1678 TRACE("(%p) Relay\n" , This);
1680 if(pStream == NULL){
1681 return D3DERR_INVALIDCALL;
1684 wined3d_mutex_lock();
1685 rc = IWineD3DDevice_GetStreamSource(This->WineD3DDevice, StreamNumber, &retStream, OffsetInBytes, pStride);
1686 if (rc == D3D_OK && NULL != retStream) {
1687 IWineD3DBuffer_GetParent(retStream, (IUnknown **)pStream);
1688 IWineD3DBuffer_Release(retStream);
1691 FIXME("Call to GetStreamSource failed %p %p\n", OffsetInBytes, pStride);
1695 wined3d_mutex_unlock();
1700 static HRESULT WINAPI IDirect3DDevice9Impl_SetStreamSourceFreq(IDirect3DDevice9Ex *iface, UINT StreamNumber,
1703 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1705 TRACE("(%p) Relay\n" , This);
1707 wined3d_mutex_lock();
1708 hr = IWineD3DDevice_SetStreamSourceFreq(This->WineD3DDevice, StreamNumber, Divider);
1709 wined3d_mutex_unlock();
1714 static HRESULT WINAPI IDirect3DDevice9Impl_GetStreamSourceFreq(LPDIRECT3DDEVICE9EX iface, UINT StreamNumber, UINT* Divider) {
1715 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1717 TRACE("(%p) Relay\n" , This);
1719 wined3d_mutex_lock();
1720 hr = IWineD3DDevice_GetStreamSourceFreq(This->WineD3DDevice, StreamNumber, Divider);
1721 wined3d_mutex_unlock();
1726 static HRESULT WINAPI IDirect3DDevice9Impl_SetIndices(LPDIRECT3DDEVICE9EX iface, IDirect3DIndexBuffer9* pIndexData) {
1727 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1729 IDirect3DIndexBuffer9Impl *ib = (IDirect3DIndexBuffer9Impl *) pIndexData;
1730 TRACE("(%p) Relay\n", This);
1732 wined3d_mutex_lock();
1733 hr = IWineD3DDevice_SetIndices(This->WineD3DDevice,
1734 ib ? ib->wineD3DIndexBuffer : NULL,
1735 ib ? ib->format : WINED3DFMT_UNKNOWN);
1736 wined3d_mutex_unlock();
1741 static HRESULT WINAPI IDirect3DDevice9Impl_GetIndices(LPDIRECT3DDEVICE9EX iface, IDirect3DIndexBuffer9 **ppIndexData) {
1742 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1743 IWineD3DBuffer *retIndexData = NULL;
1744 HRESULT rc = D3D_OK;
1746 TRACE("(%p) Relay\n", This);
1748 if(ppIndexData == NULL){
1749 return D3DERR_INVALIDCALL;
1752 wined3d_mutex_lock();
1753 rc = IWineD3DDevice_GetIndices(This->WineD3DDevice, &retIndexData);
1754 if (SUCCEEDED(rc) && retIndexData) {
1755 IWineD3DBuffer_GetParent(retIndexData, (IUnknown **)ppIndexData);
1756 IWineD3DBuffer_Release(retIndexData);
1758 if (FAILED(rc)) FIXME("Call to GetIndices failed\n");
1759 *ppIndexData = NULL;
1761 wined3d_mutex_unlock();
1766 static HRESULT WINAPI IDirect3DDevice9Impl_DrawRectPatch(LPDIRECT3DDEVICE9EX iface, UINT Handle, CONST float* pNumSegs, CONST D3DRECTPATCH_INFO* pRectPatchInfo) {
1767 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1769 TRACE("(%p) Relay\n", This);
1771 wined3d_mutex_lock();
1772 hr = IWineD3DDevice_DrawRectPatch(This->WineD3DDevice, Handle, pNumSegs, (CONST WINED3DRECTPATCH_INFO *)pRectPatchInfo);
1773 wined3d_mutex_unlock();
1778 static HRESULT WINAPI IDirect3DDevice9Impl_DrawTriPatch(LPDIRECT3DDEVICE9EX iface, UINT Handle, CONST float* pNumSegs, CONST D3DTRIPATCH_INFO* pTriPatchInfo) {
1779 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1781 TRACE("(%p) Relay\n", This);
1783 wined3d_mutex_lock();
1784 hr = IWineD3DDevice_DrawTriPatch(This->WineD3DDevice, Handle, pNumSegs, (CONST WINED3DTRIPATCH_INFO *)pTriPatchInfo);
1785 wined3d_mutex_unlock();
1790 static HRESULT WINAPI IDirect3DDevice9Impl_DeletePatch(LPDIRECT3DDEVICE9EX iface, UINT Handle) {
1791 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1793 TRACE("(%p) Relay\n", This);
1795 wined3d_mutex_lock();
1796 hr = IWineD3DDevice_DeletePatch(This->WineD3DDevice, Handle);
1797 wined3d_mutex_unlock();
1802 static HRESULT WINAPI IDirect3DDevice9ExImpl_SetConvolutionMonoKernel(LPDIRECT3DDEVICE9EX iface, UINT width, UINT height, float *rows, float *columns) {
1803 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1804 FIXME("(%p)->(%d, %d, %p, %p) Stub!\n", This, width, height, rows, columns);
1805 return WINED3DERR_INVALIDCALL;
1808 static HRESULT WINAPI IDirect3DDevice9ExImpl_ComposeRects(LPDIRECT3DDEVICE9EX iface, IDirect3DSurface9 *pSrc, IDirect3DDevice9 *pDst, IDirect3DVertexBuffer9 *pSrcRectDescs, UINT NumRects, IDirect3DVertexBuffer9 *pDstRectDescs, D3DCOMPOSERECTSOP Operation, int Xoffset, int Yoffset) {
1809 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1810 FIXME("(%p)->(%p, %p, %p, %d, %p, %d, %d, %d) Stub!\n", This, pSrc, pDst, pSrcRectDescs, NumRects, pDstRectDescs, Operation, Xoffset, Yoffset);
1811 return WINED3DERR_INVALIDCALL;
1814 static HRESULT WINAPI IDirect3DDevice9ExImpl_PresentEx(LPDIRECT3DDEVICE9EX iface, CONST RECT *pSourceRect, CONST RECT *pDestRect, HWND hDestWindowOverride, CONST RGNDATA *pDirtyRegion, DWORD dwFlags) {
1815 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1816 FIXME("(%p= -> (%p), %p, %p, %p, 0x%08x) Stub!\n", This, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion, dwFlags);
1817 return WINED3DERR_INVALIDCALL;
1820 static HRESULT WINAPI IDirect3DDevice9ExImpl_GetGPUThreadPriority(LPDIRECT3DDEVICE9EX iface, INT *pPriority) {
1821 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1822 FIXME("(%p)->(%p) Stub!\n", This, pPriority);
1823 return WINED3DERR_INVALIDCALL;
1826 static HRESULT WINAPI IDirect3DDevice9ExImpl_SetGPUThreadPriority(LPDIRECT3DDEVICE9EX iface, INT Priority) {
1827 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1828 FIXME("(%p)->(%d) Stub!\n", This, Priority);
1829 return WINED3DERR_INVALIDCALL;
1832 static HRESULT WINAPI IDirect3DDevice9ExImpl_WaitForVBlank(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain) {
1833 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1834 FIXME("(%p)->(%d) Stub!\n", This, iSwapChain);
1835 return WINED3DERR_INVALIDCALL;
1838 static HRESULT WINAPI IDirect3DDevice9ExImpl_CheckresourceResidency(LPDIRECT3DDEVICE9EX iface, IDirect3DResource9 ** pResourceArray, UINT32 Numresources) {
1839 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1840 FIXME("(%p)->(%p, %d) Stub!\n", This, pResourceArray, Numresources);
1841 return WINED3DERR_INVALIDCALL;
1844 static HRESULT WINAPI IDirect3DDevice9ExImpl_SetMaximumFrameLatency(LPDIRECT3DDEVICE9EX iface, UINT MaxLatency) {
1845 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1846 FIXME("(%p)->(%d) Stub!\n", This, MaxLatency);
1847 return WINED3DERR_INVALIDCALL;
1850 static HRESULT WINAPI IDirect3DDevice9ExImpl_GetMaximumFrameLatency(LPDIRECT3DDEVICE9EX iface, UINT *pMaxLatency) {
1851 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1852 FIXME("(%p)->(%p) Stub!\n", This, pMaxLatency);
1854 return WINED3DERR_INVALIDCALL;
1857 static HRESULT WINAPI IDirect3DDevice9ExImpl_CheckdeviceState(LPDIRECT3DDEVICE9EX iface, HWND hDestinationWindow) {
1858 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1859 FIXME("(%p)->(%p) Stub!\n", This, hDestinationWindow);
1860 return WINED3DERR_INVALIDCALL;
1863 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) {
1864 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1865 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);
1866 return WINED3DERR_INVALIDCALL;
1869 static HRESULT WINAPI IDirect3DDevice9ExImpl_CreateOffscreenPlainSurfaceEx(LPDIRECT3DDEVICE9EX iface, UINT Width, UINT Height, D3DFORMAT Format, D3DPOOL Pool, IDirect3DSurface9 **ppSurface, HANDLE *pSharedHandle, DWORD Usage) {
1870 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1871 FIXME("(%p)->(%d, %d, %d, %d, %p, %p, 0x%08x) Stub!\n", This, Width, Height, Format, Pool, ppSurface, pSharedHandle, Usage);
1872 return WINED3DERR_INVALIDCALL;
1875 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) {
1876 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1877 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);
1878 return WINED3DERR_INVALIDCALL;
1881 static HRESULT WINAPI IDirect3DDevice9ExImpl_ResetEx(LPDIRECT3DDEVICE9EX iface, D3DPRESENT_PARAMETERS *pPresentationParameters, D3DDISPLAYMODEEX *pFullscreenDisplayMode) {
1882 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1883 FIXME("(%p)->(%p) Stub!\n", This, pPresentationParameters);
1884 return WINED3DERR_INVALIDCALL;
1887 static HRESULT WINAPI IDirect3DDevice9ExImpl_GetDisplayModeEx(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain, D3DDISPLAYMODEEX *pMode, D3DDISPLAYROTATION *pRotation) {
1888 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1889 FIXME("(%p)->(%d, %p, %p) Stub!\n", This, iSwapChain, pMode, pRotation);
1890 return WINED3DERR_INVALIDCALL;
1893 const IDirect3DDevice9ExVtbl Direct3DDevice9_Vtbl =
1896 IDirect3DDevice9Impl_QueryInterface,
1897 IDirect3DDevice9Impl_AddRef,
1898 IDirect3DDevice9Impl_Release,
1899 /* IDirect3DDevice9 */
1900 IDirect3DDevice9Impl_TestCooperativeLevel,
1901 IDirect3DDevice9Impl_GetAvailableTextureMem,
1902 IDirect3DDevice9Impl_EvictManagedResources,
1903 IDirect3DDevice9Impl_GetDirect3D,
1904 IDirect3DDevice9Impl_GetDeviceCaps,
1905 IDirect3DDevice9Impl_GetDisplayMode,
1906 IDirect3DDevice9Impl_GetCreationParameters,
1907 IDirect3DDevice9Impl_SetCursorProperties,
1908 IDirect3DDevice9Impl_SetCursorPosition,
1909 IDirect3DDevice9Impl_ShowCursor,
1910 IDirect3DDevice9Impl_CreateAdditionalSwapChain,
1911 IDirect3DDevice9Impl_GetSwapChain,
1912 IDirect3DDevice9Impl_GetNumberOfSwapChains,
1913 IDirect3DDevice9Impl_Reset,
1914 IDirect3DDevice9Impl_Present,
1915 IDirect3DDevice9Impl_GetBackBuffer,
1916 IDirect3DDevice9Impl_GetRasterStatus,
1917 IDirect3DDevice9Impl_SetDialogBoxMode,
1918 IDirect3DDevice9Impl_SetGammaRamp,
1919 IDirect3DDevice9Impl_GetGammaRamp,
1920 IDirect3DDevice9Impl_CreateTexture,
1921 IDirect3DDevice9Impl_CreateVolumeTexture,
1922 IDirect3DDevice9Impl_CreateCubeTexture,
1923 IDirect3DDevice9Impl_CreateVertexBuffer,
1924 IDirect3DDevice9Impl_CreateIndexBuffer,
1925 IDirect3DDevice9Impl_CreateRenderTarget,
1926 IDirect3DDevice9Impl_CreateDepthStencilSurface,
1927 IDirect3DDevice9Impl_UpdateSurface,
1928 IDirect3DDevice9Impl_UpdateTexture,
1929 IDirect3DDevice9Impl_GetRenderTargetData,
1930 IDirect3DDevice9Impl_GetFrontBufferData,
1931 IDirect3DDevice9Impl_StretchRect,
1932 IDirect3DDevice9Impl_ColorFill,
1933 IDirect3DDevice9Impl_CreateOffscreenPlainSurface,
1934 IDirect3DDevice9Impl_SetRenderTarget,
1935 IDirect3DDevice9Impl_GetRenderTarget,
1936 IDirect3DDevice9Impl_SetDepthStencilSurface,
1937 IDirect3DDevice9Impl_GetDepthStencilSurface,
1938 IDirect3DDevice9Impl_BeginScene,
1939 IDirect3DDevice9Impl_EndScene,
1940 IDirect3DDevice9Impl_Clear,
1941 IDirect3DDevice9Impl_SetTransform,
1942 IDirect3DDevice9Impl_GetTransform,
1943 IDirect3DDevice9Impl_MultiplyTransform,
1944 IDirect3DDevice9Impl_SetViewport,
1945 IDirect3DDevice9Impl_GetViewport,
1946 IDirect3DDevice9Impl_SetMaterial,
1947 IDirect3DDevice9Impl_GetMaterial,
1948 IDirect3DDevice9Impl_SetLight,
1949 IDirect3DDevice9Impl_GetLight,
1950 IDirect3DDevice9Impl_LightEnable,
1951 IDirect3DDevice9Impl_GetLightEnable,
1952 IDirect3DDevice9Impl_SetClipPlane,
1953 IDirect3DDevice9Impl_GetClipPlane,
1954 IDirect3DDevice9Impl_SetRenderState,
1955 IDirect3DDevice9Impl_GetRenderState,
1956 IDirect3DDevice9Impl_CreateStateBlock,
1957 IDirect3DDevice9Impl_BeginStateBlock,
1958 IDirect3DDevice9Impl_EndStateBlock,
1959 IDirect3DDevice9Impl_SetClipStatus,
1960 IDirect3DDevice9Impl_GetClipStatus,
1961 IDirect3DDevice9Impl_GetTexture,
1962 IDirect3DDevice9Impl_SetTexture,
1963 IDirect3DDevice9Impl_GetTextureStageState,
1964 IDirect3DDevice9Impl_SetTextureStageState,
1965 IDirect3DDevice9Impl_GetSamplerState,
1966 IDirect3DDevice9Impl_SetSamplerState,
1967 IDirect3DDevice9Impl_ValidateDevice,
1968 IDirect3DDevice9Impl_SetPaletteEntries,
1969 IDirect3DDevice9Impl_GetPaletteEntries,
1970 IDirect3DDevice9Impl_SetCurrentTexturePalette,
1971 IDirect3DDevice9Impl_GetCurrentTexturePalette,
1972 IDirect3DDevice9Impl_SetScissorRect,
1973 IDirect3DDevice9Impl_GetScissorRect,
1974 IDirect3DDevice9Impl_SetSoftwareVertexProcessing,
1975 IDirect3DDevice9Impl_GetSoftwareVertexProcessing,
1976 IDirect3DDevice9Impl_SetNPatchMode,
1977 IDirect3DDevice9Impl_GetNPatchMode,
1978 IDirect3DDevice9Impl_DrawPrimitive,
1979 IDirect3DDevice9Impl_DrawIndexedPrimitive,
1980 IDirect3DDevice9Impl_DrawPrimitiveUP,
1981 IDirect3DDevice9Impl_DrawIndexedPrimitiveUP,
1982 IDirect3DDevice9Impl_ProcessVertices,
1983 IDirect3DDevice9Impl_CreateVertexDeclaration,
1984 IDirect3DDevice9Impl_SetVertexDeclaration,
1985 IDirect3DDevice9Impl_GetVertexDeclaration,
1986 IDirect3DDevice9Impl_SetFVF,
1987 IDirect3DDevice9Impl_GetFVF,
1988 IDirect3DDevice9Impl_CreateVertexShader,
1989 IDirect3DDevice9Impl_SetVertexShader,
1990 IDirect3DDevice9Impl_GetVertexShader,
1991 IDirect3DDevice9Impl_SetVertexShaderConstantF,
1992 IDirect3DDevice9Impl_GetVertexShaderConstantF,
1993 IDirect3DDevice9Impl_SetVertexShaderConstantI,
1994 IDirect3DDevice9Impl_GetVertexShaderConstantI,
1995 IDirect3DDevice9Impl_SetVertexShaderConstantB,
1996 IDirect3DDevice9Impl_GetVertexShaderConstantB,
1997 IDirect3DDevice9Impl_SetStreamSource,
1998 IDirect3DDevice9Impl_GetStreamSource,
1999 IDirect3DDevice9Impl_SetStreamSourceFreq,
2000 IDirect3DDevice9Impl_GetStreamSourceFreq,
2001 IDirect3DDevice9Impl_SetIndices,
2002 IDirect3DDevice9Impl_GetIndices,
2003 IDirect3DDevice9Impl_CreatePixelShader,
2004 IDirect3DDevice9Impl_SetPixelShader,
2005 IDirect3DDevice9Impl_GetPixelShader,
2006 IDirect3DDevice9Impl_SetPixelShaderConstantF,
2007 IDirect3DDevice9Impl_GetPixelShaderConstantF,
2008 IDirect3DDevice9Impl_SetPixelShaderConstantI,
2009 IDirect3DDevice9Impl_GetPixelShaderConstantI,
2010 IDirect3DDevice9Impl_SetPixelShaderConstantB,
2011 IDirect3DDevice9Impl_GetPixelShaderConstantB,
2012 IDirect3DDevice9Impl_DrawRectPatch,
2013 IDirect3DDevice9Impl_DrawTriPatch,
2014 IDirect3DDevice9Impl_DeletePatch,
2015 IDirect3DDevice9Impl_CreateQuery,
2016 /* IDirect3DDevice9Ex */
2017 IDirect3DDevice9ExImpl_SetConvolutionMonoKernel,
2018 IDirect3DDevice9ExImpl_ComposeRects,
2019 IDirect3DDevice9ExImpl_PresentEx,
2020 IDirect3DDevice9ExImpl_GetGPUThreadPriority,
2021 IDirect3DDevice9ExImpl_SetGPUThreadPriority,
2022 IDirect3DDevice9ExImpl_WaitForVBlank,
2023 IDirect3DDevice9ExImpl_CheckresourceResidency,
2024 IDirect3DDevice9ExImpl_SetMaximumFrameLatency,
2025 IDirect3DDevice9ExImpl_GetMaximumFrameLatency,
2026 IDirect3DDevice9ExImpl_CheckdeviceState,
2027 IDirect3DDevice9ExImpl_CreateRenderTargetEx,
2028 IDirect3DDevice9ExImpl_CreateOffscreenPlainSurfaceEx,
2029 IDirect3DDevice9ExImpl_CreateDepthStencilSurfaceEx,
2030 IDirect3DDevice9ExImpl_ResetEx,
2031 IDirect3DDevice9ExImpl_GetDisplayModeEx
2034 /* IWineD3DDeviceParent IUnknown methods */
2036 static inline struct IDirect3DDevice9Impl *device_from_device_parent(IWineD3DDeviceParent *iface)
2038 return (struct IDirect3DDevice9Impl *)((char*)iface
2039 - FIELD_OFFSET(struct IDirect3DDevice9Impl, device_parent_vtbl));
2042 static HRESULT STDMETHODCALLTYPE device_parent_QueryInterface(IWineD3DDeviceParent *iface, REFIID riid, void **object)
2044 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
2045 return IDirect3DDevice9Impl_QueryInterface((IDirect3DDevice9Ex *)This, riid, object);
2048 static ULONG STDMETHODCALLTYPE device_parent_AddRef(IWineD3DDeviceParent *iface)
2050 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
2051 return IDirect3DDevice9Impl_AddRef((IDirect3DDevice9Ex *)This);
2054 static ULONG STDMETHODCALLTYPE device_parent_Release(IWineD3DDeviceParent *iface)
2056 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
2057 return IDirect3DDevice9Impl_Release((IDirect3DDevice9Ex *)This);
2060 /* IWineD3DDeviceParent methods */
2062 static void STDMETHODCALLTYPE device_parent_WineD3DDeviceCreated(IWineD3DDeviceParent *iface, IWineD3DDevice *device)
2064 TRACE("iface %p, device %p\n", iface, device);
2067 static HRESULT STDMETHODCALLTYPE device_parent_CreateSurface(IWineD3DDeviceParent *iface,
2068 IUnknown *superior, UINT width, UINT height, WINED3DFORMAT format, DWORD usage,
2069 WINED3DPOOL pool, UINT level, WINED3DCUBEMAP_FACES face, IWineD3DSurface **surface)
2071 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
2072 IDirect3DSurface9Impl *d3d_surface;
2073 BOOL lockable = TRUE;
2076 TRACE("iface %p, superior %p, width %u, height %u, format %#x, usage %#x,\n"
2077 "\tpool %#x, level %u, face %u, surface %p\n",
2078 iface, superior, width, height, format, usage, pool, level, face, surface);
2080 if (pool == WINED3DPOOL_DEFAULT && !(usage & D3DUSAGE_DYNAMIC))
2083 hr = IDirect3DDevice9Impl_CreateSurface((IDirect3DDevice9Ex *)This, width, height,
2084 d3dformat_from_wined3dformat(format), lockable, FALSE /* Discard */, level,
2085 (IDirect3DSurface9 **)&d3d_surface, usage, pool, D3DMULTISAMPLE_NONE, 0 /* MultisampleQuality */);
2088 ERR("(%p) CreateSurface failed, returning %#x\n", iface, hr);
2092 *surface = d3d_surface->wineD3DSurface;
2093 IWineD3DSurface_AddRef(*surface);
2095 d3d_surface->container = superior;
2096 IDirect3DDevice9Ex_Release(d3d_surface->parentDevice);
2097 d3d_surface->parentDevice = NULL;
2099 IDirect3DSurface9_Release((IDirect3DSurface9 *)d3d_surface);
2100 d3d_surface->forwardReference = superior;
2105 static HRESULT STDMETHODCALLTYPE device_parent_CreateRenderTarget(IWineD3DDeviceParent *iface,
2106 IUnknown *superior, UINT width, UINT height, WINED3DFORMAT format, WINED3DMULTISAMPLE_TYPE multisample_type,
2107 DWORD multisample_quality, BOOL lockable, IWineD3DSurface **surface)
2109 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
2110 IDirect3DSurface9Impl *d3d_surface;
2113 TRACE("iface %p, superior %p, width %u, height %u, format %#x, multisample_type %#x,\n"
2114 "\tmultisample_quality %u, lockable %u, surface %p\n",
2115 iface, superior, width, height, format, multisample_type, multisample_quality, lockable, surface);
2117 hr = IDirect3DDevice9Impl_CreateRenderTarget((IDirect3DDevice9Ex *)This, width, height,
2118 d3dformat_from_wined3dformat(format), multisample_type, multisample_quality, lockable,
2119 (IDirect3DSurface9 **)&d3d_surface, NULL);
2122 ERR("(%p) CreateRenderTarget failed, returning %#x\n", iface, hr);
2126 *surface = d3d_surface->wineD3DSurface;
2127 IWineD3DSurface_AddRef(*surface);
2129 d3d_surface->container = superior;
2130 /* Implicit surfaces are created with an refcount of 0 */
2131 IDirect3DSurface9_Release((IDirect3DSurface9 *)d3d_surface);
2136 static HRESULT STDMETHODCALLTYPE device_parent_CreateDepthStencilSurface(IWineD3DDeviceParent *iface,
2137 IUnknown *superior, UINT width, UINT height, WINED3DFORMAT format, WINED3DMULTISAMPLE_TYPE multisample_type,
2138 DWORD multisample_quality, BOOL discard, IWineD3DSurface **surface)
2140 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
2141 IDirect3DSurface9Impl *d3d_surface;
2144 TRACE("iface %p, superior %p, width %u, height %u, format %#x, multisample_type %#x,\n"
2145 "\tmultisample_quality %u, discard %u, surface %p\n",
2146 iface, superior, width, height, format, multisample_type, multisample_quality, discard, surface);
2148 hr = IDirect3DDevice9Impl_CreateDepthStencilSurface((IDirect3DDevice9Ex *)This, width, height,
2149 d3dformat_from_wined3dformat(format), multisample_type, multisample_quality, discard,
2150 (IDirect3DSurface9 **)&d3d_surface, NULL);
2153 ERR("(%p) CreateDepthStencilSurface failed, returning %#x\n", iface, hr);
2157 *surface = d3d_surface->wineD3DSurface;
2158 IWineD3DSurface_AddRef(*surface);
2159 d3d_surface->container = (IUnknown *)This;
2160 /* Implicit surfaces are created with an refcount of 0 */
2161 IDirect3DSurface9_Release((IDirect3DSurface9 *)d3d_surface);
2166 static HRESULT STDMETHODCALLTYPE device_parent_CreateVolume(IWineD3DDeviceParent *iface,
2167 IUnknown *superior, UINT width, UINT height, UINT depth, WINED3DFORMAT format,
2168 WINED3DPOOL pool, DWORD usage, IWineD3DVolume **volume)
2170 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
2171 IDirect3DVolume9Impl *object;
2174 TRACE("iface %p, superior %p, width %u, height %u, depth %u, format %#x, pool %#x, usage %#x, volume %p\n",
2175 iface, superior, width, height, depth, format, pool, usage, volume);
2177 /* Allocate the storage for the device */
2178 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2181 FIXME("Allocation of memory failed\n");
2183 return D3DERR_OUTOFVIDEOMEMORY;
2186 hr = volume_init(object, This, width, height, depth, usage, format, pool);
2189 WARN("Failed to initialize volume, hr %#x.\n", hr);
2190 HeapFree(GetProcessHeap(), 0, object);
2194 *volume = object->wineD3DVolume;
2195 IWineD3DVolume_AddRef(*volume);
2196 IDirect3DVolume9_Release((IDirect3DVolume9 *)object);
2198 object->container = superior;
2199 object->forwardReference = superior;
2201 TRACE("(%p) Created volume %p\n", iface, object);
2206 static HRESULT STDMETHODCALLTYPE device_parent_CreateSwapChain(IWineD3DDeviceParent *iface,
2207 WINED3DPRESENT_PARAMETERS *present_parameters, IWineD3DSwapChain **swapchain)
2209 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
2210 IDirect3DSwapChain9Impl *d3d_swapchain;
2211 D3DPRESENT_PARAMETERS local_parameters;
2214 TRACE("iface %p, present_parameters %p, swapchain %p\n", iface, present_parameters, swapchain);
2216 /* Copy the presentation parameters */
2217 local_parameters.BackBufferWidth = present_parameters->BackBufferWidth;
2218 local_parameters.BackBufferHeight = present_parameters->BackBufferHeight;
2219 local_parameters.BackBufferFormat = d3dformat_from_wined3dformat(present_parameters->BackBufferFormat);
2220 local_parameters.BackBufferCount = present_parameters->BackBufferCount;
2221 local_parameters.MultiSampleType = present_parameters->MultiSampleType;
2222 local_parameters.MultiSampleQuality = present_parameters->MultiSampleQuality;
2223 local_parameters.SwapEffect = present_parameters->SwapEffect;
2224 local_parameters.hDeviceWindow = present_parameters->hDeviceWindow;
2225 local_parameters.Windowed = present_parameters->Windowed;
2226 local_parameters.EnableAutoDepthStencil = present_parameters->EnableAutoDepthStencil;
2227 local_parameters.AutoDepthStencilFormat = d3dformat_from_wined3dformat(present_parameters->AutoDepthStencilFormat);
2228 local_parameters.Flags = present_parameters->Flags;
2229 local_parameters.FullScreen_RefreshRateInHz = present_parameters->FullScreen_RefreshRateInHz;
2230 local_parameters.PresentationInterval = present_parameters->PresentationInterval;
2232 hr = IDirect3DDevice9Impl_CreateAdditionalSwapChain((IDirect3DDevice9Ex *)This,
2233 &local_parameters, (IDirect3DSwapChain9 **)&d3d_swapchain);
2236 ERR("(%p) CreateAdditionalSwapChain failed, returning %#x\n", iface, hr);
2241 *swapchain = d3d_swapchain->wineD3DSwapChain;
2242 d3d_swapchain->isImplicit = TRUE;
2243 /* Implicit swap chains are created with an refcount of 0 */
2244 IDirect3DSwapChain9_Release((IDirect3DSwapChain9 *)d3d_swapchain);
2246 /* Copy back the presentation parameters */
2247 present_parameters->BackBufferWidth = local_parameters.BackBufferWidth;
2248 present_parameters->BackBufferHeight = local_parameters.BackBufferHeight;
2249 present_parameters->BackBufferFormat = wined3dformat_from_d3dformat(local_parameters.BackBufferFormat);
2250 present_parameters->BackBufferCount = local_parameters.BackBufferCount;
2251 present_parameters->MultiSampleType = local_parameters.MultiSampleType;
2252 present_parameters->MultiSampleQuality = local_parameters.MultiSampleQuality;
2253 present_parameters->SwapEffect = local_parameters.SwapEffect;
2254 present_parameters->hDeviceWindow = local_parameters.hDeviceWindow;
2255 present_parameters->Windowed = local_parameters.Windowed;
2256 present_parameters->EnableAutoDepthStencil = local_parameters.EnableAutoDepthStencil;
2257 present_parameters->AutoDepthStencilFormat = wined3dformat_from_d3dformat(local_parameters.AutoDepthStencilFormat);
2258 present_parameters->Flags = local_parameters.Flags;
2259 present_parameters->FullScreen_RefreshRateInHz = local_parameters.FullScreen_RefreshRateInHz;
2260 present_parameters->PresentationInterval = local_parameters.PresentationInterval;
2265 const IWineD3DDeviceParentVtbl d3d9_wined3d_device_parent_vtbl =
2267 /* IUnknown methods */
2268 device_parent_QueryInterface,
2269 device_parent_AddRef,
2270 device_parent_Release,
2271 /* IWineD3DDeviceParent methods */
2272 device_parent_WineD3DDeviceCreated,
2273 device_parent_CreateSurface,
2274 device_parent_CreateRenderTarget,
2275 device_parent_CreateDepthStencilSurface,
2276 device_parent_CreateVolume,
2277 device_parent_CreateSwapChain,