blob: dedb292b34e256257adafb4c2e6f82854f1b609e [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
Vishnu Nairb4a6a772024-06-12 14:41:08 -0700216TEST_F(LayerSnapshotTest, offscreenLayerSnapshotIsInvisible) {
217 EXPECT_EQ(getSnapshot(111)->isVisible, true);
218
219 reparentLayer(11, UNASSIGNED_LAYER_ID);
220 destroyLayerHandle(11);
221 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 13, 2});
222
223 EXPECT_EQ(getSnapshot(111)->isVisible, false);
224 EXPECT_TRUE(getSnapshot(111)->changes.test(RequestedLayerState::Changes::Visibility));
225}
226
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000227// relative tests
228TEST_F(LayerSnapshotTest, RelativeParentCanHideChild) {
229 reparentRelativeLayer(13, 11);
230 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 11, 13, 111, 12, 121, 122, 1221, 2});
231
232 hideLayer(11);
233 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 2});
234}
235
236TEST_F(LayerSnapshotTest, ReparentingToHiddenRelativeParentHidesChild) {
237 hideLayer(11);
238 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 13, 2});
239 reparentRelativeLayer(13, 11);
240 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 2});
241}
242
243TEST_F(LayerSnapshotTest, AlphaInheritedByChildren) {
244 setAlpha(1, 0.5);
245 setAlpha(122, 0.5);
246 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
Vishnu Naira02943f2023-06-03 13:44:46 -0700247 EXPECT_EQ(getSnapshot(1)->alpha, 0.5f);
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000248 EXPECT_EQ(getSnapshot(12)->alpha, 0.5f);
249 EXPECT_EQ(getSnapshot(1221)->alpha, 0.25f);
250}
251
252// Change states
253TEST_F(LayerSnapshotTest, UpdateClearsPreviousChangeStates) {
254 setCrop(1, Rect(1, 2, 3, 4));
255 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
Vishnu Naira02943f2023-06-03 13:44:46 -0700256 EXPECT_TRUE(getSnapshot(1)->changes.test(RequestedLayerState::Changes::Geometry));
257 EXPECT_TRUE(getSnapshot(11)->changes.test(RequestedLayerState::Changes::Geometry));
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000258 setCrop(2, Rect(1, 2, 3, 4));
259 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
Vishnu Naira02943f2023-06-03 13:44:46 -0700260 EXPECT_TRUE(getSnapshot(2)->changes.test(RequestedLayerState::Changes::Geometry));
261 EXPECT_FALSE(getSnapshot(1)->changes.test(RequestedLayerState::Changes::Geometry));
262 EXPECT_FALSE(getSnapshot(11)->changes.test(RequestedLayerState::Changes::Geometry));
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000263}
264
265TEST_F(LayerSnapshotTest, FastPathClearsPreviousChangeStates) {
266 setColor(11, {1._hf, 0._hf, 0._hf});
267 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
Vishnu Nairdf59f472024-05-17 16:51:33 +0000268 EXPECT_EQ(getSnapshot(11)->changes,
Ady Abraham6846ade2024-05-20 21:58:27 +0000269 RequestedLayerState::Changes::Content);
Vishnu Naira02943f2023-06-03 13:44:46 -0700270 EXPECT_EQ(getSnapshot(11)->clientChanges, layer_state_t::eColorChanged);
271 EXPECT_EQ(getSnapshot(1)->changes.get(), 0u);
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000272 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
Vishnu Naira02943f2023-06-03 13:44:46 -0700273 EXPECT_EQ(getSnapshot(11)->changes.get(), 0u);
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000274}
275
276TEST_F(LayerSnapshotTest, FastPathSetsChangeFlagToContent) {
277 setColor(1, {1._hf, 0._hf, 0._hf});
278 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
Vishnu Nairdf59f472024-05-17 16:51:33 +0000279 EXPECT_EQ(getSnapshot(1)->changes,
Ady Abraham6846ade2024-05-20 21:58:27 +0000280 RequestedLayerState::Changes::Content);
Vishnu Naira02943f2023-06-03 13:44:46 -0700281 EXPECT_EQ(getSnapshot(1)->clientChanges, layer_state_t::eColorChanged);
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000282}
283
Vishnu Naircfb2d252023-01-19 04:44:02 +0000284TEST_F(LayerSnapshotTest, GameMode) {
285 std::vector<TransactionState> transactions;
286 transactions.emplace_back();
287 transactions.back().states.push_back({});
288 transactions.back().states.front().state.what = layer_state_t::eMetadataChanged;
289 transactions.back().states.front().state.metadata = LayerMetadata();
290 transactions.back().states.front().state.metadata.setInt32(METADATA_GAME_MODE, 42);
Vishnu Nair1391de22023-03-05 19:56:14 -0800291 transactions.back().states.front().layerId = 1;
Vishnu Naircfb2d252023-01-19 04:44:02 +0000292 transactions.back().states.front().state.layerId = static_cast<int32_t>(1);
293 mLifecycleManager.applyTransactions(transactions);
Nergi Rahardi10fbacd2024-05-21 09:37:59 +0000294 EXPECT_EQ(mLifecycleManager.getGlobalChanges(), RequestedLayerState::Changes::GameMode);
Vishnu Naircfb2d252023-01-19 04:44:02 +0000295 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
Vishnu Naira02943f2023-06-03 13:44:46 -0700296 EXPECT_EQ(getSnapshot(1)->clientChanges, layer_state_t::eMetadataChanged);
Vishnu Naircfb2d252023-01-19 04:44:02 +0000297 EXPECT_EQ(static_cast<int32_t>(getSnapshot(1)->gameMode), 42);
298 EXPECT_EQ(static_cast<int32_t>(getSnapshot(11)->gameMode), 42);
299}
300
301TEST_F(LayerSnapshotTest, NoLayerVoteForParentWithChildVotes) {
302 // ROOT
303 // ├── 1
304 // │ ├── 11 (frame rate set)
305 // │ │ └── 111
306 // │ ├── 12
307 // │ │ ├── 121
308 // │ │ └── 122
309 // │ │ └── 1221
310 // │ └── 13
311 // └── 2
312
Vishnu Nair30515cb2023-10-19 21:54:08 -0700313 setFrameRate(11, 90.0, ANATIVEWINDOW_FRAME_RATE_EXACT, ANATIVEWINDOW_CHANGE_FRAME_RATE_ALWAYS);
Vishnu Naircfb2d252023-01-19 04:44:02 +0000314 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
315
Rachel Leece6e0042023-06-27 11:22:54 -0700316 EXPECT_EQ(getSnapshot(11)->frameRate.vote.rate.getIntValue(), 90);
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700317 EXPECT_EQ(getSnapshot(11)->frameRate.vote.type, scheduler::FrameRateCompatibility::Exact);
Rachel Leece6e0042023-06-27 11:22:54 -0700318 EXPECT_EQ(getSnapshot(111)->frameRate.vote.rate.getIntValue(), 90);
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700319 EXPECT_EQ(getSnapshot(111)->frameRate.vote.type, scheduler::FrameRateCompatibility::Exact);
Rachel Leece6e0042023-06-27 11:22:54 -0700320 EXPECT_EQ(getSnapshot(1)->frameRate.vote.rate.getIntValue(), 0);
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700321 EXPECT_EQ(getSnapshot(1)->frameRate.vote.type, scheduler::FrameRateCompatibility::NoVote);
Vishnu Naircfb2d252023-01-19 04:44:02 +0000322}
323
Vishnu Nair30515cb2023-10-19 21:54:08 -0700324TEST_F(LayerSnapshotTest, NoLayerVoteForParentWithChildVotesDoesNotAffectSiblings) {
325 // ROOT
326 // ├── 1 (verify layer has no vote)
327 // │ ├── 11 (frame rate set)
328 // │ │ └── 111
329 // │ ├── 12 (frame rate set)
330 // │ │ ├── 121
331 // │ │ └── 122
332 // │ │ └── 1221
333 // │ └── 13 (verify layer has default vote)
334 // └── 2
335
336 setFrameRate(11, 90.0, ANATIVEWINDOW_FRAME_RATE_EXACT, ANATIVEWINDOW_CHANGE_FRAME_RATE_ALWAYS);
337 setFrameRate(12, 45.0, ANATIVEWINDOW_FRAME_RATE_EXACT, ANATIVEWINDOW_CHANGE_FRAME_RATE_ALWAYS);
338
339 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
340
341 EXPECT_EQ(getSnapshot(11)->frameRate.vote.rate.getIntValue(), 90);
342 EXPECT_EQ(getSnapshot(11)->frameRate.vote.type, scheduler::FrameRateCompatibility::Exact);
343 EXPECT_EQ(getSnapshot(111)->frameRate.vote.rate.getIntValue(), 90);
344 EXPECT_EQ(getSnapshot(111)->frameRate.vote.type, scheduler::FrameRateCompatibility::Exact);
345 EXPECT_EQ(getSnapshot(12)->frameRate.vote.rate.getIntValue(), 45);
346 EXPECT_EQ(getSnapshot(12)->frameRate.vote.type, scheduler::FrameRateCompatibility::Exact);
347 EXPECT_EQ(getSnapshot(121)->frameRate.vote.rate.getIntValue(), 45);
348 EXPECT_EQ(getSnapshot(121)->frameRate.vote.type, scheduler::FrameRateCompatibility::Exact);
349 EXPECT_EQ(getSnapshot(1221)->frameRate.vote.rate.getIntValue(), 45);
350 EXPECT_EQ(getSnapshot(1221)->frameRate.vote.type, scheduler::FrameRateCompatibility::Exact);
351
352 EXPECT_EQ(getSnapshot(1)->frameRate.vote.rate.getIntValue(), 0);
353 EXPECT_EQ(getSnapshot(1)->frameRate.vote.type, scheduler::FrameRateCompatibility::NoVote);
354 EXPECT_EQ(getSnapshot(13)->frameRate.vote.rate.getIntValue(), 0);
355 EXPECT_EQ(getSnapshot(13)->frameRate.vote.type, scheduler::FrameRateCompatibility::Default);
356 EXPECT_EQ(getSnapshot(2)->frameRate.vote.rate.getIntValue(), 0);
357 EXPECT_EQ(getSnapshot(2)->frameRate.vote.type, scheduler::FrameRateCompatibility::Default);
358}
359
Vishnu Naira02943f2023-06-03 13:44:46 -0700360TEST_F(LayerSnapshotTest, CanCropTouchableRegion) {
Vishnu Nair29354ec2023-03-28 18:51:28 -0700361 // ROOT
362 // ├── 1
363 // │ ├── 11
364 // │ │ └── 111 (touchregion set to touch but cropped by layer 13)
365 // │ ├── 12
366 // │ │ ├── 121
367 // │ │ └── 122
368 // │ │ └── 1221
369 // │ └── 13 (crop set to touchCrop)
370 // └── 2
371
372 Rect touchCrop{300, 300, 400, 500};
373 setCrop(13, touchCrop);
374 Region touch{Rect{0, 0, 1000, 1000}};
375 setTouchableRegionCrop(111, touch, /*touchCropId=*/13, /*replaceTouchableRegionWithCrop=*/true);
376 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
377 EXPECT_EQ(getSnapshot({.id = 111})->inputInfo.touchableRegion.bounds(), touchCrop);
378
379 Rect modifiedTouchCrop{100, 300, 400, 700};
380 setCrop(13, modifiedTouchCrop);
381 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
382 EXPECT_EQ(getSnapshot({.id = 111})->inputInfo.touchableRegion.bounds(), modifiedTouchCrop);
383}
384
Chavi Weingarten1ba381e2024-01-09 21:54:11 +0000385TEST_F(LayerSnapshotTest, CanCropTouchableRegionWithDisplayTransform) {
386 DisplayInfo displayInfo;
387 displayInfo.transform = ui::Transform(ui::Transform::RotationFlags::ROT_90, 1000, 1000);
388 mFrontEndDisplayInfos.emplace_or_replace(ui::LayerStack::fromValue(1), displayInfo);
389
390 Rect touchCrop{300, 300, 400, 500};
391 createRootLayer(3);
392 setCrop(3, touchCrop);
393 setLayerStack(3, 1);
394 Region touch{Rect{0, 0, 1000, 1000}};
395 setTouchableRegionCrop(3, touch, /*touchCropId=*/3, /*replaceTouchableRegionWithCrop=*/false);
396
397 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 11, 111, 12, 121, 122, 1221, 13, 2, 3});
398 Rect rotatedCrop = {500, 300, 700, 400};
399 EXPECT_EQ(getSnapshot({.id = 3})->inputInfo.touchableRegion.bounds(), rotatedCrop);
400}
401
Vishnu Nair444f3952023-04-11 13:01:02 -0700402TEST_F(LayerSnapshotTest, blurUpdatesWhenAlphaChanges) {
Vishnu Nair854ce1c2023-08-19 15:00:13 -0700403 int blurRadius = 42;
404 setBackgroundBlurRadius(1221, static_cast<uint32_t>(blurRadius));
Vishnu Nair444f3952023-04-11 13:01:02 -0700405
406 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
407 EXPECT_EQ(getSnapshot({.id = 1221})->backgroundBlurRadius, blurRadius);
408
Vishnu Nair854ce1c2023-08-19 15:00:13 -0700409 blurRadius = 21;
410 setBackgroundBlurRadius(1221, static_cast<uint32_t>(blurRadius));
411 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
412 EXPECT_EQ(getSnapshot({.id = 1221})->backgroundBlurRadius, blurRadius);
413
Vishnu Nair444f3952023-04-11 13:01:02 -0700414 static constexpr float alpha = 0.5;
415 setAlpha(12, alpha);
416 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
Vishnu Nair854ce1c2023-08-19 15:00:13 -0700417 EXPECT_EQ(getSnapshot({.id = 1221})->backgroundBlurRadius,
418 static_cast<int>(static_cast<float>(blurRadius) * alpha));
Vishnu Nair444f3952023-04-11 13:01:02 -0700419}
420
Vishnu Naira9c43762023-01-27 19:10:25 +0000421// Display Mirroring Tests
422// tree with 3 levels of children
423// ROOT (DISPLAY 0)
424// ├── 1
425// │ ├── 11
426// │ │ └── 111
427// │ ├── 12 (has skip screenshot flag)
428// │ │ ├── 121
429// │ │ └── 122
430// │ │ └── 1221
431// │ └── 13
432// └── 2
433// ROOT (DISPLAY 1)
434// └── 3 (mirrors display 0)
Vishnu Nair92990e22023-02-24 20:01:05 +0000435TEST_F(LayerSnapshotTest, displayMirrorRespectsLayerSkipScreenshotFlag) {
Vishnu Naira9c43762023-01-27 19:10:25 +0000436 setFlags(12, layer_state_t::eLayerSkipScreenshot, layer_state_t::eLayerSkipScreenshot);
437 createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0));
438 setLayerStack(3, 1);
439
Vishnu Nair444f3952023-04-11 13:01:02 -0700440 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 +0000441 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
442}
443
Vishnu Nair92990e22023-02-24 20:01:05 +0000444// ROOT (DISPLAY 0)
445// ├── 1
446// │ ├── 11
447// │ │ └── 111
448// │ └── 13
449// └── 2
450// ROOT (DISPLAY 3)
451// └── 3 (mirrors display 0)
452TEST_F(LayerSnapshotTest, mirrorLayerGetsCorrectLayerStack) {
453 reparentLayer(12, UNASSIGNED_LAYER_ID);
454 createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0));
455 setLayerStack(3, 3);
456 createDisplayMirrorLayer(4, ui::LayerStack::fromValue(0));
457 setLayerStack(4, 4);
458
Vishnu Nair444f3952023-04-11 13:01:02 -0700459 std::vector<uint32_t> expected = {1, 11, 111, 13, 2, 3, 1, 11, 111,
460 13, 2, 4, 1, 11, 111, 13, 2};
Vishnu Nair92990e22023-02-24 20:01:05 +0000461 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
Vishnu Nair6f878312023-09-08 11:05:01 -0700462 EXPECT_EQ(getSnapshot({.id = 111, .mirrorRootIds = 3u})->outputFilter.layerStack.id, 3u);
463 EXPECT_EQ(getSnapshot({.id = 111, .mirrorRootIds = 4u})->outputFilter.layerStack.id, 4u);
Vishnu Nair92990e22023-02-24 20:01:05 +0000464}
465
466// ROOT (DISPLAY 0)
467// ├── 1 (crop 50x50)
468// │ ├── 11
469// │ │ └── 111
470// │ └── 13
471// └── 2
472// ROOT (DISPLAY 3)
473// └── 3 (mirrors display 0) (crop 100x100)
474TEST_F(LayerSnapshotTest, mirrorLayerTouchIsCroppedByMirrorRoot) {
475 reparentLayer(12, UNASSIGNED_LAYER_ID);
476 createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0));
477 setLayerStack(3, 3);
478 setCrop(1, Rect{50, 50});
479 setCrop(3, Rect{100, 100});
480 setCrop(111, Rect{200, 200});
481 Region touch{Rect{0, 0, 1000, 1000}};
482 setTouchableRegion(111, touch);
Vishnu Nair444f3952023-04-11 13:01:02 -0700483 std::vector<uint32_t> expected = {1, 11, 111, 13, 2, 3, 1, 11, 111, 13, 2};
Vishnu Nair92990e22023-02-24 20:01:05 +0000484 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
485 EXPECT_TRUE(getSnapshot({.id = 111})->inputInfo.touchableRegion.hasSameRects(touch));
486 Region touchCroppedByMirrorRoot{Rect{0, 0, 50, 50}};
Vishnu Nair6f878312023-09-08 11:05:01 -0700487 EXPECT_TRUE(getSnapshot({.id = 111, .mirrorRootIds = 3u})
Vishnu Nair92990e22023-02-24 20:01:05 +0000488 ->inputInfo.touchableRegion.hasSameRects(touchCroppedByMirrorRoot));
489}
490
491TEST_F(LayerSnapshotTest, canRemoveDisplayMirror) {
492 setFlags(12, layer_state_t::eLayerSkipScreenshot, layer_state_t::eLayerSkipScreenshot);
493 createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0));
494 setLayerStack(3, 1);
Vishnu Nair444f3952023-04-11 13:01:02 -0700495 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 +0000496 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
497 destroyLayerHandle(3);
498 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
499}
500
Vishnu Nairfccd6362023-02-24 23:39:53 +0000501TEST_F(LayerSnapshotTest, cleanUpUnreachableSnapshotsAfterMirroring) {
502 size_t startingNumSnapshots = mSnapshotBuilder.getSnapshots().size();
503 createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0));
504 setLayerStack(3, 1);
Vishnu Nair444f3952023-04-11 13:01:02 -0700505 std::vector<uint32_t> expected = {1, 11, 111, 12, 121, 122, 1221, 13, 2, 3,
506 1, 11, 111, 12, 121, 122, 1221, 13, 2};
Vishnu Nairfccd6362023-02-24 23:39:53 +0000507 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
508 destroyLayerHandle(3);
509 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
510
511 EXPECT_EQ(startingNumSnapshots, mSnapshotBuilder.getSnapshots().size());
512}
513
Vishnu Nair6f878312023-09-08 11:05:01 -0700514TEST_F(LayerSnapshotTest, canMirrorDisplayWithMirrors) {
515 reparentLayer(12, UNASSIGNED_LAYER_ID);
516 mirrorLayer(/*layer*/ 14, /*parent*/ 1, /*layerToMirror*/ 11);
517 std::vector<uint32_t> expected = {1, 11, 111, 13, 14, 11, 111, 2};
518 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
519
520 createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0));
521 setLayerStack(3, 3);
522 expected = {1, 11, 111, 13, 14, 11, 111, 2, 3, 1, 11, 111, 13, 14, 11, 111, 2};
523 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
524 EXPECT_EQ(getSnapshot({.id = 11, .mirrorRootIds = 14u})->outputFilter.layerStack.id, 0u);
525 EXPECT_EQ(getSnapshot({.id = 11, .mirrorRootIds = 3u})->outputFilter.layerStack.id, 3u);
526 EXPECT_EQ(getSnapshot({.id = 11, .mirrorRootIds = 3u, 14u})->outputFilter.layerStack.id, 3u);
527}
528
Vishnu Nairfccd6362023-02-24 23:39:53 +0000529// Rel z doesn't create duplicate snapshots but this is for completeness
530TEST_F(LayerSnapshotTest, cleanUpUnreachableSnapshotsAfterRelZ) {
531 size_t startingNumSnapshots = mSnapshotBuilder.getSnapshots().size();
532 reparentRelativeLayer(13, 11);
533 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 11, 13, 111, 12, 121, 122, 1221, 2});
534 setZ(13, 0);
535 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
536
537 EXPECT_EQ(startingNumSnapshots, mSnapshotBuilder.getSnapshots().size());
538}
539
540TEST_F(LayerSnapshotTest, cleanUpUnreachableSnapshotsAfterLayerDestruction) {
541 size_t startingNumSnapshots = mSnapshotBuilder.getSnapshots().size();
542 destroyLayerHandle(2);
543 destroyLayerHandle(122);
544
545 std::vector<uint32_t> expected = {1, 11, 111, 12, 121, 122, 1221, 13};
546 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
547
548 EXPECT_LE(startingNumSnapshots - 2, mSnapshotBuilder.getSnapshots().size());
549}
550
Vishnu Nair3d8565a2023-06-30 07:23:24 +0000551TEST_F(LayerSnapshotTest, snashotContainsMetadataFromLayerCreationArgs) {
552 LayerCreationArgs args(std::make_optional<uint32_t>(200));
553 args.name = "testlayer";
554 args.addToRoot = true;
555 args.metadata.setInt32(42, 24);
556
557 std::vector<std::unique_ptr<RequestedLayerState>> layers;
558 layers.emplace_back(std::make_unique<RequestedLayerState>(args));
559 EXPECT_TRUE(layers.back()->metadata.has(42));
560 EXPECT_EQ(layers.back()->metadata.getInt32(42, 0), 24);
561 mLifecycleManager.addLayers(std::move(layers));
562
563 std::vector<uint32_t> expected = STARTING_ZORDER;
564 expected.push_back(200);
565 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
566
567 EXPECT_TRUE(mSnapshotBuilder.getSnapshot(200)->layerMetadata.has(42));
568 EXPECT_EQ(mSnapshotBuilder.getSnapshot(200)->layerMetadata.getInt32(42, 0), 24);
569}
570
571TEST_F(LayerSnapshotTest, frameRateSelectionPriorityPassedToChildLayers) {
572 setFrameRateSelectionPriority(11, 1);
573
574 setFrameRateSelectionPriority(12, 2);
575
576 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
577 EXPECT_EQ(getSnapshot({.id = 1})->frameRateSelectionPriority, Layer::PRIORITY_UNSET);
578 EXPECT_EQ(getSnapshot({.id = 11})->frameRateSelectionPriority, 1);
579 EXPECT_EQ(getSnapshot({.id = 12})->frameRateSelectionPriority, 2);
580 EXPECT_EQ(getSnapshot({.id = 122})->frameRateSelectionPriority, 2);
581 EXPECT_EQ(getSnapshot({.id = 1221})->frameRateSelectionPriority, 2);
582
583 // reparent and verify the child gets the new parent's framerate selection priority
584 reparentLayer(122, 11);
585
586 std::vector<uint32_t> expected = {1, 11, 111, 122, 1221, 12, 121, 13, 2};
587 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
588 EXPECT_EQ(getSnapshot({.id = 1})->frameRateSelectionPriority, Layer::PRIORITY_UNSET);
589 EXPECT_EQ(getSnapshot({.id = 11})->frameRateSelectionPriority, 1);
590 EXPECT_EQ(getSnapshot({.id = 12})->frameRateSelectionPriority, 2);
591 EXPECT_EQ(getSnapshot({.id = 122})->frameRateSelectionPriority, 1);
592 EXPECT_EQ(getSnapshot({.id = 1221})->frameRateSelectionPriority, 1);
593}
594
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000595TEST_F(LayerSnapshotTest, framerate) {
596 setFrameRate(11, 244.f, 0, 0);
597
598 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
599 // verify parent is gets no vote
Rachel Leece6e0042023-06-27 11:22:54 -0700600 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
601 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700602 scheduler::FrameRateCompatibility::NoVote);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000603 EXPECT_TRUE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate));
604
605 // verify layer and children get the requested votes
Rachel Leece6e0042023-06-27 11:22:54 -0700606 EXPECT_TRUE(getSnapshot({.id = 11})->frameRate.vote.rate.isValid());
607 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 244.f);
608 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700609 scheduler::FrameRateCompatibility::Default);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000610 EXPECT_TRUE(getSnapshot({.id = 11})->changes.test(RequestedLayerState::Changes::FrameRate));
611
Rachel Leece6e0042023-06-27 11:22:54 -0700612 EXPECT_TRUE(getSnapshot({.id = 111})->frameRate.vote.rate.isValid());
613 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.rate.getValue(), 244.f);
614 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700615 scheduler::FrameRateCompatibility::Default);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000616 EXPECT_TRUE(getSnapshot({.id = 111})->changes.test(RequestedLayerState::Changes::FrameRate));
617
618 // reparent and verify the child gets the new parent's framerate
619 reparentLayer(122, 11);
620
621 std::vector<uint32_t> expected = {1, 11, 111, 122, 1221, 12, 121, 13, 2};
622 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
623 // verify parent is gets no vote
Rachel Leece6e0042023-06-27 11:22:54 -0700624 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
625 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700626 scheduler::FrameRateCompatibility::NoVote);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000627
628 // verify layer and children get the requested votes
Rachel Leece6e0042023-06-27 11:22:54 -0700629 EXPECT_TRUE(getSnapshot({.id = 11})->frameRate.vote.rate.isValid());
630 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 244.f);
631 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700632 scheduler::FrameRateCompatibility::Default);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000633
Rachel Leece6e0042023-06-27 11:22:54 -0700634 EXPECT_TRUE(getSnapshot({.id = 111})->frameRate.vote.rate.isValid());
635 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.rate.getValue(), 244.f);
636 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700637 scheduler::FrameRateCompatibility::Default);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000638
Rachel Leece6e0042023-06-27 11:22:54 -0700639 EXPECT_TRUE(getSnapshot({.id = 122})->frameRate.vote.rate.isValid());
640 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.rate.getValue(), 244.f);
641 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700642 scheduler::FrameRateCompatibility::Default);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000643 EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate));
644
645 // reparent and verify the new parent gets no vote
646 reparentLayer(11, 2);
647 expected = {1, 12, 121, 13, 2, 11, 111, 122, 1221};
648 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
649
650 // verify old parent has invalid framerate (default)
Rachel Leece6e0042023-06-27 11:22:54 -0700651 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
652 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700653 scheduler::FrameRateCompatibility::Default);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000654 EXPECT_TRUE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate));
655
656 // verify new parent get no vote
Rachel Leece6e0042023-06-27 11:22:54 -0700657 EXPECT_FALSE(getSnapshot({.id = 2})->frameRate.vote.rate.isValid());
658 EXPECT_EQ(getSnapshot({.id = 2})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700659 scheduler::FrameRateCompatibility::NoVote);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000660 EXPECT_TRUE(getSnapshot({.id = 2})->changes.test(RequestedLayerState::Changes::FrameRate));
661
662 // verify layer and children get the requested votes (unchanged)
Rachel Leece6e0042023-06-27 11:22:54 -0700663 EXPECT_TRUE(getSnapshot({.id = 11})->frameRate.vote.rate.isValid());
664 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 244.f);
665 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700666 scheduler::FrameRateCompatibility::Default);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000667
Rachel Leece6e0042023-06-27 11:22:54 -0700668 EXPECT_TRUE(getSnapshot({.id = 111})->frameRate.vote.rate.isValid());
669 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.rate.getValue(), 244.f);
670 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700671 scheduler::FrameRateCompatibility::Default);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000672
Rachel Leece6e0042023-06-27 11:22:54 -0700673 EXPECT_TRUE(getSnapshot({.id = 122})->frameRate.vote.rate.isValid());
674 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.rate.getValue(), 244.f);
675 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700676 scheduler::FrameRateCompatibility::Default);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000677}
678
Vishnu Nair3996ee32023-08-14 04:32:31 +0000679TEST_F(LayerSnapshotTest, translateDataspace) {
680 setDataspace(1, ui::Dataspace::UNKNOWN);
681 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
682 EXPECT_EQ(getSnapshot({.id = 1})->dataspace, ui::Dataspace::V0_SRGB);
683}
684
Rachel Leece6e0042023-06-27 11:22:54 -0700685// This test is similar to "frameRate" test case but checks that the setFrameRateCategory API
686// interaction also works correctly with the setFrameRate API within SF frontend.
687TEST_F(LayerSnapshotTest, frameRateWithCategory) {
Rachel Lee45681982024-03-14 18:40:15 -0700688 SET_FLAG_FOR_TEST(flags::frame_rate_category_mrr, true);
689
Rachel Leece6e0042023-06-27 11:22:54 -0700690 // ROOT
691 // ├── 1
692 // │ ├── 11 (frame rate set to 244.f)
693 // │ │ └── 111
694 // │ ├── 12
695 // │ │ ├── 121
696 // │ │ └── 122 (frame rate category set to Normal)
697 // │ │ └── 1221
698 // │ └── 13
699 // └── 2
700 setFrameRate(11, 244.f, 0, 0);
Rachel Lee9580ff12023-12-26 17:33:41 -0800701 setFrameRateCategory(122, ANATIVEWINDOW_FRAME_RATE_CATEGORY_NORMAL);
Rachel Leece6e0042023-06-27 11:22:54 -0700702
703 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
704 // verify parent 1 gets no vote
705 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
706 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700707 scheduler::FrameRateCompatibility::NoVote);
Rachel Leece6e0042023-06-27 11:22:54 -0700708 EXPECT_TRUE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate));
709
710 // verify layer 11 and children 111 get the requested votes
711 EXPECT_TRUE(getSnapshot({.id = 11})->frameRate.vote.rate.isValid());
712 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 244.f);
713 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700714 scheduler::FrameRateCompatibility::Default);
Rachel Leece6e0042023-06-27 11:22:54 -0700715 EXPECT_TRUE(getSnapshot({.id = 11})->changes.test(RequestedLayerState::Changes::FrameRate));
716
717 EXPECT_TRUE(getSnapshot({.id = 111})->frameRate.vote.rate.isValid());
718 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.rate.getValue(), 244.f);
719 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700720 scheduler::FrameRateCompatibility::Default);
Rachel Leece6e0042023-06-27 11:22:54 -0700721 EXPECT_TRUE(getSnapshot({.id = 111})->changes.test(RequestedLayerState::Changes::FrameRate));
722
723 // verify parent 12 gets no vote
724 EXPECT_FALSE(getSnapshot({.id = 12})->frameRate.vote.rate.isValid());
725 EXPECT_EQ(getSnapshot({.id = 12})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700726 scheduler::FrameRateCompatibility::NoVote);
Rachel Leece6e0042023-06-27 11:22:54 -0700727 EXPECT_TRUE(getSnapshot({.id = 12})->changes.test(RequestedLayerState::Changes::FrameRate));
728
729 // verify layer 122 and children 1221 get the requested votes
730 EXPECT_FALSE(getSnapshot({.id = 122})->frameRate.vote.rate.isValid());
731 EXPECT_TRUE(getSnapshot({.id = 122})->frameRate.isValid());
732 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700733 scheduler::FrameRateCompatibility::Default);
Rachel Leece6e0042023-06-27 11:22:54 -0700734 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.category, FrameRateCategory::Normal);
735 EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate));
Rachel Lee43369b22023-09-05 18:40:40 -0700736 EXPECT_TRUE(
737 getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::AffectsChildren));
Rachel Leece6e0042023-06-27 11:22:54 -0700738
739 EXPECT_FALSE(getSnapshot({.id = 1221})->frameRate.vote.rate.isValid());
740 EXPECT_TRUE(getSnapshot({.id = 1221})->frameRate.isValid());
741 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700742 scheduler::FrameRateCompatibility::Default);
Rachel Leece6e0042023-06-27 11:22:54 -0700743 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.category, FrameRateCategory::Normal);
744 EXPECT_TRUE(getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::FrameRate));
Rachel Lee43369b22023-09-05 18:40:40 -0700745 EXPECT_TRUE(
746 getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::AffectsChildren));
Rachel Leece6e0042023-06-27 11:22:54 -0700747
748 // reparent and verify the child does NOT get the new parent's framerate because it already has
749 // the frame rate category specified.
750 // ROOT
751 // ├─1
752 // │ ├─11 (frame rate set to 244.f)
753 // │ │ ├─111
754 // │ │ └─122 (frame rate category set to Normal)
755 // │ │ └─1221
756 // │ ├─12
757 // │ │ └─121
758 // │ └─13
759 // └─2
760 reparentLayer(122, 11);
761
762 std::vector<uint32_t> expected = {1, 11, 111, 122, 1221, 12, 121, 13, 2};
763 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
764 // verify parent is gets no vote
765 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
766 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700767 scheduler::FrameRateCompatibility::NoVote);
Rachel Leece6e0042023-06-27 11:22:54 -0700768
769 // verify layer 11 and children 111 get the requested votes
770 EXPECT_TRUE(getSnapshot({.id = 11})->frameRate.vote.rate.isValid());
771 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 244.f);
772 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700773 scheduler::FrameRateCompatibility::Default);
Rachel Leece6e0042023-06-27 11:22:54 -0700774
775 EXPECT_TRUE(getSnapshot({.id = 111})->frameRate.vote.rate.isValid());
776 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.rate.getValue(), 244.f);
777 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700778 scheduler::FrameRateCompatibility::Default);
Rachel Leece6e0042023-06-27 11:22:54 -0700779
780 // verify layer 122 and children 1221 get the requested category vote (unchanged from
781 // reparenting)
782 EXPECT_FALSE(getSnapshot({.id = 122})->frameRate.vote.rate.isValid());
783 EXPECT_TRUE(getSnapshot({.id = 122})->frameRate.isValid());
784 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700785 scheduler::FrameRateCompatibility::Default);
Rachel Leece6e0042023-06-27 11:22:54 -0700786 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.category, FrameRateCategory::Normal);
787 EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate));
788
789 EXPECT_FALSE(getSnapshot({.id = 1221})->frameRate.vote.rate.isValid());
790 EXPECT_TRUE(getSnapshot({.id = 1221})->frameRate.isValid());
791 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700792 scheduler::FrameRateCompatibility::Default);
Rachel Leece6e0042023-06-27 11:22:54 -0700793 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.category, FrameRateCategory::Normal);
794 EXPECT_TRUE(getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::FrameRate));
795}
796
Rachel Lee58cc90d2023-09-05 18:50:20 -0700797TEST_F(LayerSnapshotTest, frameRateSelectionStrategy) {
798 // ROOT
799 // ├── 1
800 // │ ├── 11
801 // │ │ └── 111
802 // │ ├── 12 (frame rate set to 244.f with strategy OverrideChildren)
803 // │ │ ├── 121
804 // │ │ └── 122 (frame rate set to 123.f but should be overridden by layer 12)
805 // │ │ └── 1221
806 // │ └── 13
807 // └── 2
808 setFrameRate(12, 244.f, 0, 0);
809 setFrameRate(122, 123.f, 0, 0);
810 setFrameRateSelectionStrategy(12, 1 /* OverrideChildren */);
811
812 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
813 // verify parent 1 gets no vote
814 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
815 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700816 scheduler::FrameRateCompatibility::NoVote);
Rachel Lee58cc90d2023-09-05 18:50:20 -0700817 EXPECT_TRUE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate));
818
819 // verify layer 12 and all descendants (121, 122, 1221) get the requested vote
820 EXPECT_EQ(getSnapshot({.id = 12})->frameRate.vote.rate.getValue(), 244.f);
821 EXPECT_EQ(getSnapshot({.id = 12})->frameRateSelectionStrategy,
822 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
823 EXPECT_TRUE(getSnapshot({.id = 12})->changes.test(RequestedLayerState::Changes::FrameRate));
824
825 EXPECT_EQ(getSnapshot({.id = 121})->frameRate.vote.rate.getValue(), 244.f);
826 EXPECT_EQ(getSnapshot({.id = 121})->frameRateSelectionStrategy,
827 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
828 EXPECT_TRUE(getSnapshot({.id = 121})->changes.test(RequestedLayerState::Changes::FrameRate));
829
830 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.rate.getValue(), 244.f);
831 EXPECT_EQ(getSnapshot({.id = 122})->frameRateSelectionStrategy,
832 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
833 EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate));
834
835 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.vote.rate.getValue(), 244.f);
836 EXPECT_EQ(getSnapshot({.id = 1221})->frameRateSelectionStrategy,
837 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
838 EXPECT_TRUE(getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::FrameRate));
Vishnu Nair41376b62023-11-08 05:08:58 -0800839
840 // ROOT
841 // ├── 1
842 // │ ├── 11
843 // │ │ └── 111
844 // │ ├── 12 (frame rate set to default with strategy default)
845 // │ │ ├── 121
846 // │ │ └── 122 (frame rate set to 123.f)
847 // │ │ └── 1221
848 // │ └── 13
849 // └── 2
850 setFrameRate(12, -1.f, 0, 0);
851 setFrameRateSelectionStrategy(12, 0 /* Default */);
852 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
853 // verify parent 1 gets no vote
854 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
855 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
856 scheduler::FrameRateCompatibility::NoVote);
857 EXPECT_FALSE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate));
858
859 // verify layer 12 and all descendants (121, 122, 1221) get the requested vote
860 EXPECT_FALSE(getSnapshot({.id = 12})->frameRate.vote.rate.isValid());
861 EXPECT_EQ(getSnapshot({.id = 12})->frameRate.vote.type,
862 scheduler::FrameRateCompatibility::NoVote);
863 EXPECT_EQ(getSnapshot({.id = 12})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -0800864 scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate);
Vishnu Nair41376b62023-11-08 05:08:58 -0800865 EXPECT_TRUE(getSnapshot({.id = 12})->changes.test(RequestedLayerState::Changes::FrameRate));
866
867 EXPECT_FALSE(getSnapshot({.id = 121})->frameRate.vote.rate.isValid());
868 EXPECT_EQ(getSnapshot({.id = 121})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -0800869 scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate);
Vishnu Nair41376b62023-11-08 05:08:58 -0800870 EXPECT_EQ(getSnapshot({.id = 121})->frameRate.vote.type,
871 scheduler::FrameRateCompatibility::Default);
872 EXPECT_TRUE(getSnapshot({.id = 121})->changes.test(RequestedLayerState::Changes::FrameRate));
873
874 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.rate.getValue(), 123.f);
875 EXPECT_EQ(getSnapshot({.id = 122})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -0800876 scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate);
Vishnu Nair41376b62023-11-08 05:08:58 -0800877 EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate));
878
879 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.vote.rate.getValue(), 123.f);
880 EXPECT_EQ(getSnapshot({.id = 1221})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -0800881 scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate);
Vishnu Nair41376b62023-11-08 05:08:58 -0800882 EXPECT_TRUE(getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::FrameRate));
883}
884
885TEST_F(LayerSnapshotTest, frameRateSelectionStrategyWithCategory) {
Rachel Lee45681982024-03-14 18:40:15 -0700886 SET_FLAG_FOR_TEST(flags::frame_rate_category_mrr, true);
887
Vishnu Nair41376b62023-11-08 05:08:58 -0800888 // ROOT
889 // ├── 1
890 // │ ├── 11
891 // │ │ └── 111
892 // │ ├── 12 (frame rate category set to high with strategy OverrideChildren)
893 // │ │ ├── 121
894 // │ │ └── 122 (frame rate set to 123.f but should be overridden by layer 12)
895 // │ │ └── 1221
896 // │ └── 13
897 // └── 2
Rachel Lee9580ff12023-12-26 17:33:41 -0800898 setFrameRateCategory(12, ANATIVEWINDOW_FRAME_RATE_CATEGORY_HIGH);
Vishnu Nair41376b62023-11-08 05:08:58 -0800899 setFrameRate(122, 123.f, 0, 0);
900 setFrameRateSelectionStrategy(12, 1 /* OverrideChildren */);
901
902 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
903 // verify parent 1 gets no vote
904 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
905 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
906 scheduler::FrameRateCompatibility::NoVote);
907 EXPECT_TRUE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate));
908
909 // verify layer 12 and all descendants (121, 122, 1221) get the requested vote
910 EXPECT_EQ(getSnapshot({.id = 12})->frameRate.category, FrameRateCategory::High);
911 EXPECT_EQ(getSnapshot({.id = 12})->frameRateSelectionStrategy,
912 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
913 EXPECT_TRUE(getSnapshot({.id = 12})->changes.test(RequestedLayerState::Changes::FrameRate));
914
915 EXPECT_EQ(getSnapshot({.id = 121})->frameRate.category, FrameRateCategory::High);
916 EXPECT_EQ(getSnapshot({.id = 121})->frameRateSelectionStrategy,
917 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
918 EXPECT_TRUE(getSnapshot({.id = 121})->changes.test(RequestedLayerState::Changes::FrameRate));
919
920 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.category, FrameRateCategory::High);
921 EXPECT_EQ(getSnapshot({.id = 122})->frameRateSelectionStrategy,
922 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
923 EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate));
924
925 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.category, FrameRateCategory::High);
926 EXPECT_EQ(getSnapshot({.id = 1221})->frameRateSelectionStrategy,
927 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
928 EXPECT_TRUE(getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::FrameRate));
929
930 // ROOT
931 // ├── 1
932 // │ ├── 11
933 // │ │ └── 111
934 // │ ├── 12 (frame rate category to default with strategy default)
935 // │ │ ├── 121
936 // │ │ └── 122 (frame rate set to 123.f)
937 // │ │ └── 1221
938 // │ └── 13
939 // └── 2
Rachel Lee9580ff12023-12-26 17:33:41 -0800940 setFrameRateCategory(12, ANATIVEWINDOW_FRAME_RATE_CATEGORY_DEFAULT);
Vishnu Nair41376b62023-11-08 05:08:58 -0800941 setFrameRateSelectionStrategy(12, 0 /* Default */);
942 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
943 // verify parent 1 gets no vote
944 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
945 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
946 scheduler::FrameRateCompatibility::NoVote);
947 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.category, FrameRateCategory::Default);
948 EXPECT_FALSE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate));
949
950 // verify layer 12 and all descendants (121, 122, 1221) get the requested vote
951 EXPECT_FALSE(getSnapshot({.id = 12})->frameRate.vote.rate.isValid());
952 EXPECT_EQ(getSnapshot({.id = 12})->frameRate.vote.type,
953 scheduler::FrameRateCompatibility::NoVote);
954 EXPECT_EQ(getSnapshot({.id = 12})->frameRate.category, FrameRateCategory::Default);
955 EXPECT_EQ(getSnapshot({.id = 12})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -0800956 scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate);
Vishnu Nair41376b62023-11-08 05:08:58 -0800957 EXPECT_TRUE(getSnapshot({.id = 12})->changes.test(RequestedLayerState::Changes::FrameRate));
958
959 EXPECT_FALSE(getSnapshot({.id = 12})->frameRate.vote.rate.isValid());
960 EXPECT_EQ(getSnapshot({.id = 121})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -0800961 scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate);
Vishnu Nair41376b62023-11-08 05:08:58 -0800962 EXPECT_EQ(getSnapshot({.id = 121})->frameRate.category, FrameRateCategory::Default);
963 EXPECT_EQ(getSnapshot({.id = 121})->frameRate.vote.type,
964 scheduler::FrameRateCompatibility::Default);
965 EXPECT_TRUE(getSnapshot({.id = 121})->changes.test(RequestedLayerState::Changes::FrameRate));
966
967 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.rate.getValue(), 123.f);
968 EXPECT_EQ(getSnapshot({.id = 122})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -0800969 scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate);
Vishnu Nair41376b62023-11-08 05:08:58 -0800970 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.category, FrameRateCategory::Default);
971 EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate));
972
973 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.vote.rate.getValue(), 123.f);
974 EXPECT_EQ(getSnapshot({.id = 1221})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -0800975 scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate);
Vishnu Nair41376b62023-11-08 05:08:58 -0800976 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.category, FrameRateCategory::Default);
977 EXPECT_TRUE(getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::FrameRate));
Rachel Lee58cc90d2023-09-05 18:50:20 -0700978}
979
Rachel Lee70f7b692023-11-22 11:24:02 -0800980TEST_F(LayerSnapshotTest, frameRateSelectionStrategyWithOverrideChildrenAndSelf) {
Rachel Leea021bb02023-11-20 21:51:09 -0800981 // ROOT
982 // ├── 1
Rachel Lee70f7b692023-11-22 11:24:02 -0800983 // │ ├── 11 (frame rate set to 11.f with strategy Self)
Rachel Leea021bb02023-11-20 21:51:09 -0800984 // │ │ └── 111 (frame rate is not inherited)
985 // │ ├── 12 (frame rate set to 244.f)
986 // │ │ ├── 121
987 // │ │ └── 122 (strategy OverrideChildren and inherits frame rate 244.f)
988 // │ │ └── 1221 (frame rate set to 123.f but should be overridden by layer 122)
989 // │ └── 13
990 // └── 2
991 setFrameRate(11, 11.f, 0, 0);
Rachel Lee70f7b692023-11-22 11:24:02 -0800992 setFrameRateSelectionStrategy(11, 2 /* Self */);
Rachel Leea021bb02023-11-20 21:51:09 -0800993 setFrameRate(12, 244.f, 0, 0);
994 setFrameRateSelectionStrategy(122, 1 /* OverrideChildren */);
995 setFrameRate(1221, 123.f, 0, 0);
996
997 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
998 // verify parent 1 gets no vote
999 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
1000 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
1001 scheduler::FrameRateCompatibility::NoVote);
1002 EXPECT_EQ(getSnapshot({.id = 1})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -08001003 scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate);
Rachel Leea021bb02023-11-20 21:51:09 -08001004 EXPECT_TRUE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate));
1005
1006 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 11.f);
1007 EXPECT_EQ(getSnapshot({.id = 11})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -08001008 scheduler::LayerInfo::FrameRateSelectionStrategy::Self);
Rachel Leea021bb02023-11-20 21:51:09 -08001009 EXPECT_TRUE(getSnapshot({.id = 11})->changes.test(RequestedLayerState::Changes::FrameRate));
1010
1011 // verify layer 11 does does not propagate its framerate to 111.
1012 EXPECT_FALSE(getSnapshot({.id = 111})->frameRate.vote.rate.isValid());
1013 EXPECT_EQ(getSnapshot({.id = 111})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -08001014 scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate);
Rachel Leea021bb02023-11-20 21:51:09 -08001015 EXPECT_TRUE(getSnapshot({.id = 111})->changes.test(RequestedLayerState::Changes::FrameRate));
1016
1017 // verify layer 12 and all descendants (121, 122, 1221) get the requested vote
1018 EXPECT_EQ(getSnapshot({.id = 12})->frameRate.vote.rate.getValue(), 244.f);
1019 EXPECT_EQ(getSnapshot({.id = 12})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -08001020 scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate);
Rachel Leea021bb02023-11-20 21:51:09 -08001021 EXPECT_TRUE(getSnapshot({.id = 12})->changes.test(RequestedLayerState::Changes::FrameRate));
1022
1023 EXPECT_EQ(getSnapshot({.id = 121})->frameRate.vote.rate.getValue(), 244.f);
1024 EXPECT_EQ(getSnapshot({.id = 121})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -08001025 scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate);
Rachel Leea021bb02023-11-20 21:51:09 -08001026 EXPECT_TRUE(getSnapshot({.id = 121})->changes.test(RequestedLayerState::Changes::FrameRate));
1027
1028 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.rate.getValue(), 244.f);
1029 EXPECT_EQ(getSnapshot({.id = 122})->frameRateSelectionStrategy,
1030 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
1031 EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate));
1032
1033 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.vote.rate.getValue(), 244.f);
1034 EXPECT_EQ(getSnapshot({.id = 1221})->frameRateSelectionStrategy,
1035 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
1036 EXPECT_TRUE(getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::FrameRate));
1037
1038 // ROOT
1039 // ├── 1 (frame rate set to 1.f with strategy OverrideChildren)
Rachel Lee70f7b692023-11-22 11:24:02 -08001040 // │ ├── 11 (frame rate set to 11.f with strategy Self, but overridden by 1)
Rachel Leea021bb02023-11-20 21:51:09 -08001041 // │ │ └── 111 (frame rate inherited from 11 due to override from 1)
1042 // â‹® â‹®
1043 setFrameRate(1, 1.f, 0, 0);
1044 setFrameRateSelectionStrategy(1, 1 /* OverrideChildren */);
1045 setFrameRate(11, 11.f, 0, 0);
Rachel Lee70f7b692023-11-22 11:24:02 -08001046 setFrameRateSelectionStrategy(11, 2 /* Self */);
Rachel Leea021bb02023-11-20 21:51:09 -08001047 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1048
1049 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.rate.getValue(), 1.f);
1050 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
1051 scheduler::FrameRateCompatibility::Default);
1052 EXPECT_EQ(getSnapshot({.id = 1})->frameRateSelectionStrategy,
1053 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
1054 EXPECT_TRUE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate));
1055
1056 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 1.f);
1057 EXPECT_EQ(getSnapshot({.id = 11})->frameRateSelectionStrategy,
1058 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
1059 EXPECT_TRUE(getSnapshot({.id = 11})->changes.test(RequestedLayerState::Changes::FrameRate));
1060
1061 // verify layer 11 does does not propagate its framerate to 111.
1062 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.rate.getValue(), 1.f);
1063 EXPECT_EQ(getSnapshot({.id = 111})->frameRateSelectionStrategy,
1064 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
1065 EXPECT_TRUE(getSnapshot({.id = 111})->changes.test(RequestedLayerState::Changes::FrameRate));
1066}
1067
Vishnu Nair0808ae62023-08-07 21:42:42 -07001068TEST_F(LayerSnapshotTest, skipRoundCornersWhenProtected) {
1069 setRoundedCorners(1, 42.f);
1070 setRoundedCorners(2, 42.f);
1071 setCrop(1, Rect{1000, 1000});
1072 setCrop(2, Rect{1000, 1000});
1073
1074 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1075 EXPECT_TRUE(getSnapshot({.id = 1})->roundedCorner.hasRoundedCorners());
1076 EXPECT_EQ(getSnapshot({.id = 1})->roundedCorner.radius.x, 42.f);
1077 EXPECT_TRUE(getSnapshot({.id = 2})->roundedCorner.hasRoundedCorners());
1078
1079 // add a buffer with the protected bit, check rounded corners are not set when
1080 // skipRoundCornersWhenProtected == true
1081 setBuffer(1,
1082 std::make_shared<
1083 renderengine::mock::FakeExternalTexture>(1U /*width*/, 1U /*height*/,
1084 1ULL /* bufferId */,
1085 HAL_PIXEL_FORMAT_RGBA_8888,
1086 GRALLOC_USAGE_PROTECTED /*usage*/));
1087
1088 LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(),
1089 .layerLifecycleManager = mLifecycleManager,
1090 .includeMetadata = false,
1091 .displays = mFrontEndDisplayInfos,
1092 .displayChanges = false,
1093 .globalShadowSettings = globalShadowSettings,
1094 .supportsBlur = true,
1095 .supportedLayerGenericMetadata = {},
1096 .genericLayerMetadataKeyMap = {},
1097 .skipRoundCornersWhenProtected = true};
1098 update(mSnapshotBuilder, args);
1099 EXPECT_FALSE(getSnapshot({.id = 1})->roundedCorner.hasRoundedCorners());
1100 // layer 2 doesn't have a buffer and should be unaffected
1101 EXPECT_TRUE(getSnapshot({.id = 2})->roundedCorner.hasRoundedCorners());
1102
1103 // remove protected bit, check rounded corners are set
1104 setBuffer(1,
1105 std::make_shared<renderengine::mock::FakeExternalTexture>(1U /*width*/, 1U /*height*/,
1106 2ULL /* bufferId */,
1107 HAL_PIXEL_FORMAT_RGBA_8888,
1108 0 /*usage*/));
1109 update(mSnapshotBuilder, args);
1110 EXPECT_TRUE(getSnapshot({.id = 1})->roundedCorner.hasRoundedCorners());
1111 EXPECT_EQ(getSnapshot({.id = 1})->roundedCorner.radius.x, 42.f);
1112}
1113
Vishnu Nairbd51f952023-08-31 22:50:14 -07001114TEST_F(LayerSnapshotTest, setRefreshRateIndicatorCompositionType) {
1115 setFlags(1, layer_state_t::eLayerIsRefreshRateIndicator,
1116 layer_state_t::eLayerIsRefreshRateIndicator);
1117 setBuffer(1,
1118 std::make_shared<renderengine::mock::FakeExternalTexture>(1U /*width*/, 1U /*height*/,
1119 42ULL /* bufferId */,
1120 HAL_PIXEL_FORMAT_RGBA_8888,
1121 0 /*usage*/));
1122 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1123 EXPECT_EQ(getSnapshot({.id = 1})->compositionType,
1124 aidl::android::hardware::graphics::composer3::Composition::REFRESH_RATE_INDICATOR);
1125}
1126
Chavi Weingarten07597342023-09-14 21:10:59 +00001127TEST_F(LayerSnapshotTest, setBufferCrop) {
1128 // validate no buffer but has crop
1129 Rect crop = Rect(0, 0, 50, 50);
1130 setBufferCrop(1, crop);
1131 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1132 EXPECT_EQ(getSnapshot(1)->geomContentCrop, crop);
1133
1134 setBuffer(1,
1135 std::make_shared<renderengine::mock::FakeExternalTexture>(100U /*width*/,
1136 100U /*height*/,
1137 42ULL /* bufferId */,
1138 HAL_PIXEL_FORMAT_RGBA_8888,
1139 0 /*usage*/));
1140 // validate a buffer crop within the buffer bounds
1141 setBufferCrop(1, crop);
1142 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1143 EXPECT_EQ(getSnapshot(1)->geomContentCrop, crop);
1144
1145 // validate a buffer crop outside the buffer bounds
1146 crop = Rect(0, 0, 150, 150);
1147 setBufferCrop(1, crop);
1148 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1149 EXPECT_EQ(getSnapshot(1)->geomContentCrop, Rect(0, 0, 100, 100));
1150
1151 // validate no buffer crop
1152 setBufferCrop(1, Rect());
1153 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1154 EXPECT_EQ(getSnapshot(1)->geomContentCrop, Rect(0, 0, 100, 100));
1155}
Vishnu Nairbefd3e22023-10-05 17:48:31 +00001156
1157TEST_F(LayerSnapshotTest, setShadowRadius) {
1158 static constexpr float SHADOW_RADIUS = 123.f;
1159 setShadowRadius(1, SHADOW_RADIUS);
1160 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1161 EXPECT_EQ(getSnapshot(1)->shadowSettings.length, SHADOW_RADIUS);
Vishnu Nairbefd3e22023-10-05 17:48:31 +00001162}
1163
Chavi Weingartenb74093a2023-10-11 20:29:59 +00001164TEST_F(LayerSnapshotTest, setTrustedOverlayForNonVisibleInput) {
1165 hideLayer(1);
Vishnu Nair9e0017e2024-05-22 19:02:44 +00001166 setTrustedOverlay(1, gui::TrustedOverlay::ENABLED);
Chavi Weingartenb74093a2023-10-11 20:29:59 +00001167 Region touch{Rect{0, 0, 1000, 1000}};
1168 setTouchableRegion(1, touch);
1169
1170 UPDATE_AND_VERIFY(mSnapshotBuilder, {2});
1171 EXPECT_TRUE(getSnapshot(1)->inputInfo.inputConfig.test(
1172 gui::WindowInfo::InputConfig::TRUSTED_OVERLAY));
1173}
1174
Alec Mouri89f5d4e2023-10-20 17:12:49 +00001175TEST_F(LayerSnapshotTest, isFrontBuffered) {
1176 setBuffer(1,
1177 std::make_shared<renderengine::mock::FakeExternalTexture>(
1178 1U /*width*/, 1U /*height*/, 1ULL /* bufferId */, HAL_PIXEL_FORMAT_RGBA_8888,
1179 GRALLOC_USAGE_HW_TEXTURE | AHARDWAREBUFFER_USAGE_FRONT_BUFFER /*usage*/));
1180
1181 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1182 EXPECT_TRUE(getSnapshot(1)->isFrontBuffered());
1183
1184 setBuffer(1,
1185 std::make_shared<
1186 renderengine::mock::FakeExternalTexture>(1U /*width*/, 1U /*height*/,
1187 1ULL /* bufferId */,
1188 HAL_PIXEL_FORMAT_RGBA_8888,
1189 GRALLOC_USAGE_HW_TEXTURE /*usage*/));
1190
1191 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1192 EXPECT_FALSE(getSnapshot(1)->isFrontBuffered());
1193}
1194
Chavi Weingarten4aa22af2023-11-17 19:37:07 +00001195TEST_F(LayerSnapshotTest, setSecureRootSnapshot) {
1196 setFlags(1, layer_state_t::eLayerSecure, layer_state_t::eLayerSecure);
1197 LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(),
1198 .layerLifecycleManager = mLifecycleManager,
1199 .includeMetadata = false,
1200 .displays = mFrontEndDisplayInfos,
1201 .displayChanges = false,
1202 .globalShadowSettings = globalShadowSettings,
1203 .supportsBlur = true,
1204 .supportedLayerGenericMetadata = {},
1205 .genericLayerMetadataKeyMap = {}};
1206 args.rootSnapshot.isSecure = true;
1207 update(mSnapshotBuilder, args);
1208
1209 EXPECT_TRUE(getSnapshot(1)->isSecure);
1210 // Ensure child is also marked as secure
1211 EXPECT_TRUE(getSnapshot(11)->isSecure);
1212}
1213
Prabir Pradhancf359192024-03-20 00:42:57 +00001214TEST_F(LayerSnapshotTest, setSensitiveForTracingConfigForSecureLayers) {
1215 setFlags(11, layer_state_t::eLayerSecure, layer_state_t::eLayerSecure);
1216
1217 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1218
1219 EXPECT_TRUE(getSnapshot(11)->inputInfo.inputConfig.test(
Arpit Singh490ccc92024-04-30 14:26:21 +00001220 gui::WindowInfo::InputConfig::SENSITIVE_FOR_PRIVACY));
Prabir Pradhancf359192024-03-20 00:42:57 +00001221 EXPECT_TRUE(getSnapshot(111)->inputInfo.inputConfig.test(
Arpit Singh490ccc92024-04-30 14:26:21 +00001222 gui::WindowInfo::InputConfig::SENSITIVE_FOR_PRIVACY));
Prabir Pradhancf359192024-03-20 00:42:57 +00001223 EXPECT_FALSE(getSnapshot(1)->inputInfo.inputConfig.test(
Arpit Singh490ccc92024-04-30 14:26:21 +00001224 gui::WindowInfo::InputConfig::SENSITIVE_FOR_PRIVACY));
Prabir Pradhancf359192024-03-20 00:42:57 +00001225 EXPECT_FALSE(getSnapshot(12)->inputInfo.inputConfig.test(
Arpit Singh490ccc92024-04-30 14:26:21 +00001226 gui::WindowInfo::InputConfig::SENSITIVE_FOR_PRIVACY));
Prabir Pradhancf359192024-03-20 00:42:57 +00001227 EXPECT_FALSE(getSnapshot(2)->inputInfo.inputConfig.test(
Arpit Singh490ccc92024-04-30 14:26:21 +00001228 gui::WindowInfo::InputConfig::SENSITIVE_FOR_PRIVACY));
Prabir Pradhancf359192024-03-20 00:42:57 +00001229}
1230
1231TEST_F(LayerSnapshotTest, setSensitiveForTracingFromInputWindowHandle) {
1232 setInputInfo(11, [](auto& inputInfo) {
Arpit Singh490ccc92024-04-30 14:26:21 +00001233 inputInfo.inputConfig |= gui::WindowInfo::InputConfig::SENSITIVE_FOR_PRIVACY;
Prabir Pradhancf359192024-03-20 00:42:57 +00001234 });
1235
1236 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1237
1238 EXPECT_TRUE(getSnapshot(11)->inputInfo.inputConfig.test(
Arpit Singh490ccc92024-04-30 14:26:21 +00001239 gui::WindowInfo::InputConfig::SENSITIVE_FOR_PRIVACY));
Prabir Pradhancf359192024-03-20 00:42:57 +00001240 EXPECT_TRUE(getSnapshot(111)->inputInfo.inputConfig.test(
Arpit Singh490ccc92024-04-30 14:26:21 +00001241 gui::WindowInfo::InputConfig::SENSITIVE_FOR_PRIVACY));
Prabir Pradhancf359192024-03-20 00:42:57 +00001242 EXPECT_FALSE(getSnapshot(1)->inputInfo.inputConfig.test(
Arpit Singh490ccc92024-04-30 14:26:21 +00001243 gui::WindowInfo::InputConfig::SENSITIVE_FOR_PRIVACY));
Prabir Pradhancf359192024-03-20 00:42:57 +00001244 EXPECT_FALSE(getSnapshot(12)->inputInfo.inputConfig.test(
Arpit Singh490ccc92024-04-30 14:26:21 +00001245 gui::WindowInfo::InputConfig::SENSITIVE_FOR_PRIVACY));
Prabir Pradhancf359192024-03-20 00:42:57 +00001246 EXPECT_FALSE(getSnapshot(2)->inputInfo.inputConfig.test(
Arpit Singh490ccc92024-04-30 14:26:21 +00001247 gui::WindowInfo::InputConfig::SENSITIVE_FOR_PRIVACY));
Prabir Pradhancf359192024-03-20 00:42:57 +00001248}
1249
Vishnu Nairf13c8982023-12-02 11:26:09 -08001250// b/314350323
1251TEST_F(LayerSnapshotTest, propagateDropInputMode) {
1252 setDropInputMode(1, gui::DropInputMode::ALL);
1253 LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(),
1254 .layerLifecycleManager = mLifecycleManager,
1255 .includeMetadata = false,
1256 .displays = mFrontEndDisplayInfos,
1257 .displayChanges = false,
1258 .globalShadowSettings = globalShadowSettings,
1259 .supportsBlur = true,
1260 .supportedLayerGenericMetadata = {},
1261 .genericLayerMetadataKeyMap = {}};
1262 args.rootSnapshot.isSecure = true;
1263 update(mSnapshotBuilder, args);
1264
1265 EXPECT_EQ(getSnapshot(1)->dropInputMode, gui::DropInputMode::ALL);
1266 // Ensure child also has the correct drop input mode regardless of whether either layer has
1267 // an input channel
1268 EXPECT_EQ(getSnapshot(11)->dropInputMode, gui::DropInputMode::ALL);
1269}
1270
Chavi Weingarten92c7d8c2024-01-19 23:25:45 +00001271TEST_F(LayerSnapshotTest, NonVisibleLayerWithInput) {
1272 LayerHierarchyTestBase::createRootLayer(3);
1273 setColor(3, {-1._hf, -1._hf, -1._hf});
1274 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1275
1276 std::vector<TransactionState> transactions;
1277 transactions.emplace_back();
1278 transactions.back().states.push_back({});
1279 transactions.back().states.front().state.what = layer_state_t::eInputInfoChanged;
1280 transactions.back().states.front().layerId = 3;
1281 transactions.back().states.front().state.windowInfoHandle = sp<gui::WindowInfoHandle>::make();
1282 auto inputInfo = transactions.back().states.front().state.windowInfoHandle->editInfo();
1283 inputInfo->token = sp<BBinder>::make();
1284 mLifecycleManager.applyTransactions(transactions);
1285
1286 update(mSnapshotBuilder);
1287
1288 bool foundInputLayer = false;
1289 mSnapshotBuilder.forEachInputSnapshot([&](const frontend::LayerSnapshot& snapshot) {
1290 if (snapshot.uniqueSequence == 3) {
1291 foundInputLayer = true;
1292 }
1293 });
1294 EXPECT_TRUE(foundInputLayer);
1295}
1296
Vishnu Nair59a6be32024-01-29 10:26:21 -08001297TEST_F(LayerSnapshotTest, canOccludePresentation) {
1298 setFlags(12, layer_state_t::eCanOccludePresentation, layer_state_t::eCanOccludePresentation);
1299 LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(),
1300 .layerLifecycleManager = mLifecycleManager,
1301 .includeMetadata = false,
1302 .displays = mFrontEndDisplayInfos,
1303 .displayChanges = false,
1304 .globalShadowSettings = globalShadowSettings,
1305 .supportsBlur = true,
1306 .supportedLayerGenericMetadata = {},
1307 .genericLayerMetadataKeyMap = {}};
1308 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1309
1310 EXPECT_EQ(getSnapshot(1)->inputInfo.canOccludePresentation, false);
1311
1312 // ensure we can set the property on the window info for layer and all its children
1313 EXPECT_EQ(getSnapshot(12)->inputInfo.canOccludePresentation, true);
1314 EXPECT_EQ(getSnapshot(121)->inputInfo.canOccludePresentation, true);
1315 EXPECT_EQ(getSnapshot(1221)->inputInfo.canOccludePresentation, true);
1316}
1317
Vishnu Nair491827d2024-04-29 23:43:26 +00001318TEST_F(LayerSnapshotTest, mirroredHierarchyIgnoresLocalTransform) {
1319 SET_FLAG_FOR_TEST(flags::detached_mirror, true);
1320 reparentLayer(12, UNASSIGNED_LAYER_ID);
1321 setPosition(11, 2, 20);
1322 setPosition(111, 20, 200);
1323 mirrorLayer(/*layer*/ 14, /*parent*/ 1, /*layerToMirror*/ 11);
1324 std::vector<uint32_t> expected = {1, 11, 111, 13, 14, 11, 111, 2};
1325 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
1326
1327 // mirror root has no position set
1328 EXPECT_EQ(getSnapshot({.id = 11, .mirrorRootIds = 14u})->localTransform.tx(), 0);
1329 EXPECT_EQ(getSnapshot({.id = 11, .mirrorRootIds = 14u})->localTransform.ty(), 0);
1330 // original root still has a position
1331 EXPECT_EQ(getSnapshot({.id = 11})->localTransform.tx(), 2);
1332 EXPECT_EQ(getSnapshot({.id = 11})->localTransform.ty(), 20);
1333
1334 // mirror child still has the correct position
1335 EXPECT_EQ(getSnapshot({.id = 111, .mirrorRootIds = 14u})->localTransform.tx(), 20);
1336 EXPECT_EQ(getSnapshot({.id = 111, .mirrorRootIds = 14u})->localTransform.ty(), 200);
1337 EXPECT_EQ(getSnapshot({.id = 111, .mirrorRootIds = 14u})->geomLayerTransform.tx(), 20);
1338 EXPECT_EQ(getSnapshot({.id = 111, .mirrorRootIds = 14u})->geomLayerTransform.ty(), 200);
1339
1340 // original child still has the correct position including its parent's position
1341 EXPECT_EQ(getSnapshot({.id = 111})->localTransform.tx(), 20);
1342 EXPECT_EQ(getSnapshot({.id = 111})->localTransform.ty(), 200);
1343 EXPECT_EQ(getSnapshot({.id = 111})->geomLayerTransform.tx(), 22);
1344 EXPECT_EQ(getSnapshot({.id = 111})->geomLayerTransform.ty(), 220);
1345}
1346
Vishnu Nair9e0017e2024-05-22 19:02:44 +00001347TEST_F(LayerSnapshotTest, overrideParentTrustedOverlayState) {
1348 SET_FLAG_FOR_TEST(flags::override_trusted_overlay, true);
1349 hideLayer(1);
1350 setTrustedOverlay(1, gui::TrustedOverlay::ENABLED);
1351
1352 Region touch{Rect{0, 0, 1000, 1000}};
1353 setTouchableRegion(1, touch);
1354 setTouchableRegion(11, touch);
1355 setTouchableRegion(111, touch);
1356
1357 UPDATE_AND_VERIFY(mSnapshotBuilder, {2});
1358 EXPECT_TRUE(getSnapshot(1)->inputInfo.inputConfig.test(
1359 gui::WindowInfo::InputConfig::TRUSTED_OVERLAY));
1360 EXPECT_TRUE(getSnapshot(11)->inputInfo.inputConfig.test(
1361 gui::WindowInfo::InputConfig::TRUSTED_OVERLAY));
1362 EXPECT_TRUE(getSnapshot(111)->inputInfo.inputConfig.test(
1363 gui::WindowInfo::InputConfig::TRUSTED_OVERLAY));
1364
1365 // disable trusted overlay and override parent state
1366 setTrustedOverlay(11, gui::TrustedOverlay::DISABLED);
1367 UPDATE_AND_VERIFY(mSnapshotBuilder, {2});
1368 EXPECT_TRUE(getSnapshot(1)->inputInfo.inputConfig.test(
1369 gui::WindowInfo::InputConfig::TRUSTED_OVERLAY));
1370 EXPECT_FALSE(getSnapshot(11)->inputInfo.inputConfig.test(
1371 gui::WindowInfo::InputConfig::TRUSTED_OVERLAY));
1372 EXPECT_FALSE(getSnapshot(111)->inputInfo.inputConfig.test(
1373 gui::WindowInfo::InputConfig::TRUSTED_OVERLAY));
1374
1375 // unset state and go back to default behavior of inheriting
1376 // state
1377 setTrustedOverlay(11, gui::TrustedOverlay::UNSET);
1378 UPDATE_AND_VERIFY(mSnapshotBuilder, {2});
1379 EXPECT_TRUE(getSnapshot(1)->inputInfo.inputConfig.test(
1380 gui::WindowInfo::InputConfig::TRUSTED_OVERLAY));
1381 EXPECT_TRUE(getSnapshot(11)->inputInfo.inputConfig.test(
1382 gui::WindowInfo::InputConfig::TRUSTED_OVERLAY));
1383 EXPECT_TRUE(getSnapshot(111)->inputInfo.inputConfig.test(
1384 gui::WindowInfo::InputConfig::TRUSTED_OVERLAY));
1385}
1386
1387TEST_F(LayerSnapshotTest, doNotOverrideParentTrustedOverlayState) {
1388 SET_FLAG_FOR_TEST(flags::override_trusted_overlay, false);
1389 hideLayer(1);
1390 setTrustedOverlay(1, gui::TrustedOverlay::ENABLED);
1391
1392 Region touch{Rect{0, 0, 1000, 1000}};
1393 setTouchableRegion(1, touch);
1394 setTouchableRegion(11, touch);
1395 setTouchableRegion(111, touch);
1396
1397 UPDATE_AND_VERIFY(mSnapshotBuilder, {2});
1398 EXPECT_TRUE(getSnapshot(1)->inputInfo.inputConfig.test(
1399 gui::WindowInfo::InputConfig::TRUSTED_OVERLAY));
1400 EXPECT_TRUE(getSnapshot(11)->inputInfo.inputConfig.test(
1401 gui::WindowInfo::InputConfig::TRUSTED_OVERLAY));
1402 EXPECT_TRUE(getSnapshot(111)->inputInfo.inputConfig.test(
1403 gui::WindowInfo::InputConfig::TRUSTED_OVERLAY));
1404
1405 // disable trusted overlay but flag is disabled so this behaves
1406 // as UNSET
1407 setTrustedOverlay(11, gui::TrustedOverlay::DISABLED);
1408 UPDATE_AND_VERIFY(mSnapshotBuilder, {2});
1409 EXPECT_TRUE(getSnapshot(1)->inputInfo.inputConfig.test(
1410 gui::WindowInfo::InputConfig::TRUSTED_OVERLAY));
1411 EXPECT_TRUE(getSnapshot(11)->inputInfo.inputConfig.test(
1412 gui::WindowInfo::InputConfig::TRUSTED_OVERLAY));
1413 EXPECT_TRUE(getSnapshot(111)->inputInfo.inputConfig.test(
1414 gui::WindowInfo::InputConfig::TRUSTED_OVERLAY));
1415
1416 // unset state and go back to default behavior of inheriting
1417 // state
1418 setTrustedOverlay(11, gui::TrustedOverlay::UNSET);
1419 UPDATE_AND_VERIFY(mSnapshotBuilder, {2});
1420 EXPECT_TRUE(getSnapshot(1)->inputInfo.inputConfig.test(
1421 gui::WindowInfo::InputConfig::TRUSTED_OVERLAY));
1422 EXPECT_TRUE(getSnapshot(11)->inputInfo.inputConfig.test(
1423 gui::WindowInfo::InputConfig::TRUSTED_OVERLAY));
1424 EXPECT_TRUE(getSnapshot(111)->inputInfo.inputConfig.test(
1425 gui::WindowInfo::InputConfig::TRUSTED_OVERLAY));
1426}
1427
Vishnu Nair8fc721b2022-12-22 20:06:32 +00001428} // namespace android::surfaceflinger::frontend