Flutter Engine
The Flutter Engine
ParagraphCache.h
Go to the documentation of this file.
1// Copyright 2019 Google LLC.
2#ifndef ParagraphCache_DEFINED
3#define ParagraphCache_DEFINED
4
7#include <functional> // std::function
8
9#define PARAGRAPH_CACHE_STATS
10
11namespace skia {
12namespace textlayout {
13
14class ParagraphImpl;
15class ParagraphCacheKey;
16class ParagraphCacheValue;
17
19public:
22
23 void abandon();
24 void reset();
25 bool updateParagraph(ParagraphImpl* paragraph);
26 bool findParagraph(ParagraphImpl* paragraph);
27
28 // For testing
29 void setChecker(std::function<void(ParagraphImpl* impl, const char*, bool)> checker) {
30 fChecker = std::move(checker);
31 }
32 void printStatistics();
33 void turnOn(bool value) { fCacheIsOn = value; }
34 int count() { return fLRUCacheMap.count(); }
35
36 bool isPossiblyTextEditing(ParagraphImpl* paragraph);
37
38 private:
39
40 struct Entry;
41 void updateFrom(const ParagraphImpl* paragraph, Entry* entry);
42 void updateTo(ParagraphImpl* paragraph, const Entry* entry);
43
44 mutable SkMutex fParagraphMutex;
45 std::function<void(ParagraphImpl* impl, const char*, bool)> fChecker;
46
47 static const int kMaxEntries = 128;
48
49 struct KeyHash {
50 uint32_t operator()(const ParagraphCacheKey& key) const;
51 };
52
54 bool fCacheIsOn;
55 ParagraphCacheValue* fLastCachedValue;
56
57#ifdef PARAGRAPH_CACHE_STATS
58 int fTotalRequests;
59 int fCacheMisses;
60 int fHashMisses; // cache hit but hash table missed
61#endif
62};
63
64} // namespace textlayout
65} // namespace skia
66
67#endif // ParagraphCache_DEFINED
void setChecker(std::function< void(ParagraphImpl *impl, const char *, bool)> checker)
bool updateParagraph(ParagraphImpl *paragraph)
bool findParagraph(ParagraphImpl *paragraph)
bool isPossiblyTextEditing(ParagraphImpl *paragraph)
uint8_t value
Dart_NativeFunction function
Definition: fuchsia.cc:51
Definition: DartTypes.h:13