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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 unsigned g = SkColorGetG(c); | 117 unsigned g = SkColorGetG(c); |
118 unsigned b = SkColorGetB(c); | 118 unsigned b = SkColorGetB(c); |
119 return GrColorPackRGBA(r, g, b, 0xff); | 119 return GrColorPackRGBA(r, g, b, 0xff); |
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 const SkMatrix& ctm = fContext->getMatrix(); |
127 | 128 |
128 // set up any flags | 129 // set up any flags |
129 uint32_t flags = 0; | 130 uint32_t flags = 0; |
130 flags |= fTextMatrix.isSimilarity() ? kSimilarity_DistanceFieldEffectFlag :
0; | 131 flags |= ctm.isSimilarity() ? kSimilarity_DistanceFieldEffectFlag : 0; |
131 flags |= fUseLCDText ? kUseLCD_DistanceFieldEffectFlag : 0; | 132 flags |= fUseLCDText ? kUseLCD_DistanceFieldEffectFlag : 0; |
132 flags |= fUseLCDText && fTextMatrix.rectStaysRect() ? | 133 flags |= fUseLCDText && ctm.rectStaysRect() ? |
133 kRectToRect_DistanceFieldEffectFlag : 0; | 134 kRectToRect_DistanceFieldEffectFlag : 0; |
134 bool useBGR = SkPixelGeometryIsBGR(fDeviceProperties.fPixelGeometry); | 135 bool useBGR = SkPixelGeometryIsBGR(fDeviceProperties.fPixelGeometry); |
135 flags |= fUseLCDText && useBGR ? kBGR_DistanceFieldEffectFlag : 0; | 136 flags |= fUseLCDText && useBGR ? kBGR_DistanceFieldEffectFlag : 0; |
136 | 137 |
137 // see if we need to create a new effect | 138 // see if we need to create a new effect |
138 if (textureUniqueID != fEffectTextureUniqueID || | 139 if (textureUniqueID != fEffectTextureUniqueID || |
139 filteredColor != fEffectColor || | 140 filteredColor != fEffectColor || |
140 flags != fEffectFlags) { | 141 flags != fEffectFlags) { |
141 if (fUseLCDText) { | 142 if (fUseLCDText) { |
142 GrColor colorNoPreMul = skcolor_to_grcolor_nopremultiply(filteredCol
or); | 143 GrColor colorNoPreMul = skcolor_to_grcolor_nopremultiply(filteredCol
or); |
(...skipping 26 matching lines...) Expand all Loading... |
169 } | 170 } |
170 | 171 |
171 void GrDistanceFieldTextContext::flushGlyphs() { | 172 void GrDistanceFieldTextContext::flushGlyphs() { |
172 if (NULL == fDrawTarget) { | 173 if (NULL == fDrawTarget) { |
173 return; | 174 return; |
174 } | 175 } |
175 | 176 |
176 GrDrawState* drawState = fDrawTarget->drawState(); | 177 GrDrawState* drawState = fDrawTarget->drawState(); |
177 GrDrawState::AutoRestoreEffects are(drawState); | 178 GrDrawState::AutoRestoreEffects are(drawState); |
178 | 179 |
179 drawState->setFromPaint(fPaint, fTextMatrix, fContext->getRenderTarget()); | 180 drawState->setFromPaint(fPaint, fContext->getMatrix(), fContext->getRenderTa
rget()); |
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 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 } | 439 } |
439 | 440 |
440 fCurrVertex += 4; | 441 fCurrVertex += 4; |
441 } | 442 } |
442 | 443 |
443 inline void GrDistanceFieldTextContext::init(const GrPaint& paint, const SkPaint
& skPaint) { | 444 inline void GrDistanceFieldTextContext::init(const GrPaint& paint, const SkPaint
& skPaint) { |
444 GrTextContext::init(paint, skPaint); | 445 GrTextContext::init(paint, skPaint); |
445 | 446 |
446 fStrike = NULL; | 447 fStrike = NULL; |
447 | 448 |
448 fTextMatrix = fContext->getMatrix(); | 449 const SkMatrix& ctm = fContext->getMatrix(); |
449 | 450 |
450 // getMaxScale doesn't support perspective, so neither do we at the moment | 451 // getMaxScale doesn't support perspective, so neither do we at the moment |
451 SkASSERT(!fTextMatrix.hasPerspective()); | 452 SkASSERT(!ctm.hasPerspective()); |
452 SkScalar maxScale = fTextMatrix.getMaxScale(); | 453 SkScalar maxScale = ctm.getMaxScale(); |
453 SkScalar textSize = fSkPaint.getTextSize(); | 454 SkScalar textSize = fSkPaint.getTextSize(); |
454 // if we have non-unity scale, we need to adjust our text size accordingly | 455 SkScalar scaledTextSize = textSize; |
455 // to avoid aliasing, and prescale the matrix by the inverse to end up with
the same size | 456 // if we have non-unity scale, we need to choose our base text size |
| 457 // based on the SkPaint's text size multiplied by the max scale factor |
456 // TODO: do we need to do this if we're scaling down (i.e. maxScale < 1)? | 458 // TODO: do we need to do this if we're scaling down (i.e. maxScale < 1)? |
457 if (maxScale > 0 && !SkScalarNearlyEqual(maxScale, SK_Scalar1)) { | 459 if (maxScale > 0 && !SkScalarNearlyEqual(maxScale, SK_Scalar1)) { |
458 textSize *= maxScale; | 460 scaledTextSize *= maxScale; |
459 fTextMatrix.preScale(SK_Scalar1 / maxScale, SK_Scalar1 / maxScale); | |
460 } | 461 } |
461 | 462 |
462 fCurrVertex = 0; | 463 fCurrVertex = 0; |
463 | 464 |
464 fVertices = NULL; | 465 fVertices = NULL; |
465 | 466 |
466 if (textSize <= kSmallDFFontLimit) { | 467 if (scaledTextSize <= kSmallDFFontLimit) { |
467 fTextRatio = textSize / kSmallDFFontSize; | 468 fTextRatio = textSize / kSmallDFFontSize; |
468 fSkPaint.setTextSize(SkIntToScalar(kSmallDFFontSize)); | 469 fSkPaint.setTextSize(SkIntToScalar(kSmallDFFontSize)); |
469 } else if (textSize <= kMediumDFFontLimit) { | 470 } else if (scaledTextSize <= kMediumDFFontLimit) { |
470 fTextRatio = textSize / kMediumDFFontSize; | 471 fTextRatio = textSize / kMediumDFFontSize; |
471 fSkPaint.setTextSize(SkIntToScalar(kMediumDFFontSize)); | 472 fSkPaint.setTextSize(SkIntToScalar(kMediumDFFontSize)); |
472 } else { | 473 } else { |
473 fTextRatio = textSize / kLargeDFFontSize; | 474 fTextRatio = textSize / kLargeDFFontSize; |
474 fSkPaint.setTextSize(SkIntToScalar(kLargeDFFontSize)); | 475 fSkPaint.setTextSize(SkIntToScalar(kLargeDFFontSize)); |
475 } | 476 } |
476 | 477 |
477 fUseLCDText = fSkPaint.isLCDRenderText(); | 478 fUseLCDText = fSkPaint.isLCDRenderText(); |
478 | 479 |
479 fSkPaint.setLCDRenderText(false); | 480 fSkPaint.setLCDRenderText(false); |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
663 SkScalarToFixed(x) - (glyph.fAdvanceX >> a
lignShift), | 664 SkScalarToFixed(x) - (glyph.fAdvanceX >> a
lignShift), |
664 SkScalarToFixed(y) - (glyph.fAdvanceY >> a
lignShift), | 665 SkScalarToFixed(y) - (glyph.fAdvanceY >> a
lignShift), |
665 fontScaler); | 666 fontScaler); |
666 } | 667 } |
667 pos += scalarsPerPosition; | 668 pos += scalarsPerPosition; |
668 } | 669 } |
669 } | 670 } |
670 | 671 |
671 this->finish(); | 672 this->finish(); |
672 } | 673 } |
OLD | NEW |