Merge "Small code cleanup in FontRenderer" into jb-mr1-dev
This commit is contained in:
@@ -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++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user