summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author TreeHugger Robot <treehugger-gerrit@google.com> 2019-12-03 19:32:06 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2019-12-03 19:32:06 +0000
commit2e153088bdadf0e8bef0aec21d82bcdc4bf2eee4 (patch)
tree88749ef3ccc219ba7a29805357f00e11871d8eb6
parentb8fb471b4ceb549f270645451164634b4e13034c (diff)
parentee2ad9f4d1039fd2603818cd66233e2791277f5b (diff)
Merge "SF: VSyncReactor add period modification functions"
-rw-r--r--services/surfaceflinger/Scheduler/VSyncReactor.cpp8
-rw-r--r--services/surfaceflinger/Scheduler/VSyncReactor.h3
-rw-r--r--services/surfaceflinger/Scheduler/VSyncTracker.h7
-rw-r--r--services/surfaceflinger/tests/unittests/VSyncDispatchRealtimeTest.cpp4
-rw-r--r--services/surfaceflinger/tests/unittests/VSyncDispatchTimerQueueTest.cpp1
-rw-r--r--services/surfaceflinger/tests/unittests/VSyncReactorTest.cpp14
6 files changed, 37 insertions, 0 deletions
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<Clock> const mClock;
std::unique_ptr<VSyncDispatch> 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<VSyncTracker> 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