VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/device.c@ 30705

Last change on this file since 30705 was 28475, checked in by vboxsync, 15 years ago

crOpenGL: update to wine 1.1.43

  • Property svn:eol-style set to native
File size: 105.7 KB
Line 
1/*
2 * IDirect3DDevice8 implementation
3 *
4 * Copyright 2002-2004 Jason Edmeades
5 * Copyright 2004 Christian Costa
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 */
21
22/*
23 * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
24 * other than GPL or LGPL is available it will apply instead, Sun elects to use only
25 * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
26 * a choice of LGPL license versions is made available with the language indicating
27 * that LGPLv2 or any later version may be used, or where a choice of which version
28 * of the LGPL is applied is otherwise unspecified.
29 */
30
31#include "config.h"
32
33#include <math.h>
34#include <stdarg.h>
35
36#define NONAMELESSUNION
37#define NONAMELESSSTRUCT
38#include "windef.h"
39#include "winbase.h"
40#include "winuser.h"
41#include "wingdi.h"
42#include "wine/debug.h"
43
44#include "d3d8_private.h"
45
46WINE_DEFAULT_DEBUG_CHANNEL(d3d8);
47
48D3DFORMAT d3dformat_from_wined3dformat(WINED3DFORMAT format)
49{
50 BYTE *c = (BYTE *)&format;
51
52 /* Don't translate FOURCC formats */
53 if (isprint(c[0]) && isprint(c[1]) && isprint(c[2]) && isprint(c[3])) return format;
54
55 switch(format)
56 {
57 case WINED3DFMT_UNKNOWN: return D3DFMT_UNKNOWN;
58 case WINED3DFMT_B8G8R8_UNORM: return D3DFMT_R8G8B8;
59 case WINED3DFMT_B8G8R8A8_UNORM: return D3DFMT_A8R8G8B8;
60 case WINED3DFMT_B8G8R8X8_UNORM: return D3DFMT_X8R8G8B8;
61 case WINED3DFMT_B5G6R5_UNORM: return D3DFMT_R5G6B5;
62 case WINED3DFMT_B5G5R5X1_UNORM: return D3DFMT_X1R5G5B5;
63 case WINED3DFMT_B5G5R5A1_UNORM: return D3DFMT_A1R5G5B5;
64 case WINED3DFMT_B4G4R4A4_UNORM: return D3DFMT_A4R4G4B4;
65 case WINED3DFMT_B2G3R3_UNORM: return D3DFMT_R3G3B2;
66 case WINED3DFMT_A8_UNORM: return D3DFMT_A8;
67 case WINED3DFMT_B2G3R3A8_UNORM: return D3DFMT_A8R3G3B2;
68 case WINED3DFMT_B4G4R4X4_UNORM: return D3DFMT_X4R4G4B4;
69 case WINED3DFMT_R10G10B10A2_UNORM: return D3DFMT_A2B10G10R10;
70 case WINED3DFMT_R16G16_UNORM: return D3DFMT_G16R16;
71 case WINED3DFMT_P8_UINT_A8_UNORM: return D3DFMT_A8P8;
72 case WINED3DFMT_P8_UINT: return D3DFMT_P8;
73 case WINED3DFMT_L8_UNORM: return D3DFMT_L8;
74 case WINED3DFMT_L8A8_UNORM: return D3DFMT_A8L8;
75 case WINED3DFMT_L4A4_UNORM: return D3DFMT_A4L4;
76 case WINED3DFMT_R8G8_SNORM: return D3DFMT_V8U8;
77 case WINED3DFMT_R5G5_SNORM_L6_UNORM: return D3DFMT_L6V5U5;
78 case WINED3DFMT_R8G8_SNORM_L8X8_UNORM: return D3DFMT_X8L8V8U8;
79 case WINED3DFMT_R8G8B8A8_SNORM: return D3DFMT_Q8W8V8U8;
80 case WINED3DFMT_R16G16_SNORM: return D3DFMT_V16U16;
81 case WINED3DFMT_R10G11B11_SNORM: return D3DFMT_W11V11U10;
82 case WINED3DFMT_R10G10B10_SNORM_A2_UNORM: return D3DFMT_A2W10V10U10;
83 case WINED3DFMT_D16_LOCKABLE: return D3DFMT_D16_LOCKABLE;
84 case WINED3DFMT_D32_UNORM: return D3DFMT_D32;
85 case WINED3DFMT_S1_UINT_D15_UNORM: return D3DFMT_D15S1;
86 case WINED3DFMT_D24_UNORM_S8_UINT: return D3DFMT_D24S8;
87 case WINED3DFMT_X8D24_UNORM: return D3DFMT_D24X8;
88 case WINED3DFMT_S4X4_UINT_D24_UNORM: return D3DFMT_D24X4S4;
89 case WINED3DFMT_D16_UNORM: return D3DFMT_D16;
90 case WINED3DFMT_VERTEXDATA: return D3DFMT_VERTEXDATA;
91 case WINED3DFMT_R16_UINT: return D3DFMT_INDEX16;
92 case WINED3DFMT_R32_UINT: return D3DFMT_INDEX32;
93 default:
94 FIXME("Unhandled WINED3DFORMAT %#x\n", format);
95 return D3DFMT_UNKNOWN;
96 }
97}
98
99WINED3DFORMAT wined3dformat_from_d3dformat(D3DFORMAT format)
100{
101 BYTE *c = (BYTE *)&format;
102
103 /* Don't translate FOURCC formats */
104 if (isprint(c[0]) && isprint(c[1]) && isprint(c[2]) && isprint(c[3])) return format;
105
106 switch(format)
107 {
108 case D3DFMT_UNKNOWN: return WINED3DFMT_UNKNOWN;
109 case D3DFMT_R8G8B8: return WINED3DFMT_B8G8R8_UNORM;
110 case D3DFMT_A8R8G8B8: return WINED3DFMT_B8G8R8A8_UNORM;
111 case D3DFMT_X8R8G8B8: return WINED3DFMT_B8G8R8X8_UNORM;
112 case D3DFMT_R5G6B5: return WINED3DFMT_B5G6R5_UNORM;
113 case D3DFMT_X1R5G5B5: return WINED3DFMT_B5G5R5X1_UNORM;
114 case D3DFMT_A1R5G5B5: return WINED3DFMT_B5G5R5A1_UNORM;
115 case D3DFMT_A4R4G4B4: return WINED3DFMT_B4G4R4A4_UNORM;
116 case D3DFMT_R3G3B2: return WINED3DFMT_B2G3R3_UNORM;
117 case D3DFMT_A8: return WINED3DFMT_A8_UNORM;
118 case D3DFMT_A8R3G3B2: return WINED3DFMT_B2G3R3A8_UNORM;
119 case D3DFMT_X4R4G4B4: return WINED3DFMT_B4G4R4X4_UNORM;
120 case D3DFMT_A2B10G10R10: return WINED3DFMT_R10G10B10A2_UNORM;
121 case D3DFMT_G16R16: return WINED3DFMT_R16G16_UNORM;
122 case D3DFMT_A8P8: return WINED3DFMT_P8_UINT_A8_UNORM;
123 case D3DFMT_P8: return WINED3DFMT_P8_UINT;
124 case D3DFMT_L8: return WINED3DFMT_L8_UNORM;
125 case D3DFMT_A8L8: return WINED3DFMT_L8A8_UNORM;
126 case D3DFMT_A4L4: return WINED3DFMT_L4A4_UNORM;
127 case D3DFMT_V8U8: return WINED3DFMT_R8G8_SNORM;
128 case D3DFMT_L6V5U5: return WINED3DFMT_R5G5_SNORM_L6_UNORM;
129 case D3DFMT_X8L8V8U8: return WINED3DFMT_R8G8_SNORM_L8X8_UNORM;
130 case D3DFMT_Q8W8V8U8: return WINED3DFMT_R8G8B8A8_SNORM;
131 case D3DFMT_V16U16: return WINED3DFMT_R16G16_SNORM;
132 case D3DFMT_W11V11U10: return WINED3DFMT_R10G11B11_SNORM;
133 case D3DFMT_A2W10V10U10: return WINED3DFMT_R10G10B10_SNORM_A2_UNORM;
134 case D3DFMT_D16_LOCKABLE: return WINED3DFMT_D16_LOCKABLE;
135 case D3DFMT_D32: return WINED3DFMT_D32_UNORM;
136 case D3DFMT_D15S1: return WINED3DFMT_S1_UINT_D15_UNORM;
137 case D3DFMT_D24S8: return WINED3DFMT_D24_UNORM_S8_UINT;
138 case D3DFMT_D24X8: return WINED3DFMT_X8D24_UNORM;
139 case D3DFMT_D24X4S4: return WINED3DFMT_S4X4_UINT_D24_UNORM;
140 case D3DFMT_D16: return WINED3DFMT_D16_UNORM;
141 case D3DFMT_VERTEXDATA: return WINED3DFMT_VERTEXDATA;
142 case D3DFMT_INDEX16: return WINED3DFMT_R16_UINT;
143 case D3DFMT_INDEX32: return WINED3DFMT_R32_UINT;
144 default:
145 FIXME("Unhandled D3DFORMAT %#x\n", format);
146 return WINED3DFMT_UNKNOWN;
147 }
148}
149
150static UINT vertex_count_from_primitive_count(D3DPRIMITIVETYPE primitive_type, UINT primitive_count)
151{
152 switch(primitive_type)
153 {
154 case D3DPT_POINTLIST:
155 return primitive_count;
156
157 case D3DPT_LINELIST:
158 return primitive_count * 2;
159
160 case D3DPT_LINESTRIP:
161 return primitive_count + 1;
162
163 case D3DPT_TRIANGLELIST:
164 return primitive_count * 3;
165
166 case D3DPT_TRIANGLESTRIP:
167 case D3DPT_TRIANGLEFAN:
168 return primitive_count + 2;
169
170 default:
171 FIXME("Unhandled primitive type %#x\n", primitive_type);
172 return 0;
173 }
174}
175
176/* Handle table functions */
177static DWORD d3d8_allocate_handle(struct d3d8_handle_table *t, void *object, enum d3d8_handle_type type)
178{
179 struct d3d8_handle_entry *entry;
180
181 if (t->free_entries)
182 {
183 DWORD index = t->free_entries - t->entries;
184 /* Use a free handle */
185 entry = t->free_entries;
186 if (entry->type != D3D8_HANDLE_FREE)
187 {
188 ERR("Handle %u(%p) is in the free list, but has type %#x.\n", index, entry, entry->type);
189 return D3D8_INVALID_HANDLE;
190 }
191 t->free_entries = entry->object;
192 entry->object = object;
193 entry->type = type;
194
195 return index;
196 }
197
198 if (!(t->entry_count < t->table_size))
199 {
200 /* Grow the table */
201 UINT new_size = t->table_size + (t->table_size >> 1);
202 struct d3d8_handle_entry *new_entries = HeapReAlloc(GetProcessHeap(),
203 0, t->entries, new_size * sizeof(*t->entries));
204 if (!new_entries)
205 {
206 ERR("Failed to grow the handle table.\n");
207 return D3D8_INVALID_HANDLE;
208 }
209 t->entries = new_entries;
210 t->table_size = new_size;
211 }
212
213 entry = &t->entries[t->entry_count];
214 entry->object = object;
215 entry->type = type;
216
217 return t->entry_count++;
218}
219
220static void *d3d8_free_handle(struct d3d8_handle_table *t, DWORD handle, enum d3d8_handle_type type)
221{
222 struct d3d8_handle_entry *entry;
223 void *object;
224
225 if (handle == D3D8_INVALID_HANDLE || handle >= t->entry_count)
226 {
227 WARN("Invalid handle %u passed.\n", handle);
228 return NULL;
229 }
230
231 entry = &t->entries[handle];
232 if (entry->type != type)
233 {
234 WARN("Handle %u(%p) is not of type %#x.\n", handle, entry, type);
235 return NULL;
236 }
237
238 object = entry->object;
239 entry->object = t->free_entries;
240 entry->type = D3D8_HANDLE_FREE;
241 t->free_entries = entry;
242
243 return object;
244}
245
246static void *d3d8_get_object(struct d3d8_handle_table *t, DWORD handle, enum d3d8_handle_type type)
247{
248 struct d3d8_handle_entry *entry;
249
250 if (handle == D3D8_INVALID_HANDLE || handle >= t->entry_count)
251 {
252 WARN("Invalid handle %u passed.\n", handle);
253 return NULL;
254 }
255
256 entry = &t->entries[handle];
257 if (entry->type != type)
258 {
259 WARN("Handle %u(%p) is not of type %#x.\n", handle, entry, type);
260 return NULL;
261 }
262
263 return entry->object;
264}
265
266static ULONG WINAPI D3D8CB_DestroySwapChain(IWineD3DSwapChain *swapchain)
267{
268 IUnknown *parent;
269
270 TRACE("swapchain %p.\n", swapchain);
271
272 IWineD3DSwapChain_GetParent(swapchain, &parent);
273 IUnknown_Release(parent);
274 return IUnknown_Release(parent);
275}
276
277/* IDirect3D IUnknown parts follow: */
278static HRESULT WINAPI IDirect3DDevice8Impl_QueryInterface(LPDIRECT3DDEVICE8 iface,REFIID riid,LPVOID *ppobj)
279{
280 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
281
282 TRACE("iface %p, riid %s, object %p.\n",
283 iface, debugstr_guid(riid), ppobj);
284
285 if (IsEqualGUID(riid, &IID_IUnknown)
286 || IsEqualGUID(riid, &IID_IDirect3DDevice8)) {
287 IUnknown_AddRef(iface);
288 *ppobj = This;
289 return S_OK;
290 }
291
292 if (IsEqualGUID(riid, &IID_IWineD3DDeviceParent))
293 {
294 IUnknown_AddRef((IUnknown *)&This->device_parent_vtbl);
295 *ppobj = &This->device_parent_vtbl;
296 return S_OK;
297 }
298
299 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
300 *ppobj = NULL;
301 return E_NOINTERFACE;
302}
303
304static ULONG WINAPI IDirect3DDevice8Impl_AddRef(LPDIRECT3DDEVICE8 iface) {
305 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
306 ULONG ref = InterlockedIncrement(&This->ref);
307
308 TRACE("%p increasing refcount to %u.\n", iface, ref);
309
310 return ref;
311}
312
313static ULONG WINAPI IDirect3DDevice8Impl_Release(LPDIRECT3DDEVICE8 iface) {
314 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
315 ULONG ref;
316
317 if (This->inDestruction) return 0;
318 ref = InterlockedDecrement(&This->ref);
319
320 TRACE("%p decreasing refcount to %u.\n", iface, ref);
321
322 if (ref == 0) {
323 unsigned i;
324
325 TRACE("Releasing wined3d device %p\n", This->WineD3DDevice);
326
327 wined3d_mutex_lock();
328
329 This->inDestruction = TRUE;
330
331 for(i = 0; i < This->numConvertedDecls; i++) {
332 IDirect3DVertexDeclaration8_Release(This->decls[i].decl);
333 }
334 HeapFree(GetProcessHeap(), 0, This->decls);
335
336 IWineD3DDevice_Uninit3D(This->WineD3DDevice, D3D8CB_DestroySwapChain);
337 IWineD3DDevice_ReleaseFocusWindow(This->WineD3DDevice);
338 IWineD3DDevice_Release(This->WineD3DDevice);
339 HeapFree(GetProcessHeap(), 0, This->handle_table.entries);
340 HeapFree(GetProcessHeap(), 0, This);
341
342 wined3d_mutex_unlock();
343 }
344 return ref;
345}
346
347/* IDirect3DDevice Interface follow: */
348static HRESULT WINAPI IDirect3DDevice8Impl_TestCooperativeLevel(IDirect3DDevice8 *iface)
349{
350 TRACE("iface %p.\n", iface);
351
352 return D3D_OK;
353}
354
355static UINT WINAPI IDirect3DDevice8Impl_GetAvailableTextureMem(LPDIRECT3DDEVICE8 iface) {
356 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
357 HRESULT hr;
358
359 TRACE("iface %p.\n", iface);
360
361 wined3d_mutex_lock();
362 hr = IWineD3DDevice_GetAvailableTextureMem(This->WineD3DDevice);
363 wined3d_mutex_unlock();
364
365 return hr;
366}
367
368static HRESULT WINAPI IDirect3DDevice8Impl_ResourceManagerDiscardBytes(LPDIRECT3DDEVICE8 iface, DWORD Bytes) {
369 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
370 HRESULT hr;
371
372 TRACE("iface %p, byte_count %u.\n", iface, Bytes);
373 FIXME("Byte count ignored.\n");
374
375 wined3d_mutex_lock();
376 hr = IWineD3DDevice_EvictManagedResources(This->WineD3DDevice);
377 wined3d_mutex_unlock();
378
379 return hr;
380}
381
382static HRESULT WINAPI IDirect3DDevice8Impl_GetDirect3D(LPDIRECT3DDEVICE8 iface, IDirect3D8** ppD3D8) {
383 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
384 HRESULT hr = D3D_OK;
385 IWineD3D* pWineD3D;
386
387 TRACE("iface %p, d3d8 %p.\n", iface, ppD3D8);
388
389 if (NULL == ppD3D8) {
390 return D3DERR_INVALIDCALL;
391 }
392
393 wined3d_mutex_lock();
394 hr = IWineD3DDevice_GetDirect3D(This->WineD3DDevice, &pWineD3D);
395 if (hr == D3D_OK && pWineD3D != NULL)
396 {
397 IWineD3D_GetParent(pWineD3D,(IUnknown **)ppD3D8);
398 IWineD3D_Release(pWineD3D);
399 } else {
400 FIXME("Call to IWineD3DDevice_GetDirect3D failed\n");
401 *ppD3D8 = NULL;
402 }
403 wined3d_mutex_unlock();
404
405 TRACE("(%p) returning %p\n",This , *ppD3D8);
406
407 return hr;
408}
409
410static HRESULT WINAPI IDirect3DDevice8Impl_GetDeviceCaps(LPDIRECT3DDEVICE8 iface, D3DCAPS8* pCaps) {
411 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
412 HRESULT hrc = D3D_OK;
413 WINED3DCAPS *pWineCaps;
414
415 TRACE("iface %p, caps %p.\n", iface, pCaps);
416
417 if(NULL == pCaps){
418 return D3DERR_INVALIDCALL;
419 }
420 pWineCaps = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WINED3DCAPS));
421 if(pWineCaps == NULL){
422 return D3DERR_INVALIDCALL; /* well this is what MSDN says to return */
423 }
424
425 wined3d_mutex_lock();
426 hrc = IWineD3DDevice_GetDeviceCaps(This->WineD3DDevice, pWineCaps);
427 wined3d_mutex_unlock();
428
429 fixup_caps(pWineCaps);
430 WINECAPSTOD3D8CAPS(pCaps, pWineCaps)
431 HeapFree(GetProcessHeap(), 0, pWineCaps);
432
433 TRACE("Returning %p %p\n", This, pCaps);
434 return hrc;
435}
436
437static HRESULT WINAPI IDirect3DDevice8Impl_GetDisplayMode(LPDIRECT3DDEVICE8 iface, D3DDISPLAYMODE* pMode) {
438 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
439 HRESULT hr;
440
441 TRACE("iface %p, mode %p.\n", iface, pMode);
442
443 wined3d_mutex_lock();
444 hr = IWineD3DDevice_GetDisplayMode(This->WineD3DDevice, 0, (WINED3DDISPLAYMODE *) pMode);
445 wined3d_mutex_unlock();
446
447 if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format);
448
449 return hr;
450}
451
452static HRESULT WINAPI IDirect3DDevice8Impl_GetCreationParameters(LPDIRECT3DDEVICE8 iface, D3DDEVICE_CREATION_PARAMETERS *pParameters) {
453 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
454 HRESULT hr;
455
456 TRACE("iface %p, parameters %p.\n", iface, pParameters);
457
458 wined3d_mutex_lock();
459 hr = IWineD3DDevice_GetCreationParameters(This->WineD3DDevice, (WINED3DDEVICE_CREATION_PARAMETERS *) pParameters);
460 wined3d_mutex_unlock();
461
462 return hr;
463}
464
465static HRESULT WINAPI IDirect3DDevice8Impl_SetCursorProperties(LPDIRECT3DDEVICE8 iface, UINT XHotSpot, UINT YHotSpot, IDirect3DSurface8* pCursorBitmap) {
466 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
467 IDirect3DSurface8Impl *pSurface = (IDirect3DSurface8Impl*)pCursorBitmap;
468 HRESULT hr;
469
470 TRACE("iface %p, hotspot_x %u, hotspot_y %u, bitmap %p.\n",
471 iface, XHotSpot, YHotSpot, pCursorBitmap);
472
473 if(!pCursorBitmap) {
474 WARN("No cursor bitmap, returning WINED3DERR_INVALIDCALL\n");
475 return WINED3DERR_INVALIDCALL;
476 }
477
478 wined3d_mutex_lock();
479 hr = IWineD3DDevice_SetCursorProperties(This->WineD3DDevice,XHotSpot,YHotSpot,pSurface->wineD3DSurface);
480 wined3d_mutex_unlock();
481
482 return hr;
483}
484
485static void WINAPI IDirect3DDevice8Impl_SetCursorPosition(LPDIRECT3DDEVICE8 iface, UINT XScreenSpace, UINT YScreenSpace, DWORD Flags) {
486 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
487
488 TRACE("iface %p, x %u, y %u, flags %#x.\n",
489 iface, XScreenSpace, YScreenSpace, Flags);
490
491 wined3d_mutex_lock();
492 IWineD3DDevice_SetCursorPosition(This->WineD3DDevice, XScreenSpace, YScreenSpace, Flags);
493 wined3d_mutex_unlock();
494}
495
496static BOOL WINAPI IDirect3DDevice8Impl_ShowCursor(LPDIRECT3DDEVICE8 iface, BOOL bShow) {
497 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
498 BOOL ret;
499
500 TRACE("iface %p, show %#x.\n", iface, bShow);
501
502 wined3d_mutex_lock();
503 ret = IWineD3DDevice_ShowCursor(This->WineD3DDevice, bShow);
504 wined3d_mutex_unlock();
505
506 return ret;
507}
508
509static HRESULT WINAPI IDirect3DDevice8Impl_CreateAdditionalSwapChain(IDirect3DDevice8 *iface,
510 D3DPRESENT_PARAMETERS *present_parameters, IDirect3DSwapChain8 **swapchain)
511{
512 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
513 IDirect3DSwapChain8Impl *object;
514 HRESULT hr;
515
516 TRACE("iface %p, present_parameters %p, swapchain %p.\n",
517 iface, present_parameters, swapchain);
518
519 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
520 if (!object)
521 {
522 ERR("Failed to allocate swapchain memory.\n");
523 return E_OUTOFMEMORY;
524 }
525
526 hr = swapchain_init(object, This, present_parameters);
527 if (FAILED(hr))
528 {
529 WARN("Failed to initialize swapchain, hr %#x.\n", hr);
530 HeapFree(GetProcessHeap(), 0, object);
531 return hr;
532 }
533
534 TRACE("Created swapchain %p.\n", object);
535 *swapchain = (IDirect3DSwapChain8 *)object;
536
537 return D3D_OK;
538}
539
540static HRESULT WINAPI IDirect3DDevice8Impl_Reset(LPDIRECT3DDEVICE8 iface, D3DPRESENT_PARAMETERS* pPresentationParameters) {
541 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
542 WINED3DPRESENT_PARAMETERS localParameters;
543 HRESULT hr;
544
545 TRACE("iface %p, present_parameters %p.\n", iface, pPresentationParameters);
546
547 localParameters.BackBufferWidth = pPresentationParameters->BackBufferWidth;
548 localParameters.BackBufferHeight = pPresentationParameters->BackBufferHeight;
549 localParameters.BackBufferFormat = wined3dformat_from_d3dformat(pPresentationParameters->BackBufferFormat);
550 localParameters.BackBufferCount = pPresentationParameters->BackBufferCount;
551 localParameters.MultiSampleType = pPresentationParameters->MultiSampleType;
552 localParameters.MultiSampleQuality = 0; /* d3d9 only */
553 localParameters.SwapEffect = pPresentationParameters->SwapEffect;
554 localParameters.hDeviceWindow = pPresentationParameters->hDeviceWindow;
555 localParameters.Windowed = pPresentationParameters->Windowed;
556 localParameters.EnableAutoDepthStencil = pPresentationParameters->EnableAutoDepthStencil;
557 localParameters.AutoDepthStencilFormat = wined3dformat_from_d3dformat(pPresentationParameters->AutoDepthStencilFormat);
558 localParameters.Flags = pPresentationParameters->Flags;
559 localParameters.FullScreen_RefreshRateInHz = pPresentationParameters->FullScreen_RefreshRateInHz;
560 localParameters.PresentationInterval = pPresentationParameters->FullScreen_PresentationInterval;
561 localParameters.AutoRestoreDisplayMode = TRUE;
562
563 wined3d_mutex_lock();
564 hr = IWineD3DDevice_Reset(This->WineD3DDevice, &localParameters);
565 if(SUCCEEDED(hr)) {
566 hr = IWineD3DDevice_SetRenderState(This->WineD3DDevice, WINED3DRS_POINTSIZE_MIN, 0);
567 }
568 wined3d_mutex_unlock();
569
570 pPresentationParameters->BackBufferWidth = localParameters.BackBufferWidth;
571 pPresentationParameters->BackBufferHeight = localParameters.BackBufferHeight;
572 pPresentationParameters->BackBufferFormat = d3dformat_from_wined3dformat(localParameters.BackBufferFormat);
573 pPresentationParameters->BackBufferCount = localParameters.BackBufferCount;
574 pPresentationParameters->MultiSampleType = localParameters.MultiSampleType;
575 pPresentationParameters->SwapEffect = localParameters.SwapEffect;
576 pPresentationParameters->hDeviceWindow = localParameters.hDeviceWindow;
577 pPresentationParameters->Windowed = localParameters.Windowed;
578 pPresentationParameters->EnableAutoDepthStencil = localParameters.EnableAutoDepthStencil;
579 pPresentationParameters->AutoDepthStencilFormat = d3dformat_from_wined3dformat(localParameters.AutoDepthStencilFormat);
580 pPresentationParameters->Flags = localParameters.Flags;
581 pPresentationParameters->FullScreen_RefreshRateInHz = localParameters.FullScreen_RefreshRateInHz;
582 pPresentationParameters->FullScreen_PresentationInterval = localParameters.PresentationInterval;
583
584 return hr;
585}
586
587static HRESULT WINAPI IDirect3DDevice8Impl_Present(LPDIRECT3DDEVICE8 iface, CONST RECT* pSourceRect,CONST RECT* pDestRect,HWND hDestWindowOverride,CONST RGNDATA* pDirtyRegion) {
588 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
589 HRESULT hr;
590
591 TRACE("iface %p, src_rect %p, dst_rect %p, dst_window_override %p, dirty_region %p.\n",
592 iface, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
593
594 wined3d_mutex_lock();
595 hr = IWineD3DDevice_Present(This->WineD3DDevice, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
596 wined3d_mutex_unlock();
597
598 return hr;
599}
600
601static HRESULT WINAPI IDirect3DDevice8Impl_GetBackBuffer(LPDIRECT3DDEVICE8 iface, UINT BackBuffer, D3DBACKBUFFER_TYPE Type, IDirect3DSurface8** ppBackBuffer) {
602 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
603 IWineD3DSurface *retSurface = NULL;
604 HRESULT rc = D3D_OK;
605
606 TRACE("iface %p, backbuffer_idx %u, backbuffer_type %#x, backbuffer %p.\n",
607 iface, BackBuffer, Type, ppBackBuffer);
608
609 wined3d_mutex_lock();
610 rc = IWineD3DDevice_GetBackBuffer(This->WineD3DDevice, 0, BackBuffer, (WINED3DBACKBUFFER_TYPE) Type, &retSurface);
611 if (rc == D3D_OK && NULL != retSurface && NULL != ppBackBuffer) {
612 IWineD3DSurface_GetParent(retSurface, (IUnknown **)ppBackBuffer);
613 IWineD3DSurface_Release(retSurface);
614 }
615 wined3d_mutex_unlock();
616
617 return rc;
618}
619
620static HRESULT WINAPI IDirect3DDevice8Impl_GetRasterStatus(LPDIRECT3DDEVICE8 iface, D3DRASTER_STATUS* pRasterStatus) {
621 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
622 HRESULT hr;
623
624 TRACE("iface %p, raster_status %p.\n", iface, pRasterStatus);
625
626 wined3d_mutex_lock();
627 hr = IWineD3DDevice_GetRasterStatus(This->WineD3DDevice, 0, (WINED3DRASTER_STATUS *) pRasterStatus);
628 wined3d_mutex_unlock();
629
630 return hr;
631}
632
633static void WINAPI IDirect3DDevice8Impl_SetGammaRamp(LPDIRECT3DDEVICE8 iface, DWORD Flags, CONST D3DGAMMARAMP* pRamp) {
634 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
635
636 TRACE("iface %p, flags %#x, ramp %p.\n", iface, Flags, pRamp);
637
638 /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
639 wined3d_mutex_lock();
640 IWineD3DDevice_SetGammaRamp(This->WineD3DDevice, 0, Flags, (CONST WINED3DGAMMARAMP *) pRamp);
641 wined3d_mutex_unlock();
642}
643
644static void WINAPI IDirect3DDevice8Impl_GetGammaRamp(LPDIRECT3DDEVICE8 iface, D3DGAMMARAMP* pRamp) {
645 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
646
647 TRACE("iface %p, ramp %p.\n", iface, pRamp);
648
649 /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
650 wined3d_mutex_lock();
651 IWineD3DDevice_GetGammaRamp(This->WineD3DDevice, 0, (WINED3DGAMMARAMP *) pRamp);
652 wined3d_mutex_unlock();
653}
654
655static HRESULT WINAPI IDirect3DDevice8Impl_CreateTexture(IDirect3DDevice8 *iface,
656 UINT width, UINT height, UINT levels, DWORD usage, D3DFORMAT format,
657 D3DPOOL pool, IDirect3DTexture8 **texture)
658{
659 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
660 IDirect3DTexture8Impl *object;
661 HRESULT hr;
662
663 TRACE("iface %p, width %u, height %u, levels %u, usage %#x, format %#x, pool %#x, texture %p.\n",
664 iface, width, height, levels, usage, format, pool, texture);
665
666 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
667 if (!object)
668 {
669 ERR("Failed to allocate texture memory.\n");
670 return D3DERR_OUTOFVIDEOMEMORY;
671 }
672
673 hr = texture_init(object, This, width, height, levels, usage, format, pool);
674 if (FAILED(hr))
675 {
676 WARN("Failed to initialize texture, hr %#x.\n", hr);
677 HeapFree(GetProcessHeap(), 0, object);
678 return hr;
679 }
680
681 TRACE("Created texture %p.\n", object);
682 *texture = (IDirect3DTexture8 *)object;
683
684 return D3D_OK;
685}
686
687static HRESULT WINAPI IDirect3DDevice8Impl_CreateVolumeTexture(IDirect3DDevice8 *iface,
688 UINT width, UINT height, UINT depth, UINT levels, DWORD usage, D3DFORMAT format,
689 D3DPOOL pool, IDirect3DVolumeTexture8 **texture)
690{
691 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
692 IDirect3DVolumeTexture8Impl *object;
693 HRESULT hr;
694
695 TRACE("iface %p, width %u, height %u, depth %u, levels %u, usage %#x, format %#x, pool %#x, texture %p.\n",
696 iface, width, height, depth, levels, usage, format, pool, texture);
697
698 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
699 if (!object)
700 {
701 ERR("Failed to allocate volume texture memory.\n");
702 return D3DERR_OUTOFVIDEOMEMORY;
703 }
704
705 hr = volumetexture_init(object, This, width, height, depth, levels, usage, format, pool);
706 if (FAILED(hr))
707 {
708 WARN("Failed to initialize volume texture, hr %#x.\n", hr);
709 HeapFree(GetProcessHeap(), 0, object);
710 return hr;
711 }
712
713 TRACE("Created volume texture %p.\n", object);
714 *texture = (IDirect3DVolumeTexture8 *)object;
715
716 return D3D_OK;
717}
718
719static HRESULT WINAPI IDirect3DDevice8Impl_CreateCubeTexture(IDirect3DDevice8 *iface, UINT edge_length,
720 UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool, IDirect3DCubeTexture8 **texture)
721{
722 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
723 IDirect3DCubeTexture8Impl *object;
724 HRESULT hr;
725
726 TRACE("iface %p, edge_length %u, levels %u, usage %#x, format %#x, pool %#x, texture %p.\n",
727 iface, edge_length, levels, usage, format, pool, texture);
728
729 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
730 if (!object)
731 {
732 ERR("Failed to allocate cube texture memory.\n");
733 return D3DERR_OUTOFVIDEOMEMORY;
734 }
735
736 hr = cubetexture_init(object, This, edge_length, levels, usage, format, pool);
737 if (FAILED(hr))
738 {
739 WARN("Failed to initialize cube texture, hr %#x.\n", hr);
740 HeapFree(GetProcessHeap(), 0, object);
741 return hr;
742 }
743
744 TRACE("Created cube texture %p.\n", object);
745 *texture = (IDirect3DCubeTexture8 *)object;
746
747 return hr;
748}
749
750static HRESULT WINAPI IDirect3DDevice8Impl_CreateVertexBuffer(IDirect3DDevice8 *iface, UINT size, DWORD usage,
751 DWORD fvf, D3DPOOL pool, IDirect3DVertexBuffer8 **buffer)
752{
753 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
754 IDirect3DVertexBuffer8Impl *object;
755 HRESULT hr;
756
757 TRACE("iface %p, size %u, usage %#x, fvf %#x, pool %#x, buffer %p.\n",
758 iface, size, usage, fvf, pool, buffer);
759
760 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
761 if (!object)
762 {
763 ERR("Failed to allocate buffer memory.\n");
764 return D3DERR_OUTOFVIDEOMEMORY;
765 }
766
767 hr = vertexbuffer_init(object, This, size, usage, fvf, pool);
768 if (FAILED(hr))
769 {
770 WARN("Failed to initialize vertex buffer, hr %#x.\n", hr);
771 HeapFree(GetProcessHeap(), 0, object);
772 return hr;
773 }
774
775 TRACE("Created vertex buffer %p.\n", object);
776 *buffer = (IDirect3DVertexBuffer8 *)object;
777
778 return D3D_OK;
779}
780
781static HRESULT WINAPI IDirect3DDevice8Impl_CreateIndexBuffer(IDirect3DDevice8 *iface, UINT size, DWORD usage,
782 D3DFORMAT format, D3DPOOL pool, IDirect3DIndexBuffer8 **buffer)
783{
784 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
785 IDirect3DIndexBuffer8Impl *object;
786 HRESULT hr;
787
788 TRACE("iface %p, size %u, usage %#x, format %#x, pool %#x, buffer %p.\n",
789 iface, size, usage, format, pool, buffer);
790
791 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
792 if (!object)
793 {
794 ERR("Failed to allocate buffer memory.\n");
795 return D3DERR_OUTOFVIDEOMEMORY;
796 }
797
798 hr = indexbuffer_init(object, This, size, usage, format, pool);
799 if (FAILED(hr))
800 {
801 WARN("Failed to initialize index buffer, hr %#x.\n", hr);
802 HeapFree(GetProcessHeap(), 0, object);
803 return hr;
804 }
805
806 TRACE("Created index buffer %p.\n", object);
807 *buffer = (IDirect3DIndexBuffer8 *)object;
808
809 return D3D_OK;
810}
811
812static HRESULT IDirect3DDevice8Impl_CreateSurface(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height,
813 D3DFORMAT Format, BOOL Lockable, BOOL Discard, UINT Level, IDirect3DSurface8 **ppSurface,
814 UINT Usage, D3DPOOL Pool, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality)
815{
816 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
817 IDirect3DSurface8Impl *object;
818 HRESULT hr;
819
820 TRACE("iface %p, width %u, height %u, format %#x, lockable %#x, discard %#x, level %u, surface %p,\n"
821 "\tusage %#x, pool %#x, multisample_type %#x, multisample_quality %u.\n",
822 iface, Width, Height, Format, Lockable, Discard, Level, ppSurface,
823 Usage, Pool, MultiSample, MultisampleQuality);
824
825 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DSurface8Impl));
826 if (!object)
827 {
828 FIXME("Failed to allocate surface memory.\n");
829 return D3DERR_OUTOFVIDEOMEMORY;
830 }
831
832 hr = surface_init(object, This, Width, Height, Format, Lockable, Discard,
833 Level, Usage, Pool, MultiSample, MultisampleQuality);
834 if (FAILED(hr))
835 {
836 WARN("Failed to initialize surface, hr %#x.\n", hr);
837 HeapFree(GetProcessHeap(), 0, object);
838 return hr;
839 }
840
841 TRACE("Created surface %p.\n", object);
842 *ppSurface = (IDirect3DSurface8 *)object;
843
844 return D3D_OK;
845}
846
847static HRESULT WINAPI IDirect3DDevice8Impl_CreateRenderTarget(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, BOOL Lockable, IDirect3DSurface8** ppSurface) {
848 HRESULT hr;
849
850 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, lockable %#x, surface %p.\n",
851 iface, Width, Height, Format, MultiSample, Lockable, ppSurface);
852
853 hr = IDirect3DDevice8Impl_CreateSurface(iface, Width, Height, Format, Lockable, FALSE /* Discard */,
854 0 /* Level */, ppSurface, D3DUSAGE_RENDERTARGET, D3DPOOL_DEFAULT, MultiSample, 0);
855
856 return hr;
857}
858
859static HRESULT WINAPI IDirect3DDevice8Impl_CreateDepthStencilSurface(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, IDirect3DSurface8** ppSurface) {
860 HRESULT hr;
861
862 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, surface %p.\n",
863 iface, Width, Height, Format, MultiSample, ppSurface);
864
865 /* TODO: Verify that Discard is false */
866 hr = IDirect3DDevice8Impl_CreateSurface(iface, Width, Height, Format, TRUE /* Lockable */, FALSE,
867 0 /* Level */, ppSurface, D3DUSAGE_DEPTHSTENCIL, D3DPOOL_DEFAULT, MultiSample, 0);
868
869 return hr;
870}
871
872/* IDirect3DDevice8Impl::CreateImageSurface returns surface with pool type SYSTEMMEM */
873static HRESULT WINAPI IDirect3DDevice8Impl_CreateImageSurface(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height, D3DFORMAT Format, IDirect3DSurface8** ppSurface) {
874 HRESULT hr;
875
876 TRACE("iface %p, width %u, height %u, format %#x, surface %p.\n",
877 iface, Width, Height, Format, ppSurface);
878
879 hr = IDirect3DDevice8Impl_CreateSurface(iface, Width, Height, Format, TRUE /* Lockable */, FALSE /* Discard */,
880 0 /* Level */, ppSurface, 0 /* Usage (undefined/none) */, D3DPOOL_SYSTEMMEM, D3DMULTISAMPLE_NONE,
881 0 /* MultisampleQuality */);
882
883 return hr;
884}
885
886static HRESULT WINAPI IDirect3DDevice8Impl_CopyRects(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8 *pSourceSurface, CONST RECT *pSourceRects, UINT cRects, IDirect3DSurface8 *pDestinationSurface, CONST POINT *pDestPoints) {
887 IDirect3DSurface8Impl *Source = (IDirect3DSurface8Impl *) pSourceSurface;
888 IDirect3DSurface8Impl *Dest = (IDirect3DSurface8Impl *) pDestinationSurface;
889
890 HRESULT hr = WINED3D_OK;
891 WINED3DFORMAT srcFormat, destFormat;
892 WINED3DSURFACE_DESC winedesc;
893
894 TRACE("iface %p, src_surface %p, src_rects %p, rect_count %u, dst_surface %p, dst_points %p.\n",
895 iface, pSourceSurface, pSourceRects, cRects, pDestinationSurface, pDestPoints);
896
897 /* Check that the source texture is in WINED3DPOOL_SYSTEMMEM and the
898 * destination texture is in WINED3DPOOL_DEFAULT. */
899
900 wined3d_mutex_lock();
901 IWineD3DSurface_GetDesc(Source->wineD3DSurface, &winedesc);
902 srcFormat = winedesc.format;
903
904 IWineD3DSurface_GetDesc(Dest->wineD3DSurface, &winedesc);
905 destFormat = winedesc.format;
906
907 /* Check that the source and destination formats match */
908 if (srcFormat != destFormat && WINED3DFMT_UNKNOWN != destFormat) {
909 WARN("(%p) source %p format must match the dest %p format, returning WINED3DERR_INVALIDCALL\n", iface, pSourceSurface, pDestinationSurface);
910 wined3d_mutex_unlock();
911 return WINED3DERR_INVALIDCALL;
912 } else if (WINED3DFMT_UNKNOWN == destFormat) {
913 TRACE("(%p) : Converting destination surface from WINED3DFMT_UNKNOWN to the source format\n", iface);
914 IWineD3DSurface_SetFormat(Dest->wineD3DSurface, srcFormat);
915 }
916
917 /* Quick if complete copy ... */
918 if (cRects == 0 && pSourceRects == NULL && pDestPoints == NULL) {
919 IWineD3DSurface_BltFast(Dest->wineD3DSurface, 0, 0, Source->wineD3DSurface, NULL, WINEDDBLTFAST_NOCOLORKEY);
920 } else {
921 unsigned int i;
922 /* Copy rect by rect */
923 if (NULL != pSourceRects && NULL != pDestPoints) {
924 for (i = 0; i < cRects; ++i) {
925 IWineD3DSurface_BltFast(Dest->wineD3DSurface, pDestPoints[i].x, pDestPoints[i].y, Source->wineD3DSurface, &pSourceRects[i], WINEDDBLTFAST_NOCOLORKEY);
926 }
927 } else {
928 for (i = 0; i < cRects; ++i) {
929 IWineD3DSurface_BltFast(Dest->wineD3DSurface, 0, 0, Source->wineD3DSurface, &pSourceRects[i], WINEDDBLTFAST_NOCOLORKEY);
930 }
931 }
932 }
933 wined3d_mutex_unlock();
934
935 return hr;
936}
937
938static HRESULT WINAPI IDirect3DDevice8Impl_UpdateTexture(LPDIRECT3DDEVICE8 iface, IDirect3DBaseTexture8* pSourceTexture, IDirect3DBaseTexture8* pDestinationTexture) {
939 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
940 HRESULT hr;
941
942 TRACE("iface %p, src_texture %p, dst_texture %p.\n", iface, pSourceTexture, pDestinationTexture);
943
944 wined3d_mutex_lock();
945 hr = IWineD3DDevice_UpdateTexture(This->WineD3DDevice, ((IDirect3DBaseTexture8Impl *)pSourceTexture)->wineD3DBaseTexture, ((IDirect3DBaseTexture8Impl *)pDestinationTexture)->wineD3DBaseTexture);
946 wined3d_mutex_unlock();
947
948 return hr;
949}
950
951static HRESULT WINAPI IDirect3DDevice8Impl_GetFrontBuffer(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8* pDestSurface) {
952 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
953 IDirect3DSurface8Impl *destSurface = (IDirect3DSurface8Impl *)pDestSurface;
954 HRESULT hr;
955
956 TRACE("iface %p, dst_surface %p.\n", iface, pDestSurface);
957
958 if (pDestSurface == NULL) {
959 WARN("(%p) : Caller passed NULL as pDestSurface returning D3DERR_INVALIDCALL\n", This);
960 return D3DERR_INVALIDCALL;
961 }
962
963 wined3d_mutex_lock();
964 hr = IWineD3DDevice_GetFrontBufferData(This->WineD3DDevice, 0, destSurface->wineD3DSurface);
965 wined3d_mutex_unlock();
966
967 return hr;
968}
969
970static HRESULT WINAPI IDirect3DDevice8Impl_SetRenderTarget(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8* pRenderTarget, IDirect3DSurface8* pNewZStencil) {
971 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
972 IDirect3DSurface8Impl *pSurface = (IDirect3DSurface8Impl *)pRenderTarget;
973 IDirect3DSurface8Impl *pZSurface = (IDirect3DSurface8Impl *)pNewZStencil;
974 IWineD3DSurface *original_ds = NULL;
975 HRESULT hr;
976
977 TRACE("iface %p, render_target %p, depth_stencil %p.\n", iface, pRenderTarget, pNewZStencil);
978
979 wined3d_mutex_lock();
980
981 hr = IWineD3DDevice_GetDepthStencilSurface(This->WineD3DDevice, &original_ds);
982 if (hr == WINED3D_OK || hr == WINED3DERR_NOTFOUND)
983 {
984 hr = IWineD3DDevice_SetDepthStencilSurface(This->WineD3DDevice, pZSurface ? pZSurface->wineD3DSurface : NULL);
985 if (SUCCEEDED(hr) && pSurface)
986 hr = IWineD3DDevice_SetRenderTarget(This->WineD3DDevice, 0, pSurface->wineD3DSurface, TRUE);
987 if (FAILED(hr)) IWineD3DDevice_SetDepthStencilSurface(This->WineD3DDevice, original_ds);
988 }
989 if (original_ds) IWineD3DSurface_Release(original_ds);
990
991 wined3d_mutex_unlock();
992
993 return hr;
994}
995
996static HRESULT WINAPI IDirect3DDevice8Impl_GetRenderTarget(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8** ppRenderTarget) {
997 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
998 HRESULT hr = D3D_OK;
999 IWineD3DSurface *pRenderTarget;
1000
1001 TRACE("iface %p, render_target %p.\n", iface, ppRenderTarget);
1002
1003 if (ppRenderTarget == NULL) {
1004 return D3DERR_INVALIDCALL;
1005 }
1006
1007 wined3d_mutex_lock();
1008 hr = IWineD3DDevice_GetRenderTarget(This->WineD3DDevice, 0, &pRenderTarget);
1009
1010 if (hr == D3D_OK && pRenderTarget != NULL) {
1011 IWineD3DSurface_GetParent(pRenderTarget,(IUnknown**)ppRenderTarget);
1012 IWineD3DSurface_Release(pRenderTarget);
1013 } else {
1014 FIXME("Call to IWineD3DDevice_GetRenderTarget failed\n");
1015 *ppRenderTarget = NULL;
1016 }
1017 wined3d_mutex_unlock();
1018
1019 return hr;
1020}
1021
1022static HRESULT WINAPI IDirect3DDevice8Impl_GetDepthStencilSurface(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8** ppZStencilSurface) {
1023 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1024 HRESULT hr = D3D_OK;
1025 IWineD3DSurface *pZStencilSurface;
1026
1027 TRACE("iface %p, depth_stencil %p.\n", iface, ppZStencilSurface);
1028
1029 if(ppZStencilSurface == NULL){
1030 return D3DERR_INVALIDCALL;
1031 }
1032
1033 wined3d_mutex_lock();
1034 hr=IWineD3DDevice_GetDepthStencilSurface(This->WineD3DDevice,&pZStencilSurface);
1035 if (hr == WINED3D_OK) {
1036 IWineD3DSurface_GetParent(pZStencilSurface,(IUnknown**)ppZStencilSurface);
1037 IWineD3DSurface_Release(pZStencilSurface);
1038 }else{
1039 if (hr != WINED3DERR_NOTFOUND)
1040 FIXME("Call to IWineD3DDevice_GetDepthStencilSurface failed with 0x%08x\n", hr);
1041 *ppZStencilSurface = NULL;
1042 }
1043 wined3d_mutex_unlock();
1044
1045 return hr;
1046}
1047
1048static HRESULT WINAPI IDirect3DDevice8Impl_BeginScene(LPDIRECT3DDEVICE8 iface) {
1049 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1050 HRESULT hr;
1051
1052 TRACE("iface %p.\n", iface);
1053
1054 wined3d_mutex_lock();
1055 hr = IWineD3DDevice_BeginScene(This->WineD3DDevice);
1056 wined3d_mutex_unlock();
1057
1058 return hr;
1059}
1060
1061static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDevice8Impl_EndScene(LPDIRECT3DDEVICE8 iface) {
1062 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1063 HRESULT hr;
1064
1065 TRACE("iface %p.\n", iface);
1066
1067 wined3d_mutex_lock();
1068 hr = IWineD3DDevice_EndScene(This->WineD3DDevice);
1069 wined3d_mutex_unlock();
1070
1071 return hr;
1072}
1073
1074static HRESULT WINAPI IDirect3DDevice8Impl_Clear(LPDIRECT3DDEVICE8 iface, DWORD Count, CONST D3DRECT* pRects, DWORD Flags, D3DCOLOR Color, float Z, DWORD Stencil) {
1075 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1076 HRESULT hr;
1077
1078 TRACE("iface %p, rect_count %u, rects %p, flags %#x, color 0x%08x, z %.8e, stencil %u.\n",
1079 iface, Count, pRects, Flags, Color, Z, Stencil);
1080
1081 /* Note: D3DRECT is compatible with WINED3DRECT */
1082 wined3d_mutex_lock();
1083 hr = IWineD3DDevice_Clear(This->WineD3DDevice, Count, (CONST WINED3DRECT*) pRects, Flags, Color, Z, Stencil);
1084 wined3d_mutex_unlock();
1085
1086 return hr;
1087}
1088
1089static HRESULT WINAPI IDirect3DDevice8Impl_SetTransform(LPDIRECT3DDEVICE8 iface, D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX* lpMatrix) {
1090 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1091 HRESULT hr;
1092
1093 TRACE("iface %p, state %#x, matrix %p.\n", iface, State, lpMatrix);
1094
1095 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1096 wined3d_mutex_lock();
1097 hr = IWineD3DDevice_SetTransform(This->WineD3DDevice, State, (CONST WINED3DMATRIX*) lpMatrix);
1098 wined3d_mutex_unlock();
1099
1100 return hr;
1101}
1102
1103static HRESULT WINAPI IDirect3DDevice8Impl_GetTransform(LPDIRECT3DDEVICE8 iface, D3DTRANSFORMSTATETYPE State,D3DMATRIX* pMatrix) {
1104 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1105 HRESULT hr;
1106
1107 TRACE("iface %p, state %#x, matrix %p.\n", iface, State, pMatrix);
1108
1109 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1110 wined3d_mutex_lock();
1111 hr = IWineD3DDevice_GetTransform(This->WineD3DDevice, State, (WINED3DMATRIX*) pMatrix);
1112 wined3d_mutex_unlock();
1113
1114 return hr;
1115}
1116
1117static HRESULT WINAPI IDirect3DDevice8Impl_MultiplyTransform(LPDIRECT3DDEVICE8 iface, D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX* pMatrix) {
1118 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1119 HRESULT hr;
1120
1121 TRACE("iface %p, state %#x, matrix %p.\n", iface, State, pMatrix);
1122
1123 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1124 wined3d_mutex_lock();
1125 hr = IWineD3DDevice_MultiplyTransform(This->WineD3DDevice, State, (CONST WINED3DMATRIX*) pMatrix);
1126 wined3d_mutex_unlock();
1127
1128 return hr;
1129}
1130
1131static HRESULT WINAPI IDirect3DDevice8Impl_SetViewport(LPDIRECT3DDEVICE8 iface, CONST D3DVIEWPORT8* pViewport) {
1132 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1133 HRESULT hr;
1134
1135 TRACE("iface %p, viewport %p.\n", iface, pViewport);
1136
1137 /* Note: D3DVIEWPORT8 is compatible with WINED3DVIEWPORT */
1138 wined3d_mutex_lock();
1139 hr = IWineD3DDevice_SetViewport(This->WineD3DDevice, (const WINED3DVIEWPORT *)pViewport);
1140 wined3d_mutex_unlock();
1141
1142 return hr;
1143}
1144
1145static HRESULT WINAPI IDirect3DDevice8Impl_GetViewport(LPDIRECT3DDEVICE8 iface, D3DVIEWPORT8* pViewport) {
1146 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1147 HRESULT hr;
1148
1149 TRACE("iface %p, viewport %p.\n", iface, pViewport);
1150
1151 /* Note: D3DVIEWPORT8 is compatible with WINED3DVIEWPORT */
1152 wined3d_mutex_lock();
1153 hr = IWineD3DDevice_GetViewport(This->WineD3DDevice, (WINED3DVIEWPORT *)pViewport);
1154 wined3d_mutex_unlock();
1155
1156 return hr;
1157}
1158
1159static HRESULT WINAPI IDirect3DDevice8Impl_SetMaterial(LPDIRECT3DDEVICE8 iface, CONST D3DMATERIAL8* pMaterial) {
1160 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1161 HRESULT hr;
1162
1163 TRACE("iface %p, material %p.\n", iface, pMaterial);
1164
1165 /* Note: D3DMATERIAL8 is compatible with WINED3DMATERIAL */
1166 wined3d_mutex_lock();
1167 hr = IWineD3DDevice_SetMaterial(This->WineD3DDevice, (const WINED3DMATERIAL *)pMaterial);
1168 wined3d_mutex_unlock();
1169
1170 return hr;
1171}
1172
1173static HRESULT WINAPI IDirect3DDevice8Impl_GetMaterial(LPDIRECT3DDEVICE8 iface, D3DMATERIAL8* pMaterial) {
1174 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1175 HRESULT hr;
1176
1177 TRACE("iface %p, material %p.\n", iface, pMaterial);
1178
1179 /* Note: D3DMATERIAL8 is compatible with WINED3DMATERIAL */
1180 wined3d_mutex_lock();
1181 hr = IWineD3DDevice_GetMaterial(This->WineD3DDevice, (WINED3DMATERIAL *)pMaterial);
1182 wined3d_mutex_unlock();
1183
1184 return hr;
1185}
1186
1187static HRESULT WINAPI IDirect3DDevice8Impl_SetLight(LPDIRECT3DDEVICE8 iface, DWORD Index, CONST D3DLIGHT8* pLight) {
1188 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1189 HRESULT hr;
1190
1191 TRACE("iface %p, index %u, light %p.\n", iface, Index, pLight);
1192
1193 /* Note: D3DLIGHT8 is compatible with WINED3DLIGHT */
1194 wined3d_mutex_lock();
1195 hr = IWineD3DDevice_SetLight(This->WineD3DDevice, Index, (const WINED3DLIGHT *)pLight);
1196 wined3d_mutex_unlock();
1197
1198 return hr;
1199}
1200
1201static HRESULT WINAPI IDirect3DDevice8Impl_GetLight(LPDIRECT3DDEVICE8 iface, DWORD Index,D3DLIGHT8* pLight) {
1202 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1203 HRESULT hr;
1204
1205 TRACE("iface %p, index %u, light %p.\n", iface, Index, pLight);
1206
1207 /* Note: D3DLIGHT8 is compatible with WINED3DLIGHT */
1208 wined3d_mutex_lock();
1209 hr = IWineD3DDevice_GetLight(This->WineD3DDevice, Index, (WINED3DLIGHT *)pLight);
1210 wined3d_mutex_unlock();
1211
1212 return hr;
1213}
1214
1215static HRESULT WINAPI IDirect3DDevice8Impl_LightEnable(LPDIRECT3DDEVICE8 iface, DWORD Index,BOOL Enable) {
1216 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1217 HRESULT hr;
1218
1219 TRACE("iface %p, index %u, enable %#x.\n", iface, Index, Enable);
1220
1221 wined3d_mutex_lock();
1222 hr = IWineD3DDevice_SetLightEnable(This->WineD3DDevice, Index, Enable);
1223 wined3d_mutex_unlock();
1224
1225 return hr;
1226}
1227
1228static HRESULT WINAPI IDirect3DDevice8Impl_GetLightEnable(LPDIRECT3DDEVICE8 iface, DWORD Index,BOOL* pEnable) {
1229 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1230 HRESULT hr;
1231
1232 TRACE("iface %p, index %u, enable %p.\n", iface, Index, pEnable);
1233
1234 wined3d_mutex_lock();
1235 hr = IWineD3DDevice_GetLightEnable(This->WineD3DDevice, Index, pEnable);
1236 wined3d_mutex_unlock();
1237
1238 return hr;
1239}
1240
1241static HRESULT WINAPI IDirect3DDevice8Impl_SetClipPlane(LPDIRECT3DDEVICE8 iface, DWORD Index,CONST float* pPlane) {
1242 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1243 HRESULT hr;
1244
1245 TRACE("iface %p, index %u, plane %p.\n", iface, Index, pPlane);
1246
1247 wined3d_mutex_lock();
1248 hr = IWineD3DDevice_SetClipPlane(This->WineD3DDevice, Index, pPlane);
1249 wined3d_mutex_unlock();
1250
1251 return hr;
1252}
1253
1254static HRESULT WINAPI IDirect3DDevice8Impl_GetClipPlane(LPDIRECT3DDEVICE8 iface, DWORD Index,float* pPlane) {
1255 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1256 HRESULT hr;
1257
1258 TRACE("iface %p, index %u, plane %p.\n", iface, Index, pPlane);
1259
1260 wined3d_mutex_lock();
1261 hr = IWineD3DDevice_GetClipPlane(This->WineD3DDevice, Index, pPlane);
1262 wined3d_mutex_unlock();
1263
1264 return hr;
1265}
1266
1267static HRESULT WINAPI IDirect3DDevice8Impl_SetRenderState(LPDIRECT3DDEVICE8 iface, D3DRENDERSTATETYPE State,DWORD Value) {
1268 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1269 HRESULT hr;
1270
1271 TRACE("iface %p, state %#x, value %#x.\n", iface, State, Value);
1272
1273 wined3d_mutex_lock();
1274 hr = IWineD3DDevice_SetRenderState(This->WineD3DDevice, State, Value);
1275 wined3d_mutex_unlock();
1276
1277 return hr;
1278}
1279
1280static HRESULT WINAPI IDirect3DDevice8Impl_GetRenderState(LPDIRECT3DDEVICE8 iface, D3DRENDERSTATETYPE State,DWORD* pValue) {
1281 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1282 HRESULT hr;
1283
1284 TRACE("iface %p, state %#x, value %p.\n", iface, State, pValue);
1285
1286 wined3d_mutex_lock();
1287 hr = IWineD3DDevice_GetRenderState(This->WineD3DDevice, State, pValue);
1288 wined3d_mutex_unlock();
1289
1290 return hr;
1291}
1292
1293static HRESULT WINAPI IDirect3DDevice8Impl_BeginStateBlock(LPDIRECT3DDEVICE8 iface) {
1294 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1295 HRESULT hr;
1296
1297 TRACE("iface %p.\n", iface);
1298
1299 wined3d_mutex_lock();
1300 hr = IWineD3DDevice_BeginStateBlock(This->WineD3DDevice);
1301 wined3d_mutex_unlock();
1302
1303 return hr;
1304}
1305
1306static HRESULT WINAPI IDirect3DDevice8Impl_EndStateBlock(LPDIRECT3DDEVICE8 iface, DWORD* pToken) {
1307 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1308 IWineD3DStateBlock *stateblock;
1309 HRESULT hr;
1310
1311 TRACE("iface %p, token %p.\n", iface, pToken);
1312
1313 /* Tell wineD3D to endstateblock before anything else (in case we run out
1314 * of memory later and cause locking problems)
1315 */
1316 wined3d_mutex_lock();
1317 hr = IWineD3DDevice_EndStateBlock(This->WineD3DDevice , &stateblock);
1318 if (hr != D3D_OK) {
1319 WARN("IWineD3DDevice_EndStateBlock returned an error\n");
1320 wined3d_mutex_unlock();
1321 return hr;
1322 }
1323
1324 *pToken = d3d8_allocate_handle(&This->handle_table, stateblock, D3D8_HANDLE_SB);
1325 wined3d_mutex_unlock();
1326
1327 if (*pToken == D3D8_INVALID_HANDLE)
1328 {
1329 ERR("Failed to create a handle\n");
1330 wined3d_mutex_lock();
1331 IWineD3DStateBlock_Release(stateblock);
1332 wined3d_mutex_unlock();
1333 return E_FAIL;
1334 }
1335 ++*pToken;
1336
1337 TRACE("Returning %#x (%p).\n", *pToken, stateblock);
1338
1339 return hr;
1340}
1341
1342static HRESULT WINAPI IDirect3DDevice8Impl_ApplyStateBlock(LPDIRECT3DDEVICE8 iface, DWORD Token) {
1343 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1344 IWineD3DStateBlock *stateblock;
1345 HRESULT hr;
1346
1347 TRACE("iface %p, token %#x.\n", iface, Token);
1348
1349 wined3d_mutex_lock();
1350 stateblock = d3d8_get_object(&This->handle_table, Token - 1, D3D8_HANDLE_SB);
1351 if (!stateblock)
1352 {
1353 WARN("Invalid handle (%#x) passed.\n", Token);
1354 wined3d_mutex_unlock();
1355 return D3DERR_INVALIDCALL;
1356 }
1357 hr = IWineD3DStateBlock_Apply(stateblock);
1358 wined3d_mutex_unlock();
1359
1360 return hr;
1361}
1362
1363static HRESULT WINAPI IDirect3DDevice8Impl_CaptureStateBlock(LPDIRECT3DDEVICE8 iface, DWORD Token) {
1364 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1365 IWineD3DStateBlock *stateblock;
1366 HRESULT hr;
1367
1368 TRACE("iface %p, token %#x.\n", iface, Token);
1369
1370 wined3d_mutex_lock();
1371 stateblock = d3d8_get_object(&This->handle_table, Token - 1, D3D8_HANDLE_SB);
1372 if (!stateblock)
1373 {
1374 WARN("Invalid handle (%#x) passed.\n", Token);
1375 wined3d_mutex_unlock();
1376 return D3DERR_INVALIDCALL;
1377 }
1378 hr = IWineD3DStateBlock_Capture(stateblock);
1379 wined3d_mutex_unlock();
1380
1381 return hr;
1382}
1383
1384static HRESULT WINAPI IDirect3DDevice8Impl_DeleteStateBlock(LPDIRECT3DDEVICE8 iface, DWORD Token) {
1385 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1386 IWineD3DStateBlock *stateblock;
1387
1388 TRACE("iface %p, token %#x.\n", iface, Token);
1389
1390 wined3d_mutex_lock();
1391 stateblock = d3d8_free_handle(&This->handle_table, Token - 1, D3D8_HANDLE_SB);
1392
1393 if (!stateblock)
1394 {
1395 WARN("Invalid handle (%#x) passed.\n", Token);
1396 wined3d_mutex_unlock();
1397 return D3DERR_INVALIDCALL;
1398 }
1399
1400 if (IWineD3DStateBlock_Release((IUnknown *)stateblock))
1401 {
1402 ERR("Stateblock %p has references left, this shouldn't happen.\n", stateblock);
1403 }
1404 wined3d_mutex_unlock();
1405
1406 return D3D_OK;
1407}
1408
1409static HRESULT WINAPI IDirect3DDevice8Impl_CreateStateBlock(IDirect3DDevice8 *iface,
1410 D3DSTATEBLOCKTYPE Type, DWORD *handle)
1411{
1412 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1413 IWineD3DStateBlock *stateblock;
1414 HRESULT hr;
1415
1416 TRACE("iface %p, type %#x, handle %p.\n", iface, Type, handle);
1417
1418 if (Type != D3DSBT_ALL
1419 && Type != D3DSBT_PIXELSTATE
1420 && Type != D3DSBT_VERTEXSTATE)
1421 {
1422 WARN("Unexpected stateblock type, returning D3DERR_INVALIDCALL\n");
1423 return D3DERR_INVALIDCALL;
1424 }
1425
1426 wined3d_mutex_lock();
1427 hr = IWineD3DDevice_CreateStateBlock(This->WineD3DDevice, (WINED3DSTATEBLOCKTYPE)Type,
1428 &stateblock, NULL);
1429 if (FAILED(hr))
1430 {
1431 wined3d_mutex_unlock();
1432 ERR("IWineD3DDevice_CreateStateBlock failed, hr %#x\n", hr);
1433 return hr;
1434 }
1435
1436 *handle = d3d8_allocate_handle(&This->handle_table, stateblock, D3D8_HANDLE_SB);
1437 wined3d_mutex_unlock();
1438
1439 if (*handle == D3D8_INVALID_HANDLE)
1440 {
1441 ERR("Failed to allocate a handle.\n");
1442 wined3d_mutex_lock();
1443 IWineD3DStateBlock_Release(stateblock);
1444 wined3d_mutex_unlock();
1445 return E_FAIL;
1446 }
1447 ++*handle;
1448
1449 TRACE("Returning %#x (%p).\n", *handle, stateblock);
1450
1451 return hr;
1452}
1453
1454static HRESULT WINAPI IDirect3DDevice8Impl_SetClipStatus(LPDIRECT3DDEVICE8 iface, CONST D3DCLIPSTATUS8* pClipStatus) {
1455 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1456 HRESULT hr;
1457
1458 TRACE("iface %p, clip_status %p.\n", iface, pClipStatus);
1459/* FIXME: Verify that D3DCLIPSTATUS8 ~= WINED3DCLIPSTATUS */
1460
1461 wined3d_mutex_lock();
1462 hr = IWineD3DDevice_SetClipStatus(This->WineD3DDevice, (const WINED3DCLIPSTATUS *)pClipStatus);
1463 wined3d_mutex_unlock();
1464
1465 return hr;
1466}
1467
1468static HRESULT WINAPI IDirect3DDevice8Impl_GetClipStatus(LPDIRECT3DDEVICE8 iface, D3DCLIPSTATUS8* pClipStatus) {
1469 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1470 HRESULT hr;
1471
1472 TRACE("iface %p, clip_status %p.\n", iface, pClipStatus);
1473
1474 wined3d_mutex_lock();
1475 hr = IWineD3DDevice_GetClipStatus(This->WineD3DDevice, (WINED3DCLIPSTATUS *)pClipStatus);
1476 wined3d_mutex_unlock();
1477
1478 return hr;
1479}
1480
1481static HRESULT WINAPI IDirect3DDevice8Impl_GetTexture(LPDIRECT3DDEVICE8 iface, DWORD Stage,IDirect3DBaseTexture8** ppTexture) {
1482 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1483 IWineD3DBaseTexture *retTexture;
1484 HRESULT hr;
1485
1486 TRACE("iface %p, stage %u, texture %p.\n", iface, Stage, ppTexture);
1487
1488 if(ppTexture == NULL){
1489 return D3DERR_INVALIDCALL;
1490 }
1491
1492 wined3d_mutex_lock();
1493 hr = IWineD3DDevice_GetTexture(This->WineD3DDevice, Stage, &retTexture);
1494 if (FAILED(hr))
1495 {
1496 WARN("Failed to get texture for stage %u, hr %#x.\n", Stage, hr);
1497 wined3d_mutex_unlock();
1498 *ppTexture = NULL;
1499 return hr;
1500 }
1501
1502 if (retTexture)
1503 {
1504 IWineD3DBaseTexture_GetParent(retTexture, (IUnknown **)ppTexture);
1505 IWineD3DBaseTexture_Release(retTexture);
1506 }
1507 else
1508 {
1509 *ppTexture = NULL;
1510 }
1511 wined3d_mutex_unlock();
1512
1513 return D3D_OK;
1514}
1515
1516static HRESULT WINAPI IDirect3DDevice8Impl_SetTexture(LPDIRECT3DDEVICE8 iface, DWORD Stage, IDirect3DBaseTexture8* pTexture) {
1517 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1518 HRESULT hr;
1519
1520 TRACE("iface %p, stage %u, texture %p.\n", iface, Stage, pTexture);
1521
1522 wined3d_mutex_lock();
1523 hr = IWineD3DDevice_SetTexture(This->WineD3DDevice, Stage,
1524 pTexture==NULL ? NULL : ((IDirect3DBaseTexture8Impl *)pTexture)->wineD3DBaseTexture);
1525 wined3d_mutex_unlock();
1526
1527 return hr;
1528}
1529
1530static const struct tss_lookup
1531{
1532 BOOL sampler_state;
1533 DWORD state;
1534}
1535tss_lookup[] =
1536{
1537 {FALSE, WINED3DTSS_FORCE_DWORD}, /* 0, unused */
1538 {FALSE, WINED3DTSS_COLOROP}, /* 1, D3DTSS_COLOROP */
1539 {FALSE, WINED3DTSS_COLORARG1}, /* 2, D3DTSS_COLORARG1 */
1540 {FALSE, WINED3DTSS_COLORARG2}, /* 3, D3DTSS_COLORARG2 */
1541 {FALSE, WINED3DTSS_ALPHAOP}, /* 4, D3DTSS_ALPHAOP */
1542 {FALSE, WINED3DTSS_ALPHAARG1}, /* 5, D3DTSS_ALPHAARG1 */
1543 {FALSE, WINED3DTSS_ALPHAARG2}, /* 6, D3DTSS_ALPHAARG2 */
1544 {FALSE, WINED3DTSS_BUMPENVMAT00}, /* 7, D3DTSS_BUMPENVMAT00 */
1545 {FALSE, WINED3DTSS_BUMPENVMAT01}, /* 8, D3DTSS_BUMPENVMAT01 */
1546 {FALSE, WINED3DTSS_BUMPENVMAT10}, /* 9, D3DTSS_BUMPENVMAT10 */
1547 {FALSE, WINED3DTSS_BUMPENVMAT11}, /* 10, D3DTSS_BUMPENVMAT11 */
1548 {FALSE, WINED3DTSS_TEXCOORDINDEX}, /* 11, D3DTSS_TEXCOORDINDEX */
1549 {FALSE, WINED3DTSS_FORCE_DWORD}, /* 12, unused */
1550 {TRUE, WINED3DSAMP_ADDRESSU}, /* 13, D3DTSS_ADDRESSU */
1551 {TRUE, WINED3DSAMP_ADDRESSV}, /* 14, D3DTSS_ADDRESSV */
1552 {TRUE, WINED3DSAMP_BORDERCOLOR}, /* 15, D3DTSS_BORDERCOLOR */
1553 {TRUE, WINED3DSAMP_MAGFILTER}, /* 16, D3DTSS_MAGFILTER */
1554 {TRUE, WINED3DSAMP_MINFILTER}, /* 17, D3DTSS_MINFILTER */
1555 {TRUE, WINED3DSAMP_MIPFILTER}, /* 18, D3DTSS_MIPFILTER */
1556 {TRUE, WINED3DSAMP_MIPMAPLODBIAS}, /* 19, D3DTSS_MIPMAPLODBIAS */
1557 {TRUE, WINED3DSAMP_MAXMIPLEVEL}, /* 20, D3DTSS_MAXMIPLEVEL */
1558 {TRUE, WINED3DSAMP_MAXANISOTROPY}, /* 21, D3DTSS_MAXANISOTROPY */
1559 {FALSE, WINED3DTSS_BUMPENVLSCALE}, /* 22, D3DTSS_BUMPENVLSCALE */
1560 {FALSE, WINED3DTSS_BUMPENVLOFFSET}, /* 23, D3DTSS_BUMPENVLOFFSET */
1561 {FALSE, WINED3DTSS_TEXTURETRANSFORMFLAGS}, /* 24, D3DTSS_TEXTURETRANSFORMFLAGS */
1562 {TRUE, WINED3DSAMP_ADDRESSW}, /* 25, D3DTSS_ADDRESSW */
1563 {FALSE, WINED3DTSS_COLORARG0}, /* 26, D3DTSS_COLORARG0 */
1564 {FALSE, WINED3DTSS_ALPHAARG0}, /* 27, D3DTSS_ALPHAARG0 */
1565 {FALSE, WINED3DTSS_RESULTARG}, /* 28, D3DTSS_RESULTARG */
1566};
1567
1568static HRESULT WINAPI IDirect3DDevice8Impl_GetTextureStageState(LPDIRECT3DDEVICE8 iface, DWORD Stage,D3DTEXTURESTAGESTATETYPE Type,DWORD* pValue) {
1569 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1570 const struct tss_lookup *l = &tss_lookup[Type];
1571 HRESULT hr;
1572
1573 TRACE("iface %p, stage %u, state %#x, value %p.\n", iface, Stage, Type, pValue);
1574
1575 wined3d_mutex_lock();
1576 if (l->sampler_state) hr = IWineD3DDevice_GetSamplerState(This->WineD3DDevice, Stage, l->state, pValue);
1577 else hr = IWineD3DDevice_GetTextureStageState(This->WineD3DDevice, Stage, l->state, pValue);
1578 wined3d_mutex_unlock();
1579
1580 return hr;
1581}
1582
1583static HRESULT WINAPI IDirect3DDevice8Impl_SetTextureStageState(LPDIRECT3DDEVICE8 iface, DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD Value) {
1584 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1585 const struct tss_lookup *l = &tss_lookup[Type];
1586 HRESULT hr;
1587
1588 TRACE("iface %p, stage %u, state %#x, value %#x.\n", iface, Stage, Type, Value);
1589
1590 wined3d_mutex_lock();
1591 if (l->sampler_state) hr = IWineD3DDevice_SetSamplerState(This->WineD3DDevice, Stage, l->state, Value);
1592 else hr = IWineD3DDevice_SetTextureStageState(This->WineD3DDevice, Stage, l->state, Value);
1593 wined3d_mutex_unlock();
1594
1595 return hr;
1596}
1597
1598static HRESULT WINAPI IDirect3DDevice8Impl_ValidateDevice(LPDIRECT3DDEVICE8 iface, DWORD* pNumPasses) {
1599 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1600 HRESULT hr;
1601
1602 TRACE("iface %p, pass_count %p.\n", iface, pNumPasses);
1603
1604 wined3d_mutex_lock();
1605 hr = IWineD3DDevice_ValidateDevice(This->WineD3DDevice, pNumPasses);
1606 wined3d_mutex_unlock();
1607
1608 return hr;
1609}
1610
1611static HRESULT WINAPI IDirect3DDevice8Impl_GetInfo(IDirect3DDevice8 *iface,
1612 DWORD info_id, void *info, DWORD info_size)
1613{
1614 FIXME("iface %p, info_id %#x, info %p, info_size %u stub!\n", iface, info_id, info, info_size);
1615
1616 return D3D_OK;
1617}
1618
1619static HRESULT WINAPI IDirect3DDevice8Impl_SetPaletteEntries(LPDIRECT3DDEVICE8 iface, UINT PaletteNumber, CONST PALETTEENTRY* pEntries) {
1620 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1621 HRESULT hr;
1622
1623 TRACE("iface %p, palette_idx %u, entries %p.\n", iface, PaletteNumber, pEntries);
1624
1625 wined3d_mutex_lock();
1626 hr = IWineD3DDevice_SetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
1627 wined3d_mutex_unlock();
1628
1629 return hr;
1630}
1631
1632static HRESULT WINAPI IDirect3DDevice8Impl_GetPaletteEntries(LPDIRECT3DDEVICE8 iface, UINT PaletteNumber, PALETTEENTRY* pEntries) {
1633 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1634 HRESULT hr;
1635
1636 TRACE("iface %p, palette_idx %u, entries %p.\n", iface, PaletteNumber, pEntries);
1637
1638 wined3d_mutex_lock();
1639 hr = IWineD3DDevice_GetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
1640 wined3d_mutex_unlock();
1641
1642 return hr;
1643}
1644
1645static HRESULT WINAPI IDirect3DDevice8Impl_SetCurrentTexturePalette(LPDIRECT3DDEVICE8 iface, UINT PaletteNumber) {
1646 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1647 HRESULT hr;
1648
1649 TRACE("iface %p, palette_idx %u.\n", iface, PaletteNumber);
1650
1651 wined3d_mutex_lock();
1652 hr = IWineD3DDevice_SetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
1653 wined3d_mutex_unlock();
1654
1655 return hr;
1656}
1657
1658static HRESULT WINAPI IDirect3DDevice8Impl_GetCurrentTexturePalette(LPDIRECT3DDEVICE8 iface, UINT *PaletteNumber) {
1659 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1660 HRESULT hr;
1661
1662 TRACE("iface %p, palette_idx %p.\n", iface, PaletteNumber);
1663
1664 wined3d_mutex_lock();
1665 hr = IWineD3DDevice_GetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
1666 wined3d_mutex_unlock();
1667
1668 return hr;
1669}
1670
1671static HRESULT WINAPI IDirect3DDevice8Impl_DrawPrimitive(IDirect3DDevice8 *iface, D3DPRIMITIVETYPE PrimitiveType,
1672 UINT StartVertex, UINT PrimitiveCount)
1673{
1674 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1675 HRESULT hr;
1676
1677 TRACE("iface %p, primitive_type %#x, start_vertex %u, primitive_count %u.\n",
1678 iface, PrimitiveType, StartVertex, PrimitiveCount);
1679
1680 wined3d_mutex_lock();
1681 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1682 hr = IWineD3DDevice_DrawPrimitive(This->WineD3DDevice, StartVertex,
1683 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount));
1684 wined3d_mutex_unlock();
1685
1686 return hr;
1687}
1688
1689static HRESULT WINAPI IDirect3DDevice8Impl_DrawIndexedPrimitive(LPDIRECT3DDEVICE8 iface, D3DPRIMITIVETYPE PrimitiveType,
1690 UINT MinVertexIndex,UINT NumVertices,UINT startIndex,UINT primCount) {
1691 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1692 HRESULT hr;
1693
1694 TRACE("iface %p, primitive_type %#x, min_vertex_idx %u, vertex_count %u, start_idx %u, primitive_count %u.\n",
1695 iface, PrimitiveType, MinVertexIndex, NumVertices, startIndex, primCount);
1696
1697 wined3d_mutex_lock();
1698 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1699 hr = IWineD3DDevice_DrawIndexedPrimitive(This->WineD3DDevice, startIndex,
1700 vertex_count_from_primitive_count(PrimitiveType, primCount));
1701 wined3d_mutex_unlock();
1702
1703 return hr;
1704}
1705
1706static HRESULT WINAPI IDirect3DDevice8Impl_DrawPrimitiveUP(LPDIRECT3DDEVICE8 iface, D3DPRIMITIVETYPE PrimitiveType,UINT PrimitiveCount,CONST void* pVertexStreamZeroData,UINT VertexStreamZeroStride) {
1707 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1708 HRESULT hr;
1709
1710 TRACE("iface %p, primitive_type %#x, primitive_count %u, data %p, stride %u.\n",
1711 iface, PrimitiveType, PrimitiveCount, pVertexStreamZeroData, VertexStreamZeroStride);
1712
1713 wined3d_mutex_lock();
1714 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1715 hr = IWineD3DDevice_DrawPrimitiveUP(This->WineD3DDevice,
1716 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount),
1717 pVertexStreamZeroData, VertexStreamZeroStride);
1718 wined3d_mutex_unlock();
1719
1720 return hr;
1721}
1722
1723static HRESULT WINAPI IDirect3DDevice8Impl_DrawIndexedPrimitiveUP(LPDIRECT3DDEVICE8 iface, D3DPRIMITIVETYPE PrimitiveType,UINT MinVertexIndex,
1724 UINT NumVertexIndices,UINT PrimitiveCount,CONST void* pIndexData,
1725 D3DFORMAT IndexDataFormat,CONST void* pVertexStreamZeroData,
1726 UINT VertexStreamZeroStride) {
1727 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1728 HRESULT hr;
1729
1730 TRACE("iface %p, primitive_type %#x, min_vertex_idx %u, index_count %u, primitive_count %u,\n"
1731 "index_data %p, index_format %#x, vertex_data %p, vertex_stride %u.\n",
1732 iface, PrimitiveType, MinVertexIndex, NumVertexIndices, PrimitiveCount,
1733 pIndexData, IndexDataFormat, pVertexStreamZeroData, VertexStreamZeroStride);
1734
1735 wined3d_mutex_lock();
1736 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1737 hr = IWineD3DDevice_DrawIndexedPrimitiveUP(This->WineD3DDevice,
1738 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount), pIndexData,
1739 wined3dformat_from_d3dformat(IndexDataFormat), pVertexStreamZeroData, VertexStreamZeroStride);
1740 wined3d_mutex_unlock();
1741
1742 return hr;
1743}
1744
1745static HRESULT WINAPI IDirect3DDevice8Impl_ProcessVertices(LPDIRECT3DDEVICE8 iface, UINT SrcStartIndex,UINT DestIndex,UINT VertexCount,IDirect3DVertexBuffer8* pDestBuffer,DWORD Flags) {
1746 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1747 HRESULT hr;
1748 IDirect3DVertexBuffer8Impl *dest = (IDirect3DVertexBuffer8Impl *) pDestBuffer;
1749
1750 TRACE("iface %p, src_start_idx %u, dst_idx %u, vertex_count %u, dst_buffer %p, flags %#x.\n",
1751 iface, SrcStartIndex, DestIndex, VertexCount, pDestBuffer, Flags);
1752
1753 wined3d_mutex_lock();
1754 hr = IWineD3DDevice_ProcessVertices(This->WineD3DDevice,SrcStartIndex, DestIndex, VertexCount, dest->wineD3DVertexBuffer, NULL, Flags, dest->fvf);
1755 wined3d_mutex_unlock();
1756
1757 return hr;
1758}
1759
1760static HRESULT WINAPI IDirect3DDevice8Impl_CreateVertexShader(IDirect3DDevice8 *iface,
1761 const DWORD *declaration, const DWORD *byte_code, DWORD *shader, DWORD usage)
1762{
1763 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1764 IDirect3DVertexShader8Impl *object;
1765 DWORD shader_handle;
1766 DWORD handle;
1767 HRESULT hr;
1768
1769 TRACE("iface %p, declaration %p, byte_code %p, shader %p, usage %#x.\n",
1770 iface, declaration, byte_code, shader, usage);
1771
1772 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1773 if (!object)
1774 {
1775 ERR("Failed to allocate vertex shader memory.\n");
1776 *shader = 0;
1777 return E_OUTOFMEMORY;
1778 }
1779
1780 wined3d_mutex_lock();
1781 handle = d3d8_allocate_handle(&This->handle_table, object, D3D8_HANDLE_VS);
1782 wined3d_mutex_unlock();
1783 if (handle == D3D8_INVALID_HANDLE)
1784 {
1785 ERR("Failed to allocate vertex shader handle.\n");
1786 HeapFree(GetProcessHeap(), 0, object);
1787 *shader = 0;
1788 return E_OUTOFMEMORY;
1789 }
1790
1791 shader_handle = handle + VS_HIGHESTFIXEDFXF + 1;
1792
1793 hr = vertexshader_init(object, This, declaration, byte_code, shader_handle, usage);
1794 if (FAILED(hr))
1795 {
1796 WARN("Failed to initialize vertex shader, hr %#x.\n", hr);
1797 wined3d_mutex_lock();
1798 d3d8_free_handle(&This->handle_table, handle, D3D8_HANDLE_VS);
1799 wined3d_mutex_unlock();
1800 HeapFree(GetProcessHeap(), 0, object);
1801 *shader = 0;
1802 return hr;
1803 }
1804
1805 TRACE("Created vertex shader %p (handle %#x).\n", object, shader_handle);
1806 *shader = shader_handle;
1807
1808 return D3D_OK;
1809}
1810
1811static IDirect3DVertexDeclaration8Impl *IDirect3DDevice8Impl_FindDecl(IDirect3DDevice8Impl *This, DWORD fvf)
1812{
1813 IDirect3DVertexDeclaration8Impl *d3d8_declaration;
1814 HRESULT hr;
1815 int p, low, high; /* deliberately signed */
1816 struct FvfToDecl *convertedDecls = This->decls;
1817
1818 TRACE("Searching for declaration for fvf %08x... ", fvf);
1819
1820 low = 0;
1821 high = This->numConvertedDecls - 1;
1822 while(low <= high) {
1823 p = (low + high) >> 1;
1824 TRACE("%d ", p);
1825 if(convertedDecls[p].fvf == fvf) {
1826 TRACE("found %p\n", convertedDecls[p].decl);
1827 return (IDirect3DVertexDeclaration8Impl *)convertedDecls[p].decl;
1828 } else if(convertedDecls[p].fvf < fvf) {
1829 low = p + 1;
1830 } else {
1831 high = p - 1;
1832 }
1833 }
1834 TRACE("not found. Creating and inserting at position %d.\n", low);
1835
1836 d3d8_declaration = HeapAlloc(GetProcessHeap(), 0, sizeof(*d3d8_declaration));
1837 if (!d3d8_declaration)
1838 {
1839 ERR("Memory allocation failed.\n");
1840 return NULL;
1841 }
1842
1843 hr = vertexdeclaration_init_fvf(d3d8_declaration, This, fvf);
1844 if (FAILED(hr))
1845 {
1846 WARN("Failed to initialize vertex declaration, hr %#x.\n", hr);
1847 HeapFree(GetProcessHeap(), 0, d3d8_declaration);
1848 return NULL;
1849 }
1850
1851 if(This->declArraySize == This->numConvertedDecls) {
1852 int grow = This->declArraySize / 2;
1853 convertedDecls = HeapReAlloc(GetProcessHeap(), 0, convertedDecls,
1854 sizeof(convertedDecls[0]) * (This->numConvertedDecls + grow));
1855 if(!convertedDecls) {
1856 /* This will destroy it */
1857 IDirect3DVertexDeclaration8_Release((IDirect3DVertexDeclaration8 *)d3d8_declaration);
1858 return NULL;
1859 }
1860 This->decls = convertedDecls;
1861 This->declArraySize += grow;
1862 }
1863
1864 memmove(convertedDecls + low + 1, convertedDecls + low, sizeof(convertedDecls[0]) * (This->numConvertedDecls - low));
1865 convertedDecls[low].decl = (IDirect3DVertexDeclaration8 *)d3d8_declaration;
1866 convertedDecls[low].fvf = fvf;
1867 This->numConvertedDecls++;
1868
1869 TRACE("Returning %p. %u decls in array\n", d3d8_declaration, This->numConvertedDecls);
1870 return d3d8_declaration;
1871}
1872
1873static HRESULT WINAPI IDirect3DDevice8Impl_SetVertexShader(LPDIRECT3DDEVICE8 iface, DWORD pShader) {
1874 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1875 IDirect3DVertexShader8Impl *shader;
1876 HRESULT hr;
1877
1878 TRACE("iface %p, shader %#x.\n", iface, pShader);
1879
1880 if (VS_HIGHESTFIXEDFXF >= pShader) {
1881 TRACE("Setting FVF, %#x\n", pShader);
1882
1883 wined3d_mutex_lock();
1884 IWineD3DDevice_SetVertexDeclaration(This->WineD3DDevice,
1885 IDirect3DDevice8Impl_FindDecl(This, pShader)->wined3d_vertex_declaration);
1886 IWineD3DDevice_SetVertexShader(This->WineD3DDevice, NULL);
1887 wined3d_mutex_unlock();
1888
1889 return D3D_OK;
1890 }
1891
1892 TRACE("Setting shader\n");
1893
1894 wined3d_mutex_lock();
1895 shader = d3d8_get_object(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS);
1896 if (!shader)
1897 {
1898 WARN("Invalid handle (%#x) passed.\n", pShader);
1899 wined3d_mutex_unlock();
1900
1901 return D3DERR_INVALIDCALL;
1902 }
1903
1904 hr = IWineD3DDevice_SetVertexDeclaration(This->WineD3DDevice,
1905 ((IDirect3DVertexDeclaration8Impl *)shader->vertex_declaration)->wined3d_vertex_declaration);
1906 if (SUCCEEDED(hr)) hr = IWineD3DDevice_SetVertexShader(This->WineD3DDevice, shader->wineD3DVertexShader);
1907 wined3d_mutex_unlock();
1908
1909 TRACE("Returning hr %#x\n", hr);
1910
1911 return hr;
1912}
1913
1914static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShader(LPDIRECT3DDEVICE8 iface, DWORD* ppShader) {
1915 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1916 IWineD3DVertexDeclaration *wined3d_declaration;
1917 IDirect3DVertexDeclaration8 *d3d8_declaration;
1918 HRESULT hrc;
1919
1920 TRACE("iface %p, shader %p.\n", iface, ppShader);
1921
1922 wined3d_mutex_lock();
1923 hrc = IWineD3DDevice_GetVertexDeclaration(This->WineD3DDevice, &wined3d_declaration);
1924 if (FAILED(hrc))
1925 {
1926 wined3d_mutex_unlock();
1927 WARN("(%p) : Call to IWineD3DDevice_GetVertexDeclaration failed %#x (device %p)\n",
1928 This, hrc, This->WineD3DDevice);
1929 return hrc;
1930 }
1931
1932 if (!wined3d_declaration)
1933 {
1934 wined3d_mutex_unlock();
1935 *ppShader = 0;
1936 return D3D_OK;
1937 }
1938
1939 hrc = IWineD3DVertexDeclaration_GetParent(wined3d_declaration, (IUnknown **)&d3d8_declaration);
1940 IWineD3DVertexDeclaration_Release(wined3d_declaration);
1941 wined3d_mutex_unlock();
1942 if (SUCCEEDED(hrc))
1943 {
1944 *ppShader = ((IDirect3DVertexDeclaration8Impl *)d3d8_declaration)->shader_handle;
1945 IDirect3DVertexDeclaration8_Release(d3d8_declaration);
1946 }
1947
1948 TRACE("(%p) : returning %#x\n", This, *ppShader);
1949
1950 return hrc;
1951}
1952
1953static HRESULT WINAPI IDirect3DDevice8Impl_DeleteVertexShader(LPDIRECT3DDEVICE8 iface, DWORD pShader) {
1954 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1955 IDirect3DVertexShader8Impl *shader;
1956 IWineD3DVertexShader *cur = NULL;
1957
1958 TRACE("iface %p, shader %#x.\n", iface, pShader);
1959
1960 wined3d_mutex_lock();
1961 shader = d3d8_free_handle(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS);
1962 if (!shader)
1963 {
1964 WARN("Invalid handle (%#x) passed.\n", pShader);
1965 wined3d_mutex_unlock();
1966
1967 return D3DERR_INVALIDCALL;
1968 }
1969
1970 IWineD3DDevice_GetVertexShader(This->WineD3DDevice, &cur);
1971
1972 if (cur)
1973 {
1974 if (cur == shader->wineD3DVertexShader) IDirect3DDevice8_SetVertexShader(iface, 0);
1975 IWineD3DVertexShader_Release(cur);
1976 }
1977
1978 wined3d_mutex_unlock();
1979
1980 if (IUnknown_Release((IUnknown *)shader))
1981 {
1982 ERR("Shader %p has references left, this shouldn't happen.\n", shader);
1983 }
1984
1985 return D3D_OK;
1986}
1987
1988static HRESULT WINAPI IDirect3DDevice8Impl_SetVertexShaderConstant(LPDIRECT3DDEVICE8 iface, DWORD Register, CONST void* pConstantData, DWORD ConstantCount) {
1989 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1990 HRESULT hr;
1991
1992 TRACE("iface %p, register %u, data %p, count %u.\n",
1993 iface, Register, pConstantData, ConstantCount);
1994
1995 if(Register + ConstantCount > D3D8_MAX_VERTEX_SHADER_CONSTANTF) {
1996 WARN("Trying to access %u constants, but d3d8 only supports %u\n",
1997 Register + ConstantCount, D3D8_MAX_VERTEX_SHADER_CONSTANTF);
1998 return D3DERR_INVALIDCALL;
1999 }
2000
2001 wined3d_mutex_lock();
2002 hr = IWineD3DDevice_SetVertexShaderConstantF(This->WineD3DDevice, Register, pConstantData, ConstantCount);
2003 wined3d_mutex_unlock();
2004
2005 return hr;
2006}
2007
2008static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShaderConstant(LPDIRECT3DDEVICE8 iface, DWORD Register, void* pConstantData, DWORD ConstantCount) {
2009 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2010 HRESULT hr;
2011
2012 TRACE("iface %p, register %u, data %p, count %u.\n",
2013 iface, Register, pConstantData, ConstantCount);
2014
2015 if(Register + ConstantCount > D3D8_MAX_VERTEX_SHADER_CONSTANTF) {
2016 WARN("Trying to access %u constants, but d3d8 only supports %u\n",
2017 Register + ConstantCount, D3D8_MAX_VERTEX_SHADER_CONSTANTF);
2018 return D3DERR_INVALIDCALL;
2019 }
2020
2021 wined3d_mutex_lock();
2022 hr = IWineD3DDevice_GetVertexShaderConstantF(This->WineD3DDevice, Register, pConstantData, ConstantCount);
2023 wined3d_mutex_unlock();
2024
2025 return hr;
2026}
2027
2028static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShaderDeclaration(LPDIRECT3DDEVICE8 iface, DWORD pVertexShader, void* pData, DWORD* pSizeOfData) {
2029 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2030 IDirect3DVertexDeclaration8Impl *declaration;
2031 IDirect3DVertexShader8Impl *shader;
2032
2033 TRACE("iface %p, shader %#x, data %p, data_size %p.\n",
2034 iface, pVertexShader, pData, pSizeOfData);
2035
2036 wined3d_mutex_lock();
2037 shader = d3d8_get_object(&This->handle_table, pVertexShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS);
2038 wined3d_mutex_unlock();
2039
2040 if (!shader)
2041 {
2042 WARN("Invalid handle (%#x) passed.\n", pVertexShader);
2043 return D3DERR_INVALIDCALL;
2044 }
2045 declaration = (IDirect3DVertexDeclaration8Impl *)shader->vertex_declaration;
2046
2047 /* If pData is NULL, we just return the required size of the buffer. */
2048 if (!pData) {
2049 *pSizeOfData = declaration->elements_size;
2050 return D3D_OK;
2051 }
2052
2053 /* MSDN claims that if *pSizeOfData is smaller than the required size
2054 * we should write the required size and return D3DERR_MOREDATA.
2055 * That's not actually true. */
2056 if (*pSizeOfData < declaration->elements_size) {
2057 return D3DERR_INVALIDCALL;
2058 }
2059
2060 CopyMemory(pData, declaration->elements, declaration->elements_size);
2061
2062 return D3D_OK;
2063}
2064
2065static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShaderFunction(LPDIRECT3DDEVICE8 iface, DWORD pVertexShader, void* pData, DWORD* pSizeOfData) {
2066 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2067 IDirect3DVertexShader8Impl *shader = NULL;
2068 HRESULT hr;
2069
2070 TRACE("iface %p, shader %#x, data %p, data_size %p.\n",
2071 iface, pVertexShader, pData, pSizeOfData);
2072
2073 wined3d_mutex_lock();
2074 shader = d3d8_get_object(&This->handle_table, pVertexShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS);
2075 if (!shader)
2076 {
2077 WARN("Invalid handle (%#x) passed.\n", pVertexShader);
2078 wined3d_mutex_unlock();
2079
2080 return D3DERR_INVALIDCALL;
2081 }
2082
2083 if (!shader->wineD3DVertexShader)
2084 {
2085 wined3d_mutex_unlock();
2086 *pSizeOfData = 0;
2087 return D3D_OK;
2088 }
2089
2090 hr = IWineD3DVertexShader_GetFunction(shader->wineD3DVertexShader, pData, pSizeOfData);
2091 wined3d_mutex_unlock();
2092
2093 return hr;
2094}
2095
2096static HRESULT WINAPI IDirect3DDevice8Impl_SetIndices(LPDIRECT3DDEVICE8 iface, IDirect3DIndexBuffer8* pIndexData, UINT baseVertexIndex) {
2097 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2098 HRESULT hr;
2099 IDirect3DIndexBuffer8Impl *ib = (IDirect3DIndexBuffer8Impl *)pIndexData;
2100
2101 TRACE("iface %p, buffer %p, base_vertex_idx %u.\n", iface, pIndexData, baseVertexIndex);
2102
2103 /* WineD3D takes an INT(due to d3d9), but d3d8 uses UINTs. Do I have to add a check here that
2104 * the UINT doesn't cause an overflow in the INT? It seems rather unlikely because such large
2105 * vertex buffers can't be created to address them with an index that requires the 32nd bit
2106 * (4 Byte minimum vertex size * 2^31-1 -> 8 gb buffer. The index sign would be the least
2107 * problem)
2108 */
2109 wined3d_mutex_lock();
2110 IWineD3DDevice_SetBaseVertexIndex(This->WineD3DDevice, baseVertexIndex);
2111 hr = IWineD3DDevice_SetIndexBuffer(This->WineD3DDevice,
2112 ib ? ib->wineD3DIndexBuffer : NULL,
2113 ib ? ib->format : WINED3DFMT_UNKNOWN);
2114 wined3d_mutex_unlock();
2115
2116 return hr;
2117}
2118
2119static HRESULT WINAPI IDirect3DDevice8Impl_GetIndices(LPDIRECT3DDEVICE8 iface, IDirect3DIndexBuffer8** ppIndexData,UINT* pBaseVertexIndex) {
2120 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2121 IWineD3DBuffer *retIndexData = NULL;
2122 HRESULT rc = D3D_OK;
2123
2124 TRACE("iface %p, buffer %p, base_vertex_index %p.\n", iface, ppIndexData, pBaseVertexIndex);
2125
2126 if(ppIndexData == NULL){
2127 return D3DERR_INVALIDCALL;
2128 }
2129
2130 /* The case from UINT to INT is safe because d3d8 will never set negative values */
2131 wined3d_mutex_lock();
2132 IWineD3DDevice_GetBaseVertexIndex(This->WineD3DDevice, (INT *) pBaseVertexIndex);
2133 rc = IWineD3DDevice_GetIndexBuffer(This->WineD3DDevice, &retIndexData);
2134 if (SUCCEEDED(rc) && retIndexData) {
2135 IWineD3DBuffer_GetParent(retIndexData, (IUnknown **)ppIndexData);
2136 IWineD3DBuffer_Release(retIndexData);
2137 } else {
2138 if (FAILED(rc)) FIXME("Call to GetIndices failed\n");
2139 *ppIndexData = NULL;
2140 }
2141 wined3d_mutex_unlock();
2142
2143 return rc;
2144}
2145
2146static HRESULT WINAPI IDirect3DDevice8Impl_CreatePixelShader(IDirect3DDevice8 *iface,
2147 const DWORD *byte_code, DWORD *shader)
2148{
2149 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2150 IDirect3DPixelShader8Impl *object;
2151 DWORD shader_handle;
2152 DWORD handle;
2153 HRESULT hr;
2154
2155 TRACE("iface %p, byte_code %p, shader %p.\n", iface, byte_code, shader);
2156
2157 if (!shader)
2158 {
2159 TRACE("(%p) Invalid call\n", This);
2160 return D3DERR_INVALIDCALL;
2161 }
2162
2163 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2164 if (!object)
2165 {
2166 ERR("Failed to allocate pixel shader memmory.\n");
2167 return E_OUTOFMEMORY;
2168 }
2169
2170 wined3d_mutex_lock();
2171 handle = d3d8_allocate_handle(&This->handle_table, object, D3D8_HANDLE_PS);
2172 wined3d_mutex_unlock();
2173 if (handle == D3D8_INVALID_HANDLE)
2174 {
2175 ERR("Failed to allocate pixel shader handle.\n");
2176 HeapFree(GetProcessHeap(), 0, object);
2177 return E_OUTOFMEMORY;
2178 }
2179
2180 shader_handle = handle + VS_HIGHESTFIXEDFXF + 1;
2181
2182 hr = pixelshader_init(object, This, byte_code, shader_handle);
2183 if (FAILED(hr))
2184 {
2185 WARN("Failed to initialize pixel shader, hr %#x.\n", hr);
2186 wined3d_mutex_lock();
2187 d3d8_free_handle(&This->handle_table, handle, D3D8_HANDLE_PS);
2188 wined3d_mutex_unlock();
2189 HeapFree(GetProcessHeap(), 0, object);
2190 *shader = 0;
2191 return hr;
2192 }
2193
2194 TRACE("Created pixel shader %p (handle %#x).\n", object, shader_handle);
2195 *shader = shader_handle;
2196
2197 return D3D_OK;
2198}
2199
2200static HRESULT WINAPI IDirect3DDevice8Impl_SetPixelShader(LPDIRECT3DDEVICE8 iface, DWORD pShader) {
2201 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2202 IDirect3DPixelShader8Impl *shader;
2203 HRESULT hr;
2204
2205 TRACE("iface %p, shader %#x.\n", iface, pShader);
2206
2207 wined3d_mutex_lock();
2208
2209 if (!pShader)
2210 {
2211 hr = IWineD3DDevice_SetPixelShader(This->WineD3DDevice, NULL);
2212 wined3d_mutex_unlock();
2213 return hr;
2214 }
2215
2216 shader = d3d8_get_object(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_PS);
2217 if (!shader)
2218 {
2219 WARN("Invalid handle (%#x) passed.\n", pShader);
2220 wined3d_mutex_unlock();
2221 return D3DERR_INVALIDCALL;
2222 }
2223
2224 TRACE("(%p) : Setting shader %p\n", This, shader);
2225 hr = IWineD3DDevice_SetPixelShader(This->WineD3DDevice, shader->wineD3DPixelShader);
2226 wined3d_mutex_unlock();
2227
2228 return hr;
2229}
2230
2231static HRESULT WINAPI IDirect3DDevice8Impl_GetPixelShader(LPDIRECT3DDEVICE8 iface, DWORD* ppShader) {
2232 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2233 IWineD3DPixelShader *object;
2234 HRESULT hrc = D3D_OK;
2235
2236 TRACE("iface %p, shader %p.\n", iface, ppShader);
2237
2238 if (NULL == ppShader) {
2239 TRACE("(%p) Invalid call\n", This);
2240 return D3DERR_INVALIDCALL;
2241 }
2242
2243 wined3d_mutex_lock();
2244 hrc = IWineD3DDevice_GetPixelShader(This->WineD3DDevice, &object);
2245 if (D3D_OK == hrc && NULL != object) {
2246 IDirect3DPixelShader8Impl *d3d8_shader;
2247 hrc = IWineD3DPixelShader_GetParent(object, (IUnknown **)&d3d8_shader);
2248 IWineD3DPixelShader_Release(object);
2249 *ppShader = d3d8_shader->handle;
2250 IDirect3DPixelShader8_Release((IDirect3DPixelShader8 *)d3d8_shader);
2251 } else {
2252 *ppShader = 0;
2253 }
2254 wined3d_mutex_unlock();
2255
2256 TRACE("(%p) : returning %#x\n", This, *ppShader);
2257
2258 return hrc;
2259}
2260
2261static HRESULT WINAPI IDirect3DDevice8Impl_DeletePixelShader(LPDIRECT3DDEVICE8 iface, DWORD pShader) {
2262 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2263 IDirect3DPixelShader8Impl *shader;
2264 IWineD3DPixelShader *cur = NULL;
2265
2266 TRACE("iface %p, shader %#x.\n", iface, pShader);
2267
2268 wined3d_mutex_lock();
2269
2270 shader = d3d8_free_handle(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_PS);
2271 if (!shader)
2272 {
2273 WARN("Invalid handle (%#x) passed.\n", pShader);
2274 wined3d_mutex_unlock();
2275 return D3DERR_INVALIDCALL;
2276 }
2277
2278 IWineD3DDevice_GetPixelShader(This->WineD3DDevice, &cur);
2279
2280 if (cur)
2281 {
2282 if (cur == shader->wineD3DPixelShader) IDirect3DDevice8_SetPixelShader(iface, 0);
2283 IWineD3DPixelShader_Release(cur);
2284 }
2285
2286 wined3d_mutex_unlock();
2287
2288 if (IUnknown_Release((IUnknown *)shader))
2289 {
2290 ERR("Shader %p has references left, this shouldn't happen.\n", shader);
2291 }
2292
2293 return D3D_OK;
2294}
2295
2296static HRESULT WINAPI IDirect3DDevice8Impl_SetPixelShaderConstant(LPDIRECT3DDEVICE8 iface, DWORD Register, CONST void* pConstantData, DWORD ConstantCount) {
2297 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2298 HRESULT hr;
2299
2300 TRACE("iface %p, register %u, data %p, count %u.\n",
2301 iface, Register, pConstantData, ConstantCount);
2302
2303 wined3d_mutex_lock();
2304 hr = IWineD3DDevice_SetPixelShaderConstantF(This->WineD3DDevice, Register, pConstantData, ConstantCount);
2305 wined3d_mutex_unlock();
2306
2307 return hr;
2308}
2309
2310static HRESULT WINAPI IDirect3DDevice8Impl_GetPixelShaderConstant(LPDIRECT3DDEVICE8 iface, DWORD Register, void* pConstantData, DWORD ConstantCount) {
2311 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2312 HRESULT hr;
2313
2314 TRACE("iface %p, register %u, data %p, count %u.\n",
2315 iface, Register, pConstantData, ConstantCount);
2316
2317 wined3d_mutex_lock();
2318 hr = IWineD3DDevice_GetPixelShaderConstantF(This->WineD3DDevice, Register, pConstantData, ConstantCount);
2319 wined3d_mutex_unlock();
2320
2321 return hr;
2322}
2323
2324static HRESULT WINAPI IDirect3DDevice8Impl_GetPixelShaderFunction(LPDIRECT3DDEVICE8 iface, DWORD pPixelShader, void* pData, DWORD* pSizeOfData) {
2325 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2326 IDirect3DPixelShader8Impl *shader = NULL;
2327 HRESULT hr;
2328
2329 TRACE("iface %p, shader %#x, data %p, data_size %p.\n",
2330 iface, pPixelShader, pData, pSizeOfData);
2331
2332 wined3d_mutex_lock();
2333 shader = d3d8_get_object(&This->handle_table, pPixelShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_PS);
2334 if (!shader)
2335 {
2336 WARN("Invalid handle (%#x) passed.\n", pPixelShader);
2337 wined3d_mutex_unlock();
2338
2339 return D3DERR_INVALIDCALL;
2340 }
2341
2342 hr = IWineD3DPixelShader_GetFunction(shader->wineD3DPixelShader, pData, pSizeOfData);
2343 wined3d_mutex_unlock();
2344
2345 return hr;
2346}
2347
2348static HRESULT WINAPI IDirect3DDevice8Impl_DrawRectPatch(LPDIRECT3DDEVICE8 iface, UINT Handle,CONST float* pNumSegs,CONST D3DRECTPATCH_INFO* pRectPatchInfo) {
2349 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2350 HRESULT hr;
2351
2352 TRACE("iface %p, handle %#x, segment_count %p, patch_info %p.\n",
2353 iface, Handle, pNumSegs, pRectPatchInfo);
2354
2355 wined3d_mutex_lock();
2356 hr = IWineD3DDevice_DrawRectPatch(This->WineD3DDevice, Handle, pNumSegs, (CONST WINED3DRECTPATCH_INFO *)pRectPatchInfo);
2357 wined3d_mutex_unlock();
2358
2359 return hr;
2360}
2361
2362static HRESULT WINAPI IDirect3DDevice8Impl_DrawTriPatch(LPDIRECT3DDEVICE8 iface, UINT Handle,CONST float* pNumSegs,CONST D3DTRIPATCH_INFO* pTriPatchInfo) {
2363 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2364 HRESULT hr;
2365
2366 TRACE("iface %p, handle %#x, segment_count %p, patch_info %p.\n",
2367 iface, Handle, pNumSegs, pTriPatchInfo);
2368
2369 wined3d_mutex_lock();
2370 hr = IWineD3DDevice_DrawTriPatch(This->WineD3DDevice, Handle, pNumSegs, (CONST WINED3DTRIPATCH_INFO *)pTriPatchInfo);
2371 wined3d_mutex_unlock();
2372
2373 return hr;
2374}
2375
2376static HRESULT WINAPI IDirect3DDevice8Impl_DeletePatch(LPDIRECT3DDEVICE8 iface, UINT Handle) {
2377 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2378 HRESULT hr;
2379
2380 TRACE("iface %p, handle %#x.\n", iface, Handle);
2381
2382 wined3d_mutex_lock();
2383 hr = IWineD3DDevice_DeletePatch(This->WineD3DDevice, Handle);
2384 wined3d_mutex_unlock();
2385
2386 return hr;
2387}
2388
2389static HRESULT WINAPI IDirect3DDevice8Impl_SetStreamSource(LPDIRECT3DDEVICE8 iface, UINT StreamNumber,IDirect3DVertexBuffer8* pStreamData,UINT Stride) {
2390 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2391 HRESULT hr;
2392
2393 TRACE("iface %p, stream_idx %u, buffer %p, stride %u.\n",
2394 iface, StreamNumber, pStreamData, Stride);
2395
2396 wined3d_mutex_lock();
2397 hr = IWineD3DDevice_SetStreamSource(This->WineD3DDevice, StreamNumber,
2398 NULL == pStreamData ? NULL : ((IDirect3DVertexBuffer8Impl *)pStreamData)->wineD3DVertexBuffer,
2399 0/* Offset in bytes */, Stride);
2400 wined3d_mutex_unlock();
2401
2402 return hr;
2403}
2404
2405static HRESULT WINAPI IDirect3DDevice8Impl_GetStreamSource(LPDIRECT3DDEVICE8 iface, UINT StreamNumber,IDirect3DVertexBuffer8** pStream,UINT* pStride) {
2406 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2407 IWineD3DBuffer *retStream = NULL;
2408 HRESULT rc = D3D_OK;
2409
2410 TRACE("iface %p, stream_idx %u, buffer %p, stride %p.\n",
2411 iface, StreamNumber, pStream, pStride);
2412
2413 if(pStream == NULL){
2414 return D3DERR_INVALIDCALL;
2415 }
2416
2417 wined3d_mutex_lock();
2418 rc = IWineD3DDevice_GetStreamSource(This->WineD3DDevice, StreamNumber, &retStream, 0 /* Offset in bytes */, pStride);
2419 if (rc == D3D_OK && NULL != retStream) {
2420 IWineD3DBuffer_GetParent(retStream, (IUnknown **)pStream);
2421 IWineD3DBuffer_Release(retStream);
2422 }else{
2423 if (rc != D3D_OK){
2424 FIXME("Call to GetStreamSource failed %p\n", pStride);
2425 }
2426 *pStream = NULL;
2427 }
2428 wined3d_mutex_unlock();
2429
2430 return rc;
2431}
2432
2433static const IDirect3DDevice8Vtbl Direct3DDevice8_Vtbl =
2434{
2435 IDirect3DDevice8Impl_QueryInterface,
2436 IDirect3DDevice8Impl_AddRef,
2437 IDirect3DDevice8Impl_Release,
2438 IDirect3DDevice8Impl_TestCooperativeLevel,
2439 IDirect3DDevice8Impl_GetAvailableTextureMem,
2440 IDirect3DDevice8Impl_ResourceManagerDiscardBytes,
2441 IDirect3DDevice8Impl_GetDirect3D,
2442 IDirect3DDevice8Impl_GetDeviceCaps,
2443 IDirect3DDevice8Impl_GetDisplayMode,
2444 IDirect3DDevice8Impl_GetCreationParameters,
2445 IDirect3DDevice8Impl_SetCursorProperties,
2446 IDirect3DDevice8Impl_SetCursorPosition,
2447 IDirect3DDevice8Impl_ShowCursor,
2448 IDirect3DDevice8Impl_CreateAdditionalSwapChain,
2449 IDirect3DDevice8Impl_Reset,
2450 IDirect3DDevice8Impl_Present,
2451 IDirect3DDevice8Impl_GetBackBuffer,
2452 IDirect3DDevice8Impl_GetRasterStatus,
2453 IDirect3DDevice8Impl_SetGammaRamp,
2454 IDirect3DDevice8Impl_GetGammaRamp,
2455 IDirect3DDevice8Impl_CreateTexture,
2456 IDirect3DDevice8Impl_CreateVolumeTexture,
2457 IDirect3DDevice8Impl_CreateCubeTexture,
2458 IDirect3DDevice8Impl_CreateVertexBuffer,
2459 IDirect3DDevice8Impl_CreateIndexBuffer,
2460 IDirect3DDevice8Impl_CreateRenderTarget,
2461 IDirect3DDevice8Impl_CreateDepthStencilSurface,
2462 IDirect3DDevice8Impl_CreateImageSurface,
2463 IDirect3DDevice8Impl_CopyRects,
2464 IDirect3DDevice8Impl_UpdateTexture,
2465 IDirect3DDevice8Impl_GetFrontBuffer,
2466 IDirect3DDevice8Impl_SetRenderTarget,
2467 IDirect3DDevice8Impl_GetRenderTarget,
2468 IDirect3DDevice8Impl_GetDepthStencilSurface,
2469 IDirect3DDevice8Impl_BeginScene,
2470 IDirect3DDevice8Impl_EndScene,
2471 IDirect3DDevice8Impl_Clear,
2472 IDirect3DDevice8Impl_SetTransform,
2473 IDirect3DDevice8Impl_GetTransform,
2474 IDirect3DDevice8Impl_MultiplyTransform,
2475 IDirect3DDevice8Impl_SetViewport,
2476 IDirect3DDevice8Impl_GetViewport,
2477 IDirect3DDevice8Impl_SetMaterial,
2478 IDirect3DDevice8Impl_GetMaterial,
2479 IDirect3DDevice8Impl_SetLight,
2480 IDirect3DDevice8Impl_GetLight,
2481 IDirect3DDevice8Impl_LightEnable,
2482 IDirect3DDevice8Impl_GetLightEnable,
2483 IDirect3DDevice8Impl_SetClipPlane,
2484 IDirect3DDevice8Impl_GetClipPlane,
2485 IDirect3DDevice8Impl_SetRenderState,
2486 IDirect3DDevice8Impl_GetRenderState,
2487 IDirect3DDevice8Impl_BeginStateBlock,
2488 IDirect3DDevice8Impl_EndStateBlock,
2489 IDirect3DDevice8Impl_ApplyStateBlock,
2490 IDirect3DDevice8Impl_CaptureStateBlock,
2491 IDirect3DDevice8Impl_DeleteStateBlock,
2492 IDirect3DDevice8Impl_CreateStateBlock,
2493 IDirect3DDevice8Impl_SetClipStatus,
2494 IDirect3DDevice8Impl_GetClipStatus,
2495 IDirect3DDevice8Impl_GetTexture,
2496 IDirect3DDevice8Impl_SetTexture,
2497 IDirect3DDevice8Impl_GetTextureStageState,
2498 IDirect3DDevice8Impl_SetTextureStageState,
2499 IDirect3DDevice8Impl_ValidateDevice,
2500 IDirect3DDevice8Impl_GetInfo,
2501 IDirect3DDevice8Impl_SetPaletteEntries,
2502 IDirect3DDevice8Impl_GetPaletteEntries,
2503 IDirect3DDevice8Impl_SetCurrentTexturePalette,
2504 IDirect3DDevice8Impl_GetCurrentTexturePalette,
2505 IDirect3DDevice8Impl_DrawPrimitive,
2506 IDirect3DDevice8Impl_DrawIndexedPrimitive,
2507 IDirect3DDevice8Impl_DrawPrimitiveUP,
2508 IDirect3DDevice8Impl_DrawIndexedPrimitiveUP,
2509 IDirect3DDevice8Impl_ProcessVertices,
2510 IDirect3DDevice8Impl_CreateVertexShader,
2511 IDirect3DDevice8Impl_SetVertexShader,
2512 IDirect3DDevice8Impl_GetVertexShader,
2513 IDirect3DDevice8Impl_DeleteVertexShader,
2514 IDirect3DDevice8Impl_SetVertexShaderConstant,
2515 IDirect3DDevice8Impl_GetVertexShaderConstant,
2516 IDirect3DDevice8Impl_GetVertexShaderDeclaration,
2517 IDirect3DDevice8Impl_GetVertexShaderFunction,
2518 IDirect3DDevice8Impl_SetStreamSource,
2519 IDirect3DDevice8Impl_GetStreamSource,
2520 IDirect3DDevice8Impl_SetIndices,
2521 IDirect3DDevice8Impl_GetIndices,
2522 IDirect3DDevice8Impl_CreatePixelShader,
2523 IDirect3DDevice8Impl_SetPixelShader,
2524 IDirect3DDevice8Impl_GetPixelShader,
2525 IDirect3DDevice8Impl_DeletePixelShader,
2526 IDirect3DDevice8Impl_SetPixelShaderConstant,
2527 IDirect3DDevice8Impl_GetPixelShaderConstant,
2528 IDirect3DDevice8Impl_GetPixelShaderFunction,
2529 IDirect3DDevice8Impl_DrawRectPatch,
2530 IDirect3DDevice8Impl_DrawTriPatch,
2531 IDirect3DDevice8Impl_DeletePatch
2532};
2533
2534/* IWineD3DDeviceParent IUnknown methods */
2535
2536static inline struct IDirect3DDevice8Impl *device_from_device_parent(IWineD3DDeviceParent *iface)
2537{
2538 return (struct IDirect3DDevice8Impl *)((char*)iface
2539 - FIELD_OFFSET(struct IDirect3DDevice8Impl, device_parent_vtbl));
2540}
2541
2542static HRESULT STDMETHODCALLTYPE device_parent_QueryInterface(IWineD3DDeviceParent *iface, REFIID riid, void **object)
2543{
2544 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2545 return IDirect3DDevice8Impl_QueryInterface((IDirect3DDevice8 *)This, riid, object);
2546}
2547
2548static ULONG STDMETHODCALLTYPE device_parent_AddRef(IWineD3DDeviceParent *iface)
2549{
2550 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2551 return IDirect3DDevice8Impl_AddRef((IDirect3DDevice8 *)This);
2552}
2553
2554static ULONG STDMETHODCALLTYPE device_parent_Release(IWineD3DDeviceParent *iface)
2555{
2556 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2557 return IDirect3DDevice8Impl_Release((IDirect3DDevice8 *)This);
2558}
2559
2560/* IWineD3DDeviceParent methods */
2561
2562static void STDMETHODCALLTYPE device_parent_WineD3DDeviceCreated(IWineD3DDeviceParent *iface, IWineD3DDevice *device)
2563{
2564 TRACE("iface %p, device %p\n", iface, device);
2565}
2566
2567static HRESULT STDMETHODCALLTYPE device_parent_CreateSurface(IWineD3DDeviceParent *iface,
2568 IUnknown *superior, UINT width, UINT height, WINED3DFORMAT format, DWORD usage,
2569 WINED3DPOOL pool, UINT level, WINED3DCUBEMAP_FACES face, IWineD3DSurface **surface)
2570{
2571 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2572 IDirect3DSurface8Impl *d3d_surface;
2573 BOOL lockable = TRUE;
2574 HRESULT hr;
2575
2576 TRACE("iface %p, superior %p, width %u, height %u, format %#x, usage %#x,\n"
2577 "\tpool %#x, level %u, face %u, surface %p\n",
2578 iface, superior, width, height, format, usage, pool, level, face, surface);
2579
2580
2581 if (pool == WINED3DPOOL_DEFAULT && !(usage & WINED3DUSAGE_DYNAMIC)) lockable = FALSE;
2582
2583 hr = IDirect3DDevice8Impl_CreateSurface((IDirect3DDevice8 *)This, width, height,
2584 d3dformat_from_wined3dformat(format), lockable, FALSE /* Discard */, level,
2585 (IDirect3DSurface8 **)&d3d_surface, usage, pool, D3DMULTISAMPLE_NONE, 0 /* MultisampleQuality */);
2586 if (FAILED(hr))
2587 {
2588 ERR("(%p) CreateSurface failed, returning %#x\n", iface, hr);
2589 return hr;
2590 }
2591
2592 *surface = d3d_surface->wineD3DSurface;
2593 IWineD3DSurface_AddRef(*surface);
2594
2595 d3d_surface->container = superior;
2596 IUnknown_Release(d3d_surface->parentDevice);
2597 d3d_surface->parentDevice = NULL;
2598
2599 IDirect3DSurface8_Release((IDirect3DSurface8 *)d3d_surface);
2600 d3d_surface->forwardReference = superior;
2601
2602 return hr;
2603}
2604
2605static HRESULT STDMETHODCALLTYPE device_parent_CreateRenderTarget(IWineD3DDeviceParent *iface,
2606 IUnknown *superior, UINT width, UINT height, WINED3DFORMAT format, WINED3DMULTISAMPLE_TYPE multisample_type,
2607 DWORD multisample_quality, BOOL lockable, IWineD3DSurface **surface)
2608{
2609 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2610 IDirect3DSurface8Impl *d3d_surface;
2611 HRESULT hr;
2612
2613 TRACE("iface %p, superior %p, width %u, height %u, format %#x, multisample_type %#x,\n"
2614 "\tmultisample_quality %u, lockable %u, surface %p\n",
2615 iface, superior, width, height, format, multisample_type, multisample_quality, lockable, surface);
2616
2617 hr = IDirect3DDevice8_CreateRenderTarget((IDirect3DDevice8 *)This, width, height,
2618 d3dformat_from_wined3dformat(format), multisample_type, lockable, (IDirect3DSurface8 **)&d3d_surface);
2619 if (FAILED(hr))
2620 {
2621 ERR("(%p) CreateRenderTarget failed, returning %#x\n", iface, hr);
2622 return hr;
2623 }
2624
2625 *surface = d3d_surface->wineD3DSurface;
2626 IWineD3DSurface_AddRef(*surface);
2627
2628 d3d_surface->container = (IUnknown *)This;
2629 /* Implicit surfaces are created with an refcount of 0 */
2630 IUnknown_Release((IUnknown *)d3d_surface);
2631
2632 return hr;
2633}
2634
2635static HRESULT STDMETHODCALLTYPE device_parent_CreateDepthStencilSurface(IWineD3DDeviceParent *iface,
2636 IUnknown *superior, UINT width, UINT height, WINED3DFORMAT format, WINED3DMULTISAMPLE_TYPE multisample_type,
2637 DWORD multisample_quality, BOOL discard, IWineD3DSurface **surface)
2638{
2639 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2640 IDirect3DSurface8Impl *d3d_surface;
2641 HRESULT hr;
2642
2643 TRACE("iface %p, superior %p, width %u, height %u, format %#x, multisample_type %#x,\n"
2644 "\tmultisample_quality %u, discard %u, surface %p\n",
2645 iface, superior, width, height, format, multisample_type, multisample_quality, discard, surface);
2646
2647 hr = IDirect3DDevice8_CreateDepthStencilSurface((IDirect3DDevice8 *)This, width, height,
2648 d3dformat_from_wined3dformat(format), multisample_type, (IDirect3DSurface8 **)&d3d_surface);
2649 if (FAILED(hr))
2650 {
2651 ERR("(%p) CreateDepthStencilSurface failed, returning %#x\n", iface, hr);
2652 return hr;
2653 }
2654
2655 *surface = d3d_surface->wineD3DSurface;
2656 IWineD3DSurface_AddRef(*surface);
2657
2658 d3d_surface->container = (IUnknown *)This;
2659 /* Implicit surfaces are created with an refcount of 0 */
2660 IUnknown_Release((IUnknown *)d3d_surface);
2661
2662 return hr;
2663}
2664
2665static HRESULT STDMETHODCALLTYPE device_parent_CreateVolume(IWineD3DDeviceParent *iface,
2666 IUnknown *superior, UINT width, UINT height, UINT depth, WINED3DFORMAT format,
2667 WINED3DPOOL pool, DWORD usage, IWineD3DVolume **volume)
2668{
2669 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2670 IDirect3DVolume8Impl *object;
2671 HRESULT hr;
2672
2673 TRACE("iface %p, superior %p, width %u, height %u, depth %u, format %#x, pool %#x, usage %#x, volume %p\n",
2674 iface, superior, width, height, depth, format, pool, usage, volume);
2675
2676 /* Allocate the storage for the device */
2677 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2678 if (!object)
2679 {
2680 FIXME("Allocation of memory failed\n");
2681 *volume = NULL;
2682 return D3DERR_OUTOFVIDEOMEMORY;
2683 }
2684
2685 hr = volume_init(object, This, width, height, depth, usage, format, pool);
2686 if (FAILED(hr))
2687 {
2688 WARN("Failed to initialize volume, hr %#x.\n", hr);
2689 HeapFree(GetProcessHeap(), 0, object);
2690 return hr;
2691 }
2692
2693 *volume = object->wineD3DVolume;
2694 IWineD3DVolume_AddRef(*volume);
2695 IDirect3DVolume8_Release((IDirect3DVolume8 *)object);
2696
2697 object->container = superior;
2698 object->forwardReference = superior;
2699
2700 TRACE("(%p) Created volume %p\n", iface, object);
2701
2702 return hr;
2703}
2704
2705static HRESULT STDMETHODCALLTYPE device_parent_CreateSwapChain(IWineD3DDeviceParent *iface,
2706 WINED3DPRESENT_PARAMETERS *present_parameters, IWineD3DSwapChain **swapchain)
2707{
2708 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2709 IDirect3DSwapChain8Impl *d3d_swapchain;
2710 D3DPRESENT_PARAMETERS local_parameters;
2711 HRESULT hr;
2712
2713 TRACE("iface %p, present_parameters %p, swapchain %p\n", iface, present_parameters, swapchain);
2714
2715 /* Copy the presentation parameters */
2716 local_parameters.BackBufferWidth = present_parameters->BackBufferWidth;
2717 local_parameters.BackBufferHeight = present_parameters->BackBufferHeight;
2718 local_parameters.BackBufferFormat = d3dformat_from_wined3dformat(present_parameters->BackBufferFormat);
2719 local_parameters.BackBufferCount = present_parameters->BackBufferCount;
2720 local_parameters.MultiSampleType = present_parameters->MultiSampleType;
2721 local_parameters.SwapEffect = present_parameters->SwapEffect;
2722 local_parameters.hDeviceWindow = present_parameters->hDeviceWindow;
2723 local_parameters.Windowed = present_parameters->Windowed;
2724 local_parameters.EnableAutoDepthStencil = present_parameters->EnableAutoDepthStencil;
2725 local_parameters.AutoDepthStencilFormat = d3dformat_from_wined3dformat(present_parameters->AutoDepthStencilFormat);
2726 local_parameters.Flags = present_parameters->Flags;
2727 local_parameters.FullScreen_RefreshRateInHz = present_parameters->FullScreen_RefreshRateInHz;
2728 local_parameters.FullScreen_PresentationInterval = present_parameters->PresentationInterval;
2729
2730 hr = IDirect3DDevice8_CreateAdditionalSwapChain((IDirect3DDevice8 *)This,
2731 &local_parameters, (IDirect3DSwapChain8 **)&d3d_swapchain);
2732 if (FAILED(hr))
2733 {
2734 ERR("(%p) CreateAdditionalSwapChain failed, returning %#x\n", iface, hr);
2735 *swapchain = NULL;
2736 return hr;
2737 }
2738
2739 *swapchain = d3d_swapchain->wineD3DSwapChain;
2740 IUnknown_Release(d3d_swapchain->parentDevice);
2741 d3d_swapchain->parentDevice = NULL;
2742
2743 /* Copy back the presentation parameters */
2744 present_parameters->BackBufferWidth = local_parameters.BackBufferWidth;
2745 present_parameters->BackBufferHeight = local_parameters.BackBufferHeight;
2746 present_parameters->BackBufferFormat = wined3dformat_from_d3dformat(local_parameters.BackBufferFormat);
2747 present_parameters->BackBufferCount = local_parameters.BackBufferCount;
2748 present_parameters->MultiSampleType = local_parameters.MultiSampleType;
2749 present_parameters->SwapEffect = local_parameters.SwapEffect;
2750 present_parameters->hDeviceWindow = local_parameters.hDeviceWindow;
2751 present_parameters->Windowed = local_parameters.Windowed;
2752 present_parameters->EnableAutoDepthStencil = local_parameters.EnableAutoDepthStencil;
2753 present_parameters->AutoDepthStencilFormat = wined3dformat_from_d3dformat(local_parameters.AutoDepthStencilFormat);
2754 present_parameters->Flags = local_parameters.Flags;
2755 present_parameters->FullScreen_RefreshRateInHz = local_parameters.FullScreen_RefreshRateInHz;
2756 present_parameters->PresentationInterval = local_parameters.FullScreen_PresentationInterval;
2757
2758 return hr;
2759}
2760
2761static const IWineD3DDeviceParentVtbl d3d8_wined3d_device_parent_vtbl =
2762{
2763 /* IUnknown methods */
2764 device_parent_QueryInterface,
2765 device_parent_AddRef,
2766 device_parent_Release,
2767 /* IWineD3DDeviceParent methods */
2768 device_parent_WineD3DDeviceCreated,
2769 device_parent_CreateSurface,
2770 device_parent_CreateRenderTarget,
2771 device_parent_CreateDepthStencilSurface,
2772 device_parent_CreateVolume,
2773 device_parent_CreateSwapChain,
2774};
2775
2776HRESULT device_init(IDirect3DDevice8Impl *device, IWineD3D *wined3d, UINT adapter,
2777 D3DDEVTYPE device_type, HWND focus_window, DWORD flags, D3DPRESENT_PARAMETERS *parameters)
2778{
2779 WINED3DPRESENT_PARAMETERS wined3d_parameters;
2780 HRESULT hr;
2781
2782 device->lpVtbl = &Direct3DDevice8_Vtbl;
2783 device->device_parent_vtbl = &d3d8_wined3d_device_parent_vtbl;
2784 device->ref = 1;
2785 device->handle_table.entries = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
2786 D3D8_INITIAL_HANDLE_TABLE_SIZE * sizeof(*device->handle_table.entries));
2787 if (!device->handle_table.entries)
2788 {
2789 ERR("Failed to allocate handle table memory.\n");
2790 return E_OUTOFMEMORY;
2791 }
2792 device->handle_table.table_size = D3D8_INITIAL_HANDLE_TABLE_SIZE;
2793
2794 wined3d_mutex_lock();
2795 hr = IWineD3D_CreateDevice(wined3d, adapter, device_type, focus_window, flags, (IUnknown *)device,
2796 (IWineD3DDeviceParent *)&device->device_parent_vtbl, &device->WineD3DDevice);
2797 if (FAILED(hr))
2798 {
2799 WARN("Failed to create wined3d device, hr %#x.\n", hr);
2800 wined3d_mutex_unlock();
2801 HeapFree(GetProcessHeap(), 0, device->handle_table.entries);
2802 return hr;
2803 }
2804
2805 if (!parameters->Windowed)
2806 {
2807 if (!focus_window) focus_window = parameters->hDeviceWindow;
2808 if (FAILED(hr = IWineD3DDevice_AcquireFocusWindow(device->WineD3DDevice, focus_window)))
2809 {
2810 ERR("Failed to acquire focus window, hr %#x.\n", hr);
2811 IWineD3DDevice_Release(device->WineD3DDevice);
2812 wined3d_mutex_unlock();
2813 HeapFree(GetProcessHeap(), 0, device->handle_table.entries);
2814 return hr;
2815 }
2816 }
2817
2818 if (flags & D3DCREATE_MULTITHREADED) IWineD3DDevice_SetMultithreaded(device->WineD3DDevice);
2819
2820 wined3d_parameters.BackBufferWidth = parameters->BackBufferWidth;
2821 wined3d_parameters.BackBufferHeight = parameters->BackBufferHeight;
2822 wined3d_parameters.BackBufferFormat = wined3dformat_from_d3dformat(parameters->BackBufferFormat);
2823 wined3d_parameters.BackBufferCount = parameters->BackBufferCount;
2824 wined3d_parameters.MultiSampleType = parameters->MultiSampleType;
2825 wined3d_parameters.MultiSampleQuality = 0; /* d3d9 only */
2826 wined3d_parameters.SwapEffect = parameters->SwapEffect;
2827 wined3d_parameters.hDeviceWindow = parameters->hDeviceWindow;
2828 wined3d_parameters.Windowed = parameters->Windowed;
2829 wined3d_parameters.EnableAutoDepthStencil = parameters->EnableAutoDepthStencil;
2830 wined3d_parameters.AutoDepthStencilFormat = wined3dformat_from_d3dformat(parameters->AutoDepthStencilFormat);
2831 wined3d_parameters.Flags = parameters->Flags;
2832 wined3d_parameters.FullScreen_RefreshRateInHz = parameters->FullScreen_RefreshRateInHz;
2833 wined3d_parameters.PresentationInterval = parameters->FullScreen_PresentationInterval;
2834 wined3d_parameters.AutoRestoreDisplayMode = TRUE;
2835
2836 hr = IWineD3DDevice_Init3D(device->WineD3DDevice, &wined3d_parameters);
2837 if (FAILED(hr))
2838 {
2839 WARN("Failed to initialize 3D, hr %#x.\n", hr);
2840 IWineD3DDevice_ReleaseFocusWindow(device->WineD3DDevice);
2841 IWineD3DDevice_Release(device->WineD3DDevice);
2842 wined3d_mutex_unlock();
2843 HeapFree(GetProcessHeap(), 0, device->handle_table.entries);
2844 return hr;
2845 }
2846
2847 hr = IWineD3DDevice_SetRenderState(device->WineD3DDevice, WINED3DRS_POINTSIZE_MIN, 0);
2848 wined3d_mutex_unlock();
2849 if (FAILED(hr))
2850 {
2851 ERR("Failed to set minimum pointsize, hr %#x.\n", hr);
2852 goto err;
2853 }
2854
2855 parameters->BackBufferWidth = wined3d_parameters.BackBufferWidth;
2856 parameters->BackBufferHeight = wined3d_parameters.BackBufferHeight;
2857 parameters->BackBufferFormat = d3dformat_from_wined3dformat(wined3d_parameters.BackBufferFormat);
2858 parameters->BackBufferCount = wined3d_parameters.BackBufferCount;
2859 parameters->MultiSampleType = wined3d_parameters.MultiSampleType;
2860 parameters->SwapEffect = wined3d_parameters.SwapEffect;
2861 parameters->hDeviceWindow = wined3d_parameters.hDeviceWindow;
2862 parameters->Windowed = wined3d_parameters.Windowed;
2863 parameters->EnableAutoDepthStencil = wined3d_parameters.EnableAutoDepthStencil;
2864 parameters->AutoDepthStencilFormat = d3dformat_from_wined3dformat(wined3d_parameters.AutoDepthStencilFormat);
2865 parameters->Flags = wined3d_parameters.Flags;
2866 parameters->FullScreen_RefreshRateInHz = wined3d_parameters.FullScreen_RefreshRateInHz;
2867 parameters->FullScreen_PresentationInterval = wined3d_parameters.PresentationInterval;
2868
2869 device->declArraySize = 16;
2870 device->decls = HeapAlloc(GetProcessHeap(), 0, device->declArraySize * sizeof(*device->decls));
2871 if (!device->decls)
2872 {
2873 ERR("Failed to allocate FVF vertex delcaration map memory.\n");
2874 hr = E_OUTOFMEMORY;
2875 goto err;
2876 }
2877
2878 return D3D_OK;
2879
2880err:
2881 wined3d_mutex_lock();
2882 IWineD3DDevice_Uninit3D(device->WineD3DDevice, D3D8CB_DestroySwapChain);
2883 IWineD3DDevice_ReleaseFocusWindow(device->WineD3DDevice);
2884 IWineD3DDevice_Release(device->WineD3DDevice);
2885 wined3d_mutex_unlock();
2886 HeapFree(GetProcessHeap(), 0, device->handle_table.entries);
2887 return hr;
2888}
Note: See TracBrowser for help on using the repository browser.

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