| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef SkRRect_DEFINED | 8 #ifndef SkRRect_DEFINED |
| 9 #define SkRRect_DEFINED | 9 #define SkRRect_DEFINED |
| 10 | 10 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 setRectRadii, etc.) | 40 setRectRadii, etc.) |
| 41 | 41 |
| 42 This class is intended to roughly match CSS' border-*-*-radius capabilities. | 42 This class is intended to roughly match CSS' border-*-*-radius capabilities. |
| 43 This means: | 43 This means: |
| 44 If either of a corner's radii are 0 the corner will be square. | 44 If either of a corner's radii are 0 the corner will be square. |
| 45 Negative radii are not allowed (they are clamped to zero). | 45 Negative radii are not allowed (they are clamped to zero). |
| 46 If the corner curves overlap they will be proportionally reduced to fit. | 46 If the corner curves overlap they will be proportionally reduced to fit. |
| 47 */ | 47 */ |
| 48 class SK_API SkRRect { | 48 class SK_API SkRRect { |
| 49 public: | 49 public: |
| 50 SkRRect() { /* unititialized */ } |
| 51 SkRRect(const SkRRect&) = default; |
| 52 SkRRect& operator=(const SkRRect&) = default; |
| 53 |
| 50 /** | 54 /** |
| 51 * Enum to capture the various possible subtypes of RR. Accessed | 55 * Enum to capture the various possible subtypes of RR. Accessed |
| 52 * by type(). The subtypes become progressively less restrictive. | 56 * by type(). The subtypes become progressively less restrictive. |
| 53 */ | 57 */ |
| 54 enum Type { | 58 enum Type { |
| 55 // !< The RR is empty | 59 // !< The RR is empty |
| 56 kEmpty_Type, | 60 kEmpty_Type, |
| 57 | 61 |
| 58 //!< The RR is actually a (non-empty) rect (i.e., at least one radius | 62 //!< The RR is actually a (non-empty) rect (i.e., at least one radius |
| 59 //!< at each corner is zero) | 63 //!< at each corner is zero) |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 this->inset(-dx, -dy, this); | 271 this->inset(-dx, -dy, this); |
| 268 } | 272 } |
| 269 | 273 |
| 270 /** | 274 /** |
| 271 * Translate the rrect by (dx, dy). | 275 * Translate the rrect by (dx, dy). |
| 272 */ | 276 */ |
| 273 void offset(SkScalar dx, SkScalar dy) { | 277 void offset(SkScalar dx, SkScalar dy) { |
| 274 fRect.offset(dx, dy); | 278 fRect.offset(dx, dy); |
| 275 } | 279 } |
| 276 | 280 |
| 281 SkRRect SK_WARN_UNUSED_RESULT makeOffset(SkScalar dx, SkScalar dy) const { |
| 282 return SkRRect(fRect.makeOffset(dx, dy), fRadii, fType); |
| 283 } |
| 284 |
| 277 /** | 285 /** |
| 278 * Returns true if 'rect' is wholy inside the RR, and both | 286 * Returns true if 'rect' is wholy inside the RR, and both |
| 279 * are not empty. | 287 * are not empty. |
| 280 */ | 288 */ |
| 281 bool contains(const SkRect& rect) const; | 289 bool contains(const SkRect& rect) const; |
| 282 | 290 |
| 283 SkDEBUGCODE(void validate() const;) | 291 SkDEBUGCODE(void validate() const;) |
| 284 | 292 |
| 285 enum { | 293 enum { |
| 286 kSizeInMemory = 12 * sizeof(SkScalar) | 294 kSizeInMemory = 12 * sizeof(SkScalar) |
| (...skipping 28 matching lines...) Expand all Loading... |
| 315 * which would make this function no longer const. | 323 * which would make this function no longer const. |
| 316 * @return true on success, false on failure. If false, dst is unmodified. | 324 * @return true on success, false on failure. If false, dst is unmodified. |
| 317 */ | 325 */ |
| 318 bool transform(const SkMatrix& matrix, SkRRect* dst) const; | 326 bool transform(const SkMatrix& matrix, SkRRect* dst) const; |
| 319 | 327 |
| 320 void dump(bool asHex) const; | 328 void dump(bool asHex) const; |
| 321 void dump() const { this->dump(false); } | 329 void dump() const { this->dump(false); } |
| 322 void dumpHex() const { this->dump(true); } | 330 void dumpHex() const { this->dump(true); } |
| 323 | 331 |
| 324 private: | 332 private: |
| 333 SkRRect(const SkRect& rect, const SkVector radii[4], int32_t type) |
| 334 : fRect(rect) |
| 335 , fRadii{radii[0], radii[1], radii[2], radii[3]} |
| 336 , fType(type) {} |
| 337 |
| 325 SkRect fRect; | 338 SkRect fRect; |
| 326 // Radii order is UL, UR, LR, LL. Use Corner enum to index into fRadii[] | 339 // Radii order is UL, UR, LR, LL. Use Corner enum to index into fRadii[] |
| 327 SkVector fRadii[4]; | 340 SkVector fRadii[4]; |
| 328 // use an explicitly sized type so we're sure the class is dense (no uniniti
alized bytes) | 341 // use an explicitly sized type so we're sure the class is dense (no uniniti
alized bytes) |
| 329 int32_t fType; | 342 int32_t fType; |
| 330 // TODO: add padding so we can use memcpy for flattening and not copy | 343 // TODO: add padding so we can use memcpy for flattening and not copy |
| 331 // uninitialized data | 344 // uninitialized data |
| 332 | 345 |
| 333 void computeType(); | 346 void computeType(); |
| 334 bool checkCornerContainment(SkScalar x, SkScalar y) const; | 347 bool checkCornerContainment(SkScalar x, SkScalar y) const; |
| 335 void scaleRadii(); | 348 void scaleRadii(); |
| 336 | 349 |
| 337 // to access fRadii directly | 350 // to access fRadii directly |
| 338 friend class SkPath; | 351 friend class SkPath; |
| 339 }; | 352 }; |
| 340 | 353 |
| 341 #endif | 354 #endif |
| OLD | NEW |