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

Side by Side Diff: src/gpu/GrDistanceFieldTextContext.cpp

Issue 424173002: Revert of Add effect caching to distance field text. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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
« no previous file with comments | « src/gpu/GrDistanceFieldTextContext.h ('k') | src/gpu/effects/GrDistanceFieldTextureEffect.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 fEffectTextureUniqueID = SK_InvalidUniqueID; 69
70 fEffectColor = GrColor_ILLEGAL;
71 fEffectFlags = 0;
72
73 fVertices = NULL; 70 fVertices = NULL;
74 } 71 }
75 72
76 GrDistanceFieldTextContext::~GrDistanceFieldTextContext() { 73 GrDistanceFieldTextContext::~GrDistanceFieldTextContext() {
77 this->flushGlyphs(); 74 this->flushGlyphs();
78 SkSafeSetNull(fGammaTexture); 75 SkSafeSetNull(fGammaTexture);
79 } 76 }
80 77
81 bool GrDistanceFieldTextContext::canDraw(const SkPaint& paint) { 78 bool GrDistanceFieldTextContext::canDraw(const SkPaint& paint) {
82 if (!fEnableDFRendering && !paint.isDistanceFieldTextTEMP()) { 79 if (!fEnableDFRendering && !paint.isDistanceFieldTextTEMP()) {
(...skipping 24 matching lines...) Expand all
107 return rec.getFormat() != SkMask::kARGB32_Format; 104 return rec.getFormat() != SkMask::kARGB32_Format;
108 } 105 }
109 106
110 static inline GrColor skcolor_to_grcolor_nopremultiply(SkColor c) { 107 static inline GrColor skcolor_to_grcolor_nopremultiply(SkColor c) {
111 unsigned r = SkColorGetR(c); 108 unsigned r = SkColorGetR(c);
112 unsigned g = SkColorGetG(c); 109 unsigned g = SkColorGetG(c);
113 unsigned b = SkColorGetB(c); 110 unsigned b = SkColorGetB(c);
114 return GrColorPackRGBA(r, g, b, 0xff); 111 return GrColorPackRGBA(r, g, b, 0xff);
115 } 112 }
116 113
117 void GrDistanceFieldTextContext::setupCoverageEffect(const SkColor& filteredColo r) {
118 GrTextureParams params(SkShader::kRepeat_TileMode, GrTextureParams::kBilerp_ FilterMode);
119 GrTextureParams gammaParams(SkShader::kClamp_TileMode, GrTextureParams::kNon e_FilterMode);
120
121 GrTexture* currTexture = fStrike->getTexture();
122 SkASSERT(currTexture);
123 uint32_t textureUniqueID = currTexture->getUniqueID();
124
125 // set up any flags
126 uint32_t flags = 0;
127 flags |= fContext->getMatrix().isSimilarity() ? kSimilarity_DistanceFieldEff ectFlag : 0;
128 flags |= fUseLCDText ? kUseLCD_DistanceFieldEffectFlag : 0;
129 flags |= fUseLCDText && fContext->getMatrix().rectStaysRect() ?
130 kRectToRect_DistanceFieldEffectFlag : 0;
131 bool useBGR = SkDeviceProperties::Geometry::kBGR_Layout ==
132 fDeviceProperties.fGeometry.getLayout();
133 flags |= fUseLCDText && useBGR ? kBGR_DistanceFieldEffectFlag : 0;
134
135 // see if we need to create a new effect
136 if (textureUniqueID != fEffectTextureUniqueID ||
137 filteredColor != fEffectColor ||
138 flags != fEffectFlags) {
139 if (fUseLCDText) {
140 GrColor colorNoPreMul = skcolor_to_grcolor_nopremultiply(filteredCol or);
141 fCachedEffect.reset(GrDistanceFieldLCDTextureEffect::Create(currText ure,
142 params,
143 fGammaTe xture,
144 gammaPar ams,
145 colorNoP reMul,
146 flags));
147 } else {
148 #ifdef SK_GAMMA_APPLY_TO_A8
149 U8CPU lum = SkColorSpaceLuminance::computeLuminance(fDevicePropertie s.fGamma,
150 filteredColor);
151 fCachedEffect.reset(GrDistanceFieldTextureEffect::Create(currTexture ,
152 params,
153 fGammaTextu re,
154 gammaParams ,
155 lum/255.f,
156 flags));
157 #else
158 fCachedEffect.reset(GrDistanceFieldTextureEffect::Create(currTexture ,
159 params, fla gs));
160 #endif
161 }
162 fEffectTextureUniqueID = textureUniqueID;
163 fEffectColor = filteredColor;
164 fEffectFlags = flags;
165 }
166
167 }
168
169 void GrDistanceFieldTextContext::flushGlyphs() { 114 void GrDistanceFieldTextContext::flushGlyphs() {
170 if (NULL == fDrawTarget) { 115 if (NULL == fDrawTarget) {
171 return; 116 return;
172 } 117 }
173 118
174 GrDrawState* drawState = fDrawTarget->drawState(); 119 GrDrawState* drawState = fDrawTarget->drawState();
175 GrDrawState::AutoRestoreEffects are(drawState); 120 GrDrawState::AutoRestoreEffects are(drawState);
176 drawState->setFromPaint(fPaint, fContext->getMatrix(), fContext->getRenderTa rget()); 121 drawState->setFromPaint(fPaint, fContext->getMatrix(), fContext->getRenderTa rget());
177 122
178 if (fCurrVertex > 0) { 123 if (fCurrVertex > 0) {
179 // setup our sampler state for our text texture/atlas 124 // setup our sampler state for our text texture/atlas
180 SkASSERT(SkIsAlign4(fCurrVertex)); 125 SkASSERT(SkIsAlign4(fCurrVertex));
126 GrTexture* currTexture = fStrike->getTexture();
127 SkASSERT(currTexture);
128 GrTextureParams params(SkShader::kRepeat_TileMode, GrTextureParams::kBil erp_FilterMode);
129 GrTextureParams gammaParams(SkShader::kClamp_TileMode, GrTextureParams:: kNone_FilterMode);
181 130
182 // get our current color 131 // Effects could be stored with one of the cache objects (atlas?)
132 int coordsIdx = drawState->hasColorVertexAttribute() ? kGlyphCoordsWithC olorAttributeIndex :
133 kGlyphCoordsNoCol orAttributeIndex;
183 SkColor filteredColor; 134 SkColor filteredColor;
184 SkColorFilter* colorFilter = fSkPaint.getColorFilter(); 135 SkColorFilter* colorFilter = fSkPaint.getColorFilter();
185 if (NULL != colorFilter) { 136 if (NULL != colorFilter) {
186 filteredColor = colorFilter->filterColor(fSkPaint.getColor()); 137 filteredColor = colorFilter->filterColor(fSkPaint.getColor());
187 } else { 138 } else {
188 filteredColor = fSkPaint.getColor(); 139 filteredColor = fSkPaint.getColor();
189 } 140 }
190 this->setupCoverageEffect(filteredColor);
191
192 // Effects could be stored with one of the cache objects (atlas?)
193 int coordsIdx = drawState->hasColorVertexAttribute() ? kGlyphCoordsWithC olorAttributeIndex :
194 kGlyphCoordsNoCol orAttributeIndex;
195 drawState->addCoverageEffect(fCachedEffect.get(), coordsIdx);
196
197 // Set draw state
198 if (fUseLCDText) { 141 if (fUseLCDText) {
199 GrColor colorNoPreMul = skcolor_to_grcolor_nopremultiply(filteredCol or); 142 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
200 if (kOne_GrBlendCoeff != fPaint.getSrcBlendCoeff() || 156 if (kOne_GrBlendCoeff != fPaint.getSrcBlendCoeff() ||
201 kISA_GrBlendCoeff != fPaint.getDstBlendCoeff() || 157 kISA_GrBlendCoeff != fPaint.getDstBlendCoeff() ||
202 fPaint.numColorStages()) { 158 fPaint.numColorStages()) {
203 GrPrintf("LCD Text will not draw correctly.\n"); 159 GrPrintf("LCD Text will not draw correctly.\n");
204 } 160 }
205 SkASSERT(!drawState->hasColorVertexAttribute()); 161 SkASSERT(!drawState->hasColorVertexAttribute());
206 // We don't use the GrPaint's color in this case because it's been p remultiplied by 162 // We don't use the GrPaint's color in this case because it's been p remultiplied by
207 // alpha. Instead we feed in a non-premultiplied color, and multiply its alpha by 163 // alpha. Instead we feed in a non-premultiplied color, and multiply its alpha by
208 // the mask texture color. The end result is that we get 164 // the mask texture color. The end result is that we get
209 // mask*paintAlpha*paintColor + (1-mask*paintAlpha)*dstCo lor 165 // mask*paintAlpha*paintColor + (1-mask*paintAlpha)*dstCo lor
210 int a = SkColorGetA(fSkPaint.getColor()); 166 int a = SkColorGetA(fSkPaint.getColor());
211 // paintAlpha 167 // paintAlpha
212 drawState->setColor(SkColorSetARGB(a, a, a, a)); 168 drawState->setColor(SkColorSetARGB(a, a, a, a));
213 // paintColor 169 // paintColor
214 drawState->setBlendConstant(colorNoPreMul); 170 drawState->setBlendConstant(colorNoPreMul);
215 drawState->setBlendFunc(kConstC_GrBlendCoeff, kISC_GrBlendCoeff); 171 drawState->setBlendFunc(kConstC_GrBlendCoeff, kISC_GrBlendCoeff);
216 } else { 172 } 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
217 // set back to normal in case we took LCD path previously. 188 // set back to normal in case we took LCD path previously.
218 drawState->setBlendFunc(fPaint.getSrcBlendCoeff(), fPaint.getDstBlen dCoeff()); 189 drawState->setBlendFunc(fPaint.getSrcBlendCoeff(), fPaint.getDstBlen dCoeff());
219 //drawState->setColor(fPaint.getColor()); 190 //drawState->setColor(fPaint.getColor());
220 // We're using per-vertex color. 191 // We're using per-vertex color.
221 SkASSERT(drawState->hasColorVertexAttribute()); 192 SkASSERT(drawState->hasColorVertexAttribute());
222 drawState->setColor(0xFFFFFFFF); 193 drawState->setColor(0xFFFFFFFF);
223 } 194 }
224 int nGlyphs = fCurrVertex / 4; 195 int nGlyphs = fCurrVertex / 4;
225 fDrawTarget->setIndexSourceToBuffer(fContext->getQuadIndexBuffer()); 196 fDrawTarget->setIndexSourceToBuffer(fContext->getQuadIndexBuffer());
226 fDrawTarget->drawIndexedInstances(kTriangles_GrPrimitiveType, 197 fDrawTarget->drawIndexedInstances(kTriangles_GrPrimitiveType,
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 SkScalarToFixed(x) - (glyph.fAdvanceX >> a lignShift), 590 SkScalarToFixed(x) - (glyph.fAdvanceX >> a lignShift),
620 SkScalarToFixed(y) - (glyph.fAdvanceY >> a lignShift), 591 SkScalarToFixed(y) - (glyph.fAdvanceY >> a lignShift),
621 fontScaler); 592 fontScaler);
622 } 593 }
623 pos += scalarsPerPosition; 594 pos += scalarsPerPosition;
624 } 595 }
625 } 596 }
626 597
627 this->finish(); 598 this->finish();
628 } 599 }
OLDNEW
« no previous file with comments | « src/gpu/GrDistanceFieldTextContext.h ('k') | src/gpu/effects/GrDistanceFieldTextureEffect.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698