OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 "GrStrokeInfo.h" | |
9 #include "GrTestUtils.h" | 8 #include "GrTestUtils.h" |
| 9 #include "GrStyle.h" |
| 10 #include "SkDashPathPriv.h" |
10 #include "SkMatrix.h" | 11 #include "SkMatrix.h" |
11 #include "SkPathEffect.h" | |
12 #include "SkPath.h" | 12 #include "SkPath.h" |
13 #include "SkRRect.h" | 13 #include "SkRRect.h" |
14 | 14 |
15 #ifdef GR_TEST_UTILS | 15 #ifdef GR_TEST_UTILS |
16 | 16 |
17 static const SkMatrix& test_matrix(SkRandom* random, bool includePerspective) { | 17 static const SkMatrix& test_matrix(SkRandom* random, bool includePerspective) { |
18 static SkMatrix gMatrices[5]; | 18 static SkMatrix gMatrices[5]; |
19 static const int kPerspectiveCount = 1; | 19 static const int kPerspectiveCount = 1; |
20 static bool gOnce; | 20 static bool gOnce; |
21 if (!gOnce) { | 21 if (!gOnce) { |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 } | 230 } |
231 | 231 |
232 SkStrokeRec TestStrokeRec(SkRandom* random) { | 232 SkStrokeRec TestStrokeRec(SkRandom* random) { |
233 SkStrokeRec::InitStyle style = | 233 SkStrokeRec::InitStyle style = |
234 SkStrokeRec::InitStyle(random->nextULessThan(SkStrokeRec::kFill_Init
Style + 1)); | 234 SkStrokeRec::InitStyle(random->nextULessThan(SkStrokeRec::kFill_Init
Style + 1)); |
235 SkStrokeRec rec(style); | 235 SkStrokeRec rec(style); |
236 randomize_stroke_rec(&rec, random); | 236 randomize_stroke_rec(&rec, random); |
237 return rec; | 237 return rec; |
238 } | 238 } |
239 | 239 |
240 GrStrokeInfo TestStrokeInfo(SkRandom* random) { | 240 void TestStyle(SkRandom* random, GrStyle* style) { |
241 SkStrokeRec::InitStyle style = | 241 SkStrokeRec::InitStyle initStyle = |
242 SkStrokeRec::InitStyle(random->nextULessThan(SkStrokeRec::kFill_Init
Style + 1)); | 242 SkStrokeRec::InitStyle(random->nextULessThan(SkStrokeRec::kFill_Init
Style + 1)); |
243 GrStrokeInfo strokeInfo(style); | 243 SkStrokeRec stroke(initStyle); |
244 randomize_stroke_rec(&strokeInfo, random); | 244 randomize_stroke_rec(&stroke, random); |
245 SkPathEffect::DashInfo dashInfo; | 245 sk_sp<SkPathEffect> pe; |
246 dashInfo.fCount = random->nextRangeU(1, 50) * 2; | 246 if (random->nextBool()) { |
247 dashInfo.fIntervals = new SkScalar[dashInfo.fCount]; | 247 int cnt = random->nextRangeU(1, 50) * 2; |
248 SkScalar sum = 0; | 248 SkAutoTDeleteArray<SkScalar> intervals(new SkScalar[cnt]); |
249 for (int i = 0; i < dashInfo.fCount; i++) { | 249 SkScalar sum = 0; |
250 dashInfo.fIntervals[i] = random->nextRangeScalar(SkDoubleToScalar(0.01), | 250 for (int i = 0; i < cnt; i++) { |
251 SkDoubleToScalar(10.0))
; | 251 intervals[i] = random->nextRangeScalar(SkDoubleToScalar(0.01), |
252 sum += dashInfo.fIntervals[i]; | 252 SkDoubleToScalar(10.0)); |
| 253 sum += intervals[i]; |
| 254 } |
| 255 SkScalar phase = random->nextRangeScalar(0, sum); |
| 256 pe = TestDashPathEffect::Make(intervals.get(), cnt, phase); |
253 } | 257 } |
254 dashInfo.fPhase = random->nextRangeScalar(0, sum); | 258 *style = GrStyle(stroke, pe.get()); |
255 strokeInfo.setDashInfo(dashInfo); | |
256 delete[] dashInfo.fIntervals; | |
257 return strokeInfo; | |
258 } | 259 } |
259 | 260 |
260 }; | 261 TestDashPathEffect::TestDashPathEffect(const SkScalar* intervals, int count, SkS
calar phase) { |
| 262 fCount = count; |
| 263 fIntervals.reset(count); |
| 264 memcpy(fIntervals.get(), intervals, count * sizeof(SkScalar)); |
| 265 SkDashPath::CalcDashParameters(phase, intervals, count, &fInitialDashLength, |
| 266 &fInitialDashIndex, &fIntervalLength, &fPhase
); |
| 267 } |
| 268 |
| 269 bool TestDashPathEffect::filterPath(SkPath* dst, const SkPath& src, SkStroke
Rec* rec, |
| 270 const SkRect* cullRect) const { |
| 271 return SkDashPath::InternalFilter(dst, src, rec, cullRect, fIntervals.get(),
fCount, |
| 272 fInitialDashLength, fInitialDashIndex, fIn
tervalLength); |
| 273 } |
| 274 |
| 275 SkPathEffect::DashType TestDashPathEffect::asADash(DashInfo* info) const { |
| 276 if (info) { |
| 277 if (info->fCount >= fCount && info->fIntervals) { |
| 278 memcpy(info->fIntervals, fIntervals.get(), fCount * sizeof(SkScalar)
); |
| 279 } |
| 280 info->fCount = fCount; |
| 281 info->fPhase = fPhase; |
| 282 } |
| 283 return kDash_DashType; |
| 284 } |
| 285 |
| 286 |
| 287 } // namespace GrTest |
261 | 288 |
262 #endif | 289 #endif |
OLD | NEW |