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(enum wined3d_format_id 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_B8G8R8_UNORM: return D3DFMT_R8G8B8;
39 case WINED3DFMT_B8G8R8A8_UNORM: return D3DFMT_A8R8G8B8;
40 case WINED3DFMT_B8G8R8X8_UNORM: return D3DFMT_X8R8G8B8;
41 case WINED3DFMT_B5G6R5_UNORM: return D3DFMT_R5G6B5;
42 case WINED3DFMT_B5G5R5X1_UNORM: return D3DFMT_X1R5G5B5;
43 case WINED3DFMT_B5G5R5A1_UNORM: return D3DFMT_A1R5G5B5;
44 case WINED3DFMT_B4G4R4A4_UNORM: return D3DFMT_A4R4G4B4;
45 case WINED3DFMT_B2G3R3_UNORM: return D3DFMT_R3G3B2;
46 case WINED3DFMT_A8_UNORM: return D3DFMT_A8;
47 case WINED3DFMT_B2G3R3A8_UNORM: return D3DFMT_A8R3G3B2;
48 case WINED3DFMT_B4G4R4X4_UNORM: return D3DFMT_X4R4G4B4;
49 case WINED3DFMT_R10G10B10A2_UNORM: return D3DFMT_A2B10G10R10;
50 case WINED3DFMT_R8G8B8A8_UNORM: return D3DFMT_A8B8G8R8;
51 case WINED3DFMT_R8G8B8X8_UNORM: return D3DFMT_X8B8G8R8;
52 case WINED3DFMT_R16G16_UNORM: return D3DFMT_G16R16;
53 case WINED3DFMT_B10G10R10A2_UNORM: return D3DFMT_A2R10G10B10;
54 case WINED3DFMT_R16G16B16A16_UNORM: return D3DFMT_A16B16G16R16;
55 case WINED3DFMT_P8_UINT_A8_UNORM: return D3DFMT_A8P8;
56 case WINED3DFMT_P8_UINT: return D3DFMT_P8;
57 case WINED3DFMT_L8_UNORM: return D3DFMT_L8;
58 case WINED3DFMT_L8A8_UNORM: return D3DFMT_A8L8;
59 case WINED3DFMT_L4A4_UNORM: return D3DFMT_A4L4;
60 case WINED3DFMT_R8G8_SNORM: return D3DFMT_V8U8;
61 case WINED3DFMT_R5G5_SNORM_L6_UNORM: return D3DFMT_L6V5U5;
62 case WINED3DFMT_R8G8_SNORM_L8X8_UNORM: return D3DFMT_X8L8V8U8;
63 case WINED3DFMT_R8G8B8A8_SNORM: return D3DFMT_Q8W8V8U8;
64 case WINED3DFMT_R16G16_SNORM: return D3DFMT_V16U16;
65 case WINED3DFMT_R10G10B10_SNORM_A2_UNORM: return D3DFMT_A2W10V10U10;
66 case WINED3DFMT_D16_LOCKABLE: return D3DFMT_D16_LOCKABLE;
67 case WINED3DFMT_D32_UNORM: return D3DFMT_D32;
68 case WINED3DFMT_S1_UINT_D15_UNORM: return D3DFMT_D15S1;
69 case WINED3DFMT_D24_UNORM_S8_UINT: return D3DFMT_D24S8;
70 case WINED3DFMT_X8D24_UNORM: return D3DFMT_D24X8;
71 case WINED3DFMT_S4X4_UINT_D24_UNORM: return D3DFMT_D24X4S4;
72 case WINED3DFMT_D16_UNORM: return D3DFMT_D16;
73 case WINED3DFMT_L16_UNORM: return D3DFMT_L16;
74 case WINED3DFMT_D32_FLOAT: return D3DFMT_D32F_LOCKABLE;
75 case WINED3DFMT_S8_UINT_D24_FLOAT: 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_R8G8_SNORM_Cx: return D3DFMT_CxV8U8;
88 FIXME("Unhandled wined3d format %#x.\n", format);
89 return D3DFMT_UNKNOWN;
93 enum wined3d_format_id 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_B8G8R8_UNORM;
104 case D3DFMT_A8R8G8B8: return WINED3DFMT_B8G8R8A8_UNORM;
105 case D3DFMT_X8R8G8B8: return WINED3DFMT_B8G8R8X8_UNORM;
106 case D3DFMT_R5G6B5: return WINED3DFMT_B5G6R5_UNORM;
107 case D3DFMT_X1R5G5B5: return WINED3DFMT_B5G5R5X1_UNORM;
108 case D3DFMT_A1R5G5B5: return WINED3DFMT_B5G5R5A1_UNORM;
109 case D3DFMT_A4R4G4B4: return WINED3DFMT_B4G4R4A4_UNORM;
110 case D3DFMT_R3G3B2: return WINED3DFMT_B2G3R3_UNORM;
111 case D3DFMT_A8: return WINED3DFMT_A8_UNORM;
112 case D3DFMT_A8R3G3B2: return WINED3DFMT_B2G3R3A8_UNORM;
113 case D3DFMT_X4R4G4B4: return WINED3DFMT_B4G4R4X4_UNORM;
114 case D3DFMT_A2B10G10R10: return WINED3DFMT_R10G10B10A2_UNORM;
115 case D3DFMT_A8B8G8R8: return WINED3DFMT_R8G8B8A8_UNORM;
116 case D3DFMT_X8B8G8R8: return WINED3DFMT_R8G8B8X8_UNORM;
117 case D3DFMT_G16R16: return WINED3DFMT_R16G16_UNORM;
118 case D3DFMT_A2R10G10B10: return WINED3DFMT_B10G10R10A2_UNORM;
119 case D3DFMT_A16B16G16R16: return WINED3DFMT_R16G16B16A16_UNORM;
120 case D3DFMT_A8P8: return WINED3DFMT_P8_UINT_A8_UNORM;
121 case D3DFMT_P8: return WINED3DFMT_P8_UINT;
122 case D3DFMT_L8: return WINED3DFMT_L8_UNORM;
123 case D3DFMT_A8L8: return WINED3DFMT_L8A8_UNORM;
124 case D3DFMT_A4L4: return WINED3DFMT_L4A4_UNORM;
125 case D3DFMT_V8U8: return WINED3DFMT_R8G8_SNORM;
126 case D3DFMT_L6V5U5: return WINED3DFMT_R5G5_SNORM_L6_UNORM;
127 case D3DFMT_X8L8V8U8: return WINED3DFMT_R8G8_SNORM_L8X8_UNORM;
128 case D3DFMT_Q8W8V8U8: return WINED3DFMT_R8G8B8A8_SNORM;
129 case D3DFMT_V16U16: return WINED3DFMT_R16G16_SNORM;
130 case D3DFMT_A2W10V10U10: return WINED3DFMT_R10G10B10_SNORM_A2_UNORM;
131 case D3DFMT_D16_LOCKABLE: return WINED3DFMT_D16_LOCKABLE;
132 case D3DFMT_D32: return WINED3DFMT_D32_UNORM;
133 case D3DFMT_D15S1: return WINED3DFMT_S1_UINT_D15_UNORM;
134 case D3DFMT_D24S8: return WINED3DFMT_D24_UNORM_S8_UINT;
135 case D3DFMT_D24X8: return WINED3DFMT_X8D24_UNORM;
136 case D3DFMT_D24X4S4: return WINED3DFMT_S4X4_UINT_D24_UNORM;
137 case D3DFMT_D16: return WINED3DFMT_D16_UNORM;
138 case D3DFMT_L16: return WINED3DFMT_L16_UNORM;
139 case D3DFMT_D32F_LOCKABLE: return WINED3DFMT_D32_FLOAT;
140 case D3DFMT_D24FS8: return WINED3DFMT_S8_UINT_D24_FLOAT;
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_R8G8_SNORM_Cx;
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 static inline IDirect3DDevice9Impl *impl_from_IDirect3DDevice9Ex(IDirect3DDevice9Ex *iface)
186 return CONTAINING_RECORD(iface, IDirect3DDevice9Impl, IDirect3DDevice9Ex_iface);
189 static HRESULT WINAPI IDirect3DDevice9Impl_QueryInterface(IDirect3DDevice9Ex *iface, REFIID riid,
192 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
194 IDirect3D9Impl *d3dimpl;
196 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
198 if (IsEqualGUID(riid, &IID_IUnknown)
199 || IsEqualGUID(riid, &IID_IDirect3DDevice9)) {
200 IDirect3DDevice9Ex_AddRef(iface);
202 TRACE("Returning IDirect3DDevice9 interface at %p\n", *ppobj);
204 } else if(IsEqualGUID(riid, &IID_IDirect3DDevice9Ex)) {
205 /* Find out if the creating d3d9 interface was created with Direct3DCreate9Ex.
206 * It doesn't matter with which function the device was created.
208 IDirect3DDevice9_GetDirect3D(iface, &d3d);
209 d3dimpl = (IDirect3D9Impl *) d3d;
211 if(d3dimpl->extended) {
213 IDirect3DDevice9Ex_AddRef((IDirect3DDevice9Ex *) *ppobj);
214 IDirect3D9_Release(d3d);
215 TRACE("Returning IDirect3DDevice9Ex interface at %p\n", *ppobj);
218 WARN("IDirect3D9 instance wasn't created with CreateDirect3D9Ex, returning E_NOINTERFACE\n");
219 IDirect3D9_Release(d3d);
221 return E_NOINTERFACE;
225 if (IsEqualGUID(riid, &IID_IWineD3DDeviceParent))
227 IUnknown_AddRef((IUnknown *)&This->device_parent_vtbl);
228 *ppobj = &This->device_parent_vtbl;
232 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
234 return E_NOINTERFACE;
237 static ULONG WINAPI IDirect3DDevice9Impl_AddRef(IDirect3DDevice9Ex *iface)
239 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
240 ULONG ref = InterlockedIncrement(&This->ref);
242 TRACE("%p increasing refcount to %u.\n", iface, ref);
247 static ULONG WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_Release(IDirect3DDevice9Ex *iface)
249 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
252 if (This->inDestruction) return 0;
253 ref = InterlockedDecrement(&This->ref);
255 TRACE("%p decreasing refcount to %u.\n", iface, ref);
259 This->inDestruction = TRUE;
261 wined3d_mutex_lock();
262 for(i = 0; i < This->numConvertedDecls; i++) {
263 /* Unless Wine is buggy or the app has a bug the refcount will be 0, because decls hold a reference to the
266 IDirect3DVertexDeclaration9Impl_Destroy(This->convertedDecls[i]);
268 HeapFree(GetProcessHeap(), 0, This->convertedDecls);
270 IWineD3DDevice_Uninit3D(This->WineD3DDevice);
271 IWineD3DDevice_ReleaseFocusWindow(This->WineD3DDevice);
272 IWineD3DDevice_Release(This->WineD3DDevice);
273 wined3d_mutex_unlock();
275 HeapFree(GetProcessHeap(), 0, This);
280 static HRESULT WINAPI IDirect3DDevice9Impl_TestCooperativeLevel(IDirect3DDevice9Ex *iface)
282 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
284 TRACE("iface %p.\n", iface);
288 TRACE("D3D9 device is marked not reset.\n");
289 return D3DERR_DEVICENOTRESET;
295 static UINT WINAPI IDirect3DDevice9Impl_GetAvailableTextureMem(IDirect3DDevice9Ex *iface)
297 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
300 TRACE("iface %p.\n", iface);
302 wined3d_mutex_lock();
303 hr = IWineD3DDevice_GetAvailableTextureMem(This->WineD3DDevice);
304 wined3d_mutex_unlock();
309 static HRESULT WINAPI IDirect3DDevice9Impl_EvictManagedResources(IDirect3DDevice9Ex *iface)
311 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
314 TRACE("iface %p.\n", iface);
316 wined3d_mutex_lock();
317 hr = IWineD3DDevice_EvictManagedResources(This->WineD3DDevice);
318 wined3d_mutex_unlock();
323 static HRESULT WINAPI IDirect3DDevice9Impl_GetDirect3D(IDirect3DDevice9Ex *iface,
326 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
327 struct wined3d *wined3d;
330 TRACE("iface %p, d3d9 %p.\n", iface, ppD3D9);
332 if (NULL == ppD3D9) {
333 return D3DERR_INVALIDCALL;
336 wined3d_mutex_lock();
337 hr = IWineD3DDevice_GetDirect3D(This->WineD3DDevice, &wined3d);
338 if (hr == D3D_OK && wined3d)
340 *ppD3D9 = wined3d_get_parent(wined3d);
341 IDirect3D9_AddRef(*ppD3D9);
342 wined3d_decref(wined3d);
346 FIXME("Call to IWineD3DDevice_GetDirect3D failed\n");
349 TRACE("(%p) returning %p\n", This, *ppD3D9);
350 wined3d_mutex_unlock();
355 static HRESULT WINAPI IDirect3DDevice9Impl_GetDeviceCaps(IDirect3DDevice9Ex *iface, D3DCAPS9 *pCaps)
357 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
358 HRESULT hrc = D3D_OK;
359 WINED3DCAPS *pWineCaps;
361 TRACE("iface %p, caps %p.\n", iface, pCaps);
364 return D3DERR_INVALIDCALL;
366 pWineCaps = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WINED3DCAPS));
367 if(pWineCaps == NULL){
368 return D3DERR_INVALIDCALL; /* well this is what MSDN says to return */
371 memset(pCaps, 0, sizeof(*pCaps));
373 wined3d_mutex_lock();
374 hrc = IWineD3DDevice_GetDeviceCaps(This->WineD3DDevice, pWineCaps);
375 wined3d_mutex_unlock();
377 WINECAPSTOD3D9CAPS(pCaps, pWineCaps)
378 HeapFree(GetProcessHeap(), 0, pWineCaps);
380 /* Some functionality is implemented in d3d9.dll, not wined3d.dll. Add the needed caps */
381 pCaps->DevCaps2 |= D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES;
385 TRACE("Returning %p %p\n", This, pCaps);
389 static HRESULT WINAPI IDirect3DDevice9Impl_GetDisplayMode(IDirect3DDevice9Ex *iface,
390 UINT iSwapChain, D3DDISPLAYMODE *pMode)
392 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
395 TRACE("iface %p, swapchain %u, mode %p.\n", iface, iSwapChain, pMode);
397 wined3d_mutex_lock();
398 hr = IWineD3DDevice_GetDisplayMode(This->WineD3DDevice, iSwapChain, (WINED3DDISPLAYMODE *) pMode);
399 wined3d_mutex_unlock();
401 if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format);
406 static HRESULT WINAPI IDirect3DDevice9Impl_GetCreationParameters(IDirect3DDevice9Ex *iface,
407 D3DDEVICE_CREATION_PARAMETERS *pParameters)
409 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
412 TRACE("iface %p, parameters %p.\n", iface, pParameters);
414 wined3d_mutex_lock();
415 hr = IWineD3DDevice_GetCreationParameters(This->WineD3DDevice, (WINED3DDEVICE_CREATION_PARAMETERS *) pParameters);
416 wined3d_mutex_unlock();
421 static HRESULT WINAPI IDirect3DDevice9Impl_SetCursorProperties(IDirect3DDevice9Ex *iface,
422 UINT XHotSpot, UINT YHotSpot, IDirect3DSurface9 *pCursorBitmap)
424 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
425 IDirect3DSurface9Impl *pSurface = (IDirect3DSurface9Impl*)pCursorBitmap;
428 TRACE("iface %p, hotspot_x %u, hotspot_y %u, bitmap %p.\n",
429 iface, XHotSpot, YHotSpot, pCursorBitmap);
433 WARN("No cursor bitmap, returning D3DERR_INVALIDCALL.\n");
434 return D3DERR_INVALIDCALL;
437 wined3d_mutex_lock();
438 hr = IWineD3DDevice_SetCursorProperties(This->WineD3DDevice, XHotSpot, YHotSpot, pSurface->wineD3DSurface);
439 wined3d_mutex_unlock();
444 static void WINAPI IDirect3DDevice9Impl_SetCursorPosition(IDirect3DDevice9Ex *iface,
445 int XScreenSpace, int YScreenSpace, DWORD Flags)
447 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
449 TRACE("iface %p, x %u, y %u, flags %#x.\n", iface, XScreenSpace, YScreenSpace, Flags);
451 wined3d_mutex_lock();
452 IWineD3DDevice_SetCursorPosition(This->WineD3DDevice, XScreenSpace, YScreenSpace, Flags);
453 wined3d_mutex_unlock();
456 static BOOL WINAPI IDirect3DDevice9Impl_ShowCursor(IDirect3DDevice9Ex *iface, BOOL bShow)
458 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
461 TRACE("iface %p, show %#x.\n", iface, bShow);
463 wined3d_mutex_lock();
464 ret = IWineD3DDevice_ShowCursor(This->WineD3DDevice, bShow);
465 wined3d_mutex_unlock();
470 static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_CreateAdditionalSwapChain(IDirect3DDevice9Ex *iface,
471 D3DPRESENT_PARAMETERS *present_parameters, IDirect3DSwapChain9 **swapchain)
473 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
474 IDirect3DSwapChain9Impl *object;
477 TRACE("iface %p, present_parameters %p, swapchain %p.\n",
478 iface, present_parameters, swapchain);
480 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
483 ERR("Failed to allocate swapchain memory.\n");
484 return E_OUTOFMEMORY;
487 hr = swapchain_init(object, This, present_parameters);
490 WARN("Failed to initialize swapchain, hr %#x.\n", hr);
491 HeapFree(GetProcessHeap(), 0, object);
495 TRACE("Created swapchain %p.\n", object);
496 *swapchain = (IDirect3DSwapChain9 *)object;
501 static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_GetSwapChain(IDirect3DDevice9Ex *iface,
502 UINT swapchain_idx, IDirect3DSwapChain9 **swapchain)
504 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
505 struct wined3d_swapchain *wined3d_swapchain = NULL;
508 TRACE("iface %p, swapchain_idx %u, swapchain %p.\n", iface, swapchain_idx, swapchain);
510 wined3d_mutex_lock();
511 hr = IWineD3DDevice_GetSwapChain(This->WineD3DDevice, swapchain_idx, &wined3d_swapchain);
512 if (SUCCEEDED(hr) && wined3d_swapchain)
514 *swapchain = wined3d_swapchain_get_parent(wined3d_swapchain);
515 IDirect3DSwapChain9_AddRef(*swapchain);
516 wined3d_swapchain_decref(wined3d_swapchain);
522 wined3d_mutex_unlock();
527 static UINT WINAPI IDirect3DDevice9Impl_GetNumberOfSwapChains(IDirect3DDevice9Ex *iface)
529 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
532 TRACE("iface %p.\n", iface);
534 wined3d_mutex_lock();
535 count = IWineD3DDevice_GetNumberOfSwapChains(This->WineD3DDevice);
536 wined3d_mutex_unlock();
541 static HRESULT WINAPI reset_enum_callback(struct wined3d_resource *resource, void *data)
543 BOOL *resources_ok = data;
544 D3DRESOURCETYPE type;
546 D3DSURFACE_DESC surface_desc;
547 D3DVOLUME_DESC volume_desc;
548 D3DINDEXBUFFER_DESC index_desc;
549 D3DVERTEXBUFFER_DESC vertex_desc;
551 IDirect3DResource9 *parent;
553 parent = wined3d_resource_get_parent(resource);
554 type = IDirect3DResource9_GetType(parent);
556 case D3DRTYPE_SURFACE:
557 IDirect3DSurface9_GetDesc((IDirect3DSurface9 *)parent, &surface_desc);
558 pool = surface_desc.Pool;
561 case D3DRTYPE_VOLUME:
562 IDirect3DVolume9_GetDesc((IDirect3DVolume9 *)parent, &volume_desc);
563 pool = volume_desc.Pool;
566 case D3DRTYPE_INDEXBUFFER:
567 IDirect3DIndexBuffer9_GetDesc((IDirect3DIndexBuffer9 *) parent, &index_desc);
568 pool = index_desc.Pool;
571 case D3DRTYPE_VERTEXBUFFER:
572 IDirect3DVertexBuffer9_GetDesc((IDirect3DVertexBuffer9 *)parent, &vertex_desc);
573 pool = vertex_desc.Pool;
576 /* No need to check for textures. If there is a D3DPOOL_DEFAULT texture, there
577 * is a D3DPOOL_DEFAULT surface or volume as well
580 pool = WINED3DPOOL_SCRATCH; /* a harmless pool */
584 if (pool == WINED3DPOOL_DEFAULT)
586 IDirect3DResource9_AddRef(parent);
587 if (IUnknown_Release(parent) == 0)
589 TRACE("Parent %p is an implicit resource with ref 0\n", parent);
591 WARN("Resource %p(wineD3D %p) with pool D3DPOOL_DEFAULT blocks the Reset call\n", parent, resource);
593 *resources_ok = FALSE;
600 static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_Reset(IDirect3DDevice9Ex *iface,
601 D3DPRESENT_PARAMETERS *pPresentationParameters)
603 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
604 WINED3DPRESENT_PARAMETERS localParameters;
606 BOOL resources_ok = TRUE;
609 TRACE("iface %p, present_parameters %p.\n", iface, pPresentationParameters);
611 /* Reset states that hold a COM object. WineD3D holds an internal reference to set objects, because
612 * such objects can still be used for rendering after their external d3d9 object has been destroyed.
613 * These objects must not be enumerated. Unsetting them tells WineD3D that the application will not
614 * make use of the hidden reference and destroys the objects.
616 * Unsetting them is no problem, because the states are supposed to be reset anyway. If the validation
617 * below fails, the device is considered "lost", and _Reset and _Release are the only allowed calls
619 wined3d_mutex_lock();
620 IWineD3DDevice_SetIndexBuffer(This->WineD3DDevice, NULL, WINED3DFMT_UNKNOWN);
621 for(i = 0; i < 16; i++) {
622 IWineD3DDevice_SetStreamSource(This->WineD3DDevice, i, NULL, 0, 0);
624 for(i = 0; i < 16; i++) {
625 IWineD3DDevice_SetTexture(This->WineD3DDevice, i, NULL);
628 IWineD3DDevice_EnumResources(This->WineD3DDevice, reset_enum_callback, &resources_ok);
630 WARN("The application is holding D3DPOOL_DEFAULT resources, rejecting reset\n");
631 This->notreset = TRUE;
632 wined3d_mutex_unlock();
634 return D3DERR_INVALIDCALL;
637 localParameters.BackBufferWidth = pPresentationParameters->BackBufferWidth;
638 localParameters.BackBufferHeight = pPresentationParameters->BackBufferHeight;
639 localParameters.BackBufferFormat = wined3dformat_from_d3dformat(pPresentationParameters->BackBufferFormat);
640 localParameters.BackBufferCount = pPresentationParameters->BackBufferCount;
641 localParameters.MultiSampleType = pPresentationParameters->MultiSampleType;
642 localParameters.MultiSampleQuality = pPresentationParameters->MultiSampleQuality;
643 localParameters.SwapEffect = pPresentationParameters->SwapEffect;
644 localParameters.hDeviceWindow = pPresentationParameters->hDeviceWindow;
645 localParameters.Windowed = pPresentationParameters->Windowed;
646 localParameters.EnableAutoDepthStencil = pPresentationParameters->EnableAutoDepthStencil;
647 localParameters.AutoDepthStencilFormat = wined3dformat_from_d3dformat(pPresentationParameters->AutoDepthStencilFormat);
648 localParameters.Flags = pPresentationParameters->Flags;
649 localParameters.FullScreen_RefreshRateInHz = pPresentationParameters->FullScreen_RefreshRateInHz;
650 localParameters.PresentationInterval = pPresentationParameters->PresentationInterval;
651 localParameters.AutoRestoreDisplayMode = TRUE;
653 hr = IWineD3DDevice_Reset(This->WineD3DDevice, &localParameters);
655 This->notreset = TRUE;
657 pPresentationParameters->BackBufferWidth = localParameters.BackBufferWidth;
658 pPresentationParameters->BackBufferHeight = localParameters.BackBufferHeight;
659 pPresentationParameters->BackBufferFormat = d3dformat_from_wined3dformat(localParameters.BackBufferFormat);
660 pPresentationParameters->BackBufferCount = localParameters.BackBufferCount;
661 pPresentationParameters->MultiSampleType = localParameters.MultiSampleType;
662 pPresentationParameters->MultiSampleQuality = localParameters.MultiSampleQuality;
663 pPresentationParameters->SwapEffect = localParameters.SwapEffect;
664 pPresentationParameters->hDeviceWindow = localParameters.hDeviceWindow;
665 pPresentationParameters->Windowed = localParameters.Windowed;
666 pPresentationParameters->EnableAutoDepthStencil = localParameters.EnableAutoDepthStencil;
667 pPresentationParameters->AutoDepthStencilFormat = d3dformat_from_wined3dformat(localParameters.AutoDepthStencilFormat);
668 pPresentationParameters->Flags = localParameters.Flags;
669 pPresentationParameters->FullScreen_RefreshRateInHz = localParameters.FullScreen_RefreshRateInHz;
670 pPresentationParameters->PresentationInterval = localParameters.PresentationInterval;
672 This->notreset = FALSE;
675 wined3d_mutex_unlock();
680 static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_Present(IDirect3DDevice9Ex *iface,
681 const RECT *pSourceRect, const RECT *pDestRect, HWND hDestWindowOverride,
682 const RGNDATA *pDirtyRegion)
684 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
687 TRACE("iface %p, src_rect %p, dst_rect %p, dst_window_override %p, dirty_region %p.\n",
688 iface, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
690 wined3d_mutex_lock();
691 hr = IWineD3DDevice_Present(This->WineD3DDevice, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
692 wined3d_mutex_unlock();
697 static HRESULT WINAPI IDirect3DDevice9Impl_GetBackBuffer(IDirect3DDevice9Ex *iface,
698 UINT iSwapChain, UINT BackBuffer, D3DBACKBUFFER_TYPE Type, IDirect3DSurface9 **ppBackBuffer)
700 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
701 IWineD3DSurface *retSurface = NULL;
704 TRACE("iface %p, swapchain %u, backbuffer_idx %u, backbuffer_type %#x, backbuffer %p.\n",
705 iface, iSwapChain, BackBuffer, Type, ppBackBuffer);
707 wined3d_mutex_lock();
708 hr = IWineD3DDevice_GetBackBuffer(This->WineD3DDevice, iSwapChain,
709 BackBuffer, (WINED3DBACKBUFFER_TYPE) Type, &retSurface);
710 if (SUCCEEDED(hr) && retSurface && ppBackBuffer)
712 *ppBackBuffer = IWineD3DSurface_GetParent(retSurface);
713 IDirect3DSurface9_AddRef(*ppBackBuffer);
714 IWineD3DSurface_Release(retSurface);
716 wined3d_mutex_unlock();
720 static HRESULT WINAPI IDirect3DDevice9Impl_GetRasterStatus(IDirect3DDevice9Ex *iface,
721 UINT iSwapChain, D3DRASTER_STATUS *pRasterStatus)
723 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
726 TRACE("iface %p, swapchain %u, raster_status %p.\n", iface, iSwapChain, pRasterStatus);
728 wined3d_mutex_lock();
729 hr = IWineD3DDevice_GetRasterStatus(This->WineD3DDevice, iSwapChain, (WINED3DRASTER_STATUS *) pRasterStatus);
730 wined3d_mutex_unlock();
735 static HRESULT WINAPI IDirect3DDevice9Impl_SetDialogBoxMode(IDirect3DDevice9Ex *iface,
738 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
741 TRACE("iface %p, enable %#x.\n", iface, bEnableDialogs);
743 wined3d_mutex_lock();
744 hr = IWineD3DDevice_SetDialogBoxMode(This->WineD3DDevice, bEnableDialogs);
745 wined3d_mutex_unlock();
750 static void WINAPI IDirect3DDevice9Impl_SetGammaRamp(IDirect3DDevice9Ex *iface, UINT iSwapChain,
751 DWORD Flags, const D3DGAMMARAMP *pRamp)
753 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
755 TRACE("iface %p, swapchain %u, flags %#x, ramp %p.\n", iface, iSwapChain, Flags, pRamp);
757 /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
758 wined3d_mutex_lock();
759 IWineD3DDevice_SetGammaRamp(This->WineD3DDevice, iSwapChain, Flags, (CONST WINED3DGAMMARAMP *)pRamp);
760 wined3d_mutex_unlock();
763 static void WINAPI IDirect3DDevice9Impl_GetGammaRamp(IDirect3DDevice9Ex *iface, UINT iSwapChain,
766 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
768 TRACE("iface %p, swapchain %u, ramp %p.\n", iface, iSwapChain, pRamp);
770 /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
771 wined3d_mutex_lock();
772 IWineD3DDevice_GetGammaRamp(This->WineD3DDevice, iSwapChain, (WINED3DGAMMARAMP *) pRamp);
773 wined3d_mutex_unlock();
776 static HRESULT WINAPI IDirect3DDevice9Impl_CreateTexture(IDirect3DDevice9Ex *iface,
777 UINT width, UINT height, UINT levels, DWORD usage, D3DFORMAT format,
778 D3DPOOL pool, IDirect3DTexture9 **texture, HANDLE *shared_handle)
780 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
781 IDirect3DTexture9Impl *object;
784 TRACE("iface %p, width %u, height %u, levels %u, usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n",
785 iface, width, height, levels, usage, format, pool, texture, shared_handle);
787 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
790 ERR("Failed to allocate texture memory.\n");
791 return D3DERR_OUTOFVIDEOMEMORY;
794 hr = texture_init(object, This, width, height, levels, usage, format, pool);
797 WARN("Failed to initialize texture, hr %#x.\n", hr);
798 HeapFree(GetProcessHeap(), 0, object);
802 TRACE("Created texture %p.\n", object);
803 *texture = &object->IDirect3DTexture9_iface;
808 static HRESULT WINAPI IDirect3DDevice9Impl_CreateVolumeTexture(IDirect3DDevice9Ex *iface,
809 UINT width, UINT height, UINT depth, UINT levels, DWORD usage, D3DFORMAT format,
810 D3DPOOL pool, IDirect3DVolumeTexture9 **texture, HANDLE *shared_handle)
812 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
813 IDirect3DVolumeTexture9Impl *object;
816 TRACE("iface %p, width %u, height %u, depth %u, levels %u\n",
817 iface, width, height, depth, levels);
818 TRACE("usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n",
819 usage, format, pool, texture, shared_handle);
821 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
824 ERR("Failed to allocate volume texture memory.\n");
825 return D3DERR_OUTOFVIDEOMEMORY;
828 hr = volumetexture_init(object, This, width, height, depth, levels, usage, format, pool);
831 WARN("Failed to initialize volume texture, hr %#x.\n", hr);
832 HeapFree(GetProcessHeap(), 0, object);
836 TRACE("Created volume texture %p.\n", object);
837 *texture = &object->IDirect3DVolumeTexture9_iface;
842 static HRESULT WINAPI IDirect3DDevice9Impl_CreateCubeTexture(IDirect3DDevice9Ex *iface,
843 UINT edge_length, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool,
844 IDirect3DCubeTexture9 **texture, HANDLE *shared_handle)
846 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
847 IDirect3DCubeTexture9Impl *object;
850 TRACE("iface %p, edge_length %u, levels %u, usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n",
851 iface, edge_length, levels, usage, format, pool, texture, shared_handle);
853 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
856 ERR("Failed to allocate cube texture memory.\n");
857 return D3DERR_OUTOFVIDEOMEMORY;
860 hr = cubetexture_init(object, This, edge_length, levels, usage, format, pool);
863 WARN("Failed to initialize cube texture, hr %#x.\n", hr);
864 HeapFree(GetProcessHeap(), 0, object);
868 TRACE("Created cube texture %p.\n", object);
869 *texture = &object->IDirect3DCubeTexture9_iface;
874 static HRESULT WINAPI IDirect3DDevice9Impl_CreateVertexBuffer(IDirect3DDevice9Ex *iface, UINT size,
875 DWORD usage, DWORD fvf, D3DPOOL pool, IDirect3DVertexBuffer9 **buffer,
876 HANDLE *shared_handle)
878 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
879 IDirect3DVertexBuffer9Impl *object;
882 TRACE("iface %p, size %u, usage %#x, fvf %#x, pool %#x, buffer %p, shared_handle %p.\n",
883 iface, size, usage, fvf, pool, buffer, shared_handle);
885 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
888 ERR("Failed to allocate buffer memory.\n");
889 return D3DERR_OUTOFVIDEOMEMORY;
892 hr = vertexbuffer_init(object, This, size, usage, fvf, pool);
895 WARN("Failed to initialize vertex buffer, hr %#x.\n", hr);
896 HeapFree(GetProcessHeap(), 0, object);
900 TRACE("Created vertex buffer %p.\n", object);
901 *buffer = (IDirect3DVertexBuffer9 *)object;
906 static HRESULT WINAPI IDirect3DDevice9Impl_CreateIndexBuffer(IDirect3DDevice9Ex *iface, UINT size,
907 DWORD usage, D3DFORMAT format, D3DPOOL pool, IDirect3DIndexBuffer9 **buffer,
908 HANDLE *shared_handle)
910 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
911 IDirect3DIndexBuffer9Impl *object;
914 TRACE("iface %p, size %u, usage %#x, format %#x, pool %#x, buffer %p, shared_handle %p.\n",
915 iface, size, usage, format, pool, buffer, shared_handle);
917 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
920 ERR("Failed to allocate buffer memory.\n");
921 return D3DERR_OUTOFVIDEOMEMORY;
924 hr = indexbuffer_init(object, This, size, usage, format, pool);
927 WARN("Failed to initialize index buffer, hr %#x.\n", hr);
928 HeapFree(GetProcessHeap(), 0, object);
932 TRACE("Created index buffer %p.\n", object);
933 *buffer = (IDirect3DIndexBuffer9 *)object;
938 static HRESULT IDirect3DDevice9Impl_CreateSurface(IDirect3DDevice9Impl *device, UINT Width,
939 UINT Height, D3DFORMAT Format, BOOL Lockable, BOOL Discard, UINT Level,
940 IDirect3DSurface9 **ppSurface, UINT Usage, D3DPOOL Pool, D3DMULTISAMPLE_TYPE MultiSample,
941 DWORD MultisampleQuality)
943 IDirect3DSurface9Impl *object;
946 TRACE("device %p, width %u, height %u, format %#x, lockable %#x, discard %#x, level %u, surface %p.\n"
947 "usage %#x, pool %#x, multisample_type %#x, multisample_quality %u.\n",
948 device, Width, Height, Format, Lockable, Discard, Level, ppSurface, Usage, Pool,
949 MultiSample, MultisampleQuality);
951 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DSurface9Impl));
954 FIXME("Failed to allocate surface memory.\n");
955 return D3DERR_OUTOFVIDEOMEMORY;
958 hr = surface_init(object, device, Width, Height, Format, Lockable, Discard, Level, Usage, Pool,
959 MultiSample, MultisampleQuality);
962 WARN("Failed to initialize surface, hr %#x.\n", hr);
963 HeapFree(GetProcessHeap(), 0, object);
967 TRACE("Created surface %p.\n", object);
968 *ppSurface = (IDirect3DSurface9 *)object;
973 static HRESULT WINAPI IDirect3DDevice9Impl_CreateRenderTarget(IDirect3DDevice9Ex *iface, UINT Width,
974 UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality,
975 BOOL Lockable, IDirect3DSurface9 **ppSurface, HANDLE *pSharedHandle)
977 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
980 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u.\n"
981 "lockable %#x, surface %p, shared_handle %p.\n",
982 iface, Width, Height, Format, MultiSample, MultisampleQuality,
983 Lockable, ppSurface, pSharedHandle);
985 hr = IDirect3DDevice9Impl_CreateSurface(This, Width, Height, Format, Lockable,
986 FALSE /* Discard */, 0 /* Level */, ppSurface, D3DUSAGE_RENDERTARGET, D3DPOOL_DEFAULT,
987 MultiSample, MultisampleQuality);
992 static HRESULT WINAPI IDirect3DDevice9Impl_CreateDepthStencilSurface(IDirect3DDevice9Ex *iface,
993 UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample,
994 DWORD MultisampleQuality, BOOL Discard, IDirect3DSurface9 **ppSurface,
995 HANDLE *pSharedHandle)
997 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1000 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u.\n"
1001 "discard %#x, surface %p, shared_handle %p.\n",
1002 iface, Width, Height, Format, MultiSample, MultisampleQuality,
1003 Discard, ppSurface, pSharedHandle);
1005 hr = IDirect3DDevice9Impl_CreateSurface(This, Width, Height, Format, TRUE /* Lockable */,
1006 Discard, 0 /* Level */, ppSurface, D3DUSAGE_DEPTHSTENCIL, D3DPOOL_DEFAULT, MultiSample,
1007 MultisampleQuality);
1013 static HRESULT WINAPI IDirect3DDevice9Impl_UpdateSurface(IDirect3DDevice9Ex *iface,
1014 IDirect3DSurface9 *pSourceSurface, const RECT *pSourceRect,
1015 IDirect3DSurface9 *pDestinationSurface, const POINT *pDestPoint)
1017 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1020 TRACE("iface %p, src_surface %p, src_rect %p, dst_surface %p, dst_point %p.\n",
1021 iface, pSourceSurface, pSourceRect, pDestinationSurface, pDestPoint);
1023 wined3d_mutex_lock();
1024 hr = IWineD3DDevice_UpdateSurface(This->WineD3DDevice, ((IDirect3DSurface9Impl *)pSourceSurface)->wineD3DSurface, pSourceRect, ((IDirect3DSurface9Impl *)pDestinationSurface)->wineD3DSurface, pDestPoint);
1025 wined3d_mutex_unlock();
1030 static HRESULT WINAPI IDirect3DDevice9Impl_UpdateTexture(IDirect3DDevice9Ex *iface,
1031 IDirect3DBaseTexture9 *src_texture, IDirect3DBaseTexture9 *dst_texture)
1033 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1036 TRACE("iface %p, src_texture %p, dst_texture %p.\n", iface, src_texture, dst_texture);
1038 wined3d_mutex_lock();
1039 hr = IWineD3DDevice_UpdateTexture(This->WineD3DDevice,
1040 ((IDirect3DBaseTexture9Impl *)src_texture)->wined3d_texture,
1041 ((IDirect3DBaseTexture9Impl *)dst_texture)->wined3d_texture);
1042 wined3d_mutex_unlock();
1047 static HRESULT WINAPI IDirect3DDevice9Impl_GetRenderTargetData(IDirect3DDevice9Ex *iface,
1048 IDirect3DSurface9 *pRenderTarget, IDirect3DSurface9 *pDestSurface)
1050 IDirect3DSurface9Impl *renderTarget = (IDirect3DSurface9Impl *)pRenderTarget;
1051 IDirect3DSurface9Impl *destSurface = (IDirect3DSurface9Impl *)pDestSurface;
1054 TRACE("iface %p, render_target %p, dst_surface %p.\n", iface, pRenderTarget, pDestSurface);
1056 wined3d_mutex_lock();
1057 hr = IWineD3DSurface_BltFast(destSurface->wineD3DSurface, 0, 0, renderTarget->wineD3DSurface, NULL, WINEDDBLTFAST_NOCOLORKEY);
1058 wined3d_mutex_unlock();
1063 static HRESULT WINAPI IDirect3DDevice9Impl_GetFrontBufferData(IDirect3DDevice9Ex *iface,
1064 UINT iSwapChain, IDirect3DSurface9 *pDestSurface)
1066 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1067 IDirect3DSurface9Impl *destSurface = (IDirect3DSurface9Impl *)pDestSurface;
1070 TRACE("iface %p, swapchain %u, dst_surface %p.\n", iface, iSwapChain, pDestSurface);
1072 wined3d_mutex_lock();
1073 hr = IWineD3DDevice_GetFrontBufferData(This->WineD3DDevice, iSwapChain, destSurface->wineD3DSurface);
1074 wined3d_mutex_unlock();
1079 static HRESULT WINAPI IDirect3DDevice9Impl_StretchRect(IDirect3DDevice9Ex *iface, IDirect3DSurface9 *pSourceSurface,
1080 const RECT *pSourceRect, IDirect3DSurface9 *pDestSurface, const RECT *pDestRect, D3DTEXTUREFILTERTYPE Filter)
1082 IDirect3DSurface9Impl *src = (IDirect3DSurface9Impl *) pSourceSurface;
1083 IDirect3DSurface9Impl *dst = (IDirect3DSurface9Impl *) pDestSurface;
1086 TRACE("iface %p, src_surface %p, src_rect %p, dst_surface %p, dst_rect %p, filter %#x.\n",
1087 iface, pSourceSurface, pSourceRect, pDestSurface, pDestRect, Filter);
1089 wined3d_mutex_lock();
1090 hr = IWineD3DSurface_Blt(dst->wineD3DSurface, pDestRect, src->wineD3DSurface, pSourceRect, 0, NULL, Filter);
1091 wined3d_mutex_unlock();
1096 static HRESULT WINAPI IDirect3DDevice9Impl_ColorFill(IDirect3DDevice9Ex *iface,
1097 IDirect3DSurface9 *pSurface, const RECT *pRect, D3DCOLOR color)
1099 const WINED3DCOLORVALUE c =
1101 ((color >> 16) & 0xff) / 255.0f,
1102 ((color >> 8) & 0xff) / 255.0f,
1103 (color & 0xff) / 255.0f,
1104 ((color >> 24) & 0xff) / 255.0f,
1106 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1107 IDirect3DSurface9Impl *surface = (IDirect3DSurface9Impl *)pSurface;
1108 struct wined3d_resource *wined3d_resource;
1109 struct wined3d_resource_desc desc;
1112 TRACE("iface %p, surface %p, rect %p, color 0x%08x.\n", iface, pSurface, pRect, color);
1114 wined3d_mutex_lock();
1116 wined3d_resource = IWineD3DSurface_GetResource(surface->wineD3DSurface);
1117 wined3d_resource_get_desc(wined3d_resource, &desc);
1119 /* This method is only allowed with surfaces that are render targets, or
1120 * offscreen plain surfaces in D3DPOOL_DEFAULT. */
1121 if (!(desc.usage & WINED3DUSAGE_RENDERTARGET) && desc.pool != WINED3DPOOL_DEFAULT)
1123 wined3d_mutex_unlock();
1124 WARN("Surface is not a render target, or not a stand-alone D3DPOOL_DEFAULT surface\n");
1125 return D3DERR_INVALIDCALL;
1128 /* Colorfill can only be used on rendertarget surfaces, or offscreen plain surfaces in D3DPOOL_DEFAULT */
1129 hr = IWineD3DDevice_ColorFill(This->WineD3DDevice, surface->wineD3DSurface, pRect, &c);
1131 wined3d_mutex_unlock();
1136 static HRESULT WINAPI IDirect3DDevice9Impl_CreateOffscreenPlainSurface(IDirect3DDevice9Ex *iface,
1137 UINT Width, UINT Height, D3DFORMAT Format, D3DPOOL Pool, IDirect3DSurface9 **ppSurface,
1138 HANDLE *pSharedHandle)
1140 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1143 TRACE("iface %p, width %u, height %u, format %#x, pool %#x, surface %p, shared_handle %p.\n",
1144 iface, Width, Height, Format, Pool, ppSurface, pSharedHandle);
1146 if(Pool == D3DPOOL_MANAGED ){
1147 FIXME("Attempting to create a managed offscreen plain surface\n");
1148 return D3DERR_INVALIDCALL;
1151 'Off-screen plain surfaces are always lockable, regardless of their pool types.'
1153 D3DPOOL_DEFAULT is the appropriate pool for use with the IDirect3DDevice9::StretchRect and IDirect3DDevice9::ColorFill.
1154 Why, their always lockable?
1155 should I change the usage to dynamic?
1157 hr = IDirect3DDevice9Impl_CreateSurface(This, Width, Height, Format, TRUE /* Lockable */,
1158 FALSE /* Discard */, 0 /* Level */, ppSurface, 0 /* Usage (undefined/none) */,
1159 (WINED3DPOOL)Pool, D3DMULTISAMPLE_NONE, 0 /* MultisampleQuality */);
1164 /* TODO: move to wineD3D */
1165 static HRESULT WINAPI IDirect3DDevice9Impl_SetRenderTarget(IDirect3DDevice9Ex *iface,
1166 DWORD RenderTargetIndex, IDirect3DSurface9 *pRenderTarget)
1168 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1169 IDirect3DSurface9Impl *pSurface = (IDirect3DSurface9Impl*)pRenderTarget;
1172 TRACE("iface %p, idx %u, surface %p.\n", iface, RenderTargetIndex, pRenderTarget);
1174 if (RenderTargetIndex >= D3D9_MAX_SIMULTANEOUS_RENDERTARGETS)
1176 WARN("Invalid index %u specified.\n", RenderTargetIndex);
1177 return D3DERR_INVALIDCALL;
1180 wined3d_mutex_lock();
1181 hr = IWineD3DDevice_SetRenderTarget(This->WineD3DDevice, RenderTargetIndex, pSurface ? pSurface->wineD3DSurface : NULL, TRUE);
1182 wined3d_mutex_unlock();
1187 static HRESULT WINAPI IDirect3DDevice9Impl_GetRenderTarget(IDirect3DDevice9Ex *iface,
1188 DWORD RenderTargetIndex, IDirect3DSurface9 **ppRenderTarget)
1190 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1191 IWineD3DSurface *pRenderTarget;
1194 TRACE("iface %p, idx %u, surface %p.\n", iface, RenderTargetIndex, ppRenderTarget);
1196 if (ppRenderTarget == NULL) {
1197 return D3DERR_INVALIDCALL;
1200 if (RenderTargetIndex >= D3D9_MAX_SIMULTANEOUS_RENDERTARGETS)
1202 WARN("Invalid index %u specified.\n", RenderTargetIndex);
1203 return D3DERR_INVALIDCALL;
1206 wined3d_mutex_lock();
1208 hr=IWineD3DDevice_GetRenderTarget(This->WineD3DDevice,RenderTargetIndex,&pRenderTarget);
1212 FIXME("Call to IWineD3DDevice_GetRenderTarget failed, hr %#x\n", hr);
1214 else if (!pRenderTarget)
1216 *ppRenderTarget = NULL;
1220 *ppRenderTarget = IWineD3DSurface_GetParent(pRenderTarget);
1221 IDirect3DSurface9_AddRef(*ppRenderTarget);
1222 IWineD3DSurface_Release(pRenderTarget);
1225 wined3d_mutex_unlock();
1230 static HRESULT WINAPI IDirect3DDevice9Impl_SetDepthStencilSurface(IDirect3DDevice9Ex *iface,
1231 IDirect3DSurface9 *pZStencilSurface)
1233 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1234 IDirect3DSurface9Impl *pSurface;
1237 TRACE("iface %p, depth_stencil %p.\n", iface, pZStencilSurface);
1239 pSurface = (IDirect3DSurface9Impl*)pZStencilSurface;
1241 wined3d_mutex_lock();
1242 hr = IWineD3DDevice_SetDepthStencilSurface(This->WineD3DDevice, NULL==pSurface ? NULL : pSurface->wineD3DSurface);
1243 wined3d_mutex_unlock();
1248 static HRESULT WINAPI IDirect3DDevice9Impl_GetDepthStencilSurface(IDirect3DDevice9Ex *iface,
1249 IDirect3DSurface9 **ppZStencilSurface)
1251 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1252 IWineD3DSurface *pZStencilSurface;
1255 TRACE("iface %p, depth_stencil %p.\n", iface, ppZStencilSurface);
1257 if(ppZStencilSurface == NULL){
1258 return D3DERR_INVALIDCALL;
1261 wined3d_mutex_lock();
1262 hr = IWineD3DDevice_GetDepthStencilSurface(This->WineD3DDevice,&pZStencilSurface);
1265 *ppZStencilSurface = IWineD3DSurface_GetParent(pZStencilSurface);
1266 IDirect3DSurface9_AddRef(*ppZStencilSurface);
1267 IWineD3DSurface_Release(pZStencilSurface);
1271 if (hr != WINED3DERR_NOTFOUND)
1272 WARN("Call to IWineD3DDevice_GetDepthStencilSurface failed with 0x%08x\n", hr);
1273 *ppZStencilSurface = NULL;
1275 wined3d_mutex_unlock();
1280 static HRESULT WINAPI IDirect3DDevice9Impl_BeginScene(IDirect3DDevice9Ex *iface)
1282 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1285 TRACE("iface %p.\n", iface);
1287 wined3d_mutex_lock();
1288 hr = IWineD3DDevice_BeginScene(This->WineD3DDevice);
1289 wined3d_mutex_unlock();
1294 static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_EndScene(IDirect3DDevice9Ex *iface)
1296 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1299 TRACE("iface %p.\n", iface);
1301 wined3d_mutex_lock();
1302 hr = IWineD3DDevice_EndScene(This->WineD3DDevice);
1303 wined3d_mutex_unlock();
1308 static HRESULT WINAPI IDirect3DDevice9Impl_Clear(IDirect3DDevice9Ex *iface, DWORD Count,
1309 const D3DRECT *pRects, DWORD Flags, D3DCOLOR Color, float Z, DWORD Stencil)
1311 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1314 TRACE("iface %p, rect_count %u, rects %p, flags %#x, color 0x%08x, z %.8e, stencil %u.\n",
1315 iface, Count, pRects, Flags, Color, Z, Stencil);
1317 /* Note: D3DRECT is compatible with WINED3DRECT */
1318 wined3d_mutex_lock();
1319 hr = IWineD3DDevice_Clear(This->WineD3DDevice, Count, (const RECT *)pRects, Flags, Color, Z, Stencil);
1320 wined3d_mutex_unlock();
1325 static HRESULT WINAPI IDirect3DDevice9Impl_SetTransform(IDirect3DDevice9Ex *iface,
1326 D3DTRANSFORMSTATETYPE State, const D3DMATRIX *lpMatrix)
1328 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1331 TRACE("iface %p, state %#x, matrix %p.\n", iface, State, lpMatrix);
1333 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1334 wined3d_mutex_lock();
1335 hr = IWineD3DDevice_SetTransform(This->WineD3DDevice, State, (CONST WINED3DMATRIX*) lpMatrix);
1336 wined3d_mutex_unlock();
1341 static HRESULT WINAPI IDirect3DDevice9Impl_GetTransform(IDirect3DDevice9Ex *iface,
1342 D3DTRANSFORMSTATETYPE State, D3DMATRIX *pMatrix)
1344 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1347 TRACE("iface %p, state %#x, matrix %p.\n", iface, State, pMatrix);
1349 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1350 wined3d_mutex_lock();
1351 hr = IWineD3DDevice_GetTransform(This->WineD3DDevice, State, (WINED3DMATRIX*) pMatrix);
1352 wined3d_mutex_unlock();
1357 static HRESULT WINAPI IDirect3DDevice9Impl_MultiplyTransform(IDirect3DDevice9Ex *iface,
1358 D3DTRANSFORMSTATETYPE State, const D3DMATRIX *pMatrix)
1360 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1363 TRACE("iface %p, state %#x, matrix %p.\n", iface, State, pMatrix);
1365 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1366 wined3d_mutex_lock();
1367 hr = IWineD3DDevice_MultiplyTransform(This->WineD3DDevice, State, (CONST WINED3DMATRIX*) pMatrix);
1368 wined3d_mutex_unlock();
1373 static HRESULT WINAPI IDirect3DDevice9Impl_SetViewport(IDirect3DDevice9Ex *iface,
1374 const D3DVIEWPORT9 *pViewport)
1376 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1379 TRACE("iface %p, viewport %p.\n", iface, pViewport);
1381 /* Note: D3DVIEWPORT9 is compatible with WINED3DVIEWPORT */
1382 wined3d_mutex_lock();
1383 hr = IWineD3DDevice_SetViewport(This->WineD3DDevice, (const WINED3DVIEWPORT *)pViewport);
1384 wined3d_mutex_unlock();
1389 static HRESULT WINAPI IDirect3DDevice9Impl_GetViewport(IDirect3DDevice9Ex *iface,
1390 D3DVIEWPORT9 *pViewport)
1392 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1395 TRACE("iface %p, viewport %p.\n", iface, pViewport);
1397 /* Note: D3DVIEWPORT9 is compatible with WINED3DVIEWPORT */
1398 wined3d_mutex_lock();
1399 hr = IWineD3DDevice_GetViewport(This->WineD3DDevice, (WINED3DVIEWPORT *)pViewport);
1400 wined3d_mutex_unlock();
1405 static HRESULT WINAPI IDirect3DDevice9Impl_SetMaterial(IDirect3DDevice9Ex *iface,
1406 const D3DMATERIAL9 *pMaterial)
1408 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1411 TRACE("iface %p, material %p.\n", iface, pMaterial);
1413 /* Note: D3DMATERIAL9 is compatible with WINED3DMATERIAL */
1414 wined3d_mutex_lock();
1415 hr = IWineD3DDevice_SetMaterial(This->WineD3DDevice, (const WINED3DMATERIAL *)pMaterial);
1416 wined3d_mutex_unlock();
1421 static HRESULT WINAPI IDirect3DDevice9Impl_GetMaterial(IDirect3DDevice9Ex *iface,
1422 D3DMATERIAL9 *pMaterial)
1424 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1427 TRACE("iface %p, material %p.\n", iface, pMaterial);
1429 /* Note: D3DMATERIAL9 is compatible with WINED3DMATERIAL */
1430 wined3d_mutex_lock();
1431 hr = IWineD3DDevice_GetMaterial(This->WineD3DDevice, (WINED3DMATERIAL *)pMaterial);
1432 wined3d_mutex_unlock();
1437 static HRESULT WINAPI IDirect3DDevice9Impl_SetLight(IDirect3DDevice9Ex *iface, DWORD Index,
1438 const D3DLIGHT9 *pLight)
1440 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1443 TRACE("iface %p, index %u, light %p.\n", iface, Index, pLight);
1445 /* Note: D3DLIGHT9 is compatible with WINED3DLIGHT */
1446 wined3d_mutex_lock();
1447 hr = IWineD3DDevice_SetLight(This->WineD3DDevice, Index, (const WINED3DLIGHT *)pLight);
1448 wined3d_mutex_unlock();
1453 static HRESULT WINAPI IDirect3DDevice9Impl_GetLight(IDirect3DDevice9Ex *iface, DWORD Index,
1456 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1459 TRACE("iface %p, index %u, light %p.\n", iface, Index, pLight);
1461 /* Note: D3DLIGHT9 is compatible with WINED3DLIGHT */
1462 wined3d_mutex_lock();
1463 hr = IWineD3DDevice_GetLight(This->WineD3DDevice, Index, (WINED3DLIGHT *)pLight);
1464 wined3d_mutex_unlock();
1469 static HRESULT WINAPI IDirect3DDevice9Impl_LightEnable(IDirect3DDevice9Ex *iface, DWORD Index,
1472 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1475 TRACE("iface %p, index %u, enable %#x.\n", iface, Index, Enable);
1477 wined3d_mutex_lock();
1478 hr = IWineD3DDevice_SetLightEnable(This->WineD3DDevice, Index, Enable);
1479 wined3d_mutex_unlock();
1484 static HRESULT WINAPI IDirect3DDevice9Impl_GetLightEnable(IDirect3DDevice9Ex *iface, DWORD Index,
1487 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1490 TRACE("iface %p, index %u, enable %p.\n", iface, Index, pEnable);
1492 wined3d_mutex_lock();
1493 hr = IWineD3DDevice_GetLightEnable(This->WineD3DDevice, Index, pEnable);
1494 wined3d_mutex_unlock();
1499 static HRESULT WINAPI IDirect3DDevice9Impl_SetClipPlane(IDirect3DDevice9Ex *iface, DWORD Index,
1500 const float *pPlane)
1502 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1505 TRACE("iface %p, index %u, plane %p.\n", iface, Index, pPlane);
1507 wined3d_mutex_lock();
1508 hr = IWineD3DDevice_SetClipPlane(This->WineD3DDevice, Index, pPlane);
1509 wined3d_mutex_unlock();
1514 static HRESULT WINAPI IDirect3DDevice9Impl_GetClipPlane(IDirect3DDevice9Ex *iface, DWORD Index,
1517 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1520 TRACE("iface %p, index %u, plane %p.\n", iface, Index, pPlane);
1522 wined3d_mutex_lock();
1523 hr = IWineD3DDevice_GetClipPlane(This->WineD3DDevice, Index, pPlane);
1524 wined3d_mutex_unlock();
1529 static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_SetRenderState(IDirect3DDevice9Ex *iface,
1530 D3DRENDERSTATETYPE State, DWORD Value)
1532 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1535 TRACE("iface %p, state %#x, value %#x.\n", iface, State, Value);
1537 wined3d_mutex_lock();
1538 hr = IWineD3DDevice_SetRenderState(This->WineD3DDevice, State, Value);
1539 wined3d_mutex_unlock();
1544 static HRESULT WINAPI IDirect3DDevice9Impl_GetRenderState(IDirect3DDevice9Ex *iface,
1545 D3DRENDERSTATETYPE State, DWORD *pValue)
1547 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1550 TRACE("iface %p, state %#x, value %p.\n", iface, State, pValue);
1552 wined3d_mutex_lock();
1553 hr = IWineD3DDevice_GetRenderState(This->WineD3DDevice, State, pValue);
1554 wined3d_mutex_unlock();
1559 static HRESULT WINAPI IDirect3DDevice9Impl_CreateStateBlock(IDirect3DDevice9Ex *iface,
1560 D3DSTATEBLOCKTYPE type, IDirect3DStateBlock9 **stateblock)
1562 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1563 IDirect3DStateBlock9Impl *object;
1566 TRACE("iface %p, type %#x, stateblock %p.\n", iface, type, stateblock);
1568 if (type != D3DSBT_ALL && type != D3DSBT_PIXELSTATE && type != D3DSBT_VERTEXSTATE)
1570 WARN("Unexpected stateblock type, returning D3DERR_INVALIDCALL.\n");
1571 return D3DERR_INVALIDCALL;
1574 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1577 ERR("Failed to allocate stateblock memory.\n");
1578 return E_OUTOFMEMORY;
1581 hr = stateblock_init(object, This, type, NULL);
1584 WARN("Failed to initialize stateblock, hr %#x.\n", hr);
1585 HeapFree(GetProcessHeap(), 0, object);
1589 TRACE("Created stateblock %p.\n", object);
1590 *stateblock = &object->IDirect3DStateBlock9_iface;
1595 static HRESULT WINAPI IDirect3DDevice9Impl_BeginStateBlock(IDirect3DDevice9Ex *iface)
1597 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1600 TRACE("iface %p.\n", iface);
1602 wined3d_mutex_lock();
1603 hr = IWineD3DDevice_BeginStateBlock(This->WineD3DDevice);
1604 wined3d_mutex_unlock();
1609 static HRESULT WINAPI IDirect3DDevice9Impl_EndStateBlock(IDirect3DDevice9Ex *iface,
1610 IDirect3DStateBlock9 **stateblock)
1612 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1613 struct wined3d_stateblock *wined3d_stateblock;
1614 IDirect3DStateBlock9Impl *object;
1617 TRACE("iface %p, stateblock %p.\n", iface, stateblock);
1619 wined3d_mutex_lock();
1620 hr = IWineD3DDevice_EndStateBlock(This->WineD3DDevice, &wined3d_stateblock);
1621 wined3d_mutex_unlock();
1624 WARN("IWineD3DDevice_EndStateBlock() failed, hr %#x.\n", hr);
1628 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1631 ERR("Failed to allocate stateblock memory.\n");
1632 wined3d_mutex_lock();
1633 wined3d_stateblock_decref(wined3d_stateblock);
1634 wined3d_mutex_unlock();
1635 return E_OUTOFMEMORY;
1638 hr = stateblock_init(object, This, 0, wined3d_stateblock);
1641 WARN("Failed to initialize stateblock, hr %#x.\n", hr);
1642 wined3d_mutex_lock();
1643 wined3d_stateblock_decref(wined3d_stateblock);
1644 wined3d_mutex_unlock();
1645 HeapFree(GetProcessHeap(), 0, object);
1649 TRACE("Created stateblock %p.\n", object);
1650 *stateblock = &object->IDirect3DStateBlock9_iface;
1655 static HRESULT WINAPI IDirect3DDevice9Impl_SetClipStatus(IDirect3DDevice9Ex *iface,
1656 const D3DCLIPSTATUS9 *pClipStatus)
1658 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1661 TRACE("iface %p, clip_status %p.\n", iface, pClipStatus);
1663 wined3d_mutex_lock();
1664 hr = IWineD3DDevice_SetClipStatus(This->WineD3DDevice, (const WINED3DCLIPSTATUS *)pClipStatus);
1665 wined3d_mutex_unlock();
1670 static HRESULT WINAPI IDirect3DDevice9Impl_GetClipStatus(IDirect3DDevice9Ex *iface,
1671 D3DCLIPSTATUS9 *pClipStatus)
1673 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1676 TRACE("iface %p, clip_status %p.\n", iface, pClipStatus);
1678 wined3d_mutex_lock();
1679 hr = IWineD3DDevice_GetClipStatus(This->WineD3DDevice, (WINED3DCLIPSTATUS *)pClipStatus);
1680 wined3d_mutex_unlock();
1685 static HRESULT WINAPI IDirect3DDevice9Impl_GetTexture(IDirect3DDevice9Ex *iface, DWORD Stage,
1686 IDirect3DBaseTexture9 **ppTexture)
1688 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1689 struct wined3d_texture *wined3d_texture = NULL;
1692 TRACE("iface %p, stage %u, texture %p.\n", iface, Stage, ppTexture);
1694 if(ppTexture == NULL){
1695 return D3DERR_INVALIDCALL;
1698 wined3d_mutex_lock();
1699 hr = IWineD3DDevice_GetTexture(This->WineD3DDevice, Stage, &wined3d_texture);
1700 if (SUCCEEDED(hr) && wined3d_texture)
1702 *ppTexture = wined3d_texture_get_parent(wined3d_texture);
1703 IDirect3DBaseTexture9_AddRef(*ppTexture);
1704 wined3d_texture_decref(wined3d_texture);
1710 WARN("Call to get texture (%u) failed (%p).\n", Stage, wined3d_texture);
1714 wined3d_mutex_unlock();
1719 static HRESULT WINAPI IDirect3DDevice9Impl_SetTexture(IDirect3DDevice9Ex *iface, DWORD stage,
1720 IDirect3DBaseTexture9 *texture)
1722 IDirect3DDevice9Impl *device = impl_from_IDirect3DDevice9Ex(iface);
1725 TRACE("iface %p, stage %u, texture %p.\n", iface, stage, texture);
1727 wined3d_mutex_lock();
1728 hr = IWineD3DDevice_SetTexture(device->WineD3DDevice, stage,
1729 texture ? ((IDirect3DBaseTexture9Impl *)texture)->wined3d_texture : NULL);
1730 wined3d_mutex_unlock();
1735 static const WINED3DTEXTURESTAGESTATETYPE tss_lookup[] =
1737 WINED3DTSS_FORCE_DWORD, /* 0, unused */
1738 WINED3DTSS_COLOROP, /* 1, D3DTSS_COLOROP */
1739 WINED3DTSS_COLORARG1, /* 2, D3DTSS_COLORARG1 */
1740 WINED3DTSS_COLORARG2, /* 3, D3DTSS_COLORARG2 */
1741 WINED3DTSS_ALPHAOP, /* 4, D3DTSS_ALPHAOP */
1742 WINED3DTSS_ALPHAARG1, /* 5, D3DTSS_ALPHAARG1 */
1743 WINED3DTSS_ALPHAARG2, /* 6, D3DTSS_ALPHAARG2 */
1744 WINED3DTSS_BUMPENVMAT00, /* 7, D3DTSS_BUMPENVMAT00 */
1745 WINED3DTSS_BUMPENVMAT01, /* 8, D3DTSS_BUMPENVMAT01 */
1746 WINED3DTSS_BUMPENVMAT10, /* 9, D3DTSS_BUMPENVMAT10 */
1747 WINED3DTSS_BUMPENVMAT11, /* 10, D3DTSS_BUMPENVMAT11 */
1748 WINED3DTSS_TEXCOORDINDEX, /* 11, D3DTSS_TEXCOORDINDEX */
1749 WINED3DTSS_FORCE_DWORD, /* 12, unused */
1750 WINED3DTSS_FORCE_DWORD, /* 13, unused */
1751 WINED3DTSS_FORCE_DWORD, /* 14, unused */
1752 WINED3DTSS_FORCE_DWORD, /* 15, unused */
1753 WINED3DTSS_FORCE_DWORD, /* 16, unused */
1754 WINED3DTSS_FORCE_DWORD, /* 17, unused */
1755 WINED3DTSS_FORCE_DWORD, /* 18, unused */
1756 WINED3DTSS_FORCE_DWORD, /* 19, unused */
1757 WINED3DTSS_FORCE_DWORD, /* 20, unused */
1758 WINED3DTSS_FORCE_DWORD, /* 21, unused */
1759 WINED3DTSS_BUMPENVLSCALE, /* 22, D3DTSS_BUMPENVLSCALE */
1760 WINED3DTSS_BUMPENVLOFFSET, /* 23, D3DTSS_BUMPENVLOFFSET */
1761 WINED3DTSS_TEXTURETRANSFORMFLAGS, /* 24, D3DTSS_TEXTURETRANSFORMFLAGS */
1762 WINED3DTSS_FORCE_DWORD, /* 25, unused */
1763 WINED3DTSS_COLORARG0, /* 26, D3DTSS_COLORARG0 */
1764 WINED3DTSS_ALPHAARG0, /* 27, D3DTSS_ALPHAARG0 */
1765 WINED3DTSS_RESULTARG, /* 28, D3DTSS_RESULTARG */
1766 WINED3DTSS_FORCE_DWORD, /* 29, unused */
1767 WINED3DTSS_FORCE_DWORD, /* 30, unused */
1768 WINED3DTSS_FORCE_DWORD, /* 31, unused */
1769 WINED3DTSS_CONSTANT, /* 32, D3DTSS_CONSTANT */
1772 static HRESULT WINAPI IDirect3DDevice9Impl_GetTextureStageState(IDirect3DDevice9Ex *iface,
1773 DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD *pValue)
1775 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1778 TRACE("iface %p, stage %u, state %#x, value %p.\n", iface, Stage, Type, pValue);
1780 if (Type >= sizeof(tss_lookup) / sizeof(*tss_lookup))
1782 WARN("Invalid Type %#x passed.\n", Type);
1786 wined3d_mutex_lock();
1787 hr = IWineD3DDevice_GetTextureStageState(This->WineD3DDevice, Stage, tss_lookup[Type], pValue);
1788 wined3d_mutex_unlock();
1793 static HRESULT WINAPI IDirect3DDevice9Impl_SetTextureStageState(IDirect3DDevice9Ex *iface,
1794 DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD Value)
1796 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1799 TRACE("iface %p, stage %u, state %#x, value %#x.\n", iface, Stage, Type, Value);
1801 if (Type >= sizeof(tss_lookup) / sizeof(*tss_lookup))
1803 WARN("Invalid Type %#x passed.\n", Type);
1807 wined3d_mutex_lock();
1808 hr = IWineD3DDevice_SetTextureStageState(This->WineD3DDevice, Stage, tss_lookup[Type], Value);
1809 wined3d_mutex_unlock();
1814 static HRESULT WINAPI IDirect3DDevice9Impl_GetSamplerState(IDirect3DDevice9Ex *iface, DWORD Sampler,
1815 D3DSAMPLERSTATETYPE Type, DWORD *pValue)
1817 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1820 TRACE("iface %p, sampler %u, state %#x, value %p.\n", iface, Sampler, Type, pValue);
1822 wined3d_mutex_lock();
1823 hr = IWineD3DDevice_GetSamplerState(This->WineD3DDevice, Sampler, Type, pValue);
1824 wined3d_mutex_unlock();
1829 static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_SetSamplerState(IDirect3DDevice9Ex *iface,
1830 DWORD Sampler, D3DSAMPLERSTATETYPE Type, DWORD Value)
1832 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1835 TRACE("iface %p, sampler %u, state %#x, value %#x.\n", iface, Sampler, Type, Value);
1837 wined3d_mutex_lock();
1838 hr = IWineD3DDevice_SetSamplerState(This->WineD3DDevice, Sampler, Type, Value);
1839 wined3d_mutex_unlock();
1844 static HRESULT WINAPI IDirect3DDevice9Impl_ValidateDevice(IDirect3DDevice9Ex *iface,
1847 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1850 TRACE("iface %p, pass_count %p.\n", iface, pNumPasses);
1852 wined3d_mutex_lock();
1853 hr = IWineD3DDevice_ValidateDevice(This->WineD3DDevice, pNumPasses);
1854 wined3d_mutex_unlock();
1859 static HRESULT WINAPI IDirect3DDevice9Impl_SetPaletteEntries(IDirect3DDevice9Ex *iface,
1860 UINT PaletteNumber, const PALETTEENTRY *pEntries)
1862 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1865 TRACE("iface %p, palette_idx %u, entries %p.\n", iface, PaletteNumber, pEntries);
1867 wined3d_mutex_lock();
1868 hr = IWineD3DDevice_SetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
1869 wined3d_mutex_unlock();
1874 static HRESULT WINAPI IDirect3DDevice9Impl_GetPaletteEntries(IDirect3DDevice9Ex *iface,
1875 UINT PaletteNumber, PALETTEENTRY *pEntries)
1877 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1880 TRACE("iface %p, palette_idx %u, entries %p.\n", iface, PaletteNumber, pEntries);
1882 wined3d_mutex_lock();
1883 hr = IWineD3DDevice_GetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
1884 wined3d_mutex_unlock();
1889 static HRESULT WINAPI IDirect3DDevice9Impl_SetCurrentTexturePalette(IDirect3DDevice9Ex *iface,
1892 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1895 TRACE("iface %p, palette_idx %u.\n", iface, PaletteNumber);
1897 wined3d_mutex_lock();
1898 hr = IWineD3DDevice_SetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
1899 wined3d_mutex_unlock();
1904 static HRESULT WINAPI IDirect3DDevice9Impl_GetCurrentTexturePalette(IDirect3DDevice9Ex *iface,
1905 UINT *PaletteNumber)
1907 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1910 TRACE("iface %p, palette_idx %p.\n", iface, PaletteNumber);
1912 wined3d_mutex_lock();
1913 hr = IWineD3DDevice_GetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
1914 wined3d_mutex_unlock();
1919 static HRESULT WINAPI IDirect3DDevice9Impl_SetScissorRect(IDirect3DDevice9Ex *iface,
1922 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1925 TRACE("iface %p, rect %p.\n", iface, pRect);
1927 wined3d_mutex_lock();
1928 hr = IWineD3DDevice_SetScissorRect(This->WineD3DDevice, pRect);
1929 wined3d_mutex_unlock();
1934 static HRESULT WINAPI IDirect3DDevice9Impl_GetScissorRect(IDirect3DDevice9Ex *iface, RECT *pRect)
1936 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1939 TRACE("iface %p, rect %p.\n", iface, pRect);
1941 wined3d_mutex_lock();
1942 hr = IWineD3DDevice_GetScissorRect(This->WineD3DDevice, pRect);
1943 wined3d_mutex_unlock();
1948 static HRESULT WINAPI IDirect3DDevice9Impl_SetSoftwareVertexProcessing(IDirect3DDevice9Ex *iface,
1951 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1954 TRACE("iface %p, software %#x.\n", iface, bSoftware);
1956 wined3d_mutex_lock();
1957 hr = IWineD3DDevice_SetSoftwareVertexProcessing(This->WineD3DDevice, bSoftware);
1958 wined3d_mutex_unlock();
1963 static BOOL WINAPI IDirect3DDevice9Impl_GetSoftwareVertexProcessing(IDirect3DDevice9Ex *iface)
1965 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1968 TRACE("iface %p.\n", iface);
1970 wined3d_mutex_lock();
1971 ret = IWineD3DDevice_GetSoftwareVertexProcessing(This->WineD3DDevice);
1972 wined3d_mutex_unlock();
1977 static HRESULT WINAPI IDirect3DDevice9Impl_SetNPatchMode(IDirect3DDevice9Ex *iface, float nSegments)
1979 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1982 TRACE("iface %p, segment_count %.8e.\n", iface, nSegments);
1984 wined3d_mutex_lock();
1985 hr = IWineD3DDevice_SetNPatchMode(This->WineD3DDevice, nSegments);
1986 wined3d_mutex_unlock();
1991 static float WINAPI IDirect3DDevice9Impl_GetNPatchMode(IDirect3DDevice9Ex *iface)
1993 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1996 TRACE("iface %p.\n", iface);
1998 wined3d_mutex_lock();
1999 ret = IWineD3DDevice_GetNPatchMode(This->WineD3DDevice);
2000 wined3d_mutex_unlock();
2005 static HRESULT WINAPI IDirect3DDevice9Impl_DrawPrimitive(IDirect3DDevice9Ex *iface,
2006 D3DPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT PrimitiveCount)
2008 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
2011 TRACE("iface %p, primitive_type %#x, start_vertex %u, primitive_count %u.\n",
2012 iface, PrimitiveType, StartVertex, PrimitiveCount);
2014 wined3d_mutex_lock();
2015 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
2016 hr = IWineD3DDevice_DrawPrimitive(This->WineD3DDevice, StartVertex,
2017 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount));
2018 wined3d_mutex_unlock();
2023 static HRESULT WINAPI IDirect3DDevice9Impl_DrawIndexedPrimitive(IDirect3DDevice9Ex *iface,
2024 D3DPRIMITIVETYPE PrimitiveType, INT BaseVertexIndex, UINT MinVertexIndex, UINT NumVertices,
2025 UINT startIndex, UINT primCount)
2027 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
2030 TRACE("iface %p, primitive_type %#x, base_vertex_idx %u, min_vertex_idx %u,\n"
2031 "vertex_count %u, start_idx %u, primitive_count %u.\n",
2032 iface, PrimitiveType, BaseVertexIndex, MinVertexIndex,
2033 NumVertices, startIndex, primCount);
2035 wined3d_mutex_lock();
2036 IWineD3DDevice_SetBaseVertexIndex(This->WineD3DDevice, BaseVertexIndex);
2037 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
2038 hr = IWineD3DDevice_DrawIndexedPrimitive(This->WineD3DDevice, startIndex,
2039 vertex_count_from_primitive_count(PrimitiveType, primCount));
2040 wined3d_mutex_unlock();
2045 static HRESULT WINAPI IDirect3DDevice9Impl_DrawPrimitiveUP(IDirect3DDevice9Ex *iface,
2046 D3DPRIMITIVETYPE PrimitiveType, UINT PrimitiveCount, const void *pVertexStreamZeroData,
2047 UINT VertexStreamZeroStride)
2049 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
2052 TRACE("iface %p, primitive_type %#x, primitive_count %u, data %p, stride %u.\n",
2053 iface, PrimitiveType, PrimitiveCount, pVertexStreamZeroData, VertexStreamZeroStride);
2055 wined3d_mutex_lock();
2056 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
2057 hr = IWineD3DDevice_DrawPrimitiveUP(This->WineD3DDevice,
2058 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount),
2059 pVertexStreamZeroData, VertexStreamZeroStride);
2060 wined3d_mutex_unlock();
2065 static HRESULT WINAPI IDirect3DDevice9Impl_DrawIndexedPrimitiveUP(IDirect3DDevice9Ex *iface,
2066 D3DPRIMITIVETYPE PrimitiveType, UINT MinVertexIndex, UINT NumVertexIndices,
2067 UINT PrimitiveCount, const void *pIndexData, D3DFORMAT IndexDataFormat,
2068 const void *pVertexStreamZeroData, UINT VertexStreamZeroStride)
2070 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
2073 TRACE("iface %p, primitive_type %#x, min_vertex_idx %u, index_count %u, primitive_count %u,\n"
2074 "index_data %p, index_format %#x, vertex_data %p, vertex_stride %u.\n",
2075 iface, PrimitiveType, MinVertexIndex, NumVertexIndices, PrimitiveCount,
2076 pIndexData, IndexDataFormat, pVertexStreamZeroData, VertexStreamZeroStride);
2078 wined3d_mutex_lock();
2079 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
2080 hr = IWineD3DDevice_DrawIndexedPrimitiveUP(This->WineD3DDevice,
2081 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount), pIndexData,
2082 wined3dformat_from_d3dformat(IndexDataFormat), pVertexStreamZeroData, VertexStreamZeroStride);
2083 wined3d_mutex_unlock();
2088 static HRESULT WINAPI IDirect3DDevice9Impl_ProcessVertices(IDirect3DDevice9Ex *iface,
2089 UINT SrcStartIndex, UINT DestIndex, UINT VertexCount, IDirect3DVertexBuffer9 *pDestBuffer,
2090 IDirect3DVertexDeclaration9 *pVertexDecl, DWORD Flags)
2092 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
2093 IDirect3DVertexDeclaration9Impl *Decl = (IDirect3DVertexDeclaration9Impl *) pVertexDecl;
2095 IDirect3DVertexBuffer9Impl *dest = (IDirect3DVertexBuffer9Impl *) pDestBuffer;
2097 TRACE("iface %p, src_start_idx %u, dst_idx %u, vertex_count %u, dst_buffer %p, declaration %p, flags %#x.\n",
2098 iface, SrcStartIndex, DestIndex, VertexCount, pDestBuffer, pVertexDecl, Flags);
2100 wined3d_mutex_lock();
2101 hr = IWineD3DDevice_ProcessVertices(This->WineD3DDevice,SrcStartIndex, DestIndex, VertexCount, dest->wineD3DVertexBuffer, Decl ? Decl->wineD3DVertexDeclaration : NULL, Flags, dest->fvf);
2102 wined3d_mutex_unlock();
2107 static HRESULT WINAPI IDirect3DDevice9Impl_CreateVertexDeclaration(IDirect3DDevice9Ex *iface,
2108 const D3DVERTEXELEMENT9 *elements, IDirect3DVertexDeclaration9 **declaration)
2110 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
2111 IDirect3DVertexDeclaration9Impl *object;
2114 TRACE("iface %p, elements %p, declaration %p.\n", iface, elements, declaration);
2118 WARN("Caller passed a NULL declaration, returning D3DERR_INVALIDCALL.\n");
2119 return D3DERR_INVALIDCALL;
2122 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2125 ERR("Failed to allocate vertex declaration memory.\n");
2126 return E_OUTOFMEMORY;
2129 hr = vertexdeclaration_init(object, This, elements);
2132 WARN("Failed to initialize vertex declaration, hr %#x.\n", hr);
2133 HeapFree(GetProcessHeap(), 0, object);
2137 TRACE("Created vertex declaration %p.\n", object);
2138 *declaration = (IDirect3DVertexDeclaration9 *)object;
2143 static HRESULT WINAPI IDirect3DDevice9Impl_SetVertexDeclaration(IDirect3DDevice9Ex *iface,
2144 IDirect3DVertexDeclaration9 *declaration)
2146 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
2149 TRACE("iface %p, declaration %p.\n", iface, declaration);
2151 wined3d_mutex_lock();
2152 hr = IWineD3DDevice_SetVertexDeclaration(This->WineD3DDevice,
2153 declaration ? ((IDirect3DVertexDeclaration9Impl *)declaration)->wineD3DVertexDeclaration : NULL);
2154 wined3d_mutex_unlock();
2159 static HRESULT WINAPI IDirect3DDevice9Impl_GetVertexDeclaration(IDirect3DDevice9Ex *iface,
2160 IDirect3DVertexDeclaration9 **declaration)
2162 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
2163 struct wined3d_vertex_declaration *wined3d_declaration = NULL;
2166 TRACE("iface %p, declaration %p.\n", iface, declaration);
2168 if (!declaration) return D3DERR_INVALIDCALL;
2170 wined3d_mutex_lock();
2171 hr = IWineD3DDevice_GetVertexDeclaration(This->WineD3DDevice, &wined3d_declaration);
2172 if (SUCCEEDED(hr) && wined3d_declaration)
2174 *declaration = wined3d_vertex_declaration_get_parent(wined3d_declaration);
2175 IDirect3DVertexDeclaration9_AddRef(*declaration);
2176 wined3d_vertex_declaration_decref(wined3d_declaration);
2180 *declaration = NULL;
2182 wined3d_mutex_unlock();
2184 TRACE("Returning %p.\n", *declaration);
2188 static IDirect3DVertexDeclaration9 *getConvertedDecl(IDirect3DDevice9Impl *This, DWORD fvf) {
2190 D3DVERTEXELEMENT9* elements = NULL;
2191 IDirect3DVertexDeclaration9* pDecl = NULL;
2192 int p, low, high; /* deliberately signed */
2193 IDirect3DVertexDeclaration9 **convertedDecls = This->convertedDecls;
2195 TRACE("Searching for declaration for fvf %08x... ", fvf);
2198 high = This->numConvertedDecls - 1;
2199 while(low <= high) {
2200 p = (low + high) >> 1;
2202 if(((IDirect3DVertexDeclaration9Impl *) convertedDecls[p])->convFVF == fvf) {
2203 TRACE("found %p\n", convertedDecls[p]);
2204 return convertedDecls[p];
2205 } else if(((IDirect3DVertexDeclaration9Impl *) convertedDecls[p])->convFVF < fvf) {
2211 TRACE("not found. Creating and inserting at position %d.\n", low);
2213 hr = vdecl_convert_fvf(fvf, &elements);
2214 if (hr != S_OK) return NULL;
2216 hr = IDirect3DDevice9Impl_CreateVertexDeclaration(&This->IDirect3DDevice9Ex_iface, elements,
2218 HeapFree(GetProcessHeap(), 0, elements); /* CreateVertexDeclaration makes a copy */
2219 if (hr != S_OK) return NULL;
2221 if(This->declArraySize == This->numConvertedDecls) {
2222 int grow = max(This->declArraySize / 2, 8);
2223 convertedDecls = HeapReAlloc(GetProcessHeap(), 0, convertedDecls,
2224 sizeof(convertedDecls[0]) * (This->numConvertedDecls + grow));
2225 if(!convertedDecls) {
2226 /* This will destroy it */
2227 IDirect3DVertexDeclaration9_Release(pDecl);
2230 This->convertedDecls = convertedDecls;
2231 This->declArraySize += grow;
2234 memmove(convertedDecls + low + 1, convertedDecls + low, sizeof(IDirect3DVertexDeclaration9Impl *) * (This->numConvertedDecls - low));
2235 convertedDecls[low] = pDecl;
2236 This->numConvertedDecls++;
2238 /* Will prevent the decl from being destroyed */
2239 ((IDirect3DVertexDeclaration9Impl *) pDecl)->convFVF = fvf;
2240 IDirect3DVertexDeclaration9_Release(pDecl); /* Does not destroy now */
2242 TRACE("Returning %p. %d decls in array\n", pDecl, This->numConvertedDecls);
2246 static HRESULT WINAPI IDirect3DDevice9Impl_SetFVF(IDirect3DDevice9Ex *iface, DWORD FVF)
2248 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
2249 IDirect3DVertexDeclaration9 *decl;
2252 TRACE("iface %p, fvf %#x.\n", iface, FVF);
2256 WARN("%#x is not a valid FVF\n", FVF);
2260 wined3d_mutex_lock();
2261 decl = getConvertedDecl(This, FVF);
2262 wined3d_mutex_unlock();
2266 /* Any situation when this should happen, except out of memory? */
2267 ERR("Failed to create a converted vertex declaration\n");
2268 return D3DERR_DRIVERINTERNALERROR;
2271 hr = IDirect3DDevice9Impl_SetVertexDeclaration(iface, decl);
2272 if (FAILED(hr)) ERR("Failed to set vertex declaration\n");
2277 static HRESULT WINAPI IDirect3DDevice9Impl_GetFVF(IDirect3DDevice9Ex *iface, DWORD *pFVF)
2279 IDirect3DVertexDeclaration9 *decl;
2282 TRACE("iface %p, fvf %p.\n", iface, pFVF);
2284 hr = IDirect3DDevice9_GetVertexDeclaration(iface, &decl);
2287 WARN("Failed to get vertex declaration, %#x\n", hr);
2294 *pFVF = ((IDirect3DVertexDeclaration9Impl *)decl)->convFVF;
2295 IDirect3DVertexDeclaration9_Release(decl);
2302 TRACE("Returning FVF %#x\n", *pFVF);
2307 static HRESULT WINAPI IDirect3DDevice9Impl_CreateVertexShader(IDirect3DDevice9Ex *iface,
2308 const DWORD *byte_code, IDirect3DVertexShader9 **shader)
2310 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
2311 IDirect3DVertexShader9Impl *object;
2314 TRACE("iface %p, byte_code %p, shader %p.\n", iface, byte_code, shader);
2316 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2319 ERR("Failed to allocate vertex shader memory.\n");
2320 return E_OUTOFMEMORY;
2323 hr = vertexshader_init(object, This, byte_code);
2326 WARN("Failed to initialize vertex shader, hr %#x.\n", hr);
2327 HeapFree(GetProcessHeap(), 0, object);
2331 TRACE("Created vertex shader %p.\n", object);
2332 *shader = (IDirect3DVertexShader9 *)object;
2337 static HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShader(IDirect3DDevice9Ex *iface,
2338 IDirect3DVertexShader9 *shader)
2340 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
2343 TRACE("iface %p, shader %p.\n", iface, shader);
2345 wined3d_mutex_lock();
2346 hr = IWineD3DDevice_SetVertexShader(This->WineD3DDevice,
2347 shader ? ((IDirect3DVertexShader9Impl *)shader)->wined3d_shader : NULL);
2348 wined3d_mutex_unlock();
2353 static HRESULT WINAPI IDirect3DDevice9Impl_GetVertexShader(IDirect3DDevice9Ex *iface,
2354 IDirect3DVertexShader9 **shader)
2356 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
2357 struct wined3d_shader *wined3d_shader;
2359 TRACE("iface %p, shader %p.\n", iface, shader);
2361 wined3d_mutex_lock();
2362 wined3d_shader = IWineD3DDevice_GetVertexShader(This->WineD3DDevice);
2365 *shader = wined3d_shader_get_parent(wined3d_shader);
2366 IDirect3DVertexShader9_AddRef(*shader);
2367 wined3d_shader_decref(wined3d_shader);
2373 wined3d_mutex_unlock();
2375 TRACE("Returning %p.\n", *shader);
2380 static HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShaderConstantF(IDirect3DDevice9Ex *iface,
2381 UINT reg_idx, const float *data, UINT count)
2383 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
2386 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface, reg_idx, data, count);
2388 if (reg_idx + count > D3D9_MAX_VERTEX_SHADER_CONSTANTF)
2390 WARN("Trying to access %u constants, but d3d9 only supports %u\n",
2391 reg_idx + count, D3D9_MAX_VERTEX_SHADER_CONSTANTF);
2392 return D3DERR_INVALIDCALL;
2395 wined3d_mutex_lock();
2396 hr = IWineD3DDevice_SetVertexShaderConstantF(This->WineD3DDevice, reg_idx, data, count);
2397 wined3d_mutex_unlock();
2402 static HRESULT WINAPI IDirect3DDevice9Impl_GetVertexShaderConstantF(IDirect3DDevice9Ex *iface,
2403 UINT reg_idx, float *data, UINT count)
2405 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
2408 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface, reg_idx, data, count);
2410 if (reg_idx + count > D3D9_MAX_VERTEX_SHADER_CONSTANTF)
2412 WARN("Trying to access %u constants, but d3d9 only supports %u\n",
2413 reg_idx + count, D3D9_MAX_VERTEX_SHADER_CONSTANTF);
2414 return D3DERR_INVALIDCALL;
2417 wined3d_mutex_lock();
2418 hr = IWineD3DDevice_GetVertexShaderConstantF(This->WineD3DDevice, reg_idx, data, count);
2419 wined3d_mutex_unlock();
2424 static HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShaderConstantI(IDirect3DDevice9Ex *iface,
2425 UINT reg_idx, const int *data, UINT count)
2427 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
2430 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface, reg_idx, data, count);
2432 wined3d_mutex_lock();
2433 hr = IWineD3DDevice_SetVertexShaderConstantI(This->WineD3DDevice, reg_idx, data, count);
2434 wined3d_mutex_unlock();
2439 static HRESULT WINAPI IDirect3DDevice9Impl_GetVertexShaderConstantI(IDirect3DDevice9Ex *iface,
2440 UINT reg_idx, int *data, UINT count)
2442 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
2445 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface, reg_idx, data, count);
2447 wined3d_mutex_lock();
2448 hr = IWineD3DDevice_GetVertexShaderConstantI(This->WineD3DDevice, reg_idx, data, count);
2449 wined3d_mutex_unlock();
2454 static HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShaderConstantB(IDirect3DDevice9Ex *iface,
2455 UINT reg_idx, const BOOL *data, UINT count)
2457 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
2460 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface, reg_idx, data, count);
2462 wined3d_mutex_lock();
2463 hr = IWineD3DDevice_SetVertexShaderConstantB(This->WineD3DDevice, reg_idx, data, count);
2464 wined3d_mutex_unlock();
2469 static HRESULT WINAPI IDirect3DDevice9Impl_GetVertexShaderConstantB(IDirect3DDevice9Ex *iface,
2470 UINT reg_idx, BOOL *data, UINT count)
2472 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
2475 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface, reg_idx, data, count);
2477 wined3d_mutex_lock();
2478 hr = IWineD3DDevice_GetVertexShaderConstantB(This->WineD3DDevice, reg_idx, data, count);
2479 wined3d_mutex_unlock();
2484 static HRESULT WINAPI IDirect3DDevice9Impl_SetStreamSource(IDirect3DDevice9Ex *iface,
2485 UINT StreamNumber, IDirect3DVertexBuffer9 *pStreamData, UINT OffsetInBytes, UINT Stride)
2487 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
2490 TRACE("iface %p, stream_idx %u, buffer %p, offset %u, stride %u.\n",
2491 iface, StreamNumber, pStreamData, OffsetInBytes, Stride);
2493 wined3d_mutex_lock();
2494 hr = IWineD3DDevice_SetStreamSource(This->WineD3DDevice, StreamNumber,
2495 pStreamData ? ((IDirect3DVertexBuffer9Impl *)pStreamData)->wineD3DVertexBuffer : NULL,
2496 OffsetInBytes, Stride);
2497 wined3d_mutex_unlock();
2502 static HRESULT WINAPI IDirect3DDevice9Impl_GetStreamSource(IDirect3DDevice9Ex *iface,
2503 UINT StreamNumber, IDirect3DVertexBuffer9 **pStream, UINT *OffsetInBytes, UINT *pStride)
2505 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
2506 struct wined3d_buffer *retStream = NULL;
2509 TRACE("iface %p, stream_idx %u, buffer %p, offset %p, stride %p.\n",
2510 iface, StreamNumber, pStream, OffsetInBytes, pStride);
2512 if(pStream == NULL){
2513 return D3DERR_INVALIDCALL;
2516 wined3d_mutex_lock();
2517 hr = IWineD3DDevice_GetStreamSource(This->WineD3DDevice, StreamNumber, &retStream, OffsetInBytes, pStride);
2518 if (SUCCEEDED(hr) && retStream)
2520 *pStream = wined3d_buffer_get_parent(retStream);
2521 IDirect3DVertexBuffer9_AddRef(*pStream);
2522 wined3d_buffer_decref(retStream);
2528 FIXME("Call to GetStreamSource failed %p %p\n", OffsetInBytes, pStride);
2532 wined3d_mutex_unlock();
2537 static HRESULT WINAPI IDirect3DDevice9Impl_SetStreamSourceFreq(IDirect3DDevice9Ex *iface,
2538 UINT StreamNumber, UINT Divider)
2540 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
2543 TRACE("iface %p, stream_idx %u, freq %u.\n", iface, StreamNumber, Divider);
2545 wined3d_mutex_lock();
2546 hr = IWineD3DDevice_SetStreamSourceFreq(This->WineD3DDevice, StreamNumber, Divider);
2547 wined3d_mutex_unlock();
2552 static HRESULT WINAPI IDirect3DDevice9Impl_GetStreamSourceFreq(IDirect3DDevice9Ex *iface,
2553 UINT StreamNumber, UINT *Divider)
2555 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
2558 TRACE("iface %p, stream_idx %u, freq %p.\n", iface, StreamNumber, Divider);
2560 wined3d_mutex_lock();
2561 hr = IWineD3DDevice_GetStreamSourceFreq(This->WineD3DDevice, StreamNumber, Divider);
2562 wined3d_mutex_unlock();
2567 static HRESULT WINAPI IDirect3DDevice9Impl_SetIndices(IDirect3DDevice9Ex *iface,
2568 IDirect3DIndexBuffer9 *pIndexData)
2570 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
2572 IDirect3DIndexBuffer9Impl *ib = (IDirect3DIndexBuffer9Impl *) pIndexData;
2574 TRACE("iface %p, buffer %p.\n", iface, pIndexData);
2576 wined3d_mutex_lock();
2577 hr = IWineD3DDevice_SetIndexBuffer(This->WineD3DDevice,
2578 ib ? ib->wineD3DIndexBuffer : NULL,
2579 ib ? ib->format : WINED3DFMT_UNKNOWN);
2580 wined3d_mutex_unlock();
2585 static HRESULT WINAPI IDirect3DDevice9Impl_GetIndices(IDirect3DDevice9Ex *iface,
2586 IDirect3DIndexBuffer9 **ppIndexData)
2588 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
2589 struct wined3d_buffer *retIndexData = NULL;
2592 TRACE("iface %p, buffer %p.\n", iface, ppIndexData);
2594 if(ppIndexData == NULL){
2595 return D3DERR_INVALIDCALL;
2598 wined3d_mutex_lock();
2599 hr = IWineD3DDevice_GetIndexBuffer(This->WineD3DDevice, &retIndexData);
2600 if (SUCCEEDED(hr) && retIndexData)
2602 *ppIndexData = wined3d_buffer_get_parent(retIndexData);
2603 IDirect3DIndexBuffer9_AddRef(*ppIndexData);
2604 wined3d_buffer_decref(retIndexData);
2608 if (FAILED(hr)) FIXME("Call to GetIndices failed\n");
2609 *ppIndexData = NULL;
2611 wined3d_mutex_unlock();
2616 static HRESULT WINAPI IDirect3DDevice9Impl_CreatePixelShader(IDirect3DDevice9Ex *iface,
2617 const DWORD *byte_code, IDirect3DPixelShader9 **shader)
2619 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
2620 IDirect3DPixelShader9Impl *object;
2623 TRACE("iface %p, byte_code %p, shader %p.\n", iface, byte_code, shader);
2625 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2628 FIXME("Failed to allocate pixel shader memory.\n");
2629 return E_OUTOFMEMORY;
2632 hr = pixelshader_init(object, This, byte_code);
2635 WARN("Failed to initialize pixel shader, hr %#x.\n", hr);
2636 HeapFree(GetProcessHeap(), 0, object);
2640 TRACE("Created pixel shader %p.\n", object);
2641 *shader = (IDirect3DPixelShader9 *)object;
2646 static HRESULT WINAPI IDirect3DDevice9Impl_SetPixelShader(IDirect3DDevice9Ex *iface,
2647 IDirect3DPixelShader9 *shader)
2649 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
2652 TRACE("iface %p, shader %p.\n", iface, shader);
2654 wined3d_mutex_lock();
2655 hr = IWineD3DDevice_SetPixelShader(This->WineD3DDevice,
2656 shader ? ((IDirect3DPixelShader9Impl *)shader)->wined3d_shader : NULL);
2657 wined3d_mutex_unlock();
2662 static HRESULT WINAPI IDirect3DDevice9Impl_GetPixelShader(IDirect3DDevice9Ex *iface,
2663 IDirect3DPixelShader9 **shader)
2665 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
2666 struct wined3d_shader *wined3d_shader;
2668 TRACE("iface %p, shader %p.\n", iface, shader);
2670 if (!shader) return D3DERR_INVALIDCALL;
2672 wined3d_mutex_lock();
2673 wined3d_shader = IWineD3DDevice_GetPixelShader(This->WineD3DDevice);
2676 *shader = wined3d_shader_get_parent(wined3d_shader);
2677 IDirect3DPixelShader9_AddRef(*shader);
2678 wined3d_shader_decref(wined3d_shader);
2684 wined3d_mutex_unlock();
2686 TRACE("Returning %p.\n", *shader);
2691 static HRESULT WINAPI IDirect3DDevice9Impl_SetPixelShaderConstantF(IDirect3DDevice9Ex *iface,
2692 UINT reg_idx, const float *data, UINT count)
2694 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
2697 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface, reg_idx, data, count);
2699 wined3d_mutex_lock();
2700 hr = IWineD3DDevice_SetPixelShaderConstantF(This->WineD3DDevice, reg_idx, data, count);
2701 wined3d_mutex_unlock();
2706 static HRESULT WINAPI IDirect3DDevice9Impl_GetPixelShaderConstantF(IDirect3DDevice9Ex *iface,
2707 UINT reg_idx, float *data, UINT count)
2709 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
2712 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface, reg_idx, data, count);
2714 wined3d_mutex_lock();
2715 hr = IWineD3DDevice_GetPixelShaderConstantF(This->WineD3DDevice, reg_idx, data, count);
2716 wined3d_mutex_unlock();
2721 static HRESULT WINAPI IDirect3DDevice9Impl_SetPixelShaderConstantI(IDirect3DDevice9Ex *iface,
2722 UINT reg_idx, const int *data, UINT count)
2724 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
2727 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface, reg_idx, data, count);
2729 wined3d_mutex_lock();
2730 hr = IWineD3DDevice_SetPixelShaderConstantI(This->WineD3DDevice, reg_idx, data, count);
2731 wined3d_mutex_unlock();
2736 static HRESULT WINAPI IDirect3DDevice9Impl_GetPixelShaderConstantI(IDirect3DDevice9Ex *iface,
2737 UINT reg_idx, int *data, UINT count)
2739 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
2742 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface, reg_idx, data, count);
2744 wined3d_mutex_lock();
2745 hr = IWineD3DDevice_GetPixelShaderConstantI(This->WineD3DDevice, reg_idx, data, count);
2746 wined3d_mutex_unlock();
2751 static HRESULT WINAPI IDirect3DDevice9Impl_SetPixelShaderConstantB(IDirect3DDevice9Ex *iface,
2752 UINT reg_idx, const BOOL *data, UINT count)
2754 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
2757 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface, reg_idx, data, count);
2759 wined3d_mutex_lock();
2760 hr = IWineD3DDevice_SetPixelShaderConstantB(This->WineD3DDevice, reg_idx, data, count);
2761 wined3d_mutex_unlock();
2766 static HRESULT WINAPI IDirect3DDevice9Impl_GetPixelShaderConstantB(IDirect3DDevice9Ex *iface,
2767 UINT reg_idx, BOOL *data, UINT count)
2769 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
2772 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface, reg_idx, data, count);
2774 wined3d_mutex_lock();
2775 hr = IWineD3DDevice_GetPixelShaderConstantB(This->WineD3DDevice, reg_idx, data, count);
2776 wined3d_mutex_unlock();
2781 static HRESULT WINAPI IDirect3DDevice9Impl_DrawRectPatch(IDirect3DDevice9Ex *iface, UINT Handle,
2782 const float *pNumSegs, const D3DRECTPATCH_INFO *pRectPatchInfo)
2784 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
2787 TRACE("iface %p, handle %#x, segment_count %p, patch_info %p.\n",
2788 iface, Handle, pNumSegs, pRectPatchInfo);
2790 wined3d_mutex_lock();
2791 hr = IWineD3DDevice_DrawRectPatch(This->WineD3DDevice, Handle, pNumSegs, (CONST WINED3DRECTPATCH_INFO *)pRectPatchInfo);
2792 wined3d_mutex_unlock();
2797 static HRESULT WINAPI IDirect3DDevice9Impl_DrawTriPatch(IDirect3DDevice9Ex *iface, UINT Handle,
2798 const float *pNumSegs, const D3DTRIPATCH_INFO *pTriPatchInfo)
2800 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
2803 TRACE("iface %p, handle %#x, segment_count %p, patch_info %p.\n",
2804 iface, Handle, pNumSegs, pTriPatchInfo);
2806 wined3d_mutex_lock();
2807 hr = IWineD3DDevice_DrawTriPatch(This->WineD3DDevice, Handle, pNumSegs, (CONST WINED3DTRIPATCH_INFO *)pTriPatchInfo);
2808 wined3d_mutex_unlock();
2813 static HRESULT WINAPI IDirect3DDevice9Impl_DeletePatch(IDirect3DDevice9Ex *iface, UINT Handle)
2815 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
2818 TRACE("iface %p, handle %#x.\n", iface, Handle);
2820 wined3d_mutex_lock();
2821 hr = IWineD3DDevice_DeletePatch(This->WineD3DDevice, Handle);
2822 wined3d_mutex_unlock();
2827 static HRESULT WINAPI IDirect3DDevice9Impl_CreateQuery(IDirect3DDevice9Ex *iface, D3DQUERYTYPE type,
2828 IDirect3DQuery9 **query)
2830 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
2831 IDirect3DQuery9Impl *object;
2834 TRACE("iface %p, type %#x, query %p.\n", iface, type, query);
2836 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2839 ERR("Failed to allocate query memory.\n");
2840 return E_OUTOFMEMORY;
2843 hr = query_init(object, This, type);
2846 WARN("Failed to initialize query, hr %#x.\n", hr);
2847 HeapFree(GetProcessHeap(), 0, object);
2851 TRACE("Created query %p.\n", object);
2852 if (query) *query = &object->IDirect3DQuery9_iface;
2853 else IDirect3DQuery9_Release(&object->IDirect3DQuery9_iface);
2858 static HRESULT WINAPI IDirect3DDevice9ExImpl_SetConvolutionMonoKernel(IDirect3DDevice9Ex *iface,
2859 UINT width, UINT height, float *rows, float *columns)
2861 FIXME("iface %p, width %u, height %u, rows %p, columns %p stub!\n",
2862 iface, width, height, rows, columns);
2867 static HRESULT WINAPI IDirect3DDevice9ExImpl_ComposeRects(IDirect3DDevice9Ex *iface,
2868 IDirect3DSurface9 *src_surface, IDirect3DSurface9 *dst_surface, IDirect3DVertexBuffer9 *src_descs,
2869 UINT rect_count, IDirect3DVertexBuffer9 *dst_descs, D3DCOMPOSERECTSOP operation, INT offset_x, INT offset_y)
2871 FIXME("iface %p, src_surface %p, dst_surface %p, src_descs %p, rect_count %u,\n"
2872 "dst_descs %p, operation %#x, offset_x %u, offset_y %u stub!\n",
2873 iface, src_surface, dst_surface, src_descs, rect_count,
2874 dst_descs, operation, offset_x, offset_y);
2879 static HRESULT WINAPI IDirect3DDevice9ExImpl_PresentEx(IDirect3DDevice9Ex *iface,
2880 const RECT *src_rect, const RECT *dst_rect, HWND dst_window_override,
2881 const RGNDATA *dirty_region, DWORD flags)
2883 FIXME("iface %p, src_rect %p, dst_rect %p, dst_window_override %p, dirty_region %p, flags %#x stub!\n",
2884 iface, src_rect, dst_rect, dst_window_override, dirty_region, flags);
2889 static HRESULT WINAPI IDirect3DDevice9ExImpl_GetGPUThreadPriority(IDirect3DDevice9Ex *iface, INT *priority)
2891 FIXME("iface %p, priority %p stub!\n", iface, priority);
2896 static HRESULT WINAPI IDirect3DDevice9ExImpl_SetGPUThreadPriority(IDirect3DDevice9Ex *iface, INT priority)
2898 FIXME("iface %p, priority %d stub!\n", iface, priority);
2903 static HRESULT WINAPI IDirect3DDevice9ExImpl_WaitForVBlank(IDirect3DDevice9Ex *iface, UINT swapchain_idx)
2905 FIXME("iface %p, swapchain_idx %u stub!\n", iface, swapchain_idx);
2910 static HRESULT WINAPI IDirect3DDevice9ExImpl_CheckResourceResidency(IDirect3DDevice9Ex *iface,
2911 IDirect3DResource9 **resources, UINT32 resource_count)
2913 FIXME("iface %p, resources %p, resource_count %u stub!\n",
2914 iface, resources, resource_count);
2919 static HRESULT WINAPI IDirect3DDevice9ExImpl_SetMaximumFrameLatency(IDirect3DDevice9Ex *iface, UINT max_latency)
2921 FIXME("iface %p, max_latency %u stub!\n", iface, max_latency);
2926 static HRESULT WINAPI IDirect3DDevice9ExImpl_GetMaximumFrameLatency(IDirect3DDevice9Ex *iface, UINT *max_latency)
2928 FIXME("iface %p, max_latency %p stub!\n", iface, max_latency);
2935 static HRESULT WINAPI IDirect3DDevice9ExImpl_CheckDeviceState(IDirect3DDevice9Ex *iface, HWND dst_window)
2939 TRACE("iface %p, dst_window %p stub!\n", iface, dst_window);
2942 FIXME("iface %p, dst_window %p stub!\n", iface, dst_window);
2947 static HRESULT WINAPI IDirect3DDevice9ExImpl_CreateRenderTargetEx(IDirect3DDevice9Ex *iface,
2948 UINT width, UINT height, D3DFORMAT format, D3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality,
2949 BOOL lockable, IDirect3DSurface9 **surface, HANDLE *shared_handle, DWORD usage)
2951 FIXME("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u,\n"
2952 "lockable %#x, surface %p, shared_handle %p, usage %#x stub!\n",
2953 iface, width, height, format, multisample_type, multisample_quality,
2954 lockable, surface, shared_handle, usage);
2959 static HRESULT WINAPI IDirect3DDevice9ExImpl_CreateOffscreenPlainSurfaceEx(IDirect3DDevice9Ex *iface,
2960 UINT width, UINT height, D3DFORMAT format, D3DPOOL pool, IDirect3DSurface9 **surface,
2961 HANDLE *shared_handle, DWORD usage)
2963 FIXME("iface %p, width %u, height %u, format %#x, pool %#x, surface %p, shared_handle %p, usage %#x stub!\n",
2964 iface, width, height, format, pool, surface, shared_handle, usage);
2969 static HRESULT WINAPI IDirect3DDevice9ExImpl_CreateDepthStencilSurfaceEx(IDirect3DDevice9Ex *iface,
2970 UINT width, UINT height, D3DFORMAT format, D3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality,
2971 BOOL discard, IDirect3DSurface9 **surface, HANDLE *shared_handle, DWORD usage)
2973 FIXME("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u,\n"
2974 "discard %#x, surface %p, shared_handle %p, usage %#x stub!\n",
2975 iface, width, height, format, multisample_type, multisample_quality,
2976 discard, surface, shared_handle, usage);
2981 static HRESULT WINAPI IDirect3DDevice9ExImpl_ResetEx(IDirect3DDevice9Ex *iface,
2982 D3DPRESENT_PARAMETERS *present_parameters, D3DDISPLAYMODEEX *mode)
2984 FIXME("iface %p, present_parameters %p, mode %p stub!\n", iface, present_parameters, mode);
2989 static HRESULT WINAPI IDirect3DDevice9ExImpl_GetDisplayModeEx(IDirect3DDevice9Ex *iface,
2990 UINT swapchain_idx, D3DDISPLAYMODEEX *mode, D3DDISPLAYROTATION *rotation)
2992 FIXME("iface %p, swapchain_idx %u, mode %p, rotation %p stub!\n", iface, swapchain_idx, mode, rotation);
2997 static const IDirect3DDevice9ExVtbl Direct3DDevice9_Vtbl =
3000 IDirect3DDevice9Impl_QueryInterface,
3001 IDirect3DDevice9Impl_AddRef,
3002 IDirect3DDevice9Impl_Release,
3003 /* IDirect3DDevice9 */
3004 IDirect3DDevice9Impl_TestCooperativeLevel,
3005 IDirect3DDevice9Impl_GetAvailableTextureMem,
3006 IDirect3DDevice9Impl_EvictManagedResources,
3007 IDirect3DDevice9Impl_GetDirect3D,
3008 IDirect3DDevice9Impl_GetDeviceCaps,
3009 IDirect3DDevice9Impl_GetDisplayMode,
3010 IDirect3DDevice9Impl_GetCreationParameters,
3011 IDirect3DDevice9Impl_SetCursorProperties,
3012 IDirect3DDevice9Impl_SetCursorPosition,
3013 IDirect3DDevice9Impl_ShowCursor,
3014 IDirect3DDevice9Impl_CreateAdditionalSwapChain,
3015 IDirect3DDevice9Impl_GetSwapChain,
3016 IDirect3DDevice9Impl_GetNumberOfSwapChains,
3017 IDirect3DDevice9Impl_Reset,
3018 IDirect3DDevice9Impl_Present,
3019 IDirect3DDevice9Impl_GetBackBuffer,
3020 IDirect3DDevice9Impl_GetRasterStatus,
3021 IDirect3DDevice9Impl_SetDialogBoxMode,
3022 IDirect3DDevice9Impl_SetGammaRamp,
3023 IDirect3DDevice9Impl_GetGammaRamp,
3024 IDirect3DDevice9Impl_CreateTexture,
3025 IDirect3DDevice9Impl_CreateVolumeTexture,
3026 IDirect3DDevice9Impl_CreateCubeTexture,
3027 IDirect3DDevice9Impl_CreateVertexBuffer,
3028 IDirect3DDevice9Impl_CreateIndexBuffer,
3029 IDirect3DDevice9Impl_CreateRenderTarget,
3030 IDirect3DDevice9Impl_CreateDepthStencilSurface,
3031 IDirect3DDevice9Impl_UpdateSurface,
3032 IDirect3DDevice9Impl_UpdateTexture,
3033 IDirect3DDevice9Impl_GetRenderTargetData,
3034 IDirect3DDevice9Impl_GetFrontBufferData,
3035 IDirect3DDevice9Impl_StretchRect,
3036 IDirect3DDevice9Impl_ColorFill,
3037 IDirect3DDevice9Impl_CreateOffscreenPlainSurface,
3038 IDirect3DDevice9Impl_SetRenderTarget,
3039 IDirect3DDevice9Impl_GetRenderTarget,
3040 IDirect3DDevice9Impl_SetDepthStencilSurface,
3041 IDirect3DDevice9Impl_GetDepthStencilSurface,
3042 IDirect3DDevice9Impl_BeginScene,
3043 IDirect3DDevice9Impl_EndScene,
3044 IDirect3DDevice9Impl_Clear,
3045 IDirect3DDevice9Impl_SetTransform,
3046 IDirect3DDevice9Impl_GetTransform,
3047 IDirect3DDevice9Impl_MultiplyTransform,
3048 IDirect3DDevice9Impl_SetViewport,
3049 IDirect3DDevice9Impl_GetViewport,
3050 IDirect3DDevice9Impl_SetMaterial,
3051 IDirect3DDevice9Impl_GetMaterial,
3052 IDirect3DDevice9Impl_SetLight,
3053 IDirect3DDevice9Impl_GetLight,
3054 IDirect3DDevice9Impl_LightEnable,
3055 IDirect3DDevice9Impl_GetLightEnable,
3056 IDirect3DDevice9Impl_SetClipPlane,
3057 IDirect3DDevice9Impl_GetClipPlane,
3058 IDirect3DDevice9Impl_SetRenderState,
3059 IDirect3DDevice9Impl_GetRenderState,
3060 IDirect3DDevice9Impl_CreateStateBlock,
3061 IDirect3DDevice9Impl_BeginStateBlock,
3062 IDirect3DDevice9Impl_EndStateBlock,
3063 IDirect3DDevice9Impl_SetClipStatus,
3064 IDirect3DDevice9Impl_GetClipStatus,
3065 IDirect3DDevice9Impl_GetTexture,
3066 IDirect3DDevice9Impl_SetTexture,
3067 IDirect3DDevice9Impl_GetTextureStageState,
3068 IDirect3DDevice9Impl_SetTextureStageState,
3069 IDirect3DDevice9Impl_GetSamplerState,
3070 IDirect3DDevice9Impl_SetSamplerState,
3071 IDirect3DDevice9Impl_ValidateDevice,
3072 IDirect3DDevice9Impl_SetPaletteEntries,
3073 IDirect3DDevice9Impl_GetPaletteEntries,
3074 IDirect3DDevice9Impl_SetCurrentTexturePalette,
3075 IDirect3DDevice9Impl_GetCurrentTexturePalette,
3076 IDirect3DDevice9Impl_SetScissorRect,
3077 IDirect3DDevice9Impl_GetScissorRect,
3078 IDirect3DDevice9Impl_SetSoftwareVertexProcessing,
3079 IDirect3DDevice9Impl_GetSoftwareVertexProcessing,
3080 IDirect3DDevice9Impl_SetNPatchMode,
3081 IDirect3DDevice9Impl_GetNPatchMode,
3082 IDirect3DDevice9Impl_DrawPrimitive,
3083 IDirect3DDevice9Impl_DrawIndexedPrimitive,
3084 IDirect3DDevice9Impl_DrawPrimitiveUP,
3085 IDirect3DDevice9Impl_DrawIndexedPrimitiveUP,
3086 IDirect3DDevice9Impl_ProcessVertices,
3087 IDirect3DDevice9Impl_CreateVertexDeclaration,
3088 IDirect3DDevice9Impl_SetVertexDeclaration,
3089 IDirect3DDevice9Impl_GetVertexDeclaration,
3090 IDirect3DDevice9Impl_SetFVF,
3091 IDirect3DDevice9Impl_GetFVF,
3092 IDirect3DDevice9Impl_CreateVertexShader,
3093 IDirect3DDevice9Impl_SetVertexShader,
3094 IDirect3DDevice9Impl_GetVertexShader,
3095 IDirect3DDevice9Impl_SetVertexShaderConstantF,
3096 IDirect3DDevice9Impl_GetVertexShaderConstantF,
3097 IDirect3DDevice9Impl_SetVertexShaderConstantI,
3098 IDirect3DDevice9Impl_GetVertexShaderConstantI,
3099 IDirect3DDevice9Impl_SetVertexShaderConstantB,
3100 IDirect3DDevice9Impl_GetVertexShaderConstantB,
3101 IDirect3DDevice9Impl_SetStreamSource,
3102 IDirect3DDevice9Impl_GetStreamSource,
3103 IDirect3DDevice9Impl_SetStreamSourceFreq,
3104 IDirect3DDevice9Impl_GetStreamSourceFreq,
3105 IDirect3DDevice9Impl_SetIndices,
3106 IDirect3DDevice9Impl_GetIndices,
3107 IDirect3DDevice9Impl_CreatePixelShader,
3108 IDirect3DDevice9Impl_SetPixelShader,
3109 IDirect3DDevice9Impl_GetPixelShader,
3110 IDirect3DDevice9Impl_SetPixelShaderConstantF,
3111 IDirect3DDevice9Impl_GetPixelShaderConstantF,
3112 IDirect3DDevice9Impl_SetPixelShaderConstantI,
3113 IDirect3DDevice9Impl_GetPixelShaderConstantI,
3114 IDirect3DDevice9Impl_SetPixelShaderConstantB,
3115 IDirect3DDevice9Impl_GetPixelShaderConstantB,
3116 IDirect3DDevice9Impl_DrawRectPatch,
3117 IDirect3DDevice9Impl_DrawTriPatch,
3118 IDirect3DDevice9Impl_DeletePatch,
3119 IDirect3DDevice9Impl_CreateQuery,
3120 /* IDirect3DDevice9Ex */
3121 IDirect3DDevice9ExImpl_SetConvolutionMonoKernel,
3122 IDirect3DDevice9ExImpl_ComposeRects,
3123 IDirect3DDevice9ExImpl_PresentEx,
3124 IDirect3DDevice9ExImpl_GetGPUThreadPriority,
3125 IDirect3DDevice9ExImpl_SetGPUThreadPriority,
3126 IDirect3DDevice9ExImpl_WaitForVBlank,
3127 IDirect3DDevice9ExImpl_CheckResourceResidency,
3128 IDirect3DDevice9ExImpl_SetMaximumFrameLatency,
3129 IDirect3DDevice9ExImpl_GetMaximumFrameLatency,
3130 IDirect3DDevice9ExImpl_CheckDeviceState,
3131 IDirect3DDevice9ExImpl_CreateRenderTargetEx,
3132 IDirect3DDevice9ExImpl_CreateOffscreenPlainSurfaceEx,
3133 IDirect3DDevice9ExImpl_CreateDepthStencilSurfaceEx,
3134 IDirect3DDevice9ExImpl_ResetEx,
3135 IDirect3DDevice9ExImpl_GetDisplayModeEx
3138 /* IWineD3DDeviceParent IUnknown methods */
3140 static inline struct IDirect3DDevice9Impl *device_from_device_parent(IWineD3DDeviceParent *iface)
3142 return (struct IDirect3DDevice9Impl *)((char*)iface
3143 - FIELD_OFFSET(struct IDirect3DDevice9Impl, device_parent_vtbl));
3146 static HRESULT STDMETHODCALLTYPE device_parent_QueryInterface(IWineD3DDeviceParent *iface,
3147 REFIID riid, void **object)
3149 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
3150 return IDirect3DDevice9Impl_QueryInterface(&This->IDirect3DDevice9Ex_iface, riid, object);
3153 static ULONG STDMETHODCALLTYPE device_parent_AddRef(IWineD3DDeviceParent *iface)
3155 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
3156 return IDirect3DDevice9Impl_AddRef(&This->IDirect3DDevice9Ex_iface);
3159 static ULONG STDMETHODCALLTYPE device_parent_Release(IWineD3DDeviceParent *iface)
3161 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
3162 return IDirect3DDevice9Impl_Release(&This->IDirect3DDevice9Ex_iface);
3165 /* IWineD3DDeviceParent methods */
3167 static void STDMETHODCALLTYPE device_parent_WineD3DDeviceCreated(IWineD3DDeviceParent *iface, IWineD3DDevice *device)
3169 TRACE("iface %p, device %p\n", iface, device);
3172 static HRESULT STDMETHODCALLTYPE device_parent_CreateSurface(IWineD3DDeviceParent *iface,
3173 void *container_parent, UINT width, UINT height, enum wined3d_format_id format, DWORD usage,
3174 WINED3DPOOL pool, UINT level, WINED3DCUBEMAP_FACES face, IWineD3DSurface **surface)
3176 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
3177 IDirect3DSurface9Impl *d3d_surface;
3178 BOOL lockable = TRUE;
3181 TRACE("iface %p, container_parent %p, width %u, height %u, format %#x, usage %#x,\n"
3182 "\tpool %#x, level %u, face %u, surface %p\n",
3183 iface, container_parent, width, height, format, usage, pool, level, face, surface);
3185 if (pool == WINED3DPOOL_DEFAULT && !(usage & D3DUSAGE_DYNAMIC))
3188 hr = IDirect3DDevice9Impl_CreateSurface(This, width, height,
3189 d3dformat_from_wined3dformat(format), lockable, FALSE /* Discard */, level,
3190 (IDirect3DSurface9 **)&d3d_surface, usage, pool, D3DMULTISAMPLE_NONE, 0 /* MultisampleQuality */);
3193 ERR("(%p) CreateSurface failed, returning %#x\n", iface, hr);
3197 *surface = d3d_surface->wineD3DSurface;
3198 IWineD3DSurface_AddRef(*surface);
3200 d3d_surface->container = container_parent;
3201 IDirect3DDevice9Ex_Release(d3d_surface->parentDevice);
3202 d3d_surface->parentDevice = NULL;
3204 IDirect3DSurface9_Release((IDirect3DSurface9 *)d3d_surface);
3205 d3d_surface->forwardReference = container_parent;
3210 static HRESULT STDMETHODCALLTYPE device_parent_CreateRenderTarget(IWineD3DDeviceParent *iface,
3211 void *container_parent, UINT width, UINT height, enum wined3d_format_id format,
3212 WINED3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality, BOOL lockable,
3213 IWineD3DSurface **surface)
3215 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
3216 IDirect3DSurface9Impl *d3d_surface;
3219 TRACE("iface %p, container_parent %p, width %u, height %u, format %#x, multisample_type %#x,\n"
3220 "\tmultisample_quality %u, lockable %u, surface %p\n",
3221 iface, container_parent, width, height, format, multisample_type, multisample_quality, lockable, surface);
3223 hr = IDirect3DDevice9Impl_CreateRenderTarget(&This->IDirect3DDevice9Ex_iface, width, height,
3224 d3dformat_from_wined3dformat(format), multisample_type, multisample_quality, lockable,
3225 (IDirect3DSurface9 **)&d3d_surface, NULL);
3228 ERR("(%p) CreateRenderTarget failed, returning %#x\n", iface, hr);
3232 *surface = d3d_surface->wineD3DSurface;
3233 IWineD3DSurface_AddRef(*surface);
3235 d3d_surface->container = container_parent;
3236 /* Implicit surfaces are created with an refcount of 0 */
3237 IDirect3DSurface9_Release((IDirect3DSurface9 *)d3d_surface);
3242 static HRESULT STDMETHODCALLTYPE device_parent_CreateDepthStencilSurface(IWineD3DDeviceParent *iface,
3243 UINT width, UINT height, enum wined3d_format_id format, WINED3DMULTISAMPLE_TYPE multisample_type,
3244 DWORD multisample_quality, BOOL discard, IWineD3DSurface **surface)
3246 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
3247 IDirect3DSurface9Impl *d3d_surface;
3250 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x,\n"
3251 "\tmultisample_quality %u, discard %u, surface %p\n",
3252 iface, width, height, format, multisample_type, multisample_quality, discard, surface);
3254 hr = IDirect3DDevice9Impl_CreateDepthStencilSurface(&This->IDirect3DDevice9Ex_iface, width,
3255 height, d3dformat_from_wined3dformat(format), multisample_type, multisample_quality,
3256 discard, (IDirect3DSurface9 **)&d3d_surface, NULL);
3259 ERR("(%p) CreateDepthStencilSurface failed, returning %#x\n", iface, hr);
3263 *surface = d3d_surface->wineD3DSurface;
3264 IWineD3DSurface_AddRef(*surface);
3265 d3d_surface->container = (IUnknown *)&This->IDirect3DDevice9Ex_iface;
3266 /* Implicit surfaces are created with an refcount of 0 */
3267 IDirect3DSurface9_Release((IDirect3DSurface9 *)d3d_surface);
3272 static HRESULT STDMETHODCALLTYPE device_parent_CreateVolume(IWineD3DDeviceParent *iface,
3273 void *container_parent, UINT width, UINT height, UINT depth, enum wined3d_format_id format,
3274 WINED3DPOOL pool, DWORD usage, struct wined3d_volume **volume)
3276 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
3277 IDirect3DVolume9Impl *object;
3280 TRACE("iface %p, container_parent %p, width %u, height %u, depth %u, format %#x, pool %#x, usage %#x, volume %p\n",
3281 iface, container_parent, width, height, depth, format, pool, usage, volume);
3283 /* Allocate the storage for the device */
3284 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
3287 FIXME("Allocation of memory failed\n");
3289 return D3DERR_OUTOFVIDEOMEMORY;
3292 hr = volume_init(object, This, width, height, depth, usage, format, pool);
3295 WARN("Failed to initialize volume, hr %#x.\n", hr);
3296 HeapFree(GetProcessHeap(), 0, object);
3300 *volume = object->wined3d_volume;
3301 wined3d_volume_incref(*volume);
3302 IDirect3DVolume9_Release(&object->IDirect3DVolume9_iface);
3304 object->container = container_parent;
3305 object->forwardReference = container_parent;
3307 TRACE("(%p) Created volume %p\n", iface, object);
3312 static HRESULT STDMETHODCALLTYPE device_parent_CreateSwapChain(IWineD3DDeviceParent *iface,
3313 WINED3DPRESENT_PARAMETERS *present_parameters, struct wined3d_swapchain **swapchain)
3315 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
3316 D3DPRESENT_PARAMETERS local_parameters;
3317 IDirect3DSwapChain9 *d3d_swapchain;
3320 TRACE("iface %p, present_parameters %p, swapchain %p\n", iface, present_parameters, swapchain);
3322 /* Copy the presentation parameters */
3323 local_parameters.BackBufferWidth = present_parameters->BackBufferWidth;
3324 local_parameters.BackBufferHeight = present_parameters->BackBufferHeight;
3325 local_parameters.BackBufferFormat = d3dformat_from_wined3dformat(present_parameters->BackBufferFormat);
3326 local_parameters.BackBufferCount = present_parameters->BackBufferCount;
3327 local_parameters.MultiSampleType = present_parameters->MultiSampleType;
3328 local_parameters.MultiSampleQuality = present_parameters->MultiSampleQuality;
3329 local_parameters.SwapEffect = present_parameters->SwapEffect;
3330 local_parameters.hDeviceWindow = present_parameters->hDeviceWindow;
3331 local_parameters.Windowed = present_parameters->Windowed;
3332 local_parameters.EnableAutoDepthStencil = present_parameters->EnableAutoDepthStencil;
3333 local_parameters.AutoDepthStencilFormat = d3dformat_from_wined3dformat(present_parameters->AutoDepthStencilFormat);
3334 local_parameters.Flags = present_parameters->Flags;
3335 local_parameters.FullScreen_RefreshRateInHz = present_parameters->FullScreen_RefreshRateInHz;
3336 local_parameters.PresentationInterval = present_parameters->PresentationInterval;
3338 hr = IDirect3DDevice9Impl_CreateAdditionalSwapChain(&This->IDirect3DDevice9Ex_iface,
3339 &local_parameters, &d3d_swapchain);
3342 ERR("(%p) CreateAdditionalSwapChain failed, returning %#x\n", iface, hr);
3347 *swapchain = ((IDirect3DSwapChain9Impl *)d3d_swapchain)->wined3d_swapchain;
3348 wined3d_swapchain_incref(*swapchain);
3349 IDirect3DSwapChain9_Release((IDirect3DSwapChain9 *)d3d_swapchain);
3351 /* Copy back the presentation parameters */
3352 present_parameters->BackBufferWidth = local_parameters.BackBufferWidth;
3353 present_parameters->BackBufferHeight = local_parameters.BackBufferHeight;
3354 present_parameters->BackBufferFormat = wined3dformat_from_d3dformat(local_parameters.BackBufferFormat);
3355 present_parameters->BackBufferCount = local_parameters.BackBufferCount;
3356 present_parameters->MultiSampleType = local_parameters.MultiSampleType;
3357 present_parameters->MultiSampleQuality = local_parameters.MultiSampleQuality;
3358 present_parameters->SwapEffect = local_parameters.SwapEffect;
3359 present_parameters->hDeviceWindow = local_parameters.hDeviceWindow;
3360 present_parameters->Windowed = local_parameters.Windowed;
3361 present_parameters->EnableAutoDepthStencil = local_parameters.EnableAutoDepthStencil;
3362 present_parameters->AutoDepthStencilFormat = wined3dformat_from_d3dformat(local_parameters.AutoDepthStencilFormat);
3363 present_parameters->Flags = local_parameters.Flags;
3364 present_parameters->FullScreen_RefreshRateInHz = local_parameters.FullScreen_RefreshRateInHz;
3365 present_parameters->PresentationInterval = local_parameters.PresentationInterval;
3370 static const IWineD3DDeviceParentVtbl d3d9_wined3d_device_parent_vtbl =
3372 /* IUnknown methods */
3373 device_parent_QueryInterface,
3374 device_parent_AddRef,
3375 device_parent_Release,
3376 /* IWineD3DDeviceParent methods */
3377 device_parent_WineD3DDeviceCreated,
3378 device_parent_CreateSurface,
3379 device_parent_CreateRenderTarget,
3380 device_parent_CreateDepthStencilSurface,
3381 device_parent_CreateVolume,
3382 device_parent_CreateSwapChain,
3385 static void setup_fpu(void)
3387 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
3389 __asm__ volatile ("fnstcw %0" : "=m" (cw));
3390 cw = (cw & ~0xf3f) | 0x3f;
3391 __asm__ volatile ("fldcw %0" : : "m" (cw));
3393 FIXME("FPU setup not implemented for this platform.\n");
3397 HRESULT device_init(IDirect3DDevice9Impl *device, struct wined3d *wined3d, UINT adapter, D3DDEVTYPE device_type,
3398 HWND focus_window, DWORD flags, D3DPRESENT_PARAMETERS *parameters, D3DDISPLAYMODEEX *mode)
3400 WINED3DPRESENT_PARAMETERS *wined3d_parameters;
3405 FIXME("Ignoring display mode.\n");
3407 device->IDirect3DDevice9Ex_iface.lpVtbl = &Direct3DDevice9_Vtbl;
3408 device->device_parent_vtbl = &d3d9_wined3d_device_parent_vtbl;
3411 if (!(flags & D3DCREATE_FPU_PRESERVE)) setup_fpu();
3413 wined3d_mutex_lock();
3414 hr = wined3d_device_create(wined3d, adapter, device_type, focus_window, flags,
3415 (IWineD3DDeviceParent *)&device->device_parent_vtbl, &device->WineD3DDevice);
3418 WARN("Failed to create wined3d device, hr %#x.\n", hr);
3419 wined3d_mutex_unlock();
3423 if (flags & D3DCREATE_ADAPTERGROUP_DEVICE)
3427 wined3d_get_device_caps(wined3d, adapter, device_type, &caps);
3428 count = caps.NumberOfAdaptersInGroup;
3431 if (flags & D3DCREATE_MULTITHREADED) IWineD3DDevice_SetMultithreaded(device->WineD3DDevice);
3433 if (!parameters->Windowed)
3435 if (!focus_window) focus_window = parameters->hDeviceWindow;
3436 if (FAILED(hr = IWineD3DDevice_AcquireFocusWindow(device->WineD3DDevice, focus_window)))
3438 ERR("Failed to acquire focus window, hr %#x.\n", hr);
3439 IWineD3DDevice_Release(device->WineD3DDevice);
3440 wined3d_mutex_unlock();
3444 for (i = 0; i < count; ++i)
3446 HWND device_window = parameters[i].hDeviceWindow;
3448 if (!device_window) device_window = focus_window;
3449 IWineD3DDevice_SetupFullscreenWindow(device->WineD3DDevice, device_window,
3450 parameters[i].BackBufferWidth,
3451 parameters[i].BackBufferHeight);
3455 wined3d_parameters = HeapAlloc(GetProcessHeap(), 0, sizeof(*wined3d_parameters) * count);
3456 if (!wined3d_parameters)
3458 ERR("Failed to allocate wined3d parameters.\n");
3459 IWineD3DDevice_Release(device->WineD3DDevice);
3460 wined3d_mutex_unlock();
3461 return E_OUTOFMEMORY;
3464 for (i = 0; i < count; ++i)
3466 wined3d_parameters[i].BackBufferWidth = parameters[i].BackBufferWidth;
3467 wined3d_parameters[i].BackBufferHeight = parameters[i].BackBufferHeight;
3468 wined3d_parameters[i].BackBufferFormat = wined3dformat_from_d3dformat(parameters[i].BackBufferFormat);
3469 wined3d_parameters[i].BackBufferCount = parameters[i].BackBufferCount;
3470 wined3d_parameters[i].MultiSampleType = parameters[i].MultiSampleType;
3471 wined3d_parameters[i].MultiSampleQuality = parameters[i].MultiSampleQuality;
3472 wined3d_parameters[i].SwapEffect = parameters[i].SwapEffect;
3473 wined3d_parameters[i].hDeviceWindow = parameters[i].hDeviceWindow;
3474 wined3d_parameters[i].Windowed = parameters[i].Windowed;
3475 wined3d_parameters[i].EnableAutoDepthStencil = parameters[i].EnableAutoDepthStencil;
3476 wined3d_parameters[i].AutoDepthStencilFormat =
3477 wined3dformat_from_d3dformat(parameters[i].AutoDepthStencilFormat);
3478 wined3d_parameters[i].Flags = parameters[i].Flags;
3479 wined3d_parameters[i].FullScreen_RefreshRateInHz = parameters[i].FullScreen_RefreshRateInHz;
3480 wined3d_parameters[i].PresentationInterval = parameters[i].PresentationInterval;
3481 wined3d_parameters[i].AutoRestoreDisplayMode = TRUE;
3484 hr = IWineD3DDevice_Init3D(device->WineD3DDevice, wined3d_parameters);
3487 WARN("Failed to initialize 3D, hr %#x.\n", hr);
3488 IWineD3DDevice_ReleaseFocusWindow(device->WineD3DDevice);
3489 HeapFree(GetProcessHeap(), 0, wined3d_parameters);
3490 IWineD3DDevice_Release(device->WineD3DDevice);
3491 wined3d_mutex_unlock();
3495 wined3d_mutex_unlock();
3497 for (i = 0; i < count; ++i)
3499 parameters[i].BackBufferWidth = wined3d_parameters[i].BackBufferWidth;
3500 parameters[i].BackBufferHeight = wined3d_parameters[i].BackBufferHeight;
3501 parameters[i].BackBufferFormat = d3dformat_from_wined3dformat(wined3d_parameters[i].BackBufferFormat);
3502 parameters[i].BackBufferCount = wined3d_parameters[i].BackBufferCount;
3503 parameters[i].MultiSampleType = wined3d_parameters[i].MultiSampleType;
3504 parameters[i].MultiSampleQuality = wined3d_parameters[i].MultiSampleQuality;
3505 parameters[i].SwapEffect = wined3d_parameters[i].SwapEffect;
3506 parameters[i].hDeviceWindow = wined3d_parameters[i].hDeviceWindow;
3507 parameters[i].Windowed = wined3d_parameters[i].Windowed;
3508 parameters[i].EnableAutoDepthStencil = wined3d_parameters[i].EnableAutoDepthStencil;
3509 parameters[i].AutoDepthStencilFormat =
3510 d3dformat_from_wined3dformat(wined3d_parameters[i].AutoDepthStencilFormat);
3511 parameters[i].Flags = wined3d_parameters[i].Flags;
3512 parameters[i].FullScreen_RefreshRateInHz = wined3d_parameters[i].FullScreen_RefreshRateInHz;
3513 parameters[i].PresentationInterval = wined3d_parameters[i].PresentationInterval;
3515 HeapFree(GetProcessHeap(), 0, wined3d_parameters);
3517 /* Initialize the converted declaration array. This creates a valid pointer
3518 * and when adding decls HeapReAlloc() can be used without further checking. */
3519 device->convertedDecls = HeapAlloc(GetProcessHeap(), 0, 0);
3520 if (!device->convertedDecls)
3522 ERR("Failed to allocate FVF vertex declaration map memory.\n");
3523 wined3d_mutex_lock();
3524 IWineD3DDevice_Uninit3D(device->WineD3DDevice);
3525 IWineD3DDevice_ReleaseFocusWindow(device->WineD3DDevice);
3526 IWineD3DDevice_Release(device->WineD3DDevice);
3527 wined3d_mutex_unlock();
3528 return E_OUTOFMEMORY;