Allow unbudgeted resources to be recycled by the cache as scratch.

Review URL: https://codereview.chromium.org/870743002
diff --git a/src/gpu/GrGpuResourceCacheAccess.h b/src/gpu/GrGpuResourceCacheAccess.h
index 33fe1ad..474438f 100644
--- a/src/gpu/GrGpuResourceCacheAccess.h
+++ b/src/gpu/GrGpuResourceCacheAccess.h
@@ -29,11 +29,12 @@
     }
 
     /**
-     * Is the resource currently cached as scratch? This means it has a valid scratch key and does
-     * not have a content key.
+     * Is the resource currently cached as scratch? This means it is cached, has a valid scratch
+     * key, and does not have a content key.
      */
     bool isScratch() const {
-        return !this->getContentKey().isValid() && fResource->fScratchKey.isValid();
+        return !this->getContentKey().isValid() && fResource->fScratchKey.isValid() &&
+                this->isBudgeted();
     }
 
     /** 
@@ -62,7 +63,11 @@
     /**
      * Does the resource count against the resource budget?
      */
-    bool isBudgeted() const { return GrGpuResource::kCached_LifeCycle == fResource->fLifeCycle; }
+    bool isBudgeted() const {
+        bool ret = GrGpuResource::kCached_LifeCycle == fResource->fLifeCycle;
+        SkASSERT(ret || !this->getContentKey().isValid());
+        return ret;
+    }
 
     /**
      * If the resource is uncached make it cached. Has no effect on resources that are wrapped or
@@ -71,6 +76,12 @@
     void makeBudgeted() { fResource->makeBudgeted(); }
 
     /**
+     * If the resource is cached make it uncached. Has no effect on resources that are wrapped or
+     * already uncached. Furthermore, resources with content keys cannot be made unbudgeted.
+     */
+    void makeUnbudgeted() { fResource->makeUnbudgeted(); }
+
+    /**
      * Called by the cache to delete the resource under normal circumstances.
      */
     void release() {