aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-05-05 19:21:16 +0000
committerGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-05-05 19:21:16 +0000
commit95a2b0e86d361c06716874f8a56782e1551c308e (patch)
treef170bb884932e4d628d826671cc2570caf68b0c7
parent11c6b39cfa24f812ceb115589f51a60a56ef14fe (diff)
Allow custom resources in the GrContext's cache
Adds methods to GrContext for client code to store custom resources in the cache. BUG=skia: R=bsalomon@google.com Author: cdalton@nvidia.com Review URL: https://codereview.chromium.org/261593009 git-svn-id: http://skia.googlecode.com/svn/trunk@14577 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r--include/gpu/GrContext.h11
-rw-r--r--src/gpu/GrContext.cpp11
2 files changed, 22 insertions, 0 deletions
diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h
index 4d0a94e4cd..195ab72a7f 100644
--- a/include/gpu/GrContext.h
+++ b/include/gpu/GrContext.h
@@ -899,6 +899,17 @@ public:
GrPathRendererChain::DrawType drawType = GrPathRendererChain::kColor_DrawType,
GrPathRendererChain::StencilSupport* stencilSupport = NULL);
+ /**
+ * Stores a custom resource in the cache, based on the specified key.
+ */
+ void addResourceToCache(const GrResourceKey&, GrCacheable*);
+
+ /**
+ * Finds a resource in the cache, based on the specified key. This is intended for use in
+ * conjunction with addResourceToCache(). The return value will be NULL if not found. The
+ * caller must balance with a call to unref().
+ */
+ GrCacheable* findAndRefCachedResource(const GrResourceKey&);
#if GR_CACHE_STATS
void printCacheStats() const;
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index c518a1c8ac..d2664c3b86 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -1825,6 +1825,17 @@ GrPath* GrContext::createPath(const SkPath& inPath, const SkStrokeRec& stroke) {
return path;
}
+void GrContext::addResourceToCache(const GrResourceKey& resourceKey, GrCacheable* resource) {
+ fTextureCache->purgeAsNeeded(1, resource->gpuMemorySize());
+ fTextureCache->addResource(resourceKey, resource);
+}
+
+GrCacheable* GrContext::findAndRefCachedResource(const GrResourceKey& resourceKey) {
+ GrCacheable* resource = fTextureCache->find(resourceKey);
+ SkSafeRef(resource);
+ return resource;
+}
+
///////////////////////////////////////////////////////////////////////////////
#if GR_CACHE_STATS
void GrContext::printCacheStats() const {