Made gradient effects use GrTextureStripAtlas.
Review URL: https://codereview.appspot.com/6450131

git-svn-id: http://skia.googlecode.com/svn/trunk@5101 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/gpu/effects/GrTextureStripAtlas.cpp b/src/gpu/effects/GrTextureStripAtlas.cpp
index 1a8a93b..3f3b29d 100644
--- a/src/gpu/effects/GrTextureStripAtlas.cpp
+++ b/src/gpu/effects/GrTextureStripAtlas.cpp
@@ -34,14 +34,8 @@
     GrTextureStripAtlas* fAtlas;
 };
 
-// Ugly way of ensuring that we clean up the atlases on exit
-struct AtlasEntries {
-    ~AtlasEntries() { fEntries.deleteAll(); }
-    SkTDArray<AtlasEntry*> fEntries;
-};
-
 GrTextureStripAtlas* GrTextureStripAtlas::GetAtlas(const GrTextureStripAtlas::Desc& desc) {
-    static AtlasEntries gAtlasEntries;
+    static SkTDArray<AtlasEntry> gAtlasEntries;
     static GrTHashTable<AtlasEntry, AtlasHashKey, 8> gAtlasCache;
     AtlasHashKey key;
     key.setKeyData(desc.asKey());
@@ -49,8 +43,7 @@
     if (NULL != entry) {
         return entry->fAtlas;
     } else {
-        entry = SkNEW(AtlasEntry);
-        gAtlasEntries.fEntries.push(entry);
+        entry = gAtlasEntries.push();
         entry->fAtlas = SkNEW_ARGS(GrTextureStripAtlas, (desc));
         entry->fKey = key;
         gAtlasCache.insert(key, entry);
@@ -115,8 +108,6 @@
         this->removeFromLRU(row);
 
         uint32_t oldKey = row->fKey;
-        row->fKey = key;
-        row->fLocks = 1;
 
         // If we are writing into a row that already held bitmap data, we need to remove the
         // reference to that genID which is stored in our sorted table of key values.
@@ -125,13 +116,15 @@
             // Find the entry in the list; if it's before the index where we plan on adding the new
             // entry, we decrement since it will shift elements ahead of it back by one.
             int oldIndex = this->searchByKey(oldKey);
-            if (oldIndex <= index) {
+            if (oldIndex < index) {
                 --index;
             }
 
             fKeyTable.remove(oldIndex);
         }
 
+        row->fKey = key;
+        row->fLocks = 1;
         fKeyTable.insert(index, 1, &row);
         rowNumber = static_cast<int>(row - fRows);