| 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 "SkLazyPtr.h" | 9 #include "SkLazyPtr.h" |
| 10 #include "SkPath.h" | 10 #include "SkPath.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 pathRef->reset(copy); | 23 pathRef->reset(copy); |
| 24 } | 24 } |
| 25 fPathRef = *pathRef; | 25 fPathRef = *pathRef; |
| 26 fPathRef->fGenerationID = 0; | 26 fPathRef->fGenerationID = 0; |
| 27 SkDEBUGCODE(sk_atomic_inc(&fPathRef->fEditorsAttached);) | 27 SkDEBUGCODE(sk_atomic_inc(&fPathRef->fEditorsAttached);) |
| 28 } | 28 } |
| 29 | 29 |
| 30 ////////////////////////////////////////////////////////////////////////////// | 30 ////////////////////////////////////////////////////////////////////////////// |
| 31 | 31 |
| 32 SkPathRef* SkPathRef::CreateEmptyImpl() { | 32 SkPathRef* SkPathRef::CreateEmptyImpl() { |
| 33 return SkNEW(SkPathRef); | 33 SkPathRef* p = SkNEW(SkPathRef); |
| 34 p->computeBounds(); // Preemptively avoid a race to clear fBoundsIsDirty. |
| 35 return p; |
| 34 } | 36 } |
| 35 | 37 |
| 36 SkPathRef* SkPathRef::CreateEmpty() { | 38 SkPathRef* SkPathRef::CreateEmpty() { |
| 37 SK_DECLARE_STATIC_LAZY_PTR(SkPathRef, empty, CreateEmptyImpl); | 39 SK_DECLARE_STATIC_LAZY_PTR(SkPathRef, empty, CreateEmptyImpl); |
| 38 return SkRef(empty.get()); | 40 return SkRef(empty.get()); |
| 39 } | 41 } |
| 40 | 42 |
| 41 void SkPathRef::CreateTransformedCopy(SkAutoTUnref<SkPathRef>* dst, | 43 void SkPathRef::CreateTransformedCopy(SkAutoTUnref<SkPathRef>* dst, |
| 42 const SkPathRef& src, | 44 const SkPathRef& src, |
| 43 const SkMatrix& matrix) { | 45 const SkMatrix& matrix) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 * them as "known", rather than force the transformed path to have to | 78 * them as "known", rather than force the transformed path to have to |
| 77 * recompute them. | 79 * recompute them. |
| 78 * | 80 * |
| 79 * Special gotchas if the path is effectively empty (<= 1 point) or | 81 * Special gotchas if the path is effectively empty (<= 1 point) or |
| 80 * if it is non-finite. In those cases bounds need to stay empty, | 82 * if it is non-finite. In those cases bounds need to stay empty, |
| 81 * regardless of the matrix. | 83 * regardless of the matrix. |
| 82 */ | 84 */ |
| 83 if (canXformBounds) { | 85 if (canXformBounds) { |
| 84 (*dst)->fBoundsIsDirty = false; | 86 (*dst)->fBoundsIsDirty = false; |
| 85 if (src.fIsFinite) { | 87 if (src.fIsFinite) { |
| 86 matrix.mapRect((*dst)->fBounds.get(), src.fBounds); | 88 matrix.mapRect(&(*dst)->fBounds, src.fBounds); |
| 87 if (!((*dst)->fIsFinite = (*dst)->fBounds->isFinite())) { | 89 if (!((*dst)->fIsFinite = (*dst)->fBounds.isFinite())) { |
| 88 (*dst)->fBounds->setEmpty(); | 90 (*dst)->fBounds.setEmpty(); |
| 89 } | 91 } |
| 90 } else { | 92 } else { |
| 91 (*dst)->fIsFinite = false; | 93 (*dst)->fIsFinite = false; |
| 92 (*dst)->fBounds->setEmpty(); | 94 (*dst)->fBounds.setEmpty(); |
| 93 } | 95 } |
| 94 } else { | 96 } else { |
| 95 (*dst)->fBoundsIsDirty = true; | 97 (*dst)->fBoundsIsDirty = true; |
| 96 } | 98 } |
| 97 | 99 |
| 98 (*dst)->fSegmentMask = src.fSegmentMask; | 100 (*dst)->fSegmentMask = src.fSegmentMask; |
| 99 | 101 |
| 100 // It's an oval only if it stays a rect. | 102 // It's an oval only if it stays a rect. |
| 101 (*dst)->fIsOval = src.fIsOval && matrix.rectStaysRect(); | 103 (*dst)->fIsOval = src.fIsOval && matrix.rectStaysRect(); |
| 102 | 104 |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 SkASSERT(static_cast<ptrdiff_t>(fFreeSpace) >= 0); | 434 SkASSERT(static_cast<ptrdiff_t>(fFreeSpace) >= 0); |
| 433 SkASSERT(reinterpret_cast<intptr_t>(fVerbs) - reinterpret_cast<intptr_t>(fPo
ints) >= 0); | 435 SkASSERT(reinterpret_cast<intptr_t>(fVerbs) - reinterpret_cast<intptr_t>(fPo
ints) >= 0); |
| 434 SkASSERT((NULL == fPoints) == (NULL == fVerbs)); | 436 SkASSERT((NULL == fPoints) == (NULL == fVerbs)); |
| 435 SkASSERT(!(NULL == fPoints && 0 != fFreeSpace)); | 437 SkASSERT(!(NULL == fPoints && 0 != fFreeSpace)); |
| 436 SkASSERT(!(NULL == fPoints && 0 != fFreeSpace)); | 438 SkASSERT(!(NULL == fPoints && 0 != fFreeSpace)); |
| 437 SkASSERT(!(NULL == fPoints && fPointCnt)); | 439 SkASSERT(!(NULL == fPoints && fPointCnt)); |
| 438 SkASSERT(!(NULL == fVerbs && fVerbCnt)); | 440 SkASSERT(!(NULL == fVerbs && fVerbCnt)); |
| 439 SkASSERT(this->currSize() == | 441 SkASSERT(this->currSize() == |
| 440 fFreeSpace + sizeof(SkPoint) * fPointCnt + sizeof(uint8_t) * fVe
rbCnt); | 442 fFreeSpace + sizeof(SkPoint) * fPointCnt + sizeof(uint8_t) * fVe
rbCnt); |
| 441 | 443 |
| 442 if (!fBoundsIsDirty && !fBounds->isEmpty()) { | 444 if (!fBoundsIsDirty && !fBounds.isEmpty()) { |
| 443 bool isFinite = true; | 445 bool isFinite = true; |
| 444 for (int i = 0; i < fPointCnt; ++i) { | 446 for (int i = 0; i < fPointCnt; ++i) { |
| 445 SkASSERT(!fPoints[i].isFinite() || ( | 447 SkASSERT(!fPoints[i].isFinite() || ( |
| 446 fBounds->fLeft - fPoints[i].fX < SK_ScalarNearlyZero && | 448 fBounds.fLeft - fPoints[i].fX < SK_ScalarNearlyZero && |
| 447 fPoints[i].fX - fBounds->fRight < SK_ScalarNearlyZero && | 449 fPoints[i].fX - fBounds.fRight < SK_ScalarNearlyZero && |
| 448 fBounds->fTop - fPoints[i].fY < SK_ScalarNearlyZero && | 450 fBounds.fTop - fPoints[i].fY < SK_ScalarNearlyZero && |
| 449 fPoints[i].fY - fBounds->fBottom < SK_ScalarNearlyZero)); | 451 fPoints[i].fY - fBounds.fBottom < SK_ScalarNearlyZero)); |
| 450 if (!fPoints[i].isFinite()) { | 452 if (!fPoints[i].isFinite()) { |
| 451 isFinite = false; | 453 isFinite = false; |
| 452 } | 454 } |
| 453 } | 455 } |
| 454 SkASSERT(SkToBool(fIsFinite) == isFinite); | 456 SkASSERT(SkToBool(fIsFinite) == isFinite); |
| 455 } | 457 } |
| 456 | 458 |
| 457 #ifdef SK_DEBUG_PATH | 459 #ifdef SK_DEBUG_PATH |
| 458 uint32_t mask = 0; | 460 uint32_t mask = 0; |
| 459 for (int i = 0; i < fVerbCnt; ++i) { | 461 for (int i = 0; i < fVerbCnt; ++i) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 479 break; | 481 break; |
| 480 default: | 482 default: |
| 481 SkDEBUGFAIL("Unknown Verb"); | 483 SkDEBUGFAIL("Unknown Verb"); |
| 482 break; | 484 break; |
| 483 } | 485 } |
| 484 } | 486 } |
| 485 SkASSERT(mask == fSegmentMask); | 487 SkASSERT(mask == fSegmentMask); |
| 486 #endif // SK_DEBUG_PATH | 488 #endif // SK_DEBUG_PATH |
| 487 } | 489 } |
| 488 #endif | 490 #endif |
| OLD | NEW |