| 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
|
|
|