| 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 | |
| 642 // TODO: move supportsRGBCoverage check to setupCoverageEffect and o
nly add LCD | 640 // TODO: move supportsRGBCoverage check to setupCoverageEffect and o
nly add LCD |
| 643 // processor if the xp can support it. For now we will simply assume
that if | 641 // processor if the xp can support it. For now we will simply assume
that if |
| 644 // fUseLCDText is true, then we have a known color output. | 642 // fUseLCDText is true, then we have a known color output. |
| 645 if (!drawState.getXPFactory()->supportsRGBCoverage(0, kRGBA_GrColorC
omponentFlags)) { | 643 if (!drawState.getXPFactory()->supportsRGBCoverage(0, kRGBA_GrColorC
omponentFlags)) { |
| 646 SkDebugf("LCD Text will not draw correctly.\n"); | 644 SkDebugf("LCD Text will not draw correctly.\n"); |
| 647 } | 645 } |
| 648 SkASSERT(!drawState.hasColorVertexAttribute()); | 646 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); | |
| 659 } else { | 647 } else { |
| 660 if (0xFF == GrColorUnpackA(fPaint.getColor())) { | 648 if (0xFF == GrColorUnpackA(fPaint.getColor())) { |
| 661 drawState.setHint(GrDrawState::kVertexColorsAreOpaque_Hint, true
); | 649 drawState.setHint(GrDrawState::kVertexColorsAreOpaque_Hint, true
); |
| 662 } | 650 } |
| 663 // set back to normal in case we took LCD path previously. | |
| 664 drawState.setBlendFunc(fPaint.getSrcBlendCoeff(), fPaint.getDstBlend
Coeff()); | |
| 665 // We're using per-vertex color. | 651 // We're using per-vertex color. |
| 666 SkASSERT(drawState.hasColorVertexAttribute()); | 652 SkASSERT(drawState.hasColorVertexAttribute()); |
| 667 } | 653 } |
| 668 int nGlyphs = fCurrVertex / kVerticesPerGlyph; | 654 int nGlyphs = fCurrVertex / kVerticesPerGlyph; |
| 669 fDrawTarget->setIndexSourceToBuffer(fContext->getQuadIndexBuffer()); | 655 fDrawTarget->setIndexSourceToBuffer(fContext->getQuadIndexBuffer()); |
| 670 fDrawTarget->drawIndexedInstances(&drawState, | 656 fDrawTarget->drawIndexedInstances(&drawState, |
| 671 kTriangles_GrPrimitiveType, | 657 kTriangles_GrPrimitiveType, |
| 672 nGlyphs, | 658 nGlyphs, |
| 673 kVerticesPerGlyph, | 659 kVerticesPerGlyph, |
| 674 kIndicesPerGlyph, | 660 kIndicesPerGlyph, |
| 675 &fVertexBounds); | 661 &fVertexBounds); |
| 676 fDrawTarget->resetVertexSource(); | 662 fDrawTarget->resetVertexSource(); |
| 677 fVertices = NULL; | 663 fVertices = NULL; |
| 678 fTotalVertexCount -= fCurrVertex; | 664 fTotalVertexCount -= fCurrVertex; |
| 679 fCurrVertex = 0; | 665 fCurrVertex = 0; |
| 680 SkSafeSetNull(fCurrTexture); | 666 SkSafeSetNull(fCurrTexture); |
| 681 fVertexBounds.setLargestInverted(); | 667 fVertexBounds.setLargestInverted(); |
| 682 } | 668 } |
| 683 } | 669 } |
| 684 | 670 |
| 685 inline void GrDistanceFieldTextContext::finish() { | 671 inline void GrDistanceFieldTextContext::finish() { |
| 686 this->flush(); | 672 this->flush(); |
| 687 fTotalVertexCount = 0; | 673 fTotalVertexCount = 0; |
| 688 | 674 |
| 689 GrTextContext::finish(); | 675 GrTextContext::finish(); |
| 690 } | 676 } |
| 691 | 677 |
| OLD | NEW |