aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/GrShape.h
diff options
context:
space:
mode:
authorGravatar bsalomon <bsalomon@google.com>2016-06-28 10:41:34 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-06-28 10:41:35 -0700
commitc62318c748a1907649bd75382c4f4fd10533f2b3 (patch)
tree5f27386533260d1c9dedffe708fb03259d5af039 /src/gpu/GrShape.h
parent0829e49af2d70d9d33ba3b6b43d2114bcf5c95df (diff)
Make lines a special case in GrShape
Diffstat (limited to 'src/gpu/GrShape.h')
-rw-r--r--src/gpu/GrShape.h48
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;