New approach for GPU font atlas

In the previous code, each GrTextStrike had exclusive access to one or more GrPlots in the texture atlas. This led to poor packing when only a few glyphs were used. This change allows GrTextStrikes to share GrPlots, thereby getting much better utilization of the entire texture.

BUG=skia:2224
R=robertphillips@google.com, bsalomon@google.com

Author: jvanverth@google.com

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

git-svn-id: http://skia.googlecode.com/svn/trunk@13636 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/gpu/GrDistanceFieldTextContext.cpp b/src/gpu/GrDistanceFieldTextContext.cpp
index c22807d..e372b6c 100755
--- a/src/gpu/GrDistanceFieldTextContext.cpp
+++ b/src/gpu/GrDistanceFieldTextContext.cpp
@@ -161,13 +161,13 @@
     }
 */
     if (NULL == glyph->fPlot) {
-        if (fStrike->getGlyphAtlas(glyph, scaler)) {
+        if (fStrike->addGlyphToAtlas(glyph, scaler)) {
             goto HAS_ATLAS;
         }
 
         // try to clear out an unused plot before we flush
-        fContext->getFontCache()->freePlotExceptFor(fStrike);
-        if (fStrike->getGlyphAtlas(glyph, scaler)) {
+        if (fContext->getFontCache()->freeUnusedPlot(fStrike) &&
+            fStrike->addGlyphToAtlas(glyph, scaler)) {
             goto HAS_ATLAS;
         }
 
@@ -181,10 +181,9 @@
         this->flushGlyphs();
         fContext->flush();
 
-        // try to purge
-        fContext->getFontCache()->purgeExceptFor(fStrike);
-        // need to use new flush count here
-        if (fStrike->getGlyphAtlas(glyph, scaler)) {
+        // we should have an unused plot now
+        if (fContext->getFontCache()->freeUnusedPlot(fStrike) &&
+            fStrike->addGlyphToAtlas(glyph, scaler)) {
             goto HAS_ATLAS;
         }