Commit a156973a authored by Aaron Krajeski's avatar Aaron Krajeski Committed by Commit Bot

Add canvas to canvas perf test

With deferral enabled we can get a lot of resource thrash when
intermediate canvases and contexts are created, updated and drawn
to a target canvas multiple times in a tight loop.

Add a perf test for this.

Bug: 1049491
Change-Id: I360ed39a36027bd6efafddee5582a64b90eb3ae7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2053727Reviewed-by: default avatarKhushal <khushalsagar@chromium.org>
Reviewed-by: default avatarAaron Krajeski <aaronhk@chromium.org>
Reviewed-by: default avatarFernando Serboncini <fserb@chromium.org>
Commit-Queue: Aaron Krajeski <aaronhk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#741517}
parent ff6a3597
<!DOCTYPE html>
<html>
<body>
<script src="../resources/runner.js"></script>
<script src="resources/canvas_runner.js"></script>
<script>
// With deferral enabled we can get a lot of resource thrash when intermediate
// canvases and contexts are created, updated and drawn to a target canvas
// multiple times in a tight loop.
// See crbug.com/1030108
// We're more likely to see regressions with large canvases
const size = 1024;
const targetCanvas = document.createElement("canvas");
targetCanvas.width = targetCanvas.height = size;
document.body.appendChild(targetCanvas);
const targetCtx = targetCanvas.getContext("2d");
const intermediateCanvas = document.createElement("canvas");
intermediateCanvas.width = intermediateCanvas.height = size;
const intermediateCtx = intermediateCanvas.getContext("2d");
function rand(range) {
return Math.floor(Math.random() * range);
}
function randomColor() {
return "rgba(" + rand(255) + "," + rand(255) + "," + rand(255) + "," + rand(255) + ")";
}
function makeAndFillCanvasWithRandomColor(i) {
intermediateCtx.fillStyle = randomColor();
intermediateCtx.fillRect(0, 0, intermediateCanvas.width, intermediateCanvas.height);
targetCtx.drawImage(intermediateCanvas, 0, 0);
}
function doRun() {
// Make and fill many canvases
for (let i = 0; i < 50; i++) {
makeAndFillCanvasWithRandomColor(i);
}
}
window.onload = function () {
CanvasRunner.start({
description: "This benchmark tests the performance of creating many intermediate canvases and drawing them onto a target canvas in a tight loop",
doRun: doRun});
}
</script>
</body>
</html>
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment