| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 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 GrShape_DEFINED | 8 #ifndef GrShape_DEFINED |
| 9 #define GrShape_DEFINED | 9 #define GrShape_DEFINED |
| 10 | 10 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 * applying style to the geometry. The idea is to expand this to cover most or a
ll of the geometries | 32 * applying style to the geometry. The idea is to expand this to cover most or a
ll of the geometries |
| 33 * that have SkCanvas::draw APIs. | 33 * that have SkCanvas::draw APIs. |
| 34 */ | 34 */ |
| 35 class GrShape { | 35 class GrShape { |
| 36 public: | 36 public: |
| 37 GrShape() : fType(Type::kEmpty) {} | 37 GrShape() : fType(Type::kEmpty) {} |
| 38 | 38 |
| 39 explicit GrShape(const SkPath& path) | 39 explicit GrShape(const SkPath& path) |
| 40 : fType(Type::kPath) | 40 : fType(Type::kPath) |
| 41 , fPath(&path) { | 41 , fPath(&path) { |
| 42 this->attemptToReduceFromPath(); | 42 this->attemptToSimplifyPath(); |
| 43 } | 43 } |
| 44 | 44 |
| 45 explicit GrShape(const SkRRect& rrect) | 45 explicit GrShape(const SkRRect& rrect) |
| 46 : fType(Type::kRRect) | 46 : fType(Type::kRRect) |
| 47 , fRRect(rrect) | 47 , fRRect(rrect) |
| 48 , fRRectIsInverted(false) { | 48 , fRRectIsInverted(false) { |
| 49 fRRectStart = DefaultRRectDirAndStartIndex(rrect, false, &fRRectDir); | 49 fRRectStart = DefaultRRectDirAndStartIndex(rrect, false, &fRRectDir); |
| 50 this->attemptToReduceFromRRect(); | 50 this->attemptToSimplifyRRect(); |
| 51 } | 51 } |
| 52 | 52 |
| 53 explicit GrShape(const SkRect& rect) | 53 explicit GrShape(const SkRect& rect) |
| 54 : fType(Type::kRRect) | 54 : fType(Type::kRRect) |
| 55 , fRRect(SkRRect::MakeRect(rect)) | 55 , fRRect(SkRRect::MakeRect(rect)) |
| 56 , fRRectIsInverted(false) { | 56 , fRRectIsInverted(false) { |
| 57 fRRectStart = DefaultRectDirAndStartIndex(rect, false, &fRRectDir); | 57 fRRectStart = DefaultRectDirAndStartIndex(rect, false, &fRRectDir); |
| 58 this->attemptToReduceFromRRect(); | 58 this->attemptToSimplifyRRect(); |
| 59 } | 59 } |
| 60 | 60 |
| 61 GrShape(const SkPath& path, const GrStyle& style) | 61 GrShape(const SkPath& path, const GrStyle& style) |
| 62 : fType(Type::kPath) | 62 : fType(Type::kPath) |
| 63 , fPath(&path) | 63 , fPath(&path) |
| 64 , fStyle(style) { | 64 , fStyle(style) { |
| 65 this->attemptToReduceFromPath(); | 65 this->attemptToSimplifyPath(); |
| 66 } | 66 } |
| 67 | 67 |
| 68 GrShape(const SkRRect& rrect, const GrStyle& style) | 68 GrShape(const SkRRect& rrect, const GrStyle& style) |
| 69 : fType(Type::kRRect) | 69 : fType(Type::kRRect) |
| 70 , fRRect(rrect) | 70 , fRRect(rrect) |
| 71 , fRRectIsInverted(false) | 71 , fRRectIsInverted(false) |
| 72 , fStyle(style) { | 72 , fStyle(style) { |
| 73 fRRectStart = DefaultRRectDirAndStartIndex(rrect, style.hasPathEffect(),
&fRRectDir); | 73 fRRectStart = DefaultRRectDirAndStartIndex(rrect, style.hasPathEffect(),
&fRRectDir); |
| 74 this->attemptToReduceFromRRect(); | 74 this->attemptToSimplifyRRect(); |
| 75 } | 75 } |
| 76 | 76 |
| 77 GrShape(const SkRRect& rrect, SkPath::Direction dir, unsigned start, bool in
verted, | 77 GrShape(const SkRRect& rrect, SkPath::Direction dir, unsigned start, bool in
verted, |
| 78 const GrStyle& style) | 78 const GrStyle& style) |
| 79 : fType(Type::kRRect) | 79 : fType(Type::kRRect) |
| 80 , fRRect(rrect) | 80 , fRRect(rrect) |
| 81 , fRRectIsInverted(inverted) | 81 , fRRectIsInverted(inverted) |
| 82 , fStyle(style) { | 82 , fStyle(style) { |
| 83 if (style.pathEffect()) { | 83 if (style.pathEffect()) { |
| 84 fRRectDir = dir; | 84 fRRectDir = dir; |
| 85 fRRectStart = start; | 85 fRRectStart = start; |
| 86 if (fRRect.getType() == SkRRect::kRect_Type) { | 86 if (fRRect.getType() == SkRRect::kRect_Type) { |
| 87 fRRectStart = (fRRectStart + 1) & 0b110; | 87 fRRectStart = (fRRectStart + 1) & 0b110; |
| 88 } else if (fRRect.getType() == SkRRect::kOval_Type) { | 88 } else if (fRRect.getType() == SkRRect::kOval_Type) { |
| 89 fRRectStart &= 0b110; | 89 fRRectStart &= 0b110; |
| 90 } | 90 } |
| 91 } else { | 91 } else { |
| 92 fRRectStart = DefaultRRectDirAndStartIndex(rrect, false, &fRRectDir)
; | 92 fRRectStart = DefaultRRectDirAndStartIndex(rrect, false, &fRRectDir)
; |
| 93 } | 93 } |
| 94 this->attemptToReduceFromRRect(); | 94 this->attemptToSimplifyRRect(); |
| 95 } | 95 } |
| 96 | 96 |
| 97 GrShape(const SkRect& rect, const GrStyle& style) | 97 GrShape(const SkRect& rect, const GrStyle& style) |
| 98 : fType(Type::kRRect) | 98 : fType(Type::kRRect) |
| 99 , fRRect(SkRRect::MakeRect(rect)) | 99 , fRRect(SkRRect::MakeRect(rect)) |
| 100 , fRRectIsInverted(false) | 100 , fRRectIsInverted(false) |
| 101 , fStyle(style) { | 101 , fStyle(style) { |
| 102 fRRectStart = DefaultRectDirAndStartIndex(rect, style.hasPathEffect(), &
fRRectDir); | 102 fRRectStart = DefaultRectDirAndStartIndex(rect, style.hasPathEffect(), &
fRRectDir); |
| 103 this->attemptToReduceFromRRect(); | 103 this->attemptToSimplifyRRect(); |
| 104 } | 104 } |
| 105 | 105 |
| 106 GrShape(const SkPath& path, const SkPaint& paint) | 106 GrShape(const SkPath& path, const SkPaint& paint) |
| 107 : fType(Type::kPath) | 107 : fType(Type::kPath) |
| 108 , fPath(&path) | 108 , fPath(&path) |
| 109 , fStyle(paint) { | 109 , fStyle(paint) { |
| 110 this->attemptToReduceFromPath(); | 110 this->attemptToSimplifyPath(); |
| 111 } | 111 } |
| 112 | 112 |
| 113 GrShape(const SkRRect& rrect, const SkPaint& paint) | 113 GrShape(const SkRRect& rrect, const SkPaint& paint) |
| 114 : fType(Type::kRRect) | 114 : fType(Type::kRRect) |
| 115 , fRRect(rrect) | 115 , fRRect(rrect) |
| 116 , fRRectIsInverted(false) | 116 , fRRectIsInverted(false) |
| 117 , fStyle(paint) { | 117 , fStyle(paint) { |
| 118 fRRectStart = DefaultRRectDirAndStartIndex(rrect, fStyle.hasPathEffect()
, &fRRectDir); | 118 fRRectStart = DefaultRRectDirAndStartIndex(rrect, fStyle.hasPathEffect()
, &fRRectDir); |
| 119 this->attemptToReduceFromRRect(); | 119 this->attemptToSimplifyRRect(); |
| 120 } | 120 } |
| 121 | 121 |
| 122 GrShape(const SkRect& rect, const SkPaint& paint) | 122 GrShape(const SkRect& rect, const SkPaint& paint) |
| 123 : fType(Type::kRRect) | 123 : fType(Type::kRRect) |
| 124 , fRRect(SkRRect::MakeRect(rect)) | 124 , fRRect(SkRRect::MakeRect(rect)) |
| 125 , fRRectIsInverted(false) | 125 , fRRectIsInverted(false) |
| 126 , fStyle(paint) { | 126 , fStyle(paint) { |
| 127 fRRectStart = DefaultRectDirAndStartIndex(rect, fStyle.hasPathEffect(),
&fRRectDir); | 127 fRRectStart = DefaultRectDirAndStartIndex(rect, fStyle.hasPathEffect(),
&fRRectDir); |
| 128 this->attemptToReduceFromRRect(); | 128 this->attemptToSimplifyRRect(); |
| 129 } | 129 } |
| 130 | 130 |
| 131 GrShape(const GrShape&); | 131 GrShape(const GrShape&); |
| 132 GrShape& operator=(const GrShape& that); | 132 GrShape& operator=(const GrShape& that); |
| 133 | 133 |
| 134 ~GrShape() { | 134 ~GrShape() { |
| 135 if (Type::kPath == fType) { | 135 if (Type::kPath == fType) { |
| 136 fPath.reset(); | 136 fPath.reset(); |
| 137 } | 137 } |
| 138 } | 138 } |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 | 271 |
| 272 /** Constructor used by the applyStyle() function */ | 272 /** Constructor used by the applyStyle() function */ |
| 273 GrShape(const GrShape& parentShape, GrStyle::Apply, SkScalar scale); | 273 GrShape(const GrShape& parentShape, GrStyle::Apply, SkScalar scale); |
| 274 | 274 |
| 275 /** | 275 /** |
| 276 * Determines the key we should inherit from the input shape's geometry and
style when | 276 * Determines the key we should inherit from the input shape's geometry and
style when |
| 277 * we are applying the style to create a new shape. | 277 * we are applying the style to create a new shape. |
| 278 */ | 278 */ |
| 279 void setInheritedKey(const GrShape& parentShape, GrStyle::Apply, SkScalar sc
ale); | 279 void setInheritedKey(const GrShape& parentShape, GrStyle::Apply, SkScalar sc
ale); |
| 280 | 280 |
| 281 void attemptToReduceFromPath() { | 281 void attemptToSimplifyPath(); |
| 282 SkASSERT(Type::kPath == fType); | |
| 283 fType = AttemptToReduceFromPathImpl(*fPath.get(), &fRRect, &fRRectDir, &
fRRectStart, | |
| 284 &fRRectIsInverted, fStyle.pathEffect
(), | |
| 285 fStyle.strokeRec()); | |
| 286 if (Type::kPath != fType) { | |
| 287 fPath.reset(); | |
| 288 fInheritedKey.reset(0); | |
| 289 } | |
| 290 } | |
| 291 | 282 |
| 292 void attemptToReduceFromRRect() { | 283 void attemptToSimplifyRRect(); |
| 293 SkASSERT(Type::kRRect == fType); | |
| 294 SkASSERT(!fInheritedKey.count()); | |
| 295 if (fRRectIsInverted) { | |
| 296 if (fStyle.isDashed()) { | |
| 297 // Dashing ignores the inverseness (currently). skbug.com/5421 | |
| 298 fRRectIsInverted = false; | |
| 299 } | |
| 300 } else if (fRRect.isEmpty()) { | |
| 301 fType = Type::kEmpty; | |
| 302 } | |
| 303 } | |
| 304 | |
| 305 static Type AttemptToReduceFromPathImpl(const SkPath& path, SkRRect* rrect, | |
| 306 SkPath::Direction* rrectDir, unsigne
d* rrectStart, | |
| 307 bool* rrectIsInverted, const SkPathE
ffect* pe, | |
| 308 const SkStrokeRec& strokeRec); | |
| 309 | 284 |
| 310 static constexpr SkPath::Direction kDefaultRRectDir = SkPath::kCW_Direction; | 285 static constexpr SkPath::Direction kDefaultRRectDir = SkPath::kCW_Direction; |
| 311 static constexpr unsigned kDefaultRRectStart = 0; | 286 static constexpr unsigned kDefaultRRectStart = 0; |
| 312 | 287 |
| 313 static unsigned DefaultRectDirAndStartIndex(const SkRect& rect, bool hasPath
Effect, | 288 static unsigned DefaultRectDirAndStartIndex(const SkRect& rect, bool hasPath
Effect, |
| 314 SkPath::Direction* dir) { | 289 SkPath::Direction* dir) { |
| 315 *dir = kDefaultRRectDir; | 290 *dir = kDefaultRRectDir; |
| 316 // This comes from SkPath's interface. The default for adding a SkRect i
s counter clockwise | 291 // This comes from SkPath's interface. The default for adding a SkRect i
s counter clockwise |
| 317 // beginning at index 0 (which happens to correspond to rrect index 0 or
7). | 292 // beginning at index 0 (which happens to correspond to rrect index 0 or
7). |
| 318 if (!hasPathEffect) { | 293 if (!hasPathEffect) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 Type fType; | 330 Type fType; |
| 356 SkRRect fRRect; | 331 SkRRect fRRect; |
| 357 SkPath::Direction fRRectDir; | 332 SkPath::Direction fRRectDir; |
| 358 unsigned fRRectStart; | 333 unsigned fRRectStart; |
| 359 bool fRRectIsInverted; | 334 bool fRRectIsInverted; |
| 360 SkTLazy<SkPath> fPath; | 335 SkTLazy<SkPath> fPath; |
| 361 GrStyle fStyle; | 336 GrStyle fStyle; |
| 362 SkAutoSTArray<8, uint32_t> fInheritedKey; | 337 SkAutoSTArray<8, uint32_t> fInheritedKey; |
| 363 }; | 338 }; |
| 364 #endif | 339 #endif |
| OLD | NEW |