blob: 23b6851bed1809a4568c3f03bc21ff8e5847ee96 [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 Rahardi6431d4a2024-05-15 18:42:48 +0900283 EXPECT_EQ(mLifecycleManager.getGlobalChanges(),
284 RequestedLayerState::Changes::GameMode | RequestedLayerState::Changes::Metadata);
Vishnu Naircfb2d252023-01-19 04:44:02 +0000285 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
Vishnu Naira02943f2023-06-03 13:44:46 -0700286 EXPECT_EQ(getSnapshot(1)->clientChanges, layer_state_t::eMetadataChanged);
Vishnu Naircfb2d252023-01-19 04:44:02 +0000287 EXPECT_EQ(static_cast<int32_t>(getSnapshot(1)->gameMode), 42);
288 EXPECT_EQ(static_cast<int32_t>(getSnapshot(11)->gameMode), 42);
289}
290
Nergi Rahardi6431d4a2024-05-15 18:42:48 +0900291TEST_F(LayerSnapshotTest, UpdateMetadata) {
292 std::vector<TransactionState> transactions;
293 transactions.emplace_back();
294 transactions.back().states.push_back({});
295 transactions.back().states.front().state.what = layer_state_t::eMetadataChanged;
296 // This test focuses on metadata used by ARC++ to ensure LayerMetadata is updated correctly,
297 // and not using stale data.
298 transactions.back().states.front().state.metadata = LayerMetadata();
299 transactions.back().states.front().state.metadata.setInt32(METADATA_OWNER_UID, 123);
300 transactions.back().states.front().state.metadata.setInt32(METADATA_WINDOW_TYPE, 234);
301 transactions.back().states.front().state.metadata.setInt32(METADATA_TASK_ID, 345);
302 transactions.back().states.front().state.metadata.setInt32(METADATA_MOUSE_CURSOR, 456);
303 transactions.back().states.front().state.metadata.setInt32(METADATA_ACCESSIBILITY_ID, 567);
304 transactions.back().states.front().state.metadata.setInt32(METADATA_OWNER_PID, 678);
305 transactions.back().states.front().state.metadata.setInt32(METADATA_CALLING_UID, 789);
306
307 transactions.back().states.front().layerId = 1;
308 transactions.back().states.front().state.layerId = static_cast<int32_t>(1);
309
310 mLifecycleManager.applyTransactions(transactions);
311 EXPECT_EQ(mLifecycleManager.getGlobalChanges(), RequestedLayerState::Changes::Metadata);
312
313 // Setting includeMetadata=true to ensure metadata update is applied to LayerSnapshot
314 LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(),
315 .layerLifecycleManager = mLifecycleManager,
316 .includeMetadata = true,
317 .displays = mFrontEndDisplayInfos,
318 .globalShadowSettings = globalShadowSettings,
319 .supportsBlur = true,
320 .supportedLayerGenericMetadata = {},
321 .genericLayerMetadataKeyMap = {}};
322 update(mSnapshotBuilder, args);
323
324 EXPECT_EQ(getSnapshot(1)->clientChanges, layer_state_t::eMetadataChanged);
325 EXPECT_EQ(getSnapshot(1)->layerMetadata.getInt32(METADATA_OWNER_UID, -1), 123);
326 EXPECT_EQ(getSnapshot(1)->layerMetadata.getInt32(METADATA_WINDOW_TYPE, -1), 234);
327 EXPECT_EQ(getSnapshot(1)->layerMetadata.getInt32(METADATA_TASK_ID, -1), 345);
328 EXPECT_EQ(getSnapshot(1)->layerMetadata.getInt32(METADATA_MOUSE_CURSOR, -1), 456);
329 EXPECT_EQ(getSnapshot(1)->layerMetadata.getInt32(METADATA_ACCESSIBILITY_ID, -1), 567);
330 EXPECT_EQ(getSnapshot(1)->layerMetadata.getInt32(METADATA_OWNER_PID, -1), 678);
331 EXPECT_EQ(getSnapshot(1)->layerMetadata.getInt32(METADATA_CALLING_UID, -1), 789);
332}
333
Garfield Tan8eb8f352024-05-17 09:12:01 -0700334TEST_F(LayerSnapshotTest, UpdateMetadataOfHiddenLayers) {
335 hideLayer(1);
336
337 std::vector<TransactionState> transactions;
338 transactions.emplace_back();
339 transactions.back().states.push_back({});
340 transactions.back().states.front().state.what = layer_state_t::eMetadataChanged;
341 // This test focuses on metadata used by ARC++ to ensure LayerMetadata is updated correctly,
342 // and not using stale data.
343 transactions.back().states.front().state.metadata = LayerMetadata();
344 transactions.back().states.front().state.metadata.setInt32(METADATA_OWNER_UID, 123);
345 transactions.back().states.front().state.metadata.setInt32(METADATA_WINDOW_TYPE, 234);
346 transactions.back().states.front().state.metadata.setInt32(METADATA_TASK_ID, 345);
347 transactions.back().states.front().state.metadata.setInt32(METADATA_MOUSE_CURSOR, 456);
348 transactions.back().states.front().state.metadata.setInt32(METADATA_ACCESSIBILITY_ID, 567);
349 transactions.back().states.front().state.metadata.setInt32(METADATA_OWNER_PID, 678);
350 transactions.back().states.front().state.metadata.setInt32(METADATA_CALLING_UID, 789);
351
352 transactions.back().states.front().layerId = 1;
353 transactions.back().states.front().state.layerId = static_cast<int32_t>(1);
354
355 mLifecycleManager.applyTransactions(transactions);
356 EXPECT_EQ(mLifecycleManager.getGlobalChanges(),
357 RequestedLayerState::Changes::Metadata | RequestedLayerState::Changes::Visibility |
358 RequestedLayerState::Changes::VisibleRegion |
359 RequestedLayerState::Changes::AffectsChildren);
360
361 // Setting includeMetadata=true to ensure metadata update is applied to LayerSnapshot
362 LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(),
363 .layerLifecycleManager = mLifecycleManager,
364 .includeMetadata = true,
365 .displays = mFrontEndDisplayInfos,
366 .globalShadowSettings = globalShadowSettings,
367 .supportsBlur = true,
368 .supportedLayerGenericMetadata = {},
369 .genericLayerMetadataKeyMap = {}};
370 update(mSnapshotBuilder, args);
371
372 EXPECT_EQ(static_cast<int64_t>(getSnapshot(1)->clientChanges),
373 layer_state_t::eMetadataChanged | layer_state_t::eFlagsChanged);
374 EXPECT_EQ(getSnapshot(1)->layerMetadata.getInt32(METADATA_OWNER_UID, -1), 123);
375 EXPECT_EQ(getSnapshot(1)->layerMetadata.getInt32(METADATA_WINDOW_TYPE, -1), 234);
376 EXPECT_EQ(getSnapshot(1)->layerMetadata.getInt32(METADATA_TASK_ID, -1), 345);
377 EXPECT_EQ(getSnapshot(1)->layerMetadata.getInt32(METADATA_MOUSE_CURSOR, -1), 456);
378 EXPECT_EQ(getSnapshot(1)->layerMetadata.getInt32(METADATA_ACCESSIBILITY_ID, -1), 567);
379 EXPECT_EQ(getSnapshot(1)->layerMetadata.getInt32(METADATA_OWNER_PID, -1), 678);
380 EXPECT_EQ(getSnapshot(1)->layerMetadata.getInt32(METADATA_CALLING_UID, -1), 789);
381}
382
Vishnu Naircfb2d252023-01-19 04:44:02 +0000383TEST_F(LayerSnapshotTest, NoLayerVoteForParentWithChildVotes) {
384 // ROOT
385 // ├── 1
386 // │ ├── 11 (frame rate set)
387 // │ │ └── 111
388 // │ ├── 12
389 // │ │ ├── 121
390 // │ │ └── 122
391 // │ │ └── 1221
392 // │ └── 13
393 // └── 2
394
Vishnu Nair30515cb2023-10-19 21:54:08 -0700395 setFrameRate(11, 90.0, ANATIVEWINDOW_FRAME_RATE_EXACT, ANATIVEWINDOW_CHANGE_FRAME_RATE_ALWAYS);
Vishnu Naircfb2d252023-01-19 04:44:02 +0000396 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
397
Rachel Leece6e0042023-06-27 11:22:54 -0700398 EXPECT_EQ(getSnapshot(11)->frameRate.vote.rate.getIntValue(), 90);
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700399 EXPECT_EQ(getSnapshot(11)->frameRate.vote.type, scheduler::FrameRateCompatibility::Exact);
Rachel Leece6e0042023-06-27 11:22:54 -0700400 EXPECT_EQ(getSnapshot(111)->frameRate.vote.rate.getIntValue(), 90);
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700401 EXPECT_EQ(getSnapshot(111)->frameRate.vote.type, scheduler::FrameRateCompatibility::Exact);
Rachel Leece6e0042023-06-27 11:22:54 -0700402 EXPECT_EQ(getSnapshot(1)->frameRate.vote.rate.getIntValue(), 0);
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700403 EXPECT_EQ(getSnapshot(1)->frameRate.vote.type, scheduler::FrameRateCompatibility::NoVote);
Vishnu Naircfb2d252023-01-19 04:44:02 +0000404}
405
Vishnu Nair30515cb2023-10-19 21:54:08 -0700406TEST_F(LayerSnapshotTest, NoLayerVoteForParentWithChildVotesDoesNotAffectSiblings) {
407 // ROOT
408 // ├── 1 (verify layer has no vote)
409 // │ ├── 11 (frame rate set)
410 // │ │ └── 111
411 // │ ├── 12 (frame rate set)
412 // │ │ ├── 121
413 // │ │ └── 122
414 // │ │ └── 1221
415 // │ └── 13 (verify layer has default vote)
416 // └── 2
417
418 setFrameRate(11, 90.0, ANATIVEWINDOW_FRAME_RATE_EXACT, ANATIVEWINDOW_CHANGE_FRAME_RATE_ALWAYS);
419 setFrameRate(12, 45.0, ANATIVEWINDOW_FRAME_RATE_EXACT, ANATIVEWINDOW_CHANGE_FRAME_RATE_ALWAYS);
420
421 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
422
423 EXPECT_EQ(getSnapshot(11)->frameRate.vote.rate.getIntValue(), 90);
424 EXPECT_EQ(getSnapshot(11)->frameRate.vote.type, scheduler::FrameRateCompatibility::Exact);
425 EXPECT_EQ(getSnapshot(111)->frameRate.vote.rate.getIntValue(), 90);
426 EXPECT_EQ(getSnapshot(111)->frameRate.vote.type, scheduler::FrameRateCompatibility::Exact);
427 EXPECT_EQ(getSnapshot(12)->frameRate.vote.rate.getIntValue(), 45);
428 EXPECT_EQ(getSnapshot(12)->frameRate.vote.type, scheduler::FrameRateCompatibility::Exact);
429 EXPECT_EQ(getSnapshot(121)->frameRate.vote.rate.getIntValue(), 45);
430 EXPECT_EQ(getSnapshot(121)->frameRate.vote.type, scheduler::FrameRateCompatibility::Exact);
431 EXPECT_EQ(getSnapshot(1221)->frameRate.vote.rate.getIntValue(), 45);
432 EXPECT_EQ(getSnapshot(1221)->frameRate.vote.type, scheduler::FrameRateCompatibility::Exact);
433
434 EXPECT_EQ(getSnapshot(1)->frameRate.vote.rate.getIntValue(), 0);
435 EXPECT_EQ(getSnapshot(1)->frameRate.vote.type, scheduler::FrameRateCompatibility::NoVote);
436 EXPECT_EQ(getSnapshot(13)->frameRate.vote.rate.getIntValue(), 0);
437 EXPECT_EQ(getSnapshot(13)->frameRate.vote.type, scheduler::FrameRateCompatibility::Default);
438 EXPECT_EQ(getSnapshot(2)->frameRate.vote.rate.getIntValue(), 0);
439 EXPECT_EQ(getSnapshot(2)->frameRate.vote.type, scheduler::FrameRateCompatibility::Default);
440}
441
Vishnu Naira02943f2023-06-03 13:44:46 -0700442TEST_F(LayerSnapshotTest, CanCropTouchableRegion) {
Vishnu Nair29354ec2023-03-28 18:51:28 -0700443 // ROOT
444 // ├── 1
445 // │ ├── 11
446 // │ │ └── 111 (touchregion set to touch but cropped by layer 13)
447 // │ ├── 12
448 // │ │ ├── 121
449 // │ │ └── 122
450 // │ │ └── 1221
451 // │ └── 13 (crop set to touchCrop)
452 // └── 2
453
454 Rect touchCrop{300, 300, 400, 500};
455 setCrop(13, touchCrop);
456 Region touch{Rect{0, 0, 1000, 1000}};
457 setTouchableRegionCrop(111, touch, /*touchCropId=*/13, /*replaceTouchableRegionWithCrop=*/true);
458 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
459 EXPECT_EQ(getSnapshot({.id = 111})->inputInfo.touchableRegion.bounds(), touchCrop);
460
461 Rect modifiedTouchCrop{100, 300, 400, 700};
462 setCrop(13, modifiedTouchCrop);
463 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
464 EXPECT_EQ(getSnapshot({.id = 111})->inputInfo.touchableRegion.bounds(), modifiedTouchCrop);
465}
466
Chavi Weingarten1ba381e2024-01-09 21:54:11 +0000467TEST_F(LayerSnapshotTest, CanCropTouchableRegionWithDisplayTransform) {
468 DisplayInfo displayInfo;
469 displayInfo.transform = ui::Transform(ui::Transform::RotationFlags::ROT_90, 1000, 1000);
470 mFrontEndDisplayInfos.emplace_or_replace(ui::LayerStack::fromValue(1), displayInfo);
471
472 Rect touchCrop{300, 300, 400, 500};
473 createRootLayer(3);
474 setCrop(3, touchCrop);
475 setLayerStack(3, 1);
476 Region touch{Rect{0, 0, 1000, 1000}};
477 setTouchableRegionCrop(3, touch, /*touchCropId=*/3, /*replaceTouchableRegionWithCrop=*/false);
478
479 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 11, 111, 12, 121, 122, 1221, 13, 2, 3});
480 Rect rotatedCrop = {500, 300, 700, 400};
481 EXPECT_EQ(getSnapshot({.id = 3})->inputInfo.touchableRegion.bounds(), rotatedCrop);
482}
483
Vishnu Nair444f3952023-04-11 13:01:02 -0700484TEST_F(LayerSnapshotTest, blurUpdatesWhenAlphaChanges) {
Vishnu Nair854ce1c2023-08-19 15:00:13 -0700485 int blurRadius = 42;
486 setBackgroundBlurRadius(1221, static_cast<uint32_t>(blurRadius));
Vishnu Nair444f3952023-04-11 13:01:02 -0700487
488 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
489 EXPECT_EQ(getSnapshot({.id = 1221})->backgroundBlurRadius, blurRadius);
490
Vishnu Nair854ce1c2023-08-19 15:00:13 -0700491 blurRadius = 21;
492 setBackgroundBlurRadius(1221, static_cast<uint32_t>(blurRadius));
493 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
494 EXPECT_EQ(getSnapshot({.id = 1221})->backgroundBlurRadius, blurRadius);
495
Vishnu Nair444f3952023-04-11 13:01:02 -0700496 static constexpr float alpha = 0.5;
497 setAlpha(12, alpha);
498 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
Vishnu Nair854ce1c2023-08-19 15:00:13 -0700499 EXPECT_EQ(getSnapshot({.id = 1221})->backgroundBlurRadius,
500 static_cast<int>(static_cast<float>(blurRadius) * alpha));
Vishnu Nair444f3952023-04-11 13:01:02 -0700501}
502
Vishnu Naira9c43762023-01-27 19:10:25 +0000503// Display Mirroring Tests
504// tree with 3 levels of children
505// ROOT (DISPLAY 0)
506// ├── 1
507// │ ├── 11
508// │ │ └── 111
509// │ ├── 12 (has skip screenshot flag)
510// │ │ ├── 121
511// │ │ └── 122
512// │ │ └── 1221
513// │ └── 13
514// └── 2
515// ROOT (DISPLAY 1)
516// └── 3 (mirrors display 0)
Vishnu Nair92990e22023-02-24 20:01:05 +0000517TEST_F(LayerSnapshotTest, displayMirrorRespectsLayerSkipScreenshotFlag) {
Vishnu Naira9c43762023-01-27 19:10:25 +0000518 setFlags(12, layer_state_t::eLayerSkipScreenshot, layer_state_t::eLayerSkipScreenshot);
519 createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0));
520 setLayerStack(3, 1);
521
Vishnu Nair444f3952023-04-11 13:01:02 -0700522 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 +0000523 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
524}
525
Vishnu Nair92990e22023-02-24 20:01:05 +0000526// ROOT (DISPLAY 0)
527// ├── 1
528// │ ├── 11
529// │ │ └── 111
530// │ └── 13
531// └── 2
532// ROOT (DISPLAY 3)
533// └── 3 (mirrors display 0)
534TEST_F(LayerSnapshotTest, mirrorLayerGetsCorrectLayerStack) {
535 reparentLayer(12, UNASSIGNED_LAYER_ID);
536 createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0));
537 setLayerStack(3, 3);
538 createDisplayMirrorLayer(4, ui::LayerStack::fromValue(0));
539 setLayerStack(4, 4);
540
Vishnu Nair444f3952023-04-11 13:01:02 -0700541 std::vector<uint32_t> expected = {1, 11, 111, 13, 2, 3, 1, 11, 111,
542 13, 2, 4, 1, 11, 111, 13, 2};
Vishnu Nair92990e22023-02-24 20:01:05 +0000543 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
Vishnu Nair6f878312023-09-08 11:05:01 -0700544 EXPECT_EQ(getSnapshot({.id = 111, .mirrorRootIds = 3u})->outputFilter.layerStack.id, 3u);
545 EXPECT_EQ(getSnapshot({.id = 111, .mirrorRootIds = 4u})->outputFilter.layerStack.id, 4u);
Vishnu Nair92990e22023-02-24 20:01:05 +0000546}
547
548// ROOT (DISPLAY 0)
549// ├── 1 (crop 50x50)
550// │ ├── 11
551// │ │ └── 111
552// │ └── 13
553// └── 2
554// ROOT (DISPLAY 3)
555// └── 3 (mirrors display 0) (crop 100x100)
556TEST_F(LayerSnapshotTest, mirrorLayerTouchIsCroppedByMirrorRoot) {
557 reparentLayer(12, UNASSIGNED_LAYER_ID);
558 createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0));
559 setLayerStack(3, 3);
560 setCrop(1, Rect{50, 50});
561 setCrop(3, Rect{100, 100});
562 setCrop(111, Rect{200, 200});
563 Region touch{Rect{0, 0, 1000, 1000}};
564 setTouchableRegion(111, touch);
Vishnu Nair444f3952023-04-11 13:01:02 -0700565 std::vector<uint32_t> expected = {1, 11, 111, 13, 2, 3, 1, 11, 111, 13, 2};
Vishnu Nair92990e22023-02-24 20:01:05 +0000566 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
567 EXPECT_TRUE(getSnapshot({.id = 111})->inputInfo.touchableRegion.hasSameRects(touch));
568 Region touchCroppedByMirrorRoot{Rect{0, 0, 50, 50}};
Vishnu Nair6f878312023-09-08 11:05:01 -0700569 EXPECT_TRUE(getSnapshot({.id = 111, .mirrorRootIds = 3u})
Vishnu Nair92990e22023-02-24 20:01:05 +0000570 ->inputInfo.touchableRegion.hasSameRects(touchCroppedByMirrorRoot));
571}
572
573TEST_F(LayerSnapshotTest, canRemoveDisplayMirror) {
574 setFlags(12, layer_state_t::eLayerSkipScreenshot, layer_state_t::eLayerSkipScreenshot);
575 createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0));
576 setLayerStack(3, 1);
Vishnu Nair444f3952023-04-11 13:01:02 -0700577 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 +0000578 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
579 destroyLayerHandle(3);
580 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
581}
582
Vishnu Nairfccd6362023-02-24 23:39:53 +0000583TEST_F(LayerSnapshotTest, cleanUpUnreachableSnapshotsAfterMirroring) {
584 size_t startingNumSnapshots = mSnapshotBuilder.getSnapshots().size();
585 createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0));
586 setLayerStack(3, 1);
Vishnu Nair444f3952023-04-11 13:01:02 -0700587 std::vector<uint32_t> expected = {1, 11, 111, 12, 121, 122, 1221, 13, 2, 3,
588 1, 11, 111, 12, 121, 122, 1221, 13, 2};
Vishnu Nairfccd6362023-02-24 23:39:53 +0000589 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
590 destroyLayerHandle(3);
591 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
592
593 EXPECT_EQ(startingNumSnapshots, mSnapshotBuilder.getSnapshots().size());
594}
595
Vishnu Nair6f878312023-09-08 11:05:01 -0700596TEST_F(LayerSnapshotTest, canMirrorDisplayWithMirrors) {
597 reparentLayer(12, UNASSIGNED_LAYER_ID);
598 mirrorLayer(/*layer*/ 14, /*parent*/ 1, /*layerToMirror*/ 11);
599 std::vector<uint32_t> expected = {1, 11, 111, 13, 14, 11, 111, 2};
600 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
601
602 createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0));
603 setLayerStack(3, 3);
604 expected = {1, 11, 111, 13, 14, 11, 111, 2, 3, 1, 11, 111, 13, 14, 11, 111, 2};
605 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
606 EXPECT_EQ(getSnapshot({.id = 11, .mirrorRootIds = 14u})->outputFilter.layerStack.id, 0u);
607 EXPECT_EQ(getSnapshot({.id = 11, .mirrorRootIds = 3u})->outputFilter.layerStack.id, 3u);
608 EXPECT_EQ(getSnapshot({.id = 11, .mirrorRootIds = 3u, 14u})->outputFilter.layerStack.id, 3u);
609}
610
Vishnu Nairfccd6362023-02-24 23:39:53 +0000611// Rel z doesn't create duplicate snapshots but this is for completeness
612TEST_F(LayerSnapshotTest, cleanUpUnreachableSnapshotsAfterRelZ) {
613 size_t startingNumSnapshots = mSnapshotBuilder.getSnapshots().size();
614 reparentRelativeLayer(13, 11);
615 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 11, 13, 111, 12, 121, 122, 1221, 2});
616 setZ(13, 0);
617 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
618
619 EXPECT_EQ(startingNumSnapshots, mSnapshotBuilder.getSnapshots().size());
620}
621
622TEST_F(LayerSnapshotTest, cleanUpUnreachableSnapshotsAfterLayerDestruction) {
623 size_t startingNumSnapshots = mSnapshotBuilder.getSnapshots().size();
624 destroyLayerHandle(2);
625 destroyLayerHandle(122);
626
627 std::vector<uint32_t> expected = {1, 11, 111, 12, 121, 122, 1221, 13};
628 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
629
630 EXPECT_LE(startingNumSnapshots - 2, mSnapshotBuilder.getSnapshots().size());
631}
632
Vishnu Nair3d8565a2023-06-30 07:23:24 +0000633TEST_F(LayerSnapshotTest, snashotContainsMetadataFromLayerCreationArgs) {
634 LayerCreationArgs args(std::make_optional<uint32_t>(200));
635 args.name = "testlayer";
636 args.addToRoot = true;
637 args.metadata.setInt32(42, 24);
638
639 std::vector<std::unique_ptr<RequestedLayerState>> layers;
640 layers.emplace_back(std::make_unique<RequestedLayerState>(args));
641 EXPECT_TRUE(layers.back()->metadata.has(42));
642 EXPECT_EQ(layers.back()->metadata.getInt32(42, 0), 24);
643 mLifecycleManager.addLayers(std::move(layers));
644
645 std::vector<uint32_t> expected = STARTING_ZORDER;
646 expected.push_back(200);
647 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
648
649 EXPECT_TRUE(mSnapshotBuilder.getSnapshot(200)->layerMetadata.has(42));
650 EXPECT_EQ(mSnapshotBuilder.getSnapshot(200)->layerMetadata.getInt32(42, 0), 24);
651}
652
653TEST_F(LayerSnapshotTest, frameRateSelectionPriorityPassedToChildLayers) {
654 setFrameRateSelectionPriority(11, 1);
655
656 setFrameRateSelectionPriority(12, 2);
657
658 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
659 EXPECT_EQ(getSnapshot({.id = 1})->frameRateSelectionPriority, Layer::PRIORITY_UNSET);
660 EXPECT_EQ(getSnapshot({.id = 11})->frameRateSelectionPriority, 1);
661 EXPECT_EQ(getSnapshot({.id = 12})->frameRateSelectionPriority, 2);
662 EXPECT_EQ(getSnapshot({.id = 122})->frameRateSelectionPriority, 2);
663 EXPECT_EQ(getSnapshot({.id = 1221})->frameRateSelectionPriority, 2);
664
665 // reparent and verify the child gets the new parent's framerate selection priority
666 reparentLayer(122, 11);
667
668 std::vector<uint32_t> expected = {1, 11, 111, 122, 1221, 12, 121, 13, 2};
669 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
670 EXPECT_EQ(getSnapshot({.id = 1})->frameRateSelectionPriority, Layer::PRIORITY_UNSET);
671 EXPECT_EQ(getSnapshot({.id = 11})->frameRateSelectionPriority, 1);
672 EXPECT_EQ(getSnapshot({.id = 12})->frameRateSelectionPriority, 2);
673 EXPECT_EQ(getSnapshot({.id = 122})->frameRateSelectionPriority, 1);
674 EXPECT_EQ(getSnapshot({.id = 1221})->frameRateSelectionPriority, 1);
675}
676
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000677TEST_F(LayerSnapshotTest, framerate) {
678 setFrameRate(11, 244.f, 0, 0);
679
680 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
681 // verify parent is gets no vote
Rachel Leece6e0042023-06-27 11:22:54 -0700682 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
683 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700684 scheduler::FrameRateCompatibility::NoVote);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000685 EXPECT_TRUE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate));
686
687 // verify layer and children get the requested votes
Rachel Leece6e0042023-06-27 11:22:54 -0700688 EXPECT_TRUE(getSnapshot({.id = 11})->frameRate.vote.rate.isValid());
689 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 244.f);
690 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700691 scheduler::FrameRateCompatibility::Default);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000692 EXPECT_TRUE(getSnapshot({.id = 11})->changes.test(RequestedLayerState::Changes::FrameRate));
693
Rachel Leece6e0042023-06-27 11:22:54 -0700694 EXPECT_TRUE(getSnapshot({.id = 111})->frameRate.vote.rate.isValid());
695 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.rate.getValue(), 244.f);
696 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700697 scheduler::FrameRateCompatibility::Default);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000698 EXPECT_TRUE(getSnapshot({.id = 111})->changes.test(RequestedLayerState::Changes::FrameRate));
699
700 // reparent and verify the child gets the new parent's framerate
701 reparentLayer(122, 11);
702
703 std::vector<uint32_t> expected = {1, 11, 111, 122, 1221, 12, 121, 13, 2};
704 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
705 // verify parent is gets no vote
Rachel Leece6e0042023-06-27 11:22:54 -0700706 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
707 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700708 scheduler::FrameRateCompatibility::NoVote);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000709
710 // verify layer and children get the requested votes
Rachel Leece6e0042023-06-27 11:22:54 -0700711 EXPECT_TRUE(getSnapshot({.id = 11})->frameRate.vote.rate.isValid());
712 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 244.f);
713 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700714 scheduler::FrameRateCompatibility::Default);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000715
Rachel Leece6e0042023-06-27 11:22:54 -0700716 EXPECT_TRUE(getSnapshot({.id = 111})->frameRate.vote.rate.isValid());
717 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.rate.getValue(), 244.f);
718 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700719 scheduler::FrameRateCompatibility::Default);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000720
Rachel Leece6e0042023-06-27 11:22:54 -0700721 EXPECT_TRUE(getSnapshot({.id = 122})->frameRate.vote.rate.isValid());
722 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.rate.getValue(), 244.f);
723 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700724 scheduler::FrameRateCompatibility::Default);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000725 EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate));
726
727 // reparent and verify the new parent gets no vote
728 reparentLayer(11, 2);
729 expected = {1, 12, 121, 13, 2, 11, 111, 122, 1221};
730 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
731
732 // verify old parent has invalid framerate (default)
Rachel Leece6e0042023-06-27 11:22:54 -0700733 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
734 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700735 scheduler::FrameRateCompatibility::Default);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000736 EXPECT_TRUE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate));
737
738 // verify new parent get no vote
Rachel Leece6e0042023-06-27 11:22:54 -0700739 EXPECT_FALSE(getSnapshot({.id = 2})->frameRate.vote.rate.isValid());
740 EXPECT_EQ(getSnapshot({.id = 2})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700741 scheduler::FrameRateCompatibility::NoVote);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000742 EXPECT_TRUE(getSnapshot({.id = 2})->changes.test(RequestedLayerState::Changes::FrameRate));
743
744 // verify layer and children get the requested votes (unchanged)
Rachel Leece6e0042023-06-27 11:22:54 -0700745 EXPECT_TRUE(getSnapshot({.id = 11})->frameRate.vote.rate.isValid());
746 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 244.f);
747 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700748 scheduler::FrameRateCompatibility::Default);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000749
Rachel Leece6e0042023-06-27 11:22:54 -0700750 EXPECT_TRUE(getSnapshot({.id = 111})->frameRate.vote.rate.isValid());
751 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.rate.getValue(), 244.f);
752 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700753 scheduler::FrameRateCompatibility::Default);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000754
Rachel Leece6e0042023-06-27 11:22:54 -0700755 EXPECT_TRUE(getSnapshot({.id = 122})->frameRate.vote.rate.isValid());
756 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.rate.getValue(), 244.f);
757 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700758 scheduler::FrameRateCompatibility::Default);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000759}
760
Vishnu Nair3996ee32023-08-14 04:32:31 +0000761TEST_F(LayerSnapshotTest, translateDataspace) {
762 setDataspace(1, ui::Dataspace::UNKNOWN);
763 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
764 EXPECT_EQ(getSnapshot({.id = 1})->dataspace, ui::Dataspace::V0_SRGB);
765}
766
Rachel Leece6e0042023-06-27 11:22:54 -0700767// This test is similar to "frameRate" test case but checks that the setFrameRateCategory API
768// interaction also works correctly with the setFrameRate API within SF frontend.
769TEST_F(LayerSnapshotTest, frameRateWithCategory) {
Rachel Lee45681982024-03-14 18:40:15 -0700770 SET_FLAG_FOR_TEST(flags::frame_rate_category_mrr, true);
771
Rachel Leece6e0042023-06-27 11:22:54 -0700772 // ROOT
773 // ├── 1
774 // │ ├── 11 (frame rate set to 244.f)
775 // │ │ └── 111
776 // │ ├── 12
777 // │ │ ├── 121
778 // │ │ └── 122 (frame rate category set to Normal)
779 // │ │ └── 1221
780 // │ └── 13
781 // └── 2
782 setFrameRate(11, 244.f, 0, 0);
Rachel Lee9580ff12023-12-26 17:33:41 -0800783 setFrameRateCategory(122, ANATIVEWINDOW_FRAME_RATE_CATEGORY_NORMAL);
Rachel Leece6e0042023-06-27 11:22:54 -0700784
785 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
786 // verify parent 1 gets no vote
787 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
788 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700789 scheduler::FrameRateCompatibility::NoVote);
Rachel Leece6e0042023-06-27 11:22:54 -0700790 EXPECT_TRUE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate));
791
792 // verify layer 11 and children 111 get the requested votes
793 EXPECT_TRUE(getSnapshot({.id = 11})->frameRate.vote.rate.isValid());
794 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 244.f);
795 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700796 scheduler::FrameRateCompatibility::Default);
Rachel Leece6e0042023-06-27 11:22:54 -0700797 EXPECT_TRUE(getSnapshot({.id = 11})->changes.test(RequestedLayerState::Changes::FrameRate));
798
799 EXPECT_TRUE(getSnapshot({.id = 111})->frameRate.vote.rate.isValid());
800 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.rate.getValue(), 244.f);
801 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700802 scheduler::FrameRateCompatibility::Default);
Rachel Leece6e0042023-06-27 11:22:54 -0700803 EXPECT_TRUE(getSnapshot({.id = 111})->changes.test(RequestedLayerState::Changes::FrameRate));
804
805 // verify parent 12 gets no vote
806 EXPECT_FALSE(getSnapshot({.id = 12})->frameRate.vote.rate.isValid());
807 EXPECT_EQ(getSnapshot({.id = 12})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700808 scheduler::FrameRateCompatibility::NoVote);
Rachel Leece6e0042023-06-27 11:22:54 -0700809 EXPECT_TRUE(getSnapshot({.id = 12})->changes.test(RequestedLayerState::Changes::FrameRate));
810
811 // verify layer 122 and children 1221 get the requested votes
812 EXPECT_FALSE(getSnapshot({.id = 122})->frameRate.vote.rate.isValid());
813 EXPECT_TRUE(getSnapshot({.id = 122})->frameRate.isValid());
814 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700815 scheduler::FrameRateCompatibility::Default);
Rachel Leece6e0042023-06-27 11:22:54 -0700816 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.category, FrameRateCategory::Normal);
817 EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate));
Rachel Lee43369b22023-09-05 18:40:40 -0700818 EXPECT_TRUE(
819 getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::AffectsChildren));
Rachel Leece6e0042023-06-27 11:22:54 -0700820
821 EXPECT_FALSE(getSnapshot({.id = 1221})->frameRate.vote.rate.isValid());
822 EXPECT_TRUE(getSnapshot({.id = 1221})->frameRate.isValid());
823 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700824 scheduler::FrameRateCompatibility::Default);
Rachel Leece6e0042023-06-27 11:22:54 -0700825 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.category, FrameRateCategory::Normal);
826 EXPECT_TRUE(getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::FrameRate));
Rachel Lee43369b22023-09-05 18:40:40 -0700827 EXPECT_TRUE(
828 getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::AffectsChildren));
Rachel Leece6e0042023-06-27 11:22:54 -0700829
830 // reparent and verify the child does NOT get the new parent's framerate because it already has
831 // the frame rate category specified.
832 // ROOT
833 // ├─1
834 // │ ├─11 (frame rate set to 244.f)
835 // │ │ ├─111
836 // │ │ └─122 (frame rate category set to Normal)
837 // │ │ └─1221
838 // │ ├─12
839 // │ │ └─121
840 // │ └─13
841 // └─2
842 reparentLayer(122, 11);
843
844 std::vector<uint32_t> expected = {1, 11, 111, 122, 1221, 12, 121, 13, 2};
845 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
846 // verify parent is gets no vote
847 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
848 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700849 scheduler::FrameRateCompatibility::NoVote);
Rachel Leece6e0042023-06-27 11:22:54 -0700850
851 // verify layer 11 and children 111 get the requested votes
852 EXPECT_TRUE(getSnapshot({.id = 11})->frameRate.vote.rate.isValid());
853 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 244.f);
854 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700855 scheduler::FrameRateCompatibility::Default);
Rachel Leece6e0042023-06-27 11:22:54 -0700856
857 EXPECT_TRUE(getSnapshot({.id = 111})->frameRate.vote.rate.isValid());
858 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.rate.getValue(), 244.f);
859 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700860 scheduler::FrameRateCompatibility::Default);
Rachel Leece6e0042023-06-27 11:22:54 -0700861
862 // verify layer 122 and children 1221 get the requested category vote (unchanged from
863 // reparenting)
864 EXPECT_FALSE(getSnapshot({.id = 122})->frameRate.vote.rate.isValid());
865 EXPECT_TRUE(getSnapshot({.id = 122})->frameRate.isValid());
866 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700867 scheduler::FrameRateCompatibility::Default);
Rachel Leece6e0042023-06-27 11:22:54 -0700868 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.category, FrameRateCategory::Normal);
869 EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate));
870
871 EXPECT_FALSE(getSnapshot({.id = 1221})->frameRate.vote.rate.isValid());
872 EXPECT_TRUE(getSnapshot({.id = 1221})->frameRate.isValid());
873 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700874 scheduler::FrameRateCompatibility::Default);
Rachel Leece6e0042023-06-27 11:22:54 -0700875 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.category, FrameRateCategory::Normal);
876 EXPECT_TRUE(getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::FrameRate));
877}
878
Rachel Lee58cc90d2023-09-05 18:50:20 -0700879TEST_F(LayerSnapshotTest, frameRateSelectionStrategy) {
880 // ROOT
881 // ├── 1
882 // │ ├── 11
883 // │ │ └── 111
884 // │ ├── 12 (frame rate set to 244.f with strategy OverrideChildren)
885 // │ │ ├── 121
886 // │ │ └── 122 (frame rate set to 123.f but should be overridden by layer 12)
887 // │ │ └── 1221
888 // │ └── 13
889 // └── 2
890 setFrameRate(12, 244.f, 0, 0);
891 setFrameRate(122, 123.f, 0, 0);
892 setFrameRateSelectionStrategy(12, 1 /* OverrideChildren */);
893
894 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
895 // verify parent 1 gets no vote
896 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
897 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700898 scheduler::FrameRateCompatibility::NoVote);
Rachel Lee58cc90d2023-09-05 18:50:20 -0700899 EXPECT_TRUE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate));
900
901 // verify layer 12 and all descendants (121, 122, 1221) get the requested vote
902 EXPECT_EQ(getSnapshot({.id = 12})->frameRate.vote.rate.getValue(), 244.f);
903 EXPECT_EQ(getSnapshot({.id = 12})->frameRateSelectionStrategy,
904 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
905 EXPECT_TRUE(getSnapshot({.id = 12})->changes.test(RequestedLayerState::Changes::FrameRate));
906
907 EXPECT_EQ(getSnapshot({.id = 121})->frameRate.vote.rate.getValue(), 244.f);
908 EXPECT_EQ(getSnapshot({.id = 121})->frameRateSelectionStrategy,
909 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
910 EXPECT_TRUE(getSnapshot({.id = 121})->changes.test(RequestedLayerState::Changes::FrameRate));
911
912 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.rate.getValue(), 244.f);
913 EXPECT_EQ(getSnapshot({.id = 122})->frameRateSelectionStrategy,
914 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
915 EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate));
916
917 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.vote.rate.getValue(), 244.f);
918 EXPECT_EQ(getSnapshot({.id = 1221})->frameRateSelectionStrategy,
919 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
920 EXPECT_TRUE(getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::FrameRate));
Vishnu Nair41376b62023-11-08 05:08:58 -0800921
922 // ROOT
923 // ├── 1
924 // │ ├── 11
925 // │ │ └── 111
926 // │ ├── 12 (frame rate set to default with strategy default)
927 // │ │ ├── 121
928 // │ │ └── 122 (frame rate set to 123.f)
929 // │ │ └── 1221
930 // │ └── 13
931 // └── 2
932 setFrameRate(12, -1.f, 0, 0);
933 setFrameRateSelectionStrategy(12, 0 /* Default */);
934 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
935 // verify parent 1 gets no vote
936 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
937 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
938 scheduler::FrameRateCompatibility::NoVote);
939 EXPECT_FALSE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate));
940
941 // verify layer 12 and all descendants (121, 122, 1221) get the requested vote
942 EXPECT_FALSE(getSnapshot({.id = 12})->frameRate.vote.rate.isValid());
943 EXPECT_EQ(getSnapshot({.id = 12})->frameRate.vote.type,
944 scheduler::FrameRateCompatibility::NoVote);
945 EXPECT_EQ(getSnapshot({.id = 12})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -0800946 scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate);
Vishnu Nair41376b62023-11-08 05:08:58 -0800947 EXPECT_TRUE(getSnapshot({.id = 12})->changes.test(RequestedLayerState::Changes::FrameRate));
948
949 EXPECT_FALSE(getSnapshot({.id = 121})->frameRate.vote.rate.isValid());
950 EXPECT_EQ(getSnapshot({.id = 121})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -0800951 scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate);
Vishnu Nair41376b62023-11-08 05:08:58 -0800952 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_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate));
960
961 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.vote.rate.getValue(), 123.f);
962 EXPECT_EQ(getSnapshot({.id = 1221})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -0800963 scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate);
Vishnu Nair41376b62023-11-08 05:08:58 -0800964 EXPECT_TRUE(getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::FrameRate));
965}
966
967TEST_F(LayerSnapshotTest, frameRateSelectionStrategyWithCategory) {
Rachel Lee45681982024-03-14 18:40:15 -0700968 SET_FLAG_FOR_TEST(flags::frame_rate_category_mrr, true);
969
Vishnu Nair41376b62023-11-08 05:08:58 -0800970 // ROOT
971 // ├── 1
972 // │ ├── 11
973 // │ │ └── 111
974 // │ ├── 12 (frame rate category set to high with strategy OverrideChildren)
975 // │ │ ├── 121
976 // │ │ └── 122 (frame rate set to 123.f but should be overridden by layer 12)
977 // │ │ └── 1221
978 // │ └── 13
979 // └── 2
Rachel Lee9580ff12023-12-26 17:33:41 -0800980 setFrameRateCategory(12, ANATIVEWINDOW_FRAME_RATE_CATEGORY_HIGH);
Vishnu Nair41376b62023-11-08 05:08:58 -0800981 setFrameRate(122, 123.f, 0, 0);
982 setFrameRateSelectionStrategy(12, 1 /* OverrideChildren */);
983
984 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
985 // verify parent 1 gets no vote
986 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
987 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
988 scheduler::FrameRateCompatibility::NoVote);
989 EXPECT_TRUE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate));
990
991 // verify layer 12 and all descendants (121, 122, 1221) get the requested vote
992 EXPECT_EQ(getSnapshot({.id = 12})->frameRate.category, FrameRateCategory::High);
993 EXPECT_EQ(getSnapshot({.id = 12})->frameRateSelectionStrategy,
994 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
995 EXPECT_TRUE(getSnapshot({.id = 12})->changes.test(RequestedLayerState::Changes::FrameRate));
996
997 EXPECT_EQ(getSnapshot({.id = 121})->frameRate.category, FrameRateCategory::High);
998 EXPECT_EQ(getSnapshot({.id = 121})->frameRateSelectionStrategy,
999 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
1000 EXPECT_TRUE(getSnapshot({.id = 121})->changes.test(RequestedLayerState::Changes::FrameRate));
1001
1002 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.category, FrameRateCategory::High);
1003 EXPECT_EQ(getSnapshot({.id = 122})->frameRateSelectionStrategy,
1004 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
1005 EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate));
1006
1007 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.category, FrameRateCategory::High);
1008 EXPECT_EQ(getSnapshot({.id = 1221})->frameRateSelectionStrategy,
1009 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
1010 EXPECT_TRUE(getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::FrameRate));
1011
1012 // ROOT
1013 // ├── 1
1014 // │ ├── 11
1015 // │ │ └── 111
1016 // │ ├── 12 (frame rate category to default with strategy default)
1017 // │ │ ├── 121
1018 // │ │ └── 122 (frame rate set to 123.f)
1019 // │ │ └── 1221
1020 // │ └── 13
1021 // └── 2
Rachel Lee9580ff12023-12-26 17:33:41 -08001022 setFrameRateCategory(12, ANATIVEWINDOW_FRAME_RATE_CATEGORY_DEFAULT);
Vishnu Nair41376b62023-11-08 05:08:58 -08001023 setFrameRateSelectionStrategy(12, 0 /* Default */);
1024 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1025 // verify parent 1 gets no vote
1026 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
1027 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
1028 scheduler::FrameRateCompatibility::NoVote);
1029 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.category, FrameRateCategory::Default);
1030 EXPECT_FALSE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate));
1031
1032 // verify layer 12 and all descendants (121, 122, 1221) get the requested vote
1033 EXPECT_FALSE(getSnapshot({.id = 12})->frameRate.vote.rate.isValid());
1034 EXPECT_EQ(getSnapshot({.id = 12})->frameRate.vote.type,
1035 scheduler::FrameRateCompatibility::NoVote);
1036 EXPECT_EQ(getSnapshot({.id = 12})->frameRate.category, FrameRateCategory::Default);
1037 EXPECT_EQ(getSnapshot({.id = 12})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -08001038 scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate);
Vishnu Nair41376b62023-11-08 05:08:58 -08001039 EXPECT_TRUE(getSnapshot({.id = 12})->changes.test(RequestedLayerState::Changes::FrameRate));
1040
1041 EXPECT_FALSE(getSnapshot({.id = 12})->frameRate.vote.rate.isValid());
1042 EXPECT_EQ(getSnapshot({.id = 121})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -08001043 scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate);
Vishnu Nair41376b62023-11-08 05:08:58 -08001044 EXPECT_EQ(getSnapshot({.id = 121})->frameRate.category, FrameRateCategory::Default);
1045 EXPECT_EQ(getSnapshot({.id = 121})->frameRate.vote.type,
1046 scheduler::FrameRateCompatibility::Default);
1047 EXPECT_TRUE(getSnapshot({.id = 121})->changes.test(RequestedLayerState::Changes::FrameRate));
1048
1049 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.rate.getValue(), 123.f);
1050 EXPECT_EQ(getSnapshot({.id = 122})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -08001051 scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate);
Vishnu Nair41376b62023-11-08 05:08:58 -08001052 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.category, FrameRateCategory::Default);
1053 EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate));
1054
1055 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.vote.rate.getValue(), 123.f);
1056 EXPECT_EQ(getSnapshot({.id = 1221})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -08001057 scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate);
Vishnu Nair41376b62023-11-08 05:08:58 -08001058 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.category, FrameRateCategory::Default);
1059 EXPECT_TRUE(getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::FrameRate));
Rachel Lee58cc90d2023-09-05 18:50:20 -07001060}
1061
Rachel Lee70f7b692023-11-22 11:24:02 -08001062TEST_F(LayerSnapshotTest, frameRateSelectionStrategyWithOverrideChildrenAndSelf) {
Rachel Leea021bb02023-11-20 21:51:09 -08001063 // ROOT
1064 // ├── 1
Rachel Lee70f7b692023-11-22 11:24:02 -08001065 // │ ├── 11 (frame rate set to 11.f with strategy Self)
Rachel Leea021bb02023-11-20 21:51:09 -08001066 // │ │ └── 111 (frame rate is not inherited)
1067 // │ ├── 12 (frame rate set to 244.f)
1068 // │ │ ├── 121
1069 // │ │ └── 122 (strategy OverrideChildren and inherits frame rate 244.f)
1070 // │ │ └── 1221 (frame rate set to 123.f but should be overridden by layer 122)
1071 // │ └── 13
1072 // └── 2
1073 setFrameRate(11, 11.f, 0, 0);
Rachel Lee70f7b692023-11-22 11:24:02 -08001074 setFrameRateSelectionStrategy(11, 2 /* Self */);
Rachel Leea021bb02023-11-20 21:51:09 -08001075 setFrameRate(12, 244.f, 0, 0);
1076 setFrameRateSelectionStrategy(122, 1 /* OverrideChildren */);
1077 setFrameRate(1221, 123.f, 0, 0);
1078
1079 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1080 // verify parent 1 gets no vote
1081 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
1082 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
1083 scheduler::FrameRateCompatibility::NoVote);
1084 EXPECT_EQ(getSnapshot({.id = 1})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -08001085 scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate);
Rachel Leea021bb02023-11-20 21:51:09 -08001086 EXPECT_TRUE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate));
1087
1088 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 11.f);
1089 EXPECT_EQ(getSnapshot({.id = 11})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -08001090 scheduler::LayerInfo::FrameRateSelectionStrategy::Self);
Rachel Leea021bb02023-11-20 21:51:09 -08001091 EXPECT_TRUE(getSnapshot({.id = 11})->changes.test(RequestedLayerState::Changes::FrameRate));
1092
1093 // verify layer 11 does does not propagate its framerate to 111.
1094 EXPECT_FALSE(getSnapshot({.id = 111})->frameRate.vote.rate.isValid());
1095 EXPECT_EQ(getSnapshot({.id = 111})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -08001096 scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate);
Rachel Leea021bb02023-11-20 21:51:09 -08001097 EXPECT_TRUE(getSnapshot({.id = 111})->changes.test(RequestedLayerState::Changes::FrameRate));
1098
1099 // verify layer 12 and all descendants (121, 122, 1221) get the requested vote
1100 EXPECT_EQ(getSnapshot({.id = 12})->frameRate.vote.rate.getValue(), 244.f);
1101 EXPECT_EQ(getSnapshot({.id = 12})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -08001102 scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate);
Rachel Leea021bb02023-11-20 21:51:09 -08001103 EXPECT_TRUE(getSnapshot({.id = 12})->changes.test(RequestedLayerState::Changes::FrameRate));
1104
1105 EXPECT_EQ(getSnapshot({.id = 121})->frameRate.vote.rate.getValue(), 244.f);
1106 EXPECT_EQ(getSnapshot({.id = 121})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -08001107 scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate);
Rachel Leea021bb02023-11-20 21:51:09 -08001108 EXPECT_TRUE(getSnapshot({.id = 121})->changes.test(RequestedLayerState::Changes::FrameRate));
1109
1110 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.rate.getValue(), 244.f);
1111 EXPECT_EQ(getSnapshot({.id = 122})->frameRateSelectionStrategy,
1112 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
1113 EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate));
1114
1115 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.vote.rate.getValue(), 244.f);
1116 EXPECT_EQ(getSnapshot({.id = 1221})->frameRateSelectionStrategy,
1117 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
1118 EXPECT_TRUE(getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::FrameRate));
1119
1120 // ROOT
1121 // ├── 1 (frame rate set to 1.f with strategy OverrideChildren)
Rachel Lee70f7b692023-11-22 11:24:02 -08001122 // │ ├── 11 (frame rate set to 11.f with strategy Self, but overridden by 1)
Rachel Leea021bb02023-11-20 21:51:09 -08001123 // │ │ └── 111 (frame rate inherited from 11 due to override from 1)
1124 // â‹® â‹®
1125 setFrameRate(1, 1.f, 0, 0);
1126 setFrameRateSelectionStrategy(1, 1 /* OverrideChildren */);
1127 setFrameRate(11, 11.f, 0, 0);
Rachel Lee70f7b692023-11-22 11:24:02 -08001128 setFrameRateSelectionStrategy(11, 2 /* Self */);
Rachel Leea021bb02023-11-20 21:51:09 -08001129 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1130
1131 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.rate.getValue(), 1.f);
1132 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
1133 scheduler::FrameRateCompatibility::Default);
1134 EXPECT_EQ(getSnapshot({.id = 1})->frameRateSelectionStrategy,
1135 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
1136 EXPECT_TRUE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate));
1137
1138 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 1.f);
1139 EXPECT_EQ(getSnapshot({.id = 11})->frameRateSelectionStrategy,
1140 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
1141 EXPECT_TRUE(getSnapshot({.id = 11})->changes.test(RequestedLayerState::Changes::FrameRate));
1142
1143 // verify layer 11 does does not propagate its framerate to 111.
1144 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.rate.getValue(), 1.f);
1145 EXPECT_EQ(getSnapshot({.id = 111})->frameRateSelectionStrategy,
1146 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
1147 EXPECT_TRUE(getSnapshot({.id = 111})->changes.test(RequestedLayerState::Changes::FrameRate));
1148}
1149
Vishnu Nair0808ae62023-08-07 21:42:42 -07001150TEST_F(LayerSnapshotTest, skipRoundCornersWhenProtected) {
1151 setRoundedCorners(1, 42.f);
1152 setRoundedCorners(2, 42.f);
1153 setCrop(1, Rect{1000, 1000});
1154 setCrop(2, Rect{1000, 1000});
1155
1156 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1157 EXPECT_TRUE(getSnapshot({.id = 1})->roundedCorner.hasRoundedCorners());
1158 EXPECT_EQ(getSnapshot({.id = 1})->roundedCorner.radius.x, 42.f);
1159 EXPECT_TRUE(getSnapshot({.id = 2})->roundedCorner.hasRoundedCorners());
1160
1161 // add a buffer with the protected bit, check rounded corners are not set when
1162 // skipRoundCornersWhenProtected == true
1163 setBuffer(1,
1164 std::make_shared<
1165 renderengine::mock::FakeExternalTexture>(1U /*width*/, 1U /*height*/,
1166 1ULL /* bufferId */,
1167 HAL_PIXEL_FORMAT_RGBA_8888,
1168 GRALLOC_USAGE_PROTECTED /*usage*/));
1169
1170 LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(),
1171 .layerLifecycleManager = mLifecycleManager,
1172 .includeMetadata = false,
1173 .displays = mFrontEndDisplayInfos,
1174 .displayChanges = false,
1175 .globalShadowSettings = globalShadowSettings,
1176 .supportsBlur = true,
1177 .supportedLayerGenericMetadata = {},
1178 .genericLayerMetadataKeyMap = {},
1179 .skipRoundCornersWhenProtected = true};
1180 update(mSnapshotBuilder, args);
1181 EXPECT_FALSE(getSnapshot({.id = 1})->roundedCorner.hasRoundedCorners());
1182 // layer 2 doesn't have a buffer and should be unaffected
1183 EXPECT_TRUE(getSnapshot({.id = 2})->roundedCorner.hasRoundedCorners());
1184
1185 // remove protected bit, check rounded corners are set
1186 setBuffer(1,
1187 std::make_shared<renderengine::mock::FakeExternalTexture>(1U /*width*/, 1U /*height*/,
1188 2ULL /* bufferId */,
1189 HAL_PIXEL_FORMAT_RGBA_8888,
1190 0 /*usage*/));
1191 update(mSnapshotBuilder, args);
1192 EXPECT_TRUE(getSnapshot({.id = 1})->roundedCorner.hasRoundedCorners());
1193 EXPECT_EQ(getSnapshot({.id = 1})->roundedCorner.radius.x, 42.f);
1194}
1195
Vishnu Nairbd51f952023-08-31 22:50:14 -07001196TEST_F(LayerSnapshotTest, setRefreshRateIndicatorCompositionType) {
1197 setFlags(1, layer_state_t::eLayerIsRefreshRateIndicator,
1198 layer_state_t::eLayerIsRefreshRateIndicator);
1199 setBuffer(1,
1200 std::make_shared<renderengine::mock::FakeExternalTexture>(1U /*width*/, 1U /*height*/,
1201 42ULL /* bufferId */,
1202 HAL_PIXEL_FORMAT_RGBA_8888,
1203 0 /*usage*/));
1204 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1205 EXPECT_EQ(getSnapshot({.id = 1})->compositionType,
1206 aidl::android::hardware::graphics::composer3::Composition::REFRESH_RATE_INDICATOR);
1207}
1208
Chavi Weingarten07597342023-09-14 21:10:59 +00001209TEST_F(LayerSnapshotTest, setBufferCrop) {
1210 // validate no buffer but has crop
1211 Rect crop = Rect(0, 0, 50, 50);
1212 setBufferCrop(1, crop);
1213 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1214 EXPECT_EQ(getSnapshot(1)->geomContentCrop, crop);
1215
1216 setBuffer(1,
1217 std::make_shared<renderengine::mock::FakeExternalTexture>(100U /*width*/,
1218 100U /*height*/,
1219 42ULL /* bufferId */,
1220 HAL_PIXEL_FORMAT_RGBA_8888,
1221 0 /*usage*/));
1222 // validate a buffer crop within the buffer bounds
1223 setBufferCrop(1, crop);
1224 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1225 EXPECT_EQ(getSnapshot(1)->geomContentCrop, crop);
1226
1227 // validate a buffer crop outside the buffer bounds
1228 crop = Rect(0, 0, 150, 150);
1229 setBufferCrop(1, crop);
1230 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1231 EXPECT_EQ(getSnapshot(1)->geomContentCrop, Rect(0, 0, 100, 100));
1232
1233 // validate no buffer crop
1234 setBufferCrop(1, Rect());
1235 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1236 EXPECT_EQ(getSnapshot(1)->geomContentCrop, Rect(0, 0, 100, 100));
1237}
Vishnu Nairbefd3e22023-10-05 17:48:31 +00001238
1239TEST_F(LayerSnapshotTest, setShadowRadius) {
1240 static constexpr float SHADOW_RADIUS = 123.f;
1241 setShadowRadius(1, SHADOW_RADIUS);
1242 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1243 EXPECT_EQ(getSnapshot(1)->shadowSettings.length, SHADOW_RADIUS);
Vishnu Nairbefd3e22023-10-05 17:48:31 +00001244}
1245
Chavi Weingartenb74093a2023-10-11 20:29:59 +00001246TEST_F(LayerSnapshotTest, setTrustedOverlayForNonVisibleInput) {
1247 hideLayer(1);
1248 setTrustedOverlay(1, true);
1249 Region touch{Rect{0, 0, 1000, 1000}};
1250 setTouchableRegion(1, touch);
1251
1252 UPDATE_AND_VERIFY(mSnapshotBuilder, {2});
1253 EXPECT_TRUE(getSnapshot(1)->inputInfo.inputConfig.test(
1254 gui::WindowInfo::InputConfig::TRUSTED_OVERLAY));
1255}
1256
Alec Mouri89f5d4e2023-10-20 17:12:49 +00001257TEST_F(LayerSnapshotTest, isFrontBuffered) {
1258 setBuffer(1,
1259 std::make_shared<renderengine::mock::FakeExternalTexture>(
1260 1U /*width*/, 1U /*height*/, 1ULL /* bufferId */, HAL_PIXEL_FORMAT_RGBA_8888,
1261 GRALLOC_USAGE_HW_TEXTURE | AHARDWAREBUFFER_USAGE_FRONT_BUFFER /*usage*/));
1262
1263 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1264 EXPECT_TRUE(getSnapshot(1)->isFrontBuffered());
1265
1266 setBuffer(1,
1267 std::make_shared<
1268 renderengine::mock::FakeExternalTexture>(1U /*width*/, 1U /*height*/,
1269 1ULL /* bufferId */,
1270 HAL_PIXEL_FORMAT_RGBA_8888,
1271 GRALLOC_USAGE_HW_TEXTURE /*usage*/));
1272
1273 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1274 EXPECT_FALSE(getSnapshot(1)->isFrontBuffered());
1275}
1276
Chavi Weingarten4aa22af2023-11-17 19:37:07 +00001277TEST_F(LayerSnapshotTest, setSecureRootSnapshot) {
1278 setFlags(1, layer_state_t::eLayerSecure, layer_state_t::eLayerSecure);
1279 LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(),
1280 .layerLifecycleManager = mLifecycleManager,
1281 .includeMetadata = false,
1282 .displays = mFrontEndDisplayInfos,
1283 .displayChanges = false,
1284 .globalShadowSettings = globalShadowSettings,
1285 .supportsBlur = true,
1286 .supportedLayerGenericMetadata = {},
1287 .genericLayerMetadataKeyMap = {}};
1288 args.rootSnapshot.isSecure = true;
1289 update(mSnapshotBuilder, args);
1290
1291 EXPECT_TRUE(getSnapshot(1)->isSecure);
1292 // Ensure child is also marked as secure
1293 EXPECT_TRUE(getSnapshot(11)->isSecure);
1294}
1295
Prabir Pradhancf359192024-03-20 00:42:57 +00001296TEST_F(LayerSnapshotTest, setSensitiveForTracingConfigForSecureLayers) {
1297 setFlags(11, layer_state_t::eLayerSecure, layer_state_t::eLayerSecure);
1298
1299 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1300
1301 EXPECT_TRUE(getSnapshot(11)->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_TRUE(getSnapshot(111)->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(1)->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(12)->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 EXPECT_FALSE(getSnapshot(2)->inputInfo.inputConfig.test(
Arpit Singh490ccc92024-04-30 14:26:21 +00001310 gui::WindowInfo::InputConfig::SENSITIVE_FOR_PRIVACY));
Prabir Pradhancf359192024-03-20 00:42:57 +00001311}
1312
1313TEST_F(LayerSnapshotTest, setSensitiveForTracingFromInputWindowHandle) {
1314 setInputInfo(11, [](auto& inputInfo) {
Arpit Singh490ccc92024-04-30 14:26:21 +00001315 inputInfo.inputConfig |= gui::WindowInfo::InputConfig::SENSITIVE_FOR_PRIVACY;
Prabir Pradhancf359192024-03-20 00:42:57 +00001316 });
1317
1318 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1319
1320 EXPECT_TRUE(getSnapshot(11)->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_TRUE(getSnapshot(111)->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(1)->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(12)->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 EXPECT_FALSE(getSnapshot(2)->inputInfo.inputConfig.test(
Arpit Singh490ccc92024-04-30 14:26:21 +00001329 gui::WindowInfo::InputConfig::SENSITIVE_FOR_PRIVACY));
Prabir Pradhancf359192024-03-20 00:42:57 +00001330}
1331
Vishnu Nairf13c8982023-12-02 11:26:09 -08001332// b/314350323
1333TEST_F(LayerSnapshotTest, propagateDropInputMode) {
1334 setDropInputMode(1, gui::DropInputMode::ALL);
1335 LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(),
1336 .layerLifecycleManager = mLifecycleManager,
1337 .includeMetadata = false,
1338 .displays = mFrontEndDisplayInfos,
1339 .displayChanges = false,
1340 .globalShadowSettings = globalShadowSettings,
1341 .supportsBlur = true,
1342 .supportedLayerGenericMetadata = {},
1343 .genericLayerMetadataKeyMap = {}};
1344 args.rootSnapshot.isSecure = true;
1345 update(mSnapshotBuilder, args);
1346
1347 EXPECT_EQ(getSnapshot(1)->dropInputMode, gui::DropInputMode::ALL);
1348 // Ensure child also has the correct drop input mode regardless of whether either layer has
1349 // an input channel
1350 EXPECT_EQ(getSnapshot(11)->dropInputMode, gui::DropInputMode::ALL);
1351}
1352
Chavi Weingarten92c7d8c2024-01-19 23:25:45 +00001353TEST_F(LayerSnapshotTest, NonVisibleLayerWithInput) {
1354 LayerHierarchyTestBase::createRootLayer(3);
1355 setColor(3, {-1._hf, -1._hf, -1._hf});
1356 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1357
1358 std::vector<TransactionState> transactions;
1359 transactions.emplace_back();
1360 transactions.back().states.push_back({});
1361 transactions.back().states.front().state.what = layer_state_t::eInputInfoChanged;
1362 transactions.back().states.front().layerId = 3;
1363 transactions.back().states.front().state.windowInfoHandle = sp<gui::WindowInfoHandle>::make();
1364 auto inputInfo = transactions.back().states.front().state.windowInfoHandle->editInfo();
1365 inputInfo->token = sp<BBinder>::make();
1366 mLifecycleManager.applyTransactions(transactions);
1367
1368 update(mSnapshotBuilder);
1369
1370 bool foundInputLayer = false;
1371 mSnapshotBuilder.forEachInputSnapshot([&](const frontend::LayerSnapshot& snapshot) {
1372 if (snapshot.uniqueSequence == 3) {
1373 foundInputLayer = true;
1374 }
1375 });
1376 EXPECT_TRUE(foundInputLayer);
1377}
1378
Garfield Tan8eb8f352024-05-17 09:12:01 -07001379TEST_F(LayerSnapshotTest, ForEachSnapshotsWithPredicate) {
1380 std::vector<uint32_t> visitedUniqueSequences;
1381 mSnapshotBuilder.forEachSnapshot(
1382 [&](const std::unique_ptr<frontend::LayerSnapshot>& snapshot) {
1383 visitedUniqueSequences.push_back(snapshot->uniqueSequence);
1384 },
1385 [](const frontend::LayerSnapshot& snapshot) { return snapshot.uniqueSequence == 111; });
1386 EXPECT_EQ(visitedUniqueSequences.size(), 1u);
1387 EXPECT_EQ(visitedUniqueSequences[0], 111u);
1388}
1389
Vishnu Nair59a6be32024-01-29 10:26:21 -08001390TEST_F(LayerSnapshotTest, canOccludePresentation) {
1391 setFlags(12, layer_state_t::eCanOccludePresentation, layer_state_t::eCanOccludePresentation);
1392 LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(),
1393 .layerLifecycleManager = mLifecycleManager,
1394 .includeMetadata = false,
1395 .displays = mFrontEndDisplayInfos,
1396 .displayChanges = false,
1397 .globalShadowSettings = globalShadowSettings,
1398 .supportsBlur = true,
1399 .supportedLayerGenericMetadata = {},
1400 .genericLayerMetadataKeyMap = {}};
1401 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1402
1403 EXPECT_EQ(getSnapshot(1)->inputInfo.canOccludePresentation, false);
1404
1405 // ensure we can set the property on the window info for layer and all its children
1406 EXPECT_EQ(getSnapshot(12)->inputInfo.canOccludePresentation, true);
1407 EXPECT_EQ(getSnapshot(121)->inputInfo.canOccludePresentation, true);
1408 EXPECT_EQ(getSnapshot(1221)->inputInfo.canOccludePresentation, true);
1409}
1410
Vishnu Nair491827d2024-04-29 23:43:26 +00001411TEST_F(LayerSnapshotTest, mirroredHierarchyIgnoresLocalTransform) {
1412 SET_FLAG_FOR_TEST(flags::detached_mirror, true);
1413 reparentLayer(12, UNASSIGNED_LAYER_ID);
1414 setPosition(11, 2, 20);
1415 setPosition(111, 20, 200);
1416 mirrorLayer(/*layer*/ 14, /*parent*/ 1, /*layerToMirror*/ 11);
1417 std::vector<uint32_t> expected = {1, 11, 111, 13, 14, 11, 111, 2};
1418 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
1419
1420 // mirror root has no position set
1421 EXPECT_EQ(getSnapshot({.id = 11, .mirrorRootIds = 14u})->localTransform.tx(), 0);
1422 EXPECT_EQ(getSnapshot({.id = 11, .mirrorRootIds = 14u})->localTransform.ty(), 0);
1423 // original root still has a position
1424 EXPECT_EQ(getSnapshot({.id = 11})->localTransform.tx(), 2);
1425 EXPECT_EQ(getSnapshot({.id = 11})->localTransform.ty(), 20);
1426
1427 // mirror child still has the correct position
1428 EXPECT_EQ(getSnapshot({.id = 111, .mirrorRootIds = 14u})->localTransform.tx(), 20);
1429 EXPECT_EQ(getSnapshot({.id = 111, .mirrorRootIds = 14u})->localTransform.ty(), 200);
1430 EXPECT_EQ(getSnapshot({.id = 111, .mirrorRootIds = 14u})->geomLayerTransform.tx(), 20);
1431 EXPECT_EQ(getSnapshot({.id = 111, .mirrorRootIds = 14u})->geomLayerTransform.ty(), 200);
1432
1433 // original child still has the correct position including its parent's position
1434 EXPECT_EQ(getSnapshot({.id = 111})->localTransform.tx(), 20);
1435 EXPECT_EQ(getSnapshot({.id = 111})->localTransform.ty(), 200);
1436 EXPECT_EQ(getSnapshot({.id = 111})->geomLayerTransform.tx(), 22);
1437 EXPECT_EQ(getSnapshot({.id = 111})->geomLayerTransform.ty(), 220);
1438}
1439
Vishnu Nair8fc721b2022-12-22 20:06:32 +00001440} // namespace android::surfaceflinger::frontend