Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0b1dd98a authored by Romain Guy's avatar Romain Guy Committed by The Android Automerger
Browse files

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

Conflicts:

	libs/hwui/FontRenderer.cpp
	libs/hwui/FontRenderer.h
parent d15ae539
Loading
Loading
Loading
Loading
+9 −3
Original line number Diff line number Diff line
@@ -553,6 +553,7 @@ void FontRenderer::deallocateTextureMemory(CacheTexture *cacheTexture) {
        glDeleteTextures(1, &cacheTexture->mTextureId);
        delete cacheTexture->mTexture;
        cacheTexture->mTexture = NULL;
        cacheTexture->mTextureId = 0;
    }
}

@@ -586,7 +587,14 @@ void FontRenderer::allocateTextureMemory(CacheTexture *cacheTexture) {
    int width = cacheTexture->mWidth;
    int height = cacheTexture->mHeight;
    cacheTexture->mTexture = new uint8_t[width * height];
#if DEBUG_FONT_RENDERER
    memset(cacheTexture->mTexture, 0, width * height * sizeof(uint8_t));
#endif

    if (!cacheTexture->mTextureId) {
        glGenTextures(1, &cacheTexture->mTextureId);
    }

    glBindTexture(GL_TEXTURE_2D, cacheTexture->mTextureId);
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    // Initialize texture dimensions
@@ -675,11 +683,9 @@ void FontRenderer::cacheBitmap(const SkGlyph& glyph, CachedGlyphInfo* cachedGlyp
}

CacheTexture* FontRenderer::createCacheTexture(int width, int height, bool allocate) {
    GLuint textureId;
    glGenTextures(1, &textureId);
    uint8_t* textureMemory = NULL;
    CacheTexture* cacheTexture = new CacheTexture(textureMemory, width, height);

    CacheTexture* cacheTexture = new CacheTexture(textureMemory, textureId, width, height);
    if (allocate) {
        allocateTextureMemory(cacheTexture);
    }
+3 −3
Original line number Diff line number Diff line
@@ -60,8 +60,8 @@ class FontRenderer;
class CacheTexture {
public:
    CacheTexture(){}
    CacheTexture(uint8_t* texture, GLuint textureId, uint16_t width, uint16_t height) :
        mTexture(texture), mTextureId(textureId), mWidth(width), mHeight(height),
    CacheTexture(uint8_t* texture, uint16_t width, uint16_t height) :
            mTexture(texture), mTextureId(0), mWidth(width), mHeight(height),
            mLinearFiltering(false) { }
    ~CacheTexture() {
        if (mTexture != NULL) {