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 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 | 173 |
174 static SkPathRef* CreateFromBuffer(SkRBuffer* buffer); | 174 static SkPathRef* CreateFromBuffer(SkRBuffer* buffer); |
175 | 175 |
176 /** | 176 /** |
177 * Rollsback a path ref to zero verbs and points with the assumption that th
e path ref will be | 177 * Rollsback a path ref to zero verbs and points with the assumption that th
e path ref will be |
178 * repopulated with approximately the same number of verbs and points. A new
path ref is created | 178 * repopulated with approximately the same number of verbs and points. A new
path ref is created |
179 * only if necessary. | 179 * only if necessary. |
180 */ | 180 */ |
181 static void Rewind(SkAutoTUnref<SkPathRef>* pathRef); | 181 static void Rewind(SkAutoTUnref<SkPathRef>* pathRef); |
182 | 182 |
183 virtual ~SkPathRef() { | 183 virtual ~SkPathRef(); |
184 SkDEBUGCODE(this->validate();) | |
185 sk_free(fPoints); | |
186 | |
187 SkDEBUGCODE(fPoints = NULL;) | |
188 SkDEBUGCODE(fVerbs = NULL;) | |
189 SkDEBUGCODE(fVerbCnt = 0x9999999;) | |
190 SkDEBUGCODE(fPointCnt = 0xAAAAAAA;) | |
191 SkDEBUGCODE(fPointCnt = 0xBBBBBBB;) | |
192 SkDEBUGCODE(fGenerationID = 0xEEEEEEEE;) | |
193 SkDEBUGCODE(fEditorsAttached = 0x7777777;) | |
194 } | |
195 | |
196 int countPoints() const { SkDEBUGCODE(this->validate();) return fPointCnt; } | 184 int countPoints() const { SkDEBUGCODE(this->validate();) return fPointCnt; } |
197 int countVerbs() const { SkDEBUGCODE(this->validate();) return fVerbCnt; } | 185 int countVerbs() const { SkDEBUGCODE(this->validate();) return fVerbCnt; } |
198 int countWeights() const { SkDEBUGCODE(this->validate();) return fConicWeigh
ts.count(); } | 186 int countWeights() const { SkDEBUGCODE(this->validate();) return fConicWeigh
ts.count(); } |
199 | 187 |
200 /** | 188 /** |
201 * Returns a pointer one beyond the first logical verb (last verb in memory
order). | 189 * Returns a pointer one beyond the first logical verb (last verb in memory
order). |
202 */ | 190 */ |
203 const uint8_t* verbs() const { SkDEBUGCODE(this->validate();) return fVerbs;
} | 191 const uint8_t* verbs() const { SkDEBUGCODE(this->validate();) return fVerbs;
} |
204 | 192 |
205 /** | 193 /** |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 */ | 232 */ |
245 uint32_t writeSize() const; | 233 uint32_t writeSize() const; |
246 | 234 |
247 /** | 235 /** |
248 * Gets an ID that uniquely identifies the contents of the path ref. If two
path refs have the | 236 * Gets an ID that uniquely identifies the contents of the path ref. If two
path refs have the |
249 * same ID then they have the same verbs and points. However, two path refs
may have the same | 237 * same ID then they have the same verbs and points. However, two path refs
may have the same |
250 * contents but different genIDs. | 238 * contents but different genIDs. |
251 */ | 239 */ |
252 uint32_t genID() const; | 240 uint32_t genID() const; |
253 | 241 |
| 242 struct GenIDChangeListener { |
| 243 virtual ~GenIDChangeListener() {} |
| 244 virtual void onChange() = 0; |
| 245 }; |
| 246 |
| 247 void addGenIDChangeListener(GenIDChangeListener* listener); |
| 248 |
254 SkDEBUGCODE(void validate() const;) | 249 SkDEBUGCODE(void validate() const;) |
255 | 250 |
256 private: | 251 private: |
257 enum SerializationOffsets { | 252 enum SerializationOffsets { |
258 kIsFinite_SerializationShift = 25, // requires 1 bit | 253 kIsFinite_SerializationShift = 25, // requires 1 bit |
259 kIsOval_SerializationShift = 24, // requires 1 bit | 254 kIsOval_SerializationShift = 24, // requires 1 bit |
260 kSegmentMask_SerializationShift = 0 // requires 4 bits | 255 kSegmentMask_SerializationShift = 0 // requires 4 bits |
261 }; | 256 }; |
262 | 257 |
263 SkPathRef() { | 258 SkPathRef() { |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 friend SkPathRef* sk_create_empty_pathref(); | 410 friend SkPathRef* sk_create_empty_pathref(); |
416 | 411 |
417 void setIsOval(bool isOval) { fIsOval = isOval; } | 412 void setIsOval(bool isOval) { fIsOval = isOval; } |
418 | 413 |
419 SkPoint* getPoints() { | 414 SkPoint* getPoints() { |
420 SkDEBUGCODE(this->validate();) | 415 SkDEBUGCODE(this->validate();) |
421 fIsOval = false; | 416 fIsOval = false; |
422 return fPoints; | 417 return fPoints; |
423 } | 418 } |
424 | 419 |
| 420 void callGenIDChangeListeners(); |
| 421 |
425 enum { | 422 enum { |
426 kMinSize = 256, | 423 kMinSize = 256, |
427 }; | 424 }; |
428 | 425 |
429 mutable SkRect fBounds; | 426 mutable SkRect fBounds; |
430 mutable uint8_t fBoundsIsDirty; | 427 mutable uint8_t fBoundsIsDirty; |
431 mutable SkBool8 fIsFinite; // only meaningful if bounds are valid | 428 mutable SkBool8 fIsFinite; // only meaningful if bounds are valid |
432 | 429 |
433 SkBool8 fIsOval; | 430 SkBool8 fIsOval; |
434 uint8_t fSegmentMask; | 431 uint8_t fSegmentMask; |
435 | 432 |
436 SkPoint* fPoints; // points to begining of the allocation | 433 SkPoint* fPoints; // points to begining of the allocation |
437 uint8_t* fVerbs; // points just past the end of the allocation (v
erbs grow backwards) | 434 uint8_t* fVerbs; // points just past the end of the allocation (v
erbs grow backwards) |
438 int fVerbCnt; | 435 int fVerbCnt; |
439 int fPointCnt; | 436 int fPointCnt; |
440 size_t fFreeSpace; // redundant but saves computation | 437 size_t fFreeSpace; // redundant but saves computation |
441 SkTDArray<SkScalar> fConicWeights; | 438 SkTDArray<SkScalar> fConicWeights; |
442 | 439 |
443 enum { | 440 enum { |
444 kEmptyGenID = 1, // GenID reserved for path ref with zero points and zer
o verbs. | 441 kEmptyGenID = 1, // GenID reserved for path ref with zero points and zer
o verbs. |
445 }; | 442 }; |
446 mutable uint32_t fGenerationID; | 443 mutable uint32_t fGenerationID; |
447 SkDEBUGCODE(int32_t fEditorsAttached;) // assert that only one editor in use
at any time. | 444 SkDEBUGCODE(int32_t fEditorsAttached;) // assert that only one editor in use
at any time. |
448 | 445 |
| 446 SkTDArray<GenIDChangeListener*> fGenIDChangeListeners; // pointers are owne
d |
| 447 |
449 friend class PathRefTest_Private; | 448 friend class PathRefTest_Private; |
450 typedef SkRefCnt INHERITED; | 449 typedef SkRefCnt INHERITED; |
451 }; | 450 }; |
452 | 451 |
453 #endif | 452 #endif |
OLD | NEW |