diff --git a/gfx/2d/DrawTargetSkia.cpp b/gfx/2d/DrawTargetSkia.cpp index f7c1fdf60a10..1af8a47140e9 100644 --- a/gfx/2d/DrawTargetSkia.cpp +++ b/gfx/2d/DrawTargetSkia.cpp @@ -137,36 +137,6 @@ GfxOpToSkiaOp(CompositionOp op) return SkXfermode::kSrcOver_Mode; } -SkPaint::Cap -CapStyleToSkiaCap(CapStyle aCap) -{ - switch (aCap) - { - case CAP_BUTT: - return SkPaint::kButt_Cap; - case CAP_ROUND: - return SkPaint::kRound_Cap; - case CAP_SQUARE: - return SkPaint::kSquare_Cap; - } - return SkPaint::kDefault_Cap; -} - -SkPaint::Join -JoinStyleToSkiaJoin(JoinStyle aJoin) -{ - switch (aJoin) - { - case JOIN_BEVEL: - return SkPaint::kBevel_Join; - case JOIN_ROUND: - return SkPaint::kRound_Join; - case JOIN_MITER: - case JOIN_MITER_OR_BEVEL: - return SkPaint::kMiter_Join; - } - return SkPaint::kDefault_Join; -} SkRect RectToSkRect(const Rect& aRect) @@ -337,27 +307,6 @@ struct AutoPaintSetup { } } - void SetStroke(const StrokeOptions &aOptions) - { - mPaint.setStrokeWidth(SkFloatToScalar(aOptions.mLineWidth)); - mPaint.setStrokeMiter(SkFloatToScalar(aOptions.mMiterLimit)); - mPaint.setStrokeCap(CapStyleToSkiaCap(aOptions.mLineCap)); - mPaint.setStrokeJoin(JoinStyleToSkiaJoin(aOptions.mLineJoin)); - if (aOptions.mDashLength) { - std::vector 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(mPaint.setPathEffect(dash)); - } - mPaint.setStyle(SkPaint::kStroke_Style); - } - // TODO: Maybe add an operator overload to access this easier? SkPaint mPaint; bool mNeedsRestore; @@ -495,7 +444,7 @@ DrawTargetSkia::Stroke(const Path *aPath, AutoPaintSetup paint(mCanvas.get(), aOptions, aPattern); - paint.SetStroke(aStrokeOptions); + StrokeOptionsToPaint(paint.mPaint, aStrokeOptions); mCanvas->drawPath(skiaPath->GetPath(), paint.mPaint); } @@ -508,7 +457,7 @@ DrawTargetSkia::StrokeRect(const Rect &aRect, { MarkChanged(); AutoPaintSetup paint(mCanvas.get(), aOptions, aPattern); - paint.SetStroke(aStrokeOptions); + StrokeOptionsToPaint(paint.mPaint, aStrokeOptions); mCanvas->drawRect(RectToSkRect(aRect), paint.mPaint); } @@ -522,7 +471,7 @@ DrawTargetSkia::StrokeLine(const Point &aStart, { MarkChanged(); AutoPaintSetup paint(mCanvas.get(), aOptions, aPattern); - paint.SetStroke(aStrokeOptions); + StrokeOptionsToPaint(paint.mPaint, aStrokeOptions); mCanvas->drawLine(SkFloatToScalar(aStart.x), SkFloatToScalar(aStart.y), SkFloatToScalar(aEnd.x), SkFloatToScalar(aEnd.y), diff --git a/gfx/2d/HelpersSkia.h b/gfx/2d/HelpersSkia.h index d52dff165df6..38f07eeef5d9 100644 --- a/gfx/2d/HelpersSkia.h +++ b/gfx/2d/HelpersSkia.h @@ -40,6 +40,7 @@ #include "2D.h" #include "skia/SkCanvas.h" +#include "skia/SkDashPathEffect.h" namespace mozilla { namespace gfx { @@ -72,6 +73,59 @@ GfxMatrixToSkiaMatrix(const Matrix& mat, SkMatrix& retval) 0, 0, SK_Scalar1); } +static inline SkPaint::Cap +CapStyleToSkiaCap(CapStyle aCap) +{ + switch (aCap) + { + case CAP_BUTT: + return SkPaint::kButt_Cap; + case CAP_ROUND: + return SkPaint::kRound_Cap; + case CAP_SQUARE: + return SkPaint::kSquare_Cap; + } + return SkPaint::kDefault_Cap; +} + +static inline SkPaint::Join +JoinStyleToSkiaJoin(JoinStyle aJoin) +{ + switch (aJoin) + { + case JOIN_BEVEL: + return SkPaint::kBevel_Join; + case JOIN_ROUND: + return SkPaint::kRound_Join; + case JOIN_MITER: + case JOIN_MITER_OR_BEVEL: + return SkPaint::kMiter_Join; + } + return SkPaint::kDefault_Join; +} + +static inline void +StrokeOptionsToPaint(SkPaint& aPaint, const StrokeOptions &aOptions) +{ + aPaint.setStrokeWidth(SkFloatToScalar(aOptions.mLineWidth)); + aPaint.setStrokeMiter(SkFloatToScalar(aOptions.mMiterLimit)); + aPaint.setStrokeCap(CapStyleToSkiaCap(aOptions.mLineCap)); + aPaint.setStrokeJoin(JoinStyleToSkiaJoin(aOptions.mLineJoin)); + if (aOptions.mDashLength) { + std::vector 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); +} + } } diff --git a/gfx/2d/PathSkia.cpp b/gfx/2d/PathSkia.cpp index df9bfc017bfd..c28f2923c4a1 100644 --- a/gfx/2d/PathSkia.cpp +++ b/gfx/2d/PathSkia.cpp @@ -196,8 +196,14 @@ Rect PathSkia::GetStrokedBounds(const StrokeOptions &aStrokeOptions, const Matrix &aTransform) const { - NS_ASSERTION(false, "GetStrokedBounds not supported yet!"); - return Rect(0, 0, 0, 0); + SkPaint paint; + StrokeOptionsToPaint(paint, aStrokeOptions); + + SkPath result; + paint.getFillPath(mPath, &result); + + Rect bounds = SkRectToRect(result.getBounds()); + return aTransform.TransformBounds(bounds); } }