widget/windows/winrt/MetroD3DCheckHelper.h

branch
TOR_BUG_9701
changeset 10
ac0c01689b40
equal deleted inserted replaced
-1:000000000000 0:567da1a2962f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 #pragma once
7
8 /* this file is included by exe stubs, don't pull xpcom into it. */
9
10 #include <d3d10_1.h>
11 #include <dxgi.h>
12 #include <d3d10misc.h>
13
14 /*
15 * Checks to see if the d3d implementation supports feature level 9.3 or
16 * above. Metrofx can't run on systems that fail this check.
17 *
18 * Note, this can hit perf, don't call this unless you absolutely have to.
19 * Both the ceh and winrt widget code save a cached result in the registry.
20 */
21 static bool D3DFeatureLevelCheck()
22 {
23 HMODULE dxgiModule = LoadLibraryA("dxgi.dll");
24 if (!dxgiModule) {
25 return false;
26 }
27 decltype(CreateDXGIFactory1)* createDXGIFactory1 =
28 (decltype(CreateDXGIFactory1)*) GetProcAddress(dxgiModule, "CreateDXGIFactory1");
29 if (!createDXGIFactory1) {
30 FreeLibrary(dxgiModule);
31 return false;
32 }
33
34 HMODULE d3d10module = LoadLibraryA("d3d10_1.dll");
35 if (!d3d10module) {
36 FreeLibrary(dxgiModule);
37 return false;
38 }
39 decltype(D3D10CreateDevice1)* createD3DDevice =
40 (decltype(D3D10CreateDevice1)*) GetProcAddress(d3d10module,
41 "D3D10CreateDevice1");
42 if (!createD3DDevice) {
43 FreeLibrary(d3d10module);
44 FreeLibrary(dxgiModule);
45 return false;
46 }
47
48 IDXGIFactory1* factory1;
49 if (FAILED(createDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&factory1))) {
50 FreeLibrary(d3d10module);
51 FreeLibrary(dxgiModule);
52 return false;
53 }
54
55 IDXGIAdapter1* adapter1;
56 if (FAILED(factory1->EnumAdapters1(0, &adapter1))) {
57 factory1->Release();
58 FreeLibrary(d3d10module);
59 FreeLibrary(dxgiModule);
60 return false;
61 }
62
63 // Try for DX10.1
64 ID3D10Device1* device;
65 if (FAILED(createD3DDevice(adapter1, D3D10_DRIVER_TYPE_HARDWARE, nullptr,
66 D3D10_CREATE_DEVICE_BGRA_SUPPORT |
67 D3D10_CREATE_DEVICE_PREVENT_INTERNAL_THREADING_OPTIMIZATIONS,
68 D3D10_FEATURE_LEVEL_10_1,
69 D3D10_1_SDK_VERSION, &device))) {
70 // Try for DX10
71 if (FAILED(createD3DDevice(adapter1, D3D10_DRIVER_TYPE_HARDWARE, nullptr,
72 D3D10_CREATE_DEVICE_BGRA_SUPPORT |
73 D3D10_CREATE_DEVICE_PREVENT_INTERNAL_THREADING_OPTIMIZATIONS,
74 D3D10_FEATURE_LEVEL_10_0,
75 D3D10_1_SDK_VERSION, &device))) {
76 // Try for DX9.3 (we fall back to cairo and cairo has support for D3D 9.3)
77 if (FAILED(createD3DDevice(adapter1, D3D10_DRIVER_TYPE_HARDWARE, nullptr,
78 D3D10_CREATE_DEVICE_BGRA_SUPPORT |
79 D3D10_CREATE_DEVICE_PREVENT_INTERNAL_THREADING_OPTIMIZATIONS,
80 D3D10_FEATURE_LEVEL_9_3,
81 D3D10_1_SDK_VERSION, &device))) {
82 adapter1->Release();
83 factory1->Release();
84 FreeLibrary(d3d10module);
85 FreeLibrary(dxgiModule);
86 return false;
87 }
88 }
89 }
90 device->Release();
91 adapter1->Release();
92 factory1->Release();
93 FreeLibrary(d3d10module);
94 FreeLibrary(dxgiModule);
95 return true;
96 }

mercurial