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 | |
| 53 | class LayerSnapshotTest : public LayerHierarchyTestBase { |
| 54 | protected: |
| 55 | LayerSnapshotTest() : LayerHierarchyTestBase() { |
| 56 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 57 | } |
| 58 | |
| 59 | void createRootLayer(uint32_t id) override { |
| 60 | LayerHierarchyTestBase::createRootLayer(id); |
| 61 | setColor(id); |
| 62 | } |
| 63 | |
| 64 | void createLayer(uint32_t id, uint32_t parentId) override { |
| 65 | LayerHierarchyTestBase::createLayer(id, parentId); |
| 66 | setColor(parentId); |
| 67 | } |
| 68 | |
| 69 | void mirrorLayer(uint32_t id, uint32_t parent, uint32_t layerToMirror) override { |
| 70 | LayerHierarchyTestBase::mirrorLayer(id, parent, layerToMirror); |
| 71 | setColor(id); |
| 72 | } |
| 73 | |
Vishnu Nair | 0808ae6 | 2023-08-07 21:42:42 -0700 | [diff] [blame] | 74 | void update(LayerSnapshotBuilder& actualBuilder, LayerSnapshotBuilder::Args& args) { |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 75 | if (mLifecycleManager.getGlobalChanges().test(RequestedLayerState::Changes::Hierarchy)) { |
| 76 | mHierarchyBuilder.update(mLifecycleManager.getLayers(), |
| 77 | mLifecycleManager.getDestroyedLayers()); |
| 78 | } |
Vishnu Nair | 0808ae6 | 2023-08-07 21:42:42 -0700 | [diff] [blame] | 79 | args.root = mHierarchyBuilder.getHierarchy(); |
| 80 | actualBuilder.update(args); |
| 81 | } |
| 82 | |
| 83 | void updateAndVerify(LayerSnapshotBuilder& actualBuilder, bool hasDisplayChanges, |
| 84 | const std::vector<uint32_t> expectedVisibleLayerIdsInZOrder) { |
Vishnu Nair | c765c6c | 2023-02-23 00:08:01 +0000 | [diff] [blame] | 85 | LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(), |
| 86 | .layerLifecycleManager = mLifecycleManager, |
| 87 | .includeMetadata = false, |
| 88 | .displays = mFrontEndDisplayInfos, |
| 89 | .displayChanges = hasDisplayChanges, |
| 90 | .globalShadowSettings = globalShadowSettings, |
Vishnu Nair | 444f395 | 2023-04-11 13:01:02 -0700 | [diff] [blame] | 91 | .supportsBlur = true, |
Vishnu Nair | c765c6c | 2023-02-23 00:08:01 +0000 | [diff] [blame] | 92 | .supportedLayerGenericMetadata = {}, |
| 93 | .genericLayerMetadataKeyMap = {}}; |
Vishnu Nair | 0808ae6 | 2023-08-07 21:42:42 -0700 | [diff] [blame] | 94 | update(actualBuilder, args); |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 95 | |
| 96 | // rebuild layer snapshots from scratch and verify that it matches the updated state. |
| 97 | LayerSnapshotBuilder expectedBuilder(args); |
| 98 | mLifecycleManager.commitChanges(); |
| 99 | ASSERT_TRUE(expectedBuilder.getSnapshots().size() > 0); |
| 100 | ASSERT_TRUE(actualBuilder.getSnapshots().size() > 0); |
| 101 | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 102 | std::vector<uint32_t> actualVisibleLayerIdsInZOrder; |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 103 | actualBuilder.forEachVisibleSnapshot( |
| 104 | [&actualVisibleLayerIdsInZOrder](const LayerSnapshot& snapshot) { |
| 105 | actualVisibleLayerIdsInZOrder.push_back(snapshot.path.id); |
| 106 | }); |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 107 | EXPECT_EQ(expectedVisibleLayerIdsInZOrder, actualVisibleLayerIdsInZOrder); |
| 108 | } |
| 109 | |
| 110 | LayerSnapshot* getSnapshot(uint32_t layerId) { return mSnapshotBuilder.getSnapshot(layerId); } |
Vishnu Nair | 92990e2 | 2023-02-24 20:01:05 +0000 | [diff] [blame] | 111 | LayerSnapshot* getSnapshot(const LayerHierarchy::TraversalPath path) { |
| 112 | return mSnapshotBuilder.getSnapshot(path); |
| 113 | } |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 114 | |
| 115 | LayerHierarchyBuilder mHierarchyBuilder{{}}; |
| 116 | LayerSnapshotBuilder mSnapshotBuilder; |
Dominik Laskowski | 6b049ff | 2023-01-29 15:46:45 -0500 | [diff] [blame] | 117 | DisplayInfos mFrontEndDisplayInfos; |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 118 | renderengine::ShadowSettings globalShadowSettings; |
| 119 | static const std::vector<uint32_t> STARTING_ZORDER; |
| 120 | }; |
| 121 | const std::vector<uint32_t> LayerSnapshotTest::STARTING_ZORDER = {1, 11, 111, 12, 121, |
| 122 | 122, 1221, 13, 2}; |
| 123 | |
| 124 | TEST_F(LayerSnapshotTest, buildSnapshot) { |
Vishnu Nair | c765c6c | 2023-02-23 00:08:01 +0000 | [diff] [blame] | 125 | LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(), |
| 126 | .layerLifecycleManager = mLifecycleManager, |
| 127 | .includeMetadata = false, |
| 128 | .displays = mFrontEndDisplayInfos, |
| 129 | .globalShadowSettings = globalShadowSettings, |
| 130 | .supportedLayerGenericMetadata = {}, |
| 131 | .genericLayerMetadataKeyMap = {}}; |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 132 | LayerSnapshotBuilder builder(args); |
| 133 | } |
| 134 | |
| 135 | TEST_F(LayerSnapshotTest, updateSnapshot) { |
Vishnu Nair | c765c6c | 2023-02-23 00:08:01 +0000 | [diff] [blame] | 136 | LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(), |
| 137 | .layerLifecycleManager = mLifecycleManager, |
| 138 | .includeMetadata = false, |
| 139 | .displays = mFrontEndDisplayInfos, |
| 140 | .globalShadowSettings = globalShadowSettings, |
| 141 | .supportedLayerGenericMetadata = {}, |
| 142 | .genericLayerMetadataKeyMap = {} |
| 143 | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 144 | }; |
| 145 | |
| 146 | LayerSnapshotBuilder builder; |
| 147 | builder.update(args); |
| 148 | } |
| 149 | |
| 150 | // update using parent snapshot data |
| 151 | TEST_F(LayerSnapshotTest, croppedByParent) { |
| 152 | /// MAKE ALL LAYERS VISIBLE BY DEFAULT |
| 153 | DisplayInfo info; |
| 154 | info.info.logicalHeight = 100; |
| 155 | info.info.logicalWidth = 200; |
| 156 | mFrontEndDisplayInfos.emplace_or_replace(ui::LayerStack::fromValue(1), info); |
| 157 | Rect layerCrop(0, 0, 10, 20); |
| 158 | setCrop(11, layerCrop); |
| 159 | EXPECT_TRUE(mLifecycleManager.getGlobalChanges().test(RequestedLayerState::Changes::Geometry)); |
| 160 | UPDATE_AND_VERIFY_WITH_DISPLAY_CHANGES(mSnapshotBuilder, STARTING_ZORDER); |
| 161 | EXPECT_EQ(getSnapshot(11)->geomCrop, layerCrop); |
| 162 | EXPECT_EQ(getSnapshot(111)->geomLayerBounds, layerCrop.toFloatRect()); |
| 163 | float maxHeight = static_cast<float>(info.info.logicalHeight * 10); |
| 164 | float maxWidth = static_cast<float>(info.info.logicalWidth * 10); |
| 165 | |
| 166 | FloatRect maxDisplaySize(-maxWidth, -maxHeight, maxWidth, maxHeight); |
| 167 | EXPECT_EQ(getSnapshot(1)->geomLayerBounds, maxDisplaySize); |
| 168 | } |
| 169 | |
| 170 | // visibility tests |
| 171 | TEST_F(LayerSnapshotTest, newLayerHiddenByPolicy) { |
| 172 | createLayer(112, 11); |
| 173 | hideLayer(112); |
| 174 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 175 | |
| 176 | showLayer(112); |
| 177 | UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 11, 111, 112, 12, 121, 122, 1221, 13, 2}); |
| 178 | } |
| 179 | |
| 180 | TEST_F(LayerSnapshotTest, hiddenByParent) { |
| 181 | hideLayer(11); |
| 182 | UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 13, 2}); |
| 183 | } |
| 184 | |
| 185 | TEST_F(LayerSnapshotTest, reparentShowsChild) { |
| 186 | hideLayer(11); |
| 187 | UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 13, 2}); |
| 188 | |
| 189 | showLayer(11); |
| 190 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 191 | } |
| 192 | |
| 193 | TEST_F(LayerSnapshotTest, reparentHidesChild) { |
| 194 | hideLayer(11); |
| 195 | UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 13, 2}); |
| 196 | |
| 197 | reparentLayer(121, 11); |
| 198 | UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 122, 1221, 13, 2}); |
| 199 | } |
| 200 | |
| 201 | TEST_F(LayerSnapshotTest, unHidingUpdatesSnapshot) { |
| 202 | hideLayer(11); |
| 203 | Rect crop(1, 2, 3, 4); |
| 204 | setCrop(111, crop); |
| 205 | UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 13, 2}); |
| 206 | |
| 207 | showLayer(11); |
| 208 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 209 | EXPECT_EQ(getSnapshot(111)->geomLayerBounds, crop.toFloatRect()); |
| 210 | } |
| 211 | |
| 212 | TEST_F(LayerSnapshotTest, childBehindParentCanBeHiddenByParent) { |
| 213 | setZ(111, -1); |
| 214 | UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 111, 11, 12, 121, 122, 1221, 13, 2}); |
| 215 | |
| 216 | hideLayer(11); |
| 217 | UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 13, 2}); |
| 218 | } |
| 219 | |
| 220 | // relative tests |
| 221 | TEST_F(LayerSnapshotTest, RelativeParentCanHideChild) { |
| 222 | reparentRelativeLayer(13, 11); |
| 223 | UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 11, 13, 111, 12, 121, 122, 1221, 2}); |
| 224 | |
| 225 | hideLayer(11); |
| 226 | UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 2}); |
| 227 | } |
| 228 | |
| 229 | TEST_F(LayerSnapshotTest, ReparentingToHiddenRelativeParentHidesChild) { |
| 230 | hideLayer(11); |
| 231 | UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 13, 2}); |
| 232 | reparentRelativeLayer(13, 11); |
| 233 | UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 12, 121, 122, 1221, 2}); |
| 234 | } |
| 235 | |
| 236 | TEST_F(LayerSnapshotTest, AlphaInheritedByChildren) { |
| 237 | setAlpha(1, 0.5); |
| 238 | setAlpha(122, 0.5); |
| 239 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 240 | EXPECT_EQ(getSnapshot(1)->alpha, 0.5f); |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 241 | EXPECT_EQ(getSnapshot(12)->alpha, 0.5f); |
| 242 | EXPECT_EQ(getSnapshot(1221)->alpha, 0.25f); |
| 243 | } |
| 244 | |
| 245 | // Change states |
| 246 | TEST_F(LayerSnapshotTest, UpdateClearsPreviousChangeStates) { |
| 247 | setCrop(1, Rect(1, 2, 3, 4)); |
| 248 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 249 | EXPECT_TRUE(getSnapshot(1)->changes.test(RequestedLayerState::Changes::Geometry)); |
| 250 | EXPECT_TRUE(getSnapshot(11)->changes.test(RequestedLayerState::Changes::Geometry)); |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 251 | setCrop(2, Rect(1, 2, 3, 4)); |
| 252 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 253 | EXPECT_TRUE(getSnapshot(2)->changes.test(RequestedLayerState::Changes::Geometry)); |
| 254 | EXPECT_FALSE(getSnapshot(1)->changes.test(RequestedLayerState::Changes::Geometry)); |
| 255 | EXPECT_FALSE(getSnapshot(11)->changes.test(RequestedLayerState::Changes::Geometry)); |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | TEST_F(LayerSnapshotTest, FastPathClearsPreviousChangeStates) { |
| 259 | setColor(11, {1._hf, 0._hf, 0._hf}); |
| 260 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 261 | EXPECT_EQ(getSnapshot(11)->changes, RequestedLayerState::Changes::Content); |
| 262 | EXPECT_EQ(getSnapshot(11)->clientChanges, layer_state_t::eColorChanged); |
| 263 | EXPECT_EQ(getSnapshot(1)->changes.get(), 0u); |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 264 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 265 | EXPECT_EQ(getSnapshot(11)->changes.get(), 0u); |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | TEST_F(LayerSnapshotTest, FastPathSetsChangeFlagToContent) { |
| 269 | setColor(1, {1._hf, 0._hf, 0._hf}); |
| 270 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 271 | EXPECT_EQ(getSnapshot(1)->changes, RequestedLayerState::Changes::Content); |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 272 | EXPECT_EQ(getSnapshot(1)->clientChanges, layer_state_t::eColorChanged); |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 273 | } |
| 274 | |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 275 | TEST_F(LayerSnapshotTest, GameMode) { |
| 276 | std::vector<TransactionState> transactions; |
| 277 | transactions.emplace_back(); |
| 278 | transactions.back().states.push_back({}); |
| 279 | transactions.back().states.front().state.what = layer_state_t::eMetadataChanged; |
| 280 | transactions.back().states.front().state.metadata = LayerMetadata(); |
| 281 | transactions.back().states.front().state.metadata.setInt32(METADATA_GAME_MODE, 42); |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 282 | transactions.back().states.front().layerId = 1; |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 283 | transactions.back().states.front().state.layerId = static_cast<int32_t>(1); |
| 284 | mLifecycleManager.applyTransactions(transactions); |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 285 | EXPECT_EQ(mLifecycleManager.getGlobalChanges(), RequestedLayerState::Changes::GameMode); |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 286 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 287 | EXPECT_EQ(getSnapshot(1)->clientChanges, layer_state_t::eMetadataChanged); |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 288 | EXPECT_EQ(static_cast<int32_t>(getSnapshot(1)->gameMode), 42); |
| 289 | EXPECT_EQ(static_cast<int32_t>(getSnapshot(11)->gameMode), 42); |
| 290 | } |
| 291 | |
| 292 | TEST_F(LayerSnapshotTest, NoLayerVoteForParentWithChildVotes) { |
| 293 | // ROOT |
| 294 | // ├── 1 |
| 295 | // │ ├── 11 (frame rate set) |
| 296 | // │ │ └── 111 |
| 297 | // │ ├── 12 |
| 298 | // │ │ ├── 121 |
| 299 | // │ │ └── 122 |
| 300 | // │ │ └── 1221 |
| 301 | // │ └── 13 |
| 302 | // └── 2 |
| 303 | |
| 304 | std::vector<TransactionState> transactions; |
| 305 | transactions.emplace_back(); |
| 306 | transactions.back().states.push_back({}); |
| 307 | transactions.back().states.front().state.what = layer_state_t::eFrameRateChanged; |
| 308 | transactions.back().states.front().state.frameRate = 90.0; |
| 309 | transactions.back().states.front().state.frameRateCompatibility = |
| 310 | ANATIVEWINDOW_FRAME_RATE_EXACT; |
| 311 | transactions.back().states.front().state.changeFrameRateStrategy = |
| 312 | ANATIVEWINDOW_CHANGE_FRAME_RATE_ALWAYS; |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 313 | transactions.back().states.front().layerId = 11; |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 314 | mLifecycleManager.applyTransactions(transactions); |
| 315 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 316 | |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 317 | EXPECT_EQ(getSnapshot(11)->frameRate.vote.rate.getIntValue(), 90); |
Vishnu Nair | 3fbe326 | 2023-09-29 17:07:00 -0700 | [diff] [blame] | 318 | EXPECT_EQ(getSnapshot(11)->frameRate.vote.type, scheduler::FrameRateCompatibility::Exact); |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 319 | EXPECT_EQ(getSnapshot(111)->frameRate.vote.rate.getIntValue(), 90); |
Vishnu Nair | 3fbe326 | 2023-09-29 17:07:00 -0700 | [diff] [blame] | 320 | EXPECT_EQ(getSnapshot(111)->frameRate.vote.type, scheduler::FrameRateCompatibility::Exact); |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 321 | EXPECT_EQ(getSnapshot(1)->frameRate.vote.rate.getIntValue(), 0); |
Vishnu Nair | 3fbe326 | 2023-09-29 17:07:00 -0700 | [diff] [blame] | 322 | EXPECT_EQ(getSnapshot(1)->frameRate.vote.type, scheduler::FrameRateCompatibility::NoVote); |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 323 | } |
| 324 | |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 325 | TEST_F(LayerSnapshotTest, CanCropTouchableRegion) { |
Vishnu Nair | 29354ec | 2023-03-28 18:51:28 -0700 | [diff] [blame] | 326 | // ROOT |
| 327 | // ├── 1 |
| 328 | // │ ├── 11 |
| 329 | // │ │ └── 111 (touchregion set to touch but cropped by layer 13) |
| 330 | // │ ├── 12 |
| 331 | // │ │ ├── 121 |
| 332 | // │ │ └── 122 |
| 333 | // │ │ └── 1221 |
| 334 | // │ └── 13 (crop set to touchCrop) |
| 335 | // └── 2 |
| 336 | |
| 337 | Rect touchCrop{300, 300, 400, 500}; |
| 338 | setCrop(13, touchCrop); |
| 339 | Region touch{Rect{0, 0, 1000, 1000}}; |
| 340 | setTouchableRegionCrop(111, touch, /*touchCropId=*/13, /*replaceTouchableRegionWithCrop=*/true); |
| 341 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 342 | EXPECT_EQ(getSnapshot({.id = 111})->inputInfo.touchableRegion.bounds(), touchCrop); |
| 343 | |
| 344 | Rect modifiedTouchCrop{100, 300, 400, 700}; |
| 345 | setCrop(13, modifiedTouchCrop); |
| 346 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 347 | EXPECT_EQ(getSnapshot({.id = 111})->inputInfo.touchableRegion.bounds(), modifiedTouchCrop); |
| 348 | } |
| 349 | |
Vishnu Nair | 444f395 | 2023-04-11 13:01:02 -0700 | [diff] [blame] | 350 | TEST_F(LayerSnapshotTest, blurUpdatesWhenAlphaChanges) { |
Vishnu Nair | 854ce1c | 2023-08-19 15:00:13 -0700 | [diff] [blame] | 351 | int blurRadius = 42; |
| 352 | setBackgroundBlurRadius(1221, static_cast<uint32_t>(blurRadius)); |
Vishnu Nair | 444f395 | 2023-04-11 13:01:02 -0700 | [diff] [blame] | 353 | |
| 354 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 355 | EXPECT_EQ(getSnapshot({.id = 1221})->backgroundBlurRadius, blurRadius); |
| 356 | |
Vishnu Nair | 854ce1c | 2023-08-19 15:00:13 -0700 | [diff] [blame] | 357 | blurRadius = 21; |
| 358 | setBackgroundBlurRadius(1221, static_cast<uint32_t>(blurRadius)); |
| 359 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 360 | EXPECT_EQ(getSnapshot({.id = 1221})->backgroundBlurRadius, blurRadius); |
| 361 | |
Vishnu Nair | 444f395 | 2023-04-11 13:01:02 -0700 | [diff] [blame] | 362 | static constexpr float alpha = 0.5; |
| 363 | setAlpha(12, alpha); |
| 364 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
Vishnu Nair | 854ce1c | 2023-08-19 15:00:13 -0700 | [diff] [blame] | 365 | EXPECT_EQ(getSnapshot({.id = 1221})->backgroundBlurRadius, |
| 366 | static_cast<int>(static_cast<float>(blurRadius) * alpha)); |
Vishnu Nair | 444f395 | 2023-04-11 13:01:02 -0700 | [diff] [blame] | 367 | } |
| 368 | |
Vishnu Nair | a9c4376 | 2023-01-27 19:10:25 +0000 | [diff] [blame] | 369 | // Display Mirroring Tests |
| 370 | // tree with 3 levels of children |
| 371 | // ROOT (DISPLAY 0) |
| 372 | // ├── 1 |
| 373 | // │ ├── 11 |
| 374 | // │ │ └── 111 |
| 375 | // │ ├── 12 (has skip screenshot flag) |
| 376 | // │ │ ├── 121 |
| 377 | // │ │ └── 122 |
| 378 | // │ │ └── 1221 |
| 379 | // │ └── 13 |
| 380 | // └── 2 |
| 381 | // ROOT (DISPLAY 1) |
| 382 | // └── 3 (mirrors display 0) |
Vishnu Nair | 92990e2 | 2023-02-24 20:01:05 +0000 | [diff] [blame] | 383 | TEST_F(LayerSnapshotTest, displayMirrorRespectsLayerSkipScreenshotFlag) { |
Vishnu Nair | a9c4376 | 2023-01-27 19:10:25 +0000 | [diff] [blame] | 384 | setFlags(12, layer_state_t::eLayerSkipScreenshot, layer_state_t::eLayerSkipScreenshot); |
| 385 | createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0)); |
| 386 | setLayerStack(3, 1); |
| 387 | |
Vishnu Nair | 444f395 | 2023-04-11 13:01:02 -0700 | [diff] [blame] | 388 | 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] | 389 | UPDATE_AND_VERIFY(mSnapshotBuilder, expected); |
| 390 | } |
| 391 | |
Vishnu Nair | 92990e2 | 2023-02-24 20:01:05 +0000 | [diff] [blame] | 392 | // ROOT (DISPLAY 0) |
| 393 | // ├── 1 |
| 394 | // │ ├── 11 |
| 395 | // │ │ └── 111 |
| 396 | // │ └── 13 |
| 397 | // └── 2 |
| 398 | // ROOT (DISPLAY 3) |
| 399 | // └── 3 (mirrors display 0) |
| 400 | TEST_F(LayerSnapshotTest, mirrorLayerGetsCorrectLayerStack) { |
| 401 | reparentLayer(12, UNASSIGNED_LAYER_ID); |
| 402 | createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0)); |
| 403 | setLayerStack(3, 3); |
| 404 | createDisplayMirrorLayer(4, ui::LayerStack::fromValue(0)); |
| 405 | setLayerStack(4, 4); |
| 406 | |
Vishnu Nair | 444f395 | 2023-04-11 13:01:02 -0700 | [diff] [blame] | 407 | std::vector<uint32_t> expected = {1, 11, 111, 13, 2, 3, 1, 11, 111, |
| 408 | 13, 2, 4, 1, 11, 111, 13, 2}; |
Vishnu Nair | 92990e2 | 2023-02-24 20:01:05 +0000 | [diff] [blame] | 409 | UPDATE_AND_VERIFY(mSnapshotBuilder, expected); |
Vishnu Nair | 6f87831 | 2023-09-08 11:05:01 -0700 | [diff] [blame] | 410 | EXPECT_EQ(getSnapshot({.id = 111, .mirrorRootIds = 3u})->outputFilter.layerStack.id, 3u); |
| 411 | EXPECT_EQ(getSnapshot({.id = 111, .mirrorRootIds = 4u})->outputFilter.layerStack.id, 4u); |
Vishnu Nair | 92990e2 | 2023-02-24 20:01:05 +0000 | [diff] [blame] | 412 | } |
| 413 | |
| 414 | // ROOT (DISPLAY 0) |
| 415 | // ├── 1 (crop 50x50) |
| 416 | // │ ├── 11 |
| 417 | // │ │ └── 111 |
| 418 | // │ └── 13 |
| 419 | // └── 2 |
| 420 | // ROOT (DISPLAY 3) |
| 421 | // └── 3 (mirrors display 0) (crop 100x100) |
| 422 | TEST_F(LayerSnapshotTest, mirrorLayerTouchIsCroppedByMirrorRoot) { |
| 423 | reparentLayer(12, UNASSIGNED_LAYER_ID); |
| 424 | createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0)); |
| 425 | setLayerStack(3, 3); |
| 426 | setCrop(1, Rect{50, 50}); |
| 427 | setCrop(3, Rect{100, 100}); |
| 428 | setCrop(111, Rect{200, 200}); |
| 429 | Region touch{Rect{0, 0, 1000, 1000}}; |
| 430 | setTouchableRegion(111, touch); |
Vishnu Nair | 444f395 | 2023-04-11 13:01:02 -0700 | [diff] [blame] | 431 | 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] | 432 | UPDATE_AND_VERIFY(mSnapshotBuilder, expected); |
| 433 | EXPECT_TRUE(getSnapshot({.id = 111})->inputInfo.touchableRegion.hasSameRects(touch)); |
| 434 | Region touchCroppedByMirrorRoot{Rect{0, 0, 50, 50}}; |
Vishnu Nair | 6f87831 | 2023-09-08 11:05:01 -0700 | [diff] [blame] | 435 | EXPECT_TRUE(getSnapshot({.id = 111, .mirrorRootIds = 3u}) |
Vishnu Nair | 92990e2 | 2023-02-24 20:01:05 +0000 | [diff] [blame] | 436 | ->inputInfo.touchableRegion.hasSameRects(touchCroppedByMirrorRoot)); |
| 437 | } |
| 438 | |
| 439 | TEST_F(LayerSnapshotTest, canRemoveDisplayMirror) { |
| 440 | setFlags(12, layer_state_t::eLayerSkipScreenshot, layer_state_t::eLayerSkipScreenshot); |
| 441 | createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0)); |
| 442 | setLayerStack(3, 1); |
Vishnu Nair | 444f395 | 2023-04-11 13:01:02 -0700 | [diff] [blame] | 443 | 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] | 444 | UPDATE_AND_VERIFY(mSnapshotBuilder, expected); |
| 445 | destroyLayerHandle(3); |
| 446 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 447 | } |
| 448 | |
Vishnu Nair | fccd636 | 2023-02-24 23:39:53 +0000 | [diff] [blame] | 449 | TEST_F(LayerSnapshotTest, cleanUpUnreachableSnapshotsAfterMirroring) { |
| 450 | size_t startingNumSnapshots = mSnapshotBuilder.getSnapshots().size(); |
| 451 | createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0)); |
| 452 | setLayerStack(3, 1); |
Vishnu Nair | 444f395 | 2023-04-11 13:01:02 -0700 | [diff] [blame] | 453 | std::vector<uint32_t> expected = {1, 11, 111, 12, 121, 122, 1221, 13, 2, 3, |
| 454 | 1, 11, 111, 12, 121, 122, 1221, 13, 2}; |
Vishnu Nair | fccd636 | 2023-02-24 23:39:53 +0000 | [diff] [blame] | 455 | UPDATE_AND_VERIFY(mSnapshotBuilder, expected); |
| 456 | destroyLayerHandle(3); |
| 457 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 458 | |
| 459 | EXPECT_EQ(startingNumSnapshots, mSnapshotBuilder.getSnapshots().size()); |
| 460 | } |
| 461 | |
Vishnu Nair | 6f87831 | 2023-09-08 11:05:01 -0700 | [diff] [blame] | 462 | TEST_F(LayerSnapshotTest, canMirrorDisplayWithMirrors) { |
| 463 | reparentLayer(12, UNASSIGNED_LAYER_ID); |
| 464 | mirrorLayer(/*layer*/ 14, /*parent*/ 1, /*layerToMirror*/ 11); |
| 465 | std::vector<uint32_t> expected = {1, 11, 111, 13, 14, 11, 111, 2}; |
| 466 | UPDATE_AND_VERIFY(mSnapshotBuilder, expected); |
| 467 | |
| 468 | createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0)); |
| 469 | setLayerStack(3, 3); |
| 470 | expected = {1, 11, 111, 13, 14, 11, 111, 2, 3, 1, 11, 111, 13, 14, 11, 111, 2}; |
| 471 | UPDATE_AND_VERIFY(mSnapshotBuilder, expected); |
| 472 | EXPECT_EQ(getSnapshot({.id = 11, .mirrorRootIds = 14u})->outputFilter.layerStack.id, 0u); |
| 473 | EXPECT_EQ(getSnapshot({.id = 11, .mirrorRootIds = 3u})->outputFilter.layerStack.id, 3u); |
| 474 | EXPECT_EQ(getSnapshot({.id = 11, .mirrorRootIds = 3u, 14u})->outputFilter.layerStack.id, 3u); |
| 475 | } |
| 476 | |
Vishnu Nair | fccd636 | 2023-02-24 23:39:53 +0000 | [diff] [blame] | 477 | // Rel z doesn't create duplicate snapshots but this is for completeness |
| 478 | TEST_F(LayerSnapshotTest, cleanUpUnreachableSnapshotsAfterRelZ) { |
| 479 | size_t startingNumSnapshots = mSnapshotBuilder.getSnapshots().size(); |
| 480 | reparentRelativeLayer(13, 11); |
| 481 | UPDATE_AND_VERIFY(mSnapshotBuilder, {1, 11, 13, 111, 12, 121, 122, 1221, 2}); |
| 482 | setZ(13, 0); |
| 483 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 484 | |
| 485 | EXPECT_EQ(startingNumSnapshots, mSnapshotBuilder.getSnapshots().size()); |
| 486 | } |
| 487 | |
| 488 | TEST_F(LayerSnapshotTest, cleanUpUnreachableSnapshotsAfterLayerDestruction) { |
| 489 | size_t startingNumSnapshots = mSnapshotBuilder.getSnapshots().size(); |
| 490 | destroyLayerHandle(2); |
| 491 | destroyLayerHandle(122); |
| 492 | |
| 493 | std::vector<uint32_t> expected = {1, 11, 111, 12, 121, 122, 1221, 13}; |
| 494 | UPDATE_AND_VERIFY(mSnapshotBuilder, expected); |
| 495 | |
| 496 | EXPECT_LE(startingNumSnapshots - 2, mSnapshotBuilder.getSnapshots().size()); |
| 497 | } |
| 498 | |
Vishnu Nair | 3d8565a | 2023-06-30 07:23:24 +0000 | [diff] [blame] | 499 | TEST_F(LayerSnapshotTest, snashotContainsMetadataFromLayerCreationArgs) { |
| 500 | LayerCreationArgs args(std::make_optional<uint32_t>(200)); |
| 501 | args.name = "testlayer"; |
| 502 | args.addToRoot = true; |
| 503 | args.metadata.setInt32(42, 24); |
| 504 | |
| 505 | std::vector<std::unique_ptr<RequestedLayerState>> layers; |
| 506 | layers.emplace_back(std::make_unique<RequestedLayerState>(args)); |
| 507 | EXPECT_TRUE(layers.back()->metadata.has(42)); |
| 508 | EXPECT_EQ(layers.back()->metadata.getInt32(42, 0), 24); |
| 509 | mLifecycleManager.addLayers(std::move(layers)); |
| 510 | |
| 511 | std::vector<uint32_t> expected = STARTING_ZORDER; |
| 512 | expected.push_back(200); |
| 513 | UPDATE_AND_VERIFY(mSnapshotBuilder, expected); |
| 514 | |
| 515 | EXPECT_TRUE(mSnapshotBuilder.getSnapshot(200)->layerMetadata.has(42)); |
| 516 | EXPECT_EQ(mSnapshotBuilder.getSnapshot(200)->layerMetadata.getInt32(42, 0), 24); |
| 517 | } |
| 518 | |
| 519 | TEST_F(LayerSnapshotTest, frameRateSelectionPriorityPassedToChildLayers) { |
| 520 | setFrameRateSelectionPriority(11, 1); |
| 521 | |
| 522 | setFrameRateSelectionPriority(12, 2); |
| 523 | |
| 524 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 525 | EXPECT_EQ(getSnapshot({.id = 1})->frameRateSelectionPriority, Layer::PRIORITY_UNSET); |
| 526 | EXPECT_EQ(getSnapshot({.id = 11})->frameRateSelectionPriority, 1); |
| 527 | EXPECT_EQ(getSnapshot({.id = 12})->frameRateSelectionPriority, 2); |
| 528 | EXPECT_EQ(getSnapshot({.id = 122})->frameRateSelectionPriority, 2); |
| 529 | EXPECT_EQ(getSnapshot({.id = 1221})->frameRateSelectionPriority, 2); |
| 530 | |
| 531 | // reparent and verify the child gets the new parent's framerate selection priority |
| 532 | reparentLayer(122, 11); |
| 533 | |
| 534 | std::vector<uint32_t> expected = {1, 11, 111, 122, 1221, 12, 121, 13, 2}; |
| 535 | UPDATE_AND_VERIFY(mSnapshotBuilder, expected); |
| 536 | EXPECT_EQ(getSnapshot({.id = 1})->frameRateSelectionPriority, Layer::PRIORITY_UNSET); |
| 537 | EXPECT_EQ(getSnapshot({.id = 11})->frameRateSelectionPriority, 1); |
| 538 | EXPECT_EQ(getSnapshot({.id = 12})->frameRateSelectionPriority, 2); |
| 539 | EXPECT_EQ(getSnapshot({.id = 122})->frameRateSelectionPriority, 1); |
| 540 | EXPECT_EQ(getSnapshot({.id = 1221})->frameRateSelectionPriority, 1); |
| 541 | } |
| 542 | |
Vishnu Nair | 52d56fd | 2023-07-20 17:02:43 +0000 | [diff] [blame] | 543 | TEST_F(LayerSnapshotTest, framerate) { |
| 544 | setFrameRate(11, 244.f, 0, 0); |
| 545 | |
| 546 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 547 | // verify parent is gets no vote |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 548 | EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid()); |
| 549 | EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type, |
Vishnu Nair | 3fbe326 | 2023-09-29 17:07:00 -0700 | [diff] [blame] | 550 | scheduler::FrameRateCompatibility::NoVote); |
Vishnu Nair | 52d56fd | 2023-07-20 17:02:43 +0000 | [diff] [blame] | 551 | EXPECT_TRUE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate)); |
| 552 | |
| 553 | // verify layer and children get the requested votes |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 554 | EXPECT_TRUE(getSnapshot({.id = 11})->frameRate.vote.rate.isValid()); |
| 555 | EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 244.f); |
| 556 | EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.type, |
Vishnu Nair | 3fbe326 | 2023-09-29 17:07:00 -0700 | [diff] [blame] | 557 | scheduler::FrameRateCompatibility::Default); |
Vishnu Nair | 52d56fd | 2023-07-20 17:02:43 +0000 | [diff] [blame] | 558 | EXPECT_TRUE(getSnapshot({.id = 11})->changes.test(RequestedLayerState::Changes::FrameRate)); |
| 559 | |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 560 | EXPECT_TRUE(getSnapshot({.id = 111})->frameRate.vote.rate.isValid()); |
| 561 | EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.rate.getValue(), 244.f); |
| 562 | EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.type, |
Vishnu Nair | 3fbe326 | 2023-09-29 17:07:00 -0700 | [diff] [blame] | 563 | scheduler::FrameRateCompatibility::Default); |
Vishnu Nair | 52d56fd | 2023-07-20 17:02:43 +0000 | [diff] [blame] | 564 | EXPECT_TRUE(getSnapshot({.id = 111})->changes.test(RequestedLayerState::Changes::FrameRate)); |
| 565 | |
| 566 | // reparent and verify the child gets the new parent's framerate |
| 567 | reparentLayer(122, 11); |
| 568 | |
| 569 | std::vector<uint32_t> expected = {1, 11, 111, 122, 1221, 12, 121, 13, 2}; |
| 570 | UPDATE_AND_VERIFY(mSnapshotBuilder, expected); |
| 571 | // verify parent is gets no vote |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 572 | EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid()); |
| 573 | EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type, |
Vishnu Nair | 3fbe326 | 2023-09-29 17:07:00 -0700 | [diff] [blame] | 574 | scheduler::FrameRateCompatibility::NoVote); |
Vishnu Nair | 52d56fd | 2023-07-20 17:02:43 +0000 | [diff] [blame] | 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 | |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 582 | EXPECT_TRUE(getSnapshot({.id = 111})->frameRate.vote.rate.isValid()); |
| 583 | EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.rate.getValue(), 244.f); |
| 584 | EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.type, |
Vishnu Nair | 3fbe326 | 2023-09-29 17:07:00 -0700 | [diff] [blame] | 585 | scheduler::FrameRateCompatibility::Default); |
Vishnu Nair | 52d56fd | 2023-07-20 17:02:43 +0000 | [diff] [blame] | 586 | |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 587 | EXPECT_TRUE(getSnapshot({.id = 122})->frameRate.vote.rate.isValid()); |
| 588 | EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.rate.getValue(), 244.f); |
| 589 | EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.type, |
Vishnu Nair | 3fbe326 | 2023-09-29 17:07:00 -0700 | [diff] [blame] | 590 | scheduler::FrameRateCompatibility::Default); |
Vishnu Nair | 52d56fd | 2023-07-20 17:02:43 +0000 | [diff] [blame] | 591 | EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate)); |
| 592 | |
| 593 | // reparent and verify the new parent gets no vote |
| 594 | reparentLayer(11, 2); |
| 595 | expected = {1, 12, 121, 13, 2, 11, 111, 122, 1221}; |
| 596 | UPDATE_AND_VERIFY(mSnapshotBuilder, expected); |
| 597 | |
| 598 | // verify old parent has invalid framerate (default) |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 599 | EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid()); |
| 600 | EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type, |
Vishnu Nair | 3fbe326 | 2023-09-29 17:07:00 -0700 | [diff] [blame] | 601 | scheduler::FrameRateCompatibility::Default); |
Vishnu Nair | 52d56fd | 2023-07-20 17:02:43 +0000 | [diff] [blame] | 602 | EXPECT_TRUE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate)); |
| 603 | |
| 604 | // verify new parent get no vote |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 605 | EXPECT_FALSE(getSnapshot({.id = 2})->frameRate.vote.rate.isValid()); |
| 606 | EXPECT_EQ(getSnapshot({.id = 2})->frameRate.vote.type, |
Vishnu Nair | 3fbe326 | 2023-09-29 17:07:00 -0700 | [diff] [blame] | 607 | scheduler::FrameRateCompatibility::NoVote); |
Vishnu Nair | 52d56fd | 2023-07-20 17:02:43 +0000 | [diff] [blame] | 608 | EXPECT_TRUE(getSnapshot({.id = 2})->changes.test(RequestedLayerState::Changes::FrameRate)); |
| 609 | |
| 610 | // verify layer and children get the requested votes (unchanged) |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 611 | EXPECT_TRUE(getSnapshot({.id = 11})->frameRate.vote.rate.isValid()); |
| 612 | EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 244.f); |
| 613 | EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.type, |
Vishnu Nair | 3fbe326 | 2023-09-29 17:07:00 -0700 | [diff] [blame] | 614 | scheduler::FrameRateCompatibility::Default); |
Vishnu Nair | 52d56fd | 2023-07-20 17:02:43 +0000 | [diff] [blame] | 615 | |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 616 | EXPECT_TRUE(getSnapshot({.id = 111})->frameRate.vote.rate.isValid()); |
| 617 | EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.rate.getValue(), 244.f); |
| 618 | EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.type, |
Vishnu Nair | 3fbe326 | 2023-09-29 17:07:00 -0700 | [diff] [blame] | 619 | scheduler::FrameRateCompatibility::Default); |
Vishnu Nair | 52d56fd | 2023-07-20 17:02:43 +0000 | [diff] [blame] | 620 | |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 621 | EXPECT_TRUE(getSnapshot({.id = 122})->frameRate.vote.rate.isValid()); |
| 622 | EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.rate.getValue(), 244.f); |
| 623 | EXPECT_EQ(getSnapshot({.id = 122})->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 | } |
| 626 | |
Vishnu Nair | 3996ee3 | 2023-08-14 04:32:31 +0000 | [diff] [blame] | 627 | TEST_F(LayerSnapshotTest, translateDataspace) { |
| 628 | setDataspace(1, ui::Dataspace::UNKNOWN); |
| 629 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 630 | EXPECT_EQ(getSnapshot({.id = 1})->dataspace, ui::Dataspace::V0_SRGB); |
| 631 | } |
| 632 | |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 633 | // This test is similar to "frameRate" test case but checks that the setFrameRateCategory API |
| 634 | // interaction also works correctly with the setFrameRate API within SF frontend. |
| 635 | TEST_F(LayerSnapshotTest, frameRateWithCategory) { |
| 636 | // ROOT |
| 637 | // ├── 1 |
| 638 | // │ ├── 11 (frame rate set to 244.f) |
| 639 | // │ │ └── 111 |
| 640 | // │ ├── 12 |
| 641 | // │ │ ├── 121 |
| 642 | // │ │ └── 122 (frame rate category set to Normal) |
| 643 | // │ │ └── 1221 |
| 644 | // │ └── 13 |
| 645 | // └── 2 |
| 646 | setFrameRate(11, 244.f, 0, 0); |
| 647 | setFrameRateCategory(122, 3 /* Normal */); |
| 648 | |
| 649 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 650 | // verify parent 1 gets no vote |
| 651 | EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid()); |
| 652 | EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type, |
Vishnu Nair | 3fbe326 | 2023-09-29 17:07:00 -0700 | [diff] [blame] | 653 | scheduler::FrameRateCompatibility::NoVote); |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 654 | EXPECT_TRUE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate)); |
| 655 | |
| 656 | // verify layer 11 and children 111 get the requested votes |
| 657 | EXPECT_TRUE(getSnapshot({.id = 11})->frameRate.vote.rate.isValid()); |
| 658 | EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 244.f); |
| 659 | EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.type, |
Vishnu Nair | 3fbe326 | 2023-09-29 17:07:00 -0700 | [diff] [blame] | 660 | scheduler::FrameRateCompatibility::Default); |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 661 | EXPECT_TRUE(getSnapshot({.id = 11})->changes.test(RequestedLayerState::Changes::FrameRate)); |
| 662 | |
| 663 | EXPECT_TRUE(getSnapshot({.id = 111})->frameRate.vote.rate.isValid()); |
| 664 | EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.rate.getValue(), 244.f); |
| 665 | EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.type, |
Vishnu Nair | 3fbe326 | 2023-09-29 17:07:00 -0700 | [diff] [blame] | 666 | scheduler::FrameRateCompatibility::Default); |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 667 | EXPECT_TRUE(getSnapshot({.id = 111})->changes.test(RequestedLayerState::Changes::FrameRate)); |
| 668 | |
| 669 | // verify parent 12 gets no vote |
| 670 | EXPECT_FALSE(getSnapshot({.id = 12})->frameRate.vote.rate.isValid()); |
| 671 | EXPECT_EQ(getSnapshot({.id = 12})->frameRate.vote.type, |
Vishnu Nair | 3fbe326 | 2023-09-29 17:07:00 -0700 | [diff] [blame] | 672 | scheduler::FrameRateCompatibility::NoVote); |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 673 | EXPECT_TRUE(getSnapshot({.id = 12})->changes.test(RequestedLayerState::Changes::FrameRate)); |
| 674 | |
| 675 | // verify layer 122 and children 1221 get the requested votes |
| 676 | EXPECT_FALSE(getSnapshot({.id = 122})->frameRate.vote.rate.isValid()); |
| 677 | EXPECT_TRUE(getSnapshot({.id = 122})->frameRate.isValid()); |
| 678 | EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.type, |
Vishnu Nair | 3fbe326 | 2023-09-29 17:07:00 -0700 | [diff] [blame] | 679 | scheduler::FrameRateCompatibility::Default); |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 680 | EXPECT_EQ(getSnapshot({.id = 122})->frameRate.category, FrameRateCategory::Normal); |
| 681 | EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate)); |
Rachel Lee | 43369b2 | 2023-09-05 18:40:40 -0700 | [diff] [blame] | 682 | EXPECT_TRUE( |
| 683 | getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::AffectsChildren)); |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 684 | |
| 685 | EXPECT_FALSE(getSnapshot({.id = 1221})->frameRate.vote.rate.isValid()); |
| 686 | EXPECT_TRUE(getSnapshot({.id = 1221})->frameRate.isValid()); |
| 687 | EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.vote.type, |
Vishnu Nair | 3fbe326 | 2023-09-29 17:07:00 -0700 | [diff] [blame] | 688 | scheduler::FrameRateCompatibility::Default); |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 689 | EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.category, FrameRateCategory::Normal); |
| 690 | EXPECT_TRUE(getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::FrameRate)); |
Rachel Lee | 43369b2 | 2023-09-05 18:40:40 -0700 | [diff] [blame] | 691 | EXPECT_TRUE( |
| 692 | getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::AffectsChildren)); |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 693 | |
| 694 | // reparent and verify the child does NOT get the new parent's framerate because it already has |
| 695 | // the frame rate category specified. |
| 696 | // ROOT |
| 697 | // ├─1 |
| 698 | // │ ├─11 (frame rate set to 244.f) |
| 699 | // │ │ ├─111 |
| 700 | // │ │ └─122 (frame rate category set to Normal) |
| 701 | // │ │ └─1221 |
| 702 | // │ ├─12 |
| 703 | // │ │ └─121 |
| 704 | // │ └─13 |
| 705 | // └─2 |
| 706 | reparentLayer(122, 11); |
| 707 | |
| 708 | std::vector<uint32_t> expected = {1, 11, 111, 122, 1221, 12, 121, 13, 2}; |
| 709 | UPDATE_AND_VERIFY(mSnapshotBuilder, expected); |
| 710 | // verify parent is gets no vote |
| 711 | EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid()); |
| 712 | EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type, |
Vishnu Nair | 3fbe326 | 2023-09-29 17:07:00 -0700 | [diff] [blame] | 713 | scheduler::FrameRateCompatibility::NoVote); |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 714 | |
| 715 | // verify layer 11 and children 111 get the requested votes |
| 716 | EXPECT_TRUE(getSnapshot({.id = 11})->frameRate.vote.rate.isValid()); |
| 717 | EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.rate.getValue(), 244.f); |
| 718 | EXPECT_EQ(getSnapshot({.id = 11})->frameRate.vote.type, |
Vishnu Nair | 3fbe326 | 2023-09-29 17:07:00 -0700 | [diff] [blame] | 719 | scheduler::FrameRateCompatibility::Default); |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 720 | |
| 721 | EXPECT_TRUE(getSnapshot({.id = 111})->frameRate.vote.rate.isValid()); |
| 722 | EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.rate.getValue(), 244.f); |
| 723 | EXPECT_EQ(getSnapshot({.id = 111})->frameRate.vote.type, |
Vishnu Nair | 3fbe326 | 2023-09-29 17:07:00 -0700 | [diff] [blame] | 724 | scheduler::FrameRateCompatibility::Default); |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 725 | |
| 726 | // verify layer 122 and children 1221 get the requested category vote (unchanged from |
| 727 | // reparenting) |
| 728 | EXPECT_FALSE(getSnapshot({.id = 122})->frameRate.vote.rate.isValid()); |
| 729 | EXPECT_TRUE(getSnapshot({.id = 122})->frameRate.isValid()); |
| 730 | EXPECT_EQ(getSnapshot({.id = 122})->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 | EXPECT_EQ(getSnapshot({.id = 122})->frameRate.category, FrameRateCategory::Normal); |
| 733 | EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate)); |
| 734 | |
| 735 | EXPECT_FALSE(getSnapshot({.id = 1221})->frameRate.vote.rate.isValid()); |
| 736 | EXPECT_TRUE(getSnapshot({.id = 1221})->frameRate.isValid()); |
| 737 | EXPECT_EQ(getSnapshot({.id = 1221})->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 = 1221})->frameRate.category, FrameRateCategory::Normal); |
| 740 | EXPECT_TRUE(getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::FrameRate)); |
| 741 | } |
| 742 | |
Rachel Lee | 58cc90d | 2023-09-05 18:50:20 -0700 | [diff] [blame] | 743 | TEST_F(LayerSnapshotTest, frameRateSelectionStrategy) { |
| 744 | // ROOT |
| 745 | // ├── 1 |
| 746 | // │ ├── 11 |
| 747 | // │ │ └── 111 |
| 748 | // │ ├── 12 (frame rate set to 244.f with strategy OverrideChildren) |
| 749 | // │ │ ├── 121 |
| 750 | // │ │ └── 122 (frame rate set to 123.f but should be overridden by layer 12) |
| 751 | // │ │ └── 1221 |
| 752 | // │ └── 13 |
| 753 | // └── 2 |
| 754 | setFrameRate(12, 244.f, 0, 0); |
| 755 | setFrameRate(122, 123.f, 0, 0); |
| 756 | setFrameRateSelectionStrategy(12, 1 /* OverrideChildren */); |
| 757 | |
| 758 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 759 | // verify parent 1 gets no vote |
| 760 | EXPECT_FALSE(getSnapshot({.id = 1})->frameRate.vote.rate.isValid()); |
| 761 | EXPECT_EQ(getSnapshot({.id = 1})->frameRate.vote.type, |
Vishnu Nair | 3fbe326 | 2023-09-29 17:07:00 -0700 | [diff] [blame] | 762 | scheduler::FrameRateCompatibility::NoVote); |
Rachel Lee | 58cc90d | 2023-09-05 18:50:20 -0700 | [diff] [blame] | 763 | EXPECT_TRUE(getSnapshot({.id = 1})->changes.test(RequestedLayerState::Changes::FrameRate)); |
| 764 | |
| 765 | // verify layer 12 and all descendants (121, 122, 1221) get the requested vote |
| 766 | EXPECT_EQ(getSnapshot({.id = 12})->frameRate.vote.rate.getValue(), 244.f); |
| 767 | EXPECT_EQ(getSnapshot({.id = 12})->frameRateSelectionStrategy, |
| 768 | scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren); |
| 769 | EXPECT_TRUE(getSnapshot({.id = 12})->changes.test(RequestedLayerState::Changes::FrameRate)); |
| 770 | |
| 771 | EXPECT_EQ(getSnapshot({.id = 121})->frameRate.vote.rate.getValue(), 244.f); |
| 772 | EXPECT_EQ(getSnapshot({.id = 121})->frameRateSelectionStrategy, |
| 773 | scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren); |
| 774 | EXPECT_TRUE(getSnapshot({.id = 121})->changes.test(RequestedLayerState::Changes::FrameRate)); |
| 775 | |
| 776 | EXPECT_EQ(getSnapshot({.id = 122})->frameRate.vote.rate.getValue(), 244.f); |
| 777 | EXPECT_EQ(getSnapshot({.id = 122})->frameRateSelectionStrategy, |
| 778 | scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren); |
| 779 | EXPECT_TRUE(getSnapshot({.id = 122})->changes.test(RequestedLayerState::Changes::FrameRate)); |
| 780 | |
| 781 | EXPECT_EQ(getSnapshot({.id = 1221})->frameRate.vote.rate.getValue(), 244.f); |
| 782 | EXPECT_EQ(getSnapshot({.id = 1221})->frameRateSelectionStrategy, |
| 783 | scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren); |
| 784 | EXPECT_TRUE(getSnapshot({.id = 1221})->changes.test(RequestedLayerState::Changes::FrameRate)); |
| 785 | } |
| 786 | |
Vishnu Nair | 0808ae6 | 2023-08-07 21:42:42 -0700 | [diff] [blame] | 787 | TEST_F(LayerSnapshotTest, skipRoundCornersWhenProtected) { |
| 788 | setRoundedCorners(1, 42.f); |
| 789 | setRoundedCorners(2, 42.f); |
| 790 | setCrop(1, Rect{1000, 1000}); |
| 791 | setCrop(2, Rect{1000, 1000}); |
| 792 | |
| 793 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 794 | EXPECT_TRUE(getSnapshot({.id = 1})->roundedCorner.hasRoundedCorners()); |
| 795 | EXPECT_EQ(getSnapshot({.id = 1})->roundedCorner.radius.x, 42.f); |
| 796 | EXPECT_TRUE(getSnapshot({.id = 2})->roundedCorner.hasRoundedCorners()); |
| 797 | |
| 798 | // add a buffer with the protected bit, check rounded corners are not set when |
| 799 | // skipRoundCornersWhenProtected == true |
| 800 | setBuffer(1, |
| 801 | std::make_shared< |
| 802 | renderengine::mock::FakeExternalTexture>(1U /*width*/, 1U /*height*/, |
| 803 | 1ULL /* bufferId */, |
| 804 | HAL_PIXEL_FORMAT_RGBA_8888, |
| 805 | GRALLOC_USAGE_PROTECTED /*usage*/)); |
| 806 | |
| 807 | LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(), |
| 808 | .layerLifecycleManager = mLifecycleManager, |
| 809 | .includeMetadata = false, |
| 810 | .displays = mFrontEndDisplayInfos, |
| 811 | .displayChanges = false, |
| 812 | .globalShadowSettings = globalShadowSettings, |
| 813 | .supportsBlur = true, |
| 814 | .supportedLayerGenericMetadata = {}, |
| 815 | .genericLayerMetadataKeyMap = {}, |
| 816 | .skipRoundCornersWhenProtected = true}; |
| 817 | update(mSnapshotBuilder, args); |
| 818 | EXPECT_FALSE(getSnapshot({.id = 1})->roundedCorner.hasRoundedCorners()); |
| 819 | // layer 2 doesn't have a buffer and should be unaffected |
| 820 | EXPECT_TRUE(getSnapshot({.id = 2})->roundedCorner.hasRoundedCorners()); |
| 821 | |
| 822 | // remove protected bit, check rounded corners are set |
| 823 | setBuffer(1, |
| 824 | std::make_shared<renderengine::mock::FakeExternalTexture>(1U /*width*/, 1U /*height*/, |
| 825 | 2ULL /* bufferId */, |
| 826 | HAL_PIXEL_FORMAT_RGBA_8888, |
| 827 | 0 /*usage*/)); |
| 828 | update(mSnapshotBuilder, args); |
| 829 | EXPECT_TRUE(getSnapshot({.id = 1})->roundedCorner.hasRoundedCorners()); |
| 830 | EXPECT_EQ(getSnapshot({.id = 1})->roundedCorner.radius.x, 42.f); |
| 831 | } |
| 832 | |
Vishnu Nair | bd51f95 | 2023-08-31 22:50:14 -0700 | [diff] [blame] | 833 | TEST_F(LayerSnapshotTest, setRefreshRateIndicatorCompositionType) { |
| 834 | setFlags(1, layer_state_t::eLayerIsRefreshRateIndicator, |
| 835 | layer_state_t::eLayerIsRefreshRateIndicator); |
| 836 | setBuffer(1, |
| 837 | std::make_shared<renderengine::mock::FakeExternalTexture>(1U /*width*/, 1U /*height*/, |
| 838 | 42ULL /* bufferId */, |
| 839 | HAL_PIXEL_FORMAT_RGBA_8888, |
| 840 | 0 /*usage*/)); |
| 841 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 842 | EXPECT_EQ(getSnapshot({.id = 1})->compositionType, |
| 843 | aidl::android::hardware::graphics::composer3::Composition::REFRESH_RATE_INDICATOR); |
| 844 | } |
| 845 | |
Chavi Weingarten | 0759734 | 2023-09-14 21:10:59 +0000 | [diff] [blame] | 846 | TEST_F(LayerSnapshotTest, setBufferCrop) { |
| 847 | // validate no buffer but has crop |
| 848 | Rect crop = Rect(0, 0, 50, 50); |
| 849 | setBufferCrop(1, crop); |
| 850 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 851 | EXPECT_EQ(getSnapshot(1)->geomContentCrop, crop); |
| 852 | |
| 853 | setBuffer(1, |
| 854 | std::make_shared<renderengine::mock::FakeExternalTexture>(100U /*width*/, |
| 855 | 100U /*height*/, |
| 856 | 42ULL /* bufferId */, |
| 857 | HAL_PIXEL_FORMAT_RGBA_8888, |
| 858 | 0 /*usage*/)); |
| 859 | // validate a buffer crop within the buffer bounds |
| 860 | setBufferCrop(1, crop); |
| 861 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 862 | EXPECT_EQ(getSnapshot(1)->geomContentCrop, crop); |
| 863 | |
| 864 | // validate a buffer crop outside the buffer bounds |
| 865 | crop = Rect(0, 0, 150, 150); |
| 866 | setBufferCrop(1, crop); |
| 867 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 868 | EXPECT_EQ(getSnapshot(1)->geomContentCrop, Rect(0, 0, 100, 100)); |
| 869 | |
| 870 | // validate no buffer crop |
| 871 | setBufferCrop(1, Rect()); |
| 872 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 873 | EXPECT_EQ(getSnapshot(1)->geomContentCrop, Rect(0, 0, 100, 100)); |
| 874 | } |
Vishnu Nair | befd3e2 | 2023-10-05 17:48:31 +0000 | [diff] [blame^] | 875 | |
| 876 | TEST_F(LayerSnapshotTest, setShadowRadius) { |
| 877 | static constexpr float SHADOW_RADIUS = 123.f; |
| 878 | setShadowRadius(1, SHADOW_RADIUS); |
| 879 | UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 880 | EXPECT_EQ(getSnapshot(1)->shadowSettings.length, SHADOW_RADIUS); |
| 881 | EXPECT_EQ(getSnapshot(1)->shadowRadius, SHADOW_RADIUS); |
| 882 | } |
| 883 | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 884 | } // namespace android::surfaceflinger::frontend |