Split GrResource into GrCacheable/GrGpuObject

Before this change, an object needed to inherit from GrResource (and
thus be a GPU object) in order to live in the GrResourceCache. That
was a problem for caching items that weren't GPU objects themselves,
but owned GPU objects.

This change splits GrResource into two classes:

  1. GrCacheable: The base class for objects that can live in the
     GrResourceCache.

  2. GrGpuObject, which inherits from GrCacheable: The base class for
     objects that get tracked by GrGpu.

This change is purely a refactor; there is no change in functionality.

Change-Id: I3e8daeb1f123041f414aa306c1366e959ae9e39e

BUG=skia:
R=bsalomon@google.com

Author: cdalton@nvidia.com

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

git-svn-id: http://skia.googlecode.com/svn/trunk@14553 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/tests/ResourceCacheTest.cpp b/tests/ResourceCacheTest.cpp
index 6b324a7..7262b43 100644
--- a/tests/ResourceCacheTest.cpp
+++ b/tests/ResourceCacheTest.cpp
@@ -56,12 +56,11 @@
     context->setTextureCacheLimits(oldMaxNum, oldMaxBytes);
 }
 
-class TestResource : public GrResource {
+class TestResource : public GrCacheable {
 public:
     SK_DECLARE_INST_COUNT(TestResource);
-    explicit TestResource(GrGpu* gpu)
-        : INHERITED(gpu, false)
-        , fCache(NULL)
+    TestResource()
+        : fCache(NULL)
         , fToDelete(NULL) {
         ++fAlive;
     }
@@ -73,10 +72,11 @@
             fToDelete->setDeleteWhenDestroyed(NULL, NULL);
             fCache->deleteResource(fToDelete->getCacheEntry());
         }
-        this->release();
     }
 
-    size_t sizeInBytes() const SK_OVERRIDE { return 100; }
+    size_t gpuMemorySize() const SK_OVERRIDE { return 100; }
+
+    bool isValidOnGpu() const SK_OVERRIDE { return true; }
 
     static int alive() { return fAlive; }
 
@@ -90,7 +90,7 @@
     TestResource* fToDelete;
     static int fAlive;
 
-    typedef GrResource INHERITED;
+    typedef GrCacheable INHERITED;
 };
 int TestResource::fAlive = 0;
 
@@ -105,8 +105,8 @@
     GrResourceCache cache(5, 30000);
 
     // Add two resources with the same key that delete each other from the cache when destroyed.
-    TestResource* a = new TestResource(context->getGpu());
-    TestResource* b = new TestResource(context->getGpu());
+    TestResource* a = new TestResource();
+    TestResource* b = new TestResource();
     cache.addResource(key, a);
     cache.addResource(key, b);
     // Circle back.
@@ -116,7 +116,7 @@
     b->unref();
 
     // Add a third independent resource also with the same key.
-    GrResource* r = new TestResource(context->getGpu());
+    GrCacheable* r = new TestResource();
     cache.addResource(key, r);
     r->unref();
 
@@ -141,8 +141,8 @@
     {
         {
             GrResourceCache cache(3, 30000);
-            TestResource* a = new TestResource(context->getGpu());
-            TestResource* b = new TestResource(context->getGpu());
+            TestResource* a = new TestResource();
+            TestResource* b = new TestResource();
             cache.addResource(key, a);
             cache.addResource(key, b);
 
@@ -157,8 +157,8 @@
     }
     {
         GrResourceCache cache(3, 30000);
-        TestResource* a = new TestResource(context->getGpu());
-        TestResource* b = new TestResource(context->getGpu());
+        TestResource* a = new TestResource();
+        TestResource* b = new TestResource();
         cache.addResource(key, a);
         cache.addResource(key, b);