Skia
2DGraphicsLibrary
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GrFragmentProcessor.h
1 /*
2  * Copyright 2014 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 GrFragmentProcessor_DEFINED
9 #define GrFragmentProcessor_DEFINED
10 
11 #include "GrProcessor.h"
12 
13 class GrCoordTransform;
14 class GrGLSLCaps;
15 class GrGLSLFragmentProcessor;
16 class GrInvariantOutput;
18 
25 public:
35 
42 
49 
55 
65 
67  : INHERITED()
68  , fUsesDistanceVectorField(false)
69  , fUsesLocalCoords(false)
70  , fNumTexturesExclChildren(0)
71  , fNumBuffersExclChildren(0)
72  , fNumTransformsExclChildren(0) {}
73 
74  ~GrFragmentProcessor() override;
75 
76  GrGLSLFragmentProcessor* createGLSLInstance() const;
77 
78  void getGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) const {
79  this->onGetGLSLProcessorKey(caps, b);
80  for (int i = 0; i < fChildProcessors.count(); ++i) {
81  fChildProcessors[i]->getGLSLProcessorKey(caps, b);
82  }
83  }
84 
85  int numTexturesExclChildren() const { return fNumTexturesExclChildren; }
86 
87  int numBuffersExclChildren() const { return fNumBuffersExclChildren; }
88 
89  int numTransformsExclChildren() const { return fNumTransformsExclChildren; }
90 
91  int numTransforms() const { return fCoordTransforms.count(); }
92 
95  const GrCoordTransform& coordTransform(int index) const { return *fCoordTransforms[index]; }
96 
97  const SkTArray<const GrCoordTransform*, true>& coordTransforms() const {
98  return fCoordTransforms;
99  }
100 
101  void gatherCoordTransforms(SkTArray<const GrCoordTransform*, true>* outTransforms) const {
102  if (!fCoordTransforms.empty()) {
103  outTransforms->push_back_n(fCoordTransforms.count(), fCoordTransforms.begin());
104  }
105  }
106 
107  int numChildProcessors() const { return fChildProcessors.count(); }
108 
109  const GrFragmentProcessor& childProcessor(int index) const { return *fChildProcessors[index]; }
110 
112  bool usesLocalCoords() const { return fUsesLocalCoords; }
113 
115  bool usesDistanceVectorField() const { return fUsesDistanceVectorField; }
116 
124  bool isEqual(const GrFragmentProcessor& that, bool ignoreCoordTransforms) const;
125 
135  this->onComputeInvariantOutput(inout);
136  }
137 
138 protected:
139  void addTextureAccess(const GrTextureAccess* textureAccess) override;
140  void addBufferAccess(const GrBufferAccess*) override;
141 
159  void addCoordTransform(const GrCoordTransform*);
160 
171 
178  virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const = 0;
179 
180  /* Sub-classes should set this to true in their constructors if they need access to a distance
181  * vector field to the nearest edge
182  */
183  bool fUsesDistanceVectorField;
184 
185 private:
186  void notifyRefCntIsZero() const final;
187 
191  virtual GrGLSLFragmentProcessor* onCreateGLSLInstance() const = 0;
192 
194  virtual void onGetGLSLProcessorKey(const GrGLSLCaps& caps,
195  GrProcessorKeyBuilder* b) const = 0;
196 
203  virtual bool onIsEqual(const GrFragmentProcessor&) const = 0;
204 
205  bool hasSameTransforms(const GrFragmentProcessor&) const;
206 
207  bool fUsesLocalCoords;
208 
232  SkSTArray<4, const GrCoordTransform*, true> fCoordTransforms;
233  int fNumTexturesExclChildren;
234  int fNumBuffersExclChildren;
235  int fNumTransformsExclChildren;
236 
241  SkSTArray<1, GrFragmentProcessor*, true> fChildProcessors;
242 
243  typedef GrProcessor INHERITED;
244 };
245 
246 #endif
Used to represent a texture that is required by a GrProcessor.
Definition: GrTextureAccess.h:21
SkSTArray< 1, GrFragmentProcessor *, true > fChildProcessors
This is not SkSTArray<1, sk_sp<GrFragmentProcessor>> because this class holds strong references until...
Definition: GrFragmentProcessor.h:241
void addTextureAccess(const GrTextureAccess *textureAccess) override
Subclasses call these from their constructor to register sampler sources.
Provides custom fragment shader code.
Definition: GrFragmentProcessor.h:24
const GrCoordTransform & coordTransform(int index) const
Returns the coordinate transformation at index.
Definition: GrFragmentProcessor.h:95
Used to represent a texel buffer that will be read in a GrProcessor.
Definition: GrBufferAccess.h:18
static sk_sp< GrFragmentProcessor > MulOutputByInputUnpremulColor(sk_sp< GrFragmentProcessor >)
Similar to the above but it modulates the output r,g,b of the child processor by the input rgb and th...
int registerChildProcessor(sk_sp< GrFragmentProcessor > child)
FragmentProcessor subclasses call this from their constructor to register any child FragmentProcessor...
virtual bool onIsEqual(const GrFragmentProcessor &) const =0
Subclass implements this to support isEqual().
void notifyRefCntIsZero() const final
This will be called when the ref cnt is zero.
Used by processors to build their keys.
Definition: GrProcessor.h:28
bool isEqual(const GrFragmentProcessor &that, bool ignoreCoordTransforms) const
Returns true if this and other processor conservatively draw identically.
bool usesDistanceVectorField() const
Does this FP need a vector to the nearest edge?
Definition: GrFragmentProcessor.h:115
void computeInvariantOutput(GrInvariantOutput *inout) const
This function is used to perform optimizations.
Definition: GrFragmentProcessor.h:134
static sk_sp< GrFragmentProcessor > PremulInput(sk_sp< GrFragmentProcessor >)
Returns a fragment processor that premuls the input before calling the passed in fragment processor...
Shared pointer class to wrap classes that support a ref()/unref() interface.
Definition: SkRefCnt.h:258
static sk_sp< GrFragmentProcessor > MulOutputByInputAlpha(sk_sp< GrFragmentProcessor >)
In many instances (e.g.
A class representing a linear transformation from one of the built-in coordinate sets (local or posit...
Definition: GrCoordTransform.h:43
bool usesLocalCoords() const
Do any of the coordtransforms for this processor require local coords?
Definition: GrFragmentProcessor.h:112
Definition: GrInvariantOutput.h:57
virtual GrGLSLFragmentProcessor * onCreateGLSLInstance() const =0
Returns a new instance of the appropriate GL implementation class for the given GrFragmentProcessor; ...
const GrTextureAccess & textureAccess(int index) const
Returns the access pattern for the texture at index.
Definition: GrProcessor.h:79
static sk_sp< GrFragmentProcessor > RunInSeries(sk_sp< GrFragmentProcessor > *, int cnt)
Returns a fragment processor that runs the passed in array of fragment processors in a series...
virtual void onGetGLSLProcessorKey(const GrGLSLCaps &caps, GrProcessorKeyBuilder *b) const =0
Implemented using GLFragmentProcessor::GenKey as described in this class's comment.
Provides custom shader code to the Ganesh shading pipeline.
Definition: GrProcessor.h:60
SkSTArray< 4, const GrCoordTransform *, true > fCoordTransforms
fCoordTransforms stores the transforms of this proc, followed by all the transforms of this proc's ch...
Definition: GrFragmentProcessor.h:232
virtual void onComputeInvariantOutput(GrInvariantOutput *inout) const =0
Subclass implements this to support getConstantColorComponents(...).
static sk_sp< GrFragmentProcessor > OverrideInput(sk_sp< GrFragmentProcessor >, GrColor)
Returns a parent fragment processor that adopts the passed fragment processor as a child...
void addCoordTransform(const GrCoordTransform *)
Fragment Processor subclasses call this from their constructor to register coordinate transformations...