blob: 8cf3f035eaf0f6801a3ae7e737c59e7c938708c5 [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 Nairdf59f472024-05-17 16:51:33 +0000257 EXPECT_EQ(getSnapshot(11)->changes,
Ady Abraham6846ade2024-05-20 21:58:27 +0000258 RequestedLayerState::Changes::Content);
Vishnu Naira02943f2023-06-03 13:44:46 -0700259 EXPECT_EQ(getSnapshot(11)->clientChanges, layer_state_t::eColorChanged);
260 EXPECT_EQ(getSnapshot(1)->changes.get(), 0u);
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000261 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
Vishnu Naira02943f2023-06-03 13:44:46 -0700262 EXPECT_EQ(getSnapshot(11)->changes.get(), 0u);
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000263}
264
265TEST_F(LayerSnapshotTest, FastPathSetsChangeFlagToContent) {
266 setColor(1, {1._hf, 0._hf, 0._hf});
267 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
Vishnu Nairdf59f472024-05-17 16:51:33 +0000268 EXPECT_EQ(getSnapshot(1)->changes,
Ady Abraham6846ade2024-05-20 21:58:27 +0000269 RequestedLayerState::Changes::Content);
Vishnu Naira02943f2023-06-03 13:44:46 -0700270 EXPECT_EQ(getSnapshot(1)->clientChanges, layer_state_t::eColorChanged);
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000271}
272
Vishnu Naircfb2d252023-01-19 04:44:02 +0000273TEST_F(LayerSnapshotTest, GameMode) {
274 std::vector<TransactionState> transactions;
275 transactions.emplace_back();
276 transactions.back().states.push_back({});
277 transactions.back().states.front().state.what = layer_state_t::eMetadataChanged;
278 transactions.back().states.front().state.metadata = LayerMetadata();
279 transactions.back().states.front().state.metadata.setInt32(METADATA_GAME_MODE, 42);
Vishnu Nair1391de22023-03-05 19:56:14 -0800280 transactions.back().states.front().layerId = 1;
Vishnu Naircfb2d252023-01-19 04:44:02 +0000281 transactions.back().states.front().state.layerId = static_cast<int32_t>(1);
282 mLifecycleManager.applyTransactions(transactions);
Nergi Rahardi10fbacd2024-05-21 09:37:59 +0000283 EXPECT_EQ(mLifecycleManager.getGlobalChanges(), RequestedLayerState::Changes::GameMode);
Vishnu Naircfb2d252023-01-19 04:44:02 +0000284 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
Vishnu Naira02943f2023-06-03 13:44:46 -0700285 EXPECT_EQ(getSnapshot(1)->clientChanges, layer_state_t::eMetadataChanged);
Vishnu Naircfb2d252023-01-19 04:44:02 +0000286 EXPECT_EQ(static_cast<int32_t>(getSnapshot(1)->gameMode), 42);
287 EXPECT_EQ(static_cast<int32_t>(getSnapshot(11)->gameMode), 42);
288}
289
290TEST_F(LayerSnapshotTest, NoLayerVoteForParentWithChildVotes) {
291 // ROOT
292 // ├── 1
293 // │ ├── 11 (frame rate set)
294 // │ │ └── 111
295 // │ ├── 12
296 // │ │ ├── 121
297 // │ │ └── 122
298 // │ │ └── 1221
299 // │ └── 13
300 // └── 2
301
Vishnu Nair30515cb2023-10-19 21:54:08 -0700302 setFrameRate(11, 90.0, ANATIVEWINDOW_FRAME_RATE_EXACT, ANATIVEWINDOW_CHANGE_FRAME_RATE_ALWAYS);
Vishnu Naircfb2d252023-01-19 04:44:02 +0000303 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
304
Rachel Leece6e0042023-06-27 11:22:54 -0700305 EXPECT_EQ(getSnapshot(11)->frameRate.vote.rate.getIntValue(), 90);
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700306 EXPECT_EQ(getSnapshot(11)->frameRate.vote.type, scheduler::FrameRateCompatibility::Exact);
Rachel Leece6e0042023-06-27 11:22:54 -0700307 EXPECT_EQ(getSnapshot(111)->frameRate.vote.rate.getIntValue(), 90);
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700308 EXPECT_EQ(getSnapshot(111)->frameRate.vote.type, scheduler::FrameRateCompatibility::Exact);
Rachel Leece6e0042023-06-27 11:22:54 -0700309 EXPECT_EQ(getSnapshot(1)->frameRate.vote.rate.getIntValue(), 0);
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700310 EXPECT_EQ(getSnapshot(1)->frameRate.vote.type, scheduler::FrameRateCompatibility::NoVote);
Vishnu Naircfb2d252023-01-19 04:44:02 +0000311}
312
Vishnu Nair30515cb2023-10-19 21:54:08 -0700313TEST_F(LayerSnapshotTest, NoLayerVoteForParentWithChildVotesDoesNotAffectSiblings) {
314 // ROOT
315 // ├── 1 (verify layer has no vote)
316 // │ ├── 11 (frame rate set)
317 // │ │ └── 111
318 // │ ├── 12 (frame rate set)
319 // │ │ ├── 121
320 // │ │ └── 122
321 // │ │ └── 1221
322 // │ └── 13 (verify layer has default vote)
323 // └── 2
324
325 setFrameRate(11, 90.0, ANATIVEWINDOW_FRAME_RATE_EXACT, ANATIVEWINDOW_CHANGE_FRAME_RATE_ALWAYS);
326 setFrameRate(12, 45.0, ANATIVEWINDOW_FRAME_RATE_EXACT, ANATIVEWINDOW_CHANGE_FRAME_RATE_ALWAYS);
327
328 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
329
330 EXPECT_EQ(getSnapshot(11)->frameRate.vote.rate.getIntValue(), 90);
331 EXPECT_EQ(getSnapshot(11)->frameRate.vote.type, scheduler::FrameRateCompatibility::Exact);
332 EXPECT_EQ(getSnapshot(111)->frameRate.vote.rate.getIntValue(), 90);
333 EXPECT_EQ(getSnapshot(111)->frameRate.vote.type, scheduler::FrameRateCompatibility::Exact);
334 EXPECT_EQ(getSnapshot(12)->frameRate.vote.rate.getIntValue(), 45);
335 EXPECT_EQ(getSnapshot(12)->frameRate.vote.type, scheduler::FrameRateCompatibility::Exact);
336 EXPECT_EQ(getSnapshot(121)->frameRate.vote.rate.getIntValue(), 45);
337 EXPECT_EQ(getSnapshot(121)->frameRate.vote.type, scheduler::FrameRateCompatibility::Exact);
338 EXPECT_EQ(getSnapshot(1221)->frameRate.vote.rate.getIntValue(), 45);
339 EXPECT_EQ(getSnapshot(1221)->frameRate.vote.type, scheduler::FrameRateCompatibility::Exact);
340
341 EXPECT_EQ(getSnapshot(1)->frameRate.vote.rate.getIntValue(), 0);
342 EXPECT_EQ(getSnapshot(1)->frameRate.vote.type, scheduler::FrameRateCompatibility::NoVote);
343 EXPECT_EQ(getSnapshot(13)->frameRate.vote.rate.getIntValue(), 0);
344 EXPECT_EQ(getSnapshot(13)->frameRate.vote.type, scheduler::FrameRateCompatibility::Default);
345 EXPECT_EQ(getSnapshot(2)->frameRate.vote.rate.getIntValue(), 0);
346 EXPECT_EQ(getSnapshot(2)->frameRate.vote.type, scheduler::FrameRateCompatibility::Default);
347}
348
Vishnu Naira02943f2023-06-03 13:44:46 -0700349TEST_F(LayerSnapshotTest, CanCropTouchableRegion) {
Vishnu Nair29354ec2023-03-28 18:51:28 -0700350 // ROOT
351 // ├── 1
352 // │ ├── 11
353 // │ │ └── 111 (touchregion set to touch but cropped by layer 13)
354 // │ ├── 12
355 // │ │ ├── 121
356 // │ │ └── 122
357 // │ │ └── 1221
358 // │ └── 13 (crop set to touchCrop)
359 // └── 2
360
361 Rect touchCrop{300, 300, 400, 500};
362 setCrop(13, touchCrop);
363 Region touch{Rect{0, 0, 1000, 1000}};
364 setTouchableRegionCrop(111, touch, /*touchCropId=*/13, /*replaceTouchableRegionWithCrop=*/true);
365 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
366 EXPECT_EQ(getSnapshot({.id = 111})->inputInfo.touchableRegion.bounds(), touchCrop);
367
368 Rect modifiedTouchCrop{100, 300, 400, 700};
369 setCrop(13, modifiedTouchCrop);
370 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
371 EXPECT_EQ(getSnapshot({.id = 111})->inputInfo.touchableRegion.bounds(), modifiedTouchCrop);
372}
373
Chavi Weingarten1ba381e2024-01-09 21:54:11 +0000374TEST_F(LayerSnapshotTest, CanCropTouchableRegionWithDisplayTransform) {
375 DisplayInfo displayInfo;
376 displayInfo.transform = ui::Transform(ui::Transform::RotationFlags::ROT_90, 1000, 1000);
377 mFrontEndDisplayInfos.emplace_or_replace(ui::LayerStack::fromValue(1), displayInfo);
378
379 Rect touchCrop{300, 300, 400, 500};
380 createRootLayer(3);
381 setCrop(3, touchCrop);
382 setLayerStack(3, 1);
383 Region touch{Rect{0, 0, 1000, 1000}};
384 setTouchableRegionCrop(3, touch, /*touchCropId=*/3, /*replaceTouchableRegionWithCrop=*/false);
385
386 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 11, 111, 12, 121, 122, 1221, 13, 2, 3});
387 Rect rotatedCrop = {500, 300, 700, 400};
388 EXPECT_EQ(getSnapshot({.id = 3})->inputInfo.touchableRegion.bounds(), rotatedCrop);
389}
390
Vishnu Nair444f3952023-04-11 13:01:02 -0700391TEST_F(LayerSnapshotTest, blurUpdatesWhenAlphaChanges) {
Vishnu Nair854ce1c2023-08-19 15:00:13 -0700392 int blurRadius = 42;
393 setBackgroundBlurRadius(1221, static_cast<uint32_t>(blurRadius));
Vishnu Nair444f3952023-04-11 13:01:02 -0700394
395 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
396 EXPECT_EQ(getSnapshot({.id = 1221})->backgroundBlurRadius, blurRadius);
397
Vishnu Nair854ce1c2023-08-19 15:00:13 -0700398 blurRadius = 21;
399 setBackgroundBlurRadius(1221, static_cast<uint32_t>(blurRadius));
400 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
401 EXPECT_EQ(getSnapshot({.id = 1221})->backgroundBlurRadius, blurRadius);
402
Vishnu Nair444f3952023-04-11 13:01:02 -0700403 static constexpr float alpha = 0.5;
404 setAlpha(12, alpha);
405 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
Vishnu Nair854ce1c2023-08-19 15:00:13 -0700406 EXPECT_EQ(getSnapshot({.id = 1221})->backgroundBlurRadius,
407 static_cast<int>(static_cast<float>(blurRadius) * alpha));
Vishnu Nair444f3952023-04-11 13:01:02 -0700408}
409
Vishnu Naira9c43762023-01-27 19:10:25 +0000410// Display Mirroring Tests
411// tree with 3 levels of children
412// ROOT (DISPLAY 0)
413// ├── 1
414// │ ├── 11
415// │ │ └── 111
416// │ ├── 12 (has skip screenshot flag)
417// │ │ ├── 121
418// │ │ └── 122
419// │ │ └── 1221
420// │ └── 13
421// └── 2
422// ROOT (DISPLAY 1)
423// └── 3 (mirrors display 0)
Vishnu Nair92990e22023-02-24 20:01:05 +0000424TEST_F(LayerSnapshotTest, displayMirrorRespectsLayerSkipScreenshotFlag) {
Vishnu Naira9c43762023-01-27 19:10:25 +0000425 setFlags(12, layer_state_t::eLayerSkipScreenshot, layer_state_t::eLayerSkipScreenshot);
426 createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0));
427 setLayerStack(3, 1);
428
Vishnu Nair444f3952023-04-11 13:01:02 -0700429 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 +0000430 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
431}
432
Vishnu Nair92990e22023-02-24 20:01:05 +0000433// ROOT (DISPLAY 0)
434// ├── 1
435// │ ├── 11
436// │ │ └── 111
437// │ └── 13
438// └── 2
439// ROOT (DISPLAY 3)
440// └── 3 (mirrors display 0)
441TEST_F(LayerSnapshotTest, mirrorLayerGetsCorrectLayerStack) {
442 reparentLayer(12, UNASSIGNED_LAYER_ID);
443 createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0));
444 setLayerStack(3, 3);
445 createDisplayMirrorLayer(4, ui::LayerStack::fromValue(0));
446 setLayerStack(4, 4);
447
Vishnu Nair444f3952023-04-11 13:01:02 -0700448 std::vector<uint32_t> expected = {1, 11, 111, 13, 2, 3, 1, 11, 111,
449 13, 2, 4, 1, 11, 111, 13, 2};
Vishnu Nair92990e22023-02-24 20:01:05 +0000450 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
Vishnu Nair6f878312023-09-08 11:05:01 -0700451 EXPECT_EQ(getSnapshot({.id = 111, .mirrorRootIds = 3u})->outputFilter.layerStack.id, 3u);
452 EXPECT_EQ(getSnapshot({.id = 111, .mirrorRootIds = 4u})->outputFilter.layerStack.id, 4u);
Vishnu Nair92990e22023-02-24 20:01:05 +0000453}
454
455// ROOT (DISPLAY 0)
456// ├── 1 (crop 50x50)
457// │ ├── 11
458// │ │ └── 111
459// │ └── 13
460// └── 2
461// ROOT (DISPLAY 3)
462// └── 3 (mirrors display 0) (crop 100x100)
463TEST_F(LayerSnapshotTest, mirrorLayerTouchIsCroppedByMirrorRoot) {
464 reparentLayer(12, UNASSIGNED_LAYER_ID);
465 createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0));
466 setLayerStack(3, 3);
467 setCrop(1, Rect{50, 50});
468 setCrop(3, Rect{100, 100});
469 setCrop(111, Rect{200, 200});
470 Region touch{Rect{0, 0, 1000, 1000}};
471 setTouchableRegion(111, touch);
Vishnu Nair444f3952023-04-11 13:01:02 -0700472 std::vector<uint32_t> expected = {1, 11, 111, 13, 2, 3, 1, 11, 111, 13, 2};
Vishnu Nair92990e22023-02-24 20:01:05 +0000473 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
474 EXPECT_TRUE(getSnapshot({.id = 111})->inputInfo.touchableRegion.hasSameRects(touch));
475 Region touchCroppedByMirrorRoot{Rect{0, 0, 50, 50}};
Vishnu Nair6f878312023-09-08 11:05:01 -0700476 EXPECT_TRUE(getSnapshot({.id = 111, .mirrorRootIds = 3u})
Vishnu Nair92990e22023-02-24 20:01:05 +0000477 ->inputInfo.touchableRegion.hasSameRects(touchCroppedByMirrorRoot));
478}
479
480TEST_F(LayerSnapshotTest, canRemoveDisplayMirror) {
481 setFlags(12, layer_state_t::eLayerSkipScreenshot, layer_state_t::eLayerSkipScreenshot);
482 createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0));
483 setLayerStack(3, 1);
Vishnu Nair444f3952023-04-11 13:01:02 -0700484 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 +0000485 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
486 destroyLayerHandle(3);
487 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
488}
489
Vishnu Nairfccd6362023-02-24 23:39:53 +0000490TEST_F(LayerSnapshotTest, cleanUpUnreachableSnapshotsAfterMirroring) {
491 size_t startingNumSnapshots = mSnapshotBuilder.getSnapshots().size();
492 createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0));
493 setLayerStack(3, 1);
Vishnu Nair444f3952023-04-11 13:01:02 -0700494 std::vector<uint32_t> expected = {1, 11, 111, 12, 121, 122, 1221, 13, 2, 3,
495 1, 11, 111, 12, 121, 122, 1221, 13, 2};
Vishnu Nairfccd6362023-02-24 23:39:53 +0000496 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
497 destroyLayerHandle(3);
498 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
499
500 EXPECT_EQ(startingNumSnapshots, mSnapshotBuilder.getSnapshots().size());
501}
502
Vishnu Nair6f878312023-09-08 11:05:01 -0700503TEST_F(LayerSnapshotTest, canMirrorDisplayWithMirrors) {
504 reparentLayer(12, UNASSIGNED_LAYER_ID);
505 mirrorLayer(/*layer*/ 14, /*parent*/ 1, /*layerToMirror*/ 11);
506 std::vector<uint32_t> expected = {1, 11, 111, 13, 14, 11, 111, 2};
507 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
508
509 createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0));
510 setLayerStack(3, 3);
511 expected = {1, 11, 111, 13, 14, 11, 111, 2, 3, 1, 11, 111, 13, 14, 11, 111, 2};
512 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
513 EXPECT_EQ(getSnapshot({.id = 11, .mirrorRootIds = 14u})->outputFilter.layerStack.id, 0u);
514 EXPECT_EQ(getSnapshot({.id = 11, .mirrorRootIds = 3u})->outputFilter.layerStack.id, 3u);
515 EXPECT_EQ(getSnapshot({.id = 11, .mirrorRootIds = 3u, 14u})->outputFilter.layerStack.id, 3u);
516}
517
Vishnu Nairfccd6362023-02-24 23:39:53 +0000518// Rel z doesn't create duplicate snapshots but this is for completeness
519TEST_F(LayerSnapshotTest, cleanUpUnreachableSnapshotsAfterRelZ) {
520 size_t startingNumSnapshots = mSnapshotBuilder.getSnapshots().size();
521 reparentRelativeLayer(13, 11);
522 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 11, 13, 111, 12, 121, 122, 1221, 2});
523 setZ(13, 0);
524 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
525
526 EXPECT_EQ(startingNumSnapshots, mSnapshotBuilder.getSnapshots().size());
527}
528
529TEST_F(LayerSnapshotTest, cleanUpUnreachableSnapshotsAfterLayerDestruction) {
530 size_t startingNumSnapshots = mSnapshotBuilder.getSnapshots().size();
531 destroyLayerHandle(2);
532 destroyLayerHandle(122);
533
534 std::vector<uint32_t> expected = {1, 11, 111, 12, 121, 122, 1221, 13};
535 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
536
537 EXPECT_LE(startingNumSnapshots - 2, mSnapshotBuilder.getSnapshots().size());
538}
539
Vishnu Nair3d8565a2023-06-30 07:23:24 +0000540TEST_F(LayerSnapshotTest, snashotContainsMetadataFromLayerCreationArgs) {
541 LayerCreationArgs args(std::make_optional<uint32_t>(200));
542 args.name = "testlayer";
543 args.addToRoot = true;
544 args.metadata.setInt32(42, 24);
545
546 std::vector<std::unique_ptr<RequestedLayerState>> layers;
547 layers.emplace_back(std::make_unique<RequestedLayerState>(args));
548 EXPECT_TRUE(layers.back()->metadata.has(42));
549 EXPECT_EQ(layers.back()->metadata.getInt32(42, 0), 24);
550 mLifecycleManager.addLayers(std::move(layers));
551
552 std::vector<uint32_t> expected = STARTING_ZORDER;
553 expected.push_back(200);
554 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
555
556 EXPECT_TRUE(mSnapshotBuilder.getSnapshot(200)->layerMetadata.has(42));
557 EXPECT_EQ(mSnapshotBuilder.getSnapshot(200)->layerMetadata.getInt32(42, 0), 24);
558}
559
560TEST_F(LayerSnapshotTest, frameRateSelectionPriorityPassedToChildLayers) {
561 setFrameRateSelectionPriority(11, 1);
562
563 setFrameRateSelectionPriority(12, 2);
564
565 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
566 EXPECT_EQ(getSnapshot({.id = 1})->frameRateSelectionPriority, Layer::PRIORITY_UNSET);
567 EXPECT_EQ(getSnapshot({.id = 11})->frameRateSelectionPriority, 1);
568 EXPECT_EQ(getSnapshot({.id = 12})->frameRateSelectionPriority, 2);
569 EXPECT_EQ(getSnapshot({.id = 122})->frameRateSelectionPriority, 2);
570 EXPECT_EQ(getSnapshot({.id = 1221})->frameRateSelectionPriority, 2);
571
572 // reparent and verify the child gets the new parent's framerate selection priority
573 reparentLayer(122, 11);
574
575 std::vector<uint32_t> expected = {1, 11, 111, 122, 1221, 12, 121, 13, 2};
576 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
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, 1);
581 EXPECT_EQ(getSnapshot({.id = 1221})->frameRateSelectionPriority, 1);
582}
583
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000584TEST_F(LayerSnapshotTest, framerate) {
585 setFrameRate(11, 244.f, 0, 0);
586
587 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
588 // verify parent is gets no vote
Rachel Leece6e0042023-06-27 11:22:54 -0700589 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
590 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700591 scheduler::FrameRateCompatibility::NoVote);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000592 EXPECT_TRUE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate));
593
594 // verify layer and children get the requested votes
Rachel Leece6e0042023-06-27 11:22:54 -0700595 EXPECT_TRUE(getSnapshot({.id = 11})->frameRate.vote.rate.isValid());
596 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 244.f);
597 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700598 scheduler::FrameRateCompatibility::Default);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000599 EXPECT_TRUE(getSnapshot({.id = 11})->changes.test(RequestedLayerState::Changes::FrameRate));
600
Rachel Leece6e0042023-06-27 11:22:54 -0700601 EXPECT_TRUE(getSnapshot({.id = 111})->frameRate.vote.rate.isValid());
602 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.rate.getValue(), 244.f);
603 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700604 scheduler::FrameRateCompatibility::Default);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000605 EXPECT_TRUE(getSnapshot({.id = 111})->changes.test(RequestedLayerState::Changes::FrameRate));
606
607 // reparent and verify the child gets the new parent's framerate
608 reparentLayer(122, 11);
609
610 std::vector<uint32_t> expected = {1, 11, 111, 122, 1221, 12, 121, 13, 2};
611 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
612 // verify parent is gets no vote
Rachel Leece6e0042023-06-27 11:22:54 -0700613 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
614 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700615 scheduler::FrameRateCompatibility::NoVote);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000616
617 // verify layer and children get the requested votes
Rachel Leece6e0042023-06-27 11:22:54 -0700618 EXPECT_TRUE(getSnapshot({.id = 11})->frameRate.vote.rate.isValid());
619 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 244.f);
620 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700621 scheduler::FrameRateCompatibility::Default);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000622
Rachel Leece6e0042023-06-27 11:22:54 -0700623 EXPECT_TRUE(getSnapshot({.id = 111})->frameRate.vote.rate.isValid());
624 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.rate.getValue(), 244.f);
625 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700626 scheduler::FrameRateCompatibility::Default);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000627
Rachel Leece6e0042023-06-27 11:22:54 -0700628 EXPECT_TRUE(getSnapshot({.id = 122})->frameRate.vote.rate.isValid());
629 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.rate.getValue(), 244.f);
630 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700631 scheduler::FrameRateCompatibility::Default);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000632 EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate));
633
634 // reparent and verify the new parent gets no vote
635 reparentLayer(11, 2);
636 expected = {1, 12, 121, 13, 2, 11, 111, 122, 1221};
637 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
638
639 // verify old parent has invalid framerate (default)
Rachel Leece6e0042023-06-27 11:22:54 -0700640 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
641 EXPECT_EQ(getSnapshot({.id = 1})->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 = 1})->changes.test(RequestedLayerState::Changes::FrameRate));
644
645 // verify new parent get no vote
Rachel Leece6e0042023-06-27 11:22:54 -0700646 EXPECT_FALSE(getSnapshot({.id = 2})->frameRate.vote.rate.isValid());
647 EXPECT_EQ(getSnapshot({.id = 2})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700648 scheduler::FrameRateCompatibility::NoVote);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000649 EXPECT_TRUE(getSnapshot({.id = 2})->changes.test(RequestedLayerState::Changes::FrameRate));
650
651 // verify layer and children get the requested votes (unchanged)
Rachel Leece6e0042023-06-27 11:22:54 -0700652 EXPECT_TRUE(getSnapshot({.id = 11})->frameRate.vote.rate.isValid());
653 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 244.f);
654 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700655 scheduler::FrameRateCompatibility::Default);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000656
Rachel Leece6e0042023-06-27 11:22:54 -0700657 EXPECT_TRUE(getSnapshot({.id = 111})->frameRate.vote.rate.isValid());
658 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.rate.getValue(), 244.f);
659 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700660 scheduler::FrameRateCompatibility::Default);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000661
Rachel Leece6e0042023-06-27 11:22:54 -0700662 EXPECT_TRUE(getSnapshot({.id = 122})->frameRate.vote.rate.isValid());
663 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.rate.getValue(), 244.f);
664 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700665 scheduler::FrameRateCompatibility::Default);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000666}
667
Vishnu Nair3996ee32023-08-14 04:32:31 +0000668TEST_F(LayerSnapshotTest, translateDataspace) {
669 setDataspace(1, ui::Dataspace::UNKNOWN);
670 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
671 EXPECT_EQ(getSnapshot({.id = 1})->dataspace, ui::Dataspace::V0_SRGB);
672}
673
Rachel Leece6e0042023-06-27 11:22:54 -0700674// This test is similar to "frameRate" test case but checks that the setFrameRateCategory API
675// interaction also works correctly with the setFrameRate API within SF frontend.
676TEST_F(LayerSnapshotTest, frameRateWithCategory) {
Rachel Lee45681982024-03-14 18:40:15 -0700677 SET_FLAG_FOR_TEST(flags::frame_rate_category_mrr, true);
678
Rachel Leece6e0042023-06-27 11:22:54 -0700679 // ROOT
680 // ├── 1
681 // │ ├── 11 (frame rate set to 244.f)
682 // │ │ └── 111
683 // │ ├── 12
684 // │ │ ├── 121
685 // │ │ └── 122 (frame rate category set to Normal)
686 // │ │ └── 1221
687 // │ └── 13
688 // └── 2
689 setFrameRate(11, 244.f, 0, 0);
Rachel Lee9580ff12023-12-26 17:33:41 -0800690 setFrameRateCategory(122, ANATIVEWINDOW_FRAME_RATE_CATEGORY_NORMAL);
Rachel Leece6e0042023-06-27 11:22:54 -0700691
692 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
693 // verify parent 1 gets no vote
694 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
695 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700696 scheduler::FrameRateCompatibility::NoVote);
Rachel Leece6e0042023-06-27 11:22:54 -0700697 EXPECT_TRUE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate));
698
699 // verify layer 11 and children 111 get the requested votes
700 EXPECT_TRUE(getSnapshot({.id = 11})->frameRate.vote.rate.isValid());
701 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 244.f);
702 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700703 scheduler::FrameRateCompatibility::Default);
Rachel Leece6e0042023-06-27 11:22:54 -0700704 EXPECT_TRUE(getSnapshot({.id = 11})->changes.test(RequestedLayerState::Changes::FrameRate));
705
706 EXPECT_TRUE(getSnapshot({.id = 111})->frameRate.vote.rate.isValid());
707 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.rate.getValue(), 244.f);
708 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700709 scheduler::FrameRateCompatibility::Default);
Rachel Leece6e0042023-06-27 11:22:54 -0700710 EXPECT_TRUE(getSnapshot({.id = 111})->changes.test(RequestedLayerState::Changes::FrameRate));
711
712 // verify parent 12 gets no vote
713 EXPECT_FALSE(getSnapshot({.id = 12})->frameRate.vote.rate.isValid());
714 EXPECT_EQ(getSnapshot({.id = 12})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700715 scheduler::FrameRateCompatibility::NoVote);
Rachel Leece6e0042023-06-27 11:22:54 -0700716 EXPECT_TRUE(getSnapshot({.id = 12})->changes.test(RequestedLayerState::Changes::FrameRate));
717
718 // verify layer 122 and children 1221 get the requested votes
719 EXPECT_FALSE(getSnapshot({.id = 122})->frameRate.vote.rate.isValid());
720 EXPECT_TRUE(getSnapshot({.id = 122})->frameRate.isValid());
721 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700722 scheduler::FrameRateCompatibility::Default);
Rachel Leece6e0042023-06-27 11:22:54 -0700723 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.category, FrameRateCategory::Normal);
724 EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate));
Rachel Lee43369b22023-09-05 18:40:40 -0700725 EXPECT_TRUE(
726 getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::AffectsChildren));
Rachel Leece6e0042023-06-27 11:22:54 -0700727
728 EXPECT_FALSE(getSnapshot({.id = 1221})->frameRate.vote.rate.isValid());
729 EXPECT_TRUE(getSnapshot({.id = 1221})->frameRate.isValid());
730 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700731 scheduler::FrameRateCompatibility::Default);
Rachel Leece6e0042023-06-27 11:22:54 -0700732 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.category, FrameRateCategory::Normal);
733 EXPECT_TRUE(getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::FrameRate));
Rachel Lee43369b22023-09-05 18:40:40 -0700734 EXPECT_TRUE(
735 getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::AffectsChildren));
Rachel Leece6e0042023-06-27 11:22:54 -0700736
737 // reparent and verify the child does NOT get the new parent's framerate because it already has
738 // the frame rate category specified.
739 // ROOT
740 // ├─1
741 // │ ├─11 (frame rate set to 244.f)
742 // │ │ ├─111
743 // │ │ └─122 (frame rate category set to Normal)
744 // │ │ └─1221
745 // │ ├─12
746 // │ │ └─121
747 // │ └─13
748 // └─2
749 reparentLayer(122, 11);
750
751 std::vector<uint32_t> expected = {1, 11, 111, 122, 1221, 12, 121, 13, 2};
752 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
753 // verify parent is gets no vote
754 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
755 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700756 scheduler::FrameRateCompatibility::NoVote);
Rachel Leece6e0042023-06-27 11:22:54 -0700757
758 // verify layer 11 and children 111 get the requested votes
759 EXPECT_TRUE(getSnapshot({.id = 11})->frameRate.vote.rate.isValid());
760 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 244.f);
761 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700762 scheduler::FrameRateCompatibility::Default);
Rachel Leece6e0042023-06-27 11:22:54 -0700763
764 EXPECT_TRUE(getSnapshot({.id = 111})->frameRate.vote.rate.isValid());
765 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.rate.getValue(), 244.f);
766 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700767 scheduler::FrameRateCompatibility::Default);
Rachel Leece6e0042023-06-27 11:22:54 -0700768
769 // verify layer 122 and children 1221 get the requested category vote (unchanged from
770 // reparenting)
771 EXPECT_FALSE(getSnapshot({.id = 122})->frameRate.vote.rate.isValid());
772 EXPECT_TRUE(getSnapshot({.id = 122})->frameRate.isValid());
773 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700774 scheduler::FrameRateCompatibility::Default);
Rachel Leece6e0042023-06-27 11:22:54 -0700775 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.category, FrameRateCategory::Normal);
776 EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate));
777
778 EXPECT_FALSE(getSnapshot({.id = 1221})->frameRate.vote.rate.isValid());
779 EXPECT_TRUE(getSnapshot({.id = 1221})->frameRate.isValid());
780 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700781 scheduler::FrameRateCompatibility::Default);
Rachel Leece6e0042023-06-27 11:22:54 -0700782 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.category, FrameRateCategory::Normal);
783 EXPECT_TRUE(getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::FrameRate));
784}
785
Rachel Lee58cc90d2023-09-05 18:50:20 -0700786TEST_F(LayerSnapshotTest, frameRateSelectionStrategy) {
787 // ROOT
788 // ├── 1
789 // │ ├── 11
790 // │ │ └── 111
791 // │ ├── 12 (frame rate set to 244.f with strategy OverrideChildren)
792 // │ │ ├── 121
793 // │ │ └── 122 (frame rate set to 123.f but should be overridden by layer 12)
794 // │ │ └── 1221
795 // │ └── 13
796 // └── 2
797 setFrameRate(12, 244.f, 0, 0);
798 setFrameRate(122, 123.f, 0, 0);
799 setFrameRateSelectionStrategy(12, 1 /* OverrideChildren */);
800
801 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
802 // verify parent 1 gets no vote
803 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
804 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700805 scheduler::FrameRateCompatibility::NoVote);
Rachel Lee58cc90d2023-09-05 18:50:20 -0700806 EXPECT_TRUE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate));
807
808 // verify layer 12 and all descendants (121, 122, 1221) get the requested vote
809 EXPECT_EQ(getSnapshot({.id = 12})->frameRate.vote.rate.getValue(), 244.f);
810 EXPECT_EQ(getSnapshot({.id = 12})->frameRateSelectionStrategy,
811 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
812 EXPECT_TRUE(getSnapshot({.id = 12})->changes.test(RequestedLayerState::Changes::FrameRate));
813
814 EXPECT_EQ(getSnapshot({.id = 121})->frameRate.vote.rate.getValue(), 244.f);
815 EXPECT_EQ(getSnapshot({.id = 121})->frameRateSelectionStrategy,
816 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
817 EXPECT_TRUE(getSnapshot({.id = 121})->changes.test(RequestedLayerState::Changes::FrameRate));
818
819 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.rate.getValue(), 244.f);
820 EXPECT_EQ(getSnapshot({.id = 122})->frameRateSelectionStrategy,
821 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
822 EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate));
823
824 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.vote.rate.getValue(), 244.f);
825 EXPECT_EQ(getSnapshot({.id = 1221})->frameRateSelectionStrategy,
826 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
827 EXPECT_TRUE(getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::FrameRate));
Vishnu Nair41376b62023-11-08 05:08:58 -0800828
829 // ROOT
830 // ├── 1
831 // │ ├── 11
832 // │ │ └── 111
833 // │ ├── 12 (frame rate set to default with strategy default)
834 // │ │ ├── 121
835 // │ │ └── 122 (frame rate set to 123.f)
836 // │ │ └── 1221
837 // │ └── 13
838 // └── 2
839 setFrameRate(12, -1.f, 0, 0);
840 setFrameRateSelectionStrategy(12, 0 /* Default */);
841 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
842 // verify parent 1 gets no vote
843 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
844 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
845 scheduler::FrameRateCompatibility::NoVote);
846 EXPECT_FALSE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate));
847
848 // verify layer 12 and all descendants (121, 122, 1221) get the requested vote
849 EXPECT_FALSE(getSnapshot({.id = 12})->frameRate.vote.rate.isValid());
850 EXPECT_EQ(getSnapshot({.id = 12})->frameRate.vote.type,
851 scheduler::FrameRateCompatibility::NoVote);
852 EXPECT_EQ(getSnapshot({.id = 12})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -0800853 scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate);
Vishnu Nair41376b62023-11-08 05:08:58 -0800854 EXPECT_TRUE(getSnapshot({.id = 12})->changes.test(RequestedLayerState::Changes::FrameRate));
855
856 EXPECT_FALSE(getSnapshot({.id = 121})->frameRate.vote.rate.isValid());
857 EXPECT_EQ(getSnapshot({.id = 121})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -0800858 scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate);
Vishnu Nair41376b62023-11-08 05:08:58 -0800859 EXPECT_EQ(getSnapshot({.id = 121})->frameRate.vote.type,
860 scheduler::FrameRateCompatibility::Default);
861 EXPECT_TRUE(getSnapshot({.id = 121})->changes.test(RequestedLayerState::Changes::FrameRate));
862
863 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.rate.getValue(), 123.f);
864 EXPECT_EQ(getSnapshot({.id = 122})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -0800865 scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate);
Vishnu Nair41376b62023-11-08 05:08:58 -0800866 EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate));
867
868 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.vote.rate.getValue(), 123.f);
869 EXPECT_EQ(getSnapshot({.id = 1221})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -0800870 scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate);
Vishnu Nair41376b62023-11-08 05:08:58 -0800871 EXPECT_TRUE(getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::FrameRate));
872}
873
874TEST_F(LayerSnapshotTest, frameRateSelectionStrategyWithCategory) {
Rachel Lee45681982024-03-14 18:40:15 -0700875 SET_FLAG_FOR_TEST(flags::frame_rate_category_mrr, true);
876
Vishnu Nair41376b62023-11-08 05:08:58 -0800877 // ROOT
878 // ├── 1
879 // │ ├── 11
880 // │ │ └── 111
881 // │ ├── 12 (frame rate category set to high with strategy OverrideChildren)
882 // │ │ ├── 121
883 // │ │ └── 122 (frame rate set to 123.f but should be overridden by layer 12)
884 // │ │ └── 1221
885 // │ └── 13
886 // └── 2
Rachel Lee9580ff12023-12-26 17:33:41 -0800887 setFrameRateCategory(12, ANATIVEWINDOW_FRAME_RATE_CATEGORY_HIGH);
Vishnu Nair41376b62023-11-08 05:08:58 -0800888 setFrameRate(122, 123.f, 0, 0);
889 setFrameRateSelectionStrategy(12, 1 /* OverrideChildren */);
890
891 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
892 // verify parent 1 gets no vote
893 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
894 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
895 scheduler::FrameRateCompatibility::NoVote);
896 EXPECT_TRUE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate));
897
898 // verify layer 12 and all descendants (121, 122, 1221) get the requested vote
899 EXPECT_EQ(getSnapshot({.id = 12})->frameRate.category, FrameRateCategory::High);
900 EXPECT_EQ(getSnapshot({.id = 12})->frameRateSelectionStrategy,
901 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
902 EXPECT_TRUE(getSnapshot({.id = 12})->changes.test(RequestedLayerState::Changes::FrameRate));
903
904 EXPECT_EQ(getSnapshot({.id = 121})->frameRate.category, FrameRateCategory::High);
905 EXPECT_EQ(getSnapshot({.id = 121})->frameRateSelectionStrategy,
906 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
907 EXPECT_TRUE(getSnapshot({.id = 121})->changes.test(RequestedLayerState::Changes::FrameRate));
908
909 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.category, FrameRateCategory::High);
910 EXPECT_EQ(getSnapshot({.id = 122})->frameRateSelectionStrategy,
911 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
912 EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate));
913
914 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.category, FrameRateCategory::High);
915 EXPECT_EQ(getSnapshot({.id = 1221})->frameRateSelectionStrategy,
916 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
917 EXPECT_TRUE(getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::FrameRate));
918
919 // ROOT
920 // ├── 1
921 // │ ├── 11
922 // │ │ └── 111
923 // │ ├── 12 (frame rate category to default with strategy default)
924 // │ │ ├── 121
925 // │ │ └── 122 (frame rate set to 123.f)
926 // │ │ └── 1221
927 // │ └── 13
928 // └── 2
Rachel Lee9580ff12023-12-26 17:33:41 -0800929 setFrameRateCategory(12, ANATIVEWINDOW_FRAME_RATE_CATEGORY_DEFAULT);
Vishnu Nair41376b62023-11-08 05:08:58 -0800930 setFrameRateSelectionStrategy(12, 0 /* Default */);
931 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
932 // verify parent 1 gets no vote
933 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
934 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
935 scheduler::FrameRateCompatibility::NoVote);
936 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.category, FrameRateCategory::Default);
937 EXPECT_FALSE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate));
938
939 // verify layer 12 and all descendants (121, 122, 1221) get the requested vote
940 EXPECT_FALSE(getSnapshot({.id = 12})->frameRate.vote.rate.isValid());
941 EXPECT_EQ(getSnapshot({.id = 12})->frameRate.vote.type,
942 scheduler::FrameRateCompatibility::NoVote);
943 EXPECT_EQ(getSnapshot({.id = 12})->frameRate.category, FrameRateCategory::Default);
944 EXPECT_EQ(getSnapshot({.id = 12})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -0800945 scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate);
Vishnu Nair41376b62023-11-08 05:08:58 -0800946 EXPECT_TRUE(getSnapshot({.id = 12})->changes.test(RequestedLayerState::Changes::FrameRate));
947
948 EXPECT_FALSE(getSnapshot({.id = 12})->frameRate.vote.rate.isValid());
949 EXPECT_EQ(getSnapshot({.id = 121})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -0800950 scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate);
Vishnu Nair41376b62023-11-08 05:08:58 -0800951 EXPECT_EQ(getSnapshot({.id = 121})->frameRate.category, FrameRateCategory::Default);
952 EXPECT_EQ(getSnapshot({.id = 121})->frameRate.vote.type,
953 scheduler::FrameRateCompatibility::Default);
954 EXPECT_TRUE(getSnapshot({.id = 121})->changes.test(RequestedLayerState::Changes::FrameRate));
955
956 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.rate.getValue(), 123.f);
957 EXPECT_EQ(getSnapshot({.id = 122})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -0800958 scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate);
Vishnu Nair41376b62023-11-08 05:08:58 -0800959 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.category, FrameRateCategory::Default);
960 EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate));
961
962 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.vote.rate.getValue(), 123.f);
963 EXPECT_EQ(getSnapshot({.id = 1221})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -0800964 scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate);
Vishnu Nair41376b62023-11-08 05:08:58 -0800965 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.category, FrameRateCategory::Default);
966 EXPECT_TRUE(getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::FrameRate));
Rachel Lee58cc90d2023-09-05 18:50:20 -0700967}
968
Rachel Lee70f7b692023-11-22 11:24:02 -0800969TEST_F(LayerSnapshotTest, frameRateSelectionStrategyWithOverrideChildrenAndSelf) {
Rachel Leea021bb02023-11-20 21:51:09 -0800970 // ROOT
971 // ├── 1
Rachel Lee70f7b692023-11-22 11:24:02 -0800972 // │ ├── 11 (frame rate set to 11.f with strategy Self)
Rachel Leea021bb02023-11-20 21:51:09 -0800973 // │ │ └── 111 (frame rate is not inherited)
974 // │ ├── 12 (frame rate set to 244.f)
975 // │ │ ├── 121
976 // │ │ └── 122 (strategy OverrideChildren and inherits frame rate 244.f)
977 // │ │ └── 1221 (frame rate set to 123.f but should be overridden by layer 122)
978 // │ └── 13
979 // └── 2
980 setFrameRate(11, 11.f, 0, 0);
Rachel Lee70f7b692023-11-22 11:24:02 -0800981 setFrameRateSelectionStrategy(11, 2 /* Self */);
Rachel Leea021bb02023-11-20 21:51:09 -0800982 setFrameRate(12, 244.f, 0, 0);
983 setFrameRateSelectionStrategy(122, 1 /* OverrideChildren */);
984 setFrameRate(1221, 123.f, 0, 0);
985
986 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
987 // verify parent 1 gets no vote
988 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
989 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
990 scheduler::FrameRateCompatibility::NoVote);
991 EXPECT_EQ(getSnapshot({.id = 1})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -0800992 scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate);
Rachel Leea021bb02023-11-20 21:51:09 -0800993 EXPECT_TRUE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate));
994
995 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 11.f);
996 EXPECT_EQ(getSnapshot({.id = 11})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -0800997 scheduler::LayerInfo::FrameRateSelectionStrategy::Self);
Rachel Leea021bb02023-11-20 21:51:09 -0800998 EXPECT_TRUE(getSnapshot({.id = 11})->changes.test(RequestedLayerState::Changes::FrameRate));
999
1000 // verify layer 11 does does not propagate its framerate to 111.
1001 EXPECT_FALSE(getSnapshot({.id = 111})->frameRate.vote.rate.isValid());
1002 EXPECT_EQ(getSnapshot({.id = 111})->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 = 111})->changes.test(RequestedLayerState::Changes::FrameRate));
1005
1006 // verify layer 12 and all descendants (121, 122, 1221) get the requested vote
1007 EXPECT_EQ(getSnapshot({.id = 12})->frameRate.vote.rate.getValue(), 244.f);
1008 EXPECT_EQ(getSnapshot({.id = 12})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -08001009 scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate);
Rachel Leea021bb02023-11-20 21:51:09 -08001010 EXPECT_TRUE(getSnapshot({.id = 12})->changes.test(RequestedLayerState::Changes::FrameRate));
1011
1012 EXPECT_EQ(getSnapshot({.id = 121})->frameRate.vote.rate.getValue(), 244.f);
1013 EXPECT_EQ(getSnapshot({.id = 121})->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 = 121})->changes.test(RequestedLayerState::Changes::FrameRate));
1016
1017 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.rate.getValue(), 244.f);
1018 EXPECT_EQ(getSnapshot({.id = 122})->frameRateSelectionStrategy,
1019 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
1020 EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate));
1021
1022 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.vote.rate.getValue(), 244.f);
1023 EXPECT_EQ(getSnapshot({.id = 1221})->frameRateSelectionStrategy,
1024 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
1025 EXPECT_TRUE(getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::FrameRate));
1026
1027 // ROOT
1028 // ├── 1 (frame rate set to 1.f with strategy OverrideChildren)
Rachel Lee70f7b692023-11-22 11:24:02 -08001029 // │ ├── 11 (frame rate set to 11.f with strategy Self, but overridden by 1)
Rachel Leea021bb02023-11-20 21:51:09 -08001030 // │ │ └── 111 (frame rate inherited from 11 due to override from 1)
1031 // â‹® â‹®
1032 setFrameRate(1, 1.f, 0, 0);
1033 setFrameRateSelectionStrategy(1, 1 /* OverrideChildren */);
1034 setFrameRate(11, 11.f, 0, 0);
Rachel Lee70f7b692023-11-22 11:24:02 -08001035 setFrameRateSelectionStrategy(11, 2 /* Self */);
Rachel Leea021bb02023-11-20 21:51:09 -08001036 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1037
1038 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.rate.getValue(), 1.f);
1039 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
1040 scheduler::FrameRateCompatibility::Default);
1041 EXPECT_EQ(getSnapshot({.id = 1})->frameRateSelectionStrategy,
1042 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
1043 EXPECT_TRUE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate));
1044
1045 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 1.f);
1046 EXPECT_EQ(getSnapshot({.id = 11})->frameRateSelectionStrategy,
1047 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
1048 EXPECT_TRUE(getSnapshot({.id = 11})->changes.test(RequestedLayerState::Changes::FrameRate));
1049
1050 // verify layer 11 does does not propagate its framerate to 111.
1051 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.rate.getValue(), 1.f);
1052 EXPECT_EQ(getSnapshot({.id = 111})->frameRateSelectionStrategy,
1053 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
1054 EXPECT_TRUE(getSnapshot({.id = 111})->changes.test(RequestedLayerState::Changes::FrameRate));
1055}
1056
Vishnu Nair0808ae62023-08-07 21:42:42 -07001057TEST_F(LayerSnapshotTest, skipRoundCornersWhenProtected) {
1058 setRoundedCorners(1, 42.f);
1059 setRoundedCorners(2, 42.f);
1060 setCrop(1, Rect{1000, 1000});
1061 setCrop(2, Rect{1000, 1000});
1062
1063 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1064 EXPECT_TRUE(getSnapshot({.id = 1})->roundedCorner.hasRoundedCorners());
1065 EXPECT_EQ(getSnapshot({.id = 1})->roundedCorner.radius.x, 42.f);
1066 EXPECT_TRUE(getSnapshot({.id = 2})->roundedCorner.hasRoundedCorners());
1067
1068 // add a buffer with the protected bit, check rounded corners are not set when
1069 // skipRoundCornersWhenProtected == true
1070 setBuffer(1,
1071 std::make_shared<
1072 renderengine::mock::FakeExternalTexture>(1U /*width*/, 1U /*height*/,
1073 1ULL /* bufferId */,
1074 HAL_PIXEL_FORMAT_RGBA_8888,
1075 GRALLOC_USAGE_PROTECTED /*usage*/));
1076
1077 LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(),
1078 .layerLifecycleManager = mLifecycleManager,
1079 .includeMetadata = false,
1080 .displays = mFrontEndDisplayInfos,
1081 .displayChanges = false,
1082 .globalShadowSettings = globalShadowSettings,
1083 .supportsBlur = true,
1084 .supportedLayerGenericMetadata = {},
1085 .genericLayerMetadataKeyMap = {},
1086 .skipRoundCornersWhenProtected = true};
1087 update(mSnapshotBuilder, args);
1088 EXPECT_FALSE(getSnapshot({.id = 1})->roundedCorner.hasRoundedCorners());
1089 // layer 2 doesn't have a buffer and should be unaffected
1090 EXPECT_TRUE(getSnapshot({.id = 2})->roundedCorner.hasRoundedCorners());
1091
1092 // remove protected bit, check rounded corners are set
1093 setBuffer(1,
1094 std::make_shared<renderengine::mock::FakeExternalTexture>(1U /*width*/, 1U /*height*/,
1095 2ULL /* bufferId */,
1096 HAL_PIXEL_FORMAT_RGBA_8888,
1097 0 /*usage*/));
1098 update(mSnapshotBuilder, args);
1099 EXPECT_TRUE(getSnapshot({.id = 1})->roundedCorner.hasRoundedCorners());
1100 EXPECT_EQ(getSnapshot({.id = 1})->roundedCorner.radius.x, 42.f);
1101}
1102
Vishnu Nairbd51f952023-08-31 22:50:14 -07001103TEST_F(LayerSnapshotTest, setRefreshRateIndicatorCompositionType) {
1104 setFlags(1, layer_state_t::eLayerIsRefreshRateIndicator,
1105 layer_state_t::eLayerIsRefreshRateIndicator);
1106 setBuffer(1,
1107 std::make_shared<renderengine::mock::FakeExternalTexture>(1U /*width*/, 1U /*height*/,
1108 42ULL /* bufferId */,
1109 HAL_PIXEL_FORMAT_RGBA_8888,
1110 0 /*usage*/));
1111 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1112 EXPECT_EQ(getSnapshot({.id = 1})->compositionType,
1113 aidl::android::hardware::graphics::composer3::Composition::REFRESH_RATE_INDICATOR);
1114}
1115
Chavi Weingarten07597342023-09-14 21:10:59 +00001116TEST_F(LayerSnapshotTest, setBufferCrop) {
1117 // validate no buffer but has crop
1118 Rect crop = Rect(0, 0, 50, 50);
1119 setBufferCrop(1, crop);
1120 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1121 EXPECT_EQ(getSnapshot(1)->geomContentCrop, crop);
1122
1123 setBuffer(1,
1124 std::make_shared<renderengine::mock::FakeExternalTexture>(100U /*width*/,
1125 100U /*height*/,
1126 42ULL /* bufferId */,
1127 HAL_PIXEL_FORMAT_RGBA_8888,
1128 0 /*usage*/));
1129 // validate a buffer crop within the buffer bounds
1130 setBufferCrop(1, crop);
1131 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1132 EXPECT_EQ(getSnapshot(1)->geomContentCrop, crop);
1133
1134 // validate a buffer crop outside the buffer bounds
1135 crop = Rect(0, 0, 150, 150);
1136 setBufferCrop(1, crop);
1137 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1138 EXPECT_EQ(getSnapshot(1)->geomContentCrop, Rect(0, 0, 100, 100));
1139
1140 // validate no buffer crop
1141 setBufferCrop(1, Rect());
1142 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1143 EXPECT_EQ(getSnapshot(1)->geomContentCrop, Rect(0, 0, 100, 100));
1144}
Vishnu Nairbefd3e22023-10-05 17:48:31 +00001145
1146TEST_F(LayerSnapshotTest, setShadowRadius) {
1147 static constexpr float SHADOW_RADIUS = 123.f;
1148 setShadowRadius(1, SHADOW_RADIUS);
1149 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1150 EXPECT_EQ(getSnapshot(1)->shadowSettings.length, SHADOW_RADIUS);
Vishnu Nairbefd3e22023-10-05 17:48:31 +00001151}
1152
Chavi Weingartenb74093a2023-10-11 20:29:59 +00001153TEST_F(LayerSnapshotTest, setTrustedOverlayForNonVisibleInput) {
1154 hideLayer(1);
Vishnu Nair9e0017e2024-05-22 19:02:44 +00001155 setTrustedOverlay(1, gui::TrustedOverlay::ENABLED);
Chavi Weingartenb74093a2023-10-11 20:29:59 +00001156 Region touch{Rect{0, 0, 1000, 1000}};
1157 setTouchableRegion(1, touch);
1158
1159 UPDATE_AND_VERIFY(mSnapshotBuilder, {2});
1160 EXPECT_TRUE(getSnapshot(1)->inputInfo.inputConfig.test(
1161 gui::WindowInfo::InputConfig::TRUSTED_OVERLAY));
1162}
1163
Vishnu Nairab942862024-06-13 22:59:06 -07001164TEST_F(LayerSnapshotTest, alphaChangesPropagateToInput) {
1165 Region touch{Rect{0, 0, 1000, 1000}};
1166 setTouchableRegion(1, touch);
1167 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1168
1169 setAlpha(1, 0.5f);
1170 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1171 EXPECT_EQ(getSnapshot(1)->inputInfo.alpha, 0.5f);
1172}
1173
Alec Mouri89f5d4e2023-10-20 17:12:49 +00001174TEST_F(LayerSnapshotTest, isFrontBuffered) {
1175 setBuffer(1,
1176 std::make_shared<renderengine::mock::FakeExternalTexture>(
1177 1U /*width*/, 1U /*height*/, 1ULL /* bufferId */, HAL_PIXEL_FORMAT_RGBA_8888,
1178 GRALLOC_USAGE_HW_TEXTURE | AHARDWAREBUFFER_USAGE_FRONT_BUFFER /*usage*/));
1179
1180 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1181 EXPECT_TRUE(getSnapshot(1)->isFrontBuffered());
1182
1183 setBuffer(1,
1184 std::make_shared<
1185 renderengine::mock::FakeExternalTexture>(1U /*width*/, 1U /*height*/,
1186 1ULL /* bufferId */,
1187 HAL_PIXEL_FORMAT_RGBA_8888,
1188 GRALLOC_USAGE_HW_TEXTURE /*usage*/));
1189
1190 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1191 EXPECT_FALSE(getSnapshot(1)->isFrontBuffered());
1192}
1193
Chavi Weingarten4aa22af2023-11-17 19:37:07 +00001194TEST_F(LayerSnapshotTest, setSecureRootSnapshot) {
1195 setFlags(1, layer_state_t::eLayerSecure, layer_state_t::eLayerSecure);
1196 LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(),
1197 .layerLifecycleManager = mLifecycleManager,
1198 .includeMetadata = false,
1199 .displays = mFrontEndDisplayInfos,
1200 .displayChanges = false,
1201 .globalShadowSettings = globalShadowSettings,
1202 .supportsBlur = true,
1203 .supportedLayerGenericMetadata = {},
1204 .genericLayerMetadataKeyMap = {}};
1205 args.rootSnapshot.isSecure = true;
1206 update(mSnapshotBuilder, args);
1207
1208 EXPECT_TRUE(getSnapshot(1)->isSecure);
1209 // Ensure child is also marked as secure
1210 EXPECT_TRUE(getSnapshot(11)->isSecure);
1211}
1212
Prabir Pradhancf359192024-03-20 00:42:57 +00001213TEST_F(LayerSnapshotTest, setSensitiveForTracingConfigForSecureLayers) {
1214 setFlags(11, layer_state_t::eLayerSecure, layer_state_t::eLayerSecure);
1215
1216 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1217
1218 EXPECT_TRUE(getSnapshot(11)->inputInfo.inputConfig.test(
Arpit Singh490ccc92024-04-30 14:26:21 +00001219 gui::WindowInfo::InputConfig::SENSITIVE_FOR_PRIVACY));
Prabir Pradhancf359192024-03-20 00:42:57 +00001220 EXPECT_TRUE(getSnapshot(111)->inputInfo.inputConfig.test(
Arpit Singh490ccc92024-04-30 14:26:21 +00001221 gui::WindowInfo::InputConfig::SENSITIVE_FOR_PRIVACY));
Prabir Pradhancf359192024-03-20 00:42:57 +00001222 EXPECT_FALSE(getSnapshot(1)->inputInfo.inputConfig.test(
Arpit Singh490ccc92024-04-30 14:26:21 +00001223 gui::WindowInfo::InputConfig::SENSITIVE_FOR_PRIVACY));
Prabir Pradhancf359192024-03-20 00:42:57 +00001224 EXPECT_FALSE(getSnapshot(12)->inputInfo.inputConfig.test(
Arpit Singh490ccc92024-04-30 14:26:21 +00001225 gui::WindowInfo::InputConfig::SENSITIVE_FOR_PRIVACY));
Prabir Pradhancf359192024-03-20 00:42:57 +00001226 EXPECT_FALSE(getSnapshot(2)->inputInfo.inputConfig.test(
Arpit Singh490ccc92024-04-30 14:26:21 +00001227 gui::WindowInfo::InputConfig::SENSITIVE_FOR_PRIVACY));
Prabir Pradhancf359192024-03-20 00:42:57 +00001228}
1229
1230TEST_F(LayerSnapshotTest, setSensitiveForTracingFromInputWindowHandle) {
1231 setInputInfo(11, [](auto& inputInfo) {
Arpit Singh490ccc92024-04-30 14:26:21 +00001232 inputInfo.inputConfig |= gui::WindowInfo::InputConfig::SENSITIVE_FOR_PRIVACY;
Prabir Pradhancf359192024-03-20 00:42:57 +00001233 });
1234
1235 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1236
1237 EXPECT_TRUE(getSnapshot(11)->inputInfo.inputConfig.test(
Arpit Singh490ccc92024-04-30 14:26:21 +00001238 gui::WindowInfo::InputConfig::SENSITIVE_FOR_PRIVACY));
Prabir Pradhancf359192024-03-20 00:42:57 +00001239 EXPECT_TRUE(getSnapshot(111)->inputInfo.inputConfig.test(
Arpit Singh490ccc92024-04-30 14:26:21 +00001240 gui::WindowInfo::InputConfig::SENSITIVE_FOR_PRIVACY));
Prabir Pradhancf359192024-03-20 00:42:57 +00001241 EXPECT_FALSE(getSnapshot(1)->inputInfo.inputConfig.test(
Arpit Singh490ccc92024-04-30 14:26:21 +00001242 gui::WindowInfo::InputConfig::SENSITIVE_FOR_PRIVACY));
Prabir Pradhancf359192024-03-20 00:42:57 +00001243 EXPECT_FALSE(getSnapshot(12)->inputInfo.inputConfig.test(
Arpit Singh490ccc92024-04-30 14:26:21 +00001244 gui::WindowInfo::InputConfig::SENSITIVE_FOR_PRIVACY));
Prabir Pradhancf359192024-03-20 00:42:57 +00001245 EXPECT_FALSE(getSnapshot(2)->inputInfo.inputConfig.test(
Arpit Singh490ccc92024-04-30 14:26:21 +00001246 gui::WindowInfo::InputConfig::SENSITIVE_FOR_PRIVACY));
Prabir Pradhancf359192024-03-20 00:42:57 +00001247}
1248
Vishnu Nairf13c8982023-12-02 11:26:09 -08001249// b/314350323
1250TEST_F(LayerSnapshotTest, propagateDropInputMode) {
1251 setDropInputMode(1, gui::DropInputMode::ALL);
1252 LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(),
1253 .layerLifecycleManager = mLifecycleManager,
1254 .includeMetadata = false,
1255 .displays = mFrontEndDisplayInfos,
1256 .displayChanges = false,
1257 .globalShadowSettings = globalShadowSettings,
1258 .supportsBlur = true,
1259 .supportedLayerGenericMetadata = {},
1260 .genericLayerMetadataKeyMap = {}};
1261 args.rootSnapshot.isSecure = true;
1262 update(mSnapshotBuilder, args);
1263
1264 EXPECT_EQ(getSnapshot(1)->dropInputMode, gui::DropInputMode::ALL);
1265 // Ensure child also has the correct drop input mode regardless of whether either layer has
1266 // an input channel
1267 EXPECT_EQ(getSnapshot(11)->dropInputMode, gui::DropInputMode::ALL);
1268}
1269
Chavi Weingarten92c7d8c2024-01-19 23:25:45 +00001270TEST_F(LayerSnapshotTest, NonVisibleLayerWithInput) {
1271 LayerHierarchyTestBase::createRootLayer(3);
1272 setColor(3, {-1._hf, -1._hf, -1._hf});
1273 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1274
1275 std::vector<TransactionState> transactions;
1276 transactions.emplace_back();
1277 transactions.back().states.push_back({});
1278 transactions.back().states.front().state.what = layer_state_t::eInputInfoChanged;
1279 transactions.back().states.front().layerId = 3;
1280 transactions.back().states.front().state.windowInfoHandle = sp<gui::WindowInfoHandle>::make();
1281 auto inputInfo = transactions.back().states.front().state.windowInfoHandle->editInfo();
1282 inputInfo->token = sp<BBinder>::make();
1283 mLifecycleManager.applyTransactions(transactions);
1284
1285 update(mSnapshotBuilder);
1286
1287 bool foundInputLayer = false;
1288 mSnapshotBuilder.forEachInputSnapshot([&](const frontend::LayerSnapshot& snapshot) {
1289 if (snapshot.uniqueSequence == 3) {
1290 foundInputLayer = true;
1291 }
1292 });
1293 EXPECT_TRUE(foundInputLayer);
1294}
1295
Vishnu Nair59a6be32024-01-29 10:26:21 -08001296TEST_F(LayerSnapshotTest, canOccludePresentation) {
1297 setFlags(12, layer_state_t::eCanOccludePresentation, layer_state_t::eCanOccludePresentation);
1298 LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(),
1299 .layerLifecycleManager = mLifecycleManager,
1300 .includeMetadata = false,
1301 .displays = mFrontEndDisplayInfos,
1302 .displayChanges = false,
1303 .globalShadowSettings = globalShadowSettings,
1304 .supportsBlur = true,
1305 .supportedLayerGenericMetadata = {},
1306 .genericLayerMetadataKeyMap = {}};
1307 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1308
1309 EXPECT_EQ(getSnapshot(1)->inputInfo.canOccludePresentation, false);
1310
1311 // ensure we can set the property on the window info for layer and all its children
1312 EXPECT_EQ(getSnapshot(12)->inputInfo.canOccludePresentation, true);
1313 EXPECT_EQ(getSnapshot(121)->inputInfo.canOccludePresentation, true);
1314 EXPECT_EQ(getSnapshot(1221)->inputInfo.canOccludePresentation, true);
1315}
1316
Vishnu Nair491827d2024-04-29 23:43:26 +00001317TEST_F(LayerSnapshotTest, mirroredHierarchyIgnoresLocalTransform) {
1318 SET_FLAG_FOR_TEST(flags::detached_mirror, true);
1319 reparentLayer(12, UNASSIGNED_LAYER_ID);
1320 setPosition(11, 2, 20);
1321 setPosition(111, 20, 200);
1322 mirrorLayer(/*layer*/ 14, /*parent*/ 1, /*layerToMirror*/ 11);
1323 std::vector<uint32_t> expected = {1, 11, 111, 13, 14, 11, 111, 2};
1324 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
1325
1326 // mirror root has no position set
1327 EXPECT_EQ(getSnapshot({.id = 11, .mirrorRootIds = 14u})->localTransform.tx(), 0);
1328 EXPECT_EQ(getSnapshot({.id = 11, .mirrorRootIds = 14u})->localTransform.ty(), 0);
1329 // original root still has a position
1330 EXPECT_EQ(getSnapshot({.id = 11})->localTransform.tx(), 2);
1331 EXPECT_EQ(getSnapshot({.id = 11})->localTransform.ty(), 20);
1332
1333 // mirror child still has the correct position
1334 EXPECT_EQ(getSnapshot({.id = 111, .mirrorRootIds = 14u})->localTransform.tx(), 20);
1335 EXPECT_EQ(getSnapshot({.id = 111, .mirrorRootIds = 14u})->localTransform.ty(), 200);
1336 EXPECT_EQ(getSnapshot({.id = 111, .mirrorRootIds = 14u})->geomLayerTransform.tx(), 20);
1337 EXPECT_EQ(getSnapshot({.id = 111, .mirrorRootIds = 14u})->geomLayerTransform.ty(), 200);
1338
1339 // original child still has the correct position including its parent's position
1340 EXPECT_EQ(getSnapshot({.id = 111})->localTransform.tx(), 20);
1341 EXPECT_EQ(getSnapshot({.id = 111})->localTransform.ty(), 200);
1342 EXPECT_EQ(getSnapshot({.id = 111})->geomLayerTransform.tx(), 22);
1343 EXPECT_EQ(getSnapshot({.id = 111})->geomLayerTransform.ty(), 220);
1344}
1345
Vishnu Nair9e0017e2024-05-22 19:02:44 +00001346TEST_F(LayerSnapshotTest, overrideParentTrustedOverlayState) {
1347 SET_FLAG_FOR_TEST(flags::override_trusted_overlay, true);
1348 hideLayer(1);
1349 setTrustedOverlay(1, gui::TrustedOverlay::ENABLED);
1350
1351 Region touch{Rect{0, 0, 1000, 1000}};
1352 setTouchableRegion(1, touch);
1353 setTouchableRegion(11, touch);
1354 setTouchableRegion(111, touch);
1355
1356 UPDATE_AND_VERIFY(mSnapshotBuilder, {2});
1357 EXPECT_TRUE(getSnapshot(1)->inputInfo.inputConfig.test(
1358 gui::WindowInfo::InputConfig::TRUSTED_OVERLAY));
1359 EXPECT_TRUE(getSnapshot(11)->inputInfo.inputConfig.test(
1360 gui::WindowInfo::InputConfig::TRUSTED_OVERLAY));
1361 EXPECT_TRUE(getSnapshot(111)->inputInfo.inputConfig.test(
1362 gui::WindowInfo::InputConfig::TRUSTED_OVERLAY));
1363
1364 // disable trusted overlay and override parent state
1365 setTrustedOverlay(11, gui::TrustedOverlay::DISABLED);
1366 UPDATE_AND_VERIFY(mSnapshotBuilder, {2});
1367 EXPECT_TRUE(getSnapshot(1)->inputInfo.inputConfig.test(
1368 gui::WindowInfo::InputConfig::TRUSTED_OVERLAY));
1369 EXPECT_FALSE(getSnapshot(11)->inputInfo.inputConfig.test(
1370 gui::WindowInfo::InputConfig::TRUSTED_OVERLAY));
1371 EXPECT_FALSE(getSnapshot(111)->inputInfo.inputConfig.test(
1372 gui::WindowInfo::InputConfig::TRUSTED_OVERLAY));
1373
1374 // unset state and go back to default behavior of inheriting
1375 // state
1376 setTrustedOverlay(11, gui::TrustedOverlay::UNSET);
1377 UPDATE_AND_VERIFY(mSnapshotBuilder, {2});
1378 EXPECT_TRUE(getSnapshot(1)->inputInfo.inputConfig.test(
1379 gui::WindowInfo::InputConfig::TRUSTED_OVERLAY));
1380 EXPECT_TRUE(getSnapshot(11)->inputInfo.inputConfig.test(
1381 gui::WindowInfo::InputConfig::TRUSTED_OVERLAY));
1382 EXPECT_TRUE(getSnapshot(111)->inputInfo.inputConfig.test(
1383 gui::WindowInfo::InputConfig::TRUSTED_OVERLAY));
1384}
1385
1386TEST_F(LayerSnapshotTest, doNotOverrideParentTrustedOverlayState) {
1387 SET_FLAG_FOR_TEST(flags::override_trusted_overlay, false);
1388 hideLayer(1);
1389 setTrustedOverlay(1, gui::TrustedOverlay::ENABLED);
1390
1391 Region touch{Rect{0, 0, 1000, 1000}};
1392 setTouchableRegion(1, touch);
1393 setTouchableRegion(11, touch);
1394 setTouchableRegion(111, touch);
1395
1396 UPDATE_AND_VERIFY(mSnapshotBuilder, {2});
1397 EXPECT_TRUE(getSnapshot(1)->inputInfo.inputConfig.test(
1398 gui::WindowInfo::InputConfig::TRUSTED_OVERLAY));
1399 EXPECT_TRUE(getSnapshot(11)->inputInfo.inputConfig.test(
1400 gui::WindowInfo::InputConfig::TRUSTED_OVERLAY));
1401 EXPECT_TRUE(getSnapshot(111)->inputInfo.inputConfig.test(
1402 gui::WindowInfo::InputConfig::TRUSTED_OVERLAY));
1403
1404 // disable trusted overlay but flag is disabled so this behaves
1405 // as UNSET
1406 setTrustedOverlay(11, gui::TrustedOverlay::DISABLED);
1407 UPDATE_AND_VERIFY(mSnapshotBuilder, {2});
1408 EXPECT_TRUE(getSnapshot(1)->inputInfo.inputConfig.test(
1409 gui::WindowInfo::InputConfig::TRUSTED_OVERLAY));
1410 EXPECT_TRUE(getSnapshot(11)->inputInfo.inputConfig.test(
1411 gui::WindowInfo::InputConfig::TRUSTED_OVERLAY));
1412 EXPECT_TRUE(getSnapshot(111)->inputInfo.inputConfig.test(
1413 gui::WindowInfo::InputConfig::TRUSTED_OVERLAY));
1414
1415 // unset state and go back to default behavior of inheriting
1416 // state
1417 setTrustedOverlay(11, gui::TrustedOverlay::UNSET);
1418 UPDATE_AND_VERIFY(mSnapshotBuilder, {2});
1419 EXPECT_TRUE(getSnapshot(1)->inputInfo.inputConfig.test(
1420 gui::WindowInfo::InputConfig::TRUSTED_OVERLAY));
1421 EXPECT_TRUE(getSnapshot(11)->inputInfo.inputConfig.test(
1422 gui::WindowInfo::InputConfig::TRUSTED_OVERLAY));
1423 EXPECT_TRUE(getSnapshot(111)->inputInfo.inputConfig.test(
1424 gui::WindowInfo::InputConfig::TRUSTED_OVERLAY));
1425}
1426
Vishnu Nair8fc721b2022-12-22 20:06:32 +00001427} // namespace android::surfaceflinger::frontend