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

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

Issue 1334523002: Revert of Port uses of SkLazyPtr to SkOncePtr. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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 "SkOncePtr.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);
(...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 SK_DECLARE_STATIC_ONCE_PTR(SkPathRef, empty); 47 // As a template argument, this must have external linkage.
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
48 SkPathRef* SkPathRef::CreateEmpty() { 56 SkPathRef* SkPathRef::CreateEmpty() {
49 return SkRef(empty.get([]{ 57 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 }));
54 } 58 }
55 59
56 void SkPathRef::CreateTransformedCopy(SkAutoTUnref<SkPathRef>* dst, 60 void SkPathRef::CreateTransformedCopy(SkAutoTUnref<SkPathRef>* dst,
57 const SkPathRef& src, 61 const SkPathRef& src,
58 const SkMatrix& matrix) { 62 const SkMatrix& matrix) {
59 SkDEBUGCODE(src.validate();) 63 SkDEBUGCODE(src.validate();)
60 if (matrix.isIdentity()) { 64 if (matrix.isIdentity()) {
61 if (*dst != &src) { 65 if (*dst != &src) {
62 src.ref(); 66 src.ref();
63 dst->reset(const_cast<SkPathRef*>(&src)); 67 dst->reset(const_cast<SkPathRef*>(&src));
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 // empty ID 436 // empty ID
433 do { 437 do {
434 fGenerationID = (sk_atomic_inc(&gPathRefGenerationID) + 1) & kMa sk; 438 fGenerationID = (sk_atomic_inc(&gPathRefGenerationID) + 1) & kMa sk;
435 } while (fGenerationID <= kEmptyGenID); 439 } while (fGenerationID <= kEmptyGenID);
436 } 440 }
437 } 441 }
438 return fGenerationID; 442 return fGenerationID;
439 } 443 }
440 444
441 void SkPathRef::addGenIDChangeListener(GenIDChangeListener* listener) { 445 void SkPathRef::addGenIDChangeListener(GenIDChangeListener* listener) {
442 if (nullptr == listener || this == (SkPathRef*)empty) { 446 if (nullptr == listener || this == empty.get()) {
443 delete listener; 447 delete listener;
444 return; 448 return;
445 } 449 }
446 *fGenIDChangeListeners.append() = listener; 450 *fGenIDChangeListeners.append() = listener;
447 } 451 }
448 452
449 // we need to be called *before* the genID gets changed or zerod 453 // we need to be called *before* the genID gets changed or zerod
450 void SkPathRef::callGenIDChangeListeners() { 454 void SkPathRef::callGenIDChangeListeners() {
451 for (int i = 0; i < fGenIDChangeListeners.count(); i++) { 455 for (int i = 0; i < fGenIDChangeListeners.count(); i++) {
452 fGenIDChangeListeners[i]->onChange(); 456 fGenIDChangeListeners[i]->onChange();
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 break; 526 break;
523 default: 527 default:
524 SkDEBUGFAIL("Unknown Verb"); 528 SkDEBUGFAIL("Unknown Verb");
525 break; 529 break;
526 } 530 }
527 } 531 }
528 SkASSERT(mask == fSegmentMask); 532 SkASSERT(mask == fSegmentMask);
529 #endif // SK_DEBUG_PATH 533 #endif // SK_DEBUG_PATH
530 } 534 }
531 #endif 535 #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