First pass at font cache refactor: Create an atlas manager per texture
This changes the AtlasMgr from a singleton class to one that is
created per-texture. This is the first step in allowing us to create
Atlases of other types (e.g., combine small icons into one big texture).
R=bsalomon@google.com
Author: jvanverth@google.com
Review URL: https://chromiumcodereview.appspot.com/24608002
git-svn-id: http://skia.googlecode.com/svn/trunk@11468 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/gpu/GrTextStrike.cpp b/src/gpu/GrTextStrike.cpp
index 47b6216..5798e5f 100644
--- a/src/gpu/GrTextStrike.cpp
+++ b/src/gpu/GrTextStrike.cpp
@@ -23,14 +23,18 @@
GrFontCache::GrFontCache(GrGpu* gpu) : fGpu(gpu) {
gpu->ref();
- fAtlasMgr = NULL;
+ for (int i = 0; i < kMaskFormatCount; ++i) {
+ fAtlasMgr[i] = NULL;
+ }
fHead = fTail = NULL;
}
GrFontCache::~GrFontCache() {
fCache.deleteAll();
- delete fAtlasMgr;
+ for (int i = 0; i < kMaskFormatCount; ++i) {
+ delete fAtlasMgr[i];
+ }
fGpu->unref();
#if FONT_CACHE_STATS
GrPrintf("Num purges: %d\n", g_PurgeCount);
@@ -39,12 +43,13 @@
GrTextStrike* GrFontCache::generateStrike(GrFontScaler* scaler,
const Key& key) {
- if (NULL == fAtlasMgr) {
- fAtlasMgr = SkNEW_ARGS(GrAtlasMgr, (fGpu));
+ GrMaskFormat format = scaler->getMaskFormat();
+ if (NULL == fAtlasMgr[format]) {
+ fAtlasMgr[format] = SkNEW_ARGS(GrAtlasMgr, (fGpu, format));
}
GrTextStrike* strike = SkNEW_ARGS(GrTextStrike,
(this, scaler->getKey(),
- scaler->getMaskFormat(), fAtlasMgr));
+ scaler->getMaskFormat(), fAtlasMgr[format]));
fCache.insert(key, strike);
if (fHead) {
@@ -62,8 +67,10 @@
void GrFontCache::freeAll() {
fCache.deleteAll();
- delete fAtlasMgr;
- fAtlasMgr = NULL;
+ for (int i = 0; i < kMaskFormatCount; ++i) {
+ delete fAtlasMgr[i];
+ fAtlasMgr[i] = NULL;
+ }
fHead = NULL;
fTail = NULL;
}
@@ -249,7 +256,6 @@
GrAtlas* atlas = fAtlasMgr->addToAtlas(&fAtlas, glyph->width(),
glyph->height(), storage.get(),
- fMaskFormat,
&glyph->fAtlasLocation);
if (NULL == atlas) {
return false;