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