blob: 90207232b0771626a5edc874ab7ef7d83768c308 [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
Marzia Favaroa7632662024-05-24 16:42:54 +000030#include <com_android_graphics_libgui_flags.h>
Rachel Lee45681982024-03-14 18:40:15 -070031#include <com_android_graphics_surfaceflinger_flags.h>
32
Vishnu Nair8fc721b2022-12-22 20:06:32 +000033#define UPDATE_AND_VERIFY(BUILDER, ...) \
34 ({ \
35 SCOPED_TRACE(""); \
36 updateAndVerify((BUILDER), /*displayChanges=*/false, __VA_ARGS__); \
37 })
38
39#define UPDATE_AND_VERIFY_WITH_DISPLAY_CHANGES(BUILDER, ...) \
40 ({ \
41 SCOPED_TRACE(""); \
42 updateAndVerify((BUILDER), /*displayChanges=*/true, __VA_ARGS__); \
43 })
44
45namespace android::surfaceflinger::frontend {
46
Vishnu Naircfb2d252023-01-19 04:44:02 +000047using ftl::Flags;
48using namespace ftl::flag_operators;
Rachel Lee45681982024-03-14 18:40:15 -070049using namespace com::android::graphics::surfaceflinger;
Vishnu Naircfb2d252023-01-19 04:44:02 +000050
Vishnu Nair8fc721b2022-12-22 20:06:32 +000051// To run test:
52/**
53 mp :libsurfaceflinger_unittest && adb sync; adb shell \
54 /data/nativetest/libsurfaceflinger_unittest/libsurfaceflinger_unittest \
55 --gtest_filter="LayerSnapshotTest.*" --gtest_brief=1
56*/
57
Vishnu Nair47b7bb42023-09-29 16:27:33 -070058class LayerSnapshotTest : public LayerSnapshotTestBase {
Vishnu Nair8fc721b2022-12-22 20:06:32 +000059protected:
Vishnu Nair0fd773f2024-08-05 21:16:15 +000060 const Layer::FrameRate FRAME_RATE_VOTE1 =
61 Layer::FrameRate(67_Hz, scheduler::FrameRateCompatibility::Default);
62 const Layer::FrameRate FRAME_RATE_VOTE2 =
63 Layer::FrameRate(14_Hz, scheduler::FrameRateCompatibility::Default);
64 const Layer::FrameRate FRAME_RATE_VOTE3 =
65 Layer::FrameRate(99_Hz, scheduler::FrameRateCompatibility::Default);
66 const Layer::FrameRate FRAME_RATE_TREE =
67 Layer::FrameRate(Fps(), scheduler::FrameRateCompatibility::NoVote);
68 const Layer::FrameRate FRAME_RATE_NO_VOTE =
69 Layer::FrameRate(Fps(), scheduler::FrameRateCompatibility::Default);
70
Vishnu Nair47b7bb42023-09-29 16:27:33 -070071 LayerSnapshotTest() : LayerSnapshotTestBase() {
Vishnu Nair8fc721b2022-12-22 20:06:32 +000072 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
73 }
74
Vishnu Nair0808ae62023-08-07 21:42:42 -070075 void update(LayerSnapshotBuilder& actualBuilder, LayerSnapshotBuilder::Args& args) {
Vishnu Nair8fc721b2022-12-22 20:06:32 +000076 if (mLifecycleManager.getGlobalChanges().test(RequestedLayerState::Changes::Hierarchy)) {
Vishnu Naira0292282023-12-16 14:32:00 -080077 mHierarchyBuilder.update(mLifecycleManager);
Vishnu Nair8fc721b2022-12-22 20:06:32 +000078 }
Vishnu Nair0808ae62023-08-07 21:42:42 -070079 args.root = mHierarchyBuilder.getHierarchy();
80 actualBuilder.update(args);
81 }
82
Chavi Weingarten92c7d8c2024-01-19 23:25:45 +000083 void update(LayerSnapshotBuilder& actualBuilder) {
84 LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(),
85 .layerLifecycleManager = mLifecycleManager,
86 .includeMetadata = false,
87 .displays = mFrontEndDisplayInfos,
88 .globalShadowSettings = globalShadowSettings,
89 .supportsBlur = true,
90 .supportedLayerGenericMetadata = {},
91 .genericLayerMetadataKeyMap = {}};
92 update(actualBuilder, args);
93 }
94
Vishnu Nair0808ae62023-08-07 21:42:42 -070095 void updateAndVerify(LayerSnapshotBuilder& actualBuilder, bool hasDisplayChanges,
96 const std::vector<uint32_t> expectedVisibleLayerIdsInZOrder) {
Vishnu Nairc765c6c2023-02-23 00:08:01 +000097 LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(),
98 .layerLifecycleManager = mLifecycleManager,
99 .includeMetadata = false,
100 .displays = mFrontEndDisplayInfos,
101 .displayChanges = hasDisplayChanges,
102 .globalShadowSettings = globalShadowSettings,
Vishnu Nair444f3952023-04-11 13:01:02 -0700103 .supportsBlur = true,
Vishnu Nairc765c6c2023-02-23 00:08:01 +0000104 .supportedLayerGenericMetadata = {},
105 .genericLayerMetadataKeyMap = {}};
Vishnu Nair0808ae62023-08-07 21:42:42 -0700106 update(actualBuilder, args);
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000107
108 // rebuild layer snapshots from scratch and verify that it matches the updated state.
109 LayerSnapshotBuilder expectedBuilder(args);
110 mLifecycleManager.commitChanges();
111 ASSERT_TRUE(expectedBuilder.getSnapshots().size() > 0);
112 ASSERT_TRUE(actualBuilder.getSnapshots().size() > 0);
113
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000114 std::vector<uint32_t> actualVisibleLayerIdsInZOrder;
Vishnu Naircfb2d252023-01-19 04:44:02 +0000115 actualBuilder.forEachVisibleSnapshot(
116 [&actualVisibleLayerIdsInZOrder](const LayerSnapshot& snapshot) {
117 actualVisibleLayerIdsInZOrder.push_back(snapshot.path.id);
118 });
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000119 EXPECT_EQ(expectedVisibleLayerIdsInZOrder, actualVisibleLayerIdsInZOrder);
120 }
121
122 LayerSnapshot* getSnapshot(uint32_t layerId) { return mSnapshotBuilder.getSnapshot(layerId); }
Vishnu Nair92990e22023-02-24 20:01:05 +0000123 LayerSnapshot* getSnapshot(const LayerHierarchy::TraversalPath path) {
124 return mSnapshotBuilder.getSnapshot(path);
125 }
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000126 LayerSnapshotBuilder mSnapshotBuilder;
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000127 static const std::vector<uint32_t> STARTING_ZORDER;
128};
129const std::vector<uint32_t> LayerSnapshotTest::STARTING_ZORDER = {1, 11, 111, 12, 121,
130 122, 1221, 13, 2};
131
132TEST_F(LayerSnapshotTest, buildSnapshot) {
Vishnu Nairc765c6c2023-02-23 00:08:01 +0000133 LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(),
134 .layerLifecycleManager = mLifecycleManager,
135 .includeMetadata = false,
136 .displays = mFrontEndDisplayInfos,
137 .globalShadowSettings = globalShadowSettings,
138 .supportedLayerGenericMetadata = {},
139 .genericLayerMetadataKeyMap = {}};
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000140 LayerSnapshotBuilder builder(args);
141}
142
143TEST_F(LayerSnapshotTest, updateSnapshot) {
Vishnu Nairc765c6c2023-02-23 00:08:01 +0000144 LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(),
145 .layerLifecycleManager = mLifecycleManager,
146 .includeMetadata = false,
147 .displays = mFrontEndDisplayInfos,
148 .globalShadowSettings = globalShadowSettings,
149 .supportedLayerGenericMetadata = {},
150 .genericLayerMetadataKeyMap = {}
151
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000152 };
153
154 LayerSnapshotBuilder builder;
155 builder.update(args);
156}
157
158// update using parent snapshot data
159TEST_F(LayerSnapshotTest, croppedByParent) {
160 /// MAKE ALL LAYERS VISIBLE BY DEFAULT
161 DisplayInfo info;
162 info.info.logicalHeight = 100;
163 info.info.logicalWidth = 200;
164 mFrontEndDisplayInfos.emplace_or_replace(ui::LayerStack::fromValue(1), info);
165 Rect layerCrop(0, 0, 10, 20);
166 setCrop(11, layerCrop);
167 EXPECT_TRUE(mLifecycleManager.getGlobalChanges().test(RequestedLayerState::Changes::Geometry));
168 UPDATE_AND_VERIFY_WITH_DISPLAY_CHANGES(mSnapshotBuilder, STARTING_ZORDER);
169 EXPECT_EQ(getSnapshot(11)->geomCrop, layerCrop);
170 EXPECT_EQ(getSnapshot(111)->geomLayerBounds, layerCrop.toFloatRect());
171 float maxHeight = static_cast<float>(info.info.logicalHeight * 10);
172 float maxWidth = static_cast<float>(info.info.logicalWidth * 10);
173
174 FloatRect maxDisplaySize(-maxWidth, -maxHeight, maxWidth, maxHeight);
175 EXPECT_EQ(getSnapshot(1)->geomLayerBounds, maxDisplaySize);
176}
177
178// visibility tests
179TEST_F(LayerSnapshotTest, newLayerHiddenByPolicy) {
180 createLayer(112, 11);
181 hideLayer(112);
182 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
183
184 showLayer(112);
185 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 11, 111, 112, 12, 121, 122, 1221, 13, 2});
186}
187
188TEST_F(LayerSnapshotTest, hiddenByParent) {
189 hideLayer(11);
190 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 13, 2});
191}
192
193TEST_F(LayerSnapshotTest, reparentShowsChild) {
194 hideLayer(11);
195 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 13, 2});
196
197 showLayer(11);
198 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
199}
200
201TEST_F(LayerSnapshotTest, reparentHidesChild) {
202 hideLayer(11);
203 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 13, 2});
204
205 reparentLayer(121, 11);
206 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 122, 1221, 13, 2});
207}
208
209TEST_F(LayerSnapshotTest, unHidingUpdatesSnapshot) {
210 hideLayer(11);
211 Rect crop(1, 2, 3, 4);
212 setCrop(111, crop);
213 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 13, 2});
214
215 showLayer(11);
216 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
217 EXPECT_EQ(getSnapshot(111)->geomLayerBounds, crop.toFloatRect());
218}
219
220TEST_F(LayerSnapshotTest, childBehindParentCanBeHiddenByParent) {
221 setZ(111, -1);
222 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 111, 11, 12, 121, 122, 1221, 13, 2});
223
224 hideLayer(11);
225 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 13, 2});
226}
227
Vishnu Nairb4a6a772024-06-12 14:41:08 -0700228TEST_F(LayerSnapshotTest, offscreenLayerSnapshotIsInvisible) {
229 EXPECT_EQ(getSnapshot(111)->isVisible, true);
230
231 reparentLayer(11, UNASSIGNED_LAYER_ID);
232 destroyLayerHandle(11);
233 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 13, 2});
234
235 EXPECT_EQ(getSnapshot(111)->isVisible, false);
236 EXPECT_TRUE(getSnapshot(111)->changes.test(RequestedLayerState::Changes::Visibility));
237}
238
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000239// relative tests
240TEST_F(LayerSnapshotTest, RelativeParentCanHideChild) {
241 reparentRelativeLayer(13, 11);
242 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 11, 13, 111, 12, 121, 122, 1221, 2});
243
244 hideLayer(11);
245 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 2});
246}
247
248TEST_F(LayerSnapshotTest, ReparentingToHiddenRelativeParentHidesChild) {
249 hideLayer(11);
250 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 13, 2});
251 reparentRelativeLayer(13, 11);
252 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 2});
253}
254
255TEST_F(LayerSnapshotTest, AlphaInheritedByChildren) {
256 setAlpha(1, 0.5);
257 setAlpha(122, 0.5);
258 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
Vishnu Naira02943f2023-06-03 13:44:46 -0700259 EXPECT_EQ(getSnapshot(1)->alpha, 0.5f);
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000260 EXPECT_EQ(getSnapshot(12)->alpha, 0.5f);
261 EXPECT_EQ(getSnapshot(1221)->alpha, 0.25f);
262}
263
264// Change states
265TEST_F(LayerSnapshotTest, UpdateClearsPreviousChangeStates) {
266 setCrop(1, Rect(1, 2, 3, 4));
267 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
Vishnu Naira02943f2023-06-03 13:44:46 -0700268 EXPECT_TRUE(getSnapshot(1)->changes.test(RequestedLayerState::Changes::Geometry));
269 EXPECT_TRUE(getSnapshot(11)->changes.test(RequestedLayerState::Changes::Geometry));
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000270 setCrop(2, Rect(1, 2, 3, 4));
271 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
Vishnu Naira02943f2023-06-03 13:44:46 -0700272 EXPECT_TRUE(getSnapshot(2)->changes.test(RequestedLayerState::Changes::Geometry));
273 EXPECT_FALSE(getSnapshot(1)->changes.test(RequestedLayerState::Changes::Geometry));
274 EXPECT_FALSE(getSnapshot(11)->changes.test(RequestedLayerState::Changes::Geometry));
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000275}
276
277TEST_F(LayerSnapshotTest, FastPathClearsPreviousChangeStates) {
278 setColor(11, {1._hf, 0._hf, 0._hf});
279 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
Vishnu Nairdf59f472024-05-17 16:51:33 +0000280 EXPECT_EQ(getSnapshot(11)->changes,
Ady Abraham6846ade2024-05-20 21:58:27 +0000281 RequestedLayerState::Changes::Content);
Vishnu Naira02943f2023-06-03 13:44:46 -0700282 EXPECT_EQ(getSnapshot(11)->clientChanges, layer_state_t::eColorChanged);
283 EXPECT_EQ(getSnapshot(1)->changes.get(), 0u);
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000284 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
Vishnu Naira02943f2023-06-03 13:44:46 -0700285 EXPECT_EQ(getSnapshot(11)->changes.get(), 0u);
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000286}
287
288TEST_F(LayerSnapshotTest, FastPathSetsChangeFlagToContent) {
289 setColor(1, {1._hf, 0._hf, 0._hf});
290 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
Vishnu Nairdf59f472024-05-17 16:51:33 +0000291 EXPECT_EQ(getSnapshot(1)->changes,
Ady Abraham6846ade2024-05-20 21:58:27 +0000292 RequestedLayerState::Changes::Content);
Vishnu Naira02943f2023-06-03 13:44:46 -0700293 EXPECT_EQ(getSnapshot(1)->clientChanges, layer_state_t::eColorChanged);
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000294}
295
Vishnu Nair39a74a92024-07-29 19:01:50 +0000296TEST_F(LayerSnapshotTest, ChildrenInheritGameMode) {
297 setGameMode(1, gui::GameMode::Performance);
Nergi Rahardi27613c32024-05-23 06:57:02 +0000298 EXPECT_EQ(mLifecycleManager.getGlobalChanges(),
299 RequestedLayerState::Changes::GameMode | RequestedLayerState::Changes::Metadata);
Vishnu Naircfb2d252023-01-19 04:44:02 +0000300 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
Vishnu Naira02943f2023-06-03 13:44:46 -0700301 EXPECT_EQ(getSnapshot(1)->clientChanges, layer_state_t::eMetadataChanged);
Vishnu Nair39a74a92024-07-29 19:01:50 +0000302 EXPECT_EQ(getSnapshot(1)->gameMode, gui::GameMode::Performance);
303 EXPECT_EQ(getSnapshot(11)->gameMode, gui::GameMode::Performance);
304}
305
306TEST_F(LayerSnapshotTest, ChildrenCanOverrideGameMode) {
307 setGameMode(1, gui::GameMode::Performance);
308 setGameMode(11, gui::GameMode::Battery);
309 EXPECT_EQ(mLifecycleManager.getGlobalChanges(),
310 RequestedLayerState::Changes::GameMode | RequestedLayerState::Changes::Metadata);
311 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
312 EXPECT_EQ(getSnapshot(1)->clientChanges, layer_state_t::eMetadataChanged);
313 EXPECT_EQ(getSnapshot(1)->gameMode, gui::GameMode::Performance);
314 EXPECT_EQ(getSnapshot(11)->gameMode, gui::GameMode::Battery);
315}
316
317TEST_F(LayerSnapshotTest, ReparentingUpdatesGameMode) {
318 setGameMode(1, gui::GameMode::Performance);
319 EXPECT_EQ(mLifecycleManager.getGlobalChanges(),
320 RequestedLayerState::Changes::GameMode | RequestedLayerState::Changes::Metadata);
321 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
322 EXPECT_EQ(getSnapshot(1)->clientChanges, layer_state_t::eMetadataChanged);
323 EXPECT_EQ(getSnapshot(1)->gameMode, gui::GameMode::Performance);
324 EXPECT_EQ(getSnapshot(2)->gameMode, gui::GameMode::Unsupported);
325
326 reparentLayer(2, 1);
327 setZ(2, 2);
328 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
329 EXPECT_EQ(getSnapshot(2)->gameMode, gui::GameMode::Performance);
Vishnu Naircfb2d252023-01-19 04:44:02 +0000330}
331
Nergi Rahardi27613c32024-05-23 06:57:02 +0000332TEST_F(LayerSnapshotTest, UpdateMetadata) {
333 std::vector<TransactionState> transactions;
334 transactions.emplace_back();
335 transactions.back().states.push_back({});
336 transactions.back().states.front().state.what = layer_state_t::eMetadataChanged;
337 // This test focuses on metadata used by ARC++ to ensure LayerMetadata is updated correctly,
338 // and not using stale data.
339 transactions.back().states.front().state.metadata = LayerMetadata();
340 transactions.back().states.front().state.metadata.setInt32(METADATA_OWNER_UID, 123);
341 transactions.back().states.front().state.metadata.setInt32(METADATA_WINDOW_TYPE, 234);
342 transactions.back().states.front().state.metadata.setInt32(METADATA_TASK_ID, 345);
343 transactions.back().states.front().state.metadata.setInt32(METADATA_MOUSE_CURSOR, 456);
344 transactions.back().states.front().state.metadata.setInt32(METADATA_ACCESSIBILITY_ID, 567);
345 transactions.back().states.front().state.metadata.setInt32(METADATA_OWNER_PID, 678);
346 transactions.back().states.front().state.metadata.setInt32(METADATA_CALLING_UID, 789);
347
348 transactions.back().states.front().layerId = 1;
349 transactions.back().states.front().state.layerId = static_cast<int32_t>(1);
350
351 mLifecycleManager.applyTransactions(transactions);
352 EXPECT_EQ(mLifecycleManager.getGlobalChanges(), RequestedLayerState::Changes::Metadata);
353
354 // Setting includeMetadata=true to ensure metadata update is applied to LayerSnapshot
355 LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(),
356 .layerLifecycleManager = mLifecycleManager,
357 .includeMetadata = true,
358 .displays = mFrontEndDisplayInfos,
359 .globalShadowSettings = globalShadowSettings,
360 .supportsBlur = true,
361 .supportedLayerGenericMetadata = {},
362 .genericLayerMetadataKeyMap = {}};
363 update(mSnapshotBuilder, args);
364
365 EXPECT_EQ(getSnapshot(1)->clientChanges, layer_state_t::eMetadataChanged);
366 EXPECT_EQ(getSnapshot(1)->layerMetadata.getInt32(METADATA_OWNER_UID, -1), 123);
367 EXPECT_EQ(getSnapshot(1)->layerMetadata.getInt32(METADATA_WINDOW_TYPE, -1), 234);
368 EXPECT_EQ(getSnapshot(1)->layerMetadata.getInt32(METADATA_TASK_ID, -1), 345);
369 EXPECT_EQ(getSnapshot(1)->layerMetadata.getInt32(METADATA_MOUSE_CURSOR, -1), 456);
370 EXPECT_EQ(getSnapshot(1)->layerMetadata.getInt32(METADATA_ACCESSIBILITY_ID, -1), 567);
371 EXPECT_EQ(getSnapshot(1)->layerMetadata.getInt32(METADATA_OWNER_PID, -1), 678);
372 EXPECT_EQ(getSnapshot(1)->layerMetadata.getInt32(METADATA_CALLING_UID, -1), 789);
373}
374
Nergi Rahardi0dfc0962024-05-23 06:57:36 +0000375TEST_F(LayerSnapshotTest, UpdateMetadataOfHiddenLayers) {
376 hideLayer(1);
377
378 std::vector<TransactionState> transactions;
379 transactions.emplace_back();
380 transactions.back().states.push_back({});
381 transactions.back().states.front().state.what = layer_state_t::eMetadataChanged;
382 // This test focuses on metadata used by ARC++ to ensure LayerMetadata is updated correctly,
383 // and not using stale data.
384 transactions.back().states.front().state.metadata = LayerMetadata();
385 transactions.back().states.front().state.metadata.setInt32(METADATA_OWNER_UID, 123);
386 transactions.back().states.front().state.metadata.setInt32(METADATA_WINDOW_TYPE, 234);
387 transactions.back().states.front().state.metadata.setInt32(METADATA_TASK_ID, 345);
388 transactions.back().states.front().state.metadata.setInt32(METADATA_MOUSE_CURSOR, 456);
389 transactions.back().states.front().state.metadata.setInt32(METADATA_ACCESSIBILITY_ID, 567);
390 transactions.back().states.front().state.metadata.setInt32(METADATA_OWNER_PID, 678);
391 transactions.back().states.front().state.metadata.setInt32(METADATA_CALLING_UID, 789);
392
393 transactions.back().states.front().layerId = 1;
394 transactions.back().states.front().state.layerId = static_cast<int32_t>(1);
395
396 mLifecycleManager.applyTransactions(transactions);
397 EXPECT_EQ(mLifecycleManager.getGlobalChanges(),
398 RequestedLayerState::Changes::Metadata | RequestedLayerState::Changes::Visibility |
399 RequestedLayerState::Changes::VisibleRegion |
400 RequestedLayerState::Changes::AffectsChildren);
401
402 // Setting includeMetadata=true to ensure metadata update is applied to LayerSnapshot
403 LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(),
404 .layerLifecycleManager = mLifecycleManager,
405 .includeMetadata = true,
406 .displays = mFrontEndDisplayInfos,
407 .globalShadowSettings = globalShadowSettings,
408 .supportsBlur = true,
409 .supportedLayerGenericMetadata = {},
410 .genericLayerMetadataKeyMap = {}};
411 update(mSnapshotBuilder, args);
412
413 EXPECT_EQ(static_cast<int64_t>(getSnapshot(1)->clientChanges),
414 layer_state_t::eMetadataChanged | layer_state_t::eFlagsChanged);
415 EXPECT_EQ(getSnapshot(1)->layerMetadata.getInt32(METADATA_OWNER_UID, -1), 123);
416 EXPECT_EQ(getSnapshot(1)->layerMetadata.getInt32(METADATA_WINDOW_TYPE, -1), 234);
417 EXPECT_EQ(getSnapshot(1)->layerMetadata.getInt32(METADATA_TASK_ID, -1), 345);
418 EXPECT_EQ(getSnapshot(1)->layerMetadata.getInt32(METADATA_MOUSE_CURSOR, -1), 456);
419 EXPECT_EQ(getSnapshot(1)->layerMetadata.getInt32(METADATA_ACCESSIBILITY_ID, -1), 567);
420 EXPECT_EQ(getSnapshot(1)->layerMetadata.getInt32(METADATA_OWNER_PID, -1), 678);
421 EXPECT_EQ(getSnapshot(1)->layerMetadata.getInt32(METADATA_CALLING_UID, -1), 789);
422}
423
Vishnu Naircfb2d252023-01-19 04:44:02 +0000424TEST_F(LayerSnapshotTest, NoLayerVoteForParentWithChildVotes) {
425 // ROOT
426 // ├── 1
427 // │ ├── 11 (frame rate set)
428 // │ │ └── 111
429 // │ ├── 12
430 // │ │ ├── 121
431 // │ │ └── 122
432 // │ │ └── 1221
433 // │ └── 13
434 // └── 2
435
Vishnu Nair30515cb2023-10-19 21:54:08 -0700436 setFrameRate(11, 90.0, ANATIVEWINDOW_FRAME_RATE_EXACT, ANATIVEWINDOW_CHANGE_FRAME_RATE_ALWAYS);
Vishnu Naircfb2d252023-01-19 04:44:02 +0000437 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
438
Rachel Leece6e0042023-06-27 11:22:54 -0700439 EXPECT_EQ(getSnapshot(11)->frameRate.vote.rate.getIntValue(), 90);
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700440 EXPECT_EQ(getSnapshot(11)->frameRate.vote.type, scheduler::FrameRateCompatibility::Exact);
Rachel Leece6e0042023-06-27 11:22:54 -0700441 EXPECT_EQ(getSnapshot(111)->frameRate.vote.rate.getIntValue(), 90);
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700442 EXPECT_EQ(getSnapshot(111)->frameRate.vote.type, scheduler::FrameRateCompatibility::Exact);
Rachel Leece6e0042023-06-27 11:22:54 -0700443 EXPECT_EQ(getSnapshot(1)->frameRate.vote.rate.getIntValue(), 0);
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700444 EXPECT_EQ(getSnapshot(1)->frameRate.vote.type, scheduler::FrameRateCompatibility::NoVote);
Vishnu Naircfb2d252023-01-19 04:44:02 +0000445}
446
Vishnu Nair30515cb2023-10-19 21:54:08 -0700447TEST_F(LayerSnapshotTest, NoLayerVoteForParentWithChildVotesDoesNotAffectSiblings) {
448 // ROOT
449 // ├── 1 (verify layer has no vote)
450 // │ ├── 11 (frame rate set)
451 // │ │ └── 111
452 // │ ├── 12 (frame rate set)
453 // │ │ ├── 121
454 // │ │ └── 122
455 // │ │ └── 1221
456 // │ └── 13 (verify layer has default vote)
457 // └── 2
458
459 setFrameRate(11, 90.0, ANATIVEWINDOW_FRAME_RATE_EXACT, ANATIVEWINDOW_CHANGE_FRAME_RATE_ALWAYS);
460 setFrameRate(12, 45.0, ANATIVEWINDOW_FRAME_RATE_EXACT, ANATIVEWINDOW_CHANGE_FRAME_RATE_ALWAYS);
461
462 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
463
464 EXPECT_EQ(getSnapshot(11)->frameRate.vote.rate.getIntValue(), 90);
465 EXPECT_EQ(getSnapshot(11)->frameRate.vote.type, scheduler::FrameRateCompatibility::Exact);
466 EXPECT_EQ(getSnapshot(111)->frameRate.vote.rate.getIntValue(), 90);
467 EXPECT_EQ(getSnapshot(111)->frameRate.vote.type, scheduler::FrameRateCompatibility::Exact);
468 EXPECT_EQ(getSnapshot(12)->frameRate.vote.rate.getIntValue(), 45);
469 EXPECT_EQ(getSnapshot(12)->frameRate.vote.type, scheduler::FrameRateCompatibility::Exact);
470 EXPECT_EQ(getSnapshot(121)->frameRate.vote.rate.getIntValue(), 45);
471 EXPECT_EQ(getSnapshot(121)->frameRate.vote.type, scheduler::FrameRateCompatibility::Exact);
472 EXPECT_EQ(getSnapshot(1221)->frameRate.vote.rate.getIntValue(), 45);
473 EXPECT_EQ(getSnapshot(1221)->frameRate.vote.type, scheduler::FrameRateCompatibility::Exact);
474
475 EXPECT_EQ(getSnapshot(1)->frameRate.vote.rate.getIntValue(), 0);
476 EXPECT_EQ(getSnapshot(1)->frameRate.vote.type, scheduler::FrameRateCompatibility::NoVote);
477 EXPECT_EQ(getSnapshot(13)->frameRate.vote.rate.getIntValue(), 0);
478 EXPECT_EQ(getSnapshot(13)->frameRate.vote.type, scheduler::FrameRateCompatibility::Default);
479 EXPECT_EQ(getSnapshot(2)->frameRate.vote.rate.getIntValue(), 0);
480 EXPECT_EQ(getSnapshot(2)->frameRate.vote.type, scheduler::FrameRateCompatibility::Default);
481}
482
Vishnu Naira02943f2023-06-03 13:44:46 -0700483TEST_F(LayerSnapshotTest, CanCropTouchableRegion) {
Vishnu Nair29354ec2023-03-28 18:51:28 -0700484 // ROOT
485 // ├── 1
486 // │ ├── 11
487 // │ │ └── 111 (touchregion set to touch but cropped by layer 13)
488 // │ ├── 12
489 // │ │ ├── 121
490 // │ │ └── 122
491 // │ │ └── 1221
492 // │ └── 13 (crop set to touchCrop)
493 // └── 2
494
495 Rect touchCrop{300, 300, 400, 500};
496 setCrop(13, touchCrop);
497 Region touch{Rect{0, 0, 1000, 1000}};
498 setTouchableRegionCrop(111, touch, /*touchCropId=*/13, /*replaceTouchableRegionWithCrop=*/true);
499 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
500 EXPECT_EQ(getSnapshot({.id = 111})->inputInfo.touchableRegion.bounds(), touchCrop);
501
502 Rect modifiedTouchCrop{100, 300, 400, 700};
503 setCrop(13, modifiedTouchCrop);
504 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
505 EXPECT_EQ(getSnapshot({.id = 111})->inputInfo.touchableRegion.bounds(), modifiedTouchCrop);
506}
507
Chavi Weingarten1ba381e2024-01-09 21:54:11 +0000508TEST_F(LayerSnapshotTest, CanCropTouchableRegionWithDisplayTransform) {
509 DisplayInfo displayInfo;
510 displayInfo.transform = ui::Transform(ui::Transform::RotationFlags::ROT_90, 1000, 1000);
511 mFrontEndDisplayInfos.emplace_or_replace(ui::LayerStack::fromValue(1), displayInfo);
512
513 Rect touchCrop{300, 300, 400, 500};
514 createRootLayer(3);
515 setCrop(3, touchCrop);
516 setLayerStack(3, 1);
517 Region touch{Rect{0, 0, 1000, 1000}};
518 setTouchableRegionCrop(3, touch, /*touchCropId=*/3, /*replaceTouchableRegionWithCrop=*/false);
519
520 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 11, 111, 12, 121, 122, 1221, 13, 2, 3});
521 Rect rotatedCrop = {500, 300, 700, 400};
522 EXPECT_EQ(getSnapshot({.id = 3})->inputInfo.touchableRegion.bounds(), rotatedCrop);
523}
524
Vishnu Nair444f3952023-04-11 13:01:02 -0700525TEST_F(LayerSnapshotTest, blurUpdatesWhenAlphaChanges) {
Vishnu Nair854ce1c2023-08-19 15:00:13 -0700526 int blurRadius = 42;
527 setBackgroundBlurRadius(1221, static_cast<uint32_t>(blurRadius));
Vishnu Nair444f3952023-04-11 13:01:02 -0700528
529 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
530 EXPECT_EQ(getSnapshot({.id = 1221})->backgroundBlurRadius, blurRadius);
531
Vishnu Nair854ce1c2023-08-19 15:00:13 -0700532 blurRadius = 21;
533 setBackgroundBlurRadius(1221, static_cast<uint32_t>(blurRadius));
534 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
535 EXPECT_EQ(getSnapshot({.id = 1221})->backgroundBlurRadius, blurRadius);
536
Vishnu Nair444f3952023-04-11 13:01:02 -0700537 static constexpr float alpha = 0.5;
538 setAlpha(12, alpha);
539 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
Vishnu Nair854ce1c2023-08-19 15:00:13 -0700540 EXPECT_EQ(getSnapshot({.id = 1221})->backgroundBlurRadius,
541 static_cast<int>(static_cast<float>(blurRadius) * alpha));
Vishnu Nair444f3952023-04-11 13:01:02 -0700542}
543
Vishnu Naira9c43762023-01-27 19:10:25 +0000544// Display Mirroring Tests
545// tree with 3 levels of children
546// ROOT (DISPLAY 0)
547// ├── 1
548// │ ├── 11
549// │ │ └── 111
550// │ ├── 12 (has skip screenshot flag)
551// │ │ ├── 121
552// │ │ └── 122
553// │ │ └── 1221
554// │ └── 13
555// └── 2
556// ROOT (DISPLAY 1)
557// └── 3 (mirrors display 0)
Vishnu Nair92990e22023-02-24 20:01:05 +0000558TEST_F(LayerSnapshotTest, displayMirrorRespectsLayerSkipScreenshotFlag) {
Vishnu Naira9c43762023-01-27 19:10:25 +0000559 setFlags(12, layer_state_t::eLayerSkipScreenshot, layer_state_t::eLayerSkipScreenshot);
560 createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0));
561 setLayerStack(3, 1);
562
Vishnu Nair444f3952023-04-11 13:01:02 -0700563 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 +0000564 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
565}
566
Vishnu Nair92990e22023-02-24 20:01:05 +0000567// ROOT (DISPLAY 0)
568// ├── 1
569// │ ├── 11
570// │ │ └── 111
571// │ └── 13
572// └── 2
573// ROOT (DISPLAY 3)
574// └── 3 (mirrors display 0)
575TEST_F(LayerSnapshotTest, mirrorLayerGetsCorrectLayerStack) {
576 reparentLayer(12, UNASSIGNED_LAYER_ID);
577 createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0));
578 setLayerStack(3, 3);
579 createDisplayMirrorLayer(4, ui::LayerStack::fromValue(0));
580 setLayerStack(4, 4);
581
Vishnu Nair444f3952023-04-11 13:01:02 -0700582 std::vector<uint32_t> expected = {1, 11, 111, 13, 2, 3, 1, 11, 111,
583 13, 2, 4, 1, 11, 111, 13, 2};
Vishnu Nair92990e22023-02-24 20:01:05 +0000584 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
Vishnu Nair6f878312023-09-08 11:05:01 -0700585 EXPECT_EQ(getSnapshot({.id = 111, .mirrorRootIds = 3u})->outputFilter.layerStack.id, 3u);
586 EXPECT_EQ(getSnapshot({.id = 111, .mirrorRootIds = 4u})->outputFilter.layerStack.id, 4u);
Vishnu Nair92990e22023-02-24 20:01:05 +0000587}
588
589// ROOT (DISPLAY 0)
590// ├── 1 (crop 50x50)
591// │ ├── 11
592// │ │ └── 111
593// │ └── 13
594// └── 2
595// ROOT (DISPLAY 3)
596// └── 3 (mirrors display 0) (crop 100x100)
597TEST_F(LayerSnapshotTest, mirrorLayerTouchIsCroppedByMirrorRoot) {
598 reparentLayer(12, UNASSIGNED_LAYER_ID);
599 createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0));
600 setLayerStack(3, 3);
601 setCrop(1, Rect{50, 50});
602 setCrop(3, Rect{100, 100});
603 setCrop(111, Rect{200, 200});
604 Region touch{Rect{0, 0, 1000, 1000}};
605 setTouchableRegion(111, touch);
Vishnu Nair444f3952023-04-11 13:01:02 -0700606 std::vector<uint32_t> expected = {1, 11, 111, 13, 2, 3, 1, 11, 111, 13, 2};
Vishnu Nair92990e22023-02-24 20:01:05 +0000607 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
608 EXPECT_TRUE(getSnapshot({.id = 111})->inputInfo.touchableRegion.hasSameRects(touch));
609 Region touchCroppedByMirrorRoot{Rect{0, 0, 50, 50}};
Vishnu Nair6f878312023-09-08 11:05:01 -0700610 EXPECT_TRUE(getSnapshot({.id = 111, .mirrorRootIds = 3u})
Vishnu Nair92990e22023-02-24 20:01:05 +0000611 ->inputInfo.touchableRegion.hasSameRects(touchCroppedByMirrorRoot));
612}
613
614TEST_F(LayerSnapshotTest, canRemoveDisplayMirror) {
615 setFlags(12, layer_state_t::eLayerSkipScreenshot, layer_state_t::eLayerSkipScreenshot);
616 createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0));
617 setLayerStack(3, 1);
Vishnu Nair444f3952023-04-11 13:01:02 -0700618 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 +0000619 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
620 destroyLayerHandle(3);
621 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
622}
623
Vishnu Nairfccd6362023-02-24 23:39:53 +0000624TEST_F(LayerSnapshotTest, cleanUpUnreachableSnapshotsAfterMirroring) {
625 size_t startingNumSnapshots = mSnapshotBuilder.getSnapshots().size();
626 createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0));
627 setLayerStack(3, 1);
Vishnu Nair444f3952023-04-11 13:01:02 -0700628 std::vector<uint32_t> expected = {1, 11, 111, 12, 121, 122, 1221, 13, 2, 3,
629 1, 11, 111, 12, 121, 122, 1221, 13, 2};
Vishnu Nairfccd6362023-02-24 23:39:53 +0000630 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
631 destroyLayerHandle(3);
632 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
633
634 EXPECT_EQ(startingNumSnapshots, mSnapshotBuilder.getSnapshots().size());
635}
636
Vishnu Nair6f878312023-09-08 11:05:01 -0700637TEST_F(LayerSnapshotTest, canMirrorDisplayWithMirrors) {
638 reparentLayer(12, UNASSIGNED_LAYER_ID);
639 mirrorLayer(/*layer*/ 14, /*parent*/ 1, /*layerToMirror*/ 11);
640 std::vector<uint32_t> expected = {1, 11, 111, 13, 14, 11, 111, 2};
641 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
642
643 createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0));
644 setLayerStack(3, 3);
645 expected = {1, 11, 111, 13, 14, 11, 111, 2, 3, 1, 11, 111, 13, 14, 11, 111, 2};
646 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
647 EXPECT_EQ(getSnapshot({.id = 11, .mirrorRootIds = 14u})->outputFilter.layerStack.id, 0u);
648 EXPECT_EQ(getSnapshot({.id = 11, .mirrorRootIds = 3u})->outputFilter.layerStack.id, 3u);
649 EXPECT_EQ(getSnapshot({.id = 11, .mirrorRootIds = 3u, 14u})->outputFilter.layerStack.id, 3u);
650}
651
Vishnu Nairfccd6362023-02-24 23:39:53 +0000652// Rel z doesn't create duplicate snapshots but this is for completeness
653TEST_F(LayerSnapshotTest, cleanUpUnreachableSnapshotsAfterRelZ) {
654 size_t startingNumSnapshots = mSnapshotBuilder.getSnapshots().size();
655 reparentRelativeLayer(13, 11);
656 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 11, 13, 111, 12, 121, 122, 1221, 2});
657 setZ(13, 0);
658 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
659
660 EXPECT_EQ(startingNumSnapshots, mSnapshotBuilder.getSnapshots().size());
661}
662
663TEST_F(LayerSnapshotTest, cleanUpUnreachableSnapshotsAfterLayerDestruction) {
664 size_t startingNumSnapshots = mSnapshotBuilder.getSnapshots().size();
665 destroyLayerHandle(2);
666 destroyLayerHandle(122);
667
668 std::vector<uint32_t> expected = {1, 11, 111, 12, 121, 122, 1221, 13};
669 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
670
671 EXPECT_LE(startingNumSnapshots - 2, mSnapshotBuilder.getSnapshots().size());
672}
673
Vishnu Nair3d8565a2023-06-30 07:23:24 +0000674TEST_F(LayerSnapshotTest, snashotContainsMetadataFromLayerCreationArgs) {
675 LayerCreationArgs args(std::make_optional<uint32_t>(200));
676 args.name = "testlayer";
677 args.addToRoot = true;
678 args.metadata.setInt32(42, 24);
679
680 std::vector<std::unique_ptr<RequestedLayerState>> layers;
681 layers.emplace_back(std::make_unique<RequestedLayerState>(args));
682 EXPECT_TRUE(layers.back()->metadata.has(42));
683 EXPECT_EQ(layers.back()->metadata.getInt32(42, 0), 24);
684 mLifecycleManager.addLayers(std::move(layers));
685
686 std::vector<uint32_t> expected = STARTING_ZORDER;
687 expected.push_back(200);
688 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
689
690 EXPECT_TRUE(mSnapshotBuilder.getSnapshot(200)->layerMetadata.has(42));
691 EXPECT_EQ(mSnapshotBuilder.getSnapshot(200)->layerMetadata.getInt32(42, 0), 24);
692}
693
694TEST_F(LayerSnapshotTest, frameRateSelectionPriorityPassedToChildLayers) {
695 setFrameRateSelectionPriority(11, 1);
696
697 setFrameRateSelectionPriority(12, 2);
698
699 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
700 EXPECT_EQ(getSnapshot({.id = 1})->frameRateSelectionPriority, Layer::PRIORITY_UNSET);
701 EXPECT_EQ(getSnapshot({.id = 11})->frameRateSelectionPriority, 1);
702 EXPECT_EQ(getSnapshot({.id = 12})->frameRateSelectionPriority, 2);
703 EXPECT_EQ(getSnapshot({.id = 122})->frameRateSelectionPriority, 2);
704 EXPECT_EQ(getSnapshot({.id = 1221})->frameRateSelectionPriority, 2);
705
706 // reparent and verify the child gets the new parent's framerate selection priority
707 reparentLayer(122, 11);
708
709 std::vector<uint32_t> expected = {1, 11, 111, 122, 1221, 12, 121, 13, 2};
710 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
711 EXPECT_EQ(getSnapshot({.id = 1})->frameRateSelectionPriority, Layer::PRIORITY_UNSET);
712 EXPECT_EQ(getSnapshot({.id = 11})->frameRateSelectionPriority, 1);
713 EXPECT_EQ(getSnapshot({.id = 12})->frameRateSelectionPriority, 2);
714 EXPECT_EQ(getSnapshot({.id = 122})->frameRateSelectionPriority, 1);
715 EXPECT_EQ(getSnapshot({.id = 1221})->frameRateSelectionPriority, 1);
716}
717
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000718TEST_F(LayerSnapshotTest, framerate) {
719 setFrameRate(11, 244.f, 0, 0);
720
721 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
722 // verify parent is gets no vote
Rachel Leece6e0042023-06-27 11:22:54 -0700723 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
724 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700725 scheduler::FrameRateCompatibility::NoVote);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000726 EXPECT_TRUE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate));
727
728 // verify layer and children get the requested votes
Rachel Leece6e0042023-06-27 11:22:54 -0700729 EXPECT_TRUE(getSnapshot({.id = 11})->frameRate.vote.rate.isValid());
730 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 244.f);
731 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700732 scheduler::FrameRateCompatibility::Default);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000733 EXPECT_TRUE(getSnapshot({.id = 11})->changes.test(RequestedLayerState::Changes::FrameRate));
734
Rachel Leece6e0042023-06-27 11:22:54 -0700735 EXPECT_TRUE(getSnapshot({.id = 111})->frameRate.vote.rate.isValid());
736 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.rate.getValue(), 244.f);
737 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700738 scheduler::FrameRateCompatibility::Default);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000739 EXPECT_TRUE(getSnapshot({.id = 111})->changes.test(RequestedLayerState::Changes::FrameRate));
740
741 // reparent and verify the child gets the new parent's framerate
742 reparentLayer(122, 11);
743
744 std::vector<uint32_t> expected = {1, 11, 111, 122, 1221, 12, 121, 13, 2};
745 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
746 // verify parent is gets no vote
Rachel Leece6e0042023-06-27 11:22:54 -0700747 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
748 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700749 scheduler::FrameRateCompatibility::NoVote);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000750
751 // verify layer and children get the requested votes
Rachel Leece6e0042023-06-27 11:22:54 -0700752 EXPECT_TRUE(getSnapshot({.id = 11})->frameRate.vote.rate.isValid());
753 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 244.f);
754 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700755 scheduler::FrameRateCompatibility::Default);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000756
Rachel Leece6e0042023-06-27 11:22:54 -0700757 EXPECT_TRUE(getSnapshot({.id = 111})->frameRate.vote.rate.isValid());
758 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.rate.getValue(), 244.f);
759 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700760 scheduler::FrameRateCompatibility::Default);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000761
Rachel Leece6e0042023-06-27 11:22:54 -0700762 EXPECT_TRUE(getSnapshot({.id = 122})->frameRate.vote.rate.isValid());
763 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.rate.getValue(), 244.f);
764 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700765 scheduler::FrameRateCompatibility::Default);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000766 EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate));
767
768 // reparent and verify the new parent gets no vote
769 reparentLayer(11, 2);
770 expected = {1, 12, 121, 13, 2, 11, 111, 122, 1221};
771 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
772
773 // verify old parent has invalid framerate (default)
Rachel Leece6e0042023-06-27 11:22:54 -0700774 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
775 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700776 scheduler::FrameRateCompatibility::Default);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000777 EXPECT_TRUE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate));
778
779 // verify new parent get no vote
Rachel Leece6e0042023-06-27 11:22:54 -0700780 EXPECT_FALSE(getSnapshot({.id = 2})->frameRate.vote.rate.isValid());
781 EXPECT_EQ(getSnapshot({.id = 2})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700782 scheduler::FrameRateCompatibility::NoVote);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000783 EXPECT_TRUE(getSnapshot({.id = 2})->changes.test(RequestedLayerState::Changes::FrameRate));
784
785 // verify layer and children get the requested votes (unchanged)
Rachel Leece6e0042023-06-27 11:22:54 -0700786 EXPECT_TRUE(getSnapshot({.id = 11})->frameRate.vote.rate.isValid());
787 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 244.f);
788 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700789 scheduler::FrameRateCompatibility::Default);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000790
Rachel Leece6e0042023-06-27 11:22:54 -0700791 EXPECT_TRUE(getSnapshot({.id = 111})->frameRate.vote.rate.isValid());
792 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.rate.getValue(), 244.f);
793 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700794 scheduler::FrameRateCompatibility::Default);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000795
Rachel Leece6e0042023-06-27 11:22:54 -0700796 EXPECT_TRUE(getSnapshot({.id = 122})->frameRate.vote.rate.isValid());
797 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.rate.getValue(), 244.f);
798 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700799 scheduler::FrameRateCompatibility::Default);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000800}
801
Vishnu Nair0fd773f2024-08-05 21:16:15 +0000802TEST_F(LayerSnapshotTest, frameRateSetAndGet) {
803 setFrameRate(1, FRAME_RATE_VOTE1.vote.rate.getValue(), 0, 0);
804 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
805 // verify parent is gets no vote
806 EXPECT_EQ(getSnapshot({.id = 1})->frameRate, FRAME_RATE_VOTE1);
807}
808
809TEST_F(LayerSnapshotTest, frameRateSetAndGetParent) {
810 setFrameRate(111, FRAME_RATE_VOTE1.vote.rate.getValue(), 0, 0);
811 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
812 EXPECT_EQ(getSnapshot({.id = 1})->frameRate, FRAME_RATE_TREE);
813 EXPECT_EQ(getSnapshot({.id = 11})->frameRate, FRAME_RATE_TREE);
814 EXPECT_EQ(getSnapshot({.id = 111})->frameRate, FRAME_RATE_VOTE1);
815
816 setFrameRate(111, FRAME_RATE_NO_VOTE.vote.rate.getValue(), 0, 0);
817 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
818 EXPECT_EQ(getSnapshot({.id = 1})->frameRate, FRAME_RATE_NO_VOTE);
819 EXPECT_EQ(getSnapshot({.id = 11})->frameRate, FRAME_RATE_NO_VOTE);
820 EXPECT_EQ(getSnapshot({.id = 111})->frameRate, FRAME_RATE_NO_VOTE);
821}
822
823TEST_F(LayerSnapshotTest, frameRateSetAndGetParentAllVote) {
824 setFrameRate(1, FRAME_RATE_VOTE3.vote.rate.getValue(), 0, 0);
825 setFrameRate(11, FRAME_RATE_VOTE2.vote.rate.getValue(), 0, 0);
826 setFrameRate(111, FRAME_RATE_VOTE1.vote.rate.getValue(), 0, 0);
827 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
828
829 EXPECT_EQ(getSnapshot({.id = 1})->frameRate, FRAME_RATE_VOTE3);
830 EXPECT_EQ(getSnapshot({.id = 11})->frameRate, FRAME_RATE_VOTE2);
831 EXPECT_EQ(getSnapshot({.id = 111})->frameRate, FRAME_RATE_VOTE1);
832
833 setFrameRate(111, FRAME_RATE_NO_VOTE.vote.rate.getValue(), 0, 0);
834 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
835 EXPECT_EQ(getSnapshot({.id = 1})->frameRate, FRAME_RATE_VOTE3);
836 EXPECT_EQ(getSnapshot({.id = 11})->frameRate, FRAME_RATE_VOTE2);
837 EXPECT_EQ(getSnapshot({.id = 111})->frameRate, FRAME_RATE_VOTE2);
838
839 setFrameRate(11, FRAME_RATE_NO_VOTE.vote.rate.getValue(), 0, 0);
840 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
841 EXPECT_EQ(getSnapshot({.id = 1})->frameRate, FRAME_RATE_VOTE3);
842 EXPECT_EQ(getSnapshot({.id = 11})->frameRate, FRAME_RATE_VOTE3);
843 EXPECT_EQ(getSnapshot({.id = 111})->frameRate, FRAME_RATE_VOTE3);
844
845 setFrameRate(1, FRAME_RATE_NO_VOTE.vote.rate.getValue(), 0, 0);
846 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
847 EXPECT_EQ(getSnapshot({.id = 1})->frameRate, FRAME_RATE_NO_VOTE);
848 EXPECT_EQ(getSnapshot({.id = 11})->frameRate, FRAME_RATE_NO_VOTE);
849 EXPECT_EQ(getSnapshot({.id = 111})->frameRate, FRAME_RATE_NO_VOTE);
850}
851
852TEST_F(LayerSnapshotTest, frameRateSetAndGetChild) {
853 setFrameRate(1, FRAME_RATE_VOTE1.vote.rate.getValue(), 0, 0);
854 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
855 EXPECT_EQ(getSnapshot({.id = 1})->frameRate, FRAME_RATE_VOTE1);
856 EXPECT_EQ(getSnapshot({.id = 11})->frameRate, FRAME_RATE_VOTE1);
857 EXPECT_EQ(getSnapshot({.id = 111})->frameRate, FRAME_RATE_VOTE1);
858
859 setFrameRate(1, FRAME_RATE_NO_VOTE.vote.rate.getValue(), 0, 0);
860 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
861 EXPECT_EQ(getSnapshot({.id = 1})->frameRate, FRAME_RATE_NO_VOTE);
862 EXPECT_EQ(getSnapshot({.id = 11})->frameRate, FRAME_RATE_NO_VOTE);
863 EXPECT_EQ(getSnapshot({.id = 111})->frameRate, FRAME_RATE_NO_VOTE);
864}
865
866TEST_F(LayerSnapshotTest, frameRateSetAndGetChildAllVote) {
867 setFrameRate(1, FRAME_RATE_VOTE3.vote.rate.getValue(), 0, 0);
868 setFrameRate(11, FRAME_RATE_VOTE2.vote.rate.getValue(), 0, 0);
869 setFrameRate(111, FRAME_RATE_VOTE1.vote.rate.getValue(), 0, 0);
870 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
871 EXPECT_EQ(getSnapshot({.id = 1})->frameRate, FRAME_RATE_VOTE3);
872 EXPECT_EQ(getSnapshot({.id = 11})->frameRate, FRAME_RATE_VOTE2);
873 EXPECT_EQ(getSnapshot({.id = 111})->frameRate, FRAME_RATE_VOTE1);
874
875 setFrameRate(1, FRAME_RATE_NO_VOTE.vote.rate.getValue(), 0, 0);
876 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
877 EXPECT_EQ(getSnapshot({.id = 1})->frameRate, FRAME_RATE_TREE);
878 EXPECT_EQ(getSnapshot({.id = 11})->frameRate, FRAME_RATE_VOTE2);
879 EXPECT_EQ(getSnapshot({.id = 111})->frameRate, FRAME_RATE_VOTE1);
880
881 setFrameRate(11, FRAME_RATE_NO_VOTE.vote.rate.getValue(), 0, 0);
882 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
883 EXPECT_EQ(getSnapshot({.id = 1})->frameRate, FRAME_RATE_TREE);
884 EXPECT_EQ(getSnapshot({.id = 11})->frameRate, FRAME_RATE_TREE);
885 EXPECT_EQ(getSnapshot({.id = 111})->frameRate, FRAME_RATE_VOTE1);
886
887 setFrameRate(111, FRAME_RATE_NO_VOTE.vote.rate.getValue(), 0, 0);
888 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
889 EXPECT_EQ(getSnapshot({.id = 1})->frameRate, FRAME_RATE_NO_VOTE);
890 EXPECT_EQ(getSnapshot({.id = 11})->frameRate, FRAME_RATE_NO_VOTE);
891 EXPECT_EQ(getSnapshot({.id = 111})->frameRate, FRAME_RATE_NO_VOTE);
892}
893
894TEST_F(LayerSnapshotTest, frameRateSetAndGetChildAddAfterVote) {
895 setFrameRate(1, FRAME_RATE_VOTE1.vote.rate.getValue(), 0, 0);
896 reparentLayer(111, 2);
897 std::vector<uint32_t> traversalOrder = {1, 11, 12, 121, 122, 1221, 13, 2, 111};
898 UPDATE_AND_VERIFY(mSnapshotBuilder, traversalOrder);
899 EXPECT_EQ(getSnapshot({.id = 1})->frameRate, FRAME_RATE_VOTE1);
900 EXPECT_EQ(getSnapshot({.id = 11})->frameRate, FRAME_RATE_VOTE1);
901 EXPECT_EQ(getSnapshot({.id = 111})->frameRate, FRAME_RATE_NO_VOTE);
902
903 reparentLayer(111, 11);
904 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
905 EXPECT_EQ(getSnapshot({.id = 1})->frameRate, FRAME_RATE_VOTE1);
906 EXPECT_EQ(getSnapshot({.id = 11})->frameRate, FRAME_RATE_VOTE1);
907 EXPECT_EQ(getSnapshot({.id = 111})->frameRate, FRAME_RATE_VOTE1);
908
909 setFrameRate(1, FRAME_RATE_NO_VOTE.vote.rate.getValue(), 0, 0);
910 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
911 EXPECT_EQ(getSnapshot({.id = 1})->frameRate, FRAME_RATE_NO_VOTE);
912 EXPECT_EQ(getSnapshot({.id = 11})->frameRate, FRAME_RATE_NO_VOTE);
913 EXPECT_EQ(getSnapshot({.id = 111})->frameRate, FRAME_RATE_NO_VOTE);
914}
915
916TEST_F(LayerSnapshotTest, frameRateSetAndGetChildRemoveAfterVote) {
917 setFrameRate(1, FRAME_RATE_VOTE1.vote.rate.getValue(), 0, 0);
918 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
919 EXPECT_EQ(getSnapshot({.id = 1})->frameRate, FRAME_RATE_VOTE1);
920 EXPECT_EQ(getSnapshot({.id = 11})->frameRate, FRAME_RATE_VOTE1);
921 EXPECT_EQ(getSnapshot({.id = 111})->frameRate, FRAME_RATE_VOTE1);
922
923 reparentLayer(111, 2);
924 std::vector<uint32_t> traversalOrder = {1, 11, 12, 121, 122, 1221, 13, 2, 111};
925 UPDATE_AND_VERIFY(mSnapshotBuilder, traversalOrder);
926 EXPECT_EQ(getSnapshot({.id = 1})->frameRate, FRAME_RATE_VOTE1);
927 EXPECT_EQ(getSnapshot({.id = 11})->frameRate, FRAME_RATE_VOTE1);
928 EXPECT_EQ(getSnapshot({.id = 111})->frameRate, FRAME_RATE_NO_VOTE);
929
930 setFrameRate(1, FRAME_RATE_NO_VOTE.vote.rate.getValue(), 0, 0);
931 UPDATE_AND_VERIFY(mSnapshotBuilder, traversalOrder);
932 EXPECT_EQ(getSnapshot({.id = 1})->frameRate, FRAME_RATE_NO_VOTE);
933 EXPECT_EQ(getSnapshot({.id = 11})->frameRate, FRAME_RATE_NO_VOTE);
934 EXPECT_EQ(getSnapshot({.id = 111})->frameRate, FRAME_RATE_NO_VOTE);
935}
936
937TEST_F(LayerSnapshotTest, frameRateAddChildForParentWithTreeVote) {
938 setFrameRate(11, FRAME_RATE_VOTE1.vote.rate.getValue(), 0, 0);
939 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
940 EXPECT_EQ(getSnapshot({.id = 1})->frameRate, FRAME_RATE_TREE);
941 EXPECT_EQ(getSnapshot({.id = 11})->frameRate, FRAME_RATE_VOTE1);
942 EXPECT_EQ(getSnapshot({.id = 12})->frameRate, FRAME_RATE_NO_VOTE);
943
944 setFrameRate(11, FRAME_RATE_NO_VOTE.vote.rate.getValue(), 0, 0);
945 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
946 EXPECT_EQ(getSnapshot({.id = 1})->frameRate, FRAME_RATE_NO_VOTE);
947 EXPECT_EQ(getSnapshot({.id = 11})->frameRate, FRAME_RATE_NO_VOTE);
948 EXPECT_EQ(getSnapshot({.id = 12})->frameRate, FRAME_RATE_NO_VOTE);
949}
950
Vishnu Nair3996ee32023-08-14 04:32:31 +0000951TEST_F(LayerSnapshotTest, translateDataspace) {
952 setDataspace(1, ui::Dataspace::UNKNOWN);
953 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
954 EXPECT_EQ(getSnapshot({.id = 1})->dataspace, ui::Dataspace::V0_SRGB);
955}
956
Rachel Leece6e0042023-06-27 11:22:54 -0700957// This test is similar to "frameRate" test case but checks that the setFrameRateCategory API
958// interaction also works correctly with the setFrameRate API within SF frontend.
959TEST_F(LayerSnapshotTest, frameRateWithCategory) {
Rachel Lee45681982024-03-14 18:40:15 -0700960 SET_FLAG_FOR_TEST(flags::frame_rate_category_mrr, true);
961
Rachel Leece6e0042023-06-27 11:22:54 -0700962 // ROOT
963 // ├── 1
964 // │ ├── 11 (frame rate set to 244.f)
965 // │ │ └── 111
966 // │ ├── 12
967 // │ │ ├── 121
968 // │ │ └── 122 (frame rate category set to Normal)
969 // │ │ └── 1221
970 // │ └── 13
971 // └── 2
972 setFrameRate(11, 244.f, 0, 0);
Rachel Lee9580ff12023-12-26 17:33:41 -0800973 setFrameRateCategory(122, ANATIVEWINDOW_FRAME_RATE_CATEGORY_NORMAL);
Rachel Leece6e0042023-06-27 11:22:54 -0700974
975 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
976 // verify parent 1 gets no vote
977 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
978 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700979 scheduler::FrameRateCompatibility::NoVote);
Rachel Leece6e0042023-06-27 11:22:54 -0700980 EXPECT_TRUE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate));
981
982 // verify layer 11 and children 111 get the requested votes
983 EXPECT_TRUE(getSnapshot({.id = 11})->frameRate.vote.rate.isValid());
984 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 244.f);
985 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700986 scheduler::FrameRateCompatibility::Default);
Rachel Leece6e0042023-06-27 11:22:54 -0700987 EXPECT_TRUE(getSnapshot({.id = 11})->changes.test(RequestedLayerState::Changes::FrameRate));
988
989 EXPECT_TRUE(getSnapshot({.id = 111})->frameRate.vote.rate.isValid());
990 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.rate.getValue(), 244.f);
991 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700992 scheduler::FrameRateCompatibility::Default);
Rachel Leece6e0042023-06-27 11:22:54 -0700993 EXPECT_TRUE(getSnapshot({.id = 111})->changes.test(RequestedLayerState::Changes::FrameRate));
994
995 // verify parent 12 gets no vote
996 EXPECT_FALSE(getSnapshot({.id = 12})->frameRate.vote.rate.isValid());
997 EXPECT_EQ(getSnapshot({.id = 12})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700998 scheduler::FrameRateCompatibility::NoVote);
Rachel Leece6e0042023-06-27 11:22:54 -0700999 EXPECT_TRUE(getSnapshot({.id = 12})->changes.test(RequestedLayerState::Changes::FrameRate));
1000
1001 // verify layer 122 and children 1221 get the requested votes
1002 EXPECT_FALSE(getSnapshot({.id = 122})->frameRate.vote.rate.isValid());
1003 EXPECT_TRUE(getSnapshot({.id = 122})->frameRate.isValid());
1004 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -07001005 scheduler::FrameRateCompatibility::Default);
Rachel Leece6e0042023-06-27 11:22:54 -07001006 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.category, FrameRateCategory::Normal);
1007 EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate));
Rachel Lee43369b22023-09-05 18:40:40 -07001008 EXPECT_TRUE(
1009 getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::AffectsChildren));
Rachel Leece6e0042023-06-27 11:22:54 -07001010
1011 EXPECT_FALSE(getSnapshot({.id = 1221})->frameRate.vote.rate.isValid());
1012 EXPECT_TRUE(getSnapshot({.id = 1221})->frameRate.isValid());
1013 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -07001014 scheduler::FrameRateCompatibility::Default);
Rachel Leece6e0042023-06-27 11:22:54 -07001015 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.category, FrameRateCategory::Normal);
1016 EXPECT_TRUE(getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::FrameRate));
Rachel Lee43369b22023-09-05 18:40:40 -07001017 EXPECT_TRUE(
1018 getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::AffectsChildren));
Rachel Leece6e0042023-06-27 11:22:54 -07001019
1020 // reparent and verify the child does NOT get the new parent's framerate because it already has
1021 // the frame rate category specified.
1022 // ROOT
1023 // ├─1
1024 // │ ├─11 (frame rate set to 244.f)
1025 // │ │ ├─111
1026 // │ │ └─122 (frame rate category set to Normal)
1027 // │ │ └─1221
1028 // │ ├─12
1029 // │ │ └─121
1030 // │ └─13
1031 // └─2
1032 reparentLayer(122, 11);
1033
1034 std::vector<uint32_t> expected = {1, 11, 111, 122, 1221, 12, 121, 13, 2};
1035 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
1036 // verify parent is gets no vote
1037 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
1038 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -07001039 scheduler::FrameRateCompatibility::NoVote);
Rachel Leece6e0042023-06-27 11:22:54 -07001040
1041 // verify layer 11 and children 111 get the requested votes
1042 EXPECT_TRUE(getSnapshot({.id = 11})->frameRate.vote.rate.isValid());
1043 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 244.f);
1044 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -07001045 scheduler::FrameRateCompatibility::Default);
Rachel Leece6e0042023-06-27 11:22:54 -07001046
1047 EXPECT_TRUE(getSnapshot({.id = 111})->frameRate.vote.rate.isValid());
1048 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.rate.getValue(), 244.f);
1049 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -07001050 scheduler::FrameRateCompatibility::Default);
Rachel Leece6e0042023-06-27 11:22:54 -07001051
1052 // verify layer 122 and children 1221 get the requested category vote (unchanged from
1053 // reparenting)
1054 EXPECT_FALSE(getSnapshot({.id = 122})->frameRate.vote.rate.isValid());
1055 EXPECT_TRUE(getSnapshot({.id = 122})->frameRate.isValid());
1056 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -07001057 scheduler::FrameRateCompatibility::Default);
Rachel Leece6e0042023-06-27 11:22:54 -07001058 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.category, FrameRateCategory::Normal);
1059 EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate));
1060
1061 EXPECT_FALSE(getSnapshot({.id = 1221})->frameRate.vote.rate.isValid());
1062 EXPECT_TRUE(getSnapshot({.id = 1221})->frameRate.isValid());
1063 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -07001064 scheduler::FrameRateCompatibility::Default);
Rachel Leece6e0042023-06-27 11:22:54 -07001065 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.category, FrameRateCategory::Normal);
1066 EXPECT_TRUE(getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::FrameRate));
1067}
1068
Rachel Lee58cc90d2023-09-05 18:50:20 -07001069TEST_F(LayerSnapshotTest, frameRateSelectionStrategy) {
1070 // ROOT
1071 // ├── 1
1072 // │ ├── 11
1073 // │ │ └── 111
1074 // │ ├── 12 (frame rate set to 244.f with strategy OverrideChildren)
1075 // │ │ ├── 121
1076 // │ │ └── 122 (frame rate set to 123.f but should be overridden by layer 12)
1077 // │ │ └── 1221
1078 // │ └── 13
1079 // └── 2
1080 setFrameRate(12, 244.f, 0, 0);
1081 setFrameRate(122, 123.f, 0, 0);
1082 setFrameRateSelectionStrategy(12, 1 /* OverrideChildren */);
1083
1084 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1085 // verify parent 1 gets no vote
1086 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
1087 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -07001088 scheduler::FrameRateCompatibility::NoVote);
Rachel Lee58cc90d2023-09-05 18:50:20 -07001089 EXPECT_TRUE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate));
1090
1091 // verify layer 12 and all descendants (121, 122, 1221) get the requested vote
1092 EXPECT_EQ(getSnapshot({.id = 12})->frameRate.vote.rate.getValue(), 244.f);
1093 EXPECT_EQ(getSnapshot({.id = 12})->frameRateSelectionStrategy,
1094 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
1095 EXPECT_TRUE(getSnapshot({.id = 12})->changes.test(RequestedLayerState::Changes::FrameRate));
1096
1097 EXPECT_EQ(getSnapshot({.id = 121})->frameRate.vote.rate.getValue(), 244.f);
1098 EXPECT_EQ(getSnapshot({.id = 121})->frameRateSelectionStrategy,
1099 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
1100 EXPECT_TRUE(getSnapshot({.id = 121})->changes.test(RequestedLayerState::Changes::FrameRate));
1101
1102 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.rate.getValue(), 244.f);
1103 EXPECT_EQ(getSnapshot({.id = 122})->frameRateSelectionStrategy,
1104 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
1105 EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate));
1106
1107 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.vote.rate.getValue(), 244.f);
1108 EXPECT_EQ(getSnapshot({.id = 1221})->frameRateSelectionStrategy,
1109 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
1110 EXPECT_TRUE(getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::FrameRate));
Vishnu Nair41376b62023-11-08 05:08:58 -08001111
1112 // ROOT
1113 // ├── 1
1114 // │ ├── 11
1115 // │ │ └── 111
1116 // │ ├── 12 (frame rate set to default with strategy default)
1117 // │ │ ├── 121
1118 // │ │ └── 122 (frame rate set to 123.f)
1119 // │ │ └── 1221
1120 // │ └── 13
1121 // └── 2
1122 setFrameRate(12, -1.f, 0, 0);
1123 setFrameRateSelectionStrategy(12, 0 /* Default */);
1124 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1125 // verify parent 1 gets no vote
1126 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
1127 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
1128 scheduler::FrameRateCompatibility::NoVote);
Vishnu Nair0fd773f2024-08-05 21:16:15 +00001129 EXPECT_TRUE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate));
Vishnu Nair41376b62023-11-08 05:08:58 -08001130
1131 // verify layer 12 and all descendants (121, 122, 1221) get the requested vote
1132 EXPECT_FALSE(getSnapshot({.id = 12})->frameRate.vote.rate.isValid());
1133 EXPECT_EQ(getSnapshot({.id = 12})->frameRate.vote.type,
1134 scheduler::FrameRateCompatibility::NoVote);
1135 EXPECT_EQ(getSnapshot({.id = 12})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -08001136 scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate);
Vishnu Nair41376b62023-11-08 05:08:58 -08001137 EXPECT_TRUE(getSnapshot({.id = 12})->changes.test(RequestedLayerState::Changes::FrameRate));
1138
1139 EXPECT_FALSE(getSnapshot({.id = 121})->frameRate.vote.rate.isValid());
1140 EXPECT_EQ(getSnapshot({.id = 121})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -08001141 scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate);
Vishnu Nair41376b62023-11-08 05:08:58 -08001142 EXPECT_EQ(getSnapshot({.id = 121})->frameRate.vote.type,
1143 scheduler::FrameRateCompatibility::Default);
1144 EXPECT_TRUE(getSnapshot({.id = 121})->changes.test(RequestedLayerState::Changes::FrameRate));
1145
1146 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.rate.getValue(), 123.f);
1147 EXPECT_EQ(getSnapshot({.id = 122})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -08001148 scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate);
Vishnu Nair41376b62023-11-08 05:08:58 -08001149 EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate));
1150
1151 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.vote.rate.getValue(), 123.f);
1152 EXPECT_EQ(getSnapshot({.id = 1221})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -08001153 scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate);
Vishnu Nair41376b62023-11-08 05:08:58 -08001154 EXPECT_TRUE(getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::FrameRate));
1155}
1156
1157TEST_F(LayerSnapshotTest, frameRateSelectionStrategyWithCategory) {
Rachel Lee45681982024-03-14 18:40:15 -07001158 SET_FLAG_FOR_TEST(flags::frame_rate_category_mrr, true);
1159
Vishnu Nair41376b62023-11-08 05:08:58 -08001160 // ROOT
1161 // ├── 1
1162 // │ ├── 11
1163 // │ │ └── 111
1164 // │ ├── 12 (frame rate category set to high with strategy OverrideChildren)
1165 // │ │ ├── 121
1166 // │ │ └── 122 (frame rate set to 123.f but should be overridden by layer 12)
1167 // │ │ └── 1221
1168 // │ └── 13
1169 // └── 2
Rachel Lee9580ff12023-12-26 17:33:41 -08001170 setFrameRateCategory(12, ANATIVEWINDOW_FRAME_RATE_CATEGORY_HIGH);
Vishnu Nair41376b62023-11-08 05:08:58 -08001171 setFrameRate(122, 123.f, 0, 0);
1172 setFrameRateSelectionStrategy(12, 1 /* OverrideChildren */);
1173
1174 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1175 // verify parent 1 gets no vote
1176 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
1177 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
1178 scheduler::FrameRateCompatibility::NoVote);
1179 EXPECT_TRUE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate));
1180
1181 // verify layer 12 and all descendants (121, 122, 1221) get the requested vote
1182 EXPECT_EQ(getSnapshot({.id = 12})->frameRate.category, FrameRateCategory::High);
1183 EXPECT_EQ(getSnapshot({.id = 12})->frameRateSelectionStrategy,
1184 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
1185 EXPECT_TRUE(getSnapshot({.id = 12})->changes.test(RequestedLayerState::Changes::FrameRate));
1186
1187 EXPECT_EQ(getSnapshot({.id = 121})->frameRate.category, FrameRateCategory::High);
1188 EXPECT_EQ(getSnapshot({.id = 121})->frameRateSelectionStrategy,
1189 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
1190 EXPECT_TRUE(getSnapshot({.id = 121})->changes.test(RequestedLayerState::Changes::FrameRate));
1191
1192 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.category, FrameRateCategory::High);
1193 EXPECT_EQ(getSnapshot({.id = 122})->frameRateSelectionStrategy,
1194 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
1195 EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate));
1196
1197 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.category, FrameRateCategory::High);
1198 EXPECT_EQ(getSnapshot({.id = 1221})->frameRateSelectionStrategy,
1199 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
1200 EXPECT_TRUE(getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::FrameRate));
1201
1202 // ROOT
1203 // ├── 1
1204 // │ ├── 11
1205 // │ │ └── 111
1206 // │ ├── 12 (frame rate category to default with strategy default)
1207 // │ │ ├── 121
1208 // │ │ └── 122 (frame rate set to 123.f)
1209 // │ │ └── 1221
1210 // │ └── 13
1211 // └── 2
Rachel Lee9580ff12023-12-26 17:33:41 -08001212 setFrameRateCategory(12, ANATIVEWINDOW_FRAME_RATE_CATEGORY_DEFAULT);
Vishnu Nair41376b62023-11-08 05:08:58 -08001213 setFrameRateSelectionStrategy(12, 0 /* Default */);
1214 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1215 // verify parent 1 gets no vote
1216 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
1217 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
1218 scheduler::FrameRateCompatibility::NoVote);
1219 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.category, FrameRateCategory::Default);
Vishnu Nair0fd773f2024-08-05 21:16:15 +00001220 EXPECT_TRUE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate));
Vishnu Nair41376b62023-11-08 05:08:58 -08001221
1222 // verify layer 12 and all descendants (121, 122, 1221) get the requested vote
1223 EXPECT_FALSE(getSnapshot({.id = 12})->frameRate.vote.rate.isValid());
1224 EXPECT_EQ(getSnapshot({.id = 12})->frameRate.vote.type,
1225 scheduler::FrameRateCompatibility::NoVote);
1226 EXPECT_EQ(getSnapshot({.id = 12})->frameRate.category, FrameRateCategory::Default);
1227 EXPECT_EQ(getSnapshot({.id = 12})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -08001228 scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate);
Vishnu Nair41376b62023-11-08 05:08:58 -08001229 EXPECT_TRUE(getSnapshot({.id = 12})->changes.test(RequestedLayerState::Changes::FrameRate));
1230
1231 EXPECT_FALSE(getSnapshot({.id = 12})->frameRate.vote.rate.isValid());
1232 EXPECT_EQ(getSnapshot({.id = 121})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -08001233 scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate);
Vishnu Nair41376b62023-11-08 05:08:58 -08001234 EXPECT_EQ(getSnapshot({.id = 121})->frameRate.category, FrameRateCategory::Default);
1235 EXPECT_EQ(getSnapshot({.id = 121})->frameRate.vote.type,
1236 scheduler::FrameRateCompatibility::Default);
1237 EXPECT_TRUE(getSnapshot({.id = 121})->changes.test(RequestedLayerState::Changes::FrameRate));
1238
1239 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.rate.getValue(), 123.f);
1240 EXPECT_EQ(getSnapshot({.id = 122})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -08001241 scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate);
Vishnu Nair41376b62023-11-08 05:08:58 -08001242 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.category, FrameRateCategory::Default);
1243 EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate));
1244
1245 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.vote.rate.getValue(), 123.f);
1246 EXPECT_EQ(getSnapshot({.id = 1221})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -08001247 scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate);
Vishnu Nair41376b62023-11-08 05:08:58 -08001248 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.category, FrameRateCategory::Default);
1249 EXPECT_TRUE(getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::FrameRate));
Rachel Lee58cc90d2023-09-05 18:50:20 -07001250}
1251
Rachel Lee70f7b692023-11-22 11:24:02 -08001252TEST_F(LayerSnapshotTest, frameRateSelectionStrategyWithOverrideChildrenAndSelf) {
Rachel Leea021bb02023-11-20 21:51:09 -08001253 // ROOT
1254 // ├── 1
Rachel Lee70f7b692023-11-22 11:24:02 -08001255 // │ ├── 11 (frame rate set to 11.f with strategy Self)
Rachel Leea021bb02023-11-20 21:51:09 -08001256 // │ │ └── 111 (frame rate is not inherited)
1257 // │ ├── 12 (frame rate set to 244.f)
1258 // │ │ ├── 121
1259 // │ │ └── 122 (strategy OverrideChildren and inherits frame rate 244.f)
1260 // │ │ └── 1221 (frame rate set to 123.f but should be overridden by layer 122)
1261 // │ └── 13
1262 // └── 2
1263 setFrameRate(11, 11.f, 0, 0);
Rachel Lee70f7b692023-11-22 11:24:02 -08001264 setFrameRateSelectionStrategy(11, 2 /* Self */);
Rachel Leea021bb02023-11-20 21:51:09 -08001265 setFrameRate(12, 244.f, 0, 0);
1266 setFrameRateSelectionStrategy(122, 1 /* OverrideChildren */);
1267 setFrameRate(1221, 123.f, 0, 0);
1268
1269 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1270 // verify parent 1 gets no vote
1271 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
1272 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
1273 scheduler::FrameRateCompatibility::NoVote);
1274 EXPECT_EQ(getSnapshot({.id = 1})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -08001275 scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate);
Rachel Leea021bb02023-11-20 21:51:09 -08001276 EXPECT_TRUE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate));
1277
1278 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 11.f);
1279 EXPECT_EQ(getSnapshot({.id = 11})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -08001280 scheduler::LayerInfo::FrameRateSelectionStrategy::Self);
Rachel Leea021bb02023-11-20 21:51:09 -08001281 EXPECT_TRUE(getSnapshot({.id = 11})->changes.test(RequestedLayerState::Changes::FrameRate));
1282
1283 // verify layer 11 does does not propagate its framerate to 111.
1284 EXPECT_FALSE(getSnapshot({.id = 111})->frameRate.vote.rate.isValid());
1285 EXPECT_EQ(getSnapshot({.id = 111})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -08001286 scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate);
Rachel Leea021bb02023-11-20 21:51:09 -08001287 EXPECT_TRUE(getSnapshot({.id = 111})->changes.test(RequestedLayerState::Changes::FrameRate));
1288
1289 // verify layer 12 and all descendants (121, 122, 1221) get the requested vote
1290 EXPECT_EQ(getSnapshot({.id = 12})->frameRate.vote.rate.getValue(), 244.f);
1291 EXPECT_EQ(getSnapshot({.id = 12})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -08001292 scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate);
Rachel Leea021bb02023-11-20 21:51:09 -08001293 EXPECT_TRUE(getSnapshot({.id = 12})->changes.test(RequestedLayerState::Changes::FrameRate));
1294
1295 EXPECT_EQ(getSnapshot({.id = 121})->frameRate.vote.rate.getValue(), 244.f);
1296 EXPECT_EQ(getSnapshot({.id = 121})->frameRateSelectionStrategy,
Rachel Lee70f7b692023-11-22 11:24:02 -08001297 scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate);
Rachel Leea021bb02023-11-20 21:51:09 -08001298 EXPECT_TRUE(getSnapshot({.id = 121})->changes.test(RequestedLayerState::Changes::FrameRate));
1299
1300 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.rate.getValue(), 244.f);
1301 EXPECT_EQ(getSnapshot({.id = 122})->frameRateSelectionStrategy,
1302 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
1303 EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate));
1304
1305 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.vote.rate.getValue(), 244.f);
1306 EXPECT_EQ(getSnapshot({.id = 1221})->frameRateSelectionStrategy,
1307 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
1308 EXPECT_TRUE(getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::FrameRate));
1309
1310 // ROOT
1311 // ├── 1 (frame rate set to 1.f with strategy OverrideChildren)
Rachel Lee70f7b692023-11-22 11:24:02 -08001312 // │ ├── 11 (frame rate set to 11.f with strategy Self, but overridden by 1)
Rachel Leea021bb02023-11-20 21:51:09 -08001313 // │ │ └── 111 (frame rate inherited from 11 due to override from 1)
1314 // â‹® â‹®
1315 setFrameRate(1, 1.f, 0, 0);
1316 setFrameRateSelectionStrategy(1, 1 /* OverrideChildren */);
1317 setFrameRate(11, 11.f, 0, 0);
Rachel Lee70f7b692023-11-22 11:24:02 -08001318 setFrameRateSelectionStrategy(11, 2 /* Self */);
Rachel Leea021bb02023-11-20 21:51:09 -08001319 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1320
1321 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.rate.getValue(), 1.f);
1322 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
1323 scheduler::FrameRateCompatibility::Default);
1324 EXPECT_EQ(getSnapshot({.id = 1})->frameRateSelectionStrategy,
1325 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
1326 EXPECT_TRUE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate));
1327
1328 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 1.f);
1329 EXPECT_EQ(getSnapshot({.id = 11})->frameRateSelectionStrategy,
1330 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
1331 EXPECT_TRUE(getSnapshot({.id = 11})->changes.test(RequestedLayerState::Changes::FrameRate));
1332
1333 // verify layer 11 does does not propagate its framerate to 111.
1334 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.rate.getValue(), 1.f);
1335 EXPECT_EQ(getSnapshot({.id = 111})->frameRateSelectionStrategy,
1336 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
1337 EXPECT_TRUE(getSnapshot({.id = 111})->changes.test(RequestedLayerState::Changes::FrameRate));
1338}
1339
Vishnu Nair0808ae62023-08-07 21:42:42 -07001340TEST_F(LayerSnapshotTest, skipRoundCornersWhenProtected) {
1341 setRoundedCorners(1, 42.f);
1342 setRoundedCorners(2, 42.f);
1343 setCrop(1, Rect{1000, 1000});
1344 setCrop(2, Rect{1000, 1000});
1345
1346 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1347 EXPECT_TRUE(getSnapshot({.id = 1})->roundedCorner.hasRoundedCorners());
1348 EXPECT_EQ(getSnapshot({.id = 1})->roundedCorner.radius.x, 42.f);
1349 EXPECT_TRUE(getSnapshot({.id = 2})->roundedCorner.hasRoundedCorners());
1350
1351 // add a buffer with the protected bit, check rounded corners are not set when
1352 // skipRoundCornersWhenProtected == true
1353 setBuffer(1,
1354 std::make_shared<
1355 renderengine::mock::FakeExternalTexture>(1U /*width*/, 1U /*height*/,
1356 1ULL /* bufferId */,
1357 HAL_PIXEL_FORMAT_RGBA_8888,
1358 GRALLOC_USAGE_PROTECTED /*usage*/));
1359
1360 LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(),
1361 .layerLifecycleManager = mLifecycleManager,
1362 .includeMetadata = false,
1363 .displays = mFrontEndDisplayInfos,
1364 .displayChanges = false,
1365 .globalShadowSettings = globalShadowSettings,
1366 .supportsBlur = true,
1367 .supportedLayerGenericMetadata = {},
1368 .genericLayerMetadataKeyMap = {},
1369 .skipRoundCornersWhenProtected = true};
1370 update(mSnapshotBuilder, args);
1371 EXPECT_FALSE(getSnapshot({.id = 1})->roundedCorner.hasRoundedCorners());
1372 // layer 2 doesn't have a buffer and should be unaffected
1373 EXPECT_TRUE(getSnapshot({.id = 2})->roundedCorner.hasRoundedCorners());
1374
1375 // remove protected bit, check rounded corners are set
1376 setBuffer(1,
1377 std::make_shared<renderengine::mock::FakeExternalTexture>(1U /*width*/, 1U /*height*/,
1378 2ULL /* bufferId */,
1379 HAL_PIXEL_FORMAT_RGBA_8888,
1380 0 /*usage*/));
1381 update(mSnapshotBuilder, args);
1382 EXPECT_TRUE(getSnapshot({.id = 1})->roundedCorner.hasRoundedCorners());
1383 EXPECT_EQ(getSnapshot({.id = 1})->roundedCorner.radius.x, 42.f);
1384}
1385
Vishnu Nairbd51f952023-08-31 22:50:14 -07001386TEST_F(LayerSnapshotTest, setRefreshRateIndicatorCompositionType) {
1387 setFlags(1, layer_state_t::eLayerIsRefreshRateIndicator,
1388 layer_state_t::eLayerIsRefreshRateIndicator);
1389 setBuffer(1,
1390 std::make_shared<renderengine::mock::FakeExternalTexture>(1U /*width*/, 1U /*height*/,
1391 42ULL /* bufferId */,
1392 HAL_PIXEL_FORMAT_RGBA_8888,
1393 0 /*usage*/));
1394 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1395 EXPECT_EQ(getSnapshot({.id = 1})->compositionType,
1396 aidl::android::hardware::graphics::composer3::Composition::REFRESH_RATE_INDICATOR);
1397}
1398
Chavi Weingarten07597342023-09-14 21:10:59 +00001399TEST_F(LayerSnapshotTest, setBufferCrop) {
1400 // validate no buffer but has crop
1401 Rect crop = Rect(0, 0, 50, 50);
1402 setBufferCrop(1, crop);
1403 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1404 EXPECT_EQ(getSnapshot(1)->geomContentCrop, crop);
1405
1406 setBuffer(1,
1407 std::make_shared<renderengine::mock::FakeExternalTexture>(100U /*width*/,
1408 100U /*height*/,
1409 42ULL /* bufferId */,
1410 HAL_PIXEL_FORMAT_RGBA_8888,
1411 0 /*usage*/));
1412 // validate a buffer crop within the buffer bounds
1413 setBufferCrop(1, crop);
1414 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1415 EXPECT_EQ(getSnapshot(1)->geomContentCrop, crop);
1416
1417 // validate a buffer crop outside the buffer bounds
1418 crop = Rect(0, 0, 150, 150);
1419 setBufferCrop(1, crop);
1420 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1421 EXPECT_EQ(getSnapshot(1)->geomContentCrop, Rect(0, 0, 100, 100));
1422
1423 // validate no buffer crop
1424 setBufferCrop(1, Rect());
1425 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1426 EXPECT_EQ(getSnapshot(1)->geomContentCrop, Rect(0, 0, 100, 100));
1427}
Vishnu Nairbefd3e22023-10-05 17:48:31 +00001428
1429TEST_F(LayerSnapshotTest, setShadowRadius) {
1430 static constexpr float SHADOW_RADIUS = 123.f;
1431 setShadowRadius(1, SHADOW_RADIUS);
1432 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1433 EXPECT_EQ(getSnapshot(1)->shadowSettings.length, SHADOW_RADIUS);
Vishnu Nairbefd3e22023-10-05 17:48:31 +00001434}
1435
Chavi Weingartenb74093a2023-10-11 20:29:59 +00001436TEST_F(LayerSnapshotTest, setTrustedOverlayForNonVisibleInput) {
1437 hideLayer(1);
Vishnu Nair9e0017e2024-05-22 19:02:44 +00001438 setTrustedOverlay(1, gui::TrustedOverlay::ENABLED);
Chavi Weingartenb74093a2023-10-11 20:29:59 +00001439 Region touch{Rect{0, 0, 1000, 1000}};
1440 setTouchableRegion(1, touch);
1441
1442 UPDATE_AND_VERIFY(mSnapshotBuilder, {2});
1443 EXPECT_TRUE(getSnapshot(1)->inputInfo.inputConfig.test(
1444 gui::WindowInfo::InputConfig::TRUSTED_OVERLAY));
1445}
1446
Vishnu Nairab942862024-06-13 22:59:06 -07001447TEST_F(LayerSnapshotTest, alphaChangesPropagateToInput) {
1448 Region touch{Rect{0, 0, 1000, 1000}};
1449 setTouchableRegion(1, touch);
1450 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1451
1452 setAlpha(1, 0.5f);
1453 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1454 EXPECT_EQ(getSnapshot(1)->inputInfo.alpha, 0.5f);
1455}
1456
Alec Mouri89f5d4e2023-10-20 17:12:49 +00001457TEST_F(LayerSnapshotTest, isFrontBuffered) {
1458 setBuffer(1,
1459 std::make_shared<renderengine::mock::FakeExternalTexture>(
1460 1U /*width*/, 1U /*height*/, 1ULL /* bufferId */, HAL_PIXEL_FORMAT_RGBA_8888,
1461 GRALLOC_USAGE_HW_TEXTURE | AHARDWAREBUFFER_USAGE_FRONT_BUFFER /*usage*/));
1462
1463 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1464 EXPECT_TRUE(getSnapshot(1)->isFrontBuffered());
1465
1466 setBuffer(1,
1467 std::make_shared<
1468 renderengine::mock::FakeExternalTexture>(1U /*width*/, 1U /*height*/,
1469 1ULL /* bufferId */,
1470 HAL_PIXEL_FORMAT_RGBA_8888,
1471 GRALLOC_USAGE_HW_TEXTURE /*usage*/));
1472
1473 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1474 EXPECT_FALSE(getSnapshot(1)->isFrontBuffered());
1475}
1476
Chavi Weingarten4aa22af2023-11-17 19:37:07 +00001477TEST_F(LayerSnapshotTest, setSecureRootSnapshot) {
1478 setFlags(1, layer_state_t::eLayerSecure, layer_state_t::eLayerSecure);
1479 LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(),
1480 .layerLifecycleManager = mLifecycleManager,
1481 .includeMetadata = false,
1482 .displays = mFrontEndDisplayInfos,
1483 .displayChanges = false,
1484 .globalShadowSettings = globalShadowSettings,
1485 .supportsBlur = true,
1486 .supportedLayerGenericMetadata = {},
1487 .genericLayerMetadataKeyMap = {}};
1488 args.rootSnapshot.isSecure = true;
1489 update(mSnapshotBuilder, args);
1490
1491 EXPECT_TRUE(getSnapshot(1)->isSecure);
1492 // Ensure child is also marked as secure
1493 EXPECT_TRUE(getSnapshot(11)->isSecure);
1494}
1495
Prabir Pradhancf359192024-03-20 00:42:57 +00001496TEST_F(LayerSnapshotTest, setSensitiveForTracingConfigForSecureLayers) {
1497 setFlags(11, layer_state_t::eLayerSecure, layer_state_t::eLayerSecure);
1498
1499 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1500
1501 EXPECT_TRUE(getSnapshot(11)->inputInfo.inputConfig.test(
Arpit Singh490ccc92024-04-30 14:26:21 +00001502 gui::WindowInfo::InputConfig::SENSITIVE_FOR_PRIVACY));
Prabir Pradhancf359192024-03-20 00:42:57 +00001503 EXPECT_TRUE(getSnapshot(111)->inputInfo.inputConfig.test(
Arpit Singh490ccc92024-04-30 14:26:21 +00001504 gui::WindowInfo::InputConfig::SENSITIVE_FOR_PRIVACY));
Prabir Pradhancf359192024-03-20 00:42:57 +00001505 EXPECT_FALSE(getSnapshot(1)->inputInfo.inputConfig.test(
Arpit Singh490ccc92024-04-30 14:26:21 +00001506 gui::WindowInfo::InputConfig::SENSITIVE_FOR_PRIVACY));
Prabir Pradhancf359192024-03-20 00:42:57 +00001507 EXPECT_FALSE(getSnapshot(12)->inputInfo.inputConfig.test(
Arpit Singh490ccc92024-04-30 14:26:21 +00001508 gui::WindowInfo::InputConfig::SENSITIVE_FOR_PRIVACY));
Prabir Pradhancf359192024-03-20 00:42:57 +00001509 EXPECT_FALSE(getSnapshot(2)->inputInfo.inputConfig.test(
Arpit Singh490ccc92024-04-30 14:26:21 +00001510 gui::WindowInfo::InputConfig::SENSITIVE_FOR_PRIVACY));
Prabir Pradhancf359192024-03-20 00:42:57 +00001511}
1512
1513TEST_F(LayerSnapshotTest, setSensitiveForTracingFromInputWindowHandle) {
1514 setInputInfo(11, [](auto& inputInfo) {
Arpit Singh490ccc92024-04-30 14:26:21 +00001515 inputInfo.inputConfig |= gui::WindowInfo::InputConfig::SENSITIVE_FOR_PRIVACY;
Prabir Pradhancf359192024-03-20 00:42:57 +00001516 });
1517
1518 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1519
1520 EXPECT_TRUE(getSnapshot(11)->inputInfo.inputConfig.test(
Arpit Singh490ccc92024-04-30 14:26:21 +00001521 gui::WindowInfo::InputConfig::SENSITIVE_FOR_PRIVACY));
Prabir Pradhancf359192024-03-20 00:42:57 +00001522 EXPECT_TRUE(getSnapshot(111)->inputInfo.inputConfig.test(
Arpit Singh490ccc92024-04-30 14:26:21 +00001523 gui::WindowInfo::InputConfig::SENSITIVE_FOR_PRIVACY));
Prabir Pradhancf359192024-03-20 00:42:57 +00001524 EXPECT_FALSE(getSnapshot(1)->inputInfo.inputConfig.test(
Arpit Singh490ccc92024-04-30 14:26:21 +00001525 gui::WindowInfo::InputConfig::SENSITIVE_FOR_PRIVACY));
Prabir Pradhancf359192024-03-20 00:42:57 +00001526 EXPECT_FALSE(getSnapshot(12)->inputInfo.inputConfig.test(
Arpit Singh490ccc92024-04-30 14:26:21 +00001527 gui::WindowInfo::InputConfig::SENSITIVE_FOR_PRIVACY));
Prabir Pradhancf359192024-03-20 00:42:57 +00001528 EXPECT_FALSE(getSnapshot(2)->inputInfo.inputConfig.test(
Arpit Singh490ccc92024-04-30 14:26:21 +00001529 gui::WindowInfo::InputConfig::SENSITIVE_FOR_PRIVACY));
Prabir Pradhancf359192024-03-20 00:42:57 +00001530}
1531
Vishnu Nairf13c8982023-12-02 11:26:09 -08001532// b/314350323
1533TEST_F(LayerSnapshotTest, propagateDropInputMode) {
1534 setDropInputMode(1, gui::DropInputMode::ALL);
1535 LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(),
1536 .layerLifecycleManager = mLifecycleManager,
1537 .includeMetadata = false,
1538 .displays = mFrontEndDisplayInfos,
1539 .displayChanges = false,
1540 .globalShadowSettings = globalShadowSettings,
1541 .supportsBlur = true,
1542 .supportedLayerGenericMetadata = {},
1543 .genericLayerMetadataKeyMap = {}};
1544 args.rootSnapshot.isSecure = true;
1545 update(mSnapshotBuilder, args);
1546
1547 EXPECT_EQ(getSnapshot(1)->dropInputMode, gui::DropInputMode::ALL);
1548 // Ensure child also has the correct drop input mode regardless of whether either layer has
1549 // an input channel
1550 EXPECT_EQ(getSnapshot(11)->dropInputMode, gui::DropInputMode::ALL);
1551}
1552
Chavi Weingarten92c7d8c2024-01-19 23:25:45 +00001553TEST_F(LayerSnapshotTest, NonVisibleLayerWithInput) {
1554 LayerHierarchyTestBase::createRootLayer(3);
1555 setColor(3, {-1._hf, -1._hf, -1._hf});
1556 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1557
1558 std::vector<TransactionState> transactions;
1559 transactions.emplace_back();
1560 transactions.back().states.push_back({});
1561 transactions.back().states.front().state.what = layer_state_t::eInputInfoChanged;
1562 transactions.back().states.front().layerId = 3;
1563 transactions.back().states.front().state.windowInfoHandle = sp<gui::WindowInfoHandle>::make();
1564 auto inputInfo = transactions.back().states.front().state.windowInfoHandle->editInfo();
1565 inputInfo->token = sp<BBinder>::make();
1566 mLifecycleManager.applyTransactions(transactions);
1567
1568 update(mSnapshotBuilder);
1569
1570 bool foundInputLayer = false;
1571 mSnapshotBuilder.forEachInputSnapshot([&](const frontend::LayerSnapshot& snapshot) {
1572 if (snapshot.uniqueSequence == 3) {
1573 foundInputLayer = true;
1574 }
1575 });
1576 EXPECT_TRUE(foundInputLayer);
1577}
1578
Nergi Rahardi0dfc0962024-05-23 06:57:36 +00001579TEST_F(LayerSnapshotTest, ForEachSnapshotsWithPredicate) {
1580 std::vector<uint32_t> visitedUniqueSequences;
1581 mSnapshotBuilder.forEachSnapshot(
1582 [&](const std::unique_ptr<frontend::LayerSnapshot>& snapshot) {
1583 visitedUniqueSequences.push_back(snapshot->uniqueSequence);
1584 },
1585 [](const frontend::LayerSnapshot& snapshot) { return snapshot.uniqueSequence == 111; });
1586 EXPECT_EQ(visitedUniqueSequences.size(), 1u);
1587 EXPECT_EQ(visitedUniqueSequences[0], 111u);
1588}
1589
Vishnu Nair59a6be32024-01-29 10:26:21 -08001590TEST_F(LayerSnapshotTest, canOccludePresentation) {
1591 setFlags(12, layer_state_t::eCanOccludePresentation, layer_state_t::eCanOccludePresentation);
1592 LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(),
1593 .layerLifecycleManager = mLifecycleManager,
1594 .includeMetadata = false,
1595 .displays = mFrontEndDisplayInfos,
1596 .displayChanges = false,
1597 .globalShadowSettings = globalShadowSettings,
1598 .supportsBlur = true,
1599 .supportedLayerGenericMetadata = {},
1600 .genericLayerMetadataKeyMap = {}};
1601 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1602
1603 EXPECT_EQ(getSnapshot(1)->inputInfo.canOccludePresentation, false);
1604
1605 // ensure we can set the property on the window info for layer and all its children
1606 EXPECT_EQ(getSnapshot(12)->inputInfo.canOccludePresentation, true);
1607 EXPECT_EQ(getSnapshot(121)->inputInfo.canOccludePresentation, true);
1608 EXPECT_EQ(getSnapshot(1221)->inputInfo.canOccludePresentation, true);
1609}
1610
Vishnu Nair491827d2024-04-29 23:43:26 +00001611TEST_F(LayerSnapshotTest, mirroredHierarchyIgnoresLocalTransform) {
1612 SET_FLAG_FOR_TEST(flags::detached_mirror, true);
1613 reparentLayer(12, UNASSIGNED_LAYER_ID);
1614 setPosition(11, 2, 20);
1615 setPosition(111, 20, 200);
1616 mirrorLayer(/*layer*/ 14, /*parent*/ 1, /*layerToMirror*/ 11);
1617 std::vector<uint32_t> expected = {1, 11, 111, 13, 14, 11, 111, 2};
1618 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
1619
1620 // mirror root has no position set
1621 EXPECT_EQ(getSnapshot({.id = 11, .mirrorRootIds = 14u})->localTransform.tx(), 0);
1622 EXPECT_EQ(getSnapshot({.id = 11, .mirrorRootIds = 14u})->localTransform.ty(), 0);
1623 // original root still has a position
1624 EXPECT_EQ(getSnapshot({.id = 11})->localTransform.tx(), 2);
1625 EXPECT_EQ(getSnapshot({.id = 11})->localTransform.ty(), 20);
1626
1627 // mirror child still has the correct position
1628 EXPECT_EQ(getSnapshot({.id = 111, .mirrorRootIds = 14u})->localTransform.tx(), 20);
1629 EXPECT_EQ(getSnapshot({.id = 111, .mirrorRootIds = 14u})->localTransform.ty(), 200);
1630 EXPECT_EQ(getSnapshot({.id = 111, .mirrorRootIds = 14u})->geomLayerTransform.tx(), 20);
1631 EXPECT_EQ(getSnapshot({.id = 111, .mirrorRootIds = 14u})->geomLayerTransform.ty(), 200);
1632
1633 // original child still has the correct position including its parent's position
1634 EXPECT_EQ(getSnapshot({.id = 111})->localTransform.tx(), 20);
1635 EXPECT_EQ(getSnapshot({.id = 111})->localTransform.ty(), 200);
1636 EXPECT_EQ(getSnapshot({.id = 111})->geomLayerTransform.tx(), 22);
1637 EXPECT_EQ(getSnapshot({.id = 111})->geomLayerTransform.ty(), 220);
1638}
1639
Vishnu Nair9e0017e2024-05-22 19:02:44 +00001640TEST_F(LayerSnapshotTest, overrideParentTrustedOverlayState) {
1641 SET_FLAG_FOR_TEST(flags::override_trusted_overlay, true);
1642 hideLayer(1);
1643 setTrustedOverlay(1, gui::TrustedOverlay::ENABLED);
1644
1645 Region touch{Rect{0, 0, 1000, 1000}};
1646 setTouchableRegion(1, touch);
1647 setTouchableRegion(11, touch);
1648 setTouchableRegion(111, touch);
1649
1650 UPDATE_AND_VERIFY(mSnapshotBuilder, {2});
1651 EXPECT_TRUE(getSnapshot(1)->inputInfo.inputConfig.test(
1652 gui::WindowInfo::InputConfig::TRUSTED_OVERLAY));
1653 EXPECT_TRUE(getSnapshot(11)->inputInfo.inputConfig.test(
1654 gui::WindowInfo::InputConfig::TRUSTED_OVERLAY));
1655 EXPECT_TRUE(getSnapshot(111)->inputInfo.inputConfig.test(
1656 gui::WindowInfo::InputConfig::TRUSTED_OVERLAY));
1657
1658 // disable trusted overlay and override parent state
1659 setTrustedOverlay(11, gui::TrustedOverlay::DISABLED);
1660 UPDATE_AND_VERIFY(mSnapshotBuilder, {2});
1661 EXPECT_TRUE(getSnapshot(1)->inputInfo.inputConfig.test(
1662 gui::WindowInfo::InputConfig::TRUSTED_OVERLAY));
1663 EXPECT_FALSE(getSnapshot(11)->inputInfo.inputConfig.test(
1664 gui::WindowInfo::InputConfig::TRUSTED_OVERLAY));
1665 EXPECT_FALSE(getSnapshot(111)->inputInfo.inputConfig.test(
1666 gui::WindowInfo::InputConfig::TRUSTED_OVERLAY));
1667
1668 // unset state and go back to default behavior of inheriting
1669 // state
1670 setTrustedOverlay(11, gui::TrustedOverlay::UNSET);
1671 UPDATE_AND_VERIFY(mSnapshotBuilder, {2});
1672 EXPECT_TRUE(getSnapshot(1)->inputInfo.inputConfig.test(
1673 gui::WindowInfo::InputConfig::TRUSTED_OVERLAY));
1674 EXPECT_TRUE(getSnapshot(11)->inputInfo.inputConfig.test(
1675 gui::WindowInfo::InputConfig::TRUSTED_OVERLAY));
1676 EXPECT_TRUE(getSnapshot(111)->inputInfo.inputConfig.test(
1677 gui::WindowInfo::InputConfig::TRUSTED_OVERLAY));
1678}
1679
1680TEST_F(LayerSnapshotTest, doNotOverrideParentTrustedOverlayState) {
1681 SET_FLAG_FOR_TEST(flags::override_trusted_overlay, false);
1682 hideLayer(1);
1683 setTrustedOverlay(1, gui::TrustedOverlay::ENABLED);
1684
1685 Region touch{Rect{0, 0, 1000, 1000}};
1686 setTouchableRegion(1, touch);
1687 setTouchableRegion(11, touch);
1688 setTouchableRegion(111, touch);
1689
1690 UPDATE_AND_VERIFY(mSnapshotBuilder, {2});
1691 EXPECT_TRUE(getSnapshot(1)->inputInfo.inputConfig.test(
1692 gui::WindowInfo::InputConfig::TRUSTED_OVERLAY));
1693 EXPECT_TRUE(getSnapshot(11)->inputInfo.inputConfig.test(
1694 gui::WindowInfo::InputConfig::TRUSTED_OVERLAY));
1695 EXPECT_TRUE(getSnapshot(111)->inputInfo.inputConfig.test(
1696 gui::WindowInfo::InputConfig::TRUSTED_OVERLAY));
1697
1698 // disable trusted overlay but flag is disabled so this behaves
1699 // as UNSET
1700 setTrustedOverlay(11, gui::TrustedOverlay::DISABLED);
1701 UPDATE_AND_VERIFY(mSnapshotBuilder, {2});
1702 EXPECT_TRUE(getSnapshot(1)->inputInfo.inputConfig.test(
1703 gui::WindowInfo::InputConfig::TRUSTED_OVERLAY));
1704 EXPECT_TRUE(getSnapshot(11)->inputInfo.inputConfig.test(
1705 gui::WindowInfo::InputConfig::TRUSTED_OVERLAY));
1706 EXPECT_TRUE(getSnapshot(111)->inputInfo.inputConfig.test(
1707 gui::WindowInfo::InputConfig::TRUSTED_OVERLAY));
1708
1709 // unset state and go back to default behavior of inheriting
1710 // state
1711 setTrustedOverlay(11, gui::TrustedOverlay::UNSET);
1712 UPDATE_AND_VERIFY(mSnapshotBuilder, {2});
1713 EXPECT_TRUE(getSnapshot(1)->inputInfo.inputConfig.test(
1714 gui::WindowInfo::InputConfig::TRUSTED_OVERLAY));
1715 EXPECT_TRUE(getSnapshot(11)->inputInfo.inputConfig.test(
1716 gui::WindowInfo::InputConfig::TRUSTED_OVERLAY));
1717 EXPECT_TRUE(getSnapshot(111)->inputInfo.inputConfig.test(
1718 gui::WindowInfo::InputConfig::TRUSTED_OVERLAY));
1719}
1720
Vishnu Nair384ba8a2024-07-25 20:41:17 -07001721static constexpr const FloatRect LARGE_FLOAT_RECT{std::numeric_limits<float>::min(),
1722 std::numeric_limits<float>::min(),
1723 std::numeric_limits<float>::max(),
1724 std::numeric_limits<float>::max()};
1725TEST_F(LayerSnapshotTest, layerVisibleByDefault) {
1726 DisplayInfo info;
1727 info.info.logicalHeight = 1000000;
1728 info.info.logicalWidth = 1000000;
1729 mFrontEndDisplayInfos.emplace_or_replace(ui::LayerStack::fromValue(1), info);
1730 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1731 EXPECT_FALSE(getSnapshot(1)->isHiddenByPolicy());
1732}
1733
1734TEST_F(LayerSnapshotTest, hideLayerWithZeroMatrix) {
1735 DisplayInfo info;
1736 info.info.logicalHeight = 1000000;
1737 info.info.logicalWidth = 1000000;
1738 mFrontEndDisplayInfos.emplace_or_replace(ui::LayerStack::fromValue(1), info);
1739 setMatrix(1, 0.f, 0.f, 0.f, 0.f);
1740 UPDATE_AND_VERIFY(mSnapshotBuilder, {2});
1741 EXPECT_TRUE(getSnapshot(1)->isHiddenByPolicy());
1742}
1743
1744TEST_F(LayerSnapshotTest, hideLayerWithInfMatrix) {
1745 DisplayInfo info;
1746 info.info.logicalHeight = 1000000;
1747 info.info.logicalWidth = 1000000;
1748 mFrontEndDisplayInfos.emplace_or_replace(ui::LayerStack::fromValue(1), info);
1749 setMatrix(1, std::numeric_limits<float>::infinity(), 0.f, 0.f,
1750 std::numeric_limits<float>::infinity());
1751 UPDATE_AND_VERIFY(mSnapshotBuilder, {2});
1752 EXPECT_TRUE(getSnapshot(1)->isHiddenByPolicy());
1753}
1754
1755TEST_F(LayerSnapshotTest, hideLayerWithNanMatrix) {
1756 DisplayInfo info;
1757 info.info.logicalHeight = 1000000;
1758 info.info.logicalWidth = 1000000;
1759 mFrontEndDisplayInfos.emplace_or_replace(ui::LayerStack::fromValue(1), info);
1760 setMatrix(1, std::numeric_limits<float>::quiet_NaN(), 0.f, 0.f,
1761 std::numeric_limits<float>::quiet_NaN());
1762 UPDATE_AND_VERIFY(mSnapshotBuilder, {2});
1763 EXPECT_TRUE(getSnapshot(1)->isHiddenByPolicy());
1764}
Marzia Favaroa7632662024-05-24 16:42:54 +00001765TEST_F(LayerSnapshotTest, edgeExtensionPropagatesInHierarchy) {
1766 if (!com::android::graphics::libgui::flags::edge_extension_shader()) {
1767 GTEST_SKIP() << "Skipping test because edge_extension_shader is off";
1768 }
1769 setCrop(1, Rect(0, 0, 20, 20));
1770 setBuffer(1221,
1771 std::make_shared<renderengine::mock::FakeExternalTexture>(20 /* width */,
1772 20 /* height */,
1773 42ULL /* bufferId */,
1774 HAL_PIXEL_FORMAT_RGBA_8888,
1775 0 /*usage*/));
1776 setEdgeExtensionEffect(12, LEFT);
1777 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1778
1779 EXPECT_TRUE(getSnapshot({.id = 12})->edgeExtensionEffect.extendsEdge(LEFT));
1780 EXPECT_TRUE(getSnapshot({.id = 121})->edgeExtensionEffect.extendsEdge(LEFT));
1781 EXPECT_TRUE(getSnapshot({.id = 1221})->edgeExtensionEffect.extendsEdge(LEFT));
1782
1783 setEdgeExtensionEffect(12, RIGHT);
1784 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1785
1786 EXPECT_TRUE(getSnapshot({.id = 12})->edgeExtensionEffect.extendsEdge(RIGHT));
1787 EXPECT_TRUE(getSnapshot({.id = 121})->edgeExtensionEffect.extendsEdge(RIGHT));
1788 EXPECT_TRUE(getSnapshot({.id = 1221})->edgeExtensionEffect.extendsEdge(RIGHT));
1789
1790 setEdgeExtensionEffect(12, TOP);
1791 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1792
1793 EXPECT_TRUE(getSnapshot({.id = 12})->edgeExtensionEffect.extendsEdge(TOP));
1794 EXPECT_TRUE(getSnapshot({.id = 121})->edgeExtensionEffect.extendsEdge(TOP));
1795 EXPECT_TRUE(getSnapshot({.id = 1221})->edgeExtensionEffect.extendsEdge(TOP));
1796
1797 setEdgeExtensionEffect(12, BOTTOM);
1798 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1799
1800 EXPECT_TRUE(getSnapshot({.id = 12})->edgeExtensionEffect.extendsEdge(BOTTOM));
1801 EXPECT_TRUE(getSnapshot({.id = 121})->edgeExtensionEffect.extendsEdge(BOTTOM));
1802 EXPECT_TRUE(getSnapshot({.id = 1221})->edgeExtensionEffect.extendsEdge(BOTTOM));
1803}
1804
1805TEST_F(LayerSnapshotTest, leftEdgeExtensionIncreaseBoundSizeWithinCrop) {
1806 // The left bound is extended when shifting to the right
1807 if (!com::android::graphics::libgui::flags::edge_extension_shader()) {
1808 GTEST_SKIP() << "Skipping test because edge_extension_shader is off";
1809 }
1810 setCrop(1, Rect(0, 0, 20, 20));
1811 const int texSize = 10;
1812 setBuffer(1221,
1813 std::make_shared<renderengine::mock::FakeExternalTexture>(texSize /* width */,
1814 texSize /* height*/,
1815 42ULL /* bufferId */,
1816 HAL_PIXEL_FORMAT_RGBA_8888,
1817 0 /*usage*/));
1818 const float translation = 5.0;
1819 setPosition(12, translation, 0);
1820 setEdgeExtensionEffect(12, LEFT);
1821 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1822 EXPECT_EQ(getSnapshot({.id = 1221})->transformedBounds.right, texSize + translation);
1823 EXPECT_LT(getSnapshot({.id = 1221})->transformedBounds.left, translation);
1824 EXPECT_GE(getSnapshot({.id = 1221})->transformedBounds.left, 0.0);
1825}
1826
1827TEST_F(LayerSnapshotTest, rightEdgeExtensionIncreaseBoundSizeWithinCrop) {
1828 // The right bound is extended when shifting to the left
1829 if (!com::android::graphics::libgui::flags::edge_extension_shader()) {
1830 GTEST_SKIP() << "Skipping test because edge_extension_shader is off";
1831 }
1832 const int crop = 20;
1833 setCrop(1, Rect(0, 0, crop, crop));
1834 const int texSize = 10;
1835 setBuffer(1221,
1836 std::make_shared<renderengine::mock::FakeExternalTexture>(texSize /* width */,
1837 texSize /* height*/,
1838 42ULL /* bufferId */,
1839 HAL_PIXEL_FORMAT_RGBA_8888,
1840 0 /*usage*/));
1841 const float translation = -5.0;
1842 setPosition(12, translation, 0);
1843 setEdgeExtensionEffect(12, RIGHT);
1844 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1845 EXPECT_EQ(getSnapshot({.id = 1221})->transformedBounds.left, 0);
1846 EXPECT_GT(getSnapshot({.id = 1221})->transformedBounds.right, texSize + translation);
1847 EXPECT_LE(getSnapshot({.id = 1221})->transformedBounds.right, (float)crop);
1848}
1849
1850TEST_F(LayerSnapshotTest, topEdgeExtensionIncreaseBoundSizeWithinCrop) {
1851 // The top bound is extended when shifting to the bottom
1852 if (!com::android::graphics::libgui::flags::edge_extension_shader()) {
1853 GTEST_SKIP() << "Skipping test because edge_extension_shader is off";
1854 }
1855 setCrop(1, Rect(0, 0, 20, 20));
1856 const int texSize = 10;
1857 setBuffer(1221,
1858 std::make_shared<renderengine::mock::FakeExternalTexture>(texSize /* width */,
1859 texSize /* height*/,
1860 42ULL /* bufferId */,
1861 HAL_PIXEL_FORMAT_RGBA_8888,
1862 0 /*usage*/));
1863 const float translation = 5.0;
1864 setPosition(12, 0, translation);
1865 setEdgeExtensionEffect(12, TOP);
1866 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1867 EXPECT_EQ(getSnapshot({.id = 1221})->transformedBounds.bottom, texSize + translation);
1868 EXPECT_LT(getSnapshot({.id = 1221})->transformedBounds.top, translation);
1869 EXPECT_GE(getSnapshot({.id = 1221})->transformedBounds.top, 0.0);
1870}
1871
1872TEST_F(LayerSnapshotTest, bottomEdgeExtensionIncreaseBoundSizeWithinCrop) {
1873 // The bottom bound is extended when shifting to the top
1874 if (!com::android::graphics::libgui::flags::edge_extension_shader()) {
1875 GTEST_SKIP() << "Skipping test because edge_extension_shader is off";
1876 }
1877 const int crop = 20;
1878 setCrop(1, Rect(0, 0, crop, crop));
1879 const int texSize = 10;
1880 setBuffer(1221,
1881 std::make_shared<renderengine::mock::FakeExternalTexture>(texSize /* width */,
1882 texSize /* height*/,
1883 42ULL /* bufferId */,
1884 HAL_PIXEL_FORMAT_RGBA_8888,
1885 0 /*usage*/));
1886 const float translation = -5.0;
1887 setPosition(12, 0, translation);
1888 setEdgeExtensionEffect(12, BOTTOM);
1889 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1890 EXPECT_EQ(getSnapshot({.id = 1221})->transformedBounds.top, 0);
1891 EXPECT_GT(getSnapshot({.id = 1221})->transformedBounds.bottom, texSize - translation);
1892 EXPECT_LE(getSnapshot({.id = 1221})->transformedBounds.bottom, (float)crop);
1893}
1894
1895TEST_F(LayerSnapshotTest, multipleEdgeExtensionIncreaseBoundSizeWithinCrop) {
1896 // The left bound is extended when shifting to the right
1897 if (!com::android::graphics::libgui::flags::edge_extension_shader()) {
1898 GTEST_SKIP() << "Skipping test because edge_extension_shader is off";
1899 }
1900 const int crop = 20;
1901 setCrop(1, Rect(0, 0, crop, crop));
1902 const int texSize = 10;
1903 setBuffer(1221,
1904 std::make_shared<renderengine::mock::FakeExternalTexture>(texSize /* width */,
1905 texSize /* height*/,
1906 42ULL /* bufferId */,
1907 HAL_PIXEL_FORMAT_RGBA_8888,
1908 0 /*usage*/));
1909 const float translation = 5.0;
1910 setPosition(12, translation, translation);
1911 setEdgeExtensionEffect(12, LEFT | RIGHT | TOP | BOTTOM);
1912 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
1913 EXPECT_GT(getSnapshot({.id = 1221})->transformedBounds.right, texSize + translation);
1914 EXPECT_LE(getSnapshot({.id = 1221})->transformedBounds.right, (float)crop);
1915 EXPECT_LT(getSnapshot({.id = 1221})->transformedBounds.left, translation);
1916 EXPECT_GE(getSnapshot({.id = 1221})->transformedBounds.left, 0.0);
1917 EXPECT_GT(getSnapshot({.id = 1221})->transformedBounds.bottom, texSize + translation);
1918 EXPECT_LE(getSnapshot({.id = 1221})->transformedBounds.bottom, (float)crop);
1919 EXPECT_LT(getSnapshot({.id = 1221})->transformedBounds.top, translation);
1920 EXPECT_GE(getSnapshot({.id = 1221})->transformedBounds.top, 0);
1921}
1922
Vishnu Nair8fc721b2022-12-22 20:06:32 +00001923} // namespace android::surfaceflinger::frontend