| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef GrFragmentProcessor_DEFINED | 8 #ifndef GrFragmentProcessor_DEFINED |
| 9 #define GrFragmentProcessor_DEFINED | 9 #define GrFragmentProcessor_DEFINED |
| 10 | 10 |
| 11 #include "GrProcessor.h" | 11 #include "GrProcessor.h" |
| 12 | 12 |
| 13 class GrCoordTransform; | 13 class GrCoordTransform; |
| 14 class GrGLSLCaps; | 14 class GrGLSLCaps; |
| 15 class GrGLSLFragmentProcessor; | 15 class GrGLSLFragmentProcessor; |
| 16 class GrInvariantOutput; | 16 class GrInvariantOutput; |
| 17 class GrPipeline; | |
| 18 class GrProcessorKeyBuilder; | 17 class GrProcessorKeyBuilder; |
| 19 | 18 |
| 20 /** Provides custom fragment shader code. Fragment processors receive an input c
olor (vec4f) and | 19 /** Provides custom fragment shader code. Fragment processors receive an input c
olor (vec4f) and |
| 21 produce an output color. They may reference textures and uniforms. They may
use | 20 produce an output color. They may reference textures and uniforms. They may
use |
| 22 GrCoordTransforms to receive a transformation of the local coordinates that
map from local space | 21 GrCoordTransforms to receive a transformation of the local coordinates that
map from local space |
| 23 to the fragment being processed. | 22 to the fragment being processed. |
| 24 */ | 23 */ |
| 25 class GrFragmentProcessor : public GrProcessor { | 24 class GrFragmentProcessor : public GrProcessor { |
| 26 public: | 25 public: |
| 27 /** | 26 /** |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 * | 61 * |
| 63 * The array elements with be moved. | 62 * The array elements with be moved. |
| 64 */ | 63 */ |
| 65 static sk_sp<GrFragmentProcessor> RunInSeries(sk_sp<GrFragmentProcessor>*, i
nt cnt); | 64 static sk_sp<GrFragmentProcessor> RunInSeries(sk_sp<GrFragmentProcessor>*, i
nt cnt); |
| 66 | 65 |
| 67 GrFragmentProcessor() | 66 GrFragmentProcessor() |
| 68 : INHERITED() | 67 : INHERITED() |
| 69 , fUsesDistanceVectorField(false) | 68 , fUsesDistanceVectorField(false) |
| 70 , fUsesLocalCoords(false) | 69 , fUsesLocalCoords(false) |
| 71 , fNumTexturesExclChildren(0) | 70 , fNumTexturesExclChildren(0) |
| 72 , fNumBuffersExclChildren(0) {} | 71 , fNumBuffersExclChildren(0) |
| 72 , fNumTransformsExclChildren(0) {} |
| 73 | 73 |
| 74 ~GrFragmentProcessor() override; | 74 ~GrFragmentProcessor() override; |
| 75 | 75 |
| 76 GrGLSLFragmentProcessor* createGLSLInstance() const; | 76 GrGLSLFragmentProcessor* createGLSLInstance() const; |
| 77 | 77 |
| 78 void getGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) c
onst { | 78 void getGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) c
onst { |
| 79 this->onGetGLSLProcessorKey(caps, b); | 79 this->onGetGLSLProcessorKey(caps, b); |
| 80 for (int i = 0; i < fChildProcessors.count(); ++i) { | 80 for (int i = 0; i < fChildProcessors.count(); ++i) { |
| 81 fChildProcessors[i]->getGLSLProcessorKey(caps, b); | 81 fChildProcessors[i]->getGLSLProcessorKey(caps, b); |
| 82 } | 82 } |
| 83 } | 83 } |
| 84 | 84 |
| 85 int numTexturesExclChildren() const { return fNumTexturesExclChildren; } | 85 int numTexturesExclChildren() const { return fNumTexturesExclChildren; } |
| 86 | 86 |
| 87 int numBuffersExclChildren() const { return fNumBuffersExclChildren; } | 87 int numBuffersExclChildren() const { return fNumBuffersExclChildren; } |
| 88 | 88 |
| 89 int numCoordTransforms() const { return fCoordTransforms.count(); } | 89 int numTransformsExclChildren() const { return fNumTransformsExclChildren; } |
| 90 |
| 91 int numTransforms() const { return fCoordTransforms.count(); } |
| 90 | 92 |
| 91 /** Returns the coordinate transformation at index. index must be valid acco
rding to | 93 /** Returns the coordinate transformation at index. index must be valid acco
rding to |
| 92 numTransforms(). */ | 94 numTransforms(). */ |
| 93 const GrCoordTransform& coordTransform(int index) const { return *fCoordTran
sforms[index]; } | 95 const GrCoordTransform& coordTransform(int index) const { return *fCoordTran
sforms[index]; } |
| 94 | 96 |
| 95 const SkTArray<const GrCoordTransform*, true>& coordTransforms() const { | 97 const SkTArray<const GrCoordTransform*, true>& coordTransforms() const { |
| 96 return fCoordTransforms; | 98 return fCoordTransforms; |
| 97 } | 99 } |
| 98 | 100 |
| 99 void gatherCoordTransforms(SkTArray<const GrCoordTransform*, true>* outTrans
forms) const { | 101 void gatherCoordTransforms(SkTArray<const GrCoordTransform*, true>* outTrans
forms) const { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 126 * indicate whether the input components to this processor in the FS will ha
ve known values. | 128 * indicate whether the input components to this processor in the FS will ha
ve known values. |
| 127 * In inout the validFlags member is a bitfield of GrColorComponentFlags. Th
e isSingleComponent | 129 * In inout the validFlags member is a bitfield of GrColorComponentFlags. Th
e isSingleComponent |
| 128 * member indicates whether the input will be 1 or 4 bytes. The function upd
ates the members of | 130 * member indicates whether the input will be 1 or 4 bytes. The function upd
ates the members of |
| 129 * inout to indicate known values of its output. A component of the color me
mber only has | 131 * inout to indicate known values of its output. A component of the color me
mber only has |
| 130 * meaning if the corresponding bit in validFlags is set. | 132 * meaning if the corresponding bit in validFlags is set. |
| 131 */ | 133 */ |
| 132 void computeInvariantOutput(GrInvariantOutput* inout) const { | 134 void computeInvariantOutput(GrInvariantOutput* inout) const { |
| 133 this->onComputeInvariantOutput(inout); | 135 this->onComputeInvariantOutput(inout); |
| 134 } | 136 } |
| 135 | 137 |
| 136 /** | |
| 137 * Pre-order traversal of a FP hierarchy, or of the forest of FPs in a GrPip
eline. In the latter | |
| 138 * case the tree rooted at each FP in the GrPipeline is visited successively
. | |
| 139 * */ | |
| 140 class Iter : public SkNoncopyable { | |
| 141 public: | |
| 142 explicit Iter(const GrFragmentProcessor* fp) { fFPStack.push_back(fp); } | |
| 143 explicit Iter(const GrPipeline& pipeline); | |
| 144 const GrFragmentProcessor* next(); | |
| 145 | |
| 146 private: | |
| 147 SkSTArray<4, const GrFragmentProcessor*, true> fFPStack; | |
| 148 }; | |
| 149 | |
| 150 /** | |
| 151 * Iterates over all the GrCoordTransforms in a GrPipeline's GrFragmentProce
ssors. FPs are | |
| 152 * visited in the same order as Iter and each of an FP's coord transforms ar
e visited linearly. | |
| 153 */ | |
| 154 class CoordTransformIter : public SkNoncopyable { | |
| 155 public: | |
| 156 explicit CoordTransformIter(const GrPipeline& pipeline) | |
| 157 : fCurrFP(nullptr) | |
| 158 , fCTIdx(0) | |
| 159 , fFPIter(pipeline) { | |
| 160 fCurrFP = fFPIter.next(); | |
| 161 } | |
| 162 const GrCoordTransform* next(); | |
| 163 | |
| 164 private: | |
| 165 const GrFragmentProcessor* fCurrFP; | |
| 166 int fCTIdx; | |
| 167 GrFragmentProcessor::Iter fFPIter; | |
| 168 }; | |
| 169 | |
| 170 protected: | 138 protected: |
| 171 void addTextureAccess(const GrTextureAccess* textureAccess) override; | 139 void addTextureAccess(const GrTextureAccess* textureAccess) override; |
| 172 void addBufferAccess(const GrBufferAccess*) override; | 140 void addBufferAccess(const GrBufferAccess*) override; |
| 173 | 141 |
| 174 /** | 142 /** |
| 175 * Fragment Processor subclasses call this from their constructor to registe
r coordinate | 143 * Fragment Processor subclasses call this from their constructor to registe
r coordinate |
| 176 * transformations. Coord transforms provide a mechanism for a processor to
receive coordinates | 144 * transformations. Coord transforms provide a mechanism for a processor to
receive coordinates |
| 177 * in their FS code. The matrix expresses a transformation from local space.
For a given | 145 * in their FS code. The matrix expresses a transformation from local space.
For a given |
| 178 * fragment the matrix will be applied to the local coordinate that maps to
the fragment. | 146 * fragment the matrix will be applied to the local coordinate that maps to
the fragment. |
| 179 * | 147 * |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 * the two processors are of the same subclass (i.e. they return the same ob
ject from | 199 * the two processors are of the same subclass (i.e. they return the same ob
ject from |
| 232 * getFactory()). The processor subclass should not compare its coord transf
orms as that will | 200 * getFactory()). The processor subclass should not compare its coord transf
orms as that will |
| 233 * be performed automatically in the non-virtual isEqual(). | 201 * be performed automatically in the non-virtual isEqual(). |
| 234 */ | 202 */ |
| 235 virtual bool onIsEqual(const GrFragmentProcessor&) const = 0; | 203 virtual bool onIsEqual(const GrFragmentProcessor&) const = 0; |
| 236 | 204 |
| 237 bool hasSameTransforms(const GrFragmentProcessor&) const; | 205 bool hasSameTransforms(const GrFragmentProcessor&) const; |
| 238 | 206 |
| 239 bool fUsesLocalCoords; | 207 bool fUsesLocalCoords; |
| 240 | 208 |
| 241 SkSTArray<4, const GrCoordTransform*, true> fCoordTransforms; | |
| 242 | |
| 243 /** | 209 /** |
| 244 * A processor stores the texture accesses of this proc, followed by all the
accesses of this | 210 * fCoordTransforms stores the transforms of this proc, followed by all the
transforms of this |
| 245 * proc's children. In other words, each proc stores all the accesses of its
subtree as if | 211 * proc's children. In other words, each proc stores all the transforms of i
ts subtree as if |
| 246 * they were collected using preorder traversal. | 212 * they were collected using preorder traversal. |
| 247 * | 213 * |
| 248 * Example: | 214 * Example: |
| 249 * Suppose we have frag proc A, who has two children B and D. B has a child
C, and D has | 215 * Suppose we have frag proc A, who has two children B and D. B has a child
C, and D has |
| 250 * two children E and F. Suppose procs A, B, C, D, E, F have 1, 2, 1, 1, 3,
2 accesses | 216 * two children E and F. Suppose procs A, B, C, D, E, F have 1, 2, 1, 1, 3,
2 transforms |
| 251 * respectively. The following shows what the array of each proc's texture a
ccesses would | 217 * respectively. The following shows what the fCoordTransforms array of each
proc would contain: |
| 252 * contain: | |
| 253 * | 218 * |
| 254 * (A) | 219 * (A) |
| 255 * [a1,b1,b2,c1,d1,e1,e2,e3,f1,f2] | 220 * [a1,b1,b2,c1,d1,e1,e2,e3,f1,f2] |
| 256 * / \ | 221 * / \ |
| 257 * / \ | 222 * / \ |
| 258 * (B) (D) | 223 * (B) (D) |
| 259 * [b1,b2,c1] [d1,e1,e2,e3,f1,f2] | 224 * [b1,b2,c1] [d1,e1,e2,e3,f1,f2] |
| 260 * / / \ | 225 * / / \ |
| 261 * / / \ | 226 * / / \ |
| 262 * (C) (E) (F) | 227 * (C) (E) (F) |
| 263 * [c1] [e1,e2,e3] [f1,f2] | 228 * [c1] [e1,e2,e3] [f1,f2] |
| 264 * | 229 * |
| 265 * The same goes for buffer accesses. | 230 * The same goes for fTextureAccesses with textures. |
| 266 */ | 231 */ |
| 232 SkSTArray<4, const GrCoordTransform*, true> fCoordTransforms; |
| 267 int fNumTexturesExclChildren; | 233 int fNumTexturesExclChildren; |
| 268 int fNumBuffersExclChildren; | 234 int fNumBuffersExclChildren; |
| 235 int fNumTransformsExclChildren; |
| 269 | 236 |
| 270 /** | 237 /** |
| 271 * This is not SkSTArray<1, sk_sp<GrFragmentProcessor>> because this class h
olds strong | 238 * This is not SkSTArray<1, sk_sp<GrFragmentProcessor>> because this class h
olds strong |
| 272 * references until notifyRefCntIsZero and then it holds pending executions. | 239 * references until notifyRefCntIsZero and then it holds pending executions. |
| 273 */ | 240 */ |
| 274 SkSTArray<1, GrFragmentProcessor*, true> fChildProcessors; | 241 SkSTArray<1, GrFragmentProcessor*, true> fChildProcessors; |
| 275 | 242 |
| 276 typedef GrProcessor INHERITED; | 243 typedef GrProcessor INHERITED; |
| 277 }; | 244 }; |
| 278 | 245 |
| 279 #endif | 246 #endif |
| OLD | NEW |