Chromium Code Reviews| Index: src/gpu/GrShape.h |
| diff --git a/src/gpu/GrShape.h b/src/gpu/GrShape.h |
| index 3c3f9ecec7b661ecbee709b21a85d11b81a214c9..604f969202377b6e18dfa51c3a0eebd8a4ec4f02 100644 |
| --- a/src/gpu/GrShape.h |
| +++ b/src/gpu/GrShape.h |
| @@ -38,6 +38,13 @@ public: |
| explicit GrShape(const SkRRect& rrect) : fType(Type::kRRect), fRRect(rrect) {} |
| explicit GrShape(const SkRect& rect) : fType(Type::kRRect), fRRect(SkRRect::MakeRect(rect)) {} |
|
robertphillips
2016/04/26 22:18:32
No un-styled variants ?
bsalomon
2016/04/29 23:12:06
Done.
|
| + GrShape(const SkPath& path, const GrStyle& style) |
| + : fType(Type::kPath) |
| + , fPath(&path) |
| + , fStyle(style) { |
| + this->attemptToReduceFromPath(); |
| + } |
| + |
| GrShape(const SkRRect& rrect, const GrStyle& style) |
| : fType(Type::kRRect) |
| , fRRect(rrect) |
| @@ -48,6 +55,13 @@ public: |
| , fRRect(SkRRect::MakeRect(rect)) |
| , fStyle(style) {} |
| + GrShape(const SkPath& path, const SkPaint& paint) |
| + : fType(Type::kPath) |
| + , fPath(&path) |
| + , fStyle(paint) { |
| + this->attemptToReduceFromPath(); |
| + } |
| + |
| GrShape(const SkRRect& rrect, const SkPaint& paint) |
| : fType(Type::kRRect) |
| , fRRect(rrect) |
| @@ -122,6 +136,12 @@ public: |
| void writeUnstyledKey(uint32_t* key) const; |
| private: |
| + enum class Type { |
| + kEmpty, |
| + kRRect, |
| + kPath, |
| + }; |
| + |
| /** |
| * Computes the key length for a GrStyle. The return will be negative if it cannot be turned |
| * into a key. |
| @@ -146,12 +166,40 @@ private: |
| */ |
| void setInheritedKey(const GrShape& parentShape, bool stopAfterPE); |
| - enum class Type { |
| - kEmpty, |
| - kRRect, |
| - kPath, |
| - } fType; |
| + void attemptToReduceFromPath() { |
| + SkASSERT(Type::kPath == fType); |
| + fType = AttemptToReduceFromPathImpl(*fPath.get(), &fRRect, fStyle.pathEffect(), |
| + fStyle.strokeRec()); |
| + if (Type::kPath != fType) { |
| + fPath.reset(); |
| + fInheritedKey.reset(0); |
| + } |
| + } |
| + |
| + static Type AttemptToReduceFromPathImpl(const SkPath& path, SkRRect* rrect, |
| + const SkPathEffect* pe, const SkStrokeRec& strokeRec) { |
| + if (path.isEmpty()) { |
| + return Type::kEmpty; |
| + } |
| + if (path.isRRect(rrect)) { |
| + return Type::kRRect; |
| + } |
| + SkRect rect; |
| + if (path.isOval(&rect)) { |
| + rrect->setOval(rect); |
| + return Type::kRRect; |
| + } |
| + bool closed; |
| + if (path.isRect(&rect, &closed, nullptr)) { |
| + if (closed || (!pe && strokeRec.isFillStyle())) { |
| + rrect->setRect(rect); |
| + return Type::kRRect; |
| + } |
| + } |
| + return Type::kPath; |
| + } |
| + Type fType; |
| SkRRect fRRect; |
| SkTLazy<SkPath> fPath; |
| GrStyle fStyle; |