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 #ifndef GrTestUtils_DEFINED | 8 #ifndef GrTestUtils_DEFINED |
9 #define GrTestUtils_DEFINED | 9 #define GrTestUtils_DEFINED |
10 | 10 |
11 #include "SkTypes.h" | 11 #include "SkTypes.h" |
12 | 12 |
13 #ifdef GR_TEST_UTILS | 13 #ifdef GR_TEST_UTILS |
14 | 14 |
15 #include "GrColor.h" | 15 #include "GrColor.h" |
| 16 #include "SkPathEffect.h" |
16 #include "SkRandom.h" | 17 #include "SkRandom.h" |
17 #include "SkStrokeRec.h" | 18 #include "SkStrokeRec.h" |
| 19 #include "../private/SkTemplates.h" |
18 | 20 |
19 class GrStrokeInfo; | 21 class GrStyle; |
20 class SkMatrix; | 22 class SkMatrix; |
21 class SkPath; | 23 class SkPath; |
22 class SkRRect; | 24 class SkRRect; |
23 struct SkRect; | 25 struct SkRect; |
24 | 26 |
25 namespace GrTest { | 27 namespace GrTest { |
26 /** | 28 /** |
27 * A helper for use in Test functions. | 29 * Helpers for use in Test functions. |
28 */ | 30 */ |
29 const SkMatrix& TestMatrix(SkRandom*); | 31 const SkMatrix& TestMatrix(SkRandom*); |
30 const SkMatrix& TestMatrixPreservesRightAngles(SkRandom*); | 32 const SkMatrix& TestMatrixPreservesRightAngles(SkRandom*); |
31 const SkMatrix& TestMatrixRectStaysRect(SkRandom*); | 33 const SkMatrix& TestMatrixRectStaysRect(SkRandom*); |
32 const SkMatrix& TestMatrixInvertible(SkRandom*); | 34 const SkMatrix& TestMatrixInvertible(SkRandom*); |
33 const SkRect& TestRect(SkRandom*); | 35 const SkRect& TestRect(SkRandom*); |
34 const SkRect& TestSquare(SkRandom*); | 36 const SkRect& TestSquare(SkRandom*); |
35 const SkRRect& TestRRectSimple(SkRandom*); | 37 const SkRRect& TestRRectSimple(SkRandom*); |
36 const SkPath& TestPath(SkRandom*); | 38 const SkPath& TestPath(SkRandom*); |
37 const SkPath& TestPathConvex(SkRandom*); | 39 const SkPath& TestPathConvex(SkRandom*); |
38 SkStrokeRec TestStrokeRec(SkRandom*); | 40 SkStrokeRec TestStrokeRec(SkRandom*); |
39 GrStrokeInfo TestStrokeInfo(SkRandom*); | 41 /** Creates styles with dash path effects and null path effects */ |
| 42 void TestStyle(SkRandom*, GrStyle*); |
40 | 43 |
41 } | 44 // We have a simplified dash path effect here to avoid relying on SkDashPathEffe
ct which |
| 45 // is in the optional build target effects. |
| 46 class TestDashPathEffect : public SkPathEffect { |
| 47 public: |
| 48 static sk_sp<SkPathEffect> Make(const SkScalar* intervals, int count, SkScal
ar phase) { |
| 49 return sk_sp<SkPathEffect>(new TestDashPathEffect(intervals, count, phas
e)); |
| 50 } |
| 51 |
| 52 bool filterPath(SkPath* dst, const SkPath&, SkStrokeRec* , const SkRect*) co
nst override; |
| 53 DashType asADash(DashInfo* info) const override; |
| 54 Factory getFactory() const override { return nullptr; } |
| 55 void toString(SkString*) const override {} |
| 56 |
| 57 private: |
| 58 TestDashPathEffect(const SkScalar* intervals, int count, SkScalar phase); |
| 59 |
| 60 int fCount; |
| 61 SkAutoTArray<SkScalar> fIntervals; |
| 62 SkScalar fPhase; |
| 63 SkScalar fInitialDashLength; |
| 64 int fInitialDashIndex; |
| 65 SkScalar fIntervalLength; |
| 66 }; |
| 67 |
| 68 } // namespace GrTest |
42 | 69 |
43 static inline GrColor GrRandomColor(SkRandom* random) { | 70 static inline GrColor GrRandomColor(SkRandom* random) { |
44 // There are only a few cases of random colors which interest us | 71 // There are only a few cases of random colors which interest us |
45 enum ColorMode { | 72 enum ColorMode { |
46 kAllOnes_ColorMode, | 73 kAllOnes_ColorMode, |
47 kAllZeros_ColorMode, | 74 kAllZeros_ColorMode, |
48 kAlphaOne_ColorMode, | 75 kAlphaOne_ColorMode, |
49 kRandom_ColorMode, | 76 kRandom_ColorMode, |
50 kLast_ColorMode = kRandom_ColorMode | 77 kLast_ColorMode = kRandom_ColorMode |
51 }; | 78 }; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 break; | 124 break; |
98 case kRandom_CoverageMode: | 125 case kRandom_CoverageMode: |
99 coverage = random->nextULessThan(256); | 126 coverage = random->nextULessThan(256); |
100 break; | 127 break; |
101 } | 128 } |
102 return coverage; | 129 return coverage; |
103 } | 130 } |
104 | 131 |
105 #endif | 132 #endif |
106 #endif | 133 #endif |
OLD | NEW |