Backed out changeset 8fc3326bce7f (bug 1943032) for causing failures at browser_tab_g...
[gecko.git] / dom / canvas / test / webgl-conf / checkout / conformance / offscreencanvas / offscreencanvas-timer-query.html
blob0d32f14c1927abd442c5093d92424e77760c8347
1 <!--
2 Copyright (c) 2019 The Khronos Group Inc.
3 Use of this source code is governed by an MIT-style license that can be
4 found in the LICENSE.txt file.
5 -->
6 <!DOCTYPE html>
7 <html>
8 <head>
9 <meta charset="utf-8">
10 <title>Test for Timer Query objects with OffscreenCanvas</title>
11 <link rel="stylesheet" href="../../resources/js-test-style.css"/>
12 <script src="../../js/js-test-pre.js"></script>
13 <script src="../../js/webgl-test-utils.js"></script>
14 </head>
15 <body>
16 <div id="description"></div>
17 <div id="console"></div>
18 <script id='myWorker' type='text/worker'>
19 function tick(callback) {
20 function tickImpl() {
21 const res = callback();
22 if (res) {
23 if (requestAnimationFrame) {
24 requestAnimationFrame(tickImpl);
25 } else {
26 setTimeout(tickImpl, 10);
31 tickImpl();
34 self.onmessage = function(e) {
35 let canvas = new OffscreenCanvas(128, 128);
36 let gl = canvas.getContext("webgl");
37 let ext = gl.getExtension("EXT_disjoint_timer_query");
38 if (!ext) {
39 self.postMessage("PASSED - no EXT_disjoint_timer_query extension - this is legal");
40 return false;
42 let query = ext.createQueryEXT();
43 ext.beginQueryEXT(ext.TIME_ELAPSED_EXT, query);
44 ext.endQueryEXT(ext.TIME_ELAPSED_EXT);
45 gl.clearColor(0.0, 1.0, 0.0, 1.0);
46 gl.clear(gl.COLOR_BUFFER_BIT);
47 tick(function() {
48 const status = ext.getQueryObjectEXT(query, ext.QUERY_RESULT_AVAILABLE_EXT);
49 if (status) {
50 self.postMessage("PASSED - timer query object completed successfully on worker");
51 return false;
52 } else {
53 const err = gl.getError();
54 if (err != 0) {
55 self.postMessage("FAILED - GL error " + err);
56 return false;
59 return true;
60 });
62 </script>
63 <script>
64 "use strict";
65 description("This test ensures that timer query objects work with the WebGL 1.0 context created via OffscreenCanvas.");
66 if (!window.OffscreenCanvas) {
67 testPassed("No OffscreenCanvas support");
68 finishTest();
69 } else {
70 var blob = new Blob([document.getElementById('myWorker').textContent]);
71 var worker = new Worker(URL.createObjectURL(blob));
72 worker.onmessage = function(msg) {
73 if (msg.data.startsWith("PASSED")) {
74 testPassed(msg.data);
75 } else {
76 testFailed(msg.data);
78 finishTest();
80 worker.postMessage("Start Worker");
82 </script>
83 </body>
84 </html>