Make onVsync return a display id
The caller of this method then turns around and asks HWComposer for the
display id, so we might as well return the id in the first place. Use an
optional so it can return the equivalent of false in the old version.
Use ftl::Concat to save memory allocations.
Factored out from If60218e85292c786b9fa70ecb33ee374d3a385e0 after it was
reverted.
Bug: 255601557
Bug: 256196556
Test: atest libsurfaceflinger_unittest:HWComposerTest
Change-Id: I21be76e20776d8a3f49e5bd295a0042de9e2dde9
diff --git a/services/surfaceflinger/tests/unittests/HWComposerTest.cpp b/services/surfaceflinger/tests/unittests/HWComposerTest.cpp
index afbc57a..9534f3b 100644
--- a/services/surfaceflinger/tests/unittests/HWComposerTest.cpp
+++ b/services/surfaceflinger/tests/unittests/HWComposerTest.cpp
@@ -118,6 +118,34 @@
}
}
+TEST_F(HWComposerTest, onVsync) {
+ constexpr hal::HWDisplayId kHwcDisplayId = 1;
+ expectHotplugConnect(kHwcDisplayId);
+
+ const auto info = mHwc.onHotplug(kHwcDisplayId, hal::Connection::CONNECTED);
+ ASSERT_TRUE(info);
+
+ const auto physicalDisplayId = info->id;
+
+ // Deliberately chosen not to match DisplayData.lastPresentTimestamp's
+ // initial value.
+ constexpr nsecs_t kTimestamp = 1;
+ auto displayIdOpt = mHwc.onVsync(kHwcDisplayId, kTimestamp);
+ ASSERT_TRUE(displayIdOpt);
+ EXPECT_EQ(physicalDisplayId, displayIdOpt);
+
+ // Attempt to send the same time stamp again.
+ displayIdOpt = mHwc.onVsync(kHwcDisplayId, kTimestamp);
+ EXPECT_FALSE(displayIdOpt);
+}
+
+TEST_F(HWComposerTest, onVsyncInvalid) {
+ constexpr hal::HWDisplayId kInvalidHwcDisplayId = 2;
+ constexpr nsecs_t kTimestamp = 1;
+ const auto displayIdOpt = mHwc.onVsync(kInvalidHwcDisplayId, kTimestamp);
+ EXPECT_FALSE(displayIdOpt);
+}
+
struct MockHWC2ComposerCallback final : StrictMock<HWC2::ComposerCallback> {
MOCK_METHOD2(onComposerHalHotplug, void(hal::HWDisplayId, hal::Connection));
MOCK_METHOD1(onComposerHalRefresh, void(hal::HWDisplayId));