Reimplement gpu message bus for invalidated bitmap gen IDs
Review URL: https://codereview.chromium.org/902873002
diff --git a/src/gpu/GrResourceCache2.cpp b/src/gpu/GrResourceCache2.cpp
index 84a8d48..c165659 100644
--- a/src/gpu/GrResourceCache2.cpp
+++ b/src/gpu/GrResourceCache2.cpp
@@ -14,7 +14,7 @@
#include "SkGr.h"
#include "SkMessageBus.h"
-DECLARE_SKMESSAGEBUS_MESSAGE(GrResourceInvalidatedMessage);
+DECLARE_SKMESSAGEBUS_MESSAGE(GrContentKeyInvalidatedMessage);
//////////////////////////////////////////////////////////////////////////////
@@ -221,6 +221,13 @@
fScratchMap.remove(resource->cacheAccess().getScratchKey(), resource);
}
+void GrResourceCache2::willRemoveContentKey(const 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->getContentKey().isValid());
+ fContentHash.remove(resource->getContentKey());
+}
+
bool GrResourceCache2::didSetContentKey(GrGpuResource* resource) {
SkASSERT(!fPurging);
SkASSERT(resource);
@@ -406,6 +413,17 @@
this->validate();
}
+void GrResourceCache2::processInvalidContentKeys(
+ const SkTArray<GrContentKeyInvalidatedMessage>& msgs) {
+ for (int i = 0; i < msgs.count(); ++i) {
+ GrGpuResource* resource = this->findAndRefContentResource(msgs[i].key());
+ if (resource) {
+ resource->cacheAccess().removeContentKey();
+ resource->unref(); // will call notifyPurgeable, if it is indeed now purgeable.
+ }
+ }
+}
+
#ifdef SK_DEBUG
void GrResourceCache2::validate() const {
// Reduce the frequency of validations for large resource counts.