blob: a1e4e25c06d80f35c123551a95c05ff3fd20f4f3 [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"
Ady Abraham60e42ea2020-03-09 19:17:31 -070027#include "Layer.h"
28// TODO(b/129481165): remove the #pragma below and fix conversion issues
29#pragma clang diagnostic pop // ignored "-Wconversion"
Dominik Laskowski6eab42d2021-09-13 14:34:13 -070030#include "FpsOps.h"
Garfield Tan23202892022-03-02 16:10:21 -080031#include "LayerTestUtils.h"
Ady Abraham60e42ea2020-03-09 19:17:31 -070032#include "TestableSurfaceFlinger.h"
33#include "mock/DisplayHardware/MockComposer.h"
Ady Abraham8cb21882020-08-26 18:22:05 -070034#include "mock/MockVsyncController.h"
Ady Abraham60e42ea2020-03-09 19:17:31 -070035
36namespace android {
37
Ady Abraham60e42ea2020-03-09 19:17:31 -070038using testing::DoAll;
39using testing::Mock;
Ady Abraham60e42ea2020-03-09 19:17:31 -070040using testing::SetArgPointee;
41
42using android::Hwc2::IComposer;
43using android::Hwc2::IComposerClient;
44
Dominik Laskowski068173d2021-08-11 17:22:59 -070045using scheduler::LayerHistory;
46
Ady Abraham60e42ea2020-03-09 19:17:31 -070047using FrameRate = Layer::FrameRate;
48using FrameRateCompatibility = Layer::FrameRateCompatibility;
49
Ady Abraham60e42ea2020-03-09 19:17:31 -070050/**
51 * This class tests the behaviour of Layer::SetFrameRate and Layer::GetFrameRate
52 */
Garfield Tan23202892022-03-02 16:10:21 -080053class SetFrameRateTest : public BaseLayerTest {
Ady Abraham60e42ea2020-03-09 19:17:31 -070054protected:
Dominik Laskowski6eab42d2021-09-13 14:34:13 -070055 const FrameRate FRAME_RATE_VOTE1 = FrameRate(67_Hz, FrameRateCompatibility::Default);
56 const FrameRate FRAME_RATE_VOTE2 = FrameRate(14_Hz, FrameRateCompatibility::ExactOrMultiple);
57 const FrameRate FRAME_RATE_VOTE3 = FrameRate(99_Hz, FrameRateCompatibility::NoVote);
58 const FrameRate FRAME_RATE_TREE = FrameRate(Fps(), FrameRateCompatibility::NoVote);
59 const FrameRate FRAME_RATE_NO_VOTE = FrameRate(Fps(), FrameRateCompatibility::Default);
Ady Abraham60e42ea2020-03-09 19:17:31 -070060
61 SetFrameRateTest();
62
Ady Abraham60e42ea2020-03-09 19:17:31 -070063 void addChild(sp<Layer> layer, sp<Layer> child);
64 void removeChild(sp<Layer> layer, sp<Layer> child);
Ady Abraham60e42ea2020-03-09 19:17:31 -070065 void commitTransaction();
66
Ady Abraham60e42ea2020-03-09 19:17:31 -070067 std::vector<sp<Layer>> mLayers;
68};
69
70SetFrameRateTest::SetFrameRateTest() {
71 const ::testing::TestInfo* const test_info =
72 ::testing::UnitTest::GetInstance()->current_test_info();
73 ALOGD("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name());
74
Dominik Laskowski13948602021-03-08 20:48:28 -080075 mFlinger.setupComposer(std::make_unique<Hwc2::mock::Composer>());
Ady Abraham60e42ea2020-03-09 19:17:31 -070076}
Dominik Laskowski13948602021-03-08 20:48:28 -080077
Ady Abraham60e42ea2020-03-09 19:17:31 -070078void SetFrameRateTest::addChild(sp<Layer> layer, sp<Layer> child) {
Ady Abrahamd11bade2022-08-01 16:18:03 -070079 layer->addChild(child);
Ady Abraham60e42ea2020-03-09 19:17:31 -070080}
81
82void SetFrameRateTest::removeChild(sp<Layer> layer, sp<Layer> child) {
Ady Abrahamd11bade2022-08-01 16:18:03 -070083 layer->removeChild(child);
Ady Abraham60e42ea2020-03-09 19:17:31 -070084}
85
Ady Abraham60e42ea2020-03-09 19:17:31 -070086void SetFrameRateTest::commitTransaction() {
87 for (auto layer : mLayers) {
Vishnu Nairc1d19d72023-08-10 12:35:11 -070088 layer->commitTransaction();
Ady Abraham60e42ea2020-03-09 19:17:31 -070089 }
90}
91
Ady Abraham60e42ea2020-03-09 19:17:31 -070092namespace {
Dominik Laskowski6eab42d2021-09-13 14:34:13 -070093
Ady Abraham60e42ea2020-03-09 19:17:31 -070094TEST_P(SetFrameRateTest, SetAndGet) {
Dominik Laskowski46f3e3b2021-08-10 11:44:24 -070095 EXPECT_CALL(*mFlinger.scheduler(), scheduleFrame()).Times(1);
Ady Abraham60e42ea2020-03-09 19:17:31 -070096
97 const auto& layerFactory = GetParam();
98
99 auto layer = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
100 layer->setFrameRate(FRAME_RATE_VOTE1);
101 commitTransaction();
102 EXPECT_EQ(FRAME_RATE_VOTE1, layer->getFrameRateForLayerTree());
103}
104
105TEST_P(SetFrameRateTest, SetAndGetParent) {
Dominik Laskowski46f3e3b2021-08-10 11:44:24 -0700106 EXPECT_CALL(*mFlinger.scheduler(), scheduleFrame()).Times(1);
Ady Abraham60e42ea2020-03-09 19:17:31 -0700107
108 const auto& layerFactory = GetParam();
109
110 auto parent = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
111 auto child1 = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
112 auto child2 = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
113
114 addChild(parent, child1);
115 addChild(child1, child2);
116
117 child2->setFrameRate(FRAME_RATE_VOTE1);
118 commitTransaction();
119 EXPECT_EQ(FRAME_RATE_TREE, parent->getFrameRateForLayerTree());
120 EXPECT_EQ(FRAME_RATE_TREE, child1->getFrameRateForLayerTree());
121 EXPECT_EQ(FRAME_RATE_VOTE1, child2->getFrameRateForLayerTree());
122
123 child2->setFrameRate(FRAME_RATE_NO_VOTE);
124 commitTransaction();
125 EXPECT_EQ(FRAME_RATE_NO_VOTE, parent->getFrameRateForLayerTree());
126 EXPECT_EQ(FRAME_RATE_NO_VOTE, child1->getFrameRateForLayerTree());
127 EXPECT_EQ(FRAME_RATE_NO_VOTE, child2->getFrameRateForLayerTree());
128}
129
130TEST_P(SetFrameRateTest, SetAndGetParentAllVote) {
Dominik Laskowski46f3e3b2021-08-10 11:44:24 -0700131 EXPECT_CALL(*mFlinger.scheduler(), scheduleFrame()).Times(1);
Ady Abraham60e42ea2020-03-09 19:17:31 -0700132
133 const auto& layerFactory = GetParam();
134
135 auto parent = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
136 auto child1 = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
137 auto child2 = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
138
139 addChild(parent, child1);
140 addChild(child1, child2);
141
142 child2->setFrameRate(FRAME_RATE_VOTE1);
143 child1->setFrameRate(FRAME_RATE_VOTE2);
144 parent->setFrameRate(FRAME_RATE_VOTE3);
145 commitTransaction();
146 EXPECT_EQ(FRAME_RATE_VOTE3, parent->getFrameRateForLayerTree());
147 EXPECT_EQ(FRAME_RATE_VOTE2, child1->getFrameRateForLayerTree());
148 EXPECT_EQ(FRAME_RATE_VOTE1, child2->getFrameRateForLayerTree());
149
150 child2->setFrameRate(FRAME_RATE_NO_VOTE);
151 commitTransaction();
152 EXPECT_EQ(FRAME_RATE_VOTE3, parent->getFrameRateForLayerTree());
153 EXPECT_EQ(FRAME_RATE_VOTE2, child1->getFrameRateForLayerTree());
Ady Abrahamf467f892020-07-31 16:01:53 -0700154 EXPECT_EQ(FRAME_RATE_VOTE2, child2->getFrameRateForLayerTree());
Ady Abraham60e42ea2020-03-09 19:17:31 -0700155
156 child1->setFrameRate(FRAME_RATE_NO_VOTE);
157 commitTransaction();
158 EXPECT_EQ(FRAME_RATE_VOTE3, parent->getFrameRateForLayerTree());
Ady Abrahamf467f892020-07-31 16:01:53 -0700159 EXPECT_EQ(FRAME_RATE_VOTE3, child1->getFrameRateForLayerTree());
160 EXPECT_EQ(FRAME_RATE_VOTE3, child2->getFrameRateForLayerTree());
Ady Abraham60e42ea2020-03-09 19:17:31 -0700161
162 parent->setFrameRate(FRAME_RATE_NO_VOTE);
163 commitTransaction();
164 EXPECT_EQ(FRAME_RATE_NO_VOTE, parent->getFrameRateForLayerTree());
165 EXPECT_EQ(FRAME_RATE_NO_VOTE, child1->getFrameRateForLayerTree());
166 EXPECT_EQ(FRAME_RATE_NO_VOTE, child2->getFrameRateForLayerTree());
167}
168
169TEST_P(SetFrameRateTest, SetAndGetChild) {
Dominik Laskowski46f3e3b2021-08-10 11:44:24 -0700170 EXPECT_CALL(*mFlinger.scheduler(), scheduleFrame()).Times(1);
Ady Abraham60e42ea2020-03-09 19:17:31 -0700171
172 const auto& layerFactory = GetParam();
173
174 auto parent = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
175 auto child1 = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
176 auto child2 = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
177
178 addChild(parent, child1);
179 addChild(child1, child2);
180
181 parent->setFrameRate(FRAME_RATE_VOTE1);
182 commitTransaction();
183 EXPECT_EQ(FRAME_RATE_VOTE1, parent->getFrameRateForLayerTree());
Ady Abrahamf467f892020-07-31 16:01:53 -0700184 EXPECT_EQ(FRAME_RATE_VOTE1, child1->getFrameRateForLayerTree());
185 EXPECT_EQ(FRAME_RATE_VOTE1, child2->getFrameRateForLayerTree());
Ady Abraham60e42ea2020-03-09 19:17:31 -0700186
187 parent->setFrameRate(FRAME_RATE_NO_VOTE);
188 commitTransaction();
189 EXPECT_EQ(FRAME_RATE_NO_VOTE, parent->getFrameRateForLayerTree());
190 EXPECT_EQ(FRAME_RATE_NO_VOTE, child1->getFrameRateForLayerTree());
191 EXPECT_EQ(FRAME_RATE_NO_VOTE, child2->getFrameRateForLayerTree());
192}
193
194TEST_P(SetFrameRateTest, SetAndGetChildAllVote) {
Dominik Laskowski46f3e3b2021-08-10 11:44:24 -0700195 EXPECT_CALL(*mFlinger.scheduler(), scheduleFrame()).Times(1);
Ady Abraham60e42ea2020-03-09 19:17:31 -0700196
197 const auto& layerFactory = GetParam();
198
199 auto parent = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
200 auto child1 = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
201 auto child2 = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
202
203 addChild(parent, child1);
204 addChild(child1, child2);
205
206 child2->setFrameRate(FRAME_RATE_VOTE1);
207 child1->setFrameRate(FRAME_RATE_VOTE2);
208 parent->setFrameRate(FRAME_RATE_VOTE3);
209 commitTransaction();
210 EXPECT_EQ(FRAME_RATE_VOTE3, parent->getFrameRateForLayerTree());
211 EXPECT_EQ(FRAME_RATE_VOTE2, child1->getFrameRateForLayerTree());
212 EXPECT_EQ(FRAME_RATE_VOTE1, child2->getFrameRateForLayerTree());
213
214 parent->setFrameRate(FRAME_RATE_NO_VOTE);
215 commitTransaction();
216 EXPECT_EQ(FRAME_RATE_TREE, parent->getFrameRateForLayerTree());
217 EXPECT_EQ(FRAME_RATE_VOTE2, child1->getFrameRateForLayerTree());
218 EXPECT_EQ(FRAME_RATE_VOTE1, child2->getFrameRateForLayerTree());
219
220 child1->setFrameRate(FRAME_RATE_NO_VOTE);
221 commitTransaction();
222 EXPECT_EQ(FRAME_RATE_TREE, parent->getFrameRateForLayerTree());
223 EXPECT_EQ(FRAME_RATE_TREE, child1->getFrameRateForLayerTree());
224 EXPECT_EQ(FRAME_RATE_VOTE1, child2->getFrameRateForLayerTree());
225
226 child2->setFrameRate(FRAME_RATE_NO_VOTE);
227 commitTransaction();
228 EXPECT_EQ(FRAME_RATE_NO_VOTE, parent->getFrameRateForLayerTree());
229 EXPECT_EQ(FRAME_RATE_NO_VOTE, child1->getFrameRateForLayerTree());
230 EXPECT_EQ(FRAME_RATE_NO_VOTE, child2->getFrameRateForLayerTree());
231}
232
233TEST_P(SetFrameRateTest, SetAndGetChildAddAfterVote) {
Dominik Laskowski46f3e3b2021-08-10 11:44:24 -0700234 EXPECT_CALL(*mFlinger.scheduler(), scheduleFrame()).Times(1);
Ady Abraham60e42ea2020-03-09 19:17:31 -0700235
236 const auto& layerFactory = GetParam();
237
238 auto parent = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
239 auto child1 = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
240 auto child2 = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
241
242 addChild(parent, child1);
243
244 parent->setFrameRate(FRAME_RATE_VOTE1);
245 commitTransaction();
246 EXPECT_EQ(FRAME_RATE_VOTE1, parent->getFrameRateForLayerTree());
Ady Abrahamf467f892020-07-31 16:01:53 -0700247 EXPECT_EQ(FRAME_RATE_VOTE1, child1->getFrameRateForLayerTree());
Ady Abraham60e42ea2020-03-09 19:17:31 -0700248 EXPECT_EQ(FRAME_RATE_NO_VOTE, child2->getFrameRateForLayerTree());
249
250 addChild(child1, child2);
251 commitTransaction();
252 EXPECT_EQ(FRAME_RATE_VOTE1, parent->getFrameRateForLayerTree());
Ady Abrahamf467f892020-07-31 16:01:53 -0700253 EXPECT_EQ(FRAME_RATE_VOTE1, child1->getFrameRateForLayerTree());
254 EXPECT_EQ(FRAME_RATE_VOTE1, child2->getFrameRateForLayerTree());
Ady Abraham60e42ea2020-03-09 19:17:31 -0700255
256 parent->setFrameRate(FRAME_RATE_NO_VOTE);
257 commitTransaction();
258 EXPECT_EQ(FRAME_RATE_NO_VOTE, parent->getFrameRateForLayerTree());
259 EXPECT_EQ(FRAME_RATE_NO_VOTE, child1->getFrameRateForLayerTree());
260 EXPECT_EQ(FRAME_RATE_NO_VOTE, child2->getFrameRateForLayerTree());
261}
262
263TEST_P(SetFrameRateTest, SetAndGetChildRemoveAfterVote) {
Dominik Laskowski46f3e3b2021-08-10 11:44:24 -0700264 EXPECT_CALL(*mFlinger.scheduler(), scheduleFrame()).Times(1);
Ady Abraham60e42ea2020-03-09 19:17:31 -0700265
266 const auto& layerFactory = GetParam();
267
268 auto parent = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
269 auto child1 = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
270 auto child2 = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
271
272 addChild(parent, child1);
273 addChild(child1, child2);
274
275 parent->setFrameRate(FRAME_RATE_VOTE1);
276 commitTransaction();
277 EXPECT_EQ(FRAME_RATE_VOTE1, parent->getFrameRateForLayerTree());
Ady Abrahamf467f892020-07-31 16:01:53 -0700278 EXPECT_EQ(FRAME_RATE_VOTE1, child1->getFrameRateForLayerTree());
279 EXPECT_EQ(FRAME_RATE_VOTE1, child2->getFrameRateForLayerTree());
Ady Abraham60e42ea2020-03-09 19:17:31 -0700280
281 removeChild(child1, child2);
282 commitTransaction();
283 EXPECT_EQ(FRAME_RATE_VOTE1, parent->getFrameRateForLayerTree());
Ady Abrahamf467f892020-07-31 16:01:53 -0700284 EXPECT_EQ(FRAME_RATE_VOTE1, child1->getFrameRateForLayerTree());
Ady Abraham60e42ea2020-03-09 19:17:31 -0700285 EXPECT_EQ(FRAME_RATE_NO_VOTE, child2->getFrameRateForLayerTree());
286
287 parent->setFrameRate(FRAME_RATE_NO_VOTE);
288 commitTransaction();
289 EXPECT_EQ(FRAME_RATE_NO_VOTE, parent->getFrameRateForLayerTree());
290 EXPECT_EQ(FRAME_RATE_NO_VOTE, child1->getFrameRateForLayerTree());
291 EXPECT_EQ(FRAME_RATE_NO_VOTE, child2->getFrameRateForLayerTree());
292}
293
294TEST_P(SetFrameRateTest, SetAndGetParentNotInTree) {
Dominik Laskowski46f3e3b2021-08-10 11:44:24 -0700295 EXPECT_CALL(*mFlinger.scheduler(), scheduleFrame()).Times(1);
Ady Abraham60e42ea2020-03-09 19:17:31 -0700296
297 const auto& layerFactory = GetParam();
298
299 auto parent = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
300 auto child1 = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
301 auto child2 = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
302 auto child2_1 = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
303
304 addChild(parent, child1);
305 addChild(child1, child2);
306 addChild(child1, child2_1);
307
308 child2->setFrameRate(FRAME_RATE_VOTE1);
309 commitTransaction();
310 EXPECT_EQ(FRAME_RATE_TREE, parent->getFrameRateForLayerTree());
311 EXPECT_EQ(FRAME_RATE_TREE, child1->getFrameRateForLayerTree());
312 EXPECT_EQ(FRAME_RATE_VOTE1, child2->getFrameRateForLayerTree());
313 EXPECT_EQ(FRAME_RATE_NO_VOTE, child2_1->getFrameRateForLayerTree());
314
315 child2->setFrameRate(FRAME_RATE_NO_VOTE);
316 commitTransaction();
317 EXPECT_EQ(FRAME_RATE_NO_VOTE, parent->getFrameRateForLayerTree());
318 EXPECT_EQ(FRAME_RATE_NO_VOTE, child1->getFrameRateForLayerTree());
319 EXPECT_EQ(FRAME_RATE_NO_VOTE, child2->getFrameRateForLayerTree());
320 EXPECT_EQ(FRAME_RATE_NO_VOTE, child2_1->getFrameRateForLayerTree());
321}
322
Ady Abraham60e42ea2020-03-09 19:17:31 -0700323INSTANTIATE_TEST_SUITE_P(PerLayerType, SetFrameRateTest,
Robert Carr80b1b1c2021-09-29 12:44:17 -0700324 testing::Values(std::make_shared<BufferStateLayerFactory>(),
Ady Abraham60e42ea2020-03-09 19:17:31 -0700325 std::make_shared<EffectLayerFactory>()),
326 PrintToStringParamName);
327
Ady Abrahamdd5bfa92021-01-07 17:56:08 -0800328TEST_F(SetFrameRateTest, ValidateFrameRate) {
Marin Shalamanovc5986772021-03-16 16:09:49 +0100329 EXPECT_TRUE(ValidateFrameRate(60.0f, ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT,
330 ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS, ""));
331 EXPECT_TRUE(ValidateFrameRate(60.0f, ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT,
332 ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS, ""));
333 EXPECT_TRUE(ValidateFrameRate(60.0f, ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT,
334 ANATIVEWINDOW_CHANGE_FRAME_RATE_ALWAYS, ""));
335 EXPECT_TRUE(ValidateFrameRate(60.0f, ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_FIXED_SOURCE,
336 ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS, ""));
Dominik Laskowski1f6fc702022-03-21 08:34:50 -0700337
338 // Privileged APIs.
339 EXPECT_FALSE(ValidateFrameRate(60.0f, ANATIVEWINDOW_FRAME_RATE_EXACT,
340 ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS, ""));
341 EXPECT_FALSE(ValidateFrameRate(0.0f, ANATIVEWINDOW_FRAME_RATE_NO_VOTE,
342 ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS, ""));
343
344 constexpr bool kPrivileged = true;
Marin Shalamanovc5986772021-03-16 16:09:49 +0100345 EXPECT_TRUE(ValidateFrameRate(60.0f, ANATIVEWINDOW_FRAME_RATE_EXACT,
346 ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS, "",
Dominik Laskowski1f6fc702022-03-21 08:34:50 -0700347 kPrivileged));
348 EXPECT_TRUE(ValidateFrameRate(0.0f, ANATIVEWINDOW_FRAME_RATE_NO_VOTE,
349 ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS, "",
350 kPrivileged));
Ady Abrahamdd5bfa92021-01-07 17:56:08 -0800351
Dominik Laskowski1f6fc702022-03-21 08:34:50 -0700352 // Invalid frame rate.
Marin Shalamanovc5986772021-03-16 16:09:49 +0100353 EXPECT_FALSE(ValidateFrameRate(-1, ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT,
354 ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS, ""));
355 EXPECT_FALSE(ValidateFrameRate(1.0f / 0.0f, ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT,
356 ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS, ""));
357 EXPECT_FALSE(ValidateFrameRate(0.0f / 0.0f, ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT,
358 ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS, ""));
Ady Abrahamdd5bfa92021-01-07 17:56:08 -0800359
Dominik Laskowski1f6fc702022-03-21 08:34:50 -0700360 // Invalid compatibility.
Marin Shalamanovc5986772021-03-16 16:09:49 +0100361 EXPECT_FALSE(
362 ValidateFrameRate(60.0f, -1, ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS, ""));
363 EXPECT_FALSE(ValidateFrameRate(60.0f, 2, ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS, ""));
364
Dominik Laskowski1f6fc702022-03-21 08:34:50 -0700365 // Invalid change frame rate strategy.
Marin Shalamanovc5986772021-03-16 16:09:49 +0100366 EXPECT_FALSE(ValidateFrameRate(60.0f, ANATIVEWINDOW_FRAME_RATE_EXACT, -1, ""));
367 EXPECT_FALSE(ValidateFrameRate(60.0f, ANATIVEWINDOW_FRAME_RATE_EXACT, 2, ""));
Ady Abrahamdd5bfa92021-01-07 17:56:08 -0800368}
369
Ady Abraham44e9f3b2021-02-16 15:22:58 -0800370TEST_P(SetFrameRateTest, SetOnParentActivatesTree) {
371 const auto& layerFactory = GetParam();
372
373 auto parent = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
Ady Abraham44e9f3b2021-02-16 15:22:58 -0800374
375 auto child = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
376 addChild(parent, child);
377
378 parent->setFrameRate(FRAME_RATE_VOTE1);
379 commitTransaction();
380
Dominik Laskowski9c93d602021-10-07 19:38:26 -0700381 auto& history = mFlinger.mutableScheduler().mutableLayerHistory();
Vishnu Nairef68d6d2023-02-28 06:18:27 +0000382 history.record(parent->getSequence(), parent->getLayerProps(), 0, 0,
383 LayerHistory::LayerUpdateType::Buffer);
384 history.record(child->getSequence(), child->getLayerProps(), 0, 0,
385 LayerHistory::LayerUpdateType::Buffer);
Ady Abrahambdda8f02021-04-01 16:06:11 -0700386
Dominik Laskowskid82e0f02022-10-26 15:23:04 -0400387 const auto selectorPtr = mFlinger.mutableScheduler().refreshRateSelector();
388 const auto summary = history.summarize(*selectorPtr, 0);
Dominik Laskowski9c93d602021-10-07 19:38:26 -0700389
390 ASSERT_EQ(2u, summary.size());
391 EXPECT_EQ(FRAME_RATE_VOTE1.rate, summary[0].desiredRefreshRate);
392 EXPECT_EQ(FRAME_RATE_VOTE1.rate, summary[1].desiredRefreshRate);
Ady Abraham44e9f3b2021-02-16 15:22:58 -0800393}
394
Ady Abrahama850c182021-08-04 13:04:37 -0700395TEST_P(SetFrameRateTest, addChildForParentWithTreeVote) {
Dominik Laskowski46f3e3b2021-08-10 11:44:24 -0700396 EXPECT_CALL(*mFlinger.scheduler(), scheduleFrame()).Times(1);
Ady Abrahama850c182021-08-04 13:04:37 -0700397
398 const auto& layerFactory = GetParam();
399
400 const auto parent = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
401 const auto child1 = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
402 const auto child2 = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
403 const auto childOfChild1 = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
404
405 addChild(parent, child1);
406 addChild(child1, childOfChild1);
407
408 childOfChild1->setFrameRate(FRAME_RATE_VOTE1);
409 commitTransaction();
410 EXPECT_EQ(FRAME_RATE_TREE, parent->getFrameRateForLayerTree());
411 EXPECT_EQ(FRAME_RATE_TREE, child1->getFrameRateForLayerTree());
412 EXPECT_EQ(FRAME_RATE_VOTE1, childOfChild1->getFrameRateForLayerTree());
413 EXPECT_EQ(FRAME_RATE_NO_VOTE, child2->getFrameRateForLayerTree());
414
415 addChild(parent, child2);
416 commitTransaction();
417 EXPECT_EQ(FRAME_RATE_TREE, parent->getFrameRateForLayerTree());
418 EXPECT_EQ(FRAME_RATE_TREE, child1->getFrameRateForLayerTree());
419 EXPECT_EQ(FRAME_RATE_VOTE1, childOfChild1->getFrameRateForLayerTree());
420 EXPECT_EQ(FRAME_RATE_NO_VOTE, child2->getFrameRateForLayerTree());
421
422 childOfChild1->setFrameRate(FRAME_RATE_NO_VOTE);
423 commitTransaction();
424 EXPECT_EQ(FRAME_RATE_NO_VOTE, parent->getFrameRateForLayerTree());
425 EXPECT_EQ(FRAME_RATE_NO_VOTE, child1->getFrameRateForLayerTree());
426 EXPECT_EQ(FRAME_RATE_NO_VOTE, childOfChild1->getFrameRateForLayerTree());
427 EXPECT_EQ(FRAME_RATE_NO_VOTE, child2->getFrameRateForLayerTree());
428}
429
Ady Abraham60e42ea2020-03-09 19:17:31 -0700430} // namespace
431} // namespace android