mapi32: Implement the rest of the Simple MAPI functions.
[wine/hacks.git] / dlls / d3d9 / device.c
blob86890ff925401d2f25699e4cea36bbc54ceb98cd
1 /*
2 * IDirect3DDevice9 implementation
4 * Copyright 2002-2005 Jason Edmeades
5 * Copyright 2002-2005 Raphael Junqueira
6 * Copyright 2005 Oliver Stieber
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "config.h"
24 #include "d3d9_private.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
28 D3DFORMAT d3dformat_from_wined3dformat(WINED3DFORMAT format)
30 BYTE *c = (BYTE *)&format;
32 /* Don't translate FOURCC formats */
33 if (isprint(c[0]) && isprint(c[1]) && isprint(c[2]) && isprint(c[3])) return format;
35 switch(format)
37 case WINED3DFMT_UNKNOWN: return D3DFMT_UNKNOWN;
38 case WINED3DFMT_R8G8B8: return D3DFMT_R8G8B8;
39 case WINED3DFMT_A8R8G8B8: return D3DFMT_A8R8G8B8;
40 case WINED3DFMT_X8R8G8B8: return D3DFMT_X8R8G8B8;
41 case WINED3DFMT_R5G6B5: return D3DFMT_R5G6B5;
42 case WINED3DFMT_X1R5G5B5: return D3DFMT_X1R5G5B5;
43 case WINED3DFMT_A1R5G5B5: return D3DFMT_A1R5G5B5;
44 case WINED3DFMT_A4R4G4B4: return D3DFMT_A4R4G4B4;
45 case WINED3DFMT_R3G3B2: return D3DFMT_R3G3B2;
46 case WINED3DFMT_A8_UNORM: return D3DFMT_A8;
47 case WINED3DFMT_A8R3G3B2: return D3DFMT_A8R3G3B2;
48 case WINED3DFMT_X4R4G4B4: return D3DFMT_X4R4G4B4;
49 case WINED3DFMT_R10G10B10A2_UNORM: return D3DFMT_A2B10G10R10;
50 case WINED3DFMT_R8G8B8A8_UNORM: return D3DFMT_A8B8G8R8;
51 case WINED3DFMT_X8B8G8R8: return D3DFMT_X8B8G8R8;
52 case WINED3DFMT_R16G16_UNORM: return D3DFMT_G16R16;
53 case WINED3DFMT_A2R10G10B10: return D3DFMT_A2R10G10B10;
54 case WINED3DFMT_R16G16B16A16_UNORM: return D3DFMT_A16B16G16R16;
55 case WINED3DFMT_A8P8: return D3DFMT_A8P8;
56 case WINED3DFMT_P8: return D3DFMT_P8;
57 case WINED3DFMT_L8: return D3DFMT_L8;
58 case WINED3DFMT_A8L8: return D3DFMT_A8L8;
59 case WINED3DFMT_A4L4: return D3DFMT_A4L4;
60 case WINED3DFMT_R8G8_SNORM: return D3DFMT_V8U8;
61 case WINED3DFMT_L6V5U5: return D3DFMT_L6V5U5;
62 case WINED3DFMT_X8L8V8U8: return D3DFMT_X8L8V8U8;
63 case WINED3DFMT_R8G8B8A8_SNORM: return D3DFMT_Q8W8V8U8;
64 case WINED3DFMT_R16G16_SNORM: return D3DFMT_V16U16;
65 case WINED3DFMT_A2W10V10U10: return D3DFMT_A2W10V10U10;
66 case WINED3DFMT_D16_LOCKABLE: return D3DFMT_D16_LOCKABLE;
67 case WINED3DFMT_D32: return D3DFMT_D32;
68 case WINED3DFMT_D15S1: return D3DFMT_D15S1;
69 case WINED3DFMT_D24S8: return D3DFMT_D24S8;
70 case WINED3DFMT_D24X8: return D3DFMT_D24X8;
71 case WINED3DFMT_D24X4S4: return D3DFMT_D24X4S4;
72 case WINED3DFMT_D16_UNORM: return D3DFMT_D16;
73 case WINED3DFMT_L16: return D3DFMT_L16;
74 case WINED3DFMT_D32F_LOCKABLE: return D3DFMT_D32F_LOCKABLE;
75 case WINED3DFMT_D24FS8: return D3DFMT_D24FS8;
76 case WINED3DFMT_VERTEXDATA: return D3DFMT_VERTEXDATA;
77 case WINED3DFMT_R16_UINT: return D3DFMT_INDEX16;
78 case WINED3DFMT_R32_UINT: return D3DFMT_INDEX32;
79 case WINED3DFMT_R16G16B16A16_SNORM: return D3DFMT_Q16W16V16U16;
80 case WINED3DFMT_R16_FLOAT: return D3DFMT_R16F;
81 case WINED3DFMT_R16G16_FLOAT: return D3DFMT_G16R16F;
82 case WINED3DFMT_R16G16B16A16_FLOAT: return D3DFMT_A16B16G16R16F;
83 case WINED3DFMT_R32_FLOAT: return D3DFMT_R32F;
84 case WINED3DFMT_R32G32_FLOAT: return D3DFMT_G32R32F;
85 case WINED3DFMT_R32G32B32A32_FLOAT: return D3DFMT_A32B32G32R32F;
86 case WINED3DFMT_CxV8U8: return D3DFMT_CxV8U8;
87 default:
88 FIXME("Unhandled WINED3DFORMAT %#x\n", format);
89 return D3DFMT_UNKNOWN;
93 WINED3DFORMAT wined3dformat_from_d3dformat(D3DFORMAT format)
95 BYTE *c = (BYTE *)&format;
97 /* Don't translate FOURCC formats */
98 if (isprint(c[0]) && isprint(c[1]) && isprint(c[2]) && isprint(c[3])) return format;
100 switch(format)
102 case D3DFMT_UNKNOWN: return WINED3DFMT_UNKNOWN;
103 case D3DFMT_R8G8B8: return WINED3DFMT_R8G8B8;
104 case D3DFMT_A8R8G8B8: return WINED3DFMT_A8R8G8B8;
105 case D3DFMT_X8R8G8B8: return WINED3DFMT_X8R8G8B8;
106 case D3DFMT_R5G6B5: return WINED3DFMT_R5G6B5;
107 case D3DFMT_X1R5G5B5: return WINED3DFMT_X1R5G5B5;
108 case D3DFMT_A1R5G5B5: return WINED3DFMT_A1R5G5B5;
109 case D3DFMT_A4R4G4B4: return WINED3DFMT_A4R4G4B4;
110 case D3DFMT_R3G3B2: return WINED3DFMT_R3G3B2;
111 case D3DFMT_A8: return WINED3DFMT_A8_UNORM;
112 case D3DFMT_A8R3G3B2: return WINED3DFMT_A8R3G3B2;
113 case D3DFMT_X4R4G4B4: return WINED3DFMT_X4R4G4B4;
114 case D3DFMT_A2B10G10R10: return WINED3DFMT_R10G10B10A2_UNORM;
115 case D3DFMT_A8B8G8R8: return WINED3DFMT_R8G8B8A8_UNORM;
116 case D3DFMT_X8B8G8R8: return WINED3DFMT_X8B8G8R8;
117 case D3DFMT_G16R16: return WINED3DFMT_R16G16_UNORM;
118 case D3DFMT_A2R10G10B10: return WINED3DFMT_A2R10G10B10;
119 case D3DFMT_A16B16G16R16: return WINED3DFMT_R16G16B16A16_UNORM;
120 case D3DFMT_A8P8: return WINED3DFMT_A8P8;
121 case D3DFMT_P8: return WINED3DFMT_P8;
122 case D3DFMT_L8: return WINED3DFMT_L8;
123 case D3DFMT_A8L8: return WINED3DFMT_A8L8;
124 case D3DFMT_A4L4: return WINED3DFMT_A4L4;
125 case D3DFMT_V8U8: return WINED3DFMT_R8G8_SNORM;
126 case D3DFMT_L6V5U5: return WINED3DFMT_L6V5U5;
127 case D3DFMT_X8L8V8U8: return WINED3DFMT_X8L8V8U8;
128 case D3DFMT_Q8W8V8U8: return WINED3DFMT_R8G8B8A8_SNORM;
129 case D3DFMT_V16U16: return WINED3DFMT_R16G16_SNORM;
130 case D3DFMT_A2W10V10U10: return WINED3DFMT_A2W10V10U10;
131 case D3DFMT_D16_LOCKABLE: return WINED3DFMT_D16_LOCKABLE;
132 case D3DFMT_D32: return WINED3DFMT_D32;
133 case D3DFMT_D15S1: return WINED3DFMT_D15S1;
134 case D3DFMT_D24S8: return WINED3DFMT_D24S8;
135 case D3DFMT_D24X8: return WINED3DFMT_D24X8;
136 case D3DFMT_D24X4S4: return WINED3DFMT_D24X4S4;
137 case D3DFMT_D16: return WINED3DFMT_D16_UNORM;
138 case D3DFMT_L16: return WINED3DFMT_L16;
139 case D3DFMT_D32F_LOCKABLE: return WINED3DFMT_D32F_LOCKABLE;
140 case D3DFMT_D24FS8: return WINED3DFMT_D24FS8;
141 case D3DFMT_VERTEXDATA: return WINED3DFMT_VERTEXDATA;
142 case D3DFMT_INDEX16: return WINED3DFMT_R16_UINT;
143 case D3DFMT_INDEX32: return WINED3DFMT_R32_UINT;
144 case D3DFMT_Q16W16V16U16: return WINED3DFMT_R16G16B16A16_SNORM;
145 case D3DFMT_R16F: return WINED3DFMT_R16_FLOAT;
146 case D3DFMT_G16R16F: return WINED3DFMT_R16G16_FLOAT;
147 case D3DFMT_A16B16G16R16F: return WINED3DFMT_R16G16B16A16_FLOAT;
148 case D3DFMT_R32F: return WINED3DFMT_R32_FLOAT;
149 case D3DFMT_G32R32F: return WINED3DFMT_R32G32_FLOAT;
150 case D3DFMT_A32B32G32R32F: return WINED3DFMT_R32G32B32A32_FLOAT;
151 case D3DFMT_CxV8U8: return WINED3DFMT_CxV8U8;
152 default:
153 FIXME("Unhandled D3DFORMAT %#x\n", format);
154 return WINED3DFMT_UNKNOWN;
158 static UINT vertex_count_from_primitive_count(D3DPRIMITIVETYPE primitive_type, UINT primitive_count)
160 switch(primitive_type)
162 case D3DPT_POINTLIST:
163 return primitive_count;
165 case D3DPT_LINELIST:
166 return primitive_count * 2;
168 case D3DPT_LINESTRIP:
169 return primitive_count + 1;
171 case D3DPT_TRIANGLELIST:
172 return primitive_count * 3;
174 case D3DPT_TRIANGLESTRIP:
175 case D3DPT_TRIANGLEFAN:
176 return primitive_count + 2;
178 default:
179 FIXME("Unhandled primitive type %#x\n", primitive_type);
180 return 0;
184 /* IDirect3D IUnknown parts follow: */
185 static HRESULT WINAPI IDirect3DDevice9Impl_QueryInterface(LPDIRECT3DDEVICE9EX iface, REFIID riid, LPVOID* ppobj) {
186 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
187 IDirect3D9 *d3d;
188 IDirect3D9Impl *d3dimpl;
190 if (IsEqualGUID(riid, &IID_IUnknown)
191 || IsEqualGUID(riid, &IID_IDirect3DDevice9)) {
192 IDirect3DDevice9Ex_AddRef(iface);
193 *ppobj = This;
194 TRACE("Returning IDirect3DDevice9 interface at %p\n", *ppobj);
195 return S_OK;
196 } else if(IsEqualGUID(riid, &IID_IDirect3DDevice9Ex)) {
197 /* Find out if the creating d3d9 interface was created with Direct3DCreate9Ex.
198 * It doesn't matter with which function the device was created.
200 IDirect3DDevice9_GetDirect3D(iface, &d3d);
201 d3dimpl = (IDirect3D9Impl *) d3d;
203 if(d3dimpl->extended) {
204 *ppobj = iface;
205 IDirect3DDevice9Ex_AddRef((IDirect3DDevice9Ex *) *ppobj);
206 IDirect3D9_Release(d3d);
207 TRACE("Returning IDirect3DDevice9Ex interface at %p\n", *ppobj);
208 return S_OK;
209 } else {
210 WARN("IDirect3D9 instance wasn't created with CreateDirect3D9Ex, returning E_NOINTERFACE\n");
211 IDirect3D9_Release(d3d);
212 *ppobj = NULL;
213 return E_NOINTERFACE;
217 if (IsEqualGUID(riid, &IID_IWineD3DDeviceParent))
219 IUnknown_AddRef((IUnknown *)&This->device_parent_vtbl);
220 *ppobj = &This->device_parent_vtbl;
221 return S_OK;
224 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
225 *ppobj = NULL;
226 return E_NOINTERFACE;
229 static ULONG WINAPI IDirect3DDevice9Impl_AddRef(LPDIRECT3DDEVICE9EX iface) {
230 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
231 ULONG ref = InterlockedIncrement(&This->ref);
233 TRACE("(%p) : AddRef from %d\n", This, ref - 1);
235 return ref;
238 static ULONG WINAPI IDirect3DDevice9Impl_Release(LPDIRECT3DDEVICE9EX iface) {
239 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
240 ULONG ref;
242 if (This->inDestruction) return 0;
243 ref = InterlockedDecrement(&This->ref);
245 TRACE("(%p) : ReleaseRef to %d\n", This, ref);
247 if (ref == 0) {
248 unsigned i;
249 This->inDestruction = TRUE;
251 wined3d_mutex_lock();
252 for(i = 0; i < This->numConvertedDecls; i++) {
253 /* Unless Wine is buggy or the app has a bug the refcount will be 0, because decls hold a reference to the
254 * device
256 IDirect3DVertexDeclaration9Impl_Destroy(This->convertedDecls[i]);
258 HeapFree(GetProcessHeap(), 0, This->convertedDecls);
260 IWineD3DDevice_Uninit3D(This->WineD3DDevice, D3D9CB_DestroySwapChain);
261 IWineD3DDevice_Release(This->WineD3DDevice);
262 wined3d_mutex_unlock();
264 HeapFree(GetProcessHeap(), 0, This);
266 return ref;
269 /* IDirect3DDevice Interface follow: */
270 static HRESULT WINAPI IDirect3DDevice9Impl_TestCooperativeLevel(LPDIRECT3DDEVICE9EX iface) {
271 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
272 HRESULT hr;
273 TRACE("(%p)\n", This);
275 wined3d_mutex_lock();
276 hr = IWineD3DDevice_TestCooperativeLevel(This->WineD3DDevice);
277 wined3d_mutex_unlock();
279 if(hr == WINED3D_OK && This->notreset) {
280 TRACE("D3D9 Device is marked not reset\n");
281 hr = D3DERR_DEVICENOTRESET;
284 return hr;
287 static UINT WINAPI IDirect3DDevice9Impl_GetAvailableTextureMem(LPDIRECT3DDEVICE9EX iface) {
288 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
289 HRESULT hr;
290 TRACE("(%p) Relay\n", This);
292 wined3d_mutex_lock();
293 hr = IWineD3DDevice_GetAvailableTextureMem(This->WineD3DDevice);
294 wined3d_mutex_unlock();
296 return hr;
299 static HRESULT WINAPI IDirect3DDevice9Impl_EvictManagedResources(LPDIRECT3DDEVICE9EX iface) {
300 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
301 HRESULT hr;
302 TRACE("(%p) : Relay\n", This);
304 wined3d_mutex_lock();
305 hr = IWineD3DDevice_EvictManagedResources(This->WineD3DDevice);
306 wined3d_mutex_unlock();
308 return hr;
311 static HRESULT WINAPI IDirect3DDevice9Impl_GetDirect3D(LPDIRECT3DDEVICE9EX iface, IDirect3D9** ppD3D9) {
312 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
313 HRESULT hr = D3D_OK;
314 IWineD3D* pWineD3D;
316 TRACE("(%p) Relay\n", This);
318 if (NULL == ppD3D9) {
319 return D3DERR_INVALIDCALL;
322 wined3d_mutex_lock();
323 hr = IWineD3DDevice_GetDirect3D(This->WineD3DDevice, &pWineD3D);
324 if (hr == D3D_OK && pWineD3D != NULL)
326 IWineD3D_GetParent(pWineD3D,(IUnknown **)ppD3D9);
327 IWineD3D_Release(pWineD3D);
328 } else {
329 FIXME("Call to IWineD3DDevice_GetDirect3D failed\n");
330 *ppD3D9 = NULL;
332 TRACE("(%p) returning %p\n", This, *ppD3D9);
333 wined3d_mutex_unlock();
335 return hr;
338 static HRESULT WINAPI IDirect3DDevice9Impl_GetDeviceCaps(LPDIRECT3DDEVICE9EX iface, D3DCAPS9* pCaps) {
339 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
340 HRESULT hrc = D3D_OK;
341 WINED3DCAPS *pWineCaps;
343 TRACE("(%p) : Relay pCaps %p\n", This, pCaps);
344 if(NULL == pCaps){
345 return D3DERR_INVALIDCALL;
347 pWineCaps = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WINED3DCAPS));
348 if(pWineCaps == NULL){
349 return D3DERR_INVALIDCALL; /* well this is what MSDN says to return */
352 memset(pCaps, 0, sizeof(*pCaps));
354 wined3d_mutex_lock();
355 hrc = IWineD3DDevice_GetDeviceCaps(This->WineD3DDevice, pWineCaps);
356 wined3d_mutex_unlock();
358 WINECAPSTOD3D9CAPS(pCaps, pWineCaps)
359 HeapFree(GetProcessHeap(), 0, pWineCaps);
361 /* Some functionality is implemented in d3d9.dll, not wined3d.dll. Add the needed caps */
362 pCaps->DevCaps2 |= D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES;
364 filter_caps(pCaps);
366 TRACE("Returning %p %p\n", This, pCaps);
367 return hrc;
370 static HRESULT WINAPI IDirect3DDevice9Impl_GetDisplayMode(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain, D3DDISPLAYMODE* pMode) {
371 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
372 HRESULT hr;
373 TRACE("(%p) Relay\n", This);
375 wined3d_mutex_lock();
376 hr = IWineD3DDevice_GetDisplayMode(This->WineD3DDevice, iSwapChain, (WINED3DDISPLAYMODE *) pMode);
377 wined3d_mutex_unlock();
379 if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format);
381 return hr;
384 static HRESULT WINAPI IDirect3DDevice9Impl_GetCreationParameters(LPDIRECT3DDEVICE9EX iface, D3DDEVICE_CREATION_PARAMETERS *pParameters) {
385 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
386 HRESULT hr;
387 TRACE("(%p) Relay\n", This);
389 wined3d_mutex_lock();
390 hr = IWineD3DDevice_GetCreationParameters(This->WineD3DDevice, (WINED3DDEVICE_CREATION_PARAMETERS *) pParameters);
391 wined3d_mutex_unlock();
393 return hr;
396 static HRESULT WINAPI IDirect3DDevice9Impl_SetCursorProperties(LPDIRECT3DDEVICE9EX iface, UINT XHotSpot, UINT YHotSpot, IDirect3DSurface9* pCursorBitmap) {
397 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
398 IDirect3DSurface9Impl *pSurface = (IDirect3DSurface9Impl*)pCursorBitmap;
399 HRESULT hr;
401 TRACE("(%p) Relay\n", This);
402 if(!pCursorBitmap) {
403 WARN("No cursor bitmap, returning WINED3DERR_INVALIDCALL\n");
404 return WINED3DERR_INVALIDCALL;
407 wined3d_mutex_lock();
408 hr = IWineD3DDevice_SetCursorProperties(This->WineD3DDevice, XHotSpot, YHotSpot, pSurface->wineD3DSurface);
409 wined3d_mutex_unlock();
411 return hr;
414 static void WINAPI IDirect3DDevice9Impl_SetCursorPosition(LPDIRECT3DDEVICE9EX iface, int XScreenSpace, int YScreenSpace, DWORD Flags) {
415 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
416 TRACE("(%p) Relay\n", This);
418 wined3d_mutex_lock();
419 IWineD3DDevice_SetCursorPosition(This->WineD3DDevice, XScreenSpace, YScreenSpace, Flags);
420 wined3d_mutex_unlock();
423 static BOOL WINAPI IDirect3DDevice9Impl_ShowCursor(LPDIRECT3DDEVICE9EX iface, BOOL bShow) {
424 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
425 BOOL ret;
426 TRACE("(%p) Relay\n", This);
428 wined3d_mutex_lock();
429 ret = IWineD3DDevice_ShowCursor(This->WineD3DDevice, bShow);
430 wined3d_mutex_unlock();
432 return ret;
435 static HRESULT WINAPI reset_enum_callback(IWineD3DResource *resource, void *data) {
436 BOOL *resources_ok = data;
437 D3DRESOURCETYPE type;
438 HRESULT ret = S_OK;
439 WINED3DSURFACE_DESC surface_desc;
440 WINED3DVOLUME_DESC volume_desc;
441 D3DINDEXBUFFER_DESC index_desc;
442 D3DVERTEXBUFFER_DESC vertex_desc;
443 WINED3DPOOL pool;
444 IDirect3DResource9 *parent;
446 IWineD3DResource_GetParent(resource, (IUnknown **) &parent);
447 type = IDirect3DResource9_GetType(parent);
448 switch(type) {
449 case D3DRTYPE_SURFACE:
450 IWineD3DSurface_GetDesc((IWineD3DSurface *) resource, &surface_desc);
451 pool = surface_desc.pool;
452 break;
454 case D3DRTYPE_VOLUME:
455 IWineD3DVolume_GetDesc((IWineD3DVolume *) resource, &volume_desc);
456 pool = volume_desc.Pool;
457 break;
459 case D3DRTYPE_INDEXBUFFER:
460 IDirect3DIndexBuffer9_GetDesc((IDirect3DIndexBuffer9 *) parent, &index_desc);
461 pool = index_desc.Pool;
462 break;
464 case D3DRTYPE_VERTEXBUFFER:
465 IDirect3DVertexBuffer9_GetDesc((IDirect3DVertexBuffer9 *)parent, &vertex_desc);
466 pool = vertex_desc.Pool;
467 break;
469 /* No need to check for textures. If there is a D3DPOOL_DEFAULT texture, there
470 * is a D3DPOOL_DEFAULT surface or volume as well
472 default:
473 pool = WINED3DPOOL_SCRATCH; /* a harmless pool */
474 break;
477 if(pool == WINED3DPOOL_DEFAULT) {
478 if(IUnknown_Release(parent) == 0) {
479 TRACE("Parent %p is an implicit resource with ref 0\n", parent);
480 } else {
481 WARN("Resource %p(wineD3D %p) with pool D3DPOOL_DEFAULT blocks the Reset call\n", parent, resource);
482 ret = S_FALSE;
483 *resources_ok = FALSE;
485 } else {
486 IUnknown_Release(parent);
488 IWineD3DResource_Release(resource);
490 return ret;
493 static HRESULT WINAPI IDirect3DDevice9Impl_Reset(LPDIRECT3DDEVICE9EX iface, D3DPRESENT_PARAMETERS* pPresentationParameters) {
494 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
495 WINED3DPRESENT_PARAMETERS localParameters;
496 HRESULT hr;
497 BOOL resources_ok = TRUE;
498 UINT i;
500 TRACE("(%p) Relay pPresentationParameters(%p)\n", This, pPresentationParameters);
502 /* Reset states that hold a COM object. WineD3D holds an internal reference to set objects, because
503 * such objects can still be used for rendering after their external d3d9 object has been destroyed.
504 * These objects must not be enumerated. Unsetting them tells WineD3D that the application will not
505 * make use of the hidden reference and destroys the objects.
507 * Unsetting them is no problem, because the states are supposed to be reset anyway. If the validation
508 * below fails, the device is considered "lost", and _Reset and _Release are the only allowed calls
510 wined3d_mutex_lock();
511 IWineD3DDevice_SetIndices(This->WineD3DDevice, NULL, WINED3DFMT_UNKNOWN);
512 for(i = 0; i < 16; i++) {
513 IWineD3DDevice_SetStreamSource(This->WineD3DDevice, i, NULL, 0, 0);
515 for(i = 0; i < 16; i++) {
516 IWineD3DDevice_SetTexture(This->WineD3DDevice, i, NULL);
519 IWineD3DDevice_EnumResources(This->WineD3DDevice, reset_enum_callback, &resources_ok);
520 if(!resources_ok) {
521 WARN("The application is holding D3DPOOL_DEFAULT resources, rejecting reset\n");
522 This->notreset = TRUE;
523 wined3d_mutex_unlock();
525 return WINED3DERR_INVALIDCALL;
528 localParameters.BackBufferWidth = pPresentationParameters->BackBufferWidth;
529 localParameters.BackBufferHeight = pPresentationParameters->BackBufferHeight;
530 localParameters.BackBufferFormat = wined3dformat_from_d3dformat(pPresentationParameters->BackBufferFormat);
531 localParameters.BackBufferCount = pPresentationParameters->BackBufferCount;
532 localParameters.MultiSampleType = pPresentationParameters->MultiSampleType;
533 localParameters.MultiSampleQuality = pPresentationParameters->MultiSampleQuality;
534 localParameters.SwapEffect = pPresentationParameters->SwapEffect;
535 localParameters.hDeviceWindow = pPresentationParameters->hDeviceWindow;
536 localParameters.Windowed = pPresentationParameters->Windowed;
537 localParameters.EnableAutoDepthStencil = pPresentationParameters->EnableAutoDepthStencil;
538 localParameters.AutoDepthStencilFormat = wined3dformat_from_d3dformat(pPresentationParameters->AutoDepthStencilFormat);
539 localParameters.Flags = pPresentationParameters->Flags;
540 localParameters.FullScreen_RefreshRateInHz = pPresentationParameters->FullScreen_RefreshRateInHz;
541 localParameters.PresentationInterval = pPresentationParameters->PresentationInterval;
542 localParameters.AutoRestoreDisplayMode = TRUE;
544 hr = IWineD3DDevice_Reset(This->WineD3DDevice, &localParameters);
545 if(FAILED(hr)) {
546 This->notreset = TRUE;
548 pPresentationParameters->BackBufferWidth = localParameters.BackBufferWidth;
549 pPresentationParameters->BackBufferHeight = localParameters.BackBufferHeight;
550 pPresentationParameters->BackBufferFormat = d3dformat_from_wined3dformat(localParameters.BackBufferFormat);
551 pPresentationParameters->BackBufferCount = localParameters.BackBufferCount;
552 pPresentationParameters->MultiSampleType = localParameters.MultiSampleType;
553 pPresentationParameters->MultiSampleQuality = localParameters.MultiSampleQuality;
554 pPresentationParameters->SwapEffect = localParameters.SwapEffect;
555 pPresentationParameters->hDeviceWindow = localParameters.hDeviceWindow;
556 pPresentationParameters->Windowed = localParameters.Windowed;
557 pPresentationParameters->EnableAutoDepthStencil = localParameters.EnableAutoDepthStencil;
558 pPresentationParameters->AutoDepthStencilFormat = d3dformat_from_wined3dformat(localParameters.AutoDepthStencilFormat);
559 pPresentationParameters->Flags = localParameters.Flags;
560 pPresentationParameters->FullScreen_RefreshRateInHz = localParameters.FullScreen_RefreshRateInHz;
561 pPresentationParameters->PresentationInterval = localParameters.PresentationInterval;
562 } else {
563 This->notreset = FALSE;
566 wined3d_mutex_unlock();
568 return hr;
571 static HRESULT WINAPI IDirect3DDevice9Impl_Present(LPDIRECT3DDEVICE9EX iface, CONST RECT* pSourceRect,CONST RECT* pDestRect,HWND hDestWindowOverride,CONST RGNDATA*
572 pDirtyRegion) {
573 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
574 HRESULT hr;
575 TRACE("(%p) Relay\n", This);
577 wined3d_mutex_lock();
578 hr = IWineD3DDevice_Present(This->WineD3DDevice, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
579 wined3d_mutex_unlock();
581 return hr;
584 static HRESULT WINAPI IDirect3DDevice9Impl_GetBackBuffer(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain, UINT BackBuffer, D3DBACKBUFFER_TYPE Type, IDirect3DSurface9 ** ppBackBuffer) {
585 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
586 IWineD3DSurface *retSurface = NULL;
587 HRESULT rc = D3D_OK;
589 TRACE("(%p) Relay\n", This);
591 wined3d_mutex_lock();
592 rc = IWineD3DDevice_GetBackBuffer(This->WineD3DDevice, iSwapChain, BackBuffer, (WINED3DBACKBUFFER_TYPE) Type, &retSurface);
593 if (rc == D3D_OK && NULL != retSurface && NULL != ppBackBuffer) {
594 IWineD3DSurface_GetParent(retSurface, (IUnknown **)ppBackBuffer);
595 IWineD3DSurface_Release(retSurface);
597 wined3d_mutex_unlock();
599 return rc;
601 static HRESULT WINAPI IDirect3DDevice9Impl_GetRasterStatus(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain, D3DRASTER_STATUS* pRasterStatus) {
602 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
603 HRESULT hr;
604 TRACE("(%p) Relay\n", This);
606 wined3d_mutex_lock();
607 hr = IWineD3DDevice_GetRasterStatus(This->WineD3DDevice, iSwapChain, (WINED3DRASTER_STATUS *) pRasterStatus);
608 wined3d_mutex_unlock();
610 return hr;
613 static HRESULT WINAPI IDirect3DDevice9Impl_SetDialogBoxMode(LPDIRECT3DDEVICE9EX iface, BOOL bEnableDialogs) {
614 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
615 HRESULT hr;
616 TRACE("(%p) Relay\n", This);
618 wined3d_mutex_lock();
619 hr = IWineD3DDevice_SetDialogBoxMode(This->WineD3DDevice, bEnableDialogs);
620 wined3d_mutex_unlock();
622 return hr;
625 static void WINAPI IDirect3DDevice9Impl_SetGammaRamp(IDirect3DDevice9Ex *iface, UINT iSwapChain,
626 DWORD Flags, const D3DGAMMARAMP *pRamp)
628 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
629 TRACE("(%p) Relay\n", This);
631 /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
632 wined3d_mutex_lock();
633 IWineD3DDevice_SetGammaRamp(This->WineD3DDevice, iSwapChain, Flags, (CONST WINED3DGAMMARAMP *)pRamp);
634 wined3d_mutex_unlock();
637 static void WINAPI IDirect3DDevice9Impl_GetGammaRamp(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain, D3DGAMMARAMP* pRamp) {
638 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
639 TRACE("(%p) Relay\n", This);
641 /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
642 wined3d_mutex_lock();
643 IWineD3DDevice_GetGammaRamp(This->WineD3DDevice, iSwapChain, (WINED3DGAMMARAMP *) pRamp);
644 wined3d_mutex_unlock();
647 static HRESULT WINAPI IDirect3DDevice9Impl_CreateTexture(IDirect3DDevice9Ex *iface,
648 UINT width, UINT height, UINT levels, DWORD usage, D3DFORMAT format,
649 D3DPOOL pool, IDirect3DTexture9 **texture, HANDLE *shared_handle)
651 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
652 IDirect3DTexture9Impl *object;
653 HRESULT hr;
655 TRACE("iface %p, width %u, height %u, levels %u, usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n",
656 iface, width, height, levels, usage, format, pool, texture, shared_handle);
658 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
659 if (!object)
661 ERR("Failed to allocate texture memory.\n");
662 return D3DERR_OUTOFVIDEOMEMORY;
665 hr = texture_init(object, This, width, height, levels, usage, format, pool);
666 if (FAILED(hr))
668 WARN("Failed to initialize texture, hr %#x.\n", hr);
669 HeapFree(GetProcessHeap(), 0, object);
670 return hr;
673 TRACE("Created texture %p.\n", object);
674 *texture = (IDirect3DTexture9 *)object;
676 return D3D_OK;
679 static HRESULT WINAPI IDirect3DDevice9Impl_CreateVolumeTexture(IDirect3DDevice9Ex *iface,
680 UINT width, UINT height, UINT depth, UINT levels, DWORD usage, D3DFORMAT format,
681 D3DPOOL pool, IDirect3DVolumeTexture9 **texture, HANDLE *shared_handle)
683 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
684 IDirect3DVolumeTexture9Impl *object;
685 HRESULT hr;
687 TRACE("iface %p, width %u, height %u, depth %u, levels %u\n",
688 iface, width, height, depth, levels);
689 TRACE("usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n",
690 usage, format, pool, texture, shared_handle);
692 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
693 if (!object)
695 ERR("Failed to allocate volume texture memory.\n");
696 return D3DERR_OUTOFVIDEOMEMORY;
699 hr = volumetexture_init(object, This, width, height, depth, levels, usage, format, pool);
700 if (FAILED(hr))
702 WARN("Failed to initialize volume texture, hr %#x.\n", hr);
703 HeapFree(GetProcessHeap(), 0, object);
704 return hr;
707 TRACE("Created volume texture %p.\n", object);
708 *texture = (IDirect3DVolumeTexture9 *)object;
710 return D3D_OK;
713 static HRESULT WINAPI IDirect3DDevice9Impl_CreateCubeTexture(IDirect3DDevice9Ex *iface,
714 UINT edge_length, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool,
715 IDirect3DCubeTexture9 **texture, HANDLE *shared_handle)
717 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
718 IDirect3DCubeTexture9Impl *object;
719 HRESULT hr;
721 TRACE("iface %p, edge_length %u, levels %u, usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n",
722 iface, edge_length, levels, usage, format, pool, texture, shared_handle);
724 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
725 if (!object)
727 ERR("Failed to allocate cube texture memory.\n");
728 return D3DERR_OUTOFVIDEOMEMORY;
731 hr = cubetexture_init(object, This, edge_length, levels, usage, format, pool);
732 if (FAILED(hr))
734 WARN("Failed to initialize cube texture, hr %#x.\n", hr);
735 HeapFree(GetProcessHeap(), 0, object);
736 return hr;
739 TRACE("Created cube texture %p.\n", object);
740 *texture = (IDirect3DCubeTexture9 *)object;
742 return D3D_OK;
745 static HRESULT WINAPI IDirect3DDevice9Impl_CreateVertexBuffer(IDirect3DDevice9Ex *iface, UINT size, DWORD usage,
746 DWORD fvf, D3DPOOL pool, IDirect3DVertexBuffer9 **buffer, HANDLE *shared_handle)
748 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
749 IDirect3DVertexBuffer9Impl *object;
750 HRESULT hr;
752 TRACE("iface %p, size %u, usage %#x, fvf %#x, pool %#x, buffer %p, shared_handle %p.\n",
753 iface, size, usage, fvf, pool, buffer, shared_handle);
755 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
756 if (!object)
758 ERR("Failed to allocate buffer memory.\n");
759 return D3DERR_OUTOFVIDEOMEMORY;
762 hr = vertexbuffer_init(object, This, size, usage, fvf, pool);
763 if (FAILED(hr))
765 WARN("Failed to initialize vertex buffer, hr %#x.\n", hr);
766 HeapFree(GetProcessHeap(), 0, object);
767 return hr;
770 TRACE("Created vertex buffer %p.\n", object);
771 *buffer = (IDirect3DVertexBuffer9 *)object;
773 return D3D_OK;
776 static HRESULT WINAPI IDirect3DDevice9Impl_CreateIndexBuffer(IDirect3DDevice9Ex *iface, UINT size, DWORD usage,
777 D3DFORMAT format, D3DPOOL pool, IDirect3DIndexBuffer9 **buffer, HANDLE *shared_handle)
779 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
780 IDirect3DIndexBuffer9Impl *object;
781 HRESULT hr;
783 TRACE("iface %p, size %u, usage %#x, format %#x, pool %#x, buffer %p, shared_handle %p.\n",
784 iface, size, usage, format, pool, buffer, shared_handle);
786 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
787 if (!object)
789 ERR("Failed to allocate buffer memory.\n");
790 return D3DERR_OUTOFVIDEOMEMORY;
793 hr = indexbuffer_init(object, This, size, usage, format, pool);
794 if (FAILED(hr))
796 WARN("Failed to initialize index buffer, hr %#x.\n", hr);
797 HeapFree(GetProcessHeap(), 0, object);
798 return hr;
801 TRACE("Created index buffer %p.\n", object);
802 *buffer = (IDirect3DIndexBuffer9 *)object;
804 return D3D_OK;
807 static HRESULT IDirect3DDevice9Impl_CreateSurface(LPDIRECT3DDEVICE9EX iface, UINT Width, UINT Height,
808 D3DFORMAT Format, BOOL Lockable, BOOL Discard, UINT Level, IDirect3DSurface9 **ppSurface,
809 UINT Usage, D3DPOOL Pool, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality)
811 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
812 IDirect3DSurface9Impl *object;
813 HRESULT hr;
815 TRACE("(%p) : w(%d) h(%d) fmt(%d) surf@%p\n", This, Width, Height, Format, *ppSurface);
817 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DSurface9Impl));
818 if (!object)
820 FIXME("Failed to allocate surface memory.\n");
821 return D3DERR_OUTOFVIDEOMEMORY;
824 hr = surface_init(object, This, Width, Height, Format, Lockable, Discard,
825 Level, Usage, Pool, MultiSample, MultisampleQuality);
826 if (FAILED(hr))
828 WARN("Failed to initialize surface, hr %#x.\n", hr);
829 HeapFree(GetProcessHeap(), 0, object);
830 return hr;
833 TRACE("Created surface %p.\n", object);
834 *ppSurface = (IDirect3DSurface9 *)object;
836 return D3D_OK;
839 static HRESULT WINAPI IDirect3DDevice9Impl_CreateRenderTarget(IDirect3DDevice9Ex *iface, UINT Width, UINT Height,
840 D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality, BOOL Lockable,
841 IDirect3DSurface9 **ppSurface, HANDLE *pSharedHandle)
843 HRESULT hr;
844 TRACE("Relay\n");
846 hr = IDirect3DDevice9Impl_CreateSurface(iface, Width, Height, Format, Lockable, FALSE /* Discard */,
847 0 /* Level */, ppSurface, D3DUSAGE_RENDERTARGET, D3DPOOL_DEFAULT, MultiSample, MultisampleQuality);
849 return hr;
852 static HRESULT WINAPI IDirect3DDevice9Impl_CreateDepthStencilSurface(LPDIRECT3DDEVICE9EX iface, UINT Width, UINT Height,
853 D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample,
854 DWORD MultisampleQuality, BOOL Discard,
855 IDirect3DSurface9 **ppSurface, HANDLE* pSharedHandle) {
856 HRESULT hr;
857 TRACE("Relay\n");
859 hr = IDirect3DDevice9Impl_CreateSurface(iface, Width, Height, Format, TRUE /* Lockable */, Discard,
860 0 /* Level */, ppSurface, D3DUSAGE_DEPTHSTENCIL, D3DPOOL_DEFAULT, MultiSample, MultisampleQuality);
862 return hr;
866 static HRESULT WINAPI IDirect3DDevice9Impl_UpdateSurface(LPDIRECT3DDEVICE9EX iface, IDirect3DSurface9* pSourceSurface, CONST RECT* pSourceRect, IDirect3DSurface9* pDestinationSurface, CONST POINT* pDestPoint) {
867 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
868 HRESULT hr;
869 TRACE("(%p) Relay\n" , This);
871 wined3d_mutex_lock();
872 hr = IWineD3DDevice_UpdateSurface(This->WineD3DDevice, ((IDirect3DSurface9Impl *)pSourceSurface)->wineD3DSurface, pSourceRect, ((IDirect3DSurface9Impl *)pDestinationSurface)->wineD3DSurface, pDestPoint);
873 wined3d_mutex_unlock();
875 return hr;
878 static HRESULT WINAPI IDirect3DDevice9Impl_UpdateTexture(LPDIRECT3DDEVICE9EX iface, IDirect3DBaseTexture9* pSourceTexture, IDirect3DBaseTexture9* pDestinationTexture) {
879 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
880 HRESULT hr;
881 TRACE("(%p) Relay\n" , This);
883 wined3d_mutex_lock();
884 hr = IWineD3DDevice_UpdateTexture(This->WineD3DDevice, ((IDirect3DBaseTexture9Impl *)pSourceTexture)->wineD3DBaseTexture, ((IDirect3DBaseTexture9Impl *)pDestinationTexture)->wineD3DBaseTexture);
885 wined3d_mutex_unlock();
887 return hr;
890 static HRESULT WINAPI IDirect3DDevice9Impl_GetRenderTargetData(LPDIRECT3DDEVICE9EX iface, IDirect3DSurface9* pRenderTarget, IDirect3DSurface9* pDestSurface) {
891 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
892 IDirect3DSurface9Impl *renderTarget = (IDirect3DSurface9Impl *)pRenderTarget;
893 IDirect3DSurface9Impl *destSurface = (IDirect3DSurface9Impl *)pDestSurface;
894 HRESULT hr;
895 TRACE("(%p)->(%p,%p)\n" , This, renderTarget, destSurface);
897 wined3d_mutex_lock();
898 hr = IWineD3DSurface_BltFast(destSurface->wineD3DSurface, 0, 0, renderTarget->wineD3DSurface, NULL, WINEDDBLTFAST_NOCOLORKEY);
899 wined3d_mutex_unlock();
901 return hr;
904 static HRESULT WINAPI IDirect3DDevice9Impl_GetFrontBufferData(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain, IDirect3DSurface9* pDestSurface) {
905 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
906 IDirect3DSurface9Impl *destSurface = (IDirect3DSurface9Impl *)pDestSurface;
907 HRESULT hr;
908 TRACE("(%p) Relay\n" , This);
910 wined3d_mutex_lock();
911 hr = IWineD3DDevice_GetFrontBufferData(This->WineD3DDevice, iSwapChain, destSurface->wineD3DSurface);
912 wined3d_mutex_unlock();
914 return hr;
917 static HRESULT WINAPI IDirect3DDevice9Impl_StretchRect(LPDIRECT3DDEVICE9EX iface, IDirect3DSurface9* pSourceSurface, CONST RECT* pSourceRect, IDirect3DSurface9* pDestSurface, CONST RECT* pDestRect, D3DTEXTUREFILTERTYPE Filter) {
918 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
919 IDirect3DSurface9Impl *src = (IDirect3DSurface9Impl *) pSourceSurface;
920 IDirect3DSurface9Impl *dst = (IDirect3DSurface9Impl *) pDestSurface;
921 HRESULT hr;
923 TRACE("(%p)->(%p,%p,%p,%p,%d)\n" , This, src, pSourceRect, dst, pDestRect, Filter);
925 wined3d_mutex_lock();
926 hr = IWineD3DSurface_Blt(dst->wineD3DSurface, pDestRect, src->wineD3DSurface, pSourceRect, 0, NULL, Filter);
927 wined3d_mutex_unlock();
929 return hr;
932 static HRESULT WINAPI IDirect3DDevice9Impl_ColorFill(LPDIRECT3DDEVICE9EX iface, IDirect3DSurface9* pSurface, CONST RECT* pRect, D3DCOLOR color) {
933 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
934 IDirect3DSurface9Impl *surface = (IDirect3DSurface9Impl *)pSurface;
935 WINED3DPOOL pool;
936 WINED3DRESOURCETYPE restype;
937 DWORD usage;
938 WINED3DSURFACE_DESC desc;
939 HRESULT hr;
940 TRACE("(%p) Relay\n" , This);
942 wined3d_mutex_lock();
944 IWineD3DSurface_GetDesc(surface->wineD3DSurface, &desc);
945 usage = desc.usage;
946 pool = desc.pool;
947 restype = desc.resource_type;
949 /* This method is only allowed with surfaces that are render targets, or offscreen plain surfaces
950 * in D3DPOOL_DEFAULT
952 if(!(usage & WINED3DUSAGE_RENDERTARGET) && (pool != WINED3DPOOL_DEFAULT || restype != WINED3DRTYPE_SURFACE)) {
953 wined3d_mutex_unlock();
954 WARN("Surface is not a render target, or not a stand-alone D3DPOOL_DEFAULT surface\n");
955 return D3DERR_INVALIDCALL;
958 /* Colorfill can only be used on rendertarget surfaces, or offscreen plain surfaces in D3DPOOL_DEFAULT */
959 /* Note: D3DRECT is compatible with WINED3DRECT */
960 hr = IWineD3DDevice_ColorFill(This->WineD3DDevice, surface->wineD3DSurface, (CONST WINED3DRECT*)pRect, color);
962 wined3d_mutex_unlock();
964 return hr;
967 static HRESULT WINAPI IDirect3DDevice9Impl_CreateOffscreenPlainSurface(LPDIRECT3DDEVICE9EX iface, UINT Width, UINT Height, D3DFORMAT Format, D3DPOOL Pool, IDirect3DSurface9 **ppSurface, HANDLE* pSharedHandle) {
968 HRESULT hr;
969 TRACE("Relay\n");
970 if(Pool == D3DPOOL_MANAGED ){
971 FIXME("Attempting to create a managed offscreen plain surface\n");
972 return D3DERR_INVALIDCALL;
975 'Off-screen plain surfaces are always lockable, regardless of their pool types.'
976 but then...
977 D3DPOOL_DEFAULT is the appropriate pool for use with the IDirect3DDevice9::StretchRect and IDirect3DDevice9::ColorFill.
978 Why, their always lockable?
979 should I change the usage to dynamic?
981 hr = IDirect3DDevice9Impl_CreateSurface(iface, Width, Height, Format, TRUE /* Lockable */, FALSE /* Discard */,
982 0 /* Level */, ppSurface, 0 /* Usage (undefined/none) */, (WINED3DPOOL)Pool, D3DMULTISAMPLE_NONE,
983 0 /* MultisampleQuality */);
985 return hr;
988 /* TODO: move to wineD3D */
989 static HRESULT WINAPI IDirect3DDevice9Impl_SetRenderTarget(LPDIRECT3DDEVICE9EX iface, DWORD RenderTargetIndex, IDirect3DSurface9* pRenderTarget) {
990 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
991 IDirect3DSurface9Impl *pSurface = (IDirect3DSurface9Impl*)pRenderTarget;
992 HRESULT hr;
993 TRACE("(%p) Relay\n" , This);
995 wined3d_mutex_lock();
996 hr = IWineD3DDevice_SetRenderTarget(This->WineD3DDevice, RenderTargetIndex, pSurface ? pSurface->wineD3DSurface : NULL);
997 wined3d_mutex_unlock();
999 return hr;
1002 static HRESULT WINAPI IDirect3DDevice9Impl_GetRenderTarget(LPDIRECT3DDEVICE9EX iface, DWORD RenderTargetIndex, IDirect3DSurface9 **ppRenderTarget) {
1003 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1004 IWineD3DSurface *pRenderTarget;
1005 HRESULT hr;
1007 TRACE("(%p) Relay\n" , This);
1009 if (ppRenderTarget == NULL) {
1010 return D3DERR_INVALIDCALL;
1013 wined3d_mutex_lock();
1015 hr=IWineD3DDevice_GetRenderTarget(This->WineD3DDevice,RenderTargetIndex,&pRenderTarget);
1017 if (FAILED(hr))
1019 FIXME("Call to IWineD3DDevice_GetRenderTarget failed, hr %#x\n", hr);
1021 else if (!pRenderTarget)
1023 *ppRenderTarget = NULL;
1025 else
1027 IWineD3DSurface_GetParent(pRenderTarget, (IUnknown **)ppRenderTarget);
1028 IWineD3DSurface_Release(pRenderTarget);
1031 wined3d_mutex_unlock();
1033 return hr;
1036 static HRESULT WINAPI IDirect3DDevice9Impl_SetDepthStencilSurface(LPDIRECT3DDEVICE9EX iface, IDirect3DSurface9* pZStencilSurface) {
1037 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1038 IDirect3DSurface9Impl *pSurface;
1039 HRESULT hr;
1040 TRACE("(%p) Relay\n" , This);
1042 pSurface = (IDirect3DSurface9Impl*)pZStencilSurface;
1044 wined3d_mutex_lock();
1045 hr = IWineD3DDevice_SetDepthStencilSurface(This->WineD3DDevice, NULL==pSurface ? NULL : pSurface->wineD3DSurface);
1046 wined3d_mutex_unlock();
1048 return hr;
1051 static HRESULT WINAPI IDirect3DDevice9Impl_GetDepthStencilSurface(LPDIRECT3DDEVICE9EX iface, IDirect3DSurface9 **ppZStencilSurface) {
1052 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1053 HRESULT hr = D3D_OK;
1054 IWineD3DSurface *pZStencilSurface;
1056 TRACE("(%p) Relay\n" , This);
1057 if(ppZStencilSurface == NULL){
1058 return D3DERR_INVALIDCALL;
1061 wined3d_mutex_lock();
1062 hr = IWineD3DDevice_GetDepthStencilSurface(This->WineD3DDevice,&pZStencilSurface);
1063 if (hr == WINED3D_OK) {
1064 IWineD3DSurface_GetParent(pZStencilSurface,(IUnknown**)ppZStencilSurface);
1065 IWineD3DSurface_Release(pZStencilSurface);
1066 } else {
1067 if (hr != WINED3DERR_NOTFOUND)
1068 WARN("Call to IWineD3DDevice_GetDepthStencilSurface failed with 0x%08x\n", hr);
1069 *ppZStencilSurface = NULL;
1071 wined3d_mutex_unlock();
1073 return hr;
1076 static HRESULT WINAPI IDirect3DDevice9Impl_BeginScene(LPDIRECT3DDEVICE9EX iface) {
1077 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1078 HRESULT hr;
1079 TRACE("(%p) Relay\n" , This);
1081 wined3d_mutex_lock();
1082 hr = IWineD3DDevice_BeginScene(This->WineD3DDevice);
1083 wined3d_mutex_unlock();
1085 return hr;
1088 static HRESULT WINAPI IDirect3DDevice9Impl_EndScene(LPDIRECT3DDEVICE9EX iface) {
1089 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1090 HRESULT hr;
1091 TRACE("(%p) Relay\n" , This);
1093 wined3d_mutex_lock();
1094 hr = IWineD3DDevice_EndScene(This->WineD3DDevice);
1095 wined3d_mutex_unlock();
1097 return hr;
1100 static HRESULT WINAPI IDirect3DDevice9Impl_Clear(LPDIRECT3DDEVICE9EX iface, DWORD Count, CONST D3DRECT* pRects, DWORD Flags, D3DCOLOR Color, float Z, DWORD Stencil) {
1101 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1102 HRESULT hr;
1103 TRACE("(%p) Relay\n" , This);
1105 /* Note: D3DRECT is compatible with WINED3DRECT */
1106 wined3d_mutex_lock();
1107 hr = IWineD3DDevice_Clear(This->WineD3DDevice, Count, (CONST WINED3DRECT*) pRects, Flags, Color, Z, Stencil);
1108 wined3d_mutex_unlock();
1110 return hr;
1113 static HRESULT WINAPI IDirect3DDevice9Impl_SetTransform(LPDIRECT3DDEVICE9EX iface, D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX* lpMatrix) {
1114 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1115 HRESULT hr;
1116 TRACE("(%p) Relay\n" , This);
1118 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1119 wined3d_mutex_lock();
1120 hr = IWineD3DDevice_SetTransform(This->WineD3DDevice, State, (CONST WINED3DMATRIX*) lpMatrix);
1121 wined3d_mutex_unlock();
1123 return hr;
1126 static HRESULT WINAPI IDirect3DDevice9Impl_GetTransform(LPDIRECT3DDEVICE9EX iface, D3DTRANSFORMSTATETYPE State, D3DMATRIX* pMatrix) {
1127 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1128 HRESULT hr;
1130 TRACE("(%p) Relay\n" , This);
1132 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1133 wined3d_mutex_lock();
1134 hr = IWineD3DDevice_GetTransform(This->WineD3DDevice, State, (WINED3DMATRIX*) pMatrix);
1135 wined3d_mutex_unlock();
1137 return hr;
1140 static HRESULT WINAPI IDirect3DDevice9Impl_MultiplyTransform(LPDIRECT3DDEVICE9EX iface, D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX* pMatrix) {
1141 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1142 HRESULT hr;
1143 TRACE("(%p) Relay\n" , This);
1145 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1146 wined3d_mutex_lock();
1147 hr = IWineD3DDevice_MultiplyTransform(This->WineD3DDevice, State, (CONST WINED3DMATRIX*) pMatrix);
1148 wined3d_mutex_unlock();
1150 return hr;
1153 static HRESULT WINAPI IDirect3DDevice9Impl_SetViewport(LPDIRECT3DDEVICE9EX iface, CONST D3DVIEWPORT9* pViewport) {
1154 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1155 HRESULT hr;
1156 TRACE("(%p) Relay\n" , This);
1158 /* Note: D3DVIEWPORT9 is compatible with WINED3DVIEWPORT */
1159 wined3d_mutex_lock();
1160 hr = IWineD3DDevice_SetViewport(This->WineD3DDevice, (const WINED3DVIEWPORT *)pViewport);
1161 wined3d_mutex_unlock();
1163 return hr;
1166 static HRESULT WINAPI IDirect3DDevice9Impl_GetViewport(LPDIRECT3DDEVICE9EX iface, D3DVIEWPORT9* pViewport) {
1167 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1168 HRESULT hr;
1169 TRACE("(%p) Relay\n" , This);
1171 /* Note: D3DVIEWPORT9 is compatible with WINED3DVIEWPORT */
1172 wined3d_mutex_lock();
1173 hr = IWineD3DDevice_GetViewport(This->WineD3DDevice, (WINED3DVIEWPORT *)pViewport);
1174 wined3d_mutex_unlock();
1176 return hr;
1179 static HRESULT WINAPI IDirect3DDevice9Impl_SetMaterial(LPDIRECT3DDEVICE9EX iface, CONST D3DMATERIAL9* pMaterial) {
1180 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1181 HRESULT hr;
1182 TRACE("(%p) Relay\n" , This);
1184 /* Note: D3DMATERIAL9 is compatible with WINED3DMATERIAL */
1185 wined3d_mutex_lock();
1186 hr = IWineD3DDevice_SetMaterial(This->WineD3DDevice, (const WINED3DMATERIAL *)pMaterial);
1187 wined3d_mutex_unlock();
1189 return hr;
1192 static HRESULT WINAPI IDirect3DDevice9Impl_GetMaterial(LPDIRECT3DDEVICE9EX iface, D3DMATERIAL9* pMaterial) {
1193 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1194 HRESULT hr;
1195 TRACE("(%p) Relay\n" , This);
1197 /* Note: D3DMATERIAL9 is compatible with WINED3DMATERIAL */
1198 wined3d_mutex_lock();
1199 hr = IWineD3DDevice_GetMaterial(This->WineD3DDevice, (WINED3DMATERIAL *)pMaterial);
1200 wined3d_mutex_unlock();
1202 return hr;
1205 static HRESULT WINAPI IDirect3DDevice9Impl_SetLight(LPDIRECT3DDEVICE9EX iface, DWORD Index, CONST D3DLIGHT9* pLight) {
1206 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1207 HRESULT hr;
1208 TRACE("(%p) Relay\n" , This);
1210 /* Note: D3DLIGHT9 is compatible with WINED3DLIGHT */
1211 wined3d_mutex_lock();
1212 hr = IWineD3DDevice_SetLight(This->WineD3DDevice, Index, (const WINED3DLIGHT *)pLight);
1213 wined3d_mutex_unlock();
1215 return hr;
1218 static HRESULT WINAPI IDirect3DDevice9Impl_GetLight(LPDIRECT3DDEVICE9EX iface, DWORD Index, D3DLIGHT9* pLight) {
1219 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1220 HRESULT hr;
1221 TRACE("(%p) Relay\n" , This);
1223 /* Note: D3DLIGHT9 is compatible with WINED3DLIGHT */
1224 wined3d_mutex_lock();
1225 hr = IWineD3DDevice_GetLight(This->WineD3DDevice, Index, (WINED3DLIGHT *)pLight);
1226 wined3d_mutex_unlock();
1228 return hr;
1231 static HRESULT WINAPI IDirect3DDevice9Impl_LightEnable(LPDIRECT3DDEVICE9EX iface, DWORD Index, BOOL Enable) {
1232 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1233 HRESULT hr;
1234 TRACE("(%p) Relay\n" , This);
1236 wined3d_mutex_lock();
1237 hr = IWineD3DDevice_SetLightEnable(This->WineD3DDevice, Index, Enable);
1238 wined3d_mutex_unlock();
1240 return hr;
1243 static HRESULT WINAPI IDirect3DDevice9Impl_GetLightEnable(LPDIRECT3DDEVICE9EX iface, DWORD Index, BOOL* pEnable) {
1244 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1245 HRESULT hr;
1246 TRACE("(%p) Relay\n" , This);
1248 wined3d_mutex_lock();
1249 hr = IWineD3DDevice_GetLightEnable(This->WineD3DDevice, Index, pEnable);
1250 wined3d_mutex_unlock();
1252 return hr;
1255 static HRESULT WINAPI IDirect3DDevice9Impl_SetClipPlane(LPDIRECT3DDEVICE9EX iface, DWORD Index, CONST float* pPlane) {
1256 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1257 HRESULT hr;
1258 TRACE("(%p) Relay\n" , This);
1260 wined3d_mutex_lock();
1261 hr = IWineD3DDevice_SetClipPlane(This->WineD3DDevice, Index, pPlane);
1262 wined3d_mutex_unlock();
1264 return hr;
1267 static HRESULT WINAPI IDirect3DDevice9Impl_GetClipPlane(LPDIRECT3DDEVICE9EX iface, DWORD Index, float* pPlane) {
1268 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1269 HRESULT hr;
1270 TRACE("(%p) Relay\n" , This);
1272 wined3d_mutex_lock();
1273 hr = IWineD3DDevice_GetClipPlane(This->WineD3DDevice, Index, pPlane);
1274 wined3d_mutex_unlock();
1276 return hr;
1279 static HRESULT WINAPI IDirect3DDevice9Impl_SetRenderState(LPDIRECT3DDEVICE9EX iface, D3DRENDERSTATETYPE State, DWORD Value) {
1280 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1281 HRESULT hr;
1282 TRACE("(%p) Relay\n" , This);
1284 wined3d_mutex_lock();
1285 hr = IWineD3DDevice_SetRenderState(This->WineD3DDevice, State, Value);
1286 wined3d_mutex_unlock();
1288 return hr;
1291 static HRESULT WINAPI IDirect3DDevice9Impl_GetRenderState(LPDIRECT3DDEVICE9EX iface, D3DRENDERSTATETYPE State, DWORD* pValue) {
1292 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1293 HRESULT hr;
1294 TRACE("(%p) Relay\n" , This);
1296 wined3d_mutex_lock();
1297 hr = IWineD3DDevice_GetRenderState(This->WineD3DDevice, State, pValue);
1298 wined3d_mutex_unlock();
1300 return hr;
1303 static HRESULT WINAPI IDirect3DDevice9Impl_SetClipStatus(LPDIRECT3DDEVICE9EX iface, CONST D3DCLIPSTATUS9* pClipStatus) {
1304 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1305 HRESULT hr;
1306 TRACE("(%p) Relay\n" , This);
1308 wined3d_mutex_lock();
1309 hr = IWineD3DDevice_SetClipStatus(This->WineD3DDevice, (const WINED3DCLIPSTATUS *)pClipStatus);
1310 wined3d_mutex_unlock();
1312 return hr;
1315 static HRESULT WINAPI IDirect3DDevice9Impl_GetClipStatus(LPDIRECT3DDEVICE9EX iface, D3DCLIPSTATUS9* pClipStatus) {
1316 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1317 HRESULT hr;
1318 TRACE("(%p) Relay\n" , This);
1320 wined3d_mutex_lock();
1321 hr = IWineD3DDevice_GetClipStatus(This->WineD3DDevice, (WINED3DCLIPSTATUS *)pClipStatus);
1322 wined3d_mutex_unlock();
1324 return hr;
1327 static HRESULT WINAPI IDirect3DDevice9Impl_GetTexture(LPDIRECT3DDEVICE9EX iface, DWORD Stage, IDirect3DBaseTexture9 **ppTexture) {
1328 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1329 IWineD3DBaseTexture *retTexture = NULL;
1330 HRESULT rc = D3D_OK;
1332 TRACE("(%p) Relay\n" , This);
1334 if(ppTexture == NULL){
1335 return D3DERR_INVALIDCALL;
1338 wined3d_mutex_lock();
1339 rc = IWineD3DDevice_GetTexture(This->WineD3DDevice, Stage, &retTexture);
1340 if (SUCCEEDED(rc) && NULL != retTexture) {
1341 IWineD3DBaseTexture_GetParent(retTexture, (IUnknown **)ppTexture);
1342 IWineD3DBaseTexture_Release(retTexture);
1343 } else {
1344 if(FAILED(rc)) {
1345 WARN("Call to get texture (%d) failed (%p)\n", Stage, retTexture);
1347 *ppTexture = NULL;
1349 wined3d_mutex_unlock();
1351 return rc;
1354 static HRESULT WINAPI IDirect3DDevice9Impl_SetTexture(LPDIRECT3DDEVICE9EX iface, DWORD Stage, IDirect3DBaseTexture9* pTexture) {
1355 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1356 HRESULT hr;
1357 TRACE("(%p) Relay %d %p\n" , This, Stage, pTexture);
1359 wined3d_mutex_lock();
1360 hr = IWineD3DDevice_SetTexture(This->WineD3DDevice, Stage,
1361 pTexture==NULL ? NULL:((IDirect3DBaseTexture9Impl *)pTexture)->wineD3DBaseTexture);
1362 wined3d_mutex_unlock();
1364 return hr;
1367 static const WINED3DTEXTURESTAGESTATETYPE tss_lookup[] =
1369 WINED3DTSS_FORCE_DWORD, /* 0, unused */
1370 WINED3DTSS_COLOROP, /* 1, D3DTSS_COLOROP */
1371 WINED3DTSS_COLORARG1, /* 2, D3DTSS_COLORARG1 */
1372 WINED3DTSS_COLORARG2, /* 3, D3DTSS_COLORARG2 */
1373 WINED3DTSS_ALPHAOP, /* 4, D3DTSS_ALPHAOP */
1374 WINED3DTSS_ALPHAARG1, /* 5, D3DTSS_ALPHAARG1 */
1375 WINED3DTSS_ALPHAARG2, /* 6, D3DTSS_ALPHAARG2 */
1376 WINED3DTSS_BUMPENVMAT00, /* 7, D3DTSS_BUMPENVMAT00 */
1377 WINED3DTSS_BUMPENVMAT01, /* 8, D3DTSS_BUMPENVMAT01 */
1378 WINED3DTSS_BUMPENVMAT10, /* 9, D3DTSS_BUMPENVMAT10 */
1379 WINED3DTSS_BUMPENVMAT11, /* 10, D3DTSS_BUMPENVMAT11 */
1380 WINED3DTSS_TEXCOORDINDEX, /* 11, D3DTSS_TEXCOORDINDEX */
1381 WINED3DTSS_FORCE_DWORD, /* 12, unused */
1382 WINED3DTSS_FORCE_DWORD, /* 13, unused */
1383 WINED3DTSS_FORCE_DWORD, /* 14, unused */
1384 WINED3DTSS_FORCE_DWORD, /* 15, unused */
1385 WINED3DTSS_FORCE_DWORD, /* 16, unused */
1386 WINED3DTSS_FORCE_DWORD, /* 17, unused */
1387 WINED3DTSS_FORCE_DWORD, /* 18, unused */
1388 WINED3DTSS_FORCE_DWORD, /* 19, unused */
1389 WINED3DTSS_FORCE_DWORD, /* 20, unused */
1390 WINED3DTSS_FORCE_DWORD, /* 21, unused */
1391 WINED3DTSS_BUMPENVLSCALE, /* 22, D3DTSS_BUMPENVLSCALE */
1392 WINED3DTSS_BUMPENVLOFFSET, /* 23, D3DTSS_BUMPENVLOFFSET */
1393 WINED3DTSS_TEXTURETRANSFORMFLAGS, /* 24, D3DTSS_TEXTURETRANSFORMFLAGS */
1394 WINED3DTSS_FORCE_DWORD, /* 25, unused */
1395 WINED3DTSS_COLORARG0, /* 26, D3DTSS_COLORARG0 */
1396 WINED3DTSS_ALPHAARG0, /* 27, D3DTSS_ALPHAARG0 */
1397 WINED3DTSS_RESULTARG, /* 28, D3DTSS_RESULTARG */
1398 WINED3DTSS_FORCE_DWORD, /* 29, unused */
1399 WINED3DTSS_FORCE_DWORD, /* 30, unused */
1400 WINED3DTSS_FORCE_DWORD, /* 31, unused */
1401 WINED3DTSS_CONSTANT, /* 32, D3DTSS_CONSTANT */
1404 static HRESULT WINAPI IDirect3DDevice9Impl_GetTextureStageState(LPDIRECT3DDEVICE9EX iface, DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD* pValue) {
1405 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1406 HRESULT hr;
1407 TRACE("(%p) Relay\n" , This);
1409 wined3d_mutex_lock();
1410 hr = IWineD3DDevice_GetTextureStageState(This->WineD3DDevice, Stage, tss_lookup[Type], pValue);
1411 wined3d_mutex_unlock();
1413 return hr;
1416 static HRESULT WINAPI IDirect3DDevice9Impl_SetTextureStageState(LPDIRECT3DDEVICE9EX iface, DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD Value) {
1417 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1418 HRESULT hr;
1419 TRACE("(%p) Relay\n" , This);
1421 wined3d_mutex_lock();
1422 hr = IWineD3DDevice_SetTextureStageState(This->WineD3DDevice, Stage, tss_lookup[Type], Value);
1423 wined3d_mutex_unlock();
1425 return hr;
1428 static HRESULT WINAPI IDirect3DDevice9Impl_GetSamplerState(IDirect3DDevice9Ex *iface, DWORD Sampler,
1429 D3DSAMPLERSTATETYPE Type, DWORD *pValue)
1431 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1432 HRESULT hr;
1433 TRACE("(%p) Relay\n" , This);
1435 wined3d_mutex_lock();
1436 hr = IWineD3DDevice_GetSamplerState(This->WineD3DDevice, Sampler, Type, pValue);
1437 wined3d_mutex_unlock();
1439 return hr;
1442 static HRESULT WINAPI IDirect3DDevice9Impl_SetSamplerState(LPDIRECT3DDEVICE9EX iface, DWORD Sampler, D3DSAMPLERSTATETYPE Type, DWORD Value) {
1443 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1444 HRESULT hr;
1445 TRACE("(%p) Relay\n" , This);
1447 wined3d_mutex_lock();
1448 hr = IWineD3DDevice_SetSamplerState(This->WineD3DDevice, Sampler, Type, Value);
1449 wined3d_mutex_unlock();
1451 return hr;
1454 static HRESULT WINAPI IDirect3DDevice9Impl_ValidateDevice(LPDIRECT3DDEVICE9EX iface, DWORD* pNumPasses) {
1455 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1456 HRESULT hr;
1457 TRACE("(%p) Relay\n" , This);
1459 wined3d_mutex_lock();
1460 hr = IWineD3DDevice_ValidateDevice(This->WineD3DDevice, pNumPasses);
1461 wined3d_mutex_unlock();
1463 return hr;
1466 static HRESULT WINAPI IDirect3DDevice9Impl_SetPaletteEntries(IDirect3DDevice9Ex *iface, UINT PaletteNumber,
1467 const PALETTEENTRY *pEntries)
1469 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1470 HRESULT hr;
1471 TRACE("(%p) Relay\n" , This);
1473 wined3d_mutex_lock();
1474 hr = IWineD3DDevice_SetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
1475 wined3d_mutex_unlock();
1477 return hr;
1480 static HRESULT WINAPI IDirect3DDevice9Impl_GetPaletteEntries(LPDIRECT3DDEVICE9EX iface, UINT PaletteNumber, PALETTEENTRY* pEntries) {
1481 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1482 HRESULT hr;
1483 TRACE("(%p) Relay\n" , This);
1485 wined3d_mutex_lock();
1486 hr = IWineD3DDevice_GetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
1487 wined3d_mutex_unlock();
1489 return hr;
1492 static HRESULT WINAPI IDirect3DDevice9Impl_SetCurrentTexturePalette(LPDIRECT3DDEVICE9EX iface, UINT PaletteNumber) {
1493 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1494 HRESULT hr;
1495 TRACE("(%p) Relay\n" , This);
1497 wined3d_mutex_lock();
1498 hr = IWineD3DDevice_SetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
1499 wined3d_mutex_unlock();
1501 return hr;
1504 static HRESULT WINAPI IDirect3DDevice9Impl_GetCurrentTexturePalette(LPDIRECT3DDEVICE9EX iface, UINT* PaletteNumber) {
1505 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1506 HRESULT hr;
1507 TRACE("(%p) Relay\n" , This);
1509 wined3d_mutex_lock();
1510 hr = IWineD3DDevice_GetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
1511 wined3d_mutex_unlock();
1513 return hr;
1516 static HRESULT WINAPI IDirect3DDevice9Impl_SetScissorRect(LPDIRECT3DDEVICE9EX iface, CONST RECT* pRect) {
1517 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1518 HRESULT hr;
1519 TRACE("(%p) Relay\n" , This);
1521 wined3d_mutex_lock();
1522 hr = IWineD3DDevice_SetScissorRect(This->WineD3DDevice, pRect);
1523 wined3d_mutex_unlock();
1525 return hr;
1528 static HRESULT WINAPI IDirect3DDevice9Impl_GetScissorRect(LPDIRECT3DDEVICE9EX iface, RECT* pRect) {
1529 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1530 HRESULT hr;
1531 TRACE("(%p) Relay\n" , This);
1533 wined3d_mutex_lock();
1534 hr = IWineD3DDevice_GetScissorRect(This->WineD3DDevice, pRect);
1535 wined3d_mutex_unlock();
1537 return hr;
1540 static HRESULT WINAPI IDirect3DDevice9Impl_SetSoftwareVertexProcessing(LPDIRECT3DDEVICE9EX iface, BOOL bSoftware) {
1541 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1542 HRESULT hr;
1543 TRACE("(%p) Relay\n" , This);
1545 wined3d_mutex_lock();
1546 hr = IWineD3DDevice_SetSoftwareVertexProcessing(This->WineD3DDevice, bSoftware);
1547 wined3d_mutex_unlock();
1549 return hr;
1552 static BOOL WINAPI IDirect3DDevice9Impl_GetSoftwareVertexProcessing(LPDIRECT3DDEVICE9EX iface) {
1553 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1554 BOOL ret;
1555 TRACE("(%p) Relay\n" , This);
1557 wined3d_mutex_lock();
1558 ret = IWineD3DDevice_GetSoftwareVertexProcessing(This->WineD3DDevice);
1559 wined3d_mutex_unlock();
1561 return ret;
1564 static HRESULT WINAPI IDirect3DDevice9Impl_SetNPatchMode(LPDIRECT3DDEVICE9EX iface, float nSegments) {
1565 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1566 HRESULT hr;
1567 TRACE("(%p) Relay\n" , This);
1569 wined3d_mutex_lock();
1570 hr = IWineD3DDevice_SetNPatchMode(This->WineD3DDevice, nSegments);
1571 wined3d_mutex_unlock();
1573 return hr;
1576 static float WINAPI IDirect3DDevice9Impl_GetNPatchMode(LPDIRECT3DDEVICE9EX iface) {
1577 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1578 float ret;
1579 TRACE("(%p) Relay\n" , This);
1581 wined3d_mutex_lock();
1582 ret = IWineD3DDevice_GetNPatchMode(This->WineD3DDevice);
1583 wined3d_mutex_unlock();
1585 return ret;
1588 static HRESULT WINAPI IDirect3DDevice9Impl_DrawPrimitive(IDirect3DDevice9Ex *iface, D3DPRIMITIVETYPE PrimitiveType,
1589 UINT StartVertex, UINT PrimitiveCount)
1591 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1592 HRESULT hr;
1593 TRACE("(%p) Relay\n" , This);
1595 wined3d_mutex_lock();
1596 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1597 hr = IWineD3DDevice_DrawPrimitive(This->WineD3DDevice, StartVertex,
1598 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount));
1599 wined3d_mutex_unlock();
1601 return hr;
1604 static HRESULT WINAPI IDirect3DDevice9Impl_DrawIndexedPrimitive(LPDIRECT3DDEVICE9EX iface, D3DPRIMITIVETYPE PrimitiveType,
1605 INT BaseVertexIndex, UINT MinVertexIndex, UINT NumVertices, UINT startIndex, UINT primCount) {
1606 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1607 HRESULT hr;
1608 TRACE("(%p) Relay\n" , This);
1610 /* D3D8 passes the baseVertexIndex in SetIndices, and due to the stateblock functions wined3d has to work that way */
1611 wined3d_mutex_lock();
1612 IWineD3DDevice_SetBaseVertexIndex(This->WineD3DDevice, BaseVertexIndex);
1613 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1614 hr = IWineD3DDevice_DrawIndexedPrimitive(This->WineD3DDevice, startIndex,
1615 vertex_count_from_primitive_count(PrimitiveType, primCount));
1616 wined3d_mutex_unlock();
1618 return hr;
1621 static HRESULT WINAPI IDirect3DDevice9Impl_DrawPrimitiveUP(IDirect3DDevice9Ex *iface, D3DPRIMITIVETYPE PrimitiveType,
1622 UINT PrimitiveCount, const void *pVertexStreamZeroData, UINT VertexStreamZeroStride)
1624 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1625 HRESULT hr;
1626 TRACE("(%p) Relay\n" , This);
1628 wined3d_mutex_lock();
1629 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1630 hr = IWineD3DDevice_DrawPrimitiveUP(This->WineD3DDevice,
1631 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount),
1632 pVertexStreamZeroData, VertexStreamZeroStride);
1633 wined3d_mutex_unlock();
1635 return hr;
1638 static HRESULT WINAPI IDirect3DDevice9Impl_DrawIndexedPrimitiveUP(LPDIRECT3DDEVICE9EX iface, D3DPRIMITIVETYPE PrimitiveType, UINT MinVertexIndex,
1639 UINT NumVertexIndices, UINT PrimitiveCount, CONST void* pIndexData,
1640 D3DFORMAT IndexDataFormat, CONST void* pVertexStreamZeroData, UINT VertexStreamZeroStride) {
1641 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1642 HRESULT hr;
1643 TRACE("(%p) Relay\n" , This);
1645 wined3d_mutex_lock();
1646 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1647 hr = IWineD3DDevice_DrawIndexedPrimitiveUP(This->WineD3DDevice,
1648 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount), pIndexData,
1649 wined3dformat_from_d3dformat(IndexDataFormat), pVertexStreamZeroData, VertexStreamZeroStride);
1650 wined3d_mutex_unlock();
1652 return hr;
1655 static HRESULT WINAPI IDirect3DDevice9Impl_ProcessVertices(LPDIRECT3DDEVICE9EX iface, UINT SrcStartIndex, UINT DestIndex, UINT VertexCount, IDirect3DVertexBuffer9* pDestBuffer, IDirect3DVertexDeclaration9* pVertexDecl, DWORD Flags) {
1656 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1657 IDirect3DVertexDeclaration9Impl *Decl = (IDirect3DVertexDeclaration9Impl *) pVertexDecl;
1658 HRESULT hr;
1659 IDirect3DVertexBuffer9Impl *dest = (IDirect3DVertexBuffer9Impl *) pDestBuffer;
1660 TRACE("(%p) Relay\n" , This);
1662 wined3d_mutex_lock();
1663 hr = IWineD3DDevice_ProcessVertices(This->WineD3DDevice,SrcStartIndex, DestIndex, VertexCount, dest->wineD3DVertexBuffer, Decl ? Decl->wineD3DVertexDeclaration : NULL, Flags, dest->fvf);
1664 wined3d_mutex_unlock();
1666 return hr;
1669 static IDirect3DVertexDeclaration9 *getConvertedDecl(IDirect3DDevice9Impl *This, DWORD fvf) {
1670 HRESULT hr;
1671 D3DVERTEXELEMENT9* elements = NULL;
1672 IDirect3DVertexDeclaration9* pDecl = NULL;
1673 int p, low, high; /* deliberately signed */
1674 IDirect3DVertexDeclaration9 **convertedDecls = This->convertedDecls;
1676 TRACE("Searching for declaration for fvf %08x... ", fvf);
1678 low = 0;
1679 high = This->numConvertedDecls - 1;
1680 while(low <= high) {
1681 p = (low + high) >> 1;
1682 TRACE("%d ", p);
1683 if(((IDirect3DVertexDeclaration9Impl *) convertedDecls[p])->convFVF == fvf) {
1684 TRACE("found %p\n", convertedDecls[p]);
1685 return convertedDecls[p];
1686 } else if(((IDirect3DVertexDeclaration9Impl *) convertedDecls[p])->convFVF < fvf) {
1687 low = p + 1;
1688 } else {
1689 high = p - 1;
1692 TRACE("not found. Creating and inserting at position %d.\n", low);
1694 hr = vdecl_convert_fvf(fvf, &elements);
1695 if (hr != S_OK) return NULL;
1697 hr = IDirect3DDevice9Impl_CreateVertexDeclaration((IDirect3DDevice9Ex *) This, elements, &pDecl);
1698 HeapFree(GetProcessHeap(), 0, elements); /* CreateVertexDeclaration makes a copy */
1699 if (hr != S_OK) return NULL;
1701 if(This->declArraySize == This->numConvertedDecls) {
1702 int grow = max(This->declArraySize / 2, 8);
1703 convertedDecls = HeapReAlloc(GetProcessHeap(), 0, convertedDecls,
1704 sizeof(convertedDecls[0]) * (This->numConvertedDecls + grow));
1705 if(!convertedDecls) {
1706 /* This will destroy it */
1707 IDirect3DVertexDeclaration9_Release(pDecl);
1708 return NULL;
1710 This->convertedDecls = convertedDecls;
1711 This->declArraySize += grow;
1714 memmove(convertedDecls + low + 1, convertedDecls + low, sizeof(IDirect3DVertexDeclaration9Impl *) * (This->numConvertedDecls - low));
1715 convertedDecls[low] = pDecl;
1716 This->numConvertedDecls++;
1718 /* Will prevent the decl from being destroyed */
1719 ((IDirect3DVertexDeclaration9Impl *) pDecl)->convFVF = fvf;
1720 IDirect3DVertexDeclaration9_Release(pDecl); /* Does not destroy now */
1722 TRACE("Returning %p. %d decls in array\n", pDecl, This->numConvertedDecls);
1723 return pDecl;
1726 static HRESULT WINAPI IDirect3DDevice9Impl_SetFVF(LPDIRECT3DDEVICE9EX iface, DWORD FVF) {
1727 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1728 IDirect3DVertexDeclaration9 *decl;
1729 HRESULT hr;
1731 TRACE("(%p) Relay\n" , This);
1733 if (!FVF)
1735 WARN("%#x is not a valid FVF\n", FVF);
1736 return D3D_OK;
1739 wined3d_mutex_lock();
1740 decl = getConvertedDecl(This, FVF);
1741 wined3d_mutex_unlock();
1743 if (!decl)
1745 /* Any situation when this should happen, except out of memory? */
1746 ERR("Failed to create a converted vertex declaration\n");
1747 return D3DERR_DRIVERINTERNALERROR;
1750 hr = IDirect3DDevice9Impl_SetVertexDeclaration(iface, decl);
1751 if (FAILED(hr)) ERR("Failed to set vertex declaration\n");
1753 return hr;
1756 static HRESULT WINAPI IDirect3DDevice9Impl_GetFVF(LPDIRECT3DDEVICE9EX iface, DWORD* pFVF) {
1757 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1758 IDirect3DVertexDeclaration9 *decl;
1759 HRESULT hr;
1760 TRACE("(%p) Relay\n" , This);
1762 hr = IDirect3DDevice9_GetVertexDeclaration(iface, &decl);
1763 if (FAILED(hr))
1765 WARN("Failed to get vertex declaration, %#x\n", hr);
1766 *pFVF = 0;
1767 return hr;
1770 if (decl)
1772 *pFVF = ((IDirect3DVertexDeclaration9Impl *)decl)->convFVF;
1773 IDirect3DVertexDeclaration9_Release(decl);
1775 else
1777 *pFVF = 0;
1780 TRACE("Returning FVF %#x\n", *pFVF);
1782 return hr;
1785 static HRESULT WINAPI IDirect3DDevice9Impl_SetStreamSource(LPDIRECT3DDEVICE9EX iface, UINT StreamNumber, IDirect3DVertexBuffer9* pStreamData, UINT OffsetInBytes, UINT Stride) {
1786 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1787 HRESULT hr;
1788 TRACE("(%p) Relay\n" , This);
1790 wined3d_mutex_lock();
1791 hr = IWineD3DDevice_SetStreamSource(This->WineD3DDevice, StreamNumber,
1792 pStreamData ? ((IDirect3DVertexBuffer9Impl *)pStreamData)->wineD3DVertexBuffer : NULL,
1793 OffsetInBytes, Stride);
1794 wined3d_mutex_unlock();
1796 return hr;
1799 static HRESULT WINAPI IDirect3DDevice9Impl_GetStreamSource(LPDIRECT3DDEVICE9EX iface, UINT StreamNumber, IDirect3DVertexBuffer9 **pStream, UINT* OffsetInBytes, UINT* pStride) {
1800 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1801 IWineD3DBuffer *retStream = NULL;
1802 HRESULT rc = D3D_OK;
1804 TRACE("(%p) Relay\n" , This);
1806 if(pStream == NULL){
1807 return D3DERR_INVALIDCALL;
1810 wined3d_mutex_lock();
1811 rc = IWineD3DDevice_GetStreamSource(This->WineD3DDevice, StreamNumber, &retStream, OffsetInBytes, pStride);
1812 if (rc == D3D_OK && NULL != retStream) {
1813 IWineD3DBuffer_GetParent(retStream, (IUnknown **)pStream);
1814 IWineD3DBuffer_Release(retStream);
1815 }else{
1816 if (rc != D3D_OK){
1817 FIXME("Call to GetStreamSource failed %p %p\n", OffsetInBytes, pStride);
1819 *pStream = NULL;
1821 wined3d_mutex_unlock();
1823 return rc;
1826 static HRESULT WINAPI IDirect3DDevice9Impl_SetStreamSourceFreq(IDirect3DDevice9Ex *iface, UINT StreamNumber,
1827 UINT Divider)
1829 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1830 HRESULT hr;
1831 TRACE("(%p) Relay\n" , This);
1833 wined3d_mutex_lock();
1834 hr = IWineD3DDevice_SetStreamSourceFreq(This->WineD3DDevice, StreamNumber, Divider);
1835 wined3d_mutex_unlock();
1837 return hr;
1840 static HRESULT WINAPI IDirect3DDevice9Impl_GetStreamSourceFreq(LPDIRECT3DDEVICE9EX iface, UINT StreamNumber, UINT* Divider) {
1841 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1842 HRESULT hr;
1843 TRACE("(%p) Relay\n" , This);
1845 wined3d_mutex_lock();
1846 hr = IWineD3DDevice_GetStreamSourceFreq(This->WineD3DDevice, StreamNumber, Divider);
1847 wined3d_mutex_unlock();
1849 return hr;
1852 static HRESULT WINAPI IDirect3DDevice9Impl_SetIndices(LPDIRECT3DDEVICE9EX iface, IDirect3DIndexBuffer9* pIndexData) {
1853 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1854 HRESULT hr;
1855 IDirect3DIndexBuffer9Impl *ib = (IDirect3DIndexBuffer9Impl *) pIndexData;
1856 TRACE("(%p) Relay\n", This);
1858 wined3d_mutex_lock();
1859 hr = IWineD3DDevice_SetIndices(This->WineD3DDevice,
1860 ib ? ib->wineD3DIndexBuffer : NULL,
1861 ib ? ib->format : WINED3DFMT_UNKNOWN);
1862 wined3d_mutex_unlock();
1864 return hr;
1867 static HRESULT WINAPI IDirect3DDevice9Impl_GetIndices(LPDIRECT3DDEVICE9EX iface, IDirect3DIndexBuffer9 **ppIndexData) {
1868 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1869 IWineD3DBuffer *retIndexData = NULL;
1870 HRESULT rc = D3D_OK;
1872 TRACE("(%p) Relay\n", This);
1874 if(ppIndexData == NULL){
1875 return D3DERR_INVALIDCALL;
1878 wined3d_mutex_lock();
1879 rc = IWineD3DDevice_GetIndices(This->WineD3DDevice, &retIndexData);
1880 if (SUCCEEDED(rc) && retIndexData) {
1881 IWineD3DBuffer_GetParent(retIndexData, (IUnknown **)ppIndexData);
1882 IWineD3DBuffer_Release(retIndexData);
1883 } else {
1884 if (FAILED(rc)) FIXME("Call to GetIndices failed\n");
1885 *ppIndexData = NULL;
1887 wined3d_mutex_unlock();
1889 return rc;
1892 static HRESULT WINAPI IDirect3DDevice9Impl_DrawRectPatch(LPDIRECT3DDEVICE9EX iface, UINT Handle, CONST float* pNumSegs, CONST D3DRECTPATCH_INFO* pRectPatchInfo) {
1893 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1894 HRESULT hr;
1895 TRACE("(%p) Relay\n", This);
1897 wined3d_mutex_lock();
1898 hr = IWineD3DDevice_DrawRectPatch(This->WineD3DDevice, Handle, pNumSegs, (CONST WINED3DRECTPATCH_INFO *)pRectPatchInfo);
1899 wined3d_mutex_unlock();
1901 return hr;
1904 static HRESULT WINAPI IDirect3DDevice9Impl_DrawTriPatch(LPDIRECT3DDEVICE9EX iface, UINT Handle, CONST float* pNumSegs, CONST D3DTRIPATCH_INFO* pTriPatchInfo) {
1905 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1906 HRESULT hr;
1907 TRACE("(%p) Relay\n", This);
1909 wined3d_mutex_lock();
1910 hr = IWineD3DDevice_DrawTriPatch(This->WineD3DDevice, Handle, pNumSegs, (CONST WINED3DTRIPATCH_INFO *)pTriPatchInfo);
1911 wined3d_mutex_unlock();
1913 return hr;
1916 static HRESULT WINAPI IDirect3DDevice9Impl_DeletePatch(LPDIRECT3DDEVICE9EX iface, UINT Handle) {
1917 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
1918 HRESULT hr;
1919 TRACE("(%p) Relay\n", This);
1921 wined3d_mutex_lock();
1922 hr = IWineD3DDevice_DeletePatch(This->WineD3DDevice, Handle);
1923 wined3d_mutex_unlock();
1925 return hr;
1928 static HRESULT WINAPI IDirect3DDevice9ExImpl_SetConvolutionMonoKernel(LPDIRECT3DDEVICE9EX iface, UINT width, UINT height, float *rows, float *columns) {
1929 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1930 FIXME("(%p)->(%d, %d, %p, %p) Stub!\n", This, width, height, rows, columns);
1931 return WINED3DERR_INVALIDCALL;
1934 static HRESULT WINAPI IDirect3DDevice9ExImpl_ComposeRects(LPDIRECT3DDEVICE9EX iface, IDirect3DSurface9 *pSrc, IDirect3DDevice9 *pDst, IDirect3DVertexBuffer9 *pSrcRectDescs, UINT NumRects, IDirect3DVertexBuffer9 *pDstRectDescs, D3DCOMPOSERECTSOP Operation, int Xoffset, int Yoffset) {
1935 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1936 FIXME("(%p)->(%p, %p, %p, %d, %p, %d, %d, %d) Stub!\n", This, pSrc, pDst, pSrcRectDescs, NumRects, pDstRectDescs, Operation, Xoffset, Yoffset);
1937 return WINED3DERR_INVALIDCALL;
1940 static HRESULT WINAPI IDirect3DDevice9ExImpl_PresentEx(LPDIRECT3DDEVICE9EX iface, CONST RECT *pSourceRect, CONST RECT *pDestRect, HWND hDestWindowOverride, CONST RGNDATA *pDirtyRegion, DWORD dwFlags) {
1941 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1942 FIXME("(%p= -> (%p), %p, %p, %p, 0x%08x) Stub!\n", This, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion, dwFlags);
1943 return WINED3DERR_INVALIDCALL;
1946 static HRESULT WINAPI IDirect3DDevice9ExImpl_GetGPUThreadPriority(LPDIRECT3DDEVICE9EX iface, INT *pPriority) {
1947 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1948 FIXME("(%p)->(%p) Stub!\n", This, pPriority);
1949 return WINED3DERR_INVALIDCALL;
1952 static HRESULT WINAPI IDirect3DDevice9ExImpl_SetGPUThreadPriority(LPDIRECT3DDEVICE9EX iface, INT Priority) {
1953 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1954 FIXME("(%p)->(%d) Stub!\n", This, Priority);
1955 return WINED3DERR_INVALIDCALL;
1958 static HRESULT WINAPI IDirect3DDevice9ExImpl_WaitForVBlank(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain) {
1959 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1960 FIXME("(%p)->(%d) Stub!\n", This, iSwapChain);
1961 return WINED3DERR_INVALIDCALL;
1964 static HRESULT WINAPI IDirect3DDevice9ExImpl_CheckresourceResidency(LPDIRECT3DDEVICE9EX iface, IDirect3DResource9 ** pResourceArray, UINT32 Numresources) {
1965 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1966 FIXME("(%p)->(%p, %d) Stub!\n", This, pResourceArray, Numresources);
1967 return WINED3DERR_INVALIDCALL;
1970 static HRESULT WINAPI IDirect3DDevice9ExImpl_SetMaximumFrameLatency(LPDIRECT3DDEVICE9EX iface, UINT MaxLatency) {
1971 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1972 FIXME("(%p)->(%d) Stub!\n", This, MaxLatency);
1973 return WINED3DERR_INVALIDCALL;
1976 static HRESULT WINAPI IDirect3DDevice9ExImpl_GetMaximumFrameLatency(LPDIRECT3DDEVICE9EX iface, UINT *pMaxLatency) {
1977 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1978 FIXME("(%p)->(%p) Stub!\n", This, pMaxLatency);
1979 *pMaxLatency = 2;
1980 return WINED3DERR_INVALIDCALL;
1983 static HRESULT WINAPI IDirect3DDevice9ExImpl_CheckdeviceState(LPDIRECT3DDEVICE9EX iface, HWND hDestinationWindow) {
1984 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1985 FIXME("(%p)->(%p) Stub!\n", This, hDestinationWindow);
1986 return WINED3DERR_INVALIDCALL;
1989 static HRESULT WINAPI IDirect3DDevice9ExImpl_CreateRenderTargetEx(LPDIRECT3DDEVICE9EX iface, UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultiSampleQuality, BOOL Lockable, IDirect3DSurface9 ** ppSurface, HANDLE *pSharedHandle, DWORD Usage) {
1990 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1991 FIXME("(%p)->(%d, %d, %d, %d, %d, %s, %p, %p, 0x%08x) Stub!\n", This, Width, Height, Format, MultiSample, MultiSampleQuality, Lockable ? "true" : "false", ppSurface, pSharedHandle, Usage);
1992 return WINED3DERR_INVALIDCALL;
1995 static HRESULT WINAPI IDirect3DDevice9ExImpl_CreateOffscreenPlainSurfaceEx(LPDIRECT3DDEVICE9EX iface, UINT Width, UINT Height, D3DFORMAT Format, D3DPOOL Pool, IDirect3DSurface9 **ppSurface, HANDLE *pSharedHandle, DWORD Usage) {
1996 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
1997 FIXME("(%p)->(%d, %d, %d, %d, %p, %p, 0x%08x) Stub!\n", This, Width, Height, Format, Pool, ppSurface, pSharedHandle, Usage);
1998 return WINED3DERR_INVALIDCALL;
2001 static HRESULT WINAPI IDirect3DDevice9ExImpl_CreateDepthStencilSurfaceEx(LPDIRECT3DDEVICE9EX iface, UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultiSampleQuality, BOOL Discard, IDirect3DSurface9 **ppSurface, HANDLE *pSharedHandle, DWORD Usage) {
2002 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
2003 FIXME("(%p)->(%d, %d, %d, %d, %d, %s, %p, %p, 0x%08x) Stub!\n", This, Width, Height, Format, MultiSample, MultiSampleQuality, Discard ? "true" : "false", ppSurface, pSharedHandle, Usage);
2004 return WINED3DERR_INVALIDCALL;
2007 static HRESULT WINAPI IDirect3DDevice9ExImpl_ResetEx(LPDIRECT3DDEVICE9EX iface, D3DPRESENT_PARAMETERS *pPresentationParameters, D3DDISPLAYMODEEX *pFullscreenDisplayMode) {
2008 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
2009 FIXME("(%p)->(%p) Stub!\n", This, pPresentationParameters);
2010 return WINED3DERR_INVALIDCALL;
2013 static HRESULT WINAPI IDirect3DDevice9ExImpl_GetDisplayModeEx(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain, D3DDISPLAYMODEEX *pMode, D3DDISPLAYROTATION *pRotation) {
2014 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *) iface;
2015 FIXME("(%p)->(%d, %p, %p) Stub!\n", This, iSwapChain, pMode, pRotation);
2016 return WINED3DERR_INVALIDCALL;
2019 const IDirect3DDevice9ExVtbl Direct3DDevice9_Vtbl =
2021 /* IUnknown */
2022 IDirect3DDevice9Impl_QueryInterface,
2023 IDirect3DDevice9Impl_AddRef,
2024 IDirect3DDevice9Impl_Release,
2025 /* IDirect3DDevice9 */
2026 IDirect3DDevice9Impl_TestCooperativeLevel,
2027 IDirect3DDevice9Impl_GetAvailableTextureMem,
2028 IDirect3DDevice9Impl_EvictManagedResources,
2029 IDirect3DDevice9Impl_GetDirect3D,
2030 IDirect3DDevice9Impl_GetDeviceCaps,
2031 IDirect3DDevice9Impl_GetDisplayMode,
2032 IDirect3DDevice9Impl_GetCreationParameters,
2033 IDirect3DDevice9Impl_SetCursorProperties,
2034 IDirect3DDevice9Impl_SetCursorPosition,
2035 IDirect3DDevice9Impl_ShowCursor,
2036 IDirect3DDevice9Impl_CreateAdditionalSwapChain,
2037 IDirect3DDevice9Impl_GetSwapChain,
2038 IDirect3DDevice9Impl_GetNumberOfSwapChains,
2039 IDirect3DDevice9Impl_Reset,
2040 IDirect3DDevice9Impl_Present,
2041 IDirect3DDevice9Impl_GetBackBuffer,
2042 IDirect3DDevice9Impl_GetRasterStatus,
2043 IDirect3DDevice9Impl_SetDialogBoxMode,
2044 IDirect3DDevice9Impl_SetGammaRamp,
2045 IDirect3DDevice9Impl_GetGammaRamp,
2046 IDirect3DDevice9Impl_CreateTexture,
2047 IDirect3DDevice9Impl_CreateVolumeTexture,
2048 IDirect3DDevice9Impl_CreateCubeTexture,
2049 IDirect3DDevice9Impl_CreateVertexBuffer,
2050 IDirect3DDevice9Impl_CreateIndexBuffer,
2051 IDirect3DDevice9Impl_CreateRenderTarget,
2052 IDirect3DDevice9Impl_CreateDepthStencilSurface,
2053 IDirect3DDevice9Impl_UpdateSurface,
2054 IDirect3DDevice9Impl_UpdateTexture,
2055 IDirect3DDevice9Impl_GetRenderTargetData,
2056 IDirect3DDevice9Impl_GetFrontBufferData,
2057 IDirect3DDevice9Impl_StretchRect,
2058 IDirect3DDevice9Impl_ColorFill,
2059 IDirect3DDevice9Impl_CreateOffscreenPlainSurface,
2060 IDirect3DDevice9Impl_SetRenderTarget,
2061 IDirect3DDevice9Impl_GetRenderTarget,
2062 IDirect3DDevice9Impl_SetDepthStencilSurface,
2063 IDirect3DDevice9Impl_GetDepthStencilSurface,
2064 IDirect3DDevice9Impl_BeginScene,
2065 IDirect3DDevice9Impl_EndScene,
2066 IDirect3DDevice9Impl_Clear,
2067 IDirect3DDevice9Impl_SetTransform,
2068 IDirect3DDevice9Impl_GetTransform,
2069 IDirect3DDevice9Impl_MultiplyTransform,
2070 IDirect3DDevice9Impl_SetViewport,
2071 IDirect3DDevice9Impl_GetViewport,
2072 IDirect3DDevice9Impl_SetMaterial,
2073 IDirect3DDevice9Impl_GetMaterial,
2074 IDirect3DDevice9Impl_SetLight,
2075 IDirect3DDevice9Impl_GetLight,
2076 IDirect3DDevice9Impl_LightEnable,
2077 IDirect3DDevice9Impl_GetLightEnable,
2078 IDirect3DDevice9Impl_SetClipPlane,
2079 IDirect3DDevice9Impl_GetClipPlane,
2080 IDirect3DDevice9Impl_SetRenderState,
2081 IDirect3DDevice9Impl_GetRenderState,
2082 IDirect3DDevice9Impl_CreateStateBlock,
2083 IDirect3DDevice9Impl_BeginStateBlock,
2084 IDirect3DDevice9Impl_EndStateBlock,
2085 IDirect3DDevice9Impl_SetClipStatus,
2086 IDirect3DDevice9Impl_GetClipStatus,
2087 IDirect3DDevice9Impl_GetTexture,
2088 IDirect3DDevice9Impl_SetTexture,
2089 IDirect3DDevice9Impl_GetTextureStageState,
2090 IDirect3DDevice9Impl_SetTextureStageState,
2091 IDirect3DDevice9Impl_GetSamplerState,
2092 IDirect3DDevice9Impl_SetSamplerState,
2093 IDirect3DDevice9Impl_ValidateDevice,
2094 IDirect3DDevice9Impl_SetPaletteEntries,
2095 IDirect3DDevice9Impl_GetPaletteEntries,
2096 IDirect3DDevice9Impl_SetCurrentTexturePalette,
2097 IDirect3DDevice9Impl_GetCurrentTexturePalette,
2098 IDirect3DDevice9Impl_SetScissorRect,
2099 IDirect3DDevice9Impl_GetScissorRect,
2100 IDirect3DDevice9Impl_SetSoftwareVertexProcessing,
2101 IDirect3DDevice9Impl_GetSoftwareVertexProcessing,
2102 IDirect3DDevice9Impl_SetNPatchMode,
2103 IDirect3DDevice9Impl_GetNPatchMode,
2104 IDirect3DDevice9Impl_DrawPrimitive,
2105 IDirect3DDevice9Impl_DrawIndexedPrimitive,
2106 IDirect3DDevice9Impl_DrawPrimitiveUP,
2107 IDirect3DDevice9Impl_DrawIndexedPrimitiveUP,
2108 IDirect3DDevice9Impl_ProcessVertices,
2109 IDirect3DDevice9Impl_CreateVertexDeclaration,
2110 IDirect3DDevice9Impl_SetVertexDeclaration,
2111 IDirect3DDevice9Impl_GetVertexDeclaration,
2112 IDirect3DDevice9Impl_SetFVF,
2113 IDirect3DDevice9Impl_GetFVF,
2114 IDirect3DDevice9Impl_CreateVertexShader,
2115 IDirect3DDevice9Impl_SetVertexShader,
2116 IDirect3DDevice9Impl_GetVertexShader,
2117 IDirect3DDevice9Impl_SetVertexShaderConstantF,
2118 IDirect3DDevice9Impl_GetVertexShaderConstantF,
2119 IDirect3DDevice9Impl_SetVertexShaderConstantI,
2120 IDirect3DDevice9Impl_GetVertexShaderConstantI,
2121 IDirect3DDevice9Impl_SetVertexShaderConstantB,
2122 IDirect3DDevice9Impl_GetVertexShaderConstantB,
2123 IDirect3DDevice9Impl_SetStreamSource,
2124 IDirect3DDevice9Impl_GetStreamSource,
2125 IDirect3DDevice9Impl_SetStreamSourceFreq,
2126 IDirect3DDevice9Impl_GetStreamSourceFreq,
2127 IDirect3DDevice9Impl_SetIndices,
2128 IDirect3DDevice9Impl_GetIndices,
2129 IDirect3DDevice9Impl_CreatePixelShader,
2130 IDirect3DDevice9Impl_SetPixelShader,
2131 IDirect3DDevice9Impl_GetPixelShader,
2132 IDirect3DDevice9Impl_SetPixelShaderConstantF,
2133 IDirect3DDevice9Impl_GetPixelShaderConstantF,
2134 IDirect3DDevice9Impl_SetPixelShaderConstantI,
2135 IDirect3DDevice9Impl_GetPixelShaderConstantI,
2136 IDirect3DDevice9Impl_SetPixelShaderConstantB,
2137 IDirect3DDevice9Impl_GetPixelShaderConstantB,
2138 IDirect3DDevice9Impl_DrawRectPatch,
2139 IDirect3DDevice9Impl_DrawTriPatch,
2140 IDirect3DDevice9Impl_DeletePatch,
2141 IDirect3DDevice9Impl_CreateQuery,
2142 /* IDirect3DDevice9Ex */
2143 IDirect3DDevice9ExImpl_SetConvolutionMonoKernel,
2144 IDirect3DDevice9ExImpl_ComposeRects,
2145 IDirect3DDevice9ExImpl_PresentEx,
2146 IDirect3DDevice9ExImpl_GetGPUThreadPriority,
2147 IDirect3DDevice9ExImpl_SetGPUThreadPriority,
2148 IDirect3DDevice9ExImpl_WaitForVBlank,
2149 IDirect3DDevice9ExImpl_CheckresourceResidency,
2150 IDirect3DDevice9ExImpl_SetMaximumFrameLatency,
2151 IDirect3DDevice9ExImpl_GetMaximumFrameLatency,
2152 IDirect3DDevice9ExImpl_CheckdeviceState,
2153 IDirect3DDevice9ExImpl_CreateRenderTargetEx,
2154 IDirect3DDevice9ExImpl_CreateOffscreenPlainSurfaceEx,
2155 IDirect3DDevice9ExImpl_CreateDepthStencilSurfaceEx,
2156 IDirect3DDevice9ExImpl_ResetEx,
2157 IDirect3DDevice9ExImpl_GetDisplayModeEx
2160 /* IWineD3DDeviceParent IUnknown methods */
2162 static inline struct IDirect3DDevice9Impl *device_from_device_parent(IWineD3DDeviceParent *iface)
2164 return (struct IDirect3DDevice9Impl *)((char*)iface
2165 - FIELD_OFFSET(struct IDirect3DDevice9Impl, device_parent_vtbl));
2168 static HRESULT STDMETHODCALLTYPE device_parent_QueryInterface(IWineD3DDeviceParent *iface, REFIID riid, void **object)
2170 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
2171 return IDirect3DDevice9Impl_QueryInterface((IDirect3DDevice9Ex *)This, riid, object);
2174 static ULONG STDMETHODCALLTYPE device_parent_AddRef(IWineD3DDeviceParent *iface)
2176 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
2177 return IDirect3DDevice9Impl_AddRef((IDirect3DDevice9Ex *)This);
2180 static ULONG STDMETHODCALLTYPE device_parent_Release(IWineD3DDeviceParent *iface)
2182 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
2183 return IDirect3DDevice9Impl_Release((IDirect3DDevice9Ex *)This);
2186 /* IWineD3DDeviceParent methods */
2188 static void STDMETHODCALLTYPE device_parent_WineD3DDeviceCreated(IWineD3DDeviceParent *iface, IWineD3DDevice *device)
2190 TRACE("iface %p, device %p\n", iface, device);
2193 static HRESULT STDMETHODCALLTYPE device_parent_CreateSurface(IWineD3DDeviceParent *iface,
2194 IUnknown *superior, UINT width, UINT height, WINED3DFORMAT format, DWORD usage,
2195 WINED3DPOOL pool, UINT level, WINED3DCUBEMAP_FACES face, IWineD3DSurface **surface)
2197 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
2198 IDirect3DSurface9Impl *d3d_surface;
2199 BOOL lockable = TRUE;
2200 HRESULT hr;
2202 TRACE("iface %p, superior %p, width %u, height %u, format %#x, usage %#x,\n"
2203 "\tpool %#x, level %u, face %u, surface %p\n",
2204 iface, superior, width, height, format, usage, pool, level, face, surface);
2206 if (pool == WINED3DPOOL_DEFAULT && !(usage & D3DUSAGE_DYNAMIC))
2207 lockable = FALSE;
2209 hr = IDirect3DDevice9Impl_CreateSurface((IDirect3DDevice9Ex *)This, width, height,
2210 d3dformat_from_wined3dformat(format), lockable, FALSE /* Discard */, level,
2211 (IDirect3DSurface9 **)&d3d_surface, usage, pool, D3DMULTISAMPLE_NONE, 0 /* MultisampleQuality */);
2212 if (FAILED(hr))
2214 ERR("(%p) CreateSurface failed, returning %#x\n", iface, hr);
2215 return hr;
2218 *surface = d3d_surface->wineD3DSurface;
2219 IWineD3DSurface_AddRef(*surface);
2221 d3d_surface->container = superior;
2222 IDirect3DDevice9Ex_Release(d3d_surface->parentDevice);
2223 d3d_surface->parentDevice = NULL;
2225 IDirect3DSurface9_Release((IDirect3DSurface9 *)d3d_surface);
2226 d3d_surface->forwardReference = superior;
2228 return hr;
2231 static HRESULT STDMETHODCALLTYPE device_parent_CreateRenderTarget(IWineD3DDeviceParent *iface,
2232 IUnknown *superior, UINT width, UINT height, WINED3DFORMAT format, WINED3DMULTISAMPLE_TYPE multisample_type,
2233 DWORD multisample_quality, BOOL lockable, IWineD3DSurface **surface)
2235 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
2236 IDirect3DSurface9Impl *d3d_surface;
2237 HRESULT hr;
2239 TRACE("iface %p, superior %p, width %u, height %u, format %#x, multisample_type %#x,\n"
2240 "\tmultisample_quality %u, lockable %u, surface %p\n",
2241 iface, superior, width, height, format, multisample_type, multisample_quality, lockable, surface);
2243 hr = IDirect3DDevice9Impl_CreateRenderTarget((IDirect3DDevice9Ex *)This, width, height,
2244 d3dformat_from_wined3dformat(format), multisample_type, multisample_quality, lockable,
2245 (IDirect3DSurface9 **)&d3d_surface, NULL);
2246 if (FAILED(hr))
2248 ERR("(%p) CreateRenderTarget failed, returning %#x\n", iface, hr);
2249 return hr;
2252 *surface = d3d_surface->wineD3DSurface;
2253 IWineD3DSurface_AddRef(*surface);
2255 d3d_surface->container = superior;
2256 /* Implicit surfaces are created with an refcount of 0 */
2257 IDirect3DSurface9_Release((IDirect3DSurface9 *)d3d_surface);
2259 return hr;
2262 static HRESULT STDMETHODCALLTYPE device_parent_CreateDepthStencilSurface(IWineD3DDeviceParent *iface,
2263 IUnknown *superior, UINT width, UINT height, WINED3DFORMAT format, WINED3DMULTISAMPLE_TYPE multisample_type,
2264 DWORD multisample_quality, BOOL discard, IWineD3DSurface **surface)
2266 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
2267 IDirect3DSurface9Impl *d3d_surface;
2268 HRESULT hr;
2270 TRACE("iface %p, superior %p, width %u, height %u, format %#x, multisample_type %#x,\n"
2271 "\tmultisample_quality %u, discard %u, surface %p\n",
2272 iface, superior, width, height, format, multisample_type, multisample_quality, discard, surface);
2274 hr = IDirect3DDevice9Impl_CreateDepthStencilSurface((IDirect3DDevice9Ex *)This, width, height,
2275 d3dformat_from_wined3dformat(format), multisample_type, multisample_quality, discard,
2276 (IDirect3DSurface9 **)&d3d_surface, NULL);
2277 if (FAILED(hr))
2279 ERR("(%p) CreateDepthStencilSurface failed, returning %#x\n", iface, hr);
2280 return hr;
2283 *surface = d3d_surface->wineD3DSurface;
2284 IWineD3DSurface_AddRef(*surface);
2285 d3d_surface->container = (IUnknown *)This;
2286 /* Implicit surfaces are created with an refcount of 0 */
2287 IDirect3DSurface9_Release((IDirect3DSurface9 *)d3d_surface);
2289 return hr;
2292 static HRESULT STDMETHODCALLTYPE device_parent_CreateVolume(IWineD3DDeviceParent *iface,
2293 IUnknown *superior, UINT width, UINT height, UINT depth, WINED3DFORMAT format,
2294 WINED3DPOOL pool, DWORD usage, IWineD3DVolume **volume)
2296 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
2297 IDirect3DVolume9Impl *object;
2298 HRESULT hr;
2300 TRACE("iface %p, superior %p, width %u, height %u, depth %u, format %#x, pool %#x, usage %#x, volume %p\n",
2301 iface, superior, width, height, depth, format, pool, usage, volume);
2303 /* Allocate the storage for the device */
2304 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2305 if (!object)
2307 FIXME("Allocation of memory failed\n");
2308 *volume = NULL;
2309 return D3DERR_OUTOFVIDEOMEMORY;
2312 hr = volume_init(object, This, width, height, depth, usage, format, pool);
2313 if (FAILED(hr))
2315 WARN("Failed to initialize volume, hr %#x.\n", hr);
2316 HeapFree(GetProcessHeap(), 0, object);
2317 return hr;
2320 *volume = object->wineD3DVolume;
2321 IWineD3DVolume_AddRef(*volume);
2322 IDirect3DVolume9_Release((IDirect3DVolume9 *)object);
2324 object->container = superior;
2325 object->forwardReference = superior;
2327 TRACE("(%p) Created volume %p\n", iface, object);
2329 return hr;
2332 static HRESULT STDMETHODCALLTYPE device_parent_CreateSwapChain(IWineD3DDeviceParent *iface,
2333 WINED3DPRESENT_PARAMETERS *present_parameters, IWineD3DSwapChain **swapchain)
2335 struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
2336 IDirect3DSwapChain9Impl *d3d_swapchain;
2337 D3DPRESENT_PARAMETERS local_parameters;
2338 HRESULT hr;
2340 TRACE("iface %p, present_parameters %p, swapchain %p\n", iface, present_parameters, swapchain);
2342 /* Copy the presentation parameters */
2343 local_parameters.BackBufferWidth = present_parameters->BackBufferWidth;
2344 local_parameters.BackBufferHeight = present_parameters->BackBufferHeight;
2345 local_parameters.BackBufferFormat = d3dformat_from_wined3dformat(present_parameters->BackBufferFormat);
2346 local_parameters.BackBufferCount = present_parameters->BackBufferCount;
2347 local_parameters.MultiSampleType = present_parameters->MultiSampleType;
2348 local_parameters.MultiSampleQuality = present_parameters->MultiSampleQuality;
2349 local_parameters.SwapEffect = present_parameters->SwapEffect;
2350 local_parameters.hDeviceWindow = present_parameters->hDeviceWindow;
2351 local_parameters.Windowed = present_parameters->Windowed;
2352 local_parameters.EnableAutoDepthStencil = present_parameters->EnableAutoDepthStencil;
2353 local_parameters.AutoDepthStencilFormat = d3dformat_from_wined3dformat(present_parameters->AutoDepthStencilFormat);
2354 local_parameters.Flags = present_parameters->Flags;
2355 local_parameters.FullScreen_RefreshRateInHz = present_parameters->FullScreen_RefreshRateInHz;
2356 local_parameters.PresentationInterval = present_parameters->PresentationInterval;
2358 hr = IDirect3DDevice9Impl_CreateAdditionalSwapChain((IDirect3DDevice9Ex *)This,
2359 &local_parameters, (IDirect3DSwapChain9 **)&d3d_swapchain);
2360 if (FAILED(hr))
2362 ERR("(%p) CreateAdditionalSwapChain failed, returning %#x\n", iface, hr);
2363 *swapchain = NULL;
2364 return hr;
2367 *swapchain = d3d_swapchain->wineD3DSwapChain;
2368 d3d_swapchain->isImplicit = TRUE;
2369 /* Implicit swap chains are created with an refcount of 0 */
2370 IDirect3DSwapChain9_Release((IDirect3DSwapChain9 *)d3d_swapchain);
2372 /* Copy back the presentation parameters */
2373 present_parameters->BackBufferWidth = local_parameters.BackBufferWidth;
2374 present_parameters->BackBufferHeight = local_parameters.BackBufferHeight;
2375 present_parameters->BackBufferFormat = wined3dformat_from_d3dformat(local_parameters.BackBufferFormat);
2376 present_parameters->BackBufferCount = local_parameters.BackBufferCount;
2377 present_parameters->MultiSampleType = local_parameters.MultiSampleType;
2378 present_parameters->MultiSampleQuality = local_parameters.MultiSampleQuality;
2379 present_parameters->SwapEffect = local_parameters.SwapEffect;
2380 present_parameters->hDeviceWindow = local_parameters.hDeviceWindow;
2381 present_parameters->Windowed = local_parameters.Windowed;
2382 present_parameters->EnableAutoDepthStencil = local_parameters.EnableAutoDepthStencil;
2383 present_parameters->AutoDepthStencilFormat = wined3dformat_from_d3dformat(local_parameters.AutoDepthStencilFormat);
2384 present_parameters->Flags = local_parameters.Flags;
2385 present_parameters->FullScreen_RefreshRateInHz = local_parameters.FullScreen_RefreshRateInHz;
2386 present_parameters->PresentationInterval = local_parameters.PresentationInterval;
2388 return hr;
2391 const IWineD3DDeviceParentVtbl d3d9_wined3d_device_parent_vtbl =
2393 /* IUnknown methods */
2394 device_parent_QueryInterface,
2395 device_parent_AddRef,
2396 device_parent_Release,
2397 /* IWineD3DDeviceParent methods */
2398 device_parent_WineD3DDeviceCreated,
2399 device_parent_CreateSurface,
2400 device_parent_CreateRenderTarget,
2401 device_parent_CreateDepthStencilSurface,
2402 device_parent_CreateVolume,
2403 device_parent_CreateSwapChain,