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 /* IDirect3D IUnknown parts follow: */
185 static HRESULT WINAPI IDirect3DDevice9Impl_QueryInterface(LPDIRECT3DDEVICE9EX iface, REFIID riid, LPVOID* ppobj) {
186 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
188 IDirect3D9Impl *d3dimpl;
190 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
192 if (IsEqualGUID(riid, &IID_IUnknown)
193 || IsEqualGUID(riid, &IID_IDirect3DDevice9)) {
194 IDirect3DDevice9Ex_AddRef(iface);
196 TRACE("Returning IDirect3DDevice9 interface at %p\n", *ppobj);
198 } else if(IsEqualGUID(riid, &IID_IDirect3DDevice9Ex)) {
199 /* Find out if the creating d3d9 interface was created with Direct3DCreate9Ex.
200 * It doesn't matter with which function the device was created.
202 IDirect3DDevice9_GetDirect3D(iface, &d3d);
203 d3dimpl = (IDirect3D9Impl *) d3d;
205 if(d3dimpl->extended) {
207 IDirect3DDevice9Ex_AddRef((IDirect3DDevice9Ex *) *ppobj);
208 IDirect3D9_Release(d3d);
209 TRACE("Returning IDirect3DDevice9Ex interface at %p\n", *ppobj);
212 WARN("IDirect3D9 instance wasn't created with CreateDirect3D9Ex, returning E_NOINTERFACE\n");
213 IDirect3D9_Release(d3d);
215 return E_NOINTERFACE;
219 if (IsEqualGUID(riid, &IID_IWineD3DDeviceParent))
221 IUnknown_AddRef((IUnknown *)&This->device_parent_vtbl);
222 *ppobj = &This->device_parent_vtbl;
226 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
228 return E_NOINTERFACE;
231 static ULONG WINAPI IDirect3DDevice9Impl_AddRef(LPDIRECT3DDEVICE9EX iface) {
232 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
233 ULONG ref = InterlockedIncrement(&This->ref);
235 TRACE("%p increasing refcount to %u.\n", iface, ref);
240 static ULONG WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_Release(LPDIRECT3DDEVICE9EX iface) {
241 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
244 if (This->inDestruction) return 0;
245 ref = InterlockedDecrement(&This->ref);
247 TRACE("%p decreasing refcount to %u.\n", iface, ref);
251 This->inDestruction = TRUE;
253 wined3d_mutex_lock();
254 for(i = 0; i < This->numConvertedDecls; i++) {
255 /* Unless Wine is buggy or the app has a bug the refcount will be 0, because decls hold a reference to the
258 IDirect3DVertexDeclaration9Impl_Destroy(This->convertedDecls[i]);
260 HeapFree(GetProcessHeap(), 0, This->convertedDecls);
262 IWineD3DDevice_Uninit3D(This->WineD3DDevice);
263 IWineD3DDevice_ReleaseFocusWindow(This->WineD3DDevice);
264 IWineD3DDevice_Release(This->WineD3DDevice);
265 wined3d_mutex_unlock();
267 HeapFree(GetProcessHeap(), 0, This);
272 /* IDirect3DDevice Interface follow: */
273 static HRESULT WINAPI IDirect3DDevice9Impl_TestCooperativeLevel(IDirect3DDevice9Ex *iface)
275 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
277 TRACE("iface %p.\n", iface);
281 TRACE("D3D9 device is marked not reset.\n");
282 return D3DERR_DEVICENOTRESET;
288 static UINT WINAPI IDirect3DDevice9Impl_GetAvailableTextureMem(LPDIRECT3DDEVICE9EX iface) {
289 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
292 TRACE("iface %p.\n", iface);
294 wined3d_mutex_lock();
295 hr = IWineD3DDevice_GetAvailableTextureMem(This->WineD3DDevice);
296 wined3d_mutex_unlock();
301 static HRESULT WINAPI IDirect3DDevice9Impl_EvictManagedResources(LPDIRECT3DDEVICE9EX iface) {
302 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
305 TRACE("iface %p.\n", iface);
307 wined3d_mutex_lock();
308 hr = IWineD3DDevice_EvictManagedResources(This->WineD3DDevice);
309 wined3d_mutex_unlock();
314 static HRESULT WINAPI IDirect3DDevice9Impl_GetDirect3D(IDirect3DDevice9Ex *iface, IDirect3D9 **ppD3D9)
316 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
317 struct wined3d *wined3d;
320 TRACE("iface %p, d3d9 %p.\n", iface, ppD3D9);
322 if (NULL == ppD3D9) {
323 return D3DERR_INVALIDCALL;
326 wined3d_mutex_lock();
327 hr = IWineD3DDevice_GetDirect3D(This->WineD3DDevice, &wined3d);
328 if (hr == D3D_OK && wined3d)
330 *ppD3D9 = wined3d_get_parent(wined3d);
331 IDirect3D9_AddRef(*ppD3D9);
332 wined3d_decref(wined3d);
336 FIXME("Call to IWineD3DDevice_GetDirect3D failed\n");
339 TRACE("(%p) returning %p\n", This, *ppD3D9);
340 wined3d_mutex_unlock();
345 static HRESULT WINAPI IDirect3DDevice9Impl_GetDeviceCaps(LPDIRECT3DDEVICE9EX iface, D3DCAPS9* pCaps) {
346 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
347 HRESULT hrc = D3D_OK;
348 WINED3DCAPS *pWineCaps;
350 TRACE("iface %p, caps %p.\n", iface, pCaps);
353 return D3DERR_INVALIDCALL;
355 pWineCaps = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WINED3DCAPS));
356 if(pWineCaps == NULL){
357 return D3DERR_INVALIDCALL; /* well this is what MSDN says to return */
360 memset(pCaps, 0, sizeof(*pCaps));
362 wined3d_mutex_lock();
363 hrc = IWineD3DDevice_GetDeviceCaps(This->WineD3DDevice, pWineCaps);
364 wined3d_mutex_unlock();
366 WINECAPSTOD3D9CAPS(pCaps, pWineCaps)
367 HeapFree(GetProcessHeap(), 0, pWineCaps);
369 /* Some functionality is implemented in d3d9.dll, not wined3d.dll. Add the needed caps */
370 pCaps->DevCaps2 |= D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES;
374 TRACE("Returning %p %p\n", This, pCaps);
378 static HRESULT WINAPI IDirect3DDevice9Impl_GetDisplayMode(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain, D3DDISPLAYMODE* pMode) {
379 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
382 TRACE("iface %p, swapchain %u, mode %p.\n", iface, iSwapChain, pMode);
384 wined3d_mutex_lock();
385 hr = IWineD3DDevice_GetDisplayMode(This->WineD3DDevice, iSwapChain, (WINED3DDISPLAYMODE *) pMode);
386 wined3d_mutex_unlock();
388 if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format);
393 static HRESULT WINAPI IDirect3DDevice9Impl_GetCreationParameters(LPDIRECT3DDEVICE9EX iface, D3DDEVICE_CREATION_PARAMETERS *pParameters) {
394 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
397 TRACE("iface %p, parameters %p.\n", iface, pParameters);
399 wined3d_mutex_lock();
400 hr = IWineD3DDevice_GetCreationParameters(This->WineD3DDevice, (WINED3DDEVICE_CREATION_PARAMETERS *) pParameters);
401 wined3d_mutex_unlock();
406 static HRESULT WINAPI IDirect3DDevice9Impl_SetCursorProperties(LPDIRECT3DDEVICE9EX iface, UINT XHotSpot, UINT YHotSpot, IDirect3DSurface9* pCursorBitmap) {
407 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
408 IDirect3DSurface9Impl *pSurface = (IDirect3DSurface9Impl*)pCursorBitmap;
411 TRACE("iface %p, hotspot_x %u, hotspot_y %u, bitmap %p.\n",
412 iface, XHotSpot, YHotSpot, pCursorBitmap);
416 WARN("No cursor bitmap, returning D3DERR_INVALIDCALL.\n");
417 return D3DERR_INVALIDCALL;
420 wined3d_mutex_lock();
421 hr = IWineD3DDevice_SetCursorProperties(This->WineD3DDevice, XHotSpot, YHotSpot, pSurface->wineD3DSurface);
422 wined3d_mutex_unlock();
427 static void WINAPI IDirect3DDevice9Impl_SetCursorPosition(LPDIRECT3DDEVICE9EX iface, int XScreenSpace, int YScreenSpace, DWORD Flags) {
428 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
430 TRACE("iface %p, x %u, y %u, flags %#x.\n", iface, XScreenSpace, YScreenSpace, Flags);
432 wined3d_mutex_lock();
433 IWineD3DDevice_SetCursorPosition(This->WineD3DDevice, XScreenSpace, YScreenSpace, Flags);
434 wined3d_mutex_unlock();
437 static BOOL WINAPI IDirect3DDevice9Impl_ShowCursor(LPDIRECT3DDEVICE9EX iface, BOOL bShow) {
438 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
441 TRACE("iface %p, show %#x.\n", iface, bShow);
443 wined3d_mutex_lock();
444 ret = IWineD3DDevice_ShowCursor(This->WineD3DDevice, bShow);
445 wined3d_mutex_unlock();
450 static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_CreateAdditionalSwapChain(IDirect3DDevice9Ex *iface,
451 D3DPRESENT_PARAMETERS *present_parameters, IDirect3DSwapChain9 **swapchain)
453 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
454 IDirect3DSwapChain9Impl *object;
457 TRACE("iface %p, present_parameters %p, swapchain %p.\n",
458 iface, present_parameters, swapchain);
460 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
463 ERR("Failed to allocate swapchain memory.\n");
464 return E_OUTOFMEMORY;
467 hr = swapchain_init(object, This, present_parameters);
470 WARN("Failed to initialize swapchain, hr %#x.\n", hr);
471 HeapFree(GetProcessHeap(), 0, object);
475 TRACE("Created swapchain %p.\n", object);
476 *swapchain = (IDirect3DSwapChain9 *)object;
481 static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_GetSwapChain(IDirect3DDevice9Ex *iface,
482 UINT swapchain_idx, IDirect3DSwapChain9 **swapchain)
484 struct wined3d_swapchain *wined3d_swapchain = NULL;
487 TRACE("iface %p, swapchain_idx %u, swapchain %p.\n", iface, swapchain_idx, swapchain);
489 wined3d_mutex_lock();
490 hr = IWineD3DDevice_GetSwapChain(((IDirect3DDevice9Impl *)iface)->WineD3DDevice,
491 swapchain_idx, &wined3d_swapchain);
492 if (SUCCEEDED(hr) && wined3d_swapchain)
494 *swapchain = wined3d_swapchain_get_parent(wined3d_swapchain);
495 IDirect3DSwapChain9_AddRef(*swapchain);
496 wined3d_swapchain_decref(wined3d_swapchain);
502 wined3d_mutex_unlock();
507 static UINT WINAPI IDirect3DDevice9Impl_GetNumberOfSwapChains(IDirect3DDevice9Ex *iface)
511 TRACE("iface %p.\n", iface);
513 wined3d_mutex_lock();
514 count = IWineD3DDevice_GetNumberOfSwapChains(((IDirect3DDevice9Impl *)iface)->WineD3DDevice);
515 wined3d_mutex_unlock();
520 static HRESULT WINAPI reset_enum_callback(struct wined3d_resource *resource, void *data)
522 BOOL *resources_ok = data;
523 D3DRESOURCETYPE type;
525 D3DSURFACE_DESC surface_desc;
526 D3DVOLUME_DESC volume_desc;
527 D3DINDEXBUFFER_DESC index_desc;
528 D3DVERTEXBUFFER_DESC vertex_desc;
530 IDirect3DResource9 *parent;
532 parent = wined3d_resource_get_parent(resource);
533 type = IDirect3DResource9_GetType(parent);
535 case D3DRTYPE_SURFACE:
536 IDirect3DSurface9_GetDesc((IDirect3DSurface9 *)parent, &surface_desc);
537 pool = surface_desc.Pool;
540 case D3DRTYPE_VOLUME:
541 IDirect3DVolume9_GetDesc((IDirect3DVolume9 *)parent, &volume_desc);
542 pool = volume_desc.Pool;
545 case D3DRTYPE_INDEXBUFFER:
546 IDirect3DIndexBuffer9_GetDesc((IDirect3DIndexBuffer9 *) parent, &index_desc);
547 pool = index_desc.Pool;
550 case D3DRTYPE_VERTEXBUFFER:
551 IDirect3DVertexBuffer9_GetDesc((IDirect3DVertexBuffer9 *)parent, &vertex_desc);
552 pool = vertex_desc.Pool;
555 /* No need to check for textures. If there is a D3DPOOL_DEFAULT texture, there
556 * is a D3DPOOL_DEFAULT surface or volume as well
559 pool = WINED3DPOOL_SCRATCH; /* a harmless pool */
563 if (pool == WINED3DPOOL_DEFAULT)
565 IDirect3DResource9_AddRef(parent);
566 if (IUnknown_Release(parent) == 0)
568 TRACE("Parent %p is an implicit resource with ref 0\n", parent);
570 WARN("Resource %p(wineD3D %p) with pool D3DPOOL_DEFAULT blocks the Reset call\n", parent, resource);
572 *resources_ok = FALSE;
579 static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_Reset(LPDIRECT3DDEVICE9EX iface, D3DPRESENT_PARAMETERS* pPresentationParameters) {
580 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
581 WINED3DPRESENT_PARAMETERS localParameters;
583 BOOL resources_ok = TRUE;
586 TRACE("iface %p, present_parameters %p.\n", iface, pPresentationParameters);
588 /* Reset states that hold a COM object. WineD3D holds an internal reference to set objects, because
589 * such objects can still be used for rendering after their external d3d9 object has been destroyed.
590 * These objects must not be enumerated. Unsetting them tells WineD3D that the application will not
591 * make use of the hidden reference and destroys the objects.
593 * Unsetting them is no problem, because the states are supposed to be reset anyway. If the validation
594 * below fails, the device is considered "lost", and _Reset and _Release are the only allowed calls
596 wined3d_mutex_lock();
597 IWineD3DDevice_SetIndexBuffer(This->WineD3DDevice, NULL, WINED3DFMT_UNKNOWN);
598 for(i = 0; i < 16; i++) {
599 IWineD3DDevice_SetStreamSource(This->WineD3DDevice, i, NULL, 0, 0);
601 for(i = 0; i < 16; i++) {
602 IWineD3DDevice_SetTexture(This->WineD3DDevice, i, NULL);
605 IWineD3DDevice_EnumResources(This->WineD3DDevice, reset_enum_callback, &resources_ok);
607 WARN("The application is holding D3DPOOL_DEFAULT resources, rejecting reset\n");
608 This->notreset = TRUE;
609 wined3d_mutex_unlock();
611 return D3DERR_INVALIDCALL;
614 localParameters.BackBufferWidth = pPresentationParameters->BackBufferWidth;
615 localParameters.BackBufferHeight = pPresentationParameters->BackBufferHeight;
616 localParameters.BackBufferFormat = wined3dformat_from_d3dformat(pPresentationParameters->BackBufferFormat);
617 localParameters.BackBufferCount = pPresentationParameters->BackBufferCount;
618 localParameters.MultiSampleType = pPresentationParameters->MultiSampleType;
619 localParameters.MultiSampleQuality = pPresentationParameters->MultiSampleQuality;
620 localParameters.SwapEffect = pPresentationParameters->SwapEffect;
621 localParameters.hDeviceWindow = pPresentationParameters->hDeviceWindow;
622 localParameters.Windowed = pPresentationParameters->Windowed;
623 localParameters.EnableAutoDepthStencil = pPresentationParameters->EnableAutoDepthStencil;
624 localParameters.AutoDepthStencilFormat = wined3dformat_from_d3dformat(pPresentationParameters->AutoDepthStencilFormat);
625 localParameters.Flags = pPresentationParameters->Flags;
626 localParameters.FullScreen_RefreshRateInHz = pPresentationParameters->FullScreen_RefreshRateInHz;
627 localParameters.PresentationInterval = pPresentationParameters->PresentationInterval;
628 localParameters.AutoRestoreDisplayMode = TRUE;
630 hr = IWineD3DDevice_Reset(This->WineD3DDevice, &localParameters);
632 This->notreset = TRUE;
634 pPresentationParameters->BackBufferWidth = localParameters.BackBufferWidth;
635 pPresentationParameters->BackBufferHeight = localParameters.BackBufferHeight;
636 pPresentationParameters->BackBufferFormat = d3dformat_from_wined3dformat(localParameters.BackBufferFormat);
637 pPresentationParameters->BackBufferCount = localParameters.BackBufferCount;
638 pPresentationParameters->MultiSampleType = localParameters.MultiSampleType;
639 pPresentationParameters->MultiSampleQuality = localParameters.MultiSampleQuality;
640 pPresentationParameters->SwapEffect = localParameters.SwapEffect;
641 pPresentationParameters->hDeviceWindow = localParameters.hDeviceWindow;
642 pPresentationParameters->Windowed = localParameters.Windowed;
643 pPresentationParameters->EnableAutoDepthStencil = localParameters.EnableAutoDepthStencil;
644 pPresentationParameters->AutoDepthStencilFormat = d3dformat_from_wined3dformat(localParameters.AutoDepthStencilFormat);
645 pPresentationParameters->Flags = localParameters.Flags;
646 pPresentationParameters->FullScreen_RefreshRateInHz = localParameters.FullScreen_RefreshRateInHz;
647 pPresentationParameters->PresentationInterval = localParameters.PresentationInterval;
649 This->notreset = FALSE;
652 wined3d_mutex_unlock();
657 static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_Present(LPDIRECT3DDEVICE9EX iface, CONST RECT* pSourceRect,CONST RECT* pDestRect,HWND hDestWindowOverride,CONST RGNDATA*
659 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
662 TRACE("iface %p, src_rect %p, dst_rect %p, dst_window_override %p, dirty_region %p.\n",
663 iface, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
665 wined3d_mutex_lock();
666 hr = IWineD3DDevice_Present(This->WineD3DDevice, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
667 wined3d_mutex_unlock();
672 static HRESULT WINAPI IDirect3DDevice9Impl_GetBackBuffer(IDirect3DDevice9Ex *iface,
673 UINT iSwapChain, UINT BackBuffer, D3DBACKBUFFER_TYPE Type, IDirect3DSurface9 **ppBackBuffer)
675 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
676 IWineD3DSurface *retSurface = NULL;
679 TRACE("iface %p, swapchain %u, backbuffer_idx %u, backbuffer_type %#x, backbuffer %p.\n",
680 iface, iSwapChain, BackBuffer, Type, ppBackBuffer);
682 wined3d_mutex_lock();
683 hr = IWineD3DDevice_GetBackBuffer(This->WineD3DDevice, iSwapChain,
684 BackBuffer, (WINED3DBACKBUFFER_TYPE) Type, &retSurface);
685 if (SUCCEEDED(hr) && retSurface && ppBackBuffer)
687 *ppBackBuffer = IWineD3DSurface_GetParent(retSurface);
688 IDirect3DSurface9_AddRef(*ppBackBuffer);
689 IWineD3DSurface_Release(retSurface);
691 wined3d_mutex_unlock();
695 static HRESULT WINAPI IDirect3DDevice9Impl_GetRasterStatus(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain, D3DRASTER_STATUS* pRasterStatus) {
696 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
699 TRACE("iface %p, swapchain %u, raster_status %p.\n", iface, iSwapChain, pRasterStatus);
701 wined3d_mutex_lock();
702 hr = IWineD3DDevice_GetRasterStatus(This->WineD3DDevice, iSwapChain, (WINED3DRASTER_STATUS *) pRasterStatus);
703 wined3d_mutex_unlock();
708 static HRESULT WINAPI IDirect3DDevice9Impl_SetDialogBoxMode(LPDIRECT3DDEVICE9EX iface, BOOL bEnableDialogs) {
709 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
712 TRACE("iface %p, enable %#x.\n", iface, bEnableDialogs);
714 wined3d_mutex_lock();
715 hr = IWineD3DDevice_SetDialogBoxMode(This->WineD3DDevice, bEnableDialogs);
716 wined3d_mutex_unlock();
721 static void WINAPI IDirect3DDevice9Impl_SetGammaRamp(IDirect3DDevice9Ex *iface, UINT iSwapChain,
722 DWORD Flags, const D3DGAMMARAMP *pRamp)
724 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
726 TRACE("iface %p, swapchain %u, flags %#x, ramp %p.\n", iface, iSwapChain, Flags, pRamp);
728 /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
729 wined3d_mutex_lock();
730 IWineD3DDevice_SetGammaRamp(This->WineD3DDevice, iSwapChain, Flags, (CONST WINED3DGAMMARAMP *)pRamp);
731 wined3d_mutex_unlock();
734 static void WINAPI IDirect3DDevice9Impl_GetGammaRamp(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain, D3DGAMMARAMP* pRamp) {
735 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
737 TRACE("iface %p, swapchain %u, ramp %p.\n", iface, iSwapChain, pRamp);
739 /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
740 wined3d_mutex_lock();
741 IWineD3DDevice_GetGammaRamp(This->WineD3DDevice, iSwapChain, (WINED3DGAMMARAMP *) pRamp);
742 wined3d_mutex_unlock();
745 static HRESULT WINAPI IDirect3DDevice9Impl_CreateTexture(IDirect3DDevice9Ex *iface,
746 UINT width, UINT height, UINT levels, DWORD usage, D3DFORMAT format,
747 D3DPOOL pool, IDirect3DTexture9 **texture, HANDLE *shared_handle)
749 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
750 IDirect3DTexture9Impl *object;
753 TRACE("iface %p, width %u, height %u, levels %u, usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n",
754 iface, width, height, levels, usage, format, pool, texture, shared_handle);
756 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
759 ERR("Failed to allocate texture memory.\n");
760 return D3DERR_OUTOFVIDEOMEMORY;
763 hr = texture_init(object, This, width, height, levels, usage, format, pool);
766 WARN("Failed to initialize texture, hr %#x.\n", hr);
767 HeapFree(GetProcessHeap(), 0, object);
771 TRACE("Created texture %p.\n", object);
772 *texture = &object->IDirect3DTexture9_iface;
777 static HRESULT WINAPI IDirect3DDevice9Impl_CreateVolumeTexture(IDirect3DDevice9Ex *iface,
778 UINT width, UINT height, UINT depth, UINT levels, DWORD usage, D3DFORMAT format,
779 D3DPOOL pool, IDirect3DVolumeTexture9 **texture, HANDLE *shared_handle)
781 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
782 IDirect3DVolumeTexture9Impl *object;
785 TRACE("iface %p, width %u, height %u, depth %u, levels %u\n",
786 iface, width, height, depth, levels);
787 TRACE("usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n",
788 usage, format, pool, texture, shared_handle);
790 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
793 ERR("Failed to allocate volume texture memory.\n");
794 return D3DERR_OUTOFVIDEOMEMORY;
797 hr = volumetexture_init(object, This, width, height, depth, levels, usage, format, pool);
800 WARN("Failed to initialize volume texture, hr %#x.\n", hr);
801 HeapFree(GetProcessHeap(), 0, object);
805 TRACE("Created volume texture %p.\n", object);
806 *texture = (IDirect3DVolumeTexture9 *)object;
811 static HRESULT WINAPI IDirect3DDevice9Impl_CreateCubeTexture(IDirect3DDevice9Ex *iface,
812 UINT edge_length, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool,
813 IDirect3DCubeTexture9 **texture, HANDLE *shared_handle)
815 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
816 IDirect3DCubeTexture9Impl *object;
819 TRACE("iface %p, edge_length %u, levels %u, usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n",
820 iface, edge_length, levels, usage, format, pool, texture, shared_handle);
822 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
825 ERR("Failed to allocate cube texture memory.\n");
826 return D3DERR_OUTOFVIDEOMEMORY;
829 hr = cubetexture_init(object, This, edge_length, levels, usage, format, pool);
832 WARN("Failed to initialize cube texture, hr %#x.\n", hr);
833 HeapFree(GetProcessHeap(), 0, object);
837 TRACE("Created cube texture %p.\n", object);
838 *texture = &object->IDirect3DCubeTexture9_iface;
843 static HRESULT WINAPI IDirect3DDevice9Impl_CreateVertexBuffer(IDirect3DDevice9Ex *iface, UINT size, DWORD usage,
844 DWORD fvf, D3DPOOL pool, IDirect3DVertexBuffer9 **buffer, HANDLE *shared_handle)
846 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
847 IDirect3DVertexBuffer9Impl *object;
850 TRACE("iface %p, size %u, usage %#x, fvf %#x, pool %#x, buffer %p, shared_handle %p.\n",
851 iface, size, usage, fvf, pool, buffer, shared_handle);
853 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
856 ERR("Failed to allocate buffer memory.\n");
857 return D3DERR_OUTOFVIDEOMEMORY;
860 hr = vertexbuffer_init(object, This, size, usage, fvf, pool);
863 WARN("Failed to initialize vertex buffer, hr %#x.\n", hr);
864 HeapFree(GetProcessHeap(), 0, object);
868 TRACE("Created vertex buffer %p.\n", object);
869 *buffer = (IDirect3DVertexBuffer9 *)object;
874 static HRESULT WINAPI IDirect3DDevice9Impl_CreateIndexBuffer(IDirect3DDevice9Ex *iface, UINT size, DWORD usage,
875 D3DFORMAT format, D3DPOOL pool, IDirect3DIndexBuffer9 **buffer, HANDLE *shared_handle)
877 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
878 IDirect3DIndexBuffer9Impl *object;
881 TRACE("iface %p, size %u, usage %#x, format %#x, pool %#x, buffer %p, shared_handle %p.\n",
882 iface, size, usage, format, pool, buffer, shared_handle);
884 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
887 ERR("Failed to allocate buffer memory.\n");
888 return D3DERR_OUTOFVIDEOMEMORY;
891 hr = indexbuffer_init(object, This, size, usage, format, pool);
894 WARN("Failed to initialize index buffer, hr %#x.\n", hr);
895 HeapFree(GetProcessHeap(), 0, object);
899 TRACE("Created index buffer %p.\n", object);
900 *buffer = (IDirect3DIndexBuffer9 *)object;
905 static HRESULT IDirect3DDevice9Impl_CreateSurface(LPDIRECT3DDEVICE9EX iface, UINT Width, UINT Height,
906 D3DFORMAT Format, BOOL Lockable, BOOL Discard, UINT Level, IDirect3DSurface9 **ppSurface,
907 UINT Usage, D3DPOOL Pool, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality)
909 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
910 IDirect3DSurface9Impl *object;
913 TRACE("iface %p, width %u, height %u, format %#x, lockable %#x, discard %#x, level %u, surface %p.\n"
914 "usage %#x, pool %#x, multisample_type %#x, multisample_quality %u.\n",
915 iface, Width, Height, Format, Lockable, Discard, Level, ppSurface,
916 Usage, Pool, MultiSample, MultisampleQuality);
918 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DSurface9Impl));
921 FIXME("Failed to allocate surface memory.\n");
922 return D3DERR_OUTOFVIDEOMEMORY;
925 hr = surface_init(object, This, Width, Height, Format, Lockable, Discard,
926 Level, Usage, Pool, MultiSample, MultisampleQuality);
929 WARN("Failed to initialize surface, hr %#x.\n", hr);
930 HeapFree(GetProcessHeap(), 0, object);
934 TRACE("Created surface %p.\n", object);
935 *ppSurface = (IDirect3DSurface9 *)object;
940 static HRESULT WINAPI IDirect3DDevice9Impl_CreateRenderTarget(IDirect3DDevice9Ex *iface, UINT Width, UINT Height,
941 D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality, BOOL Lockable,
942 IDirect3DSurface9 **ppSurface, HANDLE *pSharedHandle)
946 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u.\n"
947 "lockable %#x, surface %p, shared_handle %p.\n",
948 iface, Width, Height, Format, MultiSample, MultisampleQuality,
949 Lockable, ppSurface, pSharedHandle);
951 hr = IDirect3DDevice9Impl_CreateSurface(iface, Width, Height, Format, Lockable, FALSE /* Discard */,
952 0 /* Level */, ppSurface, D3DUSAGE_RENDERTARGET, D3DPOOL_DEFAULT, MultiSample, MultisampleQuality);
957 static HRESULT WINAPI IDirect3DDevice9Impl_CreateDepthStencilSurface(LPDIRECT3DDEVICE9EX iface, UINT Width, UINT Height,
958 D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample,
959 DWORD MultisampleQuality, BOOL Discard,
960 IDirect3DSurface9 **ppSurface, HANDLE* pSharedHandle) {
963 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u.\n"
964 "discard %#x, surface %p, shared_handle %p.\n",
965 iface, Width, Height, Format, MultiSample, MultisampleQuality,
966 Discard, ppSurface, pSharedHandle);
968 hr = IDirect3DDevice9Impl_CreateSurface(iface, Width, Height, Format, TRUE /* Lockable */, Discard,
969 0 /* Level */, ppSurface, D3DUSAGE_DEPTHSTENCIL, D3DPOOL_DEFAULT, MultiSample, MultisampleQuality);
975 static HRESULT WINAPI IDirect3DDevice9Impl_UpdateSurface(LPDIRECT3DDEVICE9EX iface, IDirect3DSurface9* pSourceSurface, CONST RECT* pSourceRect, IDirect3DSurface9* pDestinationSurface, CONST POINT* pDestPoint) {
976 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
979 TRACE("iface %p, src_surface %p, src_rect %p, dst_surface %p, dst_point %p.\n",
980 iface, pSourceSurface, pSourceRect, pDestinationSurface, pDestPoint);
982 wined3d_mutex_lock();
983 hr = IWineD3DDevice_UpdateSurface(This->WineD3DDevice, ((IDirect3DSurface9Impl *)pSourceSurface)->wineD3DSurface, pSourceRect, ((IDirect3DSurface9Impl *)pDestinationSurface)->wineD3DSurface, pDestPoint);
984 wined3d_mutex_unlock();
989 static HRESULT WINAPI IDirect3DDevice9Impl_UpdateTexture(IDirect3DDevice9Ex *iface,
990 IDirect3DBaseTexture9 *src_texture, IDirect3DBaseTexture9 *dst_texture)
992 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
995 TRACE("iface %p, src_texture %p, dst_texture %p.\n", iface, src_texture, dst_texture);
997 wined3d_mutex_lock();
998 hr = IWineD3DDevice_UpdateTexture(This->WineD3DDevice,
999 ((IDirect3DBaseTexture9Impl *)src_texture)->wined3d_texture,
1000 ((IDirect3DBaseTexture9Impl *)dst_texture)->wined3d_texture);
1001 wined3d_mutex_unlock();
1006 static HRESULT WINAPI IDirect3DDevice9Impl_GetRenderTargetData(IDirect3DDevice9Ex *iface,
1007 IDirect3DSurface9 *pRenderTarget, IDirect3DSurface9 *pDestSurface)
1009 IDirect3DSurface9Impl *renderTarget = (IDirect3DSurface9Impl *)pRenderTarget;
1010 IDirect3DSurface9Impl *destSurface = (IDirect3DSurface9Impl *)pDestSurface;
1013 TRACE("iface %p, render_target %p, dst_surface %p.\n", iface, pRenderTarget, pDestSurface);
1015 wined3d_mutex_lock();
1016 hr = IWineD3DSurface_BltFast(destSurface->wineD3DSurface, 0, 0, renderTarget->wineD3DSurface, NULL, WINEDDBLTFAST_NOCOLORKEY);
1017 wined3d_mutex_unlock();
1022 static HRESULT WINAPI IDirect3DDevice9Impl_GetFrontBufferData(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain, IDirect3DSurface9* pDestSurface) {
1023 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1024 IDirect3DSurface9Impl *destSurface = (IDirect3DSurface9Impl *)pDestSurface;
1027 TRACE("iface %p, swapchain %u, dst_surface %p.\n", iface, iSwapChain, pDestSurface);
1029 wined3d_mutex_lock();
1030 hr = IWineD3DDevice_GetFrontBufferData(This->WineD3DDevice, iSwapChain, destSurface->wineD3DSurface);
1031 wined3d_mutex_unlock();
1036 static HRESULT WINAPI IDirect3DDevice9Impl_StretchRect(IDirect3DDevice9Ex *iface, IDirect3DSurface9 *pSourceSurface,
1037 const RECT *pSourceRect, IDirect3DSurface9 *pDestSurface, const RECT *pDestRect, D3DTEXTUREFILTERTYPE Filter)
1039 IDirect3DSurface9Impl *src = (IDirect3DSurface9Impl *) pSourceSurface;
1040 IDirect3DSurface9Impl *dst = (IDirect3DSurface9Impl *) pDestSurface;
1043 TRACE("iface %p, src_surface %p, src_rect %p, dst_surface %p, dst_rect %p, filter %#x.\n",
1044 iface, pSourceSurface, pSourceRect, pDestSurface, pDestRect, Filter);
1046 wined3d_mutex_lock();
1047 hr = IWineD3DSurface_Blt(dst->wineD3DSurface, pDestRect, src->wineD3DSurface, pSourceRect, 0, NULL, Filter);
1048 wined3d_mutex_unlock();
1053 static HRESULT WINAPI IDirect3DDevice9Impl_ColorFill(IDirect3DDevice9Ex *iface,
1054 IDirect3DSurface9 *pSurface, const RECT *pRect, D3DCOLOR color)
1056 const WINED3DCOLORVALUE c =
1058 ((color >> 16) & 0xff) / 255.0f,
1059 ((color >> 8) & 0xff) / 255.0f,
1060 (color & 0xff) / 255.0f,
1061 ((color >> 24) & 0xff) / 255.0f,
1063 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1064 IDirect3DSurface9Impl *surface = (IDirect3DSurface9Impl *)pSurface;
1065 struct wined3d_resource *wined3d_resource;
1066 struct wined3d_resource_desc desc;
1069 TRACE("iface %p, surface %p, rect %p, color 0x%08x.\n", iface, pSurface, pRect, color);
1071 wined3d_mutex_lock();
1073 wined3d_resource = IWineD3DSurface_GetResource(surface->wineD3DSurface);
1074 wined3d_resource_get_desc(wined3d_resource, &desc);
1076 /* This method is only allowed with surfaces that are render targets, or
1077 * offscreen plain surfaces in D3DPOOL_DEFAULT. */
1078 if (!(desc.usage & WINED3DUSAGE_RENDERTARGET) && desc.pool != WINED3DPOOL_DEFAULT)
1080 wined3d_mutex_unlock();
1081 WARN("Surface is not a render target, or not a stand-alone D3DPOOL_DEFAULT surface\n");
1082 return D3DERR_INVALIDCALL;
1085 /* Colorfill can only be used on rendertarget surfaces, or offscreen plain surfaces in D3DPOOL_DEFAULT */
1086 hr = IWineD3DDevice_ColorFill(This->WineD3DDevice, surface->wineD3DSurface, pRect, &c);
1088 wined3d_mutex_unlock();
1093 static HRESULT WINAPI IDirect3DDevice9Impl_CreateOffscreenPlainSurface(LPDIRECT3DDEVICE9EX iface, UINT Width, UINT Height, D3DFORMAT Format, D3DPOOL Pool, IDirect3DSurface9 **ppSurface, HANDLE* pSharedHandle) {
1096 TRACE("iface %p, width %u, height %u, format %#x, pool %#x, surface %p, shared_handle %p.\n",
1097 iface, Width, Height, Format, Pool, ppSurface, pSharedHandle);
1099 if(Pool == D3DPOOL_MANAGED ){
1100 FIXME("Attempting to create a managed offscreen plain surface\n");
1101 return D3DERR_INVALIDCALL;
1104 'Off-screen plain surfaces are always lockable, regardless of their pool types.'
1106 D3DPOOL_DEFAULT is the appropriate pool for use with the IDirect3DDevice9::StretchRect and IDirect3DDevice9::ColorFill.
1107 Why, their always lockable?
1108 should I change the usage to dynamic?
1110 hr = IDirect3DDevice9Impl_CreateSurface(iface, Width, Height, Format, TRUE /* Lockable */, FALSE /* Discard */,
1111 0 /* Level */, ppSurface, 0 /* Usage (undefined/none) */, (WINED3DPOOL)Pool, D3DMULTISAMPLE_NONE,
1112 0 /* MultisampleQuality */);
1117 /* TODO: move to wineD3D */
1118 static HRESULT WINAPI IDirect3DDevice9Impl_SetRenderTarget(LPDIRECT3DDEVICE9EX iface, DWORD RenderTargetIndex, IDirect3DSurface9* pRenderTarget) {
1119 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1120 IDirect3DSurface9Impl *pSurface = (IDirect3DSurface9Impl*)pRenderTarget;
1123 TRACE("iface %p, idx %u, surface %p.\n", iface, RenderTargetIndex, pRenderTarget);
1125 if (RenderTargetIndex >= D3D9_MAX_SIMULTANEOUS_RENDERTARGETS)
1127 WARN("Invalid index %u specified.\n", RenderTargetIndex);
1128 return D3DERR_INVALIDCALL;
1131 wined3d_mutex_lock();
1132 hr = IWineD3DDevice_SetRenderTarget(This->WineD3DDevice, RenderTargetIndex, pSurface ? pSurface->wineD3DSurface : NULL, TRUE);
1133 wined3d_mutex_unlock();
1138 static HRESULT WINAPI IDirect3DDevice9Impl_GetRenderTarget(IDirect3DDevice9Ex *iface,
1139 DWORD RenderTargetIndex, IDirect3DSurface9 **ppRenderTarget)
1141 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1142 IWineD3DSurface *pRenderTarget;
1145 TRACE("iface %p, idx %u, surface %p.\n", iface, RenderTargetIndex, ppRenderTarget);
1147 if (ppRenderTarget == NULL) {
1148 return D3DERR_INVALIDCALL;
1151 if (RenderTargetIndex >= D3D9_MAX_SIMULTANEOUS_RENDERTARGETS)
1153 WARN("Invalid index %u specified.\n", RenderTargetIndex);
1154 return D3DERR_INVALIDCALL;
1157 wined3d_mutex_lock();
1159 hr=IWineD3DDevice_GetRenderTarget(This->WineD3DDevice,RenderTargetIndex,&pRenderTarget);
1163 FIXME("Call to IWineD3DDevice_GetRenderTarget failed, hr %#x\n", hr);
1165 else if (!pRenderTarget)
1167 *ppRenderTarget = NULL;
1171 *ppRenderTarget = IWineD3DSurface_GetParent(pRenderTarget);
1172 IDirect3DSurface9_AddRef(*ppRenderTarget);
1173 IWineD3DSurface_Release(pRenderTarget);
1176 wined3d_mutex_unlock();
1181 static HRESULT WINAPI IDirect3DDevice9Impl_SetDepthStencilSurface(LPDIRECT3DDEVICE9EX iface, IDirect3DSurface9* pZStencilSurface) {
1182 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1183 IDirect3DSurface9Impl *pSurface;
1186 TRACE("iface %p, depth_stencil %p.\n", iface, pZStencilSurface);
1188 pSurface = (IDirect3DSurface9Impl*)pZStencilSurface;
1190 wined3d_mutex_lock();
1191 hr = IWineD3DDevice_SetDepthStencilSurface(This->WineD3DDevice, NULL==pSurface ? NULL : pSurface->wineD3DSurface);
1192 wined3d_mutex_unlock();
1197 static HRESULT WINAPI IDirect3DDevice9Impl_GetDepthStencilSurface(IDirect3DDevice9Ex *iface,
1198 IDirect3DSurface9 **ppZStencilSurface)
1200 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1201 IWineD3DSurface *pZStencilSurface;
1204 TRACE("iface %p, depth_stencil %p.\n", iface, ppZStencilSurface);
1206 if(ppZStencilSurface == NULL){
1207 return D3DERR_INVALIDCALL;
1210 wined3d_mutex_lock();
1211 hr = IWineD3DDevice_GetDepthStencilSurface(This->WineD3DDevice,&pZStencilSurface);
1214 *ppZStencilSurface = IWineD3DSurface_GetParent(pZStencilSurface);
1215 IDirect3DSurface9_AddRef(*ppZStencilSurface);
1216 IWineD3DSurface_Release(pZStencilSurface);
1220 if (hr != WINED3DERR_NOTFOUND)
1221 WARN("Call to IWineD3DDevice_GetDepthStencilSurface failed with 0x%08x\n", hr);
1222 *ppZStencilSurface = NULL;
1224 wined3d_mutex_unlock();
1229 static HRESULT WINAPI IDirect3DDevice9Impl_BeginScene(LPDIRECT3DDEVICE9EX iface) {
1230 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1233 TRACE("iface %p.\n", iface);
1235 wined3d_mutex_lock();
1236 hr = IWineD3DDevice_BeginScene(This->WineD3DDevice);
1237 wined3d_mutex_unlock();
1242 static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_EndScene(LPDIRECT3DDEVICE9EX iface) {
1243 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1246 TRACE("iface %p.\n", iface);
1248 wined3d_mutex_lock();
1249 hr = IWineD3DDevice_EndScene(This->WineD3DDevice);
1250 wined3d_mutex_unlock();
1255 static HRESULT WINAPI IDirect3DDevice9Impl_Clear(LPDIRECT3DDEVICE9EX iface, DWORD Count, CONST D3DRECT* pRects, DWORD Flags, D3DCOLOR Color, float Z, DWORD Stencil) {
1256 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1259 TRACE("iface %p, rect_count %u, rects %p, flags %#x, color 0x%08x, z %.8e, stencil %u.\n",
1260 iface, Count, pRects, Flags, Color, Z, Stencil);
1262 /* Note: D3DRECT is compatible with WINED3DRECT */
1263 wined3d_mutex_lock();
1264 hr = IWineD3DDevice_Clear(This->WineD3DDevice, Count, (const RECT *)pRects, Flags, Color, Z, Stencil);
1265 wined3d_mutex_unlock();
1270 static HRESULT WINAPI IDirect3DDevice9Impl_SetTransform(LPDIRECT3DDEVICE9EX iface, D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX* lpMatrix) {
1271 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1274 TRACE("iface %p, state %#x, matrix %p.\n", iface, State, lpMatrix);
1276 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1277 wined3d_mutex_lock();
1278 hr = IWineD3DDevice_SetTransform(This->WineD3DDevice, State, (CONST WINED3DMATRIX*) lpMatrix);
1279 wined3d_mutex_unlock();
1284 static HRESULT WINAPI IDirect3DDevice9Impl_GetTransform(LPDIRECT3DDEVICE9EX iface, D3DTRANSFORMSTATETYPE State, D3DMATRIX* pMatrix) {
1285 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1288 TRACE("iface %p, state %#x, matrix %p.\n", iface, State, pMatrix);
1290 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1291 wined3d_mutex_lock();
1292 hr = IWineD3DDevice_GetTransform(This->WineD3DDevice, State, (WINED3DMATRIX*) pMatrix);
1293 wined3d_mutex_unlock();
1298 static HRESULT WINAPI IDirect3DDevice9Impl_MultiplyTransform(LPDIRECT3DDEVICE9EX iface, D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX* pMatrix) {
1299 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1302 TRACE("iface %p, state %#x, matrix %p.\n", iface, State, pMatrix);
1304 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1305 wined3d_mutex_lock();
1306 hr = IWineD3DDevice_MultiplyTransform(This->WineD3DDevice, State, (CONST WINED3DMATRIX*) pMatrix);
1307 wined3d_mutex_unlock();
1312 static HRESULT WINAPI IDirect3DDevice9Impl_SetViewport(LPDIRECT3DDEVICE9EX iface, CONST D3DVIEWPORT9* pViewport) {
1313 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1316 TRACE("iface %p, viewport %p.\n", iface, pViewport);
1318 /* Note: D3DVIEWPORT9 is compatible with WINED3DVIEWPORT */
1319 wined3d_mutex_lock();
1320 hr = IWineD3DDevice_SetViewport(This->WineD3DDevice, (const WINED3DVIEWPORT *)pViewport);
1321 wined3d_mutex_unlock();
1326 static HRESULT WINAPI IDirect3DDevice9Impl_GetViewport(LPDIRECT3DDEVICE9EX iface, D3DVIEWPORT9* pViewport) {
1327 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1330 TRACE("iface %p, viewport %p.\n", iface, pViewport);
1332 /* Note: D3DVIEWPORT9 is compatible with WINED3DVIEWPORT */
1333 wined3d_mutex_lock();
1334 hr = IWineD3DDevice_GetViewport(This->WineD3DDevice, (WINED3DVIEWPORT *)pViewport);
1335 wined3d_mutex_unlock();
1340 static HRESULT WINAPI IDirect3DDevice9Impl_SetMaterial(LPDIRECT3DDEVICE9EX iface, CONST D3DMATERIAL9* pMaterial) {
1341 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1344 TRACE("iface %p, material %p.\n", iface, pMaterial);
1346 /* Note: D3DMATERIAL9 is compatible with WINED3DMATERIAL */
1347 wined3d_mutex_lock();
1348 hr = IWineD3DDevice_SetMaterial(This->WineD3DDevice, (const WINED3DMATERIAL *)pMaterial);
1349 wined3d_mutex_unlock();
1354 static HRESULT WINAPI IDirect3DDevice9Impl_GetMaterial(LPDIRECT3DDEVICE9EX iface, D3DMATERIAL9* pMaterial) {
1355 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1358 TRACE("iface %p, material %p.\n", iface, pMaterial);
1360 /* Note: D3DMATERIAL9 is compatible with WINED3DMATERIAL */
1361 wined3d_mutex_lock();
1362 hr = IWineD3DDevice_GetMaterial(This->WineD3DDevice, (WINED3DMATERIAL *)pMaterial);
1363 wined3d_mutex_unlock();
1368 static HRESULT WINAPI IDirect3DDevice9Impl_SetLight(LPDIRECT3DDEVICE9EX iface, DWORD Index, CONST D3DLIGHT9* pLight) {
1369 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1372 TRACE("iface %p, index %u, light %p.\n", iface, Index, pLight);
1374 /* Note: D3DLIGHT9 is compatible with WINED3DLIGHT */
1375 wined3d_mutex_lock();
1376 hr = IWineD3DDevice_SetLight(This->WineD3DDevice, Index, (const WINED3DLIGHT *)pLight);
1377 wined3d_mutex_unlock();
1382 static HRESULT WINAPI IDirect3DDevice9Impl_GetLight(LPDIRECT3DDEVICE9EX iface, DWORD Index, D3DLIGHT9* pLight) {
1383 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1386 TRACE("iface %p, index %u, light %p.\n", iface, Index, pLight);
1388 /* Note: D3DLIGHT9 is compatible with WINED3DLIGHT */
1389 wined3d_mutex_lock();
1390 hr = IWineD3DDevice_GetLight(This->WineD3DDevice, Index, (WINED3DLIGHT *)pLight);
1391 wined3d_mutex_unlock();
1396 static HRESULT WINAPI IDirect3DDevice9Impl_LightEnable(LPDIRECT3DDEVICE9EX iface, DWORD Index, BOOL Enable) {
1397 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1400 TRACE("iface %p, index %u, enable %#x.\n", iface, Index, Enable);
1402 wined3d_mutex_lock();
1403 hr = IWineD3DDevice_SetLightEnable(This->WineD3DDevice, Index, Enable);
1404 wined3d_mutex_unlock();
1409 static HRESULT WINAPI IDirect3DDevice9Impl_GetLightEnable(LPDIRECT3DDEVICE9EX iface, DWORD Index, BOOL* pEnable) {
1410 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1413 TRACE("iface %p, index %u, enable %p.\n", iface, Index, pEnable);
1415 wined3d_mutex_lock();
1416 hr = IWineD3DDevice_GetLightEnable(This->WineD3DDevice, Index, pEnable);
1417 wined3d_mutex_unlock();
1422 static HRESULT WINAPI IDirect3DDevice9Impl_SetClipPlane(LPDIRECT3DDEVICE9EX iface, DWORD Index, CONST float* pPlane) {
1423 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1426 TRACE("iface %p, index %u, plane %p.\n", iface, Index, pPlane);
1428 wined3d_mutex_lock();
1429 hr = IWineD3DDevice_SetClipPlane(This->WineD3DDevice, Index, pPlane);
1430 wined3d_mutex_unlock();
1435 static HRESULT WINAPI IDirect3DDevice9Impl_GetClipPlane(LPDIRECT3DDEVICE9EX iface, DWORD Index, float* pPlane) {
1436 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1439 TRACE("iface %p, index %u, plane %p.\n", iface, Index, pPlane);
1441 wined3d_mutex_lock();
1442 hr = IWineD3DDevice_GetClipPlane(This->WineD3DDevice, Index, pPlane);
1443 wined3d_mutex_unlock();
1448 static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_SetRenderState(LPDIRECT3DDEVICE9EX iface, D3DRENDERSTATETYPE State, DWORD Value) {
1449 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1452 TRACE("iface %p, state %#x, value %#x.\n", iface, State, Value);
1454 wined3d_mutex_lock();
1455 hr = IWineD3DDevice_SetRenderState(This->WineD3DDevice, State, Value);
1456 wined3d_mutex_unlock();
1461 static HRESULT WINAPI IDirect3DDevice9Impl_GetRenderState(LPDIRECT3DDEVICE9EX iface, D3DRENDERSTATETYPE State, DWORD* pValue) {
1462 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1465 TRACE("iface %p, state %#x, value %p.\n", iface, State, pValue);
1467 wined3d_mutex_lock();
1468 hr = IWineD3DDevice_GetRenderState(This->WineD3DDevice, State, pValue);
1469 wined3d_mutex_unlock();
1474 static HRESULT WINAPI IDirect3DDevice9Impl_CreateStateBlock(IDirect3DDevice9Ex *iface,
1475 D3DSTATEBLOCKTYPE type, IDirect3DStateBlock9 **stateblock)
1477 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1478 IDirect3DStateBlock9Impl *object;
1481 TRACE("iface %p, type %#x, stateblock %p.\n", iface, type, stateblock);
1483 if (type != D3DSBT_ALL && type != D3DSBT_PIXELSTATE && type != D3DSBT_VERTEXSTATE)
1485 WARN("Unexpected stateblock type, returning D3DERR_INVALIDCALL.\n");
1486 return D3DERR_INVALIDCALL;
1489 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1492 ERR("Failed to allocate stateblock memory.\n");
1493 return E_OUTOFMEMORY;
1496 hr = stateblock_init(object, This, type, NULL);
1499 WARN("Failed to initialize stateblock, hr %#x.\n", hr);
1500 HeapFree(GetProcessHeap(), 0, object);
1504 TRACE("Created stateblock %p.\n", object);
1505 *stateblock = &object->IDirect3DStateBlock9_iface;
1510 static HRESULT WINAPI IDirect3DDevice9Impl_BeginStateBlock(IDirect3DDevice9Ex *iface)
1512 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1515 TRACE("iface %p.\n", iface);
1517 wined3d_mutex_lock();
1518 hr = IWineD3DDevice_BeginStateBlock(This->WineD3DDevice);
1519 wined3d_mutex_unlock();
1524 static HRESULT WINAPI IDirect3DDevice9Impl_EndStateBlock(IDirect3DDevice9Ex *iface, IDirect3DStateBlock9 **stateblock)
1526 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1527 struct wined3d_stateblock *wined3d_stateblock;
1528 IDirect3DStateBlock9Impl *object;
1531 TRACE("iface %p, stateblock %p.\n", iface, stateblock);
1533 wined3d_mutex_lock();
1534 hr = IWineD3DDevice_EndStateBlock(This->WineD3DDevice, &wined3d_stateblock);
1535 wined3d_mutex_unlock();
1538 WARN("IWineD3DDevice_EndStateBlock() failed, hr %#x.\n", hr);
1542 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1545 ERR("Failed to allocate stateblock memory.\n");
1546 wined3d_mutex_lock();
1547 wined3d_stateblock_decref(wined3d_stateblock);
1548 wined3d_mutex_unlock();
1549 return E_OUTOFMEMORY;
1552 hr = stateblock_init(object, This, 0, wined3d_stateblock);
1555 WARN("Failed to initialize stateblock, hr %#x.\n", hr);
1556 wined3d_mutex_lock();
1557 wined3d_stateblock_decref(wined3d_stateblock);
1558 wined3d_mutex_unlock();
1559 HeapFree(GetProcessHeap(), 0, object);
1563 TRACE("Created stateblock %p.\n", object);
1564 *stateblock = &object->IDirect3DStateBlock9_iface;
1569 static HRESULT WINAPI IDirect3DDevice9Impl_SetClipStatus(LPDIRECT3DDEVICE9EX iface, CONST D3DCLIPSTATUS9* pClipStatus) {
1570 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1573 TRACE("iface %p, clip_status %p.\n", iface, pClipStatus);
1575 wined3d_mutex_lock();
1576 hr = IWineD3DDevice_SetClipStatus(This->WineD3DDevice, (const WINED3DCLIPSTATUS *)pClipStatus);
1577 wined3d_mutex_unlock();
1582 static HRESULT WINAPI IDirect3DDevice9Impl_GetClipStatus(LPDIRECT3DDEVICE9EX iface, D3DCLIPSTATUS9* pClipStatus) {
1583 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1586 TRACE("iface %p, clip_status %p.\n", iface, pClipStatus);
1588 wined3d_mutex_lock();
1589 hr = IWineD3DDevice_GetClipStatus(This->WineD3DDevice, (WINED3DCLIPSTATUS *)pClipStatus);
1590 wined3d_mutex_unlock();
1595 static HRESULT WINAPI IDirect3DDevice9Impl_GetTexture(IDirect3DDevice9Ex *iface,
1596 DWORD Stage, IDirect3DBaseTexture9 **ppTexture)
1598 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1599 struct wined3d_texture *wined3d_texture = NULL;
1602 TRACE("iface %p, stage %u, texture %p.\n", iface, Stage, ppTexture);
1604 if(ppTexture == NULL){
1605 return D3DERR_INVALIDCALL;
1608 wined3d_mutex_lock();
1609 hr = IWineD3DDevice_GetTexture(This->WineD3DDevice, Stage, &wined3d_texture);
1610 if (SUCCEEDED(hr) && wined3d_texture)
1612 *ppTexture = wined3d_texture_get_parent(wined3d_texture);
1613 IDirect3DBaseTexture9_AddRef(*ppTexture);
1614 wined3d_texture_decref(wined3d_texture);
1620 WARN("Call to get texture (%u) failed (%p).\n", Stage, wined3d_texture);
1624 wined3d_mutex_unlock();
1629 static HRESULT WINAPI IDirect3DDevice9Impl_SetTexture(IDirect3DDevice9Ex *iface,
1630 DWORD stage, IDirect3DBaseTexture9 *texture)
1632 IDirect3DDevice9Impl *device = (IDirect3DDevice9Impl *)iface;
1635 TRACE("iface %p, stage %u, texture %p.\n", iface, stage, texture);
1637 wined3d_mutex_lock();
1638 hr = IWineD3DDevice_SetTexture(device->WineD3DDevice, stage,
1639 texture ? ((IDirect3DBaseTexture9Impl *)texture)->wined3d_texture : NULL);
1640 wined3d_mutex_unlock();
1645 static const WINED3DTEXTURESTAGESTATETYPE tss_lookup[] =
1647 WINED3DTSS_FORCE_DWORD, /* 0, unused */
1648 WINED3DTSS_COLOROP, /* 1, D3DTSS_COLOROP */
1649 WINED3DTSS_COLORARG1, /* 2, D3DTSS_COLORARG1 */
1650 WINED3DTSS_COLORARG2, /* 3, D3DTSS_COLORARG2 */
1651 WINED3DTSS_ALPHAOP, /* 4, D3DTSS_ALPHAOP */
1652 WINED3DTSS_ALPHAARG1, /* 5, D3DTSS_ALPHAARG1 */
1653 WINED3DTSS_ALPHAARG2, /* 6, D3DTSS_ALPHAARG2 */
1654 WINED3DTSS_BUMPENVMAT00, /* 7, D3DTSS_BUMPENVMAT00 */
1655 WINED3DTSS_BUMPENVMAT01, /* 8, D3DTSS_BUMPENVMAT01 */
1656 WINED3DTSS_BUMPENVMAT10, /* 9, D3DTSS_BUMPENVMAT10 */
1657 WINED3DTSS_BUMPENVMAT11, /* 10, D3DTSS_BUMPENVMAT11 */
1658 WINED3DTSS_TEXCOORDINDEX, /* 11, D3DTSS_TEXCOORDINDEX */
1659 WINED3DTSS_FORCE_DWORD, /* 12, unused */
1660 WINED3DTSS_FORCE_DWORD, /* 13, unused */
1661 WINED3DTSS_FORCE_DWORD, /* 14, unused */
1662 WINED3DTSS_FORCE_DWORD, /* 15, unused */
1663 WINED3DTSS_FORCE_DWORD, /* 16, unused */
1664 WINED3DTSS_FORCE_DWORD, /* 17, unused */
1665 WINED3DTSS_FORCE_DWORD, /* 18, unused */
1666 WINED3DTSS_FORCE_DWORD, /* 19, unused */
1667 WINED3DTSS_FORCE_DWORD, /* 20, unused */
1668 WINED3DTSS_FORCE_DWORD, /* 21, unused */
1669 WINED3DTSS_BUMPENVLSCALE, /* 22, D3DTSS_BUMPENVLSCALE */
1670 WINED3DTSS_BUMPENVLOFFSET, /* 23, D3DTSS_BUMPENVLOFFSET */
1671 WINED3DTSS_TEXTURETRANSFORMFLAGS, /* 24, D3DTSS_TEXTURETRANSFORMFLAGS */
1672 WINED3DTSS_FORCE_DWORD, /* 25, unused */
1673 WINED3DTSS_COLORARG0, /* 26, D3DTSS_COLORARG0 */
1674 WINED3DTSS_ALPHAARG0, /* 27, D3DTSS_ALPHAARG0 */
1675 WINED3DTSS_RESULTARG, /* 28, D3DTSS_RESULTARG */
1676 WINED3DTSS_FORCE_DWORD, /* 29, unused */
1677 WINED3DTSS_FORCE_DWORD, /* 30, unused */
1678 WINED3DTSS_FORCE_DWORD, /* 31, unused */
1679 WINED3DTSS_CONSTANT, /* 32, D3DTSS_CONSTANT */
1682 static HRESULT WINAPI IDirect3DDevice9Impl_GetTextureStageState(LPDIRECT3DDEVICE9EX iface, DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD *pValue)
1684 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1687 TRACE("iface %p, stage %u, state %#x, value %p.\n", iface, Stage, Type, pValue);
1689 if (Type >= sizeof(tss_lookup) / sizeof(*tss_lookup))
1691 WARN("Invalid Type %#x passed.\n", Type);
1695 wined3d_mutex_lock();
1696 hr = IWineD3DDevice_GetTextureStageState(This->WineD3DDevice, Stage, tss_lookup[Type], pValue);
1697 wined3d_mutex_unlock();
1702 static HRESULT WINAPI IDirect3DDevice9Impl_SetTextureStageState(LPDIRECT3DDEVICE9EX iface, DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD Value)
1704 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1707 TRACE("iface %p, stage %u, state %#x, value %#x.\n", iface, Stage, Type, Value);
1709 if (Type >= sizeof(tss_lookup) / sizeof(*tss_lookup))
1711 WARN("Invalid Type %#x passed.\n", Type);
1715 wined3d_mutex_lock();
1716 hr = IWineD3DDevice_SetTextureStageState(This->WineD3DDevice, Stage, tss_lookup[Type], Value);
1717 wined3d_mutex_unlock();
1722 static HRESULT WINAPI IDirect3DDevice9Impl_GetSamplerState(IDirect3DDevice9Ex *iface, DWORD Sampler,
1723 D3DSAMPLERSTATETYPE Type, DWORD *pValue)
1725 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1728 TRACE("iface %p, sampler %u, state %#x, value %p.\n", iface, Sampler, Type, pValue);
1730 wined3d_mutex_lock();
1731 hr = IWineD3DDevice_GetSamplerState(This->WineD3DDevice, Sampler, Type, pValue);
1732 wined3d_mutex_unlock();
1737 static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_SetSamplerState(LPDIRECT3DDEVICE9EX iface, DWORD Sampler, D3DSAMPLERSTATETYPE Type, DWORD Value) {
1738 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1741 TRACE("iface %p, sampler %u, state %#x, value %#x.\n", iface, Sampler, Type, Value);
1743 wined3d_mutex_lock();
1744 hr = IWineD3DDevice_SetSamplerState(This->WineD3DDevice, Sampler, Type, Value);
1745 wined3d_mutex_unlock();
1750 static HRESULT WINAPI IDirect3DDevice9Impl_ValidateDevice(LPDIRECT3DDEVICE9EX iface, DWORD* pNumPasses) {
1751 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1754 TRACE("iface %p, pass_count %p.\n", iface, pNumPasses);
1756 wined3d_mutex_lock();
1757 hr = IWineD3DDevice_ValidateDevice(This->WineD3DDevice, pNumPasses);
1758 wined3d_mutex_unlock();
1763 static HRESULT WINAPI IDirect3DDevice9Impl_SetPaletteEntries(IDirect3DDevice9Ex *iface, UINT PaletteNumber,
1764 const PALETTEENTRY *pEntries)
1766 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1769 TRACE("iface %p, palette_idx %u, entries %p.\n", iface, PaletteNumber, pEntries);
1771 wined3d_mutex_lock();
1772 hr = IWineD3DDevice_SetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
1773 wined3d_mutex_unlock();
1778 static HRESULT WINAPI IDirect3DDevice9Impl_GetPaletteEntries(LPDIRECT3DDEVICE9EX iface, UINT PaletteNumber, PALETTEENTRY* pEntries) {
1779 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1782 TRACE("iface %p, palette_idx %u, entries %p.\n", iface, PaletteNumber, pEntries);
1784 wined3d_mutex_lock();
1785 hr = IWineD3DDevice_GetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
1786 wined3d_mutex_unlock();
1791 static HRESULT WINAPI IDirect3DDevice9Impl_SetCurrentTexturePalette(LPDIRECT3DDEVICE9EX iface, UINT PaletteNumber) {
1792 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1795 TRACE("iface %p, palette_idx %u.\n", iface, PaletteNumber);
1797 wined3d_mutex_lock();
1798 hr = IWineD3DDevice_SetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
1799 wined3d_mutex_unlock();
1804 static HRESULT WINAPI IDirect3DDevice9Impl_GetCurrentTexturePalette(LPDIRECT3DDEVICE9EX iface, UINT* PaletteNumber) {
1805 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1808 TRACE("iface %p, palette_idx %p.\n", iface, PaletteNumber);
1810 wined3d_mutex_lock();
1811 hr = IWineD3DDevice_GetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
1812 wined3d_mutex_unlock();
1817 static HRESULT WINAPI IDirect3DDevice9Impl_SetScissorRect(LPDIRECT3DDEVICE9EX iface, CONST RECT* pRect) {
1818 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1821 TRACE("iface %p, rect %p.\n", iface, pRect);
1823 wined3d_mutex_lock();
1824 hr = IWineD3DDevice_SetScissorRect(This->WineD3DDevice, pRect);
1825 wined3d_mutex_unlock();
1830 static HRESULT WINAPI IDirect3DDevice9Impl_GetScissorRect(LPDIRECT3DDEVICE9EX iface, RECT* pRect) {
1831 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1834 TRACE("iface %p, rect %p.\n", iface, pRect);
1836 wined3d_mutex_lock();
1837 hr = IWineD3DDevice_GetScissorRect(This->WineD3DDevice, pRect);
1838 wined3d_mutex_unlock();
1843 static HRESULT WINAPI IDirect3DDevice9Impl_SetSoftwareVertexProcessing(LPDIRECT3DDEVICE9EX iface, BOOL bSoftware) {
1844 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1847 TRACE("iface %p, software %#x.\n", iface, bSoftware);
1849 wined3d_mutex_lock();
1850 hr = IWineD3DDevice_SetSoftwareVertexProcessing(This->WineD3DDevice, bSoftware);
1851 wined3d_mutex_unlock();
1856 static BOOL WINAPI IDirect3DDevice9Impl_GetSoftwareVertexProcessing(LPDIRECT3DDEVICE9EX iface) {
1857 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1860 TRACE("iface %p.\n", iface);
1862 wined3d_mutex_lock();
1863 ret = IWineD3DDevice_GetSoftwareVertexProcessing(This->WineD3DDevice);
1864 wined3d_mutex_unlock();
1869 static HRESULT WINAPI IDirect3DDevice9Impl_SetNPatchMode(LPDIRECT3DDEVICE9EX iface, float nSegments) {
1870 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1873 TRACE("iface %p, segment_count %.8e.\n", iface, nSegments);
1875 wined3d_mutex_lock();
1876 hr = IWineD3DDevice_SetNPatchMode(This->WineD3DDevice, nSegments);
1877 wined3d_mutex_unlock();
1882 static float WINAPI IDirect3DDevice9Impl_GetNPatchMode(LPDIRECT3DDEVICE9EX iface) {
1883 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1886 TRACE("iface %p.\n", iface);
1888 wined3d_mutex_lock();
1889 ret = IWineD3DDevice_GetNPatchMode(This->WineD3DDevice);
1890 wined3d_mutex_unlock();
1895 static HRESULT WINAPI IDirect3DDevice9Impl_DrawPrimitive(IDirect3DDevice9Ex *iface, D3DPRIMITIVETYPE PrimitiveType,
1896 UINT StartVertex, UINT PrimitiveCount)
1898 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1901 TRACE("iface %p, primitive_type %#x, start_vertex %u, primitive_count %u.\n",
1902 iface, PrimitiveType, StartVertex, PrimitiveCount);
1904 wined3d_mutex_lock();
1905 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1906 hr = IWineD3DDevice_DrawPrimitive(This->WineD3DDevice, StartVertex,
1907 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount));
1908 wined3d_mutex_unlock();
1913 static HRESULT WINAPI IDirect3DDevice9Impl_DrawIndexedPrimitive(LPDIRECT3DDEVICE9EX iface, D3DPRIMITIVETYPE PrimitiveType,
1914 INT BaseVertexIndex, UINT MinVertexIndex, UINT NumVertices, UINT startIndex, UINT primCount) {
1915 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1918 TRACE("iface %p, primitive_type %#x, base_vertex_idx %u, min_vertex_idx %u,\n"
1919 "vertex_count %u, start_idx %u, primitive_count %u.\n",
1920 iface, PrimitiveType, BaseVertexIndex, MinVertexIndex,
1921 NumVertices, startIndex, primCount);
1923 wined3d_mutex_lock();
1924 IWineD3DDevice_SetBaseVertexIndex(This->WineD3DDevice, BaseVertexIndex);
1925 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1926 hr = IWineD3DDevice_DrawIndexedPrimitive(This->WineD3DDevice, startIndex,
1927 vertex_count_from_primitive_count(PrimitiveType, primCount));
1928 wined3d_mutex_unlock();
1933 static HRESULT WINAPI IDirect3DDevice9Impl_DrawPrimitiveUP(IDirect3DDevice9Ex *iface, D3DPRIMITIVETYPE PrimitiveType,
1934 UINT PrimitiveCount, const void *pVertexStreamZeroData, UINT VertexStreamZeroStride)
1936 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1939 TRACE("iface %p, primitive_type %#x, primitive_count %u, data %p, stride %u.\n",
1940 iface, PrimitiveType, PrimitiveCount, pVertexStreamZeroData, VertexStreamZeroStride);
1942 wined3d_mutex_lock();
1943 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1944 hr = IWineD3DDevice_DrawPrimitiveUP(This->WineD3DDevice,
1945 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount),
1946 pVertexStreamZeroData, VertexStreamZeroStride);
1947 wined3d_mutex_unlock();
1952 static HRESULT WINAPI IDirect3DDevice9Impl_DrawIndexedPrimitiveUP(LPDIRECT3DDEVICE9EX iface, D3DPRIMITIVETYPE PrimitiveType, UINT MinVertexIndex,
1953 UINT NumVertexIndices, UINT PrimitiveCount, CONST void* pIndexData,
1954 D3DFORMAT IndexDataFormat, CONST void* pVertexStreamZeroData, UINT VertexStreamZeroStride) {
1955 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1958 TRACE("iface %p, primitive_type %#x, min_vertex_idx %u, index_count %u, primitive_count %u,\n"
1959 "index_data %p, index_format %#x, vertex_data %p, vertex_stride %u.\n",
1960 iface, PrimitiveType, MinVertexIndex, NumVertexIndices, PrimitiveCount,
1961 pIndexData, IndexDataFormat, pVertexStreamZeroData, VertexStreamZeroStride);
1963 wined3d_mutex_lock();
1964 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1965 hr = IWineD3DDevice_DrawIndexedPrimitiveUP(This->WineD3DDevice,
1966 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount), pIndexData,
1967 wined3dformat_from_d3dformat(IndexDataFormat), pVertexStreamZeroData, VertexStreamZeroStride);
1968 wined3d_mutex_unlock();
1973 static HRESULT WINAPI IDirect3DDevice9Impl_ProcessVertices(LPDIRECT3DDEVICE9EX iface, UINT SrcStartIndex, UINT DestIndex, UINT VertexCount, IDirect3DVertexBuffer9* pDestBuffer, IDirect3DVertexDeclaration9* pVertexDecl, DWORD Flags) {
1974 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1975 IDirect3DVertexDeclaration9Impl *Decl = (IDirect3DVertexDeclaration9Impl *) pVertexDecl;
1977 IDirect3DVertexBuffer9Impl *dest = (IDirect3DVertexBuffer9Impl *) pDestBuffer;
1979 TRACE("iface %p, src_start_idx %u, dst_idx %u, vertex_count %u, dst_buffer %p, declaration %p, flags %#x.\n",
1980 iface, SrcStartIndex, DestIndex, VertexCount, pDestBuffer, pVertexDecl, Flags);
1982 wined3d_mutex_lock();
1983 hr = IWineD3DDevice_ProcessVertices(This->WineD3DDevice,SrcStartIndex, DestIndex, VertexCount, dest->wineD3DVertexBuffer, Decl ? Decl->wineD3DVertexDeclaration : NULL, Flags, dest->fvf);
1984 wined3d_mutex_unlock();
1989 static HRESULT WINAPI IDirect3DDevice9Impl_CreateVertexDeclaration(IDirect3DDevice9Ex *iface,
1990 const D3DVERTEXELEMENT9 *elements, IDirect3DVertexDeclaration9 **declaration)
1992 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1993 IDirect3DVertexDeclaration9Impl *object;
1996 TRACE("iface %p, elements %p, declaration %p.\n", iface, elements, declaration);
2000 WARN("Caller passed a NULL declaration, returning D3DERR_INVALIDCALL.\n");
2001 return D3DERR_INVALIDCALL;
2004 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2007 ERR("Failed to allocate vertex declaration memory.\n");
2008 return E_OUTOFMEMORY;
2011 hr = vertexdeclaration_init(object, This, elements);
2014 WARN("Failed to initialize vertex declaration, hr %#x.\n", hr);
2015 HeapFree(GetProcessHeap(), 0, object);
2019 TRACE("Created vertex declaration %p.\n", object);
2020 *declaration = (IDirect3DVertexDeclaration9 *)object;
2025 static HRESULT WINAPI IDirect3DDevice9Impl_SetVertexDeclaration(IDirect3DDevice9Ex *iface,
2026 IDirect3DVertexDeclaration9 *declaration)
2030 TRACE("iface %p, declaration %p.\n", iface, declaration);
2032 wined3d_mutex_lock();
2033 hr = IWineD3DDevice_SetVertexDeclaration(((IDirect3DDevice9Impl *)iface)->WineD3DDevice,
2034 declaration ? ((IDirect3DVertexDeclaration9Impl *)declaration)->wineD3DVertexDeclaration : NULL);
2035 wined3d_mutex_unlock();
2040 static HRESULT WINAPI IDirect3DDevice9Impl_GetVertexDeclaration(IDirect3DDevice9Ex *iface,
2041 IDirect3DVertexDeclaration9 **declaration)
2043 struct wined3d_vertex_declaration *wined3d_declaration = NULL;
2046 TRACE("iface %p, declaration %p.\n", iface, declaration);
2048 if (!declaration) return D3DERR_INVALIDCALL;
2050 wined3d_mutex_lock();
2051 hr = IWineD3DDevice_GetVertexDeclaration(((IDirect3DDevice9Impl *)iface)->WineD3DDevice, &wined3d_declaration);
2052 if (SUCCEEDED(hr) && wined3d_declaration)
2054 *declaration = wined3d_vertex_declaration_get_parent(wined3d_declaration);
2055 IDirect3DVertexDeclaration9_AddRef(*declaration);
2056 wined3d_vertex_declaration_decref(wined3d_declaration);
2060 *declaration = NULL;
2062 wined3d_mutex_unlock();
2064 TRACE("Returning %p.\n", *declaration);
2068 static IDirect3DVertexDeclaration9 *getConvertedDecl(IDirect3DDevice9Impl *This, DWORD fvf) {
2070 D3DVERTEXELEMENT9* elements = NULL;
2071 IDirect3DVertexDeclaration9* pDecl = NULL;
2072 int p, low, high; /* deliberately signed */
2073 IDirect3DVertexDeclaration9 **convertedDecls = This->convertedDecls;
2075 TRACE("Searching for declaration for fvf %08x... ", fvf);
2078 high = This->numConvertedDecls - 1;
2079 while(low <= high) {
2080 p = (low + high) >> 1;
2082 if(((IDirect3DVertexDeclaration9Impl *) convertedDecls[p])->convFVF == fvf) {
2083 TRACE("found %p\n", convertedDecls[p]);
2084 return convertedDecls[p];
2085 } else if(((IDirect3DVertexDeclaration9Impl *) convertedDecls[p])->convFVF < fvf) {
2091 TRACE("not found. Creating and inserting at position %d.\n", low);
2093 hr = vdecl_convert_fvf(fvf, &elements);
2094 if (hr != S_OK) return NULL;
2096 hr = IDirect3DDevice9Impl_CreateVertexDeclaration((IDirect3DDevice9Ex *) This, elements, &pDecl);
2097 HeapFree(GetProcessHeap(), 0, elements); /* CreateVertexDeclaration makes a copy */
2098 if (hr != S_OK) return NULL;
2100 if(This->declArraySize == This->numConvertedDecls) {
2101 int grow = max(This->declArraySize / 2, 8);
2102 convertedDecls = HeapReAlloc(GetProcessHeap(), 0, convertedDecls,
2103 sizeof(convertedDecls[0]) * (This->numConvertedDecls + grow));
2104 if(!convertedDecls) {
2105 /* This will destroy it */
2106 IDirect3DVertexDeclaration9_Release(pDecl);
2109 This->convertedDecls = convertedDecls;
2110 This->declArraySize += grow;
2113 memmove(convertedDecls + low + 1, convertedDecls + low, sizeof(IDirect3DVertexDeclaration9Impl *) * (This->numConvertedDecls - low));
2114 convertedDecls[low] = pDecl;
2115 This->numConvertedDecls++;
2117 /* Will prevent the decl from being destroyed */
2118 ((IDirect3DVertexDeclaration9Impl *) pDecl)->convFVF = fvf;
2119 IDirect3DVertexDeclaration9_Release(pDecl); /* Does not destroy now */
2121 TRACE("Returning %p. %d decls in array\n", pDecl, This->numConvertedDecls);
2125 static HRESULT WINAPI IDirect3DDevice9Impl_SetFVF(LPDIRECT3DDEVICE9EX iface, DWORD FVF) {
2126 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2127 IDirect3DVertexDeclaration9 *decl;
2130 TRACE("iface %p, fvf %#x.\n", iface, FVF);
2134 WARN("%#x is not a valid FVF\n", FVF);
2138 wined3d_mutex_lock();
2139 decl = getConvertedDecl(This, FVF);
2140 wined3d_mutex_unlock();
2144 /* Any situation when this should happen, except out of memory? */
2145 ERR("Failed to create a converted vertex declaration\n");
2146 return D3DERR_DRIVERINTERNALERROR;
2149 hr = IDirect3DDevice9Impl_SetVertexDeclaration(iface, decl);
2150 if (FAILED(hr)) ERR("Failed to set vertex declaration\n");
2155 static HRESULT WINAPI IDirect3DDevice9Impl_GetFVF(IDirect3DDevice9Ex *iface, DWORD *pFVF)
2157 IDirect3DVertexDeclaration9 *decl;
2160 TRACE("iface %p, fvf %p.\n", iface, pFVF);
2162 hr = IDirect3DDevice9_GetVertexDeclaration(iface, &decl);
2165 WARN("Failed to get vertex declaration, %#x\n", hr);
2172 *pFVF = ((IDirect3DVertexDeclaration9Impl *)decl)->convFVF;
2173 IDirect3DVertexDeclaration9_Release(decl);
2180 TRACE("Returning FVF %#x\n", *pFVF);
2185 static HRESULT WINAPI IDirect3DDevice9Impl_CreateVertexShader(IDirect3DDevice9Ex *iface,
2186 const DWORD *byte_code, IDirect3DVertexShader9 **shader)
2188 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2189 IDirect3DVertexShader9Impl *object;
2192 TRACE("iface %p, byte_code %p, shader %p.\n", iface, byte_code, shader);
2194 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2197 ERR("Failed to allocate vertex shader memory.\n");
2198 return E_OUTOFMEMORY;
2201 hr = vertexshader_init(object, This, byte_code);
2204 WARN("Failed to initialize vertex shader, hr %#x.\n", hr);
2205 HeapFree(GetProcessHeap(), 0, object);
2209 TRACE("Created vertex shader %p.\n", object);
2210 *shader = (IDirect3DVertexShader9 *)object;
2215 static HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShader(IDirect3DDevice9Ex *iface,
2216 IDirect3DVertexShader9 *shader)
2220 TRACE("iface %p, shader %p.\n", iface, shader);
2222 wined3d_mutex_lock();
2223 hr = IWineD3DDevice_SetVertexShader(((IDirect3DDevice9Impl *)iface)->WineD3DDevice,
2224 shader ? ((IDirect3DVertexShader9Impl *)shader)->wined3d_shader : NULL);
2225 wined3d_mutex_unlock();
2230 static HRESULT WINAPI IDirect3DDevice9Impl_GetVertexShader(IDirect3DDevice9Ex *iface,
2231 IDirect3DVertexShader9 **shader)
2233 struct wined3d_shader *wined3d_shader;
2235 TRACE("iface %p, shader %p.\n", iface, shader);
2237 wined3d_mutex_lock();
2238 wined3d_shader = IWineD3DDevice_GetVertexShader(((IDirect3DDevice9Impl *)iface)->WineD3DDevice);
2241 *shader = wined3d_shader_get_parent(wined3d_shader);
2242 IDirect3DVertexShader9_AddRef(*shader);
2243 wined3d_shader_decref(wined3d_shader);
2249 wined3d_mutex_unlock();
2251 TRACE("Returning %p.\n", *shader);
2256 static HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShaderConstantF(IDirect3DDevice9Ex *iface,
2257 UINT reg_idx, const float *data, UINT count)
2261 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface, reg_idx, data, count);
2263 if (reg_idx + count > D3D9_MAX_VERTEX_SHADER_CONSTANTF)
2265 WARN("Trying to access %u constants, but d3d9 only supports %u\n",
2266 reg_idx + count, D3D9_MAX_VERTEX_SHADER_CONSTANTF);
2267 return D3DERR_INVALIDCALL;
2270 wined3d_mutex_lock();
2271 hr = IWineD3DDevice_SetVertexShaderConstantF(((IDirect3DDevice9Impl *)iface)->WineD3DDevice, reg_idx, data, count);
2272 wined3d_mutex_unlock();
2277 static HRESULT WINAPI IDirect3DDevice9Impl_GetVertexShaderConstantF(IDirect3DDevice9Ex *iface,
2278 UINT reg_idx, float *data, UINT count)
2282 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface, reg_idx, data, count);
2284 if (reg_idx + count > D3D9_MAX_VERTEX_SHADER_CONSTANTF)
2286 WARN("Trying to access %u constants, but d3d9 only supports %u\n",
2287 reg_idx + count, D3D9_MAX_VERTEX_SHADER_CONSTANTF);
2288 return D3DERR_INVALIDCALL;
2291 wined3d_mutex_lock();
2292 hr = IWineD3DDevice_GetVertexShaderConstantF(((IDirect3DDevice9Impl *)iface)->WineD3DDevice, reg_idx, data, count);
2293 wined3d_mutex_unlock();
2298 static HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShaderConstantI(IDirect3DDevice9Ex *iface,
2299 UINT reg_idx, const int *data, UINT count)
2303 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface, reg_idx, data, count);
2305 wined3d_mutex_lock();
2306 hr = IWineD3DDevice_SetVertexShaderConstantI(((IDirect3DDevice9Impl *)iface)->WineD3DDevice, reg_idx, data, count);
2307 wined3d_mutex_unlock();
2312 static HRESULT WINAPI IDirect3DDevice9Impl_GetVertexShaderConstantI(IDirect3DDevice9Ex *iface,
2313 UINT reg_idx, int *data, UINT count)
2317 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface, reg_idx, data, count);
2319 wined3d_mutex_lock();
2320 hr = IWineD3DDevice_GetVertexShaderConstantI(((IDirect3DDevice9Impl *)iface)->WineD3DDevice, reg_idx, data, count);
2321 wined3d_mutex_unlock();
2326 static HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShaderConstantB(IDirect3DDevice9Ex *iface,
2327 UINT reg_idx, const BOOL *data, UINT count)
2331 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface, reg_idx, data, count);
2333 wined3d_mutex_lock();
2334 hr = IWineD3DDevice_SetVertexShaderConstantB(((IDirect3DDevice9Impl *)iface)->WineD3DDevice, reg_idx, data, count);
2335 wined3d_mutex_unlock();
2340 static HRESULT WINAPI IDirect3DDevice9Impl_GetVertexShaderConstantB(IDirect3DDevice9Ex *iface,
2341 UINT reg_idx, BOOL *data, UINT count)
2345 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface, reg_idx, data, count);
2347 wined3d_mutex_lock();
2348 hr = IWineD3DDevice_GetVertexShaderConstantB(((IDirect3DDevice9Impl *)iface)->WineD3DDevice, reg_idx, data, count);
2349 wined3d_mutex_unlock();
2354 static HRESULT WINAPI IDirect3DDevice9Impl_SetStreamSource(LPDIRECT3DDEVICE9EX iface, UINT StreamNumber, IDirect3DVertexBuffer9* pStreamData, UINT OffsetInBytes, UINT Stride) {
2355 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2358 TRACE("iface %p, stream_idx %u, buffer %p, offset %u, stride %u.\n",
2359 iface, StreamNumber, pStreamData, OffsetInBytes, Stride);
2361 wined3d_mutex_lock();
2362 hr = IWineD3DDevice_SetStreamSource(This->WineD3DDevice, StreamNumber,
2363 pStreamData ? ((IDirect3DVertexBuffer9Impl *)pStreamData)->wineD3DVertexBuffer : NULL,
2364 OffsetInBytes, Stride);
2365 wined3d_mutex_unlock();
2370 static HRESULT WINAPI IDirect3DDevice9Impl_GetStreamSource(IDirect3DDevice9Ex *iface,
2371 UINT StreamNumber, IDirect3DVertexBuffer9 **pStream, UINT* OffsetInBytes, UINT* pStride)
2373 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2374 struct wined3d_buffer *retStream = NULL;
2377 TRACE("iface %p, stream_idx %u, buffer %p, offset %p, stride %p.\n",
2378 iface, StreamNumber, pStream, OffsetInBytes, pStride);
2380 if(pStream == NULL){
2381 return D3DERR_INVALIDCALL;
2384 wined3d_mutex_lock();
2385 hr = IWineD3DDevice_GetStreamSource(This->WineD3DDevice, StreamNumber, &retStream, OffsetInBytes, pStride);
2386 if (SUCCEEDED(hr) && retStream)
2388 *pStream = wined3d_buffer_get_parent(retStream);
2389 IDirect3DVertexBuffer9_AddRef(*pStream);
2390 wined3d_buffer_decref(retStream);
2396 FIXME("Call to GetStreamSource failed %p %p\n", OffsetInBytes, pStride);
2400 wined3d_mutex_unlock();
2405 static HRESULT WINAPI IDirect3DDevice9Impl_SetStreamSourceFreq(IDirect3DDevice9Ex *iface, UINT StreamNumber,
2408 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2411 TRACE("iface %p, stream_idx %u, freq %u.\n", iface, StreamNumber, Divider);
2413 wined3d_mutex_lock();
2414 hr = IWineD3DDevice_SetStreamSourceFreq(This->WineD3DDevice, StreamNumber, Divider);
2415 wined3d_mutex_unlock();
2420 static HRESULT WINAPI IDirect3DDevice9Impl_GetStreamSourceFreq(LPDIRECT3DDEVICE9EX iface, UINT StreamNumber, UINT* Divider) {
2421 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2424 TRACE("iface %p, stream_idx %u, freq %p.\n", iface, StreamNumber, Divider);
2426 wined3d_mutex_lock();
2427 hr = IWineD3DDevice_GetStreamSourceFreq(This->WineD3DDevice, StreamNumber, Divider);
2428 wined3d_mutex_unlock();
2433 static HRESULT WINAPI IDirect3DDevice9Impl_SetIndices(LPDIRECT3DDEVICE9EX iface, IDirect3DIndexBuffer9* pIndexData) {
2434 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2436 IDirect3DIndexBuffer9Impl *ib = (IDirect3DIndexBuffer9Impl *) pIndexData;
2438 TRACE("iface %p, buffer %p.\n", iface, pIndexData);
2440 wined3d_mutex_lock();
2441 hr = IWineD3DDevice_SetIndexBuffer(This->WineD3DDevice,
2442 ib ? ib->wineD3DIndexBuffer : NULL,
2443 ib ? ib->format : WINED3DFMT_UNKNOWN);
2444 wined3d_mutex_unlock();
2449 static HRESULT WINAPI IDirect3DDevice9Impl_GetIndices(IDirect3DDevice9Ex *iface, IDirect3DIndexBuffer9 **ppIndexData)
2451 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2452 struct wined3d_buffer *retIndexData = NULL;
2455 TRACE("iface %p, buffer %p.\n", iface, ppIndexData);
2457 if(ppIndexData == NULL){
2458 return D3DERR_INVALIDCALL;
2461 wined3d_mutex_lock();
2462 hr = IWineD3DDevice_GetIndexBuffer(This->WineD3DDevice, &retIndexData);
2463 if (SUCCEEDED(hr) && retIndexData)
2465 *ppIndexData = wined3d_buffer_get_parent(retIndexData);
2466 IDirect3DIndexBuffer9_AddRef(*ppIndexData);
2467 wined3d_buffer_decref(retIndexData);
2471 if (FAILED(hr)) FIXME("Call to GetIndices failed\n");
2472 *ppIndexData = NULL;
2474 wined3d_mutex_unlock();
2479 static HRESULT WINAPI IDirect3DDevice9Impl_CreatePixelShader(IDirect3DDevice9Ex *iface,
2480 const DWORD *byte_code, IDirect3DPixelShader9 **shader)
2482 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2483 IDirect3DPixelShader9Impl *object;
2486 TRACE("iface %p, byte_code %p, shader %p.\n", iface, byte_code, shader);
2488 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2491 FIXME("Failed to allocate pixel shader memory.\n");
2492 return E_OUTOFMEMORY;
2495 hr = pixelshader_init(object, This, byte_code);
2498 WARN("Failed to initialize pixel shader, hr %#x.\n", hr);
2499 HeapFree(GetProcessHeap(), 0, object);
2503 TRACE("Created pixel shader %p.\n", object);
2504 *shader = (IDirect3DPixelShader9 *)object;
2509 static HRESULT WINAPI IDirect3DDevice9Impl_SetPixelShader(IDirect3DDevice9Ex *iface,
2510 IDirect3DPixelShader9 *shader)
2514 TRACE("iface %p, shader %p.\n", iface, shader);
2516 wined3d_mutex_lock();
2517 hr = IWineD3DDevice_SetPixelShader(((IDirect3DDevice9Impl *)iface)->WineD3DDevice,
2518 shader ? ((IDirect3DPixelShader9Impl *)shader)->wined3d_shader : NULL);
2519 wined3d_mutex_unlock();
2524 static HRESULT WINAPI IDirect3DDevice9Impl_GetPixelShader(IDirect3DDevice9Ex *iface,
2525 IDirect3DPixelShader9 **shader)
2527 struct wined3d_shader *wined3d_shader;
2529 TRACE("iface %p, shader %p.\n", iface, shader);
2531 if (!shader) return D3DERR_INVALIDCALL;
2533 wined3d_mutex_lock();
2534 wined3d_shader = IWineD3DDevice_GetPixelShader(((IDirect3DDevice9Impl *)iface)->WineD3DDevice);
2537 *shader = wined3d_shader_get_parent(wined3d_shader);
2538 IDirect3DPixelShader9_AddRef(*shader);
2539 wined3d_shader_decref(wined3d_shader);
2545 wined3d_mutex_unlock();
2547 TRACE("Returning %p.\n", *shader);
2552 static HRESULT WINAPI IDirect3DDevice9Impl_SetPixelShaderConstantF(IDirect3DDevice9Ex *iface,
2553 UINT reg_idx, const float *data, UINT count)
2557 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface, reg_idx, data, count);
2559 wined3d_mutex_lock();
2560 hr = IWineD3DDevice_SetPixelShaderConstantF(((IDirect3DDevice9Impl *)iface)->WineD3DDevice, reg_idx, data, count);
2561 wined3d_mutex_unlock();
2566 static HRESULT WINAPI IDirect3DDevice9Impl_GetPixelShaderConstantF(IDirect3DDevice9Ex *iface,
2567 UINT reg_idx, float *data, UINT count)
2571 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface, reg_idx, data, count);
2573 wined3d_mutex_lock();
2574 hr = IWineD3DDevice_GetPixelShaderConstantF(((IDirect3DDevice9Impl *)iface)->WineD3DDevice, reg_idx, data, count);
2575 wined3d_mutex_unlock();
2580 static HRESULT WINAPI IDirect3DDevice9Impl_SetPixelShaderConstantI(IDirect3DDevice9Ex *iface,
2581 UINT reg_idx, const int *data, UINT count)
2585 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface, reg_idx, data, count);
2587 wined3d_mutex_lock();
2588 hr = IWineD3DDevice_SetPixelShaderConstantI(((IDirect3DDevice9Impl *)iface)->WineD3DDevice, reg_idx, data, count);
2589 wined3d_mutex_unlock();
2594 static HRESULT WINAPI IDirect3DDevice9Impl_GetPixelShaderConstantI(IDirect3DDevice9Ex *iface,
2595 UINT reg_idx, int *data, UINT count)
2599 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface, reg_idx, data, count);
2601 wined3d_mutex_lock();
2602 hr = IWineD3DDevice_GetPixelShaderConstantI(((IDirect3DDevice9Impl *)iface)->WineD3DDevice, reg_idx, data, count);
2603 wined3d_mutex_unlock();
2608 static HRESULT WINAPI IDirect3DDevice9Impl_SetPixelShaderConstantB(IDirect3DDevice9Ex *iface,
2609 UINT reg_idx, const BOOL *data, UINT count)
2613 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface, reg_idx, data, count);
2615 wined3d_mutex_lock();
2616 hr = IWineD3DDevice_SetPixelShaderConstantB(((IDirect3DDevice9Impl *)iface)->WineD3DDevice, reg_idx, data, count);
2617 wined3d_mutex_unlock();
2622 static HRESULT WINAPI IDirect3DDevice9Impl_GetPixelShaderConstantB(IDirect3DDevice9Ex *iface,
2623 UINT reg_idx, BOOL *data, UINT count)
2627 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface, reg_idx, data, count);
2629 wined3d_mutex_lock();
2630 hr = IWineD3DDevice_GetPixelShaderConstantB(((IDirect3DDevice9Impl *)iface)->WineD3DDevice, reg_idx, data, count);
2631 wined3d_mutex_unlock();
2636 static HRESULT WINAPI IDirect3DDevice9Impl_DrawRectPatch(LPDIRECT3DDEVICE9EX iface, UINT Handle, CONST float* pNumSegs, CONST D3DRECTPATCH_INFO* pRectPatchInfo) {
2637 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2640 TRACE("iface %p, handle %#x, segment_count %p, patch_info %p.\n",
2641 iface, Handle, pNumSegs, pRectPatchInfo);
2643 wined3d_mutex_lock();
2644 hr = IWineD3DDevice_DrawRectPatch(This->WineD3DDevice, Handle, pNumSegs, (CONST WINED3DRECTPATCH_INFO *)pRectPatchInfo);
2645 wined3d_mutex_unlock();
2650 static HRESULT WINAPI IDirect3DDevice9Impl_DrawTriPatch(LPDIRECT3DDEVICE9EX iface, UINT Handle, CONST float* pNumSegs, CONST D3DTRIPATCH_INFO* pTriPatchInfo) {
2651 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2654 TRACE("iface %p, handle %#x, segment_count %p, patch_info %p.\n",
2655 iface, Handle, pNumSegs, pTriPatchInfo);
2657 wined3d_mutex_lock();
2658 hr = IWineD3DDevice_DrawTriPatch(This->WineD3DDevice, Handle, pNumSegs, (CONST WINED3DTRIPATCH_INFO *)pTriPatchInfo);
2659 wined3d_mutex_unlock();
2664 static HRESULT WINAPI IDirect3DDevice9Impl_DeletePatch(LPDIRECT3DDEVICE9EX iface, UINT Handle) {
2665 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2668 TRACE("iface %p, handle %#x.\n", iface, Handle);
2670 wined3d_mutex_lock();
2671 hr = IWineD3DDevice_DeletePatch(This->WineD3DDevice, Handle);
2672 wined3d_mutex_unlock();
2677 static HRESULT WINAPI IDirect3DDevice9Impl_CreateQuery(IDirect3DDevice9Ex *iface,
2678 D3DQUERYTYPE type, IDirect3DQuery9 **query)
2680 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2681 IDirect3DQuery9Impl *object;
2684 TRACE("iface %p, type %#x, query %p.\n", iface, type, query);
2686 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2689 ERR("Failed to allocate query memory.\n");
2690 return E_OUTOFMEMORY;
2693 hr = query_init(object, This, type);
2696 WARN("Failed to initialize query, hr %#x.\n", hr);
2697 HeapFree(GetProcessHeap(), 0, object);
2701 TRACE("Created query %p.\n", object);
2702 if (query) *query = &object->IDirect3DQuery9_iface;
2703 else IDirect3DQuery9_Release(&object->IDirect3DQuery9_iface);
2708 static HRESULT WINAPI IDirect3DDevice9ExImpl_SetConvolutionMonoKernel(IDirect3DDevice9Ex *iface,
2709 UINT width, UINT height, float *rows, float *columns)
2711 FIXME("iface %p, width %u, height %u, rows %p, columns %p stub!\n",
2712 iface, width, height, rows, columns);
2717 static HRESULT WINAPI IDirect3DDevice9ExImpl_ComposeRects(IDirect3DDevice9Ex *iface,
2718 IDirect3DSurface9 *src_surface, IDirect3DSurface9 *dst_surface, IDirect3DVertexBuffer9 *src_descs,
2719 UINT rect_count, IDirect3DVertexBuffer9 *dst_descs, D3DCOMPOSERECTSOP operation, INT offset_x, INT offset_y)
2721 FIXME("iface %p, src_surface %p, dst_surface %p, src_descs %p, rect_count %u,\n"
2722 "dst_descs %p, operation %#x, offset_x %u, offset_y %u stub!\n",
2723 iface, src_surface, dst_surface, src_descs, rect_count,
2724 dst_descs, operation, offset_x, offset_y);
2729 static HRESULT WINAPI IDirect3DDevice9ExImpl_PresentEx(IDirect3DDevice9Ex *iface,
2730 const RECT *src_rect, const RECT *dst_rect, HWND dst_window_override,
2731 const RGNDATA *dirty_region, DWORD flags)
2733 FIXME("iface %p, src_rect %p, dst_rect %p, dst_window_override %p, dirty_region %p, flags %#x stub!\n",
2734 iface, src_rect, dst_rect, dst_window_override, dirty_region, flags);
2739 static HRESULT WINAPI IDirect3DDevice9ExImpl_GetGPUThreadPriority(IDirect3DDevice9Ex *iface, INT *priority)
2741 FIXME("iface %p, priority %p stub!\n", iface, priority);
2746 static HRESULT WINAPI IDirect3DDevice9ExImpl_SetGPUThreadPriority(IDirect3DDevice9Ex *iface, INT priority)
2748 FIXME("iface %p, priority %d stub!\n", iface, priority);
2753 static HRESULT WINAPI IDirect3DDevice9ExImpl_WaitForVBlank(IDirect3DDevice9Ex *iface, UINT swapchain_idx)
2755 FIXME("iface %p, swapchain_idx %u stub!\n", iface, swapchain_idx);
2760 static HRESULT WINAPI IDirect3DDevice9ExImpl_CheckResourceResidency(IDirect3DDevice9Ex *iface,
2761 IDirect3DResource9 **resources, UINT32 resource_count)
2763 FIXME("iface %p, resources %p, resource_count %u stub!\n",
2764 iface, resources, resource_count);
2769 static HRESULT WINAPI IDirect3DDevice9ExImpl_SetMaximumFrameLatency(IDirect3DDevice9Ex *iface, UINT max_latency)
2771 FIXME("iface %p, max_latency %u stub!\n", iface, max_latency);
2776 static HRESULT WINAPI IDirect3DDevice9ExImpl_GetMaximumFrameLatency(IDirect3DDevice9Ex *iface, UINT *max_latency)
2778 FIXME("iface %p, max_latency %p stub!\n", iface, max_latency);
2785 static HRESULT WINAPI IDirect3DDevice9ExImpl_CheckDeviceState(IDirect3DDevice9Ex *iface, HWND dst_window)
2789 TRACE("iface %p, dst_window %p stub!\n", iface, dst_window);
2792 FIXME("iface %p, dst_window %p stub!\n", iface, dst_window);
2797 static HRESULT WINAPI IDirect3DDevice9ExImpl_CreateRenderTargetEx(IDirect3DDevice9Ex *iface,
2798 UINT width, UINT height, D3DFORMAT format, D3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality,
2799 BOOL lockable, IDirect3DSurface9 **surface, HANDLE *shared_handle, DWORD usage)
2801 FIXME("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u,\n"
2802 "lockable %#x, surface %p, shared_handle %p, usage %#x stub!\n",
2803 iface, width, height, format, multisample_type, multisample_quality,
2804 lockable, surface, shared_handle, usage);
2809 static HRESULT WINAPI IDirect3DDevice9ExImpl_CreateOffscreenPlainSurfaceEx(IDirect3DDevice9Ex *iface,
2810 UINT width, UINT height, D3DFORMAT format, D3DPOOL pool, IDirect3DSurface9 **surface,
2811 HANDLE *shared_handle, DWORD usage)
2813 FIXME("iface %p, width %u, height %u, format %#x, pool %#x, surface %p, shared_handle %p, usage %#x stub!\n",
2814 iface, width, height, format, pool, surface, shared_handle, usage);
2819 static HRESULT WINAPI IDirect3DDevice9ExImpl_CreateDepthStencilSurfaceEx(IDirect3DDevice9Ex *iface,
2820 UINT width, UINT height, D3DFORMAT format, D3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality,
2821 BOOL discard, IDirect3DSurface9 **surface, HANDLE *shared_handle, DWORD usage)
2823 FIXME("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u,\n"
2824 "discard %#x, surface %p, shared_handle %p, usage %#x stub!\n",
2825 iface, width, height, format, multisample_type, multisample_quality,
2826 discard, surface, shared_handle, usage);
2831 static HRESULT WINAPI IDirect3DDevice9ExImpl_ResetEx(IDirect3DDevice9Ex *iface,
2832 D3DPRESENT_PARAMETERS *present_parameters, D3DDISPLAYMODEEX *mode)
2834 FIXME("iface %p, present_parameters %p, mode %p stub!\n", iface, present_parameters, mode);
2839 static HRESULT WINAPI IDirect3DDevice9ExImpl_GetDisplayModeEx(IDirect3DDevice9Ex *iface,
2840 UINT swapchain_idx, D3DDISPLAYMODEEX *mode, D3DDISPLAYROTATION *rotation)
2842 FIXME("iface %p, swapchain_idx %u, mode %p, rotation %p stub!\n", iface, swapchain_idx, mode, rotation);
2847 static const IDirect3DDevice9ExVtbl Direct3DDevice9_Vtbl =
2850 IDirect3DDevice9Impl_QueryInterface,
2851 IDirect3DDevice9Impl_AddRef,
2852 IDirect3DDevice9Impl_Release,
2853 /* IDirect3DDevice9 */
2854 IDirect3DDevice9Impl_TestCooperativeLevel,
2855 IDirect3DDevice9Impl_GetAvailableTextureMem,
2856 IDirect3DDevice9Impl_EvictManagedResources,
2857 IDirect3DDevice9Impl_GetDirect3D,
2858 IDirect3DDevice9Impl_GetDeviceCaps,
2859 IDirect3DDevice9Impl_GetDisplayMode,
2860 IDirect3DDevice9Impl_GetCreationParameters,
2861 IDirect3DDevice9Impl_SetCursorProperties,
2862 IDirect3DDevice9Impl_SetCursorPosition,
2863 IDirect3DDevice9Impl_ShowCursor,
2864 IDirect3DDevice9Impl_CreateAdditionalSwapChain,
2865 IDirect3DDevice9Impl_GetSwapChain,
2866 IDirect3DDevice9Impl_GetNumberOfSwapChains,
2867 IDirect3DDevice9Impl_Reset,
2868 IDirect3DDevice9Impl_Present,
2869 IDirect3DDevice9Impl_GetBackBuffer,
2870 IDirect3DDevice9Impl_GetRasterStatus,
2871 IDirect3DDevice9Impl_SetDialogBoxMode,
2872 IDirect3DDevice9Impl_SetGammaRamp,
2873 IDirect3DDevice9Impl_GetGammaRamp,
2874 IDirect3DDevice9Impl_CreateTexture,
2875 IDirect3DDevice9Impl_CreateVolumeTexture,
2876 IDirect3DDevice9Impl_CreateCubeTexture,
2877 IDirect3DDevice9Impl_CreateVertexBuffer,
2878 IDirect3DDevice9Impl_CreateIndexBuffer,
2879 IDirect3DDevice9Impl_CreateRenderTarget,
2880 IDirect3DDevice9Impl_CreateDepthStencilSurface,
2881 IDirect3DDevice9Impl_UpdateSurface,
2882 IDirect3DDevice9Impl_UpdateTexture,
2883 IDirect3DDevice9Impl_GetRenderTargetData,
2884 IDirect3DDevice9Impl_GetFrontBufferData,
2885 IDirect3DDevice9Impl_StretchRect,
2886 IDirect3DDevice9Impl_ColorFill,
2887 IDirect3DDevice9Impl_CreateOffscreenPlainSurface,
2888 IDirect3DDevice9Impl_SetRenderTarget,
2889 IDirect3DDevice9Impl_GetRenderTarget,
2890 IDirect3DDevice9Impl_SetDepthStencilSurface,
2891 IDirect3DDevice9Impl_GetDepthStencilSurface,
2892 IDirect3DDevice9Impl_BeginScene,
2893 IDirect3DDevice9Impl_EndScene,
2894 IDirect3DDevice9Impl_Clear,
2895 IDirect3DDevice9Impl_SetTransform,
2896 IDirect3DDevice9Impl_GetTransform,
2897 IDirect3DDevice9Impl_MultiplyTransform,
2898 IDirect3DDevice9Impl_SetViewport,
2899 IDirect3DDevice9Impl_GetViewport,
2900 IDirect3DDevice9Impl_SetMaterial,
2901 IDirect3DDevice9Impl_GetMaterial,
2902 IDirect3DDevice9Impl_SetLight,
2903 IDirect3DDevice9Impl_GetLight,
2904 IDirect3DDevice9Impl_LightEnable,
2905 IDirect3DDevice9Impl_GetLightEnable,
2906 IDirect3DDevice9Impl_SetClipPlane,
2907 IDirect3DDevice9Impl_GetClipPlane,
2908 IDirect3DDevice9Impl_SetRenderState,
2909 IDirect3DDevice9Impl_GetRenderState,
2910 IDirect3DDevice9Impl_CreateStateBlock,
2911 IDirect3DDevice9Impl_BeginStateBlock,
2912 IDirect3DDevice9Impl_EndStateBlock,
2913 IDirect3DDevice9Impl_SetClipStatus,
2914 IDirect3DDevice9Impl_GetClipStatus,
2915 IDirect3DDevice9Impl_GetTexture,
2916 IDirect3DDevice9Impl_SetTexture,
2917 IDirect3DDevice9Impl_GetTextureStageState,
2918 IDirect3DDevice9Impl_SetTextureStageState,
2919 IDirect3DDevice9Impl_GetSamplerState,
2920 IDirect3DDevice9Impl_SetSamplerState,
2921 IDirect3DDevice9Impl_ValidateDevice,
2922 IDirect3DDevice9Impl_SetPaletteEntries,
2923 IDirect3DDevice9Impl_GetPaletteEntries,
2924 IDirect3DDevice9Impl_SetCurrentTexturePalette,
2925 IDirect3DDevice9Impl_GetCurrentTexturePalette,
2926 IDirect3DDevice9Impl_SetScissorRect,
2927 IDirect3DDevice9Impl_GetScissorRect,
2928 IDirect3DDevice9Impl_SetSoftwareVertexProcessing,
2929 IDirect3DDevice9Impl_GetSoftwareVertexProcessing,
2930 IDirect3DDevice9Impl_SetNPatchMode,
2931 IDirect3DDevice9Impl_GetNPatchMode,
2932 IDirect3DDevice9Impl_DrawPrimitive,
2933 IDirect3DDevice9Impl_DrawIndexedPrimitive,
2934 IDirect3DDevice9Impl_DrawPrimitiveUP,
2935 IDirect3DDevice9Impl_DrawIndexedPrimitiveUP,
2936 IDirect3DDevice9Impl_ProcessVertices,
2937 IDirect3DDevice9Impl_CreateVertexDeclaration,
2938 IDirect3DDevice9Impl_SetVertexDeclaration,
2939 IDirect3DDevice9Impl_GetVertexDeclaration,
2940 IDirect3DDevice9Impl_SetFVF,
2941 IDirect3DDevice9Impl_GetFVF,
2942 IDirect3DDevice9Impl_CreateVertexShader,
2943 IDirect3DDevice9Impl_SetVertexShader,
2944 IDirect3DDevice9Impl_GetVertexShader,
2945 IDirect3DDevice9Impl_SetVertexShaderConstantF,
2946 IDirect3DDevice9Impl_GetVertexShaderConstantF,
2947 IDirect3DDevice9Impl_SetVertexShaderConstantI,
2948 IDirect3DDevice9Impl_GetVertexShaderConstantI,
2949 IDirect3DDevice9Impl_SetVertexShaderConstantB,
2950 IDirect3DDevice9Impl_GetVertexShaderConstantB,
2951 IDirect3DDevice9Impl_SetStreamSource,
2952 IDirect3DDevice9Impl_GetStreamSource,
2953 IDirect3DDevice9Impl_SetStreamSourceFreq,
2954 IDirect3DDevice9Impl_GetStreamSourceFreq,
2955 IDirect3DDevice9Impl_SetIndices,
2956 IDirect3DDevice9Impl_GetIndices,
2957 IDirect3DDevice9Impl_CreatePixelShader,
2958 IDirect3DDevice9Impl_SetPixelShader,
2959 IDirect3DDevice9Impl_GetPixelShader,
2960 IDirect3DDevice9Impl_SetPixelShaderConstantF,
2961 IDirect3DDevice9Impl_GetPixelShaderConstantF,
2962 IDirect3DDevice9Impl_SetPixelShaderConstantI,
2963 IDirect3DDevice9Impl_GetPixelShaderConstantI,
2964 IDirect3DDevice9Impl_SetPixelShaderConstantB,
2965 IDirect3DDevice9Impl_GetPixelShaderConstantB,
2966 IDirect3DDevice9Impl_DrawRectPatch,
2967 IDirect3DDevice9Impl_DrawTriPatch,
2968 IDirect3DDevice9Impl_DeletePatch,
2969 IDirect3DDevice9Impl_CreateQuery,
2970 /* IDirect3DDevice9Ex */
2971 IDirect3DDevice9ExImpl_SetConvolutionMonoKernel,
2972 IDirect3DDevice9ExImpl_ComposeRects,
2973 IDirect3DDevice9ExImpl_PresentEx,
2974 IDirect3DDevice9ExImpl_GetGPUThreadPriority,
2975 IDirect3DDevice9ExImpl_SetGPUThreadPriority,
2976 IDirect3DDevice9ExImpl_WaitForVBlank,
2977 IDirect3DDevice9ExImpl_CheckResourceResidency,
2978 IDirect3DDevice9ExImpl_SetMaximumFrameLatency,
2979 IDirect3DDevice9ExImpl_GetMaximumFrameLatency,
2980 IDirect3DDevice9ExImpl_CheckDeviceState,
2981 IDirect3DDevice9ExImpl_CreateRenderTargetEx,
2982 IDirect3DDevice9ExImpl_CreateOffscreenPlainSurfaceEx,
2983 IDirect3DDevice9ExImpl_CreateDepthStencilSurfaceEx,
2984 IDirect3DDevice9ExImpl_ResetEx,
2985 IDirect3DDevice9ExImpl_GetDisplayModeEx
2988 /* IWineD3DDeviceParent IUnknown methods */
2990 static inline struct IDirect3DDevice9Impl *device_from_device_parent(IWineD3DDeviceParent *iface)
2992 return (struct IDirect3DDevice9Impl *)((char*)iface
2993 - FIELD_OFFSET(struct IDirect3DDevice9Impl, device_parent_vtbl));
2996 static HRESULT STDMETHODCALLTYPE device_parent_QueryInterface(IWineD3DDeviceParent *iface, REFIID riid, void **object)
2998 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
2999 return IDirect3DDevice9Impl_QueryInterface((IDirect3DDevice9Ex *)This, riid, object);
3002 static ULONG STDMETHODCALLTYPE device_parent_AddRef(IWineD3DDeviceParent *iface)
3004 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
3005 return IDirect3DDevice9Impl_AddRef((IDirect3DDevice9Ex *)This);
3008 static ULONG STDMETHODCALLTYPE device_parent_Release(IWineD3DDeviceParent *iface)
3010 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
3011 return IDirect3DDevice9Impl_Release((IDirect3DDevice9Ex *)This);
3014 /* IWineD3DDeviceParent methods */
3016 static void STDMETHODCALLTYPE device_parent_WineD3DDeviceCreated(IWineD3DDeviceParent *iface, IWineD3DDevice *device)
3018 TRACE("iface %p, device %p\n", iface, device);
3021 static HRESULT STDMETHODCALLTYPE device_parent_CreateSurface(IWineD3DDeviceParent *iface,
3022 void *container_parent, UINT width, UINT height, enum wined3d_format_id format, DWORD usage,
3023 WINED3DPOOL pool, UINT level, WINED3DCUBEMAP_FACES face, IWineD3DSurface **surface)
3025 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
3026 IDirect3DSurface9Impl *d3d_surface;
3027 BOOL lockable = TRUE;
3030 TRACE("iface %p, container_parent %p, width %u, height %u, format %#x, usage %#x,\n"
3031 "\tpool %#x, level %u, face %u, surface %p\n",
3032 iface, container_parent, width, height, format, usage, pool, level, face, surface);
3034 if (pool == WINED3DPOOL_DEFAULT && !(usage & D3DUSAGE_DYNAMIC))
3037 hr = IDirect3DDevice9Impl_CreateSurface((IDirect3DDevice9Ex *)This, width, height,
3038 d3dformat_from_wined3dformat(format), lockable, FALSE /* Discard */, level,
3039 (IDirect3DSurface9 **)&d3d_surface, usage, pool, D3DMULTISAMPLE_NONE, 0 /* MultisampleQuality */);
3042 ERR("(%p) CreateSurface failed, returning %#x\n", iface, hr);
3046 *surface = d3d_surface->wineD3DSurface;
3047 IWineD3DSurface_AddRef(*surface);
3049 d3d_surface->container = container_parent;
3050 IDirect3DDevice9Ex_Release(d3d_surface->parentDevice);
3051 d3d_surface->parentDevice = NULL;
3053 IDirect3DSurface9_Release((IDirect3DSurface9 *)d3d_surface);
3054 d3d_surface->forwardReference = container_parent;
3059 static HRESULT STDMETHODCALLTYPE device_parent_CreateRenderTarget(IWineD3DDeviceParent *iface,
3060 void *container_parent, UINT width, UINT height, enum wined3d_format_id format,
3061 WINED3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality, BOOL lockable,
3062 IWineD3DSurface **surface)
3064 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
3065 IDirect3DSurface9Impl *d3d_surface;
3068 TRACE("iface %p, container_parent %p, width %u, height %u, format %#x, multisample_type %#x,\n"
3069 "\tmultisample_quality %u, lockable %u, surface %p\n",
3070 iface, container_parent, width, height, format, multisample_type, multisample_quality, lockable, surface);
3072 hr = IDirect3DDevice9Impl_CreateRenderTarget((IDirect3DDevice9Ex *)This, width, height,
3073 d3dformat_from_wined3dformat(format), multisample_type, multisample_quality, lockable,
3074 (IDirect3DSurface9 **)&d3d_surface, NULL);
3077 ERR("(%p) CreateRenderTarget failed, returning %#x\n", iface, hr);
3081 *surface = d3d_surface->wineD3DSurface;
3082 IWineD3DSurface_AddRef(*surface);
3084 d3d_surface->container = container_parent;
3085 /* Implicit surfaces are created with an refcount of 0 */
3086 IDirect3DSurface9_Release((IDirect3DSurface9 *)d3d_surface);
3091 static HRESULT STDMETHODCALLTYPE device_parent_CreateDepthStencilSurface(IWineD3DDeviceParent *iface,
3092 UINT width, UINT height, enum wined3d_format_id format, WINED3DMULTISAMPLE_TYPE multisample_type,
3093 DWORD multisample_quality, BOOL discard, IWineD3DSurface **surface)
3095 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
3096 IDirect3DSurface9Impl *d3d_surface;
3099 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x,\n"
3100 "\tmultisample_quality %u, discard %u, surface %p\n",
3101 iface, width, height, format, multisample_type, multisample_quality, discard, surface);
3103 hr = IDirect3DDevice9Impl_CreateDepthStencilSurface((IDirect3DDevice9Ex *)This, width, height,
3104 d3dformat_from_wined3dformat(format), multisample_type, multisample_quality, discard,
3105 (IDirect3DSurface9 **)&d3d_surface, NULL);
3108 ERR("(%p) CreateDepthStencilSurface failed, returning %#x\n", iface, hr);
3112 *surface = d3d_surface->wineD3DSurface;
3113 IWineD3DSurface_AddRef(*surface);
3114 d3d_surface->container = (IUnknown *)This;
3115 /* Implicit surfaces are created with an refcount of 0 */
3116 IDirect3DSurface9_Release((IDirect3DSurface9 *)d3d_surface);
3121 static HRESULT STDMETHODCALLTYPE device_parent_CreateVolume(IWineD3DDeviceParent *iface,
3122 void *container_parent, UINT width, UINT height, UINT depth, enum wined3d_format_id format,
3123 WINED3DPOOL pool, DWORD usage, struct wined3d_volume **volume)
3125 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
3126 IDirect3DVolume9Impl *object;
3129 TRACE("iface %p, container_parent %p, width %u, height %u, depth %u, format %#x, pool %#x, usage %#x, volume %p\n",
3130 iface, container_parent, width, height, depth, format, pool, usage, volume);
3132 /* Allocate the storage for the device */
3133 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
3136 FIXME("Allocation of memory failed\n");
3138 return D3DERR_OUTOFVIDEOMEMORY;
3141 hr = volume_init(object, This, width, height, depth, usage, format, pool);
3144 WARN("Failed to initialize volume, hr %#x.\n", hr);
3145 HeapFree(GetProcessHeap(), 0, object);
3149 *volume = object->wined3d_volume;
3150 wined3d_volume_incref(*volume);
3151 IDirect3DVolume9_Release(&object->IDirect3DVolume9_iface);
3153 object->container = container_parent;
3154 object->forwardReference = container_parent;
3156 TRACE("(%p) Created volume %p\n", iface, object);
3161 static HRESULT STDMETHODCALLTYPE device_parent_CreateSwapChain(IWineD3DDeviceParent *iface,
3162 WINED3DPRESENT_PARAMETERS *present_parameters, struct wined3d_swapchain **swapchain)
3164 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
3165 D3DPRESENT_PARAMETERS local_parameters;
3166 IDirect3DSwapChain9 *d3d_swapchain;
3169 TRACE("iface %p, present_parameters %p, swapchain %p\n", iface, present_parameters, swapchain);
3171 /* Copy the presentation parameters */
3172 local_parameters.BackBufferWidth = present_parameters->BackBufferWidth;
3173 local_parameters.BackBufferHeight = present_parameters->BackBufferHeight;
3174 local_parameters.BackBufferFormat = d3dformat_from_wined3dformat(present_parameters->BackBufferFormat);
3175 local_parameters.BackBufferCount = present_parameters->BackBufferCount;
3176 local_parameters.MultiSampleType = present_parameters->MultiSampleType;
3177 local_parameters.MultiSampleQuality = present_parameters->MultiSampleQuality;
3178 local_parameters.SwapEffect = present_parameters->SwapEffect;
3179 local_parameters.hDeviceWindow = present_parameters->hDeviceWindow;
3180 local_parameters.Windowed = present_parameters->Windowed;
3181 local_parameters.EnableAutoDepthStencil = present_parameters->EnableAutoDepthStencil;
3182 local_parameters.AutoDepthStencilFormat = d3dformat_from_wined3dformat(present_parameters->AutoDepthStencilFormat);
3183 local_parameters.Flags = present_parameters->Flags;
3184 local_parameters.FullScreen_RefreshRateInHz = present_parameters->FullScreen_RefreshRateInHz;
3185 local_parameters.PresentationInterval = present_parameters->PresentationInterval;
3187 hr = IDirect3DDevice9Impl_CreateAdditionalSwapChain((IDirect3DDevice9Ex *)This,
3188 &local_parameters, &d3d_swapchain);
3191 ERR("(%p) CreateAdditionalSwapChain failed, returning %#x\n", iface, hr);
3196 *swapchain = ((IDirect3DSwapChain9Impl *)d3d_swapchain)->wined3d_swapchain;
3197 wined3d_swapchain_incref(*swapchain);
3198 IDirect3DSwapChain9_Release((IDirect3DSwapChain9 *)d3d_swapchain);
3200 /* Copy back the presentation parameters */
3201 present_parameters->BackBufferWidth = local_parameters.BackBufferWidth;
3202 present_parameters->BackBufferHeight = local_parameters.BackBufferHeight;
3203 present_parameters->BackBufferFormat = wined3dformat_from_d3dformat(local_parameters.BackBufferFormat);
3204 present_parameters->BackBufferCount = local_parameters.BackBufferCount;
3205 present_parameters->MultiSampleType = local_parameters.MultiSampleType;
3206 present_parameters->MultiSampleQuality = local_parameters.MultiSampleQuality;
3207 present_parameters->SwapEffect = local_parameters.SwapEffect;
3208 present_parameters->hDeviceWindow = local_parameters.hDeviceWindow;
3209 present_parameters->Windowed = local_parameters.Windowed;
3210 present_parameters->EnableAutoDepthStencil = local_parameters.EnableAutoDepthStencil;
3211 present_parameters->AutoDepthStencilFormat = wined3dformat_from_d3dformat(local_parameters.AutoDepthStencilFormat);
3212 present_parameters->Flags = local_parameters.Flags;
3213 present_parameters->FullScreen_RefreshRateInHz = local_parameters.FullScreen_RefreshRateInHz;
3214 present_parameters->PresentationInterval = local_parameters.PresentationInterval;
3219 static const IWineD3DDeviceParentVtbl d3d9_wined3d_device_parent_vtbl =
3221 /* IUnknown methods */
3222 device_parent_QueryInterface,
3223 device_parent_AddRef,
3224 device_parent_Release,
3225 /* IWineD3DDeviceParent methods */
3226 device_parent_WineD3DDeviceCreated,
3227 device_parent_CreateSurface,
3228 device_parent_CreateRenderTarget,
3229 device_parent_CreateDepthStencilSurface,
3230 device_parent_CreateVolume,
3231 device_parent_CreateSwapChain,
3234 static void setup_fpu(void)
3236 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
3238 __asm__ volatile ("fnstcw %0" : "=m" (cw));
3239 cw = (cw & ~0xf3f) | 0x3f;
3240 __asm__ volatile ("fldcw %0" : : "m" (cw));
3242 FIXME("FPU setup not implemented for this platform.\n");
3246 HRESULT device_init(IDirect3DDevice9Impl *device, struct wined3d *wined3d, UINT adapter, D3DDEVTYPE device_type,
3247 HWND focus_window, DWORD flags, D3DPRESENT_PARAMETERS *parameters, D3DDISPLAYMODEEX *mode)
3249 WINED3DPRESENT_PARAMETERS *wined3d_parameters;
3254 FIXME("Ignoring display mode.\n");
3256 device->lpVtbl = &Direct3DDevice9_Vtbl;
3257 device->device_parent_vtbl = &d3d9_wined3d_device_parent_vtbl;
3260 if (!(flags & D3DCREATE_FPU_PRESERVE)) setup_fpu();
3262 wined3d_mutex_lock();
3263 hr = wined3d_device_create(wined3d, adapter, device_type, focus_window, flags,
3264 (IWineD3DDeviceParent *)&device->device_parent_vtbl, &device->WineD3DDevice);
3267 WARN("Failed to create wined3d device, hr %#x.\n", hr);
3268 wined3d_mutex_unlock();
3272 if (flags & D3DCREATE_ADAPTERGROUP_DEVICE)
3276 wined3d_get_device_caps(wined3d, adapter, device_type, &caps);
3277 count = caps.NumberOfAdaptersInGroup;
3280 if (flags & D3DCREATE_MULTITHREADED) IWineD3DDevice_SetMultithreaded(device->WineD3DDevice);
3282 if (!parameters->Windowed)
3284 if (!focus_window) focus_window = parameters->hDeviceWindow;
3285 if (FAILED(hr = IWineD3DDevice_AcquireFocusWindow(device->WineD3DDevice, focus_window)))
3287 ERR("Failed to acquire focus window, hr %#x.\n", hr);
3288 IWineD3DDevice_Release(device->WineD3DDevice);
3289 wined3d_mutex_unlock();
3293 for (i = 0; i < count; ++i)
3295 HWND device_window = parameters[i].hDeviceWindow;
3297 if (!device_window) device_window = focus_window;
3298 IWineD3DDevice_SetupFullscreenWindow(device->WineD3DDevice, device_window,
3299 parameters[i].BackBufferWidth,
3300 parameters[i].BackBufferHeight);
3304 wined3d_parameters = HeapAlloc(GetProcessHeap(), 0, sizeof(*wined3d_parameters) * count);
3305 if (!wined3d_parameters)
3307 ERR("Failed to allocate wined3d parameters.\n");
3308 IWineD3DDevice_Release(device->WineD3DDevice);
3309 wined3d_mutex_unlock();
3310 return E_OUTOFMEMORY;
3313 for (i = 0; i < count; ++i)
3315 wined3d_parameters[i].BackBufferWidth = parameters[i].BackBufferWidth;
3316 wined3d_parameters[i].BackBufferHeight = parameters[i].BackBufferHeight;
3317 wined3d_parameters[i].BackBufferFormat = wined3dformat_from_d3dformat(parameters[i].BackBufferFormat);
3318 wined3d_parameters[i].BackBufferCount = parameters[i].BackBufferCount;
3319 wined3d_parameters[i].MultiSampleType = parameters[i].MultiSampleType;
3320 wined3d_parameters[i].MultiSampleQuality = parameters[i].MultiSampleQuality;
3321 wined3d_parameters[i].SwapEffect = parameters[i].SwapEffect;
3322 wined3d_parameters[i].hDeviceWindow = parameters[i].hDeviceWindow;
3323 wined3d_parameters[i].Windowed = parameters[i].Windowed;
3324 wined3d_parameters[i].EnableAutoDepthStencil = parameters[i].EnableAutoDepthStencil;
3325 wined3d_parameters[i].AutoDepthStencilFormat =
3326 wined3dformat_from_d3dformat(parameters[i].AutoDepthStencilFormat);
3327 wined3d_parameters[i].Flags = parameters[i].Flags;
3328 wined3d_parameters[i].FullScreen_RefreshRateInHz = parameters[i].FullScreen_RefreshRateInHz;
3329 wined3d_parameters[i].PresentationInterval = parameters[i].PresentationInterval;
3330 wined3d_parameters[i].AutoRestoreDisplayMode = TRUE;
3333 hr = IWineD3DDevice_Init3D(device->WineD3DDevice, wined3d_parameters);
3336 WARN("Failed to initialize 3D, hr %#x.\n", hr);
3337 IWineD3DDevice_ReleaseFocusWindow(device->WineD3DDevice);
3338 HeapFree(GetProcessHeap(), 0, wined3d_parameters);
3339 IWineD3DDevice_Release(device->WineD3DDevice);
3340 wined3d_mutex_unlock();
3344 wined3d_mutex_unlock();
3346 for (i = 0; i < count; ++i)
3348 parameters[i].BackBufferWidth = wined3d_parameters[i].BackBufferWidth;
3349 parameters[i].BackBufferHeight = wined3d_parameters[i].BackBufferHeight;
3350 parameters[i].BackBufferFormat = d3dformat_from_wined3dformat(wined3d_parameters[i].BackBufferFormat);
3351 parameters[i].BackBufferCount = wined3d_parameters[i].BackBufferCount;
3352 parameters[i].MultiSampleType = wined3d_parameters[i].MultiSampleType;
3353 parameters[i].MultiSampleQuality = wined3d_parameters[i].MultiSampleQuality;
3354 parameters[i].SwapEffect = wined3d_parameters[i].SwapEffect;
3355 parameters[i].hDeviceWindow = wined3d_parameters[i].hDeviceWindow;
3356 parameters[i].Windowed = wined3d_parameters[i].Windowed;
3357 parameters[i].EnableAutoDepthStencil = wined3d_parameters[i].EnableAutoDepthStencil;
3358 parameters[i].AutoDepthStencilFormat =
3359 d3dformat_from_wined3dformat(wined3d_parameters[i].AutoDepthStencilFormat);
3360 parameters[i].Flags = wined3d_parameters[i].Flags;
3361 parameters[i].FullScreen_RefreshRateInHz = wined3d_parameters[i].FullScreen_RefreshRateInHz;
3362 parameters[i].PresentationInterval = wined3d_parameters[i].PresentationInterval;
3364 HeapFree(GetProcessHeap(), 0, wined3d_parameters);
3366 /* Initialize the converted declaration array. This creates a valid pointer
3367 * and when adding decls HeapReAlloc() can be used without further checking. */
3368 device->convertedDecls = HeapAlloc(GetProcessHeap(), 0, 0);
3369 if (!device->convertedDecls)
3371 ERR("Failed to allocate FVF vertex declaration map memory.\n");
3372 wined3d_mutex_lock();
3373 IWineD3DDevice_Uninit3D(device->WineD3DDevice);
3374 IWineD3DDevice_ReleaseFocusWindow(device->WineD3DDevice);
3375 IWineD3DDevice_Release(device->WineD3DDevice);
3376 wined3d_mutex_unlock();
3377 return E_OUTOFMEMORY;