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