VirtualBox

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

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

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