From ae91c4cbc79ea910753be65e2f1d7899abcb4da2 Mon Sep 17 00:00:00 2001 From: Romain Guy Date: Mon, 14 May 2012 14:00:27 -0700 Subject: [PATCH] Properly pre-cache latin glyphs Bug #6408362 Change-Id: Ie11644c5a9e2d87d3b851b7e619e5f04b60a7e02 --- libs/hwui/FontRenderer.cpp | 22 ++++++++++++---------- libs/hwui/FontRenderer.h | 9 +++++---- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/libs/hwui/FontRenderer.cpp b/libs/hwui/FontRenderer.cpp index 9e7fbb52285f..44bfb11f679a 100644 --- a/libs/hwui/FontRenderer.cpp +++ b/libs/hwui/FontRenderer.cpp @@ -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++; } } diff --git a/libs/hwui/FontRenderer.h b/libs/hwui/FontRenderer.h index 4fc5862b1ee5..b5aa26b10089 100644 --- a/libs/hwui/FontRenderer.h +++ b/libs/hwui/FontRenderer.h @@ -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(); -- 2.11.0