More cleanup on GrStrikeCache
I missed the comments on cl/260038; do them in this cl.
Change-Id: If3a842385c935ae7833ae9ead6ba527e4e9f11a9
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/260096
Auto-Submit: Herb Derby <herb@google.com>
Commit-Queue: Mike Klein <mtklein@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
diff --git a/src/gpu/text/GrStrikeCache.cpp b/src/gpu/text/GrStrikeCache.cpp
index 39be9bf..edf9458 100644
--- a/src/gpu/text/GrStrikeCache.cpp
+++ b/src/gpu/text/GrStrikeCache.cpp
@@ -23,9 +23,7 @@
GrMaskFormatBytesPerPixel(kA565_GrMaskFormat))) { }
GrStrikeCache::~GrStrikeCache() {
- fCache.foreach([](sk_sp<GrTextStrike>* strike){
- (*strike)->fIsAbandoned = true;
- });
+ this->freeAll();
}
void GrStrikeCache::freeAll() {
@@ -38,8 +36,8 @@
void GrStrikeCache::HandleEviction(GrDrawOpAtlas::AtlasID id, void* ptr) {
GrStrikeCache* grStrikeCache = reinterpret_cast<GrStrikeCache*>(ptr);
- grStrikeCache->fCache.mutate([grStrikeCache, id](sk_sp<GrTextStrike>* strikeHandle){
- GrTextStrike* strike = strikeHandle->get();
+ grStrikeCache->fCache.mutate([grStrikeCache, id](sk_sp<GrTextStrike>* cacheSlot){
+ GrTextStrike* strike = cacheSlot->get();
strike->removeID(id);
// clear out any empty strikes. We will preserve the strike whose call to addToAtlas
diff --git a/src/gpu/text/GrStrikeCache.h b/src/gpu/text/GrStrikeCache.h
index 0a49827..7d04c6f 100644
--- a/src/gpu/text/GrStrikeCache.h
+++ b/src/gpu/text/GrStrikeCache.h
@@ -96,8 +96,9 @@
// Therefore, the caller must check GrTextStrike::isAbandoned() if there are other
// interactions with the cache since the strike was received.
sk_sp<GrTextStrike> getStrike(const SkDescriptor& desc) {
- sk_sp<GrTextStrike>* strike = fCache.find(desc);
- if (strike) { return *strike; }
+ if (sk_sp<GrTextStrike>* cached = fCache.find(desc)) {
+ return *cached;
+ }
return this->generateStrike(desc);
}
@@ -109,7 +110,6 @@
private:
sk_sp<GrTextStrike> generateStrike(const SkDescriptor& desc) {
- // 'fCache' get the construction ref
sk_sp<GrTextStrike> strike = sk_make_sp<GrTextStrike>(desc);
fCache.set(strike);
return strike;
@@ -122,8 +122,6 @@
static uint32_t Hash(const SkDescriptor& desc) { return desc.getChecksum(); }
};
- // TODO - switch from GrTextStrike* to sk_sp<GrTextStrike>.
- // TODO - can this become SkTHashMap?
using StrikeHash = SkTHashTable<sk_sp<GrTextStrike>, SkDescriptor, DescriptorHashTraits>;
StrikeHash fCache;