Index: src/gpu/effects/GrDistanceFieldGeoProc.cpp |
diff --git a/src/gpu/effects/GrDistanceFieldGeoProc.cpp b/src/gpu/effects/GrDistanceFieldGeoProc.cpp |
index ba42bb44f1a4d2db1a1c1030b34ea0bb78349658..09228e505a8715ad468cf3f325d295a8ddc4959e 100755 |
--- a/src/gpu/effects/GrDistanceFieldGeoProc.cpp |
+++ b/src/gpu/effects/GrDistanceFieldGeoProc.cpp |
@@ -21,12 +21,6 @@ |
// Assuming a radius of a little less than the diagonal of the fragment |
#define SK_DistanceFieldAAFactor "0.65" |
-struct DistanceFieldBatchTracker { |
- GrGPInput fInputColorType; |
- GrColor fColor; |
- bool fUsesLocalCoords; |
-}; |
- |
class GrGLDistanceFieldA8TextGeoProc : public GrGLGeometryProcessor { |
public: |
GrGLDistanceFieldA8TextGeoProc(const GrGeometryProcessor&, |
@@ -40,7 +34,6 @@ public: |
void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ |
const GrDistanceFieldA8TextGeoProc& dfTexEffect = |
args.fGP.cast<GrDistanceFieldA8TextGeoProc>(); |
- const DistanceFieldBatchTracker& local = args.fBT.cast<DistanceFieldBatchTracker>(); |
GrGLGPBuilder* pb = args.fPB; |
GrGLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); |
SkAssertResult(fsBuilder->enableFeature( |
@@ -61,8 +54,13 @@ public: |
#endif |
// Setup pass through color |
- this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor, |
- dfTexEffect.inColor(), &fColorUniform); |
+ if (!dfTexEffect.colorIgnored()) { |
+ if (dfTexEffect.hasVertexColor()) { |
+ pb->addPassThroughAttribute(dfTexEffect.inColor(), args.fOutputColor); |
+ } else { |
+ this->setupUniformColor(pb, args.fOutputColor, &fColorUniform); |
+ } |
+ } |
// Setup position |
this->setupPosition(pb, gpArgs, dfTexEffect.inPosition()->fName, dfTexEffect.viewMatrix()); |
@@ -154,12 +152,11 @@ public: |
const GrDistanceFieldA8TextGeoProc& dfa8gp = proc.cast<GrDistanceFieldA8TextGeoProc>(); |
this->setUniformViewMatrix(pdman, dfa8gp.viewMatrix()); |
- const DistanceFieldBatchTracker& local = bt.cast<DistanceFieldBatchTracker>(); |
- if (kUniform_GrGPInput == local.fInputColorType && local.fColor != fColor) { |
+ if (dfa8gp.color() != fColor && !dfa8gp.hasVertexColor()) { |
GrGLfloat c[4]; |
- GrColorToRGBAFloat(local.fColor, c); |
+ GrColorToRGBAFloat(dfa8gp.color(), c); |
pdman.set4fv(fColorUniform, 1, c); |
- fColor = local.fColor; |
+ fColor = dfa8gp.color(); |
} |
} |
@@ -168,9 +165,9 @@ public: |
const GrGLSLCaps&, |
GrProcessorKeyBuilder* b) { |
const GrDistanceFieldA8TextGeoProc& dfTexEffect = gp.cast<GrDistanceFieldA8TextGeoProc>(); |
- const DistanceFieldBatchTracker& local = bt.cast<DistanceFieldBatchTracker>(); |
uint32_t key = dfTexEffect.getFlags(); |
- key |= local.fInputColorType << 16; |
+ key |= dfTexEffect.hasVertexColor() << 16; |
+ key |= dfTexEffect.colorIgnored() << 17; |
key |= ComputePosKey(dfTexEffect.viewMatrix()) << 25; |
b->add32(key); |
} |
@@ -195,7 +192,8 @@ GrDistanceFieldA8TextGeoProc::GrDistanceFieldA8TextGeoProc(GrColor color, |
#ifdef SK_GAMMA_APPLY_TO_A8 |
float distanceAdjust, |
#endif |
- uint32_t flags) |
+ uint32_t flags, |
+ bool usesLocalCoords) |
: fColor(color) |
, fViewMatrix(viewMatrix) |
, fTextureAccess(texture, params) |
@@ -203,7 +201,8 @@ GrDistanceFieldA8TextGeoProc::GrDistanceFieldA8TextGeoProc(GrColor color, |
, fDistanceAdjust(distanceAdjust) |
#endif |
, fFlags(flags & kNonLCD_DistanceFieldEffectMask) |
- , fInColor(NULL) { |
+ , fInColor(NULL) |
+ , fUsesLocalCoords(usesLocalCoords) { |
SkASSERT(!(flags & ~kNonLCD_DistanceFieldEffectMask)); |
this->initClassID<GrDistanceFieldA8TextGeoProc>(); |
fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertexAttribType)); |
@@ -227,14 +226,6 @@ GrDistanceFieldA8TextGeoProc::createGLInstance(const GrBatchTracker& bt, |
return SkNEW_ARGS(GrGLDistanceFieldA8TextGeoProc, (*this, bt)); |
} |
-void GrDistanceFieldA8TextGeoProc::initBatchTracker(GrBatchTracker* bt, |
- const GrPipelineInfo& init) const { |
- DistanceFieldBatchTracker* local = bt->cast<DistanceFieldBatchTracker>(); |
- local->fInputColorType = GetColorInputType(&local->fColor, this->color(), init, |
- SkToBool(fInColor)); |
- local->fUsesLocalCoords = init.fUsesLocalCoords; |
-} |
- |
/////////////////////////////////////////////////////////////////////////////// |
GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrDistanceFieldA8TextGeoProc); |
@@ -264,17 +255,12 @@ GrGeometryProcessor* GrDistanceFieldA8TextGeoProc::TestCreate(SkRandom* random, |
random->nextF(), |
#endif |
random->nextBool() ? |
- kSimilarity_DistanceFieldEffectFlag : 0); |
+ kSimilarity_DistanceFieldEffectFlag : 0, |
+ random->nextBool()); |
} |
/////////////////////////////////////////////////////////////////////////////// |
-struct DistanceFieldPathBatchTracker { |
- GrGPInput fInputColorType; |
- GrColor fColor; |
- bool fUsesLocalCoords; |
-}; |
- |
class GrGLDistanceFieldPathGeoProc : public GrGLGeometryProcessor { |
public: |
GrGLDistanceFieldPathGeoProc(const GrGeometryProcessor&, |
@@ -284,7 +270,6 @@ public: |
void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ |
const GrDistanceFieldPathGeoProc& dfTexEffect = args.fGP.cast<GrDistanceFieldPathGeoProc>(); |
- const DistanceFieldPathBatchTracker& local = args.fBT.cast<DistanceFieldPathBatchTracker>(); |
GrGLGPBuilder* pb = args.fPB; |
GrGLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); |
SkAssertResult(fsBuilder->enableFeature( |
@@ -299,9 +284,13 @@ public: |
args.fPB->addVarying("TextureCoords", &v, kHigh_GrSLPrecision); |
// setup pass through color |
- this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor, |
- dfTexEffect.inColor(), &fColorUniform); |
- |
+ if (!dfTexEffect.colorIgnored()) { |
+ if (dfTexEffect.hasVertexColor()) { |
+ pb->addPassThroughAttribute(dfTexEffect.inColor(), args.fOutputColor); |
+ } else { |
+ this->setupUniformColor(pb, args.fOutputColor, &fColorUniform); |
+ } |
+ } |
vsBuilder->codeAppendf("%s = %s;", v.vsOut(), dfTexEffect.inTextureCoords()->fName); |
// Setup position |
@@ -384,12 +373,11 @@ public: |
const GrDistanceFieldPathGeoProc& dfpgp = proc.cast<GrDistanceFieldPathGeoProc>(); |
this->setUniformViewMatrix(pdman, dfpgp.viewMatrix()); |
- const DistanceFieldPathBatchTracker& local = bt.cast<DistanceFieldPathBatchTracker>(); |
- if (kUniform_GrGPInput == local.fInputColorType && local.fColor != fColor) { |
+ if (dfpgp.color() != fColor) { |
GrGLfloat c[4]; |
- GrColorToRGBAFloat(local.fColor, c); |
+ GrColorToRGBAFloat(dfpgp.color(), c); |
pdman.set4fv(fColorUniform, 1, c); |
- fColor = local.fColor; |
+ fColor = dfpgp.color(); |
} |
} |
@@ -399,9 +387,9 @@ public: |
GrProcessorKeyBuilder* b) { |
const GrDistanceFieldPathGeoProc& dfTexEffect = gp.cast<GrDistanceFieldPathGeoProc>(); |
- const DistanceFieldPathBatchTracker& local = bt.cast<DistanceFieldPathBatchTracker>(); |
uint32_t key = dfTexEffect.getFlags(); |
- key |= local.fInputColorType << 16; |
+ key |= dfTexEffect.colorIgnored() << 16; |
+ key |= dfTexEffect.hasVertexColor() << 17; |
key |= ComputePosKey(dfTexEffect.viewMatrix()) << 25; |
b->add32(key); |
} |
@@ -422,12 +410,14 @@ GrDistanceFieldPathGeoProc::GrDistanceFieldPathGeoProc( |
const SkMatrix& viewMatrix, |
GrTexture* texture, |
const GrTextureParams& params, |
- uint32_t flags) |
+ uint32_t flags, |
+ bool usesLocalCoords) |
: fColor(color) |
, fViewMatrix(viewMatrix) |
, fTextureAccess(texture, params) |
, fFlags(flags & kNonLCD_DistanceFieldEffectMask) |
- , fInColor(NULL) { |
+ , fInColor(NULL) |
+ , fUsesLocalCoords(usesLocalCoords) { |
SkASSERT(!(flags & ~kNonLCD_DistanceFieldEffectMask)); |
this->initClassID<GrDistanceFieldPathGeoProc>(); |
fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertexAttribType)); |
@@ -435,7 +425,7 @@ GrDistanceFieldPathGeoProc::GrDistanceFieldPathGeoProc( |
fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVertexAttribType)); |
} |
fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords", |
- kVec2f_GrVertexAttribType)); |
+ kVec2f_GrVertexAttribType)); |
this->addTextureAccess(&fTextureAccess); |
} |
@@ -450,14 +440,6 @@ GrDistanceFieldPathGeoProc::createGLInstance(const GrBatchTracker& bt, const GrG |
return SkNEW_ARGS(GrGLDistanceFieldPathGeoProc, (*this, bt)); |
} |
-void GrDistanceFieldPathGeoProc::initBatchTracker(GrBatchTracker* bt, |
- const GrPipelineInfo& init) const { |
- DistanceFieldPathBatchTracker* local = bt->cast<DistanceFieldPathBatchTracker>(); |
- local->fInputColorType = GetColorInputType(&local->fColor, this->color(), init, |
- SkToBool(fInColor)); |
- local->fUsesLocalCoords = init.fUsesLocalCoords; |
-} |
- |
/////////////////////////////////////////////////////////////////////////////// |
GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrDistanceFieldPathGeoProc); |
@@ -484,17 +466,13 @@ GrGeometryProcessor* GrDistanceFieldPathGeoProc::TestCreate(SkRandom* random, |
GrTest::TestMatrix(random), |
textures[texIdx], |
params, |
- random->nextBool() ? kSimilarity_DistanceFieldEffectFlag : 0); |
+ random->nextBool() ? |
+ kSimilarity_DistanceFieldEffectFlag : 0, |
+ random->nextBool()); |
} |
/////////////////////////////////////////////////////////////////////////////// |
-struct DistanceFieldLCDBatchTracker { |
- GrGPInput fInputColorType; |
- GrColor fColor; |
- bool fUsesLocalCoords; |
-}; |
- |
class GrGLDistanceFieldLCDTextGeoProc : public GrGLGeometryProcessor { |
public: |
GrGLDistanceFieldLCDTextGeoProc(const GrGeometryProcessor&, const GrBatchTracker&) |
@@ -505,7 +483,6 @@ public: |
void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ |
const GrDistanceFieldLCDTextGeoProc& dfTexEffect = |
args.fGP.cast<GrDistanceFieldLCDTextGeoProc>(); |
- const DistanceFieldLCDBatchTracker& local = args.fBT.cast<DistanceFieldLCDBatchTracker>(); |
GrGLGPBuilder* pb = args.fPB; |
GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); |
@@ -514,8 +491,9 @@ public: |
vsBuilder->emitAttributes(dfTexEffect); |
// setup pass through color |
- this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor, NULL, |
- &fColorUniform); |
+ if (!dfTexEffect.colorIgnored()) { |
+ this->setupUniformColor(pb, args.fOutputColor, &fColorUniform); |
+ } |
// Setup position |
this->setupPosition(pb, gpArgs, dfTexEffect.inPosition()->fName, dfTexEffect.viewMatrix()); |
@@ -652,12 +630,11 @@ public: |
this->setUniformViewMatrix(pdman, dfTexEffect.viewMatrix()); |
- const DistanceFieldLCDBatchTracker& local = bt.cast<DistanceFieldLCDBatchTracker>(); |
- if (kUniform_GrGPInput == local.fInputColorType && local.fColor != fColor) { |
+ if (dfTexEffect.color() != fColor) { |
GrGLfloat c[4]; |
- GrColorToRGBAFloat(local.fColor, c); |
+ GrColorToRGBAFloat(dfTexEffect.color(), c); |
pdman.set4fv(fColorUniform, 1, c); |
- fColor = local.fColor; |
+ fColor = dfTexEffect.color(); |
} |
} |
@@ -667,9 +644,8 @@ public: |
GrProcessorKeyBuilder* b) { |
const GrDistanceFieldLCDTextGeoProc& dfTexEffect = gp.cast<GrDistanceFieldLCDTextGeoProc>(); |
- const DistanceFieldLCDBatchTracker& local = bt.cast<DistanceFieldLCDBatchTracker>(); |
uint32_t key = dfTexEffect.getFlags(); |
- key |= local.fInputColorType << 16; |
+ key |= dfTexEffect.colorIgnored() << 16; |
key |= ComputePosKey(dfTexEffect.viewMatrix()) << 25; |
b->add32(key); |
} |
@@ -689,17 +665,18 @@ GrDistanceFieldLCDTextGeoProc::GrDistanceFieldLCDTextGeoProc( |
GrColor color, const SkMatrix& viewMatrix, |
GrTexture* texture, const GrTextureParams& params, |
DistanceAdjust distanceAdjust, |
- uint32_t flags) |
+ uint32_t flags, bool usesLocalCoords) |
: fColor(color) |
, fViewMatrix(viewMatrix) |
, fTextureAccess(texture, params) |
, fDistanceAdjust(distanceAdjust) |
- , fFlags(flags & kLCD_DistanceFieldEffectMask){ |
+ , fFlags(flags & kLCD_DistanceFieldEffectMask) |
+ , fUsesLocalCoords(usesLocalCoords) { |
SkASSERT(!(flags & ~kLCD_DistanceFieldEffectMask) && (flags & kUseLCD_DistanceFieldEffectFlag)); |
this->initClassID<GrDistanceFieldLCDTextGeoProc>(); |
fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertexAttribType)); |
fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords", |
- kVec2s_GrVertexAttribType)); |
+ kVec2s_GrVertexAttribType)); |
this->addTextureAccess(&fTextureAccess); |
} |
@@ -715,13 +692,6 @@ GrDistanceFieldLCDTextGeoProc::createGLInstance(const GrBatchTracker& bt, |
return SkNEW_ARGS(GrGLDistanceFieldLCDTextGeoProc, (*this, bt)); |
} |
-void GrDistanceFieldLCDTextGeoProc::initBatchTracker(GrBatchTracker* bt, |
- const GrPipelineInfo& init) const { |
- DistanceFieldLCDBatchTracker* local = bt->cast<DistanceFieldLCDBatchTracker>(); |
- local->fInputColorType = GetColorInputType(&local->fColor, this->color(), init, false); |
- local->fUsesLocalCoords = init.fUsesLocalCoords; |
-} |
- |
/////////////////////////////////////////////////////////////////////////////// |
GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrDistanceFieldLCDTextGeoProc); |
@@ -751,5 +721,6 @@ GrGeometryProcessor* GrDistanceFieldLCDTextGeoProc::TestCreate(SkRandom* random, |
GrTest::TestMatrix(random), |
textures[texIdx], params, |
wa, |
- flags); |
+ flags, |
+ random->nextBool()); |
} |