blob: b8a7446b3a14a65fb740a72d278e4d576c3fc462 [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 Nair8fc721b2022-12-22 20:06:32 +000020#include "FrontEnd/LayerHierarchy.h"
21#include "FrontEnd/LayerLifecycleManager.h"
22#include "FrontEnd/LayerSnapshotBuilder.h"
Vishnu Nair8fc721b2022-12-22 20:06:32 +000023#include "LayerHierarchyTest.h"
24
25#define UPDATE_AND_VERIFY(BUILDER, ...) \
26 ({ \
27 SCOPED_TRACE(""); \
28 updateAndVerify((BUILDER), /*displayChanges=*/false, __VA_ARGS__); \
29 })
30
31#define UPDATE_AND_VERIFY_WITH_DISPLAY_CHANGES(BUILDER, ...) \
32 ({ \
33 SCOPED_TRACE(""); \
34 updateAndVerify((BUILDER), /*displayChanges=*/true, __VA_ARGS__); \
35 })
36
37namespace android::surfaceflinger::frontend {
38
Vishnu Naircfb2d252023-01-19 04:44:02 +000039using ftl::Flags;
40using namespace ftl::flag_operators;
41
Vishnu Nair8fc721b2022-12-22 20:06:32 +000042// To run test:
43/**
44 mp :libsurfaceflinger_unittest && adb sync; adb shell \
45 /data/nativetest/libsurfaceflinger_unittest/libsurfaceflinger_unittest \
46 --gtest_filter="LayerSnapshotTest.*" --gtest_brief=1
47*/
48
49class LayerSnapshotTest : public LayerHierarchyTestBase {
50protected:
51 LayerSnapshotTest() : LayerHierarchyTestBase() {
52 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
53 }
54
55 void createRootLayer(uint32_t id) override {
56 LayerHierarchyTestBase::createRootLayer(id);
57 setColor(id);
58 }
59
60 void createLayer(uint32_t id, uint32_t parentId) override {
61 LayerHierarchyTestBase::createLayer(id, parentId);
62 setColor(parentId);
63 }
64
65 void mirrorLayer(uint32_t id, uint32_t parent, uint32_t layerToMirror) override {
66 LayerHierarchyTestBase::mirrorLayer(id, parent, layerToMirror);
67 setColor(id);
68 }
69
70 void updateAndVerify(LayerSnapshotBuilder& actualBuilder, bool hasDisplayChanges,
71 const std::vector<uint32_t> expectedVisibleLayerIdsInZOrder) {
72 if (mLifecycleManager.getGlobalChanges().test(RequestedLayerState::Changes::Hierarchy)) {
73 mHierarchyBuilder.update(mLifecycleManager.getLayers(),
74 mLifecycleManager.getDestroyedLayers());
75 }
Vishnu Nairc765c6c2023-02-23 00:08:01 +000076 LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(),
77 .layerLifecycleManager = mLifecycleManager,
78 .includeMetadata = false,
79 .displays = mFrontEndDisplayInfos,
80 .displayChanges = hasDisplayChanges,
81 .globalShadowSettings = globalShadowSettings,
Vishnu Nair444f3952023-04-11 13:01:02 -070082 .supportsBlur = true,
Vishnu Nairc765c6c2023-02-23 00:08:01 +000083 .supportedLayerGenericMetadata = {},
84 .genericLayerMetadataKeyMap = {}};
Vishnu Nair8fc721b2022-12-22 20:06:32 +000085 actualBuilder.update(args);
86
87 // rebuild layer snapshots from scratch and verify that it matches the updated state.
88 LayerSnapshotBuilder expectedBuilder(args);
89 mLifecycleManager.commitChanges();
90 ASSERT_TRUE(expectedBuilder.getSnapshots().size() > 0);
91 ASSERT_TRUE(actualBuilder.getSnapshots().size() > 0);
92
Vishnu Nair8fc721b2022-12-22 20:06:32 +000093 std::vector<uint32_t> actualVisibleLayerIdsInZOrder;
Vishnu Naircfb2d252023-01-19 04:44:02 +000094 actualBuilder.forEachVisibleSnapshot(
95 [&actualVisibleLayerIdsInZOrder](const LayerSnapshot& snapshot) {
96 actualVisibleLayerIdsInZOrder.push_back(snapshot.path.id);
97 });
Vishnu Nair8fc721b2022-12-22 20:06:32 +000098 EXPECT_EQ(expectedVisibleLayerIdsInZOrder, actualVisibleLayerIdsInZOrder);
99 }
100
101 LayerSnapshot* getSnapshot(uint32_t layerId) { return mSnapshotBuilder.getSnapshot(layerId); }
Vishnu Nair92990e22023-02-24 20:01:05 +0000102 LayerSnapshot* getSnapshot(const LayerHierarchy::TraversalPath path) {
103 return mSnapshotBuilder.getSnapshot(path);
104 }
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000105
106 LayerHierarchyBuilder mHierarchyBuilder{{}};
107 LayerSnapshotBuilder mSnapshotBuilder;
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000108 display::DisplayMap<ui::LayerStack, frontend::DisplayInfo> mFrontEndDisplayInfos;
109 renderengine::ShadowSettings globalShadowSettings;
110 static const std::vector<uint32_t> STARTING_ZORDER;
111};
112const std::vector<uint32_t> LayerSnapshotTest::STARTING_ZORDER = {1, 11, 111, 12, 121,
113 122, 1221, 13, 2};
114
115TEST_F(LayerSnapshotTest, buildSnapshot) {
Vishnu Nairc765c6c2023-02-23 00:08:01 +0000116 LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(),
117 .layerLifecycleManager = mLifecycleManager,
118 .includeMetadata = false,
119 .displays = mFrontEndDisplayInfos,
120 .globalShadowSettings = globalShadowSettings,
121 .supportedLayerGenericMetadata = {},
122 .genericLayerMetadataKeyMap = {}};
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000123 LayerSnapshotBuilder builder(args);
124}
125
126TEST_F(LayerSnapshotTest, updateSnapshot) {
Vishnu Nairc765c6c2023-02-23 00:08:01 +0000127 LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(),
128 .layerLifecycleManager = mLifecycleManager,
129 .includeMetadata = false,
130 .displays = mFrontEndDisplayInfos,
131 .globalShadowSettings = globalShadowSettings,
132 .supportedLayerGenericMetadata = {},
133 .genericLayerMetadataKeyMap = {}
134
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000135 };
136
137 LayerSnapshotBuilder builder;
138 builder.update(args);
139}
140
141// update using parent snapshot data
142TEST_F(LayerSnapshotTest, croppedByParent) {
143 /// MAKE ALL LAYERS VISIBLE BY DEFAULT
144 DisplayInfo info;
145 info.info.logicalHeight = 100;
146 info.info.logicalWidth = 200;
147 mFrontEndDisplayInfos.emplace_or_replace(ui::LayerStack::fromValue(1), info);
148 Rect layerCrop(0, 0, 10, 20);
149 setCrop(11, layerCrop);
150 EXPECT_TRUE(mLifecycleManager.getGlobalChanges().test(RequestedLayerState::Changes::Geometry));
151 UPDATE_AND_VERIFY_WITH_DISPLAY_CHANGES(mSnapshotBuilder, STARTING_ZORDER);
152 EXPECT_EQ(getSnapshot(11)->geomCrop, layerCrop);
153 EXPECT_EQ(getSnapshot(111)->geomLayerBounds, layerCrop.toFloatRect());
154 float maxHeight = static_cast<float>(info.info.logicalHeight * 10);
155 float maxWidth = static_cast<float>(info.info.logicalWidth * 10);
156
157 FloatRect maxDisplaySize(-maxWidth, -maxHeight, maxWidth, maxHeight);
158 EXPECT_EQ(getSnapshot(1)->geomLayerBounds, maxDisplaySize);
159}
160
161// visibility tests
162TEST_F(LayerSnapshotTest, newLayerHiddenByPolicy) {
163 createLayer(112, 11);
164 hideLayer(112);
165 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
166
167 showLayer(112);
168 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 11, 111, 112, 12, 121, 122, 1221, 13, 2});
169}
170
171TEST_F(LayerSnapshotTest, hiddenByParent) {
172 hideLayer(11);
173 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 13, 2});
174}
175
176TEST_F(LayerSnapshotTest, reparentShowsChild) {
177 hideLayer(11);
178 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 13, 2});
179
180 showLayer(11);
181 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
182}
183
184TEST_F(LayerSnapshotTest, reparentHidesChild) {
185 hideLayer(11);
186 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 13, 2});
187
188 reparentLayer(121, 11);
189 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 122, 1221, 13, 2});
190}
191
192TEST_F(LayerSnapshotTest, unHidingUpdatesSnapshot) {
193 hideLayer(11);
194 Rect crop(1, 2, 3, 4);
195 setCrop(111, crop);
196 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 13, 2});
197
198 showLayer(11);
199 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
200 EXPECT_EQ(getSnapshot(111)->geomLayerBounds, crop.toFloatRect());
201}
202
203TEST_F(LayerSnapshotTest, childBehindParentCanBeHiddenByParent) {
204 setZ(111, -1);
205 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 111, 11, 12, 121, 122, 1221, 13, 2});
206
207 hideLayer(11);
208 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 13, 2});
209}
210
211// relative tests
212TEST_F(LayerSnapshotTest, RelativeParentCanHideChild) {
213 reparentRelativeLayer(13, 11);
214 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 11, 13, 111, 12, 121, 122, 1221, 2});
215
216 hideLayer(11);
217 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 2});
218}
219
220TEST_F(LayerSnapshotTest, ReparentingToHiddenRelativeParentHidesChild) {
221 hideLayer(11);
222 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 13, 2});
223 reparentRelativeLayer(13, 11);
224 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 2});
225}
226
227TEST_F(LayerSnapshotTest, AlphaInheritedByChildren) {
228 setAlpha(1, 0.5);
229 setAlpha(122, 0.5);
230 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
231 EXPECT_EQ(getSnapshot(12)->alpha, 0.5f);
232 EXPECT_EQ(getSnapshot(1221)->alpha, 0.25f);
233}
234
235// Change states
236TEST_F(LayerSnapshotTest, UpdateClearsPreviousChangeStates) {
237 setCrop(1, Rect(1, 2, 3, 4));
238 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
239 EXPECT_TRUE(getSnapshot(1)->changes.get() != 0);
240 EXPECT_TRUE(getSnapshot(11)->changes.get() != 0);
241 setCrop(2, Rect(1, 2, 3, 4));
242 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
243 EXPECT_TRUE(getSnapshot(2)->changes.get() != 0);
244 EXPECT_TRUE(getSnapshot(1)->changes.get() == 0);
245 EXPECT_TRUE(getSnapshot(11)->changes.get() == 0);
246}
247
248TEST_F(LayerSnapshotTest, FastPathClearsPreviousChangeStates) {
249 setColor(11, {1._hf, 0._hf, 0._hf});
250 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
251 EXPECT_TRUE(getSnapshot(11)->changes.get() != 0);
252 EXPECT_TRUE(getSnapshot(1)->changes.get() == 0);
253 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
254 EXPECT_TRUE(getSnapshot(11)->changes.get() == 0);
255}
256
257TEST_F(LayerSnapshotTest, FastPathSetsChangeFlagToContent) {
258 setColor(1, {1._hf, 0._hf, 0._hf});
259 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
260 EXPECT_EQ(getSnapshot(1)->changes, RequestedLayerState::Changes::Content);
261}
262
Vishnu Naircfb2d252023-01-19 04:44:02 +0000263TEST_F(LayerSnapshotTest, GameMode) {
264 std::vector<TransactionState> transactions;
265 transactions.emplace_back();
266 transactions.back().states.push_back({});
267 transactions.back().states.front().state.what = layer_state_t::eMetadataChanged;
268 transactions.back().states.front().state.metadata = LayerMetadata();
269 transactions.back().states.front().state.metadata.setInt32(METADATA_GAME_MODE, 42);
Vishnu Nair1391de22023-03-05 19:56:14 -0800270 transactions.back().states.front().layerId = 1;
Vishnu Naircfb2d252023-01-19 04:44:02 +0000271 transactions.back().states.front().state.layerId = static_cast<int32_t>(1);
272 mLifecycleManager.applyTransactions(transactions);
273 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
274 EXPECT_EQ(static_cast<int32_t>(getSnapshot(1)->gameMode), 42);
275 EXPECT_EQ(static_cast<int32_t>(getSnapshot(11)->gameMode), 42);
276}
277
278TEST_F(LayerSnapshotTest, NoLayerVoteForParentWithChildVotes) {
279 // ROOT
280 // ├── 1
281 // │ ├── 11 (frame rate set)
282 // │ │ └── 111
283 // │ ├── 12
284 // │ │ ├── 121
285 // │ │ └── 122
286 // │ │ └── 1221
287 // │ └── 13
288 // └── 2
289
290 std::vector<TransactionState> transactions;
291 transactions.emplace_back();
292 transactions.back().states.push_back({});
293 transactions.back().states.front().state.what = layer_state_t::eFrameRateChanged;
294 transactions.back().states.front().state.frameRate = 90.0;
295 transactions.back().states.front().state.frameRateCompatibility =
296 ANATIVEWINDOW_FRAME_RATE_EXACT;
297 transactions.back().states.front().state.changeFrameRateStrategy =
298 ANATIVEWINDOW_CHANGE_FRAME_RATE_ALWAYS;
Vishnu Nair1391de22023-03-05 19:56:14 -0800299 transactions.back().states.front().layerId = 11;
Vishnu Naircfb2d252023-01-19 04:44:02 +0000300 mLifecycleManager.applyTransactions(transactions);
301 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
302
303 EXPECT_EQ(getSnapshot(11)->frameRate.rate.getIntValue(), 90);
304 EXPECT_EQ(getSnapshot(11)->frameRate.type, scheduler::LayerInfo::FrameRateCompatibility::Exact);
305 EXPECT_EQ(getSnapshot(111)->frameRate.rate.getIntValue(), 90);
306 EXPECT_EQ(getSnapshot(111)->frameRate.type,
307 scheduler::LayerInfo::FrameRateCompatibility::Exact);
308 EXPECT_EQ(getSnapshot(1)->frameRate.rate.getIntValue(), 0);
309 EXPECT_EQ(getSnapshot(1)->frameRate.type, scheduler::LayerInfo::FrameRateCompatibility::NoVote);
310}
311
Vishnu Nair29354ec2023-03-28 18:51:28 -0700312TEST_F(LayerSnapshotTest, canCropTouchableRegion) {
313 // ROOT
314 // ├── 1
315 // │ ├── 11
316 // │ │ └── 111 (touchregion set to touch but cropped by layer 13)
317 // │ ├── 12
318 // │ │ ├── 121
319 // │ │ └── 122
320 // │ │ └── 1221
321 // │ └── 13 (crop set to touchCrop)
322 // └── 2
323
324 Rect touchCrop{300, 300, 400, 500};
325 setCrop(13, touchCrop);
326 Region touch{Rect{0, 0, 1000, 1000}};
327 setTouchableRegionCrop(111, touch, /*touchCropId=*/13, /*replaceTouchableRegionWithCrop=*/true);
328 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
329 EXPECT_EQ(getSnapshot({.id = 111})->inputInfo.touchableRegion.bounds(), touchCrop);
330
331 Rect modifiedTouchCrop{100, 300, 400, 700};
332 setCrop(13, modifiedTouchCrop);
333 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
334 EXPECT_EQ(getSnapshot({.id = 111})->inputInfo.touchableRegion.bounds(), modifiedTouchCrop);
335}
336
Vishnu Nair444f3952023-04-11 13:01:02 -0700337TEST_F(LayerSnapshotTest, blurUpdatesWhenAlphaChanges) {
338 static constexpr int blurRadius = 42;
339 setBackgroundBlurRadius(1221, blurRadius);
340
341 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
342 EXPECT_EQ(getSnapshot({.id = 1221})->backgroundBlurRadius, blurRadius);
343
344 static constexpr float alpha = 0.5;
345 setAlpha(12, alpha);
346 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
347 EXPECT_EQ(getSnapshot({.id = 1221})->backgroundBlurRadius, blurRadius * alpha);
348}
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);
391 EXPECT_EQ(getSnapshot({.id = 111, .mirrorRootId = 3})->outputFilter.layerStack.id, 3u);
392 EXPECT_EQ(getSnapshot({.id = 111, .mirrorRootId = 4})->outputFilter.layerStack.id, 4u);
393}
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}};
416 EXPECT_TRUE(getSnapshot({.id = 111, .mirrorRootId = 3})
417 ->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
443// Rel z doesn't create duplicate snapshots but this is for completeness
444TEST_F(LayerSnapshotTest, cleanUpUnreachableSnapshotsAfterRelZ) {
445 size_t startingNumSnapshots = mSnapshotBuilder.getSnapshots().size();
446 reparentRelativeLayer(13, 11);
447 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 11, 13, 111, 12, 121, 122, 1221, 2});
448 setZ(13, 0);
449 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
450
451 EXPECT_EQ(startingNumSnapshots, mSnapshotBuilder.getSnapshots().size());
452}
453
454TEST_F(LayerSnapshotTest, cleanUpUnreachableSnapshotsAfterLayerDestruction) {
455 size_t startingNumSnapshots = mSnapshotBuilder.getSnapshots().size();
456 destroyLayerHandle(2);
457 destroyLayerHandle(122);
458
459 std::vector<uint32_t> expected = {1, 11, 111, 12, 121, 122, 1221, 13};
460 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
461
462 EXPECT_LE(startingNumSnapshots - 2, mSnapshotBuilder.getSnapshots().size());
463}
464
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000465} // namespace android::surfaceflinger::frontend