OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 #include "GrAtlasTextContext.h" | 7 #include "GrAtlasTextContext.h" |
8 | 8 |
9 #include "GrAtlas.h" | 9 #include "GrAtlas.h" |
10 #include "GrBatch.h" | 10 #include "GrBatch.h" |
(...skipping 798 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
809 // then we can't really trust the atlas has all of the correct data.
Atlas evictions | 809 // then we can't really trust the atlas has all of the correct data.
Atlas evictions |
810 // should be pretty rare, so we just always regenerate in those case
s | 810 // should be pretty rare, so we just always regenerate in those case
s |
811 if (regenerateTextureCoords || regenerateColors) { | 811 if (regenerateTextureCoords || regenerateColors) { |
812 // first regenerate texture coordinates / colors if need be | 812 // first regenerate texture coordinates / colors if need be |
813 const SkDescriptor* desc = NULL; | 813 const SkDescriptor* desc = NULL; |
814 SkGlyphCache* cache = NULL; | 814 SkGlyphCache* cache = NULL; |
815 GrFontScaler* scaler = NULL; | 815 GrFontScaler* scaler = NULL; |
816 GrBatchTextStrike* strike = NULL; | 816 GrBatchTextStrike* strike = NULL; |
817 bool brokenRun = false; | 817 bool brokenRun = false; |
818 if (regenerateTextureCoords) { | 818 if (regenerateTextureCoords) { |
| 819 info.fBulkUseToken.reset(); |
819 desc = run.fDescriptor.getDesc(); | 820 desc = run.fDescriptor.getDesc(); |
820 cache = SkGlyphCache::DetachCache(run.fTypeface, desc); | 821 cache = SkGlyphCache::DetachCache(run.fTypeface, desc); |
821 scaler = GrTextContext::GetGrFontScaler(cache); | 822 scaler = GrTextContext::GetGrFontScaler(cache); |
822 strike = fFontCache->getStrike(scaler); | 823 strike = fFontCache->getStrike(scaler); |
823 } | 824 } |
824 for (int glyphIdx = 0; glyphIdx < glyphCount; glyphIdx++) { | 825 for (int glyphIdx = 0; glyphIdx < glyphCount; glyphIdx++) { |
825 GrGlyph::PackedID glyphID = blob->fGlyphIDs[glyphIdx + info.
fGlyphStartIndex]; | 826 GrGlyph::PackedID glyphID = blob->fGlyphIDs[glyphIdx + info.
fGlyphStartIndex]; |
826 | 827 |
827 if (regenerateTextureCoords) { | 828 if (regenerateTextureCoords) { |
828 // Upload the glyph only if needed | 829 // Upload the glyph only if needed |
829 GrGlyph* glyph = strike->getGlyph(glyphID, scaler); | 830 GrGlyph* glyph = strike->getGlyph(glyphID, scaler); |
830 SkASSERT(glyph); | 831 SkASSERT(glyph); |
831 | 832 |
832 if (!fFontCache->hasGlyph(glyph) && | 833 if (!fFontCache->hasGlyph(glyph) && |
833 !strike->addGlyphToAtlas(batchTarget, glyph, scaler)
) { | 834 !strike->addGlyphToAtlas(batchTarget, glyph, scaler)
) { |
834 this->flush(batchTarget, &drawInfo, instancesToFlush
, | 835 this->flush(batchTarget, &drawInfo, instancesToFlush
, |
835 maxInstancesPerDraw); | 836 maxInstancesPerDraw); |
836 this->initDraw(batchTarget, gp, pipeline); | 837 this->initDraw(batchTarget, gp, pipeline); |
837 instancesToFlush = 0; | 838 instancesToFlush = 0; |
838 brokenRun = glyphIdx > 0; | 839 brokenRun = glyphIdx > 0; |
839 | 840 |
840 SkDEBUGCODE(bool success =) strike->addGlyphToAtlas(
batchTarget, glyph, | 841 SkDEBUGCODE(bool success =) strike->addGlyphToAtlas(
batchTarget, glyph, |
841
scaler); | 842
scaler); |
842 SkASSERT(success); | 843 SkASSERT(success); |
843 } | 844 } |
844 | 845 fFontCache->addGlyphToBulkAndSetUseToken(&info.fBulkUseT
oken, glyph, |
845 fFontCache->setGlyphRefToken(glyph, batchTarget->current
Token()); | 846 batchTarget->cu
rrentToken()); |
846 | 847 |
847 // Texture coords are the last vertex attribute so we ge
t a pointer to the | 848 // Texture coords are the last vertex attribute so we ge
t a pointer to the |
848 // first one and then map with stride in regenerateTextu
reCoords | 849 // first one and then map with stride in regenerateTextu
reCoords |
849 intptr_t vertex = reinterpret_cast<intptr_t>(blob->fVert
ices); | 850 intptr_t vertex = reinterpret_cast<intptr_t>(blob->fVert
ices); |
850 vertex += info.fVertexStartIndex; | 851 vertex += info.fVertexStartIndex; |
851 vertex += vertexStride * glyphIdx * kVerticesPerGlyph; | 852 vertex += vertexStride * glyphIdx * kVerticesPerGlyph; |
852 vertex += vertexStride - sizeof(SkIPoint16); | 853 vertex += vertexStride - sizeof(SkIPoint16); |
853 | 854 |
854 this->regenerateTextureCoords(glyph, vertex, vertexStrid
e); | 855 this->regenerateTextureCoords(glyph, vertex, vertexStrid
e); |
855 } | 856 } |
856 | 857 |
857 if (regenerateColors) { | 858 if (regenerateColors) { |
858 intptr_t vertex = reinterpret_cast<intptr_t>(blob->fVert
ices); | 859 intptr_t vertex = reinterpret_cast<intptr_t>(blob->fVert
ices); |
859 vertex += info.fVertexStartIndex; | 860 vertex += info.fVertexStartIndex; |
860 vertex += vertexStride * glyphIdx * kVerticesPerGlyph +
sizeof(SkPoint); | 861 vertex += vertexStride * glyphIdx * kVerticesPerGlyph +
sizeof(SkPoint); |
861 this->regenerateColors(vertex, vertexStride, args.fColor
); | 862 this->regenerateColors(vertex, vertexStride, args.fColor
); |
862 } | 863 } |
863 | 864 |
864 instancesToFlush++; | 865 instancesToFlush++; |
865 } | 866 } |
866 | 867 |
867 if (regenerateTextureCoords) { | 868 if (regenerateTextureCoords) { |
868 SkGlyphCache::AttachCache(cache); | 869 SkGlyphCache::AttachCache(cache); |
869 info.fAtlasGeneration = brokenRun ? GrBatchAtlas::kInvalidAt
lasGeneration : | 870 info.fAtlasGeneration = brokenRun ? GrBatchAtlas::kInvalidAt
lasGeneration : |
870 fFontCache->atlasGenerat
ion(fMaskFormat); | 871 fFontCache->atlasGenerat
ion(fMaskFormat); |
871 } | 872 } |
872 } else { | 873 } else { |
873 instancesToFlush += glyphCount; | 874 instancesToFlush += glyphCount; |
| 875 |
| 876 // set use tokens for all of the glyphs in our subrun. This is
only valid if we |
| 877 // have a valid atlas generation |
| 878 fFontCache->setUseTokenBulk(info.fBulkUseToken, |
| 879 batchTarget->currentToken(), |
| 880 fMaskFormat); |
874 } | 881 } |
875 | 882 |
876 // now copy all vertices | 883 // now copy all vertices |
877 size_t byteCount = info.fVertexEndIndex - info.fVertexStartIndex; | 884 size_t byteCount = info.fVertexEndIndex - info.fVertexStartIndex; |
878 memcpy(currVertex, blob->fVertices + info.fVertexStartIndex, byteCou
nt); | 885 memcpy(currVertex, blob->fVertices + info.fVertexStartIndex, byteCou
nt); |
879 | 886 |
880 currVertex += byteCount; | 887 currVertex += byteCount; |
881 } | 888 } |
882 | 889 |
883 this->flush(batchTarget, &drawInfo, instancesToFlush, maxInstancesPerDra
w); | 890 this->flush(batchTarget, &drawInfo, instancesToFlush, maxInstancesPerDra
w); |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1128 | 1135 |
1129 GrColor color = grPaint.getColor(); | 1136 GrColor color = grPaint.getColor(); |
1130 SkPaint runPaint = skPaint; | 1137 SkPaint runPaint = skPaint; |
1131 for (int run = 0; run < cacheBlob->fRunCount; run++) { | 1138 for (int run = 0; run < cacheBlob->fRunCount; run++) { |
1132 this->flushRun(target, &pipelineBuilder, cacheBlob, run, color, skPaint)
; | 1139 this->flushRun(target, &pipelineBuilder, cacheBlob, run, color, skPaint)
; |
1133 } | 1140 } |
1134 | 1141 |
1135 // Now flush big glyphs | 1142 // Now flush big glyphs |
1136 this->flushBigGlyphs(cacheBlob, rt, grPaint, clip); | 1143 this->flushBigGlyphs(cacheBlob, rt, grPaint, clip); |
1137 } | 1144 } |
OLD | NEW |