Flutter Engine
The Flutter Engine
StrikeCache.cpp
Go to the documentation of this file.
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 */
8
12#include "src/core/SkGlyph.h"
17#include "src/text/gpu/Glyph.h"
18
19#include <optional>
20#include <utility>
21
22class SkStrike;
23
24namespace sktext::gpu {
25
27 this->freeAll();
28}
29
31 fCache.reset();
32}
33
35 if (sk_sp<TextStrike>* cached = fCache.find(strikeSpec.descriptor())) {
36 return *cached;
37 }
38 return this->generateStrike(strikeSpec);
39}
40
41sk_sp<TextStrike> StrikeCache::generateStrike(const SkStrikeSpec& strikeSpec) {
42 sk_sp<TextStrike> strike = sk_make_sp<TextStrike>(strikeSpec);
43 fCache.set(strike);
44 return strike;
45}
46
47const SkDescriptor& StrikeCache::HashTraits::GetKey(const sk_sp<TextStrike>& strike) {
48 return strike->fStrikeSpec.descriptor();
49}
50
51uint32_t StrikeCache::HashTraits::Hash(const SkDescriptor& descriptor) {
52 return descriptor.getChecksum();
53}
54
55TextStrike::TextStrike(const SkStrikeSpec& strikeSpec) : fStrikeSpec{strikeSpec} {}
56
58 Glyph* glyph = fCache.findOrNull(packedGlyphID);
59 if (glyph == nullptr) {
60 glyph = fAlloc.make<Glyph>(packedGlyphID);
61 fCache.set(glyph);
62 }
63 return glyph;
64}
65
66const SkPackedGlyphID& TextStrike::HashTraits::GetKey(const Glyph* glyph) {
67 return glyph->fPackedID;
68}
69
71 return key.hash();
72}
73
74} // namespace sktext::gpu
75
76namespace sktext {
77std::optional<SkStrikePromise> SkStrikePromise::MakeFromBuffer(
78 SkReadBuffer& buffer, const SkStrikeClient* client, SkStrikeCache* strikeCache) {
79 std::optional<SkAutoDescriptor> descriptor = SkAutoDescriptor::MakeFromBuffer(buffer);
80 if (!buffer.validate(descriptor.has_value())) {
81 return std::nullopt;
82 }
83
84 // If there is a client, then this from a different process. Translate the SkTypefaceID from
85 // the strike server (Renderer) process to strike client (GPU) process.
86 if (client != nullptr) {
87 if (!client->translateTypefaceID(&descriptor.value())) {
88 return std::nullopt;
89 }
90 }
91
92 sk_sp<SkStrike> strike = strikeCache->findStrike(*descriptor->getDesc());
93 SkASSERT(strike != nullptr);
94 if (!buffer.validate(strike != nullptr)) {
95 return std::nullopt;
96 }
97
98 return SkStrikePromise{std::move(strike)};
99}
100} // namespace sktext
#define SkASSERT(cond)
Definition: SkAssert.h:116
auto make(Ctor &&ctor) -> decltype(ctor(nullptr))
Definition: SkArenaAlloc.h:120
static std::optional< SkAutoDescriptor > MakeFromBuffer(SkReadBuffer &buffer)
uint32_t getChecksum() const
Definition: SkDescriptor.h:64
sk_sp< SkStrike > findStrike(const SkDescriptor &desc) SK_EXCLUDES(fLock)
SK_SPI bool translateTypefaceID(SkAutoDescriptor *descriptor) const
const SkDescriptor & descriptor() const
Definition: SkStrikeSpec.h:96
T * find(const K &key) const
Definition: SkTHash.h:107
static std::optional< SkStrikePromise > MakeFromBuffer(SkReadBuffer &buffer, const SkStrikeClient *client, SkStrikeCache *strikeCache)
Definition: StrikeCache.cpp:77
const SkDescriptor & descriptor() const
const SkPackedGlyphID fPackedID
Definition: Glyph.h:39
sk_sp< TextStrike > findOrCreateStrike(const SkStrikeSpec &strikeSpec)
Definition: StrikeCache.cpp:34
TextStrike(const SkStrikeSpec &strikeSpec)
Definition: StrikeCache.cpp:55
Glyph * getGlyph(SkPackedGlyphID)
Definition: StrikeCache.cpp:57
static uint32_t Hash(uint32_t key)
Definition: hashmap_test.cc:65
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126