Bug 1915045 Ensure decode tasks are scheduled on BufferingState::Enter() r=media...
[gecko.git] / dom / canvas / test / webgl-mochitest / test_backends.html
blob7fc209be243248e13687e4285ca36886b403e52e
1 <!DOCTYPE HTML>
2 <html>
3 <head>
4 <meta charset='UTF-8'>
5 <script src='/tests/SimpleTest/SimpleTest.js'></script>
6 <link rel='stylesheet' href='/tests/SimpleTest/test.css'>
7 </head>
8 <body>
9 <script>
11 function RunWithPrefs(prefPairList, func) {
12 var prefEnv = {'set': prefPairList};
13 try {
14 SpecialPowers.pushPrefEnv(prefEnv, func);
15 } catch (e) {
16 console.log('Warning: Failed to set prefs: ' + JSON.stringify(prefPairList));
17 func();
21 ////////////////////////////////////////
23 var ANGLE_IS_SINGLETON = true;
25 var expectD3DType;
26 try {
27 // code borrowed from browser/modules/test/browser_taskbar_preview.js
28 var version = SpecialPowers.Services.sysinfo.getProperty('version');
29 version = parseFloat(version);
31 // Version 6.0 is Vista, 6.1 is 7.
32 if (version <= 6.0)
33 expectD3DType = 'd3d9';
34 else
35 expectD3DType = 'd3d11';
36 } catch (e) {
37 expectD3DType = 'd3d11';
40 function GetRenderer() {
41 var c = document.createElement('canvas');
42 var gl = c.getContext('experimental-webgl');
43 if (!gl)
44 return undefined;
46 var ext = gl.getExtension('WEBGL_debug_renderer_info');
47 if (!ext)
48 throw new Error('Requires WEBGL_debug_renderer_info.');
50 var renderer = gl.getParameter(ext.UNMASKED_RENDERER_WEBGL);
51 return renderer;
54 function GetRendererType() {
55 var renderer = GetRenderer();
56 if (renderer === undefined)
57 return 'none';
59 if (renderer.includes('ANGLE')) {
60 if (renderer.includes('Microsoft Basic Render Driver')) // Also includes 'Direct3D11'.
61 return 'warp';
62 if (renderer.includes('Direct3D11'))
63 return 'd3d11';
64 if (renderer.includes('Direct3D9'))
65 return 'd3d9';
67 } else {
68 return 'gl';
71 throw new Error('Unrecognized renderer type for: ' + renderer);
74 function TestActualType(testName, expectedType) {
75 var actualType = GetRendererType();
76 ok(actualType == expectedType,
77 '[' + testName + '] Expected ' + expectedType + ', was ' + actualType);
80 ////////////////////////////////////////
82 function TestDefault() {
83 var expectedType = 'gl';
84 var isWindows = (navigator.platform.indexOf('Win') == 0);
85 if (isWindows) {
86 expectedType = expectD3DType;
88 TestActualType('TestDefault', expectedType);
90 if (isWindows && !ANGLE_IS_SINGLETON) {
91 var prefPairList = [
92 ['webgl.angle.force-warp', true],
94 RunWithPrefs(prefPairList, TestWARP);
95 return;
98 var prefPairList = [
99 ['webgl.disabled', true],
101 RunWithPrefs(prefPairList, TestDisabled);
105 function TestWARP() {
106 var expectedType = (expectD3DType == 'd3d11') ? 'warp' : 'none';
107 TestActualType('TestWARP', expectedType);
109 var prefPairList = [
110 ['webgl.angle.force-warp', false],
111 ['webgl.angle.force-d3d11', true],
113 RunWithPrefs(prefPairList, TestD3D11);
117 function TestD3D11() {
118 var expectedType = (expectD3DType == 'd3d11') ? 'd3d11' : 'none';
119 TestActualType('TestD3D11', expectedType);
121 var prefPairList = [
122 ['webgl.angle.force-d3d11', false],
123 ['webgl.angle.try-d3d11', false],
125 RunWithPrefs(prefPairList, TestD3D9);
129 function TestD3D9() {
130 TestActualType('TestD3D9', 'd3d9');
132 var prefPairList = [
133 ['webgl.angle.try-d3d11', true],
134 ['webgl.disable-angle', true],
136 RunWithPrefs(prefPairList, TestWinGL);
140 function TestWinGL() {
141 TestActualType('TestWinGL', 'gl');
143 var prefPairList = [
144 ['webgl.disabled', true],
146 RunWithPrefs(prefPairList, TestDisabled);
150 function TestDisabled() {
151 TestActualType('TestDisabled', 'none');
153 SimpleTest.finish();
156 ////////////////////////////////////////
158 SimpleTest.waitForExplicitFinish();
160 var prefPairList = [
161 ['webgl.force-enabled', true],
162 ['webgl.enable-debug-renderer-info', true],
164 RunWithPrefs(prefPairList, TestDefault);
166 </script>
167 </body>
168 </html>