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