From 5e410b4a68d11a06c331139905171952ef535cf8 Mon Sep 17 00:00:00 2001 From: bsalomon Date: Thu, 28 Apr 2016 09:30:46 -0700 Subject: [PATCH] Detect empty (r)rects in GrShape. GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1929643002 Review-Url: https://codereview.chromium.org/1929643002 --- src/gpu/GrShape.h | 42 ++++++++++++++++++++++++++++++++++-------- tests/GrShapeTest.cpp | 15 ++++++++++++++- 2 files changed, 48 insertions(+), 9 deletions(-) diff --git a/src/gpu/GrShape.h b/src/gpu/GrShape.h index 57b1d8a..0e863e2 100644 --- a/src/gpu/GrShape.h +++ b/src/gpu/GrShape.h @@ -33,16 +33,25 @@ */ class GrShape { public: - GrShape(const SkPath& path) + GrShape() : fType(Type::kEmpty) {} + + explicit GrShape(const SkPath& path) : fType(Type::kPath) , fPath(&path) { this->attemptToReduceFromPath(); } - GrShape() : fType(Type::kEmpty) {} + explicit GrShape(const SkRRect& rrect) + : fType(Type::kRRect) + , fRRect(rrect) { + this->attemptToReduceFromRRect(); + } - explicit GrShape(const SkRRect& rrect) : fType(Type::kRRect), fRRect(rrect) {} - explicit GrShape(const SkRect& rect) : fType(Type::kRRect), fRRect(SkRRect::MakeRect(rect)) {} + explicit GrShape(const SkRect& rect) + : fType(Type::kRRect) + , fRRect(SkRRect::MakeRect(rect)) { + this->attemptToReduceFromRRect(); + } GrShape(const SkPath& path, const GrStyle& style) : fType(Type::kPath) @@ -54,12 +63,16 @@ public: GrShape(const SkRRect& rrect, const GrStyle& style) : fType(Type::kRRect) , fRRect(rrect) - , fStyle(style) {} + , fStyle(style) { + this->attemptToReduceFromRRect(); + } GrShape(const SkRect& rect, const GrStyle& style) : fType(Type::kRRect) , fRRect(SkRRect::MakeRect(rect)) - , fStyle(style) {} + , fStyle(style) { + this->attemptToReduceFromRRect(); + } GrShape(const SkPath& path, const SkPaint& paint) : fType(Type::kPath) @@ -71,12 +84,16 @@ public: GrShape(const SkRRect& rrect, const SkPaint& paint) : fType(Type::kRRect) , fRRect(rrect) - , fStyle(paint) {} + , fStyle(paint) { + this->attemptToReduceFromRRect(); + } GrShape(const SkRect& rect, const SkPaint& paint) : fType(Type::kRRect) , fRRect(SkRRect::MakeRect(rect)) - , fStyle(paint) {} + , fStyle(paint) { + this->attemptToReduceFromRRect(); + } GrShape(const GrShape&); GrShape& operator=(const GrShape& that); @@ -182,12 +199,21 @@ private: } } + void attemptToReduceFromRRect() { + SkASSERT(Type::kRRect == fType); + SkASSERT(!fInheritedKey.count()); + if (fRRect.isEmpty()) { + fType = Type::kEmpty; + } + } + static Type AttemptToReduceFromPathImpl(const SkPath& path, SkRRect* rrect, const SkPathEffect* pe, const SkStrokeRec& strokeRec) { if (path.isEmpty()) { return Type::kEmpty; } if (path.isRRect(rrect)) { + SkASSERT(!rrect->isEmpty()); return Type::kRRect; } SkRect rect; diff --git a/tests/GrShapeTest.cpp b/tests/GrShapeTest.cpp index de08457..715afcb 100644 --- a/tests/GrShapeTest.cpp +++ b/tests/GrShapeTest.cpp @@ -550,9 +550,22 @@ void test_empty_shape(skiatest::Reporter* reporter) { dashAndStroke.setPathEffect(make_dash()); dashAndStroke.setStrokeWidth(2.f); dashAndStroke.setStyle(SkPaint::kStroke_Style); - TestCase dashAndStrokeEmptyCase(emptyPath3, stroke); + TestCase dashAndStrokeEmptyCase(emptyPath3, dashAndStroke); dashAndStrokeEmptyCase.compare(reporter, fillEmptyCase, TestCase::kAllSame_ComparisonExpecation); + + // A shape made from an empty rrect should behave the same as an empty path. + SkRRect emptyRRect = SkRRect::MakeRect(SkRect::MakeEmpty()); + REPORTER_ASSERT(reporter, emptyRRect.getType() == SkRRect::kEmpty_Type); + TestCase dashAndStrokeEmptyRRectCase(emptyRRect, dashAndStroke); + dashAndStrokeEmptyRRectCase.compare(reporter, fillEmptyCase, + TestCase::kAllSame_ComparisonExpecation); + + // Same for a rect. + SkRect emptyRect = SkRect::MakeEmpty(); + TestCase dashAndStrokeEmptyRectCase(emptyRect, dashAndStroke); + dashAndStrokeEmptyRectCase.compare(reporter, fillEmptyCase, + TestCase::kAllSame_ComparisonExpecation); } DEF_TEST(GrShape, reporter) { -- 2.7.4