OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 GrStrokeInfo_DEFINED | 8 #ifndef GrStrokeInfo_DEFINED |
9 #define GrStrokeInfo_DEFINED | 9 #define GrStrokeInfo_DEFINED |
10 | 10 |
11 #include "SkStrokeRec.h" | 11 #include "SkStrokeRec.h" |
12 #include "SkPathEffect.h" | 12 #include "SkPathEffect.h" |
13 | 13 |
14 /* | 14 /* |
15 * GrStrokeInfo encapsulates the data objects that hold all the pertinent infoma tion | 15 * GrStrokeInfo encapsulates the data objects that hold all the pertinent infoma tion |
16 * regarding the stroke. The two objects are SkStrokeRec which holds information on fill style, | 16 * regarding the stroke. The two objects are SkStrokeRec which holds information on fill style, |
17 * width, miter, cap, and join. The second object is DashInfo. This holds inform ation about the | 17 * width, miter, cap, and join. The second object is DashInfo. This holds inform ation about the |
egdaniel
2015/04/28 14:45:29
update comment
Kimmo Kinnunen
2015/05/04 06:08:07
Done.
| |
18 * dash like intervals, count, and phase. | 18 * dash like intervals, count, and phase. |
19 */ | 19 */ |
20 class GrStrokeInfo { | 20 class GrStrokeInfo { |
21 public: | 21 public: |
22 GrStrokeInfo(SkStrokeRec::InitStyle style) : | 22 GrStrokeInfo(SkStrokeRec::InitStyle style) : |
23 fStroke(style), fDashType(SkPathEffect::kNone_DashType) {} | 23 fStroke(style), fDashType(SkPathEffect::kNone_DashType) {} |
24 | 24 |
25 GrStrokeInfo(const GrStrokeInfo& src, bool includeDash = true) : fStroke(src .fStroke) { | 25 GrStrokeInfo(const GrStrokeInfo& src, bool includeDash = true) : fStroke(src .fStroke) { |
26 if (includeDash) { | 26 if (includeDash && src.isDashed()) { |
27 fDashInfo = src.fDashInfo; | |
28 fDashType = src.fDashType; | 27 fDashType = src.fDashType; |
29 fIntervals.reset(src.dashCount()); | 28 fDashPhase = src.fDashPhase; |
30 memcpy(fIntervals.get(), src.fIntervals.get(), src.dashCount() * siz eof(SkScalar)); | 29 fIntervals.reset(src.getDashCount()); |
30 memcpy(fIntervals.get(), src.fIntervals.get(), fIntervals.count() * sizeof(SkScalar)); | |
31 } else { | 31 } else { |
32 fDashType = SkPathEffect::kNone_DashType; | 32 fDashType = SkPathEffect::kNone_DashType; |
33 } | 33 } |
34 } | 34 } |
35 | 35 |
36 GrStrokeInfo(const SkPaint& paint, SkPaint::Style styleOverride) : | 36 GrStrokeInfo(const SkPaint& paint, SkPaint::Style styleOverride) : |
37 fStroke(paint, styleOverride), fDashType(SkPathEffect::kNone_DashType) { | 37 fStroke(paint, styleOverride), fDashType(SkPathEffect::kNone_DashType) { |
38 this->init(paint); | 38 this->init(paint); |
39 } | 39 } |
40 | 40 |
41 | 41 |
42 explicit GrStrokeInfo(const SkPaint& paint) : | 42 explicit GrStrokeInfo(const SkPaint& paint) : |
43 fStroke(paint), fDashType(SkPathEffect::kNone_DashType) { | 43 fStroke(paint), fDashType(SkPathEffect::kNone_DashType) { |
44 this->init(paint); | 44 this->init(paint); |
45 } | 45 } |
46 | 46 |
47 GrStrokeInfo& operator=(const GrStrokeInfo& other) { | 47 GrStrokeInfo& operator=(const GrStrokeInfo& other) { |
48 if (other.isDashed()) { | |
49 fDashType = other.fDashType; | |
50 fDashPhase = other.fDashPhase; | |
51 fIntervals.reset(other.getDashCount()); | |
52 memcpy(fIntervals.get(), other.fIntervals.get(), fIntervals.count() * sizeof(SkScalar)); | |
53 } else { | |
54 this->removeDash(); | |
55 } | |
48 fStroke = other.fStroke; | 56 fStroke = other.fStroke; |
49 fDashInfo = other.fDashInfo; | |
50 fDashType = other.fDashType; | |
51 fIntervals.reset(other.dashCount()); | |
52 memcpy(fIntervals.get(), other.fIntervals.get(), other.dashCount() * siz eof(SkScalar)); | |
53 return *this; | 57 return *this; |
54 } | 58 } |
55 | 59 |
56 const SkStrokeRec& getStrokeRec() const { return fStroke; } | 60 const SkStrokeRec& getStrokeRec() const { return fStroke; } |
57 | 61 |
58 SkStrokeRec* getStrokeRecPtr() { return &fStroke; } | 62 SkStrokeRec* getStrokeRecPtr() { return &fStroke; } |
59 | 63 |
60 void setFillStyle() { fStroke.setFillStyle(); } | 64 void setFillStyle() { fStroke.setFillStyle(); } |
61 | 65 |
62 /* | 66 /* |
63 * This functions takes in a patheffect and fills in fDashInfo with the vari ous dashing | 67 * This functions takes in a patheffect and fills in fDashInfo with the vari ous dashing |
egdaniel
2015/04/28 14:45:29
update comment
Kimmo Kinnunen
2015/05/04 06:08:07
Done.
| |
64 * information if the path effect is a Dash type. Returns true if the path e ffect is a | 68 * information if the path effect is a Dash type. Returns true if the path e ffect is a |
65 * dashed effect and we are stroking, otherwise it retruns false. | 69 * dashed effect and we are stroking, otherwise it retruns false. |
66 */ | 70 */ |
67 bool setDashInfo(const SkPathEffect* pe) { | 71 bool setDashInfo(const SkPathEffect* pe) { |
68 if (pe && !fStroke.isFillStyle()) { | 72 if (pe && !fStroke.isFillStyle()) { |
69 fDashInfo.fIntervals = NULL; | 73 SkPathEffect::DashInfo dashInfo; |
70 fDashType = pe->asADash(&fDashInfo); | 74 fDashType = pe->asADash(&dashInfo); |
71 if (SkPathEffect::kDash_DashType == fDashType) { | 75 if (SkPathEffect::kDash_DashType == fDashType) { |
72 fIntervals.reset(fDashInfo.fCount); | 76 fIntervals.reset(dashInfo.fCount); |
73 fDashInfo.fIntervals = fIntervals.get(); | 77 dashInfo.fIntervals = fIntervals.get(); |
74 pe->asADash(&fDashInfo); | 78 pe->asADash(&dashInfo); |
79 fDashPhase = dashInfo.fPhase; | |
75 return true; | 80 return true; |
76 } | 81 } |
77 } | 82 } |
78 return false; | 83 return false; |
79 } | 84 } |
80 | 85 |
81 bool isDashed() const { | 86 bool isDashed() const { |
82 return (!fStroke.isFillStyle() && SkPathEffect::kDash_DashType == fDashT ype); | 87 return (!fStroke.isFillStyle() && SkPathEffect::kDash_DashType == fDashT ype); |
83 } | 88 } |
84 | 89 |
85 bool isFillStyle() const { return fStroke.isFillStyle(); } | 90 bool isFillStyle() const { return fStroke.isFillStyle(); } |
86 | 91 |
87 int32_t dashCount() const { | 92 int32_t getDashCount() const { |
88 return fDashInfo.fCount; | 93 SkASSERT(this->isDashed()); |
94 return fIntervals.count(); | |
95 } | |
96 | |
97 SkScalar getDashPhase() const { | |
98 SkASSERT(this->isDashed()); | |
99 return fDashPhase; | |
100 } | |
101 | |
102 const SkScalar* getDashIntervals() const { | |
103 SkASSERT(this->isDashed()); | |
104 return fIntervals.get(); | |
89 } | 105 } |
90 | 106 |
91 void removeDash() { | 107 void removeDash() { |
92 fDashType = SkPathEffect::kNone_DashType; | 108 fDashType = SkPathEffect::kNone_DashType; |
93 } | 109 } |
94 | |
95 const SkPathEffect::DashInfo& getDashInfo() const { return fDashInfo; } | |
96 | 110 |
97 /** Applies the dash to a path, if the stroke info has dashing. | 111 /** Applies the dash to a path, if the stroke info has dashing. |
98 * @return true if the dash ingwas applied (dst and dstStrokeInfo will be mo dified). | 112 * @return true if the dash ingwas applied (dst and dstStrokeInfo will be mo dified). |
99 * false if the stroke info did not have dashing. The dst and dstStr okeInfo | 113 * false if the stroke info did not have dashing. The dst and dstStr okeInfo |
100 * will be unmodified. The stroking in the SkStrokeRec might s till | 114 * will be unmodified. The stroking in the SkStrokeRec might s till |
101 * be applicable. | 115 * be applicable. |
102 */ | 116 */ |
103 bool applyDash(SkPath* dst, GrStrokeInfo* dstStrokeInfo, const SkPath& src) const; | 117 bool applyDash(SkPath* dst, GrStrokeInfo* dstStrokeInfo, const SkPath& src) const; |
104 | 118 |
105 private: | 119 private: |
106 | 120 |
107 void init(const SkPaint& paint) { | 121 void init(const SkPaint& paint) { |
108 const SkPathEffect* pe = paint.getPathEffect(); | 122 const SkPathEffect* pe = paint.getPathEffect(); |
109 this->setDashInfo(pe); | 123 this->setDashInfo(pe); |
110 } | 124 } |
111 | 125 |
112 SkStrokeRec fStroke; | 126 SkStrokeRec fStroke; |
113 SkPathEffect::DashType fDashType; | 127 SkPathEffect::DashType fDashType; |
114 SkPathEffect::DashInfo fDashInfo; | 128 SkScalar fDashPhase; |
115 SkAutoSTArray<2, SkScalar> fIntervals; | 129 SkAutoSTArray<2, SkScalar> fIntervals; |
116 }; | 130 }; |
117 | 131 |
118 #endif | 132 #endif |
OLD | NEW |