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: |
| 111 | const FrameRate FRAME_RATE_VOTE1 = FrameRate(67.f, FrameRateCompatibility::Default); |
| 112 | const FrameRate FRAME_RATE_VOTE2 = FrameRate(14.f, FrameRateCompatibility::ExactOrMultiple); |
| 113 | const FrameRate FRAME_RATE_VOTE3 = FrameRate(99.f, FrameRateCompatibility::NoVote); |
| 114 | const FrameRate FRAME_RATE_TREE = FrameRate(0, FrameRateCompatibility::NoVote); |
| 115 | const FrameRate FRAME_RATE_NO_VOTE = FrameRate(0, FrameRateCompatibility::Default); |
| 116 | |
| 117 | SetFrameRateTest(); |
| 118 | |
| 119 | void setupScheduler(); |
| 120 | void setupComposer(uint32_t virtualDisplayCount); |
| 121 | |
| 122 | void addChild(sp<Layer> layer, sp<Layer> child); |
| 123 | void removeChild(sp<Layer> layer, sp<Layer> child); |
| 124 | void reparentChildren(sp<Layer> layer, sp<Layer> child); |
| 125 | void commitTransaction(); |
| 126 | |
| 127 | TestableSurfaceFlinger mFlinger; |
| 128 | Hwc2::mock::Composer* mComposer = nullptr; |
| 129 | mock::MessageQueue* mMessageQueue = new mock::MessageQueue(); |
| 130 | |
| 131 | std::vector<sp<Layer>> mLayers; |
| 132 | }; |
| 133 | |
| 134 | SetFrameRateTest::SetFrameRateTest() { |
| 135 | const ::testing::TestInfo* const test_info = |
| 136 | ::testing::UnitTest::GetInstance()->current_test_info(); |
| 137 | ALOGD("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name()); |
| 138 | |
| 139 | mFlinger.mutableUseFrameRateApi() = true; |
| 140 | |
| 141 | setupScheduler(); |
| 142 | setupComposer(0); |
| 143 | |
| 144 | mFlinger.mutableEventQueue().reset(mMessageQueue); |
| 145 | } |
| 146 | void SetFrameRateTest::addChild(sp<Layer> layer, sp<Layer> child) { |
| 147 | layer.get()->addChild(child.get()); |
| 148 | } |
| 149 | |
| 150 | void SetFrameRateTest::removeChild(sp<Layer> layer, sp<Layer> child) { |
| 151 | layer.get()->removeChild(child.get()); |
| 152 | } |
| 153 | |
| 154 | void SetFrameRateTest::reparentChildren(sp<Layer> parent, sp<Layer> newParent) { |
| 155 | parent.get()->reparentChildren(newParent); |
| 156 | } |
| 157 | |
| 158 | void SetFrameRateTest::commitTransaction() { |
| 159 | for (auto layer : mLayers) { |
Ady Abraham | 22c7b5c | 2020-09-22 19:33:40 -0700 | [diff] [blame] | 160 | layer->pushPendingState(); |
| 161 | auto c = layer->getCurrentState(); |
| 162 | if (layer->applyPendingStates(&c)) { |
| 163 | layer->commitTransaction(c); |
| 164 | } |
Ady Abraham | 60e42ea | 2020-03-09 19:17:31 -0700 | [diff] [blame] | 165 | } |
| 166 | } |
| 167 | |
| 168 | void SetFrameRateTest::setupScheduler() { |
| 169 | auto eventThread = std::make_unique<mock::EventThread>(); |
| 170 | auto sfEventThread = std::make_unique<mock::EventThread>(); |
| 171 | |
| 172 | EXPECT_CALL(*eventThread, registerDisplayEventConnection(_)); |
| 173 | EXPECT_CALL(*eventThread, createEventConnection(_, _)) |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame] | 174 | .WillOnce(Return(new EventThreadConnection(eventThread.get(), /*callingUid=*/0, |
Ady Abraham | 62f216c | 2020-10-13 19:07:23 -0700 | [diff] [blame^] | 175 | ResyncCallback()))); |
Ady Abraham | 60e42ea | 2020-03-09 19:17:31 -0700 | [diff] [blame] | 176 | |
| 177 | EXPECT_CALL(*sfEventThread, registerDisplayEventConnection(_)); |
| 178 | EXPECT_CALL(*sfEventThread, createEventConnection(_, _)) |
Ady Abraham | 0bb6a47 | 2020-10-12 10:22:13 -0700 | [diff] [blame] | 179 | .WillOnce(Return(new EventThreadConnection(sfEventThread.get(), /*callingUid=*/0, |
Ady Abraham | 62f216c | 2020-10-13 19:07:23 -0700 | [diff] [blame^] | 180 | ResyncCallback()))); |
Ady Abraham | 60e42ea | 2020-03-09 19:17:31 -0700 | [diff] [blame] | 181 | |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 182 | auto vsyncController = std::make_unique<mock::VsyncController>(); |
| 183 | auto vsyncTracker = std::make_unique<mock::VSyncTracker>(); |
Ady Abraham | 60e42ea | 2020-03-09 19:17:31 -0700 | [diff] [blame] | 184 | |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 185 | EXPECT_CALL(*vsyncTracker, nextAnticipatedVSyncTimeFrom(_)).WillRepeatedly(Return(0)); |
| 186 | EXPECT_CALL(*vsyncTracker, currentPeriod()) |
Ady Abraham | 60e42ea | 2020-03-09 19:17:31 -0700 | [diff] [blame] | 187 | .WillRepeatedly(Return(FakeHwcDisplayInjector::DEFAULT_REFRESH_RATE)); |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 188 | EXPECT_CALL(*vsyncTracker, nextAnticipatedVSyncTimeFrom(_)).WillRepeatedly(Return(0)); |
| 189 | mFlinger.setupScheduler(std::move(vsyncController), std::move(vsyncTracker), |
| 190 | std::move(eventThread), std::move(sfEventThread)); |
Ady Abraham | 60e42ea | 2020-03-09 19:17:31 -0700 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | void SetFrameRateTest::setupComposer(uint32_t virtualDisplayCount) { |
| 194 | mComposer = new Hwc2::mock::Composer(); |
| 195 | EXPECT_CALL(*mComposer, getMaxVirtualDisplayCount()).WillOnce(Return(virtualDisplayCount)); |
| 196 | mFlinger.setupComposer(std::unique_ptr<Hwc2::Composer>(mComposer)); |
| 197 | |
| 198 | Mock::VerifyAndClear(mComposer); |
| 199 | } |
| 200 | |
| 201 | namespace { |
| 202 | /* ------------------------------------------------------------------------ |
| 203 | * Test cases |
| 204 | */ |
| 205 | TEST_P(SetFrameRateTest, SetAndGet) { |
| 206 | EXPECT_CALL(*mMessageQueue, invalidate()).Times(1); |
| 207 | |
| 208 | const auto& layerFactory = GetParam(); |
| 209 | |
| 210 | auto layer = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); |
| 211 | layer->setFrameRate(FRAME_RATE_VOTE1); |
| 212 | commitTransaction(); |
| 213 | EXPECT_EQ(FRAME_RATE_VOTE1, layer->getFrameRateForLayerTree()); |
| 214 | } |
| 215 | |
| 216 | TEST_P(SetFrameRateTest, SetAndGetParent) { |
| 217 | EXPECT_CALL(*mMessageQueue, invalidate()).Times(1); |
| 218 | |
| 219 | const auto& layerFactory = GetParam(); |
| 220 | |
| 221 | auto parent = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); |
| 222 | auto child1 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); |
| 223 | auto child2 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); |
| 224 | |
| 225 | addChild(parent, child1); |
| 226 | addChild(child1, child2); |
| 227 | |
| 228 | child2->setFrameRate(FRAME_RATE_VOTE1); |
| 229 | commitTransaction(); |
| 230 | EXPECT_EQ(FRAME_RATE_TREE, parent->getFrameRateForLayerTree()); |
| 231 | EXPECT_EQ(FRAME_RATE_TREE, child1->getFrameRateForLayerTree()); |
| 232 | EXPECT_EQ(FRAME_RATE_VOTE1, child2->getFrameRateForLayerTree()); |
| 233 | |
| 234 | child2->setFrameRate(FRAME_RATE_NO_VOTE); |
| 235 | commitTransaction(); |
| 236 | EXPECT_EQ(FRAME_RATE_NO_VOTE, parent->getFrameRateForLayerTree()); |
| 237 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child1->getFrameRateForLayerTree()); |
| 238 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child2->getFrameRateForLayerTree()); |
| 239 | } |
| 240 | |
| 241 | TEST_P(SetFrameRateTest, SetAndGetParentAllVote) { |
| 242 | EXPECT_CALL(*mMessageQueue, invalidate()).Times(1); |
| 243 | |
| 244 | const auto& layerFactory = GetParam(); |
| 245 | |
| 246 | auto parent = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); |
| 247 | auto child1 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); |
| 248 | auto child2 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); |
| 249 | |
| 250 | addChild(parent, child1); |
| 251 | addChild(child1, child2); |
| 252 | |
| 253 | child2->setFrameRate(FRAME_RATE_VOTE1); |
| 254 | child1->setFrameRate(FRAME_RATE_VOTE2); |
| 255 | parent->setFrameRate(FRAME_RATE_VOTE3); |
| 256 | commitTransaction(); |
| 257 | EXPECT_EQ(FRAME_RATE_VOTE3, parent->getFrameRateForLayerTree()); |
| 258 | EXPECT_EQ(FRAME_RATE_VOTE2, child1->getFrameRateForLayerTree()); |
| 259 | EXPECT_EQ(FRAME_RATE_VOTE1, child2->getFrameRateForLayerTree()); |
| 260 | |
| 261 | child2->setFrameRate(FRAME_RATE_NO_VOTE); |
| 262 | commitTransaction(); |
| 263 | EXPECT_EQ(FRAME_RATE_VOTE3, parent->getFrameRateForLayerTree()); |
| 264 | EXPECT_EQ(FRAME_RATE_VOTE2, child1->getFrameRateForLayerTree()); |
| 265 | EXPECT_EQ(FRAME_RATE_TREE, child2->getFrameRateForLayerTree()); |
| 266 | |
| 267 | child1->setFrameRate(FRAME_RATE_NO_VOTE); |
| 268 | commitTransaction(); |
| 269 | EXPECT_EQ(FRAME_RATE_VOTE3, parent->getFrameRateForLayerTree()); |
| 270 | EXPECT_EQ(FRAME_RATE_TREE, child1->getFrameRateForLayerTree()); |
| 271 | EXPECT_EQ(FRAME_RATE_TREE, child2->getFrameRateForLayerTree()); |
| 272 | |
| 273 | parent->setFrameRate(FRAME_RATE_NO_VOTE); |
| 274 | commitTransaction(); |
| 275 | EXPECT_EQ(FRAME_RATE_NO_VOTE, parent->getFrameRateForLayerTree()); |
| 276 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child1->getFrameRateForLayerTree()); |
| 277 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child2->getFrameRateForLayerTree()); |
| 278 | } |
| 279 | |
| 280 | TEST_P(SetFrameRateTest, SetAndGetChild) { |
| 281 | EXPECT_CALL(*mMessageQueue, invalidate()).Times(1); |
| 282 | |
| 283 | const auto& layerFactory = GetParam(); |
| 284 | |
| 285 | auto parent = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); |
| 286 | auto child1 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); |
| 287 | auto child2 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); |
| 288 | |
| 289 | addChild(parent, child1); |
| 290 | addChild(child1, child2); |
| 291 | |
| 292 | parent->setFrameRate(FRAME_RATE_VOTE1); |
| 293 | commitTransaction(); |
| 294 | EXPECT_EQ(FRAME_RATE_VOTE1, parent->getFrameRateForLayerTree()); |
| 295 | EXPECT_EQ(FRAME_RATE_TREE, child1->getFrameRateForLayerTree()); |
| 296 | EXPECT_EQ(FRAME_RATE_TREE, child2->getFrameRateForLayerTree()); |
| 297 | |
| 298 | parent->setFrameRate(FRAME_RATE_NO_VOTE); |
| 299 | commitTransaction(); |
| 300 | EXPECT_EQ(FRAME_RATE_NO_VOTE, parent->getFrameRateForLayerTree()); |
| 301 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child1->getFrameRateForLayerTree()); |
| 302 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child2->getFrameRateForLayerTree()); |
| 303 | } |
| 304 | |
| 305 | TEST_P(SetFrameRateTest, SetAndGetChildAllVote) { |
| 306 | EXPECT_CALL(*mMessageQueue, invalidate()).Times(1); |
| 307 | |
| 308 | const auto& layerFactory = GetParam(); |
| 309 | |
| 310 | auto parent = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); |
| 311 | auto child1 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); |
| 312 | auto child2 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); |
| 313 | |
| 314 | addChild(parent, child1); |
| 315 | addChild(child1, child2); |
| 316 | |
| 317 | child2->setFrameRate(FRAME_RATE_VOTE1); |
| 318 | child1->setFrameRate(FRAME_RATE_VOTE2); |
| 319 | parent->setFrameRate(FRAME_RATE_VOTE3); |
| 320 | commitTransaction(); |
| 321 | EXPECT_EQ(FRAME_RATE_VOTE3, parent->getFrameRateForLayerTree()); |
| 322 | EXPECT_EQ(FRAME_RATE_VOTE2, child1->getFrameRateForLayerTree()); |
| 323 | EXPECT_EQ(FRAME_RATE_VOTE1, child2->getFrameRateForLayerTree()); |
| 324 | |
| 325 | parent->setFrameRate(FRAME_RATE_NO_VOTE); |
| 326 | commitTransaction(); |
| 327 | EXPECT_EQ(FRAME_RATE_TREE, parent->getFrameRateForLayerTree()); |
| 328 | EXPECT_EQ(FRAME_RATE_VOTE2, child1->getFrameRateForLayerTree()); |
| 329 | EXPECT_EQ(FRAME_RATE_VOTE1, child2->getFrameRateForLayerTree()); |
| 330 | |
| 331 | child1->setFrameRate(FRAME_RATE_NO_VOTE); |
| 332 | commitTransaction(); |
| 333 | EXPECT_EQ(FRAME_RATE_TREE, parent->getFrameRateForLayerTree()); |
| 334 | EXPECT_EQ(FRAME_RATE_TREE, child1->getFrameRateForLayerTree()); |
| 335 | EXPECT_EQ(FRAME_RATE_VOTE1, child2->getFrameRateForLayerTree()); |
| 336 | |
| 337 | child2->setFrameRate(FRAME_RATE_NO_VOTE); |
| 338 | commitTransaction(); |
| 339 | EXPECT_EQ(FRAME_RATE_NO_VOTE, parent->getFrameRateForLayerTree()); |
| 340 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child1->getFrameRateForLayerTree()); |
| 341 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child2->getFrameRateForLayerTree()); |
| 342 | } |
| 343 | |
| 344 | TEST_P(SetFrameRateTest, SetAndGetChildAddAfterVote) { |
| 345 | EXPECT_CALL(*mMessageQueue, invalidate()).Times(1); |
| 346 | |
| 347 | const auto& layerFactory = GetParam(); |
| 348 | |
| 349 | auto parent = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); |
| 350 | auto child1 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); |
| 351 | auto child2 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); |
| 352 | |
| 353 | addChild(parent, child1); |
| 354 | |
| 355 | parent->setFrameRate(FRAME_RATE_VOTE1); |
| 356 | commitTransaction(); |
| 357 | EXPECT_EQ(FRAME_RATE_VOTE1, parent->getFrameRateForLayerTree()); |
| 358 | EXPECT_EQ(FRAME_RATE_TREE, child1->getFrameRateForLayerTree()); |
| 359 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child2->getFrameRateForLayerTree()); |
| 360 | |
| 361 | addChild(child1, child2); |
| 362 | commitTransaction(); |
| 363 | EXPECT_EQ(FRAME_RATE_VOTE1, parent->getFrameRateForLayerTree()); |
| 364 | EXPECT_EQ(FRAME_RATE_TREE, child1->getFrameRateForLayerTree()); |
| 365 | EXPECT_EQ(FRAME_RATE_TREE, child2->getFrameRateForLayerTree()); |
| 366 | |
| 367 | parent->setFrameRate(FRAME_RATE_NO_VOTE); |
| 368 | commitTransaction(); |
| 369 | EXPECT_EQ(FRAME_RATE_NO_VOTE, parent->getFrameRateForLayerTree()); |
| 370 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child1->getFrameRateForLayerTree()); |
| 371 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child2->getFrameRateForLayerTree()); |
| 372 | } |
| 373 | |
| 374 | TEST_P(SetFrameRateTest, SetAndGetChildRemoveAfterVote) { |
| 375 | EXPECT_CALL(*mMessageQueue, invalidate()).Times(1); |
| 376 | |
| 377 | const auto& layerFactory = GetParam(); |
| 378 | |
| 379 | auto parent = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); |
| 380 | auto child1 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); |
| 381 | auto child2 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); |
| 382 | |
| 383 | addChild(parent, child1); |
| 384 | addChild(child1, child2); |
| 385 | |
| 386 | parent->setFrameRate(FRAME_RATE_VOTE1); |
| 387 | commitTransaction(); |
| 388 | EXPECT_EQ(FRAME_RATE_VOTE1, parent->getFrameRateForLayerTree()); |
| 389 | EXPECT_EQ(FRAME_RATE_TREE, child1->getFrameRateForLayerTree()); |
| 390 | EXPECT_EQ(FRAME_RATE_TREE, child2->getFrameRateForLayerTree()); |
| 391 | |
| 392 | removeChild(child1, child2); |
| 393 | commitTransaction(); |
| 394 | EXPECT_EQ(FRAME_RATE_VOTE1, parent->getFrameRateForLayerTree()); |
| 395 | EXPECT_EQ(FRAME_RATE_TREE, child1->getFrameRateForLayerTree()); |
| 396 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child2->getFrameRateForLayerTree()); |
| 397 | |
| 398 | parent->setFrameRate(FRAME_RATE_NO_VOTE); |
| 399 | commitTransaction(); |
| 400 | EXPECT_EQ(FRAME_RATE_NO_VOTE, parent->getFrameRateForLayerTree()); |
| 401 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child1->getFrameRateForLayerTree()); |
| 402 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child2->getFrameRateForLayerTree()); |
| 403 | } |
| 404 | |
| 405 | TEST_P(SetFrameRateTest, SetAndGetParentNotInTree) { |
| 406 | EXPECT_CALL(*mMessageQueue, invalidate()).Times(1); |
| 407 | |
| 408 | const auto& layerFactory = GetParam(); |
| 409 | |
| 410 | auto parent = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); |
| 411 | auto child1 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); |
| 412 | auto child2 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); |
| 413 | auto child2_1 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); |
| 414 | |
| 415 | addChild(parent, child1); |
| 416 | addChild(child1, child2); |
| 417 | addChild(child1, child2_1); |
| 418 | |
| 419 | child2->setFrameRate(FRAME_RATE_VOTE1); |
| 420 | commitTransaction(); |
| 421 | EXPECT_EQ(FRAME_RATE_TREE, parent->getFrameRateForLayerTree()); |
| 422 | EXPECT_EQ(FRAME_RATE_TREE, child1->getFrameRateForLayerTree()); |
| 423 | EXPECT_EQ(FRAME_RATE_VOTE1, child2->getFrameRateForLayerTree()); |
| 424 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child2_1->getFrameRateForLayerTree()); |
| 425 | |
| 426 | child2->setFrameRate(FRAME_RATE_NO_VOTE); |
| 427 | commitTransaction(); |
| 428 | EXPECT_EQ(FRAME_RATE_NO_VOTE, parent->getFrameRateForLayerTree()); |
| 429 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child1->getFrameRateForLayerTree()); |
| 430 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child2->getFrameRateForLayerTree()); |
| 431 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child2_1->getFrameRateForLayerTree()); |
| 432 | } |
| 433 | |
| 434 | TEST_P(SetFrameRateTest, SetAndGetRearentChildren) { |
| 435 | EXPECT_CALL(*mMessageQueue, invalidate()).Times(1); |
| 436 | |
| 437 | const auto& layerFactory = GetParam(); |
| 438 | |
| 439 | auto parent = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); |
| 440 | auto parent2 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); |
| 441 | auto child1 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); |
| 442 | auto child2 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); |
| 443 | |
| 444 | addChild(parent, child1); |
| 445 | addChild(child1, child2); |
| 446 | |
| 447 | child2->setFrameRate(FRAME_RATE_VOTE1); |
| 448 | commitTransaction(); |
| 449 | EXPECT_EQ(FRAME_RATE_TREE, parent->getFrameRateForLayerTree()); |
| 450 | EXPECT_EQ(FRAME_RATE_NO_VOTE, parent2->getFrameRateForLayerTree()); |
| 451 | EXPECT_EQ(FRAME_RATE_TREE, child1->getFrameRateForLayerTree()); |
| 452 | EXPECT_EQ(FRAME_RATE_VOTE1, child2->getFrameRateForLayerTree()); |
| 453 | |
| 454 | reparentChildren(parent, parent2); |
| 455 | commitTransaction(); |
| 456 | EXPECT_EQ(FRAME_RATE_NO_VOTE, parent->getFrameRateForLayerTree()); |
| 457 | EXPECT_EQ(FRAME_RATE_TREE, parent2->getFrameRateForLayerTree()); |
| 458 | EXPECT_EQ(FRAME_RATE_TREE, child1->getFrameRateForLayerTree()); |
| 459 | EXPECT_EQ(FRAME_RATE_VOTE1, child2->getFrameRateForLayerTree()); |
| 460 | |
| 461 | child2->setFrameRate(FRAME_RATE_NO_VOTE); |
| 462 | commitTransaction(); |
| 463 | EXPECT_EQ(FRAME_RATE_NO_VOTE, parent->getFrameRateForLayerTree()); |
| 464 | EXPECT_EQ(FRAME_RATE_NO_VOTE, parent2->getFrameRateForLayerTree()); |
| 465 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child1->getFrameRateForLayerTree()); |
| 466 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child2->getFrameRateForLayerTree()); |
| 467 | } |
| 468 | |
| 469 | INSTANTIATE_TEST_SUITE_P(PerLayerType, SetFrameRateTest, |
| 470 | testing::Values(std::make_shared<BufferQueueLayerFactory>(), |
| 471 | std::make_shared<BufferStateLayerFactory>(), |
| 472 | std::make_shared<EffectLayerFactory>()), |
| 473 | PrintToStringParamName); |
| 474 | |
| 475 | } // namespace |
| 476 | } // namespace android |