OLD | NEW |
---|---|
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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 SkDEBUGCODE(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 lines and returns a pointer to the new |
75 * points. verbs will point one beyond the first new verb (index it usin g [~<i>]). pts points | 75 * points. The return pointer points at the first new point (indexed nor mally [<i>]). |
76 * at the first new point (indexed normally [<i>]). | |
77 */ | 76 */ |
78 void grow(int newVerbs, int newPts, uint8_t** verbs, SkPoint** pts) { | 77 SkPoint* growForLines(int numLines) { return fPathRef->growForLines(numL ines); } |
bsalomon
2013/12/09 16:16:04
This feels a little weirdly specialized in SkPathR
robertphillips
2013/12/09 19:01:52
Done.
| |
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 } | |
90 | 78 |
91 /** | 79 /** |
92 * Resets the path ref to a new verb and point count. The new verbs and points are | 80 * Resets the path ref to a new verb and point count. The new verbs and points are |
93 * uninitialized. | 81 * uninitialized. |
94 */ | 82 */ |
95 void resetToSize(int newVerbCnt, int newPointCnt, int newConicCount) { | 83 void resetToSize(int newVerbCnt, int newPointCnt, int newConicCount) { |
96 fPathRef->resetToSize(newVerbCnt, newPointCnt, newConicCount); | 84 fPathRef->resetToSize(newVerbCnt, newPointCnt, newConicCount); |
97 } | 85 } |
98 /** | 86 /** |
99 * Gets the path ref that is wrapped in the Editor. | 87 * Gets the path ref that is wrapped in the Editor. |
(...skipping 16 matching lines...) Expand all Loading... | |
116 * Returns true if all of the points in this path are finite, meaning there | 104 * Returns true if all of the points in this path are finite, meaning there |
117 * are no infinities and no NaNs. | 105 * are no infinities and no NaNs. |
118 */ | 106 */ |
119 bool isFinite() const { | 107 bool isFinite() const { |
120 if (fBoundsIsDirty) { | 108 if (fBoundsIsDirty) { |
121 this->computeBounds(); | 109 this->computeBounds(); |
122 } | 110 } |
123 return SkToBool(fIsFinite); | 111 return SkToBool(fIsFinite); |
124 } | 112 } |
125 | 113 |
114 /** | |
115 * Returns a mask, where each bit corresponding to a SegmentMask is | |
116 * set if the path contains 1 or more segments of that type. | |
117 * Returns 0 for an empty path (no segments). | |
118 */ | |
119 uint32_t getSegmentMasks() const { return fSegmentMask; } | |
120 | |
126 /** Returns true if the path is an oval. | 121 /** Returns true if the path is an oval. |
127 * | 122 * |
128 * @param rect returns the bounding rect of this oval. It's a circle | 123 * @param rect returns the bounding rect of this oval. It's a circle |
129 * if the height and width are the same. | 124 * if the height and width are the same. |
130 * | 125 * |
131 * @return true if this path is an oval. | 126 * @return true if this path is an oval. |
132 * Tracking whether a path is an oval is considered an | 127 * Tracking whether a path is an oval is considered an |
133 * optimization for performance and so some paths that are in | 128 * optimization for performance and so some paths that are in |
134 * fact ovals can report false. | 129 * fact ovals can report false. |
135 */ | 130 */ |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
219 * Shortcut for this->points() + this->countPoints() | 214 * Shortcut for this->points() + this->countPoints() |
220 */ | 215 */ |
221 const SkPoint* pointsEnd() const { return this->points() + this->countPoints (); } | 216 const SkPoint* pointsEnd() const { return this->points() + this->countPoints (); } |
222 | 217 |
223 const SkScalar* conicWeights() const { SkDEBUGCODE(this->validate();) return fConicWeights.begin(); } | 218 const SkScalar* conicWeights() const { SkDEBUGCODE(this->validate();) return fConicWeights.begin(); } |
224 const SkScalar* conicWeightsEnd() const { SkDEBUGCODE(this->validate();) ret urn fConicWeights.end(); } | 219 const SkScalar* conicWeightsEnd() const { SkDEBUGCODE(this->validate();) ret urn fConicWeights.end(); } |
225 | 220 |
226 /** | 221 /** |
227 * Convenience methods for getting to a verb or point by index. | 222 * Convenience methods for getting to a verb or point by index. |
228 */ | 223 */ |
229 uint8_t atVerb(int index) { | 224 uint8_t atVerb(int index) const { |
230 SkASSERT((unsigned) index < (unsigned) fVerbCnt); | 225 SkASSERT((unsigned) index < (unsigned) fVerbCnt); |
231 return this->verbs()[~index]; | 226 return this->verbs()[~index]; |
232 } | 227 } |
233 const SkPoint& atPoint(int index) const { | 228 const SkPoint& atPoint(int index) const { |
234 SkASSERT((unsigned) index < (unsigned) fPointCnt); | 229 SkASSERT((unsigned) index < (unsigned) fPointCnt); |
235 return this->points()[index]; | 230 return this->points()[index]; |
236 } | 231 } |
237 | 232 |
238 bool operator== (const SkPathRef& ref) const; | 233 bool operator== (const SkPathRef& ref) const; |
239 | 234 |
240 /** | 235 /** |
241 * Writes the path points and verbs to a buffer. | 236 * Writes the path points and verbs to a buffer. |
242 */ | 237 */ |
243 void writeToBuffer(SkWBuffer* buffer); | 238 void writeToBuffer(SkWBuffer* buffer) const; |
244 | 239 |
245 /** | 240 /** |
246 * Gets the number of bytes that would be written in writeBuffer() | 241 * Gets the number of bytes that would be written in writeBuffer() |
247 */ | 242 */ |
248 uint32_t writeSize(); | 243 uint32_t writeSize() const; |
249 | 244 |
250 /** | 245 /** |
251 * Gets an ID that uniquely identifies the contents of the path ref. If two path refs have the | 246 * 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 | 247 * same ID then they have the same verbs and points. However, two path refs may have the same |
253 * contents but different genIDs. | 248 * contents but different genIDs. |
254 */ | 249 */ |
255 uint32_t genID() const; | 250 uint32_t genID() const; |
256 | 251 |
257 private: | 252 private: |
258 enum SerializationOffsets { | 253 enum SerializationOffsets { |
259 kIsFinite_SerializationShift = 25, // requires 1 bit | 254 kIsFinite_SerializationShift = 25, // requires 1 bit |
260 kIsOval_SerializationShift = 24, // requires 1 bit | 255 kIsOval_SerializationShift = 24, // requires 1 bit |
256 kSegmentMask_SerializationShift = 0 // requires 4 bits | |
261 }; | 257 }; |
262 | 258 |
263 SkPathRef() { | 259 SkPathRef() { |
264 fBoundsIsDirty = true; // this also invalidates fIsFinite | 260 fBoundsIsDirty = true; // this also invalidates fIsFinite |
265 fPointCnt = 0; | 261 fPointCnt = 0; |
266 fVerbCnt = 0; | 262 fVerbCnt = 0; |
267 fVerbs = NULL; | 263 fVerbs = NULL; |
268 fPoints = NULL; | 264 fPoints = NULL; |
269 fFreeSpace = 0; | 265 fFreeSpace = 0; |
270 fGenerationID = kEmptyGenID; | 266 fGenerationID = kEmptyGenID; |
267 fSegmentMask = 0; | |
271 fIsOval = false; | 268 fIsOval = false; |
272 SkDEBUGCODE(fEditorsAttached = 0;) | 269 SkDEBUGCODE(fEditorsAttached = 0;) |
273 SkDEBUGCODE(this->validate();) | 270 SkDEBUGCODE(this->validate();) |
274 } | 271 } |
275 | 272 |
276 void copy(const SkPathRef& ref, int additionalReserveVerbs, int additionalRe servePoints); | 273 void copy(const SkPathRef& ref, int additionalReserveVerbs, int additionalRe servePoints); |
277 | 274 |
278 // Return true if the computed bounds are finite. | 275 // Return true if the computed bounds are finite. |
279 static bool ComputePtBounds(SkRect* bounds, const SkPathRef& ref) { | 276 static bool ComputePtBounds(SkRect* bounds, const SkPathRef& ref) { |
280 int count = ref.countPoints(); | 277 int count = ref.countPoints(); |
(...skipping 23 matching lines...) Expand all Loading... | |
304 } | 301 } |
305 | 302 |
306 /** Resets the path ref with verbCount verbs and pointCount points, all unin itialized. Also | 303 /** 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.*/ | 304 * allocates space for reserveVerb additional verbs and reservePoints addit ional points.*/ |
308 void resetToSize(int verbCount, int pointCount, int conicCount, | 305 void resetToSize(int verbCount, int pointCount, int conicCount, |
309 int reserveVerbs = 0, int reservePoints = 0) { | 306 int reserveVerbs = 0, int reservePoints = 0) { |
310 SkDEBUGCODE(this->validate();) | 307 SkDEBUGCODE(this->validate();) |
311 fBoundsIsDirty = true; // this also invalidates fIsFinite | 308 fBoundsIsDirty = true; // this also invalidates fIsFinite |
312 fGenerationID = 0; | 309 fGenerationID = 0; |
313 | 310 |
311 fSegmentMask = 0; | |
314 fIsOval = false; | 312 fIsOval = false; |
315 | 313 |
316 size_t newSize = sizeof(uint8_t) * verbCount + sizeof(SkPoint) * pointCo unt; | 314 size_t newSize = sizeof(uint8_t) * verbCount + sizeof(SkPoint) * pointCo unt; |
317 size_t newReserve = sizeof(uint8_t) * reserveVerbs + sizeof(SkPoint) * r eservePoints; | 315 size_t newReserve = sizeof(uint8_t) * reserveVerbs + sizeof(SkPoint) * r eservePoints; |
318 size_t minSize = newSize + newReserve; | 316 size_t minSize = newSize + newReserve; |
319 | 317 |
320 ptrdiff_t sizeDelta = this->currSize() - minSize; | 318 ptrdiff_t sizeDelta = this->currSize() - minSize; |
321 | 319 |
322 if (sizeDelta < 0 || static_cast<size_t>(sizeDelta) >= 3 * minSize) { | 320 if (sizeDelta < 0 || static_cast<size_t>(sizeDelta) >= 3 * minSize) { |
323 sk_free(fPoints); | 321 sk_free(fPoints); |
324 fPoints = NULL; | 322 fPoints = NULL; |
325 fVerbs = NULL; | 323 fVerbs = NULL; |
326 fFreeSpace = 0; | 324 fFreeSpace = 0; |
327 fVerbCnt = 0; | 325 fVerbCnt = 0; |
328 fPointCnt = 0; | 326 fPointCnt = 0; |
329 this->makeSpace(minSize); | 327 this->makeSpace(minSize); |
330 fVerbCnt = verbCount; | 328 fVerbCnt = verbCount; |
331 fPointCnt = pointCount; | 329 fPointCnt = pointCount; |
332 fFreeSpace -= newSize; | 330 fFreeSpace -= newSize; |
333 } else { | 331 } else { |
334 fPointCnt = pointCount; | 332 fPointCnt = pointCount; |
335 fVerbCnt = verbCount; | 333 fVerbCnt = verbCount; |
336 fFreeSpace = this->currSize() - minSize; | 334 fFreeSpace = this->currSize() - minSize; |
337 } | 335 } |
338 fConicWeights.setCount(conicCount); | 336 fConicWeights.setCount(conicCount); |
339 SkDEBUGCODE(this->validate();) | 337 SkDEBUGCODE(this->validate();) |
340 } | 338 } |
341 | 339 |
342 /** | 340 /** |
343 * Increases the verb count by newVerbs and the point count be newPoints. Ne w verbs and points | 341 * Increases the verb and point count by numLines. The new points |
344 * are uninitialized. | 342 * are uninitialized. All the new verbs are set to kLine_Verb. |
345 */ | 343 */ |
346 void grow(int newVerbs, int newPoints) { | 344 SkPoint* growForLines(int numLines); |
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 | 345 |
357 /** | 346 /** |
358 * Increases the verb count 1, records the new verb, and creates room for th e requisite number | 347 * 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 | 348 * of additional points. A pointer to the first point is returned. Any new p oints are |
360 * uninitialized. | 349 * uninitialized. |
361 */ | 350 */ |
362 SkPoint* growForVerb(int /*SkPath::Verb*/ verb); | 351 SkPoint* growForVerb(int /*SkPath::Verb*/ verb); |
363 | 352 |
364 /** | 353 /** |
365 * Ensures that the free space available in the path ref is >= size. The ver b and point counts | 354 * Ensures that the free space available in the path ref is >= size. The ver b and point counts |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
418 */ | 407 */ |
419 static void CreateEmptyImpl(SkPathRef** empty); | 408 static void CreateEmptyImpl(SkPathRef** empty); |
420 | 409 |
421 void setIsOval(bool isOval) { fIsOval = isOval; } | 410 void setIsOval(bool isOval) { fIsOval = isOval; } |
422 | 411 |
423 enum { | 412 enum { |
424 kMinSize = 256, | 413 kMinSize = 256, |
425 }; | 414 }; |
426 | 415 |
427 mutable SkRect fBounds; | 416 mutable SkRect fBounds; |
417 uint8_t fSegmentMask; | |
428 mutable uint8_t fBoundsIsDirty; | 418 mutable uint8_t fBoundsIsDirty; |
429 mutable SkBool8 fIsFinite; // only meaningful if bounds are valid | 419 mutable SkBool8 fIsFinite; // only meaningful if bounds are valid |
430 mutable SkBool8 fIsOval; | 420 mutable SkBool8 fIsOval; |
431 | 421 |
432 SkPoint* fPoints; // points to begining of the allocation | 422 SkPoint* fPoints; // points to begining of the allocation |
433 uint8_t* fVerbs; // points just past the end of the allocation (v erbs grow backwards) | 423 uint8_t* fVerbs; // points just past the end of the allocation (v erbs grow backwards) |
434 int fVerbCnt; | 424 int fVerbCnt; |
435 int fPointCnt; | 425 int fPointCnt; |
436 size_t fFreeSpace; // redundant but saves computation | 426 size_t fFreeSpace; // redundant but saves computation |
437 SkTDArray<SkScalar> fConicWeights; | 427 SkTDArray<SkScalar> fConicWeights; |
438 | 428 |
439 enum { | 429 enum { |
440 kEmptyGenID = 1, // GenID reserved for path ref with zero points and zer o verbs. | 430 kEmptyGenID = 1, // GenID reserved for path ref with zero points and zer o verbs. |
441 }; | 431 }; |
442 mutable uint32_t fGenerationID; | 432 mutable uint32_t fGenerationID; |
443 SkDEBUGCODE(int32_t fEditorsAttached;) // assert that only one editor in use at any time. | 433 SkDEBUGCODE(int32_t fEditorsAttached;) // assert that only one editor in use at any time. |
444 | 434 |
445 typedef SkRefCnt INHERITED; | 435 typedef SkRefCnt INHERITED; |
446 }; | 436 }; |
447 | 437 |
448 #endif | 438 #endif |
OLD | NEW |