Use SkTHashTable in GrTextStrike
Change-Id: I29eb56e9fc7397836c2326bafd131554ad69c33f
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/259998
Reviewed-by: Mike Klein <mtklein@google.com>
Commit-Queue: Herb Derby <herb@google.com>
diff --git a/src/gpu/GrGlyph.h b/src/gpu/GrGlyph.h
index 96ea558..45cfb61 100644
--- a/src/gpu/GrGlyph.h
+++ b/src/gpu/GrGlyph.h
@@ -83,15 +83,6 @@
uint32_t pageIndex() const { return GrDrawOpAtlas::GetPageIndexFromID(fID); }
MaskStyle maskStyle() const { return fMaskStyle; }
- // GetKey and Hash for the the hash table.
- static const SkPackedGlyphID& GetKey(const GrGlyph& glyph) {
- return glyph.fPackedID;
- }
-
- static uint32_t Hash(SkPackedGlyphID key) {
- return SkChecksum::Mix(key.hash());
- }
-
const SkPackedGlyphID fPackedID;
const GrMaskFormat fMaskFormat;
const MaskStyle fMaskStyle;
diff --git a/src/gpu/text/GrStrikeCache.cpp b/src/gpu/text/GrStrikeCache.cpp
index 10f1bc7..39be9bf 100644
--- a/src/gpu/text/GrStrikeCache.cpp
+++ b/src/gpu/text/GrStrikeCache.cpp
@@ -169,15 +169,13 @@
: fFontScalerKey(key) {}
void GrTextStrike::removeID(GrDrawOpAtlas::AtlasID id) {
- SkTDynamicHash<GrGlyph, SkPackedGlyphID>::Iter iter(&fCache);
- while (!iter.done()) {
- if (id == (*iter).fID) {
- (*iter).fID = GrDrawOpAtlas::kInvalidAtlasID;
+ fCache.foreach([this, id](GrGlyph** glyph){
+ if ((*glyph)->fID == id) {
+ (*glyph)->fID = GrDrawOpAtlas::kInvalidAtlasID;
fAtlasedGlyphs--;
SkASSERT(fAtlasedGlyphs >= 0);
}
- ++iter;
- }
+ });
}
GrDrawOpAtlas::ErrorCode GrTextStrike::addGlyphToAtlas(
@@ -191,7 +189,7 @@
bool isScaledGlyph) {
SkASSERT(glyph);
SkASSERT(metricsAndImages);
- SkASSERT(fCache.find(glyph->fPackedID));
+ SkASSERT(fCache.findOrNull(glyph->fPackedID));
expectedMaskFormat = fullAtlasManager->resolveMaskFormat(expectedMaskFormat);
int bytesPerPixel = GrMaskFormatBytesPerPixel(expectedMaskFormat);
@@ -240,23 +238,23 @@
}
GrGlyph* GrTextStrike::getGlyph(const SkGlyph& skGlyph) {
- GrGlyph* grGlyph = fCache.find(skGlyph.getPackedID());
+ GrGlyph* grGlyph = fCache.findOrNull(skGlyph.getPackedID());
if (grGlyph == nullptr) {
grGlyph = fAlloc.make<GrGlyph>(skGlyph);
- fCache.add(grGlyph);
+ fCache.set(grGlyph);
}
return grGlyph;
}
GrGlyph*
GrTextStrike::getGlyph(SkPackedGlyphID packed, SkBulkGlyphMetricsAndImages* metricsAndImages) {
- GrGlyph* grGlyph = fCache.find(packed);
+ GrGlyph* grGlyph = fCache.findOrNull(packed);
if (grGlyph == nullptr) {
// We could return this to the caller, but in practice it adds code complexity for
// potentially little benefit(ie, if the glyph is not in our font cache, then its not
// in the atlas and we're going to be doing a texture upload anyways).
grGlyph = fAlloc.make<GrGlyph>(*metricsAndImages->glyph(packed));
- fCache.add(grGlyph);
+ fCache.set(grGlyph);
}
return grGlyph;
}
diff --git a/src/gpu/text/GrStrikeCache.h b/src/gpu/text/GrStrikeCache.h
index 6920b4f..0a49827 100644
--- a/src/gpu/text/GrStrikeCache.h
+++ b/src/gpu/text/GrStrikeCache.h
@@ -60,7 +60,17 @@
bool isAbandoned() const { return fIsAbandoned; }
private:
- SkTDynamicHash<GrGlyph, SkPackedGlyphID> fCache;
+ struct HashTraits {
+ // GetKey and Hash for the the hash table.
+ static const SkPackedGlyphID& GetKey(const GrGlyph* glyph) {
+ return glyph->fPackedID;
+ }
+
+ static uint32_t Hash(SkPackedGlyphID key) {
+ return SkChecksum::Mix(key.hash());
+ }
+ };
+ SkTHashTable<GrGlyph*, SkPackedGlyphID, HashTraits> fCache;
SkAutoDescriptor fFontScalerKey;
SkArenaAlloc fAlloc{512};