Clear HWC layer buffer slots by assiging a placeholder buffer
When buffers are discarded by SurfaceFlinger clients, the memory should
be free'd immediately. This includes clearing references to them from
within the implementation of Composer HAL, specifically in cache slots
associated with the layer.
Since there is no HAL API to clear the slot directly, prior to writing
any other buffer to the layer, we set the layer's buffer multiple times
to a placeholder buffer, using each of the slot numbers that need to be
cleared. This replaces the reference to the client-discarded buffer
inside Composer HAL with a reference to the placeholder buffer, causing
the reference count to drop, allowing the buffer memory to be freed.
Bug: 258196272
Test: atest OutputLayerUncacheBufferTest
Change-Id: Id85482e8859490566f0eedbd8d8729c47a7349fb
diff --git a/services/surfaceflinger/CompositionEngine/src/HwcBufferCache.cpp b/services/surfaceflinger/CompositionEngine/src/HwcBufferCache.cpp
index d64fd57..e2c0acf 100644
--- a/services/surfaceflinger/CompositionEngine/src/HwcBufferCache.cpp
+++ b/services/surfaceflinger/CompositionEngine/src/HwcBufferCache.cpp
@@ -22,7 +22,7 @@
namespace android::compositionengine::impl {
HwcBufferCache::HwcBufferCache() {
- for (uint32_t i = 0; i < kMaxLayerBufferCount; i++) {
+ for (uint32_t i = kMaxLayerBufferCount; i-- > 0;) {
mFreeSlots.push(i);
}
}