GrAtlas cleanup: Split out GrPlot and GrAtlas

This breaks up GrAtlas into the head of the list (GrAtlas) and the list elements (GrPlot). It also moves all of the GrPlot management code into GrAtlasMgr. It adds a simple pool allocator for GrPlots and removes use of GrPlotMgr.

R=bsalomon@google.com, robertphillips@google.com

Author: jvanverth@google.com

Review URL: https://codereview.chromium.org/24981004

git-svn-id: http://skia.googlecode.com/svn/trunk@11508 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/gpu/GrTextStrike.cpp b/src/gpu/GrTextStrike.cpp
index d1f1861..e399c91 100644
--- a/src/gpu/GrTextStrike.cpp
+++ b/src/gpu/GrTextStrike.cpp
@@ -103,7 +103,7 @@
         strike = strikeToPurge->fPrev;
         if (purge) {
             // keep purging if we won't free up any atlases with this strike.
-            purge = (NULL == strikeToPurge->fAtlas);
+            purge = strikeToPurge->fAtlas.isEmpty();
             int index = fCache.slowFindIndex(strikeToPurge);
             SkASSERT(index >= 0);
             fCache.removeAt(index, strikeToPurge->fFontScalerKey->getHash());
@@ -116,7 +116,7 @@
 #endif
 }
 
-void GrFontCache::freeAtlasExceptFor(GrTextStrike* preserveStrike) {
+void GrFontCache::freePlotExceptFor(GrTextStrike* preserveStrike) {
     SkASSERT(NULL != preserveStrike);
     GrTextStrike* strike = fTail;
     GrMaskFormat maskFormat = preserveStrike->fMaskFormat;
@@ -127,8 +127,8 @@
         }
         GrTextStrike* strikeToPurge = strike;
         strike = strikeToPurge->fPrev;
-        if (strikeToPurge->removeUnusedAtlases()) {
-            if (NULL == strikeToPurge->fAtlas) {
+        if (strikeToPurge->removeUnusedPlots()) {
+            if (strikeToPurge->fAtlas.isEmpty()) {
                 int index = fCache.slowFindIndex(strikeToPurge);
                 SkASSERT(index >= 0);
                 fCache.removeAt(index, strikeToPurge->fFontScalerKey->getHash());
@@ -186,13 +186,12 @@
 
 GrTextStrike::GrTextStrike(GrFontCache* cache, const GrKey* key,
                            GrMaskFormat format,
-                           GrAtlasMgr* atlasMgr) : fPool(64) {
+                           GrAtlasMgr* atlasMgr) : fPool(64), fAtlas(atlasMgr) {
     fFontScalerKey = key;
     fFontScalerKey->ref();
 
     fFontCache = cache;     // no need to ref, it won't go away before we do
     fAtlasMgr = atlasMgr;   // no need to ref, it won't go away before we do
-    fAtlas = NULL;
 
     fMaskFormat = format;
 
@@ -207,13 +206,12 @@
 static void free_glyph(GrGlyph*& glyph) { glyph->free(); }
 
 static void invalidate_glyph(GrGlyph*& glyph) {
-    if (glyph->fAtlas && glyph->fAtlas->drawToken().isIssued()) {
-        glyph->fAtlas = NULL;
+    if (glyph->fPlot && glyph->fPlot->drawToken().isIssued()) {
+        glyph->fPlot = NULL;
     }
 }
 
 GrTextStrike::~GrTextStrike() {
-    GrAtlas::FreeLList(fAtlas);
     fFontScalerKey->unref();
     fCache.getArray().visitAll(free_glyph);
 
@@ -236,9 +234,9 @@
     return glyph;
 }
 
-bool GrTextStrike::removeUnusedAtlases() {
+bool GrTextStrike::removeUnusedPlots() {
     fCache.getArray().visitAll(invalidate_glyph);
-    return GrAtlas::RemoveUnusedAtlases(fAtlasMgr, &fAtlas);
+    return fAtlasMgr->removeUnusedPlots(&fAtlas);
 }
 
 bool GrTextStrike::getGlyphAtlas(GrGlyph* glyph, GrFontScaler* scaler,
@@ -251,8 +249,8 @@
     SkASSERT(glyph);
     SkASSERT(scaler);
     SkASSERT(fCache.contains(glyph));
-    if (glyph->fAtlas) {
-        glyph->fAtlas->setDrawToken(currentDrawToken);
+    if (glyph->fPlot) {
+        glyph->fPlot->setDrawToken(currentDrawToken);
         return true;
     }
 
@@ -268,14 +266,14 @@
         return false;
     }
 
-    GrAtlas* atlas = fAtlasMgr->addToAtlas(&fAtlas, glyph->width(),
-                                           glyph->height(), storage.get(),
-                                           &glyph->fAtlasLocation);
-    if (NULL == atlas) {
+    GrPlot* plot = fAtlasMgr->addToAtlas(&fAtlas, glyph->width(),
+                                         glyph->height(), storage.get(),
+                                         &glyph->fAtlasLocation);
+    if (NULL == plot) {
         return false;
     }
 
-    glyph->fAtlas = atlas;
-    atlas->setDrawToken(currentDrawToken);
+    glyph->fPlot = plot;
+    plot->setDrawToken(currentDrawToken);
     return true;
 }