Update rive-cpp to 2.0 version
[platform/core/uifw/rive-tizen.git] / submodule / skia / src / text / gpu / StrikeCache.cpp
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/text/gpu/Glyph.h"
11 #include "src/text/gpu/StrikeCache.h"
12
13 namespace sktext::gpu {
14
15 StrikeCache::~StrikeCache() {
16     this->freeAll();
17 }
18
19 void StrikeCache::freeAll() {
20     fCache.reset();
21 }
22
23 sk_sp<TextStrike> StrikeCache::findOrCreateStrike(const SkStrikeSpec& strikeSpec) {
24     if (sk_sp<TextStrike>* cached = fCache.find(strikeSpec.descriptor())) {
25         return *cached;
26     }
27     return this->generateStrike(strikeSpec);
28 }
29
30 sk_sp<TextStrike> StrikeCache::generateStrike(const SkStrikeSpec& strikeSpec) {
31     sk_sp<TextStrike> strike = sk_make_sp<TextStrike>(strikeSpec);
32     fCache.set(strike);
33     return strike;
34 }
35
36 const SkDescriptor& StrikeCache::HashTraits::GetKey(const sk_sp<TextStrike>& strike) {
37     return strike->fStrikeSpec.descriptor();
38 }
39
40 uint32_t StrikeCache::HashTraits::Hash(const SkDescriptor& descriptor) {
41     return descriptor.getChecksum();
42 }
43
44 TextStrike::TextStrike(const SkStrikeSpec& strikeSpec) : fStrikeSpec{strikeSpec} {}
45
46 Glyph* TextStrike::getGlyph(SkPackedGlyphID packedGlyphID) {
47     Glyph* glyph = fCache.findOrNull(packedGlyphID);
48     if (glyph == nullptr) {
49         glyph = fAlloc.make<Glyph>(packedGlyphID);
50         fCache.set(glyph);
51     }
52     return glyph;
53 }
54
55 const SkPackedGlyphID& TextStrike::HashTraits::GetKey(const Glyph* glyph) {
56     return glyph->fPackedID;
57 }
58
59 uint32_t TextStrike::HashTraits::Hash(SkPackedGlyphID key) {
60     return key.hash();
61 }
62
63 }  // namespace sktext::gpu