blob: ae9a89c0b628b190e86b07c2108c8fb35ea53429 [file] [log] [blame]
Vishnu Nair8fc721b2022-12-22 20:06:32 +00001/*
2 * Copyright 2022 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#include <gmock/gmock.h>
18#include <gtest/gtest.h>
19
Rachel Lee45681982024-03-14 18:40:15 -070020#include <common/test/FlagUtils.h>
Vishnu Nair0808ae62023-08-07 21:42:42 -070021#include <renderengine/mock/FakeExternalTexture.h>
22
Vishnu Nair8fc721b2022-12-22 20:06:32 +000023#include "FrontEnd/LayerHierarchy.h"
24#include "FrontEnd/LayerLifecycleManager.h"
25#include "FrontEnd/LayerSnapshotBuilder.h"
Vishnu Nair3d8565a2023-06-30 07:23:24 +000026#include "Layer.h"
Vishnu Nair8fc721b2022-12-22 20:06:32 +000027#include "LayerHierarchyTest.h"
Vishnu Nair3996ee32023-08-14 04:32:31 +000028#include "ui/GraphicTypes.h"
Vishnu Nair8fc721b2022-12-22 20:06:32 +000029
Rachel Lee45681982024-03-14 18:40:15 -070030#include <com_android_graphics_surfaceflinger_flags.h>
31
Vishnu Nair8fc721b2022-12-22 20:06:32 +000032#define UPDATE_AND_VERIFY(BUILDER, ...) \
33 ({ \
34 SCOPED_TRACE(""); \
35 updateAndVerify((BUILDER), /*displayChanges=*/false, __VA_ARGS__); \
36 })
37
38#define UPDATE_AND_VERIFY_WITH_DISPLAY_CHANGES(BUILDER, ...) \
39 ({ \
40 SCOPED_TRACE(""); \
41 updateAndVerify((BUILDER), /*displayChanges=*/true, __VA_ARGS__); \
42 })
43
44namespace android::surfaceflinger::frontend {
45
Vishnu Naircfb2d252023-01-19 04:44:02 +000046using ftl::Flags;
47using namespace ftl::flag_operators;
Rachel Lee45681982024-03-14 18:40:15 -070048using namespace com::android::graphics::surfaceflinger;
Vishnu Naircfb2d252023-01-19 04:44:02 +000049
Vishnu Nair8fc721b2022-12-22 20:06:32 +000050// To run test:
51/**
52 mp :libsurfaceflinger_unittest && adb sync; adb shell \
53 /data/nativetest/libsurfaceflinger_unittest/libsurfaceflinger_unittest \
54 --gtest_filter="LayerSnapshotTest.*" --gtest_brief=1
55*/
56
Vishnu Nair47b7bb42023-09-29 16:27:33 -070057class LayerSnapshotTest : public LayerSnapshotTestBase {
Vishnu Nair8fc721b2022-12-22 20:06:32 +000058protected:
Vishnu Nair47b7bb42023-09-29 16:27:33 -070059 LayerSnapshotTest() : LayerSnapshotTestBase() {
Vishnu Nair8fc721b2022-12-22 20:06:32 +000060 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
61 }
62
Vishnu Nair0808ae62023-08-07 21:42:42 -070063 void update(LayerSnapshotBuilder& actualBuilder, LayerSnapshotBuilder::Args& args) {
Vishnu Nair8fc721b2022-12-22 20:06:32 +000064 if (mLifecycleManager.getGlobalChanges().test(RequestedLayerState::Changes::Hierarchy)) {
Vishnu Naira0292282023-12-16 14:32:00 -080065 mHierarchyBuilder.update(mLifecycleManager);
Vishnu Nair8fc721b2022-12-22 20:06:32 +000066 }
Vishnu Nair0808ae62023-08-07 21:42:42 -070067 args.root = mHierarchyBuilder.getHierarchy();
68 actualBuilder.update(args);
69 }
70
Chavi Weingarten92c7d8c2024-01-19 23:25:45 +000071 void update(LayerSnapshotBuilder& actualBuilder) {
72 LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(),
73 .layerLifecycleManager = mLifecycleManager,
74 .includeMetadata = false,
75 .displays = mFrontEndDisplayInfos,
76 .globalShadowSettings = globalShadowSettings,
77 .supportsBlur = true,
78 .supportedLayerGenericMetadata = {},
79 .genericLayerMetadataKeyMap = {}};
80 update(actualBuilder, args);
81 }
82
Vishnu Nair0808ae62023-08-07 21:42:42 -070083 void updateAndVerify(LayerSnapshotBuilder& actualBuilder, bool hasDisplayChanges,
84 const std::vector<uint32_t> expectedVisibleLayerIdsInZOrder) {
Vishnu Nairc765c6c2023-02-23 00:08:01 +000085 LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(),
86 .layerLifecycleManager = mLifecycleManager,
87 .includeMetadata = false,
88 .displays = mFrontEndDisplayInfos,
89 .displayChanges = hasDisplayChanges,
90 .globalShadowSettings = globalShadowSettings,
Vishnu Nair444f3952023-04-11 13:01:02 -070091 .supportsBlur = true,
Vishnu Nairc765c6c2023-02-23 00:08:01 +000092 .supportedLayerGenericMetadata = {},
93 .genericLayerMetadataKeyMap = {}};
Vishnu Nair0808ae62023-08-07 21:42:42 -070094 update(actualBuilder, args);
Vishnu Nair8fc721b2022-12-22 20:06:32 +000095
96 // rebuild layer snapshots from scratch and verify that it matches the updated state.
97 LayerSnapshotBuilder expectedBuilder(args);
98 mLifecycleManager.commitChanges();
99 ASSERT_TRUE(expectedBuilder.getSnapshots().size() > 0);
100 ASSERT_TRUE(actualBuilder.getSnapshots().size() > 0);
101
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000102 std::vector<uint32_t> actualVisibleLayerIdsInZOrder;
Vishnu Naircfb2d252023-01-19 04:44:02 +0000103 actualBuilder.forEachVisibleSnapshot(
104 [&actualVisibleLayerIdsInZOrder](const LayerSnapshot& snapshot) {
105 actualVisibleLayerIdsInZOrder.push_back(snapshot.path.id);
106 });
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000107 EXPECT_EQ(expectedVisibleLayerIdsInZOrder, actualVisibleLayerIdsInZOrder);
108 }
109
110 LayerSnapshot* getSnapshot(uint32_t layerId) { return mSnapshotBuilder.getSnapshot(layerId); }
Vishnu Nair92990e22023-02-24 20:01:05 +0000111 LayerSnapshot* getSnapshot(const LayerHierarchy::TraversalPath path) {
112 return mSnapshotBuilder.getSnapshot(path);
113 }
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000114 LayerSnapshotBuilder mSnapshotBuilder;
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000115 static const std::vector<uint32_t> STARTING_ZORDER;
116};
117const std::vector<uint32_t> LayerSnapshotTest::STARTING_ZORDER = {1, 11, 111, 12, 121,
118 122, 1221, 13, 2};
119
120TEST_F(LayerSnapshotTest, buildSnapshot) {
Vishnu Nairc765c6c2023-02-23 00:08:01 +0000121 LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(),
122 .layerLifecycleManager = mLifecycleManager,
123 .includeMetadata = false,
124 .displays = mFrontEndDisplayInfos,
125 .globalShadowSettings = globalShadowSettings,
126 .supportedLayerGenericMetadata = {},
127 .genericLayerMetadataKeyMap = {}};
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000128 LayerSnapshotBuilder builder(args);
129}
130
131TEST_F(LayerSnapshotTest, updateSnapshot) {
Vishnu Nairc765c6c2023-02-23 00:08:01 +0000132 LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(),
133 .layerLifecycleManager = mLifecycleManager,
134 .includeMetadata = false,
135 .displays = mFrontEndDisplayInfos,
136 .globalShadowSettings = globalShadowSettings,
137 .supportedLayerGenericMetadata = {},
138 .genericLayerMetadataKeyMap = {}
139
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000140 };
141
142 LayerSnapshotBuilder builder;
143 builder.update(args);
144}
145
146// update using parent snapshot data
147TEST_F(LayerSnapshotTest, croppedByParent) {
148 /// MAKE ALL LAYERS VISIBLE BY DEFAULT
149 DisplayInfo info;
150 info.info.logicalHeight = 100;
151 info.info.logicalWidth = 200;
152 mFrontEndDisplayInfos.emplace_or_replace(ui::LayerStack::fromValue(1), info);
153 Rect layerCrop(0, 0, 10, 20);
154 setCrop(11, layerCrop);
155 EXPECT_TRUE(mLifecycleManager.getGlobalChanges().test(RequestedLayerState::Changes::Geometry));
156 UPDATE_AND_VERIFY_WITH_DISPLAY_CHANGES(mSnapshotBuilder, STARTING_ZORDER);
157 EXPECT_EQ(getSnapshot(11)->geomCrop, layerCrop);
158 EXPECT_EQ(getSnapshot(111)->geomLayerBounds, layerCrop.toFloatRect());
159 float maxHeight = static_cast<float>(info.info.logicalHeight * 10);
160 float maxWidth = static_cast<float>(info.info.logicalWidth * 10);
161
162 FloatRect maxDisplaySize(-maxWidth, -maxHeight, maxWidth, maxHeight);
163 EXPECT_EQ(getSnapshot(1)->geomLayerBounds, maxDisplaySize);
164}
165
166// visibility tests
167TEST_F(LayerSnapshotTest, newLayerHiddenByPolicy) {
168 createLayer(112, 11);
169 hideLayer(112);
170 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
171
172 showLayer(112);
173 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 11, 111, 112, 12, 121, 122, 1221, 13, 2});
174}
175
176TEST_F(LayerSnapshotTest, hiddenByParent) {
177 hideLayer(11);
178 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 13, 2});
179}
180
181TEST_F(LayerSnapshotTest, reparentShowsChild) {
182 hideLayer(11);
183 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 13, 2});
184
185 showLayer(11);
186 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
187}
188
189TEST_F(LayerSnapshotTest, reparentHidesChild) {
190 hideLayer(11);
191 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 13, 2});
192
193 reparentLayer(121, 11);
194 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 122, 1221, 13, 2});
195}
196
197TEST_F(LayerSnapshotTest, unHidingUpdatesSnapshot) {
198 hideLayer(11);
199 Rect crop(1, 2, 3, 4);
200 setCrop(111, crop);
201 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 13, 2});
202
203 showLayer(11);
204 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
205 EXPECT_EQ(getSnapshot(111)->geomLayerBounds, crop.toFloatRect());
206}
207
208TEST_F(LayerSnapshotTest, childBehindParentCanBeHiddenByParent) {
209 setZ(111, -1);
210 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 111, 11, 12, 121, 122, 1221, 13, 2});
211
212 hideLayer(11);
213 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 13, 2});
214}
215
216// relative tests
217TEST_F(LayerSnapshotTest, RelativeParentCanHideChild) {
218 reparentRelativeLayer(13, 11);
219 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 11, 13, 111, 12, 121, 122, 1221, 2});
220
221 hideLayer(11);
222 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 2});
223}
224
225TEST_F(LayerSnapshotTest, ReparentingToHiddenRelativeParentHidesChild) {
226 hideLayer(11);
227 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 13, 2});
228 reparentRelativeLayer(13, 11);
229 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 2});
230}
231
232TEST_F(LayerSnapshotTest, AlphaInheritedByChildren) {
233 setAlpha(1, 0.5);
234 setAlpha(122, 0.5);
235 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
Vishnu Naira02943f2023-06-03 13:44:46 -0700236 EXPECT_EQ(getSnapshot(1)->alpha, 0.5f);
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000237 EXPECT_EQ(getSnapshot(12)->alpha, 0.5f);
238 EXPECT_EQ(getSnapshot(1221)->alpha, 0.25f);
239}
240
241// Change states
242TEST_F(LayerSnapshotTest, UpdateClearsPreviousChangeStates) {
243 setCrop(1, Rect(1, 2, 3, 4));
244 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
Vishnu Naira02943f2023-06-03 13:44:46 -0700245 EXPECT_TRUE(getSnapshot(1)->changes.test(RequestedLayerState::Changes::Geometry));
246 EXPECT_TRUE(getSnapshot(11)->changes.test(RequestedLayerState::Changes::Geometry));
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000247 setCrop(2, Rect(1, 2, 3, 4));
248 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
Vishnu Naira02943f2023-06-03 13:44:46 -0700249 EXPECT_TRUE(getSnapshot(2)->changes.test(RequestedLayerState::Changes::Geometry));
250 EXPECT_FALSE(getSnapshot(1)->changes.test(RequestedLayerState::Changes::Geometry));
251 EXPECT_FALSE(getSnapshot(11)->changes.test(RequestedLayerState::Changes::Geometry));
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000252}
253
254TEST_F(LayerSnapshotTest, FastPathClearsPreviousChangeStates) {
255 setColor(11, {1._hf, 0._hf, 0._hf});
256 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
Vishnu Naira02943f2023-06-03 13:44:46 -0700257 EXPECT_EQ(getSnapshot(11)->changes, RequestedLayerState::Changes::Content);
258 EXPECT_EQ(getSnapshot(11)->clientChanges, layer_state_t::eColorChanged);
259 EXPECT_EQ(getSnapshot(1)->changes.get(), 0u);
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000260 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
Vishnu Naira02943f2023-06-03 13:44:46 -0700261 EXPECT_EQ(getSnapshot(11)->changes.get(), 0u);
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000262}
263
264TEST_F(LayerSnapshotTest, FastPathSetsChangeFlagToContent) {
265 setColor(1, {1._hf, 0._hf, 0._hf});
266 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
267 EXPECT_EQ(getSnapshot(1)->changes, RequestedLayerState::Changes::Content);
Vishnu Naira02943f2023-06-03 13:44:46 -0700268 EXPECT_EQ(getSnapshot(1)->clientChanges, layer_state_t::eColorChanged);
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000269}
270
Vishnu Naircfb2d252023-01-19 04:44:02 +0000271TEST_F(LayerSnapshotTest, GameMode) {
272 std::vector<TransactionState> transactions;
273 transactions.emplace_back();
274 transactions.back().states.push_back({});
275 transactions.back().states.front().state.what = layer_state_t::eMetadataChanged;
276 transactions.back().states.front().state.metadata = LayerMetadata();
277 transactions.back().states.front().state.metadata.setInt32(METADATA_GAME_MODE, 42);
Vishnu Nair1391de22023-03-05 19:56:14 -0800278 transactions.back().states.front().layerId = 1;
Vishnu Naircfb2d252023-01-19 04:44:02 +0000279 transactions.back().states.front().state.layerId = static_cast<int32_t>(1);
280 mLifecycleManager.applyTransactions(transactions);
Vishnu Naira02943f2023-06-03 13:44:46 -0700281 EXPECT_EQ(mLifecycleManager.getGlobalChanges(), RequestedLayerState::Changes::GameMode);
Vishnu Naircfb2d252023-01-19 04:44:02 +0000282 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
Vishnu Naira02943f2023-06-03 13:44:46 -0700283 EXPECT_EQ(getSnapshot(1)->clientChanges, layer_state_t::eMetadataChanged);
Vishnu Naircfb2d252023-01-19 04:44:02 +0000284 EXPECT_EQ(static_cast<int32_t>(getSnapshot(1)->gameMode), 42);
285 EXPECT_EQ(static_cast<int32_t>(getSnapshot(11)->gameMode), 42);
286}
287
288TEST_F(LayerSnapshotTest, NoLayerVoteForParentWithChildVotes) {
289 // ROOT
290 // ├── 1
291 // │ ├── 11 (frame rate set)
292 // │ │ └── 111
293 // │ ├── 12
294 // │ │ ├── 121
295 // │ │ └── 122
296 // │ │ └── 1221
297 // │ └── 13
298 // └── 2
299
Vishnu Nair30515cb2023-10-19 21:54:08 -0700300 setFrameRate(11, 90.0, ANATIVEWINDOW_FRAME_RATE_EXACT, ANATIVEWINDOW_CHANGE_FRAME_RATE_ALWAYS);
Vishnu Naircfb2d252023-01-19 04:44:02 +0000301 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
302
Rachel Leece6e0042023-06-27 11:22:54 -0700303 EXPECT_EQ(getSnapshot(11)->frameRate.vote.rate.getIntValue(), 90);
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700304 EXPECT_EQ(getSnapshot(11)->frameRate.vote.type, scheduler::FrameRateCompatibility::Exact);
Rachel Leece6e0042023-06-27 11:22:54 -0700305 EXPECT_EQ(getSnapshot(111)->frameRate.vote.rate.getIntValue(), 90);
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700306 EXPECT_EQ(getSnapshot(111)->frameRate.vote.type, scheduler::FrameRateCompatibility::Exact);
Rachel Leece6e0042023-06-27 11:22:54 -0700307 EXPECT_EQ(getSnapshot(1)->frameRate.vote.rate.getIntValue(), 0);
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700308 EXPECT_EQ(getSnapshot(1)->frameRate.vote.type, scheduler::FrameRateCompatibility::NoVote);
Vishnu Naircfb2d252023-01-19 04:44:02 +0000309}
310
Vishnu Nair30515cb2023-10-19 21:54:08 -0700311TEST_F(LayerSnapshotTest, NoLayerVoteForParentWithChildVotesDoesNotAffectSiblings) {
312 // ROOT
313 // ├── 1 (verify layer has no vote)
314 // │ ├── 11 (frame rate set)
315 // │ │ └── 111
316 // │ ├── 12 (frame rate set)
317 // │ │ ├── 121
318 // │ │ └── 122
319 // │ │ └── 1221
320 // │ └── 13 (verify layer has default vote)
321 // └── 2
322
323 setFrameRate(11, 90.0, ANATIVEWINDOW_FRAME_RATE_EXACT, ANATIVEWINDOW_CHANGE_FRAME_RATE_ALWAYS);
324 setFrameRate(12, 45.0, ANATIVEWINDOW_FRAME_RATE_EXACT, ANATIVEWINDOW_CHANGE_FRAME_RATE_ALWAYS);
325
326 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
327
328 EXPECT_EQ(getSnapshot(11)->frameRate.vote.rate.getIntValue(), 90);
329 EXPECT_EQ(getSnapshot(11)->frameRate.vote.type, scheduler::FrameRateCompatibility::Exact);
330 EXPECT_EQ(getSnapshot(111)->frameRate.vote.rate.getIntValue(), 90);
331 EXPECT_EQ(getSnapshot(111)->frameRate.vote.type, scheduler::FrameRateCompatibility::Exact);
332 EXPECT_EQ(getSnapshot(12)->frameRate.vote.rate.getIntValue(), 45);
333 EXPECT_EQ(getSnapshot(12)->frameRate.vote.type, scheduler::FrameRateCompatibility::Exact);
334 EXPECT_EQ(getSnapshot(121)->frameRate.vote.rate.getIntValue(), 45);
335 EXPECT_EQ(getSnapshot(121)->frameRate.vote.type, scheduler::FrameRateCompatibility::Exact);
336 EXPECT_EQ(getSnapshot(1221)->frameRate.vote.rate.getIntValue(), 45);
337 EXPECT_EQ(getSnapshot(1221)->frameRate.vote.type, scheduler::FrameRateCompatibility::Exact);
338
339 EXPECT_EQ(getSnapshot(1)->frameRate.vote.rate.getIntValue(), 0);
340 EXPECT_EQ(getSnapshot(1)->frameRate.vote.type, scheduler::FrameRateCompatibility::NoVote);
341 EXPECT_EQ(getSnapshot(13)->frameRate.vote.rate.getIntValue(), 0);
342 EXPECT_EQ(getSnapshot(13)->frameRate.vote.type, scheduler::FrameRateCompatibility::Default);
343 EXPECT_EQ(getSnapshot(2)->frameRate.vote.rate.getIntValue(), 0);
344 EXPECT_EQ(getSnapshot(2)->frameRate.vote.type, scheduler::FrameRateCompatibility::Default);
345}
346
Vishnu Naira02943f2023-06-03 13:44:46 -0700347TEST_F(LayerSnapshotTest, CanCropTouchableRegion) {
Vishnu Nair29354ec2023-03-28 18:51:28 -0700348 // ROOT
349 // ├── 1
350 // │ ├── 11
351 // │ │ └── 111 (touchregion set to touch but cropped by layer 13)
352 // │ ├── 12
353 // │ │ ├── 121
354 // │ │ └── 122
355 // │ │ └── 1221
356 // │ └── 13 (crop set to touchCrop)
357 // └── 2
358
359 Rect touchCrop{300, 300, 400, 500};
360 setCrop(13, touchCrop);
361 Region touch{Rect{0, 0, 1000, 1000}};
362 setTouchableRegionCrop(111, touch, /*touchCropId=*/13, /*replaceTouchableRegionWithCrop=*/true);
363 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
364 EXPECT_EQ(getSnapshot({.id = 111})->inputInfo.touchableRegion.bounds(), touchCrop);
365
366 Rect modifiedTouchCrop{100, 300, 400, 700};
367 setCrop(13, modifiedTouchCrop);
368 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
369 EXPECT_EQ(getSnapshot({.id = 111})->inputInfo.touchableRegion.bounds(), modifiedTouchCrop);
370}
371
Chavi Weingarten1ba381e2024-01-09 21:54:11 +0000372TEST_F(LayerSnapshotTest, CanCropTouchableRegionWithDisplayTransform) {
373 DisplayInfo displayInfo;
374 displayInfo.transform = ui::Transform(ui::Transform::RotationFlags::ROT_90, 1000, 1000);
375 mFrontEndDisplayInfos.emplace_or_replace(ui::LayerStack::fromValue(1), displayInfo);
376
377 Rect touchCrop{300, 300, 400, 500};
378 createRootLayer(3);
379 setCrop(3, touchCrop);
380 setLayerStack(3, 1);
381 Region touch{Rect{0, 0, 1000, 1000}};
382 setTouchableRegionCrop(3, touch, /*touchCropId=*/3, /*replaceTouchableRegionWithCrop=*/false);
383
384 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 11, 111, 12, 121, 122, 1221, 13, 2, 3});
385 Rect rotatedCrop = {500, 300, 700, 400};
386 EXPECT_EQ(getSnapshot({.id = 3})->inputInfo.touchableRegion.bounds(), rotatedCrop);
387}
388
Vishnu Nair444f3952023-04-11 13:01:02 -0700389TEST_F(LayerSnapshotTest, blurUpdatesWhenAlphaChanges) {
Vishnu Nair854ce1c2023-08-19 15:00:13 -0700390 int blurRadius = 42;
391 setBackgroundBlurRadius(1221, static_cast<uint32_t>(blurRadius));
Vishnu Nair444f3952023-04-11 13:01:02 -0700392
393 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
394 EXPECT_EQ(getSnapshot({.id = 1221})->backgroundBlurRadius, blurRadius);
395
Vishnu Nair854ce1c2023-08-19 15:00:13 -0700396 blurRadius = 21;
397 setBackgroundBlurRadius(1221, static_cast<uint32_t>(blurRadius));
398 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
399 EXPECT_EQ(getSnapshot({.id = 1221})->backgroundBlurRadius, blurRadius);
400
Vishnu Nair444f3952023-04-11 13:01:02 -0700401 static constexpr float alpha = 0.5;
402 setAlpha(12, alpha);
403 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
Vishnu Nair854ce1c2023-08-19 15:00:13 -0700404 EXPECT_EQ(getSnapshot({.id = 1221})->backgroundBlurRadius,
405 static_cast<int>(static_cast<float>(blurRadius) * alpha));
Vishnu Nair444f3952023-04-11 13:01:02 -0700406}
407
Vishnu Naira9c43762023-01-27 19:10:25 +0000408// Display Mirroring Tests
409// tree with 3 levels of children
410// ROOT (DISPLAY 0)
411// ├── 1
412// │ ├── 11
413// │ │ └── 111
414// │ ├── 12 (has skip screenshot flag)
415// │ │ ├── 121
416// │ │ └── 122
417// │ │ └── 1221
418// │ └── 13
419// └── 2
420// ROOT (DISPLAY 1)
421// └── 3 (mirrors display 0)
Vishnu Nair92990e22023-02-24 20:01:05 +0000422TEST_F(LayerSnapshotTest, displayMirrorRespectsLayerSkipScreenshotFlag) {
Vishnu Naira9c43762023-01-27 19:10:25 +0000423 setFlags(12, layer_state_t::eLayerSkipScreenshot, layer_state_t::eLayerSkipScreenshot);
424 createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0));
425 setLayerStack(3, 1);
426
Vishnu Nair444f3952023-04-11 13:01:02 -0700427 std::vector<uint32_t> expected = {1, 11, 111, 12, 121, 122, 1221, 13, 2, 3, 1, 11, 111, 13, 2};
Vishnu Naira9c43762023-01-27 19:10:25 +0000428 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
429}
430
Vishnu Nair92990e22023-02-24 20:01:05 +0000431// ROOT (DISPLAY 0)
432// ├── 1
433// │ ├── 11
434// │ │ └── 111
435// │ └── 13
436// └── 2
437// ROOT (DISPLAY 3)
438// └── 3 (mirrors display 0)
439TEST_F(LayerSnapshotTest, mirrorLayerGetsCorrectLayerStack) {
440 reparentLayer(12, UNASSIGNED_LAYER_ID);
441 createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0));
442 setLayerStack(3, 3);
443 createDisplayMirrorLayer(4, ui::LayerStack::fromValue(0));
444 setLayerStack(4, 4);
445
Vishnu Nair444f3952023-04-11 13:01:02 -0700446 std::vector<uint32_t> expected = {1, 11, 111, 13, 2, 3, 1, 11, 111,
447 13, 2, 4, 1, 11, 111, 13, 2};
Vishnu Nair92990e22023-02-24 20:01:05 +0000448 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
Vishnu Nair6f878312023-09-08 11:05:01 -0700449 EXPECT_EQ(getSnapshot({.id = 111, .mirrorRootIds = 3u})->outputFilter.layerStack.id, 3u);
450 EXPECT_EQ(getSnapshot({.id = 111, .mirrorRootIds = 4u})->outputFilter.layerStack.id, 4u);
Vishnu Nair92990e22023-02-24 20:01:05 +0000451}
452
453// ROOT (DISPLAY 0)
454// ├── 1 (crop 50x50)
455// │ ├── 11
456// │ │ └── 111
457// │ └── 13
458// └── 2
459// ROOT (DISPLAY 3)
460// └── 3 (mirrors display 0) (crop 100x100)
461TEST_F(LayerSnapshotTest, mirrorLayerTouchIsCroppedByMirrorRoot) {
462 reparentLayer(12, UNASSIGNED_LAYER_ID);
463 createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0));
464 setLayerStack(3, 3);
465 setCrop(1, Rect{50, 50});
466 setCrop(3, Rect{100, 100});
467 setCrop(111, Rect{200, 200});
468 Region touch{Rect{0, 0, 1000, 1000}};
469 setTouchableRegion(111, touch);
Vishnu Nair444f3952023-04-11 13:01:02 -0700470 std::vector<uint32_t> expected = {1, 11, 111, 13, 2, 3, 1, 11, 111, 13, 2};
Vishnu Nair92990e22023-02-24 20:01:05 +0000471 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
472 EXPECT_TRUE(getSnapshot({.id = 111})->inputInfo.touchableRegion.hasSameRects(touch));
473 Region touchCroppedByMirrorRoot{Rect{0, 0, 50, 50}};
Vishnu Nair6f878312023-09-08 11:05:01 -0700474 EXPECT_TRUE(getSnapshot({.id = 111, .mirrorRootIds = 3u})
Vishnu Nair92990e22023-02-24 20:01:05 +0000475 ->inputInfo.touchableRegion.hasSameRects(touchCroppedByMirrorRoot));
476}
477
478TEST_F(LayerSnapshotTest, canRemoveDisplayMirror) {
479 setFlags(12, layer_state_t::eLayerSkipScreenshot, layer_state_t::eLayerSkipScreenshot);
480 createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0));
481 setLayerStack(3, 1);
Vishnu Nair444f3952023-04-11 13:01:02 -0700482 std::vector<uint32_t> expected = {1, 11, 111, 12, 121, 122, 1221, 13, 2, 3, 1, 11, 111, 13, 2};
Vishnu Nair92990e22023-02-24 20:01:05 +0000483 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
484 destroyLayerHandle(3);
485 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
486}
487
Vishnu Nairfccd6362023-02-24 23:39:53 +0000488TEST_F(LayerSnapshotTest, cleanUpUnreachableSnapshotsAfterMirroring) {
489 size_t startingNumSnapshots = mSnapshotBuilder.getSnapshots().size();
490 createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0));
491 setLayerStack(3, 1);
Vishnu Nair444f3952023-04-11 13:01:02 -0700492 std::vector<uint32_t> expected = {1, 11, 111, 12, 121, 122, 1221, 13, 2, 3,
493 1, 11, 111, 12, 121, 122, 1221, 13, 2};
Vishnu Nairfccd6362023-02-24 23:39:53 +0000494 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
495 destroyLayerHandle(3);
496 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
497
498 EXPECT_EQ(startingNumSnapshots, mSnapshotBuilder.getSnapshots().size());
499}
500
Vishnu Nair6f878312023-09-08 11:05:01 -0700501TEST_F(LayerSnapshotTest, canMirrorDisplayWithMirrors) {
502 reparentLayer(12, UNASSIGNED_LAYER_ID);
503 mirrorLayer(/*layer*/ 14, /*parent*/ 1, /*layerToMirror*/ 11);
504 std::vector<uint32_t> expected = {1, 11, 111, 13, 14, 11, 111, 2};
505 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
506
507 createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0));
508 setLayerStack(3, 3);
509 expected = {1, 11, 111, 13, 14, 11, 111, 2, 3, 1, 11, 111, 13, 14, 11, 111, 2};
510 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
511 EXPECT_EQ(getSnapshot({.id = 11, .mirrorRootIds = 14u})->outputFilter.layerStack.id, 0u);
512 EXPECT_EQ(getSnapshot({.id = 11, .mirrorRootIds = 3u})->outputFilter.layerStack.id, 3u);
513 EXPECT_EQ(getSnapshot({.id = 11, .mirrorRootIds = 3u, 14u})->outputFilter.layerStack.id, 3u);
514}
515
Vishnu Nairfccd6362023-02-24 23:39:53 +0000516// Rel z doesn't create duplicate snapshots but this is for completeness
517TEST_F(LayerSnapshotTest, cleanUpUnreachableSnapshotsAfterRelZ) {
518 size_t startingNumSnapshots = mSnapshotBuilder.getSnapshots().size();
519 reparentRelativeLayer(13, 11);
520 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 11, 13, 111, 12, 121, 122, 1221, 2});
521 setZ(13, 0);
522 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
523
524 EXPECT_EQ(startingNumSnapshots, mSnapshotBuilder.getSnapshots().size());
525}
526
527TEST_F(LayerSnapshotTest, cleanUpUnreachableSnapshotsAfterLayerDestruction) {
528 size_t startingNumSnapshots = mSnapshotBuilder.getSnapshots().size();
529 destroyLayerHandle(2);
530 destroyLayerHandle(122);
531
532 std::vector<uint32_t> expected = {1, 11, 111, 12, 121, 122, 1221, 13};
533 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
534
535 EXPECT_LE(startingNumSnapshots - 2, mSnapshotBuilder.getSnapshots().size());
536}
537
Vishnu Nair3d8565a2023-06-30 07:23:24 +0000538TEST_F(LayerSnapshotTest, snashotContainsMetadataFromLayerCreationArgs) {
539 LayerCreationArgs args(std::make_optional<uint32_t>(200));
540 args.name = "testlayer";
541 args.addToRoot = true;
542 args.metadata.setInt32(42, 24);
543
544 std::vector<std::unique_ptr<RequestedLayerState>> layers;
545 layers.emplace_back(std::make_unique<RequestedLayerState>(args));
546 EXPECT_TRUE(layers.back()->metadata.has(42));
547 EXPECT_EQ(layers.back()->metadata.getInt32(42, 0), 24);
548 mLifecycleManager.addLayers(std::move(layers));
549
550 std::vector<uint32_t> expected = STARTING_ZORDER;
551 expected.push_back(200);
552 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
553
554 EXPECT_TRUE(mSnapshotBuilder.getSnapshot(200)->layerMetadata.has(42));
555 EXPECT_EQ(mSnapshotBuilder.getSnapshot(200)->layerMetadata.getInt32(42, 0), 24);
556}
557
558TEST_F(LayerSnapshotTest, frameRateSelectionPriorityPassedToChildLayers) {
559 setFrameRateSelectionPriority(11, 1);
560
561 setFrameRateSelectionPriority(12, 2);
562
563 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
564 EXPECT_EQ(getSnapshot({.id = 1})->frameRateSelectionPriority, Layer::PRIORITY_UNSET);
565 EXPECT_EQ(getSnapshot({.id = 11})->frameRateSelectionPriority, 1);
566 EXPECT_EQ(getSnapshot({.id = 12})->frameRateSelectionPriority, 2);
567 EXPECT_EQ(getSnapshot({.id = 122})->frameRateSelectionPriority, 2);
568 EXPECT_EQ(getSnapshot({.id = 1221})->frameRateSelectionPriority, 2);
569
570 // reparent and verify the child gets the new parent's framerate selection priority
571 reparentLayer(122, 11);
572
573 std::vector<uint32_t> expected = {1, 11, 111, 122, 1221, 12, 121, 13, 2};
574 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
575 EXPECT_EQ(getSnapshot({.id = 1})->frameRateSelectionPriority, Layer::PRIORITY_UNSET);
576 EXPECT_EQ(getSnapshot({.id = 11})->frameRateSelectionPriority, 1);
577 EXPECT_EQ(getSnapshot({.id = 12})->frameRateSelectionPriority, 2);
578 EXPECT_EQ(getSnapshot({.id = 122})->frameRateSelectionPriority, 1);
579 EXPECT_EQ(getSnapshot({.id = 1221})->frameRateSelectionPriority, 1);
580}
581
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000582TEST_F(LayerSnapshotTest, framerate) {
583 setFrameRate(11, 244.f, 0, 0);
584
585 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
586 // verify parent is gets no vote
Rachel Leece6e0042023-06-27 11:22:54 -0700587 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
588 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700589 scheduler::FrameRateCompatibility::NoVote);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000590 EXPECT_TRUE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate));
591
592 // verify layer and children get the requested votes
Rachel Leece6e0042023-06-27 11:22:54 -0700593 EXPECT_TRUE(getSnapshot({.id = 11})->frameRate.vote.rate.isValid());
594 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 244.f);
595 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700596 scheduler::FrameRateCompatibility::Default);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000597 EXPECT_TRUE(getSnapshot({.id = 11})->changes.test(RequestedLayerState::Changes::FrameRate));
598
Rachel Leece6e0042023-06-27 11:22:54 -0700599 EXPECT_TRUE(getSnapshot({.id = 111})->frameRate.vote.rate.isValid());
600 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.rate.getValue(), 244.f);
601 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700602 scheduler::FrameRateCompatibility::Default);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000603 EXPECT_TRUE(getSnapshot({.id = 111})->changes.test(RequestedLayerState::Changes::FrameRate));
604
605 // reparent and verify the child gets the new parent's framerate
606 reparentLayer(122, 11);
607
608 std::vector<uint32_t> expected = {1, 11, 111, 122, 1221, 12, 121, 13, 2};
609 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
610 // verify parent is gets no vote
Rachel Leece6e0042023-06-27 11:22:54 -0700611 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
612 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700613 scheduler::FrameRateCompatibility::NoVote);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000614
615 // verify layer and children get the requested votes
Rachel Leece6e0042023-06-27 11:22:54 -0700616 EXPECT_TRUE(getSnapshot({.id = 11})->frameRate.vote.rate.isValid());
617 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 244.f);
618 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700619 scheduler::FrameRateCompatibility::Default);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000620
Rachel Leece6e0042023-06-27 11:22:54 -0700621 EXPECT_TRUE(getSnapshot({.id = 111})->frameRate.vote.rate.isValid());
622 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.rate.getValue(), 244.f);
623 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700624 scheduler::FrameRateCompatibility::Default);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000625
Rachel Leece6e0042023-06-27 11:22:54 -0700626 EXPECT_TRUE(getSnapshot({.id = 122})->frameRate.vote.rate.isValid());
627 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.rate.getValue(), 244.f);
628 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700629 scheduler::FrameRateCompatibility::Default);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000630 EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate));
631
632 // reparent and verify the new parent gets no vote
633 reparentLayer(11, 2);
634 expected = {1, 12, 121, 13, 2, 11, 111, 122, 1221};
635 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
636
637 // verify old parent has invalid framerate (default)
Rachel Leece6e0042023-06-27 11:22:54 -0700638 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
639 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700640 scheduler::FrameRateCompatibility::Default);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000641 EXPECT_TRUE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate));
642
643 // verify new parent get no vote
Rachel Leece6e0042023-06-27 11:22:54 -0700644 EXPECT_FALSE(getSnapshot({.id = 2})->frameRate.vote.rate.isValid());
645 EXPECT_EQ(getSnapshot({.id = 2})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700646 scheduler::FrameRateCompatibility::NoVote);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000647 EXPECT_TRUE(getSnapshot({.id = 2})->changes.test(RequestedLayerState::Changes::FrameRate));
648
649 // verify layer and children get the requested votes (unchanged)
Rachel Leece6e0042023-06-27 11:22:54 -0700650 EXPECT_TRUE(getSnapshot({.id = 11})->frameRate.vote.rate.isValid());
651 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 244.f);
652 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700653 scheduler::FrameRateCompatibility::Default);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000654
Rachel Leece6e0042023-06-27 11:22:54 -0700655 EXPECT_TRUE(getSnapshot({.id = 111})->frameRate.vote.rate.isValid());
656 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.rate.getValue(), 244.f);
657 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700658 scheduler::FrameRateCompatibility::Default);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000659
Rachel Leece6e0042023-06-27 11:22:54 -0700660 EXPECT_TRUE(getSnapshot({.id = 122})->frameRate.vote.rate.isValid());
661 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.rate.getValue(), 244.f);
662 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700663 scheduler::FrameRateCompatibility::Default);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000664}
665
Vishnu Nair3996ee32023-08-14 04:32:31 +0000666TEST_F(LayerSnapshotTest, translateDataspace) {
667 setDataspace(1, ui::Dataspace::UNKNOWN);
668 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
669 EXPECT_EQ(getSnapshot({.id = 1})->dataspace, ui::Dataspace::V0_SRGB);
670}
671
Rachel Leece6e0042023-06-27 11:22:54 -0700672// This test is similar to "frameRate" test case but checks that the setFrameRateCategory API
673// interaction also works correctly with the setFrameRate API within SF frontend.
674TEST_F(LayerSnapshotTest, frameRateWithCategory) {
Rachel Lee45681982024-03-14 18:40:15 -0700675 SET_FLAG_FOR_TEST(flags::frame_rate_category_mrr, true);
676
Rachel Leece6e0042023-06-27 11:22:54 -0700677 // ROOT
678 // ├── 1
679 // │ ├── 11 (frame rate set to 244.f)
680 // │ │ └── 111
681 // │ ├── 12
682 // │ │ ├── 121
683 // │ │ └── 122 (frame rate category set to Normal)
684 // │ │ └── 1221
685 // │ └── 13
686 // └── 2
687 setFrameRate(11, 244.f, 0, 0);
Rachel Lee9580ff12023-12-26 17:33:41 -0800688 setFrameRateCategory(122, ANATIVEWINDOW_FRAME_RATE_CATEGORY_NORMAL);
Rachel Leece6e0042023-06-27 11:22:54 -0700689
690 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
691 // verify parent 1 gets no vote
692 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
693 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700694 scheduler::FrameRateCompatibility::NoVote);
Rachel Leece6e0042023-06-27 11:22:54 -0700695 EXPECT_TRUE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate));
696
697 // verify layer 11 and children 111 get the requested votes
698 EXPECT_TRUE(getSnapshot({.id = 11})->frameRate.vote.rate.isValid());
699 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 244.f);
700 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700701 scheduler::FrameRateCompatibility::Default);
Rachel Leece6e0042023-06-27 11:22:54 -0700702 EXPECT_TRUE(getSnapshot({.id = 11})->changes.test(RequestedLayerState::Changes::FrameRate));
703
704 EXPECT_TRUE(getSnapshot({.id = 111})->frameRate.vote.rate.isValid());
705 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.rate.getValue(), 244.f);
706 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700707 scheduler::FrameRateCompatibility::Default);
Rachel Leece6e0042023-06-27 11:22:54 -0700708 EXPECT_TRUE(getSnapshot({.id = 111})->changes.test(RequestedLayerState::Changes::FrameRate));
709
710 // verify parent 12 gets no vote
711 EXPECT_FALSE(getSnapshot({.id = 12})->frameRate.vote.rate.isValid());
712 EXPECT_EQ(getSnapshot({.id = 12})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700713 scheduler::FrameRateCompatibility::NoVote);
Rachel Leece6e0042023-06-27 11:22:54 -0700714 EXPECT_TRUE(getSnapshot({.id = 12})->changes.test(RequestedLayerState::Changes::FrameRate));
715
716 // verify layer 122 and children 1221 get the requested votes
717 EXPECT_FALSE(getSnapshot({.id = 122})->frameRate.vote.rate.isValid());
718 EXPECT_TRUE(getSnapshot({.id = 122})->frameRate.isValid());
719 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700720 scheduler::FrameRateCompatibility::Default);
Rachel Leece6e0042023-06-27 11:22:54 -0700721 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.category, FrameRateCategory::Normal);
722 EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate));
Rachel Lee43369b22023-09-05 18:40:40 -0700723 EXPECT_TRUE(
724 getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::AffectsChildren));
Rachel Leece6e0042023-06-27 11:22:54 -0700725
726 EXPECT_FALSE(getSnapshot({.id = 1221})->frameRate.vote.rate.isValid());
727 EXPECT_TRUE(getSnapshot({.id = 1221})->frameRate.isValid());
728 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700729 scheduler::FrameRateCompatibility::Default);
Rachel Leece6e0042023-06-27 11:22:54 -0700730 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.category, FrameRateCategory::Normal);
731 EXPECT_TRUE(getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::FrameRate));
Rachel Lee43369b22023-09-05 18:40:40 -0700732 EXPECT_TRUE(
733 getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::AffectsChildren));
Rachel Leece6e0042023-06-27 11:22:54 -0700734
735 // reparent and verify the child does NOT get the new parent's framerate because it already has
736 // the frame rate category specified.
737 // ROOT
738 // ├─1
739 // │ ├─11 (frame rate set to 244.f)
740 // │ │ ├─111
741 // │ │ └─122 (frame rate category set to Normal)
742 // │ │ └─1221
743 // │ ├─12
744 // │ │ └─121
745 // │ └─13
746 // └─2
747 reparentLayer(122, 11);
748
749 std::vector<uint32_t> expected = {1, 11, 111, 122, 1221, 12, 121, 13, 2};
750 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
751 // verify parent is gets no vote
752 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
753 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700754 scheduler::FrameRateCompatibility::NoVote);
Rachel Leece6e0042023-06-27 11:22:54 -0700755
756 // verify layer 11 and children 111 get the requested votes
757 EXPECT_TRUE(getSnapshot({.id = 11})->frameRate.vote.rate.isValid());
758 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 244.f);
759 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700760 scheduler::FrameRateCompatibility::Default);
Rachel Leece6e0042023-06-27 11:22:54 -0700761
762 EXPECT_TRUE(getSnapshot({.id = 111})->frameRate.vote.rate.isValid());
763 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.rate.getValue(), 244.f);
764 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700765 scheduler::FrameRateCompatibility::Default);
Rachel Leece6e0042023-06-27 11:22:54 -0700766
767 // verify layer 122 and children 1221 get the requested category vote (unchanged from
768 // reparenting)
769 EXPECT_FALSE(getSnapshot({.id = 122})->frameRate.vote.rate.isValid());
770 EXPECT_TRUE(getSnapshot({.id = 122})->frameRate.isValid());
771 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700772 scheduler::FrameRateCompatibility::Default);
Rachel Leece6e0042023-06-27 11:22:54 -0700773 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.category, FrameRateCategory::Normal);
774 EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate));
775
776 EXPECT_FALSE(getSnapshot({.id = 1221})->frameRate.vote.rate.isValid());
777 EXPECT_TRUE(getSnapshot({.id = 1221})->frameRate.isValid());
778 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700779 scheduler::FrameRateCompatibility::Default);
Rachel Leece6e0042023-06-27 11:22:54 -0700780 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.category, FrameRateCategory::Normal);
781 EXPECT_TRUE(getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::FrameRate));
782}
783
Rachel Lee58cc90d2023-09-05 18:50:20 -0700784TEST_F(LayerSnapshotTest, frameRateSelectionStrategy) {
785 // ROOT
786 // ├── 1
787 // │ ├── 11
788 // │ │ └── 111
789 // │ ├── 12 (frame rate set to 244.f with strategy OverrideChildren)
790 // │ │ ├── 121
791 // │ │ └── 122 (frame rate set to 123.f but should be overridden by layer 12)
792 // │ │ └── 1221
793 // │ └── 13
794 // └── 2
795 setFrameRate(12, 244.f, 0, 0);
796 setFrameRate(122, 123.f, 0, 0);
797 setFrameRateSelectionStrategy(12, 1 /* OverrideChildren */);
798
799 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
800 // verify parent 1 gets no vote
801 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
802 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700803 scheduler::FrameRateCompatibility::NoVote);
Rachel Lee58cc90d2023-09-05 18:50:20 -0700804 EXPECT_TRUE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate));
805
806 // verify layer 12 and all descendants (121, 122, 1221) get the requested vote
807 EXPECT_EQ(getSnapshot({.id = 12})->frameRate.vote.rate.getValue(), 244.f);
808 EXPECT_EQ(getSnapshot({.id = 12})->frameRateSelectionStrategy,
809 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
810 EXPECT_TRUE(getSnapshot({.id = 12})->changes.test(RequestedLayerState::Changes::FrameRate));
811
812 EXPECT_EQ(getSnapshot({.id = 121})->frameRate.vote.rate.getValue(), 244.f);
813 EXPECT_EQ(getSnapshot({.id = 121})->frameRateSelectionStrategy,
814 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
815 EXPECT_TRUE(getSnapshot({.id = 121})->changes.test(RequestedLayerState::Changes::FrameRate));
816
817 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.rate.getValue(), 244.f);
818 EXPECT_EQ(getSnapshot({.id = 122})->frameRateSelectionStrategy,
819 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
820 EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate));
821
822 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.vote.rate.getValue(), 244.f);
823 EXPECT_EQ(getSnapshot({.id = 1221})->frameRateSelectionStrategy,
824 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
825 EXPECT_TRUE(getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::FrameRate));
Vishnu Nair41376b62023-11-08 05:08:58 -0800826
827 // ROOT
828 // ├── 1
829 // │ ├── 11
830 // │ │ └── 111
831 // │ ├── 12 (frame rate set to default with strategy default)
832 // │ │ ├── 121
833 // │ │ └── 122 (frame rate set to 123.f)
834 // │ │ └── 1221
835 // │ └── 13
836 // └── 2
837 setFrameRate(12, -1.f, 0, 0);
838 setFrameRateSelectionStrategy(12, 0 /* Default */);
839 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
840 // verify parent 1 gets no vote
841 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
842 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
843 scheduler::FrameRateCompatibility::NoVote);
844 EXPECT_FALSE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate));
845
846 // verify layer 12 and all descendants (121, 122, 1221) get the requested vote
847 EXPECT_FALSE(getSnapshot({.id = 12})->frameRate.vote.rate.isValid());
848 EXPECT_EQ(getSnapshot({.id = 12})->frameRate.vote.type,
849 scheduler::FrameRateCompatibility::NoVote);
850 EXPECT_EQ(getSnapshot({.id = 12})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -0800851 scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate);
Vishnu Nair41376b62023-11-08 05:08:58 -0800852 EXPECT_TRUE(getSnapshot({.id = 12})->changes.test(RequestedLayerState::Changes::FrameRate));
853
854 EXPECT_FALSE(getSnapshot({.id = 121})->frameRate.vote.rate.isValid());
855 EXPECT_EQ(getSnapshot({.id = 121})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -0800856 scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate);
Vishnu Nair41376b62023-11-08 05:08:58 -0800857 EXPECT_EQ(getSnapshot({.id = 121})->frameRate.vote.type,
858 scheduler::FrameRateCompatibility::Default);
859 EXPECT_TRUE(getSnapshot({.id = 121})->changes.test(RequestedLayerState::Changes::FrameRate));
860
861 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.rate.getValue(), 123.f);
862 EXPECT_EQ(getSnapshot({.id = 122})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -0800863 scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate);
Vishnu Nair41376b62023-11-08 05:08:58 -0800864 EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate));
865
866 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.vote.rate.getValue(), 123.f);
867 EXPECT_EQ(getSnapshot({.id = 1221})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -0800868 scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate);
Vishnu Nair41376b62023-11-08 05:08:58 -0800869 EXPECT_TRUE(getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::FrameRate));
870}
871
872TEST_F(LayerSnapshotTest, frameRateSelectionStrategyWithCategory) {
Rachel Lee45681982024-03-14 18:40:15 -0700873 SET_FLAG_FOR_TEST(flags::frame_rate_category_mrr, true);
874
Vishnu Nair41376b62023-11-08 05:08:58 -0800875 // ROOT
876 // ├── 1
877 // │ ├── 11
878 // │ │ └── 111
879 // │ ├── 12 (frame rate category set to high with strategy OverrideChildren)
880 // │ │ ├── 121
881 // │ │ └── 122 (frame rate set to 123.f but should be overridden by layer 12)
882 // │ │ └── 1221
883 // │ └── 13
884 // └── 2
Rachel Lee9580ff12023-12-26 17:33:41 -0800885 setFrameRateCategory(12, ANATIVEWINDOW_FRAME_RATE_CATEGORY_HIGH);
Vishnu Nair41376b62023-11-08 05:08:58 -0800886 setFrameRate(122, 123.f, 0, 0);
887 setFrameRateSelectionStrategy(12, 1 /* OverrideChildren */);
888
889 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
890 // verify parent 1 gets no vote
891 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
892 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
893 scheduler::FrameRateCompatibility::NoVote);
894 EXPECT_TRUE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate));
895
896 // verify layer 12 and all descendants (121, 122, 1221) get the requested vote
897 EXPECT_EQ(getSnapshot({.id = 12})->frameRate.category, FrameRateCategory::High);
898 EXPECT_EQ(getSnapshot({.id = 12})->frameRateSelectionStrategy,
899 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
900 EXPECT_TRUE(getSnapshot({.id = 12})->changes.test(RequestedLayerState::Changes::FrameRate));
901
902 EXPECT_EQ(getSnapshot({.id = 121})->frameRate.category, FrameRateCategory::High);
903 EXPECT_EQ(getSnapshot({.id = 121})->frameRateSelectionStrategy,
904 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
905 EXPECT_TRUE(getSnapshot({.id = 121})->changes.test(RequestedLayerState::Changes::FrameRate));
906
907 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.category, FrameRateCategory::High);
908 EXPECT_EQ(getSnapshot({.id = 122})->frameRateSelectionStrategy,
909 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
910 EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate));
911
912 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.category, FrameRateCategory::High);
913 EXPECT_EQ(getSnapshot({.id = 1221})->frameRateSelectionStrategy,
914 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
915 EXPECT_TRUE(getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::FrameRate));
916
917 // ROOT
918 // ├── 1
919 // │ ├── 11
920 // │ │ └── 111
921 // │ ├── 12 (frame rate category to default with strategy default)
922 // │ │ ├── 121
923 // │ │ └── 122 (frame rate set to 123.f)
924 // │ │ └── 1221
925 // │ └── 13
926 // └── 2
Rachel Lee9580ff12023-12-26 17:33:41 -0800927 setFrameRateCategory(12, ANATIVEWINDOW_FRAME_RATE_CATEGORY_DEFAULT);
Vishnu Nair41376b62023-11-08 05:08:58 -0800928 setFrameRateSelectionStrategy(12, 0 /* Default */);
929 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
930 // verify parent 1 gets no vote
931 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
932 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
933 scheduler::FrameRateCompatibility::NoVote);
934 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.category, FrameRateCategory::Default);
935 EXPECT_FALSE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate));
936
937 // verify layer 12 and all descendants (121, 122, 1221) get the requested vote
938 EXPECT_FALSE(getSnapshot({.id = 12})->frameRate.vote.rate.isValid());
939 EXPECT_EQ(getSnapshot({.id = 12})->frameRate.vote.type,
940 scheduler::FrameRateCompatibility::NoVote);
941 EXPECT_EQ(getSnapshot({.id = 12})->frameRate.category, FrameRateCategory::Default);
942 EXPECT_EQ(getSnapshot({.id = 12})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -0800943 scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate);
Vishnu Nair41376b62023-11-08 05:08:58 -0800944 EXPECT_TRUE(getSnapshot({.id = 12})->changes.test(RequestedLayerState::Changes::FrameRate));
945
946 EXPECT_FALSE(getSnapshot({.id = 12})->frameRate.vote.rate.isValid());
947 EXPECT_EQ(getSnapshot({.id = 121})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -0800948 scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate);
Vishnu Nair41376b62023-11-08 05:08:58 -0800949 EXPECT_EQ(getSnapshot({.id = 121})->frameRate.category, FrameRateCategory::Default);
950 EXPECT_EQ(getSnapshot({.id = 121})->frameRate.vote.type,
951 scheduler::FrameRateCompatibility::Default);
952 EXPECT_TRUE(getSnapshot({.id = 121})->changes.test(RequestedLayerState::Changes::FrameRate));
953
954 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.rate.getValue(), 123.f);
955 EXPECT_EQ(getSnapshot({.id = 122})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -0800956 scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate);
Vishnu Nair41376b62023-11-08 05:08:58 -0800957 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.category, FrameRateCategory::Default);
958 EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate));
959
960 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.vote.rate.getValue(), 123.f);
961 EXPECT_EQ(getSnapshot({.id = 1221})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -0800962 scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate);
Vishnu Nair41376b62023-11-08 05:08:58 -0800963 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.category, FrameRateCategory::Default);
964 EXPECT_TRUE(getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::FrameRate));
Rachel Lee58cc90d2023-09-05 18:50:20 -0700965}
966
Rachel Lee70f7b692023-11-22 11:24:02 -0800967TEST_F(LayerSnapshotTest, frameRateSelectionStrategyWithOverrideChildrenAndSelf) {
Rachel Leea021bb02023-11-20 21:51:09 -0800968 // ROOT
969 // ├── 1
Rachel Lee70f7b692023-11-22 11:24:02 -0800970 // │ ├── 11 (frame rate set to 11.f with strategy Self)
Rachel Leea021bb02023-11-20 21:51:09 -0800971 // │ │ └── 111 (frame rate is not inherited)
972 // │ ├── 12 (frame rate set to 244.f)
973 // │ │ ├── 121
974 // │ │ └── 122 (strategy OverrideChildren and inherits frame rate 244.f)
975 // │ │ └── 1221 (frame rate set to 123.f but should be overridden by layer 122)
976 // │ └── 13
977 // └── 2
978 setFrameRate(11, 11.f, 0, 0);
Rachel Lee70f7b692023-11-22 11:24:02 -0800979 setFrameRateSelectionStrategy(11, 2 /* Self */);
Rachel Leea021bb02023-11-20 21:51:09 -0800980 setFrameRate(12, 244.f, 0, 0);
981 setFrameRateSelectionStrategy(122, 1 /* OverrideChildren */);
982 setFrameRate(1221, 123.f, 0, 0);
983
984 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
985 // verify parent 1 gets no vote
986 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
987 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
988 scheduler::FrameRateCompatibility::NoVote);
989 EXPECT_EQ(getSnapshot({.id = 1})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -0800990 scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate);
Rachel Leea021bb02023-11-20 21:51:09 -0800991 EXPECT_TRUE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate));
992
993 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 11.f);
994 EXPECT_EQ(getSnapshot({.id = 11})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -0800995 scheduler::LayerInfo::FrameRateSelectionStrategy::Self);
Rachel Leea021bb02023-11-20 21:51:09 -0800996 EXPECT_TRUE(getSnapshot({.id = 11})->changes.test(RequestedLayerState::Changes::FrameRate));
997
998 // verify layer 11 does does not propagate its framerate to 111.
999 EXPECT_FALSE(getSnapshot({.id = 111})->frameRate.vote.rate.isValid());
1000 EXPECT_EQ(getSnapshot({.id = 111})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -08001001 scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate);
Rachel Leea021bb02023-11-20 21:51:09 -08001002 EXPECT_TRUE(getSnapshot({.id = 111})->changes.test(RequestedLayerState::Changes::FrameRate));
1003
1004 // verify layer 12 and all descendants (121, 122, 1221) get the requested vote
1005 EXPECT_EQ(getSnapshot({.id = 12})->frameRate.vote.rate.getValue(), 244.f);
1006 EXPECT_EQ(getSnapshot({.id = 12})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -08001007 scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate);
Rachel Leea021bb02023-11-20 21:51:09 -08001008 EXPECT_TRUE(getSnapshot({.id = 12})->changes.test(RequestedLayerState::Changes::FrameRate));
1009
1010 EXPECT_EQ(getSnapshot({.id = 121})->frameRate.vote.rate.getValue(), 244.f);
1011 EXPECT_EQ(getSnapshot({.id = 121})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -08001012 scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate);
Rachel Leea021bb02023-11-20 21:51:09 -08001013 EXPECT_TRUE(getSnapshot({.id = 121})->changes.test(RequestedLayerState::Changes::FrameRate));
1014
1015 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.rate.getValue(), 244.f);
1016 EXPECT_EQ(getSnapshot({.id = 122})->frameRateSelectionStrategy,
1017 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
1018 EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate));
1019
1020 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.vote.rate.getValue(), 244.f);
1021 EXPECT_EQ(getSnapshot({.id = 1221})->frameRateSelectionStrategy,
1022 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
1023 EXPECT_TRUE(getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::FrameRate));
1024
1025 // ROOT
1026 // ├── 1 (frame rate set to 1.f with strategy OverrideChildren)
Rachel Lee70f7b692023-11-22 11:24:02 -08001027 // │ ├── 11 (frame rate set to 11.f with strategy Self, but overridden by 1)
Rachel Leea021bb02023-11-20 21:51:09 -08001028 // │ │ └── 111 (frame rate inherited from 11 due to override from 1)
1029 // â‹® â‹®
1030 setFrameRate(1, 1.f, 0, 0);
1031 setFrameRateSelectionStrategy(1, 1 /* OverrideChildren */);
1032 setFrameRate(11, 11.f, 0, 0);
Rachel Lee70f7b692023-11-22 11:24:02 -08001033 setFrameRateSelectionStrategy(11, 2 /* Self */);
Rachel Leea021bb02023-11-20 21:51:09 -08001034 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1035
1036 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.rate.getValue(), 1.f);
1037 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
1038 scheduler::FrameRateCompatibility::Default);
1039 EXPECT_EQ(getSnapshot({.id = 1})->frameRateSelectionStrategy,
1040 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
1041 EXPECT_TRUE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate));
1042
1043 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 1.f);
1044 EXPECT_EQ(getSnapshot({.id = 11})->frameRateSelectionStrategy,
1045 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
1046 EXPECT_TRUE(getSnapshot({.id = 11})->changes.test(RequestedLayerState::Changes::FrameRate));
1047
1048 // verify layer 11 does does not propagate its framerate to 111.
1049 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.rate.getValue(), 1.f);
1050 EXPECT_EQ(getSnapshot({.id = 111})->frameRateSelectionStrategy,
1051 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
1052 EXPECT_TRUE(getSnapshot({.id = 111})->changes.test(RequestedLayerState::Changes::FrameRate));
1053}
1054
Vishnu Nair0808ae62023-08-07 21:42:42 -07001055TEST_F(LayerSnapshotTest, skipRoundCornersWhenProtected) {
1056 setRoundedCorners(1, 42.f);
1057 setRoundedCorners(2, 42.f);
1058 setCrop(1, Rect{1000, 1000});
1059 setCrop(2, Rect{1000, 1000});
1060
1061 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1062 EXPECT_TRUE(getSnapshot({.id = 1})->roundedCorner.hasRoundedCorners());
1063 EXPECT_EQ(getSnapshot({.id = 1})->roundedCorner.radius.x, 42.f);
1064 EXPECT_TRUE(getSnapshot({.id = 2})->roundedCorner.hasRoundedCorners());
1065
1066 // add a buffer with the protected bit, check rounded corners are not set when
1067 // skipRoundCornersWhenProtected == true
1068 setBuffer(1,
1069 std::make_shared<
1070 renderengine::mock::FakeExternalTexture>(1U /*width*/, 1U /*height*/,
1071 1ULL /* bufferId */,
1072 HAL_PIXEL_FORMAT_RGBA_8888,
1073 GRALLOC_USAGE_PROTECTED /*usage*/));
1074
1075 LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(),
1076 .layerLifecycleManager = mLifecycleManager,
1077 .includeMetadata = false,
1078 .displays = mFrontEndDisplayInfos,
1079 .displayChanges = false,
1080 .globalShadowSettings = globalShadowSettings,
1081 .supportsBlur = true,
1082 .supportedLayerGenericMetadata = {},
1083 .genericLayerMetadataKeyMap = {},
1084 .skipRoundCornersWhenProtected = true};
1085 update(mSnapshotBuilder, args);
1086 EXPECT_FALSE(getSnapshot({.id = 1})->roundedCorner.hasRoundedCorners());
1087 // layer 2 doesn't have a buffer and should be unaffected
1088 EXPECT_TRUE(getSnapshot({.id = 2})->roundedCorner.hasRoundedCorners());
1089
1090 // remove protected bit, check rounded corners are set
1091 setBuffer(1,
1092 std::make_shared<renderengine::mock::FakeExternalTexture>(1U /*width*/, 1U /*height*/,
1093 2ULL /* bufferId */,
1094 HAL_PIXEL_FORMAT_RGBA_8888,
1095 0 /*usage*/));
1096 update(mSnapshotBuilder, args);
1097 EXPECT_TRUE(getSnapshot({.id = 1})->roundedCorner.hasRoundedCorners());
1098 EXPECT_EQ(getSnapshot({.id = 1})->roundedCorner.radius.x, 42.f);
1099}
1100
Vishnu Nairbd51f952023-08-31 22:50:14 -07001101TEST_F(LayerSnapshotTest, setRefreshRateIndicatorCompositionType) {
1102 setFlags(1, layer_state_t::eLayerIsRefreshRateIndicator,
1103 layer_state_t::eLayerIsRefreshRateIndicator);
1104 setBuffer(1,
1105 std::make_shared<renderengine::mock::FakeExternalTexture>(1U /*width*/, 1U /*height*/,
1106 42ULL /* bufferId */,
1107 HAL_PIXEL_FORMAT_RGBA_8888,
1108 0 /*usage*/));
1109 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1110 EXPECT_EQ(getSnapshot({.id = 1})->compositionType,
1111 aidl::android::hardware::graphics::composer3::Composition::REFRESH_RATE_INDICATOR);
1112}
1113
Chavi Weingarten07597342023-09-14 21:10:59 +00001114TEST_F(LayerSnapshotTest, setBufferCrop) {
1115 // validate no buffer but has crop
1116 Rect crop = Rect(0, 0, 50, 50);
1117 setBufferCrop(1, crop);
1118 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1119 EXPECT_EQ(getSnapshot(1)->geomContentCrop, crop);
1120
1121 setBuffer(1,
1122 std::make_shared<renderengine::mock::FakeExternalTexture>(100U /*width*/,
1123 100U /*height*/,
1124 42ULL /* bufferId */,
1125 HAL_PIXEL_FORMAT_RGBA_8888,
1126 0 /*usage*/));
1127 // validate a buffer crop within the buffer bounds
1128 setBufferCrop(1, crop);
1129 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1130 EXPECT_EQ(getSnapshot(1)->geomContentCrop, crop);
1131
1132 // validate a buffer crop outside the buffer bounds
1133 crop = Rect(0, 0, 150, 150);
1134 setBufferCrop(1, crop);
1135 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1136 EXPECT_EQ(getSnapshot(1)->geomContentCrop, Rect(0, 0, 100, 100));
1137
1138 // validate no buffer crop
1139 setBufferCrop(1, Rect());
1140 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1141 EXPECT_EQ(getSnapshot(1)->geomContentCrop, Rect(0, 0, 100, 100));
1142}
Vishnu Nairbefd3e22023-10-05 17:48:31 +00001143
1144TEST_F(LayerSnapshotTest, setShadowRadius) {
1145 static constexpr float SHADOW_RADIUS = 123.f;
1146 setShadowRadius(1, SHADOW_RADIUS);
1147 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1148 EXPECT_EQ(getSnapshot(1)->shadowSettings.length, SHADOW_RADIUS);
Vishnu Nairbefd3e22023-10-05 17:48:31 +00001149}
1150
Chavi Weingartenb74093a2023-10-11 20:29:59 +00001151TEST_F(LayerSnapshotTest, setTrustedOverlayForNonVisibleInput) {
1152 hideLayer(1);
1153 setTrustedOverlay(1, true);
1154 Region touch{Rect{0, 0, 1000, 1000}};
1155 setTouchableRegion(1, touch);
1156
1157 UPDATE_AND_VERIFY(mSnapshotBuilder, {2});
1158 EXPECT_TRUE(getSnapshot(1)->inputInfo.inputConfig.test(
1159 gui::WindowInfo::InputConfig::TRUSTED_OVERLAY));
1160}
1161
Alec Mouri89f5d4e2023-10-20 17:12:49 +00001162TEST_F(LayerSnapshotTest, isFrontBuffered) {
1163 setBuffer(1,
1164 std::make_shared<renderengine::mock::FakeExternalTexture>(
1165 1U /*width*/, 1U /*height*/, 1ULL /* bufferId */, HAL_PIXEL_FORMAT_RGBA_8888,
1166 GRALLOC_USAGE_HW_TEXTURE | AHARDWAREBUFFER_USAGE_FRONT_BUFFER /*usage*/));
1167
1168 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1169 EXPECT_TRUE(getSnapshot(1)->isFrontBuffered());
1170
1171 setBuffer(1,
1172 std::make_shared<
1173 renderengine::mock::FakeExternalTexture>(1U /*width*/, 1U /*height*/,
1174 1ULL /* bufferId */,
1175 HAL_PIXEL_FORMAT_RGBA_8888,
1176 GRALLOC_USAGE_HW_TEXTURE /*usage*/));
1177
1178 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1179 EXPECT_FALSE(getSnapshot(1)->isFrontBuffered());
1180}
1181
Chavi Weingarten4aa22af2023-11-17 19:37:07 +00001182TEST_F(LayerSnapshotTest, setSecureRootSnapshot) {
1183 setFlags(1, layer_state_t::eLayerSecure, layer_state_t::eLayerSecure);
1184 LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(),
1185 .layerLifecycleManager = mLifecycleManager,
1186 .includeMetadata = false,
1187 .displays = mFrontEndDisplayInfos,
1188 .displayChanges = false,
1189 .globalShadowSettings = globalShadowSettings,
1190 .supportsBlur = true,
1191 .supportedLayerGenericMetadata = {},
1192 .genericLayerMetadataKeyMap = {}};
1193 args.rootSnapshot.isSecure = true;
1194 update(mSnapshotBuilder, args);
1195
1196 EXPECT_TRUE(getSnapshot(1)->isSecure);
1197 // Ensure child is also marked as secure
1198 EXPECT_TRUE(getSnapshot(11)->isSecure);
1199}
1200
Prabir Pradhancf359192024-03-20 00:42:57 +00001201TEST_F(LayerSnapshotTest, setSensitiveForTracingConfigForSecureLayers) {
1202 setFlags(11, layer_state_t::eLayerSecure, layer_state_t::eLayerSecure);
1203
1204 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1205
1206 EXPECT_TRUE(getSnapshot(11)->inputInfo.inputConfig.test(
1207 gui::WindowInfo::InputConfig::SENSITIVE_FOR_TRACING));
1208 EXPECT_TRUE(getSnapshot(111)->inputInfo.inputConfig.test(
1209 gui::WindowInfo::InputConfig::SENSITIVE_FOR_TRACING));
1210 EXPECT_FALSE(getSnapshot(1)->inputInfo.inputConfig.test(
1211 gui::WindowInfo::InputConfig::SENSITIVE_FOR_TRACING));
1212 EXPECT_FALSE(getSnapshot(12)->inputInfo.inputConfig.test(
1213 gui::WindowInfo::InputConfig::SENSITIVE_FOR_TRACING));
1214 EXPECT_FALSE(getSnapshot(2)->inputInfo.inputConfig.test(
1215 gui::WindowInfo::InputConfig::SENSITIVE_FOR_TRACING));
1216}
1217
1218TEST_F(LayerSnapshotTest, setSensitiveForTracingFromInputWindowHandle) {
1219 setInputInfo(11, [](auto& inputInfo) {
1220 inputInfo.inputConfig |= gui::WindowInfo::InputConfig::SENSITIVE_FOR_TRACING;
1221 });
1222
1223 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1224
1225 EXPECT_TRUE(getSnapshot(11)->inputInfo.inputConfig.test(
1226 gui::WindowInfo::InputConfig::SENSITIVE_FOR_TRACING));
1227 EXPECT_TRUE(getSnapshot(111)->inputInfo.inputConfig.test(
1228 gui::WindowInfo::InputConfig::SENSITIVE_FOR_TRACING));
1229 EXPECT_FALSE(getSnapshot(1)->inputInfo.inputConfig.test(
1230 gui::WindowInfo::InputConfig::SENSITIVE_FOR_TRACING));
1231 EXPECT_FALSE(getSnapshot(12)->inputInfo.inputConfig.test(
1232 gui::WindowInfo::InputConfig::SENSITIVE_FOR_TRACING));
1233 EXPECT_FALSE(getSnapshot(2)->inputInfo.inputConfig.test(
1234 gui::WindowInfo::InputConfig::SENSITIVE_FOR_TRACING));
1235}
1236
Vishnu Nairf13c8982023-12-02 11:26:09 -08001237// b/314350323
1238TEST_F(LayerSnapshotTest, propagateDropInputMode) {
1239 setDropInputMode(1, gui::DropInputMode::ALL);
1240 LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(),
1241 .layerLifecycleManager = mLifecycleManager,
1242 .includeMetadata = false,
1243 .displays = mFrontEndDisplayInfos,
1244 .displayChanges = false,
1245 .globalShadowSettings = globalShadowSettings,
1246 .supportsBlur = true,
1247 .supportedLayerGenericMetadata = {},
1248 .genericLayerMetadataKeyMap = {}};
1249 args.rootSnapshot.isSecure = true;
1250 update(mSnapshotBuilder, args);
1251
1252 EXPECT_EQ(getSnapshot(1)->dropInputMode, gui::DropInputMode::ALL);
1253 // Ensure child also has the correct drop input mode regardless of whether either layer has
1254 // an input channel
1255 EXPECT_EQ(getSnapshot(11)->dropInputMode, gui::DropInputMode::ALL);
1256}
1257
Chavi Weingarten92c7d8c2024-01-19 23:25:45 +00001258TEST_F(LayerSnapshotTest, NonVisibleLayerWithInput) {
1259 LayerHierarchyTestBase::createRootLayer(3);
1260 setColor(3, {-1._hf, -1._hf, -1._hf});
1261 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1262
1263 std::vector<TransactionState> transactions;
1264 transactions.emplace_back();
1265 transactions.back().states.push_back({});
1266 transactions.back().states.front().state.what = layer_state_t::eInputInfoChanged;
1267 transactions.back().states.front().layerId = 3;
1268 transactions.back().states.front().state.windowInfoHandle = sp<gui::WindowInfoHandle>::make();
1269 auto inputInfo = transactions.back().states.front().state.windowInfoHandle->editInfo();
1270 inputInfo->token = sp<BBinder>::make();
1271 mLifecycleManager.applyTransactions(transactions);
1272
1273 update(mSnapshotBuilder);
1274
1275 bool foundInputLayer = false;
1276 mSnapshotBuilder.forEachInputSnapshot([&](const frontend::LayerSnapshot& snapshot) {
1277 if (snapshot.uniqueSequence == 3) {
1278 foundInputLayer = true;
1279 }
1280 });
1281 EXPECT_TRUE(foundInputLayer);
1282}
1283
Vishnu Nair59a6be32024-01-29 10:26:21 -08001284TEST_F(LayerSnapshotTest, canOccludePresentation) {
1285 setFlags(12, layer_state_t::eCanOccludePresentation, layer_state_t::eCanOccludePresentation);
1286 LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(),
1287 .layerLifecycleManager = mLifecycleManager,
1288 .includeMetadata = false,
1289 .displays = mFrontEndDisplayInfos,
1290 .displayChanges = false,
1291 .globalShadowSettings = globalShadowSettings,
1292 .supportsBlur = true,
1293 .supportedLayerGenericMetadata = {},
1294 .genericLayerMetadataKeyMap = {}};
1295 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1296
1297 EXPECT_EQ(getSnapshot(1)->inputInfo.canOccludePresentation, false);
1298
1299 // ensure we can set the property on the window info for layer and all its children
1300 EXPECT_EQ(getSnapshot(12)->inputInfo.canOccludePresentation, true);
1301 EXPECT_EQ(getSnapshot(121)->inputInfo.canOccludePresentation, true);
1302 EXPECT_EQ(getSnapshot(1221)->inputInfo.canOccludePresentation, true);
1303}
1304
Vishnu Nair8fc721b2022-12-22 20:06:32 +00001305} // namespace android::surfaceflinger::frontend