| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 public: | 42 public: |
| 43 Editor(SkAutoTUnref<SkPathRef>* pathRef, | 43 Editor(SkAutoTUnref<SkPathRef>* pathRef, |
| 44 int incReserveVerbs = 0, | 44 int incReserveVerbs = 0, |
| 45 int incReservePoints = 0); | 45 int incReservePoints = 0); |
| 46 | 46 |
| 47 ~Editor() { SkDEBUGCODE(sk_atomic_dec(&fPathRef->fEditorsAttached);) } | 47 ~Editor() { SkDEBUGCODE(sk_atomic_dec(&fPathRef->fEditorsAttached);) } |
| 48 | 48 |
| 49 /** | 49 /** |
| 50 * Returns the array of points. | 50 * Returns the array of points. |
| 51 */ | 51 */ |
| 52 SkPoint* points() { return fPathRef->fPoints; } | 52 SkPoint* points() { return fPathRef->getPoints(); } |
| 53 const SkPoint* points() const { return fPathRef->points(); } |
| 53 | 54 |
| 54 /** | 55 /** |
| 55 * Gets the ith point. Shortcut for this->points() + i | 56 * Gets the ith point. Shortcut for this->points() + i |
| 56 */ | 57 */ |
| 57 SkPoint* atPoint(int i) { | 58 SkPoint* atPoint(int i) { |
| 58 SkASSERT((unsigned) i < (unsigned) fPathRef->fPointCnt); | 59 SkASSERT((unsigned) i < (unsigned) fPathRef->fPointCnt); |
| 59 return this->points() + i; | 60 return this->points() + i; |
| 60 }; | 61 }; |
| 62 const SkPoint* atPoint(int i) const { |
| 63 SkASSERT((unsigned) i < (unsigned) fPathRef->fPointCnt); |
| 64 return this->points() + i; |
| 65 }; |
| 61 | 66 |
| 62 /** | 67 /** |
| 63 * Adds the verb and allocates space for the number of points indicated
by the verb. The | 68 * 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. | 69 * 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 | 70 * 'weight' is only used if 'verb' is kConic_Verb |
| 66 */ | 71 */ |
| 67 SkPoint* growForVerb(int /*SkPath::Verb*/ verb, SkScalar weight = 0) { | 72 SkPoint* growForVerb(int /*SkPath::Verb*/ verb, SkScalar weight = 0) { |
| 68 SkDEBUGCODE(fPathRef->validate();) | 73 SkDEBUGCODE(fPathRef->validate();) |
| 69 return fPathRef->growForVerb(verb, weight); | 74 return fPathRef->growForVerb(verb, weight); |
| 70 } | 75 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 82 return fPathRef->growForRepeatedVerb(verb, numVbs, weights); | 87 return fPathRef->growForRepeatedVerb(verb, numVbs, weights); |
| 83 } | 88 } |
| 84 | 89 |
| 85 /** | 90 /** |
| 86 * Resets the path ref to a new verb and point count. The new verbs and
points are | 91 * Resets the path ref to a new verb and point count. The new verbs and
points are |
| 87 * uninitialized. | 92 * uninitialized. |
| 88 */ | 93 */ |
| 89 void resetToSize(int newVerbCnt, int newPointCnt, int newConicCount) { | 94 void resetToSize(int newVerbCnt, int newPointCnt, int newConicCount) { |
| 90 fPathRef->resetToSize(newVerbCnt, newPointCnt, newConicCount); | 95 fPathRef->resetToSize(newVerbCnt, newPointCnt, newConicCount); |
| 91 } | 96 } |
| 97 |
| 92 /** | 98 /** |
| 93 * Gets the path ref that is wrapped in the Editor. | 99 * Gets the path ref that is wrapped in the Editor. |
| 94 */ | 100 */ |
| 95 SkPathRef* pathRef() { return fPathRef; } | 101 SkPathRef* pathRef() { return fPathRef; } |
| 96 | 102 |
| 97 void setIsOval(bool isOval) { fPathRef->setIsOval(isOval); } | 103 void setIsOval(bool isOval) { fPathRef->setIsOval(isOval); } |
| 98 | 104 |
| 105 void setBounds(const SkRect& rect) { fPathRef->setBounds(rect); } |
| 106 |
| 99 private: | 107 private: |
| 100 SkPathRef* fPathRef; | 108 SkPathRef* fPathRef; |
| 101 }; | 109 }; |
| 102 | 110 |
| 103 public: | 111 public: |
| 104 /** | 112 /** |
| 105 * Gets a path ref with no verbs or points. | 113 * Gets a path ref with no verbs or points. |
| 106 */ | 114 */ |
| 107 static SkPathRef* CreateEmpty(); | 115 static SkPathRef* CreateEmpty(); |
| 108 | 116 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 Note: this bounds may be larger than the actual shape, since curves | 159 Note: this bounds may be larger than the actual shape, since curves |
| 152 do not extend as far as their control points. | 160 do not extend as far as their control points. |
| 153 */ | 161 */ |
| 154 const SkRect& getBounds() const { | 162 const SkRect& getBounds() const { |
| 155 if (fBoundsIsDirty) { | 163 if (fBoundsIsDirty) { |
| 156 this->computeBounds(); | 164 this->computeBounds(); |
| 157 } | 165 } |
| 158 return fBounds; | 166 return fBounds; |
| 159 } | 167 } |
| 160 | 168 |
| 161 void setBounds(const SkRect& rect) { | |
| 162 SkASSERT(rect.fLeft <= rect.fRight && rect.fTop <= rect.fBottom); | |
| 163 fBounds = rect; | |
| 164 fBoundsIsDirty = false; | |
| 165 fIsFinite = fBounds.isFinite(); | |
| 166 } | |
| 167 | |
| 168 /** | 169 /** |
| 169 * Transforms a path ref by a matrix, allocating a new one only if necessary
. | 170 * Transforms a path ref by a matrix, allocating a new one only if necessary
. |
| 170 */ | 171 */ |
| 171 static void CreateTransformedCopy(SkAutoTUnref<SkPathRef>* dst, | 172 static void CreateTransformedCopy(SkAutoTUnref<SkPathRef>* dst, |
| 172 const SkPathRef& src, | 173 const SkPathRef& src, |
| 173 const SkMatrix& matrix); | 174 const SkMatrix& matrix); |
| 174 | 175 |
| 175 static SkPathRef* CreateFromBuffer(SkRBuffer* buffer | 176 static SkPathRef* CreateFromBuffer(SkRBuffer* buffer |
| 176 #ifndef DELETE_THIS_CODE_WHEN_SKPS_ARE_REBUILT_AT_V16_AND_ALL_OTHER_INSTANCES_TO
O | 177 #ifndef DELETE_THIS_CODE_WHEN_SKPS_ARE_REBUILT_AT_V16_AND_ALL_OTHER_INSTANCES_TO
O |
| 177 , bool newFormat, int32_t oldPacked | 178 , bool newFormat, int32_t oldPacked |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 | 293 |
| 293 // called, if dirty, by getBounds() | 294 // called, if dirty, by getBounds() |
| 294 void computeBounds() const { | 295 void computeBounds() const { |
| 295 SkDEBUGCODE(this->validate();) | 296 SkDEBUGCODE(this->validate();) |
| 296 SkASSERT(fBoundsIsDirty); | 297 SkASSERT(fBoundsIsDirty); |
| 297 | 298 |
| 298 fIsFinite = ComputePtBounds(&fBounds, *this); | 299 fIsFinite = ComputePtBounds(&fBounds, *this); |
| 299 fBoundsIsDirty = false; | 300 fBoundsIsDirty = false; |
| 300 } | 301 } |
| 301 | 302 |
| 303 void setBounds(const SkRect& rect) { |
| 304 SkASSERT(rect.fLeft <= rect.fRight && rect.fTop <= rect.fBottom); |
| 305 fBounds = rect; |
| 306 fBoundsIsDirty = false; |
| 307 fIsFinite = fBounds.isFinite(); |
| 308 } |
| 309 |
| 302 /** Makes additional room but does not change the counts or change the genID
*/ | 310 /** Makes additional room but does not change the counts or change the genID
*/ |
| 303 void incReserve(int additionalVerbs, int additionalPoints) { | 311 void incReserve(int additionalVerbs, int additionalPoints) { |
| 304 SkDEBUGCODE(this->validate();) | 312 SkDEBUGCODE(this->validate();) |
| 305 size_t space = additionalVerbs * sizeof(uint8_t) + additionalPoints * si
zeof (SkPoint); | 313 size_t space = additionalVerbs * sizeof(uint8_t) + additionalPoints * si
zeof (SkPoint); |
| 306 this->makeSpace(space); | 314 this->makeSpace(space); |
| 307 SkDEBUGCODE(this->validate();) | 315 SkDEBUGCODE(this->validate();) |
| 308 } | 316 } |
| 309 | 317 |
| 310 /** Resets the path ref with verbCount verbs and pointCount points, all unin
itialized. Also | 318 /** Resets the path ref with verbCount verbs and pointCount points, all unin
itialized. Also |
| 311 * allocates space for reserveVerb additional verbs and reservePoints addit
ional points.*/ | 319 * allocates space for reserveVerb additional verbs and reservePoints addit
ional points.*/ |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 | 419 |
| 412 SkDEBUGCODE(void validate() const;) | 420 SkDEBUGCODE(void validate() const;) |
| 413 | 421 |
| 414 /** | 422 /** |
| 415 * Called the first time someone calls CreateEmpty to actually create the si
ngleton. | 423 * Called the first time someone calls CreateEmpty to actually create the si
ngleton. |
| 416 */ | 424 */ |
| 417 static void CreateEmptyImpl(SkPathRef** empty); | 425 static void CreateEmptyImpl(SkPathRef** empty); |
| 418 | 426 |
| 419 void setIsOval(bool isOval) { fIsOval = isOval; } | 427 void setIsOval(bool isOval) { fIsOval = isOval; } |
| 420 | 428 |
| 429 SkPoint* getPoints() { |
| 430 SkDEBUGCODE(this->validate();) |
| 431 fIsOval = false; |
| 432 return fPoints; |
| 433 } |
| 434 |
| 421 enum { | 435 enum { |
| 422 kMinSize = 256, | 436 kMinSize = 256, |
| 423 }; | 437 }; |
| 424 | 438 |
| 425 mutable SkRect fBounds; | 439 mutable SkRect fBounds; |
| 426 uint8_t fSegmentMask; | 440 uint8_t fSegmentMask; |
| 427 mutable uint8_t fBoundsIsDirty; | 441 mutable uint8_t fBoundsIsDirty; |
| 428 mutable SkBool8 fIsFinite; // only meaningful if bounds are valid | 442 mutable SkBool8 fIsFinite; // only meaningful if bounds are valid |
| 429 mutable SkBool8 fIsOval; | 443 mutable SkBool8 fIsOval; |
| 430 | 444 |
| 431 SkPoint* fPoints; // points to begining of the allocation | 445 SkPoint* fPoints; // points to begining of the allocation |
| 432 uint8_t* fVerbs; // points just past the end of the allocation (v
erbs grow backwards) | 446 uint8_t* fVerbs; // points just past the end of the allocation (v
erbs grow backwards) |
| 433 int fVerbCnt; | 447 int fVerbCnt; |
| 434 int fPointCnt; | 448 int fPointCnt; |
| 435 size_t fFreeSpace; // redundant but saves computation | 449 size_t fFreeSpace; // redundant but saves computation |
| 436 SkTDArray<SkScalar> fConicWeights; | 450 SkTDArray<SkScalar> fConicWeights; |
| 437 | 451 |
| 438 enum { | 452 enum { |
| 439 kEmptyGenID = 1, // GenID reserved for path ref with zero points and zer
o verbs. | 453 kEmptyGenID = 1, // GenID reserved for path ref with zero points and zer
o verbs. |
| 440 }; | 454 }; |
| 441 mutable uint32_t fGenerationID; | 455 mutable uint32_t fGenerationID; |
| 442 SkDEBUGCODE(int32_t fEditorsAttached;) // assert that only one editor in use
at any time. | 456 SkDEBUGCODE(int32_t fEditorsAttached;) // assert that only one editor in use
at any time. |
| 443 | 457 |
| 458 friend class PathRefTest_Private; |
| 444 typedef SkRefCnt INHERITED; | 459 typedef SkRefCnt INHERITED; |
| 445 }; | 460 }; |
| 446 | 461 |
| 447 #endif | 462 #endif |
| OLD | NEW |