VirtualBox

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

Last change on this file since 23793 was 23571, checked in by vboxsync, 15 years ago

crOpenGL: update to wine 1.1.30

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

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