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 GrStyle_DEFINED | 8 #ifndef GrStyle_DEFINED |
9 #define GrStyle_DEFINED | 9 #define GrStyle_DEFINED |
10 | 10 |
(...skipping 11 matching lines...) Expand all Loading... |
22 * is handled by drawing a stroke and a fill separately. | 22 * is handled by drawing a stroke and a fill separately. |
23 * | 23 * |
24 * This will replace GrStrokeInfo as GrShape is deployed. | 24 * This will replace GrStrokeInfo as GrShape is deployed. |
25 */ | 25 */ |
26 class GrStyle { | 26 class GrStyle { |
27 public: | 27 public: |
28 GrStyle() : fStrokeRec(SkStrokeRec::kFill_InitStyle) { | 28 GrStyle() : fStrokeRec(SkStrokeRec::kFill_InitStyle) { |
29 fDashInfo.fType = SkPathEffect::kNone_DashType; | 29 fDashInfo.fType = SkPathEffect::kNone_DashType; |
30 } | 30 } |
31 | 31 |
32 GrStyle(const SkStrokeRec& strokeRec, SkPathEffect* pe) : fStrokeRec(strokeR
ec) { | 32 GrStyle(const SkStrokeRec& strokeRec, sk_sp<SkPathEffect> pe) : fStrokeRec(s
trokeRec) { |
33 SkASSERT(SkStrokeRec::kStrokeAndFill_Style != strokeRec.getStyle()); | 33 SkASSERT(SkStrokeRec::kStrokeAndFill_Style != strokeRec.getStyle()); |
34 this->initPathEffect(pe); | 34 this->initPathEffect(std::move(pe)); |
35 } | 35 } |
36 | 36 |
37 GrStyle(const GrStyle& that) : fStrokeRec(SkStrokeRec::kFill_InitStyle) { | 37 GrStyle(const GrStyle& that) : fStrokeRec(SkStrokeRec::kFill_InitStyle) { |
38 *this = that; | 38 *this = that; |
39 } | 39 } |
40 | 40 |
41 explicit GrStyle(const SkPaint& paint) : fStrokeRec(paint) { | 41 explicit GrStyle(const SkPaint& paint) : fStrokeRec(paint) { |
42 SkASSERT(SkStrokeRec::kStrokeAndFill_Style != fStrokeRec.getStyle()); | 42 SkASSERT(SkStrokeRec::kStrokeAndFill_Style != fStrokeRec.getStyle()); |
43 this->initPathEffect(paint.getPathEffect()); | 43 this->initPathEffect(sk_ref_sp(paint.getPathEffect())); |
44 } | 44 } |
45 | 45 |
46 GrStyle& operator=(const GrStyle& that) { | 46 GrStyle& operator=(const GrStyle& that) { |
47 fPathEffect = that.fPathEffect; | 47 fPathEffect = that.fPathEffect; |
48 fDashInfo = that.fDashInfo; | 48 fDashInfo = that.fDashInfo; |
49 fStrokeRec = that.fStrokeRec; | 49 fStrokeRec = that.fStrokeRec; |
50 return *this; | 50 return *this; |
51 } | 51 } |
52 SkPathEffect* pathEffect() const { return fPathEffect.get(); } | 52 SkPathEffect* pathEffect() const { return fPathEffect.get(); } |
53 | 53 |
54 bool isDashed() const { return SkPathEffect::kDash_DashType == fDashInfo.fTy
pe; } | 54 bool isDashed() const { return SkPathEffect::kDash_DashType == fDashInfo.fTy
pe; } |
55 SkScalar dashPhase() const { | 55 SkScalar dashPhase() const { |
56 SkASSERT(this->isDashed()); | 56 SkASSERT(this->isDashed()); |
57 return fDashInfo.fPhase; | 57 return fDashInfo.fPhase; |
58 } | 58 } |
59 int dashIntervalCnt() const { | 59 int dashIntervalCnt() const { |
60 SkASSERT(this->isDashed()); | 60 SkASSERT(this->isDashed()); |
61 return fDashInfo.fIntervals.count(); | 61 return fDashInfo.fIntervals.count(); |
62 } | 62 } |
63 const SkScalar* dashIntervals() const { | 63 const SkScalar* dashIntervals() const { |
64 SkASSERT(this->isDashed()); | 64 SkASSERT(this->isDashed()); |
65 return fDashInfo.fIntervals.get(); | 65 return fDashInfo.fIntervals.get(); |
66 } | 66 } |
67 | 67 |
68 const SkStrokeRec& strokeRec() const { return fStrokeRec; } | 68 const SkStrokeRec& strokeRec() const { return fStrokeRec; } |
69 | 69 |
70 private: | 70 private: |
71 void initPathEffect(SkPathEffect* pe); | 71 void initPathEffect(sk_sp<SkPathEffect> pe); |
72 | 72 |
73 struct DashInfo { | 73 struct DashInfo { |
74 DashInfo& operator=(const DashInfo& that) { | 74 DashInfo& operator=(const DashInfo& that) { |
75 fType = that.fType; | 75 fType = that.fType; |
76 fPhase = that.fPhase; | 76 fPhase = that.fPhase; |
77 fIntervals.reset(that.fIntervals.count()); | 77 fIntervals.reset(that.fIntervals.count()); |
78 memcpy(fIntervals.get(), that.fIntervals.get(), | 78 memcpy(fIntervals.get(), that.fIntervals.get(), |
79 sizeof(SkScalar) * that.fIntervals.count()); | 79 sizeof(SkScalar) * that.fIntervals.count()); |
80 return *this; | 80 return *this; |
81 } | 81 } |
82 SkPathEffect::DashType fType; | 82 SkPathEffect::DashType fType; |
83 SkScalar fPhase; | 83 SkScalar fPhase; |
84 SkAutoSTArray<4, SkScalar> fIntervals; | 84 SkAutoSTArray<4, SkScalar> fIntervals; |
85 }; | 85 }; |
86 | 86 |
87 SkStrokeRec fStrokeRec; | 87 SkStrokeRec fStrokeRec; |
88 sk_sp<SkPathEffect> fPathEffect; | 88 sk_sp<SkPathEffect> fPathEffect; |
89 DashInfo fDashInfo; | 89 DashInfo fDashInfo; |
90 }; | 90 }; |
91 | 91 |
92 #endif | 92 #endif |
OLD | NEW |