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) {} |
28 | 29 |
29 /** Returns a new instance of the appropriate *GL* implementation class | 30 /** Returns a new instance of the appropriate *GL* implementation class |
30 for the given GrFragmentProcessor; caller is responsible for deleting | 31 for the given GrFragmentProcessor; caller is responsible for deleting |
31 the object. */ | 32 the object. */ |
32 virtual GrGLFragmentProcessor* createGLInstance() const = 0; | 33 virtual GrGLFragmentProcessor* createGLInstance() const = 0; |
33 | 34 |
34 /** Human-meaningful string to identify this GrFragmentProcessor; may be emb
edded | 35 /** Human-meaningful string to identify this GrFragmentProcessor; may be emb
edded |
35 in generated shader code. */ | 36 in generated shader code. */ |
36 virtual const char* name() const = 0; | 37 virtual const char* name() const = 0; |
37 | 38 |
38 void getGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) con
st { | 39 void getGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) con
st { |
39 this->onGetGLProcessorKey(caps, b); | 40 this->onGetGLProcessorKey(caps, b); |
40 for (int i = 0; i < fChildProcessors.count(); ++i) { | 41 for (int i = 0; i < fChildProcessors.count(); ++i) { |
41 fChildProcessors[i]->getGLProcessorKey(caps, b); | 42 fChildProcessors[i].processor()->getGLProcessorKey(caps, b); |
42 } | 43 } |
43 } | 44 } |
44 | 45 |
45 int numTransforms() const { return fCoordTransforms.count(); } | 46 int numTransforms() const { return fCoordTransforms.count(); } |
46 | 47 |
47 int numTransformsIncludeChildProcs() const { | |
48 int numTransforms = fCoordTransforms.count(); | |
49 for (int i = 0; i < fChildProcessors.count(); ++i) { | |
50 numTransforms += fChildProcessors[i]->numTransformsIncludeChildProcs
(); | |
51 } | |
52 return numTransforms; | |
53 } | |
54 | |
55 /** Returns the coordinate transformation at index. index must be valid acco
rding to | 48 /** Returns the coordinate transformation at index. index must be valid acco
rding to |
56 numTransforms(). */ | 49 numTransforms(). */ |
57 const GrCoordTransform& coordTransform(int index) const { return *fCoordTran
sforms[index]; } | 50 const GrCoordTransform& coordTransform(int index) const { return *fCoordTran
sforms[index]; } |
58 | 51 |
59 const SkTArray<const GrCoordTransform*, true>& coordTransforms() const { | 52 const SkTArray<const GrCoordTransform*, true>& coordTransforms() const { |
60 return fCoordTransforms; | 53 return fCoordTransforms; |
61 } | 54 } |
62 | 55 |
63 /** Gather the coord transforms into an array. We use preorder traversal */ | |
64 void gatherCoordTransforms(SkTArray<const GrCoordTransform*, true>* outTrans
forms) const { | 56 void gatherCoordTransforms(SkTArray<const GrCoordTransform*, true>* outTrans
forms) const { |
65 SkASSERT(outTransforms); | 57 if (!fCoordTransforms.empty()) { |
66 outTransforms->push_back_n(fCoordTransforms.count(), fCoordTransforms.be
gin()); | 58 outTransforms->push_back_n(fCoordTransforms.count(), fCoordTransform
s.begin()); |
67 for (int i = 0; i < fChildProcessors.count(); ++i) { | |
68 fChildProcessors[i]->gatherCoordTransforms(outTransforms); | |
69 } | 59 } |
70 } | 60 } |
71 | 61 |
72 int numChildProcessors() const { return fChildProcessors.count(); } | 62 int numChildProcessors() const { return fChildProcessors.count(); } |
73 | 63 |
74 GrFragmentProcessor* childProcessor(int index) const { return fChildProcesso
rs[index]; } | 64 const GrFragmentProcessor& childProcessor(int index) const { |
75 | 65 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 } | 66 } |
87 | 67 |
88 /** Do any of the coordtransforms for this processor require local coords? *
/ | 68 /** Do any of the coordtransforms for this processor require local coords? *
/ |
89 bool usesLocalCoords() const { return fUsesLocalCoords; } | 69 bool usesLocalCoords() const { return fUsesLocalCoords; } |
90 | 70 |
91 /** Returns true if this and other processor conservatively draw identically
. It can only return | 71 /** 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 | 72 true when the two processor are of the same subclass (i.e. they return t
he same object from |
93 from getFactory()). | 73 from getFactory()). |
94 | 74 |
95 A return value of true from isEqual() should not be used to test whether
the processor would | 75 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 | 113 * 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. | 114 * pointer). The GrCoordTransform is typically a member field of the GrProce
ssor subclass. |
135 * | 115 * |
136 * A processor subclass that has multiple methods of construction should alw
ays add its coord | 116 * 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 | 117 * 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. | 118 * compares transforms and will assume they line up across the two processor
instances. |
139 */ | 119 */ |
140 void addCoordTransform(const GrCoordTransform*); | 120 void addCoordTransform(const GrCoordTransform*); |
141 | 121 |
142 /** | 122 /** |
143 * FragmentProcessor subclasses call this to register any child FragmentProc
essors they have. | 123 * FragmentProcessor subclasses call this from their constructor to register
any child |
| 124 * FragmentProcessors they have. |
144 * This is for processors whose shader code will be composed of nested proce
ssors whose output | 125 * 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 | 126 * 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 | 127 * 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 | 128 * texture accesses and mangle their uniform and output color names. |
148 */ | 129 */ |
149 void registerChildProcessor(GrFragmentProcessor* child); | 130 int registerChildProcessor(const GrFragmentProcessor* child); |
150 | 131 |
151 /** | 132 /** |
152 * Subclass implements this to support getConstantColorComponents(...). | 133 * Subclass implements this to support getConstantColorComponents(...). |
153 */ | 134 */ |
154 virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const = 0; | 135 virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const = 0; |
155 | 136 |
156 private: | 137 private: |
157 /** Implemented using GLFragmentProcessor::GenKey as described in this class
's comment. */ | 138 /** Implemented using GLFragmentProcessor::GenKey as described in this class
's comment. */ |
158 virtual void onGetGLProcessorKey(const GrGLSLCaps& caps, | 139 virtual void onGetGLProcessorKey(const GrGLSLCaps& caps, |
159 GrProcessorKeyBuilder* b) const = 0; | 140 GrProcessorKeyBuilder* b) const = 0; |
160 | 141 |
161 /** | 142 /** |
162 * Subclass implements this to support isEqual(). It will only be called if
it is known that | 143 * 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 | 144 * 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 | 145 * getFactory()). The processor subclass should not compare its coord transf
orms as that will |
165 * be performed automatically in the non-virtual isEqual(). | 146 * be performed automatically in the non-virtual isEqual(). |
166 */ | 147 */ |
167 virtual bool onIsEqual(const GrFragmentProcessor&) const = 0; | 148 virtual bool onIsEqual(const GrFragmentProcessor&) const = 0; |
168 | 149 |
169 bool hasSameTransforms(const GrFragmentProcessor&) const; | 150 bool hasSameTransforms(const GrFragmentProcessor&) const; |
170 | 151 |
| 152 bool fUsesLocalCoords; |
| 153 |
| 154 /** |
| 155 * This stores the transforms of this proc, followed by all the transforms o
f this proc's |
| 156 * children. In other words, each proc stores all the transforms of its subt
ree. |
| 157 * The same goes for fTextureAccesses with textures. |
| 158 */ |
171 SkSTArray<4, const GrCoordTransform*, true> fCoordTransforms; | 159 SkSTArray<4, const GrCoordTransform*, true> fCoordTransforms; |
172 bool fUsesLocalCoords; | 160 |
173 SkTArray<GrFragmentProcessor*, false> fChildProcessors; | 161 SkTArray<GrFragmentStage, false> fChildProcessors; |
174 | 162 |
175 typedef GrProcessor INHERITED; | 163 typedef GrProcessor INHERITED; |
176 }; | 164 }; |
177 | 165 |
178 #endif | 166 #endif |
OLD | NEW |