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