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

Commit 9aa8e3d4 authored by Dan Stoza's avatar Dan Stoza Committed by Sudheer Shanka
Browse files

[sf] Move texture deletion to main thread via pool

Places deleted texture names into the texture pool, and adds code to
postComposition to either generate textures if the pool is low or delete
them if it is overfilled.

Bug: 129393280
Test: Manual, systrace with gesture nav and observe deferred deletions
Test: libsurfaceflinger_unittest, which was updated to pass
Change-Id: I683ad5b817a29f679def22f0b746223aac3241d9
parent c1a72e00
Loading
Loading
Loading
Loading
+13 −3
Original line number Diff line number Diff line
@@ -590,7 +590,11 @@ uint32_t SurfaceFlinger::getNewTexture() {
}

void SurfaceFlinger::deleteTextureAsync(uint32_t texture) {
    postMessageAsync(new LambdaMessage([=] { getRenderEngine().deleteTextures(1, &texture); }));
    std::lock_guard lock(mTexturePoolMutex);
    // We don't change the pool size, so the fix-up logic in postComposition will decide whether
    // to actually delete this or not based on mTexturePoolSize
    mTexturePool.push_back(texture);
    ATRACE_INT("TexturePoolSize", mTexturePool.size());
}

// Do not call property_set on main thread which will be blocked by init
@@ -2078,12 +2082,18 @@ void SurfaceFlinger::postComposition()

    {
        std::lock_guard lock(mTexturePoolMutex);
        if (mTexturePool.size() < mTexturePoolSize) {
            const size_t refillCount = mTexturePoolSize - mTexturePool.size();
        if (refillCount > 0) {
            const size_t offset = mTexturePool.size();
            mTexturePool.resize(mTexturePoolSize);
            getRenderEngine().genTextures(refillCount, mTexturePool.data() + offset);
            ATRACE_INT("TexturePoolSize", mTexturePool.size());
        } else if (mTexturePool.size() > mTexturePoolSize) {
            const size_t deleteCount = mTexturePool.size() - mTexturePoolSize;
            const size_t offset = mTexturePoolSize;
            getRenderEngine().deleteTextures(deleteCount, mTexturePool.data() + offset);
            mTexturePool.resize(mTexturePoolSize);
            ATRACE_INT("TexturePoolSize", mTexturePool.size());
        }
    }

+1 −1
Original line number Diff line number Diff line
@@ -856,7 +856,7 @@ struct BufferLayerVariant : public BaseLayerVariant<LayerProperties> {
    }

    static void cleanupInjectedLayers(CompositionTest* test) {
        EXPECT_CALL(*test->mMessageQueue, postMessage(_, 0)).Times(2);
        EXPECT_CALL(*test->mMessageQueue, postMessage(_, 0)).Times(1);
        Base::cleanupInjectedLayers(test);
    }