SF: change acquired buffers based on the current refresh rate

BLASTBufferQueue set the max acquired buffers based on SF
vsync configuration (sf.duration and app.duration). This is calculated
based on the max supported refresh rate on the device, and it turn
is propogated to apps via min_undequeued_buffers to the app could
allocate enough buffers for maintaining the pipeline SF expects.

This leads to a higher latency when the device is running in a lower
refresh rate as there are more buffers on the buffer queue then required.
In this change we are holding on the these "extra buffers" and not
releasing them back to the buffer queue so the app would use the number
of buffers it needs based on the current refresh rate, and to avoid having
unnecessary long latency.

Bug: 188553729
Test: Run backpressure based game on 60Hz and 120Hz and collect systraces
Change-Id: I9d4e6278f0ddd28008ac437ab0576aa79d05166a
diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h
index a3fa8d6..22d17eb 100644
--- a/services/surfaceflinger/SurfaceFlinger.h
+++ b/services/surfaceflinger/SurfaceFlinger.h
@@ -708,7 +708,7 @@
 
     int getGPUContextPriority() override;
 
-    status_t getExtraBufferCount(int* extraBuffers) const override;
+    status_t getMaxAcquiredBufferCount(int* buffers) const override;
 
     // Implements IBinder::DeathRecipient.
     void binderDied(const wp<IBinder>& who) override;
@@ -923,6 +923,8 @@
     size_t getMaxTextureSize() const;
     size_t getMaxViewportDims() const;
 
+    int getMaxAcquiredBufferCountForCurrentRefreshRate(uid_t uid) const;
+
     /*
      * Display and layer stack management
      */
@@ -1062,6 +1064,7 @@
 
     // Calculates the expected present time for this frame. For negative offsets, performs a
     // correction using the predicted vsync for the next frame instead.
+
     nsecs_t calculateExpectedPresentTime(DisplayStatInfo) const;
 
     /*
@@ -1177,8 +1180,9 @@
     std::vector<ui::ColorMode> getDisplayColorModes(PhysicalDisplayId displayId)
             REQUIRES(mStateLock);
 
-    static int calculateExtraBufferCount(Fps maxSupportedRefreshRate,
-                                         std::chrono::nanoseconds presentLatency);
+    static int calculateMaxAcquiredBufferCount(Fps refreshRate,
+                                               std::chrono::nanoseconds presentLatency);
+    int getMaxAcquiredBufferCountForRefreshRate(Fps refreshRate) const;
 
     sp<StartPropertySetThread> mStartPropertySetThread;
     surfaceflinger::Factory& mFactory;