2 * IDirect3DDevice9 implementation
4 * Copyright 2002-2005 Jason Edmeades
5 * Copyright 2002-2005 Raphael Junqueira
6 * Copyright 2005 Oliver Stieber
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "d3d9_private.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
28 D3DFORMAT d3dformat_from_wined3dformat(enum wined3d_format_id format)
30 BYTE *c = (BYTE *)&format;
32 /* Don't translate FOURCC formats */
33 if (isprint(c[0]) && isprint(c[1]) && isprint(c[2]) && isprint(c[3])) return format;
37 case WINED3DFMT_UNKNOWN: return D3DFMT_UNKNOWN;
38 case WINED3DFMT_B8G8R8_UNORM: return D3DFMT_R8G8B8;
39 case WINED3DFMT_B8G8R8A8_UNORM: return D3DFMT_A8R8G8B8;
40 case WINED3DFMT_B8G8R8X8_UNORM: return D3DFMT_X8R8G8B8;
41 case WINED3DFMT_B5G6R5_UNORM: return D3DFMT_R5G6B5;
42 case WINED3DFMT_B5G5R5X1_UNORM: return D3DFMT_X1R5G5B5;
43 case WINED3DFMT_B5G5R5A1_UNORM: return D3DFMT_A1R5G5B5;
44 case WINED3DFMT_B4G4R4A4_UNORM: return D3DFMT_A4R4G4B4;
45 case WINED3DFMT_B2G3R3_UNORM: return D3DFMT_R3G3B2;
46 case WINED3DFMT_A8_UNORM: return D3DFMT_A8;
47 case WINED3DFMT_B2G3R3A8_UNORM: return D3DFMT_A8R3G3B2;
48 case WINED3DFMT_B4G4R4X4_UNORM: return D3DFMT_X4R4G4B4;
49 case WINED3DFMT_R10G10B10A2_UNORM: return D3DFMT_A2B10G10R10;
50 case WINED3DFMT_R8G8B8A8_UNORM: return D3DFMT_A8B8G8R8;
51 case WINED3DFMT_R8G8B8X8_UNORM: return D3DFMT_X8B8G8R8;
52 case WINED3DFMT_R16G16_UNORM: return D3DFMT_G16R16;
53 case WINED3DFMT_B10G10R10A2_UNORM: return D3DFMT_A2R10G10B10;
54 case WINED3DFMT_R16G16B16A16_UNORM: return D3DFMT_A16B16G16R16;
55 case WINED3DFMT_P8_UINT_A8_UNORM: return D3DFMT_A8P8;
56 case WINED3DFMT_P8_UINT: return D3DFMT_P8;
57 case WINED3DFMT_L8_UNORM: return D3DFMT_L8;
58 case WINED3DFMT_L8A8_UNORM: return D3DFMT_A8L8;
59 case WINED3DFMT_L4A4_UNORM: return D3DFMT_A4L4;
60 case WINED3DFMT_R8G8_SNORM: return D3DFMT_V8U8;
61 case WINED3DFMT_R5G5_SNORM_L6_UNORM: return D3DFMT_L6V5U5;
62 case WINED3DFMT_R8G8_SNORM_L8X8_UNORM: return D3DFMT_X8L8V8U8;
63 case WINED3DFMT_R8G8B8A8_SNORM: return D3DFMT_Q8W8V8U8;
64 case WINED3DFMT_R16G16_SNORM: return D3DFMT_V16U16;
65 case WINED3DFMT_R10G10B10_SNORM_A2_UNORM: return D3DFMT_A2W10V10U10;
66 case WINED3DFMT_D16_LOCKABLE: return D3DFMT_D16_LOCKABLE;
67 case WINED3DFMT_D32_UNORM: return D3DFMT_D32;
68 case WINED3DFMT_S1_UINT_D15_UNORM: return D3DFMT_D15S1;
69 case WINED3DFMT_D24_UNORM_S8_UINT: return D3DFMT_D24S8;
70 case WINED3DFMT_X8D24_UNORM: return D3DFMT_D24X8;
71 case WINED3DFMT_S4X4_UINT_D24_UNORM: return D3DFMT_D24X4S4;
72 case WINED3DFMT_D16_UNORM: return D3DFMT_D16;
73 case WINED3DFMT_L16_UNORM: return D3DFMT_L16;
74 case WINED3DFMT_D32_FLOAT: return D3DFMT_D32F_LOCKABLE;
75 case WINED3DFMT_S8_UINT_D24_FLOAT: return D3DFMT_D24FS8;
76 case WINED3DFMT_VERTEXDATA: return D3DFMT_VERTEXDATA;
77 case WINED3DFMT_R16_UINT: return D3DFMT_INDEX16;
78 case WINED3DFMT_R32_UINT: return D3DFMT_INDEX32;
79 case WINED3DFMT_R16G16B16A16_SNORM: return D3DFMT_Q16W16V16U16;
80 case WINED3DFMT_R16_FLOAT: return D3DFMT_R16F;
81 case WINED3DFMT_R16G16_FLOAT: return D3DFMT_G16R16F;
82 case WINED3DFMT_R16G16B16A16_FLOAT: return D3DFMT_A16B16G16R16F;
83 case WINED3DFMT_R32_FLOAT: return D3DFMT_R32F;
84 case WINED3DFMT_R32G32_FLOAT: return D3DFMT_G32R32F;
85 case WINED3DFMT_R32G32B32A32_FLOAT: return D3DFMT_A32B32G32R32F;
86 case WINED3DFMT_R8G8_SNORM_Cx: return D3DFMT_CxV8U8;
88 FIXME("Unhandled wined3d format %#x.\n", format);
89 return D3DFMT_UNKNOWN;
93 enum wined3d_format_id wined3dformat_from_d3dformat(D3DFORMAT format)
95 BYTE *c = (BYTE *)&format;
97 /* Don't translate FOURCC formats */
98 if (isprint(c[0]) && isprint(c[1]) && isprint(c[2]) && isprint(c[3])) return format;
102 case D3DFMT_UNKNOWN: return WINED3DFMT_UNKNOWN;
103 case D3DFMT_R8G8B8: return WINED3DFMT_B8G8R8_UNORM;
104 case D3DFMT_A8R8G8B8: return WINED3DFMT_B8G8R8A8_UNORM;
105 case D3DFMT_X8R8G8B8: return WINED3DFMT_B8G8R8X8_UNORM;
106 case D3DFMT_R5G6B5: return WINED3DFMT_B5G6R5_UNORM;
107 case D3DFMT_X1R5G5B5: return WINED3DFMT_B5G5R5X1_UNORM;
108 case D3DFMT_A1R5G5B5: return WINED3DFMT_B5G5R5A1_UNORM;
109 case D3DFMT_A4R4G4B4: return WINED3DFMT_B4G4R4A4_UNORM;
110 case D3DFMT_R3G3B2: return WINED3DFMT_B2G3R3_UNORM;
111 case D3DFMT_A8: return WINED3DFMT_A8_UNORM;
112 case D3DFMT_A8R3G3B2: return WINED3DFMT_B2G3R3A8_UNORM;
113 case D3DFMT_X4R4G4B4: return WINED3DFMT_B4G4R4X4_UNORM;
114 case D3DFMT_A2B10G10R10: return WINED3DFMT_R10G10B10A2_UNORM;
115 case D3DFMT_A8B8G8R8: return WINED3DFMT_R8G8B8A8_UNORM;
116 case D3DFMT_X8B8G8R8: return WINED3DFMT_R8G8B8X8_UNORM;
117 case D3DFMT_G16R16: return WINED3DFMT_R16G16_UNORM;
118 case D3DFMT_A2R10G10B10: return WINED3DFMT_B10G10R10A2_UNORM;
119 case D3DFMT_A16B16G16R16: return WINED3DFMT_R16G16B16A16_UNORM;
120 case D3DFMT_A8P8: return WINED3DFMT_P8_UINT_A8_UNORM;
121 case D3DFMT_P8: return WINED3DFMT_P8_UINT;
122 case D3DFMT_L8: return WINED3DFMT_L8_UNORM;
123 case D3DFMT_A8L8: return WINED3DFMT_L8A8_UNORM;
124 case D3DFMT_A4L4: return WINED3DFMT_L4A4_UNORM;
125 case D3DFMT_V8U8: return WINED3DFMT_R8G8_SNORM;
126 case D3DFMT_L6V5U5: return WINED3DFMT_R5G5_SNORM_L6_UNORM;
127 case D3DFMT_X8L8V8U8: return WINED3DFMT_R8G8_SNORM_L8X8_UNORM;
128 case D3DFMT_Q8W8V8U8: return WINED3DFMT_R8G8B8A8_SNORM;
129 case D3DFMT_V16U16: return WINED3DFMT_R16G16_SNORM;
130 case D3DFMT_A2W10V10U10: return WINED3DFMT_R10G10B10_SNORM_A2_UNORM;
131 case D3DFMT_D16_LOCKABLE: return WINED3DFMT_D16_LOCKABLE;
132 case D3DFMT_D32: return WINED3DFMT_D32_UNORM;
133 case D3DFMT_D15S1: return WINED3DFMT_S1_UINT_D15_UNORM;
134 case D3DFMT_D24S8: return WINED3DFMT_D24_UNORM_S8_UINT;
135 case D3DFMT_D24X8: return WINED3DFMT_X8D24_UNORM;
136 case D3DFMT_D24X4S4: return WINED3DFMT_S4X4_UINT_D24_UNORM;
137 case D3DFMT_D16: return WINED3DFMT_D16_UNORM;
138 case D3DFMT_L16: return WINED3DFMT_L16_UNORM;
139 case D3DFMT_D32F_LOCKABLE: return WINED3DFMT_D32_FLOAT;
140 case D3DFMT_D24FS8: return WINED3DFMT_S8_UINT_D24_FLOAT;
141 case D3DFMT_VERTEXDATA: return WINED3DFMT_VERTEXDATA;
142 case D3DFMT_INDEX16: return WINED3DFMT_R16_UINT;
143 case D3DFMT_INDEX32: return WINED3DFMT_R32_UINT;
144 case D3DFMT_Q16W16V16U16: return WINED3DFMT_R16G16B16A16_SNORM;
145 case D3DFMT_R16F: return WINED3DFMT_R16_FLOAT;
146 case D3DFMT_G16R16F: return WINED3DFMT_R16G16_FLOAT;
147 case D3DFMT_A16B16G16R16F: return WINED3DFMT_R16G16B16A16_FLOAT;
148 case D3DFMT_R32F: return WINED3DFMT_R32_FLOAT;
149 case D3DFMT_G32R32F: return WINED3DFMT_R32G32_FLOAT;
150 case D3DFMT_A32B32G32R32F: return WINED3DFMT_R32G32B32A32_FLOAT;
151 case D3DFMT_CxV8U8: return WINED3DFMT_R8G8_SNORM_Cx;
153 FIXME("Unhandled D3DFORMAT %#x\n", format);
154 return WINED3DFMT_UNKNOWN;
158 static UINT vertex_count_from_primitive_count(D3DPRIMITIVETYPE primitive_type, UINT primitive_count)
160 switch(primitive_type)
162 case D3DPT_POINTLIST:
163 return primitive_count;
166 return primitive_count * 2;
168 case D3DPT_LINESTRIP:
169 return primitive_count + 1;
171 case D3DPT_TRIANGLELIST:
172 return primitive_count * 3;
174 case D3DPT_TRIANGLESTRIP:
175 case D3DPT_TRIANGLEFAN:
176 return primitive_count + 2;
179 FIXME("Unhandled primitive type %#x\n", primitive_type);
184 static ULONG WINAPI D3D9CB_DestroySwapChain(IWineD3DSwapChain *swapchain)
186 IDirect3DSwapChain9Impl *parent;
188 TRACE("swapchain %p.\n", swapchain);
190 IWineD3DSwapChain_GetParent(swapchain, (IUnknown **)&parent);
191 parent->isImplicit = FALSE;
192 return IDirect3DSwapChain9_Release((IDirect3DSwapChain9 *)parent);
195 /* IDirect3D IUnknown parts follow: */
196 static HRESULT WINAPI IDirect3DDevice9Impl_QueryInterface(LPDIRECT3DDEVICE9EX iface, REFIID riid, LPVOID* ppobj) {
197 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
199 IDirect3D9Impl *d3dimpl;
201 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
203 if (IsEqualGUID(riid, &IID_IUnknown)
204 || IsEqualGUID(riid, &IID_IDirect3DDevice9)) {
205 IDirect3DDevice9Ex_AddRef(iface);
207 TRACE("Returning IDirect3DDevice9 interface at %p\n", *ppobj);
209 } else if(IsEqualGUID(riid, &IID_IDirect3DDevice9Ex)) {
210 /* Find out if the creating d3d9 interface was created with Direct3DCreate9Ex.
211 * It doesn't matter with which function the device was created.
213 IDirect3DDevice9_GetDirect3D(iface, &d3d);
214 d3dimpl = (IDirect3D9Impl *) d3d;
216 if(d3dimpl->extended) {
218 IDirect3DDevice9Ex_AddRef((IDirect3DDevice9Ex *) *ppobj);
219 IDirect3D9_Release(d3d);
220 TRACE("Returning IDirect3DDevice9Ex interface at %p\n", *ppobj);
223 WARN("IDirect3D9 instance wasn't created with CreateDirect3D9Ex, returning E_NOINTERFACE\n");
224 IDirect3D9_Release(d3d);
226 return E_NOINTERFACE;
230 if (IsEqualGUID(riid, &IID_IWineD3DDeviceParent))
232 IUnknown_AddRef((IUnknown *)&This->device_parent_vtbl);
233 *ppobj = &This->device_parent_vtbl;
237 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
239 return E_NOINTERFACE;
242 static ULONG WINAPI IDirect3DDevice9Impl_AddRef(LPDIRECT3DDEVICE9EX iface) {
243 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
244 ULONG ref = InterlockedIncrement(&This->ref);
246 TRACE("%p increasing refcount to %u.\n", iface, ref);
251 static ULONG WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_Release(LPDIRECT3DDEVICE9EX iface) {
252 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
255 if (This->inDestruction) return 0;
256 ref = InterlockedDecrement(&This->ref);
258 TRACE("%p decreasing refcount to %u.\n", iface, ref);
262 This->inDestruction = TRUE;
264 wined3d_mutex_lock();
265 for(i = 0; i < This->numConvertedDecls; i++) {
266 /* Unless Wine is buggy or the app has a bug the refcount will be 0, because decls hold a reference to the
269 IDirect3DVertexDeclaration9Impl_Destroy(This->convertedDecls[i]);
271 HeapFree(GetProcessHeap(), 0, This->convertedDecls);
273 IWineD3DDevice_Uninit3D(This->WineD3DDevice, D3D9CB_DestroySwapChain);
274 IWineD3DDevice_ReleaseFocusWindow(This->WineD3DDevice);
275 IWineD3DDevice_Release(This->WineD3DDevice);
276 wined3d_mutex_unlock();
278 HeapFree(GetProcessHeap(), 0, This);
283 /* IDirect3DDevice Interface follow: */
284 static HRESULT WINAPI IDirect3DDevice9Impl_TestCooperativeLevel(IDirect3DDevice9Ex *iface)
286 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
288 TRACE("iface %p.\n", iface);
292 TRACE("D3D9 device is marked not reset.\n");
293 return D3DERR_DEVICENOTRESET;
299 static UINT WINAPI IDirect3DDevice9Impl_GetAvailableTextureMem(LPDIRECT3DDEVICE9EX iface) {
300 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
303 TRACE("iface %p.\n", iface);
305 wined3d_mutex_lock();
306 hr = IWineD3DDevice_GetAvailableTextureMem(This->WineD3DDevice);
307 wined3d_mutex_unlock();
312 static HRESULT WINAPI IDirect3DDevice9Impl_EvictManagedResources(LPDIRECT3DDEVICE9EX iface) {
313 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
316 TRACE("iface %p.\n", iface);
318 wined3d_mutex_lock();
319 hr = IWineD3DDevice_EvictManagedResources(This->WineD3DDevice);
320 wined3d_mutex_unlock();
325 static HRESULT WINAPI IDirect3DDevice9Impl_GetDirect3D(LPDIRECT3DDEVICE9EX iface, IDirect3D9** ppD3D9) {
326 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
330 TRACE("iface %p, d3d9 %p.\n", iface, ppD3D9);
332 if (NULL == ppD3D9) {
333 return D3DERR_INVALIDCALL;
336 wined3d_mutex_lock();
337 hr = IWineD3DDevice_GetDirect3D(This->WineD3DDevice, &pWineD3D);
338 if (hr == D3D_OK && pWineD3D != NULL)
340 IWineD3D_GetParent(pWineD3D,(IUnknown **)ppD3D9);
341 IWineD3D_Release(pWineD3D);
343 FIXME("Call to IWineD3DDevice_GetDirect3D failed\n");
346 TRACE("(%p) returning %p\n", This, *ppD3D9);
347 wined3d_mutex_unlock();
352 static HRESULT WINAPI IDirect3DDevice9Impl_GetDeviceCaps(LPDIRECT3DDEVICE9EX iface, D3DCAPS9* pCaps) {
353 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
354 HRESULT hrc = D3D_OK;
355 WINED3DCAPS *pWineCaps;
357 TRACE("iface %p, caps %p.\n", iface, pCaps);
360 return D3DERR_INVALIDCALL;
362 pWineCaps = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WINED3DCAPS));
363 if(pWineCaps == NULL){
364 return D3DERR_INVALIDCALL; /* well this is what MSDN says to return */
367 memset(pCaps, 0, sizeof(*pCaps));
369 wined3d_mutex_lock();
370 hrc = IWineD3DDevice_GetDeviceCaps(This->WineD3DDevice, pWineCaps);
371 wined3d_mutex_unlock();
373 WINECAPSTOD3D9CAPS(pCaps, pWineCaps)
374 HeapFree(GetProcessHeap(), 0, pWineCaps);
376 /* Some functionality is implemented in d3d9.dll, not wined3d.dll. Add the needed caps */
377 pCaps->DevCaps2 |= D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES;
381 TRACE("Returning %p %p\n", This, pCaps);
385 static HRESULT WINAPI IDirect3DDevice9Impl_GetDisplayMode(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain, D3DDISPLAYMODE* pMode) {
386 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
389 TRACE("iface %p, swapchain %u, mode %p.\n", iface, iSwapChain, pMode);
391 wined3d_mutex_lock();
392 hr = IWineD3DDevice_GetDisplayMode(This->WineD3DDevice, iSwapChain, (WINED3DDISPLAYMODE *) pMode);
393 wined3d_mutex_unlock();
395 if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format);
400 static HRESULT WINAPI IDirect3DDevice9Impl_GetCreationParameters(LPDIRECT3DDEVICE9EX iface, D3DDEVICE_CREATION_PARAMETERS *pParameters) {
401 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
404 TRACE("iface %p, parameters %p.\n", iface, pParameters);
406 wined3d_mutex_lock();
407 hr = IWineD3DDevice_GetCreationParameters(This->WineD3DDevice, (WINED3DDEVICE_CREATION_PARAMETERS *) pParameters);
408 wined3d_mutex_unlock();
413 static HRESULT WINAPI IDirect3DDevice9Impl_SetCursorProperties(LPDIRECT3DDEVICE9EX iface, UINT XHotSpot, UINT YHotSpot, IDirect3DSurface9* pCursorBitmap) {
414 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
415 IDirect3DSurface9Impl *pSurface = (IDirect3DSurface9Impl*)pCursorBitmap;
418 TRACE("iface %p, hotspot_x %u, hotspot_y %u, bitmap %p.\n",
419 iface, XHotSpot, YHotSpot, pCursorBitmap);
422 WARN("No cursor bitmap, returning WINED3DERR_INVALIDCALL\n");
423 return WINED3DERR_INVALIDCALL;
426 wined3d_mutex_lock();
427 hr = IWineD3DDevice_SetCursorProperties(This->WineD3DDevice, XHotSpot, YHotSpot, pSurface->wineD3DSurface);
428 wined3d_mutex_unlock();
433 static void WINAPI IDirect3DDevice9Impl_SetCursorPosition(LPDIRECT3DDEVICE9EX iface, int XScreenSpace, int YScreenSpace, DWORD Flags) {
434 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
436 TRACE("iface %p, x %u, y %u, flags %#x.\n", iface, XScreenSpace, YScreenSpace, Flags);
438 wined3d_mutex_lock();
439 IWineD3DDevice_SetCursorPosition(This->WineD3DDevice, XScreenSpace, YScreenSpace, Flags);
440 wined3d_mutex_unlock();
443 static BOOL WINAPI IDirect3DDevice9Impl_ShowCursor(LPDIRECT3DDEVICE9EX iface, BOOL bShow) {
444 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
447 TRACE("iface %p, show %#x.\n", iface, bShow);
449 wined3d_mutex_lock();
450 ret = IWineD3DDevice_ShowCursor(This->WineD3DDevice, bShow);
451 wined3d_mutex_unlock();
456 static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_CreateAdditionalSwapChain(IDirect3DDevice9Ex *iface,
457 D3DPRESENT_PARAMETERS *present_parameters, IDirect3DSwapChain9 **swapchain)
459 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
460 IDirect3DSwapChain9Impl *object;
463 TRACE("iface %p, present_parameters %p, swapchain %p.\n",
464 iface, present_parameters, swapchain);
466 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
469 ERR("Failed to allocate swapchain memory.\n");
470 return E_OUTOFMEMORY;
473 hr = swapchain_init(object, This, present_parameters);
476 WARN("Failed to initialize swapchain, hr %#x.\n", hr);
477 HeapFree(GetProcessHeap(), 0, object);
481 TRACE("Created swapchain %p.\n", object);
482 *swapchain = (IDirect3DSwapChain9 *)object;
487 static HRESULT WINAPI reset_enum_callback(IWineD3DResource *resource, void *data) {
488 BOOL *resources_ok = data;
489 D3DRESOURCETYPE type;
491 WINED3DSURFACE_DESC surface_desc;
492 WINED3DVOLUME_DESC volume_desc;
493 D3DINDEXBUFFER_DESC index_desc;
494 D3DVERTEXBUFFER_DESC vertex_desc;
496 IDirect3DResource9 *parent;
498 IWineD3DResource_GetParent(resource, (IUnknown **) &parent);
499 type = IDirect3DResource9_GetType(parent);
501 case D3DRTYPE_SURFACE:
502 IWineD3DSurface_GetDesc((IWineD3DSurface *) resource, &surface_desc);
503 pool = surface_desc.pool;
506 case D3DRTYPE_VOLUME:
507 IWineD3DVolume_GetDesc((IWineD3DVolume *) resource, &volume_desc);
508 pool = volume_desc.Pool;
511 case D3DRTYPE_INDEXBUFFER:
512 IDirect3DIndexBuffer9_GetDesc((IDirect3DIndexBuffer9 *) parent, &index_desc);
513 pool = index_desc.Pool;
516 case D3DRTYPE_VERTEXBUFFER:
517 IDirect3DVertexBuffer9_GetDesc((IDirect3DVertexBuffer9 *)parent, &vertex_desc);
518 pool = vertex_desc.Pool;
521 /* No need to check for textures. If there is a D3DPOOL_DEFAULT texture, there
522 * is a D3DPOOL_DEFAULT surface or volume as well
525 pool = WINED3DPOOL_SCRATCH; /* a harmless pool */
529 if(pool == WINED3DPOOL_DEFAULT) {
530 if(IUnknown_Release(parent) == 0) {
531 TRACE("Parent %p is an implicit resource with ref 0\n", parent);
533 WARN("Resource %p(wineD3D %p) with pool D3DPOOL_DEFAULT blocks the Reset call\n", parent, resource);
535 *resources_ok = FALSE;
538 IUnknown_Release(parent);
540 IWineD3DResource_Release(resource);
545 static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_Reset(LPDIRECT3DDEVICE9EX iface, D3DPRESENT_PARAMETERS* pPresentationParameters) {
546 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
547 WINED3DPRESENT_PARAMETERS localParameters;
549 BOOL resources_ok = TRUE;
552 TRACE("iface %p, present_parameters %p.\n", iface, pPresentationParameters);
554 /* Reset states that hold a COM object. WineD3D holds an internal reference to set objects, because
555 * such objects can still be used for rendering after their external d3d9 object has been destroyed.
556 * These objects must not be enumerated. Unsetting them tells WineD3D that the application will not
557 * make use of the hidden reference and destroys the objects.
559 * Unsetting them is no problem, because the states are supposed to be reset anyway. If the validation
560 * below fails, the device is considered "lost", and _Reset and _Release are the only allowed calls
562 wined3d_mutex_lock();
563 IWineD3DDevice_SetIndexBuffer(This->WineD3DDevice, NULL, WINED3DFMT_UNKNOWN);
564 for(i = 0; i < 16; i++) {
565 IWineD3DDevice_SetStreamSource(This->WineD3DDevice, i, NULL, 0, 0);
567 for(i = 0; i < 16; i++) {
568 IWineD3DDevice_SetTexture(This->WineD3DDevice, i, NULL);
571 IWineD3DDevice_EnumResources(This->WineD3DDevice, reset_enum_callback, &resources_ok);
573 WARN("The application is holding D3DPOOL_DEFAULT resources, rejecting reset\n");
574 This->notreset = TRUE;
575 wined3d_mutex_unlock();
577 return WINED3DERR_INVALIDCALL;
580 localParameters.BackBufferWidth = pPresentationParameters->BackBufferWidth;
581 localParameters.BackBufferHeight = pPresentationParameters->BackBufferHeight;
582 localParameters.BackBufferFormat = wined3dformat_from_d3dformat(pPresentationParameters->BackBufferFormat);
583 localParameters.BackBufferCount = pPresentationParameters->BackBufferCount;
584 localParameters.MultiSampleType = pPresentationParameters->MultiSampleType;
585 localParameters.MultiSampleQuality = pPresentationParameters->MultiSampleQuality;
586 localParameters.SwapEffect = pPresentationParameters->SwapEffect;
587 localParameters.hDeviceWindow = pPresentationParameters->hDeviceWindow;
588 localParameters.Windowed = pPresentationParameters->Windowed;
589 localParameters.EnableAutoDepthStencil = pPresentationParameters->EnableAutoDepthStencil;
590 localParameters.AutoDepthStencilFormat = wined3dformat_from_d3dformat(pPresentationParameters->AutoDepthStencilFormat);
591 localParameters.Flags = pPresentationParameters->Flags;
592 localParameters.FullScreen_RefreshRateInHz = pPresentationParameters->FullScreen_RefreshRateInHz;
593 localParameters.PresentationInterval = pPresentationParameters->PresentationInterval;
594 localParameters.AutoRestoreDisplayMode = TRUE;
596 hr = IWineD3DDevice_Reset(This->WineD3DDevice, &localParameters);
598 This->notreset = TRUE;
600 pPresentationParameters->BackBufferWidth = localParameters.BackBufferWidth;
601 pPresentationParameters->BackBufferHeight = localParameters.BackBufferHeight;
602 pPresentationParameters->BackBufferFormat = d3dformat_from_wined3dformat(localParameters.BackBufferFormat);
603 pPresentationParameters->BackBufferCount = localParameters.BackBufferCount;
604 pPresentationParameters->MultiSampleType = localParameters.MultiSampleType;
605 pPresentationParameters->MultiSampleQuality = localParameters.MultiSampleQuality;
606 pPresentationParameters->SwapEffect = localParameters.SwapEffect;
607 pPresentationParameters->hDeviceWindow = localParameters.hDeviceWindow;
608 pPresentationParameters->Windowed = localParameters.Windowed;
609 pPresentationParameters->EnableAutoDepthStencil = localParameters.EnableAutoDepthStencil;
610 pPresentationParameters->AutoDepthStencilFormat = d3dformat_from_wined3dformat(localParameters.AutoDepthStencilFormat);
611 pPresentationParameters->Flags = localParameters.Flags;
612 pPresentationParameters->FullScreen_RefreshRateInHz = localParameters.FullScreen_RefreshRateInHz;
613 pPresentationParameters->PresentationInterval = localParameters.PresentationInterval;
615 This->notreset = FALSE;
618 wined3d_mutex_unlock();
623 static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_Present(LPDIRECT3DDEVICE9EX iface, CONST RECT* pSourceRect,CONST RECT* pDestRect,HWND hDestWindowOverride,CONST RGNDATA*
625 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
628 TRACE("iface %p, src_rect %p, dst_rect %p, dst_window_override %p, dirty_region %p.\n",
629 iface, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
631 wined3d_mutex_lock();
632 hr = IWineD3DDevice_Present(This->WineD3DDevice, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
633 wined3d_mutex_unlock();
638 static HRESULT WINAPI IDirect3DDevice9Impl_GetBackBuffer(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain, UINT BackBuffer, D3DBACKBUFFER_TYPE Type, IDirect3DSurface9 ** ppBackBuffer) {
639 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
640 IWineD3DSurface *retSurface = NULL;
643 TRACE("iface %p, swapchain %u, backbuffer_idx %u, backbuffer_type %#x, backbuffer %p.\n",
644 iface, iSwapChain, BackBuffer, Type, ppBackBuffer);
646 wined3d_mutex_lock();
647 rc = IWineD3DDevice_GetBackBuffer(This->WineD3DDevice, iSwapChain, BackBuffer, (WINED3DBACKBUFFER_TYPE) Type, &retSurface);
648 if (rc == D3D_OK && NULL != retSurface && NULL != ppBackBuffer) {
649 IWineD3DSurface_GetParent(retSurface, (IUnknown **)ppBackBuffer);
650 IWineD3DSurface_Release(retSurface);
652 wined3d_mutex_unlock();
656 static HRESULT WINAPI IDirect3DDevice9Impl_GetRasterStatus(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain, D3DRASTER_STATUS* pRasterStatus) {
657 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
660 TRACE("iface %p, swapchain %u, raster_status %p.\n", iface, iSwapChain, pRasterStatus);
662 wined3d_mutex_lock();
663 hr = IWineD3DDevice_GetRasterStatus(This->WineD3DDevice, iSwapChain, (WINED3DRASTER_STATUS *) pRasterStatus);
664 wined3d_mutex_unlock();
669 static HRESULT WINAPI IDirect3DDevice9Impl_SetDialogBoxMode(LPDIRECT3DDEVICE9EX iface, BOOL bEnableDialogs) {
670 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
673 TRACE("iface %p, enable %#x.\n", iface, bEnableDialogs);
675 wined3d_mutex_lock();
676 hr = IWineD3DDevice_SetDialogBoxMode(This->WineD3DDevice, bEnableDialogs);
677 wined3d_mutex_unlock();
682 static void WINAPI IDirect3DDevice9Impl_SetGammaRamp(IDirect3DDevice9Ex *iface, UINT iSwapChain,
683 DWORD Flags, const D3DGAMMARAMP *pRamp)
685 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
687 TRACE("iface %p, swapchain %u, flags %#x, ramp %p.\n", iface, iSwapChain, Flags, pRamp);
689 /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
690 wined3d_mutex_lock();
691 IWineD3DDevice_SetGammaRamp(This->WineD3DDevice, iSwapChain, Flags, (CONST WINED3DGAMMARAMP *)pRamp);
692 wined3d_mutex_unlock();
695 static void WINAPI IDirect3DDevice9Impl_GetGammaRamp(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain, D3DGAMMARAMP* pRamp) {
696 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
698 TRACE("iface %p, swapchain %u, ramp %p.\n", iface, iSwapChain, pRamp);
700 /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
701 wined3d_mutex_lock();
702 IWineD3DDevice_GetGammaRamp(This->WineD3DDevice, iSwapChain, (WINED3DGAMMARAMP *) pRamp);
703 wined3d_mutex_unlock();
706 static HRESULT WINAPI IDirect3DDevice9Impl_CreateTexture(IDirect3DDevice9Ex *iface,
707 UINT width, UINT height, UINT levels, DWORD usage, D3DFORMAT format,
708 D3DPOOL pool, IDirect3DTexture9 **texture, HANDLE *shared_handle)
710 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
711 IDirect3DTexture9Impl *object;
714 TRACE("iface %p, width %u, height %u, levels %u, usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n",
715 iface, width, height, levels, usage, format, pool, texture, shared_handle);
717 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
720 ERR("Failed to allocate texture memory.\n");
721 return D3DERR_OUTOFVIDEOMEMORY;
724 hr = texture_init(object, This, width, height, levels, usage, format, pool);
727 WARN("Failed to initialize texture, hr %#x.\n", hr);
728 HeapFree(GetProcessHeap(), 0, object);
732 TRACE("Created texture %p.\n", object);
733 *texture = (IDirect3DTexture9 *)object;
738 static HRESULT WINAPI IDirect3DDevice9Impl_CreateVolumeTexture(IDirect3DDevice9Ex *iface,
739 UINT width, UINT height, UINT depth, UINT levels, DWORD usage, D3DFORMAT format,
740 D3DPOOL pool, IDirect3DVolumeTexture9 **texture, HANDLE *shared_handle)
742 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
743 IDirect3DVolumeTexture9Impl *object;
746 TRACE("iface %p, width %u, height %u, depth %u, levels %u\n",
747 iface, width, height, depth, levels);
748 TRACE("usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n",
749 usage, format, pool, texture, shared_handle);
751 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
754 ERR("Failed to allocate volume texture memory.\n");
755 return D3DERR_OUTOFVIDEOMEMORY;
758 hr = volumetexture_init(object, This, width, height, depth, levels, usage, format, pool);
761 WARN("Failed to initialize volume texture, hr %#x.\n", hr);
762 HeapFree(GetProcessHeap(), 0, object);
766 TRACE("Created volume texture %p.\n", object);
767 *texture = (IDirect3DVolumeTexture9 *)object;
772 static HRESULT WINAPI IDirect3DDevice9Impl_CreateCubeTexture(IDirect3DDevice9Ex *iface,
773 UINT edge_length, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool,
774 IDirect3DCubeTexture9 **texture, HANDLE *shared_handle)
776 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
777 IDirect3DCubeTexture9Impl *object;
780 TRACE("iface %p, edge_length %u, levels %u, usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n",
781 iface, edge_length, levels, usage, format, pool, texture, shared_handle);
783 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
786 ERR("Failed to allocate cube texture memory.\n");
787 return D3DERR_OUTOFVIDEOMEMORY;
790 hr = cubetexture_init(object, This, edge_length, levels, usage, format, pool);
793 WARN("Failed to initialize cube texture, hr %#x.\n", hr);
794 HeapFree(GetProcessHeap(), 0, object);
798 TRACE("Created cube texture %p.\n", object);
799 *texture = (IDirect3DCubeTexture9 *)object;
804 static HRESULT WINAPI IDirect3DDevice9Impl_CreateVertexBuffer(IDirect3DDevice9Ex *iface, UINT size, DWORD usage,
805 DWORD fvf, D3DPOOL pool, IDirect3DVertexBuffer9 **buffer, HANDLE *shared_handle)
807 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
808 IDirect3DVertexBuffer9Impl *object;
811 TRACE("iface %p, size %u, usage %#x, fvf %#x, pool %#x, buffer %p, shared_handle %p.\n",
812 iface, size, usage, fvf, pool, buffer, shared_handle);
814 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
817 ERR("Failed to allocate buffer memory.\n");
818 return D3DERR_OUTOFVIDEOMEMORY;
821 hr = vertexbuffer_init(object, This, size, usage, fvf, pool);
824 WARN("Failed to initialize vertex buffer, hr %#x.\n", hr);
825 HeapFree(GetProcessHeap(), 0, object);
829 TRACE("Created vertex buffer %p.\n", object);
830 *buffer = (IDirect3DVertexBuffer9 *)object;
835 static HRESULT WINAPI IDirect3DDevice9Impl_CreateIndexBuffer(IDirect3DDevice9Ex *iface, UINT size, DWORD usage,
836 D3DFORMAT format, D3DPOOL pool, IDirect3DIndexBuffer9 **buffer, HANDLE *shared_handle)
838 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
839 IDirect3DIndexBuffer9Impl *object;
842 TRACE("iface %p, size %u, usage %#x, format %#x, pool %#x, buffer %p, shared_handle %p.\n",
843 iface, size, usage, format, pool, buffer, shared_handle);
845 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
848 ERR("Failed to allocate buffer memory.\n");
849 return D3DERR_OUTOFVIDEOMEMORY;
852 hr = indexbuffer_init(object, This, size, usage, format, pool);
855 WARN("Failed to initialize index buffer, hr %#x.\n", hr);
856 HeapFree(GetProcessHeap(), 0, object);
860 TRACE("Created index buffer %p.\n", object);
861 *buffer = (IDirect3DIndexBuffer9 *)object;
866 static HRESULT IDirect3DDevice9Impl_CreateSurface(LPDIRECT3DDEVICE9EX iface, UINT Width, UINT Height,
867 D3DFORMAT Format, BOOL Lockable, BOOL Discard, UINT Level, IDirect3DSurface9 **ppSurface,
868 UINT Usage, D3DPOOL Pool, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality)
870 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
871 IDirect3DSurface9Impl *object;
874 TRACE("iface %p, width %u, height %u, format %#x, lockable %#x, discard %#x, level %u, surface %p.\n"
875 "usage %#x, pool %#x, multisample_type %#x, multisample_quality %u.\n",
876 iface, Width, Height, Format, Lockable, Discard, Level, ppSurface,
877 Usage, Pool, MultiSample, MultisampleQuality);
879 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DSurface9Impl));
882 FIXME("Failed to allocate surface memory.\n");
883 return D3DERR_OUTOFVIDEOMEMORY;
886 hr = surface_init(object, This, Width, Height, Format, Lockable, Discard,
887 Level, Usage, Pool, MultiSample, MultisampleQuality);
890 WARN("Failed to initialize surface, hr %#x.\n", hr);
891 HeapFree(GetProcessHeap(), 0, object);
895 TRACE("Created surface %p.\n", object);
896 *ppSurface = (IDirect3DSurface9 *)object;
901 static HRESULT WINAPI IDirect3DDevice9Impl_CreateRenderTarget(IDirect3DDevice9Ex *iface, UINT Width, UINT Height,
902 D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality, BOOL Lockable,
903 IDirect3DSurface9 **ppSurface, HANDLE *pSharedHandle)
907 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u.\n"
908 "lockable %#x, surface %p, shared_handle %p.\n",
909 iface, Width, Height, Format, MultiSample, MultisampleQuality,
910 Lockable, ppSurface, pSharedHandle);
912 hr = IDirect3DDevice9Impl_CreateSurface(iface, Width, Height, Format, Lockable, FALSE /* Discard */,
913 0 /* Level */, ppSurface, D3DUSAGE_RENDERTARGET, D3DPOOL_DEFAULT, MultiSample, MultisampleQuality);
918 static HRESULT WINAPI IDirect3DDevice9Impl_CreateDepthStencilSurface(LPDIRECT3DDEVICE9EX iface, UINT Width, UINT Height,
919 D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample,
920 DWORD MultisampleQuality, BOOL Discard,
921 IDirect3DSurface9 **ppSurface, HANDLE* pSharedHandle) {
924 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u.\n"
925 "discard %#x, surface %p, shared_handle %p.\n",
926 iface, Width, Height, Format, MultiSample, MultisampleQuality,
927 Discard, ppSurface, pSharedHandle);
929 hr = IDirect3DDevice9Impl_CreateSurface(iface, Width, Height, Format, TRUE /* Lockable */, Discard,
930 0 /* Level */, ppSurface, D3DUSAGE_DEPTHSTENCIL, D3DPOOL_DEFAULT, MultiSample, MultisampleQuality);
936 static HRESULT WINAPI IDirect3DDevice9Impl_UpdateSurface(LPDIRECT3DDEVICE9EX iface, IDirect3DSurface9* pSourceSurface, CONST RECT* pSourceRect, IDirect3DSurface9* pDestinationSurface, CONST POINT* pDestPoint) {
937 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
940 TRACE("iface %p, src_surface %p, src_rect %p, dst_surface %p, dst_point %p.\n",
941 iface, pSourceSurface, pSourceRect, pDestinationSurface, pDestPoint);
943 wined3d_mutex_lock();
944 hr = IWineD3DDevice_UpdateSurface(This->WineD3DDevice, ((IDirect3DSurface9Impl *)pSourceSurface)->wineD3DSurface, pSourceRect, ((IDirect3DSurface9Impl *)pDestinationSurface)->wineD3DSurface, pDestPoint);
945 wined3d_mutex_unlock();
950 static HRESULT WINAPI IDirect3DDevice9Impl_UpdateTexture(LPDIRECT3DDEVICE9EX iface, IDirect3DBaseTexture9* pSourceTexture, IDirect3DBaseTexture9* pDestinationTexture) {
951 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
954 TRACE("iface %p, src_texture %p, dst_texture %p.\n", iface, pSourceTexture, pDestinationTexture);
956 wined3d_mutex_lock();
957 hr = IWineD3DDevice_UpdateTexture(This->WineD3DDevice, ((IDirect3DBaseTexture9Impl *)pSourceTexture)->wineD3DBaseTexture, ((IDirect3DBaseTexture9Impl *)pDestinationTexture)->wineD3DBaseTexture);
958 wined3d_mutex_unlock();
963 static HRESULT WINAPI IDirect3DDevice9Impl_GetRenderTargetData(IDirect3DDevice9Ex *iface,
964 IDirect3DSurface9 *pRenderTarget, IDirect3DSurface9 *pDestSurface)
966 IDirect3DSurface9Impl *renderTarget = (IDirect3DSurface9Impl *)pRenderTarget;
967 IDirect3DSurface9Impl *destSurface = (IDirect3DSurface9Impl *)pDestSurface;
970 TRACE("iface %p, render_target %p, dst_surface %p.\n", iface, pRenderTarget, pDestSurface);
972 wined3d_mutex_lock();
973 hr = IWineD3DSurface_BltFast(destSurface->wineD3DSurface, 0, 0, renderTarget->wineD3DSurface, NULL, WINEDDBLTFAST_NOCOLORKEY);
974 wined3d_mutex_unlock();
979 static HRESULT WINAPI IDirect3DDevice9Impl_GetFrontBufferData(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain, IDirect3DSurface9* pDestSurface) {
980 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
981 IDirect3DSurface9Impl *destSurface = (IDirect3DSurface9Impl *)pDestSurface;
984 TRACE("iface %p, swapchain %u, dst_surface %p.\n", iface, iSwapChain, pDestSurface);
986 wined3d_mutex_lock();
987 hr = IWineD3DDevice_GetFrontBufferData(This->WineD3DDevice, iSwapChain, destSurface->wineD3DSurface);
988 wined3d_mutex_unlock();
993 static HRESULT WINAPI IDirect3DDevice9Impl_StretchRect(IDirect3DDevice9Ex *iface, IDirect3DSurface9 *pSourceSurface,
994 const RECT *pSourceRect, IDirect3DSurface9 *pDestSurface, const RECT *pDestRect, D3DTEXTUREFILTERTYPE Filter)
996 IDirect3DSurface9Impl *src = (IDirect3DSurface9Impl *) pSourceSurface;
997 IDirect3DSurface9Impl *dst = (IDirect3DSurface9Impl *) pDestSurface;
1000 TRACE("iface %p, src_surface %p, src_rect %p, dst_surface %p, dst_rect %p, filter %#x.\n",
1001 iface, pSourceSurface, pSourceRect, pDestSurface, pDestRect, Filter);
1003 wined3d_mutex_lock();
1004 hr = IWineD3DSurface_Blt(dst->wineD3DSurface, pDestRect, src->wineD3DSurface, pSourceRect, 0, NULL, Filter);
1005 wined3d_mutex_unlock();
1010 static HRESULT WINAPI IDirect3DDevice9Impl_ColorFill(IDirect3DDevice9Ex *iface,
1011 IDirect3DSurface9 *pSurface, const RECT *pRect, D3DCOLOR color)
1013 const WINED3DCOLORVALUE c =
1015 ((color >> 16) & 0xff) / 255.0f,
1016 ((color >> 8) & 0xff) / 255.0f,
1017 (color & 0xff) / 255.0f,
1018 ((color >> 24) & 0xff) / 255.0f,
1020 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1021 IDirect3DSurface9Impl *surface = (IDirect3DSurface9Impl *)pSurface;
1023 WINED3DRESOURCETYPE restype;
1025 WINED3DSURFACE_DESC desc;
1028 TRACE("iface %p, surface %p, rect %p, color 0x%08x.\n", iface, pSurface, pRect, color);
1030 wined3d_mutex_lock();
1032 IWineD3DSurface_GetDesc(surface->wineD3DSurface, &desc);
1035 restype = desc.resource_type;
1037 /* This method is only allowed with surfaces that are render targets, or offscreen plain surfaces
1038 * in D3DPOOL_DEFAULT
1040 if(!(usage & WINED3DUSAGE_RENDERTARGET) && (pool != WINED3DPOOL_DEFAULT || restype != WINED3DRTYPE_SURFACE)) {
1041 wined3d_mutex_unlock();
1042 WARN("Surface is not a render target, or not a stand-alone D3DPOOL_DEFAULT surface\n");
1043 return D3DERR_INVALIDCALL;
1046 /* Colorfill can only be used on rendertarget surfaces, or offscreen plain surfaces in D3DPOOL_DEFAULT */
1047 hr = IWineD3DDevice_ColorFill(This->WineD3DDevice, surface->wineD3DSurface, pRect, &c);
1049 wined3d_mutex_unlock();
1054 static HRESULT WINAPI IDirect3DDevice9Impl_CreateOffscreenPlainSurface(LPDIRECT3DDEVICE9EX iface, UINT Width, UINT Height, D3DFORMAT Format, D3DPOOL Pool, IDirect3DSurface9 **ppSurface, HANDLE* pSharedHandle) {
1057 TRACE("iface %p, width %u, height %u, format %#x, pool %#x, surface %p, shared_handle %p.\n",
1058 iface, Width, Height, Format, Pool, ppSurface, pSharedHandle);
1060 if(Pool == D3DPOOL_MANAGED ){
1061 FIXME("Attempting to create a managed offscreen plain surface\n");
1062 return D3DERR_INVALIDCALL;
1065 'Off-screen plain surfaces are always lockable, regardless of their pool types.'
1067 D3DPOOL_DEFAULT is the appropriate pool for use with the IDirect3DDevice9::StretchRect and IDirect3DDevice9::ColorFill.
1068 Why, their always lockable?
1069 should I change the usage to dynamic?
1071 hr = IDirect3DDevice9Impl_CreateSurface(iface, Width, Height, Format, TRUE /* Lockable */, FALSE /* Discard */,
1072 0 /* Level */, ppSurface, 0 /* Usage (undefined/none) */, (WINED3DPOOL)Pool, D3DMULTISAMPLE_NONE,
1073 0 /* MultisampleQuality */);
1078 /* TODO: move to wineD3D */
1079 static HRESULT WINAPI IDirect3DDevice9Impl_SetRenderTarget(LPDIRECT3DDEVICE9EX iface, DWORD RenderTargetIndex, IDirect3DSurface9* pRenderTarget) {
1080 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1081 IDirect3DSurface9Impl *pSurface = (IDirect3DSurface9Impl*)pRenderTarget;
1084 TRACE("iface %p, idx %u, surface %p.\n", iface, RenderTargetIndex, pRenderTarget);
1086 if (RenderTargetIndex >= D3D9_MAX_SIMULTANEOUS_RENDERTARGETS)
1088 WARN("Invalid index %u specified.\n", RenderTargetIndex);
1089 return D3DERR_INVALIDCALL;
1092 wined3d_mutex_lock();
1093 hr = IWineD3DDevice_SetRenderTarget(This->WineD3DDevice, RenderTargetIndex, pSurface ? pSurface->wineD3DSurface : NULL, TRUE);
1094 wined3d_mutex_unlock();
1099 static HRESULT WINAPI IDirect3DDevice9Impl_GetRenderTarget(LPDIRECT3DDEVICE9EX iface, DWORD RenderTargetIndex, IDirect3DSurface9 **ppRenderTarget) {
1100 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1101 IWineD3DSurface *pRenderTarget;
1104 TRACE("iface %p, idx %u, surface %p.\n", iface, RenderTargetIndex, ppRenderTarget);
1106 if (ppRenderTarget == NULL) {
1107 return D3DERR_INVALIDCALL;
1110 if (RenderTargetIndex >= D3D9_MAX_SIMULTANEOUS_RENDERTARGETS)
1112 WARN("Invalid index %u specified.\n", RenderTargetIndex);
1113 return D3DERR_INVALIDCALL;
1116 wined3d_mutex_lock();
1118 hr=IWineD3DDevice_GetRenderTarget(This->WineD3DDevice,RenderTargetIndex,&pRenderTarget);
1122 FIXME("Call to IWineD3DDevice_GetRenderTarget failed, hr %#x\n", hr);
1124 else if (!pRenderTarget)
1126 *ppRenderTarget = NULL;
1130 IWineD3DSurface_GetParent(pRenderTarget, (IUnknown **)ppRenderTarget);
1131 IWineD3DSurface_Release(pRenderTarget);
1134 wined3d_mutex_unlock();
1139 static HRESULT WINAPI IDirect3DDevice9Impl_SetDepthStencilSurface(LPDIRECT3DDEVICE9EX iface, IDirect3DSurface9* pZStencilSurface) {
1140 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1141 IDirect3DSurface9Impl *pSurface;
1144 TRACE("iface %p, depth_stencil %p.\n", iface, pZStencilSurface);
1146 pSurface = (IDirect3DSurface9Impl*)pZStencilSurface;
1148 wined3d_mutex_lock();
1149 hr = IWineD3DDevice_SetDepthStencilSurface(This->WineD3DDevice, NULL==pSurface ? NULL : pSurface->wineD3DSurface);
1150 wined3d_mutex_unlock();
1155 static HRESULT WINAPI IDirect3DDevice9Impl_GetDepthStencilSurface(LPDIRECT3DDEVICE9EX iface, IDirect3DSurface9 **ppZStencilSurface) {
1156 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1157 HRESULT hr = D3D_OK;
1158 IWineD3DSurface *pZStencilSurface;
1160 TRACE("iface %p, depth_stencil %p.\n", iface, ppZStencilSurface);
1162 if(ppZStencilSurface == NULL){
1163 return D3DERR_INVALIDCALL;
1166 wined3d_mutex_lock();
1167 hr = IWineD3DDevice_GetDepthStencilSurface(This->WineD3DDevice,&pZStencilSurface);
1168 if (hr == WINED3D_OK) {
1169 IWineD3DSurface_GetParent(pZStencilSurface,(IUnknown**)ppZStencilSurface);
1170 IWineD3DSurface_Release(pZStencilSurface);
1172 if (hr != WINED3DERR_NOTFOUND)
1173 WARN("Call to IWineD3DDevice_GetDepthStencilSurface failed with 0x%08x\n", hr);
1174 *ppZStencilSurface = NULL;
1176 wined3d_mutex_unlock();
1181 static HRESULT WINAPI IDirect3DDevice9Impl_BeginScene(LPDIRECT3DDEVICE9EX iface) {
1182 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1185 TRACE("iface %p.\n", iface);
1187 wined3d_mutex_lock();
1188 hr = IWineD3DDevice_BeginScene(This->WineD3DDevice);
1189 wined3d_mutex_unlock();
1194 static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_EndScene(LPDIRECT3DDEVICE9EX iface) {
1195 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1198 TRACE("iface %p.\n", iface);
1200 wined3d_mutex_lock();
1201 hr = IWineD3DDevice_EndScene(This->WineD3DDevice);
1202 wined3d_mutex_unlock();
1207 static HRESULT WINAPI IDirect3DDevice9Impl_Clear(LPDIRECT3DDEVICE9EX iface, DWORD Count, CONST D3DRECT* pRects, DWORD Flags, D3DCOLOR Color, float Z, DWORD Stencil) {
1208 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1211 TRACE("iface %p, rect_count %u, rects %p, flags %#x, color 0x%08x, z %.8e, stencil %u.\n",
1212 iface, Count, pRects, Flags, Color, Z, Stencil);
1214 /* Note: D3DRECT is compatible with WINED3DRECT */
1215 wined3d_mutex_lock();
1216 hr = IWineD3DDevice_Clear(This->WineD3DDevice, Count, (const RECT *)pRects, Flags, Color, Z, Stencil);
1217 wined3d_mutex_unlock();
1222 static HRESULT WINAPI IDirect3DDevice9Impl_SetTransform(LPDIRECT3DDEVICE9EX iface, D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX* lpMatrix) {
1223 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1226 TRACE("iface %p, state %#x, matrix %p.\n", iface, State, lpMatrix);
1228 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1229 wined3d_mutex_lock();
1230 hr = IWineD3DDevice_SetTransform(This->WineD3DDevice, State, (CONST WINED3DMATRIX*) lpMatrix);
1231 wined3d_mutex_unlock();
1236 static HRESULT WINAPI IDirect3DDevice9Impl_GetTransform(LPDIRECT3DDEVICE9EX iface, D3DTRANSFORMSTATETYPE State, D3DMATRIX* pMatrix) {
1237 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1240 TRACE("iface %p, state %#x, matrix %p.\n", iface, State, pMatrix);
1242 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1243 wined3d_mutex_lock();
1244 hr = IWineD3DDevice_GetTransform(This->WineD3DDevice, State, (WINED3DMATRIX*) pMatrix);
1245 wined3d_mutex_unlock();
1250 static HRESULT WINAPI IDirect3DDevice9Impl_MultiplyTransform(LPDIRECT3DDEVICE9EX iface, D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX* pMatrix) {
1251 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1254 TRACE("iface %p, state %#x, matrix %p.\n", iface, State, pMatrix);
1256 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1257 wined3d_mutex_lock();
1258 hr = IWineD3DDevice_MultiplyTransform(This->WineD3DDevice, State, (CONST WINED3DMATRIX*) pMatrix);
1259 wined3d_mutex_unlock();
1264 static HRESULT WINAPI IDirect3DDevice9Impl_SetViewport(LPDIRECT3DDEVICE9EX iface, CONST D3DVIEWPORT9* pViewport) {
1265 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1268 TRACE("iface %p, viewport %p.\n", iface, pViewport);
1270 /* Note: D3DVIEWPORT9 is compatible with WINED3DVIEWPORT */
1271 wined3d_mutex_lock();
1272 hr = IWineD3DDevice_SetViewport(This->WineD3DDevice, (const WINED3DVIEWPORT *)pViewport);
1273 wined3d_mutex_unlock();
1278 static HRESULT WINAPI IDirect3DDevice9Impl_GetViewport(LPDIRECT3DDEVICE9EX iface, D3DVIEWPORT9* pViewport) {
1279 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1282 TRACE("iface %p, viewport %p.\n", iface, pViewport);
1284 /* Note: D3DVIEWPORT9 is compatible with WINED3DVIEWPORT */
1285 wined3d_mutex_lock();
1286 hr = IWineD3DDevice_GetViewport(This->WineD3DDevice, (WINED3DVIEWPORT *)pViewport);
1287 wined3d_mutex_unlock();
1292 static HRESULT WINAPI IDirect3DDevice9Impl_SetMaterial(LPDIRECT3DDEVICE9EX iface, CONST D3DMATERIAL9* pMaterial) {
1293 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1296 TRACE("iface %p, material %p.\n", iface, pMaterial);
1298 /* Note: D3DMATERIAL9 is compatible with WINED3DMATERIAL */
1299 wined3d_mutex_lock();
1300 hr = IWineD3DDevice_SetMaterial(This->WineD3DDevice, (const WINED3DMATERIAL *)pMaterial);
1301 wined3d_mutex_unlock();
1306 static HRESULT WINAPI IDirect3DDevice9Impl_GetMaterial(LPDIRECT3DDEVICE9EX iface, D3DMATERIAL9* pMaterial) {
1307 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1310 TRACE("iface %p, material %p.\n", iface, pMaterial);
1312 /* Note: D3DMATERIAL9 is compatible with WINED3DMATERIAL */
1313 wined3d_mutex_lock();
1314 hr = IWineD3DDevice_GetMaterial(This->WineD3DDevice, (WINED3DMATERIAL *)pMaterial);
1315 wined3d_mutex_unlock();
1320 static HRESULT WINAPI IDirect3DDevice9Impl_SetLight(LPDIRECT3DDEVICE9EX iface, DWORD Index, CONST D3DLIGHT9* pLight) {
1321 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1324 TRACE("iface %p, index %u, light %p.\n", iface, Index, pLight);
1326 /* Note: D3DLIGHT9 is compatible with WINED3DLIGHT */
1327 wined3d_mutex_lock();
1328 hr = IWineD3DDevice_SetLight(This->WineD3DDevice, Index, (const WINED3DLIGHT *)pLight);
1329 wined3d_mutex_unlock();
1334 static HRESULT WINAPI IDirect3DDevice9Impl_GetLight(LPDIRECT3DDEVICE9EX iface, DWORD Index, D3DLIGHT9* pLight) {
1335 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1338 TRACE("iface %p, index %u, light %p.\n", iface, Index, pLight);
1340 /* Note: D3DLIGHT9 is compatible with WINED3DLIGHT */
1341 wined3d_mutex_lock();
1342 hr = IWineD3DDevice_GetLight(This->WineD3DDevice, Index, (WINED3DLIGHT *)pLight);
1343 wined3d_mutex_unlock();
1348 static HRESULT WINAPI IDirect3DDevice9Impl_LightEnable(LPDIRECT3DDEVICE9EX iface, DWORD Index, BOOL Enable) {
1349 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1352 TRACE("iface %p, index %u, enable %#x.\n", iface, Index, Enable);
1354 wined3d_mutex_lock();
1355 hr = IWineD3DDevice_SetLightEnable(This->WineD3DDevice, Index, Enable);
1356 wined3d_mutex_unlock();
1361 static HRESULT WINAPI IDirect3DDevice9Impl_GetLightEnable(LPDIRECT3DDEVICE9EX iface, DWORD Index, BOOL* pEnable) {
1362 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1365 TRACE("iface %p, index %u, enable %p.\n", iface, Index, pEnable);
1367 wined3d_mutex_lock();
1368 hr = IWineD3DDevice_GetLightEnable(This->WineD3DDevice, Index, pEnable);
1369 wined3d_mutex_unlock();
1374 static HRESULT WINAPI IDirect3DDevice9Impl_SetClipPlane(LPDIRECT3DDEVICE9EX iface, DWORD Index, CONST float* pPlane) {
1375 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1378 TRACE("iface %p, index %u, plane %p.\n", iface, Index, pPlane);
1380 wined3d_mutex_lock();
1381 hr = IWineD3DDevice_SetClipPlane(This->WineD3DDevice, Index, pPlane);
1382 wined3d_mutex_unlock();
1387 static HRESULT WINAPI IDirect3DDevice9Impl_GetClipPlane(LPDIRECT3DDEVICE9EX iface, DWORD Index, float* pPlane) {
1388 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1391 TRACE("iface %p, index %u, plane %p.\n", iface, Index, pPlane);
1393 wined3d_mutex_lock();
1394 hr = IWineD3DDevice_GetClipPlane(This->WineD3DDevice, Index, pPlane);
1395 wined3d_mutex_unlock();
1400 static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_SetRenderState(LPDIRECT3DDEVICE9EX iface, D3DRENDERSTATETYPE State, DWORD Value) {
1401 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1404 TRACE("iface %p, state %#x, value %#x.\n", iface, State, Value);
1406 wined3d_mutex_lock();
1407 hr = IWineD3DDevice_SetRenderState(This->WineD3DDevice, State, Value);
1408 wined3d_mutex_unlock();
1413 static HRESULT WINAPI IDirect3DDevice9Impl_GetRenderState(LPDIRECT3DDEVICE9EX iface, D3DRENDERSTATETYPE State, DWORD* pValue) {
1414 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1417 TRACE("iface %p, state %#x, value %p.\n", iface, State, pValue);
1419 wined3d_mutex_lock();
1420 hr = IWineD3DDevice_GetRenderState(This->WineD3DDevice, State, pValue);
1421 wined3d_mutex_unlock();
1426 static HRESULT WINAPI IDirect3DDevice9Impl_CreateStateBlock(IDirect3DDevice9Ex *iface,
1427 D3DSTATEBLOCKTYPE type, IDirect3DStateBlock9 **stateblock)
1429 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1430 IDirect3DStateBlock9Impl *object;
1433 TRACE("iface %p, type %#x, stateblock %p.\n", iface, type, stateblock);
1435 if (type != D3DSBT_ALL && type != D3DSBT_PIXELSTATE && type != D3DSBT_VERTEXSTATE)
1437 WARN("Unexpected stateblock type, returning D3DERR_INVALIDCALL.\n");
1438 return D3DERR_INVALIDCALL;
1441 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1444 ERR("Failed to allocate stateblock memory.\n");
1445 return E_OUTOFMEMORY;
1448 hr = stateblock_init(object, This, type, NULL);
1451 WARN("Failed to initialize stateblock, hr %#x.\n", hr);
1452 HeapFree(GetProcessHeap(), 0, object);
1456 TRACE("Created stateblock %p.\n", object);
1457 *stateblock = (IDirect3DStateBlock9 *)object;
1462 static HRESULT WINAPI IDirect3DDevice9Impl_BeginStateBlock(IDirect3DDevice9Ex *iface)
1464 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1467 TRACE("iface %p.\n", iface);
1469 wined3d_mutex_lock();
1470 hr = IWineD3DDevice_BeginStateBlock(This->WineD3DDevice);
1471 wined3d_mutex_unlock();
1476 static HRESULT WINAPI IDirect3DDevice9Impl_EndStateBlock(IDirect3DDevice9Ex *iface, IDirect3DStateBlock9 **stateblock)
1478 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1479 IWineD3DStateBlock *wined3d_stateblock;
1480 IDirect3DStateBlock9Impl *object;
1483 TRACE("iface %p, stateblock %p.\n", iface, stateblock);
1485 wined3d_mutex_lock();
1486 hr = IWineD3DDevice_EndStateBlock(This->WineD3DDevice, &wined3d_stateblock);
1487 wined3d_mutex_unlock();
1490 WARN("IWineD3DDevice_EndStateBlock() failed, hr %#x.\n", hr);
1494 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1497 ERR("Failed to allocate stateblock memory.\n");
1498 IWineD3DStateBlock_Release(wined3d_stateblock);
1499 return E_OUTOFMEMORY;
1502 hr = stateblock_init(object, This, 0, wined3d_stateblock);
1505 WARN("Failed to initialize stateblock, hr %#x.\n", hr);
1506 IWineD3DStateBlock_Release(wined3d_stateblock);
1507 HeapFree(GetProcessHeap(), 0, object);
1511 TRACE("Created stateblock %p.\n", object);
1512 *stateblock = (IDirect3DStateBlock9 *)object;
1517 static HRESULT WINAPI IDirect3DDevice9Impl_SetClipStatus(LPDIRECT3DDEVICE9EX iface, CONST D3DCLIPSTATUS9* pClipStatus) {
1518 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1521 TRACE("iface %p, clip_status %p.\n", iface, pClipStatus);
1523 wined3d_mutex_lock();
1524 hr = IWineD3DDevice_SetClipStatus(This->WineD3DDevice, (const WINED3DCLIPSTATUS *)pClipStatus);
1525 wined3d_mutex_unlock();
1530 static HRESULT WINAPI IDirect3DDevice9Impl_GetClipStatus(LPDIRECT3DDEVICE9EX iface, D3DCLIPSTATUS9* pClipStatus) {
1531 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1534 TRACE("iface %p, clip_status %p.\n", iface, pClipStatus);
1536 wined3d_mutex_lock();
1537 hr = IWineD3DDevice_GetClipStatus(This->WineD3DDevice, (WINED3DCLIPSTATUS *)pClipStatus);
1538 wined3d_mutex_unlock();
1543 static HRESULT WINAPI IDirect3DDevice9Impl_GetTexture(LPDIRECT3DDEVICE9EX iface, DWORD Stage, IDirect3DBaseTexture9 **ppTexture) {
1544 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1545 IWineD3DBaseTexture *retTexture = NULL;
1546 HRESULT rc = D3D_OK;
1548 TRACE("iface %p, stage %u, texture %p.\n", iface, Stage, ppTexture);
1550 if(ppTexture == NULL){
1551 return D3DERR_INVALIDCALL;
1554 wined3d_mutex_lock();
1555 rc = IWineD3DDevice_GetTexture(This->WineD3DDevice, Stage, &retTexture);
1556 if (SUCCEEDED(rc) && NULL != retTexture) {
1557 IWineD3DBaseTexture_GetParent(retTexture, (IUnknown **)ppTexture);
1558 IWineD3DBaseTexture_Release(retTexture);
1561 WARN("Call to get texture (%d) failed (%p)\n", Stage, retTexture);
1565 wined3d_mutex_unlock();
1570 static HRESULT WINAPI IDirect3DDevice9Impl_SetTexture(LPDIRECT3DDEVICE9EX iface, DWORD Stage, IDirect3DBaseTexture9* pTexture) {
1571 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1574 TRACE("iface %p, stage %u, texture %p.\n", iface, Stage, pTexture);
1576 wined3d_mutex_lock();
1577 hr = IWineD3DDevice_SetTexture(This->WineD3DDevice, Stage,
1578 pTexture==NULL ? NULL:((IDirect3DBaseTexture9Impl *)pTexture)->wineD3DBaseTexture);
1579 wined3d_mutex_unlock();
1584 static const WINED3DTEXTURESTAGESTATETYPE tss_lookup[] =
1586 WINED3DTSS_FORCE_DWORD, /* 0, unused */
1587 WINED3DTSS_COLOROP, /* 1, D3DTSS_COLOROP */
1588 WINED3DTSS_COLORARG1, /* 2, D3DTSS_COLORARG1 */
1589 WINED3DTSS_COLORARG2, /* 3, D3DTSS_COLORARG2 */
1590 WINED3DTSS_ALPHAOP, /* 4, D3DTSS_ALPHAOP */
1591 WINED3DTSS_ALPHAARG1, /* 5, D3DTSS_ALPHAARG1 */
1592 WINED3DTSS_ALPHAARG2, /* 6, D3DTSS_ALPHAARG2 */
1593 WINED3DTSS_BUMPENVMAT00, /* 7, D3DTSS_BUMPENVMAT00 */
1594 WINED3DTSS_BUMPENVMAT01, /* 8, D3DTSS_BUMPENVMAT01 */
1595 WINED3DTSS_BUMPENVMAT10, /* 9, D3DTSS_BUMPENVMAT10 */
1596 WINED3DTSS_BUMPENVMAT11, /* 10, D3DTSS_BUMPENVMAT11 */
1597 WINED3DTSS_TEXCOORDINDEX, /* 11, D3DTSS_TEXCOORDINDEX */
1598 WINED3DTSS_FORCE_DWORD, /* 12, unused */
1599 WINED3DTSS_FORCE_DWORD, /* 13, unused */
1600 WINED3DTSS_FORCE_DWORD, /* 14, unused */
1601 WINED3DTSS_FORCE_DWORD, /* 15, unused */
1602 WINED3DTSS_FORCE_DWORD, /* 16, unused */
1603 WINED3DTSS_FORCE_DWORD, /* 17, unused */
1604 WINED3DTSS_FORCE_DWORD, /* 18, unused */
1605 WINED3DTSS_FORCE_DWORD, /* 19, unused */
1606 WINED3DTSS_FORCE_DWORD, /* 20, unused */
1607 WINED3DTSS_FORCE_DWORD, /* 21, unused */
1608 WINED3DTSS_BUMPENVLSCALE, /* 22, D3DTSS_BUMPENVLSCALE */
1609 WINED3DTSS_BUMPENVLOFFSET, /* 23, D3DTSS_BUMPENVLOFFSET */
1610 WINED3DTSS_TEXTURETRANSFORMFLAGS, /* 24, D3DTSS_TEXTURETRANSFORMFLAGS */
1611 WINED3DTSS_FORCE_DWORD, /* 25, unused */
1612 WINED3DTSS_COLORARG0, /* 26, D3DTSS_COLORARG0 */
1613 WINED3DTSS_ALPHAARG0, /* 27, D3DTSS_ALPHAARG0 */
1614 WINED3DTSS_RESULTARG, /* 28, D3DTSS_RESULTARG */
1615 WINED3DTSS_FORCE_DWORD, /* 29, unused */
1616 WINED3DTSS_FORCE_DWORD, /* 30, unused */
1617 WINED3DTSS_FORCE_DWORD, /* 31, unused */
1618 WINED3DTSS_CONSTANT, /* 32, D3DTSS_CONSTANT */
1621 static HRESULT WINAPI IDirect3DDevice9Impl_GetTextureStageState(LPDIRECT3DDEVICE9EX iface, DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD* pValue) {
1622 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1625 TRACE("iface %p, stage %u, state %#x, value %p.\n", iface, Stage, Type, pValue);
1627 wined3d_mutex_lock();
1628 hr = IWineD3DDevice_GetTextureStageState(This->WineD3DDevice, Stage, tss_lookup[Type], pValue);
1629 wined3d_mutex_unlock();
1634 static HRESULT WINAPI IDirect3DDevice9Impl_SetTextureStageState(LPDIRECT3DDEVICE9EX iface, DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD Value) {
1635 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1638 TRACE("iface %p, stage %u, state %#x, value %#x.\n", iface, Stage, Type, Value);
1640 wined3d_mutex_lock();
1641 hr = IWineD3DDevice_SetTextureStageState(This->WineD3DDevice, Stage, tss_lookup[Type], Value);
1642 wined3d_mutex_unlock();
1647 static HRESULT WINAPI IDirect3DDevice9Impl_GetSamplerState(IDirect3DDevice9Ex *iface, DWORD Sampler,
1648 D3DSAMPLERSTATETYPE Type, DWORD *pValue)
1650 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1653 TRACE("iface %p, sampler %u, state %#x, value %p.\n", iface, Sampler, Type, pValue);
1655 wined3d_mutex_lock();
1656 hr = IWineD3DDevice_GetSamplerState(This->WineD3DDevice, Sampler, Type, pValue);
1657 wined3d_mutex_unlock();
1662 static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_SetSamplerState(LPDIRECT3DDEVICE9EX iface, DWORD Sampler, D3DSAMPLERSTATETYPE Type, DWORD Value) {
1663 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1666 TRACE("iface %p, sampler %u, state %#x, value %#x.\n", iface, Sampler, Type, Value);
1668 wined3d_mutex_lock();
1669 hr = IWineD3DDevice_SetSamplerState(This->WineD3DDevice, Sampler, Type, Value);
1670 wined3d_mutex_unlock();
1675 static HRESULT WINAPI IDirect3DDevice9Impl_ValidateDevice(LPDIRECT3DDEVICE9EX iface, DWORD* pNumPasses) {
1676 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1679 TRACE("iface %p, pass_count %p.\n", iface, pNumPasses);
1681 wined3d_mutex_lock();
1682 hr = IWineD3DDevice_ValidateDevice(This->WineD3DDevice, pNumPasses);
1683 wined3d_mutex_unlock();
1688 static HRESULT WINAPI IDirect3DDevice9Impl_SetPaletteEntries(IDirect3DDevice9Ex *iface, UINT PaletteNumber,
1689 const PALETTEENTRY *pEntries)
1691 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1694 TRACE("iface %p, palette_idx %u, entries %p.\n", iface, PaletteNumber, pEntries);
1696 wined3d_mutex_lock();
1697 hr = IWineD3DDevice_SetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
1698 wined3d_mutex_unlock();
1703 static HRESULT WINAPI IDirect3DDevice9Impl_GetPaletteEntries(LPDIRECT3DDEVICE9EX iface, UINT PaletteNumber, PALETTEENTRY* pEntries) {
1704 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1707 TRACE("iface %p, palette_idx %u, entries %p.\n", iface, PaletteNumber, pEntries);
1709 wined3d_mutex_lock();
1710 hr = IWineD3DDevice_GetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
1711 wined3d_mutex_unlock();
1716 static HRESULT WINAPI IDirect3DDevice9Impl_SetCurrentTexturePalette(LPDIRECT3DDEVICE9EX iface, UINT PaletteNumber) {
1717 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1720 TRACE("iface %p, palette_idx %u.\n", iface, PaletteNumber);
1722 wined3d_mutex_lock();
1723 hr = IWineD3DDevice_SetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
1724 wined3d_mutex_unlock();
1729 static HRESULT WINAPI IDirect3DDevice9Impl_GetCurrentTexturePalette(LPDIRECT3DDEVICE9EX iface, UINT* PaletteNumber) {
1730 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1733 TRACE("iface %p, palette_idx %p.\n", iface, PaletteNumber);
1735 wined3d_mutex_lock();
1736 hr = IWineD3DDevice_GetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
1737 wined3d_mutex_unlock();
1742 static HRESULT WINAPI IDirect3DDevice9Impl_SetScissorRect(LPDIRECT3DDEVICE9EX iface, CONST RECT* pRect) {
1743 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1746 TRACE("iface %p, rect %p.\n", iface, pRect);
1748 wined3d_mutex_lock();
1749 hr = IWineD3DDevice_SetScissorRect(This->WineD3DDevice, pRect);
1750 wined3d_mutex_unlock();
1755 static HRESULT WINAPI IDirect3DDevice9Impl_GetScissorRect(LPDIRECT3DDEVICE9EX iface, RECT* pRect) {
1756 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1759 TRACE("iface %p, rect %p.\n", iface, pRect);
1761 wined3d_mutex_lock();
1762 hr = IWineD3DDevice_GetScissorRect(This->WineD3DDevice, pRect);
1763 wined3d_mutex_unlock();
1768 static HRESULT WINAPI IDirect3DDevice9Impl_SetSoftwareVertexProcessing(LPDIRECT3DDEVICE9EX iface, BOOL bSoftware) {
1769 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1772 TRACE("iface %p, software %#x.\n", iface, bSoftware);
1774 wined3d_mutex_lock();
1775 hr = IWineD3DDevice_SetSoftwareVertexProcessing(This->WineD3DDevice, bSoftware);
1776 wined3d_mutex_unlock();
1781 static BOOL WINAPI IDirect3DDevice9Impl_GetSoftwareVertexProcessing(LPDIRECT3DDEVICE9EX iface) {
1782 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1785 TRACE("iface %p.\n", iface);
1787 wined3d_mutex_lock();
1788 ret = IWineD3DDevice_GetSoftwareVertexProcessing(This->WineD3DDevice);
1789 wined3d_mutex_unlock();
1794 static HRESULT WINAPI IDirect3DDevice9Impl_SetNPatchMode(LPDIRECT3DDEVICE9EX iface, float nSegments) {
1795 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1798 TRACE("iface %p, segment_count %.8e.\n", iface, nSegments);
1800 wined3d_mutex_lock();
1801 hr = IWineD3DDevice_SetNPatchMode(This->WineD3DDevice, nSegments);
1802 wined3d_mutex_unlock();
1807 static float WINAPI IDirect3DDevice9Impl_GetNPatchMode(LPDIRECT3DDEVICE9EX iface) {
1808 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1811 TRACE("iface %p.\n", iface);
1813 wined3d_mutex_lock();
1814 ret = IWineD3DDevice_GetNPatchMode(This->WineD3DDevice);
1815 wined3d_mutex_unlock();
1820 static HRESULT WINAPI IDirect3DDevice9Impl_DrawPrimitive(IDirect3DDevice9Ex *iface, D3DPRIMITIVETYPE PrimitiveType,
1821 UINT StartVertex, UINT PrimitiveCount)
1823 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1826 TRACE("iface %p, primitive_type %#x, start_vertex %u, primitive_count %u.\n",
1827 iface, PrimitiveType, StartVertex, PrimitiveCount);
1829 wined3d_mutex_lock();
1830 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1831 hr = IWineD3DDevice_DrawPrimitive(This->WineD3DDevice, StartVertex,
1832 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount));
1833 wined3d_mutex_unlock();
1838 static HRESULT WINAPI IDirect3DDevice9Impl_DrawIndexedPrimitive(LPDIRECT3DDEVICE9EX iface, D3DPRIMITIVETYPE PrimitiveType,
1839 INT BaseVertexIndex, UINT MinVertexIndex, UINT NumVertices, UINT startIndex, UINT primCount) {
1840 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1843 TRACE("iface %p, primitive_type %#x, base_vertex_idx %u, min_vertex_idx %u,\n"
1844 "vertex_count %u, start_idx %u, primitive_count %u.\n",
1845 iface, PrimitiveType, BaseVertexIndex, MinVertexIndex,
1846 NumVertices, startIndex, primCount);
1848 wined3d_mutex_lock();
1849 IWineD3DDevice_SetBaseVertexIndex(This->WineD3DDevice, BaseVertexIndex);
1850 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1851 hr = IWineD3DDevice_DrawIndexedPrimitive(This->WineD3DDevice, startIndex,
1852 vertex_count_from_primitive_count(PrimitiveType, primCount));
1853 wined3d_mutex_unlock();
1858 static HRESULT WINAPI IDirect3DDevice9Impl_DrawPrimitiveUP(IDirect3DDevice9Ex *iface, D3DPRIMITIVETYPE PrimitiveType,
1859 UINT PrimitiveCount, const void *pVertexStreamZeroData, UINT VertexStreamZeroStride)
1861 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1864 TRACE("iface %p, primitive_type %#x, primitive_count %u, data %p, stride %u.\n",
1865 iface, PrimitiveType, PrimitiveCount, pVertexStreamZeroData, VertexStreamZeroStride);
1867 wined3d_mutex_lock();
1868 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1869 hr = IWineD3DDevice_DrawPrimitiveUP(This->WineD3DDevice,
1870 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount),
1871 pVertexStreamZeroData, VertexStreamZeroStride);
1872 wined3d_mutex_unlock();
1877 static HRESULT WINAPI IDirect3DDevice9Impl_DrawIndexedPrimitiveUP(LPDIRECT3DDEVICE9EX iface, D3DPRIMITIVETYPE PrimitiveType, UINT MinVertexIndex,
1878 UINT NumVertexIndices, UINT PrimitiveCount, CONST void* pIndexData,
1879 D3DFORMAT IndexDataFormat, CONST void* pVertexStreamZeroData, UINT VertexStreamZeroStride) {
1880 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1883 TRACE("iface %p, primitive_type %#x, min_vertex_idx %u, index_count %u, primitive_count %u,\n"
1884 "index_data %p, index_format %#x, vertex_data %p, vertex_stride %u.\n",
1885 iface, PrimitiveType, MinVertexIndex, NumVertexIndices, PrimitiveCount,
1886 pIndexData, IndexDataFormat, pVertexStreamZeroData, VertexStreamZeroStride);
1888 wined3d_mutex_lock();
1889 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1890 hr = IWineD3DDevice_DrawIndexedPrimitiveUP(This->WineD3DDevice,
1891 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount), pIndexData,
1892 wined3dformat_from_d3dformat(IndexDataFormat), pVertexStreamZeroData, VertexStreamZeroStride);
1893 wined3d_mutex_unlock();
1898 static HRESULT WINAPI IDirect3DDevice9Impl_ProcessVertices(LPDIRECT3DDEVICE9EX iface, UINT SrcStartIndex, UINT DestIndex, UINT VertexCount, IDirect3DVertexBuffer9* pDestBuffer, IDirect3DVertexDeclaration9* pVertexDecl, DWORD Flags) {
1899 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1900 IDirect3DVertexDeclaration9Impl *Decl = (IDirect3DVertexDeclaration9Impl *) pVertexDecl;
1902 IDirect3DVertexBuffer9Impl *dest = (IDirect3DVertexBuffer9Impl *) pDestBuffer;
1904 TRACE("iface %p, src_start_idx %u, dst_idx %u, vertex_count %u, dst_buffer %p, declaration %p, flags %#x.\n",
1905 iface, SrcStartIndex, DestIndex, VertexCount, pDestBuffer, pVertexDecl, Flags);
1907 wined3d_mutex_lock();
1908 hr = IWineD3DDevice_ProcessVertices(This->WineD3DDevice,SrcStartIndex, DestIndex, VertexCount, dest->wineD3DVertexBuffer, Decl ? Decl->wineD3DVertexDeclaration : NULL, Flags, dest->fvf);
1909 wined3d_mutex_unlock();
1914 static HRESULT WINAPI IDirect3DDevice9Impl_CreateVertexDeclaration(IDirect3DDevice9Ex *iface,
1915 const D3DVERTEXELEMENT9 *elements, IDirect3DVertexDeclaration9 **declaration)
1917 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1918 IDirect3DVertexDeclaration9Impl *object;
1921 TRACE("iface %p, elements %p, declaration %p.\n", iface, elements, declaration);
1925 WARN("Caller passed a NULL declaration, returning D3DERR_INVALIDCALL.\n");
1926 return D3DERR_INVALIDCALL;
1929 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1932 ERR("Failed to allocate vertex declaration memory.\n");
1933 return E_OUTOFMEMORY;
1936 hr = vertexdeclaration_init(object, This, elements);
1939 WARN("Failed to initialize vertex declaration, hr %#x.\n", hr);
1940 HeapFree(GetProcessHeap(), 0, object);
1944 TRACE("Created vertex declaration %p.\n", object);
1945 *declaration = (IDirect3DVertexDeclaration9 *)object;
1950 static IDirect3DVertexDeclaration9 *getConvertedDecl(IDirect3DDevice9Impl *This, DWORD fvf) {
1952 D3DVERTEXELEMENT9* elements = NULL;
1953 IDirect3DVertexDeclaration9* pDecl = NULL;
1954 int p, low, high; /* deliberately signed */
1955 IDirect3DVertexDeclaration9 **convertedDecls = This->convertedDecls;
1957 TRACE("Searching for declaration for fvf %08x... ", fvf);
1960 high = This->numConvertedDecls - 1;
1961 while(low <= high) {
1962 p = (low + high) >> 1;
1964 if(((IDirect3DVertexDeclaration9Impl *) convertedDecls[p])->convFVF == fvf) {
1965 TRACE("found %p\n", convertedDecls[p]);
1966 return convertedDecls[p];
1967 } else if(((IDirect3DVertexDeclaration9Impl *) convertedDecls[p])->convFVF < fvf) {
1973 TRACE("not found. Creating and inserting at position %d.\n", low);
1975 hr = vdecl_convert_fvf(fvf, &elements);
1976 if (hr != S_OK) return NULL;
1978 hr = IDirect3DDevice9Impl_CreateVertexDeclaration((IDirect3DDevice9Ex *) This, elements, &pDecl);
1979 HeapFree(GetProcessHeap(), 0, elements); /* CreateVertexDeclaration makes a copy */
1980 if (hr != S_OK) return NULL;
1982 if(This->declArraySize == This->numConvertedDecls) {
1983 int grow = max(This->declArraySize / 2, 8);
1984 convertedDecls = HeapReAlloc(GetProcessHeap(), 0, convertedDecls,
1985 sizeof(convertedDecls[0]) * (This->numConvertedDecls + grow));
1986 if(!convertedDecls) {
1987 /* This will destroy it */
1988 IDirect3DVertexDeclaration9_Release(pDecl);
1991 This->convertedDecls = convertedDecls;
1992 This->declArraySize += grow;
1995 memmove(convertedDecls + low + 1, convertedDecls + low, sizeof(IDirect3DVertexDeclaration9Impl *) * (This->numConvertedDecls - low));
1996 convertedDecls[low] = pDecl;
1997 This->numConvertedDecls++;
1999 /* Will prevent the decl from being destroyed */
2000 ((IDirect3DVertexDeclaration9Impl *) pDecl)->convFVF = fvf;
2001 IDirect3DVertexDeclaration9_Release(pDecl); /* Does not destroy now */
2003 TRACE("Returning %p. %d decls in array\n", pDecl, This->numConvertedDecls);
2007 static HRESULT WINAPI IDirect3DDevice9Impl_SetFVF(LPDIRECT3DDEVICE9EX iface, DWORD FVF) {
2008 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2009 IDirect3DVertexDeclaration9 *decl;
2012 TRACE("iface %p, fvf %#x.\n", iface, FVF);
2016 WARN("%#x is not a valid FVF\n", FVF);
2020 wined3d_mutex_lock();
2021 decl = getConvertedDecl(This, FVF);
2022 wined3d_mutex_unlock();
2026 /* Any situation when this should happen, except out of memory? */
2027 ERR("Failed to create a converted vertex declaration\n");
2028 return D3DERR_DRIVERINTERNALERROR;
2031 hr = IDirect3DDevice9Impl_SetVertexDeclaration(iface, decl);
2032 if (FAILED(hr)) ERR("Failed to set vertex declaration\n");
2037 static HRESULT WINAPI IDirect3DDevice9Impl_GetFVF(IDirect3DDevice9Ex *iface, DWORD *pFVF)
2039 IDirect3DVertexDeclaration9 *decl;
2042 TRACE("iface %p, fvf %p.\n", iface, pFVF);
2044 hr = IDirect3DDevice9_GetVertexDeclaration(iface, &decl);
2047 WARN("Failed to get vertex declaration, %#x\n", hr);
2054 *pFVF = ((IDirect3DVertexDeclaration9Impl *)decl)->convFVF;
2055 IDirect3DVertexDeclaration9_Release(decl);
2062 TRACE("Returning FVF %#x\n", *pFVF);
2067 static HRESULT WINAPI IDirect3DDevice9Impl_CreateVertexShader(IDirect3DDevice9Ex *iface,
2068 const DWORD *byte_code, IDirect3DVertexShader9 **shader)
2070 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2071 IDirect3DVertexShader9Impl *object;
2074 TRACE("iface %p, byte_code %p, shader %p.\n", iface, byte_code, shader);
2076 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2079 ERR("Failed to allocate vertex shader memory.\n");
2080 return E_OUTOFMEMORY;
2083 hr = vertexshader_init(object, This, byte_code);
2086 WARN("Failed to initialize vertex shader, hr %#x.\n", hr);
2087 HeapFree(GetProcessHeap(), 0, object);
2091 TRACE("Created vertex shader %p.\n", object);
2092 *shader = (IDirect3DVertexShader9 *)object;
2097 static HRESULT WINAPI IDirect3DDevice9Impl_SetStreamSource(LPDIRECT3DDEVICE9EX iface, UINT StreamNumber, IDirect3DVertexBuffer9* pStreamData, UINT OffsetInBytes, UINT Stride) {
2098 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2101 TRACE("iface %p, stream_idx %u, buffer %p, offset %u, stride %u.\n",
2102 iface, StreamNumber, pStreamData, OffsetInBytes, Stride);
2104 wined3d_mutex_lock();
2105 hr = IWineD3DDevice_SetStreamSource(This->WineD3DDevice, StreamNumber,
2106 pStreamData ? ((IDirect3DVertexBuffer9Impl *)pStreamData)->wineD3DVertexBuffer : NULL,
2107 OffsetInBytes, Stride);
2108 wined3d_mutex_unlock();
2113 static HRESULT WINAPI IDirect3DDevice9Impl_GetStreamSource(LPDIRECT3DDEVICE9EX iface, UINT StreamNumber, IDirect3DVertexBuffer9 **pStream, UINT* OffsetInBytes, UINT* pStride) {
2114 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2115 IWineD3DBuffer *retStream = NULL;
2116 HRESULT rc = D3D_OK;
2118 TRACE("iface %p, stream_idx %u, buffer %p, offset %p, stride %p.\n",
2119 iface, StreamNumber, pStream, OffsetInBytes, pStride);
2121 if(pStream == NULL){
2122 return D3DERR_INVALIDCALL;
2125 wined3d_mutex_lock();
2126 rc = IWineD3DDevice_GetStreamSource(This->WineD3DDevice, StreamNumber, &retStream, OffsetInBytes, pStride);
2127 if (rc == D3D_OK && NULL != retStream) {
2128 IWineD3DBuffer_GetParent(retStream, (IUnknown **)pStream);
2129 IWineD3DBuffer_Release(retStream);
2132 FIXME("Call to GetStreamSource failed %p %p\n", OffsetInBytes, pStride);
2136 wined3d_mutex_unlock();
2141 static HRESULT WINAPI IDirect3DDevice9Impl_SetStreamSourceFreq(IDirect3DDevice9Ex *iface, UINT StreamNumber,
2144 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2147 TRACE("iface %p, stream_idx %u, freq %u.\n", iface, StreamNumber, Divider);
2149 wined3d_mutex_lock();
2150 hr = IWineD3DDevice_SetStreamSourceFreq(This->WineD3DDevice, StreamNumber, Divider);
2151 wined3d_mutex_unlock();
2156 static HRESULT WINAPI IDirect3DDevice9Impl_GetStreamSourceFreq(LPDIRECT3DDEVICE9EX iface, UINT StreamNumber, UINT* Divider) {
2157 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2160 TRACE("iface %p, stream_idx %u, freq %p.\n", iface, StreamNumber, Divider);
2162 wined3d_mutex_lock();
2163 hr = IWineD3DDevice_GetStreamSourceFreq(This->WineD3DDevice, StreamNumber, Divider);
2164 wined3d_mutex_unlock();
2169 static HRESULT WINAPI IDirect3DDevice9Impl_SetIndices(LPDIRECT3DDEVICE9EX iface, IDirect3DIndexBuffer9* pIndexData) {
2170 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2172 IDirect3DIndexBuffer9Impl *ib = (IDirect3DIndexBuffer9Impl *) pIndexData;
2174 TRACE("iface %p, buffer %p.\n", iface, pIndexData);
2176 wined3d_mutex_lock();
2177 hr = IWineD3DDevice_SetIndexBuffer(This->WineD3DDevice,
2178 ib ? ib->wineD3DIndexBuffer : NULL,
2179 ib ? ib->format : WINED3DFMT_UNKNOWN);
2180 wined3d_mutex_unlock();
2185 static HRESULT WINAPI IDirect3DDevice9Impl_GetIndices(LPDIRECT3DDEVICE9EX iface, IDirect3DIndexBuffer9 **ppIndexData) {
2186 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2187 IWineD3DBuffer *retIndexData = NULL;
2188 HRESULT rc = D3D_OK;
2190 TRACE("iface %p, buffer %p.\n", iface, ppIndexData);
2192 if(ppIndexData == NULL){
2193 return D3DERR_INVALIDCALL;
2196 wined3d_mutex_lock();
2197 rc = IWineD3DDevice_GetIndexBuffer(This->WineD3DDevice, &retIndexData);
2198 if (SUCCEEDED(rc) && retIndexData) {
2199 IWineD3DBuffer_GetParent(retIndexData, (IUnknown **)ppIndexData);
2200 IWineD3DBuffer_Release(retIndexData);
2202 if (FAILED(rc)) FIXME("Call to GetIndices failed\n");
2203 *ppIndexData = NULL;
2205 wined3d_mutex_unlock();
2210 static HRESULT WINAPI IDirect3DDevice9Impl_CreatePixelShader(IDirect3DDevice9Ex *iface,
2211 const DWORD *byte_code, IDirect3DPixelShader9 **shader)
2213 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2214 IDirect3DPixelShader9Impl *object;
2217 TRACE("iface %p, byte_code %p, shader %p.\n", iface, byte_code, shader);
2219 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2222 FIXME("Failed to allocate pixel shader memory.\n");
2223 return E_OUTOFMEMORY;
2226 hr = pixelshader_init(object, This, byte_code);
2229 WARN("Failed to initialize pixel shader, hr %#x.\n", hr);
2230 HeapFree(GetProcessHeap(), 0, object);
2234 TRACE("Created pixel shader %p.\n", object);
2235 *shader = (IDirect3DPixelShader9 *)object;
2240 static HRESULT WINAPI IDirect3DDevice9Impl_DrawRectPatch(LPDIRECT3DDEVICE9EX iface, UINT Handle, CONST float* pNumSegs, CONST D3DRECTPATCH_INFO* pRectPatchInfo) {
2241 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2244 TRACE("iface %p, handle %#x, segment_count %p, patch_info %p.\n",
2245 iface, Handle, pNumSegs, pRectPatchInfo);
2247 wined3d_mutex_lock();
2248 hr = IWineD3DDevice_DrawRectPatch(This->WineD3DDevice, Handle, pNumSegs, (CONST WINED3DRECTPATCH_INFO *)pRectPatchInfo);
2249 wined3d_mutex_unlock();
2254 static HRESULT WINAPI IDirect3DDevice9Impl_DrawTriPatch(LPDIRECT3DDEVICE9EX iface, UINT Handle, CONST float* pNumSegs, CONST D3DTRIPATCH_INFO* pTriPatchInfo) {
2255 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2258 TRACE("iface %p, handle %#x, segment_count %p, patch_info %p.\n",
2259 iface, Handle, pNumSegs, pTriPatchInfo);
2261 wined3d_mutex_lock();
2262 hr = IWineD3DDevice_DrawTriPatch(This->WineD3DDevice, Handle, pNumSegs, (CONST WINED3DTRIPATCH_INFO *)pTriPatchInfo);
2263 wined3d_mutex_unlock();
2268 static HRESULT WINAPI IDirect3DDevice9Impl_DeletePatch(LPDIRECT3DDEVICE9EX iface, UINT Handle) {
2269 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2272 TRACE("iface %p, handle %#x.\n", iface, Handle);
2274 wined3d_mutex_lock();
2275 hr = IWineD3DDevice_DeletePatch(This->WineD3DDevice, Handle);
2276 wined3d_mutex_unlock();
2281 static HRESULT WINAPI IDirect3DDevice9Impl_CreateQuery(IDirect3DDevice9Ex *iface,
2282 D3DQUERYTYPE type, IDirect3DQuery9 **query)
2284 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2285 IDirect3DQuery9Impl *object;
2288 TRACE("iface %p, type %#x, query %p.\n", iface, type, query);
2290 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2293 ERR("Failed to allocate query memory.\n");
2294 return E_OUTOFMEMORY;
2297 hr = query_init(object, This, type);
2300 WARN("Failed to initialize query, hr %#x.\n", hr);
2301 HeapFree(GetProcessHeap(), 0, object);
2305 TRACE("Created query %p.\n", object);
2306 if (query) *query = (IDirect3DQuery9 *)object;
2307 else IDirect3DQuery9_Release((IDirect3DQuery9 *)object);
2312 static HRESULT WINAPI IDirect3DDevice9ExImpl_SetConvolutionMonoKernel(IDirect3DDevice9Ex *iface,
2313 UINT width, UINT height, float *rows, float *columns)
2315 FIXME("iface %p, width %u, height %u, rows %p, columns %p stub!\n",
2316 iface, width, height, rows, columns);
2318 return WINED3DERR_INVALIDCALL;
2321 static HRESULT WINAPI IDirect3DDevice9ExImpl_ComposeRects(IDirect3DDevice9Ex *iface,
2322 IDirect3DSurface9 *src_surface, IDirect3DSurface9 *dst_surface, IDirect3DVertexBuffer9 *src_descs,
2323 UINT rect_count, IDirect3DVertexBuffer9 *dst_descs, D3DCOMPOSERECTSOP operation, INT offset_x, INT offset_y)
2325 FIXME("iface %p, src_surface %p, dst_surface %p, src_descs %p, rect_count %u,\n"
2326 "dst_descs %p, operation %#x, offset_x %u, offset_y %u stub!\n",
2327 iface, src_surface, dst_surface, src_descs, rect_count,
2328 dst_descs, operation, offset_x, offset_y);
2330 return WINED3DERR_INVALIDCALL;
2333 static HRESULT WINAPI IDirect3DDevice9ExImpl_PresentEx(IDirect3DDevice9Ex *iface,
2334 const RECT *src_rect, const RECT *dst_rect, HWND dst_window_override,
2335 const RGNDATA *dirty_region, DWORD flags)
2337 FIXME("iface %p, src_rect %p, dst_rect %p, dst_window_override %p, dirty_region %p, flags %#x stub!\n",
2338 iface, src_rect, dst_rect, dst_window_override, dirty_region, flags);
2340 return WINED3DERR_INVALIDCALL;
2343 static HRESULT WINAPI IDirect3DDevice9ExImpl_GetGPUThreadPriority(IDirect3DDevice9Ex *iface, INT *priority)
2345 FIXME("iface %p, priority %p stub!\n", iface, priority);
2347 return WINED3DERR_INVALIDCALL;
2350 static HRESULT WINAPI IDirect3DDevice9ExImpl_SetGPUThreadPriority(IDirect3DDevice9Ex *iface, INT priority)
2352 FIXME("iface %p, priority %d stub!\n", iface, priority);
2354 return WINED3DERR_INVALIDCALL;
2357 static HRESULT WINAPI IDirect3DDevice9ExImpl_WaitForVBlank(IDirect3DDevice9Ex *iface, UINT swapchain_idx)
2359 FIXME("iface %p, swapchain_idx %u stub!\n", iface, swapchain_idx);
2361 return WINED3DERR_INVALIDCALL;
2364 static HRESULT WINAPI IDirect3DDevice9ExImpl_CheckResourceResidency(IDirect3DDevice9Ex *iface,
2365 IDirect3DResource9 **resources, UINT32 resource_count)
2367 FIXME("iface %p, resources %p, resource_count %u stub!\n",
2368 iface, resources, resource_count);
2370 return WINED3DERR_INVALIDCALL;
2373 static HRESULT WINAPI IDirect3DDevice9ExImpl_SetMaximumFrameLatency(IDirect3DDevice9Ex *iface, UINT max_latency)
2375 FIXME("iface %p, max_latency %u stub!\n", iface, max_latency);
2377 return WINED3DERR_INVALIDCALL;
2380 static HRESULT WINAPI IDirect3DDevice9ExImpl_GetMaximumFrameLatency(IDirect3DDevice9Ex *iface, UINT *max_latency)
2382 FIXME("iface %p, max_latency %p stub!\n", iface, max_latency);
2386 return WINED3DERR_INVALIDCALL;
2389 static HRESULT WINAPI IDirect3DDevice9ExImpl_CheckDeviceState(IDirect3DDevice9Ex *iface, HWND dst_window)
2391 FIXME("iface %p, dst_window %p stub!\n", iface, dst_window);
2393 return WINED3DERR_INVALIDCALL;
2396 static HRESULT WINAPI IDirect3DDevice9ExImpl_CreateRenderTargetEx(IDirect3DDevice9Ex *iface,
2397 UINT width, UINT height, D3DFORMAT format, D3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality,
2398 BOOL lockable, IDirect3DSurface9 **surface, HANDLE *shared_handle, DWORD usage)
2400 FIXME("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u,\n"
2401 "lockable %#x, surface %p, shared_handle %p, usage %#x stub!\n",
2402 iface, width, height, format, multisample_type, multisample_quality,
2403 lockable, surface, shared_handle, usage);
2405 return WINED3DERR_INVALIDCALL;
2408 static HRESULT WINAPI IDirect3DDevice9ExImpl_CreateOffscreenPlainSurfaceEx(IDirect3DDevice9Ex *iface,
2409 UINT width, UINT height, D3DFORMAT format, D3DPOOL pool, IDirect3DSurface9 **surface,
2410 HANDLE *shared_handle, DWORD usage)
2412 FIXME("iface %p, width %u, height %u, format %#x, pool %#x, surface %p, shared_handle %p, usage %#x stub!\n",
2413 iface, width, height, format, pool, surface, shared_handle, usage);
2415 return WINED3DERR_INVALIDCALL;
2418 static HRESULT WINAPI IDirect3DDevice9ExImpl_CreateDepthStencilSurfaceEx(IDirect3DDevice9Ex *iface,
2419 UINT width, UINT height, D3DFORMAT format, D3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality,
2420 BOOL discard, IDirect3DSurface9 **surface, HANDLE *shared_handle, DWORD usage)
2422 FIXME("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u,\n"
2423 "discard %#x, surface %p, shared_handle %p, usage %#x stub!\n",
2424 iface, width, height, format, multisample_type, multisample_quality,
2425 discard, surface, shared_handle, usage);
2427 return WINED3DERR_INVALIDCALL;
2430 static HRESULT WINAPI IDirect3DDevice9ExImpl_ResetEx(IDirect3DDevice9Ex *iface,
2431 D3DPRESENT_PARAMETERS *present_parameters, D3DDISPLAYMODEEX *mode)
2433 FIXME("iface %p, present_parameters %p, mode %p stub!\n", iface, present_parameters, mode);
2435 return WINED3DERR_INVALIDCALL;
2438 static HRESULT WINAPI IDirect3DDevice9ExImpl_GetDisplayModeEx(IDirect3DDevice9Ex *iface,
2439 UINT swapchain_idx, D3DDISPLAYMODEEX *mode, D3DDISPLAYROTATION *rotation)
2441 FIXME("iface %p, swapchain_idx %u, mode %p, rotation %p stub!\n", iface, swapchain_idx, mode, rotation);
2443 return WINED3DERR_INVALIDCALL;
2446 static const IDirect3DDevice9ExVtbl Direct3DDevice9_Vtbl =
2449 IDirect3DDevice9Impl_QueryInterface,
2450 IDirect3DDevice9Impl_AddRef,
2451 IDirect3DDevice9Impl_Release,
2452 /* IDirect3DDevice9 */
2453 IDirect3DDevice9Impl_TestCooperativeLevel,
2454 IDirect3DDevice9Impl_GetAvailableTextureMem,
2455 IDirect3DDevice9Impl_EvictManagedResources,
2456 IDirect3DDevice9Impl_GetDirect3D,
2457 IDirect3DDevice9Impl_GetDeviceCaps,
2458 IDirect3DDevice9Impl_GetDisplayMode,
2459 IDirect3DDevice9Impl_GetCreationParameters,
2460 IDirect3DDevice9Impl_SetCursorProperties,
2461 IDirect3DDevice9Impl_SetCursorPosition,
2462 IDirect3DDevice9Impl_ShowCursor,
2463 IDirect3DDevice9Impl_CreateAdditionalSwapChain,
2464 IDirect3DDevice9Impl_GetSwapChain,
2465 IDirect3DDevice9Impl_GetNumberOfSwapChains,
2466 IDirect3DDevice9Impl_Reset,
2467 IDirect3DDevice9Impl_Present,
2468 IDirect3DDevice9Impl_GetBackBuffer,
2469 IDirect3DDevice9Impl_GetRasterStatus,
2470 IDirect3DDevice9Impl_SetDialogBoxMode,
2471 IDirect3DDevice9Impl_SetGammaRamp,
2472 IDirect3DDevice9Impl_GetGammaRamp,
2473 IDirect3DDevice9Impl_CreateTexture,
2474 IDirect3DDevice9Impl_CreateVolumeTexture,
2475 IDirect3DDevice9Impl_CreateCubeTexture,
2476 IDirect3DDevice9Impl_CreateVertexBuffer,
2477 IDirect3DDevice9Impl_CreateIndexBuffer,
2478 IDirect3DDevice9Impl_CreateRenderTarget,
2479 IDirect3DDevice9Impl_CreateDepthStencilSurface,
2480 IDirect3DDevice9Impl_UpdateSurface,
2481 IDirect3DDevice9Impl_UpdateTexture,
2482 IDirect3DDevice9Impl_GetRenderTargetData,
2483 IDirect3DDevice9Impl_GetFrontBufferData,
2484 IDirect3DDevice9Impl_StretchRect,
2485 IDirect3DDevice9Impl_ColorFill,
2486 IDirect3DDevice9Impl_CreateOffscreenPlainSurface,
2487 IDirect3DDevice9Impl_SetRenderTarget,
2488 IDirect3DDevice9Impl_GetRenderTarget,
2489 IDirect3DDevice9Impl_SetDepthStencilSurface,
2490 IDirect3DDevice9Impl_GetDepthStencilSurface,
2491 IDirect3DDevice9Impl_BeginScene,
2492 IDirect3DDevice9Impl_EndScene,
2493 IDirect3DDevice9Impl_Clear,
2494 IDirect3DDevice9Impl_SetTransform,
2495 IDirect3DDevice9Impl_GetTransform,
2496 IDirect3DDevice9Impl_MultiplyTransform,
2497 IDirect3DDevice9Impl_SetViewport,
2498 IDirect3DDevice9Impl_GetViewport,
2499 IDirect3DDevice9Impl_SetMaterial,
2500 IDirect3DDevice9Impl_GetMaterial,
2501 IDirect3DDevice9Impl_SetLight,
2502 IDirect3DDevice9Impl_GetLight,
2503 IDirect3DDevice9Impl_LightEnable,
2504 IDirect3DDevice9Impl_GetLightEnable,
2505 IDirect3DDevice9Impl_SetClipPlane,
2506 IDirect3DDevice9Impl_GetClipPlane,
2507 IDirect3DDevice9Impl_SetRenderState,
2508 IDirect3DDevice9Impl_GetRenderState,
2509 IDirect3DDevice9Impl_CreateStateBlock,
2510 IDirect3DDevice9Impl_BeginStateBlock,
2511 IDirect3DDevice9Impl_EndStateBlock,
2512 IDirect3DDevice9Impl_SetClipStatus,
2513 IDirect3DDevice9Impl_GetClipStatus,
2514 IDirect3DDevice9Impl_GetTexture,
2515 IDirect3DDevice9Impl_SetTexture,
2516 IDirect3DDevice9Impl_GetTextureStageState,
2517 IDirect3DDevice9Impl_SetTextureStageState,
2518 IDirect3DDevice9Impl_GetSamplerState,
2519 IDirect3DDevice9Impl_SetSamplerState,
2520 IDirect3DDevice9Impl_ValidateDevice,
2521 IDirect3DDevice9Impl_SetPaletteEntries,
2522 IDirect3DDevice9Impl_GetPaletteEntries,
2523 IDirect3DDevice9Impl_SetCurrentTexturePalette,
2524 IDirect3DDevice9Impl_GetCurrentTexturePalette,
2525 IDirect3DDevice9Impl_SetScissorRect,
2526 IDirect3DDevice9Impl_GetScissorRect,
2527 IDirect3DDevice9Impl_SetSoftwareVertexProcessing,
2528 IDirect3DDevice9Impl_GetSoftwareVertexProcessing,
2529 IDirect3DDevice9Impl_SetNPatchMode,
2530 IDirect3DDevice9Impl_GetNPatchMode,
2531 IDirect3DDevice9Impl_DrawPrimitive,
2532 IDirect3DDevice9Impl_DrawIndexedPrimitive,
2533 IDirect3DDevice9Impl_DrawPrimitiveUP,
2534 IDirect3DDevice9Impl_DrawIndexedPrimitiveUP,
2535 IDirect3DDevice9Impl_ProcessVertices,
2536 IDirect3DDevice9Impl_CreateVertexDeclaration,
2537 IDirect3DDevice9Impl_SetVertexDeclaration,
2538 IDirect3DDevice9Impl_GetVertexDeclaration,
2539 IDirect3DDevice9Impl_SetFVF,
2540 IDirect3DDevice9Impl_GetFVF,
2541 IDirect3DDevice9Impl_CreateVertexShader,
2542 IDirect3DDevice9Impl_SetVertexShader,
2543 IDirect3DDevice9Impl_GetVertexShader,
2544 IDirect3DDevice9Impl_SetVertexShaderConstantF,
2545 IDirect3DDevice9Impl_GetVertexShaderConstantF,
2546 IDirect3DDevice9Impl_SetVertexShaderConstantI,
2547 IDirect3DDevice9Impl_GetVertexShaderConstantI,
2548 IDirect3DDevice9Impl_SetVertexShaderConstantB,
2549 IDirect3DDevice9Impl_GetVertexShaderConstantB,
2550 IDirect3DDevice9Impl_SetStreamSource,
2551 IDirect3DDevice9Impl_GetStreamSource,
2552 IDirect3DDevice9Impl_SetStreamSourceFreq,
2553 IDirect3DDevice9Impl_GetStreamSourceFreq,
2554 IDirect3DDevice9Impl_SetIndices,
2555 IDirect3DDevice9Impl_GetIndices,
2556 IDirect3DDevice9Impl_CreatePixelShader,
2557 IDirect3DDevice9Impl_SetPixelShader,
2558 IDirect3DDevice9Impl_GetPixelShader,
2559 IDirect3DDevice9Impl_SetPixelShaderConstantF,
2560 IDirect3DDevice9Impl_GetPixelShaderConstantF,
2561 IDirect3DDevice9Impl_SetPixelShaderConstantI,
2562 IDirect3DDevice9Impl_GetPixelShaderConstantI,
2563 IDirect3DDevice9Impl_SetPixelShaderConstantB,
2564 IDirect3DDevice9Impl_GetPixelShaderConstantB,
2565 IDirect3DDevice9Impl_DrawRectPatch,
2566 IDirect3DDevice9Impl_DrawTriPatch,
2567 IDirect3DDevice9Impl_DeletePatch,
2568 IDirect3DDevice9Impl_CreateQuery,
2569 /* IDirect3DDevice9Ex */
2570 IDirect3DDevice9ExImpl_SetConvolutionMonoKernel,
2571 IDirect3DDevice9ExImpl_ComposeRects,
2572 IDirect3DDevice9ExImpl_PresentEx,
2573 IDirect3DDevice9ExImpl_GetGPUThreadPriority,
2574 IDirect3DDevice9ExImpl_SetGPUThreadPriority,
2575 IDirect3DDevice9ExImpl_WaitForVBlank,
2576 IDirect3DDevice9ExImpl_CheckResourceResidency,
2577 IDirect3DDevice9ExImpl_SetMaximumFrameLatency,
2578 IDirect3DDevice9ExImpl_GetMaximumFrameLatency,
2579 IDirect3DDevice9ExImpl_CheckDeviceState,
2580 IDirect3DDevice9ExImpl_CreateRenderTargetEx,
2581 IDirect3DDevice9ExImpl_CreateOffscreenPlainSurfaceEx,
2582 IDirect3DDevice9ExImpl_CreateDepthStencilSurfaceEx,
2583 IDirect3DDevice9ExImpl_ResetEx,
2584 IDirect3DDevice9ExImpl_GetDisplayModeEx
2587 /* IWineD3DDeviceParent IUnknown methods */
2589 static inline struct IDirect3DDevice9Impl *device_from_device_parent(IWineD3DDeviceParent *iface)
2591 return (struct IDirect3DDevice9Impl *)((char*)iface
2592 - FIELD_OFFSET(struct IDirect3DDevice9Impl, device_parent_vtbl));
2595 static HRESULT STDMETHODCALLTYPE device_parent_QueryInterface(IWineD3DDeviceParent *iface, REFIID riid, void **object)
2597 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
2598 return IDirect3DDevice9Impl_QueryInterface((IDirect3DDevice9Ex *)This, riid, object);
2601 static ULONG STDMETHODCALLTYPE device_parent_AddRef(IWineD3DDeviceParent *iface)
2603 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
2604 return IDirect3DDevice9Impl_AddRef((IDirect3DDevice9Ex *)This);
2607 static ULONG STDMETHODCALLTYPE device_parent_Release(IWineD3DDeviceParent *iface)
2609 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
2610 return IDirect3DDevice9Impl_Release((IDirect3DDevice9Ex *)This);
2613 /* IWineD3DDeviceParent methods */
2615 static void STDMETHODCALLTYPE device_parent_WineD3DDeviceCreated(IWineD3DDeviceParent *iface, IWineD3DDevice *device)
2617 TRACE("iface %p, device %p\n", iface, device);
2620 static HRESULT STDMETHODCALLTYPE device_parent_CreateSurface(IWineD3DDeviceParent *iface,
2621 IUnknown *superior, UINT width, UINT height, enum wined3d_format_id format, DWORD usage,
2622 WINED3DPOOL pool, UINT level, WINED3DCUBEMAP_FACES face, IWineD3DSurface **surface)
2624 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
2625 IDirect3DSurface9Impl *d3d_surface;
2626 BOOL lockable = TRUE;
2629 TRACE("iface %p, superior %p, width %u, height %u, format %#x, usage %#x,\n"
2630 "\tpool %#x, level %u, face %u, surface %p\n",
2631 iface, superior, width, height, format, usage, pool, level, face, surface);
2633 if (pool == WINED3DPOOL_DEFAULT && !(usage & D3DUSAGE_DYNAMIC))
2636 hr = IDirect3DDevice9Impl_CreateSurface((IDirect3DDevice9Ex *)This, width, height,
2637 d3dformat_from_wined3dformat(format), lockable, FALSE /* Discard */, level,
2638 (IDirect3DSurface9 **)&d3d_surface, usage, pool, D3DMULTISAMPLE_NONE, 0 /* MultisampleQuality */);
2641 ERR("(%p) CreateSurface failed, returning %#x\n", iface, hr);
2645 *surface = d3d_surface->wineD3DSurface;
2646 IWineD3DSurface_AddRef(*surface);
2648 d3d_surface->container = superior;
2649 IDirect3DDevice9Ex_Release(d3d_surface->parentDevice);
2650 d3d_surface->parentDevice = NULL;
2652 IDirect3DSurface9_Release((IDirect3DSurface9 *)d3d_surface);
2653 d3d_surface->forwardReference = superior;
2658 static HRESULT STDMETHODCALLTYPE device_parent_CreateRenderTarget(IWineD3DDeviceParent *iface,
2659 IUnknown *superior, UINT width, UINT height, enum wined3d_format_id format,
2660 WINED3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality, BOOL lockable,
2661 IWineD3DSurface **surface)
2663 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
2664 IDirect3DSurface9Impl *d3d_surface;
2667 TRACE("iface %p, superior %p, width %u, height %u, format %#x, multisample_type %#x,\n"
2668 "\tmultisample_quality %u, lockable %u, surface %p\n",
2669 iface, superior, width, height, format, multisample_type, multisample_quality, lockable, surface);
2671 hr = IDirect3DDevice9Impl_CreateRenderTarget((IDirect3DDevice9Ex *)This, width, height,
2672 d3dformat_from_wined3dformat(format), multisample_type, multisample_quality, lockable,
2673 (IDirect3DSurface9 **)&d3d_surface, NULL);
2676 ERR("(%p) CreateRenderTarget failed, returning %#x\n", iface, hr);
2680 *surface = d3d_surface->wineD3DSurface;
2681 IWineD3DSurface_AddRef(*surface);
2683 d3d_surface->container = superior;
2684 /* Implicit surfaces are created with an refcount of 0 */
2685 IDirect3DSurface9_Release((IDirect3DSurface9 *)d3d_surface);
2690 static HRESULT STDMETHODCALLTYPE device_parent_CreateDepthStencilSurface(IWineD3DDeviceParent *iface,
2691 UINT width, UINT height, enum wined3d_format_id format, WINED3DMULTISAMPLE_TYPE multisample_type,
2692 DWORD multisample_quality, BOOL discard, IWineD3DSurface **surface)
2694 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
2695 IDirect3DSurface9Impl *d3d_surface;
2698 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x,\n"
2699 "\tmultisample_quality %u, discard %u, surface %p\n",
2700 iface, width, height, format, multisample_type, multisample_quality, discard, surface);
2702 hr = IDirect3DDevice9Impl_CreateDepthStencilSurface((IDirect3DDevice9Ex *)This, width, height,
2703 d3dformat_from_wined3dformat(format), multisample_type, multisample_quality, discard,
2704 (IDirect3DSurface9 **)&d3d_surface, NULL);
2707 ERR("(%p) CreateDepthStencilSurface failed, returning %#x\n", iface, hr);
2711 *surface = d3d_surface->wineD3DSurface;
2712 IWineD3DSurface_AddRef(*surface);
2713 d3d_surface->container = (IUnknown *)This;
2714 /* Implicit surfaces are created with an refcount of 0 */
2715 IDirect3DSurface9_Release((IDirect3DSurface9 *)d3d_surface);
2720 static HRESULT STDMETHODCALLTYPE device_parent_CreateVolume(IWineD3DDeviceParent *iface,
2721 IUnknown *superior, UINT width, UINT height, UINT depth, enum wined3d_format_id format,
2722 WINED3DPOOL pool, DWORD usage, IWineD3DVolume **volume)
2724 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
2725 IDirect3DVolume9Impl *object;
2728 TRACE("iface %p, superior %p, width %u, height %u, depth %u, format %#x, pool %#x, usage %#x, volume %p\n",
2729 iface, superior, width, height, depth, format, pool, usage, volume);
2731 /* Allocate the storage for the device */
2732 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2735 FIXME("Allocation of memory failed\n");
2737 return D3DERR_OUTOFVIDEOMEMORY;
2740 hr = volume_init(object, This, width, height, depth, usage, format, pool);
2743 WARN("Failed to initialize volume, hr %#x.\n", hr);
2744 HeapFree(GetProcessHeap(), 0, object);
2748 *volume = object->wineD3DVolume;
2749 IWineD3DVolume_AddRef(*volume);
2750 IDirect3DVolume9_Release((IDirect3DVolume9 *)object);
2752 object->container = superior;
2753 object->forwardReference = superior;
2755 TRACE("(%p) Created volume %p\n", iface, object);
2760 static HRESULT STDMETHODCALLTYPE device_parent_CreateSwapChain(IWineD3DDeviceParent *iface,
2761 WINED3DPRESENT_PARAMETERS *present_parameters, IWineD3DSwapChain **swapchain)
2763 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
2764 IDirect3DSwapChain9Impl *d3d_swapchain;
2765 D3DPRESENT_PARAMETERS local_parameters;
2768 TRACE("iface %p, present_parameters %p, swapchain %p\n", iface, present_parameters, swapchain);
2770 /* Copy the presentation parameters */
2771 local_parameters.BackBufferWidth = present_parameters->BackBufferWidth;
2772 local_parameters.BackBufferHeight = present_parameters->BackBufferHeight;
2773 local_parameters.BackBufferFormat = d3dformat_from_wined3dformat(present_parameters->BackBufferFormat);
2774 local_parameters.BackBufferCount = present_parameters->BackBufferCount;
2775 local_parameters.MultiSampleType = present_parameters->MultiSampleType;
2776 local_parameters.MultiSampleQuality = present_parameters->MultiSampleQuality;
2777 local_parameters.SwapEffect = present_parameters->SwapEffect;
2778 local_parameters.hDeviceWindow = present_parameters->hDeviceWindow;
2779 local_parameters.Windowed = present_parameters->Windowed;
2780 local_parameters.EnableAutoDepthStencil = present_parameters->EnableAutoDepthStencil;
2781 local_parameters.AutoDepthStencilFormat = d3dformat_from_wined3dformat(present_parameters->AutoDepthStencilFormat);
2782 local_parameters.Flags = present_parameters->Flags;
2783 local_parameters.FullScreen_RefreshRateInHz = present_parameters->FullScreen_RefreshRateInHz;
2784 local_parameters.PresentationInterval = present_parameters->PresentationInterval;
2786 hr = IDirect3DDevice9Impl_CreateAdditionalSwapChain((IDirect3DDevice9Ex *)This,
2787 &local_parameters, (IDirect3DSwapChain9 **)&d3d_swapchain);
2790 ERR("(%p) CreateAdditionalSwapChain failed, returning %#x\n", iface, hr);
2795 *swapchain = d3d_swapchain->wineD3DSwapChain;
2796 d3d_swapchain->isImplicit = TRUE;
2797 /* Implicit swap chains are created with an refcount of 0 */
2798 IDirect3DSwapChain9_Release((IDirect3DSwapChain9 *)d3d_swapchain);
2800 /* Copy back the presentation parameters */
2801 present_parameters->BackBufferWidth = local_parameters.BackBufferWidth;
2802 present_parameters->BackBufferHeight = local_parameters.BackBufferHeight;
2803 present_parameters->BackBufferFormat = wined3dformat_from_d3dformat(local_parameters.BackBufferFormat);
2804 present_parameters->BackBufferCount = local_parameters.BackBufferCount;
2805 present_parameters->MultiSampleType = local_parameters.MultiSampleType;
2806 present_parameters->MultiSampleQuality = local_parameters.MultiSampleQuality;
2807 present_parameters->SwapEffect = local_parameters.SwapEffect;
2808 present_parameters->hDeviceWindow = local_parameters.hDeviceWindow;
2809 present_parameters->Windowed = local_parameters.Windowed;
2810 present_parameters->EnableAutoDepthStencil = local_parameters.EnableAutoDepthStencil;
2811 present_parameters->AutoDepthStencilFormat = wined3dformat_from_d3dformat(local_parameters.AutoDepthStencilFormat);
2812 present_parameters->Flags = local_parameters.Flags;
2813 present_parameters->FullScreen_RefreshRateInHz = local_parameters.FullScreen_RefreshRateInHz;
2814 present_parameters->PresentationInterval = local_parameters.PresentationInterval;
2819 static const IWineD3DDeviceParentVtbl d3d9_wined3d_device_parent_vtbl =
2821 /* IUnknown methods */
2822 device_parent_QueryInterface,
2823 device_parent_AddRef,
2824 device_parent_Release,
2825 /* IWineD3DDeviceParent methods */
2826 device_parent_WineD3DDeviceCreated,
2827 device_parent_CreateSurface,
2828 device_parent_CreateRenderTarget,
2829 device_parent_CreateDepthStencilSurface,
2830 device_parent_CreateVolume,
2831 device_parent_CreateSwapChain,
2834 static void setup_fpu(void)
2836 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
2838 __asm__ volatile ("fnstcw %0" : "=m" (cw));
2839 cw = (cw & ~0xf3f) | 0x3f;
2840 __asm__ volatile ("fldcw %0" : : "m" (cw));
2842 FIXME("FPU setup not implemented for this platform.\n");
2846 HRESULT device_init(IDirect3DDevice9Impl *device, IWineD3D *wined3d, UINT adapter, D3DDEVTYPE device_type,
2847 HWND focus_window, DWORD flags, D3DPRESENT_PARAMETERS *parameters)
2849 WINED3DPRESENT_PARAMETERS *wined3d_parameters;
2853 device->lpVtbl = &Direct3DDevice9_Vtbl;
2854 device->device_parent_vtbl = &d3d9_wined3d_device_parent_vtbl;
2857 if (!(flags & D3DCREATE_FPU_PRESERVE)) setup_fpu();
2859 wined3d_mutex_lock();
2860 hr = IWineD3D_CreateDevice(wined3d, adapter, device_type, focus_window, flags, (IUnknown *)device,
2861 (IWineD3DDeviceParent *)&device->device_parent_vtbl, &device->WineD3DDevice);
2864 WARN("Failed to create wined3d device, hr %#x.\n", hr);
2865 wined3d_mutex_unlock();
2869 if (!parameters->Windowed)
2871 if (!focus_window) focus_window = parameters->hDeviceWindow;
2872 if (FAILED(hr = IWineD3DDevice_AcquireFocusWindow(device->WineD3DDevice, focus_window)))
2874 ERR("Failed to acquire focus window, hr %#x.\n", hr);
2875 IWineD3DDevice_Release(device->WineD3DDevice);
2876 wined3d_mutex_unlock();
2881 if (flags & D3DCREATE_ADAPTERGROUP_DEVICE)
2885 IWineD3D_GetDeviceCaps(wined3d, adapter, device_type, &caps);
2886 count = caps.NumberOfAdaptersInGroup;
2889 if (flags & D3DCREATE_MULTITHREADED) IWineD3DDevice_SetMultithreaded(device->WineD3DDevice);
2891 wined3d_parameters = HeapAlloc(GetProcessHeap(), 0, sizeof(*wined3d_parameters) * count);
2892 if (!wined3d_parameters)
2894 ERR("Failed to allocate wined3d parameters.\n");
2895 IWineD3DDevice_Release(device->WineD3DDevice);
2896 wined3d_mutex_unlock();
2897 return E_OUTOFMEMORY;
2900 for (i = 0; i < count; ++i)
2902 wined3d_parameters[i].BackBufferWidth = parameters[i].BackBufferWidth;
2903 wined3d_parameters[i].BackBufferHeight = parameters[i].BackBufferHeight;
2904 wined3d_parameters[i].BackBufferFormat = wined3dformat_from_d3dformat(parameters[i].BackBufferFormat);
2905 wined3d_parameters[i].BackBufferCount = parameters[i].BackBufferCount;
2906 wined3d_parameters[i].MultiSampleType = parameters[i].MultiSampleType;
2907 wined3d_parameters[i].MultiSampleQuality = parameters[i].MultiSampleQuality;
2908 wined3d_parameters[i].SwapEffect = parameters[i].SwapEffect;
2909 wined3d_parameters[i].hDeviceWindow = parameters[i].hDeviceWindow;
2910 wined3d_parameters[i].Windowed = parameters[i].Windowed;
2911 wined3d_parameters[i].EnableAutoDepthStencil = parameters[i].EnableAutoDepthStencil;
2912 wined3d_parameters[i].AutoDepthStencilFormat =
2913 wined3dformat_from_d3dformat(parameters[i].AutoDepthStencilFormat);
2914 wined3d_parameters[i].Flags = parameters[i].Flags;
2915 wined3d_parameters[i].FullScreen_RefreshRateInHz = parameters[i].FullScreen_RefreshRateInHz;
2916 wined3d_parameters[i].PresentationInterval = parameters[i].PresentationInterval;
2917 wined3d_parameters[i].AutoRestoreDisplayMode = TRUE;
2920 hr = IWineD3DDevice_Init3D(device->WineD3DDevice, wined3d_parameters);
2923 WARN("Failed to initialize 3D, hr %#x.\n", hr);
2924 IWineD3DDevice_ReleaseFocusWindow(device->WineD3DDevice);
2925 HeapFree(GetProcessHeap(), 0, wined3d_parameters);
2926 IWineD3DDevice_Release(device->WineD3DDevice);
2927 wined3d_mutex_unlock();
2931 wined3d_mutex_unlock();
2933 for (i = 0; i < count; ++i)
2935 parameters[i].BackBufferWidth = wined3d_parameters[i].BackBufferWidth;
2936 parameters[i].BackBufferHeight = wined3d_parameters[i].BackBufferHeight;
2937 parameters[i].BackBufferFormat = d3dformat_from_wined3dformat(wined3d_parameters[i].BackBufferFormat);
2938 parameters[i].BackBufferCount = wined3d_parameters[i].BackBufferCount;
2939 parameters[i].MultiSampleType = wined3d_parameters[i].MultiSampleType;
2940 parameters[i].MultiSampleQuality = wined3d_parameters[i].MultiSampleQuality;
2941 parameters[i].SwapEffect = wined3d_parameters[i].SwapEffect;
2942 parameters[i].hDeviceWindow = wined3d_parameters[i].hDeviceWindow;
2943 parameters[i].Windowed = wined3d_parameters[i].Windowed;
2944 parameters[i].EnableAutoDepthStencil = wined3d_parameters[i].EnableAutoDepthStencil;
2945 parameters[i].AutoDepthStencilFormat =
2946 d3dformat_from_wined3dformat(wined3d_parameters[i].AutoDepthStencilFormat);
2947 parameters[i].Flags = wined3d_parameters[i].Flags;
2948 parameters[i].FullScreen_RefreshRateInHz = wined3d_parameters[i].FullScreen_RefreshRateInHz;
2949 parameters[i].PresentationInterval = wined3d_parameters[i].PresentationInterval;
2951 HeapFree(GetProcessHeap(), 0, wined3d_parameters);
2953 /* Initialize the converted declaration array. This creates a valid pointer
2954 * and when adding decls HeapReAlloc() can be used without further checking. */
2955 device->convertedDecls = HeapAlloc(GetProcessHeap(), 0, 0);
2956 if (!device->convertedDecls)
2958 ERR("Failed to allocate FVF vertex declaration map memory.\n");
2959 wined3d_mutex_lock();
2960 IWineD3DDevice_Uninit3D(device->WineD3DDevice, D3D9CB_DestroySwapChain);
2961 IWineD3DDevice_ReleaseFocusWindow(device->WineD3DDevice);
2962 IWineD3DDevice_Release(device->WineD3DDevice);
2963 wined3d_mutex_unlock();
2964 return E_OUTOFMEMORY;