Index: src/gpu/GrDefaultGeoProcFactory.cpp |
diff --git a/src/gpu/GrDefaultGeoProcFactory.cpp b/src/gpu/GrDefaultGeoProcFactory.cpp |
index 6dbf71e0d89930fff7f1969d82a1a335412f36b4..59e9dcda2766b678ec4fa5ba3a69ee0cd8f6a14b 100644 |
--- a/src/gpu/GrDefaultGeoProcFactory.cpp |
+++ b/src/gpu/GrDefaultGeoProcFactory.cpp |
@@ -24,12 +24,16 @@ public: |
GrColor color, |
const SkMatrix& viewMatrix, |
const SkMatrix& localMatrix, |
+ bool usesLocalCoords, |
+ bool coverageIgnored, |
uint8_t coverage) { |
return SkNEW_ARGS(DefaultGeoProc, (gpTypeFlags, |
color, |
viewMatrix, |
localMatrix, |
- coverage)); |
+ coverage, |
+ usesLocalCoords, |
+ coverageIgnored)); |
} |
const char* name() const override { return "DefaultGeometryProcessor"; } |
@@ -39,30 +43,14 @@ public: |
const Attribute* inLocalCoords() const { return fInLocalCoords; } |
const Attribute* inCoverage() const { return fInCoverage; } |
GrColor color() const { return fColor; } |
+ bool colorIgnored() const { return GrColor_ILLEGAL == fColor; } |
+ bool hasVertexColor() const { return SkToBool(fInColor); } |
const SkMatrix& viewMatrix() const { return fViewMatrix; } |
const SkMatrix& localMatrix() const { return fLocalMatrix; } |
+ bool usesLocalCoords() const { return fUsesLocalCoords; } |
uint8_t coverage() const { return fCoverage; } |
- |
- void initBatchTracker(GrBatchTracker* bt, const GrPipelineInfo& init) const override { |
- BatchTracker* local = bt->cast<BatchTracker>(); |
- local->fInputColorType = GetColorInputType(&local->fColor, this->color(), init, |
- SkToBool(fInColor)); |
- |
- bool hasVertexCoverage = SkToBool(fInCoverage) && !init.fCoverageIgnored; |
- bool covIsSolidWhite = !hasVertexCoverage && 0xff == this->coverage(); |
- if (init.fCoverageIgnored) { |
- local->fInputCoverageType = kIgnored_GrGPInput; |
- } else if (covIsSolidWhite) { |
- local->fInputCoverageType = kAllOnes_GrGPInput; |
- } else if (hasVertexCoverage) { |
- SkASSERT(fInCoverage); |
- local->fInputCoverageType = kAttribute_GrGPInput; |
- } else { |
- local->fInputCoverageType = kUniform_GrGPInput; |
- local->fCoverage = this->coverage(); |
- } |
- local->fUsesLocalCoords = init.fUsesLocalCoords; |
- } |
+ bool coverageIgnored() const { return fCoverageIgnored; } |
+ bool hasVertexCoverage() const { return SkToBool(fInCoverage); } |
class GLProcessor : public GrGLGeometryProcessor { |
public: |
@@ -74,14 +62,19 @@ public: |
GrGLGPBuilder* pb = args.fPB; |
GrGLVertexBuilder* vsBuilder = pb->getVertexShaderBuilder(); |
GrGLFragmentBuilder* fs = args.fPB->getFragmentShaderBuilder(); |
- const BatchTracker& local = args.fBT.cast<BatchTracker>(); |
// emit attributes |
vsBuilder->emitAttributes(gp); |
// Setup pass through color |
- this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor, gp.inColor(), |
- &fColorUniform); |
+ if (!gp.colorIgnored()) { |
+ if (gp.hasVertexColor()) { |
+ pb->addPassThroughAttribute(gp.inColor(), args.fOutputColor); |
+ } else { |
+ this->setupUniformColor(pb, args.fOutputColor, &fColorUniform); |
+ } |
+ } |
+ |
// Setup position |
this->setupPosition(pb, gpArgs, gp.inPosition()->fName, gp.viewMatrix()); |
@@ -96,21 +89,22 @@ public: |
} |
// Setup coverage as pass through |
- if (kUniform_GrGPInput == local.fInputCoverageType) { |
- const char* fragCoverage; |
- fCoverageUniform = pb->addUniform(GrGLProgramBuilder::kFragment_Visibility, |
- kFloat_GrSLType, |
- kDefault_GrSLPrecision, |
- "Coverage", |
- &fragCoverage); |
- fs->codeAppendf("%s = vec4(%s);", args.fOutputCoverage, fragCoverage); |
- } else if (kAttribute_GrGPInput == local.fInputCoverageType) { |
- SkASSERT(gp.inCoverage()); |
- fs->codeAppendf("float alpha = 1.0;"); |
- args.fPB->addPassThroughAttribute(gp.inCoverage(), "alpha"); |
- fs->codeAppendf("%s = vec4(alpha);", args.fOutputCoverage); |
- } else if (kAllOnes_GrGPInput == local.fInputCoverageType) { |
- fs->codeAppendf("%s = vec4(1);", args.fOutputCoverage); |
+ if (!gp.coverageIgnored()) { |
+ if (gp.hasVertexCoverage()) { |
+ fs->codeAppendf("float alpha = 1.0;"); |
+ args.fPB->addPassThroughAttribute(gp.inCoverage(), "alpha"); |
+ fs->codeAppendf("%s = vec4(alpha);", args.fOutputCoverage); |
+ } else if (gp.coverage() == 0xff) { |
+ fs->codeAppendf("%s = vec4(1);", args.fOutputCoverage); |
+ } else { |
+ const char* fragCoverage; |
+ fCoverageUniform = pb->addUniform(GrGLProgramBuilder::kFragment_Visibility, |
+ kFloat_GrSLType, |
+ kDefault_GrSLPrecision, |
+ "Coverage", |
+ &fragCoverage); |
+ fs->codeAppendf("%s = vec4(%s);", args.fOutputCoverage, fragCoverage); |
+ } |
} |
} |
@@ -119,10 +113,13 @@ public: |
const GrGLSLCaps&, |
GrProcessorKeyBuilder* b) { |
const DefaultGeoProc& def = gp.cast<DefaultGeoProc>(); |
- const BatchTracker& local = bt.cast<BatchTracker>(); |
uint32_t key = def.fFlags; |
- key |= local.fInputColorType << 8 | local.fInputCoverageType << 16; |
- key |= local.fUsesLocalCoords && def.localMatrix().hasPerspective() ? 0x1 << 24 : 0x0; |
+ key |= def.colorIgnored() << 8; |
+ key |= def.coverageIgnored() << 9; |
+ key |= def.hasVertexColor() << 10; |
+ key |= def.hasVertexCoverage() << 11; |
+ key |= def.coverage() == 0xff ? 0x1 << 12 : 0; |
+ key |= def.usesLocalCoords() && def.localMatrix().hasPerspective() ? 0x1 << 24 : 0x0; |
key |= ComputePosKey(def.viewMatrix()) << 25; |
b->add32(key); |
} |
@@ -133,16 +130,16 @@ public: |
const DefaultGeoProc& dgp = gp.cast<DefaultGeoProc>(); |
this->setUniformViewMatrix(pdman, dgp.viewMatrix()); |
- const BatchTracker& local = bt.cast<BatchTracker>(); |
- if (kUniform_GrGPInput == local.fInputColorType && local.fColor != fColor) { |
+ if (dgp.color() != fColor && !dgp.hasVertexColor()) { |
GrGLfloat c[4]; |
- GrColorToRGBAFloat(local.fColor, c); |
+ GrColorToRGBAFloat(dgp.color(), c); |
pdman.set4fv(fColorUniform, 1, c); |
- fColor = local.fColor; |
+ fColor = dgp.color(); |
} |
- if (kUniform_GrGPInput == local.fInputCoverageType && local.fCoverage != fCoverage) { |
- pdman.set1f(fCoverageUniform, GrNormalizeByteToFloat(local.fCoverage)); |
- fCoverage = local.fCoverage; |
+ |
+ if (!dgp.coverageIgnored() && dgp.coverage() != fCoverage && !dgp.hasVertexCoverage()) { |
+ pdman.set1f(fCoverageUniform, GrNormalizeByteToFloat(dgp.coverage())); |
+ fCoverage = dgp.coverage(); |
} |
} |
@@ -178,7 +175,9 @@ private: |
GrColor color, |
const SkMatrix& viewMatrix, |
const SkMatrix& localMatrix, |
- uint8_t coverage) |
+ uint8_t coverage, |
+ bool usesLocalCoords, |
+ bool coverageIgnored) |
: fInPosition(NULL) |
, fInColor(NULL) |
, fInLocalCoords(NULL) |
@@ -187,7 +186,9 @@ private: |
, fViewMatrix(viewMatrix) |
, fLocalMatrix(localMatrix) |
, fCoverage(coverage) |
- , fFlags(gpTypeFlags) { |
+ , fFlags(gpTypeFlags) |
+ , fUsesLocalCoords(usesLocalCoords) |
+ , fCoverageIgnored(coverageIgnored) { |
this->initClassID<DefaultGeoProc>(); |
bool hasColor = SkToBool(gpTypeFlags & GrDefaultGeoProcFactory::kColor_GPType); |
bool hasLocalCoord = SkToBool(gpTypeFlags & GrDefaultGeoProcFactory::kLocalCoord_GPType); |
@@ -198,7 +199,7 @@ private: |
} |
if (hasLocalCoord) { |
fInLocalCoords = &this->addVertexAttrib(Attribute("inLocalCoord", |
- kVec2f_GrVertexAttribType)); |
+ kVec2f_GrVertexAttribType)); |
this->setHasLocalCoords(); |
} |
if (hasCoverage) { |
@@ -207,14 +208,6 @@ private: |
} |
} |
- struct BatchTracker { |
- GrGPInput fInputColorType; |
- GrGPInput fInputCoverageType; |
- GrColor fColor; |
- GrColor fCoverage; |
- bool fUsesLocalCoords; |
- }; |
- |
const Attribute* fInPosition; |
const Attribute* fInColor; |
const Attribute* fInLocalCoords; |
@@ -224,6 +217,8 @@ private: |
SkMatrix fLocalMatrix; |
uint8_t fCoverage; |
uint32_t fFlags; |
+ bool fUsesLocalCoords; |
+ bool fCoverageIgnored; |
GR_DECLARE_GEOMETRY_PROCESSOR_TEST; |
@@ -251,11 +246,15 @@ GrGeometryProcessor* DefaultGeoProc::TestCreate(SkRandom* random, |
GrRandomColor(random), |
GrTest::TestMatrix(random), |
GrTest::TestMatrix(random), |
+ random->nextBool(), |
+ random->nextBool(), |
GrRandomCoverage(random)); |
} |
const GrGeometryProcessor* GrDefaultGeoProcFactory::Create(uint32_t gpTypeFlags, |
GrColor color, |
+ bool usesLocalCoords, |
+ bool coverageIgnored, |
const SkMatrix& viewMatrix, |
const SkMatrix& localMatrix, |
uint8_t coverage) { |
@@ -263,5 +262,7 @@ const GrGeometryProcessor* GrDefaultGeoProcFactory::Create(uint32_t gpTypeFlags, |
color, |
viewMatrix, |
localMatrix, |
+ usesLocalCoords, |
+ coverageIgnored, |
coverage); |
} |