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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 | 97 |
98 /** | 98 /** |
99 * Gets the path ref that is wrapped in the Editor. | 99 * Gets the path ref that is wrapped in the Editor. |
100 */ | 100 */ |
101 SkPathRef* pathRef() { return fPathRef; } | 101 SkPathRef* pathRef() { return fPathRef; } |
102 | 102 |
103 void setIsOval(bool isOval) { fPathRef->setIsOval(isOval); } | 103 void setIsOval(bool isOval) { fPathRef->setIsOval(isOval); } |
104 | 104 |
105 void setBounds(const SkRect& rect) { fPathRef->setBounds(rect); } | 105 void setBounds(const SkRect& rect) { fPathRef->setBounds(rect); } |
106 | 106 |
107 // In some cases we need to inject a leading moveTo before we add points | |
108 // for lineTo, quadTo, conicTo, cubicTo | |
109 // | |
110 // SkPath path; path.lineTo(...); <--- need a leading moveTo(0, 0) | |
111 // SkPath path; ... path.close(); path.lineTo(...) <-- need a moveTo(pre
vious moveTo) | |
112 void injectMoveToIfNeeded() { fPathRef->injectMoveToIfNeeded(); } | |
113 | |
114 private: | 107 private: |
115 SkPathRef* fPathRef; | 108 SkPathRef* fPathRef; |
116 }; | 109 }; |
117 | 110 |
118 public: | 111 public: |
119 /** | 112 /** |
120 * Gets a path ref with no verbs or points. | 113 * Gets a path ref with no verbs or points. |
121 */ | 114 */ |
122 static SkPathRef* CreateEmpty(); | 115 static SkPathRef* CreateEmpty(); |
123 | 116 |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 uint32_t writeSize() const; | 247 uint32_t writeSize() const; |
255 | 248 |
256 /** | 249 /** |
257 * Gets an ID that uniquely identifies the contents of the path ref. If two
path refs have the | 250 * Gets an ID that uniquely identifies the contents of the path ref. If two
path refs have the |
258 * same ID then they have the same verbs and points. However, two path refs
may have the same | 251 * same ID then they have the same verbs and points. However, two path refs
may have the same |
259 * contents but different genIDs. | 252 * contents but different genIDs. |
260 */ | 253 */ |
261 uint32_t genID() const; | 254 uint32_t genID() const; |
262 | 255 |
263 private: | 256 private: |
264 // flag to require a moveTo if we begin with something else, like lineTo etc
. | |
265 static const int kINITIAL_LASTMOVETOINDEX_VALUE = ~0; | |
266 | |
267 enum SerializationOffsets { | 257 enum SerializationOffsets { |
268 kIsFinite_SerializationShift = 25, // requires 1 bit | 258 kIsFinite_SerializationShift = 25, // requires 1 bit |
269 kIsOval_SerializationShift = 24, // requires 1 bit | 259 kIsOval_SerializationShift = 24, // requires 1 bit |
270 kSegmentMask_SerializationShift = 0 // requires 4 bits | 260 kSegmentMask_SerializationShift = 0 // requires 4 bits |
271 }; | 261 }; |
272 | 262 |
273 SkPathRef() { | 263 SkPathRef() { |
274 fLastMoveToIndex = kINITIAL_LASTMOVETOINDEX_VALUE; | |
275 fBoundsIsDirty = true; // this also invalidates fIsFinite | 264 fBoundsIsDirty = true; // this also invalidates fIsFinite |
276 fPointCnt = 0; | 265 fPointCnt = 0; |
277 fVerbCnt = 0; | 266 fVerbCnt = 0; |
278 fVerbs = NULL; | 267 fVerbs = NULL; |
279 fPoints = NULL; | 268 fPoints = NULL; |
280 fFreeSpace = 0; | 269 fFreeSpace = 0; |
281 fGenerationID = kEmptyGenID; | 270 fGenerationID = kEmptyGenID; |
282 fSegmentMask = 0; | 271 fSegmentMask = 0; |
283 fIsOval = false; | 272 fIsOval = false; |
284 SkDEBUGCODE(fEditorsAttached = 0;) | 273 SkDEBUGCODE(fEditorsAttached = 0;) |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 fFreeSpace -= newSize; | 341 fFreeSpace -= newSize; |
353 } else { | 342 } else { |
354 fPointCnt = pointCount; | 343 fPointCnt = pointCount; |
355 fVerbCnt = verbCount; | 344 fVerbCnt = verbCount; |
356 fFreeSpace = this->currSize() - minSize; | 345 fFreeSpace = this->currSize() - minSize; |
357 } | 346 } |
358 fConicWeights.setCount(conicCount); | 347 fConicWeights.setCount(conicCount); |
359 SkDEBUGCODE(this->validate();) | 348 SkDEBUGCODE(this->validate();) |
360 } | 349 } |
361 | 350 |
362 void injectMoveToIfNeeded(); | |
363 | |
364 /** | 351 /** |
365 * Increases the verb count by numVbs and point count by the required amount
. | 352 * Increases the verb count by numVbs and point count by the required amount
. |
366 * The new points are uninitialized. All the new verbs are set to the specif
ied | 353 * The new points are uninitialized. All the new verbs are set to the specif
ied |
367 * verb. If 'verb' is kConic_Verb, 'weights' will return a pointer to the | 354 * verb. If 'verb' is kConic_Verb, 'weights' will return a pointer to the |
368 * uninitialized conic weights. | 355 * uninitialized conic weights. |
369 */ | 356 */ |
370 SkPoint* growForRepeatedVerb(int /*SkPath::Verb*/ verb, int numVbs, SkScalar
** weights); | 357 SkPoint* growForRepeatedVerb(int /*SkPath::Verb*/ verb, int numVbs, SkScalar
** weights); |
371 | 358 |
372 /** | 359 /** |
373 * Increases the verb count 1, records the new verb, and creates room for th
e requisite number | 360 * Increases the verb count 1, records the new verb, and creates room for th
e requisite number |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 SkDEBUGCODE(this->validate();) | 426 SkDEBUGCODE(this->validate();) |
440 fIsOval = false; | 427 fIsOval = false; |
441 return fPoints; | 428 return fPoints; |
442 } | 429 } |
443 | 430 |
444 enum { | 431 enum { |
445 kMinSize = 256, | 432 kMinSize = 256, |
446 }; | 433 }; |
447 | 434 |
448 mutable SkRect fBounds; | 435 mutable SkRect fBounds; |
449 int fLastMoveToIndex; | |
450 uint8_t fSegmentMask; | 436 uint8_t fSegmentMask; |
451 mutable uint8_t fBoundsIsDirty; | 437 mutable uint8_t fBoundsIsDirty; |
452 mutable SkBool8 fIsFinite; // only meaningful if bounds are valid | 438 mutable SkBool8 fIsFinite; // only meaningful if bounds are valid |
453 mutable SkBool8 fIsOval; | 439 mutable SkBool8 fIsOval; |
454 | 440 |
455 SkPoint* fPoints; // points to begining of the allocation | 441 SkPoint* fPoints; // points to begining of the allocation |
456 uint8_t* fVerbs; // points just past the end of the allocation (v
erbs grow backwards) | 442 uint8_t* fVerbs; // points just past the end of the allocation (v
erbs grow backwards) |
457 int fVerbCnt; | 443 int fVerbCnt; |
458 int fPointCnt; | 444 int fPointCnt; |
459 size_t fFreeSpace; // redundant but saves computation | 445 size_t fFreeSpace; // redundant but saves computation |
460 SkTDArray<SkScalar> fConicWeights; | 446 SkTDArray<SkScalar> fConicWeights; |
461 | 447 |
462 enum { | 448 enum { |
463 kEmptyGenID = 1, // GenID reserved for path ref with zero points and zer
o verbs. | 449 kEmptyGenID = 1, // GenID reserved for path ref with zero points and zer
o verbs. |
464 }; | 450 }; |
465 mutable uint32_t fGenerationID; | 451 mutable uint32_t fGenerationID; |
466 SkDEBUGCODE(int32_t fEditorsAttached;) // assert that only one editor in use
at any time. | 452 SkDEBUGCODE(int32_t fEditorsAttached;) // assert that only one editor in use
at any time. |
467 | 453 |
468 friend class PathRefTest_Private; | 454 friend class PathRefTest_Private; |
469 typedef SkRefCnt INHERITED; | 455 typedef SkRefCnt INHERITED; |
470 }; | 456 }; |
471 | 457 |
472 #endif | 458 #endif |
OLD | NEW |