2d.layer.non-invertible-matrix.with-render-states.plain-layer.w.html (2260B)
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.with-render-states.plain-layer-expected.html"> 6 <title>Canvas test: 2d.layer.non-invertible-matrix.with-render-states.plain-layer</title> 7 <h1>2d.layer.non-invertible-matrix.with-render-states.plain-layer</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 ctx.globalAlpha = 0.8; 24 ctx.globalCompositeOperation = 'multiply'; 25 ctx.shadowOffsetX = 0; 26 ctx.shadowOffsetY = 20; 27 ctx.shadowColor = 'rgba(255, 165, 0, 0.6)'; 28 ctx.filter = 'blur(10px)'; 29 30 // Open the layer with a non-invertible matrix. The whole layer will be 31 // non-rasterizable. 32 ctx.beginLayer(); 33 34 // Because the transform is global, the matrix is still non-invertible. 35 ctx.fillStyle = 'rgba(225, 0, 0, 1)'; 36 ctx.fillRect(40, 70, 50, 50); 37 38 // Set a valid matrix in the middle of the layer. This makes the global 39 // matrix invertible again, but because because the layer was opened with a 40 // non-invertible matrix, the whole layer remains non-rasterizable. 41 ctx.setTransform(1, 0, 0, 1, 0, 0); 42 43 ctx.fillStyle = 'green'; 44 ctx.fillRect(70, 40, 50, 50); 45 46 ctx.endLayer(); 47 48 const bitmap = canvas.transferToImageBitmap(); 49 self.postMessage(bitmap, bitmap); 50 }; 51 </script> 52 <script> 53 const blob = new Blob([document.getElementById('myWorker').textContent]); 54 const worker = new Worker(URL.createObjectURL(blob)); 55 worker.addEventListener('message', msg => { 56 const outputCtx = document.getElementById("canvas").getContext('2d'); 57 outputCtx.drawImage(msg.data, 0, 0); 58 document.documentElement.classList.remove("reftest-wait"); 59 }); 60 worker.postMessage(null); 61 </script> 62 </html>