[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/tests/unittests/LayerLifecycleManagerTest.cpp b/services/surfaceflinger/tests/unittests/LayerLifecycleManagerTest.cpp
index e3c7837..d65277a 100644
--- a/services/surfaceflinger/tests/unittests/LayerLifecycleManagerTest.cpp
+++ b/services/surfaceflinger/tests/unittests/LayerLifecycleManagerTest.cpp
@@ -389,4 +389,52 @@
listener->expectLayersDestroyed({1, bgLayerId});
}
+TEST_F(LayerLifecycleManagerTest, blurSetsVisibilityChangeFlag) {
+ // clear default color on layer so we start with a layer that does not draw anything.
+ setColor(1, {-1.f, -1.f, -1.f});
+ mLifecycleManager.commitChanges();
+
+ // layer has something to draw
+ setBackgroundBlurRadius(1, 2);
+ EXPECT_TRUE(
+ mLifecycleManager.getGlobalChanges().test(RequestedLayerState::Changes::Visibility));
+ mLifecycleManager.commitChanges();
+
+ // layer still has something to draw, so visibility shouldn't change
+ setBackgroundBlurRadius(1, 3);
+ EXPECT_FALSE(
+ mLifecycleManager.getGlobalChanges().test(RequestedLayerState::Changes::Visibility));
+ mLifecycleManager.commitChanges();
+
+ // layer has nothing to draw
+ setBackgroundBlurRadius(1, 0);
+ EXPECT_TRUE(
+ mLifecycleManager.getGlobalChanges().test(RequestedLayerState::Changes::Visibility));
+ mLifecycleManager.commitChanges();
+}
+
+TEST_F(LayerLifecycleManagerTest, colorSetsVisibilityChangeFlag) {
+ // clear default color on layer so we start with a layer that does not draw anything.
+ setColor(1, {-1.f, -1.f, -1.f});
+ mLifecycleManager.commitChanges();
+
+ // layer has something to draw
+ setColor(1, {2.f, 3.f, 4.f});
+ EXPECT_TRUE(
+ mLifecycleManager.getGlobalChanges().test(RequestedLayerState::Changes::Visibility));
+ mLifecycleManager.commitChanges();
+
+ // layer still has something to draw, so visibility shouldn't change
+ setColor(1, {0.f, 0.f, 0.f});
+ EXPECT_FALSE(
+ mLifecycleManager.getGlobalChanges().test(RequestedLayerState::Changes::Visibility));
+ mLifecycleManager.commitChanges();
+
+ // layer has nothing to draw
+ setColor(1, {-1.f, -1.f, -1.f});
+ EXPECT_TRUE(
+ mLifecycleManager.getGlobalChanges().test(RequestedLayerState::Changes::Visibility));
+ mLifecycleManager.commitChanges();
+}
+
} // namespace android::surfaceflinger::frontend