tor-browser

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

2d.layer.non-invertible-matrix.w.html (1958B)


      1 <!DOCTYPE html>
      2 <!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
      3 <meta charset="UTF-8">
      4 <html class="reftest-wait">
      5 <link rel="match" href="2d.layer.non-invertible-matrix-expected.html">
      6 <title>Canvas test: 2d.layer.non-invertible-matrix</title>
      7 <h1>2d.layer.non-invertible-matrix</h1>
      8 <p class="desc">Test drawing layers when the transform is not invertible.</p>
      9 <canvas id="canvas" width="200" height="200">
     10  <p class="fallback">FAIL (fallback content)</p>
     11 </canvas>
     12 <script id='myWorker' type='text/worker'>
     13  self.onmessage = function(e) {
     14    const canvas = new OffscreenCanvas(200, 200);
     15    const ctx = canvas.getContext('2d');
     16 
     17    ctx.fillStyle = 'blue';
     18    ctx.fillRect(30, 30, 50, 50);
     19 
     20    // Anything below will be non-rasterizable.
     21    ctx.scale(1, 0);
     22 
     23    // Open the layer with a non-invertible matrix. The whole layer will be
     24    // non-rasterizable.
     25    ctx.beginLayer();
     26 
     27    // Because the transform is global, the matrix is still non-invertible.
     28    ctx.fillStyle = 'rgba(225, 0, 0, 1)';
     29    ctx.fillRect(40, 70, 50, 50);
     30 
     31    // Set a valid matrix in the middle of the layer. This makes the global
     32    // matrix invertible again, but because because the layer was opened with a
     33    // non-invertible matrix, the whole layer remains non-rasterizable.
     34    ctx.setTransform(1, 0, 0, 1, 0, 0);
     35 
     36    ctx.fillStyle = 'green';
     37    ctx.fillRect(70, 40, 50, 50);
     38 
     39    ctx.endLayer();
     40 
     41    const bitmap = canvas.transferToImageBitmap();
     42    self.postMessage(bitmap, bitmap);
     43  };
     44 </script>
     45 <script>
     46  const blob = new Blob([document.getElementById('myWorker').textContent]);
     47  const worker = new Worker(URL.createObjectURL(blob));
     48  worker.addEventListener('message', msg => {
     49    const outputCtx = document.getElementById("canvas").getContext('2d');
     50    outputCtx.drawImage(msg.data, 0, 0);
     51    document.documentElement.classList.remove("reftest-wait");
     52  });
     53  worker.postMessage(null);
     54 </script>
     55 </html>