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