Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
StrikeCache.h
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 */
7
8#ifndef sktext_gpu_StrikeCache_DEFINED
9#define sktext_gpu_StrikeCache_DEFINED
10
15#include "src/core/SkTHash.h"
16
17#include <cstdint>
18
19struct SkPackedGlyphID;
20
21namespace sktext::gpu {
22
23class Glyph;
24
25// The TextStrike manages an SkArenaAlloc for Glyphs. The SkStrike is what actually creates
26// the mask. The TextStrike may outlive the generating SkStrike. However, it retains a copy
27// of it's SkDescriptor as a key to access (or regenerate) the SkStrike. TextStrikes are
28// created by and owned by a StrikeCache.
29class TextStrike : public SkNVRefCnt<TextStrike> {
30public:
32
34 const SkStrikeSpec& strikeSpec() const { return fStrikeSpec; }
35
36private:
37 // Key for retrieving the SkStrike for creating new atlas data.
38 const SkStrikeSpec fStrikeSpec;
39
40 struct HashTraits {
41 static const SkPackedGlyphID& GetKey(const Glyph* glyph);
42 static uint32_t Hash(SkPackedGlyphID key);
43 };
44 // Map SkPackedGlyphID -> Glyph*.
46
47 // Store for the glyph information.
48 SkArenaAlloc fAlloc{512};
49
50 friend class StrikeCache;
51};
52
53// StrikeCache manages strikes which are indexed by a SkStrike. These strikes can then be
54// used to generate individual Glyph Masks.
56public:
58
59 // The user of the cache may hold a long-lived ref to the returned strike.
61
62 void freeAll();
63
64private:
65 sk_sp<TextStrike> generateStrike(const SkStrikeSpec& strikeSpec);
66
67 struct HashTraits {
68 static const SkDescriptor& GetKey(const sk_sp<TextStrike>& strike);
69 static uint32_t Hash(const SkDescriptor& strikeSpec);
70 };
71
73
74 StrikeHash fCache;
75};
76
77} // namespace sktext::gpu
78
79#endif // sktext_gpu_StrikeCache_DEFINED
sk_sp< TextStrike > findOrCreateStrike(const SkStrikeSpec &strikeSpec)
Glyph * getGlyph(SkPackedGlyphID)
const SkStrikeSpec & strikeSpec() const
Definition StrikeCache.h:34