Update snapshot changes flags when visibility changes

Layerhistory walks through all snapshots and checks the change
flags before updating its state. When a layer moves offscreen,
we update its snapshot but did not update the change flag. This
cl fixes this.

Bug: 345021645
Test: presubmit
Flag: EXEMPT bugfix

Change-Id: Icee06279f0fa8b0f4c0539e99dde8960ba3fab31
diff --git a/services/surfaceflinger/tests/unittests/LayerSnapshotTest.cpp b/services/surfaceflinger/tests/unittests/LayerSnapshotTest.cpp
index bd0accd..dedb292 100644
--- a/services/surfaceflinger/tests/unittests/LayerSnapshotTest.cpp
+++ b/services/surfaceflinger/tests/unittests/LayerSnapshotTest.cpp
@@ -213,6 +213,17 @@
     UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 13, 2});
 }
 
+TEST_F(LayerSnapshotTest, offscreenLayerSnapshotIsInvisible) {
+    EXPECT_EQ(getSnapshot(111)->isVisible, true);
+
+    reparentLayer(11, UNASSIGNED_LAYER_ID);
+    destroyLayerHandle(11);
+    UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 13, 2});
+
+    EXPECT_EQ(getSnapshot(111)->isVisible, false);
+    EXPECT_TRUE(getSnapshot(111)->changes.test(RequestedLayerState::Changes::Visibility));
+}
+
 // relative tests
 TEST_F(LayerSnapshotTest, RelativeParentCanHideChild) {
     reparentRelativeLayer(13, 11);