blob: cdf078b1ea2570ed8a7662635cd2d6ad305d9890 [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) {
Vishnu Nair854ce1c2023-08-19 15:00:13 -0700354 int blurRadius = 42;
355 setBackgroundBlurRadius(1221, static_cast<uint32_t>(blurRadius));
Vishnu Nair444f3952023-04-11 13:01:02 -0700356
357 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
358 EXPECT_EQ(getSnapshot({.id = 1221})->backgroundBlurRadius, blurRadius);
359
Vishnu Nair854ce1c2023-08-19 15:00:13 -0700360 blurRadius = 21;
361 setBackgroundBlurRadius(1221, static_cast<uint32_t>(blurRadius));
362 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
363 EXPECT_EQ(getSnapshot({.id = 1221})->backgroundBlurRadius, blurRadius);
364
Vishnu Nair444f3952023-04-11 13:01:02 -0700365 static constexpr float alpha = 0.5;
366 setAlpha(12, alpha);
367 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
Vishnu Nair854ce1c2023-08-19 15:00:13 -0700368 EXPECT_EQ(getSnapshot({.id = 1221})->backgroundBlurRadius,
369 static_cast<int>(static_cast<float>(blurRadius) * alpha));
Vishnu Nair444f3952023-04-11 13:01:02 -0700370}
371
Vishnu Naira9c43762023-01-27 19:10:25 +0000372// Display Mirroring Tests
373// tree with 3 levels of children
374// ROOT (DISPLAY 0)
375// ├── 1
376// │ ├── 11
377// │ │ └── 111
378// │ ├── 12 (has skip screenshot flag)
379// │ │ ├── 121
380// │ │ └── 122
381// │ │ └── 1221
382// │ └── 13
383// └── 2
384// ROOT (DISPLAY 1)
385// └── 3 (mirrors display 0)
Vishnu Nair92990e22023-02-24 20:01:05 +0000386TEST_F(LayerSnapshotTest, displayMirrorRespectsLayerSkipScreenshotFlag) {
Vishnu Naira9c43762023-01-27 19:10:25 +0000387 setFlags(12, layer_state_t::eLayerSkipScreenshot, layer_state_t::eLayerSkipScreenshot);
388 createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0));
389 setLayerStack(3, 1);
390
Vishnu Nair444f3952023-04-11 13:01:02 -0700391 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 +0000392 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
393}
394
Vishnu Nair92990e22023-02-24 20:01:05 +0000395// ROOT (DISPLAY 0)
396// ├── 1
397// │ ├── 11
398// │ │ └── 111
399// │ └── 13
400// └── 2
401// ROOT (DISPLAY 3)
402// └── 3 (mirrors display 0)
403TEST_F(LayerSnapshotTest, mirrorLayerGetsCorrectLayerStack) {
404 reparentLayer(12, UNASSIGNED_LAYER_ID);
405 createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0));
406 setLayerStack(3, 3);
407 createDisplayMirrorLayer(4, ui::LayerStack::fromValue(0));
408 setLayerStack(4, 4);
409
Vishnu Nair444f3952023-04-11 13:01:02 -0700410 std::vector<uint32_t> expected = {1, 11, 111, 13, 2, 3, 1, 11, 111,
411 13, 2, 4, 1, 11, 111, 13, 2};
Vishnu Nair92990e22023-02-24 20:01:05 +0000412 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
413 EXPECT_EQ(getSnapshot({.id = 111, .mirrorRootId = 3})->outputFilter.layerStack.id, 3u);
414 EXPECT_EQ(getSnapshot({.id = 111, .mirrorRootId = 4})->outputFilter.layerStack.id, 4u);
415}
416
417// ROOT (DISPLAY 0)
418// ├── 1 (crop 50x50)
419// │ ├── 11
420// │ │ └── 111
421// │ └── 13
422// └── 2
423// ROOT (DISPLAY 3)
424// └── 3 (mirrors display 0) (crop 100x100)
425TEST_F(LayerSnapshotTest, mirrorLayerTouchIsCroppedByMirrorRoot) {
426 reparentLayer(12, UNASSIGNED_LAYER_ID);
427 createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0));
428 setLayerStack(3, 3);
429 setCrop(1, Rect{50, 50});
430 setCrop(3, Rect{100, 100});
431 setCrop(111, Rect{200, 200});
432 Region touch{Rect{0, 0, 1000, 1000}};
433 setTouchableRegion(111, touch);
Vishnu Nair444f3952023-04-11 13:01:02 -0700434 std::vector<uint32_t> expected = {1, 11, 111, 13, 2, 3, 1, 11, 111, 13, 2};
Vishnu Nair92990e22023-02-24 20:01:05 +0000435 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
436 EXPECT_TRUE(getSnapshot({.id = 111})->inputInfo.touchableRegion.hasSameRects(touch));
437 Region touchCroppedByMirrorRoot{Rect{0, 0, 50, 50}};
438 EXPECT_TRUE(getSnapshot({.id = 111, .mirrorRootId = 3})
439 ->inputInfo.touchableRegion.hasSameRects(touchCroppedByMirrorRoot));
440}
441
442TEST_F(LayerSnapshotTest, canRemoveDisplayMirror) {
443 setFlags(12, layer_state_t::eLayerSkipScreenshot, layer_state_t::eLayerSkipScreenshot);
444 createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0));
445 setLayerStack(3, 1);
Vishnu Nair444f3952023-04-11 13:01:02 -0700446 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 +0000447 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
448 destroyLayerHandle(3);
449 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
450}
451
Vishnu Nairfccd6362023-02-24 23:39:53 +0000452TEST_F(LayerSnapshotTest, cleanUpUnreachableSnapshotsAfterMirroring) {
453 size_t startingNumSnapshots = mSnapshotBuilder.getSnapshots().size();
454 createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0));
455 setLayerStack(3, 1);
Vishnu Nair444f3952023-04-11 13:01:02 -0700456 std::vector<uint32_t> expected = {1, 11, 111, 12, 121, 122, 1221, 13, 2, 3,
457 1, 11, 111, 12, 121, 122, 1221, 13, 2};
Vishnu Nairfccd6362023-02-24 23:39:53 +0000458 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
459 destroyLayerHandle(3);
460 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
461
462 EXPECT_EQ(startingNumSnapshots, mSnapshotBuilder.getSnapshots().size());
463}
464
465// Rel z doesn't create duplicate snapshots but this is for completeness
466TEST_F(LayerSnapshotTest, cleanUpUnreachableSnapshotsAfterRelZ) {
467 size_t startingNumSnapshots = mSnapshotBuilder.getSnapshots().size();
468 reparentRelativeLayer(13, 11);
469 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 11, 13, 111, 12, 121, 122, 1221, 2});
470 setZ(13, 0);
471 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
472
473 EXPECT_EQ(startingNumSnapshots, mSnapshotBuilder.getSnapshots().size());
474}
475
476TEST_F(LayerSnapshotTest, cleanUpUnreachableSnapshotsAfterLayerDestruction) {
477 size_t startingNumSnapshots = mSnapshotBuilder.getSnapshots().size();
478 destroyLayerHandle(2);
479 destroyLayerHandle(122);
480
481 std::vector<uint32_t> expected = {1, 11, 111, 12, 121, 122, 1221, 13};
482 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
483
484 EXPECT_LE(startingNumSnapshots - 2, mSnapshotBuilder.getSnapshots().size());
485}
486
Vishnu Nair3d8565a2023-06-30 07:23:24 +0000487TEST_F(LayerSnapshotTest, snashotContainsMetadataFromLayerCreationArgs) {
488 LayerCreationArgs args(std::make_optional<uint32_t>(200));
489 args.name = "testlayer";
490 args.addToRoot = true;
491 args.metadata.setInt32(42, 24);
492
493 std::vector<std::unique_ptr<RequestedLayerState>> layers;
494 layers.emplace_back(std::make_unique<RequestedLayerState>(args));
495 EXPECT_TRUE(layers.back()->metadata.has(42));
496 EXPECT_EQ(layers.back()->metadata.getInt32(42, 0), 24);
497 mLifecycleManager.addLayers(std::move(layers));
498
499 std::vector<uint32_t> expected = STARTING_ZORDER;
500 expected.push_back(200);
501 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
502
503 EXPECT_TRUE(mSnapshotBuilder.getSnapshot(200)->layerMetadata.has(42));
504 EXPECT_EQ(mSnapshotBuilder.getSnapshot(200)->layerMetadata.getInt32(42, 0), 24);
505}
506
507TEST_F(LayerSnapshotTest, frameRateSelectionPriorityPassedToChildLayers) {
508 setFrameRateSelectionPriority(11, 1);
509
510 setFrameRateSelectionPriority(12, 2);
511
512 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
513 EXPECT_EQ(getSnapshot({.id = 1})->frameRateSelectionPriority, Layer::PRIORITY_UNSET);
514 EXPECT_EQ(getSnapshot({.id = 11})->frameRateSelectionPriority, 1);
515 EXPECT_EQ(getSnapshot({.id = 12})->frameRateSelectionPriority, 2);
516 EXPECT_EQ(getSnapshot({.id = 122})->frameRateSelectionPriority, 2);
517 EXPECT_EQ(getSnapshot({.id = 1221})->frameRateSelectionPriority, 2);
518
519 // reparent and verify the child gets the new parent's framerate selection priority
520 reparentLayer(122, 11);
521
522 std::vector<uint32_t> expected = {1, 11, 111, 122, 1221, 12, 121, 13, 2};
523 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
524 EXPECT_EQ(getSnapshot({.id = 1})->frameRateSelectionPriority, Layer::PRIORITY_UNSET);
525 EXPECT_EQ(getSnapshot({.id = 11})->frameRateSelectionPriority, 1);
526 EXPECT_EQ(getSnapshot({.id = 12})->frameRateSelectionPriority, 2);
527 EXPECT_EQ(getSnapshot({.id = 122})->frameRateSelectionPriority, 1);
528 EXPECT_EQ(getSnapshot({.id = 1221})->frameRateSelectionPriority, 1);
529}
530
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000531TEST_F(LayerSnapshotTest, framerate) {
532 setFrameRate(11, 244.f, 0, 0);
533
534 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
535 // verify parent is gets no vote
Rachel Leece6e0042023-06-27 11:22:54 -0700536 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
537 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000538 scheduler::LayerInfo::FrameRateCompatibility::NoVote);
539 EXPECT_TRUE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate));
540
541 // verify layer and children get the requested votes
Rachel Leece6e0042023-06-27 11:22:54 -0700542 EXPECT_TRUE(getSnapshot({.id = 11})->frameRate.vote.rate.isValid());
543 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 244.f);
544 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.type,
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000545 scheduler::LayerInfo::FrameRateCompatibility::Default);
546 EXPECT_TRUE(getSnapshot({.id = 11})->changes.test(RequestedLayerState::Changes::FrameRate));
547
Rachel Leece6e0042023-06-27 11:22:54 -0700548 EXPECT_TRUE(getSnapshot({.id = 111})->frameRate.vote.rate.isValid());
549 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.rate.getValue(), 244.f);
550 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.type,
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000551 scheduler::LayerInfo::FrameRateCompatibility::Default);
552 EXPECT_TRUE(getSnapshot({.id = 111})->changes.test(RequestedLayerState::Changes::FrameRate));
553
554 // reparent and verify the child gets the new parent's framerate
555 reparentLayer(122, 11);
556
557 std::vector<uint32_t> expected = {1, 11, 111, 122, 1221, 12, 121, 13, 2};
558 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
559 // verify parent is gets no vote
Rachel Leece6e0042023-06-27 11:22:54 -0700560 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
561 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000562 scheduler::LayerInfo::FrameRateCompatibility::NoVote);
563
564 // verify layer and children get the requested votes
Rachel Leece6e0042023-06-27 11:22:54 -0700565 EXPECT_TRUE(getSnapshot({.id = 11})->frameRate.vote.rate.isValid());
566 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 244.f);
567 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.type,
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000568 scheduler::LayerInfo::FrameRateCompatibility::Default);
569
Rachel Leece6e0042023-06-27 11:22:54 -0700570 EXPECT_TRUE(getSnapshot({.id = 111})->frameRate.vote.rate.isValid());
571 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.rate.getValue(), 244.f);
572 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.type,
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000573 scheduler::LayerInfo::FrameRateCompatibility::Default);
574
Rachel Leece6e0042023-06-27 11:22:54 -0700575 EXPECT_TRUE(getSnapshot({.id = 122})->frameRate.vote.rate.isValid());
576 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.rate.getValue(), 244.f);
577 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.type,
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000578 scheduler::LayerInfo::FrameRateCompatibility::Default);
579 EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate));
580
581 // reparent and verify the new parent gets no vote
582 reparentLayer(11, 2);
583 expected = {1, 12, 121, 13, 2, 11, 111, 122, 1221};
584 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
585
586 // verify old parent has invalid framerate (default)
Rachel Leece6e0042023-06-27 11:22:54 -0700587 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
588 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000589 scheduler::LayerInfo::FrameRateCompatibility::Default);
590 EXPECT_TRUE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate));
591
592 // verify new parent get no vote
Rachel Leece6e0042023-06-27 11:22:54 -0700593 EXPECT_FALSE(getSnapshot({.id = 2})->frameRate.vote.rate.isValid());
594 EXPECT_EQ(getSnapshot({.id = 2})->frameRate.vote.type,
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000595 scheduler::LayerInfo::FrameRateCompatibility::NoVote);
596 EXPECT_TRUE(getSnapshot({.id = 2})->changes.test(RequestedLayerState::Changes::FrameRate));
597
598 // verify layer and children get the requested votes (unchanged)
Rachel Leece6e0042023-06-27 11:22:54 -0700599 EXPECT_TRUE(getSnapshot({.id = 11})->frameRate.vote.rate.isValid());
600 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 244.f);
601 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.type,
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000602 scheduler::LayerInfo::FrameRateCompatibility::Default);
603
Rachel Leece6e0042023-06-27 11:22:54 -0700604 EXPECT_TRUE(getSnapshot({.id = 111})->frameRate.vote.rate.isValid());
605 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.rate.getValue(), 244.f);
606 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.type,
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000607 scheduler::LayerInfo::FrameRateCompatibility::Default);
608
Rachel Leece6e0042023-06-27 11:22:54 -0700609 EXPECT_TRUE(getSnapshot({.id = 122})->frameRate.vote.rate.isValid());
610 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.rate.getValue(), 244.f);
611 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.type,
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000612 scheduler::LayerInfo::FrameRateCompatibility::Default);
613}
614
Vishnu Nair3996ee32023-08-14 04:32:31 +0000615TEST_F(LayerSnapshotTest, translateDataspace) {
616 setDataspace(1, ui::Dataspace::UNKNOWN);
617 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
618 EXPECT_EQ(getSnapshot({.id = 1})->dataspace, ui::Dataspace::V0_SRGB);
619}
620
Rachel Leece6e0042023-06-27 11:22:54 -0700621// This test is similar to "frameRate" test case but checks that the setFrameRateCategory API
622// interaction also works correctly with the setFrameRate API within SF frontend.
623TEST_F(LayerSnapshotTest, frameRateWithCategory) {
624 // ROOT
625 // ├── 1
626 // │ ├── 11 (frame rate set to 244.f)
627 // │ │ └── 111
628 // │ ├── 12
629 // │ │ ├── 121
630 // │ │ └── 122 (frame rate category set to Normal)
631 // │ │ └── 1221
632 // │ └── 13
633 // └── 2
634 setFrameRate(11, 244.f, 0, 0);
635 setFrameRateCategory(122, 3 /* Normal */);
636
637 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
638 // verify parent 1 gets no vote
639 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
640 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
641 scheduler::LayerInfo::FrameRateCompatibility::NoVote);
642 EXPECT_TRUE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate));
643
644 // verify layer 11 and children 111 get the requested votes
645 EXPECT_TRUE(getSnapshot({.id = 11})->frameRate.vote.rate.isValid());
646 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 244.f);
647 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.type,
648 scheduler::LayerInfo::FrameRateCompatibility::Default);
649 EXPECT_TRUE(getSnapshot({.id = 11})->changes.test(RequestedLayerState::Changes::FrameRate));
650
651 EXPECT_TRUE(getSnapshot({.id = 111})->frameRate.vote.rate.isValid());
652 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.rate.getValue(), 244.f);
653 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.type,
654 scheduler::LayerInfo::FrameRateCompatibility::Default);
655 EXPECT_TRUE(getSnapshot({.id = 111})->changes.test(RequestedLayerState::Changes::FrameRate));
656
657 // verify parent 12 gets no vote
658 EXPECT_FALSE(getSnapshot({.id = 12})->frameRate.vote.rate.isValid());
659 EXPECT_EQ(getSnapshot({.id = 12})->frameRate.vote.type,
660 scheduler::LayerInfo::FrameRateCompatibility::NoVote);
661 EXPECT_TRUE(getSnapshot({.id = 12})->changes.test(RequestedLayerState::Changes::FrameRate));
662
663 // verify layer 122 and children 1221 get the requested votes
664 EXPECT_FALSE(getSnapshot({.id = 122})->frameRate.vote.rate.isValid());
665 EXPECT_TRUE(getSnapshot({.id = 122})->frameRate.isValid());
666 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.type,
667 scheduler::LayerInfo::FrameRateCompatibility::Default);
668 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.category, FrameRateCategory::Normal);
669 EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate));
670
671 EXPECT_FALSE(getSnapshot({.id = 1221})->frameRate.vote.rate.isValid());
672 EXPECT_TRUE(getSnapshot({.id = 1221})->frameRate.isValid());
673 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.vote.type,
674 scheduler::LayerInfo::FrameRateCompatibility::Default);
675 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.category, FrameRateCategory::Normal);
676 EXPECT_TRUE(getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::FrameRate));
677
678 // reparent and verify the child does NOT get the new parent's framerate because it already has
679 // the frame rate category specified.
680 // ROOT
681 // ├─1
682 // │ ├─11 (frame rate set to 244.f)
683 // │ │ ├─111
684 // │ │ └─122 (frame rate category set to Normal)
685 // │ │ └─1221
686 // │ ├─12
687 // │ │ └─121
688 // │ └─13
689 // └─2
690 reparentLayer(122, 11);
691
692 std::vector<uint32_t> expected = {1, 11, 111, 122, 1221, 12, 121, 13, 2};
693 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
694 // verify parent is gets no vote
695 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
696 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
697 scheduler::LayerInfo::FrameRateCompatibility::NoVote);
698
699 // verify layer 11 and children 111 get the requested votes
700 EXPECT_TRUE(getSnapshot({.id = 11})->frameRate.vote.rate.isValid());
701 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 244.f);
702 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.type,
703 scheduler::LayerInfo::FrameRateCompatibility::Default);
704
705 EXPECT_TRUE(getSnapshot({.id = 111})->frameRate.vote.rate.isValid());
706 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.rate.getValue(), 244.f);
707 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.type,
708 scheduler::LayerInfo::FrameRateCompatibility::Default);
709
710 // verify layer 122 and children 1221 get the requested category vote (unchanged from
711 // reparenting)
712 EXPECT_FALSE(getSnapshot({.id = 122})->frameRate.vote.rate.isValid());
713 EXPECT_TRUE(getSnapshot({.id = 122})->frameRate.isValid());
714 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.type,
715 scheduler::LayerInfo::FrameRateCompatibility::Default);
716 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.category, FrameRateCategory::Normal);
717 EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate));
718
719 EXPECT_FALSE(getSnapshot({.id = 1221})->frameRate.vote.rate.isValid());
720 EXPECT_TRUE(getSnapshot({.id = 1221})->frameRate.isValid());
721 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.vote.type,
722 scheduler::LayerInfo::FrameRateCompatibility::Default);
723 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.category, FrameRateCategory::Normal);
724 EXPECT_TRUE(getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::FrameRate));
725}
726
Vishnu Nair0808ae62023-08-07 21:42:42 -0700727TEST_F(LayerSnapshotTest, skipRoundCornersWhenProtected) {
728 setRoundedCorners(1, 42.f);
729 setRoundedCorners(2, 42.f);
730 setCrop(1, Rect{1000, 1000});
731 setCrop(2, Rect{1000, 1000});
732
733 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
734 EXPECT_TRUE(getSnapshot({.id = 1})->roundedCorner.hasRoundedCorners());
735 EXPECT_EQ(getSnapshot({.id = 1})->roundedCorner.radius.x, 42.f);
736 EXPECT_TRUE(getSnapshot({.id = 2})->roundedCorner.hasRoundedCorners());
737
738 // add a buffer with the protected bit, check rounded corners are not set when
739 // skipRoundCornersWhenProtected == true
740 setBuffer(1,
741 std::make_shared<
742 renderengine::mock::FakeExternalTexture>(1U /*width*/, 1U /*height*/,
743 1ULL /* bufferId */,
744 HAL_PIXEL_FORMAT_RGBA_8888,
745 GRALLOC_USAGE_PROTECTED /*usage*/));
746
747 LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(),
748 .layerLifecycleManager = mLifecycleManager,
749 .includeMetadata = false,
750 .displays = mFrontEndDisplayInfos,
751 .displayChanges = false,
752 .globalShadowSettings = globalShadowSettings,
753 .supportsBlur = true,
754 .supportedLayerGenericMetadata = {},
755 .genericLayerMetadataKeyMap = {},
756 .skipRoundCornersWhenProtected = true};
757 update(mSnapshotBuilder, args);
758 EXPECT_FALSE(getSnapshot({.id = 1})->roundedCorner.hasRoundedCorners());
759 // layer 2 doesn't have a buffer and should be unaffected
760 EXPECT_TRUE(getSnapshot({.id = 2})->roundedCorner.hasRoundedCorners());
761
762 // remove protected bit, check rounded corners are set
763 setBuffer(1,
764 std::make_shared<renderengine::mock::FakeExternalTexture>(1U /*width*/, 1U /*height*/,
765 2ULL /* bufferId */,
766 HAL_PIXEL_FORMAT_RGBA_8888,
767 0 /*usage*/));
768 update(mSnapshotBuilder, args);
769 EXPECT_TRUE(getSnapshot({.id = 1})->roundedCorner.hasRoundedCorners());
770 EXPECT_EQ(getSnapshot({.id = 1})->roundedCorner.radius.x, 42.f);
771}
772
Vishnu Nairbd51f952023-08-31 22:50:14 -0700773TEST_F(LayerSnapshotTest, setRefreshRateIndicatorCompositionType) {
774 setFlags(1, layer_state_t::eLayerIsRefreshRateIndicator,
775 layer_state_t::eLayerIsRefreshRateIndicator);
776 setBuffer(1,
777 std::make_shared<renderengine::mock::FakeExternalTexture>(1U /*width*/, 1U /*height*/,
778 42ULL /* bufferId */,
779 HAL_PIXEL_FORMAT_RGBA_8888,
780 0 /*usage*/));
781 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
782 EXPECT_EQ(getSnapshot({.id = 1})->compositionType,
783 aidl::android::hardware::graphics::composer3::Composition::REFRESH_RATE_INDICATOR);
784}
785
Chavi Weingarten07597342023-09-14 21:10:59 +0000786TEST_F(LayerSnapshotTest, setBufferCrop) {
787 // validate no buffer but has crop
788 Rect crop = Rect(0, 0, 50, 50);
789 setBufferCrop(1, crop);
790 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
791 EXPECT_EQ(getSnapshot(1)->geomContentCrop, crop);
792
793 setBuffer(1,
794 std::make_shared<renderengine::mock::FakeExternalTexture>(100U /*width*/,
795 100U /*height*/,
796 42ULL /* bufferId */,
797 HAL_PIXEL_FORMAT_RGBA_8888,
798 0 /*usage*/));
799 // validate a buffer crop within the buffer bounds
800 setBufferCrop(1, crop);
801 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
802 EXPECT_EQ(getSnapshot(1)->geomContentCrop, crop);
803
804 // validate a buffer crop outside the buffer bounds
805 crop = Rect(0, 0, 150, 150);
806 setBufferCrop(1, crop);
807 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
808 EXPECT_EQ(getSnapshot(1)->geomContentCrop, Rect(0, 0, 100, 100));
809
810 // validate no buffer crop
811 setBufferCrop(1, Rect());
812 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
813 EXPECT_EQ(getSnapshot(1)->geomContentCrop, Rect(0, 0, 100, 100));
814}
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000815} // namespace android::surfaceflinger::frontend