VirtualBox

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

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

win additions burn fix

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