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