1 <!DOCTYPE html> 2 <html> 3 <body> 4 <script src="../resources/runner.js"></script> 5 <script src="resources/canvas_runner.js"></script> 6 <script> 7 var sourceCanvas2D = document.createElement("canvas"); 8 var sourceCtx2D = sourceCanvas2D.getContext("2d"); 9 var destCanvas2D = document.createElement("canvas"); 10 var destCtx2D = destCanvas2D.getContext("2d"); 11 12 function setSize(sourceWidth, sourceHeight, destWidth, destHeight) { 13 sourceCanvas2D.width = sourceWidth; 14 sourceCanvas2D.height = sourceHeight; 15 destCanvas2D.width = destWidth; 16 destCanvas2D.height = destHeight; 17 } 18 19 function rand(range) { 20 return Math.floor(Math.random() * range); 21 } 22 23 function fillCanvas(ctx2d, canvas2d) { 24 ctx2d.fillStyle = "rgba(" + rand(255) + "," + rand(255) + "," + rand(255) + "," + rand(255) + ")"; 25 ctx2d.fillRect(0, 0, canvas2d.width, canvas2d.height); 26 } 27 28 function doRun() { 29 // draw static Canvas 30 destCtx2D.drawImage(sourceCanvas2D, 0, 0); 31 } 32 33 function ensureComplete() { 34 // Calling getImageData() is just to flush out the content when 35 // accelerated 2D canvas is in use. The cost of reading 1x1 pixels is low. 36 destCtx2D.getImageData(0, 0, 1, 1); 37 } 38 39 window.onload = function () { 40 // It should use setMinimumAccelerated2dCanvasSize() to enable accelerated Canvas for a specified size 41 // but this API is not available in JS or WebPage. Assume the threshold size is 256x257 42 // and the dest canvas is HW accelerated Canvas when setting its size to 1024x1024. 43 setSize(1024, 1024, 1024, 1024); 44 fillCanvas(sourceCtx2D, sourceCanvas2D); 45 CanvasRunner.start({ 46 description: "This bench test checks the speed on drawing static 2d Canvas(1024x1024) to HW accelerated Canvas2D(1024x1024).", 47 doRun: doRun, 48 ensureComplete: ensureComplete}); 49 } 50 51 </script> 52 </body> 53 </html> 54