Index: src/gpu/GrTextStrike.cpp |
diff --git a/src/gpu/GrTextStrike.cpp b/src/gpu/GrTextStrike.cpp |
index 81be3418f7ca1d8c71596bdbfb0afb55f16b602e..8ae10cc8ddafc937230b61be62408e830914012c 100644 |
--- a/src/gpu/GrTextStrike.cpp |
+++ b/src/gpu/GrTextStrike.cpp |
@@ -80,47 +80,7 @@ |
} |
GrTextStrike* GrFontCache::generateStrike(GrFontScaler* scaler) { |
- GrTextStrike* strike = SkNEW_ARGS(GrTextStrike, (this, scaler->getKey())); |
- fCache.add(strike); |
- |
- if (fHead) { |
- fHead->fPrev = strike; |
- } else { |
- SkASSERT(NULL == fTail); |
- fTail = strike; |
- } |
- strike->fPrev = NULL; |
- strike->fNext = fHead; |
- fHead = strike; |
- |
- return strike; |
-} |
- |
-void GrFontCache::freeAll() { |
- SkTDynamicHash<GrTextStrike, GrFontDescKey>::Iter iter(&fCache); |
- while (!iter.done()) { |
- SkDELETE(&(*iter)); |
- ++iter; |
- } |
- fCache.rewind(); |
- for (int i = 0; i < kAtlasCount; ++i) { |
- delete fAtlases[i]; |
- fAtlases[i] = NULL; |
- } |
- fHead = NULL; |
- fTail = NULL; |
-} |
- |
-void GrFontCache::purgeStrike(GrTextStrike* strike) { |
- fCache.remove(*(strike->fFontScalerKey)); |
- this->detachStrikeFromList(strike); |
- delete strike; |
-} |
- |
- |
-GrPlot* GrFontCache::addToAtlas(GrMaskFormat format, GrAtlas::ClientPlotUsage* usage, |
- int width, int height, const void* image, |
- SkIPoint16* loc) { |
+ GrMaskFormat format = scaler->getMaskFormat(); |
GrPixelConfig config = mask_format_to_pixel_config(format); |
int atlasIndex = mask_format_to_atlas_index(format); |
if (NULL == fAtlases[atlasIndex]) { |
@@ -132,15 +92,48 @@ |
GR_NUM_PLOTS_Y, |
true)); |
} |
- return fAtlases[atlasIndex]->addToAtlas(usage, width, height, image, loc); |
-} |
- |
- |
-bool GrFontCache::freeUnusedPlot(GrTextStrike* preserveStrike, const GrGlyph* glyph) { |
+ GrTextStrike* strike = SkNEW_ARGS(GrTextStrike, |
+ (this, scaler->getKey(), format, fAtlases[atlasIndex])); |
+ fCache.add(strike); |
+ |
+ if (fHead) { |
+ fHead->fPrev = strike; |
+ } else { |
+ SkASSERT(NULL == fTail); |
+ fTail = strike; |
+ } |
+ strike->fPrev = NULL; |
+ strike->fNext = fHead; |
+ fHead = strike; |
+ |
+ return strike; |
+} |
+ |
+void GrFontCache::freeAll() { |
+ SkTDynamicHash<GrTextStrike, GrFontDescKey>::Iter iter(&fCache); |
+ while (!iter.done()) { |
+ SkDELETE(&(*iter)); |
+ ++iter; |
+ } |
+ fCache.rewind(); |
+ for (int i = 0; i < kAtlasCount; ++i) { |
+ delete fAtlases[i]; |
+ fAtlases[i] = NULL; |
+ } |
+ fHead = NULL; |
+ fTail = NULL; |
+} |
+ |
+void GrFontCache::purgeStrike(GrTextStrike* strike) { |
+ fCache.remove(*(strike->fFontScalerKey)); |
+ this->detachStrikeFromList(strike); |
+ delete strike; |
+} |
+ |
+bool GrFontCache::freeUnusedPlot(GrTextStrike* preserveStrike) { |
SkASSERT(preserveStrike); |
- int index = mask_format_to_atlas_index(glyph->fMaskFormat); |
- GrAtlas* atlas = fAtlases[index]; |
+ GrAtlas* atlas = preserveStrike->fAtlas; |
GrPlot* plot = atlas->getUnusedPlot(); |
if (NULL == plot) { |
return false; |
@@ -148,7 +141,13 @@ |
plot->resetRects(); |
GrTextStrike* strike = fHead; |
+ GrMaskFormat maskFormat = preserveStrike->fMaskFormat; |
while (strike) { |
+ if (maskFormat != strike->fMaskFormat) { |
+ strike = strike->fNext; |
+ continue; |
+ } |
+ |
GrTextStrike* strikeToPurge = strike; |
strike = strikeToPurge->fNext; |
strikeToPurge->removePlot(plot); |
@@ -229,11 +228,16 @@ |
atlas and a position within that texture. |
*/ |
-GrTextStrike::GrTextStrike(GrFontCache* cache, const GrFontDescKey* key) : fPool(64) { |
+GrTextStrike::GrTextStrike(GrFontCache* cache, const GrFontDescKey* key, |
+ GrMaskFormat format, |
+ GrAtlas* atlas) : fPool(64) { |
fFontScalerKey = key; |
fFontScalerKey->ref(); |
fFontCache = cache; // no need to ref, it won't go away before we do |
+ fAtlas = atlas; // no need to ref, it won't go away before we do |
+ |
+ fMaskFormat = format; |
#ifdef SK_DEBUG |
// GrPrintf(" GrTextStrike %p %d\n", this, gCounter); |
@@ -267,10 +271,9 @@ |
return NULL; |
} |
} |
- GrMaskFormat format = scaler->getPackedGlyphMaskFormat(packed); |
- |
+ |
GrGlyph* glyph = fPool.alloc(); |
- glyph->init(packed, bounds, format); |
+ glyph->init(packed, bounds); |
fCache.add(glyph); |
return glyph; |
} |
@@ -314,7 +317,7 @@ |
SkAutoUnref ar(SkSafeRef(scaler)); |
- int bytesPerPixel = GrMaskFormatBytesPerPixel(glyph->fMaskFormat); |
+ int bytesPerPixel = GrMaskFormatBytesPerPixel(fMaskFormat); |
size_t size = glyph->fBounds.area() * bytesPerPixel; |
GrAutoMalloc<1024> storage(size); |
@@ -334,9 +337,9 @@ |
} |
} |
- GrPlot* plot = fFontCache->addToAtlas(glyph->fMaskFormat, &fPlotUsage, |
- glyph->width(), glyph->height(), |
- storage.get(), &glyph->fAtlasLocation); |
+ GrPlot* plot = fAtlas->addToAtlas(&fPlotUsage, glyph->width(), |
+ glyph->height(), storage.get(), |
+ &glyph->fAtlasLocation); |
if (NULL == plot) { |
return false; |