Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e5ac40f4 authored by chaviw's avatar chaviw
Browse files

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
parent 577b70b5
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -899,6 +899,7 @@ bool Layer::setLayer(int32_t z) {
        }
        setZOrderRelativeOf(nullptr);
    }
    mCurrentState.isRelativeOf = false;
    setTransactionFlags(eTransactionNeeded);
    return true;
}
@@ -942,6 +943,7 @@ bool Layer::setRelativeLayer(const sp<IBinder>& relativeToHandle, int32_t relati
    mCurrentState.sequence++;
    mCurrentState.modified = true;
    mCurrentState.z = relativeZ;
    mCurrentState.isRelativeOf = true;

    auto oldZOrderRelativeOf = mCurrentState.zOrderRelativeOf.promote();
    if (oldZOrderRelativeOf != nullptr) {
@@ -1540,7 +1542,7 @@ int32_t Layer::getZ() const {
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 @@ __attribute__((no_sanitize("unsigned-integer-overflow"))) LayerVector Layer::mak
    }

    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);
+1 −0
Original line number Diff line number Diff line
@@ -170,6 +170,7 @@ public:

        // If non-null, a Surface this Surface's Z-order is interpreted relative to.
        wp<Layer> zOrderRelativeOf;
        bool isRelativeOf{false};

        // A list of surfaces whose Z-order is interpreted relative to ours.
        SortedVector<wp<Layer>> zOrderRelatives;
+2 −2
Original line number Diff line number Diff line
@@ -64,7 +64,7 @@ void LayerVector::traverseInZOrder(StateSet stateSet, const Visitor& visitor) co
        const auto& layer = (*this)[i];
        auto& state = (stateSet == StateSet::Current) ? layer->getCurrentState()
                                                      : layer->getDrawingState();
        if (state.zOrderRelativeOf != nullptr) {
        if (state.isRelativeOf) {
            continue;
        }
        layer->traverseInZOrder(stateSet, visitor);
@@ -76,7 +76,7 @@ void LayerVector::traverseInReverseZOrder(StateSet stateSet, const Visitor& visi
        const auto& layer = (*this)[i];
        auto& state = (stateSet == StateSet::Current) ? layer->getCurrentState()
                                                      : layer->getDrawingState();
        if (state.zOrderRelativeOf != nullptr) {
        if (state.isRelativeOf) {
            continue;
        }
        layer->traverseInReverseZOrder(stateSet, visitor);