Index: src/gpu/GrDefaultGeoProcFactory.cpp |
diff --git a/src/gpu/GrDefaultGeoProcFactory.cpp b/src/gpu/GrDefaultGeoProcFactory.cpp |
index 55b3a1f9ef4853e4627c1b98750234a26f9d18cf..6dbf71e0d89930fff7f1969d82a1a335412f36b4 100644 |
--- a/src/gpu/GrDefaultGeoProcFactory.cpp |
+++ b/src/gpu/GrDefaultGeoProcFactory.cpp |
@@ -24,16 +24,12 @@ |
GrColor color, |
const SkMatrix& viewMatrix, |
const SkMatrix& localMatrix, |
- bool usesLocalCoords, |
- bool coverageIgnored, |
uint8_t coverage) { |
return SkNEW_ARGS(DefaultGeoProc, (gpTypeFlags, |
color, |
viewMatrix, |
localMatrix, |
- coverage, |
- usesLocalCoords, |
- coverageIgnored)); |
+ coverage)); |
} |
const char* name() const override { return "DefaultGeometryProcessor"; } |
@@ -43,14 +39,30 @@ |
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; } |
- bool coverageIgnored() const { return fCoverageIgnored; } |
- bool hasVertexCoverage() const { return SkToBool(fInCoverage); } |
+ |
+ 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; |
+ } |
class GLProcessor : public GrGLGeometryProcessor { |
public: |
@@ -62,19 +74,14 @@ |
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 |
- if (!gp.colorIgnored()) { |
- if (gp.hasVertexColor()) { |
- pb->addPassThroughAttribute(gp.inColor(), args.fOutputColor); |
- } else { |
- this->setupUniformColor(pb, args.fOutputColor, &fColorUniform); |
- } |
- } |
- |
+ this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor, gp.inColor(), |
+ &fColorUniform); |
// Setup position |
this->setupPosition(pb, gpArgs, gp.inPosition()->fName, gp.viewMatrix()); |
@@ -89,22 +96,21 @@ |
} |
// Setup coverage as pass through |
- 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); |
- } |
+ 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); |
} |
} |
@@ -113,13 +119,10 @@ |
const GrGLSLCaps&, |
GrProcessorKeyBuilder* b) { |
const DefaultGeoProc& def = gp.cast<DefaultGeoProc>(); |
+ const BatchTracker& local = bt.cast<BatchTracker>(); |
uint32_t key = def.fFlags; |
- 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 |= local.fInputColorType << 8 | local.fInputCoverageType << 16; |
+ key |= local.fUsesLocalCoords && def.localMatrix().hasPerspective() ? 0x1 << 24 : 0x0; |
key |= ComputePosKey(def.viewMatrix()) << 25; |
b->add32(key); |
} |
@@ -130,16 +133,16 @@ |
const DefaultGeoProc& dgp = gp.cast<DefaultGeoProc>(); |
this->setUniformViewMatrix(pdman, dgp.viewMatrix()); |
- if (dgp.color() != fColor && !dgp.hasVertexColor()) { |
+ const BatchTracker& local = bt.cast<BatchTracker>(); |
+ if (kUniform_GrGPInput == local.fInputColorType && local.fColor != fColor) { |
GrGLfloat c[4]; |
- GrColorToRGBAFloat(dgp.color(), c); |
+ GrColorToRGBAFloat(local.fColor, c); |
pdman.set4fv(fColorUniform, 1, c); |
- fColor = dgp.color(); |
- } |
- |
- if (dgp.coverage() != fCoverage && !dgp.hasVertexCoverage()) { |
- pdman.set1f(fCoverageUniform, GrNormalizeByteToFloat(dgp.coverage())); |
- fCoverage = dgp.coverage(); |
+ fColor = local.fColor; |
+ } |
+ if (kUniform_GrGPInput == local.fInputCoverageType && local.fCoverage != fCoverage) { |
+ pdman.set1f(fCoverageUniform, GrNormalizeByteToFloat(local.fCoverage)); |
+ fCoverage = local.fCoverage; |
} |
} |
@@ -175,9 +178,7 @@ |
GrColor color, |
const SkMatrix& viewMatrix, |
const SkMatrix& localMatrix, |
- uint8_t coverage, |
- bool usesLocalCoords, |
- bool coverageIgnored) |
+ uint8_t coverage) |
: fInPosition(NULL) |
, fInColor(NULL) |
, fInLocalCoords(NULL) |
@@ -186,9 +187,7 @@ |
, fViewMatrix(viewMatrix) |
, fLocalMatrix(localMatrix) |
, fCoverage(coverage) |
- , fFlags(gpTypeFlags) |
- , fUsesLocalCoords(usesLocalCoords) |
- , fCoverageIgnored(coverageIgnored) { |
+ , fFlags(gpTypeFlags) { |
this->initClassID<DefaultGeoProc>(); |
bool hasColor = SkToBool(gpTypeFlags & GrDefaultGeoProcFactory::kColor_GPType); |
bool hasLocalCoord = SkToBool(gpTypeFlags & GrDefaultGeoProcFactory::kLocalCoord_GPType); |
@@ -199,7 +198,7 @@ |
} |
if (hasLocalCoord) { |
fInLocalCoords = &this->addVertexAttrib(Attribute("inLocalCoord", |
- kVec2f_GrVertexAttribType)); |
+ kVec2f_GrVertexAttribType)); |
this->setHasLocalCoords(); |
} |
if (hasCoverage) { |
@@ -207,6 +206,14 @@ |
kFloat_GrVertexAttribType)); |
} |
} |
+ |
+ struct BatchTracker { |
+ GrGPInput fInputColorType; |
+ GrGPInput fInputCoverageType; |
+ GrColor fColor; |
+ GrColor fCoverage; |
+ bool fUsesLocalCoords; |
+ }; |
const Attribute* fInPosition; |
const Attribute* fInColor; |
@@ -217,8 +224,6 @@ |
SkMatrix fLocalMatrix; |
uint8_t fCoverage; |
uint32_t fFlags; |
- bool fUsesLocalCoords; |
- bool fCoverageIgnored; |
GR_DECLARE_GEOMETRY_PROCESSOR_TEST; |
@@ -246,15 +251,11 @@ |
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) { |
@@ -262,7 +263,5 @@ |
color, |
viewMatrix, |
localMatrix, |
- usesLocalCoords, |
- coverageIgnored, |
coverage); |
} |