VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/device.c@ 35650

Last change on this file since 35650 was 35650, checked in by vboxsync, 14 years ago

wddm/3d: cube texture support fixes + some cleanup & refactoring

  • Property svn:eol-style set to native
File size: 117.7 KB
Line 
1/*
2 * IDirect3DDevice9 implementation
3 *
4 * Copyright 2002-2005 Jason Edmeades
5 * Copyright 2002-2005 Raphael Junqueira
6 * Copyright 2005 Oliver Stieber
7 *
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.
12 *
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.
17 *
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
21 */
22
23/*
24 * Oracle LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
25 * other than GPL or LGPL is available it will apply instead, Oracle elects to use only
26 * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
27 * a choice of LGPL license versions is made available with the language indicating
28 * that LGPLv2 or any later version may be used, or where a choice of which version
29 * of the LGPL is applied is otherwise unspecified.
30 */
31
32#include "config.h"
33#include "d3d9_private.h"
34
35WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
36
37D3DFORMAT d3dformat_from_wined3dformat(WINED3DFORMAT format)
38{
39 BYTE *c = (BYTE *)&format;
40
41 /* Don't translate FOURCC formats */
42 if (isprint(c[0]) && isprint(c[1]) && isprint(c[2]) && isprint(c[3])) return format;
43
44 switch(format)
45 {
46 case WINED3DFMT_UNKNOWN: return D3DFMT_UNKNOWN;
47 case WINED3DFMT_B8G8R8_UNORM: return D3DFMT_R8G8B8;
48 case WINED3DFMT_B8G8R8A8_UNORM: return D3DFMT_A8R8G8B8;
49 case WINED3DFMT_B8G8R8X8_UNORM: return D3DFMT_X8R8G8B8;
50 case WINED3DFMT_B5G6R5_UNORM: return D3DFMT_R5G6B5;
51 case WINED3DFMT_B5G5R5X1_UNORM: return D3DFMT_X1R5G5B5;
52 case WINED3DFMT_B5G5R5A1_UNORM: return D3DFMT_A1R5G5B5;
53 case WINED3DFMT_B4G4R4A4_UNORM: return D3DFMT_A4R4G4B4;
54 case WINED3DFMT_B2G3R3_UNORM: return D3DFMT_R3G3B2;
55 case WINED3DFMT_A8_UNORM: return D3DFMT_A8;
56 case WINED3DFMT_B2G3R3A8_UNORM: return D3DFMT_A8R3G3B2;
57 case WINED3DFMT_B4G4R4X4_UNORM: return D3DFMT_X4R4G4B4;
58 case WINED3DFMT_R10G10B10A2_UNORM: return D3DFMT_A2B10G10R10;
59 case WINED3DFMT_R8G8B8A8_UNORM: return D3DFMT_A8B8G8R8;
60 case WINED3DFMT_R8G8B8X8_UNORM: return D3DFMT_X8B8G8R8;
61 case WINED3DFMT_R16G16_UNORM: return D3DFMT_G16R16;
62 case WINED3DFMT_B10G10R10A2_UNORM: return D3DFMT_A2R10G10B10;
63 case WINED3DFMT_R16G16B16A16_UNORM: return D3DFMT_A16B16G16R16;
64 case WINED3DFMT_P8_UINT_A8_UNORM: return D3DFMT_A8P8;
65 case WINED3DFMT_P8_UINT: return D3DFMT_P8;
66 case WINED3DFMT_L8_UNORM: return D3DFMT_L8;
67 case WINED3DFMT_L8A8_UNORM: return D3DFMT_A8L8;
68 case WINED3DFMT_L4A4_UNORM: return D3DFMT_A4L4;
69 case WINED3DFMT_R8G8_SNORM: return D3DFMT_V8U8;
70 case WINED3DFMT_R5G5_SNORM_L6_UNORM: return D3DFMT_L6V5U5;
71 case WINED3DFMT_R8G8_SNORM_L8X8_UNORM: return D3DFMT_X8L8V8U8;
72 case WINED3DFMT_R8G8B8A8_SNORM: return D3DFMT_Q8W8V8U8;
73 case WINED3DFMT_R16G16_SNORM: return D3DFMT_V16U16;
74 case WINED3DFMT_R10G10B10_SNORM_A2_UNORM: return D3DFMT_A2W10V10U10;
75 case WINED3DFMT_D16_LOCKABLE: return D3DFMT_D16_LOCKABLE;
76 case WINED3DFMT_D32_UNORM: return D3DFMT_D32;
77 case WINED3DFMT_S1_UINT_D15_UNORM: return D3DFMT_D15S1;
78 case WINED3DFMT_D24_UNORM_S8_UINT: return D3DFMT_D24S8;
79 case WINED3DFMT_X8D24_UNORM: return D3DFMT_D24X8;
80 case WINED3DFMT_S4X4_UINT_D24_UNORM: return D3DFMT_D24X4S4;
81 case WINED3DFMT_D16_UNORM: return D3DFMT_D16;
82 case WINED3DFMT_L16_UNORM: return D3DFMT_L16;
83 case WINED3DFMT_D32_FLOAT: return D3DFMT_D32F_LOCKABLE;
84 case WINED3DFMT_S8_UINT_D24_FLOAT: return D3DFMT_D24FS8;
85 case WINED3DFMT_VERTEXDATA: return D3DFMT_VERTEXDATA;
86 case WINED3DFMT_R16_UINT: return D3DFMT_INDEX16;
87 case WINED3DFMT_R32_UINT: return D3DFMT_INDEX32;
88 case WINED3DFMT_R16G16B16A16_SNORM: return D3DFMT_Q16W16V16U16;
89 case WINED3DFMT_R16_FLOAT: return D3DFMT_R16F;
90 case WINED3DFMT_R16G16_FLOAT: return D3DFMT_G16R16F;
91 case WINED3DFMT_R16G16B16A16_FLOAT: return D3DFMT_A16B16G16R16F;
92 case WINED3DFMT_R32_FLOAT: return D3DFMT_R32F;
93 case WINED3DFMT_R32G32_FLOAT: return D3DFMT_G32R32F;
94 case WINED3DFMT_R32G32B32A32_FLOAT: return D3DFMT_A32B32G32R32F;
95 case WINED3DFMT_R8G8_SNORM_Cx: return D3DFMT_CxV8U8;
96 default:
97 FIXME("Unhandled WINED3DFORMAT %#x\n", format);
98 return D3DFMT_UNKNOWN;
99 }
100}
101
102WINED3DFORMAT wined3dformat_from_d3dformat(D3DFORMAT format)
103{
104 BYTE *c = (BYTE *)&format;
105
106 /* Don't translate FOURCC formats */
107 if (isprint(c[0]) && isprint(c[1]) && isprint(c[2]) && isprint(c[3])) return format;
108
109 switch(format)
110 {
111 case D3DFMT_UNKNOWN: return WINED3DFMT_UNKNOWN;
112 case D3DFMT_R8G8B8: return WINED3DFMT_B8G8R8_UNORM;
113 case D3DFMT_A8R8G8B8: return WINED3DFMT_B8G8R8A8_UNORM;
114 case D3DFMT_X8R8G8B8: return WINED3DFMT_B8G8R8X8_UNORM;
115 case D3DFMT_R5G6B5: return WINED3DFMT_B5G6R5_UNORM;
116 case D3DFMT_X1R5G5B5: return WINED3DFMT_B5G5R5X1_UNORM;
117 case D3DFMT_A1R5G5B5: return WINED3DFMT_B5G5R5A1_UNORM;
118 case D3DFMT_A4R4G4B4: return WINED3DFMT_B4G4R4A4_UNORM;
119 case D3DFMT_R3G3B2: return WINED3DFMT_B2G3R3_UNORM;
120 case D3DFMT_A8: return WINED3DFMT_A8_UNORM;
121 case D3DFMT_A8R3G3B2: return WINED3DFMT_B2G3R3A8_UNORM;
122 case D3DFMT_X4R4G4B4: return WINED3DFMT_B4G4R4X4_UNORM;
123 case D3DFMT_A2B10G10R10: return WINED3DFMT_R10G10B10A2_UNORM;
124 case D3DFMT_A8B8G8R8: return WINED3DFMT_R8G8B8A8_UNORM;
125 case D3DFMT_X8B8G8R8: return WINED3DFMT_R8G8B8X8_UNORM;
126 case D3DFMT_G16R16: return WINED3DFMT_R16G16_UNORM;
127 case D3DFMT_A2R10G10B10: return WINED3DFMT_B10G10R10A2_UNORM;
128 case D3DFMT_A16B16G16R16: return WINED3DFMT_R16G16B16A16_UNORM;
129 case D3DFMT_A8P8: return WINED3DFMT_P8_UINT_A8_UNORM;
130 case D3DFMT_P8: return WINED3DFMT_P8_UINT;
131 case D3DFMT_L8: return WINED3DFMT_L8_UNORM;
132 case D3DFMT_A8L8: return WINED3DFMT_L8A8_UNORM;
133 case D3DFMT_A4L4: return WINED3DFMT_L4A4_UNORM;
134 case D3DFMT_V8U8: return WINED3DFMT_R8G8_SNORM;
135 case D3DFMT_L6V5U5: return WINED3DFMT_R5G5_SNORM_L6_UNORM;
136 case D3DFMT_X8L8V8U8: return WINED3DFMT_R8G8_SNORM_L8X8_UNORM;
137 case D3DFMT_Q8W8V8U8: return WINED3DFMT_R8G8B8A8_SNORM;
138 case D3DFMT_V16U16: return WINED3DFMT_R16G16_SNORM;
139 case D3DFMT_A2W10V10U10: return WINED3DFMT_R10G10B10_SNORM_A2_UNORM;
140 case D3DFMT_D16_LOCKABLE: return WINED3DFMT_D16_LOCKABLE;
141 case D3DFMT_D32: return WINED3DFMT_D32_UNORM;
142 case D3DFMT_D15S1: return WINED3DFMT_S1_UINT_D15_UNORM;
143 case D3DFMT_D24S8: return WINED3DFMT_D24_UNORM_S8_UINT;
144 case D3DFMT_D24X8: return WINED3DFMT_X8D24_UNORM;
145 case D3DFMT_D24X4S4: return WINED3DFMT_S4X4_UINT_D24_UNORM;
146 case D3DFMT_D16: return WINED3DFMT_D16_UNORM;
147 case D3DFMT_L16: return WINED3DFMT_L16_UNORM;
148 case D3DFMT_D32F_LOCKABLE: return WINED3DFMT_D32_FLOAT;
149 case D3DFMT_D24FS8: return WINED3DFMT_S8_UINT_D24_FLOAT;
150 case D3DFMT_VERTEXDATA: return WINED3DFMT_VERTEXDATA;
151 case D3DFMT_INDEX16: return WINED3DFMT_R16_UINT;
152 case D3DFMT_INDEX32: return WINED3DFMT_R32_UINT;
153 case D3DFMT_Q16W16V16U16: return WINED3DFMT_R16G16B16A16_SNORM;
154 case D3DFMT_R16F: return WINED3DFMT_R16_FLOAT;
155 case D3DFMT_G16R16F: return WINED3DFMT_R16G16_FLOAT;
156 case D3DFMT_A16B16G16R16F: return WINED3DFMT_R16G16B16A16_FLOAT;
157 case D3DFMT_R32F: return WINED3DFMT_R32_FLOAT;
158 case D3DFMT_G32R32F: return WINED3DFMT_R32G32_FLOAT;
159 case D3DFMT_A32B32G32R32F: return WINED3DFMT_R32G32B32A32_FLOAT;
160 case D3DFMT_CxV8U8: return WINED3DFMT_R8G8_SNORM_Cx;
161 default:
162 FIXME("Unhandled D3DFORMAT %#x\n", format);
163 return WINED3DFMT_UNKNOWN;
164 }
165}
166
167static UINT vertex_count_from_primitive_count(D3DPRIMITIVETYPE primitive_type, UINT primitive_count)
168{
169 switch(primitive_type)
170 {
171 case D3DPT_POINTLIST:
172 return primitive_count;
173
174 case D3DPT_LINELIST:
175 return primitive_count * 2;
176
177 case D3DPT_LINESTRIP:
178 return primitive_count + 1;
179
180 case D3DPT_TRIANGLELIST:
181 return primitive_count * 3;
182
183 case D3DPT_TRIANGLESTRIP:
184 case D3DPT_TRIANGLEFAN:
185 return primitive_count + 2;
186
187 default:
188 FIXME("Unhandled primitive type %#x\n", primitive_type);
189 return 0;
190 }
191}
192
193static ULONG WINAPI D3D9CB_DestroySwapChain(IWineD3DSwapChain *swapchain)
194{
195 IDirect3DSwapChain9Impl *parent;
196
197 TRACE("swapchain %p.\n", swapchain);
198
199 IWineD3DSwapChain_GetParent(swapchain, (IUnknown **)&parent);
200 parent->isImplicit = FALSE;
201 return IDirect3DSwapChain9_Release((IDirect3DSwapChain9 *)parent);
202}
203
204/* IDirect3D IUnknown parts follow: */
205static HRESULT WINAPI IDirect3DDevice9Impl_QueryInterface(LPDIRECT3DDEVICE9EX iface, REFIID riid, LPVOID* ppobj) {
206 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
207 IDirect3D9 *d3d;
208 IDirect3D9Impl *d3dimpl;
209
210 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
211
212 if (IsEqualGUID(riid, &IID_IUnknown)
213 || IsEqualGUID(riid, &IID_IDirect3DDevice9)) {
214 IDirect3DDevice9Ex_AddRef(iface);
215 *ppobj = This;
216 TRACE("Returning IDirect3DDevice9 interface at %p\n", *ppobj);
217 return S_OK;
218 } else if(IsEqualGUID(riid, &IID_IDirect3DDevice9Ex)) {
219 /* Find out if the creating d3d9 interface was created with Direct3DCreate9Ex.
220 * It doesn't matter with which function the device was created.
221 */
222 IDirect3DDevice9_GetDirect3D(iface, &d3d);
223 d3dimpl = (IDirect3D9Impl *) d3d;
224
225 if(d3dimpl->extended) {
226 *ppobj = iface;
227 IDirect3DDevice9Ex_AddRef((IDirect3DDevice9Ex *) *ppobj);
228 IDirect3D9_Release(d3d);
229 TRACE("Returning IDirect3DDevice9Ex interface at %p\n", *ppobj);
230 return S_OK;
231 } else {
232 WARN("IDirect3D9 instance wasn't created with CreateDirect3D9Ex, returning E_NOINTERFACE\n");
233 IDirect3D9_Release(d3d);
234 *ppobj = NULL;
235 return E_NOINTERFACE;
236 }
237 }
238
239 if (IsEqualGUID(riid, &IID_IWineD3DDeviceParent))
240 {
241 IUnknown_AddRef((IUnknown *)&This->device_parent_vtbl);
242 *ppobj = &This->device_parent_vtbl;
243 return S_OK;
244 }
245
246 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
247 *ppobj = NULL;
248 return E_NOINTERFACE;
249}
250
251static ULONG WINAPI IDirect3DDevice9Impl_AddRef(LPDIRECT3DDEVICE9EX iface) {
252 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
253 ULONG ref = InterlockedIncrement(&This->ref);
254
255 TRACE("%p increasing refcount to %u.\n", iface, ref);
256
257 return ref;
258}
259
260static ULONG WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_Release(LPDIRECT3DDEVICE9EX iface) {
261 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
262 ULONG ref;
263
264 if (This->inDestruction) return 0;
265 ref = InterlockedDecrement(&This->ref);
266
267 TRACE("%p decreasing refcount to %u.\n", iface, ref);
268
269 if (ref == 0) {
270 unsigned i;
271 This->inDestruction = TRUE;
272
273 wined3d_mutex_lock();
274 for(i = 0; i < This->numConvertedDecls; i++) {
275 /* Unless Wine is buggy or the app has a bug the refcount will be 0, because decls hold a reference to the
276 * device
277 */
278 IDirect3DVertexDeclaration9Impl_Destroy(This->convertedDecls[i]);
279 }
280 HeapFree(GetProcessHeap(), 0, This->convertedDecls);
281
282 IWineD3DDevice_Uninit3D(This->WineD3DDevice, D3D9CB_DestroySwapChain);
283 IWineD3DDevice_ReleaseFocusWindow(This->WineD3DDevice);
284 IWineD3DDevice_Release(This->WineD3DDevice);
285 wined3d_mutex_unlock();
286
287 HeapFree(GetProcessHeap(), 0, This);
288 }
289 return ref;
290}
291
292/* IDirect3DDevice Interface follow: */
293static HRESULT WINAPI IDirect3DDevice9Impl_TestCooperativeLevel(IDirect3DDevice9Ex *iface)
294{
295 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
296
297 TRACE("iface %p.\n", iface);
298
299 if (This->notreset)
300 {
301 TRACE("D3D9 device is marked not reset.\n");
302 return D3DERR_DEVICENOTRESET;
303 }
304
305 return D3D_OK;
306}
307
308static UINT WINAPI IDirect3DDevice9Impl_GetAvailableTextureMem(LPDIRECT3DDEVICE9EX iface) {
309 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
310 HRESULT hr;
311
312 TRACE("iface %p.\n", iface);
313
314 wined3d_mutex_lock();
315 hr = IWineD3DDevice_GetAvailableTextureMem(This->WineD3DDevice);
316 wined3d_mutex_unlock();
317
318 return hr;
319}
320
321static HRESULT WINAPI IDirect3DDevice9Impl_EvictManagedResources(LPDIRECT3DDEVICE9EX iface) {
322 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
323 HRESULT hr;
324
325 TRACE("iface %p.\n", iface);
326
327 wined3d_mutex_lock();
328 hr = IWineD3DDevice_EvictManagedResources(This->WineD3DDevice);
329 wined3d_mutex_unlock();
330
331 return hr;
332}
333
334static HRESULT WINAPI IDirect3DDevice9Impl_GetDirect3D(LPDIRECT3DDEVICE9EX iface, IDirect3D9** ppD3D9) {
335 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
336 HRESULT hr = D3D_OK;
337 IWineD3D* pWineD3D;
338
339 TRACE("iface %p, d3d9 %p.\n", iface, ppD3D9);
340
341 if (NULL == ppD3D9) {
342 return D3DERR_INVALIDCALL;
343 }
344
345 wined3d_mutex_lock();
346 hr = IWineD3DDevice_GetDirect3D(This->WineD3DDevice, &pWineD3D);
347 if (hr == D3D_OK && pWineD3D != NULL)
348 {
349 IWineD3D_GetParent(pWineD3D,(IUnknown **)ppD3D9);
350 IWineD3D_Release(pWineD3D);
351 } else {
352 FIXME("Call to IWineD3DDevice_GetDirect3D failed\n");
353 *ppD3D9 = NULL;
354 }
355 TRACE("(%p) returning %p\n", This, *ppD3D9);
356 wined3d_mutex_unlock();
357
358 return hr;
359}
360
361static HRESULT WINAPI IDirect3DDevice9Impl_GetDeviceCaps(LPDIRECT3DDEVICE9EX iface, D3DCAPS9* pCaps) {
362 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
363 HRESULT hrc = D3D_OK;
364 WINED3DCAPS *pWineCaps;
365
366 TRACE("iface %p, caps %p.\n", iface, pCaps);
367
368 if(NULL == pCaps){
369 return D3DERR_INVALIDCALL;
370 }
371 pWineCaps = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WINED3DCAPS));
372 if(pWineCaps == NULL){
373 return D3DERR_INVALIDCALL; /* well this is what MSDN says to return */
374 }
375
376 memset(pCaps, 0, sizeof(*pCaps));
377
378 wined3d_mutex_lock();
379 hrc = IWineD3DDevice_GetDeviceCaps(This->WineD3DDevice, pWineCaps);
380 wined3d_mutex_unlock();
381
382 WINECAPSTOD3D9CAPS(pCaps, pWineCaps)
383 HeapFree(GetProcessHeap(), 0, pWineCaps);
384
385 /* Some functionality is implemented in d3d9.dll, not wined3d.dll. Add the needed caps */
386 pCaps->DevCaps2 |= D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES;
387
388 filter_caps(pCaps);
389
390 TRACE("Returning %p %p\n", This, pCaps);
391 return hrc;
392}
393
394static HRESULT WINAPI IDirect3DDevice9Impl_GetDisplayMode(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain, D3DDISPLAYMODE* pMode) {
395 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
396 HRESULT hr;
397
398 TRACE("iface %p, swapchain %u, mode %p.\n", iface, iSwapChain, pMode);
399
400 wined3d_mutex_lock();
401 hr = IWineD3DDevice_GetDisplayMode(This->WineD3DDevice, iSwapChain, (WINED3DDISPLAYMODE *) pMode);
402 wined3d_mutex_unlock();
403
404 if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format);
405
406 return hr;
407}
408
409static HRESULT WINAPI IDirect3DDevice9Impl_GetCreationParameters(LPDIRECT3DDEVICE9EX iface, D3DDEVICE_CREATION_PARAMETERS *pParameters) {
410 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
411 HRESULT hr;
412
413 TRACE("iface %p, parameters %p.\n", iface, pParameters);
414
415 wined3d_mutex_lock();
416 hr = IWineD3DDevice_GetCreationParameters(This->WineD3DDevice, (WINED3DDEVICE_CREATION_PARAMETERS *) pParameters);
417 wined3d_mutex_unlock();
418
419 return hr;
420}
421
422static HRESULT WINAPI IDirect3DDevice9Impl_SetCursorProperties(LPDIRECT3DDEVICE9EX iface, UINT XHotSpot, UINT YHotSpot, IDirect3DSurface9* pCursorBitmap) {
423 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
424 IDirect3DSurface9Impl *pSurface = (IDirect3DSurface9Impl*)pCursorBitmap;
425 HRESULT hr;
426
427 TRACE("iface %p, hotspot_x %u, hotspot_y %u, bitmap %p.\n",
428 iface, XHotSpot, YHotSpot, pCursorBitmap);
429
430 if(!pCursorBitmap) {
431 WARN("No cursor bitmap, returning WINED3DERR_INVALIDCALL\n");
432 return WINED3DERR_INVALIDCALL;
433 }
434
435 wined3d_mutex_lock();
436 hr = IWineD3DDevice_SetCursorProperties(This->WineD3DDevice, XHotSpot, YHotSpot, pSurface->wineD3DSurface);
437 wined3d_mutex_unlock();
438
439 return hr;
440}
441
442static void WINAPI IDirect3DDevice9Impl_SetCursorPosition(LPDIRECT3DDEVICE9EX iface, int XScreenSpace, int YScreenSpace, DWORD Flags) {
443 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
444
445 TRACE("iface %p, x %u, y %u, flags %#x.\n", iface, XScreenSpace, YScreenSpace, Flags);
446
447 wined3d_mutex_lock();
448 IWineD3DDevice_SetCursorPosition(This->WineD3DDevice, XScreenSpace, YScreenSpace, Flags);
449 wined3d_mutex_unlock();
450}
451
452static BOOL WINAPI IDirect3DDevice9Impl_ShowCursor(LPDIRECT3DDEVICE9EX iface, BOOL bShow) {
453 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
454 BOOL ret;
455
456 TRACE("iface %p, show %#x.\n", iface, bShow);
457
458 wined3d_mutex_lock();
459 ret = IWineD3DDevice_ShowCursor(This->WineD3DDevice, bShow);
460 wined3d_mutex_unlock();
461
462 return ret;
463}
464#ifdef VBOX_WITH_WDDM
465static HRESULT IDirect3DDevice9Impl_DoCreateAdditionalSwapChain(IDirect3DDevice9Ex *iface,
466 D3DPRESENT_PARAMETERS *present_parameters, IDirect3DSwapChain9 **swapchain)
467#else
468static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_CreateAdditionalSwapChain(IDirect3DDevice9Ex *iface,
469 D3DPRESENT_PARAMETERS *present_parameters, IDirect3DSwapChain9 **swapchain)
470#endif
471{
472 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
473 IDirect3DSwapChain9Impl *object;
474 HRESULT hr;
475
476 TRACE("iface %p, present_parameters %p, swapchain %p.\n",
477 iface, present_parameters, swapchain);
478
479 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
480 if (!object)
481 {
482 ERR("Failed to allocate swapchain memory.\n");
483 return E_OUTOFMEMORY;
484 }
485
486 hr = swapchain_init(object, This, present_parameters);
487 if (FAILED(hr))
488 {
489 WARN("Failed to initialize swapchain, hr %#x.\n", hr);
490 HeapFree(GetProcessHeap(), 0, object);
491 return hr;
492 }
493
494 TRACE("Created swapchain %p.\n", object);
495 *swapchain = (IDirect3DSwapChain9 *)object;
496
497 return D3D_OK;
498}
499
500#ifdef VBOX_WITH_WDDM
501static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_CreateAdditionalSwapChain(IDirect3DDevice9Ex *iface,
502 D3DPRESENT_PARAMETERS *present_parameters, IDirect3DSwapChain9 **swapchain)
503{
504 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
505 IDirect3DSwapChain9Impl *newSwapchain;
506 HRESULT hr = IDirect3DDevice9Impl_DoCreateAdditionalSwapChain(iface, present_parameters, &newSwapchain);
507 if (FAILED(hr))
508 {
509 ERR("Failed to create additional swapchain, hr %#x.\n", hr);
510 return hr;
511 }
512
513 /* add swapchain to the swapchain list */
514 wined3d_mutex_lock();
515 hr = IWineD3DDevice_AddSwapChain(This->WineD3DDevice, newSwapchain->wineD3DSwapChain);
516 wined3d_mutex_unlock();
517 if (FAILED(hr))
518 {
519 ERR("Failed to add additional swapchain, hr %#x.\n", hr);
520 IUnknown_Release(newSwapchain);
521 return hr;
522 }
523
524 *swapchain = (IDirect3DSwapChain9 *)newSwapchain;
525 return D3D_OK;
526}
527#endif
528
529static HRESULT WINAPI reset_enum_callback(IWineD3DResource *resource, void *data) {
530 BOOL *resources_ok = data;
531 D3DRESOURCETYPE type;
532 HRESULT ret = S_OK;
533 WINED3DSURFACE_DESC surface_desc;
534 WINED3DVOLUME_DESC volume_desc;
535 D3DINDEXBUFFER_DESC index_desc;
536 D3DVERTEXBUFFER_DESC vertex_desc;
537 WINED3DPOOL pool;
538 IDirect3DResource9 *parent;
539
540 IWineD3DResource_GetParent(resource, (IUnknown **) &parent);
541 type = IDirect3DResource9_GetType(parent);
542 switch(type) {
543 case D3DRTYPE_SURFACE:
544 IWineD3DSurface_GetDesc((IWineD3DSurface *) resource, &surface_desc);
545 pool = surface_desc.pool;
546 break;
547
548 case D3DRTYPE_VOLUME:
549 IWineD3DVolume_GetDesc((IWineD3DVolume *) resource, &volume_desc);
550 pool = volume_desc.Pool;
551 break;
552
553 case D3DRTYPE_INDEXBUFFER:
554 IDirect3DIndexBuffer9_GetDesc((IDirect3DIndexBuffer9 *) parent, &index_desc);
555 pool = index_desc.Pool;
556 break;
557
558 case D3DRTYPE_VERTEXBUFFER:
559 IDirect3DVertexBuffer9_GetDesc((IDirect3DVertexBuffer9 *)parent, &vertex_desc);
560 pool = vertex_desc.Pool;
561 break;
562
563 /* No need to check for textures. If there is a D3DPOOL_DEFAULT texture, there
564 * is a D3DPOOL_DEFAULT surface or volume as well
565 */
566 default:
567 pool = WINED3DPOOL_SCRATCH; /* a harmless pool */
568 break;
569 }
570
571 if(pool == WINED3DPOOL_DEFAULT) {
572 if(IUnknown_Release(parent) == 0) {
573 TRACE("Parent %p is an implicit resource with ref 0\n", parent);
574 } else {
575 WARN("Resource %p(wineD3D %p) with pool D3DPOOL_DEFAULT blocks the Reset call\n", parent, resource);
576 ret = S_FALSE;
577 *resources_ok = FALSE;
578 }
579 } else {
580 IUnknown_Release(parent);
581 }
582 IWineD3DResource_Release(resource);
583
584 return ret;
585}
586
587static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_Reset(LPDIRECT3DDEVICE9EX iface, D3DPRESENT_PARAMETERS* pPresentationParameters) {
588 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
589 WINED3DPRESENT_PARAMETERS localParameters;
590 HRESULT hr;
591 BOOL resources_ok = TRUE;
592 UINT i;
593
594 TRACE("iface %p, present_parameters %p.\n", iface, pPresentationParameters);
595
596 /* Reset states that hold a COM object. WineD3D holds an internal reference to set objects, because
597 * such objects can still be used for rendering after their external d3d9 object has been destroyed.
598 * These objects must not be enumerated. Unsetting them tells WineD3D that the application will not
599 * make use of the hidden reference and destroys the objects.
600 *
601 * Unsetting them is no problem, because the states are supposed to be reset anyway. If the validation
602 * below fails, the device is considered "lost", and _Reset and _Release are the only allowed calls
603 */
604 wined3d_mutex_lock();
605 IWineD3DDevice_SetIndexBuffer(This->WineD3DDevice, NULL, WINED3DFMT_UNKNOWN);
606 for(i = 0; i < 16; i++) {
607 IWineD3DDevice_SetStreamSource(This->WineD3DDevice, i, NULL, 0, 0);
608 }
609 for(i = 0; i < 16; i++) {
610 IWineD3DDevice_SetTexture(This->WineD3DDevice, i, NULL);
611 }
612
613 IWineD3DDevice_EnumResources(This->WineD3DDevice, reset_enum_callback, &resources_ok);
614 if(!resources_ok) {
615 WARN("The application is holding D3DPOOL_DEFAULT resources, rejecting reset\n");
616 This->notreset = TRUE;
617 wined3d_mutex_unlock();
618
619 return WINED3DERR_INVALIDCALL;
620 }
621
622 localParameters.BackBufferWidth = pPresentationParameters->BackBufferWidth;
623 localParameters.BackBufferHeight = pPresentationParameters->BackBufferHeight;
624 localParameters.BackBufferFormat = wined3dformat_from_d3dformat(pPresentationParameters->BackBufferFormat);
625 localParameters.BackBufferCount = pPresentationParameters->BackBufferCount;
626 localParameters.MultiSampleType = pPresentationParameters->MultiSampleType;
627 localParameters.MultiSampleQuality = pPresentationParameters->MultiSampleQuality;
628 localParameters.SwapEffect = pPresentationParameters->SwapEffect;
629 localParameters.hDeviceWindow = pPresentationParameters->hDeviceWindow;
630 localParameters.Windowed = pPresentationParameters->Windowed;
631 localParameters.EnableAutoDepthStencil = pPresentationParameters->EnableAutoDepthStencil;
632 localParameters.AutoDepthStencilFormat = wined3dformat_from_d3dformat(pPresentationParameters->AutoDepthStencilFormat);
633 localParameters.Flags = pPresentationParameters->Flags;
634 localParameters.FullScreen_RefreshRateInHz = pPresentationParameters->FullScreen_RefreshRateInHz;
635 localParameters.PresentationInterval = pPresentationParameters->PresentationInterval;
636 localParameters.AutoRestoreDisplayMode = TRUE;
637
638 hr = IWineD3DDevice_Reset(This->WineD3DDevice, &localParameters);
639 if(FAILED(hr)) {
640 This->notreset = TRUE;
641
642 pPresentationParameters->BackBufferWidth = localParameters.BackBufferWidth;
643 pPresentationParameters->BackBufferHeight = localParameters.BackBufferHeight;
644 pPresentationParameters->BackBufferFormat = d3dformat_from_wined3dformat(localParameters.BackBufferFormat);
645 pPresentationParameters->BackBufferCount = localParameters.BackBufferCount;
646 pPresentationParameters->MultiSampleType = localParameters.MultiSampleType;
647 pPresentationParameters->MultiSampleQuality = localParameters.MultiSampleQuality;
648 pPresentationParameters->SwapEffect = localParameters.SwapEffect;
649 pPresentationParameters->hDeviceWindow = localParameters.hDeviceWindow;
650 pPresentationParameters->Windowed = localParameters.Windowed;
651 pPresentationParameters->EnableAutoDepthStencil = localParameters.EnableAutoDepthStencil;
652 pPresentationParameters->AutoDepthStencilFormat = d3dformat_from_wined3dformat(localParameters.AutoDepthStencilFormat);
653 pPresentationParameters->Flags = localParameters.Flags;
654 pPresentationParameters->FullScreen_RefreshRateInHz = localParameters.FullScreen_RefreshRateInHz;
655 pPresentationParameters->PresentationInterval = localParameters.PresentationInterval;
656 } else {
657 This->notreset = FALSE;
658 }
659
660 wined3d_mutex_unlock();
661
662 return hr;
663}
664
665static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_Present(LPDIRECT3DDEVICE9EX iface, CONST RECT* pSourceRect,CONST RECT* pDestRect,HWND hDestWindowOverride,CONST RGNDATA*
666 pDirtyRegion) {
667 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
668 HRESULT hr;
669
670 TRACE("iface %p, src_rect %p, dst_rect %p, dst_window_override %p, dirty_region %p.\n",
671 iface, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
672
673 wined3d_mutex_lock();
674 hr = IWineD3DDevice_Present(This->WineD3DDevice, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
675 wined3d_mutex_unlock();
676
677 return hr;
678 }
679
680static HRESULT WINAPI IDirect3DDevice9Impl_GetBackBuffer(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain, UINT BackBuffer, D3DBACKBUFFER_TYPE Type, IDirect3DSurface9 ** ppBackBuffer) {
681 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
682 IWineD3DSurface *retSurface = NULL;
683 HRESULT rc = D3D_OK;
684
685 TRACE("iface %p, swapchain %u, backbuffer_idx %u, backbuffer_type %#x, backbuffer %p.\n",
686 iface, iSwapChain, BackBuffer, Type, ppBackBuffer);
687
688 wined3d_mutex_lock();
689 rc = IWineD3DDevice_GetBackBuffer(This->WineD3DDevice, iSwapChain, BackBuffer, (WINED3DBACKBUFFER_TYPE) Type, &retSurface);
690 if (rc == D3D_OK && NULL != retSurface && NULL != ppBackBuffer) {
691 IWineD3DSurface_GetParent(retSurface, (IUnknown **)ppBackBuffer);
692 IWineD3DSurface_Release(retSurface);
693 }
694 wined3d_mutex_unlock();
695
696 return rc;
697}
698static HRESULT WINAPI IDirect3DDevice9Impl_GetRasterStatus(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain, D3DRASTER_STATUS* pRasterStatus) {
699 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
700 HRESULT hr;
701
702 TRACE("iface %p, swapchain %u, raster_status %p.\n", iface, iSwapChain, pRasterStatus);
703
704 wined3d_mutex_lock();
705 hr = IWineD3DDevice_GetRasterStatus(This->WineD3DDevice, iSwapChain, (WINED3DRASTER_STATUS *) pRasterStatus);
706 wined3d_mutex_unlock();
707
708 return hr;
709}
710
711static HRESULT WINAPI IDirect3DDevice9Impl_SetDialogBoxMode(LPDIRECT3DDEVICE9EX iface, BOOL bEnableDialogs) {
712 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
713 HRESULT hr;
714
715 TRACE("iface %p, enable %#x.\n", iface, bEnableDialogs);
716
717 wined3d_mutex_lock();
718 hr = IWineD3DDevice_SetDialogBoxMode(This->WineD3DDevice, bEnableDialogs);
719 wined3d_mutex_unlock();
720
721 return hr;
722}
723
724static void WINAPI IDirect3DDevice9Impl_SetGammaRamp(IDirect3DDevice9Ex *iface, UINT iSwapChain,
725 DWORD Flags, const D3DGAMMARAMP *pRamp)
726{
727 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
728
729 TRACE("iface %p, swapchain %u, flags %#x, ramp %p.\n", iface, iSwapChain, Flags, pRamp);
730
731 /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
732 wined3d_mutex_lock();
733 IWineD3DDevice_SetGammaRamp(This->WineD3DDevice, iSwapChain, Flags, (CONST WINED3DGAMMARAMP *)pRamp);
734 wined3d_mutex_unlock();
735}
736
737static void WINAPI IDirect3DDevice9Impl_GetGammaRamp(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain, D3DGAMMARAMP* pRamp) {
738 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
739
740 TRACE("iface %p, swapchain %u, ramp %p.\n", iface, iSwapChain, pRamp);
741
742 /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
743 wined3d_mutex_lock();
744 IWineD3DDevice_GetGammaRamp(This->WineD3DDevice, iSwapChain, (WINED3DGAMMARAMP *) pRamp);
745 wined3d_mutex_unlock();
746}
747
748#ifdef VBOX_WITH_WDDM
749//#pragma comment(linker, "/export:VBoxWineExD3DDev9Flush=_VBoxWineExD3DDev9Flush@4")
750
751VBOXWINEEX_DECL(HRESULT) VBoxWineExD3DDev9Flush(IDirect3DDevice9Ex *iface)
752{
753 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
754 HRESULT hr;
755
756 TRACE("iface %p, Flush\n", iface);
757
758 wined3d_mutex_lock();
759 hr = IWineD3DDevice_Flush(This->WineD3DDevice);
760 wined3d_mutex_unlock();
761
762 return hr;
763}
764
765//#pragma comment(linker, "/export:VBoxWineExD3DDev9CreateTexture=_VBoxWineExD3DDev9CreateTexture@40")
766
767VBOXWINEEX_DECL(HRESULT) VBoxWineExD3DDev9CreateTexture(IDirect3DDevice9Ex *iface,
768 UINT width, UINT height, UINT levels, DWORD usage, D3DFORMAT format,
769 D3DPOOL pool, IDirect3DTexture9 **texture, HANDLE *shared_handle,
770 void **pavClientMem) /* <- extension arg to pass in the client memory buffer,
771 * applicable ONLY for SYSMEM textures */
772{
773 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
774 IDirect3DTexture9Impl *object;
775 HRESULT hr;
776
777 TRACE("iface %p, width %u, height %u, levels %u, usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n",
778 iface, width, height, levels, usage, format, pool, texture, shared_handle);
779
780 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
781 if (!object)
782 {
783 ERR("Failed to allocate texture memory.\n");
784 return D3DERR_OUTOFVIDEOMEMORY;
785 }
786
787 hr = texture_init(object, This, width, height, levels, usage, format, pool
788 , shared_handle
789 , pavClientMem
790 );
791 if (FAILED(hr))
792 {
793 WARN("Failed to initialize texture, hr %#x.\n", hr);
794 HeapFree(GetProcessHeap(), 0, object);
795 return hr;
796 }
797
798 TRACE("Created texture %p.\n", object);
799 *texture = (IDirect3DTexture9 *)object;
800
801 return D3D_OK;
802}
803
804VBOXWINEEX_DECL(HRESULT) VBoxWineExD3DDev9Update(IDirect3DDevice9Ex *iface, D3DPRESENT_PARAMETERS * pParams, IDirect3DDevice9Ex **outIface)
805{
806 IDirect3DDevice9_AddRef(iface);
807 *outIface = iface;
808 return D3D_OK;
809}
810
811VBOXWINEEX_DECL(HRESULT) VBoxWineExD3DDev9CreateCubeTexture(IDirect3DDevice9Ex *iface,
812 UINT edge_length, UINT levels, DWORD usage, D3DFORMAT format,
813 D3DPOOL pool, IDirect3DCubeTexture9 **texture, HANDLE *shared_handle,
814 void **pavClientMem) /* <- extension arg to pass in the client memory buffer,
815 * applicable ONLY for SYSMEM textures */
816{
817 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
818 IDirect3DCubeTexture9Impl *object;
819 HRESULT hr;
820
821 TRACE("iface %p, edge_length %u, levels %u, usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n",
822 iface, edge_length, levels, usage, format, pool, texture, shared_handle);
823
824 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
825 if (!object)
826 {
827 ERR("Failed to allocate cube texture memory.\n");
828 return D3DERR_OUTOFVIDEOMEMORY;
829 }
830
831 hr = cubetexture_init(object, This, edge_length, levels, usage, format, pool, shared_handle, pavClientMem);
832 if (FAILED(hr))
833 {
834 WARN("Failed to initialize cube texture, hr %#x.\n", hr);
835 HeapFree(GetProcessHeap(), 0, object);
836 return hr;
837 }
838
839 TRACE("Created cube texture %p.\n", object);
840 *texture = (IDirect3DCubeTexture9 *)object;
841
842 return D3D_OK;
843}
844
845#endif
846
847static HRESULT WINAPI IDirect3DDevice9Impl_CreateTexture(IDirect3DDevice9Ex *iface,
848 UINT width, UINT height, UINT levels, DWORD usage, D3DFORMAT format,
849 D3DPOOL pool, IDirect3DTexture9 **texture, HANDLE *shared_handle)
850{
851#ifdef VBOX_WITH_WDDM
852 return VBoxWineExD3DDev9CreateTexture(iface, width, height, levels, usage, format,
853 pool, texture, shared_handle, NULL);
854#else
855 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
856 IDirect3DTexture9Impl *object;
857 HRESULT hr;
858
859 TRACE("iface %p, width %u, height %u, levels %u, usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n",
860 iface, width, height, levels, usage, format, pool, texture, shared_handle);
861
862 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
863 if (!object)
864 {
865 ERR("Failed to allocate texture memory.\n");
866 return D3DERR_OUTOFVIDEOMEMORY;
867 }
868
869 hr = texture_init(object, This, width, height, levels, usage, format, pool);
870 if (FAILED(hr))
871 {
872 WARN("Failed to initialize texture, hr %#x.\n", hr);
873 HeapFree(GetProcessHeap(), 0, object);
874 return hr;
875 }
876
877 TRACE("Created texture %p.\n", object);
878 *texture = (IDirect3DTexture9 *)object;
879
880 return D3D_OK;
881#endif
882}
883
884static HRESULT WINAPI IDirect3DDevice9Impl_CreateVolumeTexture(IDirect3DDevice9Ex *iface,
885 UINT width, UINT height, UINT depth, UINT levels, DWORD usage, D3DFORMAT format,
886 D3DPOOL pool, IDirect3DVolumeTexture9 **texture, HANDLE *shared_handle)
887{
888 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
889 IDirect3DVolumeTexture9Impl *object;
890 HRESULT hr;
891
892 TRACE("iface %p, width %u, height %u, depth %u, levels %u\n",
893 iface, width, height, depth, levels);
894 TRACE("usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n",
895 usage, format, pool, texture, shared_handle);
896
897 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
898 if (!object)
899 {
900 ERR("Failed to allocate volume texture memory.\n");
901 return D3DERR_OUTOFVIDEOMEMORY;
902 }
903
904 hr = volumetexture_init(object, This, width, height, depth, levels, usage, format, pool);
905 if (FAILED(hr))
906 {
907 WARN("Failed to initialize volume texture, hr %#x.\n", hr);
908 HeapFree(GetProcessHeap(), 0, object);
909 return hr;
910 }
911
912 TRACE("Created volume texture %p.\n", object);
913 *texture = (IDirect3DVolumeTexture9 *)object;
914
915 return D3D_OK;
916}
917
918static HRESULT WINAPI IDirect3DDevice9Impl_CreateCubeTexture(IDirect3DDevice9Ex *iface,
919 UINT edge_length, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool,
920 IDirect3DCubeTexture9 **texture, HANDLE *shared_handle)
921{
922#ifdef VBOX_WITH_WDDM
923 return VBoxWineExD3DDev9CreateCubeTexture(iface, edge_length, levels, usage, format,
924 pool, texture, shared_handle, NULL);
925#else
926 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
927 IDirect3DCubeTexture9Impl *object;
928 HRESULT hr;
929
930 TRACE("iface %p, edge_length %u, levels %u, usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n",
931 iface, edge_length, levels, usage, format, pool, texture, shared_handle);
932
933 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
934 if (!object)
935 {
936 ERR("Failed to allocate cube texture memory.\n");
937 return D3DERR_OUTOFVIDEOMEMORY;
938 }
939
940 hr = cubetexture_init(object, This, edge_length, levels, usage, format, pool);
941 if (FAILED(hr))
942 {
943 WARN("Failed to initialize cube texture, hr %#x.\n", hr);
944 HeapFree(GetProcessHeap(), 0, object);
945 return hr;
946 }
947
948 TRACE("Created cube texture %p.\n", object);
949 *texture = (IDirect3DCubeTexture9 *)object;
950
951 return D3D_OK;
952#endif
953}
954
955static HRESULT WINAPI IDirect3DDevice9Impl_CreateVertexBuffer(IDirect3DDevice9Ex *iface, UINT size, DWORD usage,
956 DWORD fvf, D3DPOOL pool, IDirect3DVertexBuffer9 **buffer, HANDLE *shared_handle)
957{
958 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
959 IDirect3DVertexBuffer9Impl *object;
960 HRESULT hr;
961
962 TRACE("iface %p, size %u, usage %#x, fvf %#x, pool %#x, buffer %p, shared_handle %p.\n",
963 iface, size, usage, fvf, pool, buffer, shared_handle);
964
965 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
966 if (!object)
967 {
968 ERR("Failed to allocate buffer memory.\n");
969 return D3DERR_OUTOFVIDEOMEMORY;
970 }
971
972 hr = vertexbuffer_init(object, This, size, usage, fvf, pool);
973 if (FAILED(hr))
974 {
975 WARN("Failed to initialize vertex buffer, hr %#x.\n", hr);
976 HeapFree(GetProcessHeap(), 0, object);
977 return hr;
978 }
979
980 TRACE("Created vertex buffer %p.\n", object);
981 *buffer = (IDirect3DVertexBuffer9 *)object;
982
983 return D3D_OK;
984}
985
986static HRESULT WINAPI IDirect3DDevice9Impl_CreateIndexBuffer(IDirect3DDevice9Ex *iface, UINT size, DWORD usage,
987 D3DFORMAT format, D3DPOOL pool, IDirect3DIndexBuffer9 **buffer, HANDLE *shared_handle)
988{
989 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
990 IDirect3DIndexBuffer9Impl *object;
991 HRESULT hr;
992
993 TRACE("iface %p, size %u, usage %#x, format %#x, pool %#x, buffer %p, shared_handle %p.\n",
994 iface, size, usage, format, pool, buffer, shared_handle);
995
996 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
997 if (!object)
998 {
999 ERR("Failed to allocate buffer memory.\n");
1000 return D3DERR_OUTOFVIDEOMEMORY;
1001 }
1002
1003 hr = indexbuffer_init(object, This, size, usage, format, pool);
1004 if (FAILED(hr))
1005 {
1006 WARN("Failed to initialize index buffer, hr %#x.\n", hr);
1007 HeapFree(GetProcessHeap(), 0, object);
1008 return hr;
1009 }
1010
1011 TRACE("Created index buffer %p.\n", object);
1012 *buffer = (IDirect3DIndexBuffer9 *)object;
1013
1014 return D3D_OK;
1015}
1016
1017static HRESULT IDirect3DDevice9Impl_CreateSurface(LPDIRECT3DDEVICE9EX iface, UINT Width, UINT Height,
1018 D3DFORMAT Format, BOOL Lockable, BOOL Discard, UINT Level, IDirect3DSurface9 **ppSurface,
1019 UINT Usage, D3DPOOL Pool, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality
1020#ifdef VBOX_WITH_WDDM
1021 , HANDLE *shared_handle
1022 , void *pvClientMem
1023#endif
1024 )
1025{
1026 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1027 IDirect3DSurface9Impl *object;
1028 HRESULT hr;
1029
1030 TRACE("iface %p, width %u, height %u, format %#x, lockable %#x, discard %#x, level %u, surface %p.\n"
1031 "usage %#x, pool %#x, multisample_type %#x, multisample_quality %u.\n",
1032 iface, Width, Height, Format, Lockable, Discard, Level, ppSurface,
1033 Usage, Pool, MultiSample, MultisampleQuality);
1034
1035 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DSurface9Impl));
1036 if (!object)
1037 {
1038 FIXME("Failed to allocate surface memory.\n");
1039 return D3DERR_OUTOFVIDEOMEMORY;
1040 }
1041
1042 hr = surface_init(object, This, Width, Height, Format, Lockable, Discard,
1043 Level, Usage, Pool, MultiSample, MultisampleQuality
1044#ifdef VBOX_WITH_WDDM
1045 , shared_handle
1046 , pvClientMem
1047#endif
1048 );
1049 if (FAILED(hr))
1050 {
1051 WARN("Failed to initialize surface, hr %#x.\n", hr);
1052 HeapFree(GetProcessHeap(), 0, object);
1053 return hr;
1054 }
1055
1056 TRACE("Created surface %p.\n", object);
1057 *ppSurface = (IDirect3DSurface9 *)object;
1058
1059 return D3D_OK;
1060}
1061
1062static HRESULT WINAPI IDirect3DDevice9Impl_CreateRenderTarget(IDirect3DDevice9Ex *iface, UINT Width, UINT Height,
1063 D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality, BOOL Lockable,
1064 IDirect3DSurface9 **ppSurface, HANDLE *pSharedHandle)
1065{
1066 HRESULT hr;
1067
1068 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u.\n"
1069 "lockable %#x, surface %p, shared_handle %p.\n",
1070 iface, Width, Height, Format, MultiSample, MultisampleQuality,
1071 Lockable, ppSurface, pSharedHandle);
1072
1073 hr = IDirect3DDevice9Impl_CreateSurface(iface, Width, Height, Format, Lockable, FALSE /* Discard */,
1074 0 /* Level */, ppSurface, D3DUSAGE_RENDERTARGET, D3DPOOL_DEFAULT, MultiSample, MultisampleQuality
1075#ifdef VBOX_WITH_WDDM
1076 , pSharedHandle
1077 , NULL
1078#endif
1079 );
1080
1081 return hr;
1082}
1083
1084static HRESULT WINAPI IDirect3DDevice9Impl_CreateDepthStencilSurface(LPDIRECT3DDEVICE9EX iface, UINT Width, UINT Height,
1085 D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample,
1086 DWORD MultisampleQuality, BOOL Discard,
1087 IDirect3DSurface9 **ppSurface, HANDLE* pSharedHandle) {
1088 HRESULT hr;
1089
1090 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u.\n"
1091 "discard %#x, surface %p, shared_handle %p.\n",
1092 iface, Width, Height, Format, MultiSample, MultisampleQuality,
1093 Discard, ppSurface, pSharedHandle);
1094
1095 hr = IDirect3DDevice9Impl_CreateSurface(iface, Width, Height, Format, TRUE /* Lockable */, Discard,
1096 0 /* Level */, ppSurface, D3DUSAGE_DEPTHSTENCIL, D3DPOOL_DEFAULT, MultiSample, MultisampleQuality
1097#ifdef VBOX_WITH_WDDM
1098 , pSharedHandle
1099 , NULL
1100#endif
1101 );
1102
1103 return hr;
1104}
1105
1106
1107static HRESULT WINAPI IDirect3DDevice9Impl_UpdateSurface(LPDIRECT3DDEVICE9EX iface, IDirect3DSurface9* pSourceSurface, CONST RECT* pSourceRect, IDirect3DSurface9* pDestinationSurface, CONST POINT* pDestPoint) {
1108 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1109 HRESULT hr;
1110
1111 TRACE("iface %p, src_surface %p, src_rect %p, dst_surface %p, dst_point %p.\n",
1112 iface, pSourceSurface, pSourceRect, pDestinationSurface, pDestPoint);
1113
1114 wined3d_mutex_lock();
1115 hr = IWineD3DDevice_UpdateSurface(This->WineD3DDevice, ((IDirect3DSurface9Impl *)pSourceSurface)->wineD3DSurface, pSourceRect, ((IDirect3DSurface9Impl *)pDestinationSurface)->wineD3DSurface, pDestPoint);
1116 wined3d_mutex_unlock();
1117
1118 return hr;
1119}
1120
1121static HRESULT WINAPI IDirect3DDevice9Impl_UpdateTexture(LPDIRECT3DDEVICE9EX iface, IDirect3DBaseTexture9* pSourceTexture, IDirect3DBaseTexture9* pDestinationTexture) {
1122 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1123 HRESULT hr;
1124
1125 TRACE("iface %p, src_texture %p, dst_texture %p.\n", iface, pSourceTexture, pDestinationTexture);
1126
1127 wined3d_mutex_lock();
1128 hr = IWineD3DDevice_UpdateTexture(This->WineD3DDevice, ((IDirect3DBaseTexture9Impl *)pSourceTexture)->wineD3DBaseTexture, ((IDirect3DBaseTexture9Impl *)pDestinationTexture)->wineD3DBaseTexture);
1129 wined3d_mutex_unlock();
1130
1131 return hr;
1132}
1133
1134static HRESULT WINAPI IDirect3DDevice9Impl_GetRenderTargetData(IDirect3DDevice9Ex *iface,
1135 IDirect3DSurface9 *pRenderTarget, IDirect3DSurface9 *pDestSurface)
1136{
1137 IDirect3DSurface9Impl *renderTarget = (IDirect3DSurface9Impl *)pRenderTarget;
1138 IDirect3DSurface9Impl *destSurface = (IDirect3DSurface9Impl *)pDestSurface;
1139 HRESULT hr;
1140
1141 TRACE("iface %p, render_target %p, dst_surface %p.\n", iface, pRenderTarget, pDestSurface);
1142
1143 wined3d_mutex_lock();
1144 hr = IWineD3DSurface_BltFast(destSurface->wineD3DSurface, 0, 0, renderTarget->wineD3DSurface, NULL, WINEDDBLTFAST_NOCOLORKEY);
1145 wined3d_mutex_unlock();
1146
1147 return hr;
1148}
1149
1150static HRESULT WINAPI IDirect3DDevice9Impl_GetFrontBufferData(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain, IDirect3DSurface9* pDestSurface) {
1151 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1152 IDirect3DSurface9Impl *destSurface = (IDirect3DSurface9Impl *)pDestSurface;
1153 HRESULT hr;
1154
1155 TRACE("iface %p, swapchain %u, dst_surface %p.\n", iface, iSwapChain, pDestSurface);
1156
1157 wined3d_mutex_lock();
1158 hr = IWineD3DDevice_GetFrontBufferData(This->WineD3DDevice, iSwapChain, destSurface->wineD3DSurface);
1159 wined3d_mutex_unlock();
1160
1161 return hr;
1162}
1163
1164static HRESULT WINAPI IDirect3DDevice9Impl_StretchRect(IDirect3DDevice9Ex *iface, IDirect3DSurface9 *pSourceSurface,
1165 const RECT *pSourceRect, IDirect3DSurface9 *pDestSurface, const RECT *pDestRect, D3DTEXTUREFILTERTYPE Filter)
1166{
1167 IDirect3DSurface9Impl *src = (IDirect3DSurface9Impl *) pSourceSurface;
1168 IDirect3DSurface9Impl *dst = (IDirect3DSurface9Impl *) pDestSurface;
1169 HRESULT hr;
1170
1171 TRACE("iface %p, src_surface %p, src_rect %p, dst_surface %p, dst_rect %p, filter %#x.\n",
1172 iface, pSourceSurface, pSourceRect, pDestSurface, pDestRect, Filter);
1173
1174 wined3d_mutex_lock();
1175 hr = IWineD3DSurface_Blt(dst->wineD3DSurface, pDestRect, src->wineD3DSurface, pSourceRect, 0, NULL, Filter);
1176 wined3d_mutex_unlock();
1177
1178 return hr;
1179}
1180
1181static HRESULT WINAPI IDirect3DDevice9Impl_ColorFill(LPDIRECT3DDEVICE9EX iface, IDirect3DSurface9* pSurface, CONST RECT* pRect, D3DCOLOR color) {
1182 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1183 IDirect3DSurface9Impl *surface = (IDirect3DSurface9Impl *)pSurface;
1184 WINED3DPOOL pool;
1185 WINED3DRESOURCETYPE restype;
1186 DWORD usage;
1187 WINED3DSURFACE_DESC desc;
1188 HRESULT hr;
1189
1190 TRACE("iface %p, surface %p, rect %p, color 0x%08x.\n", iface, pSurface, pRect, color);
1191
1192 wined3d_mutex_lock();
1193
1194 IWineD3DSurface_GetDesc(surface->wineD3DSurface, &desc);
1195 usage = desc.usage;
1196 pool = desc.pool;
1197 restype = desc.resource_type;
1198
1199 /* This method is only allowed with surfaces that are render targets, or offscreen plain surfaces
1200 * in D3DPOOL_DEFAULT
1201 */
1202 if(!(usage & WINED3DUSAGE_RENDERTARGET) && (pool != WINED3DPOOL_DEFAULT || restype != WINED3DRTYPE_SURFACE)) {
1203 wined3d_mutex_unlock();
1204 WARN("Surface is not a render target, or not a stand-alone D3DPOOL_DEFAULT surface\n");
1205 return D3DERR_INVALIDCALL;
1206 }
1207
1208 /* Colorfill can only be used on rendertarget surfaces, or offscreen plain surfaces in D3DPOOL_DEFAULT */
1209 /* Note: D3DRECT is compatible with WINED3DRECT */
1210 hr = IWineD3DDevice_ColorFill(This->WineD3DDevice, surface->wineD3DSurface, (CONST WINED3DRECT*)pRect, color);
1211
1212 wined3d_mutex_unlock();
1213
1214 return hr;
1215}
1216
1217static HRESULT WINAPI IDirect3DDevice9Impl_CreateOffscreenPlainSurface(LPDIRECT3DDEVICE9EX iface, UINT Width, UINT Height, D3DFORMAT Format, D3DPOOL Pool, IDirect3DSurface9 **ppSurface, HANDLE* pSharedHandle) {
1218 HRESULT hr;
1219
1220 TRACE("iface %p, width %u, height %u, format %#x, pool %#x, surface %p, shared_handle %p.\n",
1221 iface, Width, Height, Format, Pool, ppSurface, pSharedHandle);
1222
1223 if(Pool == D3DPOOL_MANAGED ){
1224 FIXME("Attempting to create a managed offscreen plain surface\n");
1225 return D3DERR_INVALIDCALL;
1226 }
1227 /*
1228 'Off-screen plain surfaces are always lockable, regardless of their pool types.'
1229 but then...
1230 D3DPOOL_DEFAULT is the appropriate pool for use with the IDirect3DDevice9::StretchRect and IDirect3DDevice9::ColorFill.
1231 Why, their always lockable?
1232 should I change the usage to dynamic?
1233 */
1234 hr = IDirect3DDevice9Impl_CreateSurface(iface, Width, Height, Format, TRUE /* Lockable */, FALSE /* Discard */,
1235 0 /* Level */, ppSurface, 0 /* Usage (undefined/none) */, (WINED3DPOOL)Pool, D3DMULTISAMPLE_NONE,
1236 0 /* MultisampleQuality */
1237#ifdef VBOX_WITH_WDDM
1238 , pSharedHandle
1239 , NULL
1240#endif
1241 );
1242
1243 return hr;
1244}
1245
1246/* TODO: move to wineD3D */
1247static HRESULT WINAPI IDirect3DDevice9Impl_SetRenderTarget(LPDIRECT3DDEVICE9EX iface, DWORD RenderTargetIndex, IDirect3DSurface9* pRenderTarget) {
1248 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1249 IDirect3DSurface9Impl *pSurface = (IDirect3DSurface9Impl*)pRenderTarget;
1250 HRESULT hr;
1251
1252 TRACE("iface %p, idx %u, surface %p.\n", iface, RenderTargetIndex, pRenderTarget);
1253
1254 if (RenderTargetIndex >= D3D9_MAX_SIMULTANEOUS_RENDERTARGETS)
1255 {
1256 WARN("Invalid index %u specified.\n", RenderTargetIndex);
1257 return D3DERR_INVALIDCALL;
1258 }
1259
1260 wined3d_mutex_lock();
1261 hr = IWineD3DDevice_SetRenderTarget(This->WineD3DDevice, RenderTargetIndex, pSurface ? pSurface->wineD3DSurface : NULL, TRUE);
1262 wined3d_mutex_unlock();
1263
1264 return hr;
1265}
1266
1267static HRESULT WINAPI IDirect3DDevice9Impl_GetRenderTarget(LPDIRECT3DDEVICE9EX iface, DWORD RenderTargetIndex, IDirect3DSurface9 **ppRenderTarget) {
1268 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1269 IWineD3DSurface *pRenderTarget;
1270 HRESULT hr;
1271
1272 TRACE("iface %p, idx %u, surface %p.\n", iface, RenderTargetIndex, ppRenderTarget);
1273
1274 if (ppRenderTarget == NULL) {
1275 return D3DERR_INVALIDCALL;
1276 }
1277
1278 if (RenderTargetIndex >= D3D9_MAX_SIMULTANEOUS_RENDERTARGETS)
1279 {
1280 WARN("Invalid index %u specified.\n", RenderTargetIndex);
1281 return D3DERR_INVALIDCALL;
1282 }
1283
1284 wined3d_mutex_lock();
1285
1286 hr=IWineD3DDevice_GetRenderTarget(This->WineD3DDevice,RenderTargetIndex,&pRenderTarget);
1287
1288 if (FAILED(hr))
1289 {
1290 FIXME("Call to IWineD3DDevice_GetRenderTarget failed, hr %#x\n", hr);
1291 }
1292 else if (!pRenderTarget)
1293 {
1294 *ppRenderTarget = NULL;
1295 }
1296 else
1297 {
1298 IWineD3DSurface_GetParent(pRenderTarget, (IUnknown **)ppRenderTarget);
1299 IWineD3DSurface_Release(pRenderTarget);
1300 }
1301
1302 wined3d_mutex_unlock();
1303
1304 return hr;
1305}
1306
1307static HRESULT WINAPI IDirect3DDevice9Impl_SetDepthStencilSurface(LPDIRECT3DDEVICE9EX iface, IDirect3DSurface9* pZStencilSurface) {
1308 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1309 IDirect3DSurface9Impl *pSurface;
1310 IDirect3DSurface9 *pOldSurface;
1311 HRESULT hr;
1312
1313 TRACE("iface %p, depth_stencil %p.\n", iface, pZStencilSurface);
1314
1315 pSurface = (IDirect3DSurface9Impl*)pZStencilSurface;
1316
1317 wined3d_mutex_lock();
1318 hr = IDirect3DDevice9_GetDepthStencilSurface(iface, &pOldSurface);
1319 if (D3D_OK==hr) {
1320 IDirect3DSurface9_Release(pOldSurface);
1321 IDirect3DSurface9_Release(pOldSurface);
1322 }
1323 hr = IWineD3DDevice_SetDepthStencilSurface(This->WineD3DDevice, NULL==pSurface ? NULL : pSurface->wineD3DSurface);
1324 if (pZStencilSurface) {
1325 IDirect3DSurface9_AddRef(pZStencilSurface);
1326 }
1327 wined3d_mutex_unlock();
1328
1329 return hr;
1330}
1331
1332static HRESULT WINAPI IDirect3DDevice9Impl_GetDepthStencilSurface(LPDIRECT3DDEVICE9EX iface, IDirect3DSurface9 **ppZStencilSurface) {
1333 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1334 HRESULT hr = D3D_OK;
1335 IWineD3DSurface *pZStencilSurface;
1336
1337 TRACE("iface %p, depth_stencil %p.\n", iface, ppZStencilSurface);
1338
1339 if(ppZStencilSurface == NULL){
1340 return D3DERR_INVALIDCALL;
1341 }
1342
1343 wined3d_mutex_lock();
1344 hr = IWineD3DDevice_GetDepthStencilSurface(This->WineD3DDevice,&pZStencilSurface);
1345 if (hr == WINED3D_OK) {
1346 IWineD3DSurface_GetParent(pZStencilSurface,(IUnknown**)ppZStencilSurface);
1347 IWineD3DSurface_Release(pZStencilSurface);
1348 } else {
1349 if (hr != WINED3DERR_NOTFOUND)
1350 WARN("Call to IWineD3DDevice_GetDepthStencilSurface failed with 0x%08x\n", hr);
1351 *ppZStencilSurface = NULL;
1352 }
1353 wined3d_mutex_unlock();
1354
1355 return hr;
1356}
1357
1358static HRESULT WINAPI IDirect3DDevice9Impl_BeginScene(LPDIRECT3DDEVICE9EX iface) {
1359 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1360 HRESULT hr;
1361
1362 TRACE("iface %p.\n", iface);
1363
1364 wined3d_mutex_lock();
1365 hr = IWineD3DDevice_BeginScene(This->WineD3DDevice);
1366 wined3d_mutex_unlock();
1367
1368 return hr;
1369}
1370
1371static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_EndScene(LPDIRECT3DDEVICE9EX iface) {
1372 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1373 HRESULT hr;
1374
1375 TRACE("iface %p.\n", iface);
1376
1377 wined3d_mutex_lock();
1378 hr = IWineD3DDevice_EndScene(This->WineD3DDevice);
1379 wined3d_mutex_unlock();
1380
1381 return hr;
1382}
1383
1384static HRESULT WINAPI IDirect3DDevice9Impl_Clear(LPDIRECT3DDEVICE9EX iface, DWORD Count, CONST D3DRECT* pRects, DWORD Flags, D3DCOLOR Color, float Z, DWORD Stencil) {
1385 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1386 HRESULT hr;
1387
1388 TRACE("iface %p, rect_count %u, rects %p, flags %#x, color 0x%08x, z %.8e, stencil %u.\n",
1389 iface, Count, pRects, Flags, Color, Z, Stencil);
1390
1391 /* Note: D3DRECT is compatible with WINED3DRECT */
1392 wined3d_mutex_lock();
1393 hr = IWineD3DDevice_Clear(This->WineD3DDevice, Count, (CONST WINED3DRECT*) pRects, Flags, Color, Z, Stencil);
1394 wined3d_mutex_unlock();
1395
1396 return hr;
1397}
1398
1399static HRESULT WINAPI IDirect3DDevice9Impl_SetTransform(LPDIRECT3DDEVICE9EX iface, D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX* lpMatrix) {
1400 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1401 HRESULT hr;
1402
1403 TRACE("iface %p, state %#x, matrix %p.\n", iface, State, lpMatrix);
1404
1405 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1406 wined3d_mutex_lock();
1407 hr = IWineD3DDevice_SetTransform(This->WineD3DDevice, State, (CONST WINED3DMATRIX*) lpMatrix);
1408 wined3d_mutex_unlock();
1409
1410 return hr;
1411}
1412
1413static HRESULT WINAPI IDirect3DDevice9Impl_GetTransform(LPDIRECT3DDEVICE9EX iface, D3DTRANSFORMSTATETYPE State, D3DMATRIX* pMatrix) {
1414 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1415 HRESULT hr;
1416
1417 TRACE("iface %p, state %#x, matrix %p.\n", iface, State, pMatrix);
1418
1419 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1420 wined3d_mutex_lock();
1421 hr = IWineD3DDevice_GetTransform(This->WineD3DDevice, State, (WINED3DMATRIX*) pMatrix);
1422 wined3d_mutex_unlock();
1423
1424 return hr;
1425}
1426
1427static HRESULT WINAPI IDirect3DDevice9Impl_MultiplyTransform(LPDIRECT3DDEVICE9EX iface, D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX* pMatrix) {
1428 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1429 HRESULT hr;
1430
1431 TRACE("iface %p, state %#x, matrix %p.\n", iface, State, pMatrix);
1432
1433 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1434 wined3d_mutex_lock();
1435 hr = IWineD3DDevice_MultiplyTransform(This->WineD3DDevice, State, (CONST WINED3DMATRIX*) pMatrix);
1436 wined3d_mutex_unlock();
1437
1438 return hr;
1439}
1440
1441static HRESULT WINAPI IDirect3DDevice9Impl_SetViewport(LPDIRECT3DDEVICE9EX iface, CONST D3DVIEWPORT9* pViewport) {
1442 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1443 HRESULT hr;
1444
1445 TRACE("iface %p, viewport %p.\n", iface, pViewport);
1446
1447 /* Note: D3DVIEWPORT9 is compatible with WINED3DVIEWPORT */
1448 wined3d_mutex_lock();
1449 hr = IWineD3DDevice_SetViewport(This->WineD3DDevice, (const WINED3DVIEWPORT *)pViewport);
1450 wined3d_mutex_unlock();
1451
1452 return hr;
1453}
1454
1455static HRESULT WINAPI IDirect3DDevice9Impl_GetViewport(LPDIRECT3DDEVICE9EX iface, D3DVIEWPORT9* pViewport) {
1456 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1457 HRESULT hr;
1458
1459 TRACE("iface %p, viewport %p.\n", iface, pViewport);
1460
1461 /* Note: D3DVIEWPORT9 is compatible with WINED3DVIEWPORT */
1462 wined3d_mutex_lock();
1463 hr = IWineD3DDevice_GetViewport(This->WineD3DDevice, (WINED3DVIEWPORT *)pViewport);
1464 wined3d_mutex_unlock();
1465
1466 return hr;
1467}
1468
1469static HRESULT WINAPI IDirect3DDevice9Impl_SetMaterial(LPDIRECT3DDEVICE9EX iface, CONST D3DMATERIAL9* pMaterial) {
1470 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1471 HRESULT hr;
1472
1473 TRACE("iface %p, material %p.\n", iface, pMaterial);
1474
1475 /* Note: D3DMATERIAL9 is compatible with WINED3DMATERIAL */
1476 wined3d_mutex_lock();
1477 hr = IWineD3DDevice_SetMaterial(This->WineD3DDevice, (const WINED3DMATERIAL *)pMaterial);
1478 wined3d_mutex_unlock();
1479
1480 return hr;
1481}
1482
1483static HRESULT WINAPI IDirect3DDevice9Impl_GetMaterial(LPDIRECT3DDEVICE9EX iface, D3DMATERIAL9* pMaterial) {
1484 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1485 HRESULT hr;
1486
1487 TRACE("iface %p, material %p.\n", iface, pMaterial);
1488
1489 /* Note: D3DMATERIAL9 is compatible with WINED3DMATERIAL */
1490 wined3d_mutex_lock();
1491 hr = IWineD3DDevice_GetMaterial(This->WineD3DDevice, (WINED3DMATERIAL *)pMaterial);
1492 wined3d_mutex_unlock();
1493
1494 return hr;
1495}
1496
1497static HRESULT WINAPI IDirect3DDevice9Impl_SetLight(LPDIRECT3DDEVICE9EX iface, DWORD Index, CONST D3DLIGHT9* pLight) {
1498 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1499 HRESULT hr;
1500
1501 TRACE("iface %p, index %u, light %p.\n", iface, Index, pLight);
1502
1503 /* Note: D3DLIGHT9 is compatible with WINED3DLIGHT */
1504 wined3d_mutex_lock();
1505 hr = IWineD3DDevice_SetLight(This->WineD3DDevice, Index, (const WINED3DLIGHT *)pLight);
1506 wined3d_mutex_unlock();
1507
1508 return hr;
1509}
1510
1511static HRESULT WINAPI IDirect3DDevice9Impl_GetLight(LPDIRECT3DDEVICE9EX iface, DWORD Index, D3DLIGHT9* pLight) {
1512 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1513 HRESULT hr;
1514
1515 TRACE("iface %p, index %u, light %p.\n", iface, Index, pLight);
1516
1517 /* Note: D3DLIGHT9 is compatible with WINED3DLIGHT */
1518 wined3d_mutex_lock();
1519 hr = IWineD3DDevice_GetLight(This->WineD3DDevice, Index, (WINED3DLIGHT *)pLight);
1520 wined3d_mutex_unlock();
1521
1522 return hr;
1523}
1524
1525static HRESULT WINAPI IDirect3DDevice9Impl_LightEnable(LPDIRECT3DDEVICE9EX iface, DWORD Index, BOOL Enable) {
1526 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1527 HRESULT hr;
1528
1529 TRACE("iface %p, index %u, enable %#x.\n", iface, Index, Enable);
1530
1531 wined3d_mutex_lock();
1532 hr = IWineD3DDevice_SetLightEnable(This->WineD3DDevice, Index, Enable);
1533 wined3d_mutex_unlock();
1534
1535 return hr;
1536}
1537
1538static HRESULT WINAPI IDirect3DDevice9Impl_GetLightEnable(LPDIRECT3DDEVICE9EX iface, DWORD Index, BOOL* pEnable) {
1539 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1540 HRESULT hr;
1541
1542 TRACE("iface %p, index %u, enable %p.\n", iface, Index, pEnable);
1543
1544 wined3d_mutex_lock();
1545 hr = IWineD3DDevice_GetLightEnable(This->WineD3DDevice, Index, pEnable);
1546 wined3d_mutex_unlock();
1547
1548 return hr;
1549}
1550
1551static HRESULT WINAPI IDirect3DDevice9Impl_SetClipPlane(LPDIRECT3DDEVICE9EX iface, DWORD Index, CONST float* pPlane) {
1552 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1553 HRESULT hr;
1554
1555 TRACE("iface %p, index %u, plane %p.\n", iface, Index, pPlane);
1556
1557 wined3d_mutex_lock();
1558 hr = IWineD3DDevice_SetClipPlane(This->WineD3DDevice, Index, pPlane);
1559 wined3d_mutex_unlock();
1560
1561 return hr;
1562}
1563
1564static HRESULT WINAPI IDirect3DDevice9Impl_GetClipPlane(LPDIRECT3DDEVICE9EX iface, DWORD Index, float* pPlane) {
1565 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1566 HRESULT hr;
1567
1568 TRACE("iface %p, index %u, plane %p.\n", iface, Index, pPlane);
1569
1570 wined3d_mutex_lock();
1571 hr = IWineD3DDevice_GetClipPlane(This->WineD3DDevice, Index, pPlane);
1572 wined3d_mutex_unlock();
1573
1574 return hr;
1575}
1576
1577static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_SetRenderState(LPDIRECT3DDEVICE9EX iface, D3DRENDERSTATETYPE State, DWORD Value) {
1578 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1579 HRESULT hr;
1580
1581 TRACE("iface %p, state %#x, value %#x.\n", iface, State, Value);
1582
1583 wined3d_mutex_lock();
1584 hr = IWineD3DDevice_SetRenderState(This->WineD3DDevice, State, Value);
1585 wined3d_mutex_unlock();
1586
1587 return hr;
1588}
1589
1590static HRESULT WINAPI IDirect3DDevice9Impl_GetRenderState(LPDIRECT3DDEVICE9EX iface, D3DRENDERSTATETYPE State, DWORD* pValue) {
1591 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1592 HRESULT hr;
1593
1594 TRACE("iface %p, state %#x, value %p.\n", iface, State, pValue);
1595
1596 wined3d_mutex_lock();
1597 hr = IWineD3DDevice_GetRenderState(This->WineD3DDevice, State, pValue);
1598 wined3d_mutex_unlock();
1599
1600 return hr;
1601}
1602
1603static HRESULT WINAPI IDirect3DDevice9Impl_CreateStateBlock(IDirect3DDevice9Ex *iface,
1604 D3DSTATEBLOCKTYPE type, IDirect3DStateBlock9 **stateblock)
1605{
1606 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1607 IDirect3DStateBlock9Impl *object;
1608 HRESULT hr;
1609
1610 TRACE("iface %p, type %#x, stateblock %p.\n", iface, type, stateblock);
1611
1612 if (type != D3DSBT_ALL && type != D3DSBT_PIXELSTATE && type != D3DSBT_VERTEXSTATE)
1613 {
1614 WARN("Unexpected stateblock type, returning D3DERR_INVALIDCALL.\n");
1615 return D3DERR_INVALIDCALL;
1616 }
1617
1618 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1619 if (!object)
1620 {
1621 ERR("Failed to allocate stateblock memory.\n");
1622 return E_OUTOFMEMORY;
1623 }
1624
1625 hr = stateblock_init(object, This, type, NULL);
1626 if (FAILED(hr))
1627 {
1628 WARN("Failed to initialize stateblock, hr %#x.\n", hr);
1629 HeapFree(GetProcessHeap(), 0, object);
1630 return hr;
1631 }
1632
1633 TRACE("Created stateblock %p.\n", object);
1634 *stateblock = (IDirect3DStateBlock9 *)object;
1635
1636 return D3D_OK;
1637}
1638
1639static HRESULT WINAPI IDirect3DDevice9Impl_BeginStateBlock(IDirect3DDevice9Ex *iface)
1640{
1641 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1642 HRESULT hr;
1643
1644 TRACE("iface %p.\n", iface);
1645
1646 wined3d_mutex_lock();
1647 hr = IWineD3DDevice_BeginStateBlock(This->WineD3DDevice);
1648 wined3d_mutex_unlock();
1649
1650 return hr;
1651}
1652
1653static HRESULT WINAPI IDirect3DDevice9Impl_EndStateBlock(IDirect3DDevice9Ex *iface, IDirect3DStateBlock9 **stateblock)
1654{
1655 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1656 IWineD3DStateBlock *wined3d_stateblock;
1657 IDirect3DStateBlock9Impl *object;
1658 HRESULT hr;
1659
1660 TRACE("iface %p, stateblock %p.\n", iface, stateblock);
1661
1662 wined3d_mutex_lock();
1663 hr = IWineD3DDevice_EndStateBlock(This->WineD3DDevice, &wined3d_stateblock);
1664 wined3d_mutex_unlock();
1665 if (FAILED(hr))
1666 {
1667 WARN("IWineD3DDevice_EndStateBlock() failed, hr %#x.\n", hr);
1668 return hr;
1669 }
1670
1671 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1672 if (!object)
1673 {
1674 ERR("Failed to allocate stateblock memory.\n");
1675 IWineD3DStateBlock_Release(wined3d_stateblock);
1676 return E_OUTOFMEMORY;
1677 }
1678
1679 hr = stateblock_init(object, This, 0, wined3d_stateblock);
1680 if (FAILED(hr))
1681 {
1682 WARN("Failed to initialize stateblock, hr %#x.\n", hr);
1683 IWineD3DStateBlock_Release(wined3d_stateblock);
1684 HeapFree(GetProcessHeap(), 0, object);
1685 return hr;
1686 }
1687
1688 TRACE("Created stateblock %p.\n", object);
1689 *stateblock = (IDirect3DStateBlock9 *)object;
1690
1691 return D3D_OK;
1692}
1693
1694static HRESULT WINAPI IDirect3DDevice9Impl_SetClipStatus(LPDIRECT3DDEVICE9EX iface, CONST D3DCLIPSTATUS9* pClipStatus) {
1695 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1696 HRESULT hr;
1697
1698 TRACE("iface %p, clip_status %p.\n", iface, pClipStatus);
1699
1700 wined3d_mutex_lock();
1701 hr = IWineD3DDevice_SetClipStatus(This->WineD3DDevice, (const WINED3DCLIPSTATUS *)pClipStatus);
1702 wined3d_mutex_unlock();
1703
1704 return hr;
1705}
1706
1707static HRESULT WINAPI IDirect3DDevice9Impl_GetClipStatus(LPDIRECT3DDEVICE9EX iface, D3DCLIPSTATUS9* pClipStatus) {
1708 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1709 HRESULT hr;
1710
1711 TRACE("iface %p, clip_status %p.\n", iface, pClipStatus);
1712
1713 wined3d_mutex_lock();
1714 hr = IWineD3DDevice_GetClipStatus(This->WineD3DDevice, (WINED3DCLIPSTATUS *)pClipStatus);
1715 wined3d_mutex_unlock();
1716
1717 return hr;
1718}
1719
1720static HRESULT WINAPI IDirect3DDevice9Impl_GetTexture(LPDIRECT3DDEVICE9EX iface, DWORD Stage, IDirect3DBaseTexture9 **ppTexture) {
1721 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1722 IWineD3DBaseTexture *retTexture = NULL;
1723 HRESULT rc = D3D_OK;
1724
1725 TRACE("iface %p, stage %u, texture %p.\n", iface, Stage, ppTexture);
1726
1727 if(ppTexture == NULL){
1728 return D3DERR_INVALIDCALL;
1729 }
1730
1731 wined3d_mutex_lock();
1732 rc = IWineD3DDevice_GetTexture(This->WineD3DDevice, Stage, &retTexture);
1733 if (SUCCEEDED(rc) && NULL != retTexture) {
1734 IWineD3DBaseTexture_GetParent(retTexture, (IUnknown **)ppTexture);
1735 IWineD3DBaseTexture_Release(retTexture);
1736 } else {
1737 if(FAILED(rc)) {
1738 WARN("Call to get texture (%d) failed (%p)\n", Stage, retTexture);
1739 }
1740 *ppTexture = NULL;
1741 }
1742 wined3d_mutex_unlock();
1743
1744 return rc;
1745}
1746
1747static HRESULT WINAPI IDirect3DDevice9Impl_SetTexture(LPDIRECT3DDEVICE9EX iface, DWORD Stage, IDirect3DBaseTexture9* pTexture) {
1748 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1749 HRESULT hr;
1750
1751 TRACE("iface %p, stage %u, texture %p.\n", iface, Stage, pTexture);
1752
1753 wined3d_mutex_lock();
1754 hr = IWineD3DDevice_SetTexture(This->WineD3DDevice, Stage,
1755 pTexture==NULL ? NULL:((IDirect3DBaseTexture9Impl *)pTexture)->wineD3DBaseTexture);
1756 wined3d_mutex_unlock();
1757
1758 return hr;
1759}
1760
1761static const WINED3DTEXTURESTAGESTATETYPE tss_lookup[] =
1762{
1763 WINED3DTSS_FORCE_DWORD, /* 0, unused */
1764 WINED3DTSS_COLOROP, /* 1, D3DTSS_COLOROP */
1765 WINED3DTSS_COLORARG1, /* 2, D3DTSS_COLORARG1 */
1766 WINED3DTSS_COLORARG2, /* 3, D3DTSS_COLORARG2 */
1767 WINED3DTSS_ALPHAOP, /* 4, D3DTSS_ALPHAOP */
1768 WINED3DTSS_ALPHAARG1, /* 5, D3DTSS_ALPHAARG1 */
1769 WINED3DTSS_ALPHAARG2, /* 6, D3DTSS_ALPHAARG2 */
1770 WINED3DTSS_BUMPENVMAT00, /* 7, D3DTSS_BUMPENVMAT00 */
1771 WINED3DTSS_BUMPENVMAT01, /* 8, D3DTSS_BUMPENVMAT01 */
1772 WINED3DTSS_BUMPENVMAT10, /* 9, D3DTSS_BUMPENVMAT10 */
1773 WINED3DTSS_BUMPENVMAT11, /* 10, D3DTSS_BUMPENVMAT11 */
1774 WINED3DTSS_TEXCOORDINDEX, /* 11, D3DTSS_TEXCOORDINDEX */
1775 WINED3DTSS_FORCE_DWORD, /* 12, unused */
1776 WINED3DTSS_FORCE_DWORD, /* 13, unused */
1777 WINED3DTSS_FORCE_DWORD, /* 14, unused */
1778 WINED3DTSS_FORCE_DWORD, /* 15, unused */
1779 WINED3DTSS_FORCE_DWORD, /* 16, unused */
1780 WINED3DTSS_FORCE_DWORD, /* 17, unused */
1781 WINED3DTSS_FORCE_DWORD, /* 18, unused */
1782 WINED3DTSS_FORCE_DWORD, /* 19, unused */
1783 WINED3DTSS_FORCE_DWORD, /* 20, unused */
1784 WINED3DTSS_FORCE_DWORD, /* 21, unused */
1785 WINED3DTSS_BUMPENVLSCALE, /* 22, D3DTSS_BUMPENVLSCALE */
1786 WINED3DTSS_BUMPENVLOFFSET, /* 23, D3DTSS_BUMPENVLOFFSET */
1787 WINED3DTSS_TEXTURETRANSFORMFLAGS, /* 24, D3DTSS_TEXTURETRANSFORMFLAGS */
1788 WINED3DTSS_FORCE_DWORD, /* 25, unused */
1789 WINED3DTSS_COLORARG0, /* 26, D3DTSS_COLORARG0 */
1790 WINED3DTSS_ALPHAARG0, /* 27, D3DTSS_ALPHAARG0 */
1791 WINED3DTSS_RESULTARG, /* 28, D3DTSS_RESULTARG */
1792 WINED3DTSS_FORCE_DWORD, /* 29, unused */
1793 WINED3DTSS_FORCE_DWORD, /* 30, unused */
1794 WINED3DTSS_FORCE_DWORD, /* 31, unused */
1795 WINED3DTSS_CONSTANT, /* 32, D3DTSS_CONSTANT */
1796};
1797
1798static HRESULT WINAPI IDirect3DDevice9Impl_GetTextureStageState(LPDIRECT3DDEVICE9EX iface, DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD* pValue) {
1799 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1800 HRESULT hr;
1801
1802 TRACE("iface %p, stage %u, state %#x, value %p.\n", iface, Stage, Type, pValue);
1803
1804 wined3d_mutex_lock();
1805 hr = IWineD3DDevice_GetTextureStageState(This->WineD3DDevice, Stage, tss_lookup[Type], pValue);
1806 wined3d_mutex_unlock();
1807
1808 return hr;
1809}
1810
1811static HRESULT WINAPI IDirect3DDevice9Impl_SetTextureStageState(LPDIRECT3DDEVICE9EX iface, DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD Value) {
1812 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1813 HRESULT hr;
1814
1815 TRACE("iface %p, stage %u, state %#x, value %#x.\n", iface, Stage, Type, Value);
1816
1817 wined3d_mutex_lock();
1818 hr = IWineD3DDevice_SetTextureStageState(This->WineD3DDevice, Stage, tss_lookup[Type], Value);
1819 wined3d_mutex_unlock();
1820
1821 return hr;
1822}
1823
1824static HRESULT WINAPI IDirect3DDevice9Impl_GetSamplerState(IDirect3DDevice9Ex *iface, DWORD Sampler,
1825 D3DSAMPLERSTATETYPE Type, DWORD *pValue)
1826{
1827 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1828 HRESULT hr;
1829
1830 TRACE("iface %p, sampler %u, state %#x, value %p.\n", iface, Sampler, Type, pValue);
1831
1832 wined3d_mutex_lock();
1833 hr = IWineD3DDevice_GetSamplerState(This->WineD3DDevice, Sampler, Type, pValue);
1834 wined3d_mutex_unlock();
1835
1836 return hr;
1837}
1838
1839static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_SetSamplerState(LPDIRECT3DDEVICE9EX iface, DWORD Sampler, D3DSAMPLERSTATETYPE Type, DWORD Value) {
1840 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1841 HRESULT hr;
1842
1843 TRACE("iface %p, sampler %u, state %#x, value %#x.\n", iface, Sampler, Type, Value);
1844
1845 wined3d_mutex_lock();
1846 hr = IWineD3DDevice_SetSamplerState(This->WineD3DDevice, Sampler, Type, Value);
1847 wined3d_mutex_unlock();
1848
1849 return hr;
1850}
1851
1852static HRESULT WINAPI IDirect3DDevice9Impl_ValidateDevice(LPDIRECT3DDEVICE9EX iface, DWORD* pNumPasses) {
1853 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1854 HRESULT hr;
1855
1856 TRACE("iface %p, pass_count %p.\n", iface, pNumPasses);
1857
1858 wined3d_mutex_lock();
1859 hr = IWineD3DDevice_ValidateDevice(This->WineD3DDevice, pNumPasses);
1860 wined3d_mutex_unlock();
1861
1862 return hr;
1863}
1864
1865static HRESULT WINAPI IDirect3DDevice9Impl_SetPaletteEntries(IDirect3DDevice9Ex *iface, UINT PaletteNumber,
1866 const PALETTEENTRY *pEntries)
1867{
1868 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1869 HRESULT hr;
1870
1871 TRACE("iface %p, palette_idx %u, entries %p.\n", iface, PaletteNumber, pEntries);
1872
1873 wined3d_mutex_lock();
1874 hr = IWineD3DDevice_SetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
1875 wined3d_mutex_unlock();
1876
1877 return hr;
1878}
1879
1880static HRESULT WINAPI IDirect3DDevice9Impl_GetPaletteEntries(LPDIRECT3DDEVICE9EX iface, UINT PaletteNumber, PALETTEENTRY* pEntries) {
1881 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1882 HRESULT hr;
1883
1884 TRACE("iface %p, palette_idx %u, entries %p.\n", iface, PaletteNumber, pEntries);
1885
1886 wined3d_mutex_lock();
1887 hr = IWineD3DDevice_GetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
1888 wined3d_mutex_unlock();
1889
1890 return hr;
1891}
1892
1893static HRESULT WINAPI IDirect3DDevice9Impl_SetCurrentTexturePalette(LPDIRECT3DDEVICE9EX iface, UINT PaletteNumber) {
1894 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1895 HRESULT hr;
1896
1897 TRACE("iface %p, palette_idx %u.\n", iface, PaletteNumber);
1898
1899 wined3d_mutex_lock();
1900 hr = IWineD3DDevice_SetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
1901 wined3d_mutex_unlock();
1902
1903 return hr;
1904}
1905
1906static HRESULT WINAPI IDirect3DDevice9Impl_GetCurrentTexturePalette(LPDIRECT3DDEVICE9EX iface, UINT* PaletteNumber) {
1907 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1908 HRESULT hr;
1909
1910 TRACE("iface %p, palette_idx %p.\n", iface, PaletteNumber);
1911
1912 wined3d_mutex_lock();
1913 hr = IWineD3DDevice_GetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
1914 wined3d_mutex_unlock();
1915
1916 return hr;
1917}
1918
1919static HRESULT WINAPI IDirect3DDevice9Impl_SetScissorRect(LPDIRECT3DDEVICE9EX iface, CONST RECT* pRect) {
1920 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1921 HRESULT hr;
1922
1923 TRACE("iface %p, rect %p.\n", iface, pRect);
1924
1925 wined3d_mutex_lock();
1926 hr = IWineD3DDevice_SetScissorRect(This->WineD3DDevice, pRect);
1927 wined3d_mutex_unlock();
1928
1929 return hr;
1930}
1931
1932static HRESULT WINAPI IDirect3DDevice9Impl_GetScissorRect(LPDIRECT3DDEVICE9EX iface, RECT* pRect) {
1933 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1934 HRESULT hr;
1935
1936 TRACE("iface %p, rect %p.\n", iface, pRect);
1937
1938 wined3d_mutex_lock();
1939 hr = IWineD3DDevice_GetScissorRect(This->WineD3DDevice, pRect);
1940 wined3d_mutex_unlock();
1941
1942 return hr;
1943}
1944
1945static HRESULT WINAPI IDirect3DDevice9Impl_SetSoftwareVertexProcessing(LPDIRECT3DDEVICE9EX iface, BOOL bSoftware) {
1946 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1947 HRESULT hr;
1948
1949 TRACE("iface %p, software %#x.\n", iface, bSoftware);
1950
1951 wined3d_mutex_lock();
1952 hr = IWineD3DDevice_SetSoftwareVertexProcessing(This->WineD3DDevice, bSoftware);
1953 wined3d_mutex_unlock();
1954
1955 return hr;
1956}
1957
1958static BOOL WINAPI IDirect3DDevice9Impl_GetSoftwareVertexProcessing(LPDIRECT3DDEVICE9EX iface) {
1959 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1960 BOOL ret;
1961
1962 TRACE("iface %p.\n", iface);
1963
1964 wined3d_mutex_lock();
1965 ret = IWineD3DDevice_GetSoftwareVertexProcessing(This->WineD3DDevice);
1966 wined3d_mutex_unlock();
1967
1968 return ret;
1969}
1970
1971static HRESULT WINAPI IDirect3DDevice9Impl_SetNPatchMode(LPDIRECT3DDEVICE9EX iface, float nSegments) {
1972 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1973 HRESULT hr;
1974
1975 TRACE("iface %p, segment_count %.8e.\n", iface, nSegments);
1976
1977 wined3d_mutex_lock();
1978 hr = IWineD3DDevice_SetNPatchMode(This->WineD3DDevice, nSegments);
1979 wined3d_mutex_unlock();
1980
1981 return hr;
1982}
1983
1984static float WINAPI IDirect3DDevice9Impl_GetNPatchMode(LPDIRECT3DDEVICE9EX iface) {
1985 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1986 float ret;
1987
1988 TRACE("iface %p.\n", iface);
1989
1990 wined3d_mutex_lock();
1991 ret = IWineD3DDevice_GetNPatchMode(This->WineD3DDevice);
1992 wined3d_mutex_unlock();
1993
1994 return ret;
1995}
1996
1997static HRESULT WINAPI IDirect3DDevice9Impl_DrawPrimitive(IDirect3DDevice9Ex *iface, D3DPRIMITIVETYPE PrimitiveType,
1998 UINT StartVertex, UINT PrimitiveCount)
1999{
2000 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2001 HRESULT hr;
2002
2003 TRACE("iface %p, primitive_type %#x, start_vertex %u, primitive_count %u.\n",
2004 iface, PrimitiveType, StartVertex, PrimitiveCount);
2005
2006 wined3d_mutex_lock();
2007 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
2008 hr = IWineD3DDevice_DrawPrimitive(This->WineD3DDevice, StartVertex,
2009 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount));
2010 wined3d_mutex_unlock();
2011
2012 return hr;
2013}
2014
2015static HRESULT WINAPI IDirect3DDevice9Impl_DrawIndexedPrimitive(LPDIRECT3DDEVICE9EX iface, D3DPRIMITIVETYPE PrimitiveType,
2016 INT BaseVertexIndex, UINT MinVertexIndex, UINT NumVertices, UINT startIndex, UINT primCount) {
2017 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2018 HRESULT hr;
2019
2020 TRACE("iface %p, primitive_type %#x, base_vertex_idx %u, min_vertex_idx %u,\n"
2021 "vertex_count %u, start_idx %u, primitive_count %u.\n",
2022 iface, PrimitiveType, BaseVertexIndex, MinVertexIndex,
2023 NumVertices, startIndex, primCount);
2024
2025 wined3d_mutex_lock();
2026 IWineD3DDevice_SetBaseVertexIndex(This->WineD3DDevice, BaseVertexIndex);
2027 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
2028 hr = IWineD3DDevice_DrawIndexedPrimitive(This->WineD3DDevice, startIndex,
2029 vertex_count_from_primitive_count(PrimitiveType, primCount));
2030 wined3d_mutex_unlock();
2031
2032 return hr;
2033}
2034
2035static HRESULT WINAPI IDirect3DDevice9Impl_DrawPrimitiveUP(IDirect3DDevice9Ex *iface, D3DPRIMITIVETYPE PrimitiveType,
2036 UINT PrimitiveCount, const void *pVertexStreamZeroData, UINT VertexStreamZeroStride)
2037{
2038 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2039 HRESULT hr;
2040
2041 TRACE("iface %p, primitive_type %#x, primitive_count %u, data %p, stride %u.\n",
2042 iface, PrimitiveType, PrimitiveCount, pVertexStreamZeroData, VertexStreamZeroStride);
2043
2044 wined3d_mutex_lock();
2045 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
2046 hr = IWineD3DDevice_DrawPrimitiveUP(This->WineD3DDevice,
2047 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount),
2048 pVertexStreamZeroData, VertexStreamZeroStride);
2049 wined3d_mutex_unlock();
2050
2051 return hr;
2052}
2053
2054static HRESULT WINAPI IDirect3DDevice9Impl_DrawIndexedPrimitiveUP(LPDIRECT3DDEVICE9EX iface, D3DPRIMITIVETYPE PrimitiveType, UINT MinVertexIndex,
2055 UINT NumVertexIndices, UINT PrimitiveCount, CONST void* pIndexData,
2056 D3DFORMAT IndexDataFormat, CONST void* pVertexStreamZeroData, UINT VertexStreamZeroStride) {
2057 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2058 HRESULT hr;
2059
2060 TRACE("iface %p, primitive_type %#x, min_vertex_idx %u, index_count %u, primitive_count %u,\n"
2061 "index_data %p, index_format %#x, vertex_data %p, vertex_stride %u.\n",
2062 iface, PrimitiveType, MinVertexIndex, NumVertexIndices, PrimitiveCount,
2063 pIndexData, IndexDataFormat, pVertexStreamZeroData, VertexStreamZeroStride);
2064
2065 wined3d_mutex_lock();
2066 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
2067 hr = IWineD3DDevice_DrawIndexedPrimitiveUP(This->WineD3DDevice,
2068 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount), pIndexData,
2069 wined3dformat_from_d3dformat(IndexDataFormat), pVertexStreamZeroData, VertexStreamZeroStride);
2070 wined3d_mutex_unlock();
2071
2072 return hr;
2073}
2074
2075static HRESULT WINAPI IDirect3DDevice9Impl_ProcessVertices(LPDIRECT3DDEVICE9EX iface, UINT SrcStartIndex, UINT DestIndex, UINT VertexCount, IDirect3DVertexBuffer9* pDestBuffer, IDirect3DVertexDeclaration9* pVertexDecl, DWORD Flags) {
2076 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2077 IDirect3DVertexDeclaration9Impl *Decl = (IDirect3DVertexDeclaration9Impl *) pVertexDecl;
2078 HRESULT hr;
2079 IDirect3DVertexBuffer9Impl *dest = (IDirect3DVertexBuffer9Impl *) pDestBuffer;
2080
2081 TRACE("iface %p, src_start_idx %u, dst_idx %u, vertex_count %u, dst_buffer %p, declaration %p, flags %#x.\n",
2082 iface, SrcStartIndex, DestIndex, VertexCount, pDestBuffer, pVertexDecl, Flags);
2083
2084 wined3d_mutex_lock();
2085 hr = IWineD3DDevice_ProcessVertices(This->WineD3DDevice,SrcStartIndex, DestIndex, VertexCount, dest->wineD3DVertexBuffer, Decl ? Decl->wineD3DVertexDeclaration : NULL, Flags, dest->fvf);
2086 wined3d_mutex_unlock();
2087
2088 return hr;
2089}
2090
2091static HRESULT WINAPI IDirect3DDevice9Impl_CreateVertexDeclaration(IDirect3DDevice9Ex *iface,
2092 const D3DVERTEXELEMENT9 *elements, IDirect3DVertexDeclaration9 **declaration)
2093{
2094 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2095 IDirect3DVertexDeclaration9Impl *object;
2096 HRESULT hr;
2097
2098 TRACE("iface %p, elements %p, declaration %p.\n", iface, elements, declaration);
2099
2100 if (!declaration)
2101 {
2102 WARN("Caller passed a NULL declaration, returning D3DERR_INVALIDCALL.\n");
2103 return D3DERR_INVALIDCALL;
2104 }
2105
2106 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2107 if (!object)
2108 {
2109 ERR("Failed to allocate vertex declaration memory.\n");
2110 return E_OUTOFMEMORY;
2111 }
2112
2113 hr = vertexdeclaration_init(object, This, elements);
2114 if (FAILED(hr))
2115 {
2116 WARN("Failed to initialize vertex declaration, hr %#x.\n", hr);
2117 HeapFree(GetProcessHeap(), 0, object);
2118 return hr;
2119 }
2120
2121 TRACE("Created vertex declaration %p.\n", object);
2122 *declaration = (IDirect3DVertexDeclaration9 *)object;
2123
2124 return D3D_OK;
2125}
2126
2127static IDirect3DVertexDeclaration9 *getConvertedDecl(IDirect3DDevice9Impl *This, DWORD fvf) {
2128 HRESULT hr;
2129 D3DVERTEXELEMENT9* elements = NULL;
2130 IDirect3DVertexDeclaration9* pDecl = NULL;
2131 int p, low, high; /* deliberately signed */
2132 IDirect3DVertexDeclaration9 **convertedDecls = This->convertedDecls;
2133
2134 TRACE("Searching for declaration for fvf %08x... ", fvf);
2135
2136 low = 0;
2137 high = This->numConvertedDecls - 1;
2138 while(low <= high) {
2139 p = (low + high) >> 1;
2140 TRACE("%d ", p);
2141 if(((IDirect3DVertexDeclaration9Impl *) convertedDecls[p])->convFVF == fvf) {
2142 TRACE("found %p\n", convertedDecls[p]);
2143 return convertedDecls[p];
2144 } else if(((IDirect3DVertexDeclaration9Impl *) convertedDecls[p])->convFVF < fvf) {
2145 low = p + 1;
2146 } else {
2147 high = p - 1;
2148 }
2149 }
2150 TRACE("not found. Creating and inserting at position %d.\n", low);
2151
2152 hr = vdecl_convert_fvf(fvf, &elements);
2153 if (hr != S_OK) return NULL;
2154
2155 hr = IDirect3DDevice9Impl_CreateVertexDeclaration((IDirect3DDevice9Ex *) This, elements, &pDecl);
2156 HeapFree(GetProcessHeap(), 0, elements); /* CreateVertexDeclaration makes a copy */
2157 if (hr != S_OK) return NULL;
2158
2159 if(This->declArraySize == This->numConvertedDecls) {
2160 int grow = max(This->declArraySize / 2, 8);
2161 convertedDecls = HeapReAlloc(GetProcessHeap(), 0, convertedDecls,
2162 sizeof(convertedDecls[0]) * (This->numConvertedDecls + grow));
2163 if(!convertedDecls) {
2164 /* This will destroy it */
2165 IDirect3DVertexDeclaration9_Release(pDecl);
2166 return NULL;
2167 }
2168 This->convertedDecls = convertedDecls;
2169 This->declArraySize += grow;
2170 }
2171
2172 memmove(convertedDecls + low + 1, convertedDecls + low, sizeof(IDirect3DVertexDeclaration9Impl *) * (This->numConvertedDecls - low));
2173 convertedDecls[low] = pDecl;
2174 This->numConvertedDecls++;
2175
2176 /* Will prevent the decl from being destroyed */
2177 ((IDirect3DVertexDeclaration9Impl *) pDecl)->convFVF = fvf;
2178 IDirect3DVertexDeclaration9_Release(pDecl); /* Does not destroy now */
2179
2180 TRACE("Returning %p. %d decls in array\n", pDecl, This->numConvertedDecls);
2181 return pDecl;
2182}
2183
2184static HRESULT WINAPI IDirect3DDevice9Impl_SetFVF(LPDIRECT3DDEVICE9EX iface, DWORD FVF) {
2185 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2186 IDirect3DVertexDeclaration9 *decl;
2187 HRESULT hr;
2188
2189 TRACE("iface %p, fvf %#x.\n", iface, FVF);
2190
2191 if (!FVF)
2192 {
2193 WARN("%#x is not a valid FVF\n", FVF);
2194 return D3D_OK;
2195 }
2196
2197 wined3d_mutex_lock();
2198 decl = getConvertedDecl(This, FVF);
2199 wined3d_mutex_unlock();
2200
2201 if (!decl)
2202 {
2203 /* Any situation when this should happen, except out of memory? */
2204 ERR("Failed to create a converted vertex declaration\n");
2205 return D3DERR_DRIVERINTERNALERROR;
2206 }
2207
2208 hr = IDirect3DDevice9Impl_SetVertexDeclaration(iface, decl);
2209 if (FAILED(hr)) ERR("Failed to set vertex declaration\n");
2210
2211 return hr;
2212}
2213
2214static HRESULT WINAPI IDirect3DDevice9Impl_GetFVF(IDirect3DDevice9Ex *iface, DWORD *pFVF)
2215{
2216 IDirect3DVertexDeclaration9 *decl;
2217 HRESULT hr;
2218
2219 TRACE("iface %p, fvf %p.\n", iface, pFVF);
2220
2221 hr = IDirect3DDevice9_GetVertexDeclaration(iface, &decl);
2222 if (FAILED(hr))
2223 {
2224 WARN("Failed to get vertex declaration, %#x\n", hr);
2225 *pFVF = 0;
2226 return hr;
2227 }
2228
2229 if (decl)
2230 {
2231 *pFVF = ((IDirect3DVertexDeclaration9Impl *)decl)->convFVF;
2232 IDirect3DVertexDeclaration9_Release(decl);
2233 }
2234 else
2235 {
2236 *pFVF = 0;
2237 }
2238
2239 TRACE("Returning FVF %#x\n", *pFVF);
2240
2241 return hr;
2242}
2243
2244static HRESULT WINAPI IDirect3DDevice9Impl_CreateVertexShader(IDirect3DDevice9Ex *iface,
2245 const DWORD *byte_code, IDirect3DVertexShader9 **shader)
2246{
2247 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2248 IDirect3DVertexShader9Impl *object;
2249 HRESULT hr;
2250
2251 TRACE("iface %p, byte_code %p, shader %p.\n", iface, byte_code, shader);
2252
2253 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2254 if (!object)
2255 {
2256 ERR("Failed to allocate vertex shader memory.\n");
2257 return E_OUTOFMEMORY;
2258 }
2259
2260 hr = vertexshader_init(object, This, byte_code);
2261 if (FAILED(hr))
2262 {
2263 WARN("Failed to initialize vertex shader, hr %#x.\n", hr);
2264 HeapFree(GetProcessHeap(), 0, object);
2265 return hr;
2266 }
2267
2268 TRACE("Created vertex shader %p.\n", object);
2269 *shader = (IDirect3DVertexShader9 *)object;
2270
2271 return D3D_OK;
2272}
2273
2274static HRESULT WINAPI IDirect3DDevice9Impl_SetStreamSource(LPDIRECT3DDEVICE9EX iface, UINT StreamNumber, IDirect3DVertexBuffer9* pStreamData, UINT OffsetInBytes, UINT Stride) {
2275 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2276 HRESULT hr;
2277
2278 TRACE("iface %p, stream_idx %u, buffer %p, offset %u, stride %u.\n",
2279 iface, StreamNumber, pStreamData, OffsetInBytes, Stride);
2280
2281 wined3d_mutex_lock();
2282 hr = IWineD3DDevice_SetStreamSource(This->WineD3DDevice, StreamNumber,
2283 pStreamData ? ((IDirect3DVertexBuffer9Impl *)pStreamData)->wineD3DVertexBuffer : NULL,
2284 OffsetInBytes, Stride);
2285 wined3d_mutex_unlock();
2286
2287 return hr;
2288}
2289
2290static HRESULT WINAPI IDirect3DDevice9Impl_GetStreamSource(LPDIRECT3DDEVICE9EX iface, UINT StreamNumber, IDirect3DVertexBuffer9 **pStream, UINT* OffsetInBytes, UINT* pStride) {
2291 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2292 IWineD3DBuffer *retStream = NULL;
2293 HRESULT rc = D3D_OK;
2294
2295 TRACE("iface %p, stream_idx %u, buffer %p, offset %p, stride %p.\n",
2296 iface, StreamNumber, pStream, OffsetInBytes, pStride);
2297
2298 if(pStream == NULL){
2299 return D3DERR_INVALIDCALL;
2300 }
2301
2302 wined3d_mutex_lock();
2303 rc = IWineD3DDevice_GetStreamSource(This->WineD3DDevice, StreamNumber, &retStream, OffsetInBytes, pStride);
2304 if (rc == D3D_OK && NULL != retStream) {
2305 IWineD3DBuffer_GetParent(retStream, (IUnknown **)pStream);
2306 IWineD3DBuffer_Release(retStream);
2307 }else{
2308 if (rc != D3D_OK){
2309 FIXME("Call to GetStreamSource failed %p %p\n", OffsetInBytes, pStride);
2310 }
2311 *pStream = NULL;
2312 }
2313 wined3d_mutex_unlock();
2314
2315 return rc;
2316}
2317
2318static HRESULT WINAPI IDirect3DDevice9Impl_SetStreamSourceFreq(IDirect3DDevice9Ex *iface, UINT StreamNumber,
2319 UINT Divider)
2320{
2321 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2322 HRESULT hr;
2323
2324 TRACE("iface %p, stream_idx %u, freq %u.\n", iface, StreamNumber, Divider);
2325
2326 wined3d_mutex_lock();
2327 hr = IWineD3DDevice_SetStreamSourceFreq(This->WineD3DDevice, StreamNumber, Divider);
2328 wined3d_mutex_unlock();
2329
2330 return hr;
2331}
2332
2333static HRESULT WINAPI IDirect3DDevice9Impl_GetStreamSourceFreq(LPDIRECT3DDEVICE9EX iface, UINT StreamNumber, UINT* Divider) {
2334 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2335 HRESULT hr;
2336
2337 TRACE("iface %p, stream_idx %u, freq %p.\n", iface, StreamNumber, Divider);
2338
2339 wined3d_mutex_lock();
2340 hr = IWineD3DDevice_GetStreamSourceFreq(This->WineD3DDevice, StreamNumber, Divider);
2341 wined3d_mutex_unlock();
2342
2343 return hr;
2344}
2345
2346static HRESULT WINAPI IDirect3DDevice9Impl_SetIndices(LPDIRECT3DDEVICE9EX iface, IDirect3DIndexBuffer9* pIndexData) {
2347 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2348 HRESULT hr;
2349 IDirect3DIndexBuffer9Impl *ib = (IDirect3DIndexBuffer9Impl *) pIndexData;
2350
2351 TRACE("iface %p, buffer %p.\n", iface, pIndexData);
2352
2353 wined3d_mutex_lock();
2354 hr = IWineD3DDevice_SetIndexBuffer(This->WineD3DDevice,
2355 ib ? ib->wineD3DIndexBuffer : NULL,
2356 ib ? ib->format : WINED3DFMT_UNKNOWN);
2357 wined3d_mutex_unlock();
2358
2359 return hr;
2360}
2361
2362static HRESULT WINAPI IDirect3DDevice9Impl_GetIndices(LPDIRECT3DDEVICE9EX iface, IDirect3DIndexBuffer9 **ppIndexData) {
2363 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2364 IWineD3DBuffer *retIndexData = NULL;
2365 HRESULT rc = D3D_OK;
2366
2367 TRACE("iface %p, buffer %p.\n", iface, ppIndexData);
2368
2369 if(ppIndexData == NULL){
2370 return D3DERR_INVALIDCALL;
2371 }
2372
2373 wined3d_mutex_lock();
2374 rc = IWineD3DDevice_GetIndexBuffer(This->WineD3DDevice, &retIndexData);
2375 if (SUCCEEDED(rc) && retIndexData) {
2376 IWineD3DBuffer_GetParent(retIndexData, (IUnknown **)ppIndexData);
2377 IWineD3DBuffer_Release(retIndexData);
2378 } else {
2379 if (FAILED(rc)) FIXME("Call to GetIndices failed\n");
2380 *ppIndexData = NULL;
2381 }
2382 wined3d_mutex_unlock();
2383
2384 return rc;
2385}
2386
2387static HRESULT WINAPI IDirect3DDevice9Impl_CreatePixelShader(IDirect3DDevice9Ex *iface,
2388 const DWORD *byte_code, IDirect3DPixelShader9 **shader)
2389{
2390 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2391 IDirect3DPixelShader9Impl *object;
2392 HRESULT hr;
2393
2394 TRACE("iface %p, byte_code %p, shader %p.\n", iface, byte_code, shader);
2395
2396 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2397 if (!object)
2398 {
2399 FIXME("Failed to allocate pixel shader memory.\n");
2400 return E_OUTOFMEMORY;
2401 }
2402
2403 hr = pixelshader_init(object, This, byte_code);
2404 if (FAILED(hr))
2405 {
2406 WARN("Failed to initialize pixel shader, hr %#x.\n", hr);
2407 HeapFree(GetProcessHeap(), 0, object);
2408 return hr;
2409 }
2410
2411 TRACE("Created pixel shader %p.\n", object);
2412 *shader = (IDirect3DPixelShader9 *)object;
2413
2414 return D3D_OK;
2415}
2416
2417static HRESULT WINAPI IDirect3DDevice9Impl_DrawRectPatch(LPDIRECT3DDEVICE9EX iface, UINT Handle, CONST float* pNumSegs, CONST D3DRECTPATCH_INFO* pRectPatchInfo) {
2418 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2419 HRESULT hr;
2420
2421 TRACE("iface %p, handle %#x, segment_count %p, patch_info %p.\n",
2422 iface, Handle, pNumSegs, pRectPatchInfo);
2423
2424 wined3d_mutex_lock();
2425 hr = IWineD3DDevice_DrawRectPatch(This->WineD3DDevice, Handle, pNumSegs, (CONST WINED3DRECTPATCH_INFO *)pRectPatchInfo);
2426 wined3d_mutex_unlock();
2427
2428 return hr;
2429}
2430
2431static HRESULT WINAPI IDirect3DDevice9Impl_DrawTriPatch(LPDIRECT3DDEVICE9EX iface, UINT Handle, CONST float* pNumSegs, CONST D3DTRIPATCH_INFO* pTriPatchInfo) {
2432 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2433 HRESULT hr;
2434
2435 TRACE("iface %p, handle %#x, segment_count %p, patch_info %p.\n",
2436 iface, Handle, pNumSegs, pTriPatchInfo);
2437
2438 wined3d_mutex_lock();
2439 hr = IWineD3DDevice_DrawTriPatch(This->WineD3DDevice, Handle, pNumSegs, (CONST WINED3DTRIPATCH_INFO *)pTriPatchInfo);
2440 wined3d_mutex_unlock();
2441
2442 return hr;
2443}
2444
2445static HRESULT WINAPI IDirect3DDevice9Impl_DeletePatch(LPDIRECT3DDEVICE9EX iface, UINT Handle) {
2446 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2447 HRESULT hr;
2448
2449 TRACE("iface %p, handle %#x.\n", iface, Handle);
2450
2451 wined3d_mutex_lock();
2452 hr = IWineD3DDevice_DeletePatch(This->WineD3DDevice, Handle);
2453 wined3d_mutex_unlock();
2454
2455 return hr;
2456}
2457
2458static HRESULT WINAPI IDirect3DDevice9Impl_CreateQuery(IDirect3DDevice9Ex *iface,
2459 D3DQUERYTYPE type, IDirect3DQuery9 **query)
2460{
2461 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2462 IDirect3DQuery9Impl *object;
2463 HRESULT hr;
2464
2465 TRACE("iface %p, type %#x, query %p.\n", iface, type, query);
2466
2467 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2468 if (!object)
2469 {
2470 ERR("Failed to allocate query memory.\n");
2471 return E_OUTOFMEMORY;
2472 }
2473
2474 hr = query_init(object, This, type);
2475 if (FAILED(hr))
2476 {
2477 WARN("Failed to initialize query, hr %#x.\n", hr);
2478 HeapFree(GetProcessHeap(), 0, object);
2479 return hr;
2480 }
2481
2482 TRACE("Created query %p.\n", object);
2483 if (query) *query = (IDirect3DQuery9 *)object;
2484 else IDirect3DQuery9_Release((IDirect3DQuery9 *)object);
2485
2486 return D3D_OK;
2487}
2488
2489static HRESULT WINAPI IDirect3DDevice9ExImpl_SetConvolutionMonoKernel(IDirect3DDevice9Ex *iface,
2490 UINT width, UINT height, float *rows, float *columns)
2491{
2492 FIXME("iface %p, width %u, height %u, rows %p, columns %p stub!\n",
2493 iface, width, height, rows, columns);
2494
2495 return WINED3DERR_INVALIDCALL;
2496}
2497
2498static HRESULT WINAPI IDirect3DDevice9ExImpl_ComposeRects(IDirect3DDevice9Ex *iface,
2499 IDirect3DSurface9 *src_surface, IDirect3DSurface9 *dst_surface, IDirect3DVertexBuffer9 *src_descs,
2500 UINT rect_count, IDirect3DVertexBuffer9 *dst_descs, D3DCOMPOSERECTSOP operation, INT offset_x, INT offset_y)
2501{
2502 FIXME("iface %p, src_surface %p, dst_surface %p, src_descs %p, rect_count %u,\n"
2503 "dst_descs %p, operation %#x, offset_x %u, offset_y %u stub!\n",
2504 iface, src_surface, dst_surface, src_descs, rect_count,
2505 dst_descs, operation, offset_x, offset_y);
2506
2507 return WINED3DERR_INVALIDCALL;
2508}
2509
2510static HRESULT WINAPI IDirect3DDevice9ExImpl_PresentEx(IDirect3DDevice9Ex *iface,
2511 const RECT *src_rect, const RECT *dst_rect, HWND dst_window_override,
2512 const RGNDATA *dirty_region, DWORD flags)
2513{
2514 FIXME("iface %p, src_rect %p, dst_rect %p, dst_window_override %p, dirty_region %p, flags %#x stub!\n",
2515 iface, src_rect, dst_rect, dst_window_override, dirty_region, flags);
2516
2517 return WINED3DERR_INVALIDCALL;
2518}
2519
2520static HRESULT WINAPI IDirect3DDevice9ExImpl_GetGPUThreadPriority(IDirect3DDevice9Ex *iface, INT *priority)
2521{
2522 FIXME("iface %p, priority %p stub!\n", iface, priority);
2523
2524 return WINED3DERR_INVALIDCALL;
2525}
2526
2527static HRESULT WINAPI IDirect3DDevice9ExImpl_SetGPUThreadPriority(IDirect3DDevice9Ex *iface, INT priority)
2528{
2529 FIXME("iface %p, priority %d stub!\n", iface, priority);
2530
2531 return WINED3DERR_INVALIDCALL;
2532}
2533
2534static HRESULT WINAPI IDirect3DDevice9ExImpl_WaitForVBlank(IDirect3DDevice9Ex *iface, UINT swapchain_idx)
2535{
2536 FIXME("iface %p, swapchain_idx %u stub!\n", iface, swapchain_idx);
2537
2538 return WINED3DERR_INVALIDCALL;
2539}
2540
2541static HRESULT WINAPI IDirect3DDevice9ExImpl_CheckResourceResidency(IDirect3DDevice9Ex *iface,
2542 IDirect3DResource9 **resources, UINT32 resource_count)
2543{
2544 FIXME("iface %p, resources %p, resource_count %u stub!\n",
2545 iface, resources, resource_count);
2546
2547 return WINED3DERR_INVALIDCALL;
2548}
2549
2550static HRESULT WINAPI IDirect3DDevice9ExImpl_SetMaximumFrameLatency(IDirect3DDevice9Ex *iface, UINT max_latency)
2551{
2552 FIXME("iface %p, max_latency %u stub!\n", iface, max_latency);
2553
2554 return WINED3DERR_INVALIDCALL;
2555}
2556
2557static HRESULT WINAPI IDirect3DDevice9ExImpl_GetMaximumFrameLatency(IDirect3DDevice9Ex *iface, UINT *max_latency)
2558{
2559 FIXME("iface %p, max_latency %p stub!\n", iface, max_latency);
2560
2561 *max_latency = 2;
2562
2563 return WINED3DERR_INVALIDCALL;
2564}
2565
2566static HRESULT WINAPI IDirect3DDevice9ExImpl_CheckDeviceState(IDirect3DDevice9Ex *iface, HWND dst_window)
2567{
2568 FIXME("iface %p, dst_window %p stub!\n", iface, dst_window);
2569
2570 return WINED3DERR_INVALIDCALL;
2571}
2572
2573static HRESULT WINAPI IDirect3DDevice9ExImpl_CreateRenderTargetEx(IDirect3DDevice9Ex *iface,
2574 UINT width, UINT height, D3DFORMAT format, D3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality,
2575 BOOL lockable, IDirect3DSurface9 **surface, HANDLE *shared_handle, DWORD usage)
2576{
2577 FIXME("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u,\n"
2578 "lockable %#x, surface %p, shared_handle %p, usage %#x stub!\n",
2579 iface, width, height, format, multisample_type, multisample_quality,
2580 lockable, surface, shared_handle, usage);
2581
2582 return WINED3DERR_INVALIDCALL;
2583}
2584
2585static HRESULT WINAPI IDirect3DDevice9ExImpl_CreateOffscreenPlainSurfaceEx(IDirect3DDevice9Ex *iface,
2586 UINT width, UINT height, D3DFORMAT format, D3DPOOL pool, IDirect3DSurface9 **surface,
2587 HANDLE *shared_handle, DWORD usage)
2588{
2589 FIXME("iface %p, width %u, height %u, format %#x, pool %#x, surface %p, shared_handle %p, usage %#x stub!\n",
2590 iface, width, height, format, pool, surface, shared_handle, usage);
2591
2592 return WINED3DERR_INVALIDCALL;
2593}
2594
2595static HRESULT WINAPI IDirect3DDevice9ExImpl_CreateDepthStencilSurfaceEx(IDirect3DDevice9Ex *iface,
2596 UINT width, UINT height, D3DFORMAT format, D3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality,
2597 BOOL discard, IDirect3DSurface9 **surface, HANDLE *shared_handle, DWORD usage)
2598{
2599 FIXME("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u,\n"
2600 "discard %#x, surface %p, shared_handle %p, usage %#x stub!\n",
2601 iface, width, height, format, multisample_type, multisample_quality,
2602 discard, surface, shared_handle, usage);
2603
2604 return WINED3DERR_INVALIDCALL;
2605}
2606
2607static HRESULT WINAPI IDirect3DDevice9ExImpl_ResetEx(IDirect3DDevice9Ex *iface,
2608 D3DPRESENT_PARAMETERS *present_parameters, D3DDISPLAYMODEEX *mode)
2609{
2610 FIXME("iface %p, present_parameters %p, mode %p stub!\n", iface, present_parameters, mode);
2611
2612 return WINED3DERR_INVALIDCALL;
2613}
2614
2615static HRESULT WINAPI IDirect3DDevice9ExImpl_GetDisplayModeEx(IDirect3DDevice9Ex *iface,
2616 UINT swapchain_idx, D3DDISPLAYMODEEX *mode, D3DDISPLAYROTATION *rotation)
2617{
2618 FIXME("iface %p, swapchain_idx %u, mode %p, rotation %p stub!\n", iface, swapchain_idx, mode, rotation);
2619
2620 return WINED3DERR_INVALIDCALL;
2621}
2622
2623static const IDirect3DDevice9ExVtbl Direct3DDevice9_Vtbl =
2624{
2625 /* IUnknown */
2626 IDirect3DDevice9Impl_QueryInterface,
2627 IDirect3DDevice9Impl_AddRef,
2628 IDirect3DDevice9Impl_Release,
2629 /* IDirect3DDevice9 */
2630 IDirect3DDevice9Impl_TestCooperativeLevel,
2631 IDirect3DDevice9Impl_GetAvailableTextureMem,
2632 IDirect3DDevice9Impl_EvictManagedResources,
2633 IDirect3DDevice9Impl_GetDirect3D,
2634 IDirect3DDevice9Impl_GetDeviceCaps,
2635 IDirect3DDevice9Impl_GetDisplayMode,
2636 IDirect3DDevice9Impl_GetCreationParameters,
2637 IDirect3DDevice9Impl_SetCursorProperties,
2638 IDirect3DDevice9Impl_SetCursorPosition,
2639 IDirect3DDevice9Impl_ShowCursor,
2640 IDirect3DDevice9Impl_CreateAdditionalSwapChain,
2641 IDirect3DDevice9Impl_GetSwapChain,
2642 IDirect3DDevice9Impl_GetNumberOfSwapChains,
2643 IDirect3DDevice9Impl_Reset,
2644 IDirect3DDevice9Impl_Present,
2645 IDirect3DDevice9Impl_GetBackBuffer,
2646 IDirect3DDevice9Impl_GetRasterStatus,
2647 IDirect3DDevice9Impl_SetDialogBoxMode,
2648 IDirect3DDevice9Impl_SetGammaRamp,
2649 IDirect3DDevice9Impl_GetGammaRamp,
2650 IDirect3DDevice9Impl_CreateTexture,
2651 IDirect3DDevice9Impl_CreateVolumeTexture,
2652 IDirect3DDevice9Impl_CreateCubeTexture,
2653 IDirect3DDevice9Impl_CreateVertexBuffer,
2654 IDirect3DDevice9Impl_CreateIndexBuffer,
2655 IDirect3DDevice9Impl_CreateRenderTarget,
2656 IDirect3DDevice9Impl_CreateDepthStencilSurface,
2657 IDirect3DDevice9Impl_UpdateSurface,
2658 IDirect3DDevice9Impl_UpdateTexture,
2659 IDirect3DDevice9Impl_GetRenderTargetData,
2660 IDirect3DDevice9Impl_GetFrontBufferData,
2661 IDirect3DDevice9Impl_StretchRect,
2662 IDirect3DDevice9Impl_ColorFill,
2663 IDirect3DDevice9Impl_CreateOffscreenPlainSurface,
2664 IDirect3DDevice9Impl_SetRenderTarget,
2665 IDirect3DDevice9Impl_GetRenderTarget,
2666 IDirect3DDevice9Impl_SetDepthStencilSurface,
2667 IDirect3DDevice9Impl_GetDepthStencilSurface,
2668 IDirect3DDevice9Impl_BeginScene,
2669 IDirect3DDevice9Impl_EndScene,
2670 IDirect3DDevice9Impl_Clear,
2671 IDirect3DDevice9Impl_SetTransform,
2672 IDirect3DDevice9Impl_GetTransform,
2673 IDirect3DDevice9Impl_MultiplyTransform,
2674 IDirect3DDevice9Impl_SetViewport,
2675 IDirect3DDevice9Impl_GetViewport,
2676 IDirect3DDevice9Impl_SetMaterial,
2677 IDirect3DDevice9Impl_GetMaterial,
2678 IDirect3DDevice9Impl_SetLight,
2679 IDirect3DDevice9Impl_GetLight,
2680 IDirect3DDevice9Impl_LightEnable,
2681 IDirect3DDevice9Impl_GetLightEnable,
2682 IDirect3DDevice9Impl_SetClipPlane,
2683 IDirect3DDevice9Impl_GetClipPlane,
2684 IDirect3DDevice9Impl_SetRenderState,
2685 IDirect3DDevice9Impl_GetRenderState,
2686 IDirect3DDevice9Impl_CreateStateBlock,
2687 IDirect3DDevice9Impl_BeginStateBlock,
2688 IDirect3DDevice9Impl_EndStateBlock,
2689 IDirect3DDevice9Impl_SetClipStatus,
2690 IDirect3DDevice9Impl_GetClipStatus,
2691 IDirect3DDevice9Impl_GetTexture,
2692 IDirect3DDevice9Impl_SetTexture,
2693 IDirect3DDevice9Impl_GetTextureStageState,
2694 IDirect3DDevice9Impl_SetTextureStageState,
2695 IDirect3DDevice9Impl_GetSamplerState,
2696 IDirect3DDevice9Impl_SetSamplerState,
2697 IDirect3DDevice9Impl_ValidateDevice,
2698 IDirect3DDevice9Impl_SetPaletteEntries,
2699 IDirect3DDevice9Impl_GetPaletteEntries,
2700 IDirect3DDevice9Impl_SetCurrentTexturePalette,
2701 IDirect3DDevice9Impl_GetCurrentTexturePalette,
2702 IDirect3DDevice9Impl_SetScissorRect,
2703 IDirect3DDevice9Impl_GetScissorRect,
2704 IDirect3DDevice9Impl_SetSoftwareVertexProcessing,
2705 IDirect3DDevice9Impl_GetSoftwareVertexProcessing,
2706 IDirect3DDevice9Impl_SetNPatchMode,
2707 IDirect3DDevice9Impl_GetNPatchMode,
2708 IDirect3DDevice9Impl_DrawPrimitive,
2709 IDirect3DDevice9Impl_DrawIndexedPrimitive,
2710 IDirect3DDevice9Impl_DrawPrimitiveUP,
2711 IDirect3DDevice9Impl_DrawIndexedPrimitiveUP,
2712 IDirect3DDevice9Impl_ProcessVertices,
2713 IDirect3DDevice9Impl_CreateVertexDeclaration,
2714 IDirect3DDevice9Impl_SetVertexDeclaration,
2715 IDirect3DDevice9Impl_GetVertexDeclaration,
2716 IDirect3DDevice9Impl_SetFVF,
2717 IDirect3DDevice9Impl_GetFVF,
2718 IDirect3DDevice9Impl_CreateVertexShader,
2719 IDirect3DDevice9Impl_SetVertexShader,
2720 IDirect3DDevice9Impl_GetVertexShader,
2721 IDirect3DDevice9Impl_SetVertexShaderConstantF,
2722 IDirect3DDevice9Impl_GetVertexShaderConstantF,
2723 IDirect3DDevice9Impl_SetVertexShaderConstantI,
2724 IDirect3DDevice9Impl_GetVertexShaderConstantI,
2725 IDirect3DDevice9Impl_SetVertexShaderConstantB,
2726 IDirect3DDevice9Impl_GetVertexShaderConstantB,
2727 IDirect3DDevice9Impl_SetStreamSource,
2728 IDirect3DDevice9Impl_GetStreamSource,
2729 IDirect3DDevice9Impl_SetStreamSourceFreq,
2730 IDirect3DDevice9Impl_GetStreamSourceFreq,
2731 IDirect3DDevice9Impl_SetIndices,
2732 IDirect3DDevice9Impl_GetIndices,
2733 IDirect3DDevice9Impl_CreatePixelShader,
2734 IDirect3DDevice9Impl_SetPixelShader,
2735 IDirect3DDevice9Impl_GetPixelShader,
2736 IDirect3DDevice9Impl_SetPixelShaderConstantF,
2737 IDirect3DDevice9Impl_GetPixelShaderConstantF,
2738 IDirect3DDevice9Impl_SetPixelShaderConstantI,
2739 IDirect3DDevice9Impl_GetPixelShaderConstantI,
2740 IDirect3DDevice9Impl_SetPixelShaderConstantB,
2741 IDirect3DDevice9Impl_GetPixelShaderConstantB,
2742 IDirect3DDevice9Impl_DrawRectPatch,
2743 IDirect3DDevice9Impl_DrawTriPatch,
2744 IDirect3DDevice9Impl_DeletePatch,
2745 IDirect3DDevice9Impl_CreateQuery,
2746 /* IDirect3DDevice9Ex */
2747 IDirect3DDevice9ExImpl_SetConvolutionMonoKernel,
2748 IDirect3DDevice9ExImpl_ComposeRects,
2749 IDirect3DDevice9ExImpl_PresentEx,
2750 IDirect3DDevice9ExImpl_GetGPUThreadPriority,
2751 IDirect3DDevice9ExImpl_SetGPUThreadPriority,
2752 IDirect3DDevice9ExImpl_WaitForVBlank,
2753 IDirect3DDevice9ExImpl_CheckResourceResidency,
2754 IDirect3DDevice9ExImpl_SetMaximumFrameLatency,
2755 IDirect3DDevice9ExImpl_GetMaximumFrameLatency,
2756 IDirect3DDevice9ExImpl_CheckDeviceState,
2757 IDirect3DDevice9ExImpl_CreateRenderTargetEx,
2758 IDirect3DDevice9ExImpl_CreateOffscreenPlainSurfaceEx,
2759 IDirect3DDevice9ExImpl_CreateDepthStencilSurfaceEx,
2760 IDirect3DDevice9ExImpl_ResetEx,
2761 IDirect3DDevice9ExImpl_GetDisplayModeEx
2762};
2763
2764/* IWineD3DDeviceParent IUnknown methods */
2765
2766static inline struct IDirect3DDevice9Impl *device_from_device_parent(IWineD3DDeviceParent *iface)
2767{
2768 return (struct IDirect3DDevice9Impl *)((char*)iface
2769 - FIELD_OFFSET(struct IDirect3DDevice9Impl, device_parent_vtbl));
2770}
2771
2772static HRESULT STDMETHODCALLTYPE device_parent_QueryInterface(IWineD3DDeviceParent *iface, REFIID riid, void **object)
2773{
2774 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
2775 return IDirect3DDevice9Impl_QueryInterface((IDirect3DDevice9Ex *)This, riid, object);
2776}
2777
2778static ULONG STDMETHODCALLTYPE device_parent_AddRef(IWineD3DDeviceParent *iface)
2779{
2780 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
2781 return IDirect3DDevice9Impl_AddRef((IDirect3DDevice9Ex *)This);
2782}
2783
2784static ULONG STDMETHODCALLTYPE device_parent_Release(IWineD3DDeviceParent *iface)
2785{
2786 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
2787 return IDirect3DDevice9Impl_Release((IDirect3DDevice9Ex *)This);
2788}
2789
2790/* IWineD3DDeviceParent methods */
2791
2792static void STDMETHODCALLTYPE device_parent_WineD3DDeviceCreated(IWineD3DDeviceParent *iface, IWineD3DDevice *device)
2793{
2794 TRACE("iface %p, device %p\n", iface, device);
2795}
2796
2797static HRESULT STDMETHODCALLTYPE device_parent_CreateSurface(IWineD3DDeviceParent *iface,
2798 IUnknown *superior, UINT width, UINT height, WINED3DFORMAT format, DWORD usage,
2799 WINED3DPOOL pool, UINT level, WINED3DCUBEMAP_FACES face, IWineD3DSurface **surface
2800#ifdef VBOX_WITH_WDDM
2801 , HANDLE *shared_handle
2802 , void *pvClientMem
2803#endif
2804 )
2805{
2806 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
2807 IDirect3DSurface9Impl *d3d_surface;
2808 BOOL lockable = TRUE;
2809 HRESULT hr;
2810
2811 TRACE("iface %p, superior %p, width %u, height %u, format %#x, usage %#x,\n"
2812 "\tpool %#x, level %u, face %u, surface %p\n",
2813 iface, superior, width, height, format, usage, pool, level, face, surface);
2814
2815 if (pool == WINED3DPOOL_DEFAULT && !(usage & D3DUSAGE_DYNAMIC))
2816 lockable = FALSE;
2817
2818 hr = IDirect3DDevice9Impl_CreateSurface((IDirect3DDevice9Ex *)This, width, height,
2819 d3dformat_from_wined3dformat(format), lockable, FALSE /* Discard */, level,
2820 (IDirect3DSurface9 **)&d3d_surface, usage, pool, D3DMULTISAMPLE_NONE, 0 /* MultisampleQuality */
2821#ifdef VBOX_WITH_WDDM
2822 , shared_handle
2823 , pvClientMem
2824#endif
2825 );
2826 if (FAILED(hr))
2827 {
2828 ERR("(%p) CreateSurface failed, returning %#x\n", iface, hr);
2829 return hr;
2830 }
2831
2832 *surface = d3d_surface->wineD3DSurface;
2833 IWineD3DSurface_AddRef(*surface);
2834
2835 d3d_surface->container = superior;
2836 IDirect3DDevice9Ex_Release(d3d_surface->parentDevice);
2837 d3d_surface->parentDevice = NULL;
2838
2839 IDirect3DSurface9_Release((IDirect3DSurface9 *)d3d_surface);
2840 d3d_surface->forwardReference = superior;
2841
2842 return hr;
2843}
2844
2845static HRESULT STDMETHODCALLTYPE device_parent_CreateRenderTarget(IWineD3DDeviceParent *iface,
2846 IUnknown *superior, UINT width, UINT height, WINED3DFORMAT format, WINED3DMULTISAMPLE_TYPE multisample_type,
2847 DWORD multisample_quality, BOOL lockable, IWineD3DSurface **surface)
2848{
2849 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
2850 IDirect3DSurface9Impl *d3d_surface;
2851 HRESULT hr;
2852
2853 TRACE("iface %p, superior %p, width %u, height %u, format %#x, multisample_type %#x,\n"
2854 "\tmultisample_quality %u, lockable %u, surface %p\n",
2855 iface, superior, width, height, format, multisample_type, multisample_quality, lockable, surface);
2856
2857 hr = IDirect3DDevice9Impl_CreateRenderTarget((IDirect3DDevice9Ex *)This, width, height,
2858 d3dformat_from_wined3dformat(format), multisample_type, multisample_quality, lockable,
2859 (IDirect3DSurface9 **)&d3d_surface, NULL);
2860 if (FAILED(hr))
2861 {
2862 ERR("(%p) CreateRenderTarget failed, returning %#x\n", iface, hr);
2863 return hr;
2864 }
2865
2866 *surface = d3d_surface->wineD3DSurface;
2867 IWineD3DSurface_AddRef(*surface);
2868
2869 d3d_surface->container = superior;
2870 /* Implicit surfaces are created with an refcount of 0 */
2871 IDirect3DSurface9_Release((IDirect3DSurface9 *)d3d_surface);
2872
2873 return hr;
2874}
2875
2876static HRESULT STDMETHODCALLTYPE device_parent_CreateDepthStencilSurface(IWineD3DDeviceParent *iface,
2877 IUnknown *superior, UINT width, UINT height, WINED3DFORMAT format, WINED3DMULTISAMPLE_TYPE multisample_type,
2878 DWORD multisample_quality, BOOL discard, IWineD3DSurface **surface)
2879{
2880 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
2881 IDirect3DSurface9Impl *d3d_surface;
2882 HRESULT hr;
2883
2884 TRACE("iface %p, superior %p, width %u, height %u, format %#x, multisample_type %#x,\n"
2885 "\tmultisample_quality %u, discard %u, surface %p\n",
2886 iface, superior, width, height, format, multisample_type, multisample_quality, discard, surface);
2887
2888 hr = IDirect3DDevice9Impl_CreateDepthStencilSurface((IDirect3DDevice9Ex *)This, width, height,
2889 d3dformat_from_wined3dformat(format), multisample_type, multisample_quality, discard,
2890 (IDirect3DSurface9 **)&d3d_surface, NULL);
2891 if (FAILED(hr))
2892 {
2893 ERR("(%p) CreateDepthStencilSurface failed, returning %#x\n", iface, hr);
2894 return hr;
2895 }
2896
2897 *surface = d3d_surface->wineD3DSurface;
2898 IWineD3DSurface_AddRef(*surface);
2899 d3d_surface->container = (IUnknown *)This;
2900 /* Implicit surfaces are created with an refcount of 0 */
2901 IDirect3DSurface9_Release((IDirect3DSurface9 *)d3d_surface);
2902
2903 return hr;
2904}
2905
2906static HRESULT STDMETHODCALLTYPE device_parent_CreateVolume(IWineD3DDeviceParent *iface,
2907 IUnknown *superior, UINT width, UINT height, UINT depth, WINED3DFORMAT format,
2908 WINED3DPOOL pool, DWORD usage, IWineD3DVolume **volume)
2909{
2910 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
2911 IDirect3DVolume9Impl *object;
2912 HRESULT hr;
2913
2914 TRACE("iface %p, superior %p, width %u, height %u, depth %u, format %#x, pool %#x, usage %#x, volume %p\n",
2915 iface, superior, width, height, depth, format, pool, usage, volume);
2916
2917 /* Allocate the storage for the device */
2918 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2919 if (!object)
2920 {
2921 FIXME("Allocation of memory failed\n");
2922 *volume = NULL;
2923 return D3DERR_OUTOFVIDEOMEMORY;
2924 }
2925
2926 hr = volume_init(object, This, width, height, depth, usage, format, pool);
2927 if (FAILED(hr))
2928 {
2929 WARN("Failed to initialize volume, hr %#x.\n", hr);
2930 HeapFree(GetProcessHeap(), 0, object);
2931 return hr;
2932 }
2933
2934 *volume = object->wineD3DVolume;
2935 IWineD3DVolume_AddRef(*volume);
2936 IDirect3DVolume9_Release((IDirect3DVolume9 *)object);
2937
2938 object->container = superior;
2939 object->forwardReference = superior;
2940
2941 TRACE("(%p) Created volume %p\n", iface, object);
2942
2943 return hr;
2944}
2945
2946static HRESULT STDMETHODCALLTYPE device_parent_CreateSwapChain(IWineD3DDeviceParent *iface,
2947 WINED3DPRESENT_PARAMETERS *present_parameters, IWineD3DSwapChain **swapchain)
2948{
2949 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
2950 IDirect3DSwapChain9Impl *d3d_swapchain;
2951 D3DPRESENT_PARAMETERS local_parameters;
2952 HRESULT hr;
2953
2954 TRACE("iface %p, present_parameters %p, swapchain %p\n", iface, present_parameters, swapchain);
2955
2956 /* Copy the presentation parameters */
2957 local_parameters.BackBufferWidth = present_parameters->BackBufferWidth;
2958 local_parameters.BackBufferHeight = present_parameters->BackBufferHeight;
2959 local_parameters.BackBufferFormat = d3dformat_from_wined3dformat(present_parameters->BackBufferFormat);
2960 local_parameters.BackBufferCount = present_parameters->BackBufferCount;
2961 local_parameters.MultiSampleType = present_parameters->MultiSampleType;
2962 local_parameters.MultiSampleQuality = present_parameters->MultiSampleQuality;
2963 local_parameters.SwapEffect = present_parameters->SwapEffect;
2964 local_parameters.hDeviceWindow = present_parameters->hDeviceWindow;
2965 local_parameters.Windowed = present_parameters->Windowed;
2966 local_parameters.EnableAutoDepthStencil = present_parameters->EnableAutoDepthStencil;
2967 local_parameters.AutoDepthStencilFormat = d3dformat_from_wined3dformat(present_parameters->AutoDepthStencilFormat);
2968 local_parameters.Flags = present_parameters->Flags;
2969 local_parameters.FullScreen_RefreshRateInHz = present_parameters->FullScreen_RefreshRateInHz;
2970 local_parameters.PresentationInterval = present_parameters->PresentationInterval;
2971
2972#ifdef VBOX_WITH_WDDM
2973 hr = IDirect3DDevice9Impl_DoCreateAdditionalSwapChain((IDirect3DDevice9Ex *)This,
2974 &local_parameters, (IDirect3DSwapChain9 **)&d3d_swapchain);
2975#else
2976 hr = IDirect3DDevice9Impl_CreateAdditionalSwapChain((IDirect3DDevice9Ex *)This,
2977 &local_parameters, (IDirect3DSwapChain9 **)&d3d_swapchain);
2978#endif
2979 if (FAILED(hr))
2980 {
2981 ERR("(%p) CreateAdditionalSwapChain failed, returning %#x\n", iface, hr);
2982 *swapchain = NULL;
2983 return hr;
2984 }
2985
2986 *swapchain = d3d_swapchain->wineD3DSwapChain;
2987 d3d_swapchain->isImplicit = TRUE;
2988 /* Implicit swap chains are created with an refcount of 0 */
2989 IDirect3DSwapChain9_Release((IDirect3DSwapChain9 *)d3d_swapchain);
2990
2991 /* Copy back the presentation parameters */
2992 present_parameters->BackBufferWidth = local_parameters.BackBufferWidth;
2993 present_parameters->BackBufferHeight = local_parameters.BackBufferHeight;
2994 present_parameters->BackBufferFormat = wined3dformat_from_d3dformat(local_parameters.BackBufferFormat);
2995 present_parameters->BackBufferCount = local_parameters.BackBufferCount;
2996 present_parameters->MultiSampleType = local_parameters.MultiSampleType;
2997 present_parameters->MultiSampleQuality = local_parameters.MultiSampleQuality;
2998 present_parameters->SwapEffect = local_parameters.SwapEffect;
2999 present_parameters->hDeviceWindow = local_parameters.hDeviceWindow;
3000 present_parameters->Windowed = local_parameters.Windowed;
3001 present_parameters->EnableAutoDepthStencil = local_parameters.EnableAutoDepthStencil;
3002 present_parameters->AutoDepthStencilFormat = wined3dformat_from_d3dformat(local_parameters.AutoDepthStencilFormat);
3003 present_parameters->Flags = local_parameters.Flags;
3004 present_parameters->FullScreen_RefreshRateInHz = local_parameters.FullScreen_RefreshRateInHz;
3005 present_parameters->PresentationInterval = local_parameters.PresentationInterval;
3006
3007 return hr;
3008}
3009
3010static const IWineD3DDeviceParentVtbl d3d9_wined3d_device_parent_vtbl =
3011{
3012 /* IUnknown methods */
3013 device_parent_QueryInterface,
3014 device_parent_AddRef,
3015 device_parent_Release,
3016 /* IWineD3DDeviceParent methods */
3017 device_parent_WineD3DDeviceCreated,
3018 device_parent_CreateSurface,
3019 device_parent_CreateRenderTarget,
3020 device_parent_CreateDepthStencilSurface,
3021 device_parent_CreateVolume,
3022 device_parent_CreateSwapChain,
3023};
3024
3025HRESULT device_init(IDirect3DDevice9Impl *device, IWineD3D *wined3d, UINT adapter, D3DDEVTYPE device_type,
3026 HWND focus_window, DWORD flags, D3DPRESENT_PARAMETERS *parameters)
3027{
3028 WINED3DPRESENT_PARAMETERS *wined3d_parameters;
3029 UINT i, count = 1;
3030 HRESULT hr;
3031
3032 device->lpVtbl = &Direct3DDevice9_Vtbl;
3033 device->device_parent_vtbl = &d3d9_wined3d_device_parent_vtbl;
3034 device->ref = 1;
3035
3036 wined3d_mutex_lock();
3037 hr = IWineD3D_CreateDevice(wined3d, adapter, device_type, focus_window, flags, (IUnknown *)device,
3038 (IWineD3DDeviceParent *)&device->device_parent_vtbl, &device->WineD3DDevice);
3039 if (FAILED(hr))
3040 {
3041 WARN("Failed to create wined3d device, hr %#x.\n", hr);
3042 wined3d_mutex_unlock();
3043 return hr;
3044 }
3045
3046 if (!parameters->Windowed)
3047 {
3048 if (!focus_window) focus_window = parameters->hDeviceWindow;
3049 if (FAILED(hr = IWineD3DDevice_AcquireFocusWindow(device->WineD3DDevice, focus_window)))
3050 {
3051 ERR("Failed to acquire focus window, hr %#x.\n", hr);
3052 IWineD3DDevice_Release(device->WineD3DDevice);
3053 wined3d_mutex_unlock();
3054 return hr;
3055 }
3056 }
3057
3058 if (flags & D3DCREATE_ADAPTERGROUP_DEVICE)
3059 {
3060 WINED3DCAPS caps;
3061
3062 IWineD3D_GetDeviceCaps(wined3d, adapter, device_type, &caps);
3063 count = caps.NumberOfAdaptersInGroup;
3064 }
3065
3066 if (flags & D3DCREATE_MULTITHREADED) IWineD3DDevice_SetMultithreaded(device->WineD3DDevice);
3067
3068 wined3d_parameters = HeapAlloc(GetProcessHeap(), 0, sizeof(*wined3d_parameters) * count);
3069 if (!wined3d_parameters)
3070 {
3071 ERR("Failed to allocate wined3d parameters.\n");
3072 IWineD3DDevice_Release(device->WineD3DDevice);
3073 wined3d_mutex_unlock();
3074 return E_OUTOFMEMORY;
3075 }
3076
3077 for (i = 0; i < count; ++i)
3078 {
3079 wined3d_parameters[i].BackBufferWidth = parameters[i].BackBufferWidth;
3080 wined3d_parameters[i].BackBufferHeight = parameters[i].BackBufferHeight;
3081 wined3d_parameters[i].BackBufferFormat = wined3dformat_from_d3dformat(parameters[i].BackBufferFormat);
3082 wined3d_parameters[i].BackBufferCount = parameters[i].BackBufferCount;
3083 wined3d_parameters[i].MultiSampleType = parameters[i].MultiSampleType;
3084 wined3d_parameters[i].MultiSampleQuality = parameters[i].MultiSampleQuality;
3085 wined3d_parameters[i].SwapEffect = parameters[i].SwapEffect;
3086 wined3d_parameters[i].hDeviceWindow = parameters[i].hDeviceWindow;
3087 wined3d_parameters[i].Windowed = parameters[i].Windowed;
3088 wined3d_parameters[i].EnableAutoDepthStencil = parameters[i].EnableAutoDepthStencil;
3089 wined3d_parameters[i].AutoDepthStencilFormat =
3090 wined3dformat_from_d3dformat(parameters[i].AutoDepthStencilFormat);
3091 wined3d_parameters[i].Flags = parameters[i].Flags;
3092 wined3d_parameters[i].FullScreen_RefreshRateInHz = parameters[i].FullScreen_RefreshRateInHz;
3093 wined3d_parameters[i].PresentationInterval = parameters[i].PresentationInterval;
3094 wined3d_parameters[i].AutoRestoreDisplayMode = TRUE;
3095 }
3096
3097 hr = IWineD3DDevice_Init3D(device->WineD3DDevice, wined3d_parameters);
3098 if (FAILED(hr))
3099 {
3100 WARN("Failed to initialize 3D, hr %#x.\n", hr);
3101 IWineD3DDevice_ReleaseFocusWindow(device->WineD3DDevice);
3102 HeapFree(GetProcessHeap(), 0, wined3d_parameters);
3103 IWineD3DDevice_Release(device->WineD3DDevice);
3104 wined3d_mutex_unlock();
3105 return hr;
3106 }
3107
3108 wined3d_mutex_unlock();
3109
3110 for (i = 0; i < count; ++i)
3111 {
3112 parameters[i].BackBufferWidth = wined3d_parameters[i].BackBufferWidth;
3113 parameters[i].BackBufferHeight = wined3d_parameters[i].BackBufferHeight;
3114 parameters[i].BackBufferFormat = d3dformat_from_wined3dformat(wined3d_parameters[i].BackBufferFormat);
3115 parameters[i].BackBufferCount = wined3d_parameters[i].BackBufferCount;
3116 parameters[i].MultiSampleType = wined3d_parameters[i].MultiSampleType;
3117 parameters[i].MultiSampleQuality = wined3d_parameters[i].MultiSampleQuality;
3118 parameters[i].SwapEffect = wined3d_parameters[i].SwapEffect;
3119 parameters[i].hDeviceWindow = wined3d_parameters[i].hDeviceWindow;
3120 parameters[i].Windowed = wined3d_parameters[i].Windowed;
3121 parameters[i].EnableAutoDepthStencil = wined3d_parameters[i].EnableAutoDepthStencil;
3122 parameters[i].AutoDepthStencilFormat =
3123 d3dformat_from_wined3dformat(wined3d_parameters[i].AutoDepthStencilFormat);
3124 parameters[i].Flags = wined3d_parameters[i].Flags;
3125 parameters[i].FullScreen_RefreshRateInHz = wined3d_parameters[i].FullScreen_RefreshRateInHz;
3126 parameters[i].PresentationInterval = wined3d_parameters[i].PresentationInterval;
3127 }
3128 HeapFree(GetProcessHeap(), 0, wined3d_parameters);
3129
3130 /* Initialize the converted declaration array. This creates a valid pointer
3131 * and when adding decls HeapReAlloc() can be used without further checking. */
3132 device->convertedDecls = HeapAlloc(GetProcessHeap(), 0, 0);
3133 if (!device->convertedDecls)
3134 {
3135 ERR("Failed to allocate FVF vertex declaration map memory.\n");
3136 wined3d_mutex_lock();
3137 IWineD3DDevice_Uninit3D(device->WineD3DDevice, D3D9CB_DestroySwapChain);
3138 IWineD3DDevice_ReleaseFocusWindow(device->WineD3DDevice);
3139 IWineD3DDevice_Release(device->WineD3DDevice);
3140 wined3d_mutex_unlock();
3141 return E_OUTOFMEMORY;
3142 }
3143
3144 return D3D_OK;
3145}
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette