Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 17 | #include <ftl/fake_guard.h> |
Ana Krulec | 0c8cd52 | 2018-08-31 12:27:28 -0700 | [diff] [blame] | 18 | #include <gmock/gmock.h> |
| 19 | #include <gtest/gtest.h> |
Ana Krulec | 0c8cd52 | 2018-08-31 12:27:28 -0700 | [diff] [blame] | 20 | #include <log/log.h> |
| 21 | |
Ana Krulec | e588e31 | 2018-09-18 12:32:24 -0700 | [diff] [blame] | 22 | #include <mutex> |
| 23 | |
Ana Krulec | 0c8cd52 | 2018-08-31 12:27:28 -0700 | [diff] [blame] | 24 | #include "Scheduler/EventThread.h" |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 25 | #include "Scheduler/RefreshRateSelector.h" |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 26 | #include "TestableScheduler.h" |
Dominik Laskowski | 983f2b5 | 2020-06-25 16:54:06 -0700 | [diff] [blame] | 27 | #include "TestableSurfaceFlinger.h" |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 28 | #include "mock/DisplayHardware/MockDisplayMode.h" |
Ana Krulec | 0c8cd52 | 2018-08-31 12:27:28 -0700 | [diff] [blame] | 29 | #include "mock/MockEventThread.h" |
Dominik Laskowski | 983f2b5 | 2020-06-25 16:54:06 -0700 | [diff] [blame] | 30 | #include "mock/MockLayer.h" |
Dominik Laskowski | 8b01cc0 | 2020-07-14 19:02:41 -0700 | [diff] [blame] | 31 | #include "mock/MockSchedulerCallback.h" |
Ana Krulec | 0c8cd52 | 2018-08-31 12:27:28 -0700 | [diff] [blame] | 32 | |
Ady Abraham | 822ecbd | 2023-07-07 16:16:09 -0700 | [diff] [blame] | 33 | #include <FrontEnd/LayerHierarchy.h> |
| 34 | |
| 35 | #include "FpsOps.h" |
| 36 | |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 37 | namespace android::scheduler { |
| 38 | |
Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 39 | using android::mock::createDisplayMode; |
| 40 | |
Ana Krulec | 0c8cd52 | 2018-08-31 12:27:28 -0700 | [diff] [blame] | 41 | using testing::_; |
| 42 | using testing::Return; |
| 43 | |
Dominik Laskowski | 8b01cc0 | 2020-07-14 19:02:41 -0700 | [diff] [blame] | 44 | namespace { |
Ana Krulec | 0c8cd52 | 2018-08-31 12:27:28 -0700 | [diff] [blame] | 45 | |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 46 | using MockEventThread = android::mock::EventThread; |
| 47 | using MockLayer = android::mock::MockLayer; |
| 48 | |
Ady Abraham | 822ecbd | 2023-07-07 16:16:09 -0700 | [diff] [blame] | 49 | using LayerHierarchy = surfaceflinger::frontend::LayerHierarchy; |
| 50 | using LayerHierarchyBuilder = surfaceflinger::frontend::LayerHierarchyBuilder; |
| 51 | using RequestedLayerState = surfaceflinger::frontend::RequestedLayerState; |
| 52 | |
Ana Krulec | 0c8cd52 | 2018-08-31 12:27:28 -0700 | [diff] [blame] | 53 | class SchedulerTest : public testing::Test { |
| 54 | protected: |
Ana Krulec | 85c39af | 2018-12-26 17:29:57 -0800 | [diff] [blame] | 55 | class MockEventThreadConnection : public android::EventThreadConnection { |
Ana Krulec | 0c8cd52 | 2018-08-31 12:27:28 -0700 | [diff] [blame] | 56 | public: |
Ana Krulec | 85c39af | 2018-12-26 17:29:57 -0800 | [diff] [blame] | 57 | explicit MockEventThreadConnection(EventThread* eventThread) |
Ady Abraham | f285161 | 2023-09-25 17:19:00 -0700 | [diff] [blame] | 58 | : EventThreadConnection(eventThread, /*callingUid*/ static_cast<uid_t>(0)) {} |
Ana Krulec | 0c8cd52 | 2018-08-31 12:27:28 -0700 | [diff] [blame] | 59 | ~MockEventThreadConnection() = default; |
| 60 | |
Huihong Luo | 6fac523 | 2021-11-22 16:05:23 -0800 | [diff] [blame] | 61 | MOCK_METHOD1(stealReceiveChannel, binder::Status(gui::BitTube* outChannel)); |
| 62 | MOCK_METHOD1(setVsyncRate, binder::Status(int count)); |
| 63 | MOCK_METHOD0(requestNextVsync, binder::Status()); |
Ana Krulec | 0c8cd52 | 2018-08-31 12:27:28 -0700 | [diff] [blame] | 64 | }; |
| 65 | |
Ana Krulec | 0c8cd52 | 2018-08-31 12:27:28 -0700 | [diff] [blame] | 66 | SchedulerTest(); |
Ana Krulec | 0c8cd52 | 2018-08-31 12:27:28 -0700 | [diff] [blame] | 67 | |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 68 | static constexpr PhysicalDisplayId kDisplayId1 = PhysicalDisplayId::fromPort(255u); |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 69 | static inline const ftl::NonNull<DisplayModePtr> kDisplay1Mode60 = |
| 70 | ftl::as_non_null(createDisplayMode(kDisplayId1, DisplayModeId(0), 60_Hz)); |
| 71 | static inline const ftl::NonNull<DisplayModePtr> kDisplay1Mode120 = |
| 72 | ftl::as_non_null(createDisplayMode(kDisplayId1, DisplayModeId(1), 120_Hz)); |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 73 | static inline const DisplayModes kDisplay1Modes = makeModes(kDisplay1Mode60, kDisplay1Mode120); |
| 74 | |
| 75 | static constexpr PhysicalDisplayId kDisplayId2 = PhysicalDisplayId::fromPort(254u); |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 76 | static inline const ftl::NonNull<DisplayModePtr> kDisplay2Mode60 = |
| 77 | ftl::as_non_null(createDisplayMode(kDisplayId2, DisplayModeId(0), 60_Hz)); |
| 78 | static inline const ftl::NonNull<DisplayModePtr> kDisplay2Mode120 = |
| 79 | ftl::as_non_null(createDisplayMode(kDisplayId2, DisplayModeId(1), 120_Hz)); |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 80 | static inline const DisplayModes kDisplay2Modes = makeModes(kDisplay2Mode60, kDisplay2Mode120); |
| 81 | |
| 82 | static constexpr PhysicalDisplayId kDisplayId3 = PhysicalDisplayId::fromPort(253u); |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 83 | static inline const ftl::NonNull<DisplayModePtr> kDisplay3Mode60 = |
| 84 | ftl::as_non_null(createDisplayMode(kDisplayId3, DisplayModeId(0), 60_Hz)); |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 85 | static inline const DisplayModes kDisplay3Modes = makeModes(kDisplay3Mode60); |
Marin Shalamanov | 2cde100 | 2021-06-08 19:50:10 +0200 | [diff] [blame] | 86 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 87 | std::shared_ptr<RefreshRateSelector> mSelector = |
| 88 | std::make_shared<RefreshRateSelector>(makeModes(kDisplay1Mode60), |
| 89 | kDisplay1Mode60->getId()); |
Dominik Laskowski | 983f2b5 | 2020-06-25 16:54:06 -0700 | [diff] [blame] | 90 | |
Dominik Laskowski | 8b01cc0 | 2020-07-14 19:02:41 -0700 | [diff] [blame] | 91 | mock::SchedulerCallback mSchedulerCallback; |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 92 | TestableScheduler* mScheduler = new TestableScheduler{mSelector, mSchedulerCallback}; |
Ady Abraham | 822ecbd | 2023-07-07 16:16:09 -0700 | [diff] [blame] | 93 | surfaceflinger::frontend::LayerHierarchyBuilder mLayerHierarchyBuilder{{}}; |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 94 | |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 95 | ConnectionHandle mConnectionHandle; |
| 96 | MockEventThread* mEventThread; |
Ana Krulec | 0c8cd52 | 2018-08-31 12:27:28 -0700 | [diff] [blame] | 97 | sp<MockEventThreadConnection> mEventThreadConnection; |
Ady Abraham | 564f9de | 2021-02-03 18:34:33 -0800 | [diff] [blame] | 98 | |
| 99 | TestableSurfaceFlinger mFlinger; |
Ana Krulec | 0c8cd52 | 2018-08-31 12:27:28 -0700 | [diff] [blame] | 100 | }; |
| 101 | |
| 102 | SchedulerTest::SchedulerTest() { |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 103 | auto eventThread = std::make_unique<MockEventThread>(); |
Ana Krulec | 0c8cd52 | 2018-08-31 12:27:28 -0700 | [diff] [blame] | 104 | mEventThread = eventThread.get(); |
Ana Krulec | 85c39af | 2018-12-26 17:29:57 -0800 | [diff] [blame] | 105 | EXPECT_CALL(*mEventThread, registerDisplayEventConnection(_)).WillOnce(Return(0)); |
| 106 | |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 107 | mEventThreadConnection = sp<MockEventThreadConnection>::make(mEventThread); |
Ana Krulec | 0c8cd52 | 2018-08-31 12:27:28 -0700 | [diff] [blame] | 108 | |
| 109 | // createConnection call to scheduler makes a createEventConnection call to EventThread. Make |
| 110 | // sure that call gets executed and returns an EventThread::Connection object. |
Ady Abraham | 0f4a1b1 | 2019-06-04 16:04:04 -0700 | [diff] [blame] | 111 | EXPECT_CALL(*mEventThread, createEventConnection(_, _)) |
Ana Krulec | 0c8cd52 | 2018-08-31 12:27:28 -0700 | [diff] [blame] | 112 | .WillRepeatedly(Return(mEventThreadConnection)); |
| 113 | |
Ady Abraham | a0a1627 | 2021-03-03 15:23:35 -0800 | [diff] [blame] | 114 | mConnectionHandle = mScheduler->createConnection(std::move(eventThread)); |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 115 | EXPECT_TRUE(mConnectionHandle); |
Ady Abraham | a0a1627 | 2021-03-03 15:23:35 -0800 | [diff] [blame] | 116 | |
| 117 | mFlinger.resetScheduler(mScheduler); |
Ana Krulec | 0c8cd52 | 2018-08-31 12:27:28 -0700 | [diff] [blame] | 118 | } |
| 119 | |
Dominik Laskowski | 8b01cc0 | 2020-07-14 19:02:41 -0700 | [diff] [blame] | 120 | } // namespace |
Ana Krulec | 0c8cd52 | 2018-08-31 12:27:28 -0700 | [diff] [blame] | 121 | |
Ana Krulec | 0c8cd52 | 2018-08-31 12:27:28 -0700 | [diff] [blame] | 122 | TEST_F(SchedulerTest, invalidConnectionHandle) { |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 123 | ConnectionHandle handle; |
Ana Krulec | 0c8cd52 | 2018-08-31 12:27:28 -0700 | [diff] [blame] | 124 | |
Ady Abraham | a0a1627 | 2021-03-03 15:23:35 -0800 | [diff] [blame] | 125 | const sp<IDisplayEventConnection> connection = mScheduler->createDisplayEventConnection(handle); |
Dominik Laskowski | 983f2b5 | 2020-06-25 16:54:06 -0700 | [diff] [blame] | 126 | |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 127 | EXPECT_FALSE(connection); |
Ady Abraham | a0a1627 | 2021-03-03 15:23:35 -0800 | [diff] [blame] | 128 | EXPECT_FALSE(mScheduler->getEventConnection(handle)); |
Ana Krulec | 0c8cd52 | 2018-08-31 12:27:28 -0700 | [diff] [blame] | 129 | |
| 130 | // The EXPECT_CALLS make sure we don't call the functions on the subsequent event threads. |
| 131 | EXPECT_CALL(*mEventThread, onHotplugReceived(_, _)).Times(0); |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 132 | mScheduler->onHotplugReceived(handle, kDisplayId1, false); |
Ana Krulec | 0c8cd52 | 2018-08-31 12:27:28 -0700 | [diff] [blame] | 133 | |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 134 | std::string output; |
Ana Krulec | 0c8cd52 | 2018-08-31 12:27:28 -0700 | [diff] [blame] | 135 | EXPECT_CALL(*mEventThread, dump(_)).Times(0); |
Ady Abraham | a0a1627 | 2021-03-03 15:23:35 -0800 | [diff] [blame] | 136 | mScheduler->dump(handle, output); |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 137 | EXPECT_TRUE(output.empty()); |
Ana Krulec | 0c8cd52 | 2018-08-31 12:27:28 -0700 | [diff] [blame] | 138 | |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 139 | EXPECT_CALL(*mEventThread, setDuration(10ns, 20ns)).Times(0); |
Ady Abraham | a0a1627 | 2021-03-03 15:23:35 -0800 | [diff] [blame] | 140 | mScheduler->setDuration(handle, 10ns, 20ns); |
Ana Krulec | 0c8cd52 | 2018-08-31 12:27:28 -0700 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | TEST_F(SchedulerTest, validConnectionHandle) { |
Dominik Laskowski | 983f2b5 | 2020-06-25 16:54:06 -0700 | [diff] [blame] | 144 | const sp<IDisplayEventConnection> connection = |
Ady Abraham | a0a1627 | 2021-03-03 15:23:35 -0800 | [diff] [blame] | 145 | mScheduler->createDisplayEventConnection(mConnectionHandle); |
Dominik Laskowski | 983f2b5 | 2020-06-25 16:54:06 -0700 | [diff] [blame] | 146 | |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 147 | ASSERT_EQ(mEventThreadConnection, connection); |
Ady Abraham | a0a1627 | 2021-03-03 15:23:35 -0800 | [diff] [blame] | 148 | EXPECT_TRUE(mScheduler->getEventConnection(mConnectionHandle)); |
Ana Krulec | 0c8cd52 | 2018-08-31 12:27:28 -0700 | [diff] [blame] | 149 | |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 150 | EXPECT_CALL(*mEventThread, onHotplugReceived(kDisplayId1, false)).Times(1); |
| 151 | mScheduler->onHotplugReceived(mConnectionHandle, kDisplayId1, false); |
Ana Krulec | 0c8cd52 | 2018-08-31 12:27:28 -0700 | [diff] [blame] | 152 | |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 153 | std::string output("dump"); |
| 154 | EXPECT_CALL(*mEventThread, dump(output)).Times(1); |
Ady Abraham | a0a1627 | 2021-03-03 15:23:35 -0800 | [diff] [blame] | 155 | mScheduler->dump(mConnectionHandle, output); |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 156 | EXPECT_FALSE(output.empty()); |
Ana Krulec | 0c8cd52 | 2018-08-31 12:27:28 -0700 | [diff] [blame] | 157 | |
Ady Abraham | 9c53ee7 | 2020-07-22 21:16:18 -0700 | [diff] [blame] | 158 | EXPECT_CALL(*mEventThread, setDuration(10ns, 20ns)).Times(1); |
Ady Abraham | a0a1627 | 2021-03-03 15:23:35 -0800 | [diff] [blame] | 159 | mScheduler->setDuration(mConnectionHandle, 10ns, 20ns); |
Ana Krulec | 0c8cd52 | 2018-08-31 12:27:28 -0700 | [diff] [blame] | 160 | } |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 161 | |
Dominik Laskowski | 6629543 | 2023-03-14 12:25:36 -0400 | [diff] [blame] | 162 | TEST_F(SchedulerTest, registerDisplay) FTL_FAKE_GUARD(kMainThreadContext) { |
Dominik Laskowski | 008bec0 | 2023-03-14 12:04:58 -0400 | [diff] [blame] | 163 | // Hardware VSYNC should not change if the display is already registered. |
Dominik Laskowski | 6629543 | 2023-03-14 12:25:36 -0400 | [diff] [blame] | 164 | EXPECT_CALL(mSchedulerCallback, requestHardwareVsync(kDisplayId1, false)).Times(0); |
Dominik Laskowski | 008bec0 | 2023-03-14 12:04:58 -0400 | [diff] [blame] | 165 | mScheduler->registerDisplay(kDisplayId1, |
| 166 | std::make_shared<RefreshRateSelector>(kDisplay1Modes, |
| 167 | kDisplay1Mode60->getId())); |
| 168 | |
Dominik Laskowski | 6629543 | 2023-03-14 12:25:36 -0400 | [diff] [blame] | 169 | // TODO(b/241285191): Restore once VsyncSchedule::getPendingHardwareVsyncState is called by |
| 170 | // Scheduler::setDisplayPowerMode rather than SF::setPowerModeInternal. |
| 171 | #if 0 |
Dominik Laskowski | 008bec0 | 2023-03-14 12:04:58 -0400 | [diff] [blame] | 172 | // Hardware VSYNC should be disabled for newly registered displays. |
Dominik Laskowski | 6629543 | 2023-03-14 12:25:36 -0400 | [diff] [blame] | 173 | EXPECT_CALL(mSchedulerCallback, requestHardwareVsync(kDisplayId2, false)).Times(1); |
| 174 | EXPECT_CALL(mSchedulerCallback, requestHardwareVsync(kDisplayId3, false)).Times(1); |
| 175 | #endif |
Dominik Laskowski | 008bec0 | 2023-03-14 12:04:58 -0400 | [diff] [blame] | 176 | |
| 177 | mScheduler->registerDisplay(kDisplayId2, |
| 178 | std::make_shared<RefreshRateSelector>(kDisplay2Modes, |
| 179 | kDisplay2Mode60->getId())); |
| 180 | mScheduler->registerDisplay(kDisplayId3, |
| 181 | std::make_shared<RefreshRateSelector>(kDisplay3Modes, |
| 182 | kDisplay3Mode60->getId())); |
Dominik Laskowski | 6629543 | 2023-03-14 12:25:36 -0400 | [diff] [blame] | 183 | |
| 184 | EXPECT_FALSE(mScheduler->getVsyncSchedule(kDisplayId1)->getPendingHardwareVsyncState()); |
| 185 | EXPECT_FALSE(mScheduler->getVsyncSchedule(kDisplayId2)->getPendingHardwareVsyncState()); |
| 186 | EXPECT_FALSE(mScheduler->getVsyncSchedule(kDisplayId3)->getPendingHardwareVsyncState()); |
Dominik Laskowski | 008bec0 | 2023-03-14 12:04:58 -0400 | [diff] [blame] | 187 | } |
| 188 | |
Marin Shalamanov | 2cde100 | 2021-06-08 19:50:10 +0200 | [diff] [blame] | 189 | TEST_F(SchedulerTest, chooseRefreshRateForContentIsNoopWhenModeSwitchingIsNotSupported) { |
| 190 | // The layer is registered at creation time and deregistered at destruction time. |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 191 | sp<MockLayer> layer = sp<MockLayer>::make(mFlinger.flinger()); |
Dominik Laskowski | 983f2b5 | 2020-06-25 16:54:06 -0700 | [diff] [blame] | 192 | |
Marin Shalamanov | 2cde100 | 2021-06-08 19:50:10 +0200 | [diff] [blame] | 193 | // recordLayerHistory should be a noop |
Dominik Laskowski | 9c93d60 | 2021-10-07 19:38:26 -0700 | [diff] [blame] | 194 | ASSERT_EQ(0u, mScheduler->getNumActiveLayers()); |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 195 | mScheduler->recordLayerHistory(layer->getSequence(), layer->getLayerProps(), 0, |
| 196 | LayerHistory::LayerUpdateType::Buffer); |
Dominik Laskowski | 9c93d60 | 2021-10-07 19:38:26 -0700 | [diff] [blame] | 197 | ASSERT_EQ(0u, mScheduler->getNumActiveLayers()); |
Dominik Laskowski | 983f2b5 | 2020-06-25 16:54:06 -0700 | [diff] [blame] | 198 | |
Rachel Lee | 6a9731d | 2022-06-06 17:08:14 -0700 | [diff] [blame] | 199 | constexpr hal::PowerMode kPowerModeOn = hal::PowerMode::ON; |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 200 | FTL_FAKE_GUARD(kMainThreadContext, mScheduler->setDisplayPowerMode(kDisplayId1, kPowerModeOn)); |
Dominik Laskowski | 983f2b5 | 2020-06-25 16:54:06 -0700 | [diff] [blame] | 201 | |
| 202 | constexpr uint32_t kDisplayArea = 999'999; |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 203 | mScheduler->onActiveDisplayAreaChanged(kDisplayArea); |
Dominik Laskowski | 983f2b5 | 2020-06-25 16:54:06 -0700 | [diff] [blame] | 204 | |
ramindani | 69b58e8 | 2022-09-26 16:48:36 -0700 | [diff] [blame] | 205 | EXPECT_CALL(mSchedulerCallback, requestDisplayModes(_)).Times(0); |
Ady Abraham | 822ecbd | 2023-07-07 16:16:09 -0700 | [diff] [blame] | 206 | mScheduler->chooseRefreshRateForContent(/*LayerHierarchy*/ nullptr, |
| 207 | /*updateAttachedChoreographer*/ false); |
Dominik Laskowski | 983f2b5 | 2020-06-25 16:54:06 -0700 | [diff] [blame] | 208 | } |
| 209 | |
Marin Shalamanov | 2cde100 | 2021-06-08 19:50:10 +0200 | [diff] [blame] | 210 | TEST_F(SchedulerTest, updateDisplayModes) { |
Dominik Laskowski | 9c93d60 | 2021-10-07 19:38:26 -0700 | [diff] [blame] | 211 | ASSERT_EQ(0u, mScheduler->layerHistorySize()); |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 212 | sp<MockLayer> layer = sp<MockLayer>::make(mFlinger.flinger()); |
Dominik Laskowski | 9c93d60 | 2021-10-07 19:38:26 -0700 | [diff] [blame] | 213 | ASSERT_EQ(1u, mScheduler->layerHistorySize()); |
Marin Shalamanov | 2cde100 | 2021-06-08 19:50:10 +0200 | [diff] [blame] | 214 | |
Dominik Laskowski | 596a256 | 2022-10-28 11:26:12 -0400 | [diff] [blame] | 215 | // Replace `mSelector` with a new `RefreshRateSelector` that has different display modes. |
| 216 | mScheduler->registerDisplay(kDisplayId1, |
| 217 | std::make_shared<RefreshRateSelector>(kDisplay1Modes, |
| 218 | kDisplay1Mode60->getId())); |
Marin Shalamanov | 2cde100 | 2021-06-08 19:50:10 +0200 | [diff] [blame] | 219 | |
Dominik Laskowski | 9c93d60 | 2021-10-07 19:38:26 -0700 | [diff] [blame] | 220 | ASSERT_EQ(0u, mScheduler->getNumActiveLayers()); |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 221 | mScheduler->recordLayerHistory(layer->getSequence(), layer->getLayerProps(), 0, |
| 222 | LayerHistory::LayerUpdateType::Buffer); |
Dominik Laskowski | 9c93d60 | 2021-10-07 19:38:26 -0700 | [diff] [blame] | 223 | ASSERT_EQ(1u, mScheduler->getNumActiveLayers()); |
Marin Shalamanov | 2cde100 | 2021-06-08 19:50:10 +0200 | [diff] [blame] | 224 | } |
| 225 | |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 226 | TEST_F(SchedulerTest, dispatchCachedReportedMode) { |
| 227 | mScheduler->clearCachedReportedMode(); |
| 228 | |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 229 | EXPECT_CALL(*mEventThread, onModeChanged(_)).Times(0); |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 230 | EXPECT_NO_FATAL_FAILURE(mScheduler->dispatchCachedReportedMode()); |
Ana Krulec | 6ddd261 | 2020-09-24 13:06:33 -0700 | [diff] [blame] | 231 | } |
| 232 | |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 233 | TEST_F(SchedulerTest, onNonPrimaryDisplayModeChanged_invalidParameters) { |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 234 | const auto mode = DisplayMode::Builder(hal::HWConfigId(0)) |
| 235 | .setId(DisplayModeId(111)) |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 236 | .setPhysicalDisplayId(kDisplayId1) |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 237 | .setVsyncPeriod(111111) |
| 238 | .build(); |
Ana Krulec | 6ddd261 | 2020-09-24 13:06:33 -0700 | [diff] [blame] | 239 | |
| 240 | // If the handle is incorrect, the function should return before |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 241 | // onModeChange is called. |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 242 | ConnectionHandle invalidHandle = {.id = 123}; |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 243 | EXPECT_NO_FATAL_FAILURE( |
| 244 | mScheduler->onNonPrimaryDisplayModeChanged(invalidHandle, |
| 245 | {90_Hz, ftl::as_non_null(mode)})); |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 246 | EXPECT_CALL(*mEventThread, onModeChanged(_)).Times(0); |
Ana Krulec | 6ddd261 | 2020-09-24 13:06:33 -0700 | [diff] [blame] | 247 | } |
| 248 | |
Ady Abraham | 899dcdb | 2021-06-15 16:56:21 -0700 | [diff] [blame] | 249 | TEST_F(SchedulerTest, calculateMaxAcquiredBufferCount) { |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 250 | EXPECT_EQ(1, mFlinger.calculateMaxAcquiredBufferCount(60_Hz, 30ms)); |
| 251 | EXPECT_EQ(2, mFlinger.calculateMaxAcquiredBufferCount(90_Hz, 30ms)); |
| 252 | EXPECT_EQ(3, mFlinger.calculateMaxAcquiredBufferCount(120_Hz, 30ms)); |
Ady Abraham | 564f9de | 2021-02-03 18:34:33 -0800 | [diff] [blame] | 253 | |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 254 | EXPECT_EQ(2, mFlinger.calculateMaxAcquiredBufferCount(60_Hz, 40ms)); |
Ady Abraham | 564f9de | 2021-02-03 18:34:33 -0800 | [diff] [blame] | 255 | |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 256 | EXPECT_EQ(1, mFlinger.calculateMaxAcquiredBufferCount(60_Hz, 10ms)); |
Lloyd Pique | a1456c1 | 2023-05-17 12:11:15 -0700 | [diff] [blame] | 257 | |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 258 | const auto savedMinAcquiredBuffers = mFlinger.mutableMinAcquiredBuffers(); |
| 259 | mFlinger.mutableMinAcquiredBuffers() = 2; |
Lloyd Pique | a1456c1 | 2023-05-17 12:11:15 -0700 | [diff] [blame] | 260 | EXPECT_EQ(2, mFlinger.calculateMaxAcquiredBufferCount(60_Hz, 10ms)); |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 261 | mFlinger.mutableMinAcquiredBuffers() = savedMinAcquiredBuffers; |
Ady Abraham | 564f9de | 2021-02-03 18:34:33 -0800 | [diff] [blame] | 262 | } |
| 263 | |
Marin Shalamanov | 4c7831e | 2021-06-08 20:44:06 +0200 | [diff] [blame] | 264 | MATCHER(Is120Hz, "") { |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 265 | return isApproxEqual(arg.front().mode.fps, 120_Hz); |
Marin Shalamanov | 4c7831e | 2021-06-08 20:44:06 +0200 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | TEST_F(SchedulerTest, chooseRefreshRateForContentSelectsMaxRefreshRate) { |
Dominik Laskowski | 596a256 | 2022-10-28 11:26:12 -0400 | [diff] [blame] | 269 | mScheduler->registerDisplay(kDisplayId1, |
| 270 | std::make_shared<RefreshRateSelector>(kDisplay1Modes, |
| 271 | kDisplay1Mode60->getId())); |
Marin Shalamanov | 4c7831e | 2021-06-08 20:44:06 +0200 | [diff] [blame] | 272 | |
Dominik Laskowski | 0c41ffa | 2021-12-24 16:45:12 -0800 | [diff] [blame] | 273 | const sp<MockLayer> layer = sp<MockLayer>::make(mFlinger.flinger()); |
| 274 | EXPECT_CALL(*layer, isVisible()).WillOnce(Return(true)); |
Marin Shalamanov | 4c7831e | 2021-06-08 20:44:06 +0200 | [diff] [blame] | 275 | |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 276 | mScheduler->recordLayerHistory(layer->getSequence(), layer->getLayerProps(), 0, |
| 277 | LayerHistory::LayerUpdateType::Buffer); |
Marin Shalamanov | 4c7831e | 2021-06-08 20:44:06 +0200 | [diff] [blame] | 278 | |
Rachel Lee | 6a9731d | 2022-06-06 17:08:14 -0700 | [diff] [blame] | 279 | constexpr hal::PowerMode kPowerModeOn = hal::PowerMode::ON; |
Leon Scroggins III | 6738862 | 2023-02-06 20:36:20 -0500 | [diff] [blame] | 280 | FTL_FAKE_GUARD(kMainThreadContext, mScheduler->setDisplayPowerMode(kDisplayId1, kPowerModeOn)); |
Marin Shalamanov | 4c7831e | 2021-06-08 20:44:06 +0200 | [diff] [blame] | 281 | |
| 282 | constexpr uint32_t kDisplayArea = 999'999; |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 283 | mScheduler->onActiveDisplayAreaChanged(kDisplayArea); |
Marin Shalamanov | 4c7831e | 2021-06-08 20:44:06 +0200 | [diff] [blame] | 284 | |
ramindani | 69b58e8 | 2022-09-26 16:48:36 -0700 | [diff] [blame] | 285 | EXPECT_CALL(mSchedulerCallback, requestDisplayModes(Is120Hz())).Times(1); |
Ady Abraham | 822ecbd | 2023-07-07 16:16:09 -0700 | [diff] [blame] | 286 | mScheduler->chooseRefreshRateForContent(/*LayerHierarchy*/ nullptr, |
| 287 | /*updateAttachedChoreographer*/ false); |
Dominik Laskowski | 0c41ffa | 2021-12-24 16:45:12 -0800 | [diff] [blame] | 288 | |
| 289 | // No-op if layer requirements have not changed. |
ramindani | 69b58e8 | 2022-09-26 16:48:36 -0700 | [diff] [blame] | 290 | EXPECT_CALL(mSchedulerCallback, requestDisplayModes(_)).Times(0); |
Ady Abraham | 822ecbd | 2023-07-07 16:16:09 -0700 | [diff] [blame] | 291 | mScheduler->chooseRefreshRateForContent(/*LayerHierarchy*/ nullptr, |
| 292 | /*updateAttachedChoreographer*/ false); |
Marin Shalamanov | 4c7831e | 2021-06-08 20:44:06 +0200 | [diff] [blame] | 293 | } |
| 294 | |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 295 | TEST_F(SchedulerTest, chooseDisplayModesSingleDisplay) { |
Dominik Laskowski | b5a094b | 2022-10-27 12:00:12 -0400 | [diff] [blame] | 296 | mScheduler->registerDisplay(kDisplayId1, |
| 297 | std::make_shared<RefreshRateSelector>(kDisplay1Modes, |
| 298 | kDisplay1Mode60->getId())); |
ramindani | 69b58e8 | 2022-09-26 16:48:36 -0700 | [diff] [blame] | 299 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 300 | std::vector<RefreshRateSelector::LayerRequirement> layers = |
| 301 | std::vector<RefreshRateSelector::LayerRequirement>({{.weight = 1.f}, {.weight = 1.f}}); |
ramindani | 69b58e8 | 2022-09-26 16:48:36 -0700 | [diff] [blame] | 302 | mScheduler->setContentRequirements(layers); |
| 303 | GlobalSignals globalSignals = {.idle = true}; |
| 304 | mScheduler->setTouchStateAndIdleTimerPolicy(globalSignals); |
| 305 | |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 306 | using DisplayModeChoice = TestableScheduler::DisplayModeChoice; |
| 307 | |
| 308 | auto modeChoices = mScheduler->chooseDisplayModes(); |
| 309 | ASSERT_EQ(1u, modeChoices.size()); |
| 310 | |
| 311 | auto choice = modeChoices.get(kDisplayId1); |
| 312 | ASSERT_TRUE(choice); |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 313 | EXPECT_EQ(choice->get(), DisplayModeChoice({60_Hz, kDisplay1Mode60}, globalSignals)); |
ramindani | 69b58e8 | 2022-09-26 16:48:36 -0700 | [diff] [blame] | 314 | |
| 315 | globalSignals = {.idle = false}; |
| 316 | mScheduler->setTouchStateAndIdleTimerPolicy(globalSignals); |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 317 | |
| 318 | modeChoices = mScheduler->chooseDisplayModes(); |
| 319 | ASSERT_EQ(1u, modeChoices.size()); |
| 320 | |
| 321 | choice = modeChoices.get(kDisplayId1); |
| 322 | ASSERT_TRUE(choice); |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 323 | EXPECT_EQ(choice->get(), DisplayModeChoice({120_Hz, kDisplay1Mode120}, globalSignals)); |
ramindani | 69b58e8 | 2022-09-26 16:48:36 -0700 | [diff] [blame] | 324 | |
| 325 | globalSignals = {.touch = true}; |
| 326 | mScheduler->replaceTouchTimer(10); |
| 327 | mScheduler->setTouchStateAndIdleTimerPolicy(globalSignals); |
ramindani | 69b58e8 | 2022-09-26 16:48:36 -0700 | [diff] [blame] | 328 | |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 329 | modeChoices = mScheduler->chooseDisplayModes(); |
| 330 | ASSERT_EQ(1u, modeChoices.size()); |
| 331 | |
| 332 | choice = modeChoices.get(kDisplayId1); |
| 333 | ASSERT_TRUE(choice); |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 334 | EXPECT_EQ(choice->get(), DisplayModeChoice({120_Hz, kDisplay1Mode120}, globalSignals)); |
ramindani | 69b58e8 | 2022-09-26 16:48:36 -0700 | [diff] [blame] | 335 | } |
| 336 | |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 337 | TEST_F(SchedulerTest, chooseDisplayModesMultipleDisplays) { |
Dominik Laskowski | b5a094b | 2022-10-27 12:00:12 -0400 | [diff] [blame] | 338 | mScheduler->registerDisplay(kDisplayId1, |
| 339 | std::make_shared<RefreshRateSelector>(kDisplay1Modes, |
| 340 | kDisplay1Mode60->getId())); |
| 341 | mScheduler->registerDisplay(kDisplayId2, |
| 342 | std::make_shared<RefreshRateSelector>(kDisplay2Modes, |
| 343 | kDisplay2Mode60->getId())); |
ramindani | 69b58e8 | 2022-09-26 16:48:36 -0700 | [diff] [blame] | 344 | |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 345 | using DisplayModeChoice = TestableScheduler::DisplayModeChoice; |
| 346 | TestableScheduler::DisplayModeChoiceMap expectedChoices; |
ramindani | 69b58e8 | 2022-09-26 16:48:36 -0700 | [diff] [blame] | 347 | |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 348 | { |
| 349 | const GlobalSignals globalSignals = {.idle = true}; |
| 350 | expectedChoices = |
| 351 | ftl::init::map<const PhysicalDisplayId&, |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 352 | DisplayModeChoice>(kDisplayId1, |
| 353 | FrameRateMode{60_Hz, kDisplay1Mode60}, |
| 354 | globalSignals)(kDisplayId2, |
| 355 | FrameRateMode{60_Hz, |
| 356 | kDisplay2Mode60}, |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 357 | globalSignals); |
| 358 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 359 | std::vector<RefreshRateSelector::LayerRequirement> layers = {{.weight = 1.f}, |
| 360 | {.weight = 1.f}}; |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 361 | mScheduler->setContentRequirements(layers); |
| 362 | mScheduler->setTouchStateAndIdleTimerPolicy(globalSignals); |
| 363 | |
| 364 | const auto actualChoices = mScheduler->chooseDisplayModes(); |
| 365 | EXPECT_EQ(expectedChoices, actualChoices); |
ramindani | 69b58e8 | 2022-09-26 16:48:36 -0700 | [diff] [blame] | 366 | } |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 367 | { |
| 368 | const GlobalSignals globalSignals = {.idle = false}; |
| 369 | expectedChoices = |
| 370 | ftl::init::map<const PhysicalDisplayId&, |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 371 | DisplayModeChoice>(kDisplayId1, |
| 372 | FrameRateMode{120_Hz, kDisplay1Mode120}, |
| 373 | globalSignals)(kDisplayId2, |
| 374 | FrameRateMode{120_Hz, |
| 375 | kDisplay2Mode120}, |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 376 | globalSignals); |
ramindani | 69b58e8 | 2022-09-26 16:48:36 -0700 | [diff] [blame] | 377 | |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 378 | mScheduler->setTouchStateAndIdleTimerPolicy(globalSignals); |
ramindani | 69b58e8 | 2022-09-26 16:48:36 -0700 | [diff] [blame] | 379 | |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 380 | const auto actualChoices = mScheduler->chooseDisplayModes(); |
| 381 | EXPECT_EQ(expectedChoices, actualChoices); |
ramindani | 69b58e8 | 2022-09-26 16:48:36 -0700 | [diff] [blame] | 382 | } |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 383 | { |
| 384 | const GlobalSignals globalSignals = {.touch = true}; |
| 385 | mScheduler->replaceTouchTimer(10); |
| 386 | mScheduler->setTouchStateAndIdleTimerPolicy(globalSignals); |
ramindani | 69b58e8 | 2022-09-26 16:48:36 -0700 | [diff] [blame] | 387 | |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 388 | expectedChoices = |
| 389 | ftl::init::map<const PhysicalDisplayId&, |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 390 | DisplayModeChoice>(kDisplayId1, |
| 391 | FrameRateMode{120_Hz, kDisplay1Mode120}, |
| 392 | globalSignals)(kDisplayId2, |
| 393 | FrameRateMode{120_Hz, |
| 394 | kDisplay2Mode120}, |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 395 | globalSignals); |
| 396 | |
| 397 | const auto actualChoices = mScheduler->chooseDisplayModes(); |
| 398 | EXPECT_EQ(expectedChoices, actualChoices); |
ramindani | 69b58e8 | 2022-09-26 16:48:36 -0700 | [diff] [blame] | 399 | } |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 400 | { |
ramindani | 22f2ead | 2023-04-21 10:27:11 -0700 | [diff] [blame] | 401 | // The kDisplayId3 does not support 120Hz, The pacesetter display rate is chosen to be 120 |
| 402 | // Hz. In this case only the display kDisplayId3 choose 60Hz as it does not support 120Hz. |
Dominik Laskowski | b5a094b | 2022-10-27 12:00:12 -0400 | [diff] [blame] | 403 | mScheduler |
| 404 | ->registerDisplay(kDisplayId3, |
| 405 | std::make_shared<RefreshRateSelector>(kDisplay3Modes, |
| 406 | kDisplay3Mode60->getId())); |
Dominik Laskowski | 327d609 | 2022-10-11 18:05:08 -0400 | [diff] [blame] | 407 | |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 408 | const GlobalSignals globalSignals = {.touch = true}; |
| 409 | mScheduler->replaceTouchTimer(10); |
| 410 | mScheduler->setTouchStateAndIdleTimerPolicy(globalSignals); |
ramindani | 7c48728 | 2022-10-10 16:17:51 -0700 | [diff] [blame] | 411 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 412 | expectedChoices = ftl::init::map< |
| 413 | const PhysicalDisplayId&, |
ramindani | 22f2ead | 2023-04-21 10:27:11 -0700 | [diff] [blame] | 414 | DisplayModeChoice>(kDisplayId1, FrameRateMode{120_Hz, kDisplay1Mode120}, |
| 415 | globalSignals)(kDisplayId2, |
| 416 | FrameRateMode{120_Hz, kDisplay2Mode120}, |
| 417 | globalSignals)(kDisplayId3, |
| 418 | FrameRateMode{60_Hz, |
| 419 | kDisplay3Mode60}, |
| 420 | globalSignals); |
| 421 | |
| 422 | const auto actualChoices = mScheduler->chooseDisplayModes(); |
| 423 | EXPECT_EQ(expectedChoices, actualChoices); |
| 424 | } |
| 425 | { |
| 426 | // We should choose 60Hz despite the touch signal as pacesetter only supports 60Hz |
| 427 | mScheduler->setPacesetterDisplay(kDisplayId3); |
| 428 | const GlobalSignals globalSignals = {.touch = true}; |
| 429 | mScheduler->replaceTouchTimer(10); |
| 430 | mScheduler->setTouchStateAndIdleTimerPolicy(globalSignals); |
| 431 | |
| 432 | expectedChoices = ftl::init::map< |
| 433 | const PhysicalDisplayId&, |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 434 | DisplayModeChoice>(kDisplayId1, FrameRateMode{60_Hz, kDisplay1Mode60}, |
| 435 | globalSignals)(kDisplayId2, |
| 436 | FrameRateMode{60_Hz, kDisplay2Mode60}, |
| 437 | globalSignals)(kDisplayId3, |
| 438 | FrameRateMode{60_Hz, |
| 439 | kDisplay3Mode60}, |
| 440 | globalSignals); |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 441 | |
| 442 | const auto actualChoices = mScheduler->chooseDisplayModes(); |
| 443 | EXPECT_EQ(expectedChoices, actualChoices); |
ramindani | 7c48728 | 2022-10-10 16:17:51 -0700 | [diff] [blame] | 444 | } |
ramindani | 69b58e8 | 2022-09-26 16:48:36 -0700 | [diff] [blame] | 445 | } |
| 446 | |
Dominik Laskowski | 50e2e4d | 2023-10-04 10:58:28 -0400 | [diff] [blame^] | 447 | TEST_F(SchedulerTest, onFrameSignalMultipleDisplays) { |
| 448 | mScheduler->registerDisplay(kDisplayId1, |
| 449 | std::make_shared<RefreshRateSelector>(kDisplay1Modes, |
| 450 | kDisplay1Mode60->getId())); |
| 451 | mScheduler->registerDisplay(kDisplayId2, |
| 452 | std::make_shared<RefreshRateSelector>(kDisplay2Modes, |
| 453 | kDisplay2Mode60->getId())); |
| 454 | |
| 455 | using VsyncIds = std::vector<std::pair<PhysicalDisplayId, VsyncId>>; |
| 456 | |
| 457 | struct Compositor final : ICompositor { |
| 458 | VsyncIds vsyncIds; |
| 459 | bool committed = true; |
| 460 | |
| 461 | void configure() override {} |
| 462 | |
| 463 | bool commit(PhysicalDisplayId, const scheduler::FrameTargets& targets) override { |
| 464 | vsyncIds.clear(); |
| 465 | |
| 466 | for (const auto& [id, target] : targets) { |
| 467 | vsyncIds.emplace_back(id, target->vsyncId()); |
| 468 | } |
| 469 | |
| 470 | return committed; |
| 471 | } |
| 472 | |
| 473 | CompositeResultsPerDisplay composite(PhysicalDisplayId, |
| 474 | const scheduler::FrameTargeters&) override { |
| 475 | CompositeResultsPerDisplay results; |
| 476 | |
| 477 | for (const auto& [id, _] : vsyncIds) { |
| 478 | results.try_emplace(id, |
| 479 | CompositeResult{.compositionCoverage = |
| 480 | CompositionCoverage::Hwc}); |
| 481 | } |
| 482 | |
| 483 | return results; |
| 484 | } |
| 485 | |
| 486 | void sample() override {} |
| 487 | } compositor; |
| 488 | |
| 489 | mScheduler->doFrameSignal(compositor, VsyncId(42)); |
| 490 | |
| 491 | const auto makeVsyncIds = [](VsyncId vsyncId) -> VsyncIds { |
| 492 | return {{kDisplayId1, vsyncId}, {kDisplayId2, vsyncId}}; |
| 493 | }; |
| 494 | |
| 495 | EXPECT_EQ(makeVsyncIds(VsyncId(42)), compositor.vsyncIds); |
| 496 | |
| 497 | compositor.committed = false; |
| 498 | mScheduler->doFrameSignal(compositor, VsyncId(43)); |
| 499 | |
| 500 | // FrameTargets should be updated despite the skipped commit. |
| 501 | EXPECT_EQ(makeVsyncIds(VsyncId(43)), compositor.vsyncIds); |
| 502 | } |
| 503 | |
Ady Abraham | 822ecbd | 2023-07-07 16:16:09 -0700 | [diff] [blame] | 504 | class AttachedChoreographerTest : public SchedulerTest { |
| 505 | protected: |
| 506 | void frameRateTestScenario(Fps layerFps, int8_t frameRateCompatibility, Fps displayFps, |
| 507 | Fps expectedChoreographerFps); |
| 508 | }; |
| 509 | |
| 510 | TEST_F(AttachedChoreographerTest, registerSingle) { |
| 511 | EXPECT_TRUE(mScheduler->mutableAttachedChoreographers().empty()); |
| 512 | |
| 513 | const sp<MockLayer> layer = sp<MockLayer>::make(mFlinger.flinger()); |
| 514 | |
| 515 | EXPECT_CALL(mSchedulerCallback, onChoreographerAttached); |
| 516 | const sp<IDisplayEventConnection> connection = |
| 517 | mScheduler->createDisplayEventConnection(mConnectionHandle, {}, layer->getHandle()); |
| 518 | |
| 519 | EXPECT_EQ(1u, mScheduler->mutableAttachedChoreographers().size()); |
| 520 | ASSERT_EQ(1u, mScheduler->mutableAttachedChoreographers().count(layer->getSequence())); |
| 521 | EXPECT_EQ(1u, |
| 522 | mScheduler->mutableAttachedChoreographers()[layer->getSequence()].connections.size()); |
| 523 | EXPECT_FALSE( |
| 524 | mScheduler->mutableAttachedChoreographers()[layer->getSequence()].frameRate.isValid()); |
| 525 | } |
| 526 | |
| 527 | TEST_F(AttachedChoreographerTest, registerMultipleOnSameLayer) { |
| 528 | EXPECT_TRUE(mScheduler->mutableAttachedChoreographers().empty()); |
| 529 | |
| 530 | const sp<MockLayer> layer = sp<MockLayer>::make(mFlinger.flinger()); |
| 531 | const auto handle = layer->getHandle(); |
| 532 | |
| 533 | EXPECT_CALL(mSchedulerCallback, onChoreographerAttached).Times(2); |
| 534 | |
| 535 | EXPECT_CALL(*mEventThread, registerDisplayEventConnection(_)) |
| 536 | .WillOnce(Return(0)) |
| 537 | .WillOnce(Return(0)); |
| 538 | |
| 539 | const auto mockConnection1 = sp<MockEventThreadConnection>::make(mEventThread); |
| 540 | const auto mockConnection2 = sp<MockEventThreadConnection>::make(mEventThread); |
| 541 | EXPECT_CALL(*mEventThread, createEventConnection(_, _)) |
| 542 | .WillOnce(Return(mockConnection1)) |
| 543 | .WillOnce(Return(mockConnection2)); |
| 544 | |
| 545 | const sp<IDisplayEventConnection> connection1 = |
| 546 | mScheduler->createDisplayEventConnection(mConnectionHandle, {}, handle); |
| 547 | const sp<IDisplayEventConnection> connection2 = |
| 548 | mScheduler->createDisplayEventConnection(mConnectionHandle, {}, handle); |
| 549 | |
| 550 | EXPECT_EQ(1u, mScheduler->mutableAttachedChoreographers().size()); |
| 551 | ASSERT_EQ(1u, mScheduler->mutableAttachedChoreographers().count(layer->getSequence())); |
| 552 | EXPECT_EQ(2u, |
| 553 | mScheduler->mutableAttachedChoreographers()[layer->getSequence()].connections.size()); |
| 554 | EXPECT_FALSE( |
| 555 | mScheduler->mutableAttachedChoreographers()[layer->getSequence()].frameRate.isValid()); |
| 556 | } |
| 557 | |
| 558 | TEST_F(AttachedChoreographerTest, registerMultipleOnDifferentLayers) { |
| 559 | EXPECT_TRUE(mScheduler->mutableAttachedChoreographers().empty()); |
| 560 | |
| 561 | const sp<MockLayer> layer1 = sp<MockLayer>::make(mFlinger.flinger()); |
| 562 | const sp<MockLayer> layer2 = sp<MockLayer>::make(mFlinger.flinger()); |
| 563 | |
| 564 | EXPECT_CALL(mSchedulerCallback, onChoreographerAttached).Times(2); |
| 565 | const sp<IDisplayEventConnection> connection1 = |
| 566 | mScheduler->createDisplayEventConnection(mConnectionHandle, {}, layer1->getHandle()); |
| 567 | const sp<IDisplayEventConnection> connection2 = |
| 568 | mScheduler->createDisplayEventConnection(mConnectionHandle, {}, layer2->getHandle()); |
| 569 | |
| 570 | EXPECT_EQ(2u, mScheduler->mutableAttachedChoreographers().size()); |
| 571 | |
| 572 | ASSERT_EQ(1u, mScheduler->mutableAttachedChoreographers().count(layer1->getSequence())); |
| 573 | EXPECT_EQ(1u, |
| 574 | mScheduler->mutableAttachedChoreographers()[layer1->getSequence()] |
| 575 | .connections.size()); |
| 576 | EXPECT_FALSE( |
| 577 | mScheduler->mutableAttachedChoreographers()[layer1->getSequence()].frameRate.isValid()); |
| 578 | |
| 579 | ASSERT_EQ(1u, mScheduler->mutableAttachedChoreographers().count(layer2->getSequence())); |
| 580 | EXPECT_EQ(1u, |
| 581 | mScheduler->mutableAttachedChoreographers()[layer2->getSequence()] |
| 582 | .connections.size()); |
| 583 | EXPECT_FALSE( |
| 584 | mScheduler->mutableAttachedChoreographers()[layer2->getSequence()].frameRate.isValid()); |
| 585 | } |
| 586 | |
| 587 | TEST_F(AttachedChoreographerTest, removedWhenConnectionIsGone) { |
| 588 | EXPECT_TRUE(mScheduler->mutableAttachedChoreographers().empty()); |
| 589 | |
| 590 | const sp<MockLayer> layer = sp<MockLayer>::make(mFlinger.flinger()); |
| 591 | |
| 592 | EXPECT_CALL(mSchedulerCallback, onChoreographerAttached); |
| 593 | |
| 594 | sp<IDisplayEventConnection> connection = |
| 595 | mScheduler->createDisplayEventConnection(mConnectionHandle, {}, layer->getHandle()); |
| 596 | |
| 597 | ASSERT_EQ(1u, mScheduler->mutableAttachedChoreographers().count(layer->getSequence())); |
| 598 | EXPECT_EQ(1u, |
| 599 | mScheduler->mutableAttachedChoreographers()[layer->getSequence()].connections.size()); |
| 600 | |
| 601 | // The connection is used all over this test, so it is quite hard to release it from here. |
| 602 | // Instead, we just do a small shortcut. |
| 603 | { |
| 604 | EXPECT_CALL(*mEventThread, registerDisplayEventConnection(_)).WillOnce(Return(0)); |
| 605 | sp<MockEventThreadConnection> mockConnection = |
| 606 | sp<MockEventThreadConnection>::make(mEventThread); |
| 607 | mScheduler->mutableAttachedChoreographers()[layer->getSequence()].connections.clear(); |
| 608 | mScheduler->mutableAttachedChoreographers()[layer->getSequence()].connections.emplace( |
| 609 | mockConnection); |
| 610 | } |
| 611 | |
| 612 | RequestedLayerState layerState(LayerCreationArgs(layer->getSequence())); |
| 613 | LayerHierarchy hierarchy(&layerState); |
| 614 | mScheduler->updateAttachedChoreographers(hierarchy, 60_Hz); |
| 615 | EXPECT_TRUE(mScheduler->mutableAttachedChoreographers().empty()); |
| 616 | } |
| 617 | |
| 618 | TEST_F(AttachedChoreographerTest, removedWhenLayerIsGone) { |
| 619 | EXPECT_TRUE(mScheduler->mutableAttachedChoreographers().empty()); |
| 620 | |
| 621 | sp<MockLayer> layer = sp<MockLayer>::make(mFlinger.flinger()); |
| 622 | |
| 623 | EXPECT_CALL(mSchedulerCallback, onChoreographerAttached); |
| 624 | const sp<IDisplayEventConnection> connection = |
| 625 | mScheduler->createDisplayEventConnection(mConnectionHandle, {}, layer->getHandle()); |
| 626 | |
| 627 | layer.clear(); |
| 628 | mFlinger.mutableLayersPendingRemoval().clear(); |
| 629 | EXPECT_TRUE(mScheduler->mutableAttachedChoreographers().empty()); |
| 630 | } |
| 631 | |
| 632 | void AttachedChoreographerTest::frameRateTestScenario(Fps layerFps, int8_t frameRateCompatibility, |
| 633 | Fps displayFps, |
| 634 | Fps expectedChoreographerFps) { |
| 635 | const sp<MockLayer> layer = sp<MockLayer>::make(mFlinger.flinger()); |
| 636 | |
| 637 | EXPECT_CALL(mSchedulerCallback, onChoreographerAttached); |
| 638 | sp<IDisplayEventConnection> connection = |
| 639 | mScheduler->createDisplayEventConnection(mConnectionHandle, {}, layer->getHandle()); |
| 640 | |
| 641 | RequestedLayerState layerState(LayerCreationArgs(layer->getSequence())); |
| 642 | LayerHierarchy hierarchy(&layerState); |
| 643 | |
| 644 | layerState.frameRate = layerFps.getValue(); |
| 645 | layerState.frameRateCompatibility = frameRateCompatibility; |
| 646 | |
| 647 | mScheduler->updateAttachedChoreographers(hierarchy, displayFps); |
| 648 | |
| 649 | ASSERT_EQ(1u, mScheduler->mutableAttachedChoreographers().count(layer->getSequence())); |
| 650 | EXPECT_EQ(expectedChoreographerFps, |
| 651 | mScheduler->mutableAttachedChoreographers()[layer->getSequence()].frameRate); |
| 652 | EXPECT_EQ(expectedChoreographerFps, mEventThreadConnection->frameRate); |
| 653 | } |
| 654 | |
| 655 | TEST_F(AttachedChoreographerTest, setsFrameRateDefault) { |
| 656 | Fps layerFps = 30_Hz; |
| 657 | int8_t frameRateCompatibility = ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT; |
| 658 | Fps displayFps = 60_Hz; |
| 659 | Fps expectedChoreographerFps = 30_Hz; |
| 660 | |
| 661 | frameRateTestScenario(layerFps, frameRateCompatibility, displayFps, expectedChoreographerFps); |
| 662 | |
| 663 | layerFps = Fps::fromValue(32.7f); |
| 664 | frameRateTestScenario(layerFps, frameRateCompatibility, displayFps, expectedChoreographerFps); |
| 665 | } |
| 666 | |
| 667 | TEST_F(AttachedChoreographerTest, setsFrameRateExact) { |
| 668 | Fps layerFps = 30_Hz; |
| 669 | int8_t frameRateCompatibility = ANATIVEWINDOW_FRAME_RATE_EXACT; |
| 670 | Fps displayFps = 60_Hz; |
| 671 | Fps expectedChoreographerFps = 30_Hz; |
| 672 | |
| 673 | frameRateTestScenario(layerFps, frameRateCompatibility, displayFps, expectedChoreographerFps); |
| 674 | |
| 675 | layerFps = Fps::fromValue(32.7f); |
| 676 | expectedChoreographerFps = {}; |
| 677 | frameRateTestScenario(layerFps, frameRateCompatibility, displayFps, expectedChoreographerFps); |
| 678 | } |
| 679 | |
| 680 | TEST_F(AttachedChoreographerTest, setsFrameRateExactOrMultiple) { |
| 681 | Fps layerFps = 30_Hz; |
| 682 | int8_t frameRateCompatibility = ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_FIXED_SOURCE; |
| 683 | Fps displayFps = 60_Hz; |
| 684 | Fps expectedChoreographerFps = 30_Hz; |
| 685 | |
| 686 | frameRateTestScenario(layerFps, frameRateCompatibility, displayFps, expectedChoreographerFps); |
| 687 | |
| 688 | layerFps = Fps::fromValue(32.7f); |
| 689 | expectedChoreographerFps = {}; |
| 690 | frameRateTestScenario(layerFps, frameRateCompatibility, displayFps, expectedChoreographerFps); |
| 691 | } |
| 692 | |
| 693 | TEST_F(AttachedChoreographerTest, setsFrameRateParent) { |
| 694 | const sp<MockLayer> layer = sp<MockLayer>::make(mFlinger.flinger()); |
| 695 | const sp<MockLayer> parent = sp<MockLayer>::make(mFlinger.flinger()); |
| 696 | |
| 697 | EXPECT_CALL(mSchedulerCallback, onChoreographerAttached); |
| 698 | sp<IDisplayEventConnection> connection = |
| 699 | mScheduler->createDisplayEventConnection(mConnectionHandle, {}, parent->getHandle()); |
| 700 | |
| 701 | RequestedLayerState parentState(LayerCreationArgs(parent->getSequence())); |
| 702 | LayerHierarchy parentHierarchy(&parentState); |
| 703 | |
| 704 | RequestedLayerState layerState(LayerCreationArgs(layer->getSequence())); |
| 705 | LayerHierarchy hierarchy(&layerState); |
| 706 | parentHierarchy.mChildren.push_back( |
| 707 | std::make_pair(&hierarchy, LayerHierarchy::Variant::Attached)); |
| 708 | |
| 709 | layerState.frameRate = (30_Hz).getValue(); |
| 710 | layerState.frameRateCompatibility = ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT; |
| 711 | |
| 712 | mScheduler->updateAttachedChoreographers(parentHierarchy, 120_Hz); |
| 713 | |
| 714 | ASSERT_EQ(1u, mScheduler->mutableAttachedChoreographers().count(parent->getSequence())); |
| 715 | |
| 716 | EXPECT_EQ(30_Hz, mScheduler->mutableAttachedChoreographers()[parent->getSequence()].frameRate); |
| 717 | } |
| 718 | |
| 719 | TEST_F(AttachedChoreographerTest, setsFrameRateParent2Children) { |
| 720 | const sp<MockLayer> layer1 = sp<MockLayer>::make(mFlinger.flinger()); |
| 721 | const sp<MockLayer> layer2 = sp<MockLayer>::make(mFlinger.flinger()); |
| 722 | const sp<MockLayer> parent = sp<MockLayer>::make(mFlinger.flinger()); |
| 723 | |
| 724 | EXPECT_CALL(mSchedulerCallback, onChoreographerAttached); |
| 725 | sp<IDisplayEventConnection> connection = |
| 726 | mScheduler->createDisplayEventConnection(mConnectionHandle, {}, parent->getHandle()); |
| 727 | |
| 728 | RequestedLayerState parentState(LayerCreationArgs(parent->getSequence())); |
| 729 | LayerHierarchy parentHierarchy(&parentState); |
| 730 | |
| 731 | RequestedLayerState layer1State(LayerCreationArgs(layer1->getSequence())); |
| 732 | LayerHierarchy layer1Hierarchy(&layer1State); |
| 733 | parentHierarchy.mChildren.push_back( |
| 734 | std::make_pair(&layer1Hierarchy, LayerHierarchy::Variant::Attached)); |
| 735 | |
| 736 | RequestedLayerState layer2State(LayerCreationArgs(layer1->getSequence())); |
| 737 | LayerHierarchy layer2Hierarchy(&layer2State); |
| 738 | parentHierarchy.mChildren.push_back( |
| 739 | std::make_pair(&layer2Hierarchy, LayerHierarchy::Variant::Attached)); |
| 740 | |
| 741 | layer1State.frameRate = (30_Hz).getValue(); |
| 742 | layer1State.frameRateCompatibility = ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT; |
| 743 | |
| 744 | layer2State.frameRate = (20_Hz).getValue(); |
| 745 | layer2State.frameRateCompatibility = ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT; |
| 746 | |
| 747 | mScheduler->updateAttachedChoreographers(parentHierarchy, 120_Hz); |
| 748 | |
| 749 | ASSERT_EQ(1u, mScheduler->mutableAttachedChoreographers().count(parent->getSequence())); |
| 750 | |
| 751 | EXPECT_EQ(60_Hz, mScheduler->mutableAttachedChoreographers()[parent->getSequence()].frameRate); |
| 752 | } |
| 753 | |
| 754 | TEST_F(AttachedChoreographerTest, setsFrameRateParentConflictingChildren) { |
| 755 | const sp<MockLayer> layer1 = sp<MockLayer>::make(mFlinger.flinger()); |
| 756 | const sp<MockLayer> layer2 = sp<MockLayer>::make(mFlinger.flinger()); |
| 757 | const sp<MockLayer> parent = sp<MockLayer>::make(mFlinger.flinger()); |
| 758 | |
| 759 | EXPECT_CALL(mSchedulerCallback, onChoreographerAttached); |
| 760 | sp<IDisplayEventConnection> connection = |
| 761 | mScheduler->createDisplayEventConnection(mConnectionHandle, {}, parent->getHandle()); |
| 762 | |
| 763 | RequestedLayerState parentState(LayerCreationArgs(parent->getSequence())); |
| 764 | LayerHierarchy parentHierarchy(&parentState); |
| 765 | |
| 766 | RequestedLayerState layer1State(LayerCreationArgs(layer1->getSequence())); |
| 767 | LayerHierarchy layer1Hierarchy(&layer1State); |
| 768 | parentHierarchy.mChildren.push_back( |
| 769 | std::make_pair(&layer1Hierarchy, LayerHierarchy::Variant::Attached)); |
| 770 | |
| 771 | RequestedLayerState layer2State(LayerCreationArgs(layer1->getSequence())); |
| 772 | LayerHierarchy layer2Hierarchy(&layer2State); |
| 773 | parentHierarchy.mChildren.push_back( |
| 774 | std::make_pair(&layer2Hierarchy, LayerHierarchy::Variant::Attached)); |
| 775 | |
| 776 | layer1State.frameRate = (30_Hz).getValue(); |
| 777 | layer1State.frameRateCompatibility = ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT; |
| 778 | |
| 779 | layer2State.frameRate = (25_Hz).getValue(); |
| 780 | layer2State.frameRateCompatibility = ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT; |
| 781 | |
| 782 | mScheduler->updateAttachedChoreographers(parentHierarchy, 120_Hz); |
| 783 | |
| 784 | ASSERT_EQ(1u, mScheduler->mutableAttachedChoreographers().count(parent->getSequence())); |
| 785 | |
| 786 | EXPECT_EQ(Fps(), mScheduler->mutableAttachedChoreographers()[parent->getSequence()].frameRate); |
| 787 | } |
| 788 | |
| 789 | TEST_F(AttachedChoreographerTest, setsFrameRateChild) { |
| 790 | const sp<MockLayer> layer = sp<MockLayer>::make(mFlinger.flinger()); |
| 791 | const sp<MockLayer> parent = sp<MockLayer>::make(mFlinger.flinger()); |
| 792 | |
| 793 | EXPECT_CALL(mSchedulerCallback, onChoreographerAttached); |
| 794 | sp<IDisplayEventConnection> connection = |
| 795 | mScheduler->createDisplayEventConnection(mConnectionHandle, {}, layer->getHandle()); |
| 796 | |
| 797 | RequestedLayerState parentState(LayerCreationArgs(parent->getSequence())); |
| 798 | LayerHierarchy parentHierarchy(&parentState); |
| 799 | |
| 800 | RequestedLayerState layerState(LayerCreationArgs(layer->getSequence())); |
| 801 | LayerHierarchy hierarchy(&layerState); |
| 802 | parentHierarchy.mChildren.push_back( |
| 803 | std::make_pair(&hierarchy, LayerHierarchy::Variant::Attached)); |
| 804 | |
| 805 | parentState.frameRate = (30_Hz).getValue(); |
| 806 | parentState.frameRateCompatibility = ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT; |
| 807 | |
| 808 | mScheduler->updateAttachedChoreographers(parentHierarchy, 120_Hz); |
| 809 | |
| 810 | ASSERT_EQ(1u, mScheduler->mutableAttachedChoreographers().count(layer->getSequence())); |
| 811 | |
| 812 | EXPECT_EQ(30_Hz, mScheduler->mutableAttachedChoreographers()[layer->getSequence()].frameRate); |
| 813 | } |
| 814 | |
| 815 | TEST_F(AttachedChoreographerTest, setsFrameRateChildNotOverriddenByParent) { |
| 816 | const sp<MockLayer> layer = sp<MockLayer>::make(mFlinger.flinger()); |
| 817 | const sp<MockLayer> parent = sp<MockLayer>::make(mFlinger.flinger()); |
| 818 | |
| 819 | EXPECT_CALL(mSchedulerCallback, onChoreographerAttached); |
| 820 | sp<IDisplayEventConnection> connection = |
| 821 | mScheduler->createDisplayEventConnection(mConnectionHandle, {}, layer->getHandle()); |
| 822 | |
| 823 | RequestedLayerState parentState(LayerCreationArgs(parent->getSequence())); |
| 824 | LayerHierarchy parentHierarchy(&parentState); |
| 825 | |
| 826 | RequestedLayerState layerState(LayerCreationArgs(layer->getSequence())); |
| 827 | LayerHierarchy hierarchy(&layerState); |
| 828 | parentHierarchy.mChildren.push_back( |
| 829 | std::make_pair(&hierarchy, LayerHierarchy::Variant::Attached)); |
| 830 | |
| 831 | parentState.frameRate = (30_Hz).getValue(); |
| 832 | parentState.frameRateCompatibility = ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT; |
| 833 | |
| 834 | layerState.frameRate = (60_Hz).getValue(); |
| 835 | layerState.frameRateCompatibility = ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT; |
| 836 | |
| 837 | mScheduler->updateAttachedChoreographers(parentHierarchy, 120_Hz); |
| 838 | |
| 839 | ASSERT_EQ(1u, mScheduler->mutableAttachedChoreographers().count(layer->getSequence())); |
| 840 | |
| 841 | EXPECT_EQ(60_Hz, mScheduler->mutableAttachedChoreographers()[layer->getSequence()].frameRate); |
| 842 | } |
| 843 | |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 844 | } // namespace android::scheduler |