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, |
| 175 | ResyncCallback(), |
Ady Abraham | 60e42ea | 2020-03-09 19:17:31 -0700 | [diff] [blame] | 176 | ISurfaceComposer::eConfigChangedSuppress))); |
| 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, |
| 181 | ResyncCallback(), |
Ady Abraham | 60e42ea | 2020-03-09 19:17:31 -0700 | [diff] [blame] | 182 | ISurfaceComposer::eConfigChangedSuppress))); |
| 183 | |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 184 | auto vsyncController = std::make_unique<mock::VsyncController>(); |
| 185 | auto vsyncTracker = std::make_unique<mock::VSyncTracker>(); |
Ady Abraham | 60e42ea | 2020-03-09 19:17:31 -0700 | [diff] [blame] | 186 | |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 187 | EXPECT_CALL(*vsyncTracker, nextAnticipatedVSyncTimeFrom(_)).WillRepeatedly(Return(0)); |
| 188 | EXPECT_CALL(*vsyncTracker, currentPeriod()) |
Ady Abraham | 60e42ea | 2020-03-09 19:17:31 -0700 | [diff] [blame] | 189 | .WillRepeatedly(Return(FakeHwcDisplayInjector::DEFAULT_REFRESH_RATE)); |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 190 | EXPECT_CALL(*vsyncTracker, nextAnticipatedVSyncTimeFrom(_)).WillRepeatedly(Return(0)); |
| 191 | mFlinger.setupScheduler(std::move(vsyncController), std::move(vsyncTracker), |
| 192 | std::move(eventThread), std::move(sfEventThread)); |
Ady Abraham | 60e42ea | 2020-03-09 19:17:31 -0700 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | void SetFrameRateTest::setupComposer(uint32_t virtualDisplayCount) { |
| 196 | mComposer = new Hwc2::mock::Composer(); |
| 197 | EXPECT_CALL(*mComposer, getMaxVirtualDisplayCount()).WillOnce(Return(virtualDisplayCount)); |
| 198 | mFlinger.setupComposer(std::unique_ptr<Hwc2::Composer>(mComposer)); |
| 199 | |
| 200 | Mock::VerifyAndClear(mComposer); |
| 201 | } |
| 202 | |
| 203 | namespace { |
| 204 | /* ------------------------------------------------------------------------ |
| 205 | * Test cases |
| 206 | */ |
| 207 | TEST_P(SetFrameRateTest, SetAndGet) { |
| 208 | EXPECT_CALL(*mMessageQueue, invalidate()).Times(1); |
| 209 | |
| 210 | const auto& layerFactory = GetParam(); |
| 211 | |
| 212 | auto layer = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); |
| 213 | layer->setFrameRate(FRAME_RATE_VOTE1); |
| 214 | commitTransaction(); |
| 215 | EXPECT_EQ(FRAME_RATE_VOTE1, layer->getFrameRateForLayerTree()); |
| 216 | } |
| 217 | |
| 218 | TEST_P(SetFrameRateTest, SetAndGetParent) { |
| 219 | EXPECT_CALL(*mMessageQueue, invalidate()).Times(1); |
| 220 | |
| 221 | const auto& layerFactory = GetParam(); |
| 222 | |
| 223 | auto parent = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); |
| 224 | auto child1 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); |
| 225 | auto child2 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); |
| 226 | |
| 227 | addChild(parent, child1); |
| 228 | addChild(child1, child2); |
| 229 | |
| 230 | child2->setFrameRate(FRAME_RATE_VOTE1); |
| 231 | commitTransaction(); |
| 232 | EXPECT_EQ(FRAME_RATE_TREE, parent->getFrameRateForLayerTree()); |
| 233 | EXPECT_EQ(FRAME_RATE_TREE, child1->getFrameRateForLayerTree()); |
| 234 | EXPECT_EQ(FRAME_RATE_VOTE1, child2->getFrameRateForLayerTree()); |
| 235 | |
| 236 | child2->setFrameRate(FRAME_RATE_NO_VOTE); |
| 237 | commitTransaction(); |
| 238 | EXPECT_EQ(FRAME_RATE_NO_VOTE, parent->getFrameRateForLayerTree()); |
| 239 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child1->getFrameRateForLayerTree()); |
| 240 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child2->getFrameRateForLayerTree()); |
| 241 | } |
| 242 | |
| 243 | TEST_P(SetFrameRateTest, SetAndGetParentAllVote) { |
| 244 | EXPECT_CALL(*mMessageQueue, invalidate()).Times(1); |
| 245 | |
| 246 | const auto& layerFactory = GetParam(); |
| 247 | |
| 248 | auto parent = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); |
| 249 | auto child1 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); |
| 250 | auto child2 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); |
| 251 | |
| 252 | addChild(parent, child1); |
| 253 | addChild(child1, child2); |
| 254 | |
| 255 | child2->setFrameRate(FRAME_RATE_VOTE1); |
| 256 | child1->setFrameRate(FRAME_RATE_VOTE2); |
| 257 | parent->setFrameRate(FRAME_RATE_VOTE3); |
| 258 | commitTransaction(); |
| 259 | EXPECT_EQ(FRAME_RATE_VOTE3, parent->getFrameRateForLayerTree()); |
| 260 | EXPECT_EQ(FRAME_RATE_VOTE2, child1->getFrameRateForLayerTree()); |
| 261 | EXPECT_EQ(FRAME_RATE_VOTE1, child2->getFrameRateForLayerTree()); |
| 262 | |
| 263 | child2->setFrameRate(FRAME_RATE_NO_VOTE); |
| 264 | commitTransaction(); |
| 265 | EXPECT_EQ(FRAME_RATE_VOTE3, parent->getFrameRateForLayerTree()); |
| 266 | EXPECT_EQ(FRAME_RATE_VOTE2, child1->getFrameRateForLayerTree()); |
| 267 | EXPECT_EQ(FRAME_RATE_TREE, child2->getFrameRateForLayerTree()); |
| 268 | |
| 269 | child1->setFrameRate(FRAME_RATE_NO_VOTE); |
| 270 | commitTransaction(); |
| 271 | EXPECT_EQ(FRAME_RATE_VOTE3, parent->getFrameRateForLayerTree()); |
| 272 | EXPECT_EQ(FRAME_RATE_TREE, child1->getFrameRateForLayerTree()); |
| 273 | EXPECT_EQ(FRAME_RATE_TREE, child2->getFrameRateForLayerTree()); |
| 274 | |
| 275 | parent->setFrameRate(FRAME_RATE_NO_VOTE); |
| 276 | commitTransaction(); |
| 277 | EXPECT_EQ(FRAME_RATE_NO_VOTE, parent->getFrameRateForLayerTree()); |
| 278 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child1->getFrameRateForLayerTree()); |
| 279 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child2->getFrameRateForLayerTree()); |
| 280 | } |
| 281 | |
| 282 | TEST_P(SetFrameRateTest, SetAndGetChild) { |
| 283 | EXPECT_CALL(*mMessageQueue, invalidate()).Times(1); |
| 284 | |
| 285 | const auto& layerFactory = GetParam(); |
| 286 | |
| 287 | auto parent = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); |
| 288 | auto child1 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); |
| 289 | auto child2 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); |
| 290 | |
| 291 | addChild(parent, child1); |
| 292 | addChild(child1, child2); |
| 293 | |
| 294 | parent->setFrameRate(FRAME_RATE_VOTE1); |
| 295 | commitTransaction(); |
| 296 | EXPECT_EQ(FRAME_RATE_VOTE1, parent->getFrameRateForLayerTree()); |
| 297 | EXPECT_EQ(FRAME_RATE_TREE, child1->getFrameRateForLayerTree()); |
| 298 | EXPECT_EQ(FRAME_RATE_TREE, child2->getFrameRateForLayerTree()); |
| 299 | |
| 300 | parent->setFrameRate(FRAME_RATE_NO_VOTE); |
| 301 | commitTransaction(); |
| 302 | EXPECT_EQ(FRAME_RATE_NO_VOTE, parent->getFrameRateForLayerTree()); |
| 303 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child1->getFrameRateForLayerTree()); |
| 304 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child2->getFrameRateForLayerTree()); |
| 305 | } |
| 306 | |
| 307 | TEST_P(SetFrameRateTest, SetAndGetChildAllVote) { |
| 308 | EXPECT_CALL(*mMessageQueue, invalidate()).Times(1); |
| 309 | |
| 310 | const auto& layerFactory = GetParam(); |
| 311 | |
| 312 | auto parent = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); |
| 313 | auto child1 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); |
| 314 | auto child2 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); |
| 315 | |
| 316 | addChild(parent, child1); |
| 317 | addChild(child1, child2); |
| 318 | |
| 319 | child2->setFrameRate(FRAME_RATE_VOTE1); |
| 320 | child1->setFrameRate(FRAME_RATE_VOTE2); |
| 321 | parent->setFrameRate(FRAME_RATE_VOTE3); |
| 322 | commitTransaction(); |
| 323 | EXPECT_EQ(FRAME_RATE_VOTE3, parent->getFrameRateForLayerTree()); |
| 324 | EXPECT_EQ(FRAME_RATE_VOTE2, child1->getFrameRateForLayerTree()); |
| 325 | EXPECT_EQ(FRAME_RATE_VOTE1, child2->getFrameRateForLayerTree()); |
| 326 | |
| 327 | parent->setFrameRate(FRAME_RATE_NO_VOTE); |
| 328 | commitTransaction(); |
| 329 | EXPECT_EQ(FRAME_RATE_TREE, parent->getFrameRateForLayerTree()); |
| 330 | EXPECT_EQ(FRAME_RATE_VOTE2, child1->getFrameRateForLayerTree()); |
| 331 | EXPECT_EQ(FRAME_RATE_VOTE1, child2->getFrameRateForLayerTree()); |
| 332 | |
| 333 | child1->setFrameRate(FRAME_RATE_NO_VOTE); |
| 334 | commitTransaction(); |
| 335 | EXPECT_EQ(FRAME_RATE_TREE, parent->getFrameRateForLayerTree()); |
| 336 | EXPECT_EQ(FRAME_RATE_TREE, child1->getFrameRateForLayerTree()); |
| 337 | EXPECT_EQ(FRAME_RATE_VOTE1, child2->getFrameRateForLayerTree()); |
| 338 | |
| 339 | child2->setFrameRate(FRAME_RATE_NO_VOTE); |
| 340 | commitTransaction(); |
| 341 | EXPECT_EQ(FRAME_RATE_NO_VOTE, parent->getFrameRateForLayerTree()); |
| 342 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child1->getFrameRateForLayerTree()); |
| 343 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child2->getFrameRateForLayerTree()); |
| 344 | } |
| 345 | |
| 346 | TEST_P(SetFrameRateTest, SetAndGetChildAddAfterVote) { |
| 347 | EXPECT_CALL(*mMessageQueue, invalidate()).Times(1); |
| 348 | |
| 349 | const auto& layerFactory = GetParam(); |
| 350 | |
| 351 | auto parent = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); |
| 352 | auto child1 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); |
| 353 | auto child2 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); |
| 354 | |
| 355 | addChild(parent, child1); |
| 356 | |
| 357 | parent->setFrameRate(FRAME_RATE_VOTE1); |
| 358 | commitTransaction(); |
| 359 | EXPECT_EQ(FRAME_RATE_VOTE1, parent->getFrameRateForLayerTree()); |
| 360 | EXPECT_EQ(FRAME_RATE_TREE, child1->getFrameRateForLayerTree()); |
| 361 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child2->getFrameRateForLayerTree()); |
| 362 | |
| 363 | addChild(child1, child2); |
| 364 | commitTransaction(); |
| 365 | EXPECT_EQ(FRAME_RATE_VOTE1, parent->getFrameRateForLayerTree()); |
| 366 | EXPECT_EQ(FRAME_RATE_TREE, child1->getFrameRateForLayerTree()); |
| 367 | EXPECT_EQ(FRAME_RATE_TREE, child2->getFrameRateForLayerTree()); |
| 368 | |
| 369 | parent->setFrameRate(FRAME_RATE_NO_VOTE); |
| 370 | commitTransaction(); |
| 371 | EXPECT_EQ(FRAME_RATE_NO_VOTE, parent->getFrameRateForLayerTree()); |
| 372 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child1->getFrameRateForLayerTree()); |
| 373 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child2->getFrameRateForLayerTree()); |
| 374 | } |
| 375 | |
| 376 | TEST_P(SetFrameRateTest, SetAndGetChildRemoveAfterVote) { |
| 377 | EXPECT_CALL(*mMessageQueue, invalidate()).Times(1); |
| 378 | |
| 379 | const auto& layerFactory = GetParam(); |
| 380 | |
| 381 | auto parent = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); |
| 382 | auto child1 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); |
| 383 | auto child2 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); |
| 384 | |
| 385 | addChild(parent, child1); |
| 386 | addChild(child1, child2); |
| 387 | |
| 388 | parent->setFrameRate(FRAME_RATE_VOTE1); |
| 389 | commitTransaction(); |
| 390 | EXPECT_EQ(FRAME_RATE_VOTE1, parent->getFrameRateForLayerTree()); |
| 391 | EXPECT_EQ(FRAME_RATE_TREE, child1->getFrameRateForLayerTree()); |
| 392 | EXPECT_EQ(FRAME_RATE_TREE, child2->getFrameRateForLayerTree()); |
| 393 | |
| 394 | removeChild(child1, child2); |
| 395 | commitTransaction(); |
| 396 | EXPECT_EQ(FRAME_RATE_VOTE1, parent->getFrameRateForLayerTree()); |
| 397 | EXPECT_EQ(FRAME_RATE_TREE, child1->getFrameRateForLayerTree()); |
| 398 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child2->getFrameRateForLayerTree()); |
| 399 | |
| 400 | parent->setFrameRate(FRAME_RATE_NO_VOTE); |
| 401 | commitTransaction(); |
| 402 | EXPECT_EQ(FRAME_RATE_NO_VOTE, parent->getFrameRateForLayerTree()); |
| 403 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child1->getFrameRateForLayerTree()); |
| 404 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child2->getFrameRateForLayerTree()); |
| 405 | } |
| 406 | |
| 407 | TEST_P(SetFrameRateTest, SetAndGetParentNotInTree) { |
| 408 | EXPECT_CALL(*mMessageQueue, invalidate()).Times(1); |
| 409 | |
| 410 | const auto& layerFactory = GetParam(); |
| 411 | |
| 412 | auto parent = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); |
| 413 | auto child1 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); |
| 414 | auto child2 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); |
| 415 | auto child2_1 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); |
| 416 | |
| 417 | addChild(parent, child1); |
| 418 | addChild(child1, child2); |
| 419 | addChild(child1, child2_1); |
| 420 | |
| 421 | child2->setFrameRate(FRAME_RATE_VOTE1); |
| 422 | commitTransaction(); |
| 423 | EXPECT_EQ(FRAME_RATE_TREE, parent->getFrameRateForLayerTree()); |
| 424 | EXPECT_EQ(FRAME_RATE_TREE, child1->getFrameRateForLayerTree()); |
| 425 | EXPECT_EQ(FRAME_RATE_VOTE1, child2->getFrameRateForLayerTree()); |
| 426 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child2_1->getFrameRateForLayerTree()); |
| 427 | |
| 428 | child2->setFrameRate(FRAME_RATE_NO_VOTE); |
| 429 | commitTransaction(); |
| 430 | EXPECT_EQ(FRAME_RATE_NO_VOTE, parent->getFrameRateForLayerTree()); |
| 431 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child1->getFrameRateForLayerTree()); |
| 432 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child2->getFrameRateForLayerTree()); |
| 433 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child2_1->getFrameRateForLayerTree()); |
| 434 | } |
| 435 | |
| 436 | TEST_P(SetFrameRateTest, SetAndGetRearentChildren) { |
| 437 | EXPECT_CALL(*mMessageQueue, invalidate()).Times(1); |
| 438 | |
| 439 | const auto& layerFactory = GetParam(); |
| 440 | |
| 441 | auto parent = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); |
| 442 | auto parent2 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); |
| 443 | auto child1 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); |
| 444 | auto child2 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); |
| 445 | |
| 446 | addChild(parent, child1); |
| 447 | addChild(child1, child2); |
| 448 | |
| 449 | child2->setFrameRate(FRAME_RATE_VOTE1); |
| 450 | commitTransaction(); |
| 451 | EXPECT_EQ(FRAME_RATE_TREE, parent->getFrameRateForLayerTree()); |
| 452 | EXPECT_EQ(FRAME_RATE_NO_VOTE, parent2->getFrameRateForLayerTree()); |
| 453 | EXPECT_EQ(FRAME_RATE_TREE, child1->getFrameRateForLayerTree()); |
| 454 | EXPECT_EQ(FRAME_RATE_VOTE1, child2->getFrameRateForLayerTree()); |
| 455 | |
| 456 | reparentChildren(parent, parent2); |
| 457 | commitTransaction(); |
| 458 | EXPECT_EQ(FRAME_RATE_NO_VOTE, parent->getFrameRateForLayerTree()); |
| 459 | EXPECT_EQ(FRAME_RATE_TREE, parent2->getFrameRateForLayerTree()); |
| 460 | EXPECT_EQ(FRAME_RATE_TREE, child1->getFrameRateForLayerTree()); |
| 461 | EXPECT_EQ(FRAME_RATE_VOTE1, child2->getFrameRateForLayerTree()); |
| 462 | |
| 463 | child2->setFrameRate(FRAME_RATE_NO_VOTE); |
| 464 | commitTransaction(); |
| 465 | EXPECT_EQ(FRAME_RATE_NO_VOTE, parent->getFrameRateForLayerTree()); |
| 466 | EXPECT_EQ(FRAME_RATE_NO_VOTE, parent2->getFrameRateForLayerTree()); |
| 467 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child1->getFrameRateForLayerTree()); |
| 468 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child2->getFrameRateForLayerTree()); |
| 469 | } |
| 470 | |
| 471 | INSTANTIATE_TEST_SUITE_P(PerLayerType, SetFrameRateTest, |
| 472 | testing::Values(std::make_shared<BufferQueueLayerFactory>(), |
| 473 | std::make_shared<BufferStateLayerFactory>(), |
| 474 | std::make_shared<EffectLayerFactory>()), |
| 475 | PrintToStringParamName); |
| 476 | |
| 477 | } // namespace |
| 478 | } // namespace android |