SF Generalization of Refresh Rates: Adding layer priority hint

Test: Device boots. Observe logs for errors.
Test: Open Swappy and Chrome in split screen, tap between apps,
      SF prints the correct priority.
Test: Open Chrome, play video. SF prints correct priority.
Test: SF prints the correct priority received.
Bug: 142507166
Change-Id: I5fa8a857c950db01f42a380a72d098039badc289
diff --git a/services/surfaceflinger/Scheduler/LayerHistory.cpp b/services/surfaceflinger/Scheduler/LayerHistory.cpp
index cf79d9f..aaac1ec 100644
--- a/services/surfaceflinger/Scheduler/LayerHistory.cpp
+++ b/services/surfaceflinger/Scheduler/LayerHistory.cpp
@@ -48,6 +48,12 @@
     return atoi(value);
 }
 
+bool useFrameRatePriority() {
+    char value[PROPERTY_VALUE_MAX];
+    property_get("debug.sf.use_frame_rate_priority", value, "1");
+    return atoi(value);
+}
+
 void trace(const wp<Layer>& weak, int fps) {
     const auto layer = weak.promote();
     if (!layer) return;
@@ -60,7 +66,8 @@
 
 } // namespace
 
-LayerHistory::LayerHistory() : mTraceEnabled(traceEnabled()) {}
+LayerHistory::LayerHistory()
+      : mTraceEnabled(traceEnabled()), mUseFrameRatePriority(useFrameRatePriority()) {}
 LayerHistory::~LayerHistory() = default;
 
 void LayerHistory::registerLayer(Layer* layer, float lowRefreshRate, float highRefreshRate) {
@@ -94,16 +101,23 @@
     partitionLayers(now);
 
     // Find the maximum refresh rate among recently active layers.
-    for (const auto& [layer, info] : activeLayers()) {
+    for (const auto& [activeLayer, info] : activeLayers()) {
         const bool recent = info->isRecentlyActive(now);
+
         if (recent || CC_UNLIKELY(mTraceEnabled)) {
             const float refreshRate = info->getRefreshRate(now);
             if (recent && refreshRate > maxRefreshRate) {
+                if (const auto layer = activeLayer.promote(); layer) {
+                    const int32_t priority = layer->getFrameRateSelectionPriority();
+                    // TODO(b/142507166): This is where the scoring algorithm should live.
+                    // Layers should be organized by priority
+                    ALOGD("Layer has priority: %d", priority);
+                }
                 maxRefreshRate = refreshRate;
             }
 
             if (CC_UNLIKELY(mTraceEnabled)) {
-                trace(layer, std::round(refreshRate));
+                trace(activeLayer, std::round(refreshRate));
             }
         }
     }