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: GrProcessorKeyBuilder(SkTArray<unsigned char,true> * data)30 GrProcessorKeyBuilder(SkTArray<unsigned char, true>* data) : fData(data), fCount(0) { 31 SkASSERT(0 == fData->count() % sizeof(uint32_t)); 32 } 33 add32(uint32_t v)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. */ add32n(int count)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 size()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 kGrComposeLerpRedEffect_ClassID, 100 kGrConfigConversionEffect_ClassID, 101 kGrConicEffect_ClassID, 102 kGrConstColorProcessor_ClassID, 103 kGrConvexPolyEffect_ClassID, 104 kGrDeviceSpaceTextureDecalFragmentProcessor_ClassID, 105 kGrDiffuseLightingEffect_ClassID, 106 kGrDisplacementMapEffect_ClassID, 107 kGrDistanceFieldA8TextGeoProc_ClassID, 108 kGrDistanceFieldLCDTextGeoProc_ClassID, 109 kGrDistanceFieldPathGeoProc_ClassID, 110 kGrDualIntervalGradientColorizer_ClassID, 111 kGrEllipseEffect_ClassID, 112 kGrFillRRectOp_Processor_ClassID, 113 kGrGaussianConvolutionFragmentProcessor_ClassID, 114 kGrGSCoverageProcessor_ClassID, 115 kGrHSLToRGBFilterEffect_ClassID, 116 kGrImprovedPerlinNoiseEffect_ClassID, 117 kGrLinearGradientLayout_ClassID, 118 kGrLumaColorFilterEffect_ClassID, 119 kGrMagnifierEffect_ClassID, 120 kGrMatrixConvolutionEffect_ClassID, 121 kGrMeshTestProcessor_ClassID, 122 kGrMorphologyEffect_ClassID, 123 kGrMixerEffect_ClassID, 124 kGrOverrideInputFragmentProcessor_ClassID, 125 kGrPathProcessor_ClassID, 126 kGrPerlinNoise2Effect_ClassID, 127 kGrPipelineDynamicStateTestProcessor_ClassID, 128 kGrPremulInputFragmentProcessor_ClassID, 129 kGrQuadEffect_ClassID, 130 kGrRadialGradientLayout_ClassID, 131 kGrRectBlurEffect_ClassID, 132 kGrRGBToHSLFilterEffect_ClassID, 133 kGrRRectBlurEffect_ClassID, 134 kGrRRectShadowGeoProc_ClassID, 135 kGrSingleIntervalGradientColorizer_ClassID, 136 kGrSkSLFP_ClassID, 137 kGrSpecularLightingEffect_ClassID, 138 kGrSRGBEffect_ClassID, 139 kGrSampleMaskProcessor_ClassID, 140 kGrSweepGradientLayout_ClassID, 141 kGrTextureEffect_ClassID, 142 kGrTextureGradientColorizer_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 kTessellationTestTriShader_ClassID, 162 kTessellationTestRectShader_ClassID, 163 kTessellate_GrFillBoundingBoxShader_ClassID, 164 kTessellate_GrFillCubicHullShader_ClassID, 165 kTessellate_GrFillTriangleShader_ClassID, 166 kTessellate_GrStencilCubicShader_ClassID, 167 kTessellate_GrStencilTriangleShader_ClassID, 168 kTessellate_GrStencilWedgeShader_ClassID, 169 kTestFP_ClassID, 170 kTestRectOp_ClassID, 171 kFlatNormalsFP_ClassID, 172 kMappedNormalsFP_ClassID, 173 kLightingFP_ClassID, 174 kLinearStrokeProcessor_ClassID, 175 }; 176 177 virtual ~GrProcessor() = default; 178 179 /** Human-meaningful string to identify this prcoessor; may be embedded in generated shader 180 code. */ 181 virtual const char* name() const = 0; 182 183 /** Human-readable dump of all information */ 184 #ifdef SK_DEBUG dumpInfo()185 virtual SkString dumpInfo() const { 186 SkString str; 187 str.appendf("Missing data"); 188 return str; 189 } 190 #else dumpInfo()191 SkString dumpInfo() const { return SkString("<Processor information unavailable>"); } 192 #endif 193 194 /** 195 * Custom shader features provided by the framework. These require special handling when 196 * preparing shaders, so a processor must call setWillUseCustomFeature() from its constructor if 197 * it intends to use one. 198 */ 199 enum class CustomFeatures { 200 kNone = 0, 201 kSampleLocations = 1 << 0, 202 }; 203 204 GR_DECL_BITFIELD_CLASS_OPS_FRIENDS(CustomFeatures); 205 requestedFeatures()206 CustomFeatures requestedFeatures() const { return fRequestedFeatures; } 207 208 void* operator new(size_t size); 209 void operator delete(void* target); 210 new(size_t size,void * placement)211 void* operator new(size_t size, void* placement) { 212 return ::operator new(size, placement); 213 } delete(void * target,void * placement)214 void operator delete(void* target, void* placement) { 215 ::operator delete(target, placement); 216 } 217 218 /** Helper for down-casting to a GrProcessor subclass */ cast()219 template <typename T> const T& cast() const { return *static_cast<const T*>(this); } 220 classID()221 ClassID classID() const { return fClassID; } 222 223 protected: GrProcessor(ClassID classID)224 GrProcessor(ClassID classID) : fClassID(classID) {} 225 GrProcessor(const GrProcessor&) = delete; 226 GrProcessor& operator=(const GrProcessor&) = delete; 227 setWillUseCustomFeature(CustomFeatures feature)228 void setWillUseCustomFeature(CustomFeatures feature) { fRequestedFeatures |= feature; } resetCustomFeatures()229 void resetCustomFeatures() { fRequestedFeatures = CustomFeatures::kNone; } 230 231 const ClassID fClassID; 232 CustomFeatures fRequestedFeatures = CustomFeatures::kNone; 233 }; 234 235 GR_MAKE_BITFIELD_CLASS_OPS(GrProcessor::CustomFeatures) 236 237 #endif 238