Introduce a dependency monitor for fences

This allows for userspace logging for a buffer and read/write dependencies on the buffer.

Hook up SF to the dependency monitor.

Right now this _does_ emit logs in SF when the primary display is powered down, which is likely indicative of SF being sloppy about release fences in situations where tearing won't be noticeable, but I did verify that manually making screenshotting forget to merge GPU work into a layer's release fence, which has been one way SF's torn the screen, triggers logcat, which is ultimately what we want.

Bug: 360932099
Flag: com.android.graphics.surfaceflinger.flags.monitor_buffer_fences
Test: manually remove screenshot fence handling and check logs

Change-Id: Ica391dfa8a4f2924bb72664b9d9399e4ad9e1747
diff --git a/libs/ui/FenceTime.cpp b/libs/ui/FenceTime.cpp
index 4246c40..81afe9e 100644
--- a/libs/ui/FenceTime.cpp
+++ b/libs/ui/FenceTime.cpp
@@ -59,6 +59,14 @@
     }
 }
 
+FenceTimePtr FenceTime::makeValid(const sp<Fence>& fence) {
+    if (fence && fence->isValid()) {
+        return std::make_shared<FenceTime>(fence);
+    } else {
+        return std::make_shared<FenceTime>(systemTime());
+    }
+}
+
 void FenceTime::applyTrustedSnapshot(const Snapshot& src) {
     if (CC_UNLIKELY(src.state != Snapshot::State::SIGNAL_TIME)) {
         // Applying Snapshot::State::FENCE, could change the valid state of the
@@ -289,9 +297,10 @@
 // ============================================================================
 void FenceTimeline::push(const std::shared_ptr<FenceTime>& fence) {
     std::lock_guard<std::mutex> lock(mMutex);
-    while (mQueue.size() >= MAX_ENTRIES) {
+    static constexpr size_t MAX_QUEUE_SIZE = 64;
+    while (mQueue.size() >= MAX_QUEUE_SIZE) {
         // This is a sanity check to make sure the queue doesn't grow unbounded.
-        // MAX_ENTRIES should be big enough not to trigger this path.
+        // MAX_QUEUE_SIZE should be big enough not to trigger this path.
         // In case this path is taken though, users of FenceTime must make sure
         // not to rely solely on FenceTimeline to get the final timestamp and
         // should eventually call Fence::getSignalTime on their own.