| 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 "GrBitmapTextContext.h" | 8 #include "GrBitmapTextContext.h" |
| 9 #include "GrAtlas.h" | 9 #include "GrAtlas.h" |
| 10 #include "GrDefaultGeoProcFactory.h" | 10 #include "GrDefaultGeoProcFactory.h" |
| (...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 528 } | 528 } |
| 529 | 529 |
| 530 if (fCurrVertex > 0) { | 530 if (fCurrVertex > 0) { |
| 531 GrDrawState drawState; | 531 GrDrawState drawState; |
| 532 drawState.setFromPaint(fPaint, SkMatrix::I(), fContext->getRenderTarget(
)); | 532 drawState.setFromPaint(fPaint, SkMatrix::I(), fContext->getRenderTarget(
)); |
| 533 | 533 |
| 534 // setup our sampler state for our text texture/atlas | 534 // setup our sampler state for our text texture/atlas |
| 535 SkASSERT(SkIsAlign4(fCurrVertex)); | 535 SkASSERT(SkIsAlign4(fCurrVertex)); |
| 536 SkASSERT(fCurrTexture); | 536 SkASSERT(fCurrTexture); |
| 537 | 537 |
| 538 // This effect could be stored with one of the cache objects (atlas?) | |
| 539 GrTextureParams params(SkShader::kRepeat_TileMode, GrTextureParams::kNon
e_FilterMode); | |
| 540 if (kARGB_GrMaskFormat == fCurrMaskFormat) { | |
| 541 uint32_t flags = GrDefaultGeoProcFactory::kLocalCoord_GPType; | |
| 542 drawState.setGeometryProcessor(GrDefaultGeoProcFactory::Create(flags
))->unref(); | |
| 543 GrFragmentProcessor* fragProcessor = GrSimpleTextureEffect::Create(f
CurrTexture, | |
| 544 S
kMatrix::I(), | |
| 545 p
arams); | |
| 546 drawState.addColorProcessor(fragProcessor)->unref(); | |
| 547 } else { | |
| 548 uint32_t textureUniqueID = fCurrTexture->getUniqueID(); | |
| 549 if (textureUniqueID != fEffectTextureUniqueID) { | |
| 550 bool hasColor = kA8_GrMaskFormat == fCurrMaskFormat; | |
| 551 fCachedGeometryProcessor.reset(GrCustomCoordsTextureEffect::Crea
te(fCurrTexture, | |
| 552
params, | |
| 553
hasColor)); | |
| 554 fEffectTextureUniqueID = textureUniqueID; | |
| 555 } | |
| 556 drawState.setGeometryProcessor(fCachedGeometryProcessor.get()); | |
| 557 } | |
| 558 | |
| 559 SkASSERT(fStrike); | 538 SkASSERT(fStrike); |
| 539 GrColor color; |
| 560 switch (fCurrMaskFormat) { | 540 switch (fCurrMaskFormat) { |
| 561 // Color bitmap text | 541 // Color bitmap text |
| 562 case kARGB_GrMaskFormat: | 542 case kARGB_GrMaskFormat: { |
| 563 SkASSERT(!drawState.hasColorVertexAttribute()); | 543 int a = fSkPaint.getAlpha(); |
| 564 drawState.setAlpha(fSkPaint.getAlpha()); | 544 color = SkColorSetARGB(a, a, a, a); |
| 565 break; | 545 break; |
| 546 } |
| 566 // LCD text | 547 // LCD text |
| 567 case kA565_GrMaskFormat: { | 548 case kA565_GrMaskFormat: { |
| 568 // TODO: move supportsRGBCoverage check to setupCoverageEffect a
nd only add LCD | 549 // TODO: move supportsRGBCoverage check to setupCoverageEffect a
nd only add LCD |
| 569 // processor if the xp can support it. For now we will simply as
sume that if | 550 // processor if the xp can support it. For now we will simply as
sume that if |
| 570 // fUseLCDText is true, then we have a known color output. | 551 // fUseLCDText is true, then we have a known color output. |
| 571 if (!drawState.getXPFactory()->supportsRGBCoverage(0, kRGBA_GrCo
lorComponentFlags)) { | 552 if (!drawState.getXPFactory()->supportsRGBCoverage(0, kRGBA_GrCo
lorComponentFlags)) { |
| 572 SkDebugf("LCD Text will not draw correctly.\n"); | 553 SkDebugf("LCD Text will not draw correctly.\n"); |
| 573 } | 554 } |
| 574 SkASSERT(!drawState.hasColorVertexAttribute()); | 555 // We don't use the GrPaint's color in this case because it's be
en premultiplied by |
| 556 // alpha. Instead we feed in a non-premultiplied color, and mult
iply its alpha by |
| 557 // the mask texture color. The end result is that we get |
| 558 // mask*paintAlpha*paintColor + (1-mask*paintAlpha)*d
stColor |
| 559 int a = SkColorGetA(fSkPaint.getColor()); |
| 560 // paintAlpha |
| 561 color = SkColorSetARGB(a, a, a, a); |
| 575 break; | 562 break; |
| 576 } | 563 } |
| 577 // Grayscale/BW text | 564 // Grayscale/BW text |
| 578 case kA8_GrMaskFormat: | 565 case kA8_GrMaskFormat: |
| 579 drawState.setHint(GrDrawState::kVertexColorsAreOpaque_Hint, | 566 drawState.setHint(GrDrawState::kVertexColorsAreOpaque_Hint, |
| 580 0xFF == GrColorUnpackA(fPaint.getColor())); | 567 0xFF == GrColorUnpackA(fPaint.getColor())); |
| 581 // We're using per-vertex color. | 568 color = fPaint.getColor(); |
| 582 SkASSERT(drawState.hasColorVertexAttribute()); | |
| 583 break; | 569 break; |
| 584 default: | 570 default: |
| 585 SkFAIL("Unexpected mask format."); | 571 SkFAIL("Unexpected mask format."); |
| 586 } | 572 } |
| 573 |
| 574 GrTextureParams params(SkShader::kRepeat_TileMode, GrTextureParams::kNon
e_FilterMode); |
| 575 // TODO cache these GPs |
| 576 if (kARGB_GrMaskFormat == fCurrMaskFormat) { |
| 577 uint32_t textureUniqueID = fCurrTexture->getUniqueID(); |
| 578 if (textureUniqueID != fEffectTextureUniqueID || |
| 579 fCachedGeometryProcessor->getColor() != color) { |
| 580 uint32_t flags = GrDefaultGeoProcFactory::kLocalCoord_GPType; |
| 581 fCachedGeometryProcessor.reset(GrDefaultGeoProcFactory::Create(c
olor, flags)); |
| 582 fCachedTextureProcessor.reset(GrSimpleTextureEffect::Create(fCur
rTexture, |
| 583 SkMa
trix::I(), |
| 584 para
ms)); |
| 585 } |
| 586 drawState.setGeometryProcessor(fCachedGeometryProcessor.get()); |
| 587 drawState.addColorProcessor(fCachedTextureProcessor.get()); |
| 588 } else { |
| 589 uint32_t textureUniqueID = fCurrTexture->getUniqueID(); |
| 590 if (textureUniqueID != fEffectTextureUniqueID || |
| 591 fCachedGeometryProcessor->getColor() != color) { |
| 592 bool hasColor = kA8_GrMaskFormat == fCurrMaskFormat; |
| 593 fCachedGeometryProcessor.reset(GrCustomCoordsTextureEffect::Crea
te(color, |
| 594
fCurrTexture, |
| 595
params, |
| 596
hasColor)); |
| 597 fEffectTextureUniqueID = textureUniqueID; |
| 598 } |
| 599 drawState.setGeometryProcessor(fCachedGeometryProcessor.get()); |
| 600 } |
| 601 |
| 587 int nGlyphs = fCurrVertex / kVerticesPerGlyph; | 602 int nGlyphs = fCurrVertex / kVerticesPerGlyph; |
| 588 fDrawTarget->setIndexSourceToBuffer(fContext->getQuadIndexBuffer()); | 603 fDrawTarget->setIndexSourceToBuffer(fContext->getQuadIndexBuffer()); |
| 589 fDrawTarget->drawIndexedInstances(&drawState, | 604 fDrawTarget->drawIndexedInstances(&drawState, |
| 590 kTriangles_GrPrimitiveType, | 605 kTriangles_GrPrimitiveType, |
| 591 nGlyphs, | 606 nGlyphs, |
| 592 kVerticesPerGlyph, | 607 kVerticesPerGlyph, |
| 593 kIndicesPerGlyph, | 608 kIndicesPerGlyph, |
| 594 &fVertexBounds); | 609 &fVertexBounds); |
| 595 | 610 |
| 596 fDrawTarget->resetVertexSource(); | 611 fDrawTarget->resetVertexSource(); |
| 597 fVertices = NULL; | 612 fVertices = NULL; |
| 598 fAllocVertexCount = 0; | 613 fAllocVertexCount = 0; |
| 599 // reset to be those that are left | 614 // reset to be those that are left |
| 600 fTotalVertexCount -= fCurrVertex; | 615 fTotalVertexCount -= fCurrVertex; |
| 601 fCurrVertex = 0; | 616 fCurrVertex = 0; |
| 602 fVertexBounds.setLargestInverted(); | 617 fVertexBounds.setLargestInverted(); |
| 603 SkSafeSetNull(fCurrTexture); | 618 SkSafeSetNull(fCurrTexture); |
| 604 } | 619 } |
| 605 } | 620 } |
| 606 | 621 |
| 607 inline void GrBitmapTextContext::finish() { | 622 inline void GrBitmapTextContext::finish() { |
| 608 this->flush(); | 623 this->flush(); |
| 609 fTotalVertexCount = 0; | 624 fTotalVertexCount = 0; |
| 610 | 625 |
| 611 GrTextContext::finish(); | 626 GrTextContext::finish(); |
| 612 } | 627 } |
| 613 | 628 |
| OLD | NEW |