Merge "SF: Clear mCompositionInfo before recomputing visible layers"
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index ae0a957..af73346 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -1679,8 +1679,6 @@
mDrawingState.colorMatrixChanged = false;
for (const auto& [token, display] : mDisplays) {
- getBE().mCompositionInfo[token].clear();
-
for (auto& layer : display->getVisibleLayersSortedByZ()) {
const auto displayId = display->getId();
layer->getBE().compositionInfo.compositionType = layer->getCompositionType(displayId);
@@ -1964,6 +1962,17 @@
ATRACE_CALL();
ALOGV("rebuildLayerStacks");
+ // We need to clear these out now as these may be holding on to a
+ // HWC2::Layer reference at the same time as the LayerBE::HWCInfo structure
+ // also holds a reference. When the set of visible layers is recomputed,
+ // some layers may be destroyed if the only thing keeping them alive was
+ // that list of visible layers associated with each display. The layer
+ // destruction code asserts that the HWC2::Layer is properly destroyed, but
+ // that doesn't happen if SurfaceFlingerBE::mCompositionInfo keeps it alive.
+ for (const auto& [token, display] : mDisplays) {
+ getBE().mCompositionInfo[token].clear();
+ }
+
// rebuild the visible layer list per screen
if (CC_UNLIKELY(mVisibleRegionsDirty)) {
ATRACE_NAME("rebuildLayerStacks VR Dirty");