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