blob: 46ef75091ee592f286ebb548f2c43ce6678da310 [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();
Ady Abraham60e42ea2020-03-09 19:17:31 -0700121
122 void addChild(sp<Layer> layer, sp<Layer> child);
123 void removeChild(sp<Layer> layer, sp<Layer> child);
Ady Abraham60e42ea2020-03-09 19:17:31 -0700124 void commitTransaction();
125
126 TestableSurfaceFlinger mFlinger;
Ady Abraham60e42ea2020-03-09 19:17:31 -0700127 mock::MessageQueue* mMessageQueue = new mock::MessageQueue();
128
129 std::vector<sp<Layer>> mLayers;
130};
131
132SetFrameRateTest::SetFrameRateTest() {
133 const ::testing::TestInfo* const test_info =
134 ::testing::UnitTest::GetInstance()->current_test_info();
135 ALOGD("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name());
136
137 mFlinger.mutableUseFrameRateApi() = true;
138
139 setupScheduler();
Ady Abraham60e42ea2020-03-09 19:17:31 -0700140
Dominik Laskowski13948602021-03-08 20:48:28 -0800141 mFlinger.setupComposer(std::make_unique<Hwc2::mock::Composer>());
Ady Abraham60e42ea2020-03-09 19:17:31 -0700142 mFlinger.mutableEventQueue().reset(mMessageQueue);
143}
Dominik Laskowski13948602021-03-08 20:48:28 -0800144
Ady Abraham60e42ea2020-03-09 19:17:31 -0700145void SetFrameRateTest::addChild(sp<Layer> layer, sp<Layer> child) {
146 layer.get()->addChild(child.get());
147}
148
149void SetFrameRateTest::removeChild(sp<Layer> layer, sp<Layer> child) {
150 layer.get()->removeChild(child.get());
151}
152
Ady Abraham60e42ea2020-03-09 19:17:31 -0700153void SetFrameRateTest::commitTransaction() {
154 for (auto layer : mLayers) {
Ady Abraham22c7b5c2020-09-22 19:33:40 -0700155 auto c = layer->getCurrentState();
Robert Carr0758e5d2021-03-11 22:15:04 -0800156 layer->commitTransaction(c);
Ady Abraham60e42ea2020-03-09 19:17:31 -0700157 }
158}
159
160void SetFrameRateTest::setupScheduler() {
161 auto eventThread = std::make_unique<mock::EventThread>();
162 auto sfEventThread = std::make_unique<mock::EventThread>();
163
164 EXPECT_CALL(*eventThread, registerDisplayEventConnection(_));
165 EXPECT_CALL(*eventThread, createEventConnection(_, _))
Ady Abraham0bb6a472020-10-12 10:22:13 -0700166 .WillOnce(Return(new EventThreadConnection(eventThread.get(), /*callingUid=*/0,
Ady Abraham62f216c2020-10-13 19:07:23 -0700167 ResyncCallback())));
Ady Abraham60e42ea2020-03-09 19:17:31 -0700168
169 EXPECT_CALL(*sfEventThread, registerDisplayEventConnection(_));
170 EXPECT_CALL(*sfEventThread, createEventConnection(_, _))
Ady Abraham0bb6a472020-10-12 10:22:13 -0700171 .WillOnce(Return(new EventThreadConnection(sfEventThread.get(), /*callingUid=*/0,
Ady Abraham62f216c2020-10-13 19:07:23 -0700172 ResyncCallback())));
Ady Abraham60e42ea2020-03-09 19:17:31 -0700173
Ady Abraham8cb21882020-08-26 18:22:05 -0700174 auto vsyncController = std::make_unique<mock::VsyncController>();
175 auto vsyncTracker = std::make_unique<mock::VSyncTracker>();
Ady Abraham60e42ea2020-03-09 19:17:31 -0700176
Ady Abraham8cb21882020-08-26 18:22:05 -0700177 EXPECT_CALL(*vsyncTracker, nextAnticipatedVSyncTimeFrom(_)).WillRepeatedly(Return(0));
178 EXPECT_CALL(*vsyncTracker, currentPeriod())
Marin Shalamanov045b7002021-01-07 16:56:24 +0100179 .WillRepeatedly(Return(FakeHwcDisplayInjector::DEFAULT_VSYNC_PERIOD));
Ady Abraham8cb21882020-08-26 18:22:05 -0700180 EXPECT_CALL(*vsyncTracker, nextAnticipatedVSyncTimeFrom(_)).WillRepeatedly(Return(0));
181 mFlinger.setupScheduler(std::move(vsyncController), std::move(vsyncTracker),
Ady Abraham44e9f3b2021-02-16 15:22:58 -0800182 std::move(eventThread), std::move(sfEventThread), /*callback*/ nullptr,
183 /*hasMultipleModes*/ true);
Ady Abraham60e42ea2020-03-09 19:17:31 -0700184}
185
Ady Abraham60e42ea2020-03-09 19:17:31 -0700186namespace {
187/* ------------------------------------------------------------------------
188 * Test cases
189 */
190TEST_P(SetFrameRateTest, SetAndGet) {
191 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
192
193 const auto& layerFactory = GetParam();
194
195 auto layer = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
196 layer->setFrameRate(FRAME_RATE_VOTE1);
197 commitTransaction();
198 EXPECT_EQ(FRAME_RATE_VOTE1, layer->getFrameRateForLayerTree());
199}
200
201TEST_P(SetFrameRateTest, SetAndGetParent) {
202 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
203
204 const auto& layerFactory = GetParam();
205
206 auto parent = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
207 auto child1 = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
208 auto child2 = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
209
210 addChild(parent, child1);
211 addChild(child1, child2);
212
213 child2->setFrameRate(FRAME_RATE_VOTE1);
214 commitTransaction();
215 EXPECT_EQ(FRAME_RATE_TREE, parent->getFrameRateForLayerTree());
216 EXPECT_EQ(FRAME_RATE_TREE, child1->getFrameRateForLayerTree());
217 EXPECT_EQ(FRAME_RATE_VOTE1, child2->getFrameRateForLayerTree());
218
219 child2->setFrameRate(FRAME_RATE_NO_VOTE);
220 commitTransaction();
221 EXPECT_EQ(FRAME_RATE_NO_VOTE, parent->getFrameRateForLayerTree());
222 EXPECT_EQ(FRAME_RATE_NO_VOTE, child1->getFrameRateForLayerTree());
223 EXPECT_EQ(FRAME_RATE_NO_VOTE, child2->getFrameRateForLayerTree());
224}
225
226TEST_P(SetFrameRateTest, SetAndGetParentAllVote) {
227 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
228
229 const auto& layerFactory = GetParam();
230
231 auto parent = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
232 auto child1 = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
233 auto child2 = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
234
235 addChild(parent, child1);
236 addChild(child1, child2);
237
238 child2->setFrameRate(FRAME_RATE_VOTE1);
239 child1->setFrameRate(FRAME_RATE_VOTE2);
240 parent->setFrameRate(FRAME_RATE_VOTE3);
241 commitTransaction();
242 EXPECT_EQ(FRAME_RATE_VOTE3, parent->getFrameRateForLayerTree());
243 EXPECT_EQ(FRAME_RATE_VOTE2, child1->getFrameRateForLayerTree());
244 EXPECT_EQ(FRAME_RATE_VOTE1, child2->getFrameRateForLayerTree());
245
246 child2->setFrameRate(FRAME_RATE_NO_VOTE);
247 commitTransaction();
248 EXPECT_EQ(FRAME_RATE_VOTE3, parent->getFrameRateForLayerTree());
249 EXPECT_EQ(FRAME_RATE_VOTE2, child1->getFrameRateForLayerTree());
Ady Abrahamf467f892020-07-31 16:01:53 -0700250 EXPECT_EQ(FRAME_RATE_VOTE2, child2->getFrameRateForLayerTree());
Ady Abraham60e42ea2020-03-09 19:17:31 -0700251
252 child1->setFrameRate(FRAME_RATE_NO_VOTE);
253 commitTransaction();
254 EXPECT_EQ(FRAME_RATE_VOTE3, parent->getFrameRateForLayerTree());
Ady Abrahamf467f892020-07-31 16:01:53 -0700255 EXPECT_EQ(FRAME_RATE_VOTE3, child1->getFrameRateForLayerTree());
256 EXPECT_EQ(FRAME_RATE_VOTE3, child2->getFrameRateForLayerTree());
Ady Abraham60e42ea2020-03-09 19:17:31 -0700257
258 parent->setFrameRate(FRAME_RATE_NO_VOTE);
259 commitTransaction();
260 EXPECT_EQ(FRAME_RATE_NO_VOTE, parent->getFrameRateForLayerTree());
261 EXPECT_EQ(FRAME_RATE_NO_VOTE, child1->getFrameRateForLayerTree());
262 EXPECT_EQ(FRAME_RATE_NO_VOTE, child2->getFrameRateForLayerTree());
263}
264
265TEST_P(SetFrameRateTest, SetAndGetChild) {
266 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
267
268 const auto& layerFactory = GetParam();
269
270 auto parent = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
271 auto child1 = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
272 auto child2 = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
273
274 addChild(parent, child1);
275 addChild(child1, child2);
276
277 parent->setFrameRate(FRAME_RATE_VOTE1);
278 commitTransaction();
279 EXPECT_EQ(FRAME_RATE_VOTE1, parent->getFrameRateForLayerTree());
Ady Abrahamf467f892020-07-31 16:01:53 -0700280 EXPECT_EQ(FRAME_RATE_VOTE1, child1->getFrameRateForLayerTree());
281 EXPECT_EQ(FRAME_RATE_VOTE1, child2->getFrameRateForLayerTree());
Ady Abraham60e42ea2020-03-09 19:17:31 -0700282
283 parent->setFrameRate(FRAME_RATE_NO_VOTE);
284 commitTransaction();
285 EXPECT_EQ(FRAME_RATE_NO_VOTE, parent->getFrameRateForLayerTree());
286 EXPECT_EQ(FRAME_RATE_NO_VOTE, child1->getFrameRateForLayerTree());
287 EXPECT_EQ(FRAME_RATE_NO_VOTE, child2->getFrameRateForLayerTree());
288}
289
290TEST_P(SetFrameRateTest, SetAndGetChildAllVote) {
291 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
292
293 const auto& layerFactory = GetParam();
294
295 auto parent = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
296 auto child1 = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
297 auto child2 = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
298
299 addChild(parent, child1);
300 addChild(child1, child2);
301
302 child2->setFrameRate(FRAME_RATE_VOTE1);
303 child1->setFrameRate(FRAME_RATE_VOTE2);
304 parent->setFrameRate(FRAME_RATE_VOTE3);
305 commitTransaction();
306 EXPECT_EQ(FRAME_RATE_VOTE3, parent->getFrameRateForLayerTree());
307 EXPECT_EQ(FRAME_RATE_VOTE2, child1->getFrameRateForLayerTree());
308 EXPECT_EQ(FRAME_RATE_VOTE1, child2->getFrameRateForLayerTree());
309
310 parent->setFrameRate(FRAME_RATE_NO_VOTE);
311 commitTransaction();
312 EXPECT_EQ(FRAME_RATE_TREE, parent->getFrameRateForLayerTree());
313 EXPECT_EQ(FRAME_RATE_VOTE2, child1->getFrameRateForLayerTree());
314 EXPECT_EQ(FRAME_RATE_VOTE1, child2->getFrameRateForLayerTree());
315
316 child1->setFrameRate(FRAME_RATE_NO_VOTE);
317 commitTransaction();
318 EXPECT_EQ(FRAME_RATE_TREE, parent->getFrameRateForLayerTree());
319 EXPECT_EQ(FRAME_RATE_TREE, child1->getFrameRateForLayerTree());
320 EXPECT_EQ(FRAME_RATE_VOTE1, child2->getFrameRateForLayerTree());
321
322 child2->setFrameRate(FRAME_RATE_NO_VOTE);
323 commitTransaction();
324 EXPECT_EQ(FRAME_RATE_NO_VOTE, parent->getFrameRateForLayerTree());
325 EXPECT_EQ(FRAME_RATE_NO_VOTE, child1->getFrameRateForLayerTree());
326 EXPECT_EQ(FRAME_RATE_NO_VOTE, child2->getFrameRateForLayerTree());
327}
328
329TEST_P(SetFrameRateTest, SetAndGetChildAddAfterVote) {
330 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
331
332 const auto& layerFactory = GetParam();
333
334 auto parent = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
335 auto child1 = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
336 auto child2 = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
337
338 addChild(parent, child1);
339
340 parent->setFrameRate(FRAME_RATE_VOTE1);
341 commitTransaction();
342 EXPECT_EQ(FRAME_RATE_VOTE1, parent->getFrameRateForLayerTree());
Ady Abrahamf467f892020-07-31 16:01:53 -0700343 EXPECT_EQ(FRAME_RATE_VOTE1, child1->getFrameRateForLayerTree());
Ady Abraham60e42ea2020-03-09 19:17:31 -0700344 EXPECT_EQ(FRAME_RATE_NO_VOTE, child2->getFrameRateForLayerTree());
345
346 addChild(child1, child2);
347 commitTransaction();
348 EXPECT_EQ(FRAME_RATE_VOTE1, parent->getFrameRateForLayerTree());
Ady Abrahamf467f892020-07-31 16:01:53 -0700349 EXPECT_EQ(FRAME_RATE_VOTE1, child1->getFrameRateForLayerTree());
350 EXPECT_EQ(FRAME_RATE_VOTE1, child2->getFrameRateForLayerTree());
Ady Abraham60e42ea2020-03-09 19:17:31 -0700351
352 parent->setFrameRate(FRAME_RATE_NO_VOTE);
353 commitTransaction();
354 EXPECT_EQ(FRAME_RATE_NO_VOTE, parent->getFrameRateForLayerTree());
355 EXPECT_EQ(FRAME_RATE_NO_VOTE, child1->getFrameRateForLayerTree());
356 EXPECT_EQ(FRAME_RATE_NO_VOTE, child2->getFrameRateForLayerTree());
357}
358
359TEST_P(SetFrameRateTest, SetAndGetChildRemoveAfterVote) {
360 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
361
362 const auto& layerFactory = GetParam();
363
364 auto parent = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
365 auto child1 = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
366 auto child2 = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
367
368 addChild(parent, child1);
369 addChild(child1, child2);
370
371 parent->setFrameRate(FRAME_RATE_VOTE1);
372 commitTransaction();
373 EXPECT_EQ(FRAME_RATE_VOTE1, parent->getFrameRateForLayerTree());
Ady Abrahamf467f892020-07-31 16:01:53 -0700374 EXPECT_EQ(FRAME_RATE_VOTE1, child1->getFrameRateForLayerTree());
375 EXPECT_EQ(FRAME_RATE_VOTE1, child2->getFrameRateForLayerTree());
Ady Abraham60e42ea2020-03-09 19:17:31 -0700376
377 removeChild(child1, child2);
378 commitTransaction();
379 EXPECT_EQ(FRAME_RATE_VOTE1, parent->getFrameRateForLayerTree());
Ady Abrahamf467f892020-07-31 16:01:53 -0700380 EXPECT_EQ(FRAME_RATE_VOTE1, child1->getFrameRateForLayerTree());
Ady Abraham60e42ea2020-03-09 19:17:31 -0700381 EXPECT_EQ(FRAME_RATE_NO_VOTE, child2->getFrameRateForLayerTree());
382
383 parent->setFrameRate(FRAME_RATE_NO_VOTE);
384 commitTransaction();
385 EXPECT_EQ(FRAME_RATE_NO_VOTE, parent->getFrameRateForLayerTree());
386 EXPECT_EQ(FRAME_RATE_NO_VOTE, child1->getFrameRateForLayerTree());
387 EXPECT_EQ(FRAME_RATE_NO_VOTE, child2->getFrameRateForLayerTree());
388}
389
390TEST_P(SetFrameRateTest, SetAndGetParentNotInTree) {
391 EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
392
393 const auto& layerFactory = GetParam();
394
395 auto parent = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
396 auto child1 = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
397 auto child2 = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
398 auto child2_1 = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
399
400 addChild(parent, child1);
401 addChild(child1, child2);
402 addChild(child1, child2_1);
403
404 child2->setFrameRate(FRAME_RATE_VOTE1);
405 commitTransaction();
406 EXPECT_EQ(FRAME_RATE_TREE, parent->getFrameRateForLayerTree());
407 EXPECT_EQ(FRAME_RATE_TREE, child1->getFrameRateForLayerTree());
408 EXPECT_EQ(FRAME_RATE_VOTE1, child2->getFrameRateForLayerTree());
409 EXPECT_EQ(FRAME_RATE_NO_VOTE, child2_1->getFrameRateForLayerTree());
410
411 child2->setFrameRate(FRAME_RATE_NO_VOTE);
412 commitTransaction();
413 EXPECT_EQ(FRAME_RATE_NO_VOTE, parent->getFrameRateForLayerTree());
414 EXPECT_EQ(FRAME_RATE_NO_VOTE, child1->getFrameRateForLayerTree());
415 EXPECT_EQ(FRAME_RATE_NO_VOTE, child2->getFrameRateForLayerTree());
416 EXPECT_EQ(FRAME_RATE_NO_VOTE, child2_1->getFrameRateForLayerTree());
417}
418
Ady Abraham60e42ea2020-03-09 19:17:31 -0700419INSTANTIATE_TEST_SUITE_P(PerLayerType, SetFrameRateTest,
420 testing::Values(std::make_shared<BufferQueueLayerFactory>(),
421 std::make_shared<BufferStateLayerFactory>(),
422 std::make_shared<EffectLayerFactory>()),
423 PrintToStringParamName);
424
Ady Abrahamdd5bfa92021-01-07 17:56:08 -0800425TEST_F(SetFrameRateTest, ValidateFrameRate) {
Marin Shalamanovc5986772021-03-16 16:09:49 +0100426 EXPECT_TRUE(ValidateFrameRate(60.0f, ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT,
427 ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS, ""));
428 EXPECT_TRUE(ValidateFrameRate(60.0f, ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT,
429 ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS, ""));
430 EXPECT_TRUE(ValidateFrameRate(60.0f, ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT,
431 ANATIVEWINDOW_CHANGE_FRAME_RATE_ALWAYS, ""));
432 EXPECT_TRUE(ValidateFrameRate(60.0f, ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_FIXED_SOURCE,
433 ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS, ""));
434 EXPECT_TRUE(ValidateFrameRate(60.0f, ANATIVEWINDOW_FRAME_RATE_EXACT,
435 ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS, "",
436 /*privileged=*/true));
Ady Abrahamdd5bfa92021-01-07 17:56:08 -0800437
Marin Shalamanovc5986772021-03-16 16:09:49 +0100438 EXPECT_FALSE(ValidateFrameRate(-1, ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT,
439 ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS, ""));
440 EXPECT_FALSE(ValidateFrameRate(1.0f / 0.0f, ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT,
441 ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS, ""));
442 EXPECT_FALSE(ValidateFrameRate(0.0f / 0.0f, ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT,
443 ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS, ""));
Ady Abrahamdd5bfa92021-01-07 17:56:08 -0800444
Marin Shalamanovc5986772021-03-16 16:09:49 +0100445 EXPECT_FALSE(ValidateFrameRate(60.0f, ANATIVEWINDOW_FRAME_RATE_EXACT,
446 ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS, ""));
447
448 // Invalid compatibility
449 EXPECT_FALSE(
450 ValidateFrameRate(60.0f, -1, ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS, ""));
451 EXPECT_FALSE(ValidateFrameRate(60.0f, 2, ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS, ""));
452
453 // Invalid change frame rate strategy
454 EXPECT_FALSE(ValidateFrameRate(60.0f, ANATIVEWINDOW_FRAME_RATE_EXACT, -1, ""));
455 EXPECT_FALSE(ValidateFrameRate(60.0f, ANATIVEWINDOW_FRAME_RATE_EXACT, 2, ""));
Ady Abrahamdd5bfa92021-01-07 17:56:08 -0800456}
457
Ady Abraham44e9f3b2021-02-16 15:22:58 -0800458TEST_P(SetFrameRateTest, SetOnParentActivatesTree) {
459 const auto& layerFactory = GetParam();
460
461 auto parent = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
462 if (!parent->isVisible()) {
463 // This is a hack as all the test layers except EffectLayer are not visible,
464 // but since the logic is unified in Layer, it should be fine.
465 return;
466 }
467
468 auto child = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
469 addChild(parent, child);
470
471 parent->setFrameRate(FRAME_RATE_VOTE1);
472 commitTransaction();
473
Ady Abrahambdda8f02021-04-01 16:06:11 -0700474 mFlinger.mutableScheduler()
475 .mutableLayerHistory()
476 ->record(parent.get(), 0, 0, LayerHistory::LayerUpdateType::Buffer);
477 mFlinger.mutableScheduler()
478 .mutableLayerHistory()
479 ->record(child.get(), 0, 0, LayerHistory::LayerUpdateType::Buffer);
480
Ady Abraham44e9f3b2021-02-16 15:22:58 -0800481 const auto layerHistorySummary =
482 mFlinger.mutableScheduler().mutableLayerHistory()->summarize(0);
483 ASSERT_EQ(2u, layerHistorySummary.size());
484 EXPECT_TRUE(FRAME_RATE_VOTE1.rate.equalsWithMargin(layerHistorySummary[0].desiredRefreshRate));
485 EXPECT_TRUE(FRAME_RATE_VOTE1.rate.equalsWithMargin(layerHistorySummary[1].desiredRefreshRate));
486}
487
Ady Abraham60e42ea2020-03-09 19:17:31 -0700488} // namespace
489} // namespace android