Backed out changeset 7272b7396c78 (bug 1932758) for causing fenix debug failures...
[gecko.git] / dom / canvas / test / webgl-conf / checkout / conformance2 / offscreencanvas / offscreencanvas-query.html
blob8d9e92e511d2ab36b7211dbf92c277aab2f9363c
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 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("webgl2");
37 let query = gl.createQuery();
38 gl.beginQuery(gl.ANY_SAMPLES_PASSED_CONSERVATIVE, query);
39 gl.endQuery(gl.ANY_SAMPLES_PASSED_CONSERVATIVE);
40 gl.clearColor(0.0, 1.0, 0.0, 1.0);
41 gl.clear(gl.COLOR_BUFFER_BIT);
42 tick(function() {
43 const status = gl.getQueryParameter(query, gl.QUERY_RESULT_AVAILABLE);
44 if (status) {
45 self.postMessage("PASSED - query object completed successfully from worker");
46 return false;
47 } else {
48 const err = gl.getError();
49 if (err != 0) {
50 self.postMessage("FAILED - GL error " + err);
51 return false;
54 return true;
55 });
57 </script>
58 <script>
59 "use strict";
60 description("This test ensures that query objects work with the WebGL 2.0 context created via OffscreenCanvas.");
61 if (!window.OffscreenCanvas) {
62 testPassed("No OffscreenCanvas support");
63 finishTest();
64 } else {
65 var blob = new Blob([document.getElementById("myWorker").textContent]);
66 var worker = new Worker(URL.createObjectURL(blob));
67 worker.onmessage = function(msg) {
68 if (msg.data.startsWith("PASSED")) {
69 testPassed(msg.data);
70 } else {
71 testFailed(msg.data);
73 finishTest();
75 worker.postMessage("Start Worker");
77 </script>
78 </body>
79 </html>