Backed out changeset 7272b7396c78 (bug 1932758) for causing fenix debug failures...
[gecko.git] / dom / canvas / test / webgl-conf / checkout / conformance / rendering / draw-webgl-to-canvas-2d-repeatedly.html
blobd9a83e9166e079a9a72a7cdbb9bc8547c2c657c4
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 -->
7 <!DOCTYPE html>
8 <html>
9 <head>
10 <meta charset="utf-8">
11 <title>Draw WebGL to Canvas2D Repeatedly</title>
12 <link rel="stylesheet" href="../../resources/js-test-style.css"/>
13 <script src="../../js/js-test-pre.js"></script>
14 <script src="../../js/webgl-test-utils.js"></script>
15 </head>
16 <body>
17 <div id="description"></div>
18 <div id="console"></div>
19 <canvas id="canvas-webgl" width="256" height="256"></canvas>
20 <canvas id="canvas-2d" width="256" height="256"></canvas>
21 <script>
22 "use strict";
23 const wtu = WebGLTestUtils;
25 const sz = 256;
27 function drawTo2DCanvas(c2, webGLCanvas) {
28 // Always clear 2D canvas to solid green first.
29 c2.clearRect(0, 0, sz, sz);
30 c2.fillStyle = 'rgb(0,255,0)';
31 c2.fillRect(0, 0, sz, sz);
32 // Draw WebGL canvas to this canvas.
33 c2.drawImage(webGLCanvas, 0, 0);
36 function runTest() {
37 description();
38 debug('Repeatedly drawing a WebGL canvas to a 2D canvas should only draw the most recently rendered WebGL content.');
39 debug('Regression test for <a href="http://crbug.com/894021">http://crbug.com/894021</a>');
41 let c2 = document.getElementById('canvas-2d').getContext('2d');
42 let webGLCanvas = document.getElementById('canvas-webgl');
43 let gl = wtu.create3DContext(webGLCanvas, { alpha: true, antialias: false, premultipliedAlpha: true });
44 let tolerance = 2;
46 // Clear left half of WebGL canvas to red and right half to
47 // transparent black.
48 gl.disable(gl.SCISSOR_TEST);
49 gl.clearColor(0.0, 0.0, 0.0, 0.0);
50 gl.clear(gl.COLOR_BUFFER_BIT);
51 gl.scissor(0, 0, sz / 2, sz);
52 gl.enable(gl.SCISSOR_TEST);
53 gl.clearColor(1.0, 0.0, 0.0, 1.0);
54 gl.clear(gl.COLOR_BUFFER_BIT);
55 // Draw to 2D canvas.
56 drawTo2DCanvas(c2, webGLCanvas);
58 // Clear right half of WebGL canvas to red and left half to
59 // transparent black.
60 gl.disable(gl.SCISSOR_TEST);
61 gl.clearColor(0.0, 0.0, 0.0, 0.0);
62 gl.clear(gl.COLOR_BUFFER_BIT);
63 gl.scissor(sz / 2, 0, sz / 2, sz);
64 gl.enable(gl.SCISSOR_TEST);
65 gl.clearColor(1.0, 0.0, 0.0, 1.0);
66 gl.clear(gl.COLOR_BUFFER_BIT);
67 // Draw to 2D canvas.
68 drawTo2DCanvas(c2, webGLCanvas);
70 // Clear WebGL canvas to transparent black.
71 gl.disable(gl.SCISSOR_TEST);
72 gl.clearColor(0.0, 0.0, 0.0, 0.0);
73 gl.clear(gl.COLOR_BUFFER_BIT);
74 // Draw to 2D canvas.
75 drawTo2DCanvas(c2, webGLCanvas);
77 // 2D canvas should be green.
78 // In the error case, the rendering results from earlier draws were
79 // being accumulated, so the 2D canvas was ultimately red.
80 wtu.checkCanvasRect(c2, 0, 0, sz, sz,
81 [ 0, 255, 0, 255 ],
82 "should be green",
83 tolerance);
85 finishTest();
88 requestAnimationFrame(runTest);
89 </script>
90 </body>
91 </html>