| 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 "GrDrawTarget.h" | 10 #include "GrDrawTarget.h" |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 GrDrawState* drawState = fDrawTarget->drawState(); | 77 GrDrawState* drawState = fDrawTarget->drawState(); |
| 78 GrDrawState::AutoRestoreEffects are(drawState); | 78 GrDrawState::AutoRestoreEffects are(drawState); |
| 79 drawState->setFromPaint(fPaint, fContext->getMatrix(), fContext->getRenderTa
rget()); | 79 drawState->setFromPaint(fPaint, fContext->getMatrix(), fContext->getRenderTa
rget()); |
| 80 | 80 |
| 81 if (fCurrVertex > 0) { | 81 if (fCurrVertex > 0) { |
| 82 // setup our sampler state for our text texture/atlas | 82 // setup our sampler state for our text texture/atlas |
| 83 SkASSERT(SkIsAlign4(fCurrVertex)); | 83 SkASSERT(SkIsAlign4(fCurrVertex)); |
| 84 SkASSERT(fCurrTexture); | 84 SkASSERT(fCurrTexture); |
| 85 GrTextureParams params(SkShader::kRepeat_TileMode, GrTextureParams::kBil
erp_FilterMode); | 85 GrTextureParams params(SkShader::kRepeat_TileMode, GrTextureParams::kBil
erp_FilterMode); |
| 86 | 86 |
| 87 // This effect could be stored with one of the cache objects (atlas?) | 87 // Effects could be stored with one of the cache objects (atlas?) |
| 88 drawState->addCoverageEffect( | 88 if (fUseLCDText) { |
| 89 GrDistanceFieldTextureEffect::Create(fCurrTexture, para
ms, | 89 bool useBGR = SkDeviceProperties::Geometry::kBGR_Layout == |
| 90 fContext->getMatri
x().isSimilarity()), | 90 fDeviceProperties.fG
eometry.getLayout(); |
| 91 kGlyphCoordsAttributeIndex)->unref(); | 91 drawState->addCoverageEffect(GrDistanceFieldLCDTextureEffect::Create
( |
| 92 fCurrTexture, |
| 93 params, |
| 94 fContext->getMatrix(
).rectStaysRect() && |
| 95 fContext->getMatrix(
).isSimilarity(), |
| 96 useBGR), |
| 97 kGlyphCoordsAttributeIndex)->unref(); |
| 92 | 98 |
| 93 if (!GrPixelConfigIsAlphaOnly(fCurrTexture->config())) { | |
| 94 if (kOne_GrBlendCoeff != fPaint.getSrcBlendCoeff() || | 99 if (kOne_GrBlendCoeff != fPaint.getSrcBlendCoeff() || |
| 95 kISA_GrBlendCoeff != fPaint.getDstBlendCoeff() || | 100 kISA_GrBlendCoeff != fPaint.getDstBlendCoeff() || |
| 96 fPaint.numColorStages()) { | 101 fPaint.numColorStages()) { |
| 97 GrPrintf("LCD Text will not draw correctly.\n"); | 102 GrPrintf("LCD Text will not draw correctly.\n"); |
| 98 } | 103 } |
| 99 // We don't use the GrPaint's color in this case because it's been p
remultiplied by | 104 // We don't use the GrPaint's color in this case because it's been p
remultiplied by |
| 100 // alpha. Instead we feed in a non-premultiplied color, and multiply
its alpha by | 105 // alpha. Instead we feed in a non-premultiplied color, and multiply
its alpha by |
| 101 // the mask texture color. The end result is that we get | 106 // the mask texture color. The end result is that we get |
| 102 // mask*paintAlpha*paintColor + (1-mask*paintAlpha)*dstCo
lor | 107 // mask*paintAlpha*paintColor + (1-mask*paintAlpha)*dstCo
lor |
| 103 int a = SkColorGetA(fSkPaint.getColor()); | 108 int a = SkColorGetA(fSkPaint.getColor()); |
| 104 // paintAlpha | 109 // paintAlpha |
| 105 drawState->setColor(SkColorSetARGB(a, a, a, a)); | 110 drawState->setColor(SkColorSetARGB(a, a, a, a)); |
| 106 // paintColor | 111 // paintColor |
| 107 drawState->setBlendConstant(skcolor_to_grcolor_nopremultiply(fSkPain
t.getColor())); | 112 drawState->setBlendConstant(skcolor_to_grcolor_nopremultiply(fSkPain
t.getColor())); |
| 108 drawState->setBlendFunc(kConstC_GrBlendCoeff, kISC_GrBlendCoeff); | 113 drawState->setBlendFunc(kConstC_GrBlendCoeff, kISC_GrBlendCoeff); |
| 109 } else { | 114 } else { |
| 115 drawState->addCoverageEffect(GrDistanceFieldTextureEffect::Create(fC
urrTexture, params, |
| 116 fContext->getMatri
x().isSimilarity()), |
| 117 kGlyphCoordsAttributeIndex)->unref(); |
| 118 |
| 110 // set back to normal in case we took LCD path previously. | 119 // set back to normal in case we took LCD path previously. |
| 111 drawState->setBlendFunc(fPaint.getSrcBlendCoeff(), fPaint.getDstBlen
dCoeff()); | 120 drawState->setBlendFunc(fPaint.getSrcBlendCoeff(), fPaint.getDstBlen
dCoeff()); |
| 112 drawState->setColor(fPaint.getColor()); | 121 drawState->setColor(fPaint.getColor()); |
| 113 } | 122 } |
| 114 | 123 |
| 115 int nGlyphs = fCurrVertex / 4; | 124 int nGlyphs = fCurrVertex / 4; |
| 116 fDrawTarget->setIndexSourceToBuffer(fContext->getQuadIndexBuffer()); | 125 fDrawTarget->setIndexSourceToBuffer(fContext->getQuadIndexBuffer()); |
| 117 fDrawTarget->drawIndexedInstances(kTriangles_GrPrimitiveType, | 126 fDrawTarget->drawIndexedInstances(kTriangles_GrPrimitiveType, |
| 118 nGlyphs, | 127 nGlyphs, |
| 119 4, 6); | 128 4, 6); |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 fTextRatio = fSkPaint.getTextSize()/kSmallDFFontSize; | 320 fTextRatio = fSkPaint.getTextSize()/kSmallDFFontSize; |
| 312 fSkPaint.setTextSize(SkIntToScalar(kSmallDFFontSize)); | 321 fSkPaint.setTextSize(SkIntToScalar(kSmallDFFontSize)); |
| 313 } else if (fSkPaint.getTextSize() <= kMediumDFFontLimit) { | 322 } else if (fSkPaint.getTextSize() <= kMediumDFFontLimit) { |
| 314 fTextRatio = fSkPaint.getTextSize()/kMediumDFFontSize; | 323 fTextRatio = fSkPaint.getTextSize()/kMediumDFFontSize; |
| 315 fSkPaint.setTextSize(SkIntToScalar(kMediumDFFontSize)); | 324 fSkPaint.setTextSize(SkIntToScalar(kMediumDFFontSize)); |
| 316 } else { | 325 } else { |
| 317 fTextRatio = fSkPaint.getTextSize()/kLargeDFFontSize; | 326 fTextRatio = fSkPaint.getTextSize()/kLargeDFFontSize; |
| 318 fSkPaint.setTextSize(SkIntToScalar(kLargeDFFontSize)); | 327 fSkPaint.setTextSize(SkIntToScalar(kLargeDFFontSize)); |
| 319 } | 328 } |
| 320 | 329 |
| 330 fUseLCDText = fSkPaint.isLCDRenderText(); |
| 331 |
| 321 fSkPaint.setLCDRenderText(false); | 332 fSkPaint.setLCDRenderText(false); |
| 322 fSkPaint.setAutohinted(false); | 333 fSkPaint.setAutohinted(false); |
| 323 fSkPaint.setSubpixelText(true); | 334 fSkPaint.setSubpixelText(true); |
| 324 } | 335 } |
| 325 | 336 |
| 326 inline void GrDistanceFieldTextContext::finish() { | 337 inline void GrDistanceFieldTextContext::finish() { |
| 327 flushGlyphs(); | 338 flushGlyphs(); |
| 328 | 339 |
| 329 GrTextContext::finish(); | 340 GrTextContext::finish(); |
| 330 } | 341 } |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 461 SkScalarToFixed(y) - (glyph.fAdvanceY >> a
lignShift) | 472 SkScalarToFixed(y) - (glyph.fAdvanceY >> a
lignShift) |
| 462 + SK_FixedHalf, //d1g.fHalfSampleY, | 473 + SK_FixedHalf, //d1g.fHalfSampleY, |
| 463 fontScaler); | 474 fontScaler); |
| 464 } | 475 } |
| 465 pos += scalarsPerPosition; | 476 pos += scalarsPerPosition; |
| 466 } | 477 } |
| 467 } | 478 } |
| 468 | 479 |
| 469 this->finish(); | 480 this->finish(); |
| 470 } | 481 } |
| OLD | NEW |