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

Side by Side 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, 4 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "GrDistanceFieldTextContext.h" 8 #include "GrDistanceFieldTextContext.h"
9 #include "GrAtlas.h" 9 #include "GrAtlas.h"
10 #include "SkColorFilter.h" 10 #include "SkColorFilter.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 : GrTextContext(context, pro perties) { 59 : GrTextContext(context, pro perties) {
60 #if SK_FORCE_DISTANCEFIELD_FONTS 60 #if SK_FORCE_DISTANCEFIELD_FONTS
61 fEnableDFRendering = true; 61 fEnableDFRendering = true;
62 #else 62 #else
63 fEnableDFRendering = enable; 63 fEnableDFRendering = enable;
64 #endif 64 #endif
65 fStrike = NULL; 65 fStrike = NULL;
66 fGammaTexture = NULL; 66 fGammaTexture = NULL;
67 67
68 fCurrVertex = 0; 68 fCurrVertex = 0;
69 69 fEffectTextureUniqueID = SK_InvalidUniqueID;
robertphillips 2014/07/29 14:01:06 fEffectColor = XXX; ?
jvanverth1 2014/07/29 14:43:41 Done.
70 fEffectFlags = 0;
71
70 fVertices = NULL; 72 fVertices = NULL;
71 } 73 }
72 74
73 GrDistanceFieldTextContext::~GrDistanceFieldTextContext() { 75 GrDistanceFieldTextContext::~GrDistanceFieldTextContext() {
74 this->flushGlyphs(); 76 this->flushGlyphs();
75 SkSafeSetNull(fGammaTexture); 77 SkSafeSetNull(fGammaTexture);
76 } 78 }
77 79
78 bool GrDistanceFieldTextContext::canDraw(const SkPaint& paint) { 80 bool GrDistanceFieldTextContext::canDraw(const SkPaint& paint) {
79 if (!fEnableDFRendering && !paint.isDistanceFieldTextTEMP()) { 81 if (!fEnableDFRendering && !paint.isDistanceFieldTextTEMP()) {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 GrDrawState::AutoRestoreEffects are(drawState); 122 GrDrawState::AutoRestoreEffects are(drawState);
121 drawState->setFromPaint(fPaint, fContext->getMatrix(), fContext->getRenderTa rget()); 123 drawState->setFromPaint(fPaint, fContext->getMatrix(), fContext->getRenderTa rget());
122 124
123 if (fCurrVertex > 0) { 125 if (fCurrVertex > 0) {
124 // setup our sampler state for our text texture/atlas 126 // setup our sampler state for our text texture/atlas
125 SkASSERT(SkIsAlign4(fCurrVertex)); 127 SkASSERT(SkIsAlign4(fCurrVertex));
126 GrTexture* currTexture = fStrike->getTexture(); 128 GrTexture* currTexture = fStrike->getTexture();
127 SkASSERT(currTexture); 129 SkASSERT(currTexture);
128 GrTextureParams params(SkShader::kRepeat_TileMode, GrTextureParams::kBil erp_FilterMode); 130 GrTextureParams params(SkShader::kRepeat_TileMode, GrTextureParams::kBil erp_FilterMode);
129 GrTextureParams gammaParams(SkShader::kClamp_TileMode, GrTextureParams:: kNone_FilterMode); 131 GrTextureParams gammaParams(SkShader::kClamp_TileMode, GrTextureParams:: kNone_FilterMode);
130 132
robertphillips 2014/07/29 14:01:06 textureUniqueID ?
jvanverth1 2014/07/29 14:43:41 Done.
131 // Effects could be stored with one of the cache objects (atlas?) 133 uint32_t textureGenID = currTexture->getUniqueID();
132 int coordsIdx = drawState->hasColorVertexAttribute() ? kGlyphCoordsWithC olorAttributeIndex : 134
133 kGlyphCoordsNoCol orAttributeIndex; 135 // get our current color
134 SkColor filteredColor; 136 SkColor filteredColor;
135 SkColorFilter* colorFilter = fSkPaint.getColorFilter(); 137 SkColorFilter* colorFilter = fSkPaint.getColorFilter();
136 if (NULL != colorFilter) { 138 if (NULL != colorFilter) {
137 filteredColor = colorFilter->filterColor(fSkPaint.getColor()); 139 filteredColor = colorFilter->filterColor(fSkPaint.getColor());
138 } else { 140 } else {
139 filteredColor = fSkPaint.getColor(); 141 filteredColor = fSkPaint.getColor();
140 } 142 }
robertphillips 2014/07/29 14:01:06 Could this be a helper method like "setupCoverageE
jvanverth1 2014/07/29 14:43:41 Done.
143
144 // set up any flags
145 uint32_t flags = 0;
146 flags |= fContext->getMatrix().isSimilarity() ? kSimilarity_DistanceFiel dEffectFlag : 0;
147 flags |= fUseLCDText ? kUseLCD_DistanceFieldEffectFlag : 0;
148 flags |= fUseLCDText && fContext->getMatrix().rectStaysRect() ?
149 kRectToRect_Distance FieldEffectFlag : 0;
150 bool useBGR = SkDeviceProperties::Geometry::kBGR_Layout ==
151 fDeviceProperties.fG eometry.getLayout();
152 flags |= fUseLCDText && useBGR ? kBGR_DistanceFieldEffectFlag : 0;
153
154 // see if we need to create a new effect
155 if (textureGenID != fEffectTextureUniqueID ||
156 filteredColor != fEffectColor ||
157 flags != fEffectFlags) {
158 if (fUseLCDText) {
159 GrColor colorNoPreMul = skcolor_to_grcolor_nopremultiply(filtere dColor);
160 fCachedEffect.reset(GrDistanceFieldLCDTextureEffect::Create(curr Texture,
161 para ms,
162 fGam maTexture,
163 gamm aParams,
164 colo rNoPreMul,
165 flag s));
166 } else {
167 #ifdef SK_GAMMA_APPLY_TO_A8
168 U8CPU lum = SkColorSpaceLuminance::computeLuminance(fDevicePrope rties.fGamma,
169 filteredColo r);
170 fCachedEffect.reset(GrDistanceFieldTextureEffect::Create(currTex ture,
171 params,
172 fGammaT exture,
173 gammaPa rams,
174 lum/255 .f,
175 flags)) ;
176 #else
177 fCachedEffect.reset(GrDistanceFieldTextureEffect::Create(currTex ture,
178 params, flags));
179 #endif
180
181 }
182 fEffectTextureUniqueID = textureGenID;
183 fEffectColor = filteredColor;
184 fEffectFlags = flags;
185 }
186
187 // Effects could be stored with one of the cache objects (atlas?)
188 int coordsIdx = drawState->hasColorVertexAttribute() ? kGlyphCoordsWithC olorAttributeIndex :
189 kGlyphCoordsNoCol orAttributeIndex;
190 drawState->addCoverageEffect(fCachedEffect.get(), coordsIdx);
191
192 // Set draw state
141 if (fUseLCDText) { 193 if (fUseLCDText) {
142 GrColor colorNoPreMul = skcolor_to_grcolor_nopremultiply(filteredCol or); 194 GrColor colorNoPreMul = skcolor_to_grcolor_nopremultiply(filteredCol or);
143 bool useBGR = SkDeviceProperties::Geometry::kBGR_Layout ==
144 fDeviceProperties.fG eometry.getLayout();
145 drawState->addCoverageEffect(GrDistanceFieldLCDTextureEffect::Create (
146 currTexture,
147 params,
148 fGammaTexture,
149 gammaParams,
150 colorNoPreMul,
151 fContext->getMatrix( ).rectStaysRect() &&
152 fContext->getMatrix( ).isSimilarity(),
153 useBGR),
154 coordsIdx)->unref();
155
156 if (kOne_GrBlendCoeff != fPaint.getSrcBlendCoeff() || 195 if (kOne_GrBlendCoeff != fPaint.getSrcBlendCoeff() ||
157 kISA_GrBlendCoeff != fPaint.getDstBlendCoeff() || 196 kISA_GrBlendCoeff != fPaint.getDstBlendCoeff() ||
158 fPaint.numColorStages()) { 197 fPaint.numColorStages()) {
159 GrPrintf("LCD Text will not draw correctly.\n"); 198 GrPrintf("LCD Text will not draw correctly.\n");
160 } 199 }
161 SkASSERT(!drawState->hasColorVertexAttribute()); 200 SkASSERT(!drawState->hasColorVertexAttribute());
162 // We don't use the GrPaint's color in this case because it's been p remultiplied by 201 // We don't use the GrPaint's color in this case because it's been p remultiplied by
163 // alpha. Instead we feed in a non-premultiplied color, and multiply its alpha by 202 // alpha. Instead we feed in a non-premultiplied color, and multiply its alpha by
164 // the mask texture color. The end result is that we get 203 // the mask texture color. The end result is that we get
165 // mask*paintAlpha*paintColor + (1-mask*paintAlpha)*dstCo lor 204 // mask*paintAlpha*paintColor + (1-mask*paintAlpha)*dstCo lor
166 int a = SkColorGetA(fSkPaint.getColor()); 205 int a = SkColorGetA(fSkPaint.getColor());
167 // paintAlpha 206 // paintAlpha
168 drawState->setColor(SkColorSetARGB(a, a, a, a)); 207 drawState->setColor(SkColorSetARGB(a, a, a, a));
169 // paintColor 208 // paintColor
170 drawState->setBlendConstant(colorNoPreMul); 209 drawState->setBlendConstant(colorNoPreMul);
171 drawState->setBlendFunc(kConstC_GrBlendCoeff, kISC_GrBlendCoeff); 210 drawState->setBlendFunc(kConstC_GrBlendCoeff, kISC_GrBlendCoeff);
172 } else { 211 } else {
173 #ifdef SK_GAMMA_APPLY_TO_A8
174 U8CPU lum = SkColorSpaceLuminance::computeLuminance(fDevicePropertie s.fGamma,
175 filteredColor);
176 drawState->addCoverageEffect(GrDistanceFieldTextureEffect::Create(
177 currTexture, param s,
178 fGammaTexture, gam maParams,
179 lum/255.f,
180 fContext->getMatri x().isSimilarity()),
181 coordsIdx)->unref();
182 #else
183 drawState->addCoverageEffect(GrDistanceFieldTextureEffect::Create(
184 currTexture, param s,
185 fContext->getMatri x().isSimilarity()),
186 coordsIdx)->unref();
187 #endif
188 // set back to normal in case we took LCD path previously. 212 // set back to normal in case we took LCD path previously.
189 drawState->setBlendFunc(fPaint.getSrcBlendCoeff(), fPaint.getDstBlen dCoeff()); 213 drawState->setBlendFunc(fPaint.getSrcBlendCoeff(), fPaint.getDstBlen dCoeff());
190 //drawState->setColor(fPaint.getColor()); 214 //drawState->setColor(fPaint.getColor());
191 // We're using per-vertex color. 215 // We're using per-vertex color.
192 SkASSERT(drawState->hasColorVertexAttribute()); 216 SkASSERT(drawState->hasColorVertexAttribute());
193 drawState->setColor(0xFFFFFFFF); 217 drawState->setColor(0xFFFFFFFF);
194 } 218 }
195 int nGlyphs = fCurrVertex / 4; 219 int nGlyphs = fCurrVertex / 4;
196 fDrawTarget->setIndexSourceToBuffer(fContext->getQuadIndexBuffer()); 220 fDrawTarget->setIndexSourceToBuffer(fContext->getQuadIndexBuffer());
197 fDrawTarget->drawIndexedInstances(kTriangles_GrPrimitiveType, 221 fDrawTarget->drawIndexedInstances(kTriangles_GrPrimitiveType,
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 SkScalarToFixed(x) - (glyph.fAdvanceX >> a lignShift), 614 SkScalarToFixed(x) - (glyph.fAdvanceX >> a lignShift),
591 SkScalarToFixed(y) - (glyph.fAdvanceY >> a lignShift), 615 SkScalarToFixed(y) - (glyph.fAdvanceY >> a lignShift),
592 fontScaler); 616 fontScaler);
593 } 617 }
594 pos += scalarsPerPosition; 618 pos += scalarsPerPosition;
595 } 619 }
596 } 620 }
597 621
598 this->finish(); 622 this->finish();
599 } 623 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698