Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <html> | 2 <html> |
| 3 <body> | 3 <body> |
| 4 <video id="video" loop></video> | 4 <video id="video" loop></video> |
| 5 <script src="../resources/runner.js"></script> | 5 <script src="../resources/runner.js"></script> |
| 6 <script src="resources/canvas_runner.js"></script> | 6 <script src="resources/canvas_runner.js"></script> |
| 7 <script> | 7 <script> |
| 8 var videoElement = document.getElementById("video"); | 8 var videoElement = document.getElementById("video"); |
| 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(width, height) { | 17 function setSize(width, height) { |
| 13 destCanvas2D.width = width; | 18 destCanvas2D.width = width; |
| 14 destCanvas2D.height = height; | 19 destCanvas2D.height = height; |
| 15 } | 20 } |
| 16 | 21 |
| 17 function startPerfTest() { | 22 function startPerfTest() { |
| 18 CanvasRunner.start({ | 23 CanvasRunner.start({ |
| 19 description: "This bench test checks the speed on drawing Video element to HW accelerated Canvas2D(1024x1024).", | 24 description: "This bench test checks the speed on drawing Video element to HW accelerated Canvas2D(1024x1024).", |
| 20 doRun: doRun, | 25 doRun: doRun, |
| 21 ensureComplete: ensureComplete}); | 26 ensureComplete: ensureComplete}); |
| 22 } | 27 } |
| 23 | 28 |
| 24 function doRun() { | 29 function ensureComplete() { |
| 25 // draw Video | 30 // Using destCanvas2D a source image is just to flush out the content when |
| 26 destCtx2D.drawImage(videoElement, 0, 0); | 31 // accelerated 2D canvas is in use. |
| 32 dummyCtx2D.drawImage(destCanvas2D, 0, 0, 1, 1, 0, 0, 1, 1); | |
| 27 } | 33 } |
| 28 | 34 |
| 29 function ensureComplete() { | 35 function ensureComplete() { |
| 30 // Calling getImageData() is just to flush out the content when | 36 // Calling getImageData() is just to flush out the content when |
| 31 // accelerated 2D canvas is in use. The cost of reading 1x1 pixels is low. | 37 // accelerated 2D canvas is in use. The cost of reading 1x1 pixels is low. |
| 32 destCtx2D.getImageData(0, 0, 1, 1); | 38 destCtx2D.getImageData(0, 0, 1, 1); |
|
xidachen
2016/07/06 20:16:25
I think you meant to make the change in here.
| |
| 33 } | 39 } |
| 34 | 40 |
| 35 window.onload = function () { | 41 window.onload = function () { |
| 36 // It should use setMinimumAccelerated2dCanvasSize() to enable accelerated C anvas for a specified size | 42 // It should use setMinimumAccelerated2dCanvasSize() to enable accelerated C anvas for a specified size |
| 37 // but this API is not available in JS or WebPage. Assume the threshold size is 256x257 | 43 // but this API is not available in JS or WebPage. Assume the threshold size is 256x257 |
| 38 // and the dest canvas is HW accelerated Canvas when setting its size to 102 4x1024. | 44 // and the dest canvas is HW accelerated Canvas when setting its size to 102 4x1024. |
| 39 setSize(1024, 1024); | 45 setSize(1024, 1024); |
| 40 | 46 |
| 41 videoElement.src = "resources/bear-1280x720.mp4"; | 47 videoElement.src = "resources/bear-1280x720.mp4"; |
| 42 if(!videoElement.canPlayType('video/mp4').replace(/no/, '')) { | 48 if(!videoElement.canPlayType('video/mp4').replace(/no/, '')) { |
| 43 CanvasRunner.logFatalError("video/mp4 is unsupported"); | 49 CanvasRunner.logFatalError("video/mp4 is unsupported"); |
| 44 }; | 50 }; |
| 45 CanvasRunner.startPlayingAndWaitForVideo(videoElement, startPerfTest); | 51 CanvasRunner.startPlayingAndWaitForVideo(videoElement, startPerfTest); |
| 46 } | 52 } |
| 47 | 53 |
| 48 </script> | 54 </script> |
| 49 </body> | 55 </body> |
| 50 </html> | 56 </html> |
| OLD | NEW |