blob: 0011c128b05169b1f4acf4dc517db3f94033d3cf [file] [log] [blame]
Vishnu Nair8fc721b2022-12-22 20:06:32 +00001/*
2 * Copyright 2022 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <gmock/gmock.h>
18#include <gtest/gtest.h>
19
Rachel Lee45681982024-03-14 18:40:15 -070020#include <common/test/FlagUtils.h>
Vishnu Nair0808ae62023-08-07 21:42:42 -070021#include <renderengine/mock/FakeExternalTexture.h>
22
Vishnu Nair8fc721b2022-12-22 20:06:32 +000023#include "FrontEnd/LayerHierarchy.h"
24#include "FrontEnd/LayerLifecycleManager.h"
25#include "FrontEnd/LayerSnapshotBuilder.h"
Vishnu Nair3d8565a2023-06-30 07:23:24 +000026#include "Layer.h"
Vishnu Nair8fc721b2022-12-22 20:06:32 +000027#include "LayerHierarchyTest.h"
Vishnu Nair3996ee32023-08-14 04:32:31 +000028#include "ui/GraphicTypes.h"
Vishnu Nair8fc721b2022-12-22 20:06:32 +000029
Rachel Lee45681982024-03-14 18:40:15 -070030#include <com_android_graphics_surfaceflinger_flags.h>
31
Vishnu Nair8fc721b2022-12-22 20:06:32 +000032#define UPDATE_AND_VERIFY(BUILDER, ...) \
33 ({ \
34 SCOPED_TRACE(""); \
35 updateAndVerify((BUILDER), /*displayChanges=*/false, __VA_ARGS__); \
36 })
37
38#define UPDATE_AND_VERIFY_WITH_DISPLAY_CHANGES(BUILDER, ...) \
39 ({ \
40 SCOPED_TRACE(""); \
41 updateAndVerify((BUILDER), /*displayChanges=*/true, __VA_ARGS__); \
42 })
43
44namespace android::surfaceflinger::frontend {
45
Vishnu Naircfb2d252023-01-19 04:44:02 +000046using ftl::Flags;
47using namespace ftl::flag_operators;
Rachel Lee45681982024-03-14 18:40:15 -070048using namespace com::android::graphics::surfaceflinger;
Vishnu Naircfb2d252023-01-19 04:44:02 +000049
Vishnu Nair8fc721b2022-12-22 20:06:32 +000050// To run test:
51/**
52 mp :libsurfaceflinger_unittest && adb sync; adb shell \
53 /data/nativetest/libsurfaceflinger_unittest/libsurfaceflinger_unittest \
54 --gtest_filter="LayerSnapshotTest.*" --gtest_brief=1
55*/
56
Vishnu Nair47b7bb42023-09-29 16:27:33 -070057class LayerSnapshotTest : public LayerSnapshotTestBase {
Vishnu Nair8fc721b2022-12-22 20:06:32 +000058protected:
Vishnu Nair47b7bb42023-09-29 16:27:33 -070059 LayerSnapshotTest() : LayerSnapshotTestBase() {
Vishnu Nair8fc721b2022-12-22 20:06:32 +000060 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
61 }
62
Vishnu Nair0808ae62023-08-07 21:42:42 -070063 void update(LayerSnapshotBuilder& actualBuilder, LayerSnapshotBuilder::Args& args) {
Vishnu Nair8fc721b2022-12-22 20:06:32 +000064 if (mLifecycleManager.getGlobalChanges().test(RequestedLayerState::Changes::Hierarchy)) {
Vishnu Naira0292282023-12-16 14:32:00 -080065 mHierarchyBuilder.update(mLifecycleManager);
Vishnu Nair8fc721b2022-12-22 20:06:32 +000066 }
Vishnu Nair0808ae62023-08-07 21:42:42 -070067 args.root = mHierarchyBuilder.getHierarchy();
68 actualBuilder.update(args);
69 }
70
Chavi Weingarten92c7d8c2024-01-19 23:25:45 +000071 void update(LayerSnapshotBuilder& actualBuilder) {
72 LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(),
73 .layerLifecycleManager = mLifecycleManager,
74 .includeMetadata = false,
75 .displays = mFrontEndDisplayInfos,
76 .globalShadowSettings = globalShadowSettings,
77 .supportsBlur = true,
78 .supportedLayerGenericMetadata = {},
79 .genericLayerMetadataKeyMap = {}};
80 update(actualBuilder, args);
81 }
82
Vishnu Nair0808ae62023-08-07 21:42:42 -070083 void updateAndVerify(LayerSnapshotBuilder& actualBuilder, bool hasDisplayChanges,
84 const std::vector<uint32_t> expectedVisibleLayerIdsInZOrder) {
Vishnu Nairc765c6c2023-02-23 00:08:01 +000085 LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(),
86 .layerLifecycleManager = mLifecycleManager,
87 .includeMetadata = false,
88 .displays = mFrontEndDisplayInfos,
89 .displayChanges = hasDisplayChanges,
90 .globalShadowSettings = globalShadowSettings,
Vishnu Nair444f3952023-04-11 13:01:02 -070091 .supportsBlur = true,
Vishnu Nairc765c6c2023-02-23 00:08:01 +000092 .supportedLayerGenericMetadata = {},
93 .genericLayerMetadataKeyMap = {}};
Vishnu Nair0808ae62023-08-07 21:42:42 -070094 update(actualBuilder, args);
Vishnu Nair8fc721b2022-12-22 20:06:32 +000095
96 // rebuild layer snapshots from scratch and verify that it matches the updated state.
97 LayerSnapshotBuilder expectedBuilder(args);
98 mLifecycleManager.commitChanges();
99 ASSERT_TRUE(expectedBuilder.getSnapshots().size() > 0);
100 ASSERT_TRUE(actualBuilder.getSnapshots().size() > 0);
101
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000102 std::vector<uint32_t> actualVisibleLayerIdsInZOrder;
Vishnu Naircfb2d252023-01-19 04:44:02 +0000103 actualBuilder.forEachVisibleSnapshot(
104 [&actualVisibleLayerIdsInZOrder](const LayerSnapshot& snapshot) {
105 actualVisibleLayerIdsInZOrder.push_back(snapshot.path.id);
106 });
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000107 EXPECT_EQ(expectedVisibleLayerIdsInZOrder, actualVisibleLayerIdsInZOrder);
108 }
109
110 LayerSnapshot* getSnapshot(uint32_t layerId) { return mSnapshotBuilder.getSnapshot(layerId); }
Vishnu Nair92990e22023-02-24 20:01:05 +0000111 LayerSnapshot* getSnapshot(const LayerHierarchy::TraversalPath path) {
112 return mSnapshotBuilder.getSnapshot(path);
113 }
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000114 LayerSnapshotBuilder mSnapshotBuilder;
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000115 static const std::vector<uint32_t> STARTING_ZORDER;
116};
117const std::vector<uint32_t> LayerSnapshotTest::STARTING_ZORDER = {1, 11, 111, 12, 121,
118 122, 1221, 13, 2};
119
120TEST_F(LayerSnapshotTest, buildSnapshot) {
Vishnu Nairc765c6c2023-02-23 00:08:01 +0000121 LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(),
122 .layerLifecycleManager = mLifecycleManager,
123 .includeMetadata = false,
124 .displays = mFrontEndDisplayInfos,
125 .globalShadowSettings = globalShadowSettings,
126 .supportedLayerGenericMetadata = {},
127 .genericLayerMetadataKeyMap = {}};
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000128 LayerSnapshotBuilder builder(args);
129}
130
131TEST_F(LayerSnapshotTest, updateSnapshot) {
Vishnu Nairc765c6c2023-02-23 00:08:01 +0000132 LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(),
133 .layerLifecycleManager = mLifecycleManager,
134 .includeMetadata = false,
135 .displays = mFrontEndDisplayInfos,
136 .globalShadowSettings = globalShadowSettings,
137 .supportedLayerGenericMetadata = {},
138 .genericLayerMetadataKeyMap = {}
139
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000140 };
141
142 LayerSnapshotBuilder builder;
143 builder.update(args);
144}
145
146// update using parent snapshot data
147TEST_F(LayerSnapshotTest, croppedByParent) {
148 /// MAKE ALL LAYERS VISIBLE BY DEFAULT
149 DisplayInfo info;
150 info.info.logicalHeight = 100;
151 info.info.logicalWidth = 200;
152 mFrontEndDisplayInfos.emplace_or_replace(ui::LayerStack::fromValue(1), info);
153 Rect layerCrop(0, 0, 10, 20);
154 setCrop(11, layerCrop);
155 EXPECT_TRUE(mLifecycleManager.getGlobalChanges().test(RequestedLayerState::Changes::Geometry));
156 UPDATE_AND_VERIFY_WITH_DISPLAY_CHANGES(mSnapshotBuilder, STARTING_ZORDER);
157 EXPECT_EQ(getSnapshot(11)->geomCrop, layerCrop);
158 EXPECT_EQ(getSnapshot(111)->geomLayerBounds, layerCrop.toFloatRect());
159 float maxHeight = static_cast<float>(info.info.logicalHeight * 10);
160 float maxWidth = static_cast<float>(info.info.logicalWidth * 10);
161
162 FloatRect maxDisplaySize(-maxWidth, -maxHeight, maxWidth, maxHeight);
163 EXPECT_EQ(getSnapshot(1)->geomLayerBounds, maxDisplaySize);
164}
165
166// visibility tests
167TEST_F(LayerSnapshotTest, newLayerHiddenByPolicy) {
168 createLayer(112, 11);
169 hideLayer(112);
170 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
171
172 showLayer(112);
173 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 11, 111, 112, 12, 121, 122, 1221, 13, 2});
174}
175
176TEST_F(LayerSnapshotTest, hiddenByParent) {
177 hideLayer(11);
178 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 13, 2});
179}
180
181TEST_F(LayerSnapshotTest, reparentShowsChild) {
182 hideLayer(11);
183 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 13, 2});
184
185 showLayer(11);
186 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
187}
188
189TEST_F(LayerSnapshotTest, reparentHidesChild) {
190 hideLayer(11);
191 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 13, 2});
192
193 reparentLayer(121, 11);
194 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 122, 1221, 13, 2});
195}
196
197TEST_F(LayerSnapshotTest, unHidingUpdatesSnapshot) {
198 hideLayer(11);
199 Rect crop(1, 2, 3, 4);
200 setCrop(111, crop);
201 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 13, 2});
202
203 showLayer(11);
204 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
205 EXPECT_EQ(getSnapshot(111)->geomLayerBounds, crop.toFloatRect());
206}
207
208TEST_F(LayerSnapshotTest, childBehindParentCanBeHiddenByParent) {
209 setZ(111, -1);
210 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 111, 11, 12, 121, 122, 1221, 13, 2});
211
212 hideLayer(11);
213 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 13, 2});
214}
215
216// relative tests
217TEST_F(LayerSnapshotTest, RelativeParentCanHideChild) {
218 reparentRelativeLayer(13, 11);
219 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 11, 13, 111, 12, 121, 122, 1221, 2});
220
221 hideLayer(11);
222 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 2});
223}
224
225TEST_F(LayerSnapshotTest, ReparentingToHiddenRelativeParentHidesChild) {
226 hideLayer(11);
227 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 13, 2});
228 reparentRelativeLayer(13, 11);
229 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 2});
230}
231
232TEST_F(LayerSnapshotTest, AlphaInheritedByChildren) {
233 setAlpha(1, 0.5);
234 setAlpha(122, 0.5);
235 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
Vishnu Naira02943f2023-06-03 13:44:46 -0700236 EXPECT_EQ(getSnapshot(1)->alpha, 0.5f);
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000237 EXPECT_EQ(getSnapshot(12)->alpha, 0.5f);
238 EXPECT_EQ(getSnapshot(1221)->alpha, 0.25f);
239}
240
241// Change states
242TEST_F(LayerSnapshotTest, UpdateClearsPreviousChangeStates) {
243 setCrop(1, Rect(1, 2, 3, 4));
244 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
Vishnu Naira02943f2023-06-03 13:44:46 -0700245 EXPECT_TRUE(getSnapshot(1)->changes.test(RequestedLayerState::Changes::Geometry));
246 EXPECT_TRUE(getSnapshot(11)->changes.test(RequestedLayerState::Changes::Geometry));
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000247 setCrop(2, Rect(1, 2, 3, 4));
248 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
Vishnu Naira02943f2023-06-03 13:44:46 -0700249 EXPECT_TRUE(getSnapshot(2)->changes.test(RequestedLayerState::Changes::Geometry));
250 EXPECT_FALSE(getSnapshot(1)->changes.test(RequestedLayerState::Changes::Geometry));
251 EXPECT_FALSE(getSnapshot(11)->changes.test(RequestedLayerState::Changes::Geometry));
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000252}
253
254TEST_F(LayerSnapshotTest, FastPathClearsPreviousChangeStates) {
255 setColor(11, {1._hf, 0._hf, 0._hf});
256 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
Vishnu Naira02943f2023-06-03 13:44:46 -0700257 EXPECT_EQ(getSnapshot(11)->changes, RequestedLayerState::Changes::Content);
258 EXPECT_EQ(getSnapshot(11)->clientChanges, layer_state_t::eColorChanged);
259 EXPECT_EQ(getSnapshot(1)->changes.get(), 0u);
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000260 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
Vishnu Naira02943f2023-06-03 13:44:46 -0700261 EXPECT_EQ(getSnapshot(11)->changes.get(), 0u);
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000262}
263
264TEST_F(LayerSnapshotTest, FastPathSetsChangeFlagToContent) {
265 setColor(1, {1._hf, 0._hf, 0._hf});
266 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
267 EXPECT_EQ(getSnapshot(1)->changes, RequestedLayerState::Changes::Content);
Vishnu Naira02943f2023-06-03 13:44:46 -0700268 EXPECT_EQ(getSnapshot(1)->clientChanges, layer_state_t::eColorChanged);
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000269}
270
Vishnu Naircfb2d252023-01-19 04:44:02 +0000271TEST_F(LayerSnapshotTest, GameMode) {
272 std::vector<TransactionState> transactions;
273 transactions.emplace_back();
274 transactions.back().states.push_back({});
275 transactions.back().states.front().state.what = layer_state_t::eMetadataChanged;
276 transactions.back().states.front().state.metadata = LayerMetadata();
277 transactions.back().states.front().state.metadata.setInt32(METADATA_GAME_MODE, 42);
Vishnu Nair1391de22023-03-05 19:56:14 -0800278 transactions.back().states.front().layerId = 1;
Vishnu Naircfb2d252023-01-19 04:44:02 +0000279 transactions.back().states.front().state.layerId = static_cast<int32_t>(1);
280 mLifecycleManager.applyTransactions(transactions);
Nergi Rahardi6431d4a2024-05-15 18:42:48 +0900281 EXPECT_EQ(mLifecycleManager.getGlobalChanges(),
282 RequestedLayerState::Changes::GameMode | RequestedLayerState::Changes::Metadata);
Vishnu Naircfb2d252023-01-19 04:44:02 +0000283 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
Vishnu Naira02943f2023-06-03 13:44:46 -0700284 EXPECT_EQ(getSnapshot(1)->clientChanges, layer_state_t::eMetadataChanged);
Vishnu Naircfb2d252023-01-19 04:44:02 +0000285 EXPECT_EQ(static_cast<int32_t>(getSnapshot(1)->gameMode), 42);
286 EXPECT_EQ(static_cast<int32_t>(getSnapshot(11)->gameMode), 42);
287}
288
Nergi Rahardi6431d4a2024-05-15 18:42:48 +0900289TEST_F(LayerSnapshotTest, UpdateMetadata) {
290 std::vector<TransactionState> transactions;
291 transactions.emplace_back();
292 transactions.back().states.push_back({});
293 transactions.back().states.front().state.what = layer_state_t::eMetadataChanged;
294 // This test focuses on metadata used by ARC++ to ensure LayerMetadata is updated correctly,
295 // and not using stale data.
296 transactions.back().states.front().state.metadata = LayerMetadata();
297 transactions.back().states.front().state.metadata.setInt32(METADATA_OWNER_UID, 123);
298 transactions.back().states.front().state.metadata.setInt32(METADATA_WINDOW_TYPE, 234);
299 transactions.back().states.front().state.metadata.setInt32(METADATA_TASK_ID, 345);
300 transactions.back().states.front().state.metadata.setInt32(METADATA_MOUSE_CURSOR, 456);
301 transactions.back().states.front().state.metadata.setInt32(METADATA_ACCESSIBILITY_ID, 567);
302 transactions.back().states.front().state.metadata.setInt32(METADATA_OWNER_PID, 678);
303 transactions.back().states.front().state.metadata.setInt32(METADATA_CALLING_UID, 789);
304
305 transactions.back().states.front().layerId = 1;
306 transactions.back().states.front().state.layerId = static_cast<int32_t>(1);
307
308 mLifecycleManager.applyTransactions(transactions);
309 EXPECT_EQ(mLifecycleManager.getGlobalChanges(), RequestedLayerState::Changes::Metadata);
310
311 // Setting includeMetadata=true to ensure metadata update is applied to LayerSnapshot
312 LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(),
313 .layerLifecycleManager = mLifecycleManager,
314 .includeMetadata = true,
315 .displays = mFrontEndDisplayInfos,
316 .globalShadowSettings = globalShadowSettings,
317 .supportsBlur = true,
318 .supportedLayerGenericMetadata = {},
319 .genericLayerMetadataKeyMap = {}};
320 update(mSnapshotBuilder, args);
321
322 EXPECT_EQ(getSnapshot(1)->clientChanges, layer_state_t::eMetadataChanged);
323 EXPECT_EQ(getSnapshot(1)->layerMetadata.getInt32(METADATA_OWNER_UID, -1), 123);
324 EXPECT_EQ(getSnapshot(1)->layerMetadata.getInt32(METADATA_WINDOW_TYPE, -1), 234);
325 EXPECT_EQ(getSnapshot(1)->layerMetadata.getInt32(METADATA_TASK_ID, -1), 345);
326 EXPECT_EQ(getSnapshot(1)->layerMetadata.getInt32(METADATA_MOUSE_CURSOR, -1), 456);
327 EXPECT_EQ(getSnapshot(1)->layerMetadata.getInt32(METADATA_ACCESSIBILITY_ID, -1), 567);
328 EXPECT_EQ(getSnapshot(1)->layerMetadata.getInt32(METADATA_OWNER_PID, -1), 678);
329 EXPECT_EQ(getSnapshot(1)->layerMetadata.getInt32(METADATA_CALLING_UID, -1), 789);
330}
331
Garfield Tan8eb8f352024-05-17 09:12:01 -0700332TEST_F(LayerSnapshotTest, UpdateMetadataOfHiddenLayers) {
333 hideLayer(1);
334
335 std::vector<TransactionState> transactions;
336 transactions.emplace_back();
337 transactions.back().states.push_back({});
338 transactions.back().states.front().state.what = layer_state_t::eMetadataChanged;
339 // This test focuses on metadata used by ARC++ to ensure LayerMetadata is updated correctly,
340 // and not using stale data.
341 transactions.back().states.front().state.metadata = LayerMetadata();
342 transactions.back().states.front().state.metadata.setInt32(METADATA_OWNER_UID, 123);
343 transactions.back().states.front().state.metadata.setInt32(METADATA_WINDOW_TYPE, 234);
344 transactions.back().states.front().state.metadata.setInt32(METADATA_TASK_ID, 345);
345 transactions.back().states.front().state.metadata.setInt32(METADATA_MOUSE_CURSOR, 456);
346 transactions.back().states.front().state.metadata.setInt32(METADATA_ACCESSIBILITY_ID, 567);
347 transactions.back().states.front().state.metadata.setInt32(METADATA_OWNER_PID, 678);
348 transactions.back().states.front().state.metadata.setInt32(METADATA_CALLING_UID, 789);
349
350 transactions.back().states.front().layerId = 1;
351 transactions.back().states.front().state.layerId = static_cast<int32_t>(1);
352
353 mLifecycleManager.applyTransactions(transactions);
354 EXPECT_EQ(mLifecycleManager.getGlobalChanges(),
355 RequestedLayerState::Changes::Metadata | RequestedLayerState::Changes::Visibility |
356 RequestedLayerState::Changes::VisibleRegion |
357 RequestedLayerState::Changes::AffectsChildren);
358
359 // Setting includeMetadata=true to ensure metadata update is applied to LayerSnapshot
360 LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(),
361 .layerLifecycleManager = mLifecycleManager,
362 .includeMetadata = true,
363 .displays = mFrontEndDisplayInfos,
364 .globalShadowSettings = globalShadowSettings,
365 .supportsBlur = true,
366 .supportedLayerGenericMetadata = {},
367 .genericLayerMetadataKeyMap = {}};
368 update(mSnapshotBuilder, args);
369
370 EXPECT_EQ(static_cast<int64_t>(getSnapshot(1)->clientChanges),
371 layer_state_t::eMetadataChanged | layer_state_t::eFlagsChanged);
372 EXPECT_EQ(getSnapshot(1)->layerMetadata.getInt32(METADATA_OWNER_UID, -1), 123);
373 EXPECT_EQ(getSnapshot(1)->layerMetadata.getInt32(METADATA_WINDOW_TYPE, -1), 234);
374 EXPECT_EQ(getSnapshot(1)->layerMetadata.getInt32(METADATA_TASK_ID, -1), 345);
375 EXPECT_EQ(getSnapshot(1)->layerMetadata.getInt32(METADATA_MOUSE_CURSOR, -1), 456);
376 EXPECT_EQ(getSnapshot(1)->layerMetadata.getInt32(METADATA_ACCESSIBILITY_ID, -1), 567);
377 EXPECT_EQ(getSnapshot(1)->layerMetadata.getInt32(METADATA_OWNER_PID, -1), 678);
378 EXPECT_EQ(getSnapshot(1)->layerMetadata.getInt32(METADATA_CALLING_UID, -1), 789);
379}
380
Vishnu Naircfb2d252023-01-19 04:44:02 +0000381TEST_F(LayerSnapshotTest, NoLayerVoteForParentWithChildVotes) {
382 // ROOT
383 // ├── 1
384 // │ ├── 11 (frame rate set)
385 // │ │ └── 111
386 // │ ├── 12
387 // │ │ ├── 121
388 // │ │ └── 122
389 // │ │ └── 1221
390 // │ └── 13
391 // └── 2
392
Vishnu Nair30515cb2023-10-19 21:54:08 -0700393 setFrameRate(11, 90.0, ANATIVEWINDOW_FRAME_RATE_EXACT, ANATIVEWINDOW_CHANGE_FRAME_RATE_ALWAYS);
Vishnu Naircfb2d252023-01-19 04:44:02 +0000394 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
395
Rachel Leece6e0042023-06-27 11:22:54 -0700396 EXPECT_EQ(getSnapshot(11)->frameRate.vote.rate.getIntValue(), 90);
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700397 EXPECT_EQ(getSnapshot(11)->frameRate.vote.type, scheduler::FrameRateCompatibility::Exact);
Rachel Leece6e0042023-06-27 11:22:54 -0700398 EXPECT_EQ(getSnapshot(111)->frameRate.vote.rate.getIntValue(), 90);
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700399 EXPECT_EQ(getSnapshot(111)->frameRate.vote.type, scheduler::FrameRateCompatibility::Exact);
Rachel Leece6e0042023-06-27 11:22:54 -0700400 EXPECT_EQ(getSnapshot(1)->frameRate.vote.rate.getIntValue(), 0);
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700401 EXPECT_EQ(getSnapshot(1)->frameRate.vote.type, scheduler::FrameRateCompatibility::NoVote);
Vishnu Naircfb2d252023-01-19 04:44:02 +0000402}
403
Vishnu Nair30515cb2023-10-19 21:54:08 -0700404TEST_F(LayerSnapshotTest, NoLayerVoteForParentWithChildVotesDoesNotAffectSiblings) {
405 // ROOT
406 // ├── 1 (verify layer has no vote)
407 // │ ├── 11 (frame rate set)
408 // │ │ └── 111
409 // │ ├── 12 (frame rate set)
410 // │ │ ├── 121
411 // │ │ └── 122
412 // │ │ └── 1221
413 // │ └── 13 (verify layer has default vote)
414 // └── 2
415
416 setFrameRate(11, 90.0, ANATIVEWINDOW_FRAME_RATE_EXACT, ANATIVEWINDOW_CHANGE_FRAME_RATE_ALWAYS);
417 setFrameRate(12, 45.0, ANATIVEWINDOW_FRAME_RATE_EXACT, ANATIVEWINDOW_CHANGE_FRAME_RATE_ALWAYS);
418
419 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
420
421 EXPECT_EQ(getSnapshot(11)->frameRate.vote.rate.getIntValue(), 90);
422 EXPECT_EQ(getSnapshot(11)->frameRate.vote.type, scheduler::FrameRateCompatibility::Exact);
423 EXPECT_EQ(getSnapshot(111)->frameRate.vote.rate.getIntValue(), 90);
424 EXPECT_EQ(getSnapshot(111)->frameRate.vote.type, scheduler::FrameRateCompatibility::Exact);
425 EXPECT_EQ(getSnapshot(12)->frameRate.vote.rate.getIntValue(), 45);
426 EXPECT_EQ(getSnapshot(12)->frameRate.vote.type, scheduler::FrameRateCompatibility::Exact);
427 EXPECT_EQ(getSnapshot(121)->frameRate.vote.rate.getIntValue(), 45);
428 EXPECT_EQ(getSnapshot(121)->frameRate.vote.type, scheduler::FrameRateCompatibility::Exact);
429 EXPECT_EQ(getSnapshot(1221)->frameRate.vote.rate.getIntValue(), 45);
430 EXPECT_EQ(getSnapshot(1221)->frameRate.vote.type, scheduler::FrameRateCompatibility::Exact);
431
432 EXPECT_EQ(getSnapshot(1)->frameRate.vote.rate.getIntValue(), 0);
433 EXPECT_EQ(getSnapshot(1)->frameRate.vote.type, scheduler::FrameRateCompatibility::NoVote);
434 EXPECT_EQ(getSnapshot(13)->frameRate.vote.rate.getIntValue(), 0);
435 EXPECT_EQ(getSnapshot(13)->frameRate.vote.type, scheduler::FrameRateCompatibility::Default);
436 EXPECT_EQ(getSnapshot(2)->frameRate.vote.rate.getIntValue(), 0);
437 EXPECT_EQ(getSnapshot(2)->frameRate.vote.type, scheduler::FrameRateCompatibility::Default);
438}
439
Vishnu Naira02943f2023-06-03 13:44:46 -0700440TEST_F(LayerSnapshotTest, CanCropTouchableRegion) {
Vishnu Nair29354ec2023-03-28 18:51:28 -0700441 // ROOT
442 // ├── 1
443 // │ ├── 11
444 // │ │ └── 111 (touchregion set to touch but cropped by layer 13)
445 // │ ├── 12
446 // │ │ ├── 121
447 // │ │ └── 122
448 // │ │ └── 1221
449 // │ └── 13 (crop set to touchCrop)
450 // └── 2
451
452 Rect touchCrop{300, 300, 400, 500};
453 setCrop(13, touchCrop);
454 Region touch{Rect{0, 0, 1000, 1000}};
455 setTouchableRegionCrop(111, touch, /*touchCropId=*/13, /*replaceTouchableRegionWithCrop=*/true);
456 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
457 EXPECT_EQ(getSnapshot({.id = 111})->inputInfo.touchableRegion.bounds(), touchCrop);
458
459 Rect modifiedTouchCrop{100, 300, 400, 700};
460 setCrop(13, modifiedTouchCrop);
461 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
462 EXPECT_EQ(getSnapshot({.id = 111})->inputInfo.touchableRegion.bounds(), modifiedTouchCrop);
463}
464
Chavi Weingarten1ba381e2024-01-09 21:54:11 +0000465TEST_F(LayerSnapshotTest, CanCropTouchableRegionWithDisplayTransform) {
466 DisplayInfo displayInfo;
467 displayInfo.transform = ui::Transform(ui::Transform::RotationFlags::ROT_90, 1000, 1000);
468 mFrontEndDisplayInfos.emplace_or_replace(ui::LayerStack::fromValue(1), displayInfo);
469
470 Rect touchCrop{300, 300, 400, 500};
471 createRootLayer(3);
472 setCrop(3, touchCrop);
473 setLayerStack(3, 1);
474 Region touch{Rect{0, 0, 1000, 1000}};
475 setTouchableRegionCrop(3, touch, /*touchCropId=*/3, /*replaceTouchableRegionWithCrop=*/false);
476
477 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 11, 111, 12, 121, 122, 1221, 13, 2, 3});
478 Rect rotatedCrop = {500, 300, 700, 400};
479 EXPECT_EQ(getSnapshot({.id = 3})->inputInfo.touchableRegion.bounds(), rotatedCrop);
480}
481
Vishnu Nair444f3952023-04-11 13:01:02 -0700482TEST_F(LayerSnapshotTest, blurUpdatesWhenAlphaChanges) {
Vishnu Nair854ce1c2023-08-19 15:00:13 -0700483 int blurRadius = 42;
484 setBackgroundBlurRadius(1221, static_cast<uint32_t>(blurRadius));
Vishnu Nair444f3952023-04-11 13:01:02 -0700485
486 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
487 EXPECT_EQ(getSnapshot({.id = 1221})->backgroundBlurRadius, blurRadius);
488
Vishnu Nair854ce1c2023-08-19 15:00:13 -0700489 blurRadius = 21;
490 setBackgroundBlurRadius(1221, static_cast<uint32_t>(blurRadius));
491 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
492 EXPECT_EQ(getSnapshot({.id = 1221})->backgroundBlurRadius, blurRadius);
493
Vishnu Nair444f3952023-04-11 13:01:02 -0700494 static constexpr float alpha = 0.5;
495 setAlpha(12, alpha);
496 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
Vishnu Nair854ce1c2023-08-19 15:00:13 -0700497 EXPECT_EQ(getSnapshot({.id = 1221})->backgroundBlurRadius,
498 static_cast<int>(static_cast<float>(blurRadius) * alpha));
Vishnu Nair444f3952023-04-11 13:01:02 -0700499}
500
Vishnu Naira9c43762023-01-27 19:10:25 +0000501// Display Mirroring Tests
502// tree with 3 levels of children
503// ROOT (DISPLAY 0)
504// ├── 1
505// │ ├── 11
506// │ │ └── 111
507// │ ├── 12 (has skip screenshot flag)
508// │ │ ├── 121
509// │ │ └── 122
510// │ │ └── 1221
511// │ └── 13
512// └── 2
513// ROOT (DISPLAY 1)
514// └── 3 (mirrors display 0)
Vishnu Nair92990e22023-02-24 20:01:05 +0000515TEST_F(LayerSnapshotTest, displayMirrorRespectsLayerSkipScreenshotFlag) {
Vishnu Naira9c43762023-01-27 19:10:25 +0000516 setFlags(12, layer_state_t::eLayerSkipScreenshot, layer_state_t::eLayerSkipScreenshot);
517 createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0));
518 setLayerStack(3, 1);
519
Vishnu Nair444f3952023-04-11 13:01:02 -0700520 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 +0000521 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
522}
523
Vishnu Nair92990e22023-02-24 20:01:05 +0000524// ROOT (DISPLAY 0)
525// ├── 1
526// │ ├── 11
527// │ │ └── 111
528// │ └── 13
529// └── 2
530// ROOT (DISPLAY 3)
531// └── 3 (mirrors display 0)
532TEST_F(LayerSnapshotTest, mirrorLayerGetsCorrectLayerStack) {
533 reparentLayer(12, UNASSIGNED_LAYER_ID);
534 createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0));
535 setLayerStack(3, 3);
536 createDisplayMirrorLayer(4, ui::LayerStack::fromValue(0));
537 setLayerStack(4, 4);
538
Vishnu Nair444f3952023-04-11 13:01:02 -0700539 std::vector<uint32_t> expected = {1, 11, 111, 13, 2, 3, 1, 11, 111,
540 13, 2, 4, 1, 11, 111, 13, 2};
Vishnu Nair92990e22023-02-24 20:01:05 +0000541 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
Vishnu Nair6f878312023-09-08 11:05:01 -0700542 EXPECT_EQ(getSnapshot({.id = 111, .mirrorRootIds = 3u})->outputFilter.layerStack.id, 3u);
543 EXPECT_EQ(getSnapshot({.id = 111, .mirrorRootIds = 4u})->outputFilter.layerStack.id, 4u);
Vishnu Nair92990e22023-02-24 20:01:05 +0000544}
545
546// ROOT (DISPLAY 0)
547// ├── 1 (crop 50x50)
548// │ ├── 11
549// │ │ └── 111
550// │ └── 13
551// └── 2
552// ROOT (DISPLAY 3)
553// └── 3 (mirrors display 0) (crop 100x100)
554TEST_F(LayerSnapshotTest, mirrorLayerTouchIsCroppedByMirrorRoot) {
555 reparentLayer(12, UNASSIGNED_LAYER_ID);
556 createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0));
557 setLayerStack(3, 3);
558 setCrop(1, Rect{50, 50});
559 setCrop(3, Rect{100, 100});
560 setCrop(111, Rect{200, 200});
561 Region touch{Rect{0, 0, 1000, 1000}};
562 setTouchableRegion(111, touch);
Vishnu Nair444f3952023-04-11 13:01:02 -0700563 std::vector<uint32_t> expected = {1, 11, 111, 13, 2, 3, 1, 11, 111, 13, 2};
Vishnu Nair92990e22023-02-24 20:01:05 +0000564 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
565 EXPECT_TRUE(getSnapshot({.id = 111})->inputInfo.touchableRegion.hasSameRects(touch));
566 Region touchCroppedByMirrorRoot{Rect{0, 0, 50, 50}};
Vishnu Nair6f878312023-09-08 11:05:01 -0700567 EXPECT_TRUE(getSnapshot({.id = 111, .mirrorRootIds = 3u})
Vishnu Nair92990e22023-02-24 20:01:05 +0000568 ->inputInfo.touchableRegion.hasSameRects(touchCroppedByMirrorRoot));
569}
570
571TEST_F(LayerSnapshotTest, canRemoveDisplayMirror) {
572 setFlags(12, layer_state_t::eLayerSkipScreenshot, layer_state_t::eLayerSkipScreenshot);
573 createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0));
574 setLayerStack(3, 1);
Vishnu Nair444f3952023-04-11 13:01:02 -0700575 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 +0000576 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
577 destroyLayerHandle(3);
578 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
579}
580
Vishnu Nairfccd6362023-02-24 23:39:53 +0000581TEST_F(LayerSnapshotTest, cleanUpUnreachableSnapshotsAfterMirroring) {
582 size_t startingNumSnapshots = mSnapshotBuilder.getSnapshots().size();
583 createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0));
584 setLayerStack(3, 1);
Vishnu Nair444f3952023-04-11 13:01:02 -0700585 std::vector<uint32_t> expected = {1, 11, 111, 12, 121, 122, 1221, 13, 2, 3,
586 1, 11, 111, 12, 121, 122, 1221, 13, 2};
Vishnu Nairfccd6362023-02-24 23:39:53 +0000587 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
588 destroyLayerHandle(3);
589 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
590
591 EXPECT_EQ(startingNumSnapshots, mSnapshotBuilder.getSnapshots().size());
592}
593
Vishnu Nair6f878312023-09-08 11:05:01 -0700594TEST_F(LayerSnapshotTest, canMirrorDisplayWithMirrors) {
595 reparentLayer(12, UNASSIGNED_LAYER_ID);
596 mirrorLayer(/*layer*/ 14, /*parent*/ 1, /*layerToMirror*/ 11);
597 std::vector<uint32_t> expected = {1, 11, 111, 13, 14, 11, 111, 2};
598 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
599
600 createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0));
601 setLayerStack(3, 3);
602 expected = {1, 11, 111, 13, 14, 11, 111, 2, 3, 1, 11, 111, 13, 14, 11, 111, 2};
603 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
604 EXPECT_EQ(getSnapshot({.id = 11, .mirrorRootIds = 14u})->outputFilter.layerStack.id, 0u);
605 EXPECT_EQ(getSnapshot({.id = 11, .mirrorRootIds = 3u})->outputFilter.layerStack.id, 3u);
606 EXPECT_EQ(getSnapshot({.id = 11, .mirrorRootIds = 3u, 14u})->outputFilter.layerStack.id, 3u);
607}
608
Vishnu Nairfccd6362023-02-24 23:39:53 +0000609// Rel z doesn't create duplicate snapshots but this is for completeness
610TEST_F(LayerSnapshotTest, cleanUpUnreachableSnapshotsAfterRelZ) {
611 size_t startingNumSnapshots = mSnapshotBuilder.getSnapshots().size();
612 reparentRelativeLayer(13, 11);
613 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 11, 13, 111, 12, 121, 122, 1221, 2});
614 setZ(13, 0);
615 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
616
617 EXPECT_EQ(startingNumSnapshots, mSnapshotBuilder.getSnapshots().size());
618}
619
620TEST_F(LayerSnapshotTest, cleanUpUnreachableSnapshotsAfterLayerDestruction) {
621 size_t startingNumSnapshots = mSnapshotBuilder.getSnapshots().size();
622 destroyLayerHandle(2);
623 destroyLayerHandle(122);
624
625 std::vector<uint32_t> expected = {1, 11, 111, 12, 121, 122, 1221, 13};
626 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
627
628 EXPECT_LE(startingNumSnapshots - 2, mSnapshotBuilder.getSnapshots().size());
629}
630
Vishnu Nair3d8565a2023-06-30 07:23:24 +0000631TEST_F(LayerSnapshotTest, snashotContainsMetadataFromLayerCreationArgs) {
632 LayerCreationArgs args(std::make_optional<uint32_t>(200));
633 args.name = "testlayer";
634 args.addToRoot = true;
635 args.metadata.setInt32(42, 24);
636
637 std::vector<std::unique_ptr<RequestedLayerState>> layers;
638 layers.emplace_back(std::make_unique<RequestedLayerState>(args));
639 EXPECT_TRUE(layers.back()->metadata.has(42));
640 EXPECT_EQ(layers.back()->metadata.getInt32(42, 0), 24);
641 mLifecycleManager.addLayers(std::move(layers));
642
643 std::vector<uint32_t> expected = STARTING_ZORDER;
644 expected.push_back(200);
645 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
646
647 EXPECT_TRUE(mSnapshotBuilder.getSnapshot(200)->layerMetadata.has(42));
648 EXPECT_EQ(mSnapshotBuilder.getSnapshot(200)->layerMetadata.getInt32(42, 0), 24);
649}
650
651TEST_F(LayerSnapshotTest, frameRateSelectionPriorityPassedToChildLayers) {
652 setFrameRateSelectionPriority(11, 1);
653
654 setFrameRateSelectionPriority(12, 2);
655
656 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
657 EXPECT_EQ(getSnapshot({.id = 1})->frameRateSelectionPriority, Layer::PRIORITY_UNSET);
658 EXPECT_EQ(getSnapshot({.id = 11})->frameRateSelectionPriority, 1);
659 EXPECT_EQ(getSnapshot({.id = 12})->frameRateSelectionPriority, 2);
660 EXPECT_EQ(getSnapshot({.id = 122})->frameRateSelectionPriority, 2);
661 EXPECT_EQ(getSnapshot({.id = 1221})->frameRateSelectionPriority, 2);
662
663 // reparent and verify the child gets the new parent's framerate selection priority
664 reparentLayer(122, 11);
665
666 std::vector<uint32_t> expected = {1, 11, 111, 122, 1221, 12, 121, 13, 2};
667 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
668 EXPECT_EQ(getSnapshot({.id = 1})->frameRateSelectionPriority, Layer::PRIORITY_UNSET);
669 EXPECT_EQ(getSnapshot({.id = 11})->frameRateSelectionPriority, 1);
670 EXPECT_EQ(getSnapshot({.id = 12})->frameRateSelectionPriority, 2);
671 EXPECT_EQ(getSnapshot({.id = 122})->frameRateSelectionPriority, 1);
672 EXPECT_EQ(getSnapshot({.id = 1221})->frameRateSelectionPriority, 1);
673}
674
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000675TEST_F(LayerSnapshotTest, framerate) {
676 setFrameRate(11, 244.f, 0, 0);
677
678 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
679 // verify parent is gets no vote
Rachel Leece6e0042023-06-27 11:22:54 -0700680 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
681 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700682 scheduler::FrameRateCompatibility::NoVote);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000683 EXPECT_TRUE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate));
684
685 // verify layer and children get the requested votes
Rachel Leece6e0042023-06-27 11:22:54 -0700686 EXPECT_TRUE(getSnapshot({.id = 11})->frameRate.vote.rate.isValid());
687 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 244.f);
688 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700689 scheduler::FrameRateCompatibility::Default);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000690 EXPECT_TRUE(getSnapshot({.id = 11})->changes.test(RequestedLayerState::Changes::FrameRate));
691
Rachel Leece6e0042023-06-27 11:22:54 -0700692 EXPECT_TRUE(getSnapshot({.id = 111})->frameRate.vote.rate.isValid());
693 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.rate.getValue(), 244.f);
694 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700695 scheduler::FrameRateCompatibility::Default);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000696 EXPECT_TRUE(getSnapshot({.id = 111})->changes.test(RequestedLayerState::Changes::FrameRate));
697
698 // reparent and verify the child gets the new parent's framerate
699 reparentLayer(122, 11);
700
701 std::vector<uint32_t> expected = {1, 11, 111, 122, 1221, 12, 121, 13, 2};
702 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
703 // verify parent is gets no vote
Rachel Leece6e0042023-06-27 11:22:54 -0700704 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
705 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700706 scheduler::FrameRateCompatibility::NoVote);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000707
708 // verify layer and children get the requested votes
Rachel Leece6e0042023-06-27 11:22:54 -0700709 EXPECT_TRUE(getSnapshot({.id = 11})->frameRate.vote.rate.isValid());
710 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 244.f);
711 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700712 scheduler::FrameRateCompatibility::Default);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000713
Rachel Leece6e0042023-06-27 11:22:54 -0700714 EXPECT_TRUE(getSnapshot({.id = 111})->frameRate.vote.rate.isValid());
715 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.rate.getValue(), 244.f);
716 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700717 scheduler::FrameRateCompatibility::Default);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000718
Rachel Leece6e0042023-06-27 11:22:54 -0700719 EXPECT_TRUE(getSnapshot({.id = 122})->frameRate.vote.rate.isValid());
720 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.rate.getValue(), 244.f);
721 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700722 scheduler::FrameRateCompatibility::Default);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000723 EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate));
724
725 // reparent and verify the new parent gets no vote
726 reparentLayer(11, 2);
727 expected = {1, 12, 121, 13, 2, 11, 111, 122, 1221};
728 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
729
730 // verify old parent has invalid framerate (default)
Rachel Leece6e0042023-06-27 11:22:54 -0700731 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
732 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700733 scheduler::FrameRateCompatibility::Default);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000734 EXPECT_TRUE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate));
735
736 // verify new parent get no vote
Rachel Leece6e0042023-06-27 11:22:54 -0700737 EXPECT_FALSE(getSnapshot({.id = 2})->frameRate.vote.rate.isValid());
738 EXPECT_EQ(getSnapshot({.id = 2})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700739 scheduler::FrameRateCompatibility::NoVote);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000740 EXPECT_TRUE(getSnapshot({.id = 2})->changes.test(RequestedLayerState::Changes::FrameRate));
741
742 // verify layer and children get the requested votes (unchanged)
Rachel Leece6e0042023-06-27 11:22:54 -0700743 EXPECT_TRUE(getSnapshot({.id = 11})->frameRate.vote.rate.isValid());
744 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 244.f);
745 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700746 scheduler::FrameRateCompatibility::Default);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000747
Rachel Leece6e0042023-06-27 11:22:54 -0700748 EXPECT_TRUE(getSnapshot({.id = 111})->frameRate.vote.rate.isValid());
749 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.rate.getValue(), 244.f);
750 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700751 scheduler::FrameRateCompatibility::Default);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000752
Rachel Leece6e0042023-06-27 11:22:54 -0700753 EXPECT_TRUE(getSnapshot({.id = 122})->frameRate.vote.rate.isValid());
754 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.rate.getValue(), 244.f);
755 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700756 scheduler::FrameRateCompatibility::Default);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000757}
758
Vishnu Nair3996ee32023-08-14 04:32:31 +0000759TEST_F(LayerSnapshotTest, translateDataspace) {
760 setDataspace(1, ui::Dataspace::UNKNOWN);
761 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
762 EXPECT_EQ(getSnapshot({.id = 1})->dataspace, ui::Dataspace::V0_SRGB);
763}
764
Rachel Leece6e0042023-06-27 11:22:54 -0700765// This test is similar to "frameRate" test case but checks that the setFrameRateCategory API
766// interaction also works correctly with the setFrameRate API within SF frontend.
767TEST_F(LayerSnapshotTest, frameRateWithCategory) {
Rachel Lee45681982024-03-14 18:40:15 -0700768 SET_FLAG_FOR_TEST(flags::frame_rate_category_mrr, true);
769
Rachel Leece6e0042023-06-27 11:22:54 -0700770 // ROOT
771 // ├── 1
772 // │ ├── 11 (frame rate set to 244.f)
773 // │ │ └── 111
774 // │ ├── 12
775 // │ │ ├── 121
776 // │ │ └── 122 (frame rate category set to Normal)
777 // │ │ └── 1221
778 // │ └── 13
779 // └── 2
780 setFrameRate(11, 244.f, 0, 0);
Rachel Lee9580ff12023-12-26 17:33:41 -0800781 setFrameRateCategory(122, ANATIVEWINDOW_FRAME_RATE_CATEGORY_NORMAL);
Rachel Leece6e0042023-06-27 11:22:54 -0700782
783 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
784 // verify parent 1 gets no vote
785 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
786 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700787 scheduler::FrameRateCompatibility::NoVote);
Rachel Leece6e0042023-06-27 11:22:54 -0700788 EXPECT_TRUE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate));
789
790 // verify layer 11 and children 111 get the requested votes
791 EXPECT_TRUE(getSnapshot({.id = 11})->frameRate.vote.rate.isValid());
792 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 244.f);
793 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700794 scheduler::FrameRateCompatibility::Default);
Rachel Leece6e0042023-06-27 11:22:54 -0700795 EXPECT_TRUE(getSnapshot({.id = 11})->changes.test(RequestedLayerState::Changes::FrameRate));
796
797 EXPECT_TRUE(getSnapshot({.id = 111})->frameRate.vote.rate.isValid());
798 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.rate.getValue(), 244.f);
799 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700800 scheduler::FrameRateCompatibility::Default);
Rachel Leece6e0042023-06-27 11:22:54 -0700801 EXPECT_TRUE(getSnapshot({.id = 111})->changes.test(RequestedLayerState::Changes::FrameRate));
802
803 // verify parent 12 gets no vote
804 EXPECT_FALSE(getSnapshot({.id = 12})->frameRate.vote.rate.isValid());
805 EXPECT_EQ(getSnapshot({.id = 12})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700806 scheduler::FrameRateCompatibility::NoVote);
Rachel Leece6e0042023-06-27 11:22:54 -0700807 EXPECT_TRUE(getSnapshot({.id = 12})->changes.test(RequestedLayerState::Changes::FrameRate));
808
809 // verify layer 122 and children 1221 get the requested votes
810 EXPECT_FALSE(getSnapshot({.id = 122})->frameRate.vote.rate.isValid());
811 EXPECT_TRUE(getSnapshot({.id = 122})->frameRate.isValid());
812 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700813 scheduler::FrameRateCompatibility::Default);
Rachel Leece6e0042023-06-27 11:22:54 -0700814 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.category, FrameRateCategory::Normal);
815 EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate));
Rachel Lee43369b22023-09-05 18:40:40 -0700816 EXPECT_TRUE(
817 getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::AffectsChildren));
Rachel Leece6e0042023-06-27 11:22:54 -0700818
819 EXPECT_FALSE(getSnapshot({.id = 1221})->frameRate.vote.rate.isValid());
820 EXPECT_TRUE(getSnapshot({.id = 1221})->frameRate.isValid());
821 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700822 scheduler::FrameRateCompatibility::Default);
Rachel Leece6e0042023-06-27 11:22:54 -0700823 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.category, FrameRateCategory::Normal);
824 EXPECT_TRUE(getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::FrameRate));
Rachel Lee43369b22023-09-05 18:40:40 -0700825 EXPECT_TRUE(
826 getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::AffectsChildren));
Rachel Leece6e0042023-06-27 11:22:54 -0700827
828 // reparent and verify the child does NOT get the new parent's framerate because it already has
829 // the frame rate category specified.
830 // ROOT
831 // ├─1
832 // │ ├─11 (frame rate set to 244.f)
833 // │ │ ├─111
834 // │ │ └─122 (frame rate category set to Normal)
835 // │ │ └─1221
836 // │ ├─12
837 // │ │ └─121
838 // │ └─13
839 // └─2
840 reparentLayer(122, 11);
841
842 std::vector<uint32_t> expected = {1, 11, 111, 122, 1221, 12, 121, 13, 2};
843 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
844 // verify parent is gets no vote
845 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
846 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700847 scheduler::FrameRateCompatibility::NoVote);
Rachel Leece6e0042023-06-27 11:22:54 -0700848
849 // verify layer 11 and children 111 get the requested votes
850 EXPECT_TRUE(getSnapshot({.id = 11})->frameRate.vote.rate.isValid());
851 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 244.f);
852 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700853 scheduler::FrameRateCompatibility::Default);
Rachel Leece6e0042023-06-27 11:22:54 -0700854
855 EXPECT_TRUE(getSnapshot({.id = 111})->frameRate.vote.rate.isValid());
856 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.rate.getValue(), 244.f);
857 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700858 scheduler::FrameRateCompatibility::Default);
Rachel Leece6e0042023-06-27 11:22:54 -0700859
860 // verify layer 122 and children 1221 get the requested category vote (unchanged from
861 // reparenting)
862 EXPECT_FALSE(getSnapshot({.id = 122})->frameRate.vote.rate.isValid());
863 EXPECT_TRUE(getSnapshot({.id = 122})->frameRate.isValid());
864 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700865 scheduler::FrameRateCompatibility::Default);
Rachel Leece6e0042023-06-27 11:22:54 -0700866 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.category, FrameRateCategory::Normal);
867 EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate));
868
869 EXPECT_FALSE(getSnapshot({.id = 1221})->frameRate.vote.rate.isValid());
870 EXPECT_TRUE(getSnapshot({.id = 1221})->frameRate.isValid());
871 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700872 scheduler::FrameRateCompatibility::Default);
Rachel Leece6e0042023-06-27 11:22:54 -0700873 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.category, FrameRateCategory::Normal);
874 EXPECT_TRUE(getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::FrameRate));
875}
876
Rachel Lee58cc90d2023-09-05 18:50:20 -0700877TEST_F(LayerSnapshotTest, frameRateSelectionStrategy) {
878 // ROOT
879 // ├── 1
880 // │ ├── 11
881 // │ │ └── 111
882 // │ ├── 12 (frame rate set to 244.f with strategy OverrideChildren)
883 // │ │ ├── 121
884 // │ │ └── 122 (frame rate set to 123.f but should be overridden by layer 12)
885 // │ │ └── 1221
886 // │ └── 13
887 // └── 2
888 setFrameRate(12, 244.f, 0, 0);
889 setFrameRate(122, 123.f, 0, 0);
890 setFrameRateSelectionStrategy(12, 1 /* OverrideChildren */);
891
892 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
893 // verify parent 1 gets no vote
894 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
895 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700896 scheduler::FrameRateCompatibility::NoVote);
Rachel Lee58cc90d2023-09-05 18:50:20 -0700897 EXPECT_TRUE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate));
898
899 // verify layer 12 and all descendants (121, 122, 1221) get the requested vote
900 EXPECT_EQ(getSnapshot({.id = 12})->frameRate.vote.rate.getValue(), 244.f);
901 EXPECT_EQ(getSnapshot({.id = 12})->frameRateSelectionStrategy,
902 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
903 EXPECT_TRUE(getSnapshot({.id = 12})->changes.test(RequestedLayerState::Changes::FrameRate));
904
905 EXPECT_EQ(getSnapshot({.id = 121})->frameRate.vote.rate.getValue(), 244.f);
906 EXPECT_EQ(getSnapshot({.id = 121})->frameRateSelectionStrategy,
907 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
908 EXPECT_TRUE(getSnapshot({.id = 121})->changes.test(RequestedLayerState::Changes::FrameRate));
909
910 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.rate.getValue(), 244.f);
911 EXPECT_EQ(getSnapshot({.id = 122})->frameRateSelectionStrategy,
912 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
913 EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate));
914
915 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.vote.rate.getValue(), 244.f);
916 EXPECT_EQ(getSnapshot({.id = 1221})->frameRateSelectionStrategy,
917 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
918 EXPECT_TRUE(getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::FrameRate));
Vishnu Nair41376b62023-11-08 05:08:58 -0800919
920 // ROOT
921 // ├── 1
922 // │ ├── 11
923 // │ │ └── 111
924 // │ ├── 12 (frame rate set to default with strategy default)
925 // │ │ ├── 121
926 // │ │ └── 122 (frame rate set to 123.f)
927 // │ │ └── 1221
928 // │ └── 13
929 // └── 2
930 setFrameRate(12, -1.f, 0, 0);
931 setFrameRateSelectionStrategy(12, 0 /* Default */);
932 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
933 // verify parent 1 gets no vote
934 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
935 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
936 scheduler::FrameRateCompatibility::NoVote);
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})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -0800944 scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate);
Vishnu Nair41376b62023-11-08 05:08:58 -0800945 EXPECT_TRUE(getSnapshot({.id = 12})->changes.test(RequestedLayerState::Changes::FrameRate));
946
947 EXPECT_FALSE(getSnapshot({.id = 121})->frameRate.vote.rate.isValid());
948 EXPECT_EQ(getSnapshot({.id = 121})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -0800949 scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate);
Vishnu Nair41376b62023-11-08 05:08:58 -0800950 EXPECT_EQ(getSnapshot({.id = 121})->frameRate.vote.type,
951 scheduler::FrameRateCompatibility::Default);
952 EXPECT_TRUE(getSnapshot({.id = 121})->changes.test(RequestedLayerState::Changes::FrameRate));
953
954 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.rate.getValue(), 123.f);
955 EXPECT_EQ(getSnapshot({.id = 122})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -0800956 scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate);
Vishnu Nair41376b62023-11-08 05:08:58 -0800957 EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate));
958
959 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.vote.rate.getValue(), 123.f);
960 EXPECT_EQ(getSnapshot({.id = 1221})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -0800961 scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate);
Vishnu Nair41376b62023-11-08 05:08:58 -0800962 EXPECT_TRUE(getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::FrameRate));
963}
964
965TEST_F(LayerSnapshotTest, frameRateSelectionStrategyWithCategory) {
Rachel Lee45681982024-03-14 18:40:15 -0700966 SET_FLAG_FOR_TEST(flags::frame_rate_category_mrr, true);
967
Vishnu Nair41376b62023-11-08 05:08:58 -0800968 // ROOT
969 // ├── 1
970 // │ ├── 11
971 // │ │ └── 111
972 // │ ├── 12 (frame rate category set to high with strategy OverrideChildren)
973 // │ │ ├── 121
974 // │ │ └── 122 (frame rate set to 123.f but should be overridden by layer 12)
975 // │ │ └── 1221
976 // │ └── 13
977 // └── 2
Rachel Lee9580ff12023-12-26 17:33:41 -0800978 setFrameRateCategory(12, ANATIVEWINDOW_FRAME_RATE_CATEGORY_HIGH);
Vishnu Nair41376b62023-11-08 05:08:58 -0800979 setFrameRate(122, 123.f, 0, 0);
980 setFrameRateSelectionStrategy(12, 1 /* OverrideChildren */);
981
982 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
983 // verify parent 1 gets no vote
984 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
985 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
986 scheduler::FrameRateCompatibility::NoVote);
987 EXPECT_TRUE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate));
988
989 // verify layer 12 and all descendants (121, 122, 1221) get the requested vote
990 EXPECT_EQ(getSnapshot({.id = 12})->frameRate.category, FrameRateCategory::High);
991 EXPECT_EQ(getSnapshot({.id = 12})->frameRateSelectionStrategy,
992 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
993 EXPECT_TRUE(getSnapshot({.id = 12})->changes.test(RequestedLayerState::Changes::FrameRate));
994
995 EXPECT_EQ(getSnapshot({.id = 121})->frameRate.category, FrameRateCategory::High);
996 EXPECT_EQ(getSnapshot({.id = 121})->frameRateSelectionStrategy,
997 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
998 EXPECT_TRUE(getSnapshot({.id = 121})->changes.test(RequestedLayerState::Changes::FrameRate));
999
1000 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.category, FrameRateCategory::High);
1001 EXPECT_EQ(getSnapshot({.id = 122})->frameRateSelectionStrategy,
1002 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
1003 EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate));
1004
1005 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.category, FrameRateCategory::High);
1006 EXPECT_EQ(getSnapshot({.id = 1221})->frameRateSelectionStrategy,
1007 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
1008 EXPECT_TRUE(getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::FrameRate));
1009
1010 // ROOT
1011 // ├── 1
1012 // │ ├── 11
1013 // │ │ └── 111
1014 // │ ├── 12 (frame rate category to default with strategy default)
1015 // │ │ ├── 121
1016 // │ │ └── 122 (frame rate set to 123.f)
1017 // │ │ └── 1221
1018 // │ └── 13
1019 // └── 2
Rachel Lee9580ff12023-12-26 17:33:41 -08001020 setFrameRateCategory(12, ANATIVEWINDOW_FRAME_RATE_CATEGORY_DEFAULT);
Vishnu Nair41376b62023-11-08 05:08:58 -08001021 setFrameRateSelectionStrategy(12, 0 /* Default */);
1022 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1023 // verify parent 1 gets no vote
1024 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
1025 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
1026 scheduler::FrameRateCompatibility::NoVote);
1027 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.category, FrameRateCategory::Default);
1028 EXPECT_FALSE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate));
1029
1030 // verify layer 12 and all descendants (121, 122, 1221) get the requested vote
1031 EXPECT_FALSE(getSnapshot({.id = 12})->frameRate.vote.rate.isValid());
1032 EXPECT_EQ(getSnapshot({.id = 12})->frameRate.vote.type,
1033 scheduler::FrameRateCompatibility::NoVote);
1034 EXPECT_EQ(getSnapshot({.id = 12})->frameRate.category, FrameRateCategory::Default);
1035 EXPECT_EQ(getSnapshot({.id = 12})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -08001036 scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate);
Vishnu Nair41376b62023-11-08 05:08:58 -08001037 EXPECT_TRUE(getSnapshot({.id = 12})->changes.test(RequestedLayerState::Changes::FrameRate));
1038
1039 EXPECT_FALSE(getSnapshot({.id = 12})->frameRate.vote.rate.isValid());
1040 EXPECT_EQ(getSnapshot({.id = 121})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -08001041 scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate);
Vishnu Nair41376b62023-11-08 05:08:58 -08001042 EXPECT_EQ(getSnapshot({.id = 121})->frameRate.category, FrameRateCategory::Default);
1043 EXPECT_EQ(getSnapshot({.id = 121})->frameRate.vote.type,
1044 scheduler::FrameRateCompatibility::Default);
1045 EXPECT_TRUE(getSnapshot({.id = 121})->changes.test(RequestedLayerState::Changes::FrameRate));
1046
1047 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.rate.getValue(), 123.f);
1048 EXPECT_EQ(getSnapshot({.id = 122})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -08001049 scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate);
Vishnu Nair41376b62023-11-08 05:08:58 -08001050 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.category, FrameRateCategory::Default);
1051 EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate));
1052
1053 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.vote.rate.getValue(), 123.f);
1054 EXPECT_EQ(getSnapshot({.id = 1221})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -08001055 scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate);
Vishnu Nair41376b62023-11-08 05:08:58 -08001056 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.category, FrameRateCategory::Default);
1057 EXPECT_TRUE(getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::FrameRate));
Rachel Lee58cc90d2023-09-05 18:50:20 -07001058}
1059
Rachel Lee70f7b692023-11-22 11:24:02 -08001060TEST_F(LayerSnapshotTest, frameRateSelectionStrategyWithOverrideChildrenAndSelf) {
Rachel Leea021bb02023-11-20 21:51:09 -08001061 // ROOT
1062 // ├── 1
Rachel Lee70f7b692023-11-22 11:24:02 -08001063 // │ ├── 11 (frame rate set to 11.f with strategy Self)
Rachel Leea021bb02023-11-20 21:51:09 -08001064 // │ │ └── 111 (frame rate is not inherited)
1065 // │ ├── 12 (frame rate set to 244.f)
1066 // │ │ ├── 121
1067 // │ │ └── 122 (strategy OverrideChildren and inherits frame rate 244.f)
1068 // │ │ └── 1221 (frame rate set to 123.f but should be overridden by layer 122)
1069 // │ └── 13
1070 // └── 2
1071 setFrameRate(11, 11.f, 0, 0);
Rachel Lee70f7b692023-11-22 11:24:02 -08001072 setFrameRateSelectionStrategy(11, 2 /* Self */);
Rachel Leea021bb02023-11-20 21:51:09 -08001073 setFrameRate(12, 244.f, 0, 0);
1074 setFrameRateSelectionStrategy(122, 1 /* OverrideChildren */);
1075 setFrameRate(1221, 123.f, 0, 0);
1076
1077 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1078 // verify parent 1 gets no vote
1079 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
1080 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
1081 scheduler::FrameRateCompatibility::NoVote);
1082 EXPECT_EQ(getSnapshot({.id = 1})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -08001083 scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate);
Rachel Leea021bb02023-11-20 21:51:09 -08001084 EXPECT_TRUE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate));
1085
1086 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 11.f);
1087 EXPECT_EQ(getSnapshot({.id = 11})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -08001088 scheduler::LayerInfo::FrameRateSelectionStrategy::Self);
Rachel Leea021bb02023-11-20 21:51:09 -08001089 EXPECT_TRUE(getSnapshot({.id = 11})->changes.test(RequestedLayerState::Changes::FrameRate));
1090
1091 // verify layer 11 does does not propagate its framerate to 111.
1092 EXPECT_FALSE(getSnapshot({.id = 111})->frameRate.vote.rate.isValid());
1093 EXPECT_EQ(getSnapshot({.id = 111})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -08001094 scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate);
Rachel Leea021bb02023-11-20 21:51:09 -08001095 EXPECT_TRUE(getSnapshot({.id = 111})->changes.test(RequestedLayerState::Changes::FrameRate));
1096
1097 // verify layer 12 and all descendants (121, 122, 1221) get the requested vote
1098 EXPECT_EQ(getSnapshot({.id = 12})->frameRate.vote.rate.getValue(), 244.f);
1099 EXPECT_EQ(getSnapshot({.id = 12})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -08001100 scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate);
Rachel Leea021bb02023-11-20 21:51:09 -08001101 EXPECT_TRUE(getSnapshot({.id = 12})->changes.test(RequestedLayerState::Changes::FrameRate));
1102
1103 EXPECT_EQ(getSnapshot({.id = 121})->frameRate.vote.rate.getValue(), 244.f);
1104 EXPECT_EQ(getSnapshot({.id = 121})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -08001105 scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate);
Rachel Leea021bb02023-11-20 21:51:09 -08001106 EXPECT_TRUE(getSnapshot({.id = 121})->changes.test(RequestedLayerState::Changes::FrameRate));
1107
1108 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.rate.getValue(), 244.f);
1109 EXPECT_EQ(getSnapshot({.id = 122})->frameRateSelectionStrategy,
1110 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
1111 EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate));
1112
1113 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.vote.rate.getValue(), 244.f);
1114 EXPECT_EQ(getSnapshot({.id = 1221})->frameRateSelectionStrategy,
1115 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
1116 EXPECT_TRUE(getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::FrameRate));
1117
1118 // ROOT
1119 // ├── 1 (frame rate set to 1.f with strategy OverrideChildren)
Rachel Lee70f7b692023-11-22 11:24:02 -08001120 // │ ├── 11 (frame rate set to 11.f with strategy Self, but overridden by 1)
Rachel Leea021bb02023-11-20 21:51:09 -08001121 // │ │ └── 111 (frame rate inherited from 11 due to override from 1)
1122 // â‹® â‹®
1123 setFrameRate(1, 1.f, 0, 0);
1124 setFrameRateSelectionStrategy(1, 1 /* OverrideChildren */);
1125 setFrameRate(11, 11.f, 0, 0);
Rachel Lee70f7b692023-11-22 11:24:02 -08001126 setFrameRateSelectionStrategy(11, 2 /* Self */);
Rachel Leea021bb02023-11-20 21:51:09 -08001127 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1128
1129 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.rate.getValue(), 1.f);
1130 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
1131 scheduler::FrameRateCompatibility::Default);
1132 EXPECT_EQ(getSnapshot({.id = 1})->frameRateSelectionStrategy,
1133 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
1134 EXPECT_TRUE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate));
1135
1136 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 1.f);
1137 EXPECT_EQ(getSnapshot({.id = 11})->frameRateSelectionStrategy,
1138 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
1139 EXPECT_TRUE(getSnapshot({.id = 11})->changes.test(RequestedLayerState::Changes::FrameRate));
1140
1141 // verify layer 11 does does not propagate its framerate to 111.
1142 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.rate.getValue(), 1.f);
1143 EXPECT_EQ(getSnapshot({.id = 111})->frameRateSelectionStrategy,
1144 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
1145 EXPECT_TRUE(getSnapshot({.id = 111})->changes.test(RequestedLayerState::Changes::FrameRate));
1146}
1147
Vishnu Nair0808ae62023-08-07 21:42:42 -07001148TEST_F(LayerSnapshotTest, skipRoundCornersWhenProtected) {
1149 setRoundedCorners(1, 42.f);
1150 setRoundedCorners(2, 42.f);
1151 setCrop(1, Rect{1000, 1000});
1152 setCrop(2, Rect{1000, 1000});
1153
1154 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1155 EXPECT_TRUE(getSnapshot({.id = 1})->roundedCorner.hasRoundedCorners());
1156 EXPECT_EQ(getSnapshot({.id = 1})->roundedCorner.radius.x, 42.f);
1157 EXPECT_TRUE(getSnapshot({.id = 2})->roundedCorner.hasRoundedCorners());
1158
1159 // add a buffer with the protected bit, check rounded corners are not set when
1160 // skipRoundCornersWhenProtected == true
1161 setBuffer(1,
1162 std::make_shared<
1163 renderengine::mock::FakeExternalTexture>(1U /*width*/, 1U /*height*/,
1164 1ULL /* bufferId */,
1165 HAL_PIXEL_FORMAT_RGBA_8888,
1166 GRALLOC_USAGE_PROTECTED /*usage*/));
1167
1168 LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(),
1169 .layerLifecycleManager = mLifecycleManager,
1170 .includeMetadata = false,
1171 .displays = mFrontEndDisplayInfos,
1172 .displayChanges = false,
1173 .globalShadowSettings = globalShadowSettings,
1174 .supportsBlur = true,
1175 .supportedLayerGenericMetadata = {},
1176 .genericLayerMetadataKeyMap = {},
1177 .skipRoundCornersWhenProtected = true};
1178 update(mSnapshotBuilder, args);
1179 EXPECT_FALSE(getSnapshot({.id = 1})->roundedCorner.hasRoundedCorners());
1180 // layer 2 doesn't have a buffer and should be unaffected
1181 EXPECT_TRUE(getSnapshot({.id = 2})->roundedCorner.hasRoundedCorners());
1182
1183 // remove protected bit, check rounded corners are set
1184 setBuffer(1,
1185 std::make_shared<renderengine::mock::FakeExternalTexture>(1U /*width*/, 1U /*height*/,
1186 2ULL /* bufferId */,
1187 HAL_PIXEL_FORMAT_RGBA_8888,
1188 0 /*usage*/));
1189 update(mSnapshotBuilder, args);
1190 EXPECT_TRUE(getSnapshot({.id = 1})->roundedCorner.hasRoundedCorners());
1191 EXPECT_EQ(getSnapshot({.id = 1})->roundedCorner.radius.x, 42.f);
1192}
1193
Vishnu Nairbd51f952023-08-31 22:50:14 -07001194TEST_F(LayerSnapshotTest, setRefreshRateIndicatorCompositionType) {
1195 setFlags(1, layer_state_t::eLayerIsRefreshRateIndicator,
1196 layer_state_t::eLayerIsRefreshRateIndicator);
1197 setBuffer(1,
1198 std::make_shared<renderengine::mock::FakeExternalTexture>(1U /*width*/, 1U /*height*/,
1199 42ULL /* bufferId */,
1200 HAL_PIXEL_FORMAT_RGBA_8888,
1201 0 /*usage*/));
1202 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1203 EXPECT_EQ(getSnapshot({.id = 1})->compositionType,
1204 aidl::android::hardware::graphics::composer3::Composition::REFRESH_RATE_INDICATOR);
1205}
1206
Chavi Weingarten07597342023-09-14 21:10:59 +00001207TEST_F(LayerSnapshotTest, setBufferCrop) {
1208 // validate no buffer but has crop
1209 Rect crop = Rect(0, 0, 50, 50);
1210 setBufferCrop(1, crop);
1211 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1212 EXPECT_EQ(getSnapshot(1)->geomContentCrop, crop);
1213
1214 setBuffer(1,
1215 std::make_shared<renderengine::mock::FakeExternalTexture>(100U /*width*/,
1216 100U /*height*/,
1217 42ULL /* bufferId */,
1218 HAL_PIXEL_FORMAT_RGBA_8888,
1219 0 /*usage*/));
1220 // validate a buffer crop within the buffer bounds
1221 setBufferCrop(1, crop);
1222 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1223 EXPECT_EQ(getSnapshot(1)->geomContentCrop, crop);
1224
1225 // validate a buffer crop outside the buffer bounds
1226 crop = Rect(0, 0, 150, 150);
1227 setBufferCrop(1, crop);
1228 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1229 EXPECT_EQ(getSnapshot(1)->geomContentCrop, Rect(0, 0, 100, 100));
1230
1231 // validate no buffer crop
1232 setBufferCrop(1, Rect());
1233 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1234 EXPECT_EQ(getSnapshot(1)->geomContentCrop, Rect(0, 0, 100, 100));
1235}
Vishnu Nairbefd3e22023-10-05 17:48:31 +00001236
1237TEST_F(LayerSnapshotTest, setShadowRadius) {
1238 static constexpr float SHADOW_RADIUS = 123.f;
1239 setShadowRadius(1, SHADOW_RADIUS);
1240 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1241 EXPECT_EQ(getSnapshot(1)->shadowSettings.length, SHADOW_RADIUS);
Vishnu Nairbefd3e22023-10-05 17:48:31 +00001242}
1243
Chavi Weingartenb74093a2023-10-11 20:29:59 +00001244TEST_F(LayerSnapshotTest, setTrustedOverlayForNonVisibleInput) {
1245 hideLayer(1);
1246 setTrustedOverlay(1, true);
1247 Region touch{Rect{0, 0, 1000, 1000}};
1248 setTouchableRegion(1, touch);
1249
1250 UPDATE_AND_VERIFY(mSnapshotBuilder, {2});
1251 EXPECT_TRUE(getSnapshot(1)->inputInfo.inputConfig.test(
1252 gui::WindowInfo::InputConfig::TRUSTED_OVERLAY));
1253}
1254
Alec Mouri89f5d4e2023-10-20 17:12:49 +00001255TEST_F(LayerSnapshotTest, isFrontBuffered) {
1256 setBuffer(1,
1257 std::make_shared<renderengine::mock::FakeExternalTexture>(
1258 1U /*width*/, 1U /*height*/, 1ULL /* bufferId */, HAL_PIXEL_FORMAT_RGBA_8888,
1259 GRALLOC_USAGE_HW_TEXTURE | AHARDWAREBUFFER_USAGE_FRONT_BUFFER /*usage*/));
1260
1261 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1262 EXPECT_TRUE(getSnapshot(1)->isFrontBuffered());
1263
1264 setBuffer(1,
1265 std::make_shared<
1266 renderengine::mock::FakeExternalTexture>(1U /*width*/, 1U /*height*/,
1267 1ULL /* bufferId */,
1268 HAL_PIXEL_FORMAT_RGBA_8888,
1269 GRALLOC_USAGE_HW_TEXTURE /*usage*/));
1270
1271 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1272 EXPECT_FALSE(getSnapshot(1)->isFrontBuffered());
1273}
1274
Chavi Weingarten4aa22af2023-11-17 19:37:07 +00001275TEST_F(LayerSnapshotTest, setSecureRootSnapshot) {
1276 setFlags(1, layer_state_t::eLayerSecure, layer_state_t::eLayerSecure);
1277 LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(),
1278 .layerLifecycleManager = mLifecycleManager,
1279 .includeMetadata = false,
1280 .displays = mFrontEndDisplayInfos,
1281 .displayChanges = false,
1282 .globalShadowSettings = globalShadowSettings,
1283 .supportsBlur = true,
1284 .supportedLayerGenericMetadata = {},
1285 .genericLayerMetadataKeyMap = {}};
1286 args.rootSnapshot.isSecure = true;
1287 update(mSnapshotBuilder, args);
1288
1289 EXPECT_TRUE(getSnapshot(1)->isSecure);
1290 // Ensure child is also marked as secure
1291 EXPECT_TRUE(getSnapshot(11)->isSecure);
1292}
1293
Prabir Pradhancf359192024-03-20 00:42:57 +00001294TEST_F(LayerSnapshotTest, setSensitiveForTracingConfigForSecureLayers) {
1295 setFlags(11, layer_state_t::eLayerSecure, layer_state_t::eLayerSecure);
1296
1297 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1298
1299 EXPECT_TRUE(getSnapshot(11)->inputInfo.inputConfig.test(
Arpit Singh490ccc92024-04-30 14:26:21 +00001300 gui::WindowInfo::InputConfig::SENSITIVE_FOR_PRIVACY));
Prabir Pradhancf359192024-03-20 00:42:57 +00001301 EXPECT_TRUE(getSnapshot(111)->inputInfo.inputConfig.test(
Arpit Singh490ccc92024-04-30 14:26:21 +00001302 gui::WindowInfo::InputConfig::SENSITIVE_FOR_PRIVACY));
Prabir Pradhancf359192024-03-20 00:42:57 +00001303 EXPECT_FALSE(getSnapshot(1)->inputInfo.inputConfig.test(
Arpit Singh490ccc92024-04-30 14:26:21 +00001304 gui::WindowInfo::InputConfig::SENSITIVE_FOR_PRIVACY));
Prabir Pradhancf359192024-03-20 00:42:57 +00001305 EXPECT_FALSE(getSnapshot(12)->inputInfo.inputConfig.test(
Arpit Singh490ccc92024-04-30 14:26:21 +00001306 gui::WindowInfo::InputConfig::SENSITIVE_FOR_PRIVACY));
Prabir Pradhancf359192024-03-20 00:42:57 +00001307 EXPECT_FALSE(getSnapshot(2)->inputInfo.inputConfig.test(
Arpit Singh490ccc92024-04-30 14:26:21 +00001308 gui::WindowInfo::InputConfig::SENSITIVE_FOR_PRIVACY));
Prabir Pradhancf359192024-03-20 00:42:57 +00001309}
1310
1311TEST_F(LayerSnapshotTest, setSensitiveForTracingFromInputWindowHandle) {
1312 setInputInfo(11, [](auto& inputInfo) {
Arpit Singh490ccc92024-04-30 14:26:21 +00001313 inputInfo.inputConfig |= gui::WindowInfo::InputConfig::SENSITIVE_FOR_PRIVACY;
Prabir Pradhancf359192024-03-20 00:42:57 +00001314 });
1315
1316 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1317
1318 EXPECT_TRUE(getSnapshot(11)->inputInfo.inputConfig.test(
Arpit Singh490ccc92024-04-30 14:26:21 +00001319 gui::WindowInfo::InputConfig::SENSITIVE_FOR_PRIVACY));
Prabir Pradhancf359192024-03-20 00:42:57 +00001320 EXPECT_TRUE(getSnapshot(111)->inputInfo.inputConfig.test(
Arpit Singh490ccc92024-04-30 14:26:21 +00001321 gui::WindowInfo::InputConfig::SENSITIVE_FOR_PRIVACY));
Prabir Pradhancf359192024-03-20 00:42:57 +00001322 EXPECT_FALSE(getSnapshot(1)->inputInfo.inputConfig.test(
Arpit Singh490ccc92024-04-30 14:26:21 +00001323 gui::WindowInfo::InputConfig::SENSITIVE_FOR_PRIVACY));
Prabir Pradhancf359192024-03-20 00:42:57 +00001324 EXPECT_FALSE(getSnapshot(12)->inputInfo.inputConfig.test(
Arpit Singh490ccc92024-04-30 14:26:21 +00001325 gui::WindowInfo::InputConfig::SENSITIVE_FOR_PRIVACY));
Prabir Pradhancf359192024-03-20 00:42:57 +00001326 EXPECT_FALSE(getSnapshot(2)->inputInfo.inputConfig.test(
Arpit Singh490ccc92024-04-30 14:26:21 +00001327 gui::WindowInfo::InputConfig::SENSITIVE_FOR_PRIVACY));
Prabir Pradhancf359192024-03-20 00:42:57 +00001328}
1329
Vishnu Nairf13c8982023-12-02 11:26:09 -08001330// b/314350323
1331TEST_F(LayerSnapshotTest, propagateDropInputMode) {
1332 setDropInputMode(1, gui::DropInputMode::ALL);
1333 LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(),
1334 .layerLifecycleManager = mLifecycleManager,
1335 .includeMetadata = false,
1336 .displays = mFrontEndDisplayInfos,
1337 .displayChanges = false,
1338 .globalShadowSettings = globalShadowSettings,
1339 .supportsBlur = true,
1340 .supportedLayerGenericMetadata = {},
1341 .genericLayerMetadataKeyMap = {}};
1342 args.rootSnapshot.isSecure = true;
1343 update(mSnapshotBuilder, args);
1344
1345 EXPECT_EQ(getSnapshot(1)->dropInputMode, gui::DropInputMode::ALL);
1346 // Ensure child also has the correct drop input mode regardless of whether either layer has
1347 // an input channel
1348 EXPECT_EQ(getSnapshot(11)->dropInputMode, gui::DropInputMode::ALL);
1349}
1350
Chavi Weingarten92c7d8c2024-01-19 23:25:45 +00001351TEST_F(LayerSnapshotTest, NonVisibleLayerWithInput) {
1352 LayerHierarchyTestBase::createRootLayer(3);
1353 setColor(3, {-1._hf, -1._hf, -1._hf});
1354 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1355
1356 std::vector<TransactionState> transactions;
1357 transactions.emplace_back();
1358 transactions.back().states.push_back({});
1359 transactions.back().states.front().state.what = layer_state_t::eInputInfoChanged;
1360 transactions.back().states.front().layerId = 3;
1361 transactions.back().states.front().state.windowInfoHandle = sp<gui::WindowInfoHandle>::make();
1362 auto inputInfo = transactions.back().states.front().state.windowInfoHandle->editInfo();
1363 inputInfo->token = sp<BBinder>::make();
1364 mLifecycleManager.applyTransactions(transactions);
1365
1366 update(mSnapshotBuilder);
1367
1368 bool foundInputLayer = false;
1369 mSnapshotBuilder.forEachInputSnapshot([&](const frontend::LayerSnapshot& snapshot) {
1370 if (snapshot.uniqueSequence == 3) {
1371 foundInputLayer = true;
1372 }
1373 });
1374 EXPECT_TRUE(foundInputLayer);
1375}
1376
Garfield Tan8eb8f352024-05-17 09:12:01 -07001377TEST_F(LayerSnapshotTest, ForEachSnapshotsWithPredicate) {
1378 std::vector<uint32_t> visitedUniqueSequences;
1379 mSnapshotBuilder.forEachSnapshot(
1380 [&](const std::unique_ptr<frontend::LayerSnapshot>& snapshot) {
1381 visitedUniqueSequences.push_back(snapshot->uniqueSequence);
1382 },
1383 [](const frontend::LayerSnapshot& snapshot) { return snapshot.uniqueSequence == 111; });
1384 EXPECT_EQ(visitedUniqueSequences.size(), 1u);
1385 EXPECT_EQ(visitedUniqueSequences[0], 111u);
1386}
1387
Vishnu Nair59a6be32024-01-29 10:26:21 -08001388TEST_F(LayerSnapshotTest, canOccludePresentation) {
1389 setFlags(12, layer_state_t::eCanOccludePresentation, layer_state_t::eCanOccludePresentation);
1390 LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(),
1391 .layerLifecycleManager = mLifecycleManager,
1392 .includeMetadata = false,
1393 .displays = mFrontEndDisplayInfos,
1394 .displayChanges = false,
1395 .globalShadowSettings = globalShadowSettings,
1396 .supportsBlur = true,
1397 .supportedLayerGenericMetadata = {},
1398 .genericLayerMetadataKeyMap = {}};
1399 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1400
1401 EXPECT_EQ(getSnapshot(1)->inputInfo.canOccludePresentation, false);
1402
1403 // ensure we can set the property on the window info for layer and all its children
1404 EXPECT_EQ(getSnapshot(12)->inputInfo.canOccludePresentation, true);
1405 EXPECT_EQ(getSnapshot(121)->inputInfo.canOccludePresentation, true);
1406 EXPECT_EQ(getSnapshot(1221)->inputInfo.canOccludePresentation, true);
1407}
1408
Vishnu Nair491827d2024-04-29 23:43:26 +00001409TEST_F(LayerSnapshotTest, mirroredHierarchyIgnoresLocalTransform) {
1410 SET_FLAG_FOR_TEST(flags::detached_mirror, true);
1411 reparentLayer(12, UNASSIGNED_LAYER_ID);
1412 setPosition(11, 2, 20);
1413 setPosition(111, 20, 200);
1414 mirrorLayer(/*layer*/ 14, /*parent*/ 1, /*layerToMirror*/ 11);
1415 std::vector<uint32_t> expected = {1, 11, 111, 13, 14, 11, 111, 2};
1416 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
1417
1418 // mirror root has no position set
1419 EXPECT_EQ(getSnapshot({.id = 11, .mirrorRootIds = 14u})->localTransform.tx(), 0);
1420 EXPECT_EQ(getSnapshot({.id = 11, .mirrorRootIds = 14u})->localTransform.ty(), 0);
1421 // original root still has a position
1422 EXPECT_EQ(getSnapshot({.id = 11})->localTransform.tx(), 2);
1423 EXPECT_EQ(getSnapshot({.id = 11})->localTransform.ty(), 20);
1424
1425 // mirror child still has the correct position
1426 EXPECT_EQ(getSnapshot({.id = 111, .mirrorRootIds = 14u})->localTransform.tx(), 20);
1427 EXPECT_EQ(getSnapshot({.id = 111, .mirrorRootIds = 14u})->localTransform.ty(), 200);
1428 EXPECT_EQ(getSnapshot({.id = 111, .mirrorRootIds = 14u})->geomLayerTransform.tx(), 20);
1429 EXPECT_EQ(getSnapshot({.id = 111, .mirrorRootIds = 14u})->geomLayerTransform.ty(), 200);
1430
1431 // original child still has the correct position including its parent's position
1432 EXPECT_EQ(getSnapshot({.id = 111})->localTransform.tx(), 20);
1433 EXPECT_EQ(getSnapshot({.id = 111})->localTransform.ty(), 200);
1434 EXPECT_EQ(getSnapshot({.id = 111})->geomLayerTransform.tx(), 22);
1435 EXPECT_EQ(getSnapshot({.id = 111})->geomLayerTransform.ty(), 220);
1436}
1437
Vishnu Nair8fc721b2022-12-22 20:06:32 +00001438} // namespace android::surfaceflinger::frontend