Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(733)

Side by Side Diff: src/core/SkPathRef.cpp

Issue 1322933005: Port uses of SkLazyPtr to SkOncePtr. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: name Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/core/SkMiniRecorder.cpp ('k') | src/core/SkTypeface.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "SkOncePtr.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);
(...skipping 17 matching lines...) Expand all
37 37
38 SkDEBUGCODE(fPoints = nullptr;) 38 SkDEBUGCODE(fPoints = nullptr;)
39 SkDEBUGCODE(fVerbs = nullptr;) 39 SkDEBUGCODE(fVerbs = nullptr;)
40 SkDEBUGCODE(fVerbCnt = 0x9999999;) 40 SkDEBUGCODE(fVerbCnt = 0x9999999;)
41 SkDEBUGCODE(fPointCnt = 0xAAAAAAA;) 41 SkDEBUGCODE(fPointCnt = 0xAAAAAAA;)
42 SkDEBUGCODE(fPointCnt = 0xBBBBBBB;) 42 SkDEBUGCODE(fPointCnt = 0xBBBBBBB;)
43 SkDEBUGCODE(fGenerationID = 0xEEEEEEEE;) 43 SkDEBUGCODE(fGenerationID = 0xEEEEEEEE;)
44 SkDEBUGCODE(fEditorsAttached = 0x7777777;) 44 SkDEBUGCODE(fEditorsAttached = 0x7777777;)
45 } 45 }
46 46
47 // As a template argument, this must have external linkage. 47 SK_DECLARE_STATIC_ONCE_PTR(SkPathRef, empty);
48 SkPathRef* sk_create_empty_pathref() {
49 SkPathRef* empty = new SkPathRef;
50 empty->computeBounds(); // Avoids races later to be the first to do this.
51 return empty;
52 }
53
54 SK_DECLARE_STATIC_LAZY_PTR(SkPathRef, empty, sk_create_empty_pathref);
55
56 SkPathRef* SkPathRef::CreateEmpty() { 48 SkPathRef* SkPathRef::CreateEmpty() {
57 return SkRef(empty.get()); 49 return SkRef(empty.get([]{
50 SkPathRef* pr = new SkPathRef;
51 pr->computeBounds(); // Avoids races later to be the first to do this.
52 return pr;
53 }));
58 } 54 }
59 55
60 void SkPathRef::CreateTransformedCopy(SkAutoTUnref<SkPathRef>* dst, 56 void SkPathRef::CreateTransformedCopy(SkAutoTUnref<SkPathRef>* dst,
61 const SkPathRef& src, 57 const SkPathRef& src,
62 const SkMatrix& matrix) { 58 const SkMatrix& matrix) {
63 SkDEBUGCODE(src.validate();) 59 SkDEBUGCODE(src.validate();)
64 if (matrix.isIdentity()) { 60 if (matrix.isIdentity()) {
65 if (*dst != &src) { 61 if (*dst != &src) {
66 src.ref(); 62 src.ref();
67 dst->reset(const_cast<SkPathRef*>(&src)); 63 dst->reset(const_cast<SkPathRef*>(&src));
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 // empty ID 432 // empty ID
437 do { 433 do {
438 fGenerationID = (sk_atomic_inc(&gPathRefGenerationID) + 1) & kMa sk; 434 fGenerationID = (sk_atomic_inc(&gPathRefGenerationID) + 1) & kMa sk;
439 } while (fGenerationID <= kEmptyGenID); 435 } while (fGenerationID <= kEmptyGenID);
440 } 436 }
441 } 437 }
442 return fGenerationID; 438 return fGenerationID;
443 } 439 }
444 440
445 void SkPathRef::addGenIDChangeListener(GenIDChangeListener* listener) { 441 void SkPathRef::addGenIDChangeListener(GenIDChangeListener* listener) {
446 if (nullptr == listener || this == empty.get()) { 442 if (nullptr == listener || this == (SkPathRef*)empty) {
447 delete listener; 443 delete listener;
448 return; 444 return;
449 } 445 }
450 *fGenIDChangeListeners.append() = listener; 446 *fGenIDChangeListeners.append() = listener;
451 } 447 }
452 448
453 // we need to be called *before* the genID gets changed or zerod 449 // we need to be called *before* the genID gets changed or zerod
454 void SkPathRef::callGenIDChangeListeners() { 450 void SkPathRef::callGenIDChangeListeners() {
455 for (int i = 0; i < fGenIDChangeListeners.count(); i++) { 451 for (int i = 0; i < fGenIDChangeListeners.count(); i++) {
456 fGenIDChangeListeners[i]->onChange(); 452 fGenIDChangeListeners[i]->onChange();
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 break; 522 break;
527 default: 523 default:
528 SkDEBUGFAIL("Unknown Verb"); 524 SkDEBUGFAIL("Unknown Verb");
529 break; 525 break;
530 } 526 }
531 } 527 }
532 SkASSERT(mask == fSegmentMask); 528 SkASSERT(mask == fSegmentMask);
533 #endif // SK_DEBUG_PATH 529 #endif // SK_DEBUG_PATH
534 } 530 }
535 #endif 531 #endif
OLDNEW
« no previous file with comments | « src/core/SkMiniRecorder.cpp ('k') | src/core/SkTypeface.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698