Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 349b2902 authored by ramindani's avatar ramindani
Browse files

SF: Flag guard VSyncPredictor duplicate timestamp check

Bug: 411593328
Bug: 385059265
Flag: com.android.graphics.surfaceflinger.flags.vsync_predictor_predicts_within_threshold
Test: atest VSyncPredictorTest
Change-Id: Ib0f4679aae7626d56094b541193a953a8f2cff59
parent 6569cd19
Loading
Loading
Loading
Loading
+10 −6
Original line number Diff line number Diff line
@@ -111,16 +111,20 @@ bool VSyncPredictor::validate(nsecs_t timestamp) const {
        return false;
    }

    const auto isThresholdEnabled =
            FlagManager::getInstance().vsync_predictor_predicts_within_threshold() &&
            mDisplayModePtr->getVrrConfig();
    const auto iter = std::min_element(mTimestamps.begin(), mTimestamps.end(),
                                       [timestamp, this](nsecs_t a, nsecs_t b) {
                                       [=, this](nsecs_t a, nsecs_t b) {
                                           nsecs_t diffA = std::abs(timestamp - a);
                                           nsecs_t diffB = std::abs(timestamp - b);
                                           if (isThresholdEnabled) {
                                               bool withinThresholdA = diffA <= kPredictorThreshold;
                                               bool withinThresholdB = diffB <= kPredictorThreshold;

                                               if (withinThresholdA != withinThresholdB) {
                                                   return withinThresholdA;
                                               }
                                           }
                                           return diffA < diffB;
                                       });
    const auto distancePercent = std::abs(*iter - timestamp) * kMaxPercent / idealPeriod();