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