OLD | NEW |
---|---|
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 | 6 |
7 var canvas2D = document.createElement("canvas"); | 7 var canvas2D = document.createElement("canvas"); |
8 var ctx2D = canvas2D.getContext("2d"); | 8 var ctx2D = canvas2D.getContext("2d"); |
9 var canvas3D = document.createElement('canvas'); | 9 var canvas3D = document.createElement('canvas'); |
10 var gl = canvas3D.getContext('experimental-webgl'); | 10 var gl = canvas3D.getContext('experimental-webgl'); |
11 if(!gl) | 11 if(!gl) |
12 PerfTestRunner.log("\nWebGL is not supported or enabled on this platform!\n" ); | 12 PerfTestRunner.log("\nWebGL is not supported or enabled on this platform!\n" ); |
13 var MEASURE_DRAW_TIMES = 1000; | 13 var MEASURE_DRAW_TIMES = 50; |
14 var MAX_COUNT = 60000; | 14 var MAX_MEASURE_DRAW_TIMES = 1000; |
15 var count = 0; | 15 var MAX_MEASURE_TIME_PER_FRAME = 1000; // 1 sec |
16 | 16 |
17 function setSize(width, height) { | 17 function setSize(width, height) { |
18 canvas2D.width = width; | 18 canvas2D.width = width; |
19 canvas2D.height = height; | 19 canvas2D.height = height; |
20 canvas3D.width = width; | 20 canvas3D.width = width; |
21 canvas3D.height = height; | 21 canvas3D.height = height; |
22 } | 22 } |
23 | 23 |
24 function rand(range) { | 24 function rand(range) { |
25 return Math.floor(Math.random() * range); | 25 return Math.floor(Math.random() * range); |
26 } | 26 } |
27 | 27 |
28 function fillCanvas(ctx2d, canvas2d) { | 28 function fillCanvas(ctx2d, canvas2d) { |
29 ctx2d.fillStyle = "rgba(" + rand(255) + "," + rand(255) + "," + rand(255) + "," + rand(255) + ")"; | 29 ctx2d.fillStyle = "rgba(" + rand(255) + "," + rand(255) + "," + rand(255) + "," + rand(255) + ")"; |
30 ctx2d.fillRect(0, 0, canvas2d.width, canvas2d.height); | 30 ctx2d.fillRect(0, 0, canvas2d.width, canvas2d.height); |
31 } | 31 } |
32 | 32 |
33 function uploadCanvas2DToWebGLTexture() { | 33 function uploadCanvas2DToWebGLTexture() { |
34 if (gl) { | 34 if (gl) { |
35 var tex = gl.createTexture(); | 35 var tex = gl.createTexture(); |
36 gl.bindTexture(gl.TEXTURE_2D, tex); | 36 gl.bindTexture(gl.TEXTURE_2D, tex); |
37 | 37 |
38 var start = PerfTestRunner.now(); | 38 var start = PerfTestRunner.now(); |
39 for (var i = 0; i < MEASURE_DRAW_TIMES; i++) { | 39 var count = 0; |
40 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, canvas2D); | 40 while ((PerfTestRunner.now() - start <= MAX_MEASURE_TIME_PER_FRAME) && ( count * MEASURE_DRAW_TIMES < MAX_MEASURE_DRAW_TIMES)) { |
41 for (var i = 0; i < MEASURE_DRAW_TIMES; i++) { | |
42 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BY TE, canvas2D); | |
43 } | |
44 count++; | |
41 } | 45 } |
42 gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, new Uint8Array(4)); | 46 gl.finish(); |
Ken Russell (switch to Gerrit)
2014/03/17 06:03:24
The earlier implementation using readPixels was be
| |
47 var elapsedTime = PerfTestRunner.now() - start; | |
43 gl.deleteTexture(tex); | 48 gl.deleteTexture(tex); |
44 count++; | |
45 | 49 |
46 var elapsedTime = PerfTestRunner.now() - start; | 50 PerfTestRunner.measureValueAsync(MEASURE_DRAW_TIMES * count * 1000 / ela psedTime); |
47 PerfTestRunner.measureValueAsync(MEASURE_DRAW_TIMES * 1000 / elapsedTime ); | |
48 } else | 51 } else |
49 PerfTestRunner.measureValueAsync(0); | 52 PerfTestRunner.measureValueAsync(0); |
50 if (count < MAX_COUNT) | 53 |
51 requestAnimationFrame(uploadCanvas2DToWebGLTexture); | 54 requestAnimationFrame(uploadCanvas2DToWebGLTexture); |
52 } | 55 } |
53 | 56 |
54 function onCompletedRun() { | 57 function onCompletedRun() { |
55 count = MAX_COUNT; | |
56 } | 58 } |
57 | 59 |
58 window.onload = function () { | 60 window.onload = function () { |
59 PerfTestRunner.prepareToMeasureValuesAsync({done: onCompletedRun, unit: 'run s/s', | 61 PerfTestRunner.prepareToMeasureValuesAsync({done: onCompletedRun, unit: 'run s/s', |
60 description: "This bench test checks the speed on uploading 2d Canvas(10 24x1024) to Webgl Texture(1024x1024)."}); | 62 description: "This bench test checks the speed on uploading 2d Canvas(10 24x1024) to Webgl Texture(1024x1024)."}); |
61 setSize(1024, 1024); | 63 setSize(1024, 1024); |
62 fillCanvas(ctx2D, canvas2D); | 64 fillCanvas(ctx2D, canvas2D); |
63 uploadCanvas2DToWebGLTexture(); | 65 uploadCanvas2DToWebGLTexture(); |
64 } | 66 } |
65 | 67 |
66 </script> | 68 </script> |
67 </body> | 69 </body> |
68 </html> | 70 </html> |
OLD | NEW |