blob: c088ddc97138651f02a69f7b09d67a90d977bb8c [file] [log] [blame]
Ady Abraham60e42ea2020-03-09 19:17:31 -07001/*
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 Abraham60e42ea2020-03-09 19:17:31 -070035#include "mock/MockEventThread.h"
36#include "mock/MockMessageQueue.h"
Ady Abraham8cb21882020-08-26 18:22:05 -070037#include "mock/MockVsyncController.h"
Ady Abraham60e42ea2020-03-09 19:17:31 -070038
39namespace android {
40
41using testing::_;
42using testing::DoAll;
43using testing::Mock;
44using testing::Return;
45using testing::SetArgPointee;
46
47using android::Hwc2::IComposer;
48using android::Hwc2::IComposerClient;
49
50using FakeHwcDisplayInjector = TestableSurfaceFlinger::FakeHwcDisplayInjector;
51
52using FrameRate = Layer::FrameRate;
53using FrameRateCompatibility = Layer::FrameRateCompatibility;
54
55class LayerFactory {
56public:
57 virtual ~LayerFactory() = default;
58
59 virtual std::string name() = 0;
60 virtual sp<Layer> createLayer(TestableSurfaceFlinger& flinger) = 0;
61
62protected:
63 static constexpr uint32_t WIDTH = 100;
64 static constexpr uint32_t HEIGHT = 100;
65 static constexpr uint32_t LAYER_FLAGS = 0;
66};
67
68class BufferQueueLayerFactory : public LayerFactory {
69public:
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
79class BufferStateLayerFactory : public LayerFactory {
80public:
81 std::string name() override { return "BufferStateLayer"; }
82 sp<Layer> createLayer(TestableSurfaceFlinger& flinger) override {
83 sp<Client> client;
Ady Abraham44e9f3b2021-02-16 15:22:58 -080084 LayerCreationArgs args(flinger.flinger(), client, "buffer-state-layer", WIDTH, HEIGHT,
Ady Abraham60e42ea2020-03-09 19:17:31 -070085 LAYER_FLAGS, LayerMetadata());
86 return new BufferStateLayer(args);
87 }
88};
89
90class EffectLayerFactory : public LayerFactory {
91public:
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
101std::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 */
109class SetFrameRateTest : public ::testing::TestWithParam<std::shared_ptr<LayerFactory>> {
110protected:
Marin Shalamanove8a663d2020-11-24 17:48:00 +0100111 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 Abraham60e42ea2020-03-09 19:17:31 -0700117
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);
Ady Abraham60e42ea2020-03-09 19:17:31 -0700125 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
134SetFrameRateTest::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}
146void SetFrameRateTest::addChild(sp<Layer> layer, sp<Layer> child) {
147 layer.get()->addChild(child.get());
148}
149
150void SetFrameRateTest::removeChild(sp<Layer> layer, sp<Layer> child) {
151 layer.get()->removeChild(child.get());
152}
153
Ady Abraham60e42ea2020-03-09 19:17:31 -0700154void SetFrameRateTest::commitTransaction() {
155 for (auto layer : mLayers) {
Ady Abraham22c7b5c2020-09-22 19:33:40 -0700156 auto c = layer->getCurrentState();
Robert Carr0758e5d2021-03-11 22:15:04 -0800157 layer->commitTransaction(c);
Ady Abraham60e42ea2020-03-09 19:17:31 -0700158 }
159}
160
161void SetFrameRateTest::setupScheduler() {
162 auto eventThread = std::make_unique<mock::EventThread>();
163 auto sfEventThread = std::make_unique<mock::EventThread>();
164
165 EXPECT_CALL(*eventThread, registerDisplayEventConnection(_));
166 EXPECT_CALL(*eventThread, createEventConnection(_, _))
Ady Abraham0bb6a472020-10-12 10:22:13 -0700167 .WillOnce(Return(new EventThreadConnection(eventThread.get(), /*callingUid=*/0,
Ady Abraham62f216c2020-10-13 19:07:23 -0700168 ResyncCallback())));
Ady Abraham60e42ea2020-03-09 19:17:31 -0700169
170 EXPECT_CALL(*sfEventThread, registerDisplayEventConnection(_));
171 EXPECT_CALL(*sfEventThread, createEventConnection(_, _))
Ady Abraham0bb6a472020-10-12 10:22:13 -0700172 .WillOnce(Return(new EventThreadConnection(sfEventThread.get(), /*callingUid=*/0,
Ady Abraham62f216c2020-10-13 19:07:23 -0700173 ResyncCallback())));
Ady Abraham60e42ea2020-03-09 19:17:31 -0700174
Ady Abraham8cb21882020-08-26 18:22:05 -0700175 auto vsyncController = std::make_unique<mock::VsyncController>();
176 auto vsyncTracker = std::make_unique<mock::VSyncTracker>();
Ady Abraham60e42ea2020-03-09 19:17:31 -0700177
Ady Abraham8cb21882020-08-26 18:22:05 -0700178 EXPECT_CALL(*vsyncTracker, nextAnticipatedVSyncTimeFrom(_)).WillRepeatedly(Return(0));
179 EXPECT_CALL(*vsyncTracker, currentPeriod())
Marin Shalamanov045b7002021-01-07 16:56:24 +0100180 .WillRepeatedly(Return(FakeHwcDisplayInjector::DEFAULT_VSYNC_PERIOD));
Ady Abraham8cb21882020-08-26 18:22:05 -0700181 EXPECT_CALL(*vsyncTracker, nextAnticipatedVSyncTimeFrom(_)).WillRepeatedly(Return(0));
182 mFlinger.setupScheduler(std::move(vsyncController), std::move(vsyncTracker),
Ady Abraham44e9f3b2021-02-16 15:22:58 -0800183 std::move(eventThread), std::move(sfEventThread), /*callback*/ nullptr,
184 /*hasMultipleModes*/ true);
Ady Abraham60e42ea2020-03-09 19:17:31 -0700185}
186
187void SetFrameRateTest::setupComposer(uint32_t virtualDisplayCount) {
188 mComposer = new Hwc2::mock::Composer();
189 EXPECT_CALL(*mComposer, getMaxVirtualDisplayCount()).WillOnce(Return(virtualDisplayCount));
190 mFlinger.setupComposer(std::unique_ptr<Hwc2::Composer>(mComposer));
191
192 Mock::VerifyAndClear(mComposer);
193}
194
195namespace {
196/* ------------------------------------------------------------------------
197 * Test cases
198 */
199TEST_P(SetFrameRateTest, SetAndGet) {
200 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
201
202 const auto& layerFactory = GetParam();
203
204 auto layer = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
205 layer->setFrameRate(FRAME_RATE_VOTE1);
206 commitTransaction();
207 EXPECT_EQ(FRAME_RATE_VOTE1, layer->getFrameRateForLayerTree());
208}
209
210TEST_P(SetFrameRateTest, SetAndGetParent) {
211 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
212
213 const auto& layerFactory = GetParam();
214
215 auto parent = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
216 auto child1 = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
217 auto child2 = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
218
219 addChild(parent, child1);
220 addChild(child1, child2);
221
222 child2->setFrameRate(FRAME_RATE_VOTE1);
223 commitTransaction();
224 EXPECT_EQ(FRAME_RATE_TREE, parent->getFrameRateForLayerTree());
225 EXPECT_EQ(FRAME_RATE_TREE, child1->getFrameRateForLayerTree());
226 EXPECT_EQ(FRAME_RATE_VOTE1, child2->getFrameRateForLayerTree());
227
228 child2->setFrameRate(FRAME_RATE_NO_VOTE);
229 commitTransaction();
230 EXPECT_EQ(FRAME_RATE_NO_VOTE, parent->getFrameRateForLayerTree());
231 EXPECT_EQ(FRAME_RATE_NO_VOTE, child1->getFrameRateForLayerTree());
232 EXPECT_EQ(FRAME_RATE_NO_VOTE, child2->getFrameRateForLayerTree());
233}
234
235TEST_P(SetFrameRateTest, SetAndGetParentAllVote) {
236 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
237
238 const auto& layerFactory = GetParam();
239
240 auto parent = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
241 auto child1 = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
242 auto child2 = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
243
244 addChild(parent, child1);
245 addChild(child1, child2);
246
247 child2->setFrameRate(FRAME_RATE_VOTE1);
248 child1->setFrameRate(FRAME_RATE_VOTE2);
249 parent->setFrameRate(FRAME_RATE_VOTE3);
250 commitTransaction();
251 EXPECT_EQ(FRAME_RATE_VOTE3, parent->getFrameRateForLayerTree());
252 EXPECT_EQ(FRAME_RATE_VOTE2, child1->getFrameRateForLayerTree());
253 EXPECT_EQ(FRAME_RATE_VOTE1, child2->getFrameRateForLayerTree());
254
255 child2->setFrameRate(FRAME_RATE_NO_VOTE);
256 commitTransaction();
257 EXPECT_EQ(FRAME_RATE_VOTE3, parent->getFrameRateForLayerTree());
258 EXPECT_EQ(FRAME_RATE_VOTE2, child1->getFrameRateForLayerTree());
Ady Abrahamf467f892020-07-31 16:01:53 -0700259 EXPECT_EQ(FRAME_RATE_VOTE2, child2->getFrameRateForLayerTree());
Ady Abraham60e42ea2020-03-09 19:17:31 -0700260
261 child1->setFrameRate(FRAME_RATE_NO_VOTE);
262 commitTransaction();
263 EXPECT_EQ(FRAME_RATE_VOTE3, parent->getFrameRateForLayerTree());
Ady Abrahamf467f892020-07-31 16:01:53 -0700264 EXPECT_EQ(FRAME_RATE_VOTE3, child1->getFrameRateForLayerTree());
265 EXPECT_EQ(FRAME_RATE_VOTE3, child2->getFrameRateForLayerTree());
Ady Abraham60e42ea2020-03-09 19:17:31 -0700266
267 parent->setFrameRate(FRAME_RATE_NO_VOTE);
268 commitTransaction();
269 EXPECT_EQ(FRAME_RATE_NO_VOTE, parent->getFrameRateForLayerTree());
270 EXPECT_EQ(FRAME_RATE_NO_VOTE, child1->getFrameRateForLayerTree());
271 EXPECT_EQ(FRAME_RATE_NO_VOTE, child2->getFrameRateForLayerTree());
272}
273
274TEST_P(SetFrameRateTest, SetAndGetChild) {
275 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
276
277 const auto& layerFactory = GetParam();
278
279 auto parent = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
280 auto child1 = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
281 auto child2 = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
282
283 addChild(parent, child1);
284 addChild(child1, child2);
285
286 parent->setFrameRate(FRAME_RATE_VOTE1);
287 commitTransaction();
288 EXPECT_EQ(FRAME_RATE_VOTE1, parent->getFrameRateForLayerTree());
Ady Abrahamf467f892020-07-31 16:01:53 -0700289 EXPECT_EQ(FRAME_RATE_VOTE1, child1->getFrameRateForLayerTree());
290 EXPECT_EQ(FRAME_RATE_VOTE1, child2->getFrameRateForLayerTree());
Ady Abraham60e42ea2020-03-09 19:17:31 -0700291
292 parent->setFrameRate(FRAME_RATE_NO_VOTE);
293 commitTransaction();
294 EXPECT_EQ(FRAME_RATE_NO_VOTE, parent->getFrameRateForLayerTree());
295 EXPECT_EQ(FRAME_RATE_NO_VOTE, child1->getFrameRateForLayerTree());
296 EXPECT_EQ(FRAME_RATE_NO_VOTE, child2->getFrameRateForLayerTree());
297}
298
299TEST_P(SetFrameRateTest, SetAndGetChildAllVote) {
300 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
301
302 const auto& layerFactory = GetParam();
303
304 auto parent = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
305 auto child1 = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
306 auto child2 = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
307
308 addChild(parent, child1);
309 addChild(child1, child2);
310
311 child2->setFrameRate(FRAME_RATE_VOTE1);
312 child1->setFrameRate(FRAME_RATE_VOTE2);
313 parent->setFrameRate(FRAME_RATE_VOTE3);
314 commitTransaction();
315 EXPECT_EQ(FRAME_RATE_VOTE3, parent->getFrameRateForLayerTree());
316 EXPECT_EQ(FRAME_RATE_VOTE2, child1->getFrameRateForLayerTree());
317 EXPECT_EQ(FRAME_RATE_VOTE1, child2->getFrameRateForLayerTree());
318
319 parent->setFrameRate(FRAME_RATE_NO_VOTE);
320 commitTransaction();
321 EXPECT_EQ(FRAME_RATE_TREE, parent->getFrameRateForLayerTree());
322 EXPECT_EQ(FRAME_RATE_VOTE2, child1->getFrameRateForLayerTree());
323 EXPECT_EQ(FRAME_RATE_VOTE1, child2->getFrameRateForLayerTree());
324
325 child1->setFrameRate(FRAME_RATE_NO_VOTE);
326 commitTransaction();
327 EXPECT_EQ(FRAME_RATE_TREE, parent->getFrameRateForLayerTree());
328 EXPECT_EQ(FRAME_RATE_TREE, child1->getFrameRateForLayerTree());
329 EXPECT_EQ(FRAME_RATE_VOTE1, child2->getFrameRateForLayerTree());
330
331 child2->setFrameRate(FRAME_RATE_NO_VOTE);
332 commitTransaction();
333 EXPECT_EQ(FRAME_RATE_NO_VOTE, parent->getFrameRateForLayerTree());
334 EXPECT_EQ(FRAME_RATE_NO_VOTE, child1->getFrameRateForLayerTree());
335 EXPECT_EQ(FRAME_RATE_NO_VOTE, child2->getFrameRateForLayerTree());
336}
337
338TEST_P(SetFrameRateTest, SetAndGetChildAddAfterVote) {
339 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
340
341 const auto& layerFactory = GetParam();
342
343 auto parent = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
344 auto child1 = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
345 auto child2 = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
346
347 addChild(parent, child1);
348
349 parent->setFrameRate(FRAME_RATE_VOTE1);
350 commitTransaction();
351 EXPECT_EQ(FRAME_RATE_VOTE1, parent->getFrameRateForLayerTree());
Ady Abrahamf467f892020-07-31 16:01:53 -0700352 EXPECT_EQ(FRAME_RATE_VOTE1, child1->getFrameRateForLayerTree());
Ady Abraham60e42ea2020-03-09 19:17:31 -0700353 EXPECT_EQ(FRAME_RATE_NO_VOTE, child2->getFrameRateForLayerTree());
354
355 addChild(child1, child2);
356 commitTransaction();
357 EXPECT_EQ(FRAME_RATE_VOTE1, parent->getFrameRateForLayerTree());
Ady Abrahamf467f892020-07-31 16:01:53 -0700358 EXPECT_EQ(FRAME_RATE_VOTE1, child1->getFrameRateForLayerTree());
359 EXPECT_EQ(FRAME_RATE_VOTE1, child2->getFrameRateForLayerTree());
Ady Abraham60e42ea2020-03-09 19:17:31 -0700360
361 parent->setFrameRate(FRAME_RATE_NO_VOTE);
362 commitTransaction();
363 EXPECT_EQ(FRAME_RATE_NO_VOTE, parent->getFrameRateForLayerTree());
364 EXPECT_EQ(FRAME_RATE_NO_VOTE, child1->getFrameRateForLayerTree());
365 EXPECT_EQ(FRAME_RATE_NO_VOTE, child2->getFrameRateForLayerTree());
366}
367
368TEST_P(SetFrameRateTest, SetAndGetChildRemoveAfterVote) {
369 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
370
371 const auto& layerFactory = GetParam();
372
373 auto parent = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
374 auto child1 = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
375 auto child2 = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
376
377 addChild(parent, child1);
378 addChild(child1, child2);
379
380 parent->setFrameRate(FRAME_RATE_VOTE1);
381 commitTransaction();
382 EXPECT_EQ(FRAME_RATE_VOTE1, parent->getFrameRateForLayerTree());
Ady Abrahamf467f892020-07-31 16:01:53 -0700383 EXPECT_EQ(FRAME_RATE_VOTE1, child1->getFrameRateForLayerTree());
384 EXPECT_EQ(FRAME_RATE_VOTE1, child2->getFrameRateForLayerTree());
Ady Abraham60e42ea2020-03-09 19:17:31 -0700385
386 removeChild(child1, child2);
387 commitTransaction();
388 EXPECT_EQ(FRAME_RATE_VOTE1, parent->getFrameRateForLayerTree());
Ady Abrahamf467f892020-07-31 16:01:53 -0700389 EXPECT_EQ(FRAME_RATE_VOTE1, child1->getFrameRateForLayerTree());
Ady Abraham60e42ea2020-03-09 19:17:31 -0700390 EXPECT_EQ(FRAME_RATE_NO_VOTE, child2->getFrameRateForLayerTree());
391
392 parent->setFrameRate(FRAME_RATE_NO_VOTE);
393 commitTransaction();
394 EXPECT_EQ(FRAME_RATE_NO_VOTE, parent->getFrameRateForLayerTree());
395 EXPECT_EQ(FRAME_RATE_NO_VOTE, child1->getFrameRateForLayerTree());
396 EXPECT_EQ(FRAME_RATE_NO_VOTE, child2->getFrameRateForLayerTree());
397}
398
399TEST_P(SetFrameRateTest, SetAndGetParentNotInTree) {
400 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
401
402 const auto& layerFactory = GetParam();
403
404 auto parent = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
405 auto child1 = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
406 auto child2 = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
407 auto child2_1 = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
408
409 addChild(parent, child1);
410 addChild(child1, child2);
411 addChild(child1, child2_1);
412
413 child2->setFrameRate(FRAME_RATE_VOTE1);
414 commitTransaction();
415 EXPECT_EQ(FRAME_RATE_TREE, parent->getFrameRateForLayerTree());
416 EXPECT_EQ(FRAME_RATE_TREE, child1->getFrameRateForLayerTree());
417 EXPECT_EQ(FRAME_RATE_VOTE1, child2->getFrameRateForLayerTree());
418 EXPECT_EQ(FRAME_RATE_NO_VOTE, child2_1->getFrameRateForLayerTree());
419
420 child2->setFrameRate(FRAME_RATE_NO_VOTE);
421 commitTransaction();
422 EXPECT_EQ(FRAME_RATE_NO_VOTE, parent->getFrameRateForLayerTree());
423 EXPECT_EQ(FRAME_RATE_NO_VOTE, child1->getFrameRateForLayerTree());
424 EXPECT_EQ(FRAME_RATE_NO_VOTE, child2->getFrameRateForLayerTree());
425 EXPECT_EQ(FRAME_RATE_NO_VOTE, child2_1->getFrameRateForLayerTree());
426}
427
Ady Abraham60e42ea2020-03-09 19:17:31 -0700428INSTANTIATE_TEST_SUITE_P(PerLayerType, SetFrameRateTest,
429 testing::Values(std::make_shared<BufferQueueLayerFactory>(),
430 std::make_shared<BufferStateLayerFactory>(),
431 std::make_shared<EffectLayerFactory>()),
432 PrintToStringParamName);
433
Ady Abrahamdd5bfa92021-01-07 17:56:08 -0800434TEST_F(SetFrameRateTest, ValidateFrameRate) {
Marin Shalamanovc5986772021-03-16 16:09:49 +0100435 EXPECT_TRUE(ValidateFrameRate(60.0f, ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT,
436 ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS, ""));
437 EXPECT_TRUE(ValidateFrameRate(60.0f, ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT,
438 ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS, ""));
439 EXPECT_TRUE(ValidateFrameRate(60.0f, ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT,
440 ANATIVEWINDOW_CHANGE_FRAME_RATE_ALWAYS, ""));
441 EXPECT_TRUE(ValidateFrameRate(60.0f, ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_FIXED_SOURCE,
442 ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS, ""));
443 EXPECT_TRUE(ValidateFrameRate(60.0f, ANATIVEWINDOW_FRAME_RATE_EXACT,
444 ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS, "",
445 /*privileged=*/true));
Ady Abrahamdd5bfa92021-01-07 17:56:08 -0800446
Marin Shalamanovc5986772021-03-16 16:09:49 +0100447 EXPECT_FALSE(ValidateFrameRate(-1, ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT,
448 ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS, ""));
449 EXPECT_FALSE(ValidateFrameRate(1.0f / 0.0f, ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT,
450 ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS, ""));
451 EXPECT_FALSE(ValidateFrameRate(0.0f / 0.0f, ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT,
452 ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS, ""));
Ady Abrahamdd5bfa92021-01-07 17:56:08 -0800453
Marin Shalamanovc5986772021-03-16 16:09:49 +0100454 EXPECT_FALSE(ValidateFrameRate(60.0f, ANATIVEWINDOW_FRAME_RATE_EXACT,
455 ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS, ""));
456
457 // Invalid compatibility
458 EXPECT_FALSE(
459 ValidateFrameRate(60.0f, -1, ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS, ""));
460 EXPECT_FALSE(ValidateFrameRate(60.0f, 2, ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS, ""));
461
462 // Invalid change frame rate strategy
463 EXPECT_FALSE(ValidateFrameRate(60.0f, ANATIVEWINDOW_FRAME_RATE_EXACT, -1, ""));
464 EXPECT_FALSE(ValidateFrameRate(60.0f, ANATIVEWINDOW_FRAME_RATE_EXACT, 2, ""));
Ady Abrahamdd5bfa92021-01-07 17:56:08 -0800465}
466
Ady Abraham44e9f3b2021-02-16 15:22:58 -0800467TEST_P(SetFrameRateTest, SetOnParentActivatesTree) {
468 const auto& layerFactory = GetParam();
469
470 auto parent = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
471 if (!parent->isVisible()) {
472 // This is a hack as all the test layers except EffectLayer are not visible,
473 // but since the logic is unified in Layer, it should be fine.
474 return;
475 }
476
477 auto child = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
478 addChild(parent, child);
479
480 parent->setFrameRate(FRAME_RATE_VOTE1);
481 commitTransaction();
482
Ady Abrahambdda8f02021-04-01 16:06:11 -0700483 mFlinger.mutableScheduler()
484 .mutableLayerHistory()
485 ->record(parent.get(), 0, 0, LayerHistory::LayerUpdateType::Buffer);
486 mFlinger.mutableScheduler()
487 .mutableLayerHistory()
488 ->record(child.get(), 0, 0, LayerHistory::LayerUpdateType::Buffer);
489
Ady Abraham44e9f3b2021-02-16 15:22:58 -0800490 const auto layerHistorySummary =
491 mFlinger.mutableScheduler().mutableLayerHistory()->summarize(0);
492 ASSERT_EQ(2u, layerHistorySummary.size());
493 EXPECT_TRUE(FRAME_RATE_VOTE1.rate.equalsWithMargin(layerHistorySummary[0].desiredRefreshRate));
494 EXPECT_TRUE(FRAME_RATE_VOTE1.rate.equalsWithMargin(layerHistorySummary[1].desiredRefreshRate));
495}
496
Ady Abraham60e42ea2020-03-09 19:17:31 -0700497} // namespace
498} // namespace android