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 GrProcessor_DEFINED |
9 | #define GrProcessor_DEFINED |
10 | |
11 | #include "include/core/SkMath.h" |
12 | #include "include/core/SkString.h" |
13 | #include "src/gpu/GrColor.h" |
14 | #include "src/gpu/GrGpuBuffer.h" |
15 | #include "src/gpu/GrProcessorUnitTest.h" |
16 | #include "src/gpu/GrSamplerState.h" |
17 | #include "src/gpu/GrShaderVar.h" |
18 | #include "src/gpu/GrSurfaceProxyPriv.h" |
19 | #include "src/gpu/GrTextureProxy.h" |
20 | |
21 | class GrResourceProvider; |
22 | |
23 | /** |
24 | * Used by processors to build their keys. It incorporates each per-processor key into a larger |
25 | * shader key. |
26 | */ |
27 | class GrProcessorKeyBuilder { |
28 | public: |
29 | GrProcessorKeyBuilder(SkTArray<unsigned char, true>* data) : fData(data), fCount(0) { |
30 | SkASSERT(0 == fData->count() % sizeof(uint32_t)); |
31 | } |
32 | |
33 | void add32(uint32_t v) { |
34 | ++fCount; |
35 | fData->push_back_n(4, reinterpret_cast<uint8_t*>(&v)); |
36 | } |
37 | |
38 | /** Inserts count uint32_ts into the key. The returned pointer is only valid until the next |
39 | add*() call. */ |
40 | uint32_t* SK_WARN_UNUSED_RESULT add32n(int count) { |
41 | SkASSERT(count > 0); |
42 | fCount += count; |
43 | return reinterpret_cast<uint32_t*>(fData->push_back_n(4 * count)); |
44 | } |
45 | |
46 | size_t size() const { return sizeof(uint32_t) * fCount; } |
47 | |
48 | private: |
49 | SkTArray<uint8_t, true>* fData; // unowned ptr to the larger key. |
50 | int fCount; // number of uint32_ts added to fData by the processor. |
51 | }; |
52 | |
53 | /** Provides custom shader code to the Ganesh shading pipeline. GrProcessor objects *must* be |
54 | immutable: after being constructed, their fields may not change. |
55 | |
56 | Dynamically allocated GrProcessors are managed by a per-thread memory pool. The ref count of an |
57 | processor must reach 0 before the thread terminates and the pool is destroyed. |
58 | */ |
59 | class GrProcessor { |
60 | public: |
61 | enum ClassID { |
62 | kNull_ClassID, // Reserved ID for missing (null) processors |
63 | |
64 | kBigKeyProcessor_ClassID, |
65 | kBlendFragmentProcessor_ClassID, |
66 | kBlockInputFragmentProcessor_ClassID, |
67 | kButtCapStrokedCircleGeometryProcessor_ClassID, |
68 | kCircleGeometryProcessor_ClassID, |
69 | kCircularRRectEffect_ClassID, |
70 | kClockwiseTestProcessor_ClassID, |
71 | kColorTableEffect_ClassID, |
72 | kCoverageSetOpXP_ClassID, |
73 | kCubicStrokeProcessor_ClassID, |
74 | kCustomXP_ClassID, |
75 | kDashingCircleEffect_ClassID, |
76 | kDashingLineEffect_ClassID, |
77 | kDefaultGeoProc_ClassID, |
78 | kDIEllipseGeometryProcessor_ClassID, |
79 | kDisableColorXP_ClassID, |
80 | kDrawAtlasPathShader_ClassID, |
81 | kEllipseGeometryProcessor_ClassID, |
82 | kEllipticalRRectEffect_ClassID, |
83 | kGP_ClassID, |
84 | kVertexColorSpaceBenchGP_ClassID, |
85 | kGrArithmeticProcessor_ClassID, |
86 | kGrAARectEffect_ClassID, |
87 | kGrAlphaThresholdFragmentProcessor_ClassID, |
88 | kGrBicubicEffect_ClassID, |
89 | kGrBitmapTextGeoProc_ClassID, |
90 | kGrBlurredEdgeFragmentProcessor_ClassID, |
91 | kGrCCClipProcessor_ClassID, |
92 | kGrCCPathProcessor_ClassID, |
93 | kGrCircleBlurFragmentProcessor_ClassID, |
94 | kGrCircleEffect_ClassID, |
95 | kGrClampedGradientEffect_ClassID, |
96 | kGrClampFragmentProcessor_ClassID, |
97 | kGrColorMatrixFragmentProcessor_ClassID, |
98 | kGrColorSpaceXformEffect_ClassID, |
99 | kGrComposeLerpEffect_ClassID, |
100 | kGrConfigConversionEffect_ClassID, |
101 | kGrConicEffect_ClassID, |
102 | kGrConstColorProcessor_ClassID, |
103 | kGrConvexPolyEffect_ClassID, |
104 | kGrDeviceSpaceEffect_ClassID, |
105 | kGrDiffuseLightingEffect_ClassID, |
106 | kGrDisplacementMapEffect_ClassID, |
107 | kGrDistanceFieldA8TextGeoProc_ClassID, |
108 | kGrDistanceFieldLCDTextGeoProc_ClassID, |
109 | kGrDistanceFieldPathGeoProc_ClassID, |
110 | kGrDitherEffect_ClassID, |
111 | kGrDualIntervalGradientColorizer_ClassID, |
112 | kGrEllipseEffect_ClassID, |
113 | kGrFillRRectOp_Processor_ClassID, |
114 | kGrGaussianConvolutionFragmentProcessor_ClassID, |
115 | kGrGSCoverageProcessor_ClassID, |
116 | kGrHighContrastFilterEffect_ClassID, |
117 | kGrHSLToRGBFilterEffect_ClassID, |
118 | kGrImprovedPerlinNoiseEffect_ClassID, |
119 | kGrLinearGradientLayout_ClassID, |
120 | kGrLumaColorFilterEffect_ClassID, |
121 | kGrMagnifierEffect_ClassID, |
122 | kGrMatrixConvolutionEffect_ClassID, |
123 | kGrMatrixEffect_ClassID, |
124 | kGrMeshTestProcessor_ClassID, |
125 | kGrMorphologyEffect_ClassID, |
126 | kGrMixerEffect_ClassID, |
127 | kGrOverrideInputFragmentProcessor_ClassID, |
128 | kGrPathProcessor_ClassID, |
129 | kGrPerlinNoise2Effect_ClassID, |
130 | kGrPipelineDynamicStateTestProcessor_ClassID, |
131 | kGrQuadEffect_ClassID, |
132 | kGrRadialGradientLayout_ClassID, |
133 | kGrRectBlurEffect_ClassID, |
134 | kGrRGBToHSLFilterEffect_ClassID, |
135 | kGrRRectBlurEffect_ClassID, |
136 | kGrRRectShadowGeoProc_ClassID, |
137 | kGrSingleIntervalGradientColorizer_ClassID, |
138 | kGrSkSLFP_ClassID, |
139 | kGrSpecularLightingEffect_ClassID, |
140 | kGrSampleMaskProcessor_ClassID, |
141 | kGrSweepGradientLayout_ClassID, |
142 | kGrTextureEffect_ClassID, |
143 | kGrTiledGradientEffect_ClassID, |
144 | kGrTwoPointConicalGradientLayout_ClassID, |
145 | kGrUnrolledBinaryGradientColorizer_ClassID, |
146 | kGrVSCoverageProcessor_ClassID, |
147 | kGrYUVtoRGBEffect_ClassID, |
148 | kHighContrastFilterEffect_ClassID, |
149 | kLatticeGP_ClassID, |
150 | kPDLCDXferProcessor_ClassID, |
151 | kPorterDuffXferProcessor_ClassID, |
152 | kPremulFragmentProcessor_ClassID, |
153 | kQuadEdgeEffect_ClassID, |
154 | kQuadPerEdgeAAGeometryProcessor_ClassID, |
155 | kSampleLocationsTestProcessor_ClassID, |
156 | kSeriesFragmentProcessor_ClassID, |
157 | kShaderPDXferProcessor_ClassID, |
158 | kStencilResolveProcessor_ClassID, |
159 | kFwidthSquircleTestProcessor_ClassID, |
160 | kSwizzleFragmentProcessor_ClassID, |
161 | kTessellate_GrCubicTessellateShader_ClassID, |
162 | kTessellate_GrFillBoundingBoxShader_ClassID, |
163 | kTessellate_GrFillCubicHullShader_ClassID, |
164 | kTessellate_GrFillTriangleShader_ClassID, |
165 | kTessellate_GrMiddleOutCubicShader_ClassID, |
166 | kTessellate_GrStencilTriangleShader_ClassID, |
167 | kTessellate_GrStrokeTessellateShader_ClassID, |
168 | kTessellate_GrWedgeTessellateShader_ClassID, |
169 | kTessellationTestTriShader_ClassID, |
170 | kTessellationTestRectShader_ClassID, |
171 | kTestFP_ClassID, |
172 | kTestRectOp_ClassID, |
173 | kFlatNormalsFP_ClassID, |
174 | kMappedNormalsFP_ClassID, |
175 | kLightingFP_ClassID, |
176 | kLinearStrokeProcessor_ClassID, |
177 | kVerticesGP_ClassID, |
178 | }; |
179 | |
180 | virtual ~GrProcessor() = default; |
181 | |
182 | /** Human-meaningful string to identify this processor; may be embedded in generated shader |
183 | code and must be a legal SkSL identifier prefix. */ |
184 | virtual const char* name() const = 0; |
185 | |
186 | /** Human-readable dump of all information */ |
187 | #if GR_TEST_UTILS |
188 | virtual SkString onDumpInfo() const { return SkString(); } |
189 | |
190 | virtual SkString dumpInfo() const final { |
191 | SkString info(name()); |
192 | info.append(this->onDumpInfo()); |
193 | return info; |
194 | } |
195 | #endif |
196 | |
197 | /** |
198 | * Custom shader features provided by the framework. These require special handling when |
199 | * preparing shaders, so a processor must call setWillUseCustomFeature() from its constructor if |
200 | * it intends to use one. |
201 | */ |
202 | enum class CustomFeatures { |
203 | kNone = 0, |
204 | kSampleLocations = 1 << 0, |
205 | }; |
206 | |
207 | GR_DECL_BITFIELD_CLASS_OPS_FRIENDS(CustomFeatures); |
208 | |
209 | CustomFeatures requestedFeatures() const { return fRequestedFeatures; } |
210 | |
211 | void* operator new(size_t size); |
212 | void operator delete(void* target); |
213 | |
214 | void* operator new(size_t size, void* placement) { |
215 | return ::operator new(size, placement); |
216 | } |
217 | void operator delete(void* target, void* placement) { |
218 | ::operator delete(target, placement); |
219 | } |
220 | |
221 | /** Helper for down-casting to a GrProcessor subclass */ |
222 | template <typename T> const T& cast() const { return *static_cast<const T*>(this); } |
223 | |
224 | ClassID classID() const { return fClassID; } |
225 | |
226 | protected: |
227 | GrProcessor(ClassID classID) : fClassID(classID) {} |
228 | GrProcessor(const GrProcessor&) = delete; |
229 | GrProcessor& operator=(const GrProcessor&) = delete; |
230 | |
231 | void setWillUseCustomFeature(CustomFeatures feature) { fRequestedFeatures |= feature; } |
232 | void resetCustomFeatures() { fRequestedFeatures = CustomFeatures::kNone; } |
233 | |
234 | const ClassID fClassID; |
235 | CustomFeatures fRequestedFeatures = CustomFeatures::kNone; |
236 | }; |
237 | |
238 | GR_MAKE_BITFIELD_CLASS_OPS(GrProcessor::CustomFeatures) |
239 | |
240 | #endif |
241 | |