Skip to content

Commit 01771c1

Browse files
rphilliSkia Commit-Bot
authored andcommitted
Increase encapsulation of GrThreadSafeCache::Entry
Prepare this class to hold either a proxyView or a vertex blob Bug: 1108408 Change-Id: Ib6abb4da64ccc70b9e2af2546e1b071396dd42cb Reviewed-on: https://skia-review.googlesource.com/c/skia/+/328836 Reviewed-by: Adlai Holler <adlai@google.com> Commit-Queue: Robert Phillips <robertphillips@google.com>
1 parent ffad5d3 commit 01771c1

File tree

2 files changed

+69
-16
lines changed

2 files changed

+69
-16
lines changed

src/gpu/GrThreadSafeCache.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ void GrThreadSafeCache::dropUniqueRefs(GrResourceCache* resourceCache) {
6060
return;
6161
}
6262

63-
if (cur->fView.proxy()->unique()) {
64-
fUniquelyKeyedEntryMap.remove(cur->fKey);
63+
if (cur->uniquelyHeld()) {
64+
fUniquelyKeyedEntryMap.remove(cur->key());
6565
fUniquelyKeyedEntryList.remove(cur);
6666
this->recycleEntry(cur);
6767
}
@@ -84,8 +84,8 @@ void GrThreadSafeCache::dropUniqueRefsOlderThan(GrStdSteadyClock::time_point pur
8484
return;
8585
}
8686

87-
if (cur->fView.proxy()->unique()) {
88-
fUniquelyKeyedEntryMap.remove(cur->fKey);
87+
if (cur->uniquelyHeld()) {
88+
fUniquelyKeyedEntryMap.remove(cur->key());
8989
fUniquelyKeyedEntryList.remove(cur);
9090
this->recycleEntry(cur);
9191
}
@@ -104,7 +104,7 @@ std::tuple<GrSurfaceProxyView, sk_sp<SkData>> GrThreadSafeCache::internalFind(
104104
tmp->fLastAccess = GrStdSteadyClock::now();
105105
fUniquelyKeyedEntryList.remove(tmp);
106106
fUniquelyKeyedEntryList.addToHead(tmp);
107-
return { tmp->fView, tmp->fKey.refCustomData() };
107+
return { tmp->view(), tmp->refCustomData() };
108108
}
109109

110110
return {};
@@ -134,8 +134,7 @@ GrThreadSafeCache::Entry* GrThreadSafeCache::getEntry(const GrUniqueKey& key,
134134
fFreeEntryList = entry->fNext;
135135
entry->fNext = nullptr;
136136

137-
entry->fKey = key;
138-
entry->fView = view;
137+
entry->set(key, view);
139138
} else {
140139
entry = fEntryAllocator.make<Entry>(key, view);
141140
}
@@ -150,8 +149,7 @@ GrThreadSafeCache::Entry* GrThreadSafeCache::getEntry(const GrUniqueKey& key,
150149
void GrThreadSafeCache::recycleEntry(Entry* dead) {
151150
SkASSERT(!dead->fPrev && !dead->fNext && !dead->fList);
152151

153-
dead->fKey.reset();
154-
dead->fView.reset();
152+
dead->makeEmpty();
155153

156154
dead->fNext = fFreeEntryList;
157155
fFreeEntryList = dead;
@@ -167,7 +165,7 @@ std::tuple<GrSurfaceProxyView, sk_sp<SkData>> GrThreadSafeCache::internalAdd(
167165
SkASSERT(fUniquelyKeyedEntryMap.find(key));
168166
}
169167

170-
return { tmp->fView, tmp->fKey.refCustomData() };
168+
return { tmp->view(), tmp->refCustomData() };
171169
}
172170

173171
GrSurfaceProxyView GrThreadSafeCache::add(const GrUniqueKey& key, const GrSurfaceProxyView& view) {

src/gpu/GrThreadSafeCache.h

Lines changed: 61 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,18 +110,73 @@ class GrThreadSafeCache {
110110
SkBackingFit);
111111
private:
112112
struct Entry {
113-
Entry(const GrUniqueKey& key, const GrSurfaceProxyView& view) : fKey(key), fView(view) {}
114-
115-
// Note: the unique key is stored here bc it is never attached to a proxy or a GrTexture
116-
GrUniqueKey fKey;
117-
GrSurfaceProxyView fView;
113+
Entry(const GrUniqueKey& key, const GrSurfaceProxyView& view)
114+
: fKey(key)
115+
, fView(view)
116+
, fTag(Entry::kView) {
117+
}
118+
119+
bool uniquelyHeld() const {
120+
SkASSERT(fTag != kEmpty);
121+
122+
if (fTag == kView && fView.proxy()->unique()) {
123+
return true;
124+
}
125+
126+
return false;
127+
}
128+
129+
const GrUniqueKey& key() const {
130+
SkASSERT(fTag != kEmpty);
131+
return fKey;
132+
}
133+
134+
sk_sp<SkData> refCustomData() const {
135+
SkASSERT(fTag != kEmpty);
136+
return fKey.refCustomData();
137+
}
138+
139+
GrSurfaceProxyView view() {
140+
SkASSERT(fTag == kView);
141+
return fView;
142+
}
143+
144+
void set(const GrUniqueKey& key, const GrSurfaceProxyView& view) {
145+
SkASSERT(fTag == kEmpty);
146+
fKey = key;
147+
fView = view;
148+
fTag = kView;
149+
}
150+
151+
void makeEmpty() {
152+
SkASSERT(fTag != kEmpty);
153+
154+
fKey.reset();
155+
fView.reset();
156+
fTag = kEmpty;
157+
}
158+
159+
// The thread-safe cache gets to manipulate the llist and last-access members
118160
GrStdSteadyClock::time_point fLastAccess;
119161

120162
SK_DECLARE_INTERNAL_LLIST_INTERFACE(Entry);
121163

122164
// for SkTDynamicHash
123-
static const GrUniqueKey& GetKey(const Entry& e) { return e.fKey; }
165+
static const GrUniqueKey& GetKey(const Entry& e) {
166+
SkASSERT(e.fTag != kEmpty);
167+
return e.fKey;
168+
}
124169
static uint32_t Hash(const GrUniqueKey& key) { return key.hash(); }
170+
171+
private:
172+
// Note: the unique key is stored here bc it is never attached to a proxy or a GrTexture
173+
GrUniqueKey fKey;
174+
GrSurfaceProxyView fView;
175+
176+
enum {
177+
kEmpty,
178+
kView,
179+
} fTag { kEmpty };
125180
};
126181

127182
Entry* getEntry(const GrUniqueKey&, const GrSurfaceProxyView&) SK_REQUIRES(fSpinLock);

0 commit comments

Comments
 (0)