diff options
7 files changed, 47 insertions, 42 deletions
diff --git a/services/surfaceflinger/Scheduler/DispSyncSource.cpp b/services/surfaceflinger/Scheduler/DispSyncSource.cpp index 50b38c9cf6..c593340625 100644 --- a/services/surfaceflinger/Scheduler/DispSyncSource.cpp +++ b/services/surfaceflinger/Scheduler/DispSyncSource.cpp @@ -180,7 +180,7 @@ void DispSyncSource::onVsyncCallback(nsecs_t vsyncTime, nsecs_t targetWakeupTime } if (callback != nullptr) { - callback->onVSyncEvent(targetWakeupTime, vsyncTime, readyTime); + callback->onVSyncEvent(targetWakeupTime, {vsyncTime, readyTime}); } } diff --git a/services/surfaceflinger/Scheduler/EventThread.cpp b/services/surfaceflinger/Scheduler/EventThread.cpp index b57ffceb27..adc1009731 100644 --- a/services/surfaceflinger/Scheduler/EventThread.cpp +++ b/services/surfaceflinger/Scheduler/EventThread.cpp @@ -350,13 +350,13 @@ void EventThread::onScreenAcquired() { mCondition.notify_all(); } -void EventThread::onVSyncEvent(nsecs_t timestamp, nsecs_t expectedVSyncTimestamp, - nsecs_t deadlineTimestamp) { +void EventThread::onVSyncEvent(nsecs_t timestamp, VSyncSource::VSyncData vsyncData) { std::lock_guard<std::mutex> lock(mMutex); LOG_FATAL_IF(!mVSyncState); mPendingEvents.push_back(makeVSync(mVSyncState->displayId, timestamp, ++mVSyncState->count, - expectedVSyncTimestamp, deadlineTimestamp)); + vsyncData.expectedVSyncTimestamp, + vsyncData.deadlineTimestamp)); mCondition.notify_all(); } diff --git a/services/surfaceflinger/Scheduler/EventThread.h b/services/surfaceflinger/Scheduler/EventThread.h index fa9af098f6..c3b9129744 100644 --- a/services/surfaceflinger/Scheduler/EventThread.h +++ b/services/surfaceflinger/Scheduler/EventThread.h @@ -62,11 +62,16 @@ enum class VSyncRequest { class VSyncSource { public: + class VSyncData { + public: + nsecs_t expectedVSyncTimestamp; + nsecs_t deadlineTimestamp; + }; + class Callback { public: virtual ~Callback() {} - virtual void onVSyncEvent(nsecs_t when, nsecs_t expectedVSyncTimestamp, - nsecs_t deadlineTimestamp) = 0; + virtual void onVSyncEvent(nsecs_t when, VSyncData vsyncData) = 0; }; virtual ~VSyncSource() {} @@ -201,8 +206,7 @@ private: REQUIRES(mMutex); // Implements VSyncSource::Callback - void onVSyncEvent(nsecs_t timestamp, nsecs_t expectedVSyncTimestamp, - nsecs_t deadlineTimestamp) override; + void onVSyncEvent(nsecs_t timestamp, VSyncSource::VSyncData vsyncData) override; int64_t generateToken(nsecs_t timestamp, nsecs_t deadlineTimestamp, nsecs_t expectedVSyncTimestamp) const; diff --git a/services/surfaceflinger/Scheduler/InjectVSyncSource.h b/services/surfaceflinger/Scheduler/InjectVSyncSource.h index 016b076444..7b93f1eb13 100644 --- a/services/surfaceflinger/Scheduler/InjectVSyncSource.h +++ b/services/surfaceflinger/Scheduler/InjectVSyncSource.h @@ -39,7 +39,7 @@ public: nsecs_t deadlineTimestamp) { std::lock_guard<std::mutex> lock(mCallbackMutex); if (mCallback) { - mCallback->onVSyncEvent(when, expectedVSyncTimestamp, deadlineTimestamp); + mCallback->onVSyncEvent(when, {expectedVSyncTimestamp, deadlineTimestamp}); } } diff --git a/services/surfaceflinger/fuzzer/surfaceflinger_scheduler_fuzzer.cpp b/services/surfaceflinger/fuzzer/surfaceflinger_scheduler_fuzzer.cpp index 51a50818ba..06bbfd26c2 100644 --- a/services/surfaceflinger/fuzzer/surfaceflinger_scheduler_fuzzer.cpp +++ b/services/surfaceflinger/fuzzer/surfaceflinger_scheduler_fuzzer.cpp @@ -63,8 +63,7 @@ private: FuzzedDataProvider mFdp; protected: - void onVSyncEvent(nsecs_t /* when */, nsecs_t /* expectedVSyncTimestamp */, - nsecs_t /* deadlineTimestamp */) {} + void onVSyncEvent(nsecs_t /* when */, VSyncSource::VSyncData) {} }; PhysicalDisplayId SchedulerFuzzer::getPhysicalDisplayId() { diff --git a/services/surfaceflinger/tests/unittests/DispSyncSourceTest.cpp b/services/surfaceflinger/tests/unittests/DispSyncSourceTest.cpp index f613e43324..5a0ea352d5 100644 --- a/services/surfaceflinger/tests/unittests/DispSyncSourceTest.cpp +++ b/services/surfaceflinger/tests/unittests/DispSyncSourceTest.cpp @@ -128,13 +128,12 @@ protected: void createDispSync(); void createDispSyncSource(); - void onVSyncEvent(nsecs_t when, nsecs_t expectedVSyncTimestamp, - nsecs_t deadlineTimestamp) override; + void onVSyncEvent(nsecs_t when, VSyncSource::VSyncData) override; std::unique_ptr<MockVSyncDispatch> mVSyncDispatch; std::unique_ptr<scheduler::DispSyncSource> mDispSyncSource; - AsyncCallRecorder<void (*)(nsecs_t, nsecs_t, nsecs_t)> mVSyncEventCallRecorder; + AsyncCallRecorder<void (*)(nsecs_t, VSyncSource::VSyncData)> mVSyncEventCallRecorder; static constexpr std::chrono::nanoseconds mWorkDuration = 20ms; static constexpr std::chrono::nanoseconds mReadyDuration = 10ms; @@ -155,11 +154,10 @@ DispSyncSourceTest::~DispSyncSourceTest() { ALOGD("**** Tearing down after %s.%s\n", test_info->test_case_name(), test_info->name()); } -void DispSyncSourceTest::onVSyncEvent(nsecs_t when, nsecs_t expectedVSyncTimestamp, - nsecs_t deadlineTimestamp) { +void DispSyncSourceTest::onVSyncEvent(nsecs_t when, VSyncSource::VSyncData vsyncData) { ALOGD("onVSyncEvent: %" PRId64, when); - mVSyncEventCallRecorder.recordCall(when, expectedVSyncTimestamp, deadlineTimestamp); + mVSyncEventCallRecorder.recordCall(when, vsyncData); } void DispSyncSourceTest::createDispSync() { @@ -233,8 +231,10 @@ TEST_F(DispSyncSourceTest, waitForCallbacks) { mVSyncDispatch->triggerCallbacks(); const auto callbackData = mVSyncEventCallRecorder.waitForCall(); ASSERT_TRUE(callbackData.has_value()); - const auto [when, expectedVSyncTimestamp, deadlineTimestamp] = callbackData.value(); - EXPECT_EQ(when, expectedVSyncTimestamp - mWorkDuration.count() - mReadyDuration.count()); + const auto [when, vsyncData] = callbackData.value(); + EXPECT_EQ(when, + vsyncData.expectedVSyncTimestamp - mWorkDuration.count() - + mReadyDuration.count()); } } @@ -265,8 +265,10 @@ TEST_F(DispSyncSourceTest, waitForCallbacksWithDurationChange) { mVSyncDispatch->triggerCallbacks(); const auto callbackData = mVSyncEventCallRecorder.waitForCall(); ASSERT_TRUE(callbackData.has_value()); - const auto [when, expectedVSyncTimestamp, deadlineTimestamp] = callbackData.value(); - EXPECT_EQ(when, expectedVSyncTimestamp - mWorkDuration.count() - mReadyDuration.count()); + const auto [when, vsyncData] = callbackData.value(); + EXPECT_EQ(when, + vsyncData.expectedVSyncTimestamp - mWorkDuration.count() - + mReadyDuration.count()); } const auto newDuration = mWorkDuration / 2; @@ -286,8 +288,8 @@ TEST_F(DispSyncSourceTest, waitForCallbacksWithDurationChange) { mVSyncDispatch->triggerCallbacks(); const auto callbackData = mVSyncEventCallRecorder.waitForCall(); ASSERT_TRUE(callbackData.has_value()); - const auto [when, expectedVSyncTimestamp, deadlineTimestamp] = callbackData.value(); - EXPECT_EQ(when, expectedVSyncTimestamp - newDuration.count()); + const auto [when, vsyncData] = callbackData.value(); + EXPECT_EQ(when, vsyncData.expectedVSyncTimestamp - newDuration.count()); } EXPECT_CALL(*mVSyncDispatch, cancel(_)).Times(1); diff --git a/services/surfaceflinger/tests/unittests/EventThreadTest.cpp b/services/surfaceflinger/tests/unittests/EventThreadTest.cpp index 7761828849..e5f7b03732 100644 --- a/services/surfaceflinger/tests/unittests/EventThreadTest.cpp +++ b/services/surfaceflinger/tests/unittests/EventThreadTest.cpp @@ -368,7 +368,7 @@ TEST_F(EventThreadTest, requestNextVsyncPostsASingleVSyncEventToTheConnection) { // Use the received callback to signal a first vsync event. // The interceptor should receive the event, as well as the connection. - mCallback->onVSyncEvent(123, 456, 789); + mCallback->onVSyncEvent(123, {456, 789}); expectInterceptCallReceived(123); expectThrottleVsyncReceived(456, mConnectionUid); expectVsyncEventReceivedByConnection(123, 1u); @@ -376,7 +376,7 @@ TEST_F(EventThreadTest, requestNextVsyncPostsASingleVSyncEventToTheConnection) { // Use the received callback to signal a second vsync event. // The interceptor should receive the event, but the connection should // not as it was only interested in the first. - mCallback->onVSyncEvent(456, 123, 0); + mCallback->onVSyncEvent(456, {123, 0}); expectInterceptCallReceived(456); EXPECT_FALSE(mThrottleVsyncCallRecorder.waitForUnexpectedCall().has_value()); EXPECT_FALSE(mConnectionEventCallRecorder.waitForUnexpectedCall().has_value()); @@ -394,7 +394,7 @@ TEST_F(EventThreadTest, requestNextVsyncEventFrameTimelinesCorrect) { // Use the received callback to signal a vsync event. // The interceptor should receive the event, as well as the connection. - mCallback->onVSyncEvent(123, 456, 789); + mCallback->onVSyncEvent(123, {456, 789}); expectInterceptCallReceived(123); expectVsyncEventFrameTimelinesCorrect(123, 789); } @@ -421,7 +421,7 @@ TEST_F(EventThreadTest, setVsyncRateZeroPostsNoVSyncEventsToThatConnection) { // Send a vsync event. EventThread should then make a call to the // interceptor, and the second connection. The first connection should not // get the event. - mCallback->onVSyncEvent(123, 456, 0); + mCallback->onVSyncEvent(123, {456, 0}); expectInterceptCallReceived(123); EXPECT_FALSE(firstConnectionEventRecorder.waitForUnexpectedCall().has_value()); expectVsyncEventReceivedByConnection("secondConnection", secondConnectionEventRecorder, 123, @@ -436,19 +436,19 @@ TEST_F(EventThreadTest, setVsyncRateOnePostsAllEventsToThatConnection) { // Send a vsync event. EventThread should then make a call to the // interceptor, and the connection. - mCallback->onVSyncEvent(123, 456, 789); + mCallback->onVSyncEvent(123, {456, 789}); expectInterceptCallReceived(123); expectThrottleVsyncReceived(456, mConnectionUid); expectVsyncEventReceivedByConnection(123, 1u); // A second event should go to the same places. - mCallback->onVSyncEvent(456, 123, 0); + mCallback->onVSyncEvent(456, {123, 0}); expectInterceptCallReceived(456); expectThrottleVsyncReceived(123, mConnectionUid); expectVsyncEventReceivedByConnection(456, 2u); // A third event should go to the same places. - mCallback->onVSyncEvent(789, 777, 111); + mCallback->onVSyncEvent(789, {777, 111}); expectInterceptCallReceived(789); expectThrottleVsyncReceived(777, mConnectionUid); expectVsyncEventReceivedByConnection(789, 3u); @@ -461,25 +461,25 @@ TEST_F(EventThreadTest, setVsyncRateTwoPostsEveryOtherEventToThatConnection) { expectVSyncSetEnabledCallReceived(true); // The first event will be seen by the interceptor, and not the connection. - mCallback->onVSyncEvent(123, 456, 789); + mCallback->onVSyncEvent(123, {456, 789}); expectInterceptCallReceived(123); EXPECT_FALSE(mConnectionEventCallRecorder.waitForUnexpectedCall().has_value()); EXPECT_FALSE(mThrottleVsyncCallRecorder.waitForUnexpectedCall().has_value()); // The second event will be seen by the interceptor and the connection. - mCallback->onVSyncEvent(456, 123, 0); + mCallback->onVSyncEvent(456, {123, 0}); expectInterceptCallReceived(456); expectVsyncEventReceivedByConnection(456, 2u); EXPECT_FALSE(mThrottleVsyncCallRecorder.waitForUnexpectedCall().has_value()); // The third event will be seen by the interceptor, and not the connection. - mCallback->onVSyncEvent(789, 777, 744); + mCallback->onVSyncEvent(789, {777, 744}); expectInterceptCallReceived(789); EXPECT_FALSE(mConnectionEventCallRecorder.waitForUnexpectedCall().has_value()); EXPECT_FALSE(mThrottleVsyncCallRecorder.waitForUnexpectedCall().has_value()); // The fourth event will be seen by the interceptor and the connection. - mCallback->onVSyncEvent(101112, 7847, 86); + mCallback->onVSyncEvent(101112, {7847, 86}); expectInterceptCallReceived(101112); expectVsyncEventReceivedByConnection(101112, 4u); } @@ -494,7 +494,7 @@ TEST_F(EventThreadTest, connectionsRemovedIfInstanceDestroyed) { mConnection = nullptr; // The first event will be seen by the interceptor, and not the connection. - mCallback->onVSyncEvent(123, 456, 789); + mCallback->onVSyncEvent(123, {456, 789}); expectInterceptCallReceived(123); EXPECT_FALSE(mConnectionEventCallRecorder.waitForUnexpectedCall().has_value()); @@ -512,13 +512,13 @@ TEST_F(EventThreadTest, connectionsRemovedIfEventDeliveryError) { // The first event will be seen by the interceptor, and by the connection, // which then returns an error. - mCallback->onVSyncEvent(123, 456, 789); + mCallback->onVSyncEvent(123, {456, 789}); expectInterceptCallReceived(123); expectVsyncEventReceivedByConnection("errorConnection", errorConnectionEventRecorder, 123, 1u); // A subsequent event will be seen by the interceptor and not by the // connection. - mCallback->onVSyncEvent(456, 123, 0); + mCallback->onVSyncEvent(456, {123, 0}); expectInterceptCallReceived(456); EXPECT_FALSE(errorConnectionEventRecorder.waitForUnexpectedCall().has_value()); @@ -543,7 +543,7 @@ TEST_F(EventThreadTest, tracksEventConnections) { // The first event will be seen by the interceptor, and by the connection, // which then returns an error. - mCallback->onVSyncEvent(123, 456, 789); + mCallback->onVSyncEvent(123, {456, 789}); expectInterceptCallReceived(123); expectVsyncEventReceivedByConnection("errorConnection", errorConnectionEventRecorder, 123, 1u); expectVsyncEventReceivedByConnection("successConnection", secondConnectionEventRecorder, 123, @@ -561,13 +561,13 @@ TEST_F(EventThreadTest, eventsDroppedIfNonfatalEventDeliveryError) { // The first event will be seen by the interceptor, and by the connection, // which then returns an non-fatal error. - mCallback->onVSyncEvent(123, 456, 789); + mCallback->onVSyncEvent(123, {456, 789}); expectInterceptCallReceived(123); expectVsyncEventReceivedByConnection("errorConnection", errorConnectionEventRecorder, 123, 1u); // A subsequent event will be seen by the interceptor, and by the connection, // which still then returns an non-fatal error. - mCallback->onVSyncEvent(456, 123, 0); + mCallback->onVSyncEvent(456, {123, 0}); expectInterceptCallReceived(456); expectVsyncEventReceivedByConnection("errorConnection", errorConnectionEventRecorder, 456, 2u); @@ -691,7 +691,7 @@ TEST_F(EventThreadTest, requestNextVsyncWithThrottleVsyncDoesntPostVSync) { // Use the received callback to signal a first vsync event. // The interceptor should receive the event, but not the connection. - mCallback->onVSyncEvent(123, 456, 789); + mCallback->onVSyncEvent(123, {456, 789}); expectInterceptCallReceived(123); expectThrottleVsyncReceived(456, mThrottledConnectionUid); mThrottledConnectionEventCallRecorder.waitForUnexpectedCall(); @@ -699,7 +699,7 @@ TEST_F(EventThreadTest, requestNextVsyncWithThrottleVsyncDoesntPostVSync) { // Use the received callback to signal a second vsync event. // The interceptor should receive the event, but the connection should // not as it was only interested in the first. - mCallback->onVSyncEvent(456, 123, 0); + mCallback->onVSyncEvent(456, {123, 0}); expectInterceptCallReceived(456); expectThrottleVsyncReceived(123, mThrottledConnectionUid); EXPECT_FALSE(mConnectionEventCallRecorder.waitForUnexpectedCall().has_value()); |