1 /* 2 * Copyright 2015 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #ifndef GrTestUtils_DEFINED 9 #define GrTestUtils_DEFINED 10 11 #include "include/core/SkTypes.h" 12 13 #if GR_TEST_UTILS 14 15 #include "include/core/SkStrokeRec.h" 16 #include "include/core/SkSurfaceProps.h" 17 #include "include/private/base/SkMacros.h" 18 #include "include/private/base/SkTemplates.h" 19 #include "src/base/SkRandom.h" 20 #include "src/core/SkMatrixProvider.h" 21 #include "src/core/SkPathEffectBase.h" 22 #include "src/gpu/ganesh/GrColor.h" 23 #include "src/gpu/ganesh/GrFPArgs.h" 24 #include "src/gpu/ganesh/GrSamplerState.h" 25 #include "src/shaders/SkShaderBase.h" 26 27 class GrColorInfo; 28 class GrColorSpaceXform; 29 class GrProcessorTestData; 30 class GrStyle; 31 class SkMatrix; 32 class SkPath; 33 class SkRRect; 34 struct SkRect; 35 36 namespace GrTest { 37 /** 38 * Helpers for use in Test functions. 39 */ 40 const SkMatrix& TestMatrix(SkRandom*); 41 const SkMatrix& TestMatrixPreservesRightAngles(SkRandom*); 42 const SkMatrix& TestMatrixRectStaysRect(SkRandom*); 43 const SkMatrix& TestMatrixInvertible(SkRandom*); 44 const SkMatrix& TestMatrixPerspective(SkRandom*); 45 void TestWrapModes(SkRandom*, GrSamplerState::WrapMode[2]); 46 const SkRect& TestRect(SkRandom*); 47 const SkRect& TestSquare(SkRandom*); 48 const SkRRect& TestRRectSimple(SkRandom*); 49 const SkPath& TestPath(SkRandom*); 50 const SkPath& TestPathConvex(SkRandom*); 51 SkStrokeRec TestStrokeRec(SkRandom*); 52 /** Creates styles with dash path effects and null path effects */ 53 void TestStyle(SkRandom*, GrStyle*); 54 sk_sp<SkColorSpace> TestColorSpace(SkRandom*); 55 sk_sp<GrColorSpaceXform> TestColorXform(SkRandom*); 56 57 GrColor RandomColor(SkRandom* random); 58 uint8_t RandomCoverage(SkRandom* random); 59 60 class TestAsFPArgs { 61 public: 62 TestAsFPArgs(GrProcessorTestData*); 63 ~TestAsFPArgs(); args()64 const GrFPArgs& args() const { return fArgs; } 65 66 private: 67 std::unique_ptr<GrColorInfo> fColorInfoStorage; 68 SkSurfaceProps fSurfaceProps; 69 GrFPArgs fArgs; 70 }; 71 72 // We have a simplified dash path effect here to avoid relying on SkDashPathEffect which 73 // is in the optional build target effects. 74 class TestDashPathEffect : public SkPathEffectBase { 75 public: Make(const SkScalar * intervals,int count,SkScalar phase)76 static sk_sp<SkPathEffect> Make(const SkScalar* intervals, int count, SkScalar phase) { 77 return sk_sp<SkPathEffect>(new TestDashPathEffect(intervals, count, phase)); 78 } 79 getFactory()80 Factory getFactory() const override { return nullptr; } getTypeName()81 const char* getTypeName() const override { return nullptr; } 82 83 protected: 84 bool onFilterPath(SkPath* dst, const SkPath&, SkStrokeRec* , const SkRect*, 85 const SkMatrix&) const override; 86 DashType onAsADash(DashInfo* info) const override; 87 88 private: 89 TestDashPathEffect(const SkScalar* intervals, int count, SkScalar phase); 90 computeFastBounds(SkRect * bounds)91 bool computeFastBounds(SkRect* bounds) const override { return true; } 92 93 int fCount; 94 skia_private::AutoTArray<SkScalar> fIntervals; 95 SkScalar fPhase; 96 SkScalar fInitialDashLength; 97 int fInitialDashIndex; 98 SkScalar fIntervalLength; 99 }; 100 101 } // namespace GrTest 102 103 #endif 104 #endif 105