Ganesh resource cache changes

https://codereview.appspot.com/6784051/



git-svn-id: http://skia.googlecode.com/svn/trunk@6211 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index 900af8a..f7f6b0c 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -236,7 +236,7 @@
     GrResourceKey resourceKey = GrStencilBuffer::ComputeKey(sb->width(),
                                                             sb->height(),
                                                             sb->numSamples());
-    fTextureCache->create(resourceKey, sb);
+    fTextureCache->addResource(resourceKey, sb);
 }
 
 GrStencilBuffer* GrContext::findStencilBuffer(int width, int height,
@@ -378,7 +378,7 @@
     }
 
     if (NULL != texture) {
-        fTextureCache->create(resourceKey, texture);
+        fTextureCache->addResource(resourceKey, texture);
     }
 
     return texture;
@@ -407,7 +407,8 @@
 
     do {
         GrResourceKey key = GrTexture::ComputeKey(fGpu, NULL, desc, cacheData, true);
-        resource = fTextureCache->find(key);
+        // Ensure we have exclusive access to the texture so future 'find' calls don't return it
+        resource = fTextureCache->find(key, GrResourceCache::kHide_OwnershipFlag);
         // if we miss, relax the fit of the flags...
         // then try doubling width... then height.
         if (NULL != resource || kExact_ScratchTexMatch == match) {
@@ -443,18 +444,12 @@
                                                       texture->desc(),
                                                       cacheData,
                                                       true);
-            fTextureCache->create(key, texture);
+            // Make the resource exclusive so future 'find' calls don't return it
+            fTextureCache->addResource(key, texture, GrResourceCache::kHide_OwnershipFlag);
             resource = texture;
         }
     }
 
-    // If the caller gives us the same desc twice we don't want to return the
-    // same texture the second time (unless it was previously released). So
-    // make it exclusive to hide it from future searches.
-    if (NULL != resource) {
-        fTextureCache->makeExclusive(resource->getCacheEntry());
-    }
-
     return static_cast<GrTexture*>(resource);
 }