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 /* Note: D3DRECT is compatible with WINED3DRECT */
1048 hr = IWineD3DDevice_ColorFill(This->WineD3DDevice, surface->wineD3DSurface, (const WINED3DRECT *)pRect, &c);
1050 wined3d_mutex_unlock();
1055 static HRESULT WINAPI IDirect3DDevice9Impl_CreateOffscreenPlainSurface(LPDIRECT3DDEVICE9EX iface, UINT Width, UINT Height, D3DFORMAT Format, D3DPOOL Pool, IDirect3DSurface9 **ppSurface, HANDLE* pSharedHandle) {
1058 TRACE("iface %p, width %u, height %u, format %#x, pool %#x, surface %p, shared_handle %p.\n",
1059 iface, Width, Height, Format, Pool, ppSurface, pSharedHandle);
1061 if(Pool == D3DPOOL_MANAGED ){
1062 FIXME("Attempting to create a managed offscreen plain surface\n");
1063 return D3DERR_INVALIDCALL;
1066 'Off-screen plain surfaces are always lockable, regardless of their pool types.'
1068 D3DPOOL_DEFAULT is the appropriate pool for use with the IDirect3DDevice9::StretchRect and IDirect3DDevice9::ColorFill.
1069 Why, their always lockable?
1070 should I change the usage to dynamic?
1072 hr = IDirect3DDevice9Impl_CreateSurface(iface, Width, Height, Format, TRUE /* Lockable */, FALSE /* Discard */,
1073 0 /* Level */, ppSurface, 0 /* Usage (undefined/none) */, (WINED3DPOOL)Pool, D3DMULTISAMPLE_NONE,
1074 0 /* MultisampleQuality */);
1079 /* TODO: move to wineD3D */
1080 static HRESULT WINAPI IDirect3DDevice9Impl_SetRenderTarget(LPDIRECT3DDEVICE9EX iface, DWORD RenderTargetIndex, IDirect3DSurface9* pRenderTarget) {
1081 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1082 IDirect3DSurface9Impl *pSurface = (IDirect3DSurface9Impl*)pRenderTarget;
1085 TRACE("iface %p, idx %u, surface %p.\n", iface, RenderTargetIndex, pRenderTarget);
1087 if (RenderTargetIndex >= D3D9_MAX_SIMULTANEOUS_RENDERTARGETS)
1089 WARN("Invalid index %u specified.\n", RenderTargetIndex);
1090 return D3DERR_INVALIDCALL;
1093 wined3d_mutex_lock();
1094 hr = IWineD3DDevice_SetRenderTarget(This->WineD3DDevice, RenderTargetIndex, pSurface ? pSurface->wineD3DSurface : NULL, TRUE);
1095 wined3d_mutex_unlock();
1100 static HRESULT WINAPI IDirect3DDevice9Impl_GetRenderTarget(LPDIRECT3DDEVICE9EX iface, DWORD RenderTargetIndex, IDirect3DSurface9 **ppRenderTarget) {
1101 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1102 IWineD3DSurface *pRenderTarget;
1105 TRACE("iface %p, idx %u, surface %p.\n", iface, RenderTargetIndex, ppRenderTarget);
1107 if (ppRenderTarget == NULL) {
1108 return D3DERR_INVALIDCALL;
1111 if (RenderTargetIndex >= D3D9_MAX_SIMULTANEOUS_RENDERTARGETS)
1113 WARN("Invalid index %u specified.\n", RenderTargetIndex);
1114 return D3DERR_INVALIDCALL;
1117 wined3d_mutex_lock();
1119 hr=IWineD3DDevice_GetRenderTarget(This->WineD3DDevice,RenderTargetIndex,&pRenderTarget);
1123 FIXME("Call to IWineD3DDevice_GetRenderTarget failed, hr %#x\n", hr);
1125 else if (!pRenderTarget)
1127 *ppRenderTarget = NULL;
1131 IWineD3DSurface_GetParent(pRenderTarget, (IUnknown **)ppRenderTarget);
1132 IWineD3DSurface_Release(pRenderTarget);
1135 wined3d_mutex_unlock();
1140 static HRESULT WINAPI IDirect3DDevice9Impl_SetDepthStencilSurface(LPDIRECT3DDEVICE9EX iface, IDirect3DSurface9* pZStencilSurface) {
1141 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1142 IDirect3DSurface9Impl *pSurface;
1145 TRACE("iface %p, depth_stencil %p.\n", iface, pZStencilSurface);
1147 pSurface = (IDirect3DSurface9Impl*)pZStencilSurface;
1149 wined3d_mutex_lock();
1150 hr = IWineD3DDevice_SetDepthStencilSurface(This->WineD3DDevice, NULL==pSurface ? NULL : pSurface->wineD3DSurface);
1151 wined3d_mutex_unlock();
1156 static HRESULT WINAPI IDirect3DDevice9Impl_GetDepthStencilSurface(LPDIRECT3DDEVICE9EX iface, IDirect3DSurface9 **ppZStencilSurface) {
1157 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1158 HRESULT hr = D3D_OK;
1159 IWineD3DSurface *pZStencilSurface;
1161 TRACE("iface %p, depth_stencil %p.\n", iface, ppZStencilSurface);
1163 if(ppZStencilSurface == NULL){
1164 return D3DERR_INVALIDCALL;
1167 wined3d_mutex_lock();
1168 hr = IWineD3DDevice_GetDepthStencilSurface(This->WineD3DDevice,&pZStencilSurface);
1169 if (hr == WINED3D_OK) {
1170 IWineD3DSurface_GetParent(pZStencilSurface,(IUnknown**)ppZStencilSurface);
1171 IWineD3DSurface_Release(pZStencilSurface);
1173 if (hr != WINED3DERR_NOTFOUND)
1174 WARN("Call to IWineD3DDevice_GetDepthStencilSurface failed with 0x%08x\n", hr);
1175 *ppZStencilSurface = NULL;
1177 wined3d_mutex_unlock();
1182 static HRESULT WINAPI IDirect3DDevice9Impl_BeginScene(LPDIRECT3DDEVICE9EX iface) {
1183 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1186 TRACE("iface %p.\n", iface);
1188 wined3d_mutex_lock();
1189 hr = IWineD3DDevice_BeginScene(This->WineD3DDevice);
1190 wined3d_mutex_unlock();
1195 static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_EndScene(LPDIRECT3DDEVICE9EX iface) {
1196 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1199 TRACE("iface %p.\n", iface);
1201 wined3d_mutex_lock();
1202 hr = IWineD3DDevice_EndScene(This->WineD3DDevice);
1203 wined3d_mutex_unlock();
1208 static HRESULT WINAPI IDirect3DDevice9Impl_Clear(LPDIRECT3DDEVICE9EX iface, DWORD Count, CONST D3DRECT* pRects, DWORD Flags, D3DCOLOR Color, float Z, DWORD Stencil) {
1209 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1212 TRACE("iface %p, rect_count %u, rects %p, flags %#x, color 0x%08x, z %.8e, stencil %u.\n",
1213 iface, Count, pRects, Flags, Color, Z, Stencil);
1215 /* Note: D3DRECT is compatible with WINED3DRECT */
1216 wined3d_mutex_lock();
1217 hr = IWineD3DDevice_Clear(This->WineD3DDevice, Count, (CONST WINED3DRECT*) pRects, Flags, Color, Z, Stencil);
1218 wined3d_mutex_unlock();
1223 static HRESULT WINAPI IDirect3DDevice9Impl_SetTransform(LPDIRECT3DDEVICE9EX iface, D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX* lpMatrix) {
1224 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1227 TRACE("iface %p, state %#x, matrix %p.\n", iface, State, lpMatrix);
1229 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1230 wined3d_mutex_lock();
1231 hr = IWineD3DDevice_SetTransform(This->WineD3DDevice, State, (CONST WINED3DMATRIX*) lpMatrix);
1232 wined3d_mutex_unlock();
1237 static HRESULT WINAPI IDirect3DDevice9Impl_GetTransform(LPDIRECT3DDEVICE9EX iface, D3DTRANSFORMSTATETYPE State, D3DMATRIX* pMatrix) {
1238 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1241 TRACE("iface %p, state %#x, matrix %p.\n", iface, State, pMatrix);
1243 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1244 wined3d_mutex_lock();
1245 hr = IWineD3DDevice_GetTransform(This->WineD3DDevice, State, (WINED3DMATRIX*) pMatrix);
1246 wined3d_mutex_unlock();
1251 static HRESULT WINAPI IDirect3DDevice9Impl_MultiplyTransform(LPDIRECT3DDEVICE9EX iface, D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX* pMatrix) {
1252 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1255 TRACE("iface %p, state %#x, matrix %p.\n", iface, State, pMatrix);
1257 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1258 wined3d_mutex_lock();
1259 hr = IWineD3DDevice_MultiplyTransform(This->WineD3DDevice, State, (CONST WINED3DMATRIX*) pMatrix);
1260 wined3d_mutex_unlock();
1265 static HRESULT WINAPI IDirect3DDevice9Impl_SetViewport(LPDIRECT3DDEVICE9EX iface, CONST D3DVIEWPORT9* pViewport) {
1266 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1269 TRACE("iface %p, viewport %p.\n", iface, pViewport);
1271 /* Note: D3DVIEWPORT9 is compatible with WINED3DVIEWPORT */
1272 wined3d_mutex_lock();
1273 hr = IWineD3DDevice_SetViewport(This->WineD3DDevice, (const WINED3DVIEWPORT *)pViewport);
1274 wined3d_mutex_unlock();
1279 static HRESULT WINAPI IDirect3DDevice9Impl_GetViewport(LPDIRECT3DDEVICE9EX iface, D3DVIEWPORT9* pViewport) {
1280 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1283 TRACE("iface %p, viewport %p.\n", iface, pViewport);
1285 /* Note: D3DVIEWPORT9 is compatible with WINED3DVIEWPORT */
1286 wined3d_mutex_lock();
1287 hr = IWineD3DDevice_GetViewport(This->WineD3DDevice, (WINED3DVIEWPORT *)pViewport);
1288 wined3d_mutex_unlock();
1293 static HRESULT WINAPI IDirect3DDevice9Impl_SetMaterial(LPDIRECT3DDEVICE9EX iface, CONST D3DMATERIAL9* pMaterial) {
1294 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1297 TRACE("iface %p, material %p.\n", iface, pMaterial);
1299 /* Note: D3DMATERIAL9 is compatible with WINED3DMATERIAL */
1300 wined3d_mutex_lock();
1301 hr = IWineD3DDevice_SetMaterial(This->WineD3DDevice, (const WINED3DMATERIAL *)pMaterial);
1302 wined3d_mutex_unlock();
1307 static HRESULT WINAPI IDirect3DDevice9Impl_GetMaterial(LPDIRECT3DDEVICE9EX iface, D3DMATERIAL9* pMaterial) {
1308 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1311 TRACE("iface %p, material %p.\n", iface, pMaterial);
1313 /* Note: D3DMATERIAL9 is compatible with WINED3DMATERIAL */
1314 wined3d_mutex_lock();
1315 hr = IWineD3DDevice_GetMaterial(This->WineD3DDevice, (WINED3DMATERIAL *)pMaterial);
1316 wined3d_mutex_unlock();
1321 static HRESULT WINAPI IDirect3DDevice9Impl_SetLight(LPDIRECT3DDEVICE9EX iface, DWORD Index, CONST D3DLIGHT9* pLight) {
1322 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1325 TRACE("iface %p, index %u, light %p.\n", iface, Index, pLight);
1327 /* Note: D3DLIGHT9 is compatible with WINED3DLIGHT */
1328 wined3d_mutex_lock();
1329 hr = IWineD3DDevice_SetLight(This->WineD3DDevice, Index, (const WINED3DLIGHT *)pLight);
1330 wined3d_mutex_unlock();
1335 static HRESULT WINAPI IDirect3DDevice9Impl_GetLight(LPDIRECT3DDEVICE9EX iface, DWORD Index, D3DLIGHT9* pLight) {
1336 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1339 TRACE("iface %p, index %u, light %p.\n", iface, Index, pLight);
1341 /* Note: D3DLIGHT9 is compatible with WINED3DLIGHT */
1342 wined3d_mutex_lock();
1343 hr = IWineD3DDevice_GetLight(This->WineD3DDevice, Index, (WINED3DLIGHT *)pLight);
1344 wined3d_mutex_unlock();
1349 static HRESULT WINAPI IDirect3DDevice9Impl_LightEnable(LPDIRECT3DDEVICE9EX iface, DWORD Index, BOOL Enable) {
1350 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1353 TRACE("iface %p, index %u, enable %#x.\n", iface, Index, Enable);
1355 wined3d_mutex_lock();
1356 hr = IWineD3DDevice_SetLightEnable(This->WineD3DDevice, Index, Enable);
1357 wined3d_mutex_unlock();
1362 static HRESULT WINAPI IDirect3DDevice9Impl_GetLightEnable(LPDIRECT3DDEVICE9EX iface, DWORD Index, BOOL* pEnable) {
1363 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1366 TRACE("iface %p, index %u, enable %p.\n", iface, Index, pEnable);
1368 wined3d_mutex_lock();
1369 hr = IWineD3DDevice_GetLightEnable(This->WineD3DDevice, Index, pEnable);
1370 wined3d_mutex_unlock();
1375 static HRESULT WINAPI IDirect3DDevice9Impl_SetClipPlane(LPDIRECT3DDEVICE9EX iface, DWORD Index, CONST float* pPlane) {
1376 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1379 TRACE("iface %p, index %u, plane %p.\n", iface, Index, pPlane);
1381 wined3d_mutex_lock();
1382 hr = IWineD3DDevice_SetClipPlane(This->WineD3DDevice, Index, pPlane);
1383 wined3d_mutex_unlock();
1388 static HRESULT WINAPI IDirect3DDevice9Impl_GetClipPlane(LPDIRECT3DDEVICE9EX iface, DWORD Index, float* pPlane) {
1389 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1392 TRACE("iface %p, index %u, plane %p.\n", iface, Index, pPlane);
1394 wined3d_mutex_lock();
1395 hr = IWineD3DDevice_GetClipPlane(This->WineD3DDevice, Index, pPlane);
1396 wined3d_mutex_unlock();
1401 static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_SetRenderState(LPDIRECT3DDEVICE9EX iface, D3DRENDERSTATETYPE State, DWORD Value) {
1402 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1405 TRACE("iface %p, state %#x, value %#x.\n", iface, State, Value);
1407 wined3d_mutex_lock();
1408 hr = IWineD3DDevice_SetRenderState(This->WineD3DDevice, State, Value);
1409 wined3d_mutex_unlock();
1414 static HRESULT WINAPI IDirect3DDevice9Impl_GetRenderState(LPDIRECT3DDEVICE9EX iface, D3DRENDERSTATETYPE State, DWORD* pValue) {
1415 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1418 TRACE("iface %p, state %#x, value %p.\n", iface, State, pValue);
1420 wined3d_mutex_lock();
1421 hr = IWineD3DDevice_GetRenderState(This->WineD3DDevice, State, pValue);
1422 wined3d_mutex_unlock();
1427 static HRESULT WINAPI IDirect3DDevice9Impl_CreateStateBlock(IDirect3DDevice9Ex *iface,
1428 D3DSTATEBLOCKTYPE type, IDirect3DStateBlock9 **stateblock)
1430 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1431 IDirect3DStateBlock9Impl *object;
1434 TRACE("iface %p, type %#x, stateblock %p.\n", iface, type, stateblock);
1436 if (type != D3DSBT_ALL && type != D3DSBT_PIXELSTATE && type != D3DSBT_VERTEXSTATE)
1438 WARN("Unexpected stateblock type, returning D3DERR_INVALIDCALL.\n");
1439 return D3DERR_INVALIDCALL;
1442 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1445 ERR("Failed to allocate stateblock memory.\n");
1446 return E_OUTOFMEMORY;
1449 hr = stateblock_init(object, This, type, NULL);
1452 WARN("Failed to initialize stateblock, hr %#x.\n", hr);
1453 HeapFree(GetProcessHeap(), 0, object);
1457 TRACE("Created stateblock %p.\n", object);
1458 *stateblock = (IDirect3DStateBlock9 *)object;
1463 static HRESULT WINAPI IDirect3DDevice9Impl_BeginStateBlock(IDirect3DDevice9Ex *iface)
1465 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1468 TRACE("iface %p.\n", iface);
1470 wined3d_mutex_lock();
1471 hr = IWineD3DDevice_BeginStateBlock(This->WineD3DDevice);
1472 wined3d_mutex_unlock();
1477 static HRESULT WINAPI IDirect3DDevice9Impl_EndStateBlock(IDirect3DDevice9Ex *iface, IDirect3DStateBlock9 **stateblock)
1479 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1480 IWineD3DStateBlock *wined3d_stateblock;
1481 IDirect3DStateBlock9Impl *object;
1484 TRACE("iface %p, stateblock %p.\n", iface, stateblock);
1486 wined3d_mutex_lock();
1487 hr = IWineD3DDevice_EndStateBlock(This->WineD3DDevice, &wined3d_stateblock);
1488 wined3d_mutex_unlock();
1491 WARN("IWineD3DDevice_EndStateBlock() failed, hr %#x.\n", hr);
1495 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1498 ERR("Failed to allocate stateblock memory.\n");
1499 IWineD3DStateBlock_Release(wined3d_stateblock);
1500 return E_OUTOFMEMORY;
1503 hr = stateblock_init(object, This, 0, wined3d_stateblock);
1506 WARN("Failed to initialize stateblock, hr %#x.\n", hr);
1507 IWineD3DStateBlock_Release(wined3d_stateblock);
1508 HeapFree(GetProcessHeap(), 0, object);
1512 TRACE("Created stateblock %p.\n", object);
1513 *stateblock = (IDirect3DStateBlock9 *)object;
1518 static HRESULT WINAPI IDirect3DDevice9Impl_SetClipStatus(LPDIRECT3DDEVICE9EX iface, CONST D3DCLIPSTATUS9* pClipStatus) {
1519 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1522 TRACE("iface %p, clip_status %p.\n", iface, pClipStatus);
1524 wined3d_mutex_lock();
1525 hr = IWineD3DDevice_SetClipStatus(This->WineD3DDevice, (const WINED3DCLIPSTATUS *)pClipStatus);
1526 wined3d_mutex_unlock();
1531 static HRESULT WINAPI IDirect3DDevice9Impl_GetClipStatus(LPDIRECT3DDEVICE9EX iface, D3DCLIPSTATUS9* pClipStatus) {
1532 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1535 TRACE("iface %p, clip_status %p.\n", iface, pClipStatus);
1537 wined3d_mutex_lock();
1538 hr = IWineD3DDevice_GetClipStatus(This->WineD3DDevice, (WINED3DCLIPSTATUS *)pClipStatus);
1539 wined3d_mutex_unlock();
1544 static HRESULT WINAPI IDirect3DDevice9Impl_GetTexture(LPDIRECT3DDEVICE9EX iface, DWORD Stage, IDirect3DBaseTexture9 **ppTexture) {
1545 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1546 IWineD3DBaseTexture *retTexture = NULL;
1547 HRESULT rc = D3D_OK;
1549 TRACE("iface %p, stage %u, texture %p.\n", iface, Stage, ppTexture);
1551 if(ppTexture == NULL){
1552 return D3DERR_INVALIDCALL;
1555 wined3d_mutex_lock();
1556 rc = IWineD3DDevice_GetTexture(This->WineD3DDevice, Stage, &retTexture);
1557 if (SUCCEEDED(rc) && NULL != retTexture) {
1558 IWineD3DBaseTexture_GetParent(retTexture, (IUnknown **)ppTexture);
1559 IWineD3DBaseTexture_Release(retTexture);
1562 WARN("Call to get texture (%d) failed (%p)\n", Stage, retTexture);
1566 wined3d_mutex_unlock();
1571 static HRESULT WINAPI IDirect3DDevice9Impl_SetTexture(LPDIRECT3DDEVICE9EX iface, DWORD Stage, IDirect3DBaseTexture9* pTexture) {
1572 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1575 TRACE("iface %p, stage %u, texture %p.\n", iface, Stage, pTexture);
1577 wined3d_mutex_lock();
1578 hr = IWineD3DDevice_SetTexture(This->WineD3DDevice, Stage,
1579 pTexture==NULL ? NULL:((IDirect3DBaseTexture9Impl *)pTexture)->wineD3DBaseTexture);
1580 wined3d_mutex_unlock();
1585 static const WINED3DTEXTURESTAGESTATETYPE tss_lookup[] =
1587 WINED3DTSS_FORCE_DWORD, /* 0, unused */
1588 WINED3DTSS_COLOROP, /* 1, D3DTSS_COLOROP */
1589 WINED3DTSS_COLORARG1, /* 2, D3DTSS_COLORARG1 */
1590 WINED3DTSS_COLORARG2, /* 3, D3DTSS_COLORARG2 */
1591 WINED3DTSS_ALPHAOP, /* 4, D3DTSS_ALPHAOP */
1592 WINED3DTSS_ALPHAARG1, /* 5, D3DTSS_ALPHAARG1 */
1593 WINED3DTSS_ALPHAARG2, /* 6, D3DTSS_ALPHAARG2 */
1594 WINED3DTSS_BUMPENVMAT00, /* 7, D3DTSS_BUMPENVMAT00 */
1595 WINED3DTSS_BUMPENVMAT01, /* 8, D3DTSS_BUMPENVMAT01 */
1596 WINED3DTSS_BUMPENVMAT10, /* 9, D3DTSS_BUMPENVMAT10 */
1597 WINED3DTSS_BUMPENVMAT11, /* 10, D3DTSS_BUMPENVMAT11 */
1598 WINED3DTSS_TEXCOORDINDEX, /* 11, D3DTSS_TEXCOORDINDEX */
1599 WINED3DTSS_FORCE_DWORD, /* 12, unused */
1600 WINED3DTSS_FORCE_DWORD, /* 13, unused */
1601 WINED3DTSS_FORCE_DWORD, /* 14, unused */
1602 WINED3DTSS_FORCE_DWORD, /* 15, unused */
1603 WINED3DTSS_FORCE_DWORD, /* 16, unused */
1604 WINED3DTSS_FORCE_DWORD, /* 17, unused */
1605 WINED3DTSS_FORCE_DWORD, /* 18, unused */
1606 WINED3DTSS_FORCE_DWORD, /* 19, unused */
1607 WINED3DTSS_FORCE_DWORD, /* 20, unused */
1608 WINED3DTSS_FORCE_DWORD, /* 21, unused */
1609 WINED3DTSS_BUMPENVLSCALE, /* 22, D3DTSS_BUMPENVLSCALE */
1610 WINED3DTSS_BUMPENVLOFFSET, /* 23, D3DTSS_BUMPENVLOFFSET */
1611 WINED3DTSS_TEXTURETRANSFORMFLAGS, /* 24, D3DTSS_TEXTURETRANSFORMFLAGS */
1612 WINED3DTSS_FORCE_DWORD, /* 25, unused */
1613 WINED3DTSS_COLORARG0, /* 26, D3DTSS_COLORARG0 */
1614 WINED3DTSS_ALPHAARG0, /* 27, D3DTSS_ALPHAARG0 */
1615 WINED3DTSS_RESULTARG, /* 28, D3DTSS_RESULTARG */
1616 WINED3DTSS_FORCE_DWORD, /* 29, unused */
1617 WINED3DTSS_FORCE_DWORD, /* 30, unused */
1618 WINED3DTSS_FORCE_DWORD, /* 31, unused */
1619 WINED3DTSS_CONSTANT, /* 32, D3DTSS_CONSTANT */
1622 static HRESULT WINAPI IDirect3DDevice9Impl_GetTextureStageState(LPDIRECT3DDEVICE9EX iface, DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD* pValue) {
1623 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1626 TRACE("iface %p, stage %u, state %#x, value %p.\n", iface, Stage, Type, pValue);
1628 wined3d_mutex_lock();
1629 hr = IWineD3DDevice_GetTextureStageState(This->WineD3DDevice, Stage, tss_lookup[Type], pValue);
1630 wined3d_mutex_unlock();
1635 static HRESULT WINAPI IDirect3DDevice9Impl_SetTextureStageState(LPDIRECT3DDEVICE9EX iface, DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD Value) {
1636 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1639 TRACE("iface %p, stage %u, state %#x, value %#x.\n", iface, Stage, Type, Value);
1641 wined3d_mutex_lock();
1642 hr = IWineD3DDevice_SetTextureStageState(This->WineD3DDevice, Stage, tss_lookup[Type], Value);
1643 wined3d_mutex_unlock();
1648 static HRESULT WINAPI IDirect3DDevice9Impl_GetSamplerState(IDirect3DDevice9Ex *iface, DWORD Sampler,
1649 D3DSAMPLERSTATETYPE Type, DWORD *pValue)
1651 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1654 TRACE("iface %p, sampler %u, state %#x, value %p.\n", iface, Sampler, Type, pValue);
1656 wined3d_mutex_lock();
1657 hr = IWineD3DDevice_GetSamplerState(This->WineD3DDevice, Sampler, Type, pValue);
1658 wined3d_mutex_unlock();
1663 static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_SetSamplerState(LPDIRECT3DDEVICE9EX iface, DWORD Sampler, D3DSAMPLERSTATETYPE Type, DWORD Value) {
1664 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1667 TRACE("iface %p, sampler %u, state %#x, value %#x.\n", iface, Sampler, Type, Value);
1669 wined3d_mutex_lock();
1670 hr = IWineD3DDevice_SetSamplerState(This->WineD3DDevice, Sampler, Type, Value);
1671 wined3d_mutex_unlock();
1676 static HRESULT WINAPI IDirect3DDevice9Impl_ValidateDevice(LPDIRECT3DDEVICE9EX iface, DWORD* pNumPasses) {
1677 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1680 TRACE("iface %p, pass_count %p.\n", iface, pNumPasses);
1682 wined3d_mutex_lock();
1683 hr = IWineD3DDevice_ValidateDevice(This->WineD3DDevice, pNumPasses);
1684 wined3d_mutex_unlock();
1689 static HRESULT WINAPI IDirect3DDevice9Impl_SetPaletteEntries(IDirect3DDevice9Ex *iface, UINT PaletteNumber,
1690 const PALETTEENTRY *pEntries)
1692 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1695 TRACE("iface %p, palette_idx %u, entries %p.\n", iface, PaletteNumber, pEntries);
1697 wined3d_mutex_lock();
1698 hr = IWineD3DDevice_SetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
1699 wined3d_mutex_unlock();
1704 static HRESULT WINAPI IDirect3DDevice9Impl_GetPaletteEntries(LPDIRECT3DDEVICE9EX iface, UINT PaletteNumber, PALETTEENTRY* pEntries) {
1705 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1708 TRACE("iface %p, palette_idx %u, entries %p.\n", iface, PaletteNumber, pEntries);
1710 wined3d_mutex_lock();
1711 hr = IWineD3DDevice_GetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
1712 wined3d_mutex_unlock();
1717 static HRESULT WINAPI IDirect3DDevice9Impl_SetCurrentTexturePalette(LPDIRECT3DDEVICE9EX iface, UINT PaletteNumber) {
1718 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1721 TRACE("iface %p, palette_idx %u.\n", iface, PaletteNumber);
1723 wined3d_mutex_lock();
1724 hr = IWineD3DDevice_SetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
1725 wined3d_mutex_unlock();
1730 static HRESULT WINAPI IDirect3DDevice9Impl_GetCurrentTexturePalette(LPDIRECT3DDEVICE9EX iface, UINT* PaletteNumber) {
1731 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1734 TRACE("iface %p, palette_idx %p.\n", iface, PaletteNumber);
1736 wined3d_mutex_lock();
1737 hr = IWineD3DDevice_GetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
1738 wined3d_mutex_unlock();
1743 static HRESULT WINAPI IDirect3DDevice9Impl_SetScissorRect(LPDIRECT3DDEVICE9EX iface, CONST RECT* pRect) {
1744 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1747 TRACE("iface %p, rect %p.\n", iface, pRect);
1749 wined3d_mutex_lock();
1750 hr = IWineD3DDevice_SetScissorRect(This->WineD3DDevice, pRect);
1751 wined3d_mutex_unlock();
1756 static HRESULT WINAPI IDirect3DDevice9Impl_GetScissorRect(LPDIRECT3DDEVICE9EX iface, RECT* pRect) {
1757 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1760 TRACE("iface %p, rect %p.\n", iface, pRect);
1762 wined3d_mutex_lock();
1763 hr = IWineD3DDevice_GetScissorRect(This->WineD3DDevice, pRect);
1764 wined3d_mutex_unlock();
1769 static HRESULT WINAPI IDirect3DDevice9Impl_SetSoftwareVertexProcessing(LPDIRECT3DDEVICE9EX iface, BOOL bSoftware) {
1770 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1773 TRACE("iface %p, software %#x.\n", iface, bSoftware);
1775 wined3d_mutex_lock();
1776 hr = IWineD3DDevice_SetSoftwareVertexProcessing(This->WineD3DDevice, bSoftware);
1777 wined3d_mutex_unlock();
1782 static BOOL WINAPI IDirect3DDevice9Impl_GetSoftwareVertexProcessing(LPDIRECT3DDEVICE9EX iface) {
1783 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1786 TRACE("iface %p.\n", iface);
1788 wined3d_mutex_lock();
1789 ret = IWineD3DDevice_GetSoftwareVertexProcessing(This->WineD3DDevice);
1790 wined3d_mutex_unlock();
1795 static HRESULT WINAPI IDirect3DDevice9Impl_SetNPatchMode(LPDIRECT3DDEVICE9EX iface, float nSegments) {
1796 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1799 TRACE("iface %p, segment_count %.8e.\n", iface, nSegments);
1801 wined3d_mutex_lock();
1802 hr = IWineD3DDevice_SetNPatchMode(This->WineD3DDevice, nSegments);
1803 wined3d_mutex_unlock();
1808 static float WINAPI IDirect3DDevice9Impl_GetNPatchMode(LPDIRECT3DDEVICE9EX iface) {
1809 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1812 TRACE("iface %p.\n", iface);
1814 wined3d_mutex_lock();
1815 ret = IWineD3DDevice_GetNPatchMode(This->WineD3DDevice);
1816 wined3d_mutex_unlock();
1821 static HRESULT WINAPI IDirect3DDevice9Impl_DrawPrimitive(IDirect3DDevice9Ex *iface, D3DPRIMITIVETYPE PrimitiveType,
1822 UINT StartVertex, UINT PrimitiveCount)
1824 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1827 TRACE("iface %p, primitive_type %#x, start_vertex %u, primitive_count %u.\n",
1828 iface, PrimitiveType, StartVertex, PrimitiveCount);
1830 wined3d_mutex_lock();
1831 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1832 hr = IWineD3DDevice_DrawPrimitive(This->WineD3DDevice, StartVertex,
1833 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount));
1834 wined3d_mutex_unlock();
1839 static HRESULT WINAPI IDirect3DDevice9Impl_DrawIndexedPrimitive(LPDIRECT3DDEVICE9EX iface, D3DPRIMITIVETYPE PrimitiveType,
1840 INT BaseVertexIndex, UINT MinVertexIndex, UINT NumVertices, UINT startIndex, UINT primCount) {
1841 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1844 TRACE("iface %p, primitive_type %#x, base_vertex_idx %u, min_vertex_idx %u,\n"
1845 "vertex_count %u, start_idx %u, primitive_count %u.\n",
1846 iface, PrimitiveType, BaseVertexIndex, MinVertexIndex,
1847 NumVertices, startIndex, primCount);
1849 wined3d_mutex_lock();
1850 IWineD3DDevice_SetBaseVertexIndex(This->WineD3DDevice, BaseVertexIndex);
1851 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1852 hr = IWineD3DDevice_DrawIndexedPrimitive(This->WineD3DDevice, startIndex,
1853 vertex_count_from_primitive_count(PrimitiveType, primCount));
1854 wined3d_mutex_unlock();
1859 static HRESULT WINAPI IDirect3DDevice9Impl_DrawPrimitiveUP(IDirect3DDevice9Ex *iface, D3DPRIMITIVETYPE PrimitiveType,
1860 UINT PrimitiveCount, const void *pVertexStreamZeroData, UINT VertexStreamZeroStride)
1862 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1865 TRACE("iface %p, primitive_type %#x, primitive_count %u, data %p, stride %u.\n",
1866 iface, PrimitiveType, PrimitiveCount, pVertexStreamZeroData, VertexStreamZeroStride);
1868 wined3d_mutex_lock();
1869 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1870 hr = IWineD3DDevice_DrawPrimitiveUP(This->WineD3DDevice,
1871 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount),
1872 pVertexStreamZeroData, VertexStreamZeroStride);
1873 wined3d_mutex_unlock();
1878 static HRESULT WINAPI IDirect3DDevice9Impl_DrawIndexedPrimitiveUP(LPDIRECT3DDEVICE9EX iface, D3DPRIMITIVETYPE PrimitiveType, UINT MinVertexIndex,
1879 UINT NumVertexIndices, UINT PrimitiveCount, CONST void* pIndexData,
1880 D3DFORMAT IndexDataFormat, CONST void* pVertexStreamZeroData, UINT VertexStreamZeroStride) {
1881 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1884 TRACE("iface %p, primitive_type %#x, min_vertex_idx %u, index_count %u, primitive_count %u,\n"
1885 "index_data %p, index_format %#x, vertex_data %p, vertex_stride %u.\n",
1886 iface, PrimitiveType, MinVertexIndex, NumVertexIndices, PrimitiveCount,
1887 pIndexData, IndexDataFormat, pVertexStreamZeroData, VertexStreamZeroStride);
1889 wined3d_mutex_lock();
1890 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1891 hr = IWineD3DDevice_DrawIndexedPrimitiveUP(This->WineD3DDevice,
1892 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount), pIndexData,
1893 wined3dformat_from_d3dformat(IndexDataFormat), pVertexStreamZeroData, VertexStreamZeroStride);
1894 wined3d_mutex_unlock();
1899 static HRESULT WINAPI IDirect3DDevice9Impl_ProcessVertices(LPDIRECT3DDEVICE9EX iface, UINT SrcStartIndex, UINT DestIndex, UINT VertexCount, IDirect3DVertexBuffer9* pDestBuffer, IDirect3DVertexDeclaration9* pVertexDecl, DWORD Flags) {
1900 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1901 IDirect3DVertexDeclaration9Impl *Decl = (IDirect3DVertexDeclaration9Impl *) pVertexDecl;
1903 IDirect3DVertexBuffer9Impl *dest = (IDirect3DVertexBuffer9Impl *) pDestBuffer;
1905 TRACE("iface %p, src_start_idx %u, dst_idx %u, vertex_count %u, dst_buffer %p, declaration %p, flags %#x.\n",
1906 iface, SrcStartIndex, DestIndex, VertexCount, pDestBuffer, pVertexDecl, Flags);
1908 wined3d_mutex_lock();
1909 hr = IWineD3DDevice_ProcessVertices(This->WineD3DDevice,SrcStartIndex, DestIndex, VertexCount, dest->wineD3DVertexBuffer, Decl ? Decl->wineD3DVertexDeclaration : NULL, Flags, dest->fvf);
1910 wined3d_mutex_unlock();
1915 static HRESULT WINAPI IDirect3DDevice9Impl_CreateVertexDeclaration(IDirect3DDevice9Ex *iface,
1916 const D3DVERTEXELEMENT9 *elements, IDirect3DVertexDeclaration9 **declaration)
1918 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1919 IDirect3DVertexDeclaration9Impl *object;
1922 TRACE("iface %p, elements %p, declaration %p.\n", iface, elements, declaration);
1926 WARN("Caller passed a NULL declaration, returning D3DERR_INVALIDCALL.\n");
1927 return D3DERR_INVALIDCALL;
1930 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1933 ERR("Failed to allocate vertex declaration memory.\n");
1934 return E_OUTOFMEMORY;
1937 hr = vertexdeclaration_init(object, This, elements);
1940 WARN("Failed to initialize vertex declaration, hr %#x.\n", hr);
1941 HeapFree(GetProcessHeap(), 0, object);
1945 TRACE("Created vertex declaration %p.\n", object);
1946 *declaration = (IDirect3DVertexDeclaration9 *)object;
1951 static IDirect3DVertexDeclaration9 *getConvertedDecl(IDirect3DDevice9Impl *This, DWORD fvf) {
1953 D3DVERTEXELEMENT9* elements = NULL;
1954 IDirect3DVertexDeclaration9* pDecl = NULL;
1955 int p, low, high; /* deliberately signed */
1956 IDirect3DVertexDeclaration9 **convertedDecls = This->convertedDecls;
1958 TRACE("Searching for declaration for fvf %08x... ", fvf);
1961 high = This->numConvertedDecls - 1;
1962 while(low <= high) {
1963 p = (low + high) >> 1;
1965 if(((IDirect3DVertexDeclaration9Impl *) convertedDecls[p])->convFVF == fvf) {
1966 TRACE("found %p\n", convertedDecls[p]);
1967 return convertedDecls[p];
1968 } else if(((IDirect3DVertexDeclaration9Impl *) convertedDecls[p])->convFVF < fvf) {
1974 TRACE("not found. Creating and inserting at position %d.\n", low);
1976 hr = vdecl_convert_fvf(fvf, &elements);
1977 if (hr != S_OK) return NULL;
1979 hr = IDirect3DDevice9Impl_CreateVertexDeclaration((IDirect3DDevice9Ex *) This, elements, &pDecl);
1980 HeapFree(GetProcessHeap(), 0, elements); /* CreateVertexDeclaration makes a copy */
1981 if (hr != S_OK) return NULL;
1983 if(This->declArraySize == This->numConvertedDecls) {
1984 int grow = max(This->declArraySize / 2, 8);
1985 convertedDecls = HeapReAlloc(GetProcessHeap(), 0, convertedDecls,
1986 sizeof(convertedDecls[0]) * (This->numConvertedDecls + grow));
1987 if(!convertedDecls) {
1988 /* This will destroy it */
1989 IDirect3DVertexDeclaration9_Release(pDecl);
1992 This->convertedDecls = convertedDecls;
1993 This->declArraySize += grow;
1996 memmove(convertedDecls + low + 1, convertedDecls + low, sizeof(IDirect3DVertexDeclaration9Impl *) * (This->numConvertedDecls - low));
1997 convertedDecls[low] = pDecl;
1998 This->numConvertedDecls++;
2000 /* Will prevent the decl from being destroyed */
2001 ((IDirect3DVertexDeclaration9Impl *) pDecl)->convFVF = fvf;
2002 IDirect3DVertexDeclaration9_Release(pDecl); /* Does not destroy now */
2004 TRACE("Returning %p. %d decls in array\n", pDecl, This->numConvertedDecls);
2008 static HRESULT WINAPI IDirect3DDevice9Impl_SetFVF(LPDIRECT3DDEVICE9EX iface, DWORD FVF) {
2009 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2010 IDirect3DVertexDeclaration9 *decl;
2013 TRACE("iface %p, fvf %#x.\n", iface, FVF);
2017 WARN("%#x is not a valid FVF\n", FVF);
2021 wined3d_mutex_lock();
2022 decl = getConvertedDecl(This, FVF);
2023 wined3d_mutex_unlock();
2027 /* Any situation when this should happen, except out of memory? */
2028 ERR("Failed to create a converted vertex declaration\n");
2029 return D3DERR_DRIVERINTERNALERROR;
2032 hr = IDirect3DDevice9Impl_SetVertexDeclaration(iface, decl);
2033 if (FAILED(hr)) ERR("Failed to set vertex declaration\n");
2038 static HRESULT WINAPI IDirect3DDevice9Impl_GetFVF(IDirect3DDevice9Ex *iface, DWORD *pFVF)
2040 IDirect3DVertexDeclaration9 *decl;
2043 TRACE("iface %p, fvf %p.\n", iface, pFVF);
2045 hr = IDirect3DDevice9_GetVertexDeclaration(iface, &decl);
2048 WARN("Failed to get vertex declaration, %#x\n", hr);
2055 *pFVF = ((IDirect3DVertexDeclaration9Impl *)decl)->convFVF;
2056 IDirect3DVertexDeclaration9_Release(decl);
2063 TRACE("Returning FVF %#x\n", *pFVF);
2068 static HRESULT WINAPI IDirect3DDevice9Impl_CreateVertexShader(IDirect3DDevice9Ex *iface,
2069 const DWORD *byte_code, IDirect3DVertexShader9 **shader)
2071 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2072 IDirect3DVertexShader9Impl *object;
2075 TRACE("iface %p, byte_code %p, shader %p.\n", iface, byte_code, shader);
2077 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2080 ERR("Failed to allocate vertex shader memory.\n");
2081 return E_OUTOFMEMORY;
2084 hr = vertexshader_init(object, This, byte_code);
2087 WARN("Failed to initialize vertex shader, hr %#x.\n", hr);
2088 HeapFree(GetProcessHeap(), 0, object);
2092 TRACE("Created vertex shader %p.\n", object);
2093 *shader = (IDirect3DVertexShader9 *)object;
2098 static HRESULT WINAPI IDirect3DDevice9Impl_SetStreamSource(LPDIRECT3DDEVICE9EX iface, UINT StreamNumber, IDirect3DVertexBuffer9* pStreamData, UINT OffsetInBytes, UINT Stride) {
2099 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2102 TRACE("iface %p, stream_idx %u, buffer %p, offset %u, stride %u.\n",
2103 iface, StreamNumber, pStreamData, OffsetInBytes, Stride);
2105 wined3d_mutex_lock();
2106 hr = IWineD3DDevice_SetStreamSource(This->WineD3DDevice, StreamNumber,
2107 pStreamData ? ((IDirect3DVertexBuffer9Impl *)pStreamData)->wineD3DVertexBuffer : NULL,
2108 OffsetInBytes, Stride);
2109 wined3d_mutex_unlock();
2114 static HRESULT WINAPI IDirect3DDevice9Impl_GetStreamSource(LPDIRECT3DDEVICE9EX iface, UINT StreamNumber, IDirect3DVertexBuffer9 **pStream, UINT* OffsetInBytes, UINT* pStride) {
2115 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2116 IWineD3DBuffer *retStream = NULL;
2117 HRESULT rc = D3D_OK;
2119 TRACE("iface %p, stream_idx %u, buffer %p, offset %p, stride %p.\n",
2120 iface, StreamNumber, pStream, OffsetInBytes, pStride);
2122 if(pStream == NULL){
2123 return D3DERR_INVALIDCALL;
2126 wined3d_mutex_lock();
2127 rc = IWineD3DDevice_GetStreamSource(This->WineD3DDevice, StreamNumber, &retStream, OffsetInBytes, pStride);
2128 if (rc == D3D_OK && NULL != retStream) {
2129 IWineD3DBuffer_GetParent(retStream, (IUnknown **)pStream);
2130 IWineD3DBuffer_Release(retStream);
2133 FIXME("Call to GetStreamSource failed %p %p\n", OffsetInBytes, pStride);
2137 wined3d_mutex_unlock();
2142 static HRESULT WINAPI IDirect3DDevice9Impl_SetStreamSourceFreq(IDirect3DDevice9Ex *iface, UINT StreamNumber,
2145 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2148 TRACE("iface %p, stream_idx %u, freq %u.\n", iface, StreamNumber, Divider);
2150 wined3d_mutex_lock();
2151 hr = IWineD3DDevice_SetStreamSourceFreq(This->WineD3DDevice, StreamNumber, Divider);
2152 wined3d_mutex_unlock();
2157 static HRESULT WINAPI IDirect3DDevice9Impl_GetStreamSourceFreq(LPDIRECT3DDEVICE9EX iface, UINT StreamNumber, UINT* Divider) {
2158 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2161 TRACE("iface %p, stream_idx %u, freq %p.\n", iface, StreamNumber, Divider);
2163 wined3d_mutex_lock();
2164 hr = IWineD3DDevice_GetStreamSourceFreq(This->WineD3DDevice, StreamNumber, Divider);
2165 wined3d_mutex_unlock();
2170 static HRESULT WINAPI IDirect3DDevice9Impl_SetIndices(LPDIRECT3DDEVICE9EX iface, IDirect3DIndexBuffer9* pIndexData) {
2171 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2173 IDirect3DIndexBuffer9Impl *ib = (IDirect3DIndexBuffer9Impl *) pIndexData;
2175 TRACE("iface %p, buffer %p.\n", iface, pIndexData);
2177 wined3d_mutex_lock();
2178 hr = IWineD3DDevice_SetIndexBuffer(This->WineD3DDevice,
2179 ib ? ib->wineD3DIndexBuffer : NULL,
2180 ib ? ib->format : WINED3DFMT_UNKNOWN);
2181 wined3d_mutex_unlock();
2186 static HRESULT WINAPI IDirect3DDevice9Impl_GetIndices(LPDIRECT3DDEVICE9EX iface, IDirect3DIndexBuffer9 **ppIndexData) {
2187 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2188 IWineD3DBuffer *retIndexData = NULL;
2189 HRESULT rc = D3D_OK;
2191 TRACE("iface %p, buffer %p.\n", iface, ppIndexData);
2193 if(ppIndexData == NULL){
2194 return D3DERR_INVALIDCALL;
2197 wined3d_mutex_lock();
2198 rc = IWineD3DDevice_GetIndexBuffer(This->WineD3DDevice, &retIndexData);
2199 if (SUCCEEDED(rc) && retIndexData) {
2200 IWineD3DBuffer_GetParent(retIndexData, (IUnknown **)ppIndexData);
2201 IWineD3DBuffer_Release(retIndexData);
2203 if (FAILED(rc)) FIXME("Call to GetIndices failed\n");
2204 *ppIndexData = NULL;
2206 wined3d_mutex_unlock();
2211 static HRESULT WINAPI IDirect3DDevice9Impl_CreatePixelShader(IDirect3DDevice9Ex *iface,
2212 const DWORD *byte_code, IDirect3DPixelShader9 **shader)
2214 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2215 IDirect3DPixelShader9Impl *object;
2218 TRACE("iface %p, byte_code %p, shader %p.\n", iface, byte_code, shader);
2220 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2223 FIXME("Failed to allocate pixel shader memory.\n");
2224 return E_OUTOFMEMORY;
2227 hr = pixelshader_init(object, This, byte_code);
2230 WARN("Failed to initialize pixel shader, hr %#x.\n", hr);
2231 HeapFree(GetProcessHeap(), 0, object);
2235 TRACE("Created pixel shader %p.\n", object);
2236 *shader = (IDirect3DPixelShader9 *)object;
2241 static HRESULT WINAPI IDirect3DDevice9Impl_DrawRectPatch(LPDIRECT3DDEVICE9EX iface, UINT Handle, CONST float* pNumSegs, CONST D3DRECTPATCH_INFO* pRectPatchInfo) {
2242 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2245 TRACE("iface %p, handle %#x, segment_count %p, patch_info %p.\n",
2246 iface, Handle, pNumSegs, pRectPatchInfo);
2248 wined3d_mutex_lock();
2249 hr = IWineD3DDevice_DrawRectPatch(This->WineD3DDevice, Handle, pNumSegs, (CONST WINED3DRECTPATCH_INFO *)pRectPatchInfo);
2250 wined3d_mutex_unlock();
2255 static HRESULT WINAPI IDirect3DDevice9Impl_DrawTriPatch(LPDIRECT3DDEVICE9EX iface, UINT Handle, CONST float* pNumSegs, CONST D3DTRIPATCH_INFO* pTriPatchInfo) {
2256 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2259 TRACE("iface %p, handle %#x, segment_count %p, patch_info %p.\n",
2260 iface, Handle, pNumSegs, pTriPatchInfo);
2262 wined3d_mutex_lock();
2263 hr = IWineD3DDevice_DrawTriPatch(This->WineD3DDevice, Handle, pNumSegs, (CONST WINED3DTRIPATCH_INFO *)pTriPatchInfo);
2264 wined3d_mutex_unlock();
2269 static HRESULT WINAPI IDirect3DDevice9Impl_DeletePatch(LPDIRECT3DDEVICE9EX iface, UINT Handle) {
2270 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2273 TRACE("iface %p, handle %#x.\n", iface, Handle);
2275 wined3d_mutex_lock();
2276 hr = IWineD3DDevice_DeletePatch(This->WineD3DDevice, Handle);
2277 wined3d_mutex_unlock();
2282 static HRESULT WINAPI IDirect3DDevice9Impl_CreateQuery(IDirect3DDevice9Ex *iface,
2283 D3DQUERYTYPE type, IDirect3DQuery9 **query)
2285 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2286 IDirect3DQuery9Impl *object;
2289 TRACE("iface %p, type %#x, query %p.\n", iface, type, query);
2291 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2294 ERR("Failed to allocate query memory.\n");
2295 return E_OUTOFMEMORY;
2298 hr = query_init(object, This, type);
2301 WARN("Failed to initialize query, hr %#x.\n", hr);
2302 HeapFree(GetProcessHeap(), 0, object);
2306 TRACE("Created query %p.\n", object);
2307 if (query) *query = (IDirect3DQuery9 *)object;
2308 else IDirect3DQuery9_Release((IDirect3DQuery9 *)object);
2313 static HRESULT WINAPI IDirect3DDevice9ExImpl_SetConvolutionMonoKernel(IDirect3DDevice9Ex *iface,
2314 UINT width, UINT height, float *rows, float *columns)
2316 FIXME("iface %p, width %u, height %u, rows %p, columns %p stub!\n",
2317 iface, width, height, rows, columns);
2319 return WINED3DERR_INVALIDCALL;
2322 static HRESULT WINAPI IDirect3DDevice9ExImpl_ComposeRects(IDirect3DDevice9Ex *iface,
2323 IDirect3DSurface9 *src_surface, IDirect3DSurface9 *dst_surface, IDirect3DVertexBuffer9 *src_descs,
2324 UINT rect_count, IDirect3DVertexBuffer9 *dst_descs, D3DCOMPOSERECTSOP operation, INT offset_x, INT offset_y)
2326 FIXME("iface %p, src_surface %p, dst_surface %p, src_descs %p, rect_count %u,\n"
2327 "dst_descs %p, operation %#x, offset_x %u, offset_y %u stub!\n",
2328 iface, src_surface, dst_surface, src_descs, rect_count,
2329 dst_descs, operation, offset_x, offset_y);
2331 return WINED3DERR_INVALIDCALL;
2334 static HRESULT WINAPI IDirect3DDevice9ExImpl_PresentEx(IDirect3DDevice9Ex *iface,
2335 const RECT *src_rect, const RECT *dst_rect, HWND dst_window_override,
2336 const RGNDATA *dirty_region, DWORD flags)
2338 FIXME("iface %p, src_rect %p, dst_rect %p, dst_window_override %p, dirty_region %p, flags %#x stub!\n",
2339 iface, src_rect, dst_rect, dst_window_override, dirty_region, flags);
2341 return WINED3DERR_INVALIDCALL;
2344 static HRESULT WINAPI IDirect3DDevice9ExImpl_GetGPUThreadPriority(IDirect3DDevice9Ex *iface, INT *priority)
2346 FIXME("iface %p, priority %p stub!\n", iface, priority);
2348 return WINED3DERR_INVALIDCALL;
2351 static HRESULT WINAPI IDirect3DDevice9ExImpl_SetGPUThreadPriority(IDirect3DDevice9Ex *iface, INT priority)
2353 FIXME("iface %p, priority %d stub!\n", iface, priority);
2355 return WINED3DERR_INVALIDCALL;
2358 static HRESULT WINAPI IDirect3DDevice9ExImpl_WaitForVBlank(IDirect3DDevice9Ex *iface, UINT swapchain_idx)
2360 FIXME("iface %p, swapchain_idx %u stub!\n", iface, swapchain_idx);
2362 return WINED3DERR_INVALIDCALL;
2365 static HRESULT WINAPI IDirect3DDevice9ExImpl_CheckResourceResidency(IDirect3DDevice9Ex *iface,
2366 IDirect3DResource9 **resources, UINT32 resource_count)
2368 FIXME("iface %p, resources %p, resource_count %u stub!\n",
2369 iface, resources, resource_count);
2371 return WINED3DERR_INVALIDCALL;
2374 static HRESULT WINAPI IDirect3DDevice9ExImpl_SetMaximumFrameLatency(IDirect3DDevice9Ex *iface, UINT max_latency)
2376 FIXME("iface %p, max_latency %u stub!\n", iface, max_latency);
2378 return WINED3DERR_INVALIDCALL;
2381 static HRESULT WINAPI IDirect3DDevice9ExImpl_GetMaximumFrameLatency(IDirect3DDevice9Ex *iface, UINT *max_latency)
2383 FIXME("iface %p, max_latency %p stub!\n", iface, max_latency);
2387 return WINED3DERR_INVALIDCALL;
2390 static HRESULT WINAPI IDirect3DDevice9ExImpl_CheckDeviceState(IDirect3DDevice9Ex *iface, HWND dst_window)
2392 FIXME("iface %p, dst_window %p stub!\n", iface, dst_window);
2394 return WINED3DERR_INVALIDCALL;
2397 static HRESULT WINAPI IDirect3DDevice9ExImpl_CreateRenderTargetEx(IDirect3DDevice9Ex *iface,
2398 UINT width, UINT height, D3DFORMAT format, D3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality,
2399 BOOL lockable, IDirect3DSurface9 **surface, HANDLE *shared_handle, DWORD usage)
2401 FIXME("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u,\n"
2402 "lockable %#x, surface %p, shared_handle %p, usage %#x stub!\n",
2403 iface, width, height, format, multisample_type, multisample_quality,
2404 lockable, surface, shared_handle, usage);
2406 return WINED3DERR_INVALIDCALL;
2409 static HRESULT WINAPI IDirect3DDevice9ExImpl_CreateOffscreenPlainSurfaceEx(IDirect3DDevice9Ex *iface,
2410 UINT width, UINT height, D3DFORMAT format, D3DPOOL pool, IDirect3DSurface9 **surface,
2411 HANDLE *shared_handle, DWORD usage)
2413 FIXME("iface %p, width %u, height %u, format %#x, pool %#x, surface %p, shared_handle %p, usage %#x stub!\n",
2414 iface, width, height, format, pool, surface, shared_handle, usage);
2416 return WINED3DERR_INVALIDCALL;
2419 static HRESULT WINAPI IDirect3DDevice9ExImpl_CreateDepthStencilSurfaceEx(IDirect3DDevice9Ex *iface,
2420 UINT width, UINT height, D3DFORMAT format, D3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality,
2421 BOOL discard, IDirect3DSurface9 **surface, HANDLE *shared_handle, DWORD usage)
2423 FIXME("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u,\n"
2424 "discard %#x, surface %p, shared_handle %p, usage %#x stub!\n",
2425 iface, width, height, format, multisample_type, multisample_quality,
2426 discard, surface, shared_handle, usage);
2428 return WINED3DERR_INVALIDCALL;
2431 static HRESULT WINAPI IDirect3DDevice9ExImpl_ResetEx(IDirect3DDevice9Ex *iface,
2432 D3DPRESENT_PARAMETERS *present_parameters, D3DDISPLAYMODEEX *mode)
2434 FIXME("iface %p, present_parameters %p, mode %p stub!\n", iface, present_parameters, mode);
2436 return WINED3DERR_INVALIDCALL;
2439 static HRESULT WINAPI IDirect3DDevice9ExImpl_GetDisplayModeEx(IDirect3DDevice9Ex *iface,
2440 UINT swapchain_idx, D3DDISPLAYMODEEX *mode, D3DDISPLAYROTATION *rotation)
2442 FIXME("iface %p, swapchain_idx %u, mode %p, rotation %p stub!\n", iface, swapchain_idx, mode, rotation);
2444 return WINED3DERR_INVALIDCALL;
2447 static const IDirect3DDevice9ExVtbl Direct3DDevice9_Vtbl =
2450 IDirect3DDevice9Impl_QueryInterface,
2451 IDirect3DDevice9Impl_AddRef,
2452 IDirect3DDevice9Impl_Release,
2453 /* IDirect3DDevice9 */
2454 IDirect3DDevice9Impl_TestCooperativeLevel,
2455 IDirect3DDevice9Impl_GetAvailableTextureMem,
2456 IDirect3DDevice9Impl_EvictManagedResources,
2457 IDirect3DDevice9Impl_GetDirect3D,
2458 IDirect3DDevice9Impl_GetDeviceCaps,
2459 IDirect3DDevice9Impl_GetDisplayMode,
2460 IDirect3DDevice9Impl_GetCreationParameters,
2461 IDirect3DDevice9Impl_SetCursorProperties,
2462 IDirect3DDevice9Impl_SetCursorPosition,
2463 IDirect3DDevice9Impl_ShowCursor,
2464 IDirect3DDevice9Impl_CreateAdditionalSwapChain,
2465 IDirect3DDevice9Impl_GetSwapChain,
2466 IDirect3DDevice9Impl_GetNumberOfSwapChains,
2467 IDirect3DDevice9Impl_Reset,
2468 IDirect3DDevice9Impl_Present,
2469 IDirect3DDevice9Impl_GetBackBuffer,
2470 IDirect3DDevice9Impl_GetRasterStatus,
2471 IDirect3DDevice9Impl_SetDialogBoxMode,
2472 IDirect3DDevice9Impl_SetGammaRamp,
2473 IDirect3DDevice9Impl_GetGammaRamp,
2474 IDirect3DDevice9Impl_CreateTexture,
2475 IDirect3DDevice9Impl_CreateVolumeTexture,
2476 IDirect3DDevice9Impl_CreateCubeTexture,
2477 IDirect3DDevice9Impl_CreateVertexBuffer,
2478 IDirect3DDevice9Impl_CreateIndexBuffer,
2479 IDirect3DDevice9Impl_CreateRenderTarget,
2480 IDirect3DDevice9Impl_CreateDepthStencilSurface,
2481 IDirect3DDevice9Impl_UpdateSurface,
2482 IDirect3DDevice9Impl_UpdateTexture,
2483 IDirect3DDevice9Impl_GetRenderTargetData,
2484 IDirect3DDevice9Impl_GetFrontBufferData,
2485 IDirect3DDevice9Impl_StretchRect,
2486 IDirect3DDevice9Impl_ColorFill,
2487 IDirect3DDevice9Impl_CreateOffscreenPlainSurface,
2488 IDirect3DDevice9Impl_SetRenderTarget,
2489 IDirect3DDevice9Impl_GetRenderTarget,
2490 IDirect3DDevice9Impl_SetDepthStencilSurface,
2491 IDirect3DDevice9Impl_GetDepthStencilSurface,
2492 IDirect3DDevice9Impl_BeginScene,
2493 IDirect3DDevice9Impl_EndScene,
2494 IDirect3DDevice9Impl_Clear,
2495 IDirect3DDevice9Impl_SetTransform,
2496 IDirect3DDevice9Impl_GetTransform,
2497 IDirect3DDevice9Impl_MultiplyTransform,
2498 IDirect3DDevice9Impl_SetViewport,
2499 IDirect3DDevice9Impl_GetViewport,
2500 IDirect3DDevice9Impl_SetMaterial,
2501 IDirect3DDevice9Impl_GetMaterial,
2502 IDirect3DDevice9Impl_SetLight,
2503 IDirect3DDevice9Impl_GetLight,
2504 IDirect3DDevice9Impl_LightEnable,
2505 IDirect3DDevice9Impl_GetLightEnable,
2506 IDirect3DDevice9Impl_SetClipPlane,
2507 IDirect3DDevice9Impl_GetClipPlane,
2508 IDirect3DDevice9Impl_SetRenderState,
2509 IDirect3DDevice9Impl_GetRenderState,
2510 IDirect3DDevice9Impl_CreateStateBlock,
2511 IDirect3DDevice9Impl_BeginStateBlock,
2512 IDirect3DDevice9Impl_EndStateBlock,
2513 IDirect3DDevice9Impl_SetClipStatus,
2514 IDirect3DDevice9Impl_GetClipStatus,
2515 IDirect3DDevice9Impl_GetTexture,
2516 IDirect3DDevice9Impl_SetTexture,
2517 IDirect3DDevice9Impl_GetTextureStageState,
2518 IDirect3DDevice9Impl_SetTextureStageState,
2519 IDirect3DDevice9Impl_GetSamplerState,
2520 IDirect3DDevice9Impl_SetSamplerState,
2521 IDirect3DDevice9Impl_ValidateDevice,
2522 IDirect3DDevice9Impl_SetPaletteEntries,
2523 IDirect3DDevice9Impl_GetPaletteEntries,
2524 IDirect3DDevice9Impl_SetCurrentTexturePalette,
2525 IDirect3DDevice9Impl_GetCurrentTexturePalette,
2526 IDirect3DDevice9Impl_SetScissorRect,
2527 IDirect3DDevice9Impl_GetScissorRect,
2528 IDirect3DDevice9Impl_SetSoftwareVertexProcessing,
2529 IDirect3DDevice9Impl_GetSoftwareVertexProcessing,
2530 IDirect3DDevice9Impl_SetNPatchMode,
2531 IDirect3DDevice9Impl_GetNPatchMode,
2532 IDirect3DDevice9Impl_DrawPrimitive,
2533 IDirect3DDevice9Impl_DrawIndexedPrimitive,
2534 IDirect3DDevice9Impl_DrawPrimitiveUP,
2535 IDirect3DDevice9Impl_DrawIndexedPrimitiveUP,
2536 IDirect3DDevice9Impl_ProcessVertices,
2537 IDirect3DDevice9Impl_CreateVertexDeclaration,
2538 IDirect3DDevice9Impl_SetVertexDeclaration,
2539 IDirect3DDevice9Impl_GetVertexDeclaration,
2540 IDirect3DDevice9Impl_SetFVF,
2541 IDirect3DDevice9Impl_GetFVF,
2542 IDirect3DDevice9Impl_CreateVertexShader,
2543 IDirect3DDevice9Impl_SetVertexShader,
2544 IDirect3DDevice9Impl_GetVertexShader,
2545 IDirect3DDevice9Impl_SetVertexShaderConstantF,
2546 IDirect3DDevice9Impl_GetVertexShaderConstantF,
2547 IDirect3DDevice9Impl_SetVertexShaderConstantI,
2548 IDirect3DDevice9Impl_GetVertexShaderConstantI,
2549 IDirect3DDevice9Impl_SetVertexShaderConstantB,
2550 IDirect3DDevice9Impl_GetVertexShaderConstantB,
2551 IDirect3DDevice9Impl_SetStreamSource,
2552 IDirect3DDevice9Impl_GetStreamSource,
2553 IDirect3DDevice9Impl_SetStreamSourceFreq,
2554 IDirect3DDevice9Impl_GetStreamSourceFreq,
2555 IDirect3DDevice9Impl_SetIndices,
2556 IDirect3DDevice9Impl_GetIndices,
2557 IDirect3DDevice9Impl_CreatePixelShader,
2558 IDirect3DDevice9Impl_SetPixelShader,
2559 IDirect3DDevice9Impl_GetPixelShader,
2560 IDirect3DDevice9Impl_SetPixelShaderConstantF,
2561 IDirect3DDevice9Impl_GetPixelShaderConstantF,
2562 IDirect3DDevice9Impl_SetPixelShaderConstantI,
2563 IDirect3DDevice9Impl_GetPixelShaderConstantI,
2564 IDirect3DDevice9Impl_SetPixelShaderConstantB,
2565 IDirect3DDevice9Impl_GetPixelShaderConstantB,
2566 IDirect3DDevice9Impl_DrawRectPatch,
2567 IDirect3DDevice9Impl_DrawTriPatch,
2568 IDirect3DDevice9Impl_DeletePatch,
2569 IDirect3DDevice9Impl_CreateQuery,
2570 /* IDirect3DDevice9Ex */
2571 IDirect3DDevice9ExImpl_SetConvolutionMonoKernel,
2572 IDirect3DDevice9ExImpl_ComposeRects,
2573 IDirect3DDevice9ExImpl_PresentEx,
2574 IDirect3DDevice9ExImpl_GetGPUThreadPriority,
2575 IDirect3DDevice9ExImpl_SetGPUThreadPriority,
2576 IDirect3DDevice9ExImpl_WaitForVBlank,
2577 IDirect3DDevice9ExImpl_CheckResourceResidency,
2578 IDirect3DDevice9ExImpl_SetMaximumFrameLatency,
2579 IDirect3DDevice9ExImpl_GetMaximumFrameLatency,
2580 IDirect3DDevice9ExImpl_CheckDeviceState,
2581 IDirect3DDevice9ExImpl_CreateRenderTargetEx,
2582 IDirect3DDevice9ExImpl_CreateOffscreenPlainSurfaceEx,
2583 IDirect3DDevice9ExImpl_CreateDepthStencilSurfaceEx,
2584 IDirect3DDevice9ExImpl_ResetEx,
2585 IDirect3DDevice9ExImpl_GetDisplayModeEx
2588 /* IWineD3DDeviceParent IUnknown methods */
2590 static inline struct IDirect3DDevice9Impl *device_from_device_parent(IWineD3DDeviceParent *iface)
2592 return (struct IDirect3DDevice9Impl *)((char*)iface
2593 - FIELD_OFFSET(struct IDirect3DDevice9Impl, device_parent_vtbl));
2596 static HRESULT STDMETHODCALLTYPE device_parent_QueryInterface(IWineD3DDeviceParent *iface, REFIID riid, void **object)
2598 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
2599 return IDirect3DDevice9Impl_QueryInterface((IDirect3DDevice9Ex *)This, riid, object);
2602 static ULONG STDMETHODCALLTYPE device_parent_AddRef(IWineD3DDeviceParent *iface)
2604 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
2605 return IDirect3DDevice9Impl_AddRef((IDirect3DDevice9Ex *)This);
2608 static ULONG STDMETHODCALLTYPE device_parent_Release(IWineD3DDeviceParent *iface)
2610 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
2611 return IDirect3DDevice9Impl_Release((IDirect3DDevice9Ex *)This);
2614 /* IWineD3DDeviceParent methods */
2616 static void STDMETHODCALLTYPE device_parent_WineD3DDeviceCreated(IWineD3DDeviceParent *iface, IWineD3DDevice *device)
2618 TRACE("iface %p, device %p\n", iface, device);
2621 static HRESULT STDMETHODCALLTYPE device_parent_CreateSurface(IWineD3DDeviceParent *iface,
2622 IUnknown *superior, UINT width, UINT height, enum wined3d_format_id format, DWORD usage,
2623 WINED3DPOOL pool, UINT level, WINED3DCUBEMAP_FACES face, IWineD3DSurface **surface)
2625 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
2626 IDirect3DSurface9Impl *d3d_surface;
2627 BOOL lockable = TRUE;
2630 TRACE("iface %p, superior %p, width %u, height %u, format %#x, usage %#x,\n"
2631 "\tpool %#x, level %u, face %u, surface %p\n",
2632 iface, superior, width, height, format, usage, pool, level, face, surface);
2634 if (pool == WINED3DPOOL_DEFAULT && !(usage & D3DUSAGE_DYNAMIC))
2637 hr = IDirect3DDevice9Impl_CreateSurface((IDirect3DDevice9Ex *)This, width, height,
2638 d3dformat_from_wined3dformat(format), lockable, FALSE /* Discard */, level,
2639 (IDirect3DSurface9 **)&d3d_surface, usage, pool, D3DMULTISAMPLE_NONE, 0 /* MultisampleQuality */);
2642 ERR("(%p) CreateSurface failed, returning %#x\n", iface, hr);
2646 *surface = d3d_surface->wineD3DSurface;
2647 IWineD3DSurface_AddRef(*surface);
2649 d3d_surface->container = superior;
2650 IDirect3DDevice9Ex_Release(d3d_surface->parentDevice);
2651 d3d_surface->parentDevice = NULL;
2653 IDirect3DSurface9_Release((IDirect3DSurface9 *)d3d_surface);
2654 d3d_surface->forwardReference = superior;
2659 static HRESULT STDMETHODCALLTYPE device_parent_CreateRenderTarget(IWineD3DDeviceParent *iface,
2660 IUnknown *superior, UINT width, UINT height, enum wined3d_format_id format,
2661 WINED3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality, BOOL lockable,
2662 IWineD3DSurface **surface)
2664 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
2665 IDirect3DSurface9Impl *d3d_surface;
2668 TRACE("iface %p, superior %p, width %u, height %u, format %#x, multisample_type %#x,\n"
2669 "\tmultisample_quality %u, lockable %u, surface %p\n",
2670 iface, superior, width, height, format, multisample_type, multisample_quality, lockable, surface);
2672 hr = IDirect3DDevice9Impl_CreateRenderTarget((IDirect3DDevice9Ex *)This, width, height,
2673 d3dformat_from_wined3dformat(format), multisample_type, multisample_quality, lockable,
2674 (IDirect3DSurface9 **)&d3d_surface, NULL);
2677 ERR("(%p) CreateRenderTarget failed, returning %#x\n", iface, hr);
2681 *surface = d3d_surface->wineD3DSurface;
2682 IWineD3DSurface_AddRef(*surface);
2684 d3d_surface->container = superior;
2685 /* Implicit surfaces are created with an refcount of 0 */
2686 IDirect3DSurface9_Release((IDirect3DSurface9 *)d3d_surface);
2691 static HRESULT STDMETHODCALLTYPE device_parent_CreateDepthStencilSurface(IWineD3DDeviceParent *iface,
2692 IUnknown *superior, UINT width, UINT height, enum wined3d_format_id format,
2693 WINED3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality, BOOL discard,
2694 IWineD3DSurface **surface)
2696 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
2697 IDirect3DSurface9Impl *d3d_surface;
2700 TRACE("iface %p, superior %p, width %u, height %u, format %#x, multisample_type %#x,\n"
2701 "\tmultisample_quality %u, discard %u, surface %p\n",
2702 iface, superior, width, height, format, multisample_type, multisample_quality, discard, surface);
2704 hr = IDirect3DDevice9Impl_CreateDepthStencilSurface((IDirect3DDevice9Ex *)This, width, height,
2705 d3dformat_from_wined3dformat(format), multisample_type, multisample_quality, discard,
2706 (IDirect3DSurface9 **)&d3d_surface, NULL);
2709 ERR("(%p) CreateDepthStencilSurface failed, returning %#x\n", iface, hr);
2713 *surface = d3d_surface->wineD3DSurface;
2714 IWineD3DSurface_AddRef(*surface);
2715 d3d_surface->container = (IUnknown *)This;
2716 /* Implicit surfaces are created with an refcount of 0 */
2717 IDirect3DSurface9_Release((IDirect3DSurface9 *)d3d_surface);
2722 static HRESULT STDMETHODCALLTYPE device_parent_CreateVolume(IWineD3DDeviceParent *iface,
2723 IUnknown *superior, UINT width, UINT height, UINT depth, enum wined3d_format_id format,
2724 WINED3DPOOL pool, DWORD usage, IWineD3DVolume **volume)
2726 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
2727 IDirect3DVolume9Impl *object;
2730 TRACE("iface %p, superior %p, width %u, height %u, depth %u, format %#x, pool %#x, usage %#x, volume %p\n",
2731 iface, superior, width, height, depth, format, pool, usage, volume);
2733 /* Allocate the storage for the device */
2734 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2737 FIXME("Allocation of memory failed\n");
2739 return D3DERR_OUTOFVIDEOMEMORY;
2742 hr = volume_init(object, This, width, height, depth, usage, format, pool);
2745 WARN("Failed to initialize volume, hr %#x.\n", hr);
2746 HeapFree(GetProcessHeap(), 0, object);
2750 *volume = object->wineD3DVolume;
2751 IWineD3DVolume_AddRef(*volume);
2752 IDirect3DVolume9_Release((IDirect3DVolume9 *)object);
2754 object->container = superior;
2755 object->forwardReference = superior;
2757 TRACE("(%p) Created volume %p\n", iface, object);
2762 static HRESULT STDMETHODCALLTYPE device_parent_CreateSwapChain(IWineD3DDeviceParent *iface,
2763 WINED3DPRESENT_PARAMETERS *present_parameters, IWineD3DSwapChain **swapchain)
2765 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
2766 IDirect3DSwapChain9Impl *d3d_swapchain;
2767 D3DPRESENT_PARAMETERS local_parameters;
2770 TRACE("iface %p, present_parameters %p, swapchain %p\n", iface, present_parameters, swapchain);
2772 /* Copy the presentation parameters */
2773 local_parameters.BackBufferWidth = present_parameters->BackBufferWidth;
2774 local_parameters.BackBufferHeight = present_parameters->BackBufferHeight;
2775 local_parameters.BackBufferFormat = d3dformat_from_wined3dformat(present_parameters->BackBufferFormat);
2776 local_parameters.BackBufferCount = present_parameters->BackBufferCount;
2777 local_parameters.MultiSampleType = present_parameters->MultiSampleType;
2778 local_parameters.MultiSampleQuality = present_parameters->MultiSampleQuality;
2779 local_parameters.SwapEffect = present_parameters->SwapEffect;
2780 local_parameters.hDeviceWindow = present_parameters->hDeviceWindow;
2781 local_parameters.Windowed = present_parameters->Windowed;
2782 local_parameters.EnableAutoDepthStencil = present_parameters->EnableAutoDepthStencil;
2783 local_parameters.AutoDepthStencilFormat = d3dformat_from_wined3dformat(present_parameters->AutoDepthStencilFormat);
2784 local_parameters.Flags = present_parameters->Flags;
2785 local_parameters.FullScreen_RefreshRateInHz = present_parameters->FullScreen_RefreshRateInHz;
2786 local_parameters.PresentationInterval = present_parameters->PresentationInterval;
2788 hr = IDirect3DDevice9Impl_CreateAdditionalSwapChain((IDirect3DDevice9Ex *)This,
2789 &local_parameters, (IDirect3DSwapChain9 **)&d3d_swapchain);
2792 ERR("(%p) CreateAdditionalSwapChain failed, returning %#x\n", iface, hr);
2797 *swapchain = d3d_swapchain->wineD3DSwapChain;
2798 d3d_swapchain->isImplicit = TRUE;
2799 /* Implicit swap chains are created with an refcount of 0 */
2800 IDirect3DSwapChain9_Release((IDirect3DSwapChain9 *)d3d_swapchain);
2802 /* Copy back the presentation parameters */
2803 present_parameters->BackBufferWidth = local_parameters.BackBufferWidth;
2804 present_parameters->BackBufferHeight = local_parameters.BackBufferHeight;
2805 present_parameters->BackBufferFormat = wined3dformat_from_d3dformat(local_parameters.BackBufferFormat);
2806 present_parameters->BackBufferCount = local_parameters.BackBufferCount;
2807 present_parameters->MultiSampleType = local_parameters.MultiSampleType;
2808 present_parameters->MultiSampleQuality = local_parameters.MultiSampleQuality;
2809 present_parameters->SwapEffect = local_parameters.SwapEffect;
2810 present_parameters->hDeviceWindow = local_parameters.hDeviceWindow;
2811 present_parameters->Windowed = local_parameters.Windowed;
2812 present_parameters->EnableAutoDepthStencil = local_parameters.EnableAutoDepthStencil;
2813 present_parameters->AutoDepthStencilFormat = wined3dformat_from_d3dformat(local_parameters.AutoDepthStencilFormat);
2814 present_parameters->Flags = local_parameters.Flags;
2815 present_parameters->FullScreen_RefreshRateInHz = local_parameters.FullScreen_RefreshRateInHz;
2816 present_parameters->PresentationInterval = local_parameters.PresentationInterval;
2821 static const IWineD3DDeviceParentVtbl d3d9_wined3d_device_parent_vtbl =
2823 /* IUnknown methods */
2824 device_parent_QueryInterface,
2825 device_parent_AddRef,
2826 device_parent_Release,
2827 /* IWineD3DDeviceParent methods */
2828 device_parent_WineD3DDeviceCreated,
2829 device_parent_CreateSurface,
2830 device_parent_CreateRenderTarget,
2831 device_parent_CreateDepthStencilSurface,
2832 device_parent_CreateVolume,
2833 device_parent_CreateSwapChain,
2836 static void setup_fpu(void)
2840 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
2841 __asm__ volatile ("fnstcw %0" : "=m" (cw));
2842 cw = (cw & ~0xf3f) | 0x3f;
2843 __asm__ volatile ("fldcw %0" : : "m" (cw));
2845 FIXME("FPU setup not implemented for this platform.\n");
2849 HRESULT device_init(IDirect3DDevice9Impl *device, IWineD3D *wined3d, UINT adapter, D3DDEVTYPE device_type,
2850 HWND focus_window, DWORD flags, D3DPRESENT_PARAMETERS *parameters)
2852 WINED3DPRESENT_PARAMETERS *wined3d_parameters;
2856 device->lpVtbl = &Direct3DDevice9_Vtbl;
2857 device->device_parent_vtbl = &d3d9_wined3d_device_parent_vtbl;
2860 if (!(flags & D3DCREATE_FPU_PRESERVE)) setup_fpu();
2862 wined3d_mutex_lock();
2863 hr = IWineD3D_CreateDevice(wined3d, adapter, device_type, focus_window, flags, (IUnknown *)device,
2864 (IWineD3DDeviceParent *)&device->device_parent_vtbl, &device->WineD3DDevice);
2867 WARN("Failed to create wined3d device, hr %#x.\n", hr);
2868 wined3d_mutex_unlock();
2872 if (!parameters->Windowed)
2874 if (!focus_window) focus_window = parameters->hDeviceWindow;
2875 if (FAILED(hr = IWineD3DDevice_AcquireFocusWindow(device->WineD3DDevice, focus_window)))
2877 ERR("Failed to acquire focus window, hr %#x.\n", hr);
2878 IWineD3DDevice_Release(device->WineD3DDevice);
2879 wined3d_mutex_unlock();
2884 if (flags & D3DCREATE_ADAPTERGROUP_DEVICE)
2888 IWineD3D_GetDeviceCaps(wined3d, adapter, device_type, &caps);
2889 count = caps.NumberOfAdaptersInGroup;
2892 if (flags & D3DCREATE_MULTITHREADED) IWineD3DDevice_SetMultithreaded(device->WineD3DDevice);
2894 wined3d_parameters = HeapAlloc(GetProcessHeap(), 0, sizeof(*wined3d_parameters) * count);
2895 if (!wined3d_parameters)
2897 ERR("Failed to allocate wined3d parameters.\n");
2898 IWineD3DDevice_Release(device->WineD3DDevice);
2899 wined3d_mutex_unlock();
2900 return E_OUTOFMEMORY;
2903 for (i = 0; i < count; ++i)
2905 wined3d_parameters[i].BackBufferWidth = parameters[i].BackBufferWidth;
2906 wined3d_parameters[i].BackBufferHeight = parameters[i].BackBufferHeight;
2907 wined3d_parameters[i].BackBufferFormat = wined3dformat_from_d3dformat(parameters[i].BackBufferFormat);
2908 wined3d_parameters[i].BackBufferCount = parameters[i].BackBufferCount;
2909 wined3d_parameters[i].MultiSampleType = parameters[i].MultiSampleType;
2910 wined3d_parameters[i].MultiSampleQuality = parameters[i].MultiSampleQuality;
2911 wined3d_parameters[i].SwapEffect = parameters[i].SwapEffect;
2912 wined3d_parameters[i].hDeviceWindow = parameters[i].hDeviceWindow;
2913 wined3d_parameters[i].Windowed = parameters[i].Windowed;
2914 wined3d_parameters[i].EnableAutoDepthStencil = parameters[i].EnableAutoDepthStencil;
2915 wined3d_parameters[i].AutoDepthStencilFormat =
2916 wined3dformat_from_d3dformat(parameters[i].AutoDepthStencilFormat);
2917 wined3d_parameters[i].Flags = parameters[i].Flags;
2918 wined3d_parameters[i].FullScreen_RefreshRateInHz = parameters[i].FullScreen_RefreshRateInHz;
2919 wined3d_parameters[i].PresentationInterval = parameters[i].PresentationInterval;
2920 wined3d_parameters[i].AutoRestoreDisplayMode = TRUE;
2923 hr = IWineD3DDevice_Init3D(device->WineD3DDevice, wined3d_parameters);
2926 WARN("Failed to initialize 3D, hr %#x.\n", hr);
2927 IWineD3DDevice_ReleaseFocusWindow(device->WineD3DDevice);
2928 HeapFree(GetProcessHeap(), 0, wined3d_parameters);
2929 IWineD3DDevice_Release(device->WineD3DDevice);
2930 wined3d_mutex_unlock();
2934 wined3d_mutex_unlock();
2936 for (i = 0; i < count; ++i)
2938 parameters[i].BackBufferWidth = wined3d_parameters[i].BackBufferWidth;
2939 parameters[i].BackBufferHeight = wined3d_parameters[i].BackBufferHeight;
2940 parameters[i].BackBufferFormat = d3dformat_from_wined3dformat(wined3d_parameters[i].BackBufferFormat);
2941 parameters[i].BackBufferCount = wined3d_parameters[i].BackBufferCount;
2942 parameters[i].MultiSampleType = wined3d_parameters[i].MultiSampleType;
2943 parameters[i].MultiSampleQuality = wined3d_parameters[i].MultiSampleQuality;
2944 parameters[i].SwapEffect = wined3d_parameters[i].SwapEffect;
2945 parameters[i].hDeviceWindow = wined3d_parameters[i].hDeviceWindow;
2946 parameters[i].Windowed = wined3d_parameters[i].Windowed;
2947 parameters[i].EnableAutoDepthStencil = wined3d_parameters[i].EnableAutoDepthStencil;
2948 parameters[i].AutoDepthStencilFormat =
2949 d3dformat_from_wined3dformat(wined3d_parameters[i].AutoDepthStencilFormat);
2950 parameters[i].Flags = wined3d_parameters[i].Flags;
2951 parameters[i].FullScreen_RefreshRateInHz = wined3d_parameters[i].FullScreen_RefreshRateInHz;
2952 parameters[i].PresentationInterval = wined3d_parameters[i].PresentationInterval;
2954 HeapFree(GetProcessHeap(), 0, wined3d_parameters);
2956 /* Initialize the converted declaration array. This creates a valid pointer
2957 * and when adding decls HeapReAlloc() can be used without further checking. */
2958 device->convertedDecls = HeapAlloc(GetProcessHeap(), 0, 0);
2959 if (!device->convertedDecls)
2961 ERR("Failed to allocate FVF vertex declaration map memory.\n");
2962 wined3d_mutex_lock();
2963 IWineD3DDevice_Uninit3D(device->WineD3DDevice, D3D9CB_DestroySwapChain);
2964 IWineD3DDevice_ReleaseFocusWindow(device->WineD3DDevice);
2965 IWineD3DDevice_Release(device->WineD3DDevice);
2966 wined3d_mutex_unlock();
2967 return E_OUTOFMEMORY;