Add canvas line segment tests
authorjonlee@apple.com <jonlee@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 13 Oct 2015 02:10:42 +0000 (02:10 +0000)
committerjonlee@apple.com <jonlee@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 13 Oct 2015 02:10:42 +0000 (02:10 +0000)
https://bugs.webkit.org/show_bug.cgi?id=150073
<rdar://problem/23082138>

Reviewed by Dean Jackson.

* Animometer/runner/resources/tests.js: Add new line segment tests, with different
line caps.
* Animometer/tests/simple/resources/simple-canvas-paths.js:
(CanvasLineSegment): Add new line segment paint object.
(CanvasLineSegmentStage): Create a new stage that sets the lineCap.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@190918 268f45cc-cd09-0410-ab3c-d52691b4dbfc

PerformanceTests/Animometer/runner/resources/tests.js
PerformanceTests/Animometer/tests/simple/resources/simple-canvas-paths.js
PerformanceTests/ChangeLog

index 597f963..741b160 100644 (file)
@@ -139,6 +139,18 @@ Suites.push(new Suite("SVG suite",
 Suites.push(new Suite("Basic canvas path suite",
     [
         {
+            url: "simple/simple-canvas-paths.html?pathType=line&lineCap=butt",
+            name: "Canvas line segments, butt caps"
+        },
+        {
+            url: "simple/simple-canvas-paths.html?pathType=line&lineCap=round",
+            name: "Canvas line segments, round caps"
+        },
+        {
+            url: "simple/simple-canvas-paths.html?pathType=line&lineCap=square",
+            name: "Canvas line segments, square caps"
+        },
+        {
             url: "simple/simple-canvas-paths.html?pathType=quadratic",
             name: "Canvas quadratic segments"
         },
index 3b0d96c..4d4fc30 100644 (file)
@@ -1,5 +1,24 @@
 // === PAINT OBJECTS ===
 
+function CanvasLineSegment(stage) {
+    var radius = stage.randomInt(10, 100);
+    var center = stage.randomPosition(stage.size);
+    var delta = Point.pointOnCircle(stage.randomAngle(), radius/2);
+
+    this._point1 = center.add(delta);
+    this._point2 = center.subtract(delta);
+    this._color = stage.randomColor();
+    this._lineWidth = stage.randomInt(1, 100);
+}
+CanvasLineSegment.prototype.draw = function(context) {
+    context.strokeStyle = this._color;
+    context.lineWidth = this._lineWidth;
+    context.beginPath();
+    context.moveTo(this._point1.x, this._point1.y);
+    context.lineTo(this._point2.x, this._point2.y);
+    context.stroke();
+};
+
 function CanvasLinePoint(stage, coordinateMaximum) {
     this._point = stage.randomPosition(new Point(Math.min(stage.size.x, coordinateMaximum), Math.min(stage.size.y, coordinateMaximum)));
 }
@@ -165,6 +184,14 @@ SimpleCanvasPathFillStage.prototype.animate = function() {
     context.fill();
 }
 
+function CanvasLineSegmentStage(element, options)
+{
+    SimpleCanvasStage.call(this, element, options, CanvasLineSegment);
+    this.context.lineCap = options["lineCap"] || "butt";
+}
+CanvasLineSegmentStage.prototype = Object.create(SimpleCanvasStage.prototype);
+CanvasLineSegmentStage.prototype.constructor = CanvasLineSegmentStage;
+
 // === BENCHMARK ===
 
 function CanvasPathBenchmark(suite, test, options, recordTable, progressBar) {
@@ -175,6 +202,8 @@ CanvasPathBenchmark.prototype.constructor = CanvasPathBenchmark;
 CanvasPathBenchmark.prototype.createStage = function(element)
 {
     switch (this._options["pathType"]) {
+    case "line":
+        return new CanvasLineSegmentStage(element, this._options);
     case "quadratic":
         return new SimpleCanvasStage(element, this._options, CanvasQuadraticSegment);
     case "quadraticPath":
index eb6d6a8..80b33d9 100644 (file)
@@ -1,5 +1,19 @@
 2015-10-12  Jon Lee  <jonlee@apple.com>
 
+        Add canvas line segment tests
+        https://bugs.webkit.org/show_bug.cgi?id=150073
+        <rdar://problem/23082138>
+
+        Reviewed by Dean Jackson.
+
+        * Animometer/runner/resources/tests.js: Add new line segment tests, with different
+        line caps.
+        * Animometer/tests/simple/resources/simple-canvas-paths.js:
+        (CanvasLineSegment): Add new line segment paint object.
+        (CanvasLineSegmentStage): Create a new stage that sets the lineCap.
+
+2015-10-12  Jon Lee  <jonlee@apple.com>
+
         Add canvas path fill tests
         https://bugs.webkit.org/show_bug.cgi?id=150071
         <rdar://problem/23082001>