Chromium Code Reviews| Index: src/gpu/GrTextStrike.cpp |
| diff --git a/src/gpu/GrTextStrike.cpp b/src/gpu/GrTextStrike.cpp |
| index 8ae10cc8ddafc937230b61be62408e830914012c..647ae84ba80d40ddb781e578f42582ce60bd6cd0 100644 |
| --- a/src/gpu/GrTextStrike.cpp |
| +++ b/src/gpu/GrTextStrike.cpp |
| @@ -80,20 +80,7 @@ static int mask_format_to_atlas_index(GrMaskFormat format) { |
| } |
| GrTextStrike* GrFontCache::generateStrike(GrFontScaler* scaler) { |
| - GrMaskFormat format = scaler->getMaskFormat(); |
| - GrPixelConfig config = mask_format_to_pixel_config(format); |
| - int atlasIndex = mask_format_to_atlas_index(format); |
| - if (NULL == fAtlases[atlasIndex]) { |
| - SkISize textureSize = SkISize::Make(GR_ATLAS_TEXTURE_WIDTH, |
| - GR_ATLAS_TEXTURE_HEIGHT); |
| - fAtlases[atlasIndex] = SkNEW_ARGS(GrAtlas, (fGpu, config, kNone_GrTextureFlags, |
| - textureSize, |
| - GR_NUM_PLOTS_X, |
| - GR_NUM_PLOTS_Y, |
| - true)); |
| - } |
| - GrTextStrike* strike = SkNEW_ARGS(GrTextStrike, |
| - (this, scaler->getKey(), format, fAtlases[atlasIndex])); |
| + GrTextStrike* strike = SkNEW_ARGS(GrTextStrike, (this, scaler->getKey())); |
| fCache.add(strike); |
| if (fHead) { |
| @@ -130,10 +117,31 @@ void GrFontCache::purgeStrike(GrTextStrike* strike) { |
| delete strike; |
| } |
| -bool GrFontCache::freeUnusedPlot(GrTextStrike* preserveStrike) { |
| + |
| +GrPlot* GrFontCache::addToAtlas(GrMaskFormat format, GrAtlas::ClientPlotUsage* usage, |
| + int width, int height, const void* image, |
| + SkIPoint16* loc) { |
|
robertphillips
2014/10/09 16:14:53
Do we need both index and atlasIndex ?
jvanverth1
2014/10/09 17:34:35
Done.
|
| + int index = mask_format_to_atlas_index(format); |
| + GrPixelConfig config = mask_format_to_pixel_config(format); |
| + int atlasIndex = mask_format_to_atlas_index(format); |
| + if (NULL == fAtlases[atlasIndex]) { |
| + SkISize textureSize = SkISize::Make(GR_ATLAS_TEXTURE_WIDTH, |
| + GR_ATLAS_TEXTURE_HEIGHT); |
| + fAtlases[atlasIndex] = SkNEW_ARGS(GrAtlas, (fGpu, config, kNone_GrTextureFlags, |
| + textureSize, |
| + GR_NUM_PLOTS_X, |
| + GR_NUM_PLOTS_Y, |
| + true)); |
| + } |
| + return fAtlases[index]->addToAtlas(usage, width, height, image, loc); |
| +} |
| + |
| + |
| +bool GrFontCache::freeUnusedPlot(GrTextStrike* preserveStrike, const GrGlyph* glyph) { |
| SkASSERT(preserveStrike); |
| - GrAtlas* atlas = preserveStrike->fAtlas; |
| + int index = mask_format_to_atlas_index(glyph->fMaskFormat); |
| + GrAtlas* atlas = fAtlases[index]; |
| GrPlot* plot = atlas->getUnusedPlot(); |
| if (NULL == plot) { |
| return false; |
| @@ -141,13 +149,7 @@ bool GrFontCache::freeUnusedPlot(GrTextStrike* preserveStrike) { |
| 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); |
| @@ -228,16 +230,11 @@ void GrFontCache::dump() const { |
| atlas and a position within that texture. |
| */ |
| -GrTextStrike::GrTextStrike(GrFontCache* cache, const GrFontDescKey* key, |
| - GrMaskFormat format, |
| - GrAtlas* atlas) : fPool(64) { |
| +GrTextStrike::GrTextStrike(GrFontCache* cache, const GrFontDescKey* key) : 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); |
| @@ -271,9 +268,10 @@ GrGlyph* GrTextStrike::generateGlyph(GrGlyph::PackedID packed, |
| return NULL; |
| } |
| } |
| - |
| + GrMaskFormat format = scaler->getPackedGlyphMaskFormat(packed); |
| + |
| GrGlyph* glyph = fPool.alloc(); |
| - glyph->init(packed, bounds); |
| + glyph->init(packed, bounds, format); |
| fCache.add(glyph); |
| return glyph; |
| } |
| @@ -317,7 +315,7 @@ bool GrTextStrike::addGlyphToAtlas(GrGlyph* glyph, GrFontScaler* scaler) { |
| SkAutoUnref ar(SkSafeRef(scaler)); |
| - int bytesPerPixel = GrMaskFormatBytesPerPixel(fMaskFormat); |
| + int bytesPerPixel = GrMaskFormatBytesPerPixel(glyph->fMaskFormat); |
| size_t size = glyph->fBounds.area() * bytesPerPixel; |
| GrAutoMalloc<1024> storage(size); |
| @@ -337,9 +335,9 @@ bool GrTextStrike::addGlyphToAtlas(GrGlyph* glyph, GrFontScaler* scaler) { |
| } |
| } |
| - GrPlot* plot = fAtlas->addToAtlas(&fPlotUsage, glyph->width(), |
| - glyph->height(), storage.get(), |
| - &glyph->fAtlasLocation); |
| + GrPlot* plot = fFontCache->addToAtlas(glyph->fMaskFormat, &fPlotUsage, |
| + glyph->width(), glyph->height(), |
| + storage.get(), &glyph->fAtlasLocation); |
| if (NULL == plot) { |
| return false; |