Add callback to thread-safe cache to resolve vertexData collisions
The triangulating path renderer can generate multiple triangulations of
the same path at different levels of precision. As previously
implemented the more precise triangulations would steal the unique
key from prior triangulations. This new callback will allow us to
replicate this behavior in the thread-safe cache.
Bug: 1108408
Change-Id: I8b445ca1e503b2fd78727a23d9376a2cf77f291c
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/330562
Reviewed-by: Adlai Holler <adlai@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
diff --git a/src/gpu/GrThreadSafeCache.cpp b/src/gpu/GrThreadSafeCache.cpp
index c33a9fc..c3b01e1 100644
--- a/src/gpu/GrThreadSafeCache.cpp
+++ b/src/gpu/GrThreadSafeCache.cpp
@@ -280,12 +280,17 @@
std::tuple<sk_sp<GrThreadSafeCache::VertexData>, sk_sp<SkData>> GrThreadSafeCache::internalAddVerts(
const GrUniqueKey& key,
- sk_sp<VertexData> vertData) {
+ sk_sp<VertexData> vertData,
+ IsNewerBetter isNewerBetter) {
Entry* tmp = fUniquelyKeyedEntryMap.find(key);
if (!tmp) {
tmp = this->getEntry(key, std::move(vertData));
SkASSERT(fUniquelyKeyedEntryMap.find(key));
+ } else if (isNewerBetter(tmp->getCustomData(), key.getCustomData())) {
+ // This orphans any existing uses of the prior vertex data but ensures the best
+ // version is in the cache.
+ tmp->set(key, std::move(vertData));
}
return { tmp->vertexData(), tmp->refCustomData() };
@@ -293,10 +298,11 @@
std::tuple<sk_sp<GrThreadSafeCache::VertexData>, sk_sp<SkData>> GrThreadSafeCache::addVertsWithData(
const GrUniqueKey& key,
- sk_sp<VertexData> vertData) {
+ sk_sp<VertexData> vertData,
+ IsNewerBetter isNewerBetter) {
SkAutoSpinlock lock{fSpinLock};
- return this->internalAddVerts(key, std::move(vertData));
+ return this->internalAddVerts(key, std::move(vertData), isNewerBetter);
}
void GrThreadSafeCache::remove(const GrUniqueKey& key) {