michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #pragma once michael@0: michael@0: /* this file is included by exe stubs, don't pull xpcom into it. */ michael@0: michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: /* michael@0: * Checks to see if the d3d implementation supports feature level 9.3 or michael@0: * above. Metrofx can't run on systems that fail this check. michael@0: * michael@0: * Note, this can hit perf, don't call this unless you absolutely have to. michael@0: * Both the ceh and winrt widget code save a cached result in the registry. michael@0: */ michael@0: static bool D3DFeatureLevelCheck() michael@0: { michael@0: HMODULE dxgiModule = LoadLibraryA("dxgi.dll"); michael@0: if (!dxgiModule) { michael@0: return false; michael@0: } michael@0: decltype(CreateDXGIFactory1)* createDXGIFactory1 = michael@0: (decltype(CreateDXGIFactory1)*) GetProcAddress(dxgiModule, "CreateDXGIFactory1"); michael@0: if (!createDXGIFactory1) { michael@0: FreeLibrary(dxgiModule); michael@0: return false; michael@0: } michael@0: michael@0: HMODULE d3d10module = LoadLibraryA("d3d10_1.dll"); michael@0: if (!d3d10module) { michael@0: FreeLibrary(dxgiModule); michael@0: return false; michael@0: } michael@0: decltype(D3D10CreateDevice1)* createD3DDevice = michael@0: (decltype(D3D10CreateDevice1)*) GetProcAddress(d3d10module, michael@0: "D3D10CreateDevice1"); michael@0: if (!createD3DDevice) { michael@0: FreeLibrary(d3d10module); michael@0: FreeLibrary(dxgiModule); michael@0: return false; michael@0: } michael@0: michael@0: IDXGIFactory1* factory1; michael@0: if (FAILED(createDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&factory1))) { michael@0: FreeLibrary(d3d10module); michael@0: FreeLibrary(dxgiModule); michael@0: return false; michael@0: } michael@0: michael@0: IDXGIAdapter1* adapter1; michael@0: if (FAILED(factory1->EnumAdapters1(0, &adapter1))) { michael@0: factory1->Release(); michael@0: FreeLibrary(d3d10module); michael@0: FreeLibrary(dxgiModule); michael@0: return false; michael@0: } michael@0: michael@0: // Try for DX10.1 michael@0: ID3D10Device1* device; michael@0: if (FAILED(createD3DDevice(adapter1, D3D10_DRIVER_TYPE_HARDWARE, nullptr, michael@0: D3D10_CREATE_DEVICE_BGRA_SUPPORT | michael@0: D3D10_CREATE_DEVICE_PREVENT_INTERNAL_THREADING_OPTIMIZATIONS, michael@0: D3D10_FEATURE_LEVEL_10_1, michael@0: D3D10_1_SDK_VERSION, &device))) { michael@0: // Try for DX10 michael@0: if (FAILED(createD3DDevice(adapter1, D3D10_DRIVER_TYPE_HARDWARE, nullptr, michael@0: D3D10_CREATE_DEVICE_BGRA_SUPPORT | michael@0: D3D10_CREATE_DEVICE_PREVENT_INTERNAL_THREADING_OPTIMIZATIONS, michael@0: D3D10_FEATURE_LEVEL_10_0, michael@0: D3D10_1_SDK_VERSION, &device))) { michael@0: // Try for DX9.3 (we fall back to cairo and cairo has support for D3D 9.3) michael@0: if (FAILED(createD3DDevice(adapter1, D3D10_DRIVER_TYPE_HARDWARE, nullptr, michael@0: D3D10_CREATE_DEVICE_BGRA_SUPPORT | michael@0: D3D10_CREATE_DEVICE_PREVENT_INTERNAL_THREADING_OPTIMIZATIONS, michael@0: D3D10_FEATURE_LEVEL_9_3, michael@0: D3D10_1_SDK_VERSION, &device))) { michael@0: adapter1->Release(); michael@0: factory1->Release(); michael@0: FreeLibrary(d3d10module); michael@0: FreeLibrary(dxgiModule); michael@0: return false; michael@0: } michael@0: } michael@0: } michael@0: device->Release(); michael@0: adapter1->Release(); michael@0: factory1->Release(); michael@0: FreeLibrary(d3d10module); michael@0: FreeLibrary(dxgiModule); michael@0: return true; michael@0: }