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

Side by Side Diff: PerformanceTests/Canvas/upload-canvas-2d-to-texture.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 7
7 var canvas2D = document.createElement("canvas"); 8 var canvas2D = document.createElement("canvas");
8 var ctx2D = canvas2D.getContext("2d"); 9 var ctx2D = canvas2D.getContext("2d");
9 var canvas3D = document.createElement('canvas'); 10 var canvas3D = document.createElement('canvas');
10 var gl = canvas3D.getContext('experimental-webgl'); 11 var gl = canvas3D.getContext('experimental-webgl');
11 if(!gl) 12 if(!gl)
12 PerfTestRunner.logFatalError("\nWebGL is not supported or enabled on this pl atform!\n"); 13 CanvasRunner.logFatalError("\nWebGL is not supported or enabled on this plat form!\n");
13 var MEASURE_DRAW_TIMES = 1000; 14 var tex = null;
14 var MAX_COUNT = 60000;
15 var count = 0;
16 15
17 function setSize(width, height) { 16 function setSize(width, height) {
18 canvas2D.width = width; 17 canvas2D.width = width;
19 canvas2D.height = height; 18 canvas2D.height = height;
20 canvas3D.width = width; 19 canvas3D.width = width;
21 canvas3D.height = height; 20 canvas3D.height = height;
22 } 21 }
23 22
24 function rand(range) { 23 function rand(range) {
25 return Math.floor(Math.random() * range); 24 return Math.floor(Math.random() * range);
26 } 25 }
27 26
28 function fillCanvas(ctx2d, canvas2d) { 27 function fillCanvas(ctx2d, canvas2d) {
29 ctx2d.fillStyle = "rgba(" + rand(255) + "," + rand(255) + "," + rand(255) + "," + rand(255) + ")"; 28 ctx2d.fillStyle = "rgba(" + rand(255) + "," + rand(255) + "," + rand(255) + "," + rand(255) + ")";
30 ctx2d.fillRect(0, 0, canvas2d.width, canvas2d.height); 29 ctx2d.fillRect(0, 0, canvas2d.width, canvas2d.height);
31 } 30 }
32 31
33 function uploadCanvas2DToWebGLTexture() { 32 function preRun() {
34 var tex = gl.createTexture(); 33 tex = gl.createTexture();
35 gl.bindTexture(gl.TEXTURE_2D, tex); 34 gl.bindTexture(gl.TEXTURE_2D, tex);
36
37 var start = PerfTestRunner.now();
38 for (var i = 0; i < MEASURE_DRAW_TIMES; i++) {
39 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, canv as2D);
40 }
41 gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, new Uint8Array(4));
42 gl.deleteTexture(tex);
43 count++;
44
45 var elapsedTime = PerfTestRunner.now() - start;
46 PerfTestRunner.measureValueAsync(MEASURE_DRAW_TIMES * 1000 / elapsedTime);
47 if (count < MAX_COUNT)
48 requestAnimationFrame(uploadCanvas2DToWebGLTexture);
49 } 35 }
50 36
51 function onCompletedRun() { 37 function doRun() {
52 count = MAX_COUNT; 38 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, canvas2D );
39 }
40
41 function ensureComplete() {
42 gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, new Uint8Array(4));
43 }
44
45 function postRun() {
46 gl.deleteTexture(tex);
53 } 47 }
54 48
55 window.onload = function () { 49 window.onload = function () {
56 PerfTestRunner.prepareToMeasureValuesAsync({done: onCompletedRun, unit: 'run s/s',
57 description: "This bench test checks the speed on uploading 2d Canvas(10 24x1024) to Webgl Texture(1024x1024)."});
58 setSize(1024, 1024); 50 setSize(1024, 1024);
59 fillCanvas(ctx2D, canvas2D); 51 fillCanvas(ctx2D, canvas2D);
60 uploadCanvas2DToWebGLTexture(); 52 CanvasRunner.start({
53 description: "This bench test checks the speed on uploading 2d Canvas(10 24x1024) to Webgl Texture(1024x1024).",
54 preRun: preRun,
55 doRun: doRun,
56 ensureComplete: ensureComplete,
57 postRun: postRun});
61 } 58 }
62 59
63 </script> 60 </script>
64 </body> 61 </body>
65 </html> 62 </html>
OLDNEW
« no previous file with comments | « PerformanceTests/Canvas/resources/canvas_runner.js ('k') | PerformanceTests/Canvas/upload-webgl-to-texture.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698