Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
GrProcessorUnitTest.h
Go to the documentation of this file.
1/*
2 * Copyright 2012 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 GrProcessorUnitTest_DEFINED
9#define GrProcessorUnitTest_DEFINED
10
12
13#if defined(GR_TEST_UTILS)
14
20
21#include <tuple>
22
23class GrCaps;
26class GrProcessorTestData;
27class GrProxyProvider;
28class GrTexture;
29class GrXPFactory;
30class SkMatrix;
31
32namespace GrProcessorUnitTest {
33
34/** This allows parent FPs to implement a test create with known leaf children in order to avoid
35 * creating an unbounded FP tree which may overflow various shader limits.
36 * MakeOptionalChildFP is the same as MakeChildFP, but can return null.
37 */
38std::unique_ptr<GrFragmentProcessor> MakeChildFP(GrProcessorTestData*);
39std::unique_ptr<GrFragmentProcessor> MakeOptionalChildFP(GrProcessorTestData*);
40
41} // namespace GrProcessorUnitTest
42
43/** GrProcessorTestData is an argument struct to TestCreate functions
44 * fTextures are valid textures that can optionally be used to construct
45 * TextureSampler. The first texture has a RGBA8 format and the second has Alpha8 format for the
46 * specific backend API. TestCreate functions are also free to create additional textures using
47 * the GrContext.
48 */
49class GrProcessorTestData {
50public:
51 using ViewInfo = std::tuple<GrSurfaceProxyView, GrColorType, SkAlphaType>;
52
53 GrProcessorTestData(SkRandom* random, GrRecordingContext* context, int maxTreeDepth,
54 int numViews, const ViewInfo views[]);
55 GrProcessorTestData(SkRandom* random, GrRecordingContext* context, int maxTreeDepth,
56 int numViews, const ViewInfo views[],
57 std::unique_ptr<GrFragmentProcessor> inputFP);
58 GrProcessorTestData(const GrProcessorTestData&) = delete;
59 ~GrProcessorTestData();
60
61 GrRecordingContext* context() { return fContext; }
62 GrProxyProvider* proxyProvider();
63 const GrCaps* caps();
64 SkArenaAlloc* allocator() { return fArena.get(); }
65 std::unique_ptr<GrFragmentProcessor> inputFP();
66
67 ViewInfo randomView();
68 ViewInfo randomAlphaOnlyView();
69
70 SkRandom* fRandom;
71 int fCurrentTreeDepth = 0;
72 int fMaxTreeDepth = 1;
73
74private:
77 std::unique_ptr<SkArenaAlloc> fArena;
78 std::unique_ptr<GrFragmentProcessor> fInputFP;
79};
80
81class GrProcessor;
82class GrTexture;
83
84template <class ProcessorSmartPtr>
85class GrProcessorTestFactory : private SkNoncopyable {
86public:
87 using MakeProc = ProcessorSmartPtr (*)(GrProcessorTestData*);
88
89 GrProcessorTestFactory(MakeProc makeProc, const char* name);
90
91 /** Pick a random factory function and create a processor. */
92 static ProcessorSmartPtr Make(GrProcessorTestData* data);
93
94 /** Use factory function at Index idx to create a processor. */
95 static ProcessorSmartPtr MakeIdx(int idx, GrProcessorTestData* data);
96
97 /** Number of registered factory functions */
98 static int Count();
99
100private:
101 /** A test function which verifies the count of factories. */
102 static void VerifyFactoryCount();
104
105 MakeProc fMakeProc;
107};
108
109using GrFragmentProcessorTestFactory = GrProcessorTestFactory<std::unique_ptr<GrFragmentProcessor>>;
110using GrGeometryProcessorTestFactory = GrProcessorTestFactory<GrGeometryProcessor*>;
111
112class GrXPFactoryTestFactory : private SkNoncopyable {
113public:
114 using GetFn = const GrXPFactory*(GrProcessorTestData*);
115
116 GrXPFactoryTestFactory(GetFn* getProc);
117
118 static const GrXPFactory* Get(GrProcessorTestData* data);
119
120private:
121 /** A test function which verifies the count of factories. */
122 static void VerifyFactoryCount();
124
125 GetFn* fGetProc;
126};
127
128#if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
129
130/** GrProcessor subclasses should insert this macro in their declaration to be included in the
131 * program generation unit test.
132 */
133#define GR_DECLARE_GEOMETRY_PROCESSOR_TEST \
134 [[maybe_unused]] static GrGeometryProcessorTestFactory* gTestFactory; \
135 static GrGeometryProcessor* TestCreate(GrProcessorTestData*);
136
137#define GR_DECLARE_FRAGMENT_PROCESSOR_TEST \
138 [[maybe_unused]] static GrFragmentProcessorTestFactory* gTestFactory; \
139 static std::unique_ptr<GrFragmentProcessor> TestCreate(GrProcessorTestData*);
140
141#define GR_DECLARE_XP_FACTORY_TEST \
142 [[maybe_unused]] static GrXPFactoryTestFactory* gTestFactory; \
143 static const GrXPFactory* TestGet(GrProcessorTestData*);
144
145/** GrProcessor subclasses should insert this macro in their implementation file. They must then
146 * also implement this static function:
147 * GrProcessor* TestCreate(GrProcessorTestData*);
148 */
149#define GR_DEFINE_FRAGMENT_PROCESSOR_TEST(Effect) \
150 GrFragmentProcessorTestFactory* Effect::gTestFactory = \
151 new GrFragmentProcessorTestFactory(Effect::TestCreate, #Effect);
152
153#define GR_DEFINE_GEOMETRY_PROCESSOR_TEST(Effect) \
154 GrGeometryProcessorTestFactory* Effect::gTestFactory = \
155 new GrGeometryProcessorTestFactory(Effect::TestCreate, #Effect);
156
157#define GR_DEFINE_XP_FACTORY_TEST(Factory) \
158 GrXPFactoryTestFactory* Factory::gTestFactory = new GrXPFactoryTestFactory(Factory::TestGet);
159
160#else // !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
161
162// The unit test relies on static initializers. Just declare the TestCreate function so that
163// its definitions will compile.
164#define GR_DECLARE_FRAGMENT_PROCESSOR_TEST \
165 static std::unique_ptr<GrFragmentProcessor> TestCreate(GrProcessorTestData*);
166#define GR_DEFINE_FRAGMENT_PROCESSOR_TEST(X)
167
168// The unit test relies on static initializers. Just declare the TestCreate function so that
169// its definitions will compile.
170#define GR_DECLARE_GEOMETRY_PROCESSOR_TEST \
171 static GrGeometryProcessor* TestCreate(GrProcessorTestData*);
172#define GR_DEFINE_GEOMETRY_PROCESSOR_TEST(X)
173
174// The unit test relies on static initializers. Just declare the TestGet function so that
175// its definitions will compile.
176#define GR_DECLARE_XP_FACTORY_TEST \
177 const GrXPFactory* TestGet(GrProcessorTestData*);
178#define GR_DEFINE_XP_FACTORY_TEST(X)
179
180#endif // !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
181#else // defined(GR_TEST_UTILS)
182 #define GR_DECLARE_GEOMETRY_PROCESSOR_TEST
183 #define GR_DECLARE_FRAGMENT_PROCESSOR_TEST
184 #define GR_DECLARE_XP_FACTORY_TEST
185 #define GR_DEFINE_FRAGMENT_PROCESSOR_TEST(...)
186 #define GR_DEFINE_GEOMETRY_PROCESSOR_TEST(...)
187 #define GR_DEFINE_XP_FACTORY_TEST(...)
188 #define GR_DECLARE_FRAGMENT_PROCESSOR_TEST
189 #define GR_DEFINE_FRAGMENT_PROCESSOR_TEST(...)
190 #define GR_DECLARE_GEOMETRY_PROCESSOR_TEST
191 #define GR_DEFINE_GEOMETRY_PROCESSOR_TEST(...)
192 #define GR_DECLARE_XP_FACTORY_TEST
193 #define GR_DEFINE_XP_FACTORY_TEST(...)
194#endif // defined(GR_TEST_UTILS)
195#endif // GrProcessorUnitTest_DEFINED
const char * fName
static std::unique_ptr< SkEncoder > Make(SkWStream *dst, const SkPixmap *src, const SkYUVAPixmaps *srcYUVA, const SkColorSpace *srcYUVAColorSpace, const SkJpegEncoder::Options &options)
const Context & fContext
const char * name
Definition fuchsia.cc:50
const GrXPFactory * Get(SkBlendMode mode)
GrFPResult MakeChildFP(const SkRuntimeEffect::ChildPtr &child, const GrFPArgs &childArgs)