Loading services/surfaceflinger/Scheduler/VSyncReactor.cpp +19 −0 Original line number Diff line number Diff line Loading @@ -89,10 +89,29 @@ nsecs_t VSyncReactor::expectedPresentTime() { void VSyncReactor::setPeriod(nsecs_t period) { mTracker->setPeriod(period); { std::lock_guard<std::mutex> lk(mMutex); mPeriodChangeInProgress = true; } } nsecs_t VSyncReactor::getPeriod() { return mTracker->currentPeriod(); } void VSyncReactor::beginResync() {} void VSyncReactor::endResync() {} bool VSyncReactor::addResyncSample(nsecs_t timestamp, bool* periodFlushed) { assert(periodFlushed); mTracker->addVsyncTimestamp(timestamp); { std::lock_guard<std::mutex> lk(mMutex); *periodFlushed = mPeriodChangeInProgress; mPeriodChangeInProgress = false; } return false; } } // namespace android::scheduler services/surfaceflinger/Scheduler/VSyncReactor.h +6 −0 Original line number Diff line number Diff line Loading @@ -43,6 +43,11 @@ public: void setPeriod(nsecs_t period); nsecs_t getPeriod(); // TODO: (b/145626181) remove begin,endResync functions from DispSync i/f when possible. void beginResync(); bool addResyncSample(nsecs_t timestamp, bool* periodFlushed); void endResync(); private: std::unique_ptr<Clock> const mClock; std::unique_ptr<VSyncDispatch> const mDispatch; Loading @@ -52,6 +57,7 @@ private: std::mutex mMutex; bool mIgnorePresentFences GUARDED_BY(mMutex) = false; std::vector<std::shared_ptr<FenceTime>> mUnfiredFences GUARDED_BY(mMutex); bool mPeriodChangeInProgress GUARDED_BY(mMutex) = false; }; } // namespace android::scheduler services/surfaceflinger/tests/unittests/VSyncReactorTest.cpp +20 −1 Original line number Diff line number Diff line Loading @@ -126,7 +126,7 @@ class VSyncReactorTest : public testing::Test { protected: VSyncReactorTest() : mMockDispatch(std::make_shared<MockVSyncDispatch>()), mMockTracker(std::make_shared<MockVSyncTracker>()), mMockTracker(std::make_shared<NiceMock<MockVSyncTracker>>()), mMockClock(std::make_shared<NiceMock<MockClock>>()), mReactor(std::make_unique<ClockWrapper>(mMockClock), std::make_unique<VSyncDispatchWrapper>(mMockDispatch), Loading Loading @@ -248,4 +248,23 @@ TEST_F(VSyncReactorTest, setPeriod) { mReactor.setPeriod(fakePeriod); } TEST_F(VSyncReactorTest, addResyncSampleTypical) { nsecs_t const fakeTimestamp = 3032; bool periodFlushed = false; EXPECT_CALL(*mMockTracker, addVsyncTimestamp(fakeTimestamp)); EXPECT_FALSE(mReactor.addResyncSample(fakeTimestamp, &periodFlushed)); EXPECT_FALSE(periodFlushed); } TEST_F(VSyncReactorTest, addResyncSamplePeriodChanges) { bool periodFlushed = false; nsecs_t const fakeTimestamp = 4398; nsecs_t const newPeriod = 3490; EXPECT_CALL(*mMockTracker, addVsyncTimestamp(fakeTimestamp)); mReactor.setPeriod(newPeriod); EXPECT_FALSE(mReactor.addResyncSample(fakeTimestamp, &periodFlushed)); EXPECT_TRUE(periodFlushed); } } // namespace android::scheduler Loading
services/surfaceflinger/Scheduler/VSyncReactor.cpp +19 −0 Original line number Diff line number Diff line Loading @@ -89,10 +89,29 @@ nsecs_t VSyncReactor::expectedPresentTime() { void VSyncReactor::setPeriod(nsecs_t period) { mTracker->setPeriod(period); { std::lock_guard<std::mutex> lk(mMutex); mPeriodChangeInProgress = true; } } nsecs_t VSyncReactor::getPeriod() { return mTracker->currentPeriod(); } void VSyncReactor::beginResync() {} void VSyncReactor::endResync() {} bool VSyncReactor::addResyncSample(nsecs_t timestamp, bool* periodFlushed) { assert(periodFlushed); mTracker->addVsyncTimestamp(timestamp); { std::lock_guard<std::mutex> lk(mMutex); *periodFlushed = mPeriodChangeInProgress; mPeriodChangeInProgress = false; } return false; } } // namespace android::scheduler
services/surfaceflinger/Scheduler/VSyncReactor.h +6 −0 Original line number Diff line number Diff line Loading @@ -43,6 +43,11 @@ public: void setPeriod(nsecs_t period); nsecs_t getPeriod(); // TODO: (b/145626181) remove begin,endResync functions from DispSync i/f when possible. void beginResync(); bool addResyncSample(nsecs_t timestamp, bool* periodFlushed); void endResync(); private: std::unique_ptr<Clock> const mClock; std::unique_ptr<VSyncDispatch> const mDispatch; Loading @@ -52,6 +57,7 @@ private: std::mutex mMutex; bool mIgnorePresentFences GUARDED_BY(mMutex) = false; std::vector<std::shared_ptr<FenceTime>> mUnfiredFences GUARDED_BY(mMutex); bool mPeriodChangeInProgress GUARDED_BY(mMutex) = false; }; } // namespace android::scheduler
services/surfaceflinger/tests/unittests/VSyncReactorTest.cpp +20 −1 Original line number Diff line number Diff line Loading @@ -126,7 +126,7 @@ class VSyncReactorTest : public testing::Test { protected: VSyncReactorTest() : mMockDispatch(std::make_shared<MockVSyncDispatch>()), mMockTracker(std::make_shared<MockVSyncTracker>()), mMockTracker(std::make_shared<NiceMock<MockVSyncTracker>>()), mMockClock(std::make_shared<NiceMock<MockClock>>()), mReactor(std::make_unique<ClockWrapper>(mMockClock), std::make_unique<VSyncDispatchWrapper>(mMockDispatch), Loading Loading @@ -248,4 +248,23 @@ TEST_F(VSyncReactorTest, setPeriod) { mReactor.setPeriod(fakePeriod); } TEST_F(VSyncReactorTest, addResyncSampleTypical) { nsecs_t const fakeTimestamp = 3032; bool periodFlushed = false; EXPECT_CALL(*mMockTracker, addVsyncTimestamp(fakeTimestamp)); EXPECT_FALSE(mReactor.addResyncSample(fakeTimestamp, &periodFlushed)); EXPECT_FALSE(periodFlushed); } TEST_F(VSyncReactorTest, addResyncSamplePeriodChanges) { bool periodFlushed = false; nsecs_t const fakeTimestamp = 4398; nsecs_t const newPeriod = 3490; EXPECT_CALL(*mMockTracker, addVsyncTimestamp(fakeTimestamp)); mReactor.setPeriod(newPeriod); EXPECT_FALSE(mReactor.addResyncSample(fakeTimestamp, &periodFlushed)); EXPECT_TRUE(periodFlushed); } } // namespace android::scheduler