[sf] avoid traversals for cursor updates and buffer udpates
In U, we have a unified way to traverse the layer
hierarchy from both new FrontEnd and legacy logic
to generate the snapshots to provide to CE.
We update CE twice, once to draw the cursor and once
for the remaining layers. In T we relied on the previous
frame's composition state to update cursor state. This
extra traversal increases the cpu usage for buffer updates.
Fix this by keeping track of the previous composition state
and expand on this to avoid all traversals when there are
only buffer updates.
Bug: 278634536
Test: simple perf and check the instruction count between T and U
Change-Id: I26989bf42aa00650ee97c3c60e7f34171c385c5c
diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h
index d92ec7a..adf52cb 100644
--- a/services/surfaceflinger/SurfaceFlinger.h
+++ b/services/surfaceflinger/SurfaceFlinger.h
@@ -1199,6 +1199,11 @@
std::unordered_set<sp<Layer>, SpHash<Layer>> mLayersWithBuffersRemoved;
// Tracks layers that need to update a display's dirty region.
std::vector<sp<Layer>> mLayersPendingRefresh;
+ // Sorted list of layers that were composed during previous frame. This is used to
+ // avoid an expensive traversal of the layer hierarchy when there are no
+ // visible region changes. Because this is a list of strong pointers, this will
+ // extend the life of the layer but this list is only updated in the main thread.
+ std::vector<sp<Layer>> mPreviouslyComposedLayers;
BootStage mBootStage = BootStage::BOOTLOADER;