Chromium Code Reviews| 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) { |
| 322 fVertexStride += attribute.fOffset; | 337 fVertexStride += attribute.fOffset; |
|
bsalomon
2015/01/13 20:19:22
fail if too many are added?
| |
| 323 return fAttribs.push_back(attribute); | 338 fAttribs[fNumAttribs] = attribute; |
| 339 return fAttribs[fNumAttribs++]; | |
| 324 } | 340 } |
| 325 | 341 |
| 326 void setWillUseGeoShader() { fWillUseGeoShader = true; } | 342 void setWillUseGeoShader() { fWillUseGeoShader = true; } |
| 327 | 343 |
| 328 // TODO hack see above | 344 // TODO hack see above |
| 329 void setHasVertexColor() { fHasVertexColor = true; } | 345 void setHasVertexColor() { fHasVertexColor = true; } |
| 330 void setHasLocalCoords() { fHasLocalCoords = true; } | 346 void setHasLocalCoords() { fHasLocalCoords = true; } |
| 331 | 347 |
| 332 virtual void onGetInvariantOutputColor(GrInitInvariantOutput*) const {} | 348 virtual void onGetInvariantOutputColor(GrInitInvariantOutput*) const {} |
| 333 virtual void onGetInvariantOutputCoverage(GrInitInvariantOutput*) const = 0; | 349 virtual void onGetInvariantOutputCoverage(GrInitInvariantOutput*) const = 0; |
| 334 | 350 |
| 335 private: | 351 private: |
| 336 virtual bool onCanMakeEqual(const GrBatchTracker& mine, | 352 virtual bool onCanMakeEqual(const GrBatchTracker& mine, |
| 337 const GrGeometryProcessor& that, | 353 const GrGeometryProcessor& that, |
| 338 const GrBatchTracker& theirs) const = 0; | 354 const GrBatchTracker& theirs) const = 0; |
| 339 | 355 |
| 340 // TODO delete this when we have more advanced equality testing via bundles and the BT | 356 // TODO delete this when we have more advanced equality testing via bundles and the BT |
| 341 virtual bool onIsEqual(const GrGeometryProcessor&) const = 0; | 357 virtual bool onIsEqual(const GrGeometryProcessor&) const = 0; |
| 342 | 358 |
| 343 bool hasExplicitLocalCoords() const SK_OVERRIDE { return fHasLocalCoords; } | 359 bool hasExplicitLocalCoords() const SK_OVERRIDE { return fHasLocalCoords; } |
| 344 | 360 |
| 345 SkSTArray<kMaxVertexAttribs, GrAttribute, true> fAttribs; | |
| 346 size_t fVertexStride; | |
| 347 GrColor fColor; | 361 GrColor fColor; |
| 348 bool fOpaqueVertexColors; | 362 bool fOpaqueVertexColors; |
| 349 bool fWillUseGeoShader; | 363 bool fWillUseGeoShader; |
| 350 bool fHasVertexColor; | 364 bool fHasVertexColor; |
| 351 bool fHasLocalCoords; | 365 bool fHasLocalCoords; |
| 352 | 366 |
| 353 typedef GrPrimitiveProcessor INHERITED; | 367 typedef GrPrimitiveProcessor INHERITED; |
| 354 }; | 368 }; |
| 355 | 369 |
| 356 /* | 370 /* |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 371 const GrPrimitiveProcessor& that, | 385 const GrPrimitiveProcessor& that, |
| 372 const GrBatchTracker& theirs) const SK_OVERRIDE; | 386 const GrBatchTracker& theirs) const SK_OVERRIDE; |
| 373 | 387 |
| 374 const char* name() const SK_OVERRIDE { return "PathProcessor"; } | 388 const char* name() const SK_OVERRIDE { return "PathProcessor"; } |
| 375 | 389 |
| 376 GrColor color() const { return fColor; } | 390 GrColor color() const { return fColor; } |
| 377 | 391 |
| 378 void getInvariantOutputColor(GrInitInvariantOutput* out) const SK_OVERRIDE; | 392 void getInvariantOutputColor(GrInitInvariantOutput* out) const SK_OVERRIDE; |
| 379 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const SK_OVERRID E; | 393 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const SK_OVERRID E; |
| 380 | 394 |
| 395 bool willUseGeoShader() const SK_OVERRIDE { return false; } | |
| 396 | |
| 381 virtual void getGLProcessorKey(const GrBatchTracker& bt, | 397 virtual void getGLProcessorKey(const GrBatchTracker& bt, |
| 382 const GrGLCaps& caps, | 398 const GrGLCaps& caps, |
| 383 GrProcessorKeyBuilder* b) const SK_OVERRIDE; | 399 GrProcessorKeyBuilder* b) const SK_OVERRIDE; |
| 384 | 400 |
| 385 virtual GrGLPrimitiveProcessor* createGLInstance(const GrBatchTracker& bt, | 401 virtual GrGLPrimitiveProcessor* createGLInstance(const GrBatchTracker& bt, |
| 386 const GrGLCaps& caps) const SK_OVERRIDE; | 402 const GrGLCaps& caps) const SK_OVERRIDE; |
| 387 | 403 |
| 388 protected: | 404 protected: |
| 389 GrPathProcessor(GrColor color, const SkMatrix& viewMatrix, const SkMatrix& l ocalMatrix); | 405 GrPathProcessor(GrColor color, const SkMatrix& viewMatrix, const SkMatrix& l ocalMatrix); |
| 390 | 406 |
| 391 private: | 407 private: |
| 392 bool hasExplicitLocalCoords() const SK_OVERRIDE { return false; } | 408 bool hasExplicitLocalCoords() const SK_OVERRIDE { return false; } |
| 393 | 409 |
| 394 GrColor fColor; | 410 GrColor fColor; |
| 395 | 411 |
| 396 typedef GrPrimitiveProcessor INHERITED; | 412 typedef GrPrimitiveProcessor INHERITED; |
| 397 }; | 413 }; |
| 398 | 414 |
| 399 #endif | 415 #endif |
| OLD | NEW |