OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 GrGeometryProcessor_DEFINED | 8 #ifndef GrGeometryProcessor_DEFINED |
9 #define GrGeometryProcessor_DEFINED | 9 #define GrGeometryProcessor_DEFINED |
10 | 10 |
(...skipping 21 matching lines...) Expand all Loading... | |
32 static const size_t kMaxSize = 32; | 32 static const size_t kMaxSize = 32; |
33 | 33 |
34 private: | 34 private: |
35 uint8_t fData[kMaxSize]; | 35 uint8_t fData[kMaxSize]; |
36 }; | 36 }; |
37 | 37 |
38 class GrGLCaps; | 38 class GrGLCaps; |
39 class GrGLGeometryProcessor; | 39 class GrGLGeometryProcessor; |
40 class GrOptDrawState; | 40 class GrOptDrawState; |
41 | 41 |
42 struct GrInitInvariantOutput; | |
43 | |
44 /* | |
45 * GrGeometryProcessors and GrPathProcessors may effect invariantColor | |
46 */ | |
47 class GrPrimitiveProcessor : public GrProcessor { | |
48 public: | |
49 // TODO GPs and PPs have to provide an initial coverage because the coverage invariant code is | |
50 // broken right now | |
51 virtual uint8_t coverage() const = 0; | |
52 virtual void computeOutputColor(GrInitInvariantOutput* out) const = 0; | |
bsalomon
2014/12/10 15:27:00
I'm wondering if this should be "getInvariantColor
| |
53 virtual void computeOutputCoverage(GrInitInvariantOutput* out) const = 0; | |
54 | |
55 private: | |
56 typedef GrProcessor INHERITED; | |
57 }; | |
58 | |
42 /** | 59 /** |
43 * A GrGeometryProcessor is used to perform computation in the vertex shader and | 60 * A GrGeometryProcessor is used to perform computation in the vertex shader and |
44 * add support for custom vertex attributes. A GrGemeotryProcessor is typically | 61 * add support for custom vertex attributes. A GrGemeotryProcessor is typically |
45 * tied to the code that does a specific type of high-level primitive rendering | 62 * tied to the code that does a specific type of high-level primitive rendering |
46 * (e.g. anti-aliased circle rendering). The GrGeometryProcessor used for a draw is | 63 * (e.g. anti-aliased circle rendering). The GrGeometryProcessor used for a draw is |
47 * specified using GrDrawState. There can only be one geometry processor active for | 64 * specified using GrDrawState. There can only be one geometry processor active for |
48 * a draw. The custom vertex attributes required by the geometry processor must be | 65 * a draw. The custom vertex attributes required by the geometry processor must be |
49 * added to the vertex attribute array specified on the GrDrawState. | 66 * added to the vertex attribute array specified on the GrDrawState. |
50 * GrGeometryProcessor subclasses should be immutable after construction. | 67 * GrGeometryProcessor subclasses should be immutable after construction. |
51 */ | 68 */ |
52 class GrGeometryProcessor : public GrProcessor { | 69 class GrGeometryProcessor : public GrPrimitiveProcessor { |
53 public: | 70 public: |
54 GrGeometryProcessor(GrColor color, uint8_t coverage = 0xff) | 71 GrGeometryProcessor(GrColor color, uint8_t coverage = 0xff) |
55 : fVertexStride(0) | 72 : fVertexStride(0) |
56 , fColor(color) | 73 , fColor(color) |
57 , fCoverage(coverage) | 74 , fCoverage(coverage) |
58 , fWillUseGeoShader(false) | 75 , fWillUseGeoShader(false) |
59 , fHasVertexColor(false) | 76 , fHasVertexColor(false) |
60 , fHasVertexCoverage(false) | 77 , fHasVertexCoverage(false) |
61 , fHasLocalCoords(false) {} | 78 , fHasLocalCoords(false) {} |
62 | 79 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
104 true when the two prcoessors are of the same subclass (i.e. they return the same object from | 121 true when the two prcoessors are of the same subclass (i.e. they return the same object from |
105 from getFactory()). | 122 from getFactory()). |
106 A return value of true from isEqual() should not be used to test whether the processors | 123 A return value of true from isEqual() should not be used to test whether the processors |
107 would generate the same shader code. To test for identical code generati on use the | 124 would generate the same shader code. To test for identical code generati on use the |
108 processors' keys computed by the GrBackendEffectFactory. */ | 125 processors' keys computed by the GrBackendEffectFactory. */ |
109 bool isEqual(const GrGeometryProcessor& that) const { | 126 bool isEqual(const GrGeometryProcessor& that) const { |
110 if (this->classID() != that.classID() || !this->hasSameTextureAccesses(t hat)) { | 127 if (this->classID() != that.classID() || !this->hasSameTextureAccesses(t hat)) { |
111 return false; | 128 return false; |
112 } | 129 } |
113 | 130 |
114 if (!fHasVertexColor && this->getColor() != that.getColor()) { | 131 if (!fHasVertexColor && this->color() != that.color()) { |
115 return false; | 132 return false; |
116 } | 133 } |
117 | 134 |
118 if (!fHasVertexCoverage && this->getCoverage() != that.getCoverage()) { | 135 // TODO this is fragile, most gps set their coverage to 0xff so this is okay |
bsalomon
2014/12/10 15:27:00
what's the plan here?
| |
136 if (!fHasVertexCoverage && this->coverage() != that.coverage()) { | |
119 return false; | 137 return false; |
120 } | 138 } |
121 return this->onIsEqual(that); | 139 return this->onIsEqual(that); |
122 } | 140 } |
123 | 141 |
124 struct InitBT { | 142 struct InitBT { |
125 bool fOutputColor; | 143 bool fOutputColor; |
126 bool fOutputCoverage; | 144 bool fOutputCoverage; |
127 GrColor fColor; | 145 GrColor fColor; |
128 GrColor fCoverage; | 146 GrColor fCoverage; |
129 }; | 147 }; |
130 | 148 |
131 virtual void initBatchTracker(GrBatchTracker*, const InitBT&) const {} | 149 virtual void initBatchTracker(GrBatchTracker*, const InitBT&) const {} |
132 | 150 |
133 GrColor getColor() const { return fColor; } | 151 GrColor color() const { return fColor; } |
134 uint8_t getCoverage() const { return fCoverage; } | 152 uint8_t coverage() const { return fCoverage; } |
135 | 153 |
136 // TODO this is a total hack until the gp can own whether or not it uses uni form | 154 // TODO this is a total hack until the gp can own whether or not it uses uni form |
137 // color / coverage | 155 // color / coverage |
138 bool hasVertexColor() const { return fHasVertexColor; } | 156 bool hasVertexColor() const { return fHasVertexColor; } |
139 bool hasVertexCoverage() const { return fHasVertexCoverage; } | 157 bool hasVertexCoverage() const { return fHasVertexCoverage; } |
140 bool hasLocalCoords() const { return fHasLocalCoords; } | 158 bool hasLocalCoords() const { return fHasLocalCoords; } |
141 | 159 |
142 void computeInvariantColor(GrInvariantOutput* inout) const; | 160 virtual void computeOutputColor(GrInitInvariantOutput* out) const SK_OVERRID E; |
161 virtual void computeOutputCoverage(GrInitInvariantOutput* out) const SK_OVER RIDE; | |
143 | 162 |
144 protected: | 163 protected: |
145 /** | 164 /** |
146 * Subclasses call this from their constructor to register vertex attributes . Attributes | 165 * Subclasses call this from their constructor to register vertex attributes . Attributes |
147 * will be padded to the nearest 4 bytes for performance reasons. | 166 * will be padded to the nearest 4 bytes for performance reasons. |
148 * TODO After deferred geometry, we should do all of this inline in Generate Geometry alongside | 167 * TODO After deferred geometry, we should do all of this inline in Generate Geometry alongside |
149 * the struct used to actually populate the attributes | 168 * the struct used to actually populate the attributes |
150 */ | 169 */ |
151 const GrAttribute& addVertexAttrib(const GrAttribute& attribute) { | 170 const GrAttribute& addVertexAttrib(const GrAttribute& attribute) { |
152 fVertexStride += attribute.fOffset; | 171 fVertexStride += attribute.fOffset; |
153 return fAttribs.push_back(attribute); | 172 return fAttribs.push_back(attribute); |
154 } | 173 } |
155 | 174 |
156 void setWillUseGeoShader() { fWillUseGeoShader = true; } | 175 void setWillUseGeoShader() { fWillUseGeoShader = true; } |
157 | 176 |
158 // TODO hack see above | 177 // TODO hack see above |
159 void setHasVertexColor() { fHasVertexColor = true; } | 178 void setHasVertexColor() { fHasVertexColor = true; } |
160 void setHasVertexCoverage() { fHasVertexCoverage = true; } | 179 void setHasVertexCoverage() { fHasVertexCoverage = true; } |
161 void setHasLocalCoords() { fHasLocalCoords = true; } | 180 void setHasLocalCoords() { fHasLocalCoords = true; } |
162 | 181 |
182 virtual void onComputeOutputColor(GrInitInvariantOutput*) const {} | |
183 virtual void onComputeOutputCoverage(GrInitInvariantOutput*) const = 0; | |
184 | |
163 private: | 185 private: |
164 virtual bool onIsEqual(const GrGeometryProcessor&) const = 0; | 186 virtual bool onIsEqual(const GrGeometryProcessor&) const = 0; |
165 | 187 |
166 SkSTArray<kMaxVertexAttribs, GrAttribute, true> fAttribs; | 188 SkSTArray<kMaxVertexAttribs, GrAttribute, true> fAttribs; |
167 size_t fVertexStride; | 189 size_t fVertexStride; |
168 GrColor fColor; | 190 GrColor fColor; |
191 // TODO HACK | |
192 public: | |
169 uint8_t fCoverage; | 193 uint8_t fCoverage; |
170 bool fWillUseGeoShader; | 194 bool fWillUseGeoShader; |
171 bool fHasVertexColor; | 195 bool fHasVertexColor; |
172 bool fHasVertexCoverage; | 196 bool fHasVertexCoverage; |
173 bool fHasLocalCoords; | 197 bool fHasLocalCoords; |
174 | 198 |
175 typedef GrProcessor INHERITED; | 199 typedef GrProcessor INHERITED; |
176 }; | 200 }; |
201 | |
202 /* | |
203 * The path equivalent of the GP. Can only upload uniform color. | |
bsalomon
2014/12/10 15:27:00
Maybe a comment that we plan to extend responsibil
| |
204 */ | |
205 class GrPathProcessor : public GrPrimitiveProcessor { | |
206 public: | |
207 static GrPathProcessor* Create(GrColor color) { | |
208 return SkNEW_ARGS(GrPathProcessor, (color)); | |
209 } | |
210 | |
211 virtual const char* name() SK_OVERRIDE const { return "PathProcessor"; } | |
212 virtual uint8_t coverage() SK_OVERRIDE const { return 0xff; } | |
bsalomon
2014/12/10 15:27:00
no need for virtual keyword on overrides.
| |
213 virtual void computeOutputColor(GrInitInvariantOutput* out) const SK_OVERRID E; | |
214 virtual void computeOutputCoverage(GrInitInvariantOutput* out) const SK_OVER RIDE; | |
215 | |
216 private: | |
217 GrPathProcessor(GrColor color) : fColor(color) {} | |
218 GrColor fColor; | |
219 | |
220 typedef GrProcessor INHERITED; | |
221 }; | |
177 #endif | 222 #endif |
OLD | NEW |