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 619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
630 } else { | 630 } else { |
631 filteredColor = fSkPaint.getColor(); | 631 filteredColor = fSkPaint.getColor(); |
632 } | 632 } |
633 this->setupCoverageEffect(filteredColor); | 633 this->setupCoverageEffect(filteredColor); |
634 | 634 |
635 // Effects could be stored with one of the cache objects (atlas?) | 635 // Effects could be stored with one of the cache objects (atlas?) |
636 drawState.setGeometryProcessor(fCachedGeometryProcessor.get()); | 636 drawState.setGeometryProcessor(fCachedGeometryProcessor.get()); |
637 | 637 |
638 // Set draw state | 638 // Set draw state |
639 if (fUseLCDText) { | 639 if (fUseLCDText) { |
| 640 GrColor colorNoPreMul = skcolor_to_grcolor_nopremultiply(filteredCol
or); |
| 641 |
640 // TODO: move supportsRGBCoverage check to setupCoverageEffect and o
nly add LCD | 642 // TODO: move supportsRGBCoverage check to setupCoverageEffect and o
nly add LCD |
641 // processor if the xp can support it. For now we will simply assume
that if | 643 // processor if the xp can support it. For now we will simply assume
that if |
642 // fUseLCDText is true, then we have a known color output. | 644 // fUseLCDText is true, then we have a known color output. |
643 if (!drawState.getXPFactory()->supportsRGBCoverage(0, kRGBA_GrColorC
omponentFlags)) { | 645 if (!drawState.getXPFactory()->supportsRGBCoverage(0, kRGBA_GrColorC
omponentFlags)) { |
644 SkDebugf("LCD Text will not draw correctly.\n"); | 646 SkDebugf("LCD Text will not draw correctly.\n"); |
645 } | 647 } |
646 SkASSERT(!drawState.hasColorVertexAttribute()); | 648 SkASSERT(!drawState.hasColorVertexAttribute()); |
| 649 // We don't use the GrPaint's color in this case because it's been p
remultiplied by |
| 650 // alpha. Instead we feed in a non-premultiplied color, and multiply
its alpha by |
| 651 // the mask texture color. The end result is that we get |
| 652 // mask*paintAlpha*paintColor + (1-mask*paintAlpha)*dstCo
lor |
| 653 int a = SkColorGetA(fSkPaint.getColor()); |
| 654 // paintAlpha |
| 655 drawState.setColor(SkColorSetARGB(a, a, a, a)); |
| 656 // paintColor |
| 657 drawState.setBlendConstant(colorNoPreMul); |
| 658 drawState.setBlendFunc(kConstC_GrBlendCoeff, kISC_GrBlendCoeff); |
647 } else { | 659 } else { |
648 if (0xFF == GrColorUnpackA(fPaint.getColor())) { | 660 if (0xFF == GrColorUnpackA(fPaint.getColor())) { |
649 drawState.setHint(GrDrawState::kVertexColorsAreOpaque_Hint, true
); | 661 drawState.setHint(GrDrawState::kVertexColorsAreOpaque_Hint, true
); |
650 } | 662 } |
| 663 // set back to normal in case we took LCD path previously. |
| 664 drawState.setBlendFunc(fPaint.getSrcBlendCoeff(), fPaint.getDstBlend
Coeff()); |
651 // We're using per-vertex color. | 665 // We're using per-vertex color. |
652 SkASSERT(drawState.hasColorVertexAttribute()); | 666 SkASSERT(drawState.hasColorVertexAttribute()); |
653 } | 667 } |
654 int nGlyphs = fCurrVertex / kVerticesPerGlyph; | 668 int nGlyphs = fCurrVertex / kVerticesPerGlyph; |
655 fDrawTarget->setIndexSourceToBuffer(fContext->getQuadIndexBuffer()); | 669 fDrawTarget->setIndexSourceToBuffer(fContext->getQuadIndexBuffer()); |
656 fDrawTarget->drawIndexedInstances(&drawState, | 670 fDrawTarget->drawIndexedInstances(&drawState, |
657 kTriangles_GrPrimitiveType, | 671 kTriangles_GrPrimitiveType, |
658 nGlyphs, | 672 nGlyphs, |
659 kVerticesPerGlyph, | 673 kVerticesPerGlyph, |
660 kIndicesPerGlyph, | 674 kIndicesPerGlyph, |
661 &fVertexBounds); | 675 &fVertexBounds); |
662 fDrawTarget->resetVertexSource(); | 676 fDrawTarget->resetVertexSource(); |
663 fVertices = NULL; | 677 fVertices = NULL; |
664 fTotalVertexCount -= fCurrVertex; | 678 fTotalVertexCount -= fCurrVertex; |
665 fCurrVertex = 0; | 679 fCurrVertex = 0; |
666 SkSafeSetNull(fCurrTexture); | 680 SkSafeSetNull(fCurrTexture); |
667 fVertexBounds.setLargestInverted(); | 681 fVertexBounds.setLargestInverted(); |
668 } | 682 } |
669 } | 683 } |
670 | 684 |
671 inline void GrDistanceFieldTextContext::finish() { | 685 inline void GrDistanceFieldTextContext::finish() { |
672 this->flush(); | 686 this->flush(); |
673 fTotalVertexCount = 0; | 687 fTotalVertexCount = 0; |
674 | 688 |
675 GrTextContext::finish(); | 689 GrTextContext::finish(); |
676 } | 690 } |
677 | 691 |
OLD | NEW |