<!DOCTYPE HTML>
<html>
<head>
<title>OffscreenCanvas transferToImageBitmap on main thread: RGB squares and on large blue square on white background.</title>
<style type="text/css">
.nomargin {
margin: 0px auto;
}
</style>
<script>
var g_swapsBeforeAck = 15;
function main()
{
draw();
waitForFinish();
}
function draw()
{
var width = 100;
var height = 100;
var aCanvas = new OffscreenCanvas(width, height);
var gl = aCanvas.getContext('webgl');
gl.enable(gl.SCISSOR_TEST);
gl.scissor(0, 50, 50, 50);
gl.clearColor(1, 0, 0, 1);
gl.clear(gl.COLOR_BUFFER_BIT);
gl.scissor(50, 50, 100, 50);
gl.clearColor(0, 1, 0, 1);
gl.clear(gl.COLOR_BUFFER_BIT);
gl.scissor(0, 0, 50, 50);
gl.clearColor(0, 0, 1, 1);
gl.clear(gl.COLOR_BUFFER_BIT);
gl.disable(gl.SCISSOR_TEST);
var image1 = aCanvas.transferToImageBitmap();
gl.clearColor(0.0, 0.0, 1.0, 1.0);
gl.clear(gl.COLOR_BUFFER_BIT);
var image2 = aCanvas.transferToImageBitmap();
var canvas1 = document.getElementById("canvas1");
var ctx1 = canvas1.getContext('bitmaprenderer');
ctx1.transferFromImageBitmap(image1);
var canvas2 = document.getElementById('canvas2');
var ctx2 = canvas2.getContext('bitmaprenderer');
ctx2.transferFromImageBitmap(image2);
}
function waitForFinish()
{
if (g_swapsBeforeAck == 0) {
domAutomationController.send("SUCCESS");
} else {
g_swapsBeforeAck--;
document.getElementById('container').style.zIndex = g_swapsBeforeAck + 1;
window.requestAnimationFrame(waitForFinish);
}
}
</script>
</head>
<body onload="main()">
<div style="position:relative; width:200px; height:200px; background-color:white">
</div>
<div id="container" style="position:absolute; top:0px; left:0px">
<canvas id="canvas1" width="100" height="100" class="nomargin"></canvas>
</div>
<div id="container" style="position:absolute; top:0px; left:150px">
<canvas id="canvas2" width="100" height="100" class="nomargin"></canvas>
</div>
</body>
</html>