Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(286)

Unified Diff: src/gpu/effects/GrDistanceFieldTextureEffect.cpp

Issue 424103002: Add effect caching to distance field text. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Rebase to ToT Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/gpu/effects/GrDistanceFieldTextureEffect.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/effects/GrDistanceFieldTextureEffect.cpp
diff --git a/src/gpu/effects/GrDistanceFieldTextureEffect.cpp b/src/gpu/effects/GrDistanceFieldTextureEffect.cpp
index 510142e8fe1fb78d854c283b038a076d865af4b9..7ef1cbb2ba3c64719a045d27d0ae145897488953 100755
--- a/src/gpu/effects/GrDistanceFieldTextureEffect.cpp
+++ b/src/gpu/effects/GrDistanceFieldTextureEffect.cpp
@@ -79,7 +79,7 @@ public:
builder->fsCodeAppendf("\tvec2 uv = %s;\n", fsCoordName.c_str());
builder->fsCodeAppendf("\tvec2 st = uv*%s;\n", textureSizeUniName);
builder->fsCodeAppend("\tfloat afwidth;\n");
- if (dfTexEffect.isSimilarity()) {
+ if (dfTexEffect.getFlags() & kSimilarity_DistanceFieldEffectFlag) {
// this gives us a smooth step across approximately one fragment
builder->fsCodeAppend("\tafwidth = " SK_DistanceFieldAAFactor "*dFdx(st.x);\n");
} else {
@@ -153,7 +153,7 @@ public:
const GrDistanceFieldTextureEffect& dfTexEffect =
drawEffect.castEffect<GrDistanceFieldTextureEffect>();
- b->add32(dfTexEffect.isSimilarity());
+ b->add32(dfTexEffect.getFlags());
}
private:
@@ -174,13 +174,14 @@ GrDistanceFieldTextureEffect::GrDistanceFieldTextureEffect(GrTexture* texture,
const GrTextureParams& gammaParams,
float luminance,
#endif
- bool similarity)
+ uint32_t flags)
: fTextureAccess(texture, params)
#ifdef SK_GAMMA_APPLY_TO_A8
, fGammaTextureAccess(gamma, gammaParams)
, fLuminance(luminance)
#endif
- , fIsSimilarity(similarity) {
+ , fFlags(flags & kNonLCD_DistanceFieldEffectMask) {
+ SkASSERT(!(flags & ~kNonLCD_DistanceFieldEffectMask));
this->addTextureAccess(&fTextureAccess);
#ifdef SK_GAMMA_APPLY_TO_A8
this->addTextureAccess(&fGammaTextureAccess);
@@ -190,7 +191,12 @@ GrDistanceFieldTextureEffect::GrDistanceFieldTextureEffect(GrTexture* texture,
bool GrDistanceFieldTextureEffect::onIsEqual(const GrEffect& other) const {
const GrDistanceFieldTextureEffect& cte = CastEffect<GrDistanceFieldTextureEffect>(other);
- return fTextureAccess == cte.fTextureAccess;
+ return fTextureAccess == cte.fTextureAccess &&
+#ifdef SK_GAMMA_APPLY_TO_A8
+ fGammaTextureAccess == cte.fGammaTextureAccess &&
+ fLuminance == cte.fLuminance &&
+#endif
+ fFlags == cte.fFlags;
}
void GrDistanceFieldTextureEffect::getConstantColorComponents(GrColor* color,
@@ -242,7 +248,8 @@ GrEffect* GrDistanceFieldTextureEffect::TestCreate(SkRandom* random,
textures[texIdx2], params2,
random->nextF(),
#endif
- random->nextBool());
+ random->nextBool() ?
+ kSimilarity_DistanceFieldEffectFlag : 0);
}
///////////////////////////////////////////////////////////////////////////////
@@ -286,7 +293,8 @@ public:
// create LCD offset adjusted by inverse of transform
builder->fsCodeAppendf("\tvec2 uv = %s;\n", fsCoordName.c_str());
builder->fsCodeAppendf("\tvec2 st = uv*%s.xy;\n", textureSizeUniName);
- if (dfTexEffect.isUniformScale()) {
+ bool isUniformScale = !!(dfTexEffect.getFlags() & kUniformScale_DistanceFieldEffectMask);
+ if (isUniformScale) {
builder->fsCodeAppend("\tfloat dx = dFdx(st.x);\n");
builder->fsCodeAppendf("\tvec2 offset = vec2(dx*%s.z, 0.0);\n", textureSizeUniName);
} else {
@@ -327,7 +335,7 @@ public:
// transformations, and even then using a single factor seems like a reasonable
// trade-off between quality and speed.
builder->fsCodeAppend("\tfloat afwidth;\n");
- if (dfTexEffect.isUniformScale()) {
+ if (isUniformScale) {
// this gives us a smooth step across approximately one fragment
builder->fsCodeAppend("\tafwidth = " SK_DistanceFieldAAFactor "*dx;\n");
} else {
@@ -393,7 +401,7 @@ public:
texture->height() != fTextureSize.height()) {
fTextureSize = SkISize::Make(texture->width(), texture->height());
float delta = 1.0f/(3.0f*texture->width());
- if (dfTexEffect.useBGR()) {
+ if (dfTexEffect.getFlags() & kBGR_DistanceFieldEffectFlag) {
delta = -delta;
}
pdman.set3f(fTextureSizeUni,
@@ -418,7 +426,7 @@ public:
const GrDistanceFieldLCDTextureEffect& dfTexEffect =
drawEffect.castEffect<GrDistanceFieldLCDTextureEffect>();
- b->add32(dfTexEffect.isUniformScale());
+ b->add32(dfTexEffect.getFlags());
}
private:
@@ -436,12 +444,13 @@ GrDistanceFieldLCDTextureEffect::GrDistanceFieldLCDTextureEffect(
GrTexture* texture, const GrTextureParams& params,
GrTexture* gamma, const GrTextureParams& gParams,
SkColor textColor,
- bool uniformScale, bool useBGR)
+ uint32_t flags)
: fTextureAccess(texture, params)
, fGammaTextureAccess(gamma, gParams)
, fTextColor(textColor)
- , fUniformScale(uniformScale)
- , fUseBGR(useBGR) {
+ , fFlags(flags & kLCD_DistanceFieldEffectMask) {
+ SkASSERT(!(flags & ~kLCD_DistanceFieldEffectMask) && (flags & kUseLCD_DistanceFieldEffectFlag));
+
this->addTextureAccess(&fTextureAccess);
this->addTextureAccess(&fGammaTextureAccess);
this->addVertexAttrib(kVec2f_GrSLType);
@@ -450,7 +459,10 @@ GrDistanceFieldLCDTextureEffect::GrDistanceFieldLCDTextureEffect(
bool GrDistanceFieldLCDTextureEffect::onIsEqual(const GrEffect& other) const {
const GrDistanceFieldLCDTextureEffect& cte =
CastEffect<GrDistanceFieldLCDTextureEffect>(other);
- return (fTextureAccess == cte.fTextureAccess && fGammaTextureAccess == cte.fGammaTextureAccess);
+ return (fTextureAccess == cte.fTextureAccess &&
+ fGammaTextureAccess == cte.fGammaTextureAccess &&
+ fTextColor == cte.fTextColor &&
+ fFlags == cte.fFlags);
}
void GrDistanceFieldLCDTextureEffect::getConstantColorComponents(GrColor* color,
@@ -496,8 +508,11 @@ GrEffect* GrDistanceFieldLCDTextureEffect::TestCreate(SkRandom* random,
random->nextULessThan(256),
random->nextULessThan(256),
random->nextULessThan(256));
+ uint32_t flags = kUseLCD_DistanceFieldEffectFlag;
+ flags |= random->nextBool() ? kUniformScale_DistanceFieldEffectMask : 0;
+ flags |= random->nextBool() ? kBGR_DistanceFieldEffectFlag : 0;
return GrDistanceFieldLCDTextureEffect::Create(textures[texIdx], params,
textures[texIdx2], params2,
textColor,
- random->nextBool(), random->nextBool());
+ flags);
}
« no previous file with comments | « src/gpu/effects/GrDistanceFieldTextureEffect.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698