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

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

Issue 25716003: Make it explicit that some validate methods are debug only ... (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 2 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 | « no previous file | include/core/SkRefCnt.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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 SkPoint* atPoint(int i) { 57 SkPoint* atPoint(int i) {
58 SkASSERT((unsigned) i < (unsigned) fPathRef->fPointCnt); 58 SkASSERT((unsigned) i < (unsigned) fPathRef->fPointCnt);
59 return this->points() + i; 59 return this->points() + i;
60 }; 60 };
61 61
62 /** 62 /**
63 * Adds the verb and allocates space for the number of points indicated by the verb. The 63 * Adds the verb and allocates space for the number of points indicated by the verb. The
64 * return value is a pointer to where the points for the verb should be written. 64 * return value is a pointer to where the points for the verb should be written.
65 */ 65 */
66 SkPoint* growForVerb(int /*SkPath::Verb*/ verb) { 66 SkPoint* growForVerb(int /*SkPath::Verb*/ verb) {
67 fPathRef->validate(); 67 SkDEBUGCODE(fPathRef->validate();)
68 return fPathRef->growForVerb(verb); 68 return fPathRef->growForVerb(verb);
69 } 69 }
70 70
71 SkPoint* growForConic(SkScalar w); 71 SkPoint* growForConic(SkScalar w);
72 72
73 /** 73 /**
74 * Allocates space for additional verbs and points and returns pointers to the new verbs and 74 * Allocates space for additional verbs and points and returns pointers to the new verbs and
75 * points. verbs will point one beyond the first new verb (index it usin g [~<i>]). pts points 75 * points. verbs will point one beyond the first new verb (index it usin g [~<i>]). pts points
76 * at the first new point (indexed normally [<i>]). 76 * at the first new point (indexed normally [<i>]).
77 */ 77 */
78 void grow(int newVerbs, int newPts, uint8_t** verbs, SkPoint** pts) { 78 void grow(int newVerbs, int newPts, uint8_t** verbs, SkPoint** pts) {
79 SkASSERT(NULL != verbs); 79 SkASSERT(NULL != verbs);
80 SkASSERT(NULL != pts); 80 SkASSERT(NULL != pts);
81 fPathRef->validate(); 81 SkDEBUGCODE(fPathRef->validate();)
82 int oldVerbCnt = fPathRef->fVerbCnt; 82 int oldVerbCnt = fPathRef->fVerbCnt;
83 int oldPointCnt = fPathRef->fPointCnt; 83 int oldPointCnt = fPathRef->fPointCnt;
84 SkASSERT(verbs && pts); 84 SkASSERT(verbs && pts);
85 fPathRef->grow(newVerbs, newPts); 85 fPathRef->grow(newVerbs, newPts);
86 *verbs = fPathRef->fVerbs - oldVerbCnt; 86 *verbs = fPathRef->fVerbs - oldVerbCnt;
87 *pts = fPathRef->fPoints + oldPointCnt; 87 *pts = fPathRef->fPoints + oldPointCnt;
88 fPathRef->validate(); 88 SkDEBUGCODE(fPathRef->validate();)
89 } 89 }
90 90
91 /** 91 /**
92 * Resets the path ref to a new verb and point count. The new verbs and points are 92 * Resets the path ref to a new verb and point count. The new verbs and points are
93 * uninitialized. 93 * uninitialized.
94 */ 94 */
95 void resetToSize(int newVerbCnt, int newPointCnt, int newConicCount) { 95 void resetToSize(int newVerbCnt, int newPointCnt, int newConicCount) {
96 fPathRef->resetToSize(newVerbCnt, newPointCnt, newConicCount); 96 fPathRef->resetToSize(newVerbCnt, newPointCnt, newConicCount);
97 } 97 }
98 /** 98 /**
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 ); 164 );
165 165
166 /** 166 /**
167 * Rollsback a path ref to zero verbs and points with the assumption that th e path ref will be 167 * Rollsback a path ref to zero verbs and points with the assumption that th e path ref will be
168 * repopulated with approximately the same number of verbs and points. A new path ref is created 168 * repopulated with approximately the same number of verbs and points. A new path ref is created
169 * only if necessary. 169 * only if necessary.
170 */ 170 */
171 static void Rewind(SkAutoTUnref<SkPathRef>* pathRef); 171 static void Rewind(SkAutoTUnref<SkPathRef>* pathRef);
172 172
173 virtual ~SkPathRef() { 173 virtual ~SkPathRef() {
174 this->validate(); 174 SkDEBUGCODE(this->validate();)
175 sk_free(fPoints); 175 sk_free(fPoints);
176 176
177 SkDEBUGCODE(fPoints = NULL;) 177 SkDEBUGCODE(fPoints = NULL;)
178 SkDEBUGCODE(fVerbs = NULL;) 178 SkDEBUGCODE(fVerbs = NULL;)
179 SkDEBUGCODE(fVerbCnt = 0x9999999;) 179 SkDEBUGCODE(fVerbCnt = 0x9999999;)
180 SkDEBUGCODE(fPointCnt = 0xAAAAAAA;) 180 SkDEBUGCODE(fPointCnt = 0xAAAAAAA;)
181 SkDEBUGCODE(fPointCnt = 0xBBBBBBB;) 181 SkDEBUGCODE(fPointCnt = 0xBBBBBBB;)
182 SkDEBUGCODE(fGenerationID = 0xEEEEEEEE;) 182 SkDEBUGCODE(fGenerationID = 0xEEEEEEEE;)
183 SkDEBUGCODE(fEditorsAttached = 0x7777777;) 183 SkDEBUGCODE(fEditorsAttached = 0x7777777;)
184 } 184 }
185 185
186 int countPoints() const { this->validate(); return fPointCnt; } 186 int countPoints() const { SkDEBUGCODE(this->validate();) return fPointCnt; }
187 int countVerbs() const { this->validate(); return fVerbCnt; } 187 int countVerbs() const { SkDEBUGCODE(this->validate();) return fVerbCnt; }
188 188
189 /** 189 /**
190 * Returns a pointer one beyond the first logical verb (last verb in memory order). 190 * Returns a pointer one beyond the first logical verb (last verb in memory order).
191 */ 191 */
192 const uint8_t* verbs() const { this->validate(); return fVerbs; } 192 const uint8_t* verbs() const { SkDEBUGCODE(this->validate();) return fVerbs; }
193 193
194 /** 194 /**
195 * Returns a const pointer to the first verb in memory (which is the last lo gical verb). 195 * Returns a const pointer to the first verb in memory (which is the last lo gical verb).
196 */ 196 */
197 const uint8_t* verbsMemBegin() const { return this->verbs() - fVerbCnt; } 197 const uint8_t* verbsMemBegin() const { return this->verbs() - fVerbCnt; }
198 198
199 /** 199 /**
200 * Returns a const pointer to the first point. 200 * Returns a const pointer to the first point.
201 */ 201 */
202 const SkPoint* points() const { this->validate(); return fPoints; } 202 const SkPoint* points() const { SkDEBUGCODE(this->validate();) return fPoint s; }
203 203
204 /** 204 /**
205 * Shortcut for this->points() + this->countPoints() 205 * Shortcut for this->points() + this->countPoints()
206 */ 206 */
207 const SkPoint* pointsEnd() const { return this->points() + this->countPoints (); } 207 const SkPoint* pointsEnd() const { return this->points() + this->countPoints (); }
208 208
209 const SkScalar* conicWeights() const { this->validate(); return fConicWeight s.begin(); } 209 const SkScalar* conicWeights() const { SkDEBUGCODE(this->validate();) return fConicWeights.begin(); }
210 const SkScalar* conicWeightsEnd() const { this->validate(); return fConicWei ghts.end(); } 210 const SkScalar* conicWeightsEnd() const { SkDEBUGCODE(this->validate();) ret urn fConicWeights.end(); }
211 211
212 /** 212 /**
213 * Convenience methods for getting to a verb or point by index. 213 * Convenience methods for getting to a verb or point by index.
214 */ 214 */
215 uint8_t atVerb(int index) { 215 uint8_t atVerb(int index) {
216 SkASSERT((unsigned) index < (unsigned) fVerbCnt); 216 SkASSERT((unsigned) index < (unsigned) fVerbCnt);
217 return this->verbs()[~index]; 217 return this->verbs()[~index];
218 } 218 }
219 const SkPoint& atPoint(int index) const { 219 const SkPoint& atPoint(int index) const {
220 SkASSERT((unsigned) index < (unsigned) fPointCnt); 220 SkASSERT((unsigned) index < (unsigned) fPointCnt);
(...skipping 19 matching lines...) Expand all
240 240
241 SkPathRef() { 241 SkPathRef() {
242 fBoundsIsDirty = true; // this also invalidates fIsFinite 242 fBoundsIsDirty = true; // this also invalidates fIsFinite
243 fPointCnt = 0; 243 fPointCnt = 0;
244 fVerbCnt = 0; 244 fVerbCnt = 0;
245 fVerbs = NULL; 245 fVerbs = NULL;
246 fPoints = NULL; 246 fPoints = NULL;
247 fFreeSpace = 0; 247 fFreeSpace = 0;
248 fGenerationID = kEmptyGenID; 248 fGenerationID = kEmptyGenID;
249 SkDEBUGCODE(fEditorsAttached = 0;) 249 SkDEBUGCODE(fEditorsAttached = 0;)
250 this->validate(); 250 SkDEBUGCODE(this->validate();)
251 } 251 }
252 252
253 void copy(const SkPathRef& ref, int additionalReserveVerbs, int additionalRe servePoints); 253 void copy(const SkPathRef& ref, int additionalReserveVerbs, int additionalRe servePoints);
254 254
255 // Return true if the computed bounds are finite. 255 // Return true if the computed bounds are finite.
256 static bool ComputePtBounds(SkRect* bounds, const SkPathRef& ref) { 256 static bool ComputePtBounds(SkRect* bounds, const SkPathRef& ref) {
257 int count = ref.countPoints(); 257 int count = ref.countPoints();
258 if (count <= 1) { // we ignore just 1 point (moveto) 258 if (count <= 1) { // we ignore just 1 point (moveto)
259 bounds->setEmpty(); 259 bounds->setEmpty();
260 return count ? ref.points()->isFinite() : true; 260 return count ? ref.points()->isFinite() : true;
261 } else { 261 } else {
262 return bounds->setBoundsCheck(ref.points(), count); 262 return bounds->setBoundsCheck(ref.points(), count);
263 } 263 }
264 } 264 }
265 265
266 // called, if dirty, by getBounds() 266 // called, if dirty, by getBounds()
267 void computeBounds() const { 267 void computeBounds() const {
268 SkDEBUGCODE(this->validate();) 268 SkDEBUGCODE(this->validate();)
269 SkASSERT(fBoundsIsDirty); 269 SkASSERT(fBoundsIsDirty);
270 270
271 fIsFinite = ComputePtBounds(&fBounds, *this); 271 fIsFinite = ComputePtBounds(&fBounds, *this);
272 fBoundsIsDirty = false; 272 fBoundsIsDirty = false;
273 } 273 }
274 274
275 /** Makes additional room but does not change the counts or change the genID */ 275 /** Makes additional room but does not change the counts or change the genID */
276 void incReserve(int additionalVerbs, int additionalPoints) { 276 void incReserve(int additionalVerbs, int additionalPoints) {
277 this->validate(); 277 SkDEBUGCODE(this->validate();)
278 size_t space = additionalVerbs * sizeof(uint8_t) + additionalPoints * si zeof (SkPoint); 278 size_t space = additionalVerbs * sizeof(uint8_t) + additionalPoints * si zeof (SkPoint);
279 this->makeSpace(space); 279 this->makeSpace(space);
280 this->validate(); 280 SkDEBUGCODE(this->validate();)
281 } 281 }
282 282
283 /** Resets the path ref with verbCount verbs and pointCount points, all unin itialized. Also 283 /** Resets the path ref with verbCount verbs and pointCount points, all unin itialized. Also
284 * allocates space for reserveVerb additional verbs and reservePoints addit ional points.*/ 284 * allocates space for reserveVerb additional verbs and reservePoints addit ional points.*/
285 void resetToSize(int verbCount, int pointCount, int conicCount, 285 void resetToSize(int verbCount, int pointCount, int conicCount,
286 int reserveVerbs = 0, int reservePoints = 0); 286 int reserveVerbs = 0, int reservePoints = 0);
287 287
288 /** 288 /**
289 * Increases the verb count by newVerbs and the point count be newPoints. Ne w verbs and points 289 * Increases the verb count by newVerbs and the point count be newPoints. Ne w verbs and points
290 * are uninitialized. 290 * are uninitialized.
291 */ 291 */
292 void grow(int newVerbs, int newPoints) { 292 void grow(int newVerbs, int newPoints) {
293 this->validate(); 293 SkDEBUGCODE(this->validate();)
294 size_t space = newVerbs * sizeof(uint8_t) + newPoints * sizeof (SkPoint) ; 294 size_t space = newVerbs * sizeof(uint8_t) + newPoints * sizeof (SkPoint) ;
295 this->makeSpace(space); 295 this->makeSpace(space);
296 fVerbCnt += newVerbs; 296 fVerbCnt += newVerbs;
297 fPointCnt += newPoints; 297 fPointCnt += newPoints;
298 fFreeSpace -= space; 298 fFreeSpace -= space;
299 fBoundsIsDirty = true; // this also invalidates fIsFinite 299 fBoundsIsDirty = true; // this also invalidates fIsFinite
300 this->validate(); 300 SkDEBUGCODE(this->validate();)
301 } 301 }
302 302
303 /** 303 /**
304 * Increases the verb count 1, records the new verb, and creates room for th e requisite number 304 * Increases the verb count 1, records the new verb, and creates room for th e requisite number
305 * of additional points. A pointer to the first point is returned. Any new p oints are 305 * of additional points. A pointer to the first point is returned. Any new p oints are
306 * uninitialized. 306 * uninitialized.
307 */ 307 */
308 SkPoint* growForVerb(int /*SkPath::Verb*/ verb); 308 SkPoint* growForVerb(int /*SkPath::Verb*/ verb);
309 309
310 /** 310 /**
311 * Ensures that the free space available in the path ref is >= size. The ver b and point counts 311 * Ensures that the free space available in the path ref is >= size. The ver b and point counts
312 * are not changed. 312 * are not changed.
313 */ 313 */
314 void makeSpace(size_t size); 314 void makeSpace(size_t size);
315 315
316 /** 316 /**
317 * Private, non-const-ptr version of the public function verbsMemBegin(). 317 * Private, non-const-ptr version of the public function verbsMemBegin().
318 */ 318 */
319 uint8_t* verbsMemWritable() { 319 uint8_t* verbsMemWritable() {
320 this->validate(); 320 SkDEBUGCODE(this->validate();)
321 return fVerbs - fVerbCnt; 321 return fVerbs - fVerbCnt;
322 } 322 }
323 323
324 /** 324 /**
325 * Gets the total amount of space allocated for verbs, points, and reserve. 325 * Gets the total amount of space allocated for verbs, points, and reserve.
326 */ 326 */
327 size_t currSize() const { 327 size_t currSize() const {
328 return reinterpret_cast<intptr_t>(fVerbs) - reinterpret_cast<intptr_t>(f Points); 328 return reinterpret_cast<intptr_t>(fVerbs) - reinterpret_cast<intptr_t>(f Points);
329 } 329 }
330 330
331 /** 331 /**
332 * Gets an ID that uniquely identifies the contents of the path ref. If two path refs have the 332 * Gets an ID that uniquely identifies the contents of the path ref. If two path refs have the
333 * same ID then they have the same verbs and points. However, two path refs may have the same 333 * same ID then they have the same verbs and points. However, two path refs may have the same
334 * contents but different genIDs. Zero is reserved and means an ID has not y et been determined 334 * contents but different genIDs. Zero is reserved and means an ID has not y et been determined
335 * for the path ref. 335 * for the path ref.
336 */ 336 */
337 int32_t genID() const; 337 int32_t genID() const;
338 338
339 void validate() const; 339 SkDEBUGCODE(void validate() const;)
340 340
341 enum { 341 enum {
342 kMinSize = 256, 342 kMinSize = 256,
343 }; 343 };
344 344
345 mutable SkRect fBounds; 345 mutable SkRect fBounds;
346 mutable uint8_t fBoundsIsDirty; 346 mutable uint8_t fBoundsIsDirty;
347 mutable SkBool8 fIsFinite; // only meaningful if bounds are valid 347 mutable SkBool8 fIsFinite; // only meaningful if bounds are valid
348 348
349 SkPoint* fPoints; // points to begining of the allocation 349 SkPoint* fPoints; // points to begining of the allocation
350 uint8_t* fVerbs; // points just past the end of the allocation (v erbs grow backwards) 350 uint8_t* fVerbs; // points just past the end of the allocation (v erbs grow backwards)
351 int fVerbCnt; 351 int fVerbCnt;
352 int fPointCnt; 352 int fPointCnt;
353 size_t fFreeSpace; // redundant but saves computation 353 size_t fFreeSpace; // redundant but saves computation
354 SkTDArray<SkScalar> fConicWeights; 354 SkTDArray<SkScalar> fConicWeights;
355 355
356 enum { 356 enum {
357 kEmptyGenID = 1, // GenID reserved for path ref with zero points and zer o verbs. 357 kEmptyGenID = 1, // GenID reserved for path ref with zero points and zer o verbs.
358 }; 358 };
359 mutable int32_t fGenerationID; 359 mutable int32_t fGenerationID;
360 SkDEBUGCODE(int32_t fEditorsAttached;) // assert that only one editor in use at any time. 360 SkDEBUGCODE(int32_t fEditorsAttached;) // assert that only one editor in use at any time.
361 361
362 typedef SkRefCnt INHERITED; 362 typedef SkRefCnt INHERITED;
363 }; 363 };
364 364
365 #endif 365 #endif
OLDNEW
« no previous file with comments | « no previous file | include/core/SkRefCnt.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698