Input: Update input window info when the layer receives its first buffer
Currently input window info is populated when a surface flinger transaction is applied. When
populating input window info for a layer that is yet to receive its first buffer, the window
will be invisible and not receive any input until another transaction is applied. This can
result in input being dispatched to a window beneath the target window.
To fix, populate the input window info when we latch a new buffer as well.
Test: sf unit tests+go/wm-smoke
Bug: 120839715
Change-Id: I42f9dc3a64a7af2f3359f0dfeefb57f7a3e75306
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index e6a43c5..a75f17f 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -2736,7 +2736,7 @@
commitTransaction();
- if ((inputChanged || mVisibleRegionsDirty) && mInputFlinger) {
+ if (inputChanged || mVisibleRegionsDirty) {
updateInputWindows();
}
@@ -2746,6 +2746,10 @@
void SurfaceFlinger::updateInputWindows() {
ATRACE_CALL();
+ if (mInputFlinger == nullptr) {
+ return;
+ }
+
Vector<InputWindowInfo> inputHandles;
mDrawingState.traverseInReverseZOrder([&](Layer* layer) {
@@ -3015,6 +3019,11 @@
mVisibleRegionsDirty |= visibleRegions;
+ if (visibleRegions) {
+ // Update input window info if the layer receives its first buffer.
+ updateInputWindows();
+ }
+
// If we will need to wake up at some time in the future to deal with a
// queued frame that shouldn't be displayed during this vsync period, wake
// up during the next vsync period to check again.