Merge "Fix two memory leaks Bug #6408362" into jb-dev
This commit is contained in:
@@ -540,9 +540,11 @@ void FontRenderer::flushAllAndInvalidate() {
|
|||||||
issueDrawCommand();
|
issueDrawCommand();
|
||||||
mCurrentQuadIndex = 0;
|
mCurrentQuadIndex = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint32_t i = 0; i < mActiveFonts.size(); i++) {
|
for (uint32_t i = 0; i < mActiveFonts.size(); i++) {
|
||||||
mActiveFonts[i]->invalidateTextureCache();
|
mActiveFonts[i]->invalidateTextureCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint32_t i = 0; i < mCacheLines.size(); i++) {
|
for (uint32_t i = 0; i < mCacheLines.size(); i++) {
|
||||||
mCacheLines[i]->mCurrentCol = 0;
|
mCacheLines[i]->mCurrentCol = 0;
|
||||||
}
|
}
|
||||||
@@ -551,7 +553,7 @@ void FontRenderer::flushAllAndInvalidate() {
|
|||||||
void FontRenderer::deallocateTextureMemory(CacheTexture *cacheTexture) {
|
void FontRenderer::deallocateTextureMemory(CacheTexture *cacheTexture) {
|
||||||
if (cacheTexture && cacheTexture->mTexture) {
|
if (cacheTexture && cacheTexture->mTexture) {
|
||||||
glDeleteTextures(1, &cacheTexture->mTextureId);
|
glDeleteTextures(1, &cacheTexture->mTextureId);
|
||||||
delete cacheTexture->mTexture;
|
delete[] cacheTexture->mTexture;
|
||||||
cacheTexture->mTexture = NULL;
|
cacheTexture->mTexture = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -582,11 +584,13 @@ void FontRenderer::flushLargeCaches() {
|
|||||||
deallocateTextureMemory(mCacheTexture512);
|
deallocateTextureMemory(mCacheTexture512);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FontRenderer::allocateTextureMemory(CacheTexture *cacheTexture) {
|
void FontRenderer::allocateTextureMemory(CacheTexture* cacheTexture) {
|
||||||
int width = cacheTexture->mWidth;
|
int width = cacheTexture->mWidth;
|
||||||
int height = cacheTexture->mHeight;
|
int height = cacheTexture->mHeight;
|
||||||
|
|
||||||
cacheTexture->mTexture = new uint8_t[width * height];
|
cacheTexture->mTexture = new uint8_t[width * height];
|
||||||
memset(cacheTexture->mTexture, 0, width * height * sizeof(uint8_t));
|
memset(cacheTexture->mTexture, 0, width * height * sizeof(uint8_t));
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, cacheTexture->mTextureId);
|
glBindTexture(GL_TEXTURE_2D, cacheTexture->mTextureId);
|
||||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||||
// Initialize texture dimensions
|
// Initialize texture dimensions
|
||||||
@@ -654,11 +658,12 @@ void FontRenderer::cacheBitmap(const SkGlyph& glyph, CachedGlyphInfo* cachedGlyp
|
|||||||
|
|
||||||
uint32_t cacheWidth = cacheLine->mMaxWidth;
|
uint32_t cacheWidth = cacheLine->mMaxWidth;
|
||||||
|
|
||||||
CacheTexture *cacheTexture = cacheLine->mCacheTexture;
|
CacheTexture* cacheTexture = cacheLine->mCacheTexture;
|
||||||
if (cacheTexture->mTexture == NULL) {
|
if (!cacheTexture->mTexture) {
|
||||||
// Large-glyph texture memory is allocated only as needed
|
// Large-glyph texture memory is allocated only as needed
|
||||||
allocateTextureMemory(cacheTexture);
|
allocateTextureMemory(cacheTexture);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t* cacheBuffer = cacheTexture->mTexture;
|
uint8_t* cacheBuffer = cacheTexture->mTexture;
|
||||||
uint8_t* bitmapBuffer = (uint8_t*) glyph.fImage;
|
uint8_t* bitmapBuffer = (uint8_t*) glyph.fImage;
|
||||||
unsigned int stride = glyph.rowBytes();
|
unsigned int stride = glyph.rowBytes();
|
||||||
@@ -677,32 +682,40 @@ void FontRenderer::cacheBitmap(const SkGlyph& glyph, CachedGlyphInfo* cachedGlyp
|
|||||||
CacheTexture* FontRenderer::createCacheTexture(int width, int height, bool allocate) {
|
CacheTexture* FontRenderer::createCacheTexture(int width, int height, bool allocate) {
|
||||||
GLuint textureId;
|
GLuint textureId;
|
||||||
glGenTextures(1, &textureId);
|
glGenTextures(1, &textureId);
|
||||||
uint8_t* textureMemory = NULL;
|
|
||||||
|
|
||||||
|
uint8_t* textureMemory = NULL;
|
||||||
CacheTexture* cacheTexture = new CacheTexture(textureMemory, textureId, width, height);
|
CacheTexture* cacheTexture = new CacheTexture(textureMemory, textureId, width, height);
|
||||||
|
|
||||||
if (allocate) {
|
if (allocate) {
|
||||||
allocateTextureMemory(cacheTexture);
|
allocateTextureMemory(cacheTexture);
|
||||||
}
|
}
|
||||||
|
|
||||||
return cacheTexture;
|
return cacheTexture;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FontRenderer::initTextTexture() {
|
void FontRenderer::initTextTexture() {
|
||||||
|
for (uint32_t i = 0; i < mCacheLines.size(); i++) {
|
||||||
|
delete mCacheLines[i];
|
||||||
|
}
|
||||||
mCacheLines.clear();
|
mCacheLines.clear();
|
||||||
|
|
||||||
|
if (mCacheTextureSmall) {
|
||||||
|
delete mCacheTextureSmall;
|
||||||
|
delete mCacheTexture128;
|
||||||
|
delete mCacheTexture256;
|
||||||
|
delete mCacheTexture512;
|
||||||
|
}
|
||||||
|
|
||||||
// Next, use other, separate caches for large glyphs.
|
// Next, use other, separate caches for large glyphs.
|
||||||
uint16_t maxWidth = 0;
|
uint16_t maxWidth = 0;
|
||||||
if (Caches::hasInstance()) {
|
if (Caches::hasInstance()) {
|
||||||
maxWidth = Caches::getInstance().maxTextureSize;
|
maxWidth = Caches::getInstance().maxTextureSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (maxWidth > MAX_TEXT_CACHE_WIDTH || maxWidth == 0) {
|
if (maxWidth > MAX_TEXT_CACHE_WIDTH || maxWidth == 0) {
|
||||||
maxWidth = MAX_TEXT_CACHE_WIDTH;
|
maxWidth = MAX_TEXT_CACHE_WIDTH;
|
||||||
}
|
}
|
||||||
if (mCacheTextureSmall != NULL) {
|
|
||||||
delete mCacheTextureSmall;
|
|
||||||
delete mCacheTexture128;
|
|
||||||
delete mCacheTexture256;
|
|
||||||
delete mCacheTexture512;
|
|
||||||
}
|
|
||||||
mCacheTextureSmall = createCacheTexture(mSmallCacheWidth, mSmallCacheHeight, true);
|
mCacheTextureSmall = createCacheTexture(mSmallCacheWidth, mSmallCacheHeight, true);
|
||||||
mCacheTexture128 = createCacheTexture(maxWidth, 256, false);
|
mCacheTexture128 = createCacheTexture(maxWidth, 256, false);
|
||||||
mCacheTexture256 = createCacheTexture(maxWidth, 256, false);
|
mCacheTexture256 = createCacheTexture(maxWidth, 256, false);
|
||||||
|
|||||||
@@ -61,15 +61,15 @@ class FontRenderer;
|
|||||||
|
|
||||||
class CacheTexture {
|
class CacheTexture {
|
||||||
public:
|
public:
|
||||||
CacheTexture(){}
|
CacheTexture() { }
|
||||||
CacheTexture(uint8_t* texture, GLuint textureId, uint16_t width, uint16_t height) :
|
CacheTexture(uint8_t* texture, GLuint textureId, uint16_t width, uint16_t height) :
|
||||||
mTexture(texture), mTextureId(textureId), mWidth(width), mHeight(height),
|
mTexture(texture), mTextureId(textureId), mWidth(width), mHeight(height),
|
||||||
mLinearFiltering(false) {}
|
mLinearFiltering(false) { }
|
||||||
~CacheTexture() {
|
~CacheTexture() {
|
||||||
if (mTexture != NULL) {
|
if (mTexture) {
|
||||||
delete[] mTexture;
|
delete[] mTexture;
|
||||||
}
|
}
|
||||||
if (mTextureId != 0) {
|
if (mTextureId) {
|
||||||
glDeleteTextures(1, &mTextureId);
|
glDeleteTextures(1, &mTextureId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -90,7 +90,7 @@ public:
|
|||||||
mCurrentRow(currentRow),
|
mCurrentRow(currentRow),
|
||||||
mCurrentCol(currentCol),
|
mCurrentCol(currentCol),
|
||||||
mDirty(false),
|
mDirty(false),
|
||||||
mCacheTexture(cacheTexture){
|
mCacheTexture(cacheTexture) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool fitBitmap(const SkGlyph& glyph, uint32_t *retOriginX, uint32_t *retOriginY);
|
bool fitBitmap(const SkGlyph& glyph, uint32_t *retOriginX, uint32_t *retOriginY);
|
||||||
|
|||||||
Reference in New Issue
Block a user