blob: 67cd4c67ebf404b3862bdb88968fb66a38cf337a [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
53class LayerSnapshotTest : public LayerHierarchyTestBase {
54protected:
55 LayerSnapshotTest() : LayerHierarchyTestBase() {
56 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
57 }
58
59 void createRootLayer(uint32_t id) override {
60 LayerHierarchyTestBase::createRootLayer(id);
61 setColor(id);
62 }
63
64 void createLayer(uint32_t id, uint32_t parentId) override {
65 LayerHierarchyTestBase::createLayer(id, parentId);
66 setColor(parentId);
67 }
68
69 void mirrorLayer(uint32_t id, uint32_t parent, uint32_t layerToMirror) override {
70 LayerHierarchyTestBase::mirrorLayer(id, parent, layerToMirror);
71 setColor(id);
72 }
73
Vishnu Nair0808ae62023-08-07 21:42:42 -070074 void update(LayerSnapshotBuilder& actualBuilder, LayerSnapshotBuilder::Args& args) {
Vishnu Nair8fc721b2022-12-22 20:06:32 +000075 if (mLifecycleManager.getGlobalChanges().test(RequestedLayerState::Changes::Hierarchy)) {
76 mHierarchyBuilder.update(mLifecycleManager.getLayers(),
77 mLifecycleManager.getDestroyedLayers());
78 }
Vishnu Nair0808ae62023-08-07 21:42:42 -070079 args.root = mHierarchyBuilder.getHierarchy();
80 actualBuilder.update(args);
81 }
82
83 void updateAndVerify(LayerSnapshotBuilder& actualBuilder, bool hasDisplayChanges,
84 const std::vector<uint32_t> expectedVisibleLayerIdsInZOrder) {
Vishnu Nairc765c6c2023-02-23 00:08:01 +000085 LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(),
86 .layerLifecycleManager = mLifecycleManager,
87 .includeMetadata = false,
88 .displays = mFrontEndDisplayInfos,
89 .displayChanges = hasDisplayChanges,
90 .globalShadowSettings = globalShadowSettings,
Vishnu Nair444f3952023-04-11 13:01:02 -070091 .supportsBlur = true,
Vishnu Nairc765c6c2023-02-23 00:08:01 +000092 .supportedLayerGenericMetadata = {},
93 .genericLayerMetadataKeyMap = {}};
Vishnu Nair0808ae62023-08-07 21:42:42 -070094 update(actualBuilder, args);
Vishnu Nair8fc721b2022-12-22 20:06:32 +000095
96 // rebuild layer snapshots from scratch and verify that it matches the updated state.
97 LayerSnapshotBuilder expectedBuilder(args);
98 mLifecycleManager.commitChanges();
99 ASSERT_TRUE(expectedBuilder.getSnapshots().size() > 0);
100 ASSERT_TRUE(actualBuilder.getSnapshots().size() > 0);
101
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000102 std::vector<uint32_t> actualVisibleLayerIdsInZOrder;
Vishnu Naircfb2d252023-01-19 04:44:02 +0000103 actualBuilder.forEachVisibleSnapshot(
104 [&actualVisibleLayerIdsInZOrder](const LayerSnapshot& snapshot) {
105 actualVisibleLayerIdsInZOrder.push_back(snapshot.path.id);
106 });
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000107 EXPECT_EQ(expectedVisibleLayerIdsInZOrder, actualVisibleLayerIdsInZOrder);
108 }
109
110 LayerSnapshot* getSnapshot(uint32_t layerId) { return mSnapshotBuilder.getSnapshot(layerId); }
Vishnu Nair92990e22023-02-24 20:01:05 +0000111 LayerSnapshot* getSnapshot(const LayerHierarchy::TraversalPath path) {
112 return mSnapshotBuilder.getSnapshot(path);
113 }
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000114
115 LayerHierarchyBuilder mHierarchyBuilder{{}};
116 LayerSnapshotBuilder mSnapshotBuilder;
Dominik Laskowski6b049ff2023-01-29 15:46:45 -0500117 DisplayInfos mFrontEndDisplayInfos;
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000118 renderengine::ShadowSettings globalShadowSettings;
119 static const std::vector<uint32_t> STARTING_ZORDER;
120};
121const std::vector<uint32_t> LayerSnapshotTest::STARTING_ZORDER = {1, 11, 111, 12, 121,
122 122, 1221, 13, 2};
123
124TEST_F(LayerSnapshotTest, buildSnapshot) {
Vishnu Nairc765c6c2023-02-23 00:08:01 +0000125 LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(),
126 .layerLifecycleManager = mLifecycleManager,
127 .includeMetadata = false,
128 .displays = mFrontEndDisplayInfos,
129 .globalShadowSettings = globalShadowSettings,
130 .supportedLayerGenericMetadata = {},
131 .genericLayerMetadataKeyMap = {}};
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000132 LayerSnapshotBuilder builder(args);
133}
134
135TEST_F(LayerSnapshotTest, updateSnapshot) {
Vishnu Nairc765c6c2023-02-23 00:08:01 +0000136 LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(),
137 .layerLifecycleManager = mLifecycleManager,
138 .includeMetadata = false,
139 .displays = mFrontEndDisplayInfos,
140 .globalShadowSettings = globalShadowSettings,
141 .supportedLayerGenericMetadata = {},
142 .genericLayerMetadataKeyMap = {}
143
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000144 };
145
146 LayerSnapshotBuilder builder;
147 builder.update(args);
148}
149
150// update using parent snapshot data
151TEST_F(LayerSnapshotTest, croppedByParent) {
152 /// MAKE ALL LAYERS VISIBLE BY DEFAULT
153 DisplayInfo info;
154 info.info.logicalHeight = 100;
155 info.info.logicalWidth = 200;
156 mFrontEndDisplayInfos.emplace_or_replace(ui::LayerStack::fromValue(1), info);
157 Rect layerCrop(0, 0, 10, 20);
158 setCrop(11, layerCrop);
159 EXPECT_TRUE(mLifecycleManager.getGlobalChanges().test(RequestedLayerState::Changes::Geometry));
160 UPDATE_AND_VERIFY_WITH_DISPLAY_CHANGES(mSnapshotBuilder, STARTING_ZORDER);
161 EXPECT_EQ(getSnapshot(11)->geomCrop, layerCrop);
162 EXPECT_EQ(getSnapshot(111)->geomLayerBounds, layerCrop.toFloatRect());
163 float maxHeight = static_cast<float>(info.info.logicalHeight * 10);
164 float maxWidth = static_cast<float>(info.info.logicalWidth * 10);
165
166 FloatRect maxDisplaySize(-maxWidth, -maxHeight, maxWidth, maxHeight);
167 EXPECT_EQ(getSnapshot(1)->geomLayerBounds, maxDisplaySize);
168}
169
170// visibility tests
171TEST_F(LayerSnapshotTest, newLayerHiddenByPolicy) {
172 createLayer(112, 11);
173 hideLayer(112);
174 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
175
176 showLayer(112);
177 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 11, 111, 112, 12, 121, 122, 1221, 13, 2});
178}
179
180TEST_F(LayerSnapshotTest, hiddenByParent) {
181 hideLayer(11);
182 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 13, 2});
183}
184
185TEST_F(LayerSnapshotTest, reparentShowsChild) {
186 hideLayer(11);
187 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 13, 2});
188
189 showLayer(11);
190 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
191}
192
193TEST_F(LayerSnapshotTest, reparentHidesChild) {
194 hideLayer(11);
195 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 13, 2});
196
197 reparentLayer(121, 11);
198 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 122, 1221, 13, 2});
199}
200
201TEST_F(LayerSnapshotTest, unHidingUpdatesSnapshot) {
202 hideLayer(11);
203 Rect crop(1, 2, 3, 4);
204 setCrop(111, crop);
205 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 13, 2});
206
207 showLayer(11);
208 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
209 EXPECT_EQ(getSnapshot(111)->geomLayerBounds, crop.toFloatRect());
210}
211
212TEST_F(LayerSnapshotTest, childBehindParentCanBeHiddenByParent) {
213 setZ(111, -1);
214 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 111, 11, 12, 121, 122, 1221, 13, 2});
215
216 hideLayer(11);
217 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 13, 2});
218}
219
220// relative tests
221TEST_F(LayerSnapshotTest, RelativeParentCanHideChild) {
222 reparentRelativeLayer(13, 11);
223 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 11, 13, 111, 12, 121, 122, 1221, 2});
224
225 hideLayer(11);
226 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 2});
227}
228
229TEST_F(LayerSnapshotTest, ReparentingToHiddenRelativeParentHidesChild) {
230 hideLayer(11);
231 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 13, 2});
232 reparentRelativeLayer(13, 11);
233 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 2});
234}
235
236TEST_F(LayerSnapshotTest, AlphaInheritedByChildren) {
237 setAlpha(1, 0.5);
238 setAlpha(122, 0.5);
239 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
Vishnu Naira02943f2023-06-03 13:44:46 -0700240 EXPECT_EQ(getSnapshot(1)->alpha, 0.5f);
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000241 EXPECT_EQ(getSnapshot(12)->alpha, 0.5f);
242 EXPECT_EQ(getSnapshot(1221)->alpha, 0.25f);
243}
244
245// Change states
246TEST_F(LayerSnapshotTest, UpdateClearsPreviousChangeStates) {
247 setCrop(1, Rect(1, 2, 3, 4));
248 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
Vishnu Naira02943f2023-06-03 13:44:46 -0700249 EXPECT_TRUE(getSnapshot(1)->changes.test(RequestedLayerState::Changes::Geometry));
250 EXPECT_TRUE(getSnapshot(11)->changes.test(RequestedLayerState::Changes::Geometry));
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000251 setCrop(2, Rect(1, 2, 3, 4));
252 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
Vishnu Naira02943f2023-06-03 13:44:46 -0700253 EXPECT_TRUE(getSnapshot(2)->changes.test(RequestedLayerState::Changes::Geometry));
254 EXPECT_FALSE(getSnapshot(1)->changes.test(RequestedLayerState::Changes::Geometry));
255 EXPECT_FALSE(getSnapshot(11)->changes.test(RequestedLayerState::Changes::Geometry));
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000256}
257
258TEST_F(LayerSnapshotTest, FastPathClearsPreviousChangeStates) {
259 setColor(11, {1._hf, 0._hf, 0._hf});
260 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
Vishnu Naira02943f2023-06-03 13:44:46 -0700261 EXPECT_EQ(getSnapshot(11)->changes, RequestedLayerState::Changes::Content);
262 EXPECT_EQ(getSnapshot(11)->clientChanges, layer_state_t::eColorChanged);
263 EXPECT_EQ(getSnapshot(1)->changes.get(), 0u);
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000264 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
Vishnu Naira02943f2023-06-03 13:44:46 -0700265 EXPECT_EQ(getSnapshot(11)->changes.get(), 0u);
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000266}
267
268TEST_F(LayerSnapshotTest, FastPathSetsChangeFlagToContent) {
269 setColor(1, {1._hf, 0._hf, 0._hf});
270 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
271 EXPECT_EQ(getSnapshot(1)->changes, RequestedLayerState::Changes::Content);
Vishnu Naira02943f2023-06-03 13:44:46 -0700272 EXPECT_EQ(getSnapshot(1)->clientChanges, layer_state_t::eColorChanged);
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000273}
274
Vishnu Naircfb2d252023-01-19 04:44:02 +0000275TEST_F(LayerSnapshotTest, GameMode) {
276 std::vector<TransactionState> transactions;
277 transactions.emplace_back();
278 transactions.back().states.push_back({});
279 transactions.back().states.front().state.what = layer_state_t::eMetadataChanged;
280 transactions.back().states.front().state.metadata = LayerMetadata();
281 transactions.back().states.front().state.metadata.setInt32(METADATA_GAME_MODE, 42);
Vishnu Nair1391de22023-03-05 19:56:14 -0800282 transactions.back().states.front().layerId = 1;
Vishnu Naircfb2d252023-01-19 04:44:02 +0000283 transactions.back().states.front().state.layerId = static_cast<int32_t>(1);
284 mLifecycleManager.applyTransactions(transactions);
Vishnu Naira02943f2023-06-03 13:44:46 -0700285 EXPECT_EQ(mLifecycleManager.getGlobalChanges(), RequestedLayerState::Changes::GameMode);
Vishnu Naircfb2d252023-01-19 04:44:02 +0000286 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
Vishnu Naira02943f2023-06-03 13:44:46 -0700287 EXPECT_EQ(getSnapshot(1)->clientChanges, layer_state_t::eMetadataChanged);
Vishnu Naircfb2d252023-01-19 04:44:02 +0000288 EXPECT_EQ(static_cast<int32_t>(getSnapshot(1)->gameMode), 42);
289 EXPECT_EQ(static_cast<int32_t>(getSnapshot(11)->gameMode), 42);
290}
291
292TEST_F(LayerSnapshotTest, NoLayerVoteForParentWithChildVotes) {
293 // ROOT
294 // ├── 1
295 // │ ├── 11 (frame rate set)
296 // │ │ └── 111
297 // │ ├── 12
298 // │ │ ├── 121
299 // │ │ └── 122
300 // │ │ └── 1221
301 // │ └── 13
302 // └── 2
303
304 std::vector<TransactionState> transactions;
305 transactions.emplace_back();
306 transactions.back().states.push_back({});
307 transactions.back().states.front().state.what = layer_state_t::eFrameRateChanged;
308 transactions.back().states.front().state.frameRate = 90.0;
309 transactions.back().states.front().state.frameRateCompatibility =
310 ANATIVEWINDOW_FRAME_RATE_EXACT;
311 transactions.back().states.front().state.changeFrameRateStrategy =
312 ANATIVEWINDOW_CHANGE_FRAME_RATE_ALWAYS;
Vishnu Nair1391de22023-03-05 19:56:14 -0800313 transactions.back().states.front().layerId = 11;
Vishnu Naircfb2d252023-01-19 04:44:02 +0000314 mLifecycleManager.applyTransactions(transactions);
315 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
316
Rachel Leece6e0042023-06-27 11:22:54 -0700317 EXPECT_EQ(getSnapshot(11)->frameRate.vote.rate.getIntValue(), 90);
318 EXPECT_EQ(getSnapshot(11)->frameRate.vote.type,
Vishnu Naircfb2d252023-01-19 04:44:02 +0000319 scheduler::LayerInfo::FrameRateCompatibility::Exact);
Rachel Leece6e0042023-06-27 11:22:54 -0700320 EXPECT_EQ(getSnapshot(111)->frameRate.vote.rate.getIntValue(), 90);
321 EXPECT_EQ(getSnapshot(111)->frameRate.vote.type,
322 scheduler::LayerInfo::FrameRateCompatibility::Exact);
323 EXPECT_EQ(getSnapshot(1)->frameRate.vote.rate.getIntValue(), 0);
324 EXPECT_EQ(getSnapshot(1)->frameRate.vote.type,
325 scheduler::LayerInfo::FrameRateCompatibility::NoVote);
Vishnu Naircfb2d252023-01-19 04:44:02 +0000326}
327
Vishnu Naira02943f2023-06-03 13:44:46 -0700328TEST_F(LayerSnapshotTest, CanCropTouchableRegion) {
Vishnu Nair29354ec2023-03-28 18:51:28 -0700329 // ROOT
330 // ├── 1
331 // │ ├── 11
332 // │ │ └── 111 (touchregion set to touch but cropped by layer 13)
333 // │ ├── 12
334 // │ │ ├── 121
335 // │ │ └── 122
336 // │ │ └── 1221
337 // │ └── 13 (crop set to touchCrop)
338 // └── 2
339
340 Rect touchCrop{300, 300, 400, 500};
341 setCrop(13, touchCrop);
342 Region touch{Rect{0, 0, 1000, 1000}};
343 setTouchableRegionCrop(111, touch, /*touchCropId=*/13, /*replaceTouchableRegionWithCrop=*/true);
344 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
345 EXPECT_EQ(getSnapshot({.id = 111})->inputInfo.touchableRegion.bounds(), touchCrop);
346
347 Rect modifiedTouchCrop{100, 300, 400, 700};
348 setCrop(13, modifiedTouchCrop);
349 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
350 EXPECT_EQ(getSnapshot({.id = 111})->inputInfo.touchableRegion.bounds(), modifiedTouchCrop);
351}
352
Vishnu Nair444f3952023-04-11 13:01:02 -0700353TEST_F(LayerSnapshotTest, blurUpdatesWhenAlphaChanges) {
354 static constexpr int blurRadius = 42;
355 setBackgroundBlurRadius(1221, blurRadius);
356
357 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
358 EXPECT_EQ(getSnapshot({.id = 1221})->backgroundBlurRadius, blurRadius);
359
360 static constexpr float alpha = 0.5;
361 setAlpha(12, alpha);
362 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
363 EXPECT_EQ(getSnapshot({.id = 1221})->backgroundBlurRadius, blurRadius * alpha);
364}
365
Vishnu Naira9c43762023-01-27 19:10:25 +0000366// Display Mirroring Tests
367// tree with 3 levels of children
368// ROOT (DISPLAY 0)
369// ├── 1
370// │ ├── 11
371// │ │ └── 111
372// │ ├── 12 (has skip screenshot flag)
373// │ │ ├── 121
374// │ │ └── 122
375// │ │ └── 1221
376// │ └── 13
377// └── 2
378// ROOT (DISPLAY 1)
379// └── 3 (mirrors display 0)
Vishnu Nair92990e22023-02-24 20:01:05 +0000380TEST_F(LayerSnapshotTest, displayMirrorRespectsLayerSkipScreenshotFlag) {
Vishnu Naira9c43762023-01-27 19:10:25 +0000381 setFlags(12, layer_state_t::eLayerSkipScreenshot, layer_state_t::eLayerSkipScreenshot);
382 createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0));
383 setLayerStack(3, 1);
384
Vishnu Nair444f3952023-04-11 13:01:02 -0700385 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 +0000386 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
387}
388
Vishnu Nair92990e22023-02-24 20:01:05 +0000389// ROOT (DISPLAY 0)
390// ├── 1
391// │ ├── 11
392// │ │ └── 111
393// │ └── 13
394// └── 2
395// ROOT (DISPLAY 3)
396// └── 3 (mirrors display 0)
397TEST_F(LayerSnapshotTest, mirrorLayerGetsCorrectLayerStack) {
398 reparentLayer(12, UNASSIGNED_LAYER_ID);
399 createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0));
400 setLayerStack(3, 3);
401 createDisplayMirrorLayer(4, ui::LayerStack::fromValue(0));
402 setLayerStack(4, 4);
403
Vishnu Nair444f3952023-04-11 13:01:02 -0700404 std::vector<uint32_t> expected = {1, 11, 111, 13, 2, 3, 1, 11, 111,
405 13, 2, 4, 1, 11, 111, 13, 2};
Vishnu Nair92990e22023-02-24 20:01:05 +0000406 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
407 EXPECT_EQ(getSnapshot({.id = 111, .mirrorRootId = 3})->outputFilter.layerStack.id, 3u);
408 EXPECT_EQ(getSnapshot({.id = 111, .mirrorRootId = 4})->outputFilter.layerStack.id, 4u);
409}
410
411// ROOT (DISPLAY 0)
412// ├── 1 (crop 50x50)
413// │ ├── 11
414// │ │ └── 111
415// │ └── 13
416// └── 2
417// ROOT (DISPLAY 3)
418// └── 3 (mirrors display 0) (crop 100x100)
419TEST_F(LayerSnapshotTest, mirrorLayerTouchIsCroppedByMirrorRoot) {
420 reparentLayer(12, UNASSIGNED_LAYER_ID);
421 createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0));
422 setLayerStack(3, 3);
423 setCrop(1, Rect{50, 50});
424 setCrop(3, Rect{100, 100});
425 setCrop(111, Rect{200, 200});
426 Region touch{Rect{0, 0, 1000, 1000}};
427 setTouchableRegion(111, touch);
Vishnu Nair444f3952023-04-11 13:01:02 -0700428 std::vector<uint32_t> expected = {1, 11, 111, 13, 2, 3, 1, 11, 111, 13, 2};
Vishnu Nair92990e22023-02-24 20:01:05 +0000429 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
430 EXPECT_TRUE(getSnapshot({.id = 111})->inputInfo.touchableRegion.hasSameRects(touch));
431 Region touchCroppedByMirrorRoot{Rect{0, 0, 50, 50}};
432 EXPECT_TRUE(getSnapshot({.id = 111, .mirrorRootId = 3})
433 ->inputInfo.touchableRegion.hasSameRects(touchCroppedByMirrorRoot));
434}
435
436TEST_F(LayerSnapshotTest, canRemoveDisplayMirror) {
437 setFlags(12, layer_state_t::eLayerSkipScreenshot, layer_state_t::eLayerSkipScreenshot);
438 createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0));
439 setLayerStack(3, 1);
Vishnu Nair444f3952023-04-11 13:01:02 -0700440 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 +0000441 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
442 destroyLayerHandle(3);
443 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
444}
445
Vishnu Nairfccd6362023-02-24 23:39:53 +0000446TEST_F(LayerSnapshotTest, cleanUpUnreachableSnapshotsAfterMirroring) {
447 size_t startingNumSnapshots = mSnapshotBuilder.getSnapshots().size();
448 createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0));
449 setLayerStack(3, 1);
Vishnu Nair444f3952023-04-11 13:01:02 -0700450 std::vector<uint32_t> expected = {1, 11, 111, 12, 121, 122, 1221, 13, 2, 3,
451 1, 11, 111, 12, 121, 122, 1221, 13, 2};
Vishnu Nairfccd6362023-02-24 23:39:53 +0000452 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
453 destroyLayerHandle(3);
454 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
455
456 EXPECT_EQ(startingNumSnapshots, mSnapshotBuilder.getSnapshots().size());
457}
458
459// Rel z doesn't create duplicate snapshots but this is for completeness
460TEST_F(LayerSnapshotTest, cleanUpUnreachableSnapshotsAfterRelZ) {
461 size_t startingNumSnapshots = mSnapshotBuilder.getSnapshots().size();
462 reparentRelativeLayer(13, 11);
463 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 11, 13, 111, 12, 121, 122, 1221, 2});
464 setZ(13, 0);
465 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
466
467 EXPECT_EQ(startingNumSnapshots, mSnapshotBuilder.getSnapshots().size());
468}
469
470TEST_F(LayerSnapshotTest, cleanUpUnreachableSnapshotsAfterLayerDestruction) {
471 size_t startingNumSnapshots = mSnapshotBuilder.getSnapshots().size();
472 destroyLayerHandle(2);
473 destroyLayerHandle(122);
474
475 std::vector<uint32_t> expected = {1, 11, 111, 12, 121, 122, 1221, 13};
476 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
477
478 EXPECT_LE(startingNumSnapshots - 2, mSnapshotBuilder.getSnapshots().size());
479}
480
Vishnu Nair3d8565a2023-06-30 07:23:24 +0000481TEST_F(LayerSnapshotTest, snashotContainsMetadataFromLayerCreationArgs) {
482 LayerCreationArgs args(std::make_optional<uint32_t>(200));
483 args.name = "testlayer";
484 args.addToRoot = true;
485 args.metadata.setInt32(42, 24);
486
487 std::vector<std::unique_ptr<RequestedLayerState>> layers;
488 layers.emplace_back(std::make_unique<RequestedLayerState>(args));
489 EXPECT_TRUE(layers.back()->metadata.has(42));
490 EXPECT_EQ(layers.back()->metadata.getInt32(42, 0), 24);
491 mLifecycleManager.addLayers(std::move(layers));
492
493 std::vector<uint32_t> expected = STARTING_ZORDER;
494 expected.push_back(200);
495 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
496
497 EXPECT_TRUE(mSnapshotBuilder.getSnapshot(200)->layerMetadata.has(42));
498 EXPECT_EQ(mSnapshotBuilder.getSnapshot(200)->layerMetadata.getInt32(42, 0), 24);
499}
500
501TEST_F(LayerSnapshotTest, frameRateSelectionPriorityPassedToChildLayers) {
502 setFrameRateSelectionPriority(11, 1);
503
504 setFrameRateSelectionPriority(12, 2);
505
506 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
507 EXPECT_EQ(getSnapshot({.id = 1})->frameRateSelectionPriority, Layer::PRIORITY_UNSET);
508 EXPECT_EQ(getSnapshot({.id = 11})->frameRateSelectionPriority, 1);
509 EXPECT_EQ(getSnapshot({.id = 12})->frameRateSelectionPriority, 2);
510 EXPECT_EQ(getSnapshot({.id = 122})->frameRateSelectionPriority, 2);
511 EXPECT_EQ(getSnapshot({.id = 1221})->frameRateSelectionPriority, 2);
512
513 // reparent and verify the child gets the new parent's framerate selection priority
514 reparentLayer(122, 11);
515
516 std::vector<uint32_t> expected = {1, 11, 111, 122, 1221, 12, 121, 13, 2};
517 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
518 EXPECT_EQ(getSnapshot({.id = 1})->frameRateSelectionPriority, Layer::PRIORITY_UNSET);
519 EXPECT_EQ(getSnapshot({.id = 11})->frameRateSelectionPriority, 1);
520 EXPECT_EQ(getSnapshot({.id = 12})->frameRateSelectionPriority, 2);
521 EXPECT_EQ(getSnapshot({.id = 122})->frameRateSelectionPriority, 1);
522 EXPECT_EQ(getSnapshot({.id = 1221})->frameRateSelectionPriority, 1);
523}
524
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000525TEST_F(LayerSnapshotTest, framerate) {
526 setFrameRate(11, 244.f, 0, 0);
527
528 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
529 // verify parent is gets no vote
Rachel Leece6e0042023-06-27 11:22:54 -0700530 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
531 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000532 scheduler::LayerInfo::FrameRateCompatibility::NoVote);
533 EXPECT_TRUE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate));
534
535 // verify layer and children get the requested votes
Rachel Leece6e0042023-06-27 11:22:54 -0700536 EXPECT_TRUE(getSnapshot({.id = 11})->frameRate.vote.rate.isValid());
537 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 244.f);
538 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.type,
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000539 scheduler::LayerInfo::FrameRateCompatibility::Default);
540 EXPECT_TRUE(getSnapshot({.id = 11})->changes.test(RequestedLayerState::Changes::FrameRate));
541
Rachel Leece6e0042023-06-27 11:22:54 -0700542 EXPECT_TRUE(getSnapshot({.id = 111})->frameRate.vote.rate.isValid());
543 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.rate.getValue(), 244.f);
544 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.type,
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000545 scheduler::LayerInfo::FrameRateCompatibility::Default);
546 EXPECT_TRUE(getSnapshot({.id = 111})->changes.test(RequestedLayerState::Changes::FrameRate));
547
548 // reparent and verify the child gets the new parent's framerate
549 reparentLayer(122, 11);
550
551 std::vector<uint32_t> expected = {1, 11, 111, 122, 1221, 12, 121, 13, 2};
552 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
553 // verify parent is gets no vote
Rachel Leece6e0042023-06-27 11:22:54 -0700554 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
555 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000556 scheduler::LayerInfo::FrameRateCompatibility::NoVote);
557
558 // verify layer and children get the requested votes
Rachel Leece6e0042023-06-27 11:22:54 -0700559 EXPECT_TRUE(getSnapshot({.id = 11})->frameRate.vote.rate.isValid());
560 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 244.f);
561 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.type,
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000562 scheduler::LayerInfo::FrameRateCompatibility::Default);
563
Rachel Leece6e0042023-06-27 11:22:54 -0700564 EXPECT_TRUE(getSnapshot({.id = 111})->frameRate.vote.rate.isValid());
565 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.rate.getValue(), 244.f);
566 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.type,
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000567 scheduler::LayerInfo::FrameRateCompatibility::Default);
568
Rachel Leece6e0042023-06-27 11:22:54 -0700569 EXPECT_TRUE(getSnapshot({.id = 122})->frameRate.vote.rate.isValid());
570 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.rate.getValue(), 244.f);
571 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.type,
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000572 scheduler::LayerInfo::FrameRateCompatibility::Default);
573 EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate));
574
575 // reparent and verify the new parent gets no vote
576 reparentLayer(11, 2);
577 expected = {1, 12, 121, 13, 2, 11, 111, 122, 1221};
578 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
579
580 // verify old parent has invalid framerate (default)
Rachel Leece6e0042023-06-27 11:22:54 -0700581 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
582 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000583 scheduler::LayerInfo::FrameRateCompatibility::Default);
584 EXPECT_TRUE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate));
585
586 // verify new parent get no vote
Rachel Leece6e0042023-06-27 11:22:54 -0700587 EXPECT_FALSE(getSnapshot({.id = 2})->frameRate.vote.rate.isValid());
588 EXPECT_EQ(getSnapshot({.id = 2})->frameRate.vote.type,
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000589 scheduler::LayerInfo::FrameRateCompatibility::NoVote);
590 EXPECT_TRUE(getSnapshot({.id = 2})->changes.test(RequestedLayerState::Changes::FrameRate));
591
592 // verify layer and children get the requested votes (unchanged)
Rachel Leece6e0042023-06-27 11:22:54 -0700593 EXPECT_TRUE(getSnapshot({.id = 11})->frameRate.vote.rate.isValid());
594 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 244.f);
595 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.type,
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000596 scheduler::LayerInfo::FrameRateCompatibility::Default);
597
Rachel Leece6e0042023-06-27 11:22:54 -0700598 EXPECT_TRUE(getSnapshot({.id = 111})->frameRate.vote.rate.isValid());
599 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.rate.getValue(), 244.f);
600 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.type,
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000601 scheduler::LayerInfo::FrameRateCompatibility::Default);
602
Rachel Leece6e0042023-06-27 11:22:54 -0700603 EXPECT_TRUE(getSnapshot({.id = 122})->frameRate.vote.rate.isValid());
604 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.rate.getValue(), 244.f);
605 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.type,
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000606 scheduler::LayerInfo::FrameRateCompatibility::Default);
607}
608
Vishnu Nair3996ee32023-08-14 04:32:31 +0000609TEST_F(LayerSnapshotTest, translateDataspace) {
610 setDataspace(1, ui::Dataspace::UNKNOWN);
611 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
612 EXPECT_EQ(getSnapshot({.id = 1})->dataspace, ui::Dataspace::V0_SRGB);
613}
614
Rachel Leece6e0042023-06-27 11:22:54 -0700615// This test is similar to "frameRate" test case but checks that the setFrameRateCategory API
616// interaction also works correctly with the setFrameRate API within SF frontend.
617TEST_F(LayerSnapshotTest, frameRateWithCategory) {
618 // ROOT
619 // ├── 1
620 // │ ├── 11 (frame rate set to 244.f)
621 // │ │ └── 111
622 // │ ├── 12
623 // │ │ ├── 121
624 // │ │ └── 122 (frame rate category set to Normal)
625 // │ │ └── 1221
626 // │ └── 13
627 // └── 2
628 setFrameRate(11, 244.f, 0, 0);
629 setFrameRateCategory(122, 3 /* Normal */);
630
631 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
632 // verify parent 1 gets no vote
633 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
634 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
635 scheduler::LayerInfo::FrameRateCompatibility::NoVote);
636 EXPECT_TRUE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate));
637
638 // verify layer 11 and children 111 get the requested votes
639 EXPECT_TRUE(getSnapshot({.id = 11})->frameRate.vote.rate.isValid());
640 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 244.f);
641 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.type,
642 scheduler::LayerInfo::FrameRateCompatibility::Default);
643 EXPECT_TRUE(getSnapshot({.id = 11})->changes.test(RequestedLayerState::Changes::FrameRate));
644
645 EXPECT_TRUE(getSnapshot({.id = 111})->frameRate.vote.rate.isValid());
646 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.rate.getValue(), 244.f);
647 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.type,
648 scheduler::LayerInfo::FrameRateCompatibility::Default);
649 EXPECT_TRUE(getSnapshot({.id = 111})->changes.test(RequestedLayerState::Changes::FrameRate));
650
651 // verify parent 12 gets no vote
652 EXPECT_FALSE(getSnapshot({.id = 12})->frameRate.vote.rate.isValid());
653 EXPECT_EQ(getSnapshot({.id = 12})->frameRate.vote.type,
654 scheduler::LayerInfo::FrameRateCompatibility::NoVote);
655 EXPECT_TRUE(getSnapshot({.id = 12})->changes.test(RequestedLayerState::Changes::FrameRate));
656
657 // verify layer 122 and children 1221 get the requested votes
658 EXPECT_FALSE(getSnapshot({.id = 122})->frameRate.vote.rate.isValid());
659 EXPECT_TRUE(getSnapshot({.id = 122})->frameRate.isValid());
660 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.type,
661 scheduler::LayerInfo::FrameRateCompatibility::Default);
662 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.category, FrameRateCategory::Normal);
663 EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate));
664
665 EXPECT_FALSE(getSnapshot({.id = 1221})->frameRate.vote.rate.isValid());
666 EXPECT_TRUE(getSnapshot({.id = 1221})->frameRate.isValid());
667 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.vote.type,
668 scheduler::LayerInfo::FrameRateCompatibility::Default);
669 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.category, FrameRateCategory::Normal);
670 EXPECT_TRUE(getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::FrameRate));
671
672 // reparent and verify the child does NOT get the new parent's framerate because it already has
673 // the frame rate category specified.
674 // ROOT
675 // ├─1
676 // │ ├─11 (frame rate set to 244.f)
677 // │ │ ├─111
678 // │ │ └─122 (frame rate category set to Normal)
679 // │ │ └─1221
680 // │ ├─12
681 // │ │ └─121
682 // │ └─13
683 // └─2
684 reparentLayer(122, 11);
685
686 std::vector<uint32_t> expected = {1, 11, 111, 122, 1221, 12, 121, 13, 2};
687 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
688 // verify parent is gets no vote
689 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
690 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
691 scheduler::LayerInfo::FrameRateCompatibility::NoVote);
692
693 // verify layer 11 and children 111 get the requested votes
694 EXPECT_TRUE(getSnapshot({.id = 11})->frameRate.vote.rate.isValid());
695 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 244.f);
696 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.type,
697 scheduler::LayerInfo::FrameRateCompatibility::Default);
698
699 EXPECT_TRUE(getSnapshot({.id = 111})->frameRate.vote.rate.isValid());
700 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.rate.getValue(), 244.f);
701 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.type,
702 scheduler::LayerInfo::FrameRateCompatibility::Default);
703
704 // verify layer 122 and children 1221 get the requested category vote (unchanged from
705 // reparenting)
706 EXPECT_FALSE(getSnapshot({.id = 122})->frameRate.vote.rate.isValid());
707 EXPECT_TRUE(getSnapshot({.id = 122})->frameRate.isValid());
708 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.type,
709 scheduler::LayerInfo::FrameRateCompatibility::Default);
710 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.category, FrameRateCategory::Normal);
711 EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate));
712
713 EXPECT_FALSE(getSnapshot({.id = 1221})->frameRate.vote.rate.isValid());
714 EXPECT_TRUE(getSnapshot({.id = 1221})->frameRate.isValid());
715 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.vote.type,
716 scheduler::LayerInfo::FrameRateCompatibility::Default);
717 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.category, FrameRateCategory::Normal);
718 EXPECT_TRUE(getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::FrameRate));
719}
720
Vishnu Nair0808ae62023-08-07 21:42:42 -0700721TEST_F(LayerSnapshotTest, skipRoundCornersWhenProtected) {
722 setRoundedCorners(1, 42.f);
723 setRoundedCorners(2, 42.f);
724 setCrop(1, Rect{1000, 1000});
725 setCrop(2, Rect{1000, 1000});
726
727 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
728 EXPECT_TRUE(getSnapshot({.id = 1})->roundedCorner.hasRoundedCorners());
729 EXPECT_EQ(getSnapshot({.id = 1})->roundedCorner.radius.x, 42.f);
730 EXPECT_TRUE(getSnapshot({.id = 2})->roundedCorner.hasRoundedCorners());
731
732 // add a buffer with the protected bit, check rounded corners are not set when
733 // skipRoundCornersWhenProtected == true
734 setBuffer(1,
735 std::make_shared<
736 renderengine::mock::FakeExternalTexture>(1U /*width*/, 1U /*height*/,
737 1ULL /* bufferId */,
738 HAL_PIXEL_FORMAT_RGBA_8888,
739 GRALLOC_USAGE_PROTECTED /*usage*/));
740
741 LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(),
742 .layerLifecycleManager = mLifecycleManager,
743 .includeMetadata = false,
744 .displays = mFrontEndDisplayInfos,
745 .displayChanges = false,
746 .globalShadowSettings = globalShadowSettings,
747 .supportsBlur = true,
748 .supportedLayerGenericMetadata = {},
749 .genericLayerMetadataKeyMap = {},
750 .skipRoundCornersWhenProtected = true};
751 update(mSnapshotBuilder, args);
752 EXPECT_FALSE(getSnapshot({.id = 1})->roundedCorner.hasRoundedCorners());
753 // layer 2 doesn't have a buffer and should be unaffected
754 EXPECT_TRUE(getSnapshot({.id = 2})->roundedCorner.hasRoundedCorners());
755
756 // remove protected bit, check rounded corners are set
757 setBuffer(1,
758 std::make_shared<renderengine::mock::FakeExternalTexture>(1U /*width*/, 1U /*height*/,
759 2ULL /* bufferId */,
760 HAL_PIXEL_FORMAT_RGBA_8888,
761 0 /*usage*/));
762 update(mSnapshotBuilder, args);
763 EXPECT_TRUE(getSnapshot({.id = 1})->roundedCorner.hasRoundedCorners());
764 EXPECT_EQ(getSnapshot({.id = 1})->roundedCorner.radius.x, 42.f);
765}
766
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000767} // namespace android::surfaceflinger::frontend