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