blob: d2fe21285742b731e811187d51c0a17d5d8d08fc [file] [log] [blame]
<!DOCTYPE HTML>
<!-- READ BEFORE UPDATING:
If this test is updated make sure to increment the "revision" value of the
associated test in content/test/gpu/gpu_tests/pixel_test_pages.py. This will ensure
that the baseline images are regenerated on the next run.
-->
<html>
<head>
<title>OffscreenCanvas 2d commit flow on main thread: Four-color squares on white background.</title>
<style type="text/css">
.nomargin {
margin: 0px auto;
}
</style>
</head>
<body onload="main()">
<div style="position:relative; width:300px; height:300px; background-color:white">
</div>
<div id="container" style="position:absolute; top:0px; left:0px">
<canvas id="c" width="200" height="200" class="nomargin"></canvas>
</div>
<script>
var g_swapsBeforeAck = 15;
function main()
{
drawLoop();
}
var g_animationFrameNumber = 0;
var canvas = document.getElementById("c");
var offscreenCanvas = canvas.transferControlToOffscreen();
var offscreen2d = offscreenCanvas.getContext("2d");
offscreen2d.fillStyle = "red";
offscreen2d.fillRect(0, 0, 200, 200);
function drawLoop()
{
if (g_animationFrameNumber < 10) {
g_animationFrameNumber++;
// Purposely intersperse overdraw and non-overdraw commit cases to see
// if OffscreenCanvas commit() handles both cases well.
if (0 == g_animationFrameNumber % 2) {
// When promise is used, the next drawLoop() is called after the first
// frame is resolved; therefore there is no overdraw in this case.
offscreen2d.commit().then(drawLoop);
} else {
// When the next drawLoop() is invoked regardless the promise resolve
// status of the previous commit(), the frame committed in the next
// drawLoop() is very likely to be overdrawn.
offscreen2d.commit();
drawLoop();
}
} else {
offscreen2d.fillStyle = "red";
offscreen2d.fillRect(0, 0, 100, 100);
offscreen2d.fillStyle = "green";
offscreen2d.fillRect(100, 0, 100, 100);
offscreen2d.fillStyle = "blue";
offscreen2d.fillRect(0, 100, 100, 100);
offscreen2d.fillStyle = "black";
offscreen2d.fillRect(100, 100, 100, 100);
offscreen2d.commit();
// The following fill is never committed
offscreen2d.fillStyle = "blue";
offscreen2d.fillRect(0, 0, 200, 200);
waitForFinish();
}
}
function waitForFinish()
{
if (g_swapsBeforeAck == 0) {
domAutomationController.setAutomationId(1);
domAutomationController.send("SUCCESS");
} else {
g_swapsBeforeAck--;
document.getElementById('container').style.zIndex = g_swapsBeforeAck + 1;
window.requestAnimationFrame(waitForFinish);
}
}
</script>
</body>
</html>