robertphillips@google.com | ca0c838 | 2013-09-26 12:18:23 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 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 "SkBuffer.h" |
commit-bot@chromium.org | 1f81fd6 | 2013-10-23 14:44:08 +0000 | [diff] [blame] | 9 | #include "SkOnce.h" |
robertphillips@google.com | ca0c838 | 2013-09-26 12:18:23 +0000 | [diff] [blame] | 10 | #include "SkPath.h" |
| 11 | #include "SkPathRef.h" |
| 12 | |
| 13 | SK_DEFINE_INST_COUNT(SkPathRef); |
| 14 | |
robertphillips@google.com | 3e292aa | 2013-09-27 17:48:49 +0000 | [diff] [blame] | 15 | ////////////////////////////////////////////////////////////////////////////// |
| 16 | SkPathRef::Editor::Editor(SkAutoTUnref<SkPathRef>* pathRef, |
| 17 | int incReserveVerbs, |
| 18 | int incReservePoints) |
| 19 | { |
| 20 | if ((*pathRef)->unique()) { |
| 21 | (*pathRef)->incReserve(incReserveVerbs, incReservePoints); |
| 22 | } else { |
| 23 | SkPathRef* copy = SkNEW(SkPathRef); |
| 24 | copy->copy(**pathRef, incReserveVerbs, incReservePoints); |
| 25 | pathRef->reset(copy); |
| 26 | } |
| 27 | fPathRef = *pathRef; |
| 28 | fPathRef->fGenerationID = 0; |
robertphillips@google.com | 466310d | 2013-12-03 16:43:54 +0000 | [diff] [blame^] | 29 | fPathRef->fIsOval = false; |
robertphillips@google.com | 3e292aa | 2013-09-27 17:48:49 +0000 | [diff] [blame] | 30 | SkDEBUGCODE(sk_atomic_inc(&fPathRef->fEditorsAttached);) |
robertphillips@google.com | ca0c838 | 2013-09-26 12:18:23 +0000 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | SkPoint* SkPathRef::Editor::growForConic(SkScalar w) { |
robertphillips@google.com | 0308707 | 2013-10-02 16:42:21 +0000 | [diff] [blame] | 34 | SkDEBUGCODE(fPathRef->validate();) |
robertphillips@google.com | ca0c838 | 2013-09-26 12:18:23 +0000 | [diff] [blame] | 35 | SkPoint* pts = fPathRef->growForVerb(SkPath::kConic_Verb); |
| 36 | *fPathRef->fConicWeights.append() = w; |
| 37 | return pts; |
| 38 | } |
| 39 | |
robertphillips@google.com | 3e292aa | 2013-09-27 17:48:49 +0000 | [diff] [blame] | 40 | ////////////////////////////////////////////////////////////////////////////// |
commit-bot@chromium.org | 1f81fd6 | 2013-10-23 14:44:08 +0000 | [diff] [blame] | 41 | void SkPathRef::CreateEmptyImpl(SkPathRef** empty) { |
| 42 | *empty = SkNEW(SkPathRef); |
| 43 | (*empty)->computeBounds(); // Preemptively avoid a race to clear fBoundsIsDirty. |
| 44 | } |
| 45 | |
| 46 | SkPathRef* SkPathRef::CreateEmpty() { |
| 47 | static SkPathRef* gEmptyPathRef; |
| 48 | SK_DECLARE_STATIC_ONCE(once); |
| 49 | SkOnce(&once, SkPathRef::CreateEmptyImpl, &gEmptyPathRef); |
| 50 | return SkRef(gEmptyPathRef); |
| 51 | } |
| 52 | |
robertphillips@google.com | 3e292aa | 2013-09-27 17:48:49 +0000 | [diff] [blame] | 53 | void SkPathRef::CreateTransformedCopy(SkAutoTUnref<SkPathRef>* dst, |
| 54 | const SkPathRef& src, |
| 55 | const SkMatrix& matrix) { |
robertphillips@google.com | 0308707 | 2013-10-02 16:42:21 +0000 | [diff] [blame] | 56 | SkDEBUGCODE(src.validate();) |
robertphillips@google.com | 3e292aa | 2013-09-27 17:48:49 +0000 | [diff] [blame] | 57 | if (matrix.isIdentity()) { |
| 58 | if (*dst != &src) { |
| 59 | src.ref(); |
| 60 | dst->reset(const_cast<SkPathRef*>(&src)); |
robertphillips@google.com | 0308707 | 2013-10-02 16:42:21 +0000 | [diff] [blame] | 61 | SkDEBUGCODE((*dst)->validate();) |
robertphillips@google.com | 3e292aa | 2013-09-27 17:48:49 +0000 | [diff] [blame] | 62 | } |
| 63 | return; |
| 64 | } |
| 65 | |
| 66 | bool dstUnique = (*dst)->unique(); |
| 67 | if (!dstUnique) { |
| 68 | dst->reset(SkNEW(SkPathRef)); |
| 69 | (*dst)->resetToSize(src.fVerbCnt, src.fPointCnt, src.fConicWeights.count()); |
| 70 | memcpy((*dst)->verbsMemWritable(), src.verbsMemBegin(), src.fVerbCnt * sizeof(uint8_t)); |
| 71 | (*dst)->fConicWeights = src.fConicWeights; |
| 72 | } |
| 73 | |
| 74 | // Need to check this here in case (&src == dst) |
| 75 | bool canXformBounds = !src.fBoundsIsDirty && matrix.rectStaysRect() && src.countPoints() > 1; |
| 76 | |
| 77 | matrix.mapPoints((*dst)->fPoints, src.points(), src.fPointCnt); |
| 78 | |
| 79 | /* |
| 80 | * Here we optimize the bounds computation, by noting if the bounds are |
| 81 | * already known, and if so, we just transform those as well and mark |
| 82 | * them as "known", rather than force the transformed path to have to |
| 83 | * recompute them. |
| 84 | * |
| 85 | * Special gotchas if the path is effectively empty (<= 1 point) or |
| 86 | * if it is non-finite. In those cases bounds need to stay empty, |
| 87 | * regardless of the matrix. |
| 88 | */ |
| 89 | if (canXformBounds) { |
| 90 | (*dst)->fBoundsIsDirty = false; |
| 91 | if (src.fIsFinite) { |
| 92 | matrix.mapRect(&(*dst)->fBounds, src.fBounds); |
| 93 | if (!((*dst)->fIsFinite = (*dst)->fBounds.isFinite())) { |
| 94 | (*dst)->fBounds.setEmpty(); |
| 95 | } |
| 96 | } else { |
| 97 | (*dst)->fIsFinite = false; |
| 98 | (*dst)->fBounds.setEmpty(); |
| 99 | } |
| 100 | } else { |
| 101 | (*dst)->fBoundsIsDirty = true; |
| 102 | } |
| 103 | |
robertphillips@google.com | 466310d | 2013-12-03 16:43:54 +0000 | [diff] [blame^] | 104 | // It's an oval only if it stays a rect. |
| 105 | (*dst)->fIsOval = src.fIsOval && matrix.rectStaysRect(); |
| 106 | |
robertphillips@google.com | 0308707 | 2013-10-02 16:42:21 +0000 | [diff] [blame] | 107 | SkDEBUGCODE((*dst)->validate();) |
robertphillips@google.com | 3e292aa | 2013-09-27 17:48:49 +0000 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | SkPathRef* SkPathRef::CreateFromBuffer(SkRBuffer* buffer |
robertphillips@google.com | 466310d | 2013-12-03 16:43:54 +0000 | [diff] [blame^] | 111 | #ifndef DELETE_THIS_CODE_WHEN_SKPS_ARE_REBUILT_AT_V16_AND_ALL_OTHER_INSTANCES_TOO |
robertphillips@google.com | 3e292aa | 2013-09-27 17:48:49 +0000 | [diff] [blame] | 112 | , bool newFormat, int32_t oldPacked |
| 113 | #endif |
| 114 | ) { |
| 115 | SkPathRef* ref = SkNEW(SkPathRef); |
robertphillips@google.com | 466310d | 2013-12-03 16:43:54 +0000 | [diff] [blame^] | 116 | bool isOval; |
| 117 | |
| 118 | int32_t packed; |
| 119 | if (!buffer->readS32(&packed)) { |
| 120 | SkDELETE(ref); |
| 121 | return NULL; |
| 122 | } |
| 123 | |
| 124 | ref->fIsFinite = (packed >> kIsFinite_SerializationShift) & 1; |
| 125 | |
| 126 | #ifndef DELETE_THIS_CODE_WHEN_SKPS_ARE_REBUILT_AT_V16_AND_ALL_OTHER_INSTANCES_TOO |
robertphillips@google.com | 3e292aa | 2013-09-27 17:48:49 +0000 | [diff] [blame] | 127 | if (newFormat) { |
| 128 | #endif |
robertphillips@google.com | 466310d | 2013-12-03 16:43:54 +0000 | [diff] [blame^] | 129 | isOval = (packed >> kIsOval_SerializationShift) & 1; |
| 130 | #ifndef DELETE_THIS_CODE_WHEN_SKPS_ARE_REBUILT_AT_V16_AND_ALL_OTHER_INSTANCES_TOO |
robertphillips@google.com | 3e292aa | 2013-09-27 17:48:49 +0000 | [diff] [blame] | 131 | } else { |
robertphillips@google.com | 466310d | 2013-12-03 16:43:54 +0000 | [diff] [blame^] | 132 | isOval = (oldPacked >> SkPath::kOldIsOval_SerializationShift) & 1; |
robertphillips@google.com | 3e292aa | 2013-09-27 17:48:49 +0000 | [diff] [blame] | 133 | } |
| 134 | #endif |
| 135 | |
commit-bot@chromium.org | 8f457e3 | 2013-11-08 19:22:57 +0000 | [diff] [blame] | 136 | int32_t verbCount, pointCount, conicCount; |
| 137 | if (!buffer->readU32(&(ref->fGenerationID)) || |
| 138 | !buffer->readS32(&verbCount) || |
| 139 | !buffer->readS32(&pointCount) || |
| 140 | !buffer->readS32(&conicCount)) { |
| 141 | SkDELETE(ref); |
| 142 | return NULL; |
| 143 | } |
robertphillips@google.com | 3e292aa | 2013-09-27 17:48:49 +0000 | [diff] [blame] | 144 | |
commit-bot@chromium.org | 8f457e3 | 2013-11-08 19:22:57 +0000 | [diff] [blame] | 145 | ref->resetToSize(verbCount, pointCount, conicCount); |
robertphillips@google.com | 3e292aa | 2013-09-27 17:48:49 +0000 | [diff] [blame] | 146 | SkASSERT(verbCount == ref->countVerbs()); |
| 147 | SkASSERT(pointCount == ref->countPoints()); |
| 148 | SkASSERT(conicCount == ref->fConicWeights.count()); |
commit-bot@chromium.org | 8f457e3 | 2013-11-08 19:22:57 +0000 | [diff] [blame] | 149 | |
| 150 | if (!buffer->read(ref->verbsMemWritable(), verbCount * sizeof(uint8_t)) || |
| 151 | !buffer->read(ref->fPoints, pointCount * sizeof(SkPoint)) || |
| 152 | !buffer->read(ref->fConicWeights.begin(), conicCount * sizeof(SkScalar)) || |
| 153 | !buffer->read(&ref->fBounds, sizeof(SkRect))) { |
| 154 | SkDELETE(ref); |
| 155 | return NULL; |
| 156 | } |
robertphillips@google.com | 3e292aa | 2013-09-27 17:48:49 +0000 | [diff] [blame] | 157 | ref->fBoundsIsDirty = false; |
robertphillips@google.com | 466310d | 2013-12-03 16:43:54 +0000 | [diff] [blame^] | 158 | ref->fIsOval = isOval; |
robertphillips@google.com | 3e292aa | 2013-09-27 17:48:49 +0000 | [diff] [blame] | 159 | return ref; |
| 160 | } |
| 161 | |
| 162 | void SkPathRef::Rewind(SkAutoTUnref<SkPathRef>* pathRef) { |
| 163 | if ((*pathRef)->unique()) { |
robertphillips@google.com | 0308707 | 2013-10-02 16:42:21 +0000 | [diff] [blame] | 164 | SkDEBUGCODE((*pathRef)->validate();) |
robertphillips@google.com | 3e292aa | 2013-09-27 17:48:49 +0000 | [diff] [blame] | 165 | (*pathRef)->fBoundsIsDirty = true; // this also invalidates fIsFinite |
| 166 | (*pathRef)->fVerbCnt = 0; |
| 167 | (*pathRef)->fPointCnt = 0; |
| 168 | (*pathRef)->fFreeSpace = (*pathRef)->currSize(); |
| 169 | (*pathRef)->fGenerationID = 0; |
| 170 | (*pathRef)->fConicWeights.rewind(); |
robertphillips@google.com | 466310d | 2013-12-03 16:43:54 +0000 | [diff] [blame^] | 171 | (*pathRef)->fIsOval = false; |
robertphillips@google.com | 0308707 | 2013-10-02 16:42:21 +0000 | [diff] [blame] | 172 | SkDEBUGCODE((*pathRef)->validate();) |
robertphillips@google.com | 3e292aa | 2013-09-27 17:48:49 +0000 | [diff] [blame] | 173 | } else { |
| 174 | int oldVCnt = (*pathRef)->countVerbs(); |
| 175 | int oldPCnt = (*pathRef)->countPoints(); |
| 176 | pathRef->reset(SkNEW(SkPathRef)); |
| 177 | (*pathRef)->resetToSize(0, 0, 0, oldVCnt, oldPCnt); |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | bool SkPathRef::operator== (const SkPathRef& ref) const { |
robertphillips@google.com | 0308707 | 2013-10-02 16:42:21 +0000 | [diff] [blame] | 182 | SkDEBUGCODE(this->validate();) |
| 183 | SkDEBUGCODE(ref.validate();) |
robertphillips@google.com | 3e292aa | 2013-09-27 17:48:49 +0000 | [diff] [blame] | 184 | bool genIDMatch = fGenerationID && fGenerationID == ref.fGenerationID; |
| 185 | #ifdef SK_RELEASE |
| 186 | if (genIDMatch) { |
| 187 | return true; |
| 188 | } |
| 189 | #endif |
| 190 | if (fPointCnt != ref.fPointCnt || |
| 191 | fVerbCnt != ref.fVerbCnt) { |
| 192 | SkASSERT(!genIDMatch); |
| 193 | return false; |
| 194 | } |
| 195 | if (0 != memcmp(this->verbsMemBegin(), |
| 196 | ref.verbsMemBegin(), |
| 197 | ref.fVerbCnt * sizeof(uint8_t))) { |
| 198 | SkASSERT(!genIDMatch); |
| 199 | return false; |
| 200 | } |
| 201 | if (0 != memcmp(this->points(), |
| 202 | ref.points(), |
| 203 | ref.fPointCnt * sizeof(SkPoint))) { |
| 204 | SkASSERT(!genIDMatch); |
| 205 | return false; |
| 206 | } |
| 207 | if (fConicWeights != ref.fConicWeights) { |
| 208 | SkASSERT(!genIDMatch); |
| 209 | return false; |
| 210 | } |
| 211 | // We've done the work to determine that these are equal. If either has a zero genID, copy |
| 212 | // the other's. If both are 0 then genID() will compute the next ID. |
| 213 | if (0 == fGenerationID) { |
| 214 | fGenerationID = ref.genID(); |
| 215 | } else if (0 == ref.fGenerationID) { |
| 216 | ref.fGenerationID = this->genID(); |
| 217 | } |
| 218 | return true; |
| 219 | } |
| 220 | |
| 221 | void SkPathRef::writeToBuffer(SkWBuffer* buffer) { |
robertphillips@google.com | 0308707 | 2013-10-02 16:42:21 +0000 | [diff] [blame] | 222 | SkDEBUGCODE(this->validate();) |
robertphillips@google.com | 3e292aa | 2013-09-27 17:48:49 +0000 | [diff] [blame] | 223 | SkDEBUGCODE(size_t beforePos = buffer->pos();) |
| 224 | |
| 225 | // Call getBounds() to ensure (as a side-effect) that fBounds |
| 226 | // and fIsFinite are computed. |
| 227 | const SkRect& bounds = this->getBounds(); |
| 228 | |
robertphillips@google.com | 466310d | 2013-12-03 16:43:54 +0000 | [diff] [blame^] | 229 | int32_t packed = ((fIsFinite & 1) << kIsFinite_SerializationShift) | |
| 230 | ((fIsOval & 1) << kIsOval_SerializationShift); |
robertphillips@google.com | 3e292aa | 2013-09-27 17:48:49 +0000 | [diff] [blame] | 231 | buffer->write32(packed); |
| 232 | |
| 233 | // TODO: write gen ID here. Problem: We don't know if we're cross process or not from |
| 234 | // SkWBuffer. Until this is fixed we write 0. |
| 235 | buffer->write32(0); |
| 236 | buffer->write32(fVerbCnt); |
| 237 | buffer->write32(fPointCnt); |
| 238 | buffer->write32(fConicWeights.count()); |
| 239 | buffer->write(verbsMemBegin(), fVerbCnt * sizeof(uint8_t)); |
| 240 | buffer->write(fPoints, fPointCnt * sizeof(SkPoint)); |
| 241 | buffer->write(fConicWeights.begin(), fConicWeights.bytes()); |
| 242 | buffer->write(&bounds, sizeof(bounds)); |
| 243 | |
| 244 | SkASSERT(buffer->pos() - beforePos == (size_t) this->writeSize()); |
| 245 | } |
| 246 | |
| 247 | uint32_t SkPathRef::writeSize() { |
| 248 | return uint32_t(5 * sizeof(uint32_t) + |
| 249 | fVerbCnt * sizeof(uint8_t) + |
| 250 | fPointCnt * sizeof(SkPoint) + |
| 251 | fConicWeights.bytes() + |
| 252 | sizeof(SkRect)); |
| 253 | } |
| 254 | |
skia.committer@gmail.com | 50df4d0 | 2013-09-28 07:01:33 +0000 | [diff] [blame] | 255 | void SkPathRef::copy(const SkPathRef& ref, |
| 256 | int additionalReserveVerbs, |
robertphillips@google.com | 3e292aa | 2013-09-27 17:48:49 +0000 | [diff] [blame] | 257 | int additionalReservePoints) { |
robertphillips@google.com | 0308707 | 2013-10-02 16:42:21 +0000 | [diff] [blame] | 258 | SkDEBUGCODE(this->validate();) |
robertphillips@google.com | 3e292aa | 2013-09-27 17:48:49 +0000 | [diff] [blame] | 259 | this->resetToSize(ref.fVerbCnt, ref.fPointCnt, ref.fConicWeights.count(), |
| 260 | additionalReserveVerbs, additionalReservePoints); |
| 261 | memcpy(this->verbsMemWritable(), ref.verbsMemBegin(), ref.fVerbCnt * sizeof(uint8_t)); |
| 262 | memcpy(this->fPoints, ref.fPoints, ref.fPointCnt * sizeof(SkPoint)); |
| 263 | fConicWeights = ref.fConicWeights; |
| 264 | // We could call genID() here to force a real ID (instead of 0). However, if we're making |
| 265 | // a copy then presumably we intend to make a modification immediately afterwards. |
| 266 | fGenerationID = ref.fGenerationID; |
| 267 | fBoundsIsDirty = ref.fBoundsIsDirty; |
| 268 | if (!fBoundsIsDirty) { |
| 269 | fBounds = ref.fBounds; |
| 270 | fIsFinite = ref.fIsFinite; |
| 271 | } |
robertphillips@google.com | 466310d | 2013-12-03 16:43:54 +0000 | [diff] [blame^] | 272 | fIsOval = ref.fIsOval; |
robertphillips@google.com | 0308707 | 2013-10-02 16:42:21 +0000 | [diff] [blame] | 273 | SkDEBUGCODE(this->validate();) |
robertphillips@google.com | 3e292aa | 2013-09-27 17:48:49 +0000 | [diff] [blame] | 274 | } |
| 275 | |
robertphillips@google.com | ca0c838 | 2013-09-26 12:18:23 +0000 | [diff] [blame] | 276 | SkPoint* SkPathRef::growForVerb(int /* SkPath::Verb*/ verb) { |
robertphillips@google.com | 0308707 | 2013-10-02 16:42:21 +0000 | [diff] [blame] | 277 | SkDEBUGCODE(this->validate();) |
robertphillips@google.com | ca0c838 | 2013-09-26 12:18:23 +0000 | [diff] [blame] | 278 | int pCnt; |
robertphillips@google.com | 466310d | 2013-12-03 16:43:54 +0000 | [diff] [blame^] | 279 | bool dirtyAfterEdit = true; |
robertphillips@google.com | ca0c838 | 2013-09-26 12:18:23 +0000 | [diff] [blame] | 280 | switch (verb) { |
| 281 | case SkPath::kMove_Verb: |
| 282 | pCnt = 1; |
robertphillips@google.com | 466310d | 2013-12-03 16:43:54 +0000 | [diff] [blame^] | 283 | dirtyAfterEdit = false; |
robertphillips@google.com | ca0c838 | 2013-09-26 12:18:23 +0000 | [diff] [blame] | 284 | break; |
| 285 | case SkPath::kLine_Verb: |
| 286 | pCnt = 1; |
| 287 | break; |
| 288 | case SkPath::kQuad_Verb: |
| 289 | // fall through |
| 290 | case SkPath::kConic_Verb: |
| 291 | pCnt = 2; |
| 292 | break; |
| 293 | case SkPath::kCubic_Verb: |
| 294 | pCnt = 3; |
| 295 | break; |
| 296 | case SkPath::kClose_Verb: |
| 297 | pCnt = 0; |
robertphillips@google.com | 466310d | 2013-12-03 16:43:54 +0000 | [diff] [blame^] | 298 | dirtyAfterEdit = false; |
robertphillips@google.com | ca0c838 | 2013-09-26 12:18:23 +0000 | [diff] [blame] | 299 | break; |
| 300 | case SkPath::kDone_Verb: |
| 301 | SkDEBUGFAIL("growForVerb called for kDone"); |
| 302 | // fall through |
| 303 | default: |
| 304 | SkDEBUGFAIL("default is not reached"); |
robertphillips@google.com | 466310d | 2013-12-03 16:43:54 +0000 | [diff] [blame^] | 305 | dirtyAfterEdit = false; |
robertphillips@google.com | ca0c838 | 2013-09-26 12:18:23 +0000 | [diff] [blame] | 306 | pCnt = 0; |
| 307 | } |
| 308 | size_t space = sizeof(uint8_t) + pCnt * sizeof (SkPoint); |
| 309 | this->makeSpace(space); |
| 310 | this->fVerbs[~fVerbCnt] = verb; |
| 311 | SkPoint* ret = fPoints + fPointCnt; |
| 312 | fVerbCnt += 1; |
| 313 | fPointCnt += pCnt; |
| 314 | fFreeSpace -= space; |
| 315 | fBoundsIsDirty = true; // this also invalidates fIsFinite |
robertphillips@google.com | 466310d | 2013-12-03 16:43:54 +0000 | [diff] [blame^] | 316 | if (dirtyAfterEdit) { |
| 317 | fIsOval = false; |
| 318 | } |
robertphillips@google.com | 0308707 | 2013-10-02 16:42:21 +0000 | [diff] [blame] | 319 | SkDEBUGCODE(this->validate();) |
robertphillips@google.com | ca0c838 | 2013-09-26 12:18:23 +0000 | [diff] [blame] | 320 | return ret; |
| 321 | } |
| 322 | |
commit-bot@chromium.org | 1ab9f73 | 2013-10-30 18:57:55 +0000 | [diff] [blame] | 323 | uint32_t SkPathRef::genID() const { |
robertphillips@google.com | 3e292aa | 2013-09-27 17:48:49 +0000 | [diff] [blame] | 324 | SkASSERT(!fEditorsAttached); |
commit-bot@chromium.org | 1ab9f73 | 2013-10-30 18:57:55 +0000 | [diff] [blame] | 325 | static const uint32_t kMask = (static_cast<int64_t>(1) << SkPath::kPathRefGenIDBitCnt) - 1; |
robertphillips@google.com | 3e292aa | 2013-09-27 17:48:49 +0000 | [diff] [blame] | 326 | if (!fGenerationID) { |
| 327 | if (0 == fPointCnt && 0 == fVerbCnt) { |
| 328 | fGenerationID = kEmptyGenID; |
| 329 | } else { |
| 330 | static int32_t gPathRefGenerationID; |
| 331 | // do a loop in case our global wraps around, as we never want to return a 0 or the |
| 332 | // empty ID |
| 333 | do { |
commit-bot@chromium.org | 1ab9f73 | 2013-10-30 18:57:55 +0000 | [diff] [blame] | 334 | fGenerationID = (sk_atomic_inc(&gPathRefGenerationID) + 1) & kMask; |
robertphillips@google.com | 3e292aa | 2013-09-27 17:48:49 +0000 | [diff] [blame] | 335 | } while (fGenerationID <= kEmptyGenID); |
| 336 | } |
| 337 | } |
| 338 | return fGenerationID; |
| 339 | } |
robertphillips@google.com | ca0c838 | 2013-09-26 12:18:23 +0000 | [diff] [blame] | 340 | |
robertphillips@google.com | 0308707 | 2013-10-02 16:42:21 +0000 | [diff] [blame] | 341 | #ifdef SK_DEBUG |
robertphillips@google.com | 3e292aa | 2013-09-27 17:48:49 +0000 | [diff] [blame] | 342 | void SkPathRef::validate() const { |
robertphillips@google.com | 0308707 | 2013-10-02 16:42:21 +0000 | [diff] [blame] | 343 | this->INHERITED::validate(); |
robertphillips@google.com | 3e292aa | 2013-09-27 17:48:49 +0000 | [diff] [blame] | 344 | SkASSERT(static_cast<ptrdiff_t>(fFreeSpace) >= 0); |
| 345 | SkASSERT(reinterpret_cast<intptr_t>(fVerbs) - reinterpret_cast<intptr_t>(fPoints) >= 0); |
| 346 | SkASSERT((NULL == fPoints) == (NULL == fVerbs)); |
| 347 | SkASSERT(!(NULL == fPoints && 0 != fFreeSpace)); |
| 348 | SkASSERT(!(NULL == fPoints && 0 != fFreeSpace)); |
| 349 | SkASSERT(!(NULL == fPoints && fPointCnt)); |
| 350 | SkASSERT(!(NULL == fVerbs && fVerbCnt)); |
| 351 | SkASSERT(this->currSize() == |
| 352 | fFreeSpace + sizeof(SkPoint) * fPointCnt + sizeof(uint8_t) * fVerbCnt); |
robertphillips@google.com | ca0c838 | 2013-09-26 12:18:23 +0000 | [diff] [blame] | 353 | |
robertphillips@google.com | 3e292aa | 2013-09-27 17:48:49 +0000 | [diff] [blame] | 354 | if (!fBoundsIsDirty && !fBounds.isEmpty()) { |
| 355 | bool isFinite = true; |
| 356 | for (int i = 0; i < fPointCnt; ++i) { |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 357 | SkASSERT(!fPoints[i].isFinite() || ( |
| 358 | fBounds.fLeft - fPoints[i].fX < SK_ScalarNearlyZero && |
robertphillips@google.com | 1cc385b | 2013-10-17 12:17:27 +0000 | [diff] [blame] | 359 | fPoints[i].fX - fBounds.fRight < SK_ScalarNearlyZero && |
skia.committer@gmail.com | f84ad8f | 2013-10-18 07:01:59 +0000 | [diff] [blame] | 360 | fBounds.fTop - fPoints[i].fY < SK_ScalarNearlyZero && |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 361 | fPoints[i].fY - fBounds.fBottom < SK_ScalarNearlyZero)); |
robertphillips@google.com | 3e292aa | 2013-09-27 17:48:49 +0000 | [diff] [blame] | 362 | if (!fPoints[i].isFinite()) { |
| 363 | isFinite = false; |
| 364 | } |
| 365 | } |
| 366 | SkASSERT(SkToBool(fIsFinite) == isFinite); |
| 367 | } |
robertphillips@google.com | ca0c838 | 2013-09-26 12:18:23 +0000 | [diff] [blame] | 368 | } |
robertphillips@google.com | 0308707 | 2013-10-02 16:42:21 +0000 | [diff] [blame] | 369 | #endif |