Index: src/gpu/text/GrAtlasTextBlob_regenInBatch.cpp |
diff --git a/src/gpu/text/GrAtlasTextBlob_regenInBatch.cpp b/src/gpu/text/GrAtlasTextBlob_regenInBatch.cpp |
index e5a8956517cad675758ae5cec291c23608b5bfdf..af015a4bc7744b527eaf549e86596c1c53feb1f0 100644 |
--- a/src/gpu/text/GrAtlasTextBlob_regenInBatch.cpp |
+++ b/src/gpu/text/GrAtlasTextBlob_regenInBatch.cpp |
@@ -137,14 +137,27 @@ inline void regen_vertices(intptr_t vertex, const GrGlyph* glyph, size_t vertexS |
} |
} |
+void GrAtlasTextBlob::LazyGlyphCache::initIfNecessary(Run* run, Run::SubRunInfo* info) { |
+ // We can reuse if we have a valid strike and our descriptors / typeface are the same. The |
+ // override descriptor is only for the non-distance field text within a run a run |
+ const SkDescriptor* newDesc = (run->fOverrideDescriptor && !info->drawAsDistanceFields()) |
+ ? run->fOverrideDescriptor->getDesc() |
+ : run->fDescriptor.getDesc(); |
+ if (!fCache || !SkTypeface::Equal(fTypeface, run->fTypeface) || |
bsalomon
2016/05/18 01:53:22
Ben, is it possible for the descriptors to match w
|
+ fCache->getDescriptor() != *newDesc) { |
+ fCache.reset(SkGlyphCache::DetachCache(run->fTypeface, run->fEffects, newDesc)); |
+ SkASSERT(*newDesc == fCache->getDescriptor()); |
+ fTypeface = run->fTypeface; |
+ } |
+} |
+ |
template <bool regenPos, bool regenCol, bool regenTexCoords, bool regenGlyphs> |
void GrAtlasTextBlob::regenInBatch(GrDrawBatch::Target* target, |
GrBatchFontCache* fontCache, |
GrBlobRegenHelper *helper, |
Run* run, |
- Run::SubRunInfo* info, SkGlyphCache** cache, |
- SkTypeface** typeface, |
- const SkDescriptor** desc, |
+ Run::SubRunInfo* info, |
+ LazyGlyphCache* lazyCache, |
int glyphCount, size_t vertexStride, |
GrColor color, SkScalar transX, |
SkScalar transY) const { |
@@ -153,24 +166,10 @@ void GrAtlasTextBlob::regenInBatch(GrDrawBatch::Target* target, |
if (regenTexCoords) { |
info->resetBulkUseToken(); |
- // We can reuse if we have a valid strike and our descriptors / typeface are the |
- // same. The override descriptor is only for the non distance field text within |
- // a run |
- const SkDescriptor* newDesc = (run->fOverrideDescriptor && !info->drawAsDistanceFields()) ? |
- run->fOverrideDescriptor->getDesc() : |
- run->fDescriptor.getDesc(); |
- if (!*cache || !SkTypeface::Equal(*typeface, run->fTypeface) || |
- !(**desc == *newDesc)) { |
- if (*cache) { |
- SkGlyphCache::AttachCache(*cache); |
- } |
- *desc = newDesc; |
- *cache = SkGlyphCache::DetachCache(run->fTypeface, run->fEffects, *desc); |
- *typeface = run->fTypeface; |
- } |
+ lazyCache->initIfNecessary(run, info); |
if (regenGlyphs) { |
- strike = fontCache->getStrike(*cache); |
+ strike = fontCache->getStrike(lazyCache->cache()); |
} else { |
strike = info->strike(); |
} |
@@ -187,20 +186,20 @@ void GrAtlasTextBlob::regenInBatch(GrDrawBatch::Target* target, |
// Get the id from the old glyph, and use the new strike to lookup |
// the glyph. |
GrGlyph::PackedID id = fGlyphs[glyphOffset]->fPackedID; |
- fGlyphs[glyphOffset] = strike->getGlyph(id, info->maskFormat(), *cache); |
+ fGlyphs[glyphOffset] = strike->getGlyph(id, info->maskFormat(), lazyCache->cache()); |
SkASSERT(id == fGlyphs[glyphOffset]->fPackedID); |
} |
glyph = fGlyphs[glyphOffset]; |
SkASSERT(glyph && glyph->fMaskFormat == info->maskFormat()); |
if (!fontCache->hasGlyph(glyph) && |
- !strike->addGlyphToAtlas(target, glyph, *cache, info->maskFormat())) { |
+ !strike->addGlyphToAtlas(target, glyph, lazyCache->cache(), info->maskFormat())) { |
helper->flush(); |
brokenRun = glyphIdx > 0; |
SkDEBUGCODE(bool success =) strike->addGlyphToAtlas(target, |
glyph, |
- *cache, |
+ lazyCache->cache(), |
info->maskFormat()); |
SkASSERT(success); |
} |
@@ -238,7 +237,7 @@ enum RegenMask { |
kRegenGlyph = 0x8 | kRegenTex, // we have to regenerate the texture coords when we regen glyphs |
// combinations |
- kRegenPosCol = kRegenPos | kRegenCol, |
+ kRegenPosCol = kRegenPos | kRegenCol, |
kRegenPosTex = kRegenPos | kRegenTex, |
kRegenPosTexGlyph = kRegenPos | kRegenGlyph, |
kRegenPosColTex = kRegenPos | kRegenCol | kRegenTex, |
@@ -247,14 +246,13 @@ enum RegenMask { |
kRegenColTexGlyph = kRegenCol | kRegenGlyph, |
}; |
-#define REGEN_ARGS target, fontCache, helper, &run, &info, cache, typeface, desc, \ |
+#define REGEN_ARGS target, fontCache, helper, &run, &info, lazyCache, \ |
*glyphCount, vertexStride, color, transX, transY |
void GrAtlasTextBlob::regenInBatch(GrDrawBatch::Target* target, |
GrBatchFontCache* fontCache, |
GrBlobRegenHelper *helper, |
- int runIndex, int subRunIndex, SkGlyphCache** cache, |
- SkTypeface** typeface, const SkDescriptor** desc, |
+ int runIndex, int subRunIndex, LazyGlyphCache* lazyCache, |
size_t vertexStride, const SkMatrix& viewMatrix, |
SkScalar x, SkScalar y, GrColor color, |
void** vertices, size_t* byteCount, int* glyphCount) { |