surfaceflinger: simplify HWC buffer cache clean up
When a Layer is no longer connected, we destroy the associated HWC
layers on next call to SurfaceFlinger::rebuildLayerStacks or when
the Layer is destroyed. There is no need to listen to
onBuffersReleased. Besides, we need to perform the cleanup from the
main thread as we only talk to HWC process from the main thread.
While at it, move HWComposerBufferCache to its own files.
Bug: 35320590
Test: manual
Change-Id: Ifa32f24076b094c8fa9cda8572b03d5bfb8e0b93
diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp
index 7a4ace9..51984b7 100644
--- a/services/surfaceflinger/Layer.cpp
+++ b/services/surfaceflinger/Layer.cpp
@@ -276,16 +276,6 @@
}
}
-void Layer::onBuffersReleased() {
-#ifdef USE_HWC2
- Mutex::Autolock lock(mHwcBufferCacheMutex);
-
- for (auto info : mHwcBufferCaches) {
- info.second.clear();
- }
-#endif
-}
-
void Layer::onSidebandStreamChanged() {
if (android_atomic_release_cas(false, true, &mSidebandStreamChanged) == 0) {
// mSidebandStreamChanged was false
@@ -780,7 +770,8 @@
const auto& viewport = displayDevice->getViewport();
Region visible = tr.transform(visibleRegion.intersect(viewport));
auto hwcId = displayDevice->getHwcDisplayId();
- auto& hwcLayer = mHwcLayers[hwcId].layer;
+ auto& hwcInfo = mHwcLayers[hwcId];
+ auto& hwcLayer = hwcInfo.layer;
auto error = hwcLayer->setVisibleRegion(visible);
if (error != HWC2::Error::None) {
ALOGE("[%s] Failed to set visible region: %s (%d)", mName.string(),
@@ -809,7 +800,7 @@
}
// Client layers
- if (mHwcLayers[hwcId].forceClientComposition ||
+ if (hwcInfo.forceClientComposition ||
(mActiveBuffer != nullptr && mActiveBuffer->handle == nullptr)) {
ALOGV("[%s] Requesting Client composition", mName.string());
setCompositionType(hwcId, HWC2::Composition::Client);
@@ -858,11 +849,8 @@
uint32_t hwcSlot = 0;
buffer_handle_t hwcHandle = nullptr;
{
- Mutex::Autolock lock(mHwcBufferCacheMutex);
-
- auto& hwcBufferCache = mHwcBufferCaches[hwcId];
sp<GraphicBuffer> hwcBuffer;
- hwcBufferCache.getHwcBuffer(mActiveBufferSlot, mActiveBuffer,
+ hwcInfo.bufferCache.getHwcBuffer(mActiveBufferSlot, mActiveBuffer,
&hwcSlot, &hwcBuffer);
if (hwcBuffer != nullptr) {
hwcHandle = hwcBuffer->handle;