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

Unified Diff: src/core/SkImageFilter.cpp

Issue 1514893003: Create a hash table from id<-->key in SkImageFilter::CacheImpl (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: clean up in ~CacheImpl Created 5 years 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 | « include/core/SkImageFilter.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkImageFilter.cpp
diff --git a/src/core/SkImageFilter.cpp b/src/core/SkImageFilter.cpp
index a3f89d08fad3fc4023c4ddc9805764a34972372e..eec6d3a7e87da85e08fa0a15b4abe030222368cf 100644
--- a/src/core/SkImageFilter.cpp
+++ b/src/core/SkImageFilter.cpp
@@ -18,6 +18,7 @@
#include "SkReadBuffer.h"
#include "SkRect.h"
#include "SkTDynamicHash.h"
+#include "SkTHash.h"
#include "SkTInternalLList.h"
#include "SkValidationUtils.h"
#include "SkWriteBuffer.h"
@@ -201,6 +202,7 @@ SkImageFilter::~SkImageFilter() {
SkSafeUnref(fInputs[i]);
}
delete[] fInputs;
+ Cache::Get()->purgeByImageFilterId(fUniqueID);
}
SkImageFilter::SkImageFilter(int inputCount, SkReadBuffer& buffer)
@@ -566,6 +568,7 @@ public:
++iter;
delete v;
}
+ fIdToKeys.foreach([](uint32_t, SkTArray<Key>** array) { delete *array; });
}
struct Value {
Value(const Key& key, const SkBitmap& bitmap, const SkIPoint& offset)
@@ -600,6 +603,13 @@ public:
removeInternal(v);
}
Value* v = new Value(key, result, offset);
+ if (SkTArray<Key>** array = fIdToKeys.find(key.fUniqueID)) {
+ (*array)->push_back(key);
+ } else {
+ SkTArray<Key>* keyArray = new SkTArray<Key>();
+ keyArray->push_back(key);
+ fIdToKeys.set(key.fUniqueID, keyArray);
+ }
fLookup.add(v);
fLRU.addToHead(v);
fCurrentBytes += result.getSize();
@@ -622,6 +632,19 @@ public:
}
}
+ void purgeByImageFilterId(uint32_t uniqueID) override {
+ SkAutoMutexAcquire mutex(fMutex);
+ if (SkTArray<Key>** array = fIdToKeys.find(uniqueID)) {
+ for (auto& key : **array) {
+ if (Value* v = fLookup.find(key)) {
+ this->removeInternal(v);
+ }
+ }
+ fIdToKeys.remove(uniqueID);
+ delete *array; // This can be deleted outside the lock
+ }
+ }
+
private:
void removeInternal(Value* v) {
fCurrentBytes -= v->fBitmap.getSize();
@@ -630,11 +653,12 @@ private:
delete v;
}
private:
- SkTDynamicHash<Value, Key> fLookup;
- mutable SkTInternalLList<Value> fLRU;
- size_t fMaxBytes;
- size_t fCurrentBytes;
- mutable SkMutex fMutex;
+ SkTDynamicHash<Value, Key> fLookup;
+ SkTHashMap<uint32_t, SkTArray<Key>*> fIdToKeys;
+ mutable SkTInternalLList<Value> fLRU;
+ size_t fMaxBytes;
+ size_t fCurrentBytes;
+ mutable SkMutex fMutex;
};
} // namespace
« no previous file with comments | « include/core/SkImageFilter.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698