[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
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index f8745f7..8ef03fb 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -590,7 +590,11 @@
}
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 @@
{
std::lock_guard lock(mTexturePoolMutex);
- const size_t refillCount = mTexturePoolSize - mTexturePool.size();
- if (refillCount > 0) {
+ if (mTexturePool.size() < mTexturePoolSize) {
+ const size_t refillCount = mTexturePoolSize - mTexturePool.size();
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());
}
}