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