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
diff --git a/services/surfaceflinger/Scheduler/VSyncReactor.cpp b/services/surfaceflinger/Scheduler/VSyncReactor.cpp
index 9ce440c..6588d1b 100644
--- a/services/surfaceflinger/Scheduler/VSyncReactor.cpp
+++ b/services/surfaceflinger/Scheduler/VSyncReactor.cpp
@@ -87,4 +87,12 @@
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 8436e8a..73a09f1 100644
--- a/services/surfaceflinger/Scheduler/VSyncReactor.h
+++ b/services/surfaceflinger/Scheduler/VSyncReactor.h
@@ -40,6 +40,9 @@
nsecs_t computeNextRefresh(int periodOffset) const;
nsecs_t expectedPresentTime();
+ void setPeriod(nsecs_t period);
+ nsecs_t getPeriod();
+
private:
std::unique_ptr<Clock> const mClock;
std::unique_ptr<VSyncDispatch> const mDispatch;
diff --git a/services/surfaceflinger/Scheduler/VSyncTracker.h b/services/surfaceflinger/Scheduler/VSyncTracker.h
index 335042d..6be63fe 100644
--- a/services/surfaceflinger/Scheduler/VSyncTracker.h
+++ b/services/surfaceflinger/Scheduler/VSyncTracker.h
@@ -54,6 +54,13 @@
*/
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 448954f..484947d 100644
--- a/services/surfaceflinger/tests/unittests/VSyncDispatchRealtimeTest.cpp
+++ b/services/surfaceflinger/tests/unittests/VSyncDispatchRealtimeTest.cpp
@@ -49,6 +49,8 @@
nsecs_t currentPeriod() const final { return mPeriod; }
+ void setPeriod(nsecs_t) final {}
+
private:
nsecs_t const mPeriod;
};
@@ -80,6 +82,8 @@
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 6a9b67c..d668a41 100644
--- a/services/surfaceflinger/tests/unittests/VSyncDispatchTimerQueueTest.cpp
+++ b/services/surfaceflinger/tests/unittests/VSyncDispatchTimerQueueTest.cpp
@@ -40,6 +40,7 @@
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 c8784c6..2e01d5c 100644
--- a/services/surfaceflinger/tests/unittests/VSyncReactorTest.cpp
+++ b/services/surfaceflinger/tests/unittests/VSyncReactorTest.cpp
@@ -38,6 +38,7 @@
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 @@
return mTracker->nextAnticipatedVSyncTimeFrom(timePoint);
}
nsecs_t currentPeriod() const final { return mTracker->currentPeriod(); }
+ void setPeriod(nsecs_t period) { mTracker->setPeriod(period); }
private:
std::shared_ptr<VSyncTracker> const mTracker;
@@ -234,4 +236,16 @@
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