• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2015 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #include "src/core/SkArenaAlloc.h"
9 #include "src/core/SkStrikeSpec.h"
10 #include "src/gpu/GrGlyph.h"
11 #include "src/gpu/text/GrStrikeCache.h"
12 
~GrStrikeCache()13 GrStrikeCache::~GrStrikeCache() {
14     this->freeAll();
15 }
16 
freeAll()17 void GrStrikeCache::freeAll() {
18     fCache.reset();
19 }
20 
findOrCreateStrike(const SkStrikeSpec & strikeSpec)21 sk_sp<GrTextStrike> GrStrikeCache::findOrCreateStrike(const SkStrikeSpec& strikeSpec) {
22     if (sk_sp<GrTextStrike>* cached = fCache.find(strikeSpec.descriptor())) {
23         return *cached;
24     }
25     return this->generateStrike(strikeSpec);
26 }
27 
generateStrike(const SkStrikeSpec & strikeSpec)28 sk_sp<GrTextStrike> GrStrikeCache::generateStrike(const SkStrikeSpec& strikeSpec) {
29     sk_sp<GrTextStrike> strike = sk_make_sp<GrTextStrike>(strikeSpec);
30     fCache.set(strike);
31     return strike;
32 }
33 
GetKey(const sk_sp<GrTextStrike> & strike)34 const SkDescriptor& GrStrikeCache::HashTraits::GetKey(const sk_sp<GrTextStrike>& strike) {
35     return strike->fStrikeSpec.descriptor();
36 }
37 
Hash(const SkDescriptor & descriptor)38 uint32_t GrStrikeCache::HashTraits::Hash(const SkDescriptor& descriptor) {
39     return descriptor.getChecksum();
40 }
41 
GrTextStrike(const SkStrikeSpec & strikeSpec)42 GrTextStrike::GrTextStrike(const SkStrikeSpec& strikeSpec) : fStrikeSpec{strikeSpec} {}
43 
getGlyph(SkPackedGlyphID packedGlyphID)44 GrGlyph* GrTextStrike::getGlyph(SkPackedGlyphID packedGlyphID) {
45     GrGlyph* grGlyph = fCache.findOrNull(packedGlyphID);
46     if (grGlyph == nullptr) {
47         grGlyph = fAlloc.make<GrGlyph>(packedGlyphID);
48         fCache.set(grGlyph);
49     }
50     return grGlyph;
51 }
52 
GetKey(const GrGlyph * glyph)53 const SkPackedGlyphID& GrTextStrike::HashTraits::GetKey(const GrGlyph* glyph) {
54     return glyph->fPackedID;
55 }
56 
Hash(SkPackedGlyphID key)57 uint32_t GrTextStrike::HashTraits::Hash(SkPackedGlyphID key) {
58     return key.hash();
59 }
60 
61