Chromium Code Reviews| 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 #include "GrDefaultGeoProcFactory.h" | 8 #include "GrDefaultGeoProcFactory.h" |
| 9 | 9 |
| 10 #include "GrInvariantOutput.h" | 10 #include "GrInvariantOutput.h" |
| 11 #include "gl/GrGLGeometryProcessor.h" | 11 #include "gl/GrGLGeometryProcessor.h" |
| 12 #include "gl/builders/GrGLProgramBuilder.h" | 12 #include "gl/builders/GrGLProgramBuilder.h" |
| 13 | 13 |
| 14 /* | 14 /* |
| 15 * The default Geometry Processor simply takes position and multiplies it by the uniform view | 15 * The default Geometry Processor simply takes position and multiplies it by the uniform view |
| 16 * matrix. It also leaves coverage untouched. Behind the scenes, we may add per vertex color or | 16 * matrix. It also leaves coverage untouched. Behind the scenes, we may add per vertex color or |
| 17 * local coords. | 17 * local coords. |
| 18 */ | 18 */ |
| 19 | |
| 20 enum GPType { | |
|
bsalomon
2015/08/05 15:17:02
This looks like a set of flags for a bitfield rath
| |
| 21 kPosition_GPType = 0x0, // we ALWAYS have position | |
| 22 kColor_GPType = 0x01, | |
| 23 kLocalCoord_GPType = 0x02, | |
| 24 kCoverage_GPType= 0x04, | |
| 25 kTransformedLocalCoord_GPType = 0x08, | |
| 26 kLastGPType = kTransformedLocalCoord_GPType | |
| 27 }; | |
| 28 | |
| 19 class DefaultGeoProc : public GrGeometryProcessor { | 29 class DefaultGeoProc : public GrGeometryProcessor { |
| 20 public: | 30 public: |
| 21 static GrGeometryProcessor* Create(uint32_t gpTypeFlags, | 31 static GrGeometryProcessor* Create(uint32_t gpTypeFlags, |
| 22 GrColor color, | 32 GrColor color, |
| 23 const SkMatrix& viewMatrix, | 33 const SkMatrix& viewMatrix, |
| 24 const SkMatrix& localMatrix, | 34 const SkMatrix& localMatrix, |
| 25 bool localCoordsWillBeRead, | 35 bool localCoordsWillBeRead, |
| 26 bool coverageWillBeIgnored, | 36 bool coverageWillBeIgnored, |
| 27 uint8_t coverage) { | 37 uint8_t coverage) { |
| 28 return SkNEW_ARGS(DefaultGeoProc, (gpTypeFlags, | 38 return SkNEW_ARGS(DefaultGeoProc, (gpTypeFlags, |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 70 pb->addPassThroughAttribute(gp.inColor(), args.fOutputColor) ; | 80 pb->addPassThroughAttribute(gp.inColor(), args.fOutputColor) ; |
| 71 } else { | 81 } else { |
| 72 this->setupUniformColor(pb, args.fOutputColor, &fColorUnifor m); | 82 this->setupUniformColor(pb, args.fOutputColor, &fColorUnifor m); |
| 73 } | 83 } |
| 74 } | 84 } |
| 75 | 85 |
| 76 // Setup position | 86 // Setup position |
| 77 this->setupPosition(pb, gpArgs, gp.inPosition()->fName, gp.viewMatri x(), | 87 this->setupPosition(pb, gpArgs, gp.inPosition()->fName, gp.viewMatri x(), |
| 78 &fViewMatrixUniform); | 88 &fViewMatrixUniform); |
| 79 | 89 |
| 80 if (gp.inLocalCoords()) { | 90 if (gp.hasExplicitLocalCoords()) { |
| 81 // emit transforms with explicit local coords | 91 // emit transforms with explicit local coords |
| 82 this->emitTransforms(pb, gpArgs->fPositionVar, gp.inLocalCoords( )->fName, | 92 this->emitTransforms(pb, gpArgs->fPositionVar, gp.inLocalCoords( )->fName, |
| 83 gp.localMatrix(), args.fTransformsIn, args. fTransformsOut); | 93 gp.localMatrix(), args.fTransformsIn, args. fTransformsOut); |
| 94 } else if(gp.hasTransformedLocalCoords()) { | |
| 95 // transforms have already been applied to vertex attributes on the cpu | |
| 96 this->emitTransforms(pb, gp.inLocalCoords()->fName, | |
| 97 args.fTransformsIn, args.fTransformsOut); | |
| 84 } else { | 98 } else { |
| 85 // emit transforms with position | 99 // emit transforms with position |
| 86 this->emitTransforms(pb, gpArgs->fPositionVar, gp.inPosition()-> fName, | 100 this->emitTransforms(pb, gpArgs->fPositionVar, gp.inPosition()-> fName, |
| 87 gp.localMatrix(), args.fTransformsIn, args. fTransformsOut); | 101 gp.localMatrix(), args.fTransformsIn, args. fTransformsOut); |
| 88 } | 102 } |
| 89 | 103 |
| 90 // Setup coverage as pass through | 104 // Setup coverage as pass through |
| 91 if (!gp.coverageWillBeIgnored()) { | 105 if (!gp.coverageWillBeIgnored()) { |
| 92 if (gp.hasVertexCoverage()) { | 106 if (gp.hasVertexCoverage()) { |
| 93 fs->codeAppendf("float alpha = 1.0;"); | 107 fs->codeAppendf("float alpha = 1.0;"); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 192 , fInLocalCoords(NULL) | 206 , fInLocalCoords(NULL) |
| 193 , fInCoverage(NULL) | 207 , fInCoverage(NULL) |
| 194 , fColor(color) | 208 , fColor(color) |
| 195 , fViewMatrix(viewMatrix) | 209 , fViewMatrix(viewMatrix) |
| 196 , fLocalMatrix(localMatrix) | 210 , fLocalMatrix(localMatrix) |
| 197 , fCoverage(coverage) | 211 , fCoverage(coverage) |
| 198 , fFlags(gpTypeFlags) | 212 , fFlags(gpTypeFlags) |
| 199 , fLocalCoordsWillBeRead(localCoordsWillBeRead) | 213 , fLocalCoordsWillBeRead(localCoordsWillBeRead) |
| 200 , fCoverageWillBeIgnored(coverageWillBeIgnored) { | 214 , fCoverageWillBeIgnored(coverageWillBeIgnored) { |
| 201 this->initClassID<DefaultGeoProc>(); | 215 this->initClassID<DefaultGeoProc>(); |
| 202 bool hasColor = SkToBool(gpTypeFlags & GrDefaultGeoProcFactory::kColor_G PType); | 216 bool hasColor = SkToBool(gpTypeFlags & kColor_GPType); |
| 203 bool hasLocalCoord = SkToBool(gpTypeFlags & GrDefaultGeoProcFactory::kLo calCoord_GPType); | 217 bool hasExplicitLocalCoords = SkToBool(gpTypeFlags & kLocalCoord_GPType) ; |
| 204 bool hasCoverage = SkToBool(gpTypeFlags & GrDefaultGeoProcFactory::kCove rage_GPType); | 218 bool hasTransformedLocalCoords = SkToBool(gpTypeFlags & kTransformedLoca lCoord_GPType); |
| 219 bool hasLocalCoord = hasExplicitLocalCoords || hasTransformedLocalCoords ; | |
| 220 bool hasCoverage = SkToBool(gpTypeFlags & kCoverage_GPType); | |
| 205 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVe rtexAttribType, | 221 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVe rtexAttribType, |
| 206 kHigh_GrSLPrecision)); | 222 kHigh_GrSLPrecision)); |
| 207 if (hasColor) { | 223 if (hasColor) { |
| 208 fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVer texAttribType)); | 224 fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVer texAttribType)); |
| 209 } | 225 } |
| 210 if (hasLocalCoord) { | 226 if (hasLocalCoord) { |
| 211 fInLocalCoords = &this->addVertexAttrib(Attribute("inLocalCoord", | 227 fInLocalCoords = &this->addVertexAttrib(Attribute("inLocalCoord", |
| 212 kVec2f_GrVertexAtt ribType)); | 228 kVec2f_GrVertexAtt ribType)); |
| 213 this->setHasLocalCoords(); | 229 if (hasExplicitLocalCoords) { |
| 230 this->setHasExplicitLocalCoords(); | |
| 231 } else { | |
| 232 SkASSERT(hasTransformedLocalCoords); | |
| 233 this->setHasTransformedLocalCoords(); | |
| 234 } | |
| 214 } | 235 } |
| 215 if (hasCoverage) { | 236 if (hasCoverage) { |
| 216 fInCoverage = &this->addVertexAttrib(Attribute("inCoverage", | 237 fInCoverage = &this->addVertexAttrib(Attribute("inCoverage", |
| 217 kFloat_GrVertexAttrib Type)); | 238 kFloat_GrVertexAttrib Type)); |
| 218 } | 239 } |
| 219 } | 240 } |
| 220 | 241 |
| 221 const Attribute* fInPosition; | 242 const Attribute* fInPosition; |
| 222 const Attribute* fInColor; | 243 const Attribute* fInColor; |
| 223 const Attribute* fInLocalCoords; | 244 const Attribute* fInLocalCoords; |
| 224 const Attribute* fInCoverage; | 245 const Attribute* fInCoverage; |
| 225 GrColor fColor; | 246 GrColor fColor; |
| 226 SkMatrix fViewMatrix; | 247 SkMatrix fViewMatrix; |
| 227 SkMatrix fLocalMatrix; | 248 SkMatrix fLocalMatrix; |
| 228 uint8_t fCoverage; | 249 uint8_t fCoverage; |
| 229 uint32_t fFlags; | 250 uint32_t fFlags; |
| 230 bool fLocalCoordsWillBeRead; | 251 bool fLocalCoordsWillBeRead; |
| 231 bool fCoverageWillBeIgnored; | 252 bool fCoverageWillBeIgnored; |
| 232 | 253 |
| 233 GR_DECLARE_GEOMETRY_PROCESSOR_TEST; | 254 GR_DECLARE_GEOMETRY_PROCESSOR_TEST; |
| 234 | 255 |
| 235 typedef GrGeometryProcessor INHERITED; | 256 typedef GrGeometryProcessor INHERITED; |
| 236 }; | 257 }; |
| 237 | 258 |
| 238 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(DefaultGeoProc); | 259 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(DefaultGeoProc); |
| 239 | 260 |
| 240 GrGeometryProcessor* DefaultGeoProc::TestCreate(GrProcessorTestData* d) { | 261 GrGeometryProcessor* DefaultGeoProc::TestCreate(GrProcessorTestData* d) { |
| 241 uint32_t flags = 0; | 262 uint32_t flags = 0; |
| 242 if (d->fRandom->nextBool()) { | 263 if (d->fRandom->nextBool()) { |
| 243 flags |= GrDefaultGeoProcFactory::kColor_GPType; | 264 flags |= kColor_GPType; |
| 244 } | 265 } |
| 245 if (d->fRandom->nextBool()) { | 266 if (d->fRandom->nextBool()) { |
| 246 flags |= GrDefaultGeoProcFactory::kCoverage_GPType; | 267 flags |= kCoverage_GPType; |
| 247 } | 268 } |
| 248 if (d->fRandom->nextBool()) { | 269 if (d->fRandom->nextBool()) { |
| 249 flags |= GrDefaultGeoProcFactory::kLocalCoord_GPType; | 270 flags |= kLocalCoord_GPType; |
| 271 } | |
| 272 if (d->fRandom->nextBool()) { | |
| 273 flags |= kTransformedLocalCoord_GPType; | |
| 250 } | 274 } |
| 251 | 275 |
| 252 return DefaultGeoProc::Create(flags, | 276 return DefaultGeoProc::Create(flags, |
| 253 GrRandomColor(d->fRandom), | 277 GrRandomColor(d->fRandom), |
| 254 GrTest::TestMatrix(d->fRandom), | 278 GrTest::TestMatrix(d->fRandom), |
| 255 GrTest::TestMatrix(d->fRandom), | 279 GrTest::TestMatrix(d->fRandom), |
| 256 d->fRandom->nextBool(), | 280 d->fRandom->nextBool(), |
| 257 d->fRandom->nextBool(), | 281 d->fRandom->nextBool(), |
| 258 GrRandomCoverage(d->fRandom)); | 282 GrRandomCoverage(d->fRandom)); |
| 259 } | 283 } |
| 260 | 284 |
| 261 const GrGeometryProcessor* GrDefaultGeoProcFactory::Create(const Color& color, | 285 const GrGeometryProcessor* GrDefaultGeoProcFactory::Create(const Color& color, |
| 262 const Coverage& cover age, | 286 const Coverage& cover age, |
| 263 const LocalCoords& lo calCoords, | 287 const LocalCoords& lo calCoords, |
| 264 const SkMatrix& viewM atrix) { | 288 const SkMatrix& viewM atrix) { |
| 265 uint32_t flags = 0; | 289 uint32_t flags = 0; |
| 266 flags |= color.fType == Color::kAttribute_Type ? kColor_GPType : 0; | 290 flags |= color.fType == Color::kAttribute_Type ? kColor_GPType : 0; |
| 267 flags |= coverage.fType == Coverage::kAttribute_Type ? kCoverage_GPType : 0; | 291 flags |= coverage.fType == Coverage::kAttribute_Type ? kCoverage_GPType : 0; |
| 268 flags |= localCoords.fType == LocalCoords::kHasExplicit_Type ? kLocalCoord_G PType : 0; | 292 flags |= localCoords.fType == LocalCoords::kHasExplicit_Type ? kLocalCoord_G PType : 0; |
| 293 flags |= localCoords.fType == LocalCoords::kHasTransformed_Type ? | |
| 294 kTransformedLocalCoord_GPType : 0; | |
| 269 | 295 |
| 270 uint8_t inCoverage = coverage.fCoverage; | 296 uint8_t inCoverage = coverage.fCoverage; |
| 271 bool coverageWillBeIgnored = coverage.fType == Coverage::kNone_Type; | 297 bool coverageWillBeIgnored = coverage.fType == Coverage::kNone_Type; |
| 272 bool localCoordsWillBeRead = localCoords.fType != LocalCoords::kUnused_Type; | 298 bool localCoordsWillBeRead = localCoords.fType != LocalCoords::kUnused_Type; |
| 273 | 299 |
| 274 GrColor inColor = color.fColor; | 300 GrColor inColor = color.fColor; |
| 275 return DefaultGeoProc::Create(flags, | 301 return DefaultGeoProc::Create(flags, |
| 276 inColor, | 302 inColor, |
| 277 viewMatrix, | 303 viewMatrix, |
| 278 localCoords.fMatrix ? *localCoords.fMatrix : S kMatrix::I(), | 304 localCoords.fMatrix ? *localCoords.fMatrix : S kMatrix::I(), |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 295 } | 321 } |
| 296 | 322 |
| 297 if (localCoords.hasLocalMatrix()) { | 323 if (localCoords.hasLocalMatrix()) { |
| 298 invert.preConcat(*localCoords.fMatrix); | 324 invert.preConcat(*localCoords.fMatrix); |
| 299 } | 325 } |
| 300 } | 326 } |
| 301 | 327 |
| 302 LocalCoords inverted(LocalCoords::kUsePosition_Type, &invert); | 328 LocalCoords inverted(LocalCoords::kUsePosition_Type, &invert); |
| 303 return Create(color, coverage, inverted, SkMatrix::I()); | 329 return Create(color, coverage, inverted, SkMatrix::I()); |
| 304 } | 330 } |
| OLD | NEW |