Bug 703428 - Handle invalid stroke options. r=jrmuizel
authorMatt Woodrow <mwoodrow@mozilla.com>
Fri, 18 Nov 2011 17:00:38 +1300
changeset 82074 a5b54026dfb66e45f9fc76969a70055cbd5ff287
parent 82073 104c6daf8715ac46369c5c561f2b2d379cf27d10
child 82075 c94985276834e957515cf4972c79694cb7e5daae
push id519
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 00:38:35 +0000
treeherdermozilla-beta@788ea1ef610b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel
bugs703428
milestone11.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 703428 - Handle invalid stroke options. r=jrmuizel
gfx/2d/DrawTargetSkia.cpp
gfx/2d/HelpersSkia.h
--- a/gfx/2d/DrawTargetSkia.cpp
+++ b/gfx/2d/DrawTargetSkia.cpp
@@ -439,44 +439,50 @@ DrawTargetSkia::Stroke(const Path *aPath
   if (aPath->GetBackendType() != BACKEND_SKIA) {
     return;
   }
 
   const PathSkia *skiaPath = static_cast<const PathSkia*>(aPath);
 
 
   AutoPaintSetup paint(mCanvas.get(), aOptions, aPattern);
-  StrokeOptionsToPaint(paint.mPaint, aStrokeOptions);
+  if (!StrokeOptionsToPaint(paint.mPaint, aStrokeOptions)) {
+    return;
+  }
 
   mCanvas->drawPath(skiaPath->GetPath(), paint.mPaint);
 }
 
 void
 DrawTargetSkia::StrokeRect(const Rect &aRect,
                            const Pattern &aPattern,
                            const StrokeOptions &aStrokeOptions,
                            const DrawOptions &aOptions)
 {
   MarkChanged();
   AutoPaintSetup paint(mCanvas.get(), aOptions, aPattern);
-  StrokeOptionsToPaint(paint.mPaint, aStrokeOptions);
+  if (!StrokeOptionsToPaint(paint.mPaint, aStrokeOptions)) {
+    return;
+  }
 
   mCanvas->drawRect(RectToSkRect(aRect), paint.mPaint);
 }
 
 void 
 DrawTargetSkia::StrokeLine(const Point &aStart,
                            const Point &aEnd,
                            const Pattern &aPattern,
                            const StrokeOptions &aStrokeOptions,
                            const DrawOptions &aOptions)
 {
   MarkChanged();
   AutoPaintSetup paint(mCanvas.get(), aOptions, aPattern);
-  StrokeOptionsToPaint(paint.mPaint, aStrokeOptions);
+  if (!StrokeOptionsToPaint(paint.mPaint, aStrokeOptions)) {
+    return;
+  }
 
   mCanvas->drawLine(SkFloatToScalar(aStart.x), SkFloatToScalar(aStart.y), 
                     SkFloatToScalar(aEnd.x), SkFloatToScalar(aEnd.y), 
                     paint.mPaint);
 }
 
 void
 DrawTargetSkia::Fill(const Path *aPath,
--- a/gfx/2d/HelpersSkia.h
+++ b/gfx/2d/HelpersSkia.h
@@ -99,34 +99,40 @@ JoinStyleToSkiaJoin(JoinStyle aJoin)
       return SkPaint::kRound_Join;
     case JOIN_MITER:
     case JOIN_MITER_OR_BEVEL:
       return SkPaint::kMiter_Join;
   }
   return SkPaint::kDefault_Join;
 }
 
-static inline void
+static inline bool
 StrokeOptionsToPaint(SkPaint& aPaint, const StrokeOptions &aOptions)
 {
+  // Skia rendewrs 0 width strokes with a width of 1 (and in black),
+  // so we should just skip the draw call entirely.
+  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));
-  if (aOptions.mDashLength) {
+  if (aOptions.mDashLength > 1) {
     std::vector<SkScalar> pattern;
     pattern.resize(aOptions.mDashLength);
     for (uint32_t i = 0; i < aOptions.mDashLength; i++) {
       pattern[i] = SkFloatToScalar(aOptions.mDashPattern[i]);
     }
     
     SkDashPathEffect* dash = new SkDashPathEffect(&pattern.front(), 
                                                   aOptions.mDashLength, 
                                                   SkFloatToScalar(aOptions.mDashOffset));
     SkSafeUnref(aPaint.setPathEffect(dash));
   }
   aPaint.setStyle(SkPaint::kStroke_Style);
+  return true;
 }
 
 }
 }
 
 #endif /* MOZILLA_GFX_HELPERSSKIA_H_ */