[sf] Set visible regions change flag when layer starts drawing
If a layer state changes so it has a buffer or an effect like
color then, update the flags to indicate that visiblity of a
snapshot has changed. This will mark the visible regions
flag in CE args and force CE to rebuild its layer stack.
Without this flag, there was a scenario where CE
would get a null snapshot and crash.
Also crash early with traces if we ever pass a null snapshot to
CE.
Test: presubmit
Bug: 238781169, 295069311, 294889236
Change-Id: I355502fbe7f1be38c46a5ed25233b6b07c6b4eeb
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index fa07001..32bb46c 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -134,6 +134,7 @@
#include "FrontEnd/LayerCreationArgs.h"
#include "FrontEnd/LayerHandle.h"
#include "FrontEnd/LayerLifecycleManager.h"
+#include "FrontEnd/LayerLog.h"
#include "FrontEnd/LayerSnapshot.h"
#include "HdrLayerInfoReporter.h"
#include "Layer.h"
@@ -2620,6 +2621,23 @@
constexpr bool kCursorOnly = false;
const auto layers = moveSnapshotsToCompositionArgs(refreshArgs, kCursorOnly);
+ if (mLayerLifecycleManagerEnabled && !refreshArgs.updatingGeometryThisFrame) {
+ for (const auto& [token, display] : FTL_FAKE_GUARD(mStateLock, mDisplays)) {
+ auto compositionDisplay = display->getCompositionDisplay();
+ if (!compositionDisplay->getState().isEnabled) continue;
+ for (auto outputLayer : compositionDisplay->getOutputLayersOrderedByZ()) {
+ LLOG_ALWAYS_FATAL_WITH_TRACE_IF(outputLayer->getLayerFE().getCompositionState() ==
+ nullptr,
+ "Output layer %s for display %s %" PRIu64
+ " has a null "
+ "snapshot.",
+ outputLayer->getLayerFE().getDebugName(),
+ compositionDisplay->getName().c_str(),
+ compositionDisplay->getId().value);
+ }
+ }
+ }
+
mCompositionEngine->present(refreshArgs);
moveSnapshotsFromCompositionArgs(refreshArgs, layers);