Remove displayBounds when computing layer bounds
Display bounds will be applied later in CE and RE so there's no need for
them to be used when computing the layer bounds. This fixes a few
issues:
1. Accessibility can now get the real bounds of the window, even if it's
offscreen when magnified
2. Screenrecord rotation flicker is fixed. This was caused by the
multiple calculation using different display bounds and caching the last
value
3. Reducing number of calls to computeBounds. We now only call it once
where previously we'd call it once per display. Each computeBounds
traverses down the entire hierarchy so it can be inefficient.
Test: Existing tests pass. WindowInfo has bounds outside display
Bug: 188792659
Fixes: 140855415
Change-Id: I1f5072adb674c7c4dacb6a392473821968c67767
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index b56e696..8f8262e 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -2417,23 +2417,28 @@
}
}
-FloatRect SurfaceFlinger::getLayerClipBoundsForDisplay(const DisplayDevice& displayDevice) const {
- return displayDevice.getLayerStackSpaceRect().toFloatRect();
-}
-
void SurfaceFlinger::computeLayerBounds() {
+ // Find the largest width and height among all the displays.
+ int32_t maxDisplayWidth = 0;
+ int32_t maxDisplayHeight = 0;
for (const auto& pair : ON_MAIN_THREAD(mDisplays)) {
const auto& displayDevice = pair.second;
- const auto display = displayDevice->getCompositionDisplay();
- for (const auto& layer : mDrawingState.layersSortedByZ) {
- // Only consider the layers on this display.
- if (!display->includesLayer(layer->getOutputFilter())) {
- continue;
- }
-
- layer->computeBounds(getLayerClipBoundsForDisplay(*displayDevice), ui::Transform(),
- 0.f /* shadowRadius */);
+ int32_t width = displayDevice->getWidth();
+ int32_t height = displayDevice->getHeight();
+ if (width > maxDisplayWidth) {
+ maxDisplayWidth = width;
}
+ if (height > maxDisplayHeight) {
+ maxDisplayHeight = height;
+ }
+ }
+
+ // Ignore display bounds for now since they will be computed later. Use a large Rect bound
+ // to ensure it's bigger than an actual display will be.
+ FloatRect maxBounds(-maxDisplayWidth * 10, -maxDisplayHeight * 10, maxDisplayWidth * 10,
+ maxDisplayHeight * 10);
+ for (const auto& layer : mDrawingState.layersSortedByZ) {
+ layer->computeBounds(maxBounds, ui::Transform(), 0.f /* shadowRadius */);
}
}