tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 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 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 8 | #ifndef GrProcessor_DEFINED |
| 9 | #define GrProcessor_DEFINED |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 10 | |
Brian Salomon | b014cca | 2016-11-18 11:39:15 -0500 | [diff] [blame] | 11 | #include "GrBuffer.h" |
Brian Salomon | 0c26a9d | 2017-07-06 10:09:38 -0400 | [diff] [blame] | 12 | #include "GrColor.h" |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 13 | #include "GrProcessorUnitTest.h" |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 14 | #include "GrSamplerState.h" |
Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 15 | #include "GrShaderVar.h" |
Robert Phillips | 8a02f65 | 2017-05-12 14:49:16 -0400 | [diff] [blame] | 16 | #include "GrSurfaceProxyPriv.h" |
Brian Salomon | 0c26a9d | 2017-07-06 10:09:38 -0400 | [diff] [blame] | 17 | #include "GrTextureProxy.h" |
egdaniel | 9e4d6d1 | 2014-10-15 13:49:02 -0700 | [diff] [blame] | 18 | #include "SkMath.h" |
robertphillips | e004bfc | 2015-11-16 09:06:59 -0800 | [diff] [blame] | 19 | #include "SkString.h" |
tomhudson@google.com | 07eecdc | 2012-04-20 18:35:38 +0000 | [diff] [blame] | 20 | |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 21 | class GrContext; |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 22 | class GrResourceProvider; |
bsalomon | 9574098 | 2014-09-04 13:12:37 -0700 | [diff] [blame] | 23 | |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 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 | |
bsalomon | 98b33eb | 2014-10-15 11:05:26 -0700 | [diff] [blame] | 54 | /** Provides custom shader code to the Ganesh shading pipeline. GrProcessor objects *must* be |
| 55 | immutable: after being constructed, their fields may not change. |
bsalomon@google.com | 0ac6af4 | 2013-01-16 15:16:18 +0000 | [diff] [blame] | 56 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 57 | Dynamically allocated GrProcessors are managed by a per-thread memory pool. The ref count of an |
mdempsky | 38f1f6f | 2015-08-27 12:57:01 -0700 | [diff] [blame] | 58 | processor must reach 0 before the thread terminates and the pool is destroyed. |
bsalomon | 98b33eb | 2014-10-15 11:05:26 -0700 | [diff] [blame] | 59 | */ |
Brian Salomon | d61c9d9 | 2017-04-10 10:54:25 -0400 | [diff] [blame] | 60 | class GrProcessor { |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 61 | public: |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 62 | enum ClassID { |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 63 | kBigKeyProcessor_ClassID, |
| 64 | kBlockInputFragmentProcessor_ClassID, |
Brian Salomon | 62e4f3d | 2018-04-20 13:54:11 -0400 | [diff] [blame] | 65 | kButtCapStrokedCircleGeometryProcessor_ClassID, |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 66 | kCircleGeometryProcessor_ClassID, |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 67 | kCircularRRectEffect_ClassID, |
Chris Dalton | 49d14e9 | 2018-07-27 12:38:35 -0600 | [diff] [blame] | 68 | kClockwiseTestProcessor_ClassID, |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 69 | kColorMatrixEffect_ClassID, |
| 70 | kColorTableEffect_ClassID, |
| 71 | kComposeOneFragmentProcessor_ClassID, |
| 72 | kComposeTwoFragmentProcessor_ClassID, |
| 73 | kCoverageSetOpXP_ClassID, |
Chris Dalton | 09a7bb2 | 2018-08-31 19:53:15 +0800 | [diff] [blame] | 74 | kCubicStrokeProcessor_ClassID, |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 75 | kCustomXP_ClassID, |
| 76 | kDashingCircleEffect_ClassID, |
| 77 | kDashingLineEffect_ClassID, |
| 78 | kDefaultGeoProc_ClassID, |
| 79 | kDIEllipseGeometryProcessor_ClassID, |
| 80 | kDisableColorXP_ClassID, |
Yuqian Li | 915817b | 2017-12-14 13:45:08 -0500 | [diff] [blame] | 81 | kTwoPointConicalEffect_ClassID, |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 82 | kEllipseGeometryProcessor_ClassID, |
| 83 | kEllipticalRRectEffect_ClassID, |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 84 | kGP_ClassID, |
Brian Osman | 387eaff | 2018-07-20 14:50:44 -0400 | [diff] [blame] | 85 | kVertexColorSpaceBenchGP_ClassID, |
Chris Dalton | 133944a | 2018-11-16 23:30:29 -0500 | [diff] [blame] | 86 | kGrAAFillRRectOp_Processor_ClassID, |
Ethan Nicholas | 8dca18a | 2017-11-15 15:33:33 -0500 | [diff] [blame] | 87 | kGrAARectEffect_ClassID, |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 88 | kGrAlphaThresholdFragmentProcessor_ClassID, |
Ethan Nicholas | c9472af | 2017-10-10 16:30:21 -0400 | [diff] [blame] | 89 | kGrArithmeticFP_ClassID, |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 90 | kGrBicubicEffect_ClassID, |
| 91 | kGrBitmapTextGeoProc_ClassID, |
| 92 | kGrBlurredEdgeFragmentProcessor_ClassID, |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 93 | kGrCCClipProcessor_ClassID, |
| 94 | kGrCCCoverageProcessor_ClassID, |
| 95 | kGrCCPathProcessor_ClassID, |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 96 | kGrCircleBlurFragmentProcessor_ClassID, |
| 97 | kGrCircleEffect_ClassID, |
Michael Ludwig | 4f94ef6 | 2018-09-12 15:22:16 -0400 | [diff] [blame] | 98 | kGrClampedGradientEffect_ClassID, |
Brian Osman | c4f93ca | 2017-10-17 17:15:52 -0400 | [diff] [blame] | 99 | kGrColorSpaceXformEffect_ClassID, |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 100 | kGrConfigConversionEffect_ClassID, |
| 101 | kGrConicEffect_ClassID, |
| 102 | kGrConstColorProcessor_ClassID, |
| 103 | kGrConvexPolyEffect_ClassID, |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 104 | kGrDeviceSpaceTextureDecalFragmentProcessor_ClassID, |
| 105 | kGrDiffuseLightingEffect_ClassID, |
| 106 | kGrDisplacementMapEffect_ClassID, |
| 107 | kGrDistanceFieldA8TextGeoProc_ClassID, |
| 108 | kGrDistanceFieldLCDTextGeoProc_ClassID, |
| 109 | kGrDistanceFieldPathGeoProc_ClassID, |
| 110 | kGrDitherEffect_ClassID, |
Michael Ludwig | 0495f7a | 2018-09-12 15:23:33 -0400 | [diff] [blame] | 111 | kGrDualIntervalGradientColorizer_ClassID, |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 112 | kGrEllipseEffect_ClassID, |
| 113 | kGrGaussianConvolutionFragmentProcessor_ClassID, |
| 114 | kGrImprovedPerlinNoiseEffect_ClassID, |
| 115 | kGrLightingEffect_ClassID, |
| 116 | kGrLinearGradient_ClassID, |
Michael Ludwig | 4f94ef6 | 2018-09-12 15:22:16 -0400 | [diff] [blame] | 117 | kGrLinearGradientLayout_ClassID, |
Ethan Nicholas | 14efcbf | 2017-11-07 09:23:38 -0500 | [diff] [blame] | 118 | kGrLumaColorFilterEffect_ClassID, |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 119 | kGrMagnifierEffect_ClassID, |
| 120 | kGrMatrixConvolutionEffect_ClassID, |
| 121 | kGrMeshTestProcessor_ClassID, |
| 122 | kGrMorphologyEffect_ClassID, |
Ethan Nicholas | d608c09 | 2017-10-26 09:30:08 -0400 | [diff] [blame] | 123 | kGrOverdrawFragmentProcessor_ClassID, |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 124 | kGrPathProcessor_ClassID, |
| 125 | kGrPerlinNoise2Effect_ClassID, |
| 126 | kGrPipelineDynamicStateTestProcessor_ClassID, |
Ethan Nicholas | be0a042 | 2017-11-17 13:44:05 -0500 | [diff] [blame] | 127 | kGrPremulInputFragmentProcessor_ClassID, |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 128 | kGrQuadEffect_ClassID, |
| 129 | kGrRadialGradient_ClassID, |
Michael Ludwig | 4089df8 | 2018-09-12 15:22:37 -0400 | [diff] [blame] | 130 | kGrRadialGradientLayout_ClassID, |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 131 | kGrRectBlurEffect_ClassID, |
| 132 | kGrRRectBlurEffect_ClassID, |
| 133 | kGrRRectShadowGeoProc_ClassID, |
| 134 | kGrSimpleTextureEffect_ClassID, |
Michael Ludwig | 4f94ef6 | 2018-09-12 15:22:16 -0400 | [diff] [blame] | 135 | kGrSingleIntervalGradientColorizer_ClassID, |
Ethan Nicholas | 0054311 | 2018-07-31 09:44:36 -0400 | [diff] [blame] | 136 | kGrSkSLFP_ClassID, |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 137 | kGrSpecularLightingEffect_ClassID, |
| 138 | kGrSRGBEffect_ClassID, |
| 139 | kGrSweepGradient_ClassID, |
Michael Ludwig | 24d438b | 2018-09-12 15:22:50 -0400 | [diff] [blame] | 140 | kGrSweepGradientLayout_ClassID, |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 141 | kGrTextureDomainEffect_ClassID, |
Michael Ludwig | a7914d3 | 2018-09-14 09:47:21 -0400 | [diff] [blame] | 142 | kGrTextureGradientColorizer_ClassID, |
Michael Ludwig | 4f94ef6 | 2018-09-12 15:22:16 -0400 | [diff] [blame] | 143 | kGrTiledGradientEffect_ClassID, |
Michael Ludwig | 8f68508 | 2018-09-12 15:23:01 -0400 | [diff] [blame] | 144 | kGrTwoPointConicalGradientLayout_ClassID, |
Ethan Nicholas | be0a042 | 2017-11-17 13:44:05 -0500 | [diff] [blame] | 145 | kGrUnpremulInputFragmentProcessor_ClassID, |
Michael Ludwig | 72535fb | 2018-09-28 11:53:32 -0400 | [diff] [blame] | 146 | kGrUnrolledBinaryGradientColorizer_ClassID, |
Ethan Nicholas | 7461a4a | 2017-12-21 14:18:01 -0500 | [diff] [blame] | 147 | kGrYUVtoRGBEffect_ClassID, |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 148 | kHighContrastFilterEffect_ClassID, |
| 149 | kInstanceProcessor_ClassID, |
Brian Salomon | 2a943df | 2018-05-04 13:43:19 -0400 | [diff] [blame] | 150 | kLatticeGP_ClassID, |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 151 | kLumaColorFilterEffect_ClassID, |
| 152 | kMSAAQuadProcessor_ClassID, |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 153 | kPDLCDXferProcessor_ClassID, |
| 154 | kPorterDuffXferProcessor_ClassID, |
| 155 | kPremulFragmentProcessor_ClassID, |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 156 | kQuadEdgeEffect_ClassID, |
Michael Ludwig | 6985853 | 2018-11-28 15:34:34 -0500 | [diff] [blame] | 157 | kQuadPerEdgeAAGeometryProcessor_ClassID, |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 158 | kReplaceInputFragmentProcessor_ClassID, |
| 159 | kRRectsGaussianEdgeFP_ClassID, |
| 160 | kSeriesFragmentProcessor_ClassID, |
| 161 | kShaderPDXferProcessor_ClassID, |
Chris Dalton | 0921219 | 2018-11-13 15:07:24 -0500 | [diff] [blame] | 162 | kFwidthSquircleTestProcessor_ClassID, |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 163 | kSwizzleFragmentProcessor_ClassID, |
| 164 | kTestFP_ClassID, |
| 165 | kTextureGeometryProcessor_ClassID, |
Robert Phillips | a8cdbd7 | 2018-07-17 12:30:40 -0400 | [diff] [blame] | 166 | kFlatNormalsFP_ClassID, |
| 167 | kMappedNormalsFP_ClassID, |
| 168 | kLightingFP_ClassID, |
Chris Dalton | 09a7bb2 | 2018-08-31 19:53:15 +0800 | [diff] [blame] | 169 | kLinearStrokeProcessor_ClassID, |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 170 | }; |
| 171 | |
Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame] | 172 | virtual ~GrProcessor() = default; |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 173 | |
Brian Salomon | b014cca | 2016-11-18 11:39:15 -0500 | [diff] [blame] | 174 | /** Human-meaningful string to identify this prcoessor; may be embedded in generated shader |
| 175 | code. */ |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 176 | virtual const char* name() const = 0; |
bsalomon@google.com | 289efe0 | 2012-05-21 20:57:59 +0000 | [diff] [blame] | 177 | |
Brian Salomon | b014cca | 2016-11-18 11:39:15 -0500 | [diff] [blame] | 178 | /** Human-readable dump of all information */ |
Brian Osman | 9a390ac | 2018-11-12 09:47:48 -0500 | [diff] [blame] | 179 | #ifdef SK_DEBUG |
robertphillips | e004bfc | 2015-11-16 09:06:59 -0800 | [diff] [blame] | 180 | virtual SkString dumpInfo() const { |
| 181 | SkString str; |
| 182 | str.appendf("Missing data"); |
| 183 | return str; |
| 184 | } |
Brian Osman | 9a390ac | 2018-11-12 09:47:48 -0500 | [diff] [blame] | 185 | #else |
| 186 | SkString dumpInfo() const { return SkString("<Processor information unavailable>"); } |
| 187 | #endif |
robertphillips | e004bfc | 2015-11-16 09:06:59 -0800 | [diff] [blame] | 188 | |
tomhudson@google.com | dcba4c2 | 2012-07-24 21:36:16 +0000 | [diff] [blame] | 189 | void* operator new(size_t size); |
| 190 | void operator delete(void* target); |
| 191 | |
bsalomon@google.com | d42aca3 | 2013-04-23 15:37:27 +0000 | [diff] [blame] | 192 | void* operator new(size_t size, void* placement) { |
| 193 | return ::operator new(size, placement); |
| 194 | } |
| 195 | void operator delete(void* target, void* placement) { |
| 196 | ::operator delete(target, placement); |
| 197 | } |
| 198 | |
Brian Salomon | b014cca | 2016-11-18 11:39:15 -0500 | [diff] [blame] | 199 | /** Helper for down-casting to a GrProcessor subclass */ |
joshualitt | 49586be | 2014-09-16 08:21:41 -0700 | [diff] [blame] | 200 | template <typename T> const T& cast() const { return *static_cast<const T*>(this); } |
| 201 | |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 202 | ClassID classID() const { return fClassID; } |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 203 | |
bsalomon@google.com | 50db75c | 2013-01-11 13:54:30 +0000 | [diff] [blame] | 204 | protected: |
Chris Dalton | 535ba8d | 2018-02-20 09:51:59 -0700 | [diff] [blame] | 205 | GrProcessor(ClassID classID) : fClassID(classID) {} |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 206 | |
bsalomon | 0e08fc1 | 2014-10-15 08:19:04 -0700 | [diff] [blame] | 207 | private: |
Brian Salomon | d61c9d9 | 2017-04-10 10:54:25 -0400 | [diff] [blame] | 208 | GrProcessor(const GrProcessor&) = delete; |
| 209 | GrProcessor& operator=(const GrProcessor&) = delete; |
| 210 | |
Chris Dalton | 535ba8d | 2018-02-20 09:51:59 -0700 | [diff] [blame] | 211 | ClassID fClassID; |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 212 | }; |
| 213 | |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 214 | #endif |