summaryrefslogtreecommitdiffstats
path: root/libs
diff options
context:
space:
mode:
authorChet Haase <chet@google.com>2011-05-20 07:33:41 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2011-05-20 07:33:41 -0700
commit9162bca1424da7b4e36ac3750069ddfffe39634f (patch)
tree75cd1d680b00d1efd0e2a650e6e5c6b0fcce6b9f /libs
parent0ca2fda0f703a05f3bbad538d3f33b7492118e62 (diff)
parent44984ea0cb3702384d023b5f211deda3c4b0b656 (diff)
downloadframeworks_base-9162bca1424da7b4e36ac3750069ddfffe39634f.zip
frameworks_base-9162bca1424da7b4e36ac3750069ddfffe39634f.tar.gz
frameworks_base-9162bca1424da7b4e36ac3750069ddfffe39634f.tar.bz2
Merge "Enable large font rendering with GPU acceleration"
Diffstat (limited to 'libs')
-rw-r--r--libs/hwui/FontRenderer.cpp39
-rw-r--r--libs/hwui/FontRenderer.h2
2 files changed, 35 insertions, 6 deletions
diff --git a/libs/hwui/FontRenderer.cpp b/libs/hwui/FontRenderer.cpp
index aa9b40e..1ca0a19 100644
--- a/libs/hwui/FontRenderer.cpp
+++ b/libs/hwui/FontRenderer.cpp
@@ -35,6 +35,9 @@ namespace uirenderer {
#define DEFAULT_TEXT_CACHE_WIDTH 1024
#define DEFAULT_TEXT_CACHE_HEIGHT 256
+#define MAX_TEXT_CACHE_WIDTH 2048
+#define MAX_TEXT_CACHE_HEIGHT 2048
+
///////////////////////////////////////////////////////////////////////////////
// Font
///////////////////////////////////////////////////////////////////////////////
@@ -386,9 +389,17 @@ void FontRenderer::flushAllAndInvalidate() {
bool FontRenderer::cacheBitmap(const SkGlyph& glyph, uint32_t* retOriginX, uint32_t* retOriginY) {
// If the glyph is too tall, don't cache it
if (glyph.fHeight > mCacheLines[mCacheLines.size() - 1]->mMaxHeight) {
- LOGE("Font size to large to fit in cache. width, height = %i, %i",
- (int) glyph.fWidth, (int) glyph.fHeight);
- return false;
+ if (mCacheHeight < MAX_TEXT_CACHE_HEIGHT) {
+ // Default cache not large enough for large glyphs - resize cache to
+ // max size and try again
+ flushAllAndInvalidate();
+ initTextTexture(true);
+ }
+ if (glyph.fHeight > mCacheLines[mCacheLines.size() - 1]->mMaxHeight) {
+ LOGE("Font size to large to fit in cache. width, height = %i, %i",
+ (int) glyph.fWidth, (int) glyph.fHeight);
+ return false;
+ }
}
// Now copy the bitmap into the cache texture
@@ -446,16 +457,25 @@ bool FontRenderer::cacheBitmap(const SkGlyph& glyph, uint32_t* retOriginX, uint3
return true;
}
-void FontRenderer::initTextTexture() {
+void FontRenderer::initTextTexture(bool largeFonts) {
+ mCacheLines.clear();
+ if (largeFonts) {
+ mCacheWidth = MAX_TEXT_CACHE_WIDTH;
+ mCacheHeight = MAX_TEXT_CACHE_HEIGHT;
+ }
+
mTextTexture = new uint8_t[mCacheWidth * mCacheHeight];
memset(mTextTexture, 0, mCacheWidth * mCacheHeight * sizeof(uint8_t));
mUploadTexture = false;
+ if (mTextureId != 0) {
+ glDeleteTextures(1, &mTextureId);
+ }
glGenTextures(1, &mTextureId);
glBindTexture(GL_TEXTURE_2D, mTextureId);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
- // Initialize texture dimentions
+ // Initialize texture dimensions
glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, mCacheWidth, mCacheHeight, 0,
GL_ALPHA, GL_UNSIGNED_BYTE, 0);
@@ -480,6 +500,15 @@ void FontRenderer::initTextTexture() {
nextLine += mCacheLines.top()->mMaxHeight;
mCacheLines.push(new CacheTextureLine(mCacheWidth, 42, nextLine, 0));
nextLine += mCacheLines.top()->mMaxHeight;
+ if (largeFonts) {
+ int nextSize = 76;
+ // Make several new lines with increasing font sizes
+ while (nextSize < (int)(mCacheHeight - nextLine - (2 * nextSize))) {
+ mCacheLines.push(new CacheTextureLine(mCacheWidth, nextSize, nextLine, 0));
+ nextLine += mCacheLines.top()->mMaxHeight;
+ nextSize += 50;
+ }
+ }
mCacheLines.push(new CacheTextureLine(mCacheWidth, mCacheHeight - nextLine, nextLine, 0));
}
diff --git a/libs/hwui/FontRenderer.h b/libs/hwui/FontRenderer.h
index f685d5f..95f714f 100644
--- a/libs/hwui/FontRenderer.h
+++ b/libs/hwui/FontRenderer.h
@@ -229,7 +229,7 @@ protected:
}
};
- void initTextTexture();
+ void initTextTexture(bool largeFonts = false);
bool cacheBitmap(const SkGlyph& glyph, uint32_t *retOriginX, uint32_t *retOriginY);
void flushAllAndInvalidate();