Improvements/additions to SkImageCache/SkLazyPixelRef.

SkPurgeableImageCache:
New image cache that uses virtual memory to store the pixels. Combines
features of SkAshmemImageCache (which has been removed) with SkPurgeableMemoryBlock, which has android and Mac versions.

SkImageCache:
Modified the API. pinCache now returns a status out parameter which
states whether the pinned memory retained the old data. This allows
allocAndPinCache to only be used for allocations.
Add a new debug only interface to purge unpinned data.
Updates to documentation, clarifying behavior.
Changed CachedStatus to MemoryStatus

SkLruImageCache:
Implement the new function purgeAllUnpinnedCaches and change implementation
of pinCache for the new behavior.

SkLazyPixelRef:
Rewrite onLockPixels to account for the new behavior of pinCache.

BitmapFactoryTest:
Test the new SkPurgeableImageCache.
Write tests which directly test the SkImageCaches.
Create a larger bitmap, since some of the SkImageCaches are designed
to handle large bitmaps.

bench_ and render_pictures:
Consolidate lazy_decode_bitmap into one function.
Allow using a flag to specify using the purgeable image cache.
Clean up some #includes.

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

git-svn-id: http://skia.googlecode.com/svn/trunk@8207 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/lazy/SkLruImageCache.cpp b/src/lazy/SkLruImageCache.cpp
index 54f26fb..26f7ef5 100644
--- a/src/lazy/SkLruImageCache.cpp
+++ b/src/lazy/SkLruImageCache.cpp
@@ -74,16 +74,24 @@
 }
 
 #ifdef SK_DEBUG
-SkImageCache::CacheStatus SkLruImageCache::getCacheStatus(intptr_t ID) const {
+SkImageCache::MemoryStatus SkLruImageCache::getMemoryStatus(intptr_t ID) const {
+    if (SkImageCache::UNINITIALIZED_ID == ID) {
+        return SkImageCache::kFreed_MemoryStatus;
+    }
     SkAutoMutexAcquire ac(&fMutex);
     CachedPixels* pixels = this->findByID(ID);
     if (NULL == pixels) {
-        return SkImageCache::kThrownAway_CacheStatus;
+        return SkImageCache::kFreed_MemoryStatus;
     }
     if (pixels->isLocked()) {
-        return SkImageCache::kPinned_CacheStatus;
+        return SkImageCache::kPinned_MemoryStatus;
     }
-    return SkImageCache::kUnpinned_CacheStatus;
+    return SkImageCache::kUnpinned_MemoryStatus;
+}
+
+void SkLruImageCache::purgeAllUnpinnedCaches() {
+    SkAutoMutexAcquire ac(&fMutex);
+    this->purgeTilAtOrBelow(0);
 }
 #endif
 
@@ -108,7 +116,7 @@
     return pixels->getData();
 }
 
-void* SkLruImageCache::pinCache(intptr_t ID) {
+void* SkLruImageCache::pinCache(intptr_t ID, SkImageCache::DataStatus* status) {
     SkASSERT(ID != SkImageCache::UNINITIALIZED_ID);
     SkAutoMutexAcquire ac(&fMutex);
     CachedPixels* pixels = this->findByID(ID);
@@ -119,6 +127,9 @@
         fLRU.remove(pixels);
         fLRU.addToHead(pixels);
     }
+    SkASSERT(status != NULL);
+    // This cache will never return pinned memory whose data has been overwritten.
+    *status = SkImageCache::kRetained_DataStatus;
     pixels->lock();
     return pixels->getData();
 }
@@ -133,6 +144,7 @@
 }
 
 void SkLruImageCache::throwAwayCache(intptr_t ID) {
+    SkASSERT(ID != SkImageCache::UNINITIALIZED_ID);
     SkAutoMutexAcquire ac(&fMutex);
     CachedPixels* pixels = this->findByID(ID);
     if (pixels != NULL) {
@@ -155,9 +167,6 @@
 
 CachedPixels* SkLruImageCache::findByID(intptr_t ID) const {
     // Mutex is already locked.
-    if (SkImageCache::UNINITIALIZED_ID == ID) {
-        return NULL;
-    }
     Iter iter;
     // Start from the head, most recently used.
     CachedPixels* pixels = iter.init(fLRU, Iter::kHead_IterStart);