2010-05-29  Sterling Swigart  <sswigart@google.com>

        Reviewed by David Levin.

        Adding tests to canvas.html performance test
        https://bugs.webkit.org/show_bug.cgi?id=39883

        * demos/canvas-perf/canvas.html:
        Added tests for:
            strokeText
            fillText
            strokeLine

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@60407 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebKitSite/ChangeLog b/WebKitSite/ChangeLog
index 683940a..b8d6f3c 100644
--- a/WebKitSite/ChangeLog
+++ b/WebKitSite/ChangeLog
@@ -1,3 +1,16 @@
+2010-05-29  Sterling Swigart  <sswigart@google.com>
+
+        Reviewed by David Levin.
+
+        Adding tests to canvas.html performance test
+        https://bugs.webkit.org/show_bug.cgi?id=39883
+
+        * demos/canvas-perf/canvas.html:
+        Added tests for:
+            strokeText
+            fillText
+            strokeLine
+
 2010-05-25  Jeremy Orlow  <jorlow@chromium.org>
 
         Reviewed by Darin Adler.
diff --git a/WebKitSite/demos/canvas-perf/canvas.html b/WebKitSite/demos/canvas-perf/canvas.html
index 9f57eb7..851c3ed 100644
--- a/WebKitSite/demos/canvas-perf/canvas.html
+++ b/WebKitSite/demos/canvas-perf/canvas.html
@@ -67,6 +67,8 @@
 }
 
 function doCopy() {
+    log("===== Copy/Scale/Rotate Tests =====");
+
     var copy =  document.getElementById("copy");
     copy.width = width;
     copy.height = height;
@@ -142,7 +144,95 @@
     log("Copy with rotate: " + time + "ms");
     shouldBe("document.getElementById('rotated').width", "height");
     shouldBe("document.getElementById('rotated').height", "width");
-    log("DONE!");
+    log("");
+    window.setTimeout(doStrokeTextTests, idleTimer);
+}
+
+function doStrokeTextTests() {
+    log("===== StrokeText Tests =====");
+    var strokeTextFunc = function(canvas, str, x, y) { canvas.strokeText(str, x, y); };
+    doNextTextTest(strokeTextFunc, doFillTextTests, 1);
+}
+
+function doFillTextTests() {
+    log("===== FillText Tests =====");
+    var fillTextFunc = function(obj, str, x, y) { obj.fillText(str, x, y); };
+    doNextTextTest(fillTextFunc, doSmallStrokeLineTests, 1);
+}
+
+function doNextTextTest(writeText, nextFunc, numStrings) {
+    var canvas = document.createElement('canvas');
+    canvas.width = 100;
+    canvas.height = 550;
+    document.body.appendChild(canvas);
+    var ctx = canvas.getContext('2d');
+
+    var time = timeCanvasOperation(ctx,
+        function () {
+            for (var i = 0; i < 10; i++)
+                for (var j = 0; j < numStrings; j++)
+                    writeText(ctx, "Printing text!", 25, 500 * j / numStrings + 25);
+        });
+    log(numStrings + " strings: " + (time / 10) + "ms");
+
+    numStrings *= 10;
+    if (numStrings < 1001)
+        window.setTimeout(function () {
+                              doNextTextTest(writeText, nextFunc, numStrings);
+                          }, idleTimer);
+    else {
+        log("");
+        window.setTimeout(nextFunc, idleTimer);
+    }
+}
+
+function doSmallStrokeLineTests() {
+    log("===== StrokeLine Tests =====");
+    doNextStrokeLineTest(doLargeStrokeLineTests, 1, 150, 150);
+}
+
+function doLargeStrokeLineTests() {
+    doNextStrokeLineTest(null, 1, 1000, 1000);
+}
+
+function doNextStrokeLineTest(nextFunc, numLines, xSize, ySize) {
+    var canvas = document.createElement('canvas');
+    canvas.width = xSize;
+    canvas.height = ySize;
+    document.body.appendChild(canvas);
+    var ctx = canvas.getContext('2d');
+
+    var time = timeCanvasOperation(ctx,
+        function() {
+            for (var i = 0; i < 10; i++) {
+                ctx.beginPath();
+                if (numLines == 1) {
+                    ctx.moveTo(5, 5);
+                    ctx.lineTo(xSize - 1, ySize - 1);
+                } else {
+                    for (var j = 0; j < numLines; j++) {
+                        ctx.moveTo(j * xSize / numLines, j * ySize / numLines);
+                        ctx.lineTo(xSize - 5, 5);
+                    }
+                }
+                ctx.stroke();
+                ctx.closePath();
+            }
+        });
+    log("Stroking " + numLines + " lines in " + xSize + "x" + ySize + ": " + (time / 10) + "ms");
+    
+    numLines *= 10;
+    if (numLines < 1001)
+        window.setTimeout(function () {
+                              doNextStrokeLineTest(nextFunc, numLines, xSize, ySize);
+                          }, idleTimer);
+    else {
+        log("");
+        if (nextFunc)
+            window.setTimeout(nextFunc, idleTimer);
+        else
+            log("DONE!");
+    }
 }
 </script>