SF: Suppress frame rate when small area updating

The small area is defined as the area that user is hard to obvious the
content updating such as small icon animtion or progress bar.

When content detect frame rate feature is enabled, and no explict
refresh vote is set to the layer, it will heuristically calculate the
predict frame rate by counting the average frame time of recent frames.

This CL will enhance the contect detection by checking the small dirty
frames and supress the predict frame rate that could prevent the app
always running at max frame rate cause unexcpected battery consumption.

This will cover 2 use cases:
1. When a layer contains a textureview, it will enter the heuristic
   calcuation, and this would skip the small dirty frames and supress
   the calculated frame rate not always to be max.

2. When an app has the separated video surface and ui surface, and the
   video had set an explicit rate by the content, this will ignore the
   heristic calculation for ui layer when it detected the small dirty
   frames, so the final refresh rate selection could mainly rely on the
   weight of the video layer.

Bug: 281720315
Test: atest LayerHistoryTest
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:65705849c4f6339ade986bd0745ea5470ba76ebb)
Merged-In: I9731de8adf8e68b72326b195fa720d51e02bae74
Change-Id: I9731de8adf8e68b72326b195fa720d51e02bae74
diff --git a/services/surfaceflinger/Layer.h b/services/surfaceflinger/Layer.h
index 1f2485f..7b6c56b 100644
--- a/services/surfaceflinger/Layer.h
+++ b/services/surfaceflinger/Layer.h
@@ -841,6 +841,14 @@
     mutable bool contentDirty{false};
     Region surfaceDamageRegion;
 
+    // True when the surfaceDamageRegion is recognized as a small area update.
+    bool mSmallDirty{false};
+    // Used to check if mUsedVsyncIdForRefreshRateSelection should be expired when it stop updating.
+    nsecs_t mMaxTimeForUseVsyncId = 0;
+    // True when DrawState.useVsyncIdForRefreshRateSelection previously set to true during updating
+    // buffer.
+    bool mUsedVsyncIdForRefreshRateSelection{false};
+
     // Layer serial number.  This gives layers an explicit ordering, so we
     // have a stable sort order when their layer stack and Z-order are
     // the same.
@@ -903,6 +911,7 @@
                 .transform = getTransform(),
                 .setFrameRateVote = getFrameRateForLayerTree(),
                 .frameRateSelectionPriority = getFrameRateSelectionPriority(),
+                .isSmallDirty = mSmallDirty,
         };
     };
     bool hasBuffer() const { return mBufferInfo.mBuffer != nullptr; }
@@ -917,6 +926,9 @@
     // Exposed so SurfaceFlinger can assert that it's held
     const sp<SurfaceFlinger> mFlinger;
 
+    // Check if the damage region is a small dirty.
+    void setIsSmallDirty();
+
 protected:
     // For unit tests
     friend class TestableSurfaceFlinger;