GPU Font Cache improvements:
- If a strike has multiple atlases, check all for room for a new glyph
- Mark remaining atlases unused after a purge, then check for an unused
atlas before purging (reduces TextContext flushes and ghosting)
- Hide Atlas management a little better inside AtlasMgr

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

Author: jvanverth@google.com

Review URL: https://chromiumcodereview.appspot.com/21594005

git-svn-id: http://skia.googlecode.com/svn/trunk@10544 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/gpu/GrAtlas.h b/src/gpu/GrAtlas.h
index 40a2154..b6f25c2 100644
--- a/src/gpu/GrAtlas.h
+++ b/src/gpu/GrAtlas.h
@@ -20,8 +20,6 @@
 
 class GrAtlas {
 public:
-    GrAtlas(GrAtlasMgr*, int plotX, int plotY, GrMaskFormat);
-
     int getPlotX() const { return fPlot.fX; }
     int getPlotY() const { return fPlot.fY; }
     GrMaskFormat getMaskFormat() const { return fMaskFormat; }
@@ -31,20 +29,34 @@
     bool addSubImage(int width, int height, const void*, GrIPoint16*);
 
     static void FreeLList(GrAtlas* atlas) {
-        while (atlas) {
+        while (NULL != atlas) {
             GrAtlas* next = atlas->fNext;
             delete atlas;
             atlas = next;
         }
     }
 
-    // testing
-    GrAtlas* nextAtlas() const { return fNext; }
+    static void MarkAllUnused(GrAtlas* atlas) {
+        while (NULL != atlas) {
+            atlas->fUsed = false;
+            atlas = atlas->fNext;
+        }
+    }
+
+    static bool RemoveUnusedAtlases(GrAtlasMgr* atlasMgr, GrAtlas** startAtlas);
+
+    bool used() const { return fUsed; }
+    void setUsed(bool used) { fUsed = used; }
 
 private:
+    GrAtlas(GrAtlasMgr*, int plotX, int plotY, GrMaskFormat format);
     ~GrAtlas(); // does not try to delete the fNext field
 
     GrAtlas*        fNext;
+
+    // for recycling
+    bool            fUsed;
+
     GrTexture*      fTexture;
     GrRectanizer*   fRects;
     GrAtlasMgr*     fAtlasMgr;
@@ -61,8 +73,9 @@
     GrAtlasMgr(GrGpu*);
     ~GrAtlasMgr();
 
-    GrAtlas* addToAtlas(GrAtlas*, int width, int height, const void*,
+    GrAtlas* addToAtlas(GrAtlas**, int width, int height, const void*,
                         GrMaskFormat, GrIPoint16*);
+    void deleteAtlas(GrAtlas* atlas) { delete atlas; }
 
     GrTexture* getTexture(GrMaskFormat format) const {
         GrAssert((unsigned)format < kCount_GrMaskFormats);
@@ -70,7 +83,7 @@
     }
 
     // to be called by ~GrAtlas()
-    void freePlot(int x, int y);
+    void freePlot(GrMaskFormat format, int x, int y);
 
 private:
     GrGpu*      fGpu;