Bug 703428 - Handle invalid stroke options. r=jrmuizel

This commit is contained in:
Matt Woodrow 2011-11-18 17:00:38 +13:00
parent c57d11d687
commit 26c2668d5a
2 changed files with 17 additions and 5 deletions

View File

@ -444,7 +444,9 @@ DrawTargetSkia::Stroke(const Path *aPath,
AutoPaintSetup paint(mCanvas.get(), aOptions, aPattern);
StrokeOptionsToPaint(paint.mPaint, aStrokeOptions);
if (!StrokeOptionsToPaint(paint.mPaint, aStrokeOptions)) {
return;
}
mCanvas->drawPath(skiaPath->GetPath(), paint.mPaint);
}
@ -457,7 +459,9 @@ DrawTargetSkia::StrokeRect(const Rect &aRect,
{
MarkChanged();
AutoPaintSetup paint(mCanvas.get(), aOptions, aPattern);
StrokeOptionsToPaint(paint.mPaint, aStrokeOptions);
if (!StrokeOptionsToPaint(paint.mPaint, aStrokeOptions)) {
return;
}
mCanvas->drawRect(RectToSkRect(aRect), paint.mPaint);
}
@ -471,7 +475,9 @@ DrawTargetSkia::StrokeLine(const Point &aStart,
{
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),

View File

@ -104,14 +104,19 @@ JoinStyleToSkiaJoin(JoinStyle aJoin)
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++) {
@ -124,6 +129,7 @@ StrokeOptionsToPaint(SkPaint& aPaint, const StrokeOptions &aOptions)
SkSafeUnref(aPaint.setPathEffect(dash));
}
aPaint.setStyle(SkPaint::kStroke_Style);
return true;
}
}