SurfaceFlinger: Move generic dtor logic to Layer

Move Layer generic code from BufferLayer destructor
to the Layer destructor so that ColorLayer will
be able to use it.

Bug: 69127378
Test: CTS SurfaceView tests
Change-Id: Ie48ee2c3433e80bcae822654d4dc186d09c49c00
diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp
index fa4d289..13df1e2 100644
--- a/services/surfaceflinger/Layer.cpp
+++ b/services/surfaceflinger/Layer.cpp
@@ -142,6 +142,17 @@
 void Layer::onFirstRef() {}
 
 Layer::~Layer() {
+    sp<Client> c(mClientRef.promote());
+    if (c != 0) {
+        c->detachLayer(this);
+    }
+
+    for (auto& point : mRemoteSyncPoints) {
+        point->setTransactionApplied();
+    }
+    for (auto& point : mLocalSyncPoints) {
+        point->setFrameAvailable();
+    }
     mFrameTracker.logAndResetStats(mName);
 }