tor-browser

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

tex-image-and-sub-image-3d-with-image-bitmap-from-canvas.js (2511B)


      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 function generateTest(internalFormat, pixelFormat, pixelType, prologue, resourcePath, defaultContextVersion) {
      8    var wtu = WebGLTestUtils;
      9    var tiu = TexImageUtils;
     10    var gl = null;
     11    var successfullyParsed = false;
     12 
     13    function init()
     14    {
     15        description('Verify texImage3D and texSubImage3D code paths taking ImageBitmap created from an HTMLCanvasElement (' + internalFormat + '/' + pixelFormat + '/' + pixelType + ')');
     16 
     17        if(!window.createImageBitmap || !window.ImageBitmap) {
     18            finishTest();
     19            return;
     20        }
     21 
     22        // Set the default context version while still allowing the webglVersion URL query string to override it.
     23        wtu.setDefault3DContextVersion(defaultContextVersion);
     24        gl = wtu.create3DContext("example");
     25 
     26        if (!prologue(gl)) {
     27            finishTest();
     28            return;
     29        }
     30 
     31        gl.clearColor(0,0,0,1);
     32        gl.clearDepth(1);
     33 
     34        var testCanvas = document.createElement('canvas');
     35        var ctx = testCanvas.getContext("2d");
     36        setCanvasToMin(ctx);
     37        runImageBitmapTest(testCanvas, 0.5, internalFormat, pixelFormat, pixelType, gl, tiu, wtu, true)
     38        .then(() => {
     39            setCanvasTo257x257(ctx);
     40            return runImageBitmapTest(testCanvas, 0.5, internalFormat, pixelFormat, pixelType, gl, tiu, wtu, true);
     41        }).then(() => {
     42            finishTest();
     43        });
     44    }
     45 
     46    function setCanvasToRedGreen(ctx) {
     47        var width = ctx.canvas.width;
     48        var halfWidth = Math.floor(width / 2);
     49        var height = ctx.canvas.height;
     50        var halfHeight = Math.floor(height / 2);
     51        ctx.fillStyle = "rgba(255, 0, 0, 1)";
     52        ctx.fillRect(0, 0, halfWidth, halfHeight);
     53        ctx.fillStyle = "rgba(255, 0, 0, 0.5)";
     54        ctx.fillRect(halfWidth, 0, halfWidth, halfHeight);
     55        ctx.fillStyle = "rgba(0, 255, 0, 1)";
     56        ctx.fillRect(0, halfHeight, halfWidth, halfHeight);
     57        ctx.fillStyle = "rgba(0, 255, 0, 0.5)";
     58        ctx.fillRect(halfWidth, halfHeight, halfWidth, halfHeight);
     59    }
     60 
     61    function setCanvasToMin(ctx) {
     62        ctx.canvas.width = 2;
     63        ctx.canvas.height = 2;
     64        setCanvasToRedGreen(ctx);
     65    }
     66 
     67    function setCanvasTo257x257(ctx) {
     68        ctx.canvas.width = 257;
     69        ctx.canvas.height = 257;
     70        setCanvasToRedGreen(ctx);
     71    }
     72 
     73    return init;
     74 }