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