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->wined3d_surface);
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 struct wined3d_resource_desc desc;
544 BOOL *resources_ok = data;
546 wined3d_resource_get_desc(resource, &desc);
547 if (desc.pool == WINED3DPOOL_DEFAULT)
549 IDirect3DSurface9 *surface;
551 if (desc.resource_type != WINED3DRTYPE_SURFACE)
553 WARN("Resource %p in pool D3DPOOL_DEFAULT blocks the Reset call.\n", resource);
554 *resources_ok = FALSE;
558 surface = wined3d_resource_get_parent(resource);
560 IDirect3DSurface9_AddRef(surface);
561 if (IDirect3DSurface9_Release(surface))
563 WARN("Surface %p (resource %p) in pool D3DPOOL_DEFAULT blocks the Reset call.\n", surface, resource);
564 *resources_ok = FALSE;
568 WARN("Surface %p (resource %p) is an implicit resource with ref 0.\n", surface, resource);
574 static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_Reset(IDirect3DDevice9Ex *iface,
575 D3DPRESENT_PARAMETERS *pPresentationParameters)
577 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
578 WINED3DPRESENT_PARAMETERS localParameters;
580 BOOL resources_ok = TRUE;
583 TRACE("iface %p, present_parameters %p.\n", iface, pPresentationParameters);
585 /* Reset states that hold a COM object. WineD3D holds an internal reference to set objects, because
586 * such objects can still be used for rendering after their external d3d9 object has been destroyed.
587 * These objects must not be enumerated. Unsetting them tells WineD3D that the application will not
588 * make use of the hidden reference and destroys the objects.
590 * Unsetting them is no problem, because the states are supposed to be reset anyway. If the validation
591 * below fails, the device is considered "lost", and _Reset and _Release are the only allowed calls
593 wined3d_mutex_lock();
594 IWineD3DDevice_SetIndexBuffer(This->WineD3DDevice, NULL, WINED3DFMT_UNKNOWN);
595 for(i = 0; i < 16; i++) {
596 IWineD3DDevice_SetStreamSource(This->WineD3DDevice, i, NULL, 0, 0);
598 for(i = 0; i < 16; i++) {
599 IWineD3DDevice_SetTexture(This->WineD3DDevice, i, NULL);
602 IWineD3DDevice_EnumResources(This->WineD3DDevice, reset_enum_callback, &resources_ok);
604 WARN("The application is holding D3DPOOL_DEFAULT resources, rejecting reset\n");
605 This->notreset = TRUE;
606 wined3d_mutex_unlock();
608 return D3DERR_INVALIDCALL;
611 localParameters.BackBufferWidth = pPresentationParameters->BackBufferWidth;
612 localParameters.BackBufferHeight = pPresentationParameters->BackBufferHeight;
613 localParameters.BackBufferFormat = wined3dformat_from_d3dformat(pPresentationParameters->BackBufferFormat);
614 localParameters.BackBufferCount = pPresentationParameters->BackBufferCount;
615 localParameters.MultiSampleType = pPresentationParameters->MultiSampleType;
616 localParameters.MultiSampleQuality = pPresentationParameters->MultiSampleQuality;
617 localParameters.SwapEffect = pPresentationParameters->SwapEffect;
618 localParameters.hDeviceWindow = pPresentationParameters->hDeviceWindow;
619 localParameters.Windowed = pPresentationParameters->Windowed;
620 localParameters.EnableAutoDepthStencil = pPresentationParameters->EnableAutoDepthStencil;
621 localParameters.AutoDepthStencilFormat = wined3dformat_from_d3dformat(pPresentationParameters->AutoDepthStencilFormat);
622 localParameters.Flags = pPresentationParameters->Flags;
623 localParameters.FullScreen_RefreshRateInHz = pPresentationParameters->FullScreen_RefreshRateInHz;
624 localParameters.PresentationInterval = pPresentationParameters->PresentationInterval;
625 localParameters.AutoRestoreDisplayMode = TRUE;
627 hr = IWineD3DDevice_Reset(This->WineD3DDevice, &localParameters);
629 This->notreset = TRUE;
631 pPresentationParameters->BackBufferWidth = localParameters.BackBufferWidth;
632 pPresentationParameters->BackBufferHeight = localParameters.BackBufferHeight;
633 pPresentationParameters->BackBufferFormat = d3dformat_from_wined3dformat(localParameters.BackBufferFormat);
634 pPresentationParameters->BackBufferCount = localParameters.BackBufferCount;
635 pPresentationParameters->MultiSampleType = localParameters.MultiSampleType;
636 pPresentationParameters->MultiSampleQuality = localParameters.MultiSampleQuality;
637 pPresentationParameters->SwapEffect = localParameters.SwapEffect;
638 pPresentationParameters->hDeviceWindow = localParameters.hDeviceWindow;
639 pPresentationParameters->Windowed = localParameters.Windowed;
640 pPresentationParameters->EnableAutoDepthStencil = localParameters.EnableAutoDepthStencil;
641 pPresentationParameters->AutoDepthStencilFormat = d3dformat_from_wined3dformat(localParameters.AutoDepthStencilFormat);
642 pPresentationParameters->Flags = localParameters.Flags;
643 pPresentationParameters->FullScreen_RefreshRateInHz = localParameters.FullScreen_RefreshRateInHz;
644 pPresentationParameters->PresentationInterval = localParameters.PresentationInterval;
646 This->notreset = FALSE;
649 wined3d_mutex_unlock();
654 static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_Present(IDirect3DDevice9Ex *iface,
655 const RECT *pSourceRect, const RECT *pDestRect, HWND hDestWindowOverride,
656 const RGNDATA *pDirtyRegion)
658 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
661 TRACE("iface %p, src_rect %p, dst_rect %p, dst_window_override %p, dirty_region %p.\n",
662 iface, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
664 wined3d_mutex_lock();
665 hr = IWineD3DDevice_Present(This->WineD3DDevice, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
666 wined3d_mutex_unlock();
671 static HRESULT WINAPI IDirect3DDevice9Impl_GetBackBuffer(IDirect3DDevice9Ex *iface,
672 UINT iSwapChain, UINT BackBuffer, D3DBACKBUFFER_TYPE Type, IDirect3DSurface9 **ppBackBuffer)
674 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
675 struct wined3d_surface *wined3d_surface = NULL;
678 TRACE("iface %p, swapchain %u, backbuffer_idx %u, backbuffer_type %#x, backbuffer %p.\n",
679 iface, iSwapChain, BackBuffer, Type, ppBackBuffer);
681 wined3d_mutex_lock();
682 hr = IWineD3DDevice_GetBackBuffer(This->WineD3DDevice, iSwapChain,
683 BackBuffer, (WINED3DBACKBUFFER_TYPE) Type, &wined3d_surface);
684 if (SUCCEEDED(hr) && wined3d_surface && ppBackBuffer)
686 *ppBackBuffer = wined3d_surface_get_parent(wined3d_surface);
687 IDirect3DSurface9_AddRef(*ppBackBuffer);
688 wined3d_surface_decref(wined3d_surface);
690 wined3d_mutex_unlock();
694 static HRESULT WINAPI IDirect3DDevice9Impl_GetRasterStatus(IDirect3DDevice9Ex *iface,
695 UINT iSwapChain, D3DRASTER_STATUS *pRasterStatus)
697 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
700 TRACE("iface %p, swapchain %u, raster_status %p.\n", iface, iSwapChain, pRasterStatus);
702 wined3d_mutex_lock();
703 hr = IWineD3DDevice_GetRasterStatus(This->WineD3DDevice, iSwapChain, (WINED3DRASTER_STATUS *) pRasterStatus);
704 wined3d_mutex_unlock();
709 static HRESULT WINAPI IDirect3DDevice9Impl_SetDialogBoxMode(IDirect3DDevice9Ex *iface,
712 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
715 TRACE("iface %p, enable %#x.\n", iface, bEnableDialogs);
717 wined3d_mutex_lock();
718 hr = IWineD3DDevice_SetDialogBoxMode(This->WineD3DDevice, bEnableDialogs);
719 wined3d_mutex_unlock();
724 static void WINAPI IDirect3DDevice9Impl_SetGammaRamp(IDirect3DDevice9Ex *iface, UINT iSwapChain,
725 DWORD Flags, const D3DGAMMARAMP *pRamp)
727 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
729 TRACE("iface %p, swapchain %u, flags %#x, ramp %p.\n", iface, iSwapChain, Flags, pRamp);
731 /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
732 wined3d_mutex_lock();
733 IWineD3DDevice_SetGammaRamp(This->WineD3DDevice, iSwapChain, Flags, (CONST WINED3DGAMMARAMP *)pRamp);
734 wined3d_mutex_unlock();
737 static void WINAPI IDirect3DDevice9Impl_GetGammaRamp(IDirect3DDevice9Ex *iface, UINT iSwapChain,
740 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
742 TRACE("iface %p, swapchain %u, ramp %p.\n", iface, iSwapChain, pRamp);
744 /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
745 wined3d_mutex_lock();
746 IWineD3DDevice_GetGammaRamp(This->WineD3DDevice, iSwapChain, (WINED3DGAMMARAMP *) pRamp);
747 wined3d_mutex_unlock();
750 static HRESULT WINAPI IDirect3DDevice9Impl_CreateTexture(IDirect3DDevice9Ex *iface,
751 UINT width, UINT height, UINT levels, DWORD usage, D3DFORMAT format,
752 D3DPOOL pool, IDirect3DTexture9 **texture, HANDLE *shared_handle)
754 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
755 IDirect3DTexture9Impl *object;
758 TRACE("iface %p, width %u, height %u, levels %u, usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n",
759 iface, width, height, levels, usage, format, pool, texture, shared_handle);
761 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
764 ERR("Failed to allocate texture memory.\n");
765 return D3DERR_OUTOFVIDEOMEMORY;
768 hr = texture_init(object, This, width, height, levels, usage, format, pool);
771 WARN("Failed to initialize texture, hr %#x.\n", hr);
772 HeapFree(GetProcessHeap(), 0, object);
776 TRACE("Created texture %p.\n", object);
777 *texture = &object->IDirect3DTexture9_iface;
782 static HRESULT WINAPI IDirect3DDevice9Impl_CreateVolumeTexture(IDirect3DDevice9Ex *iface,
783 UINT width, UINT height, UINT depth, UINT levels, DWORD usage, D3DFORMAT format,
784 D3DPOOL pool, IDirect3DVolumeTexture9 **texture, HANDLE *shared_handle)
786 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
787 IDirect3DVolumeTexture9Impl *object;
790 TRACE("iface %p, width %u, height %u, depth %u, levels %u\n",
791 iface, width, height, depth, levels);
792 TRACE("usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n",
793 usage, format, pool, texture, shared_handle);
795 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
798 ERR("Failed to allocate volume texture memory.\n");
799 return D3DERR_OUTOFVIDEOMEMORY;
802 hr = volumetexture_init(object, This, width, height, depth, levels, usage, format, pool);
805 WARN("Failed to initialize volume texture, hr %#x.\n", hr);
806 HeapFree(GetProcessHeap(), 0, object);
810 TRACE("Created volume texture %p.\n", object);
811 *texture = &object->IDirect3DVolumeTexture9_iface;
816 static HRESULT WINAPI IDirect3DDevice9Impl_CreateCubeTexture(IDirect3DDevice9Ex *iface,
817 UINT edge_length, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool,
818 IDirect3DCubeTexture9 **texture, HANDLE *shared_handle)
820 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
821 IDirect3DCubeTexture9Impl *object;
824 TRACE("iface %p, edge_length %u, levels %u, usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n",
825 iface, edge_length, levels, usage, format, pool, texture, shared_handle);
827 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
830 ERR("Failed to allocate cube texture memory.\n");
831 return D3DERR_OUTOFVIDEOMEMORY;
834 hr = cubetexture_init(object, This, edge_length, levels, usage, format, pool);
837 WARN("Failed to initialize cube texture, hr %#x.\n", hr);
838 HeapFree(GetProcessHeap(), 0, object);
842 TRACE("Created cube texture %p.\n", object);
843 *texture = &object->IDirect3DCubeTexture9_iface;
848 static HRESULT WINAPI IDirect3DDevice9Impl_CreateVertexBuffer(IDirect3DDevice9Ex *iface, UINT size,
849 DWORD usage, DWORD fvf, D3DPOOL pool, IDirect3DVertexBuffer9 **buffer,
850 HANDLE *shared_handle)
852 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
853 IDirect3DVertexBuffer9Impl *object;
856 TRACE("iface %p, size %u, usage %#x, fvf %#x, pool %#x, buffer %p, shared_handle %p.\n",
857 iface, size, usage, fvf, pool, buffer, shared_handle);
859 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
862 ERR("Failed to allocate buffer memory.\n");
863 return D3DERR_OUTOFVIDEOMEMORY;
866 hr = vertexbuffer_init(object, This, size, usage, fvf, pool);
869 WARN("Failed to initialize vertex buffer, hr %#x.\n", hr);
870 HeapFree(GetProcessHeap(), 0, object);
874 TRACE("Created vertex buffer %p.\n", object);
875 *buffer = (IDirect3DVertexBuffer9 *)object;
880 static HRESULT WINAPI IDirect3DDevice9Impl_CreateIndexBuffer(IDirect3DDevice9Ex *iface, UINT size,
881 DWORD usage, D3DFORMAT format, D3DPOOL pool, IDirect3DIndexBuffer9 **buffer,
882 HANDLE *shared_handle)
884 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
885 IDirect3DIndexBuffer9Impl *object;
888 TRACE("iface %p, size %u, usage %#x, format %#x, pool %#x, buffer %p, shared_handle %p.\n",
889 iface, size, usage, format, pool, buffer, shared_handle);
891 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
894 ERR("Failed to allocate buffer memory.\n");
895 return D3DERR_OUTOFVIDEOMEMORY;
898 hr = indexbuffer_init(object, This, size, usage, format, pool);
901 WARN("Failed to initialize index buffer, hr %#x.\n", hr);
902 HeapFree(GetProcessHeap(), 0, object);
906 TRACE("Created index buffer %p.\n", object);
907 *buffer = (IDirect3DIndexBuffer9 *)object;
912 static HRESULT IDirect3DDevice9Impl_CreateSurface(IDirect3DDevice9Impl *device, UINT Width,
913 UINT Height, D3DFORMAT Format, BOOL Lockable, BOOL Discard, UINT Level,
914 IDirect3DSurface9 **ppSurface, UINT Usage, D3DPOOL Pool, D3DMULTISAMPLE_TYPE MultiSample,
915 DWORD MultisampleQuality)
917 IDirect3DSurface9Impl *object;
920 TRACE("device %p, width %u, height %u, format %#x, lockable %#x, discard %#x, level %u, surface %p.\n"
921 "usage %#x, pool %#x, multisample_type %#x, multisample_quality %u.\n",
922 device, Width, Height, Format, Lockable, Discard, Level, ppSurface, Usage, Pool,
923 MultiSample, MultisampleQuality);
925 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DSurface9Impl));
928 FIXME("Failed to allocate surface memory.\n");
929 return D3DERR_OUTOFVIDEOMEMORY;
932 hr = surface_init(object, device, Width, Height, Format, Lockable, Discard, Level, Usage, Pool,
933 MultiSample, MultisampleQuality);
936 WARN("Failed to initialize surface, hr %#x.\n", hr);
937 HeapFree(GetProcessHeap(), 0, object);
941 TRACE("Created surface %p.\n", object);
942 *ppSurface = (IDirect3DSurface9 *)object;
947 static HRESULT WINAPI IDirect3DDevice9Impl_CreateRenderTarget(IDirect3DDevice9Ex *iface, UINT Width,
948 UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality,
949 BOOL Lockable, IDirect3DSurface9 **ppSurface, HANDLE *pSharedHandle)
951 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
954 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u.\n"
955 "lockable %#x, surface %p, shared_handle %p.\n",
956 iface, Width, Height, Format, MultiSample, MultisampleQuality,
957 Lockable, ppSurface, pSharedHandle);
959 hr = IDirect3DDevice9Impl_CreateSurface(This, Width, Height, Format, Lockable,
960 FALSE /* Discard */, 0 /* Level */, ppSurface, D3DUSAGE_RENDERTARGET, D3DPOOL_DEFAULT,
961 MultiSample, MultisampleQuality);
966 static HRESULT WINAPI IDirect3DDevice9Impl_CreateDepthStencilSurface(IDirect3DDevice9Ex *iface,
967 UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample,
968 DWORD MultisampleQuality, BOOL Discard, IDirect3DSurface9 **ppSurface,
969 HANDLE *pSharedHandle)
971 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
974 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u.\n"
975 "discard %#x, surface %p, shared_handle %p.\n",
976 iface, Width, Height, Format, MultiSample, MultisampleQuality,
977 Discard, ppSurface, pSharedHandle);
979 hr = IDirect3DDevice9Impl_CreateSurface(This, Width, Height, Format, TRUE /* Lockable */,
980 Discard, 0 /* Level */, ppSurface, D3DUSAGE_DEPTHSTENCIL, D3DPOOL_DEFAULT, MultiSample,
987 static HRESULT WINAPI IDirect3DDevice9Impl_UpdateSurface(IDirect3DDevice9Ex *iface,
988 IDirect3DSurface9 *pSourceSurface, const RECT *pSourceRect,
989 IDirect3DSurface9 *pDestinationSurface, const POINT *pDestPoint)
991 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
994 TRACE("iface %p, src_surface %p, src_rect %p, dst_surface %p, dst_point %p.\n",
995 iface, pSourceSurface, pSourceRect, pDestinationSurface, pDestPoint);
997 wined3d_mutex_lock();
998 hr = IWineD3DDevice_UpdateSurface(This->WineD3DDevice,
999 ((IDirect3DSurface9Impl *)pSourceSurface)->wined3d_surface, pSourceRect,
1000 ((IDirect3DSurface9Impl *)pDestinationSurface)->wined3d_surface, pDestPoint);
1001 wined3d_mutex_unlock();
1006 static HRESULT WINAPI IDirect3DDevice9Impl_UpdateTexture(IDirect3DDevice9Ex *iface,
1007 IDirect3DBaseTexture9 *src_texture, IDirect3DBaseTexture9 *dst_texture)
1009 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1012 TRACE("iface %p, src_texture %p, dst_texture %p.\n", iface, src_texture, dst_texture);
1014 wined3d_mutex_lock();
1015 hr = IWineD3DDevice_UpdateTexture(This->WineD3DDevice,
1016 ((IDirect3DBaseTexture9Impl *)src_texture)->wined3d_texture,
1017 ((IDirect3DBaseTexture9Impl *)dst_texture)->wined3d_texture);
1018 wined3d_mutex_unlock();
1023 static HRESULT WINAPI IDirect3DDevice9Impl_GetRenderTargetData(IDirect3DDevice9Ex *iface,
1024 IDirect3DSurface9 *pRenderTarget, IDirect3DSurface9 *pDestSurface)
1026 IDirect3DSurface9Impl *renderTarget = (IDirect3DSurface9Impl *)pRenderTarget;
1027 IDirect3DSurface9Impl *destSurface = (IDirect3DSurface9Impl *)pDestSurface;
1030 TRACE("iface %p, render_target %p, dst_surface %p.\n", iface, pRenderTarget, pDestSurface);
1032 wined3d_mutex_lock();
1033 hr = wined3d_surface_bltfast(destSurface->wined3d_surface, 0, 0,
1034 renderTarget->wined3d_surface, NULL, WINEDDBLTFAST_NOCOLORKEY);
1035 wined3d_mutex_unlock();
1040 static HRESULT WINAPI IDirect3DDevice9Impl_GetFrontBufferData(IDirect3DDevice9Ex *iface,
1041 UINT iSwapChain, IDirect3DSurface9 *pDestSurface)
1043 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1044 IDirect3DSurface9Impl *destSurface = (IDirect3DSurface9Impl *)pDestSurface;
1047 TRACE("iface %p, swapchain %u, dst_surface %p.\n", iface, iSwapChain, pDestSurface);
1049 wined3d_mutex_lock();
1050 hr = IWineD3DDevice_GetFrontBufferData(This->WineD3DDevice, iSwapChain, destSurface->wined3d_surface);
1051 wined3d_mutex_unlock();
1056 static HRESULT WINAPI IDirect3DDevice9Impl_StretchRect(IDirect3DDevice9Ex *iface, IDirect3DSurface9 *pSourceSurface,
1057 const RECT *pSourceRect, IDirect3DSurface9 *pDestSurface, const RECT *pDestRect, D3DTEXTUREFILTERTYPE Filter)
1059 IDirect3DSurface9Impl *src = (IDirect3DSurface9Impl *) pSourceSurface;
1060 IDirect3DSurface9Impl *dst = (IDirect3DSurface9Impl *) pDestSurface;
1063 TRACE("iface %p, src_surface %p, src_rect %p, dst_surface %p, dst_rect %p, filter %#x.\n",
1064 iface, pSourceSurface, pSourceRect, pDestSurface, pDestRect, Filter);
1066 wined3d_mutex_lock();
1067 hr = wined3d_surface_blt(dst->wined3d_surface, pDestRect, src->wined3d_surface, pSourceRect, 0, NULL, Filter);
1068 wined3d_mutex_unlock();
1073 static HRESULT WINAPI IDirect3DDevice9Impl_ColorFill(IDirect3DDevice9Ex *iface,
1074 IDirect3DSurface9 *pSurface, const RECT *pRect, D3DCOLOR color)
1076 const WINED3DCOLORVALUE c =
1078 ((color >> 16) & 0xff) / 255.0f,
1079 ((color >> 8) & 0xff) / 255.0f,
1080 (color & 0xff) / 255.0f,
1081 ((color >> 24) & 0xff) / 255.0f,
1083 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1084 IDirect3DSurface9Impl *surface = (IDirect3DSurface9Impl *)pSurface;
1085 struct wined3d_resource *wined3d_resource;
1086 struct wined3d_resource_desc desc;
1089 TRACE("iface %p, surface %p, rect %p, color 0x%08x.\n", iface, pSurface, pRect, color);
1091 wined3d_mutex_lock();
1093 wined3d_resource = wined3d_surface_get_resource(surface->wined3d_surface);
1094 wined3d_resource_get_desc(wined3d_resource, &desc);
1096 /* This method is only allowed with surfaces that are render targets, or
1097 * offscreen plain surfaces in D3DPOOL_DEFAULT. */
1098 if (!(desc.usage & WINED3DUSAGE_RENDERTARGET) && desc.pool != WINED3DPOOL_DEFAULT)
1100 wined3d_mutex_unlock();
1101 WARN("Surface is not a render target, or not a stand-alone D3DPOOL_DEFAULT surface\n");
1102 return D3DERR_INVALIDCALL;
1105 /* Colorfill can only be used on rendertarget surfaces, or offscreen plain surfaces in D3DPOOL_DEFAULT */
1106 hr = IWineD3DDevice_ColorFill(This->WineD3DDevice, surface->wined3d_surface, pRect, &c);
1108 wined3d_mutex_unlock();
1113 static HRESULT WINAPI IDirect3DDevice9Impl_CreateOffscreenPlainSurface(IDirect3DDevice9Ex *iface,
1114 UINT Width, UINT Height, D3DFORMAT Format, D3DPOOL Pool, IDirect3DSurface9 **ppSurface,
1115 HANDLE *pSharedHandle)
1117 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1120 TRACE("iface %p, width %u, height %u, format %#x, pool %#x, surface %p, shared_handle %p.\n",
1121 iface, Width, Height, Format, Pool, ppSurface, pSharedHandle);
1123 if(Pool == D3DPOOL_MANAGED ){
1124 FIXME("Attempting to create a managed offscreen plain surface\n");
1125 return D3DERR_INVALIDCALL;
1128 'Off-screen plain surfaces are always lockable, regardless of their pool types.'
1130 D3DPOOL_DEFAULT is the appropriate pool for use with the IDirect3DDevice9::StretchRect and IDirect3DDevice9::ColorFill.
1131 Why, their always lockable?
1132 should I change the usage to dynamic?
1134 hr = IDirect3DDevice9Impl_CreateSurface(This, Width, Height, Format, TRUE /* Lockable */,
1135 FALSE /* Discard */, 0 /* Level */, ppSurface, 0 /* Usage (undefined/none) */,
1136 (WINED3DPOOL)Pool, D3DMULTISAMPLE_NONE, 0 /* MultisampleQuality */);
1141 /* TODO: move to wineD3D */
1142 static HRESULT WINAPI IDirect3DDevice9Impl_SetRenderTarget(IDirect3DDevice9Ex *iface,
1143 DWORD RenderTargetIndex, IDirect3DSurface9 *pRenderTarget)
1145 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1146 IDirect3DSurface9Impl *pSurface = (IDirect3DSurface9Impl*)pRenderTarget;
1149 TRACE("iface %p, idx %u, surface %p.\n", iface, RenderTargetIndex, pRenderTarget);
1151 if (RenderTargetIndex >= D3D9_MAX_SIMULTANEOUS_RENDERTARGETS)
1153 WARN("Invalid index %u specified.\n", RenderTargetIndex);
1154 return D3DERR_INVALIDCALL;
1157 wined3d_mutex_lock();
1158 hr = IWineD3DDevice_SetRenderTarget(This->WineD3DDevice, RenderTargetIndex,
1159 pSurface ? pSurface->wined3d_surface : NULL, TRUE);
1160 wined3d_mutex_unlock();
1165 static HRESULT WINAPI IDirect3DDevice9Impl_GetRenderTarget(IDirect3DDevice9Ex *iface,
1166 DWORD RenderTargetIndex, IDirect3DSurface9 **ppRenderTarget)
1168 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1169 struct wined3d_surface *wined3d_surface;
1172 TRACE("iface %p, idx %u, surface %p.\n", iface, RenderTargetIndex, ppRenderTarget);
1174 if (ppRenderTarget == NULL) {
1175 return D3DERR_INVALIDCALL;
1178 if (RenderTargetIndex >= D3D9_MAX_SIMULTANEOUS_RENDERTARGETS)
1180 WARN("Invalid index %u specified.\n", RenderTargetIndex);
1181 return D3DERR_INVALIDCALL;
1184 wined3d_mutex_lock();
1186 hr = IWineD3DDevice_GetRenderTarget(This->WineD3DDevice, RenderTargetIndex, &wined3d_surface);
1190 FIXME("Call to IWineD3DDevice_GetRenderTarget failed, hr %#x\n", hr);
1192 else if (!wined3d_surface)
1194 *ppRenderTarget = NULL;
1198 *ppRenderTarget = wined3d_surface_get_parent(wined3d_surface);
1199 IDirect3DSurface9_AddRef(*ppRenderTarget);
1200 wined3d_surface_decref(wined3d_surface);
1203 wined3d_mutex_unlock();
1208 static HRESULT WINAPI IDirect3DDevice9Impl_SetDepthStencilSurface(IDirect3DDevice9Ex *iface,
1209 IDirect3DSurface9 *pZStencilSurface)
1211 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1212 IDirect3DSurface9Impl *pSurface;
1215 TRACE("iface %p, depth_stencil %p.\n", iface, pZStencilSurface);
1217 pSurface = (IDirect3DSurface9Impl*)pZStencilSurface;
1219 wined3d_mutex_lock();
1220 hr = IWineD3DDevice_SetDepthStencilSurface(This->WineD3DDevice, pSurface ? pSurface->wined3d_surface : NULL);
1221 wined3d_mutex_unlock();
1226 static HRESULT WINAPI IDirect3DDevice9Impl_GetDepthStencilSurface(IDirect3DDevice9Ex *iface,
1227 IDirect3DSurface9 **ppZStencilSurface)
1229 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1230 struct wined3d_surface *wined3d_surface;
1233 TRACE("iface %p, depth_stencil %p.\n", iface, ppZStencilSurface);
1235 if(ppZStencilSurface == NULL){
1236 return D3DERR_INVALIDCALL;
1239 wined3d_mutex_lock();
1240 hr = IWineD3DDevice_GetDepthStencilSurface(This->WineD3DDevice, &wined3d_surface);
1243 *ppZStencilSurface = wined3d_surface_get_parent(wined3d_surface);
1244 IDirect3DSurface9_AddRef(*ppZStencilSurface);
1245 wined3d_surface_decref(wined3d_surface);
1249 if (hr != WINED3DERR_NOTFOUND)
1250 WARN("Call to IWineD3DDevice_GetDepthStencilSurface failed with 0x%08x\n", hr);
1251 *ppZStencilSurface = NULL;
1253 wined3d_mutex_unlock();
1258 static HRESULT WINAPI IDirect3DDevice9Impl_BeginScene(IDirect3DDevice9Ex *iface)
1260 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1263 TRACE("iface %p.\n", iface);
1265 wined3d_mutex_lock();
1266 hr = IWineD3DDevice_BeginScene(This->WineD3DDevice);
1267 wined3d_mutex_unlock();
1272 static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_EndScene(IDirect3DDevice9Ex *iface)
1274 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1277 TRACE("iface %p.\n", iface);
1279 wined3d_mutex_lock();
1280 hr = IWineD3DDevice_EndScene(This->WineD3DDevice);
1281 wined3d_mutex_unlock();
1286 static HRESULT WINAPI IDirect3DDevice9Impl_Clear(IDirect3DDevice9Ex *iface, DWORD Count,
1287 const D3DRECT *pRects, DWORD Flags, D3DCOLOR Color, float Z, DWORD Stencil)
1289 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1292 TRACE("iface %p, rect_count %u, rects %p, flags %#x, color 0x%08x, z %.8e, stencil %u.\n",
1293 iface, Count, pRects, Flags, Color, Z, Stencil);
1295 /* Note: D3DRECT is compatible with WINED3DRECT */
1296 wined3d_mutex_lock();
1297 hr = IWineD3DDevice_Clear(This->WineD3DDevice, Count, (const RECT *)pRects, Flags, Color, Z, Stencil);
1298 wined3d_mutex_unlock();
1303 static HRESULT WINAPI IDirect3DDevice9Impl_SetTransform(IDirect3DDevice9Ex *iface,
1304 D3DTRANSFORMSTATETYPE State, const D3DMATRIX *lpMatrix)
1306 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1309 TRACE("iface %p, state %#x, matrix %p.\n", iface, State, lpMatrix);
1311 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1312 wined3d_mutex_lock();
1313 hr = IWineD3DDevice_SetTransform(This->WineD3DDevice, State, (CONST WINED3DMATRIX*) lpMatrix);
1314 wined3d_mutex_unlock();
1319 static HRESULT WINAPI IDirect3DDevice9Impl_GetTransform(IDirect3DDevice9Ex *iface,
1320 D3DTRANSFORMSTATETYPE State, D3DMATRIX *pMatrix)
1322 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1325 TRACE("iface %p, state %#x, matrix %p.\n", iface, State, pMatrix);
1327 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1328 wined3d_mutex_lock();
1329 hr = IWineD3DDevice_GetTransform(This->WineD3DDevice, State, (WINED3DMATRIX*) pMatrix);
1330 wined3d_mutex_unlock();
1335 static HRESULT WINAPI IDirect3DDevice9Impl_MultiplyTransform(IDirect3DDevice9Ex *iface,
1336 D3DTRANSFORMSTATETYPE State, const D3DMATRIX *pMatrix)
1338 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1341 TRACE("iface %p, state %#x, matrix %p.\n", iface, State, pMatrix);
1343 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1344 wined3d_mutex_lock();
1345 hr = IWineD3DDevice_MultiplyTransform(This->WineD3DDevice, State, (CONST WINED3DMATRIX*) pMatrix);
1346 wined3d_mutex_unlock();
1351 static HRESULT WINAPI IDirect3DDevice9Impl_SetViewport(IDirect3DDevice9Ex *iface,
1352 const D3DVIEWPORT9 *pViewport)
1354 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1357 TRACE("iface %p, viewport %p.\n", iface, pViewport);
1359 /* Note: D3DVIEWPORT9 is compatible with WINED3DVIEWPORT */
1360 wined3d_mutex_lock();
1361 hr = IWineD3DDevice_SetViewport(This->WineD3DDevice, (const WINED3DVIEWPORT *)pViewport);
1362 wined3d_mutex_unlock();
1367 static HRESULT WINAPI IDirect3DDevice9Impl_GetViewport(IDirect3DDevice9Ex *iface,
1368 D3DVIEWPORT9 *pViewport)
1370 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1373 TRACE("iface %p, viewport %p.\n", iface, pViewport);
1375 /* Note: D3DVIEWPORT9 is compatible with WINED3DVIEWPORT */
1376 wined3d_mutex_lock();
1377 hr = IWineD3DDevice_GetViewport(This->WineD3DDevice, (WINED3DVIEWPORT *)pViewport);
1378 wined3d_mutex_unlock();
1383 static HRESULT WINAPI IDirect3DDevice9Impl_SetMaterial(IDirect3DDevice9Ex *iface,
1384 const D3DMATERIAL9 *pMaterial)
1386 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1389 TRACE("iface %p, material %p.\n", iface, pMaterial);
1391 /* Note: D3DMATERIAL9 is compatible with WINED3DMATERIAL */
1392 wined3d_mutex_lock();
1393 hr = IWineD3DDevice_SetMaterial(This->WineD3DDevice, (const WINED3DMATERIAL *)pMaterial);
1394 wined3d_mutex_unlock();
1399 static HRESULT WINAPI IDirect3DDevice9Impl_GetMaterial(IDirect3DDevice9Ex *iface,
1400 D3DMATERIAL9 *pMaterial)
1402 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1405 TRACE("iface %p, material %p.\n", iface, pMaterial);
1407 /* Note: D3DMATERIAL9 is compatible with WINED3DMATERIAL */
1408 wined3d_mutex_lock();
1409 hr = IWineD3DDevice_GetMaterial(This->WineD3DDevice, (WINED3DMATERIAL *)pMaterial);
1410 wined3d_mutex_unlock();
1415 static HRESULT WINAPI IDirect3DDevice9Impl_SetLight(IDirect3DDevice9Ex *iface, DWORD Index,
1416 const D3DLIGHT9 *pLight)
1418 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1421 TRACE("iface %p, index %u, light %p.\n", iface, Index, pLight);
1423 /* Note: D3DLIGHT9 is compatible with WINED3DLIGHT */
1424 wined3d_mutex_lock();
1425 hr = IWineD3DDevice_SetLight(This->WineD3DDevice, Index, (const WINED3DLIGHT *)pLight);
1426 wined3d_mutex_unlock();
1431 static HRESULT WINAPI IDirect3DDevice9Impl_GetLight(IDirect3DDevice9Ex *iface, DWORD Index,
1434 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1437 TRACE("iface %p, index %u, light %p.\n", iface, Index, pLight);
1439 /* Note: D3DLIGHT9 is compatible with WINED3DLIGHT */
1440 wined3d_mutex_lock();
1441 hr = IWineD3DDevice_GetLight(This->WineD3DDevice, Index, (WINED3DLIGHT *)pLight);
1442 wined3d_mutex_unlock();
1447 static HRESULT WINAPI IDirect3DDevice9Impl_LightEnable(IDirect3DDevice9Ex *iface, DWORD Index,
1450 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1453 TRACE("iface %p, index %u, enable %#x.\n", iface, Index, Enable);
1455 wined3d_mutex_lock();
1456 hr = IWineD3DDevice_SetLightEnable(This->WineD3DDevice, Index, Enable);
1457 wined3d_mutex_unlock();
1462 static HRESULT WINAPI IDirect3DDevice9Impl_GetLightEnable(IDirect3DDevice9Ex *iface, DWORD Index,
1465 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1468 TRACE("iface %p, index %u, enable %p.\n", iface, Index, pEnable);
1470 wined3d_mutex_lock();
1471 hr = IWineD3DDevice_GetLightEnable(This->WineD3DDevice, Index, pEnable);
1472 wined3d_mutex_unlock();
1477 static HRESULT WINAPI IDirect3DDevice9Impl_SetClipPlane(IDirect3DDevice9Ex *iface, DWORD Index,
1478 const float *pPlane)
1480 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1483 TRACE("iface %p, index %u, plane %p.\n", iface, Index, pPlane);
1485 wined3d_mutex_lock();
1486 hr = IWineD3DDevice_SetClipPlane(This->WineD3DDevice, Index, pPlane);
1487 wined3d_mutex_unlock();
1492 static HRESULT WINAPI IDirect3DDevice9Impl_GetClipPlane(IDirect3DDevice9Ex *iface, DWORD Index,
1495 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1498 TRACE("iface %p, index %u, plane %p.\n", iface, Index, pPlane);
1500 wined3d_mutex_lock();
1501 hr = IWineD3DDevice_GetClipPlane(This->WineD3DDevice, Index, pPlane);
1502 wined3d_mutex_unlock();
1507 static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_SetRenderState(IDirect3DDevice9Ex *iface,
1508 D3DRENDERSTATETYPE State, DWORD Value)
1510 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1513 TRACE("iface %p, state %#x, value %#x.\n", iface, State, Value);
1515 wined3d_mutex_lock();
1516 hr = IWineD3DDevice_SetRenderState(This->WineD3DDevice, State, Value);
1517 wined3d_mutex_unlock();
1522 static HRESULT WINAPI IDirect3DDevice9Impl_GetRenderState(IDirect3DDevice9Ex *iface,
1523 D3DRENDERSTATETYPE State, DWORD *pValue)
1525 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1528 TRACE("iface %p, state %#x, value %p.\n", iface, State, pValue);
1530 wined3d_mutex_lock();
1531 hr = IWineD3DDevice_GetRenderState(This->WineD3DDevice, State, pValue);
1532 wined3d_mutex_unlock();
1537 static HRESULT WINAPI IDirect3DDevice9Impl_CreateStateBlock(IDirect3DDevice9Ex *iface,
1538 D3DSTATEBLOCKTYPE type, IDirect3DStateBlock9 **stateblock)
1540 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1541 IDirect3DStateBlock9Impl *object;
1544 TRACE("iface %p, type %#x, stateblock %p.\n", iface, type, stateblock);
1546 if (type != D3DSBT_ALL && type != D3DSBT_PIXELSTATE && type != D3DSBT_VERTEXSTATE)
1548 WARN("Unexpected stateblock type, returning D3DERR_INVALIDCALL.\n");
1549 return D3DERR_INVALIDCALL;
1552 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1555 ERR("Failed to allocate stateblock memory.\n");
1556 return E_OUTOFMEMORY;
1559 hr = stateblock_init(object, This, type, NULL);
1562 WARN("Failed to initialize stateblock, hr %#x.\n", hr);
1563 HeapFree(GetProcessHeap(), 0, object);
1567 TRACE("Created stateblock %p.\n", object);
1568 *stateblock = &object->IDirect3DStateBlock9_iface;
1573 static HRESULT WINAPI IDirect3DDevice9Impl_BeginStateBlock(IDirect3DDevice9Ex *iface)
1575 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1578 TRACE("iface %p.\n", iface);
1580 wined3d_mutex_lock();
1581 hr = IWineD3DDevice_BeginStateBlock(This->WineD3DDevice);
1582 wined3d_mutex_unlock();
1587 static HRESULT WINAPI IDirect3DDevice9Impl_EndStateBlock(IDirect3DDevice9Ex *iface,
1588 IDirect3DStateBlock9 **stateblock)
1590 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1591 struct wined3d_stateblock *wined3d_stateblock;
1592 IDirect3DStateBlock9Impl *object;
1595 TRACE("iface %p, stateblock %p.\n", iface, stateblock);
1597 wined3d_mutex_lock();
1598 hr = IWineD3DDevice_EndStateBlock(This->WineD3DDevice, &wined3d_stateblock);
1599 wined3d_mutex_unlock();
1602 WARN("IWineD3DDevice_EndStateBlock() failed, hr %#x.\n", hr);
1606 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1609 ERR("Failed to allocate stateblock memory.\n");
1610 wined3d_mutex_lock();
1611 wined3d_stateblock_decref(wined3d_stateblock);
1612 wined3d_mutex_unlock();
1613 return E_OUTOFMEMORY;
1616 hr = stateblock_init(object, This, 0, wined3d_stateblock);
1619 WARN("Failed to initialize stateblock, hr %#x.\n", hr);
1620 wined3d_mutex_lock();
1621 wined3d_stateblock_decref(wined3d_stateblock);
1622 wined3d_mutex_unlock();
1623 HeapFree(GetProcessHeap(), 0, object);
1627 TRACE("Created stateblock %p.\n", object);
1628 *stateblock = &object->IDirect3DStateBlock9_iface;
1633 static HRESULT WINAPI IDirect3DDevice9Impl_SetClipStatus(IDirect3DDevice9Ex *iface,
1634 const D3DCLIPSTATUS9 *pClipStatus)
1636 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1639 TRACE("iface %p, clip_status %p.\n", iface, pClipStatus);
1641 wined3d_mutex_lock();
1642 hr = IWineD3DDevice_SetClipStatus(This->WineD3DDevice, (const WINED3DCLIPSTATUS *)pClipStatus);
1643 wined3d_mutex_unlock();
1648 static HRESULT WINAPI IDirect3DDevice9Impl_GetClipStatus(IDirect3DDevice9Ex *iface,
1649 D3DCLIPSTATUS9 *pClipStatus)
1651 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1654 TRACE("iface %p, clip_status %p.\n", iface, pClipStatus);
1656 wined3d_mutex_lock();
1657 hr = IWineD3DDevice_GetClipStatus(This->WineD3DDevice, (WINED3DCLIPSTATUS *)pClipStatus);
1658 wined3d_mutex_unlock();
1663 static HRESULT WINAPI IDirect3DDevice9Impl_GetTexture(IDirect3DDevice9Ex *iface, DWORD Stage,
1664 IDirect3DBaseTexture9 **ppTexture)
1666 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1667 struct wined3d_texture *wined3d_texture = NULL;
1670 TRACE("iface %p, stage %u, texture %p.\n", iface, Stage, ppTexture);
1672 if(ppTexture == NULL){
1673 return D3DERR_INVALIDCALL;
1676 wined3d_mutex_lock();
1677 hr = IWineD3DDevice_GetTexture(This->WineD3DDevice, Stage, &wined3d_texture);
1678 if (SUCCEEDED(hr) && wined3d_texture)
1680 *ppTexture = wined3d_texture_get_parent(wined3d_texture);
1681 IDirect3DBaseTexture9_AddRef(*ppTexture);
1682 wined3d_texture_decref(wined3d_texture);
1688 WARN("Call to get texture (%u) failed (%p).\n", Stage, wined3d_texture);
1692 wined3d_mutex_unlock();
1697 static HRESULT WINAPI IDirect3DDevice9Impl_SetTexture(IDirect3DDevice9Ex *iface, DWORD stage,
1698 IDirect3DBaseTexture9 *texture)
1700 IDirect3DDevice9Impl *device = impl_from_IDirect3DDevice9Ex(iface);
1703 TRACE("iface %p, stage %u, texture %p.\n", iface, stage, texture);
1705 wined3d_mutex_lock();
1706 hr = IWineD3DDevice_SetTexture(device->WineD3DDevice, stage,
1707 texture ? ((IDirect3DBaseTexture9Impl *)texture)->wined3d_texture : NULL);
1708 wined3d_mutex_unlock();
1713 static const WINED3DTEXTURESTAGESTATETYPE tss_lookup[] =
1715 WINED3DTSS_FORCE_DWORD, /* 0, unused */
1716 WINED3DTSS_COLOROP, /* 1, D3DTSS_COLOROP */
1717 WINED3DTSS_COLORARG1, /* 2, D3DTSS_COLORARG1 */
1718 WINED3DTSS_COLORARG2, /* 3, D3DTSS_COLORARG2 */
1719 WINED3DTSS_ALPHAOP, /* 4, D3DTSS_ALPHAOP */
1720 WINED3DTSS_ALPHAARG1, /* 5, D3DTSS_ALPHAARG1 */
1721 WINED3DTSS_ALPHAARG2, /* 6, D3DTSS_ALPHAARG2 */
1722 WINED3DTSS_BUMPENVMAT00, /* 7, D3DTSS_BUMPENVMAT00 */
1723 WINED3DTSS_BUMPENVMAT01, /* 8, D3DTSS_BUMPENVMAT01 */
1724 WINED3DTSS_BUMPENVMAT10, /* 9, D3DTSS_BUMPENVMAT10 */
1725 WINED3DTSS_BUMPENVMAT11, /* 10, D3DTSS_BUMPENVMAT11 */
1726 WINED3DTSS_TEXCOORDINDEX, /* 11, D3DTSS_TEXCOORDINDEX */
1727 WINED3DTSS_FORCE_DWORD, /* 12, unused */
1728 WINED3DTSS_FORCE_DWORD, /* 13, unused */
1729 WINED3DTSS_FORCE_DWORD, /* 14, unused */
1730 WINED3DTSS_FORCE_DWORD, /* 15, unused */
1731 WINED3DTSS_FORCE_DWORD, /* 16, unused */
1732 WINED3DTSS_FORCE_DWORD, /* 17, unused */
1733 WINED3DTSS_FORCE_DWORD, /* 18, unused */
1734 WINED3DTSS_FORCE_DWORD, /* 19, unused */
1735 WINED3DTSS_FORCE_DWORD, /* 20, unused */
1736 WINED3DTSS_FORCE_DWORD, /* 21, unused */
1737 WINED3DTSS_BUMPENVLSCALE, /* 22, D3DTSS_BUMPENVLSCALE */
1738 WINED3DTSS_BUMPENVLOFFSET, /* 23, D3DTSS_BUMPENVLOFFSET */
1739 WINED3DTSS_TEXTURETRANSFORMFLAGS, /* 24, D3DTSS_TEXTURETRANSFORMFLAGS */
1740 WINED3DTSS_FORCE_DWORD, /* 25, unused */
1741 WINED3DTSS_COLORARG0, /* 26, D3DTSS_COLORARG0 */
1742 WINED3DTSS_ALPHAARG0, /* 27, D3DTSS_ALPHAARG0 */
1743 WINED3DTSS_RESULTARG, /* 28, D3DTSS_RESULTARG */
1744 WINED3DTSS_FORCE_DWORD, /* 29, unused */
1745 WINED3DTSS_FORCE_DWORD, /* 30, unused */
1746 WINED3DTSS_FORCE_DWORD, /* 31, unused */
1747 WINED3DTSS_CONSTANT, /* 32, D3DTSS_CONSTANT */
1750 static HRESULT WINAPI IDirect3DDevice9Impl_GetTextureStageState(IDirect3DDevice9Ex *iface,
1751 DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD *pValue)
1753 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1756 TRACE("iface %p, stage %u, state %#x, value %p.\n", iface, Stage, Type, pValue);
1758 if (Type >= sizeof(tss_lookup) / sizeof(*tss_lookup))
1760 WARN("Invalid Type %#x passed.\n", Type);
1764 wined3d_mutex_lock();
1765 hr = IWineD3DDevice_GetTextureStageState(This->WineD3DDevice, Stage, tss_lookup[Type], pValue);
1766 wined3d_mutex_unlock();
1771 static HRESULT WINAPI IDirect3DDevice9Impl_SetTextureStageState(IDirect3DDevice9Ex *iface,
1772 DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD Value)
1774 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1777 TRACE("iface %p, stage %u, state %#x, value %#x.\n", iface, Stage, Type, Value);
1779 if (Type >= sizeof(tss_lookup) / sizeof(*tss_lookup))
1781 WARN("Invalid Type %#x passed.\n", Type);
1785 wined3d_mutex_lock();
1786 hr = IWineD3DDevice_SetTextureStageState(This->WineD3DDevice, Stage, tss_lookup[Type], Value);
1787 wined3d_mutex_unlock();
1792 static HRESULT WINAPI IDirect3DDevice9Impl_GetSamplerState(IDirect3DDevice9Ex *iface, DWORD Sampler,
1793 D3DSAMPLERSTATETYPE Type, DWORD *pValue)
1795 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1798 TRACE("iface %p, sampler %u, state %#x, value %p.\n", iface, Sampler, Type, pValue);
1800 wined3d_mutex_lock();
1801 hr = IWineD3DDevice_GetSamplerState(This->WineD3DDevice, Sampler, Type, pValue);
1802 wined3d_mutex_unlock();
1807 static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_SetSamplerState(IDirect3DDevice9Ex *iface,
1808 DWORD Sampler, D3DSAMPLERSTATETYPE Type, DWORD Value)
1810 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1813 TRACE("iface %p, sampler %u, state %#x, value %#x.\n", iface, Sampler, Type, Value);
1815 wined3d_mutex_lock();
1816 hr = IWineD3DDevice_SetSamplerState(This->WineD3DDevice, Sampler, Type, Value);
1817 wined3d_mutex_unlock();
1822 static HRESULT WINAPI IDirect3DDevice9Impl_ValidateDevice(IDirect3DDevice9Ex *iface,
1825 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1828 TRACE("iface %p, pass_count %p.\n", iface, pNumPasses);
1830 wined3d_mutex_lock();
1831 hr = IWineD3DDevice_ValidateDevice(This->WineD3DDevice, pNumPasses);
1832 wined3d_mutex_unlock();
1837 static HRESULT WINAPI IDirect3DDevice9Impl_SetPaletteEntries(IDirect3DDevice9Ex *iface,
1838 UINT PaletteNumber, const PALETTEENTRY *pEntries)
1840 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1843 TRACE("iface %p, palette_idx %u, entries %p.\n", iface, PaletteNumber, pEntries);
1845 wined3d_mutex_lock();
1846 hr = IWineD3DDevice_SetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
1847 wined3d_mutex_unlock();
1852 static HRESULT WINAPI IDirect3DDevice9Impl_GetPaletteEntries(IDirect3DDevice9Ex *iface,
1853 UINT PaletteNumber, PALETTEENTRY *pEntries)
1855 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1858 TRACE("iface %p, palette_idx %u, entries %p.\n", iface, PaletteNumber, pEntries);
1860 wined3d_mutex_lock();
1861 hr = IWineD3DDevice_GetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
1862 wined3d_mutex_unlock();
1867 static HRESULT WINAPI IDirect3DDevice9Impl_SetCurrentTexturePalette(IDirect3DDevice9Ex *iface,
1870 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1873 TRACE("iface %p, palette_idx %u.\n", iface, PaletteNumber);
1875 wined3d_mutex_lock();
1876 hr = IWineD3DDevice_SetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
1877 wined3d_mutex_unlock();
1882 static HRESULT WINAPI IDirect3DDevice9Impl_GetCurrentTexturePalette(IDirect3DDevice9Ex *iface,
1883 UINT *PaletteNumber)
1885 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1888 TRACE("iface %p, palette_idx %p.\n", iface, PaletteNumber);
1890 wined3d_mutex_lock();
1891 hr = IWineD3DDevice_GetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
1892 wined3d_mutex_unlock();
1897 static HRESULT WINAPI IDirect3DDevice9Impl_SetScissorRect(IDirect3DDevice9Ex *iface,
1900 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1903 TRACE("iface %p, rect %p.\n", iface, pRect);
1905 wined3d_mutex_lock();
1906 hr = IWineD3DDevice_SetScissorRect(This->WineD3DDevice, pRect);
1907 wined3d_mutex_unlock();
1912 static HRESULT WINAPI IDirect3DDevice9Impl_GetScissorRect(IDirect3DDevice9Ex *iface, RECT *pRect)
1914 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1917 TRACE("iface %p, rect %p.\n", iface, pRect);
1919 wined3d_mutex_lock();
1920 hr = IWineD3DDevice_GetScissorRect(This->WineD3DDevice, pRect);
1921 wined3d_mutex_unlock();
1926 static HRESULT WINAPI IDirect3DDevice9Impl_SetSoftwareVertexProcessing(IDirect3DDevice9Ex *iface,
1929 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1932 TRACE("iface %p, software %#x.\n", iface, bSoftware);
1934 wined3d_mutex_lock();
1935 hr = IWineD3DDevice_SetSoftwareVertexProcessing(This->WineD3DDevice, bSoftware);
1936 wined3d_mutex_unlock();
1941 static BOOL WINAPI IDirect3DDevice9Impl_GetSoftwareVertexProcessing(IDirect3DDevice9Ex *iface)
1943 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1946 TRACE("iface %p.\n", iface);
1948 wined3d_mutex_lock();
1949 ret = IWineD3DDevice_GetSoftwareVertexProcessing(This->WineD3DDevice);
1950 wined3d_mutex_unlock();
1955 static HRESULT WINAPI IDirect3DDevice9Impl_SetNPatchMode(IDirect3DDevice9Ex *iface, float nSegments)
1957 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1960 TRACE("iface %p, segment_count %.8e.\n", iface, nSegments);
1962 wined3d_mutex_lock();
1963 hr = IWineD3DDevice_SetNPatchMode(This->WineD3DDevice, nSegments);
1964 wined3d_mutex_unlock();
1969 static float WINAPI IDirect3DDevice9Impl_GetNPatchMode(IDirect3DDevice9Ex *iface)
1971 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1974 TRACE("iface %p.\n", iface);
1976 wined3d_mutex_lock();
1977 ret = IWineD3DDevice_GetNPatchMode(This->WineD3DDevice);
1978 wined3d_mutex_unlock();
1983 static HRESULT WINAPI IDirect3DDevice9Impl_DrawPrimitive(IDirect3DDevice9Ex *iface,
1984 D3DPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT PrimitiveCount)
1986 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
1989 TRACE("iface %p, primitive_type %#x, start_vertex %u, primitive_count %u.\n",
1990 iface, PrimitiveType, StartVertex, PrimitiveCount);
1992 wined3d_mutex_lock();
1993 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1994 hr = IWineD3DDevice_DrawPrimitive(This->WineD3DDevice, StartVertex,
1995 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount));
1996 wined3d_mutex_unlock();
2001 static HRESULT WINAPI IDirect3DDevice9Impl_DrawIndexedPrimitive(IDirect3DDevice9Ex *iface,
2002 D3DPRIMITIVETYPE PrimitiveType, INT BaseVertexIndex, UINT MinVertexIndex, UINT NumVertices,
2003 UINT startIndex, UINT primCount)
2005 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
2008 TRACE("iface %p, primitive_type %#x, base_vertex_idx %u, min_vertex_idx %u,\n"
2009 "vertex_count %u, start_idx %u, primitive_count %u.\n",
2010 iface, PrimitiveType, BaseVertexIndex, MinVertexIndex,
2011 NumVertices, startIndex, primCount);
2013 wined3d_mutex_lock();
2014 IWineD3DDevice_SetBaseVertexIndex(This->WineD3DDevice, BaseVertexIndex);
2015 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
2016 hr = IWineD3DDevice_DrawIndexedPrimitive(This->WineD3DDevice, startIndex,
2017 vertex_count_from_primitive_count(PrimitiveType, primCount));
2018 wined3d_mutex_unlock();
2023 static HRESULT WINAPI IDirect3DDevice9Impl_DrawPrimitiveUP(IDirect3DDevice9Ex *iface,
2024 D3DPRIMITIVETYPE PrimitiveType, UINT PrimitiveCount, const void *pVertexStreamZeroData,
2025 UINT VertexStreamZeroStride)
2027 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
2030 TRACE("iface %p, primitive_type %#x, primitive_count %u, data %p, stride %u.\n",
2031 iface, PrimitiveType, PrimitiveCount, pVertexStreamZeroData, VertexStreamZeroStride);
2033 wined3d_mutex_lock();
2034 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
2035 hr = IWineD3DDevice_DrawPrimitiveUP(This->WineD3DDevice,
2036 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount),
2037 pVertexStreamZeroData, VertexStreamZeroStride);
2038 wined3d_mutex_unlock();
2043 static HRESULT WINAPI IDirect3DDevice9Impl_DrawIndexedPrimitiveUP(IDirect3DDevice9Ex *iface,
2044 D3DPRIMITIVETYPE PrimitiveType, UINT MinVertexIndex, UINT NumVertexIndices,
2045 UINT PrimitiveCount, const void *pIndexData, D3DFORMAT IndexDataFormat,
2046 const void *pVertexStreamZeroData, UINT VertexStreamZeroStride)
2048 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
2051 TRACE("iface %p, primitive_type %#x, min_vertex_idx %u, index_count %u, primitive_count %u,\n"
2052 "index_data %p, index_format %#x, vertex_data %p, vertex_stride %u.\n",
2053 iface, PrimitiveType, MinVertexIndex, NumVertexIndices, PrimitiveCount,
2054 pIndexData, IndexDataFormat, pVertexStreamZeroData, VertexStreamZeroStride);
2056 wined3d_mutex_lock();
2057 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
2058 hr = IWineD3DDevice_DrawIndexedPrimitiveUP(This->WineD3DDevice,
2059 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount), pIndexData,
2060 wined3dformat_from_d3dformat(IndexDataFormat), pVertexStreamZeroData, VertexStreamZeroStride);
2061 wined3d_mutex_unlock();
2066 static HRESULT WINAPI IDirect3DDevice9Impl_ProcessVertices(IDirect3DDevice9Ex *iface,
2067 UINT SrcStartIndex, UINT DestIndex, UINT VertexCount, IDirect3DVertexBuffer9 *pDestBuffer,
2068 IDirect3DVertexDeclaration9 *pVertexDecl, DWORD Flags)
2070 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
2071 IDirect3DVertexDeclaration9Impl *Decl = (IDirect3DVertexDeclaration9Impl *) pVertexDecl;
2073 IDirect3DVertexBuffer9Impl *dest = (IDirect3DVertexBuffer9Impl *) pDestBuffer;
2075 TRACE("iface %p, src_start_idx %u, dst_idx %u, vertex_count %u, dst_buffer %p, declaration %p, flags %#x.\n",
2076 iface, SrcStartIndex, DestIndex, VertexCount, pDestBuffer, pVertexDecl, Flags);
2078 wined3d_mutex_lock();
2079 hr = IWineD3DDevice_ProcessVertices(This->WineD3DDevice,SrcStartIndex, DestIndex, VertexCount, dest->wineD3DVertexBuffer, Decl ? Decl->wineD3DVertexDeclaration : NULL, Flags, dest->fvf);
2080 wined3d_mutex_unlock();
2085 static HRESULT WINAPI IDirect3DDevice9Impl_CreateVertexDeclaration(IDirect3DDevice9Ex *iface,
2086 const D3DVERTEXELEMENT9 *elements, IDirect3DVertexDeclaration9 **declaration)
2088 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
2089 IDirect3DVertexDeclaration9Impl *object;
2092 TRACE("iface %p, elements %p, declaration %p.\n", iface, elements, declaration);
2096 WARN("Caller passed a NULL declaration, returning D3DERR_INVALIDCALL.\n");
2097 return D3DERR_INVALIDCALL;
2100 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2103 ERR("Failed to allocate vertex declaration memory.\n");
2104 return E_OUTOFMEMORY;
2107 hr = vertexdeclaration_init(object, This, elements);
2110 WARN("Failed to initialize vertex declaration, hr %#x.\n", hr);
2111 HeapFree(GetProcessHeap(), 0, object);
2115 TRACE("Created vertex declaration %p.\n", object);
2116 *declaration = (IDirect3DVertexDeclaration9 *)object;
2121 static HRESULT WINAPI IDirect3DDevice9Impl_SetVertexDeclaration(IDirect3DDevice9Ex *iface,
2122 IDirect3DVertexDeclaration9 *declaration)
2124 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
2127 TRACE("iface %p, declaration %p.\n", iface, declaration);
2129 wined3d_mutex_lock();
2130 hr = IWineD3DDevice_SetVertexDeclaration(This->WineD3DDevice,
2131 declaration ? ((IDirect3DVertexDeclaration9Impl *)declaration)->wineD3DVertexDeclaration : NULL);
2132 wined3d_mutex_unlock();
2137 static HRESULT WINAPI IDirect3DDevice9Impl_GetVertexDeclaration(IDirect3DDevice9Ex *iface,
2138 IDirect3DVertexDeclaration9 **declaration)
2140 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
2141 struct wined3d_vertex_declaration *wined3d_declaration = NULL;
2144 TRACE("iface %p, declaration %p.\n", iface, declaration);
2146 if (!declaration) return D3DERR_INVALIDCALL;
2148 wined3d_mutex_lock();
2149 hr = IWineD3DDevice_GetVertexDeclaration(This->WineD3DDevice, &wined3d_declaration);
2150 if (SUCCEEDED(hr) && wined3d_declaration)
2152 *declaration = wined3d_vertex_declaration_get_parent(wined3d_declaration);
2153 IDirect3DVertexDeclaration9_AddRef(*declaration);
2154 wined3d_vertex_declaration_decref(wined3d_declaration);
2158 *declaration = NULL;
2160 wined3d_mutex_unlock();
2162 TRACE("Returning %p.\n", *declaration);
2166 static IDirect3DVertexDeclaration9 *getConvertedDecl(IDirect3DDevice9Impl *This, DWORD fvf) {
2168 D3DVERTEXELEMENT9* elements = NULL;
2169 IDirect3DVertexDeclaration9* pDecl = NULL;
2170 int p, low, high; /* deliberately signed */
2171 IDirect3DVertexDeclaration9 **convertedDecls = This->convertedDecls;
2173 TRACE("Searching for declaration for fvf %08x... ", fvf);
2176 high = This->numConvertedDecls - 1;
2177 while(low <= high) {
2178 p = (low + high) >> 1;
2180 if(((IDirect3DVertexDeclaration9Impl *) convertedDecls[p])->convFVF == fvf) {
2181 TRACE("found %p\n", convertedDecls[p]);
2182 return convertedDecls[p];
2183 } else if(((IDirect3DVertexDeclaration9Impl *) convertedDecls[p])->convFVF < fvf) {
2189 TRACE("not found. Creating and inserting at position %d.\n", low);
2191 hr = vdecl_convert_fvf(fvf, &elements);
2192 if (hr != S_OK) return NULL;
2194 hr = IDirect3DDevice9Impl_CreateVertexDeclaration(&This->IDirect3DDevice9Ex_iface, elements,
2196 HeapFree(GetProcessHeap(), 0, elements); /* CreateVertexDeclaration makes a copy */
2197 if (hr != S_OK) return NULL;
2199 if(This->declArraySize == This->numConvertedDecls) {
2200 int grow = max(This->declArraySize / 2, 8);
2201 convertedDecls = HeapReAlloc(GetProcessHeap(), 0, convertedDecls,
2202 sizeof(convertedDecls[0]) * (This->numConvertedDecls + grow));
2203 if(!convertedDecls) {
2204 /* This will destroy it */
2205 IDirect3DVertexDeclaration9_Release(pDecl);
2208 This->convertedDecls = convertedDecls;
2209 This->declArraySize += grow;
2212 memmove(convertedDecls + low + 1, convertedDecls + low, sizeof(IDirect3DVertexDeclaration9Impl *) * (This->numConvertedDecls - low));
2213 convertedDecls[low] = pDecl;
2214 This->numConvertedDecls++;
2216 /* Will prevent the decl from being destroyed */
2217 ((IDirect3DVertexDeclaration9Impl *) pDecl)->convFVF = fvf;
2218 IDirect3DVertexDeclaration9_Release(pDecl); /* Does not destroy now */
2220 TRACE("Returning %p. %d decls in array\n", pDecl, This->numConvertedDecls);
2224 static HRESULT WINAPI IDirect3DDevice9Impl_SetFVF(IDirect3DDevice9Ex *iface, DWORD FVF)
2226 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
2227 IDirect3DVertexDeclaration9 *decl;
2230 TRACE("iface %p, fvf %#x.\n", iface, FVF);
2234 WARN("%#x is not a valid FVF\n", FVF);
2238 wined3d_mutex_lock();
2239 decl = getConvertedDecl(This, FVF);
2240 wined3d_mutex_unlock();
2244 /* Any situation when this should happen, except out of memory? */
2245 ERR("Failed to create a converted vertex declaration\n");
2246 return D3DERR_DRIVERINTERNALERROR;
2249 hr = IDirect3DDevice9Impl_SetVertexDeclaration(iface, decl);
2250 if (FAILED(hr)) ERR("Failed to set vertex declaration\n");
2255 static HRESULT WINAPI IDirect3DDevice9Impl_GetFVF(IDirect3DDevice9Ex *iface, DWORD *pFVF)
2257 IDirect3DVertexDeclaration9 *decl;
2260 TRACE("iface %p, fvf %p.\n", iface, pFVF);
2262 hr = IDirect3DDevice9_GetVertexDeclaration(iface, &decl);
2265 WARN("Failed to get vertex declaration, %#x\n", hr);
2272 *pFVF = ((IDirect3DVertexDeclaration9Impl *)decl)->convFVF;
2273 IDirect3DVertexDeclaration9_Release(decl);
2280 TRACE("Returning FVF %#x\n", *pFVF);
2285 static HRESULT WINAPI IDirect3DDevice9Impl_CreateVertexShader(IDirect3DDevice9Ex *iface,
2286 const DWORD *byte_code, IDirect3DVertexShader9 **shader)
2288 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
2289 IDirect3DVertexShader9Impl *object;
2292 TRACE("iface %p, byte_code %p, shader %p.\n", iface, byte_code, shader);
2294 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2297 ERR("Failed to allocate vertex shader memory.\n");
2298 return E_OUTOFMEMORY;
2301 hr = vertexshader_init(object, This, byte_code);
2304 WARN("Failed to initialize vertex shader, hr %#x.\n", hr);
2305 HeapFree(GetProcessHeap(), 0, object);
2309 TRACE("Created vertex shader %p.\n", object);
2310 *shader = (IDirect3DVertexShader9 *)object;
2315 static HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShader(IDirect3DDevice9Ex *iface,
2316 IDirect3DVertexShader9 *shader)
2318 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
2321 TRACE("iface %p, shader %p.\n", iface, shader);
2323 wined3d_mutex_lock();
2324 hr = IWineD3DDevice_SetVertexShader(This->WineD3DDevice,
2325 shader ? ((IDirect3DVertexShader9Impl *)shader)->wined3d_shader : NULL);
2326 wined3d_mutex_unlock();
2331 static HRESULT WINAPI IDirect3DDevice9Impl_GetVertexShader(IDirect3DDevice9Ex *iface,
2332 IDirect3DVertexShader9 **shader)
2334 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
2335 struct wined3d_shader *wined3d_shader;
2337 TRACE("iface %p, shader %p.\n", iface, shader);
2339 wined3d_mutex_lock();
2340 wined3d_shader = IWineD3DDevice_GetVertexShader(This->WineD3DDevice);
2343 *shader = wined3d_shader_get_parent(wined3d_shader);
2344 IDirect3DVertexShader9_AddRef(*shader);
2345 wined3d_shader_decref(wined3d_shader);
2351 wined3d_mutex_unlock();
2353 TRACE("Returning %p.\n", *shader);
2358 static HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShaderConstantF(IDirect3DDevice9Ex *iface,
2359 UINT reg_idx, const float *data, UINT count)
2361 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
2364 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface, reg_idx, data, count);
2366 if (reg_idx + count > D3D9_MAX_VERTEX_SHADER_CONSTANTF)
2368 WARN("Trying to access %u constants, but d3d9 only supports %u\n",
2369 reg_idx + count, D3D9_MAX_VERTEX_SHADER_CONSTANTF);
2370 return D3DERR_INVALIDCALL;
2373 wined3d_mutex_lock();
2374 hr = IWineD3DDevice_SetVertexShaderConstantF(This->WineD3DDevice, reg_idx, data, count);
2375 wined3d_mutex_unlock();
2380 static HRESULT WINAPI IDirect3DDevice9Impl_GetVertexShaderConstantF(IDirect3DDevice9Ex *iface,
2381 UINT reg_idx, 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_GetVertexShaderConstantF(This->WineD3DDevice, reg_idx, data, count);
2397 wined3d_mutex_unlock();
2402 static HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShaderConstantI(IDirect3DDevice9Ex *iface,
2403 UINT reg_idx, const int *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 wined3d_mutex_lock();
2411 hr = IWineD3DDevice_SetVertexShaderConstantI(This->WineD3DDevice, reg_idx, data, count);
2412 wined3d_mutex_unlock();
2417 static HRESULT WINAPI IDirect3DDevice9Impl_GetVertexShaderConstantI(IDirect3DDevice9Ex *iface,
2418 UINT reg_idx, int *data, UINT count)
2420 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
2423 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface, reg_idx, data, count);
2425 wined3d_mutex_lock();
2426 hr = IWineD3DDevice_GetVertexShaderConstantI(This->WineD3DDevice, reg_idx, data, count);
2427 wined3d_mutex_unlock();
2432 static HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShaderConstantB(IDirect3DDevice9Ex *iface,
2433 UINT reg_idx, const BOOL *data, UINT count)
2435 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
2438 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface, reg_idx, data, count);
2440 wined3d_mutex_lock();
2441 hr = IWineD3DDevice_SetVertexShaderConstantB(This->WineD3DDevice, reg_idx, data, count);
2442 wined3d_mutex_unlock();
2447 static HRESULT WINAPI IDirect3DDevice9Impl_GetVertexShaderConstantB(IDirect3DDevice9Ex *iface,
2448 UINT reg_idx, BOOL *data, UINT count)
2450 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
2453 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface, reg_idx, data, count);
2455 wined3d_mutex_lock();
2456 hr = IWineD3DDevice_GetVertexShaderConstantB(This->WineD3DDevice, reg_idx, data, count);
2457 wined3d_mutex_unlock();
2462 static HRESULT WINAPI IDirect3DDevice9Impl_SetStreamSource(IDirect3DDevice9Ex *iface,
2463 UINT StreamNumber, IDirect3DVertexBuffer9 *pStreamData, UINT OffsetInBytes, UINT Stride)
2465 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
2468 TRACE("iface %p, stream_idx %u, buffer %p, offset %u, stride %u.\n",
2469 iface, StreamNumber, pStreamData, OffsetInBytes, Stride);
2471 wined3d_mutex_lock();
2472 hr = IWineD3DDevice_SetStreamSource(This->WineD3DDevice, StreamNumber,
2473 pStreamData ? ((IDirect3DVertexBuffer9Impl *)pStreamData)->wineD3DVertexBuffer : NULL,
2474 OffsetInBytes, Stride);
2475 wined3d_mutex_unlock();
2480 static HRESULT WINAPI IDirect3DDevice9Impl_GetStreamSource(IDirect3DDevice9Ex *iface,
2481 UINT StreamNumber, IDirect3DVertexBuffer9 **pStream, UINT *OffsetInBytes, UINT *pStride)
2483 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
2484 struct wined3d_buffer *retStream = NULL;
2487 TRACE("iface %p, stream_idx %u, buffer %p, offset %p, stride %p.\n",
2488 iface, StreamNumber, pStream, OffsetInBytes, pStride);
2490 if(pStream == NULL){
2491 return D3DERR_INVALIDCALL;
2494 wined3d_mutex_lock();
2495 hr = IWineD3DDevice_GetStreamSource(This->WineD3DDevice, StreamNumber, &retStream, OffsetInBytes, pStride);
2496 if (SUCCEEDED(hr) && retStream)
2498 *pStream = wined3d_buffer_get_parent(retStream);
2499 IDirect3DVertexBuffer9_AddRef(*pStream);
2500 wined3d_buffer_decref(retStream);
2506 FIXME("Call to GetStreamSource failed %p %p\n", OffsetInBytes, pStride);
2510 wined3d_mutex_unlock();
2515 static HRESULT WINAPI IDirect3DDevice9Impl_SetStreamSourceFreq(IDirect3DDevice9Ex *iface,
2516 UINT StreamNumber, UINT Divider)
2518 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
2521 TRACE("iface %p, stream_idx %u, freq %u.\n", iface, StreamNumber, Divider);
2523 wined3d_mutex_lock();
2524 hr = IWineD3DDevice_SetStreamSourceFreq(This->WineD3DDevice, StreamNumber, Divider);
2525 wined3d_mutex_unlock();
2530 static HRESULT WINAPI IDirect3DDevice9Impl_GetStreamSourceFreq(IDirect3DDevice9Ex *iface,
2531 UINT StreamNumber, UINT *Divider)
2533 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
2536 TRACE("iface %p, stream_idx %u, freq %p.\n", iface, StreamNumber, Divider);
2538 wined3d_mutex_lock();
2539 hr = IWineD3DDevice_GetStreamSourceFreq(This->WineD3DDevice, StreamNumber, Divider);
2540 wined3d_mutex_unlock();
2545 static HRESULT WINAPI IDirect3DDevice9Impl_SetIndices(IDirect3DDevice9Ex *iface,
2546 IDirect3DIndexBuffer9 *pIndexData)
2548 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
2550 IDirect3DIndexBuffer9Impl *ib = (IDirect3DIndexBuffer9Impl *) pIndexData;
2552 TRACE("iface %p, buffer %p.\n", iface, pIndexData);
2554 wined3d_mutex_lock();
2555 hr = IWineD3DDevice_SetIndexBuffer(This->WineD3DDevice,
2556 ib ? ib->wineD3DIndexBuffer : NULL,
2557 ib ? ib->format : WINED3DFMT_UNKNOWN);
2558 wined3d_mutex_unlock();
2563 static HRESULT WINAPI IDirect3DDevice9Impl_GetIndices(IDirect3DDevice9Ex *iface,
2564 IDirect3DIndexBuffer9 **ppIndexData)
2566 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
2567 struct wined3d_buffer *retIndexData = NULL;
2570 TRACE("iface %p, buffer %p.\n", iface, ppIndexData);
2572 if(ppIndexData == NULL){
2573 return D3DERR_INVALIDCALL;
2576 wined3d_mutex_lock();
2577 hr = IWineD3DDevice_GetIndexBuffer(This->WineD3DDevice, &retIndexData);
2578 if (SUCCEEDED(hr) && retIndexData)
2580 *ppIndexData = wined3d_buffer_get_parent(retIndexData);
2581 IDirect3DIndexBuffer9_AddRef(*ppIndexData);
2582 wined3d_buffer_decref(retIndexData);
2586 if (FAILED(hr)) FIXME("Call to GetIndices failed\n");
2587 *ppIndexData = NULL;
2589 wined3d_mutex_unlock();
2594 static HRESULT WINAPI IDirect3DDevice9Impl_CreatePixelShader(IDirect3DDevice9Ex *iface,
2595 const DWORD *byte_code, IDirect3DPixelShader9 **shader)
2597 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
2598 IDirect3DPixelShader9Impl *object;
2601 TRACE("iface %p, byte_code %p, shader %p.\n", iface, byte_code, shader);
2603 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2606 FIXME("Failed to allocate pixel shader memory.\n");
2607 return E_OUTOFMEMORY;
2610 hr = pixelshader_init(object, This, byte_code);
2613 WARN("Failed to initialize pixel shader, hr %#x.\n", hr);
2614 HeapFree(GetProcessHeap(), 0, object);
2618 TRACE("Created pixel shader %p.\n", object);
2619 *shader = (IDirect3DPixelShader9 *)object;
2624 static HRESULT WINAPI IDirect3DDevice9Impl_SetPixelShader(IDirect3DDevice9Ex *iface,
2625 IDirect3DPixelShader9 *shader)
2627 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
2630 TRACE("iface %p, shader %p.\n", iface, shader);
2632 wined3d_mutex_lock();
2633 hr = IWineD3DDevice_SetPixelShader(This->WineD3DDevice,
2634 shader ? ((IDirect3DPixelShader9Impl *)shader)->wined3d_shader : NULL);
2635 wined3d_mutex_unlock();
2640 static HRESULT WINAPI IDirect3DDevice9Impl_GetPixelShader(IDirect3DDevice9Ex *iface,
2641 IDirect3DPixelShader9 **shader)
2643 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
2644 struct wined3d_shader *wined3d_shader;
2646 TRACE("iface %p, shader %p.\n", iface, shader);
2648 if (!shader) return D3DERR_INVALIDCALL;
2650 wined3d_mutex_lock();
2651 wined3d_shader = IWineD3DDevice_GetPixelShader(This->WineD3DDevice);
2654 *shader = wined3d_shader_get_parent(wined3d_shader);
2655 IDirect3DPixelShader9_AddRef(*shader);
2656 wined3d_shader_decref(wined3d_shader);
2662 wined3d_mutex_unlock();
2664 TRACE("Returning %p.\n", *shader);
2669 static HRESULT WINAPI IDirect3DDevice9Impl_SetPixelShaderConstantF(IDirect3DDevice9Ex *iface,
2670 UINT reg_idx, const float *data, UINT count)
2672 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
2675 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface, reg_idx, data, count);
2677 wined3d_mutex_lock();
2678 hr = IWineD3DDevice_SetPixelShaderConstantF(This->WineD3DDevice, reg_idx, data, count);
2679 wined3d_mutex_unlock();
2684 static HRESULT WINAPI IDirect3DDevice9Impl_GetPixelShaderConstantF(IDirect3DDevice9Ex *iface,
2685 UINT reg_idx, float *data, UINT count)
2687 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
2690 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface, reg_idx, data, count);
2692 wined3d_mutex_lock();
2693 hr = IWineD3DDevice_GetPixelShaderConstantF(This->WineD3DDevice, reg_idx, data, count);
2694 wined3d_mutex_unlock();
2699 static HRESULT WINAPI IDirect3DDevice9Impl_SetPixelShaderConstantI(IDirect3DDevice9Ex *iface,
2700 UINT reg_idx, const int *data, UINT count)
2702 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
2705 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface, reg_idx, data, count);
2707 wined3d_mutex_lock();
2708 hr = IWineD3DDevice_SetPixelShaderConstantI(This->WineD3DDevice, reg_idx, data, count);
2709 wined3d_mutex_unlock();
2714 static HRESULT WINAPI IDirect3DDevice9Impl_GetPixelShaderConstantI(IDirect3DDevice9Ex *iface,
2715 UINT reg_idx, int *data, UINT count)
2717 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
2720 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface, reg_idx, data, count);
2722 wined3d_mutex_lock();
2723 hr = IWineD3DDevice_GetPixelShaderConstantI(This->WineD3DDevice, reg_idx, data, count);
2724 wined3d_mutex_unlock();
2729 static HRESULT WINAPI IDirect3DDevice9Impl_SetPixelShaderConstantB(IDirect3DDevice9Ex *iface,
2730 UINT reg_idx, const BOOL *data, UINT count)
2732 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
2735 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface, reg_idx, data, count);
2737 wined3d_mutex_lock();
2738 hr = IWineD3DDevice_SetPixelShaderConstantB(This->WineD3DDevice, reg_idx, data, count);
2739 wined3d_mutex_unlock();
2744 static HRESULT WINAPI IDirect3DDevice9Impl_GetPixelShaderConstantB(IDirect3DDevice9Ex *iface,
2745 UINT reg_idx, BOOL *data, UINT count)
2747 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
2750 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface, reg_idx, data, count);
2752 wined3d_mutex_lock();
2753 hr = IWineD3DDevice_GetPixelShaderConstantB(This->WineD3DDevice, reg_idx, data, count);
2754 wined3d_mutex_unlock();
2759 static HRESULT WINAPI IDirect3DDevice9Impl_DrawRectPatch(IDirect3DDevice9Ex *iface, UINT Handle,
2760 const float *pNumSegs, const D3DRECTPATCH_INFO *pRectPatchInfo)
2762 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
2765 TRACE("iface %p, handle %#x, segment_count %p, patch_info %p.\n",
2766 iface, Handle, pNumSegs, pRectPatchInfo);
2768 wined3d_mutex_lock();
2769 hr = IWineD3DDevice_DrawRectPatch(This->WineD3DDevice, Handle, pNumSegs, (CONST WINED3DRECTPATCH_INFO *)pRectPatchInfo);
2770 wined3d_mutex_unlock();
2775 static HRESULT WINAPI IDirect3DDevice9Impl_DrawTriPatch(IDirect3DDevice9Ex *iface, UINT Handle,
2776 const float *pNumSegs, const D3DTRIPATCH_INFO *pTriPatchInfo)
2778 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
2781 TRACE("iface %p, handle %#x, segment_count %p, patch_info %p.\n",
2782 iface, Handle, pNumSegs, pTriPatchInfo);
2784 wined3d_mutex_lock();
2785 hr = IWineD3DDevice_DrawTriPatch(This->WineD3DDevice, Handle, pNumSegs, (CONST WINED3DTRIPATCH_INFO *)pTriPatchInfo);
2786 wined3d_mutex_unlock();
2791 static HRESULT WINAPI IDirect3DDevice9Impl_DeletePatch(IDirect3DDevice9Ex *iface, UINT Handle)
2793 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
2796 TRACE("iface %p, handle %#x.\n", iface, Handle);
2798 wined3d_mutex_lock();
2799 hr = IWineD3DDevice_DeletePatch(This->WineD3DDevice, Handle);
2800 wined3d_mutex_unlock();
2805 static HRESULT WINAPI IDirect3DDevice9Impl_CreateQuery(IDirect3DDevice9Ex *iface, D3DQUERYTYPE type,
2806 IDirect3DQuery9 **query)
2808 IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
2809 IDirect3DQuery9Impl *object;
2812 TRACE("iface %p, type %#x, query %p.\n", iface, type, query);
2814 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2817 ERR("Failed to allocate query memory.\n");
2818 return E_OUTOFMEMORY;
2821 hr = query_init(object, This, type);
2824 WARN("Failed to initialize query, hr %#x.\n", hr);
2825 HeapFree(GetProcessHeap(), 0, object);
2829 TRACE("Created query %p.\n", object);
2830 if (query) *query = &object->IDirect3DQuery9_iface;
2831 else IDirect3DQuery9_Release(&object->IDirect3DQuery9_iface);
2836 static HRESULT WINAPI IDirect3DDevice9ExImpl_SetConvolutionMonoKernel(IDirect3DDevice9Ex *iface,
2837 UINT width, UINT height, float *rows, float *columns)
2839 FIXME("iface %p, width %u, height %u, rows %p, columns %p stub!\n",
2840 iface, width, height, rows, columns);
2845 static HRESULT WINAPI IDirect3DDevice9ExImpl_ComposeRects(IDirect3DDevice9Ex *iface,
2846 IDirect3DSurface9 *src_surface, IDirect3DSurface9 *dst_surface, IDirect3DVertexBuffer9 *src_descs,
2847 UINT rect_count, IDirect3DVertexBuffer9 *dst_descs, D3DCOMPOSERECTSOP operation, INT offset_x, INT offset_y)
2849 FIXME("iface %p, src_surface %p, dst_surface %p, src_descs %p, rect_count %u,\n"
2850 "dst_descs %p, operation %#x, offset_x %u, offset_y %u stub!\n",
2851 iface, src_surface, dst_surface, src_descs, rect_count,
2852 dst_descs, operation, offset_x, offset_y);
2857 static HRESULT WINAPI IDirect3DDevice9ExImpl_PresentEx(IDirect3DDevice9Ex *iface,
2858 const RECT *src_rect, const RECT *dst_rect, HWND dst_window_override,
2859 const RGNDATA *dirty_region, DWORD flags)
2861 FIXME("iface %p, src_rect %p, dst_rect %p, dst_window_override %p, dirty_region %p, flags %#x stub!\n",
2862 iface, src_rect, dst_rect, dst_window_override, dirty_region, flags);
2867 static HRESULT WINAPI IDirect3DDevice9ExImpl_GetGPUThreadPriority(IDirect3DDevice9Ex *iface, INT *priority)
2869 FIXME("iface %p, priority %p stub!\n", iface, priority);
2874 static HRESULT WINAPI IDirect3DDevice9ExImpl_SetGPUThreadPriority(IDirect3DDevice9Ex *iface, INT priority)
2876 FIXME("iface %p, priority %d stub!\n", iface, priority);
2881 static HRESULT WINAPI IDirect3DDevice9ExImpl_WaitForVBlank(IDirect3DDevice9Ex *iface, UINT swapchain_idx)
2883 FIXME("iface %p, swapchain_idx %u stub!\n", iface, swapchain_idx);
2888 static HRESULT WINAPI IDirect3DDevice9ExImpl_CheckResourceResidency(IDirect3DDevice9Ex *iface,
2889 IDirect3DResource9 **resources, UINT32 resource_count)
2891 FIXME("iface %p, resources %p, resource_count %u stub!\n",
2892 iface, resources, resource_count);
2897 static HRESULT WINAPI IDirect3DDevice9ExImpl_SetMaximumFrameLatency(IDirect3DDevice9Ex *iface, UINT max_latency)
2899 FIXME("iface %p, max_latency %u stub!\n", iface, max_latency);
2904 static HRESULT WINAPI IDirect3DDevice9ExImpl_GetMaximumFrameLatency(IDirect3DDevice9Ex *iface, UINT *max_latency)
2906 FIXME("iface %p, max_latency %p stub!\n", iface, max_latency);
2913 static HRESULT WINAPI IDirect3DDevice9ExImpl_CheckDeviceState(IDirect3DDevice9Ex *iface, HWND dst_window)
2917 TRACE("iface %p, dst_window %p stub!\n", iface, dst_window);
2920 FIXME("iface %p, dst_window %p stub!\n", iface, dst_window);
2925 static HRESULT WINAPI IDirect3DDevice9ExImpl_CreateRenderTargetEx(IDirect3DDevice9Ex *iface,
2926 UINT width, UINT height, D3DFORMAT format, D3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality,
2927 BOOL lockable, IDirect3DSurface9 **surface, HANDLE *shared_handle, DWORD usage)
2929 FIXME("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u,\n"
2930 "lockable %#x, surface %p, shared_handle %p, usage %#x stub!\n",
2931 iface, width, height, format, multisample_type, multisample_quality,
2932 lockable, surface, shared_handle, usage);
2937 static HRESULT WINAPI IDirect3DDevice9ExImpl_CreateOffscreenPlainSurfaceEx(IDirect3DDevice9Ex *iface,
2938 UINT width, UINT height, D3DFORMAT format, D3DPOOL pool, IDirect3DSurface9 **surface,
2939 HANDLE *shared_handle, DWORD usage)
2941 FIXME("iface %p, width %u, height %u, format %#x, pool %#x, surface %p, shared_handle %p, usage %#x stub!\n",
2942 iface, width, height, format, pool, surface, shared_handle, usage);
2947 static HRESULT WINAPI IDirect3DDevice9ExImpl_CreateDepthStencilSurfaceEx(IDirect3DDevice9Ex *iface,
2948 UINT width, UINT height, D3DFORMAT format, D3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality,
2949 BOOL discard, 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 "discard %#x, surface %p, shared_handle %p, usage %#x stub!\n",
2953 iface, width, height, format, multisample_type, multisample_quality,
2954 discard, surface, shared_handle, usage);
2959 static HRESULT WINAPI IDirect3DDevice9ExImpl_ResetEx(IDirect3DDevice9Ex *iface,
2960 D3DPRESENT_PARAMETERS *present_parameters, D3DDISPLAYMODEEX *mode)
2962 FIXME("iface %p, present_parameters %p, mode %p stub!\n", iface, present_parameters, mode);
2967 static HRESULT WINAPI IDirect3DDevice9ExImpl_GetDisplayModeEx(IDirect3DDevice9Ex *iface,
2968 UINT swapchain_idx, D3DDISPLAYMODEEX *mode, D3DDISPLAYROTATION *rotation)
2970 FIXME("iface %p, swapchain_idx %u, mode %p, rotation %p stub!\n", iface, swapchain_idx, mode, rotation);
2975 static const IDirect3DDevice9ExVtbl Direct3DDevice9_Vtbl =
2978 IDirect3DDevice9Impl_QueryInterface,
2979 IDirect3DDevice9Impl_AddRef,
2980 IDirect3DDevice9Impl_Release,
2981 /* IDirect3DDevice9 */
2982 IDirect3DDevice9Impl_TestCooperativeLevel,
2983 IDirect3DDevice9Impl_GetAvailableTextureMem,
2984 IDirect3DDevice9Impl_EvictManagedResources,
2985 IDirect3DDevice9Impl_GetDirect3D,
2986 IDirect3DDevice9Impl_GetDeviceCaps,
2987 IDirect3DDevice9Impl_GetDisplayMode,
2988 IDirect3DDevice9Impl_GetCreationParameters,
2989 IDirect3DDevice9Impl_SetCursorProperties,
2990 IDirect3DDevice9Impl_SetCursorPosition,
2991 IDirect3DDevice9Impl_ShowCursor,
2992 IDirect3DDevice9Impl_CreateAdditionalSwapChain,
2993 IDirect3DDevice9Impl_GetSwapChain,
2994 IDirect3DDevice9Impl_GetNumberOfSwapChains,
2995 IDirect3DDevice9Impl_Reset,
2996 IDirect3DDevice9Impl_Present,
2997 IDirect3DDevice9Impl_GetBackBuffer,
2998 IDirect3DDevice9Impl_GetRasterStatus,
2999 IDirect3DDevice9Impl_SetDialogBoxMode,
3000 IDirect3DDevice9Impl_SetGammaRamp,
3001 IDirect3DDevice9Impl_GetGammaRamp,
3002 IDirect3DDevice9Impl_CreateTexture,
3003 IDirect3DDevice9Impl_CreateVolumeTexture,
3004 IDirect3DDevice9Impl_CreateCubeTexture,
3005 IDirect3DDevice9Impl_CreateVertexBuffer,
3006 IDirect3DDevice9Impl_CreateIndexBuffer,
3007 IDirect3DDevice9Impl_CreateRenderTarget,
3008 IDirect3DDevice9Impl_CreateDepthStencilSurface,
3009 IDirect3DDevice9Impl_UpdateSurface,
3010 IDirect3DDevice9Impl_UpdateTexture,
3011 IDirect3DDevice9Impl_GetRenderTargetData,
3012 IDirect3DDevice9Impl_GetFrontBufferData,
3013 IDirect3DDevice9Impl_StretchRect,
3014 IDirect3DDevice9Impl_ColorFill,
3015 IDirect3DDevice9Impl_CreateOffscreenPlainSurface,
3016 IDirect3DDevice9Impl_SetRenderTarget,
3017 IDirect3DDevice9Impl_GetRenderTarget,
3018 IDirect3DDevice9Impl_SetDepthStencilSurface,
3019 IDirect3DDevice9Impl_GetDepthStencilSurface,
3020 IDirect3DDevice9Impl_BeginScene,
3021 IDirect3DDevice9Impl_EndScene,
3022 IDirect3DDevice9Impl_Clear,
3023 IDirect3DDevice9Impl_SetTransform,
3024 IDirect3DDevice9Impl_GetTransform,
3025 IDirect3DDevice9Impl_MultiplyTransform,
3026 IDirect3DDevice9Impl_SetViewport,
3027 IDirect3DDevice9Impl_GetViewport,
3028 IDirect3DDevice9Impl_SetMaterial,
3029 IDirect3DDevice9Impl_GetMaterial,
3030 IDirect3DDevice9Impl_SetLight,
3031 IDirect3DDevice9Impl_GetLight,
3032 IDirect3DDevice9Impl_LightEnable,
3033 IDirect3DDevice9Impl_GetLightEnable,
3034 IDirect3DDevice9Impl_SetClipPlane,
3035 IDirect3DDevice9Impl_GetClipPlane,
3036 IDirect3DDevice9Impl_SetRenderState,
3037 IDirect3DDevice9Impl_GetRenderState,
3038 IDirect3DDevice9Impl_CreateStateBlock,
3039 IDirect3DDevice9Impl_BeginStateBlock,
3040 IDirect3DDevice9Impl_EndStateBlock,
3041 IDirect3DDevice9Impl_SetClipStatus,
3042 IDirect3DDevice9Impl_GetClipStatus,
3043 IDirect3DDevice9Impl_GetTexture,
3044 IDirect3DDevice9Impl_SetTexture,
3045 IDirect3DDevice9Impl_GetTextureStageState,
3046 IDirect3DDevice9Impl_SetTextureStageState,
3047 IDirect3DDevice9Impl_GetSamplerState,
3048 IDirect3DDevice9Impl_SetSamplerState,
3049 IDirect3DDevice9Impl_ValidateDevice,
3050 IDirect3DDevice9Impl_SetPaletteEntries,
3051 IDirect3DDevice9Impl_GetPaletteEntries,
3052 IDirect3DDevice9Impl_SetCurrentTexturePalette,
3053 IDirect3DDevice9Impl_GetCurrentTexturePalette,
3054 IDirect3DDevice9Impl_SetScissorRect,
3055 IDirect3DDevice9Impl_GetScissorRect,
3056 IDirect3DDevice9Impl_SetSoftwareVertexProcessing,
3057 IDirect3DDevice9Impl_GetSoftwareVertexProcessing,
3058 IDirect3DDevice9Impl_SetNPatchMode,
3059 IDirect3DDevice9Impl_GetNPatchMode,
3060 IDirect3DDevice9Impl_DrawPrimitive,
3061 IDirect3DDevice9Impl_DrawIndexedPrimitive,
3062 IDirect3DDevice9Impl_DrawPrimitiveUP,
3063 IDirect3DDevice9Impl_DrawIndexedPrimitiveUP,
3064 IDirect3DDevice9Impl_ProcessVertices,
3065 IDirect3DDevice9Impl_CreateVertexDeclaration,
3066 IDirect3DDevice9Impl_SetVertexDeclaration,
3067 IDirect3DDevice9Impl_GetVertexDeclaration,
3068 IDirect3DDevice9Impl_SetFVF,
3069 IDirect3DDevice9Impl_GetFVF,
3070 IDirect3DDevice9Impl_CreateVertexShader,
3071 IDirect3DDevice9Impl_SetVertexShader,
3072 IDirect3DDevice9Impl_GetVertexShader,
3073 IDirect3DDevice9Impl_SetVertexShaderConstantF,
3074 IDirect3DDevice9Impl_GetVertexShaderConstantF,
3075 IDirect3DDevice9Impl_SetVertexShaderConstantI,
3076 IDirect3DDevice9Impl_GetVertexShaderConstantI,
3077 IDirect3DDevice9Impl_SetVertexShaderConstantB,
3078 IDirect3DDevice9Impl_GetVertexShaderConstantB,
3079 IDirect3DDevice9Impl_SetStreamSource,
3080 IDirect3DDevice9Impl_GetStreamSource,
3081 IDirect3DDevice9Impl_SetStreamSourceFreq,
3082 IDirect3DDevice9Impl_GetStreamSourceFreq,
3083 IDirect3DDevice9Impl_SetIndices,
3084 IDirect3DDevice9Impl_GetIndices,
3085 IDirect3DDevice9Impl_CreatePixelShader,
3086 IDirect3DDevice9Impl_SetPixelShader,
3087 IDirect3DDevice9Impl_GetPixelShader,
3088 IDirect3DDevice9Impl_SetPixelShaderConstantF,
3089 IDirect3DDevice9Impl_GetPixelShaderConstantF,
3090 IDirect3DDevice9Impl_SetPixelShaderConstantI,
3091 IDirect3DDevice9Impl_GetPixelShaderConstantI,
3092 IDirect3DDevice9Impl_SetPixelShaderConstantB,
3093 IDirect3DDevice9Impl_GetPixelShaderConstantB,
3094 IDirect3DDevice9Impl_DrawRectPatch,
3095 IDirect3DDevice9Impl_DrawTriPatch,
3096 IDirect3DDevice9Impl_DeletePatch,
3097 IDirect3DDevice9Impl_CreateQuery,
3098 /* IDirect3DDevice9Ex */
3099 IDirect3DDevice9ExImpl_SetConvolutionMonoKernel,
3100 IDirect3DDevice9ExImpl_ComposeRects,
3101 IDirect3DDevice9ExImpl_PresentEx,
3102 IDirect3DDevice9ExImpl_GetGPUThreadPriority,
3103 IDirect3DDevice9ExImpl_SetGPUThreadPriority,
3104 IDirect3DDevice9ExImpl_WaitForVBlank,
3105 IDirect3DDevice9ExImpl_CheckResourceResidency,
3106 IDirect3DDevice9ExImpl_SetMaximumFrameLatency,
3107 IDirect3DDevice9ExImpl_GetMaximumFrameLatency,
3108 IDirect3DDevice9ExImpl_CheckDeviceState,
3109 IDirect3DDevice9ExImpl_CreateRenderTargetEx,
3110 IDirect3DDevice9ExImpl_CreateOffscreenPlainSurfaceEx,
3111 IDirect3DDevice9ExImpl_CreateDepthStencilSurfaceEx,
3112 IDirect3DDevice9ExImpl_ResetEx,
3113 IDirect3DDevice9ExImpl_GetDisplayModeEx
3116 /* IWineD3DDeviceParent IUnknown methods */
3118 static inline struct IDirect3DDevice9Impl *device_from_device_parent(IWineD3DDeviceParent *iface)
3120 return (struct IDirect3DDevice9Impl *)((char*)iface
3121 - FIELD_OFFSET(struct IDirect3DDevice9Impl, device_parent_vtbl));
3124 static HRESULT STDMETHODCALLTYPE device_parent_QueryInterface(IWineD3DDeviceParent *iface,
3125 REFIID riid, void **object)
3127 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
3128 return IDirect3DDevice9Impl_QueryInterface(&This->IDirect3DDevice9Ex_iface, riid, object);
3131 static ULONG STDMETHODCALLTYPE device_parent_AddRef(IWineD3DDeviceParent *iface)
3133 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
3134 return IDirect3DDevice9Impl_AddRef(&This->IDirect3DDevice9Ex_iface);
3137 static ULONG STDMETHODCALLTYPE device_parent_Release(IWineD3DDeviceParent *iface)
3139 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
3140 return IDirect3DDevice9Impl_Release(&This->IDirect3DDevice9Ex_iface);
3143 /* IWineD3DDeviceParent methods */
3145 static void STDMETHODCALLTYPE device_parent_WineD3DDeviceCreated(IWineD3DDeviceParent *iface, IWineD3DDevice *device)
3147 TRACE("iface %p, device %p\n", iface, device);
3150 static HRESULT STDMETHODCALLTYPE device_parent_CreateSurface(IWineD3DDeviceParent *iface,
3151 void *container_parent, UINT width, UINT height, enum wined3d_format_id format, DWORD usage,
3152 WINED3DPOOL pool, UINT level, WINED3DCUBEMAP_FACES face, struct wined3d_surface **surface)
3154 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
3155 IDirect3DSurface9Impl *d3d_surface;
3156 BOOL lockable = TRUE;
3159 TRACE("iface %p, container_parent %p, width %u, height %u, format %#x, usage %#x,\n"
3160 "\tpool %#x, level %u, face %u, surface %p\n",
3161 iface, container_parent, width, height, format, usage, pool, level, face, surface);
3163 if (pool == WINED3DPOOL_DEFAULT && !(usage & D3DUSAGE_DYNAMIC))
3166 hr = IDirect3DDevice9Impl_CreateSurface(This, width, height,
3167 d3dformat_from_wined3dformat(format), lockable, FALSE /* Discard */, level,
3168 (IDirect3DSurface9 **)&d3d_surface, usage, pool, D3DMULTISAMPLE_NONE, 0 /* MultisampleQuality */);
3171 ERR("(%p) CreateSurface failed, returning %#x\n", iface, hr);
3175 *surface = d3d_surface->wined3d_surface;
3176 wined3d_surface_incref(*surface);
3178 d3d_surface->container = container_parent;
3179 IDirect3DDevice9Ex_Release(d3d_surface->parentDevice);
3180 d3d_surface->parentDevice = NULL;
3182 IDirect3DSurface9_Release((IDirect3DSurface9 *)d3d_surface);
3183 d3d_surface->forwardReference = container_parent;
3188 static HRESULT STDMETHODCALLTYPE device_parent_CreateRenderTarget(IWineD3DDeviceParent *iface,
3189 void *container_parent, UINT width, UINT height, enum wined3d_format_id format,
3190 WINED3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality, BOOL lockable,
3191 struct wined3d_surface **surface)
3193 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
3194 IDirect3DSurface9Impl *d3d_surface;
3197 TRACE("iface %p, container_parent %p, width %u, height %u, format %#x, multisample_type %#x,\n"
3198 "\tmultisample_quality %u, lockable %u, surface %p\n",
3199 iface, container_parent, width, height, format, multisample_type, multisample_quality, lockable, surface);
3201 hr = IDirect3DDevice9Impl_CreateRenderTarget(&This->IDirect3DDevice9Ex_iface, width, height,
3202 d3dformat_from_wined3dformat(format), multisample_type, multisample_quality, lockable,
3203 (IDirect3DSurface9 **)&d3d_surface, NULL);
3206 ERR("(%p) CreateRenderTarget failed, returning %#x\n", iface, hr);
3210 *surface = d3d_surface->wined3d_surface;
3211 wined3d_surface_incref(*surface);
3213 d3d_surface->container = container_parent;
3214 /* Implicit surfaces are created with an refcount of 0 */
3215 IDirect3DSurface9_Release((IDirect3DSurface9 *)d3d_surface);
3220 static HRESULT STDMETHODCALLTYPE device_parent_CreateDepthStencilSurface(IWineD3DDeviceParent *iface,
3221 UINT width, UINT height, enum wined3d_format_id format, WINED3DMULTISAMPLE_TYPE multisample_type,
3222 DWORD multisample_quality, BOOL discard, struct wined3d_surface **surface)
3224 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
3225 IDirect3DSurface9Impl *d3d_surface;
3228 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x,\n"
3229 "\tmultisample_quality %u, discard %u, surface %p\n",
3230 iface, width, height, format, multisample_type, multisample_quality, discard, surface);
3232 hr = IDirect3DDevice9Impl_CreateDepthStencilSurface(&This->IDirect3DDevice9Ex_iface, width,
3233 height, d3dformat_from_wined3dformat(format), multisample_type, multisample_quality,
3234 discard, (IDirect3DSurface9 **)&d3d_surface, NULL);
3237 ERR("(%p) CreateDepthStencilSurface failed, returning %#x\n", iface, hr);
3241 *surface = d3d_surface->wined3d_surface;
3242 wined3d_surface_incref(*surface);
3243 d3d_surface->container = (IUnknown *)&This->IDirect3DDevice9Ex_iface;
3244 /* Implicit surfaces are created with an refcount of 0 */
3245 IDirect3DSurface9_Release((IDirect3DSurface9 *)d3d_surface);
3250 static HRESULT STDMETHODCALLTYPE device_parent_CreateVolume(IWineD3DDeviceParent *iface,
3251 void *container_parent, UINT width, UINT height, UINT depth, enum wined3d_format_id format,
3252 WINED3DPOOL pool, DWORD usage, struct wined3d_volume **volume)
3254 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
3255 IDirect3DVolume9Impl *object;
3258 TRACE("iface %p, container_parent %p, width %u, height %u, depth %u, format %#x, pool %#x, usage %#x, volume %p\n",
3259 iface, container_parent, width, height, depth, format, pool, usage, volume);
3261 /* Allocate the storage for the device */
3262 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
3265 FIXME("Allocation of memory failed\n");
3267 return D3DERR_OUTOFVIDEOMEMORY;
3270 hr = volume_init(object, This, width, height, depth, usage, format, pool);
3273 WARN("Failed to initialize volume, hr %#x.\n", hr);
3274 HeapFree(GetProcessHeap(), 0, object);
3278 *volume = object->wined3d_volume;
3279 wined3d_volume_incref(*volume);
3280 IDirect3DVolume9_Release(&object->IDirect3DVolume9_iface);
3282 object->container = container_parent;
3283 object->forwardReference = container_parent;
3285 TRACE("(%p) Created volume %p\n", iface, object);
3290 static HRESULT STDMETHODCALLTYPE device_parent_CreateSwapChain(IWineD3DDeviceParent *iface,
3291 WINED3DPRESENT_PARAMETERS *present_parameters, struct wined3d_swapchain **swapchain)
3293 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
3294 D3DPRESENT_PARAMETERS local_parameters;
3295 IDirect3DSwapChain9 *d3d_swapchain;
3298 TRACE("iface %p, present_parameters %p, swapchain %p\n", iface, present_parameters, swapchain);
3300 /* Copy the presentation parameters */
3301 local_parameters.BackBufferWidth = present_parameters->BackBufferWidth;
3302 local_parameters.BackBufferHeight = present_parameters->BackBufferHeight;
3303 local_parameters.BackBufferFormat = d3dformat_from_wined3dformat(present_parameters->BackBufferFormat);
3304 local_parameters.BackBufferCount = present_parameters->BackBufferCount;
3305 local_parameters.MultiSampleType = present_parameters->MultiSampleType;
3306 local_parameters.MultiSampleQuality = present_parameters->MultiSampleQuality;
3307 local_parameters.SwapEffect = present_parameters->SwapEffect;
3308 local_parameters.hDeviceWindow = present_parameters->hDeviceWindow;
3309 local_parameters.Windowed = present_parameters->Windowed;
3310 local_parameters.EnableAutoDepthStencil = present_parameters->EnableAutoDepthStencil;
3311 local_parameters.AutoDepthStencilFormat = d3dformat_from_wined3dformat(present_parameters->AutoDepthStencilFormat);
3312 local_parameters.Flags = present_parameters->Flags;
3313 local_parameters.FullScreen_RefreshRateInHz = present_parameters->FullScreen_RefreshRateInHz;
3314 local_parameters.PresentationInterval = present_parameters->PresentationInterval;
3316 hr = IDirect3DDevice9Impl_CreateAdditionalSwapChain(&This->IDirect3DDevice9Ex_iface,
3317 &local_parameters, &d3d_swapchain);
3320 ERR("(%p) CreateAdditionalSwapChain failed, returning %#x\n", iface, hr);
3325 *swapchain = ((IDirect3DSwapChain9Impl *)d3d_swapchain)->wined3d_swapchain;
3326 wined3d_swapchain_incref(*swapchain);
3327 IDirect3DSwapChain9_Release((IDirect3DSwapChain9 *)d3d_swapchain);
3329 /* Copy back the presentation parameters */
3330 present_parameters->BackBufferWidth = local_parameters.BackBufferWidth;
3331 present_parameters->BackBufferHeight = local_parameters.BackBufferHeight;
3332 present_parameters->BackBufferFormat = wined3dformat_from_d3dformat(local_parameters.BackBufferFormat);
3333 present_parameters->BackBufferCount = local_parameters.BackBufferCount;
3334 present_parameters->MultiSampleType = local_parameters.MultiSampleType;
3335 present_parameters->MultiSampleQuality = local_parameters.MultiSampleQuality;
3336 present_parameters->SwapEffect = local_parameters.SwapEffect;
3337 present_parameters->hDeviceWindow = local_parameters.hDeviceWindow;
3338 present_parameters->Windowed = local_parameters.Windowed;
3339 present_parameters->EnableAutoDepthStencil = local_parameters.EnableAutoDepthStencil;
3340 present_parameters->AutoDepthStencilFormat = wined3dformat_from_d3dformat(local_parameters.AutoDepthStencilFormat);
3341 present_parameters->Flags = local_parameters.Flags;
3342 present_parameters->FullScreen_RefreshRateInHz = local_parameters.FullScreen_RefreshRateInHz;
3343 present_parameters->PresentationInterval = local_parameters.PresentationInterval;
3348 static const IWineD3DDeviceParentVtbl d3d9_wined3d_device_parent_vtbl =
3350 /* IUnknown methods */
3351 device_parent_QueryInterface,
3352 device_parent_AddRef,
3353 device_parent_Release,
3354 /* IWineD3DDeviceParent methods */
3355 device_parent_WineD3DDeviceCreated,
3356 device_parent_CreateSurface,
3357 device_parent_CreateRenderTarget,
3358 device_parent_CreateDepthStencilSurface,
3359 device_parent_CreateVolume,
3360 device_parent_CreateSwapChain,
3363 static void setup_fpu(void)
3365 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
3367 __asm__ volatile ("fnstcw %0" : "=m" (cw));
3368 cw = (cw & ~0xf3f) | 0x3f;
3369 __asm__ volatile ("fldcw %0" : : "m" (cw));
3371 FIXME("FPU setup not implemented for this platform.\n");
3375 HRESULT device_init(IDirect3DDevice9Impl *device, struct wined3d *wined3d, UINT adapter, D3DDEVTYPE device_type,
3376 HWND focus_window, DWORD flags, D3DPRESENT_PARAMETERS *parameters, D3DDISPLAYMODEEX *mode)
3378 WINED3DPRESENT_PARAMETERS *wined3d_parameters;
3383 FIXME("Ignoring display mode.\n");
3385 device->IDirect3DDevice9Ex_iface.lpVtbl = &Direct3DDevice9_Vtbl;
3386 device->device_parent_vtbl = &d3d9_wined3d_device_parent_vtbl;
3389 if (!(flags & D3DCREATE_FPU_PRESERVE)) setup_fpu();
3391 wined3d_mutex_lock();
3392 hr = wined3d_device_create(wined3d, adapter, device_type, focus_window, flags,
3393 (IWineD3DDeviceParent *)&device->device_parent_vtbl, &device->WineD3DDevice);
3396 WARN("Failed to create wined3d device, hr %#x.\n", hr);
3397 wined3d_mutex_unlock();
3401 if (flags & D3DCREATE_ADAPTERGROUP_DEVICE)
3405 wined3d_get_device_caps(wined3d, adapter, device_type, &caps);
3406 count = caps.NumberOfAdaptersInGroup;
3409 if (flags & D3DCREATE_MULTITHREADED) IWineD3DDevice_SetMultithreaded(device->WineD3DDevice);
3411 if (!parameters->Windowed)
3413 if (!focus_window) focus_window = parameters->hDeviceWindow;
3414 if (FAILED(hr = IWineD3DDevice_AcquireFocusWindow(device->WineD3DDevice, focus_window)))
3416 ERR("Failed to acquire focus window, hr %#x.\n", hr);
3417 IWineD3DDevice_Release(device->WineD3DDevice);
3418 wined3d_mutex_unlock();
3422 for (i = 0; i < count; ++i)
3424 HWND device_window = parameters[i].hDeviceWindow;
3426 if (!device_window) device_window = focus_window;
3427 IWineD3DDevice_SetupFullscreenWindow(device->WineD3DDevice, device_window,
3428 parameters[i].BackBufferWidth,
3429 parameters[i].BackBufferHeight);
3433 wined3d_parameters = HeapAlloc(GetProcessHeap(), 0, sizeof(*wined3d_parameters) * count);
3434 if (!wined3d_parameters)
3436 ERR("Failed to allocate wined3d parameters.\n");
3437 IWineD3DDevice_Release(device->WineD3DDevice);
3438 wined3d_mutex_unlock();
3439 return E_OUTOFMEMORY;
3442 for (i = 0; i < count; ++i)
3444 wined3d_parameters[i].BackBufferWidth = parameters[i].BackBufferWidth;
3445 wined3d_parameters[i].BackBufferHeight = parameters[i].BackBufferHeight;
3446 wined3d_parameters[i].BackBufferFormat = wined3dformat_from_d3dformat(parameters[i].BackBufferFormat);
3447 wined3d_parameters[i].BackBufferCount = parameters[i].BackBufferCount;
3448 wined3d_parameters[i].MultiSampleType = parameters[i].MultiSampleType;
3449 wined3d_parameters[i].MultiSampleQuality = parameters[i].MultiSampleQuality;
3450 wined3d_parameters[i].SwapEffect = parameters[i].SwapEffect;
3451 wined3d_parameters[i].hDeviceWindow = parameters[i].hDeviceWindow;
3452 wined3d_parameters[i].Windowed = parameters[i].Windowed;
3453 wined3d_parameters[i].EnableAutoDepthStencil = parameters[i].EnableAutoDepthStencil;
3454 wined3d_parameters[i].AutoDepthStencilFormat =
3455 wined3dformat_from_d3dformat(parameters[i].AutoDepthStencilFormat);
3456 wined3d_parameters[i].Flags = parameters[i].Flags;
3457 wined3d_parameters[i].FullScreen_RefreshRateInHz = parameters[i].FullScreen_RefreshRateInHz;
3458 wined3d_parameters[i].PresentationInterval = parameters[i].PresentationInterval;
3459 wined3d_parameters[i].AutoRestoreDisplayMode = TRUE;
3462 hr = IWineD3DDevice_Init3D(device->WineD3DDevice, wined3d_parameters);
3465 WARN("Failed to initialize 3D, hr %#x.\n", hr);
3466 IWineD3DDevice_ReleaseFocusWindow(device->WineD3DDevice);
3467 HeapFree(GetProcessHeap(), 0, wined3d_parameters);
3468 IWineD3DDevice_Release(device->WineD3DDevice);
3469 wined3d_mutex_unlock();
3473 wined3d_mutex_unlock();
3475 for (i = 0; i < count; ++i)
3477 parameters[i].BackBufferWidth = wined3d_parameters[i].BackBufferWidth;
3478 parameters[i].BackBufferHeight = wined3d_parameters[i].BackBufferHeight;
3479 parameters[i].BackBufferFormat = d3dformat_from_wined3dformat(wined3d_parameters[i].BackBufferFormat);
3480 parameters[i].BackBufferCount = wined3d_parameters[i].BackBufferCount;
3481 parameters[i].MultiSampleType = wined3d_parameters[i].MultiSampleType;
3482 parameters[i].MultiSampleQuality = wined3d_parameters[i].MultiSampleQuality;
3483 parameters[i].SwapEffect = wined3d_parameters[i].SwapEffect;
3484 parameters[i].hDeviceWindow = wined3d_parameters[i].hDeviceWindow;
3485 parameters[i].Windowed = wined3d_parameters[i].Windowed;
3486 parameters[i].EnableAutoDepthStencil = wined3d_parameters[i].EnableAutoDepthStencil;
3487 parameters[i].AutoDepthStencilFormat =
3488 d3dformat_from_wined3dformat(wined3d_parameters[i].AutoDepthStencilFormat);
3489 parameters[i].Flags = wined3d_parameters[i].Flags;
3490 parameters[i].FullScreen_RefreshRateInHz = wined3d_parameters[i].FullScreen_RefreshRateInHz;
3491 parameters[i].PresentationInterval = wined3d_parameters[i].PresentationInterval;
3493 HeapFree(GetProcessHeap(), 0, wined3d_parameters);
3495 /* Initialize the converted declaration array. This creates a valid pointer
3496 * and when adding decls HeapReAlloc() can be used without further checking. */
3497 device->convertedDecls = HeapAlloc(GetProcessHeap(), 0, 0);
3498 if (!device->convertedDecls)
3500 ERR("Failed to allocate FVF vertex declaration map memory.\n");
3501 wined3d_mutex_lock();
3502 IWineD3DDevice_Uninit3D(device->WineD3DDevice);
3503 IWineD3DDevice_ReleaseFocusWindow(device->WineD3DDevice);
3504 IWineD3DDevice_Release(device->WineD3DDevice);
3505 wined3d_mutex_unlock();
3506 return E_OUTOFMEMORY;