aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/GrGpuResourceCacheAccess.h
diff options
context:
space:
mode:
authorGravatar bsalomon <bsalomon@google.com>2015-02-13 14:20:05 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2015-02-13 14:20:05 -0800
commit3582d3ee9fffdec715f5e4949a241ab08e6271ec (patch)
treeeab9709bbe8c4d00cd11fb987654cfb9e51acc65 /src/gpu/GrGpuResourceCacheAccess.h
parent4ccce7ea618fd9557a6d5cfa29c1fd6b015c7580 (diff)
Split out methods in GrGpuResource::CacheAccess that can be called outside of the cache.
Diffstat (limited to 'src/gpu/GrGpuResourceCacheAccess.h')
-rw-r--r--src/gpu/GrGpuResourceCacheAccess.h68
1 files changed, 13 insertions, 55 deletions
diff --git a/src/gpu/GrGpuResourceCacheAccess.h b/src/gpu/GrGpuResourceCacheAccess.h
index 6c99d08e46..922e3b36b5 100644
--- a/src/gpu/GrGpuResourceCacheAccess.h
+++ b/src/gpu/GrGpuResourceCacheAccess.h
@@ -10,74 +10,31 @@
#define GrGpuResourceCacheAccess_DEFINED
#include "GrGpuResource.h"
+#include "GrGpuResourcePriv.h"
+
+namespace skiatest {
+ class Reporter;
+}
/**
- * This class allows code internal to Skia privileged access to manage the cache keys of a
- * GrGpuResource object.
+ * This class allows GrResourceCache increased privileged access to GrGpuResource objects.
*/
class GrGpuResource::CacheAccess {
-public:
- /**
- * Sets a content key for the resource. If the resource was previously cached as scratch it will
- * be converted to a content resource. Currently this may only be called once per resource. It
- * fails if there is already a resource with the same content key. TODO: make this supplant the
- * resource that currently is using the content key, allow resources' content keys to change,
- * and allow removal of a content key to convert a resource back to scratch.
- */
- bool setContentKey(const GrContentKey& contentKey) {
- return fResource->setContentKey(contentKey);
- }
-
- void removeContentKey() { return fResource->removeContentKey(); }
-
+private:
/**
* 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 !fResource->getContentKey().isValid() && fResource->fScratchKey.isValid() &&
- this->isBudgeted();
+ fResource->resourcePriv().isBudgeted();
}
- /**
- * If this resource can be used as a scratch resource this returns a valid scratch key.
- * Otherwise it returns a key for which isNullScratch is true. The resource may currently be
- * used as a content resource rather than scratch. Check isScratch().
- */
- const GrScratchKey& getScratchKey() const { return fResource->fScratchKey; }
-
- /**
- * If the resource has a scratch key, the key will be removed. Since scratch keys are installed
- * at resource creation time, this means the resource will never again be used as scratch.
- */
- void removeScratchKey() const { fResource->removeScratchKey(); }
-
/**
* Is the resource object wrapping an externally allocated GPU resource?
*/
bool isWrapped() const { return GrGpuResource::kWrapped_LifeCycle == fResource->fLifeCycle; }
-
- /**
- * Does the resource count against the resource budget?
- */
- bool isBudgeted() const {
- bool ret = GrGpuResource::kCached_LifeCycle == fResource->fLifeCycle;
- SkASSERT(ret || !fResource->getContentKey().isValid());
- return ret;
- }
-
- /**
- * If the resource is uncached make it cached. Has no effect on resources that are wrapped or
- * already cached.
- */
- 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.
*/
@@ -98,9 +55,8 @@ public:
}
}
-private:
- CacheAccess(GrGpuResource* resource) : fResource(resource) { }
- CacheAccess(const CacheAccess& that) : fResource(that.fResource) { }
+ CacheAccess(GrGpuResource* resource) : fResource(resource) {}
+ CacheAccess(const CacheAccess& that) : fResource(that.fResource) {}
CacheAccess& operator=(const CacheAccess&); // unimpl
// No taking addresses of this type.
@@ -110,6 +66,8 @@ private:
GrGpuResource* fResource;
friend class GrGpuResource; // to construct/copy this type.
+ friend class GrResourceCache; // to use this type
+ friend void test_unbudgeted_to_scratch(skiatest::Reporter* reporter); // for unit testing
};
inline GrGpuResource::CacheAccess GrGpuResource::cacheAccess() { return CacheAccess(this); }