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 |
11 #include "GrColor.h" | 11 #include "GrColor.h" |
12 #include "GrGeometryData.h" | 12 #include "GrGeometryData.h" |
13 #include "GrProcessor.h" | 13 #include "GrProcessor.h" |
14 #include "GrShaderVar.h" | 14 #include "GrShaderVar.h" |
15 | 15 |
16 /* | 16 /* |
17 * A struct for tracking batching decisions. While this lives on GrOptState, it is managed | 17 * A struct for tracking batching decisions. While this lives on GrOptState, it is managed |
18 * entirely by the derived classes of the GP. | 18 * entirely by the derived classes of the GP. |
19 */ | 19 */ |
20 class GrBatchTracker { | 20 class GrBatchTracker { |
21 public: | 21 public: |
22 template <typename T> const T& cast() const { | 22 template <typename T> const T& cast() const { |
23 SkASSERT(sizeof(T) <= kMaxSize); | 23 SkASSERT(sizeof(T) <= kMaxSize); |
24 return *reinterpret_cast<const T*>(fData); | 24 return *reinterpret_cast<const T*>(fData.get()); |
25 } | 25 } |
26 | 26 |
27 template <typename T> T* cast() { | 27 template <typename T> T* cast() { |
28 SkASSERT(sizeof(T) <= kMaxSize); | 28 SkASSERT(sizeof(T) <= kMaxSize); |
29 return reinterpret_cast<T*>(fData); | 29 return reinterpret_cast<T*>(fData.get()); |
30 } | 30 } |
31 | 31 |
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 mutable SkAlignedSStorage<kMaxSize> fData; |
bsalomon
2014/12/10 18:36:20
Maybe these just shouldn't be const if this field
| |
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; | 42 struct GrInitInvariantOutput; |
43 | 43 |
44 /* | 44 /* |
45 * GrGeometryProcessors and GrPathProcessors may effect invariantColor | 45 * GrGeometryProcessors and GrPathProcessors may effect invariantColor |
(...skipping 16 matching lines...) Expand all Loading... | |
62 * 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 |
63 * (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 |
64 * 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 |
65 * 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 |
66 * added to the vertex attribute array specified on the GrDrawState. | 66 * added to the vertex attribute array specified on the GrDrawState. |
67 * GrGeometryProcessor subclasses should be immutable after construction. | 67 * GrGeometryProcessor subclasses should be immutable after construction. |
68 */ | 68 */ |
69 class GrGeometryProcessor : public GrPrimitiveProcessor { | 69 class GrGeometryProcessor : public GrPrimitiveProcessor { |
70 public: | 70 public: |
71 GrGeometryProcessor(GrColor color, uint8_t coverage = 0xff) | 71 GrGeometryProcessor(GrColor color, uint8_t coverage = 0xff) |
72 : fVertexStride(0) | 72 : /*TODO HACK*/fNewStyle(false), fVertexStride(0) |
73 , fColor(color) | 73 , fColor(color) |
74 , fCoverage(coverage) | 74 , fCoverage(coverage) |
75 , fWillUseGeoShader(false) | 75 , fWillUseGeoShader(false) |
76 , fHasVertexColor(false) | 76 , fHasVertexColor(false) |
77 , fHasVertexCoverage(false) | 77 , fHasVertexCoverage(false) |
78 , fHasLocalCoords(false) {} | 78 , fHasLocalCoords(false) {} |
79 | 79 |
80 virtual const char* name() const = 0; | 80 virtual const char* name() const = 0; |
81 | 81 |
82 /** | 82 /** |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
136 } | 136 } |
137 | 137 |
138 // TODO this is fragile, most gps set their coverage to 0xff so this is okay. In the long | 138 // TODO this is fragile, most gps set their coverage to 0xff so this is okay. In the long |
139 // term this should move to subclasses which set explicit coverage | 139 // term this should move to subclasses which set explicit coverage |
140 if (!fHasVertexCoverage && this->coverage() != that.coverage()) { | 140 if (!fHasVertexCoverage && this->coverage() != that.coverage()) { |
141 return false; | 141 return false; |
142 } | 142 } |
143 return this->onIsEqual(that); | 143 return this->onIsEqual(that); |
144 } | 144 } |
145 | 145 |
146 /* | |
147 * This struct allows the optstate to communicate requirements to the GP. | |
148 * TODO when the GP can encapsulate draw information in bundles, we can refa ctor this struct. | |
149 * Ultimately, when setColor and setCoverage live on the GP, this struct can be replaced with | |
150 * a simple override color passed into initBatchTracker | |
151 */ | |
146 struct InitBT { | 152 struct InitBT { |
147 bool fOutputColor; | 153 bool fOutputColor; |
148 bool fOutputCoverage; | 154 bool fOutputCoverage; |
155 bool fRemoveColorAttr; | |
156 bool fRemoveCoverageAttr; | |
149 GrColor fColor; | 157 GrColor fColor; |
150 GrColor fCoverage; | 158 GrColor fCoverage; |
151 }; | 159 }; |
152 | 160 |
153 virtual void initBatchTracker(GrBatchTracker*, const InitBT&) const {} | 161 virtual void initBatchTracker(GrBatchTracker*, const InitBT&) const {} |
154 | 162 |
163 // TODO this call is temporary. Once we have deferred geometry, GPs can alw ays make themselves | |
bsalomon
2014/12/10 18:36:20
can/should we fold this into isEqual, that is repl
| |
164 // equal | |
165 virtual bool canBatch(const GrBatchTracker&, const GrBatchTracker&) const { SkFAIL("s"); return false; } | |
166 | |
155 GrColor color() const { return fColor; } | 167 GrColor color() const { return fColor; } |
156 uint8_t coverage() const { return fCoverage; } | 168 uint8_t coverage() const { return fCoverage; } |
157 | 169 |
158 // TODO this is a total hack until the gp can own whether or not it uses uni form | 170 // TODO this is a total hack until the gp can own whether or not it uses uni form |
159 // color / coverage | 171 // color / coverage |
160 bool hasVertexColor() const { return fHasVertexColor; } | 172 bool hasVertexColor() const { return fHasVertexColor; } |
161 bool hasVertexCoverage() const { return fHasVertexCoverage; } | 173 bool hasVertexCoverage() const { return fHasVertexCoverage; } |
162 bool hasLocalCoords() const { return fHasLocalCoords; } | 174 bool hasLocalCoords() const { return fHasLocalCoords; } |
163 | 175 |
164 void getOutputColor(GrInitInvariantOutput* out) const SK_OVERRIDE; | 176 void getOutputColor(GrInitInvariantOutput* out) const SK_OVERRIDE; |
165 void getOutputCoverage(GrInitInvariantOutput* out) const SK_OVERRIDE; | 177 void getOutputCoverage(GrInitInvariantOutput* out) const SK_OVERRIDE; |
178 // TODO hack | |
179 bool fNewStyle; | |
bsalomon
2014/12/10 18:36:20
I know it's a hack but can you formalize this a li
| |
166 | 180 |
167 protected: | 181 protected: |
182 enum Output { | |
183 kAllOnes_Output, | |
184 kAttribute_Output, | |
185 kUniform_Output, | |
186 }; | |
187 | |
188 static Output GetColorOutputType(const InitBT& init, bool hasVertexColor) { | |
189 bool hasUniformColor = (init.fOutputColor && !hasVertexColor) || init.fR emoveColorAttr; | |
190 if (!init.fOutputColor) { | |
191 return kAllOnes_Output; | |
192 } else if (hasUniformColor) { | |
193 return kUniform_Output; | |
194 } else { | |
195 SkASSERT(hasVertexColor); | |
196 return kAttribute_Output; | |
197 } | |
198 } | |
199 | |
168 /** | 200 /** |
169 * Subclasses call this from their constructor to register vertex attributes . Attributes | 201 * Subclasses call this from their constructor to register vertex attributes . Attributes |
170 * will be padded to the nearest 4 bytes for performance reasons. | 202 * will be padded to the nearest 4 bytes for performance reasons. |
171 * TODO After deferred geometry, we should do all of this inline in Generate Geometry alongside | 203 * TODO After deferred geometry, we should do all of this inline in Generate Geometry alongside |
172 * the struct used to actually populate the attributes | 204 * the struct used to actually populate the attributes |
173 */ | 205 */ |
174 const GrAttribute& addVertexAttrib(const GrAttribute& attribute) { | 206 const GrAttribute& addVertexAttrib(const GrAttribute& attribute) { |
175 fVertexStride += attribute.fOffset; | 207 fVertexStride += attribute.fOffset; |
176 return fAttribs.push_back(attribute); | 208 return fAttribs.push_back(attribute); |
177 } | 209 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
216 void getOutputColor(GrInitInvariantOutput* out) const SK_OVERRIDE; | 248 void getOutputColor(GrInitInvariantOutput* out) const SK_OVERRIDE; |
217 void getOutputCoverage(GrInitInvariantOutput* out) const SK_OVERRIDE; | 249 void getOutputCoverage(GrInitInvariantOutput* out) const SK_OVERRIDE; |
218 | 250 |
219 private: | 251 private: |
220 GrPathProcessor(GrColor color) : fColor(color) {} | 252 GrPathProcessor(GrColor color) : fColor(color) {} |
221 GrColor fColor; | 253 GrColor fColor; |
222 | 254 |
223 typedef GrProcessor INHERITED; | 255 typedef GrProcessor INHERITED; |
224 }; | 256 }; |
225 #endif | 257 #endif |
OLD | NEW |