2 * Copyright 2015 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #include "src/core/SkArenaAlloc.h"
9 #include "src/core/SkStrikeSpec.h"
10 #include "src/text/gpu/Glyph.h"
11 #include "src/text/gpu/StrikeCache.h"
13 namespace sktext::gpu {
15 StrikeCache::~StrikeCache() {
19 void StrikeCache::freeAll() {
23 sk_sp<TextStrike> StrikeCache::findOrCreateStrike(const SkStrikeSpec& strikeSpec) {
24 if (sk_sp<TextStrike>* cached = fCache.find(strikeSpec.descriptor())) {
27 return this->generateStrike(strikeSpec);
30 sk_sp<TextStrike> StrikeCache::generateStrike(const SkStrikeSpec& strikeSpec) {
31 sk_sp<TextStrike> strike = sk_make_sp<TextStrike>(strikeSpec);
36 const SkDescriptor& StrikeCache::HashTraits::GetKey(const sk_sp<TextStrike>& strike) {
37 return strike->fStrikeSpec.descriptor();
40 uint32_t StrikeCache::HashTraits::Hash(const SkDescriptor& descriptor) {
41 return descriptor.getChecksum();
44 TextStrike::TextStrike(const SkStrikeSpec& strikeSpec) : fStrikeSpec{strikeSpec} {}
46 Glyph* TextStrike::getGlyph(SkPackedGlyphID packedGlyphID) {
47 Glyph* glyph = fCache.findOrNull(packedGlyphID);
48 if (glyph == nullptr) {
49 glyph = fAlloc.make<Glyph>(packedGlyphID);
55 const SkPackedGlyphID& TextStrike::HashTraits::GetKey(const Glyph* glyph) {
56 return glyph->fPackedID;
59 uint32_t TextStrike::HashTraits::Hash(SkPackedGlyphID key) {
63 } // namespace sktext::gpu