[AMSTREAM] We don't need to define WIDL_C_INLINE_WRAPPERS here anymore.
[reactos.git] / dll / directx / wine / d3d9 / directx.c
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 #include "d3d9_private.h"
23
24 static inline struct d3d9 *impl_from_IDirect3D9Ex(IDirect3D9Ex *iface)
25 {
26 return CONTAINING_RECORD(iface, struct d3d9, IDirect3D9Ex_iface);
27 }
28
29 static HRESULT WINAPI d3d9_QueryInterface(IDirect3D9Ex *iface, REFIID riid, void **out)
30 {
31 struct d3d9 *d3d9 = impl_from_IDirect3D9Ex(iface);
32
33 TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
34
35 if (IsEqualGUID(riid, &IID_IDirect3D9)
36 || IsEqualGUID(riid, &IID_IUnknown))
37 {
38 IDirect3D9Ex_AddRef(&d3d9->IDirect3D9Ex_iface);
39 *out = &d3d9->IDirect3D9Ex_iface;
40 return S_OK;
41 }
42
43 if (IsEqualGUID(riid, &IID_IDirect3D9Ex))
44 {
45 if (!d3d9->extended)
46 {
47 WARN("Application asks for IDirect3D9Ex, but this instance wasn't created with Direct3DCreate9Ex.\n");
48 *out = NULL;
49 return E_NOINTERFACE;
50 }
51
52 IDirect3D9Ex_AddRef(&d3d9->IDirect3D9Ex_iface);
53 *out = &d3d9->IDirect3D9Ex_iface;
54 return S_OK;
55 }
56
57 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
58
59 *out = NULL;
60 return E_NOINTERFACE;
61 }
62
63 static ULONG WINAPI d3d9_AddRef(IDirect3D9Ex *iface)
64 {
65 struct d3d9 *d3d9 = impl_from_IDirect3D9Ex(iface);
66 ULONG refcount = InterlockedIncrement(&d3d9->refcount);
67
68 TRACE("%p increasing refcount to %u.\n", iface, refcount);
69
70 return refcount;
71 }
72
73 static ULONG WINAPI d3d9_Release(IDirect3D9Ex *iface)
74 {
75 struct d3d9 *d3d9 = impl_from_IDirect3D9Ex(iface);
76 ULONG refcount = InterlockedDecrement(&d3d9->refcount);
77
78 TRACE("%p decreasing refcount to %u.\n", iface, refcount);
79
80 if (!refcount)
81 {
82 wined3d_mutex_lock();
83 wined3d_decref(d3d9->wined3d);
84 wined3d_mutex_unlock();
85
86 HeapFree(GetProcessHeap(), 0, d3d9);
87 }
88
89 return refcount;
90 }
91
92 static HRESULT WINAPI d3d9_RegisterSoftwareDevice(IDirect3D9Ex *iface, void *init_function)
93 {
94 struct d3d9 *d3d9 = impl_from_IDirect3D9Ex(iface);
95 HRESULT hr;
96
97 TRACE("iface %p, init_function %p.\n", iface, init_function);
98
99 wined3d_mutex_lock();
100 hr = wined3d_register_software_device(d3d9->wined3d, init_function);
101 wined3d_mutex_unlock();
102
103 return hr;
104 }
105
106 static UINT WINAPI d3d9_GetAdapterCount(IDirect3D9Ex *iface)
107 {
108 struct d3d9 *d3d9 = impl_from_IDirect3D9Ex(iface);
109 UINT ret;
110
111 TRACE("iface %p.\n", iface);
112
113 wined3d_mutex_lock();
114 ret = wined3d_get_adapter_count(d3d9->wined3d);
115 wined3d_mutex_unlock();
116
117 return ret;
118 }
119
120 static HRESULT WINAPI d3d9_GetAdapterIdentifier(IDirect3D9Ex *iface, UINT adapter,
121 DWORD flags, D3DADAPTER_IDENTIFIER9 *identifier)
122 {
123 struct d3d9 *d3d9 = impl_from_IDirect3D9Ex(iface);
124 struct wined3d_adapter_identifier adapter_id;
125 HRESULT hr;
126
127 TRACE("iface %p, adapter %u, flags %#x, identifier %p.\n",
128 iface, adapter, flags, identifier);
129
130 adapter_id.driver = identifier->Driver;
131 adapter_id.driver_size = sizeof(identifier->Driver);
132 adapter_id.description = identifier->Description;
133 adapter_id.description_size = sizeof(identifier->Description);
134 adapter_id.device_name = identifier->DeviceName;
135 adapter_id.device_name_size = sizeof(identifier->DeviceName);
136
137 wined3d_mutex_lock();
138 hr = wined3d_get_adapter_identifier(d3d9->wined3d, adapter, flags, &adapter_id);
139 wined3d_mutex_unlock();
140
141 identifier->DriverVersion = adapter_id.driver_version;
142 identifier->VendorId = adapter_id.vendor_id;
143 identifier->DeviceId = adapter_id.device_id;
144 identifier->SubSysId = adapter_id.subsystem_id;
145 identifier->Revision = adapter_id.revision;
146 memcpy(&identifier->DeviceIdentifier, &adapter_id.device_identifier, sizeof(identifier->DeviceIdentifier));
147 identifier->WHQLLevel = adapter_id.whql_level;
148
149 return hr;
150 }
151
152 static UINT WINAPI d3d9_GetAdapterModeCount(IDirect3D9Ex *iface, UINT adapter, D3DFORMAT format)
153 {
154 struct d3d9 *d3d9 = impl_from_IDirect3D9Ex(iface);
155 UINT ret;
156
157 TRACE("iface %p, adapter %u, format %#x.\n", iface, adapter, format);
158
159 /* Others than that not supported by d3d9, but reported by wined3d for ddraw. Filter them out. */
160 if (format != D3DFMT_X8R8G8B8 && format != D3DFMT_R5G6B5)
161 return 0;
162
163 wined3d_mutex_lock();
164 ret = wined3d_get_adapter_mode_count(d3d9->wined3d, adapter,
165 wined3dformat_from_d3dformat(format), WINED3D_SCANLINE_ORDERING_UNKNOWN);
166 wined3d_mutex_unlock();
167
168 return ret;
169 }
170
171 static HRESULT WINAPI d3d9_EnumAdapterModes(IDirect3D9Ex *iface, UINT adapter,
172 D3DFORMAT format, UINT mode_idx, D3DDISPLAYMODE *mode)
173 {
174 struct d3d9 *d3d9 = impl_from_IDirect3D9Ex(iface);
175 struct wined3d_display_mode wined3d_mode;
176 HRESULT hr;
177
178 TRACE("iface %p, adapter %u, format %#x, mode_idx %u, mode %p.\n",
179 iface, adapter, format, mode_idx, mode);
180
181 if (format != D3DFMT_X8R8G8B8 && format != D3DFMT_R5G6B5)
182 return D3DERR_INVALIDCALL;
183
184 wined3d_mutex_lock();
185 hr = wined3d_enum_adapter_modes(d3d9->wined3d, adapter, wined3dformat_from_d3dformat(format),
186 WINED3D_SCANLINE_ORDERING_UNKNOWN, mode_idx, &wined3d_mode);
187 wined3d_mutex_unlock();
188
189 if (SUCCEEDED(hr))
190 {
191 mode->Width = wined3d_mode.width;
192 mode->Height = wined3d_mode.height;
193 mode->RefreshRate = wined3d_mode.refresh_rate;
194 mode->Format = d3dformat_from_wined3dformat(wined3d_mode.format_id);
195 }
196
197 return hr;
198 }
199
200 static HRESULT WINAPI d3d9_GetAdapterDisplayMode(IDirect3D9Ex *iface, UINT adapter, D3DDISPLAYMODE *mode)
201 {
202 struct d3d9 *d3d9 = impl_from_IDirect3D9Ex(iface);
203 struct wined3d_display_mode wined3d_mode;
204 HRESULT hr;
205
206 TRACE("iface %p, adapter %u, mode %p.\n", iface, adapter, mode);
207
208 wined3d_mutex_lock();
209 hr = wined3d_get_adapter_display_mode(d3d9->wined3d, adapter, &wined3d_mode, NULL);
210 wined3d_mutex_unlock();
211
212 if (SUCCEEDED(hr))
213 {
214 mode->Width = wined3d_mode.width;
215 mode->Height = wined3d_mode.height;
216 mode->RefreshRate = wined3d_mode.refresh_rate;
217 mode->Format = d3dformat_from_wined3dformat(wined3d_mode.format_id);
218 }
219
220 return hr;
221 }
222
223 static HRESULT WINAPI d3d9_CheckDeviceType(IDirect3D9Ex *iface, UINT adapter, D3DDEVTYPE device_type,
224 D3DFORMAT display_format, D3DFORMAT backbuffer_format, BOOL windowed)
225 {
226 struct d3d9 *d3d9 = impl_from_IDirect3D9Ex(iface);
227 HRESULT hr;
228
229 TRACE("iface %p, adapter %u, device_type %#x, display_format %#x, backbuffer_format %#x, windowed %#x.\n",
230 iface, adapter, device_type, display_format, backbuffer_format, windowed);
231
232 /* Others than that not supported by d3d9, but reported by wined3d for ddraw. Filter them out. */
233 if (!windowed && display_format != D3DFMT_X8R8G8B8 && display_format != D3DFMT_R5G6B5)
234 return WINED3DERR_NOTAVAILABLE;
235
236 wined3d_mutex_lock();
237 hr = wined3d_check_device_type(d3d9->wined3d, adapter, device_type, wined3dformat_from_d3dformat(display_format),
238 wined3dformat_from_d3dformat(backbuffer_format), windowed);
239 wined3d_mutex_unlock();
240
241 return hr;
242 }
243
244 static HRESULT WINAPI d3d9_CheckDeviceFormat(IDirect3D9Ex *iface, UINT adapter, D3DDEVTYPE device_type,
245 D3DFORMAT adapter_format, DWORD usage, D3DRESOURCETYPE resource_type, D3DFORMAT format)
246 {
247 struct d3d9 *d3d9 = impl_from_IDirect3D9Ex(iface);
248 enum wined3d_resource_type wined3d_rtype;
249 HRESULT hr;
250
251 TRACE("iface %p, adapter %u, device_type %#x, adapter_format %#x, usage %#x, resource_type %#x, format %#x.\n",
252 iface, adapter, device_type, adapter_format, usage, resource_type, format);
253
254 usage = usage & (WINED3DUSAGE_MASK | WINED3DUSAGE_QUERY_MASK);
255 switch (resource_type)
256 {
257 case D3DRTYPE_CUBETEXTURE:
258 usage |= WINED3DUSAGE_LEGACY_CUBEMAP;
259 case D3DRTYPE_TEXTURE:
260 usage |= WINED3DUSAGE_TEXTURE;
261 case D3DRTYPE_SURFACE:
262 wined3d_rtype = WINED3D_RTYPE_TEXTURE_2D;
263 break;
264
265 case D3DRTYPE_VOLUMETEXTURE:
266 case D3DRTYPE_VOLUME:
267 usage |= WINED3DUSAGE_TEXTURE;
268 wined3d_rtype = WINED3D_RTYPE_TEXTURE_3D;
269 break;
270
271 case D3DRTYPE_VERTEXBUFFER:
272 case D3DRTYPE_INDEXBUFFER:
273 wined3d_rtype = WINED3D_RTYPE_BUFFER;
274 break;
275
276 default:
277 FIXME("Unhandled resource type %#x.\n", resource_type);
278 return WINED3DERR_INVALIDCALL;
279 }
280
281 wined3d_mutex_lock();
282 hr = wined3d_check_device_format(d3d9->wined3d, adapter, device_type, wined3dformat_from_d3dformat(adapter_format),
283 usage, wined3d_rtype, wined3dformat_from_d3dformat(format));
284 wined3d_mutex_unlock();
285
286 return hr;
287 }
288
289 static HRESULT WINAPI d3d9_CheckDeviceMultiSampleType(IDirect3D9Ex *iface, UINT adapter, D3DDEVTYPE device_type,
290 D3DFORMAT format, BOOL windowed, D3DMULTISAMPLE_TYPE multisample_type, DWORD *levels)
291 {
292 struct d3d9 *d3d9 = impl_from_IDirect3D9Ex(iface);
293 HRESULT hr;
294
295 TRACE("iface %p, adapter %u, device_type %#x, format %#x, windowed %#x, multisample_type %#x, levels %p.\n",
296 iface, adapter, device_type, format, windowed, multisample_type, levels);
297
298 if (multisample_type > D3DMULTISAMPLE_16_SAMPLES)
299 return D3DERR_INVALIDCALL;
300
301 wined3d_mutex_lock();
302 hr = wined3d_check_device_multisample_type(d3d9->wined3d, adapter, device_type,
303 wined3dformat_from_d3dformat(format), windowed, multisample_type, levels);
304 wined3d_mutex_unlock();
305 if (hr == WINED3DERR_NOTAVAILABLE && levels)
306 *levels = 1;
307
308 return hr;
309 }
310
311 static HRESULT WINAPI d3d9_CheckDepthStencilMatch(IDirect3D9Ex *iface, UINT adapter, D3DDEVTYPE device_type,
312 D3DFORMAT adapter_format, D3DFORMAT rt_format, D3DFORMAT ds_format)
313 {
314 struct d3d9 *d3d9 = impl_from_IDirect3D9Ex(iface);
315 HRESULT hr;
316
317 TRACE("iface %p, adapter %u, device_type %#x, adapter_format %#x, rt_format %#x, ds_format %#x.\n",
318 iface, adapter, device_type, adapter_format, rt_format, ds_format);
319
320 wined3d_mutex_lock();
321 hr = wined3d_check_depth_stencil_match(d3d9->wined3d, adapter, device_type,
322 wined3dformat_from_d3dformat(adapter_format), wined3dformat_from_d3dformat(rt_format),
323 wined3dformat_from_d3dformat(ds_format));
324 wined3d_mutex_unlock();
325
326 return hr;
327 }
328
329 static HRESULT WINAPI d3d9_CheckDeviceFormatConversion(IDirect3D9Ex *iface, UINT adapter,
330 D3DDEVTYPE device_type, D3DFORMAT src_format, D3DFORMAT dst_format)
331 {
332 struct d3d9 *d3d9 = impl_from_IDirect3D9Ex(iface);
333 HRESULT hr;
334
335 TRACE("iface %p, adapter %u, device_type %#x, src_format %#x, dst_format %#x.\n",
336 iface, adapter, device_type, src_format, dst_format);
337
338 wined3d_mutex_lock();
339 hr = wined3d_check_device_format_conversion(d3d9->wined3d, adapter, device_type,
340 wined3dformat_from_d3dformat(src_format), wined3dformat_from_d3dformat(dst_format));
341 wined3d_mutex_unlock();
342
343 return hr;
344 }
345
346 static HRESULT WINAPI d3d9_GetDeviceCaps(IDirect3D9Ex *iface, UINT adapter, D3DDEVTYPE device_type, D3DCAPS9 *caps)
347 {
348 struct d3d9 *d3d9 = impl_from_IDirect3D9Ex(iface);
349 WINED3DCAPS wined3d_caps;
350 HRESULT hr;
351
352 TRACE("iface %p, adapter %u, device_type %#x, caps %p.\n", iface, adapter, device_type, caps);
353
354 if (!caps)
355 return D3DERR_INVALIDCALL;
356
357 memset(caps, 0, sizeof(*caps));
358
359 wined3d_mutex_lock();
360 hr = wined3d_get_device_caps(d3d9->wined3d, adapter, device_type, &wined3d_caps);
361 wined3d_mutex_unlock();
362
363 d3dcaps_from_wined3dcaps(caps, &wined3d_caps);
364
365 return hr;
366 }
367
368 static HMONITOR WINAPI d3d9_GetAdapterMonitor(IDirect3D9Ex *iface, UINT adapter)
369 {
370 struct d3d9 *d3d9 = impl_from_IDirect3D9Ex(iface);
371 struct wined3d_output_desc desc;
372 HRESULT hr;
373
374 TRACE("iface %p, adapter %u.\n", iface, adapter);
375
376 wined3d_mutex_lock();
377 hr = wined3d_get_output_desc(d3d9->wined3d, adapter, &desc);
378 wined3d_mutex_unlock();
379
380 if (FAILED(hr))
381 {
382 WARN("Failed to get output desc, hr %#x.\n", hr);
383 return NULL;
384 }
385
386 return desc.monitor;
387 }
388
389 static HRESULT WINAPI DECLSPEC_HOTPATCH d3d9_CreateDevice(IDirect3D9Ex *iface, UINT adapter,
390 D3DDEVTYPE device_type, HWND focus_window, DWORD flags, D3DPRESENT_PARAMETERS *parameters,
391 IDirect3DDevice9 **device)
392 {
393 struct d3d9 *d3d9 = impl_from_IDirect3D9Ex(iface);
394 struct d3d9_device *object;
395 HRESULT hr;
396
397 TRACE("iface %p, adapter %u, device_type %#x, focus_window %p, flags %#x, parameters %p, device %p.\n",
398 iface, adapter, device_type, focus_window, flags, parameters, device);
399
400 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
401 if (!object)
402 return E_OUTOFMEMORY;
403
404 hr = device_init(object, d3d9, d3d9->wined3d, adapter, device_type, focus_window, flags, parameters, NULL);
405 if (FAILED(hr))
406 {
407 WARN("Failed to initialize device, hr %#x.\n", hr);
408 HeapFree(GetProcessHeap(), 0, object);
409 return hr;
410 }
411
412 TRACE("Created device %p.\n", object);
413 *device = (IDirect3DDevice9 *)&object->IDirect3DDevice9Ex_iface;
414
415 return D3D_OK;
416 }
417
418 static UINT WINAPI d3d9_GetAdapterModeCountEx(IDirect3D9Ex *iface,
419 UINT adapter, const D3DDISPLAYMODEFILTER *filter)
420 {
421 struct d3d9 *d3d9 = impl_from_IDirect3D9Ex(iface);
422 UINT ret;
423
424 TRACE("iface %p, adapter %u, filter %p.\n", iface, adapter, filter);
425
426 if (filter->Format != D3DFMT_X8R8G8B8 && filter->Format != D3DFMT_R5G6B5)
427 return 0;
428
429 wined3d_mutex_lock();
430 ret = wined3d_get_adapter_mode_count(d3d9->wined3d, adapter,
431 wined3dformat_from_d3dformat(filter->Format), filter->ScanLineOrdering);
432 wined3d_mutex_unlock();
433
434 return ret;
435 }
436
437 static HRESULT WINAPI d3d9_EnumAdapterModesEx(IDirect3D9Ex *iface,
438 UINT adapter, const D3DDISPLAYMODEFILTER *filter, UINT mode_idx, D3DDISPLAYMODEEX *mode)
439 {
440 struct d3d9 *d3d9 = impl_from_IDirect3D9Ex(iface);
441 struct wined3d_display_mode wined3d_mode;
442 HRESULT hr;
443
444 TRACE("iface %p, adapter %u, filter %p, mode_idx %u, mode %p.\n",
445 iface, adapter, filter, mode_idx, mode);
446
447 if (filter->Format != D3DFMT_X8R8G8B8 && filter->Format != D3DFMT_R5G6B5)
448 return D3DERR_INVALIDCALL;
449
450 wined3d_mutex_lock();
451 hr = wined3d_enum_adapter_modes(d3d9->wined3d, adapter, wined3dformat_from_d3dformat(filter->Format),
452 filter->ScanLineOrdering, mode_idx, &wined3d_mode);
453 wined3d_mutex_unlock();
454
455 if (SUCCEEDED(hr))
456 {
457 mode->Width = wined3d_mode.width;
458 mode->Height = wined3d_mode.height;
459 mode->RefreshRate = wined3d_mode.refresh_rate;
460 mode->Format = d3dformat_from_wined3dformat(wined3d_mode.format_id);
461 mode->ScanLineOrdering = wined3d_mode.scanline_ordering;
462 }
463
464 return hr;
465 }
466
467 static HRESULT WINAPI d3d9_GetAdapterDisplayModeEx(IDirect3D9Ex *iface,
468 UINT adapter, D3DDISPLAYMODEEX *mode, D3DDISPLAYROTATION *rotation)
469 {
470 struct d3d9 *d3d9 = impl_from_IDirect3D9Ex(iface);
471 struct wined3d_display_mode wined3d_mode;
472 HRESULT hr;
473
474 TRACE("iface %p, adapter %u, mode %p, rotation %p.\n",
475 iface, adapter, mode, rotation);
476
477 if (mode->Size != sizeof(*mode))
478 return D3DERR_INVALIDCALL;
479
480 wined3d_mutex_lock();
481 hr = wined3d_get_adapter_display_mode(d3d9->wined3d, adapter, &wined3d_mode,
482 (enum wined3d_display_rotation *)rotation);
483 wined3d_mutex_unlock();
484
485 if (SUCCEEDED(hr))
486 {
487 mode->Width = wined3d_mode.width;
488 mode->Height = wined3d_mode.height;
489 mode->RefreshRate = wined3d_mode.refresh_rate;
490 mode->Format = d3dformat_from_wined3dformat(wined3d_mode.format_id);
491 mode->ScanLineOrdering = wined3d_mode.scanline_ordering;
492 }
493
494 return hr;
495 }
496
497 static HRESULT WINAPI DECLSPEC_HOTPATCH d3d9_CreateDeviceEx(IDirect3D9Ex *iface,
498 UINT adapter, D3DDEVTYPE device_type, HWND focus_window, DWORD flags,
499 D3DPRESENT_PARAMETERS *parameters, D3DDISPLAYMODEEX *mode, IDirect3DDevice9Ex **device)
500 {
501 struct d3d9 *d3d9 = impl_from_IDirect3D9Ex(iface);
502 struct d3d9_device *object;
503 HRESULT hr;
504
505 TRACE("iface %p, adapter %u, device_type %#x, focus_window %p, flags %#x, parameters %p, mode %p, device %p.\n",
506 iface, adapter, device_type, focus_window, flags, parameters, mode, device);
507
508 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
509 if (!object)
510 return E_OUTOFMEMORY;
511
512 hr = device_init(object, d3d9, d3d9->wined3d, adapter, device_type, focus_window, flags, parameters, mode);
513 if (FAILED(hr))
514 {
515 WARN("Failed to initialize device, hr %#x.\n", hr);
516 HeapFree(GetProcessHeap(), 0, object);
517 return hr;
518 }
519
520 TRACE("Created device %p.\n", object);
521 *device = &object->IDirect3DDevice9Ex_iface;
522
523 return D3D_OK;
524 }
525
526 static HRESULT WINAPI d3d9_GetAdapterLUID(IDirect3D9Ex *iface, UINT adapter, LUID *luid)
527 {
528 struct d3d9 *d3d9 = impl_from_IDirect3D9Ex(iface);
529 struct wined3d_adapter_identifier adapter_id;
530 HRESULT hr;
531
532 TRACE("iface %p, adapter %u, luid %p.\n", iface, adapter, luid);
533
534 adapter_id.driver_size = 0;
535 adapter_id.description_size = 0;
536 adapter_id.device_name_size = 0;
537
538 wined3d_mutex_lock();
539 hr = wined3d_get_adapter_identifier(d3d9->wined3d, adapter, 0, &adapter_id);
540 wined3d_mutex_unlock();
541
542 memcpy(luid, &adapter_id.adapter_luid, sizeof(*luid));
543
544 return hr;
545 }
546
547 static const struct IDirect3D9ExVtbl d3d9_vtbl =
548 {
549 /* IUnknown */
550 d3d9_QueryInterface,
551 d3d9_AddRef,
552 d3d9_Release,
553 /* IDirect3D9 */
554 d3d9_RegisterSoftwareDevice,
555 d3d9_GetAdapterCount,
556 d3d9_GetAdapterIdentifier,
557 d3d9_GetAdapterModeCount,
558 d3d9_EnumAdapterModes,
559 d3d9_GetAdapterDisplayMode,
560 d3d9_CheckDeviceType,
561 d3d9_CheckDeviceFormat,
562 d3d9_CheckDeviceMultiSampleType,
563 d3d9_CheckDepthStencilMatch,
564 d3d9_CheckDeviceFormatConversion,
565 d3d9_GetDeviceCaps,
566 d3d9_GetAdapterMonitor,
567 d3d9_CreateDevice,
568 /* IDirect3D9Ex */
569 d3d9_GetAdapterModeCountEx,
570 d3d9_EnumAdapterModesEx,
571 d3d9_GetAdapterDisplayModeEx,
572 d3d9_CreateDeviceEx,
573 d3d9_GetAdapterLUID,
574 };
575
576 BOOL d3d9_init(struct d3d9 *d3d9, BOOL extended)
577 {
578 DWORD flags = WINED3D_PRESENT_CONVERSION | WINED3D_HANDLE_RESTORE | WINED3D_PIXEL_CENTER_INTEGER
579 | WINED3D_SRGB_READ_WRITE_CONTROL | WINED3D_LEGACY_UNBOUND_RESOURCE_COLOR
580 | WINED3D_NO_PRIMITIVE_RESTART | WINED3D_LEGACY_CUBEMAP_FILTERING | WINED3D_LIMIT_VIEWPORT;
581
582 if (!extended)
583 flags |= WINED3D_VIDMEM_ACCOUNTING;
584 else
585 flags |= WINED3D_RESTORE_MODE_ON_ACTIVATE;
586
587 d3d9->IDirect3D9Ex_iface.lpVtbl = &d3d9_vtbl;
588 d3d9->refcount = 1;
589
590 wined3d_mutex_lock();
591 d3d9->wined3d = wined3d_create(flags);
592 wined3d_mutex_unlock();
593 if (!d3d9->wined3d)
594 return FALSE;
595 d3d9->extended = extended;
596
597 return TRUE;
598 }