Don't clear timestamps when enabling HW vsync.

It should clear after the first HW Vsync timestamp comes in,
and when VSyncReactor period confirmed. Therefore, a prediction
when HW vsync is enabled but not yet confirmed is consistent with a
prediction when coming out of idle.

Bug: 272802278
Test: Flash, perfetto trace
Test: atest libsurfaceflinger_unittest
Change-Id: I619162d5583f33087de04c0e3b073a589ec4c2f7
diff --git a/services/surfaceflinger/Scheduler/VsyncSchedule.cpp b/services/surfaceflinger/Scheduler/VsyncSchedule.cpp
index ff3f29d..5691792 100644
--- a/services/surfaceflinger/Scheduler/VsyncSchedule.cpp
+++ b/services/surfaceflinger/Scheduler/VsyncSchedule.cpp
@@ -17,6 +17,7 @@
 #define ATRACE_TAG ATRACE_TAG_GRAPHICS
 
 #include <ftl/fake_guard.h>
+#include <gui/TraceUtils.h>
 #include <scheduler/Fps.h>
 #include <scheduler/Timer.h>
 
@@ -144,6 +145,14 @@
 }
 
 bool VsyncSchedule::addResyncSample(TimePoint timestamp, ftl::Optional<Period> hwcVsyncPeriod) {
+    ATRACE_CALL();
+
+    if (mClearTimestampsOnNextSample) {
+        ATRACE_FORMAT("clearing sample after HW vsync enabled", __func__);
+        getTracker().resetModel();
+        mClearTimestampsOnNextSample = false;
+    }
+
     bool needsHwVsync = false;
     bool periodFlushed = false;
     {
@@ -170,7 +179,7 @@
 
 void VsyncSchedule::enableHardwareVsyncLocked() {
     if (mHwVsyncState == HwVsyncState::Disabled) {
-        getTracker().resetModel();
+        mClearTimestampsOnNextSample = true;
         mRequestHardwareVsync(mId, true);
         mHwVsyncState = HwVsyncState::Enabled;
     }