VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/directx.c@ 40986

Last change on this file since 40986 was 38982, checked in by vboxsync, 14 years ago

wddm: proper ie rendering under win8 (shared resource open & destroy fixes, zero-init resources on creaate, etc.)

  • Property svn:eol-style set to native
File size: 13.4 KB
Line 
1/*
2 * IDirect3D8 implementation
3 *
4 * Copyright 2002-2004 Jason Edmeades
5 * Copyright 2003-2004 Raphael Junqueira
6 * Copyright 2004 Christian Costa
7 *
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.
12 *
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.
17 *
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
21 */
22
23/*
24 * Oracle LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
25 * other than GPL or LGPL is available it will apply instead, Oracle elects to use only
26 * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
27 * a choice of LGPL license versions is made available with the language indicating
28 * that LGPLv2 or any later version may be used, or where a choice of which version
29 * of the LGPL is applied is otherwise unspecified.
30 */
31
32#include "config.h"
33#include "d3d8_private.h"
34
35#include <stdarg.h>
36
37#define NONAMELESSUNION
38#define NONAMELESSSTRUCT
39#include "windef.h"
40#include "winbase.h"
41#include "wingdi.h"
42#include "winuser.h"
43#include "wine/debug.h"
44#include "wine/unicode.h"
45
46WINE_DEFAULT_DEBUG_CHANNEL(d3d8);
47
48/* IDirect3D IUnknown parts follow: */
49static HRESULT WINAPI IDirect3D8Impl_QueryInterface(LPDIRECT3D8 iface, REFIID riid,LPVOID *ppobj)
50{
51 IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
52
53 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
54
55 if (IsEqualGUID(riid, &IID_IUnknown)
56 || IsEqualGUID(riid, &IID_IDirect3D8)) {
57 IUnknown_AddRef(iface);
58 *ppobj = This;
59 return S_OK;
60 }
61
62 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid),ppobj);
63 *ppobj = NULL;
64 return E_NOINTERFACE;
65}
66
67static ULONG WINAPI IDirect3D8Impl_AddRef(LPDIRECT3D8 iface) {
68 IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
69 ULONG ref = InterlockedIncrement(&This->ref);
70
71 TRACE("%p increasing refcount to %u.\n", iface, ref);
72
73 return ref;
74}
75
76static ULONG WINAPI IDirect3D8Impl_Release(LPDIRECT3D8 iface) {
77 IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
78 ULONG ref = InterlockedDecrement(&This->ref);
79
80 TRACE("%p decreasing refcount to %u.\n", iface, ref);
81
82 if (ref == 0) {
83 TRACE("Releasing wined3d %p\n", This->WineD3D);
84
85 wined3d_mutex_lock();
86 IWineD3D_Release(This->WineD3D);
87 wined3d_mutex_unlock();
88
89 HeapFree(GetProcessHeap(), 0, This);
90 }
91
92 return ref;
93}
94
95/* IDirect3D8 Interface follow: */
96static HRESULT WINAPI IDirect3D8Impl_RegisterSoftwareDevice (LPDIRECT3D8 iface, void* pInitializeFunction) {
97 IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
98 HRESULT hr;
99
100 TRACE("iface %p, init_function %p.\n", iface, pInitializeFunction);
101
102 wined3d_mutex_lock();
103 hr = IWineD3D_RegisterSoftwareDevice(This->WineD3D, pInitializeFunction);
104 wined3d_mutex_unlock();
105
106 return hr;
107}
108
109static UINT WINAPI IDirect3D8Impl_GetAdapterCount (LPDIRECT3D8 iface) {
110 IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
111 HRESULT hr;
112
113 TRACE("iface %p.\n", iface);
114
115 wined3d_mutex_lock();
116 hr = IWineD3D_GetAdapterCount(This->WineD3D);
117 wined3d_mutex_unlock();
118
119 return hr;
120}
121
122static HRESULT WINAPI IDirect3D8Impl_GetAdapterIdentifier(LPDIRECT3D8 iface,
123 UINT Adapter, DWORD Flags, D3DADAPTER_IDENTIFIER8 *pIdentifier)
124{
125 IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
126 WINED3DADAPTER_IDENTIFIER adapter_id;
127 HRESULT hr;
128
129 TRACE("iface %p, adapter %u, flags %#x, identifier %p.\n",
130 iface, Adapter, Flags, pIdentifier);
131
132 adapter_id.driver = pIdentifier->Driver;
133 adapter_id.driver_size = sizeof(pIdentifier->Driver);
134 adapter_id.description = pIdentifier->Description;
135 adapter_id.description_size = sizeof(pIdentifier->Description);
136 adapter_id.device_name = NULL; /* d3d9 only */
137 adapter_id.device_name_size = 0; /* d3d9 only */
138
139 wined3d_mutex_lock();
140 hr = IWineD3D_GetAdapterIdentifier(This->WineD3D, Adapter, Flags, &adapter_id);
141 wined3d_mutex_unlock();
142
143 pIdentifier->DriverVersion = adapter_id.driver_version;
144 pIdentifier->VendorId = adapter_id.vendor_id;
145 pIdentifier->DeviceId = adapter_id.device_id;
146 pIdentifier->SubSysId = adapter_id.subsystem_id;
147 pIdentifier->Revision = adapter_id.revision;
148 memcpy(&pIdentifier->DeviceIdentifier, &adapter_id.device_identifier, sizeof(pIdentifier->DeviceIdentifier));
149 pIdentifier->WHQLLevel = adapter_id.whql_level;
150
151 return hr;
152}
153
154static UINT WINAPI IDirect3D8Impl_GetAdapterModeCount (LPDIRECT3D8 iface,UINT Adapter) {
155 IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
156 HRESULT hr;
157
158 TRACE("iface %p, adapter %u.\n", iface, Adapter);
159
160 wined3d_mutex_lock();
161 hr = IWineD3D_GetAdapterModeCount(This->WineD3D, Adapter, 0 /* format */);
162 wined3d_mutex_unlock();
163
164 return hr;
165}
166
167static HRESULT WINAPI IDirect3D8Impl_EnumAdapterModes (LPDIRECT3D8 iface, UINT Adapter, UINT Mode, D3DDISPLAYMODE* pMode) {
168 IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
169 HRESULT hr;
170
171 TRACE("iface %p, adapter %u, mode_idx %u, mode %p.\n",
172 iface, Adapter, Mode, pMode);
173
174 wined3d_mutex_lock();
175 hr = IWineD3D_EnumAdapterModes(This->WineD3D, Adapter, WINED3DFMT_UNKNOWN, Mode, (WINED3DDISPLAYMODE *) pMode);
176 wined3d_mutex_unlock();
177
178 if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format);
179
180 return hr;
181}
182
183static HRESULT WINAPI IDirect3D8Impl_GetAdapterDisplayMode (LPDIRECT3D8 iface, UINT Adapter, D3DDISPLAYMODE* pMode) {
184 IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
185 HRESULT hr;
186
187 TRACE("iface %p, adapter %u, mode %p.\n",
188 iface, Adapter, pMode);
189
190 wined3d_mutex_lock();
191 hr = IWineD3D_GetAdapterDisplayMode(This->WineD3D, Adapter, (WINED3DDISPLAYMODE *) pMode);
192 wined3d_mutex_unlock();
193
194 if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format);
195
196 return hr;
197}
198
199static HRESULT WINAPI IDirect3D8Impl_CheckDeviceType (LPDIRECT3D8 iface,
200 UINT Adapter, D3DDEVTYPE CheckType, D3DFORMAT DisplayFormat,
201 D3DFORMAT BackBufferFormat, BOOL Windowed) {
202 IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
203 HRESULT hr;
204
205 TRACE("iface %p, adapter %u, device_type %#x, display_format %#x, backbuffer_format %#x, windowed %#x.\n",
206 iface, Adapter, CheckType, DisplayFormat, BackBufferFormat, Windowed);
207
208 wined3d_mutex_lock();
209 hr = IWineD3D_CheckDeviceType(This->WineD3D, Adapter, CheckType, wined3dformat_from_d3dformat(DisplayFormat),
210 wined3dformat_from_d3dformat(BackBufferFormat), Windowed);
211 wined3d_mutex_unlock();
212
213 return hr;
214}
215
216static HRESULT WINAPI IDirect3D8Impl_CheckDeviceFormat (LPDIRECT3D8 iface,
217 UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat,
218 DWORD Usage, D3DRESOURCETYPE RType, D3DFORMAT CheckFormat) {
219 IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
220 HRESULT hr;
221 WINED3DRESOURCETYPE WineD3DRType;
222
223 TRACE("iface %p, adapter %u, device_type %#x, adapter_format %#x, usage %#x, resource_type %#x, format %#x.\n",
224 iface, Adapter, DeviceType, AdapterFormat, Usage, RType, CheckFormat);
225
226 if(CheckFormat == D3DFMT_R8G8B8)
227 {
228 /* See comment in dlls/d3d9/directx.c, IDirect3D9Impl_CheckDeviceFormat for details */
229 WARN("D3DFMT_R8G8B8 is not available on windows, returning D3DERR_NOTAVAILABLE\n");
230 return D3DERR_NOTAVAILABLE;
231 }
232
233
234 switch(RType) {
235 case D3DRTYPE_VERTEXBUFFER:
236 case D3DRTYPE_INDEXBUFFER:
237 WineD3DRType = WINED3DRTYPE_BUFFER;
238 break;
239
240 default:
241 WineD3DRType = RType;
242 break;
243 }
244
245 wined3d_mutex_lock();
246 hr = IWineD3D_CheckDeviceFormat(This->WineD3D, Adapter, DeviceType, wined3dformat_from_d3dformat(AdapterFormat),
247 Usage, WineD3DRType, wined3dformat_from_d3dformat(CheckFormat), SURFACE_OPENGL);
248 wined3d_mutex_unlock();
249
250 return hr;
251}
252
253static HRESULT WINAPI IDirect3D8Impl_CheckDeviceMultiSampleType(IDirect3D8 *iface, UINT Adapter,
254 D3DDEVTYPE DeviceType, D3DFORMAT SurfaceFormat, BOOL Windowed, D3DMULTISAMPLE_TYPE MultiSampleType)
255{
256 IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
257 HRESULT hr;
258
259 TRACE("iface %p, adapter %u, device_type %#x, format %#x, windowed %#x, multisample_type %#x.\n",
260 iface, Adapter, DeviceType, SurfaceFormat, Windowed, MultiSampleType);
261
262 wined3d_mutex_lock();
263 hr = IWineD3D_CheckDeviceMultiSampleType(This->WineD3D, Adapter, DeviceType,
264 wined3dformat_from_d3dformat(SurfaceFormat), Windowed, (WINED3DMULTISAMPLE_TYPE) MultiSampleType, NULL);
265 wined3d_mutex_unlock();
266
267 return hr;
268}
269
270static HRESULT WINAPI IDirect3D8Impl_CheckDepthStencilMatch(IDirect3D8 *iface, UINT Adapter, D3DDEVTYPE DeviceType,
271 D3DFORMAT AdapterFormat, D3DFORMAT RenderTargetFormat, D3DFORMAT DepthStencilFormat)
272{
273 IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
274 HRESULT hr;
275
276 TRACE("iface %p, adapter %u, device_type %#x, adapter_format %#x, rt_format %#x, ds_format %#x.\n",
277 iface, Adapter, DeviceType, AdapterFormat, RenderTargetFormat, DepthStencilFormat);
278
279 wined3d_mutex_lock();
280 hr = IWineD3D_CheckDepthStencilMatch(This->WineD3D, Adapter, DeviceType,
281 wined3dformat_from_d3dformat(AdapterFormat), wined3dformat_from_d3dformat(RenderTargetFormat),
282 wined3dformat_from_d3dformat(DepthStencilFormat));
283 wined3d_mutex_unlock();
284
285 return hr;
286}
287
288void fixup_caps(WINED3DCAPS *caps)
289{
290 /* D3D8 doesn't support SM 2.0 or higher, so clamp to 1.x */
291 if (caps->PixelShaderVersion > D3DPS_VERSION(1,4)) {
292 caps->PixelShaderVersion = D3DPS_VERSION(1,4);
293 }
294 if (caps->VertexShaderVersion > D3DVS_VERSION(1,1)) {
295 caps->VertexShaderVersion = D3DVS_VERSION(1,1);
296 }
297 caps->MaxVertexShaderConst = min(D3D8_MAX_VERTEX_SHADER_CONSTANTF, caps->MaxVertexShaderConst);
298
299 caps->StencilCaps &= ~WINED3DSTENCILCAPS_TWOSIDED;
300}
301
302static HRESULT WINAPI IDirect3D8Impl_GetDeviceCaps(LPDIRECT3D8 iface, UINT Adapter, D3DDEVTYPE DeviceType, D3DCAPS8* pCaps) {
303 IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
304 HRESULT hrc = D3D_OK;
305 WINED3DCAPS *pWineCaps;
306
307 TRACE("iface %p, adapter %u, device_type %#x, caps %p.\n", iface, Adapter, DeviceType, pCaps);
308
309 if(NULL == pCaps){
310 return D3DERR_INVALIDCALL;
311 }
312 pWineCaps = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WINED3DCAPS));
313 if(pWineCaps == NULL){
314 return D3DERR_INVALIDCALL; /*well this is what MSDN says to return*/
315 }
316
317 wined3d_mutex_lock();
318 hrc = IWineD3D_GetDeviceCaps(This->WineD3D, Adapter, DeviceType, pWineCaps);
319 wined3d_mutex_unlock();
320
321 fixup_caps(pWineCaps);
322 WINECAPSTOD3D8CAPS(pCaps, pWineCaps)
323 HeapFree(GetProcessHeap(), 0, pWineCaps);
324
325 TRACE("(%p) returning %p\n", This, pCaps);
326 return hrc;
327}
328
329static HMONITOR WINAPI IDirect3D8Impl_GetAdapterMonitor(LPDIRECT3D8 iface, UINT Adapter) {
330 IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
331 HMONITOR ret;
332
333 TRACE("iface %p, adapter %u.\n", iface, Adapter);
334
335 wined3d_mutex_lock();
336 ret = IWineD3D_GetAdapterMonitor(This->WineD3D, Adapter);
337 wined3d_mutex_unlock();
338
339 return ret;
340}
341
342static HRESULT WINAPI IDirect3D8Impl_CreateDevice(IDirect3D8 *iface, UINT adapter, D3DDEVTYPE device_type,
343 HWND focus_window, DWORD flags, D3DPRESENT_PARAMETERS *parameters, IDirect3DDevice8 **device)
344{
345 IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
346 IDirect3DDevice8Impl *object;
347 HRESULT hr;
348
349 TRACE("iface %p, adapter %u, device_type %#x, focus_window %p, flags %#x, parameters %p, device %p.\n",
350 iface, adapter, device_type, focus_window, flags, parameters, device);
351
352 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
353 if (!object)
354 {
355 ERR("Failed to allocate device memory.\n");
356 return E_OUTOFMEMORY;
357 }
358
359 hr = device_init(object, This->WineD3D, adapter, device_type, focus_window, flags, parameters);
360 if (FAILED(hr))
361 {
362 WARN("Failed to initialize device, hr %#x.\n", hr);
363 HeapFree(GetProcessHeap(), 0, object);
364 return hr;
365 }
366
367 TRACE("Created device %p.\n", object);
368 *device = (IDirect3DDevice8 *)object;
369
370 return D3D_OK;
371}
372
373const IDirect3D8Vtbl Direct3D8_Vtbl =
374{
375 /* IUnknown */
376 IDirect3D8Impl_QueryInterface,
377 IDirect3D8Impl_AddRef,
378 IDirect3D8Impl_Release,
379 /* IDirect3D8 */
380 IDirect3D8Impl_RegisterSoftwareDevice,
381 IDirect3D8Impl_GetAdapterCount,
382 IDirect3D8Impl_GetAdapterIdentifier,
383 IDirect3D8Impl_GetAdapterModeCount,
384 IDirect3D8Impl_EnumAdapterModes,
385 IDirect3D8Impl_GetAdapterDisplayMode,
386 IDirect3D8Impl_CheckDeviceType,
387 IDirect3D8Impl_CheckDeviceFormat,
388 IDirect3D8Impl_CheckDeviceMultiSampleType,
389 IDirect3D8Impl_CheckDepthStencilMatch,
390 IDirect3D8Impl_GetDeviceCaps,
391 IDirect3D8Impl_GetAdapterMonitor,
392 IDirect3D8Impl_CreateDevice
393};
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