Merge "SF: Avoid promoting parent layer in binder thread" into sc-dev am: aff187c337
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/native/+/15276211
Change-Id: I7d30e17cee07acbd541583b5065ee1564afa5da6
diff --git a/services/surfaceflinger/Layer.h b/services/surfaceflinger/Layer.h
index 24789cf..3aaa680 100644
--- a/services/surfaceflinger/Layer.h
+++ b/services/surfaceflinger/Layer.h
@@ -796,6 +796,11 @@
// for symmetry with Vector::remove
ssize_t removeChild(const sp<Layer>& layer);
sp<Layer> getParent() const { return mCurrentParent.promote(); }
+
+ // Should be called with the surfaceflinger statelock held
+ bool isAtRoot() const { return mIsAtRoot; }
+ void setIsAtRoot(bool isAtRoot) { mIsAtRoot = isAtRoot; }
+
bool hasParent() const { return getParent() != nullptr; }
Rect getScreenBounds(bool reduceTransparentRegion = true) const;
bool setChildLayer(const sp<Layer>& childLayer, int32_t z);
@@ -1103,6 +1108,8 @@
// A list of regions on this layer that should have blurs.
const std::vector<BlurRegion> getBlurRegions() const;
+
+ bool mIsAtRoot = false;
};
std::ostream& operator<<(std::ostream& stream, const Layer::FrameRate& rate);
diff --git a/services/surfaceflinger/RefreshRateOverlay.cpp b/services/surfaceflinger/RefreshRateOverlay.cpp
index b0d76e6..8704c88 100644
--- a/services/surfaceflinger/RefreshRateOverlay.cpp
+++ b/services/surfaceflinger/RefreshRateOverlay.cpp
@@ -200,6 +200,7 @@
mLayer = mClient->getLayerUser(mIBinder);
mLayer->setFrameRate(Layer::FrameRate(Fps(0.0f), Layer::FrameRateCompatibility::NoVote));
+ mLayer->setIsAtRoot(true);
// setting Layer's Z requires resorting layersSortedByZ
ssize_t idx = mFlinger.mDrawingState.layersSortedByZ.indexOf(mLayer);
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index cb3f242..a5b28fe 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -4154,6 +4154,7 @@
: nullptr;
if (layer->reparent(parentHandle)) {
if (!hadParent) {
+ layer->setIsAtRoot(false);
mCurrentState.layersSortedByZ.remove(layer);
}
flags |= eTransactionNeeded | eTraversalNeeded;
@@ -4420,7 +4421,8 @@
// with the idea that the parent holds a reference and will eventually
// be cleaned up. However no one cleans up the top-level so we do so
// here.
- if (layer->getParent() == nullptr) {
+ if (layer->isAtRoot()) {
+ layer->setIsAtRoot(false);
mCurrentState.layersSortedByZ.remove(layer);
}
markLayerPendingRemovalLocked(layer);
@@ -6898,6 +6900,7 @@
}
if (parent == nullptr && allowAddRoot) {
+ layer->setIsAtRoot(true);
mCurrentState.layersSortedByZ.add(layer);
} else if (parent == nullptr) {
layer->onRemovedFromCurrentState();