Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
- This WPT test may be referenced by the following Test IDs:
- /html/canvas/offscreen/fill-and-stroke-styles/2d.gradient.radial.transform.translated.repeat.w.html - WPT Dashboard Interop Dashboard
<!DOCTYPE html>
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
<meta charset="UTF-8">
<html class="reftest-wait">
<link rel="match" href="2d.gradient.radial.transform.translated.repeat-expected.html">
<script src="/common/reftest-wait.js"></script>
<title>Canvas test: 2d.gradient.radial.transform.translated.repeat</title>
<h1>2d.gradient.radial.transform.translated.repeat</h1>
<p class="desc">Filling with the same radial gradient under different translations draws each gradient at its own position</p>
<canvas id="canvas" width="300" height="300">
<p class="fallback">FAIL (fallback content)</p>
</canvas>
<script id='myWorker' type='text/worker'>
self.onmessage = function(e) {
try {
const canvas = new OffscreenCanvas(300, 300);
const ctx = canvas.getContext('2d');
for (let i = 0; i < 3; i++) {
ctx.save();
ctx.translate(20 + i * 90, 50);
ctx.beginPath();
ctx.rect(0, 0, 80, 80);
ctx.clip();
const g = ctx.createRadialGradient(30, 30, 0, 40, 40, 40);
g.addColorStop(0, 'rgb(180, 180, 230)');
g.addColorStop(1, 'rgb(40, 40, 110)');
ctx.fillStyle = g;
ctx.fillRect(-20 - i * 90, -50, 300, 300);
ctx.restore();
}
const bitmap = canvas.transferToImageBitmap();
self.postMessage({ type: 'bitmap', bitmap }, [bitmap]);
} catch (error) {
self.postMessage({ type: 'error', message: error });
}
};
</script>
<script>
const blob = new Blob([document.getElementById('myWorker').textContent]);
const worker = new Worker(URL.createObjectURL(blob));
worker.onerror = failOnError;
worker.onmessage = reftestStep(msg => {
if (msg.data.type === 'error') {
failOnError(msg.data.message);
return;
}
const outputCtx = document.getElementById("canvas").getContext('2d');
outputCtx.drawImage(msg.data.bitmap, 0, 0);
takeScreenshot();
});
worker.postMessage(null);
</script>
</html>