summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRomain Guy <romainguy@google.com>2012-09-04 15:26:14 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2012-09-04 15:26:14 -0700
commit2ecaedd96cdcd0c83afa042cb8ff8e4358afa3cf (patch)
treed10d77467f440a54a019228d289fba5056e19fca
parent175ae55c0d62b6adbc9b3cc215ad2e65a8b40cc3 (diff)
parent9b1204baf4740b4d443e72157dea98571cf84e1f (diff)
downloadframeworks_base-2ecaedd96cdcd0c83afa042cb8ff8e4358afa3cf.zip
frameworks_base-2ecaedd96cdcd0c83afa042cb8ff8e4358afa3cf.tar.gz
frameworks_base-2ecaedd96cdcd0c83afa042cb8ff8e4358afa3cf.tar.bz2
Merge "Small code cleanup in FontRenderer" into jb-mr1-dev
-rw-r--r--libs/hwui/FontRenderer.cpp26
-rw-r--r--libs/hwui/FontRenderer.h22
-rw-r--r--libs/hwui/font/CacheTexture.cpp23
-rw-r--r--libs/hwui/font/CacheTexture.h3
-rw-r--r--libs/hwui/font/Font.cpp9
5 files changed, 59 insertions, 24 deletions
diff --git a/libs/hwui/FontRenderer.cpp b/libs/hwui/FontRenderer.cpp
index e66ab54..5ff4aba 100644
--- a/libs/hwui/FontRenderer.cpp
+++ b/libs/hwui/FontRenderer.cpp
@@ -46,7 +46,7 @@ FontRenderer::FontRenderer() {
mMaxNumberOfQuads = 1024;
mCurrentQuadIndex = 0;
- mTextMeshPtr = NULL;
+ mTextMesh = NULL;
mCurrentCacheTexture = NULL;
mLastCacheTexture = NULL;
@@ -104,7 +104,7 @@ FontRenderer::~FontRenderer() {
Caches::getInstance().unbindIndicesBuffer();
glDeleteBuffers(1, &mIndexBufferID);
- delete[] mTextMeshPtr;
+ delete[] mTextMesh;
}
Vector<Font*> fontsToDereference = mActiveFonts;
@@ -337,7 +337,7 @@ void FontRenderer::initVertexArrayBuffers() {
uint32_t uvSize = 2;
uint32_t vertsPerQuad = 4;
uint32_t vertexBufferSize = mMaxNumberOfQuads * vertsPerQuad * coordSize * uvSize;
- mTextMeshPtr = new float[vertexBufferSize];
+ mTextMesh = new float[vertexBufferSize];
}
// We don't want to allocate anything unless we actually draw text
@@ -403,7 +403,7 @@ void FontRenderer::issueDrawCommand() {
Caches& caches = Caches::getInstance();
caches.bindIndicesBuffer(mIndexBufferID);
if (!mDrawn) {
- float* buffer = mTextMeshPtr;
+ float* buffer = mTextMesh;
int offset = 2;
bool force = caches.unbindMeshBuffer();
@@ -432,7 +432,7 @@ void FontRenderer::appendMeshQuadNoClip(float x1, float y1, float u1, float v1,
const uint32_t vertsPerQuad = 4;
const uint32_t floatsPerVert = 4;
- float* currentPos = mTextMeshPtr + mCurrentQuadIndex * vertsPerQuad * floatsPerVert;
+ float* currentPos = mTextMesh + mCurrentQuadIndex * vertsPerQuad * floatsPerVert;
(*currentPos++) = x1;
(*currentPos++) = y1;
@@ -645,6 +645,19 @@ bool FontRenderer::renderTextOnPath(SkPaint* paint, const Rect* clip, const char
return mDrawn;
}
+void FontRenderer::removeFont(const Font* font) {
+ for (uint32_t ct = 0; ct < mActiveFonts.size(); ct++) {
+ if (mActiveFonts[ct] == font) {
+ mActiveFonts.removeAt(ct);
+ break;
+ }
+ }
+
+ if (mCurrentFont == font) {
+ mCurrentFont = NULL;
+ }
+}
+
void FontRenderer::computeGaussianWeights(float* weights, int32_t radius) {
// Compute gaussian weights for the blur
// e is the euler's number
@@ -732,7 +745,6 @@ void FontRenderer::verticalBlur(float* weights, int32_t radius,
float currentPixel = 0.0f;
for (int32_t y = 0; y < height; y ++) {
-
uint8_t* output = dest + y * width;
for (int32_t x = 0; x < width; x ++) {
@@ -766,7 +778,7 @@ void FontRenderer::verticalBlur(float* weights, int32_t radius,
}
}
*output = (uint8_t) blurredPixel;
- output ++;
+ output++;
}
}
}
diff --git a/libs/hwui/FontRenderer.h b/libs/hwui/FontRenderer.h
index 58aa9c3..0114445 100644
--- a/libs/hwui/FontRenderer.h
+++ b/libs/hwui/FontRenderer.h
@@ -109,7 +109,7 @@ public:
return size;
}
-protected:
+private:
friend class Font;
const uint8_t* mGammaTable;
@@ -143,6 +143,14 @@ protected:
float x3, float y3, float u3, float v3,
float x4, float y4, float u4, float v4, CacheTexture* texture);
+ void removeFont(const Font* font);
+
+ void checkTextureUpdate();
+
+ void setTextureDirty() {
+ mUploadTexture = true;
+ }
+
uint32_t mSmallCacheWidth;
uint32_t mSmallCacheHeight;
uint32_t mLargeCacheWidth;
@@ -156,11 +164,10 @@ protected:
CacheTexture* mCurrentCacheTexture;
CacheTexture* mLastCacheTexture;
- void checkTextureUpdate();
bool mUploadTexture;
// Pointer to vertex data to speed up frame to frame work
- float *mTextMeshPtr;
+ float* mTextMesh;
uint32_t mCurrentQuadIndex;
uint32_t mMaxNumberOfQuads;
@@ -174,12 +181,13 @@ protected:
bool mLinearFiltering;
- void computeGaussianWeights(float* weights, int32_t radius);
- void horizontalBlur(float* weights, int32_t radius, const uint8_t *source, uint8_t *dest,
+ /** We should consider multi-threading this code or using Renderscript **/
+ static void computeGaussianWeights(float* weights, int32_t radius);
+ static void horizontalBlur(float* weights, int32_t radius, const uint8_t *source, uint8_t *dest,
int32_t width, int32_t height);
- void verticalBlur(float* weights, int32_t radius, const uint8_t *source, uint8_t *dest,
+ static void verticalBlur(float* weights, int32_t radius, const uint8_t *source, uint8_t *dest,
int32_t width, int32_t height);
- void blurImage(uint8_t* image, int32_t width, int32_t height, int32_t radius);
+ static void blurImage(uint8_t* image, int32_t width, int32_t height, int32_t radius);
};
}; // namespace uirenderer
diff --git a/libs/hwui/font/CacheTexture.cpp b/libs/hwui/font/CacheTexture.cpp
index 5fb2636..7932822 100644
--- a/libs/hwui/font/CacheTexture.cpp
+++ b/libs/hwui/font/CacheTexture.cpp
@@ -37,13 +37,16 @@ CacheBlock* CacheBlock::insertBlock(CacheBlock* head, CacheBlock *newBlock) {
newBlock, newBlock->mX, newBlock->mY,
newBlock->mWidth, newBlock->mHeight);
#endif
+
CacheBlock *currBlock = head;
CacheBlock *prevBlock = NULL;
+
while (currBlock && currBlock->mY != TEXTURE_BORDER_SIZE) {
if (newBlock->mWidth < currBlock->mWidth) {
newBlock->mNext = currBlock;
newBlock->mPrev = prevBlock;
currBlock->mPrev = newBlock;
+
if (prevBlock) {
prevBlock->mNext = newBlock;
return head;
@@ -51,15 +54,19 @@ CacheBlock* CacheBlock::insertBlock(CacheBlock* head, CacheBlock *newBlock) {
return newBlock;
}
}
+
prevBlock = currBlock;
currBlock = currBlock->mNext;
}
+
// new block larger than all others - insert at end (but before the remainder space, if there)
newBlock->mNext = currBlock;
newBlock->mPrev = prevBlock;
+
if (currBlock) {
currBlock->mPrev = newBlock;
}
+
if (prevBlock) {
prevBlock->mNext = newBlock;
return head;
@@ -74,18 +81,23 @@ CacheBlock* CacheBlock::removeBlock(CacheBlock* head, CacheBlock *blockToRemove)
blockToRemove, blockToRemove->mX, blockToRemove->mY,
blockToRemove->mWidth, blockToRemove->mHeight);
#endif
+
CacheBlock* newHead = head;
CacheBlock* nextBlock = blockToRemove->mNext;
CacheBlock* prevBlock = blockToRemove->mPrev;
+
if (prevBlock) {
prevBlock->mNext = nextBlock;
} else {
newHead = nextBlock;
}
+
if (nextBlock) {
nextBlock->mPrev = prevBlock;
}
+
delete blockToRemove;
+
return newHead;
}
@@ -100,12 +112,14 @@ bool CacheTexture::fitBitmap(const SkGlyph& glyph, uint32_t *retOriginX, uint32_
uint16_t glyphW = glyph.fWidth + TEXTURE_BORDER_SIZE;
uint16_t glyphH = glyph.fHeight + TEXTURE_BORDER_SIZE;
+
// roundedUpW equals glyphW to the next multiple of CACHE_BLOCK_ROUNDING_SIZE.
// This columns for glyphs that are close but not necessarily exactly the same size. It trades
// off the loss of a few pixels for some glyphs against the ability to store more glyphs
// of varying sizes in one block.
uint16_t roundedUpW =
(glyphW + CACHE_BLOCK_ROUNDING_SIZE - 1) & -CACHE_BLOCK_ROUNDING_SIZE;
+
CacheBlock *cacheBlock = mCacheBlocks;
while (cacheBlock) {
// Store glyph in this block iff: it fits the block's remaining space and:
@@ -118,8 +132,10 @@ bool CacheTexture::fitBitmap(const SkGlyph& glyph, uint32_t *retOriginX, uint32_
// Only enough space for this glyph - don't bother rounding up the width
roundedUpW = glyphW;
}
+
*retOriginX = cacheBlock->mX;
*retOriginY = cacheBlock->mY;
+
// If this is the remainder space, create a new cache block for this column. Otherwise,
// adjust the info about this column.
if (cacheBlock->mY == TEXTURE_BORDER_SIZE) {
@@ -127,6 +143,7 @@ bool CacheTexture::fitBitmap(const SkGlyph& glyph, uint32_t *retOriginX, uint32_
// Adjust remainder space dimensions
cacheBlock->mWidth -= roundedUpW;
cacheBlock->mX += roundedUpW;
+
if (mHeight - glyphH >= glyphH) {
// There's enough height left over to create a new CacheBlock
CacheBlock *newBlock = new CacheBlock(oldX, glyphH + TEXTURE_BORDER_SIZE,
@@ -148,16 +165,20 @@ bool CacheTexture::fitBitmap(const SkGlyph& glyph, uint32_t *retOriginX, uint32_
cacheBlock->mWidth, cacheBlock->mHeight);
#endif
}
+
if (cacheBlock->mHeight < fmin(glyphH, glyphW)) {
// If remaining space in this block is too small to be useful, remove it
mCacheBlocks = CacheBlock::removeBlock(mCacheBlocks, cacheBlock);
}
+
mDirty = true;
+ mNumGlyphs++;
+
#if DEBUG_FONT_RENDERER
ALOGD("fitBitmap: current block list:");
mCacheBlocks->output();
#endif
- ++mNumGlyphs;
+
return true;
}
cacheBlock = cacheBlock->mNext;
diff --git a/libs/hwui/font/CacheTexture.h b/libs/hwui/font/CacheTexture.h
index 7840d74..8d84a6b 100644
--- a/libs/hwui/font/CacheTexture.h
+++ b/libs/hwui/font/CacheTexture.h
@@ -50,8 +50,7 @@ struct CacheBlock {
CacheBlock* mPrev;
CacheBlock(uint16_t x, uint16_t y, uint16_t width, uint16_t height, bool empty = false):
- mX(x), mY(y), mWidth(width), mHeight(height), mNext(NULL), mPrev(NULL)
- {
+ mX(x), mY(y), mWidth(width), mHeight(height), mNext(NULL), mPrev(NULL) {
}
static CacheBlock* insertBlock(CacheBlock* head, CacheBlock *newBlock);
diff --git a/libs/hwui/font/Font.cpp b/libs/hwui/font/Font.cpp
index 0439875..fc6f0f1 100644
--- a/libs/hwui/font/Font.cpp
+++ b/libs/hwui/font/Font.cpp
@@ -41,12 +41,7 @@ Font::Font(FontRenderer* state, uint32_t fontId, float fontSize,
Font::~Font() {
- for (uint32_t ct = 0; ct < mState->mActiveFonts.size(); ct++) {
- if (mState->mActiveFonts[ct] == this) {
- mState->mActiveFonts.removeAt(ct);
- break;
- }
- }
+ mState->removeFont(this);
for (uint32_t i = 0; i < mCachedGlyphs.size(); i++) {
delete mCachedGlyphs.valueAt(i);
@@ -405,7 +400,7 @@ void Font::updateGlyphCache(SkPaint* paint, const SkGlyph& skiaGlyph, CachedGlyp
glyph->mBitmapMaxU = endX / (float) cacheWidth;
glyph->mBitmapMaxV = endY / (float) cacheHeight;
- mState->mUploadTexture = true;
+ mState->setTextureDirty();
}
CachedGlyphInfo* Font::cacheGlyph(SkPaint* paint, glyph_t glyph, bool precaching) {