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