Provide an option in bench_pictures to count pixel ram.

In SkLruImageCache, provide an option to keep all pixels, and document
the new behavior.

In gm/factory.cpp, set the budget for the Lru image cache to 1, to
retain (basically) the old behavior.

BUG=https://code.google.com/p/skia/issues/detail?id=1010

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

git-svn-id: http://skia.googlecode.com/svn/trunk@7972 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/tools/bench_pictures_main.cpp b/tools/bench_pictures_main.cpp
index 0c7644f..d027db9 100644
--- a/tools/bench_pictures_main.cpp
+++ b/tools/bench_pictures_main.cpp
@@ -26,6 +26,7 @@
 SkBenchLogger gLogger;
 
 // Flags used by this file, in alphabetical order.
+DEFINE_bool(countRAM, false, "Count the RAM used for bitmap pixels in each skp file");
 DECLARE_bool(deferImageDecoding);
 DEFINE_string(filter, "",
         "type:flag : Enable canvas filtering to disable a paint flag, "
@@ -173,6 +174,13 @@
         return false;
     }
 
+    // Since the old picture has been deleted, all pixels should be cleared.
+    SkASSERT(gLruImageCache.getImageCacheUsed() == 0);
+    if (FLAGS_countRAM) {
+        // Set the limit to zero, so all pixels will be kept
+        gLruImageCache.setImageCacheLimit(0);
+    }
+
     bool success = false;
     SkPicture* picture;
     if (FLAGS_deferImageDecoding) {
@@ -204,11 +212,29 @@
         int32_t cacheHits = SkLazyPixelRef::GetCacheHits();
         int32_t cacheMisses = SkLazyPixelRef::GetCacheMisses();
         SkLazyPixelRef::ResetCacheStats();
-        SkDebugf("Cache hit rate: %f\n", (double) cacheHits / (cacheHits + cacheMisses));
+        SkString hitString;
+        hitString.printf("Cache hit rate: %f\n", (double) cacheHits / (cacheHits + cacheMisses));
+        gLogger.logProgress(hitString);
         gTotalCacheHits += cacheHits;
         gTotalCacheMisses += cacheMisses;
     }
 #endif
+    if (FLAGS_countRAM) {
+        SkString ramCount("RAM used for bitmaps: ");
+        size_t bytes = gLruImageCache.getImageCacheUsed();
+        if (bytes > 1024) {
+            size_t kb = bytes / 1024;
+            if (kb > 1024) {
+                size_t mb = kb / 1024;
+                ramCount.appendf("%zi MB\n", mb);
+            } else {
+                ramCount.appendf("%zi KB\n", kb);
+            }
+        } else {
+            ramCount.appendf("%zi bytes\n", bytes);
+        }
+        gLogger.logProgress(ramCount);
+    }
 
     return true;
 }