content/canvas/test/webgl-mochitest/driver-info.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 DriverInfo = (function() {
michael@0 2 // ---------------------------------------------------------------------------
michael@0 3 // Debug info handling
michael@0 4
michael@0 5 function defaultInfoFunc(str) {
michael@0 6 console.log('Info: ' + str);
michael@0 7 }
michael@0 8
michael@0 9 var gInfoFunc = defaultInfoFunc;
michael@0 10 function setInfoFunc(func) {
michael@0 11 gInfoFunc = func;
michael@0 12 }
michael@0 13
michael@0 14 function info(str) {
michael@0 15 gInfoFunc(str);
michael@0 16 }
michael@0 17
michael@0 18 // ---------------------------------------------------------------------------
michael@0 19 // OS and driver identification
michael@0 20 // Stolen from content/canvas/test/webgl/test_webgl_conformance_test_suite.html
michael@0 21 function detectDriverInfo() {
michael@0 22 try {
michael@0 23 var cc = SpecialPowers.Cc;
michael@0 24 } catch (e) {
michael@0 25 throw 'No SpecialPowers!';
michael@0 26 }
michael@0 27
michael@0 28 const Cc = SpecialPowers.Cc;
michael@0 29 const Ci = SpecialPowers.Ci;
michael@0 30 var doc = Cc["@mozilla.org/xmlextras/domparser;1"].createInstance(Ci.nsIDOMParser).parseFromString("<html/>", "text/html");
michael@0 31
michael@0 32 var canvas = doc.createElement("canvas");
michael@0 33 canvas.width = 1;
michael@0 34 canvas.height = 1;
michael@0 35
michael@0 36 var type = "";
michael@0 37 var gl = null;
michael@0 38 try {
michael@0 39 gl = canvas.getContext("experimental-webgl");
michael@0 40 } catch(e) {}
michael@0 41
michael@0 42 if (!gl) {
michael@0 43 info('Failed to create WebGL context for querying driver info.');
michael@0 44 throw 'WebGL failed';
michael@0 45 }
michael@0 46
michael@0 47 var ext = gl.getExtension("WEBGL_debug_renderer_info");
michael@0 48 // this extension is unconditionally available to chrome. No need to check.
michael@0 49
michael@0 50 var webglRenderer = gl.getParameter(ext.UNMASKED_RENDERER_WEBGL);
michael@0 51 var webglVendor = gl.getParameter(ext.UNMASKED_VENDOR_WEBGL);
michael@0 52 return [webglVendor, webglRenderer];
michael@0 53 }
michael@0 54
michael@0 55 function detectOSInfo() {
michael@0 56 try {
michael@0 57 var cc = SpecialPowers.Cc;
michael@0 58 } catch (e) {
michael@0 59 throw 'No SpecialPowers!';
michael@0 60 }
michael@0 61
michael@0 62 const Cc = SpecialPowers.Cc;
michael@0 63 const Ci = SpecialPowers.Ci;
michael@0 64
michael@0 65 // From reftest.js:
michael@0 66 var runtime = Cc['@mozilla.org/xre/app-info;1'].getService(Ci.nsIXULRuntime);
michael@0 67
michael@0 68 var os = null;
michael@0 69 var version = null;
michael@0 70 if (navigator.platform.indexOf('Win') == 0) {
michael@0 71 os = OS.WINDOWS;
michael@0 72
michael@0 73 // code borrowed from browser/modules/test/browser_taskbar_preview.js
michael@0 74 version = SpecialPowers.Services.sysinfo.getProperty('version');
michael@0 75 version = parseFloat(version);
michael@0 76 // Version 6.0 is Vista, 6.1 is 7.
michael@0 77
michael@0 78 } else if (navigator.platform.indexOf('Mac') == 0) {
michael@0 79 os = OS.MAC;
michael@0 80
michael@0 81 var versionMatch = /Mac OS X (\d+.\d+)/.exec(navigator.userAgent);
michael@0 82 version = versionMatch ? parseFloat(versionMatch[1]) : null;
michael@0 83
michael@0 84 } else if (runtime.widgetToolkit == 'gonk') {
michael@0 85 os = OS.B2G;
michael@0 86
michael@0 87 } else if (navigator.appVersion.indexOf('Android') != -1) {
michael@0 88 os = OS.ANDROID;
michael@0 89 // From layout/tools/reftest/reftest.js:
michael@0 90 version = SpecialPowers.Services.sysinfo.getProperty('version');
michael@0 91
michael@0 92 } else if (navigator.platform.indexOf('Linux') == 0) {
michael@0 93 // Must be checked after android, as android also has a 'Linux' platform string.
michael@0 94 os = OS.LINUX;
michael@0 95 }
michael@0 96
michael@0 97 return [os, version];
michael@0 98 }
michael@0 99
michael@0 100 var OS = {
michael@0 101 WINDOWS: 'windows',
michael@0 102 MAC: 'mac',
michael@0 103 LINUX: 'linux',
michael@0 104 ANDROID: 'android',
michael@0 105 B2G: 'b2g',
michael@0 106 };
michael@0 107
michael@0 108 var DRIVER = {
michael@0 109 MESA: 'mesa',
michael@0 110 NVIDIA: 'nvidia',
michael@0 111 ANDROID_X86_EMULATOR: 'android x86 emulator',
michael@0 112 ANGLE: 'angle',
michael@0 113 };
michael@0 114
michael@0 115 var kOS = null;
michael@0 116 var kOSVersion = null;
michael@0 117 var kDriver = null;
michael@0 118
michael@0 119 try {
michael@0 120 [kOS, kOSVersion] = detectOSInfo();
michael@0 121 } catch (e) {
michael@0 122 // Generally just fails when we don't have SpecialPowers.
michael@0 123 }
michael@0 124
michael@0 125 try {
michael@0 126 var glVendor, glRenderer;
michael@0 127 [glVendor, glRenderer] = detectDriverInfo();
michael@0 128 info('GL vendor: ' + glVendor);
michael@0 129 info('GL renderer: ' + glRenderer);
michael@0 130
michael@0 131 if (glRenderer.contains('llvmpipe')) {
michael@0 132 kDriver = DRIVER.MESA;
michael@0 133 } else if (glRenderer.contains('Android Emulator')) {
michael@0 134 kDriver = DRIVER.ANDROID_X86_EMULATOR;
michael@0 135 } else if (glRenderer.contains('ANGLE')) {
michael@0 136 kDriver = DRIVER.ANGLE;
michael@0 137 } else if (glVendor.contains('NVIDIA')) {
michael@0 138 kDriver = DRIVER.NVIDIA;
michael@0 139 }
michael@0 140 } catch (e) {
michael@0 141 // detectDriverInfo is fallible where WebGL fails.
michael@0 142 }
michael@0 143
michael@0 144 if (kOS) {
michael@0 145 info('OS detected as: ' + kOS);
michael@0 146 info(' Version: ' + kOSVersion);
michael@0 147 } else {
michael@0 148 info('OS not detected.');
michael@0 149 info(' `platform`: ' + navigator.platform);
michael@0 150 info(' `appVersion`: ' + navigator.appVersion);
michael@0 151 info(' `userAgent`: ' + navigator.userAgent);
michael@0 152 }
michael@0 153 if (kDriver) {
michael@0 154 info('GL driver detected as: ' + kDriver);
michael@0 155 } else {
michael@0 156 info('GL driver not detected.');
michael@0 157 }
michael@0 158
michael@0 159 return {
michael@0 160 setInfoFunc: setInfoFunc,
michael@0 161
michael@0 162 OS: OS,
michael@0 163 DRIVER: DRIVER,
michael@0 164 getOS: function() { return kOS; },
michael@0 165 getDriver: function() { return kDriver; },
michael@0 166 getOSVersion: function() { return kOSVersion; },
michael@0 167 };
michael@0 168 })();
michael@0 169

mercurial