Add customData capability to the thread-safe proxy cache ...
and begin using it for cached SW-generated blur masks.
This is needed to begin mixing and matching HW & SW-generated blur
masks since they have different draw-rects.
It will also be useful if/when we add support for triangulated paths
to the thread-safe cache.
Bug: 1108408
Change-Id: I085ad1127dc2deb98b35d704b06e50b27c72fd1c
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/322657
Reviewed-by: Adlai Holler <adlai@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
diff --git a/src/gpu/GrThreadSafeUniquelyKeyedProxyViewCache.cpp b/src/gpu/GrThreadSafeUniquelyKeyedProxyViewCache.cpp
index c819339..d467d2b 100644
--- a/src/gpu/GrThreadSafeUniquelyKeyedProxyViewCache.cpp
+++ b/src/gpu/GrThreadSafeUniquelyKeyedProxyViewCache.cpp
@@ -92,9 +92,8 @@
}
}
-GrSurfaceProxyView GrThreadSafeUniquelyKeyedProxyViewCache::find(const GrUniqueKey& key) {
- SkAutoSpinlock lock{fSpinLock};
-
+std::tuple<GrSurfaceProxyView, sk_sp<SkData>> GrThreadSafeUniquelyKeyedProxyViewCache::internalFind(
+ const GrUniqueKey& key) {
Entry* tmp = fUniquelyKeyedProxyViewMap.find(key);
if (tmp) {
SkASSERT(fUniquelyKeyedProxyViewList.isInList(tmp));
@@ -102,12 +101,27 @@
tmp->fLastAccess = GrStdSteadyClock::now();
fUniquelyKeyedProxyViewList.remove(tmp);
fUniquelyKeyedProxyViewList.addToHead(tmp);
- return tmp->fView;
+ return { tmp->fView, tmp->fKey.refCustomData() };
}
return {};
}
+GrSurfaceProxyView GrThreadSafeUniquelyKeyedProxyViewCache::find(const GrUniqueKey& key) {
+ SkAutoSpinlock lock{fSpinLock};
+
+ GrSurfaceProxyView view;
+ std::tie(view, std::ignore) = this->internalFind(key);
+ return view;
+}
+
+std::tuple<GrSurfaceProxyView, sk_sp<SkData>> GrThreadSafeUniquelyKeyedProxyViewCache::findWithData(
+ const GrUniqueKey& key) {
+ SkAutoSpinlock lock{fSpinLock};
+
+ return this->internalFind(key);
+}
+
GrThreadSafeUniquelyKeyedProxyViewCache::Entry*
GrThreadSafeUniquelyKeyedProxyViewCache::getEntry(const GrUniqueKey& key,
const GrSurfaceProxyView& view) {
@@ -141,7 +155,7 @@
fFreeEntryList = dead;
}
-GrSurfaceProxyView GrThreadSafeUniquelyKeyedProxyViewCache::internalAdd(
+std::tuple<GrSurfaceProxyView, sk_sp<SkData>> GrThreadSafeUniquelyKeyedProxyViewCache::internalAdd(
const GrUniqueKey& key,
const GrSurfaceProxyView& view) {
Entry* tmp = fUniquelyKeyedProxyViewMap.find(key);
@@ -151,13 +165,23 @@
SkASSERT(fUniquelyKeyedProxyViewMap.find(key));
}
- return tmp->fView;
+ return { tmp->fView, tmp->fKey.refCustomData() };
}
GrSurfaceProxyView GrThreadSafeUniquelyKeyedProxyViewCache::add(const GrUniqueKey& key,
const GrSurfaceProxyView& view) {
SkAutoSpinlock lock{fSpinLock};
+ GrSurfaceProxyView newView;
+ std::tie(newView, std::ignore) = this->internalAdd(key, view);
+ return newView;
+}
+
+std::tuple<GrSurfaceProxyView, sk_sp<SkData>> GrThreadSafeUniquelyKeyedProxyViewCache::addWithData(
+ const GrUniqueKey& key,
+ const GrSurfaceProxyView& view) {
+ SkAutoSpinlock lock{fSpinLock};
+
return this->internalAdd(key, view);
}
@@ -165,14 +189,24 @@
const GrSurfaceProxyView& v) {
SkAutoSpinlock lock{fSpinLock};
- Entry* tmp = fUniquelyKeyedProxyViewMap.find(key);
- if (tmp) {
- SkASSERT(fUniquelyKeyedProxyViewList.isInList(tmp));
- // make the sought out entry the MRU
- tmp->fLastAccess = GrStdSteadyClock::now();
- fUniquelyKeyedProxyViewList.remove(tmp);
- fUniquelyKeyedProxyViewList.addToHead(tmp);
- return tmp->fView;
+ GrSurfaceProxyView view;
+ std::tie(view, std::ignore) = this->internalFind(key);
+ if (view) {
+ return view;
+ }
+
+ std::tie(view, std::ignore) = this->internalAdd(key, v);
+ return view;
+}
+
+std::tuple<GrSurfaceProxyView, sk_sp<SkData>> GrThreadSafeUniquelyKeyedProxyViewCache::findOrAddWithData(
+ const GrUniqueKey& key,
+ const GrSurfaceProxyView& v) {
+ SkAutoSpinlock lock{fSpinLock};
+
+ auto [view, data] = this->internalFind(key);
+ if (view) {
+ return { std::move(view), std::move(data) };
}
return this->internalAdd(key, v);