Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 123 } | 123 } |
| 124 | 124 |
| 125 void GrDistanceFieldTextContext::setupCoverageEffect(const SkColor& filteredColo r) { | 125 void GrDistanceFieldTextContext::setupCoverageEffect(const SkColor& filteredColo r) { |
| 126 GrTextureParams params(SkShader::kRepeat_TileMode, GrTextureParams::kBilerp_ FilterMode); | 126 GrTextureParams params(SkShader::kRepeat_TileMode, GrTextureParams::kBilerp_ FilterMode); |
| 127 GrTextureParams gammaParams(SkShader::kClamp_TileMode, GrTextureParams::kNon e_FilterMode); | 127 GrTextureParams gammaParams(SkShader::kClamp_TileMode, GrTextureParams::kNon e_FilterMode); |
| 128 | 128 |
| 129 uint32_t textureUniqueID = fCurrTexture->getUniqueID(); | 129 uint32_t textureUniqueID = fCurrTexture->getUniqueID(); |
| 130 | 130 |
| 131 // set up any flags | 131 // set up any flags |
| 132 uint32_t flags = 0; | 132 uint32_t flags = 0; |
| 133 flags |= fContext->getMatrix().isSimilarity() ? kSimilarity_DistanceFieldEff ectFlag : 0; | 133 flags |= fTextMatrix.isSimilarity() ? kSimilarity_DistanceFieldEffectFlag : 0; |
| 134 flags |= fUseLCDText ? kUseLCD_DistanceFieldEffectFlag : 0; | 134 flags |= fUseLCDText ? kUseLCD_DistanceFieldEffectFlag : 0; |
| 135 flags |= fUseLCDText && fContext->getMatrix().rectStaysRect() ? | 135 flags |= fUseLCDText && fTextMatrix.rectStaysRect() ? |
| 136 kRectToRect_DistanceFieldEffectFlag : 0; | 136 kRectToRect_DistanceFieldEffectFlag : 0; |
| 137 bool useBGR = SkDeviceProperties::Geometry::kBGR_Layout == | 137 bool useBGR = SkDeviceProperties::Geometry::kBGR_Layout == |
| 138 fDeviceProperties.fGeometry.getLayout(); | 138 fDeviceProperties.fGeometry.getLayout(); |
| 139 flags |= fUseLCDText && useBGR ? kBGR_DistanceFieldEffectFlag : 0; | 139 flags |= fUseLCDText && useBGR ? kBGR_DistanceFieldEffectFlag : 0; |
| 140 | 140 |
| 141 // see if we need to create a new effect | 141 // see if we need to create a new effect |
| 142 if (textureUniqueID != fEffectTextureUniqueID || | 142 if (textureUniqueID != fEffectTextureUniqueID || |
| 143 filteredColor != fEffectColor || | 143 filteredColor != fEffectColor || |
| 144 flags != fEffectFlags) { | 144 flags != fEffectFlags) { |
| 145 if (fUseLCDText) { | 145 if (fUseLCDText) { |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 172 | 172 |
| 173 } | 173 } |
| 174 | 174 |
| 175 void GrDistanceFieldTextContext::flushGlyphs() { | 175 void GrDistanceFieldTextContext::flushGlyphs() { |
| 176 if (NULL == fDrawTarget) { | 176 if (NULL == fDrawTarget) { |
| 177 return; | 177 return; |
| 178 } | 178 } |
| 179 | 179 |
| 180 GrDrawState* drawState = fDrawTarget->drawState(); | 180 GrDrawState* drawState = fDrawTarget->drawState(); |
| 181 GrDrawState::AutoRestoreEffects are(drawState); | 181 GrDrawState::AutoRestoreEffects are(drawState); |
| 182 drawState->setFromPaint(fPaint, fContext->getMatrix(), fContext->getRenderTa rget()); | 182 |
| 183 drawState->setFromPaint(fPaint, fTextMatrix, fContext->getRenderTarget()); | |
| 183 | 184 |
| 184 if (fCurrVertex > 0) { | 185 if (fCurrVertex > 0) { |
| 185 // setup our sampler state for our text texture/atlas | 186 // setup our sampler state for our text texture/atlas |
| 186 SkASSERT(SkIsAlign4(fCurrVertex)); | 187 SkASSERT(SkIsAlign4(fCurrVertex)); |
| 187 | 188 |
| 188 // get our current color | 189 // get our current color |
| 189 SkColor filteredColor; | 190 SkColor filteredColor; |
| 190 SkColorFilter* colorFilter = fSkPaint.getColorFilter(); | 191 SkColorFilter* colorFilter = fSkPaint.getColorFilter(); |
| 191 if (colorFilter) { | 192 if (colorFilter) { |
| 192 filteredColor = colorFilter->filterColor(fSkPaint.getColor()); | 193 filteredColor = colorFilter->filterColor(fSkPaint.getColor()); |
| 193 } else { | 194 } else { |
| 194 filteredColor = fSkPaint.getColor(); | 195 filteredColor = fSkPaint.getColor(); |
| 195 } | 196 } |
| 196 this->setupCoverageEffect(filteredColor); | 197 this->setupCoverageEffect(filteredColor); |
| 197 | 198 |
| 198 // Effects could be stored with one of the cache objects (atlas?) | 199 // Effects could be stored with one of the cache objects (atlas?) |
| 199 int coordsIdx = drawState->hasColorVertexAttribute() ? kGlyphCoordsWithC olorAttributeIndex : | 200 int coordsIdx = drawState->hasColorVertexAttribute() ? kGlyphCoordsWithC olorAttributeIndex : |
| 200 kGlyphCoordsNoCol orAttributeIndex; | 201 kGlyphCoordsNoCol orAttributeIndex; |
| 201 drawState->addCoverageEffect(fCachedEffect.get(), coordsIdx); | 202 drawState->setGeometryProcessor(fCachedEffect.get(), coordsIdx); |
| 202 | 203 |
| 203 // Set draw state | 204 // Set draw state |
| 204 if (fUseLCDText) { | 205 if (fUseLCDText) { |
| 205 GrColor colorNoPreMul = skcolor_to_grcolor_nopremultiply(filteredCol or); | 206 GrColor colorNoPreMul = skcolor_to_grcolor_nopremultiply(filteredCol or); |
| 206 if (kOne_GrBlendCoeff != fPaint.getSrcBlendCoeff() || | 207 if (kOne_GrBlendCoeff != fPaint.getSrcBlendCoeff() || |
| 207 kISA_GrBlendCoeff != fPaint.getDstBlendCoeff() || | 208 kISA_GrBlendCoeff != fPaint.getDstBlendCoeff() || |
| 208 fPaint.numColorStages()) { | 209 fPaint.numColorStages()) { |
| 209 GrPrintf("LCD Text will not draw correctly.\n"); | 210 GrPrintf("LCD Text will not draw correctly.\n"); |
| 210 } | 211 } |
| 211 SkASSERT(!drawState->hasColorVertexAttribute()); | 212 SkASSERT(!drawState->hasColorVertexAttribute()); |
| 212 // We don't use the GrPaint's color in this case because it's been p remultiplied by | 213 // We don't use the GrPaint's color in this case because it's been p remultiplied by |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 441 } | 442 } |
| 442 | 443 |
| 443 fCurrVertex += 4; | 444 fCurrVertex += 4; |
| 444 } | 445 } |
| 445 | 446 |
| 446 inline void GrDistanceFieldTextContext::init(const GrPaint& paint, const SkPaint & skPaint) { | 447 inline void GrDistanceFieldTextContext::init(const GrPaint& paint, const SkPaint & skPaint) { |
| 447 GrTextContext::init(paint, skPaint); | 448 GrTextContext::init(paint, skPaint); |
| 448 | 449 |
| 449 fStrike = NULL; | 450 fStrike = NULL; |
| 450 | 451 |
| 452 fTextMatrix = fContext->getMatrix(); | |
| 453 | |
| 454 // getMaxScale doesn't support perspective, so neither do we at the moment | |
| 455 SkASSERT(!fTextMatrix.hasPerspective()); | |
| 456 SkScalar maxScale = fTextMatrix.getMaxScale(); | |
| 457 SkScalar textSize = fSkPaint.getTextSize(); | |
| 458 // if we have non-unity scale, we need to adjust our text size accordingly | |
| 459 // to avoid aliasing, and prescale the matrix by the inverse to end up with the same size | |
| 460 // TODO: do we need to do this if we're scaling down (i.e. maxScale < 1)? | |
|
bsalomon
2014/09/15 13:33:19
Should your GM test this?
jvanverth1
2014/09/15 13:43:53
Yes, probably :)
| |
| 461 if (maxScale > 0 && !SkScalarNearlyEqual(maxScale, SK_Scalar1)) { | |
| 462 textSize *= maxScale; | |
| 463 fTextMatrix.preScale(SK_Scalar1 / maxScale, SK_Scalar1 / maxScale); | |
| 464 } | |
| 465 | |
| 451 fCurrVertex = 0; | 466 fCurrVertex = 0; |
| 452 | 467 |
| 453 fVertices = NULL; | 468 fVertices = NULL; |
| 454 | 469 |
| 455 if (fSkPaint.getTextSize() <= kSmallDFFontLimit) { | 470 if (textSize <= kSmallDFFontLimit) { |
| 456 fTextRatio = fSkPaint.getTextSize()/kSmallDFFontSize; | 471 fTextRatio = textSize / kSmallDFFontSize; |
| 457 fSkPaint.setTextSize(SkIntToScalar(kSmallDFFontSize)); | 472 fSkPaint.setTextSize(SkIntToScalar(kSmallDFFontSize)); |
| 458 } else if (fSkPaint.getTextSize() <= kMediumDFFontLimit) { | 473 } else if (textSize <= kMediumDFFontLimit) { |
| 459 fTextRatio = fSkPaint.getTextSize()/kMediumDFFontSize; | 474 fTextRatio = textSize / kMediumDFFontSize; |
| 460 fSkPaint.setTextSize(SkIntToScalar(kMediumDFFontSize)); | 475 fSkPaint.setTextSize(SkIntToScalar(kMediumDFFontSize)); |
| 461 } else { | 476 } else { |
| 462 fTextRatio = fSkPaint.getTextSize()/kLargeDFFontSize; | 477 fTextRatio = textSize / kLargeDFFontSize; |
| 463 fSkPaint.setTextSize(SkIntToScalar(kLargeDFFontSize)); | 478 fSkPaint.setTextSize(SkIntToScalar(kLargeDFFontSize)); |
| 464 } | 479 } |
| 465 | 480 |
| 466 fUseLCDText = fSkPaint.isLCDRenderText(); | 481 fUseLCDText = fSkPaint.isLCDRenderText(); |
| 467 | 482 |
| 468 fSkPaint.setLCDRenderText(false); | 483 fSkPaint.setLCDRenderText(false); |
| 469 fSkPaint.setAutohinted(false); | 484 fSkPaint.setAutohinted(false); |
| 470 fSkPaint.setHinting(SkPaint::kNormal_Hinting); | 485 fSkPaint.setHinting(SkPaint::kNormal_Hinting); |
| 471 fSkPaint.setSubpixelText(true); | 486 fSkPaint.setSubpixelText(true); |
| 472 | 487 |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 652 SkScalarToFixed(x) - (glyph.fAdvanceX >> a lignShift), | 667 SkScalarToFixed(x) - (glyph.fAdvanceX >> a lignShift), |
| 653 SkScalarToFixed(y) - (glyph.fAdvanceY >> a lignShift), | 668 SkScalarToFixed(y) - (glyph.fAdvanceY >> a lignShift), |
| 654 fontScaler); | 669 fontScaler); |
| 655 } | 670 } |
| 656 pos += scalarsPerPosition; | 671 pos += scalarsPerPosition; |
| 657 } | 672 } |
| 658 } | 673 } |
| 659 | 674 |
| 660 this->finish(); | 675 this->finish(); |
| 661 } | 676 } |
| OLD | NEW |