includes: Fix alignment for 64-bits
[wine/wine64.git] / dlls / d3d8 / device.c
blob648422532fad6fb97479be1d4781f7a726c9ed27
1 /*
2 * IDirect3DDevice8 implementation
4 * Copyright 2002-2004 Jason Edmeades
5 * Copyright 2004 Christian Costa
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.
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.
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
22 #include "config.h"
24 #include <math.h>
25 #include <stdarg.h>
27 #define NONAMELESSUNION
28 #define NONAMELESSSTRUCT
29 #include "windef.h"
30 #include "winbase.h"
31 #include "winuser.h"
32 #include "wingdi.h"
33 #include "wine/debug.h"
35 #include "d3d8_private.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(d3d8);
39 static HRESULT WINAPI D3D8CB_CreateSurface(IUnknown*,IUnknown*,UINT,UINT,WINED3DFORMAT,DWORD,WINED3DPOOL,UINT,WINED3DCUBEMAP_FACES,IWineD3DSurface**,HANDLE*);
42 /* Shader handle functions */
43 static shader_handle *alloc_shader_handle(IDirect3DDevice8Impl *This) {
44 if (This->free_shader_handles) {
45 /* Use a free handle */
46 shader_handle *handle = This->free_shader_handles;
47 This->free_shader_handles = *handle;
48 return handle;
50 if (!(This->allocated_shader_handles < This->shader_handle_table_size)) {
51 /* Grow the table */
52 DWORD new_size = This->shader_handle_table_size + (This->shader_handle_table_size >> 1);
53 shader_handle *new_handles = HeapReAlloc(GetProcessHeap(), 0, This->shader_handles, new_size * sizeof(shader_handle));
54 if (!new_handles) return NULL;
55 This->shader_handles = new_handles;
56 This->shader_handle_table_size = new_size;
59 return &This->shader_handles[This->allocated_shader_handles++];
62 static void free_shader_handle(IDirect3DDevice8Impl *This, shader_handle *handle) {
63 *handle = This->free_shader_handles;
64 This->free_shader_handles = handle;
67 /* IDirect3D IUnknown parts follow: */
68 static HRESULT WINAPI IDirect3DDevice8Impl_QueryInterface(LPDIRECT3DDEVICE8 iface,REFIID riid,LPVOID *ppobj)
70 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
72 if (IsEqualGUID(riid, &IID_IUnknown)
73 || IsEqualGUID(riid, &IID_IDirect3DDevice8)) {
74 IUnknown_AddRef(iface);
75 *ppobj = This;
76 return S_OK;
79 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
80 *ppobj = NULL;
81 return E_NOINTERFACE;
84 static ULONG WINAPI IDirect3DDevice8Impl_AddRef(LPDIRECT3DDEVICE8 iface) {
85 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
86 ULONG ref = InterlockedIncrement(&This->ref);
88 TRACE("(%p) : AddRef from %d\n", This, ref - 1);
90 return ref;
93 static ULONG WINAPI IDirect3DDevice8Impl_Release(LPDIRECT3DDEVICE8 iface) {
94 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
95 ULONG ref;
97 if (This->inDestruction) return 0;
98 ref = InterlockedDecrement(&This->ref);
100 TRACE("(%p) : ReleaseRef to %d\n", This, ref);
102 if (ref == 0) {
103 unsigned i;
105 TRACE("Releasing wined3d device %p\n", This->WineD3DDevice);
106 EnterCriticalSection(&d3d8_cs);
107 This->inDestruction = TRUE;
109 for(i = 0; i < This->numConvertedDecls; i++) {
110 IDirect3DVertexDeclaration8_Release(This->decls[i].decl);
112 HeapFree(GetProcessHeap(), 0, This->decls);
114 IWineD3DDevice_Uninit3D(This->WineD3DDevice, D3D8CB_DestroyDepthStencilSurface, D3D8CB_DestroySwapChain);
115 IWineD3DDevice_Release(This->WineD3DDevice);
116 HeapFree(GetProcessHeap(), 0, This->shader_handles);
117 HeapFree(GetProcessHeap(), 0, This);
118 LeaveCriticalSection(&d3d8_cs);
120 return ref;
123 /* IDirect3DDevice Interface follow: */
124 static HRESULT WINAPI IDirect3DDevice8Impl_TestCooperativeLevel(LPDIRECT3DDEVICE8 iface) {
125 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
126 HRESULT hr;
128 TRACE("(%p) : Relay\n", This);
129 EnterCriticalSection(&d3d8_cs);
130 hr = IWineD3DDevice_TestCooperativeLevel(This->WineD3DDevice);
131 LeaveCriticalSection(&d3d8_cs);
132 return hr;
135 static UINT WINAPI IDirect3DDevice8Impl_GetAvailableTextureMem(LPDIRECT3DDEVICE8 iface) {
136 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
137 HRESULT hr;
139 TRACE("(%p) Relay\n", This);
140 EnterCriticalSection(&d3d8_cs);
141 hr = IWineD3DDevice_GetAvailableTextureMem(This->WineD3DDevice);
142 LeaveCriticalSection(&d3d8_cs);
143 return hr;
146 static HRESULT WINAPI IDirect3DDevice8Impl_ResourceManagerDiscardBytes(LPDIRECT3DDEVICE8 iface, DWORD Bytes) {
147 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
148 HRESULT hr;
150 TRACE("(%p) : Relay bytes(%d)\n", This, Bytes);
151 EnterCriticalSection(&d3d8_cs);
152 hr = IWineD3DDevice_EvictManagedResources(This->WineD3DDevice);
153 LeaveCriticalSection(&d3d8_cs);
154 return hr;
157 static HRESULT WINAPI IDirect3DDevice8Impl_GetDirect3D(LPDIRECT3DDEVICE8 iface, IDirect3D8** ppD3D8) {
158 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
159 HRESULT hr = D3D_OK;
160 IWineD3D* pWineD3D;
162 TRACE("(%p) Relay\n", This);
164 if (NULL == ppD3D8) {
165 return D3DERR_INVALIDCALL;
168 EnterCriticalSection(&d3d8_cs);
169 hr = IWineD3DDevice_GetDirect3D(This->WineD3DDevice, &pWineD3D);
170 if (hr == D3D_OK && pWineD3D != NULL)
172 IWineD3D_GetParent(pWineD3D,(IUnknown **)ppD3D8);
173 IWineD3D_Release(pWineD3D);
174 } else {
175 FIXME("Call to IWineD3DDevice_GetDirect3D failed\n");
176 *ppD3D8 = NULL;
178 TRACE("(%p) returning %p\n",This , *ppD3D8);
179 LeaveCriticalSection(&d3d8_cs);
181 return hr;
184 static HRESULT WINAPI IDirect3DDevice8Impl_GetDeviceCaps(LPDIRECT3DDEVICE8 iface, D3DCAPS8* pCaps) {
185 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
186 HRESULT hrc = D3D_OK;
187 WINED3DCAPS *pWineCaps;
189 TRACE("(%p) : Relay pCaps %p\n", This, pCaps);
190 if(NULL == pCaps){
191 return D3DERR_INVALIDCALL;
193 pWineCaps = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WINED3DCAPS));
194 if(pWineCaps == NULL){
195 return D3DERR_INVALIDCALL; /* well this is what MSDN says to return */
198 EnterCriticalSection(&d3d8_cs);
199 hrc = IWineD3DDevice_GetDeviceCaps(This->WineD3DDevice, pWineCaps);
200 LeaveCriticalSection(&d3d8_cs);
201 WINECAPSTOD3D8CAPS(pCaps, pWineCaps)
202 HeapFree(GetProcessHeap(), 0, pWineCaps);
204 /* D3D8 doesn't support SM 2.0 or higher, so clamp to 1.x */
205 if(pCaps->PixelShaderVersion > D3DPS_VERSION(1,4)){
206 pCaps->PixelShaderVersion = D3DPS_VERSION(1,4);
208 if(pCaps->VertexShaderVersion > D3DVS_VERSION(1,1)){
209 pCaps->VertexShaderVersion = D3DVS_VERSION(1,1);
212 TRACE("Returning %p %p\n", This, pCaps);
213 return hrc;
216 static HRESULT WINAPI IDirect3DDevice8Impl_GetDisplayMode(LPDIRECT3DDEVICE8 iface, D3DDISPLAYMODE* pMode) {
217 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
218 HRESULT hr;
219 TRACE("(%p) Relay\n", This);
221 EnterCriticalSection(&d3d8_cs);
222 hr = IWineD3DDevice_GetDisplayMode(This->WineD3DDevice, 0, (WINED3DDISPLAYMODE *) pMode);
223 LeaveCriticalSection(&d3d8_cs);
224 return hr;
227 static HRESULT WINAPI IDirect3DDevice8Impl_GetCreationParameters(LPDIRECT3DDEVICE8 iface, D3DDEVICE_CREATION_PARAMETERS *pParameters) {
228 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
229 HRESULT hr;
230 TRACE("(%p) Relay\n", This);
232 EnterCriticalSection(&d3d8_cs);
233 hr = IWineD3DDevice_GetCreationParameters(This->WineD3DDevice, (WINED3DDEVICE_CREATION_PARAMETERS *) pParameters);
234 LeaveCriticalSection(&d3d8_cs);
235 return hr;
238 static HRESULT WINAPI IDirect3DDevice8Impl_SetCursorProperties(LPDIRECT3DDEVICE8 iface, UINT XHotSpot, UINT YHotSpot, IDirect3DSurface8* pCursorBitmap) {
239 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
240 IDirect3DSurface8Impl *pSurface = (IDirect3DSurface8Impl*)pCursorBitmap;
241 HRESULT hr;
242 TRACE("(%p) Relay\n", This);
243 if(!pCursorBitmap) {
244 WARN("No cursor bitmap, returning WINED3DERR_INVALIDCALL\n");
245 return WINED3DERR_INVALIDCALL;
248 EnterCriticalSection(&d3d8_cs);
249 hr = IWineD3DDevice_SetCursorProperties(This->WineD3DDevice,XHotSpot,YHotSpot,pSurface->wineD3DSurface);
250 LeaveCriticalSection(&d3d8_cs);
251 return hr;
254 static void WINAPI IDirect3DDevice8Impl_SetCursorPosition(LPDIRECT3DDEVICE8 iface, UINT XScreenSpace, UINT YScreenSpace, DWORD Flags) {
255 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
256 TRACE("(%p) Relay\n", This);
258 EnterCriticalSection(&d3d8_cs);
259 IWineD3DDevice_SetCursorPosition(This->WineD3DDevice, XScreenSpace, YScreenSpace, Flags);
260 LeaveCriticalSection(&d3d8_cs);
263 static BOOL WINAPI IDirect3DDevice8Impl_ShowCursor(LPDIRECT3DDEVICE8 iface, BOOL bShow) {
264 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
265 BOOL ret;
266 TRACE("(%p) Relay\n", This);
268 EnterCriticalSection(&d3d8_cs);
269 ret = IWineD3DDevice_ShowCursor(This->WineD3DDevice, bShow);
270 LeaveCriticalSection(&d3d8_cs);
271 return ret;
274 static HRESULT WINAPI IDirect3DDevice8Impl_CreateAdditionalSwapChain(LPDIRECT3DDEVICE8 iface, D3DPRESENT_PARAMETERS* pPresentationParameters, IDirect3DSwapChain8** pSwapChain) {
275 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
276 IDirect3DSwapChain8Impl* object;
277 HRESULT hrc = D3D_OK;
278 WINED3DPRESENT_PARAMETERS localParameters;
280 TRACE("(%p) Relay\n", This);
282 /* Fix the back buffer count */
283 if(pPresentationParameters->BackBufferCount == 0) {
284 pPresentationParameters->BackBufferCount = 1;
287 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
288 if (NULL == object) {
289 FIXME("Allocation of memory failed\n");
290 *pSwapChain = NULL;
291 return D3DERR_OUTOFVIDEOMEMORY;
293 object->ref = 1;
294 object->lpVtbl = &Direct3DSwapChain8_Vtbl;
296 /* Allocate an associated WineD3DDevice object */
297 localParameters.BackBufferWidth = pPresentationParameters->BackBufferWidth;
298 localParameters.BackBufferHeight = pPresentationParameters->BackBufferHeight;
299 localParameters.BackBufferFormat = pPresentationParameters->BackBufferFormat;
300 localParameters.BackBufferCount = pPresentationParameters->BackBufferCount;
301 localParameters.MultiSampleType = pPresentationParameters->MultiSampleType;
302 localParameters.MultiSampleQuality = 0; /* d3d9 only */
303 localParameters.SwapEffect = pPresentationParameters->SwapEffect;
304 localParameters.hDeviceWindow = pPresentationParameters->hDeviceWindow;
305 localParameters.Windowed = pPresentationParameters->Windowed;
306 localParameters.EnableAutoDepthStencil = pPresentationParameters->EnableAutoDepthStencil;
307 localParameters.AutoDepthStencilFormat = pPresentationParameters->AutoDepthStencilFormat;
308 localParameters.Flags = pPresentationParameters->Flags;
309 localParameters.FullScreen_RefreshRateInHz = pPresentationParameters->FullScreen_RefreshRateInHz;
310 localParameters.PresentationInterval = pPresentationParameters->FullScreen_PresentationInterval;
311 localParameters.AutoRestoreDisplayMode = TRUE;
313 EnterCriticalSection(&d3d8_cs);
314 hrc = IWineD3DDevice_CreateSwapChain(This->WineD3DDevice, &localParameters, &object->wineD3DSwapChain, (IUnknown*)object, D3D8CB_CreateRenderTarget, D3D8CB_CreateDepthStencilSurface, SURFACE_OPENGL);
315 LeaveCriticalSection(&d3d8_cs);
317 pPresentationParameters->BackBufferWidth = localParameters.BackBufferWidth;
318 pPresentationParameters->BackBufferHeight = localParameters.BackBufferHeight;
319 pPresentationParameters->BackBufferFormat = localParameters.BackBufferFormat;
320 pPresentationParameters->BackBufferCount = localParameters.BackBufferCount;
321 pPresentationParameters->MultiSampleType = localParameters.MultiSampleType;
322 pPresentationParameters->SwapEffect = localParameters.SwapEffect;
323 pPresentationParameters->hDeviceWindow = localParameters.hDeviceWindow;
324 pPresentationParameters->Windowed = localParameters.Windowed;
325 pPresentationParameters->EnableAutoDepthStencil = localParameters.EnableAutoDepthStencil;
326 pPresentationParameters->AutoDepthStencilFormat = localParameters.AutoDepthStencilFormat;
327 pPresentationParameters->Flags = localParameters.Flags;
328 pPresentationParameters->FullScreen_RefreshRateInHz = localParameters.FullScreen_RefreshRateInHz;
329 pPresentationParameters->FullScreen_PresentationInterval = localParameters.PresentationInterval;
331 if (hrc != D3D_OK) {
332 FIXME("(%p) call to IWineD3DDevice_CreateSwapChain failed\n", This);
333 HeapFree(GetProcessHeap(), 0 , object);
334 *pSwapChain = NULL;
335 }else{
336 IUnknown_AddRef(iface);
337 object->parentDevice = iface;
338 *pSwapChain = (IDirect3DSwapChain8 *)object;
340 TRACE("(%p) returning %p\n", This, *pSwapChain);
341 return hrc;
344 static HRESULT WINAPI IDirect3DDevice8Impl_Reset(LPDIRECT3DDEVICE8 iface, D3DPRESENT_PARAMETERS* pPresentationParameters) {
345 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
346 WINED3DPRESENT_PARAMETERS localParameters;
347 HRESULT hr;
349 TRACE("(%p) Relay pPresentationParameters(%p)\n", This, pPresentationParameters);
351 localParameters.BackBufferWidth = pPresentationParameters->BackBufferWidth;
352 localParameters.BackBufferHeight = pPresentationParameters->BackBufferHeight;
353 localParameters.BackBufferFormat = pPresentationParameters->BackBufferFormat;
354 localParameters.BackBufferCount = pPresentationParameters->BackBufferCount;
355 localParameters.MultiSampleType = pPresentationParameters->MultiSampleType;
356 localParameters.MultiSampleQuality = 0; /* d3d9 only */
357 localParameters.SwapEffect = pPresentationParameters->SwapEffect;
358 localParameters.hDeviceWindow = pPresentationParameters->hDeviceWindow;
359 localParameters.Windowed = pPresentationParameters->Windowed;
360 localParameters.EnableAutoDepthStencil = pPresentationParameters->EnableAutoDepthStencil;
361 localParameters.AutoDepthStencilFormat = pPresentationParameters->AutoDepthStencilFormat;
362 localParameters.Flags = pPresentationParameters->Flags;
363 localParameters.FullScreen_RefreshRateInHz = pPresentationParameters->FullScreen_RefreshRateInHz;
364 localParameters.PresentationInterval = pPresentationParameters->FullScreen_PresentationInterval;
365 localParameters.AutoRestoreDisplayMode = TRUE;
367 EnterCriticalSection(&d3d8_cs);
368 hr = IWineD3DDevice_Reset(This->WineD3DDevice, &localParameters);
369 LeaveCriticalSection(&d3d8_cs);
371 pPresentationParameters->BackBufferWidth = localParameters.BackBufferWidth;
372 pPresentationParameters->BackBufferHeight = localParameters.BackBufferHeight;
373 pPresentationParameters->BackBufferFormat = localParameters.BackBufferFormat;
374 pPresentationParameters->BackBufferCount = localParameters.BackBufferCount;
375 pPresentationParameters->MultiSampleType = localParameters.MultiSampleType;
376 pPresentationParameters->SwapEffect = localParameters.SwapEffect;
377 pPresentationParameters->hDeviceWindow = localParameters.hDeviceWindow;
378 pPresentationParameters->Windowed = localParameters.Windowed;
379 pPresentationParameters->EnableAutoDepthStencil = localParameters.EnableAutoDepthStencil;
380 pPresentationParameters->AutoDepthStencilFormat = localParameters.AutoDepthStencilFormat;
381 pPresentationParameters->Flags = localParameters.Flags;
382 pPresentationParameters->FullScreen_RefreshRateInHz = localParameters.FullScreen_RefreshRateInHz;
383 pPresentationParameters->FullScreen_PresentationInterval = localParameters.PresentationInterval;
385 return hr;
388 static HRESULT WINAPI IDirect3DDevice8Impl_Present(LPDIRECT3DDEVICE8 iface, CONST RECT* pSourceRect,CONST RECT* pDestRect,HWND hDestWindowOverride,CONST RGNDATA* pDirtyRegion) {
389 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
390 HRESULT hr;
391 TRACE("(%p) Relay\n", This);
393 EnterCriticalSection(&d3d8_cs);
394 hr = IWineD3DDevice_Present(This->WineD3DDevice, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
395 LeaveCriticalSection(&d3d8_cs);
396 return hr;
399 static HRESULT WINAPI IDirect3DDevice8Impl_GetBackBuffer(LPDIRECT3DDEVICE8 iface, UINT BackBuffer, D3DBACKBUFFER_TYPE Type, IDirect3DSurface8** ppBackBuffer) {
400 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
401 IWineD3DSurface *retSurface = NULL;
402 HRESULT rc = D3D_OK;
404 TRACE("(%p) Relay\n", This);
406 EnterCriticalSection(&d3d8_cs);
407 rc = IWineD3DDevice_GetBackBuffer(This->WineD3DDevice, 0, BackBuffer, (WINED3DBACKBUFFER_TYPE) Type, &retSurface);
408 if (rc == D3D_OK && NULL != retSurface && NULL != ppBackBuffer) {
409 IWineD3DSurface_GetParent(retSurface, (IUnknown **)ppBackBuffer);
410 IWineD3DSurface_Release(retSurface);
412 LeaveCriticalSection(&d3d8_cs);
413 return rc;
416 static HRESULT WINAPI IDirect3DDevice8Impl_GetRasterStatus(LPDIRECT3DDEVICE8 iface, D3DRASTER_STATUS* pRasterStatus) {
417 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
418 HRESULT hr;
419 TRACE("(%p) Relay\n", This);
421 EnterCriticalSection(&d3d8_cs);
422 hr = IWineD3DDevice_GetRasterStatus(This->WineD3DDevice, 0, (WINED3DRASTER_STATUS *) pRasterStatus);
423 LeaveCriticalSection(&d3d8_cs);
424 return hr;
427 static void WINAPI IDirect3DDevice8Impl_SetGammaRamp(LPDIRECT3DDEVICE8 iface, DWORD Flags, CONST D3DGAMMARAMP* pRamp) {
428 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
429 TRACE("(%p) Relay\n", This);
431 /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
432 EnterCriticalSection(&d3d8_cs);
433 IWineD3DDevice_SetGammaRamp(This->WineD3DDevice, 0, Flags, (CONST WINED3DGAMMARAMP *) pRamp);
434 LeaveCriticalSection(&d3d8_cs);
437 static void WINAPI IDirect3DDevice8Impl_GetGammaRamp(LPDIRECT3DDEVICE8 iface, D3DGAMMARAMP* pRamp) {
438 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
439 TRACE("(%p) Relay\n", This);
441 /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
442 EnterCriticalSection(&d3d8_cs);
443 IWineD3DDevice_GetGammaRamp(This->WineD3DDevice, 0, (WINED3DGAMMARAMP *) pRamp);
444 LeaveCriticalSection(&d3d8_cs);
447 static HRESULT WINAPI IDirect3DDevice8Impl_CreateTexture(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height, UINT Levels, DWORD Usage,
448 D3DFORMAT Format, D3DPOOL Pool, IDirect3DTexture8 **ppTexture) {
449 IDirect3DTexture8Impl *object;
450 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
451 HRESULT hrc = D3D_OK;
453 TRACE("(%p) : W(%d) H(%d), Lvl(%d) d(%d), Fmt(%u), Pool(%d)\n", This, Width, Height, Levels, Usage, Format, Pool);
455 /* Allocate the storage for the device */
456 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DTexture8Impl));
458 if (NULL == object) {
459 FIXME("Allocation of memory failed\n");
460 /* *ppTexture = NULL; */
461 return D3DERR_OUTOFVIDEOMEMORY;
464 object->lpVtbl = &Direct3DTexture8_Vtbl;
465 object->ref = 1;
466 EnterCriticalSection(&d3d8_cs);
467 hrc = IWineD3DDevice_CreateTexture(This->WineD3DDevice, Width, Height, Levels, Usage & WINED3DUSAGE_MASK,
468 (WINED3DFORMAT)Format, (WINED3DPOOL) Pool, &object->wineD3DTexture, NULL, (IUnknown *)object, D3D8CB_CreateSurface);
469 LeaveCriticalSection(&d3d8_cs);
471 if (FAILED(hrc)) {
472 /* free up object */
473 FIXME("(%p) call to IWineD3DDevice_CreateTexture failed\n", This);
474 HeapFree(GetProcessHeap(), 0, object);
475 /* *ppTexture = NULL; */
476 } else {
477 IUnknown_AddRef(iface);
478 object->parentDevice = iface;
479 *ppTexture = (LPDIRECT3DTEXTURE8) object;
480 TRACE("(%p) Created Texture %p, %p\n",This,object,object->wineD3DTexture);
483 return hrc;
486 static HRESULT WINAPI IDirect3DDevice8Impl_CreateVolumeTexture(LPDIRECT3DDEVICE8 iface,
487 UINT Width, UINT Height, UINT Depth, UINT Levels, DWORD Usage,
488 D3DFORMAT Format, D3DPOOL Pool, IDirect3DVolumeTexture8** ppVolumeTexture) {
490 IDirect3DVolumeTexture8Impl *object;
491 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
492 HRESULT hrc = D3D_OK;
494 TRACE("(%p) Relay\n", This);
496 /* Allocate the storage for the device */
497 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DVolumeTexture8Impl));
498 if (NULL == object) {
499 FIXME("(%p) allocation of memory failed\n", This);
500 *ppVolumeTexture = NULL;
501 return D3DERR_OUTOFVIDEOMEMORY;
504 object->lpVtbl = &Direct3DVolumeTexture8_Vtbl;
505 object->ref = 1;
506 EnterCriticalSection(&d3d8_cs);
507 hrc = IWineD3DDevice_CreateVolumeTexture(This->WineD3DDevice, Width, Height, Depth, Levels, Usage & WINED3DUSAGE_MASK,
508 (WINED3DFORMAT)Format, (WINED3DPOOL) Pool, &object->wineD3DVolumeTexture, NULL,
509 (IUnknown *)object, D3D8CB_CreateVolume);
510 LeaveCriticalSection(&d3d8_cs);
512 if (hrc != D3D_OK) {
514 /* free up object */
515 FIXME("(%p) call to IWineD3DDevice_CreateVolumeTexture failed\n", This);
516 HeapFree(GetProcessHeap(), 0, object);
517 *ppVolumeTexture = NULL;
518 } else {
519 IUnknown_AddRef(iface);
520 object->parentDevice = iface;
521 *ppVolumeTexture = (LPDIRECT3DVOLUMETEXTURE8) object;
523 TRACE("(%p) returning %p\n", This , *ppVolumeTexture);
524 return hrc;
527 static HRESULT WINAPI IDirect3DDevice8Impl_CreateCubeTexture(LPDIRECT3DDEVICE8 iface, UINT EdgeLength, UINT Levels, DWORD Usage,
528 D3DFORMAT Format, D3DPOOL Pool, IDirect3DCubeTexture8** ppCubeTexture) {
530 IDirect3DCubeTexture8Impl *object;
531 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
532 HRESULT hr = D3D_OK;
534 TRACE("(%p) : ELen(%d) Lvl(%d) Usage(%d) fmt(%u), Pool(%d)\n" , This, EdgeLength, Levels, Usage, Format, Pool);
536 /* Allocate the storage for the device */
537 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
539 if (NULL == object) {
540 FIXME("(%p) allocation of CubeTexture failed\n", This);
541 *ppCubeTexture = NULL;
542 return D3DERR_OUTOFVIDEOMEMORY;
545 object->lpVtbl = &Direct3DCubeTexture8_Vtbl;
546 object->ref = 1;
547 EnterCriticalSection(&d3d8_cs);
548 hr = IWineD3DDevice_CreateCubeTexture(This->WineD3DDevice, EdgeLength, Levels, Usage & WINED3DUSAGE_MASK,
549 (WINED3DFORMAT)Format, (WINED3DPOOL) Pool, &object->wineD3DCubeTexture, NULL, (IUnknown*)object,
550 D3D8CB_CreateSurface);
551 LeaveCriticalSection(&d3d8_cs);
553 if (hr != D3D_OK){
555 /* free up object */
556 FIXME("(%p) call to IWineD3DDevice_CreateCubeTexture failed\n", This);
557 HeapFree(GetProcessHeap(), 0, object);
558 *ppCubeTexture = NULL;
559 } else {
560 IUnknown_AddRef(iface);
561 object->parentDevice = iface;
562 *ppCubeTexture = (LPDIRECT3DCUBETEXTURE8) object;
565 TRACE("(%p) returning %p\n",This, *ppCubeTexture);
566 return hr;
569 static HRESULT WINAPI IDirect3DDevice8Impl_CreateVertexBuffer(LPDIRECT3DDEVICE8 iface, UINT Size, DWORD Usage, DWORD FVF, D3DPOOL Pool, IDirect3DVertexBuffer8** ppVertexBuffer) {
570 IDirect3DVertexBuffer8Impl *object;
571 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
572 HRESULT hrc = D3D_OK;
574 TRACE("(%p) Relay\n", This);
575 /* Allocate the storage for the device */
576 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DVertexBuffer8Impl));
577 if (NULL == object) {
578 FIXME("Allocation of memory failed\n");
579 *ppVertexBuffer = NULL;
580 return D3DERR_OUTOFVIDEOMEMORY;
583 object->lpVtbl = &Direct3DVertexBuffer8_Vtbl;
584 object->ref = 1;
585 EnterCriticalSection(&d3d8_cs);
586 hrc = IWineD3DDevice_CreateVertexBuffer(This->WineD3DDevice, Size, Usage & WINED3DUSAGE_MASK, FVF, (WINED3DPOOL) Pool, &(object->wineD3DVertexBuffer), NULL, (IUnknown *)object);
587 LeaveCriticalSection(&d3d8_cs);
589 if (D3D_OK != hrc) {
591 /* free up object */
592 FIXME("(%p) call to IWineD3DDevice_CreateVertexBuffer failed\n", This);
593 HeapFree(GetProcessHeap(), 0, object);
594 *ppVertexBuffer = NULL;
595 } else {
596 IUnknown_AddRef(iface);
597 object->parentDevice = iface;
598 *ppVertexBuffer = (LPDIRECT3DVERTEXBUFFER8) object;
600 return hrc;
603 static HRESULT WINAPI IDirect3DDevice8Impl_CreateIndexBuffer(LPDIRECT3DDEVICE8 iface, UINT Length, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IDirect3DIndexBuffer8** ppIndexBuffer) {
604 IDirect3DIndexBuffer8Impl *object;
605 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
606 HRESULT hrc = D3D_OK;
608 TRACE("(%p) Relay\n", This);
609 /* Allocate the storage for the device */
610 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
611 if (NULL == object) {
612 FIXME("Allocation of memory failed\n");
613 *ppIndexBuffer = NULL;
614 return D3DERR_OUTOFVIDEOMEMORY;
617 object->lpVtbl = &Direct3DIndexBuffer8_Vtbl;
618 object->ref = 1;
619 TRACE("Calling wined3d create index buffer\n");
620 EnterCriticalSection(&d3d8_cs);
621 hrc = IWineD3DDevice_CreateIndexBuffer(This->WineD3DDevice, Length, Usage & WINED3DUSAGE_MASK, Format, (WINED3DPOOL) Pool, &object->wineD3DIndexBuffer, NULL, (IUnknown *)object);
622 LeaveCriticalSection(&d3d8_cs);
624 if (D3D_OK != hrc) {
626 /* free up object */
627 FIXME("(%p) call to IWineD3DDevice_CreateIndexBuffer failed\n", This);
628 HeapFree(GetProcessHeap(), 0, object);
629 *ppIndexBuffer = NULL;
630 } else {
631 IUnknown_AddRef(iface);
632 object->parentDevice = iface;
633 *ppIndexBuffer = (LPDIRECT3DINDEXBUFFER8)object;
635 return hrc;
638 static 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) {
639 HRESULT hrc;
640 IDirect3DSurface8Impl *object;
641 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
642 TRACE("(%p) Relay\n", This);
644 if(MultisampleQuality > 0){
645 FIXME("MultisampleQuality set to %d, substituting 0\n" , MultisampleQuality);
647 MultisampleQuality
648 [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.
650 MultisampleQuality=0;
652 /*FIXME: Check MAX bounds of MultisampleQuality*/
654 /* Allocate the storage for the device */
655 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DSurface8Impl));
656 if (NULL == object) {
657 FIXME("Allocation of memory failed\n");
658 *ppSurface = NULL;
659 return D3DERR_OUTOFVIDEOMEMORY;
662 object->lpVtbl = &Direct3DSurface8_Vtbl;
663 object->ref = 1;
665 TRACE("(%p) : w(%d) h(%d) fmt(%d) surf@%p\n", This, Width, Height, Format, *ppSurface);
667 /* Not called from the VTable, no locking needed */
668 hrc = IWineD3DDevice_CreateSurface(This->WineD3DDevice, Width, Height, Format, Lockable, Discard, Level, &object->wineD3DSurface, Type, Usage & WINED3DUSAGE_MASK, (WINED3DPOOL) Pool,MultiSample,MultisampleQuality, NULL, SURFACE_OPENGL, (IUnknown *)object);
669 if (hrc != D3D_OK || NULL == object->wineD3DSurface) {
670 /* free up object */
671 FIXME("(%p) call to IWineD3DDevice_CreateSurface failed\n", This);
672 HeapFree(GetProcessHeap(), 0, object);
673 *ppSurface = NULL;
674 } else {
675 IUnknown_AddRef(iface);
676 object->parentDevice = iface;
677 *ppSurface = (LPDIRECT3DSURFACE8) object;
679 return hrc;
682 static HRESULT WINAPI IDirect3DDevice8Impl_CreateRenderTarget(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, BOOL Lockable, IDirect3DSurface8** ppSurface) {
683 HRESULT hr;
684 TRACE("Relay\n");
686 EnterCriticalSection(&d3d8_cs);
687 hr = IDirect3DDevice8Impl_CreateSurface(iface, Width, Height, Format, Lockable, FALSE /* Discard */, 0 /* Level */ , ppSurface, D3DRTYPE_SURFACE, D3DUSAGE_RENDERTARGET, D3DPOOL_DEFAULT, MultiSample, 0);
688 LeaveCriticalSection(&d3d8_cs);
689 return hr;
692 static HRESULT WINAPI IDirect3DDevice8Impl_CreateDepthStencilSurface(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, IDirect3DSurface8** ppSurface) {
693 HRESULT hr;
694 TRACE("Relay\n");
696 /* TODO: Verify that Discard is false */
697 EnterCriticalSection(&d3d8_cs);
698 hr = IDirect3DDevice8Impl_CreateSurface(iface, Width, Height, Format, TRUE /* Lockable */, FALSE, 0 /* Level */
699 ,ppSurface, D3DRTYPE_SURFACE, D3DUSAGE_DEPTHSTENCIL,
700 D3DPOOL_DEFAULT, MultiSample, 0);
701 LeaveCriticalSection(&d3d8_cs);
702 return hr;
705 /* IDirect3DDevice8Impl::CreateImageSurface returns surface with pool type SYSTEMMEM */
706 static HRESULT WINAPI IDirect3DDevice8Impl_CreateImageSurface(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height, D3DFORMAT Format, IDirect3DSurface8** ppSurface) {
707 HRESULT hr;
708 TRACE("Relay\n");
710 EnterCriticalSection(&d3d8_cs);
711 hr = IDirect3DDevice8Impl_CreateSurface(iface, Width, Height, Format, TRUE /* Loackable */ , FALSE /*Discard*/ , 0 /* Level */ , ppSurface,
712 D3DRTYPE_SURFACE, 0 /* Usage (undefined/none) */ , D3DPOOL_SYSTEMMEM, D3DMULTISAMPLE_NONE, 0 /* MultisampleQuality */);
713 LeaveCriticalSection(&d3d8_cs);
714 return hr;
717 static HRESULT WINAPI IDirect3DDevice8Impl_CopyRects(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8 *pSourceSurface, CONST RECT *pSourceRects, UINT cRects, IDirect3DSurface8 *pDestinationSurface, CONST POINT *pDestPoints) {
718 IDirect3DSurface8Impl *Source = (IDirect3DSurface8Impl *) pSourceSurface;
719 IDirect3DSurface8Impl *Dest = (IDirect3DSurface8Impl *) pDestinationSurface;
721 HRESULT hr = WINED3D_OK;
722 WINED3DFORMAT srcFormat, destFormat;
723 UINT srcWidth, destWidth;
724 UINT srcHeight, destHeight;
725 UINT srcSize;
726 WINED3DSURFACE_DESC winedesc;
728 TRACE("(%p) pSrcSur=%p, pSourceRects=%p, cRects=%d, pDstSur=%p, pDestPtsArr=%p\n", iface,
729 pSourceSurface, pSourceRects, cRects, pDestinationSurface, pDestPoints);
732 /* Check that the source texture is in WINED3DPOOL_SYSTEMMEM and the destination texture is in WINED3DPOOL_DEFAULT */
733 memset(&winedesc, 0, sizeof(winedesc));
735 winedesc.Format = &srcFormat;
736 winedesc.Width = &srcWidth;
737 winedesc.Height = &srcHeight;
738 winedesc.Size = &srcSize;
739 IWineD3DSurface_GetDesc(Source->wineD3DSurface, &winedesc);
741 winedesc.Format = &destFormat;
742 winedesc.Width = &destWidth;
743 winedesc.Height = &destHeight;
744 winedesc.Size = NULL;
745 EnterCriticalSection(&d3d8_cs);
746 IWineD3DSurface_GetDesc(Dest->wineD3DSurface, &winedesc);
748 /* Check that the source and destination formats match */
749 if (srcFormat != destFormat && WINED3DFMT_UNKNOWN != destFormat) {
750 WARN("(%p) source %p format must match the dest %p format, returning WINED3DERR_INVALIDCALL\n", iface, pSourceSurface, pDestinationSurface);
751 LeaveCriticalSection(&d3d8_cs);
752 return WINED3DERR_INVALIDCALL;
753 } else if (WINED3DFMT_UNKNOWN == destFormat) {
754 TRACE("(%p) : Converting destination surface from WINED3DFMT_UNKNOWN to the source format\n", iface);
755 IWineD3DSurface_SetFormat(Dest->wineD3DSurface, srcFormat);
756 destFormat = srcFormat;
759 /* Quick if complete copy ... */
760 if (cRects == 0 && pSourceRects == NULL && pDestPoints == NULL) {
761 IWineD3DSurface_BltFast(Dest->wineD3DSurface, 0, 0, Source->wineD3DSurface, NULL, WINEDDBLTFAST_NOCOLORKEY);
762 } else {
763 unsigned int i;
764 /* Copy rect by rect */
765 if (NULL != pSourceRects && NULL != pDestPoints) {
766 for (i = 0; i < cRects; ++i) {
767 IWineD3DSurface_BltFast(Dest->wineD3DSurface, pDestPoints[i].x, pDestPoints[i].y, Source->wineD3DSurface, (RECT *) &pSourceRects[i], WINEDDBLTFAST_NOCOLORKEY);
769 } else {
770 for (i = 0; i < cRects; ++i) {
771 IWineD3DSurface_BltFast(Dest->wineD3DSurface, 0, 0, Source->wineD3DSurface, (RECT *) &pSourceRects[i], WINEDDBLTFAST_NOCOLORKEY);
775 LeaveCriticalSection(&d3d8_cs);
777 return hr;
780 static HRESULT WINAPI IDirect3DDevice8Impl_UpdateTexture(LPDIRECT3DDEVICE8 iface, IDirect3DBaseTexture8* pSourceTexture, IDirect3DBaseTexture8* pDestinationTexture) {
781 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
782 HRESULT hr;
783 TRACE("(%p) Relay\n" , This);
785 EnterCriticalSection(&d3d8_cs);
786 hr = IWineD3DDevice_UpdateTexture(This->WineD3DDevice, ((IDirect3DBaseTexture8Impl *)pSourceTexture)->wineD3DBaseTexture, ((IDirect3DBaseTexture8Impl *)pDestinationTexture)->wineD3DBaseTexture);
787 LeaveCriticalSection(&d3d8_cs);
788 return hr;
791 static HRESULT WINAPI IDirect3DDevice8Impl_GetFrontBuffer(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8* pDestSurface) {
792 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
793 IDirect3DSurface8Impl *destSurface = (IDirect3DSurface8Impl *)pDestSurface;
794 HRESULT hr;
796 TRACE("(%p) Relay\n" , This);
798 if (pDestSurface == NULL) {
799 WARN("(%p) : Caller passed NULL as pDestSurface returning D3DERR_INVALIDCALL\n", This);
800 return D3DERR_INVALIDCALL;
803 EnterCriticalSection(&d3d8_cs);
804 hr = IWineD3DDevice_GetFrontBufferData(This->WineD3DDevice, 0, destSurface->wineD3DSurface);
805 LeaveCriticalSection(&d3d8_cs);
806 return hr;
809 static HRESULT WINAPI IDirect3DDevice8Impl_SetRenderTarget(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8* pRenderTarget, IDirect3DSurface8* pNewZStencil) {
810 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
811 IDirect3DSurface8Impl *pSurface = (IDirect3DSurface8Impl *)pRenderTarget;
812 IDirect3DSurface8Impl *pZSurface = (IDirect3DSurface8Impl *)pNewZStencil;
813 IWineD3DSurface *original_ds = NULL;
814 HRESULT hr;
815 TRACE("(%p) Relay\n" , This);
817 EnterCriticalSection(&d3d8_cs);
819 hr = IWineD3DDevice_GetDepthStencilSurface(This->WineD3DDevice, &original_ds);
820 if (hr == WINED3D_OK || hr == WINED3DERR_NOTFOUND)
822 hr = IWineD3DDevice_SetDepthStencilSurface(This->WineD3DDevice, pZSurface ? pZSurface->wineD3DSurface : NULL);
823 if (SUCCEEDED(hr) && pSurface)
824 hr = IWineD3DDevice_SetRenderTarget(This->WineD3DDevice, 0, pSurface->wineD3DSurface);
825 if (FAILED(hr)) IWineD3DDevice_SetDepthStencilSurface(This->WineD3DDevice, original_ds);
827 if (original_ds) IWineD3DSurface_Release(original_ds);
829 LeaveCriticalSection(&d3d8_cs);
830 return hr;
833 static HRESULT WINAPI IDirect3DDevice8Impl_GetRenderTarget(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8** ppRenderTarget) {
834 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
835 HRESULT hr = D3D_OK;
836 IWineD3DSurface *pRenderTarget;
838 TRACE("(%p) Relay\n" , This);
840 if (ppRenderTarget == NULL) {
841 return D3DERR_INVALIDCALL;
843 EnterCriticalSection(&d3d8_cs);
844 hr = IWineD3DDevice_GetRenderTarget(This->WineD3DDevice, 0, &pRenderTarget);
846 if (hr == D3D_OK && pRenderTarget != NULL) {
847 IWineD3DSurface_GetParent(pRenderTarget,(IUnknown**)ppRenderTarget);
848 IWineD3DSurface_Release(pRenderTarget);
849 } else {
850 FIXME("Call to IWineD3DDevice_GetRenderTarget failed\n");
851 *ppRenderTarget = NULL;
853 LeaveCriticalSection(&d3d8_cs);
855 return hr;
858 static HRESULT WINAPI IDirect3DDevice8Impl_GetDepthStencilSurface(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8** ppZStencilSurface) {
859 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
860 HRESULT hr = D3D_OK;
861 IWineD3DSurface *pZStencilSurface;
863 TRACE("(%p) Relay\n" , This);
864 if(ppZStencilSurface == NULL){
865 return D3DERR_INVALIDCALL;
868 EnterCriticalSection(&d3d8_cs);
869 hr=IWineD3DDevice_GetDepthStencilSurface(This->WineD3DDevice,&pZStencilSurface);
870 if (hr == WINED3D_OK) {
871 IWineD3DSurface_GetParent(pZStencilSurface,(IUnknown**)ppZStencilSurface);
872 IWineD3DSurface_Release(pZStencilSurface);
873 }else{
874 if (hr != WINED3DERR_NOTFOUND)
875 FIXME("Call to IWineD3DDevice_GetDepthStencilSurface failed with 0x%08x\n", hr);
876 *ppZStencilSurface = NULL;
878 LeaveCriticalSection(&d3d8_cs);
880 return hr;
883 static HRESULT WINAPI IDirect3DDevice8Impl_BeginScene(LPDIRECT3DDEVICE8 iface) {
884 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
885 HRESULT hr;
886 TRACE("(%p) Relay\n" , This);
888 EnterCriticalSection(&d3d8_cs);
889 hr = IWineD3DDevice_BeginScene(This->WineD3DDevice);
890 LeaveCriticalSection(&d3d8_cs);
891 return hr;
894 static HRESULT WINAPI IDirect3DDevice8Impl_EndScene(LPDIRECT3DDEVICE8 iface) {
895 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
896 HRESULT hr;
897 TRACE("(%p) Relay\n" , This);
899 EnterCriticalSection(&d3d8_cs);
900 hr = IWineD3DDevice_EndScene(This->WineD3DDevice);
901 LeaveCriticalSection(&d3d8_cs);
902 return hr;
905 static HRESULT WINAPI IDirect3DDevice8Impl_Clear(LPDIRECT3DDEVICE8 iface, DWORD Count, CONST D3DRECT* pRects, DWORD Flags, D3DCOLOR Color, float Z, DWORD Stencil) {
906 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
907 HRESULT hr;
908 TRACE("(%p) Relay\n" , This);
910 /* Note: D3DRECT is compatible with WINED3DRECT */
911 EnterCriticalSection(&d3d8_cs);
912 hr = IWineD3DDevice_Clear(This->WineD3DDevice, Count, (CONST WINED3DRECT*) pRects, Flags, Color, Z, Stencil);
913 LeaveCriticalSection(&d3d8_cs);
914 return hr;
917 static HRESULT WINAPI IDirect3DDevice8Impl_SetTransform(LPDIRECT3DDEVICE8 iface, D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX* lpMatrix) {
918 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
919 HRESULT hr;
920 TRACE("(%p) Relay\n" , This);
922 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
923 EnterCriticalSection(&d3d8_cs);
924 hr = IWineD3DDevice_SetTransform(This->WineD3DDevice, State, (CONST WINED3DMATRIX*) lpMatrix);
925 LeaveCriticalSection(&d3d8_cs);
926 return hr;
929 static HRESULT WINAPI IDirect3DDevice8Impl_GetTransform(LPDIRECT3DDEVICE8 iface, D3DTRANSFORMSTATETYPE State,D3DMATRIX* pMatrix) {
930 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
931 HRESULT hr;
932 TRACE("(%p) Relay\n" , This);
934 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
935 EnterCriticalSection(&d3d8_cs);
936 hr = IWineD3DDevice_GetTransform(This->WineD3DDevice, State, (WINED3DMATRIX*) pMatrix);
937 LeaveCriticalSection(&d3d8_cs);
938 return hr;
941 static HRESULT WINAPI IDirect3DDevice8Impl_MultiplyTransform(LPDIRECT3DDEVICE8 iface, D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX* pMatrix) {
942 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
943 HRESULT hr;
944 TRACE("(%p) Relay\n" , This);
946 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
947 EnterCriticalSection(&d3d8_cs);
948 hr = IWineD3DDevice_MultiplyTransform(This->WineD3DDevice, State, (CONST WINED3DMATRIX*) pMatrix);
949 LeaveCriticalSection(&d3d8_cs);
950 return hr;
953 static HRESULT WINAPI IDirect3DDevice8Impl_SetViewport(LPDIRECT3DDEVICE8 iface, CONST D3DVIEWPORT8* pViewport) {
954 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
955 HRESULT hr;
956 TRACE("(%p) Relay\n" , This);
958 /* Note: D3DVIEWPORT8 is compatible with WINED3DVIEWPORT */
959 EnterCriticalSection(&d3d8_cs);
960 hr = IWineD3DDevice_SetViewport(This->WineD3DDevice, (const WINED3DVIEWPORT *)pViewport);
961 LeaveCriticalSection(&d3d8_cs);
962 return hr;
965 static HRESULT WINAPI IDirect3DDevice8Impl_GetViewport(LPDIRECT3DDEVICE8 iface, D3DVIEWPORT8* pViewport) {
966 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
967 HRESULT hr;
968 TRACE("(%p) Relay\n" , This);
970 /* Note: D3DVIEWPORT8 is compatible with WINED3DVIEWPORT */
971 EnterCriticalSection(&d3d8_cs);
972 hr = IWineD3DDevice_GetViewport(This->WineD3DDevice, (WINED3DVIEWPORT *)pViewport);
973 LeaveCriticalSection(&d3d8_cs);
974 return hr;
977 static HRESULT WINAPI IDirect3DDevice8Impl_SetMaterial(LPDIRECT3DDEVICE8 iface, CONST D3DMATERIAL8* pMaterial) {
978 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
979 HRESULT hr;
980 TRACE("(%p) Relay\n" , This);
982 /* Note: D3DMATERIAL8 is compatible with WINED3DMATERIAL */
983 EnterCriticalSection(&d3d8_cs);
984 hr = IWineD3DDevice_SetMaterial(This->WineD3DDevice, (const WINED3DMATERIAL *)pMaterial);
985 LeaveCriticalSection(&d3d8_cs);
986 return hr;
989 static HRESULT WINAPI IDirect3DDevice8Impl_GetMaterial(LPDIRECT3DDEVICE8 iface, D3DMATERIAL8* pMaterial) {
990 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
991 HRESULT hr;
992 TRACE("(%p) Relay\n" , This);
994 /* Note: D3DMATERIAL8 is compatible with WINED3DMATERIAL */
995 EnterCriticalSection(&d3d8_cs);
996 hr = IWineD3DDevice_GetMaterial(This->WineD3DDevice, (WINED3DMATERIAL *)pMaterial);
997 LeaveCriticalSection(&d3d8_cs);
998 return hr;
1001 static HRESULT WINAPI IDirect3DDevice8Impl_SetLight(LPDIRECT3DDEVICE8 iface, DWORD Index, CONST D3DLIGHT8* pLight) {
1002 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1003 HRESULT hr;
1004 TRACE("(%p) Relay\n" , This);
1006 /* Note: D3DLIGHT8 is compatible with WINED3DLIGHT */
1007 EnterCriticalSection(&d3d8_cs);
1008 hr = IWineD3DDevice_SetLight(This->WineD3DDevice, Index, (const WINED3DLIGHT *)pLight);
1009 LeaveCriticalSection(&d3d8_cs);
1010 return hr;
1013 static HRESULT WINAPI IDirect3DDevice8Impl_GetLight(LPDIRECT3DDEVICE8 iface, DWORD Index,D3DLIGHT8* pLight) {
1014 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1015 HRESULT hr;
1016 TRACE("(%p) Relay\n" , This);
1018 /* Note: D3DLIGHT8 is compatible with WINED3DLIGHT */
1019 EnterCriticalSection(&d3d8_cs);
1020 hr = IWineD3DDevice_GetLight(This->WineD3DDevice, Index, (WINED3DLIGHT *)pLight);
1021 LeaveCriticalSection(&d3d8_cs);
1022 return hr;
1025 static HRESULT WINAPI IDirect3DDevice8Impl_LightEnable(LPDIRECT3DDEVICE8 iface, DWORD Index,BOOL Enable) {
1026 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1027 HRESULT hr;
1028 TRACE("(%p) Relay\n" , This);
1030 EnterCriticalSection(&d3d8_cs);
1031 hr = IWineD3DDevice_SetLightEnable(This->WineD3DDevice, Index, Enable);
1032 LeaveCriticalSection(&d3d8_cs);
1033 return hr;
1036 static HRESULT WINAPI IDirect3DDevice8Impl_GetLightEnable(LPDIRECT3DDEVICE8 iface, DWORD Index,BOOL* pEnable) {
1037 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1038 HRESULT hr;
1039 TRACE("(%p) Relay\n" , This);
1041 EnterCriticalSection(&d3d8_cs);
1042 hr = IWineD3DDevice_GetLightEnable(This->WineD3DDevice, Index, pEnable);
1043 LeaveCriticalSection(&d3d8_cs);
1044 return hr;
1047 static HRESULT WINAPI IDirect3DDevice8Impl_SetClipPlane(LPDIRECT3DDEVICE8 iface, DWORD Index,CONST float* pPlane) {
1048 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1049 HRESULT hr;
1050 TRACE("(%p) Relay\n" , This);
1052 EnterCriticalSection(&d3d8_cs);
1053 hr = IWineD3DDevice_SetClipPlane(This->WineD3DDevice, Index, pPlane);
1054 LeaveCriticalSection(&d3d8_cs);
1055 return hr;
1058 static HRESULT WINAPI IDirect3DDevice8Impl_GetClipPlane(LPDIRECT3DDEVICE8 iface, DWORD Index,float* pPlane) {
1059 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1060 HRESULT hr;
1061 TRACE("(%p) Relay\n" , This);
1063 EnterCriticalSection(&d3d8_cs);
1064 hr = IWineD3DDevice_GetClipPlane(This->WineD3DDevice, Index, pPlane);
1065 LeaveCriticalSection(&d3d8_cs);
1066 return hr;
1069 static HRESULT WINAPI IDirect3DDevice8Impl_SetRenderState(LPDIRECT3DDEVICE8 iface, D3DRENDERSTATETYPE State,DWORD Value) {
1070 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1071 HRESULT hr;
1072 TRACE("(%p) Relay\n" , This);
1074 EnterCriticalSection(&d3d8_cs);
1075 hr = IWineD3DDevice_SetRenderState(This->WineD3DDevice, State, Value);
1076 LeaveCriticalSection(&d3d8_cs);
1077 return hr;
1080 static HRESULT WINAPI IDirect3DDevice8Impl_GetRenderState(LPDIRECT3DDEVICE8 iface, D3DRENDERSTATETYPE State,DWORD* pValue) {
1081 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1082 HRESULT hr;
1083 TRACE("(%p) Relay\n" , This);
1085 EnterCriticalSection(&d3d8_cs);
1086 hr = IWineD3DDevice_GetRenderState(This->WineD3DDevice, State, pValue);
1087 LeaveCriticalSection(&d3d8_cs);
1088 return hr;
1091 static HRESULT WINAPI IDirect3DDevice8Impl_BeginStateBlock(LPDIRECT3DDEVICE8 iface) {
1092 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1093 HRESULT hr;
1094 TRACE("(%p)\n", This);
1096 EnterCriticalSection(&d3d8_cs);
1097 hr = IWineD3DDevice_BeginStateBlock(This->WineD3DDevice);
1098 LeaveCriticalSection(&d3d8_cs);
1099 return hr;
1102 static HRESULT WINAPI IDirect3DDevice8Impl_EndStateBlock(LPDIRECT3DDEVICE8 iface, DWORD* pToken) {
1103 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1104 HRESULT hr;
1105 IWineD3DStateBlock* wineD3DStateBlock;
1106 IDirect3DStateBlock8Impl* object;
1108 TRACE("(%p) Relay\n", This);
1110 /* Tell wineD3D to endstateblock before anything else (in case we run out
1111 * of memory later and cause locking problems)
1113 EnterCriticalSection(&d3d8_cs);
1114 hr = IWineD3DDevice_EndStateBlock(This->WineD3DDevice , &wineD3DStateBlock);
1115 if (hr != D3D_OK) {
1116 FIXME("IWineD3DDevice_EndStateBlock returned an error\n");
1117 LeaveCriticalSection(&d3d8_cs);
1118 return hr;
1121 /* allocate a new IDirectD3DStateBlock */
1122 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY ,sizeof(IDirect3DStateBlock8Impl));
1123 object->ref = 1;
1124 object->lpVtbl = &Direct3DStateBlock8_Vtbl;
1126 object->wineD3DStateBlock = wineD3DStateBlock;
1128 *pToken = (DWORD)object;
1129 TRACE("(%p)Returning %p %p\n", This, object, wineD3DStateBlock);
1131 LeaveCriticalSection(&d3d8_cs);
1132 return hr;
1135 static HRESULT WINAPI IDirect3DDevice8Impl_ApplyStateBlock(LPDIRECT3DDEVICE8 iface, DWORD Token) {
1136 IDirect3DStateBlock8Impl *pSB = (IDirect3DStateBlock8Impl*) Token;
1137 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1138 HRESULT hr;
1140 TRACE("(%p) %p Relay\n", This, pSB);
1142 EnterCriticalSection(&d3d8_cs);
1143 hr = IWineD3DStateBlock_Apply(pSB->wineD3DStateBlock);
1144 LeaveCriticalSection(&d3d8_cs);
1145 return hr;
1148 static HRESULT WINAPI IDirect3DDevice8Impl_CaptureStateBlock(LPDIRECT3DDEVICE8 iface, DWORD Token) {
1149 IDirect3DStateBlock8Impl* pSB = (IDirect3DStateBlock8Impl *)Token;
1150 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1151 HRESULT hr;
1153 TRACE("(%p) %p Relay\n", This, pSB);
1155 EnterCriticalSection(&d3d8_cs);
1156 hr = IWineD3DStateBlock_Capture(pSB->wineD3DStateBlock);
1157 LeaveCriticalSection(&d3d8_cs);
1158 return hr;
1161 static HRESULT WINAPI IDirect3DDevice8Impl_DeleteStateBlock(LPDIRECT3DDEVICE8 iface, DWORD Token) {
1162 IDirect3DStateBlock8Impl* pSB = (IDirect3DStateBlock8Impl *)Token;
1163 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1165 TRACE("(%p) Relay\n", This);
1167 EnterCriticalSection(&d3d8_cs);
1168 while(IUnknown_Release((IUnknown *)pSB));
1169 LeaveCriticalSection(&d3d8_cs);
1171 return D3D_OK;
1174 static HRESULT WINAPI IDirect3DDevice8Impl_CreateStateBlock(LPDIRECT3DDEVICE8 iface, D3DSTATEBLOCKTYPE Type, DWORD* pToken) {
1175 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1176 IDirect3DStateBlock8Impl *object;
1177 HRESULT hrc = D3D_OK;
1179 TRACE("(%p) Relay\n", This);
1181 if(Type != D3DSBT_ALL && Type != D3DSBT_PIXELSTATE &&
1182 Type != D3DSBT_VERTEXSTATE ) {
1183 WARN("Unexpected stateblock type, returning D3DERR_INVALIDCALL\n");
1184 return D3DERR_INVALIDCALL;
1187 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DStateBlock8Impl));
1188 if (NULL == object) {
1189 *pToken = 0;
1190 return E_OUTOFMEMORY;
1192 object->lpVtbl = &Direct3DStateBlock8_Vtbl;
1193 object->ref = 1;
1195 EnterCriticalSection(&d3d8_cs);
1196 hrc = IWineD3DDevice_CreateStateBlock(This->WineD3DDevice, (WINED3DSTATEBLOCKTYPE)Type, &object->wineD3DStateBlock, (IUnknown *)object);
1197 LeaveCriticalSection(&d3d8_cs);
1198 if(D3D_OK != hrc){
1199 FIXME("(%p) Call to IWineD3DDevice_CreateStateBlock failed.\n", This);
1200 HeapFree(GetProcessHeap(), 0, object);
1201 *pToken = 0;
1202 } else {
1203 *pToken = (DWORD)object;
1204 TRACE("(%p) returning token (ptr to stateblock) of %p\n", This, object);
1207 return hrc;
1210 static HRESULT WINAPI IDirect3DDevice8Impl_SetClipStatus(LPDIRECT3DDEVICE8 iface, CONST D3DCLIPSTATUS8* pClipStatus) {
1211 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1212 HRESULT hr;
1213 TRACE("(%p) Relay\n" , This);
1214 /* FIXME: Verify that D3DCLIPSTATUS8 ~= WINED3DCLIPSTATUS */
1215 EnterCriticalSection(&d3d8_cs);
1216 hr = IWineD3DDevice_SetClipStatus(This->WineD3DDevice, (const WINED3DCLIPSTATUS *)pClipStatus);
1217 LeaveCriticalSection(&d3d8_cs);
1218 return hr;
1221 static HRESULT WINAPI IDirect3DDevice8Impl_GetClipStatus(LPDIRECT3DDEVICE8 iface, D3DCLIPSTATUS8* pClipStatus) {
1222 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1223 HRESULT hr;
1224 TRACE("(%p) Relay\n" , This);
1226 EnterCriticalSection(&d3d8_cs);
1227 hr = IWineD3DDevice_GetClipStatus(This->WineD3DDevice, (WINED3DCLIPSTATUS *)pClipStatus);
1228 LeaveCriticalSection(&d3d8_cs);
1229 return hr;
1232 static HRESULT WINAPI IDirect3DDevice8Impl_GetTexture(LPDIRECT3DDEVICE8 iface, DWORD Stage,IDirect3DBaseTexture8** ppTexture) {
1233 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1234 IWineD3DBaseTexture *retTexture = NULL;
1235 HRESULT rc = D3D_OK;
1237 TRACE("(%p) Relay\n" , This);
1239 if(ppTexture == NULL){
1240 return D3DERR_INVALIDCALL;
1243 EnterCriticalSection(&d3d8_cs);
1244 rc = IWineD3DDevice_GetTexture(This->WineD3DDevice, Stage, &retTexture);
1245 if (rc == D3D_OK && NULL != retTexture) {
1246 IWineD3DBaseTexture_GetParent(retTexture, (IUnknown **)ppTexture);
1247 IWineD3DBaseTexture_Release(retTexture);
1248 } else {
1249 FIXME("Call to get texture (%d) failed (%p)\n", Stage, retTexture);
1250 *ppTexture = NULL;
1252 LeaveCriticalSection(&d3d8_cs);
1254 return rc;
1257 static HRESULT WINAPI IDirect3DDevice8Impl_SetTexture(LPDIRECT3DDEVICE8 iface, DWORD Stage, IDirect3DBaseTexture8* pTexture) {
1258 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1259 HRESULT hr;
1260 TRACE("(%p) Relay %d %p\n" , This, Stage, pTexture);
1262 EnterCriticalSection(&d3d8_cs);
1263 hr = IWineD3DDevice_SetTexture(This->WineD3DDevice, Stage,
1264 pTexture==NULL ? NULL : ((IDirect3DBaseTexture8Impl *)pTexture)->wineD3DBaseTexture);
1265 LeaveCriticalSection(&d3d8_cs);
1266 return hr;
1269 static HRESULT WINAPI IDirect3DDevice8Impl_GetTextureStageState(LPDIRECT3DDEVICE8 iface, DWORD Stage,D3DTEXTURESTAGESTATETYPE Type,DWORD* pValue) {
1270 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1271 HRESULT hr;
1272 TRACE("(%p) Relay\n" , This);
1274 switch(Type) {
1275 case D3DTSS_ADDRESSU:
1276 Type = WINED3DSAMP_ADDRESSU;
1277 break;
1278 case D3DTSS_ADDRESSV:
1279 Type = WINED3DSAMP_ADDRESSV;
1280 break;
1281 case D3DTSS_ADDRESSW:
1282 Type = WINED3DSAMP_ADDRESSW;
1283 break;
1284 case D3DTSS_BORDERCOLOR:
1285 Type = WINED3DSAMP_BORDERCOLOR;
1286 break;
1287 case D3DTSS_MAGFILTER:
1288 Type = WINED3DSAMP_MAGFILTER;
1289 break;
1290 case D3DTSS_MAXANISOTROPY:
1291 Type = WINED3DSAMP_MAXANISOTROPY;
1292 break;
1293 case D3DTSS_MAXMIPLEVEL:
1294 Type = WINED3DSAMP_MAXMIPLEVEL;
1295 break;
1296 case D3DTSS_MINFILTER:
1297 Type = WINED3DSAMP_MINFILTER;
1298 break;
1299 case D3DTSS_MIPFILTER:
1300 Type = WINED3DSAMP_MIPFILTER;
1301 break;
1302 case D3DTSS_MIPMAPLODBIAS:
1303 Type = WINED3DSAMP_MIPMAPLODBIAS;
1304 break;
1305 default:
1306 EnterCriticalSection(&d3d8_cs);
1307 hr = IWineD3DDevice_GetTextureStageState(This->WineD3DDevice, Stage, Type, pValue);
1308 LeaveCriticalSection(&d3d8_cs);
1309 return hr;
1312 EnterCriticalSection(&d3d8_cs);
1313 hr = IWineD3DDevice_GetSamplerState(This->WineD3DDevice, Stage, Type, pValue);
1314 LeaveCriticalSection(&d3d8_cs);
1315 return hr;
1318 static HRESULT WINAPI IDirect3DDevice8Impl_SetTextureStageState(LPDIRECT3DDEVICE8 iface, DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD Value) {
1319 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1320 HRESULT hr;
1321 TRACE("(%p) Relay\n" , This);
1323 switch(Type) {
1324 case D3DTSS_ADDRESSU:
1325 Type = WINED3DSAMP_ADDRESSU;
1326 break;
1327 case D3DTSS_ADDRESSV:
1328 Type = WINED3DSAMP_ADDRESSV;
1329 break;
1330 case D3DTSS_ADDRESSW:
1331 Type = WINED3DSAMP_ADDRESSW;
1332 break;
1333 case D3DTSS_BORDERCOLOR:
1334 Type = WINED3DSAMP_BORDERCOLOR;
1335 break;
1336 case D3DTSS_MAGFILTER:
1337 Type = WINED3DSAMP_MAGFILTER;
1338 break;
1339 case D3DTSS_MAXANISOTROPY:
1340 Type = WINED3DSAMP_MAXANISOTROPY;
1341 break;
1342 case D3DTSS_MAXMIPLEVEL:
1343 Type = WINED3DSAMP_MAXMIPLEVEL;
1344 break;
1345 case D3DTSS_MINFILTER:
1346 Type = WINED3DSAMP_MINFILTER;
1347 break;
1348 case D3DTSS_MIPFILTER:
1349 Type = WINED3DSAMP_MIPFILTER;
1350 break;
1351 case D3DTSS_MIPMAPLODBIAS:
1352 Type = WINED3DSAMP_MIPMAPLODBIAS;
1353 break;
1354 default:
1355 EnterCriticalSection(&d3d8_cs);
1356 hr = IWineD3DDevice_SetTextureStageState(This->WineD3DDevice, Stage, Type, Value);
1357 LeaveCriticalSection(&d3d8_cs);
1358 return hr;
1361 EnterCriticalSection(&d3d8_cs);
1362 hr = IWineD3DDevice_SetSamplerState(This->WineD3DDevice, Stage, Type, Value);
1363 LeaveCriticalSection(&d3d8_cs);
1364 return hr;
1367 static HRESULT WINAPI IDirect3DDevice8Impl_ValidateDevice(LPDIRECT3DDEVICE8 iface, DWORD* pNumPasses) {
1368 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1369 HRESULT hr;
1370 TRACE("(%p) Relay\n" , This);
1372 EnterCriticalSection(&d3d8_cs);
1373 hr = IWineD3DDevice_ValidateDevice(This->WineD3DDevice, pNumPasses);
1374 LeaveCriticalSection(&d3d8_cs);
1375 return hr;
1378 static HRESULT WINAPI IDirect3DDevice8Impl_GetInfo(LPDIRECT3DDEVICE8 iface, DWORD DevInfoID, void* pDevInfoStruct, DWORD DevInfoStructSize) {
1379 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1380 FIXME("(%p) : stub\n", This);
1381 return D3D_OK;
1384 static HRESULT WINAPI IDirect3DDevice8Impl_SetPaletteEntries(LPDIRECT3DDEVICE8 iface, UINT PaletteNumber, CONST PALETTEENTRY* pEntries) {
1385 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1386 HRESULT hr;
1387 TRACE("(%p) Relay\n" , This);
1389 EnterCriticalSection(&d3d8_cs);
1390 hr = IWineD3DDevice_SetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
1391 LeaveCriticalSection(&d3d8_cs);
1392 return hr;
1395 static HRESULT WINAPI IDirect3DDevice8Impl_GetPaletteEntries(LPDIRECT3DDEVICE8 iface, UINT PaletteNumber, PALETTEENTRY* pEntries) {
1396 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1397 HRESULT hr;
1398 TRACE("(%p) Relay\n" , This);
1400 EnterCriticalSection(&d3d8_cs);
1401 hr = IWineD3DDevice_GetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
1402 LeaveCriticalSection(&d3d8_cs);
1403 return hr;
1406 static HRESULT WINAPI IDirect3DDevice8Impl_SetCurrentTexturePalette(LPDIRECT3DDEVICE8 iface, UINT PaletteNumber) {
1407 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1408 HRESULT hr;
1409 TRACE("(%p) Relay\n" , This);
1411 EnterCriticalSection(&d3d8_cs);
1412 hr = IWineD3DDevice_SetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
1413 LeaveCriticalSection(&d3d8_cs);
1414 return hr;
1417 static HRESULT WINAPI IDirect3DDevice8Impl_GetCurrentTexturePalette(LPDIRECT3DDEVICE8 iface, UINT *PaletteNumber) {
1418 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1419 HRESULT hr;
1420 TRACE("(%p) Relay\n" , This);
1422 EnterCriticalSection(&d3d8_cs);
1423 hr = IWineD3DDevice_GetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
1424 LeaveCriticalSection(&d3d8_cs);
1425 return hr;
1428 static HRESULT WINAPI IDirect3DDevice8Impl_DrawPrimitive(LPDIRECT3DDEVICE8 iface, D3DPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT PrimitiveCount) {
1429 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1430 HRESULT hr;
1431 TRACE("(%p) Relay\n" , This);
1433 EnterCriticalSection(&d3d8_cs);
1434 hr = IWineD3DDevice_DrawPrimitive(This->WineD3DDevice, PrimitiveType, StartVertex, PrimitiveCount);
1435 LeaveCriticalSection(&d3d8_cs);
1436 return hr;
1439 static HRESULT WINAPI IDirect3DDevice8Impl_DrawIndexedPrimitive(LPDIRECT3DDEVICE8 iface, D3DPRIMITIVETYPE PrimitiveType,
1440 UINT MinVertexIndex,UINT NumVertices,UINT startIndex,UINT primCount) {
1441 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1442 HRESULT hr;
1443 TRACE("(%p) Relay\n" , This);
1445 EnterCriticalSection(&d3d8_cs);
1446 hr = IWineD3DDevice_DrawIndexedPrimitive(This->WineD3DDevice, PrimitiveType, MinVertexIndex, NumVertices, startIndex, primCount);
1447 LeaveCriticalSection(&d3d8_cs);
1448 return hr;
1451 static HRESULT WINAPI IDirect3DDevice8Impl_DrawPrimitiveUP(LPDIRECT3DDEVICE8 iface, D3DPRIMITIVETYPE PrimitiveType,UINT PrimitiveCount,CONST void* pVertexStreamZeroData,UINT VertexStreamZeroStride) {
1452 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1453 HRESULT hr;
1454 TRACE("(%p) Relay\n" , This);
1456 EnterCriticalSection(&d3d8_cs);
1457 hr = IWineD3DDevice_DrawPrimitiveUP(This->WineD3DDevice, PrimitiveType, PrimitiveCount, pVertexStreamZeroData, VertexStreamZeroStride);
1458 LeaveCriticalSection(&d3d8_cs);
1459 return hr;
1462 static HRESULT WINAPI IDirect3DDevice8Impl_DrawIndexedPrimitiveUP(LPDIRECT3DDEVICE8 iface, D3DPRIMITIVETYPE PrimitiveType,UINT MinVertexIndex,
1463 UINT NumVertexIndices,UINT PrimitiveCount,CONST void* pIndexData,
1464 D3DFORMAT IndexDataFormat,CONST void* pVertexStreamZeroData,
1465 UINT VertexStreamZeroStride) {
1466 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1467 HRESULT hr;
1468 TRACE("(%p) Relay\n" , This);
1470 EnterCriticalSection(&d3d8_cs);
1471 hr = IWineD3DDevice_DrawIndexedPrimitiveUP(This->WineD3DDevice, PrimitiveType, MinVertexIndex, NumVertexIndices, PrimitiveCount,
1472 pIndexData, IndexDataFormat, pVertexStreamZeroData, VertexStreamZeroStride);
1473 LeaveCriticalSection(&d3d8_cs);
1474 return hr;
1477 static HRESULT WINAPI IDirect3DDevice8Impl_ProcessVertices(LPDIRECT3DDEVICE8 iface, UINT SrcStartIndex,UINT DestIndex,UINT VertexCount,IDirect3DVertexBuffer8* pDestBuffer,DWORD Flags) {
1478 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1479 HRESULT hr;
1480 TRACE("(%p) Relay\n" , This);
1482 EnterCriticalSection(&d3d8_cs);
1483 hr = IWineD3DDevice_ProcessVertices(This->WineD3DDevice,SrcStartIndex, DestIndex, VertexCount, ((IDirect3DVertexBuffer8Impl *)pDestBuffer)->wineD3DVertexBuffer, NULL, Flags);
1484 LeaveCriticalSection(&d3d8_cs);
1485 return hr;
1488 static HRESULT IDirect3DDevice8Impl_CreateVertexDeclaration(IDirect3DDevice8 *iface, CONST DWORD *declaration, IDirect3DVertexDeclaration8 **decl_ptr) {
1489 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1490 IDirect3DVertexDeclaration8Impl *object;
1491 WINED3DVERTEXELEMENT *wined3d_elements;
1492 UINT wined3d_element_count;
1493 HRESULT hr = D3D_OK;
1495 TRACE("(%p) : declaration %p\n", This, declaration);
1497 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1498 if (!object) {
1499 ERR("Memory allocation failed\n");
1500 *decl_ptr = NULL;
1501 return D3DERR_OUTOFVIDEOMEMORY;
1504 object->ref_count = 1;
1505 object->lpVtbl = &Direct3DVertexDeclaration8_Vtbl;
1507 wined3d_element_count = convert_to_wined3d_declaration(declaration, &object->elements_size, &wined3d_elements);
1508 object->elements = HeapAlloc(GetProcessHeap(), 0, object->elements_size);
1509 if (!object->elements) {
1510 ERR("Memory allocation failed\n");
1511 HeapFree(GetProcessHeap(), 0, wined3d_elements);
1512 HeapFree(GetProcessHeap(), 0, object);
1513 *decl_ptr = NULL;
1514 return D3DERR_OUTOFVIDEOMEMORY;
1517 CopyMemory(object->elements, declaration, object->elements_size);
1519 EnterCriticalSection(&d3d8_cs);
1520 hr = IWineD3DDevice_CreateVertexDeclaration(This->WineD3DDevice, &object->wined3d_vertex_declaration,
1521 (IUnknown *)object, wined3d_elements, wined3d_element_count);
1522 LeaveCriticalSection(&d3d8_cs);
1523 HeapFree(GetProcessHeap(), 0, wined3d_elements);
1525 if (FAILED(hr)) {
1526 ERR("(%p) : IWineD3DDevice_CreateVertexDeclaration call failed\n", This);
1527 HeapFree(GetProcessHeap(), 0, object->elements);
1528 HeapFree(GetProcessHeap(), 0, object);
1529 } else {
1530 *decl_ptr = (IDirect3DVertexDeclaration8 *)object;
1531 TRACE("(%p) : Created vertex declaration %p\n", This, object);
1534 return hr;
1537 static HRESULT WINAPI IDirect3DDevice8Impl_CreateVertexShader(LPDIRECT3DDEVICE8 iface, CONST DWORD* pDeclaration, CONST DWORD* pFunction, DWORD* ppShader, DWORD Usage) {
1538 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1539 HRESULT hrc = D3D_OK;
1540 IDirect3DVertexShader8Impl *object;
1541 IWineD3DVertexDeclaration *wined3d_vertex_declaration;
1542 const DWORD *token = pDeclaration;
1543 shader_handle *handle;
1545 /* Test if the vertex declaration is valid */
1546 while (D3DVSD_END() != *token) {
1547 D3DVSD_TOKENTYPE token_type = ((*token & D3DVSD_TOKENTYPEMASK) >> D3DVSD_TOKENTYPESHIFT);
1549 if (token_type == D3DVSD_TOKEN_STREAMDATA && !(token_type & 0x10000000)) {
1550 DWORD type = ((*token & D3DVSD_DATATYPEMASK) >> D3DVSD_DATATYPESHIFT);
1551 DWORD reg = ((*token & D3DVSD_VERTEXREGMASK) >> D3DVSD_VERTEXREGSHIFT);
1553 if(reg == D3DVSDE_NORMAL && type != D3DVSDT_FLOAT3 && !pFunction) {
1554 WARN("Attempt to use a non-FLOAT3 normal with the fixed function function\n");
1555 return D3DERR_INVALIDCALL;
1558 token += parse_token(token);
1561 /* Setup a stub object for now */
1562 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1563 TRACE("(%p) : pFunction(%p), ppShader(%p)\n", This, pFunction, ppShader);
1564 if (NULL == object) {
1565 FIXME("Allocation of memory failed\n");
1566 *ppShader = 0;
1567 return D3DERR_OUTOFVIDEOMEMORY;
1570 object->ref = 1;
1571 object->lpVtbl = &Direct3DVertexShader8_Vtbl;
1573 EnterCriticalSection(&d3d8_cs);
1574 hrc = IDirect3DDevice8Impl_CreateVertexDeclaration(iface, pDeclaration, &object->vertex_declaration);
1575 if (FAILED(hrc)) {
1576 ERR("(%p) : IDirect3DDeviceImpl_CreateVertexDeclaration call failed\n", This);
1577 LeaveCriticalSection(&d3d8_cs);
1578 HeapFree(GetProcessHeap(), 0, object);
1579 *ppShader = 0;
1580 return D3DERR_INVALIDCALL;
1583 handle = alloc_shader_handle(This);
1584 if (!handle)
1586 ERR("Failed to allocate shader handle\n");
1587 LeaveCriticalSection(&d3d8_cs);
1588 IDirect3DVertexDeclaration8_Release(object->vertex_declaration);
1589 HeapFree(GetProcessHeap(), 0, object);
1590 *ppShader = 0;
1591 return E_OUTOFMEMORY;
1593 else
1595 DWORD shader_handle = (handle - This->shader_handles) + VS_HIGHESTFIXEDFXF + 1;
1596 *handle = object;
1597 *ppShader = ((IDirect3DVertexDeclaration8Impl *)object->vertex_declaration)->shader_handle = shader_handle;
1600 wined3d_vertex_declaration = ((IDirect3DVertexDeclaration8Impl *)object->vertex_declaration)->wined3d_vertex_declaration;
1602 if (pFunction)
1604 /* Usage is missing ... Use SetRenderState to set the sw vp render state in SetVertexShader */
1605 hrc = IWineD3DDevice_CreateVertexShader(This->WineD3DDevice, wined3d_vertex_declaration,
1606 pFunction, &object->wineD3DVertexShader, (IUnknown *)object);
1608 if (FAILED(hrc))
1610 /* free up object */
1611 FIXME("Call to IWineD3DDevice_CreateVertexShader failed\n");
1612 free_shader_handle(This, handle);
1613 IDirect3DVertexDeclaration8_Release(object->vertex_declaration);
1614 HeapFree(GetProcessHeap(), 0, object);
1615 *ppShader = 0;
1617 else
1619 load_local_constants(pDeclaration, object->wineD3DVertexShader);
1620 TRACE("(%p) : returning %p (handle %#x)\n", This, object, *ppShader);
1624 LeaveCriticalSection(&d3d8_cs);
1626 return hrc;
1629 static IDirect3DVertexDeclaration8Impl *IDirect3DDevice8Impl_FindDecl(IDirect3DDevice8Impl *This, DWORD fvf)
1631 IDirect3DVertexDeclaration8Impl *d3d8_declaration;
1632 HRESULT hr;
1633 int p, low, high; /* deliberately signed */
1634 struct FvfToDecl *convertedDecls = This->decls;
1636 TRACE("Searching for declaration for fvf %08x... ", fvf);
1638 low = 0;
1639 high = This->numConvertedDecls - 1;
1640 while(low <= high) {
1641 p = (low + high) >> 1;
1642 TRACE("%d ", p);
1643 if(convertedDecls[p].fvf == fvf) {
1644 TRACE("found %p\n", convertedDecls[p].decl);
1645 return (IDirect3DVertexDeclaration8Impl *)convertedDecls[p].decl;
1646 } else if(convertedDecls[p].fvf < fvf) {
1647 low = p + 1;
1648 } else {
1649 high = p - 1;
1652 TRACE("not found. Creating and inserting at position %d.\n", low);
1654 d3d8_declaration = HeapAlloc(GetProcessHeap(), 0, sizeof(*d3d8_declaration));
1655 if (!d3d8_declaration)
1657 ERR("Memory allocation failed.\n");
1658 return NULL;
1661 d3d8_declaration->ref_count = 1;
1662 d3d8_declaration->lpVtbl = &Direct3DVertexDeclaration8_Vtbl;
1663 d3d8_declaration->elements = NULL;
1664 d3d8_declaration->elements_size = 0;
1665 d3d8_declaration->shader_handle = fvf;
1667 hr = IWineD3DDevice_CreateVertexDeclarationFromFVF(This->WineD3DDevice,
1668 &d3d8_declaration->wined3d_vertex_declaration, (IUnknown *)d3d8_declaration, fvf);
1669 if (FAILED(hr))
1671 ERR("Failed to create wined3d vertex declaration.\n");
1672 HeapFree(GetProcessHeap(), 0, d3d8_declaration);
1673 return NULL;
1676 if(This->declArraySize == This->numConvertedDecls) {
1677 int grow = This->declArraySize / 2;
1678 convertedDecls = HeapReAlloc(GetProcessHeap(), 0, convertedDecls,
1679 sizeof(convertedDecls[0]) * (This->numConvertedDecls + grow));
1680 if(!convertedDecls) {
1681 /* This will destroy it */
1682 IDirect3DVertexDeclaration8_Release((IDirect3DVertexDeclaration8 *)d3d8_declaration);
1683 return NULL;
1685 This->decls = convertedDecls;
1686 This->declArraySize += grow;
1689 memmove(convertedDecls + low + 1, convertedDecls + low, sizeof(convertedDecls[0]) * (This->numConvertedDecls - low));
1690 convertedDecls[low].decl = (IDirect3DVertexDeclaration8 *)d3d8_declaration;
1691 convertedDecls[low].fvf = fvf;
1692 This->numConvertedDecls++;
1694 TRACE("Returning %p. %u decls in array\n", d3d8_declaration, This->numConvertedDecls);
1695 return d3d8_declaration;
1698 static HRESULT WINAPI IDirect3DDevice8Impl_SetVertexShader(LPDIRECT3DDEVICE8 iface, DWORD pShader) {
1699 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1700 HRESULT hrc = D3D_OK;
1702 TRACE("(%p) : Relay\n", This);
1703 EnterCriticalSection(&d3d8_cs);
1704 if (VS_HIGHESTFIXEDFXF >= pShader) {
1705 TRACE("Setting FVF, %#x\n", pShader);
1706 IWineD3DDevice_SetVertexDeclaration(This->WineD3DDevice,
1707 IDirect3DDevice8Impl_FindDecl(This, pShader)->wined3d_vertex_declaration);
1708 IWineD3DDevice_SetVertexShader(This->WineD3DDevice, NULL);
1709 } else {
1710 TRACE("Setting shader\n");
1711 if (This->allocated_shader_handles <= pShader - (VS_HIGHESTFIXEDFXF + 1)) {
1712 FIXME("(%p) : Number of shaders exceeds the maximum number of possible shaders\n", This);
1713 hrc = D3DERR_INVALIDCALL;
1714 } else {
1715 IDirect3DVertexShader8Impl *shader = This->shader_handles[pShader - (VS_HIGHESTFIXEDFXF + 1)];
1717 if (shader)
1719 hrc = IWineD3DDevice_SetVertexDeclaration(This->WineD3DDevice,
1720 ((IDirect3DVertexDeclaration8Impl *)shader->vertex_declaration)->wined3d_vertex_declaration);
1721 if (SUCCEEDED(hrc))
1722 hrc = IWineD3DDevice_SetVertexShader(This->WineD3DDevice, shader->wineD3DVertexShader);
1724 else
1726 hrc = IWineD3DDevice_SetVertexDeclaration(This->WineD3DDevice, NULL);
1727 if (SUCCEEDED(hrc)) hrc = IWineD3DDevice_SetVertexShader(This->WineD3DDevice, NULL);
1731 TRACE("(%p) : returning hr(%u)\n", This, hrc);
1732 LeaveCriticalSection(&d3d8_cs);
1734 return hrc;
1737 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShader(LPDIRECT3DDEVICE8 iface, DWORD* ppShader) {
1738 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1739 IWineD3DVertexDeclaration *wined3d_declaration;
1740 HRESULT hrc;
1742 TRACE("(%p) : Relay device@%p\n", This, This->WineD3DDevice);
1743 EnterCriticalSection(&d3d8_cs);
1745 hrc = IWineD3DDevice_GetVertexDeclaration(This->WineD3DDevice, &wined3d_declaration);
1746 if (SUCCEEDED(hrc))
1748 if (wined3d_declaration)
1750 IDirect3DVertexDeclaration8 *d3d8_declaration;
1751 hrc = IWineD3DVertexDeclaration_GetParent(wined3d_declaration, (IUnknown **)&d3d8_declaration);
1752 IWineD3DVertexDeclaration_Release(wined3d_declaration);
1753 if (SUCCEEDED(hrc))
1755 *ppShader = ((IDirect3DVertexDeclaration8Impl *)d3d8_declaration)->shader_handle;
1756 IDirect3DVertexDeclaration8_Release(d3d8_declaration);
1759 else
1761 *ppShader = 0;
1762 hrc = D3D_OK;
1765 else
1767 WARN("(%p) : Call to IWineD3DDevice_GetVertexDeclaration failed %#x (device %p)\n",
1768 This, hrc, This->WineD3DDevice);
1770 TRACE("(%p) : returning %#x\n", This, *ppShader);
1771 LeaveCriticalSection(&d3d8_cs);
1773 return hrc;
1776 static HRESULT WINAPI IDirect3DDevice8Impl_DeleteVertexShader(LPDIRECT3DDEVICE8 iface, DWORD pShader) {
1777 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1779 TRACE("(%p) : pShader %#x\n", This, pShader);
1781 EnterCriticalSection(&d3d8_cs);
1782 if (pShader <= VS_HIGHESTFIXEDFXF || This->allocated_shader_handles <= pShader - (VS_HIGHESTFIXEDFXF + 1)) {
1783 ERR("(%p) : Trying to delete an invalid handle\n", This);
1784 LeaveCriticalSection(&d3d8_cs);
1785 return D3DERR_INVALIDCALL;
1786 } else {
1787 IWineD3DVertexShader *cur = NULL;
1788 shader_handle *handle = &This->shader_handles[pShader - (VS_HIGHESTFIXEDFXF + 1)];
1789 IDirect3DVertexShader8Impl *shader = *handle;
1791 IWineD3DDevice_GetVertexShader(This->WineD3DDevice, &cur);
1792 if(cur) {
1793 if(cur == shader->wineD3DVertexShader) IDirect3DDevice8_SetVertexShader(iface, 0);
1794 IWineD3DVertexShader_Release(cur);
1797 while(IUnknown_Release((IUnknown *)shader));
1798 free_shader_handle(This, handle);
1800 LeaveCriticalSection(&d3d8_cs);
1802 return D3D_OK;
1805 static HRESULT WINAPI IDirect3DDevice8Impl_SetVertexShaderConstant(LPDIRECT3DDEVICE8 iface, DWORD Register, CONST void* pConstantData, DWORD ConstantCount) {
1806 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1807 HRESULT hr;
1808 TRACE("(%p) : Relay\n", This);
1810 EnterCriticalSection(&d3d8_cs);
1811 hr = IWineD3DDevice_SetVertexShaderConstantF(This->WineD3DDevice, Register, (CONST float *)pConstantData, ConstantCount);
1812 LeaveCriticalSection(&d3d8_cs);
1813 return hr;
1816 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShaderConstant(LPDIRECT3DDEVICE8 iface, DWORD Register, void* pConstantData, DWORD ConstantCount) {
1817 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1818 HRESULT hr;
1819 TRACE("(%p) : Relay\n", This);
1821 EnterCriticalSection(&d3d8_cs);
1822 hr = IWineD3DDevice_GetVertexShaderConstantF(This->WineD3DDevice, Register, (float *)pConstantData, ConstantCount);
1823 LeaveCriticalSection(&d3d8_cs);
1824 return hr;
1827 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShaderDeclaration(LPDIRECT3DDEVICE8 iface, DWORD pVertexShader, void* pData, DWORD* pSizeOfData) {
1828 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1829 IDirect3DVertexDeclaration8Impl *declaration;
1830 IDirect3DVertexShader8Impl *shader = NULL;
1832 TRACE("(%p) : pVertexShader 0x%08x, pData %p, *pSizeOfData %u\n", This, pVertexShader, pData, *pSizeOfData);
1834 EnterCriticalSection(&d3d8_cs);
1835 if (pVertexShader <= VS_HIGHESTFIXEDFXF || This->allocated_shader_handles <= pVertexShader - (VS_HIGHESTFIXEDFXF + 1)) {
1836 ERR("Passed an invalid shader handle.\n");
1837 LeaveCriticalSection(&d3d8_cs);
1838 return D3DERR_INVALIDCALL;
1841 shader = This->shader_handles[pVertexShader - (VS_HIGHESTFIXEDFXF + 1)];
1842 declaration = (IDirect3DVertexDeclaration8Impl *)shader->vertex_declaration;
1844 /* If pData is NULL, we just return the required size of the buffer. */
1845 if (!pData) {
1846 *pSizeOfData = declaration->elements_size;
1847 LeaveCriticalSection(&d3d8_cs);
1848 return D3D_OK;
1851 /* MSDN claims that if *pSizeOfData is smaller than the required size
1852 * we should write the required size and return D3DERR_MOREDATA.
1853 * That's not actually true. */
1854 if (*pSizeOfData < declaration->elements_size) {
1855 LeaveCriticalSection(&d3d8_cs);
1856 return D3DERR_INVALIDCALL;
1859 CopyMemory(pData, declaration->elements, declaration->elements_size);
1860 LeaveCriticalSection(&d3d8_cs);
1862 return D3D_OK;
1865 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShaderFunction(LPDIRECT3DDEVICE8 iface, DWORD pVertexShader, void* pData, DWORD* pSizeOfData) {
1866 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1867 IDirect3DVertexShader8Impl *shader = NULL;
1868 HRESULT hr;
1870 TRACE("(%p) : pVertexShader %#x, pData %p, pSizeOfData %p\n", This, pVertexShader, pData, pSizeOfData);
1872 EnterCriticalSection(&d3d8_cs);
1873 if (pVertexShader <= VS_HIGHESTFIXEDFXF || This->allocated_shader_handles <= pVertexShader - (VS_HIGHESTFIXEDFXF + 1)) {
1874 ERR("Passed an invalid shader handle.\n");
1875 LeaveCriticalSection(&d3d8_cs);
1876 return D3DERR_INVALIDCALL;
1879 shader = This->shader_handles[pVertexShader - (VS_HIGHESTFIXEDFXF + 1)];
1880 if (shader->wineD3DVertexShader)
1882 hr = IWineD3DVertexShader_GetFunction(shader->wineD3DVertexShader, pData, pSizeOfData);
1884 else
1886 *pSizeOfData = 0;
1887 hr = D3D_OK;
1890 LeaveCriticalSection(&d3d8_cs);
1891 return hr;
1894 static HRESULT WINAPI IDirect3DDevice8Impl_SetIndices(LPDIRECT3DDEVICE8 iface, IDirect3DIndexBuffer8* pIndexData, UINT baseVertexIndex) {
1895 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1896 HRESULT hr;
1897 TRACE("(%p) Relay\n", This);
1899 EnterCriticalSection(&d3d8_cs);
1900 /* WineD3D takes an INT(due to d3d9), but d3d8 uses UINTs. Do I have to add a check here that
1901 * the UINT doesn't cause an overflow in the INT? It seems rather unlikely because such large
1902 * vertex buffers can't be created to address them with an index that requires the 32nd bit
1903 * (4 Byte minimum vertex size * 2^31-1 -> 8 gb buffer. The index sign would be the least
1904 * problem)
1906 IWineD3DDevice_SetBaseVertexIndex(This->WineD3DDevice, baseVertexIndex);
1907 hr = IWineD3DDevice_SetIndices(This->WineD3DDevice,
1908 pIndexData ? ((IDirect3DIndexBuffer8Impl *)pIndexData)->wineD3DIndexBuffer : NULL);
1909 LeaveCriticalSection(&d3d8_cs);
1910 return hr;
1913 static HRESULT WINAPI IDirect3DDevice8Impl_GetIndices(LPDIRECT3DDEVICE8 iface, IDirect3DIndexBuffer8** ppIndexData,UINT* pBaseVertexIndex) {
1914 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1915 IWineD3DIndexBuffer *retIndexData = NULL;
1916 HRESULT rc = D3D_OK;
1918 TRACE("(%p) Relay\n", This);
1920 if(ppIndexData == NULL){
1921 return D3DERR_INVALIDCALL;
1924 EnterCriticalSection(&d3d8_cs);
1925 /* The case from UINT to INT is safe because d3d8 will never set negative values */
1926 IWineD3DDevice_GetBaseVertexIndex(This->WineD3DDevice, (INT *) pBaseVertexIndex);
1927 rc = IWineD3DDevice_GetIndices(This->WineD3DDevice, &retIndexData);
1928 if (SUCCEEDED(rc) && retIndexData) {
1929 IWineD3DIndexBuffer_GetParent(retIndexData, (IUnknown **)ppIndexData);
1930 IWineD3DIndexBuffer_Release(retIndexData);
1931 } else {
1932 if (FAILED(rc)) FIXME("Call to GetIndices failed\n");
1933 *ppIndexData = NULL;
1935 LeaveCriticalSection(&d3d8_cs);
1937 return rc;
1939 static HRESULT WINAPI IDirect3DDevice8Impl_CreatePixelShader(LPDIRECT3DDEVICE8 iface, CONST DWORD* pFunction, DWORD* ppShader) {
1940 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1941 IDirect3DPixelShader8Impl *object;
1942 HRESULT hrc = D3D_OK;
1944 TRACE("(%p) : pFunction(%p), ppShader(%p)\n", This, pFunction, ppShader);
1946 if (NULL == ppShader) {
1947 TRACE("(%p) Invalid call\n", This);
1948 return D3DERR_INVALIDCALL;
1950 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1952 if (NULL == object) {
1953 return E_OUTOFMEMORY;
1954 } else {
1955 EnterCriticalSection(&d3d8_cs);
1957 object->ref = 1;
1958 object->lpVtbl = &Direct3DPixelShader8_Vtbl;
1959 hrc = IWineD3DDevice_CreatePixelShader(This->WineD3DDevice, pFunction, &object->wineD3DPixelShader , (IUnknown *)object);
1960 if (D3D_OK != hrc) {
1961 FIXME("(%p) call to IWineD3DDevice_CreatePixelShader failed\n", This);
1962 HeapFree(GetProcessHeap(), 0 , object);
1963 *ppShader = 0;
1964 } else {
1965 shader_handle *handle = alloc_shader_handle(This);
1966 if (!handle) {
1967 ERR("Failed to allocate shader handle\n");
1968 IDirect3DVertexShader8_Release((IUnknown *)object);
1969 hrc = E_OUTOFMEMORY;
1970 } else {
1971 *handle = object;
1972 object->handle = (handle - This->shader_handles) + VS_HIGHESTFIXEDFXF + 1;
1973 *ppShader = object->handle;
1974 TRACE("(%p) : returning %p (handle %#x)\n", This, object, *ppShader);
1977 LeaveCriticalSection(&d3d8_cs);
1980 return hrc;
1983 static HRESULT WINAPI IDirect3DDevice8Impl_SetPixelShader(LPDIRECT3DDEVICE8 iface, DWORD pShader) {
1984 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1985 IDirect3DPixelShader8Impl *shader = NULL;
1986 HRESULT hr;
1988 TRACE("(%p) : pShader %#x\n", This, pShader);
1990 EnterCriticalSection(&d3d8_cs);
1991 if (pShader > VS_HIGHESTFIXEDFXF && This->allocated_shader_handles > pShader - (VS_HIGHESTFIXEDFXF + 1)) {
1992 shader = This->shader_handles[pShader - (VS_HIGHESTFIXEDFXF + 1)];
1993 } else if (pShader) {
1994 ERR("Trying to set an invalid handle.\n");
1997 TRACE("(%p) : Setting shader %p\n", This, shader);
1998 hr = IWineD3DDevice_SetPixelShader(This->WineD3DDevice, shader == NULL ? NULL :shader->wineD3DPixelShader);
1999 LeaveCriticalSection(&d3d8_cs);
2000 return hr;
2003 static HRESULT WINAPI IDirect3DDevice8Impl_GetPixelShader(LPDIRECT3DDEVICE8 iface, DWORD* ppShader) {
2004 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2005 IWineD3DPixelShader *object;
2007 HRESULT hrc = D3D_OK;
2008 TRACE("(%p) Relay\n", This);
2009 if (NULL == ppShader) {
2010 TRACE("(%p) Invalid call\n", This);
2011 return D3DERR_INVALIDCALL;
2014 EnterCriticalSection(&d3d8_cs);
2015 hrc = IWineD3DDevice_GetPixelShader(This->WineD3DDevice, &object);
2016 if (D3D_OK == hrc && NULL != object) {
2017 IDirect3DPixelShader8Impl *d3d8_shader;
2018 hrc = IWineD3DPixelShader_GetParent(object, (IUnknown **)&d3d8_shader);
2019 IWineD3DPixelShader_Release(object);
2020 *ppShader = d3d8_shader->handle;
2021 } else {
2022 *ppShader = 0;
2025 TRACE("(%p) : returning %#x\n", This, *ppShader);
2026 LeaveCriticalSection(&d3d8_cs);
2027 return hrc;
2030 static HRESULT WINAPI IDirect3DDevice8Impl_DeletePixelShader(LPDIRECT3DDEVICE8 iface, DWORD pShader) {
2031 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2033 TRACE("(%p) : pShader %#x\n", This, pShader);
2035 EnterCriticalSection(&d3d8_cs);
2036 if (pShader <= VS_HIGHESTFIXEDFXF || This->allocated_shader_handles <= pShader - (VS_HIGHESTFIXEDFXF + 1)) {
2037 ERR("(%p) : Trying to delete an invalid handle\n", This);
2038 LeaveCriticalSection(&d3d8_cs);
2039 return D3DERR_INVALIDCALL;
2040 } else {
2041 IWineD3DPixelShader *cur = NULL;
2042 shader_handle *handle = &This->shader_handles[pShader - (VS_HIGHESTFIXEDFXF + 1)];
2043 IDirect3DPixelShader8Impl *shader = *handle;
2045 IWineD3DDevice_GetPixelShader(This->WineD3DDevice, &cur);
2046 if(cur) {
2047 if(cur == shader->wineD3DPixelShader) IDirect3DDevice8_SetPixelShader(iface, 0);
2048 IWineD3DPixelShader_Release(cur);
2051 while(IUnknown_Release((IUnknown *)shader));
2052 free_shader_handle(This, handle);
2054 LeaveCriticalSection(&d3d8_cs);
2056 return D3D_OK;
2059 static HRESULT WINAPI IDirect3DDevice8Impl_SetPixelShaderConstant(LPDIRECT3DDEVICE8 iface, DWORD Register, CONST void* pConstantData, DWORD ConstantCount) {
2060 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2061 HRESULT hr;
2062 TRACE("(%p) Relay\n", This);
2064 EnterCriticalSection(&d3d8_cs);
2065 hr = IWineD3DDevice_SetPixelShaderConstantF(This->WineD3DDevice, Register, (CONST float *)pConstantData, ConstantCount);
2066 LeaveCriticalSection(&d3d8_cs);
2067 return hr;
2070 static HRESULT WINAPI IDirect3DDevice8Impl_GetPixelShaderConstant(LPDIRECT3DDEVICE8 iface, DWORD Register, void* pConstantData, DWORD ConstantCount) {
2071 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2072 HRESULT hr;
2073 TRACE("(%p) Relay\n", This);
2075 EnterCriticalSection(&d3d8_cs);
2076 hr = IWineD3DDevice_GetPixelShaderConstantF(This->WineD3DDevice, Register, (float *)pConstantData, ConstantCount);
2077 LeaveCriticalSection(&d3d8_cs);
2078 return hr;
2081 static HRESULT WINAPI IDirect3DDevice8Impl_GetPixelShaderFunction(LPDIRECT3DDEVICE8 iface, DWORD pPixelShader, void* pData, DWORD* pSizeOfData) {
2082 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2083 IDirect3DPixelShader8Impl *shader = NULL;
2084 HRESULT hr;
2086 TRACE("(%p) : pPixelShader %#x, pData %p, pSizeOfData %p\n", This, pPixelShader, pData, pSizeOfData);
2088 EnterCriticalSection(&d3d8_cs);
2089 if (pPixelShader <= VS_HIGHESTFIXEDFXF || This->allocated_shader_handles <= pPixelShader - (VS_HIGHESTFIXEDFXF + 1)) {
2090 ERR("Passed an invalid shader handle.\n");
2091 LeaveCriticalSection(&d3d8_cs);
2092 return D3DERR_INVALIDCALL;
2095 shader = This->shader_handles[pPixelShader - (VS_HIGHESTFIXEDFXF + 1)];
2096 hr = IWineD3DPixelShader_GetFunction(shader->wineD3DPixelShader, pData, pSizeOfData);
2097 LeaveCriticalSection(&d3d8_cs);
2098 return hr;
2101 static HRESULT WINAPI IDirect3DDevice8Impl_DrawRectPatch(LPDIRECT3DDEVICE8 iface, UINT Handle,CONST float* pNumSegs,CONST D3DRECTPATCH_INFO* pRectPatchInfo) {
2102 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2103 HRESULT hr;
2104 TRACE("(%p) Relay\n", This);
2106 EnterCriticalSection(&d3d8_cs);
2107 hr = IWineD3DDevice_DrawRectPatch(This->WineD3DDevice, Handle, pNumSegs, (CONST WINED3DRECTPATCH_INFO *)pRectPatchInfo);
2108 LeaveCriticalSection(&d3d8_cs);
2109 return hr;
2112 static HRESULT WINAPI IDirect3DDevice8Impl_DrawTriPatch(LPDIRECT3DDEVICE8 iface, UINT Handle,CONST float* pNumSegs,CONST D3DTRIPATCH_INFO* pTriPatchInfo) {
2113 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2114 HRESULT hr;
2115 TRACE("(%p) Relay\n", This);
2117 EnterCriticalSection(&d3d8_cs);
2118 hr = IWineD3DDevice_DrawTriPatch(This->WineD3DDevice, Handle, pNumSegs, (CONST WINED3DTRIPATCH_INFO *)pTriPatchInfo);
2119 LeaveCriticalSection(&d3d8_cs);
2120 return hr;
2123 static HRESULT WINAPI IDirect3DDevice8Impl_DeletePatch(LPDIRECT3DDEVICE8 iface, UINT Handle) {
2124 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2125 HRESULT hr;
2126 TRACE("(%p) Relay\n", This);
2128 EnterCriticalSection(&d3d8_cs);
2129 hr = IWineD3DDevice_DeletePatch(This->WineD3DDevice, Handle);
2130 LeaveCriticalSection(&d3d8_cs);
2131 return hr;
2134 static HRESULT WINAPI IDirect3DDevice8Impl_SetStreamSource(LPDIRECT3DDEVICE8 iface, UINT StreamNumber,IDirect3DVertexBuffer8* pStreamData,UINT Stride) {
2135 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2136 HRESULT hr;
2137 TRACE("(%p) Relay\n" , This);
2139 EnterCriticalSection(&d3d8_cs);
2140 hr = IWineD3DDevice_SetStreamSource(This->WineD3DDevice, StreamNumber,
2141 NULL == pStreamData ? NULL : ((IDirect3DVertexBuffer8Impl *)pStreamData)->wineD3DVertexBuffer,
2142 0/* Offset in bytes */, Stride);
2143 LeaveCriticalSection(&d3d8_cs);
2144 return hr;
2147 static HRESULT WINAPI IDirect3DDevice8Impl_GetStreamSource(LPDIRECT3DDEVICE8 iface, UINT StreamNumber,IDirect3DVertexBuffer8** pStream,UINT* pStride) {
2148 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2149 IWineD3DVertexBuffer *retStream = NULL;
2150 HRESULT rc = D3D_OK;
2152 TRACE("(%p) Relay\n" , This);
2154 if(pStream == NULL){
2155 return D3DERR_INVALIDCALL;
2158 EnterCriticalSection(&d3d8_cs);
2159 rc = IWineD3DDevice_GetStreamSource(This->WineD3DDevice, StreamNumber, &retStream, 0 /* Offset in bytes */, pStride);
2160 if (rc == D3D_OK && NULL != retStream) {
2161 IWineD3DVertexBuffer_GetParent(retStream, (IUnknown **)pStream);
2162 IWineD3DVertexBuffer_Release(retStream);
2163 }else{
2164 if (rc != D3D_OK){
2165 FIXME("Call to GetStreamSource failed %p\n", pStride);
2167 *pStream = NULL;
2169 LeaveCriticalSection(&d3d8_cs);
2171 return rc;
2175 const IDirect3DDevice8Vtbl Direct3DDevice8_Vtbl =
2177 IDirect3DDevice8Impl_QueryInterface,
2178 IDirect3DDevice8Impl_AddRef,
2179 IDirect3DDevice8Impl_Release,
2180 IDirect3DDevice8Impl_TestCooperativeLevel,
2181 IDirect3DDevice8Impl_GetAvailableTextureMem,
2182 IDirect3DDevice8Impl_ResourceManagerDiscardBytes,
2183 IDirect3DDevice8Impl_GetDirect3D,
2184 IDirect3DDevice8Impl_GetDeviceCaps,
2185 IDirect3DDevice8Impl_GetDisplayMode,
2186 IDirect3DDevice8Impl_GetCreationParameters,
2187 IDirect3DDevice8Impl_SetCursorProperties,
2188 IDirect3DDevice8Impl_SetCursorPosition,
2189 IDirect3DDevice8Impl_ShowCursor,
2190 IDirect3DDevice8Impl_CreateAdditionalSwapChain,
2191 IDirect3DDevice8Impl_Reset,
2192 IDirect3DDevice8Impl_Present,
2193 IDirect3DDevice8Impl_GetBackBuffer,
2194 IDirect3DDevice8Impl_GetRasterStatus,
2195 IDirect3DDevice8Impl_SetGammaRamp,
2196 IDirect3DDevice8Impl_GetGammaRamp,
2197 IDirect3DDevice8Impl_CreateTexture,
2198 IDirect3DDevice8Impl_CreateVolumeTexture,
2199 IDirect3DDevice8Impl_CreateCubeTexture,
2200 IDirect3DDevice8Impl_CreateVertexBuffer,
2201 IDirect3DDevice8Impl_CreateIndexBuffer,
2202 IDirect3DDevice8Impl_CreateRenderTarget,
2203 IDirect3DDevice8Impl_CreateDepthStencilSurface,
2204 IDirect3DDevice8Impl_CreateImageSurface,
2205 IDirect3DDevice8Impl_CopyRects,
2206 IDirect3DDevice8Impl_UpdateTexture,
2207 IDirect3DDevice8Impl_GetFrontBuffer,
2208 IDirect3DDevice8Impl_SetRenderTarget,
2209 IDirect3DDevice8Impl_GetRenderTarget,
2210 IDirect3DDevice8Impl_GetDepthStencilSurface,
2211 IDirect3DDevice8Impl_BeginScene,
2212 IDirect3DDevice8Impl_EndScene,
2213 IDirect3DDevice8Impl_Clear,
2214 IDirect3DDevice8Impl_SetTransform,
2215 IDirect3DDevice8Impl_GetTransform,
2216 IDirect3DDevice8Impl_MultiplyTransform,
2217 IDirect3DDevice8Impl_SetViewport,
2218 IDirect3DDevice8Impl_GetViewport,
2219 IDirect3DDevice8Impl_SetMaterial,
2220 IDirect3DDevice8Impl_GetMaterial,
2221 IDirect3DDevice8Impl_SetLight,
2222 IDirect3DDevice8Impl_GetLight,
2223 IDirect3DDevice8Impl_LightEnable,
2224 IDirect3DDevice8Impl_GetLightEnable,
2225 IDirect3DDevice8Impl_SetClipPlane,
2226 IDirect3DDevice8Impl_GetClipPlane,
2227 IDirect3DDevice8Impl_SetRenderState,
2228 IDirect3DDevice8Impl_GetRenderState,
2229 IDirect3DDevice8Impl_BeginStateBlock,
2230 IDirect3DDevice8Impl_EndStateBlock,
2231 IDirect3DDevice8Impl_ApplyStateBlock,
2232 IDirect3DDevice8Impl_CaptureStateBlock,
2233 IDirect3DDevice8Impl_DeleteStateBlock,
2234 IDirect3DDevice8Impl_CreateStateBlock,
2235 IDirect3DDevice8Impl_SetClipStatus,
2236 IDirect3DDevice8Impl_GetClipStatus,
2237 IDirect3DDevice8Impl_GetTexture,
2238 IDirect3DDevice8Impl_SetTexture,
2239 IDirect3DDevice8Impl_GetTextureStageState,
2240 IDirect3DDevice8Impl_SetTextureStageState,
2241 IDirect3DDevice8Impl_ValidateDevice,
2242 IDirect3DDevice8Impl_GetInfo,
2243 IDirect3DDevice8Impl_SetPaletteEntries,
2244 IDirect3DDevice8Impl_GetPaletteEntries,
2245 IDirect3DDevice8Impl_SetCurrentTexturePalette,
2246 IDirect3DDevice8Impl_GetCurrentTexturePalette,
2247 IDirect3DDevice8Impl_DrawPrimitive,
2248 IDirect3DDevice8Impl_DrawIndexedPrimitive,
2249 IDirect3DDevice8Impl_DrawPrimitiveUP,
2250 IDirect3DDevice8Impl_DrawIndexedPrimitiveUP,
2251 IDirect3DDevice8Impl_ProcessVertices,
2252 IDirect3DDevice8Impl_CreateVertexShader,
2253 IDirect3DDevice8Impl_SetVertexShader,
2254 IDirect3DDevice8Impl_GetVertexShader,
2255 IDirect3DDevice8Impl_DeleteVertexShader,
2256 IDirect3DDevice8Impl_SetVertexShaderConstant,
2257 IDirect3DDevice8Impl_GetVertexShaderConstant,
2258 IDirect3DDevice8Impl_GetVertexShaderDeclaration,
2259 IDirect3DDevice8Impl_GetVertexShaderFunction,
2260 IDirect3DDevice8Impl_SetStreamSource,
2261 IDirect3DDevice8Impl_GetStreamSource,
2262 IDirect3DDevice8Impl_SetIndices,
2263 IDirect3DDevice8Impl_GetIndices,
2264 IDirect3DDevice8Impl_CreatePixelShader,
2265 IDirect3DDevice8Impl_SetPixelShader,
2266 IDirect3DDevice8Impl_GetPixelShader,
2267 IDirect3DDevice8Impl_DeletePixelShader,
2268 IDirect3DDevice8Impl_SetPixelShaderConstant,
2269 IDirect3DDevice8Impl_GetPixelShaderConstant,
2270 IDirect3DDevice8Impl_GetPixelShaderFunction,
2271 IDirect3DDevice8Impl_DrawRectPatch,
2272 IDirect3DDevice8Impl_DrawTriPatch,
2273 IDirect3DDevice8Impl_DeletePatch
2276 /* Internal function called back during the CreateDevice to create a render target */
2277 static HRESULT WINAPI D3D8CB_CreateSurface(IUnknown *device, IUnknown *pSuperior, UINT Width, UINT Height,
2278 WINED3DFORMAT Format, DWORD Usage, WINED3DPOOL Pool, UINT Level,
2279 WINED3DCUBEMAP_FACES Face, IWineD3DSurface **ppSurface,
2280 HANDLE *pSharedHandle) {
2282 HRESULT res = D3D_OK;
2283 IDirect3DSurface8Impl *d3dSurface = NULL;
2284 BOOL Lockable = TRUE;
2286 if((WINED3DPOOL_DEFAULT == Pool && WINED3DUSAGE_DYNAMIC != Usage))
2287 Lockable = FALSE;
2289 TRACE("relay\n");
2290 res = IDirect3DDevice8Impl_CreateSurface((IDirect3DDevice8 *)device, Width, Height, (D3DFORMAT)Format, Lockable, FALSE/*Discard*/, Level, (IDirect3DSurface8 **)&d3dSurface, D3DRTYPE_SURFACE, Usage, Pool, D3DMULTISAMPLE_NONE, 0 /* MultisampleQuality */);
2292 if (SUCCEEDED(res)) {
2293 *ppSurface = d3dSurface->wineD3DSurface;
2294 d3dSurface->container = pSuperior;
2295 IUnknown_Release(d3dSurface->parentDevice);
2296 d3dSurface->parentDevice = NULL;
2297 d3dSurface->forwardReference = pSuperior;
2298 } else {
2299 FIXME("(%p) IDirect3DDevice8_CreateSurface failed\n", device);
2301 return res;
2304 ULONG WINAPI D3D8CB_DestroySurface(IWineD3DSurface *pSurface) {
2305 IDirect3DSurface8Impl* surfaceParent;
2306 TRACE("(%p) call back\n", pSurface);
2308 IWineD3DSurface_GetParent(pSurface, (IUnknown **) &surfaceParent);
2309 /* GetParent's AddRef was forwarded to an object in destruction.
2310 * Releasing it here again would cause an endless recursion. */
2311 surfaceParent->forwardReference = NULL;
2312 return IDirect3DSurface8_Release((IDirect3DSurface8*) surfaceParent);