bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "GrShape.h" |
| 9 | |
| 10 | GrShape& GrShape::operator=(const GrShape& that) { |
| 11 | bool wasPath = Type::kPath == fType; |
| 12 | fStyle = that.fStyle; |
| 13 | fType = that.fType; |
| 14 | switch (fType) { |
| 15 | case Type::kEmpty: |
| 16 | if (wasPath) { |
| 17 | fPath.reset(); |
| 18 | } |
| 19 | break; |
| 20 | case Type::kRRect: |
| 21 | if (wasPath) { |
| 22 | fPath.reset(); |
| 23 | } |
| 24 | fRRect = that.fRRect; |
bsalomon | ee29564 | 2016-06-06 14:01:25 -0700 | [diff] [blame] | 25 | fRRectDir = that.fRRectDir; |
| 26 | fRRectStart = that.fRRectStart; |
bsalomon | 7049396 | 2016-06-10 08:05:14 -0700 | [diff] [blame] | 27 | fRRectIsInverted = that.fRRectIsInverted; |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 28 | break; |
| 29 | case Type::kPath: |
| 30 | if (wasPath) { |
| 31 | *fPath.get() = *that.fPath.get(); |
| 32 | } else { |
| 33 | fPath.set(*that.fPath.get()); |
| 34 | } |
bsalomon | 93f66bc | 2016-06-21 08:35:49 -0700 | [diff] [blame^] | 35 | fPathGenID = that.fPathGenID; |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 36 | break; |
| 37 | } |
| 38 | fInheritedKey.reset(that.fInheritedKey.count()); |
benjaminwagner | d9cca4a | 2016-05-04 11:06:19 -0700 | [diff] [blame] | 39 | sk_careful_memcpy(fInheritedKey.get(), that.fInheritedKey.get(), |
| 40 | sizeof(uint32_t) * fInheritedKey.count()); |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 41 | return *this; |
| 42 | } |
| 43 | |
bsalomon | 9fb4203 | 2016-05-13 09:23:38 -0700 | [diff] [blame] | 44 | const SkRect& GrShape::bounds() const { |
| 45 | static constexpr SkRect kEmpty = SkRect::MakeEmpty(); |
| 46 | switch (fType) { |
| 47 | case Type::kEmpty: |
| 48 | return kEmpty; |
| 49 | case Type::kRRect: |
| 50 | return fRRect.getBounds(); |
| 51 | case Type::kPath: |
| 52 | return fPath.get()->getBounds(); |
| 53 | } |
| 54 | SkFAIL("Unknown shape type"); |
| 55 | return kEmpty; |
| 56 | } |
| 57 | |
| 58 | void GrShape::styledBounds(SkRect* bounds) const { |
| 59 | if (Type::kEmpty == fType && !fStyle.hasNonDashPathEffect()) { |
| 60 | *bounds = SkRect::MakeEmpty(); |
| 61 | } else { |
| 62 | fStyle.adjustBounds(bounds, this->bounds()); |
| 63 | } |
| 64 | } |
| 65 | |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 66 | int GrShape::unstyledKeySize() const { |
| 67 | if (fInheritedKey.count()) { |
| 68 | return fInheritedKey.count(); |
| 69 | } |
| 70 | switch (fType) { |
| 71 | case Type::kEmpty: |
| 72 | return 1; |
| 73 | case Type::kRRect: |
| 74 | SkASSERT(!fInheritedKey.count()); |
| 75 | SkASSERT(0 == SkRRect::kSizeInMemory % sizeof(uint32_t)); |
bsalomon | 7049396 | 2016-06-10 08:05:14 -0700 | [diff] [blame] | 76 | // + 1 for the direction, start index, and inverseness. |
bsalomon | ee29564 | 2016-06-06 14:01:25 -0700 | [diff] [blame] | 77 | return SkRRect::kSizeInMemory / sizeof(uint32_t) + 1; |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 78 | case Type::kPath: |
bsalomon | 93f66bc | 2016-06-21 08:35:49 -0700 | [diff] [blame^] | 79 | if (0 == fPathGenID) { |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 80 | return -1; |
| 81 | } else { |
bsalomon | 7049396 | 2016-06-10 08:05:14 -0700 | [diff] [blame] | 82 | // The key is the path ID and fill type. |
| 83 | return 2; |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 84 | } |
| 85 | } |
| 86 | SkFAIL("Should never get here."); |
| 87 | return 0; |
| 88 | } |
| 89 | |
| 90 | void GrShape::writeUnstyledKey(uint32_t* key) const { |
| 91 | SkASSERT(this->unstyledKeySize()); |
| 92 | SkDEBUGCODE(uint32_t* origKey = key;) |
| 93 | if (fInheritedKey.count()) { |
| 94 | memcpy(key, fInheritedKey.get(), sizeof(uint32_t) * fInheritedKey.count()); |
| 95 | SkDEBUGCODE(key += fInheritedKey.count();) |
| 96 | } else { |
| 97 | switch (fType) { |
| 98 | case Type::kEmpty: |
| 99 | *key++ = 1; |
| 100 | break; |
| 101 | case Type::kRRect: |
| 102 | fRRect.writeToMemory(key); |
| 103 | key += SkRRect::kSizeInMemory / sizeof(uint32_t); |
bsalomon | ee29564 | 2016-06-06 14:01:25 -0700 | [diff] [blame] | 104 | *key = (fRRectDir == SkPath::kCCW_Direction) ? (1 << 31) : 0; |
bsalomon | 7049396 | 2016-06-10 08:05:14 -0700 | [diff] [blame] | 105 | *key |= fRRectIsInverted ? (1 << 30) : 0; |
bsalomon | ee29564 | 2016-06-06 14:01:25 -0700 | [diff] [blame] | 106 | *key++ |= fRRectStart; |
| 107 | SkASSERT(fRRectStart < 8); |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 108 | break; |
| 109 | case Type::kPath: |
bsalomon | 93f66bc | 2016-06-21 08:35:49 -0700 | [diff] [blame^] | 110 | SkASSERT(fPathGenID); |
| 111 | *key++ = fPathGenID; |
bsalomon | 7049396 | 2016-06-10 08:05:14 -0700 | [diff] [blame] | 112 | // We could canonicalize the fill rule for paths that don't differentiate between |
| 113 | // even/odd or winding fill (e.g. convex). |
| 114 | *key++ = fPath.get()->getFillType(); |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 115 | break; |
| 116 | } |
| 117 | } |
| 118 | SkASSERT(key - origKey == this->unstyledKeySize()); |
| 119 | } |
| 120 | |
bsalomon | 97fd2d4 | 2016-05-09 13:02:01 -0700 | [diff] [blame] | 121 | void GrShape::setInheritedKey(const GrShape &parent, GrStyle::Apply apply, SkScalar scale) { |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 122 | SkASSERT(!fInheritedKey.count()); |
| 123 | // If the output shape turns out to be simple, then we will just use its geometric key |
| 124 | if (Type::kPath == fType) { |
| 125 | // We want ApplyFullStyle(ApplyPathEffect(shape)) to have the same key as |
| 126 | // ApplyFullStyle(shape). |
| 127 | // The full key is structured as (geo,path_effect,stroke). |
| 128 | // If we do ApplyPathEffect we get get,path_effect as the inherited key. If we then |
| 129 | // do ApplyFullStyle we'll memcpy geo,path_effect into the new inherited key |
| 130 | // and then append the style key (which should now be stroke only) at the end. |
| 131 | int parentCnt = parent.fInheritedKey.count(); |
| 132 | bool useParentGeoKey = !parentCnt; |
| 133 | if (useParentGeoKey) { |
| 134 | parentCnt = parent.unstyledKeySize(); |
bsalomon | 72dc51c | 2016-04-27 06:46:23 -0700 | [diff] [blame] | 135 | if (parentCnt < 0) { |
| 136 | // The parent's geometry has no key so we will have no key. |
bsalomon | 93f66bc | 2016-06-21 08:35:49 -0700 | [diff] [blame^] | 137 | fPathGenID = 0; |
bsalomon | 72dc51c | 2016-04-27 06:46:23 -0700 | [diff] [blame] | 138 | return; |
| 139 | } |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 140 | } |
bsalomon | 0607756 | 2016-05-04 13:50:29 -0700 | [diff] [blame] | 141 | uint32_t styleKeyFlags = 0; |
| 142 | if (parent.knownToBeClosed()) { |
| 143 | styleKeyFlags |= GrStyle::kClosed_KeyFlag; |
| 144 | } |
| 145 | int styleCnt = GrStyle::KeySize(parent.fStyle, apply, styleKeyFlags); |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 146 | if (styleCnt < 0) { |
bsalomon | 93f66bc | 2016-06-21 08:35:49 -0700 | [diff] [blame^] | 147 | // The style doesn't allow a key, set the path gen ID to 0 so that we fail when |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 148 | // we try to get a key for the shape. |
bsalomon | 93f66bc | 2016-06-21 08:35:49 -0700 | [diff] [blame^] | 149 | fPathGenID = 0; |
bsalomon | 72dc51c | 2016-04-27 06:46:23 -0700 | [diff] [blame] | 150 | return; |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 151 | } |
bsalomon | 72dc51c | 2016-04-27 06:46:23 -0700 | [diff] [blame] | 152 | fInheritedKey.reset(parentCnt + styleCnt); |
| 153 | if (useParentGeoKey) { |
| 154 | // This will be the geo key. |
| 155 | parent.writeUnstyledKey(fInheritedKey.get()); |
| 156 | } else { |
| 157 | // This should be (geo,path_effect). |
| 158 | memcpy(fInheritedKey.get(), parent.fInheritedKey.get(), |
| 159 | parentCnt * sizeof(uint32_t)); |
| 160 | } |
| 161 | // Now turn (geo,path_effect) or (geo) into (geo,path_effect,stroke) |
bsalomon | 97fd2d4 | 2016-05-09 13:02:01 -0700 | [diff] [blame] | 162 | GrStyle::WriteKey(fInheritedKey.get() + parentCnt, parent.fStyle, apply, scale, |
| 163 | styleKeyFlags); |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 164 | } |
| 165 | } |
| 166 | |
| 167 | GrShape::GrShape(const GrShape& that) : fType(that.fType), fStyle(that.fStyle) { |
| 168 | switch (fType) { |
| 169 | case Type::kEmpty: |
bsalomon | 93f66bc | 2016-06-21 08:35:49 -0700 | [diff] [blame^] | 170 | break; |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 171 | case Type::kRRect: |
| 172 | fRRect = that.fRRect; |
bsalomon | 7049396 | 2016-06-10 08:05:14 -0700 | [diff] [blame] | 173 | fRRectDir = that.fRRectDir; |
| 174 | fRRectStart = that.fRRectStart; |
| 175 | fRRectIsInverted = that.fRRectIsInverted; |
bsalomon | 93f66bc | 2016-06-21 08:35:49 -0700 | [diff] [blame^] | 176 | break; |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 177 | case Type::kPath: |
| 178 | fPath.set(*that.fPath.get()); |
bsalomon | 93f66bc | 2016-06-21 08:35:49 -0700 | [diff] [blame^] | 179 | fPathGenID = that.fPathGenID; |
| 180 | break; |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 181 | } |
| 182 | fInheritedKey.reset(that.fInheritedKey.count()); |
bsalomon | 93f66bc | 2016-06-21 08:35:49 -0700 | [diff] [blame^] | 183 | sk_careful_memcpy(fInheritedKey.get(), that.fInheritedKey.get(), |
| 184 | sizeof(uint32_t) * fInheritedKey.count()); |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 185 | } |
| 186 | |
bsalomon | 97fd2d4 | 2016-05-09 13:02:01 -0700 | [diff] [blame] | 187 | GrShape::GrShape(const GrShape& parent, GrStyle::Apply apply, SkScalar scale) { |
| 188 | // TODO: Add some quantization of scale for better cache performance here or leave that up |
| 189 | // to caller? |
| 190 | // TODO: For certain shapes and stroke params we could ignore the scale. (e.g. miter or bevel |
| 191 | // stroke of a rect). |
bsalomon | fb08327 | 2016-05-04 08:27:41 -0700 | [diff] [blame] | 192 | if (!parent.style().applies() || |
| 193 | (GrStyle::Apply::kPathEffectOnly == apply && !parent.style().pathEffect())) { |
| 194 | fType = Type::kEmpty; |
| 195 | *this = parent; |
| 196 | return; |
| 197 | } |
| 198 | |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 199 | SkPathEffect* pe = parent.fStyle.pathEffect(); |
bsalomon | fb08327 | 2016-05-04 08:27:41 -0700 | [diff] [blame] | 200 | SkTLazy<SkPath> tmpPath; |
| 201 | const GrShape* parentForKey = &parent; |
| 202 | SkTLazy<GrShape> tmpParent; |
| 203 | fType = Type::kPath; |
| 204 | fPath.init(); |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 205 | if (pe) { |
bsalomon | fb08327 | 2016-05-04 08:27:41 -0700 | [diff] [blame] | 206 | SkPath* srcForPathEffect; |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 207 | if (parent.fType == Type::kPath) { |
bsalomon | fb08327 | 2016-05-04 08:27:41 -0700 | [diff] [blame] | 208 | srcForPathEffect = parent.fPath.get(); |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 209 | } else { |
bsalomon | fb08327 | 2016-05-04 08:27:41 -0700 | [diff] [blame] | 210 | srcForPathEffect = tmpPath.init(); |
| 211 | parent.asPath(tmpPath.get()); |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 212 | } |
| 213 | // Should we consider bounds? Would have to include in key, but it'd be nice to know |
| 214 | // if the bounds actually modified anything before including in key. |
bsalomon | fb08327 | 2016-05-04 08:27:41 -0700 | [diff] [blame] | 215 | SkStrokeRec strokeRec = parent.fStyle.strokeRec(); |
bsalomon | 398e3f4 | 2016-06-13 10:22:48 -0700 | [diff] [blame] | 216 | if (!parent.fStyle.applyPathEffectToPath(fPath.get(), &strokeRec, *srcForPathEffect, |
| 217 | scale)) { |
bsalomon | d672384 | 2016-06-07 12:20:15 -0700 | [diff] [blame] | 218 | // If the path effect fails then we continue as though there was no path effect. |
| 219 | // If the original was a rrect that we couldn't canonicalize because of the path |
| 220 | // effect, then do so now. |
| 221 | if (parent.fType == Type::kRRect && (parent.fRRectDir != kDefaultRRectDir || |
| 222 | parent.fRRectStart != kDefaultRRectStart)) { |
| 223 | SkASSERT(srcForPathEffect == tmpPath.get()); |
| 224 | tmpPath.get()->reset(); |
| 225 | tmpPath.get()->addRRect(parent.fRRect, kDefaultRRectDir, kDefaultRRectDir); |
| 226 | } |
| 227 | *fPath.get() = *srcForPathEffect; |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 228 | } |
bsalomon | 97fd2d4 | 2016-05-09 13:02:01 -0700 | [diff] [blame] | 229 | // A path effect has access to change the res scale but we aren't expecting it to and it |
| 230 | // would mess up our key computation. |
| 231 | SkASSERT(scale == strokeRec.getResScale()); |
bsalomon | 1b28c1a | 2016-06-20 12:28:17 -0700 | [diff] [blame] | 232 | if (GrStyle::Apply::kPathEffectAndStrokeRec == apply && strokeRec.needToApply()) { |
| 233 | // The intermediate shape may not be a general path. If we we're just applying |
| 234 | // the path effect then attemptToReduceFromPath would catch it. This means that |
| 235 | // when we subsequently applied the remaining strokeRec we would have a non-path |
| 236 | // parent shape that would be used to determine the the stroked path's key. |
| 237 | // We detect that case here and change parentForKey to a temporary that represents |
| 238 | // the simpler shape so that applying both path effect and the strokerec all at |
| 239 | // once produces the same key. |
| 240 | tmpParent.init(*fPath.get(), GrStyle(strokeRec, nullptr)); |
| 241 | tmpParent.get()->setInheritedKey(parent, GrStyle::Apply::kPathEffectOnly, scale); |
| 242 | if (!tmpPath.isValid()) { |
| 243 | tmpPath.init(); |
bsalomon | 72dc51c | 2016-04-27 06:46:23 -0700 | [diff] [blame] | 244 | } |
bsalomon | 1b28c1a | 2016-06-20 12:28:17 -0700 | [diff] [blame] | 245 | tmpParent.get()->asPath(tmpPath.get()); |
| 246 | SkStrokeRec::InitStyle fillOrHairline; |
| 247 | SkAssertResult(tmpParent.get()->style().applyToPath(fPath.get(), &fillOrHairline, |
| 248 | *tmpPath.get(), scale)); |
| 249 | fStyle.resetToInitStyle(fillOrHairline); |
| 250 | parentForKey = tmpParent.get(); |
bsalomon | fb08327 | 2016-05-04 08:27:41 -0700 | [diff] [blame] | 251 | } else { |
| 252 | fStyle = GrStyle(strokeRec, nullptr); |
bsalomon | 72dc51c | 2016-04-27 06:46:23 -0700 | [diff] [blame] | 253 | } |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 254 | } else { |
bsalomon | 97fd2d4 | 2016-05-09 13:02:01 -0700 | [diff] [blame] | 255 | const SkPath* srcForParentStyle; |
bsalomon | fb08327 | 2016-05-04 08:27:41 -0700 | [diff] [blame] | 256 | if (parent.fType == Type::kPath) { |
bsalomon | 97fd2d4 | 2016-05-09 13:02:01 -0700 | [diff] [blame] | 257 | srcForParentStyle = parent.fPath.get(); |
bsalomon | fb08327 | 2016-05-04 08:27:41 -0700 | [diff] [blame] | 258 | } else { |
bsalomon | 97fd2d4 | 2016-05-09 13:02:01 -0700 | [diff] [blame] | 259 | srcForParentStyle = tmpPath.init(); |
bsalomon | fb08327 | 2016-05-04 08:27:41 -0700 | [diff] [blame] | 260 | parent.asPath(tmpPath.get()); |
| 261 | } |
bsalomon | 97fd2d4 | 2016-05-09 13:02:01 -0700 | [diff] [blame] | 262 | SkStrokeRec::InitStyle fillOrHairline; |
| 263 | SkASSERT(parent.fStyle.applies()); |
| 264 | SkASSERT(!parent.fStyle.pathEffect()); |
| 265 | SkAssertResult(parent.fStyle.applyToPath(fPath.get(), &fillOrHairline, *srcForParentStyle, |
| 266 | scale)); |
| 267 | fStyle.resetToInitStyle(fillOrHairline); |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 268 | } |
bsalomon | 1b28c1a | 2016-06-20 12:28:17 -0700 | [diff] [blame] | 269 | this->attemptToSimplifyPath(); |
bsalomon | 97fd2d4 | 2016-05-09 13:02:01 -0700 | [diff] [blame] | 270 | this->setInheritedKey(*parentForKey, apply, scale); |
bsalomon | 47cc769 | 2016-04-26 12:56:00 -0700 | [diff] [blame] | 271 | } |
bsalomon | ee29564 | 2016-06-06 14:01:25 -0700 | [diff] [blame] | 272 | |
bsalomon | 1b28c1a | 2016-06-20 12:28:17 -0700 | [diff] [blame] | 273 | void GrShape::attemptToSimplifyPath() { |
| 274 | SkASSERT(Type::kPath == fType); |
bsalomon | ee29564 | 2016-06-06 14:01:25 -0700 | [diff] [blame] | 275 | SkRect rect; |
bsalomon | 1b28c1a | 2016-06-20 12:28:17 -0700 | [diff] [blame] | 276 | if (fPath.get()->isEmpty()) { |
| 277 | fType = Type::kEmpty; |
| 278 | } else if (fPath.get()->isRRect(&fRRect, &fRRectDir, &fRRectStart)) { |
| 279 | // Currently SkPath does not acknowledge that empty, rect, or oval subtypes as rrects. |
| 280 | SkASSERT(!fRRect.isEmpty()); |
| 281 | SkASSERT(fRRect.getType() != SkRRect::kRect_Type); |
| 282 | SkASSERT(fRRect.getType() != SkRRect::kOval_Type); |
| 283 | fRRectIsInverted = fPath.get()->isInverseFillType(); |
| 284 | fType = Type::kRRect; |
| 285 | } else if (fPath.get()->isOval(&rect, &fRRectDir, &fRRectStart)) { |
| 286 | fRRect.setOval(rect); |
| 287 | fRRectIsInverted = fPath.get()->isInverseFillType(); |
| 288 | // convert from oval indexing to rrect indexiing. |
| 289 | fRRectStart *= 2; |
| 290 | fType = Type::kRRect; |
| 291 | } else if (SkPathPriv::IsSimpleClosedRect(*fPath.get(), &rect, &fRRectDir, &fRRectStart)) { |
| 292 | // When there is a path effect we restrict rect detection to the narrower API that |
| 293 | // gives us the starting position. Otherwise, we will retry with the more aggressive |
| 294 | // isRect(). |
| 295 | fRRect.setRect(rect); |
| 296 | fRRectIsInverted = fPath.get()->isInverseFillType(); |
| 297 | // convert from rect indexing to rrect indexiing. |
| 298 | fRRectStart *= 2; |
| 299 | fType = Type::kRRect; |
| 300 | } else if (!this->style().hasPathEffect()) { |
bsalomon | ee29564 | 2016-06-06 14:01:25 -0700 | [diff] [blame] | 301 | bool closed; |
bsalomon | 1b28c1a | 2016-06-20 12:28:17 -0700 | [diff] [blame] | 302 | if (fPath.get()->isRect(&rect, &closed, nullptr)) { |
| 303 | if (closed || this->style().isSimpleFill()) { |
| 304 | fRRect.setRect(rect); |
bsalomon | ee29564 | 2016-06-06 14:01:25 -0700 | [diff] [blame] | 305 | // Since there is no path effect the dir and start index is immaterial. |
bsalomon | 1b28c1a | 2016-06-20 12:28:17 -0700 | [diff] [blame] | 306 | fRRectDir = kDefaultRRectDir; |
| 307 | fRRectStart = kDefaultRRectStart; |
| 308 | // There isn't dashing so we will have to preserver inverseness. |
| 309 | fRRectIsInverted = fPath.get()->isInverseFillType(); |
| 310 | fType = Type::kRRect; |
bsalomon | ee29564 | 2016-06-06 14:01:25 -0700 | [diff] [blame] | 311 | } |
| 312 | } |
| 313 | } |
bsalomon | 1b28c1a | 2016-06-20 12:28:17 -0700 | [diff] [blame] | 314 | if (Type::kPath != fType) { |
| 315 | fPath.reset(); |
| 316 | fInheritedKey.reset(0); |
| 317 | if (Type::kRRect == fType) { |
| 318 | this->attemptToSimplifyRRect(); |
| 319 | } |
bsalomon | 93f66bc | 2016-06-21 08:35:49 -0700 | [diff] [blame^] | 320 | } else { |
| 321 | if (fInheritedKey.count() || fPath.get()->isVolatile()) { |
| 322 | fPathGenID = 0; |
| 323 | } else { |
| 324 | fPathGenID = fPath.get()->getGenerationID(); |
| 325 | } |
| 326 | if (this->style().isSimpleFill()) { |
| 327 | // Filled paths are treated as though all their contours were closed. |
| 328 | // Since SkPath doesn't track individual contours, this will only close the last. :( |
| 329 | // There is no point in closing lines, though, since they loose their line-ness. |
| 330 | if (!fPath.get()->isLine(nullptr)) { |
| 331 | fPath.get()->close(); |
| 332 | fPath.get()->setIsVolatile(true); |
| 333 | } |
| 334 | } |
| 335 | if (fPath.get()->isConvex()) { |
| 336 | // There is no distinction between even/odd and non-zero winding count for convex |
| 337 | // paths. |
| 338 | if (fPath.get()->isInverseFillType()) { |
| 339 | fPath.get()->setFillType(SkPath::kInverseEvenOdd_FillType); |
| 340 | } else { |
| 341 | fPath.get()->setFillType(SkPath::kEvenOdd_FillType); |
| 342 | } |
| 343 | } |
| 344 | if (this->style().isDashed()) { |
| 345 | // Dashing ignores inverseness (skbug.com/5421) |
| 346 | switch (fPath.get()->getFillType()) { |
| 347 | case SkPath::kWinding_FillType: |
| 348 | case SkPath::kEvenOdd_FillType: |
| 349 | break; |
| 350 | case SkPath::kInverseWinding_FillType: |
| 351 | fPath.get()->setFillType(SkPath::kWinding_FillType); |
| 352 | break; |
| 353 | case SkPath::kInverseEvenOdd_FillType: |
| 354 | fPath.get()->setFillType(SkPath::kEvenOdd_FillType); |
| 355 | break; |
| 356 | } |
| 357 | } |
bsalomon | 1b28c1a | 2016-06-20 12:28:17 -0700 | [diff] [blame] | 358 | } |
| 359 | } |
| 360 | |
| 361 | void GrShape::attemptToSimplifyRRect() { |
| 362 | SkASSERT(Type::kRRect == fType); |
| 363 | SkASSERT(!fInheritedKey.count()); |
| 364 | if (fRRect.isEmpty()) { |
| 365 | fType = Type::kEmpty; |
| 366 | return; |
| 367 | } |
| 368 | if (!this->style().hasPathEffect()) { |
| 369 | fRRectDir = kDefaultRRectDir; |
| 370 | fRRectStart = kDefaultRRectStart; |
| 371 | } else if (fStyle.isDashed()) { |
| 372 | // Dashing ignores the inverseness (currently). skbug.com/5421 |
| 373 | fRRectIsInverted = false; |
| 374 | } |
bsalomon | ee29564 | 2016-06-06 14:01:25 -0700 | [diff] [blame] | 375 | } |