SurfaceFlinger: Cache updateInputWindows call

This is a conservative but safe cache. We invalidate it if
any layer with InputInfo, or any layer whose children/relative-children
have input info updates their drawing state. Not all these drawing state
updates will result in Input changes, but we can be confident that
without some drawing state change there wont be any Input changes,
and thus it seems the cache is safe. This will solve the case of
moving layers that don't have any InputInfo assosciated generating
setInputWindows calls.

Bug: 148675756
Test: Existing tests pass. go/wm-smoke
Change-Id: Ie5979b25370c2d5c3d8a55f187fc6fda1cc75b27
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index c995db4..6f49c7a 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -2769,6 +2769,19 @@
 void SurfaceFlinger::updateInputWindowInfo() {
     std::vector<InputWindowInfo> inputHandles;
 
+    // We use a simple caching algorithm here. mInputDirty begins as true,
+    // after we call setInputWindows we set it to false, so
+    // in the future we wont call it again.. We set input dirty to true again
+    // when any layer that hasInput() has a transaction performed on it
+    // or when any parent or relative parent of such a layer has a transaction
+    // performed on it. Not all of these transactions will really result in
+    // input changes but all input changes will spring from these transactions
+    // so the cache is safe but not optimal. It seems like it might be annoyingly
+    // costly to cache and comapre the actual InputWindowHandle vector though.
+    if (!mInputDirty) {
+        return;
+    }
+
     mDrawingState.traverseInReverseZOrder([&](Layer* layer) {
         if (layer->hasInput()) {
             // When calculating the screen bounds we ignore the transparent region since it may
@@ -2780,6 +2793,8 @@
     mInputFlinger->setInputWindows(inputHandles,
                                    mInputWindowCommands.syncInputWindows ? mSetInputWindowsListener
                                                                          : nullptr);
+
+    mInputDirty = false;
 }
 
 void SurfaceFlinger::commitInputWindowCommands() {