Merge "Optimize offscreen layer management" into sc-dev am: 2b7d5cea13 am: 528dc3c6da
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/native/+/15150272
Change-Id: Id803f0cdb523d0da0393c919052de00926c039c3
diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp
index f1bfebc..204c49e 100644
--- a/services/surfaceflinger/Layer.cpp
+++ b/services/surfaceflinger/Layer.cpp
@@ -254,6 +254,7 @@
if (mRemovedFromDrawingState) {
mRemovedFromDrawingState = false;
mFlinger->mScheduler->registerLayer(this);
+ mFlinger->removeFromOffscreenLayers(this);
}
for (const auto& child : mCurrentChildren) {
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index 18cb0c2..79f481d 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -3245,17 +3245,6 @@
}
}
- // TODO(b/163019109): See if this traversal is needed at all...
- if (!mOffscreenLayers.empty()) {
- mDrawingState.traverse([&](Layer* layer) {
- // If the layer can be reached when traversing mDrawingState, then the layer is no
- // longer offscreen. Remove the layer from the offscreenLayer set.
- if (mOffscreenLayers.count(layer)) {
- mOffscreenLayers.erase(layer);
- }
- });
- }
-
commitOffscreenLayers();
mDrawingState.traverse([&](Layer* layer) { layer->updateMirrorInfo(); });
}
@@ -6647,7 +6636,7 @@
void SurfaceFlinger::onLayerDestroyed(Layer* layer) {
mNumLayers--;
- removeFromOffscreenLayers(layer);
+ removeHierarchyFromOffscreenLayers(layer);
if (!layer->isRemovedFromCurrentState()) {
mScheduler->deregisterLayer(layer);
}
@@ -6660,13 +6649,17 @@
// from dangling children layers such that they are not reachable from the
// Drawing state nor the offscreen layer list
// See b/141111965
-void SurfaceFlinger::removeFromOffscreenLayers(Layer* layer) {
+void SurfaceFlinger::removeHierarchyFromOffscreenLayers(Layer* layer) {
for (auto& child : layer->getCurrentChildren()) {
mOffscreenLayers.emplace(child.get());
}
mOffscreenLayers.erase(layer);
}
+void SurfaceFlinger::removeFromOffscreenLayers(Layer* layer) {
+ mOffscreenLayers.erase(layer);
+}
+
status_t SurfaceFlinger::setGlobalShadowSettings(const half4& ambientColor, const half4& spotColor,
float lightPosY, float lightPosZ,
float lightRadius) {
diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h
index 338aa18..bb20415 100644
--- a/services/surfaceflinger/SurfaceFlinger.h
+++ b/services/surfaceflinger/SurfaceFlinger.h
@@ -313,6 +313,7 @@
void onLayerFirstRef(Layer*);
void onLayerDestroyed(Layer*);
+ void removeHierarchyFromOffscreenLayers(Layer* layer);
void removeFromOffscreenLayers(Layer* layer);
TransactionCallbackInvoker& getTransactionCallbackInvoker() {