| 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 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 GrColor colorNoPreMul = skcolor_to_grcolor_nopremultiply(filteredCol
or); | 408 GrColor colorNoPreMul = skcolor_to_grcolor_nopremultiply(filteredCol
or); |
| 409 fCachedGeometryProcessor.reset(GrDistanceFieldLCDTextureEffect::Crea
te(color, | 409 fCachedGeometryProcessor.reset(GrDistanceFieldLCDTextureEffect::Crea
te(color, |
| 410
fCurrTexture, | 410
fCurrTexture, |
| 411
params, | 411
params, |
| 412
fGammaTexture, | 412
fGammaTexture, |
| 413
gammaParams, | 413
gammaParams, |
| 414
colorNoPreMul, | 414
colorNoPreMul, |
| 415
flags)); | 415
flags)); |
| 416 } else { | 416 } else { |
| 417 flags |= kColorAttr_DistanceFieldEffectFlag; | 417 flags |= kColorAttr_DistanceFieldEffectFlag; |
| 418 bool opaque = GrColorIsOpaque(color); |
| 418 #ifdef SK_GAMMA_APPLY_TO_A8 | 419 #ifdef SK_GAMMA_APPLY_TO_A8 |
| 419 U8CPU lum = SkColorSpaceLuminance::computeLuminance(fDevicePropertie
s.gamma(), | 420 U8CPU lum = SkColorSpaceLuminance::computeLuminance(fDevicePropertie
s.gamma(), |
| 420 filteredColor); | 421 filteredColor); |
| 421 fCachedGeometryProcessor.reset(GrDistanceFieldTextureEffect::Create(
color, | 422 fCachedGeometryProcessor.reset(GrDistanceFieldTextureEffect::Create(
color, |
| 422
fCurrTexture, | 423
fCurrTexture, |
| 423
params, | 424
params, |
| 424
fGammaTexture, | 425
fGammaTexture, |
| 425
gammaParams, | 426
gammaParams, |
| 426
lum/255.f, | 427
lum/255.f, |
| 427
flags)); | 428
flags, |
| 429
opaque)); |
| 428 #else | 430 #else |
| 429 fCachedGeometryProcessor.reset(GrDistanceFieldNoGammaTextureEffect::
Create(color, | 431 fCachedGeometryProcessor.reset(GrDistanceFieldNoGammaTextureEffect::
Create(color, |
| 430
fCurrTexture, | 432
fCurrTexture, |
| 431
params, | 433
params, |
| 432
flags)); | 434
flags, |
| 435
opaque)); |
| 433 #endif | 436 #endif |
| 434 } | 437 } |
| 435 fEffectTextureUniqueID = textureUniqueID; | 438 fEffectTextureUniqueID = textureUniqueID; |
| 436 fEffectColor = filteredColor; | 439 fEffectColor = filteredColor; |
| 437 fEffectFlags = flags; | 440 fEffectFlags = flags; |
| 438 } | 441 } |
| 439 | 442 |
| 440 } | 443 } |
| 441 | 444 |
| 442 inline bool GrDistanceFieldTextContext::uploadGlyph(GrGlyph* glyph, GrFontScaler
* scaler) { | 445 inline bool GrDistanceFieldTextContext::uploadGlyph(GrGlyph* glyph, GrFontScaler
* scaler) { |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 630 // get our current color | 633 // get our current color |
| 631 SkColor filteredColor; | 634 SkColor filteredColor; |
| 632 SkColorFilter* colorFilter = fSkPaint.getColorFilter(); | 635 SkColorFilter* colorFilter = fSkPaint.getColorFilter(); |
| 633 if (colorFilter) { | 636 if (colorFilter) { |
| 634 filteredColor = colorFilter->filterColor(fSkPaint.getColor()); | 637 filteredColor = colorFilter->filterColor(fSkPaint.getColor()); |
| 635 } else { | 638 } else { |
| 636 filteredColor = fSkPaint.getColor(); | 639 filteredColor = fSkPaint.getColor(); |
| 637 } | 640 } |
| 638 this->setupCoverageEffect(filteredColor); | 641 this->setupCoverageEffect(filteredColor); |
| 639 | 642 |
| 640 // Effects could be stored with one of the cache objects (atlas?) | |
| 641 drawState.setGeometryProcessor(fCachedGeometryProcessor.get()); | |
| 642 | |
| 643 // Set draw state | 643 // Set draw state |
| 644 if (fUseLCDText) { | 644 if (fUseLCDText) { |
| 645 // TODO: move supportsRGBCoverage check to setupCoverageEffect and o
nly add LCD | 645 // TODO: move supportsRGBCoverage check to setupCoverageEffect and o
nly add LCD |
| 646 // processor if the xp can support it. For now we will simply assume
that if | 646 // processor if the xp can support it. For now we will simply assume
that if |
| 647 // fUseLCDText is true, then we have a known color output. | 647 // fUseLCDText is true, then we have a known color output. |
| 648 if (!drawState.getXPFactory()->supportsRGBCoverage(0, kRGBA_GrColorC
omponentFlags)) { | 648 if (!drawState.getXPFactory()->supportsRGBCoverage(0, kRGBA_GrColorC
omponentFlags)) { |
| 649 SkDebugf("LCD Text will not draw correctly.\n"); | 649 SkDebugf("LCD Text will not draw correctly.\n"); |
| 650 } | 650 } |
| 651 SkASSERT(!drawState.hasColorVertexAttribute()); | 651 SkASSERT(!fCachedGeometryProcessor->hasVertexColor()); |
| 652 } else { | 652 } else { |
| 653 if (0xFF == GrColorUnpackA(fPaint.getColor())) { | |
| 654 drawState.setHint(GrDrawState::kVertexColorsAreOpaque_Hint, true
); | |
| 655 } | |
| 656 // We're using per-vertex color. | 653 // We're using per-vertex color. |
| 657 SkASSERT(drawState.hasColorVertexAttribute()); | 654 SkASSERT(fCachedGeometryProcessor->hasVertexColor()); |
| 658 } | 655 } |
| 659 int nGlyphs = fCurrVertex / kVerticesPerGlyph; | 656 int nGlyphs = fCurrVertex / kVerticesPerGlyph; |
| 660 fDrawTarget->setIndexSourceToBuffer(fContext->getQuadIndexBuffer()); | 657 fDrawTarget->setIndexSourceToBuffer(fContext->getQuadIndexBuffer()); |
| 661 fDrawTarget->drawIndexedInstances(&drawState, | 658 fDrawTarget->drawIndexedInstances(&drawState, |
| 659 fCachedGeometryProcessor.get(), |
| 662 kTriangles_GrPrimitiveType, | 660 kTriangles_GrPrimitiveType, |
| 663 nGlyphs, | 661 nGlyphs, |
| 664 kVerticesPerGlyph, | 662 kVerticesPerGlyph, |
| 665 kIndicesPerGlyph, | 663 kIndicesPerGlyph, |
| 666 &fVertexBounds); | 664 &fVertexBounds); |
| 667 fDrawTarget->resetVertexSource(); | 665 fDrawTarget->resetVertexSource(); |
| 668 fVertices = NULL; | 666 fVertices = NULL; |
| 669 fTotalVertexCount -= fCurrVertex; | 667 fTotalVertexCount -= fCurrVertex; |
| 670 fCurrVertex = 0; | 668 fCurrVertex = 0; |
| 671 SkSafeSetNull(fCurrTexture); | 669 SkSafeSetNull(fCurrTexture); |
| 672 fVertexBounds.setLargestInverted(); | 670 fVertexBounds.setLargestInverted(); |
| 673 } | 671 } |
| 674 } | 672 } |
| 675 | 673 |
| 676 inline void GrDistanceFieldTextContext::finish() { | 674 inline void GrDistanceFieldTextContext::finish() { |
| 677 this->flush(); | 675 this->flush(); |
| 678 fTotalVertexCount = 0; | 676 fTotalVertexCount = 0; |
| 679 | 677 |
| 680 GrTextContext::finish(); | 678 GrTextContext::finish(); |
| 681 } | 679 } |
| 682 | 680 |
| OLD | NEW |