VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Wine_new/d3d8/directx.c@ 69362

Last change on this file since 69362 was 63025, checked in by vboxsync, 9 years ago

GA/NT/Graphics: warnings

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
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
34#include <stdarg.h>
35
36#define NONAMELESSUNION
37#define NONAMELESSSTRUCT
38#ifndef VBOX
39#include "windef.h"
40#include "winbase.h"
41#include "wingdi.h"
42#include "winuser.h"
43#else
44# include <iprt/win/windows.h>
45#endif
46#include "wine/debug.h"
47#include "wine/unicode.h"
48
49#include "d3d8_private.h"
50
51WINE_DEFAULT_DEBUG_CHANNEL(d3d8);
52
53static inline struct d3d8 *impl_from_IDirect3D8(IDirect3D8 *iface)
54{
55 return CONTAINING_RECORD(iface, struct d3d8, IDirect3D8_iface);
56}
57
58static HRESULT WINAPI d3d8_QueryInterface(IDirect3D8 *iface, REFIID riid, void **out)
59{
60 TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
61
62 if (IsEqualGUID(riid, &IID_IDirect3D8)
63 || IsEqualGUID(riid, &IID_IUnknown))
64 {
65 IDirect3D8_AddRef(iface);
66 *out = iface;
67 return S_OK;
68 }
69
70 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
71
72 *out = NULL;
73 return E_NOINTERFACE;
74}
75
76static ULONG WINAPI d3d8_AddRef(IDirect3D8 *iface)
77{
78 struct d3d8 *d3d8 = impl_from_IDirect3D8(iface);
79 ULONG refcount = InterlockedIncrement(&d3d8->refcount);
80
81 TRACE("%p increasing refcount to %u.\n", iface, refcount);
82
83 return refcount;
84}
85
86static ULONG WINAPI d3d8_Release(IDirect3D8 *iface)
87{
88 struct d3d8 *d3d8 = impl_from_IDirect3D8(iface);
89 ULONG refcount = InterlockedDecrement(&d3d8->refcount);
90
91 TRACE("%p decreasing refcount to %u.\n", iface, refcount);
92
93 if (!refcount)
94 {
95 wined3d_mutex_lock();
96 wined3d_decref(d3d8->wined3d);
97 wined3d_mutex_unlock();
98
99 HeapFree(GetProcessHeap(), 0, d3d8);
100 }
101
102 return refcount;
103}
104
105static HRESULT WINAPI d3d8_RegisterSoftwareDevice(IDirect3D8 *iface, void *init_function)
106{
107 struct d3d8 *d3d8 = impl_from_IDirect3D8(iface);
108 HRESULT hr;
109
110 TRACE("iface %p, init_function %p.\n", iface, init_function);
111
112 wined3d_mutex_lock();
113 hr = wined3d_register_software_device(d3d8->wined3d, init_function);
114 wined3d_mutex_unlock();
115
116 return hr;
117}
118
119static UINT WINAPI d3d8_GetAdapterCount(IDirect3D8 *iface)
120{
121 struct d3d8 *d3d8 = impl_from_IDirect3D8(iface);
122 HRESULT hr;
123
124 TRACE("iface %p.\n", iface);
125
126 wined3d_mutex_lock();
127 hr = wined3d_get_adapter_count(d3d8->wined3d);
128 wined3d_mutex_unlock();
129
130 return hr;
131}
132
133static HRESULT WINAPI d3d8_GetAdapterIdentifier(IDirect3D8 *iface, UINT adapter,
134 DWORD flags, D3DADAPTER_IDENTIFIER8 *identifier)
135{
136 struct d3d8 *d3d8 = impl_from_IDirect3D8(iface);
137 struct wined3d_adapter_identifier adapter_id;
138 HRESULT hr;
139
140 TRACE("iface %p, adapter %u, flags %#x, identifier %p.\n",
141 iface, adapter, flags, identifier);
142
143 adapter_id.driver = identifier->Driver;
144 adapter_id.driver_size = sizeof(identifier->Driver);
145 adapter_id.description = identifier->Description;
146 adapter_id.description_size = sizeof(identifier->Description);
147 adapter_id.device_name = NULL; /* d3d9 only */
148 adapter_id.device_name_size = 0; /* d3d9 only */
149
150 wined3d_mutex_lock();
151 hr = wined3d_get_adapter_identifier(d3d8->wined3d, adapter, flags, &adapter_id);
152 wined3d_mutex_unlock();
153
154 identifier->DriverVersion = adapter_id.driver_version;
155 identifier->VendorId = adapter_id.vendor_id;
156 identifier->DeviceId = adapter_id.device_id;
157 identifier->SubSysId = adapter_id.subsystem_id;
158 identifier->Revision = adapter_id.revision;
159 memcpy(&identifier->DeviceIdentifier, &adapter_id.device_identifier, sizeof(identifier->DeviceIdentifier));
160 identifier->WHQLLevel = adapter_id.whql_level;
161
162 return hr;
163}
164
165static UINT WINAPI d3d8_GetAdapterModeCount(IDirect3D8 *iface, UINT adapter)
166{
167 struct d3d8 *d3d8 = impl_from_IDirect3D8(iface);
168 HRESULT hr;
169
170 TRACE("iface %p, adapter %u.\n", iface, adapter);
171
172 wined3d_mutex_lock();
173 hr = wined3d_get_adapter_mode_count(d3d8->wined3d, adapter,
174 WINED3DFMT_UNKNOWN, WINED3D_SCANLINE_ORDERING_UNKNOWN);
175 wined3d_mutex_unlock();
176
177 return hr;
178}
179
180static HRESULT WINAPI d3d8_EnumAdapterModes(IDirect3D8 *iface, UINT adapter, UINT mode_idx, D3DDISPLAYMODE *mode)
181{
182 struct d3d8 *d3d8 = impl_from_IDirect3D8(iface);
183 struct wined3d_display_mode wined3d_mode;
184 HRESULT hr;
185
186 TRACE("iface %p, adapter %u, mode_idx %u, mode %p.\n",
187 iface, adapter, mode_idx, mode);
188
189 wined3d_mutex_lock();
190 hr = wined3d_enum_adapter_modes(d3d8->wined3d, adapter, WINED3DFMT_UNKNOWN,
191 WINED3D_SCANLINE_ORDERING_UNKNOWN, mode_idx, &wined3d_mode);
192 wined3d_mutex_unlock();
193
194 if (SUCCEEDED(hr))
195 {
196 mode->Width = wined3d_mode.width;
197 mode->Height = wined3d_mode.height;
198 mode->RefreshRate = wined3d_mode.refresh_rate;
199 mode->Format = d3dformat_from_wined3dformat(wined3d_mode.format_id);
200 }
201
202 return hr;
203}
204
205static HRESULT WINAPI d3d8_GetAdapterDisplayMode(IDirect3D8 *iface, UINT adapter, D3DDISPLAYMODE *mode)
206{
207 struct d3d8 *d3d8 = impl_from_IDirect3D8(iface);
208 struct wined3d_display_mode wined3d_mode;
209 HRESULT hr;
210
211 TRACE("iface %p, adapter %u, mode %p.\n",
212 iface, adapter, mode);
213
214 wined3d_mutex_lock();
215 hr = wined3d_get_adapter_display_mode(d3d8->wined3d, adapter, &wined3d_mode, NULL);
216 wined3d_mutex_unlock();
217
218 if (SUCCEEDED(hr))
219 {
220 mode->Width = wined3d_mode.width;
221 mode->Height = wined3d_mode.height;
222 mode->RefreshRate = wined3d_mode.refresh_rate;
223 mode->Format = d3dformat_from_wined3dformat(wined3d_mode.format_id);
224 }
225
226 return hr;
227}
228
229static HRESULT WINAPI d3d8_CheckDeviceType(IDirect3D8 *iface, UINT adapter, D3DDEVTYPE device_type,
230 D3DFORMAT display_format, D3DFORMAT backbuffer_format, BOOL windowed)
231{
232 struct d3d8 *d3d8 = impl_from_IDirect3D8(iface);
233 HRESULT hr;
234
235 TRACE("iface %p, adapter %u, device_type %#x, display_format %#x, backbuffer_format %#x, windowed %#x.\n",
236 iface, adapter, device_type, display_format, backbuffer_format, windowed);
237
238 wined3d_mutex_lock();
239 hr = wined3d_check_device_type(d3d8->wined3d, adapter, device_type, wined3dformat_from_d3dformat(display_format),
240 wined3dformat_from_d3dformat(backbuffer_format), windowed);
241 wined3d_mutex_unlock();
242
243 return hr;
244}
245
246static HRESULT WINAPI d3d8_CheckDeviceFormat(IDirect3D8 *iface, UINT adapter, D3DDEVTYPE device_type,
247 D3DFORMAT adapter_format, DWORD usage, D3DRESOURCETYPE resource_type, D3DFORMAT format)
248{
249 struct d3d8 *d3d8 = impl_from_IDirect3D8(iface);
250 enum wined3d_resource_type wined3d_rtype;
251 HRESULT hr;
252
253 TRACE("iface %p, adapter %u, device_type %#x, adapter_format %#x, usage %#x, resource_type %#x, format %#x.\n",
254 iface, adapter, device_type, adapter_format, usage, resource_type, format);
255
256 switch (resource_type)
257 {
258 case D3DRTYPE_VERTEXBUFFER:
259 case D3DRTYPE_INDEXBUFFER:
260 wined3d_rtype = WINED3D_RTYPE_BUFFER;
261 break;
262
263 default:
264 wined3d_rtype = resource_type;
265 break;
266 }
267
268 wined3d_mutex_lock();
269 hr = wined3d_check_device_format(d3d8->wined3d, adapter, device_type, wined3dformat_from_d3dformat(adapter_format),
270 usage, wined3d_rtype, wined3dformat_from_d3dformat(format));
271 wined3d_mutex_unlock();
272
273 return hr;
274}
275
276static HRESULT WINAPI d3d8_CheckDeviceMultiSampleType(IDirect3D8 *iface, UINT adapter, D3DDEVTYPE device_type,
277 D3DFORMAT format, BOOL windowed, D3DMULTISAMPLE_TYPE multisample_type)
278{
279 struct d3d8 *d3d8 = impl_from_IDirect3D8(iface);
280 HRESULT hr;
281
282 TRACE("iface %p, adapter %u, device_type %#x, format %#x, windowed %#x, multisample_type %#x.\n",
283 iface, adapter, device_type, format, windowed, multisample_type);
284
285 wined3d_mutex_lock();
286 hr = wined3d_check_device_multisample_type(d3d8->wined3d, adapter, device_type,
287 wined3dformat_from_d3dformat(format), windowed,
288 (enum wined3d_multisample_type)multisample_type, NULL);
289 wined3d_mutex_unlock();
290
291 return hr;
292}
293
294static HRESULT WINAPI d3d8_CheckDepthStencilMatch(IDirect3D8 *iface, UINT adapter, D3DDEVTYPE device_type,
295 D3DFORMAT adapter_format, D3DFORMAT rt_format, D3DFORMAT ds_format)
296{
297 struct d3d8 *d3d8 = impl_from_IDirect3D8(iface);
298 HRESULT hr;
299
300 TRACE("iface %p, adapter %u, device_type %#x, adapter_format %#x, rt_format %#x, ds_format %#x.\n",
301 iface, adapter, device_type, adapter_format, rt_format, ds_format);
302
303 wined3d_mutex_lock();
304 hr = wined3d_check_depth_stencil_match(d3d8->wined3d, adapter, device_type,
305 wined3dformat_from_d3dformat(adapter_format), wined3dformat_from_d3dformat(rt_format),
306 wined3dformat_from_d3dformat(ds_format));
307 wined3d_mutex_unlock();
308
309 return hr;
310}
311
312void fixup_caps(WINED3DCAPS *caps)
313{
314 /* D3D8 doesn't support SM 2.0 or higher, so clamp to 1.x */
315 if (caps->PixelShaderVersion)
316 caps->PixelShaderVersion = D3DPS_VERSION(1,4);
317 else
318 caps->PixelShaderVersion = D3DPS_VERSION(0,0);
319 if (caps->VertexShaderVersion)
320 caps->VertexShaderVersion = D3DVS_VERSION(1,1);
321 else
322 caps->VertexShaderVersion = D3DVS_VERSION(0,0);
323 caps->MaxVertexShaderConst = min(D3D8_MAX_VERTEX_SHADER_CONSTANTF, caps->MaxVertexShaderConst);
324
325 caps->StencilCaps &= ~WINED3DSTENCILCAPS_TWOSIDED;
326}
327
328static HRESULT WINAPI d3d8_GetDeviceCaps(IDirect3D8 *iface, UINT adapter, D3DDEVTYPE device_type, D3DCAPS8 *caps)
329{
330 struct d3d8 *d3d8 = impl_from_IDirect3D8(iface);
331 WINED3DCAPS *wined3d_caps;
332 HRESULT hr;
333
334 TRACE("iface %p, adapter %u, device_type %#x, caps %p.\n", iface, adapter, device_type, caps);
335
336 if (!caps)
337 return D3DERR_INVALIDCALL;
338
339 if (!(wined3d_caps = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*wined3d_caps))))
340 return D3DERR_INVALIDCALL;
341
342 wined3d_mutex_lock();
343 hr = wined3d_get_device_caps(d3d8->wined3d, adapter, device_type, wined3d_caps);
344 wined3d_mutex_unlock();
345
346 fixup_caps(wined3d_caps);
347 WINECAPSTOD3D8CAPS(caps, wined3d_caps)
348 HeapFree(GetProcessHeap(), 0, wined3d_caps);
349
350 return hr;
351}
352
353static HMONITOR WINAPI d3d8_GetAdapterMonitor(IDirect3D8 *iface, UINT adapter)
354{
355 struct d3d8 *d3d8 = impl_from_IDirect3D8(iface);
356 HMONITOR ret;
357
358 TRACE("iface %p, adapter %u.\n", iface, adapter);
359
360 wined3d_mutex_lock();
361 ret = wined3d_get_adapter_monitor(d3d8->wined3d, adapter);
362 wined3d_mutex_unlock();
363
364 return ret;
365}
366
367static HRESULT WINAPI d3d8_CreateDevice(IDirect3D8 *iface, UINT adapter,
368 D3DDEVTYPE device_type, HWND focus_window, DWORD flags, D3DPRESENT_PARAMETERS *parameters,
369 IDirect3DDevice8 **device)
370{
371 struct d3d8 *d3d8 = impl_from_IDirect3D8(iface);
372 struct d3d8_device *object;
373 HRESULT hr;
374
375 TRACE("iface %p, adapter %u, device_type %#x, focus_window %p, flags %#x, parameters %p, device %p.\n",
376 iface, adapter, device_type, focus_window, flags, parameters, device);
377
378 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
379 if (!object)
380 return E_OUTOFMEMORY;
381
382 hr = device_init(object, d3d8, d3d8->wined3d, adapter, device_type, focus_window, flags, parameters);
383 if (FAILED(hr))
384 {
385 WARN("Failed to initialize device, hr %#x.\n", hr);
386 HeapFree(GetProcessHeap(), 0, object);
387 return hr;
388 }
389
390 TRACE("Created device %p.\n", object);
391 *device = &object->IDirect3DDevice8_iface;
392
393 return D3D_OK;
394}
395
396static const struct IDirect3D8Vtbl d3d8_vtbl =
397{
398 /* IUnknown */
399 d3d8_QueryInterface,
400 d3d8_AddRef,
401 d3d8_Release,
402 /* IDirect3D8 */
403 d3d8_RegisterSoftwareDevice,
404 d3d8_GetAdapterCount,
405 d3d8_GetAdapterIdentifier,
406 d3d8_GetAdapterModeCount,
407 d3d8_EnumAdapterModes,
408 d3d8_GetAdapterDisplayMode,
409 d3d8_CheckDeviceType,
410 d3d8_CheckDeviceFormat,
411 d3d8_CheckDeviceMultiSampleType,
412 d3d8_CheckDepthStencilMatch,
413 d3d8_GetDeviceCaps,
414 d3d8_GetAdapterMonitor,
415 d3d8_CreateDevice,
416};
417
418BOOL d3d8_init(struct d3d8 *d3d8)
419{
420 DWORD flags = WINED3D_LEGACY_DEPTH_BIAS | WINED3D_VIDMEM_ACCOUNTING;
421
422 d3d8->IDirect3D8_iface.lpVtbl = (struct IDirect3D8Vtbl *)&d3d8_vtbl;
423 d3d8->refcount = 1;
424
425 wined3d_mutex_lock();
426 d3d8->wined3d = wined3d_create(8, flags);
427 wined3d_mutex_unlock();
428 if (!d3d8->wined3d)
429 return FALSE;
430
431 return TRUE;
432}
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