| 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 src="resources/canvas_runner.js"></script> | 5 <script src="resources/canvas_runner.js"></script> |
| 6 <script> | 6 <script> |
| 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('webgl'); | 10 var gl = canvas3D.getContext('webgl'); |
| 11 if (!gl) | 11 if (!gl) |
| 12 CanvasRunner.logFatalError("WebGL is not supported or enabled on this platfo
rm!"); | 12 CanvasRunner.logFatalError("WebGL is not supported or enabled on this platfo
rm!"); |
| 13 | 13 |
| 14 var dummyCanvas2D = document.createElement("canvas"); |
| 15 var dummyCtx2D = dummyCanvas2D.getContext("2d"); |
| 16 |
| 17 dummyCanvas2D.width = 1; |
| 18 dummyCanvas2D.height = 1; |
| 19 |
| 14 function setSize(canvas2DWidth, canvas2DHeight, webglWidth, webglHeight) { | 20 function setSize(canvas2DWidth, canvas2DHeight, webglWidth, webglHeight) { |
| 15 canvas2D.width = canvas2DWidth; | 21 canvas2D.width = canvas2DWidth; |
| 16 canvas2D.height = canvas2DHeight; | 22 canvas2D.height = canvas2DHeight; |
| 17 canvas3D.width = webglWidth; | 23 canvas3D.width = webglWidth; |
| 18 canvas3D.height = webglHeight; | 24 canvas3D.height = webglHeight; |
| 19 } | 25 } |
| 20 | 26 |
| 21 function rand(range) { | 27 function rand(range) { |
| 22 return Math.floor(Math.random() * range); | 28 return Math.floor(Math.random() * range); |
| 23 } | 29 } |
| 24 | 30 |
| 25 function renderWebGL(gl) { | 31 function renderWebGL(gl) { |
| 26 gl.disable(gl.SCISSOR_TEST); | 32 gl.disable(gl.SCISSOR_TEST); |
| 27 gl.clear(gl.COLOR_BUFER_BIT); | 33 gl.clear(gl.COLOR_BUFER_BIT); |
| 28 gl.enable(gl.SCISSOR_TEST); | 34 gl.enable(gl.SCISSOR_TEST); |
| 29 gl.scissor(rand(1024), rand(1024), rand(1024), rand(1024)); | 35 gl.scissor(rand(1024), rand(1024), rand(1024), rand(1024)); |
| 30 gl.clearColor(Math.random(), Math.random(), Math.random(), 1); | 36 gl.clearColor(Math.random(), Math.random(), Math.random(), 1); |
| 31 gl.clear(gl.COLOR_BUFFER_BIT); | 37 gl.clear(gl.COLOR_BUFFER_BIT); |
| 32 } | 38 } |
| 33 | 39 |
| 34 function doRun() { | 40 function doRun() { |
| 35 renderWebGL(gl); | 41 renderWebGL(gl); |
| 36 // draw dynamic WebGL | 42 // draw dynamic WebGL |
| 37 ctx2D.drawImage(canvas3D, 0, 0); | 43 ctx2D.drawImage(canvas3D, 0, 0); |
| 38 } | 44 } |
| 39 | 45 |
| 40 function ensureComplete() { | 46 function ensureComplete() { |
| 41 // Calling getImageData() is just to flush out the content when | 47 // Using destCanvas2D as a source image is just to flush out the content whe
n |
| 42 // accelerated 2D canvas is in use. The cost of reading 1x1 pixels is low. | 48 // accelerated 2D canvas is in use. |
| 43 ctx2D.getImageData(0, 0, 1, 1); | 49 dummyCtx2D.drawImage(destCanvas2D, 0, 0, 1, 1, 0, 0, 1, 1); |
| 44 } | 50 } |
| 45 | 51 |
| 46 window.onload = function () { | 52 window.onload = function () { |
| 47 // It should use setMinimumAccelerated2dCanvasSize() to enable accelerated C
anvas for a specified size | 53 // It should use setMinimumAccelerated2dCanvasSize() to enable accelerated C
anvas for a specified size |
| 48 // but this API is not available in JS or WebPage. Assume the threshold size
is 256x257 | 54 // but this API is not available in JS or WebPage. Assume the threshold size
is 256x257 |
| 49 // and the dest canvas is HW accelerated Canvas when setting its size to 102
4x1024. | 55 // and the dest canvas is HW accelerated Canvas when setting its size to 102
4x1024. |
| 50 setSize(1024, 1024, 1024, 1024); | 56 setSize(1024, 1024, 1024, 1024); |
| 51 renderWebGL(gl); | 57 renderWebGL(gl); |
| 52 CanvasRunner.start({ | 58 CanvasRunner.start({ |
| 53 description: "This bench test checks the speed on drawing dynamic WebGL(
1024x1024) to HW accelerated Canvas2D(1024x1024).", | 59 description: "This bench test checks the speed on drawing dynamic WebGL(
1024x1024) to HW accelerated Canvas2D(1024x1024).", |
| 54 doRun: doRun, | 60 doRun: doRun, |
| 55 ensureComplete: ensureComplete}); | 61 ensureComplete: ensureComplete}); |
| 56 } | 62 } |
| 57 | 63 |
| 58 </script> | 64 </script> |
| 59 </body> | 65 </body> |
| 60 </html> | 66 </html> |
| OLD | NEW |