diff options
author | Romain Guy <romainguy@google.com> | 2013-03-13 16:14:47 -0700 |
---|---|---|
committer | Romain Guy <romainguy@google.com> | 2013-03-13 16:14:47 -0700 |
commit | bd3055f95e67a55648fd84a125e939293115171b (patch) | |
tree | c22ae6a64fda750461de8a0defaf85d1a999ba07 /libs/hwui/font/Font.cpp | |
parent | 0f809f3b794174f044366bf421f8d0c72d9afc14 (diff) | |
download | frameworks_base-bd3055f95e67a55648fd84a125e939293115171b.zip frameworks_base-bd3055f95e67a55648fd84a125e939293115171b.tar.gz frameworks_base-bd3055f95e67a55648fd84a125e939293115171b.tar.bz2 |
Less aggressive glyphs precaching
The renderer used to pre-cache glyphs at record time. This then changed
to pre-caching at the beginning of every frame. This unfortunately entails
a lot of duplicate work on every frame, which amounts to 0.5 to 1ms in
some stock applications.
This change is somewhere in the middle: pre-caching happens the first
time a DrawTextOp is deferred or every time the screen-space transform
is different from the last pre-caching operation.
Change-Id: Id6d9e2599d90a5b75010b0f0a28746befbf3c205
Diffstat (limited to 'libs/hwui/font/Font.cpp')
-rw-r--r-- | libs/hwui/font/Font.cpp | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/libs/hwui/font/Font.cpp b/libs/hwui/font/Font.cpp index c932087..02c1aa1 100644 --- a/libs/hwui/font/Font.cpp +++ b/libs/hwui/font/Font.cpp @@ -15,10 +15,12 @@ */ #define LOG_TAG "OpenGLRenderer" +#define ATRACE_TAG ATRACE_TAG_VIEW #include <cutils/compiler.h> #include <utils/JenkinsHash.h> +#include <utils/Trace.h> #include <SkGlyph.h> #include <SkUtils.h> @@ -261,11 +263,8 @@ void Font::drawCachedGlyph(CachedGlyphInfo* glyph, float x, float hOffset, float } CachedGlyphInfo* Font::getCachedGlyph(SkPaint* paint, glyph_t textUnit, bool precaching) { - CachedGlyphInfo* cachedGlyph = NULL; - ssize_t index = mCachedGlyphs.indexOfKey(textUnit); - if (index >= 0) { - cachedGlyph = mCachedGlyphs.valueAt(index); - + CachedGlyphInfo* cachedGlyph = mCachedGlyphs.valueFor(textUnit); + if (cachedGlyph) { // Is the glyph still in texture cache? if (!cachedGlyph->mIsValid) { const SkGlyph& skiaGlyph = GET_METRICS(paint, textUnit, @@ -346,11 +345,13 @@ void Font::measure(SkPaint* paint, const char* text, uint32_t start, uint32_t le } void Font::precache(SkPaint* paint, const char* text, int numGlyphs) { + ATRACE_NAME("precacheText"); + if (numGlyphs == 0 || text == NULL) { return; } - int glyphsCount = 0; + int glyphsCount = 0; while (glyphsCount < numGlyphs) { glyph_t glyph = GET_GLYPH(text); @@ -360,7 +361,6 @@ void Font::precache(SkPaint* paint, const char* text, int numGlyphs) { } CachedGlyphInfo* cachedGlyph = getCachedGlyph(paint, glyph, true); - glyphsCount++; } } |