blob: 1e62566f0e31b7f17d167e6b3157396bd7d5dc06 [file] [log] [blame]
<!DOCTYPE html>
<html>
<body>
<script src="../resources/runner.js"></script>
<script src="resources/canvas_runner.js"></script>
<script>
var sourceCanvas2D = document.createElement("canvas");
var sourceCtx2D = sourceCanvas2D.getContext("2d");
var destCanvas2D = document.createElement("canvas");
var destCtx2D = destCanvas2D.getContext("2d");
function setSize(sourceWidth, sourceHeight, destWidth, destHeight) {
sourceCanvas2D.width = sourceWidth;
sourceCanvas2D.height = sourceHeight;
destCanvas2D.width = destWidth;
destCanvas2D.height = destHeight;
}
function rand(range) {
return Math.floor(Math.random() * range);
}
function fillCanvas(ctx2d, canvas2d) {
ctx2d.fillStyle = "rgba(" + rand(255) + "," + rand(255) + "," + rand(255) + "," + rand(255) + ")";
ctx2d.fillRect(0, 0, canvas2d.width, canvas2d.height);
}
function doRun() {
// draw static Canvas
destCtx2D.drawImage(sourceCanvas2D, 0, 0);
}
function ensureComplete() {
// Calling getImageData() is just to flush out the content when
// accelerated 2D canvas is in use. The cost of reading 1x1 pixels is low.
destCtx2D.getImageData(0, 0, 1, 1);
}
window.onload = function () {
// It should use setMinimumAccelerated2dCanvasSize() to enable accelerated Canvas for a specified size
// but this API is not available in JS or WebPage. Assume the threshold size is 256x257
// and the dest canvas is HW accelerated Canvas when setting its size to 1024x1024.
setSize(1024, 1024, 1024, 1024);
fillCanvas(sourceCtx2D, sourceCanvas2D);
CanvasRunner.start({
description: "This bench test checks the speed on drawing static 2d Canvas(1024x1024) to HW accelerated Canvas2D(1024x1024).",
doRun: doRun,
ensureComplete: ensureComplete});
}
</script>
</body>
</html>