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

Commit 6b084d57 authored by Romain Guy's avatar Romain Guy Committed by Android (Google) Code Review
Browse files

Merge "Re-initialize the 9patch cache if cleared with onTrimMemory"

parents 1728bebe 7d9b1b3c
Loading
Loading
Loading
Loading
+19 −7
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ PatchCache::PatchCache(): mCache(LruCache<PatchDescription, Patch*>::kUnlimitedC
        mMaxSize = KB(DEFAULT_PATCH_CACHE_SIZE);
    }
    mSize = 0;
    mMeshBuffer = 0;
}

PatchCache::~PatchCache() {
@@ -47,12 +48,19 @@ PatchCache::~PatchCache() {
}

void PatchCache::init(Caches& caches) {
    bool created = false;
    if (!mMeshBuffer) {
        glGenBuffers(1, &mMeshBuffer);
        created = true;
    }

    caches.bindMeshBuffer(mMeshBuffer);
    caches.resetVertexPointers();

    if (created) {
        glBufferData(GL_ARRAY_BUFFER, mMaxSize, NULL, GL_DYNAMIC_DRAW);
    }
}

///////////////////////////////////////////////////////////////////////////////
// Caching
@@ -73,10 +81,15 @@ int PatchCache::PatchDescription::compare(const PatchCache::PatchDescription& lh
}

void PatchCache::clear() {
    glDeleteBuffers(1, &mMeshBuffer);
    clearCache();

    if (mMeshBuffer) {
        Caches::getInstance().unbindMeshBuffer();
        glDeleteBuffers(1, &mMeshBuffer);
        mMeshBuffer = 0;
        mSize = 0;
    }
}

void PatchCache::clearCache() {
    LruCache<PatchDescription, Patch*>::Iterator i(mCache);
@@ -106,9 +119,8 @@ const Patch* PatchCache::get(const AssetAtlas::Entry* entry,
        }

        if (vertices) {
            Caches& caches = Caches::getInstance();
            caches.bindMeshBuffer(mMeshBuffer);
            caches.resetVertexPointers();
            // This call ensures the VBO exists and that it is bound
            init(Caches::getInstance());

            // TODO: Simply remove the oldest items until we have enough room
            // This will require to keep a list of free blocks in the VBO
+2 −1
Original line number Diff line number Diff line
@@ -121,9 +121,10 @@ private:

    uint32_t mMaxSize;
    uint32_t mSize;
    LruCache<PatchDescription, Patch*> mCache;

    GLuint mMeshBuffer;

    LruCache<PatchDescription, Patch*> mCache;
}; // class PatchCache

}; // namespace uirenderer