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 "GrBitmapTextContext.h" | 10 #include "GrBitmapTextContext.h" |
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 kRectToRect_DistanceFieldEffectFlag : 0; | 398 kRectToRect_DistanceFieldEffectFlag : 0; |
399 bool useBGR = SkPixelGeometryIsBGR(fDeviceProperties.pixelGeometry()); | 399 bool useBGR = SkPixelGeometryIsBGR(fDeviceProperties.pixelGeometry()); |
400 flags |= fUseLCDText && useBGR ? kBGR_DistanceFieldEffectFlag : 0; | 400 flags |= fUseLCDText && useBGR ? kBGR_DistanceFieldEffectFlag : 0; |
401 | 401 |
402 // see if we need to create a new effect | 402 // see if we need to create a new effect |
403 if (textureUniqueID != fEffectTextureUniqueID || | 403 if (textureUniqueID != fEffectTextureUniqueID || |
404 filteredColor != fEffectColor || | 404 filteredColor != fEffectColor || |
405 flags != fEffectFlags) { | 405 flags != fEffectFlags) { |
406 if (fUseLCDText) { | 406 if (fUseLCDText) { |
407 GrColor colorNoPreMul = skcolor_to_grcolor_nopremultiply(filteredCol
or); | 407 GrColor colorNoPreMul = skcolor_to_grcolor_nopremultiply(filteredCol
or); |
408 fCachedGeometryProcessor.reset(GrDistanceFieldLCDTextureEffect::Crea
te(fCurrTexture, | 408 |
| 409 // We don't use the GrPaint's color in this case because it's been p
remultiplied by |
| 410 // alpha. Instead we feed in a non-premultiplied color, and multiply
its alpha by |
| 411 // the mask texture color. The end result is that we get |
| 412 // mask*paintAlpha*paintColor + (1-mask*paintAlpha)*dstCo
lor |
| 413 int a = GrColorUnpackA(fSkPaint.getColor()); |
| 414 GrColor color = GrColorPackRGBA(a, a, a, a); |
| 415 fCachedGeometryProcessor.reset(GrDistanceFieldLCDTextureEffect::Crea
te(color, |
| 416
fCurrTexture, |
409
params, | 417
params, |
410
fGammaTexture, | 418
fGammaTexture, |
411
gammaParams, | 419
gammaParams, |
412
colorNoPreMul, | 420
colorNoPreMul, |
413
flags)); | 421
flags)); |
414 } else { | 422 } else { |
415 flags |= kColorAttr_DistanceFieldEffectFlag; | 423 flags |= kColorAttr_DistanceFieldEffectFlag; |
| 424 GrColor color = fSkPaint.getColor(); |
416 #ifdef SK_GAMMA_APPLY_TO_A8 | 425 #ifdef SK_GAMMA_APPLY_TO_A8 |
417 U8CPU lum = SkColorSpaceLuminance::computeLuminance(fDevicePropertie
s.gamma(), | 426 U8CPU lum = SkColorSpaceLuminance::computeLuminance(fDevicePropertie
s.gamma(), |
418 filteredColor); | 427 filteredColor); |
419 fCachedGeometryProcessor.reset(GrDistanceFieldTextureEffect::Create(
fCurrTexture, | 428 fCachedGeometryProcessor.reset(GrDistanceFieldTextureEffect::Create(
color, |
| 429
fCurrTexture, |
420
params, | 430
params, |
421
fGammaTexture, | 431
fGammaTexture, |
422
gammaParams, | 432
gammaParams, |
423
lum/255.f, | 433
lum/255.f, |
424
flags)); | 434
flags)); |
425 #else | 435 #else |
426 fCachedGeometryProcessor.reset(GrDistanceFieldNoGammaTextureEffect::
Create(fCurrTexture, | 436 fCachedGeometryProcessor.reset(GrDistanceFieldNoGammaTextureEffect::
Create(color, |
427
params, flags)); | 437
fCurrTexture, |
| 438
params, |
| 439
flags)); |
428 #endif | 440 #endif |
429 } | 441 } |
430 fEffectTextureUniqueID = textureUniqueID; | 442 fEffectTextureUniqueID = textureUniqueID; |
431 fEffectColor = filteredColor; | 443 fEffectColor = filteredColor; |
432 fEffectFlags = flags; | 444 fEffectFlags = flags; |
433 } | 445 } |
434 | 446 |
435 } | 447 } |
436 | 448 |
437 inline bool GrDistanceFieldTextContext::uploadGlyph(GrGlyph* glyph, GrFontScaler
* scaler) { | 449 inline bool GrDistanceFieldTextContext::uploadGlyph(GrGlyph* glyph, GrFontScaler
* scaler) { |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
635 if (fUseLCDText) { | 647 if (fUseLCDText) { |
636 GrColor colorNoPreMul = skcolor_to_grcolor_nopremultiply(filteredCol
or); | 648 GrColor colorNoPreMul = skcolor_to_grcolor_nopremultiply(filteredCol
or); |
637 | 649 |
638 // TODO: move supportsRGBCoverage check to setupCoverageEffect and o
nly add LCD | 650 // TODO: move supportsRGBCoverage check to setupCoverageEffect and o
nly add LCD |
639 // processor if the xp can support it. For now we will simply assume
that if | 651 // processor if the xp can support it. For now we will simply assume
that if |
640 // fUseLCDText is true, then we have a known color output. | 652 // fUseLCDText is true, then we have a known color output. |
641 if (!drawState.getXPFactory()->supportsRGBCoverage(0, kRGBA_GrColorC
omponentFlags)) { | 653 if (!drawState.getXPFactory()->supportsRGBCoverage(0, kRGBA_GrColorC
omponentFlags)) { |
642 SkDebugf("LCD Text will not draw correctly.\n"); | 654 SkDebugf("LCD Text will not draw correctly.\n"); |
643 } | 655 } |
644 SkASSERT(!drawState.hasColorVertexAttribute()); | 656 SkASSERT(!drawState.hasColorVertexAttribute()); |
645 // We don't use the GrPaint's color in this case because it's been p
remultiplied by | |
646 // alpha. Instead we feed in a non-premultiplied color, and multiply
its alpha by | |
647 // the mask texture color. The end result is that we get | |
648 // mask*paintAlpha*paintColor + (1-mask*paintAlpha)*dstCo
lor | |
649 int a = SkColorGetA(fSkPaint.getColor()); | |
650 // paintAlpha | |
651 drawState.setColor(SkColorSetARGB(a, a, a, a)); | |
652 // paintColor | 657 // paintColor |
653 drawState.setBlendConstant(colorNoPreMul); | 658 drawState.setBlendConstant(colorNoPreMul); |
654 drawState.setBlendFunc(kConstC_GrBlendCoeff, kISC_GrBlendCoeff); | 659 drawState.setBlendFunc(kConstC_GrBlendCoeff, kISC_GrBlendCoeff); |
655 } else { | 660 } else { |
656 if (0xFF == GrColorUnpackA(fPaint.getColor())) { | 661 if (0xFF == GrColorUnpackA(fPaint.getColor())) { |
657 drawState.setHint(GrDrawState::kVertexColorsAreOpaque_Hint, true
); | 662 drawState.setHint(GrDrawState::kVertexColorsAreOpaque_Hint, true
); |
658 } | 663 } |
659 // set back to normal in case we took LCD path previously. | 664 // set back to normal in case we took LCD path previously. |
660 drawState.setBlendFunc(fPaint.getSrcBlendCoeff(), fPaint.getDstBlend
Coeff()); | 665 drawState.setBlendFunc(fPaint.getSrcBlendCoeff(), fPaint.getDstBlend
Coeff()); |
661 // We're using per-vertex color. | 666 // We're using per-vertex color. |
(...skipping 16 matching lines...) Expand all Loading... |
678 } | 683 } |
679 } | 684 } |
680 | 685 |
681 inline void GrDistanceFieldTextContext::finish() { | 686 inline void GrDistanceFieldTextContext::finish() { |
682 this->flush(); | 687 this->flush(); |
683 fTotalVertexCount = 0; | 688 fTotalVertexCount = 0; |
684 | 689 |
685 GrTextContext::finish(); | 690 GrTextContext::finish(); |
686 } | 691 } |
687 | 692 |
OLD | NEW |