| 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 "SkOnce.h" | 9 #include "SkOncePtr.h" |
| 10 #include "SkPath.h" | 10 #include "SkPath.h" |
| 11 #include "SkPathRef.h" | 11 #include "SkPathRef.h" |
| 12 #include <limits> | 12 #include <limits> |
| 13 | 13 |
| 14 ////////////////////////////////////////////////////////////////////////////// | 14 ////////////////////////////////////////////////////////////////////////////// |
| 15 SkPathRef::Editor::Editor(SkAutoTUnref<SkPathRef>* pathRef, | 15 SkPathRef::Editor::Editor(SkAutoTUnref<SkPathRef>* pathRef, |
| 16 int incReserveVerbs, | 16 int incReserveVerbs, |
| 17 int incReservePoints) | 17 int incReservePoints) |
| 18 { | 18 { |
| 19 if ((*pathRef)->unique()) { | 19 if ((*pathRef)->unique()) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 38 | 38 |
| 39 SkDEBUGCODE(fPoints = nullptr;) | 39 SkDEBUGCODE(fPoints = nullptr;) |
| 40 SkDEBUGCODE(fVerbs = nullptr;) | 40 SkDEBUGCODE(fVerbs = nullptr;) |
| 41 SkDEBUGCODE(fVerbCnt = 0x9999999;) | 41 SkDEBUGCODE(fVerbCnt = 0x9999999;) |
| 42 SkDEBUGCODE(fPointCnt = 0xAAAAAAA;) | 42 SkDEBUGCODE(fPointCnt = 0xAAAAAAA;) |
| 43 SkDEBUGCODE(fPointCnt = 0xBBBBBBB;) | 43 SkDEBUGCODE(fPointCnt = 0xBBBBBBB;) |
| 44 SkDEBUGCODE(fGenerationID = 0xEEEEEEEE;) | 44 SkDEBUGCODE(fGenerationID = 0xEEEEEEEE;) |
| 45 SkDEBUGCODE(fEditorsAttached = 0x7777777;) | 45 SkDEBUGCODE(fEditorsAttached = 0x7777777;) |
| 46 } | 46 } |
| 47 | 47 |
| 48 static SkPathRef* gEmpty = nullptr; | 48 SK_DECLARE_STATIC_ONCE_PTR(SkPathRef, empty); |
| 49 | |
| 50 SkPathRef* SkPathRef::CreateEmpty() { | 49 SkPathRef* SkPathRef::CreateEmpty() { |
| 51 static SkOnce once; | 50 return SkRef(empty.get([]{ |
| 52 once([]{ | 51 SkPathRef* pr = new SkPathRef; |
| 53 gEmpty = new SkPathRef; | 52 pr->computeBounds(); // Avoids races later to be the first to do this. |
| 54 gEmpty->computeBounds(); // Avoids races later to be the first to do t
his. | 53 return pr; |
| 55 }); | 54 })); |
| 56 return SkRef(gEmpty); | |
| 57 } | 55 } |
| 58 | 56 |
| 59 void SkPathRef::CreateTransformedCopy(SkAutoTUnref<SkPathRef>* dst, | 57 void SkPathRef::CreateTransformedCopy(SkAutoTUnref<SkPathRef>* dst, |
| 60 const SkPathRef& src, | 58 const SkPathRef& src, |
| 61 const SkMatrix& matrix) { | 59 const SkMatrix& matrix) { |
| 62 SkDEBUGCODE(src.validate();) | 60 SkDEBUGCODE(src.validate();) |
| 63 if (matrix.isIdentity()) { | 61 if (matrix.isIdentity()) { |
| 64 if (*dst != &src) { | 62 if (*dst != &src) { |
| 65 src.ref(); | 63 src.ref(); |
| 66 dst->reset(const_cast<SkPathRef*>(&src)); | 64 dst->reset(const_cast<SkPathRef*>(&src)); |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 // empty ID | 462 // empty ID |
| 465 do { | 463 do { |
| 466 fGenerationID = (sk_atomic_inc(&gPathRefGenerationID) + 1) & kMa
sk; | 464 fGenerationID = (sk_atomic_inc(&gPathRefGenerationID) + 1) & kMa
sk; |
| 467 } while (fGenerationID <= kEmptyGenID); | 465 } while (fGenerationID <= kEmptyGenID); |
| 468 } | 466 } |
| 469 } | 467 } |
| 470 return fGenerationID; | 468 return fGenerationID; |
| 471 } | 469 } |
| 472 | 470 |
| 473 void SkPathRef::addGenIDChangeListener(GenIDChangeListener* listener) { | 471 void SkPathRef::addGenIDChangeListener(GenIDChangeListener* listener) { |
| 474 if (nullptr == listener || this == gEmpty) { | 472 if (nullptr == listener || this == (SkPathRef*)empty) { |
| 475 delete listener; | 473 delete listener; |
| 476 return; | 474 return; |
| 477 } | 475 } |
| 478 *fGenIDChangeListeners.append() = listener; | 476 *fGenIDChangeListeners.append() = listener; |
| 479 } | 477 } |
| 480 | 478 |
| 481 // we need to be called *before* the genID gets changed or zerod | 479 // we need to be called *before* the genID gets changed or zerod |
| 482 void SkPathRef::callGenIDChangeListeners() { | 480 void SkPathRef::callGenIDChangeListeners() { |
| 483 for (int i = 0; i < fGenIDChangeListeners.count(); i++) { | 481 for (int i = 0; i < fGenIDChangeListeners.count(); i++) { |
| 484 fGenIDChangeListeners[i]->onChange(); | 482 fGenIDChangeListeners[i]->onChange(); |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 669 break; | 667 break; |
| 670 default: | 668 default: |
| 671 SkDEBUGFAIL("Unknown Verb"); | 669 SkDEBUGFAIL("Unknown Verb"); |
| 672 break; | 670 break; |
| 673 } | 671 } |
| 674 } | 672 } |
| 675 SkASSERT(mask == fSegmentMask); | 673 SkASSERT(mask == fSegmentMask); |
| 676 #endif // SK_DEBUG_PATH | 674 #endif // SK_DEBUG_PATH |
| 677 } | 675 } |
| 678 #endif | 676 #endif |
| OLD | NEW |