Loading libs/hwui/FontRenderer.cpp +34 −5 Original line number Diff line number Diff line Loading @@ -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 /////////////////////////////////////////////////////////////////////////////// Loading Loading @@ -385,11 +388,19 @@ 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) { 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 uint32_t startX = 0; Loading Loading @@ -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); Loading @@ -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)); } Loading libs/hwui/FontRenderer.h +1 −1 Original line number Diff line number Diff line Loading @@ -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(); Loading tests/HwAccelerationTest/src/com/android/test/hwui/TextActivity.java +12 −3 Original line number Diff line number Diff line Loading @@ -38,6 +38,7 @@ public class TextActivity extends Activity { private final Paint mStrikePaint; private final Paint mScaledPaint; private final Paint mSkewPaint; private final Paint mHugePaint; CustomTextView(Context c) { super(c); Loading @@ -64,6 +65,11 @@ public class TextActivity extends Activity { mSkewPaint.setAntiAlias(true); mSkewPaint.setTextSize(16.0f); mSkewPaint.setShadowLayer(3.0f, 3.0f, 3.0f, 0xff000000); mHugePaint = new Paint(); mHugePaint.setAntiAlias(true); mHugePaint.setColor(0xff000000); mHugePaint.setTextSize(300f); } @Override Loading Loading @@ -99,6 +105,8 @@ public class TextActivity extends Activity { mLargePaint.setColor(0xff000000); mLargePaint.clearShadowLayer(); canvas.drawText("Hello!", 500, 600, mHugePaint); canvas.drawText("Hello OpenGL renderer!", 500, 40, mStrikePaint); mStrikePaint.setStrikeThruText(true); canvas.drawText("Hello OpenGL renderer!", 500, 70, mStrikePaint); Loading @@ -125,6 +133,7 @@ public class TextActivity extends Activity { canvas.clipRect(150.0f, 220.0f, 450.0f, 320.0f); canvas.drawText("Hello OpenGL renderer!", 100, 300, mLargePaint); canvas.restore(); } } } Loading
libs/hwui/FontRenderer.cpp +34 −5 Original line number Diff line number Diff line Loading @@ -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 /////////////////////////////////////////////////////////////////////////////// Loading Loading @@ -385,11 +388,19 @@ 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) { 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 uint32_t startX = 0; Loading Loading @@ -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); Loading @@ -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)); } Loading
libs/hwui/FontRenderer.h +1 −1 Original line number Diff line number Diff line Loading @@ -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(); Loading
tests/HwAccelerationTest/src/com/android/test/hwui/TextActivity.java +12 −3 Original line number Diff line number Diff line Loading @@ -38,6 +38,7 @@ public class TextActivity extends Activity { private final Paint mStrikePaint; private final Paint mScaledPaint; private final Paint mSkewPaint; private final Paint mHugePaint; CustomTextView(Context c) { super(c); Loading @@ -64,6 +65,11 @@ public class TextActivity extends Activity { mSkewPaint.setAntiAlias(true); mSkewPaint.setTextSize(16.0f); mSkewPaint.setShadowLayer(3.0f, 3.0f, 3.0f, 0xff000000); mHugePaint = new Paint(); mHugePaint.setAntiAlias(true); mHugePaint.setColor(0xff000000); mHugePaint.setTextSize(300f); } @Override Loading Loading @@ -99,6 +105,8 @@ public class TextActivity extends Activity { mLargePaint.setColor(0xff000000); mLargePaint.clearShadowLayer(); canvas.drawText("Hello!", 500, 600, mHugePaint); canvas.drawText("Hello OpenGL renderer!", 500, 40, mStrikePaint); mStrikePaint.setStrikeThruText(true); canvas.drawText("Hello OpenGL renderer!", 500, 70, mStrikePaint); Loading @@ -125,6 +133,7 @@ public class TextActivity extends Activity { canvas.clipRect(150.0f, 220.0f, 450.0f, 320.0f); canvas.drawText("Hello OpenGL renderer!", 100, 300, mLargePaint); canvas.restore(); } } }