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

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

Issue 1949313003: Reland of SkOncePtr -> SkOnce (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 7 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/SkTaskGroup.h » ('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 "SkOnce.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
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 SK_DECLARE_STATIC_ONCE_PTR(SkPathRef, empty); 48 static SkPathRef* gEmpty = nullptr;
49
49 SkPathRef* SkPathRef::CreateEmpty() { 50 SkPathRef* SkPathRef::CreateEmpty() {
50 return SkRef(empty.get([]{ 51 static SkOnce once;
51 SkPathRef* pr = new SkPathRef; 52 once([]{
52 pr->computeBounds(); // Avoids races later to be the first to do this. 53 gEmpty = new SkPathRef;
53 return pr; 54 gEmpty->computeBounds(); // Avoids races later to be the first to do t his.
54 })); 55 });
56 return SkRef(gEmpty);
55 } 57 }
56 58
57 void SkPathRef::CreateTransformedCopy(SkAutoTUnref<SkPathRef>* dst, 59 void SkPathRef::CreateTransformedCopy(SkAutoTUnref<SkPathRef>* dst,
58 const SkPathRef& src, 60 const SkPathRef& src,
59 const SkMatrix& matrix) { 61 const SkMatrix& matrix) {
60 SkDEBUGCODE(src.validate();) 62 SkDEBUGCODE(src.validate();)
61 if (matrix.isIdentity()) { 63 if (matrix.isIdentity()) {
62 if (*dst != &src) { 64 if (*dst != &src) {
63 src.ref(); 65 src.ref();
64 dst->reset(const_cast<SkPathRef*>(&src)); 66 dst->reset(const_cast<SkPathRef*>(&src));
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 // empty ID 464 // empty ID
463 do { 465 do {
464 fGenerationID = (sk_atomic_inc(&gPathRefGenerationID) + 1) & kMa sk; 466 fGenerationID = (sk_atomic_inc(&gPathRefGenerationID) + 1) & kMa sk;
465 } while (fGenerationID <= kEmptyGenID); 467 } while (fGenerationID <= kEmptyGenID);
466 } 468 }
467 } 469 }
468 return fGenerationID; 470 return fGenerationID;
469 } 471 }
470 472
471 void SkPathRef::addGenIDChangeListener(GenIDChangeListener* listener) { 473 void SkPathRef::addGenIDChangeListener(GenIDChangeListener* listener) {
472 if (nullptr == listener || this == (SkPathRef*)empty) { 474 if (nullptr == listener || this == gEmpty) {
473 delete listener; 475 delete listener;
474 return; 476 return;
475 } 477 }
476 *fGenIDChangeListeners.append() = listener; 478 *fGenIDChangeListeners.append() = listener;
477 } 479 }
478 480
479 // we need to be called *before* the genID gets changed or zerod 481 // we need to be called *before* the genID gets changed or zerod
480 void SkPathRef::callGenIDChangeListeners() { 482 void SkPathRef::callGenIDChangeListeners() {
481 for (int i = 0; i < fGenIDChangeListeners.count(); i++) { 483 for (int i = 0; i < fGenIDChangeListeners.count(); i++) {
482 fGenIDChangeListeners[i]->onChange(); 484 fGenIDChangeListeners[i]->onChange();
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 break; 669 break;
668 default: 670 default:
669 SkDEBUGFAIL("Unknown Verb"); 671 SkDEBUGFAIL("Unknown Verb");
670 break; 672 break;
671 } 673 }
672 } 674 }
673 SkASSERT(mask == fSegmentMask); 675 SkASSERT(mask == fSegmentMask);
674 #endif // SK_DEBUG_PATH 676 #endif // SK_DEBUG_PATH
675 } 677 }
676 #endif 678 #endif
OLDNEW
« no previous file with comments | « src/core/SkMiniRecorder.cpp ('k') | src/core/SkTaskGroup.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698