VirtualBox

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

Last change on this file since 48345 was 48345, checked in by vboxsync, 11 years ago

header fixes

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

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