Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(316)

Unified Diff: src/gpu/GrResourceCache.cpp

Issue 707493002: Use GrResourceCache2 to service content key lookups (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: move #ifdef SK_SUPPORT_GPU Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/gpu/GrResourceCache.h ('k') | src/gpu/GrResourceCache2.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/GrResourceCache.cpp
diff --git a/src/gpu/GrResourceCache.cpp b/src/gpu/GrResourceCache.cpp
index 9754d4467adc02612b43179aed33635f974117ca..8eed4d4b7d5f36f0855af7f5d64a4f318d0ffcbc 100644
--- a/src/gpu/GrResourceCache.cpp
+++ b/src/gpu/GrResourceCache.cpp
@@ -49,7 +49,8 @@ GrResourceCacheEntry::GrResourceCacheEntry(GrResourceCache* resourceCache,
}
GrResourceCacheEntry::~GrResourceCacheEntry() {
- fResource->setCacheEntry(NULL);
+ // We're relying on having the cache entry to remove this from GrResourceCache2's content hash.
+ // fResource->setCacheEntry(NULL);
fResource->unref();
}
@@ -185,26 +186,11 @@ void GrResourceCache::notifyPurgable(const GrGpuResource* resource) {
}
}
-GrGpuResource* GrResourceCache::find(const GrResourceKey& key) {
- // GrResourceCache2 is responsible for scratch resources.
- SkASSERT(!key.isScratch());
-
- GrAutoResourceCacheValidate atcv(this);
-
- GrResourceCacheEntry* entry = fCache.find(key);
- if (NULL == entry) {
- return NULL;
+bool GrResourceCache::addResource(const GrResourceKey& key, GrGpuResource* resource) {
+ if (NULL != resource->getCacheEntry()) {
+ return false;
}
- // Make this resource MRU
- this->internalDetach(entry);
- this->attachToHead(entry);
-
- return entry->fResource;
-}
-
-void GrResourceCache::addResource(const GrResourceKey& key, GrGpuResource* resource) {
- SkASSERT(NULL == resource->getCacheEntry());
// we don't expect to create new resources during a purge. In theory
// this could cause purgeAsNeeded() into an infinite loop (e.g.
// each resource destroyed creates and locks 2 resources and
@@ -213,12 +199,16 @@ void GrResourceCache::addResource(const GrResourceKey& key, GrGpuResource* resou
GrAutoResourceCacheValidate atcv(this);
GrResourceCacheEntry* entry = SkNEW_ARGS(GrResourceCacheEntry, (this, key, resource));
- resource->setCacheEntry(entry);
+ if (!resource->setCacheEntry(entry)) {
+ SkDELETE(entry);
+ this->purgeAsNeeded();
+ return false;
+ }
this->attachToHead(entry);
fCache.insert(key, entry);
-
this->purgeAsNeeded();
+ return true;
}
void GrResourceCache::didIncreaseResourceSize(const GrResourceCacheEntry* entry, size_t amountInc) {
« no previous file with comments | « src/gpu/GrResourceCache.h ('k') | src/gpu/GrResourceCache2.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698