| <!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"); |
| var dummyCanvas2D = document.createElement("canvas"); |
| var dummyCtx2D = dummyCanvas2D.getContext("2d"); |
| |
| function setSize(sourceWidth, sourceHeight, destWidth, destHeight) { |
| sourceCanvas2D.width = sourceWidth; |
| sourceCanvas2D.height = sourceHeight; |
| destCanvas2D.width = destWidth; |
| destCanvas2D.height = destHeight; |
| dummyCanvas2D.width = destWidth; |
| dummyCanvas2D.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() { |
| // Using destCanvas2D as a source image is just to flush out the content when |
| // accelerated 2D canvas is in use. |
| dummyCtx2D.drawImage(destCanvas2D, 0, 0, 1, 1, 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> |