aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/GrStyle.cpp
diff options
context:
space:
mode:
authorGravatar bsalomon <bsalomon@google.com>2016-05-09 13:02:01 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-05-09 13:02:01 -0700
commit97fd2d42b97104fa32a58d7e7a5b7255913f9c9d (patch)
treef1984297182430bf5b706e6514d21c20b37d4db7 /src/gpu/GrStyle.cpp
parent1b4c01c66081cd163535eab21b29a3996b01a6cf (diff)
Incorporate scale into GrStyle and GrShape
Diffstat (limited to 'src/gpu/GrStyle.cpp')
-rw-r--r--src/gpu/GrStyle.cpp26
1 files changed, 19 insertions, 7 deletions
diff --git a/src/gpu/GrStyle.cpp b/src/gpu/GrStyle.cpp
index 68238dded9..3698c31ff8 100644
--- a/src/gpu/GrStyle.cpp
+++ b/src/gpu/GrStyle.cpp
@@ -11,8 +11,8 @@ 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()) {
- // One scalar for dash phase and one for each dash value.
- size += 1 + style.dashIntervalCnt();
+ // One scalar for scale, one for dash phase, and one for each dash value.
+ size += 2 + style.dashIntervalCnt();
} else if (style.pathEffect()) {
// No key for a generic path effect.
return -1;
@@ -23,21 +23,29 @@ int GrStyle::KeySize(const GrStyle &style, Apply apply, uint32_t flags) {
}
if (style.strokeRec().needToApply()) {
- // One for style/cap/join, 2 for miter and width.
- size += 3;
+ // One for res scale, one for style/cap/join, one for miter limit, and one for width.
+ size += 4;
}
return size;
}
-void GrStyle::WriteKey(uint32_t *key, const GrStyle &style, Apply apply, uint32_t flags) {
+void GrStyle::WriteKey(uint32_t *key, const GrStyle &style, Apply apply, SkScalar scale,
+ uint32_t flags) {
SkASSERT(key);
SkASSERT(KeySize(style, apply) >= 0);
GR_STATIC_ASSERT(sizeof(uint32_t) == sizeof(SkScalar));
int i = 0;
+ // The scale can influence both the path effect and stroking. We want to preserve the
+ // property that the following two are equal:
+ // 1. WriteKey with apply == kPathEffectAndStrokeRec
+ // 2. WriteKey with apply == kPathEffectOnly followed by WriteKey of a GrStyle made
+ // from SkStrokeRec output by the the path effect (and no additional path effect).
+ // Since the scale can affect both parts of 2 we write it into the key twice.
if (style.isDashed()) {
GR_STATIC_ASSERT(sizeof(style.dashPhase()) == sizeof(uint32_t));
SkScalar phase = style.dashPhase();
+ memcpy(&key[i++], &scale, sizeof(SkScalar));
memcpy(&key[i++], &phase, sizeof(SkScalar));
int32_t count = style.dashIntervalCnt();
@@ -52,6 +60,7 @@ void GrStyle::WriteKey(uint32_t *key, const GrStyle &style, Apply apply, uint32_
}
if (Apply::kPathEffectAndStrokeRec == apply && style.strokeRec().needToApply()) {
+ memcpy(&key[i++], &scale, sizeof(SkScalar));
enum {
kStyleBits = 2,
kJoinBits = 2,
@@ -123,9 +132,10 @@ static inline bool apply_path_effect(SkPath* dst, SkStrokeRec* strokeRec,
}
bool GrStyle::applyPathEffectToPath(SkPath *dst, SkStrokeRec *remainingStroke,
- const SkPath &src) const {
+ const SkPath &src, SkScalar resScale) const {
SkASSERT(dst);
SkStrokeRec strokeRec = fStrokeRec;
+ strokeRec.setResScale(resScale);
if (!apply_path_effect(dst, &strokeRec, fPathEffect, src)) {
return false;
}
@@ -133,10 +143,12 @@ bool GrStyle::applyPathEffectToPath(SkPath *dst, SkStrokeRec *remainingStroke,
return true;
}
-bool GrStyle::applyToPath(SkPath* dst, SkStrokeRec::InitStyle* style, const SkPath& src) const {
+bool GrStyle::applyToPath(SkPath* dst, SkStrokeRec::InitStyle* style, const SkPath& src,
+ SkScalar resScale) const {
SkASSERT(style);
SkASSERT(dst);
SkStrokeRec strokeRec = fStrokeRec;
+ strokeRec.setResScale(resScale);
const SkPath* pathForStrokeRec = &src;
if (apply_path_effect(dst, &strokeRec, fPathEffect, src)) {
pathForStrokeRec = dst;