| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkBuffer.h" | 8 #include "SkBuffer.h" |
| 9 #include "SkPath.h" | 9 #include "SkPath.h" |
| 10 #include "SkPathRef.h" | 10 #include "SkPathRef.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 SkPathRef* copy = SkNEW(SkPathRef); | 22 SkPathRef* copy = SkNEW(SkPathRef); |
| 23 copy->copy(**pathRef, incReserveVerbs, incReservePoints); | 23 copy->copy(**pathRef, incReserveVerbs, incReservePoints); |
| 24 pathRef->reset(copy); | 24 pathRef->reset(copy); |
| 25 } | 25 } |
| 26 fPathRef = *pathRef; | 26 fPathRef = *pathRef; |
| 27 fPathRef->fGenerationID = 0; | 27 fPathRef->fGenerationID = 0; |
| 28 SkDEBUGCODE(sk_atomic_inc(&fPathRef->fEditorsAttached);) | 28 SkDEBUGCODE(sk_atomic_inc(&fPathRef->fEditorsAttached);) |
| 29 } | 29 } |
| 30 | 30 |
| 31 SkPoint* SkPathRef::Editor::growForConic(SkScalar w) { | 31 SkPoint* SkPathRef::Editor::growForConic(SkScalar w) { |
| 32 fPathRef->validate(); | 32 SkDEBUGCODE(fPathRef->validate();) |
| 33 SkPoint* pts = fPathRef->growForVerb(SkPath::kConic_Verb); | 33 SkPoint* pts = fPathRef->growForVerb(SkPath::kConic_Verb); |
| 34 *fPathRef->fConicWeights.append() = w; | 34 *fPathRef->fConicWeights.append() = w; |
| 35 return pts; | 35 return pts; |
| 36 } | 36 } |
| 37 | 37 |
| 38 ////////////////////////////////////////////////////////////////////////////// | 38 ////////////////////////////////////////////////////////////////////////////// |
| 39 void SkPathRef::CreateTransformedCopy(SkAutoTUnref<SkPathRef>* dst, | 39 void SkPathRef::CreateTransformedCopy(SkAutoTUnref<SkPathRef>* dst, |
| 40 const SkPathRef& src, | 40 const SkPathRef& src, |
| 41 const SkMatrix& matrix) { | 41 const SkMatrix& matrix) { |
| 42 src.validate(); | 42 SkDEBUGCODE(src.validate();) |
| 43 if (matrix.isIdentity()) { | 43 if (matrix.isIdentity()) { |
| 44 if (*dst != &src) { | 44 if (*dst != &src) { |
| 45 src.ref(); | 45 src.ref(); |
| 46 dst->reset(const_cast<SkPathRef*>(&src)); | 46 dst->reset(const_cast<SkPathRef*>(&src)); |
| 47 (*dst)->validate(); | 47 SkDEBUGCODE((*dst)->validate();) |
| 48 } | 48 } |
| 49 return; | 49 return; |
| 50 } | 50 } |
| 51 | 51 |
| 52 bool dstUnique = (*dst)->unique(); | 52 bool dstUnique = (*dst)->unique(); |
| 53 if (!dstUnique) { | 53 if (!dstUnique) { |
| 54 dst->reset(SkNEW(SkPathRef)); | 54 dst->reset(SkNEW(SkPathRef)); |
| 55 (*dst)->resetToSize(src.fVerbCnt, src.fPointCnt, src.fConicWeights.count
()); | 55 (*dst)->resetToSize(src.fVerbCnt, src.fPointCnt, src.fConicWeights.count
()); |
| 56 memcpy((*dst)->verbsMemWritable(), src.verbsMemBegin(), src.fVerbCnt * s
izeof(uint8_t)); | 56 memcpy((*dst)->verbsMemWritable(), src.verbsMemBegin(), src.fVerbCnt * s
izeof(uint8_t)); |
| 57 (*dst)->fConicWeights = src.fConicWeights; | 57 (*dst)->fConicWeights = src.fConicWeights; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 80 (*dst)->fBounds.setEmpty(); | 80 (*dst)->fBounds.setEmpty(); |
| 81 } | 81 } |
| 82 } else { | 82 } else { |
| 83 (*dst)->fIsFinite = false; | 83 (*dst)->fIsFinite = false; |
| 84 (*dst)->fBounds.setEmpty(); | 84 (*dst)->fBounds.setEmpty(); |
| 85 } | 85 } |
| 86 } else { | 86 } else { |
| 87 (*dst)->fBoundsIsDirty = true; | 87 (*dst)->fBoundsIsDirty = true; |
| 88 } | 88 } |
| 89 | 89 |
| 90 (*dst)->validate(); | 90 SkDEBUGCODE((*dst)->validate();) |
| 91 } | 91 } |
| 92 | 92 |
| 93 SkPathRef* SkPathRef::CreateFromBuffer(SkRBuffer* buffer | 93 SkPathRef* SkPathRef::CreateFromBuffer(SkRBuffer* buffer |
| 94 #ifndef DELETE_THIS_CODE_WHEN_SKPS_ARE_REBUILT_AT_V14_AND_ALL_OTHER_INSTANCES_TO
O | 94 #ifndef DELETE_THIS_CODE_WHEN_SKPS_ARE_REBUILT_AT_V14_AND_ALL_OTHER_INSTANCES_TO
O |
| 95 , bool newFormat, int32_t oldPacked | 95 , bool newFormat, int32_t oldPacked |
| 96 #endif | 96 #endif |
| 97 ) { | 97 ) { |
| 98 SkPathRef* ref = SkNEW(SkPathRef); | 98 SkPathRef* ref = SkNEW(SkPathRef); |
| 99 #ifndef DELETE_THIS_CODE_WHEN_SKPS_ARE_REBUILT_AT_V14_AND_ALL_OTHER_INSTANCES_TO
O | 99 #ifndef DELETE_THIS_CODE_WHEN_SKPS_ARE_REBUILT_AT_V14_AND_ALL_OTHER_INSTANCES_TO
O |
| 100 if (newFormat) { | 100 if (newFormat) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 120 buffer->read(ref->verbsMemWritable(), verbCount * sizeof(uint8_t)); | 120 buffer->read(ref->verbsMemWritable(), verbCount * sizeof(uint8_t)); |
| 121 buffer->read(ref->fPoints, pointCount * sizeof(SkPoint)); | 121 buffer->read(ref->fPoints, pointCount * sizeof(SkPoint)); |
| 122 buffer->read(ref->fConicWeights.begin(), conicCount * sizeof(SkScalar)); | 122 buffer->read(ref->fConicWeights.begin(), conicCount * sizeof(SkScalar)); |
| 123 buffer->read(&ref->fBounds, sizeof(SkRect)); | 123 buffer->read(&ref->fBounds, sizeof(SkRect)); |
| 124 ref->fBoundsIsDirty = false; | 124 ref->fBoundsIsDirty = false; |
| 125 return ref; | 125 return ref; |
| 126 } | 126 } |
| 127 | 127 |
| 128 void SkPathRef::Rewind(SkAutoTUnref<SkPathRef>* pathRef) { | 128 void SkPathRef::Rewind(SkAutoTUnref<SkPathRef>* pathRef) { |
| 129 if ((*pathRef)->unique()) { | 129 if ((*pathRef)->unique()) { |
| 130 (*pathRef)->validate(); | 130 SkDEBUGCODE((*pathRef)->validate();) |
| 131 (*pathRef)->fBoundsIsDirty = true; // this also invalidates fIsFinite | 131 (*pathRef)->fBoundsIsDirty = true; // this also invalidates fIsFinite |
| 132 (*pathRef)->fVerbCnt = 0; | 132 (*pathRef)->fVerbCnt = 0; |
| 133 (*pathRef)->fPointCnt = 0; | 133 (*pathRef)->fPointCnt = 0; |
| 134 (*pathRef)->fFreeSpace = (*pathRef)->currSize(); | 134 (*pathRef)->fFreeSpace = (*pathRef)->currSize(); |
| 135 (*pathRef)->fGenerationID = 0; | 135 (*pathRef)->fGenerationID = 0; |
| 136 (*pathRef)->fConicWeights.rewind(); | 136 (*pathRef)->fConicWeights.rewind(); |
| 137 (*pathRef)->validate(); | 137 SkDEBUGCODE((*pathRef)->validate();) |
| 138 } else { | 138 } else { |
| 139 int oldVCnt = (*pathRef)->countVerbs(); | 139 int oldVCnt = (*pathRef)->countVerbs(); |
| 140 int oldPCnt = (*pathRef)->countPoints(); | 140 int oldPCnt = (*pathRef)->countPoints(); |
| 141 pathRef->reset(SkNEW(SkPathRef)); | 141 pathRef->reset(SkNEW(SkPathRef)); |
| 142 (*pathRef)->resetToSize(0, 0, 0, oldVCnt, oldPCnt); | 142 (*pathRef)->resetToSize(0, 0, 0, oldVCnt, oldPCnt); |
| 143 } | 143 } |
| 144 } | 144 } |
| 145 | 145 |
| 146 bool SkPathRef::operator== (const SkPathRef& ref) const { | 146 bool SkPathRef::operator== (const SkPathRef& ref) const { |
| 147 this->validate(); | 147 SkDEBUGCODE(this->validate();) |
| 148 ref.validate(); | 148 SkDEBUGCODE(ref.validate();) |
| 149 bool genIDMatch = fGenerationID && fGenerationID == ref.fGenerationID; | 149 bool genIDMatch = fGenerationID && fGenerationID == ref.fGenerationID; |
| 150 #ifdef SK_RELEASE | 150 #ifdef SK_RELEASE |
| 151 if (genIDMatch) { | 151 if (genIDMatch) { |
| 152 return true; | 152 return true; |
| 153 } | 153 } |
| 154 #endif | 154 #endif |
| 155 if (fPointCnt != ref.fPointCnt || | 155 if (fPointCnt != ref.fPointCnt || |
| 156 fVerbCnt != ref.fVerbCnt) { | 156 fVerbCnt != ref.fVerbCnt) { |
| 157 SkASSERT(!genIDMatch); | 157 SkASSERT(!genIDMatch); |
| 158 return false; | 158 return false; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 177 // the other's. If both are 0 then genID() will compute the next ID. | 177 // the other's. If both are 0 then genID() will compute the next ID. |
| 178 if (0 == fGenerationID) { | 178 if (0 == fGenerationID) { |
| 179 fGenerationID = ref.genID(); | 179 fGenerationID = ref.genID(); |
| 180 } else if (0 == ref.fGenerationID) { | 180 } else if (0 == ref.fGenerationID) { |
| 181 ref.fGenerationID = this->genID(); | 181 ref.fGenerationID = this->genID(); |
| 182 } | 182 } |
| 183 return true; | 183 return true; |
| 184 } | 184 } |
| 185 | 185 |
| 186 void SkPathRef::writeToBuffer(SkWBuffer* buffer) { | 186 void SkPathRef::writeToBuffer(SkWBuffer* buffer) { |
| 187 this->validate(); | 187 SkDEBUGCODE(this->validate();) |
| 188 SkDEBUGCODE(size_t beforePos = buffer->pos();) | 188 SkDEBUGCODE(size_t beforePos = buffer->pos();) |
| 189 | 189 |
| 190 // Call getBounds() to ensure (as a side-effect) that fBounds | 190 // Call getBounds() to ensure (as a side-effect) that fBounds |
| 191 // and fIsFinite are computed. | 191 // and fIsFinite are computed. |
| 192 const SkRect& bounds = this->getBounds(); | 192 const SkRect& bounds = this->getBounds(); |
| 193 | 193 |
| 194 int32_t packed = ((fIsFinite & 1) << kIsFinite_SerializationShift); | 194 int32_t packed = ((fIsFinite & 1) << kIsFinite_SerializationShift); |
| 195 buffer->write32(packed); | 195 buffer->write32(packed); |
| 196 | 196 |
| 197 // TODO: write gen ID here. Problem: We don't know if we're cross process or
not from | 197 // TODO: write gen ID here. Problem: We don't know if we're cross process or
not from |
| (...skipping 14 matching lines...) Expand all Loading... |
| 212 return uint32_t(5 * sizeof(uint32_t) + | 212 return uint32_t(5 * sizeof(uint32_t) + |
| 213 fVerbCnt * sizeof(uint8_t) + | 213 fVerbCnt * sizeof(uint8_t) + |
| 214 fPointCnt * sizeof(SkPoint) + | 214 fPointCnt * sizeof(SkPoint) + |
| 215 fConicWeights.bytes() + | 215 fConicWeights.bytes() + |
| 216 sizeof(SkRect)); | 216 sizeof(SkRect)); |
| 217 } | 217 } |
| 218 | 218 |
| 219 void SkPathRef::copy(const SkPathRef& ref, | 219 void SkPathRef::copy(const SkPathRef& ref, |
| 220 int additionalReserveVerbs, | 220 int additionalReserveVerbs, |
| 221 int additionalReservePoints) { | 221 int additionalReservePoints) { |
| 222 this->validate(); | 222 SkDEBUGCODE(this->validate();) |
| 223 this->resetToSize(ref.fVerbCnt, ref.fPointCnt, ref.fConicWeights.count(), | 223 this->resetToSize(ref.fVerbCnt, ref.fPointCnt, ref.fConicWeights.count(), |
| 224 additionalReserveVerbs, additionalReservePoints); | 224 additionalReserveVerbs, additionalReservePoints); |
| 225 memcpy(this->verbsMemWritable(), ref.verbsMemBegin(), ref.fVerbCnt * sizeof(
uint8_t)); | 225 memcpy(this->verbsMemWritable(), ref.verbsMemBegin(), ref.fVerbCnt * sizeof(
uint8_t)); |
| 226 memcpy(this->fPoints, ref.fPoints, ref.fPointCnt * sizeof(SkPoint)); | 226 memcpy(this->fPoints, ref.fPoints, ref.fPointCnt * sizeof(SkPoint)); |
| 227 fConicWeights = ref.fConicWeights; | 227 fConicWeights = ref.fConicWeights; |
| 228 // We could call genID() here to force a real ID (instead of 0). However, if
we're making | 228 // We could call genID() here to force a real ID (instead of 0). However, if
we're making |
| 229 // a copy then presumably we intend to make a modification immediately after
wards. | 229 // a copy then presumably we intend to make a modification immediately after
wards. |
| 230 fGenerationID = ref.fGenerationID; | 230 fGenerationID = ref.fGenerationID; |
| 231 fBoundsIsDirty = ref.fBoundsIsDirty; | 231 fBoundsIsDirty = ref.fBoundsIsDirty; |
| 232 if (!fBoundsIsDirty) { | 232 if (!fBoundsIsDirty) { |
| 233 fBounds = ref.fBounds; | 233 fBounds = ref.fBounds; |
| 234 fIsFinite = ref.fIsFinite; | 234 fIsFinite = ref.fIsFinite; |
| 235 } | 235 } |
| 236 this->validate(); | 236 SkDEBUGCODE(this->validate();) |
| 237 } | 237 } |
| 238 | 238 |
| 239 void SkPathRef::resetToSize(int verbCount, int pointCount, int conicCount, | 239 void SkPathRef::resetToSize(int verbCount, int pointCount, int conicCount, |
| 240 int reserveVerbs, int reservePoints) { | 240 int reserveVerbs, int reservePoints) { |
| 241 this->validate(); | 241 SkDEBUGCODE(this->validate();) |
| 242 fBoundsIsDirty = true; // this also invalidates fIsFinite | 242 fBoundsIsDirty = true; // this also invalidates fIsFinite |
| 243 fGenerationID = 0; | 243 fGenerationID = 0; |
| 244 | 244 |
| 245 size_t newSize = sizeof(uint8_t) * verbCount + sizeof(SkPoint) * pointCount; | 245 size_t newSize = sizeof(uint8_t) * verbCount + sizeof(SkPoint) * pointCount; |
| 246 size_t newReserve = sizeof(uint8_t) * reserveVerbs + sizeof(SkPoint) * reser
vePoints; | 246 size_t newReserve = sizeof(uint8_t) * reserveVerbs + sizeof(SkPoint) * reser
vePoints; |
| 247 size_t minSize = newSize + newReserve; | 247 size_t minSize = newSize + newReserve; |
| 248 | 248 |
| 249 ptrdiff_t sizeDelta = this->currSize() - minSize; | 249 ptrdiff_t sizeDelta = this->currSize() - minSize; |
| 250 | 250 |
| 251 if (sizeDelta < 0 || static_cast<size_t>(sizeDelta) >= 3 * minSize) { | 251 if (sizeDelta < 0 || static_cast<size_t>(sizeDelta) >= 3 * minSize) { |
| 252 sk_free(fPoints); | 252 sk_free(fPoints); |
| 253 fPoints = NULL; | 253 fPoints = NULL; |
| 254 fVerbs = NULL; | 254 fVerbs = NULL; |
| 255 fFreeSpace = 0; | 255 fFreeSpace = 0; |
| 256 fVerbCnt = 0; | 256 fVerbCnt = 0; |
| 257 fPointCnt = 0; | 257 fPointCnt = 0; |
| 258 this->makeSpace(minSize); | 258 this->makeSpace(minSize); |
| 259 fVerbCnt = verbCount; | 259 fVerbCnt = verbCount; |
| 260 fPointCnt = pointCount; | 260 fPointCnt = pointCount; |
| 261 fFreeSpace -= newSize; | 261 fFreeSpace -= newSize; |
| 262 } else { | 262 } else { |
| 263 fPointCnt = pointCount; | 263 fPointCnt = pointCount; |
| 264 fVerbCnt = verbCount; | 264 fVerbCnt = verbCount; |
| 265 fFreeSpace = this->currSize() - minSize; | 265 fFreeSpace = this->currSize() - minSize; |
| 266 } | 266 } |
| 267 fConicWeights.setCount(conicCount); | 267 fConicWeights.setCount(conicCount); |
| 268 this->validate(); | 268 SkDEBUGCODE(this->validate();) |
| 269 } | 269 } |
| 270 | 270 |
| 271 SkPoint* SkPathRef::growForVerb(int /* SkPath::Verb*/ verb) { | 271 SkPoint* SkPathRef::growForVerb(int /* SkPath::Verb*/ verb) { |
| 272 this->validate(); | 272 SkDEBUGCODE(this->validate();) |
| 273 int pCnt; | 273 int pCnt; |
| 274 switch (verb) { | 274 switch (verb) { |
| 275 case SkPath::kMove_Verb: | 275 case SkPath::kMove_Verb: |
| 276 pCnt = 1; | 276 pCnt = 1; |
| 277 break; | 277 break; |
| 278 case SkPath::kLine_Verb: | 278 case SkPath::kLine_Verb: |
| 279 pCnt = 1; | 279 pCnt = 1; |
| 280 break; | 280 break; |
| 281 case SkPath::kQuad_Verb: | 281 case SkPath::kQuad_Verb: |
| 282 // fall through | 282 // fall through |
| (...skipping 14 matching lines...) Expand all Loading... |
| 297 pCnt = 0; | 297 pCnt = 0; |
| 298 } | 298 } |
| 299 size_t space = sizeof(uint8_t) + pCnt * sizeof (SkPoint); | 299 size_t space = sizeof(uint8_t) + pCnt * sizeof (SkPoint); |
| 300 this->makeSpace(space); | 300 this->makeSpace(space); |
| 301 this->fVerbs[~fVerbCnt] = verb; | 301 this->fVerbs[~fVerbCnt] = verb; |
| 302 SkPoint* ret = fPoints + fPointCnt; | 302 SkPoint* ret = fPoints + fPointCnt; |
| 303 fVerbCnt += 1; | 303 fVerbCnt += 1; |
| 304 fPointCnt += pCnt; | 304 fPointCnt += pCnt; |
| 305 fFreeSpace -= space; | 305 fFreeSpace -= space; |
| 306 fBoundsIsDirty = true; // this also invalidates fIsFinite | 306 fBoundsIsDirty = true; // this also invalidates fIsFinite |
| 307 this->validate(); | 307 SkDEBUGCODE(this->validate();) |
| 308 return ret; | 308 return ret; |
| 309 } | 309 } |
| 310 | 310 |
| 311 void SkPathRef::makeSpace(size_t size) { | 311 void SkPathRef::makeSpace(size_t size) { |
| 312 this->validate(); | 312 SkDEBUGCODE(this->validate();) |
| 313 ptrdiff_t growSize = size - fFreeSpace; | 313 ptrdiff_t growSize = size - fFreeSpace; |
| 314 if (growSize <= 0) { | 314 if (growSize <= 0) { |
| 315 return; | 315 return; |
| 316 } | 316 } |
| 317 size_t oldSize = this->currSize(); | 317 size_t oldSize = this->currSize(); |
| 318 // round to next multiple of 8 bytes | 318 // round to next multiple of 8 bytes |
| 319 growSize = (growSize + 7) & ~static_cast<size_t>(7); | 319 growSize = (growSize + 7) & ~static_cast<size_t>(7); |
| 320 // we always at least double the allocation | 320 // we always at least double the allocation |
| 321 if (static_cast<size_t>(growSize) < oldSize) { | 321 if (static_cast<size_t>(growSize) < oldSize) { |
| 322 growSize = oldSize; | 322 growSize = oldSize; |
| 323 } | 323 } |
| 324 if (growSize < kMinSize) { | 324 if (growSize < kMinSize) { |
| 325 growSize = kMinSize; | 325 growSize = kMinSize; |
| 326 } | 326 } |
| 327 size_t newSize = oldSize + growSize; | 327 size_t newSize = oldSize + growSize; |
| 328 // Note that realloc could memcpy more than we need. It seems to be a win an
yway. TODO: | 328 // Note that realloc could memcpy more than we need. It seems to be a win an
yway. TODO: |
| 329 // encapsulate this. | 329 // encapsulate this. |
| 330 fPoints = reinterpret_cast<SkPoint*>(sk_realloc_throw(fPoints, newSize)); | 330 fPoints = reinterpret_cast<SkPoint*>(sk_realloc_throw(fPoints, newSize)); |
| 331 size_t oldVerbSize = fVerbCnt * sizeof(uint8_t); | 331 size_t oldVerbSize = fVerbCnt * sizeof(uint8_t); |
| 332 void* newVerbsDst = reinterpret_cast<void*>( | 332 void* newVerbsDst = reinterpret_cast<void*>( |
| 333 reinterpret_cast<intptr_t>(fPoints) + newSize - oldV
erbSize); | 333 reinterpret_cast<intptr_t>(fPoints) + newSize - oldV
erbSize); |
| 334 void* oldVerbsSrc = reinterpret_cast<void*>( | 334 void* oldVerbsSrc = reinterpret_cast<void*>( |
| 335 reinterpret_cast<intptr_t>(fPoints) + oldSize - oldV
erbSize); | 335 reinterpret_cast<intptr_t>(fPoints) + oldSize - oldV
erbSize); |
| 336 memmove(newVerbsDst, oldVerbsSrc, oldVerbSize); | 336 memmove(newVerbsDst, oldVerbsSrc, oldVerbSize); |
| 337 fVerbs = reinterpret_cast<uint8_t*>(reinterpret_cast<intptr_t>(fPoints) + ne
wSize); | 337 fVerbs = reinterpret_cast<uint8_t*>(reinterpret_cast<intptr_t>(fPoints) + ne
wSize); |
| 338 fFreeSpace += growSize; | 338 fFreeSpace += growSize; |
| 339 this->validate(); | 339 SkDEBUGCODE(this->validate();) |
| 340 } | 340 } |
| 341 | 341 |
| 342 int32_t SkPathRef::genID() const { | 342 int32_t SkPathRef::genID() const { |
| 343 SkASSERT(!fEditorsAttached); | 343 SkASSERT(!fEditorsAttached); |
| 344 if (!fGenerationID) { | 344 if (!fGenerationID) { |
| 345 if (0 == fPointCnt && 0 == fVerbCnt) { | 345 if (0 == fPointCnt && 0 == fVerbCnt) { |
| 346 fGenerationID = kEmptyGenID; | 346 fGenerationID = kEmptyGenID; |
| 347 } else { | 347 } else { |
| 348 static int32_t gPathRefGenerationID; | 348 static int32_t gPathRefGenerationID; |
| 349 // do a loop in case our global wraps around, as we never want to re
turn a 0 or the | 349 // do a loop in case our global wraps around, as we never want to re
turn a 0 or the |
| 350 // empty ID | 350 // empty ID |
| 351 do { | 351 do { |
| 352 fGenerationID = sk_atomic_inc(&gPathRefGenerationID) + 1; | 352 fGenerationID = sk_atomic_inc(&gPathRefGenerationID) + 1; |
| 353 } while (fGenerationID <= kEmptyGenID); | 353 } while (fGenerationID <= kEmptyGenID); |
| 354 } | 354 } |
| 355 } | 355 } |
| 356 return fGenerationID; | 356 return fGenerationID; |
| 357 } | 357 } |
| 358 | 358 |
| 359 #ifdef SK_DEBUG |
| 359 void SkPathRef::validate() const { | 360 void SkPathRef::validate() const { |
| 361 this->INHERITED::validate(); |
| 360 SkASSERT(static_cast<ptrdiff_t>(fFreeSpace) >= 0); | 362 SkASSERT(static_cast<ptrdiff_t>(fFreeSpace) >= 0); |
| 361 SkASSERT(reinterpret_cast<intptr_t>(fVerbs) - reinterpret_cast<intptr_t>(fPo
ints) >= 0); | 363 SkASSERT(reinterpret_cast<intptr_t>(fVerbs) - reinterpret_cast<intptr_t>(fPo
ints) >= 0); |
| 362 SkASSERT((NULL == fPoints) == (NULL == fVerbs)); | 364 SkASSERT((NULL == fPoints) == (NULL == fVerbs)); |
| 363 SkASSERT(!(NULL == fPoints && 0 != fFreeSpace)); | 365 SkASSERT(!(NULL == fPoints && 0 != fFreeSpace)); |
| 364 SkASSERT(!(NULL == fPoints && 0 != fFreeSpace)); | 366 SkASSERT(!(NULL == fPoints && 0 != fFreeSpace)); |
| 365 SkASSERT(!(NULL == fPoints && fPointCnt)); | 367 SkASSERT(!(NULL == fPoints && fPointCnt)); |
| 366 SkASSERT(!(NULL == fVerbs && fVerbCnt)); | 368 SkASSERT(!(NULL == fVerbs && fVerbCnt)); |
| 367 SkASSERT(this->currSize() == | 369 SkASSERT(this->currSize() == |
| 368 fFreeSpace + sizeof(SkPoint) * fPointCnt + sizeof(uint8_t) * fVe
rbCnt); | 370 fFreeSpace + sizeof(SkPoint) * fPointCnt + sizeof(uint8_t) * fVe
rbCnt); |
| 369 | 371 |
| 370 #ifdef SK_DEBUG | 372 #ifdef SK_DEBUG |
| 371 if (!fBoundsIsDirty && !fBounds.isEmpty()) { | 373 if (!fBoundsIsDirty && !fBounds.isEmpty()) { |
| 372 bool isFinite = true; | 374 bool isFinite = true; |
| 373 for (int i = 0; i < fPointCnt; ++i) { | 375 for (int i = 0; i < fPointCnt; ++i) { |
| 374 SkASSERT(fPoints[i].fX >= fBounds.fLeft && fPoints[i].fX <= fBounds.
fRight && | 376 SkASSERT(fPoints[i].fX >= fBounds.fLeft && fPoints[i].fX <= fBounds.
fRight && |
| 375 fPoints[i].fY >= fBounds.fTop && fPoints[i].fY <= fBound
s.fBottom); | 377 fPoints[i].fY >= fBounds.fTop && fPoints[i].fY <= fBound
s.fBottom); |
| 376 if (!fPoints[i].isFinite()) { | 378 if (!fPoints[i].isFinite()) { |
| 377 isFinite = false; | 379 isFinite = false; |
| 378 } | 380 } |
| 379 } | 381 } |
| 380 SkASSERT(SkToBool(fIsFinite) == isFinite); | 382 SkASSERT(SkToBool(fIsFinite) == isFinite); |
| 381 } | 383 } |
| 382 #endif | 384 #endif |
| 383 } | 385 } |
| 386 #endif |
| OLD | NEW |