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

Commit 2db205d8 authored by Rachel Lee's avatar Rachel Lee
Browse files

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
parent abf2cc0f
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -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 @@ void VsyncSchedule::startPeriodTransition(Period period, bool force) {
}

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::enableHardwareVsync() {

void VsyncSchedule::enableHardwareVsyncLocked() {
    if (mHwVsyncState == HwVsyncState::Disabled) {
        getTracker().resetModel();
        mClearTimestampsOnNextSample = true;
        mRequestHardwareVsync(mId, true);
        mHwVsyncState = HwVsyncState::Enabled;
    }
+5 −0
Original line number Diff line number Diff line
@@ -146,6 +146,11 @@ private:
    // device is off.
    HwVsyncState mPendingHwVsyncState GUARDED_BY(kMainThreadContext) = HwVsyncState::Disabled;

    // Whether to reset the timestamps stored in the vsync model on the next hw vsync sample. This
    // is to avoid clearing the model when hw vsync is enabled, in order to be consistent with the
    // stale timestamps. Instead, clear the model on the first hw vsync callback.
    bool mClearTimestampsOnNextSample = false;

    class PredictedVsyncTracer;
    using TracerPtr = std::unique_ptr<PredictedVsyncTracer>;

+5 −7
Original line number Diff line number Diff line
@@ -91,18 +91,16 @@ struct EventThreadIsSupportedVariant : public EventThreadBaseSupportedVariant {
};

struct DispSyncIsSupportedVariant {
    static void setupResetModelCallExpectations(DisplayTransactionTest* test) {
    static void setupStartPeriodTransitionCallExpectations(DisplayTransactionTest* test) {
        auto vsyncSchedule = test->mFlinger.scheduler()->getVsyncSchedule();
        EXPECT_CALL(static_cast<mock::VsyncController&>(vsyncSchedule->getController()),
                    startPeriodTransition(DEFAULT_VSYNC_PERIOD, false))
                .Times(1);
        EXPECT_CALL(static_cast<mock::VSyncTracker&>(vsyncSchedule->getTracker()), resetModel())
                .Times(1);
    }
};

struct DispSyncNotSupportedVariant {
    static void setupResetModelCallExpectations(DisplayTransactionTest* /* test */) {}
    static void setupStartPeriodTransitionCallExpectations(DisplayTransactionTest* /* test */) {}
};

// --------------------------------------------------------------------
@@ -125,7 +123,7 @@ struct TransitionOffToOnVariant : public TransitionVariantCommon<PowerMode::OFF,
    static void setupCallExpectations(DisplayTransactionTest* test) {
        Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::ON);
        Case::EventThread::setupEnableVsyncCallExpectations(test);
        Case::DispSync::setupResetModelCallExpectations(test);
        Case::DispSync::setupStartPeriodTransitionCallExpectations(test);
        Case::setupRepaintEverythingCallExpectations(test);
    }

@@ -186,7 +184,7 @@ struct TransitionDozeSuspendToDozeVariant
    template <typename Case>
    static void setupCallExpectations(DisplayTransactionTest* test) {
        Case::EventThread::setupEnableVsyncCallExpectations(test);
        Case::DispSync::setupResetModelCallExpectations(test);
        Case::DispSync::setupStartPeriodTransitionCallExpectations(test);
        Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE);
    }
};
@@ -204,7 +202,7 @@ struct TransitionDozeSuspendToOnVariant
    template <typename Case>
    static void setupCallExpectations(DisplayTransactionTest* test) {
        Case::EventThread::setupEnableVsyncCallExpectations(test);
        Case::DispSync::setupResetModelCallExpectations(test);
        Case::DispSync::setupStartPeriodTransitionCallExpectations(test);
        Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::ON);
    }
};