Revert "SurfaceFlinger: Allows Surfaces to outlive their parents."

This reverts commit 4340607f5f5c277eb031fdd1424fc8a1a69924e2.

Reason for revert: Causes bug 117401269

Change-Id: I10973c9dd734499e09c18f48c06f1b1a6a1f8da0
diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp
index 63a010d..f9bc1e7 100644
--- a/services/surfaceflinger/Layer.cpp
+++ b/services/surfaceflinger/Layer.cpp
@@ -118,6 +118,12 @@
         c->detachLayer(this);
     }
 
+    for (auto& point : mRemoteSyncPoints) {
+        point->setTransactionApplied();
+    }
+    for (auto& point : mLocalSyncPoints) {
+        point->setFrameAvailable();
+    }
     mFrameTracker.logAndResetStats(mName);
 }
 
@@ -135,6 +141,8 @@
 void Layer::onRemovedFromCurrentState() {
     // the layer is removed from SF mCurrentState to mLayersPendingRemoval
 
+    mPendingRemoval = true;
+
     if (mCurrentState.zOrderRelativeOf != nullptr) {
         sp<Layer> strongRelative = mCurrentState.zOrderRelativeOf.promote();
         if (strongRelative != nullptr) {
@@ -143,7 +151,7 @@
         }
         mCurrentState.zOrderRelativeOf = nullptr;
     }
-    
+
     for (const auto& child : mCurrentChildren) {
         child->onRemovedFromCurrentState();
     }
@@ -155,13 +163,8 @@
 
     destroyAllHwcLayers();
 
-    mRemoved = true;
-
-    for (auto& point : mRemoteSyncPoints) {
-        point->setTransactionApplied();
-    }
-    for (auto& point : mLocalSyncPoints) {
-        point->setFrameAvailable();
+    for (const auto& child : mCurrentChildren) {
+        child->onRemoved();
     }
 }