Add a callback for rendernode parentcount=0

Bug: 27709981
Fixes: 22565656

Change-Id: I1cb4461baf9069dc4e7ca6de10d5862578c107f4
diff --git a/libs/hwui/TreeInfo.h b/libs/hwui/TreeInfo.h
index accd303..a43e544 100644
--- a/libs/hwui/TreeInfo.h
+++ b/libs/hwui/TreeInfo.h
@@ -32,6 +32,7 @@
 class DamageAccumulator;
 class LayerUpdateQueue;
 class OpenGLRenderer;
+class RenderNode;
 class RenderState;
 
 class ErrorHandler {
@@ -41,6 +42,17 @@
     ~ErrorHandler() {}
 };
 
+class TreeObserver {
+public:
+    // Called when a RenderNode's parent count hits 0.
+    // Due to the unordered nature of tree pushes, once prepareTree
+    // is finished it is possible that the node was "resurrected" and has
+    // a non-zero parent count.
+    virtual void onMaybeRemovedFromTree(RenderNode* node) {}
+protected:
+    ~TreeObserver() {}
+};
+
 // This would be a struct, but we want to PREVENT_COPY_AND_ASSIGN
 class TreeInfo {
     PREVENT_COPY_AND_ASSIGN(TreeInfo);
@@ -86,6 +98,10 @@
 #endif
     ErrorHandler* errorHandler = nullptr;
 
+    // Optional, may be nullptr. Used to allow things to observe interesting
+    // tree state changes
+    TreeObserver* observer = nullptr;
+
     // Frame number for use with synchronized surfaceview position updating
     int64_t frameNumber = -1;
     int32_t windowInsetLeft = 0;