diff options
author | bsalomon <bsalomon@google.com> | 2016-06-28 11:56:42 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-06-28 11:56:42 -0700 |
commit | 0a0f67ececbdf1a7f81296ed0d2cb9e3bc00e4dc (patch) | |
tree | f49e73525e56c6e6d0dcfc68f1eeba895920137b /src/gpu/GrShape.h | |
parent | 635df95a9a25c66959f76b4bbb594b75333ded21 (diff) |
Make lines a special case in GrShape
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2108523002
Committed: https://skia.googlesource.com/skia/+/c62318c748a1907649bd75382c4f4fd10533f2b3
Review-Url: https://codereview.chromium.org/2108523002
Diffstat (limited to 'src/gpu/GrShape.h')
-rw-r--r-- | src/gpu/GrShape.h | 48 |
1 files changed, 40 insertions, 8 deletions
diff --git a/src/gpu/GrShape.h b/src/gpu/GrShape.h index 87ee26e173..8f3be58702 100644 --- a/src/gpu/GrShape.h +++ b/src/gpu/GrShape.h @@ -152,12 +152,19 @@ public: * If the unstyled shape is a straight line segment, returns true and sets pts to the endpoints. * An inverse filled line path is still considered a line. */ - bool asLine(SkPoint pts[2]) const { - if (fType != Type::kPath) { - return false; - } - return this->path().isLine(pts); - } + bool asLine(SkPoint pts[2], bool* inverted) const { + if (fType != Type::kLine) { + return false; + } + if (pts) { + pts[0] = fLineData.fPts[0]; + pts[1] = fLineData.fPts[1]; + } + if (inverted) { + *inverted = fLineData.fInverted; + } + return true; + } /** Returns the unstyled geometry as a path. */ void asPath(SkPath* out) const { @@ -175,6 +182,16 @@ public: out->setFillType(kDefaultPathFillType); } break; + case Type::kLine: + out->reset(); + out->moveTo(fLineData.fPts[0]); + out->lineTo(fLineData.fPts[1]); + if (fLineData.fInverted) { + out->setFillType(kDefaultPathInverseFillType); + } else { + out->setFillType(kDefaultPathFillType); + } + break; case Type::kPath: *out = this->path(); break; @@ -191,13 +208,13 @@ public: * Gets the bounds of the geometry without reflecting the shape's styling. This ignores * the inverse fill nature of the geometry. */ - const SkRect& bounds() const; + SkRect bounds() const; /** * Gets the bounds of the geometry reflecting the shape's styling (ignoring inverse fill * status). */ - void styledBounds(SkRect* bounds) const; + SkRect styledBounds() const; /** * Is this shape known to be convex, before styling is applied. An unclosed but otherwise @@ -210,6 +227,8 @@ public: return true; case Type::kRRect: return true; + case Type::kLine: + return true; case Type::kPath: // SkPath.isConvex() really means "is this path convex were it to be closed" and // thus doesn't give the correct answer for stroked paths, hence we also check @@ -231,6 +250,9 @@ public: case Type::kRRect: ret = fRRectData.fInverted; break; + case Type::kLine: + ret = fLineData.fInverted; + break; case Type::kPath: ret = this->path().isInverseFillType(); break; @@ -264,6 +286,8 @@ public: return true; case Type::kRRect: return true; + case Type::kLine: + return false; case Type::kPath: // SkPath doesn't keep track of the closed status of each contour. return SkPathPriv::IsClosedSingleContour(this->path()); @@ -282,6 +306,8 @@ public: return SkPath::kLine_SegmentMask; } return SkPath::kLine_SegmentMask | SkPath::kConic_SegmentMask; + case Type::kLine: + return SkPath::kLine_SegmentMask; case Type::kPath: return this->path().getSegmentMasks(); } @@ -307,6 +333,7 @@ private: enum class Type { kEmpty, kRRect, + kLine, kPath, }; @@ -356,6 +383,7 @@ private: void attemptToSimplifyPath(); void attemptToSimplifyRRect(); + void attemptToSimplifyLine(); // Defaults to use when there is no distinction between even/odd and winding fills. static constexpr SkPath::FillType kDefaultPathFillType = SkPath::kEvenOdd_FillType; @@ -420,6 +448,10 @@ private: // Gen ID of the original path (fPath may be modified) int32_t fGenID; } fPathData; + struct { + SkPoint fPts[2]; + bool fInverted; + } fLineData; }; GrStyle fStyle; SkAutoSTArray<8, uint32_t> fInheritedKey; |