diff options
Diffstat (limited to 'libs/hwui/font')
-rw-r--r-- | libs/hwui/font/CacheTexture.cpp | 23 | ||||
-rw-r--r-- | libs/hwui/font/CacheTexture.h | 3 | ||||
-rw-r--r-- | libs/hwui/font/Font.cpp | 9 |
3 files changed, 25 insertions, 10 deletions
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) { |