| 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" | 
|  | 35 | #include "mock/MockDispSync.h" | 
|  | 36 | #include "mock/MockEventControlThread.h" | 
|  | 37 | #include "mock/MockEventThread.h" | 
|  | 38 | #include "mock/MockMessageQueue.h" | 
|  | 39 |  | 
|  | 40 | namespace android { | 
|  | 41 |  | 
|  | 42 | using testing::_; | 
|  | 43 | using testing::DoAll; | 
|  | 44 | using testing::Mock; | 
|  | 45 | using testing::Return; | 
|  | 46 | using testing::SetArgPointee; | 
|  | 47 |  | 
|  | 48 | using android::Hwc2::IComposer; | 
|  | 49 | using android::Hwc2::IComposerClient; | 
|  | 50 |  | 
|  | 51 | using FakeHwcDisplayInjector = TestableSurfaceFlinger::FakeHwcDisplayInjector; | 
|  | 52 |  | 
|  | 53 | using FrameRate = Layer::FrameRate; | 
|  | 54 | using FrameRateCompatibility = Layer::FrameRateCompatibility; | 
|  | 55 |  | 
|  | 56 | class LayerFactory { | 
|  | 57 | public: | 
|  | 58 | virtual ~LayerFactory() = default; | 
|  | 59 |  | 
|  | 60 | virtual std::string name() = 0; | 
|  | 61 | virtual sp<Layer> createLayer(TestableSurfaceFlinger& flinger) = 0; | 
|  | 62 |  | 
|  | 63 | protected: | 
|  | 64 | static constexpr uint32_t WIDTH = 100; | 
|  | 65 | static constexpr uint32_t HEIGHT = 100; | 
|  | 66 | static constexpr uint32_t LAYER_FLAGS = 0; | 
|  | 67 | }; | 
|  | 68 |  | 
|  | 69 | class BufferQueueLayerFactory : public LayerFactory { | 
|  | 70 | public: | 
|  | 71 | std::string name() override { return "BufferQueueLayer"; } | 
|  | 72 | sp<Layer> createLayer(TestableSurfaceFlinger& flinger) override { | 
|  | 73 | sp<Client> client; | 
|  | 74 | LayerCreationArgs args(flinger.flinger(), client, "buffer-queue-layer", WIDTH, HEIGHT, | 
|  | 75 | LAYER_FLAGS, LayerMetadata()); | 
|  | 76 | return new BufferQueueLayer(args); | 
|  | 77 | } | 
|  | 78 | }; | 
|  | 79 |  | 
|  | 80 | class BufferStateLayerFactory : public LayerFactory { | 
|  | 81 | public: | 
|  | 82 | std::string name() override { return "BufferStateLayer"; } | 
|  | 83 | sp<Layer> createLayer(TestableSurfaceFlinger& flinger) override { | 
|  | 84 | sp<Client> client; | 
|  | 85 | LayerCreationArgs args(flinger.flinger(), client, "buffer-queue-layer", WIDTH, HEIGHT, | 
|  | 86 | LAYER_FLAGS, LayerMetadata()); | 
|  | 87 | return new BufferStateLayer(args); | 
|  | 88 | } | 
|  | 89 | }; | 
|  | 90 |  | 
|  | 91 | class EffectLayerFactory : public LayerFactory { | 
|  | 92 | public: | 
|  | 93 | std::string name() override { return "EffectLayer"; } | 
|  | 94 | sp<Layer> createLayer(TestableSurfaceFlinger& flinger) override { | 
|  | 95 | sp<Client> client; | 
|  | 96 | LayerCreationArgs args(flinger.flinger(), client, "color-layer", WIDTH, HEIGHT, LAYER_FLAGS, | 
|  | 97 | LayerMetadata()); | 
|  | 98 | return new EffectLayer(args); | 
|  | 99 | } | 
|  | 100 | }; | 
|  | 101 |  | 
|  | 102 | std::string PrintToStringParamName( | 
|  | 103 | const ::testing::TestParamInfo<std::shared_ptr<LayerFactory>>& info) { | 
|  | 104 | return info.param->name(); | 
|  | 105 | } | 
|  | 106 |  | 
|  | 107 | /** | 
|  | 108 | * This class tests the behaviour of Layer::SetFrameRate and Layer::GetFrameRate | 
|  | 109 | */ | 
|  | 110 | class SetFrameRateTest : public ::testing::TestWithParam<std::shared_ptr<LayerFactory>> { | 
|  | 111 | protected: | 
|  | 112 | const FrameRate FRAME_RATE_VOTE1 = FrameRate(67.f, FrameRateCompatibility::Default); | 
|  | 113 | const FrameRate FRAME_RATE_VOTE2 = FrameRate(14.f, FrameRateCompatibility::ExactOrMultiple); | 
|  | 114 | const FrameRate FRAME_RATE_VOTE3 = FrameRate(99.f, FrameRateCompatibility::NoVote); | 
|  | 115 | const FrameRate FRAME_RATE_TREE = FrameRate(0, FrameRateCompatibility::NoVote); | 
|  | 116 | const FrameRate FRAME_RATE_NO_VOTE = FrameRate(0, FrameRateCompatibility::Default); | 
|  | 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) { | 
|  | 161 | layer.get()->commitTransaction(layer.get()->getCurrentState()); | 
|  | 162 | } | 
|  | 163 | } | 
|  | 164 |  | 
|  | 165 | void SetFrameRateTest::setupScheduler() { | 
|  | 166 | auto eventThread = std::make_unique<mock::EventThread>(); | 
|  | 167 | auto sfEventThread = std::make_unique<mock::EventThread>(); | 
|  | 168 |  | 
|  | 169 | EXPECT_CALL(*eventThread, registerDisplayEventConnection(_)); | 
|  | 170 | EXPECT_CALL(*eventThread, createEventConnection(_, _)) | 
|  | 171 | .WillOnce(Return(new EventThreadConnection(eventThread.get(), ResyncCallback(), | 
|  | 172 | ISurfaceComposer::eConfigChangedSuppress))); | 
|  | 173 |  | 
|  | 174 | EXPECT_CALL(*sfEventThread, registerDisplayEventConnection(_)); | 
|  | 175 | EXPECT_CALL(*sfEventThread, createEventConnection(_, _)) | 
|  | 176 | .WillOnce(Return(new EventThreadConnection(sfEventThread.get(), ResyncCallback(), | 
|  | 177 | ISurfaceComposer::eConfigChangedSuppress))); | 
|  | 178 |  | 
|  | 179 | auto primaryDispSync = std::make_unique<mock::DispSync>(); | 
|  | 180 |  | 
| Ady Abraham | 0ed31c9 | 2020-04-16 11:48:45 -0700 | [diff] [blame] | 181 | EXPECT_CALL(*primaryDispSync, computeNextRefresh(0, _)).WillRepeatedly(Return(0)); | 
| Ady Abraham | 60e42ea | 2020-03-09 19:17:31 -0700 | [diff] [blame] | 182 | EXPECT_CALL(*primaryDispSync, getPeriod()) | 
|  | 183 | .WillRepeatedly(Return(FakeHwcDisplayInjector::DEFAULT_REFRESH_RATE)); | 
| Ady Abraham | 0ed31c9 | 2020-04-16 11:48:45 -0700 | [diff] [blame] | 184 | EXPECT_CALL(*primaryDispSync, expectedPresentTime(_)).WillRepeatedly(Return(0)); | 
| Ady Abraham | 60e42ea | 2020-03-09 19:17:31 -0700 | [diff] [blame] | 185 | mFlinger.setupScheduler(std::move(primaryDispSync), | 
|  | 186 | std::make_unique<mock::EventControlThread>(), std::move(eventThread), | 
|  | 187 | std::move(sfEventThread)); | 
|  | 188 | } | 
|  | 189 |  | 
|  | 190 | void SetFrameRateTest::setupComposer(uint32_t virtualDisplayCount) { | 
|  | 191 | mComposer = new Hwc2::mock::Composer(); | 
|  | 192 | EXPECT_CALL(*mComposer, getMaxVirtualDisplayCount()).WillOnce(Return(virtualDisplayCount)); | 
|  | 193 | mFlinger.setupComposer(std::unique_ptr<Hwc2::Composer>(mComposer)); | 
|  | 194 |  | 
|  | 195 | Mock::VerifyAndClear(mComposer); | 
|  | 196 | } | 
|  | 197 |  | 
|  | 198 | namespace { | 
|  | 199 | /* ------------------------------------------------------------------------ | 
|  | 200 | * Test cases | 
|  | 201 | */ | 
|  | 202 | TEST_P(SetFrameRateTest, SetAndGet) { | 
|  | 203 | EXPECT_CALL(*mMessageQueue, invalidate()).Times(1); | 
|  | 204 |  | 
|  | 205 | const auto& layerFactory = GetParam(); | 
|  | 206 |  | 
|  | 207 | auto layer = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); | 
|  | 208 | layer->setFrameRate(FRAME_RATE_VOTE1); | 
|  | 209 | commitTransaction(); | 
|  | 210 | EXPECT_EQ(FRAME_RATE_VOTE1, layer->getFrameRateForLayerTree()); | 
|  | 211 | } | 
|  | 212 |  | 
|  | 213 | TEST_P(SetFrameRateTest, SetAndGetParent) { | 
|  | 214 | EXPECT_CALL(*mMessageQueue, invalidate()).Times(1); | 
|  | 215 |  | 
|  | 216 | const auto& layerFactory = GetParam(); | 
|  | 217 |  | 
|  | 218 | auto parent = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); | 
|  | 219 | auto child1 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); | 
|  | 220 | auto child2 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); | 
|  | 221 |  | 
|  | 222 | addChild(parent, child1); | 
|  | 223 | addChild(child1, child2); | 
|  | 224 |  | 
|  | 225 | child2->setFrameRate(FRAME_RATE_VOTE1); | 
|  | 226 | commitTransaction(); | 
|  | 227 | EXPECT_EQ(FRAME_RATE_TREE, parent->getFrameRateForLayerTree()); | 
|  | 228 | EXPECT_EQ(FRAME_RATE_TREE, child1->getFrameRateForLayerTree()); | 
|  | 229 | EXPECT_EQ(FRAME_RATE_VOTE1, child2->getFrameRateForLayerTree()); | 
|  | 230 |  | 
|  | 231 | child2->setFrameRate(FRAME_RATE_NO_VOTE); | 
|  | 232 | commitTransaction(); | 
|  | 233 | EXPECT_EQ(FRAME_RATE_NO_VOTE, parent->getFrameRateForLayerTree()); | 
|  | 234 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child1->getFrameRateForLayerTree()); | 
|  | 235 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child2->getFrameRateForLayerTree()); | 
|  | 236 | } | 
|  | 237 |  | 
|  | 238 | TEST_P(SetFrameRateTest, SetAndGetParentAllVote) { | 
|  | 239 | EXPECT_CALL(*mMessageQueue, invalidate()).Times(1); | 
|  | 240 |  | 
|  | 241 | const auto& layerFactory = GetParam(); | 
|  | 242 |  | 
|  | 243 | auto parent = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); | 
|  | 244 | auto child1 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); | 
|  | 245 | auto child2 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); | 
|  | 246 |  | 
|  | 247 | addChild(parent, child1); | 
|  | 248 | addChild(child1, child2); | 
|  | 249 |  | 
|  | 250 | child2->setFrameRate(FRAME_RATE_VOTE1); | 
|  | 251 | child1->setFrameRate(FRAME_RATE_VOTE2); | 
|  | 252 | parent->setFrameRate(FRAME_RATE_VOTE3); | 
|  | 253 | commitTransaction(); | 
|  | 254 | EXPECT_EQ(FRAME_RATE_VOTE3, parent->getFrameRateForLayerTree()); | 
|  | 255 | EXPECT_EQ(FRAME_RATE_VOTE2, child1->getFrameRateForLayerTree()); | 
|  | 256 | EXPECT_EQ(FRAME_RATE_VOTE1, child2->getFrameRateForLayerTree()); | 
|  | 257 |  | 
|  | 258 | child2->setFrameRate(FRAME_RATE_NO_VOTE); | 
|  | 259 | commitTransaction(); | 
|  | 260 | EXPECT_EQ(FRAME_RATE_VOTE3, parent->getFrameRateForLayerTree()); | 
|  | 261 | EXPECT_EQ(FRAME_RATE_VOTE2, child1->getFrameRateForLayerTree()); | 
|  | 262 | EXPECT_EQ(FRAME_RATE_TREE, child2->getFrameRateForLayerTree()); | 
|  | 263 |  | 
|  | 264 | child1->setFrameRate(FRAME_RATE_NO_VOTE); | 
|  | 265 | commitTransaction(); | 
|  | 266 | EXPECT_EQ(FRAME_RATE_VOTE3, parent->getFrameRateForLayerTree()); | 
|  | 267 | EXPECT_EQ(FRAME_RATE_TREE, child1->getFrameRateForLayerTree()); | 
|  | 268 | EXPECT_EQ(FRAME_RATE_TREE, child2->getFrameRateForLayerTree()); | 
|  | 269 |  | 
|  | 270 | parent->setFrameRate(FRAME_RATE_NO_VOTE); | 
|  | 271 | commitTransaction(); | 
|  | 272 | EXPECT_EQ(FRAME_RATE_NO_VOTE, parent->getFrameRateForLayerTree()); | 
|  | 273 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child1->getFrameRateForLayerTree()); | 
|  | 274 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child2->getFrameRateForLayerTree()); | 
|  | 275 | } | 
|  | 276 |  | 
|  | 277 | TEST_P(SetFrameRateTest, SetAndGetChild) { | 
|  | 278 | EXPECT_CALL(*mMessageQueue, invalidate()).Times(1); | 
|  | 279 |  | 
|  | 280 | const auto& layerFactory = GetParam(); | 
|  | 281 |  | 
|  | 282 | auto parent = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); | 
|  | 283 | auto child1 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); | 
|  | 284 | auto child2 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); | 
|  | 285 |  | 
|  | 286 | addChild(parent, child1); | 
|  | 287 | addChild(child1, child2); | 
|  | 288 |  | 
|  | 289 | parent->setFrameRate(FRAME_RATE_VOTE1); | 
|  | 290 | commitTransaction(); | 
|  | 291 | EXPECT_EQ(FRAME_RATE_VOTE1, parent->getFrameRateForLayerTree()); | 
|  | 292 | EXPECT_EQ(FRAME_RATE_TREE, child1->getFrameRateForLayerTree()); | 
|  | 293 | EXPECT_EQ(FRAME_RATE_TREE, child2->getFrameRateForLayerTree()); | 
|  | 294 |  | 
|  | 295 | parent->setFrameRate(FRAME_RATE_NO_VOTE); | 
|  | 296 | commitTransaction(); | 
|  | 297 | EXPECT_EQ(FRAME_RATE_NO_VOTE, parent->getFrameRateForLayerTree()); | 
|  | 298 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child1->getFrameRateForLayerTree()); | 
|  | 299 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child2->getFrameRateForLayerTree()); | 
|  | 300 | } | 
|  | 301 |  | 
|  | 302 | TEST_P(SetFrameRateTest, SetAndGetChildAllVote) { | 
|  | 303 | EXPECT_CALL(*mMessageQueue, invalidate()).Times(1); | 
|  | 304 |  | 
|  | 305 | const auto& layerFactory = GetParam(); | 
|  | 306 |  | 
|  | 307 | auto parent = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); | 
|  | 308 | auto child1 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); | 
|  | 309 | auto child2 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); | 
|  | 310 |  | 
|  | 311 | addChild(parent, child1); | 
|  | 312 | addChild(child1, child2); | 
|  | 313 |  | 
|  | 314 | child2->setFrameRate(FRAME_RATE_VOTE1); | 
|  | 315 | child1->setFrameRate(FRAME_RATE_VOTE2); | 
|  | 316 | parent->setFrameRate(FRAME_RATE_VOTE3); | 
|  | 317 | commitTransaction(); | 
|  | 318 | EXPECT_EQ(FRAME_RATE_VOTE3, parent->getFrameRateForLayerTree()); | 
|  | 319 | EXPECT_EQ(FRAME_RATE_VOTE2, child1->getFrameRateForLayerTree()); | 
|  | 320 | EXPECT_EQ(FRAME_RATE_VOTE1, child2->getFrameRateForLayerTree()); | 
|  | 321 |  | 
|  | 322 | parent->setFrameRate(FRAME_RATE_NO_VOTE); | 
|  | 323 | commitTransaction(); | 
|  | 324 | EXPECT_EQ(FRAME_RATE_TREE, parent->getFrameRateForLayerTree()); | 
|  | 325 | EXPECT_EQ(FRAME_RATE_VOTE2, child1->getFrameRateForLayerTree()); | 
|  | 326 | EXPECT_EQ(FRAME_RATE_VOTE1, child2->getFrameRateForLayerTree()); | 
|  | 327 |  | 
|  | 328 | child1->setFrameRate(FRAME_RATE_NO_VOTE); | 
|  | 329 | commitTransaction(); | 
|  | 330 | EXPECT_EQ(FRAME_RATE_TREE, parent->getFrameRateForLayerTree()); | 
|  | 331 | EXPECT_EQ(FRAME_RATE_TREE, child1->getFrameRateForLayerTree()); | 
|  | 332 | EXPECT_EQ(FRAME_RATE_VOTE1, child2->getFrameRateForLayerTree()); | 
|  | 333 |  | 
|  | 334 | child2->setFrameRate(FRAME_RATE_NO_VOTE); | 
|  | 335 | commitTransaction(); | 
|  | 336 | EXPECT_EQ(FRAME_RATE_NO_VOTE, parent->getFrameRateForLayerTree()); | 
|  | 337 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child1->getFrameRateForLayerTree()); | 
|  | 338 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child2->getFrameRateForLayerTree()); | 
|  | 339 | } | 
|  | 340 |  | 
|  | 341 | TEST_P(SetFrameRateTest, SetAndGetChildAddAfterVote) { | 
|  | 342 | EXPECT_CALL(*mMessageQueue, invalidate()).Times(1); | 
|  | 343 |  | 
|  | 344 | const auto& layerFactory = GetParam(); | 
|  | 345 |  | 
|  | 346 | auto parent = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); | 
|  | 347 | auto child1 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); | 
|  | 348 | auto child2 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); | 
|  | 349 |  | 
|  | 350 | addChild(parent, child1); | 
|  | 351 |  | 
|  | 352 | parent->setFrameRate(FRAME_RATE_VOTE1); | 
|  | 353 | commitTransaction(); | 
|  | 354 | EXPECT_EQ(FRAME_RATE_VOTE1, parent->getFrameRateForLayerTree()); | 
|  | 355 | EXPECT_EQ(FRAME_RATE_TREE, child1->getFrameRateForLayerTree()); | 
|  | 356 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child2->getFrameRateForLayerTree()); | 
|  | 357 |  | 
|  | 358 | addChild(child1, child2); | 
|  | 359 | commitTransaction(); | 
|  | 360 | EXPECT_EQ(FRAME_RATE_VOTE1, parent->getFrameRateForLayerTree()); | 
|  | 361 | EXPECT_EQ(FRAME_RATE_TREE, child1->getFrameRateForLayerTree()); | 
|  | 362 | EXPECT_EQ(FRAME_RATE_TREE, child2->getFrameRateForLayerTree()); | 
|  | 363 |  | 
|  | 364 | parent->setFrameRate(FRAME_RATE_NO_VOTE); | 
|  | 365 | commitTransaction(); | 
|  | 366 | EXPECT_EQ(FRAME_RATE_NO_VOTE, parent->getFrameRateForLayerTree()); | 
|  | 367 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child1->getFrameRateForLayerTree()); | 
|  | 368 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child2->getFrameRateForLayerTree()); | 
|  | 369 | } | 
|  | 370 |  | 
|  | 371 | TEST_P(SetFrameRateTest, SetAndGetChildRemoveAfterVote) { | 
|  | 372 | EXPECT_CALL(*mMessageQueue, invalidate()).Times(1); | 
|  | 373 |  | 
|  | 374 | const auto& layerFactory = GetParam(); | 
|  | 375 |  | 
|  | 376 | auto parent = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); | 
|  | 377 | auto child1 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); | 
|  | 378 | auto child2 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); | 
|  | 379 |  | 
|  | 380 | addChild(parent, child1); | 
|  | 381 | addChild(child1, child2); | 
|  | 382 |  | 
|  | 383 | parent->setFrameRate(FRAME_RATE_VOTE1); | 
|  | 384 | commitTransaction(); | 
|  | 385 | EXPECT_EQ(FRAME_RATE_VOTE1, parent->getFrameRateForLayerTree()); | 
|  | 386 | EXPECT_EQ(FRAME_RATE_TREE, child1->getFrameRateForLayerTree()); | 
|  | 387 | EXPECT_EQ(FRAME_RATE_TREE, child2->getFrameRateForLayerTree()); | 
|  | 388 |  | 
|  | 389 | removeChild(child1, child2); | 
|  | 390 | commitTransaction(); | 
|  | 391 | EXPECT_EQ(FRAME_RATE_VOTE1, parent->getFrameRateForLayerTree()); | 
|  | 392 | EXPECT_EQ(FRAME_RATE_TREE, child1->getFrameRateForLayerTree()); | 
|  | 393 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child2->getFrameRateForLayerTree()); | 
|  | 394 |  | 
|  | 395 | parent->setFrameRate(FRAME_RATE_NO_VOTE); | 
|  | 396 | commitTransaction(); | 
|  | 397 | EXPECT_EQ(FRAME_RATE_NO_VOTE, parent->getFrameRateForLayerTree()); | 
|  | 398 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child1->getFrameRateForLayerTree()); | 
|  | 399 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child2->getFrameRateForLayerTree()); | 
|  | 400 | } | 
|  | 401 |  | 
|  | 402 | TEST_P(SetFrameRateTest, SetAndGetParentNotInTree) { | 
|  | 403 | EXPECT_CALL(*mMessageQueue, invalidate()).Times(1); | 
|  | 404 |  | 
|  | 405 | const auto& layerFactory = GetParam(); | 
|  | 406 |  | 
|  | 407 | auto parent = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); | 
|  | 408 | auto child1 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); | 
|  | 409 | auto child2 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); | 
|  | 410 | auto child2_1 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); | 
|  | 411 |  | 
|  | 412 | addChild(parent, child1); | 
|  | 413 | addChild(child1, child2); | 
|  | 414 | addChild(child1, child2_1); | 
|  | 415 |  | 
|  | 416 | child2->setFrameRate(FRAME_RATE_VOTE1); | 
|  | 417 | commitTransaction(); | 
|  | 418 | EXPECT_EQ(FRAME_RATE_TREE, parent->getFrameRateForLayerTree()); | 
|  | 419 | EXPECT_EQ(FRAME_RATE_TREE, child1->getFrameRateForLayerTree()); | 
|  | 420 | EXPECT_EQ(FRAME_RATE_VOTE1, child2->getFrameRateForLayerTree()); | 
|  | 421 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child2_1->getFrameRateForLayerTree()); | 
|  | 422 |  | 
|  | 423 | child2->setFrameRate(FRAME_RATE_NO_VOTE); | 
|  | 424 | commitTransaction(); | 
|  | 425 | EXPECT_EQ(FRAME_RATE_NO_VOTE, parent->getFrameRateForLayerTree()); | 
|  | 426 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child1->getFrameRateForLayerTree()); | 
|  | 427 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child2->getFrameRateForLayerTree()); | 
|  | 428 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child2_1->getFrameRateForLayerTree()); | 
|  | 429 | } | 
|  | 430 |  | 
|  | 431 | TEST_P(SetFrameRateTest, SetAndGetRearentChildren) { | 
|  | 432 | EXPECT_CALL(*mMessageQueue, invalidate()).Times(1); | 
|  | 433 |  | 
|  | 434 | const auto& layerFactory = GetParam(); | 
|  | 435 |  | 
|  | 436 | auto parent = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); | 
|  | 437 | auto parent2 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); | 
|  | 438 | auto child1 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); | 
|  | 439 | auto child2 = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); | 
|  | 440 |  | 
|  | 441 | addChild(parent, child1); | 
|  | 442 | addChild(child1, child2); | 
|  | 443 |  | 
|  | 444 | child2->setFrameRate(FRAME_RATE_VOTE1); | 
|  | 445 | commitTransaction(); | 
|  | 446 | EXPECT_EQ(FRAME_RATE_TREE, parent->getFrameRateForLayerTree()); | 
|  | 447 | EXPECT_EQ(FRAME_RATE_NO_VOTE, parent2->getFrameRateForLayerTree()); | 
|  | 448 | EXPECT_EQ(FRAME_RATE_TREE, child1->getFrameRateForLayerTree()); | 
|  | 449 | EXPECT_EQ(FRAME_RATE_VOTE1, child2->getFrameRateForLayerTree()); | 
|  | 450 |  | 
|  | 451 | reparentChildren(parent, parent2); | 
|  | 452 | commitTransaction(); | 
|  | 453 | EXPECT_EQ(FRAME_RATE_NO_VOTE, parent->getFrameRateForLayerTree()); | 
|  | 454 | EXPECT_EQ(FRAME_RATE_TREE, parent2->getFrameRateForLayerTree()); | 
|  | 455 | EXPECT_EQ(FRAME_RATE_TREE, child1->getFrameRateForLayerTree()); | 
|  | 456 | EXPECT_EQ(FRAME_RATE_VOTE1, child2->getFrameRateForLayerTree()); | 
|  | 457 |  | 
|  | 458 | child2->setFrameRate(FRAME_RATE_NO_VOTE); | 
|  | 459 | commitTransaction(); | 
|  | 460 | EXPECT_EQ(FRAME_RATE_NO_VOTE, parent->getFrameRateForLayerTree()); | 
|  | 461 | EXPECT_EQ(FRAME_RATE_NO_VOTE, parent2->getFrameRateForLayerTree()); | 
|  | 462 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child1->getFrameRateForLayerTree()); | 
|  | 463 | EXPECT_EQ(FRAME_RATE_NO_VOTE, child2->getFrameRateForLayerTree()); | 
|  | 464 | } | 
|  | 465 |  | 
|  | 466 | INSTANTIATE_TEST_SUITE_P(PerLayerType, SetFrameRateTest, | 
|  | 467 | testing::Values(std::make_shared<BufferQueueLayerFactory>(), | 
|  | 468 | std::make_shared<BufferStateLayerFactory>(), | 
|  | 469 | std::make_shared<EffectLayerFactory>()), | 
|  | 470 | PrintToStringParamName); | 
|  | 471 |  | 
|  | 472 | } // namespace | 
|  | 473 | } // namespace android |