SF: Updating content FPS tracking

1) Each time SF creates a layer, register it with Scheduler and return handle
2) BufferQueueLayer and BufferStateLayer can now send information about buffers
   for given layers via layer handle.

Algorithm for detecting content fps:
1) Keep the refresh rate per layer (explicit timestamp, or 0).
2) Keep information about last 10 present or update timestamps. This will be an
   indicator for precedence.
3) Choose the MAX refresh rate among last updated layers.

For more info see go/surface-flinger-scheduler and
go/content-fps-detection-in-scheduler

Test: Updating unit tests. Systrace.

Change-Id: I988a7a79e9a9f0f61674c9b637c5142db3336177
Bug: 127727337
diff --git a/services/surfaceflinger/Scheduler/SchedulerUtils.h b/services/surfaceflinger/Scheduler/SchedulerUtils.h
index 9e6e8c7..a935cac 100644
--- a/services/surfaceflinger/Scheduler/SchedulerUtils.h
+++ b/services/surfaceflinger/Scheduler/SchedulerUtils.h
@@ -16,6 +16,7 @@
 
 #pragma once
 
+#include <chrono>
 #include <cinttypes>
 #include <numeric>
 #include <unordered_map>
@@ -23,6 +24,8 @@
 
 namespace android {
 namespace scheduler {
+using namespace std::chrono_literals;
+
 // This number is used to set the size of the arrays in scheduler that hold information
 // about layers.
 static constexpr size_t ARRAY_SIZE = 30;
@@ -32,12 +35,20 @@
 // still like to keep track of time when the device is in this config.
 static constexpr int SCREEN_OFF_CONFIG_ID = -1;
 
+// This number is used when we try to determine how long does a given layer stay relevant.
+// Currently it is set to 100ms, because that would indicate 10Hz rendering.
+static constexpr std::chrono::nanoseconds TIME_EPSILON_NS = 100ms;
+
+// This number is used when we try to determine how long do we keep layer information around
+// before we remove it. Currently it is set to 100ms.
+static constexpr std::chrono::nanoseconds OBSOLETE_TIME_EPSILON_NS = 100ms;
+
 // Calculates the statistical mean (average) in the data structure (array, vector). The
 // function does not modify the contents of the array.
 template <typename T>
 auto calculate_mean(const T& v) {
     using V = typename T::value_type;
-    V sum = std::accumulate(v.begin(), v.end(), 0);
+    V sum = std::accumulate(v.begin(), v.end(), static_cast<V>(0));
     return sum / static_cast<V>(v.size());
 }