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