blob: 1227b994ddfb00a3c9ac969ee2baeafee1fae0e5 [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);
Vishnu Nair6f878312023-09-08 11:05:01 -0700413 EXPECT_EQ(getSnapshot({.id = 111, .mirrorRootIds = 3u})->outputFilter.layerStack.id, 3u);
414 EXPECT_EQ(getSnapshot({.id = 111, .mirrorRootIds = 4u})->outputFilter.layerStack.id, 4u);
Vishnu Nair92990e22023-02-24 20:01:05 +0000415}
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}};
Vishnu Nair6f878312023-09-08 11:05:01 -0700438 EXPECT_TRUE(getSnapshot({.id = 111, .mirrorRootIds = 3u})
Vishnu Nair92990e22023-02-24 20:01:05 +0000439 ->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
Vishnu Nair6f878312023-09-08 11:05:01 -0700465TEST_F(LayerSnapshotTest, canMirrorDisplayWithMirrors) {
466 reparentLayer(12, UNASSIGNED_LAYER_ID);
467 mirrorLayer(/*layer*/ 14, /*parent*/ 1, /*layerToMirror*/ 11);
468 std::vector<uint32_t> expected = {1, 11, 111, 13, 14, 11, 111, 2};
469 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
470
471 createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0));
472 setLayerStack(3, 3);
473 expected = {1, 11, 111, 13, 14, 11, 111, 2, 3, 1, 11, 111, 13, 14, 11, 111, 2};
474 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
475 EXPECT_EQ(getSnapshot({.id = 11, .mirrorRootIds = 14u})->outputFilter.layerStack.id, 0u);
476 EXPECT_EQ(getSnapshot({.id = 11, .mirrorRootIds = 3u})->outputFilter.layerStack.id, 3u);
477 EXPECT_EQ(getSnapshot({.id = 11, .mirrorRootIds = 3u, 14u})->outputFilter.layerStack.id, 3u);
478}
479
Vishnu Nairfccd6362023-02-24 23:39:53 +0000480// Rel z doesn't create duplicate snapshots but this is for completeness
481TEST_F(LayerSnapshotTest, cleanUpUnreachableSnapshotsAfterRelZ) {
482 size_t startingNumSnapshots = mSnapshotBuilder.getSnapshots().size();
483 reparentRelativeLayer(13, 11);
484 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 11, 13, 111, 12, 121, 122, 1221, 2});
485 setZ(13, 0);
486 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
487
488 EXPECT_EQ(startingNumSnapshots, mSnapshotBuilder.getSnapshots().size());
489}
490
491TEST_F(LayerSnapshotTest, cleanUpUnreachableSnapshotsAfterLayerDestruction) {
492 size_t startingNumSnapshots = mSnapshotBuilder.getSnapshots().size();
493 destroyLayerHandle(2);
494 destroyLayerHandle(122);
495
496 std::vector<uint32_t> expected = {1, 11, 111, 12, 121, 122, 1221, 13};
497 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
498
499 EXPECT_LE(startingNumSnapshots - 2, mSnapshotBuilder.getSnapshots().size());
500}
501
Vishnu Nair3d8565a2023-06-30 07:23:24 +0000502TEST_F(LayerSnapshotTest, snashotContainsMetadataFromLayerCreationArgs) {
503 LayerCreationArgs args(std::make_optional<uint32_t>(200));
504 args.name = "testlayer";
505 args.addToRoot = true;
506 args.metadata.setInt32(42, 24);
507
508 std::vector<std::unique_ptr<RequestedLayerState>> layers;
509 layers.emplace_back(std::make_unique<RequestedLayerState>(args));
510 EXPECT_TRUE(layers.back()->metadata.has(42));
511 EXPECT_EQ(layers.back()->metadata.getInt32(42, 0), 24);
512 mLifecycleManager.addLayers(std::move(layers));
513
514 std::vector<uint32_t> expected = STARTING_ZORDER;
515 expected.push_back(200);
516 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
517
518 EXPECT_TRUE(mSnapshotBuilder.getSnapshot(200)->layerMetadata.has(42));
519 EXPECT_EQ(mSnapshotBuilder.getSnapshot(200)->layerMetadata.getInt32(42, 0), 24);
520}
521
522TEST_F(LayerSnapshotTest, frameRateSelectionPriorityPassedToChildLayers) {
523 setFrameRateSelectionPriority(11, 1);
524
525 setFrameRateSelectionPriority(12, 2);
526
527 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
528 EXPECT_EQ(getSnapshot({.id = 1})->frameRateSelectionPriority, Layer::PRIORITY_UNSET);
529 EXPECT_EQ(getSnapshot({.id = 11})->frameRateSelectionPriority, 1);
530 EXPECT_EQ(getSnapshot({.id = 12})->frameRateSelectionPriority, 2);
531 EXPECT_EQ(getSnapshot({.id = 122})->frameRateSelectionPriority, 2);
532 EXPECT_EQ(getSnapshot({.id = 1221})->frameRateSelectionPriority, 2);
533
534 // reparent and verify the child gets the new parent's framerate selection priority
535 reparentLayer(122, 11);
536
537 std::vector<uint32_t> expected = {1, 11, 111, 122, 1221, 12, 121, 13, 2};
538 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
539 EXPECT_EQ(getSnapshot({.id = 1})->frameRateSelectionPriority, Layer::PRIORITY_UNSET);
540 EXPECT_EQ(getSnapshot({.id = 11})->frameRateSelectionPriority, 1);
541 EXPECT_EQ(getSnapshot({.id = 12})->frameRateSelectionPriority, 2);
542 EXPECT_EQ(getSnapshot({.id = 122})->frameRateSelectionPriority, 1);
543 EXPECT_EQ(getSnapshot({.id = 1221})->frameRateSelectionPriority, 1);
544}
545
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000546TEST_F(LayerSnapshotTest, framerate) {
547 setFrameRate(11, 244.f, 0, 0);
548
549 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
550 // verify parent is gets no vote
Rachel Leece6e0042023-06-27 11:22:54 -0700551 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
552 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000553 scheduler::LayerInfo::FrameRateCompatibility::NoVote);
554 EXPECT_TRUE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate));
555
556 // verify layer and children get the requested votes
Rachel Leece6e0042023-06-27 11:22:54 -0700557 EXPECT_TRUE(getSnapshot({.id = 11})->frameRate.vote.rate.isValid());
558 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 244.f);
559 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.type,
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000560 scheduler::LayerInfo::FrameRateCompatibility::Default);
561 EXPECT_TRUE(getSnapshot({.id = 11})->changes.test(RequestedLayerState::Changes::FrameRate));
562
Rachel Leece6e0042023-06-27 11:22:54 -0700563 EXPECT_TRUE(getSnapshot({.id = 111})->frameRate.vote.rate.isValid());
564 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.rate.getValue(), 244.f);
565 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.type,
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000566 scheduler::LayerInfo::FrameRateCompatibility::Default);
567 EXPECT_TRUE(getSnapshot({.id = 111})->changes.test(RequestedLayerState::Changes::FrameRate));
568
569 // reparent and verify the child gets the new parent's framerate
570 reparentLayer(122, 11);
571
572 std::vector<uint32_t> expected = {1, 11, 111, 122, 1221, 12, 121, 13, 2};
573 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
574 // verify parent is gets no vote
Rachel Leece6e0042023-06-27 11:22:54 -0700575 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
576 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000577 scheduler::LayerInfo::FrameRateCompatibility::NoVote);
578
579 // verify layer and children get the requested votes
Rachel Leece6e0042023-06-27 11:22:54 -0700580 EXPECT_TRUE(getSnapshot({.id = 11})->frameRate.vote.rate.isValid());
581 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 244.f);
582 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.type,
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000583 scheduler::LayerInfo::FrameRateCompatibility::Default);
584
Rachel Leece6e0042023-06-27 11:22:54 -0700585 EXPECT_TRUE(getSnapshot({.id = 111})->frameRate.vote.rate.isValid());
586 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.rate.getValue(), 244.f);
587 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.type,
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000588 scheduler::LayerInfo::FrameRateCompatibility::Default);
589
Rachel Leece6e0042023-06-27 11:22:54 -0700590 EXPECT_TRUE(getSnapshot({.id = 122})->frameRate.vote.rate.isValid());
591 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.rate.getValue(), 244.f);
592 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.type,
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000593 scheduler::LayerInfo::FrameRateCompatibility::Default);
594 EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate));
595
596 // reparent and verify the new parent gets no vote
597 reparentLayer(11, 2);
598 expected = {1, 12, 121, 13, 2, 11, 111, 122, 1221};
599 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
600
601 // verify old parent has invalid framerate (default)
Rachel Leece6e0042023-06-27 11:22:54 -0700602 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
603 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000604 scheduler::LayerInfo::FrameRateCompatibility::Default);
605 EXPECT_TRUE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate));
606
607 // verify new parent get no vote
Rachel Leece6e0042023-06-27 11:22:54 -0700608 EXPECT_FALSE(getSnapshot({.id = 2})->frameRate.vote.rate.isValid());
609 EXPECT_EQ(getSnapshot({.id = 2})->frameRate.vote.type,
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000610 scheduler::LayerInfo::FrameRateCompatibility::NoVote);
611 EXPECT_TRUE(getSnapshot({.id = 2})->changes.test(RequestedLayerState::Changes::FrameRate));
612
613 // verify layer and children get the requested votes (unchanged)
Rachel Leece6e0042023-06-27 11:22:54 -0700614 EXPECT_TRUE(getSnapshot({.id = 11})->frameRate.vote.rate.isValid());
615 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 244.f);
616 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.type,
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000617 scheduler::LayerInfo::FrameRateCompatibility::Default);
618
Rachel Leece6e0042023-06-27 11:22:54 -0700619 EXPECT_TRUE(getSnapshot({.id = 111})->frameRate.vote.rate.isValid());
620 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.rate.getValue(), 244.f);
621 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.type,
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000622 scheduler::LayerInfo::FrameRateCompatibility::Default);
623
Rachel Leece6e0042023-06-27 11:22:54 -0700624 EXPECT_TRUE(getSnapshot({.id = 122})->frameRate.vote.rate.isValid());
625 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.rate.getValue(), 244.f);
626 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.type,
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000627 scheduler::LayerInfo::FrameRateCompatibility::Default);
628}
629
Vishnu Nair3996ee32023-08-14 04:32:31 +0000630TEST_F(LayerSnapshotTest, translateDataspace) {
631 setDataspace(1, ui::Dataspace::UNKNOWN);
632 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
633 EXPECT_EQ(getSnapshot({.id = 1})->dataspace, ui::Dataspace::V0_SRGB);
634}
635
Rachel Leece6e0042023-06-27 11:22:54 -0700636// This test is similar to "frameRate" test case but checks that the setFrameRateCategory API
637// interaction also works correctly with the setFrameRate API within SF frontend.
638TEST_F(LayerSnapshotTest, frameRateWithCategory) {
639 // ROOT
640 // ├── 1
641 // │ ├── 11 (frame rate set to 244.f)
642 // │ │ └── 111
643 // │ ├── 12
644 // │ │ ├── 121
645 // │ │ └── 122 (frame rate category set to Normal)
646 // │ │ └── 1221
647 // │ └── 13
648 // └── 2
649 setFrameRate(11, 244.f, 0, 0);
650 setFrameRateCategory(122, 3 /* Normal */);
651
652 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
653 // verify parent 1 gets no vote
654 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
655 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
656 scheduler::LayerInfo::FrameRateCompatibility::NoVote);
657 EXPECT_TRUE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate));
658
659 // verify layer 11 and children 111 get the requested votes
660 EXPECT_TRUE(getSnapshot({.id = 11})->frameRate.vote.rate.isValid());
661 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 244.f);
662 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.type,
663 scheduler::LayerInfo::FrameRateCompatibility::Default);
664 EXPECT_TRUE(getSnapshot({.id = 11})->changes.test(RequestedLayerState::Changes::FrameRate));
665
666 EXPECT_TRUE(getSnapshot({.id = 111})->frameRate.vote.rate.isValid());
667 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.rate.getValue(), 244.f);
668 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.type,
669 scheduler::LayerInfo::FrameRateCompatibility::Default);
670 EXPECT_TRUE(getSnapshot({.id = 111})->changes.test(RequestedLayerState::Changes::FrameRate));
671
672 // verify parent 12 gets no vote
673 EXPECT_FALSE(getSnapshot({.id = 12})->frameRate.vote.rate.isValid());
674 EXPECT_EQ(getSnapshot({.id = 12})->frameRate.vote.type,
675 scheduler::LayerInfo::FrameRateCompatibility::NoVote);
676 EXPECT_TRUE(getSnapshot({.id = 12})->changes.test(RequestedLayerState::Changes::FrameRate));
677
678 // verify layer 122 and children 1221 get the requested votes
679 EXPECT_FALSE(getSnapshot({.id = 122})->frameRate.vote.rate.isValid());
680 EXPECT_TRUE(getSnapshot({.id = 122})->frameRate.isValid());
681 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.type,
682 scheduler::LayerInfo::FrameRateCompatibility::Default);
683 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.category, FrameRateCategory::Normal);
684 EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate));
Rachel Lee43369b22023-09-05 18:40:40 -0700685 EXPECT_TRUE(
686 getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::AffectsChildren));
Rachel Leece6e0042023-06-27 11:22:54 -0700687
688 EXPECT_FALSE(getSnapshot({.id = 1221})->frameRate.vote.rate.isValid());
689 EXPECT_TRUE(getSnapshot({.id = 1221})->frameRate.isValid());
690 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.vote.type,
691 scheduler::LayerInfo::FrameRateCompatibility::Default);
692 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.category, FrameRateCategory::Normal);
693 EXPECT_TRUE(getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::FrameRate));
Rachel Lee43369b22023-09-05 18:40:40 -0700694 EXPECT_TRUE(
695 getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::AffectsChildren));
Rachel Leece6e0042023-06-27 11:22:54 -0700696
697 // reparent and verify the child does NOT get the new parent's framerate because it already has
698 // the frame rate category specified.
699 // ROOT
700 // ├─1
701 // │ ├─11 (frame rate set to 244.f)
702 // │ │ ├─111
703 // │ │ └─122 (frame rate category set to Normal)
704 // │ │ └─1221
705 // │ ├─12
706 // │ │ └─121
707 // │ └─13
708 // └─2
709 reparentLayer(122, 11);
710
711 std::vector<uint32_t> expected = {1, 11, 111, 122, 1221, 12, 121, 13, 2};
712 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
713 // verify parent is gets no vote
714 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
715 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
716 scheduler::LayerInfo::FrameRateCompatibility::NoVote);
717
718 // verify layer 11 and children 111 get the requested votes
719 EXPECT_TRUE(getSnapshot({.id = 11})->frameRate.vote.rate.isValid());
720 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 244.f);
721 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.type,
722 scheduler::LayerInfo::FrameRateCompatibility::Default);
723
724 EXPECT_TRUE(getSnapshot({.id = 111})->frameRate.vote.rate.isValid());
725 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.rate.getValue(), 244.f);
726 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.type,
727 scheduler::LayerInfo::FrameRateCompatibility::Default);
728
729 // verify layer 122 and children 1221 get the requested category vote (unchanged from
730 // reparenting)
731 EXPECT_FALSE(getSnapshot({.id = 122})->frameRate.vote.rate.isValid());
732 EXPECT_TRUE(getSnapshot({.id = 122})->frameRate.isValid());
733 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.type,
734 scheduler::LayerInfo::FrameRateCompatibility::Default);
735 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.category, FrameRateCategory::Normal);
736 EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate));
737
738 EXPECT_FALSE(getSnapshot({.id = 1221})->frameRate.vote.rate.isValid());
739 EXPECT_TRUE(getSnapshot({.id = 1221})->frameRate.isValid());
740 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.vote.type,
741 scheduler::LayerInfo::FrameRateCompatibility::Default);
742 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.category, FrameRateCategory::Normal);
743 EXPECT_TRUE(getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::FrameRate));
744}
745
Vishnu Nair0808ae62023-08-07 21:42:42 -0700746TEST_F(LayerSnapshotTest, skipRoundCornersWhenProtected) {
747 setRoundedCorners(1, 42.f);
748 setRoundedCorners(2, 42.f);
749 setCrop(1, Rect{1000, 1000});
750 setCrop(2, Rect{1000, 1000});
751
752 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
753 EXPECT_TRUE(getSnapshot({.id = 1})->roundedCorner.hasRoundedCorners());
754 EXPECT_EQ(getSnapshot({.id = 1})->roundedCorner.radius.x, 42.f);
755 EXPECT_TRUE(getSnapshot({.id = 2})->roundedCorner.hasRoundedCorners());
756
757 // add a buffer with the protected bit, check rounded corners are not set when
758 // skipRoundCornersWhenProtected == true
759 setBuffer(1,
760 std::make_shared<
761 renderengine::mock::FakeExternalTexture>(1U /*width*/, 1U /*height*/,
762 1ULL /* bufferId */,
763 HAL_PIXEL_FORMAT_RGBA_8888,
764 GRALLOC_USAGE_PROTECTED /*usage*/));
765
766 LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(),
767 .layerLifecycleManager = mLifecycleManager,
768 .includeMetadata = false,
769 .displays = mFrontEndDisplayInfos,
770 .displayChanges = false,
771 .globalShadowSettings = globalShadowSettings,
772 .supportsBlur = true,
773 .supportedLayerGenericMetadata = {},
774 .genericLayerMetadataKeyMap = {},
775 .skipRoundCornersWhenProtected = true};
776 update(mSnapshotBuilder, args);
777 EXPECT_FALSE(getSnapshot({.id = 1})->roundedCorner.hasRoundedCorners());
778 // layer 2 doesn't have a buffer and should be unaffected
779 EXPECT_TRUE(getSnapshot({.id = 2})->roundedCorner.hasRoundedCorners());
780
781 // remove protected bit, check rounded corners are set
782 setBuffer(1,
783 std::make_shared<renderengine::mock::FakeExternalTexture>(1U /*width*/, 1U /*height*/,
784 2ULL /* bufferId */,
785 HAL_PIXEL_FORMAT_RGBA_8888,
786 0 /*usage*/));
787 update(mSnapshotBuilder, args);
788 EXPECT_TRUE(getSnapshot({.id = 1})->roundedCorner.hasRoundedCorners());
789 EXPECT_EQ(getSnapshot({.id = 1})->roundedCorner.radius.x, 42.f);
790}
791
Vishnu Nairbd51f952023-08-31 22:50:14 -0700792TEST_F(LayerSnapshotTest, setRefreshRateIndicatorCompositionType) {
793 setFlags(1, layer_state_t::eLayerIsRefreshRateIndicator,
794 layer_state_t::eLayerIsRefreshRateIndicator);
795 setBuffer(1,
796 std::make_shared<renderengine::mock::FakeExternalTexture>(1U /*width*/, 1U /*height*/,
797 42ULL /* bufferId */,
798 HAL_PIXEL_FORMAT_RGBA_8888,
799 0 /*usage*/));
800 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
801 EXPECT_EQ(getSnapshot({.id = 1})->compositionType,
802 aidl::android::hardware::graphics::composer3::Composition::REFRESH_RATE_INDICATOR);
803}
804
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000805} // namespace android::surfaceflinger::frontend