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