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

Unified Diff: src/gpu/GrResourceCache.cpp

Issue 938943002: Allow GrGpuResources' unique keys to be changed. (Closed) Base URL: https://skia.googlesource.com/skia.git@rename
Patch Set: Address comments Created 5 years, 10 months 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/SkGr.cpp » ('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 8658744d9ab68368b1ebb48c7f205b88f3459c3a..a2fde2fef22021d67e2a0ea671175cd5181472ab 100644
--- a/src/gpu/GrResourceCache.cpp
+++ b/src/gpu/GrResourceCache.cpp
@@ -237,26 +237,50 @@ void GrResourceCache::willRemoveScratchKey(const GrGpuResource* resource) {
fScratchMap.remove(resource->resourcePriv().getScratchKey(), resource);
}
-void GrResourceCache::willRemoveUniqueKey(const GrGpuResource* resource) {
+void GrResourceCache::removeUniqueKey(GrGpuResource* resource) {
// Someone has a ref to this resource in order to invalidate it. When the ref count reaches
// zero we will get a notifyPurgable() and figure out what to do with it.
- SkASSERT(resource->getUniqueKey().isValid());
- fUniqueHash.remove(resource->getUniqueKey());
+ if (resource->getUniqueKey().isValid()) {
+ SkASSERT(resource == fUniqueHash.find(resource->getUniqueKey()));
+ fUniqueHash.remove(resource->getUniqueKey());
+ }
+ resource->cacheAccess().removeUniqueKey();
+ this->validate();
}
-bool GrResourceCache::didSetUniqueKey(GrGpuResource* resource) {
+void GrResourceCache::changeUniqueKey(GrGpuResource* resource, const GrUniqueKey& newKey) {
SkASSERT(resource);
SkASSERT(this->isInCache(resource));
- SkASSERT(resource->getUniqueKey().isValid());
- GrGpuResource* res = fUniqueHash.find(resource->getUniqueKey());
- if (NULL != res) {
- return false;
+ // Remove the entry for this resource if it already has a unique key.
+ if (resource->getUniqueKey().isValid()) {
+ SkASSERT(resource == fUniqueHash.find(resource->getUniqueKey()));
+ fUniqueHash.remove(resource->getUniqueKey());
+ SkASSERT(NULL == fUniqueHash.find(resource->getUniqueKey()));
+ }
+
+ // If another resource has the new key, remove its key then install the key on this resource.
+ if (newKey.isValid()) {
+ if (GrGpuResource* old = fUniqueHash.find(newKey)) {
+ // If the old resource using the key is purgeable and is unreachable, then remove it.
+ if (!old->resourcePriv().getScratchKey().isValid() && old->isPurgeable()) {
+ // release may call validate() which will assert that resource is in fUniqueHash
+ // if it has a valid key. So in debug reset the key here before we assign it.
+ SkDEBUGCODE(resource->cacheAccess().removeUniqueKey();)
+ old->cacheAccess().release();
+ } else {
+ fUniqueHash.remove(newKey);
+ old->cacheAccess().removeUniqueKey();
+ }
+ }
+ SkASSERT(NULL == fUniqueHash.find(newKey));
+ resource->cacheAccess().setUniqueKey(newKey);
+ fUniqueHash.add(resource);
+ } else {
+ resource->cacheAccess().removeUniqueKey();
}
- fUniqueHash.add(resource);
this->validate();
- return true;
}
void GrResourceCache::refAndMakeResourceMRU(GrGpuResource* resource) {
« no previous file with comments | « src/gpu/GrResourceCache.h ('k') | src/gpu/SkGr.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698