Properly pre-cache latin glyphs

Bug #6408362

Change-Id: Ie11644c5a9e2d87d3b851b7e619e5f04b60a7e02
This commit is contained in:
Romain Guy
2012-05-14 14:00:27 -07:00
parent 2411c3361e
commit ae91c4cbc7
2 changed files with 17 additions and 14 deletions

View File

@@ -776,12 +776,6 @@ void FontRenderer::checkInit() {
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 @@ uint32_t FontRenderer::getRemainingCacheCapacity() {
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++;
}
}

View File

@@ -41,11 +41,13 @@ namespace uirenderer {
#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 @@ public:
uint32_t mCurrentRow;
uint32_t mCurrentCol;
bool mDirty;
CacheTexture *mCacheTexture;
CacheTexture* mCacheTexture;
};
struct CachedGlyphInfo {
@@ -236,8 +238,6 @@ public:
FontRenderer();
~FontRenderer();
void init();
void deinit();
void flushLargeCaches();
void setGammaTable(const uint8_t* gammaTable) {
@@ -278,6 +278,7 @@ public:
GLuint getTexture(bool linearFiltering = false) {
checkInit();
if (linearFiltering != mCurrentCacheTexture->mLinearFiltering) {
mCurrentCacheTexture->mLinearFiltering = linearFiltering;
mLinearFiltering = linearFiltering;
@@ -287,6 +288,7 @@ public:
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 @@ protected:
void initRender(const Rect* clip, Rect* bounds);
void finishRender();
String16 mLatinPrecache;
void precacheLatin(SkPaint* paint);
void issueDrawCommand();