Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 3380be9

Browse files
rphilliSkia Commit-Bot
authored andcommitted
Fix creation of gpu resources in GrThreadSafeViewCache tests
This CL implements and exercises the preference for gpu-generated content. This CL also switches to drawing a rect (vs. an arrow) since drawing a concave path on the gpu can be fraught. Bug: 1108408 Change-Id: Ieec1619b5357ffb31aa74b471ea09c061bd8f74e Reviewed-on: https://skia-review.googlesource.com/c/skia/+/319416 Reviewed-by: Adlai Holler <adlai@google.com> Commit-Queue: Robert Phillips <robertphillips@google.com>
1 parent ab4ab20 commit 3380be9

File tree

3 files changed

+228
-48
lines changed

3 files changed

+228
-48
lines changed

src/gpu/GrThreadSafeUniquelyKeyedProxyViewCache.cpp

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ void GrThreadSafeUniquelyKeyedProxyViewCache::dropAllRefs() {
4242
// TODO: should we empty out the fFreeEntryList and reset fEntryAllocator?
4343
}
4444

45-
// TODO: add an atomic flag so we know when it is worthwhile to iterate
45+
// TODO: If iterating becomes too expensive switch to using something like GrIORef for the
46+
// GrSurfaceProxy
4647
void GrThreadSafeUniquelyKeyedProxyViewCache::dropUniqueRefs(GrResourceCache* resourceCache) {
4748
SkAutoSpinlock lock{fSpinLock};
4849

@@ -159,3 +160,31 @@ GrSurfaceProxyView GrThreadSafeUniquelyKeyedProxyViewCache::add(const GrUniqueKe
159160

160161
return this->internalAdd(key, view);
161162
}
163+
164+
GrSurfaceProxyView GrThreadSafeUniquelyKeyedProxyViewCache::findOrAdd(const GrUniqueKey& key,
165+
const GrSurfaceProxyView& v) {
166+
SkAutoSpinlock lock{fSpinLock};
167+
168+
Entry* tmp = fUniquelyKeyedProxyViewMap.find(key);
169+
if (tmp) {
170+
SkASSERT(fUniquelyKeyedProxyViewList.isInList(tmp));
171+
// make the sought out entry the MRU
172+
tmp->fLastAccess = GrStdSteadyClock::now();
173+
fUniquelyKeyedProxyViewList.remove(tmp);
174+
fUniquelyKeyedProxyViewList.addToHead(tmp);
175+
return tmp->fView;
176+
}
177+
178+
return this->internalAdd(key, v);
179+
}
180+
181+
void GrThreadSafeUniquelyKeyedProxyViewCache::remove(const GrUniqueKey& key) {
182+
SkAutoSpinlock lock{fSpinLock};
183+
184+
Entry* tmp = fUniquelyKeyedProxyViewMap.find(key);
185+
if (tmp) {
186+
fUniquelyKeyedProxyViewMap.remove(key);
187+
fUniquelyKeyedProxyViewList.remove(tmp);
188+
this->recycleEntry(tmp);
189+
}
190+
}

src/gpu/GrThreadSafeUniquelyKeyedProxyViewCache.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ class GrThreadSafeUniquelyKeyedProxyViewCache {
8484

8585
GrSurfaceProxyView add(const GrUniqueKey&, const GrSurfaceProxyView&) SK_EXCLUDES(fSpinLock);
8686

87+
GrSurfaceProxyView findOrAdd(const GrUniqueKey&,
88+
const GrSurfaceProxyView&) SK_EXCLUDES(fSpinLock);
89+
90+
void remove(const GrUniqueKey&) SK_EXCLUDES(fSpinLock);
91+
8792
private:
8893
struct Entry {
8994
Entry(const GrUniqueKey& key, const GrSurfaceProxyView& view) : fKey(key), fView(view) {}

0 commit comments

Comments
 (0)