Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(619)

Side by Side Diff: PerformanceTests/Canvas/draw-static-canvas-2d-to-hw-accelerated-canvas-2d.html

Issue 200253002: Make canvas perf tests run less than 6 sec. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Introduce canvas_runner.js to remove duplicated code. Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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> 6 <script>
6 var sourceCanvas2D = document.createElement("canvas"); 7 var sourceCanvas2D = document.createElement("canvas");
7 var sourceCtx2D = sourceCanvas2D.getContext("2d"); 8 var sourceCtx2D = sourceCanvas2D.getContext("2d");
8 var destCanvas2D = document.createElement("canvas"); 9 var destCanvas2D = document.createElement("canvas");
9 var destCtx2D = destCanvas2D.getContext("2d"); 10 var destCtx2D = destCanvas2D.getContext("2d");
10 var MEASURE_DRAW_TIMES = 1000;
11 var MAX_COUNT = 60000;
12 var count = 0;
13 11
14 function setSize(sourceWidth, sourceHeight, destWidth, destHeight) { 12 function setSize(sourceWidth, sourceHeight, destWidth, destHeight) {
15 sourceCanvas2D.width = sourceWidth; 13 sourceCanvas2D.width = sourceWidth;
16 sourceCanvas2D.height = sourceHeight; 14 sourceCanvas2D.height = sourceHeight;
17 destCanvas2D.width = destWidth; 15 destCanvas2D.width = destWidth;
18 destCanvas2D.height = destHeight; 16 destCanvas2D.height = destHeight;
19 } 17 }
20 18
21 function rand(range) { 19 function rand(range) {
22 return Math.floor(Math.random() * range); 20 return Math.floor(Math.random() * range);
23 } 21 }
24 22
25 function fillCanvas(ctx2d, canvas2d) { 23 function fillCanvas(ctx2d, canvas2d) {
26 ctx2d.fillStyle = "rgba(" + rand(255) + "," + rand(255) + "," + rand(255) + "," + rand(255) + ")"; 24 ctx2d.fillStyle = "rgba(" + rand(255) + "," + rand(255) + "," + rand(255) + "," + rand(255) + ")";
27 ctx2d.fillRect(0, 0, canvas2d.width, canvas2d.height); 25 ctx2d.fillRect(0, 0, canvas2d.width, canvas2d.height);
28 } 26 }
29 27
30 function drawCanvas2DToCanvas2D() { 28 function doRun() {
31 var start = PerfTestRunner.now(); 29 // draw static Canvas
32 for (var i = 0; i < MEASURE_DRAW_TIMES; i++) { 30 destCtx2D.drawImage(sourceCanvas2D, 0, 0);
33 // draw static Canvas 31 }
34 destCtx2D.drawImage(sourceCanvas2D, 0, 0); 32
35 } 33 function ensureComplete() {
36 // Calling getImageData() is just to flush out the content when 34 // Calling getImageData() is just to flush out the content when
37 // accelerated 2D canvas is in use. The cost of reading 1x1 pixels is low. 35 // accelerated 2D canvas is in use. The cost of reading 1x1 pixels is low.
38 destCtx2D.getImageData(0, 0, 1, 1); 36 destCtx2D.getImageData(0, 0, 1, 1);
39 count++;
40
41 var elapsedTime = PerfTestRunner.now() - start;
42 PerfTestRunner.measureValueAsync(MEASURE_DRAW_TIMES * 1000 / elapsedTime);
43 if (count < MAX_COUNT)
44 requestAnimationFrame(drawCanvas2DToCanvas2D);
45 }
46
47 function onCompletedRun() {
48 count = MAX_COUNT;
49 } 37 }
50 38
51 window.onload = function () { 39 window.onload = function () {
52 PerfTestRunner.prepareToMeasureValuesAsync({done: onCompletedRun, unit: 'run s/s',
53 description: "This bench test checks the speed on drawing static 2d Canv as(1024x1024) to HW accelerated Canvas2D(1024x1024)."});
54 // It should use setMinimumAccelerated2dCanvasSize() to enable accelerated C anvas for a specified size 40 // It should use setMinimumAccelerated2dCanvasSize() to enable accelerated C anvas for a specified size
55 // but this API is not available in JS or WebPage. Assume the threshold size is 256x257 41 // but this API is not available in JS or WebPage. Assume the threshold size is 256x257
56 // and the dest canvas is HW accelerated Canvas when setting its size to 102 4x1024. 42 // and the dest canvas is HW accelerated Canvas when setting its size to 102 4x1024.
57 setSize(1024, 1024, 1024, 1024); 43 setSize(1024, 1024, 1024, 1024);
58 fillCanvas(sourceCtx2D, sourceCanvas2D); 44 fillCanvas(sourceCtx2D, sourceCanvas2D);
59 drawCanvas2DToCanvas2D(); 45 CanvasRunner.start({
46 description: "This bench test checks the speed on drawing static 2d Canv as(1024x1024) to HW accelerated Canvas2D(1024x1024).",
47 doRun: doRun,
48 ensureComplete: ensureComplete});
60 } 49 }
61 50
62 </script> 51 </script>
63 </body> 52 </body>
64 </html> 53 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698