Chromium Code Reviews| 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; | |
| 17 class GrProcessorKeyBuilder; | 18 class GrProcessorKeyBuilder; |
| 18 | 19 |
| 19 /** Provides custom fragment shader code. Fragment processors receive an input c olor (vec4f) and | 20 /** Provides custom fragment shader code. Fragment processors receive an input c olor (vec4f) and |
| 20 produce an output color. They may reference textures and uniforms. They may use | 21 produce an output color. They may reference textures and uniforms. They may use |
| 21 GrCoordTransforms to receive a transformation of the local coordinates that map from local space | 22 GrCoordTransforms to receive a transformation of the local coordinates that map from local space |
| 22 to the fragment being processed. | 23 to the fragment being processed. |
| 23 */ | 24 */ |
| 24 class GrFragmentProcessor : public GrProcessor { | 25 class GrFragmentProcessor : public GrProcessor { |
| 25 public: | 26 public: |
| 26 /** | 27 /** |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 61 * | 62 * |
| 62 * The array elements with be moved. | 63 * The array elements with be moved. |
| 63 */ | 64 */ |
| 64 static sk_sp<GrFragmentProcessor> RunInSeries(sk_sp<GrFragmentProcessor>*, i nt cnt); | 65 static sk_sp<GrFragmentProcessor> RunInSeries(sk_sp<GrFragmentProcessor>*, i nt cnt); |
| 65 | 66 |
| 66 GrFragmentProcessor() | 67 GrFragmentProcessor() |
| 67 : INHERITED() | 68 : INHERITED() |
| 68 , fUsesDistanceVectorField(false) | 69 , fUsesDistanceVectorField(false) |
| 69 , fUsesLocalCoords(false) | 70 , fUsesLocalCoords(false) |
| 70 , fNumTexturesExclChildren(0) | 71 , fNumTexturesExclChildren(0) |
| 71 , fNumBuffersExclChildren(0) | 72 , 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 numTransformsExclChildren() const { return fNumTransformsExclChildren; } | 89 int numCoordTransforms() const { return fCoordTransforms.count(); } |
| 90 | |
| 91 int numTransforms() const { return fCoordTransforms.count(); } | |
| 92 | 90 |
| 93 /** Returns the coordinate transformation at index. index must be valid acco rding to | 91 /** Returns the coordinate transformation at index. index must be valid acco rding to |
| 94 numTransforms(). */ | 92 numTransforms(). */ |
| 95 const GrCoordTransform& coordTransform(int index) const { return *fCoordTran sforms[index]; } | 93 const GrCoordTransform& coordTransform(int index) const { return *fCoordTran sforms[index]; } |
| 96 | 94 |
| 97 const SkTArray<const GrCoordTransform*, true>& coordTransforms() const { | 95 const SkTArray<const GrCoordTransform*, true>& coordTransforms() const { |
| 98 return fCoordTransforms; | 96 return fCoordTransforms; |
| 99 } | 97 } |
| 100 | 98 |
| 101 void gatherCoordTransforms(SkTArray<const GrCoordTransform*, true>* outTrans forms) const { | 99 void gatherCoordTransforms(SkTArray<const GrCoordTransform*, true>* outTrans forms) const { |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 128 * indicate whether the input components to this processor in the FS will ha ve known values. | 126 * indicate whether the input components to this processor in the FS will ha ve known values. |
| 129 * In inout the validFlags member is a bitfield of GrColorComponentFlags. Th e isSingleComponent | 127 * In inout the validFlags member is a bitfield of GrColorComponentFlags. Th e isSingleComponent |
| 130 * member indicates whether the input will be 1 or 4 bytes. The function upd ates the members of | 128 * member indicates whether the input will be 1 or 4 bytes. The function upd ates the members of |
| 131 * inout to indicate known values of its output. A component of the color me mber only has | 129 * inout to indicate known values of its output. A component of the color me mber only has |
| 132 * meaning if the corresponding bit in validFlags is set. | 130 * meaning if the corresponding bit in validFlags is set. |
| 133 */ | 131 */ |
| 134 void computeInvariantOutput(GrInvariantOutput* inout) const { | 132 void computeInvariantOutput(GrInvariantOutput* inout) const { |
| 135 this->onComputeInvariantOutput(inout); | 133 this->onComputeInvariantOutput(inout); |
| 136 } | 134 } |
| 137 | 135 |
| 136 /** | |
|
robertphillips
2016/09/15 20:44:30
or a the ?
bsalomon
2016/09/15 20:55:52
should be "or of the forest of FPs..."
| |
| 137 * Pre-order traversal of a FP hierarchy, or a the forest of FPs in a GrPipe line. 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 | |
| 138 protected: | 170 protected: |
| 139 void addTextureAccess(const GrTextureAccess* textureAccess) override; | 171 void addTextureAccess(const GrTextureAccess* textureAccess) override; |
| 140 void addBufferAccess(const GrBufferAccess*) override; | 172 void addBufferAccess(const GrBufferAccess*) override; |
| 141 | 173 |
| 142 /** | 174 /** |
| 143 * Fragment Processor subclasses call this from their constructor to registe r coordinate | 175 * Fragment Processor subclasses call this from their constructor to registe r coordinate |
| 144 * transformations. Coord transforms provide a mechanism for a processor to receive coordinates | 176 * transformations. Coord transforms provide a mechanism for a processor to receive coordinates |
| 145 * in their FS code. The matrix expresses a transformation from local space. For a given | 177 * in their FS code. The matrix expresses a transformation from local space. For a given |
| 146 * fragment the matrix will be applied to the local coordinate that maps to the fragment. | 178 * fragment the matrix will be applied to the local coordinate that maps to the fragment. |
| 147 * | 179 * |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 199 * the two processors are of the same subclass (i.e. they return the same ob ject from | 231 * the two processors are of the same subclass (i.e. they return the same ob ject from |
| 200 * getFactory()). The processor subclass should not compare its coord transf orms as that will | 232 * getFactory()). The processor subclass should not compare its coord transf orms as that will |
| 201 * be performed automatically in the non-virtual isEqual(). | 233 * be performed automatically in the non-virtual isEqual(). |
| 202 */ | 234 */ |
| 203 virtual bool onIsEqual(const GrFragmentProcessor&) const = 0; | 235 virtual bool onIsEqual(const GrFragmentProcessor&) const = 0; |
| 204 | 236 |
| 205 bool hasSameTransforms(const GrFragmentProcessor&) const; | 237 bool hasSameTransforms(const GrFragmentProcessor&) const; |
| 206 | 238 |
| 207 bool fUsesLocalCoords; | 239 bool fUsesLocalCoords; |
| 208 | 240 |
| 241 SkSTArray<4, const GrCoordTransform*, true> fCoordTransforms; | |
| 242 | |
| 209 /** | 243 /** |
| 210 * fCoordTransforms stores the transforms of this proc, followed by all the transforms of this | 244 * A processor stores the texture accesses of this proc, followed by all the accesses of this |
| 211 * proc's children. In other words, each proc stores all the transforms of i ts subtree as if | 245 * proc's children. In other words, each proc stores all the accesses of its subtree as if |
| 212 * they were collected using preorder traversal. | 246 * they were collected using preorder traversal. |
| 213 * | 247 * |
| 214 * Example: | 248 * Example: |
| 215 * Suppose we have frag proc A, who has two children B and D. B has a child C, and D has | 249 * Suppose we have frag proc A, who has two children B and D. B has a child C, and D has |
| 216 * two children E and F. Suppose procs A, B, C, D, E, F have 1, 2, 1, 1, 3, 2 transforms | 250 * two children E and F. Suppose procs A, B, C, D, E, F have 1, 2, 1, 1, 3, 2 accesses |
| 217 * respectively. The following shows what the fCoordTransforms array of each proc would contain: | 251 * respectively. The following shows what the array of each proc's texture a ccesses would |
| 252 * contain: | |
| 218 * | 253 * |
| 219 * (A) | 254 * (A) |
| 220 * [a1,b1,b2,c1,d1,e1,e2,e3,f1,f2] | 255 * [a1,b1,b2,c1,d1,e1,e2,e3,f1,f2] |
| 221 * / \ | 256 * / \ |
| 222 * / \ | 257 * / \ |
| 223 * (B) (D) | 258 * (B) (D) |
| 224 * [b1,b2,c1] [d1,e1,e2,e3,f1,f2] | 259 * [b1,b2,c1] [d1,e1,e2,e3,f1,f2] |
| 225 * / / \ | 260 * / / \ |
| 226 * / / \ | 261 * / / \ |
| 227 * (C) (E) (F) | 262 * (C) (E) (F) |
| 228 * [c1] [e1,e2,e3] [f1,f2] | 263 * [c1] [e1,e2,e3] [f1,f2] |
| 229 * | 264 * |
| 230 * The same goes for fTextureAccesses with textures. | 265 * The same goes for buffer accesses. |
| 231 */ | 266 */ |
| 232 SkSTArray<4, const GrCoordTransform*, true> fCoordTransforms; | |
| 233 int fNumTexturesExclChildren; | 267 int fNumTexturesExclChildren; |
| 234 int fNumBuffersExclChildren; | 268 int fNumBuffersExclChildren; |
| 235 int fNumTransformsExclChildren; | |
| 236 | 269 |
| 237 /** | 270 /** |
| 238 * This is not SkSTArray<1, sk_sp<GrFragmentProcessor>> because this class h olds strong | 271 * This is not SkSTArray<1, sk_sp<GrFragmentProcessor>> because this class h olds strong |
| 239 * references until notifyRefCntIsZero and then it holds pending executions. | 272 * references until notifyRefCntIsZero and then it holds pending executions. |
| 240 */ | 273 */ |
| 241 SkSTArray<1, GrFragmentProcessor*, true> fChildProcessors; | 274 SkSTArray<1, GrFragmentProcessor*, true> fChildProcessors; |
| 242 | 275 |
| 243 typedef GrProcessor INHERITED; | 276 typedef GrProcessor INHERITED; |
| 244 }; | 277 }; |
| 245 | 278 |
| 246 #endif | 279 #endif |
| OLD | NEW |