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