Rachel Lee | 0faad6c | 2023-09-08 13:34:34 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2023 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 | |
| 17 | #undef LOG_TAG |
| 18 | #define LOG_TAG "LibSurfaceFlingerUnittests" |
| 19 | |
| 20 | #include <gmock/gmock.h> |
| 21 | #include <gtest/gtest.h> |
| 22 | #include <gui/LayerMetadata.h> |
| 23 | |
| 24 | #include "Layer.h" |
| 25 | #include "LayerTestUtils.h" |
| 26 | #include "TestableSurfaceFlinger.h" |
| 27 | #include "mock/DisplayHardware/MockComposer.h" |
| 28 | |
| 29 | namespace android { |
| 30 | |
Ady Abraham | 9953e06 | 2024-07-24 22:56:22 -0700 | [diff] [blame] | 31 | using testing::_; |
Rachel Lee | 0faad6c | 2023-09-08 13:34:34 -0700 | [diff] [blame] | 32 | using testing::DoAll; |
| 33 | using testing::Mock; |
| 34 | using testing::SetArgPointee; |
| 35 | |
| 36 | using android::Hwc2::IComposer; |
| 37 | using android::Hwc2::IComposerClient; |
| 38 | |
| 39 | using scheduler::LayerHistory; |
| 40 | |
| 41 | using FrameRate = Layer::FrameRate; |
| 42 | using FrameRateCompatibility = Layer::FrameRateCompatibility; |
| 43 | using FrameRateSelectionStrategy = scheduler::LayerInfo::FrameRateSelectionStrategy; |
| 44 | |
| 45 | /** |
| 46 | * This class tests the behaviour of Layer::setFrameRateSelectionStrategy. |
| 47 | */ |
| 48 | class FrameRateSelectionStrategyTest : public BaseLayerTest { |
| 49 | protected: |
| 50 | const FrameRate FRAME_RATE_VOTE1 = FrameRate(11_Hz, FrameRateCompatibility::Default); |
| 51 | const FrameRate FRAME_RATE_VOTE2 = FrameRate(22_Hz, FrameRateCompatibility::Default); |
| 52 | const FrameRate FRAME_RATE_VOTE3 = FrameRate(33_Hz, FrameRateCompatibility::Default); |
Rachel Lee | a021bb0 | 2023-11-20 21:51:09 -0800 | [diff] [blame] | 53 | const FrameRate FRAME_RATE_DEFAULT = FrameRate(Fps(), FrameRateCompatibility::Default); |
Rachel Lee | 0faad6c | 2023-09-08 13:34:34 -0700 | [diff] [blame] | 54 | const FrameRate FRAME_RATE_TREE = FrameRate(Fps(), FrameRateCompatibility::NoVote); |
| 55 | |
| 56 | FrameRateSelectionStrategyTest(); |
| 57 | |
| 58 | void addChild(sp<Layer> layer, sp<Layer> child); |
| 59 | void removeChild(sp<Layer> layer, sp<Layer> child); |
| 60 | void commitTransaction(); |
| 61 | |
| 62 | std::vector<sp<Layer>> mLayers; |
| 63 | }; |
| 64 | |
| 65 | FrameRateSelectionStrategyTest::FrameRateSelectionStrategyTest() { |
| 66 | const ::testing::TestInfo* const test_info = |
| 67 | ::testing::UnitTest::GetInstance()->current_test_info(); |
| 68 | ALOGD("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name()); |
| 69 | |
| 70 | mFlinger.setupComposer(std::make_unique<Hwc2::mock::Composer>()); |
| 71 | } |
| 72 | |
| 73 | void FrameRateSelectionStrategyTest::addChild(sp<Layer> layer, sp<Layer> child) { |
| 74 | layer->addChild(child); |
| 75 | } |
| 76 | |
| 77 | void FrameRateSelectionStrategyTest::removeChild(sp<Layer> layer, sp<Layer> child) { |
| 78 | layer->removeChild(child); |
| 79 | } |
| 80 | |
| 81 | void FrameRateSelectionStrategyTest::commitTransaction() { |
| 82 | for (auto layer : mLayers) { |
| 83 | layer->commitTransaction(); |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | namespace { |
| 88 | |
| 89 | INSTANTIATE_TEST_SUITE_P(PerLayerType, FrameRateSelectionStrategyTest, |
| 90 | testing::Values(std::make_shared<BufferStateLayerFactory>(), |
| 91 | std::make_shared<EffectLayerFactory>()), |
| 92 | PrintToStringParamName); |
| 93 | |
| 94 | TEST_P(FrameRateSelectionStrategyTest, SetAndGet) { |
Ady Abraham | 9953e06 | 2024-07-24 22:56:22 -0700 | [diff] [blame] | 95 | EXPECT_CALL(*mFlinger.scheduler(), scheduleFrame(_)).Times(1); |
Rachel Lee | 0faad6c | 2023-09-08 13:34:34 -0700 | [diff] [blame] | 96 | |
| 97 | const auto& layerFactory = GetParam(); |
| 98 | auto layer = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); |
| 99 | layer->setFrameRate(FRAME_RATE_VOTE1.vote); |
| 100 | layer->setFrameRateSelectionStrategy(FrameRateSelectionStrategy::OverrideChildren); |
| 101 | commitTransaction(); |
| 102 | EXPECT_EQ(FRAME_RATE_VOTE1, layer->getFrameRateForLayerTree()); |
| 103 | EXPECT_EQ(FrameRateSelectionStrategy::OverrideChildren, |
| 104 | layer->getDrawingState().frameRateSelectionStrategy); |
| 105 | } |
| 106 | |
Rachel Lee | a021bb0 | 2023-11-20 21:51:09 -0800 | [diff] [blame] | 107 | TEST_P(FrameRateSelectionStrategyTest, SetChildOverrideChildren) { |
Ady Abraham | 9953e06 | 2024-07-24 22:56:22 -0700 | [diff] [blame] | 108 | EXPECT_CALL(*mFlinger.scheduler(), scheduleFrame(_)).Times(1); |
Rachel Lee | 0faad6c | 2023-09-08 13:34:34 -0700 | [diff] [blame] | 109 | |
| 110 | const auto& layerFactory = GetParam(); |
| 111 | auto parent = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); |
| 112 | auto child1 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); |
| 113 | auto child2 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); |
| 114 | addChild(parent, child1); |
| 115 | addChild(child1, child2); |
| 116 | |
| 117 | child2->setFrameRate(FRAME_RATE_VOTE1.vote); |
| 118 | child2->setFrameRateSelectionStrategy(FrameRateSelectionStrategy::OverrideChildren); |
| 119 | commitTransaction(); |
| 120 | EXPECT_EQ(FRAME_RATE_TREE, parent->getFrameRateForLayerTree()); |
Rachel Lee | 70f7b69 | 2023-11-22 11:24:02 -0800 | [diff] [blame] | 121 | EXPECT_EQ(FrameRateSelectionStrategy::Propagate, |
Rachel Lee | 0faad6c | 2023-09-08 13:34:34 -0700 | [diff] [blame] | 122 | parent->getDrawingState().frameRateSelectionStrategy); |
| 123 | EXPECT_EQ(FRAME_RATE_TREE, child1->getFrameRateForLayerTree()); |
Rachel Lee | 70f7b69 | 2023-11-22 11:24:02 -0800 | [diff] [blame] | 124 | EXPECT_EQ(FrameRateSelectionStrategy::Propagate, |
Rachel Lee | 0faad6c | 2023-09-08 13:34:34 -0700 | [diff] [blame] | 125 | child1->getDrawingState().frameRateSelectionStrategy); |
| 126 | EXPECT_EQ(FRAME_RATE_VOTE1, child2->getFrameRateForLayerTree()); |
| 127 | EXPECT_EQ(FrameRateSelectionStrategy::OverrideChildren, |
| 128 | child2->getDrawingState().frameRateSelectionStrategy); |
| 129 | } |
| 130 | |
Rachel Lee | a021bb0 | 2023-11-20 21:51:09 -0800 | [diff] [blame] | 131 | TEST_P(FrameRateSelectionStrategyTest, SetParentOverrideChildren) { |
Ady Abraham | 9953e06 | 2024-07-24 22:56:22 -0700 | [diff] [blame] | 132 | EXPECT_CALL(*mFlinger.scheduler(), scheduleFrame(_)).Times(1); |
Rachel Lee | 0faad6c | 2023-09-08 13:34:34 -0700 | [diff] [blame] | 133 | |
| 134 | const auto& layerFactory = GetParam(); |
| 135 | auto layer1 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); |
| 136 | auto layer2 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); |
| 137 | auto layer3 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); |
| 138 | addChild(layer1, layer2); |
| 139 | addChild(layer2, layer3); |
| 140 | |
| 141 | layer1->setFrameRate(FRAME_RATE_VOTE1.vote); |
Rachel Lee | 0faad6c | 2023-09-08 13:34:34 -0700 | [diff] [blame] | 142 | layer1->setFrameRateSelectionStrategy(FrameRateSelectionStrategy::OverrideChildren); |
| 143 | layer2->setFrameRate(FRAME_RATE_VOTE2.vote); |
| 144 | layer2->setFrameRateSelectionStrategy(FrameRateSelectionStrategy::OverrideChildren); |
| 145 | layer3->setFrameRate(FRAME_RATE_VOTE3.vote); |
| 146 | commitTransaction(); |
| 147 | |
| 148 | EXPECT_EQ(FRAME_RATE_VOTE1, layer1->getFrameRateForLayerTree()); |
| 149 | EXPECT_EQ(FrameRateSelectionStrategy::OverrideChildren, |
| 150 | layer1->getDrawingState().frameRateSelectionStrategy); |
| 151 | EXPECT_EQ(FRAME_RATE_VOTE1, layer2->getFrameRateForLayerTree()); |
| 152 | EXPECT_EQ(FrameRateSelectionStrategy::OverrideChildren, |
| 153 | layer2->getDrawingState().frameRateSelectionStrategy); |
| 154 | EXPECT_EQ(FRAME_RATE_VOTE1, layer3->getFrameRateForLayerTree()); |
Rachel Lee | 70f7b69 | 2023-11-22 11:24:02 -0800 | [diff] [blame] | 155 | EXPECT_EQ(FrameRateSelectionStrategy::Propagate, |
Rachel Lee | 0faad6c | 2023-09-08 13:34:34 -0700 | [diff] [blame] | 156 | layer3->getDrawingState().frameRateSelectionStrategy); |
Rachel Lee | d747950 | 2023-09-25 17:02:35 -0700 | [diff] [blame] | 157 | |
Rachel Lee | 70f7b69 | 2023-11-22 11:24:02 -0800 | [diff] [blame] | 158 | layer1->setFrameRateSelectionStrategy(FrameRateSelectionStrategy::Propagate); |
Rachel Lee | d747950 | 2023-09-25 17:02:35 -0700 | [diff] [blame] | 159 | commitTransaction(); |
| 160 | |
| 161 | EXPECT_EQ(FRAME_RATE_VOTE1, layer1->getFrameRateForLayerTree()); |
Rachel Lee | 70f7b69 | 2023-11-22 11:24:02 -0800 | [diff] [blame] | 162 | EXPECT_EQ(FrameRateSelectionStrategy::Propagate, |
Rachel Lee | d747950 | 2023-09-25 17:02:35 -0700 | [diff] [blame] | 163 | layer1->getDrawingState().frameRateSelectionStrategy); |
| 164 | EXPECT_EQ(FRAME_RATE_VOTE2, layer2->getFrameRateForLayerTree()); |
| 165 | EXPECT_EQ(FrameRateSelectionStrategy::OverrideChildren, |
| 166 | layer2->getDrawingState().frameRateSelectionStrategy); |
| 167 | EXPECT_EQ(FRAME_RATE_VOTE2, layer3->getFrameRateForLayerTree()); |
Rachel Lee | 70f7b69 | 2023-11-22 11:24:02 -0800 | [diff] [blame] | 168 | EXPECT_EQ(FrameRateSelectionStrategy::Propagate, |
Rachel Lee | d747950 | 2023-09-25 17:02:35 -0700 | [diff] [blame] | 169 | layer3->getDrawingState().frameRateSelectionStrategy); |
Rachel Lee | 0faad6c | 2023-09-08 13:34:34 -0700 | [diff] [blame] | 170 | } |
| 171 | |
Rachel Lee | 70f7b69 | 2023-11-22 11:24:02 -0800 | [diff] [blame] | 172 | TEST_P(FrameRateSelectionStrategyTest, OverrideChildrenAndSelf) { |
Ady Abraham | 9953e06 | 2024-07-24 22:56:22 -0700 | [diff] [blame] | 173 | EXPECT_CALL(*mFlinger.scheduler(), scheduleFrame(_)).Times(1); |
Rachel Lee | a021bb0 | 2023-11-20 21:51:09 -0800 | [diff] [blame] | 174 | |
| 175 | const auto& layerFactory = GetParam(); |
| 176 | auto layer1 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); |
| 177 | auto layer2 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); |
| 178 | auto layer3 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); |
| 179 | addChild(layer1, layer2); |
| 180 | addChild(layer2, layer3); |
| 181 | |
| 182 | layer1->setFrameRate(FRAME_RATE_VOTE1.vote); |
| 183 | layer2->setFrameRate(FRAME_RATE_VOTE2.vote); |
Rachel Lee | 70f7b69 | 2023-11-22 11:24:02 -0800 | [diff] [blame] | 184 | layer2->setFrameRateSelectionStrategy(FrameRateSelectionStrategy::Self); |
Rachel Lee | a021bb0 | 2023-11-20 21:51:09 -0800 | [diff] [blame] | 185 | commitTransaction(); |
| 186 | |
| 187 | EXPECT_EQ(FRAME_RATE_VOTE1, layer1->getFrameRateForLayerTree()); |
Rachel Lee | 70f7b69 | 2023-11-22 11:24:02 -0800 | [diff] [blame] | 188 | EXPECT_EQ(FrameRateSelectionStrategy::Propagate, |
Rachel Lee | a021bb0 | 2023-11-20 21:51:09 -0800 | [diff] [blame] | 189 | layer1->getDrawingState().frameRateSelectionStrategy); |
| 190 | EXPECT_EQ(FRAME_RATE_VOTE2, layer2->getFrameRateForLayerTree()); |
Rachel Lee | 70f7b69 | 2023-11-22 11:24:02 -0800 | [diff] [blame] | 191 | EXPECT_EQ(FrameRateSelectionStrategy::Self, |
Rachel Lee | a021bb0 | 2023-11-20 21:51:09 -0800 | [diff] [blame] | 192 | layer2->getDrawingState().frameRateSelectionStrategy); |
| 193 | EXPECT_EQ(FRAME_RATE_DEFAULT, layer3->getFrameRateForLayerTree()); |
Rachel Lee | 70f7b69 | 2023-11-22 11:24:02 -0800 | [diff] [blame] | 194 | EXPECT_EQ(FrameRateSelectionStrategy::Propagate, |
Rachel Lee | a021bb0 | 2023-11-20 21:51:09 -0800 | [diff] [blame] | 195 | layer3->getDrawingState().frameRateSelectionStrategy); |
| 196 | |
| 197 | layer1->setFrameRateSelectionStrategy(FrameRateSelectionStrategy::OverrideChildren); |
| 198 | commitTransaction(); |
| 199 | |
| 200 | EXPECT_EQ(FRAME_RATE_VOTE1, layer1->getFrameRateForLayerTree()); |
| 201 | EXPECT_EQ(FrameRateSelectionStrategy::OverrideChildren, |
| 202 | layer1->getDrawingState().frameRateSelectionStrategy); |
| 203 | EXPECT_EQ(FRAME_RATE_VOTE1, layer2->getFrameRateForLayerTree()); |
Rachel Lee | 70f7b69 | 2023-11-22 11:24:02 -0800 | [diff] [blame] | 204 | EXPECT_EQ(FrameRateSelectionStrategy::Self, |
Rachel Lee | a021bb0 | 2023-11-20 21:51:09 -0800 | [diff] [blame] | 205 | layer2->getDrawingState().frameRateSelectionStrategy); |
| 206 | EXPECT_EQ(FRAME_RATE_VOTE1, layer3->getFrameRateForLayerTree()); |
Rachel Lee | 70f7b69 | 2023-11-22 11:24:02 -0800 | [diff] [blame] | 207 | EXPECT_EQ(FrameRateSelectionStrategy::Propagate, |
Rachel Lee | a021bb0 | 2023-11-20 21:51:09 -0800 | [diff] [blame] | 208 | layer3->getDrawingState().frameRateSelectionStrategy); |
| 209 | |
| 210 | layer1->setFrameRate(FRAME_RATE_DEFAULT.vote); |
| 211 | commitTransaction(); |
| 212 | |
| 213 | EXPECT_EQ(FRAME_RATE_TREE, layer1->getFrameRateForLayerTree()); |
| 214 | EXPECT_EQ(FrameRateSelectionStrategy::OverrideChildren, |
| 215 | layer1->getDrawingState().frameRateSelectionStrategy); |
| 216 | EXPECT_EQ(FRAME_RATE_VOTE2, layer2->getFrameRateForLayerTree()); |
Rachel Lee | 70f7b69 | 2023-11-22 11:24:02 -0800 | [diff] [blame] | 217 | EXPECT_EQ(FrameRateSelectionStrategy::Self, |
Rachel Lee | a021bb0 | 2023-11-20 21:51:09 -0800 | [diff] [blame] | 218 | layer2->getDrawingState().frameRateSelectionStrategy); |
| 219 | EXPECT_EQ(FRAME_RATE_VOTE2, layer3->getFrameRateForLayerTree()); |
Rachel Lee | 70f7b69 | 2023-11-22 11:24:02 -0800 | [diff] [blame] | 220 | EXPECT_EQ(FrameRateSelectionStrategy::Propagate, |
Rachel Lee | a021bb0 | 2023-11-20 21:51:09 -0800 | [diff] [blame] | 221 | layer3->getDrawingState().frameRateSelectionStrategy); |
| 222 | } |
| 223 | |
Rachel Lee | 0faad6c | 2023-09-08 13:34:34 -0700 | [diff] [blame] | 224 | } // namespace |
| 225 | } // namespace android |