Index: src/gpu/GrResourceCache2.cpp |
diff --git a/src/gpu/GrResourceCache2.cpp b/src/gpu/GrResourceCache2.cpp |
index 6bc23a3096a5101027f4dfa2aae1c1a4ea6c8a1c..65e522aafbae13b310600138b4fee6f229bdce98 100644 |
--- a/src/gpu/GrResourceCache2.cpp |
+++ b/src/gpu/GrResourceCache2.cpp |
@@ -9,7 +9,6 @@ |
#include "GrResourceCache2.h" |
#include "GrGpuResource.h" |
-#include "SkRefCnt.h" |
GrResourceCache2::~GrResourceCache2() { |
this->releaseAll(); |
@@ -22,6 +21,8 @@ void GrResourceCache2::insertResource(GrGpuResource* resource) { |
fResources.addToHead(resource); |
++fCount; |
if (!resource->getScratchKey().isNullScratch()) { |
+ // TODO(bsalomon): Make this assertion possible. |
+ // SkASSERT(!resource->isWrapped()); |
fScratchMap.insert(resource->getScratchKey(), resource); |
} |
} |
@@ -32,6 +33,9 @@ void GrResourceCache2::removeResource(GrGpuResource* resource) { |
if (!resource->getScratchKey().isNullScratch()) { |
fScratchMap.remove(resource->getScratchKey(), resource); |
} |
+ if (const GrResourceKey* contentKey = resource->getContentKey()) { |
+ fContentHash.remove(*contentKey); |
+ } |
--fCount; |
} |
@@ -43,6 +47,7 @@ void GrResourceCache2::abandonAll() { |
SkASSERT(head != fResources.head()); |
} |
SkASSERT(!fScratchMap.count()); |
+ SkASSERT(!fContentHash.count()); |
SkASSERT(!fCount); |
} |
@@ -89,3 +94,25 @@ GrGpuResource* GrResourceCache2::findAndRefScratchResource(const GrResourceKey& |
} |
return SkSafeRef(fScratchMap.find(scratchKey, AvailableForScratchUse(false))); |
} |
+ |
+void GrResourceCache2::willRemoveContentKey(const GrGpuResource* resource) { |
+ SkASSERT(resource); |
+ SkASSERT(resource->getContentKey()); |
+ SkDEBUGCODE(GrGpuResource* res = fContentHash.find(*resource->getContentKey())); |
+ SkASSERT(res == resource); |
+ |
+ fContentHash.remove(*resource->getContentKey()); |
+} |
+ |
+bool GrResourceCache2::didAddContentKey(GrGpuResource* resource) { |
+ SkASSERT(resource); |
+ SkASSERT(resource->getContentKey()); |
+ |
+ GrGpuResource* res = fContentHash.find(*resource->getContentKey()); |
+ if (NULL != res) { |
+ return false; |
+ } |
+ |
+ fContentHash.add(resource); |
+ return true; |
+} |