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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 /* | 114 /* |
115 * We always call canMakeEqual before makeEqual so there is no need to do an
y kind of equality | 115 * We always call canMakeEqual before makeEqual so there is no need to do an
y kind of equality |
116 * testing here | 116 * testing here |
117 * TODO make this pure virtual when primProcs can actually use it | 117 * TODO make this pure virtual when primProcs can actually use it |
118 */ | 118 */ |
119 virtual void makeEqual(GrBatchTracker*, const GrBatchTracker&) const {} | 119 virtual void makeEqual(GrBatchTracker*, const GrBatchTracker&) const {} |
120 | 120 |
121 virtual void getInvariantOutputColor(GrInitInvariantOutput* out) const = 0; | 121 virtual void getInvariantOutputColor(GrInitInvariantOutput* out) const = 0; |
122 virtual void getInvariantOutputCoverage(GrInitInvariantOutput* out) const =
0; | 122 virtual void getInvariantOutputCoverage(GrInitInvariantOutput* out) const =
0; |
123 | 123 |
| 124 // Only the GrGeometryProcessor subclass actually has a geo shader or vertex
attributes, but |
| 125 // we put these calls on the base class to prevent having to cast |
| 126 virtual bool willUseGeoShader() const = 0; |
| 127 |
| 128 /* |
| 129 * This is a safeguard to prevent GrPrimitiveProcessor's from going beyond p
latform specific |
| 130 * attribute limits. This number can almost certainly be raised if required. |
| 131 */ |
| 132 static const int kMaxVertexAttribs = 6; |
| 133 |
| 134 struct Attribute { |
| 135 Attribute() |
| 136 : fName(NULL) |
| 137 , fType(kFloat_GrVertexAttribType) |
| 138 , fOffset(0) {} |
| 139 Attribute(const char* name, GrVertexAttribType type) |
| 140 : fName(name) |
| 141 , fType(type) |
| 142 , fOffset(SkAlign4(GrVertexAttribTypeSize(type))) {} |
| 143 const char* fName; |
| 144 GrVertexAttribType fType; |
| 145 size_t fOffset; |
| 146 }; |
| 147 |
| 148 int numAttribs() const { return fNumAttribs; } |
| 149 const Attribute& getAttrib(int index) const { |
| 150 SkASSERT(index < fNumAttribs); |
| 151 return fAttribs[index]; |
| 152 } |
| 153 |
| 154 // Returns the vertex stride of the GP. A common use case is to request geo
metry from a |
| 155 // drawtarget based off of the stride, and to populate this memory using an
implicit array of |
| 156 // structs. In this case, it is best to assert the vertexstride == sizeof(V
ertexStruct). |
| 157 size_t getVertexStride() const { return fVertexStride; } |
| 158 |
124 /** | 159 /** |
125 * Gets a transformKey from an array of coord transforms | 160 * Gets a transformKey from an array of coord transforms |
126 */ | 161 */ |
127 uint32_t getTransformKey(const SkTArray<const GrCoordTransform*, true>&) con
st; | 162 uint32_t getTransformKey(const SkTArray<const GrCoordTransform*, true>&) con
st; |
128 | 163 |
129 /** | 164 /** |
130 * Sets a unique key on the GrProcessorKeyBuilder that is directly associate
d with this geometry | 165 * Sets a unique key on the GrProcessorKeyBuilder that is directly associate
d with this geometry |
131 * processor's GL backend implementation. | 166 * processor's GL backend implementation. |
132 */ | 167 */ |
133 virtual void getGLProcessorKey(const GrBatchTracker& bt, | 168 virtual void getGLProcessorKey(const GrBatchTracker& bt, |
134 const GrGLCaps& caps, | 169 const GrGLCaps& caps, |
135 GrProcessorKeyBuilder* b) const = 0; | 170 GrProcessorKeyBuilder* b) const = 0; |
136 | 171 |
137 | 172 |
138 /** Returns a new instance of the appropriate *GL* implementation class | 173 /** Returns a new instance of the appropriate *GL* implementation class |
139 for the given GrProcessor; caller is responsible for deleting | 174 for the given GrProcessor; caller is responsible for deleting |
140 the object. */ | 175 the object. */ |
141 virtual GrGLPrimitiveProcessor* createGLInstance(const GrBatchTracker& bt, | 176 virtual GrGLPrimitiveProcessor* createGLInstance(const GrBatchTracker& bt, |
142 const GrGLCaps& caps) const
= 0; | 177 const GrGLCaps& caps) const
= 0; |
143 | 178 |
144 protected: | 179 protected: |
145 GrPrimitiveProcessor(const SkMatrix& viewMatrix, const SkMatrix& localMatrix
) | 180 GrPrimitiveProcessor(const SkMatrix& viewMatrix, const SkMatrix& localMatrix
) |
146 : fViewMatrix(viewMatrix) | 181 : fNumAttribs(0) |
| 182 , fVertexStride(0) |
| 183 , fViewMatrix(viewMatrix) |
147 , fLocalMatrix(localMatrix) {} | 184 , fLocalMatrix(localMatrix) {} |
148 | 185 |
149 /* | 186 /* |
150 * CanCombineOutput will return true if two draws are 'batchable' from a col
or perspective. | 187 * CanCombineOutput will return true if two draws are 'batchable' from a col
or perspective. |
151 * TODO remove this when GPs can upgrade to attribute color | 188 * TODO remove this when GPs can upgrade to attribute color |
152 */ | 189 */ |
153 static bool CanCombineOutput(GrGPInput left, GrColor lColor, GrGPInput right
, GrColor rColor) { | 190 static bool CanCombineOutput(GrGPInput left, GrColor lColor, GrGPInput right
, GrColor rColor) { |
154 if (left != right) { | 191 if (left != right) { |
155 return false; | 192 return false; |
156 } | 193 } |
(...skipping 12 matching lines...) Expand all Loading... |
169 if (leftUsesLocalCoords != rightUsesLocalCoords) { | 206 if (leftUsesLocalCoords != rightUsesLocalCoords) { |
170 return false; | 207 return false; |
171 } | 208 } |
172 | 209 |
173 if (leftUsesLocalCoords && !left.localMatrix().cheapEqualTo(right.localM
atrix())) { | 210 if (leftUsesLocalCoords && !left.localMatrix().cheapEqualTo(right.localM
atrix())) { |
174 return false; | 211 return false; |
175 } | 212 } |
176 return true; | 213 return true; |
177 } | 214 } |
178 | 215 |
| 216 Attribute fAttribs[kMaxVertexAttribs]; |
| 217 int fNumAttribs; |
| 218 size_t fVertexStride; |
| 219 |
179 private: | 220 private: |
180 virtual bool hasExplicitLocalCoords() const = 0; | 221 virtual bool hasExplicitLocalCoords() const = 0; |
181 | 222 |
182 SkMatrix fViewMatrix; | 223 SkMatrix fViewMatrix; |
183 SkMatrix fLocalMatrix; | 224 SkMatrix fLocalMatrix; |
184 | 225 |
185 typedef GrProcessor INHERITED; | 226 typedef GrProcessor INHERITED; |
186 }; | 227 }; |
187 | 228 |
188 /** | 229 /** |
189 * A GrGeometryProcessor is a flexible method for rendering a primitive. The Gr
GeometryProcessor | 230 * A GrGeometryProcessor is a flexible method for rendering a primitive. The Gr
GeometryProcessor |
190 * has complete control over vertex attributes and uniforms(aside from the rende
r target) but it | 231 * has complete control over vertex attributes and uniforms(aside from the rende
r target) but it |
191 * must obey the same contract as any GrPrimitiveProcessor, specifically it must
emit a color and | 232 * must obey the same contract as any GrPrimitiveProcessor, specifically it must
emit a color and |
192 * coverage into the fragment shader. Where this color and coverage come from i
s completely the | 233 * coverage into the fragment shader. Where this color and coverage come from i
s completely the |
193 * responsibility of the GrGeometryProcessor. | 234 * responsibility of the GrGeometryProcessor. |
194 */ | 235 */ |
195 class GrGeometryProcessor : public GrPrimitiveProcessor { | 236 class GrGeometryProcessor : public GrPrimitiveProcessor { |
196 public: | 237 public: |
197 // TODO the Hint can be handled in a much more clean way when we have deferr
ed geometry or | 238 // TODO the Hint can be handled in a much more clean way when we have deferr
ed geometry or |
198 // atleast bundles | 239 // atleast bundles |
199 GrGeometryProcessor(GrColor color, | 240 GrGeometryProcessor(GrColor color, |
200 const SkMatrix& viewMatrix = SkMatrix::I(), | 241 const SkMatrix& viewMatrix = SkMatrix::I(), |
201 const SkMatrix& localMatrix = SkMatrix::I(), | 242 const SkMatrix& localMatrix = SkMatrix::I(), |
202 bool opaqueVertexColors = false) | 243 bool opaqueVertexColors = false) |
203 : INHERITED(viewMatrix, localMatrix) | 244 : INHERITED(viewMatrix, localMatrix) |
204 , fVertexStride(0) | |
205 , fColor(color) | 245 , fColor(color) |
206 , fOpaqueVertexColors(opaqueVertexColors) | 246 , fOpaqueVertexColors(opaqueVertexColors) |
207 , fWillUseGeoShader(false) | 247 , fWillUseGeoShader(false) |
208 , fHasVertexColor(false) | 248 , fHasVertexColor(false) |
209 , fHasLocalCoords(false) {} | 249 , fHasLocalCoords(false) {} |
210 | 250 |
211 /* | |
212 * This is a safeguard to prevent GPs from going beyond platform specific at
tribute limits. | |
213 * This number can almost certainly be raised if required. | |
214 */ | |
215 static const int kMaxVertexAttribs = 6; | |
216 | |
217 struct GrAttribute { | |
218 GrAttribute(const char* name, GrVertexAttribType type) | |
219 : fName(name) | |
220 , fType(type) | |
221 , fOffset(SkAlign4(GrVertexAttribTypeSize(type))) {} | |
222 const char* fName; | |
223 GrVertexAttribType fType; | |
224 size_t fOffset; | |
225 }; | |
226 | |
227 typedef SkTArray<GrAttribute, true> VertexAttribArray; | |
228 | |
229 const VertexAttribArray& getAttribs() const { return fAttribs; } | |
230 | |
231 // Returns the vertex stride of the GP. A common use case is to request geo
metry from a | |
232 // drawtarget based off of the stride, and to populate this memory using an
implicit array of | |
233 // structs. In this case, it is best to assert the vertexstride == sizeof(V
ertexStruct). | |
234 size_t getVertexStride() const { return fVertexStride; } | |
235 | |
236 bool willUseGeoShader() const { return fWillUseGeoShader; } | 251 bool willUseGeoShader() const { return fWillUseGeoShader; } |
237 | 252 |
238 /* | 253 /* |
239 * In an ideal world, two GrGeometryProcessors with the same class id and te
xture accesses | 254 * In an ideal world, two GrGeometryProcessors with the same class id and te
xture accesses |
240 * would ALWAYS be able to batch together. If two GrGeometryProcesosrs are
the same then we | 255 * would ALWAYS be able to batch together. If two GrGeometryProcesosrs are
the same then we |
241 * will only keep one of them. The remaining GrGeometryProcessor then updat
es its | 256 * will only keep one of them. The remaining GrGeometryProcessor then updat
es its |
242 * GrBatchTracker to incorporate the draw information from the GrGeometryPro
cessor we discard. | 257 * GrBatchTracker to incorporate the draw information from the GrGeometryPro
cessor we discard. |
243 * Any bundles associated with the discarded GrGeometryProcessor will be att
ached to the | 258 * Any bundles associated with the discarded GrGeometryProcessor will be att
ached to the |
244 * remaining GrGeometryProcessor. | 259 * remaining GrGeometryProcessor. |
245 */ | 260 */ |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 | 326 |
312 /** | 327 /** |
313 * Subclasses call this from their constructor to register vertex attributes
. Attributes | 328 * Subclasses call this from their constructor to register vertex attributes
. Attributes |
314 * will be padded to the nearest 4 bytes for performance reasons. | 329 * will be padded to the nearest 4 bytes for performance reasons. |
315 * TODO After deferred geometry, we should do all of this inline in Generate
Geometry alongside | 330 * TODO After deferred geometry, we should do all of this inline in Generate
Geometry alongside |
316 * the struct used to actually populate the attributes. This is all extreme
ly fragile, vertex | 331 * the struct used to actually populate the attributes. This is all extreme
ly fragile, vertex |
317 * attributes have to be added in the order they will appear in the struct w
hich maps memory. | 332 * attributes have to be added in the order they will appear in the struct w
hich maps memory. |
318 * The processor key should reflect the vertex attributes, or there lack the
reof in the | 333 * The processor key should reflect the vertex attributes, or there lack the
reof in the |
319 * GrGeometryProcessor. | 334 * GrGeometryProcessor. |
320 */ | 335 */ |
321 const GrAttribute& addVertexAttrib(const GrAttribute& attribute) { | 336 const Attribute& addVertexAttrib(const Attribute& attribute) { |
| 337 SkASSERT(fNumAttribs < kMaxVertexAttribs); |
322 fVertexStride += attribute.fOffset; | 338 fVertexStride += attribute.fOffset; |
323 return fAttribs.push_back(attribute); | 339 fAttribs[fNumAttribs] = attribute; |
| 340 return fAttribs[fNumAttribs++]; |
324 } | 341 } |
325 | 342 |
326 void setWillUseGeoShader() { fWillUseGeoShader = true; } | 343 void setWillUseGeoShader() { fWillUseGeoShader = true; } |
327 | 344 |
328 // TODO hack see above | 345 // TODO hack see above |
329 void setHasVertexColor() { fHasVertexColor = true; } | 346 void setHasVertexColor() { fHasVertexColor = true; } |
330 void setHasLocalCoords() { fHasLocalCoords = true; } | 347 void setHasLocalCoords() { fHasLocalCoords = true; } |
331 | 348 |
332 virtual void onGetInvariantOutputColor(GrInitInvariantOutput*) const {} | 349 virtual void onGetInvariantOutputColor(GrInitInvariantOutput*) const {} |
333 virtual void onGetInvariantOutputCoverage(GrInitInvariantOutput*) const = 0; | 350 virtual void onGetInvariantOutputCoverage(GrInitInvariantOutput*) const = 0; |
334 | 351 |
335 private: | 352 private: |
336 virtual bool onCanMakeEqual(const GrBatchTracker& mine, | 353 virtual bool onCanMakeEqual(const GrBatchTracker& mine, |
337 const GrGeometryProcessor& that, | 354 const GrGeometryProcessor& that, |
338 const GrBatchTracker& theirs) const = 0; | 355 const GrBatchTracker& theirs) const = 0; |
339 | 356 |
340 // TODO delete this when we have more advanced equality testing via bundles
and the BT | 357 // TODO delete this when we have more advanced equality testing via bundles
and the BT |
341 virtual bool onIsEqual(const GrGeometryProcessor&) const = 0; | 358 virtual bool onIsEqual(const GrGeometryProcessor&) const = 0; |
342 | 359 |
343 bool hasExplicitLocalCoords() const SK_OVERRIDE { return fHasLocalCoords; } | 360 bool hasExplicitLocalCoords() const SK_OVERRIDE { return fHasLocalCoords; } |
344 | 361 |
345 SkSTArray<kMaxVertexAttribs, GrAttribute, true> fAttribs; | |
346 size_t fVertexStride; | |
347 GrColor fColor; | 362 GrColor fColor; |
348 bool fOpaqueVertexColors; | 363 bool fOpaqueVertexColors; |
349 bool fWillUseGeoShader; | 364 bool fWillUseGeoShader; |
350 bool fHasVertexColor; | 365 bool fHasVertexColor; |
351 bool fHasLocalCoords; | 366 bool fHasLocalCoords; |
352 | 367 |
353 typedef GrPrimitiveProcessor INHERITED; | 368 typedef GrPrimitiveProcessor INHERITED; |
354 }; | 369 }; |
355 | 370 |
356 /* | 371 /* |
(...skipping 14 matching lines...) Expand all Loading... |
371 const GrPrimitiveProcessor& that, | 386 const GrPrimitiveProcessor& that, |
372 const GrBatchTracker& theirs) const SK_OVERRIDE; | 387 const GrBatchTracker& theirs) const SK_OVERRIDE; |
373 | 388 |
374 const char* name() const SK_OVERRIDE { return "PathProcessor"; } | 389 const char* name() const SK_OVERRIDE { return "PathProcessor"; } |
375 | 390 |
376 GrColor color() const { return fColor; } | 391 GrColor color() const { return fColor; } |
377 | 392 |
378 void getInvariantOutputColor(GrInitInvariantOutput* out) const SK_OVERRIDE; | 393 void getInvariantOutputColor(GrInitInvariantOutput* out) const SK_OVERRIDE; |
379 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const SK_OVERRID
E; | 394 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const SK_OVERRID
E; |
380 | 395 |
| 396 bool willUseGeoShader() const SK_OVERRIDE { return false; } |
| 397 |
381 virtual void getGLProcessorKey(const GrBatchTracker& bt, | 398 virtual void getGLProcessorKey(const GrBatchTracker& bt, |
382 const GrGLCaps& caps, | 399 const GrGLCaps& caps, |
383 GrProcessorKeyBuilder* b) const SK_OVERRIDE; | 400 GrProcessorKeyBuilder* b) const SK_OVERRIDE; |
384 | 401 |
385 virtual GrGLPrimitiveProcessor* createGLInstance(const GrBatchTracker& bt, | 402 virtual GrGLPrimitiveProcessor* createGLInstance(const GrBatchTracker& bt, |
386 const GrGLCaps& caps) const
SK_OVERRIDE; | 403 const GrGLCaps& caps) const
SK_OVERRIDE; |
387 | 404 |
388 protected: | 405 protected: |
389 GrPathProcessor(GrColor color, const SkMatrix& viewMatrix, const SkMatrix& l
ocalMatrix); | 406 GrPathProcessor(GrColor color, const SkMatrix& viewMatrix, const SkMatrix& l
ocalMatrix); |
390 | 407 |
391 private: | 408 private: |
392 bool hasExplicitLocalCoords() const SK_OVERRIDE { return false; } | 409 bool hasExplicitLocalCoords() const SK_OVERRIDE { return false; } |
393 | 410 |
394 GrColor fColor; | 411 GrColor fColor; |
395 | 412 |
396 typedef GrPrimitiveProcessor INHERITED; | 413 typedef GrPrimitiveProcessor INHERITED; |
397 }; | 414 }; |
398 | 415 |
399 #endif | 416 #endif |
OLD | NEW |