| 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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 } | 120 } |
| 121 | 121 |
| 122 void GrDistanceFieldTextContext::setupCoverageEffect(const SkColor& filteredColo
r) { | 122 void GrDistanceFieldTextContext::setupCoverageEffect(const SkColor& filteredColo
r) { |
| 123 GrTextureParams params(SkShader::kRepeat_TileMode, GrTextureParams::kBilerp_
FilterMode); | 123 GrTextureParams params(SkShader::kRepeat_TileMode, GrTextureParams::kBilerp_
FilterMode); |
| 124 GrTextureParams gammaParams(SkShader::kClamp_TileMode, GrTextureParams::kNon
e_FilterMode); | 124 GrTextureParams gammaParams(SkShader::kClamp_TileMode, GrTextureParams::kNon
e_FilterMode); |
| 125 | 125 |
| 126 uint32_t textureUniqueID = fCurrTexture->getUniqueID(); | 126 uint32_t textureUniqueID = fCurrTexture->getUniqueID(); |
| 127 | 127 |
| 128 // set up any flags | 128 // set up any flags |
| 129 uint32_t flags = 0; | 129 uint32_t flags = 0; |
| 130 flags |= fContext->getMatrix().isSimilarity() ? kSimilarity_DistanceFieldEff
ectFlag : 0; | 130 flags |= fTextMatrix.isSimilarity() ? kSimilarity_DistanceFieldEffectFlag :
0; |
| 131 flags |= fUseLCDText ? kUseLCD_DistanceFieldEffectFlag : 0; | 131 flags |= fUseLCDText ? kUseLCD_DistanceFieldEffectFlag : 0; |
| 132 flags |= fUseLCDText && fContext->getMatrix().rectStaysRect() ? | 132 flags |= fUseLCDText && fTextMatrix.rectStaysRect() ? |
| 133 kRectToRect_DistanceFieldEffectFlag : 0; | 133 kRectToRect_DistanceFieldEffectFlag : 0; |
| 134 bool useBGR = SkDeviceProperties::Geometry::kBGR_Layout == | 134 bool useBGR = SkDeviceProperties::Geometry::kBGR_Layout == |
| 135 fDeviceProperties.fGeometry.getLayout(); | 135 fDeviceProperties.fGeometry.getLayout(); |
| 136 flags |= fUseLCDText && useBGR ? kBGR_DistanceFieldEffectFlag : 0; | 136 flags |= fUseLCDText && useBGR ? kBGR_DistanceFieldEffectFlag : 0; |
| 137 | 137 |
| 138 // see if we need to create a new effect | 138 // see if we need to create a new effect |
| 139 if (textureUniqueID != fEffectTextureUniqueID || | 139 if (textureUniqueID != fEffectTextureUniqueID || |
| 140 filteredColor != fEffectColor || | 140 filteredColor != fEffectColor || |
| 141 flags != fEffectFlags) { | 141 flags != fEffectFlags) { |
| 142 if (fUseLCDText) { | 142 if (fUseLCDText) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 169 | 169 |
| 170 } | 170 } |
| 171 | 171 |
| 172 void GrDistanceFieldTextContext::flushGlyphs() { | 172 void GrDistanceFieldTextContext::flushGlyphs() { |
| 173 if (NULL == fDrawTarget) { | 173 if (NULL == fDrawTarget) { |
| 174 return; | 174 return; |
| 175 } | 175 } |
| 176 | 176 |
| 177 GrDrawState* drawState = fDrawTarget->drawState(); | 177 GrDrawState* drawState = fDrawTarget->drawState(); |
| 178 GrDrawState::AutoRestoreEffects are(drawState); | 178 GrDrawState::AutoRestoreEffects are(drawState); |
| 179 drawState->setFromPaint(fPaint, fContext->getMatrix(), fContext->getRenderTa
rget()); | 179 |
| 180 drawState->setFromPaint(fPaint, fTextMatrix, fContext->getRenderTarget()); |
| 180 | 181 |
| 181 if (fCurrVertex > 0) { | 182 if (fCurrVertex > 0) { |
| 182 // setup our sampler state for our text texture/atlas | 183 // setup our sampler state for our text texture/atlas |
| 183 SkASSERT(SkIsAlign4(fCurrVertex)); | 184 SkASSERT(SkIsAlign4(fCurrVertex)); |
| 184 | 185 |
| 185 // get our current color | 186 // get our current color |
| 186 SkColor filteredColor; | 187 SkColor filteredColor; |
| 187 SkColorFilter* colorFilter = fSkPaint.getColorFilter(); | 188 SkColorFilter* colorFilter = fSkPaint.getColorFilter(); |
| 188 if (colorFilter) { | 189 if (colorFilter) { |
| 189 filteredColor = colorFilter->filterColor(fSkPaint.getColor()); | 190 filteredColor = colorFilter->filterColor(fSkPaint.getColor()); |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 436 } | 437 } |
| 437 | 438 |
| 438 fCurrVertex += 4; | 439 fCurrVertex += 4; |
| 439 } | 440 } |
| 440 | 441 |
| 441 inline void GrDistanceFieldTextContext::init(const GrPaint& paint, const SkPaint
& skPaint) { | 442 inline void GrDistanceFieldTextContext::init(const GrPaint& paint, const SkPaint
& skPaint) { |
| 442 GrTextContext::init(paint, skPaint); | 443 GrTextContext::init(paint, skPaint); |
| 443 | 444 |
| 444 fStrike = NULL; | 445 fStrike = NULL; |
| 445 | 446 |
| 447 fTextMatrix = fContext->getMatrix(); |
| 448 |
| 449 // getMaxScale doesn't support perspective, so neither do we at the moment |
| 450 SkASSERT(!fTextMatrix.hasPerspective()); |
| 451 SkScalar maxScale = fTextMatrix.getMaxScale(); |
| 452 SkScalar textSize = fSkPaint.getTextSize(); |
| 453 // if we have non-unity scale, we need to adjust our text size accordingly |
| 454 // to avoid aliasing, and prescale the matrix by the inverse to end up with
the same size |
| 455 // TODO: do we need to do this if we're scaling down (i.e. maxScale < 1)? |
| 456 if (maxScale > 0 && !SkScalarNearlyEqual(maxScale, SK_Scalar1)) { |
| 457 textSize *= maxScale; |
| 458 fTextMatrix.preScale(SK_Scalar1 / maxScale, SK_Scalar1 / maxScale); |
| 459 } |
| 460 |
| 446 fCurrVertex = 0; | 461 fCurrVertex = 0; |
| 447 | 462 |
| 448 fVertices = NULL; | 463 fVertices = NULL; |
| 449 | 464 |
| 450 if (fSkPaint.getTextSize() <= kSmallDFFontLimit) { | 465 if (textSize <= kSmallDFFontLimit) { |
| 451 fTextRatio = fSkPaint.getTextSize()/kSmallDFFontSize; | 466 fTextRatio = textSize / kSmallDFFontSize; |
| 452 fSkPaint.setTextSize(SkIntToScalar(kSmallDFFontSize)); | 467 fSkPaint.setTextSize(SkIntToScalar(kSmallDFFontSize)); |
| 453 } else if (fSkPaint.getTextSize() <= kMediumDFFontLimit) { | 468 } else if (textSize <= kMediumDFFontLimit) { |
| 454 fTextRatio = fSkPaint.getTextSize()/kMediumDFFontSize; | 469 fTextRatio = textSize / kMediumDFFontSize; |
| 455 fSkPaint.setTextSize(SkIntToScalar(kMediumDFFontSize)); | 470 fSkPaint.setTextSize(SkIntToScalar(kMediumDFFontSize)); |
| 456 } else { | 471 } else { |
| 457 fTextRatio = fSkPaint.getTextSize()/kLargeDFFontSize; | 472 fTextRatio = textSize / kLargeDFFontSize; |
| 458 fSkPaint.setTextSize(SkIntToScalar(kLargeDFFontSize)); | 473 fSkPaint.setTextSize(SkIntToScalar(kLargeDFFontSize)); |
| 459 } | 474 } |
| 460 | 475 |
| 461 fUseLCDText = fSkPaint.isLCDRenderText(); | 476 fUseLCDText = fSkPaint.isLCDRenderText(); |
| 462 | 477 |
| 463 fSkPaint.setLCDRenderText(false); | 478 fSkPaint.setLCDRenderText(false); |
| 464 fSkPaint.setAutohinted(false); | 479 fSkPaint.setAutohinted(false); |
| 465 fSkPaint.setHinting(SkPaint::kNormal_Hinting); | 480 fSkPaint.setHinting(SkPaint::kNormal_Hinting); |
| 466 fSkPaint.setSubpixelText(true); | 481 fSkPaint.setSubpixelText(true); |
| 467 | 482 |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 647 SkScalarToFixed(x) - (glyph.fAdvanceX >> a
lignShift), | 662 SkScalarToFixed(x) - (glyph.fAdvanceX >> a
lignShift), |
| 648 SkScalarToFixed(y) - (glyph.fAdvanceY >> a
lignShift), | 663 SkScalarToFixed(y) - (glyph.fAdvanceY >> a
lignShift), |
| 649 fontScaler); | 664 fontScaler); |
| 650 } | 665 } |
| 651 pos += scalarsPerPosition; | 666 pos += scalarsPerPosition; |
| 652 } | 667 } |
| 653 } | 668 } |
| 654 | 669 |
| 655 this->finish(); | 670 this->finish(); |
| 656 } | 671 } |
| OLD | NEW |