Bug 1117514 - lines with zero length dashes are not rendered. r=jwatt
authorRobert Longson <longsonr@gmail.com>
Sat, 10 Jan 2015 22:17:57 +0000
changeset 248968 29229def6b2e26f1e7d10016f6abe14e1182d9cb
parent 248967 b55daf871dd244abd3b173815a19207378670566
child 248969 5f41156dbd4c15193f07ae77a88313153b5782cf
push id4489
push userraliiev@mozilla.com
push dateMon, 23 Feb 2015 15:17:55 +0000
treeherdermozilla-beta@fd7c3dc24146 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwatt
bugs1117514
milestone37.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1117514 - lines with zero length dashes are not rendered. r=jwatt
dom/svg/SVGContentUtils.cpp
layout/reftests/svg/stroke-linecap-round-w-zero-length-segs-01.svg
--- a/dom/svg/SVGContentUtils.cpp
+++ b/dom/svg/SVGContentUtils.cpp
@@ -133,22 +133,34 @@ GetStrokeDashData(SVGContentUtils::AutoS
     // When deciding whether to return eNoStroke or eContinuousStroke below we
     // need to take into account that in the repeat pattern the dashes become
     // gaps, and the gaps become dashes.
     Float origTotalLengthOfDashes = totalLengthOfDashes;
     totalLengthOfDashes += totalLengthOfGaps;
     totalLengthOfGaps += origTotalLengthOfDashes;
   }
 
-  if (totalLengthOfDashes <= 0 || totalLengthOfGaps <= 0) {
-    if (totalLengthOfGaps > 0 && totalLengthOfDashes <= 0) {
-      return eNoStroke;
-    }
+  // Stroking using dashes is much slower than stroking a continuous line
+  // (see bug 609361 comment 40), and much, much slower than not stroking the
+  // line at all. Here we check for cases when the dash pattern causes the
+  // stroke to essentially be continuous or to be nonexistent in which case
+  // we can avoid expensive stroking operations (the underlying platform
+  // graphics libraries don't seem to optimize for this).
+  if (totalLengthOfDashes <= 0 && totalLengthOfGaps <= 0) {
+    return eNoStroke;
+  }
+  if (totalLengthOfGaps <= 0) {
     return eContinuousStroke;
   }
+  // We can only return eNoStroke if the value of stroke-linecap isn't
+  // adding caps to zero length dashes.
+  if (totalLengthOfDashes <= 0 &&
+      aStyleSVG->mStrokeLinecap == NS_STYLE_STROKE_LINECAP_BUTT) {
+    return eNoStroke;
+  }
 
   if (aContextPaint && aStyleSVG->mStrokeDashoffsetFromObject) {
     aStrokeOptions->mDashOffset = Float(aContextPaint->GetStrokeDashOffset());
   } else {
     aStrokeOptions->mDashOffset =
       SVGContentUtils::CoordToFloat(aElement, aStyleSVG->mStrokeDashoffset);
   }
 
--- a/layout/reftests/svg/stroke-linecap-round-w-zero-length-segs-01.svg
+++ b/layout/reftests/svg/stroke-linecap-round-w-zero-length-segs-01.svg
@@ -139,9 +139,17 @@ path.coverer {
 
   <!-- Column 4: test lone movetos -->
 
   <g transform="translate(425,25)">
     <path class="circles-not-expected" d="M0,0 M0,0  M20,20 L30,30  M50,50 M50,50  M70,70 L80,80  M100,100 M100,100"/>
     <path class="coverer" d="M20,20 L30,30 M70,70 L80,80"/>
   </g>
 
+  <!-- Column 5: test stroke-dasharray -->
+
+  <g transform="translate(525,25)">
+    <circle cy="0" r="8"/>
+    <circle cy="40" r="8"/>
+    <circle cy="80" r="8"/>
+    <path class="circles-expected" d="M0,0v81" stroke-dasharray="0 40" />
+  </g>
 </svg>