Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
SkCharToGlyphCache Class Reference

#include <SkCharToGlyphCache.h>

Public Member Functions

 SkCharToGlyphCache ()
 
 ~SkCharToGlyphCache ()
 
int count () const
 
void reset ()
 
int findGlyphIndex (SkUnichar c) const
 
void insertCharAndGlyph (int index, SkUnichar, SkGlyphID)
 
void addCharAndGlyph (SkUnichar unichar, SkGlyphID glyph)
 

Detailed Description

Definition at line 17 of file SkCharToGlyphCache.h.

Constructor & Destructor Documentation

◆ SkCharToGlyphCache()

SkCharToGlyphCache::SkCharToGlyphCache ( )

Definition at line 10 of file SkCharToGlyphCache.cpp.

10 {
11 this->reset();
12}

◆ ~SkCharToGlyphCache()

SkCharToGlyphCache::~SkCharToGlyphCache ( )

Definition at line 14 of file SkCharToGlyphCache.cpp.

14{}

Member Function Documentation

◆ addCharAndGlyph()

void SkCharToGlyphCache::addCharAndGlyph ( SkUnichar  unichar,
SkGlyphID  glyph 
)
inline

Definition at line 50 of file SkCharToGlyphCache.h.

50 {
51 int index = this->findGlyphIndex(unichar);
52 if (index >= 0) {
53 SkASSERT(SkToU16(index) == glyph);
54 } else {
55 this->insertCharAndGlyph(~index, unichar, glyph);
56 }
57 }
#define SkASSERT(cond)
Definition: SkAssert.h:116
constexpr uint16_t SkToU16(S x)
Definition: SkTo.h:24
int findGlyphIndex(SkUnichar c) const
void insertCharAndGlyph(int index, SkUnichar, SkGlyphID)

◆ count()

int SkCharToGlyphCache::count ( ) const
inline

Definition at line 23 of file SkCharToGlyphCache.h.

23 {
24 return fK32.size();
25 }
int size() const
Definition: SkTDArray.h:138

◆ findGlyphIndex()

int SkCharToGlyphCache::findGlyphIndex ( SkUnichar  c) const

Given a unichar, return its glyphID (if the return value is positive), else return ~index of where to insert the computed glyphID.

int result = cache.charToGlyph(unichar); if (result >= 0) { glyphID = result; } else { glyphID = compute_glyph_using_typeface(unichar); cache.insertCharAndGlyph(~result, unichar, glyphID); }

Definition at line 95 of file SkCharToGlyphCache.cpp.

95 {
96 const int count = fK32.size();
97 int index;
98 if (count <= kSmallCountLimit) {
99 index = find_simple(fK32.begin(), count, unichar);
100 } else {
101 index = find_with_slope(fK32.begin(), count, unichar, fDenom);
102 }
103 if (index >= 0) {
104 return fV16[index];
105 }
106 return index;
107}
static int find_with_slope(const SkUnichar base[], int count, SkUnichar value, double denom)
constexpr int kSmallCountLimit
static int find_simple(const SkUnichar base[], int count, SkUnichar value)
T * begin()
Definition: SkTDArray.h:150

◆ insertCharAndGlyph()

void SkCharToGlyphCache::insertCharAndGlyph ( int  index,
SkUnichar  unichar,
SkGlyphID  glyph 
)

Insert a new char/glyph pair into the cache at the specified index. See charToGlyph() for how to compute the bit-not of the index.

Definition at line 109 of file SkCharToGlyphCache.cpp.

109 {
110 SkASSERT(fK32.size() == fV16.size());
111 SkASSERT(index < fK32.size());
112 SkASSERT(unichar < fK32[index]);
113
114 *fK32.insert(index) = unichar;
115 *fV16.insert(index) = glyph;
116
117 // if we've changed the first [1] or last [count-2] entry, recompute our slope
118 const int count = fK32.size();
119 if (count >= kMinCountForSlope && (index == 1 || index == count - 2)) {
120 SkASSERT(index >= 1 && index <= count - 2);
121 fDenom = 1.0 / ((double)fK32[count - 2] - fK32[1]);
122 }
123
124#ifdef SK_DEBUG
125 for (int i = 1; i < fK32.size(); ++i) {
126 SkASSERT(fK32[i-1] < fK32[i]);
127 }
128#endif
129}
constexpr int kMinCountForSlope
T * insert(int index)
Definition: SkTDArray.h:203

◆ reset()

void SkCharToGlyphCache::reset ( )

Definition at line 16 of file SkCharToGlyphCache.cpp.

16 {
17 fK32.reset();
18 fV16.reset();
19
20 // Add sentinels so we can always rely on these to stop linear searches (in either direction)
21 // Neither is a legal unichar, so we don't care what glyphID we use.
22 //
23 *fK32.append() = 0x80000000; *fV16.append() = 0;
24 *fK32.append() = 0x7FFFFFFF; *fV16.append() = 0;
25
26 fDenom = 0;
27}
void reset()
Definition: SkTDArray.h:171
T * append()
Definition: SkTDArray.h:191

The documentation for this class was generated from the following files: