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 #include "GrStagedProcessor.h" | |
12 | 13 |
13 class GrCoordTransform; | 14 class GrCoordTransform; |
14 class GrGLSLCaps; | 15 class GrGLSLCaps; |
15 class GrGLFragmentProcessor; | 16 class GrGLFragmentProcessor; |
16 class GrProcessorKeyBuilder; | 17 class GrProcessorKeyBuilder; |
17 | 18 |
18 /** 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 |
19 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 |
20 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 |
21 to the fragment being processed. | 22 to the fragment being processed. |
22 */ | 23 */ |
23 class GrFragmentProcessor : public GrProcessor { | 24 class GrFragmentProcessor : public GrProcessor { |
24 public: | 25 public: |
25 GrFragmentProcessor() | 26 GrFragmentProcessor() |
26 : INHERITED() | 27 : INHERITED() |
27 , fUsesLocalCoords(false) {} | 28 , fUsesLocalCoords(false) { |
29 SkDEBUGCODE(fIsChild = false;) | |
30 } | |
28 | 31 |
29 /** Returns a new instance of the appropriate *GL* implementation class | 32 /** Returns a new instance of the appropriate *GL* implementation class |
30 for the given GrFragmentProcessor; caller is responsible for deleting | 33 for the given GrFragmentProcessor; caller is responsible for deleting |
31 the object. */ | 34 the object. */ |
32 virtual GrGLFragmentProcessor* createGLInstance() const = 0; | 35 virtual GrGLFragmentProcessor* createGLInstance() const = 0; |
33 | 36 |
34 /** Human-meaningful string to identify this GrFragmentProcessor; may be emb edded | 37 /** Human-meaningful string to identify this GrFragmentProcessor; may be emb edded |
35 in generated shader code. */ | 38 in generated shader code. */ |
36 virtual const char* name() const = 0; | 39 virtual const char* name() const = 0; |
37 | 40 |
38 void getGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) con st { | 41 void getGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) con st { |
39 this->onGetGLProcessorKey(caps, b); | 42 this->onGetGLProcessorKey(caps, b); |
40 for (int i = 0; i < fChildProcessors.count(); ++i) { | 43 for (int i = 0; i < fChildProcessors.count(); ++i) { |
41 fChildProcessors[i]->getGLProcessorKey(caps, b); | 44 fChildProcessors[i].processor()->getGLProcessorKey(caps, b); |
42 } | 45 } |
43 } | 46 } |
44 | 47 |
45 int numTransforms() const { return fCoordTransforms.count(); } | 48 int numTextures() const override { |
49 SkASSERT(!fIsChild); | |
50 return fTextureAccesses.count(); | |
51 } | |
46 | 52 |
47 int numTransformsIncludeChildProcs() const { | 53 const GrTextureAccess& textureAccess(int index) const override { |
48 int numTransforms = fCoordTransforms.count(); | 54 SkASSERT(!fIsChild); |
49 for (int i = 0; i < fChildProcessors.count(); ++i) { | 55 return *fTextureAccesses[index]; |
50 numTransforms += fChildProcessors[i]->numTransformsIncludeChildProcs (); | 56 } |
51 } | 57 |
52 return numTransforms; | 58 int numTransforms() const { |
59 SkASSERT(!fIsChild); | |
60 return fCoordTransforms.count(); | |
53 } | 61 } |
54 | 62 |
55 /** Returns the coordinate transformation at index. index must be valid acco rding to | 63 /** Returns the coordinate transformation at index. index must be valid acco rding to |
56 numTransforms(). */ | 64 numTransforms(). */ |
57 const GrCoordTransform& coordTransform(int index) const { return *fCoordTran sforms[index]; } | 65 const GrCoordTransform& coordTransform(int index) const { |
66 SkASSERT(!fIsChild); | |
67 return *fCoordTransforms[index]; | |
68 } | |
58 | 69 |
59 const SkTArray<const GrCoordTransform*, true>& coordTransforms() const { | 70 const SkTArray<const GrCoordTransform*, true>& coordTransforms() const { |
71 SkASSERT(!fIsChild); | |
60 return fCoordTransforms; | 72 return fCoordTransforms; |
61 } | 73 } |
62 | 74 |
63 /** Gather the coord transforms into an array. We use preorder traversal */ | |
64 void gatherCoordTransforms(SkTArray<const GrCoordTransform*, true>* outTrans forms) const { | 75 void gatherCoordTransforms(SkTArray<const GrCoordTransform*, true>* outTrans forms) const { |
65 SkASSERT(outTransforms); | 76 SkASSERT(!fIsChild); |
66 outTransforms->push_back_n(fCoordTransforms.count(), fCoordTransforms.be gin()); | 77 if (!fCoordTransforms.empty()) { |
67 for (int i = 0; i < fChildProcessors.count(); ++i) { | 78 outTransforms->push_back_n(fCoordTransforms.count(), fCoordTransform s.begin()); |
68 fChildProcessors[i]->gatherCoordTransforms(outTransforms); | |
69 } | 79 } |
70 } | 80 } |
71 | 81 |
72 int numChildProcessors() const { return fChildProcessors.count(); } | 82 int numChildProcessors() const { return fChildProcessors.count(); } |
73 | 83 |
74 GrFragmentProcessor* childProcessor(int index) const { return fChildProcesso rs[index]; } | 84 const GrFragmentProcessor& childProcessor(int index) const { |
75 | 85 return *fChildProcessors[index].processor(); |
76 const SkTArray<GrFragmentProcessor*, false>& childProcessors() const { | |
77 return fChildProcessors; | |
78 } | |
79 | |
80 int numTexturesIncludeChildProcs() const { | |
81 int numTextures = this->numTextures(); | |
82 for (int i = 0; i < fChildProcessors.count(); ++i) { | |
83 numTextures += fChildProcessors[i]->numTexturesIncludeChildProcs(); | |
84 } | |
85 return numTextures; | |
86 } | 86 } |
87 | 87 |
88 /** Do any of the coordtransforms for this processor require local coords? * / | 88 /** Do any of the coordtransforms for this processor require local coords? * / |
89 bool usesLocalCoords() const { return fUsesLocalCoords; } | 89 bool usesLocalCoords() const { return fUsesLocalCoords; } |
90 | 90 |
91 /** Returns true if this and other processor conservatively draw identically . It can only return | 91 /** Returns true if this and other processor conservatively draw identically . It can only return |
92 true when the two processor are of the same subclass (i.e. they return t he same object from | 92 true when the two processor are of the same subclass (i.e. they return t he same object from |
93 from getFactory()). | 93 from getFactory()). |
94 | 94 |
95 A return value of true from isEqual() should not be used to test whether the processor would | 95 A return value of true from isEqual() should not be used to test whether the processor would |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
133 * processor subclass manages the lifetime of the transformations (this func tion only stores a | 133 * processor subclass manages the lifetime of the transformations (this func tion only stores a |
134 * pointer). The GrCoordTransform is typically a member field of the GrProce ssor subclass. | 134 * pointer). The GrCoordTransform is typically a member field of the GrProce ssor subclass. |
135 * | 135 * |
136 * A processor subclass that has multiple methods of construction should alw ays add its coord | 136 * A processor subclass that has multiple methods of construction should alw ays add its coord |
137 * transforms in a consistent order. The non-virtual implementation of isEqu al() automatically | 137 * transforms in a consistent order. The non-virtual implementation of isEqu al() automatically |
138 * compares transforms and will assume they line up across the two processor instances. | 138 * compares transforms and will assume they line up across the two processor instances. |
139 */ | 139 */ |
140 void addCoordTransform(const GrCoordTransform*); | 140 void addCoordTransform(const GrCoordTransform*); |
141 | 141 |
142 /** | 142 /** |
143 * FragmentProcessor subclasses call this to register any child FragmentProc essors they have. | 143 * FragmentProcessor subclasses call this from their constructor to register any child |
144 * FragmentProcessors they have. | |
144 * This is for processors whose shader code will be composed of nested proce ssors whose output | 145 * This is for processors whose shader code will be composed of nested proce ssors whose output |
145 * colors will be combined somehow to produce its output color. Registering these child | 146 * colors will be combined somehow to produce its output color. Registering these child |
146 * processors will allow the ProgramBuilder to automatically add their trans formed coords and | 147 * processors will allow the ProgramBuilder to automatically handle their tr ansformed coords and |
147 * texture accesses and mangle their uniform and output color names and | 148 * texture accesses and mangle their uniform and output color names. |
148 */ | 149 */ |
149 void registerChildProcessor(GrFragmentProcessor* child); | 150 int registerChildProcessor(GrFragmentProcessor* child); |
150 | 151 |
151 /** | 152 /** |
152 * Subclass implements this to support getConstantColorComponents(...). | 153 * Subclass implements this to support getConstantColorComponents(...). |
153 */ | 154 */ |
154 virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const = 0; | 155 virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const = 0; |
155 | 156 |
156 private: | 157 private: |
157 /** Implemented using GLFragmentProcessor::GenKey as described in this class 's comment. */ | 158 /** Implemented using GLFragmentProcessor::GenKey as described in this class 's comment. */ |
158 virtual void onGetGLProcessorKey(const GrGLSLCaps& caps, | 159 virtual void onGetGLProcessorKey(const GrGLSLCaps& caps, |
159 GrProcessorKeyBuilder* b) const = 0; | 160 GrProcessorKeyBuilder* b) const = 0; |
160 | 161 |
161 /** | 162 /** |
162 * Subclass implements this to support isEqual(). It will only be called if it is known that | 163 * Subclass implements this to support isEqual(). It will only be called if it is known that |
163 * the two processors are of the same subclass (i.e. they return the same ob ject from | 164 * the two processors are of the same subclass (i.e. they return the same ob ject from |
164 * getFactory()). The processor subclass should not compare its coord transf orms as that will | 165 * getFactory()). The processor subclass should not compare its coord transf orms as that will |
165 * be performed automatically in the non-virtual isEqual(). | 166 * be performed automatically in the non-virtual isEqual(). |
166 */ | 167 */ |
167 virtual bool onIsEqual(const GrFragmentProcessor&) const = 0; | 168 virtual bool onIsEqual(const GrFragmentProcessor&) const = 0; |
168 | 169 |
169 bool hasSameTransforms(const GrFragmentProcessor&) const; | 170 bool hasSameTransforms(const GrFragmentProcessor&) const; |
170 | 171 |
172 bool fUsesLocalCoords; | |
173 | |
174 /** | |
175 * This stores the transforms of this proc, followed by all the transforms o f this proc's | |
176 * children. In other words, each proc stores all the transforms of its subt ree. | |
177 * The same goes for fTextureAccesses with textures. | |
178 */ | |
171 SkSTArray<4, const GrCoordTransform*, true> fCoordTransforms; | 179 SkSTArray<4, const GrCoordTransform*, true> fCoordTransforms; |
172 bool fUsesLocalCoords; | 180 |
173 SkTArray<GrFragmentProcessor*, false> fChildProcessors; | 181 SkTArray<GrFragmentStage, false> fChildProcessors; |
182 | |
183 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
| |
174 | 184 |
175 typedef GrProcessor INHERITED; | 185 typedef GrProcessor INHERITED; |
176 }; | 186 }; |
177 | 187 |
178 #endif | 188 #endif |
OLD | NEW |