Chromium Code Reviews| Index: include/gpu/GrFragmentProcessor.h |
| diff --git a/include/gpu/GrFragmentProcessor.h b/include/gpu/GrFragmentProcessor.h |
| index 2dc79809647758e9e6d3eac4498b31fa996cdffe..24f728aa0418b8e97e17dda91e6448be97d31e3c 100644 |
| --- a/include/gpu/GrFragmentProcessor.h |
| +++ b/include/gpu/GrFragmentProcessor.h |
| @@ -9,6 +9,7 @@ |
| #define GrFragmentProcessor_DEFINED |
| #include "GrProcessor.h" |
| +#include "GrStagedProcessor.h" |
| class GrCoordTransform; |
| class GrGLSLCaps; |
| @@ -24,7 +25,9 @@ class GrFragmentProcessor : public GrProcessor { |
| public: |
| GrFragmentProcessor() |
| : INHERITED() |
| - , fUsesLocalCoords(false) {} |
| + , fUsesLocalCoords(false) { |
| + SkDEBUGCODE(fIsChild = false;) |
| + } |
| /** Returns a new instance of the appropriate *GL* implementation class |
| for the given GrFragmentProcessor; caller is responsible for deleting |
| @@ -38,51 +41,48 @@ public: |
| void getGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) const { |
| this->onGetGLProcessorKey(caps, b); |
| for (int i = 0; i < fChildProcessors.count(); ++i) { |
| - fChildProcessors[i]->getGLProcessorKey(caps, b); |
| + fChildProcessors[i].processor()->getGLProcessorKey(caps, b); |
| } |
| } |
| - int numTransforms() const { return fCoordTransforms.count(); } |
| + int numTextures() const override { |
| + SkASSERT(!fIsChild); |
| + return fTextureAccesses.count(); |
| + } |
| - int numTransformsIncludeChildProcs() const { |
| - int numTransforms = fCoordTransforms.count(); |
| - for (int i = 0; i < fChildProcessors.count(); ++i) { |
| - numTransforms += fChildProcessors[i]->numTransformsIncludeChildProcs(); |
| - } |
| - return numTransforms; |
| + const GrTextureAccess& textureAccess(int index) const override { |
| + SkASSERT(!fIsChild); |
| + return *fTextureAccesses[index]; |
| + } |
| + |
| + int numTransforms() const { |
| + SkASSERT(!fIsChild); |
| + return fCoordTransforms.count(); |
| } |
| /** Returns the coordinate transformation at index. index must be valid according to |
| numTransforms(). */ |
| - const GrCoordTransform& coordTransform(int index) const { return *fCoordTransforms[index]; } |
| + const GrCoordTransform& coordTransform(int index) const { |
| + SkASSERT(!fIsChild); |
| + return *fCoordTransforms[index]; |
| + } |
| const SkTArray<const GrCoordTransform*, true>& coordTransforms() const { |
| + SkASSERT(!fIsChild); |
| return fCoordTransforms; |
| } |
| - /** Gather the coord transforms into an array. We use preorder traversal */ |
| void gatherCoordTransforms(SkTArray<const GrCoordTransform*, true>* outTransforms) const { |
| - SkASSERT(outTransforms); |
| - outTransforms->push_back_n(fCoordTransforms.count(), fCoordTransforms.begin()); |
| - for (int i = 0; i < fChildProcessors.count(); ++i) { |
| - fChildProcessors[i]->gatherCoordTransforms(outTransforms); |
| + SkASSERT(!fIsChild); |
| + if (!fCoordTransforms.empty()) { |
| + outTransforms->push_back_n(fCoordTransforms.count(), fCoordTransforms.begin()); |
| } |
| } |
| int numChildProcessors() const { return fChildProcessors.count(); } |
| - GrFragmentProcessor* childProcessor(int index) const { return fChildProcessors[index]; } |
| - |
| - const SkTArray<GrFragmentProcessor*, false>& childProcessors() const { |
| - return fChildProcessors; |
| - } |
| - |
| - int numTexturesIncludeChildProcs() const { |
| - int numTextures = this->numTextures(); |
| - for (int i = 0; i < fChildProcessors.count(); ++i) { |
| - numTextures += fChildProcessors[i]->numTexturesIncludeChildProcs(); |
| - } |
| - return numTextures; |
| + const GrFragmentProcessor& childProcessor(int index) const { |
| + return *fChildProcessors[index].processor(); |
| } |
| /** Do any of the coordtransforms for this processor require local coords? */ |
| @@ -140,13 +140,14 @@ protected: |
| void addCoordTransform(const GrCoordTransform*); |
| /** |
| - * FragmentProcessor subclasses call this to register any child FragmentProcessors they have. |
| + * FragmentProcessor subclasses call this from their constructor to register any child |
| + * FragmentProcessors they have. |
| * This is for processors whose shader code will be composed of nested processors whose output |
| * colors will be combined somehow to produce its output color. Registering these child |
| - * processors will allow the ProgramBuilder to automatically add their transformed coords and |
| - * texture accesses and mangle their uniform and output color names and |
| + * processors will allow the ProgramBuilder to automatically handle their transformed coords and |
| + * texture accesses and mangle their uniform and output color names. |
| */ |
| - void registerChildProcessor(GrFragmentProcessor* child); |
| + int registerChildProcessor(GrFragmentProcessor* child); |
| /** |
| * Subclass implements this to support getConstantColorComponents(...). |
| @@ -168,9 +169,18 @@ private: |
| bool hasSameTransforms(const GrFragmentProcessor&) const; |
| - SkSTArray<4, const GrCoordTransform*, true> fCoordTransforms; |
| bool fUsesLocalCoords; |
| - SkTArray<GrFragmentProcessor*, false> fChildProcessors; |
| + |
| + /** |
| + * This stores the transforms of this proc, followed by all the transforms of this proc's |
| + * children. In other words, each proc stores all the transforms of its subtree. |
| + * The same goes for fTextureAccesses with textures. |
| + */ |
| + SkSTArray<4, const GrCoordTransform*, true> fCoordTransforms; |
| + |
| + SkTArray<GrFragmentStage, false> fChildProcessors; |
| + |
| + SkDEBUGCODE(bool fIsChild;) |
|
joshualitt
2015/08/12 14:49:52
I think this has the same problem as the fIsParent
wangyix
2015/08/12 15:09:24
Ok. This variable is no longer necessary if the ch
|
| typedef GrProcessor INHERITED; |
| }; |