Added isRelativeOf instead of checking if weak pointer is not null

If a layer has a relativeOf, it will continue to assume it has a
relativeOf even if what it's relative to is removed. This is because the
client never explicitly asked to remove the relative Z.

Instead of relying on whether the weak pointer is non null, this change
adds a variable isRelativeOf that's set to true when the client calls
setRelativeLayer and false when the client calls setLayer. This is
clearer than checking whether the weak pointer is still around.

This is also needed for mirroring since we want to add this same
behavior without having to clone weak referenced layers.

Bug: 131622422
Test: go/wm-smoke
Test: SurfaceFlinger_test
Change-Id: Ia71b0f660edda9b3a63521d40ca30bfca1d456b9
diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp
index ba948cf..80d1e9a 100644
--- a/services/surfaceflinger/Layer.cpp
+++ b/services/surfaceflinger/Layer.cpp
@@ -899,6 +899,7 @@
         }
         setZOrderRelativeOf(nullptr);
     }
+    mCurrentState.isRelativeOf = false;
     setTransactionFlags(eTransactionNeeded);
     return true;
 }
@@ -942,6 +943,7 @@
     mCurrentState.sequence++;
     mCurrentState.modified = true;
     mCurrentState.z = relativeZ;
+    mCurrentState.isRelativeOf = true;
 
     auto oldZOrderRelativeOf = mCurrentState.zOrderRelativeOf.promote();
     if (oldZOrderRelativeOf != nullptr) {
@@ -1540,7 +1542,7 @@
 bool Layer::usingRelativeZ(LayerVector::StateSet stateSet) const {
     const bool useDrawing = stateSet == LayerVector::StateSet::Drawing;
     const State& state = useDrawing ? mDrawingState : mCurrentState;
-    return state.zOrderRelativeOf != nullptr;
+    return state.isRelativeOf;
 }
 
 __attribute__((no_sanitize("unsigned-integer-overflow"))) LayerVector Layer::makeTraversalList(
@@ -1565,8 +1567,7 @@
     }
 
     for (const sp<Layer>& child : children) {
-        const State& childState = useDrawing ? child->mDrawingState : child->mCurrentState;
-        if (childState.zOrderRelativeOf != nullptr) {
+        if (child->usingRelativeZ(stateSet)) {
             continue;
         }
         traverse.add(child);