blob: 9eba39091f2c187afa461d1261a159461aa0e225 [file] [log] [blame]
tomhudson@google.com168e6342012-04-18 17:49:20 +00001/*
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
joshualittb0a8a372014-09-23 09:50:21 -07008#ifndef GrProcessor_DEFINED
9#define GrProcessor_DEFINED
tomhudson@google.com168e6342012-04-18 17:49:20 +000010
Brian Salomon0c26a9d2017-07-06 10:09:38 -040011#include "../private/SkAtomics.h"
Brian Salomonb014cca2016-11-18 11:39:15 -050012#include "GrBuffer.h"
Brian Salomon0c26a9d2017-07-06 10:09:38 -040013#include "GrColor.h"
joshualittb0a8a372014-09-23 09:50:21 -070014#include "GrProcessorUnitTest.h"
Brian Salomon2bbdcc42017-09-07 12:36:34 -040015#include "GrSamplerState.h"
Brian Salomonf9f45122016-11-29 11:59:17 -050016#include "GrShaderVar.h"
Robert Phillips8a02f652017-05-12 14:49:16 -040017#include "GrSurfaceProxyPriv.h"
Brian Salomon0c26a9d2017-07-06 10:09:38 -040018#include "GrTextureProxy.h"
egdaniel9e4d6d12014-10-15 13:49:02 -070019#include "SkMath.h"
robertphillipse004bfc2015-11-16 09:06:59 -080020#include "SkString.h"
tomhudson@google.com07eecdc2012-04-20 18:35:38 +000021
tomhudson@google.com168e6342012-04-18 17:49:20 +000022class GrContext;
Brian Osman32342f02017-03-04 08:12:46 -050023class GrResourceProvider;
bsalomon95740982014-09-04 13:12:37 -070024
joshualitteb2a6762014-12-04 11:35:33 -080025/**
26 * Used by processors to build their keys. It incorporates each per-processor key into a larger
27 * shader key.
28 */
29class GrProcessorKeyBuilder {
30public:
31 GrProcessorKeyBuilder(SkTArray<unsigned char, true>* data) : fData(data), fCount(0) {
32 SkASSERT(0 == fData->count() % sizeof(uint32_t));
33 }
34
35 void add32(uint32_t v) {
36 ++fCount;
37 fData->push_back_n(4, reinterpret_cast<uint8_t*>(&v));
38 }
39
40 /** Inserts count uint32_ts into the key. The returned pointer is only valid until the next
41 add*() call. */
42 uint32_t* SK_WARN_UNUSED_RESULT add32n(int count) {
43 SkASSERT(count > 0);
44 fCount += count;
45 return reinterpret_cast<uint32_t*>(fData->push_back_n(4 * count));
46 }
47
48 size_t size() const { return sizeof(uint32_t) * fCount; }
49
50private:
51 SkTArray<uint8_t, true>* fData; // unowned ptr to the larger key.
52 int fCount; // number of uint32_ts added to fData by the processor.
53};
54
bsalomon98b33eb2014-10-15 11:05:26 -070055/** Provides custom shader code to the Ganesh shading pipeline. GrProcessor objects *must* be
56 immutable: after being constructed, their fields may not change.
bsalomon@google.com0ac6af42013-01-16 15:16:18 +000057
joshualittb0a8a372014-09-23 09:50:21 -070058 Dynamically allocated GrProcessors are managed by a per-thread memory pool. The ref count of an
mdempsky38f1f6f2015-08-27 12:57:01 -070059 processor must reach 0 before the thread terminates and the pool is destroyed.
bsalomon98b33eb2014-10-15 11:05:26 -070060 */
Brian Salomond61c9d92017-04-10 10:54:25 -040061class GrProcessor {
tomhudson@google.com168e6342012-04-18 17:49:20 +000062public:
Ethan Nicholasabff9562017-10-09 10:54:08 -040063 enum ClassID {
Ethan Nicholasabff9562017-10-09 10:54:08 -040064 kBigKeyProcessor_ClassID,
65 kBlockInputFragmentProcessor_ClassID,
Brian Salomon62e4f3d2018-04-20 13:54:11 -040066 kButtCapStrokedCircleGeometryProcessor_ClassID,
Ethan Nicholasabff9562017-10-09 10:54:08 -040067 kCircleGeometryProcessor_ClassID,
Ethan Nicholasabff9562017-10-09 10:54:08 -040068 kCircularRRectEffect_ClassID,
Chris Dalton49d14e92018-07-27 12:38:35 -060069 kClockwiseTestProcessor_ClassID,
Ethan Nicholasabff9562017-10-09 10:54:08 -040070 kColorMatrixEffect_ClassID,
71 kColorTableEffect_ClassID,
72 kComposeOneFragmentProcessor_ClassID,
73 kComposeTwoFragmentProcessor_ClassID,
74 kCoverageSetOpXP_ClassID,
Chris Dalton09a7bb22018-08-31 19:53:15 +080075 kCubicStrokeProcessor_ClassID,
Ethan Nicholasabff9562017-10-09 10:54:08 -040076 kCustomXP_ClassID,
77 kDashingCircleEffect_ClassID,
78 kDashingLineEffect_ClassID,
79 kDefaultGeoProc_ClassID,
80 kDIEllipseGeometryProcessor_ClassID,
81 kDisableColorXP_ClassID,
Yuqian Li915817b2017-12-14 13:45:08 -050082 kTwoPointConicalEffect_ClassID,
Ethan Nicholasabff9562017-10-09 10:54:08 -040083 kEllipseGeometryProcessor_ClassID,
84 kEllipticalRRectEffect_ClassID,
Ethan Nicholasabff9562017-10-09 10:54:08 -040085 kGP_ClassID,
Brian Osman387eaff2018-07-20 14:50:44 -040086 kVertexColorSpaceBenchGP_ClassID,
Ethan Nicholas8dca18a2017-11-15 15:33:33 -050087 kGrAARectEffect_ClassID,
Ethan Nicholasabff9562017-10-09 10:54:08 -040088 kGrAlphaThresholdFragmentProcessor_ClassID,
Ethan Nicholasc9472af2017-10-10 16:30:21 -040089 kGrArithmeticFP_ClassID,
Ethan Nicholasabff9562017-10-09 10:54:08 -040090 kGrBicubicEffect_ClassID,
91 kGrBitmapTextGeoProc_ClassID,
92 kGrBlurredEdgeFragmentProcessor_ClassID,
Chris Dalton383a2ef2018-01-08 17:21:41 -050093 kGrCCClipProcessor_ClassID,
94 kGrCCCoverageProcessor_ClassID,
95 kGrCCPathProcessor_ClassID,
Ethan Nicholasabff9562017-10-09 10:54:08 -040096 kGrCircleBlurFragmentProcessor_ClassID,
97 kGrCircleEffect_ClassID,
Michael Ludwig10f7a1e2018-09-11 10:19:08 -040098 kGrClampedGradientEffect_ClassID,
Brian Osmanc4f93ca2017-10-17 17:15:52 -040099 kGrColorSpaceXformEffect_ClassID,
Ethan Nicholasabff9562017-10-09 10:54:08 -0400100 kGrConfigConversionEffect_ClassID,
101 kGrConicEffect_ClassID,
102 kGrConstColorProcessor_ClassID,
103 kGrConvexPolyEffect_ClassID,
104 kGrCubicEffect_ClassID,
105 kGrDeviceSpaceTextureDecalFragmentProcessor_ClassID,
106 kGrDiffuseLightingEffect_ClassID,
107 kGrDisplacementMapEffect_ClassID,
108 kGrDistanceFieldA8TextGeoProc_ClassID,
109 kGrDistanceFieldLCDTextGeoProc_ClassID,
110 kGrDistanceFieldPathGeoProc_ClassID,
111 kGrDitherEffect_ClassID,
112 kGrEllipseEffect_ClassID,
113 kGrGaussianConvolutionFragmentProcessor_ClassID,
114 kGrImprovedPerlinNoiseEffect_ClassID,
115 kGrLightingEffect_ClassID,
116 kGrLinearGradient_ClassID,
Michael Ludwig10f7a1e2018-09-11 10:19:08 -0400117 kGrLinearGradientLayout_ClassID,
Ethan Nicholas14efcbf2017-11-07 09:23:38 -0500118 kGrLumaColorFilterEffect_ClassID,
Ethan Nicholasabff9562017-10-09 10:54:08 -0400119 kGrMagnifierEffect_ClassID,
120 kGrMatrixConvolutionEffect_ClassID,
121 kGrMeshTestProcessor_ClassID,
122 kGrMorphologyEffect_ClassID,
Ethan Nicholasd608c092017-10-26 09:30:08 -0400123 kGrOverdrawFragmentProcessor_ClassID,
Ethan Nicholasabff9562017-10-09 10:54:08 -0400124 kGrPathProcessor_ClassID,
125 kGrPerlinNoise2Effect_ClassID,
126 kGrPipelineDynamicStateTestProcessor_ClassID,
Ethan Nicholasbe0a0422017-11-17 13:44:05 -0500127 kGrPremulInputFragmentProcessor_ClassID,
Ethan Nicholasabff9562017-10-09 10:54:08 -0400128 kGrQuadEffect_ClassID,
129 kGrRadialGradient_ClassID,
130 kGrRectBlurEffect_ClassID,
131 kGrRRectBlurEffect_ClassID,
132 kGrRRectShadowGeoProc_ClassID,
133 kGrSimpleTextureEffect_ClassID,
Michael Ludwig10f7a1e2018-09-11 10:19:08 -0400134 kGrSingleIntervalGradientColorizer_ClassID,
Ethan Nicholas00543112018-07-31 09:44:36 -0400135 kGrSkSLFP_ClassID,
Ethan Nicholasabff9562017-10-09 10:54:08 -0400136 kGrSpecularLightingEffect_ClassID,
137 kGrSRGBEffect_ClassID,
138 kGrSweepGradient_ClassID,
139 kGrTextureDomainEffect_ClassID,
Michael Ludwig10f7a1e2018-09-11 10:19:08 -0400140 kGrTiledGradientEffect_ClassID,
Ethan Nicholasbe0a0422017-11-17 13:44:05 -0500141 kGrUnpremulInputFragmentProcessor_ClassID,
Ethan Nicholas7461a4a2017-12-21 14:18:01 -0500142 kGrYUVtoRGBEffect_ClassID,
Ethan Nicholasabff9562017-10-09 10:54:08 -0400143 kHighContrastFilterEffect_ClassID,
144 kInstanceProcessor_ClassID,
Brian Salomon2a943df2018-05-04 13:43:19 -0400145 kLatticeGP_ClassID,
Ethan Nicholasabff9562017-10-09 10:54:08 -0400146 kLumaColorFilterEffect_ClassID,
147 kMSAAQuadProcessor_ClassID,
Ethan Nicholasabff9562017-10-09 10:54:08 -0400148 kPDLCDXferProcessor_ClassID,
149 kPorterDuffXferProcessor_ClassID,
150 kPremulFragmentProcessor_ClassID,
Ethan Nicholasabff9562017-10-09 10:54:08 -0400151 kQuadEdgeEffect_ClassID,
152 kReplaceInputFragmentProcessor_ClassID,
153 kRRectsGaussianEdgeFP_ClassID,
154 kSeriesFragmentProcessor_ClassID,
155 kShaderPDXferProcessor_ClassID,
156 kSwizzleFragmentProcessor_ClassID,
157 kTestFP_ClassID,
158 kTextureGeometryProcessor_ClassID,
Robert Phillipsa8cdbd72018-07-17 12:30:40 -0400159 kFlatNormalsFP_ClassID,
160 kMappedNormalsFP_ClassID,
161 kLightingFP_ClassID,
Chris Dalton09a7bb22018-08-31 19:53:15 +0800162 kLinearStrokeProcessor_ClassID,
Ethan Nicholasabff9562017-10-09 10:54:08 -0400163 };
164
Brian Salomonab015ef2017-04-04 10:15:51 -0400165 virtual ~GrProcessor() = default;
tomhudson@google.com168e6342012-04-18 17:49:20 +0000166
Brian Salomonb014cca2016-11-18 11:39:15 -0500167 /** Human-meaningful string to identify this prcoessor; may be embedded in generated shader
168 code. */
joshualitteb2a6762014-12-04 11:35:33 -0800169 virtual const char* name() const = 0;
bsalomon@google.com289efe02012-05-21 20:57:59 +0000170
Brian Salomonb014cca2016-11-18 11:39:15 -0500171 /** Human-readable dump of all information */
robertphillipse004bfc2015-11-16 09:06:59 -0800172 virtual SkString dumpInfo() const {
173 SkString str;
174 str.appendf("Missing data");
175 return str;
176 }
177
tomhudson@google.comdcba4c22012-07-24 21:36:16 +0000178 void* operator new(size_t size);
179 void operator delete(void* target);
180
bsalomon@google.comd42aca32013-04-23 15:37:27 +0000181 void* operator new(size_t size, void* placement) {
182 return ::operator new(size, placement);
183 }
184 void operator delete(void* target, void* placement) {
185 ::operator delete(target, placement);
186 }
187
Brian Salomonb014cca2016-11-18 11:39:15 -0500188 /** Helper for down-casting to a GrProcessor subclass */
joshualitt49586be2014-09-16 08:21:41 -0700189 template <typename T> const T& cast() const { return *static_cast<const T*>(this); }
190
Ethan Nicholasabff9562017-10-09 10:54:08 -0400191 ClassID classID() const { return fClassID; }
joshualitteb2a6762014-12-04 11:35:33 -0800192
bsalomon@google.com50db75c2013-01-11 13:54:30 +0000193protected:
Chris Dalton535ba8d2018-02-20 09:51:59 -0700194 GrProcessor(ClassID classID) : fClassID(classID) {}
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000195
bsalomon0e08fc12014-10-15 08:19:04 -0700196private:
Brian Salomond61c9d92017-04-10 10:54:25 -0400197 GrProcessor(const GrProcessor&) = delete;
198 GrProcessor& operator=(const GrProcessor&) = delete;
199
Chris Dalton535ba8d2018-02-20 09:51:59 -0700200 ClassID fClassID;
tomhudson@google.com168e6342012-04-18 17:49:20 +0000201};
202
tomhudson@google.com168e6342012-04-18 17:49:20 +0000203#endif