diff options
Diffstat (limited to 'src/core/SkStroke.cpp')
-rw-r--r-- | src/core/SkStroke.cpp | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/src/core/SkStroke.cpp b/src/core/SkStroke.cpp index fd7dccc6c7..0d3885f0ea 100644 --- a/src/core/SkStroke.cpp +++ b/src/core/SkStroke.cpp @@ -563,12 +563,38 @@ void SkStroke::setJoin(SkPaint::Join join) { #define APPLY_PROC(proc, pts, count) #endif +// If src==dst, then we use a tmp path to record the stroke, and then swap +// its contents with src when we're done. +class AutoTmpPath { +public: + AutoTmpPath(const SkPath& src, SkPath** dst) : fSrc(src) { + if (&src == *dst) { + *dst = &fTmpDst; + } else { + (*dst)->reset(); + fSwapWithSrc = false; + } + } + + ~AutoTmpPath() { + if (fSwapWithSrc) { + fTmpDst.swap(*const_cast<SkPath*>(&fSrc)); + } + } + +private: + SkPath fTmpDst; + const SkPath& fSrc; + bool fSwapWithSrc; +}; + void SkStroke::strokePath(const SkPath& src, SkPath* dst) const { SkASSERT(&src != NULL && dst != NULL); SkScalar radius = SkScalarHalf(fWidth); - dst->reset(); + AutoTmpPath tmp(src, &dst); + if (radius <= 0) { return; } |