blob: 69316bf4e57a2f902b73cc8ce20d0b29ad513997 [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);
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700318 EXPECT_EQ(getSnapshot(11)->frameRate.vote.type, scheduler::FrameRateCompatibility::Exact);
Rachel Leece6e0042023-06-27 11:22:54 -0700319 EXPECT_EQ(getSnapshot(111)->frameRate.vote.rate.getIntValue(), 90);
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700320 EXPECT_EQ(getSnapshot(111)->frameRate.vote.type, scheduler::FrameRateCompatibility::Exact);
Rachel Leece6e0042023-06-27 11:22:54 -0700321 EXPECT_EQ(getSnapshot(1)->frameRate.vote.rate.getIntValue(), 0);
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700322 EXPECT_EQ(getSnapshot(1)->frameRate.vote.type, scheduler::FrameRateCompatibility::NoVote);
Vishnu Naircfb2d252023-01-19 04:44:02 +0000323}
324
Vishnu Naira02943f2023-06-03 13:44:46 -0700325TEST_F(LayerSnapshotTest, CanCropTouchableRegion) {
Vishnu Nair29354ec2023-03-28 18:51:28 -0700326 // ROOT
327 // ├── 1
328 // │ ├── 11
329 // │ │ └── 111 (touchregion set to touch but cropped by layer 13)
330 // │ ├── 12
331 // │ │ ├── 121
332 // │ │ └── 122
333 // │ │ └── 1221
334 // │ └── 13 (crop set to touchCrop)
335 // └── 2
336
337 Rect touchCrop{300, 300, 400, 500};
338 setCrop(13, touchCrop);
339 Region touch{Rect{0, 0, 1000, 1000}};
340 setTouchableRegionCrop(111, touch, /*touchCropId=*/13, /*replaceTouchableRegionWithCrop=*/true);
341 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
342 EXPECT_EQ(getSnapshot({.id = 111})->inputInfo.touchableRegion.bounds(), touchCrop);
343
344 Rect modifiedTouchCrop{100, 300, 400, 700};
345 setCrop(13, modifiedTouchCrop);
346 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
347 EXPECT_EQ(getSnapshot({.id = 111})->inputInfo.touchableRegion.bounds(), modifiedTouchCrop);
348}
349
Vishnu Nair444f3952023-04-11 13:01:02 -0700350TEST_F(LayerSnapshotTest, blurUpdatesWhenAlphaChanges) {
Vishnu Nair854ce1c2023-08-19 15:00:13 -0700351 int blurRadius = 42;
352 setBackgroundBlurRadius(1221, static_cast<uint32_t>(blurRadius));
Vishnu Nair444f3952023-04-11 13:01:02 -0700353
354 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
355 EXPECT_EQ(getSnapshot({.id = 1221})->backgroundBlurRadius, blurRadius);
356
Vishnu Nair854ce1c2023-08-19 15:00:13 -0700357 blurRadius = 21;
358 setBackgroundBlurRadius(1221, static_cast<uint32_t>(blurRadius));
359 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
360 EXPECT_EQ(getSnapshot({.id = 1221})->backgroundBlurRadius, blurRadius);
361
Vishnu Nair444f3952023-04-11 13:01:02 -0700362 static constexpr float alpha = 0.5;
363 setAlpha(12, alpha);
364 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
Vishnu Nair854ce1c2023-08-19 15:00:13 -0700365 EXPECT_EQ(getSnapshot({.id = 1221})->backgroundBlurRadius,
366 static_cast<int>(static_cast<float>(blurRadius) * alpha));
Vishnu Nair444f3952023-04-11 13:01:02 -0700367}
368
Vishnu Naira9c43762023-01-27 19:10:25 +0000369// Display Mirroring Tests
370// tree with 3 levels of children
371// ROOT (DISPLAY 0)
372// ├── 1
373// │ ├── 11
374// │ │ └── 111
375// │ ├── 12 (has skip screenshot flag)
376// │ │ ├── 121
377// │ │ └── 122
378// │ │ └── 1221
379// │ └── 13
380// └── 2
381// ROOT (DISPLAY 1)
382// └── 3 (mirrors display 0)
Vishnu Nair92990e22023-02-24 20:01:05 +0000383TEST_F(LayerSnapshotTest, displayMirrorRespectsLayerSkipScreenshotFlag) {
Vishnu Naira9c43762023-01-27 19:10:25 +0000384 setFlags(12, layer_state_t::eLayerSkipScreenshot, layer_state_t::eLayerSkipScreenshot);
385 createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0));
386 setLayerStack(3, 1);
387
Vishnu Nair444f3952023-04-11 13:01:02 -0700388 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 +0000389 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
390}
391
Vishnu Nair92990e22023-02-24 20:01:05 +0000392// ROOT (DISPLAY 0)
393// ├── 1
394// │ ├── 11
395// │ │ └── 111
396// │ └── 13
397// └── 2
398// ROOT (DISPLAY 3)
399// └── 3 (mirrors display 0)
400TEST_F(LayerSnapshotTest, mirrorLayerGetsCorrectLayerStack) {
401 reparentLayer(12, UNASSIGNED_LAYER_ID);
402 createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0));
403 setLayerStack(3, 3);
404 createDisplayMirrorLayer(4, ui::LayerStack::fromValue(0));
405 setLayerStack(4, 4);
406
Vishnu Nair444f3952023-04-11 13:01:02 -0700407 std::vector<uint32_t> expected = {1, 11, 111, 13, 2, 3, 1, 11, 111,
408 13, 2, 4, 1, 11, 111, 13, 2};
Vishnu Nair92990e22023-02-24 20:01:05 +0000409 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
Vishnu Nair6f878312023-09-08 11:05:01 -0700410 EXPECT_EQ(getSnapshot({.id = 111, .mirrorRootIds = 3u})->outputFilter.layerStack.id, 3u);
411 EXPECT_EQ(getSnapshot({.id = 111, .mirrorRootIds = 4u})->outputFilter.layerStack.id, 4u);
Vishnu Nair92990e22023-02-24 20:01:05 +0000412}
413
414// ROOT (DISPLAY 0)
415// ├── 1 (crop 50x50)
416// │ ├── 11
417// │ │ └── 111
418// │ └── 13
419// └── 2
420// ROOT (DISPLAY 3)
421// └── 3 (mirrors display 0) (crop 100x100)
422TEST_F(LayerSnapshotTest, mirrorLayerTouchIsCroppedByMirrorRoot) {
423 reparentLayer(12, UNASSIGNED_LAYER_ID);
424 createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0));
425 setLayerStack(3, 3);
426 setCrop(1, Rect{50, 50});
427 setCrop(3, Rect{100, 100});
428 setCrop(111, Rect{200, 200});
429 Region touch{Rect{0, 0, 1000, 1000}};
430 setTouchableRegion(111, touch);
Vishnu Nair444f3952023-04-11 13:01:02 -0700431 std::vector<uint32_t> expected = {1, 11, 111, 13, 2, 3, 1, 11, 111, 13, 2};
Vishnu Nair92990e22023-02-24 20:01:05 +0000432 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
433 EXPECT_TRUE(getSnapshot({.id = 111})->inputInfo.touchableRegion.hasSameRects(touch));
434 Region touchCroppedByMirrorRoot{Rect{0, 0, 50, 50}};
Vishnu Nair6f878312023-09-08 11:05:01 -0700435 EXPECT_TRUE(getSnapshot({.id = 111, .mirrorRootIds = 3u})
Vishnu Nair92990e22023-02-24 20:01:05 +0000436 ->inputInfo.touchableRegion.hasSameRects(touchCroppedByMirrorRoot));
437}
438
439TEST_F(LayerSnapshotTest, canRemoveDisplayMirror) {
440 setFlags(12, layer_state_t::eLayerSkipScreenshot, layer_state_t::eLayerSkipScreenshot);
441 createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0));
442 setLayerStack(3, 1);
Vishnu Nair444f3952023-04-11 13:01:02 -0700443 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 +0000444 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
445 destroyLayerHandle(3);
446 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
447}
448
Vishnu Nairfccd6362023-02-24 23:39:53 +0000449TEST_F(LayerSnapshotTest, cleanUpUnreachableSnapshotsAfterMirroring) {
450 size_t startingNumSnapshots = mSnapshotBuilder.getSnapshots().size();
451 createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0));
452 setLayerStack(3, 1);
Vishnu Nair444f3952023-04-11 13:01:02 -0700453 std::vector<uint32_t> expected = {1, 11, 111, 12, 121, 122, 1221, 13, 2, 3,
454 1, 11, 111, 12, 121, 122, 1221, 13, 2};
Vishnu Nairfccd6362023-02-24 23:39:53 +0000455 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
456 destroyLayerHandle(3);
457 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
458
459 EXPECT_EQ(startingNumSnapshots, mSnapshotBuilder.getSnapshots().size());
460}
461
Vishnu Nair6f878312023-09-08 11:05:01 -0700462TEST_F(LayerSnapshotTest, canMirrorDisplayWithMirrors) {
463 reparentLayer(12, UNASSIGNED_LAYER_ID);
464 mirrorLayer(/*layer*/ 14, /*parent*/ 1, /*layerToMirror*/ 11);
465 std::vector<uint32_t> expected = {1, 11, 111, 13, 14, 11, 111, 2};
466 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
467
468 createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0));
469 setLayerStack(3, 3);
470 expected = {1, 11, 111, 13, 14, 11, 111, 2, 3, 1, 11, 111, 13, 14, 11, 111, 2};
471 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
472 EXPECT_EQ(getSnapshot({.id = 11, .mirrorRootIds = 14u})->outputFilter.layerStack.id, 0u);
473 EXPECT_EQ(getSnapshot({.id = 11, .mirrorRootIds = 3u})->outputFilter.layerStack.id, 3u);
474 EXPECT_EQ(getSnapshot({.id = 11, .mirrorRootIds = 3u, 14u})->outputFilter.layerStack.id, 3u);
475}
476
Vishnu Nairfccd6362023-02-24 23:39:53 +0000477// Rel z doesn't create duplicate snapshots but this is for completeness
478TEST_F(LayerSnapshotTest, cleanUpUnreachableSnapshotsAfterRelZ) {
479 size_t startingNumSnapshots = mSnapshotBuilder.getSnapshots().size();
480 reparentRelativeLayer(13, 11);
481 UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 11, 13, 111, 12, 121, 122, 1221, 2});
482 setZ(13, 0);
483 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
484
485 EXPECT_EQ(startingNumSnapshots, mSnapshotBuilder.getSnapshots().size());
486}
487
488TEST_F(LayerSnapshotTest, cleanUpUnreachableSnapshotsAfterLayerDestruction) {
489 size_t startingNumSnapshots = mSnapshotBuilder.getSnapshots().size();
490 destroyLayerHandle(2);
491 destroyLayerHandle(122);
492
493 std::vector<uint32_t> expected = {1, 11, 111, 12, 121, 122, 1221, 13};
494 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
495
496 EXPECT_LE(startingNumSnapshots - 2, mSnapshotBuilder.getSnapshots().size());
497}
498
Vishnu Nair3d8565a2023-06-30 07:23:24 +0000499TEST_F(LayerSnapshotTest, snashotContainsMetadataFromLayerCreationArgs) {
500 LayerCreationArgs args(std::make_optional<uint32_t>(200));
501 args.name = "testlayer";
502 args.addToRoot = true;
503 args.metadata.setInt32(42, 24);
504
505 std::vector<std::unique_ptr<RequestedLayerState>> layers;
506 layers.emplace_back(std::make_unique<RequestedLayerState>(args));
507 EXPECT_TRUE(layers.back()->metadata.has(42));
508 EXPECT_EQ(layers.back()->metadata.getInt32(42, 0), 24);
509 mLifecycleManager.addLayers(std::move(layers));
510
511 std::vector<uint32_t> expected = STARTING_ZORDER;
512 expected.push_back(200);
513 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
514
515 EXPECT_TRUE(mSnapshotBuilder.getSnapshot(200)->layerMetadata.has(42));
516 EXPECT_EQ(mSnapshotBuilder.getSnapshot(200)->layerMetadata.getInt32(42, 0), 24);
517}
518
519TEST_F(LayerSnapshotTest, frameRateSelectionPriorityPassedToChildLayers) {
520 setFrameRateSelectionPriority(11, 1);
521
522 setFrameRateSelectionPriority(12, 2);
523
524 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
525 EXPECT_EQ(getSnapshot({.id = 1})->frameRateSelectionPriority, Layer::PRIORITY_UNSET);
526 EXPECT_EQ(getSnapshot({.id = 11})->frameRateSelectionPriority, 1);
527 EXPECT_EQ(getSnapshot({.id = 12})->frameRateSelectionPriority, 2);
528 EXPECT_EQ(getSnapshot({.id = 122})->frameRateSelectionPriority, 2);
529 EXPECT_EQ(getSnapshot({.id = 1221})->frameRateSelectionPriority, 2);
530
531 // reparent and verify the child gets the new parent's framerate selection priority
532 reparentLayer(122, 11);
533
534 std::vector<uint32_t> expected = {1, 11, 111, 122, 1221, 12, 121, 13, 2};
535 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
536 EXPECT_EQ(getSnapshot({.id = 1})->frameRateSelectionPriority, Layer::PRIORITY_UNSET);
537 EXPECT_EQ(getSnapshot({.id = 11})->frameRateSelectionPriority, 1);
538 EXPECT_EQ(getSnapshot({.id = 12})->frameRateSelectionPriority, 2);
539 EXPECT_EQ(getSnapshot({.id = 122})->frameRateSelectionPriority, 1);
540 EXPECT_EQ(getSnapshot({.id = 1221})->frameRateSelectionPriority, 1);
541}
542
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000543TEST_F(LayerSnapshotTest, framerate) {
544 setFrameRate(11, 244.f, 0, 0);
545
546 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
547 // verify parent is gets no vote
Rachel Leece6e0042023-06-27 11:22:54 -0700548 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
549 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700550 scheduler::FrameRateCompatibility::NoVote);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000551 EXPECT_TRUE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate));
552
553 // verify layer and children get the requested votes
Rachel Leece6e0042023-06-27 11:22:54 -0700554 EXPECT_TRUE(getSnapshot({.id = 11})->frameRate.vote.rate.isValid());
555 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 244.f);
556 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700557 scheduler::FrameRateCompatibility::Default);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000558 EXPECT_TRUE(getSnapshot({.id = 11})->changes.test(RequestedLayerState::Changes::FrameRate));
559
Rachel Leece6e0042023-06-27 11:22:54 -0700560 EXPECT_TRUE(getSnapshot({.id = 111})->frameRate.vote.rate.isValid());
561 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.rate.getValue(), 244.f);
562 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700563 scheduler::FrameRateCompatibility::Default);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000564 EXPECT_TRUE(getSnapshot({.id = 111})->changes.test(RequestedLayerState::Changes::FrameRate));
565
566 // reparent and verify the child gets the new parent's framerate
567 reparentLayer(122, 11);
568
569 std::vector<uint32_t> expected = {1, 11, 111, 122, 1221, 12, 121, 13, 2};
570 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
571 // verify parent is gets no vote
Rachel Leece6e0042023-06-27 11:22:54 -0700572 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
573 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700574 scheduler::FrameRateCompatibility::NoVote);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000575
576 // verify layer and children get the requested votes
Rachel Leece6e0042023-06-27 11:22:54 -0700577 EXPECT_TRUE(getSnapshot({.id = 11})->frameRate.vote.rate.isValid());
578 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 244.f);
579 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700580 scheduler::FrameRateCompatibility::Default);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000581
Rachel Leece6e0042023-06-27 11:22:54 -0700582 EXPECT_TRUE(getSnapshot({.id = 111})->frameRate.vote.rate.isValid());
583 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.rate.getValue(), 244.f);
584 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700585 scheduler::FrameRateCompatibility::Default);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000586
Rachel Leece6e0042023-06-27 11:22:54 -0700587 EXPECT_TRUE(getSnapshot({.id = 122})->frameRate.vote.rate.isValid());
588 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.rate.getValue(), 244.f);
589 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700590 scheduler::FrameRateCompatibility::Default);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000591 EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate));
592
593 // reparent and verify the new parent gets no vote
594 reparentLayer(11, 2);
595 expected = {1, 12, 121, 13, 2, 11, 111, 122, 1221};
596 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
597
598 // verify old parent has invalid framerate (default)
Rachel Leece6e0042023-06-27 11:22:54 -0700599 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
600 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700601 scheduler::FrameRateCompatibility::Default);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000602 EXPECT_TRUE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate));
603
604 // verify new parent get no vote
Rachel Leece6e0042023-06-27 11:22:54 -0700605 EXPECT_FALSE(getSnapshot({.id = 2})->frameRate.vote.rate.isValid());
606 EXPECT_EQ(getSnapshot({.id = 2})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700607 scheduler::FrameRateCompatibility::NoVote);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000608 EXPECT_TRUE(getSnapshot({.id = 2})->changes.test(RequestedLayerState::Changes::FrameRate));
609
610 // verify layer and children get the requested votes (unchanged)
Rachel Leece6e0042023-06-27 11:22:54 -0700611 EXPECT_TRUE(getSnapshot({.id = 11})->frameRate.vote.rate.isValid());
612 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 244.f);
613 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700614 scheduler::FrameRateCompatibility::Default);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000615
Rachel Leece6e0042023-06-27 11:22:54 -0700616 EXPECT_TRUE(getSnapshot({.id = 111})->frameRate.vote.rate.isValid());
617 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.rate.getValue(), 244.f);
618 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700619 scheduler::FrameRateCompatibility::Default);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000620
Rachel Leece6e0042023-06-27 11:22:54 -0700621 EXPECT_TRUE(getSnapshot({.id = 122})->frameRate.vote.rate.isValid());
622 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.rate.getValue(), 244.f);
623 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700624 scheduler::FrameRateCompatibility::Default);
Vishnu Nair52d56fd2023-07-20 17:02:43 +0000625}
626
Vishnu Nair3996ee32023-08-14 04:32:31 +0000627TEST_F(LayerSnapshotTest, translateDataspace) {
628 setDataspace(1, ui::Dataspace::UNKNOWN);
629 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
630 EXPECT_EQ(getSnapshot({.id = 1})->dataspace, ui::Dataspace::V0_SRGB);
631}
632
Rachel Leece6e0042023-06-27 11:22:54 -0700633// This test is similar to "frameRate" test case but checks that the setFrameRateCategory API
634// interaction also works correctly with the setFrameRate API within SF frontend.
635TEST_F(LayerSnapshotTest, frameRateWithCategory) {
636 // ROOT
637 // ├── 1
638 // │ ├── 11 (frame rate set to 244.f)
639 // │ │ └── 111
640 // │ ├── 12
641 // │ │ ├── 121
642 // │ │ └── 122 (frame rate category set to Normal)
643 // │ │ └── 1221
644 // │ └── 13
645 // └── 2
646 setFrameRate(11, 244.f, 0, 0);
647 setFrameRateCategory(122, 3 /* Normal */);
648
649 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
650 // verify parent 1 gets no vote
651 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
652 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700653 scheduler::FrameRateCompatibility::NoVote);
Rachel Leece6e0042023-06-27 11:22:54 -0700654 EXPECT_TRUE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate));
655
656 // verify layer 11 and children 111 get the requested votes
657 EXPECT_TRUE(getSnapshot({.id = 11})->frameRate.vote.rate.isValid());
658 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 244.f);
659 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700660 scheduler::FrameRateCompatibility::Default);
Rachel Leece6e0042023-06-27 11:22:54 -0700661 EXPECT_TRUE(getSnapshot({.id = 11})->changes.test(RequestedLayerState::Changes::FrameRate));
662
663 EXPECT_TRUE(getSnapshot({.id = 111})->frameRate.vote.rate.isValid());
664 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.rate.getValue(), 244.f);
665 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700666 scheduler::FrameRateCompatibility::Default);
Rachel Leece6e0042023-06-27 11:22:54 -0700667 EXPECT_TRUE(getSnapshot({.id = 111})->changes.test(RequestedLayerState::Changes::FrameRate));
668
669 // verify parent 12 gets no vote
670 EXPECT_FALSE(getSnapshot({.id = 12})->frameRate.vote.rate.isValid());
671 EXPECT_EQ(getSnapshot({.id = 12})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700672 scheduler::FrameRateCompatibility::NoVote);
Rachel Leece6e0042023-06-27 11:22:54 -0700673 EXPECT_TRUE(getSnapshot({.id = 12})->changes.test(RequestedLayerState::Changes::FrameRate));
674
675 // verify layer 122 and children 1221 get the requested votes
676 EXPECT_FALSE(getSnapshot({.id = 122})->frameRate.vote.rate.isValid());
677 EXPECT_TRUE(getSnapshot({.id = 122})->frameRate.isValid());
678 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700679 scheduler::FrameRateCompatibility::Default);
Rachel Leece6e0042023-06-27 11:22:54 -0700680 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.category, FrameRateCategory::Normal);
681 EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate));
Rachel Lee43369b22023-09-05 18:40:40 -0700682 EXPECT_TRUE(
683 getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::AffectsChildren));
Rachel Leece6e0042023-06-27 11:22:54 -0700684
685 EXPECT_FALSE(getSnapshot({.id = 1221})->frameRate.vote.rate.isValid());
686 EXPECT_TRUE(getSnapshot({.id = 1221})->frameRate.isValid());
687 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700688 scheduler::FrameRateCompatibility::Default);
Rachel Leece6e0042023-06-27 11:22:54 -0700689 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.category, FrameRateCategory::Normal);
690 EXPECT_TRUE(getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::FrameRate));
Rachel Lee43369b22023-09-05 18:40:40 -0700691 EXPECT_TRUE(
692 getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::AffectsChildren));
Rachel Leece6e0042023-06-27 11:22:54 -0700693
694 // reparent and verify the child does NOT get the new parent's framerate because it already has
695 // the frame rate category specified.
696 // ROOT
697 // ├─1
698 // │ ├─11 (frame rate set to 244.f)
699 // │ │ ├─111
700 // │ │ └─122 (frame rate category set to Normal)
701 // │ │ └─1221
702 // │ ├─12
703 // │ │ └─121
704 // │ └─13
705 // └─2
706 reparentLayer(122, 11);
707
708 std::vector<uint32_t> expected = {1, 11, 111, 122, 1221, 12, 121, 13, 2};
709 UPDATE_AND_VERIFY(mSnapshotBuilder, expected);
710 // verify parent is gets no vote
711 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
712 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700713 scheduler::FrameRateCompatibility::NoVote);
Rachel Leece6e0042023-06-27 11:22:54 -0700714
715 // verify layer 11 and children 111 get the requested votes
716 EXPECT_TRUE(getSnapshot({.id = 11})->frameRate.vote.rate.isValid());
717 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 244.f);
718 EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700719 scheduler::FrameRateCompatibility::Default);
Rachel Leece6e0042023-06-27 11:22:54 -0700720
721 EXPECT_TRUE(getSnapshot({.id = 111})->frameRate.vote.rate.isValid());
722 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.rate.getValue(), 244.f);
723 EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700724 scheduler::FrameRateCompatibility::Default);
Rachel Leece6e0042023-06-27 11:22:54 -0700725
726 // verify layer 122 and children 1221 get the requested category vote (unchanged from
727 // reparenting)
728 EXPECT_FALSE(getSnapshot({.id = 122})->frameRate.vote.rate.isValid());
729 EXPECT_TRUE(getSnapshot({.id = 122})->frameRate.isValid());
730 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700731 scheduler::FrameRateCompatibility::Default);
Rachel Leece6e0042023-06-27 11:22:54 -0700732 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.category, FrameRateCategory::Normal);
733 EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate));
734
735 EXPECT_FALSE(getSnapshot({.id = 1221})->frameRate.vote.rate.isValid());
736 EXPECT_TRUE(getSnapshot({.id = 1221})->frameRate.isValid());
737 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700738 scheduler::FrameRateCompatibility::Default);
Rachel Leece6e0042023-06-27 11:22:54 -0700739 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.category, FrameRateCategory::Normal);
740 EXPECT_TRUE(getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::FrameRate));
741}
742
Rachel Lee58cc90d2023-09-05 18:50:20 -0700743TEST_F(LayerSnapshotTest, frameRateSelectionStrategy) {
744 // ROOT
745 // ├── 1
746 // │ ├── 11
747 // │ │ └── 111
748 // │ ├── 12 (frame rate set to 244.f with strategy OverrideChildren)
749 // │ │ ├── 121
750 // │ │ └── 122 (frame rate set to 123.f but should be overridden by layer 12)
751 // │ │ └── 1221
752 // │ └── 13
753 // └── 2
754 setFrameRate(12, 244.f, 0, 0);
755 setFrameRate(122, 123.f, 0, 0);
756 setFrameRateSelectionStrategy(12, 1 /* OverrideChildren */);
757
758 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
759 // verify parent 1 gets no vote
760 EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid());
761 EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type,
Vishnu Nair3fbe3262023-09-29 17:07:00 -0700762 scheduler::FrameRateCompatibility::NoVote);
Rachel Lee58cc90d2023-09-05 18:50:20 -0700763 EXPECT_TRUE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate));
764
765 // verify layer 12 and all descendants (121, 122, 1221) get the requested vote
766 EXPECT_EQ(getSnapshot({.id = 12})->frameRate.vote.rate.getValue(), 244.f);
767 EXPECT_EQ(getSnapshot({.id = 12})->frameRateSelectionStrategy,
768 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
769 EXPECT_TRUE(getSnapshot({.id = 12})->changes.test(RequestedLayerState::Changes::FrameRate));
770
771 EXPECT_EQ(getSnapshot({.id = 121})->frameRate.vote.rate.getValue(), 244.f);
772 EXPECT_EQ(getSnapshot({.id = 121})->frameRateSelectionStrategy,
773 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
774 EXPECT_TRUE(getSnapshot({.id = 121})->changes.test(RequestedLayerState::Changes::FrameRate));
775
776 EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.rate.getValue(), 244.f);
777 EXPECT_EQ(getSnapshot({.id = 122})->frameRateSelectionStrategy,
778 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
779 EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate));
780
781 EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.vote.rate.getValue(), 244.f);
782 EXPECT_EQ(getSnapshot({.id = 1221})->frameRateSelectionStrategy,
783 scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren);
784 EXPECT_TRUE(getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::FrameRate));
785}
786
Vishnu Nair0808ae62023-08-07 21:42:42 -0700787TEST_F(LayerSnapshotTest, skipRoundCornersWhenProtected) {
788 setRoundedCorners(1, 42.f);
789 setRoundedCorners(2, 42.f);
790 setCrop(1, Rect{1000, 1000});
791 setCrop(2, Rect{1000, 1000});
792
793 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
794 EXPECT_TRUE(getSnapshot({.id = 1})->roundedCorner.hasRoundedCorners());
795 EXPECT_EQ(getSnapshot({.id = 1})->roundedCorner.radius.x, 42.f);
796 EXPECT_TRUE(getSnapshot({.id = 2})->roundedCorner.hasRoundedCorners());
797
798 // add a buffer with the protected bit, check rounded corners are not set when
799 // skipRoundCornersWhenProtected == true
800 setBuffer(1,
801 std::make_shared<
802 renderengine::mock::FakeExternalTexture>(1U /*width*/, 1U /*height*/,
803 1ULL /* bufferId */,
804 HAL_PIXEL_FORMAT_RGBA_8888,
805 GRALLOC_USAGE_PROTECTED /*usage*/));
806
807 LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(),
808 .layerLifecycleManager = mLifecycleManager,
809 .includeMetadata = false,
810 .displays = mFrontEndDisplayInfos,
811 .displayChanges = false,
812 .globalShadowSettings = globalShadowSettings,
813 .supportsBlur = true,
814 .supportedLayerGenericMetadata = {},
815 .genericLayerMetadataKeyMap = {},
816 .skipRoundCornersWhenProtected = true};
817 update(mSnapshotBuilder, args);
818 EXPECT_FALSE(getSnapshot({.id = 1})->roundedCorner.hasRoundedCorners());
819 // layer 2 doesn't have a buffer and should be unaffected
820 EXPECT_TRUE(getSnapshot({.id = 2})->roundedCorner.hasRoundedCorners());
821
822 // remove protected bit, check rounded corners are set
823 setBuffer(1,
824 std::make_shared<renderengine::mock::FakeExternalTexture>(1U /*width*/, 1U /*height*/,
825 2ULL /* bufferId */,
826 HAL_PIXEL_FORMAT_RGBA_8888,
827 0 /*usage*/));
828 update(mSnapshotBuilder, args);
829 EXPECT_TRUE(getSnapshot({.id = 1})->roundedCorner.hasRoundedCorners());
830 EXPECT_EQ(getSnapshot({.id = 1})->roundedCorner.radius.x, 42.f);
831}
832
Vishnu Nairbd51f952023-08-31 22:50:14 -0700833TEST_F(LayerSnapshotTest, setRefreshRateIndicatorCompositionType) {
834 setFlags(1, layer_state_t::eLayerIsRefreshRateIndicator,
835 layer_state_t::eLayerIsRefreshRateIndicator);
836 setBuffer(1,
837 std::make_shared<renderengine::mock::FakeExternalTexture>(1U /*width*/, 1U /*height*/,
838 42ULL /* bufferId */,
839 HAL_PIXEL_FORMAT_RGBA_8888,
840 0 /*usage*/));
841 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
842 EXPECT_EQ(getSnapshot({.id = 1})->compositionType,
843 aidl::android::hardware::graphics::composer3::Composition::REFRESH_RATE_INDICATOR);
844}
845
Chavi Weingarten07597342023-09-14 21:10:59 +0000846TEST_F(LayerSnapshotTest, setBufferCrop) {
847 // validate no buffer but has crop
848 Rect crop = Rect(0, 0, 50, 50);
849 setBufferCrop(1, crop);
850 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
851 EXPECT_EQ(getSnapshot(1)->geomContentCrop, crop);
852
853 setBuffer(1,
854 std::make_shared<renderengine::mock::FakeExternalTexture>(100U /*width*/,
855 100U /*height*/,
856 42ULL /* bufferId */,
857 HAL_PIXEL_FORMAT_RGBA_8888,
858 0 /*usage*/));
859 // validate a buffer crop within the buffer bounds
860 setBufferCrop(1, crop);
861 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
862 EXPECT_EQ(getSnapshot(1)->geomContentCrop, crop);
863
864 // validate a buffer crop outside the buffer bounds
865 crop = Rect(0, 0, 150, 150);
866 setBufferCrop(1, crop);
867 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
868 EXPECT_EQ(getSnapshot(1)->geomContentCrop, Rect(0, 0, 100, 100));
869
870 // validate no buffer crop
871 setBufferCrop(1, Rect());
872 UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER);
873 EXPECT_EQ(getSnapshot(1)->geomContentCrop, Rect(0, 0, 100, 100));
874}
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000875} // namespace android::surfaceflinger::frontend