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