Index: PerformanceTests/Canvas/upload-canvas-2d-to-texture.html |
diff --git a/PerformanceTests/Canvas/upload-canvas-2d-to-texture.html b/PerformanceTests/Canvas/upload-canvas-2d-to-texture.html |
index 0f41997c8a6a21918cecdd5dc49a1e40cf79caf4..30ee01aca17277d86993bfdc88e6a36c31d25558 100644 |
--- a/PerformanceTests/Canvas/upload-canvas-2d-to-texture.html |
+++ b/PerformanceTests/Canvas/upload-canvas-2d-to-texture.html |
@@ -2,6 +2,7 @@ |
<html> |
<body> |
<script src="../resources/runner.js"></script> |
+<script src="resources/canvas_runner.js"></script> |
<script> |
var canvas2D = document.createElement("canvas"); |
@@ -9,10 +10,8 @@ var ctx2D = canvas2D.getContext("2d"); |
var canvas3D = document.createElement('canvas'); |
var gl = canvas3D.getContext('experimental-webgl'); |
if(!gl) |
- PerfTestRunner.logFatalError("\nWebGL is not supported or enabled on this platform!\n"); |
-var MEASURE_DRAW_TIMES = 1000; |
-var MAX_COUNT = 60000; |
-var count = 0; |
+ CanvasRunner.logFatalError("\nWebGL is not supported or enabled on this platform!\n"); |
+var tex = null; |
function setSize(width, height) { |
canvas2D.width = width; |
@@ -30,34 +29,32 @@ function fillCanvas(ctx2d, canvas2d) { |
ctx2d.fillRect(0, 0, canvas2d.width, canvas2d.height); |
} |
-function uploadCanvas2DToWebGLTexture() { |
- var tex = gl.createTexture(); |
+function preRun() { |
+ tex = gl.createTexture(); |
gl.bindTexture(gl.TEXTURE_2D, tex); |
+} |
- var start = PerfTestRunner.now(); |
- for (var i = 0; i < MEASURE_DRAW_TIMES; i++) { |
- gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, canvas2D); |
- } |
- gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, new Uint8Array(4)); |
- gl.deleteTexture(tex); |
- count++; |
+function doRun() { |
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, canvas2D); |
+} |
- var elapsedTime = PerfTestRunner.now() - start; |
- PerfTestRunner.measureValueAsync(MEASURE_DRAW_TIMES * 1000 / elapsedTime); |
- if (count < MAX_COUNT) |
- requestAnimationFrame(uploadCanvas2DToWebGLTexture); |
+function ensureComplete() { |
+ gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, new Uint8Array(4)); |
} |
-function onCompletedRun() { |
- count = MAX_COUNT; |
+function postRun() { |
+ gl.deleteTexture(tex); |
} |
window.onload = function () { |
- PerfTestRunner.prepareToMeasureValuesAsync({done: onCompletedRun, unit: 'runs/s', |
- description: "This bench test checks the speed on uploading 2d Canvas(1024x1024) to Webgl Texture(1024x1024)."}); |
setSize(1024, 1024); |
fillCanvas(ctx2D, canvas2D); |
- uploadCanvas2DToWebGLTexture(); |
+ CanvasRunner.start({ |
+ description: "This bench test checks the speed on uploading 2d Canvas(1024x1024) to Webgl Texture(1024x1024).", |
+ preRun: preRun, |
+ doRun: doRun, |
+ ensureComplete: ensureComplete, |
+ postRun: postRun}); |
} |
</script> |