Loading services/surfaceflinger/Scheduler/VSyncReactor.cpp +18 −6 Original line number Original line Diff line number Diff line Loading @@ -175,10 +175,25 @@ nsecs_t VSyncReactor::expectedPresentTime() { return mTracker->nextAnticipatedVSyncTimeFrom(mClock->now()); return mTracker->nextAnticipatedVSyncTimeFrom(mClock->now()); } } void VSyncReactor::startPeriodTransition(nsecs_t newPeriod) { mPeriodTransitioningTo = newPeriod; mMoreSamplesNeeded = true; } void VSyncReactor::endPeriodTransition() { mPeriodTransitioningTo.reset(); mLastHwVsync.reset(); mMoreSamplesNeeded = false; } void VSyncReactor::setPeriod(nsecs_t period) { void VSyncReactor::setPeriod(nsecs_t period) { std::lock_guard lk(mMutex); std::lock_guard lk(mMutex); mLastHwVsync.reset(); mLastHwVsync.reset(); mPeriodTransitioningTo = period; if (period == getPeriod()) { endPeriodTransition(); } else { startPeriodTransition(period); } } } nsecs_t VSyncReactor::getPeriod() { nsecs_t VSyncReactor::getPeriod() { Loading @@ -202,16 +217,13 @@ bool VSyncReactor::addResyncSample(nsecs_t timestamp, bool* periodFlushed) { std::lock_guard<std::mutex> lk(mMutex); std::lock_guard<std::mutex> lk(mMutex); if (periodChangeDetected(timestamp)) { if (periodChangeDetected(timestamp)) { mMoreSamplesNeeded = false; *periodFlushed = true; mTracker->setPeriod(*mPeriodTransitioningTo); mTracker->setPeriod(*mPeriodTransitioningTo); for (auto& entry : mCallbacks) { for (auto& entry : mCallbacks) { entry.second->setPeriod(*mPeriodTransitioningTo); entry.second->setPeriod(*mPeriodTransitioningTo); } } mPeriodTransitioningTo.reset(); endPeriodTransition(); mLastHwVsync.reset(); *periodFlushed = true; } else if (mPeriodTransitioningTo) { } else if (mPeriodTransitioningTo) { mLastHwVsync = timestamp; mLastHwVsync = timestamp; mMoreSamplesNeeded = true; mMoreSamplesNeeded = true; Loading services/surfaceflinger/Scheduler/VSyncReactor.h +2 −0 Original line number Original line Diff line number Diff line Loading @@ -61,6 +61,8 @@ public: void reset() final; void reset() final; private: private: void startPeriodTransition(nsecs_t newPeriod) REQUIRES(mMutex); void endPeriodTransition() REQUIRES(mMutex); bool periodChangeDetected(nsecs_t vsync_timestamp) REQUIRES(mMutex); bool periodChangeDetected(nsecs_t vsync_timestamp) REQUIRES(mMutex); std::unique_ptr<Clock> const mClock; std::unique_ptr<Clock> const mClock; Loading services/surfaceflinger/tests/unittests/VSyncReactorTest.cpp +40 −0 Original line number Original line Diff line number Diff line Loading @@ -292,6 +292,46 @@ TEST_F(VSyncReactorTest, setPeriodCalledOnceConfirmedChange) { EXPECT_TRUE(periodFlushed); EXPECT_TRUE(periodFlushed); } } TEST_F(VSyncReactorTest, changingPeriodBackAbortsConfirmationProcess) { nsecs_t sampleTime = 0; nsecs_t const newPeriod = 5000; mReactor.setPeriod(newPeriod); bool periodFlushed = true; EXPECT_TRUE(mReactor.addResyncSample(sampleTime += period, &periodFlushed)); EXPECT_FALSE(periodFlushed); EXPECT_TRUE(mReactor.addResyncSample(sampleTime += period, &periodFlushed)); EXPECT_FALSE(periodFlushed); mReactor.setPeriod(period); EXPECT_FALSE(mReactor.addResyncSample(sampleTime += period, &periodFlushed)); EXPECT_FALSE(periodFlushed); } TEST_F(VSyncReactorTest, changingToAThirdPeriodWillWaitForLastPeriod) { nsecs_t sampleTime = 0; nsecs_t const secondPeriod = 5000; nsecs_t const thirdPeriod = 2000; mReactor.setPeriod(secondPeriod); bool periodFlushed = true; EXPECT_TRUE(mReactor.addResyncSample(sampleTime += period, &periodFlushed)); EXPECT_FALSE(periodFlushed); EXPECT_TRUE(mReactor.addResyncSample(sampleTime += period, &periodFlushed)); EXPECT_FALSE(periodFlushed); mReactor.setPeriod(thirdPeriod); EXPECT_TRUE(mReactor.addResyncSample(sampleTime += secondPeriod, &periodFlushed)); EXPECT_FALSE(periodFlushed); EXPECT_FALSE(mReactor.addResyncSample(sampleTime += thirdPeriod, &periodFlushed)); EXPECT_TRUE(periodFlushed); } TEST_F(VSyncReactorTest, presentFenceAdditionDoesNotInterruptConfirmationProcess) { nsecs_t const newPeriod = 5000; mReactor.setPeriod(newPeriod); EXPECT_TRUE(mReactor.addPresentFence(generateSignalledFenceWithTime(0))); } TEST_F(VSyncReactorTest, setPeriodCalledFirstTwoEventsNewPeriod) { TEST_F(VSyncReactorTest, setPeriodCalledFirstTwoEventsNewPeriod) { nsecs_t const newPeriod = 5000; nsecs_t const newPeriod = 5000; EXPECT_CALL(*mMockTracker, setPeriod(_)).Times(0); EXPECT_CALL(*mMockTracker, setPeriod(_)).Times(0); Loading Loading
services/surfaceflinger/Scheduler/VSyncReactor.cpp +18 −6 Original line number Original line Diff line number Diff line Loading @@ -175,10 +175,25 @@ nsecs_t VSyncReactor::expectedPresentTime() { return mTracker->nextAnticipatedVSyncTimeFrom(mClock->now()); return mTracker->nextAnticipatedVSyncTimeFrom(mClock->now()); } } void VSyncReactor::startPeriodTransition(nsecs_t newPeriod) { mPeriodTransitioningTo = newPeriod; mMoreSamplesNeeded = true; } void VSyncReactor::endPeriodTransition() { mPeriodTransitioningTo.reset(); mLastHwVsync.reset(); mMoreSamplesNeeded = false; } void VSyncReactor::setPeriod(nsecs_t period) { void VSyncReactor::setPeriod(nsecs_t period) { std::lock_guard lk(mMutex); std::lock_guard lk(mMutex); mLastHwVsync.reset(); mLastHwVsync.reset(); mPeriodTransitioningTo = period; if (period == getPeriod()) { endPeriodTransition(); } else { startPeriodTransition(period); } } } nsecs_t VSyncReactor::getPeriod() { nsecs_t VSyncReactor::getPeriod() { Loading @@ -202,16 +217,13 @@ bool VSyncReactor::addResyncSample(nsecs_t timestamp, bool* periodFlushed) { std::lock_guard<std::mutex> lk(mMutex); std::lock_guard<std::mutex> lk(mMutex); if (periodChangeDetected(timestamp)) { if (periodChangeDetected(timestamp)) { mMoreSamplesNeeded = false; *periodFlushed = true; mTracker->setPeriod(*mPeriodTransitioningTo); mTracker->setPeriod(*mPeriodTransitioningTo); for (auto& entry : mCallbacks) { for (auto& entry : mCallbacks) { entry.second->setPeriod(*mPeriodTransitioningTo); entry.second->setPeriod(*mPeriodTransitioningTo); } } mPeriodTransitioningTo.reset(); endPeriodTransition(); mLastHwVsync.reset(); *periodFlushed = true; } else if (mPeriodTransitioningTo) { } else if (mPeriodTransitioningTo) { mLastHwVsync = timestamp; mLastHwVsync = timestamp; mMoreSamplesNeeded = true; mMoreSamplesNeeded = true; Loading
services/surfaceflinger/Scheduler/VSyncReactor.h +2 −0 Original line number Original line Diff line number Diff line Loading @@ -61,6 +61,8 @@ public: void reset() final; void reset() final; private: private: void startPeriodTransition(nsecs_t newPeriod) REQUIRES(mMutex); void endPeriodTransition() REQUIRES(mMutex); bool periodChangeDetected(nsecs_t vsync_timestamp) REQUIRES(mMutex); bool periodChangeDetected(nsecs_t vsync_timestamp) REQUIRES(mMutex); std::unique_ptr<Clock> const mClock; std::unique_ptr<Clock> const mClock; Loading
services/surfaceflinger/tests/unittests/VSyncReactorTest.cpp +40 −0 Original line number Original line Diff line number Diff line Loading @@ -292,6 +292,46 @@ TEST_F(VSyncReactorTest, setPeriodCalledOnceConfirmedChange) { EXPECT_TRUE(periodFlushed); EXPECT_TRUE(periodFlushed); } } TEST_F(VSyncReactorTest, changingPeriodBackAbortsConfirmationProcess) { nsecs_t sampleTime = 0; nsecs_t const newPeriod = 5000; mReactor.setPeriod(newPeriod); bool periodFlushed = true; EXPECT_TRUE(mReactor.addResyncSample(sampleTime += period, &periodFlushed)); EXPECT_FALSE(periodFlushed); EXPECT_TRUE(mReactor.addResyncSample(sampleTime += period, &periodFlushed)); EXPECT_FALSE(periodFlushed); mReactor.setPeriod(period); EXPECT_FALSE(mReactor.addResyncSample(sampleTime += period, &periodFlushed)); EXPECT_FALSE(periodFlushed); } TEST_F(VSyncReactorTest, changingToAThirdPeriodWillWaitForLastPeriod) { nsecs_t sampleTime = 0; nsecs_t const secondPeriod = 5000; nsecs_t const thirdPeriod = 2000; mReactor.setPeriod(secondPeriod); bool periodFlushed = true; EXPECT_TRUE(mReactor.addResyncSample(sampleTime += period, &periodFlushed)); EXPECT_FALSE(periodFlushed); EXPECT_TRUE(mReactor.addResyncSample(sampleTime += period, &periodFlushed)); EXPECT_FALSE(periodFlushed); mReactor.setPeriod(thirdPeriod); EXPECT_TRUE(mReactor.addResyncSample(sampleTime += secondPeriod, &periodFlushed)); EXPECT_FALSE(periodFlushed); EXPECT_FALSE(mReactor.addResyncSample(sampleTime += thirdPeriod, &periodFlushed)); EXPECT_TRUE(periodFlushed); } TEST_F(VSyncReactorTest, presentFenceAdditionDoesNotInterruptConfirmationProcess) { nsecs_t const newPeriod = 5000; mReactor.setPeriod(newPeriod); EXPECT_TRUE(mReactor.addPresentFence(generateSignalledFenceWithTime(0))); } TEST_F(VSyncReactorTest, setPeriodCalledFirstTwoEventsNewPeriod) { TEST_F(VSyncReactorTest, setPeriodCalledFirstTwoEventsNewPeriod) { nsecs_t const newPeriod = 5000; nsecs_t const newPeriod = 5000; EXPECT_CALL(*mMockTracker, setPeriod(_)).Times(0); EXPECT_CALL(*mMockTracker, setPeriod(_)).Times(0); Loading