Skip to content

Commit ae91c4c

Browse files
author
Romain Guy
committed
Properly pre-cache latin glyphs
Bug #6408362 Change-Id: Ie11644c5a9e2d87d3b851b7e619e5f04b60a7e02
1 parent 2411c33 commit ae91c4c

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

libs/hwui/FontRenderer.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -776,12 +776,6 @@ void FontRenderer::checkInit() {
776776
initTextTexture();
777777
initVertexArrayBuffers();
778778

779-
// We store a string with letters in a rough frequency of occurrence
780-
mLatinPrecache = String16("eisarntolcdugpmhbyfvkwzxjq ");
781-
mLatinPrecache += String16("EISARNTOLCDUGPMHBYFVKWZXJQ");
782-
mLatinPrecache += String16(",.?!()-+@;:'");
783-
mLatinPrecache += String16("0123456789");
784-
785779
mInitialized = true;
786780
}
787781

@@ -944,11 +938,19 @@ uint32_t FontRenderer::getRemainingCacheCapacity() {
944938
void FontRenderer::precacheLatin(SkPaint* paint) {
945939
// Remaining capacity is measured in %
946940
uint32_t remainingCapacity = getRemainingCacheCapacity();
947-
uint32_t precacheIdx = 0;
948-
while (remainingCapacity > 25 && precacheIdx < mLatinPrecache.size()) {
949-
mCurrentFont->getCachedGlyph(paint, (int32_t) mLatinPrecache[precacheIdx]);
941+
uint32_t precacheIndex = 0;
942+
943+
// We store a string with letters in a rough frequency of occurrence
944+
String16 l("eisarntolcdugpmhbyfvkwzxjq EISARNTOLCDUGPMHBYFVKWZXJQ,.?!()-+@;:'0123456789");
945+
946+
size_t size = l.size();
947+
uint16_t latin[size];
948+
paint->utfToGlyphs(l.string(), SkPaint::kUTF16_TextEncoding, size * sizeof(char16_t), latin);
949+
950+
while (remainingCapacity > 25 && precacheIndex < size) {
951+
mCurrentFont->getCachedGlyph(paint, TO_GLYPH(latin[precacheIndex]));
950952
remainingCapacity = getRemainingCacheCapacity();
951-
precacheIdx ++;
953+
precacheIndex++;
952954
}
953955
}
954956

libs/hwui/FontRenderer.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,13 @@ namespace uirenderer {
4141

4242
#if RENDER_TEXT_AS_GLYPHS
4343
typedef uint16_t glyph_t;
44+
#define TO_GLYPH(g) g
4445
#define GET_METRICS(paint, glyph) paint->getGlyphMetrics(glyph)
4546
#define GET_GLYPH(text) nextGlyph((const uint16_t**) &text)
4647
#define IS_END_OF_STRING(glyph) false
4748
#else
4849
typedef SkUnichar glyph_t;
50+
#define TO_GLYPH(g) ((SkUnichar) g)
4951
#define GET_METRICS(paint, glyph) paint->getUnicharMetrics(glyph)
5052
#define GET_GLYPH(text) SkUTF16_NextUnichar((const uint16_t**) &text)
5153
#define IS_END_OF_STRING(glyph) glyph < 0
@@ -98,7 +100,7 @@ class CacheTextureLine {
98100
uint32_t mCurrentRow;
99101
uint32_t mCurrentCol;
100102
bool mDirty;
101-
CacheTexture *mCacheTexture;
103+
CacheTexture* mCacheTexture;
102104
};
103105

104106
struct CachedGlyphInfo {
@@ -236,8 +238,6 @@ class FontRenderer {
236238
FontRenderer();
237239
~FontRenderer();
238240

239-
void init();
240-
void deinit();
241241
void flushLargeCaches();
242242

243243
void setGammaTable(const uint8_t* gammaTable) {
@@ -278,6 +278,7 @@ class FontRenderer {
278278

279279
GLuint getTexture(bool linearFiltering = false) {
280280
checkInit();
281+
281282
if (linearFiltering != mCurrentCacheTexture->mLinearFiltering) {
282283
mCurrentCacheTexture->mLinearFiltering = linearFiltering;
283284
mLinearFiltering = linearFiltering;
@@ -287,6 +288,7 @@ class FontRenderer {
287288
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filtering);
288289
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filtering);
289290
}
291+
290292
return mCurrentCacheTexture->mTextureId;
291293
}
292294

@@ -326,7 +328,6 @@ class FontRenderer {
326328
void initRender(const Rect* clip, Rect* bounds);
327329
void finishRender();
328330

329-
String16 mLatinPrecache;
330331
void precacheLatin(SkPaint* paint);
331332

332333
void issueDrawCommand();

0 commit comments

Comments
 (0)