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