Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(260)

Unified Diff: src/gpu/GrShape.h

Issue 1922713002: Add support for building GrShape from SkPath and more tests (Closed) Base URL: https://chromium.googlesource.com/skia.git@strokeinfo
Patch Set: Address comments Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/gpu/GrShape.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/GrShape.h
diff --git a/src/gpu/GrShape.h b/src/gpu/GrShape.h
index 3c3f9ecec7b661ecbee709b21a85d11b81a214c9..57b1d8a9bf06af2ee1bd542497824ee4efdcd215 100644
--- a/src/gpu/GrShape.h
+++ b/src/gpu/GrShape.h
@@ -33,11 +33,24 @@
*/
class GrShape {
public:
+ 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) {}
explicit GrShape(const SkRect& rect) : fType(Type::kRRect), fRRect(SkRRect::MakeRect(rect)) {}
+ 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 +61,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 +142,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 +172,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;
« no previous file with comments | « no previous file | src/gpu/GrShape.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698