Clean out stale shadow vertices from the SkResourceCache
Bug: b/130757982 Change-Id: Iddfd41bcd494e1bf2d39baf6f2dc5e95a1819798 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/210629 Commit-Queue: Jim Van Verth <jvanverth@google.com> Reviewed-by: Robert Phillips <robertphillips@google.com> Reviewed-by: Brian Salomon <bsalomon@google.com>
This commit is contained in:
parent
91c35c3d9b
commit
ee90eb42fe
@ -18,6 +18,7 @@
|
||||
#include "src/core/SkDevice.h"
|
||||
#include "src/core/SkDrawShadowInfo.h"
|
||||
#include "src/core/SkEffectPriv.h"
|
||||
#include "src/core/SkPathPriv.h"
|
||||
#include "src/core/SkRasterPipeline.h"
|
||||
#include "src/core/SkResourceCache.h"
|
||||
#include "src/core/SkTLazy.h"
|
||||
@ -380,6 +381,31 @@ private:
|
||||
// This creates a domain of keys in SkResourceCache used by this file.
|
||||
static void* kNamespace;
|
||||
|
||||
// When the SkPathRef genID changes, invalidate a corresponding GrResource described by key.
|
||||
class ShadowInvalidator : public SkPathRef::GenIDChangeListener {
|
||||
public:
|
||||
ShadowInvalidator(const SkResourceCache::Key& key) {
|
||||
fKey.reset(new uint8_t[key.size()]);
|
||||
memcpy(fKey.get(), &key, key.size());
|
||||
}
|
||||
|
||||
private:
|
||||
const SkResourceCache::Key& getKey() const {
|
||||
return *reinterpret_cast<SkResourceCache::Key*>(fKey.get());
|
||||
}
|
||||
|
||||
// always purge
|
||||
static bool FindVisitor(const SkResourceCache::Rec&, void*) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void onChange() override {
|
||||
SkResourceCache::Find(this->getKey(), ShadowInvalidator::FindVisitor, nullptr);
|
||||
}
|
||||
|
||||
std::unique_ptr<uint8_t[]> fKey;
|
||||
};
|
||||
|
||||
/**
|
||||
* Draws a shadow to 'canvas'. The vertices used to draw the shadow are created by 'factory' unless
|
||||
* they are first found in SkResourceCache.
|
||||
@ -421,6 +447,7 @@ bool draw_shadow(const FACTORY& factory,
|
||||
return false;
|
||||
}
|
||||
auto rec = new CachedTessellationsRec(*key, std::move(tessellations));
|
||||
SkPathPriv::AddGenIDChangeListener(path.path(), sk_make_sp<ShadowInvalidator>(*key));
|
||||
SkResourceCache::Add(rec);
|
||||
} else {
|
||||
vertices = factory.makeVertices(path.path(), path.viewMatrix(),
|
||||
|
Loading…
Reference in New Issue
Block a user