Merge "Revert "SF: Use strong pointers to Layer when moving snapshot""
diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp
index be5fffc..8a3e784 100644
--- a/services/surfaceflinger/Layer.cpp
+++ b/services/surfaceflinger/Layer.cpp
@@ -3973,17 +3973,14 @@
 }
 
 LayerSnapshotGuard::LayerSnapshotGuard(Layer* layer) : mLayer(layer) {
-    LOG_ALWAYS_FATAL_IF(!mLayer, "LayerSnapshotGuard received a null layer.");
-    mLayer->mLayerFE->mSnapshot = std::move(mLayer->mSnapshot);
-    LOG_ALWAYS_FATAL_IF(!mLayer->mLayerFE->mSnapshot,
-                        "LayerFE snapshot null after taking ownership from layer");
+    if (mLayer) {
+        mLayer->mLayerFE->mSnapshot = std::move(mLayer->mSnapshot);
+    }
 }
 
 LayerSnapshotGuard::~LayerSnapshotGuard() {
     if (mLayer) {
         mLayer->mSnapshot = std::move(mLayer->mLayerFE->mSnapshot);
-        LOG_ALWAYS_FATAL_IF(!mLayer->mSnapshot,
-                            "Layer snapshot null after taking ownership from LayerFE");
     }
 }
 
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index 4365b64..2c510d7 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -2190,14 +2190,13 @@
 
     refreshArgs.updatingOutputGeometryThisFrame = mVisibleRegionsDirty;
     refreshArgs.updatingGeometryThisFrame = mGeometryDirty.exchange(false) || mVisibleRegionsDirty;
-    std::vector<sp<Layer>> layers;
+    std::vector<Layer*> layers;
 
     mDrawingState.traverseInZOrder([&refreshArgs, &layers](Layer* layer) {
-        auto strongLayer = sp<Layer>::fromExisting(layer);
         if (auto layerFE = layer->getCompositionEngineLayerFE()) {
             layer->updateSnapshot(refreshArgs.updatingGeometryThisFrame);
             refreshArgs.layers.push_back(layerFE);
-            layers.push_back(std::move(strongLayer));
+            layers.push_back(layer);
         }
     });
     refreshArgs.blursAreExpensive = mBlursAreExpensive;
@@ -2229,8 +2228,8 @@
 
     {
         std::vector<LayerSnapshotGuard> layerSnapshotGuards;
-        for (auto& layer : layers) {
-            layerSnapshotGuards.emplace_back(layer.get());
+        for (Layer* layer : layers) {
+            layerSnapshotGuards.emplace_back(layer);
         }
         mCompositionEngine->present(refreshArgs);
     }
@@ -3330,12 +3329,7 @@
 
     std::vector<LayerSnapshotGuard> layerSnapshotGuards;
     mDrawingState.traverse([&layerSnapshotGuards](Layer* layer) {
-        auto strongLayer = sp<Layer>::fromExisting(layer);
-        const LayerSnapshot* snapshot = layer->getLayerSnapshot();
-        if (!snapshot) {
-            LOG_ALWAYS_FATAL("Layer snapshot unexpectedly null");
-        }
-        if (snapshot->compositionType ==
+        if (layer->getLayerSnapshot()->compositionType ==
             aidl::android::hardware::graphics::composer3::Composition::CURSOR) {
             layer->updateSnapshot(false /* updateGeometry */);
             layerSnapshotGuards.emplace_back(layer);
@@ -6479,7 +6473,6 @@
     layers.reserve(layerCount);
     std::unordered_set<compositionengine::LayerFE*> filterForScreenshot;
     traverseLayers([&](Layer* layer) {
-        auto strongLayer = sp<Layer>::fromExisting(layer);
         captureResults.capturedHdrLayers |= isHdrLayer(layer);
         // Layer::prepareClientComposition uses the layer's snapshot to populate the resulting
         // LayerSettings. Calling Layer::updateSnapshot ensures that LayerSettings are