aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar bsalomon <bsalomon@google.com>2016-05-13 09:23:38 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-05-13 09:23:38 -0700
commit9fb420393ee1c24fc3282b7155985fa8fa7bcad4 (patch)
tree4112171b2d2ae213d239178af89e7ce8f55d1b4d /src
parent4ca5539df5c02fabac9ec1a8d0a0f58a9966347e (diff)
Add bounds to GrShape
Diffstat (limited to 'src')
-rw-r--r--src/gpu/GrShape.cpp22
-rw-r--r--src/gpu/GrShape.h6
-rw-r--r--src/gpu/GrStyle.h4
3 files changed, 32 insertions, 0 deletions
diff --git a/src/gpu/GrShape.cpp b/src/gpu/GrShape.cpp
index 8462d4d41d..e0ddc55e02 100644
--- a/src/gpu/GrShape.cpp
+++ b/src/gpu/GrShape.cpp
@@ -37,6 +37,28 @@ GrShape& GrShape::operator=(const GrShape& that) {
return *this;
}
+const SkRect& GrShape::bounds() const {
+ static constexpr SkRect kEmpty = SkRect::MakeEmpty();
+ switch (fType) {
+ case Type::kEmpty:
+ return kEmpty;
+ case Type::kRRect:
+ return fRRect.getBounds();
+ case Type::kPath:
+ return fPath.get()->getBounds();
+ }
+ SkFAIL("Unknown shape type");
+ return kEmpty;
+}
+
+void GrShape::styledBounds(SkRect* bounds) const {
+ if (Type::kEmpty == fType && !fStyle.hasNonDashPathEffect()) {
+ *bounds = SkRect::MakeEmpty();
+ } else {
+ fStyle.adjustBounds(bounds, this->bounds());
+ }
+}
+
int GrShape::unstyledKeySize() const {
if (fInheritedKey.count()) {
return fInheritedKey.count();
diff --git a/src/gpu/GrShape.h b/src/gpu/GrShape.h
index 81684e8e2f..12093f4143 100644
--- a/src/gpu/GrShape.h
+++ b/src/gpu/GrShape.h
@@ -148,6 +148,12 @@ public:
*/
bool isEmpty() const { return Type::kEmpty == fType; }
+ /** Gets the bounds of the geometry without reflecting the shape's styling. */
+ const SkRect& bounds() const;
+
+ /** Gets the bounds of the geometry reflecting the shape's styling. */
+ void styledBounds(SkRect* bounds) const;
+
/**
* Is it known that the unstyled geometry has no unclosed contours. This means that it will
* not have any caps if stroked (modulo the effect of any path effect).
diff --git a/src/gpu/GrStyle.h b/src/gpu/GrStyle.h
index 07efb40866..cbaa50d9ef 100644
--- a/src/gpu/GrStyle.h
+++ b/src/gpu/GrStyle.h
@@ -167,6 +167,10 @@ public:
void adjustBounds(SkRect* dst, const SkRect& src) const {
if (this->pathEffect()) {
this->pathEffect()->computeFastBounds(dst, src);
+ // This may not be the correct SkStrokeRec to use. skbug.com/5299
+ // It happens to work for dashing.
+ SkScalar radius = fStrokeRec.getInflationRadius();
+ dst->outset(radius, radius);
} else {
SkScalar radius = fStrokeRec.getInflationRadius();
*dst = src.makeOutset(radius, radius);