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