Skip to content

Commit 99a6ddd

Browse files
author
Romain Guy
committed
Forget the name of a texture after freeing
Bug #6408362 FontRenderer allocates large font textures when more room is needed to store all the glyphs used by an application. Thse large textures are the first to be freed when memory needs to be reclaimed by the system. When freeing a texture, the renderer would however not set the texture name to an invalid name, leading future allocations to be performed on the same texture name. That name could have by then be recycled by the driver and returned by a call to glGenTexture and used to create an entirely different texture. This would cause the font renderer to point to the wrong texture, thus leading to the "corruptions." Change-Id: I8a1e80e5b79e8f21d1baf5320c090df4f2066cd4
1 parent 9d9758a commit 99a6ddd

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

libs/hwui/FontRenderer.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,7 @@ void FontRenderer::deallocateTextureMemory(CacheTexture *cacheTexture) {
555555
glDeleteTextures(1, &cacheTexture->mTextureId);
556556
delete[] cacheTexture->mTexture;
557557
cacheTexture->mTexture = NULL;
558+
cacheTexture->mTextureId = 0;
558559
}
559560
}
560561

@@ -589,7 +590,13 @@ void FontRenderer::allocateTextureMemory(CacheTexture* cacheTexture) {
589590
int height = cacheTexture->mHeight;
590591

591592
cacheTexture->mTexture = new uint8_t[width * height];
593+
#if DEBUG_FONT_RENDERER
592594
memset(cacheTexture->mTexture, 0, width * height * sizeof(uint8_t));
595+
#endif
596+
597+
if (!cacheTexture->mTextureId) {
598+
glGenTextures(1, &cacheTexture->mTextureId);
599+
}
593600

594601
glBindTexture(GL_TEXTURE_2D, cacheTexture->mTextureId);
595602
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
@@ -680,11 +687,8 @@ void FontRenderer::cacheBitmap(const SkGlyph& glyph, CachedGlyphInfo* cachedGlyp
680687
}
681688

682689
CacheTexture* FontRenderer::createCacheTexture(int width, int height, bool allocate) {
683-
GLuint textureId;
684-
glGenTextures(1, &textureId);
685-
686690
uint8_t* textureMemory = NULL;
687-
CacheTexture* cacheTexture = new CacheTexture(textureMemory, textureId, width, height);
691+
CacheTexture* cacheTexture = new CacheTexture(textureMemory, width, height);
688692

689693
if (allocate) {
690694
allocateTextureMemory(cacheTexture);

libs/hwui/FontRenderer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ class FontRenderer;
6262
class CacheTexture {
6363
public:
6464
CacheTexture() { }
65-
CacheTexture(uint8_t* texture, GLuint textureId, uint16_t width, uint16_t height) :
66-
mTexture(texture), mTextureId(textureId), mWidth(width), mHeight(height),
65+
CacheTexture(uint8_t* texture, uint16_t width, uint16_t height) :
66+
mTexture(texture), mTextureId(0), mWidth(width), mHeight(height),
6767
mLinearFiltering(false) { }
6868
~CacheTexture() {
6969
if (mTexture) {

0 commit comments

Comments
 (0)