SF: Move present timing to FrameTargeter

Split out from I2c27dc709afd1f33bddbf9c2ca1cd61dd335f66c.

Store earliestPresentTime on the FrameTarget, like expectedPresentTime,
so it can be stored per display.

Add FrameTargeter::computeEarliestPresentTime. This calculation was
previously done in SurfaceFlinger, using data mostly contained in the
FrameTargeter. This will simplify computing this per display.

Move computation of the earliestPresentTime to
FrameTargeter::beginFrame. Add a scheduler::Feature to track whether
ExpectedPresentTime is supported.

Make previousFrameVsyncTime and wouldPresentEarly protected, now that
they are only called by FrameTargeter (subclass) and tests.

Make the test a friend of FrameTarget for accessing the above methods.

Bug: 255601557
Bug: 256196556
Bug: 259132483
Test: atest libscheduler_test:FrameTargeterTest
Test: atest
        libscheduler_test:FrameTargeterWithExpectedPresentSupportTest

Change-Id: Ib927935de6ba2b7b8d5037b42eb635ae92019634
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index 4d04aad..eecfabb 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -2749,24 +2749,13 @@
         refreshArgs.devOptFlashDirtyRegionsDelay = std::chrono::milliseconds(mDebugFlashDelay);
     }
 
-    const Period minFramePeriod = mScheduler->getVsyncSchedule()->minFramePeriod();
-
-    if (!getHwComposer().getComposer()->isSupported(
-                Hwc2::Composer::OptionalFeature::ExpectedPresentTime) &&
-        pacesetterTarget.wouldPresentEarly(minFramePeriod)) {
-        const auto hwcMinWorkDuration =
-                mScheduler->getVsyncConfiguration().getCurrentConfigs().hwcMinWorkDuration;
-
-        // TODO(b/255601557): Calculate and pass per-display values for each FrameTarget.
-        refreshArgs.earliestPresentTime =
-                pacesetterTarget.previousFrameVsyncTime(minFramePeriod) - hwcMinWorkDuration;
-    }
-
     const TimePoint expectedPresentTime = pacesetterTarget.expectedPresentTime();
     // TODO(b/255601557) Update frameInterval per display
     refreshArgs.frameInterval = mScheduler->getNextFrameInterval(pacesetterId, expectedPresentTime);
     refreshArgs.scheduledFrameTime = mScheduler->getScheduledFrameTime();
     refreshArgs.expectedPresentTime = expectedPresentTime.ns();
+    // TODO(b/255601557): Calculate and pass per-display values for each FrameTarget.
+    refreshArgs.earliestPresentTime = pacesetterTarget.earliestPresentTime();
     refreshArgs.hasTrustedPresentationListener = mNumTrustedPresentationListeners > 0;
     {
         auto& notifyExpectedPresentData = mNotifyExpectedPresentMap[pacesetterId];
@@ -4218,6 +4207,10 @@
     if (mBackpressureGpuComposition) {
         features |= Feature::kBackpressureGpuComposition;
     }
+    if (getHwComposer().getComposer()->isSupported(
+                Hwc2::Composer::OptionalFeature::ExpectedPresentTime)) {
+        features |= Feature::kExpectedPresentTime;
+    }
 
     mScheduler = std::make_unique<Scheduler>(static_cast<ICompositor&>(*this),
                                              static_cast<ISchedulerCallback&>(*this), features,