| 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" | |
| 17 #include "SkRandom.h" | 16 #include "SkRandom.h" |
| 18 #include "SkStrokeRec.h" | 17 #include "SkStrokeRec.h" |
| 19 #include "../private/SkTemplates.h" | |
| 20 | 18 |
| 21 class GrStyle; | 19 class GrStrokeInfo; |
| 22 class SkMatrix; | 20 class SkMatrix; |
| 23 class SkPath; | 21 class SkPath; |
| 24 class SkRRect; | 22 class SkRRect; |
| 25 struct SkRect; | 23 struct SkRect; |
| 26 | 24 |
| 27 namespace GrTest { | 25 namespace GrTest { |
| 28 /** | 26 /** |
| 29 * Helpers for use in Test functions. | 27 * A helper for use in Test functions. |
| 30 */ | 28 */ |
| 31 const SkMatrix& TestMatrix(SkRandom*); | 29 const SkMatrix& TestMatrix(SkRandom*); |
| 32 const SkMatrix& TestMatrixPreservesRightAngles(SkRandom*); | 30 const SkMatrix& TestMatrixPreservesRightAngles(SkRandom*); |
| 33 const SkMatrix& TestMatrixRectStaysRect(SkRandom*); | 31 const SkMatrix& TestMatrixRectStaysRect(SkRandom*); |
| 34 const SkMatrix& TestMatrixInvertible(SkRandom*); | 32 const SkMatrix& TestMatrixInvertible(SkRandom*); |
| 35 const SkRect& TestRect(SkRandom*); | 33 const SkRect& TestRect(SkRandom*); |
| 36 const SkRect& TestSquare(SkRandom*); | 34 const SkRect& TestSquare(SkRandom*); |
| 37 const SkRRect& TestRRectSimple(SkRandom*); | 35 const SkRRect& TestRRectSimple(SkRandom*); |
| 38 const SkPath& TestPath(SkRandom*); | 36 const SkPath& TestPath(SkRandom*); |
| 39 const SkPath& TestPathConvex(SkRandom*); | 37 const SkPath& TestPathConvex(SkRandom*); |
| 40 SkStrokeRec TestStrokeRec(SkRandom*); | 38 SkStrokeRec TestStrokeRec(SkRandom*); |
| 41 /** Creates styles with dash path effects and null path effects */ | 39 GrStrokeInfo TestStrokeInfo(SkRandom*); |
| 42 void TestStyle(SkRandom*, GrStyle*); | |
| 43 | 40 |
| 44 // We have a simplified dash path effect here to avoid relying on SkDashPathEffe
ct which | 41 } |
| 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 | |
| 69 | 42 |
| 70 static inline GrColor GrRandomColor(SkRandom* random) { | 43 static inline GrColor GrRandomColor(SkRandom* random) { |
| 71 // There are only a few cases of random colors which interest us | 44 // There are only a few cases of random colors which interest us |
| 72 enum ColorMode { | 45 enum ColorMode { |
| 73 kAllOnes_ColorMode, | 46 kAllOnes_ColorMode, |
| 74 kAllZeros_ColorMode, | 47 kAllZeros_ColorMode, |
| 75 kAlphaOne_ColorMode, | 48 kAlphaOne_ColorMode, |
| 76 kRandom_ColorMode, | 49 kRandom_ColorMode, |
| 77 kLast_ColorMode = kRandom_ColorMode | 50 kLast_ColorMode = kRandom_ColorMode |
| 78 }; | 51 }; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 break; | 97 break; |
| 125 case kRandom_CoverageMode: | 98 case kRandom_CoverageMode: |
| 126 coverage = random->nextULessThan(256); | 99 coverage = random->nextULessThan(256); |
| 127 break; | 100 break; |
| 128 } | 101 } |
| 129 return coverage; | 102 return coverage; |
| 130 } | 103 } |
| 131 | 104 |
| 132 #endif | 105 #endif |
| 133 #endif | 106 #endif |
| OLD | NEW |