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

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

Issue 18770007: Add a 'unique' method to SkRefCnt, document the usage, and add support. (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Update comments. Created 7 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « include/core/SkRefCnt.h ('k') | src/core/SkTRefArray.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 /* 2 /*
3 * Copyright 2012 Google Inc. 3 * Copyright 2012 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 #ifndef SkPathRef_DEFINED 9 #ifndef SkPathRef_DEFINED
10 #define SkPathRef_DEFINED 10 #define SkPathRef_DEFINED
(...skipping 19 matching lines...) Expand all
30 class SkPathRef; 30 class SkPathRef;
31 31
32 class SkPathRef : public ::SkRefCnt { 32 class SkPathRef : public ::SkRefCnt {
33 public: 33 public:
34 SK_DECLARE_INST_COUNT(SkPathRef); 34 SK_DECLARE_INST_COUNT(SkPathRef);
35 35
36 class Editor { 36 class Editor {
37 public: 37 public:
38 Editor(SkAutoTUnref<SkPathRef>* pathRef, 38 Editor(SkAutoTUnref<SkPathRef>* pathRef,
39 int incReserveVerbs = 0, 39 int incReserveVerbs = 0,
40 int incReservePoints = 0) { 40 int incReservePoints = 0)
41 if (pathRef->get()->getRefCnt() > 1) { 41 {
42 if ((*pathRef)->unique()) {
43 (*pathRef)->incReserve(incReserveVerbs, incReservePoints);
44 } else {
42 SkPathRef* copy = SkNEW(SkPathRef); 45 SkPathRef* copy = SkNEW(SkPathRef);
43 copy->copy(*pathRef->get(), incReserveVerbs, incReservePoints); 46 copy->copy(**pathRef, incReserveVerbs, incReservePoints);
44 pathRef->reset(copy); 47 pathRef->reset(copy);
45 } else {
46 (*pathRef)->incReserve(incReserveVerbs, incReservePoints);
47 } 48 }
48 fPathRef = pathRef->get(); 49 fPathRef = *pathRef;
49 fPathRef->fGenerationID = 0; 50 fPathRef->fGenerationID = 0;
50 SkDEBUGCODE(sk_atomic_inc(&fPathRef->fEditorsAttached);) 51 SkDEBUGCODE(sk_atomic_inc(&fPathRef->fEditorsAttached);)
51 } 52 }
52 53
53 ~Editor() { SkDEBUGCODE(sk_atomic_dec(&fPathRef->fEditorsAttached);) } 54 ~Editor() { SkDEBUGCODE(sk_atomic_dec(&fPathRef->fEditorsAttached);) }
54 55
55 /** 56 /**
56 * Returns the array of points. 57 * Returns the array of points.
57 */ 58 */
58 SkPoint* points() { return fPathRef->fPoints; } 59 SkPoint* points() { return fPathRef->fPoints; }
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 } 129 }
129 130
130 /** 131 /**
131 * Transforms a path ref by a matrix, allocating a new one only if necessary . 132 * Transforms a path ref by a matrix, allocating a new one only if necessary .
132 */ 133 */
133 static void CreateTransformedCopy(SkAutoTUnref<SkPathRef>* dst, 134 static void CreateTransformedCopy(SkAutoTUnref<SkPathRef>* dst,
134 const SkPathRef& src, 135 const SkPathRef& src,
135 const SkMatrix& matrix) { 136 const SkMatrix& matrix) {
136 src.validate(); 137 src.validate();
137 if (matrix.isIdentity()) { 138 if (matrix.isIdentity()) {
138 if (dst->get() != &src) { 139 if (*dst != &src) {
139 src.ref(); 140 src.ref();
140 dst->reset(const_cast<SkPathRef*>(&src)); 141 dst->reset(const_cast<SkPathRef*>(&src));
141 (*dst)->validate(); 142 (*dst)->validate();
142 } 143 }
143 return; 144 return;
144 } 145 }
145 int32_t rcnt = dst->get()->getRefCnt(); 146 bool dstUnique = (*dst)->unique();
146 if (&src == dst->get() && 1 == rcnt) { 147 if (&src == *dst && dstUnique) {
147 matrix.mapPoints((*dst)->fPoints, (*dst)->fPointCnt); 148 matrix.mapPoints((*dst)->fPoints, (*dst)->fPointCnt);
148 return; 149 return;
149 } else if (rcnt > 1) { 150 } else if (!dstUnique) {
150 dst->reset(SkNEW(SkPathRef)); 151 dst->reset(SkNEW(SkPathRef));
151 } 152 }
152 (*dst)->resetToSize(src.fVerbCnt, src.fPointCnt, src.fConicWeights.count ()); 153 (*dst)->resetToSize(src.fVerbCnt, src.fPointCnt, src.fConicWeights.count ());
153 memcpy((*dst)->verbsMemWritable(), src.verbsMemBegin(), src.fVerbCnt * s izeof(uint8_t)); 154 memcpy((*dst)->verbsMemWritable(), src.verbsMemBegin(), src.fVerbCnt * s izeof(uint8_t));
154 matrix.mapPoints((*dst)->fPoints, src.points(), src.fPointCnt); 155 matrix.mapPoints((*dst)->fPoints, src.points(), src.fPointCnt);
155 (*dst)->fConicWeights = src.fConicWeights; 156 (*dst)->fConicWeights = src.fConicWeights;
156 (*dst)->validate(); 157 (*dst)->validate();
157 } 158 }
158 159
159 static SkPathRef* CreateFromBuffer(SkRBuffer* buffer) { 160 static SkPathRef* CreateFromBuffer(SkRBuffer* buffer) {
(...skipping 12 matching lines...) Expand all
172 buffer->read(ref->fConicWeights.begin(), conicCount * sizeof(SkScalar)); 173 buffer->read(ref->fConicWeights.begin(), conicCount * sizeof(SkScalar));
173 return ref; 174 return ref;
174 } 175 }
175 176
176 /** 177 /**
177 * Rollsback a path ref to zero verbs and points with the assumption that th e path ref will be 178 * Rollsback a path ref to zero verbs and points with the assumption that th e path ref will be
178 * repopulated with approximately the same number of verbs and points. A new path ref is created 179 * repopulated with approximately the same number of verbs and points. A new path ref is created
179 * only if necessary. 180 * only if necessary.
180 */ 181 */
181 static void Rewind(SkAutoTUnref<SkPathRef>* pathRef) { 182 static void Rewind(SkAutoTUnref<SkPathRef>* pathRef) {
182 if (1 == (*pathRef)->getRefCnt()) { 183 if ((*pathRef)->unique()) {
183 (*pathRef)->validate(); 184 (*pathRef)->validate();
184 (*pathRef)->fVerbCnt = 0; 185 (*pathRef)->fVerbCnt = 0;
185 (*pathRef)->fPointCnt = 0; 186 (*pathRef)->fPointCnt = 0;
186 (*pathRef)->fFreeSpace = (*pathRef)->currSize(); 187 (*pathRef)->fFreeSpace = (*pathRef)->currSize();
187 (*pathRef)->fGenerationID = 0; 188 (*pathRef)->fGenerationID = 0;
188 (*pathRef)->fConicWeights.rewind(); 189 (*pathRef)->fConicWeights.rewind();
189 (*pathRef)->validate(); 190 (*pathRef)->validate();
190 } else { 191 } else {
191 int oldVCnt = (*pathRef)->countVerbs(); 192 int oldVCnt = (*pathRef)->countVerbs();
192 int oldPCnt = (*pathRef)->countPoints(); 193 int oldPCnt = (*pathRef)->countPoints();
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 }; 542 };
542 mutable int32_t fGenerationID; 543 mutable int32_t fGenerationID;
543 SkDEBUGCODE(int32_t fEditorsAttached;) // assert that only one editor in use at any time. 544 SkDEBUGCODE(int32_t fEditorsAttached;) // assert that only one editor in use at any time.
544 545
545 typedef SkRefCnt INHERITED; 546 typedef SkRefCnt INHERITED;
546 }; 547 };
547 548
548 SK_DEFINE_INST_COUNT(SkPathRef); 549 SK_DEFINE_INST_COUNT(SkPathRef);
549 550
550 #endif 551 #endif
OLDNEW
« no previous file with comments | « include/core/SkRefCnt.h ('k') | src/core/SkTRefArray.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698