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

Commit 00783be8 authored by sergeyv's avatar sergeyv
Browse files

Don't count hw bitmap's textures in TextureCache

Test: refactoring CL.
bug: 34751775
Change-Id: I0f7c8338817329a5c75cec4e8b944779587d7b7f
parent df9a4f9a
Loading
Loading
Loading
Loading
+31 −12
Original line number Diff line number Diff line
@@ -101,9 +101,31 @@ bool TextureCache::canMakeTextureFromBitmap(Bitmap* bitmap) {
    return true;
}

Texture* TextureCache::createTexture(Bitmap* bitmap) {
     Texture* texture = new Texture(Caches::getInstance());
     texture->bitmapSize = bitmap->rowBytes() * bitmap->height();
     texture->generation = bitmap->getGenerationID();
     texture->upload(*bitmap);
     return texture;
}

// Returns a prepared Texture* that either is already in the cache or can fit
// in the cache (and is thus added to the cache)
Texture* TextureCache::getCachedTexture(Bitmap* bitmap) {
    if (bitmap->isHardware()) {
        auto textureIterator = mHardwareTextures.find(bitmap->getStableID());
        if (textureIterator == mHardwareTextures.end()) {
            Texture*  texture = createTexture(bitmap);
            mHardwareTextures.insert(std::make_pair(bitmap->getStableID(),
                    std::unique_ptr<Texture>(texture)));
            if (mDebugEnabled) {
                ALOGD("Texture created for hw bitmap size = %d", texture->bitmapSize);
            }
            return texture;
        }
        return textureIterator->second.get();
    }

    Texture* texture = mCache.get(bitmap->getStableID());

    if (!texture) {
@@ -124,11 +146,7 @@ Texture* TextureCache::getCachedTexture(Bitmap* bitmap) {
        }

        if (canCache) {
            texture = new Texture(Caches::getInstance());
            texture->bitmapSize = size;
            texture->generation = bitmap->getGenerationID();
            texture->upload(*bitmap);

            texture = createTexture(bitmap);
            mSize += size;
            TEXTURE_LOGD("TextureCache::get: create texture(%p): name, size, mSize = %d, %d, %d",
                     bitmap, texture->id, size, mSize);
@@ -166,12 +184,7 @@ Texture* TextureCache::get(Bitmap* bitmap) {
        if (!canMakeTextureFromBitmap(bitmap)) {
            return nullptr;
        }

        const uint32_t size = bitmap->rowBytes() * bitmap->height();
        texture = new Texture(Caches::getInstance());
        texture->bitmapSize = size;
        texture->upload(*bitmap);
        texture->generation = bitmap->getGenerationID();
        texture = createTexture(bitmap);
        texture->cleanup = true;
    }

@@ -188,7 +201,13 @@ void TextureCache::clearGarbage() {
    size_t count = mGarbage.size();
    for (size_t i = 0; i < count; i++) {
        uint32_t pixelRefId = mGarbage[i];
        auto hardwareIter = mHardwareTextures.find(pixelRefId);
        if (hardwareIter == mHardwareTextures.end()) {
            mCache.remove(pixelRefId);
        } else {
            hardwareIter->second->deleteTexture();
            mHardwareTextures.erase(hardwareIter);
        }
    }
    mGarbage.clear();
}
+2 −0
Original line number Diff line number Diff line
@@ -125,6 +125,7 @@ private:
    bool canMakeTextureFromBitmap(Bitmap* bitmap);

    Texture* getCachedTexture(Bitmap* bitmap);
    Texture* createTexture(Bitmap* bitmap);

    LruCache<uint32_t, Texture*> mCache;

@@ -137,6 +138,7 @@ private:
    bool mDebugEnabled;

    std::vector<uint32_t> mGarbage;
    std::unordered_map<uint32_t, std::unique_ptr<Texture>> mHardwareTextures;
    mutable Mutex mLock;
}; // class TextureCache