| 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()); | |
| 564 drawState.setBlendFunc(fPaint.getSrcBlendCoeff(), fPaint.getDstB
lendCoeff()); | 543 drawState.setBlendFunc(fPaint.getSrcBlendCoeff(), fPaint.getDstB
lendCoeff()); |
| 565 drawState.setAlpha(fSkPaint.getAlpha()); | 544 int a = fSkPaint.getAlpha(); |
| 545 color = SkColorSetARGB(a, a, a, a); |
| 566 break; | 546 break; |
| 547 } |
| 567 // LCD text | 548 // LCD text |
| 568 case kA565_GrMaskFormat: { | 549 case kA565_GrMaskFormat: { |
| 569 // TODO: move supportsRGBCoverage check to setupCoverageEffect a
nd only add LCD | 550 // TODO: move supportsRGBCoverage check to setupCoverageEffect a
nd only add LCD |
| 570 // processor if the xp can support it. For now we will simply as
sume that if | 551 // processor if the xp can support it. For now we will simply as
sume that if |
| 571 // fUseLCDText is true, then we have a known color output. | 552 // fUseLCDText is true, then we have a known color output. |
| 572 if (!drawState.getXPFactory()->supportsRGBCoverage(0, kRGBA_GrCo
lorComponentFlags)) { | 553 if (!drawState.getXPFactory()->supportsRGBCoverage(0, kRGBA_GrCo
lorComponentFlags)) { |
| 573 SkDebugf("LCD Text will not draw correctly.\n"); | 554 SkDebugf("LCD Text will not draw correctly.\n"); |
| 574 } | 555 } |
| 575 SkASSERT(!drawState.hasColorVertexAttribute()); | |
| 576 // We don't use the GrPaint's color in this case because it's be
en premultiplied by | 556 // We don't use the GrPaint's color in this case because it's be
en premultiplied by |
| 577 // alpha. Instead we feed in a non-premultiplied color, and mult
iply its alpha by | 557 // alpha. Instead we feed in a non-premultiplied color, and mult
iply its alpha by |
| 578 // the mask texture color. The end result is that we get | 558 // the mask texture color. The end result is that we get |
| 579 // mask*paintAlpha*paintColor + (1-mask*paintAlpha)*d
stColor | 559 // mask*paintAlpha*paintColor + (1-mask*paintAlpha)*d
stColor |
| 580 int a = SkColorGetA(fSkPaint.getColor()); | 560 int a = SkColorGetA(fSkPaint.getColor()); |
| 581 // paintAlpha | 561 // paintAlpha |
| 582 drawState.setColor(SkColorSetARGB(a, a, a, a)); | 562 color = SkColorSetARGB(a, a, a, a); |
| 583 // paintColor | 563 // paintColor |
| 584 drawState.setBlendConstant(skcolor_to_grcolor_nopremultiply(fSkP
aint.getColor())); | 564 drawState.setBlendConstant(skcolor_to_grcolor_nopremultiply(fSkP
aint.getColor())); |
| 585 drawState.setBlendFunc(kConstC_GrBlendCoeff, kISC_GrBlendCoeff); | 565 drawState.setBlendFunc(kConstC_GrBlendCoeff, kISC_GrBlendCoeff); |
| 586 break; | 566 break; |
| 587 } | 567 } |
| 588 // Grayscale/BW text | 568 // Grayscale/BW text |
| 589 case kA8_GrMaskFormat: | 569 case kA8_GrMaskFormat: |
| 590 drawState.setHint(GrDrawState::kVertexColorsAreOpaque_Hint, | 570 drawState.setHint(GrDrawState::kVertexColorsAreOpaque_Hint, |
| 591 0xFF == GrColorUnpackA(fPaint.getColor())); | 571 0xFF == GrColorUnpackA(fPaint.getColor())); |
| 572 color = fPaint.getColor(); |
| 592 // set back to normal in case we took LCD path previously. | 573 // set back to normal in case we took LCD path previously. |
| 593 drawState.setBlendFunc(fPaint.getSrcBlendCoeff(), fPaint.getDstB
lendCoeff()); | 574 drawState.setBlendFunc(fPaint.getSrcBlendCoeff(), fPaint.getDstB
lendCoeff()); |
| 594 // We're using per-vertex color. | |
| 595 SkASSERT(drawState.hasColorVertexAttribute()); | |
| 596 break; | 575 break; |
| 597 default: | 576 default: |
| 598 SkFAIL("Unexpected mask format."); | 577 SkFAIL("Unexpected mask format."); |
| 599 } | 578 } |
| 579 |
| 580 GrTextureParams params(SkShader::kRepeat_TileMode, GrTextureParams::kNon
e_FilterMode); |
| 581 // TODO cache these GPs |
| 582 if (kARGB_GrMaskFormat == fCurrMaskFormat) { |
| 583 uint32_t textureUniqueID = fCurrTexture->getUniqueID(); |
| 584 if (textureUniqueID != fEffectTextureUniqueID || |
| 585 fCachedGeometryProcessor->getColor() != color) { |
| 586 uint32_t flags = GrDefaultGeoProcFactory::kLocalCoord_GPType; |
| 587 fCachedGeometryProcessor.reset(GrDefaultGeoProcFactory::Create(c
olor, flags)); |
| 588 fCachedTextureProcessor.reset(GrSimpleTextureEffect::Create(fCur
rTexture, |
| 589 SkMa
trix::I(), |
| 590 para
ms)); |
| 591 } |
| 592 drawState.setGeometryProcessor(fCachedGeometryProcessor.get()); |
| 593 drawState.addColorProcessor(fCachedTextureProcessor.get()); |
| 594 } else { |
| 595 uint32_t textureUniqueID = fCurrTexture->getUniqueID(); |
| 596 if (textureUniqueID != fEffectTextureUniqueID || |
| 597 fCachedGeometryProcessor->getColor() != color) { |
| 598 bool hasColor = kA8_GrMaskFormat == fCurrMaskFormat; |
| 599 fCachedGeometryProcessor.reset(GrCustomCoordsTextureEffect::Crea
te(color, |
| 600
fCurrTexture, |
| 601
params, |
| 602
hasColor)); |
| 603 fEffectTextureUniqueID = textureUniqueID; |
| 604 } |
| 605 drawState.setGeometryProcessor(fCachedGeometryProcessor.get()); |
| 606 } |
| 607 |
| 600 int nGlyphs = fCurrVertex / kVerticesPerGlyph; | 608 int nGlyphs = fCurrVertex / kVerticesPerGlyph; |
| 601 fDrawTarget->setIndexSourceToBuffer(fContext->getQuadIndexBuffer()); | 609 fDrawTarget->setIndexSourceToBuffer(fContext->getQuadIndexBuffer()); |
| 602 fDrawTarget->drawIndexedInstances(&drawState, | 610 fDrawTarget->drawIndexedInstances(&drawState, |
| 603 kTriangles_GrPrimitiveType, | 611 kTriangles_GrPrimitiveType, |
| 604 nGlyphs, | 612 nGlyphs, |
| 605 kVerticesPerGlyph, | 613 kVerticesPerGlyph, |
| 606 kIndicesPerGlyph, | 614 kIndicesPerGlyph, |
| 607 &fVertexBounds); | 615 &fVertexBounds); |
| 608 | 616 |
| 609 fDrawTarget->resetVertexSource(); | 617 fDrawTarget->resetVertexSource(); |
| 610 fVertices = NULL; | 618 fVertices = NULL; |
| 611 fAllocVertexCount = 0; | 619 fAllocVertexCount = 0; |
| 612 // reset to be those that are left | 620 // reset to be those that are left |
| 613 fTotalVertexCount -= fCurrVertex; | 621 fTotalVertexCount -= fCurrVertex; |
| 614 fCurrVertex = 0; | 622 fCurrVertex = 0; |
| 615 fVertexBounds.setLargestInverted(); | 623 fVertexBounds.setLargestInverted(); |
| 616 SkSafeSetNull(fCurrTexture); | 624 SkSafeSetNull(fCurrTexture); |
| 617 } | 625 } |
| 618 } | 626 } |
| 619 | 627 |
| 620 inline void GrBitmapTextContext::finish() { | 628 inline void GrBitmapTextContext::finish() { |
| 621 this->flush(); | 629 this->flush(); |
| 622 fTotalVertexCount = 0; | 630 fTotalVertexCount = 0; |
| 623 | 631 |
| 624 GrTextContext::finish(); | 632 GrTextContext::finish(); |
| 625 } | 633 } |
| 626 | 634 |
| OLD | NEW |