| Ady Abraham | 60e42ea | 2020-03-09 19:17:31 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright 2020 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 | // TODO(b/129481165): remove the #pragma below and fix conversion issues | 
|  | 25 | #pragma clang diagnostic push | 
|  | 26 | #pragma clang diagnostic ignored "-Wconversion" | 
|  | 27 | #include "BufferQueueLayer.h" | 
|  | 28 | #include "BufferStateLayer.h" | 
|  | 29 | #include "EffectLayer.h" | 
|  | 30 | #include "Layer.h" | 
|  | 31 | // TODO(b/129481165): remove the #pragma below and fix conversion issues | 
|  | 32 | #pragma clang diagnostic pop // ignored "-Wconversion" | 
|  | 33 | #include "TestableSurfaceFlinger.h" | 
|  | 34 | #include "mock/DisplayHardware/MockComposer.h" | 
| Ady Abraham | 60e42ea | 2020-03-09 19:17:31 -0700 | [diff] [blame] | 35 | #include "mock/MockEventThread.h" | 
|  | 36 | #include "mock/MockMessageQueue.h" | 
| Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 37 | #include "mock/MockVsyncController.h" | 
| Ady Abraham | 60e42ea | 2020-03-09 19:17:31 -0700 | [diff] [blame] | 38 |  | 
|  | 39 | namespace android { | 
|  | 40 |  | 
|  | 41 | using testing::_; | 
|  | 42 | using testing::DoAll; | 
|  | 43 | using testing::Mock; | 
|  | 44 | using testing::Return; | 
|  | 45 | using testing::SetArgPointee; | 
|  | 46 |  | 
|  | 47 | using android::Hwc2::IComposer; | 
|  | 48 | using android::Hwc2::IComposerClient; | 
|  | 49 |  | 
|  | 50 | using FakeHwcDisplayInjector = TestableSurfaceFlinger::FakeHwcDisplayInjector; | 
|  | 51 |  | 
|  | 52 | using FrameRate = Layer::FrameRate; | 
|  | 53 | using FrameRateCompatibility = Layer::FrameRateCompatibility; | 
|  | 54 |  | 
|  | 55 | class LayerFactory { | 
|  | 56 | public: | 
|  | 57 | virtual ~LayerFactory() = default; | 
|  | 58 |  | 
|  | 59 | virtual std::string name() = 0; | 
|  | 60 | virtual sp<Layer> createLayer(TestableSurfaceFlinger& flinger) = 0; | 
|  | 61 |  | 
|  | 62 | protected: | 
|  | 63 | static constexpr uint32_t WIDTH = 100; | 
|  | 64 | static constexpr uint32_t HEIGHT = 100; | 
|  | 65 | static constexpr uint32_t LAYER_FLAGS = 0; | 
|  | 66 | }; | 
|  | 67 |  | 
|  | 68 | class BufferQueueLayerFactory : public LayerFactory { | 
|  | 69 | public: | 
|  | 70 | std::string name() override { return "BufferQueueLayer"; } | 
|  | 71 | sp<Layer> createLayer(TestableSurfaceFlinger& flinger) override { | 
|  | 72 | sp<Client> client; | 
|  | 73 | LayerCreationArgs args(flinger.flinger(), client, "buffer-queue-layer", WIDTH, HEIGHT, | 
|  | 74 | LAYER_FLAGS, LayerMetadata()); | 
|  | 75 | return new BufferQueueLayer(args); | 
|  | 76 | } | 
|  | 77 | }; | 
|  | 78 |  | 
|  | 79 | class BufferStateLayerFactory : public LayerFactory { | 
|  | 80 | public: | 
|  | 81 | std::string name() override { return "BufferStateLayer"; } | 
|  | 82 | sp<Layer> createLayer(TestableSurfaceFlinger& flinger) override { | 
|  | 83 | sp<Client> client; | 
|  | 84 | LayerCreationArgs args(flinger.flinger(), client, "buffer-queue-layer", WIDTH, HEIGHT, | 
|  | 85 | LAYER_FLAGS, LayerMetadata()); | 
|  | 86 | return new BufferStateLayer(args); | 
|  | 87 | } | 
|  | 88 | }; | 
|  | 89 |  | 
|  | 90 | class EffectLayerFactory : public LayerFactory { | 
|  | 91 | public: | 
|  | 92 | std::string name() override { return "EffectLayer"; } | 
|  | 93 | sp<Layer> createLayer(TestableSurfaceFlinger& flinger) override { | 
|  | 94 | sp<Client> client; | 
|  | 95 | LayerCreationArgs args(flinger.flinger(), client, "color-layer", WIDTH, HEIGHT, LAYER_FLAGS, | 
|  | 96 | LayerMetadata()); | 
|  | 97 | return new EffectLayer(args); | 
|  | 98 | } | 
|  | 99 | }; | 
|  | 100 |  | 
|  | 101 | std::string PrintToStringParamName( | 
|  | 102 | const ::testing::TestParamInfo<std::shared_ptr<LayerFactory>>& info) { | 
|  | 103 | return info.param->name(); | 
|  | 104 | } | 
|  | 105 |  | 
|  | 106 | /** | 
|  | 107 | * This class tests the behaviour of Layer::SetFrameRate and Layer::GetFrameRate | 
|  | 108 | */ | 
|  | 109 | class SetFrameRateTest : public ::testing::TestWithParam<std::shared_ptr<LayerFactory>> { | 
|  | 110 | protected: | 
| Marin Shalamanov | e8a663d | 2020-11-24 17:48:00 +0100 | [diff] [blame] | 111 | const FrameRate FRAME_RATE_VOTE1 = FrameRate(Fps(67.f), FrameRateCompatibility::Default); | 
|  | 112 | const FrameRate FRAME_RATE_VOTE2 = | 
|  | 113 | FrameRate(Fps(14.f), FrameRateCompatibility::ExactOrMultiple); | 
|  | 114 | const FrameRate FRAME_RATE_VOTE3 = FrameRate(Fps(99.f), FrameRateCompatibility::NoVote); | 
|  | 115 | const FrameRate FRAME_RATE_TREE = FrameRate(Fps(0.f), FrameRateCompatibility::NoVote); | 
|  | 116 | const FrameRate FRAME_RATE_NO_VOTE = FrameRate(Fps(0.f), FrameRateCompatibility::Default); | 
| Ady Abraham | 60e42ea | 2020-03-09 19:17:31 -0700 | [diff] [blame] | 117 |  | 
|  | 118 | SetFrameRateTest(); | 
|  | 119 |  | 
|  | 120 | void setupScheduler(); | 
|  | 121 | void setupComposer(uint32_t virtualDisplayCount); | 
|  | 122 |  | 
|  | 123 | void addChild(sp<Layer> layer, sp<Layer> child); | 
|  | 124 | void removeChild(sp<Layer> layer, sp<Layer> child); | 
|  | 125 | void reparentChildren(sp<Layer> layer, sp<Layer> child); | 
|  | 126 | void commitTransaction(); | 
|  | 127 |  | 
|  | 128 | TestableSurfaceFlinger mFlinger; | 
|  | 129 | Hwc2::mock::Composer* mComposer = nullptr; | 
|  | 130 | mock::MessageQueue* mMessageQueue = new mock::MessageQueue(); | 
|  | 131 |  | 
|  | 132 | std::vector<sp<Layer>> mLayers; | 
|  | 133 | }; | 
|  | 134 |  | 
|  | 135 | SetFrameRateTest::SetFrameRateTest() { | 
|  | 136 | const ::testing::TestInfo* const test_info = | 
|  | 137 | ::testing::UnitTest::GetInstance()->current_test_info(); | 
|  | 138 | ALOGD("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name()); | 
|  | 139 |  | 
|  | 140 | mFlinger.mutableUseFrameRateApi() = true; | 
|  | 141 |  | 
|  | 142 | setupScheduler(); | 
|  | 143 | setupComposer(0); | 
|  | 144 |  | 
|  | 145 | mFlinger.mutableEventQueue().reset(mMessageQueue); | 
|  | 146 | } | 
|  | 147 | void SetFrameRateTest::addChild(sp<Layer> layer, sp<Layer> child) { | 
|  | 148 | layer.get()->addChild(child.get()); | 
|  | 149 | } | 
|  | 150 |  | 
|  | 151 | void SetFrameRateTest::removeChild(sp<Layer> layer, sp<Layer> child) { | 
|  | 152 | layer.get()->removeChild(child.get()); | 
|  | 153 | } | 
|  | 154 |  | 
|  | 155 | void SetFrameRateTest::reparentChildren(sp<Layer> parent, sp<Layer> newParent) { | 
|  | 156 | parent.get()->reparentChildren(newParent); | 
|  | 157 | } | 
|  | 158 |  | 
|  | 159 | void SetFrameRateTest::commitTransaction() { | 
|  | 160 | for (auto layer : mLayers) { | 
| Ady Abraham | 22c7b5c | 2020-09-22 19:33:40 -0700 | [diff] [blame] | 161 | layer->pushPendingState(); | 
|  | 162 | auto c = layer->getCurrentState(); | 
|  | 163 | if (layer->applyPendingStates(&c)) { | 
|  | 164 | layer->commitTransaction(c); | 
|  | 165 | } | 
| Ady Abraham | 60e42ea | 2020-03-09 19:17:31 -0700 | [diff] [blame] | 166 | } | 
|  | 167 | } | 
|  | 168 |  | 
|  | 169 | void SetFrameRateTest::setupScheduler() { | 
|  | 170 | auto eventThread = std::make_unique<mock::EventThread>(); | 
|  | 171 | auto sfEventThread = std::make_unique<mock::EventThread>(); | 
|  | 172 |  | 
|  | 173 | EXPECT_CALL(*eventThread, registerDisplayEventConnection(_)); | 
|  | 174 | EXPECT_CALL(*eventThread, createEventConnection(_, _)) | 
| Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame] | 175 | .WillOnce(Return(new EventThreadConnection(eventThread.get(), /*callingUid=*/0, | 
| Ady Abraham | 62f216c | 2020-10-13 19:07:23 -0700 | [diff] [blame] | 176 | ResyncCallback()))); | 
| Ady Abraham | 60e42ea | 2020-03-09 19:17:31 -0700 | [diff] [blame] | 177 |  | 
|  | 178 | EXPECT_CALL(*sfEventThread, registerDisplayEventConnection(_)); | 
|  | 179 | EXPECT_CALL(*sfEventThread, createEventConnection(_, _)) | 
| Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame] | 180 | .WillOnce(Return(new EventThreadConnection(sfEventThread.get(), /*callingUid=*/0, | 
| Ady Abraham | 62f216c | 2020-10-13 19:07:23 -0700 | [diff] [blame] | 181 | ResyncCallback()))); | 
| Ady Abraham | 60e42ea | 2020-03-09 19:17:31 -0700 | [diff] [blame] | 182 |  | 
| Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 183 | auto vsyncController = std::make_unique<mock::VsyncController>(); | 
|  | 184 | auto vsyncTracker = std::make_unique<mock::VSyncTracker>(); | 
| Ady Abraham | 60e42ea | 2020-03-09 19:17:31 -0700 | [diff] [blame] | 185 |  | 
| Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 186 | EXPECT_CALL(*vsyncTracker, nextAnticipatedVSyncTimeFrom(_)).WillRepeatedly(Return(0)); | 
|  | 187 | EXPECT_CALL(*vsyncTracker, currentPeriod()) | 
| Ady Abraham | 60e42ea | 2020-03-09 19:17:31 -0700 | [diff] [blame] | 188 | .WillRepeatedly(Return(FakeHwcDisplayInjector::DEFAULT_REFRESH_RATE)); | 
| Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 189 | EXPECT_CALL(*vsyncTracker, nextAnticipatedVSyncTimeFrom(_)).WillRepeatedly(Return(0)); | 
|  | 190 | mFlinger.setupScheduler(std::move(vsyncController), std::move(vsyncTracker), | 
|  | 191 | std::move(eventThread), std::move(sfEventThread)); | 
| Ady Abraham | 60e42ea | 2020-03-09 19:17:31 -0700 | [diff] [blame] | 192 | } | 
|  | 193 |  | 
|  | 194 | void SetFrameRateTest::setupComposer(uint32_t virtualDisplayCount) { | 
|  | 195 | mComposer = new Hwc2::mock::Composer(); | 
|  | 196 | EXPECT_CALL(*mComposer, getMaxVirtualDisplayCount()).WillOnce(Return(virtualDisplayCount)); | 
|  | 197 | mFlinger.setupComposer(std::unique_ptr<Hwc2::Composer>(mComposer)); | 
|  | 198 |  | 
|  | 199 | Mock::VerifyAndClear(mComposer); | 
|  | 200 | } | 
|  | 201 |  | 
|  | 202 | namespace { | 
|  | 203 | /* ------------------------------------------------------------------------ | 
|  | 204 | * Test cases | 
|  | 205 | */ | 
|  | 206 | TEST_P(SetFrameRateTest, SetAndGet) { | 
|  | 207 | EXPECT_CALL(*mMessageQueue, invalidate()).Times(1); | 
|  | 208 |  | 
|  | 209 | const auto& layerFactory = GetParam(); | 
|  | 210 |  | 
|  | 211 | auto layer = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); | 
|  | 212 | layer->setFrameRate(FRAME_RATE_VOTE1); | 
|  | 213 | commitTransaction(); | 
|  | 214 | EXPECT_EQ(FRAME_RATE_VOTE1, layer->getFrameRateForLayerTree()); | 
|  | 215 | } | 
|  | 216 |  | 
|  | 217 | TEST_P(SetFrameRateTest, SetAndGetParent) { | 
|  | 218 | EXPECT_CALL(*mMessageQueue, invalidate()).Times(1); | 
|  | 219 |  | 
|  | 220 | const auto& layerFactory = GetParam(); | 
|  | 221 |  | 
|  | 222 | auto parent = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); | 
|  | 223 | auto child1 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); | 
|  | 224 | auto child2 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); | 
|  | 225 |  | 
|  | 226 | addChild(parent, child1); | 
|  | 227 | addChild(child1, child2); | 
|  | 228 |  | 
|  | 229 | child2->setFrameRate(FRAME_RATE_VOTE1); | 
|  | 230 | commitTransaction(); | 
|  | 231 | EXPECT_EQ(FRAME_RATE_TREE, parent->getFrameRateForLayerTree()); | 
|  | 232 | EXPECT_EQ(FRAME_RATE_TREE, child1->getFrameRateForLayerTree()); | 
|  | 233 | EXPECT_EQ(FRAME_RATE_VOTE1, child2->getFrameRateForLayerTree()); | 
|  | 234 |  | 
|  | 235 | child2->setFrameRate(FRAME_RATE_NO_VOTE); | 
|  | 236 | commitTransaction(); | 
|  | 237 | EXPECT_EQ(FRAME_RATE_NO_VOTE, parent->getFrameRateForLayerTree()); | 
|  | 238 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child1->getFrameRateForLayerTree()); | 
|  | 239 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child2->getFrameRateForLayerTree()); | 
|  | 240 | } | 
|  | 241 |  | 
|  | 242 | TEST_P(SetFrameRateTest, SetAndGetParentAllVote) { | 
|  | 243 | EXPECT_CALL(*mMessageQueue, invalidate()).Times(1); | 
|  | 244 |  | 
|  | 245 | const auto& layerFactory = GetParam(); | 
|  | 246 |  | 
|  | 247 | auto parent = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); | 
|  | 248 | auto child1 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); | 
|  | 249 | auto child2 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); | 
|  | 250 |  | 
|  | 251 | addChild(parent, child1); | 
|  | 252 | addChild(child1, child2); | 
|  | 253 |  | 
|  | 254 | child2->setFrameRate(FRAME_RATE_VOTE1); | 
|  | 255 | child1->setFrameRate(FRAME_RATE_VOTE2); | 
|  | 256 | parent->setFrameRate(FRAME_RATE_VOTE3); | 
|  | 257 | commitTransaction(); | 
|  | 258 | EXPECT_EQ(FRAME_RATE_VOTE3, parent->getFrameRateForLayerTree()); | 
|  | 259 | EXPECT_EQ(FRAME_RATE_VOTE2, child1->getFrameRateForLayerTree()); | 
|  | 260 | EXPECT_EQ(FRAME_RATE_VOTE1, child2->getFrameRateForLayerTree()); | 
|  | 261 |  | 
|  | 262 | child2->setFrameRate(FRAME_RATE_NO_VOTE); | 
|  | 263 | commitTransaction(); | 
|  | 264 | EXPECT_EQ(FRAME_RATE_VOTE3, parent->getFrameRateForLayerTree()); | 
|  | 265 | EXPECT_EQ(FRAME_RATE_VOTE2, child1->getFrameRateForLayerTree()); | 
|  | 266 | EXPECT_EQ(FRAME_RATE_TREE, child2->getFrameRateForLayerTree()); | 
|  | 267 |  | 
|  | 268 | child1->setFrameRate(FRAME_RATE_NO_VOTE); | 
|  | 269 | commitTransaction(); | 
|  | 270 | EXPECT_EQ(FRAME_RATE_VOTE3, parent->getFrameRateForLayerTree()); | 
|  | 271 | EXPECT_EQ(FRAME_RATE_TREE, child1->getFrameRateForLayerTree()); | 
|  | 272 | EXPECT_EQ(FRAME_RATE_TREE, child2->getFrameRateForLayerTree()); | 
|  | 273 |  | 
|  | 274 | parent->setFrameRate(FRAME_RATE_NO_VOTE); | 
|  | 275 | commitTransaction(); | 
|  | 276 | EXPECT_EQ(FRAME_RATE_NO_VOTE, parent->getFrameRateForLayerTree()); | 
|  | 277 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child1->getFrameRateForLayerTree()); | 
|  | 278 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child2->getFrameRateForLayerTree()); | 
|  | 279 | } | 
|  | 280 |  | 
|  | 281 | TEST_P(SetFrameRateTest, SetAndGetChild) { | 
|  | 282 | EXPECT_CALL(*mMessageQueue, invalidate()).Times(1); | 
|  | 283 |  | 
|  | 284 | const auto& layerFactory = GetParam(); | 
|  | 285 |  | 
|  | 286 | auto parent = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); | 
|  | 287 | auto child1 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); | 
|  | 288 | auto child2 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); | 
|  | 289 |  | 
|  | 290 | addChild(parent, child1); | 
|  | 291 | addChild(child1, child2); | 
|  | 292 |  | 
|  | 293 | parent->setFrameRate(FRAME_RATE_VOTE1); | 
|  | 294 | commitTransaction(); | 
|  | 295 | EXPECT_EQ(FRAME_RATE_VOTE1, parent->getFrameRateForLayerTree()); | 
|  | 296 | EXPECT_EQ(FRAME_RATE_TREE, child1->getFrameRateForLayerTree()); | 
|  | 297 | EXPECT_EQ(FRAME_RATE_TREE, child2->getFrameRateForLayerTree()); | 
|  | 298 |  | 
|  | 299 | parent->setFrameRate(FRAME_RATE_NO_VOTE); | 
|  | 300 | commitTransaction(); | 
|  | 301 | EXPECT_EQ(FRAME_RATE_NO_VOTE, parent->getFrameRateForLayerTree()); | 
|  | 302 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child1->getFrameRateForLayerTree()); | 
|  | 303 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child2->getFrameRateForLayerTree()); | 
|  | 304 | } | 
|  | 305 |  | 
|  | 306 | TEST_P(SetFrameRateTest, SetAndGetChildAllVote) { | 
|  | 307 | EXPECT_CALL(*mMessageQueue, invalidate()).Times(1); | 
|  | 308 |  | 
|  | 309 | const auto& layerFactory = GetParam(); | 
|  | 310 |  | 
|  | 311 | auto parent = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); | 
|  | 312 | auto child1 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); | 
|  | 313 | auto child2 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); | 
|  | 314 |  | 
|  | 315 | addChild(parent, child1); | 
|  | 316 | addChild(child1, child2); | 
|  | 317 |  | 
|  | 318 | child2->setFrameRate(FRAME_RATE_VOTE1); | 
|  | 319 | child1->setFrameRate(FRAME_RATE_VOTE2); | 
|  | 320 | parent->setFrameRate(FRAME_RATE_VOTE3); | 
|  | 321 | commitTransaction(); | 
|  | 322 | EXPECT_EQ(FRAME_RATE_VOTE3, parent->getFrameRateForLayerTree()); | 
|  | 323 | EXPECT_EQ(FRAME_RATE_VOTE2, child1->getFrameRateForLayerTree()); | 
|  | 324 | EXPECT_EQ(FRAME_RATE_VOTE1, child2->getFrameRateForLayerTree()); | 
|  | 325 |  | 
|  | 326 | parent->setFrameRate(FRAME_RATE_NO_VOTE); | 
|  | 327 | commitTransaction(); | 
|  | 328 | EXPECT_EQ(FRAME_RATE_TREE, parent->getFrameRateForLayerTree()); | 
|  | 329 | EXPECT_EQ(FRAME_RATE_VOTE2, child1->getFrameRateForLayerTree()); | 
|  | 330 | EXPECT_EQ(FRAME_RATE_VOTE1, child2->getFrameRateForLayerTree()); | 
|  | 331 |  | 
|  | 332 | child1->setFrameRate(FRAME_RATE_NO_VOTE); | 
|  | 333 | commitTransaction(); | 
|  | 334 | EXPECT_EQ(FRAME_RATE_TREE, parent->getFrameRateForLayerTree()); | 
|  | 335 | EXPECT_EQ(FRAME_RATE_TREE, child1->getFrameRateForLayerTree()); | 
|  | 336 | EXPECT_EQ(FRAME_RATE_VOTE1, child2->getFrameRateForLayerTree()); | 
|  | 337 |  | 
|  | 338 | child2->setFrameRate(FRAME_RATE_NO_VOTE); | 
|  | 339 | commitTransaction(); | 
|  | 340 | EXPECT_EQ(FRAME_RATE_NO_VOTE, parent->getFrameRateForLayerTree()); | 
|  | 341 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child1->getFrameRateForLayerTree()); | 
|  | 342 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child2->getFrameRateForLayerTree()); | 
|  | 343 | } | 
|  | 344 |  | 
|  | 345 | TEST_P(SetFrameRateTest, SetAndGetChildAddAfterVote) { | 
|  | 346 | EXPECT_CALL(*mMessageQueue, invalidate()).Times(1); | 
|  | 347 |  | 
|  | 348 | const auto& layerFactory = GetParam(); | 
|  | 349 |  | 
|  | 350 | auto parent = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); | 
|  | 351 | auto child1 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); | 
|  | 352 | auto child2 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); | 
|  | 353 |  | 
|  | 354 | addChild(parent, child1); | 
|  | 355 |  | 
|  | 356 | parent->setFrameRate(FRAME_RATE_VOTE1); | 
|  | 357 | commitTransaction(); | 
|  | 358 | EXPECT_EQ(FRAME_RATE_VOTE1, parent->getFrameRateForLayerTree()); | 
|  | 359 | EXPECT_EQ(FRAME_RATE_TREE, child1->getFrameRateForLayerTree()); | 
|  | 360 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child2->getFrameRateForLayerTree()); | 
|  | 361 |  | 
|  | 362 | addChild(child1, child2); | 
|  | 363 | commitTransaction(); | 
|  | 364 | EXPECT_EQ(FRAME_RATE_VOTE1, parent->getFrameRateForLayerTree()); | 
|  | 365 | EXPECT_EQ(FRAME_RATE_TREE, child1->getFrameRateForLayerTree()); | 
|  | 366 | EXPECT_EQ(FRAME_RATE_TREE, child2->getFrameRateForLayerTree()); | 
|  | 367 |  | 
|  | 368 | parent->setFrameRate(FRAME_RATE_NO_VOTE); | 
|  | 369 | commitTransaction(); | 
|  | 370 | EXPECT_EQ(FRAME_RATE_NO_VOTE, parent->getFrameRateForLayerTree()); | 
|  | 371 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child1->getFrameRateForLayerTree()); | 
|  | 372 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child2->getFrameRateForLayerTree()); | 
|  | 373 | } | 
|  | 374 |  | 
|  | 375 | TEST_P(SetFrameRateTest, SetAndGetChildRemoveAfterVote) { | 
|  | 376 | EXPECT_CALL(*mMessageQueue, invalidate()).Times(1); | 
|  | 377 |  | 
|  | 378 | const auto& layerFactory = GetParam(); | 
|  | 379 |  | 
|  | 380 | auto parent = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); | 
|  | 381 | auto child1 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); | 
|  | 382 | auto child2 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); | 
|  | 383 |  | 
|  | 384 | addChild(parent, child1); | 
|  | 385 | addChild(child1, child2); | 
|  | 386 |  | 
|  | 387 | parent->setFrameRate(FRAME_RATE_VOTE1); | 
|  | 388 | commitTransaction(); | 
|  | 389 | EXPECT_EQ(FRAME_RATE_VOTE1, parent->getFrameRateForLayerTree()); | 
|  | 390 | EXPECT_EQ(FRAME_RATE_TREE, child1->getFrameRateForLayerTree()); | 
|  | 391 | EXPECT_EQ(FRAME_RATE_TREE, child2->getFrameRateForLayerTree()); | 
|  | 392 |  | 
|  | 393 | removeChild(child1, child2); | 
|  | 394 | commitTransaction(); | 
|  | 395 | EXPECT_EQ(FRAME_RATE_VOTE1, parent->getFrameRateForLayerTree()); | 
|  | 396 | EXPECT_EQ(FRAME_RATE_TREE, child1->getFrameRateForLayerTree()); | 
|  | 397 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child2->getFrameRateForLayerTree()); | 
|  | 398 |  | 
|  | 399 | parent->setFrameRate(FRAME_RATE_NO_VOTE); | 
|  | 400 | commitTransaction(); | 
|  | 401 | EXPECT_EQ(FRAME_RATE_NO_VOTE, parent->getFrameRateForLayerTree()); | 
|  | 402 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child1->getFrameRateForLayerTree()); | 
|  | 403 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child2->getFrameRateForLayerTree()); | 
|  | 404 | } | 
|  | 405 |  | 
|  | 406 | TEST_P(SetFrameRateTest, SetAndGetParentNotInTree) { | 
|  | 407 | EXPECT_CALL(*mMessageQueue, invalidate()).Times(1); | 
|  | 408 |  | 
|  | 409 | const auto& layerFactory = GetParam(); | 
|  | 410 |  | 
|  | 411 | auto parent = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); | 
|  | 412 | auto child1 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); | 
|  | 413 | auto child2 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); | 
|  | 414 | auto child2_1 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); | 
|  | 415 |  | 
|  | 416 | addChild(parent, child1); | 
|  | 417 | addChild(child1, child2); | 
|  | 418 | addChild(child1, child2_1); | 
|  | 419 |  | 
|  | 420 | child2->setFrameRate(FRAME_RATE_VOTE1); | 
|  | 421 | commitTransaction(); | 
|  | 422 | EXPECT_EQ(FRAME_RATE_TREE, parent->getFrameRateForLayerTree()); | 
|  | 423 | EXPECT_EQ(FRAME_RATE_TREE, child1->getFrameRateForLayerTree()); | 
|  | 424 | EXPECT_EQ(FRAME_RATE_VOTE1, child2->getFrameRateForLayerTree()); | 
|  | 425 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child2_1->getFrameRateForLayerTree()); | 
|  | 426 |  | 
|  | 427 | child2->setFrameRate(FRAME_RATE_NO_VOTE); | 
|  | 428 | commitTransaction(); | 
|  | 429 | EXPECT_EQ(FRAME_RATE_NO_VOTE, parent->getFrameRateForLayerTree()); | 
|  | 430 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child1->getFrameRateForLayerTree()); | 
|  | 431 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child2->getFrameRateForLayerTree()); | 
|  | 432 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child2_1->getFrameRateForLayerTree()); | 
|  | 433 | } | 
|  | 434 |  | 
|  | 435 | TEST_P(SetFrameRateTest, SetAndGetRearentChildren) { | 
|  | 436 | EXPECT_CALL(*mMessageQueue, invalidate()).Times(1); | 
|  | 437 |  | 
|  | 438 | const auto& layerFactory = GetParam(); | 
|  | 439 |  | 
|  | 440 | auto parent = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); | 
|  | 441 | auto parent2 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); | 
|  | 442 | auto child1 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); | 
|  | 443 | auto child2 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); | 
|  | 444 |  | 
|  | 445 | addChild(parent, child1); | 
|  | 446 | addChild(child1, child2); | 
|  | 447 |  | 
|  | 448 | child2->setFrameRate(FRAME_RATE_VOTE1); | 
|  | 449 | commitTransaction(); | 
|  | 450 | EXPECT_EQ(FRAME_RATE_TREE, parent->getFrameRateForLayerTree()); | 
|  | 451 | EXPECT_EQ(FRAME_RATE_NO_VOTE, parent2->getFrameRateForLayerTree()); | 
|  | 452 | EXPECT_EQ(FRAME_RATE_TREE, child1->getFrameRateForLayerTree()); | 
|  | 453 | EXPECT_EQ(FRAME_RATE_VOTE1, child2->getFrameRateForLayerTree()); | 
|  | 454 |  | 
|  | 455 | reparentChildren(parent, parent2); | 
|  | 456 | commitTransaction(); | 
|  | 457 | EXPECT_EQ(FRAME_RATE_NO_VOTE, parent->getFrameRateForLayerTree()); | 
|  | 458 | EXPECT_EQ(FRAME_RATE_TREE, parent2->getFrameRateForLayerTree()); | 
|  | 459 | EXPECT_EQ(FRAME_RATE_TREE, child1->getFrameRateForLayerTree()); | 
|  | 460 | EXPECT_EQ(FRAME_RATE_VOTE1, child2->getFrameRateForLayerTree()); | 
|  | 461 |  | 
|  | 462 | child2->setFrameRate(FRAME_RATE_NO_VOTE); | 
|  | 463 | commitTransaction(); | 
|  | 464 | EXPECT_EQ(FRAME_RATE_NO_VOTE, parent->getFrameRateForLayerTree()); | 
|  | 465 | EXPECT_EQ(FRAME_RATE_NO_VOTE, parent2->getFrameRateForLayerTree()); | 
|  | 466 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child1->getFrameRateForLayerTree()); | 
|  | 467 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child2->getFrameRateForLayerTree()); | 
|  | 468 | } | 
|  | 469 |  | 
|  | 470 | INSTANTIATE_TEST_SUITE_P(PerLayerType, SetFrameRateTest, | 
|  | 471 | testing::Values(std::make_shared<BufferQueueLayerFactory>(), | 
|  | 472 | std::make_shared<BufferStateLayerFactory>(), | 
|  | 473 | std::make_shared<EffectLayerFactory>()), | 
|  | 474 | PrintToStringParamName); | 
|  | 475 |  | 
|  | 476 | } // namespace | 
|  | 477 | } // namespace android |