offscreencanvas-sync.html (2365B)
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 Sync 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); 27 } 28 } 29 } 30 31 tickImpl(); 32 } 33 34 self.onmessage = function(e) { 35 let canvas = new OffscreenCanvas(128, 128); 36 let gl = canvas.getContext("webgl2"); 37 let sync = gl.fenceSync(gl.SYNC_GPU_COMMANDS_COMPLETE, 0); 38 gl.clearColor(0.0, 1.0, 0.0, 1.0); 39 gl.clear(gl.COLOR_BUFFER_BIT); 40 tick(function() { 41 const status = gl.getSyncParameter(sync, gl.SYNC_STATUS); 42 if (status == gl.SIGNALED) { 43 self.postMessage("PASSED - Sync object signaled successfully from worker"); 44 return false; 45 } else { 46 const err = gl.getError(); 47 if (err != 0) { 48 self.postMessage("FAILED - GL error " + err); 49 return false; 50 } 51 } 52 return true; 53 }); 54 }; 55 </script> 56 <script> 57 "use strict"; 58 description("This test ensures that sync objects work with the WebGL 2.0 context created via OffscreenCanvas."); 59 if (!window.OffscreenCanvas) { 60 testPassed("No OffscreenCanvas support"); 61 finishTest(); 62 } else { 63 var blob = new Blob([document.getElementById("myWorker").textContent]); 64 var worker = new Worker(URL.createObjectURL(blob)); 65 worker.onmessage = function(msg) { 66 if (msg.data.startsWith("PASSED")) { 67 testPassed(msg.data); 68 } else { 69 testFailed(msg.data); 70 } 71 finishTest(); 72 } 73 worker.postMessage("Start Worker"); 74 } 75 </script> 76 </body> 77 </html>