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