Split cache-specific fields out of GrTextureDesc

http://codereview.appspot.com/6448143/



git-svn-id: http://skia.googlecode.com/svn/trunk@5065 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp
index f6ee7ef..8240eb1 100644
--- a/src/gpu/SkGr.cpp
+++ b/src/gpu/SkGr.cpp
@@ -75,7 +75,8 @@
     desc.fWidth = bitmap->width();
     desc.fHeight = bitmap->height();
     desc.fConfig = SkBitmapConfig2GrPixelConfig(bitmap->config());
-    desc.fClientCacheID = key;
+
+    GrCacheData cacheData(key);
 
     if (SkBitmap::kIndex8_Config == bitmap->config()) {
         // build_compressed_data doesn't do npot->pot expansion
@@ -91,8 +92,9 @@
             // our compressed data will be trimmed, so pass width() for its
             // "rowBytes", since they are the same now.
             
-            if (kUncached_CacheID != key) {
-                return ctx->createAndLockTexture(params, desc, storage.get(),
+            if (GrCacheData::kScratch_CacheID != key) {
+                return ctx->createAndLockTexture(params, desc, cacheData, 
+                                                 storage.get(),
                                                  bitmap->width());
             } else {
                 entry = ctx->lockScratchTexture(desc,
@@ -111,11 +113,18 @@
     }
 
     desc.fConfig = SkBitmapConfig2GrPixelConfig(bitmap->config());
-    if (kUncached_CacheID != key) {
-        return ctx->createAndLockTexture(params, desc,
+    if (GrCacheData::kScratch_CacheID != key) {
+        // This texture is likely to be used again so leave it in the cache
+        // but locked.
+        return ctx->createAndLockTexture(params, desc, cacheData,
                                          bitmap->getPixels(),
                                          bitmap->rowBytes());
     } else {
+        // This texture is unlikely to be used again (in its present form) so 
+        // just use a scratch texture. This will remove the texture from the 
+        // cache so no one else can find it. Additionally, once unlocked, the 
+        // scratch texture will go to the end of the list for purging so will 
+        // likely be available for this volatile bitmap the next time around.
         entry = ctx->lockScratchTexture(desc,
                                         GrContext::kExact_ScratchTexMatch);
         entry.texture()->writePixels(0, 0,
@@ -135,6 +144,7 @@
     GrContext::TextureCacheEntry entry;
 
     if (!bitmap.isVolatile()) {
+        // If the bitmap isn't changing try to find a cached copy first
         uint64_t key = bitmap.getGenerationID();
         key |= ((uint64_t) bitmap.pixelRefOffset()) << 32;
 
@@ -142,14 +152,15 @@
         desc.fWidth = bitmap.width();
         desc.fHeight = bitmap.height();
         desc.fConfig = SkBitmapConfig2GrPixelConfig(bitmap.config());
-        desc.fClientCacheID = key;
 
-        entry = ctx->findAndLockTexture(desc, params);
+        GrCacheData cacheData(key);
+
+        entry = ctx->findAndLockTexture(desc, cacheData, params);
         if (NULL == entry.texture()) {
             entry = sk_gr_create_bitmap_texture(ctx, key, params, bitmap);
         }
     } else {
-        entry = sk_gr_create_bitmap_texture(ctx, kUncached_CacheID, params, bitmap);
+        entry = sk_gr_create_bitmap_texture(ctx, GrCacheData::kScratch_CacheID, params, bitmap);
     }
     if (NULL == entry.texture()) {
         GrPrintf("---- failed to create texture for cache [%d %d]\n",