VirtualBox

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

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

wddm/3d: wine multi-swapchain fixes

  • Property svn:eol-style set to native
File size: 116.1 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 * Sun 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, Sun 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 VBOXWDDM
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 VBOXWDDM
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 VBOXWDDM
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 *pvClientMem) /* <- 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 , pvClientMem
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
811#endif
812
813static HRESULT WINAPI IDirect3DDevice9Impl_CreateTexture(IDirect3DDevice9Ex *iface,
814 UINT width, UINT height, UINT levels, DWORD usage, D3DFORMAT format,
815 D3DPOOL pool, IDirect3DTexture9 **texture, HANDLE *shared_handle)
816{
817#ifdef VBOXWDDM
818 return VBoxWineExD3DDev9CreateTexture(iface, width, height, levels, usage, format,
819 pool, texture, shared_handle, NULL);
820#else
821 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
822 IDirect3DTexture9Impl *object;
823 HRESULT hr;
824
825 TRACE("iface %p, width %u, height %u, levels %u, usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n",
826 iface, width, height, levels, usage, format, pool, texture, shared_handle);
827
828 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
829 if (!object)
830 {
831 ERR("Failed to allocate texture memory.\n");
832 return D3DERR_OUTOFVIDEOMEMORY;
833 }
834
835 hr = texture_init(object, This, width, height, levels, usage, format, pool);
836 if (FAILED(hr))
837 {
838 WARN("Failed to initialize texture, hr %#x.\n", hr);
839 HeapFree(GetProcessHeap(), 0, object);
840 return hr;
841 }
842
843 TRACE("Created texture %p.\n", object);
844 *texture = (IDirect3DTexture9 *)object;
845
846 return D3D_OK;
847#endif
848}
849
850static HRESULT WINAPI IDirect3DDevice9Impl_CreateVolumeTexture(IDirect3DDevice9Ex *iface,
851 UINT width, UINT height, UINT depth, UINT levels, DWORD usage, D3DFORMAT format,
852 D3DPOOL pool, IDirect3DVolumeTexture9 **texture, HANDLE *shared_handle)
853{
854 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
855 IDirect3DVolumeTexture9Impl *object;
856 HRESULT hr;
857
858 TRACE("iface %p, width %u, height %u, depth %u, levels %u\n",
859 iface, width, height, depth, levels);
860 TRACE("usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n",
861 usage, format, pool, texture, shared_handle);
862
863 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
864 if (!object)
865 {
866 ERR("Failed to allocate volume texture memory.\n");
867 return D3DERR_OUTOFVIDEOMEMORY;
868 }
869
870 hr = volumetexture_init(object, This, width, height, depth, levels, usage, format, pool);
871 if (FAILED(hr))
872 {
873 WARN("Failed to initialize volume texture, hr %#x.\n", hr);
874 HeapFree(GetProcessHeap(), 0, object);
875 return hr;
876 }
877
878 TRACE("Created volume texture %p.\n", object);
879 *texture = (IDirect3DVolumeTexture9 *)object;
880
881 return D3D_OK;
882}
883
884static HRESULT WINAPI IDirect3DDevice9Impl_CreateCubeTexture(IDirect3DDevice9Ex *iface,
885 UINT edge_length, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool,
886 IDirect3DCubeTexture9 **texture, HANDLE *shared_handle)
887{
888 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
889 IDirect3DCubeTexture9Impl *object;
890 HRESULT hr;
891
892 TRACE("iface %p, edge_length %u, levels %u, usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n",
893 iface, edge_length, levels, usage, format, pool, texture, shared_handle);
894
895 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
896 if (!object)
897 {
898 ERR("Failed to allocate cube texture memory.\n");
899 return D3DERR_OUTOFVIDEOMEMORY;
900 }
901
902 hr = cubetexture_init(object, This, edge_length, levels, usage, format, pool);
903 if (FAILED(hr))
904 {
905 WARN("Failed to initialize cube texture, hr %#x.\n", hr);
906 HeapFree(GetProcessHeap(), 0, object);
907 return hr;
908 }
909
910 TRACE("Created cube texture %p.\n", object);
911 *texture = (IDirect3DCubeTexture9 *)object;
912
913 return D3D_OK;
914}
915
916static HRESULT WINAPI IDirect3DDevice9Impl_CreateVertexBuffer(IDirect3DDevice9Ex *iface, UINT size, DWORD usage,
917 DWORD fvf, D3DPOOL pool, IDirect3DVertexBuffer9 **buffer, HANDLE *shared_handle)
918{
919 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
920 IDirect3DVertexBuffer9Impl *object;
921 HRESULT hr;
922
923 TRACE("iface %p, size %u, usage %#x, fvf %#x, pool %#x, buffer %p, shared_handle %p.\n",
924 iface, size, usage, fvf, pool, buffer, shared_handle);
925
926 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
927 if (!object)
928 {
929 ERR("Failed to allocate buffer memory.\n");
930 return D3DERR_OUTOFVIDEOMEMORY;
931 }
932
933 hr = vertexbuffer_init(object, This, size, usage, fvf, pool);
934 if (FAILED(hr))
935 {
936 WARN("Failed to initialize vertex buffer, hr %#x.\n", hr);
937 HeapFree(GetProcessHeap(), 0, object);
938 return hr;
939 }
940
941 TRACE("Created vertex buffer %p.\n", object);
942 *buffer = (IDirect3DVertexBuffer9 *)object;
943
944 return D3D_OK;
945}
946
947static HRESULT WINAPI IDirect3DDevice9Impl_CreateIndexBuffer(IDirect3DDevice9Ex *iface, UINT size, DWORD usage,
948 D3DFORMAT format, D3DPOOL pool, IDirect3DIndexBuffer9 **buffer, HANDLE *shared_handle)
949{
950 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
951 IDirect3DIndexBuffer9Impl *object;
952 HRESULT hr;
953
954 TRACE("iface %p, size %u, usage %#x, format %#x, pool %#x, buffer %p, shared_handle %p.\n",
955 iface, size, usage, format, pool, buffer, shared_handle);
956
957 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
958 if (!object)
959 {
960 ERR("Failed to allocate buffer memory.\n");
961 return D3DERR_OUTOFVIDEOMEMORY;
962 }
963
964 hr = indexbuffer_init(object, This, size, usage, format, pool);
965 if (FAILED(hr))
966 {
967 WARN("Failed to initialize index buffer, hr %#x.\n", hr);
968 HeapFree(GetProcessHeap(), 0, object);
969 return hr;
970 }
971
972 TRACE("Created index buffer %p.\n", object);
973 *buffer = (IDirect3DIndexBuffer9 *)object;
974
975 return D3D_OK;
976}
977
978static HRESULT IDirect3DDevice9Impl_CreateSurface(LPDIRECT3DDEVICE9EX iface, UINT Width, UINT Height,
979 D3DFORMAT Format, BOOL Lockable, BOOL Discard, UINT Level, IDirect3DSurface9 **ppSurface,
980 UINT Usage, D3DPOOL Pool, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality
981#ifdef VBOXWDDM
982 , HANDLE *shared_handle
983 , void *pvClientMem
984#endif
985 )
986{
987 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
988 IDirect3DSurface9Impl *object;
989 HRESULT hr;
990
991 TRACE("iface %p, width %u, height %u, format %#x, lockable %#x, discard %#x, level %u, surface %p.\n"
992 "usage %#x, pool %#x, multisample_type %#x, multisample_quality %u.\n",
993 iface, Width, Height, Format, Lockable, Discard, Level, ppSurface,
994 Usage, Pool, MultiSample, MultisampleQuality);
995
996 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DSurface9Impl));
997 if (!object)
998 {
999 FIXME("Failed to allocate surface memory.\n");
1000 return D3DERR_OUTOFVIDEOMEMORY;
1001 }
1002
1003 hr = surface_init(object, This, Width, Height, Format, Lockable, Discard,
1004 Level, Usage, Pool, MultiSample, MultisampleQuality
1005#ifdef VBOXWDDM
1006 , shared_handle
1007 , pvClientMem
1008#endif
1009 );
1010 if (FAILED(hr))
1011 {
1012 WARN("Failed to initialize surface, hr %#x.\n", hr);
1013 HeapFree(GetProcessHeap(), 0, object);
1014 return hr;
1015 }
1016
1017 TRACE("Created surface %p.\n", object);
1018 *ppSurface = (IDirect3DSurface9 *)object;
1019
1020 return D3D_OK;
1021}
1022
1023static HRESULT WINAPI IDirect3DDevice9Impl_CreateRenderTarget(IDirect3DDevice9Ex *iface, UINT Width, UINT Height,
1024 D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality, BOOL Lockable,
1025 IDirect3DSurface9 **ppSurface, HANDLE *pSharedHandle)
1026{
1027 HRESULT hr;
1028
1029 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u.\n"
1030 "lockable %#x, surface %p, shared_handle %p.\n",
1031 iface, Width, Height, Format, MultiSample, MultisampleQuality,
1032 Lockable, ppSurface, pSharedHandle);
1033
1034 hr = IDirect3DDevice9Impl_CreateSurface(iface, Width, Height, Format, Lockable, FALSE /* Discard */,
1035 0 /* Level */, ppSurface, D3DUSAGE_RENDERTARGET, D3DPOOL_DEFAULT, MultiSample, MultisampleQuality
1036#ifdef VBOXWDDM
1037 , pSharedHandle
1038 , NULL
1039#endif
1040 );
1041
1042 return hr;
1043}
1044
1045static HRESULT WINAPI IDirect3DDevice9Impl_CreateDepthStencilSurface(LPDIRECT3DDEVICE9EX iface, UINT Width, UINT Height,
1046 D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample,
1047 DWORD MultisampleQuality, BOOL Discard,
1048 IDirect3DSurface9 **ppSurface, HANDLE* pSharedHandle) {
1049 HRESULT hr;
1050
1051 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u.\n"
1052 "discard %#x, surface %p, shared_handle %p.\n",
1053 iface, Width, Height, Format, MultiSample, MultisampleQuality,
1054 Discard, ppSurface, pSharedHandle);
1055
1056 hr = IDirect3DDevice9Impl_CreateSurface(iface, Width, Height, Format, TRUE /* Lockable */, Discard,
1057 0 /* Level */, ppSurface, D3DUSAGE_DEPTHSTENCIL, D3DPOOL_DEFAULT, MultiSample, MultisampleQuality
1058#ifdef VBOXWDDM
1059 , pSharedHandle
1060 , NULL
1061#endif
1062 );
1063
1064 return hr;
1065}
1066
1067
1068static HRESULT WINAPI IDirect3DDevice9Impl_UpdateSurface(LPDIRECT3DDEVICE9EX iface, IDirect3DSurface9* pSourceSurface, CONST RECT* pSourceRect, IDirect3DSurface9* pDestinationSurface, CONST POINT* pDestPoint) {
1069 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1070 HRESULT hr;
1071
1072 TRACE("iface %p, src_surface %p, src_rect %p, dst_surface %p, dst_point %p.\n",
1073 iface, pSourceSurface, pSourceRect, pDestinationSurface, pDestPoint);
1074
1075 wined3d_mutex_lock();
1076 hr = IWineD3DDevice_UpdateSurface(This->WineD3DDevice, ((IDirect3DSurface9Impl *)pSourceSurface)->wineD3DSurface, pSourceRect, ((IDirect3DSurface9Impl *)pDestinationSurface)->wineD3DSurface, pDestPoint);
1077 wined3d_mutex_unlock();
1078
1079 return hr;
1080}
1081
1082static HRESULT WINAPI IDirect3DDevice9Impl_UpdateTexture(LPDIRECT3DDEVICE9EX iface, IDirect3DBaseTexture9* pSourceTexture, IDirect3DBaseTexture9* pDestinationTexture) {
1083 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1084 HRESULT hr;
1085
1086 TRACE("iface %p, src_texture %p, dst_texture %p.\n", iface, pSourceTexture, pDestinationTexture);
1087
1088 wined3d_mutex_lock();
1089 hr = IWineD3DDevice_UpdateTexture(This->WineD3DDevice, ((IDirect3DBaseTexture9Impl *)pSourceTexture)->wineD3DBaseTexture, ((IDirect3DBaseTexture9Impl *)pDestinationTexture)->wineD3DBaseTexture);
1090 wined3d_mutex_unlock();
1091
1092 return hr;
1093}
1094
1095static HRESULT WINAPI IDirect3DDevice9Impl_GetRenderTargetData(IDirect3DDevice9Ex *iface,
1096 IDirect3DSurface9 *pRenderTarget, IDirect3DSurface9 *pDestSurface)
1097{
1098 IDirect3DSurface9Impl *renderTarget = (IDirect3DSurface9Impl *)pRenderTarget;
1099 IDirect3DSurface9Impl *destSurface = (IDirect3DSurface9Impl *)pDestSurface;
1100 HRESULT hr;
1101
1102 TRACE("iface %p, render_target %p, dst_surface %p.\n", iface, pRenderTarget, pDestSurface);
1103
1104 wined3d_mutex_lock();
1105 hr = IWineD3DSurface_BltFast(destSurface->wineD3DSurface, 0, 0, renderTarget->wineD3DSurface, NULL, WINEDDBLTFAST_NOCOLORKEY);
1106 wined3d_mutex_unlock();
1107
1108 return hr;
1109}
1110
1111static HRESULT WINAPI IDirect3DDevice9Impl_GetFrontBufferData(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain, IDirect3DSurface9* pDestSurface) {
1112 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1113 IDirect3DSurface9Impl *destSurface = (IDirect3DSurface9Impl *)pDestSurface;
1114 HRESULT hr;
1115
1116 TRACE("iface %p, swapchain %u, dst_surface %p.\n", iface, iSwapChain, pDestSurface);
1117
1118 wined3d_mutex_lock();
1119 hr = IWineD3DDevice_GetFrontBufferData(This->WineD3DDevice, iSwapChain, destSurface->wineD3DSurface);
1120 wined3d_mutex_unlock();
1121
1122 return hr;
1123}
1124
1125static HRESULT WINAPI IDirect3DDevice9Impl_StretchRect(IDirect3DDevice9Ex *iface, IDirect3DSurface9 *pSourceSurface,
1126 const RECT *pSourceRect, IDirect3DSurface9 *pDestSurface, const RECT *pDestRect, D3DTEXTUREFILTERTYPE Filter)
1127{
1128 IDirect3DSurface9Impl *src = (IDirect3DSurface9Impl *) pSourceSurface;
1129 IDirect3DSurface9Impl *dst = (IDirect3DSurface9Impl *) pDestSurface;
1130 HRESULT hr;
1131
1132 TRACE("iface %p, src_surface %p, src_rect %p, dst_surface %p, dst_rect %p, filter %#x.\n",
1133 iface, pSourceSurface, pSourceRect, pDestSurface, pDestRect, Filter);
1134
1135 wined3d_mutex_lock();
1136 hr = IWineD3DSurface_Blt(dst->wineD3DSurface, pDestRect, src->wineD3DSurface, pSourceRect, 0, NULL, Filter);
1137 wined3d_mutex_unlock();
1138
1139 return hr;
1140}
1141
1142static HRESULT WINAPI IDirect3DDevice9Impl_ColorFill(LPDIRECT3DDEVICE9EX iface, IDirect3DSurface9* pSurface, CONST RECT* pRect, D3DCOLOR color) {
1143 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1144 IDirect3DSurface9Impl *surface = (IDirect3DSurface9Impl *)pSurface;
1145 WINED3DPOOL pool;
1146 WINED3DRESOURCETYPE restype;
1147 DWORD usage;
1148 WINED3DSURFACE_DESC desc;
1149 HRESULT hr;
1150
1151 TRACE("iface %p, surface %p, rect %p, color 0x%08x.\n", iface, pSurface, pRect, color);
1152
1153 wined3d_mutex_lock();
1154
1155 IWineD3DSurface_GetDesc(surface->wineD3DSurface, &desc);
1156 usage = desc.usage;
1157 pool = desc.pool;
1158 restype = desc.resource_type;
1159
1160 /* This method is only allowed with surfaces that are render targets, or offscreen plain surfaces
1161 * in D3DPOOL_DEFAULT
1162 */
1163 if(!(usage & WINED3DUSAGE_RENDERTARGET) && (pool != WINED3DPOOL_DEFAULT || restype != WINED3DRTYPE_SURFACE)) {
1164 wined3d_mutex_unlock();
1165 WARN("Surface is not a render target, or not a stand-alone D3DPOOL_DEFAULT surface\n");
1166 return D3DERR_INVALIDCALL;
1167 }
1168
1169 /* Colorfill can only be used on rendertarget surfaces, or offscreen plain surfaces in D3DPOOL_DEFAULT */
1170 /* Note: D3DRECT is compatible with WINED3DRECT */
1171 hr = IWineD3DDevice_ColorFill(This->WineD3DDevice, surface->wineD3DSurface, (CONST WINED3DRECT*)pRect, color);
1172
1173 wined3d_mutex_unlock();
1174
1175 return hr;
1176}
1177
1178static HRESULT WINAPI IDirect3DDevice9Impl_CreateOffscreenPlainSurface(LPDIRECT3DDEVICE9EX iface, UINT Width, UINT Height, D3DFORMAT Format, D3DPOOL Pool, IDirect3DSurface9 **ppSurface, HANDLE* pSharedHandle) {
1179 HRESULT hr;
1180
1181 TRACE("iface %p, width %u, height %u, format %#x, pool %#x, surface %p, shared_handle %p.\n",
1182 iface, Width, Height, Format, Pool, ppSurface, pSharedHandle);
1183
1184 if(Pool == D3DPOOL_MANAGED ){
1185 FIXME("Attempting to create a managed offscreen plain surface\n");
1186 return D3DERR_INVALIDCALL;
1187 }
1188 /*
1189 'Off-screen plain surfaces are always lockable, regardless of their pool types.'
1190 but then...
1191 D3DPOOL_DEFAULT is the appropriate pool for use with the IDirect3DDevice9::StretchRect and IDirect3DDevice9::ColorFill.
1192 Why, their always lockable?
1193 should I change the usage to dynamic?
1194 */
1195 hr = IDirect3DDevice9Impl_CreateSurface(iface, Width, Height, Format, TRUE /* Lockable */, FALSE /* Discard */,
1196 0 /* Level */, ppSurface, 0 /* Usage (undefined/none) */, (WINED3DPOOL)Pool, D3DMULTISAMPLE_NONE,
1197 0 /* MultisampleQuality */
1198#ifdef VBOXWDDM
1199 , pSharedHandle
1200 , NULL
1201#endif
1202 );
1203
1204 return hr;
1205}
1206
1207/* TODO: move to wineD3D */
1208static HRESULT WINAPI IDirect3DDevice9Impl_SetRenderTarget(LPDIRECT3DDEVICE9EX iface, DWORD RenderTargetIndex, IDirect3DSurface9* pRenderTarget) {
1209 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1210 IDirect3DSurface9Impl *pSurface = (IDirect3DSurface9Impl*)pRenderTarget;
1211 HRESULT hr;
1212
1213 TRACE("iface %p, idx %u, surface %p.\n", iface, RenderTargetIndex, pRenderTarget);
1214
1215 if (RenderTargetIndex >= D3D9_MAX_SIMULTANEOUS_RENDERTARGETS)
1216 {
1217 WARN("Invalid index %u specified.\n", RenderTargetIndex);
1218 return D3DERR_INVALIDCALL;
1219 }
1220
1221 wined3d_mutex_lock();
1222 hr = IWineD3DDevice_SetRenderTarget(This->WineD3DDevice, RenderTargetIndex, pSurface ? pSurface->wineD3DSurface : NULL, TRUE);
1223 wined3d_mutex_unlock();
1224
1225 return hr;
1226}
1227
1228static HRESULT WINAPI IDirect3DDevice9Impl_GetRenderTarget(LPDIRECT3DDEVICE9EX iface, DWORD RenderTargetIndex, IDirect3DSurface9 **ppRenderTarget) {
1229 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1230 IWineD3DSurface *pRenderTarget;
1231 HRESULT hr;
1232
1233 TRACE("iface %p, idx %u, surface %p.\n", iface, RenderTargetIndex, ppRenderTarget);
1234
1235 if (ppRenderTarget == NULL) {
1236 return D3DERR_INVALIDCALL;
1237 }
1238
1239 if (RenderTargetIndex >= D3D9_MAX_SIMULTANEOUS_RENDERTARGETS)
1240 {
1241 WARN("Invalid index %u specified.\n", RenderTargetIndex);
1242 return D3DERR_INVALIDCALL;
1243 }
1244
1245 wined3d_mutex_lock();
1246
1247 hr=IWineD3DDevice_GetRenderTarget(This->WineD3DDevice,RenderTargetIndex,&pRenderTarget);
1248
1249 if (FAILED(hr))
1250 {
1251 FIXME("Call to IWineD3DDevice_GetRenderTarget failed, hr %#x\n", hr);
1252 }
1253 else if (!pRenderTarget)
1254 {
1255 *ppRenderTarget = NULL;
1256 }
1257 else
1258 {
1259 IWineD3DSurface_GetParent(pRenderTarget, (IUnknown **)ppRenderTarget);
1260 IWineD3DSurface_Release(pRenderTarget);
1261 }
1262
1263 wined3d_mutex_unlock();
1264
1265 return hr;
1266}
1267
1268static HRESULT WINAPI IDirect3DDevice9Impl_SetDepthStencilSurface(LPDIRECT3DDEVICE9EX iface, IDirect3DSurface9* pZStencilSurface) {
1269 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1270 IDirect3DSurface9Impl *pSurface;
1271 IDirect3DSurface9 *pOldSurface;
1272 HRESULT hr;
1273
1274 TRACE("iface %p, depth_stencil %p.\n", iface, pZStencilSurface);
1275
1276 pSurface = (IDirect3DSurface9Impl*)pZStencilSurface;
1277
1278 wined3d_mutex_lock();
1279 hr = IDirect3DDevice9_GetDepthStencilSurface(iface, &pOldSurface);
1280 if (D3D_OK==hr) {
1281 IDirect3DSurface9_Release(pOldSurface);
1282 IDirect3DSurface9_Release(pOldSurface);
1283 }
1284 hr = IWineD3DDevice_SetDepthStencilSurface(This->WineD3DDevice, NULL==pSurface ? NULL : pSurface->wineD3DSurface);
1285 if (pZStencilSurface) {
1286 IDirect3DSurface9_AddRef(pZStencilSurface);
1287 }
1288 wined3d_mutex_unlock();
1289
1290 return hr;
1291}
1292
1293static HRESULT WINAPI IDirect3DDevice9Impl_GetDepthStencilSurface(LPDIRECT3DDEVICE9EX iface, IDirect3DSurface9 **ppZStencilSurface) {
1294 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1295 HRESULT hr = D3D_OK;
1296 IWineD3DSurface *pZStencilSurface;
1297
1298 TRACE("iface %p, depth_stencil %p.\n", iface, ppZStencilSurface);
1299
1300 if(ppZStencilSurface == NULL){
1301 return D3DERR_INVALIDCALL;
1302 }
1303
1304 wined3d_mutex_lock();
1305 hr = IWineD3DDevice_GetDepthStencilSurface(This->WineD3DDevice,&pZStencilSurface);
1306 if (hr == WINED3D_OK) {
1307 IWineD3DSurface_GetParent(pZStencilSurface,(IUnknown**)ppZStencilSurface);
1308 IWineD3DSurface_Release(pZStencilSurface);
1309 } else {
1310 if (hr != WINED3DERR_NOTFOUND)
1311 WARN("Call to IWineD3DDevice_GetDepthStencilSurface failed with 0x%08x\n", hr);
1312 *ppZStencilSurface = NULL;
1313 }
1314 wined3d_mutex_unlock();
1315
1316 return hr;
1317}
1318
1319static HRESULT WINAPI IDirect3DDevice9Impl_BeginScene(LPDIRECT3DDEVICE9EX iface) {
1320 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1321 HRESULT hr;
1322
1323 TRACE("iface %p.\n", iface);
1324
1325 wined3d_mutex_lock();
1326 hr = IWineD3DDevice_BeginScene(This->WineD3DDevice);
1327 wined3d_mutex_unlock();
1328
1329 return hr;
1330}
1331
1332static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_EndScene(LPDIRECT3DDEVICE9EX iface) {
1333 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1334 HRESULT hr;
1335
1336 TRACE("iface %p.\n", iface);
1337
1338 wined3d_mutex_lock();
1339 hr = IWineD3DDevice_EndScene(This->WineD3DDevice);
1340 wined3d_mutex_unlock();
1341
1342 return hr;
1343}
1344
1345static HRESULT WINAPI IDirect3DDevice9Impl_Clear(LPDIRECT3DDEVICE9EX iface, DWORD Count, CONST D3DRECT* pRects, DWORD Flags, D3DCOLOR Color, float Z, DWORD Stencil) {
1346 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1347 HRESULT hr;
1348
1349 TRACE("iface %p, rect_count %u, rects %p, flags %#x, color 0x%08x, z %.8e, stencil %u.\n",
1350 iface, Count, pRects, Flags, Color, Z, Stencil);
1351
1352 /* Note: D3DRECT is compatible with WINED3DRECT */
1353 wined3d_mutex_lock();
1354 hr = IWineD3DDevice_Clear(This->WineD3DDevice, Count, (CONST WINED3DRECT*) pRects, Flags, Color, Z, Stencil);
1355 wined3d_mutex_unlock();
1356
1357 return hr;
1358}
1359
1360static HRESULT WINAPI IDirect3DDevice9Impl_SetTransform(LPDIRECT3DDEVICE9EX iface, D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX* lpMatrix) {
1361 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1362 HRESULT hr;
1363
1364 TRACE("iface %p, state %#x, matrix %p.\n", iface, State, lpMatrix);
1365
1366 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1367 wined3d_mutex_lock();
1368 hr = IWineD3DDevice_SetTransform(This->WineD3DDevice, State, (CONST WINED3DMATRIX*) lpMatrix);
1369 wined3d_mutex_unlock();
1370
1371 return hr;
1372}
1373
1374static HRESULT WINAPI IDirect3DDevice9Impl_GetTransform(LPDIRECT3DDEVICE9EX iface, D3DTRANSFORMSTATETYPE State, D3DMATRIX* pMatrix) {
1375 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1376 HRESULT hr;
1377
1378 TRACE("iface %p, state %#x, matrix %p.\n", iface, State, pMatrix);
1379
1380 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1381 wined3d_mutex_lock();
1382 hr = IWineD3DDevice_GetTransform(This->WineD3DDevice, State, (WINED3DMATRIX*) pMatrix);
1383 wined3d_mutex_unlock();
1384
1385 return hr;
1386}
1387
1388static HRESULT WINAPI IDirect3DDevice9Impl_MultiplyTransform(LPDIRECT3DDEVICE9EX iface, D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX* pMatrix) {
1389 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1390 HRESULT hr;
1391
1392 TRACE("iface %p, state %#x, matrix %p.\n", iface, State, pMatrix);
1393
1394 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1395 wined3d_mutex_lock();
1396 hr = IWineD3DDevice_MultiplyTransform(This->WineD3DDevice, State, (CONST WINED3DMATRIX*) pMatrix);
1397 wined3d_mutex_unlock();
1398
1399 return hr;
1400}
1401
1402static HRESULT WINAPI IDirect3DDevice9Impl_SetViewport(LPDIRECT3DDEVICE9EX iface, CONST D3DVIEWPORT9* pViewport) {
1403 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1404 HRESULT hr;
1405
1406 TRACE("iface %p, viewport %p.\n", iface, pViewport);
1407
1408 /* Note: D3DVIEWPORT9 is compatible with WINED3DVIEWPORT */
1409 wined3d_mutex_lock();
1410 hr = IWineD3DDevice_SetViewport(This->WineD3DDevice, (const WINED3DVIEWPORT *)pViewport);
1411 wined3d_mutex_unlock();
1412
1413 return hr;
1414}
1415
1416static HRESULT WINAPI IDirect3DDevice9Impl_GetViewport(LPDIRECT3DDEVICE9EX iface, D3DVIEWPORT9* pViewport) {
1417 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1418 HRESULT hr;
1419
1420 TRACE("iface %p, viewport %p.\n", iface, pViewport);
1421
1422 /* Note: D3DVIEWPORT9 is compatible with WINED3DVIEWPORT */
1423 wined3d_mutex_lock();
1424 hr = IWineD3DDevice_GetViewport(This->WineD3DDevice, (WINED3DVIEWPORT *)pViewport);
1425 wined3d_mutex_unlock();
1426
1427 return hr;
1428}
1429
1430static HRESULT WINAPI IDirect3DDevice9Impl_SetMaterial(LPDIRECT3DDEVICE9EX iface, CONST D3DMATERIAL9* pMaterial) {
1431 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1432 HRESULT hr;
1433
1434 TRACE("iface %p, material %p.\n", iface, pMaterial);
1435
1436 /* Note: D3DMATERIAL9 is compatible with WINED3DMATERIAL */
1437 wined3d_mutex_lock();
1438 hr = IWineD3DDevice_SetMaterial(This->WineD3DDevice, (const WINED3DMATERIAL *)pMaterial);
1439 wined3d_mutex_unlock();
1440
1441 return hr;
1442}
1443
1444static HRESULT WINAPI IDirect3DDevice9Impl_GetMaterial(LPDIRECT3DDEVICE9EX iface, D3DMATERIAL9* pMaterial) {
1445 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1446 HRESULT hr;
1447
1448 TRACE("iface %p, material %p.\n", iface, pMaterial);
1449
1450 /* Note: D3DMATERIAL9 is compatible with WINED3DMATERIAL */
1451 wined3d_mutex_lock();
1452 hr = IWineD3DDevice_GetMaterial(This->WineD3DDevice, (WINED3DMATERIAL *)pMaterial);
1453 wined3d_mutex_unlock();
1454
1455 return hr;
1456}
1457
1458static HRESULT WINAPI IDirect3DDevice9Impl_SetLight(LPDIRECT3DDEVICE9EX iface, DWORD Index, CONST D3DLIGHT9* pLight) {
1459 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1460 HRESULT hr;
1461
1462 TRACE("iface %p, index %u, light %p.\n", iface, Index, pLight);
1463
1464 /* Note: D3DLIGHT9 is compatible with WINED3DLIGHT */
1465 wined3d_mutex_lock();
1466 hr = IWineD3DDevice_SetLight(This->WineD3DDevice, Index, (const WINED3DLIGHT *)pLight);
1467 wined3d_mutex_unlock();
1468
1469 return hr;
1470}
1471
1472static HRESULT WINAPI IDirect3DDevice9Impl_GetLight(LPDIRECT3DDEVICE9EX iface, DWORD Index, D3DLIGHT9* pLight) {
1473 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1474 HRESULT hr;
1475
1476 TRACE("iface %p, index %u, light %p.\n", iface, Index, pLight);
1477
1478 /* Note: D3DLIGHT9 is compatible with WINED3DLIGHT */
1479 wined3d_mutex_lock();
1480 hr = IWineD3DDevice_GetLight(This->WineD3DDevice, Index, (WINED3DLIGHT *)pLight);
1481 wined3d_mutex_unlock();
1482
1483 return hr;
1484}
1485
1486static HRESULT WINAPI IDirect3DDevice9Impl_LightEnable(LPDIRECT3DDEVICE9EX iface, DWORD Index, BOOL Enable) {
1487 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1488 HRESULT hr;
1489
1490 TRACE("iface %p, index %u, enable %#x.\n", iface, Index, Enable);
1491
1492 wined3d_mutex_lock();
1493 hr = IWineD3DDevice_SetLightEnable(This->WineD3DDevice, Index, Enable);
1494 wined3d_mutex_unlock();
1495
1496 return hr;
1497}
1498
1499static HRESULT WINAPI IDirect3DDevice9Impl_GetLightEnable(LPDIRECT3DDEVICE9EX iface, DWORD Index, BOOL* pEnable) {
1500 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1501 HRESULT hr;
1502
1503 TRACE("iface %p, index %u, enable %p.\n", iface, Index, pEnable);
1504
1505 wined3d_mutex_lock();
1506 hr = IWineD3DDevice_GetLightEnable(This->WineD3DDevice, Index, pEnable);
1507 wined3d_mutex_unlock();
1508
1509 return hr;
1510}
1511
1512static HRESULT WINAPI IDirect3DDevice9Impl_SetClipPlane(LPDIRECT3DDEVICE9EX iface, DWORD Index, CONST float* pPlane) {
1513 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1514 HRESULT hr;
1515
1516 TRACE("iface %p, index %u, plane %p.\n", iface, Index, pPlane);
1517
1518 wined3d_mutex_lock();
1519 hr = IWineD3DDevice_SetClipPlane(This->WineD3DDevice, Index, pPlane);
1520 wined3d_mutex_unlock();
1521
1522 return hr;
1523}
1524
1525static HRESULT WINAPI IDirect3DDevice9Impl_GetClipPlane(LPDIRECT3DDEVICE9EX iface, DWORD Index, float* pPlane) {
1526 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1527 HRESULT hr;
1528
1529 TRACE("iface %p, index %u, plane %p.\n", iface, Index, pPlane);
1530
1531 wined3d_mutex_lock();
1532 hr = IWineD3DDevice_GetClipPlane(This->WineD3DDevice, Index, pPlane);
1533 wined3d_mutex_unlock();
1534
1535 return hr;
1536}
1537
1538static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_SetRenderState(LPDIRECT3DDEVICE9EX iface, D3DRENDERSTATETYPE State, DWORD Value) {
1539 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1540 HRESULT hr;
1541
1542 TRACE("iface %p, state %#x, value %#x.\n", iface, State, Value);
1543
1544 wined3d_mutex_lock();
1545 hr = IWineD3DDevice_SetRenderState(This->WineD3DDevice, State, Value);
1546 wined3d_mutex_unlock();
1547
1548 return hr;
1549}
1550
1551static HRESULT WINAPI IDirect3DDevice9Impl_GetRenderState(LPDIRECT3DDEVICE9EX iface, D3DRENDERSTATETYPE State, DWORD* pValue) {
1552 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1553 HRESULT hr;
1554
1555 TRACE("iface %p, state %#x, value %p.\n", iface, State, pValue);
1556
1557 wined3d_mutex_lock();
1558 hr = IWineD3DDevice_GetRenderState(This->WineD3DDevice, State, pValue);
1559 wined3d_mutex_unlock();
1560
1561 return hr;
1562}
1563
1564static HRESULT WINAPI IDirect3DDevice9Impl_CreateStateBlock(IDirect3DDevice9Ex *iface,
1565 D3DSTATEBLOCKTYPE type, IDirect3DStateBlock9 **stateblock)
1566{
1567 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1568 IDirect3DStateBlock9Impl *object;
1569 HRESULT hr;
1570
1571 TRACE("iface %p, type %#x, stateblock %p.\n", iface, type, stateblock);
1572
1573 if (type != D3DSBT_ALL && type != D3DSBT_PIXELSTATE && type != D3DSBT_VERTEXSTATE)
1574 {
1575 WARN("Unexpected stateblock type, returning D3DERR_INVALIDCALL.\n");
1576 return D3DERR_INVALIDCALL;
1577 }
1578
1579 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1580 if (!object)
1581 {
1582 ERR("Failed to allocate stateblock memory.\n");
1583 return E_OUTOFMEMORY;
1584 }
1585
1586 hr = stateblock_init(object, This, type, NULL);
1587 if (FAILED(hr))
1588 {
1589 WARN("Failed to initialize stateblock, hr %#x.\n", hr);
1590 HeapFree(GetProcessHeap(), 0, object);
1591 return hr;
1592 }
1593
1594 TRACE("Created stateblock %p.\n", object);
1595 *stateblock = (IDirect3DStateBlock9 *)object;
1596
1597 return D3D_OK;
1598}
1599
1600static HRESULT WINAPI IDirect3DDevice9Impl_BeginStateBlock(IDirect3DDevice9Ex *iface)
1601{
1602 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1603 HRESULT hr;
1604
1605 TRACE("iface %p.\n", iface);
1606
1607 wined3d_mutex_lock();
1608 hr = IWineD3DDevice_BeginStateBlock(This->WineD3DDevice);
1609 wined3d_mutex_unlock();
1610
1611 return hr;
1612}
1613
1614static HRESULT WINAPI IDirect3DDevice9Impl_EndStateBlock(IDirect3DDevice9Ex *iface, IDirect3DStateBlock9 **stateblock)
1615{
1616 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1617 IWineD3DStateBlock *wined3d_stateblock;
1618 IDirect3DStateBlock9Impl *object;
1619 HRESULT hr;
1620
1621 TRACE("iface %p, stateblock %p.\n", iface, stateblock);
1622
1623 wined3d_mutex_lock();
1624 hr = IWineD3DDevice_EndStateBlock(This->WineD3DDevice, &wined3d_stateblock);
1625 wined3d_mutex_unlock();
1626 if (FAILED(hr))
1627 {
1628 WARN("IWineD3DDevice_EndStateBlock() failed, hr %#x.\n", hr);
1629 return hr;
1630 }
1631
1632 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1633 if (!object)
1634 {
1635 ERR("Failed to allocate stateblock memory.\n");
1636 IWineD3DStateBlock_Release(wined3d_stateblock);
1637 return E_OUTOFMEMORY;
1638 }
1639
1640 hr = stateblock_init(object, This, 0, wined3d_stateblock);
1641 if (FAILED(hr))
1642 {
1643 WARN("Failed to initialize stateblock, hr %#x.\n", hr);
1644 IWineD3DStateBlock_Release(wined3d_stateblock);
1645 HeapFree(GetProcessHeap(), 0, object);
1646 return hr;
1647 }
1648
1649 TRACE("Created stateblock %p.\n", object);
1650 *stateblock = (IDirect3DStateBlock9 *)object;
1651
1652 return D3D_OK;
1653}
1654
1655static HRESULT WINAPI IDirect3DDevice9Impl_SetClipStatus(LPDIRECT3DDEVICE9EX iface, CONST D3DCLIPSTATUS9* pClipStatus) {
1656 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1657 HRESULT hr;
1658
1659 TRACE("iface %p, clip_status %p.\n", iface, pClipStatus);
1660
1661 wined3d_mutex_lock();
1662 hr = IWineD3DDevice_SetClipStatus(This->WineD3DDevice, (const WINED3DCLIPSTATUS *)pClipStatus);
1663 wined3d_mutex_unlock();
1664
1665 return hr;
1666}
1667
1668static HRESULT WINAPI IDirect3DDevice9Impl_GetClipStatus(LPDIRECT3DDEVICE9EX iface, D3DCLIPSTATUS9* pClipStatus) {
1669 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1670 HRESULT hr;
1671
1672 TRACE("iface %p, clip_status %p.\n", iface, pClipStatus);
1673
1674 wined3d_mutex_lock();
1675 hr = IWineD3DDevice_GetClipStatus(This->WineD3DDevice, (WINED3DCLIPSTATUS *)pClipStatus);
1676 wined3d_mutex_unlock();
1677
1678 return hr;
1679}
1680
1681static HRESULT WINAPI IDirect3DDevice9Impl_GetTexture(LPDIRECT3DDEVICE9EX iface, DWORD Stage, IDirect3DBaseTexture9 **ppTexture) {
1682 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1683 IWineD3DBaseTexture *retTexture = NULL;
1684 HRESULT rc = D3D_OK;
1685
1686 TRACE("iface %p, stage %u, texture %p.\n", iface, Stage, ppTexture);
1687
1688 if(ppTexture == NULL){
1689 return D3DERR_INVALIDCALL;
1690 }
1691
1692 wined3d_mutex_lock();
1693 rc = IWineD3DDevice_GetTexture(This->WineD3DDevice, Stage, &retTexture);
1694 if (SUCCEEDED(rc) && NULL != retTexture) {
1695 IWineD3DBaseTexture_GetParent(retTexture, (IUnknown **)ppTexture);
1696 IWineD3DBaseTexture_Release(retTexture);
1697 } else {
1698 if(FAILED(rc)) {
1699 WARN("Call to get texture (%d) failed (%p)\n", Stage, retTexture);
1700 }
1701 *ppTexture = NULL;
1702 }
1703 wined3d_mutex_unlock();
1704
1705 return rc;
1706}
1707
1708static HRESULT WINAPI IDirect3DDevice9Impl_SetTexture(LPDIRECT3DDEVICE9EX iface, DWORD Stage, IDirect3DBaseTexture9* pTexture) {
1709 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1710 HRESULT hr;
1711
1712 TRACE("iface %p, stage %u, texture %p.\n", iface, Stage, pTexture);
1713
1714 wined3d_mutex_lock();
1715 hr = IWineD3DDevice_SetTexture(This->WineD3DDevice, Stage,
1716 pTexture==NULL ? NULL:((IDirect3DBaseTexture9Impl *)pTexture)->wineD3DBaseTexture);
1717 wined3d_mutex_unlock();
1718
1719 return hr;
1720}
1721
1722static const WINED3DTEXTURESTAGESTATETYPE tss_lookup[] =
1723{
1724 WINED3DTSS_FORCE_DWORD, /* 0, unused */
1725 WINED3DTSS_COLOROP, /* 1, D3DTSS_COLOROP */
1726 WINED3DTSS_COLORARG1, /* 2, D3DTSS_COLORARG1 */
1727 WINED3DTSS_COLORARG2, /* 3, D3DTSS_COLORARG2 */
1728 WINED3DTSS_ALPHAOP, /* 4, D3DTSS_ALPHAOP */
1729 WINED3DTSS_ALPHAARG1, /* 5, D3DTSS_ALPHAARG1 */
1730 WINED3DTSS_ALPHAARG2, /* 6, D3DTSS_ALPHAARG2 */
1731 WINED3DTSS_BUMPENVMAT00, /* 7, D3DTSS_BUMPENVMAT00 */
1732 WINED3DTSS_BUMPENVMAT01, /* 8, D3DTSS_BUMPENVMAT01 */
1733 WINED3DTSS_BUMPENVMAT10, /* 9, D3DTSS_BUMPENVMAT10 */
1734 WINED3DTSS_BUMPENVMAT11, /* 10, D3DTSS_BUMPENVMAT11 */
1735 WINED3DTSS_TEXCOORDINDEX, /* 11, D3DTSS_TEXCOORDINDEX */
1736 WINED3DTSS_FORCE_DWORD, /* 12, unused */
1737 WINED3DTSS_FORCE_DWORD, /* 13, unused */
1738 WINED3DTSS_FORCE_DWORD, /* 14, unused */
1739 WINED3DTSS_FORCE_DWORD, /* 15, unused */
1740 WINED3DTSS_FORCE_DWORD, /* 16, unused */
1741 WINED3DTSS_FORCE_DWORD, /* 17, unused */
1742 WINED3DTSS_FORCE_DWORD, /* 18, unused */
1743 WINED3DTSS_FORCE_DWORD, /* 19, unused */
1744 WINED3DTSS_FORCE_DWORD, /* 20, unused */
1745 WINED3DTSS_FORCE_DWORD, /* 21, unused */
1746 WINED3DTSS_BUMPENVLSCALE, /* 22, D3DTSS_BUMPENVLSCALE */
1747 WINED3DTSS_BUMPENVLOFFSET, /* 23, D3DTSS_BUMPENVLOFFSET */
1748 WINED3DTSS_TEXTURETRANSFORMFLAGS, /* 24, D3DTSS_TEXTURETRANSFORMFLAGS */
1749 WINED3DTSS_FORCE_DWORD, /* 25, unused */
1750 WINED3DTSS_COLORARG0, /* 26, D3DTSS_COLORARG0 */
1751 WINED3DTSS_ALPHAARG0, /* 27, D3DTSS_ALPHAARG0 */
1752 WINED3DTSS_RESULTARG, /* 28, D3DTSS_RESULTARG */
1753 WINED3DTSS_FORCE_DWORD, /* 29, unused */
1754 WINED3DTSS_FORCE_DWORD, /* 30, unused */
1755 WINED3DTSS_FORCE_DWORD, /* 31, unused */
1756 WINED3DTSS_CONSTANT, /* 32, D3DTSS_CONSTANT */
1757};
1758
1759static HRESULT WINAPI IDirect3DDevice9Impl_GetTextureStageState(LPDIRECT3DDEVICE9EX iface, DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD* pValue) {
1760 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1761 HRESULT hr;
1762
1763 TRACE("iface %p, stage %u, state %#x, value %p.\n", iface, Stage, Type, pValue);
1764
1765 wined3d_mutex_lock();
1766 hr = IWineD3DDevice_GetTextureStageState(This->WineD3DDevice, Stage, tss_lookup[Type], pValue);
1767 wined3d_mutex_unlock();
1768
1769 return hr;
1770}
1771
1772static HRESULT WINAPI IDirect3DDevice9Impl_SetTextureStageState(LPDIRECT3DDEVICE9EX iface, DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD Value) {
1773 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1774 HRESULT hr;
1775
1776 TRACE("iface %p, stage %u, state %#x, value %#x.\n", iface, Stage, Type, Value);
1777
1778 wined3d_mutex_lock();
1779 hr = IWineD3DDevice_SetTextureStageState(This->WineD3DDevice, Stage, tss_lookup[Type], Value);
1780 wined3d_mutex_unlock();
1781
1782 return hr;
1783}
1784
1785static HRESULT WINAPI IDirect3DDevice9Impl_GetSamplerState(IDirect3DDevice9Ex *iface, DWORD Sampler,
1786 D3DSAMPLERSTATETYPE Type, DWORD *pValue)
1787{
1788 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1789 HRESULT hr;
1790
1791 TRACE("iface %p, sampler %u, state %#x, value %p.\n", iface, Sampler, Type, pValue);
1792
1793 wined3d_mutex_lock();
1794 hr = IWineD3DDevice_GetSamplerState(This->WineD3DDevice, Sampler, Type, pValue);
1795 wined3d_mutex_unlock();
1796
1797 return hr;
1798}
1799
1800static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_SetSamplerState(LPDIRECT3DDEVICE9EX iface, DWORD Sampler, D3DSAMPLERSTATETYPE Type, DWORD Value) {
1801 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1802 HRESULT hr;
1803
1804 TRACE("iface %p, sampler %u, state %#x, value %#x.\n", iface, Sampler, Type, Value);
1805
1806 wined3d_mutex_lock();
1807 hr = IWineD3DDevice_SetSamplerState(This->WineD3DDevice, Sampler, Type, Value);
1808 wined3d_mutex_unlock();
1809
1810 return hr;
1811}
1812
1813static HRESULT WINAPI IDirect3DDevice9Impl_ValidateDevice(LPDIRECT3DDEVICE9EX iface, DWORD* pNumPasses) {
1814 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1815 HRESULT hr;
1816
1817 TRACE("iface %p, pass_count %p.\n", iface, pNumPasses);
1818
1819 wined3d_mutex_lock();
1820 hr = IWineD3DDevice_ValidateDevice(This->WineD3DDevice, pNumPasses);
1821 wined3d_mutex_unlock();
1822
1823 return hr;
1824}
1825
1826static HRESULT WINAPI IDirect3DDevice9Impl_SetPaletteEntries(IDirect3DDevice9Ex *iface, UINT PaletteNumber,
1827 const PALETTEENTRY *pEntries)
1828{
1829 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1830 HRESULT hr;
1831
1832 TRACE("iface %p, palette_idx %u, entries %p.\n", iface, PaletteNumber, pEntries);
1833
1834 wined3d_mutex_lock();
1835 hr = IWineD3DDevice_SetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
1836 wined3d_mutex_unlock();
1837
1838 return hr;
1839}
1840
1841static HRESULT WINAPI IDirect3DDevice9Impl_GetPaletteEntries(LPDIRECT3DDEVICE9EX iface, UINT PaletteNumber, PALETTEENTRY* pEntries) {
1842 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1843 HRESULT hr;
1844
1845 TRACE("iface %p, palette_idx %u, entries %p.\n", iface, PaletteNumber, pEntries);
1846
1847 wined3d_mutex_lock();
1848 hr = IWineD3DDevice_GetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
1849 wined3d_mutex_unlock();
1850
1851 return hr;
1852}
1853
1854static HRESULT WINAPI IDirect3DDevice9Impl_SetCurrentTexturePalette(LPDIRECT3DDEVICE9EX iface, UINT PaletteNumber) {
1855 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1856 HRESULT hr;
1857
1858 TRACE("iface %p, palette_idx %u.\n", iface, PaletteNumber);
1859
1860 wined3d_mutex_lock();
1861 hr = IWineD3DDevice_SetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
1862 wined3d_mutex_unlock();
1863
1864 return hr;
1865}
1866
1867static HRESULT WINAPI IDirect3DDevice9Impl_GetCurrentTexturePalette(LPDIRECT3DDEVICE9EX iface, UINT* PaletteNumber) {
1868 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1869 HRESULT hr;
1870
1871 TRACE("iface %p, palette_idx %p.\n", iface, PaletteNumber);
1872
1873 wined3d_mutex_lock();
1874 hr = IWineD3DDevice_GetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
1875 wined3d_mutex_unlock();
1876
1877 return hr;
1878}
1879
1880static HRESULT WINAPI IDirect3DDevice9Impl_SetScissorRect(LPDIRECT3DDEVICE9EX iface, CONST RECT* pRect) {
1881 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1882 HRESULT hr;
1883
1884 TRACE("iface %p, rect %p.\n", iface, pRect);
1885
1886 wined3d_mutex_lock();
1887 hr = IWineD3DDevice_SetScissorRect(This->WineD3DDevice, pRect);
1888 wined3d_mutex_unlock();
1889
1890 return hr;
1891}
1892
1893static HRESULT WINAPI IDirect3DDevice9Impl_GetScissorRect(LPDIRECT3DDEVICE9EX iface, RECT* pRect) {
1894 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1895 HRESULT hr;
1896
1897 TRACE("iface %p, rect %p.\n", iface, pRect);
1898
1899 wined3d_mutex_lock();
1900 hr = IWineD3DDevice_GetScissorRect(This->WineD3DDevice, pRect);
1901 wined3d_mutex_unlock();
1902
1903 return hr;
1904}
1905
1906static HRESULT WINAPI IDirect3DDevice9Impl_SetSoftwareVertexProcessing(LPDIRECT3DDEVICE9EX iface, BOOL bSoftware) {
1907 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1908 HRESULT hr;
1909
1910 TRACE("iface %p, software %#x.\n", iface, bSoftware);
1911
1912 wined3d_mutex_lock();
1913 hr = IWineD3DDevice_SetSoftwareVertexProcessing(This->WineD3DDevice, bSoftware);
1914 wined3d_mutex_unlock();
1915
1916 return hr;
1917}
1918
1919static BOOL WINAPI IDirect3DDevice9Impl_GetSoftwareVertexProcessing(LPDIRECT3DDEVICE9EX iface) {
1920 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1921 BOOL ret;
1922
1923 TRACE("iface %p.\n", iface);
1924
1925 wined3d_mutex_lock();
1926 ret = IWineD3DDevice_GetSoftwareVertexProcessing(This->WineD3DDevice);
1927 wined3d_mutex_unlock();
1928
1929 return ret;
1930}
1931
1932static HRESULT WINAPI IDirect3DDevice9Impl_SetNPatchMode(LPDIRECT3DDEVICE9EX iface, float nSegments) {
1933 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1934 HRESULT hr;
1935
1936 TRACE("iface %p, segment_count %.8e.\n", iface, nSegments);
1937
1938 wined3d_mutex_lock();
1939 hr = IWineD3DDevice_SetNPatchMode(This->WineD3DDevice, nSegments);
1940 wined3d_mutex_unlock();
1941
1942 return hr;
1943}
1944
1945static float WINAPI IDirect3DDevice9Impl_GetNPatchMode(LPDIRECT3DDEVICE9EX iface) {
1946 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1947 float ret;
1948
1949 TRACE("iface %p.\n", iface);
1950
1951 wined3d_mutex_lock();
1952 ret = IWineD3DDevice_GetNPatchMode(This->WineD3DDevice);
1953 wined3d_mutex_unlock();
1954
1955 return ret;
1956}
1957
1958static HRESULT WINAPI IDirect3DDevice9Impl_DrawPrimitive(IDirect3DDevice9Ex *iface, D3DPRIMITIVETYPE PrimitiveType,
1959 UINT StartVertex, UINT PrimitiveCount)
1960{
1961 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1962 HRESULT hr;
1963
1964 TRACE("iface %p, primitive_type %#x, start_vertex %u, primitive_count %u.\n",
1965 iface, PrimitiveType, StartVertex, PrimitiveCount);
1966
1967 wined3d_mutex_lock();
1968 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1969 hr = IWineD3DDevice_DrawPrimitive(This->WineD3DDevice, StartVertex,
1970 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount));
1971 wined3d_mutex_unlock();
1972
1973 return hr;
1974}
1975
1976static HRESULT WINAPI IDirect3DDevice9Impl_DrawIndexedPrimitive(LPDIRECT3DDEVICE9EX iface, D3DPRIMITIVETYPE PrimitiveType,
1977 INT BaseVertexIndex, UINT MinVertexIndex, UINT NumVertices, UINT startIndex, UINT primCount) {
1978 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1979 HRESULT hr;
1980
1981 TRACE("iface %p, primitive_type %#x, base_vertex_idx %u, min_vertex_idx %u,\n"
1982 "vertex_count %u, start_idx %u, primitive_count %u.\n",
1983 iface, PrimitiveType, BaseVertexIndex, MinVertexIndex,
1984 NumVertices, startIndex, primCount);
1985
1986 wined3d_mutex_lock();
1987 IWineD3DDevice_SetBaseVertexIndex(This->WineD3DDevice, BaseVertexIndex);
1988 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1989 hr = IWineD3DDevice_DrawIndexedPrimitive(This->WineD3DDevice, startIndex,
1990 vertex_count_from_primitive_count(PrimitiveType, primCount));
1991 wined3d_mutex_unlock();
1992
1993 return hr;
1994}
1995
1996static HRESULT WINAPI IDirect3DDevice9Impl_DrawPrimitiveUP(IDirect3DDevice9Ex *iface, D3DPRIMITIVETYPE PrimitiveType,
1997 UINT PrimitiveCount, const void *pVertexStreamZeroData, UINT VertexStreamZeroStride)
1998{
1999 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2000 HRESULT hr;
2001
2002 TRACE("iface %p, primitive_type %#x, primitive_count %u, data %p, stride %u.\n",
2003 iface, PrimitiveType, PrimitiveCount, pVertexStreamZeroData, VertexStreamZeroStride);
2004
2005 wined3d_mutex_lock();
2006 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
2007 hr = IWineD3DDevice_DrawPrimitiveUP(This->WineD3DDevice,
2008 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount),
2009 pVertexStreamZeroData, VertexStreamZeroStride);
2010 wined3d_mutex_unlock();
2011
2012 return hr;
2013}
2014
2015static HRESULT WINAPI IDirect3DDevice9Impl_DrawIndexedPrimitiveUP(LPDIRECT3DDEVICE9EX iface, D3DPRIMITIVETYPE PrimitiveType, UINT MinVertexIndex,
2016 UINT NumVertexIndices, UINT PrimitiveCount, CONST void* pIndexData,
2017 D3DFORMAT IndexDataFormat, CONST void* pVertexStreamZeroData, UINT VertexStreamZeroStride) {
2018 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2019 HRESULT hr;
2020
2021 TRACE("iface %p, primitive_type %#x, min_vertex_idx %u, index_count %u, primitive_count %u,\n"
2022 "index_data %p, index_format %#x, vertex_data %p, vertex_stride %u.\n",
2023 iface, PrimitiveType, MinVertexIndex, NumVertexIndices, PrimitiveCount,
2024 pIndexData, IndexDataFormat, pVertexStreamZeroData, VertexStreamZeroStride);
2025
2026 wined3d_mutex_lock();
2027 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
2028 hr = IWineD3DDevice_DrawIndexedPrimitiveUP(This->WineD3DDevice,
2029 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount), pIndexData,
2030 wined3dformat_from_d3dformat(IndexDataFormat), pVertexStreamZeroData, VertexStreamZeroStride);
2031 wined3d_mutex_unlock();
2032
2033 return hr;
2034}
2035
2036static HRESULT WINAPI IDirect3DDevice9Impl_ProcessVertices(LPDIRECT3DDEVICE9EX iface, UINT SrcStartIndex, UINT DestIndex, UINT VertexCount, IDirect3DVertexBuffer9* pDestBuffer, IDirect3DVertexDeclaration9* pVertexDecl, DWORD Flags) {
2037 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2038 IDirect3DVertexDeclaration9Impl *Decl = (IDirect3DVertexDeclaration9Impl *) pVertexDecl;
2039 HRESULT hr;
2040 IDirect3DVertexBuffer9Impl *dest = (IDirect3DVertexBuffer9Impl *) pDestBuffer;
2041
2042 TRACE("iface %p, src_start_idx %u, dst_idx %u, vertex_count %u, dst_buffer %p, declaration %p, flags %#x.\n",
2043 iface, SrcStartIndex, DestIndex, VertexCount, pDestBuffer, pVertexDecl, Flags);
2044
2045 wined3d_mutex_lock();
2046 hr = IWineD3DDevice_ProcessVertices(This->WineD3DDevice,SrcStartIndex, DestIndex, VertexCount, dest->wineD3DVertexBuffer, Decl ? Decl->wineD3DVertexDeclaration : NULL, Flags, dest->fvf);
2047 wined3d_mutex_unlock();
2048
2049 return hr;
2050}
2051
2052static HRESULT WINAPI IDirect3DDevice9Impl_CreateVertexDeclaration(IDirect3DDevice9Ex *iface,
2053 const D3DVERTEXELEMENT9 *elements, IDirect3DVertexDeclaration9 **declaration)
2054{
2055 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2056 IDirect3DVertexDeclaration9Impl *object;
2057 HRESULT hr;
2058
2059 TRACE("iface %p, elements %p, declaration %p.\n", iface, elements, declaration);
2060
2061 if (!declaration)
2062 {
2063 WARN("Caller passed a NULL declaration, returning D3DERR_INVALIDCALL.\n");
2064 return D3DERR_INVALIDCALL;
2065 }
2066
2067 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2068 if (!object)
2069 {
2070 ERR("Failed to allocate vertex declaration memory.\n");
2071 return E_OUTOFMEMORY;
2072 }
2073
2074 hr = vertexdeclaration_init(object, This, elements);
2075 if (FAILED(hr))
2076 {
2077 WARN("Failed to initialize vertex declaration, hr %#x.\n", hr);
2078 HeapFree(GetProcessHeap(), 0, object);
2079 return hr;
2080 }
2081
2082 TRACE("Created vertex declaration %p.\n", object);
2083 *declaration = (IDirect3DVertexDeclaration9 *)object;
2084
2085 return D3D_OK;
2086}
2087
2088static IDirect3DVertexDeclaration9 *getConvertedDecl(IDirect3DDevice9Impl *This, DWORD fvf) {
2089 HRESULT hr;
2090 D3DVERTEXELEMENT9* elements = NULL;
2091 IDirect3DVertexDeclaration9* pDecl = NULL;
2092 int p, low, high; /* deliberately signed */
2093 IDirect3DVertexDeclaration9 **convertedDecls = This->convertedDecls;
2094
2095 TRACE("Searching for declaration for fvf %08x... ", fvf);
2096
2097 low = 0;
2098 high = This->numConvertedDecls - 1;
2099 while(low <= high) {
2100 p = (low + high) >> 1;
2101 TRACE("%d ", p);
2102 if(((IDirect3DVertexDeclaration9Impl *) convertedDecls[p])->convFVF == fvf) {
2103 TRACE("found %p\n", convertedDecls[p]);
2104 return convertedDecls[p];
2105 } else if(((IDirect3DVertexDeclaration9Impl *) convertedDecls[p])->convFVF < fvf) {
2106 low = p + 1;
2107 } else {
2108 high = p - 1;
2109 }
2110 }
2111 TRACE("not found. Creating and inserting at position %d.\n", low);
2112
2113 hr = vdecl_convert_fvf(fvf, &elements);
2114 if (hr != S_OK) return NULL;
2115
2116 hr = IDirect3DDevice9Impl_CreateVertexDeclaration((IDirect3DDevice9Ex *) This, elements, &pDecl);
2117 HeapFree(GetProcessHeap(), 0, elements); /* CreateVertexDeclaration makes a copy */
2118 if (hr != S_OK) return NULL;
2119
2120 if(This->declArraySize == This->numConvertedDecls) {
2121 int grow = max(This->declArraySize / 2, 8);
2122 convertedDecls = HeapReAlloc(GetProcessHeap(), 0, convertedDecls,
2123 sizeof(convertedDecls[0]) * (This->numConvertedDecls + grow));
2124 if(!convertedDecls) {
2125 /* This will destroy it */
2126 IDirect3DVertexDeclaration9_Release(pDecl);
2127 return NULL;
2128 }
2129 This->convertedDecls = convertedDecls;
2130 This->declArraySize += grow;
2131 }
2132
2133 memmove(convertedDecls + low + 1, convertedDecls + low, sizeof(IDirect3DVertexDeclaration9Impl *) * (This->numConvertedDecls - low));
2134 convertedDecls[low] = pDecl;
2135 This->numConvertedDecls++;
2136
2137 /* Will prevent the decl from being destroyed */
2138 ((IDirect3DVertexDeclaration9Impl *) pDecl)->convFVF = fvf;
2139 IDirect3DVertexDeclaration9_Release(pDecl); /* Does not destroy now */
2140
2141 TRACE("Returning %p. %d decls in array\n", pDecl, This->numConvertedDecls);
2142 return pDecl;
2143}
2144
2145static HRESULT WINAPI IDirect3DDevice9Impl_SetFVF(LPDIRECT3DDEVICE9EX iface, DWORD FVF) {
2146 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2147 IDirect3DVertexDeclaration9 *decl;
2148 HRESULT hr;
2149
2150 TRACE("iface %p, fvf %#x.\n", iface, FVF);
2151
2152 if (!FVF)
2153 {
2154 WARN("%#x is not a valid FVF\n", FVF);
2155 return D3D_OK;
2156 }
2157
2158 wined3d_mutex_lock();
2159 decl = getConvertedDecl(This, FVF);
2160 wined3d_mutex_unlock();
2161
2162 if (!decl)
2163 {
2164 /* Any situation when this should happen, except out of memory? */
2165 ERR("Failed to create a converted vertex declaration\n");
2166 return D3DERR_DRIVERINTERNALERROR;
2167 }
2168
2169 hr = IDirect3DDevice9Impl_SetVertexDeclaration(iface, decl);
2170 if (FAILED(hr)) ERR("Failed to set vertex declaration\n");
2171
2172 return hr;
2173}
2174
2175static HRESULT WINAPI IDirect3DDevice9Impl_GetFVF(IDirect3DDevice9Ex *iface, DWORD *pFVF)
2176{
2177 IDirect3DVertexDeclaration9 *decl;
2178 HRESULT hr;
2179
2180 TRACE("iface %p, fvf %p.\n", iface, pFVF);
2181
2182 hr = IDirect3DDevice9_GetVertexDeclaration(iface, &decl);
2183 if (FAILED(hr))
2184 {
2185 WARN("Failed to get vertex declaration, %#x\n", hr);
2186 *pFVF = 0;
2187 return hr;
2188 }
2189
2190 if (decl)
2191 {
2192 *pFVF = ((IDirect3DVertexDeclaration9Impl *)decl)->convFVF;
2193 IDirect3DVertexDeclaration9_Release(decl);
2194 }
2195 else
2196 {
2197 *pFVF = 0;
2198 }
2199
2200 TRACE("Returning FVF %#x\n", *pFVF);
2201
2202 return hr;
2203}
2204
2205static HRESULT WINAPI IDirect3DDevice9Impl_CreateVertexShader(IDirect3DDevice9Ex *iface,
2206 const DWORD *byte_code, IDirect3DVertexShader9 **shader)
2207{
2208 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2209 IDirect3DVertexShader9Impl *object;
2210 HRESULT hr;
2211
2212 TRACE("iface %p, byte_code %p, shader %p.\n", iface, byte_code, shader);
2213
2214 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2215 if (!object)
2216 {
2217 ERR("Failed to allocate vertex shader memory.\n");
2218 return E_OUTOFMEMORY;
2219 }
2220
2221 hr = vertexshader_init(object, This, byte_code);
2222 if (FAILED(hr))
2223 {
2224 WARN("Failed to initialize vertex shader, hr %#x.\n", hr);
2225 HeapFree(GetProcessHeap(), 0, object);
2226 return hr;
2227 }
2228
2229 TRACE("Created vertex shader %p.\n", object);
2230 *shader = (IDirect3DVertexShader9 *)object;
2231
2232 return D3D_OK;
2233}
2234
2235static HRESULT WINAPI IDirect3DDevice9Impl_SetStreamSource(LPDIRECT3DDEVICE9EX iface, UINT StreamNumber, IDirect3DVertexBuffer9* pStreamData, UINT OffsetInBytes, UINT Stride) {
2236 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2237 HRESULT hr;
2238
2239 TRACE("iface %p, stream_idx %u, buffer %p, offset %u, stride %u.\n",
2240 iface, StreamNumber, pStreamData, OffsetInBytes, Stride);
2241
2242 wined3d_mutex_lock();
2243 hr = IWineD3DDevice_SetStreamSource(This->WineD3DDevice, StreamNumber,
2244 pStreamData ? ((IDirect3DVertexBuffer9Impl *)pStreamData)->wineD3DVertexBuffer : NULL,
2245 OffsetInBytes, Stride);
2246 wined3d_mutex_unlock();
2247
2248 return hr;
2249}
2250
2251static HRESULT WINAPI IDirect3DDevice9Impl_GetStreamSource(LPDIRECT3DDEVICE9EX iface, UINT StreamNumber, IDirect3DVertexBuffer9 **pStream, UINT* OffsetInBytes, UINT* pStride) {
2252 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2253 IWineD3DBuffer *retStream = NULL;
2254 HRESULT rc = D3D_OK;
2255
2256 TRACE("iface %p, stream_idx %u, buffer %p, offset %p, stride %p.\n",
2257 iface, StreamNumber, pStream, OffsetInBytes, pStride);
2258
2259 if(pStream == NULL){
2260 return D3DERR_INVALIDCALL;
2261 }
2262
2263 wined3d_mutex_lock();
2264 rc = IWineD3DDevice_GetStreamSource(This->WineD3DDevice, StreamNumber, &retStream, OffsetInBytes, pStride);
2265 if (rc == D3D_OK && NULL != retStream) {
2266 IWineD3DBuffer_GetParent(retStream, (IUnknown **)pStream);
2267 IWineD3DBuffer_Release(retStream);
2268 }else{
2269 if (rc != D3D_OK){
2270 FIXME("Call to GetStreamSource failed %p %p\n", OffsetInBytes, pStride);
2271 }
2272 *pStream = NULL;
2273 }
2274 wined3d_mutex_unlock();
2275
2276 return rc;
2277}
2278
2279static HRESULT WINAPI IDirect3DDevice9Impl_SetStreamSourceFreq(IDirect3DDevice9Ex *iface, UINT StreamNumber,
2280 UINT Divider)
2281{
2282 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2283 HRESULT hr;
2284
2285 TRACE("iface %p, stream_idx %u, freq %u.\n", iface, StreamNumber, Divider);
2286
2287 wined3d_mutex_lock();
2288 hr = IWineD3DDevice_SetStreamSourceFreq(This->WineD3DDevice, StreamNumber, Divider);
2289 wined3d_mutex_unlock();
2290
2291 return hr;
2292}
2293
2294static HRESULT WINAPI IDirect3DDevice9Impl_GetStreamSourceFreq(LPDIRECT3DDEVICE9EX iface, UINT StreamNumber, UINT* Divider) {
2295 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2296 HRESULT hr;
2297
2298 TRACE("iface %p, stream_idx %u, freq %p.\n", iface, StreamNumber, Divider);
2299
2300 wined3d_mutex_lock();
2301 hr = IWineD3DDevice_GetStreamSourceFreq(This->WineD3DDevice, StreamNumber, Divider);
2302 wined3d_mutex_unlock();
2303
2304 return hr;
2305}
2306
2307static HRESULT WINAPI IDirect3DDevice9Impl_SetIndices(LPDIRECT3DDEVICE9EX iface, IDirect3DIndexBuffer9* pIndexData) {
2308 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2309 HRESULT hr;
2310 IDirect3DIndexBuffer9Impl *ib = (IDirect3DIndexBuffer9Impl *) pIndexData;
2311
2312 TRACE("iface %p, buffer %p.\n", iface, pIndexData);
2313
2314 wined3d_mutex_lock();
2315 hr = IWineD3DDevice_SetIndexBuffer(This->WineD3DDevice,
2316 ib ? ib->wineD3DIndexBuffer : NULL,
2317 ib ? ib->format : WINED3DFMT_UNKNOWN);
2318 wined3d_mutex_unlock();
2319
2320 return hr;
2321}
2322
2323static HRESULT WINAPI IDirect3DDevice9Impl_GetIndices(LPDIRECT3DDEVICE9EX iface, IDirect3DIndexBuffer9 **ppIndexData) {
2324 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2325 IWineD3DBuffer *retIndexData = NULL;
2326 HRESULT rc = D3D_OK;
2327
2328 TRACE("iface %p, buffer %p.\n", iface, ppIndexData);
2329
2330 if(ppIndexData == NULL){
2331 return D3DERR_INVALIDCALL;
2332 }
2333
2334 wined3d_mutex_lock();
2335 rc = IWineD3DDevice_GetIndexBuffer(This->WineD3DDevice, &retIndexData);
2336 if (SUCCEEDED(rc) && retIndexData) {
2337 IWineD3DBuffer_GetParent(retIndexData, (IUnknown **)ppIndexData);
2338 IWineD3DBuffer_Release(retIndexData);
2339 } else {
2340 if (FAILED(rc)) FIXME("Call to GetIndices failed\n");
2341 *ppIndexData = NULL;
2342 }
2343 wined3d_mutex_unlock();
2344
2345 return rc;
2346}
2347
2348static HRESULT WINAPI IDirect3DDevice9Impl_CreatePixelShader(IDirect3DDevice9Ex *iface,
2349 const DWORD *byte_code, IDirect3DPixelShader9 **shader)
2350{
2351 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2352 IDirect3DPixelShader9Impl *object;
2353 HRESULT hr;
2354
2355 TRACE("iface %p, byte_code %p, shader %p.\n", iface, byte_code, shader);
2356
2357 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2358 if (!object)
2359 {
2360 FIXME("Failed to allocate pixel shader memory.\n");
2361 return E_OUTOFMEMORY;
2362 }
2363
2364 hr = pixelshader_init(object, This, byte_code);
2365 if (FAILED(hr))
2366 {
2367 WARN("Failed to initialize pixel shader, hr %#x.\n", hr);
2368 HeapFree(GetProcessHeap(), 0, object);
2369 return hr;
2370 }
2371
2372 TRACE("Created pixel shader %p.\n", object);
2373 *shader = (IDirect3DPixelShader9 *)object;
2374
2375 return D3D_OK;
2376}
2377
2378static HRESULT WINAPI IDirect3DDevice9Impl_DrawRectPatch(LPDIRECT3DDEVICE9EX iface, UINT Handle, CONST float* pNumSegs, CONST D3DRECTPATCH_INFO* pRectPatchInfo) {
2379 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2380 HRESULT hr;
2381
2382 TRACE("iface %p, handle %#x, segment_count %p, patch_info %p.\n",
2383 iface, Handle, pNumSegs, pRectPatchInfo);
2384
2385 wined3d_mutex_lock();
2386 hr = IWineD3DDevice_DrawRectPatch(This->WineD3DDevice, Handle, pNumSegs, (CONST WINED3DRECTPATCH_INFO *)pRectPatchInfo);
2387 wined3d_mutex_unlock();
2388
2389 return hr;
2390}
2391
2392static HRESULT WINAPI IDirect3DDevice9Impl_DrawTriPatch(LPDIRECT3DDEVICE9EX iface, UINT Handle, CONST float* pNumSegs, CONST D3DTRIPATCH_INFO* pTriPatchInfo) {
2393 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2394 HRESULT hr;
2395
2396 TRACE("iface %p, handle %#x, segment_count %p, patch_info %p.\n",
2397 iface, Handle, pNumSegs, pTriPatchInfo);
2398
2399 wined3d_mutex_lock();
2400 hr = IWineD3DDevice_DrawTriPatch(This->WineD3DDevice, Handle, pNumSegs, (CONST WINED3DTRIPATCH_INFO *)pTriPatchInfo);
2401 wined3d_mutex_unlock();
2402
2403 return hr;
2404}
2405
2406static HRESULT WINAPI IDirect3DDevice9Impl_DeletePatch(LPDIRECT3DDEVICE9EX iface, UINT Handle) {
2407 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2408 HRESULT hr;
2409
2410 TRACE("iface %p, handle %#x.\n", iface, Handle);
2411
2412 wined3d_mutex_lock();
2413 hr = IWineD3DDevice_DeletePatch(This->WineD3DDevice, Handle);
2414 wined3d_mutex_unlock();
2415
2416 return hr;
2417}
2418
2419static HRESULT WINAPI IDirect3DDevice9Impl_CreateQuery(IDirect3DDevice9Ex *iface,
2420 D3DQUERYTYPE type, IDirect3DQuery9 **query)
2421{
2422 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
2423 IDirect3DQuery9Impl *object;
2424 HRESULT hr;
2425
2426 TRACE("iface %p, type %#x, query %p.\n", iface, type, query);
2427
2428 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2429 if (!object)
2430 {
2431 ERR("Failed to allocate query memory.\n");
2432 return E_OUTOFMEMORY;
2433 }
2434
2435 hr = query_init(object, This, type);
2436 if (FAILED(hr))
2437 {
2438 WARN("Failed to initialize query, hr %#x.\n", hr);
2439 HeapFree(GetProcessHeap(), 0, object);
2440 return hr;
2441 }
2442
2443 TRACE("Created query %p.\n", object);
2444 if (query) *query = (IDirect3DQuery9 *)object;
2445 else IDirect3DQuery9_Release((IDirect3DQuery9 *)object);
2446
2447 return D3D_OK;
2448}
2449
2450static HRESULT WINAPI IDirect3DDevice9ExImpl_SetConvolutionMonoKernel(IDirect3DDevice9Ex *iface,
2451 UINT width, UINT height, float *rows, float *columns)
2452{
2453 FIXME("iface %p, width %u, height %u, rows %p, columns %p stub!\n",
2454 iface, width, height, rows, columns);
2455
2456 return WINED3DERR_INVALIDCALL;
2457}
2458
2459static HRESULT WINAPI IDirect3DDevice9ExImpl_ComposeRects(IDirect3DDevice9Ex *iface,
2460 IDirect3DSurface9 *src_surface, IDirect3DSurface9 *dst_surface, IDirect3DVertexBuffer9 *src_descs,
2461 UINT rect_count, IDirect3DVertexBuffer9 *dst_descs, D3DCOMPOSERECTSOP operation, INT offset_x, INT offset_y)
2462{
2463 FIXME("iface %p, src_surface %p, dst_surface %p, src_descs %p, rect_count %u,\n"
2464 "dst_descs %p, operation %#x, offset_x %u, offset_y %u stub!\n",
2465 iface, src_surface, dst_surface, src_descs, rect_count,
2466 dst_descs, operation, offset_x, offset_y);
2467
2468 return WINED3DERR_INVALIDCALL;
2469}
2470
2471static HRESULT WINAPI IDirect3DDevice9ExImpl_PresentEx(IDirect3DDevice9Ex *iface,
2472 const RECT *src_rect, const RECT *dst_rect, HWND dst_window_override,
2473 const RGNDATA *dirty_region, DWORD flags)
2474{
2475 FIXME("iface %p, src_rect %p, dst_rect %p, dst_window_override %p, dirty_region %p, flags %#x stub!\n",
2476 iface, src_rect, dst_rect, dst_window_override, dirty_region, flags);
2477
2478 return WINED3DERR_INVALIDCALL;
2479}
2480
2481static HRESULT WINAPI IDirect3DDevice9ExImpl_GetGPUThreadPriority(IDirect3DDevice9Ex *iface, INT *priority)
2482{
2483 FIXME("iface %p, priority %p stub!\n", iface, priority);
2484
2485 return WINED3DERR_INVALIDCALL;
2486}
2487
2488static HRESULT WINAPI IDirect3DDevice9ExImpl_SetGPUThreadPriority(IDirect3DDevice9Ex *iface, INT priority)
2489{
2490 FIXME("iface %p, priority %d stub!\n", iface, priority);
2491
2492 return WINED3DERR_INVALIDCALL;
2493}
2494
2495static HRESULT WINAPI IDirect3DDevice9ExImpl_WaitForVBlank(IDirect3DDevice9Ex *iface, UINT swapchain_idx)
2496{
2497 FIXME("iface %p, swapchain_idx %u stub!\n", iface, swapchain_idx);
2498
2499 return WINED3DERR_INVALIDCALL;
2500}
2501
2502static HRESULT WINAPI IDirect3DDevice9ExImpl_CheckResourceResidency(IDirect3DDevice9Ex *iface,
2503 IDirect3DResource9 **resources, UINT32 resource_count)
2504{
2505 FIXME("iface %p, resources %p, resource_count %u stub!\n",
2506 iface, resources, resource_count);
2507
2508 return WINED3DERR_INVALIDCALL;
2509}
2510
2511static HRESULT WINAPI IDirect3DDevice9ExImpl_SetMaximumFrameLatency(IDirect3DDevice9Ex *iface, UINT max_latency)
2512{
2513 FIXME("iface %p, max_latency %u stub!\n", iface, max_latency);
2514
2515 return WINED3DERR_INVALIDCALL;
2516}
2517
2518static HRESULT WINAPI IDirect3DDevice9ExImpl_GetMaximumFrameLatency(IDirect3DDevice9Ex *iface, UINT *max_latency)
2519{
2520 FIXME("iface %p, max_latency %p stub!\n", iface, max_latency);
2521
2522 *max_latency = 2;
2523
2524 return WINED3DERR_INVALIDCALL;
2525}
2526
2527static HRESULT WINAPI IDirect3DDevice9ExImpl_CheckDeviceState(IDirect3DDevice9Ex *iface, HWND dst_window)
2528{
2529 FIXME("iface %p, dst_window %p stub!\n", iface, dst_window);
2530
2531 return WINED3DERR_INVALIDCALL;
2532}
2533
2534static HRESULT WINAPI IDirect3DDevice9ExImpl_CreateRenderTargetEx(IDirect3DDevice9Ex *iface,
2535 UINT width, UINT height, D3DFORMAT format, D3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality,
2536 BOOL lockable, IDirect3DSurface9 **surface, HANDLE *shared_handle, DWORD usage)
2537{
2538 FIXME("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u,\n"
2539 "lockable %#x, surface %p, shared_handle %p, usage %#x stub!\n",
2540 iface, width, height, format, multisample_type, multisample_quality,
2541 lockable, surface, shared_handle, usage);
2542
2543 return WINED3DERR_INVALIDCALL;
2544}
2545
2546static HRESULT WINAPI IDirect3DDevice9ExImpl_CreateOffscreenPlainSurfaceEx(IDirect3DDevice9Ex *iface,
2547 UINT width, UINT height, D3DFORMAT format, D3DPOOL pool, IDirect3DSurface9 **surface,
2548 HANDLE *shared_handle, DWORD usage)
2549{
2550 FIXME("iface %p, width %u, height %u, format %#x, pool %#x, surface %p, shared_handle %p, usage %#x stub!\n",
2551 iface, width, height, format, pool, surface, shared_handle, usage);
2552
2553 return WINED3DERR_INVALIDCALL;
2554}
2555
2556static HRESULT WINAPI IDirect3DDevice9ExImpl_CreateDepthStencilSurfaceEx(IDirect3DDevice9Ex *iface,
2557 UINT width, UINT height, D3DFORMAT format, D3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality,
2558 BOOL discard, IDirect3DSurface9 **surface, HANDLE *shared_handle, DWORD usage)
2559{
2560 FIXME("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u,\n"
2561 "discard %#x, surface %p, shared_handle %p, usage %#x stub!\n",
2562 iface, width, height, format, multisample_type, multisample_quality,
2563 discard, surface, shared_handle, usage);
2564
2565 return WINED3DERR_INVALIDCALL;
2566}
2567
2568static HRESULT WINAPI IDirect3DDevice9ExImpl_ResetEx(IDirect3DDevice9Ex *iface,
2569 D3DPRESENT_PARAMETERS *present_parameters, D3DDISPLAYMODEEX *mode)
2570{
2571 FIXME("iface %p, present_parameters %p, mode %p stub!\n", iface, present_parameters, mode);
2572
2573 return WINED3DERR_INVALIDCALL;
2574}
2575
2576static HRESULT WINAPI IDirect3DDevice9ExImpl_GetDisplayModeEx(IDirect3DDevice9Ex *iface,
2577 UINT swapchain_idx, D3DDISPLAYMODEEX *mode, D3DDISPLAYROTATION *rotation)
2578{
2579 FIXME("iface %p, swapchain_idx %u, mode %p, rotation %p stub!\n", iface, swapchain_idx, mode, rotation);
2580
2581 return WINED3DERR_INVALIDCALL;
2582}
2583
2584static const IDirect3DDevice9ExVtbl Direct3DDevice9_Vtbl =
2585{
2586 /* IUnknown */
2587 IDirect3DDevice9Impl_QueryInterface,
2588 IDirect3DDevice9Impl_AddRef,
2589 IDirect3DDevice9Impl_Release,
2590 /* IDirect3DDevice9 */
2591 IDirect3DDevice9Impl_TestCooperativeLevel,
2592 IDirect3DDevice9Impl_GetAvailableTextureMem,
2593 IDirect3DDevice9Impl_EvictManagedResources,
2594 IDirect3DDevice9Impl_GetDirect3D,
2595 IDirect3DDevice9Impl_GetDeviceCaps,
2596 IDirect3DDevice9Impl_GetDisplayMode,
2597 IDirect3DDevice9Impl_GetCreationParameters,
2598 IDirect3DDevice9Impl_SetCursorProperties,
2599 IDirect3DDevice9Impl_SetCursorPosition,
2600 IDirect3DDevice9Impl_ShowCursor,
2601 IDirect3DDevice9Impl_CreateAdditionalSwapChain,
2602 IDirect3DDevice9Impl_GetSwapChain,
2603 IDirect3DDevice9Impl_GetNumberOfSwapChains,
2604 IDirect3DDevice9Impl_Reset,
2605 IDirect3DDevice9Impl_Present,
2606 IDirect3DDevice9Impl_GetBackBuffer,
2607 IDirect3DDevice9Impl_GetRasterStatus,
2608 IDirect3DDevice9Impl_SetDialogBoxMode,
2609 IDirect3DDevice9Impl_SetGammaRamp,
2610 IDirect3DDevice9Impl_GetGammaRamp,
2611 IDirect3DDevice9Impl_CreateTexture,
2612 IDirect3DDevice9Impl_CreateVolumeTexture,
2613 IDirect3DDevice9Impl_CreateCubeTexture,
2614 IDirect3DDevice9Impl_CreateVertexBuffer,
2615 IDirect3DDevice9Impl_CreateIndexBuffer,
2616 IDirect3DDevice9Impl_CreateRenderTarget,
2617 IDirect3DDevice9Impl_CreateDepthStencilSurface,
2618 IDirect3DDevice9Impl_UpdateSurface,
2619 IDirect3DDevice9Impl_UpdateTexture,
2620 IDirect3DDevice9Impl_GetRenderTargetData,
2621 IDirect3DDevice9Impl_GetFrontBufferData,
2622 IDirect3DDevice9Impl_StretchRect,
2623 IDirect3DDevice9Impl_ColorFill,
2624 IDirect3DDevice9Impl_CreateOffscreenPlainSurface,
2625 IDirect3DDevice9Impl_SetRenderTarget,
2626 IDirect3DDevice9Impl_GetRenderTarget,
2627 IDirect3DDevice9Impl_SetDepthStencilSurface,
2628 IDirect3DDevice9Impl_GetDepthStencilSurface,
2629 IDirect3DDevice9Impl_BeginScene,
2630 IDirect3DDevice9Impl_EndScene,
2631 IDirect3DDevice9Impl_Clear,
2632 IDirect3DDevice9Impl_SetTransform,
2633 IDirect3DDevice9Impl_GetTransform,
2634 IDirect3DDevice9Impl_MultiplyTransform,
2635 IDirect3DDevice9Impl_SetViewport,
2636 IDirect3DDevice9Impl_GetViewport,
2637 IDirect3DDevice9Impl_SetMaterial,
2638 IDirect3DDevice9Impl_GetMaterial,
2639 IDirect3DDevice9Impl_SetLight,
2640 IDirect3DDevice9Impl_GetLight,
2641 IDirect3DDevice9Impl_LightEnable,
2642 IDirect3DDevice9Impl_GetLightEnable,
2643 IDirect3DDevice9Impl_SetClipPlane,
2644 IDirect3DDevice9Impl_GetClipPlane,
2645 IDirect3DDevice9Impl_SetRenderState,
2646 IDirect3DDevice9Impl_GetRenderState,
2647 IDirect3DDevice9Impl_CreateStateBlock,
2648 IDirect3DDevice9Impl_BeginStateBlock,
2649 IDirect3DDevice9Impl_EndStateBlock,
2650 IDirect3DDevice9Impl_SetClipStatus,
2651 IDirect3DDevice9Impl_GetClipStatus,
2652 IDirect3DDevice9Impl_GetTexture,
2653 IDirect3DDevice9Impl_SetTexture,
2654 IDirect3DDevice9Impl_GetTextureStageState,
2655 IDirect3DDevice9Impl_SetTextureStageState,
2656 IDirect3DDevice9Impl_GetSamplerState,
2657 IDirect3DDevice9Impl_SetSamplerState,
2658 IDirect3DDevice9Impl_ValidateDevice,
2659 IDirect3DDevice9Impl_SetPaletteEntries,
2660 IDirect3DDevice9Impl_GetPaletteEntries,
2661 IDirect3DDevice9Impl_SetCurrentTexturePalette,
2662 IDirect3DDevice9Impl_GetCurrentTexturePalette,
2663 IDirect3DDevice9Impl_SetScissorRect,
2664 IDirect3DDevice9Impl_GetScissorRect,
2665 IDirect3DDevice9Impl_SetSoftwareVertexProcessing,
2666 IDirect3DDevice9Impl_GetSoftwareVertexProcessing,
2667 IDirect3DDevice9Impl_SetNPatchMode,
2668 IDirect3DDevice9Impl_GetNPatchMode,
2669 IDirect3DDevice9Impl_DrawPrimitive,
2670 IDirect3DDevice9Impl_DrawIndexedPrimitive,
2671 IDirect3DDevice9Impl_DrawPrimitiveUP,
2672 IDirect3DDevice9Impl_DrawIndexedPrimitiveUP,
2673 IDirect3DDevice9Impl_ProcessVertices,
2674 IDirect3DDevice9Impl_CreateVertexDeclaration,
2675 IDirect3DDevice9Impl_SetVertexDeclaration,
2676 IDirect3DDevice9Impl_GetVertexDeclaration,
2677 IDirect3DDevice9Impl_SetFVF,
2678 IDirect3DDevice9Impl_GetFVF,
2679 IDirect3DDevice9Impl_CreateVertexShader,
2680 IDirect3DDevice9Impl_SetVertexShader,
2681 IDirect3DDevice9Impl_GetVertexShader,
2682 IDirect3DDevice9Impl_SetVertexShaderConstantF,
2683 IDirect3DDevice9Impl_GetVertexShaderConstantF,
2684 IDirect3DDevice9Impl_SetVertexShaderConstantI,
2685 IDirect3DDevice9Impl_GetVertexShaderConstantI,
2686 IDirect3DDevice9Impl_SetVertexShaderConstantB,
2687 IDirect3DDevice9Impl_GetVertexShaderConstantB,
2688 IDirect3DDevice9Impl_SetStreamSource,
2689 IDirect3DDevice9Impl_GetStreamSource,
2690 IDirect3DDevice9Impl_SetStreamSourceFreq,
2691 IDirect3DDevice9Impl_GetStreamSourceFreq,
2692 IDirect3DDevice9Impl_SetIndices,
2693 IDirect3DDevice9Impl_GetIndices,
2694 IDirect3DDevice9Impl_CreatePixelShader,
2695 IDirect3DDevice9Impl_SetPixelShader,
2696 IDirect3DDevice9Impl_GetPixelShader,
2697 IDirect3DDevice9Impl_SetPixelShaderConstantF,
2698 IDirect3DDevice9Impl_GetPixelShaderConstantF,
2699 IDirect3DDevice9Impl_SetPixelShaderConstantI,
2700 IDirect3DDevice9Impl_GetPixelShaderConstantI,
2701 IDirect3DDevice9Impl_SetPixelShaderConstantB,
2702 IDirect3DDevice9Impl_GetPixelShaderConstantB,
2703 IDirect3DDevice9Impl_DrawRectPatch,
2704 IDirect3DDevice9Impl_DrawTriPatch,
2705 IDirect3DDevice9Impl_DeletePatch,
2706 IDirect3DDevice9Impl_CreateQuery,
2707 /* IDirect3DDevice9Ex */
2708 IDirect3DDevice9ExImpl_SetConvolutionMonoKernel,
2709 IDirect3DDevice9ExImpl_ComposeRects,
2710 IDirect3DDevice9ExImpl_PresentEx,
2711 IDirect3DDevice9ExImpl_GetGPUThreadPriority,
2712 IDirect3DDevice9ExImpl_SetGPUThreadPriority,
2713 IDirect3DDevice9ExImpl_WaitForVBlank,
2714 IDirect3DDevice9ExImpl_CheckResourceResidency,
2715 IDirect3DDevice9ExImpl_SetMaximumFrameLatency,
2716 IDirect3DDevice9ExImpl_GetMaximumFrameLatency,
2717 IDirect3DDevice9ExImpl_CheckDeviceState,
2718 IDirect3DDevice9ExImpl_CreateRenderTargetEx,
2719 IDirect3DDevice9ExImpl_CreateOffscreenPlainSurfaceEx,
2720 IDirect3DDevice9ExImpl_CreateDepthStencilSurfaceEx,
2721 IDirect3DDevice9ExImpl_ResetEx,
2722 IDirect3DDevice9ExImpl_GetDisplayModeEx
2723};
2724
2725/* IWineD3DDeviceParent IUnknown methods */
2726
2727static inline struct IDirect3DDevice9Impl *device_from_device_parent(IWineD3DDeviceParent *iface)
2728{
2729 return (struct IDirect3DDevice9Impl *)((char*)iface
2730 - FIELD_OFFSET(struct IDirect3DDevice9Impl, device_parent_vtbl));
2731}
2732
2733static HRESULT STDMETHODCALLTYPE device_parent_QueryInterface(IWineD3DDeviceParent *iface, REFIID riid, void **object)
2734{
2735 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
2736 return IDirect3DDevice9Impl_QueryInterface((IDirect3DDevice9Ex *)This, riid, object);
2737}
2738
2739static ULONG STDMETHODCALLTYPE device_parent_AddRef(IWineD3DDeviceParent *iface)
2740{
2741 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
2742 return IDirect3DDevice9Impl_AddRef((IDirect3DDevice9Ex *)This);
2743}
2744
2745static ULONG STDMETHODCALLTYPE device_parent_Release(IWineD3DDeviceParent *iface)
2746{
2747 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
2748 return IDirect3DDevice9Impl_Release((IDirect3DDevice9Ex *)This);
2749}
2750
2751/* IWineD3DDeviceParent methods */
2752
2753static void STDMETHODCALLTYPE device_parent_WineD3DDeviceCreated(IWineD3DDeviceParent *iface, IWineD3DDevice *device)
2754{
2755 TRACE("iface %p, device %p\n", iface, device);
2756}
2757
2758static HRESULT STDMETHODCALLTYPE device_parent_CreateSurface(IWineD3DDeviceParent *iface,
2759 IUnknown *superior, UINT width, UINT height, WINED3DFORMAT format, DWORD usage,
2760 WINED3DPOOL pool, UINT level, WINED3DCUBEMAP_FACES face, IWineD3DSurface **surface
2761#ifdef VBOXWDDM
2762 , HANDLE *shared_handle
2763 , void *pvClientMem
2764#endif
2765 )
2766{
2767 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
2768 IDirect3DSurface9Impl *d3d_surface;
2769 BOOL lockable = TRUE;
2770 HRESULT hr;
2771
2772 TRACE("iface %p, superior %p, width %u, height %u, format %#x, usage %#x,\n"
2773 "\tpool %#x, level %u, face %u, surface %p\n",
2774 iface, superior, width, height, format, usage, pool, level, face, surface);
2775
2776 if (pool == WINED3DPOOL_DEFAULT && !(usage & D3DUSAGE_DYNAMIC))
2777 lockable = FALSE;
2778
2779 hr = IDirect3DDevice9Impl_CreateSurface((IDirect3DDevice9Ex *)This, width, height,
2780 d3dformat_from_wined3dformat(format), lockable, FALSE /* Discard */, level,
2781 (IDirect3DSurface9 **)&d3d_surface, usage, pool, D3DMULTISAMPLE_NONE, 0 /* MultisampleQuality */
2782#ifdef VBOXWDDM
2783 , shared_handle
2784 , pvClientMem
2785#endif
2786 );
2787 if (FAILED(hr))
2788 {
2789 ERR("(%p) CreateSurface failed, returning %#x\n", iface, hr);
2790 return hr;
2791 }
2792
2793 *surface = d3d_surface->wineD3DSurface;
2794 IWineD3DSurface_AddRef(*surface);
2795
2796 d3d_surface->container = superior;
2797 IDirect3DDevice9Ex_Release(d3d_surface->parentDevice);
2798 d3d_surface->parentDevice = NULL;
2799
2800 IDirect3DSurface9_Release((IDirect3DSurface9 *)d3d_surface);
2801 d3d_surface->forwardReference = superior;
2802
2803 return hr;
2804}
2805
2806static HRESULT STDMETHODCALLTYPE device_parent_CreateRenderTarget(IWineD3DDeviceParent *iface,
2807 IUnknown *superior, UINT width, UINT height, WINED3DFORMAT format, WINED3DMULTISAMPLE_TYPE multisample_type,
2808 DWORD multisample_quality, BOOL lockable, IWineD3DSurface **surface)
2809{
2810 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
2811 IDirect3DSurface9Impl *d3d_surface;
2812 HRESULT hr;
2813
2814 TRACE("iface %p, superior %p, width %u, height %u, format %#x, multisample_type %#x,\n"
2815 "\tmultisample_quality %u, lockable %u, surface %p\n",
2816 iface, superior, width, height, format, multisample_type, multisample_quality, lockable, surface);
2817
2818 hr = IDirect3DDevice9Impl_CreateRenderTarget((IDirect3DDevice9Ex *)This, width, height,
2819 d3dformat_from_wined3dformat(format), multisample_type, multisample_quality, lockable,
2820 (IDirect3DSurface9 **)&d3d_surface, NULL);
2821 if (FAILED(hr))
2822 {
2823 ERR("(%p) CreateRenderTarget failed, returning %#x\n", iface, hr);
2824 return hr;
2825 }
2826
2827 *surface = d3d_surface->wineD3DSurface;
2828 IWineD3DSurface_AddRef(*surface);
2829
2830 d3d_surface->container = superior;
2831 /* Implicit surfaces are created with an refcount of 0 */
2832 IDirect3DSurface9_Release((IDirect3DSurface9 *)d3d_surface);
2833
2834 return hr;
2835}
2836
2837static HRESULT STDMETHODCALLTYPE device_parent_CreateDepthStencilSurface(IWineD3DDeviceParent *iface,
2838 IUnknown *superior, UINT width, UINT height, WINED3DFORMAT format, WINED3DMULTISAMPLE_TYPE multisample_type,
2839 DWORD multisample_quality, BOOL discard, IWineD3DSurface **surface)
2840{
2841 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
2842 IDirect3DSurface9Impl *d3d_surface;
2843 HRESULT hr;
2844
2845 TRACE("iface %p, superior %p, width %u, height %u, format %#x, multisample_type %#x,\n"
2846 "\tmultisample_quality %u, discard %u, surface %p\n",
2847 iface, superior, width, height, format, multisample_type, multisample_quality, discard, surface);
2848
2849 hr = IDirect3DDevice9Impl_CreateDepthStencilSurface((IDirect3DDevice9Ex *)This, width, height,
2850 d3dformat_from_wined3dformat(format), multisample_type, multisample_quality, discard,
2851 (IDirect3DSurface9 **)&d3d_surface, NULL);
2852 if (FAILED(hr))
2853 {
2854 ERR("(%p) CreateDepthStencilSurface failed, returning %#x\n", iface, hr);
2855 return hr;
2856 }
2857
2858 *surface = d3d_surface->wineD3DSurface;
2859 IWineD3DSurface_AddRef(*surface);
2860 d3d_surface->container = (IUnknown *)This;
2861 /* Implicit surfaces are created with an refcount of 0 */
2862 IDirect3DSurface9_Release((IDirect3DSurface9 *)d3d_surface);
2863
2864 return hr;
2865}
2866
2867static HRESULT STDMETHODCALLTYPE device_parent_CreateVolume(IWineD3DDeviceParent *iface,
2868 IUnknown *superior, UINT width, UINT height, UINT depth, WINED3DFORMAT format,
2869 WINED3DPOOL pool, DWORD usage, IWineD3DVolume **volume)
2870{
2871 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
2872 IDirect3DVolume9Impl *object;
2873 HRESULT hr;
2874
2875 TRACE("iface %p, superior %p, width %u, height %u, depth %u, format %#x, pool %#x, usage %#x, volume %p\n",
2876 iface, superior, width, height, depth, format, pool, usage, volume);
2877
2878 /* Allocate the storage for the device */
2879 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2880 if (!object)
2881 {
2882 FIXME("Allocation of memory failed\n");
2883 *volume = NULL;
2884 return D3DERR_OUTOFVIDEOMEMORY;
2885 }
2886
2887 hr = volume_init(object, This, width, height, depth, usage, format, pool);
2888 if (FAILED(hr))
2889 {
2890 WARN("Failed to initialize volume, hr %#x.\n", hr);
2891 HeapFree(GetProcessHeap(), 0, object);
2892 return hr;
2893 }
2894
2895 *volume = object->wineD3DVolume;
2896 IWineD3DVolume_AddRef(*volume);
2897 IDirect3DVolume9_Release((IDirect3DVolume9 *)object);
2898
2899 object->container = superior;
2900 object->forwardReference = superior;
2901
2902 TRACE("(%p) Created volume %p\n", iface, object);
2903
2904 return hr;
2905}
2906
2907static HRESULT STDMETHODCALLTYPE device_parent_CreateSwapChain(IWineD3DDeviceParent *iface,
2908 WINED3DPRESENT_PARAMETERS *present_parameters, IWineD3DSwapChain **swapchain)
2909{
2910 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
2911 IDirect3DSwapChain9Impl *d3d_swapchain;
2912 D3DPRESENT_PARAMETERS local_parameters;
2913 HRESULT hr;
2914
2915 TRACE("iface %p, present_parameters %p, swapchain %p\n", iface, present_parameters, swapchain);
2916
2917 /* Copy the presentation parameters */
2918 local_parameters.BackBufferWidth = present_parameters->BackBufferWidth;
2919 local_parameters.BackBufferHeight = present_parameters->BackBufferHeight;
2920 local_parameters.BackBufferFormat = d3dformat_from_wined3dformat(present_parameters->BackBufferFormat);
2921 local_parameters.BackBufferCount = present_parameters->BackBufferCount;
2922 local_parameters.MultiSampleType = present_parameters->MultiSampleType;
2923 local_parameters.MultiSampleQuality = present_parameters->MultiSampleQuality;
2924 local_parameters.SwapEffect = present_parameters->SwapEffect;
2925 local_parameters.hDeviceWindow = present_parameters->hDeviceWindow;
2926 local_parameters.Windowed = present_parameters->Windowed;
2927 local_parameters.EnableAutoDepthStencil = present_parameters->EnableAutoDepthStencil;
2928 local_parameters.AutoDepthStencilFormat = d3dformat_from_wined3dformat(present_parameters->AutoDepthStencilFormat);
2929 local_parameters.Flags = present_parameters->Flags;
2930 local_parameters.FullScreen_RefreshRateInHz = present_parameters->FullScreen_RefreshRateInHz;
2931 local_parameters.PresentationInterval = present_parameters->PresentationInterval;
2932
2933#ifdef VBOXWDDM
2934 hr = IDirect3DDevice9Impl_DoCreateAdditionalSwapChain((IDirect3DDevice9Ex *)This,
2935 &local_parameters, (IDirect3DSwapChain9 **)&d3d_swapchain);
2936#else
2937 hr = IDirect3DDevice9Impl_CreateAdditionalSwapChain((IDirect3DDevice9Ex *)This,
2938 &local_parameters, (IDirect3DSwapChain9 **)&d3d_swapchain);
2939#endif
2940 if (FAILED(hr))
2941 {
2942 ERR("(%p) CreateAdditionalSwapChain failed, returning %#x\n", iface, hr);
2943 *swapchain = NULL;
2944 return hr;
2945 }
2946
2947 *swapchain = d3d_swapchain->wineD3DSwapChain;
2948 d3d_swapchain->isImplicit = TRUE;
2949 /* Implicit swap chains are created with an refcount of 0 */
2950 IDirect3DSwapChain9_Release((IDirect3DSwapChain9 *)d3d_swapchain);
2951
2952 /* Copy back the presentation parameters */
2953 present_parameters->BackBufferWidth = local_parameters.BackBufferWidth;
2954 present_parameters->BackBufferHeight = local_parameters.BackBufferHeight;
2955 present_parameters->BackBufferFormat = wined3dformat_from_d3dformat(local_parameters.BackBufferFormat);
2956 present_parameters->BackBufferCount = local_parameters.BackBufferCount;
2957 present_parameters->MultiSampleType = local_parameters.MultiSampleType;
2958 present_parameters->MultiSampleQuality = local_parameters.MultiSampleQuality;
2959 present_parameters->SwapEffect = local_parameters.SwapEffect;
2960 present_parameters->hDeviceWindow = local_parameters.hDeviceWindow;
2961 present_parameters->Windowed = local_parameters.Windowed;
2962 present_parameters->EnableAutoDepthStencil = local_parameters.EnableAutoDepthStencil;
2963 present_parameters->AutoDepthStencilFormat = wined3dformat_from_d3dformat(local_parameters.AutoDepthStencilFormat);
2964 present_parameters->Flags = local_parameters.Flags;
2965 present_parameters->FullScreen_RefreshRateInHz = local_parameters.FullScreen_RefreshRateInHz;
2966 present_parameters->PresentationInterval = local_parameters.PresentationInterval;
2967
2968 return hr;
2969}
2970
2971static const IWineD3DDeviceParentVtbl d3d9_wined3d_device_parent_vtbl =
2972{
2973 /* IUnknown methods */
2974 device_parent_QueryInterface,
2975 device_parent_AddRef,
2976 device_parent_Release,
2977 /* IWineD3DDeviceParent methods */
2978 device_parent_WineD3DDeviceCreated,
2979 device_parent_CreateSurface,
2980 device_parent_CreateRenderTarget,
2981 device_parent_CreateDepthStencilSurface,
2982 device_parent_CreateVolume,
2983 device_parent_CreateSwapChain,
2984};
2985
2986HRESULT device_init(IDirect3DDevice9Impl *device, IWineD3D *wined3d, UINT adapter, D3DDEVTYPE device_type,
2987 HWND focus_window, DWORD flags, D3DPRESENT_PARAMETERS *parameters)
2988{
2989 WINED3DPRESENT_PARAMETERS *wined3d_parameters;
2990 UINT i, count = 1;
2991 HRESULT hr;
2992
2993 device->lpVtbl = &Direct3DDevice9_Vtbl;
2994 device->device_parent_vtbl = &d3d9_wined3d_device_parent_vtbl;
2995 device->ref = 1;
2996
2997 wined3d_mutex_lock();
2998 hr = IWineD3D_CreateDevice(wined3d, adapter, device_type, focus_window, flags, (IUnknown *)device,
2999 (IWineD3DDeviceParent *)&device->device_parent_vtbl, &device->WineD3DDevice);
3000 if (FAILED(hr))
3001 {
3002 WARN("Failed to create wined3d device, hr %#x.\n", hr);
3003 wined3d_mutex_unlock();
3004 return hr;
3005 }
3006
3007 if (!parameters->Windowed)
3008 {
3009 if (!focus_window) focus_window = parameters->hDeviceWindow;
3010 if (FAILED(hr = IWineD3DDevice_AcquireFocusWindow(device->WineD3DDevice, focus_window)))
3011 {
3012 ERR("Failed to acquire focus window, hr %#x.\n", hr);
3013 IWineD3DDevice_Release(device->WineD3DDevice);
3014 wined3d_mutex_unlock();
3015 return hr;
3016 }
3017 }
3018
3019 if (flags & D3DCREATE_ADAPTERGROUP_DEVICE)
3020 {
3021 WINED3DCAPS caps;
3022
3023 IWineD3D_GetDeviceCaps(wined3d, adapter, device_type, &caps);
3024 count = caps.NumberOfAdaptersInGroup;
3025 }
3026
3027 if (flags & D3DCREATE_MULTITHREADED) IWineD3DDevice_SetMultithreaded(device->WineD3DDevice);
3028
3029 wined3d_parameters = HeapAlloc(GetProcessHeap(), 0, sizeof(*wined3d_parameters) * count);
3030 if (!wined3d_parameters)
3031 {
3032 ERR("Failed to allocate wined3d parameters.\n");
3033 IWineD3DDevice_Release(device->WineD3DDevice);
3034 wined3d_mutex_unlock();
3035 return E_OUTOFMEMORY;
3036 }
3037
3038 for (i = 0; i < count; ++i)
3039 {
3040 wined3d_parameters[i].BackBufferWidth = parameters[i].BackBufferWidth;
3041 wined3d_parameters[i].BackBufferHeight = parameters[i].BackBufferHeight;
3042 wined3d_parameters[i].BackBufferFormat = wined3dformat_from_d3dformat(parameters[i].BackBufferFormat);
3043 wined3d_parameters[i].BackBufferCount = parameters[i].BackBufferCount;
3044 wined3d_parameters[i].MultiSampleType = parameters[i].MultiSampleType;
3045 wined3d_parameters[i].MultiSampleQuality = parameters[i].MultiSampleQuality;
3046 wined3d_parameters[i].SwapEffect = parameters[i].SwapEffect;
3047 wined3d_parameters[i].hDeviceWindow = parameters[i].hDeviceWindow;
3048 wined3d_parameters[i].Windowed = parameters[i].Windowed;
3049 wined3d_parameters[i].EnableAutoDepthStencil = parameters[i].EnableAutoDepthStencil;
3050 wined3d_parameters[i].AutoDepthStencilFormat =
3051 wined3dformat_from_d3dformat(parameters[i].AutoDepthStencilFormat);
3052 wined3d_parameters[i].Flags = parameters[i].Flags;
3053 wined3d_parameters[i].FullScreen_RefreshRateInHz = parameters[i].FullScreen_RefreshRateInHz;
3054 wined3d_parameters[i].PresentationInterval = parameters[i].PresentationInterval;
3055 wined3d_parameters[i].AutoRestoreDisplayMode = TRUE;
3056 }
3057
3058 hr = IWineD3DDevice_Init3D(device->WineD3DDevice, wined3d_parameters);
3059 if (FAILED(hr))
3060 {
3061 WARN("Failed to initialize 3D, hr %#x.\n", hr);
3062 IWineD3DDevice_ReleaseFocusWindow(device->WineD3DDevice);
3063 HeapFree(GetProcessHeap(), 0, wined3d_parameters);
3064 IWineD3DDevice_Release(device->WineD3DDevice);
3065 wined3d_mutex_unlock();
3066 return hr;
3067 }
3068
3069 wined3d_mutex_unlock();
3070
3071 for (i = 0; i < count; ++i)
3072 {
3073 parameters[i].BackBufferWidth = wined3d_parameters[i].BackBufferWidth;
3074 parameters[i].BackBufferHeight = wined3d_parameters[i].BackBufferHeight;
3075 parameters[i].BackBufferFormat = d3dformat_from_wined3dformat(wined3d_parameters[i].BackBufferFormat);
3076 parameters[i].BackBufferCount = wined3d_parameters[i].BackBufferCount;
3077 parameters[i].MultiSampleType = wined3d_parameters[i].MultiSampleType;
3078 parameters[i].MultiSampleQuality = wined3d_parameters[i].MultiSampleQuality;
3079 parameters[i].SwapEffect = wined3d_parameters[i].SwapEffect;
3080 parameters[i].hDeviceWindow = wined3d_parameters[i].hDeviceWindow;
3081 parameters[i].Windowed = wined3d_parameters[i].Windowed;
3082 parameters[i].EnableAutoDepthStencil = wined3d_parameters[i].EnableAutoDepthStencil;
3083 parameters[i].AutoDepthStencilFormat =
3084 d3dformat_from_wined3dformat(wined3d_parameters[i].AutoDepthStencilFormat);
3085 parameters[i].Flags = wined3d_parameters[i].Flags;
3086 parameters[i].FullScreen_RefreshRateInHz = wined3d_parameters[i].FullScreen_RefreshRateInHz;
3087 parameters[i].PresentationInterval = wined3d_parameters[i].PresentationInterval;
3088 }
3089 HeapFree(GetProcessHeap(), 0, wined3d_parameters);
3090
3091 /* Initialize the converted declaration array. This creates a valid pointer
3092 * and when adding decls HeapReAlloc() can be used without further checking. */
3093 device->convertedDecls = HeapAlloc(GetProcessHeap(), 0, 0);
3094 if (!device->convertedDecls)
3095 {
3096 ERR("Failed to allocate FVF vertex declaration map memory.\n");
3097 wined3d_mutex_lock();
3098 IWineD3DDevice_Uninit3D(device->WineD3DDevice, D3D9CB_DestroySwapChain);
3099 IWineD3DDevice_ReleaseFocusWindow(device->WineD3DDevice);
3100 IWineD3DDevice_Release(device->WineD3DDevice);
3101 wined3d_mutex_unlock();
3102 return E_OUTOFMEMORY;
3103 }
3104
3105 return D3D_OK;
3106}
Note: See TracBrowser for help on using the repository browser.

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