Properly pre-cache latin glyphs
Bug #6408362
Change-Id: Ie11644c5a9e2d87d3b851b7e619e5f04b60a7e02
diff --git a/libs/hwui/FontRenderer.cpp b/libs/hwui/FontRenderer.cpp
index 9e7fbb5..44bfb11 100644
--- a/libs/hwui/FontRenderer.cpp
+++ b/libs/hwui/FontRenderer.cpp
@@ -776,12 +776,6 @@
initTextTexture();
initVertexArrayBuffers();
- // We store a string with letters in a rough frequency of occurrence
- mLatinPrecache = String16("eisarntolcdugpmhbyfvkwzxjq ");
- mLatinPrecache += String16("EISARNTOLCDUGPMHBYFVKWZXJQ");
- mLatinPrecache += String16(",.?!()-+@;:'");
- mLatinPrecache += String16("0123456789");
-
mInitialized = true;
}
@@ -944,11 +938,19 @@
void FontRenderer::precacheLatin(SkPaint* paint) {
// Remaining capacity is measured in %
uint32_t remainingCapacity = getRemainingCacheCapacity();
- uint32_t precacheIdx = 0;
- while (remainingCapacity > 25 && precacheIdx < mLatinPrecache.size()) {
- mCurrentFont->getCachedGlyph(paint, (int32_t) mLatinPrecache[precacheIdx]);
+ uint32_t precacheIndex = 0;
+
+ // We store a string with letters in a rough frequency of occurrence
+ String16 l("eisarntolcdugpmhbyfvkwzxjq EISARNTOLCDUGPMHBYFVKWZXJQ,.?!()-+@;:'0123456789");
+
+ size_t size = l.size();
+ uint16_t latin[size];
+ paint->utfToGlyphs(l.string(), SkPaint::kUTF16_TextEncoding, size * sizeof(char16_t), latin);
+
+ while (remainingCapacity > 25 && precacheIndex < size) {
+ mCurrentFont->getCachedGlyph(paint, TO_GLYPH(latin[precacheIndex]));
remainingCapacity = getRemainingCacheCapacity();
- precacheIdx ++;
+ precacheIndex++;
}
}
diff --git a/libs/hwui/FontRenderer.h b/libs/hwui/FontRenderer.h
index 4fc5862..b5aa26b 100644
--- a/libs/hwui/FontRenderer.h
+++ b/libs/hwui/FontRenderer.h
@@ -41,11 +41,13 @@
#if RENDER_TEXT_AS_GLYPHS
typedef uint16_t glyph_t;
+ #define TO_GLYPH(g) g
#define GET_METRICS(paint, glyph) paint->getGlyphMetrics(glyph)
#define GET_GLYPH(text) nextGlyph((const uint16_t**) &text)
#define IS_END_OF_STRING(glyph) false
#else
typedef SkUnichar glyph_t;
+ #define TO_GLYPH(g) ((SkUnichar) g)
#define GET_METRICS(paint, glyph) paint->getUnicharMetrics(glyph)
#define GET_GLYPH(text) SkUTF16_NextUnichar((const uint16_t**) &text)
#define IS_END_OF_STRING(glyph) glyph < 0
@@ -98,7 +100,7 @@
uint32_t mCurrentRow;
uint32_t mCurrentCol;
bool mDirty;
- CacheTexture *mCacheTexture;
+ CacheTexture* mCacheTexture;
};
struct CachedGlyphInfo {
@@ -236,8 +238,6 @@
FontRenderer();
~FontRenderer();
- void init();
- void deinit();
void flushLargeCaches();
void setGammaTable(const uint8_t* gammaTable) {
@@ -278,6 +278,7 @@
GLuint getTexture(bool linearFiltering = false) {
checkInit();
+
if (linearFiltering != mCurrentCacheTexture->mLinearFiltering) {
mCurrentCacheTexture->mLinearFiltering = linearFiltering;
mLinearFiltering = linearFiltering;
@@ -287,6 +288,7 @@
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filtering);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filtering);
}
+
return mCurrentCacheTexture->mTextureId;
}
@@ -326,7 +328,6 @@
void initRender(const Rect* clip, Rect* bounds);
void finishRender();
- String16 mLatinPrecache;
void precacheLatin(SkPaint* paint);
void issueDrawCommand();