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

Side by Side Diff: PerformanceTests/Canvas/draw-dynamic-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: Improve more 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> 5 <script>
6 var sourceCanvas2D = document.createElement("canvas"); 6 var sourceCanvas2D = document.createElement("canvas");
7 var sourceCtx2D = sourceCanvas2D.getContext("2d"); 7 var sourceCtx2D = sourceCanvas2D.getContext("2d");
8 var destCanvas2D = document.createElement("canvas"); 8 var destCanvas2D = document.createElement("canvas");
9 var destCtx2D = destCanvas2D.getContext("2d"); 9 var destCtx2D = destCanvas2D.getContext("2d");
10 var MEASURE_DRAW_TIMES = 1000; 10 var MEASURE_DRAW_TIMES = 50;
11 var MAX_COUNT = 60000; 11 var MAX_MEASURE_DRAW_TIMES = 1000;
12 var count = 0; 12 var MAX_MEASURE_TIME_PER_FRAME = 1000; // 1 sec
13 13
14 function setSize(sourceWidth, sourceHeight, destWidth, destHeight) { 14 function setSize(sourceWidth, sourceHeight, destWidth, destHeight) {
15 sourceCanvas2D.width = sourceWidth; 15 sourceCanvas2D.width = sourceWidth;
16 sourceCanvas2D.height = sourceHeight; 16 sourceCanvas2D.height = sourceHeight;
17 destCanvas2D.width = destWidth; 17 destCanvas2D.width = destWidth;
18 destCanvas2D.height = destHeight; 18 destCanvas2D.height = destHeight;
19 } 19 }
20 20
21 function rand(range) { 21 function rand(range) {
22 return Math.floor(Math.random() * range); 22 return Math.floor(Math.random() * range);
23 } 23 }
24 24
25 function fillCanvas(ctx2d, canvas2d) { 25 function fillCanvas(ctx2d, canvas2d) {
26 ctx2d.fillStyle = "rgba(" + rand(255) + "," + rand(255) + "," + rand(255) + "," + rand(255) + ")"; 26 ctx2d.fillStyle = "rgba(" + rand(255) + "," + rand(255) + "," + rand(255) + "," + rand(255) + ")";
27 ctx2d.fillRect(0, 0, canvas2d.width, canvas2d.height); 27 ctx2d.fillRect(0, 0, canvas2d.width, canvas2d.height);
28 } 28 }
29 29
30 function drawCanvas2DToCanvas2D() { 30 function drawCanvas2DToCanvas2D() {
31 var start = PerfTestRunner.now(); 31 var start = PerfTestRunner.now();
32 for (var i = 0; i < MEASURE_DRAW_TIMES; i++) { 32 var count = 0;
33 fillCanvas(sourceCtx2D, sourceCanvas2D); 33 while ((PerfTestRunner.now() - start <= MAX_MEASURE_TIME_PER_FRAME) && (coun t * MEASURE_DRAW_TIMES < MAX_MEASURE_DRAW_TIMES)) {
Ken Russell (switch to Gerrit) 2014/03/17 06:03:24 The duplicated constants and harness code througho
34 // draw dynamic Canvas 34 for (var i = 0; i < MEASURE_DRAW_TIMES; i++) {
35 destCtx2D.drawImage(sourceCanvas2D, 0, 0); 35 fillCanvas(sourceCtx2D, sourceCanvas2D);
36 // draw dynamic Canvas
37 destCtx2D.drawImage(sourceCanvas2D, 0, 0);
38 }
39 count++;
36 } 40 }
37 // Calling getImageData() is just to flush out the content when 41 // Calling getImageData() is just to flush out the content when
38 // accelerated 2D canvas is in use. The cost of reading 1x1 pixels is low. 42 // accelerated 2D canvas is in use. The cost of reading 1x1 pixels is low.
39 destCtx2D.getImageData(0, 0, 1, 1); 43 destCtx2D.getImageData(0, 0, 1, 1);
40 count++;
41 44
42 var elapsedTime = PerfTestRunner.now() - start; 45 var elapsedTime = PerfTestRunner.now() - start;
43 PerfTestRunner.measureValueAsync(MEASURE_DRAW_TIMES * 1000 / elapsedTime); 46 PerfTestRunner.measureValueAsync(MEASURE_DRAW_TIMES * count * 1000 / elapsed Time);
44 if (count < MAX_COUNT) 47
45 requestAnimationFrame(drawCanvas2DToCanvas2D); 48 requestAnimationFrame(drawCanvas2DToCanvas2D);
Ken Russell (switch to Gerrit) 2014/03/17 06:03:24 Since the conditional on requestAnimationFrame was
46 } 49 }
47 50
48 function onCompletedRun() { 51 function onCompletedRun() {
49 count = MAX_COUNT;
50 } 52 }
51 53
52 window.onload = function () { 54 window.onload = function () {
53 PerfTestRunner.prepareToMeasureValuesAsync({done: onCompletedRun, unit: 'run s/s', 55 PerfTestRunner.prepareToMeasureValuesAsync({done: onCompletedRun, unit: 'run s/s',
54 description: "This bench test checks the speed on drawing dynamic 2d Can vas(1024x1024) to HW accelerated Canvas2D(1024x1024)."}); 56 description: "This bench test checks the speed on drawing dynamic 2d Can vas(1024x1024) to HW accelerated Canvas2D(1024x1024)."});
55 // It should use setMinimumAccelerated2dCanvasSize() to enable accelerated C anvas for a specified size 57 // It should use setMinimumAccelerated2dCanvasSize() to enable accelerated C anvas for a specified size
56 // but this API is not available in JS or WebPage. Assume the threshold size is 256x257 58 // but this API is not available in JS or WebPage. Assume the threshold size is 256x257
57 // and the dest canvas is HW accelerated Canvas when setting its size to 102 4x1024. 59 // and the dest canvas is HW accelerated Canvas when setting its size to 102 4x1024.
58 setSize(1024, 1024, 1024, 1024); 60 setSize(1024, 1024, 1024, 1024);
59 fillCanvas(sourceCtx2D, sourceCanvas2D); 61 fillCanvas(sourceCtx2D, sourceCanvas2D);
60 drawCanvas2DToCanvas2D(); 62 drawCanvas2DToCanvas2D();
61 } 63 }
62 64
63 </script> 65 </script>
64 </body> 66 </body>
65 </html> 67 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698