Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
Rachel Lee | 4568198 | 2024-03-14 18:40:15 -0700 | [diff] [blame] | 20 | #include <common/test/FlagUtils.h> |
Vishnu Nair | 0808ae6 | 2023-08-07 21:42:42 -0700 | [diff] [blame] | 21 | #include <renderengine/mock/FakeExternalTexture.h> |
| 22 | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 23 | #include "FrontEnd/LayerHierarchy.h" |
| 24 | #include "FrontEnd/LayerLifecycleManager.h" |
| 25 | #include "FrontEnd/LayerSnapshotBuilder.h" |
Vishnu Nair | 3d8565a | 2023-06-30 07:23:24 +0000 | [diff] [blame] | 26 | #include "Layer.h" |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 27 | #include "LayerHierarchyTest.h" |
Vishnu Nair | 3996ee3 | 2023-08-14 04:32:31 +0000 | [diff] [blame] | 28 | #include "ui/GraphicTypes.h" |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 29 | |
Rachel Lee | 4568198 | 2024-03-14 18:40:15 -0700 | [diff] [blame] | 30 | #include <com_android_graphics_surfaceflinger_flags.h> |
| 31 | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 32 | #define UPDATE_AND_VERIFY(BUILDER, ...) \ |
| 33 | ({ \ |
| 34 | SCOPED_TRACE(""); \ |
| 35 | updateAndVerify((BUILDER), /*displayChanges=*/false, __VA_ARGS__); \ |
| 36 | }) |
| 37 | |
| 38 | #define UPDATE_AND_VERIFY_WITH_DISPLAY_CHANGES(BUILDER, ...) \ |
| 39 | ({ \ |
| 40 | SCOPED_TRACE(""); \ |
| 41 | updateAndVerify((BUILDER), /*displayChanges=*/true, __VA_ARGS__); \ |
| 42 | }) |
| 43 | |
| 44 | namespace android::surfaceflinger::frontend { |
| 45 | |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 46 | using ftl::Flags; |
| 47 | using namespace ftl::flag_operators; |
Rachel Lee | 4568198 | 2024-03-14 18:40:15 -0700 | [diff] [blame] | 48 | using namespace com::android::graphics::surfaceflinger; |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 49 | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 50 | // To run test: |
| 51 | /** |
| 52 | mp :libsurfaceflinger_unittest && adb sync; adb shell \ |
| 53 | /data/nativetest/libsurfaceflinger_unittest/libsurfaceflinger_unittest \ |
| 54 | --gtest_filter="LayerSnapshotTest.*" --gtest_brief=1 |
| 55 | */ |
| 56 | |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 57 | class LayerSnapshotTest : public LayerSnapshotTestBase { |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 58 | protected: |
Vishnu Nair | 47b7bb4 | 2023-09-29 16:27:33 -0700 | [diff] [blame] | 59 | LayerSnapshotTest() : LayerSnapshotTestBase() { |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 60 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 61 | } |
| 62 | |
Vishnu Nair | 0808ae6 | 2023-08-07 21:42:42 -0700 | [diff] [blame] | 63 | void update(LayerSnapshotBuilder& actualBuilder, LayerSnapshotBuilder::Args& args) { |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 64 | if (mLifecycleManager.getGlobalChanges().test(RequestedLayerState::Changes::Hierarchy)) { |
Vishnu Nair | a029228 | 2023-12-16 14:32:00 -0800 | [diff] [blame] | 65 | mHierarchyBuilder.update(mLifecycleManager); |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 66 | } |
Vishnu Nair | 0808ae6 | 2023-08-07 21:42:42 -0700 | [diff] [blame] | 67 | args.root = mHierarchyBuilder.getHierarchy(); |
| 68 | actualBuilder.update(args); |
| 69 | } |
| 70 | |
Chavi Weingarten | 92c7d8c | 2024-01-19 23:25:45 +0000 | [diff] [blame] | 71 | void update(LayerSnapshotBuilder& actualBuilder) { |
| 72 | LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(), |
| 73 | .layerLifecycleManager = mLifecycleManager, |
| 74 | .includeMetadata = false, |
| 75 | .displays = mFrontEndDisplayInfos, |
| 76 | .globalShadowSettings = globalShadowSettings, |
| 77 | .supportsBlur = true, |
| 78 | .supportedLayerGenericMetadata = {}, |
| 79 | .genericLayerMetadataKeyMap = {}}; |
| 80 | update(actualBuilder, args); |
| 81 | } |
| 82 | |
Vishnu Nair | 0808ae6 | 2023-08-07 21:42:42 -0700 | [diff] [blame] | 83 | void updateAndVerify(LayerSnapshotBuilder& actualBuilder, bool hasDisplayChanges, |
| 84 | const std::vector<uint32_t> expectedVisibleLayerIdsInZOrder) { |
Vishnu Nair | c765c6c | 2023-02-23 00:08:01 +0000 | [diff] [blame] | 85 | LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(), |
| 86 | .layerLifecycleManager = mLifecycleManager, |
| 87 | .includeMetadata = false, |
| 88 | .displays = mFrontEndDisplayInfos, |
| 89 | .displayChanges = hasDisplayChanges, |
| 90 | .globalShadowSettings = globalShadowSettings, |
Vishnu Nair | 444f395 | 2023-04-11 13:01:02 -0700 | [diff] [blame] | 91 | .supportsBlur = true, |
Vishnu Nair | c765c6c | 2023-02-23 00:08:01 +0000 | [diff] [blame] | 92 | .supportedLayerGenericMetadata = {}, |
| 93 | .genericLayerMetadataKeyMap = {}}; |
Vishnu Nair | 0808ae6 | 2023-08-07 21:42:42 -0700 | [diff] [blame] | 94 | update(actualBuilder, args); |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 95 | |
| 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 Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 102 | std::vector<uint32_t> actualVisibleLayerIdsInZOrder; |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 103 | actualBuilder.forEachVisibleSnapshot( |
| 104 | [&actualVisibleLayerIdsInZOrder](const LayerSnapshot& snapshot) { |
| 105 | actualVisibleLayerIdsInZOrder.push_back(snapshot.path.id); |
| 106 | }); |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 107 | EXPECT_EQ(expectedVisibleLayerIdsInZOrder, actualVisibleLayerIdsInZOrder); |
| 108 | } |
| 109 | |
| 110 | LayerSnapshot* getSnapshot(uint32_t layerId) { return mSnapshotBuilder.getSnapshot(layerId); } |
Vishnu Nair | 92990e2 | 2023-02-24 20:01:05 +0000 | [diff] [blame] | 111 | LayerSnapshot* getSnapshot(const LayerHierarchy::TraversalPath path) { |
| 112 | return mSnapshotBuilder.getSnapshot(path); |
| 113 | } |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 114 | LayerSnapshotBuilder mSnapshotBuilder; |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 115 | static const std::vector<uint32_t> STARTING_ZORDER; |
| 116 | }; |
| 117 | const std::vector<uint32_t> LayerSnapshotTest::STARTING_ZORDER = {1, 11, 111, 12, 121, |
| 118 | 122, 1221, 13, 2}; |
| 119 | |
| 120 | TEST_F(LayerSnapshotTest, buildSnapshot) { |
Vishnu Nair | c765c6c | 2023-02-23 00:08:01 +0000 | [diff] [blame] | 121 | LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(), |
| 122 | .layerLifecycleManager = mLifecycleManager, |
| 123 | .includeMetadata = false, |
| 124 | .displays = mFrontEndDisplayInfos, |
| 125 | .globalShadowSettings = globalShadowSettings, |
| 126 | .supportedLayerGenericMetadata = {}, |
| 127 | .genericLayerMetadataKeyMap = {}}; |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 128 | LayerSnapshotBuilder builder(args); |
| 129 | } |
| 130 | |
| 131 | TEST_F(LayerSnapshotTest, updateSnapshot) { |
Vishnu Nair | c765c6c | 2023-02-23 00:08:01 +0000 | [diff] [blame] | 132 | LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(), |
| 133 | .layerLifecycleManager = mLifecycleManager, |
| 134 | .includeMetadata = false, |
| 135 | .displays = mFrontEndDisplayInfos, |
| 136 | .globalShadowSettings = globalShadowSettings, |
| 137 | .supportedLayerGenericMetadata = {}, |
| 138 | .genericLayerMetadataKeyMap = {} |
| 139 | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 140 | }; |
| 141 | |
| 142 | LayerSnapshotBuilder builder; |
| 143 | builder.update(args); |
| 144 | } |
| 145 | |
| 146 | // update using parent snapshot data |
| 147 | TEST_F(LayerSnapshotTest, croppedByParent) { |
| 148 | /// MAKE ALL LAYERS VISIBLE BY DEFAULT |
| 149 | DisplayInfo info; |
| 150 | info.info.logicalHeight = 100; |
| 151 | info.info.logicalWidth = 200; |
| 152 | mFrontEndDisplayInfos.emplace_or_replace(ui::LayerStack::fromValue(1), info); |
| 153 | Rect layerCrop(0, 0, 10, 20); |
| 154 | setCrop(11, layerCrop); |
| 155 | EXPECT_TRUE(mLifecycleManager.getGlobalChanges().test(RequestedLayerState::Changes::Geometry)); |
| 156 | UPDATE_AND_VERIFY_WITH_DISPLAY_CHANGES(mSnapshotBuilder, STARTING_ZORDER); |
| 157 | EXPECT_EQ(getSnapshot(11)->geomCrop, layerCrop); |
| 158 | EXPECT_EQ(getSnapshot(111)->geomLayerBounds, layerCrop.toFloatRect()); |
| 159 | float maxHeight = static_cast<float>(info.info.logicalHeight * 10); |
| 160 | float maxWidth = static_cast<float>(info.info.logicalWidth * 10); |
| 161 | |
| 162 | FloatRect maxDisplaySize(-maxWidth, -maxHeight, maxWidth, maxHeight); |
| 163 | EXPECT_EQ(getSnapshot(1)->geomLayerBounds, maxDisplaySize); |
| 164 | } |
| 165 | |
| 166 | // visibility tests |
| 167 | TEST_F(LayerSnapshotTest, newLayerHiddenByPolicy) { |
| 168 | createLayer(112, 11); |
| 169 | hideLayer(112); |
| 170 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 171 | |
| 172 | showLayer(112); |
| 173 | UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 11, 111, 112, 12, 121, 122, 1221, 13, 2}); |
| 174 | } |
| 175 | |
| 176 | TEST_F(LayerSnapshotTest, hiddenByParent) { |
| 177 | hideLayer(11); |
| 178 | UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 13, 2}); |
| 179 | } |
| 180 | |
| 181 | TEST_F(LayerSnapshotTest, reparentShowsChild) { |
| 182 | hideLayer(11); |
| 183 | UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 13, 2}); |
| 184 | |
| 185 | showLayer(11); |
| 186 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 187 | } |
| 188 | |
| 189 | TEST_F(LayerSnapshotTest, reparentHidesChild) { |
| 190 | hideLayer(11); |
| 191 | UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 13, 2}); |
| 192 | |
| 193 | reparentLayer(121, 11); |
| 194 | UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 122, 1221, 13, 2}); |
| 195 | } |
| 196 | |
| 197 | TEST_F(LayerSnapshotTest, unHidingUpdatesSnapshot) { |
| 198 | hideLayer(11); |
| 199 | Rect crop(1, 2, 3, 4); |
| 200 | setCrop(111, crop); |
| 201 | UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 13, 2}); |
| 202 | |
| 203 | showLayer(11); |
| 204 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 205 | EXPECT_EQ(getSnapshot(111)->geomLayerBounds, crop.toFloatRect()); |
| 206 | } |
| 207 | |
| 208 | TEST_F(LayerSnapshotTest, childBehindParentCanBeHiddenByParent) { |
| 209 | setZ(111, -1); |
| 210 | UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 111, 11, 12, 121, 122, 1221, 13, 2}); |
| 211 | |
| 212 | hideLayer(11); |
| 213 | UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 13, 2}); |
| 214 | } |
| 215 | |
| 216 | // relative tests |
| 217 | TEST_F(LayerSnapshotTest, RelativeParentCanHideChild) { |
| 218 | reparentRelativeLayer(13, 11); |
| 219 | UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 11, 13, 111, 12, 121, 122, 1221, 2}); |
| 220 | |
| 221 | hideLayer(11); |
| 222 | UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 2}); |
| 223 | } |
| 224 | |
| 225 | TEST_F(LayerSnapshotTest, ReparentingToHiddenRelativeParentHidesChild) { |
| 226 | hideLayer(11); |
| 227 | UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 13, 2}); |
| 228 | reparentRelativeLayer(13, 11); |
| 229 | UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 2}); |
| 230 | } |
| 231 | |
| 232 | TEST_F(LayerSnapshotTest, AlphaInheritedByChildren) { |
| 233 | setAlpha(1, 0.5); |
| 234 | setAlpha(122, 0.5); |
| 235 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 236 | EXPECT_EQ(getSnapshot(1)->alpha, 0.5f); |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 237 | EXPECT_EQ(getSnapshot(12)->alpha, 0.5f); |
| 238 | EXPECT_EQ(getSnapshot(1221)->alpha, 0.25f); |
| 239 | } |
| 240 | |
| 241 | // Change states |
| 242 | TEST_F(LayerSnapshotTest, UpdateClearsPreviousChangeStates) { |
| 243 | setCrop(1, Rect(1, 2, 3, 4)); |
| 244 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 245 | EXPECT_TRUE(getSnapshot(1)->changes.test(RequestedLayerState::Changes::Geometry)); |
| 246 | EXPECT_TRUE(getSnapshot(11)->changes.test(RequestedLayerState::Changes::Geometry)); |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 247 | setCrop(2, Rect(1, 2, 3, 4)); |
| 248 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 249 | EXPECT_TRUE(getSnapshot(2)->changes.test(RequestedLayerState::Changes::Geometry)); |
| 250 | EXPECT_FALSE(getSnapshot(1)->changes.test(RequestedLayerState::Changes::Geometry)); |
| 251 | EXPECT_FALSE(getSnapshot(11)->changes.test(RequestedLayerState::Changes::Geometry)); |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | TEST_F(LayerSnapshotTest, FastPathClearsPreviousChangeStates) { |
| 255 | setColor(11, {1._hf, 0._hf, 0._hf}); |
| 256 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
Vishnu Nair | df59f47 | 2024-05-17 16:51:33 +0000 | [diff] [blame] | 257 | EXPECT_EQ(getSnapshot(11)->changes, |
| 258 | RequestedLayerState::Changes::Content | |
| 259 | RequestedLayerState::Changes::RequiresComposition); |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 260 | EXPECT_EQ(getSnapshot(11)->clientChanges, layer_state_t::eColorChanged); |
| 261 | EXPECT_EQ(getSnapshot(1)->changes.get(), 0u); |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 262 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 263 | EXPECT_EQ(getSnapshot(11)->changes.get(), 0u); |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | TEST_F(LayerSnapshotTest, FastPathSetsChangeFlagToContent) { |
| 267 | setColor(1, {1._hf, 0._hf, 0._hf}); |
| 268 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
Vishnu Nair | df59f47 | 2024-05-17 16:51:33 +0000 | [diff] [blame] | 269 | EXPECT_EQ(getSnapshot(1)->changes, |
| 270 | RequestedLayerState::Changes::Content | |
| 271 | RequestedLayerState::Changes::RequiresComposition); |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 272 | EXPECT_EQ(getSnapshot(1)->clientChanges, layer_state_t::eColorChanged); |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 273 | } |
| 274 | |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 275 | TEST_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 Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 282 | transactions.back().states.front().layerId = 1; |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 283 | transactions.back().states.front().state.layerId = static_cast<int32_t>(1); |
| 284 | mLifecycleManager.applyTransactions(transactions); |
Nergi Rahardi | 6431d4a | 2024-05-15 18:42:48 +0900 | [diff] [blame] | 285 | EXPECT_EQ(mLifecycleManager.getGlobalChanges(), |
| 286 | RequestedLayerState::Changes::GameMode | RequestedLayerState::Changes::Metadata); |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 287 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 288 | EXPECT_EQ(getSnapshot(1)->clientChanges, layer_state_t::eMetadataChanged); |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 289 | EXPECT_EQ(static_cast<int32_t>(getSnapshot(1)->gameMode), 42); |
| 290 | EXPECT_EQ(static_cast<int32_t>(getSnapshot(11)->gameMode), 42); |
| 291 | } |
| 292 | |
Nergi Rahardi | 6431d4a | 2024-05-15 18:42:48 +0900 | [diff] [blame] | 293 | TEST_F(LayerSnapshotTest, UpdateMetadata) { |
| 294 | std::vector<TransactionState> transactions; |
| 295 | transactions.emplace_back(); |
| 296 | transactions.back().states.push_back({}); |
| 297 | transactions.back().states.front().state.what = layer_state_t::eMetadataChanged; |
| 298 | // This test focuses on metadata used by ARC++ to ensure LayerMetadata is updated correctly, |
| 299 | // and not using stale data. |
| 300 | transactions.back().states.front().state.metadata = LayerMetadata(); |
| 301 | transactions.back().states.front().state.metadata.setInt32(METADATA_OWNER_UID, 123); |
| 302 | transactions.back().states.front().state.metadata.setInt32(METADATA_WINDOW_TYPE, 234); |
| 303 | transactions.back().states.front().state.metadata.setInt32(METADATA_TASK_ID, 345); |
| 304 | transactions.back().states.front().state.metadata.setInt32(METADATA_MOUSE_CURSOR, 456); |
| 305 | transactions.back().states.front().state.metadata.setInt32(METADATA_ACCESSIBILITY_ID, 567); |
| 306 | transactions.back().states.front().state.metadata.setInt32(METADATA_OWNER_PID, 678); |
| 307 | transactions.back().states.front().state.metadata.setInt32(METADATA_CALLING_UID, 789); |
| 308 | |
| 309 | transactions.back().states.front().layerId = 1; |
| 310 | transactions.back().states.front().state.layerId = static_cast<int32_t>(1); |
| 311 | |
| 312 | mLifecycleManager.applyTransactions(transactions); |
| 313 | EXPECT_EQ(mLifecycleManager.getGlobalChanges(), RequestedLayerState::Changes::Metadata); |
| 314 | |
| 315 | // Setting includeMetadata=true to ensure metadata update is applied to LayerSnapshot |
| 316 | LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(), |
| 317 | .layerLifecycleManager = mLifecycleManager, |
| 318 | .includeMetadata = true, |
| 319 | .displays = mFrontEndDisplayInfos, |
| 320 | .globalShadowSettings = globalShadowSettings, |
| 321 | .supportsBlur = true, |
| 322 | .supportedLayerGenericMetadata = {}, |
| 323 | .genericLayerMetadataKeyMap = {}}; |
| 324 | update(mSnapshotBuilder, args); |
| 325 | |
| 326 | EXPECT_EQ(getSnapshot(1)->clientChanges, layer_state_t::eMetadataChanged); |
| 327 | EXPECT_EQ(getSnapshot(1)->layerMetadata.getInt32(METADATA_OWNER_UID, -1), 123); |
| 328 | EXPECT_EQ(getSnapshot(1)->layerMetadata.getInt32(METADATA_WINDOW_TYPE, -1), 234); |
| 329 | EXPECT_EQ(getSnapshot(1)->layerMetadata.getInt32(METADATA_TASK_ID, -1), 345); |
| 330 | EXPECT_EQ(getSnapshot(1)->layerMetadata.getInt32(METADATA_MOUSE_CURSOR, -1), 456); |
| 331 | EXPECT_EQ(getSnapshot(1)->layerMetadata.getInt32(METADATA_ACCESSIBILITY_ID, -1), 567); |
| 332 | EXPECT_EQ(getSnapshot(1)->layerMetadata.getInt32(METADATA_OWNER_PID, -1), 678); |
| 333 | EXPECT_EQ(getSnapshot(1)->layerMetadata.getInt32(METADATA_CALLING_UID, -1), 789); |
| 334 | } |
| 335 | |
Garfield Tan | 8eb8f35 | 2024-05-17 09:12:01 -0700 | [diff] [blame] | 336 | TEST_F(LayerSnapshotTest, UpdateMetadataOfHiddenLayers) { |
| 337 | hideLayer(1); |
| 338 | |
| 339 | std::vector<TransactionState> transactions; |
| 340 | transactions.emplace_back(); |
| 341 | transactions.back().states.push_back({}); |
| 342 | transactions.back().states.front().state.what = layer_state_t::eMetadataChanged; |
| 343 | // This test focuses on metadata used by ARC++ to ensure LayerMetadata is updated correctly, |
| 344 | // and not using stale data. |
| 345 | transactions.back().states.front().state.metadata = LayerMetadata(); |
| 346 | transactions.back().states.front().state.metadata.setInt32(METADATA_OWNER_UID, 123); |
| 347 | transactions.back().states.front().state.metadata.setInt32(METADATA_WINDOW_TYPE, 234); |
| 348 | transactions.back().states.front().state.metadata.setInt32(METADATA_TASK_ID, 345); |
| 349 | transactions.back().states.front().state.metadata.setInt32(METADATA_MOUSE_CURSOR, 456); |
| 350 | transactions.back().states.front().state.metadata.setInt32(METADATA_ACCESSIBILITY_ID, 567); |
| 351 | transactions.back().states.front().state.metadata.setInt32(METADATA_OWNER_PID, 678); |
| 352 | transactions.back().states.front().state.metadata.setInt32(METADATA_CALLING_UID, 789); |
| 353 | |
| 354 | transactions.back().states.front().layerId = 1; |
| 355 | transactions.back().states.front().state.layerId = static_cast<int32_t>(1); |
| 356 | |
| 357 | mLifecycleManager.applyTransactions(transactions); |
| 358 | EXPECT_EQ(mLifecycleManager.getGlobalChanges(), |
| 359 | RequestedLayerState::Changes::Metadata | RequestedLayerState::Changes::Visibility | |
| 360 | RequestedLayerState::Changes::VisibleRegion | |
| 361 | RequestedLayerState::Changes::AffectsChildren); |
| 362 | |
| 363 | // Setting includeMetadata=true to ensure metadata update is applied to LayerSnapshot |
| 364 | LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(), |
| 365 | .layerLifecycleManager = mLifecycleManager, |
| 366 | .includeMetadata = true, |
| 367 | .displays = mFrontEndDisplayInfos, |
| 368 | .globalShadowSettings = globalShadowSettings, |
| 369 | .supportsBlur = true, |
| 370 | .supportedLayerGenericMetadata = {}, |
| 371 | .genericLayerMetadataKeyMap = {}}; |
| 372 | update(mSnapshotBuilder, args); |
| 373 | |
| 374 | EXPECT_EQ(static_cast<int64_t>(getSnapshot(1)->clientChanges), |
| 375 | layer_state_t::eMetadataChanged | layer_state_t::eFlagsChanged); |
| 376 | EXPECT_EQ(getSnapshot(1)->layerMetadata.getInt32(METADATA_OWNER_UID, -1), 123); |
| 377 | EXPECT_EQ(getSnapshot(1)->layerMetadata.getInt32(METADATA_WINDOW_TYPE, -1), 234); |
| 378 | EXPECT_EQ(getSnapshot(1)->layerMetadata.getInt32(METADATA_TASK_ID, -1), 345); |
| 379 | EXPECT_EQ(getSnapshot(1)->layerMetadata.getInt32(METADATA_MOUSE_CURSOR, -1), 456); |
| 380 | EXPECT_EQ(getSnapshot(1)->layerMetadata.getInt32(METADATA_ACCESSIBILITY_ID, -1), 567); |
| 381 | EXPECT_EQ(getSnapshot(1)->layerMetadata.getInt32(METADATA_OWNER_PID, -1), 678); |
| 382 | EXPECT_EQ(getSnapshot(1)->layerMetadata.getInt32(METADATA_CALLING_UID, -1), 789); |
| 383 | } |
| 384 | |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 385 | TEST_F(LayerSnapshotTest, NoLayerVoteForParentWithChildVotes) { |
| 386 | // ROOT |
| 387 | // ├── 1 |
| 388 | // │ ├── 11 (frame rate set) |
| 389 | // │ │ └── 111 |
| 390 | // │ ├── 12 |
| 391 | // │ │ ├── 121 |
| 392 | // │ │ └── 122 |
| 393 | // │ │ └── 1221 |
| 394 | // │ └── 13 |
| 395 | // └── 2 |
| 396 | |
Vishnu Nair | 30515cb | 2023-10-19 21:54:08 -0700 | [diff] [blame] | 397 | setFrameRate(11, 90.0, ANATIVEWINDOW_FRAME_RATE_EXACT, ANATIVEWINDOW_CHANGE_FRAME_RATE_ALWAYS); |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 398 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 399 | |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 400 | EXPECT_EQ(getSnapshot(11)->frameRate.vote.rate.getIntValue(), 90); |
Vishnu Nair | 3fbe326 | 2023-09-29 17:07:00 -0700 | [diff] [blame] | 401 | EXPECT_EQ(getSnapshot(11)->frameRate.vote.type, scheduler::FrameRateCompatibility::Exact); |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 402 | EXPECT_EQ(getSnapshot(111)->frameRate.vote.rate.getIntValue(), 90); |
Vishnu Nair | 3fbe326 | 2023-09-29 17:07:00 -0700 | [diff] [blame] | 403 | EXPECT_EQ(getSnapshot(111)->frameRate.vote.type, scheduler::FrameRateCompatibility::Exact); |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 404 | EXPECT_EQ(getSnapshot(1)->frameRate.vote.rate.getIntValue(), 0); |
Vishnu Nair | 3fbe326 | 2023-09-29 17:07:00 -0700 | [diff] [blame] | 405 | EXPECT_EQ(getSnapshot(1)->frameRate.vote.type, scheduler::FrameRateCompatibility::NoVote); |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 406 | } |
| 407 | |
Vishnu Nair | 30515cb | 2023-10-19 21:54:08 -0700 | [diff] [blame] | 408 | TEST_F(LayerSnapshotTest, NoLayerVoteForParentWithChildVotesDoesNotAffectSiblings) { |
| 409 | // ROOT |
| 410 | // ├── 1 (verify layer has no vote) |
| 411 | // │ ├── 11 (frame rate set) |
| 412 | // │ │ └── 111 |
| 413 | // │ ├── 12 (frame rate set) |
| 414 | // │ │ ├── 121 |
| 415 | // │ │ └── 122 |
| 416 | // │ │ └── 1221 |
| 417 | // │ └── 13 (verify layer has default vote) |
| 418 | // └── 2 |
| 419 | |
| 420 | setFrameRate(11, 90.0, ANATIVEWINDOW_FRAME_RATE_EXACT, ANATIVEWINDOW_CHANGE_FRAME_RATE_ALWAYS); |
| 421 | setFrameRate(12, 45.0, ANATIVEWINDOW_FRAME_RATE_EXACT, ANATIVEWINDOW_CHANGE_FRAME_RATE_ALWAYS); |
| 422 | |
| 423 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 424 | |
| 425 | EXPECT_EQ(getSnapshot(11)->frameRate.vote.rate.getIntValue(), 90); |
| 426 | EXPECT_EQ(getSnapshot(11)->frameRate.vote.type, scheduler::FrameRateCompatibility::Exact); |
| 427 | EXPECT_EQ(getSnapshot(111)->frameRate.vote.rate.getIntValue(), 90); |
| 428 | EXPECT_EQ(getSnapshot(111)->frameRate.vote.type, scheduler::FrameRateCompatibility::Exact); |
| 429 | EXPECT_EQ(getSnapshot(12)->frameRate.vote.rate.getIntValue(), 45); |
| 430 | EXPECT_EQ(getSnapshot(12)->frameRate.vote.type, scheduler::FrameRateCompatibility::Exact); |
| 431 | EXPECT_EQ(getSnapshot(121)->frameRate.vote.rate.getIntValue(), 45); |
| 432 | EXPECT_EQ(getSnapshot(121)->frameRate.vote.type, scheduler::FrameRateCompatibility::Exact); |
| 433 | EXPECT_EQ(getSnapshot(1221)->frameRate.vote.rate.getIntValue(), 45); |
| 434 | EXPECT_EQ(getSnapshot(1221)->frameRate.vote.type, scheduler::FrameRateCompatibility::Exact); |
| 435 | |
| 436 | EXPECT_EQ(getSnapshot(1)->frameRate.vote.rate.getIntValue(), 0); |
| 437 | EXPECT_EQ(getSnapshot(1)->frameRate.vote.type, scheduler::FrameRateCompatibility::NoVote); |
| 438 | EXPECT_EQ(getSnapshot(13)->frameRate.vote.rate.getIntValue(), 0); |
| 439 | EXPECT_EQ(getSnapshot(13)->frameRate.vote.type, scheduler::FrameRateCompatibility::Default); |
| 440 | EXPECT_EQ(getSnapshot(2)->frameRate.vote.rate.getIntValue(), 0); |
| 441 | EXPECT_EQ(getSnapshot(2)->frameRate.vote.type, scheduler::FrameRateCompatibility::Default); |
| 442 | } |
| 443 | |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 444 | TEST_F(LayerSnapshotTest, CanCropTouchableRegion) { |
Vishnu Nair | 29354ec | 2023-03-28 18:51:28 -0700 | [diff] [blame] | 445 | // ROOT |
| 446 | // ├── 1 |
| 447 | // │ ├── 11 |
| 448 | // │ │ └── 111 (touchregion set to touch but cropped by layer 13) |
| 449 | // │ ├── 12 |
| 450 | // │ │ ├── 121 |
| 451 | // │ │ └── 122 |
| 452 | // │ │ └── 1221 |
| 453 | // │ └── 13 (crop set to touchCrop) |
| 454 | // └── 2 |
| 455 | |
| 456 | Rect touchCrop{300, 300, 400, 500}; |
| 457 | setCrop(13, touchCrop); |
| 458 | Region touch{Rect{0, 0, 1000, 1000}}; |
| 459 | setTouchableRegionCrop(111, touch, /*touchCropId=*/13, /*replaceTouchableRegionWithCrop=*/true); |
| 460 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 461 | EXPECT_EQ(getSnapshot({.id = 111})->inputInfo.touchableRegion.bounds(), touchCrop); |
| 462 | |
| 463 | Rect modifiedTouchCrop{100, 300, 400, 700}; |
| 464 | setCrop(13, modifiedTouchCrop); |
| 465 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 466 | EXPECT_EQ(getSnapshot({.id = 111})->inputInfo.touchableRegion.bounds(), modifiedTouchCrop); |
| 467 | } |
| 468 | |
Chavi Weingarten | 1ba381e | 2024-01-09 21:54:11 +0000 | [diff] [blame] | 469 | TEST_F(LayerSnapshotTest, CanCropTouchableRegionWithDisplayTransform) { |
| 470 | DisplayInfo displayInfo; |
| 471 | displayInfo.transform = ui::Transform(ui::Transform::RotationFlags::ROT_90, 1000, 1000); |
| 472 | mFrontEndDisplayInfos.emplace_or_replace(ui::LayerStack::fromValue(1), displayInfo); |
| 473 | |
| 474 | Rect touchCrop{300, 300, 400, 500}; |
| 475 | createRootLayer(3); |
| 476 | setCrop(3, touchCrop); |
| 477 | setLayerStack(3, 1); |
| 478 | Region touch{Rect{0, 0, 1000, 1000}}; |
| 479 | setTouchableRegionCrop(3, touch, /*touchCropId=*/3, /*replaceTouchableRegionWithCrop=*/false); |
| 480 | |
| 481 | UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 11, 111, 12, 121, 122, 1221, 13, 2, 3}); |
| 482 | Rect rotatedCrop = {500, 300, 700, 400}; |
| 483 | EXPECT_EQ(getSnapshot({.id = 3})->inputInfo.touchableRegion.bounds(), rotatedCrop); |
| 484 | } |
| 485 | |
Vishnu Nair | 444f395 | 2023-04-11 13:01:02 -0700 | [diff] [blame] | 486 | TEST_F(LayerSnapshotTest, blurUpdatesWhenAlphaChanges) { |
Vishnu Nair | 854ce1c | 2023-08-19 15:00:13 -0700 | [diff] [blame] | 487 | int blurRadius = 42; |
| 488 | setBackgroundBlurRadius(1221, static_cast<uint32_t>(blurRadius)); |
Vishnu Nair | 444f395 | 2023-04-11 13:01:02 -0700 | [diff] [blame] | 489 | |
| 490 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 491 | EXPECT_EQ(getSnapshot({.id = 1221})->backgroundBlurRadius, blurRadius); |
| 492 | |
Vishnu Nair | 854ce1c | 2023-08-19 15:00:13 -0700 | [diff] [blame] | 493 | blurRadius = 21; |
| 494 | setBackgroundBlurRadius(1221, static_cast<uint32_t>(blurRadius)); |
| 495 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 496 | EXPECT_EQ(getSnapshot({.id = 1221})->backgroundBlurRadius, blurRadius); |
| 497 | |
Vishnu Nair | 444f395 | 2023-04-11 13:01:02 -0700 | [diff] [blame] | 498 | static constexpr float alpha = 0.5; |
| 499 | setAlpha(12, alpha); |
| 500 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
Vishnu Nair | 854ce1c | 2023-08-19 15:00:13 -0700 | [diff] [blame] | 501 | EXPECT_EQ(getSnapshot({.id = 1221})->backgroundBlurRadius, |
| 502 | static_cast<int>(static_cast<float>(blurRadius) * alpha)); |
Vishnu Nair | 444f395 | 2023-04-11 13:01:02 -0700 | [diff] [blame] | 503 | } |
| 504 | |
Vishnu Nair | a9c4376 | 2023-01-27 19:10:25 +0000 | [diff] [blame] | 505 | // Display Mirroring Tests |
| 506 | // tree with 3 levels of children |
| 507 | // ROOT (DISPLAY 0) |
| 508 | // ├── 1 |
| 509 | // │ ├── 11 |
| 510 | // │ │ └── 111 |
| 511 | // │ ├── 12 (has skip screenshot flag) |
| 512 | // │ │ ├── 121 |
| 513 | // │ │ └── 122 |
| 514 | // │ │ └── 1221 |
| 515 | // │ └── 13 |
| 516 | // └── 2 |
| 517 | // ROOT (DISPLAY 1) |
| 518 | // └── 3 (mirrors display 0) |
Vishnu Nair | 92990e2 | 2023-02-24 20:01:05 +0000 | [diff] [blame] | 519 | TEST_F(LayerSnapshotTest, displayMirrorRespectsLayerSkipScreenshotFlag) { |
Vishnu Nair | a9c4376 | 2023-01-27 19:10:25 +0000 | [diff] [blame] | 520 | setFlags(12, layer_state_t::eLayerSkipScreenshot, layer_state_t::eLayerSkipScreenshot); |
| 521 | createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0)); |
| 522 | setLayerStack(3, 1); |
| 523 | |
Vishnu Nair | 444f395 | 2023-04-11 13:01:02 -0700 | [diff] [blame] | 524 | std::vector<uint32_t> expected = {1, 11, 111, 12, 121, 122, 1221, 13, 2, 3, 1, 11, 111, 13, 2}; |
Vishnu Nair | a9c4376 | 2023-01-27 19:10:25 +0000 | [diff] [blame] | 525 | UPDATE_AND_VERIFY(mSnapshotBuilder, expected); |
| 526 | } |
| 527 | |
Vishnu Nair | 92990e2 | 2023-02-24 20:01:05 +0000 | [diff] [blame] | 528 | // ROOT (DISPLAY 0) |
| 529 | // ├── 1 |
| 530 | // │ ├── 11 |
| 531 | // │ │ └── 111 |
| 532 | // │ └── 13 |
| 533 | // └── 2 |
| 534 | // ROOT (DISPLAY 3) |
| 535 | // └── 3 (mirrors display 0) |
| 536 | TEST_F(LayerSnapshotTest, mirrorLayerGetsCorrectLayerStack) { |
| 537 | reparentLayer(12, UNASSIGNED_LAYER_ID); |
| 538 | createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0)); |
| 539 | setLayerStack(3, 3); |
| 540 | createDisplayMirrorLayer(4, ui::LayerStack::fromValue(0)); |
| 541 | setLayerStack(4, 4); |
| 542 | |
Vishnu Nair | 444f395 | 2023-04-11 13:01:02 -0700 | [diff] [blame] | 543 | std::vector<uint32_t> expected = {1, 11, 111, 13, 2, 3, 1, 11, 111, |
| 544 | 13, 2, 4, 1, 11, 111, 13, 2}; |
Vishnu Nair | 92990e2 | 2023-02-24 20:01:05 +0000 | [diff] [blame] | 545 | UPDATE_AND_VERIFY(mSnapshotBuilder, expected); |
Vishnu Nair | 6f87831 | 2023-09-08 11:05:01 -0700 | [diff] [blame] | 546 | EXPECT_EQ(getSnapshot({.id = 111, .mirrorRootIds = 3u})->outputFilter.layerStack.id, 3u); |
| 547 | EXPECT_EQ(getSnapshot({.id = 111, .mirrorRootIds = 4u})->outputFilter.layerStack.id, 4u); |
Vishnu Nair | 92990e2 | 2023-02-24 20:01:05 +0000 | [diff] [blame] | 548 | } |
| 549 | |
| 550 | // ROOT (DISPLAY 0) |
| 551 | // ├── 1 (crop 50x50) |
| 552 | // │ ├── 11 |
| 553 | // │ │ └── 111 |
| 554 | // │ └── 13 |
| 555 | // └── 2 |
| 556 | // ROOT (DISPLAY 3) |
| 557 | // └── 3 (mirrors display 0) (crop 100x100) |
| 558 | TEST_F(LayerSnapshotTest, mirrorLayerTouchIsCroppedByMirrorRoot) { |
| 559 | reparentLayer(12, UNASSIGNED_LAYER_ID); |
| 560 | createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0)); |
| 561 | setLayerStack(3, 3); |
| 562 | setCrop(1, Rect{50, 50}); |
| 563 | setCrop(3, Rect{100, 100}); |
| 564 | setCrop(111, Rect{200, 200}); |
| 565 | Region touch{Rect{0, 0, 1000, 1000}}; |
| 566 | setTouchableRegion(111, touch); |
Vishnu Nair | 444f395 | 2023-04-11 13:01:02 -0700 | [diff] [blame] | 567 | std::vector<uint32_t> expected = {1, 11, 111, 13, 2, 3, 1, 11, 111, 13, 2}; |
Vishnu Nair | 92990e2 | 2023-02-24 20:01:05 +0000 | [diff] [blame] | 568 | UPDATE_AND_VERIFY(mSnapshotBuilder, expected); |
| 569 | EXPECT_TRUE(getSnapshot({.id = 111})->inputInfo.touchableRegion.hasSameRects(touch)); |
| 570 | Region touchCroppedByMirrorRoot{Rect{0, 0, 50, 50}}; |
Vishnu Nair | 6f87831 | 2023-09-08 11:05:01 -0700 | [diff] [blame] | 571 | EXPECT_TRUE(getSnapshot({.id = 111, .mirrorRootIds = 3u}) |
Vishnu Nair | 92990e2 | 2023-02-24 20:01:05 +0000 | [diff] [blame] | 572 | ->inputInfo.touchableRegion.hasSameRects(touchCroppedByMirrorRoot)); |
| 573 | } |
| 574 | |
| 575 | TEST_F(LayerSnapshotTest, canRemoveDisplayMirror) { |
| 576 | setFlags(12, layer_state_t::eLayerSkipScreenshot, layer_state_t::eLayerSkipScreenshot); |
| 577 | createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0)); |
| 578 | setLayerStack(3, 1); |
Vishnu Nair | 444f395 | 2023-04-11 13:01:02 -0700 | [diff] [blame] | 579 | std::vector<uint32_t> expected = {1, 11, 111, 12, 121, 122, 1221, 13, 2, 3, 1, 11, 111, 13, 2}; |
Vishnu Nair | 92990e2 | 2023-02-24 20:01:05 +0000 | [diff] [blame] | 580 | UPDATE_AND_VERIFY(mSnapshotBuilder, expected); |
| 581 | destroyLayerHandle(3); |
| 582 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 583 | } |
| 584 | |
Vishnu Nair | fccd636 | 2023-02-24 23:39:53 +0000 | [diff] [blame] | 585 | TEST_F(LayerSnapshotTest, cleanUpUnreachableSnapshotsAfterMirroring) { |
| 586 | size_t startingNumSnapshots = mSnapshotBuilder.getSnapshots().size(); |
| 587 | createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0)); |
| 588 | setLayerStack(3, 1); |
Vishnu Nair | 444f395 | 2023-04-11 13:01:02 -0700 | [diff] [blame] | 589 | std::vector<uint32_t> expected = {1, 11, 111, 12, 121, 122, 1221, 13, 2, 3, |
| 590 | 1, 11, 111, 12, 121, 122, 1221, 13, 2}; |
Vishnu Nair | fccd636 | 2023-02-24 23:39:53 +0000 | [diff] [blame] | 591 | UPDATE_AND_VERIFY(mSnapshotBuilder, expected); |
| 592 | destroyLayerHandle(3); |
| 593 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 594 | |
| 595 | EXPECT_EQ(startingNumSnapshots, mSnapshotBuilder.getSnapshots().size()); |
| 596 | } |
| 597 | |
Vishnu Nair | 6f87831 | 2023-09-08 11:05:01 -0700 | [diff] [blame] | 598 | TEST_F(LayerSnapshotTest, canMirrorDisplayWithMirrors) { |
| 599 | reparentLayer(12, UNASSIGNED_LAYER_ID); |
| 600 | mirrorLayer(/*layer*/ 14, /*parent*/ 1, /*layerToMirror*/ 11); |
| 601 | std::vector<uint32_t> expected = {1, 11, 111, 13, 14, 11, 111, 2}; |
| 602 | UPDATE_AND_VERIFY(mSnapshotBuilder, expected); |
| 603 | |
| 604 | createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0)); |
| 605 | setLayerStack(3, 3); |
| 606 | expected = {1, 11, 111, 13, 14, 11, 111, 2, 3, 1, 11, 111, 13, 14, 11, 111, 2}; |
| 607 | UPDATE_AND_VERIFY(mSnapshotBuilder, expected); |
| 608 | EXPECT_EQ(getSnapshot({.id = 11, .mirrorRootIds = 14u})->outputFilter.layerStack.id, 0u); |
| 609 | EXPECT_EQ(getSnapshot({.id = 11, .mirrorRootIds = 3u})->outputFilter.layerStack.id, 3u); |
| 610 | EXPECT_EQ(getSnapshot({.id = 11, .mirrorRootIds = 3u, 14u})->outputFilter.layerStack.id, 3u); |
| 611 | } |
| 612 | |
Vishnu Nair | fccd636 | 2023-02-24 23:39:53 +0000 | [diff] [blame] | 613 | // Rel z doesn't create duplicate snapshots but this is for completeness |
| 614 | TEST_F(LayerSnapshotTest, cleanUpUnreachableSnapshotsAfterRelZ) { |
| 615 | size_t startingNumSnapshots = mSnapshotBuilder.getSnapshots().size(); |
| 616 | reparentRelativeLayer(13, 11); |
| 617 | UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 11, 13, 111, 12, 121, 122, 1221, 2}); |
| 618 | setZ(13, 0); |
| 619 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 620 | |
| 621 | EXPECT_EQ(startingNumSnapshots, mSnapshotBuilder.getSnapshots().size()); |
| 622 | } |
| 623 | |
| 624 | TEST_F(LayerSnapshotTest, cleanUpUnreachableSnapshotsAfterLayerDestruction) { |
| 625 | size_t startingNumSnapshots = mSnapshotBuilder.getSnapshots().size(); |
| 626 | destroyLayerHandle(2); |
| 627 | destroyLayerHandle(122); |
| 628 | |
| 629 | std::vector<uint32_t> expected = {1, 11, 111, 12, 121, 122, 1221, 13}; |
| 630 | UPDATE_AND_VERIFY(mSnapshotBuilder, expected); |
| 631 | |
| 632 | EXPECT_LE(startingNumSnapshots - 2, mSnapshotBuilder.getSnapshots().size()); |
| 633 | } |
| 634 | |
Vishnu Nair | 3d8565a | 2023-06-30 07:23:24 +0000 | [diff] [blame] | 635 | TEST_F(LayerSnapshotTest, snashotContainsMetadataFromLayerCreationArgs) { |
| 636 | LayerCreationArgs args(std::make_optional<uint32_t>(200)); |
| 637 | args.name = "testlayer"; |
| 638 | args.addToRoot = true; |
| 639 | args.metadata.setInt32(42, 24); |
| 640 | |
| 641 | std::vector<std::unique_ptr<RequestedLayerState>> layers; |
| 642 | layers.emplace_back(std::make_unique<RequestedLayerState>(args)); |
| 643 | EXPECT_TRUE(layers.back()->metadata.has(42)); |
| 644 | EXPECT_EQ(layers.back()->metadata.getInt32(42, 0), 24); |
| 645 | mLifecycleManager.addLayers(std::move(layers)); |
| 646 | |
| 647 | std::vector<uint32_t> expected = STARTING_ZORDER; |
| 648 | expected.push_back(200); |
| 649 | UPDATE_AND_VERIFY(mSnapshotBuilder, expected); |
| 650 | |
| 651 | EXPECT_TRUE(mSnapshotBuilder.getSnapshot(200)->layerMetadata.has(42)); |
| 652 | EXPECT_EQ(mSnapshotBuilder.getSnapshot(200)->layerMetadata.getInt32(42, 0), 24); |
| 653 | } |
| 654 | |
| 655 | TEST_F(LayerSnapshotTest, frameRateSelectionPriorityPassedToChildLayers) { |
| 656 | setFrameRateSelectionPriority(11, 1); |
| 657 | |
| 658 | setFrameRateSelectionPriority(12, 2); |
| 659 | |
| 660 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 661 | EXPECT_EQ(getSnapshot({.id = 1})->frameRateSelectionPriority, Layer::PRIORITY_UNSET); |
| 662 | EXPECT_EQ(getSnapshot({.id = 11})->frameRateSelectionPriority, 1); |
| 663 | EXPECT_EQ(getSnapshot({.id = 12})->frameRateSelectionPriority, 2); |
| 664 | EXPECT_EQ(getSnapshot({.id = 122})->frameRateSelectionPriority, 2); |
| 665 | EXPECT_EQ(getSnapshot({.id = 1221})->frameRateSelectionPriority, 2); |
| 666 | |
| 667 | // reparent and verify the child gets the new parent's framerate selection priority |
| 668 | reparentLayer(122, 11); |
| 669 | |
| 670 | std::vector<uint32_t> expected = {1, 11, 111, 122, 1221, 12, 121, 13, 2}; |
| 671 | UPDATE_AND_VERIFY(mSnapshotBuilder, expected); |
| 672 | EXPECT_EQ(getSnapshot({.id = 1})->frameRateSelectionPriority, Layer::PRIORITY_UNSET); |
| 673 | EXPECT_EQ(getSnapshot({.id = 11})->frameRateSelectionPriority, 1); |
| 674 | EXPECT_EQ(getSnapshot({.id = 12})->frameRateSelectionPriority, 2); |
| 675 | EXPECT_EQ(getSnapshot({.id = 122})->frameRateSelectionPriority, 1); |
| 676 | EXPECT_EQ(getSnapshot({.id = 1221})->frameRateSelectionPriority, 1); |
| 677 | } |
| 678 | |
Vishnu Nair | 52d56fd | 2023-07-20 17:02:43 +0000 | [diff] [blame] | 679 | TEST_F(LayerSnapshotTest, framerate) { |
| 680 | setFrameRate(11, 244.f, 0, 0); |
| 681 | |
| 682 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 683 | // verify parent is gets no vote |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 684 | EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid()); |
| 685 | EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type, |
Vishnu Nair | 3fbe326 | 2023-09-29 17:07:00 -0700 | [diff] [blame] | 686 | scheduler::FrameRateCompatibility::NoVote); |
Vishnu Nair | 52d56fd | 2023-07-20 17:02:43 +0000 | [diff] [blame] | 687 | EXPECT_TRUE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate)); |
| 688 | |
| 689 | // verify layer and children get the requested votes |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 690 | EXPECT_TRUE(getSnapshot({.id = 11})->frameRate.vote.rate.isValid()); |
| 691 | EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 244.f); |
| 692 | EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.type, |
Vishnu Nair | 3fbe326 | 2023-09-29 17:07:00 -0700 | [diff] [blame] | 693 | scheduler::FrameRateCompatibility::Default); |
Vishnu Nair | 52d56fd | 2023-07-20 17:02:43 +0000 | [diff] [blame] | 694 | EXPECT_TRUE(getSnapshot({.id = 11})->changes.test(RequestedLayerState::Changes::FrameRate)); |
| 695 | |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 696 | EXPECT_TRUE(getSnapshot({.id = 111})->frameRate.vote.rate.isValid()); |
| 697 | EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.rate.getValue(), 244.f); |
| 698 | EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.type, |
Vishnu Nair | 3fbe326 | 2023-09-29 17:07:00 -0700 | [diff] [blame] | 699 | scheduler::FrameRateCompatibility::Default); |
Vishnu Nair | 52d56fd | 2023-07-20 17:02:43 +0000 | [diff] [blame] | 700 | EXPECT_TRUE(getSnapshot({.id = 111})->changes.test(RequestedLayerState::Changes::FrameRate)); |
| 701 | |
| 702 | // reparent and verify the child gets the new parent's framerate |
| 703 | reparentLayer(122, 11); |
| 704 | |
| 705 | std::vector<uint32_t> expected = {1, 11, 111, 122, 1221, 12, 121, 13, 2}; |
| 706 | UPDATE_AND_VERIFY(mSnapshotBuilder, expected); |
| 707 | // verify parent is gets no vote |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 708 | EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid()); |
| 709 | EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type, |
Vishnu Nair | 3fbe326 | 2023-09-29 17:07:00 -0700 | [diff] [blame] | 710 | scheduler::FrameRateCompatibility::NoVote); |
Vishnu Nair | 52d56fd | 2023-07-20 17:02:43 +0000 | [diff] [blame] | 711 | |
| 712 | // verify layer and children get the requested votes |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 713 | EXPECT_TRUE(getSnapshot({.id = 11})->frameRate.vote.rate.isValid()); |
| 714 | EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 244.f); |
| 715 | EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.type, |
Vishnu Nair | 3fbe326 | 2023-09-29 17:07:00 -0700 | [diff] [blame] | 716 | scheduler::FrameRateCompatibility::Default); |
Vishnu Nair | 52d56fd | 2023-07-20 17:02:43 +0000 | [diff] [blame] | 717 | |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 718 | EXPECT_TRUE(getSnapshot({.id = 111})->frameRate.vote.rate.isValid()); |
| 719 | EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.rate.getValue(), 244.f); |
| 720 | EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.type, |
Vishnu Nair | 3fbe326 | 2023-09-29 17:07:00 -0700 | [diff] [blame] | 721 | scheduler::FrameRateCompatibility::Default); |
Vishnu Nair | 52d56fd | 2023-07-20 17:02:43 +0000 | [diff] [blame] | 722 | |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 723 | EXPECT_TRUE(getSnapshot({.id = 122})->frameRate.vote.rate.isValid()); |
| 724 | EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.rate.getValue(), 244.f); |
| 725 | EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.type, |
Vishnu Nair | 3fbe326 | 2023-09-29 17:07:00 -0700 | [diff] [blame] | 726 | scheduler::FrameRateCompatibility::Default); |
Vishnu Nair | 52d56fd | 2023-07-20 17:02:43 +0000 | [diff] [blame] | 727 | EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate)); |
| 728 | |
| 729 | // reparent and verify the new parent gets no vote |
| 730 | reparentLayer(11, 2); |
| 731 | expected = {1, 12, 121, 13, 2, 11, 111, 122, 1221}; |
| 732 | UPDATE_AND_VERIFY(mSnapshotBuilder, expected); |
| 733 | |
| 734 | // verify old parent has invalid framerate (default) |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 735 | EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid()); |
| 736 | EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type, |
Vishnu Nair | 3fbe326 | 2023-09-29 17:07:00 -0700 | [diff] [blame] | 737 | scheduler::FrameRateCompatibility::Default); |
Vishnu Nair | 52d56fd | 2023-07-20 17:02:43 +0000 | [diff] [blame] | 738 | EXPECT_TRUE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate)); |
| 739 | |
| 740 | // verify new parent get no vote |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 741 | EXPECT_FALSE(getSnapshot({.id = 2})->frameRate.vote.rate.isValid()); |
| 742 | EXPECT_EQ(getSnapshot({.id = 2})->frameRate.vote.type, |
Vishnu Nair | 3fbe326 | 2023-09-29 17:07:00 -0700 | [diff] [blame] | 743 | scheduler::FrameRateCompatibility::NoVote); |
Vishnu Nair | 52d56fd | 2023-07-20 17:02:43 +0000 | [diff] [blame] | 744 | EXPECT_TRUE(getSnapshot({.id = 2})->changes.test(RequestedLayerState::Changes::FrameRate)); |
| 745 | |
| 746 | // verify layer and children get the requested votes (unchanged) |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 747 | EXPECT_TRUE(getSnapshot({.id = 11})->frameRate.vote.rate.isValid()); |
| 748 | EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 244.f); |
| 749 | EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.type, |
Vishnu Nair | 3fbe326 | 2023-09-29 17:07:00 -0700 | [diff] [blame] | 750 | scheduler::FrameRateCompatibility::Default); |
Vishnu Nair | 52d56fd | 2023-07-20 17:02:43 +0000 | [diff] [blame] | 751 | |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 752 | EXPECT_TRUE(getSnapshot({.id = 111})->frameRate.vote.rate.isValid()); |
| 753 | EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.rate.getValue(), 244.f); |
| 754 | EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.type, |
Vishnu Nair | 3fbe326 | 2023-09-29 17:07:00 -0700 | [diff] [blame] | 755 | scheduler::FrameRateCompatibility::Default); |
Vishnu Nair | 52d56fd | 2023-07-20 17:02:43 +0000 | [diff] [blame] | 756 | |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 757 | EXPECT_TRUE(getSnapshot({.id = 122})->frameRate.vote.rate.isValid()); |
| 758 | EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.rate.getValue(), 244.f); |
| 759 | EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.type, |
Vishnu Nair | 3fbe326 | 2023-09-29 17:07:00 -0700 | [diff] [blame] | 760 | scheduler::FrameRateCompatibility::Default); |
Vishnu Nair | 52d56fd | 2023-07-20 17:02:43 +0000 | [diff] [blame] | 761 | } |
| 762 | |
Vishnu Nair | 3996ee3 | 2023-08-14 04:32:31 +0000 | [diff] [blame] | 763 | TEST_F(LayerSnapshotTest, translateDataspace) { |
| 764 | setDataspace(1, ui::Dataspace::UNKNOWN); |
| 765 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 766 | EXPECT_EQ(getSnapshot({.id = 1})->dataspace, ui::Dataspace::V0_SRGB); |
| 767 | } |
| 768 | |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 769 | // This test is similar to "frameRate" test case but checks that the setFrameRateCategory API |
| 770 | // interaction also works correctly with the setFrameRate API within SF frontend. |
| 771 | TEST_F(LayerSnapshotTest, frameRateWithCategory) { |
Rachel Lee | 4568198 | 2024-03-14 18:40:15 -0700 | [diff] [blame] | 772 | SET_FLAG_FOR_TEST(flags::frame_rate_category_mrr, true); |
| 773 | |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 774 | // ROOT |
| 775 | // ├── 1 |
| 776 | // │ ├── 11 (frame rate set to 244.f) |
| 777 | // │ │ └── 111 |
| 778 | // │ ├── 12 |
| 779 | // │ │ ├── 121 |
| 780 | // │ │ └── 122 (frame rate category set to Normal) |
| 781 | // │ │ └── 1221 |
| 782 | // │ └── 13 |
| 783 | // └── 2 |
| 784 | setFrameRate(11, 244.f, 0, 0); |
Rachel Lee | 9580ff1 | 2023-12-26 17:33:41 -0800 | [diff] [blame] | 785 | setFrameRateCategory(122, ANATIVEWINDOW_FRAME_RATE_CATEGORY_NORMAL); |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 786 | |
| 787 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 788 | // verify parent 1 gets no vote |
| 789 | EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid()); |
| 790 | EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type, |
Vishnu Nair | 3fbe326 | 2023-09-29 17:07:00 -0700 | [diff] [blame] | 791 | scheduler::FrameRateCompatibility::NoVote); |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 792 | EXPECT_TRUE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate)); |
| 793 | |
| 794 | // verify layer 11 and children 111 get the requested votes |
| 795 | EXPECT_TRUE(getSnapshot({.id = 11})->frameRate.vote.rate.isValid()); |
| 796 | EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 244.f); |
| 797 | EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.type, |
Vishnu Nair | 3fbe326 | 2023-09-29 17:07:00 -0700 | [diff] [blame] | 798 | scheduler::FrameRateCompatibility::Default); |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 799 | EXPECT_TRUE(getSnapshot({.id = 11})->changes.test(RequestedLayerState::Changes::FrameRate)); |
| 800 | |
| 801 | EXPECT_TRUE(getSnapshot({.id = 111})->frameRate.vote.rate.isValid()); |
| 802 | EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.rate.getValue(), 244.f); |
| 803 | EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.type, |
Vishnu Nair | 3fbe326 | 2023-09-29 17:07:00 -0700 | [diff] [blame] | 804 | scheduler::FrameRateCompatibility::Default); |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 805 | EXPECT_TRUE(getSnapshot({.id = 111})->changes.test(RequestedLayerState::Changes::FrameRate)); |
| 806 | |
| 807 | // verify parent 12 gets no vote |
| 808 | EXPECT_FALSE(getSnapshot({.id = 12})->frameRate.vote.rate.isValid()); |
| 809 | EXPECT_EQ(getSnapshot({.id = 12})->frameRate.vote.type, |
Vishnu Nair | 3fbe326 | 2023-09-29 17:07:00 -0700 | [diff] [blame] | 810 | scheduler::FrameRateCompatibility::NoVote); |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 811 | EXPECT_TRUE(getSnapshot({.id = 12})->changes.test(RequestedLayerState::Changes::FrameRate)); |
| 812 | |
| 813 | // verify layer 122 and children 1221 get the requested votes |
| 814 | EXPECT_FALSE(getSnapshot({.id = 122})->frameRate.vote.rate.isValid()); |
| 815 | EXPECT_TRUE(getSnapshot({.id = 122})->frameRate.isValid()); |
| 816 | EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.type, |
Vishnu Nair | 3fbe326 | 2023-09-29 17:07:00 -0700 | [diff] [blame] | 817 | scheduler::FrameRateCompatibility::Default); |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 818 | EXPECT_EQ(getSnapshot({.id = 122})->frameRate.category, FrameRateCategory::Normal); |
| 819 | EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate)); |
Rachel Lee | 43369b2 | 2023-09-05 18:40:40 -0700 | [diff] [blame] | 820 | EXPECT_TRUE( |
| 821 | getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::AffectsChildren)); |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 822 | |
| 823 | EXPECT_FALSE(getSnapshot({.id = 1221})->frameRate.vote.rate.isValid()); |
| 824 | EXPECT_TRUE(getSnapshot({.id = 1221})->frameRate.isValid()); |
| 825 | EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.vote.type, |
Vishnu Nair | 3fbe326 | 2023-09-29 17:07:00 -0700 | [diff] [blame] | 826 | scheduler::FrameRateCompatibility::Default); |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 827 | EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.category, FrameRateCategory::Normal); |
| 828 | EXPECT_TRUE(getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::FrameRate)); |
Rachel Lee | 43369b2 | 2023-09-05 18:40:40 -0700 | [diff] [blame] | 829 | EXPECT_TRUE( |
| 830 | getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::AffectsChildren)); |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 831 | |
| 832 | // reparent and verify the child does NOT get the new parent's framerate because it already has |
| 833 | // the frame rate category specified. |
| 834 | // ROOT |
| 835 | // ├─1 |
| 836 | // │ ├─11 (frame rate set to 244.f) |
| 837 | // │ │ ├─111 |
| 838 | // │ │ └─122 (frame rate category set to Normal) |
| 839 | // │ │ └─1221 |
| 840 | // │ ├─12 |
| 841 | // │ │ └─121 |
| 842 | // │ └─13 |
| 843 | // └─2 |
| 844 | reparentLayer(122, 11); |
| 845 | |
| 846 | std::vector<uint32_t> expected = {1, 11, 111, 122, 1221, 12, 121, 13, 2}; |
| 847 | UPDATE_AND_VERIFY(mSnapshotBuilder, expected); |
| 848 | // verify parent is gets no vote |
| 849 | EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid()); |
| 850 | EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type, |
Vishnu Nair | 3fbe326 | 2023-09-29 17:07:00 -0700 | [diff] [blame] | 851 | scheduler::FrameRateCompatibility::NoVote); |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 852 | |
| 853 | // verify layer 11 and children 111 get the requested votes |
| 854 | EXPECT_TRUE(getSnapshot({.id = 11})->frameRate.vote.rate.isValid()); |
| 855 | EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 244.f); |
| 856 | EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.type, |
Vishnu Nair | 3fbe326 | 2023-09-29 17:07:00 -0700 | [diff] [blame] | 857 | scheduler::FrameRateCompatibility::Default); |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 858 | |
| 859 | EXPECT_TRUE(getSnapshot({.id = 111})->frameRate.vote.rate.isValid()); |
| 860 | EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.rate.getValue(), 244.f); |
| 861 | EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.type, |
Vishnu Nair | 3fbe326 | 2023-09-29 17:07:00 -0700 | [diff] [blame] | 862 | scheduler::FrameRateCompatibility::Default); |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 863 | |
| 864 | // verify layer 122 and children 1221 get the requested category vote (unchanged from |
| 865 | // reparenting) |
| 866 | EXPECT_FALSE(getSnapshot({.id = 122})->frameRate.vote.rate.isValid()); |
| 867 | EXPECT_TRUE(getSnapshot({.id = 122})->frameRate.isValid()); |
| 868 | EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.type, |
Vishnu Nair | 3fbe326 | 2023-09-29 17:07:00 -0700 | [diff] [blame] | 869 | scheduler::FrameRateCompatibility::Default); |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 870 | EXPECT_EQ(getSnapshot({.id = 122})->frameRate.category, FrameRateCategory::Normal); |
| 871 | EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate)); |
| 872 | |
| 873 | EXPECT_FALSE(getSnapshot({.id = 1221})->frameRate.vote.rate.isValid()); |
| 874 | EXPECT_TRUE(getSnapshot({.id = 1221})->frameRate.isValid()); |
| 875 | EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.vote.type, |
Vishnu Nair | 3fbe326 | 2023-09-29 17:07:00 -0700 | [diff] [blame] | 876 | scheduler::FrameRateCompatibility::Default); |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 877 | EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.category, FrameRateCategory::Normal); |
| 878 | EXPECT_TRUE(getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::FrameRate)); |
| 879 | } |
| 880 | |
Rachel Lee | 58cc90d | 2023-09-05 18:50:20 -0700 | [diff] [blame] | 881 | TEST_F(LayerSnapshotTest, frameRateSelectionStrategy) { |
| 882 | // ROOT |
| 883 | // ├── 1 |
| 884 | // │ ├── 11 |
| 885 | // │ │ └── 111 |
| 886 | // │ ├── 12 (frame rate set to 244.f with strategy OverrideChildren) |
| 887 | // │ │ ├── 121 |
| 888 | // │ │ └── 122 (frame rate set to 123.f but should be overridden by layer 12) |
| 889 | // │ │ └── 1221 |
| 890 | // │ └── 13 |
| 891 | // └── 2 |
| 892 | setFrameRate(12, 244.f, 0, 0); |
| 893 | setFrameRate(122, 123.f, 0, 0); |
| 894 | setFrameRateSelectionStrategy(12, 1 /* OverrideChildren */); |
| 895 | |
| 896 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 897 | // verify parent 1 gets no vote |
| 898 | EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid()); |
| 899 | EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type, |
Vishnu Nair | 3fbe326 | 2023-09-29 17:07:00 -0700 | [diff] [blame] | 900 | scheduler::FrameRateCompatibility::NoVote); |
Rachel Lee | 58cc90d | 2023-09-05 18:50:20 -0700 | [diff] [blame] | 901 | EXPECT_TRUE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate)); |
| 902 | |
| 903 | // verify layer 12 and all descendants (121, 122, 1221) get the requested vote |
| 904 | EXPECT_EQ(getSnapshot({.id = 12})->frameRate.vote.rate.getValue(), 244.f); |
| 905 | EXPECT_EQ(getSnapshot({.id = 12})->frameRateSelectionStrategy, |
| 906 | scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren); |
| 907 | EXPECT_TRUE(getSnapshot({.id = 12})->changes.test(RequestedLayerState::Changes::FrameRate)); |
| 908 | |
| 909 | EXPECT_EQ(getSnapshot({.id = 121})->frameRate.vote.rate.getValue(), 244.f); |
| 910 | EXPECT_EQ(getSnapshot({.id = 121})->frameRateSelectionStrategy, |
| 911 | scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren); |
| 912 | EXPECT_TRUE(getSnapshot({.id = 121})->changes.test(RequestedLayerState::Changes::FrameRate)); |
| 913 | |
| 914 | EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.rate.getValue(), 244.f); |
| 915 | EXPECT_EQ(getSnapshot({.id = 122})->frameRateSelectionStrategy, |
| 916 | scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren); |
| 917 | EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate)); |
| 918 | |
| 919 | EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.vote.rate.getValue(), 244.f); |
| 920 | EXPECT_EQ(getSnapshot({.id = 1221})->frameRateSelectionStrategy, |
| 921 | scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren); |
| 922 | EXPECT_TRUE(getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::FrameRate)); |
Vishnu Nair | 41376b6 | 2023-11-08 05:08:58 -0800 | [diff] [blame] | 923 | |
| 924 | // ROOT |
| 925 | // ├── 1 |
| 926 | // │ ├── 11 |
| 927 | // │ │ └── 111 |
| 928 | // │ ├── 12 (frame rate set to default with strategy default) |
| 929 | // │ │ ├── 121 |
| 930 | // │ │ └── 122 (frame rate set to 123.f) |
| 931 | // │ │ └── 1221 |
| 932 | // │ └── 13 |
| 933 | // └── 2 |
| 934 | setFrameRate(12, -1.f, 0, 0); |
| 935 | setFrameRateSelectionStrategy(12, 0 /* Default */); |
| 936 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 937 | // verify parent 1 gets no vote |
| 938 | EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid()); |
| 939 | EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type, |
| 940 | scheduler::FrameRateCompatibility::NoVote); |
| 941 | EXPECT_FALSE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate)); |
| 942 | |
| 943 | // verify layer 12 and all descendants (121, 122, 1221) get the requested vote |
| 944 | EXPECT_FALSE(getSnapshot({.id = 12})->frameRate.vote.rate.isValid()); |
| 945 | EXPECT_EQ(getSnapshot({.id = 12})->frameRate.vote.type, |
| 946 | scheduler::FrameRateCompatibility::NoVote); |
| 947 | EXPECT_EQ(getSnapshot({.id = 12})->frameRateSelectionStrategy, |
Rachel Lee | 70f7b69 | 2023-11-22 11:24:02 -0800 | [diff] [blame] | 948 | scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate); |
Vishnu Nair | 41376b6 | 2023-11-08 05:08:58 -0800 | [diff] [blame] | 949 | EXPECT_TRUE(getSnapshot({.id = 12})->changes.test(RequestedLayerState::Changes::FrameRate)); |
| 950 | |
| 951 | EXPECT_FALSE(getSnapshot({.id = 121})->frameRate.vote.rate.isValid()); |
| 952 | EXPECT_EQ(getSnapshot({.id = 121})->frameRateSelectionStrategy, |
Rachel Lee | 70f7b69 | 2023-11-22 11:24:02 -0800 | [diff] [blame] | 953 | scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate); |
Vishnu Nair | 41376b6 | 2023-11-08 05:08:58 -0800 | [diff] [blame] | 954 | EXPECT_EQ(getSnapshot({.id = 121})->frameRate.vote.type, |
| 955 | scheduler::FrameRateCompatibility::Default); |
| 956 | EXPECT_TRUE(getSnapshot({.id = 121})->changes.test(RequestedLayerState::Changes::FrameRate)); |
| 957 | |
| 958 | EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.rate.getValue(), 123.f); |
| 959 | EXPECT_EQ(getSnapshot({.id = 122})->frameRateSelectionStrategy, |
Rachel Lee | 70f7b69 | 2023-11-22 11:24:02 -0800 | [diff] [blame] | 960 | scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate); |
Vishnu Nair | 41376b6 | 2023-11-08 05:08:58 -0800 | [diff] [blame] | 961 | EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate)); |
| 962 | |
| 963 | EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.vote.rate.getValue(), 123.f); |
| 964 | EXPECT_EQ(getSnapshot({.id = 1221})->frameRateSelectionStrategy, |
Rachel Lee | 70f7b69 | 2023-11-22 11:24:02 -0800 | [diff] [blame] | 965 | scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate); |
Vishnu Nair | 41376b6 | 2023-11-08 05:08:58 -0800 | [diff] [blame] | 966 | EXPECT_TRUE(getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::FrameRate)); |
| 967 | } |
| 968 | |
| 969 | TEST_F(LayerSnapshotTest, frameRateSelectionStrategyWithCategory) { |
Rachel Lee | 4568198 | 2024-03-14 18:40:15 -0700 | [diff] [blame] | 970 | SET_FLAG_FOR_TEST(flags::frame_rate_category_mrr, true); |
| 971 | |
Vishnu Nair | 41376b6 | 2023-11-08 05:08:58 -0800 | [diff] [blame] | 972 | // ROOT |
| 973 | // ├── 1 |
| 974 | // │ ├── 11 |
| 975 | // │ │ └── 111 |
| 976 | // │ ├── 12 (frame rate category set to high with strategy OverrideChildren) |
| 977 | // │ │ ├── 121 |
| 978 | // │ │ └── 122 (frame rate set to 123.f but should be overridden by layer 12) |
| 979 | // │ │ └── 1221 |
| 980 | // │ └── 13 |
| 981 | // └── 2 |
Rachel Lee | 9580ff1 | 2023-12-26 17:33:41 -0800 | [diff] [blame] | 982 | setFrameRateCategory(12, ANATIVEWINDOW_FRAME_RATE_CATEGORY_HIGH); |
Vishnu Nair | 41376b6 | 2023-11-08 05:08:58 -0800 | [diff] [blame] | 983 | setFrameRate(122, 123.f, 0, 0); |
| 984 | setFrameRateSelectionStrategy(12, 1 /* OverrideChildren */); |
| 985 | |
| 986 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 987 | // verify parent 1 gets no vote |
| 988 | EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid()); |
| 989 | EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type, |
| 990 | scheduler::FrameRateCompatibility::NoVote); |
| 991 | EXPECT_TRUE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate)); |
| 992 | |
| 993 | // verify layer 12 and all descendants (121, 122, 1221) get the requested vote |
| 994 | EXPECT_EQ(getSnapshot({.id = 12})->frameRate.category, FrameRateCategory::High); |
| 995 | EXPECT_EQ(getSnapshot({.id = 12})->frameRateSelectionStrategy, |
| 996 | scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren); |
| 997 | EXPECT_TRUE(getSnapshot({.id = 12})->changes.test(RequestedLayerState::Changes::FrameRate)); |
| 998 | |
| 999 | EXPECT_EQ(getSnapshot({.id = 121})->frameRate.category, FrameRateCategory::High); |
| 1000 | EXPECT_EQ(getSnapshot({.id = 121})->frameRateSelectionStrategy, |
| 1001 | scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren); |
| 1002 | EXPECT_TRUE(getSnapshot({.id = 121})->changes.test(RequestedLayerState::Changes::FrameRate)); |
| 1003 | |
| 1004 | EXPECT_EQ(getSnapshot({.id = 122})->frameRate.category, FrameRateCategory::High); |
| 1005 | EXPECT_EQ(getSnapshot({.id = 122})->frameRateSelectionStrategy, |
| 1006 | scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren); |
| 1007 | EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate)); |
| 1008 | |
| 1009 | EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.category, FrameRateCategory::High); |
| 1010 | EXPECT_EQ(getSnapshot({.id = 1221})->frameRateSelectionStrategy, |
| 1011 | scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren); |
| 1012 | EXPECT_TRUE(getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::FrameRate)); |
| 1013 | |
| 1014 | // ROOT |
| 1015 | // ├── 1 |
| 1016 | // │ ├── 11 |
| 1017 | // │ │ └── 111 |
| 1018 | // │ ├── 12 (frame rate category to default with strategy default) |
| 1019 | // │ │ ├── 121 |
| 1020 | // │ │ └── 122 (frame rate set to 123.f) |
| 1021 | // │ │ └── 1221 |
| 1022 | // │ └── 13 |
| 1023 | // └── 2 |
Rachel Lee | 9580ff1 | 2023-12-26 17:33:41 -0800 | [diff] [blame] | 1024 | setFrameRateCategory(12, ANATIVEWINDOW_FRAME_RATE_CATEGORY_DEFAULT); |
Vishnu Nair | 41376b6 | 2023-11-08 05:08:58 -0800 | [diff] [blame] | 1025 | setFrameRateSelectionStrategy(12, 0 /* Default */); |
| 1026 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 1027 | // verify parent 1 gets no vote |
| 1028 | EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid()); |
| 1029 | EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type, |
| 1030 | scheduler::FrameRateCompatibility::NoVote); |
| 1031 | EXPECT_EQ(getSnapshot({.id = 1})->frameRate.category, FrameRateCategory::Default); |
| 1032 | EXPECT_FALSE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate)); |
| 1033 | |
| 1034 | // verify layer 12 and all descendants (121, 122, 1221) get the requested vote |
| 1035 | EXPECT_FALSE(getSnapshot({.id = 12})->frameRate.vote.rate.isValid()); |
| 1036 | EXPECT_EQ(getSnapshot({.id = 12})->frameRate.vote.type, |
| 1037 | scheduler::FrameRateCompatibility::NoVote); |
| 1038 | EXPECT_EQ(getSnapshot({.id = 12})->frameRate.category, FrameRateCategory::Default); |
| 1039 | EXPECT_EQ(getSnapshot({.id = 12})->frameRateSelectionStrategy, |
Rachel Lee | 70f7b69 | 2023-11-22 11:24:02 -0800 | [diff] [blame] | 1040 | scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate); |
Vishnu Nair | 41376b6 | 2023-11-08 05:08:58 -0800 | [diff] [blame] | 1041 | EXPECT_TRUE(getSnapshot({.id = 12})->changes.test(RequestedLayerState::Changes::FrameRate)); |
| 1042 | |
| 1043 | EXPECT_FALSE(getSnapshot({.id = 12})->frameRate.vote.rate.isValid()); |
| 1044 | EXPECT_EQ(getSnapshot({.id = 121})->frameRateSelectionStrategy, |
Rachel Lee | 70f7b69 | 2023-11-22 11:24:02 -0800 | [diff] [blame] | 1045 | scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate); |
Vishnu Nair | 41376b6 | 2023-11-08 05:08:58 -0800 | [diff] [blame] | 1046 | EXPECT_EQ(getSnapshot({.id = 121})->frameRate.category, FrameRateCategory::Default); |
| 1047 | EXPECT_EQ(getSnapshot({.id = 121})->frameRate.vote.type, |
| 1048 | scheduler::FrameRateCompatibility::Default); |
| 1049 | EXPECT_TRUE(getSnapshot({.id = 121})->changes.test(RequestedLayerState::Changes::FrameRate)); |
| 1050 | |
| 1051 | EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.rate.getValue(), 123.f); |
| 1052 | EXPECT_EQ(getSnapshot({.id = 122})->frameRateSelectionStrategy, |
Rachel Lee | 70f7b69 | 2023-11-22 11:24:02 -0800 | [diff] [blame] | 1053 | scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate); |
Vishnu Nair | 41376b6 | 2023-11-08 05:08:58 -0800 | [diff] [blame] | 1054 | EXPECT_EQ(getSnapshot({.id = 122})->frameRate.category, FrameRateCategory::Default); |
| 1055 | EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate)); |
| 1056 | |
| 1057 | EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.vote.rate.getValue(), 123.f); |
| 1058 | EXPECT_EQ(getSnapshot({.id = 1221})->frameRateSelectionStrategy, |
Rachel Lee | 70f7b69 | 2023-11-22 11:24:02 -0800 | [diff] [blame] | 1059 | scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate); |
Vishnu Nair | 41376b6 | 2023-11-08 05:08:58 -0800 | [diff] [blame] | 1060 | EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.category, FrameRateCategory::Default); |
| 1061 | EXPECT_TRUE(getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::FrameRate)); |
Rachel Lee | 58cc90d | 2023-09-05 18:50:20 -0700 | [diff] [blame] | 1062 | } |
| 1063 | |
Rachel Lee | 70f7b69 | 2023-11-22 11:24:02 -0800 | [diff] [blame] | 1064 | TEST_F(LayerSnapshotTest, frameRateSelectionStrategyWithOverrideChildrenAndSelf) { |
Rachel Lee | a021bb0 | 2023-11-20 21:51:09 -0800 | [diff] [blame] | 1065 | // ROOT |
| 1066 | // ├── 1 |
Rachel Lee | 70f7b69 | 2023-11-22 11:24:02 -0800 | [diff] [blame] | 1067 | // │ ├── 11 (frame rate set to 11.f with strategy Self) |
Rachel Lee | a021bb0 | 2023-11-20 21:51:09 -0800 | [diff] [blame] | 1068 | // │ │ └── 111 (frame rate is not inherited) |
| 1069 | // │ ├── 12 (frame rate set to 244.f) |
| 1070 | // │ │ ├── 121 |
| 1071 | // │ │ └── 122 (strategy OverrideChildren and inherits frame rate 244.f) |
| 1072 | // │ │ └── 1221 (frame rate set to 123.f but should be overridden by layer 122) |
| 1073 | // │ └── 13 |
| 1074 | // └── 2 |
| 1075 | setFrameRate(11, 11.f, 0, 0); |
Rachel Lee | 70f7b69 | 2023-11-22 11:24:02 -0800 | [diff] [blame] | 1076 | setFrameRateSelectionStrategy(11, 2 /* Self */); |
Rachel Lee | a021bb0 | 2023-11-20 21:51:09 -0800 | [diff] [blame] | 1077 | setFrameRate(12, 244.f, 0, 0); |
| 1078 | setFrameRateSelectionStrategy(122, 1 /* OverrideChildren */); |
| 1079 | setFrameRate(1221, 123.f, 0, 0); |
| 1080 | |
| 1081 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 1082 | // verify parent 1 gets no vote |
| 1083 | EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid()); |
| 1084 | EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type, |
| 1085 | scheduler::FrameRateCompatibility::NoVote); |
| 1086 | EXPECT_EQ(getSnapshot({.id = 1})->frameRateSelectionStrategy, |
Rachel Lee | 70f7b69 | 2023-11-22 11:24:02 -0800 | [diff] [blame] | 1087 | scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate); |
Rachel Lee | a021bb0 | 2023-11-20 21:51:09 -0800 | [diff] [blame] | 1088 | EXPECT_TRUE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate)); |
| 1089 | |
| 1090 | EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 11.f); |
| 1091 | EXPECT_EQ(getSnapshot({.id = 11})->frameRateSelectionStrategy, |
Rachel Lee | 70f7b69 | 2023-11-22 11:24:02 -0800 | [diff] [blame] | 1092 | scheduler::LayerInfo::FrameRateSelectionStrategy::Self); |
Rachel Lee | a021bb0 | 2023-11-20 21:51:09 -0800 | [diff] [blame] | 1093 | EXPECT_TRUE(getSnapshot({.id = 11})->changes.test(RequestedLayerState::Changes::FrameRate)); |
| 1094 | |
| 1095 | // verify layer 11 does does not propagate its framerate to 111. |
| 1096 | EXPECT_FALSE(getSnapshot({.id = 111})->frameRate.vote.rate.isValid()); |
| 1097 | EXPECT_EQ(getSnapshot({.id = 111})->frameRateSelectionStrategy, |
Rachel Lee | 70f7b69 | 2023-11-22 11:24:02 -0800 | [diff] [blame] | 1098 | scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate); |
Rachel Lee | a021bb0 | 2023-11-20 21:51:09 -0800 | [diff] [blame] | 1099 | EXPECT_TRUE(getSnapshot({.id = 111})->changes.test(RequestedLayerState::Changes::FrameRate)); |
| 1100 | |
| 1101 | // verify layer 12 and all descendants (121, 122, 1221) get the requested vote |
| 1102 | EXPECT_EQ(getSnapshot({.id = 12})->frameRate.vote.rate.getValue(), 244.f); |
| 1103 | EXPECT_EQ(getSnapshot({.id = 12})->frameRateSelectionStrategy, |
Rachel Lee | 70f7b69 | 2023-11-22 11:24:02 -0800 | [diff] [blame] | 1104 | scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate); |
Rachel Lee | a021bb0 | 2023-11-20 21:51:09 -0800 | [diff] [blame] | 1105 | EXPECT_TRUE(getSnapshot({.id = 12})->changes.test(RequestedLayerState::Changes::FrameRate)); |
| 1106 | |
| 1107 | EXPECT_EQ(getSnapshot({.id = 121})->frameRate.vote.rate.getValue(), 244.f); |
| 1108 | EXPECT_EQ(getSnapshot({.id = 121})->frameRateSelectionStrategy, |
Rachel Lee | 70f7b69 | 2023-11-22 11:24:02 -0800 | [diff] [blame] | 1109 | scheduler::LayerInfo::FrameRateSelectionStrategy::Propagate); |
Rachel Lee | a021bb0 | 2023-11-20 21:51:09 -0800 | [diff] [blame] | 1110 | EXPECT_TRUE(getSnapshot({.id = 121})->changes.test(RequestedLayerState::Changes::FrameRate)); |
| 1111 | |
| 1112 | EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.rate.getValue(), 244.f); |
| 1113 | EXPECT_EQ(getSnapshot({.id = 122})->frameRateSelectionStrategy, |
| 1114 | scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren); |
| 1115 | EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate)); |
| 1116 | |
| 1117 | EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.vote.rate.getValue(), 244.f); |
| 1118 | EXPECT_EQ(getSnapshot({.id = 1221})->frameRateSelectionStrategy, |
| 1119 | scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren); |
| 1120 | EXPECT_TRUE(getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::FrameRate)); |
| 1121 | |
| 1122 | // ROOT |
| 1123 | // ├── 1 (frame rate set to 1.f with strategy OverrideChildren) |
Rachel Lee | 70f7b69 | 2023-11-22 11:24:02 -0800 | [diff] [blame] | 1124 | // │ ├── 11 (frame rate set to 11.f with strategy Self, but overridden by 1) |
Rachel Lee | a021bb0 | 2023-11-20 21:51:09 -0800 | [diff] [blame] | 1125 | // │ │ └── 111 (frame rate inherited from 11 due to override from 1) |
| 1126 | // â‹® â‹® |
| 1127 | setFrameRate(1, 1.f, 0, 0); |
| 1128 | setFrameRateSelectionStrategy(1, 1 /* OverrideChildren */); |
| 1129 | setFrameRate(11, 11.f, 0, 0); |
Rachel Lee | 70f7b69 | 2023-11-22 11:24:02 -0800 | [diff] [blame] | 1130 | setFrameRateSelectionStrategy(11, 2 /* Self */); |
Rachel Lee | a021bb0 | 2023-11-20 21:51:09 -0800 | [diff] [blame] | 1131 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 1132 | |
| 1133 | EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.rate.getValue(), 1.f); |
| 1134 | EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type, |
| 1135 | scheduler::FrameRateCompatibility::Default); |
| 1136 | EXPECT_EQ(getSnapshot({.id = 1})->frameRateSelectionStrategy, |
| 1137 | scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren); |
| 1138 | EXPECT_TRUE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate)); |
| 1139 | |
| 1140 | EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 1.f); |
| 1141 | EXPECT_EQ(getSnapshot({.id = 11})->frameRateSelectionStrategy, |
| 1142 | scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren); |
| 1143 | EXPECT_TRUE(getSnapshot({.id = 11})->changes.test(RequestedLayerState::Changes::FrameRate)); |
| 1144 | |
| 1145 | // verify layer 11 does does not propagate its framerate to 111. |
| 1146 | EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.rate.getValue(), 1.f); |
| 1147 | EXPECT_EQ(getSnapshot({.id = 111})->frameRateSelectionStrategy, |
| 1148 | scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren); |
| 1149 | EXPECT_TRUE(getSnapshot({.id = 111})->changes.test(RequestedLayerState::Changes::FrameRate)); |
| 1150 | } |
| 1151 | |
Vishnu Nair | 0808ae6 | 2023-08-07 21:42:42 -0700 | [diff] [blame] | 1152 | TEST_F(LayerSnapshotTest, skipRoundCornersWhenProtected) { |
| 1153 | setRoundedCorners(1, 42.f); |
| 1154 | setRoundedCorners(2, 42.f); |
| 1155 | setCrop(1, Rect{1000, 1000}); |
| 1156 | setCrop(2, Rect{1000, 1000}); |
| 1157 | |
| 1158 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 1159 | EXPECT_TRUE(getSnapshot({.id = 1})->roundedCorner.hasRoundedCorners()); |
| 1160 | EXPECT_EQ(getSnapshot({.id = 1})->roundedCorner.radius.x, 42.f); |
| 1161 | EXPECT_TRUE(getSnapshot({.id = 2})->roundedCorner.hasRoundedCorners()); |
| 1162 | |
| 1163 | // add a buffer with the protected bit, check rounded corners are not set when |
| 1164 | // skipRoundCornersWhenProtected == true |
| 1165 | setBuffer(1, |
| 1166 | std::make_shared< |
| 1167 | renderengine::mock::FakeExternalTexture>(1U /*width*/, 1U /*height*/, |
| 1168 | 1ULL /* bufferId */, |
| 1169 | HAL_PIXEL_FORMAT_RGBA_8888, |
| 1170 | GRALLOC_USAGE_PROTECTED /*usage*/)); |
| 1171 | |
| 1172 | LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(), |
| 1173 | .layerLifecycleManager = mLifecycleManager, |
| 1174 | .includeMetadata = false, |
| 1175 | .displays = mFrontEndDisplayInfos, |
| 1176 | .displayChanges = false, |
| 1177 | .globalShadowSettings = globalShadowSettings, |
| 1178 | .supportsBlur = true, |
| 1179 | .supportedLayerGenericMetadata = {}, |
| 1180 | .genericLayerMetadataKeyMap = {}, |
| 1181 | .skipRoundCornersWhenProtected = true}; |
| 1182 | update(mSnapshotBuilder, args); |
| 1183 | EXPECT_FALSE(getSnapshot({.id = 1})->roundedCorner.hasRoundedCorners()); |
| 1184 | // layer 2 doesn't have a buffer and should be unaffected |
| 1185 | EXPECT_TRUE(getSnapshot({.id = 2})->roundedCorner.hasRoundedCorners()); |
| 1186 | |
| 1187 | // remove protected bit, check rounded corners are set |
| 1188 | setBuffer(1, |
| 1189 | std::make_shared<renderengine::mock::FakeExternalTexture>(1U /*width*/, 1U /*height*/, |
| 1190 | 2ULL /* bufferId */, |
| 1191 | HAL_PIXEL_FORMAT_RGBA_8888, |
| 1192 | 0 /*usage*/)); |
| 1193 | update(mSnapshotBuilder, args); |
| 1194 | EXPECT_TRUE(getSnapshot({.id = 1})->roundedCorner.hasRoundedCorners()); |
| 1195 | EXPECT_EQ(getSnapshot({.id = 1})->roundedCorner.radius.x, 42.f); |
| 1196 | } |
| 1197 | |
Vishnu Nair | bd51f95 | 2023-08-31 22:50:14 -0700 | [diff] [blame] | 1198 | TEST_F(LayerSnapshotTest, setRefreshRateIndicatorCompositionType) { |
| 1199 | setFlags(1, layer_state_t::eLayerIsRefreshRateIndicator, |
| 1200 | layer_state_t::eLayerIsRefreshRateIndicator); |
| 1201 | setBuffer(1, |
| 1202 | std::make_shared<renderengine::mock::FakeExternalTexture>(1U /*width*/, 1U /*height*/, |
| 1203 | 42ULL /* bufferId */, |
| 1204 | HAL_PIXEL_FORMAT_RGBA_8888, |
| 1205 | 0 /*usage*/)); |
| 1206 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 1207 | EXPECT_EQ(getSnapshot({.id = 1})->compositionType, |
| 1208 | aidl::android::hardware::graphics::composer3::Composition::REFRESH_RATE_INDICATOR); |
| 1209 | } |
| 1210 | |
Chavi Weingarten | 0759734 | 2023-09-14 21:10:59 +0000 | [diff] [blame] | 1211 | TEST_F(LayerSnapshotTest, setBufferCrop) { |
| 1212 | // validate no buffer but has crop |
| 1213 | Rect crop = Rect(0, 0, 50, 50); |
| 1214 | setBufferCrop(1, crop); |
| 1215 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 1216 | EXPECT_EQ(getSnapshot(1)->geomContentCrop, crop); |
| 1217 | |
| 1218 | setBuffer(1, |
| 1219 | std::make_shared<renderengine::mock::FakeExternalTexture>(100U /*width*/, |
| 1220 | 100U /*height*/, |
| 1221 | 42ULL /* bufferId */, |
| 1222 | HAL_PIXEL_FORMAT_RGBA_8888, |
| 1223 | 0 /*usage*/)); |
| 1224 | // validate a buffer crop within the buffer bounds |
| 1225 | setBufferCrop(1, crop); |
| 1226 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 1227 | EXPECT_EQ(getSnapshot(1)->geomContentCrop, crop); |
| 1228 | |
| 1229 | // validate a buffer crop outside the buffer bounds |
| 1230 | crop = Rect(0, 0, 150, 150); |
| 1231 | setBufferCrop(1, crop); |
| 1232 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 1233 | EXPECT_EQ(getSnapshot(1)->geomContentCrop, Rect(0, 0, 100, 100)); |
| 1234 | |
| 1235 | // validate no buffer crop |
| 1236 | setBufferCrop(1, Rect()); |
| 1237 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 1238 | EXPECT_EQ(getSnapshot(1)->geomContentCrop, Rect(0, 0, 100, 100)); |
| 1239 | } |
Vishnu Nair | befd3e2 | 2023-10-05 17:48:31 +0000 | [diff] [blame] | 1240 | |
| 1241 | TEST_F(LayerSnapshotTest, setShadowRadius) { |
| 1242 | static constexpr float SHADOW_RADIUS = 123.f; |
| 1243 | setShadowRadius(1, SHADOW_RADIUS); |
| 1244 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 1245 | EXPECT_EQ(getSnapshot(1)->shadowSettings.length, SHADOW_RADIUS); |
Vishnu Nair | befd3e2 | 2023-10-05 17:48:31 +0000 | [diff] [blame] | 1246 | } |
| 1247 | |
Chavi Weingarten | b74093a | 2023-10-11 20:29:59 +0000 | [diff] [blame] | 1248 | TEST_F(LayerSnapshotTest, setTrustedOverlayForNonVisibleInput) { |
| 1249 | hideLayer(1); |
Vishnu Nair | 9e0017e | 2024-05-22 19:02:44 +0000 | [diff] [blame^] | 1250 | setTrustedOverlay(1, gui::TrustedOverlay::ENABLED); |
Chavi Weingarten | b74093a | 2023-10-11 20:29:59 +0000 | [diff] [blame] | 1251 | Region touch{Rect{0, 0, 1000, 1000}}; |
| 1252 | setTouchableRegion(1, touch); |
| 1253 | |
| 1254 | UPDATE_AND_VERIFY(mSnapshotBuilder, {2}); |
| 1255 | EXPECT_TRUE(getSnapshot(1)->inputInfo.inputConfig.test( |
| 1256 | gui::WindowInfo::InputConfig::TRUSTED_OVERLAY)); |
| 1257 | } |
| 1258 | |
Alec Mouri | 89f5d4e | 2023-10-20 17:12:49 +0000 | [diff] [blame] | 1259 | TEST_F(LayerSnapshotTest, isFrontBuffered) { |
| 1260 | setBuffer(1, |
| 1261 | std::make_shared<renderengine::mock::FakeExternalTexture>( |
| 1262 | 1U /*width*/, 1U /*height*/, 1ULL /* bufferId */, HAL_PIXEL_FORMAT_RGBA_8888, |
| 1263 | GRALLOC_USAGE_HW_TEXTURE | AHARDWAREBUFFER_USAGE_FRONT_BUFFER /*usage*/)); |
| 1264 | |
| 1265 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 1266 | EXPECT_TRUE(getSnapshot(1)->isFrontBuffered()); |
| 1267 | |
| 1268 | setBuffer(1, |
| 1269 | std::make_shared< |
| 1270 | renderengine::mock::FakeExternalTexture>(1U /*width*/, 1U /*height*/, |
| 1271 | 1ULL /* bufferId */, |
| 1272 | HAL_PIXEL_FORMAT_RGBA_8888, |
| 1273 | GRALLOC_USAGE_HW_TEXTURE /*usage*/)); |
| 1274 | |
| 1275 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 1276 | EXPECT_FALSE(getSnapshot(1)->isFrontBuffered()); |
| 1277 | } |
| 1278 | |
Chavi Weingarten | 4aa22af | 2023-11-17 19:37:07 +0000 | [diff] [blame] | 1279 | TEST_F(LayerSnapshotTest, setSecureRootSnapshot) { |
| 1280 | setFlags(1, layer_state_t::eLayerSecure, layer_state_t::eLayerSecure); |
| 1281 | LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(), |
| 1282 | .layerLifecycleManager = mLifecycleManager, |
| 1283 | .includeMetadata = false, |
| 1284 | .displays = mFrontEndDisplayInfos, |
| 1285 | .displayChanges = false, |
| 1286 | .globalShadowSettings = globalShadowSettings, |
| 1287 | .supportsBlur = true, |
| 1288 | .supportedLayerGenericMetadata = {}, |
| 1289 | .genericLayerMetadataKeyMap = {}}; |
| 1290 | args.rootSnapshot.isSecure = true; |
| 1291 | update(mSnapshotBuilder, args); |
| 1292 | |
| 1293 | EXPECT_TRUE(getSnapshot(1)->isSecure); |
| 1294 | // Ensure child is also marked as secure |
| 1295 | EXPECT_TRUE(getSnapshot(11)->isSecure); |
| 1296 | } |
| 1297 | |
Prabir Pradhan | cf35919 | 2024-03-20 00:42:57 +0000 | [diff] [blame] | 1298 | TEST_F(LayerSnapshotTest, setSensitiveForTracingConfigForSecureLayers) { |
| 1299 | setFlags(11, layer_state_t::eLayerSecure, layer_state_t::eLayerSecure); |
| 1300 | |
| 1301 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 1302 | |
| 1303 | EXPECT_TRUE(getSnapshot(11)->inputInfo.inputConfig.test( |
Arpit Singh | 490ccc9 | 2024-04-30 14:26:21 +0000 | [diff] [blame] | 1304 | gui::WindowInfo::InputConfig::SENSITIVE_FOR_PRIVACY)); |
Prabir Pradhan | cf35919 | 2024-03-20 00:42:57 +0000 | [diff] [blame] | 1305 | EXPECT_TRUE(getSnapshot(111)->inputInfo.inputConfig.test( |
Arpit Singh | 490ccc9 | 2024-04-30 14:26:21 +0000 | [diff] [blame] | 1306 | gui::WindowInfo::InputConfig::SENSITIVE_FOR_PRIVACY)); |
Prabir Pradhan | cf35919 | 2024-03-20 00:42:57 +0000 | [diff] [blame] | 1307 | EXPECT_FALSE(getSnapshot(1)->inputInfo.inputConfig.test( |
Arpit Singh | 490ccc9 | 2024-04-30 14:26:21 +0000 | [diff] [blame] | 1308 | gui::WindowInfo::InputConfig::SENSITIVE_FOR_PRIVACY)); |
Prabir Pradhan | cf35919 | 2024-03-20 00:42:57 +0000 | [diff] [blame] | 1309 | EXPECT_FALSE(getSnapshot(12)->inputInfo.inputConfig.test( |
Arpit Singh | 490ccc9 | 2024-04-30 14:26:21 +0000 | [diff] [blame] | 1310 | gui::WindowInfo::InputConfig::SENSITIVE_FOR_PRIVACY)); |
Prabir Pradhan | cf35919 | 2024-03-20 00:42:57 +0000 | [diff] [blame] | 1311 | EXPECT_FALSE(getSnapshot(2)->inputInfo.inputConfig.test( |
Arpit Singh | 490ccc9 | 2024-04-30 14:26:21 +0000 | [diff] [blame] | 1312 | gui::WindowInfo::InputConfig::SENSITIVE_FOR_PRIVACY)); |
Prabir Pradhan | cf35919 | 2024-03-20 00:42:57 +0000 | [diff] [blame] | 1313 | } |
| 1314 | |
| 1315 | TEST_F(LayerSnapshotTest, setSensitiveForTracingFromInputWindowHandle) { |
| 1316 | setInputInfo(11, [](auto& inputInfo) { |
Arpit Singh | 490ccc9 | 2024-04-30 14:26:21 +0000 | [diff] [blame] | 1317 | inputInfo.inputConfig |= gui::WindowInfo::InputConfig::SENSITIVE_FOR_PRIVACY; |
Prabir Pradhan | cf35919 | 2024-03-20 00:42:57 +0000 | [diff] [blame] | 1318 | }); |
| 1319 | |
| 1320 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 1321 | |
| 1322 | EXPECT_TRUE(getSnapshot(11)->inputInfo.inputConfig.test( |
Arpit Singh | 490ccc9 | 2024-04-30 14:26:21 +0000 | [diff] [blame] | 1323 | gui::WindowInfo::InputConfig::SENSITIVE_FOR_PRIVACY)); |
Prabir Pradhan | cf35919 | 2024-03-20 00:42:57 +0000 | [diff] [blame] | 1324 | EXPECT_TRUE(getSnapshot(111)->inputInfo.inputConfig.test( |
Arpit Singh | 490ccc9 | 2024-04-30 14:26:21 +0000 | [diff] [blame] | 1325 | gui::WindowInfo::InputConfig::SENSITIVE_FOR_PRIVACY)); |
Prabir Pradhan | cf35919 | 2024-03-20 00:42:57 +0000 | [diff] [blame] | 1326 | EXPECT_FALSE(getSnapshot(1)->inputInfo.inputConfig.test( |
Arpit Singh | 490ccc9 | 2024-04-30 14:26:21 +0000 | [diff] [blame] | 1327 | gui::WindowInfo::InputConfig::SENSITIVE_FOR_PRIVACY)); |
Prabir Pradhan | cf35919 | 2024-03-20 00:42:57 +0000 | [diff] [blame] | 1328 | EXPECT_FALSE(getSnapshot(12)->inputInfo.inputConfig.test( |
Arpit Singh | 490ccc9 | 2024-04-30 14:26:21 +0000 | [diff] [blame] | 1329 | gui::WindowInfo::InputConfig::SENSITIVE_FOR_PRIVACY)); |
Prabir Pradhan | cf35919 | 2024-03-20 00:42:57 +0000 | [diff] [blame] | 1330 | EXPECT_FALSE(getSnapshot(2)->inputInfo.inputConfig.test( |
Arpit Singh | 490ccc9 | 2024-04-30 14:26:21 +0000 | [diff] [blame] | 1331 | gui::WindowInfo::InputConfig::SENSITIVE_FOR_PRIVACY)); |
Prabir Pradhan | cf35919 | 2024-03-20 00:42:57 +0000 | [diff] [blame] | 1332 | } |
| 1333 | |
Vishnu Nair | f13c898 | 2023-12-02 11:26:09 -0800 | [diff] [blame] | 1334 | // b/314350323 |
| 1335 | TEST_F(LayerSnapshotTest, propagateDropInputMode) { |
| 1336 | setDropInputMode(1, gui::DropInputMode::ALL); |
| 1337 | LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(), |
| 1338 | .layerLifecycleManager = mLifecycleManager, |
| 1339 | .includeMetadata = false, |
| 1340 | .displays = mFrontEndDisplayInfos, |
| 1341 | .displayChanges = false, |
| 1342 | .globalShadowSettings = globalShadowSettings, |
| 1343 | .supportsBlur = true, |
| 1344 | .supportedLayerGenericMetadata = {}, |
| 1345 | .genericLayerMetadataKeyMap = {}}; |
| 1346 | args.rootSnapshot.isSecure = true; |
| 1347 | update(mSnapshotBuilder, args); |
| 1348 | |
| 1349 | EXPECT_EQ(getSnapshot(1)->dropInputMode, gui::DropInputMode::ALL); |
| 1350 | // Ensure child also has the correct drop input mode regardless of whether either layer has |
| 1351 | // an input channel |
| 1352 | EXPECT_EQ(getSnapshot(11)->dropInputMode, gui::DropInputMode::ALL); |
| 1353 | } |
| 1354 | |
Chavi Weingarten | 92c7d8c | 2024-01-19 23:25:45 +0000 | [diff] [blame] | 1355 | TEST_F(LayerSnapshotTest, NonVisibleLayerWithInput) { |
| 1356 | LayerHierarchyTestBase::createRootLayer(3); |
| 1357 | setColor(3, {-1._hf, -1._hf, -1._hf}); |
| 1358 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 1359 | |
| 1360 | std::vector<TransactionState> transactions; |
| 1361 | transactions.emplace_back(); |
| 1362 | transactions.back().states.push_back({}); |
| 1363 | transactions.back().states.front().state.what = layer_state_t::eInputInfoChanged; |
| 1364 | transactions.back().states.front().layerId = 3; |
| 1365 | transactions.back().states.front().state.windowInfoHandle = sp<gui::WindowInfoHandle>::make(); |
| 1366 | auto inputInfo = transactions.back().states.front().state.windowInfoHandle->editInfo(); |
| 1367 | inputInfo->token = sp<BBinder>::make(); |
| 1368 | mLifecycleManager.applyTransactions(transactions); |
| 1369 | |
| 1370 | update(mSnapshotBuilder); |
| 1371 | |
| 1372 | bool foundInputLayer = false; |
| 1373 | mSnapshotBuilder.forEachInputSnapshot([&](const frontend::LayerSnapshot& snapshot) { |
| 1374 | if (snapshot.uniqueSequence == 3) { |
| 1375 | foundInputLayer = true; |
| 1376 | } |
| 1377 | }); |
| 1378 | EXPECT_TRUE(foundInputLayer); |
| 1379 | } |
| 1380 | |
Garfield Tan | 8eb8f35 | 2024-05-17 09:12:01 -0700 | [diff] [blame] | 1381 | TEST_F(LayerSnapshotTest, ForEachSnapshotsWithPredicate) { |
| 1382 | std::vector<uint32_t> visitedUniqueSequences; |
| 1383 | mSnapshotBuilder.forEachSnapshot( |
| 1384 | [&](const std::unique_ptr<frontend::LayerSnapshot>& snapshot) { |
| 1385 | visitedUniqueSequences.push_back(snapshot->uniqueSequence); |
| 1386 | }, |
| 1387 | [](const frontend::LayerSnapshot& snapshot) { return snapshot.uniqueSequence == 111; }); |
| 1388 | EXPECT_EQ(visitedUniqueSequences.size(), 1u); |
| 1389 | EXPECT_EQ(visitedUniqueSequences[0], 111u); |
| 1390 | } |
| 1391 | |
Vishnu Nair | 59a6be3 | 2024-01-29 10:26:21 -0800 | [diff] [blame] | 1392 | TEST_F(LayerSnapshotTest, canOccludePresentation) { |
| 1393 | setFlags(12, layer_state_t::eCanOccludePresentation, layer_state_t::eCanOccludePresentation); |
| 1394 | LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(), |
| 1395 | .layerLifecycleManager = mLifecycleManager, |
| 1396 | .includeMetadata = false, |
| 1397 | .displays = mFrontEndDisplayInfos, |
| 1398 | .displayChanges = false, |
| 1399 | .globalShadowSettings = globalShadowSettings, |
| 1400 | .supportsBlur = true, |
| 1401 | .supportedLayerGenericMetadata = {}, |
| 1402 | .genericLayerMetadataKeyMap = {}}; |
| 1403 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 1404 | |
| 1405 | EXPECT_EQ(getSnapshot(1)->inputInfo.canOccludePresentation, false); |
| 1406 | |
| 1407 | // ensure we can set the property on the window info for layer and all its children |
| 1408 | EXPECT_EQ(getSnapshot(12)->inputInfo.canOccludePresentation, true); |
| 1409 | EXPECT_EQ(getSnapshot(121)->inputInfo.canOccludePresentation, true); |
| 1410 | EXPECT_EQ(getSnapshot(1221)->inputInfo.canOccludePresentation, true); |
| 1411 | } |
| 1412 | |
Vishnu Nair | 491827d | 2024-04-29 23:43:26 +0000 | [diff] [blame] | 1413 | TEST_F(LayerSnapshotTest, mirroredHierarchyIgnoresLocalTransform) { |
| 1414 | SET_FLAG_FOR_TEST(flags::detached_mirror, true); |
| 1415 | reparentLayer(12, UNASSIGNED_LAYER_ID); |
| 1416 | setPosition(11, 2, 20); |
| 1417 | setPosition(111, 20, 200); |
| 1418 | mirrorLayer(/*layer*/ 14, /*parent*/ 1, /*layerToMirror*/ 11); |
| 1419 | std::vector<uint32_t> expected = {1, 11, 111, 13, 14, 11, 111, 2}; |
| 1420 | UPDATE_AND_VERIFY(mSnapshotBuilder, expected); |
| 1421 | |
| 1422 | // mirror root has no position set |
| 1423 | EXPECT_EQ(getSnapshot({.id = 11, .mirrorRootIds = 14u})->localTransform.tx(), 0); |
| 1424 | EXPECT_EQ(getSnapshot({.id = 11, .mirrorRootIds = 14u})->localTransform.ty(), 0); |
| 1425 | // original root still has a position |
| 1426 | EXPECT_EQ(getSnapshot({.id = 11})->localTransform.tx(), 2); |
| 1427 | EXPECT_EQ(getSnapshot({.id = 11})->localTransform.ty(), 20); |
| 1428 | |
| 1429 | // mirror child still has the correct position |
| 1430 | EXPECT_EQ(getSnapshot({.id = 111, .mirrorRootIds = 14u})->localTransform.tx(), 20); |
| 1431 | EXPECT_EQ(getSnapshot({.id = 111, .mirrorRootIds = 14u})->localTransform.ty(), 200); |
| 1432 | EXPECT_EQ(getSnapshot({.id = 111, .mirrorRootIds = 14u})->geomLayerTransform.tx(), 20); |
| 1433 | EXPECT_EQ(getSnapshot({.id = 111, .mirrorRootIds = 14u})->geomLayerTransform.ty(), 200); |
| 1434 | |
| 1435 | // original child still has the correct position including its parent's position |
| 1436 | EXPECT_EQ(getSnapshot({.id = 111})->localTransform.tx(), 20); |
| 1437 | EXPECT_EQ(getSnapshot({.id = 111})->localTransform.ty(), 200); |
| 1438 | EXPECT_EQ(getSnapshot({.id = 111})->geomLayerTransform.tx(), 22); |
| 1439 | EXPECT_EQ(getSnapshot({.id = 111})->geomLayerTransform.ty(), 220); |
| 1440 | } |
| 1441 | |
Vishnu Nair | 9e0017e | 2024-05-22 19:02:44 +0000 | [diff] [blame^] | 1442 | TEST_F(LayerSnapshotTest, overrideParentTrustedOverlayState) { |
| 1443 | SET_FLAG_FOR_TEST(flags::override_trusted_overlay, true); |
| 1444 | hideLayer(1); |
| 1445 | setTrustedOverlay(1, gui::TrustedOverlay::ENABLED); |
| 1446 | |
| 1447 | Region touch{Rect{0, 0, 1000, 1000}}; |
| 1448 | setTouchableRegion(1, touch); |
| 1449 | setTouchableRegion(11, touch); |
| 1450 | setTouchableRegion(111, touch); |
| 1451 | |
| 1452 | UPDATE_AND_VERIFY(mSnapshotBuilder, {2}); |
| 1453 | EXPECT_TRUE(getSnapshot(1)->inputInfo.inputConfig.test( |
| 1454 | gui::WindowInfo::InputConfig::TRUSTED_OVERLAY)); |
| 1455 | EXPECT_TRUE(getSnapshot(11)->inputInfo.inputConfig.test( |
| 1456 | gui::WindowInfo::InputConfig::TRUSTED_OVERLAY)); |
| 1457 | EXPECT_TRUE(getSnapshot(111)->inputInfo.inputConfig.test( |
| 1458 | gui::WindowInfo::InputConfig::TRUSTED_OVERLAY)); |
| 1459 | |
| 1460 | // disable trusted overlay and override parent state |
| 1461 | setTrustedOverlay(11, gui::TrustedOverlay::DISABLED); |
| 1462 | UPDATE_AND_VERIFY(mSnapshotBuilder, {2}); |
| 1463 | EXPECT_TRUE(getSnapshot(1)->inputInfo.inputConfig.test( |
| 1464 | gui::WindowInfo::InputConfig::TRUSTED_OVERLAY)); |
| 1465 | EXPECT_FALSE(getSnapshot(11)->inputInfo.inputConfig.test( |
| 1466 | gui::WindowInfo::InputConfig::TRUSTED_OVERLAY)); |
| 1467 | EXPECT_FALSE(getSnapshot(111)->inputInfo.inputConfig.test( |
| 1468 | gui::WindowInfo::InputConfig::TRUSTED_OVERLAY)); |
| 1469 | |
| 1470 | // unset state and go back to default behavior of inheriting |
| 1471 | // state |
| 1472 | setTrustedOverlay(11, gui::TrustedOverlay::UNSET); |
| 1473 | UPDATE_AND_VERIFY(mSnapshotBuilder, {2}); |
| 1474 | EXPECT_TRUE(getSnapshot(1)->inputInfo.inputConfig.test( |
| 1475 | gui::WindowInfo::InputConfig::TRUSTED_OVERLAY)); |
| 1476 | EXPECT_TRUE(getSnapshot(11)->inputInfo.inputConfig.test( |
| 1477 | gui::WindowInfo::InputConfig::TRUSTED_OVERLAY)); |
| 1478 | EXPECT_TRUE(getSnapshot(111)->inputInfo.inputConfig.test( |
| 1479 | gui::WindowInfo::InputConfig::TRUSTED_OVERLAY)); |
| 1480 | } |
| 1481 | |
| 1482 | TEST_F(LayerSnapshotTest, doNotOverrideParentTrustedOverlayState) { |
| 1483 | SET_FLAG_FOR_TEST(flags::override_trusted_overlay, false); |
| 1484 | hideLayer(1); |
| 1485 | setTrustedOverlay(1, gui::TrustedOverlay::ENABLED); |
| 1486 | |
| 1487 | Region touch{Rect{0, 0, 1000, 1000}}; |
| 1488 | setTouchableRegion(1, touch); |
| 1489 | setTouchableRegion(11, touch); |
| 1490 | setTouchableRegion(111, touch); |
| 1491 | |
| 1492 | UPDATE_AND_VERIFY(mSnapshotBuilder, {2}); |
| 1493 | EXPECT_TRUE(getSnapshot(1)->inputInfo.inputConfig.test( |
| 1494 | gui::WindowInfo::InputConfig::TRUSTED_OVERLAY)); |
| 1495 | EXPECT_TRUE(getSnapshot(11)->inputInfo.inputConfig.test( |
| 1496 | gui::WindowInfo::InputConfig::TRUSTED_OVERLAY)); |
| 1497 | EXPECT_TRUE(getSnapshot(111)->inputInfo.inputConfig.test( |
| 1498 | gui::WindowInfo::InputConfig::TRUSTED_OVERLAY)); |
| 1499 | |
| 1500 | // disable trusted overlay but flag is disabled so this behaves |
| 1501 | // as UNSET |
| 1502 | setTrustedOverlay(11, gui::TrustedOverlay::DISABLED); |
| 1503 | UPDATE_AND_VERIFY(mSnapshotBuilder, {2}); |
| 1504 | EXPECT_TRUE(getSnapshot(1)->inputInfo.inputConfig.test( |
| 1505 | gui::WindowInfo::InputConfig::TRUSTED_OVERLAY)); |
| 1506 | EXPECT_TRUE(getSnapshot(11)->inputInfo.inputConfig.test( |
| 1507 | gui::WindowInfo::InputConfig::TRUSTED_OVERLAY)); |
| 1508 | EXPECT_TRUE(getSnapshot(111)->inputInfo.inputConfig.test( |
| 1509 | gui::WindowInfo::InputConfig::TRUSTED_OVERLAY)); |
| 1510 | |
| 1511 | // unset state and go back to default behavior of inheriting |
| 1512 | // state |
| 1513 | setTrustedOverlay(11, gui::TrustedOverlay::UNSET); |
| 1514 | UPDATE_AND_VERIFY(mSnapshotBuilder, {2}); |
| 1515 | EXPECT_TRUE(getSnapshot(1)->inputInfo.inputConfig.test( |
| 1516 | gui::WindowInfo::InputConfig::TRUSTED_OVERLAY)); |
| 1517 | EXPECT_TRUE(getSnapshot(11)->inputInfo.inputConfig.test( |
| 1518 | gui::WindowInfo::InputConfig::TRUSTED_OVERLAY)); |
| 1519 | EXPECT_TRUE(getSnapshot(111)->inputInfo.inputConfig.test( |
| 1520 | gui::WindowInfo::InputConfig::TRUSTED_OVERLAY)); |
| 1521 | } |
| 1522 | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 1523 | } // namespace android::surfaceflinger::frontend |