Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(276)

Side by Side Diff: include/core/SkPathRef.h

Issue 2006383002: preserve rrect/oval dir (Closed) Base URL: https://chromium.googlesource.com/skia.git@SkTypes
Patch Set: Improve tests Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « include/core/SkPath.h ('k') | src/core/SkPath.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 */ 93 */
94 void resetToSize(int newVerbCnt, int newPointCnt, int newConicCount) { 94 void resetToSize(int newVerbCnt, int newPointCnt, int newConicCount) {
95 fPathRef->resetToSize(newVerbCnt, newPointCnt, newConicCount); 95 fPathRef->resetToSize(newVerbCnt, newPointCnt, newConicCount);
96 } 96 }
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, bool isCCW, unsigned start) {
104 fPathRef->setIsOval(isOval, isCCW, start);
105 }
104 106
105 void setIsRRect(bool isRRect) { fPathRef->setIsRRect(isRRect); } 107 void setIsRRect(bool isRRect, bool isCCW, unsigned start) {
108 fPathRef->setIsRRect(isRRect, isCCW, start);
109 }
106 110
107 void setBounds(const SkRect& rect) { fPathRef->setBounds(rect); } 111 void setBounds(const SkRect& rect) { fPathRef->setBounds(rect); }
108 112
109 private: 113 private:
110 SkPathRef* fPathRef; 114 SkPathRef* fPathRef;
111 }; 115 };
112 116
113 class SK_API Iter { 117 class SK_API Iter {
114 public: 118 public:
115 Iter(); 119 Iter();
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 * Returns a mask, where each bit corresponding to a SegmentMask is 161 * Returns a mask, where each bit corresponding to a SegmentMask is
158 * set if the path contains 1 or more segments of that type. 162 * set if the path contains 1 or more segments of that type.
159 * Returns 0 for an empty path (no segments). 163 * Returns 0 for an empty path (no segments).
160 */ 164 */
161 uint32_t getSegmentMasks() const { return fSegmentMask; } 165 uint32_t getSegmentMasks() const { return fSegmentMask; }
162 166
163 /** Returns true if the path is an oval. 167 /** Returns true if the path is an oval.
164 * 168 *
165 * @param rect returns the bounding rect of this oval. It's a circle 169 * @param rect returns the bounding rect of this oval. It's a circle
166 * if the height and width are the same. 170 * if the height and width are the same.
171 * @param isCCW is the oval CCW (or CW if false).
172 * @param start indicates where the contour starts on the oval (see
173 * SkPath::addOval for intepretation of the index).
167 * 174 *
168 * @return true if this path is an oval. 175 * @return true if this path is an oval.
169 * Tracking whether a path is an oval is considered an 176 * Tracking whether a path is an oval is considered an
170 * optimization for performance and so some paths that are in 177 * optimization for performance and so some paths that are in
171 * fact ovals can report false. 178 * fact ovals can report false.
172 */ 179 */
173 bool isOval(SkRect* rect) const { 180 bool isOval(SkRect* rect, bool* isCCW, unsigned* start) const {
174 if (fIsOval && rect) { 181 if (fIsOval) {
175 *rect = this->getBounds(); 182 if (rect) {
183 *rect = this->getBounds();
184 }
185 if (isCCW) {
186 *isCCW = fRRectOrOvalIsCCW;
187 }
188 if (start) {
189 *start = fRRectOrOvalStartIdx;
190 }
176 } 191 }
177 192
178 return SkToBool(fIsOval); 193 return SkToBool(fIsOval);
179 } 194 }
180 195
181 bool isRRect(SkRRect* rrect) const { 196 bool isRRect(SkRRect* rrect, bool* isCCW, unsigned* start) const {
182 if (fIsRRect && rrect) { 197 if (fIsRRect) {
183 *rrect = this->getRRect(); 198 if (rrect) {
199 *rrect = this->getRRect();
200 }
201 if (isCCW) {
202 *isCCW = fRRectOrOvalIsCCW;
203 }
204 if (start) {
205 *start = fRRectOrOvalStartIdx;
206 }
184 } 207 }
185 return SkToBool(fIsRRect); 208 return SkToBool(fIsRRect);
186 } 209 }
187 210
188 211
189 bool hasComputedBounds() const { 212 bool hasComputedBounds() const {
190 return !fBoundsIsDirty; 213 return !fBoundsIsDirty;
191 } 214 }
192 215
193 /** Returns the bounds of the path's points. If the path contains 0 or 1 216 /** Returns the bounds of the path's points. If the path contains 0 or 1
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 virtual ~GenIDChangeListener() {} 308 virtual ~GenIDChangeListener() {}
286 virtual void onChange() = 0; 309 virtual void onChange() = 0;
287 }; 310 };
288 311
289 void addGenIDChangeListener(GenIDChangeListener* listener); 312 void addGenIDChangeListener(GenIDChangeListener* listener);
290 313
291 SkDEBUGCODE(void validate() const;) 314 SkDEBUGCODE(void validate() const;)
292 315
293 private: 316 private:
294 enum SerializationOffsets { 317 enum SerializationOffsets {
295 kIsRRect_SerializationShift = 26, // requires 1 bit 318 kRRectOrOvalStartIdx_SerializationShift = 28, // requires 3 bits
296 kIsFinite_SerializationShift = 25, // requires 1 bit 319 kRRectOrOvalIsCCW_SerializationShift = 27, // requires 1 bit
297 kIsOval_SerializationShift = 24, // requires 1 bit 320 kIsRRect_SerializationShift = 26, // requires 1 bit
298 kSegmentMask_SerializationShift = 0 // requires 4 bits 321 kIsFinite_SerializationShift = 25, // requires 1 bit
322 kIsOval_SerializationShift = 24, // requires 1 bit
323 kSegmentMask_SerializationShift = 0 // requires 4 bits
299 }; 324 };
300 325
301 SkPathRef() { 326 SkPathRef() {
302 fBoundsIsDirty = true; // this also invalidates fIsFinite 327 fBoundsIsDirty = true; // this also invalidates fIsFinite
303 fPointCnt = 0; 328 fPointCnt = 0;
304 fVerbCnt = 0; 329 fVerbCnt = 0;
305 fVerbs = NULL; 330 fVerbs = NULL;
306 fPoints = NULL; 331 fPoints = NULL;
307 fFreeSpace = 0; 332 fFreeSpace = 0;
308 fGenerationID = kEmptyGenID; 333 fGenerationID = kEmptyGenID;
309 fSegmentMask = 0; 334 fSegmentMask = 0;
310 fIsOval = false; 335 fIsOval = false;
311 fIsRRect = false; 336 fIsRRect = false;
337 SkDEBUGCODE(fRRectOrOvalIsCCW = 0xAB);
338 SkDEBUGCODE(fRRectOrOvalStartIdx = 0xAC);
312 SkDEBUGCODE(fEditorsAttached = 0;) 339 SkDEBUGCODE(fEditorsAttached = 0;)
313 SkDEBUGCODE(this->validate();) 340 SkDEBUGCODE(this->validate();)
314 } 341 }
315 342
316 void copy(const SkPathRef& ref, int additionalReserveVerbs, int additionalRe servePoints); 343 void copy(const SkPathRef& ref, int additionalReserveVerbs, int additionalRe servePoints);
317 344
318 // Return true if the computed bounds are finite. 345 // Return true if the computed bounds are finite.
319 static bool ComputePtBounds(SkRect* bounds, const SkPathRef& ref) { 346 static bool ComputePtBounds(SkRect* bounds, const SkPathRef& ref) {
320 return bounds->setBoundsCheck(ref.points(), ref.countPoints()); 347 return bounds->setBoundsCheck(ref.points(), ref.countPoints());
321 } 348 }
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 */ 474 */
448 size_t currSize() const { 475 size_t currSize() const {
449 return reinterpret_cast<intptr_t>(fVerbs) - reinterpret_cast<intptr_t>(f Points); 476 return reinterpret_cast<intptr_t>(fVerbs) - reinterpret_cast<intptr_t>(f Points);
450 } 477 }
451 478
452 /** 479 /**
453 * Called the first time someone calls CreateEmpty to actually create the si ngleton. 480 * Called the first time someone calls CreateEmpty to actually create the si ngleton.
454 */ 481 */
455 friend SkPathRef* sk_create_empty_pathref(); 482 friend SkPathRef* sk_create_empty_pathref();
456 483
457 void setIsOval(bool isOval) { fIsOval = isOval; } 484 void setIsOval(bool isOval, bool isCCW, unsigned start) {
485 fIsOval = isOval;
486 fRRectOrOvalIsCCW = isCCW;
487 fRRectOrOvalStartIdx = start;
488 }
458 489
459 void setIsRRect(bool isRRect) { fIsRRect = isRRect; } 490 void setIsRRect(bool isRRect, bool isCCW, unsigned start) {
491 fIsRRect = isRRect;
492 fRRectOrOvalIsCCW = isCCW;
493 fRRectOrOvalStartIdx = start;
494 }
460 495
461 // called only by the editor. Note that this is not a const function. 496 // called only by the editor. Note that this is not a const function.
462 SkPoint* getPoints() { 497 SkPoint* getPoints() {
463 SkDEBUGCODE(this->validate();) 498 SkDEBUGCODE(this->validate();)
464 fIsOval = false; 499 fIsOval = false;
465 fIsRRect = false; 500 fIsRRect = false;
466 return fPoints; 501 return fPoints;
467 } 502 }
468 503
469 const SkPoint* getPoints() const { 504 const SkPoint* getPoints() const {
(...skipping 22 matching lines...) Expand all
492 mutable uint32_t fGenerationID; 527 mutable uint32_t fGenerationID;
493 SkDEBUGCODE(int32_t fEditorsAttached;) // assert that only one editor in use at any time. 528 SkDEBUGCODE(int32_t fEditorsAttached;) // assert that only one editor in use at any time.
494 529
495 SkTDArray<GenIDChangeListener*> fGenIDChangeListeners; // pointers are owne d 530 SkTDArray<GenIDChangeListener*> fGenIDChangeListeners; // pointers are owne d
496 531
497 mutable uint8_t fBoundsIsDirty; 532 mutable uint8_t fBoundsIsDirty;
498 mutable SkBool8 fIsFinite; // only meaningful if bounds are valid 533 mutable SkBool8 fIsFinite; // only meaningful if bounds are valid
499 534
500 SkBool8 fIsOval; 535 SkBool8 fIsOval;
501 SkBool8 fIsRRect; 536 SkBool8 fIsRRect;
537 SkBool8 fRRectOrOvalIsCCW;
538 uint8_t fRRectOrOvalStartIdx;
502 uint8_t fSegmentMask; 539 uint8_t fSegmentMask;
503 540
504 friend class PathRefTest_Private; 541 friend class PathRefTest_Private;
505 friend class ForceIsRRect_Private; // unit test isRRect 542 friend class ForceIsRRect_Private; // unit test isRRect
506 typedef SkRefCnt INHERITED; 543 typedef SkRefCnt INHERITED;
507 }; 544 };
508 545
509 #endif 546 #endif
OLDNEW
« no previous file with comments | « include/core/SkPath.h ('k') | src/core/SkPath.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698