VirtualBox

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

Last change on this file since 20227 was 19678, checked in by vboxsync, 16 years ago

opengl: update wine to 1.1.21, add d3d9.dll to build list

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

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