| 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 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 } | 522 } |
| 523 fCurrVertex += 4; | 523 fCurrVertex += 4; |
| 524 } | 524 } |
| 525 | 525 |
| 526 void GrBitmapTextContext::flush() { | 526 void GrBitmapTextContext::flush() { |
| 527 if (NULL == fDrawTarget) { | 527 if (NULL == fDrawTarget) { |
| 528 return; | 528 return; |
| 529 } | 529 } |
| 530 | 530 |
| 531 if (fCurrVertex > 0) { | 531 if (fCurrVertex > 0) { |
| 532 GrDrawState drawState; | 532 GrPipelineBuilder pipelineBuilder; |
| 533 drawState.setFromPaint(fPaint, fContext->getRenderTarget()); | 533 pipelineBuilder.setFromPaint(fPaint, fContext->getRenderTarget()); |
| 534 | 534 |
| 535 // setup our sampler state for our text texture/atlas | 535 // setup our sampler state for our text texture/atlas |
| 536 SkASSERT(SkIsAlign4(fCurrVertex)); | 536 SkASSERT(SkIsAlign4(fCurrVertex)); |
| 537 SkASSERT(fCurrTexture); | 537 SkASSERT(fCurrTexture); |
| 538 | 538 |
| 539 SkASSERT(fStrike); | 539 SkASSERT(fStrike); |
| 540 GrColor color = fPaint.getColor(); | 540 GrColor color = fPaint.getColor(); |
| 541 switch (fCurrMaskFormat) { | 541 switch (fCurrMaskFormat) { |
| 542 // Color bitmap text | 542 // Color bitmap text |
| 543 case kARGB_GrMaskFormat: { | 543 case kARGB_GrMaskFormat: { |
| 544 int a = fSkPaint.getAlpha(); | 544 int a = fSkPaint.getAlpha(); |
| 545 color = SkColorSetARGB(a, a, a, a); | 545 color = SkColorSetARGB(a, a, a, a); |
| 546 break; | 546 break; |
| 547 } | 547 } |
| 548 // LCD text | 548 // LCD text |
| 549 case kA565_GrMaskFormat: { | 549 case kA565_GrMaskFormat: { |
| 550 // TODO: move supportsRGBCoverage check to setupCoverageEffect a
nd only add LCD | 550 // TODO: move supportsRGBCoverage check to setupCoverageEffect a
nd only add LCD |
| 551 // 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 |
| 552 // fUseLCDText is true, then we have a known color output. | 552 // fUseLCDText is true, then we have a known color output. |
| 553 if (!drawState.getXPFactory()->supportsRGBCoverage(0, kRGBA_GrCo
lorComponentFlags)) { | 553 const GrXPFactory* xpFactory = pipelineBuilder.getXPFactory(); |
| 554 if (!xpFactory->supportsRGBCoverage(0, kRGBA_GrColorComponentFla
gs)) { |
| 554 SkDebugf("LCD Text will not draw correctly.\n"); | 555 SkDebugf("LCD Text will not draw correctly.\n"); |
| 555 } | 556 } |
| 556 break; | 557 break; |
| 557 } | 558 } |
| 558 // Grayscale/BW text | 559 // Grayscale/BW text |
| 559 case kA8_GrMaskFormat: | 560 case kA8_GrMaskFormat: |
| 560 break; | 561 break; |
| 561 default: | 562 default: |
| 562 SkFAIL("Unexpected mask format."); | 563 SkFAIL("Unexpected mask format."); |
| 563 } | 564 } |
| 564 | 565 |
| 565 GrTextureParams params(SkShader::kRepeat_TileMode, GrTextureParams::kNon
e_FilterMode); | 566 GrTextureParams params(SkShader::kRepeat_TileMode, GrTextureParams::kNon
e_FilterMode); |
| 566 if (kARGB_GrMaskFormat == fCurrMaskFormat) { | 567 if (kARGB_GrMaskFormat == fCurrMaskFormat) { |
| 567 uint32_t textureUniqueID = fCurrTexture->getUniqueID(); | 568 uint32_t textureUniqueID = fCurrTexture->getUniqueID(); |
| 568 if (textureUniqueID != fEffectTextureUniqueID || | 569 if (textureUniqueID != fEffectTextureUniqueID || |
| 569 fCachedGeometryProcessor->color() != color) { | 570 fCachedGeometryProcessor->color() != color) { |
| 570 uint32_t flags = GrDefaultGeoProcFactory::kLocalCoord_GPType; | 571 uint32_t flags = GrDefaultGeoProcFactory::kLocalCoord_GPType; |
| 571 fCachedGeometryProcessor.reset(GrDefaultGeoProcFactory::Create(f
lags, color)); | 572 fCachedGeometryProcessor.reset(GrDefaultGeoProcFactory::Create(f
lags, color)); |
| 572 fCachedTextureProcessor.reset(GrSimpleTextureEffect::Create(fCur
rTexture, | 573 fCachedTextureProcessor.reset(GrSimpleTextureEffect::Create(fCur
rTexture, |
| 573 SkMa
trix::I(), | 574 SkMa
trix::I(), |
| 574 para
ms)); | 575 para
ms)); |
| 575 fEffectTextureUniqueID = textureUniqueID; | 576 fEffectTextureUniqueID = textureUniqueID; |
| 576 } | 577 } |
| 577 drawState.addColorProcessor(fCachedTextureProcessor.get()); | 578 pipelineBuilder.addColorProcessor(fCachedTextureProcessor.get()); |
| 578 } else { | 579 } else { |
| 579 uint32_t textureUniqueID = fCurrTexture->getUniqueID(); | 580 uint32_t textureUniqueID = fCurrTexture->getUniqueID(); |
| 580 if (textureUniqueID != fEffectTextureUniqueID || | 581 if (textureUniqueID != fEffectTextureUniqueID || |
| 581 fCachedGeometryProcessor->color() != color || | 582 fCachedGeometryProcessor->color() != color || |
| 582 !fCachedGeometryProcessor->localMatrix().cheapEqualTo(fLocalMatr
ix)) { | 583 !fCachedGeometryProcessor->localMatrix().cheapEqualTo(fLocalMatr
ix)) { |
| 583 bool hasColor = kA8_GrMaskFormat == fCurrMaskFormat; | 584 bool hasColor = kA8_GrMaskFormat == fCurrMaskFormat; |
| 584 bool opaqueVertexColors = GrColorIsOpaque(fPaint.getColor()); | 585 bool opaqueVertexColors = GrColorIsOpaque(fPaint.getColor()); |
| 585 fCachedGeometryProcessor.reset(GrBitmapTextGeoProc::Create(color
, | 586 fCachedGeometryProcessor.reset(GrBitmapTextGeoProc::Create(color
, |
| 586 fCurr
Texture, | 587 fCurr
Texture, |
| 587 param
s, | 588 param
s, |
| 588 hasCo
lor, | 589 hasCo
lor, |
| 589 opaqu
eVertexColors, | 590 opaqu
eVertexColors, |
| 590 fLoca
lMatrix)); | 591 fLoca
lMatrix)); |
| 591 fEffectTextureUniqueID = textureUniqueID; | 592 fEffectTextureUniqueID = textureUniqueID; |
| 592 } | 593 } |
| 593 } | 594 } |
| 594 | 595 |
| 595 int nGlyphs = fCurrVertex / kVerticesPerGlyph; | 596 int nGlyphs = fCurrVertex / kVerticesPerGlyph; |
| 596 fDrawTarget->setIndexSourceToBuffer(fContext->getQuadIndexBuffer()); | 597 fDrawTarget->setIndexSourceToBuffer(fContext->getQuadIndexBuffer()); |
| 597 fDrawTarget->drawIndexedInstances(&drawState, | 598 fDrawTarget->drawIndexedInstances(&pipelineBuilder, |
| 598 fCachedGeometryProcessor.get(), | 599 fCachedGeometryProcessor.get(), |
| 599 kTriangles_GrPrimitiveType, | 600 kTriangles_GrPrimitiveType, |
| 600 nGlyphs, | 601 nGlyphs, |
| 601 kVerticesPerGlyph, | 602 kVerticesPerGlyph, |
| 602 kIndicesPerGlyph, | 603 kIndicesPerGlyph, |
| 603 &fVertexBounds); | 604 &fVertexBounds); |
| 604 | 605 |
| 605 fDrawTarget->resetVertexSource(); | 606 fDrawTarget->resetVertexSource(); |
| 606 fVertices = NULL; | 607 fVertices = NULL; |
| 607 fAllocVertexCount = 0; | 608 fAllocVertexCount = 0; |
| 608 // reset to be those that are left | 609 // reset to be those that are left |
| 609 fTotalVertexCount -= fCurrVertex; | 610 fTotalVertexCount -= fCurrVertex; |
| 610 fCurrVertex = 0; | 611 fCurrVertex = 0; |
| 611 fVertexBounds.setLargestInverted(); | 612 fVertexBounds.setLargestInverted(); |
| 612 SkSafeSetNull(fCurrTexture); | 613 SkSafeSetNull(fCurrTexture); |
| 613 } | 614 } |
| 614 } | 615 } |
| 615 | 616 |
| 616 inline void GrBitmapTextContext::finish() { | 617 inline void GrBitmapTextContext::finish() { |
| 617 this->flush(); | 618 this->flush(); |
| 618 fTotalVertexCount = 0; | 619 fTotalVertexCount = 0; |
| 619 | 620 |
| 620 GrTextContext::finish(); | 621 GrTextContext::finish(); |
| 621 } | 622 } |
| 622 | 623 |
| OLD | NEW |