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

Commit 9e10841c authored by Romain Guy's avatar Romain Guy
Browse files

Correctly remove unused paths from the cache.

Change-Id: I41d9334dcd9871634037344ab49bf69383498161
parent 820b9e0d
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
@@ -127,8 +127,10 @@ DisplayList::DisplayList(const DisplayListRenderer& recorder) {
    }

    mPathHeap = recorder.mPathHeap;
    if (mPathHeap) {
        mPathHeap->safeRef();
    }
}

DisplayList::~DisplayList() {
    sk_free((void*) mReader.base());
@@ -155,8 +157,13 @@ DisplayList::~DisplayList() {
    }
    mMatrices.clear();

    if (mPathHeap) {
        for (int i = 0; i < mPathHeap->count(); i++) {
            caches.pathCache.remove(&(*mPathHeap)[i]);
        }
        mPathHeap->safeUnref();
    }
}

void DisplayList::init() {
    mPathHeap = NULL;
+15 −4
Original line number Diff line number Diff line
@@ -92,10 +92,13 @@ void PathCache::setMaxSize(uint32_t maxSize) {
///////////////////////////////////////////////////////////////////////////////

void PathCache::operator()(PathCacheEntry& path, PathTexture*& texture) {
    if (texture) {
        const uint32_t size = texture->width * texture->height;
        mSize -= size;

    if (texture) {
        PATH_LOGD("PathCache::callback: delete path: name, size, mSize = %d, %d, %d",
                texture->id, size, mSize);

        glDeleteTextures(1, &texture->id);
        delete texture;
    }
@@ -107,11 +110,17 @@ void PathCache::operator()(PathCacheEntry& path, PathTexture*& texture) {

void PathCache::remove(SkPath* path) {
    Mutex::Autolock _l(mLock);

    // TODO: Linear search...
    Vector<uint32_t> pathsToRemove;
    for (uint32_t i = 0; i < mCache.size(); i++) {
        if (mCache.getKeyAt(i).path == path) {
            mCache.removeAt(i);
            pathsToRemove.push(i);
        }
    }

    for (size_t i = 0; i < pathsToRemove.size(); i++) {
        mCache.removeAt(pathsToRemove.itemAt(i));
    }
}

@@ -188,6 +197,8 @@ PathTexture* PathCache::addTexture(const PathCacheEntry& entry,
    if (size < mMaxSize) {
        mLock.lock();
        mSize += size;
        PATH_LOGD("PathCache::get: create path: name, size, mSize = %d, %d, %d",
                texture->id, size, mSize);
        mCache.put(entry, texture);
        mLock.unlock();
    } else {
+18 −0
Original line number Diff line number Diff line
@@ -28,6 +28,24 @@
namespace android {
namespace uirenderer {

///////////////////////////////////////////////////////////////////////////////
// Defines
///////////////////////////////////////////////////////////////////////////////

// Debug
#define DEBUG_PATHS 0

// Debug
#if DEBUG_PATHS
    #define PATH_LOGD(...) LOGD(__VA_ARGS__)
#else
    #define PATH_LOGD(...)
#endif

///////////////////////////////////////////////////////////////////////////////
// Classes
///////////////////////////////////////////////////////////////////////////////

/**
 * Describe a path in the path cache.
 */
+4 −4
Original line number Diff line number Diff line
@@ -94,8 +94,8 @@ void TextureCache::operator()(SkBitmap*& bitmap, Texture*& texture) {
    // This will be called already locked
    if (texture) {
        mSize -= texture->bitmapSize;
        TEXTURE_LOGD("TextureCache::callback: removed size, mSize = %d, %d",
                texture->bitmapSize, mSize);
        TEXTURE_LOGD("TextureCache::callback: name, removed size, mSize = %d, %d, %d",
                texture->id, texture->bitmapSize, mSize);
        glDeleteTextures(1, &texture->id);
        delete texture;
    }
@@ -133,8 +133,8 @@ Texture* TextureCache::get(SkBitmap* bitmap) {
        if (size < mMaxSize) {
            mLock.lock();
            mSize += size;
            TEXTURE_LOGD("TextureCache::get: create texture(0x%p): size, mSize = %d, %d",
                     bitmap, size, mSize);
            TEXTURE_LOGD("TextureCache::get: create texture(%p): name, size, mSize = %d, %d, %d",
                     bitmap, texture->id, size, mSize);
            mCache.put(bitmap, texture);
            mLock.unlock();
        } else {
+4 −0
Original line number Diff line number Diff line
@@ -39,6 +39,10 @@ namespace uirenderer {
    #define TEXTURE_LOGD(...)
#endif

///////////////////////////////////////////////////////////////////////////////
// Classes
///////////////////////////////////////////////////////////////////////////////

/**
 * A simple LRU texture cache. The cache has a maximum size expressed in bytes.
 * Any texture added to the cache causing the cache to grow beyond the maximum