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

Unified Diff: src/gpu/GrDistanceFieldTextContext.cpp

Issue 424103002: Add effect caching to distance field text. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix initialization. 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
Index: src/gpu/GrDistanceFieldTextContext.cpp
diff --git a/src/gpu/GrDistanceFieldTextContext.cpp b/src/gpu/GrDistanceFieldTextContext.cpp
index 0ef596a27ba0ef8ebea604127018d056c3bc7313..03bfa5d9f24e9b272619de0bd941de383ed02367 100755
--- a/src/gpu/GrDistanceFieldTextContext.cpp
+++ b/src/gpu/GrDistanceFieldTextContext.cpp
@@ -66,7 +66,9 @@ GrDistanceFieldTextContext::GrDistanceFieldTextContext(GrContext* context,
fGammaTexture = NULL;
fCurrVertex = 0;
-
+ fEffectTextureUniqueID = SK_InvalidUniqueID;
robertphillips 2014/07/29 14:01:06 fEffectColor = XXX; ?
jvanverth1 2014/07/29 14:43:41 Done.
+ fEffectFlags = 0;
+
fVertices = NULL;
}
@@ -128,9 +130,9 @@ void GrDistanceFieldTextContext::flushGlyphs() {
GrTextureParams params(SkShader::kRepeat_TileMode, GrTextureParams::kBilerp_FilterMode);
GrTextureParams gammaParams(SkShader::kClamp_TileMode, GrTextureParams::kNone_FilterMode);
robertphillips 2014/07/29 14:01:06 textureUniqueID ?
jvanverth1 2014/07/29 14:43:41 Done.
- // Effects could be stored with one of the cache objects (atlas?)
- int coordsIdx = drawState->hasColorVertexAttribute() ? kGlyphCoordsWithColorAttributeIndex :
- kGlyphCoordsNoColorAttributeIndex;
+ uint32_t textureGenID = currTexture->getUniqueID();
+
+ // get our current color
SkColor filteredColor;
SkColorFilter* colorFilter = fSkPaint.getColorFilter();
if (NULL != colorFilter) {
@@ -138,21 +140,58 @@ void GrDistanceFieldTextContext::flushGlyphs() {
} else {
filteredColor = fSkPaint.getColor();
}
robertphillips 2014/07/29 14:01:06 Could this be a helper method like "setupCoverageE
jvanverth1 2014/07/29 14:43:41 Done.
+
+ // 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 (textureGenID != 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 = textureGenID;
+ fEffectColor = filteredColor;
+ fEffectFlags = flags;
+ }
+
+ // 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()) {
@@ -170,21 +209,6 @@ 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());

Powered by Google App Engine
This is Rietveld 408576698