Bug 740963 - [Skia] Handle non-multiple-of-two dash lengths in HelpersSkia::StrokeOptionsToPaint(). r=jrmuizel
authorGeorge Wright <gwright@mozilla.com>
Fri, 30 Mar 2012 17:36:34 -0400
changeset 90752 fa5f41ab53150ccb79538437efc2fd1e310307da
parent 90751 297ddf568a6a876d5943567bfaca353075031747
child 90753 84463b2ba5ff45454e0779218522b96d8fac4622
push id22382
push userbmo@edmorley.co.uk
push dateSat, 31 Mar 2012 21:44:34 +0000
treeherdermozilla-central@bbe5086163c9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel
bugs740963
milestone14.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 740963 - [Skia] Handle non-multiple-of-two dash lengths in HelpersSkia::StrokeOptionsToPaint(). r=jrmuizel
gfx/2d/HelpersSkia.h
--- a/gfx/2d/HelpersSkia.h
+++ b/gfx/2d/HelpersSkia.h
@@ -113,32 +113,39 @@ StrokeOptionsToPaint(SkPaint& aPaint, co
   if (!aOptions.mLineWidth) {
     return false;
   }
   aPaint.setStrokeWidth(SkFloatToScalar(aOptions.mLineWidth));
   aPaint.setStrokeMiter(SkFloatToScalar(aOptions.mMiterLimit));
   aPaint.setStrokeCap(CapStyleToSkiaCap(aOptions.mLineCap));
   aPaint.setStrokeJoin(JoinStyleToSkiaJoin(aOptions.mLineJoin));
 
-  // XXX: According to the webkit code skia seems to only
-  // support dash arrays that are multiples of 2. Therefor,
-  // We need to double the array when % 2 != 0
-  MOZ_ASSERT(aOptions.mDashLength % 2 == 0);
-  if (aOptions.mDashLength > 1) {
+  if (aOptions.mDashLength > 0) {
+    // Skia only supports dash arrays that are multiples of 2.
+    uint32_t dashCount;
+
+    if (aOptions.mDashLength % 2 == 0) {
+      dashCount = aOptions.mDashLength;
+    } else {
+      dashCount = aOptions.mDashLength * 2;
+    }
+
     std::vector<SkScalar> pattern;
-    pattern.resize(aOptions.mDashLength);
-    for (uint32_t i = 0; i < aOptions.mDashLength; i++) {
-      pattern[i] = SkFloatToScalar(aOptions.mDashPattern[i]);
+    pattern.resize(dashCount);
+
+    for (uint32_t i = 0; i < dashCount; i++) {
+      pattern[i] = SkFloatToScalar(aOptions.mDashPattern[i % aOptions.mDashLength]);
     }
-    
-    SkDashPathEffect* dash = new SkDashPathEffect(&pattern.front(), 
-                                                  aOptions.mDashLength, 
+
+    SkDashPathEffect* dash = new SkDashPathEffect(&pattern.front(),
+                                                  dashCount, 
                                                   SkFloatToScalar(aOptions.mDashOffset));
     SkSafeUnref(aPaint.setPathEffect(dash));
   }
+
   aPaint.setStyle(SkPaint::kStroke_Style);
   return true;
 }
 
 }
 }
 
 #endif /* MOZILLA_GFX_HELPERSSKIA_H_ */