| 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 "SkLazyPtr.h" |
| 10 #include "SkPath.h" | 10 #include "SkPath.h" |
| 11 #include "SkPathRef.h" | 11 #include "SkPathRef.h" |
| 12 | 12 |
| 13 ////////////////////////////////////////////////////////////////////////////// | 13 ////////////////////////////////////////////////////////////////////////////// |
| 14 SkPathRef::Editor::Editor(SkAutoTUnref<SkPathRef>* pathRef, | 14 SkPathRef::Editor::Editor(SkAutoTUnref<SkPathRef>* pathRef, |
| 15 int incReserveVerbs, | 15 int incReserveVerbs, |
| 16 int incReservePoints) | 16 int incReservePoints) |
| 17 { | 17 { |
| 18 if ((*pathRef)->unique()) { | 18 if ((*pathRef)->unique()) { |
| 19 (*pathRef)->incReserve(incReserveVerbs, incReservePoints); | 19 (*pathRef)->incReserve(incReserveVerbs, incReservePoints); |
| 20 } else { | 20 } else { |
| 21 SkPathRef* copy = SkNEW(SkPathRef); | 21 SkPathRef* copy = SkNEW(SkPathRef); |
| 22 copy->copy(**pathRef, incReserveVerbs, incReservePoints); | 22 copy->copy(**pathRef, incReserveVerbs, incReservePoints); |
| 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 static SkPathRef* gEmptyPathRef = NULL; | |
| 32 static void cleanup_gEmptyPathRef() { gEmptyPathRef->unref(); } | |
| 33 | 31 |
| 34 void SkPathRef::CreateEmptyImpl(int) { | 32 SkPathRef* SkPathRef::CreateEmptyImpl() { |
| 35 gEmptyPathRef = SkNEW(SkPathRef); | 33 SkPathRef* p = SkNEW(SkPathRef); |
| 36 gEmptyPathRef->computeBounds(); // Preemptively avoid a race to clear fBoun
dsIsDirty. | 34 p->computeBounds(); // Preemptively avoid a race to clear fBoundsIsDirty. |
| 35 return p; |
| 37 } | 36 } |
| 38 | 37 |
| 39 SkPathRef* SkPathRef::CreateEmpty() { | 38 SkPathRef* SkPathRef::CreateEmpty() { |
| 40 SK_DECLARE_STATIC_ONCE(once); | 39 SK_DECLARE_STATIC_LAZY_PTR(SkPathRef, empty, CreateEmptyImpl); |
| 41 SkOnce(&once, SkPathRef::CreateEmptyImpl, 0, cleanup_gEmptyPathRef); | 40 return SkRef(empty.get()); |
| 42 return SkRef(gEmptyPathRef); | |
| 43 } | 41 } |
| 44 | 42 |
| 45 void SkPathRef::CreateTransformedCopy(SkAutoTUnref<SkPathRef>* dst, | 43 void SkPathRef::CreateTransformedCopy(SkAutoTUnref<SkPathRef>* dst, |
| 46 const SkPathRef& src, | 44 const SkPathRef& src, |
| 47 const SkMatrix& matrix) { | 45 const SkMatrix& matrix) { |
| 48 SkDEBUGCODE(src.validate();) | 46 SkDEBUGCODE(src.validate();) |
| 49 if (matrix.isIdentity()) { | 47 if (matrix.isIdentity()) { |
| 50 if (*dst != &src) { | 48 if (*dst != &src) { |
| 51 src.ref(); | 49 src.ref(); |
| 52 dst->reset(const_cast<SkPathRef*>(&src)); | 50 dst->reset(const_cast<SkPathRef*>(&src)); |
| (...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 483 break; | 481 break; |
| 484 default: | 482 default: |
| 485 SkDEBUGFAIL("Unknown Verb"); | 483 SkDEBUGFAIL("Unknown Verb"); |
| 486 break; | 484 break; |
| 487 } | 485 } |
| 488 } | 486 } |
| 489 SkASSERT(mask == fSegmentMask); | 487 SkASSERT(mask == fSegmentMask); |
| 490 #endif // SK_DEBUG_PATH | 488 #endif // SK_DEBUG_PATH |
| 491 } | 489 } |
| 492 #endif | 490 #endif |
| OLD | NEW |