bsalomon 2016-04-28 09:30:46 -07:00 committed by Commit bot
parent dd97b8585a
commit 5e410b4a68
2 changed files with 48 additions and 9 deletions

View File

@ -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;

View File

@ -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) {