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