aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu
diff options
context:
space:
mode:
authorGravatar bsalomon <bsalomon@google.com>2016-05-04 13:50:29 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-05-04 13:50:29 -0700
commit06077565b18714ff3fc0db9118e2c21f6f25243f (patch)
treeb5b250ce3600dc4fd67ebea5d7096ec1779bc133 /src/gpu
parent345242671587d7273819bfe423be96e4392033e3 (diff)
Make cap only affect the keys of GrShapes that are possibly-open
Diffstat (limited to 'src/gpu')
-rw-r--r--src/gpu/GrShape.cpp8
-rw-r--r--src/gpu/GrShape.h20
-rw-r--r--src/gpu/GrStyle.cpp14
-rw-r--r--src/gpu/GrStyle.h19
4 files changed, 49 insertions, 12 deletions
diff --git a/src/gpu/GrShape.cpp b/src/gpu/GrShape.cpp
index 3b49f6ae7f..84e14e8925 100644
--- a/src/gpu/GrShape.cpp
+++ b/src/gpu/GrShape.cpp
@@ -103,7 +103,11 @@ void GrShape::setInheritedKey(const GrShape &parent, GrStyle::Apply apply) {
return;
}
}
- int styleCnt = GrStyle::KeySize(parent.fStyle, apply);
+ uint32_t styleKeyFlags = 0;
+ if (parent.knownToBeClosed()) {
+ styleKeyFlags |= GrStyle::kClosed_KeyFlag;
+ }
+ int styleCnt = GrStyle::KeySize(parent.fStyle, apply, styleKeyFlags);
if (styleCnt < 0) {
// The style doesn't allow a key, set the path to volatile so that we fail when
// we try to get a key for the shape.
@@ -120,7 +124,7 @@ void GrShape::setInheritedKey(const GrShape &parent, GrStyle::Apply apply) {
parentCnt * sizeof(uint32_t));
}
// Now turn (geo,path_effect) or (geo) into (geo,path_effect,stroke)
- GrStyle::WriteKey(fInheritedKey.get() + parentCnt, parent.fStyle, apply);
+ GrStyle::WriteKey(fInheritedKey.get() + parentCnt, parent.fStyle, apply, styleKeyFlags);
}
}
diff --git a/src/gpu/GrShape.h b/src/gpu/GrShape.h
index efc28cf737..f4bd7e581a 100644
--- a/src/gpu/GrShape.h
+++ b/src/gpu/GrShape.h
@@ -120,6 +120,9 @@ public:
void asPath(SkPath* out) const {
switch (fType) {
+ case Type::kEmpty:
+ out->reset();
+ break;
case Type::kRRect:
out->reset();
out->addRRect(fRRect);
@@ -127,10 +130,23 @@ public:
case Type::kPath:
*out = *fPath.get();
break;
+ }
+ }
+
+ /**
+ * Is it known that the shape has no unclosed contours. This means that it will not have
+ * any caps if stroked (modulo the effect of any path effect).
+ */
+ bool knownToBeClosed() const {
+ switch (fType) {
case Type::kEmpty:
- out->reset();
- break;
+ return true;
+ case Type::kRRect:
+ return true;
+ case Type::kPath:
+ return false;
}
+ return false;
}
/**
diff --git a/src/gpu/GrStyle.cpp b/src/gpu/GrStyle.cpp
index 7d70baa1bc..6480fb341a 100644
--- a/src/gpu/GrStyle.cpp
+++ b/src/gpu/GrStyle.cpp
@@ -7,7 +7,7 @@
#include "GrStyle.h"
-int GrStyle::KeySize(const GrStyle &style, Apply apply) {
+int GrStyle::KeySize(const GrStyle &style, Apply apply, uint32_t flags) {
GR_STATIC_ASSERT(sizeof(uint32_t) == sizeof(SkScalar));
int size = 0;
if (style.isDashed()) {
@@ -29,7 +29,7 @@ int GrStyle::KeySize(const GrStyle &style, Apply apply) {
return size;
}
-void GrStyle::WriteKey(uint32_t *key, const GrStyle &style, Apply apply) {
+void GrStyle::WriteKey(uint32_t *key, const GrStyle &style, Apply apply, uint32_t flags) {
SkASSERT(key);
SkASSERT(KeySize(style, apply) >= 0);
GR_STATIC_ASSERT(sizeof(uint32_t) == sizeof(SkScalar));
@@ -63,9 +63,17 @@ void GrStyle::WriteKey(uint32_t *key, const GrStyle &style, Apply apply) {
GR_STATIC_ASSERT(SkStrokeRec::kStyleCount <= (1 << kStyleBits));
GR_STATIC_ASSERT(SkPaint::kJoinCount <= (1 << kJoinBits));
GR_STATIC_ASSERT(SkPaint::kCapCount <= (1 << kCapBits));
+ // The cap type only matters for unclosed shapes. However, a path effect could unclose
+ // the shape before it is stroked.
+ SkPaint::Cap cap;
+ if ((flags & kClosed_KeyFlag) && !style.pathEffect()) {
+ cap = SkPaint::kButt_Cap;
+ } else {
+ cap = style.strokeRec().getCap();
+ }
key[i++] = style.strokeRec().getStyle() |
style.strokeRec().getJoin() << kJoinShift |
- style.strokeRec().getCap() << kCapShift;
+ cap << kCapShift;
SkScalar scalar;
// Miter limit only affects miter joins
diff --git a/src/gpu/GrStyle.h b/src/gpu/GrStyle.h
index d63df32290..c65b22b81a 100644
--- a/src/gpu/GrStyle.h
+++ b/src/gpu/GrStyle.h
@@ -49,21 +49,30 @@ public:
};
/**
+ * Optional flags for computing keys that may remove unnecessary variation in the key due to
+ * style settings that don't affect particular classes of geometry.
+ */
+ enum KeyFlags {
+ // The shape being styled has no open contours.
+ kClosed_KeyFlag = 0x1
+ };
+
+ /**
* Computes the key length for a GrStyle. The return will be negative if it cannot be turned
* into a key. This occurs when there is a path effect that is not a dash. The key can
* either reflect just the path effect (if one) or the path effect and the strokerec. Note
* that a simple fill has a zero sized key.
*/
- static int KeySize(const GrStyle& , Apply);
+ static int KeySize(const GrStyle& , Apply, uint32_t flags = 0);
/**
* Writes a unique key for the style into the provided buffer. This function assumes the buffer
* has room for at least KeySize() values. It assumes that KeySize() returns a non-negative
- * value for the style and Apply param. This is written so that the key for just dash
- * application followed by the key for the remaining SkStrokeRec is the same as the key for
- * applying dashing and SkStrokeRec all at once.
+ * value for the combination of GrStyle, Apply and flags params. This is written so that the key
+ * for just dash application followed by the key for the remaining SkStrokeRec is the same as
+ * the key for applying dashing and SkStrokeRec all at once.
*/
- static void WriteKey(uint32_t*, const GrStyle&, Apply);
+ static void WriteKey(uint32_t*, const GrStyle&, Apply, uint32_t flags = 0);
GrStyle() : GrStyle(SkStrokeRec::kFill_InitStyle) {}