1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/widget/windows/winrt/MetroD3DCheckHelper.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,96 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#pragma once 1.10 + 1.11 +/* this file is included by exe stubs, don't pull xpcom into it. */ 1.12 + 1.13 +#include <d3d10_1.h> 1.14 +#include <dxgi.h> 1.15 +#include <d3d10misc.h> 1.16 + 1.17 +/* 1.18 + * Checks to see if the d3d implementation supports feature level 9.3 or 1.19 + * above. Metrofx can't run on systems that fail this check. 1.20 + * 1.21 + * Note, this can hit perf, don't call this unless you absolutely have to. 1.22 + * Both the ceh and winrt widget code save a cached result in the registry. 1.23 + */ 1.24 +static bool D3DFeatureLevelCheck() 1.25 +{ 1.26 + HMODULE dxgiModule = LoadLibraryA("dxgi.dll"); 1.27 + if (!dxgiModule) { 1.28 + return false; 1.29 + } 1.30 + decltype(CreateDXGIFactory1)* createDXGIFactory1 = 1.31 + (decltype(CreateDXGIFactory1)*) GetProcAddress(dxgiModule, "CreateDXGIFactory1"); 1.32 + if (!createDXGIFactory1) { 1.33 + FreeLibrary(dxgiModule); 1.34 + return false; 1.35 + } 1.36 + 1.37 + HMODULE d3d10module = LoadLibraryA("d3d10_1.dll"); 1.38 + if (!d3d10module) { 1.39 + FreeLibrary(dxgiModule); 1.40 + return false; 1.41 + } 1.42 + decltype(D3D10CreateDevice1)* createD3DDevice = 1.43 + (decltype(D3D10CreateDevice1)*) GetProcAddress(d3d10module, 1.44 + "D3D10CreateDevice1"); 1.45 + if (!createD3DDevice) { 1.46 + FreeLibrary(d3d10module); 1.47 + FreeLibrary(dxgiModule); 1.48 + return false; 1.49 + } 1.50 + 1.51 + IDXGIFactory1* factory1; 1.52 + if (FAILED(createDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&factory1))) { 1.53 + FreeLibrary(d3d10module); 1.54 + FreeLibrary(dxgiModule); 1.55 + return false; 1.56 + } 1.57 + 1.58 + IDXGIAdapter1* adapter1; 1.59 + if (FAILED(factory1->EnumAdapters1(0, &adapter1))) { 1.60 + factory1->Release(); 1.61 + FreeLibrary(d3d10module); 1.62 + FreeLibrary(dxgiModule); 1.63 + return false; 1.64 + } 1.65 + 1.66 + // Try for DX10.1 1.67 + ID3D10Device1* device; 1.68 + if (FAILED(createD3DDevice(adapter1, D3D10_DRIVER_TYPE_HARDWARE, nullptr, 1.69 + D3D10_CREATE_DEVICE_BGRA_SUPPORT | 1.70 + D3D10_CREATE_DEVICE_PREVENT_INTERNAL_THREADING_OPTIMIZATIONS, 1.71 + D3D10_FEATURE_LEVEL_10_1, 1.72 + D3D10_1_SDK_VERSION, &device))) { 1.73 + // Try for DX10 1.74 + if (FAILED(createD3DDevice(adapter1, D3D10_DRIVER_TYPE_HARDWARE, nullptr, 1.75 + D3D10_CREATE_DEVICE_BGRA_SUPPORT | 1.76 + D3D10_CREATE_DEVICE_PREVENT_INTERNAL_THREADING_OPTIMIZATIONS, 1.77 + D3D10_FEATURE_LEVEL_10_0, 1.78 + D3D10_1_SDK_VERSION, &device))) { 1.79 + // Try for DX9.3 (we fall back to cairo and cairo has support for D3D 9.3) 1.80 + if (FAILED(createD3DDevice(adapter1, D3D10_DRIVER_TYPE_HARDWARE, nullptr, 1.81 + D3D10_CREATE_DEVICE_BGRA_SUPPORT | 1.82 + D3D10_CREATE_DEVICE_PREVENT_INTERNAL_THREADING_OPTIMIZATIONS, 1.83 + D3D10_FEATURE_LEVEL_9_3, 1.84 + D3D10_1_SDK_VERSION, &device))) { 1.85 + adapter1->Release(); 1.86 + factory1->Release(); 1.87 + FreeLibrary(d3d10module); 1.88 + FreeLibrary(dxgiModule); 1.89 + return false; 1.90 + } 1.91 + } 1.92 + } 1.93 + device->Release(); 1.94 + adapter1->Release(); 1.95 + factory1->Release(); 1.96 + FreeLibrary(d3d10module); 1.97 + FreeLibrary(dxgiModule); 1.98 + return true; 1.99 +}