blob: 0bb7e31194961bc69e7b126cd76f41401c1bebb3 [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 layer->pushPendingState();
157 auto c = layer->getCurrentState();
158 if (layer->applyPendingStates(&c)) {
159 layer->commitTransaction(c);
160 }
Ady Abraham60e42ea2020-03-09 19:17:31 -0700161 }
162}
163
164void SetFrameRateTest::setupScheduler() {
165 auto eventThread = std::make_unique<mock::EventThread>();
166 auto sfEventThread = std::make_unique<mock::EventThread>();
167
168 EXPECT_CALL(*eventThread, registerDisplayEventConnection(_));
169 EXPECT_CALL(*eventThread, createEventConnection(_, _))
Ady Abraham0bb6a472020-10-12 10:22:13 -0700170 .WillOnce(Return(new EventThreadConnection(eventThread.get(), /*callingUid=*/0,
Ady Abraham62f216c2020-10-13 19:07:23 -0700171 ResyncCallback())));
Ady Abraham60e42ea2020-03-09 19:17:31 -0700172
173 EXPECT_CALL(*sfEventThread, registerDisplayEventConnection(_));
174 EXPECT_CALL(*sfEventThread, createEventConnection(_, _))
Ady Abraham0bb6a472020-10-12 10:22:13 -0700175 .WillOnce(Return(new EventThreadConnection(sfEventThread.get(), /*callingUid=*/0,
Ady Abraham62f216c2020-10-13 19:07:23 -0700176 ResyncCallback())));
Ady Abraham60e42ea2020-03-09 19:17:31 -0700177
Ady Abraham8cb21882020-08-26 18:22:05 -0700178 auto vsyncController = std::make_unique<mock::VsyncController>();
179 auto vsyncTracker = std::make_unique<mock::VSyncTracker>();
Ady Abraham60e42ea2020-03-09 19:17:31 -0700180
Ady Abraham8cb21882020-08-26 18:22:05 -0700181 EXPECT_CALL(*vsyncTracker, nextAnticipatedVSyncTimeFrom(_)).WillRepeatedly(Return(0));
182 EXPECT_CALL(*vsyncTracker, currentPeriod())
Marin Shalamanov045b7002021-01-07 16:56:24 +0100183 .WillRepeatedly(Return(FakeHwcDisplayInjector::DEFAULT_VSYNC_PERIOD));
Ady Abraham8cb21882020-08-26 18:22:05 -0700184 EXPECT_CALL(*vsyncTracker, nextAnticipatedVSyncTimeFrom(_)).WillRepeatedly(Return(0));
185 mFlinger.setupScheduler(std::move(vsyncController), std::move(vsyncTracker),
Ady Abraham44e9f3b2021-02-16 15:22:58 -0800186 std::move(eventThread), std::move(sfEventThread), /*callback*/ nullptr,
187 /*hasMultipleModes*/ true);
Ady Abraham60e42ea2020-03-09 19:17:31 -0700188}
189
190void 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
198namespace {
199/* ------------------------------------------------------------------------
200 * Test cases
201 */
202TEST_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
213TEST_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
238TEST_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());
Ady Abrahamf467f892020-07-31 16:01:53 -0700262 EXPECT_EQ(FRAME_RATE_VOTE2, child2->getFrameRateForLayerTree());
Ady Abraham60e42ea2020-03-09 19:17:31 -0700263
264 child1->setFrameRate(FRAME_RATE_NO_VOTE);
265 commitTransaction();
266 EXPECT_EQ(FRAME_RATE_VOTE3, parent->getFrameRateForLayerTree());
Ady Abrahamf467f892020-07-31 16:01:53 -0700267 EXPECT_EQ(FRAME_RATE_VOTE3, child1->getFrameRateForLayerTree());
268 EXPECT_EQ(FRAME_RATE_VOTE3, child2->getFrameRateForLayerTree());
Ady Abraham60e42ea2020-03-09 19:17:31 -0700269
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
277TEST_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());
Ady Abrahamf467f892020-07-31 16:01:53 -0700292 EXPECT_EQ(FRAME_RATE_VOTE1, child1->getFrameRateForLayerTree());
293 EXPECT_EQ(FRAME_RATE_VOTE1, child2->getFrameRateForLayerTree());
Ady Abraham60e42ea2020-03-09 19:17:31 -0700294
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
302TEST_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
341TEST_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());
Ady Abrahamf467f892020-07-31 16:01:53 -0700355 EXPECT_EQ(FRAME_RATE_VOTE1, child1->getFrameRateForLayerTree());
Ady Abraham60e42ea2020-03-09 19:17:31 -0700356 EXPECT_EQ(FRAME_RATE_NO_VOTE, child2->getFrameRateForLayerTree());
357
358 addChild(child1, child2);
359 commitTransaction();
360 EXPECT_EQ(FRAME_RATE_VOTE1, parent->getFrameRateForLayerTree());
Ady Abrahamf467f892020-07-31 16:01:53 -0700361 EXPECT_EQ(FRAME_RATE_VOTE1, child1->getFrameRateForLayerTree());
362 EXPECT_EQ(FRAME_RATE_VOTE1, child2->getFrameRateForLayerTree());
Ady Abraham60e42ea2020-03-09 19:17:31 -0700363
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
371TEST_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());
Ady Abrahamf467f892020-07-31 16:01:53 -0700386 EXPECT_EQ(FRAME_RATE_VOTE1, child1->getFrameRateForLayerTree());
387 EXPECT_EQ(FRAME_RATE_VOTE1, child2->getFrameRateForLayerTree());
Ady Abraham60e42ea2020-03-09 19:17:31 -0700388
389 removeChild(child1, child2);
390 commitTransaction();
391 EXPECT_EQ(FRAME_RATE_VOTE1, parent->getFrameRateForLayerTree());
Ady Abrahamf467f892020-07-31 16:01:53 -0700392 EXPECT_EQ(FRAME_RATE_VOTE1, child1->getFrameRateForLayerTree());
Ady Abraham60e42ea2020-03-09 19:17:31 -0700393 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
402TEST_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
Ady Abraham60e42ea2020-03-09 19:17:31 -0700431INSTANTIATE_TEST_SUITE_P(PerLayerType, SetFrameRateTest,
432 testing::Values(std::make_shared<BufferQueueLayerFactory>(),
433 std::make_shared<BufferStateLayerFactory>(),
434 std::make_shared<EffectLayerFactory>()),
435 PrintToStringParamName);
436
Ady Abrahamdd5bfa92021-01-07 17:56:08 -0800437TEST_F(SetFrameRateTest, ValidateFrameRate) {
Marin Shalamanovc5986772021-03-16 16:09:49 +0100438 EXPECT_TRUE(ValidateFrameRate(60.0f, ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT,
439 ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS, ""));
440 EXPECT_TRUE(ValidateFrameRate(60.0f, ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT,
441 ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS, ""));
442 EXPECT_TRUE(ValidateFrameRate(60.0f, ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT,
443 ANATIVEWINDOW_CHANGE_FRAME_RATE_ALWAYS, ""));
444 EXPECT_TRUE(ValidateFrameRate(60.0f, ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_FIXED_SOURCE,
445 ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS, ""));
446 EXPECT_TRUE(ValidateFrameRate(60.0f, ANATIVEWINDOW_FRAME_RATE_EXACT,
447 ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS, "",
448 /*privileged=*/true));
Ady Abrahamdd5bfa92021-01-07 17:56:08 -0800449
Marin Shalamanovc5986772021-03-16 16:09:49 +0100450 EXPECT_FALSE(ValidateFrameRate(-1, ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT,
451 ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS, ""));
452 EXPECT_FALSE(ValidateFrameRate(1.0f / 0.0f, ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT,
453 ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS, ""));
454 EXPECT_FALSE(ValidateFrameRate(0.0f / 0.0f, ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT,
455 ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS, ""));
Ady Abrahamdd5bfa92021-01-07 17:56:08 -0800456
Marin Shalamanovc5986772021-03-16 16:09:49 +0100457 EXPECT_FALSE(ValidateFrameRate(60.0f, ANATIVEWINDOW_FRAME_RATE_EXACT,
458 ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS, ""));
459
460 // Invalid compatibility
461 EXPECT_FALSE(
462 ValidateFrameRate(60.0f, -1, ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS, ""));
463 EXPECT_FALSE(ValidateFrameRate(60.0f, 2, ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS, ""));
464
465 // Invalid change frame rate strategy
466 EXPECT_FALSE(ValidateFrameRate(60.0f, ANATIVEWINDOW_FRAME_RATE_EXACT, -1, ""));
467 EXPECT_FALSE(ValidateFrameRate(60.0f, ANATIVEWINDOW_FRAME_RATE_EXACT, 2, ""));
Ady Abrahamdd5bfa92021-01-07 17:56:08 -0800468}
469
Ady Abraham44e9f3b2021-02-16 15:22:58 -0800470TEST_P(SetFrameRateTest, SetOnParentActivatesTree) {
471 const auto& layerFactory = GetParam();
472
473 auto parent = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
474 if (!parent->isVisible()) {
475 // This is a hack as all the test layers except EffectLayer are not visible,
476 // but since the logic is unified in Layer, it should be fine.
477 return;
478 }
479
480 auto child = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
481 addChild(parent, child);
482
483 parent->setFrameRate(FRAME_RATE_VOTE1);
484 commitTransaction();
485
Ady Abrahambdda8f02021-04-01 16:06:11 -0700486 mFlinger.mutableScheduler()
487 .mutableLayerHistory()
488 ->record(parent.get(), 0, 0, LayerHistory::LayerUpdateType::Buffer);
489 mFlinger.mutableScheduler()
490 .mutableLayerHistory()
491 ->record(child.get(), 0, 0, LayerHistory::LayerUpdateType::Buffer);
492
Ady Abraham44e9f3b2021-02-16 15:22:58 -0800493 const auto layerHistorySummary =
494 mFlinger.mutableScheduler().mutableLayerHistory()->summarize(0);
495 ASSERT_EQ(2u, layerHistorySummary.size());
496 EXPECT_TRUE(FRAME_RATE_VOTE1.rate.equalsWithMargin(layerHistorySummary[0].desiredRefreshRate));
497 EXPECT_TRUE(FRAME_RATE_VOTE1.rate.equalsWithMargin(layerHistorySummary[1].desiredRefreshRate));
498}
499
Ady Abraham60e42ea2020-03-09 19:17:31 -0700500} // namespace
501} // namespace android