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

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

Issue 105083003: Move segment mask from SkPath to SkPathRef (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: switched growForRepeatedVerb to return conic weight pointer Created 7 years 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/SkPath.h ('k') | src/core/SkPath.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 /* 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 * Gets the ith point. Shortcut for this->points() + i 55 * Gets the ith point. Shortcut for this->points() + i
56 */ 56 */
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 * 'weight' is only used if 'verb' is kConic_Verb
65 */ 66 */
66 SkPoint* growForVerb(int /*SkPath::Verb*/ verb) { 67 SkPoint* growForVerb(int /*SkPath::Verb*/ verb, SkScalar weight = 0) {
67 SkDEBUGCODE(fPathRef->validate();) 68 SkDEBUGCODE(fPathRef->validate();)
68 return fPathRef->growForVerb(verb); 69 return fPathRef->growForVerb(verb, weight);
69 }
70
71 SkPoint* growForConic(SkScalar w);
72
73 /**
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
76 * at the first new point (indexed normally [<i>]).
77 */
78 void grow(int newVerbs, int newPts, uint8_t** verbs, SkPoint** pts) {
79 SkASSERT(NULL != verbs);
80 SkASSERT(NULL != pts);
81 SkDEBUGCODE(fPathRef->validate();)
82 int oldVerbCnt = fPathRef->fVerbCnt;
83 int oldPointCnt = fPathRef->fPointCnt;
84 SkASSERT(verbs && pts);
85 fPathRef->grow(newVerbs, newPts);
86 *verbs = fPathRef->fVerbs - oldVerbCnt;
87 *pts = fPathRef->fPoints + oldPointCnt;
88 SkDEBUGCODE(fPathRef->validate();)
89 } 70 }
90 71
91 /** 72 /**
73 * Allocates space for multiple instances of a particular verb and the
74 * requisite points & weights.
75 * The return pointer points at the first new point (indexed normally [< i>]).
76 * If 'verb' is kConic_Verb, 'weights' will return a pointer to the
77 * space for the conic weights (indexed normally).
78 */
79 SkPoint* growForRepeatedVerb(int /*SkPath::Verb*/ verb,
80 int numVbs,
81 SkScalar** weights = NULL) {
82 return fPathRef->growForRepeatedVerb(verb, numVbs, weights);
83 }
84
85 /**
92 * Resets the path ref to a new verb and point count. The new verbs and points are 86 * Resets the path ref to a new verb and point count. The new verbs and points are
93 * uninitialized. 87 * uninitialized.
94 */ 88 */
95 void resetToSize(int newVerbCnt, int newPointCnt, int newConicCount) { 89 void resetToSize(int newVerbCnt, int newPointCnt, int newConicCount) {
96 fPathRef->resetToSize(newVerbCnt, newPointCnt, newConicCount); 90 fPathRef->resetToSize(newVerbCnt, newPointCnt, newConicCount);
97 } 91 }
98 /** 92 /**
99 * Gets the path ref that is wrapped in the Editor. 93 * Gets the path ref that is wrapped in the Editor.
100 */ 94 */
101 SkPathRef* pathRef() { return fPathRef; } 95 SkPathRef* pathRef() { return fPathRef; }
(...skipping 14 matching lines...) Expand all
116 * Returns true if all of the points in this path are finite, meaning there 110 * Returns true if all of the points in this path are finite, meaning there
117 * are no infinities and no NaNs. 111 * are no infinities and no NaNs.
118 */ 112 */
119 bool isFinite() const { 113 bool isFinite() const {
120 if (fBoundsIsDirty) { 114 if (fBoundsIsDirty) {
121 this->computeBounds(); 115 this->computeBounds();
122 } 116 }
123 return SkToBool(fIsFinite); 117 return SkToBool(fIsFinite);
124 } 118 }
125 119
120 /**
121 * Returns a mask, where each bit corresponding to a SegmentMask is
122 * set if the path contains 1 or more segments of that type.
123 * Returns 0 for an empty path (no segments).
124 */
125 uint32_t getSegmentMasks() const { return fSegmentMask; }
126
126 /** Returns true if the path is an oval. 127 /** Returns true if the path is an oval.
127 * 128 *
128 * @param rect returns the bounding rect of this oval. It's a circle 129 * @param rect returns the bounding rect of this oval. It's a circle
129 * if the height and width are the same. 130 * if the height and width are the same.
130 * 131 *
131 * @return true if this path is an oval. 132 * @return true if this path is an oval.
132 * Tracking whether a path is an oval is considered an 133 * Tracking whether a path is an oval is considered an
133 * optimization for performance and so some paths that are in 134 * optimization for performance and so some paths that are in
134 * fact ovals can report false. 135 * fact ovals can report false.
135 */ 136 */
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 SkDEBUGCODE(fVerbs = NULL;) 193 SkDEBUGCODE(fVerbs = NULL;)
193 SkDEBUGCODE(fVerbCnt = 0x9999999;) 194 SkDEBUGCODE(fVerbCnt = 0x9999999;)
194 SkDEBUGCODE(fPointCnt = 0xAAAAAAA;) 195 SkDEBUGCODE(fPointCnt = 0xAAAAAAA;)
195 SkDEBUGCODE(fPointCnt = 0xBBBBBBB;) 196 SkDEBUGCODE(fPointCnt = 0xBBBBBBB;)
196 SkDEBUGCODE(fGenerationID = 0xEEEEEEEE;) 197 SkDEBUGCODE(fGenerationID = 0xEEEEEEEE;)
197 SkDEBUGCODE(fEditorsAttached = 0x7777777;) 198 SkDEBUGCODE(fEditorsAttached = 0x7777777;)
198 } 199 }
199 200
200 int countPoints() const { SkDEBUGCODE(this->validate();) return fPointCnt; } 201 int countPoints() const { SkDEBUGCODE(this->validate();) return fPointCnt; }
201 int countVerbs() const { SkDEBUGCODE(this->validate();) return fVerbCnt; } 202 int countVerbs() const { SkDEBUGCODE(this->validate();) return fVerbCnt; }
203 int countWeights() const { SkDEBUGCODE(this->validate();) return fConicWeigh ts.count(); }
202 204
203 /** 205 /**
204 * Returns a pointer one beyond the first logical verb (last verb in memory order). 206 * Returns a pointer one beyond the first logical verb (last verb in memory order).
205 */ 207 */
206 const uint8_t* verbs() const { SkDEBUGCODE(this->validate();) return fVerbs; } 208 const uint8_t* verbs() const { SkDEBUGCODE(this->validate();) return fVerbs; }
207 209
208 /** 210 /**
209 * Returns a const pointer to the first verb in memory (which is the last lo gical verb). 211 * Returns a const pointer to the first verb in memory (which is the last lo gical verb).
210 */ 212 */
211 const uint8_t* verbsMemBegin() const { return this->verbs() - fVerbCnt; } 213 const uint8_t* verbsMemBegin() const { return this->verbs() - fVerbCnt; }
212 214
213 /** 215 /**
214 * Returns a const pointer to the first point. 216 * Returns a const pointer to the first point.
215 */ 217 */
216 const SkPoint* points() const { SkDEBUGCODE(this->validate();) return fPoint s; } 218 const SkPoint* points() const { SkDEBUGCODE(this->validate();) return fPoint s; }
217 219
218 /** 220 /**
219 * Shortcut for this->points() + this->countPoints() 221 * Shortcut for this->points() + this->countPoints()
220 */ 222 */
221 const SkPoint* pointsEnd() const { return this->points() + this->countPoints (); } 223 const SkPoint* pointsEnd() const { return this->points() + this->countPoints (); }
222 224
223 const SkScalar* conicWeights() const { SkDEBUGCODE(this->validate();) return fConicWeights.begin(); } 225 const SkScalar* conicWeights() const { SkDEBUGCODE(this->validate();) return fConicWeights.begin(); }
224 const SkScalar* conicWeightsEnd() const { SkDEBUGCODE(this->validate();) ret urn fConicWeights.end(); } 226 const SkScalar* conicWeightsEnd() const { SkDEBUGCODE(this->validate();) ret urn fConicWeights.end(); }
225 227
226 /** 228 /**
227 * Convenience methods for getting to a verb or point by index. 229 * Convenience methods for getting to a verb or point by index.
228 */ 230 */
229 uint8_t atVerb(int index) { 231 uint8_t atVerb(int index) const {
230 SkASSERT((unsigned) index < (unsigned) fVerbCnt); 232 SkASSERT((unsigned) index < (unsigned) fVerbCnt);
231 return this->verbs()[~index]; 233 return this->verbs()[~index];
232 } 234 }
233 const SkPoint& atPoint(int index) const { 235 const SkPoint& atPoint(int index) const {
234 SkASSERT((unsigned) index < (unsigned) fPointCnt); 236 SkASSERT((unsigned) index < (unsigned) fPointCnt);
235 return this->points()[index]; 237 return this->points()[index];
236 } 238 }
237 239
238 bool operator== (const SkPathRef& ref) const; 240 bool operator== (const SkPathRef& ref) const;
239 241
240 /** 242 /**
241 * Writes the path points and verbs to a buffer. 243 * Writes the path points and verbs to a buffer.
242 */ 244 */
243 void writeToBuffer(SkWBuffer* buffer); 245 void writeToBuffer(SkWBuffer* buffer) const;
244 246
245 /** 247 /**
246 * Gets the number of bytes that would be written in writeBuffer() 248 * Gets the number of bytes that would be written in writeBuffer()
247 */ 249 */
248 uint32_t writeSize(); 250 uint32_t writeSize() const;
249 251
250 /** 252 /**
251 * Gets an ID that uniquely identifies the contents of the path ref. If two path refs have the 253 * Gets an ID that uniquely identifies the contents of the path ref. If two path refs have the
252 * same ID then they have the same verbs and points. However, two path refs may have the same 254 * same ID then they have the same verbs and points. However, two path refs may have the same
253 * contents but different genIDs. 255 * contents but different genIDs.
254 */ 256 */
255 uint32_t genID() const; 257 uint32_t genID() const;
256 258
257 private: 259 private:
258 enum SerializationOffsets { 260 enum SerializationOffsets {
259 kIsFinite_SerializationShift = 25, // requires 1 bit 261 kIsFinite_SerializationShift = 25, // requires 1 bit
260 kIsOval_SerializationShift = 24, // requires 1 bit 262 kIsOval_SerializationShift = 24, // requires 1 bit
263 kSegmentMask_SerializationShift = 0 // requires 4 bits
261 }; 264 };
262 265
263 SkPathRef() { 266 SkPathRef() {
264 fBoundsIsDirty = true; // this also invalidates fIsFinite 267 fBoundsIsDirty = true; // this also invalidates fIsFinite
265 fPointCnt = 0; 268 fPointCnt = 0;
266 fVerbCnt = 0; 269 fVerbCnt = 0;
267 fVerbs = NULL; 270 fVerbs = NULL;
268 fPoints = NULL; 271 fPoints = NULL;
269 fFreeSpace = 0; 272 fFreeSpace = 0;
270 fGenerationID = kEmptyGenID; 273 fGenerationID = kEmptyGenID;
274 fSegmentMask = 0;
271 fIsOval = false; 275 fIsOval = false;
272 SkDEBUGCODE(fEditorsAttached = 0;) 276 SkDEBUGCODE(fEditorsAttached = 0;)
273 SkDEBUGCODE(this->validate();) 277 SkDEBUGCODE(this->validate();)
274 } 278 }
275 279
276 void copy(const SkPathRef& ref, int additionalReserveVerbs, int additionalRe servePoints); 280 void copy(const SkPathRef& ref, int additionalReserveVerbs, int additionalRe servePoints);
277 281
278 // Return true if the computed bounds are finite. 282 // Return true if the computed bounds are finite.
279 static bool ComputePtBounds(SkRect* bounds, const SkPathRef& ref) { 283 static bool ComputePtBounds(SkRect* bounds, const SkPathRef& ref) {
280 int count = ref.countPoints(); 284 int count = ref.countPoints();
(...skipping 23 matching lines...) Expand all
304 } 308 }
305 309
306 /** Resets the path ref with verbCount verbs and pointCount points, all unin itialized. Also 310 /** Resets the path ref with verbCount verbs and pointCount points, all unin itialized. Also
307 * allocates space for reserveVerb additional verbs and reservePoints addit ional points.*/ 311 * allocates space for reserveVerb additional verbs and reservePoints addit ional points.*/
308 void resetToSize(int verbCount, int pointCount, int conicCount, 312 void resetToSize(int verbCount, int pointCount, int conicCount,
309 int reserveVerbs = 0, int reservePoints = 0) { 313 int reserveVerbs = 0, int reservePoints = 0) {
310 SkDEBUGCODE(this->validate();) 314 SkDEBUGCODE(this->validate();)
311 fBoundsIsDirty = true; // this also invalidates fIsFinite 315 fBoundsIsDirty = true; // this also invalidates fIsFinite
312 fGenerationID = 0; 316 fGenerationID = 0;
313 317
318 fSegmentMask = 0;
314 fIsOval = false; 319 fIsOval = false;
315 320
316 size_t newSize = sizeof(uint8_t) * verbCount + sizeof(SkPoint) * pointCo unt; 321 size_t newSize = sizeof(uint8_t) * verbCount + sizeof(SkPoint) * pointCo unt;
317 size_t newReserve = sizeof(uint8_t) * reserveVerbs + sizeof(SkPoint) * r eservePoints; 322 size_t newReserve = sizeof(uint8_t) * reserveVerbs + sizeof(SkPoint) * r eservePoints;
318 size_t minSize = newSize + newReserve; 323 size_t minSize = newSize + newReserve;
319 324
320 ptrdiff_t sizeDelta = this->currSize() - minSize; 325 ptrdiff_t sizeDelta = this->currSize() - minSize;
321 326
322 if (sizeDelta < 0 || static_cast<size_t>(sizeDelta) >= 3 * minSize) { 327 if (sizeDelta < 0 || static_cast<size_t>(sizeDelta) >= 3 * minSize) {
323 sk_free(fPoints); 328 sk_free(fPoints);
324 fPoints = NULL; 329 fPoints = NULL;
325 fVerbs = NULL; 330 fVerbs = NULL;
326 fFreeSpace = 0; 331 fFreeSpace = 0;
327 fVerbCnt = 0; 332 fVerbCnt = 0;
328 fPointCnt = 0; 333 fPointCnt = 0;
329 this->makeSpace(minSize); 334 this->makeSpace(minSize);
330 fVerbCnt = verbCount; 335 fVerbCnt = verbCount;
331 fPointCnt = pointCount; 336 fPointCnt = pointCount;
332 fFreeSpace -= newSize; 337 fFreeSpace -= newSize;
333 } else { 338 } else {
334 fPointCnt = pointCount; 339 fPointCnt = pointCount;
335 fVerbCnt = verbCount; 340 fVerbCnt = verbCount;
336 fFreeSpace = this->currSize() - minSize; 341 fFreeSpace = this->currSize() - minSize;
337 } 342 }
338 fConicWeights.setCount(conicCount); 343 fConicWeights.setCount(conicCount);
339 SkDEBUGCODE(this->validate();) 344 SkDEBUGCODE(this->validate();)
340 } 345 }
341 346
342 /** 347 /**
343 * Increases the verb count by newVerbs and the point count be newPoints. Ne w verbs and points 348 * Increases the verb count by numVbs and point count by the required amount .
344 * are uninitialized. 349 * The new points are uninitialized. All the new verbs are set to the specif ied
350 * verb. If 'verb' is kConic_Verb, 'weights' will return a pointer to the
351 * uninitialized conic weights.
345 */ 352 */
346 void grow(int newVerbs, int newPoints) { 353 SkPoint* growForRepeatedVerb(int /*SkPath::Verb*/ verb, int numVbs, SkScalar ** weights);
347 SkDEBUGCODE(this->validate();)
348 size_t space = newVerbs * sizeof(uint8_t) + newPoints * sizeof (SkPoint) ;
349 this->makeSpace(space);
350 fVerbCnt += newVerbs;
351 fPointCnt += newPoints;
352 fFreeSpace -= space;
353 fBoundsIsDirty = true; // this also invalidates fIsFinite
354 SkDEBUGCODE(this->validate();)
355 }
356 354
357 /** 355 /**
358 * Increases the verb count 1, records the new verb, and creates room for th e requisite number 356 * Increases the verb count 1, records the new verb, and creates room for th e requisite number
359 * of additional points. A pointer to the first point is returned. Any new p oints are 357 * of additional points. A pointer to the first point is returned. Any new p oints are
360 * uninitialized. 358 * uninitialized.
361 */ 359 */
362 SkPoint* growForVerb(int /*SkPath::Verb*/ verb); 360 SkPoint* growForVerb(int /*SkPath::Verb*/ verb, SkScalar weight);
363 361
364 /** 362 /**
365 * Ensures that the free space available in the path ref is >= size. The ver b and point counts 363 * Ensures that the free space available in the path ref is >= size. The ver b and point counts
366 * are not changed. 364 * are not changed.
367 */ 365 */
368 void makeSpace(size_t size) { 366 void makeSpace(size_t size) {
369 SkDEBUGCODE(this->validate();) 367 SkDEBUGCODE(this->validate();)
370 ptrdiff_t growSize = size - fFreeSpace; 368 ptrdiff_t growSize = size - fFreeSpace;
371 if (growSize <= 0) { 369 if (growSize <= 0) {
372 return; 370 return;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 */ 416 */
419 static void CreateEmptyImpl(SkPathRef** empty); 417 static void CreateEmptyImpl(SkPathRef** empty);
420 418
421 void setIsOval(bool isOval) { fIsOval = isOval; } 419 void setIsOval(bool isOval) { fIsOval = isOval; }
422 420
423 enum { 421 enum {
424 kMinSize = 256, 422 kMinSize = 256,
425 }; 423 };
426 424
427 mutable SkRect fBounds; 425 mutable SkRect fBounds;
426 uint8_t fSegmentMask;
428 mutable uint8_t fBoundsIsDirty; 427 mutable uint8_t fBoundsIsDirty;
429 mutable SkBool8 fIsFinite; // only meaningful if bounds are valid 428 mutable SkBool8 fIsFinite; // only meaningful if bounds are valid
430 mutable SkBool8 fIsOval; 429 mutable SkBool8 fIsOval;
431 430
432 SkPoint* fPoints; // points to begining of the allocation 431 SkPoint* fPoints; // points to begining of the allocation
433 uint8_t* fVerbs; // points just past the end of the allocation (v erbs grow backwards) 432 uint8_t* fVerbs; // points just past the end of the allocation (v erbs grow backwards)
434 int fVerbCnt; 433 int fVerbCnt;
435 int fPointCnt; 434 int fPointCnt;
436 size_t fFreeSpace; // redundant but saves computation 435 size_t fFreeSpace; // redundant but saves computation
437 SkTDArray<SkScalar> fConicWeights; 436 SkTDArray<SkScalar> fConicWeights;
438 437
439 enum { 438 enum {
440 kEmptyGenID = 1, // GenID reserved for path ref with zero points and zer o verbs. 439 kEmptyGenID = 1, // GenID reserved for path ref with zero points and zer o verbs.
441 }; 440 };
442 mutable uint32_t fGenerationID; 441 mutable uint32_t fGenerationID;
443 SkDEBUGCODE(int32_t fEditorsAttached;) // assert that only one editor in use at any time. 442 SkDEBUGCODE(int32_t fEditorsAttached;) // assert that only one editor in use at any time.
444 443
445 typedef SkRefCnt INHERITED; 444 typedef SkRefCnt INHERITED;
446 }; 445 };
447 446
448 #endif 447 #endif
OLDNEW
« no previous file with comments | « include/core/SkPath.h ('k') | src/core/SkPath.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698