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" |
10 #include "SkMatrix.h" | 9 #include "SkMatrix.h" |
11 #include "SkPathEffect.h" | |
12 #include "SkPath.h" | 10 #include "SkPath.h" |
13 #include "SkRRect.h" | 11 #include "SkRRect.h" |
14 | 12 |
15 #ifdef GR_TEST_UTILS | 13 #ifdef GR_TEST_UTILS |
16 | 14 |
17 static const SkMatrix& test_matrix(SkRandom* random, bool includePerspective) { | 15 static const SkMatrix& test_matrix(SkRandom* random, bool includePerspective) { |
18 static SkMatrix gMatrices[5]; | 16 static SkMatrix gMatrices[5]; |
19 static const int kPerspectiveCount = 1; | 17 static const int kPerspectiveCount = 1; |
20 static bool gOnce; | 18 static bool gOnce; |
21 if (!gOnce) { | 19 if (!gOnce) { |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 gPath[2].lineTo(-50.0f, 31.0f); | 209 gPath[2].lineTo(-50.0f, 31.0f); |
212 | 210 |
213 for (size_t i = 0; i < SK_ARRAY_COUNT(gPath); i++) { | 211 for (size_t i = 0; i < SK_ARRAY_COUNT(gPath); i++) { |
214 SkASSERT(SkPath::kConvex_Convexity == gPath[i].getConvexity()); | 212 SkASSERT(SkPath::kConvex_Convexity == gPath[i].getConvexity()); |
215 } | 213 } |
216 } | 214 } |
217 | 215 |
218 return gPath[random->nextULessThan(static_cast<uint32_t>(SK_ARRAY_COUNT(gPat
h)))]; | 216 return gPath[random->nextULessThan(static_cast<uint32_t>(SK_ARRAY_COUNT(gPat
h)))]; |
219 } | 217 } |
220 | 218 |
221 static void randomize_stroke_rec(SkStrokeRec* rec, SkRandom* random) { | |
222 bool strokeAndFill = random->nextBool(); | |
223 SkScalar strokeWidth = random->nextBool() ? 0.f : 1.f; | |
224 rec->setStrokeStyle(strokeWidth, strokeAndFill); | |
225 | |
226 SkPaint::Cap cap = SkPaint::Cap(random->nextULessThan(SkPaint::kCapCount)); | |
227 SkPaint::Join join = SkPaint::Join(random->nextULessThan(SkPaint::kJoinCount
)); | |
228 SkScalar miterLimit = random->nextRangeScalar(1.f, 5.f); | |
229 rec->setStrokeParams(cap, join, miterLimit); | |
230 } | |
231 | |
232 SkStrokeRec TestStrokeRec(SkRandom* random) { | 219 SkStrokeRec TestStrokeRec(SkRandom* random) { |
233 SkStrokeRec::InitStyle style = | 220 SkStrokeRec::InitStyle style = |
234 SkStrokeRec::InitStyle(random->nextULessThan(SkStrokeRec::kFill_Init
Style + 1)); | 221 SkStrokeRec::InitStyle(random->nextULessThan(SkStrokeRec::kFill_Init
Style + 1)); |
235 SkStrokeRec rec(style); | 222 SkStrokeRec rec(style); |
236 randomize_stroke_rec(&rec, random); | 223 bool strokeAndFill = random->nextBool(); |
| 224 SkScalar strokeWidth = random->nextBool() ? 0.f : 1.f; |
| 225 rec.setStrokeStyle(strokeWidth, strokeAndFill); |
| 226 |
| 227 SkPaint::Cap cap = SkPaint::Cap(random->nextULessThan(SkPaint::kCapCount)); |
| 228 SkPaint::Join join = SkPaint::Join(random->nextULessThan(SkPaint::kJoinCount
)); |
| 229 SkScalar miterLimit = random->nextRangeScalar(1.f, 5.f); |
| 230 rec.setStrokeParams(cap, join, miterLimit); |
237 return rec; | 231 return rec; |
238 } | 232 } |
239 | 233 |
240 GrStrokeInfo TestStrokeInfo(SkRandom* random) { | |
241 SkStrokeRec::InitStyle style = | |
242 SkStrokeRec::InitStyle(random->nextULessThan(SkStrokeRec::kFill_Init
Style + 1)); | |
243 GrStrokeInfo strokeInfo(style); | |
244 randomize_stroke_rec(&strokeInfo, random); | |
245 SkPathEffect::DashInfo dashInfo; | |
246 dashInfo.fCount = random->nextRangeU(1, 100); | |
247 dashInfo.fIntervals = SkNEW_ARRAY(SkScalar, dashInfo.fCount); | |
248 SkScalar sum = 0; | |
249 for (int i = 0; i < dashInfo.fCount; i++) { | |
250 dashInfo.fIntervals[i] = random->nextRangeScalar(SkDoubleToScalar(0.01), | |
251 SkDoubleToScalar(10.0))
; | |
252 sum += dashInfo.fIntervals[i]; | |
253 } | |
254 dashInfo.fPhase = random->nextRangeScalar(0, sum); | |
255 strokeInfo.setDashInfo(dashInfo); | |
256 return strokeInfo; | |
257 } | |
258 | |
259 }; | 234 }; |
260 | 235 |
261 #endif | 236 #endif |
OLD | NEW |