tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

context-size-change.html (2260B)


      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 
      7 <!DOCTYPE html>
      8 <html>
      9 <head>
     10 <meta charset="utf-8">
     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 
     15 <script>
     16 "use strict";
     17 
     18 // These declarations need to be global for "shouldBe" to see them
     19 var gl;
     20 var pixel = [0, 0, 0, 1];
     21 var canvas;
     22 
     23 function init()
     24 {
     25    description('Verify that changing the size of an antialiased WebGL context does not cause it to stop working.');
     26 
     27    runTest();
     28 }
     29 
     30 function getWebGL(canvasWidth, canvasHeight, contextAttribs)
     31 {
     32    canvas = document.createElement("canvas");
     33    if (!canvas)
     34        return null;
     35    canvas.width = canvasWidth;
     36    canvas.height = canvasHeight;
     37 
     38    gl = WebGLTestUtils.create3DContext(canvas, contextAttribs);
     39    if (!gl)
     40        return null;
     41 
     42    return gl;
     43 }
     44 
     45 function runTest()
     46 {
     47    shouldBeNonNull("gl = getWebGL(1, 1, { alpha: false, antialias: true })");
     48 
     49    // Clear to black.
     50    gl.clearColor(0.0, 0.0, 0.0, 1.0);
     51    gl.clear(gl.COLOR_BUFFER_BIT);
     52 
     53    // Check that the pixel's R channel is 0.
     54    var buf = new Uint8Array(1 * 1 * 4);
     55    gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, buf);
     56    pixel[0] = buf[0];
     57    shouldBeTrue("pixel[0] == 0");
     58 
     59    // Change the size of the canvas.
     60    canvas.width = 3;
     61    canvas.height = 3;
     62 
     63    // Clear to black.
     64    gl.clearColor(0.0, 0.0, 0.0, 1.0);
     65    gl.clear(gl.COLOR_BUFFER_BIT);
     66 
     67    // Clear the top-left pixel to white.
     68    gl.enable(gl.SCISSOR_TEST);
     69    gl.scissor(0, 0, 1, 1);
     70    gl.clearColor(1.0, 1.0, 1.0, 1.0);
     71    gl.clear(gl.COLOR_BUFFER_BIT);
     72 
     73    // Check that the top-left pixel has R channel 255.
     74    gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, buf);
     75    pixel[0] = buf[0];
     76    shouldBeTrue("pixel[0] == 255");
     77 
     78    // Check that the bottom-right pixel has R channel 0.
     79    gl.readPixels(2, 2, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, buf);
     80    pixel[0] = buf[0];
     81    shouldBeTrue("pixel[0] == 0");
     82 
     83    finishTest();
     84 }
     85 
     86 </script>
     87 </head>
     88 <body onload="init()">
     89 <div id="description"></div>
     90 <div id="console"></div>
     91 </body>
     92 </html>