diff options
author | 2019-09-24 16:36:55 -0700 | |
---|---|---|
committer | 2019-09-25 09:55:21 -0700 | |
commit | e5ac40f470e92e8f3a3dbbf58c2f432a816f4486 (patch) | |
tree | bd0f394465e06c88a8434645140c578e26024819 | |
parent | 577b70b5514d79e7477caba264fb0a2ad70620b7 (diff) |
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
-rw-r--r-- | services/surfaceflinger/Layer.cpp | 7 | ||||
-rw-r--r-- | services/surfaceflinger/Layer.h | 1 | ||||
-rw-r--r-- | services/surfaceflinger/LayerVector.cpp | 4 |
3 files changed, 7 insertions, 5 deletions
diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp index ba948cfdbc..80d1e9a233 100644 --- a/services/surfaceflinger/Layer.cpp +++ b/services/surfaceflinger/Layer.cpp @@ -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); diff --git a/services/surfaceflinger/Layer.h b/services/surfaceflinger/Layer.h index 8771ccd08e..bd192615c2 100644 --- a/services/surfaceflinger/Layer.h +++ b/services/surfaceflinger/Layer.h @@ -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; diff --git a/services/surfaceflinger/LayerVector.cpp b/services/surfaceflinger/LayerVector.cpp index 84945247a6..8271fd97ea 100644 --- a/services/surfaceflinger/LayerVector.cpp +++ b/services/surfaceflinger/LayerVector.cpp @@ -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); |