Dynamically adjust renderahead

Tracks refresh rate changes and adjusts renderahead
based off of the active refresh rate.

Default is 60hz = 0 render ahead & > 70hz is render ahead 1

Bug: 127822449
Test: systraced stuff

Change-Id: I9849aa065262f21f7602d44cd1761373279dc28d
diff --git a/libs/hwui/DeviceInfo.cpp b/libs/hwui/DeviceInfo.cpp
index cf5d7ce..0a9d965d 100644
--- a/libs/hwui/DeviceInfo.cpp
+++ b/libs/hwui/DeviceInfo.cpp
@@ -45,12 +45,12 @@
         1920,   // viewportH
 };
 
-const DeviceInfo* DeviceInfo::get() {
+DeviceInfo* DeviceInfo::get() {
         static DeviceInfo sDeviceInfo;
         return &sDeviceInfo;
 }
 
-DisplayInfo QueryDisplayInfo() {
+static DisplayInfo QueryDisplayInfo() {
     if (Properties::isolatedProcess) {
         return sDummyDisplay;
     }
@@ -65,6 +65,27 @@
     return displayInfo;
 }
 
+static float QueryMaxRefreshRate() {
+    if (Properties::isolatedProcess) {
+        return sDummyDisplay.fps;
+    }
+
+    const sp<IBinder> token = SurfaceComposerClient::getInternalDisplayToken();
+    LOG_ALWAYS_FATAL_IF(token == nullptr,
+                        "Failed to get display info because internal display is disconnected");
+
+    Vector<DisplayInfo> configs;
+    configs.reserve(10);
+    status_t status = SurfaceComposerClient::getDisplayConfigs(token, &configs);
+    LOG_ALWAYS_FATAL_IF(status, "Failed to getDisplayConfigs, error %d", status);
+    LOG_ALWAYS_FATAL_IF(configs.size() == 0, "getDisplayConfigs returned 0 configs?");
+    float max = 0.0f;
+    for (auto& info : configs) {
+        max = std::max(max, info.fps);
+    }
+    return max;
+}
+
 static void queryWideColorGamutPreference(sk_sp<SkColorSpace>* colorSpace, SkColorType* colorType) {
     if (Properties::isolatedProcess) {
         *colorSpace = SkColorSpace::MakeSRGB();
@@ -103,7 +124,7 @@
     }
 }
 
-DeviceInfo::DeviceInfo() {
+DeviceInfo::DeviceInfo() : mMaxRefreshRate(QueryMaxRefreshRate()) {
 #if HWUI_NULL_GPU
         mMaxTextureSize = NULL_GPU_MAX_TEXTURE_SIZE;
 #else
@@ -119,7 +140,11 @@
 }
 
 void DeviceInfo::setMaxTextureSize(int maxTextureSize) {
-    const_cast<DeviceInfo*>(DeviceInfo::get())->mMaxTextureSize = maxTextureSize;
+    DeviceInfo::get()->mMaxTextureSize = maxTextureSize;
+}
+
+void DeviceInfo::onDisplayConfigChanged() {
+    mDisplayInfo = QueryDisplayInfo();
 }
 
 } /* namespace uirenderer */