Correctly remove unused paths from the cache.

Change-Id: I41d9334dcd9871634037344ab49bf69383498161
diff --git a/libs/hwui/PathCache.cpp b/libs/hwui/PathCache.cpp
index b58785a..04d07db 100644
--- a/libs/hwui/PathCache.cpp
+++ b/libs/hwui/PathCache.cpp
@@ -92,10 +92,13 @@
 ///////////////////////////////////////////////////////////////////////////////
 
 void PathCache::operator()(PathCacheEntry& path, PathTexture*& texture) {
-    const uint32_t size = texture->width * texture->height;
-    mSize -= size;
-
     if (texture) {
+        const uint32_t size = texture->width * texture->height;
+        mSize -= size;
+
+        PATH_LOGD("PathCache::callback: delete path: name, size, mSize = %d, %d, %d",
+                texture->id, size, mSize);
+
         glDeleteTextures(1, &texture->id);
         delete texture;
     }
@@ -107,12 +110,18 @@
 
 void PathCache::remove(SkPath* path) {
     Mutex::Autolock _l(mLock);
+
     // TODO: Linear search...
+    Vector<uint32_t> pathsToRemove;
     for (uint32_t i = 0; i < mCache.size(); i++) {
         if (mCache.getKeyAt(i).path == path) {
-            mCache.removeAt(i);
+            pathsToRemove.push(i);
         }
     }
+
+    for (size_t i = 0; i < pathsToRemove.size(); i++) {
+        mCache.removeAt(pathsToRemove.itemAt(i));
+    }
 }
 
 PathTexture* PathCache::get(SkPath* path, SkPaint* paint) {
@@ -188,6 +197,8 @@
     if (size < mMaxSize) {
         mLock.lock();
         mSize += size;
+        PATH_LOGD("PathCache::get: create path: name, size, mSize = %d, %d, %d",
+                texture->id, size, mSize);
         mCache.put(entry, texture);
         mLock.unlock();
     } else {