diff options
-rw-r--r-- | expectations/gm/ignored-tests.txt | 3 | ||||
-rw-r--r-- | gm/strokefill.cpp | 39 | ||||
-rw-r--r-- | include/core/SkPath.h | 20 | ||||
-rw-r--r-- | src/core/SkPath.cpp | 17 | ||||
-rw-r--r-- | src/core/SkStroke.cpp | 5 |
5 files changed, 66 insertions, 18 deletions
diff --git a/expectations/gm/ignored-tests.txt b/expectations/gm/ignored-tests.txt index 9b35ba4d99..b8df60054e 100644 --- a/expectations/gm/ignored-tests.txt +++ b/expectations/gm/ignored-tests.txt @@ -48,3 +48,6 @@ dashcubics #reed - gm updated, so just need to rebaseline c_gms + +#robertphillips - updated GM +stroke-fill diff --git a/gm/strokefill.cpp b/gm/strokefill.cpp index 85d7b6d5c4..4a29100e62 100644 --- a/gm/strokefill.cpp +++ b/gm/strokefill.cpp @@ -79,6 +79,42 @@ protected: path2.addCircle(x + SkIntToScalar(360), y + SkIntToScalar(200), SkIntToScalar(50), SkPath::kCW_Direction); SkASSERT(path2.cheapIsDirection(SkPath::kCW_Direction)); canvas->drawPath(path2, paint); + + SkRect r = SkRect::MakeXYWH(x - SkIntToScalar(50), y + SkIntToScalar(280), + SkIntToScalar(100), SkIntToScalar(100)); + SkPath path3; + path3.setFillType(SkPath::kWinding_FillType); + path3.addRect(r, SkPath::kCW_Direction); + r.inset(SkIntToScalar(10), SkIntToScalar(10)); + path3.addRect(r, SkPath::kCCW_Direction); + canvas->drawPath(path3, paint); + + r = SkRect::MakeXYWH(x + SkIntToScalar(70), y + SkIntToScalar(280), + SkIntToScalar(100), SkIntToScalar(100)); + SkPath path4; + path4.setFillType(SkPath::kWinding_FillType); + path4.addRect(r, SkPath::kCCW_Direction); + r.inset(SkIntToScalar(10), SkIntToScalar(10)); + path4.addRect(r, SkPath::kCW_Direction); + canvas->drawPath(path4, paint); + + r = SkRect::MakeXYWH(x + SkIntToScalar(190), y + SkIntToScalar(280), + SkIntToScalar(100), SkIntToScalar(100)); + path4.reset(); + SkASSERT(!path4.cheapComputeDirection(NULL)); + path4.addRect(r, SkPath::kCCW_Direction); + SkASSERT(path4.cheapIsDirection(SkPath::kCCW_Direction)); + path4.moveTo(0, 0); // test for crbug.com/247770 + canvas->drawPath(path4, paint); + + r = SkRect::MakeXYWH(x + SkIntToScalar(310), y + SkIntToScalar(280), + SkIntToScalar(100), SkIntToScalar(100)); + path4.reset(); + SkASSERT(!path4.cheapComputeDirection(NULL)); + path4.addRect(r, SkPath::kCW_Direction); + SkASSERT(path4.cheapIsDirection(SkPath::kCW_Direction)); + path4.moveTo(0, 0); // test for crbug.com/247770 + canvas->drawPath(path4, paint); } private: @@ -87,7 +123,6 @@ private: ////////////////////////////////////////////////////////////////////////////// -static GM* MyFactory(void*) { return new StrokeFillGM; } -static GMRegistry reg(MyFactory); +DEF_GM(return SkNEW(StrokeFillGM);) } diff --git a/include/core/SkPath.h b/include/core/SkPath.h index f5a6d4a2e7..4b95e893e2 100644 --- a/include/core/SkPath.h +++ b/include/core/SkPath.h @@ -247,7 +247,7 @@ public: a rectangle @return true if the path specifies a rectangle */ - bool isRect(SkRect* rect) const; + bool isRect(SkRect* rect) const { return this->isRect(rect, NULL, NULL); } /** Return the number of points in the path */ @@ -601,7 +601,23 @@ public: @param direction If not null, set to the rectangle's direction @return true if the path specifies a rectangle */ - bool isRect(bool* isClosed, Direction* direction) const; + bool isRect(bool* isClosed, Direction* direction) const { + return this->isRect(NULL, isClosed, direction); + } + + /** + * Returns true if the path specifies a rectangle. + * + * If this returns false, then all output parameters are ignored, and left + * unchanged. If this returns true, then each of the output parameters + * are checked for NULL. If they are not, they return their value. + * + * @param rect If not null, set to the bounds of the rectangle + * @param isClosed If not null, set to true if the path is closed + * @param direction If not null, set to the rectangle's direction + * @return true if the path specifies a rectangle + */ + bool isRect(SkRect* rect, bool* isClosed, Direction* direction) const; /** Returns true if the path specifies a pair of nested rectangles. If so, and if rect is not null, set rect[0] to the outer rectangle and rect[1] to the inner diff --git a/src/core/SkPath.cpp b/src/core/SkPath.cpp index f8aa8521da..27b7283263 100644 --- a/src/core/SkPath.cpp +++ b/src/core/SkPath.cpp @@ -534,18 +534,18 @@ SkPath::PathAsRect SkPath::asRect(Direction* direction) const { return (PathAsRect) (isRect(&isClosed, direction) + isClosed); } -bool SkPath::isRect(SkRect* rect) const { +bool SkPath::isRect(SkRect* rect, bool* isClosed, Direction* direction) const { SkDEBUGCODE(this->validate();) int currVerb = 0; const SkPoint* pts = fPathRef->points(); const SkPoint* first = pts; - bool isClosed; - if (!this->isRectContour(false, &currVerb, &pts, &isClosed, NULL)) { + if (!this->isRectContour(false, &currVerb, &pts, isClosed, direction)) { return false; } if (rect) { - if (isClosed) { - rect->set(first, SkToS32(pts - first)); + int32_t num = SkToS32(pts - first); + if (num) { + rect->set(first, num); } else { // 'pts' isn't updated for open rects *rect = this->getBounds(); @@ -554,13 +554,6 @@ bool SkPath::isRect(SkRect* rect) const { return true; } -bool SkPath::isRect(bool* isClosed, Direction* direction) const { - SkDEBUGCODE(this->validate();) - int currVerb = 0; - const SkPoint* pts = fPathRef->points(); - return isRectContour(false, &currVerb, &pts, isClosed, direction); -} - bool SkPath::isNestedRects(SkRect rects[2], Direction dirs[2]) const { SkDEBUGCODE(this->validate();) int currVerb = 0; diff --git a/src/core/SkStroke.cpp b/src/core/SkStroke.cpp index c562c2e433..f8173c0555 100644 --- a/src/core/SkStroke.cpp +++ b/src/core/SkStroke.cpp @@ -1414,10 +1414,11 @@ void SkStroke::strokePath(const SkPath& src, SkPath* dst) const { // If src is really a rect, call our specialty strokeRect() method { + SkRect rect; bool isClosed; SkPath::Direction dir; - if (src.isRect(&isClosed, &dir) && isClosed) { - this->strokeRect(src.getBounds(), dst, dir); + if (src.isRect(&rect, &isClosed, &dir) && isClosed) { + this->strokeRect(rect, dst, dir); // our answer should preserve the inverseness of the src if (src.isInverseFillType()) { SkASSERT(!dst->isInverseFillType()); |