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/bench/GrResourceCacheBench.cpp b/bench/GrResourceCacheBench.cpp
index e808cd7..6767ca1 100644
--- a/bench/GrResourceCacheBench.cpp
+++ b/bench/GrResourceCacheBench.cpp
@@ -9,7 +9,7 @@
 #if SK_SUPPORT_GPU
 
 #include "GrContext.h"
-#include "GrResource.h"
+#include "GrCacheable.h"
 #include "GrResourceCache.h"
 #include "GrStencilBuffer.h"
 #include "GrTexture.h"
@@ -21,21 +21,21 @@
     CACHE_SIZE_BYTES = 2 * 1024 * 1024,
 };
 
-class StencilResource : public GrResource {
+class StencilResource : public GrCacheable {
 public:
     SK_DECLARE_INST_COUNT(StencilResource);
-    StencilResource(GrGpu* gpu, int id)
-        : INHERITED(gpu, false),
-          fID(id) {
-    }
-    ~StencilResource() {
-        this->release();
+    StencilResource(int id)
+        : fID(id) {
     }
 
-    virtual size_t sizeInBytes() const SK_OVERRIDE {
+    virtual size_t gpuMemorySize() const SK_OVERRIDE {
         return 100 + ((fID % 1 == 0) ? -5 : 6);
     }
 
+    virtual bool isValidOnGpu() const SK_OVERRIDE {
+        return true;
+    }
+
     static GrResourceKey ComputeKey(int width, int height, int sampleCnt) {
         return GrStencilBuffer::ComputeKey(width, height, sampleCnt);
     }
@@ -43,24 +43,24 @@
     int fID;
 
 private:
-    typedef GrResource INHERITED;
+    typedef GrCacheable INHERITED;
 };
 
-class TextureResource : public GrResource {
+class TextureResource : public GrCacheable {
 public:
     SK_DECLARE_INST_COUNT(TextureResource);
-    TextureResource(GrGpu* gpu, int id)
-        : INHERITED(gpu, false),
-          fID(id) {
-    }
-    ~TextureResource() {
-        this->release();
+    TextureResource(int id)
+        : fID(id) {
     }
 
-    virtual size_t sizeInBytes() const SK_OVERRIDE {
+    virtual size_t gpuMemorySize() const SK_OVERRIDE {
         return 100 + ((fID % 1 == 0) ? -40 : 33);
     }
 
+    virtual bool isValidOnGpu() const SK_OVERRIDE {
+        return true;
+    }
+
     static GrResourceKey ComputeKey(const GrTextureDesc& desc) {
         return GrTexture::ComputeScratchKey(desc);
     }
@@ -68,7 +68,7 @@
     int fID;
 
 private:
-    typedef GrResource INHERITED;
+    typedef GrCacheable INHERITED;
 };
 
 static void get_stencil(int i, int* w, int* h, int* s) {
@@ -91,8 +91,8 @@
         int w, h, s;
         get_stencil(i, &w, &h, &s);
         GrResourceKey key = GrStencilBuffer::ComputeKey(w, h, s);
-        GrResource* resource = SkNEW_ARGS(StencilResource, (gpu, i));
-        cache->purgeAsNeeded(1, resource->sizeInBytes());
+        GrCacheable* resource = SkNEW_ARGS(StencilResource, (i));
+        cache->purgeAsNeeded(1, resource->gpuMemorySize());
         cache->addResource(key, resource);
         resource->unref();
     }
@@ -101,8 +101,8 @@
         GrTextureDesc desc;
         get_texture_desc(i, &desc);
         GrResourceKey key =  TextureResource::ComputeKey(desc);
-        GrResource* resource = SkNEW_ARGS(TextureResource, (gpu, i));
-        cache->purgeAsNeeded(1, resource->sizeInBytes());
+        GrCacheable* resource = SkNEW_ARGS(TextureResource, (i));
+        cache->purgeAsNeeded(1, resource->gpuMemorySize());
         cache->addResource(key, resource);
         resource->unref();
     }
@@ -114,7 +114,7 @@
         GrTextureDesc desc;
         get_texture_desc(k, &desc);
         GrResourceKey key = TextureResource::ComputeKey(desc);
-        GrResource* item = cache->find(key);
+        GrCacheable* item = cache->find(key);
         if (NULL == item) {
             SkFAIL("cache add does not work as expected");
             return;
@@ -128,7 +128,7 @@
         int w, h, s;
         get_stencil(k, &w, &h, &s);
         GrResourceKey key = StencilResource::ComputeKey(w, h, s);
-        GrResource* item = cache->find(key);
+        GrCacheable* item = cache->find(key);
         if (NULL == item) {
             SkFAIL("cache add does not work as expected");
             return;
@@ -145,7 +145,7 @@
         get_texture_desc(k, &desc);
         desc.fHeight |= 1;
         GrResourceKey key = TextureResource::ComputeKey(desc);
-        GrResource* item = cache->find(key);
+        GrCacheable* item = cache->find(key);
         if (NULL != item) {
             SkFAIL("cache add does not work as expected");
             return;
@@ -156,7 +156,7 @@
         get_stencil(k, &w, &h, &s);
         h |= 1;
         GrResourceKey key = StencilResource::ComputeKey(w, h, s);
-        GrResource* item = cache->find(key);
+        GrCacheable* item = cache->find(key);
         if (NULL != item) {
             SkFAIL("cache add does not work as expected");
             return;