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