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 #include "GrStyle.h" | 8 #include "GrStyle.h" |
| 9 #include "SkDashPathPriv.h" |
9 | 10 |
10 int GrStyle::KeySize(const GrStyle &style, Apply apply, uint32_t flags) { | 11 int GrStyle::KeySize(const GrStyle &style, Apply apply, uint32_t flags) { |
11 GR_STATIC_ASSERT(sizeof(uint32_t) == sizeof(SkScalar)); | 12 GR_STATIC_ASSERT(sizeof(uint32_t) == sizeof(SkScalar)); |
12 int size = 0; | 13 int size = 0; |
13 if (style.isDashed()) { | 14 if (style.isDashed()) { |
14 // One scalar for scale, one for dash phase, and one for each dash value
. | 15 // One scalar for scale, one for dash phase, and one for each dash value
. |
15 size += 2 + style.dashIntervalCnt(); | 16 size += 2 + style.dashIntervalCnt(); |
16 } else if (style.pathEffect()) { | 17 } else if (style.pathEffect()) { |
17 // No key for a generic path effect. | 18 // No key for a generic path effect. |
18 return -1; | 19 return -1; |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 fDashInfo.fPhase = info.fPhase; | 114 fDashInfo.fPhase = info.fPhase; |
114 info.fIntervals = fDashInfo.fIntervals.get(); | 115 info.fIntervals = fDashInfo.fIntervals.get(); |
115 pe->asADash(&info); | 116 pe->asADash(&info); |
116 fPathEffect.reset(SkSafeRef(pe)); | 117 fPathEffect.reset(SkSafeRef(pe)); |
117 } | 118 } |
118 } else { | 119 } else { |
119 fPathEffect.reset(SkSafeRef(pe)); | 120 fPathEffect.reset(SkSafeRef(pe)); |
120 } | 121 } |
121 } | 122 } |
122 | 123 |
123 static inline bool apply_path_effect(SkPath* dst, SkStrokeRec* strokeRec, | 124 bool GrStyle::applyPathEffect(SkPath* dst, SkStrokeRec* strokeRec, const SkPath&
src) const { |
124 const sk_sp<SkPathEffect>& pe, const SkPath
& src) { | 125 if (!fPathEffect) { |
125 if (!pe) { | |
126 return false; | 126 return false; |
127 } | 127 } |
128 if (!pe->filterPath(dst, src, strokeRec, nullptr)) { | 128 if (SkPathEffect::kDash_DashType == fDashInfo.fType) { |
| 129 // We apply the dash ourselves here rather than using the path effect. T
his is so that |
| 130 // we can control whether the dasher applies the strokeRec for special c
ases. Our keying |
| 131 // depends on the strokeRec being applied separately. |
| 132 SkScalar phase = fDashInfo.fPhase; |
| 133 const SkScalar* intervals = fDashInfo.fIntervals.get(); |
| 134 int intervalCnt = fDashInfo.fIntervals.count(); |
| 135 SkScalar initialLength; |
| 136 int initialIndex; |
| 137 SkScalar intervalLength; |
| 138 SkDashPath::CalcDashParameters(phase, intervals, intervalCnt, &initialLe
ngth, |
| 139 &initialIndex, &intervalLength); |
| 140 if (!SkDashPath::InternalFilter(dst, src, strokeRec, |
| 141 nullptr, intervals, intervalCnt, |
| 142 initialLength, initialIndex, intervalLen
gth, |
| 143 SkDashPath::StrokeRecApplication::kDisal
low)) { |
| 144 return false; |
| 145 } |
| 146 } else if (!fPathEffect->filterPath(dst, src, strokeRec, nullptr)) { |
129 return false; | 147 return false; |
130 } | 148 } |
131 dst->setIsVolatile(true); | 149 dst->setIsVolatile(true); |
132 return true; | 150 return true; |
133 } | 151 } |
134 | 152 |
135 bool GrStyle::applyPathEffectToPath(SkPath *dst, SkStrokeRec *remainingStroke, | 153 bool GrStyle::applyPathEffectToPath(SkPath *dst, SkStrokeRec *remainingStroke, |
136 const SkPath &src, SkScalar resScale) const
{ | 154 const SkPath &src, SkScalar resScale) const
{ |
137 SkASSERT(dst); | 155 SkASSERT(dst); |
138 SkStrokeRec strokeRec = fStrokeRec; | 156 SkStrokeRec strokeRec = fStrokeRec; |
139 strokeRec.setResScale(resScale); | 157 strokeRec.setResScale(resScale); |
140 if (!apply_path_effect(dst, &strokeRec, fPathEffect, src)) { | 158 if (!this->applyPathEffect(dst, &strokeRec, src)) { |
141 return false; | 159 return false; |
142 } | 160 } |
143 *remainingStroke = strokeRec; | 161 *remainingStroke = strokeRec; |
144 return true; | 162 return true; |
145 } | 163 } |
146 | 164 |
147 bool GrStyle::applyToPath(SkPath* dst, SkStrokeRec::InitStyle* style, const SkPa
th& src, | 165 bool GrStyle::applyToPath(SkPath* dst, SkStrokeRec::InitStyle* style, const SkPa
th& src, |
148 SkScalar resScale) const { | 166 SkScalar resScale) const { |
149 SkASSERT(style); | 167 SkASSERT(style); |
150 SkASSERT(dst); | 168 SkASSERT(dst); |
151 SkStrokeRec strokeRec = fStrokeRec; | 169 SkStrokeRec strokeRec = fStrokeRec; |
152 strokeRec.setResScale(resScale); | 170 strokeRec.setResScale(resScale); |
153 const SkPath* pathForStrokeRec = &src; | 171 const SkPath* pathForStrokeRec = &src; |
154 if (apply_path_effect(dst, &strokeRec, fPathEffect, src)) { | 172 if (this->applyPathEffect(dst, &strokeRec, src)) { |
155 pathForStrokeRec = dst; | 173 pathForStrokeRec = dst; |
156 } else if (fPathEffect) { | 174 } else if (fPathEffect) { |
157 return false; | 175 return false; |
158 } | 176 } |
159 if (strokeRec.needToApply()) { | 177 if (strokeRec.needToApply()) { |
160 if (!strokeRec.applyToPath(dst, *pathForStrokeRec)) { | 178 if (!strokeRec.applyToPath(dst, *pathForStrokeRec)) { |
161 return false; | 179 return false; |
162 } | 180 } |
163 *style = SkStrokeRec::kFill_InitStyle; | 181 *style = SkStrokeRec::kFill_InitStyle; |
164 } else if (!fPathEffect) { | 182 } else if (!fPathEffect) { |
165 // Nothing to do for path effect or stroke, fail. | 183 // Nothing to do for path effect or stroke, fail. |
166 return false; | 184 return false; |
167 } else { | 185 } else { |
168 SkASSERT(SkStrokeRec::kFill_Style == strokeRec.getStyle() || | 186 SkASSERT(SkStrokeRec::kFill_Style == strokeRec.getStyle() || |
169 SkStrokeRec::kHairline_Style == strokeRec.getStyle()); | 187 SkStrokeRec::kHairline_Style == strokeRec.getStyle()); |
170 *style = strokeRec.getStyle() == SkStrokeRec::kFill_Style | 188 *style = strokeRec.getStyle() == SkStrokeRec::kFill_Style |
171 ? SkStrokeRec::kFill_InitStyle | 189 ? SkStrokeRec::kFill_InitStyle |
172 : SkStrokeRec::kHairline_InitStyle; | 190 : SkStrokeRec::kHairline_InitStyle; |
173 } | 191 } |
174 return true; | 192 return true; |
175 } | 193 } |
OLD | NEW |