Revert of Add effect caching to distance field text. (https://codereview.chromium.org/424103002/)
Reason for revert: breaking Chrome canary. Original issue's description: > Add effect caching to distance field text. > > This also is a step towards unifying GrDistanceFieldTextureEffect and GrDistanceFieldLCDTextureEffect. > > Committed: https://skia.googlesource.com/skia/+/137bac067306c5446bc4f9797bedc3bbaf302822 R=robertphillips@google.com, jvanverth@google.com TBR=jvanverth@google.com, robertphillips@google.com NOTREECHECKS=true NOTRY=true Author: bensong@google.com Review URL: https://codereview.chromium.org/424173002
This commit is contained in:
parent
b09bdd6bac
commit
fdd09c2002
@ -66,10 +66,7 @@ GrDistanceFieldTextContext::GrDistanceFieldTextContext(GrContext* context,
|
||||
fGammaTexture = NULL;
|
||||
|
||||
fCurrVertex = 0;
|
||||
fEffectTextureUniqueID = SK_InvalidUniqueID;
|
||||
fEffectColor = GrColor_ILLEGAL;
|
||||
fEffectFlags = 0;
|
||||
|
||||
|
||||
fVertices = NULL;
|
||||
}
|
||||
|
||||
@ -114,58 +111,6 @@ static inline GrColor skcolor_to_grcolor_nopremultiply(SkColor c) {
|
||||
return GrColorPackRGBA(r, g, b, 0xff);
|
||||
}
|
||||
|
||||
void GrDistanceFieldTextContext::setupCoverageEffect(const SkColor& filteredColor) {
|
||||
GrTextureParams params(SkShader::kRepeat_TileMode, GrTextureParams::kBilerp_FilterMode);
|
||||
GrTextureParams gammaParams(SkShader::kClamp_TileMode, GrTextureParams::kNone_FilterMode);
|
||||
|
||||
GrTexture* currTexture = fStrike->getTexture();
|
||||
SkASSERT(currTexture);
|
||||
uint32_t textureUniqueID = currTexture->getUniqueID();
|
||||
|
||||
// set up any flags
|
||||
uint32_t flags = 0;
|
||||
flags |= fContext->getMatrix().isSimilarity() ? kSimilarity_DistanceFieldEffectFlag : 0;
|
||||
flags |= fUseLCDText ? kUseLCD_DistanceFieldEffectFlag : 0;
|
||||
flags |= fUseLCDText && fContext->getMatrix().rectStaysRect() ?
|
||||
kRectToRect_DistanceFieldEffectFlag : 0;
|
||||
bool useBGR = SkDeviceProperties::Geometry::kBGR_Layout ==
|
||||
fDeviceProperties.fGeometry.getLayout();
|
||||
flags |= fUseLCDText && useBGR ? kBGR_DistanceFieldEffectFlag : 0;
|
||||
|
||||
// see if we need to create a new effect
|
||||
if (textureUniqueID != fEffectTextureUniqueID ||
|
||||
filteredColor != fEffectColor ||
|
||||
flags != fEffectFlags) {
|
||||
if (fUseLCDText) {
|
||||
GrColor colorNoPreMul = skcolor_to_grcolor_nopremultiply(filteredColor);
|
||||
fCachedEffect.reset(GrDistanceFieldLCDTextureEffect::Create(currTexture,
|
||||
params,
|
||||
fGammaTexture,
|
||||
gammaParams,
|
||||
colorNoPreMul,
|
||||
flags));
|
||||
} else {
|
||||
#ifdef SK_GAMMA_APPLY_TO_A8
|
||||
U8CPU lum = SkColorSpaceLuminance::computeLuminance(fDeviceProperties.fGamma,
|
||||
filteredColor);
|
||||
fCachedEffect.reset(GrDistanceFieldTextureEffect::Create(currTexture,
|
||||
params,
|
||||
fGammaTexture,
|
||||
gammaParams,
|
||||
lum/255.f,
|
||||
flags));
|
||||
#else
|
||||
fCachedEffect.reset(GrDistanceFieldTextureEffect::Create(currTexture,
|
||||
params, flags));
|
||||
#endif
|
||||
}
|
||||
fEffectTextureUniqueID = textureUniqueID;
|
||||
fEffectColor = filteredColor;
|
||||
fEffectFlags = flags;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void GrDistanceFieldTextContext::flushGlyphs() {
|
||||
if (NULL == fDrawTarget) {
|
||||
return;
|
||||
@ -178,8 +123,14 @@ void GrDistanceFieldTextContext::flushGlyphs() {
|
||||
if (fCurrVertex > 0) {
|
||||
// setup our sampler state for our text texture/atlas
|
||||
SkASSERT(SkIsAlign4(fCurrVertex));
|
||||
GrTexture* currTexture = fStrike->getTexture();
|
||||
SkASSERT(currTexture);
|
||||
GrTextureParams params(SkShader::kRepeat_TileMode, GrTextureParams::kBilerp_FilterMode);
|
||||
GrTextureParams gammaParams(SkShader::kClamp_TileMode, GrTextureParams::kNone_FilterMode);
|
||||
|
||||
// get our current color
|
||||
// Effects could be stored with one of the cache objects (atlas?)
|
||||
int coordsIdx = drawState->hasColorVertexAttribute() ? kGlyphCoordsWithColorAttributeIndex :
|
||||
kGlyphCoordsNoColorAttributeIndex;
|
||||
SkColor filteredColor;
|
||||
SkColorFilter* colorFilter = fSkPaint.getColorFilter();
|
||||
if (NULL != colorFilter) {
|
||||
@ -187,16 +138,21 @@ void GrDistanceFieldTextContext::flushGlyphs() {
|
||||
} else {
|
||||
filteredColor = fSkPaint.getColor();
|
||||
}
|
||||
this->setupCoverageEffect(filteredColor);
|
||||
|
||||
// Effects could be stored with one of the cache objects (atlas?)
|
||||
int coordsIdx = drawState->hasColorVertexAttribute() ? kGlyphCoordsWithColorAttributeIndex :
|
||||
kGlyphCoordsNoColorAttributeIndex;
|
||||
drawState->addCoverageEffect(fCachedEffect.get(), coordsIdx);
|
||||
|
||||
// Set draw state
|
||||
if (fUseLCDText) {
|
||||
GrColor colorNoPreMul = skcolor_to_grcolor_nopremultiply(filteredColor);
|
||||
bool useBGR = SkDeviceProperties::Geometry::kBGR_Layout ==
|
||||
fDeviceProperties.fGeometry.getLayout();
|
||||
drawState->addCoverageEffect(GrDistanceFieldLCDTextureEffect::Create(
|
||||
currTexture,
|
||||
params,
|
||||
fGammaTexture,
|
||||
gammaParams,
|
||||
colorNoPreMul,
|
||||
fContext->getMatrix().rectStaysRect() &&
|
||||
fContext->getMatrix().isSimilarity(),
|
||||
useBGR),
|
||||
coordsIdx)->unref();
|
||||
|
||||
if (kOne_GrBlendCoeff != fPaint.getSrcBlendCoeff() ||
|
||||
kISA_GrBlendCoeff != fPaint.getDstBlendCoeff() ||
|
||||
fPaint.numColorStages()) {
|
||||
@ -214,6 +170,21 @@ void GrDistanceFieldTextContext::flushGlyphs() {
|
||||
drawState->setBlendConstant(colorNoPreMul);
|
||||
drawState->setBlendFunc(kConstC_GrBlendCoeff, kISC_GrBlendCoeff);
|
||||
} else {
|
||||
#ifdef SK_GAMMA_APPLY_TO_A8
|
||||
U8CPU lum = SkColorSpaceLuminance::computeLuminance(fDeviceProperties.fGamma,
|
||||
filteredColor);
|
||||
drawState->addCoverageEffect(GrDistanceFieldTextureEffect::Create(
|
||||
currTexture, params,
|
||||
fGammaTexture, gammaParams,
|
||||
lum/255.f,
|
||||
fContext->getMatrix().isSimilarity()),
|
||||
coordsIdx)->unref();
|
||||
#else
|
||||
drawState->addCoverageEffect(GrDistanceFieldTextureEffect::Create(
|
||||
currTexture, params,
|
||||
fContext->getMatrix().isSimilarity()),
|
||||
coordsIdx)->unref();
|
||||
#endif
|
||||
// set back to normal in case we took LCD path previously.
|
||||
drawState->setBlendFunc(fPaint.getSrcBlendCoeff(), fPaint.getDstBlendCoeff());
|
||||
//drawState->setColor(fPaint.getColor());
|
||||
|
@ -34,17 +34,11 @@ private:
|
||||
SkScalar fTextRatio;
|
||||
bool fUseLCDText;
|
||||
bool fEnableDFRendering;
|
||||
SkAutoTUnref<GrEffect> fCachedEffect;
|
||||
// Used to check whether fCachedEffect is still valid.
|
||||
uint32_t fEffectTextureUniqueID;
|
||||
SkColor fEffectColor;
|
||||
uint32_t fEffectFlags;
|
||||
GrTexture* fGammaTexture;
|
||||
|
||||
void init(const GrPaint&, const SkPaint&);
|
||||
void drawPackedGlyph(GrGlyph::PackedID, SkFixed left, SkFixed top, GrFontScaler*);
|
||||
void flushGlyphs(); // automatically called by destructor
|
||||
void setupCoverageEffect(const SkColor& filteredColor);
|
||||
void finish();
|
||||
|
||||
enum {
|
||||
|
@ -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.getFlags() & kSimilarity_DistanceFieldEffectFlag) {
|
||||
if (dfTexEffect.isSimilarity()) {
|
||||
// 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.getFlags());
|
||||
b->add32(dfTexEffect.isSimilarity());
|
||||
}
|
||||
|
||||
private:
|
||||
@ -174,14 +174,13 @@ GrDistanceFieldTextureEffect::GrDistanceFieldTextureEffect(GrTexture* texture,
|
||||
const GrTextureParams& gammaParams,
|
||||
float luminance,
|
||||
#endif
|
||||
uint32_t flags)
|
||||
bool similarity)
|
||||
: fTextureAccess(texture, params)
|
||||
#ifdef SK_GAMMA_APPLY_TO_A8
|
||||
, fGammaTextureAccess(gamma, gammaParams)
|
||||
, fLuminance(luminance)
|
||||
#endif
|
||||
, fFlags(flags & kNonLCD_DistanceFieldEffectMask) {
|
||||
SkASSERT(!(flags & ~kNonLCD_DistanceFieldEffectMask));
|
||||
, fIsSimilarity(similarity) {
|
||||
this->addTextureAccess(&fTextureAccess);
|
||||
#ifdef SK_GAMMA_APPLY_TO_A8
|
||||
this->addTextureAccess(&fGammaTextureAccess);
|
||||
@ -191,10 +190,7 @@ GrDistanceFieldTextureEffect::GrDistanceFieldTextureEffect(GrTexture* texture,
|
||||
|
||||
bool GrDistanceFieldTextureEffect::onIsEqual(const GrEffect& other) const {
|
||||
const GrDistanceFieldTextureEffect& cte = CastEffect<GrDistanceFieldTextureEffect>(other);
|
||||
return fTextureAccess == cte.fTextureAccess &&
|
||||
fGammaTextureAccess == cte.fGammaTextureAccess &&
|
||||
fLuminance == cte.fLuminance &&
|
||||
fFlags == cte.fFlags;
|
||||
return fTextureAccess == cte.fTextureAccess;
|
||||
}
|
||||
|
||||
void GrDistanceFieldTextureEffect::getConstantColorComponents(GrColor* color,
|
||||
@ -246,8 +242,7 @@ GrEffect* GrDistanceFieldTextureEffect::TestCreate(SkRandom* random,
|
||||
textures[texIdx2], params2,
|
||||
random->nextF(),
|
||||
#endif
|
||||
random->nextBool() ?
|
||||
kSimilarity_DistanceFieldEffectFlag : 0);
|
||||
random->nextBool());
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
@ -291,8 +286,7 @@ 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);
|
||||
bool isUniformScale = !!(dfTexEffect.getFlags() & kUniformScale_DistanceFieldEffectMask);
|
||||
if (isUniformScale) {
|
||||
if (dfTexEffect.isUniformScale()) {
|
||||
builder->fsCodeAppend("\tfloat dx = dFdx(st.x);\n");
|
||||
builder->fsCodeAppendf("\tvec2 offset = vec2(dx*%s.z, 0.0);\n", textureSizeUniName);
|
||||
} else {
|
||||
@ -333,7 +327,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 (isUniformScale) {
|
||||
if (dfTexEffect.isUniformScale()) {
|
||||
// this gives us a smooth step across approximately one fragment
|
||||
builder->fsCodeAppend("\tafwidth = " SK_DistanceFieldAAFactor "*dx;\n");
|
||||
} else {
|
||||
@ -399,7 +393,7 @@ public:
|
||||
texture->height() != fTextureSize.height()) {
|
||||
fTextureSize = SkISize::Make(texture->width(), texture->height());
|
||||
float delta = 1.0f/(3.0f*texture->width());
|
||||
if (dfTexEffect.getFlags() & kBGR_DistanceFieldEffectFlag) {
|
||||
if (dfTexEffect.useBGR()) {
|
||||
delta = -delta;
|
||||
}
|
||||
uman.set3f(fTextureSizeUni,
|
||||
@ -424,7 +418,7 @@ public:
|
||||
const GrDistanceFieldLCDTextureEffect& dfTexEffect =
|
||||
drawEffect.castEffect<GrDistanceFieldLCDTextureEffect>();
|
||||
|
||||
b->add32(dfTexEffect.getFlags());
|
||||
b->add32(dfTexEffect.isUniformScale());
|
||||
}
|
||||
|
||||
private:
|
||||
@ -442,13 +436,12 @@ GrDistanceFieldLCDTextureEffect::GrDistanceFieldLCDTextureEffect(
|
||||
GrTexture* texture, const GrTextureParams& params,
|
||||
GrTexture* gamma, const GrTextureParams& gParams,
|
||||
SkColor textColor,
|
||||
uint32_t flags)
|
||||
bool uniformScale, bool useBGR)
|
||||
: fTextureAccess(texture, params)
|
||||
, fGammaTextureAccess(gamma, gParams)
|
||||
, fTextColor(textColor)
|
||||
, fFlags(flags & kLCD_DistanceFieldEffectMask) {
|
||||
SkASSERT(!(flags & ~kLCD_DistanceFieldEffectMask) && (flags & kUseLCD_DistanceFieldEffectFlag));
|
||||
|
||||
, fUniformScale(uniformScale)
|
||||
, fUseBGR(useBGR) {
|
||||
this->addTextureAccess(&fTextureAccess);
|
||||
this->addTextureAccess(&fGammaTextureAccess);
|
||||
this->addVertexAttrib(kVec2f_GrSLType);
|
||||
@ -457,10 +450,7 @@ GrDistanceFieldLCDTextureEffect::GrDistanceFieldLCDTextureEffect(
|
||||
bool GrDistanceFieldLCDTextureEffect::onIsEqual(const GrEffect& other) const {
|
||||
const GrDistanceFieldLCDTextureEffect& cte =
|
||||
CastEffect<GrDistanceFieldLCDTextureEffect>(other);
|
||||
return (fTextureAccess == cte.fTextureAccess &&
|
||||
fGammaTextureAccess == cte.fGammaTextureAccess &&
|
||||
fTextColor == cte.fTextColor &&
|
||||
fFlags == cte.fFlags);
|
||||
return (fTextureAccess == cte.fTextureAccess && fGammaTextureAccess == cte.fGammaTextureAccess);
|
||||
}
|
||||
|
||||
void GrDistanceFieldLCDTextureEffect::getConstantColorComponents(GrColor* color,
|
||||
@ -506,11 +496,8 @@ 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,
|
||||
flags);
|
||||
random->nextBool(), random->nextBool());
|
||||
}
|
||||
|
@ -14,24 +14,6 @@
|
||||
class GrGLDistanceFieldTextureEffect;
|
||||
class GrGLDistanceFieldLCDTextureEffect;
|
||||
|
||||
enum GrDistanceFieldEffectFlags {
|
||||
kSimilarity_DistanceFieldEffectFlag = 0x01, // ctm is similarity matrix
|
||||
kRectToRect_DistanceFieldEffectFlag = 0x02, // ctm maps rects to rects
|
||||
kUseLCD_DistanceFieldEffectFlag = 0x04, // use lcd text
|
||||
kBGR_DistanceFieldEffectFlag = 0x08, // lcd display has bgr order
|
||||
kPortrait_DistanceFieldEffectFlag = 0x10, // lcd display is in portrait mode (not used yet)
|
||||
|
||||
kUniformScale_DistanceFieldEffectMask = kSimilarity_DistanceFieldEffectFlag |
|
||||
kRectToRect_DistanceFieldEffectFlag,
|
||||
// The subset of the flags relevant to GrDistanceFieldTextureEffect
|
||||
kNonLCD_DistanceFieldEffectMask = kSimilarity_DistanceFieldEffectFlag,
|
||||
// The subset of the flags relevant to GrDistanceFieldLCDTextureEffect
|
||||
kLCD_DistanceFieldEffectMask = kSimilarity_DistanceFieldEffectFlag |
|
||||
kRectToRect_DistanceFieldEffectFlag |
|
||||
kUseLCD_DistanceFieldEffectFlag |
|
||||
kBGR_DistanceFieldEffectFlag,
|
||||
};
|
||||
|
||||
/**
|
||||
* The output color of this effect is a modulation of the input color and a sample from a
|
||||
* distance field texture (using a smoothed step function near 0.5).
|
||||
@ -43,14 +25,14 @@ public:
|
||||
#ifdef SK_GAMMA_APPLY_TO_A8
|
||||
static GrEffect* Create(GrTexture* tex, const GrTextureParams& params,
|
||||
GrTexture* gamma, const GrTextureParams& gammaParams, float lum,
|
||||
uint32_t flags) {
|
||||
bool similarity) {
|
||||
return SkNEW_ARGS(GrDistanceFieldTextureEffect, (tex, params, gamma, gammaParams, lum,
|
||||
flags));
|
||||
similarity));
|
||||
}
|
||||
#else
|
||||
static GrEffect* Create(GrTexture* tex, const GrTextureParams& params,
|
||||
uint32_t flags) {
|
||||
return SkNEW_ARGS(GrDistanceFieldTextureEffect, (tex, params, flags));
|
||||
bool similarity) {
|
||||
return SkNEW_ARGS(GrDistanceFieldTextureEffect, (tex, params, similarity));
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -62,7 +44,7 @@ public:
|
||||
#ifdef SK_GAMMA_APPLY_TO_A8
|
||||
float getLuminance() const { return fLuminance; }
|
||||
#endif
|
||||
uint32_t getFlags() const { return fFlags; }
|
||||
bool isSimilarity() const { return fIsSimilarity; }
|
||||
|
||||
typedef GrGLDistanceFieldTextureEffect GLEffect;
|
||||
|
||||
@ -73,7 +55,7 @@ private:
|
||||
#ifdef SK_GAMMA_APPLY_TO_A8
|
||||
GrTexture* gamma, const GrTextureParams& gammaParams, float lum,
|
||||
#endif
|
||||
uint32_t flags);
|
||||
bool uniformScale);
|
||||
|
||||
virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE;
|
||||
|
||||
@ -82,7 +64,7 @@ private:
|
||||
GrTextureAccess fGammaTextureAccess;
|
||||
float fLuminance;
|
||||
#endif
|
||||
uint32_t fFlags;
|
||||
bool fIsSimilarity;
|
||||
|
||||
GR_DECLARE_EFFECT_TEST;
|
||||
|
||||
@ -99,9 +81,9 @@ class GrDistanceFieldLCDTextureEffect : public GrVertexEffect {
|
||||
public:
|
||||
static GrEffect* Create(GrTexture* tex, const GrTextureParams& params,
|
||||
GrTexture* gamma, const GrTextureParams& gammaParams,
|
||||
SkColor textColor, uint32_t flags) {
|
||||
SkColor textColor, bool uniformScale, bool useBGR) {
|
||||
return SkNEW_ARGS(GrDistanceFieldLCDTextureEffect,
|
||||
(tex, params, gamma, gammaParams, textColor, flags));
|
||||
(tex, params, gamma, gammaParams, textColor, uniformScale, useBGR));
|
||||
}
|
||||
|
||||
virtual ~GrDistanceFieldLCDTextureEffect() {}
|
||||
@ -110,7 +92,8 @@ public:
|
||||
|
||||
virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE;
|
||||
GrColor getTextColor() const { return fTextColor; }
|
||||
uint32_t getFlags() const { return fFlags; }
|
||||
bool isUniformScale() const { return fUniformScale; }
|
||||
bool useBGR() const { return fUseBGR; }
|
||||
|
||||
typedef GrGLDistanceFieldLCDTextureEffect GLEffect;
|
||||
|
||||
@ -120,14 +103,15 @@ private:
|
||||
GrDistanceFieldLCDTextureEffect(GrTexture* texture, const GrTextureParams& params,
|
||||
GrTexture* gamma, const GrTextureParams& gammaParams,
|
||||
SkColor textColor,
|
||||
uint32_t flags);
|
||||
bool uniformScale, bool useBGR);
|
||||
|
||||
virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE;
|
||||
|
||||
GrTextureAccess fTextureAccess;
|
||||
GrTextureAccess fGammaTextureAccess;
|
||||
GrColor fTextColor;
|
||||
uint32_t fFlags;
|
||||
bool fUniformScale;
|
||||
bool fUseBGR;
|
||||
|
||||
GR_DECLARE_EFFECT_TEST;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user