From ee2ad9f4d1039fd2603818cd66233e2791277f5b Mon Sep 17 00:00:00 2001 From: Kevin DuBois Date: Thu, 21 Nov 2019 11:10:57 -0800 Subject: SF: VSyncReactor add period modification functions Adds 2 more functions from the DispSync interface to VSyncReactor, {get,set}Period Bug: 140303479 Test: 2 new units Change-Id: Ie0084597c80d6d43099201fb49b71ae9badea3ee --- services/surfaceflinger/Scheduler/VSyncReactor.cpp | 8 ++++++++ services/surfaceflinger/Scheduler/VSyncReactor.h | 3 +++ services/surfaceflinger/Scheduler/VSyncTracker.h | 7 +++++++ .../tests/unittests/VSyncDispatchRealtimeTest.cpp | 4 ++++ .../tests/unittests/VSyncDispatchTimerQueueTest.cpp | 1 + .../surfaceflinger/tests/unittests/VSyncReactorTest.cpp | 14 ++++++++++++++ 6 files changed, 37 insertions(+) diff --git a/services/surfaceflinger/Scheduler/VSyncReactor.cpp b/services/surfaceflinger/Scheduler/VSyncReactor.cpp index 9ce440c084..6588d1b9ad 100644 --- a/services/surfaceflinger/Scheduler/VSyncReactor.cpp +++ b/services/surfaceflinger/Scheduler/VSyncReactor.cpp @@ -87,4 +87,12 @@ nsecs_t VSyncReactor::expectedPresentTime() { return mTracker->nextAnticipatedVSyncTimeFrom(mClock->now()); } +void VSyncReactor::setPeriod(nsecs_t period) { + mTracker->setPeriod(period); +} + +nsecs_t VSyncReactor::getPeriod() { + return mTracker->currentPeriod(); +} + } // namespace android::scheduler diff --git a/services/surfaceflinger/Scheduler/VSyncReactor.h b/services/surfaceflinger/Scheduler/VSyncReactor.h index 8436e8a8ce..73a09f1cb7 100644 --- a/services/surfaceflinger/Scheduler/VSyncReactor.h +++ b/services/surfaceflinger/Scheduler/VSyncReactor.h @@ -40,6 +40,9 @@ public: nsecs_t computeNextRefresh(int periodOffset) const; nsecs_t expectedPresentTime(); + void setPeriod(nsecs_t period); + nsecs_t getPeriod(); + private: std::unique_ptr const mClock; std::unique_ptr const mDispatch; diff --git a/services/surfaceflinger/Scheduler/VSyncTracker.h b/services/surfaceflinger/Scheduler/VSyncTracker.h index 335042d430..6be63fe9d2 100644 --- a/services/surfaceflinger/Scheduler/VSyncTracker.h +++ b/services/surfaceflinger/Scheduler/VSyncTracker.h @@ -54,6 +54,13 @@ public: */ virtual nsecs_t currentPeriod() const = 0; + /* + * Inform the tracker that the period is changing and the tracker needs to recalibrate itself. + * + * \param [in] period The period that the system is changing into. + */ + virtual void setPeriod(nsecs_t period) = 0; + protected: VSyncTracker(VSyncTracker const&) = delete; VSyncTracker& operator=(VSyncTracker const&) = delete; diff --git a/services/surfaceflinger/tests/unittests/VSyncDispatchRealtimeTest.cpp b/services/surfaceflinger/tests/unittests/VSyncDispatchRealtimeTest.cpp index 448954fbf4..484947d3f3 100644 --- a/services/surfaceflinger/tests/unittests/VSyncDispatchRealtimeTest.cpp +++ b/services/surfaceflinger/tests/unittests/VSyncDispatchRealtimeTest.cpp @@ -49,6 +49,8 @@ public: nsecs_t currentPeriod() const final { return mPeriod; } + void setPeriod(nsecs_t) final {} + private: nsecs_t const mPeriod; }; @@ -80,6 +82,8 @@ public: return mPeriod; } + void setPeriod(nsecs_t) final {} + private: std::mutex mutable mMutex; nsecs_t mPeriod; diff --git a/services/surfaceflinger/tests/unittests/VSyncDispatchTimerQueueTest.cpp b/services/surfaceflinger/tests/unittests/VSyncDispatchTimerQueueTest.cpp index 6a9b67cbc1..d668a41bf1 100644 --- a/services/surfaceflinger/tests/unittests/VSyncDispatchTimerQueueTest.cpp +++ b/services/surfaceflinger/tests/unittests/VSyncDispatchTimerQueueTest.cpp @@ -40,6 +40,7 @@ public: MOCK_METHOD1(addVsyncTimestamp, void(nsecs_t)); MOCK_CONST_METHOD1(nextAnticipatedVSyncTimeFrom, nsecs_t(nsecs_t)); MOCK_CONST_METHOD0(currentPeriod, nsecs_t()); + MOCK_METHOD1(setPeriod, void(nsecs_t)); nsecs_t nextVSyncTime(nsecs_t timePoint) const { if (timePoint % mPeriod == 0) { diff --git a/services/surfaceflinger/tests/unittests/VSyncReactorTest.cpp b/services/surfaceflinger/tests/unittests/VSyncReactorTest.cpp index c8784c686b..2e01d5c598 100644 --- a/services/surfaceflinger/tests/unittests/VSyncReactorTest.cpp +++ b/services/surfaceflinger/tests/unittests/VSyncReactorTest.cpp @@ -38,6 +38,7 @@ public: MOCK_METHOD1(addVsyncTimestamp, void(nsecs_t)); MOCK_CONST_METHOD1(nextAnticipatedVSyncTimeFrom, nsecs_t(nsecs_t)); MOCK_CONST_METHOD0(currentPeriod, nsecs_t()); + MOCK_METHOD1(setPeriod, void(nsecs_t)); }; class VSyncTrackerWrapper : public VSyncTracker { @@ -49,6 +50,7 @@ public: return mTracker->nextAnticipatedVSyncTimeFrom(timePoint); } nsecs_t currentPeriod() const final { return mTracker->currentPeriod(); } + void setPeriod(nsecs_t period) { mTracker->setPeriod(period); } private: std::shared_ptr const mTracker; @@ -234,4 +236,16 @@ TEST_F(VSyncReactorTest, queriesTrackerForNextRefreshFuture) { EXPECT_THAT(mReactor.computeNextRefresh(numPeriodsOut), Eq(fakeTimestamp)); } +TEST_F(VSyncReactorTest, getPeriod) { + nsecs_t const fakePeriod = 1010; + EXPECT_CALL(*mMockTracker, currentPeriod()).WillOnce(Return(fakePeriod)); + EXPECT_THAT(mReactor.getPeriod(), Eq(fakePeriod)); +} + +TEST_F(VSyncReactorTest, setPeriod) { + nsecs_t const fakePeriod = 4098; + EXPECT_CALL(*mMockTracker, setPeriod(fakePeriod)); + mReactor.setPeriod(fakePeriod); +} + } // namespace android::scheduler -- cgit v1.2.3-59-g8ed1b