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 GrGLFragmentProcessor; | 15 class GrGLFragmentProcessor; |
16 class GrProcessorKeyBuilder; | 16 class GrProcessorKeyBuilder; |
17 | 17 |
18 /** Provides custom fragment shader code. Fragment processors receive an input c olor (vec4f) and | 18 /** 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 | 19 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 | 20 GrCoordTransforms to receive a transformation of the local coordinates that map from local space |
21 to the fragment being processed. | 21 to the fragment being processed. |
22 */ | 22 */ |
23 class GrFragmentProcessor : public GrProcessor { | 23 class GrFragmentProcessor : public GrProcessor { |
24 public: | 24 public: |
25 GrFragmentProcessor() | 25 GrFragmentProcessor() |
26 : INHERITED() | 26 : INHERITED() |
27 , fUsesLocalCoords(false) {} | 27 , fUsesLocalCoords(false) {} |
28 | 28 |
29 /** Implemented using GLFragmentProcessor::GenKey as described in this class 's comment. */ | 29 /** Implemented using GLFragmentProcessor::GenKey as described in this class 's comment. */ |
30 virtual void getGLProcessorKey(const GrGLSLCaps& caps, | 30 virtual void getGLProcessorKey(const GrGLSLCaps& caps, |
joshualitt
2015/08/03 14:06:02
Lets rename all of the *IncludeChildProc functions
wangyix
2015/08/03 16:12:47
Done.
| |
31 GrProcessorKeyBuilder* b) const = 0; | 31 GrProcessorKeyBuilder* b) const = 0; |
32 | 32 |
33 /** Returns a new instance of the appropriate *GL* implementation class | 33 /** Returns a new instance of the appropriate *GL* implementation class |
34 for the given GrFragmentProcessor; caller is responsible for deleting | 34 for the given GrFragmentProcessor; caller is responsible for deleting |
35 the object. */ | 35 the object. */ |
36 virtual GrGLFragmentProcessor* createGLInstance() const = 0; | 36 virtual GrGLFragmentProcessor* createGLInstance() const = 0; |
37 | 37 |
38 /** Human-meaningful string to identify this GrFragmentProcessor; may be emb edded | 38 /** Human-meaningful string to identify this GrFragmentProcessor; may be emb edded |
39 in generated shader code. */ | 39 in generated shader code. */ |
40 virtual const char* name() const = 0; | 40 virtual const char* name() const = 0; |
41 | 41 |
42 void getGLProcessorKeyIncludeChildProcs(const GrGLSLCaps& caps, | |
43 GrProcessorKeyBuilder* b) const { | |
44 this->getGLProcessorKey(caps, b); | |
45 for (int i = 0; i < fChildProcessors.count(); ++i) | |
joshualitt
2015/08/03 14:06:02
We put braces around single line for loops.
wangyix
2015/08/03 16:12:47
Done.
| |
46 fChildProcessors[i]->getGLProcessorKeyIncludeChildProcs(caps, b); | |
47 } | |
48 | |
42 int numTransforms() const { return fCoordTransforms.count(); } | 49 int numTransforms() const { return fCoordTransforms.count(); } |
43 | 50 |
51 int numTransformsIncludeChildProcs() const { | |
52 int numTransforms = fCoordTransforms.count(); | |
53 for (int i = 0; i < fChildProcessors.count(); ++i) | |
joshualitt
2015/08/03 14:06:02
same
wangyix
2015/08/03 16:12:47
Done.
| |
54 numTransforms += fChildProcessors[i]->numTransformsIncludeChildProcs (); | |
55 return numTransforms; | |
56 } | |
57 | |
44 /** Returns the coordinate transformation at index. index must be valid acco rding to | 58 /** Returns the coordinate transformation at index. index must be valid acco rding to |
45 numTransforms(). */ | 59 numTransforms(). */ |
46 const GrCoordTransform& coordTransform(int index) const { return *fCoordTran sforms[index]; } | 60 const GrCoordTransform& coordTransform(int index) const { return *fCoordTran sforms[index]; } |
47 | 61 |
48 const SkTArray<const GrCoordTransform*, true>& coordTransforms() const { | 62 const SkTArray<const GrCoordTransform*, true>& coordTransforms() const { |
49 return fCoordTransforms; | 63 return fCoordTransforms; |
50 } | 64 } |
51 | 65 |
66 int numChildProcessors() const { return fChildProcessors.count(); } | |
67 | |
68 GrFragmentProcessor* childProcessor(int index) const { return fChildProcesso rs[index]; } | |
69 | |
70 const SkTArray<GrFragmentProcessor*, false>& childProcessors() const { | |
71 return fChildProcessors; | |
72 } | |
73 | |
74 int numTexturesIncludeChildProcs() const { | |
75 int numTextures = this->numTextures(); | |
76 for (int i = 0; i < fChildProcessors.count(); ++i) | |
joshualitt
2015/08/03 14:06:02
same
wangyix
2015/08/03 16:12:47
Done.
| |
77 numTextures += fChildProcessors[i]->numTexturesIncludeChildProcs(); | |
78 return numTextures; | |
79 } | |
80 | |
52 /** Do any of the coordtransforms for this processor require local coords? * / | 81 /** Do any of the coordtransforms for this processor require local coords? * / |
53 bool usesLocalCoords() const { return fUsesLocalCoords; } | 82 bool usesLocalCoords() const { return fUsesLocalCoords; } |
54 | 83 |
55 /** Returns true if this and other processor conservatively draw identically . It can only return | 84 /** Returns true if this and other processor conservatively draw identically . It can only return |
56 true when the two processor are of the same subclass (i.e. they return t he same object from | 85 true when the two processor are of the same subclass (i.e. they return t he same object from |
57 from getFactory()). | 86 from getFactory()). |
58 | 87 |
59 A return value of true from isEqual() should not be used to test whether the processor would | 88 A return value of true from isEqual() should not be used to test whether the processor would |
60 generate the same shader code. To test for identical code generation use getGLProcessorKey*/ | 89 generate the same shader code. To test for identical code generation use getGLProcessorKey*/ |
61 bool isEqual(const GrFragmentProcessor& that) const { | 90 bool isEqual(const GrFragmentProcessor& that) const { |
(...skipping 29 matching lines...) Expand all Loading... | |
91 * processor subclass manages the lifetime of the transformations (this func tion only stores a | 120 * processor subclass manages the lifetime of the transformations (this func tion only stores a |
92 * pointer). The GrCoordTransform is typically a member field of the GrProce ssor subclass. | 121 * pointer). The GrCoordTransform is typically a member field of the GrProce ssor subclass. |
93 * | 122 * |
94 * A processor subclass that has multiple methods of construction should alw ays add its coord | 123 * A processor subclass that has multiple methods of construction should alw ays add its coord |
95 * transforms in a consistent order. The non-virtual implementation of isEqu al() automatically | 124 * transforms in a consistent order. The non-virtual implementation of isEqu al() automatically |
96 * compares transforms and will assume they line up across the two processor instances. | 125 * compares transforms and will assume they line up across the two processor instances. |
97 */ | 126 */ |
98 void addCoordTransform(const GrCoordTransform*); | 127 void addCoordTransform(const GrCoordTransform*); |
99 | 128 |
100 /** | 129 /** |
130 * FragmentProcessor subclasses call this to register any child FragmentProc essors they have. | |
131 * This is for processors whose shader code will be composed of nested proce ssors whose output | |
132 * colors will be combined somehow to produce its output color. Registering these child | |
133 * processors will allow the ProgramBuilder to automatically add their trans formed coords and | |
134 * texture accesses and mangle their uniform and output color names and | |
135 */ | |
136 void registerChildProcessor(GrFragmentProcessor* child); | |
137 | |
138 /** | |
101 * Subclass implements this to support getConstantColorComponents(...). | 139 * Subclass implements this to support getConstantColorComponents(...). |
102 */ | 140 */ |
103 virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const = 0; | 141 virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const = 0; |
104 | 142 |
105 private: | 143 private: |
106 /** | 144 /** |
107 * Subclass implements this to support isEqual(). It will only be called if it is known that | 145 * Subclass implements this to support isEqual(). It will only be called if it is known that |
108 * the two processors are of the same subclass (i.e. they return the same ob ject from | 146 * the two processors are of the same subclass (i.e. they return the same ob ject from |
109 * getFactory()). The processor subclass should not compare its coord transf orms as that will | 147 * getFactory()). The processor subclass should not compare its coord transf orms as that will |
110 * be performed automatically in the non-virtual isEqual(). | 148 * be performed automatically in the non-virtual isEqual(). |
111 */ | 149 */ |
112 virtual bool onIsEqual(const GrFragmentProcessor&) const = 0; | 150 virtual bool onIsEqual(const GrFragmentProcessor&) const = 0; |
113 | 151 |
114 bool hasSameTransforms(const GrFragmentProcessor&) const; | 152 bool hasSameTransforms(const GrFragmentProcessor&) const; |
115 | 153 |
116 SkSTArray<4, const GrCoordTransform*, true> fCoordTransforms; | 154 SkSTArray<4, const GrCoordTransform*, true> fCoordTransforms; |
117 bool fUsesLocalCoords; | 155 bool fUsesLocalCoords; |
118 | 156 SkTArray<GrFragmentProcessor*, false> fChildProcessors; |
157 » | |
joshualitt
2015/08/03 14:06:02
delete tab
wangyix
2015/08/03 16:12:47
Done.
| |
119 typedef GrProcessor INHERITED; | 158 typedef GrProcessor INHERITED; |
120 }; | 159 }; |
121 | 160 |
122 #endif | 161 #endif |
OLD | NEW |