bool GrFontCache::freeUnusedPlot(GrTextStrike* preserveStrike, const GrGlyph* glyph) { SkASSERT(preserveStrike); int index = mask_format_to_atlas_index(glyph->fMaskFormat); GrAtlas* atlas = fAtlases[index]; GrPlot* plot = atlas->getUnusedPlot(); if (NULL == plot) { return false; } plot->resetRects(); GrTextStrike* strike = fHead; while (strike) { GrTextStrike* strikeToPurge = strike; strike = strikeToPurge->fNext; strikeToPurge->removePlot(plot); // clear out any empty strikes (except this one) if (strikeToPurge != preserveStrike && strikeToPurge->fPlotUsage.isEmpty()) { this->purgeStrike(strikeToPurge); } } #if FONT_CACHE_STATS ++g_PurgeCount; #endif return true; }
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])); fCache.add(strike); if (fHead) { fHead->fPrev = strike; } else { SkASSERT(NULL == fTail); fTail = strike; } strike->fPrev = NULL; strike->fNext = fHead; fHead = strike; return strike; }
GrPlot* GrFontCache::addToAtlas(GrMaskFormat format, GrAtlas::ClientPlotUsage* usage, int width, int height, const void* image, SkIPoint16* loc) { 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_GrSurfaceFlags, textureSize, GR_NUM_PLOTS_X, GR_NUM_PLOTS_Y, true)); } return fAtlases[atlasIndex]->addToAtlas(usage, width, height, image, loc); }