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

Side by Side Diff: PerformanceTests/Canvas/draw-dynamic-webgl-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 canvas2D = document.createElement("canvas"); 7 var canvas2D = document.createElement("canvas");
7 var ctx2D = canvas2D.getContext("2d"); 8 var ctx2D = canvas2D.getContext("2d");
8 var canvas3D = document.createElement('canvas'); 9 var canvas3D = document.createElement('canvas');
9 var gl = canvas3D.getContext('experimental-webgl'); 10 var gl = canvas3D.getContext('experimental-webgl');
10 if (!gl) 11 if (!gl)
11 PerfTestRunner.logFatalError("\nWebGL is not supported or enabled on this pl atform!\n"); 12 CanvasRunner.logFatalError("\nWebGL is not supported or enabled on this plat form!\n");
12 var MEASURE_DRAW_TIMES = 100;
13 var MAX_COUNT = 60000;
14 var count = 0;
15 13
16 function setSize(canvas2DWidth, canvas2DHeight, webglWidth, webglHeight) { 14 function setSize(canvas2DWidth, canvas2DHeight, webglWidth, webglHeight) {
17 canvas2D.width = canvas2DWidth; 15 canvas2D.width = canvas2DWidth;
18 canvas2D.height = canvas2DHeight; 16 canvas2D.height = canvas2DHeight;
19 canvas3D.width = webglWidth; 17 canvas3D.width = webglWidth;
20 canvas3D.height = webglHeight; 18 canvas3D.height = webglHeight;
21 } 19 }
22 20
23 function rand(range) { 21 function rand(range) {
24 return Math.floor(Math.random() * range); 22 return Math.floor(Math.random() * range);
25 } 23 }
26 24
27 function renderWebGL(gl) { 25 function renderWebGL(gl) {
28 gl.disable(gl.SCISSOR_TEST); 26 gl.disable(gl.SCISSOR_TEST);
29 gl.clear(gl.COLOR_BUFER_BIT); 27 gl.clear(gl.COLOR_BUFER_BIT);
30 gl.enable(gl.SCISSOR_TEST); 28 gl.enable(gl.SCISSOR_TEST);
31 gl.scissor(rand(1024), rand(1024), rand(1024), rand(1024)); 29 gl.scissor(rand(1024), rand(1024), rand(1024), rand(1024));
32 gl.clearColor(Math.random(), Math.random(), Math.random(), 1); 30 gl.clearColor(Math.random(), Math.random(), Math.random(), 1);
33 gl.clear(gl.COLOR_BUFFER_BIT); 31 gl.clear(gl.COLOR_BUFFER_BIT);
34 } 32 }
35 33
36 function drawWebGLToCanvas2D() { 34 function doRun() {
37 var start = PerfTestRunner.now(); 35 renderWebGL(gl);
38 for (var i = 0; i < MEASURE_DRAW_TIMES; i++) { 36 // draw dynamic WebGL
39 renderWebGL(gl); 37 ctx2D.drawImage(canvas3D, 0, 0);
40 // draw dynamic WebGL 38 }
41 ctx2D.drawImage(canvas3D, 0, 0); 39
42 } 40 function ensureComplete() {
43 // Calling getImageData() is just to flush out the content when 41 // Calling getImageData() is just to flush out the content when
44 // 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.
45 ctx2D.getImageData(0, 0, 1, 1); 43 ctx2D.getImageData(0, 0, 1, 1);
46 count++;
47
48 var elapsedTime = PerfTestRunner.now() - start;
49 PerfTestRunner.measureValueAsync(MEASURE_DRAW_TIMES * 1000 / elapsedTime);
50 if (count < MAX_COUNT)
51 requestAnimationFrame(drawWebGLToCanvas2D);
52 }
53
54 function onCompletedRun() {
55 count = MAX_COUNT;
56 } 44 }
57 45
58 window.onload = function () { 46 window.onload = function () {
59 PerfTestRunner.prepareToMeasureValuesAsync({done: onCompletedRun, unit: 'run s/s',
60 description: "This bench test checks the speed on drawing dynamic WebGL( 1024x1024) to HW accelerated Canvas2D(1024x1024)."});
61 // It should use setMinimumAccelerated2dCanvasSize() to enable accelerated C anvas for a specified size 47 // It should use setMinimumAccelerated2dCanvasSize() to enable accelerated C anvas for a specified size
62 // but this API is not available in JS or WebPage. Assume the threshold size is 256x257 48 // but this API is not available in JS or WebPage. Assume the threshold size is 256x257
63 // and the dest canvas is HW accelerated Canvas when setting its size to 102 4x1024. 49 // and the dest canvas is HW accelerated Canvas when setting its size to 102 4x1024.
64 setSize(1024, 1024, 1024, 1024); 50 setSize(1024, 1024, 1024, 1024);
65 renderWebGL(gl); 51 renderWebGL(gl);
66 drawWebGLToCanvas2D(); 52 CanvasRunner.start({
53 description: "This bench test checks the speed on drawing dynamic WebGL( 1024x1024) to HW accelerated Canvas2D(1024x1024).",
54 doRun: doRun,
55 ensureComplete: ensureComplete});
67 } 56 }
68 57
69 </script> 58 </script>
70 </body> 59 </body>
71 </html> 60 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698