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 ULONG WINAPI D3D9CB_DestroySwapChain(IWineD3DSwapChain *swapchain)
186 IDirect3DSwapChain9Impl *parent;
188 TRACE("swapchain %p.\n", swapchain);
190 parent = IWineD3DSwapChain_GetParent(swapchain);
191 parent->isImplicit = FALSE;
192 IDirect3DSwapChain9_AddRef((IDirect3DSwapChain9 *)parent);
193 return IDirect3DSwapChain9_Release((IDirect3DSwapChain9 *)parent);
196 /* IDirect3D IUnknown parts follow: */
197 static HRESULT WINAPI IDirect3DDevice9Impl_QueryInterface(LPDIRECT3DDEVICE9EX iface, REFIID riid, LPVOID* ppobj) {
198 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
200 IDirect3D9Impl *d3dimpl;
202 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
204 if (IsEqualGUID(riid, &IID_IUnknown)
205 || IsEqualGUID(riid, &IID_IDirect3DDevice9)) {
206 IDirect3DDevice9Ex_AddRef(iface);
208 TRACE("Returning IDirect3DDevice9 interface at %p\n", *ppobj);
210 } else if(IsEqualGUID(riid, &IID_IDirect3DDevice9Ex)) {
211 /* Find out if the creating d3d9 interface was created with Direct3DCreate9Ex.
212 * It doesn't matter with which function the device was created.
214 IDirect3DDevice9_GetDirect3D(iface, &d3d);
215 d3dimpl = (IDirect3D9Impl *) d3d;
217 if(d3dimpl->extended) {
219 IDirect3DDevice9Ex_AddRef((IDirect3DDevice9Ex *) *ppobj);
220 IDirect3D9_Release(d3d);
221 TRACE("Returning IDirect3DDevice9Ex interface at %p\n", *ppobj);
224 WARN("IDirect3D9 instance wasn't created with CreateDirect3D9Ex, returning E_NOINTERFACE\n");
225 IDirect3D9_Release(d3d);
227 return E_NOINTERFACE;
231 if (IsEqualGUID(riid, &IID_IWineD3DDeviceParent))
233 IUnknown_AddRef((IUnknown *)&This->device_parent_vtbl);
234 *ppobj = &This->device_parent_vtbl;
238 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
240 return E_NOINTERFACE;
243 static ULONG WINAPI IDirect3DDevice9Impl_AddRef(LPDIRECT3DDEVICE9EX iface) {
244 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
245 ULONG ref = InterlockedIncrement(&This->ref);
247 TRACE("%p increasing refcount to %u.\n", iface, ref);
252 static ULONG WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_Release(LPDIRECT3DDEVICE9EX iface) {
253 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
256 if (This->inDestruction) return 0;
257 ref = InterlockedDecrement(&This->ref);
259 TRACE("%p decreasing refcount to %u.\n", iface, ref);
263 This->inDestruction = TRUE;
265 wined3d_mutex_lock();
266 for(i = 0; i < This->numConvertedDecls; i++) {
267 /* Unless Wine is buggy or the app has a bug the refcount will be 0, because decls hold a reference to the
270 IDirect3DVertexDeclaration9Impl_Destroy(This->convertedDecls[i]);
272 HeapFree(GetProcessHeap(), 0, This->convertedDecls);
274 IWineD3DDevice_Uninit3D(This->WineD3DDevice, D3D9CB_DestroySwapChain);
275 IWineD3DDevice_ReleaseFocusWindow(This->WineD3DDevice);
276 IWineD3DDevice_Release(This->WineD3DDevice);
277 wined3d_mutex_unlock();
279 HeapFree(GetProcessHeap(), 0, This);
284 /* IDirect3DDevice Interface follow: */
285 static HRESULT WINAPI IDirect3DDevice9Impl_TestCooperativeLevel(IDirect3DDevice9Ex *iface)
287 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
289 TRACE("iface %p.\n", iface);
293 TRACE("D3D9 device is marked not reset.\n");
294 return D3DERR_DEVICENOTRESET;
300 static UINT WINAPI IDirect3DDevice9Impl_GetAvailableTextureMem(LPDIRECT3DDEVICE9EX iface) {
301 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
304 TRACE("iface %p.\n", iface);
306 wined3d_mutex_lock();
307 hr = IWineD3DDevice_GetAvailableTextureMem(This->WineD3DDevice);
308 wined3d_mutex_unlock();
313 static HRESULT WINAPI IDirect3DDevice9Impl_EvictManagedResources(LPDIRECT3DDEVICE9EX iface) {
314 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
317 TRACE("iface %p.\n", iface);
319 wined3d_mutex_lock();
320 hr = IWineD3DDevice_EvictManagedResources(This->WineD3DDevice);
321 wined3d_mutex_unlock();
326 static HRESULT WINAPI IDirect3DDevice9Impl_GetDirect3D(LPDIRECT3DDEVICE9EX iface, IDirect3D9** ppD3D9) {
327 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
331 TRACE("iface %p, d3d9 %p.\n", iface, ppD3D9);
333 if (NULL == ppD3D9) {
334 return D3DERR_INVALIDCALL;
337 wined3d_mutex_lock();
338 hr = IWineD3DDevice_GetDirect3D(This->WineD3DDevice, &pWineD3D);
339 if (hr == D3D_OK && pWineD3D != NULL)
341 *ppD3D9 = IWineD3D_GetParent(pWineD3D);
342 IDirect3D9_AddRef(*ppD3D9);
343 IWineD3D_Release(pWineD3D);
345 FIXME("Call to IWineD3DDevice_GetDirect3D failed\n");
348 TRACE("(%p) returning %p\n", This, *ppD3D9);
349 wined3d_mutex_unlock();
354 static HRESULT WINAPI IDirect3DDevice9Impl_GetDeviceCaps(LPDIRECT3DDEVICE9EX iface, D3DCAPS9* pCaps) {
355 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
356 HRESULT hrc = D3D_OK;
357 WINED3DCAPS *pWineCaps;
359 TRACE("iface %p, caps %p.\n", iface, pCaps);
362 return D3DERR_INVALIDCALL;
364 pWineCaps = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WINED3DCAPS));
365 if(pWineCaps == NULL){
366 return D3DERR_INVALIDCALL; /* well this is what MSDN says to return */
369 memset(pCaps, 0, sizeof(*pCaps));
371 wined3d_mutex_lock();
372 hrc = IWineD3DDevice_GetDeviceCaps(This->WineD3DDevice, pWineCaps);
373 wined3d_mutex_unlock();
375 WINECAPSTOD3D9CAPS(pCaps, pWineCaps)
376 HeapFree(GetProcessHeap(), 0, pWineCaps);
378 /* Some functionality is implemented in d3d9.dll, not wined3d.dll. Add the needed caps */
379 pCaps->DevCaps2 |= D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES;
383 TRACE("Returning %p %p\n", This, pCaps);
387 static HRESULT WINAPI IDirect3DDevice9Impl_GetDisplayMode(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain, D3DDISPLAYMODE* pMode) {
388 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
391 TRACE("iface %p, swapchain %u, mode %p.\n", iface, iSwapChain, pMode);
393 wined3d_mutex_lock();
394 hr = IWineD3DDevice_GetDisplayMode(This->WineD3DDevice, iSwapChain, (WINED3DDISPLAYMODE *) pMode);
395 wined3d_mutex_unlock();
397 if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format);
402 static HRESULT WINAPI IDirect3DDevice9Impl_GetCreationParameters(LPDIRECT3DDEVICE9EX iface, D3DDEVICE_CREATION_PARAMETERS *pParameters) {
403 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
406 TRACE("iface %p, parameters %p.\n", iface, pParameters);
408 wined3d_mutex_lock();
409 hr = IWineD3DDevice_GetCreationParameters(This->WineD3DDevice, (WINED3DDEVICE_CREATION_PARAMETERS *) pParameters);
410 wined3d_mutex_unlock();
415 static HRESULT WINAPI IDirect3DDevice9Impl_SetCursorProperties(LPDIRECT3DDEVICE9EX iface, UINT XHotSpot, UINT YHotSpot, IDirect3DSurface9* pCursorBitmap) {
416 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
417 IDirect3DSurface9Impl *pSurface = (IDirect3DSurface9Impl*)pCursorBitmap;
420 TRACE("iface %p, hotspot_x %u, hotspot_y %u, bitmap %p.\n",
421 iface, XHotSpot, YHotSpot, pCursorBitmap);
424 WARN("No cursor bitmap, returning WINED3DERR_INVALIDCALL\n");
425 return WINED3DERR_INVALIDCALL;
428 wined3d_mutex_lock();
429 hr = IWineD3DDevice_SetCursorProperties(This->WineD3DDevice, XHotSpot, YHotSpot, pSurface->wineD3DSurface);
430 wined3d_mutex_unlock();
435 static void WINAPI IDirect3DDevice9Impl_SetCursorPosition(LPDIRECT3DDEVICE9EX iface, int XScreenSpace, int YScreenSpace, DWORD Flags) {
436 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
438 TRACE("iface %p, x %u, y %u, flags %#x.\n", iface, XScreenSpace, YScreenSpace, Flags);
440 wined3d_mutex_lock();
441 IWineD3DDevice_SetCursorPosition(This->WineD3DDevice, XScreenSpace, YScreenSpace, Flags);
442 wined3d_mutex_unlock();
445 static BOOL WINAPI IDirect3DDevice9Impl_ShowCursor(LPDIRECT3DDEVICE9EX iface, BOOL bShow) {
446 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
449 TRACE("iface %p, show %#x.\n", iface, bShow);
451 wined3d_mutex_lock();
452 ret = IWineD3DDevice_ShowCursor(This->WineD3DDevice, bShow);
453 wined3d_mutex_unlock();
458 static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_CreateAdditionalSwapChain(IDirect3DDevice9Ex *iface,
459 D3DPRESENT_PARAMETERS *present_parameters, IDirect3DSwapChain9 **swapchain)
461 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
462 IDirect3DSwapChain9Impl *object;
465 TRACE("iface %p, present_parameters %p, swapchain %p.\n",
466 iface, present_parameters, swapchain);
468 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
471 ERR("Failed to allocate swapchain memory.\n");
472 return E_OUTOFMEMORY;
475 hr = swapchain_init(object, This, present_parameters);
478 WARN("Failed to initialize swapchain, hr %#x.\n", hr);
479 HeapFree(GetProcessHeap(), 0, object);
483 TRACE("Created swapchain %p.\n", object);
484 *swapchain = (IDirect3DSwapChain9 *)object;
489 static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_GetSwapChain(IDirect3DDevice9Ex *iface,
490 UINT swapchain_idx, IDirect3DSwapChain9 **swapchain)
492 IWineD3DSwapChain *wined3d_swapchain = NULL;
495 TRACE("iface %p, swapchain_idx %u, swapchain %p.\n", iface, swapchain_idx, swapchain);
497 wined3d_mutex_lock();
498 hr = IWineD3DDevice_GetSwapChain(((IDirect3DDevice9Impl *)iface)->WineD3DDevice,
499 swapchain_idx, &wined3d_swapchain);
500 if (SUCCEEDED(hr) && swapchain)
502 *swapchain = IWineD3DSwapChain_GetParent(wined3d_swapchain);
503 IDirect3DSwapChain9_AddRef(*swapchain);
504 IWineD3DSwapChain_Release(wined3d_swapchain);
510 wined3d_mutex_unlock();
515 static UINT WINAPI IDirect3DDevice9Impl_GetNumberOfSwapChains(IDirect3DDevice9Ex *iface)
519 TRACE("iface %p.\n", iface);
521 wined3d_mutex_lock();
522 count = IWineD3DDevice_GetNumberOfSwapChains(((IDirect3DDevice9Impl *)iface)->WineD3DDevice);
523 wined3d_mutex_unlock();
528 static HRESULT WINAPI reset_enum_callback(IWineD3DResource *resource, void *data) {
529 BOOL *resources_ok = data;
530 D3DRESOURCETYPE type;
532 WINED3DSURFACE_DESC surface_desc;
533 WINED3DVOLUME_DESC volume_desc;
534 D3DINDEXBUFFER_DESC index_desc;
535 D3DVERTEXBUFFER_DESC vertex_desc;
537 IDirect3DResource9 *parent;
539 parent = IWineD3DResource_GetParent(resource);
540 type = IDirect3DResource9_GetType(parent);
542 case D3DRTYPE_SURFACE:
543 IWineD3DSurface_GetDesc((IWineD3DSurface *) resource, &surface_desc);
544 pool = surface_desc.pool;
547 case D3DRTYPE_VOLUME:
548 IWineD3DVolume_GetDesc((IWineD3DVolume *) resource, &volume_desc);
549 pool = volume_desc.Pool;
552 case D3DRTYPE_INDEXBUFFER:
553 IDirect3DIndexBuffer9_GetDesc((IDirect3DIndexBuffer9 *) parent, &index_desc);
554 pool = index_desc.Pool;
557 case D3DRTYPE_VERTEXBUFFER:
558 IDirect3DVertexBuffer9_GetDesc((IDirect3DVertexBuffer9 *)parent, &vertex_desc);
559 pool = vertex_desc.Pool;
562 /* No need to check for textures. If there is a D3DPOOL_DEFAULT texture, there
563 * is a D3DPOOL_DEFAULT surface or volume as well
566 pool = WINED3DPOOL_SCRATCH; /* a harmless pool */
570 if (pool == WINED3DPOOL_DEFAULT)
572 IDirect3DResource9_AddRef(parent);
573 if (IUnknown_Release(parent) == 0)
575 TRACE("Parent %p is an implicit resource with ref 0\n", parent);
577 WARN("Resource %p(wineD3D %p) with pool D3DPOOL_DEFAULT blocks the Reset call\n", parent, resource);
579 *resources_ok = FALSE;
582 IWineD3DResource_Release(resource);
587 static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_Reset(LPDIRECT3DDEVICE9EX iface, D3DPRESENT_PARAMETERS* pPresentationParameters) {
588 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
589 WINED3DPRESENT_PARAMETERS localParameters;
591 BOOL resources_ok = TRUE;
594 TRACE("iface %p, present_parameters %p.\n", iface, pPresentationParameters);
596 /* Reset states that hold a COM object. WineD3D holds an internal reference to set objects, because
597 * such objects can still be used for rendering after their external d3d9 object has been destroyed.
598 * These objects must not be enumerated. Unsetting them tells WineD3D that the application will not
599 * make use of the hidden reference and destroys the objects.
601 * Unsetting them is no problem, because the states are supposed to be reset anyway. If the validation
602 * below fails, the device is considered "lost", and _Reset and _Release are the only allowed calls
604 wined3d_mutex_lock();
605 IWineD3DDevice_SetIndexBuffer(This->WineD3DDevice, NULL, WINED3DFMT_UNKNOWN);
606 for(i = 0; i < 16; i++) {
607 IWineD3DDevice_SetStreamSource(This->WineD3DDevice, i, NULL, 0, 0);
609 for(i = 0; i < 16; i++) {
610 IWineD3DDevice_SetTexture(This->WineD3DDevice, i, NULL);
613 IWineD3DDevice_EnumResources(This->WineD3DDevice, reset_enum_callback, &resources_ok);
615 WARN("The application is holding D3DPOOL_DEFAULT resources, rejecting reset\n");
616 This->notreset = TRUE;
617 wined3d_mutex_unlock();
619 return WINED3DERR_INVALIDCALL;
622 localParameters.BackBufferWidth = pPresentationParameters->BackBufferWidth;
623 localParameters.BackBufferHeight = pPresentationParameters->BackBufferHeight;
624 localParameters.BackBufferFormat = wined3dformat_from_d3dformat(pPresentationParameters->BackBufferFormat);
625 localParameters.BackBufferCount = pPresentationParameters->BackBufferCount;
626 localParameters.MultiSampleType = pPresentationParameters->MultiSampleType;
627 localParameters.MultiSampleQuality = pPresentationParameters->MultiSampleQuality;
628 localParameters.SwapEffect = pPresentationParameters->SwapEffect;
629 localParameters.hDeviceWindow = pPresentationParameters->hDeviceWindow;
630 localParameters.Windowed = pPresentationParameters->Windowed;
631 localParameters.EnableAutoDepthStencil = pPresentationParameters->EnableAutoDepthStencil;
632 localParameters.AutoDepthStencilFormat = wined3dformat_from_d3dformat(pPresentationParameters->AutoDepthStencilFormat);
633 localParameters.Flags = pPresentationParameters->Flags;
634 localParameters.FullScreen_RefreshRateInHz = pPresentationParameters->FullScreen_RefreshRateInHz;
635 localParameters.PresentationInterval = pPresentationParameters->PresentationInterval;
636 localParameters.AutoRestoreDisplayMode = TRUE;
638 hr = IWineD3DDevice_Reset(This->WineD3DDevice, &localParameters);
640 This->notreset = TRUE;
642 pPresentationParameters->BackBufferWidth = localParameters.BackBufferWidth;
643 pPresentationParameters->BackBufferHeight = localParameters.BackBufferHeight;
644 pPresentationParameters->BackBufferFormat = d3dformat_from_wined3dformat(localParameters.BackBufferFormat);
645 pPresentationParameters->BackBufferCount = localParameters.BackBufferCount;
646 pPresentationParameters->MultiSampleType = localParameters.MultiSampleType;
647 pPresentationParameters->MultiSampleQuality = localParameters.MultiSampleQuality;
648 pPresentationParameters->SwapEffect = localParameters.SwapEffect;
649 pPresentationParameters->hDeviceWindow = localParameters.hDeviceWindow;
650 pPresentationParameters->Windowed = localParameters.Windowed;
651 pPresentationParameters->EnableAutoDepthStencil = localParameters.EnableAutoDepthStencil;
652 pPresentationParameters->AutoDepthStencilFormat = d3dformat_from_wined3dformat(localParameters.AutoDepthStencilFormat);
653 pPresentationParameters->Flags = localParameters.Flags;
654 pPresentationParameters->FullScreen_RefreshRateInHz = localParameters.FullScreen_RefreshRateInHz;
655 pPresentationParameters->PresentationInterval = localParameters.PresentationInterval;
657 This->notreset = FALSE;
660 wined3d_mutex_unlock();
665 static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_Present(LPDIRECT3DDEVICE9EX iface, CONST RECT* pSourceRect,CONST RECT* pDestRect,HWND hDestWindowOverride,CONST RGNDATA*
667 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
670 TRACE("iface %p, src_rect %p, dst_rect %p, dst_window_override %p, dirty_region %p.\n",
671 iface, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
673 wined3d_mutex_lock();
674 hr = IWineD3DDevice_Present(This->WineD3DDevice, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
675 wined3d_mutex_unlock();
680 static HRESULT WINAPI IDirect3DDevice9Impl_GetBackBuffer(IDirect3DDevice9Ex *iface,
681 UINT iSwapChain, UINT BackBuffer, D3DBACKBUFFER_TYPE Type, IDirect3DSurface9 **ppBackBuffer)
683 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
684 IWineD3DSurface *retSurface = NULL;
687 TRACE("iface %p, swapchain %u, backbuffer_idx %u, backbuffer_type %#x, backbuffer %p.\n",
688 iface, iSwapChain, BackBuffer, Type, ppBackBuffer);
690 wined3d_mutex_lock();
691 hr = IWineD3DDevice_GetBackBuffer(This->WineD3DDevice, iSwapChain,
692 BackBuffer, (WINED3DBACKBUFFER_TYPE) Type, &retSurface);
693 if (SUCCEEDED(hr) && retSurface && ppBackBuffer)
695 *ppBackBuffer = IWineD3DSurface_GetParent(retSurface);
696 IDirect3DSurface9_AddRef(*ppBackBuffer);
697 IWineD3DSurface_Release(retSurface);
699 wined3d_mutex_unlock();
703 static HRESULT WINAPI IDirect3DDevice9Impl_GetRasterStatus(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain, D3DRASTER_STATUS* pRasterStatus) {
704 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
707 TRACE("iface %p, swapchain %u, raster_status %p.\n", iface, iSwapChain, pRasterStatus);
709 wined3d_mutex_lock();
710 hr = IWineD3DDevice_GetRasterStatus(This->WineD3DDevice, iSwapChain, (WINED3DRASTER_STATUS *) pRasterStatus);
711 wined3d_mutex_unlock();
716 static HRESULT WINAPI IDirect3DDevice9Impl_SetDialogBoxMode(LPDIRECT3DDEVICE9EX iface, BOOL bEnableDialogs) {
717 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
720 TRACE("iface %p, enable %#x.\n", iface, bEnableDialogs);
722 wined3d_mutex_lock();
723 hr = IWineD3DDevice_SetDialogBoxMode(This->WineD3DDevice, bEnableDialogs);
724 wined3d_mutex_unlock();
729 static void WINAPI IDirect3DDevice9Impl_SetGammaRamp(IDirect3DDevice9Ex *iface, UINT iSwapChain,
730 DWORD Flags, const D3DGAMMARAMP *pRamp)
732 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
734 TRACE("iface %p, swapchain %u, flags %#x, ramp %p.\n", iface, iSwapChain, Flags, pRamp);
736 /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
737 wined3d_mutex_lock();
738 IWineD3DDevice_SetGammaRamp(This->WineD3DDevice, iSwapChain, Flags, (CONST WINED3DGAMMARAMP *)pRamp);
739 wined3d_mutex_unlock();
742 static void WINAPI IDirect3DDevice9Impl_GetGammaRamp(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain, D3DGAMMARAMP* pRamp) {
743 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
745 TRACE("iface %p, swapchain %u, ramp %p.\n", iface, iSwapChain, pRamp);
747 /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
748 wined3d_mutex_lock();
749 IWineD3DDevice_GetGammaRamp(This->WineD3DDevice, iSwapChain, (WINED3DGAMMARAMP *) pRamp);
750 wined3d_mutex_unlock();
753 static HRESULT WINAPI IDirect3DDevice9Impl_CreateTexture(IDirect3DDevice9Ex *iface,
754 UINT width, UINT height, UINT levels, DWORD usage, D3DFORMAT format,
755 D3DPOOL pool, IDirect3DTexture9 **texture, HANDLE *shared_handle)
757 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
758 IDirect3DTexture9Impl *object;
761 TRACE("iface %p, width %u, height %u, levels %u, usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n",
762 iface, width, height, levels, usage, format, pool, texture, shared_handle);
764 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
767 ERR("Failed to allocate texture memory.\n");
768 return D3DERR_OUTOFVIDEOMEMORY;
771 hr = texture_init(object, This, width, height, levels, usage, format, pool);
774 WARN("Failed to initialize texture, hr %#x.\n", hr);
775 HeapFree(GetProcessHeap(), 0, object);
779 TRACE("Created texture %p.\n", object);
780 *texture = (IDirect3DTexture9 *)object;
785 static HRESULT WINAPI IDirect3DDevice9Impl_CreateVolumeTexture(IDirect3DDevice9Ex *iface,
786 UINT width, UINT height, UINT depth, UINT levels, DWORD usage, D3DFORMAT format,
787 D3DPOOL pool, IDirect3DVolumeTexture9 **texture, HANDLE *shared_handle)
789 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
790 IDirect3DVolumeTexture9Impl *object;
793 TRACE("iface %p, width %u, height %u, depth %u, levels %u\n",
794 iface, width, height, depth, levels);
795 TRACE("usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n",
796 usage, format, pool, texture, shared_handle);
798 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
801 ERR("Failed to allocate volume texture memory.\n");
802 return D3DERR_OUTOFVIDEOMEMORY;
805 hr = volumetexture_init(object, This, width, height, depth, levels, usage, format, pool);
808 WARN("Failed to initialize volume texture, hr %#x.\n", hr);
809 HeapFree(GetProcessHeap(), 0, object);
813 TRACE("Created volume texture %p.\n", object);
814 *texture = (IDirect3DVolumeTexture9 *)object;
819 static HRESULT WINAPI IDirect3DDevice9Impl_CreateCubeTexture(IDirect3DDevice9Ex *iface,
820 UINT edge_length, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool,
821 IDirect3DCubeTexture9 **texture, HANDLE *shared_handle)
823 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
824 IDirect3DCubeTexture9Impl *object;
827 TRACE("iface %p, edge_length %u, levels %u, usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n",
828 iface, edge_length, levels, usage, format, pool, texture, shared_handle);
830 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
833 ERR("Failed to allocate cube texture memory.\n");
834 return D3DERR_OUTOFVIDEOMEMORY;
837 hr = cubetexture_init(object, This, edge_length, levels, usage, format, pool);
840 WARN("Failed to initialize cube texture, hr %#x.\n", hr);
841 HeapFree(GetProcessHeap(), 0, object);
845 TRACE("Created cube texture %p.\n", object);
846 *texture = (IDirect3DCubeTexture9 *)object;
851 static HRESULT WINAPI IDirect3DDevice9Impl_CreateVertexBuffer(IDirect3DDevice9Ex *iface, UINT size, DWORD usage,
852 DWORD fvf, D3DPOOL pool, IDirect3DVertexBuffer9 **buffer, HANDLE *shared_handle)
854 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
855 IDirect3DVertexBuffer9Impl *object;
858 TRACE("iface %p, size %u, usage %#x, fvf %#x, pool %#x, buffer %p, shared_handle %p.\n",
859 iface, size, usage, fvf, pool, buffer, shared_handle);
861 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
864 ERR("Failed to allocate buffer memory.\n");
865 return D3DERR_OUTOFVIDEOMEMORY;
868 hr = vertexbuffer_init(object, This, size, usage, fvf, pool);
871 WARN("Failed to initialize vertex buffer, hr %#x.\n", hr);
872 HeapFree(GetProcessHeap(), 0, object);
876 TRACE("Created vertex buffer %p.\n", object);
877 *buffer = (IDirect3DVertexBuffer9 *)object;
882 static HRESULT WINAPI IDirect3DDevice9Impl_CreateIndexBuffer(IDirect3DDevice9Ex *iface, UINT size, DWORD usage,
883 D3DFORMAT format, D3DPOOL pool, IDirect3DIndexBuffer9 **buffer, HANDLE *shared_handle)
885 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
886 IDirect3DIndexBuffer9Impl *object;
889 TRACE("iface %p, size %u, usage %#x, format %#x, pool %#x, buffer %p, shared_handle %p.\n",
890 iface, size, usage, format, pool, buffer, shared_handle);
892 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
895 ERR("Failed to allocate buffer memory.\n");
896 return D3DERR_OUTOFVIDEOMEMORY;
899 hr = indexbuffer_init(object, This, size, usage, format, pool);
902 WARN("Failed to initialize index buffer, hr %#x.\n", hr);
903 HeapFree(GetProcessHeap(), 0, object);
907 TRACE("Created index buffer %p.\n", object);
908 *buffer = (IDirect3DIndexBuffer9 *)object;
913 static HRESULT IDirect3DDevice9Impl_CreateSurface(LPDIRECT3DDEVICE9EX iface, UINT Width, UINT Height,
914 D3DFORMAT Format, BOOL Lockable, BOOL Discard, UINT Level, IDirect3DSurface9 **ppSurface,
915 UINT Usage, D3DPOOL Pool, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality)
917 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
918 IDirect3DSurface9Impl *object;
921 TRACE("iface %p, width %u, height %u, format %#x, lockable %#x, discard %#x, level %u, surface %p.\n"
922 "usage %#x, pool %#x, multisample_type %#x, multisample_quality %u.\n",
923 iface, Width, Height, Format, Lockable, Discard, Level, ppSurface,
924 Usage, Pool, MultiSample, MultisampleQuality);
926 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DSurface9Impl));
929 FIXME("Failed to allocate surface memory.\n");
930 return D3DERR_OUTOFVIDEOMEMORY;
933 hr = surface_init(object, This, Width, Height, Format, Lockable, Discard,
934 Level, Usage, Pool, MultiSample, MultisampleQuality);
937 WARN("Failed to initialize surface, hr %#x.\n", hr);
938 HeapFree(GetProcessHeap(), 0, object);
942 TRACE("Created surface %p.\n", object);
943 *ppSurface = (IDirect3DSurface9 *)object;
948 static HRESULT WINAPI IDirect3DDevice9Impl_CreateRenderTarget(IDirect3DDevice9Ex *iface, UINT Width, UINT Height,
949 D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality, BOOL Lockable,
950 IDirect3DSurface9 **ppSurface, HANDLE *pSharedHandle)
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(iface, Width, Height, Format, Lockable, FALSE /* Discard */,
960 0 /* Level */, ppSurface, D3DUSAGE_RENDERTARGET, D3DPOOL_DEFAULT, MultiSample, MultisampleQuality);
965 static HRESULT WINAPI IDirect3DDevice9Impl_CreateDepthStencilSurface(LPDIRECT3DDEVICE9EX iface, UINT Width, UINT Height,
966 D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample,
967 DWORD MultisampleQuality, BOOL Discard,
968 IDirect3DSurface9 **ppSurface, HANDLE* pSharedHandle) {
971 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u.\n"
972 "discard %#x, surface %p, shared_handle %p.\n",
973 iface, Width, Height, Format, MultiSample, MultisampleQuality,
974 Discard, ppSurface, pSharedHandle);
976 hr = IDirect3DDevice9Impl_CreateSurface(iface, Width, Height, Format, TRUE /* Lockable */, Discard,
977 0 /* Level */, ppSurface, D3DUSAGE_DEPTHSTENCIL, D3DPOOL_DEFAULT, MultiSample, MultisampleQuality);
983 static HRESULT WINAPI IDirect3DDevice9Impl_UpdateSurface(LPDIRECT3DDEVICE9EX iface, IDirect3DSurface9* pSourceSurface, CONST RECT* pSourceRect, IDirect3DSurface9* pDestinationSurface, CONST POINT* pDestPoint) {
984 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
987 TRACE("iface %p, src_surface %p, src_rect %p, dst_surface %p, dst_point %p.\n",
988 iface, pSourceSurface, pSourceRect, pDestinationSurface, pDestPoint);
990 wined3d_mutex_lock();
991 hr = IWineD3DDevice_UpdateSurface(This->WineD3DDevice, ((IDirect3DSurface9Impl *)pSourceSurface)->wineD3DSurface, pSourceRect, ((IDirect3DSurface9Impl *)pDestinationSurface)->wineD3DSurface, pDestPoint);
992 wined3d_mutex_unlock();
997 static HRESULT WINAPI IDirect3DDevice9Impl_UpdateTexture(LPDIRECT3DDEVICE9EX iface, IDirect3DBaseTexture9* pSourceTexture, IDirect3DBaseTexture9* pDestinationTexture) {
998 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1001 TRACE("iface %p, src_texture %p, dst_texture %p.\n", iface, pSourceTexture, pDestinationTexture);
1003 wined3d_mutex_lock();
1004 hr = IWineD3DDevice_UpdateTexture(This->WineD3DDevice, ((IDirect3DBaseTexture9Impl *)pSourceTexture)->wineD3DBaseTexture, ((IDirect3DBaseTexture9Impl *)pDestinationTexture)->wineD3DBaseTexture);
1005 wined3d_mutex_unlock();
1010 static HRESULT WINAPI IDirect3DDevice9Impl_GetRenderTargetData(IDirect3DDevice9Ex *iface,
1011 IDirect3DSurface9 *pRenderTarget, IDirect3DSurface9 *pDestSurface)
1013 IDirect3DSurface9Impl *renderTarget = (IDirect3DSurface9Impl *)pRenderTarget;
1014 IDirect3DSurface9Impl *destSurface = (IDirect3DSurface9Impl *)pDestSurface;
1017 TRACE("iface %p, render_target %p, dst_surface %p.\n", iface, pRenderTarget, pDestSurface);
1019 wined3d_mutex_lock();
1020 hr = IWineD3DSurface_BltFast(destSurface->wineD3DSurface, 0, 0, renderTarget->wineD3DSurface, NULL, WINEDDBLTFAST_NOCOLORKEY);
1021 wined3d_mutex_unlock();
1026 static HRESULT WINAPI IDirect3DDevice9Impl_GetFrontBufferData(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain, IDirect3DSurface9* pDestSurface) {
1027 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1028 IDirect3DSurface9Impl *destSurface = (IDirect3DSurface9Impl *)pDestSurface;
1031 TRACE("iface %p, swapchain %u, dst_surface %p.\n", iface, iSwapChain, pDestSurface);
1033 wined3d_mutex_lock();
1034 hr = IWineD3DDevice_GetFrontBufferData(This->WineD3DDevice, iSwapChain, destSurface->wineD3DSurface);
1035 wined3d_mutex_unlock();
1040 static HRESULT WINAPI IDirect3DDevice9Impl_StretchRect(IDirect3DDevice9Ex *iface, IDirect3DSurface9 *pSourceSurface,
1041 const RECT *pSourceRect, IDirect3DSurface9 *pDestSurface, const RECT *pDestRect, D3DTEXTUREFILTERTYPE Filter)
1043 IDirect3DSurface9Impl *src = (IDirect3DSurface9Impl *) pSourceSurface;
1044 IDirect3DSurface9Impl *dst = (IDirect3DSurface9Impl *) pDestSurface;
1047 TRACE("iface %p, src_surface %p, src_rect %p, dst_surface %p, dst_rect %p, filter %#x.\n",
1048 iface, pSourceSurface, pSourceRect, pDestSurface, pDestRect, Filter);
1050 wined3d_mutex_lock();
1051 hr = IWineD3DSurface_Blt(dst->wineD3DSurface, pDestRect, src->wineD3DSurface, pSourceRect, 0, NULL, Filter);
1052 wined3d_mutex_unlock();
1057 static HRESULT WINAPI IDirect3DDevice9Impl_ColorFill(IDirect3DDevice9Ex *iface,
1058 IDirect3DSurface9 *pSurface, const RECT *pRect, D3DCOLOR color)
1060 const WINED3DCOLORVALUE c =
1062 ((color >> 16) & 0xff) / 255.0f,
1063 ((color >> 8) & 0xff) / 255.0f,
1064 (color & 0xff) / 255.0f,
1065 ((color >> 24) & 0xff) / 255.0f,
1067 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1068 IDirect3DSurface9Impl *surface = (IDirect3DSurface9Impl *)pSurface;
1070 WINED3DRESOURCETYPE restype;
1072 WINED3DSURFACE_DESC desc;
1075 TRACE("iface %p, surface %p, rect %p, color 0x%08x.\n", iface, pSurface, pRect, color);
1077 wined3d_mutex_lock();
1079 IWineD3DSurface_GetDesc(surface->wineD3DSurface, &desc);
1082 restype = desc.resource_type;
1084 /* This method is only allowed with surfaces that are render targets, or offscreen plain surfaces
1085 * in D3DPOOL_DEFAULT
1087 if(!(usage & WINED3DUSAGE_RENDERTARGET) && (pool != WINED3DPOOL_DEFAULT || restype != WINED3DRTYPE_SURFACE)) {
1088 wined3d_mutex_unlock();
1089 WARN("Surface is not a render target, or not a stand-alone D3DPOOL_DEFAULT surface\n");
1090 return D3DERR_INVALIDCALL;
1093 /* Colorfill can only be used on rendertarget surfaces, or offscreen plain surfaces in D3DPOOL_DEFAULT */
1094 hr = IWineD3DDevice_ColorFill(This->WineD3DDevice, surface->wineD3DSurface, pRect, &c);
1096 wined3d_mutex_unlock();
1101 static HRESULT WINAPI IDirect3DDevice9Impl_CreateOffscreenPlainSurface(LPDIRECT3DDEVICE9EX iface, UINT Width, UINT Height, D3DFORMAT Format, D3DPOOL Pool, IDirect3DSurface9 **ppSurface, HANDLE* pSharedHandle) {
1104 TRACE("iface %p, width %u, height %u, format %#x, pool %#x, surface %p, shared_handle %p.\n",
1105 iface, Width, Height, Format, Pool, ppSurface, pSharedHandle);
1107 if(Pool == D3DPOOL_MANAGED ){
1108 FIXME("Attempting to create a managed offscreen plain surface\n");
1109 return D3DERR_INVALIDCALL;
1112 'Off-screen plain surfaces are always lockable, regardless of their pool types.'
1114 D3DPOOL_DEFAULT is the appropriate pool for use with the IDirect3DDevice9::StretchRect and IDirect3DDevice9::ColorFill.
1115 Why, their always lockable?
1116 should I change the usage to dynamic?
1118 hr = IDirect3DDevice9Impl_CreateSurface(iface, Width, Height, Format, TRUE /* Lockable */, FALSE /* Discard */,
1119 0 /* Level */, ppSurface, 0 /* Usage (undefined/none) */, (WINED3DPOOL)Pool, D3DMULTISAMPLE_NONE,
1120 0 /* MultisampleQuality */);
1125 /* TODO: move to wineD3D */
1126 static HRESULT WINAPI IDirect3DDevice9Impl_SetRenderTarget(LPDIRECT3DDEVICE9EX iface, DWORD RenderTargetIndex, IDirect3DSurface9* pRenderTarget) {
1127 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1128 IDirect3DSurface9Impl *pSurface = (IDirect3DSurface9Impl*)pRenderTarget;
1131 TRACE("iface %p, idx %u, surface %p.\n", iface, RenderTargetIndex, pRenderTarget);
1133 if (RenderTargetIndex >= D3D9_MAX_SIMULTANEOUS_RENDERTARGETS)
1135 WARN("Invalid index %u specified.\n", RenderTargetIndex);
1136 return D3DERR_INVALIDCALL;
1139 wined3d_mutex_lock();
1140 hr = IWineD3DDevice_SetRenderTarget(This->WineD3DDevice, RenderTargetIndex, pSurface ? pSurface->wineD3DSurface : NULL, TRUE);
1141 wined3d_mutex_unlock();
1146 static HRESULT WINAPI IDirect3DDevice9Impl_GetRenderTarget(IDirect3DDevice9Ex *iface,
1147 DWORD RenderTargetIndex, IDirect3DSurface9 **ppRenderTarget)
1149 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1150 IWineD3DSurface *pRenderTarget;
1153 TRACE("iface %p, idx %u, surface %p.\n", iface, RenderTargetIndex, ppRenderTarget);
1155 if (ppRenderTarget == NULL) {
1156 return D3DERR_INVALIDCALL;
1159 if (RenderTargetIndex >= D3D9_MAX_SIMULTANEOUS_RENDERTARGETS)
1161 WARN("Invalid index %u specified.\n", RenderTargetIndex);
1162 return D3DERR_INVALIDCALL;
1165 wined3d_mutex_lock();
1167 hr=IWineD3DDevice_GetRenderTarget(This->WineD3DDevice,RenderTargetIndex,&pRenderTarget);
1171 FIXME("Call to IWineD3DDevice_GetRenderTarget failed, hr %#x\n", hr);
1173 else if (!pRenderTarget)
1175 *ppRenderTarget = NULL;
1179 *ppRenderTarget = IWineD3DSurface_GetParent(pRenderTarget);
1180 IDirect3DSurface9_AddRef(*ppRenderTarget);
1181 IWineD3DSurface_Release(pRenderTarget);
1184 wined3d_mutex_unlock();
1189 static HRESULT WINAPI IDirect3DDevice9Impl_SetDepthStencilSurface(LPDIRECT3DDEVICE9EX iface, IDirect3DSurface9* pZStencilSurface) {
1190 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1191 IDirect3DSurface9Impl *pSurface;
1194 TRACE("iface %p, depth_stencil %p.\n", iface, pZStencilSurface);
1196 pSurface = (IDirect3DSurface9Impl*)pZStencilSurface;
1198 wined3d_mutex_lock();
1199 hr = IWineD3DDevice_SetDepthStencilSurface(This->WineD3DDevice, NULL==pSurface ? NULL : pSurface->wineD3DSurface);
1200 wined3d_mutex_unlock();
1205 static HRESULT WINAPI IDirect3DDevice9Impl_GetDepthStencilSurface(IDirect3DDevice9Ex *iface,
1206 IDirect3DSurface9 **ppZStencilSurface)
1208 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1209 IWineD3DSurface *pZStencilSurface;
1212 TRACE("iface %p, depth_stencil %p.\n", iface, ppZStencilSurface);
1214 if(ppZStencilSurface == NULL){
1215 return D3DERR_INVALIDCALL;
1218 wined3d_mutex_lock();
1219 hr = IWineD3DDevice_GetDepthStencilSurface(This->WineD3DDevice,&pZStencilSurface);
1222 *ppZStencilSurface = IWineD3DSurface_GetParent(pZStencilSurface);
1223 IDirect3DSurface9_AddRef(*ppZStencilSurface);
1224 IWineD3DSurface_Release(pZStencilSurface);
1228 if (hr != WINED3DERR_NOTFOUND)
1229 WARN("Call to IWineD3DDevice_GetDepthStencilSurface failed with 0x%08x\n", hr);
1230 *ppZStencilSurface = NULL;
1232 wined3d_mutex_unlock();
1237 static HRESULT WINAPI IDirect3DDevice9Impl_BeginScene(LPDIRECT3DDEVICE9EX iface) {
1238 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1241 TRACE("iface %p.\n", iface);
1243 wined3d_mutex_lock();
1244 hr = IWineD3DDevice_BeginScene(This->WineD3DDevice);
1245 wined3d_mutex_unlock();
1250 static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_EndScene(LPDIRECT3DDEVICE9EX iface) {
1251 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1254 TRACE("iface %p.\n", iface);
1256 wined3d_mutex_lock();
1257 hr = IWineD3DDevice_EndScene(This->WineD3DDevice);
1258 wined3d_mutex_unlock();
1263 static HRESULT WINAPI IDirect3DDevice9Impl_Clear(LPDIRECT3DDEVICE9EX iface, DWORD Count, CONST D3DRECT* pRects, DWORD Flags, D3DCOLOR Color, float Z, DWORD Stencil) {
1264 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1267 TRACE("iface %p, rect_count %u, rects %p, flags %#x, color 0x%08x, z %.8e, stencil %u.\n",
1268 iface, Count, pRects, Flags, Color, Z, Stencil);
1270 /* Note: D3DRECT is compatible with WINED3DRECT */
1271 wined3d_mutex_lock();
1272 hr = IWineD3DDevice_Clear(This->WineD3DDevice, Count, (const RECT *)pRects, Flags, Color, Z, Stencil);
1273 wined3d_mutex_unlock();
1278 static HRESULT WINAPI IDirect3DDevice9Impl_SetTransform(LPDIRECT3DDEVICE9EX iface, D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX* lpMatrix) {
1279 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1282 TRACE("iface %p, state %#x, matrix %p.\n", iface, State, lpMatrix);
1284 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1285 wined3d_mutex_lock();
1286 hr = IWineD3DDevice_SetTransform(This->WineD3DDevice, State, (CONST WINED3DMATRIX*) lpMatrix);
1287 wined3d_mutex_unlock();
1292 static HRESULT WINAPI IDirect3DDevice9Impl_GetTransform(LPDIRECT3DDEVICE9EX iface, D3DTRANSFORMSTATETYPE State, D3DMATRIX* pMatrix) {
1293 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1296 TRACE("iface %p, state %#x, matrix %p.\n", iface, State, pMatrix);
1298 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1299 wined3d_mutex_lock();
1300 hr = IWineD3DDevice_GetTransform(This->WineD3DDevice, State, (WINED3DMATRIX*) pMatrix);
1301 wined3d_mutex_unlock();
1306 static HRESULT WINAPI IDirect3DDevice9Impl_MultiplyTransform(LPDIRECT3DDEVICE9EX iface, D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX* pMatrix) {
1307 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1310 TRACE("iface %p, state %#x, matrix %p.\n", iface, State, pMatrix);
1312 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1313 wined3d_mutex_lock();
1314 hr = IWineD3DDevice_MultiplyTransform(This->WineD3DDevice, State, (CONST WINED3DMATRIX*) pMatrix);
1315 wined3d_mutex_unlock();
1320 static HRESULT WINAPI IDirect3DDevice9Impl_SetViewport(LPDIRECT3DDEVICE9EX iface, CONST D3DVIEWPORT9* pViewport) {
1321 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1324 TRACE("iface %p, viewport %p.\n", iface, pViewport);
1326 /* Note: D3DVIEWPORT9 is compatible with WINED3DVIEWPORT */
1327 wined3d_mutex_lock();
1328 hr = IWineD3DDevice_SetViewport(This->WineD3DDevice, (const WINED3DVIEWPORT *)pViewport);
1329 wined3d_mutex_unlock();
1334 static HRESULT WINAPI IDirect3DDevice9Impl_GetViewport(LPDIRECT3DDEVICE9EX iface, D3DVIEWPORT9* pViewport) {
1335 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1338 TRACE("iface %p, viewport %p.\n", iface, pViewport);
1340 /* Note: D3DVIEWPORT9 is compatible with WINED3DVIEWPORT */
1341 wined3d_mutex_lock();
1342 hr = IWineD3DDevice_GetViewport(This->WineD3DDevice, (WINED3DVIEWPORT *)pViewport);
1343 wined3d_mutex_unlock();
1348 static HRESULT WINAPI IDirect3DDevice9Impl_SetMaterial(LPDIRECT3DDEVICE9EX iface, CONST D3DMATERIAL9* pMaterial) {
1349 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1352 TRACE("iface %p, material %p.\n", iface, pMaterial);
1354 /* Note: D3DMATERIAL9 is compatible with WINED3DMATERIAL */
1355 wined3d_mutex_lock();
1356 hr = IWineD3DDevice_SetMaterial(This->WineD3DDevice, (const WINED3DMATERIAL *)pMaterial);
1357 wined3d_mutex_unlock();
1362 static HRESULT WINAPI IDirect3DDevice9Impl_GetMaterial(LPDIRECT3DDEVICE9EX iface, D3DMATERIAL9* pMaterial) {
1363 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1366 TRACE("iface %p, material %p.\n", iface, pMaterial);
1368 /* Note: D3DMATERIAL9 is compatible with WINED3DMATERIAL */
1369 wined3d_mutex_lock();
1370 hr = IWineD3DDevice_GetMaterial(This->WineD3DDevice, (WINED3DMATERIAL *)pMaterial);
1371 wined3d_mutex_unlock();
1376 static HRESULT WINAPI IDirect3DDevice9Impl_SetLight(LPDIRECT3DDEVICE9EX iface, DWORD Index, CONST D3DLIGHT9* pLight) {
1377 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1380 TRACE("iface %p, index %u, light %p.\n", iface, Index, pLight);
1382 /* Note: D3DLIGHT9 is compatible with WINED3DLIGHT */
1383 wined3d_mutex_lock();
1384 hr = IWineD3DDevice_SetLight(This->WineD3DDevice, Index, (const WINED3DLIGHT *)pLight);
1385 wined3d_mutex_unlock();
1390 static HRESULT WINAPI IDirect3DDevice9Impl_GetLight(LPDIRECT3DDEVICE9EX iface, DWORD Index, D3DLIGHT9* pLight) {
1391 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1394 TRACE("iface %p, index %u, light %p.\n", iface, Index, pLight);
1396 /* Note: D3DLIGHT9 is compatible with WINED3DLIGHT */
1397 wined3d_mutex_lock();
1398 hr = IWineD3DDevice_GetLight(This->WineD3DDevice, Index, (WINED3DLIGHT *)pLight);
1399 wined3d_mutex_unlock();
1404 static HRESULT WINAPI IDirect3DDevice9Impl_LightEnable(LPDIRECT3DDEVICE9EX iface, DWORD Index, BOOL Enable) {
1405 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1408 TRACE("iface %p, index %u, enable %#x.\n", iface, Index, Enable);
1410 wined3d_mutex_lock();
1411 hr = IWineD3DDevice_SetLightEnable(This->WineD3DDevice, Index, Enable);
1412 wined3d_mutex_unlock();
1417 static HRESULT WINAPI IDirect3DDevice9Impl_GetLightEnable(LPDIRECT3DDEVICE9EX iface, DWORD Index, BOOL* pEnable) {
1418 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1421 TRACE("iface %p, index %u, enable %p.\n", iface, Index, pEnable);
1423 wined3d_mutex_lock();
1424 hr = IWineD3DDevice_GetLightEnable(This->WineD3DDevice, Index, pEnable);
1425 wined3d_mutex_unlock();
1430 static HRESULT WINAPI IDirect3DDevice9Impl_SetClipPlane(LPDIRECT3DDEVICE9EX iface, DWORD Index, CONST float* pPlane) {
1431 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1434 TRACE("iface %p, index %u, plane %p.\n", iface, Index, pPlane);
1436 wined3d_mutex_lock();
1437 hr = IWineD3DDevice_SetClipPlane(This->WineD3DDevice, Index, pPlane);
1438 wined3d_mutex_unlock();
1443 static HRESULT WINAPI IDirect3DDevice9Impl_GetClipPlane(LPDIRECT3DDEVICE9EX iface, DWORD Index, float* pPlane) {
1444 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1447 TRACE("iface %p, index %u, plane %p.\n", iface, Index, pPlane);
1449 wined3d_mutex_lock();
1450 hr = IWineD3DDevice_GetClipPlane(This->WineD3DDevice, Index, pPlane);
1451 wined3d_mutex_unlock();
1456 static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_SetRenderState(LPDIRECT3DDEVICE9EX iface, D3DRENDERSTATETYPE State, DWORD Value) {
1457 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1460 TRACE("iface %p, state %#x, value %#x.\n", iface, State, Value);
1462 wined3d_mutex_lock();
1463 hr = IWineD3DDevice_SetRenderState(This->WineD3DDevice, State, Value);
1464 wined3d_mutex_unlock();
1469 static HRESULT WINAPI IDirect3DDevice9Impl_GetRenderState(LPDIRECT3DDEVICE9EX iface, D3DRENDERSTATETYPE State, DWORD* pValue) {
1470 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1473 TRACE("iface %p, state %#x, value %p.\n", iface, State, pValue);
1475 wined3d_mutex_lock();
1476 hr = IWineD3DDevice_GetRenderState(This->WineD3DDevice, State, pValue);
1477 wined3d_mutex_unlock();
1482 static HRESULT WINAPI IDirect3DDevice9Impl_CreateStateBlock(IDirect3DDevice9Ex *iface,
1483 D3DSTATEBLOCKTYPE type, IDirect3DStateBlock9 **stateblock)
1485 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1486 IDirect3DStateBlock9Impl *object;
1489 TRACE("iface %p, type %#x, stateblock %p.\n", iface, type, stateblock);
1491 if (type != D3DSBT_ALL && type != D3DSBT_PIXELSTATE && type != D3DSBT_VERTEXSTATE)
1493 WARN("Unexpected stateblock type, returning D3DERR_INVALIDCALL.\n");
1494 return D3DERR_INVALIDCALL;
1497 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1500 ERR("Failed to allocate stateblock memory.\n");
1501 return E_OUTOFMEMORY;
1504 hr = stateblock_init(object, This, type, NULL);
1507 WARN("Failed to initialize stateblock, hr %#x.\n", hr);
1508 HeapFree(GetProcessHeap(), 0, object);
1512 TRACE("Created stateblock %p.\n", object);
1513 *stateblock = (IDirect3DStateBlock9 *)object;
1518 static HRESULT WINAPI IDirect3DDevice9Impl_BeginStateBlock(IDirect3DDevice9Ex *iface)
1520 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1523 TRACE("iface %p.\n", iface);
1525 wined3d_mutex_lock();
1526 hr = IWineD3DDevice_BeginStateBlock(This->WineD3DDevice);
1527 wined3d_mutex_unlock();
1532 static HRESULT WINAPI IDirect3DDevice9Impl_EndStateBlock(IDirect3DDevice9Ex *iface, IDirect3DStateBlock9 **stateblock)
1534 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1535 IWineD3DStateBlock *wined3d_stateblock;
1536 IDirect3DStateBlock9Impl *object;
1539 TRACE("iface %p, stateblock %p.\n", iface, stateblock);
1541 wined3d_mutex_lock();
1542 hr = IWineD3DDevice_EndStateBlock(This->WineD3DDevice, &wined3d_stateblock);
1543 wined3d_mutex_unlock();
1546 WARN("IWineD3DDevice_EndStateBlock() failed, hr %#x.\n", hr);
1550 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1553 ERR("Failed to allocate stateblock memory.\n");
1554 IWineD3DStateBlock_Release(wined3d_stateblock);
1555 return E_OUTOFMEMORY;
1558 hr = stateblock_init(object, This, 0, wined3d_stateblock);
1561 WARN("Failed to initialize stateblock, hr %#x.\n", hr);
1562 IWineD3DStateBlock_Release(wined3d_stateblock);
1563 HeapFree(GetProcessHeap(), 0, object);
1567 TRACE("Created stateblock %p.\n", object);
1568 *stateblock = (IDirect3DStateBlock9 *)object;
1573 static HRESULT WINAPI IDirect3DDevice9Impl_SetClipStatus(LPDIRECT3DDEVICE9EX iface, CONST D3DCLIPSTATUS9* pClipStatus) {
1574 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1577 TRACE("iface %p, clip_status %p.\n", iface, pClipStatus);
1579 wined3d_mutex_lock();
1580 hr = IWineD3DDevice_SetClipStatus(This->WineD3DDevice, (const WINED3DCLIPSTATUS *)pClipStatus);
1581 wined3d_mutex_unlock();
1586 static HRESULT WINAPI IDirect3DDevice9Impl_GetClipStatus(LPDIRECT3DDEVICE9EX iface, D3DCLIPSTATUS9* pClipStatus) {
1587 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1590 TRACE("iface %p, clip_status %p.\n", iface, pClipStatus);
1592 wined3d_mutex_lock();
1593 hr = IWineD3DDevice_GetClipStatus(This->WineD3DDevice, (WINED3DCLIPSTATUS *)pClipStatus);
1594 wined3d_mutex_unlock();
1599 static HRESULT WINAPI IDirect3DDevice9Impl_GetTexture(IDirect3DDevice9Ex *iface,
1600 DWORD Stage, IDirect3DBaseTexture9 **ppTexture)
1602 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1603 IWineD3DBaseTexture *retTexture = NULL;
1606 TRACE("iface %p, stage %u, texture %p.\n", iface, Stage, ppTexture);
1608 if(ppTexture == NULL){
1609 return D3DERR_INVALIDCALL;
1612 wined3d_mutex_lock();
1613 hr = IWineD3DDevice_GetTexture(This->WineD3DDevice, Stage, &retTexture);
1614 if (SUCCEEDED(hr) && retTexture)
1616 *ppTexture = IWineD3DBaseTexture_GetParent(retTexture);
1617 IWineD3DBaseTexture_AddRef(*ppTexture);
1618 IWineD3DBaseTexture_Release(retTexture);
1624 WARN("Call to get texture (%d) failed (%p)\n", Stage, retTexture);
1628 wined3d_mutex_unlock();
1633 static HRESULT WINAPI IDirect3DDevice9Impl_SetTexture(LPDIRECT3DDEVICE9EX iface, DWORD Stage, IDirect3DBaseTexture9* pTexture) {
1634 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1637 TRACE("iface %p, stage %u, texture %p.\n", iface, Stage, pTexture);
1639 wined3d_mutex_lock();
1640 hr = IWineD3DDevice_SetTexture(This->WineD3DDevice, Stage,
1641 pTexture==NULL ? NULL:((IDirect3DBaseTexture9Impl *)pTexture)->wineD3DBaseTexture);
1642 wined3d_mutex_unlock();
1647 static const WINED3DTEXTURESTAGESTATETYPE tss_lookup[] =
1649 WINED3DTSS_FORCE_DWORD, /* 0, unused */
1650 WINED3DTSS_COLOROP, /* 1, D3DTSS_COLOROP */
1651 WINED3DTSS_COLORARG1, /* 2, D3DTSS_COLORARG1 */
1652 WINED3DTSS_COLORARG2, /* 3, D3DTSS_COLORARG2 */
1653 WINED3DTSS_ALPHAOP, /* 4, D3DTSS_ALPHAOP */
1654 WINED3DTSS_ALPHAARG1, /* 5, D3DTSS_ALPHAARG1 */
1655 WINED3DTSS_ALPHAARG2, /* 6, D3DTSS_ALPHAARG2 */
1656 WINED3DTSS_BUMPENVMAT00, /* 7, D3DTSS_BUMPENVMAT00 */
1657 WINED3DTSS_BUMPENVMAT01, /* 8, D3DTSS_BUMPENVMAT01 */
1658 WINED3DTSS_BUMPENVMAT10, /* 9, D3DTSS_BUMPENVMAT10 */
1659 WINED3DTSS_BUMPENVMAT11, /* 10, D3DTSS_BUMPENVMAT11 */
1660 WINED3DTSS_TEXCOORDINDEX, /* 11, D3DTSS_TEXCOORDINDEX */
1661 WINED3DTSS_FORCE_DWORD, /* 12, unused */
1662 WINED3DTSS_FORCE_DWORD, /* 13, unused */
1663 WINED3DTSS_FORCE_DWORD, /* 14, unused */
1664 WINED3DTSS_FORCE_DWORD, /* 15, unused */
1665 WINED3DTSS_FORCE_DWORD, /* 16, unused */
1666 WINED3DTSS_FORCE_DWORD, /* 17, unused */
1667 WINED3DTSS_FORCE_DWORD, /* 18, unused */
1668 WINED3DTSS_FORCE_DWORD, /* 19, unused */
1669 WINED3DTSS_FORCE_DWORD, /* 20, unused */
1670 WINED3DTSS_FORCE_DWORD, /* 21, unused */
1671 WINED3DTSS_BUMPENVLSCALE, /* 22, D3DTSS_BUMPENVLSCALE */
1672 WINED3DTSS_BUMPENVLOFFSET, /* 23, D3DTSS_BUMPENVLOFFSET */
1673 WINED3DTSS_TEXTURETRANSFORMFLAGS, /* 24, D3DTSS_TEXTURETRANSFORMFLAGS */
1674 WINED3DTSS_FORCE_DWORD, /* 25, unused */
1675 WINED3DTSS_COLORARG0, /* 26, D3DTSS_COLORARG0 */
1676 WINED3DTSS_ALPHAARG0, /* 27, D3DTSS_ALPHAARG0 */
1677 WINED3DTSS_RESULTARG, /* 28, D3DTSS_RESULTARG */
1678 WINED3DTSS_FORCE_DWORD, /* 29, unused */
1679 WINED3DTSS_FORCE_DWORD, /* 30, unused */
1680 WINED3DTSS_FORCE_DWORD, /* 31, unused */
1681 WINED3DTSS_CONSTANT, /* 32, D3DTSS_CONSTANT */
1684 static HRESULT WINAPI IDirect3DDevice9Impl_GetTextureStageState(LPDIRECT3DDEVICE9EX iface, DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD *pValue)
1686 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1689 TRACE("iface %p, stage %u, state %#x, value %p.\n", iface, Stage, Type, pValue);
1691 if (Type >= sizeof(tss_lookup) / sizeof(*tss_lookup))
1693 WARN("Invalid Type %#x passed.\n", Type);
1697 wined3d_mutex_lock();
1698 hr = IWineD3DDevice_GetTextureStageState(This->WineD3DDevice, Stage, tss_lookup[Type], pValue);
1699 wined3d_mutex_unlock();
1704 static HRESULT WINAPI IDirect3DDevice9Impl_SetTextureStageState(LPDIRECT3DDEVICE9EX iface, DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD Value)
1706 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1709 TRACE("iface %p, stage %u, state %#x, value %#x.\n", iface, Stage, Type, Value);
1711 if (Type >= sizeof(tss_lookup) / sizeof(*tss_lookup))
1713 WARN("Invalid Type %#x passed.\n", Type);
1717 wined3d_mutex_lock();
1718 hr = IWineD3DDevice_SetTextureStageState(This->WineD3DDevice, Stage, tss_lookup[Type], Value);
1719 wined3d_mutex_unlock();
1724 static HRESULT WINAPI IDirect3DDevice9Impl_GetSamplerState(IDirect3DDevice9Ex *iface, DWORD Sampler,
1725 D3DSAMPLERSTATETYPE Type, DWORD *pValue)
1727 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1730 TRACE("iface %p, sampler %u, state %#x, value %p.\n", iface, Sampler, Type, pValue);
1732 wined3d_mutex_lock();
1733 hr = IWineD3DDevice_GetSamplerState(This->WineD3DDevice, Sampler, Type, pValue);
1734 wined3d_mutex_unlock();
1739 static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_SetSamplerState(LPDIRECT3DDEVICE9EX iface, DWORD Sampler, D3DSAMPLERSTATETYPE Type, DWORD Value) {
1740 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1743 TRACE("iface %p, sampler %u, state %#x, value %#x.\n", iface, Sampler, Type, Value);
1745 wined3d_mutex_lock();
1746 hr = IWineD3DDevice_SetSamplerState(This->WineD3DDevice, Sampler, Type, Value);
1747 wined3d_mutex_unlock();
1752 static HRESULT WINAPI IDirect3DDevice9Impl_ValidateDevice(LPDIRECT3DDEVICE9EX iface, DWORD* pNumPasses) {
1753 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1756 TRACE("iface %p, pass_count %p.\n", iface, pNumPasses);
1758 wined3d_mutex_lock();
1759 hr = IWineD3DDevice_ValidateDevice(This->WineD3DDevice, pNumPasses);
1760 wined3d_mutex_unlock();
1765 static HRESULT WINAPI IDirect3DDevice9Impl_SetPaletteEntries(IDirect3DDevice9Ex *iface, UINT PaletteNumber,
1766 const PALETTEENTRY *pEntries)
1768 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1771 TRACE("iface %p, palette_idx %u, entries %p.\n", iface, PaletteNumber, pEntries);
1773 wined3d_mutex_lock();
1774 hr = IWineD3DDevice_SetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
1775 wined3d_mutex_unlock();
1780 static HRESULT WINAPI IDirect3DDevice9Impl_GetPaletteEntries(LPDIRECT3DDEVICE9EX iface, UINT PaletteNumber, PALETTEENTRY* pEntries) {
1781 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1784 TRACE("iface %p, palette_idx %u, entries %p.\n", iface, PaletteNumber, pEntries);
1786 wined3d_mutex_lock();
1787 hr = IWineD3DDevice_GetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
1788 wined3d_mutex_unlock();
1793 static HRESULT WINAPI IDirect3DDevice9Impl_SetCurrentTexturePalette(LPDIRECT3DDEVICE9EX iface, UINT PaletteNumber) {
1794 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1797 TRACE("iface %p, palette_idx %u.\n", iface, PaletteNumber);
1799 wined3d_mutex_lock();
1800 hr = IWineD3DDevice_SetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
1801 wined3d_mutex_unlock();
1806 static HRESULT WINAPI IDirect3DDevice9Impl_GetCurrentTexturePalette(LPDIRECT3DDEVICE9EX iface, UINT* PaletteNumber) {
1807 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1810 TRACE("iface %p, palette_idx %p.\n", iface, PaletteNumber);
1812 wined3d_mutex_lock();
1813 hr = IWineD3DDevice_GetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
1814 wined3d_mutex_unlock();
1819 static HRESULT WINAPI IDirect3DDevice9Impl_SetScissorRect(LPDIRECT3DDEVICE9EX iface, CONST RECT* pRect) {
1820 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1823 TRACE("iface %p, rect %p.\n", iface, pRect);
1825 wined3d_mutex_lock();
1826 hr = IWineD3DDevice_SetScissorRect(This->WineD3DDevice, pRect);
1827 wined3d_mutex_unlock();
1832 static HRESULT WINAPI IDirect3DDevice9Impl_GetScissorRect(LPDIRECT3DDEVICE9EX iface, RECT* pRect) {
1833 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1836 TRACE("iface %p, rect %p.\n", iface, pRect);
1838 wined3d_mutex_lock();
1839 hr = IWineD3DDevice_GetScissorRect(This->WineD3DDevice, pRect);
1840 wined3d_mutex_unlock();
1845 static HRESULT WINAPI IDirect3DDevice9Impl_SetSoftwareVertexProcessing(LPDIRECT3DDEVICE9EX iface, BOOL bSoftware) {
1846 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1849 TRACE("iface %p, software %#x.\n", iface, bSoftware);
1851 wined3d_mutex_lock();
1852 hr = IWineD3DDevice_SetSoftwareVertexProcessing(This->WineD3DDevice, bSoftware);
1853 wined3d_mutex_unlock();
1858 static BOOL WINAPI IDirect3DDevice9Impl_GetSoftwareVertexProcessing(LPDIRECT3DDEVICE9EX iface) {
1859 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1862 TRACE("iface %p.\n", iface);
1864 wined3d_mutex_lock();
1865 ret = IWineD3DDevice_GetSoftwareVertexProcessing(This->WineD3DDevice);
1866 wined3d_mutex_unlock();
1871 static HRESULT WINAPI IDirect3DDevice9Impl_SetNPatchMode(LPDIRECT3DDEVICE9EX iface, float nSegments) {
1872 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1875 TRACE("iface %p, segment_count %.8e.\n", iface, nSegments);
1877 wined3d_mutex_lock();
1878 hr = IWineD3DDevice_SetNPatchMode(This->WineD3DDevice, nSegments);
1879 wined3d_mutex_unlock();
1884 static float WINAPI IDirect3DDevice9Impl_GetNPatchMode(LPDIRECT3DDEVICE9EX iface) {
1885 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1888 TRACE("iface %p.\n", iface);
1890 wined3d_mutex_lock();
1891 ret = IWineD3DDevice_GetNPatchMode(This->WineD3DDevice);
1892 wined3d_mutex_unlock();
1897 static HRESULT WINAPI IDirect3DDevice9Impl_DrawPrimitive(IDirect3DDevice9Ex *iface, D3DPRIMITIVETYPE PrimitiveType,
1898 UINT StartVertex, UINT PrimitiveCount)
1900 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1903 TRACE("iface %p, primitive_type %#x, start_vertex %u, primitive_count %u.\n",
1904 iface, PrimitiveType, StartVertex, PrimitiveCount);
1906 wined3d_mutex_lock();
1907 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1908 hr = IWineD3DDevice_DrawPrimitive(This->WineD3DDevice, StartVertex,
1909 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount));
1910 wined3d_mutex_unlock();
1915 static HRESULT WINAPI IDirect3DDevice9Impl_DrawIndexedPrimitive(LPDIRECT3DDEVICE9EX iface, D3DPRIMITIVETYPE PrimitiveType,
1916 INT BaseVertexIndex, UINT MinVertexIndex, UINT NumVertices, UINT startIndex, UINT primCount) {
1917 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1920 TRACE("iface %p, primitive_type %#x, base_vertex_idx %u, min_vertex_idx %u,\n"
1921 "vertex_count %u, start_idx %u, primitive_count %u.\n",
1922 iface, PrimitiveType, BaseVertexIndex, MinVertexIndex,
1923 NumVertices, startIndex, primCount);
1925 wined3d_mutex_lock();
1926 IWineD3DDevice_SetBaseVertexIndex(This->WineD3DDevice, BaseVertexIndex);
1927 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1928 hr = IWineD3DDevice_DrawIndexedPrimitive(This->WineD3DDevice, startIndex,
1929 vertex_count_from_primitive_count(PrimitiveType, primCount));
1930 wined3d_mutex_unlock();
1935 static HRESULT WINAPI IDirect3DDevice9Impl_DrawPrimitiveUP(IDirect3DDevice9Ex *iface, D3DPRIMITIVETYPE PrimitiveType,
1936 UINT PrimitiveCount, const void *pVertexStreamZeroData, UINT VertexStreamZeroStride)
1938 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1941 TRACE("iface %p, primitive_type %#x, primitive_count %u, data %p, stride %u.\n",
1942 iface, PrimitiveType, PrimitiveCount, pVertexStreamZeroData, VertexStreamZeroStride);
1944 wined3d_mutex_lock();
1945 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1946 hr = IWineD3DDevice_DrawPrimitiveUP(This->WineD3DDevice,
1947 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount),
1948 pVertexStreamZeroData, VertexStreamZeroStride);
1949 wined3d_mutex_unlock();
1954 static HRESULT WINAPI IDirect3DDevice9Impl_DrawIndexedPrimitiveUP(LPDIRECT3DDEVICE9EX iface, D3DPRIMITIVETYPE PrimitiveType, UINT MinVertexIndex,
1955 UINT NumVertexIndices, UINT PrimitiveCount, CONST void* pIndexData,
1956 D3DFORMAT IndexDataFormat, CONST void* pVertexStreamZeroData, UINT VertexStreamZeroStride) {
1957 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1960 TRACE("iface %p, primitive_type %#x, min_vertex_idx %u, index_count %u, primitive_count %u,\n"
1961 "index_data %p, index_format %#x, vertex_data %p, vertex_stride %u.\n",
1962 iface, PrimitiveType, MinVertexIndex, NumVertexIndices, PrimitiveCount,
1963 pIndexData, IndexDataFormat, pVertexStreamZeroData, VertexStreamZeroStride);
1965 wined3d_mutex_lock();
1966 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1967 hr = IWineD3DDevice_DrawIndexedPrimitiveUP(This->WineD3DDevice,
1968 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount), pIndexData,
1969 wined3dformat_from_d3dformat(IndexDataFormat), pVertexStreamZeroData, VertexStreamZeroStride);
1970 wined3d_mutex_unlock();
1975 static HRESULT WINAPI IDirect3DDevice9Impl_ProcessVertices(LPDIRECT3DDEVICE9EX iface, UINT SrcStartIndex, UINT DestIndex, UINT VertexCount, IDirect3DVertexBuffer9* pDestBuffer, IDirect3DVertexDeclaration9* pVertexDecl, DWORD Flags) {
1976 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1977 IDirect3DVertexDeclaration9Impl *Decl = (IDirect3DVertexDeclaration9Impl *) pVertexDecl;
1979 IDirect3DVertexBuffer9Impl *dest = (IDirect3DVertexBuffer9Impl *) pDestBuffer;
1981 TRACE("iface %p, src_start_idx %u, dst_idx %u, vertex_count %u, dst_buffer %p, declaration %p, flags %#x.\n",
1982 iface, SrcStartIndex, DestIndex, VertexCount, pDestBuffer, pVertexDecl, Flags);
1984 wined3d_mutex_lock();
1985 hr = IWineD3DDevice_ProcessVertices(This->WineD3DDevice,SrcStartIndex, DestIndex, VertexCount, dest->wineD3DVertexBuffer, Decl ? Decl->wineD3DVertexDeclaration : NULL, Flags, dest->fvf);
1986 wined3d_mutex_unlock();
1991 static HRESULT WINAPI IDirect3DDevice9Impl_CreateVertexDeclaration(IDirect3DDevice9Ex *iface,
1992 const D3DVERTEXELEMENT9 *elements, IDirect3DVertexDeclaration9 **declaration)
1994 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1995 IDirect3DVertexDeclaration9Impl *object;
1998 TRACE("iface %p, elements %p, declaration %p.\n", iface, elements, declaration);
2002 WARN("Caller passed a NULL declaration, returning D3DERR_INVALIDCALL.\n");
2003 return D3DERR_INVALIDCALL;
2006 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2009 ERR("Failed to allocate vertex declaration memory.\n");
2010 return E_OUTOFMEMORY;
2013 hr = vertexdeclaration_init(object, This, elements);
2016 WARN("Failed to initialize vertex declaration, hr %#x.\n", hr);
2017 HeapFree(GetProcessHeap(), 0, object);
2021 TRACE("Created vertex declaration %p.\n", object);
2022 *declaration = (IDirect3DVertexDeclaration9 *)object;
2027 static HRESULT WINAPI IDirect3DDevice9Impl_SetVertexDeclaration(IDirect3DDevice9Ex *iface,
2028 IDirect3DVertexDeclaration9 *declaration)
2032 TRACE("iface %p, declaration %p.\n", iface, declaration);
2034 wined3d_mutex_lock();
2035 hr = IWineD3DDevice_SetVertexDeclaration(((IDirect3DDevice9Impl *)iface)->WineD3DDevice,
2036 declaration ? ((IDirect3DVertexDeclaration9Impl *)declaration)->wineD3DVertexDeclaration : NULL);
2037 wined3d_mutex_unlock();
2042 static HRESULT WINAPI IDirect3DDevice9Impl_GetVertexDeclaration(IDirect3DDevice9Ex *iface,
2043 IDirect3DVertexDeclaration9 **declaration)
2045 IWineD3DVertexDeclaration *wined3d_declaration = NULL;
2048 TRACE("iface %p, declaration %p.\n", iface, declaration);
2050 if (!declaration) return D3DERR_INVALIDCALL;
2052 wined3d_mutex_lock();
2053 hr = IWineD3DDevice_GetVertexDeclaration(((IDirect3DDevice9Impl *)iface)->WineD3DDevice, &wined3d_declaration);
2054 if (SUCCEEDED(hr) && wined3d_declaration)
2056 *declaration = IWineD3DVertexDeclaration_GetParent(wined3d_declaration);
2057 IDirect3DVertexDeclaration9_AddRef(*declaration);
2058 IWineD3DVertexDeclaration_Release(wined3d_declaration);
2062 *declaration = NULL;
2064 wined3d_mutex_unlock();
2066 TRACE("Returning %p.\n", *declaration);
2070 static IDirect3DVertexDeclaration9 *getConvertedDecl(IDirect3DDevice9Impl *This, DWORD fvf) {
2072 D3DVERTEXELEMENT9* elements = NULL;
2073 IDirect3DVertexDeclaration9* pDecl = NULL;
2074 int p, low, high; /* deliberately signed */
2075 IDirect3DVertexDeclaration9 **convertedDecls = This->convertedDecls;
2077 TRACE("Searching for declaration for fvf %08x... ", fvf);
2080 high = This->numConvertedDecls - 1;
2081 while(low <= high) {
2082 p = (low + high) >> 1;
2084 if(((IDirect3DVertexDeclaration9Impl *) convertedDecls[p])->convFVF == fvf) {
2085 TRACE("found %p\n", convertedDecls[p]);
2086 return convertedDecls[p];
2087 } else if(((IDirect3DVertexDeclaration9Impl *) convertedDecls[p])->convFVF < fvf) {
2093 TRACE("not found. Creating and inserting at position %d.\n", low);
2095 hr = vdecl_convert_fvf(fvf, &elements);
2096 if (hr != S_OK) return NULL;
2098 hr = IDirect3DDevice9Impl_CreateVertexDeclaration((IDirect3DDevice9Ex *) This, elements, &pDecl);
2099 HeapFree(GetProcessHeap(), 0, elements); /* CreateVertexDeclaration makes a copy */
2100 if (hr != S_OK) return NULL;
2102 if(This->declArraySize == This->numConvertedDecls) {
2103 int grow = max(This->declArraySize / 2, 8);
2104 convertedDecls = HeapReAlloc(GetProcessHeap(), 0, convertedDecls,
2105 sizeof(convertedDecls[0]) * (This->numConvertedDecls + grow));
2106 if(!convertedDecls) {
2107 /* This will destroy it */
2108 IDirect3DVertexDeclaration9_Release(pDecl);
2111 This->convertedDecls = convertedDecls;
2112 This->declArraySize += grow;
2115 memmove(convertedDecls + low + 1, convertedDecls + low, sizeof(IDirect3DVertexDeclaration9Impl *) * (This->numConvertedDecls - low));
2116 convertedDecls[low] = pDecl;
2117 This->numConvertedDecls++;
2119 /* Will prevent the decl from being destroyed */
2120 ((IDirect3DVertexDeclaration9Impl *) pDecl)->convFVF = fvf;
2121 IDirect3DVertexDeclaration9_Release(pDecl); /* Does not destroy now */
2123 TRACE("Returning %p. %d decls in array\n", pDecl, This->numConvertedDecls);
2127 static HRESULT WINAPI IDirect3DDevice9Impl_SetFVF(LPDIRECT3DDEVICE9EX iface, DWORD FVF) {
2128 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2129 IDirect3DVertexDeclaration9 *decl;
2132 TRACE("iface %p, fvf %#x.\n", iface, FVF);
2136 WARN("%#x is not a valid FVF\n", FVF);
2140 wined3d_mutex_lock();
2141 decl = getConvertedDecl(This, FVF);
2142 wined3d_mutex_unlock();
2146 /* Any situation when this should happen, except out of memory? */
2147 ERR("Failed to create a converted vertex declaration\n");
2148 return D3DERR_DRIVERINTERNALERROR;
2151 hr = IDirect3DDevice9Impl_SetVertexDeclaration(iface, decl);
2152 if (FAILED(hr)) ERR("Failed to set vertex declaration\n");
2157 static HRESULT WINAPI IDirect3DDevice9Impl_GetFVF(IDirect3DDevice9Ex *iface, DWORD *pFVF)
2159 IDirect3DVertexDeclaration9 *decl;
2162 TRACE("iface %p, fvf %p.\n", iface, pFVF);
2164 hr = IDirect3DDevice9_GetVertexDeclaration(iface, &decl);
2167 WARN("Failed to get vertex declaration, %#x\n", hr);
2174 *pFVF = ((IDirect3DVertexDeclaration9Impl *)decl)->convFVF;
2175 IDirect3DVertexDeclaration9_Release(decl);
2182 TRACE("Returning FVF %#x\n", *pFVF);
2187 static HRESULT WINAPI IDirect3DDevice9Impl_CreateVertexShader(IDirect3DDevice9Ex *iface,
2188 const DWORD *byte_code, IDirect3DVertexShader9 **shader)
2190 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2191 IDirect3DVertexShader9Impl *object;
2194 TRACE("iface %p, byte_code %p, shader %p.\n", iface, byte_code, shader);
2196 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2199 ERR("Failed to allocate vertex shader memory.\n");
2200 return E_OUTOFMEMORY;
2203 hr = vertexshader_init(object, This, byte_code);
2206 WARN("Failed to initialize vertex shader, hr %#x.\n", hr);
2207 HeapFree(GetProcessHeap(), 0, object);
2211 TRACE("Created vertex shader %p.\n", object);
2212 *shader = (IDirect3DVertexShader9 *)object;
2217 static HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShader(IDirect3DDevice9Ex *iface,
2218 IDirect3DVertexShader9 *shader)
2222 TRACE("iface %p, shader %p.\n", iface, shader);
2224 wined3d_mutex_lock();
2225 hr = IWineD3DDevice_SetVertexShader(((IDirect3DDevice9Impl *)iface)->WineD3DDevice,
2226 shader ? ((IDirect3DVertexShader9Impl *)shader)->wineD3DVertexShader : NULL);
2227 wined3d_mutex_unlock();
2232 static HRESULT WINAPI IDirect3DDevice9Impl_GetVertexShader(IDirect3DDevice9Ex *iface,
2233 IDirect3DVertexShader9 **shader)
2235 IWineD3DVertexShader *wined3d_shader;
2237 TRACE("iface %p, shader %p.\n", iface, shader);
2239 wined3d_mutex_lock();
2240 wined3d_shader = IWineD3DDevice_GetVertexShader(((IDirect3DDevice9Impl *)iface)->WineD3DDevice);
2243 *shader = IWineD3DVertexShader_GetParent(wined3d_shader);
2244 IDirect3DVertexShader9_AddRef(*shader);
2245 IWineD3DVertexShader_Release(wined3d_shader);
2251 wined3d_mutex_unlock();
2253 TRACE("Returning %p.\n", *shader);
2258 static HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShaderConstantF(IDirect3DDevice9Ex *iface,
2259 UINT reg_idx, const float *data, UINT count)
2263 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface, reg_idx, data, count);
2265 if (reg_idx + count > D3D9_MAX_VERTEX_SHADER_CONSTANTF)
2267 WARN("Trying to access %u constants, but d3d9 only supports %u\n",
2268 reg_idx + count, D3D9_MAX_VERTEX_SHADER_CONSTANTF);
2269 return D3DERR_INVALIDCALL;
2272 wined3d_mutex_lock();
2273 hr = IWineD3DDevice_SetVertexShaderConstantF(((IDirect3DDevice9Impl *)iface)->WineD3DDevice, reg_idx, data, count);
2274 wined3d_mutex_unlock();
2279 static HRESULT WINAPI IDirect3DDevice9Impl_GetVertexShaderConstantF(IDirect3DDevice9Ex *iface,
2280 UINT reg_idx, float *data, UINT count)
2284 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface, reg_idx, data, count);
2286 if (reg_idx + count > D3D9_MAX_VERTEX_SHADER_CONSTANTF)
2288 WARN("Trying to access %u constants, but d3d9 only supports %u\n",
2289 reg_idx + count, D3D9_MAX_VERTEX_SHADER_CONSTANTF);
2290 return D3DERR_INVALIDCALL;
2293 wined3d_mutex_lock();
2294 hr = IWineD3DDevice_GetVertexShaderConstantF(((IDirect3DDevice9Impl *)iface)->WineD3DDevice, reg_idx, data, count);
2295 wined3d_mutex_unlock();
2300 static HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShaderConstantI(IDirect3DDevice9Ex *iface,
2301 UINT reg_idx, const int *data, UINT count)
2305 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface, reg_idx, data, count);
2307 wined3d_mutex_lock();
2308 hr = IWineD3DDevice_SetVertexShaderConstantI(((IDirect3DDevice9Impl *)iface)->WineD3DDevice, reg_idx, data, count);
2309 wined3d_mutex_unlock();
2314 static HRESULT WINAPI IDirect3DDevice9Impl_GetVertexShaderConstantI(IDirect3DDevice9Ex *iface,
2315 UINT reg_idx, int *data, UINT count)
2319 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface, reg_idx, data, count);
2321 wined3d_mutex_lock();
2322 hr = IWineD3DDevice_GetVertexShaderConstantI(((IDirect3DDevice9Impl *)iface)->WineD3DDevice, reg_idx, data, count);
2323 wined3d_mutex_unlock();
2328 static HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShaderConstantB(IDirect3DDevice9Ex *iface,
2329 UINT reg_idx, const BOOL *data, UINT count)
2333 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface, reg_idx, data, count);
2335 wined3d_mutex_lock();
2336 hr = IWineD3DDevice_SetVertexShaderConstantB(((IDirect3DDevice9Impl *)iface)->WineD3DDevice, reg_idx, data, count);
2337 wined3d_mutex_unlock();
2342 static HRESULT WINAPI IDirect3DDevice9Impl_GetVertexShaderConstantB(IDirect3DDevice9Ex *iface,
2343 UINT reg_idx, BOOL *data, UINT count)
2347 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface, reg_idx, data, count);
2349 wined3d_mutex_lock();
2350 hr = IWineD3DDevice_GetVertexShaderConstantB(((IDirect3DDevice9Impl *)iface)->WineD3DDevice, reg_idx, data, count);
2351 wined3d_mutex_unlock();
2356 static HRESULT WINAPI IDirect3DDevice9Impl_SetStreamSource(LPDIRECT3DDEVICE9EX iface, UINT StreamNumber, IDirect3DVertexBuffer9* pStreamData, UINT OffsetInBytes, UINT Stride) {
2357 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2360 TRACE("iface %p, stream_idx %u, buffer %p, offset %u, stride %u.\n",
2361 iface, StreamNumber, pStreamData, OffsetInBytes, Stride);
2363 wined3d_mutex_lock();
2364 hr = IWineD3DDevice_SetStreamSource(This->WineD3DDevice, StreamNumber,
2365 pStreamData ? ((IDirect3DVertexBuffer9Impl *)pStreamData)->wineD3DVertexBuffer : NULL,
2366 OffsetInBytes, Stride);
2367 wined3d_mutex_unlock();
2372 static HRESULT WINAPI IDirect3DDevice9Impl_GetStreamSource(IDirect3DDevice9Ex *iface,
2373 UINT StreamNumber, IDirect3DVertexBuffer9 **pStream, UINT* OffsetInBytes, UINT* pStride)
2375 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2376 IWineD3DBuffer *retStream = NULL;
2379 TRACE("iface %p, stream_idx %u, buffer %p, offset %p, stride %p.\n",
2380 iface, StreamNumber, pStream, OffsetInBytes, pStride);
2382 if(pStream == NULL){
2383 return D3DERR_INVALIDCALL;
2386 wined3d_mutex_lock();
2387 hr = IWineD3DDevice_GetStreamSource(This->WineD3DDevice, StreamNumber, &retStream, OffsetInBytes, pStride);
2388 if (SUCCEEDED(hr) && retStream)
2390 *pStream = IWineD3DBuffer_GetParent(retStream);
2391 IDirect3DVertexBuffer9_AddRef(*pStream);
2392 IWineD3DBuffer_Release(retStream);
2398 FIXME("Call to GetStreamSource failed %p %p\n", OffsetInBytes, pStride);
2402 wined3d_mutex_unlock();
2407 static HRESULT WINAPI IDirect3DDevice9Impl_SetStreamSourceFreq(IDirect3DDevice9Ex *iface, UINT StreamNumber,
2410 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2413 TRACE("iface %p, stream_idx %u, freq %u.\n", iface, StreamNumber, Divider);
2415 wined3d_mutex_lock();
2416 hr = IWineD3DDevice_SetStreamSourceFreq(This->WineD3DDevice, StreamNumber, Divider);
2417 wined3d_mutex_unlock();
2422 static HRESULT WINAPI IDirect3DDevice9Impl_GetStreamSourceFreq(LPDIRECT3DDEVICE9EX iface, UINT StreamNumber, UINT* Divider) {
2423 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2426 TRACE("iface %p, stream_idx %u, freq %p.\n", iface, StreamNumber, Divider);
2428 wined3d_mutex_lock();
2429 hr = IWineD3DDevice_GetStreamSourceFreq(This->WineD3DDevice, StreamNumber, Divider);
2430 wined3d_mutex_unlock();
2435 static HRESULT WINAPI IDirect3DDevice9Impl_SetIndices(LPDIRECT3DDEVICE9EX iface, IDirect3DIndexBuffer9* pIndexData) {
2436 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2438 IDirect3DIndexBuffer9Impl *ib = (IDirect3DIndexBuffer9Impl *) pIndexData;
2440 TRACE("iface %p, buffer %p.\n", iface, pIndexData);
2442 wined3d_mutex_lock();
2443 hr = IWineD3DDevice_SetIndexBuffer(This->WineD3DDevice,
2444 ib ? ib->wineD3DIndexBuffer : NULL,
2445 ib ? ib->format : WINED3DFMT_UNKNOWN);
2446 wined3d_mutex_unlock();
2451 static HRESULT WINAPI IDirect3DDevice9Impl_GetIndices(IDirect3DDevice9Ex *iface, IDirect3DIndexBuffer9 **ppIndexData)
2453 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2454 IWineD3DBuffer *retIndexData = NULL;
2457 TRACE("iface %p, buffer %p.\n", iface, ppIndexData);
2459 if(ppIndexData == NULL){
2460 return D3DERR_INVALIDCALL;
2463 wined3d_mutex_lock();
2464 hr = IWineD3DDevice_GetIndexBuffer(This->WineD3DDevice, &retIndexData);
2465 if (SUCCEEDED(hr) && retIndexData)
2467 *ppIndexData = IWineD3DBuffer_GetParent(retIndexData);
2468 IDirect3DIndexBuffer9_AddRef(*ppIndexData);
2469 IWineD3DBuffer_Release(retIndexData);
2473 if (FAILED(hr)) FIXME("Call to GetIndices failed\n");
2474 *ppIndexData = NULL;
2476 wined3d_mutex_unlock();
2481 static HRESULT WINAPI IDirect3DDevice9Impl_CreatePixelShader(IDirect3DDevice9Ex *iface,
2482 const DWORD *byte_code, IDirect3DPixelShader9 **shader)
2484 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2485 IDirect3DPixelShader9Impl *object;
2488 TRACE("iface %p, byte_code %p, shader %p.\n", iface, byte_code, shader);
2490 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2493 FIXME("Failed to allocate pixel shader memory.\n");
2494 return E_OUTOFMEMORY;
2497 hr = pixelshader_init(object, This, byte_code);
2500 WARN("Failed to initialize pixel shader, hr %#x.\n", hr);
2501 HeapFree(GetProcessHeap(), 0, object);
2505 TRACE("Created pixel shader %p.\n", object);
2506 *shader = (IDirect3DPixelShader9 *)object;
2511 static HRESULT WINAPI IDirect3DDevice9Impl_SetPixelShader(IDirect3DDevice9Ex *iface,
2512 IDirect3DPixelShader9 *shader)
2516 TRACE("iface %p, shader %p.\n", iface, shader);
2518 wined3d_mutex_lock();
2519 hr = IWineD3DDevice_SetPixelShader(((IDirect3DDevice9Impl *)iface)->WineD3DDevice,
2520 shader ? ((IDirect3DPixelShader9Impl *)shader)->wineD3DPixelShader : NULL);
2521 wined3d_mutex_unlock();
2526 static HRESULT WINAPI IDirect3DDevice9Impl_GetPixelShader(IDirect3DDevice9Ex *iface,
2527 IDirect3DPixelShader9 **shader)
2529 IWineD3DPixelShader *wined3d_shader;
2531 TRACE("iface %p, shader %p.\n", iface, shader);
2533 if (!shader) return D3DERR_INVALIDCALL;
2535 wined3d_mutex_lock();
2536 wined3d_shader = IWineD3DDevice_GetPixelShader(((IDirect3DDevice9Impl *)iface)->WineD3DDevice);
2539 *shader = IWineD3DPixelShader_GetParent(wined3d_shader);
2540 IDirect3DPixelShader9_AddRef(*shader);
2541 IWineD3DPixelShader_Release(wined3d_shader);
2547 wined3d_mutex_unlock();
2549 TRACE("Returning %p.\n", *shader);
2554 static HRESULT WINAPI IDirect3DDevice9Impl_SetPixelShaderConstantF(IDirect3DDevice9Ex *iface,
2555 UINT reg_idx, const float *data, UINT count)
2559 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface, reg_idx, data, count);
2561 wined3d_mutex_lock();
2562 hr = IWineD3DDevice_SetPixelShaderConstantF(((IDirect3DDevice9Impl *)iface)->WineD3DDevice, reg_idx, data, count);
2563 wined3d_mutex_unlock();
2568 static HRESULT WINAPI IDirect3DDevice9Impl_GetPixelShaderConstantF(IDirect3DDevice9Ex *iface,
2569 UINT reg_idx, float *data, UINT count)
2573 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface, reg_idx, data, count);
2575 wined3d_mutex_lock();
2576 hr = IWineD3DDevice_GetPixelShaderConstantF(((IDirect3DDevice9Impl *)iface)->WineD3DDevice, reg_idx, data, count);
2577 wined3d_mutex_unlock();
2582 static HRESULT WINAPI IDirect3DDevice9Impl_SetPixelShaderConstantI(IDirect3DDevice9Ex *iface,
2583 UINT reg_idx, const int *data, UINT count)
2587 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface, reg_idx, data, count);
2589 wined3d_mutex_lock();
2590 hr = IWineD3DDevice_SetPixelShaderConstantI(((IDirect3DDevice9Impl *)iface)->WineD3DDevice, reg_idx, data, count);
2591 wined3d_mutex_unlock();
2596 static HRESULT WINAPI IDirect3DDevice9Impl_GetPixelShaderConstantI(IDirect3DDevice9Ex *iface,
2597 UINT reg_idx, int *data, UINT count)
2601 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface, reg_idx, data, count);
2603 wined3d_mutex_lock();
2604 hr = IWineD3DDevice_GetPixelShaderConstantI(((IDirect3DDevice9Impl *)iface)->WineD3DDevice, reg_idx, data, count);
2605 wined3d_mutex_unlock();
2610 static HRESULT WINAPI IDirect3DDevice9Impl_SetPixelShaderConstantB(IDirect3DDevice9Ex *iface,
2611 UINT reg_idx, const BOOL *data, UINT count)
2615 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface, reg_idx, data, count);
2617 wined3d_mutex_lock();
2618 hr = IWineD3DDevice_SetPixelShaderConstantB(((IDirect3DDevice9Impl *)iface)->WineD3DDevice, reg_idx, data, count);
2619 wined3d_mutex_unlock();
2624 static HRESULT WINAPI IDirect3DDevice9Impl_GetPixelShaderConstantB(IDirect3DDevice9Ex *iface,
2625 UINT reg_idx, BOOL *data, UINT count)
2629 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface, reg_idx, data, count);
2631 wined3d_mutex_lock();
2632 hr = IWineD3DDevice_GetPixelShaderConstantB(((IDirect3DDevice9Impl *)iface)->WineD3DDevice, reg_idx, data, count);
2633 wined3d_mutex_unlock();
2638 static HRESULT WINAPI IDirect3DDevice9Impl_DrawRectPatch(LPDIRECT3DDEVICE9EX iface, UINT Handle, CONST float* pNumSegs, CONST D3DRECTPATCH_INFO* pRectPatchInfo) {
2639 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2642 TRACE("iface %p, handle %#x, segment_count %p, patch_info %p.\n",
2643 iface, Handle, pNumSegs, pRectPatchInfo);
2645 wined3d_mutex_lock();
2646 hr = IWineD3DDevice_DrawRectPatch(This->WineD3DDevice, Handle, pNumSegs, (CONST WINED3DRECTPATCH_INFO *)pRectPatchInfo);
2647 wined3d_mutex_unlock();
2652 static HRESULT WINAPI IDirect3DDevice9Impl_DrawTriPatch(LPDIRECT3DDEVICE9EX iface, UINT Handle, CONST float* pNumSegs, CONST D3DTRIPATCH_INFO* pTriPatchInfo) {
2653 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2656 TRACE("iface %p, handle %#x, segment_count %p, patch_info %p.\n",
2657 iface, Handle, pNumSegs, pTriPatchInfo);
2659 wined3d_mutex_lock();
2660 hr = IWineD3DDevice_DrawTriPatch(This->WineD3DDevice, Handle, pNumSegs, (CONST WINED3DTRIPATCH_INFO *)pTriPatchInfo);
2661 wined3d_mutex_unlock();
2666 static HRESULT WINAPI IDirect3DDevice9Impl_DeletePatch(LPDIRECT3DDEVICE9EX iface, UINT Handle) {
2667 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2670 TRACE("iface %p, handle %#x.\n", iface, Handle);
2672 wined3d_mutex_lock();
2673 hr = IWineD3DDevice_DeletePatch(This->WineD3DDevice, Handle);
2674 wined3d_mutex_unlock();
2679 static HRESULT WINAPI IDirect3DDevice9Impl_CreateQuery(IDirect3DDevice9Ex *iface,
2680 D3DQUERYTYPE type, IDirect3DQuery9 **query)
2682 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2683 IDirect3DQuery9Impl *object;
2686 TRACE("iface %p, type %#x, query %p.\n", iface, type, query);
2688 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2691 ERR("Failed to allocate query memory.\n");
2692 return E_OUTOFMEMORY;
2695 hr = query_init(object, This, type);
2698 WARN("Failed to initialize query, hr %#x.\n", hr);
2699 HeapFree(GetProcessHeap(), 0, object);
2703 TRACE("Created query %p.\n", object);
2704 if (query) *query = (IDirect3DQuery9 *)object;
2705 else IDirect3DQuery9_Release((IDirect3DQuery9 *)object);
2710 static HRESULT WINAPI IDirect3DDevice9ExImpl_SetConvolutionMonoKernel(IDirect3DDevice9Ex *iface,
2711 UINT width, UINT height, float *rows, float *columns)
2713 FIXME("iface %p, width %u, height %u, rows %p, columns %p stub!\n",
2714 iface, width, height, rows, columns);
2716 return WINED3DERR_INVALIDCALL;
2719 static HRESULT WINAPI IDirect3DDevice9ExImpl_ComposeRects(IDirect3DDevice9Ex *iface,
2720 IDirect3DSurface9 *src_surface, IDirect3DSurface9 *dst_surface, IDirect3DVertexBuffer9 *src_descs,
2721 UINT rect_count, IDirect3DVertexBuffer9 *dst_descs, D3DCOMPOSERECTSOP operation, INT offset_x, INT offset_y)
2723 FIXME("iface %p, src_surface %p, dst_surface %p, src_descs %p, rect_count %u,\n"
2724 "dst_descs %p, operation %#x, offset_x %u, offset_y %u stub!\n",
2725 iface, src_surface, dst_surface, src_descs, rect_count,
2726 dst_descs, operation, offset_x, offset_y);
2728 return WINED3DERR_INVALIDCALL;
2731 static HRESULT WINAPI IDirect3DDevice9ExImpl_PresentEx(IDirect3DDevice9Ex *iface,
2732 const RECT *src_rect, const RECT *dst_rect, HWND dst_window_override,
2733 const RGNDATA *dirty_region, DWORD flags)
2735 FIXME("iface %p, src_rect %p, dst_rect %p, dst_window_override %p, dirty_region %p, flags %#x stub!\n",
2736 iface, src_rect, dst_rect, dst_window_override, dirty_region, flags);
2738 return WINED3DERR_INVALIDCALL;
2741 static HRESULT WINAPI IDirect3DDevice9ExImpl_GetGPUThreadPriority(IDirect3DDevice9Ex *iface, INT *priority)
2743 FIXME("iface %p, priority %p stub!\n", iface, priority);
2745 return WINED3DERR_INVALIDCALL;
2748 static HRESULT WINAPI IDirect3DDevice9ExImpl_SetGPUThreadPriority(IDirect3DDevice9Ex *iface, INT priority)
2750 FIXME("iface %p, priority %d stub!\n", iface, priority);
2752 return WINED3DERR_INVALIDCALL;
2755 static HRESULT WINAPI IDirect3DDevice9ExImpl_WaitForVBlank(IDirect3DDevice9Ex *iface, UINT swapchain_idx)
2757 FIXME("iface %p, swapchain_idx %u stub!\n", iface, swapchain_idx);
2759 return WINED3DERR_INVALIDCALL;
2762 static HRESULT WINAPI IDirect3DDevice9ExImpl_CheckResourceResidency(IDirect3DDevice9Ex *iface,
2763 IDirect3DResource9 **resources, UINT32 resource_count)
2765 FIXME("iface %p, resources %p, resource_count %u stub!\n",
2766 iface, resources, resource_count);
2768 return WINED3DERR_INVALIDCALL;
2771 static HRESULT WINAPI IDirect3DDevice9ExImpl_SetMaximumFrameLatency(IDirect3DDevice9Ex *iface, UINT max_latency)
2773 FIXME("iface %p, max_latency %u stub!\n", iface, max_latency);
2775 return WINED3DERR_INVALIDCALL;
2778 static HRESULT WINAPI IDirect3DDevice9ExImpl_GetMaximumFrameLatency(IDirect3DDevice9Ex *iface, UINT *max_latency)
2780 FIXME("iface %p, max_latency %p stub!\n", iface, max_latency);
2784 return WINED3DERR_INVALIDCALL;
2787 static HRESULT WINAPI IDirect3DDevice9ExImpl_CheckDeviceState(IDirect3DDevice9Ex *iface, HWND dst_window)
2789 FIXME("iface %p, dst_window %p stub!\n", iface, dst_window);
2791 return WINED3DERR_INVALIDCALL;
2794 static HRESULT WINAPI IDirect3DDevice9ExImpl_CreateRenderTargetEx(IDirect3DDevice9Ex *iface,
2795 UINT width, UINT height, D3DFORMAT format, D3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality,
2796 BOOL lockable, IDirect3DSurface9 **surface, HANDLE *shared_handle, DWORD usage)
2798 FIXME("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u,\n"
2799 "lockable %#x, surface %p, shared_handle %p, usage %#x stub!\n",
2800 iface, width, height, format, multisample_type, multisample_quality,
2801 lockable, surface, shared_handle, usage);
2803 return WINED3DERR_INVALIDCALL;
2806 static HRESULT WINAPI IDirect3DDevice9ExImpl_CreateOffscreenPlainSurfaceEx(IDirect3DDevice9Ex *iface,
2807 UINT width, UINT height, D3DFORMAT format, D3DPOOL pool, IDirect3DSurface9 **surface,
2808 HANDLE *shared_handle, DWORD usage)
2810 FIXME("iface %p, width %u, height %u, format %#x, pool %#x, surface %p, shared_handle %p, usage %#x stub!\n",
2811 iface, width, height, format, pool, surface, shared_handle, usage);
2813 return WINED3DERR_INVALIDCALL;
2816 static HRESULT WINAPI IDirect3DDevice9ExImpl_CreateDepthStencilSurfaceEx(IDirect3DDevice9Ex *iface,
2817 UINT width, UINT height, D3DFORMAT format, D3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality,
2818 BOOL discard, IDirect3DSurface9 **surface, HANDLE *shared_handle, DWORD usage)
2820 FIXME("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u,\n"
2821 "discard %#x, surface %p, shared_handle %p, usage %#x stub!\n",
2822 iface, width, height, format, multisample_type, multisample_quality,
2823 discard, surface, shared_handle, usage);
2825 return WINED3DERR_INVALIDCALL;
2828 static HRESULT WINAPI IDirect3DDevice9ExImpl_ResetEx(IDirect3DDevice9Ex *iface,
2829 D3DPRESENT_PARAMETERS *present_parameters, D3DDISPLAYMODEEX *mode)
2831 FIXME("iface %p, present_parameters %p, mode %p stub!\n", iface, present_parameters, mode);
2833 return WINED3DERR_INVALIDCALL;
2836 static HRESULT WINAPI IDirect3DDevice9ExImpl_GetDisplayModeEx(IDirect3DDevice9Ex *iface,
2837 UINT swapchain_idx, D3DDISPLAYMODEEX *mode, D3DDISPLAYROTATION *rotation)
2839 FIXME("iface %p, swapchain_idx %u, mode %p, rotation %p stub!\n", iface, swapchain_idx, mode, rotation);
2841 return WINED3DERR_INVALIDCALL;
2844 static const IDirect3DDevice9ExVtbl Direct3DDevice9_Vtbl =
2847 IDirect3DDevice9Impl_QueryInterface,
2848 IDirect3DDevice9Impl_AddRef,
2849 IDirect3DDevice9Impl_Release,
2850 /* IDirect3DDevice9 */
2851 IDirect3DDevice9Impl_TestCooperativeLevel,
2852 IDirect3DDevice9Impl_GetAvailableTextureMem,
2853 IDirect3DDevice9Impl_EvictManagedResources,
2854 IDirect3DDevice9Impl_GetDirect3D,
2855 IDirect3DDevice9Impl_GetDeviceCaps,
2856 IDirect3DDevice9Impl_GetDisplayMode,
2857 IDirect3DDevice9Impl_GetCreationParameters,
2858 IDirect3DDevice9Impl_SetCursorProperties,
2859 IDirect3DDevice9Impl_SetCursorPosition,
2860 IDirect3DDevice9Impl_ShowCursor,
2861 IDirect3DDevice9Impl_CreateAdditionalSwapChain,
2862 IDirect3DDevice9Impl_GetSwapChain,
2863 IDirect3DDevice9Impl_GetNumberOfSwapChains,
2864 IDirect3DDevice9Impl_Reset,
2865 IDirect3DDevice9Impl_Present,
2866 IDirect3DDevice9Impl_GetBackBuffer,
2867 IDirect3DDevice9Impl_GetRasterStatus,
2868 IDirect3DDevice9Impl_SetDialogBoxMode,
2869 IDirect3DDevice9Impl_SetGammaRamp,
2870 IDirect3DDevice9Impl_GetGammaRamp,
2871 IDirect3DDevice9Impl_CreateTexture,
2872 IDirect3DDevice9Impl_CreateVolumeTexture,
2873 IDirect3DDevice9Impl_CreateCubeTexture,
2874 IDirect3DDevice9Impl_CreateVertexBuffer,
2875 IDirect3DDevice9Impl_CreateIndexBuffer,
2876 IDirect3DDevice9Impl_CreateRenderTarget,
2877 IDirect3DDevice9Impl_CreateDepthStencilSurface,
2878 IDirect3DDevice9Impl_UpdateSurface,
2879 IDirect3DDevice9Impl_UpdateTexture,
2880 IDirect3DDevice9Impl_GetRenderTargetData,
2881 IDirect3DDevice9Impl_GetFrontBufferData,
2882 IDirect3DDevice9Impl_StretchRect,
2883 IDirect3DDevice9Impl_ColorFill,
2884 IDirect3DDevice9Impl_CreateOffscreenPlainSurface,
2885 IDirect3DDevice9Impl_SetRenderTarget,
2886 IDirect3DDevice9Impl_GetRenderTarget,
2887 IDirect3DDevice9Impl_SetDepthStencilSurface,
2888 IDirect3DDevice9Impl_GetDepthStencilSurface,
2889 IDirect3DDevice9Impl_BeginScene,
2890 IDirect3DDevice9Impl_EndScene,
2891 IDirect3DDevice9Impl_Clear,
2892 IDirect3DDevice9Impl_SetTransform,
2893 IDirect3DDevice9Impl_GetTransform,
2894 IDirect3DDevice9Impl_MultiplyTransform,
2895 IDirect3DDevice9Impl_SetViewport,
2896 IDirect3DDevice9Impl_GetViewport,
2897 IDirect3DDevice9Impl_SetMaterial,
2898 IDirect3DDevice9Impl_GetMaterial,
2899 IDirect3DDevice9Impl_SetLight,
2900 IDirect3DDevice9Impl_GetLight,
2901 IDirect3DDevice9Impl_LightEnable,
2902 IDirect3DDevice9Impl_GetLightEnable,
2903 IDirect3DDevice9Impl_SetClipPlane,
2904 IDirect3DDevice9Impl_GetClipPlane,
2905 IDirect3DDevice9Impl_SetRenderState,
2906 IDirect3DDevice9Impl_GetRenderState,
2907 IDirect3DDevice9Impl_CreateStateBlock,
2908 IDirect3DDevice9Impl_BeginStateBlock,
2909 IDirect3DDevice9Impl_EndStateBlock,
2910 IDirect3DDevice9Impl_SetClipStatus,
2911 IDirect3DDevice9Impl_GetClipStatus,
2912 IDirect3DDevice9Impl_GetTexture,
2913 IDirect3DDevice9Impl_SetTexture,
2914 IDirect3DDevice9Impl_GetTextureStageState,
2915 IDirect3DDevice9Impl_SetTextureStageState,
2916 IDirect3DDevice9Impl_GetSamplerState,
2917 IDirect3DDevice9Impl_SetSamplerState,
2918 IDirect3DDevice9Impl_ValidateDevice,
2919 IDirect3DDevice9Impl_SetPaletteEntries,
2920 IDirect3DDevice9Impl_GetPaletteEntries,
2921 IDirect3DDevice9Impl_SetCurrentTexturePalette,
2922 IDirect3DDevice9Impl_GetCurrentTexturePalette,
2923 IDirect3DDevice9Impl_SetScissorRect,
2924 IDirect3DDevice9Impl_GetScissorRect,
2925 IDirect3DDevice9Impl_SetSoftwareVertexProcessing,
2926 IDirect3DDevice9Impl_GetSoftwareVertexProcessing,
2927 IDirect3DDevice9Impl_SetNPatchMode,
2928 IDirect3DDevice9Impl_GetNPatchMode,
2929 IDirect3DDevice9Impl_DrawPrimitive,
2930 IDirect3DDevice9Impl_DrawIndexedPrimitive,
2931 IDirect3DDevice9Impl_DrawPrimitiveUP,
2932 IDirect3DDevice9Impl_DrawIndexedPrimitiveUP,
2933 IDirect3DDevice9Impl_ProcessVertices,
2934 IDirect3DDevice9Impl_CreateVertexDeclaration,
2935 IDirect3DDevice9Impl_SetVertexDeclaration,
2936 IDirect3DDevice9Impl_GetVertexDeclaration,
2937 IDirect3DDevice9Impl_SetFVF,
2938 IDirect3DDevice9Impl_GetFVF,
2939 IDirect3DDevice9Impl_CreateVertexShader,
2940 IDirect3DDevice9Impl_SetVertexShader,
2941 IDirect3DDevice9Impl_GetVertexShader,
2942 IDirect3DDevice9Impl_SetVertexShaderConstantF,
2943 IDirect3DDevice9Impl_GetVertexShaderConstantF,
2944 IDirect3DDevice9Impl_SetVertexShaderConstantI,
2945 IDirect3DDevice9Impl_GetVertexShaderConstantI,
2946 IDirect3DDevice9Impl_SetVertexShaderConstantB,
2947 IDirect3DDevice9Impl_GetVertexShaderConstantB,
2948 IDirect3DDevice9Impl_SetStreamSource,
2949 IDirect3DDevice9Impl_GetStreamSource,
2950 IDirect3DDevice9Impl_SetStreamSourceFreq,
2951 IDirect3DDevice9Impl_GetStreamSourceFreq,
2952 IDirect3DDevice9Impl_SetIndices,
2953 IDirect3DDevice9Impl_GetIndices,
2954 IDirect3DDevice9Impl_CreatePixelShader,
2955 IDirect3DDevice9Impl_SetPixelShader,
2956 IDirect3DDevice9Impl_GetPixelShader,
2957 IDirect3DDevice9Impl_SetPixelShaderConstantF,
2958 IDirect3DDevice9Impl_GetPixelShaderConstantF,
2959 IDirect3DDevice9Impl_SetPixelShaderConstantI,
2960 IDirect3DDevice9Impl_GetPixelShaderConstantI,
2961 IDirect3DDevice9Impl_SetPixelShaderConstantB,
2962 IDirect3DDevice9Impl_GetPixelShaderConstantB,
2963 IDirect3DDevice9Impl_DrawRectPatch,
2964 IDirect3DDevice9Impl_DrawTriPatch,
2965 IDirect3DDevice9Impl_DeletePatch,
2966 IDirect3DDevice9Impl_CreateQuery,
2967 /* IDirect3DDevice9Ex */
2968 IDirect3DDevice9ExImpl_SetConvolutionMonoKernel,
2969 IDirect3DDevice9ExImpl_ComposeRects,
2970 IDirect3DDevice9ExImpl_PresentEx,
2971 IDirect3DDevice9ExImpl_GetGPUThreadPriority,
2972 IDirect3DDevice9ExImpl_SetGPUThreadPriority,
2973 IDirect3DDevice9ExImpl_WaitForVBlank,
2974 IDirect3DDevice9ExImpl_CheckResourceResidency,
2975 IDirect3DDevice9ExImpl_SetMaximumFrameLatency,
2976 IDirect3DDevice9ExImpl_GetMaximumFrameLatency,
2977 IDirect3DDevice9ExImpl_CheckDeviceState,
2978 IDirect3DDevice9ExImpl_CreateRenderTargetEx,
2979 IDirect3DDevice9ExImpl_CreateOffscreenPlainSurfaceEx,
2980 IDirect3DDevice9ExImpl_CreateDepthStencilSurfaceEx,
2981 IDirect3DDevice9ExImpl_ResetEx,
2982 IDirect3DDevice9ExImpl_GetDisplayModeEx
2985 /* IWineD3DDeviceParent IUnknown methods */
2987 static inline struct IDirect3DDevice9Impl *device_from_device_parent(IWineD3DDeviceParent *iface)
2989 return (struct IDirect3DDevice9Impl *)((char*)iface
2990 - FIELD_OFFSET(struct IDirect3DDevice9Impl, device_parent_vtbl));
2993 static HRESULT STDMETHODCALLTYPE device_parent_QueryInterface(IWineD3DDeviceParent *iface, REFIID riid, void **object)
2995 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
2996 return IDirect3DDevice9Impl_QueryInterface((IDirect3DDevice9Ex *)This, riid, object);
2999 static ULONG STDMETHODCALLTYPE device_parent_AddRef(IWineD3DDeviceParent *iface)
3001 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
3002 return IDirect3DDevice9Impl_AddRef((IDirect3DDevice9Ex *)This);
3005 static ULONG STDMETHODCALLTYPE device_parent_Release(IWineD3DDeviceParent *iface)
3007 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
3008 return IDirect3DDevice9Impl_Release((IDirect3DDevice9Ex *)This);
3011 /* IWineD3DDeviceParent methods */
3013 static void STDMETHODCALLTYPE device_parent_WineD3DDeviceCreated(IWineD3DDeviceParent *iface, IWineD3DDevice *device)
3015 TRACE("iface %p, device %p\n", iface, device);
3018 static HRESULT STDMETHODCALLTYPE device_parent_CreateSurface(IWineD3DDeviceParent *iface,
3019 IUnknown *superior, UINT width, UINT height, enum wined3d_format_id format, DWORD usage,
3020 WINED3DPOOL pool, UINT level, WINED3DCUBEMAP_FACES face, IWineD3DSurface **surface)
3022 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
3023 IDirect3DSurface9Impl *d3d_surface;
3024 BOOL lockable = TRUE;
3027 TRACE("iface %p, superior %p, width %u, height %u, format %#x, usage %#x,\n"
3028 "\tpool %#x, level %u, face %u, surface %p\n",
3029 iface, superior, width, height, format, usage, pool, level, face, surface);
3031 if (pool == WINED3DPOOL_DEFAULT && !(usage & D3DUSAGE_DYNAMIC))
3034 hr = IDirect3DDevice9Impl_CreateSurface((IDirect3DDevice9Ex *)This, width, height,
3035 d3dformat_from_wined3dformat(format), lockable, FALSE /* Discard */, level,
3036 (IDirect3DSurface9 **)&d3d_surface, usage, pool, D3DMULTISAMPLE_NONE, 0 /* MultisampleQuality */);
3039 ERR("(%p) CreateSurface failed, returning %#x\n", iface, hr);
3043 *surface = d3d_surface->wineD3DSurface;
3044 IWineD3DSurface_AddRef(*surface);
3046 d3d_surface->container = superior;
3047 IDirect3DDevice9Ex_Release(d3d_surface->parentDevice);
3048 d3d_surface->parentDevice = NULL;
3050 IDirect3DSurface9_Release((IDirect3DSurface9 *)d3d_surface);
3051 d3d_surface->forwardReference = superior;
3056 static HRESULT STDMETHODCALLTYPE device_parent_CreateRenderTarget(IWineD3DDeviceParent *iface,
3057 IUnknown *superior, UINT width, UINT height, enum wined3d_format_id format,
3058 WINED3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality, BOOL lockable,
3059 IWineD3DSurface **surface)
3061 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
3062 IDirect3DSurface9Impl *d3d_surface;
3065 TRACE("iface %p, superior %p, width %u, height %u, format %#x, multisample_type %#x,\n"
3066 "\tmultisample_quality %u, lockable %u, surface %p\n",
3067 iface, superior, width, height, format, multisample_type, multisample_quality, lockable, surface);
3069 hr = IDirect3DDevice9Impl_CreateRenderTarget((IDirect3DDevice9Ex *)This, width, height,
3070 d3dformat_from_wined3dformat(format), multisample_type, multisample_quality, lockable,
3071 (IDirect3DSurface9 **)&d3d_surface, NULL);
3074 ERR("(%p) CreateRenderTarget failed, returning %#x\n", iface, hr);
3078 *surface = d3d_surface->wineD3DSurface;
3079 IWineD3DSurface_AddRef(*surface);
3081 d3d_surface->container = superior;
3082 /* Implicit surfaces are created with an refcount of 0 */
3083 IDirect3DSurface9_Release((IDirect3DSurface9 *)d3d_surface);
3088 static HRESULT STDMETHODCALLTYPE device_parent_CreateDepthStencilSurface(IWineD3DDeviceParent *iface,
3089 UINT width, UINT height, enum wined3d_format_id format, WINED3DMULTISAMPLE_TYPE multisample_type,
3090 DWORD multisample_quality, BOOL discard, IWineD3DSurface **surface)
3092 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
3093 IDirect3DSurface9Impl *d3d_surface;
3096 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x,\n"
3097 "\tmultisample_quality %u, discard %u, surface %p\n",
3098 iface, width, height, format, multisample_type, multisample_quality, discard, surface);
3100 hr = IDirect3DDevice9Impl_CreateDepthStencilSurface((IDirect3DDevice9Ex *)This, width, height,
3101 d3dformat_from_wined3dformat(format), multisample_type, multisample_quality, discard,
3102 (IDirect3DSurface9 **)&d3d_surface, NULL);
3105 ERR("(%p) CreateDepthStencilSurface failed, returning %#x\n", iface, hr);
3109 *surface = d3d_surface->wineD3DSurface;
3110 IWineD3DSurface_AddRef(*surface);
3111 d3d_surface->container = (IUnknown *)This;
3112 /* Implicit surfaces are created with an refcount of 0 */
3113 IDirect3DSurface9_Release((IDirect3DSurface9 *)d3d_surface);
3118 static HRESULT STDMETHODCALLTYPE device_parent_CreateVolume(IWineD3DDeviceParent *iface,
3119 IUnknown *superior, UINT width, UINT height, UINT depth, enum wined3d_format_id format,
3120 WINED3DPOOL pool, DWORD usage, IWineD3DVolume **volume)
3122 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
3123 IDirect3DVolume9Impl *object;
3126 TRACE("iface %p, superior %p, width %u, height %u, depth %u, format %#x, pool %#x, usage %#x, volume %p\n",
3127 iface, superior, width, height, depth, format, pool, usage, volume);
3129 /* Allocate the storage for the device */
3130 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
3133 FIXME("Allocation of memory failed\n");
3135 return D3DERR_OUTOFVIDEOMEMORY;
3138 hr = volume_init(object, This, width, height, depth, usage, format, pool);
3141 WARN("Failed to initialize volume, hr %#x.\n", hr);
3142 HeapFree(GetProcessHeap(), 0, object);
3146 *volume = object->wineD3DVolume;
3147 IWineD3DVolume_AddRef(*volume);
3148 IDirect3DVolume9_Release((IDirect3DVolume9 *)object);
3150 object->container = superior;
3151 object->forwardReference = superior;
3153 TRACE("(%p) Created volume %p\n", iface, object);
3158 static HRESULT STDMETHODCALLTYPE device_parent_CreateSwapChain(IWineD3DDeviceParent *iface,
3159 WINED3DPRESENT_PARAMETERS *present_parameters, IWineD3DSwapChain **swapchain)
3161 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
3162 IDirect3DSwapChain9Impl *d3d_swapchain;
3163 D3DPRESENT_PARAMETERS local_parameters;
3166 TRACE("iface %p, present_parameters %p, swapchain %p\n", iface, present_parameters, swapchain);
3168 /* Copy the presentation parameters */
3169 local_parameters.BackBufferWidth = present_parameters->BackBufferWidth;
3170 local_parameters.BackBufferHeight = present_parameters->BackBufferHeight;
3171 local_parameters.BackBufferFormat = d3dformat_from_wined3dformat(present_parameters->BackBufferFormat);
3172 local_parameters.BackBufferCount = present_parameters->BackBufferCount;
3173 local_parameters.MultiSampleType = present_parameters->MultiSampleType;
3174 local_parameters.MultiSampleQuality = present_parameters->MultiSampleQuality;
3175 local_parameters.SwapEffect = present_parameters->SwapEffect;
3176 local_parameters.hDeviceWindow = present_parameters->hDeviceWindow;
3177 local_parameters.Windowed = present_parameters->Windowed;
3178 local_parameters.EnableAutoDepthStencil = present_parameters->EnableAutoDepthStencil;
3179 local_parameters.AutoDepthStencilFormat = d3dformat_from_wined3dformat(present_parameters->AutoDepthStencilFormat);
3180 local_parameters.Flags = present_parameters->Flags;
3181 local_parameters.FullScreen_RefreshRateInHz = present_parameters->FullScreen_RefreshRateInHz;
3182 local_parameters.PresentationInterval = present_parameters->PresentationInterval;
3184 hr = IDirect3DDevice9Impl_CreateAdditionalSwapChain((IDirect3DDevice9Ex *)This,
3185 &local_parameters, (IDirect3DSwapChain9 **)&d3d_swapchain);
3188 ERR("(%p) CreateAdditionalSwapChain failed, returning %#x\n", iface, hr);
3193 *swapchain = d3d_swapchain->wineD3DSwapChain;
3194 d3d_swapchain->isImplicit = TRUE;
3195 /* Implicit swap chains are created with an refcount of 0 */
3196 IDirect3DSwapChain9_Release((IDirect3DSwapChain9 *)d3d_swapchain);
3198 /* Copy back the presentation parameters */
3199 present_parameters->BackBufferWidth = local_parameters.BackBufferWidth;
3200 present_parameters->BackBufferHeight = local_parameters.BackBufferHeight;
3201 present_parameters->BackBufferFormat = wined3dformat_from_d3dformat(local_parameters.BackBufferFormat);
3202 present_parameters->BackBufferCount = local_parameters.BackBufferCount;
3203 present_parameters->MultiSampleType = local_parameters.MultiSampleType;
3204 present_parameters->MultiSampleQuality = local_parameters.MultiSampleQuality;
3205 present_parameters->SwapEffect = local_parameters.SwapEffect;
3206 present_parameters->hDeviceWindow = local_parameters.hDeviceWindow;
3207 present_parameters->Windowed = local_parameters.Windowed;
3208 present_parameters->EnableAutoDepthStencil = local_parameters.EnableAutoDepthStencil;
3209 present_parameters->AutoDepthStencilFormat = wined3dformat_from_d3dformat(local_parameters.AutoDepthStencilFormat);
3210 present_parameters->Flags = local_parameters.Flags;
3211 present_parameters->FullScreen_RefreshRateInHz = local_parameters.FullScreen_RefreshRateInHz;
3212 present_parameters->PresentationInterval = local_parameters.PresentationInterval;
3217 static const IWineD3DDeviceParentVtbl d3d9_wined3d_device_parent_vtbl =
3219 /* IUnknown methods */
3220 device_parent_QueryInterface,
3221 device_parent_AddRef,
3222 device_parent_Release,
3223 /* IWineD3DDeviceParent methods */
3224 device_parent_WineD3DDeviceCreated,
3225 device_parent_CreateSurface,
3226 device_parent_CreateRenderTarget,
3227 device_parent_CreateDepthStencilSurface,
3228 device_parent_CreateVolume,
3229 device_parent_CreateSwapChain,
3232 static void setup_fpu(void)
3234 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
3236 __asm__ volatile ("fnstcw %0" : "=m" (cw));
3237 cw = (cw & ~0xf3f) | 0x3f;
3238 __asm__ volatile ("fldcw %0" : : "m" (cw));
3240 FIXME("FPU setup not implemented for this platform.\n");
3244 HRESULT device_init(IDirect3DDevice9Impl *device, IWineD3D *wined3d, UINT adapter, D3DDEVTYPE device_type,
3245 HWND focus_window, DWORD flags, D3DPRESENT_PARAMETERS *parameters)
3247 WINED3DPRESENT_PARAMETERS *wined3d_parameters;
3251 device->lpVtbl = &Direct3DDevice9_Vtbl;
3252 device->device_parent_vtbl = &d3d9_wined3d_device_parent_vtbl;
3255 if (!(flags & D3DCREATE_FPU_PRESERVE)) setup_fpu();
3257 wined3d_mutex_lock();
3258 hr = IWineD3D_CreateDevice(wined3d, adapter, device_type, focus_window, flags,
3259 (IWineD3DDeviceParent *)&device->device_parent_vtbl, &device->WineD3DDevice);
3262 WARN("Failed to create wined3d device, hr %#x.\n", hr);
3263 wined3d_mutex_unlock();
3267 if (!parameters->Windowed)
3269 if (!focus_window) focus_window = parameters->hDeviceWindow;
3270 if (FAILED(hr = IWineD3DDevice_AcquireFocusWindow(device->WineD3DDevice, focus_window)))
3272 ERR("Failed to acquire focus window, hr %#x.\n", hr);
3273 IWineD3DDevice_Release(device->WineD3DDevice);
3274 wined3d_mutex_unlock();
3279 if (flags & D3DCREATE_ADAPTERGROUP_DEVICE)
3283 IWineD3D_GetDeviceCaps(wined3d, adapter, device_type, &caps);
3284 count = caps.NumberOfAdaptersInGroup;
3287 if (flags & D3DCREATE_MULTITHREADED) IWineD3DDevice_SetMultithreaded(device->WineD3DDevice);
3289 wined3d_parameters = HeapAlloc(GetProcessHeap(), 0, sizeof(*wined3d_parameters) * count);
3290 if (!wined3d_parameters)
3292 ERR("Failed to allocate wined3d parameters.\n");
3293 IWineD3DDevice_Release(device->WineD3DDevice);
3294 wined3d_mutex_unlock();
3295 return E_OUTOFMEMORY;
3298 for (i = 0; i < count; ++i)
3300 wined3d_parameters[i].BackBufferWidth = parameters[i].BackBufferWidth;
3301 wined3d_parameters[i].BackBufferHeight = parameters[i].BackBufferHeight;
3302 wined3d_parameters[i].BackBufferFormat = wined3dformat_from_d3dformat(parameters[i].BackBufferFormat);
3303 wined3d_parameters[i].BackBufferCount = parameters[i].BackBufferCount;
3304 wined3d_parameters[i].MultiSampleType = parameters[i].MultiSampleType;
3305 wined3d_parameters[i].MultiSampleQuality = parameters[i].MultiSampleQuality;
3306 wined3d_parameters[i].SwapEffect = parameters[i].SwapEffect;
3307 wined3d_parameters[i].hDeviceWindow = parameters[i].hDeviceWindow;
3308 wined3d_parameters[i].Windowed = parameters[i].Windowed;
3309 wined3d_parameters[i].EnableAutoDepthStencil = parameters[i].EnableAutoDepthStencil;
3310 wined3d_parameters[i].AutoDepthStencilFormat =
3311 wined3dformat_from_d3dformat(parameters[i].AutoDepthStencilFormat);
3312 wined3d_parameters[i].Flags = parameters[i].Flags;
3313 wined3d_parameters[i].FullScreen_RefreshRateInHz = parameters[i].FullScreen_RefreshRateInHz;
3314 wined3d_parameters[i].PresentationInterval = parameters[i].PresentationInterval;
3315 wined3d_parameters[i].AutoRestoreDisplayMode = TRUE;
3318 hr = IWineD3DDevice_Init3D(device->WineD3DDevice, wined3d_parameters);
3321 WARN("Failed to initialize 3D, hr %#x.\n", hr);
3322 IWineD3DDevice_ReleaseFocusWindow(device->WineD3DDevice);
3323 HeapFree(GetProcessHeap(), 0, wined3d_parameters);
3324 IWineD3DDevice_Release(device->WineD3DDevice);
3325 wined3d_mutex_unlock();
3329 wined3d_mutex_unlock();
3331 for (i = 0; i < count; ++i)
3333 parameters[i].BackBufferWidth = wined3d_parameters[i].BackBufferWidth;
3334 parameters[i].BackBufferHeight = wined3d_parameters[i].BackBufferHeight;
3335 parameters[i].BackBufferFormat = d3dformat_from_wined3dformat(wined3d_parameters[i].BackBufferFormat);
3336 parameters[i].BackBufferCount = wined3d_parameters[i].BackBufferCount;
3337 parameters[i].MultiSampleType = wined3d_parameters[i].MultiSampleType;
3338 parameters[i].MultiSampleQuality = wined3d_parameters[i].MultiSampleQuality;
3339 parameters[i].SwapEffect = wined3d_parameters[i].SwapEffect;
3340 parameters[i].hDeviceWindow = wined3d_parameters[i].hDeviceWindow;
3341 parameters[i].Windowed = wined3d_parameters[i].Windowed;
3342 parameters[i].EnableAutoDepthStencil = wined3d_parameters[i].EnableAutoDepthStencil;
3343 parameters[i].AutoDepthStencilFormat =
3344 d3dformat_from_wined3dformat(wined3d_parameters[i].AutoDepthStencilFormat);
3345 parameters[i].Flags = wined3d_parameters[i].Flags;
3346 parameters[i].FullScreen_RefreshRateInHz = wined3d_parameters[i].FullScreen_RefreshRateInHz;
3347 parameters[i].PresentationInterval = wined3d_parameters[i].PresentationInterval;
3349 HeapFree(GetProcessHeap(), 0, wined3d_parameters);
3351 /* Initialize the converted declaration array. This creates a valid pointer
3352 * and when adding decls HeapReAlloc() can be used without further checking. */
3353 device->convertedDecls = HeapAlloc(GetProcessHeap(), 0, 0);
3354 if (!device->convertedDecls)
3356 ERR("Failed to allocate FVF vertex declaration map memory.\n");
3357 wined3d_mutex_lock();
3358 IWineD3DDevice_Uninit3D(device->WineD3DDevice, D3D9CB_DestroySwapChain);
3359 IWineD3DDevice_ReleaseFocusWindow(device->WineD3DDevice);
3360 IWineD3DDevice_Release(device->WineD3DDevice);
3361 wined3d_mutex_unlock();
3362 return E_OUTOFMEMORY;