blob: fc4bb229beec0cc25523271ef81d17eb7734a2bf [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
Vishnu Nair0808ae62023-08-07 21:42:42 -070020#include <renderengine/mock/FakeExternalTexture.h>
21
Vishnu Nair8fc721b2022-12-22 20:06:32 +000022#include "FrontEnd/LayerHierarchy.h"
23#include "FrontEnd/LayerLifecycleManager.h"
24#include "FrontEnd/LayerSnapshotBuilder.h"
Vishnu Nair3d8565a2023-06-30 07:23:24 +000025#include "Layer.h"
Vishnu Nair8fc721b2022-12-22 20:06:32 +000026#include "LayerHierarchyTest.h"
Vishnu Nair3996ee32023-08-14 04:32:31 +000027#include "ui/GraphicTypes.h"
Vishnu Nair8fc721b2022-12-22 20:06:32 +000028
29#define UPDATE_AND_VERIFY(BUILDER, ...) \
30 ({ \
31 SCOPED_TRACE(""); \
32 updateAndVerify((BUILDER), /*displayChanges=*/false, __VA_ARGS__); \
33 })
34
35#define UPDATE_AND_VERIFY_WITH_DISPLAY_CHANGES(BUILDER, ...) \
36 ({ \
37 SCOPED_TRACE(""); \
38 updateAndVerify((BUILDER), /*displayChanges=*/true, __VA_ARGS__); \
39 })
40
41namespace android::surfaceflinger::frontend {
42
Vishnu Naircfb2d252023-01-19 04:44:02 +000043using ftl::Flags;
44using namespace ftl::flag_operators;
45
Vishnu Nair8fc721b2022-12-22 20:06:32 +000046// To run test:
47/**
48 mp :libsurfaceflinger_unittest && adb sync; adb shell \
49 /data/nativetest/libsurfaceflinger_unittest/libsurfaceflinger_unittest \
50 --gtest_filter="LayerSnapshotTest.*" --gtest_brief=1
51*/
52
Vishnu Nair47b7bb42023-09-29 16:27:33 -070053class LayerSnapshotTest : public LayerSnapshotTestBase {
Vishnu Nair8fc721b2022-12-22 20:06:32 +000054protected:
Vishnu Nair47b7bb42023-09-29 16:27:33 -070055 LayerSnapshotTest() : LayerSnapshotTestBase() {
Vishnu Nair8fc721b2022-12-22 20:06:32 +000056 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
57 }
58
Vishnu Nair0808ae62023-08-07 21:42:42 -070059 void update(LayerSnapshotBuilder& actualBuilder, LayerSnapshotBuilder::Args& args) {
Vishnu Nair8fc721b2022-12-22 20:06:32 +000060 if (mLifecycleManager.getGlobalChanges().test(RequestedLayerState::Changes::Hierarchy)) {
61 mHierarchyBuilder.update(mLifecycleManager.getLayers(),
62 mLifecycleManager.getDestroyedLayers());
63 }
Vishnu Nair0808ae62023-08-07 21:42:42 -070064 args.root = mHierarchyBuilder.getHierarchy();
65 actualBuilder.update(args);
66 }
67
68 void updateAndVerify(LayerSnapshotBuilder& actualBuilder, bool hasDisplayChanges,
69 const std::vector<uint32_t> expectedVisibleLayerIdsInZOrder) {
Vishnu Nairc765c6c2023-02-23 00:08:01 +000070 LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(),
71 .layerLifecycleManager = mLifecycleManager,
72 .includeMetadata = false,
73 .displays = mFrontEndDisplayInfos,
74 .displayChanges = hasDisplayChanges,
75 .globalShadowSettings = globalShadowSettings,
Vishnu Nair444f3952023-04-11 13:01:02 -070076 .supportsBlur = true,
Vishnu Nairc765c6c2023-02-23 00:08:01 +000077 .supportedLayerGenericMetadata = {},
78 .genericLayerMetadataKeyMap = {}};
Vishnu Nair0808ae62023-08-07 21:42:42 -070079 update(actualBuilder, args);
Vishnu Nair8fc721b2022-12-22 20:06:32 +000080
81 // rebuild layer snapshots from scratch and verify that it matches the updated state.
82 LayerSnapshotBuilder expectedBuilder(args);
83 mLifecycleManager.commitChanges();
84 ASSERT_TRUE(expectedBuilder.getSnapshots().size() > 0);
85 ASSERT_TRUE(actualBuilder.getSnapshots().size() > 0);
86
Vishnu Nair8fc721b2022-12-22 20:06:32 +000087 std::vector<uint32_t> actualVisibleLayerIdsInZOrder;
Vishnu Naircfb2d252023-01-19 04:44:02 +000088 actualBuilder.forEachVisibleSnapshot(
89 [&actualVisibleLayerIdsInZOrder](const LayerSnapshot& snapshot) {
90 actualVisibleLayerIdsInZOrder.push_back(snapshot.path.id);
91 });
Vishnu Nair8fc721b2022-12-22 20:06:32 +000092 EXPECT_EQ(expectedVisibleLayerIdsInZOrder, actualVisibleLayerIdsInZOrder);
93 }
94
95 LayerSnapshot* getSnapshot(uint32_t layerId) { return mSnapshotBuilder.getSnapshot(layerId); }
Vishnu Nair92990e22023-02-24 20:01:05 +000096 LayerSnapshot* getSnapshot(const LayerHierarchy::TraversalPath path) {
97 return mSnapshotBuilder.getSnapshot(path);
98 }
Vishnu Nair8fc721b2022-12-22 20:06:32 +000099 LayerSnapshotBuilder mSnapshotBuilder;
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000100 static const std::vector<uint32_t> STARTING_ZORDER;
101};
102const std::vector<uint32_t> LayerSnapshotTest::STARTING_ZORDER = {1, 11, 111, 12, 121,
103 122, 1221, 13, 2};
104
105TEST_F(LayerSnapshotTest, buildSnapshot) {
Vishnu Nairc765c6c2023-02-23 00:08:01 +0000106 LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(),
107 .layerLifecycleManager = mLifecycleManager,
108 .includeMetadata = false,
109 .displays = mFrontEndDisplayInfos,
110 .globalShadowSettings = globalShadowSettings,
111 .supportedLayerGenericMetadata = {},
112 .genericLayerMetadataKeyMap = {}};
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000113 LayerSnapshotBuilder builder(args);
114}
115
116TEST_F(LayerSnapshotTest, updateSnapshot) {
Vishnu Nairc765c6c2023-02-23 00:08:01 +0000117 LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(),
118 .layerLifecycleManager = mLifecycleManager,
119 .includeMetadata = false,
120 .displays = mFrontEndDisplayInfos,
121 .globalShadowSettings = globalShadowSettings,
122 .supportedLayerGenericMetadata = {},
123 .genericLayerMetadataKeyMap = {}
124
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000125 };
126
127 LayerSnapshotBuilder builder;
128 builder.update(args);
129}
130
131// update using parent snapshot data
132TEST_F(LayerSnapshotTest, croppedByParent) {
133 /// MAKE ALL LAYERS VISIBLE BY DEFAULT
134 DisplayInfo info;
135 info.info.logicalHeight = 100;
136 info.info.logicalWidth = 200;
137 mFrontEndDisplayInfos.emplace_or_replace(ui::LayerStack::fromValue(1), info);
138 Rect layerCrop(0, 0, 10, 20);
139 setCrop(11, layerCrop);
140 EXPECT_TRUE(mLifecycleManager.getGlobalChanges().test(RequestedLayerState::Changes::Geometry));
141 UPDATE_AND_VERIFY_WITH_DISPLAY_CHANGES(mSnapshotBuilder, STARTING_ZORDER);
142 EXPECT_EQ(getSnapshot(11)->geomCrop, layerCrop);
143 EXPECT_EQ(getSnapshot(111)->geomLayerBounds, layerCrop.toFloatRect());
144 float maxHeight = static_cast<float>(info.info.logicalHeight * 10);
145 float maxWidth = static_cast<float>(info.info.logicalWidth * 10);
146
147 FloatRect maxDisplaySize(-maxWidth, -maxHeight, maxWidth, maxHeight);
148 EXPECT_EQ(getSnapshot(1)->geomLayerBounds, maxDisplaySize);
149}
150
151// visibility tests
152TEST_F(LayerSnapshotTest, newLayerHiddenByPolicy) {
153 createLayer(112, 11);
154 hideLayer(112);
155 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
156
157 showLayer(112);
158 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 11, 111, 112, 12, 121, 122, 1221, 13, 2});
159}
160
161TEST_F(LayerSnapshotTest, hiddenByParent) {
162 hideLayer(11);
163 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 13, 2});
164}
165
166TEST_F(LayerSnapshotTest, reparentShowsChild) {
167 hideLayer(11);
168 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 13, 2});
169
170 showLayer(11);
171 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
172}
173
174TEST_F(LayerSnapshotTest, reparentHidesChild) {
175 hideLayer(11);
176 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 13, 2});
177
178 reparentLayer(121, 11);
179 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 122, 1221, 13, 2});
180}
181
182TEST_F(LayerSnapshotTest, unHidingUpdatesSnapshot) {
183 hideLayer(11);
184 Rect crop(1, 2, 3, 4);
185 setCrop(111, crop);
186 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 13, 2});
187
188 showLayer(11);
189 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
190 EXPECT_EQ(getSnapshot(111)->geomLayerBounds, crop.toFloatRect());
191}
192
193TEST_F(LayerSnapshotTest, childBehindParentCanBeHiddenByParent) {
194 setZ(111, -1);
195 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 111, 11, 12, 121, 122, 1221, 13, 2});
196
197 hideLayer(11);
198 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 13, 2});
199}
200
201// relative tests
202TEST_F(LayerSnapshotTest, RelativeParentCanHideChild) {
203 reparentRelativeLayer(13, 11);
204 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 11, 13, 111, 12, 121, 122, 1221, 2});
205
206 hideLayer(11);
207 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 2});
208}
209
210TEST_F(LayerSnapshotTest, ReparentingToHiddenRelativeParentHidesChild) {
211 hideLayer(11);
212 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 13, 2});
213 reparentRelativeLayer(13, 11);
214 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 2});
215}
216
217TEST_F(LayerSnapshotTest, AlphaInheritedByChildren) {
218 setAlpha(1, 0.5);
219 setAlpha(122, 0.5);
220 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
Vishnu Naira02943f2023-06-03 13:44:46 -0700221 EXPECT_EQ(getSnapshot(1)->alpha, 0.5f);
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000222 EXPECT_EQ(getSnapshot(12)->alpha, 0.5f);
223 EXPECT_EQ(getSnapshot(1221)->alpha, 0.25f);
224}
225
226// Change states
227TEST_F(LayerSnapshotTest, UpdateClearsPreviousChangeStates) {
228 setCrop(1, Rect(1, 2, 3, 4));
229 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
Vishnu Naira02943f2023-06-03 13:44:46 -0700230 EXPECT_TRUE(getSnapshot(1)->changes.test(RequestedLayerState::Changes::Geometry));
231 EXPECT_TRUE(getSnapshot(11)->changes.test(RequestedLayerState::Changes::Geometry));
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000232 setCrop(2, Rect(1, 2, 3, 4));
233 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
Vishnu Naira02943f2023-06-03 13:44:46 -0700234 EXPECT_TRUE(getSnapshot(2)->changes.test(RequestedLayerState::Changes::Geometry));
235 EXPECT_FALSE(getSnapshot(1)->changes.test(RequestedLayerState::Changes::Geometry));
236 EXPECT_FALSE(getSnapshot(11)->changes.test(RequestedLayerState::Changes::Geometry));
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000237}
238
239TEST_F(LayerSnapshotTest, FastPathClearsPreviousChangeStates) {
240 setColor(11, {1._hf, 0._hf, 0._hf});
241 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
Vishnu Naira02943f2023-06-03 13:44:46 -0700242 EXPECT_EQ(getSnapshot(11)->changes, RequestedLayerState::Changes::Content);
243 EXPECT_EQ(getSnapshot(11)->clientChanges, layer_state_t::eColorChanged);
244 EXPECT_EQ(getSnapshot(1)->changes.get(), 0u);
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000245 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
Vishnu Naira02943f2023-06-03 13:44:46 -0700246 EXPECT_EQ(getSnapshot(11)->changes.get(), 0u);
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000247}
248
249TEST_F(LayerSnapshotTest, FastPathSetsChangeFlagToContent) {
250 setColor(1, {1._hf, 0._hf, 0._hf});
251 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
252 EXPECT_EQ(getSnapshot(1)->changes, RequestedLayerState::Changes::Content);
Vishnu Naira02943f2023-06-03 13:44:46 -0700253 EXPECT_EQ(getSnapshot(1)->clientChanges, layer_state_t::eColorChanged);
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000254}
255
Vishnu Naircfb2d252023-01-19 04:44:02 +0000256TEST_F(LayerSnapshotTest, GameMode) {
257 std::vector<TransactionState> transactions;
258 transactions.emplace_back();
259 transactions.back().states.push_back({});
260 transactions.back().states.front().state.what = layer_state_t::eMetadataChanged;
261 transactions.back().states.front().state.metadata = LayerMetadata();
262 transactions.back().states.front().state.metadata.setInt32(METADATA_GAME_MODE, 42);
Vishnu Nair1391de22023-03-05 19:56:14 -0800263 transactions.back().states.front().layerId = 1;
Vishnu Naircfb2d252023-01-19 04:44:02 +0000264 transactions.back().states.front().state.layerId = static_cast<int32_t>(1);
265 mLifecycleManager.applyTransactions(transactions);
Vishnu Naira02943f2023-06-03 13:44:46 -0700266 EXPECT_EQ(mLifecycleManager.getGlobalChanges(), RequestedLayerState::Changes::GameMode);
Vishnu Naircfb2d252023-01-19 04:44:02 +0000267 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
Vishnu Naira02943f2023-06-03 13:44:46 -0700268 EXPECT_EQ(getSnapshot(1)->clientChanges, layer_state_t::eMetadataChanged);
Vishnu Naircfb2d252023-01-19 04:44:02 +0000269 EXPECT_EQ(static_cast<int32_t>(getSnapshot(1)->gameMode), 42);
270 EXPECT_EQ(static_cast<int32_t>(getSnapshot(11)->gameMode), 42);
271}
272
273TEST_F(LayerSnapshotTest, NoLayerVoteForParentWithChildVotes) {
274 // ROOT
275 // ├── 1
276 // │ ├── 11 (frame rate set)
277 // │ │ └── 111
278 // │ ├── 12
279 // │ │ ├── 121
280 // │ │ └── 122
281 // │ │ └── 1221
282 // │ └── 13
283 // └── 2
284
285 std::vector<TransactionState> transactions;
286 transactions.emplace_back();
287 transactions.back().states.push_back({});
288 transactions.back().states.front().state.what = layer_state_t::eFrameRateChanged;
289 transactions.back().states.front().state.frameRate = 90.0;
290 transactions.back().states.front().state.frameRateCompatibility =
291 ANATIVEWINDOW_FRAME_RATE_EXACT;
292 transactions.back().states.front().state.changeFrameRateStrategy =
293 ANATIVEWINDOW_CHANGE_FRAME_RATE_ALWAYS;
Vishnu Nair1391de22023-03-05 19:56:14 -0800294 transactions.back().states.front().layerId = 11;
Vishnu Naircfb2d252023-01-19 04:44:02 +0000295 mLifecycleManager.applyTransactions(transactions);
296 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
297
Rachel Leece6e0042023-06-27 11:22:54 -0700298 EXPECT_EQ(getSnapshot(11)->frameRate.vote.rate.getIntValue(), 90);
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700299 EXPECT_EQ(getSnapshot(11)->frameRate.vote.type, scheduler::FrameRateCompatibility::Exact);
Rachel Leece6e0042023-06-27 11:22:54 -0700300 EXPECT_EQ(getSnapshot(111)->frameRate.vote.rate.getIntValue(), 90);
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700301 EXPECT_EQ(getSnapshot(111)->frameRate.vote.type, scheduler::FrameRateCompatibility::Exact);
Rachel Leece6e0042023-06-27 11:22:54 -0700302 EXPECT_EQ(getSnapshot(1)->frameRate.vote.rate.getIntValue(), 0);
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700303 EXPECT_EQ(getSnapshot(1)->frameRate.vote.type, scheduler::FrameRateCompatibility::NoVote);
Vishnu Naircfb2d252023-01-19 04:44:02 +0000304}
305
Vishnu Naira02943f2023-06-03 13:44:46 -0700306TEST_F(LayerSnapshotTest, CanCropTouchableRegion) {
Vishnu Nair29354ec2023-03-28 18:51:28 -0700307 // ROOT
308 // ├── 1
309 // │ ├── 11
310 // │ │ └── 111 (touchregion set to touch but cropped by layer 13)
311 // │ ├── 12
312 // │ │ ├── 121
313 // │ │ └── 122
314 // │ │ └── 1221
315 // │ └── 13 (crop set to touchCrop)
316 // └── 2
317
318 Rect touchCrop{300, 300, 400, 500};
319 setCrop(13, touchCrop);
320 Region touch{Rect{0, 0, 1000, 1000}};
321 setTouchableRegionCrop(111, touch, /*touchCropId=*/13, /*replaceTouchableRegionWithCrop=*/true);
322 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
323 EXPECT_EQ(getSnapshot({.id = 111})->inputInfo.touchableRegion.bounds(), touchCrop);
324
325 Rect modifiedTouchCrop{100, 300, 400, 700};
326 setCrop(13, modifiedTouchCrop);
327 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
328 EXPECT_EQ(getSnapshot({.id = 111})->inputInfo.touchableRegion.bounds(), modifiedTouchCrop);
329}
330
Vishnu Nair444f3952023-04-11 13:01:02 -0700331TEST_F(LayerSnapshotTest, blurUpdatesWhenAlphaChanges) {
Vishnu Nair854ce1c2023-08-19 15:00:13 -0700332 int blurRadius = 42;
333 setBackgroundBlurRadius(1221, static_cast<uint32_t>(blurRadius));
Vishnu Nair444f3952023-04-11 13:01:02 -0700334
335 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
336 EXPECT_EQ(getSnapshot({.id = 1221})->backgroundBlurRadius, blurRadius);
337
Vishnu Nair854ce1c2023-08-19 15:00:13 -0700338 blurRadius = 21;
339 setBackgroundBlurRadius(1221, static_cast<uint32_t>(blurRadius));
340 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
341 EXPECT_EQ(getSnapshot({.id = 1221})->backgroundBlurRadius, blurRadius);
342
Vishnu Nair444f3952023-04-11 13:01:02 -0700343 static constexpr float alpha = 0.5;
344 setAlpha(12, alpha);
345 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
Vishnu Nair854ce1c2023-08-19 15:00:13 -0700346 EXPECT_EQ(getSnapshot({.id = 1221})->backgroundBlurRadius,
347 static_cast<int>(static_cast<float>(blurRadius) * alpha));
Vishnu Nair444f3952023-04-11 13:01:02 -0700348}
349
Vishnu Naira9c43762023-01-27 19:10:25 +0000350// Display Mirroring Tests
351// tree with 3 levels of children
352// ROOT (DISPLAY 0)
353// ├── 1
354// │ ├── 11
355// │ │ └── 111
356// │ ├── 12 (has skip screenshot flag)
357// │ │ ├── 121
358// │ │ └── 122
359// │ │ └── 1221
360// │ └── 13
361// └── 2
362// ROOT (DISPLAY 1)
363// └── 3 (mirrors display 0)
Vishnu Nair92990e22023-02-24 20:01:05 +0000364TEST_F(LayerSnapshotTest, displayMirrorRespectsLayerSkipScreenshotFlag) {
Vishnu Naira9c43762023-01-27 19:10:25 +0000365 setFlags(12, layer_state_t::eLayerSkipScreenshot, layer_state_t::eLayerSkipScreenshot);
366 createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0));
367 setLayerStack(3, 1);
368
Vishnu Nair444f3952023-04-11 13:01:02 -0700369 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 +0000370 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
371}
372
Vishnu Nair92990e22023-02-24 20:01:05 +0000373// ROOT (DISPLAY 0)
374// ├── 1
375// │ ├── 11
376// │ │ └── 111
377// │ └── 13
378// └── 2
379// ROOT (DISPLAY 3)
380// └── 3 (mirrors display 0)
381TEST_F(LayerSnapshotTest, mirrorLayerGetsCorrectLayerStack) {
382 reparentLayer(12, UNASSIGNED_LAYER_ID);
383 createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0));
384 setLayerStack(3, 3);
385 createDisplayMirrorLayer(4, ui::LayerStack::fromValue(0));
386 setLayerStack(4, 4);
387
Vishnu Nair444f3952023-04-11 13:01:02 -0700388 std::vector<uint32_t> expected = {1, 11, 111, 13, 2, 3, 1, 11, 111,
389 13, 2, 4, 1, 11, 111, 13, 2};
Vishnu Nair92990e22023-02-24 20:01:05 +0000390 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
Vishnu Nair6f878312023-09-08 11:05:01 -0700391 EXPECT_EQ(getSnapshot({.id = 111, .mirrorRootIds = 3u})->outputFilter.layerStack.id, 3u);
392 EXPECT_EQ(getSnapshot({.id = 111, .mirrorRootIds = 4u})->outputFilter.layerStack.id, 4u);
Vishnu Nair92990e22023-02-24 20:01:05 +0000393}
394
395// ROOT (DISPLAY 0)
396// ├── 1 (crop 50x50)
397// │ ├── 11
398// │ │ └── 111
399// │ └── 13
400// └── 2
401// ROOT (DISPLAY 3)
402// └── 3 (mirrors display 0) (crop 100x100)
403TEST_F(LayerSnapshotTest, mirrorLayerTouchIsCroppedByMirrorRoot) {
404 reparentLayer(12, UNASSIGNED_LAYER_ID);
405 createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0));
406 setLayerStack(3, 3);
407 setCrop(1, Rect{50, 50});
408 setCrop(3, Rect{100, 100});
409 setCrop(111, Rect{200, 200});
410 Region touch{Rect{0, 0, 1000, 1000}};
411 setTouchableRegion(111, touch);
Vishnu Nair444f3952023-04-11 13:01:02 -0700412 std::vector<uint32_t> expected = {1, 11, 111, 13, 2, 3, 1, 11, 111, 13, 2};
Vishnu Nair92990e22023-02-24 20:01:05 +0000413 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
414 EXPECT_TRUE(getSnapshot({.id = 111})->inputInfo.touchableRegion.hasSameRects(touch));
415 Region touchCroppedByMirrorRoot{Rect{0, 0, 50, 50}};
Vishnu Nair6f878312023-09-08 11:05:01 -0700416 EXPECT_TRUE(getSnapshot({.id = 111, .mirrorRootIds = 3u})
Vishnu Nair92990e22023-02-24 20:01:05 +0000417 ->inputInfo.touchableRegion.hasSameRects(touchCroppedByMirrorRoot));
418}
419
420TEST_F(LayerSnapshotTest, canRemoveDisplayMirror) {
421 setFlags(12, layer_state_t::eLayerSkipScreenshot, layer_state_t::eLayerSkipScreenshot);
422 createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0));
423 setLayerStack(3, 1);
Vishnu Nair444f3952023-04-11 13:01:02 -0700424 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 +0000425 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
426 destroyLayerHandle(3);
427 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
428}
429
Vishnu Nairfccd6362023-02-24 23:39:53 +0000430TEST_F(LayerSnapshotTest, cleanUpUnreachableSnapshotsAfterMirroring) {
431 size_t startingNumSnapshots = mSnapshotBuilder.getSnapshots().size();
432 createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0));
433 setLayerStack(3, 1);
Vishnu Nair444f3952023-04-11 13:01:02 -0700434 std::vector<uint32_t> expected = {1, 11, 111, 12, 121, 122, 1221, 13, 2, 3,
435 1, 11, 111, 12, 121, 122, 1221, 13, 2};
Vishnu Nairfccd6362023-02-24 23:39:53 +0000436 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
437 destroyLayerHandle(3);
438 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
439
440 EXPECT_EQ(startingNumSnapshots, mSnapshotBuilder.getSnapshots().size());
441}
442
Vishnu Nair6f878312023-09-08 11:05:01 -0700443TEST_F(LayerSnapshotTest, canMirrorDisplayWithMirrors) {
444 reparentLayer(12, UNASSIGNED_LAYER_ID);
445 mirrorLayer(/*layer*/ 14, /*parent*/ 1, /*layerToMirror*/ 11);
446 std::vector<uint32_t> expected = {1, 11, 111, 13, 14, 11, 111, 2};
447 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
448
449 createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0));
450 setLayerStack(3, 3);
451 expected = {1, 11, 111, 13, 14, 11, 111, 2, 3, 1, 11, 111, 13, 14, 11, 111, 2};
452 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
453 EXPECT_EQ(getSnapshot({.id = 11, .mirrorRootIds = 14u})->outputFilter.layerStack.id, 0u);
454 EXPECT_EQ(getSnapshot({.id = 11, .mirrorRootIds = 3u})->outputFilter.layerStack.id, 3u);
455 EXPECT_EQ(getSnapshot({.id = 11, .mirrorRootIds = 3u, 14u})->outputFilter.layerStack.id, 3u);
456}
457
Vishnu Nairfccd6362023-02-24 23:39:53 +0000458// Rel z doesn't create duplicate snapshots but this is for completeness
459TEST_F(LayerSnapshotTest, cleanUpUnreachableSnapshotsAfterRelZ) {
460 size_t startingNumSnapshots = mSnapshotBuilder.getSnapshots().size();
461 reparentRelativeLayer(13, 11);
462 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 11, 13, 111, 12, 121, 122, 1221, 2});
463 setZ(13, 0);
464 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
465
466 EXPECT_EQ(startingNumSnapshots, mSnapshotBuilder.getSnapshots().size());
467}
468
469TEST_F(LayerSnapshotTest, cleanUpUnreachableSnapshotsAfterLayerDestruction) {
470 size_t startingNumSnapshots = mSnapshotBuilder.getSnapshots().size();
471 destroyLayerHandle(2);
472 destroyLayerHandle(122);
473
474 std::vector<uint32_t> expected = {1, 11, 111, 12, 121, 122, 1221, 13};
475 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
476
477 EXPECT_LE(startingNumSnapshots - 2, mSnapshotBuilder.getSnapshots().size());
478}
479
Vishnu Nair3d8565a2023-06-30 07:23:24 +0000480TEST_F(LayerSnapshotTest, snashotContainsMetadataFromLayerCreationArgs) {
481 LayerCreationArgs args(std::make_optional<uint32_t>(200));
482 args.name = "testlayer";
483 args.addToRoot = true;
484 args.metadata.setInt32(42, 24);
485
486 std::vector<std::unique_ptr<RequestedLayerState>> layers;
487 layers.emplace_back(std::make_unique<RequestedLayerState>(args));
488 EXPECT_TRUE(layers.back()->metadata.has(42));
489 EXPECT_EQ(layers.back()->metadata.getInt32(42, 0), 24);
490 mLifecycleManager.addLayers(std::move(layers));
491
492 std::vector<uint32_t> expected = STARTING_ZORDER;
493 expected.push_back(200);
494 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
495
496 EXPECT_TRUE(mSnapshotBuilder.getSnapshot(200)->layerMetadata.has(42));
497 EXPECT_EQ(mSnapshotBuilder.getSnapshot(200)->layerMetadata.getInt32(42, 0), 24);
498}
499
500TEST_F(LayerSnapshotTest, frameRateSelectionPriorityPassedToChildLayers) {
501 setFrameRateSelectionPriority(11, 1);
502
503 setFrameRateSelectionPriority(12, 2);
504
505 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
506 EXPECT_EQ(getSnapshot({.id = 1})->frameRateSelectionPriority, Layer::PRIORITY_UNSET);
507 EXPECT_EQ(getSnapshot({.id = 11})->frameRateSelectionPriority, 1);
508 EXPECT_EQ(getSnapshot({.id = 12})->frameRateSelectionPriority, 2);
509 EXPECT_EQ(getSnapshot({.id = 122})->frameRateSelectionPriority, 2);
510 EXPECT_EQ(getSnapshot({.id = 1221})->frameRateSelectionPriority, 2);
511
512 // reparent and verify the child gets the new parent's framerate selection priority
513 reparentLayer(122, 11);
514
515 std::vector<uint32_t> expected = {1, 11, 111, 122, 1221, 12, 121, 13, 2};
516 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
517 EXPECT_EQ(getSnapshot({.id = 1})->frameRateSelectionPriority, Layer::PRIORITY_UNSET);
518 EXPECT_EQ(getSnapshot({.id = 11})->frameRateSelectionPriority, 1);
519 EXPECT_EQ(getSnapshot({.id = 12})->frameRateSelectionPriority, 2);
520 EXPECT_EQ(getSnapshot({.id = 122})->frameRateSelectionPriority, 1);
521 EXPECT_EQ(getSnapshot({.id = 1221})->frameRateSelectionPriority, 1);
522}
523
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000524TEST_F(LayerSnapshotTest, framerate) {
525 setFrameRate(11, 244.f, 0, 0);
526
527 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
528 // verify parent is gets no vote
Rachel Leece6e0042023-06-27 11:22:54 -0700529 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
530 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700531 scheduler::FrameRateCompatibility::NoVote);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000532 EXPECT_TRUE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate));
533
534 // verify layer and children get the requested votes
Rachel Leece6e0042023-06-27 11:22:54 -0700535 EXPECT_TRUE(getSnapshot({.id = 11})->frameRate.vote.rate.isValid());
536 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 244.f);
537 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700538 scheduler::FrameRateCompatibility::Default);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000539 EXPECT_TRUE(getSnapshot({.id = 11})->changes.test(RequestedLayerState::Changes::FrameRate));
540
Rachel Leece6e0042023-06-27 11:22:54 -0700541 EXPECT_TRUE(getSnapshot({.id = 111})->frameRate.vote.rate.isValid());
542 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.rate.getValue(), 244.f);
543 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700544 scheduler::FrameRateCompatibility::Default);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000545 EXPECT_TRUE(getSnapshot({.id = 111})->changes.test(RequestedLayerState::Changes::FrameRate));
546
547 // reparent and verify the child gets the new parent's framerate
548 reparentLayer(122, 11);
549
550 std::vector<uint32_t> expected = {1, 11, 111, 122, 1221, 12, 121, 13, 2};
551 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
552 // verify parent is gets no vote
Rachel Leece6e0042023-06-27 11:22:54 -0700553 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
554 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700555 scheduler::FrameRateCompatibility::NoVote);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000556
557 // verify layer and children get the requested votes
Rachel Leece6e0042023-06-27 11:22:54 -0700558 EXPECT_TRUE(getSnapshot({.id = 11})->frameRate.vote.rate.isValid());
559 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 244.f);
560 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700561 scheduler::FrameRateCompatibility::Default);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000562
Rachel Leece6e0042023-06-27 11:22:54 -0700563 EXPECT_TRUE(getSnapshot({.id = 111})->frameRate.vote.rate.isValid());
564 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.rate.getValue(), 244.f);
565 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700566 scheduler::FrameRateCompatibility::Default);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000567
Rachel Leece6e0042023-06-27 11:22:54 -0700568 EXPECT_TRUE(getSnapshot({.id = 122})->frameRate.vote.rate.isValid());
569 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.rate.getValue(), 244.f);
570 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700571 scheduler::FrameRateCompatibility::Default);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000572 EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate));
573
574 // reparent and verify the new parent gets no vote
575 reparentLayer(11, 2);
576 expected = {1, 12, 121, 13, 2, 11, 111, 122, 1221};
577 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
578
579 // verify old parent has invalid framerate (default)
Rachel Leece6e0042023-06-27 11:22:54 -0700580 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
581 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700582 scheduler::FrameRateCompatibility::Default);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000583 EXPECT_TRUE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate));
584
585 // verify new parent get no vote
Rachel Leece6e0042023-06-27 11:22:54 -0700586 EXPECT_FALSE(getSnapshot({.id = 2})->frameRate.vote.rate.isValid());
587 EXPECT_EQ(getSnapshot({.id = 2})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700588 scheduler::FrameRateCompatibility::NoVote);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000589 EXPECT_TRUE(getSnapshot({.id = 2})->changes.test(RequestedLayerState::Changes::FrameRate));
590
591 // verify layer and children get the requested votes (unchanged)
Rachel Leece6e0042023-06-27 11:22:54 -0700592 EXPECT_TRUE(getSnapshot({.id = 11})->frameRate.vote.rate.isValid());
593 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 244.f);
594 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700595 scheduler::FrameRateCompatibility::Default);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000596
Rachel Leece6e0042023-06-27 11:22:54 -0700597 EXPECT_TRUE(getSnapshot({.id = 111})->frameRate.vote.rate.isValid());
598 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.rate.getValue(), 244.f);
599 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700600 scheduler::FrameRateCompatibility::Default);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000601
Rachel Leece6e0042023-06-27 11:22:54 -0700602 EXPECT_TRUE(getSnapshot({.id = 122})->frameRate.vote.rate.isValid());
603 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.rate.getValue(), 244.f);
604 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700605 scheduler::FrameRateCompatibility::Default);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000606}
607
Vishnu Nair3996ee32023-08-14 04:32:31 +0000608TEST_F(LayerSnapshotTest, translateDataspace) {
609 setDataspace(1, ui::Dataspace::UNKNOWN);
610 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
611 EXPECT_EQ(getSnapshot({.id = 1})->dataspace, ui::Dataspace::V0_SRGB);
612}
613
Rachel Leece6e0042023-06-27 11:22:54 -0700614// This test is similar to "frameRate" test case but checks that the setFrameRateCategory API
615// interaction also works correctly with the setFrameRate API within SF frontend.
616TEST_F(LayerSnapshotTest, frameRateWithCategory) {
617 // ROOT
618 // ├── 1
619 // │ ├── 11 (frame rate set to 244.f)
620 // │ │ └── 111
621 // │ ├── 12
622 // │ │ ├── 121
623 // │ │ └── 122 (frame rate category set to Normal)
624 // │ │ └── 1221
625 // │ └── 13
626 // └── 2
627 setFrameRate(11, 244.f, 0, 0);
628 setFrameRateCategory(122, 3 /* Normal */);
629
630 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
631 // verify parent 1 gets no vote
632 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
633 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700634 scheduler::FrameRateCompatibility::NoVote);
Rachel Leece6e0042023-06-27 11:22:54 -0700635 EXPECT_TRUE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate));
636
637 // verify layer 11 and children 111 get the requested votes
638 EXPECT_TRUE(getSnapshot({.id = 11})->frameRate.vote.rate.isValid());
639 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 244.f);
640 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700641 scheduler::FrameRateCompatibility::Default);
Rachel Leece6e0042023-06-27 11:22:54 -0700642 EXPECT_TRUE(getSnapshot({.id = 11})->changes.test(RequestedLayerState::Changes::FrameRate));
643
644 EXPECT_TRUE(getSnapshot({.id = 111})->frameRate.vote.rate.isValid());
645 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.rate.getValue(), 244.f);
646 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700647 scheduler::FrameRateCompatibility::Default);
Rachel Leece6e0042023-06-27 11:22:54 -0700648 EXPECT_TRUE(getSnapshot({.id = 111})->changes.test(RequestedLayerState::Changes::FrameRate));
649
650 // verify parent 12 gets no vote
651 EXPECT_FALSE(getSnapshot({.id = 12})->frameRate.vote.rate.isValid());
652 EXPECT_EQ(getSnapshot({.id = 12})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700653 scheduler::FrameRateCompatibility::NoVote);
Rachel Leece6e0042023-06-27 11:22:54 -0700654 EXPECT_TRUE(getSnapshot({.id = 12})->changes.test(RequestedLayerState::Changes::FrameRate));
655
656 // verify layer 122 and children 1221 get the requested votes
657 EXPECT_FALSE(getSnapshot({.id = 122})->frameRate.vote.rate.isValid());
658 EXPECT_TRUE(getSnapshot({.id = 122})->frameRate.isValid());
659 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700660 scheduler::FrameRateCompatibility::Default);
Rachel Leece6e0042023-06-27 11:22:54 -0700661 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.category, FrameRateCategory::Normal);
662 EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate));
Rachel Lee43369b22023-09-05 18:40:40 -0700663 EXPECT_TRUE(
664 getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::AffectsChildren));
Rachel Leece6e0042023-06-27 11:22:54 -0700665
666 EXPECT_FALSE(getSnapshot({.id = 1221})->frameRate.vote.rate.isValid());
667 EXPECT_TRUE(getSnapshot({.id = 1221})->frameRate.isValid());
668 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700669 scheduler::FrameRateCompatibility::Default);
Rachel Leece6e0042023-06-27 11:22:54 -0700670 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.category, FrameRateCategory::Normal);
671 EXPECT_TRUE(getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::FrameRate));
Rachel Lee43369b22023-09-05 18:40:40 -0700672 EXPECT_TRUE(
673 getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::AffectsChildren));
Rachel Leece6e0042023-06-27 11:22:54 -0700674
675 // reparent and verify the child does NOT get the new parent's framerate because it already has
676 // the frame rate category specified.
677 // ROOT
678 // ├─1
679 // │ ├─11 (frame rate set to 244.f)
680 // │ │ ├─111
681 // │ │ └─122 (frame rate category set to Normal)
682 // │ │ └─1221
683 // │ ├─12
684 // │ │ └─121
685 // │ └─13
686 // └─2
687 reparentLayer(122, 11);
688
689 std::vector<uint32_t> expected = {1, 11, 111, 122, 1221, 12, 121, 13, 2};
690 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
691 // verify parent is gets no vote
692 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
693 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700694 scheduler::FrameRateCompatibility::NoVote);
Rachel Leece6e0042023-06-27 11:22:54 -0700695
696 // verify layer 11 and children 111 get the requested votes
697 EXPECT_TRUE(getSnapshot({.id = 11})->frameRate.vote.rate.isValid());
698 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 244.f);
699 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700700 scheduler::FrameRateCompatibility::Default);
Rachel Leece6e0042023-06-27 11:22:54 -0700701
702 EXPECT_TRUE(getSnapshot({.id = 111})->frameRate.vote.rate.isValid());
703 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.rate.getValue(), 244.f);
704 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700705 scheduler::FrameRateCompatibility::Default);
Rachel Leece6e0042023-06-27 11:22:54 -0700706
707 // verify layer 122 and children 1221 get the requested category vote (unchanged from
708 // reparenting)
709 EXPECT_FALSE(getSnapshot({.id = 122})->frameRate.vote.rate.isValid());
710 EXPECT_TRUE(getSnapshot({.id = 122})->frameRate.isValid());
711 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700712 scheduler::FrameRateCompatibility::Default);
Rachel Leece6e0042023-06-27 11:22:54 -0700713 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.category, FrameRateCategory::Normal);
714 EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate));
715
716 EXPECT_FALSE(getSnapshot({.id = 1221})->frameRate.vote.rate.isValid());
717 EXPECT_TRUE(getSnapshot({.id = 1221})->frameRate.isValid());
718 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700719 scheduler::FrameRateCompatibility::Default);
Rachel Leece6e0042023-06-27 11:22:54 -0700720 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.category, FrameRateCategory::Normal);
721 EXPECT_TRUE(getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::FrameRate));
722}
723
Rachel Lee58cc90d2023-09-05 18:50:20 -0700724TEST_F(LayerSnapshotTest, frameRateSelectionStrategy) {
725 // ROOT
726 // ├── 1
727 // │ ├── 11
728 // │ │ └── 111
729 // │ ├── 12 (frame rate set to 244.f with strategy OverrideChildren)
730 // │ │ ├── 121
731 // │ │ └── 122 (frame rate set to 123.f but should be overridden by layer 12)
732 // │ │ └── 1221
733 // │ └── 13
734 // └── 2
735 setFrameRate(12, 244.f, 0, 0);
736 setFrameRate(122, 123.f, 0, 0);
737 setFrameRateSelectionStrategy(12, 1 /* OverrideChildren */);
738
739 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
740 // verify parent 1 gets no vote
741 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
742 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700743 scheduler::FrameRateCompatibility::NoVote);
Rachel Lee58cc90d2023-09-05 18:50:20 -0700744 EXPECT_TRUE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate));
745
746 // verify layer 12 and all descendants (121, 122, 1221) get the requested vote
747 EXPECT_EQ(getSnapshot({.id = 12})->frameRate.vote.rate.getValue(), 244.f);
748 EXPECT_EQ(getSnapshot({.id = 12})->frameRateSelectionStrategy,
749 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
750 EXPECT_TRUE(getSnapshot({.id = 12})->changes.test(RequestedLayerState::Changes::FrameRate));
751
752 EXPECT_EQ(getSnapshot({.id = 121})->frameRate.vote.rate.getValue(), 244.f);
753 EXPECT_EQ(getSnapshot({.id = 121})->frameRateSelectionStrategy,
754 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
755 EXPECT_TRUE(getSnapshot({.id = 121})->changes.test(RequestedLayerState::Changes::FrameRate));
756
757 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.rate.getValue(), 244.f);
758 EXPECT_EQ(getSnapshot({.id = 122})->frameRateSelectionStrategy,
759 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
760 EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate));
761
762 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.vote.rate.getValue(), 244.f);
763 EXPECT_EQ(getSnapshot({.id = 1221})->frameRateSelectionStrategy,
764 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
765 EXPECT_TRUE(getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::FrameRate));
766}
767
Vishnu Nair0808ae62023-08-07 21:42:42 -0700768TEST_F(LayerSnapshotTest, skipRoundCornersWhenProtected) {
769 setRoundedCorners(1, 42.f);
770 setRoundedCorners(2, 42.f);
771 setCrop(1, Rect{1000, 1000});
772 setCrop(2, Rect{1000, 1000});
773
774 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
775 EXPECT_TRUE(getSnapshot({.id = 1})->roundedCorner.hasRoundedCorners());
776 EXPECT_EQ(getSnapshot({.id = 1})->roundedCorner.radius.x, 42.f);
777 EXPECT_TRUE(getSnapshot({.id = 2})->roundedCorner.hasRoundedCorners());
778
779 // add a buffer with the protected bit, check rounded corners are not set when
780 // skipRoundCornersWhenProtected == true
781 setBuffer(1,
782 std::make_shared<
783 renderengine::mock::FakeExternalTexture>(1U /*width*/, 1U /*height*/,
784 1ULL /* bufferId */,
785 HAL_PIXEL_FORMAT_RGBA_8888,
786 GRALLOC_USAGE_PROTECTED /*usage*/));
787
788 LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(),
789 .layerLifecycleManager = mLifecycleManager,
790 .includeMetadata = false,
791 .displays = mFrontEndDisplayInfos,
792 .displayChanges = false,
793 .globalShadowSettings = globalShadowSettings,
794 .supportsBlur = true,
795 .supportedLayerGenericMetadata = {},
796 .genericLayerMetadataKeyMap = {},
797 .skipRoundCornersWhenProtected = true};
798 update(mSnapshotBuilder, args);
799 EXPECT_FALSE(getSnapshot({.id = 1})->roundedCorner.hasRoundedCorners());
800 // layer 2 doesn't have a buffer and should be unaffected
801 EXPECT_TRUE(getSnapshot({.id = 2})->roundedCorner.hasRoundedCorners());
802
803 // remove protected bit, check rounded corners are set
804 setBuffer(1,
805 std::make_shared<renderengine::mock::FakeExternalTexture>(1U /*width*/, 1U /*height*/,
806 2ULL /* bufferId */,
807 HAL_PIXEL_FORMAT_RGBA_8888,
808 0 /*usage*/));
809 update(mSnapshotBuilder, args);
810 EXPECT_TRUE(getSnapshot({.id = 1})->roundedCorner.hasRoundedCorners());
811 EXPECT_EQ(getSnapshot({.id = 1})->roundedCorner.radius.x, 42.f);
812}
813
Vishnu Nairbd51f952023-08-31 22:50:14 -0700814TEST_F(LayerSnapshotTest, setRefreshRateIndicatorCompositionType) {
815 setFlags(1, layer_state_t::eLayerIsRefreshRateIndicator,
816 layer_state_t::eLayerIsRefreshRateIndicator);
817 setBuffer(1,
818 std::make_shared<renderengine::mock::FakeExternalTexture>(1U /*width*/, 1U /*height*/,
819 42ULL /* bufferId */,
820 HAL_PIXEL_FORMAT_RGBA_8888,
821 0 /*usage*/));
822 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
823 EXPECT_EQ(getSnapshot({.id = 1})->compositionType,
824 aidl::android::hardware::graphics::composer3::Composition::REFRESH_RATE_INDICATOR);
825}
826
Chavi Weingarten07597342023-09-14 21:10:59 +0000827TEST_F(LayerSnapshotTest, setBufferCrop) {
828 // validate no buffer but has crop
829 Rect crop = Rect(0, 0, 50, 50);
830 setBufferCrop(1, crop);
831 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
832 EXPECT_EQ(getSnapshot(1)->geomContentCrop, crop);
833
834 setBuffer(1,
835 std::make_shared<renderengine::mock::FakeExternalTexture>(100U /*width*/,
836 100U /*height*/,
837 42ULL /* bufferId */,
838 HAL_PIXEL_FORMAT_RGBA_8888,
839 0 /*usage*/));
840 // validate a buffer crop within the buffer bounds
841 setBufferCrop(1, crop);
842 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
843 EXPECT_EQ(getSnapshot(1)->geomContentCrop, crop);
844
845 // validate a buffer crop outside the buffer bounds
846 crop = Rect(0, 0, 150, 150);
847 setBufferCrop(1, crop);
848 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
849 EXPECT_EQ(getSnapshot(1)->geomContentCrop, Rect(0, 0, 100, 100));
850
851 // validate no buffer crop
852 setBufferCrop(1, Rect());
853 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
854 EXPECT_EQ(getSnapshot(1)->geomContentCrop, Rect(0, 0, 100, 100));
855}
Vishnu Nairbefd3e22023-10-05 17:48:31 +0000856
857TEST_F(LayerSnapshotTest, setShadowRadius) {
858 static constexpr float SHADOW_RADIUS = 123.f;
859 setShadowRadius(1, SHADOW_RADIUS);
860 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
861 EXPECT_EQ(getSnapshot(1)->shadowSettings.length, SHADOW_RADIUS);
Vishnu Nairbefd3e22023-10-05 17:48:31 +0000862}
863
Chavi Weingartenb74093a2023-10-11 20:29:59 +0000864TEST_F(LayerSnapshotTest, setTrustedOverlayForNonVisibleInput) {
865 hideLayer(1);
866 setTrustedOverlay(1, true);
867 Region touch{Rect{0, 0, 1000, 1000}};
868 setTouchableRegion(1, touch);
869
870 UPDATE_AND_VERIFY(mSnapshotBuilder, {2});
871 EXPECT_TRUE(getSnapshot(1)->inputInfo.inputConfig.test(
872 gui::WindowInfo::InputConfig::TRUSTED_OVERLAY));
873}
874
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000875} // namespace android::surfaceflinger::frontend