VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/directx.c@ 20612

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

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

  • Property svn:eol-style set to native
File size: 25.1 KB
Line 
1/*
2 * IDirect3D9 implementation
3 *
4 * Copyright 2002 Jason Edmeades
5 * Copyright 2005 Oliver Stieber
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 */
21
22/*
23 * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
24 * other than GPL or LGPL is available it will apply instead, Sun elects to use only
25 * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
26 * a choice of LGPL license versions is made available with the language indicating
27 * that LGPLv2 or any later version may be used, or where a choice of which version
28 * of the LGPL is applied is otherwise unspecified.
29 */
30
31#include "config.h"
32#include "d3d9_private.h"
33
34WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
35
36/* IDirect3D9 IUnknown parts follow: */
37static HRESULT WINAPI IDirect3D9Impl_QueryInterface(LPDIRECT3D9EX iface, REFIID riid, LPVOID* ppobj)
38{
39 IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
40
41 if (IsEqualGUID(riid, &IID_IUnknown)
42 || IsEqualGUID(riid, &IID_IDirect3D9)) {
43 IDirect3D9Ex_AddRef(iface);
44 *ppobj = This;
45 TRACE("Returning IDirect3D9 interface at %p\n", *ppobj);
46 return S_OK;
47 } else if(IsEqualGUID(riid, &IID_IDirect3D9Ex)) {
48 if(This->extended) {
49 *ppobj = This;
50 TRACE("Returning IDirect3D9Ex interface at %p\n", *ppobj);
51 IDirect3D9Ex_AddRef((IDirect3D9Ex *)*ppobj);
52 } else {
53 WARN("Application asks for IDirect3D9Ex, but this instance wasn't created with Direct3DCreate9Ex\n");
54 WARN("Returning E_NOINTERFACE\n");
55 *ppobj = NULL;
56 return E_NOINTERFACE;
57 }
58 }
59
60 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
61 *ppobj = NULL;
62 return E_NOINTERFACE;
63}
64
65static ULONG WINAPI IDirect3D9Impl_AddRef(LPDIRECT3D9EX iface) {
66 IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
67 ULONG ref = InterlockedIncrement(&This->ref);
68
69 TRACE("(%p) : AddRef from %d\n", This, ref - 1);
70
71 return ref;
72}
73
74static ULONG WINAPI IDirect3D9Impl_Release(LPDIRECT3D9EX iface) {
75 IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
76 ULONG ref = InterlockedDecrement(&This->ref);
77
78 TRACE("(%p) : ReleaseRef to %d\n", This, ref);
79
80 if (ref == 0) {
81 EnterCriticalSection(&d3d9_cs);
82 IWineD3D_Release(This->WineD3D);
83 LeaveCriticalSection(&d3d9_cs);
84 HeapFree(GetProcessHeap(), 0, This);
85 }
86
87 return ref;
88}
89
90/* IDirect3D9 Interface follow: */
91static HRESULT WINAPI IDirect3D9Impl_RegisterSoftwareDevice(LPDIRECT3D9EX iface, void* pInitializeFunction) {
92 IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
93 HRESULT hr;
94 TRACE("(%p)->(%p)\n", This, pInitializeFunction);
95
96 EnterCriticalSection(&d3d9_cs);
97 hr = IWineD3D_RegisterSoftwareDevice(This->WineD3D, pInitializeFunction);
98 LeaveCriticalSection(&d3d9_cs);
99 return hr;
100}
101
102static UINT WINAPI IDirect3D9Impl_GetAdapterCount(LPDIRECT3D9EX iface) {
103 IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
104 HRESULT hr;
105 TRACE("%p\n", This);
106
107 EnterCriticalSection(&d3d9_cs);
108 hr = IWineD3D_GetAdapterCount(This->WineD3D);
109 LeaveCriticalSection(&d3d9_cs);
110 return hr;
111}
112
113static HRESULT WINAPI IDirect3D9Impl_GetAdapterIdentifier(LPDIRECT3D9EX iface, UINT Adapter, DWORD Flags, D3DADAPTER_IDENTIFIER9* pIdentifier) {
114 IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
115 WINED3DADAPTER_IDENTIFIER adapter_id;
116 HRESULT hr;
117
118 /* dx8 and dx9 have different structures to be filled in, with incompatible
119 layouts so pass in pointers to the places to be filled via an internal
120 structure */
121 adapter_id.Driver = pIdentifier->Driver;
122 adapter_id.Description = pIdentifier->Description;
123 adapter_id.DeviceName = pIdentifier->DeviceName;
124 adapter_id.DriverVersion = &pIdentifier->DriverVersion;
125 adapter_id.VendorId = &pIdentifier->VendorId;
126 adapter_id.DeviceId = &pIdentifier->DeviceId;
127 adapter_id.SubSysId = &pIdentifier->SubSysId;
128 adapter_id.Revision = &pIdentifier->Revision;
129 adapter_id.DeviceIdentifier = &pIdentifier->DeviceIdentifier;
130 adapter_id.WHQLLevel = &pIdentifier->WHQLLevel;
131
132 EnterCriticalSection(&d3d9_cs);
133 hr = IWineD3D_GetAdapterIdentifier(This->WineD3D, Adapter, Flags, &adapter_id);
134 LeaveCriticalSection(&d3d9_cs);
135 return hr;
136}
137
138static UINT WINAPI IDirect3D9Impl_GetAdapterModeCount(LPDIRECT3D9EX iface, UINT Adapter, D3DFORMAT Format) {
139 IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
140 HRESULT hr;
141 TRACE("(%p)->(%d, %d\n", This, Adapter, Format);
142
143 /* Others than that not supported by d3d9, but reported by wined3d for ddraw. Filter them out */
144 if(Format != D3DFMT_X8R8G8B8 && Format != D3DFMT_R5G6B5) {
145 return 0;
146 }
147
148 EnterCriticalSection(&d3d9_cs);
149 hr = IWineD3D_GetAdapterModeCount(This->WineD3D, Adapter, wined3dformat_from_d3dformat(Format));
150 LeaveCriticalSection(&d3d9_cs);
151 return hr;
152}
153
154static HRESULT WINAPI IDirect3D9Impl_EnumAdapterModes(LPDIRECT3D9EX iface, UINT Adapter, D3DFORMAT Format, UINT Mode, D3DDISPLAYMODE* pMode) {
155 IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
156 HRESULT hr;
157 TRACE("(%p)->(%d, %d, %d, %p)\n", This, Adapter, Format, Mode, pMode);
158 /* We can't pass this to WineD3D, otherwise it'll think it came from D3D8 or DDraw.
159 It's supposed to fail anyway, so no harm returning failure. */
160 if(Format != D3DFMT_X8R8G8B8 && Format != D3DFMT_R5G6B5)
161 return D3DERR_INVALIDCALL;
162
163 EnterCriticalSection(&d3d9_cs);
164 hr = IWineD3D_EnumAdapterModes(This->WineD3D, Adapter, wined3dformat_from_d3dformat(Format),
165 Mode, (WINED3DDISPLAYMODE *) pMode);
166 LeaveCriticalSection(&d3d9_cs);
167
168 if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format);
169
170 return hr;
171}
172
173static HRESULT WINAPI IDirect3D9Impl_GetAdapterDisplayMode(LPDIRECT3D9EX iface, UINT Adapter, D3DDISPLAYMODE* pMode) {
174 IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
175 HRESULT hr;
176
177 EnterCriticalSection(&d3d9_cs);
178 hr = IWineD3D_GetAdapterDisplayMode(This->WineD3D, Adapter, (WINED3DDISPLAYMODE *) pMode);
179 LeaveCriticalSection(&d3d9_cs);
180
181 if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format);
182
183 return hr;
184}
185
186static HRESULT WINAPI IDirect3D9Impl_CheckDeviceType(LPDIRECT3D9EX iface,
187 UINT Adapter, D3DDEVTYPE CheckType, D3DFORMAT DisplayFormat,
188 D3DFORMAT BackBufferFormat, BOOL Windowed) {
189 IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
190 HRESULT hr;
191 TRACE("(%p)->(%d, %d, %d, %d, %s\n", This, Adapter, CheckType, DisplayFormat,
192 BackBufferFormat, Windowed ? "true" : "false");
193
194 EnterCriticalSection(&d3d9_cs);
195 hr = IWineD3D_CheckDeviceType(This->WineD3D, Adapter, CheckType, wined3dformat_from_d3dformat(DisplayFormat),
196 wined3dformat_from_d3dformat(BackBufferFormat), Windowed);
197 LeaveCriticalSection(&d3d9_cs);
198 return hr;
199}
200
201static HRESULT WINAPI IDirect3D9Impl_CheckDeviceFormat(LPDIRECT3D9EX iface,
202 UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat,
203 DWORD Usage, D3DRESOURCETYPE RType, D3DFORMAT CheckFormat) {
204 IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
205 HRESULT hr;
206 WINED3DRESOURCETYPE WineD3DRType;
207 TRACE("%p\n", This);
208
209 switch(RType) {
210 case D3DRTYPE_VERTEXBUFFER:
211 case D3DRTYPE_INDEXBUFFER:
212 WineD3DRType = WINED3DRTYPE_BUFFER;
213 break;
214
215 default:
216 WineD3DRType = RType;
217 break;
218 }
219
220 EnterCriticalSection(&d3d9_cs);
221 hr = IWineD3D_CheckDeviceFormat(This->WineD3D, Adapter, DeviceType, wined3dformat_from_d3dformat(AdapterFormat),
222 Usage, WineD3DRType, wined3dformat_from_d3dformat(CheckFormat), SURFACE_OPENGL);
223 LeaveCriticalSection(&d3d9_cs);
224 return hr;
225}
226
227static HRESULT WINAPI IDirect3D9Impl_CheckDeviceMultiSampleType(LPDIRECT3D9EX iface,
228 UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT SurfaceFormat,
229 BOOL Windowed, D3DMULTISAMPLE_TYPE MultiSampleType, DWORD* pQualityLevels) {
230 IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
231 HRESULT hr;
232 TRACE("%p\n", This);
233
234 EnterCriticalSection(&d3d9_cs);
235 hr = IWineD3D_CheckDeviceMultiSampleType(This->WineD3D, Adapter, DeviceType,
236 wined3dformat_from_d3dformat(SurfaceFormat), Windowed, MultiSampleType, pQualityLevels);
237 LeaveCriticalSection(&d3d9_cs);
238 return hr;
239}
240
241static HRESULT WINAPI IDirect3D9Impl_CheckDepthStencilMatch(LPDIRECT3D9EX iface,
242 UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat,
243 D3DFORMAT RenderTargetFormat, D3DFORMAT DepthStencilFormat) {
244 IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
245 HRESULT hr;
246 TRACE("%p\n", This);
247
248 EnterCriticalSection(&d3d9_cs);
249 hr = IWineD3D_CheckDepthStencilMatch(This->WineD3D, Adapter, DeviceType,
250 wined3dformat_from_d3dformat(AdapterFormat), wined3dformat_from_d3dformat(RenderTargetFormat),
251 wined3dformat_from_d3dformat(DepthStencilFormat));
252 LeaveCriticalSection(&d3d9_cs);
253 return hr;
254}
255
256static HRESULT WINAPI IDirect3D9Impl_CheckDeviceFormatConversion(LPDIRECT3D9EX iface, UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT SourceFormat, D3DFORMAT TargetFormat) {
257 IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
258 HRESULT hr;
259 TRACE("%p\n", This);
260
261 EnterCriticalSection(&d3d9_cs);
262 hr = IWineD3D_CheckDeviceFormatConversion(This->WineD3D, Adapter, DeviceType,
263 wined3dformat_from_d3dformat(SourceFormat), wined3dformat_from_d3dformat(TargetFormat));
264 LeaveCriticalSection(&d3d9_cs);
265 return hr;
266}
267
268void filter_caps(D3DCAPS9* pCaps)
269{
270
271 DWORD textureFilterCaps =
272 D3DPTFILTERCAPS_MINFPOINT | D3DPTFILTERCAPS_MINFLINEAR | D3DPTFILTERCAPS_MINFANISOTROPIC |
273 D3DPTFILTERCAPS_MINFPYRAMIDALQUAD | D3DPTFILTERCAPS_MINFGAUSSIANQUAD|
274 D3DPTFILTERCAPS_MIPFPOINT | D3DPTFILTERCAPS_MIPFLINEAR | D3DPTFILTERCAPS_MAGFPOINT |
275 D3DPTFILTERCAPS_MAGFLINEAR |D3DPTFILTERCAPS_MAGFANISOTROPIC|D3DPTFILTERCAPS_MAGFPYRAMIDALQUAD|
276 D3DPTFILTERCAPS_MAGFGAUSSIANQUAD;
277 pCaps->TextureFilterCaps &= textureFilterCaps;
278 pCaps->CubeTextureFilterCaps &= textureFilterCaps;
279 pCaps->VolumeTextureFilterCaps &= textureFilterCaps;
280
281 pCaps->DevCaps &=
282 D3DDEVCAPS_EXECUTESYSTEMMEMORY | D3DDEVCAPS_EXECUTEVIDEOMEMORY | D3DDEVCAPS_TLVERTEXSYSTEMMEMORY |
283 D3DDEVCAPS_TLVERTEXVIDEOMEMORY | D3DDEVCAPS_TEXTURESYSTEMMEMORY| D3DDEVCAPS_TEXTUREVIDEOMEMORY |
284 D3DDEVCAPS_DRAWPRIMTLVERTEX | D3DDEVCAPS_CANRENDERAFTERFLIP | D3DDEVCAPS_TEXTURENONLOCALVIDMEM|
285 D3DDEVCAPS_DRAWPRIMITIVES2 | D3DDEVCAPS_SEPARATETEXTUREMEMORIES |
286 D3DDEVCAPS_DRAWPRIMITIVES2EX | D3DDEVCAPS_HWTRANSFORMANDLIGHT| D3DDEVCAPS_CANBLTSYSTONONLOCAL |
287 D3DDEVCAPS_HWRASTERIZATION | D3DDEVCAPS_PUREDEVICE | D3DDEVCAPS_QUINTICRTPATCHES |
288 D3DDEVCAPS_RTPATCHES | D3DDEVCAPS_RTPATCHHANDLEZERO | D3DDEVCAPS_NPATCHES;
289
290 pCaps->ShadeCaps &=
291 D3DPSHADECAPS_COLORGOURAUDRGB | D3DPSHADECAPS_SPECULARGOURAUDRGB |
292 D3DPSHADECAPS_ALPHAGOURAUDBLEND | D3DPSHADECAPS_FOGGOURAUD;
293
294 pCaps->RasterCaps &=
295 D3DPRASTERCAPS_DITHER | D3DPRASTERCAPS_ZTEST | D3DPRASTERCAPS_FOGVERTEX |
296 D3DPRASTERCAPS_FOGTABLE | D3DPRASTERCAPS_MIPMAPLODBIAS | D3DPRASTERCAPS_ZBUFFERLESSHSR |
297 D3DPRASTERCAPS_FOGRANGE | D3DPRASTERCAPS_ANISOTROPY | D3DPRASTERCAPS_WBUFFER |
298 D3DPRASTERCAPS_WFOG | D3DPRASTERCAPS_ZFOG | D3DPRASTERCAPS_COLORPERSPECTIVE |
299 D3DPRASTERCAPS_SCISSORTEST | D3DPRASTERCAPS_SLOPESCALEDEPTHBIAS |
300 D3DPRASTERCAPS_DEPTHBIAS | D3DPRASTERCAPS_MULTISAMPLE_TOGGLE;
301
302 pCaps->DevCaps2 &=
303 D3DDEVCAPS2_STREAMOFFSET | D3DDEVCAPS2_DMAPNPATCH | D3DDEVCAPS2_ADAPTIVETESSRTPATCH |
304 D3DDEVCAPS2_ADAPTIVETESSNPATCH | D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES |
305 D3DDEVCAPS2_PRESAMPLEDDMAPNPATCH| D3DDEVCAPS2_VERTEXELEMENTSCANSHARESTREAMOFFSET;
306
307 pCaps->Caps2 &=
308 D3DCAPS2_FULLSCREENGAMMA | D3DCAPS2_CANCALIBRATEGAMMA | D3DCAPS2_RESERVED |
309 D3DCAPS2_CANMANAGERESOURCE | D3DCAPS2_DYNAMICTEXTURES | D3DCAPS2_CANAUTOGENMIPMAP;
310
311 pCaps->VertexProcessingCaps &=
312 D3DVTXPCAPS_TEXGEN | D3DVTXPCAPS_MATERIALSOURCE7 | D3DVTXPCAPS_DIRECTIONALLIGHTS |
313 D3DVTXPCAPS_POSITIONALLIGHTS | D3DVTXPCAPS_LOCALVIEWER | D3DVTXPCAPS_TWEENING |
314 D3DVTXPCAPS_TEXGEN_SPHEREMAP | D3DVTXPCAPS_NO_TEXGEN_NONLOCALVIEWER;
315
316 pCaps->TextureCaps &=
317 D3DPTEXTURECAPS_PERSPECTIVE | D3DPTEXTURECAPS_POW2 | D3DPTEXTURECAPS_ALPHA |
318 D3DPTEXTURECAPS_SQUAREONLY | D3DPTEXTURECAPS_TEXREPEATNOTSCALEDBYSIZE |
319 D3DPTEXTURECAPS_ALPHAPALETTE | D3DPTEXTURECAPS_NONPOW2CONDITIONAL |
320 D3DPTEXTURECAPS_PROJECTED | D3DPTEXTURECAPS_CUBEMAP | D3DPTEXTURECAPS_VOLUMEMAP |
321 D3DPTEXTURECAPS_MIPMAP | D3DPTEXTURECAPS_MIPVOLUMEMAP | D3DPTEXTURECAPS_MIPCUBEMAP |
322 D3DPTEXTURECAPS_CUBEMAP_POW2 | D3DPTEXTURECAPS_VOLUMEMAP_POW2| D3DPTEXTURECAPS_NOPROJECTEDBUMPENV;
323
324 pCaps->MaxVertexShaderConst = min(D3D9_MAX_VERTEX_SHADER_CONSTANTF, pCaps->MaxVertexShaderConst);
325}
326
327static HRESULT WINAPI IDirect3D9Impl_GetDeviceCaps(LPDIRECT3D9EX iface, UINT Adapter, D3DDEVTYPE DeviceType, D3DCAPS9* pCaps) {
328 IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
329 HRESULT hrc = D3D_OK;
330 WINED3DCAPS *pWineCaps;
331
332 TRACE("(%p) Relay %d %u %p\n", This, Adapter, DeviceType, pCaps);
333
334 if(NULL == pCaps){
335 return D3DERR_INVALIDCALL;
336 }
337 pWineCaps = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WINED3DCAPS));
338 if(pWineCaps == NULL){
339 return D3DERR_INVALIDCALL; /*well this is what MSDN says to return*/
340 }
341 memset(pCaps, 0, sizeof(*pCaps));
342 EnterCriticalSection(&d3d9_cs);
343 hrc = IWineD3D_GetDeviceCaps(This->WineD3D, Adapter, DeviceType, pWineCaps);
344 LeaveCriticalSection(&d3d9_cs);
345 WINECAPSTOD3D9CAPS(pCaps, pWineCaps)
346 HeapFree(GetProcessHeap(), 0, pWineCaps);
347
348 /* Some functionality is implemented in d3d9.dll, not wined3d.dll. Add the needed caps */
349 pCaps->DevCaps2 |= D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES;
350
351 filter_caps(pCaps);
352
353 TRACE("(%p) returning %p\n", This, pCaps);
354 return hrc;
355}
356
357static HMONITOR WINAPI IDirect3D9Impl_GetAdapterMonitor(LPDIRECT3D9EX iface, UINT Adapter) {
358 IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
359 HMONITOR ret;
360 TRACE("%p\n", This);
361
362 EnterCriticalSection(&d3d9_cs);
363 ret = IWineD3D_GetAdapterMonitor(This->WineD3D, Adapter);
364 LeaveCriticalSection(&d3d9_cs);
365 return ret;
366}
367
368ULONG WINAPI D3D9CB_DestroyRenderTarget(IWineD3DSurface *pSurface) {
369 IDirect3DSurface9Impl* surfaceParent;
370 TRACE("(%p) call back\n", pSurface);
371
372 IWineD3DSurface_GetParent(pSurface, (IUnknown **) &surfaceParent);
373 surfaceParent->isImplicit = FALSE;
374 /* Surface had refcount of 0 GetParent addrefed to 1, so 1 Release is enough */
375 return IDirect3DSurface9_Release((IDirect3DSurface9*) surfaceParent);
376}
377
378ULONG WINAPI D3D9CB_DestroySwapChain(IWineD3DSwapChain *pSwapChain) {
379 IDirect3DSwapChain9Impl* swapChainParent;
380 TRACE("(%p) call back\n", pSwapChain);
381
382 IWineD3DSwapChain_GetParent(pSwapChain,(IUnknown **) &swapChainParent);
383 swapChainParent->isImplicit = FALSE;
384 /* Swap chain had refcount of 0 GetParent addrefed to 1, so 1 Release is enough */
385 return IDirect3DSwapChain9_Release((IDirect3DSwapChain9*) swapChainParent);
386}
387
388ULONG WINAPI D3D9CB_DestroyDepthStencilSurface(IWineD3DSurface *pSurface) {
389 IDirect3DSurface9Impl* surfaceParent;
390 TRACE("(%p) call back\n", pSurface);
391
392 IWineD3DSurface_GetParent(pSurface, (IUnknown **) &surfaceParent);
393 surfaceParent->isImplicit = FALSE;
394 /* Surface had refcount of 0 GetParent addrefed to 1, so 1 Release is enough */
395 return IDirect3DSurface9_Release((IDirect3DSurface9*) surfaceParent);
396}
397
398static HRESULT WINAPI IDirect3D9Impl_CreateDevice(LPDIRECT3D9EX iface, UINT Adapter, D3DDEVTYPE DeviceType,
399 HWND hFocusWindow, DWORD BehaviourFlags,
400 D3DPRESENT_PARAMETERS* pPresentationParameters,
401 IDirect3DDevice9** ppReturnedDeviceInterface) {
402
403 IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
404 IDirect3DDevice9Impl *object = NULL;
405 WINED3DPRESENT_PARAMETERS *localParameters;
406 UINT i, count = 1;
407 HRESULT hr;
408 TRACE("(%p) Relay\n", This);
409
410 /* Check the validity range of the adapter parameter */
411 if (Adapter >= IDirect3D9Impl_GetAdapterCount(iface)) {
412 *ppReturnedDeviceInterface = NULL;
413 return D3DERR_INVALIDCALL;
414 }
415
416 /* Allocate the storage for the device object */
417 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DDevice9Impl));
418 if (NULL == object) {
419 FIXME("Allocation of memory failed\n");
420 *ppReturnedDeviceInterface = NULL;
421 return D3DERR_OUTOFVIDEOMEMORY;
422 }
423
424 object->lpVtbl = &Direct3DDevice9_Vtbl;
425 object->device_parent_vtbl = &d3d9_wined3d_device_parent_vtbl;
426 object->ref = 1;
427 *ppReturnedDeviceInterface = (IDirect3DDevice9 *)object;
428
429 /* Allocate an associated WineD3DDevice object */
430 EnterCriticalSection(&d3d9_cs);
431 hr = IWineD3D_CreateDevice(This->WineD3D, Adapter, DeviceType, hFocusWindow, BehaviourFlags,
432 (IUnknown *)object, (IWineD3DDeviceParent *)&object->device_parent_vtbl, &object->WineD3DDevice);
433 if (hr != D3D_OK) {
434 HeapFree(GetProcessHeap(), 0, object);
435 *ppReturnedDeviceInterface = NULL;
436 LeaveCriticalSection(&d3d9_cs);
437 return hr;
438 }
439
440 TRACE("(%p) : Created Device %p\n", This, object);
441
442 if (BehaviourFlags & D3DCREATE_ADAPTERGROUP_DEVICE)
443 {
444 WINED3DCAPS caps;
445
446 IWineD3D_GetDeviceCaps(This->WineD3D, Adapter, DeviceType, &caps);
447 count = caps.NumberOfAdaptersInGroup;
448 }
449
450 if(BehaviourFlags & D3DCREATE_MULTITHREADED) {
451 IWineD3DDevice_SetMultithreaded(object->WineD3DDevice);
452 }
453
454 localParameters = HeapAlloc(GetProcessHeap(), 0, sizeof(*localParameters) * count);
455 for (i = 0; i < count; ++i)
456 {
457 localParameters[i].BackBufferWidth = pPresentationParameters[i].BackBufferWidth;
458 localParameters[i].BackBufferHeight = pPresentationParameters[i].BackBufferHeight;
459 localParameters[i].BackBufferFormat = wined3dformat_from_d3dformat(pPresentationParameters[i].BackBufferFormat);
460 localParameters[i].BackBufferCount = pPresentationParameters[i].BackBufferCount;
461 localParameters[i].MultiSampleType = pPresentationParameters[i].MultiSampleType;
462 localParameters[i].MultiSampleQuality = pPresentationParameters[i].MultiSampleQuality;
463 localParameters[i].SwapEffect = pPresentationParameters[i].SwapEffect;
464 localParameters[i].hDeviceWindow = pPresentationParameters[i].hDeviceWindow;
465 localParameters[i].Windowed = pPresentationParameters[i].Windowed;
466 localParameters[i].EnableAutoDepthStencil = pPresentationParameters[i].EnableAutoDepthStencil;
467 localParameters[i].AutoDepthStencilFormat = wined3dformat_from_d3dformat(pPresentationParameters[i].AutoDepthStencilFormat);
468 localParameters[i].Flags = pPresentationParameters[i].Flags;
469 localParameters[i].FullScreen_RefreshRateInHz = pPresentationParameters[i].FullScreen_RefreshRateInHz;
470 localParameters[i].PresentationInterval = pPresentationParameters[i].PresentationInterval;
471 localParameters[i].AutoRestoreDisplayMode = TRUE;
472 }
473
474 hr = IWineD3DDevice_Init3D(object->WineD3DDevice, localParameters);
475 if (hr != D3D_OK) {
476 FIXME("(%p) D3D Initialization failed for WineD3DDevice %p\n", This, object->WineD3DDevice);
477 HeapFree(GetProcessHeap(), 0, object);
478 *ppReturnedDeviceInterface = NULL;
479 }
480
481 for (i = 0; i < count; ++i)
482 {
483 pPresentationParameters[i].BackBufferWidth = localParameters[i].BackBufferWidth;
484 pPresentationParameters[i].BackBufferHeight = localParameters[i].BackBufferHeight;
485 pPresentationParameters[i].BackBufferFormat = d3dformat_from_wined3dformat(localParameters[i].BackBufferFormat);
486 pPresentationParameters[i].BackBufferCount = localParameters[i].BackBufferCount;
487 pPresentationParameters[i].MultiSampleType = localParameters[i].MultiSampleType;
488 pPresentationParameters[i].MultiSampleQuality = localParameters[i].MultiSampleQuality;
489 pPresentationParameters[i].SwapEffect = localParameters[i].SwapEffect;
490 pPresentationParameters[i].hDeviceWindow = localParameters[i].hDeviceWindow;
491 pPresentationParameters[i].Windowed = localParameters[i].Windowed;
492 pPresentationParameters[i].EnableAutoDepthStencil = localParameters[i].EnableAutoDepthStencil;
493 pPresentationParameters[i].AutoDepthStencilFormat = d3dformat_from_wined3dformat(localParameters[i].AutoDepthStencilFormat);
494 pPresentationParameters[i].Flags = localParameters[i].Flags;
495 pPresentationParameters[i].FullScreen_RefreshRateInHz = localParameters[i].FullScreen_RefreshRateInHz;
496 pPresentationParameters[i].PresentationInterval = localParameters[i].PresentationInterval;
497 }
498 HeapFree(GetProcessHeap(), 0, localParameters);
499
500 /* Initialize the converted declaration array. This creates a valid pointer and when adding decls HeapReAlloc
501 * can be used without further checking
502 */
503 object->convertedDecls = HeapAlloc(GetProcessHeap(), 0, 0);
504 LeaveCriticalSection(&d3d9_cs);
505
506 return hr;
507}
508
509static UINT WINAPI IDirect3D9ExImpl_GetAdapterModeCountEx(IDirect3D9Ex *iface, UINT Adapter, CONST D3DDISPLAYMODEFILTER *pFilter) {
510 IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
511 FIXME("(%p)->(%d, %p): Stub!\n", This, Adapter, pFilter);
512 return D3DERR_DRIVERINTERNALERROR;
513}
514
515static HRESULT WINAPI IDirect3D9ExImpl_EnumAdapterModesEx(IDirect3D9Ex *iface, UINT Adapter, CONST D3DDISPLAYMODEFILTER *pFilter, UINT Mode, D3DDISPLAYMODEEX* pMode) {
516 IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
517 FIXME("(%p)->(%d, %p, %p): Stub!\n", This, Adapter, pFilter, pMode);
518 return D3DERR_DRIVERINTERNALERROR;
519}
520
521static HRESULT WINAPI IDirect3D9ExImpl_GetAdapterDisplayModeEx(IDirect3D9Ex *iface, UINT Adapter, D3DDISPLAYMODEEX *pMode, D3DDISPLAYROTATION *pRotation) {
522 IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
523 FIXME("(%p)->(%d, %p, %p): Stub!\n", This, Adapter, pMode, pRotation);
524 return D3DERR_DRIVERINTERNALERROR;
525}
526
527static HRESULT WINAPI IDirect3D9ExImpl_CreateDeviceEx(IDirect3D9Ex *iface, UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD BehaviorFlags, D3DPRESENT_PARAMETERS* pPresentationParameters, D3DDISPLAYMODEEX* pFullscreenDisplayMode, struct IDirect3DDevice9Ex **ppReturnedDeviceInterface) {
528 IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
529 FIXME("(%p)->(%d, %d, %p, 0x%08x, %p, %p, %p): Stub!\n", This, Adapter, DeviceType, hFocusWindow, BehaviorFlags, pPresentationParameters, pFullscreenDisplayMode, ppReturnedDeviceInterface);
530 *ppReturnedDeviceInterface = NULL;
531 return D3DERR_DRIVERINTERNALERROR;
532}
533
534static HRESULT WINAPI IDirect3D9ExImpl_GetAdapterLUID(IDirect3D9Ex *iface, UINT Adapter, LUID *pLUID) {
535 IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
536 FIXME("(%p)->(%d, %p)\n", This, Adapter, pLUID);
537 return D3DERR_DRIVERINTERNALERROR;
538}
539
540
541const IDirect3D9ExVtbl Direct3D9_Vtbl =
542{
543 /* IUnknown */
544 IDirect3D9Impl_QueryInterface,
545 IDirect3D9Impl_AddRef,
546 IDirect3D9Impl_Release,
547 /* IDirect3D9 */
548 IDirect3D9Impl_RegisterSoftwareDevice,
549 IDirect3D9Impl_GetAdapterCount,
550 IDirect3D9Impl_GetAdapterIdentifier,
551 IDirect3D9Impl_GetAdapterModeCount,
552 IDirect3D9Impl_EnumAdapterModes,
553 IDirect3D9Impl_GetAdapterDisplayMode,
554 IDirect3D9Impl_CheckDeviceType,
555 IDirect3D9Impl_CheckDeviceFormat,
556 IDirect3D9Impl_CheckDeviceMultiSampleType,
557 IDirect3D9Impl_CheckDepthStencilMatch,
558 IDirect3D9Impl_CheckDeviceFormatConversion,
559 IDirect3D9Impl_GetDeviceCaps,
560 IDirect3D9Impl_GetAdapterMonitor,
561 IDirect3D9Impl_CreateDevice,
562 /* IDirect3D9Ex */
563 IDirect3D9ExImpl_GetAdapterModeCountEx,
564 IDirect3D9ExImpl_EnumAdapterModesEx,
565 IDirect3D9ExImpl_GetAdapterDisplayModeEx,
566 IDirect3D9ExImpl_CreateDeviceEx,
567 IDirect3D9ExImpl_GetAdapterLUID
568
569};
Note: See TracBrowser for help on using the repository browser.

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