Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 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 | |
Alec Mouri | e7cc1c2 | 2021-04-27 15:23:26 -0700 | [diff] [blame] | 17 | #include <compositionengine/impl/HwcBufferCache.h> |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 18 | #include <compositionengine/impl/OutputLayer.h> |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 19 | #include <compositionengine/impl/OutputLayerCompositionState.h> |
Lloyd Pique | 07e3321 | 2018-12-18 16:33:37 -0800 | [diff] [blame] | 20 | #include <compositionengine/mock/CompositionEngine.h> |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 21 | #include <compositionengine/mock/DisplayColorProfile.h> |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 22 | #include <compositionengine/mock/LayerFE.h> |
| 23 | #include <compositionengine/mock/Output.h> |
| 24 | #include <gtest/gtest.h> |
Marin Shalamanov | 68933fb | 2020-09-10 17:58:12 +0200 | [diff] [blame] | 25 | #include <log/log.h> |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 26 | #include <renderengine/impl/ExternalTexture.h> |
Alec Mouri | 03bf0ff | 2021-04-19 14:17:31 -0700 | [diff] [blame] | 27 | #include <renderengine/mock/RenderEngine.h> |
Lloyd Pique | e98286f | 2024-09-16 16:23:24 -0700 | [diff] [blame^] | 28 | #include <ui/FloatRect.h> |
Alec Mouri | 03bf0ff | 2021-04-19 14:17:31 -0700 | [diff] [blame] | 29 | #include <ui/PixelFormat.h> |
Lloyd Pique | e98286f | 2024-09-16 16:23:24 -0700 | [diff] [blame^] | 30 | |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 31 | #include "RegionMatcher.h" |
Lloyd Pique | e98286f | 2024-09-16 16:23:24 -0700 | [diff] [blame^] | 32 | #include "mock/DisplayHardware/MockHWC2.h" |
| 33 | #include "mock/DisplayHardware/MockHWComposer.h" |
Lloyd Pique | 07e3321 | 2018-12-18 16:33:37 -0800 | [diff] [blame] | 34 | |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 35 | #include <aidl/android/hardware/graphics/composer3/Composition.h> |
| 36 | |
| 37 | using aidl::android::hardware::graphics::composer3::Composition; |
| 38 | |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 39 | namespace android::compositionengine { |
| 40 | namespace { |
| 41 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 42 | namespace hal = android::hardware::graphics::composer::hal; |
| 43 | |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 44 | using testing::_; |
Lloyd Pique | 46b72df | 2019-10-29 13:19:27 -0700 | [diff] [blame] | 45 | using testing::InSequence; |
Brian Lindahl | 90553da | 2022-12-06 13:36:30 -0700 | [diff] [blame] | 46 | using testing::Mock; |
| 47 | using testing::NiceMock; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 48 | using testing::Return; |
| 49 | using testing::ReturnRef; |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 50 | using testing::StrictMock; |
| 51 | |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 52 | constexpr auto TR_IDENT = 0u; |
| 53 | constexpr auto TR_FLP_H = HAL_TRANSFORM_FLIP_H; |
| 54 | constexpr auto TR_FLP_V = HAL_TRANSFORM_FLIP_V; |
| 55 | constexpr auto TR_ROT_90 = HAL_TRANSFORM_ROT_90; |
| 56 | constexpr auto TR_ROT_180 = TR_FLP_H | TR_FLP_V; |
| 57 | constexpr auto TR_ROT_270 = TR_ROT_90 | TR_ROT_180; |
| 58 | |
| 59 | const std::string kOutputName{"Test Output"}; |
| 60 | |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 61 | MATCHER_P(ColorEq, expected, "") { |
| 62 | *result_listener << "Colors are not equal\n"; |
| 63 | *result_listener << "expected " << expected.r << " " << expected.g << " " << expected.b << " " |
| 64 | << expected.a << "\n"; |
| 65 | *result_listener << "actual " << arg.r << " " << arg.g << " " << arg.b << " " << arg.a << "\n"; |
| 66 | |
| 67 | return expected.r == arg.r && expected.g == arg.g && expected.b == arg.b && expected.a == arg.a; |
| 68 | } |
| 69 | |
Marin Shalamanov | 68933fb | 2020-09-10 17:58:12 +0200 | [diff] [blame] | 70 | ui::Rotation toRotation(uint32_t rotationFlag) { |
| 71 | switch (rotationFlag) { |
| 72 | case ui::Transform::RotationFlags::ROT_0: |
| 73 | return ui::ROTATION_0; |
| 74 | case ui::Transform::RotationFlags::ROT_90: |
| 75 | return ui::ROTATION_90; |
| 76 | case ui::Transform::RotationFlags::ROT_180: |
| 77 | return ui::ROTATION_180; |
| 78 | case ui::Transform::RotationFlags::ROT_270: |
| 79 | return ui::ROTATION_270; |
| 80 | default: |
| 81 | LOG_FATAL("Unexpected rotation flag %d", rotationFlag); |
| 82 | return ui::Rotation(-1); |
| 83 | } |
| 84 | } |
| 85 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 86 | struct OutputLayerTest : public testing::Test { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 87 | struct OutputLayer final : public impl::OutputLayer { |
Brian Lindahl | 90553da | 2022-12-06 13:36:30 -0700 | [diff] [blame] | 88 | OutputLayer(const compositionengine::Output& output, compositionengine::LayerFE& layerFE) |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 89 | : mOutput(output), mLayerFE(layerFE) {} |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 90 | ~OutputLayer() override = default; |
| 91 | |
| 92 | // compositionengine::OutputLayer overrides |
| 93 | const compositionengine::Output& getOutput() const override { return mOutput; } |
Brian Lindahl | 90553da | 2022-12-06 13:36:30 -0700 | [diff] [blame] | 94 | compositionengine::LayerFE& getLayerFE() const override { return mLayerFE; } |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 95 | const impl::OutputLayerCompositionState& getState() const override { return mState; } |
| 96 | impl::OutputLayerCompositionState& editState() override { return mState; } |
| 97 | |
| 98 | // compositionengine::impl::OutputLayer overrides |
| 99 | void dumpState(std::string& out) const override { mState.dump(out); } |
| 100 | |
| 101 | const compositionengine::Output& mOutput; |
Brian Lindahl | 90553da | 2022-12-06 13:36:30 -0700 | [diff] [blame] | 102 | compositionengine::LayerFE& mLayerFE; |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 103 | impl::OutputLayerCompositionState mState; |
| 104 | }; |
| 105 | |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 106 | OutputLayerTest() { |
Brian Lindahl | 90553da | 2022-12-06 13:36:30 -0700 | [diff] [blame] | 107 | ON_CALL(mLayerFE, getDebugName()).WillByDefault(Return("Test LayerFE")); |
| 108 | ON_CALL(mOutput, getName()).WillByDefault(ReturnRef(kOutputName)); |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 109 | |
Brian Lindahl | 90553da | 2022-12-06 13:36:30 -0700 | [diff] [blame] | 110 | ON_CALL(mLayerFE, getCompositionState()).WillByDefault(Return(&mLayerFEState)); |
| 111 | ON_CALL(mOutput, getState()).WillByDefault(ReturnRef(mOutputState)); |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 112 | } |
| 113 | |
Brian Lindahl | 90553da | 2022-12-06 13:36:30 -0700 | [diff] [blame] | 114 | NiceMock<compositionengine::mock::Output> mOutput; |
| 115 | sp<NiceMock<compositionengine::mock::LayerFE>> mLayerFE_ = |
| 116 | sp<NiceMock<compositionengine::mock::LayerFE>>::make(); |
| 117 | NiceMock<compositionengine::mock::LayerFE>& mLayerFE = *mLayerFE_; |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 118 | OutputLayer mOutputLayer{mOutput, mLayerFE}; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 119 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 120 | LayerFECompositionState mLayerFEState; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 121 | impl::OutputCompositionState mOutputState; |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 122 | }; |
| 123 | |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 124 | /* |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 125 | * Basic construction |
| 126 | */ |
| 127 | |
| 128 | TEST_F(OutputLayerTest, canInstantiateOutputLayer) {} |
| 129 | |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 130 | /* |
Lloyd Pique | df336d9 | 2019-03-07 21:38:42 -0800 | [diff] [blame] | 131 | * OutputLayer::setHwcLayer() |
Lloyd Pique | 07e3321 | 2018-12-18 16:33:37 -0800 | [diff] [blame] | 132 | */ |
| 133 | |
Lloyd Pique | df336d9 | 2019-03-07 21:38:42 -0800 | [diff] [blame] | 134 | TEST_F(OutputLayerTest, settingNullHwcLayerSetsEmptyHwcState) { |
Lloyd Pique | 07e3321 | 2018-12-18 16:33:37 -0800 | [diff] [blame] | 135 | StrictMock<compositionengine::mock::CompositionEngine> compositionEngine; |
| 136 | |
Lloyd Pique | df336d9 | 2019-03-07 21:38:42 -0800 | [diff] [blame] | 137 | mOutputLayer.setHwcLayer(nullptr); |
Lloyd Pique | 07e3321 | 2018-12-18 16:33:37 -0800 | [diff] [blame] | 138 | |
| 139 | EXPECT_FALSE(mOutputLayer.getState().hwc); |
| 140 | } |
| 141 | |
Lloyd Pique | df336d9 | 2019-03-07 21:38:42 -0800 | [diff] [blame] | 142 | TEST_F(OutputLayerTest, settingHwcLayerSetsHwcState) { |
| 143 | auto hwcLayer = std::make_shared<StrictMock<HWC2::mock::Layer>>(); |
Lloyd Pique | 07e3321 | 2018-12-18 16:33:37 -0800 | [diff] [blame] | 144 | |
Lloyd Pique | df336d9 | 2019-03-07 21:38:42 -0800 | [diff] [blame] | 145 | mOutputLayer.setHwcLayer(hwcLayer); |
Lloyd Pique | 07e3321 | 2018-12-18 16:33:37 -0800 | [diff] [blame] | 146 | |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 147 | const auto& outputLayerState = mOutputLayer.getState(); |
| 148 | ASSERT_TRUE(outputLayerState.hwc); |
Lloyd Pique | 07e3321 | 2018-12-18 16:33:37 -0800 | [diff] [blame] | 149 | |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 150 | const auto& hwcState = *outputLayerState.hwc; |
Lloyd Pique | df336d9 | 2019-03-07 21:38:42 -0800 | [diff] [blame] | 151 | EXPECT_EQ(hwcLayer, hwcState.hwcLayer); |
Lloyd Pique | 07e3321 | 2018-12-18 16:33:37 -0800 | [diff] [blame] | 152 | } |
| 153 | |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 154 | /* |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 155 | * OutputLayer::calculateOutputSourceCrop() |
| 156 | */ |
| 157 | |
| 158 | struct OutputLayerSourceCropTest : public OutputLayerTest { |
| 159 | OutputLayerSourceCropTest() { |
| 160 | // Set reasonable default values for a simple case. Each test will |
| 161 | // set one specific value to something different. |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 162 | mLayerFEState.geomUsesSourceCrop = true; |
| 163 | mLayerFEState.geomContentCrop = Rect{0, 0, 1920, 1080}; |
| 164 | mLayerFEState.transparentRegionHint = Region{}; |
| 165 | mLayerFEState.geomLayerBounds = FloatRect{0.f, 0.f, 1920.f, 1080.f}; |
| 166 | mLayerFEState.geomLayerTransform = ui::Transform{TR_IDENT}; |
| 167 | mLayerFEState.geomBufferSize = Rect{0, 0, 1920, 1080}; |
| 168 | mLayerFEState.geomBufferTransform = TR_IDENT; |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 169 | |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 170 | mOutputState.layerStackSpace.setContent(Rect{0, 0, 1920, 1080}); |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | FloatRect calculateOutputSourceCrop() { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 174 | mLayerFEState.geomInverseLayerTransform = mLayerFEState.geomLayerTransform.inverse(); |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 175 | |
ramindani | 2c043be | 2022-04-19 20:11:10 +0000 | [diff] [blame] | 176 | return mOutputLayer.calculateOutputSourceCrop(ui::Transform::RotationFlags::ROT_0); |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 177 | } |
| 178 | }; |
| 179 | |
| 180 | TEST_F(OutputLayerSourceCropTest, computesEmptyIfSourceCropNotUsed) { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 181 | mLayerFEState.geomUsesSourceCrop = false; |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 182 | |
| 183 | const FloatRect expected{}; |
Lloyd Pique | ea62928 | 2019-12-03 15:57:10 -0800 | [diff] [blame] | 184 | EXPECT_THAT(calculateOutputSourceCrop(), expected); |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | TEST_F(OutputLayerSourceCropTest, correctForSimpleDefaultCase) { |
| 188 | const FloatRect expected{0.f, 0.f, 1920.f, 1080.f}; |
Lloyd Pique | ea62928 | 2019-12-03 15:57:10 -0800 | [diff] [blame] | 189 | EXPECT_THAT(calculateOutputSourceCrop(), expected); |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | TEST_F(OutputLayerSourceCropTest, handlesBoundsOutsideViewport) { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 193 | mLayerFEState.geomLayerBounds = FloatRect{-2000.f, -2000.f, 2000.f, 2000.f}; |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 194 | |
| 195 | const FloatRect expected{0.f, 0.f, 1920.f, 1080.f}; |
Lloyd Pique | ea62928 | 2019-12-03 15:57:10 -0800 | [diff] [blame] | 196 | EXPECT_THAT(calculateOutputSourceCrop(), expected); |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | TEST_F(OutputLayerSourceCropTest, handlesBoundsOutsideViewportRotated) { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 200 | mLayerFEState.geomLayerBounds = FloatRect{-2000.f, -2000.f, 2000.f, 2000.f}; |
| 201 | mLayerFEState.geomLayerTransform.set(HAL_TRANSFORM_ROT_90, 1920, 1080); |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 202 | |
| 203 | const FloatRect expected{0.f, 0.f, 1080.f, 1080.f}; |
Lloyd Pique | ea62928 | 2019-12-03 15:57:10 -0800 | [diff] [blame] | 204 | EXPECT_THAT(calculateOutputSourceCrop(), expected); |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | TEST_F(OutputLayerSourceCropTest, calculateOutputSourceCropWorksWithATransformedBuffer) { |
| 208 | struct Entry { |
| 209 | uint32_t bufferInvDisplay; |
| 210 | uint32_t buffer; |
| 211 | uint32_t display; |
| 212 | FloatRect expected; |
| 213 | }; |
| 214 | // Not an exhaustive list of cases, but hopefully enough. |
| 215 | const std::array<Entry, 12> testData = { |
| 216 | // clang-format off |
| 217 | // inv buffer display expected |
| 218 | /* 0 */ Entry{false, TR_IDENT, TR_IDENT, FloatRect{0.f, 0.f, 1920.f, 1080.f}}, |
| 219 | /* 1 */ Entry{false, TR_IDENT, TR_ROT_90, FloatRect{0.f, 0.f, 1920.f, 1080.f}}, |
| 220 | /* 2 */ Entry{false, TR_IDENT, TR_ROT_180, FloatRect{0.f, 0.f, 1920.f, 1080.f}}, |
| 221 | /* 3 */ Entry{false, TR_IDENT, TR_ROT_270, FloatRect{0.f, 0.f, 1920.f, 1080.f}}, |
| 222 | |
| 223 | /* 4 */ Entry{true, TR_IDENT, TR_IDENT, FloatRect{0.f, 0.f, 1920.f, 1080.f}}, |
| 224 | /* 5 */ Entry{true, TR_IDENT, TR_ROT_90, FloatRect{0.f, 0.f, 1920.f, 1080.f}}, |
| 225 | /* 6 */ Entry{true, TR_IDENT, TR_ROT_180, FloatRect{0.f, 0.f, 1920.f, 1080.f}}, |
| 226 | /* 7 */ Entry{true, TR_IDENT, TR_ROT_270, FloatRect{0.f, 0.f, 1920.f, 1080.f}}, |
| 227 | |
| 228 | /* 8 */ Entry{false, TR_IDENT, TR_IDENT, FloatRect{0.f, 0.f, 1920.f, 1080.f}}, |
| 229 | /* 9 */ Entry{false, TR_ROT_90, TR_ROT_90, FloatRect{0.f, 0.f, 1920.f, 1080.f}}, |
| 230 | /* 10 */ Entry{false, TR_ROT_180, TR_ROT_180, FloatRect{0.f, 0.f, 1920.f, 1080.f}}, |
| 231 | /* 11 */ Entry{false, TR_ROT_270, TR_ROT_270, FloatRect{0.f, 0.f, 1920.f, 1080.f}}, |
| 232 | |
| 233 | // clang-format on |
| 234 | }; |
| 235 | |
| 236 | for (size_t i = 0; i < testData.size(); i++) { |
| 237 | const auto& entry = testData[i]; |
| 238 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 239 | mLayerFEState.geomBufferUsesDisplayInverseTransform = entry.bufferInvDisplay; |
| 240 | mLayerFEState.geomBufferTransform = entry.buffer; |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 241 | mOutputState.displaySpace.setOrientation(toRotation(entry.display)); |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 242 | |
Lloyd Pique | ea62928 | 2019-12-03 15:57:10 -0800 | [diff] [blame] | 243 | EXPECT_THAT(calculateOutputSourceCrop(), entry.expected) << "entry " << i; |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 244 | } |
| 245 | } |
| 246 | |
| 247 | TEST_F(OutputLayerSourceCropTest, geomContentCropAffectsCrop) { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 248 | mLayerFEState.geomContentCrop = Rect{0, 0, 960, 540}; |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 249 | |
| 250 | const FloatRect expected{0.f, 0.f, 960.f, 540.f}; |
Lloyd Pique | ea62928 | 2019-12-03 15:57:10 -0800 | [diff] [blame] | 251 | EXPECT_THAT(calculateOutputSourceCrop(), expected); |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | TEST_F(OutputLayerSourceCropTest, viewportAffectsCrop) { |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 255 | mOutputState.layerStackSpace.setContent(Rect{0, 0, 960, 540}); |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 256 | |
| 257 | const FloatRect expected{0.f, 0.f, 960.f, 540.f}; |
Lloyd Pique | ea62928 | 2019-12-03 15:57:10 -0800 | [diff] [blame] | 258 | EXPECT_THAT(calculateOutputSourceCrop(), expected); |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | /* |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 262 | * OutputLayer::calculateOutputDisplayFrame() |
| 263 | */ |
| 264 | |
| 265 | struct OutputLayerDisplayFrameTest : public OutputLayerTest { |
| 266 | OutputLayerDisplayFrameTest() { |
| 267 | // Set reasonable default values for a simple case. Each test will |
| 268 | // set one specific value to something different. |
| 269 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 270 | mLayerFEState.transparentRegionHint = Region{}; |
| 271 | mLayerFEState.geomLayerTransform = ui::Transform{TR_IDENT}; |
| 272 | mLayerFEState.geomBufferSize = Rect{0, 0, 1920, 1080}; |
| 273 | mLayerFEState.geomBufferUsesDisplayInverseTransform = false; |
Vishnu Nair | a9123c8 | 2024-10-03 03:56:44 +0000 | [diff] [blame] | 274 | mLayerFEState.geomCrop = FloatRect{0, 0, 1920, 1080}; |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 275 | mLayerFEState.geomLayerBounds = FloatRect{0.f, 0.f, 1920.f, 1080.f}; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 276 | |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 277 | mOutputState.layerStackSpace.setContent(Rect{0, 0, 1920, 1080}); |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 278 | mOutputState.transform = ui::Transform{TR_IDENT}; |
| 279 | } |
| 280 | |
| 281 | Rect calculateOutputDisplayFrame() { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 282 | mLayerFEState.geomInverseLayerTransform = mLayerFEState.geomLayerTransform.inverse(); |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 283 | |
| 284 | return mOutputLayer.calculateOutputDisplayFrame(); |
| 285 | } |
| 286 | }; |
| 287 | |
| 288 | TEST_F(OutputLayerDisplayFrameTest, correctForSimpleDefaultCase) { |
| 289 | const Rect expected{0, 0, 1920, 1080}; |
Lloyd Pique | ea62928 | 2019-12-03 15:57:10 -0800 | [diff] [blame] | 290 | EXPECT_THAT(calculateOutputDisplayFrame(), expected); |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | TEST_F(OutputLayerDisplayFrameTest, fullActiveTransparentRegionReturnsEmptyFrame) { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 294 | mLayerFEState.transparentRegionHint = Region{Rect{0, 0, 1920, 1080}}; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 295 | const Rect expected{0, 0, 0, 0}; |
Lloyd Pique | ea62928 | 2019-12-03 15:57:10 -0800 | [diff] [blame] | 296 | EXPECT_THAT(calculateOutputDisplayFrame(), expected); |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | TEST_F(OutputLayerDisplayFrameTest, cropAffectsDisplayFrame) { |
Vishnu Nair | a9123c8 | 2024-10-03 03:56:44 +0000 | [diff] [blame] | 300 | mLayerFEState.geomCrop = FloatRect{100, 200, 300, 500}; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 301 | const Rect expected{100, 200, 300, 500}; |
Lloyd Pique | ea62928 | 2019-12-03 15:57:10 -0800 | [diff] [blame] | 302 | EXPECT_THAT(calculateOutputDisplayFrame(), expected); |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | TEST_F(OutputLayerDisplayFrameTest, cropAffectsDisplayFrameRotated) { |
Vishnu Nair | a9123c8 | 2024-10-03 03:56:44 +0000 | [diff] [blame] | 306 | mLayerFEState.geomCrop = FloatRect{100, 200, 300, 500}; |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 307 | mLayerFEState.geomLayerTransform.set(HAL_TRANSFORM_ROT_90, 1920, 1080); |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 308 | const Rect expected{1420, 100, 1720, 300}; |
Lloyd Pique | ea62928 | 2019-12-03 15:57:10 -0800 | [diff] [blame] | 309 | EXPECT_THAT(calculateOutputDisplayFrame(), expected); |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | TEST_F(OutputLayerDisplayFrameTest, emptyGeomCropIsNotUsedToComputeFrame) { |
Vishnu Nair | a9123c8 | 2024-10-03 03:56:44 +0000 | [diff] [blame] | 313 | mLayerFEState.geomCrop = FloatRect{}; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 314 | const Rect expected{0, 0, 1920, 1080}; |
Lloyd Pique | ea62928 | 2019-12-03 15:57:10 -0800 | [diff] [blame] | 315 | EXPECT_THAT(calculateOutputDisplayFrame(), expected); |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 316 | } |
| 317 | |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 318 | TEST_F(OutputLayerDisplayFrameTest, geomLayerBoundsAffectsFrame) { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 319 | mLayerFEState.geomLayerBounds = FloatRect{0.f, 0.f, 960.f, 540.f}; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 320 | const Rect expected{0, 0, 960, 540}; |
Lloyd Pique | ea62928 | 2019-12-03 15:57:10 -0800 | [diff] [blame] | 321 | EXPECT_THAT(calculateOutputDisplayFrame(), expected); |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | TEST_F(OutputLayerDisplayFrameTest, viewportAffectsFrame) { |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 325 | mOutputState.layerStackSpace.setContent(Rect{0, 0, 960, 540}); |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 326 | const Rect expected{0, 0, 960, 540}; |
Lloyd Pique | ea62928 | 2019-12-03 15:57:10 -0800 | [diff] [blame] | 327 | EXPECT_THAT(calculateOutputDisplayFrame(), expected); |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | TEST_F(OutputLayerDisplayFrameTest, outputTransformAffectsDisplayFrame) { |
| 331 | mOutputState.transform = ui::Transform{HAL_TRANSFORM_ROT_90}; |
| 332 | const Rect expected{-1080, 0, 0, 1920}; |
Lloyd Pique | ea62928 | 2019-12-03 15:57:10 -0800 | [diff] [blame] | 333 | EXPECT_THAT(calculateOutputDisplayFrame(), expected); |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 334 | } |
| 335 | |
Leon Scroggins III | d394d3c | 2021-06-24 11:30:32 -0400 | [diff] [blame] | 336 | TEST_F(OutputLayerDisplayFrameTest, shadowExpandsDisplayFrame) { |
| 337 | const int kShadowRadius = 5; |
Vishnu Nair | d9e4f46 | 2023-10-06 04:05:45 +0000 | [diff] [blame] | 338 | mLayerFEState.shadowSettings.length = kShadowRadius; |
Leon Scroggins III | d394d3c | 2021-06-24 11:30:32 -0400 | [diff] [blame] | 339 | mLayerFEState.forceClientComposition = true; |
| 340 | |
| 341 | mLayerFEState.geomLayerBounds = FloatRect{100.f, 100.f, 200.f, 200.f}; |
| 342 | Rect expected{mLayerFEState.geomLayerBounds}; |
Alec Mouri | da12851 | 2024-09-28 23:46:58 +0000 | [diff] [blame] | 343 | expected.inset(-2 * kShadowRadius, -2 * kShadowRadius, -2 * kShadowRadius, -2 * kShadowRadius); |
Leon Scroggins III | d394d3c | 2021-06-24 11:30:32 -0400 | [diff] [blame] | 344 | EXPECT_THAT(calculateOutputDisplayFrame(), expected); |
| 345 | } |
| 346 | |
| 347 | TEST_F(OutputLayerDisplayFrameTest, shadowExpandsDisplayFrame_onlyIfForcingClientComposition) { |
| 348 | const int kShadowRadius = 5; |
Vishnu Nair | d9e4f46 | 2023-10-06 04:05:45 +0000 | [diff] [blame] | 349 | mLayerFEState.shadowSettings.length = kShadowRadius; |
Leon Scroggins III | d394d3c | 2021-06-24 11:30:32 -0400 | [diff] [blame] | 350 | mLayerFEState.forceClientComposition = false; |
| 351 | |
| 352 | mLayerFEState.geomLayerBounds = FloatRect{100.f, 100.f, 200.f, 200.f}; |
| 353 | Rect expected{mLayerFEState.geomLayerBounds}; |
| 354 | EXPECT_THAT(calculateOutputDisplayFrame(), expected); |
| 355 | } |
| 356 | |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 357 | /* |
| 358 | * OutputLayer::calculateOutputRelativeBufferTransform() |
| 359 | */ |
| 360 | |
| 361 | TEST_F(OutputLayerTest, calculateOutputRelativeBufferTransformTestsNeeded) { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 362 | mLayerFEState.geomBufferUsesDisplayInverseTransform = false; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 363 | |
| 364 | struct Entry { |
| 365 | uint32_t layer; |
| 366 | uint32_t buffer; |
| 367 | uint32_t display; |
| 368 | uint32_t expected; |
| 369 | }; |
| 370 | // Not an exhaustive list of cases, but hopefully enough. |
| 371 | const std::array<Entry, 24> testData = { |
| 372 | // clang-format off |
| 373 | // layer buffer display expected |
| 374 | /* 0 */ Entry{TR_IDENT, TR_IDENT, TR_IDENT, TR_IDENT}, |
| 375 | /* 1 */ Entry{TR_IDENT, TR_IDENT, TR_ROT_90, TR_ROT_90}, |
| 376 | /* 2 */ Entry{TR_IDENT, TR_IDENT, TR_ROT_180, TR_ROT_180}, |
| 377 | /* 3 */ Entry{TR_IDENT, TR_IDENT, TR_ROT_270, TR_ROT_270}, |
| 378 | |
| 379 | /* 4 */ Entry{TR_IDENT, TR_FLP_H, TR_IDENT, TR_FLP_H ^ TR_IDENT}, |
| 380 | /* 5 */ Entry{TR_IDENT, TR_FLP_H, TR_ROT_90, TR_FLP_H ^ TR_ROT_90}, |
| 381 | /* 6 */ Entry{TR_IDENT, TR_FLP_H, TR_ROT_180, TR_FLP_H ^ TR_ROT_180}, |
| 382 | /* 7 */ Entry{TR_IDENT, TR_FLP_H, TR_ROT_270, TR_FLP_H ^ TR_ROT_270}, |
| 383 | |
| 384 | /* 8 */ Entry{TR_IDENT, TR_FLP_V, TR_IDENT, TR_FLP_V}, |
| 385 | /* 9 */ Entry{TR_IDENT, TR_ROT_90, TR_ROT_90, TR_ROT_180}, |
| 386 | /* 10 */ Entry{TR_IDENT, TR_ROT_180, TR_ROT_180, TR_IDENT}, |
| 387 | /* 11 */ Entry{TR_IDENT, TR_ROT_270, TR_ROT_270, TR_ROT_180}, |
| 388 | |
| 389 | /* 12 */ Entry{TR_ROT_90, TR_IDENT, TR_IDENT, TR_IDENT ^ TR_ROT_90}, |
| 390 | /* 13 */ Entry{TR_ROT_90, TR_FLP_H, TR_ROT_90, TR_FLP_H ^ TR_ROT_180}, |
| 391 | /* 14 */ Entry{TR_ROT_90, TR_IDENT, TR_ROT_180, TR_IDENT ^ TR_ROT_270}, |
| 392 | /* 15 */ Entry{TR_ROT_90, TR_FLP_H, TR_ROT_270, TR_FLP_H ^ TR_IDENT}, |
| 393 | |
| 394 | /* 16 */ Entry{TR_ROT_180, TR_FLP_H, TR_IDENT, TR_FLP_H ^ TR_ROT_180}, |
| 395 | /* 17 */ Entry{TR_ROT_180, TR_IDENT, TR_ROT_90, TR_IDENT ^ TR_ROT_270}, |
| 396 | /* 18 */ Entry{TR_ROT_180, TR_FLP_H, TR_ROT_180, TR_FLP_H ^ TR_IDENT}, |
| 397 | /* 19 */ Entry{TR_ROT_180, TR_IDENT, TR_ROT_270, TR_IDENT ^ TR_ROT_90}, |
| 398 | |
| 399 | /* 20 */ Entry{TR_ROT_270, TR_IDENT, TR_IDENT, TR_IDENT ^ TR_ROT_270}, |
| 400 | /* 21 */ Entry{TR_ROT_270, TR_FLP_H, TR_ROT_90, TR_FLP_H ^ TR_IDENT}, |
| 401 | /* 22 */ Entry{TR_ROT_270, TR_FLP_H, TR_ROT_180, TR_FLP_H ^ TR_ROT_90}, |
| 402 | /* 23 */ Entry{TR_ROT_270, TR_IDENT, TR_ROT_270, TR_IDENT ^ TR_ROT_180}, |
| 403 | // clang-format on |
| 404 | }; |
| 405 | |
| 406 | for (size_t i = 0; i < testData.size(); i++) { |
| 407 | const auto& entry = testData[i]; |
| 408 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 409 | mLayerFEState.geomLayerTransform.set(entry.layer, 1920, 1080); |
| 410 | mLayerFEState.geomBufferTransform = entry.buffer; |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 411 | mOutputState.displaySpace.setOrientation(toRotation(entry.display)); |
Rashed Abdel-Tawab | 6643cd8 | 2019-10-29 10:01:56 -0700 | [diff] [blame] | 412 | mOutputState.transform = ui::Transform{entry.display}; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 413 | |
Snild Dolkow | 9e217d6 | 2020-04-22 15:53:42 +0200 | [diff] [blame] | 414 | const auto actual = mOutputLayer.calculateOutputRelativeBufferTransform(entry.display); |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 415 | EXPECT_EQ(entry.expected, actual) << "entry " << i; |
| 416 | } |
| 417 | } |
| 418 | |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 419 | TEST_F(OutputLayerTest, |
| 420 | calculateOutputRelativeBufferTransformTestWithOfBufferUsesDisplayInverseTransform) { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 421 | mLayerFEState.geomBufferUsesDisplayInverseTransform = true; |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 422 | |
| 423 | struct Entry { |
Snild Dolkow | 9e217d6 | 2020-04-22 15:53:42 +0200 | [diff] [blame] | 424 | uint32_t layer; /* shouldn't affect the result, so we just use arbitrary values */ |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 425 | uint32_t buffer; |
| 426 | uint32_t display; |
Snild Dolkow | 9e217d6 | 2020-04-22 15:53:42 +0200 | [diff] [blame] | 427 | uint32_t internal; |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 428 | uint32_t expected; |
| 429 | }; |
Snild Dolkow | 9e217d6 | 2020-04-22 15:53:42 +0200 | [diff] [blame] | 430 | const std::array<Entry, 64> testData = { |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 431 | // clang-format off |
Snild Dolkow | 9e217d6 | 2020-04-22 15:53:42 +0200 | [diff] [blame] | 432 | // layer buffer display internal expected |
| 433 | Entry{TR_IDENT, TR_IDENT, TR_IDENT, TR_IDENT, TR_IDENT}, |
| 434 | Entry{TR_IDENT, TR_IDENT, TR_IDENT, TR_ROT_90, TR_ROT_270}, |
| 435 | Entry{TR_IDENT, TR_IDENT, TR_IDENT, TR_ROT_180, TR_ROT_180}, |
| 436 | Entry{TR_IDENT, TR_IDENT, TR_IDENT, TR_ROT_270, TR_ROT_90}, |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 437 | |
Snild Dolkow | 9e217d6 | 2020-04-22 15:53:42 +0200 | [diff] [blame] | 438 | Entry{TR_IDENT, TR_IDENT, TR_ROT_90, TR_IDENT, TR_ROT_90}, |
| 439 | Entry{TR_ROT_90, TR_IDENT, TR_ROT_90, TR_ROT_90, TR_IDENT}, |
| 440 | Entry{TR_ROT_180, TR_IDENT, TR_ROT_90, TR_ROT_180, TR_ROT_270}, |
| 441 | Entry{TR_ROT_90, TR_IDENT, TR_ROT_90, TR_ROT_270, TR_ROT_180}, |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 442 | |
Snild Dolkow | 9e217d6 | 2020-04-22 15:53:42 +0200 | [diff] [blame] | 443 | Entry{TR_ROT_180, TR_IDENT, TR_ROT_180, TR_IDENT, TR_ROT_180}, |
| 444 | Entry{TR_ROT_90, TR_IDENT, TR_ROT_180, TR_ROT_90, TR_ROT_90}, |
| 445 | Entry{TR_ROT_180, TR_IDENT, TR_ROT_180, TR_ROT_180, TR_IDENT}, |
| 446 | Entry{TR_ROT_270, TR_IDENT, TR_ROT_180, TR_ROT_270, TR_ROT_270}, |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 447 | |
Snild Dolkow | 9e217d6 | 2020-04-22 15:53:42 +0200 | [diff] [blame] | 448 | Entry{TR_ROT_270, TR_IDENT, TR_ROT_270, TR_IDENT, TR_ROT_270}, |
| 449 | Entry{TR_ROT_270, TR_IDENT, TR_ROT_270, TR_ROT_90, TR_ROT_180}, |
| 450 | Entry{TR_ROT_180, TR_IDENT, TR_ROT_270, TR_ROT_180, TR_ROT_90}, |
| 451 | Entry{TR_IDENT, TR_IDENT, TR_ROT_270, TR_ROT_270, TR_IDENT}, |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 452 | |
Snild Dolkow | 9e217d6 | 2020-04-22 15:53:42 +0200 | [diff] [blame] | 453 | // layer buffer display internal expected |
| 454 | Entry{TR_IDENT, TR_ROT_90, TR_IDENT, TR_IDENT, TR_ROT_90}, |
| 455 | Entry{TR_ROT_90, TR_ROT_90, TR_IDENT, TR_ROT_90, TR_IDENT}, |
| 456 | Entry{TR_ROT_180, TR_ROT_90, TR_IDENT, TR_ROT_180, TR_ROT_270}, |
| 457 | Entry{TR_ROT_270, TR_ROT_90, TR_IDENT, TR_ROT_270, TR_ROT_180}, |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 458 | |
Snild Dolkow | 9e217d6 | 2020-04-22 15:53:42 +0200 | [diff] [blame] | 459 | Entry{TR_ROT_90, TR_ROT_90, TR_ROT_90, TR_IDENT, TR_ROT_180}, |
| 460 | Entry{TR_ROT_90, TR_ROT_90, TR_ROT_90, TR_ROT_90, TR_ROT_90}, |
| 461 | Entry{TR_ROT_90, TR_ROT_90, TR_ROT_90, TR_ROT_180, TR_IDENT}, |
| 462 | Entry{TR_ROT_270, TR_ROT_90, TR_ROT_90, TR_ROT_270, TR_ROT_270}, |
| 463 | |
| 464 | Entry{TR_IDENT, TR_ROT_90, TR_ROT_180, TR_IDENT, TR_ROT_270}, |
| 465 | Entry{TR_ROT_90, TR_ROT_90, TR_ROT_180, TR_ROT_90, TR_ROT_180}, |
| 466 | Entry{TR_ROT_180, TR_ROT_90, TR_ROT_180, TR_ROT_180, TR_ROT_90}, |
| 467 | Entry{TR_ROT_90, TR_ROT_90, TR_ROT_180, TR_ROT_270, TR_IDENT}, |
| 468 | |
| 469 | Entry{TR_IDENT, TR_ROT_90, TR_ROT_270, TR_IDENT, TR_IDENT}, |
| 470 | Entry{TR_ROT_270, TR_ROT_90, TR_ROT_270, TR_ROT_90, TR_ROT_270}, |
| 471 | Entry{TR_ROT_180, TR_ROT_90, TR_ROT_270, TR_ROT_180, TR_ROT_180}, |
| 472 | Entry{TR_ROT_270, TR_ROT_90, TR_ROT_270, TR_ROT_270, TR_ROT_90}, |
| 473 | |
| 474 | // layer buffer display internal expected |
| 475 | Entry{TR_IDENT, TR_ROT_180, TR_IDENT, TR_IDENT, TR_ROT_180}, |
| 476 | Entry{TR_IDENT, TR_ROT_180, TR_IDENT, TR_ROT_90, TR_ROT_90}, |
| 477 | Entry{TR_ROT_180, TR_ROT_180, TR_IDENT, TR_ROT_180, TR_IDENT}, |
| 478 | Entry{TR_ROT_270, TR_ROT_180, TR_IDENT, TR_ROT_270, TR_ROT_270}, |
| 479 | |
| 480 | Entry{TR_IDENT, TR_ROT_180, TR_ROT_90, TR_IDENT, TR_ROT_270}, |
| 481 | Entry{TR_ROT_90, TR_ROT_180, TR_ROT_90, TR_ROT_90, TR_ROT_180}, |
| 482 | Entry{TR_ROT_180, TR_ROT_180, TR_ROT_90, TR_ROT_180, TR_ROT_90}, |
| 483 | Entry{TR_ROT_180, TR_ROT_180, TR_ROT_90, TR_ROT_270, TR_IDENT}, |
| 484 | |
| 485 | Entry{TR_IDENT, TR_ROT_180, TR_ROT_180, TR_IDENT, TR_IDENT}, |
| 486 | Entry{TR_ROT_180, TR_ROT_180, TR_ROT_180, TR_ROT_90, TR_ROT_270}, |
| 487 | Entry{TR_ROT_180, TR_ROT_180, TR_ROT_180, TR_ROT_180, TR_ROT_180}, |
| 488 | Entry{TR_ROT_270, TR_ROT_180, TR_ROT_180, TR_ROT_270, TR_ROT_90}, |
| 489 | |
| 490 | Entry{TR_ROT_270, TR_ROT_180, TR_ROT_270, TR_IDENT, TR_ROT_90}, |
| 491 | Entry{TR_ROT_180, TR_ROT_180, TR_ROT_270, TR_ROT_90, TR_IDENT}, |
| 492 | Entry{TR_ROT_180, TR_ROT_180, TR_ROT_270, TR_ROT_180, TR_ROT_270}, |
| 493 | Entry{TR_ROT_270, TR_ROT_180, TR_ROT_270, TR_ROT_270, TR_ROT_180}, |
| 494 | |
| 495 | // layer buffer display internal expected |
| 496 | Entry{TR_IDENT, TR_ROT_270, TR_IDENT, TR_IDENT, TR_ROT_270}, |
| 497 | Entry{TR_ROT_90, TR_ROT_270, TR_IDENT, TR_ROT_90, TR_ROT_180}, |
| 498 | Entry{TR_ROT_270, TR_ROT_270, TR_IDENT, TR_ROT_180, TR_ROT_90}, |
| 499 | Entry{TR_IDENT, TR_ROT_270, TR_IDENT, TR_ROT_270, TR_IDENT}, |
| 500 | |
| 501 | Entry{TR_ROT_270, TR_ROT_270, TR_ROT_90, TR_IDENT, TR_IDENT}, |
| 502 | Entry{TR_ROT_90, TR_ROT_270, TR_ROT_90, TR_ROT_90, TR_ROT_270}, |
| 503 | Entry{TR_ROT_180, TR_ROT_270, TR_ROT_90, TR_ROT_180, TR_ROT_180}, |
| 504 | Entry{TR_ROT_90, TR_ROT_270, TR_ROT_90, TR_ROT_270, TR_ROT_90}, |
| 505 | |
| 506 | Entry{TR_IDENT, TR_ROT_270, TR_ROT_180, TR_IDENT, TR_ROT_90}, |
| 507 | Entry{TR_ROT_270, TR_ROT_270, TR_ROT_180, TR_ROT_90, TR_IDENT}, |
| 508 | Entry{TR_ROT_180, TR_ROT_270, TR_ROT_180, TR_ROT_180, TR_ROT_270}, |
| 509 | Entry{TR_ROT_270, TR_ROT_270, TR_ROT_180, TR_ROT_270, TR_ROT_180}, |
| 510 | |
| 511 | Entry{TR_IDENT, TR_ROT_270, TR_ROT_270, TR_IDENT, TR_ROT_180}, |
| 512 | Entry{TR_ROT_90, TR_ROT_270, TR_ROT_270, TR_ROT_90, TR_ROT_90}, |
| 513 | Entry{TR_ROT_270, TR_ROT_270, TR_ROT_270, TR_ROT_180, TR_IDENT}, |
| 514 | Entry{TR_ROT_270, TR_ROT_270, TR_ROT_270, TR_ROT_270, TR_ROT_270}, |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 515 | // clang-format on |
| 516 | }; |
| 517 | |
| 518 | for (size_t i = 0; i < testData.size(); i++) { |
| 519 | const auto& entry = testData[i]; |
| 520 | |
Snild Dolkow | 9e217d6 | 2020-04-22 15:53:42 +0200 | [diff] [blame] | 521 | mLayerFEState.geomLayerTransform.set(entry.layer, 1920, 1080); |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 522 | mLayerFEState.geomBufferTransform = entry.buffer; |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 523 | mOutputState.displaySpace.setOrientation(toRotation(entry.display)); |
Rashed Abdel-Tawab | 6643cd8 | 2019-10-29 10:01:56 -0700 | [diff] [blame] | 524 | mOutputState.transform = ui::Transform{entry.display}; |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 525 | |
Snild Dolkow | 9e217d6 | 2020-04-22 15:53:42 +0200 | [diff] [blame] | 526 | const auto actual = mOutputLayer.calculateOutputRelativeBufferTransform(entry.internal); |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 527 | EXPECT_EQ(entry.expected, actual) << "entry " << i; |
| 528 | } |
| 529 | } |
| 530 | |
| 531 | /* |
| 532 | * OutputLayer::updateCompositionState() |
| 533 | */ |
| 534 | |
| 535 | struct OutputLayerPartialMockForUpdateCompositionState : public impl::OutputLayer { |
| 536 | OutputLayerPartialMockForUpdateCompositionState(const compositionengine::Output& output, |
Brian Lindahl | 90553da | 2022-12-06 13:36:30 -0700 | [diff] [blame] | 537 | compositionengine::LayerFE& layerFE) |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 538 | : mOutput(output), mLayerFE(layerFE) {} |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 539 | // Mock everything called by updateCompositionState to simplify testing it. |
ramindani | 2c043be | 2022-04-19 20:11:10 +0000 | [diff] [blame] | 540 | MOCK_CONST_METHOD1(calculateOutputSourceCrop, FloatRect(uint32_t)); |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 541 | MOCK_CONST_METHOD0(calculateOutputDisplayFrame, Rect()); |
Snild Dolkow | 9e217d6 | 2020-04-22 15:53:42 +0200 | [diff] [blame] | 542 | MOCK_CONST_METHOD1(calculateOutputRelativeBufferTransform, uint32_t(uint32_t)); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 543 | |
| 544 | // compositionengine::OutputLayer overrides |
| 545 | const compositionengine::Output& getOutput() const override { return mOutput; } |
Brian Lindahl | 90553da | 2022-12-06 13:36:30 -0700 | [diff] [blame] | 546 | compositionengine::LayerFE& getLayerFE() const override { return mLayerFE; } |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 547 | const impl::OutputLayerCompositionState& getState() const override { return mState; } |
| 548 | impl::OutputLayerCompositionState& editState() override { return mState; } |
| 549 | |
| 550 | // These need implementations though are not expected to be called. |
| 551 | MOCK_CONST_METHOD1(dumpState, void(std::string&)); |
| 552 | |
| 553 | const compositionengine::Output& mOutput; |
Brian Lindahl | 90553da | 2022-12-06 13:36:30 -0700 | [diff] [blame] | 554 | compositionengine::LayerFE& mLayerFE; |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 555 | impl::OutputLayerCompositionState mState; |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 556 | }; |
| 557 | |
| 558 | struct OutputLayerUpdateCompositionStateTest : public OutputLayerTest { |
| 559 | public: |
| 560 | OutputLayerUpdateCompositionStateTest() { |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 561 | EXPECT_CALL(mOutput, getState()).WillRepeatedly(ReturnRef(mOutputState)); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 562 | EXPECT_CALL(mOutput, getDisplayColorProfile()) |
| 563 | .WillRepeatedly(Return(&mDisplayColorProfile)); |
| 564 | EXPECT_CALL(mDisplayColorProfile, isDataspaceSupported(_)).WillRepeatedly(Return(true)); |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 565 | } |
| 566 | |
| 567 | ~OutputLayerUpdateCompositionStateTest() = default; |
| 568 | |
Snild Dolkow | 9e217d6 | 2020-04-22 15:53:42 +0200 | [diff] [blame] | 569 | void setupGeometryChildCallValues(ui::Transform::RotationFlags internalDisplayRotationFlags) { |
ramindani | 2c043be | 2022-04-19 20:11:10 +0000 | [diff] [blame] | 570 | EXPECT_CALL(mOutputLayer, calculateOutputSourceCrop(internalDisplayRotationFlags)) |
| 571 | .WillOnce(Return(kSourceCrop)); |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 572 | EXPECT_CALL(mOutputLayer, calculateOutputDisplayFrame()).WillOnce(Return(kDisplayFrame)); |
Snild Dolkow | 9e217d6 | 2020-04-22 15:53:42 +0200 | [diff] [blame] | 573 | EXPECT_CALL(mOutputLayer, |
| 574 | calculateOutputRelativeBufferTransform(internalDisplayRotationFlags)) |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 575 | .WillOnce(Return(mBufferTransform)); |
| 576 | } |
| 577 | |
| 578 | void validateComputedGeometryState() { |
| 579 | const auto& state = mOutputLayer.getState(); |
| 580 | EXPECT_EQ(kSourceCrop, state.sourceCrop); |
| 581 | EXPECT_EQ(kDisplayFrame, state.displayFrame); |
| 582 | EXPECT_EQ(static_cast<Hwc2::Transform>(mBufferTransform), state.bufferTransform); |
| 583 | } |
| 584 | |
| 585 | const FloatRect kSourceCrop{1.f, 2.f, 3.f, 4.f}; |
| 586 | const Rect kDisplayFrame{11, 12, 13, 14}; |
| 587 | uint32_t mBufferTransform{21}; |
| 588 | |
| 589 | using OutputLayer = OutputLayerPartialMockForUpdateCompositionState; |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 590 | StrictMock<OutputLayer> mOutputLayer{mOutput, mLayerFE}; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 591 | StrictMock<mock::DisplayColorProfile> mDisplayColorProfile; |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 592 | }; |
| 593 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 594 | TEST_F(OutputLayerUpdateCompositionStateTest, doesNothingIfNoFECompositionState) { |
Brian Lindahl | 90553da | 2022-12-06 13:36:30 -0700 | [diff] [blame] | 595 | EXPECT_CALL(mLayerFE, getCompositionState()).WillOnce(Return(nullptr)); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 596 | |
Snild Dolkow | 9e217d6 | 2020-04-22 15:53:42 +0200 | [diff] [blame] | 597 | mOutputLayer.updateCompositionState(true, false, ui::Transform::RotationFlags::ROT_90); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 598 | } |
| 599 | |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 600 | TEST_F(OutputLayerUpdateCompositionStateTest, setsStateNormally) { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 601 | mLayerFEState.isSecure = true; |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 602 | mOutputState.isSecure = true; |
Lloyd Pique | fe67102 | 2019-09-24 10:43:03 -0700 | [diff] [blame] | 603 | mOutputLayer.editState().forceClientComposition = true; |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 604 | |
Snild Dolkow | 9e217d6 | 2020-04-22 15:53:42 +0200 | [diff] [blame] | 605 | setupGeometryChildCallValues(ui::Transform::RotationFlags::ROT_90); |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 606 | |
Snild Dolkow | 9e217d6 | 2020-04-22 15:53:42 +0200 | [diff] [blame] | 607 | mOutputLayer.updateCompositionState(true, false, ui::Transform::RotationFlags::ROT_90); |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 608 | |
| 609 | validateComputedGeometryState(); |
| 610 | |
| 611 | EXPECT_EQ(false, mOutputLayer.getState().forceClientComposition); |
| 612 | } |
| 613 | |
| 614 | TEST_F(OutputLayerUpdateCompositionStateTest, |
| 615 | alsoSetsForceCompositionIfSecureLayerOnNonsecureOutput) { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 616 | mLayerFEState.isSecure = true; |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 617 | mOutputState.isSecure = false; |
| 618 | |
Snild Dolkow | 9e217d6 | 2020-04-22 15:53:42 +0200 | [diff] [blame] | 619 | setupGeometryChildCallValues(ui::Transform::RotationFlags::ROT_0); |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 620 | |
Snild Dolkow | 9e217d6 | 2020-04-22 15:53:42 +0200 | [diff] [blame] | 621 | mOutputLayer.updateCompositionState(true, false, ui::Transform::RotationFlags::ROT_0); |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 622 | |
| 623 | validateComputedGeometryState(); |
| 624 | |
| 625 | EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition); |
| 626 | } |
| 627 | |
| 628 | TEST_F(OutputLayerUpdateCompositionStateTest, |
| 629 | alsoSetsForceCompositionIfUnsupportedBufferTransform) { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 630 | mLayerFEState.isSecure = true; |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 631 | mOutputState.isSecure = true; |
| 632 | |
| 633 | mBufferTransform = ui::Transform::ROT_INVALID; |
| 634 | |
Snild Dolkow | 9e217d6 | 2020-04-22 15:53:42 +0200 | [diff] [blame] | 635 | setupGeometryChildCallValues(ui::Transform::RotationFlags::ROT_0); |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 636 | |
Snild Dolkow | 9e217d6 | 2020-04-22 15:53:42 +0200 | [diff] [blame] | 637 | mOutputLayer.updateCompositionState(true, false, ui::Transform::RotationFlags::ROT_0); |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 638 | |
| 639 | validateComputedGeometryState(); |
| 640 | |
| 641 | EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition); |
| 642 | } |
| 643 | |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 644 | TEST_F(OutputLayerUpdateCompositionStateTest, setsOutputLayerColorspaceCorrectly) { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 645 | mLayerFEState.dataspace = ui::Dataspace::DISPLAY_P3; |
Alec Mouri | 88790f3 | 2023-07-21 01:25:14 +0000 | [diff] [blame] | 646 | mOutputState.dataspace = ui::Dataspace::V0_SCRGB; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 647 | |
| 648 | // If the layer is not colorspace agnostic, the output layer dataspace |
| 649 | // should use the layers requested colorspace. |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 650 | mLayerFEState.isColorspaceAgnostic = false; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 651 | |
Snild Dolkow | 9e217d6 | 2020-04-22 15:53:42 +0200 | [diff] [blame] | 652 | mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 653 | |
| 654 | EXPECT_EQ(ui::Dataspace::DISPLAY_P3, mOutputLayer.getState().dataspace); |
| 655 | |
| 656 | // If the layer is colorspace agnostic, the output layer dataspace |
| 657 | // should use the colorspace chosen for the whole output. |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 658 | mLayerFEState.isColorspaceAgnostic = true; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 659 | |
Snild Dolkow | 9e217d6 | 2020-04-22 15:53:42 +0200 | [diff] [blame] | 660 | mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 661 | |
| 662 | EXPECT_EQ(ui::Dataspace::V0_SCRGB, mOutputLayer.getState().dataspace); |
Alec Mouri | 88790f3 | 2023-07-21 01:25:14 +0000 | [diff] [blame] | 663 | |
| 664 | // If the output is HDR, then don't blind the user with a colorspace agnostic dataspace |
| 665 | // drawing all white |
| 666 | mOutputState.dataspace = ui::Dataspace::BT2020_PQ; |
| 667 | |
| 668 | mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0); |
| 669 | |
| 670 | EXPECT_EQ(ui::Dataspace::DISPLAY_P3, mOutputLayer.getState().dataspace); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 671 | } |
| 672 | |
Alec Mouri | dda07d9 | 2022-04-25 22:39:25 +0000 | [diff] [blame] | 673 | TEST_F(OutputLayerUpdateCompositionStateTest, setsOutputLayerColorspaceWith170mReplacement) { |
| 674 | mLayerFEState.dataspace = ui::Dataspace::TRANSFER_SMPTE_170M; |
Alec Mouri | dda07d9 | 2022-04-25 22:39:25 +0000 | [diff] [blame] | 675 | mOutputState.treat170mAsSrgb = false; |
| 676 | mLayerFEState.isColorspaceAgnostic = false; |
| 677 | |
| 678 | mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0); |
| 679 | |
| 680 | EXPECT_EQ(ui::Dataspace::TRANSFER_SMPTE_170M, mOutputLayer.getState().dataspace); |
| 681 | |
| 682 | // Rewrite SMPTE 170M as sRGB |
| 683 | mOutputState.treat170mAsSrgb = true; |
| 684 | mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0); |
| 685 | |
| 686 | EXPECT_EQ(ui::Dataspace::TRANSFER_SRGB, mOutputLayer.getState().dataspace); |
| 687 | } |
| 688 | |
Alec Mouri | e8dd356 | 2022-02-11 14:18:57 -0800 | [diff] [blame] | 689 | TEST_F(OutputLayerUpdateCompositionStateTest, setsWhitePointNitsAndDimmingRatioCorrectly) { |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 690 | mOutputState.sdrWhitePointNits = 200.f; |
| 691 | mOutputState.displayBrightnessNits = 800.f; |
| 692 | |
| 693 | mLayerFEState.dataspace = ui::Dataspace::DISPLAY_P3; |
| 694 | mLayerFEState.isColorspaceAgnostic = false; |
| 695 | mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0); |
| 696 | EXPECT_EQ(mOutputState.sdrWhitePointNits, mOutputLayer.getState().whitePointNits); |
Alec Mouri | e8dd356 | 2022-02-11 14:18:57 -0800 | [diff] [blame] | 697 | EXPECT_EQ(mOutputState.sdrWhitePointNits / mOutputState.displayBrightnessNits, |
| 698 | mOutputLayer.getState().dimmingRatio); |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 699 | |
Sally Qi | 81d95e6 | 2022-03-21 19:41:33 -0700 | [diff] [blame] | 700 | mLayerFEState.dimmingEnabled = false; |
| 701 | mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0); |
| 702 | EXPECT_EQ(mOutputState.displayBrightnessNits, mOutputLayer.getState().whitePointNits); |
| 703 | EXPECT_EQ(1.f, mOutputLayer.getState().dimmingRatio); |
| 704 | |
| 705 | // change dimmingEnabled back to true. |
| 706 | mLayerFEState.dimmingEnabled = true; |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 707 | mLayerFEState.dataspace = ui::Dataspace::BT2020_ITU_PQ; |
| 708 | mLayerFEState.isColorspaceAgnostic = false; |
| 709 | mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0); |
| 710 | |
| 711 | EXPECT_EQ(mOutputState.displayBrightnessNits, mOutputLayer.getState().whitePointNits); |
Alec Mouri | e8dd356 | 2022-02-11 14:18:57 -0800 | [diff] [blame] | 712 | EXPECT_EQ(1.f, mOutputLayer.getState().dimmingRatio); |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 713 | } |
| 714 | |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 715 | TEST_F(OutputLayerUpdateCompositionStateTest, doesNotRecomputeGeometryIfNotRequested) { |
Lloyd Pique | fe67102 | 2019-09-24 10:43:03 -0700 | [diff] [blame] | 716 | mOutputLayer.editState().forceClientComposition = false; |
| 717 | |
Snild Dolkow | 9e217d6 | 2020-04-22 15:53:42 +0200 | [diff] [blame] | 718 | mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0); |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 719 | |
| 720 | EXPECT_EQ(false, mOutputLayer.getState().forceClientComposition); |
| 721 | } |
| 722 | |
Lloyd Pique | fe67102 | 2019-09-24 10:43:03 -0700 | [diff] [blame] | 723 | TEST_F(OutputLayerUpdateCompositionStateTest, |
| 724 | doesNotClearForceClientCompositionIfNotDoingGeometry) { |
| 725 | mOutputLayer.editState().forceClientComposition = true; |
| 726 | |
Snild Dolkow | 9e217d6 | 2020-04-22 15:53:42 +0200 | [diff] [blame] | 727 | mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0); |
Lloyd Pique | fe67102 | 2019-09-24 10:43:03 -0700 | [diff] [blame] | 728 | |
| 729 | EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition); |
| 730 | } |
| 731 | |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 732 | TEST_F(OutputLayerUpdateCompositionStateTest, clientCompositionForcedFromFrontEndFlagAtAnyTime) { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 733 | mLayerFEState.forceClientComposition = true; |
Lloyd Pique | fe67102 | 2019-09-24 10:43:03 -0700 | [diff] [blame] | 734 | mOutputLayer.editState().forceClientComposition = false; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 735 | |
Snild Dolkow | 9e217d6 | 2020-04-22 15:53:42 +0200 | [diff] [blame] | 736 | mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 737 | |
| 738 | EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition); |
| 739 | } |
| 740 | |
| 741 | TEST_F(OutputLayerUpdateCompositionStateTest, |
| 742 | clientCompositionForcedFromUnsupportedDataspaceAtAnyTime) { |
Lloyd Pique | fe67102 | 2019-09-24 10:43:03 -0700 | [diff] [blame] | 743 | mOutputLayer.editState().forceClientComposition = false; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 744 | EXPECT_CALL(mDisplayColorProfile, isDataspaceSupported(_)).WillRepeatedly(Return(false)); |
| 745 | |
Snild Dolkow | 9e217d6 | 2020-04-22 15:53:42 +0200 | [diff] [blame] | 746 | mOutputLayer.updateCompositionState(false, false, ui::Transform::RotationFlags::ROT_0); |
Lloyd Pique | 7a23491 | 2019-10-03 11:54:27 -0700 | [diff] [blame] | 747 | |
| 748 | EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition); |
| 749 | } |
| 750 | |
| 751 | TEST_F(OutputLayerUpdateCompositionStateTest, clientCompositionForcedFromArgumentFlag) { |
| 752 | mLayerFEState.forceClientComposition = false; |
| 753 | mOutputLayer.editState().forceClientComposition = false; |
| 754 | |
Snild Dolkow | 9e217d6 | 2020-04-22 15:53:42 +0200 | [diff] [blame] | 755 | mOutputLayer.updateCompositionState(false, true, ui::Transform::RotationFlags::ROT_0); |
Lloyd Pique | 7a23491 | 2019-10-03 11:54:27 -0700 | [diff] [blame] | 756 | |
| 757 | EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition); |
| 758 | |
| 759 | mOutputLayer.editState().forceClientComposition = false; |
| 760 | |
Snild Dolkow | 9e217d6 | 2020-04-22 15:53:42 +0200 | [diff] [blame] | 761 | setupGeometryChildCallValues(ui::Transform::RotationFlags::ROT_0); |
Lloyd Pique | 7a23491 | 2019-10-03 11:54:27 -0700 | [diff] [blame] | 762 | |
Snild Dolkow | 9e217d6 | 2020-04-22 15:53:42 +0200 | [diff] [blame] | 763 | mOutputLayer.updateCompositionState(true, true, ui::Transform::RotationFlags::ROT_0); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 764 | |
| 765 | EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition); |
| 766 | } |
| 767 | |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 768 | /* |
| 769 | * OutputLayer::writeStateToHWC() |
| 770 | */ |
| 771 | |
| 772 | struct OutputLayerWriteStateToHWCTest : public OutputLayerTest { |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 773 | static constexpr hal::Error kError = hal::Error::UNSUPPORTED; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 774 | static constexpr FloatRect kSourceCrop{11.f, 12.f, 13.f, 14.f}; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 775 | static constexpr Hwc2::Transform kBufferTransform = static_cast<Hwc2::Transform>(31); |
Alec Mouri | 7be6c0a | 2021-03-19 15:22:01 -0700 | [diff] [blame] | 776 | static constexpr Hwc2::Transform kOverrideBufferTransform = static_cast<Hwc2::Transform>(0); |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 777 | static constexpr Hwc2::IComposerClient::BlendMode kBlendMode = |
| 778 | static_cast<Hwc2::IComposerClient::BlendMode>(41); |
Alec Mouri | ee69a59 | 2021-03-23 15:00:45 -0700 | [diff] [blame] | 779 | static constexpr Hwc2::IComposerClient::BlendMode kOverrideBlendMode = |
| 780 | Hwc2::IComposerClient::BlendMode::PREMULTIPLIED; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 781 | static constexpr float kAlpha = 51.f; |
Alec Mouri | ee69a59 | 2021-03-23 15:00:45 -0700 | [diff] [blame] | 782 | static constexpr float kOverrideAlpha = 1.f; |
Alec Mouri | 96ca45c | 2021-06-09 17:32:26 -0700 | [diff] [blame] | 783 | static constexpr float kSkipAlpha = 0.f; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 784 | static constexpr ui::Dataspace kDataspace = static_cast<ui::Dataspace>(71); |
Alec Mouri | b7edfc2 | 2021-03-17 16:20:26 -0700 | [diff] [blame] | 785 | static constexpr ui::Dataspace kOverrideDataspace = static_cast<ui::Dataspace>(72); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 786 | static constexpr int kSupportedPerFrameMetadata = 101; |
| 787 | static constexpr int kExpectedHwcSlot = 0; |
Brian Lindahl | 439afad | 2022-11-14 11:16:55 -0700 | [diff] [blame] | 788 | static constexpr int kOverrideHwcSlot = impl::HwcBufferCache::kOverrideBufferSlot; |
Lloyd Pique | 8d9f836 | 2020-02-11 19:13:09 -0800 | [diff] [blame] | 789 | static constexpr bool kLayerGenericMetadata1Mandatory = true; |
| 790 | static constexpr bool kLayerGenericMetadata2Mandatory = true; |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 791 | static constexpr float kWhitePointNits = 200.f; |
Alec Mouri | e8dd356 | 2022-02-11 14:18:57 -0800 | [diff] [blame] | 792 | static constexpr float kSdrWhitePointNits = 100.f; |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 793 | static constexpr float kDisplayBrightnessNits = 400.f; |
Alec Mouri | 6da0e27 | 2022-02-07 12:45:57 -0800 | [diff] [blame] | 794 | static constexpr float kLayerBrightness = kWhitePointNits / kDisplayBrightnessNits; |
Alec Mouri | e8dd356 | 2022-02-11 14:18:57 -0800 | [diff] [blame] | 795 | static constexpr float kOverrideLayerBrightness = kSdrWhitePointNits / kDisplayBrightnessNits; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 796 | |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 797 | static const half4 kColor; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 798 | static const Rect kDisplayFrame; |
Alec Mouri | b7edfc2 | 2021-03-17 16:20:26 -0700 | [diff] [blame] | 799 | static const Rect kOverrideDisplayFrame; |
Alec Mouri | 03bf0ff | 2021-04-19 14:17:31 -0700 | [diff] [blame] | 800 | static const FloatRect kOverrideSourceCrop; |
Lloyd Pique | a246866 | 2019-03-07 21:31:06 -0800 | [diff] [blame] | 801 | static const Region kOutputSpaceVisibleRegion; |
Alec Mouri | 464352b | 2021-03-24 16:33:21 -0700 | [diff] [blame] | 802 | static const Region kOverrideVisibleRegion; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 803 | static const mat4 kColorTransform; |
| 804 | static const Region kSurfaceDamage; |
Alec Mouri | 464352b | 2021-03-24 16:33:21 -0700 | [diff] [blame] | 805 | static const Region kOverrideSurfaceDamage; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 806 | static const HdrMetadata kHdrMetadata; |
| 807 | static native_handle_t* kSidebandStreamHandle; |
| 808 | static const sp<GraphicBuffer> kBuffer; |
Alec Mouri | 03bf0ff | 2021-04-19 14:17:31 -0700 | [diff] [blame] | 809 | static const sp<GraphicBuffer> kOverrideBuffer; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 810 | static const sp<Fence> kFence; |
Alec Mouri | b7edfc2 | 2021-03-17 16:20:26 -0700 | [diff] [blame] | 811 | static const sp<Fence> kOverrideFence; |
Lloyd Pique | 8d9f836 | 2020-02-11 19:13:09 -0800 | [diff] [blame] | 812 | static const std::string kLayerGenericMetadata1Key; |
| 813 | static const std::vector<uint8_t> kLayerGenericMetadata1Value; |
| 814 | static const std::string kLayerGenericMetadata2Key; |
| 815 | static const std::vector<uint8_t> kLayerGenericMetadata2Value; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 816 | |
| 817 | OutputLayerWriteStateToHWCTest() { |
| 818 | auto& outputLayerState = mOutputLayer.editState(); |
| 819 | outputLayerState.hwc = impl::OutputLayerCompositionState::Hwc(mHwcLayer); |
| 820 | |
| 821 | outputLayerState.displayFrame = kDisplayFrame; |
| 822 | outputLayerState.sourceCrop = kSourceCrop; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 823 | outputLayerState.bufferTransform = static_cast<Hwc2::Transform>(kBufferTransform); |
Lloyd Pique | a246866 | 2019-03-07 21:31:06 -0800 | [diff] [blame] | 824 | outputLayerState.outputSpaceVisibleRegion = kOutputSpaceVisibleRegion; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 825 | outputLayerState.dataspace = kDataspace; |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 826 | outputLayerState.whitePointNits = kWhitePointNits; |
Alec Mouri | 6da0e27 | 2022-02-07 12:45:57 -0800 | [diff] [blame] | 827 | outputLayerState.dimmingRatio = kLayerBrightness; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 828 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 829 | mLayerFEState.blendMode = kBlendMode; |
| 830 | mLayerFEState.alpha = kAlpha; |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 831 | mLayerFEState.colorTransform = kColorTransform; |
| 832 | mLayerFEState.color = kColor; |
| 833 | mLayerFEState.surfaceDamage = kSurfaceDamage; |
| 834 | mLayerFEState.hdrMetadata = kHdrMetadata; |
| 835 | mLayerFEState.sidebandStream = NativeHandle::create(kSidebandStreamHandle, false); |
| 836 | mLayerFEState.buffer = kBuffer; |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 837 | mLayerFEState.acquireFence = kFence; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 838 | |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 839 | mOutputState.displayBrightnessNits = kDisplayBrightnessNits; |
Alec Mouri | e8dd356 | 2022-02-11 14:18:57 -0800 | [diff] [blame] | 840 | mOutputState.sdrWhitePointNits = kSdrWhitePointNits; |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 841 | |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 842 | EXPECT_CALL(mOutput, getDisplayColorProfile()) |
| 843 | .WillRepeatedly(Return(&mDisplayColorProfile)); |
| 844 | EXPECT_CALL(mDisplayColorProfile, getSupportedPerFrameMetadata()) |
| 845 | .WillRepeatedly(Return(kSupportedPerFrameMetadata)); |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 846 | } |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 847 | // Some tests may need to simulate unsupported HWC calls |
| 848 | enum class SimulateUnsupported { None, ColorTransform }; |
| 849 | |
Lloyd Pique | 8d9f836 | 2020-02-11 19:13:09 -0800 | [diff] [blame] | 850 | void includeGenericLayerMetadataInState() { |
| 851 | mLayerFEState.metadata[kLayerGenericMetadata1Key] = {kLayerGenericMetadata1Mandatory, |
| 852 | kLayerGenericMetadata1Value}; |
| 853 | mLayerFEState.metadata[kLayerGenericMetadata2Key] = {kLayerGenericMetadata2Mandatory, |
| 854 | kLayerGenericMetadata2Value}; |
| 855 | } |
| 856 | |
Alec Mouri | b7edfc2 | 2021-03-17 16:20:26 -0700 | [diff] [blame] | 857 | void includeOverrideInfo() { |
| 858 | auto& overrideInfo = mOutputLayer.editState().overrideInfo; |
| 859 | |
Alec Mouri | 03bf0ff | 2021-04-19 14:17:31 -0700 | [diff] [blame] | 860 | overrideInfo.buffer = std::make_shared< |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 861 | renderengine::impl::ExternalTexture>(kOverrideBuffer, mRenderEngine, |
| 862 | renderengine::impl::ExternalTexture::Usage:: |
| 863 | READABLE | |
| 864 | renderengine::impl::ExternalTexture:: |
| 865 | Usage::WRITEABLE); |
Alec Mouri | b7edfc2 | 2021-03-17 16:20:26 -0700 | [diff] [blame] | 866 | overrideInfo.acquireFence = kOverrideFence; |
| 867 | overrideInfo.displayFrame = kOverrideDisplayFrame; |
| 868 | overrideInfo.dataspace = kOverrideDataspace; |
Alec Mouri | 464352b | 2021-03-24 16:33:21 -0700 | [diff] [blame] | 869 | overrideInfo.damageRegion = kOverrideSurfaceDamage; |
| 870 | overrideInfo.visibleRegion = kOverrideVisibleRegion; |
Alec Mouri | b7edfc2 | 2021-03-17 16:20:26 -0700 | [diff] [blame] | 871 | } |
| 872 | |
| 873 | void expectGeometryCommonCalls(Rect displayFrame = kDisplayFrame, |
Alec Mouri | 7be6c0a | 2021-03-19 15:22:01 -0700 | [diff] [blame] | 874 | FloatRect sourceCrop = kSourceCrop, |
Alec Mouri | ee69a59 | 2021-03-23 15:00:45 -0700 | [diff] [blame] | 875 | Hwc2::Transform bufferTransform = kBufferTransform, |
| 876 | Hwc2::IComposerClient::BlendMode blendMode = kBlendMode, |
| 877 | float alpha = kAlpha) { |
Alec Mouri | b7edfc2 | 2021-03-17 16:20:26 -0700 | [diff] [blame] | 878 | EXPECT_CALL(*mHwcLayer, setDisplayFrame(displayFrame)).WillOnce(Return(kError)); |
| 879 | EXPECT_CALL(*mHwcLayer, setSourceCrop(sourceCrop)).WillOnce(Return(kError)); |
Leon Scroggins III | e2ee040 | 2021-04-02 16:59:37 -0400 | [diff] [blame] | 880 | EXPECT_CALL(*mHwcLayer, setZOrder(_)).WillOnce(Return(kError)); |
Alec Mouri | 7be6c0a | 2021-03-19 15:22:01 -0700 | [diff] [blame] | 881 | EXPECT_CALL(*mHwcLayer, setTransform(bufferTransform)).WillOnce(Return(kError)); |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 882 | |
Alec Mouri | ee69a59 | 2021-03-23 15:00:45 -0700 | [diff] [blame] | 883 | EXPECT_CALL(*mHwcLayer, setBlendMode(blendMode)).WillOnce(Return(kError)); |
| 884 | EXPECT_CALL(*mHwcLayer, setPlaneAlpha(alpha)).WillOnce(Return(kError)); |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 885 | } |
| 886 | |
Alec Mouri | b7edfc2 | 2021-03-17 16:20:26 -0700 | [diff] [blame] | 887 | void expectPerFrameCommonCalls(SimulateUnsupported unsupported = SimulateUnsupported::None, |
Alec Mouri | 464352b | 2021-03-24 16:33:21 -0700 | [diff] [blame] | 888 | ui::Dataspace dataspace = kDataspace, |
| 889 | const Region& visibleRegion = kOutputSpaceVisibleRegion, |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 890 | const Region& surfaceDamage = kSurfaceDamage, |
Alec Mouri | 6da0e27 | 2022-02-07 12:45:57 -0800 | [diff] [blame] | 891 | float brightness = kLayerBrightness, |
Leon Scroggins III | 9a0afda | 2022-01-11 16:53:09 -0500 | [diff] [blame] | 892 | const Region& blockingRegion = Region()) { |
Alec Mouri | 464352b | 2021-03-24 16:33:21 -0700 | [diff] [blame] | 893 | EXPECT_CALL(*mHwcLayer, setVisibleRegion(RegionEq(visibleRegion))).WillOnce(Return(kError)); |
Alec Mouri | b7edfc2 | 2021-03-17 16:20:26 -0700 | [diff] [blame] | 894 | EXPECT_CALL(*mHwcLayer, setDataspace(dataspace)).WillOnce(Return(kError)); |
Alec Mouri | 6da0e27 | 2022-02-07 12:45:57 -0800 | [diff] [blame] | 895 | EXPECT_CALL(*mHwcLayer, setBrightness(brightness)).WillOnce(Return(kError)); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 896 | EXPECT_CALL(*mHwcLayer, setColorTransform(kColorTransform)) |
| 897 | .WillOnce(Return(unsupported == SimulateUnsupported::ColorTransform |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 898 | ? hal::Error::UNSUPPORTED |
| 899 | : hal::Error::NONE)); |
Alec Mouri | 464352b | 2021-03-24 16:33:21 -0700 | [diff] [blame] | 900 | EXPECT_CALL(*mHwcLayer, setSurfaceDamage(RegionEq(surfaceDamage))).WillOnce(Return(kError)); |
Leon Scroggins III | 9a0afda | 2022-01-11 16:53:09 -0500 | [diff] [blame] | 901 | EXPECT_CALL(*mHwcLayer, setBlockingRegion(RegionEq(blockingRegion))) |
| 902 | .WillOnce(Return(kError)); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 903 | } |
| 904 | |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 905 | void expectSetCompositionTypeCall(Composition compositionType) { |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 906 | EXPECT_CALL(*mHwcLayer, setCompositionType(compositionType)).WillOnce(Return(kError)); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 907 | } |
| 908 | |
| 909 | void expectNoSetCompositionTypeCall() { |
| 910 | EXPECT_CALL(*mHwcLayer, setCompositionType(_)).Times(0); |
| 911 | } |
| 912 | |
| 913 | void expectSetColorCall() { |
Ady Abraham | 6e60b14 | 2022-01-06 18:10:35 -0800 | [diff] [blame] | 914 | const aidl::android::hardware::graphics::composer3::Color color = {kColor.r, kColor.g, |
| 915 | kColor.b, 1.0f}; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 916 | |
| 917 | EXPECT_CALL(*mHwcLayer, setColor(ColorEq(color))).WillOnce(Return(kError)); |
| 918 | } |
| 919 | |
| 920 | void expectSetSidebandHandleCall() { |
| 921 | EXPECT_CALL(*mHwcLayer, setSidebandStream(kSidebandStreamHandle)); |
| 922 | } |
| 923 | |
Alec Mouri | e7cc1c2 | 2021-04-27 15:23:26 -0700 | [diff] [blame] | 924 | void expectSetHdrMetadataAndBufferCalls(uint32_t hwcSlot = kExpectedHwcSlot, |
| 925 | sp<GraphicBuffer> buffer = kBuffer, |
Alec Mouri | b7edfc2 | 2021-03-17 16:20:26 -0700 | [diff] [blame] | 926 | sp<Fence> fence = kFence) { |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 927 | EXPECT_CALL(*mHwcLayer, setPerFrameMetadata(kSupportedPerFrameMetadata, kHdrMetadata)); |
Alec Mouri | e7cc1c2 | 2021-04-27 15:23:26 -0700 | [diff] [blame] | 928 | EXPECT_CALL(*mHwcLayer, setBuffer(hwcSlot, buffer, fence)); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 929 | } |
| 930 | |
Lloyd Pique | 8d9f836 | 2020-02-11 19:13:09 -0800 | [diff] [blame] | 931 | void expectGenericLayerMetadataCalls() { |
| 932 | // Note: Can be in any order. |
| 933 | EXPECT_CALL(*mHwcLayer, |
| 934 | setLayerGenericMetadata(kLayerGenericMetadata1Key, |
| 935 | kLayerGenericMetadata1Mandatory, |
| 936 | kLayerGenericMetadata1Value)); |
| 937 | EXPECT_CALL(*mHwcLayer, |
| 938 | setLayerGenericMetadata(kLayerGenericMetadata2Key, |
| 939 | kLayerGenericMetadata2Mandatory, |
| 940 | kLayerGenericMetadata2Value)); |
| 941 | } |
| 942 | |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 943 | std::shared_ptr<HWC2::mock::Layer> mHwcLayer{std::make_shared<StrictMock<HWC2::mock::Layer>>()}; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 944 | StrictMock<mock::DisplayColorProfile> mDisplayColorProfile; |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 945 | renderengine::mock::RenderEngine mRenderEngine; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 946 | }; |
| 947 | |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 948 | const half4 OutputLayerWriteStateToHWCTest::kColor{81.f / 255.f, 82.f / 255.f, 83.f / 255.f, |
| 949 | 84.f / 255.f}; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 950 | const Rect OutputLayerWriteStateToHWCTest::kDisplayFrame{1001, 1002, 1003, 10044}; |
Alec Mouri | b7edfc2 | 2021-03-17 16:20:26 -0700 | [diff] [blame] | 951 | const Rect OutputLayerWriteStateToHWCTest::kOverrideDisplayFrame{1002, 1003, 1004, 20044}; |
Wiwit Rifa'i | 50abed0 | 2022-05-24 02:24:33 +0000 | [diff] [blame] | 952 | const FloatRect OutputLayerWriteStateToHWCTest::kOverrideSourceCrop{0.f, 0.f, 4.f, 5.f}; |
Lloyd Pique | a246866 | 2019-03-07 21:31:06 -0800 | [diff] [blame] | 953 | const Region OutputLayerWriteStateToHWCTest::kOutputSpaceVisibleRegion{ |
| 954 | Rect{1005, 1006, 1007, 1008}}; |
Alec Mouri | 464352b | 2021-03-24 16:33:21 -0700 | [diff] [blame] | 955 | const Region OutputLayerWriteStateToHWCTest::kOverrideVisibleRegion{Rect{1006, 1007, 1008, 1009}}; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 956 | const mat4 OutputLayerWriteStateToHWCTest::kColorTransform{ |
| 957 | 1009, 1010, 1011, 1012, 1013, 1014, 1015, 1016, |
| 958 | 1017, 1018, 1019, 1020, 1021, 1022, 1023, 1024, |
| 959 | }; |
| 960 | const Region OutputLayerWriteStateToHWCTest::kSurfaceDamage{Rect{1025, 1026, 1027, 1028}}; |
Alec Mouri | 464352b | 2021-03-24 16:33:21 -0700 | [diff] [blame] | 961 | const Region OutputLayerWriteStateToHWCTest::kOverrideSurfaceDamage{Rect{1026, 1027, 1028, 1029}}; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 962 | const HdrMetadata OutputLayerWriteStateToHWCTest::kHdrMetadata{{/* LightFlattenable */}, 1029}; |
| 963 | native_handle_t* OutputLayerWriteStateToHWCTest::kSidebandStreamHandle = |
| 964 | reinterpret_cast<native_handle_t*>(1031); |
Brian Lindahl | 90553da | 2022-12-06 13:36:30 -0700 | [diff] [blame] | 965 | const sp<GraphicBuffer> OutputLayerWriteStateToHWCTest::kBuffer = |
| 966 | sp<GraphicBuffer>::make(1, 2, PIXEL_FORMAT_RGBA_8888, |
| 967 | AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN | |
| 968 | AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN); |
Alec Mouri | 03bf0ff | 2021-04-19 14:17:31 -0700 | [diff] [blame] | 969 | const sp<GraphicBuffer> OutputLayerWriteStateToHWCTest::kOverrideBuffer = |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 970 | sp<GraphicBuffer>::make(4, 5, PIXEL_FORMAT_RGBA_8888, |
| 971 | AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN | |
| 972 | AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 973 | const sp<Fence> OutputLayerWriteStateToHWCTest::kFence; |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 974 | const sp<Fence> OutputLayerWriteStateToHWCTest::kOverrideFence = sp<Fence>::make(); |
Lloyd Pique | 8d9f836 | 2020-02-11 19:13:09 -0800 | [diff] [blame] | 975 | const std::string OutputLayerWriteStateToHWCTest::kLayerGenericMetadata1Key = |
| 976 | "com.example.metadata.1"; |
| 977 | const std::vector<uint8_t> OutputLayerWriteStateToHWCTest::kLayerGenericMetadata1Value{{1, 2, 3}}; |
| 978 | const std::string OutputLayerWriteStateToHWCTest::kLayerGenericMetadata2Key = |
| 979 | "com.example.metadata.2"; |
| 980 | const std::vector<uint8_t> OutputLayerWriteStateToHWCTest::kLayerGenericMetadata2Value{ |
| 981 | {4, 5, 6, 7}}; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 982 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 983 | TEST_F(OutputLayerWriteStateToHWCTest, doesNothingIfNoFECompositionState) { |
Brian Lindahl | 90553da | 2022-12-06 13:36:30 -0700 | [diff] [blame] | 984 | EXPECT_CALL(mLayerFE, getCompositionState()).WillOnce(Return(nullptr)); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 985 | |
Leon Scroggins III | 9aa25c2 | 2021-04-15 15:30:19 -0400 | [diff] [blame] | 986 | mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0, |
| 987 | /*zIsOverridden*/ false, /*isPeekingThrough*/ false); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 988 | } |
| 989 | |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 990 | TEST_F(OutputLayerWriteStateToHWCTest, doesNothingIfNoHWCState) { |
| 991 | mOutputLayer.editState().hwc.reset(); |
| 992 | |
Leon Scroggins III | 9aa25c2 | 2021-04-15 15:30:19 -0400 | [diff] [blame] | 993 | mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0, |
| 994 | /*zIsOverridden*/ false, /*isPeekingThrough*/ false); |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 995 | } |
| 996 | |
| 997 | TEST_F(OutputLayerWriteStateToHWCTest, doesNothingIfNoHWCLayer) { |
| 998 | mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc(nullptr); |
| 999 | |
Leon Scroggins III | 9aa25c2 | 2021-04-15 15:30:19 -0400 | [diff] [blame] | 1000 | mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0, |
| 1001 | /*zIsOverridden*/ false, /*isPeekingThrough*/ false); |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 1002 | } |
| 1003 | |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 1004 | TEST_F(OutputLayerWriteStateToHWCTest, canSetAllState) { |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 1005 | expectGeometryCommonCalls(); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 1006 | expectPerFrameCommonCalls(); |
| 1007 | |
| 1008 | expectNoSetCompositionTypeCall(); |
Brian Lindahl | 90553da | 2022-12-06 13:36:30 -0700 | [diff] [blame] | 1009 | EXPECT_CALL(mLayerFE, hasRoundedCorners()).WillOnce(Return(false)); |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 1010 | |
Leon Scroggins III | 9aa25c2 | 2021-04-15 15:30:19 -0400 | [diff] [blame] | 1011 | mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0, |
| 1012 | /*zIsOverridden*/ false, /*isPeekingThrough*/ false); |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 1013 | } |
| 1014 | |
Rashed Abdel-Tawab | 6643cd8 | 2019-10-29 10:01:56 -0700 | [diff] [blame] | 1015 | TEST_F(OutputLayerTest, displayInstallOrientationBufferTransformSetTo90) { |
| 1016 | mLayerFEState.geomBufferUsesDisplayInverseTransform = false; |
| 1017 | mLayerFEState.geomLayerTransform = ui::Transform{TR_IDENT}; |
| 1018 | // This test simulates a scenario where displayInstallOrientation is set to |
| 1019 | // ROT_90. This only has an effect on the transform; orientation stays 0 (see |
| 1020 | // DisplayDevice::setProjection). |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 1021 | mOutputState.displaySpace.setOrientation(ui::ROTATION_0); |
Rashed Abdel-Tawab | 6643cd8 | 2019-10-29 10:01:56 -0700 | [diff] [blame] | 1022 | mOutputState.transform = ui::Transform{TR_ROT_90}; |
| 1023 | // Buffers are pre-rotated based on the transform hint (ROT_90); their |
| 1024 | // geomBufferTransform is set to the inverse transform. |
| 1025 | mLayerFEState.geomBufferTransform = TR_ROT_270; |
| 1026 | |
Snild Dolkow | 9e217d6 | 2020-04-22 15:53:42 +0200 | [diff] [blame] | 1027 | EXPECT_EQ(TR_IDENT, mOutputLayer.calculateOutputRelativeBufferTransform(ui::Transform::ROT_90)); |
Rashed Abdel-Tawab | 6643cd8 | 2019-10-29 10:01:56 -0700 | [diff] [blame] | 1028 | } |
| 1029 | |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 1030 | TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForSolidColor) { |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 1031 | mLayerFEState.compositionType = Composition::SOLID_COLOR; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 1032 | |
| 1033 | expectPerFrameCommonCalls(); |
Lloyd Pique | 46b72df | 2019-10-29 13:19:27 -0700 | [diff] [blame] | 1034 | |
| 1035 | // Setting the composition type should happen before setting the color. We |
| 1036 | // check this in this test only by setting up an testing::InSeqeuence |
| 1037 | // instance before setting up the two expectations. |
| 1038 | InSequence s; |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 1039 | expectSetCompositionTypeCall(Composition::SOLID_COLOR); |
Lloyd Pique | 46b72df | 2019-10-29 13:19:27 -0700 | [diff] [blame] | 1040 | expectSetColorCall(); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 1041 | |
Leon Scroggins III | 9aa25c2 | 2021-04-15 15:30:19 -0400 | [diff] [blame] | 1042 | mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0, |
| 1043 | /*zIsOverridden*/ false, /*isPeekingThrough*/ false); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 1044 | } |
| 1045 | |
| 1046 | TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForSideband) { |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 1047 | mLayerFEState.compositionType = Composition::SIDEBAND; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 1048 | |
| 1049 | expectPerFrameCommonCalls(); |
| 1050 | expectSetSidebandHandleCall(); |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 1051 | expectSetCompositionTypeCall(Composition::SIDEBAND); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 1052 | |
Leon Scroggins III | 9aa25c2 | 2021-04-15 15:30:19 -0400 | [diff] [blame] | 1053 | mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0, |
| 1054 | /*zIsOverridden*/ false, /*isPeekingThrough*/ false); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 1055 | } |
| 1056 | |
| 1057 | TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForCursor) { |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 1058 | mLayerFEState.compositionType = Composition::CURSOR; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 1059 | |
| 1060 | expectPerFrameCommonCalls(); |
| 1061 | expectSetHdrMetadataAndBufferCalls(); |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 1062 | expectSetCompositionTypeCall(Composition::CURSOR); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 1063 | |
Leon Scroggins III | 9aa25c2 | 2021-04-15 15:30:19 -0400 | [diff] [blame] | 1064 | mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0, |
| 1065 | /*zIsOverridden*/ false, /*isPeekingThrough*/ false); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 1066 | } |
| 1067 | |
| 1068 | TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForDevice) { |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 1069 | mLayerFEState.compositionType = Composition::DEVICE; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 1070 | |
| 1071 | expectPerFrameCommonCalls(); |
| 1072 | expectSetHdrMetadataAndBufferCalls(); |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 1073 | expectSetCompositionTypeCall(Composition::DEVICE); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 1074 | |
Leon Scroggins III | 9aa25c2 | 2021-04-15 15:30:19 -0400 | [diff] [blame] | 1075 | mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0, |
| 1076 | /*zIsOverridden*/ false, /*isPeekingThrough*/ false); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 1077 | } |
| 1078 | |
| 1079 | TEST_F(OutputLayerWriteStateToHWCTest, compositionTypeIsNotSetIfUnchanged) { |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 1080 | (*mOutputLayer.editState().hwc).hwcCompositionType = Composition::SOLID_COLOR; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 1081 | |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 1082 | mLayerFEState.compositionType = Composition::SOLID_COLOR; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 1083 | |
| 1084 | expectPerFrameCommonCalls(); |
| 1085 | expectSetColorCall(); |
| 1086 | expectNoSetCompositionTypeCall(); |
| 1087 | |
Leon Scroggins III | 9aa25c2 | 2021-04-15 15:30:19 -0400 | [diff] [blame] | 1088 | mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0, |
| 1089 | /*zIsOverridden*/ false, /*isPeekingThrough*/ false); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 1090 | } |
| 1091 | |
| 1092 | TEST_F(OutputLayerWriteStateToHWCTest, compositionTypeIsSetToClientIfColorTransformNotSupported) { |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 1093 | mLayerFEState.compositionType = Composition::SOLID_COLOR; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 1094 | |
| 1095 | expectPerFrameCommonCalls(SimulateUnsupported::ColorTransform); |
| 1096 | expectSetColorCall(); |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 1097 | expectSetCompositionTypeCall(Composition::CLIENT); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 1098 | |
Leon Scroggins III | 9aa25c2 | 2021-04-15 15:30:19 -0400 | [diff] [blame] | 1099 | mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0, |
| 1100 | /*zIsOverridden*/ false, /*isPeekingThrough*/ false); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 1101 | } |
| 1102 | |
| 1103 | TEST_F(OutputLayerWriteStateToHWCTest, compositionTypeIsSetToClientIfClientCompositionForced) { |
| 1104 | mOutputLayer.editState().forceClientComposition = true; |
| 1105 | |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 1106 | mLayerFEState.compositionType = Composition::SOLID_COLOR; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 1107 | |
| 1108 | expectPerFrameCommonCalls(); |
| 1109 | expectSetColorCall(); |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 1110 | expectSetCompositionTypeCall(Composition::CLIENT); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 1111 | |
Leon Scroggins III | 9aa25c2 | 2021-04-15 15:30:19 -0400 | [diff] [blame] | 1112 | mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0, |
| 1113 | /*zIsOverridden*/ false, /*isPeekingThrough*/ false); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 1114 | } |
| 1115 | |
Lloyd Pique | 8d9f836 | 2020-02-11 19:13:09 -0800 | [diff] [blame] | 1116 | TEST_F(OutputLayerWriteStateToHWCTest, allStateIncludesMetadataIfPresent) { |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 1117 | mLayerFEState.compositionType = Composition::DEVICE; |
Lloyd Pique | 8d9f836 | 2020-02-11 19:13:09 -0800 | [diff] [blame] | 1118 | includeGenericLayerMetadataInState(); |
| 1119 | |
| 1120 | expectGeometryCommonCalls(); |
| 1121 | expectPerFrameCommonCalls(); |
| 1122 | expectSetHdrMetadataAndBufferCalls(); |
| 1123 | expectGenericLayerMetadataCalls(); |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 1124 | expectSetCompositionTypeCall(Composition::DEVICE); |
Lloyd Pique | 8d9f836 | 2020-02-11 19:13:09 -0800 | [diff] [blame] | 1125 | |
Leon Scroggins III | 9aa25c2 | 2021-04-15 15:30:19 -0400 | [diff] [blame] | 1126 | mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0, |
| 1127 | /*zIsOverridden*/ false, /*isPeekingThrough*/ false); |
Lloyd Pique | 8d9f836 | 2020-02-11 19:13:09 -0800 | [diff] [blame] | 1128 | } |
| 1129 | |
| 1130 | TEST_F(OutputLayerWriteStateToHWCTest, perFrameStateDoesNotIncludeMetadataIfPresent) { |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 1131 | mLayerFEState.compositionType = Composition::DEVICE; |
Lloyd Pique | 8d9f836 | 2020-02-11 19:13:09 -0800 | [diff] [blame] | 1132 | includeGenericLayerMetadataInState(); |
| 1133 | |
| 1134 | expectPerFrameCommonCalls(); |
| 1135 | expectSetHdrMetadataAndBufferCalls(); |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 1136 | expectSetCompositionTypeCall(Composition::DEVICE); |
Lloyd Pique | 8d9f836 | 2020-02-11 19:13:09 -0800 | [diff] [blame] | 1137 | |
Leon Scroggins III | 9aa25c2 | 2021-04-15 15:30:19 -0400 | [diff] [blame] | 1138 | mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0, |
| 1139 | /*zIsOverridden*/ false, /*isPeekingThrough*/ false); |
Lloyd Pique | 8d9f836 | 2020-02-11 19:13:09 -0800 | [diff] [blame] | 1140 | } |
| 1141 | |
Alec Mouri | 96ca45c | 2021-06-09 17:32:26 -0700 | [diff] [blame] | 1142 | TEST_F(OutputLayerWriteStateToHWCTest, overriddenSkipLayerDoesNotSendBuffer) { |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 1143 | mLayerFEState.compositionType = Composition::DEVICE; |
Alec Mouri | 96ca45c | 2021-06-09 17:32:26 -0700 | [diff] [blame] | 1144 | includeOverrideInfo(); |
| 1145 | |
| 1146 | expectGeometryCommonCalls(kOverrideDisplayFrame, kOverrideSourceCrop, kOverrideBufferTransform, |
| 1147 | kOverrideBlendMode, kSkipAlpha); |
| 1148 | expectPerFrameCommonCalls(SimulateUnsupported::None, kOverrideDataspace, kOverrideVisibleRegion, |
Alec Mouri | e8dd356 | 2022-02-11 14:18:57 -0800 | [diff] [blame] | 1149 | kOverrideSurfaceDamage, kOverrideLayerBrightness); |
Alec Mouri | 96ca45c | 2021-06-09 17:32:26 -0700 | [diff] [blame] | 1150 | expectSetHdrMetadataAndBufferCalls(); |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 1151 | expectSetCompositionTypeCall(Composition::DEVICE); |
Alec Mouri | 96ca45c | 2021-06-09 17:32:26 -0700 | [diff] [blame] | 1152 | |
| 1153 | mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ true, 0, |
| 1154 | /*zIsOverridden*/ false, /*isPeekingThrough*/ false); |
| 1155 | } |
| 1156 | |
Alec Mouri | 2b1212b | 2021-12-09 12:02:39 -0800 | [diff] [blame] | 1157 | TEST_F(OutputLayerWriteStateToHWCTest, overriddenSkipLayerForSolidColorDoesNotSendBuffer) { |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 1158 | mLayerFEState.compositionType = Composition::SOLID_COLOR; |
Alec Mouri | 2b1212b | 2021-12-09 12:02:39 -0800 | [diff] [blame] | 1159 | includeOverrideInfo(); |
| 1160 | |
| 1161 | expectGeometryCommonCalls(kOverrideDisplayFrame, kOverrideSourceCrop, kOverrideBufferTransform, |
| 1162 | kOverrideBlendMode, kSkipAlpha); |
| 1163 | expectPerFrameCommonCalls(SimulateUnsupported::None, kOverrideDataspace, kOverrideVisibleRegion, |
Alec Mouri | e8dd356 | 2022-02-11 14:18:57 -0800 | [diff] [blame] | 1164 | kOverrideSurfaceDamage, kOverrideLayerBrightness); |
Alec Mouri | 2b1212b | 2021-12-09 12:02:39 -0800 | [diff] [blame] | 1165 | expectSetHdrMetadataAndBufferCalls(); |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 1166 | expectSetCompositionTypeCall(Composition::DEVICE); |
Alec Mouri | 2b1212b | 2021-12-09 12:02:39 -0800 | [diff] [blame] | 1167 | |
| 1168 | mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ true, 0, |
| 1169 | /*zIsOverridden*/ false, /*isPeekingThrough*/ false); |
| 1170 | } |
| 1171 | |
Alec Mouri | b7edfc2 | 2021-03-17 16:20:26 -0700 | [diff] [blame] | 1172 | TEST_F(OutputLayerWriteStateToHWCTest, includesOverrideInfoIfPresent) { |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 1173 | mLayerFEState.compositionType = Composition::DEVICE; |
Alec Mouri | b7edfc2 | 2021-03-17 16:20:26 -0700 | [diff] [blame] | 1174 | includeOverrideInfo(); |
| 1175 | |
Alec Mouri | 03bf0ff | 2021-04-19 14:17:31 -0700 | [diff] [blame] | 1176 | expectGeometryCommonCalls(kOverrideDisplayFrame, kOverrideSourceCrop, kOverrideBufferTransform, |
| 1177 | kOverrideBlendMode, kOverrideAlpha); |
Alec Mouri | 464352b | 2021-03-24 16:33:21 -0700 | [diff] [blame] | 1178 | expectPerFrameCommonCalls(SimulateUnsupported::None, kOverrideDataspace, kOverrideVisibleRegion, |
Alec Mouri | e8dd356 | 2022-02-11 14:18:57 -0800 | [diff] [blame] | 1179 | kOverrideSurfaceDamage, kOverrideLayerBrightness); |
Alec Mouri | e7cc1c2 | 2021-04-27 15:23:26 -0700 | [diff] [blame] | 1180 | expectSetHdrMetadataAndBufferCalls(kOverrideHwcSlot, kOverrideBuffer, kOverrideFence); |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 1181 | expectSetCompositionTypeCall(Composition::DEVICE); |
Alec Mouri | d1bf1b5 | 2021-05-05 18:44:58 -0700 | [diff] [blame] | 1182 | |
| 1183 | mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0, |
| 1184 | /*zIsOverridden*/ false, /*isPeekingThrough*/ false); |
| 1185 | } |
| 1186 | |
Alec Mouri | 028676a | 2021-12-02 15:01:48 -0800 | [diff] [blame] | 1187 | TEST_F(OutputLayerWriteStateToHWCTest, includesOverrideInfoForSolidColorIfPresent) { |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 1188 | mLayerFEState.compositionType = Composition::SOLID_COLOR; |
Alec Mouri | 028676a | 2021-12-02 15:01:48 -0800 | [diff] [blame] | 1189 | includeOverrideInfo(); |
| 1190 | |
| 1191 | expectGeometryCommonCalls(kOverrideDisplayFrame, kOverrideSourceCrop, kOverrideBufferTransform, |
| 1192 | kOverrideBlendMode, kOverrideAlpha); |
| 1193 | expectPerFrameCommonCalls(SimulateUnsupported::None, kOverrideDataspace, kOverrideVisibleRegion, |
Alec Mouri | e8dd356 | 2022-02-11 14:18:57 -0800 | [diff] [blame] | 1194 | kOverrideSurfaceDamage, kOverrideLayerBrightness); |
Alec Mouri | 028676a | 2021-12-02 15:01:48 -0800 | [diff] [blame] | 1195 | expectSetHdrMetadataAndBufferCalls(kOverrideHwcSlot, kOverrideBuffer, kOverrideFence); |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 1196 | expectSetCompositionTypeCall(Composition::DEVICE); |
Alec Mouri | 028676a | 2021-12-02 15:01:48 -0800 | [diff] [blame] | 1197 | |
| 1198 | mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0, |
| 1199 | /*zIsOverridden*/ false, /*isPeekingThrough*/ false); |
| 1200 | } |
| 1201 | |
Alec Mouri | d1bf1b5 | 2021-05-05 18:44:58 -0700 | [diff] [blame] | 1202 | TEST_F(OutputLayerWriteStateToHWCTest, previousOverriddenLayerSendsSurfaceDamage) { |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 1203 | mLayerFEState.compositionType = Composition::DEVICE; |
Alec Mouri | d1bf1b5 | 2021-05-05 18:44:58 -0700 | [diff] [blame] | 1204 | mOutputLayer.editState().hwc->stateOverridden = true; |
| 1205 | |
| 1206 | expectGeometryCommonCalls(); |
| 1207 | expectPerFrameCommonCalls(SimulateUnsupported::None, kDataspace, kOutputSpaceVisibleRegion, |
| 1208 | Region::INVALID_REGION); |
| 1209 | expectSetHdrMetadataAndBufferCalls(); |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 1210 | expectSetCompositionTypeCall(Composition::DEVICE); |
Alec Mouri | d1bf1b5 | 2021-05-05 18:44:58 -0700 | [diff] [blame] | 1211 | |
| 1212 | mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0, |
| 1213 | /*zIsOverridden*/ false, /*isPeekingThrough*/ false); |
| 1214 | } |
| 1215 | |
| 1216 | TEST_F(OutputLayerWriteStateToHWCTest, previousSkipLayerSendsUpdatedDeviceCompositionInfo) { |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 1217 | mLayerFEState.compositionType = Composition::DEVICE; |
Alec Mouri | d1bf1b5 | 2021-05-05 18:44:58 -0700 | [diff] [blame] | 1218 | mOutputLayer.editState().hwc->stateOverridden = true; |
| 1219 | mOutputLayer.editState().hwc->layerSkipped = true; |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 1220 | mOutputLayer.editState().hwc->hwcCompositionType = Composition::DEVICE; |
Alec Mouri | d1bf1b5 | 2021-05-05 18:44:58 -0700 | [diff] [blame] | 1221 | |
| 1222 | expectGeometryCommonCalls(); |
| 1223 | expectPerFrameCommonCalls(SimulateUnsupported::None, kDataspace, kOutputSpaceVisibleRegion, |
| 1224 | Region::INVALID_REGION); |
| 1225 | expectSetHdrMetadataAndBufferCalls(); |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 1226 | expectSetCompositionTypeCall(Composition::DEVICE); |
Leon Scroggins III | e2ee040 | 2021-04-02 16:59:37 -0400 | [diff] [blame] | 1227 | |
Leon Scroggins III | 9aa25c2 | 2021-04-15 15:30:19 -0400 | [diff] [blame] | 1228 | mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0, |
| 1229 | /*zIsOverridden*/ false, /*isPeekingThrough*/ false); |
Alec Mouri | b7edfc2 | 2021-03-17 16:20:26 -0700 | [diff] [blame] | 1230 | } |
| 1231 | |
Alec Mouri | d1bf1b5 | 2021-05-05 18:44:58 -0700 | [diff] [blame] | 1232 | TEST_F(OutputLayerWriteStateToHWCTest, previousSkipLayerSendsUpdatedClientCompositionInfo) { |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 1233 | mLayerFEState.compositionType = Composition::DEVICE; |
Alec Mouri | d1bf1b5 | 2021-05-05 18:44:58 -0700 | [diff] [blame] | 1234 | mOutputLayer.editState().forceClientComposition = true; |
| 1235 | mOutputLayer.editState().hwc->stateOverridden = true; |
| 1236 | mOutputLayer.editState().hwc->layerSkipped = true; |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 1237 | mOutputLayer.editState().hwc->hwcCompositionType = Composition::CLIENT; |
Alec Mouri | d1bf1b5 | 2021-05-05 18:44:58 -0700 | [diff] [blame] | 1238 | |
| 1239 | expectGeometryCommonCalls(); |
| 1240 | expectPerFrameCommonCalls(SimulateUnsupported::None, kDataspace, kOutputSpaceVisibleRegion, |
| 1241 | Region::INVALID_REGION); |
| 1242 | expectSetHdrMetadataAndBufferCalls(); |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 1243 | expectSetCompositionTypeCall(Composition::CLIENT); |
Alec Mouri | d1bf1b5 | 2021-05-05 18:44:58 -0700 | [diff] [blame] | 1244 | |
| 1245 | mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0, |
| 1246 | /*zIsOverridden*/ false, /*isPeekingThrough*/ false); |
| 1247 | } |
| 1248 | |
Leon Scroggins III | 2e74a4c | 2021-04-09 13:41:14 -0400 | [diff] [blame] | 1249 | TEST_F(OutputLayerWriteStateToHWCTest, peekThroughChangesBlendMode) { |
Brian Lindahl | 90553da | 2022-12-06 13:36:30 -0700 | [diff] [blame] | 1250 | auto peekThroughLayerFE = sp<NiceMock<compositionengine::mock::LayerFE>>::make(); |
| 1251 | OutputLayer peekThroughLayer{mOutput, *peekThroughLayerFE}; |
Leon Scroggins III | 2e74a4c | 2021-04-09 13:41:14 -0400 | [diff] [blame] | 1252 | |
| 1253 | mOutputLayer.mState.overrideInfo.peekThroughLayer = &peekThroughLayer; |
| 1254 | |
| 1255 | expectGeometryCommonCalls(kDisplayFrame, kSourceCrop, kBufferTransform, |
| 1256 | Hwc2::IComposerClient::BlendMode::PREMULTIPLIED); |
| 1257 | expectPerFrameCommonCalls(); |
Leon Scroggins III | 2e74a4c | 2021-04-09 13:41:14 -0400 | [diff] [blame] | 1258 | |
| 1259 | mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0, |
| 1260 | /*zIsOverridden*/ false, /*isPeekingThrough*/ false); |
| 1261 | } |
| 1262 | |
| 1263 | TEST_F(OutputLayerWriteStateToHWCTest, isPeekingThroughSetsOverride) { |
| 1264 | expectGeometryCommonCalls(); |
| 1265 | expectPerFrameCommonCalls(); |
| 1266 | |
| 1267 | mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0, |
| 1268 | /*zIsOverridden*/ false, /*isPeekingThrough*/ true); |
| 1269 | EXPECT_TRUE(mOutputLayer.getState().hwc->stateOverridden); |
| 1270 | } |
| 1271 | |
| 1272 | TEST_F(OutputLayerWriteStateToHWCTest, zIsOverriddenSetsOverride) { |
| 1273 | expectGeometryCommonCalls(); |
| 1274 | expectPerFrameCommonCalls(); |
Leon Scroggins III | 2e74a4c | 2021-04-09 13:41:14 -0400 | [diff] [blame] | 1275 | |
| 1276 | mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0, |
| 1277 | /*zIsOverridden*/ true, /*isPeekingThrough*/ |
| 1278 | false); |
| 1279 | EXPECT_TRUE(mOutputLayer.getState().hwc->stateOverridden); |
| 1280 | } |
| 1281 | |
| 1282 | TEST_F(OutputLayerWriteStateToHWCTest, roundedCornersForceClientComposition) { |
| 1283 | expectGeometryCommonCalls(); |
| 1284 | expectPerFrameCommonCalls(); |
Brian Lindahl | 90553da | 2022-12-06 13:36:30 -0700 | [diff] [blame] | 1285 | EXPECT_CALL(mLayerFE, hasRoundedCorners()).WillOnce(Return(true)); |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 1286 | expectSetCompositionTypeCall(Composition::CLIENT); |
Leon Scroggins III | 2e74a4c | 2021-04-09 13:41:14 -0400 | [diff] [blame] | 1287 | |
| 1288 | mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0, |
| 1289 | /*zIsOverridden*/ false, /*isPeekingThrough*/ |
| 1290 | false); |
| 1291 | } |
| 1292 | |
| 1293 | TEST_F(OutputLayerWriteStateToHWCTest, roundedCornersPeekingThroughAllowsDeviceComposition) { |
| 1294 | expectGeometryCommonCalls(); |
| 1295 | expectPerFrameCommonCalls(); |
| 1296 | expectSetHdrMetadataAndBufferCalls(); |
Brian Lindahl | 90553da | 2022-12-06 13:36:30 -0700 | [diff] [blame] | 1297 | EXPECT_CALL(mLayerFE, hasRoundedCorners()).WillRepeatedly(Return(true)); |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 1298 | expectSetCompositionTypeCall(Composition::DEVICE); |
Leon Scroggins III | 2e74a4c | 2021-04-09 13:41:14 -0400 | [diff] [blame] | 1299 | |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 1300 | mLayerFEState.compositionType = Composition::DEVICE; |
Leon Scroggins III | 2e74a4c | 2021-04-09 13:41:14 -0400 | [diff] [blame] | 1301 | mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0, |
| 1302 | /*zIsOverridden*/ false, /*isPeekingThrough*/ |
| 1303 | true); |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 1304 | EXPECT_EQ(Composition::DEVICE, mOutputLayer.getState().hwc->hwcCompositionType); |
Leon Scroggins III | 2e74a4c | 2021-04-09 13:41:14 -0400 | [diff] [blame] | 1305 | } |
| 1306 | |
Leon Scroggins III | 9a0afda | 2022-01-11 16:53:09 -0500 | [diff] [blame] | 1307 | TEST_F(OutputLayerWriteStateToHWCTest, setBlockingRegion) { |
| 1308 | mLayerFEState.compositionType = Composition::DISPLAY_DECORATION; |
| 1309 | const auto blockingRegion = Region(Rect(0, 0, 1000, 1000)); |
| 1310 | mOutputLayer.editState().outputSpaceBlockingRegionHint = blockingRegion; |
| 1311 | |
| 1312 | expectGeometryCommonCalls(); |
| 1313 | expectPerFrameCommonCalls(SimulateUnsupported::None, kDataspace, kOutputSpaceVisibleRegion, |
Alec Mouri | 6da0e27 | 2022-02-07 12:45:57 -0800 | [diff] [blame] | 1314 | kSurfaceDamage, kLayerBrightness, blockingRegion); |
Leon Scroggins III | 9a0afda | 2022-01-11 16:53:09 -0500 | [diff] [blame] | 1315 | expectSetHdrMetadataAndBufferCalls(); |
Leon Scroggins III | 9a0afda | 2022-01-11 16:53:09 -0500 | [diff] [blame] | 1316 | expectSetCompositionTypeCall(Composition::DISPLAY_DECORATION); |
| 1317 | |
| 1318 | mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0, |
| 1319 | /*zIsOverridden*/ false, /*isPeekingThrough*/ |
| 1320 | false); |
| 1321 | } |
| 1322 | |
ramindani | b2158ee | 2023-02-13 20:29:59 -0800 | [diff] [blame] | 1323 | TEST_F(OutputLayerWriteStateToHWCTest, setCompositionTypeRefreshRateIndicator) { |
| 1324 | mLayerFEState.compositionType = Composition::REFRESH_RATE_INDICATOR; |
| 1325 | |
| 1326 | expectGeometryCommonCalls(); |
| 1327 | expectPerFrameCommonCalls(); |
| 1328 | expectSetHdrMetadataAndBufferCalls(); |
| 1329 | expectSetCompositionTypeCall(Composition::REFRESH_RATE_INDICATOR); |
| 1330 | |
| 1331 | mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0, |
| 1332 | /*zIsOverridden*/ false, /*isPeekingThrough*/ false); |
| 1333 | } |
| 1334 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 1335 | /* |
Brian Lindahl | 90553da | 2022-12-06 13:36:30 -0700 | [diff] [blame] | 1336 | * OutputLayer::uncacheBuffers |
| 1337 | */ |
| 1338 | struct OutputLayerUncacheBufferTest : public OutputLayerTest { |
| 1339 | static const sp<GraphicBuffer> kBuffer1; |
| 1340 | static const sp<GraphicBuffer> kBuffer2; |
Brian Lindahl | 3e1e1e6 | 2022-12-21 14:28:58 -0700 | [diff] [blame] | 1341 | static const sp<GraphicBuffer> kBuffer3; |
Brian Lindahl | 90553da | 2022-12-06 13:36:30 -0700 | [diff] [blame] | 1342 | static const sp<Fence> kFence; |
| 1343 | |
| 1344 | OutputLayerUncacheBufferTest() { |
| 1345 | auto& outputLayerState = mOutputLayer.editState(); |
| 1346 | outputLayerState.hwc = impl::OutputLayerCompositionState::Hwc(mHwcLayer_); |
| 1347 | |
| 1348 | mLayerFEState.compositionType = Composition::DEVICE; |
| 1349 | mLayerFEState.acquireFence = kFence; |
| 1350 | |
| 1351 | ON_CALL(mOutput, getDisplayColorProfile()).WillByDefault(Return(&mDisplayColorProfile)); |
| 1352 | } |
| 1353 | |
| 1354 | std::shared_ptr<HWC2::mock::Layer> mHwcLayer_{std::make_shared<NiceMock<HWC2::mock::Layer>>()}; |
| 1355 | HWC2::mock::Layer& mHwcLayer = *mHwcLayer_; |
| 1356 | NiceMock<mock::DisplayColorProfile> mDisplayColorProfile; |
| 1357 | }; |
| 1358 | |
| 1359 | const sp<GraphicBuffer> OutputLayerUncacheBufferTest::kBuffer1 = |
| 1360 | sp<GraphicBuffer>::make(1, 2, PIXEL_FORMAT_RGBA_8888, |
| 1361 | AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN | |
| 1362 | AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN); |
| 1363 | const sp<GraphicBuffer> OutputLayerUncacheBufferTest::kBuffer2 = |
| 1364 | sp<GraphicBuffer>::make(2, 3, PIXEL_FORMAT_RGBA_8888, |
| 1365 | AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN | |
| 1366 | AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN); |
Brian Lindahl | 3e1e1e6 | 2022-12-21 14:28:58 -0700 | [diff] [blame] | 1367 | const sp<GraphicBuffer> OutputLayerUncacheBufferTest::kBuffer3 = |
| 1368 | sp<GraphicBuffer>::make(4, 5, PIXEL_FORMAT_RGBA_8888, |
| 1369 | AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN | |
| 1370 | AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN); |
Brian Lindahl | 90553da | 2022-12-06 13:36:30 -0700 | [diff] [blame] | 1371 | const sp<Fence> OutputLayerUncacheBufferTest::kFence = sp<Fence>::make(); |
| 1372 | |
| 1373 | TEST_F(OutputLayerUncacheBufferTest, canUncacheAndReuseSlot) { |
| 1374 | // Buffer1 is stored in slot 0 |
| 1375 | mLayerFEState.buffer = kBuffer1; |
| 1376 | EXPECT_CALL(mHwcLayer, setBuffer(/*slot*/ 0, kBuffer1, kFence)); |
| 1377 | mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0, |
| 1378 | /*zIsOverridden*/ false, /*isPeekingThrough*/ false); |
| 1379 | Mock::VerifyAndClearExpectations(&mHwcLayer); |
| 1380 | |
| 1381 | // Buffer2 is stored in slot 1 |
| 1382 | mLayerFEState.buffer = kBuffer2; |
| 1383 | EXPECT_CALL(mHwcLayer, setBuffer(/*slot*/ 1, kBuffer2, kFence)); |
| 1384 | mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0, |
| 1385 | /*zIsOverridden*/ false, /*isPeekingThrough*/ false); |
| 1386 | Mock::VerifyAndClearExpectations(&mHwcLayer); |
| 1387 | |
Brian Lindahl | 3e1e1e6 | 2022-12-21 14:28:58 -0700 | [diff] [blame] | 1388 | // Buffer3 is stored in slot 2 |
| 1389 | mLayerFEState.buffer = kBuffer3; |
| 1390 | EXPECT_CALL(mHwcLayer, setBuffer(/*slot*/ 2, kBuffer3, kFence)); |
| 1391 | mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0, |
| 1392 | /*zIsOverridden*/ false, /*isPeekingThrough*/ false); |
Brian Lindahl | 90553da | 2022-12-06 13:36:30 -0700 | [diff] [blame] | 1393 | Mock::VerifyAndClearExpectations(&mHwcLayer); |
| 1394 | |
Brian Lindahl | 3e1e1e6 | 2022-12-21 14:28:58 -0700 | [diff] [blame] | 1395 | // Buffer2 becomes the active buffer again (with a nullptr) and reuses slot 1 |
| 1396 | mLayerFEState.buffer = kBuffer2; |
| 1397 | sp<GraphicBuffer> nullBuffer = nullptr; |
| 1398 | EXPECT_CALL(mHwcLayer, setBuffer(/*slot*/ 1, nullBuffer, kFence)); |
| 1399 | mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0, |
| 1400 | /*zIsOverridden*/ false, /*isPeekingThrough*/ false); |
| 1401 | Mock::VerifyAndClearExpectations(&mHwcLayer); |
| 1402 | |
| 1403 | // Buffer slots are cleared |
| 1404 | std::vector<uint32_t> slotsToClear = {0, 2, 1}; // order doesn't matter |
| 1405 | EXPECT_CALL(mHwcLayer, setBufferSlotsToClear(slotsToClear, /*activeBufferSlot*/ 1)); |
| 1406 | // Uncache the active buffer in between other buffers to exercise correct algorithmic behavior. |
| 1407 | mOutputLayer.uncacheBuffers({kBuffer1->getId(), kBuffer2->getId(), kBuffer3->getId()}); |
| 1408 | Mock::VerifyAndClearExpectations(&mHwcLayer); |
| 1409 | |
| 1410 | // Buffer1 becomes active again, and rather than allocating a new slot, or re-using slot 0, |
| 1411 | // the active buffer slot (slot 1 for Buffer2) is reused first, which allows HWC to free the |
| 1412 | // memory for the active buffer. Note: slot 1 is different from the first and last buffer slot |
| 1413 | // requested to be cleared in slotsToClear (slot 1), above, indicating that the algorithm |
| 1414 | // correctly identifies the active buffer as the buffer in slot 1, despite ping-ponging. |
Brian Lindahl | 90553da | 2022-12-06 13:36:30 -0700 | [diff] [blame] | 1415 | mLayerFEState.buffer = kBuffer1; |
| 1416 | EXPECT_CALL(mHwcLayer, setBuffer(/*slot*/ 1, kBuffer1, kFence)); |
| 1417 | mOutputLayer.writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0, |
| 1418 | /*zIsOverridden*/ false, /*isPeekingThrough*/ false); |
| 1419 | Mock::VerifyAndClearExpectations(&mHwcLayer); |
Brian Lindahl | 90553da | 2022-12-06 13:36:30 -0700 | [diff] [blame] | 1420 | } |
| 1421 | |
| 1422 | /* |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 1423 | * OutputLayer::writeCursorPositionToHWC() |
| 1424 | */ |
| 1425 | |
| 1426 | struct OutputLayerWriteCursorPositionToHWCTest : public OutputLayerTest { |
| 1427 | static constexpr int kDefaultTransform = TR_IDENT; |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 1428 | static constexpr hal::Error kDefaultError = hal::Error::UNSUPPORTED; |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 1429 | |
| 1430 | static const Rect kDefaultDisplayViewport; |
| 1431 | static const Rect kDefaultCursorFrame; |
| 1432 | |
| 1433 | OutputLayerWriteCursorPositionToHWCTest() { |
| 1434 | auto& outputLayerState = mOutputLayer.editState(); |
| 1435 | outputLayerState.hwc = impl::OutputLayerCompositionState::Hwc(mHwcLayer); |
| 1436 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 1437 | mLayerFEState.cursorFrame = kDefaultCursorFrame; |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 1438 | |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 1439 | mOutputState.layerStackSpace.setContent(kDefaultDisplayViewport); |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 1440 | mOutputState.transform = ui::Transform{kDefaultTransform}; |
| 1441 | } |
| 1442 | |
| 1443 | std::shared_ptr<HWC2::mock::Layer> mHwcLayer{std::make_shared<StrictMock<HWC2::mock::Layer>>()}; |
| 1444 | }; |
| 1445 | |
| 1446 | const Rect OutputLayerWriteCursorPositionToHWCTest::kDefaultDisplayViewport{0, 0, 1920, 1080}; |
| 1447 | const Rect OutputLayerWriteCursorPositionToHWCTest::kDefaultCursorFrame{1, 2, 3, 4}; |
| 1448 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1449 | TEST_F(OutputLayerWriteCursorPositionToHWCTest, doesNothingIfNoFECompositionState) { |
Brian Lindahl | 90553da | 2022-12-06 13:36:30 -0700 | [diff] [blame] | 1450 | EXPECT_CALL(mLayerFE, getCompositionState()).WillOnce(Return(nullptr)); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1451 | |
| 1452 | mOutputLayer.writeCursorPositionToHWC(); |
| 1453 | } |
| 1454 | |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 1455 | TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCHandlesNoHwcState) { |
| 1456 | mOutputLayer.editState().hwc.reset(); |
| 1457 | |
| 1458 | mOutputLayer.writeCursorPositionToHWC(); |
| 1459 | } |
| 1460 | |
| 1461 | TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCWritesStateToHWC) { |
| 1462 | EXPECT_CALL(*mHwcLayer, setCursorPosition(1, 2)).WillOnce(Return(kDefaultError)); |
| 1463 | |
| 1464 | mOutputLayer.writeCursorPositionToHWC(); |
| 1465 | } |
| 1466 | |
| 1467 | TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCIntersectedWithViewport) { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 1468 | mLayerFEState.cursorFrame = Rect{3000, 3000, 3016, 3016}; |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 1469 | |
| 1470 | EXPECT_CALL(*mHwcLayer, setCursorPosition(1920, 1080)).WillOnce(Return(kDefaultError)); |
| 1471 | |
| 1472 | mOutputLayer.writeCursorPositionToHWC(); |
| 1473 | } |
| 1474 | |
| 1475 | TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCRotatedByTransform) { |
| 1476 | mOutputState.transform = ui::Transform{TR_ROT_90}; |
| 1477 | |
| 1478 | EXPECT_CALL(*mHwcLayer, setCursorPosition(-4, 1)).WillOnce(Return(kDefaultError)); |
| 1479 | |
| 1480 | mOutputLayer.writeCursorPositionToHWC(); |
| 1481 | } |
| 1482 | |
| 1483 | /* |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 1484 | * OutputLayer::getHwcLayer() |
| 1485 | */ |
| 1486 | |
| 1487 | TEST_F(OutputLayerTest, getHwcLayerHandlesNoHwcState) { |
| 1488 | mOutputLayer.editState().hwc.reset(); |
| 1489 | |
| 1490 | EXPECT_TRUE(mOutputLayer.getHwcLayer() == nullptr); |
| 1491 | } |
| 1492 | |
| 1493 | TEST_F(OutputLayerTest, getHwcLayerHandlesNoHwcLayer) { |
| 1494 | mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr}; |
| 1495 | |
| 1496 | EXPECT_TRUE(mOutputLayer.getHwcLayer() == nullptr); |
| 1497 | } |
| 1498 | |
| 1499 | TEST_F(OutputLayerTest, getHwcLayerReturnsHwcLayer) { |
| 1500 | auto hwcLayer = std::make_shared<StrictMock<HWC2::mock::Layer>>(); |
| 1501 | mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{hwcLayer}; |
| 1502 | |
| 1503 | EXPECT_EQ(hwcLayer.get(), mOutputLayer.getHwcLayer()); |
| 1504 | } |
| 1505 | |
| 1506 | /* |
| 1507 | * OutputLayer::requiresClientComposition() |
| 1508 | */ |
| 1509 | |
| 1510 | TEST_F(OutputLayerTest, requiresClientCompositionReturnsTrueIfNoHWC2State) { |
| 1511 | mOutputLayer.editState().hwc.reset(); |
| 1512 | |
| 1513 | EXPECT_TRUE(mOutputLayer.requiresClientComposition()); |
| 1514 | } |
| 1515 | |
| 1516 | TEST_F(OutputLayerTest, requiresClientCompositionReturnsTrueIfSetToClientComposition) { |
| 1517 | mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr}; |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 1518 | mOutputLayer.editState().hwc->hwcCompositionType = Composition::CLIENT; |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 1519 | |
| 1520 | EXPECT_TRUE(mOutputLayer.requiresClientComposition()); |
| 1521 | } |
| 1522 | |
| 1523 | TEST_F(OutputLayerTest, requiresClientCompositionReturnsFalseIfSetToDeviceComposition) { |
| 1524 | mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr}; |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 1525 | mOutputLayer.editState().hwc->hwcCompositionType = Composition::DEVICE; |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 1526 | |
| 1527 | EXPECT_FALSE(mOutputLayer.requiresClientComposition()); |
| 1528 | } |
| 1529 | |
| 1530 | /* |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 1531 | * OutputLayer::isHardwareCursor() |
| 1532 | */ |
| 1533 | |
| 1534 | TEST_F(OutputLayerTest, isHardwareCursorReturnsFalseIfNoHWC2State) { |
| 1535 | mOutputLayer.editState().hwc.reset(); |
| 1536 | |
| 1537 | EXPECT_FALSE(mOutputLayer.isHardwareCursor()); |
| 1538 | } |
| 1539 | |
| 1540 | TEST_F(OutputLayerTest, isHardwareCursorReturnsTrueIfSetToCursorComposition) { |
| 1541 | mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr}; |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 1542 | mOutputLayer.editState().hwc->hwcCompositionType = Composition::CURSOR; |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 1543 | |
| 1544 | EXPECT_TRUE(mOutputLayer.isHardwareCursor()); |
| 1545 | } |
| 1546 | |
| 1547 | TEST_F(OutputLayerTest, isHardwareCursorReturnsFalseIfSetToDeviceComposition) { |
| 1548 | mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr}; |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 1549 | mOutputLayer.editState().hwc->hwcCompositionType = Composition::DEVICE; |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 1550 | |
| 1551 | EXPECT_FALSE(mOutputLayer.isHardwareCursor()); |
| 1552 | } |
| 1553 | |
| 1554 | /* |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 1555 | * OutputLayer::applyDeviceCompositionTypeChange() |
| 1556 | */ |
| 1557 | |
| 1558 | TEST_F(OutputLayerTest, applyDeviceCompositionTypeChangeSetsNewType) { |
| 1559 | mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr}; |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 1560 | mOutputLayer.editState().hwc->hwcCompositionType = Composition::DEVICE; |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 1561 | |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 1562 | mOutputLayer.applyDeviceCompositionTypeChange(Composition::CLIENT); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 1563 | |
| 1564 | ASSERT_TRUE(mOutputLayer.getState().hwc); |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 1565 | EXPECT_EQ(Composition::CLIENT, mOutputLayer.getState().hwc->hwcCompositionType); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 1566 | } |
| 1567 | |
| 1568 | /* |
| 1569 | * OutputLayer::prepareForDeviceLayerRequests() |
| 1570 | */ |
| 1571 | |
| 1572 | TEST_F(OutputLayerTest, prepareForDeviceLayerRequestsResetsRequestState) { |
| 1573 | mOutputLayer.editState().clearClientTarget = true; |
| 1574 | |
| 1575 | mOutputLayer.prepareForDeviceLayerRequests(); |
| 1576 | |
| 1577 | EXPECT_FALSE(mOutputLayer.getState().clearClientTarget); |
| 1578 | } |
| 1579 | |
| 1580 | /* |
| 1581 | * OutputLayer::applyDeviceLayerRequest() |
| 1582 | */ |
| 1583 | |
| 1584 | TEST_F(OutputLayerTest, applyDeviceLayerRequestHandlesClearClientTarget) { |
| 1585 | mOutputLayer.editState().clearClientTarget = false; |
| 1586 | |
| 1587 | mOutputLayer.applyDeviceLayerRequest(Hwc2::IComposerClient::LayerRequest::CLEAR_CLIENT_TARGET); |
| 1588 | |
| 1589 | EXPECT_TRUE(mOutputLayer.getState().clearClientTarget); |
| 1590 | } |
| 1591 | |
| 1592 | TEST_F(OutputLayerTest, applyDeviceLayerRequestHandlesUnknownRequest) { |
| 1593 | mOutputLayer.editState().clearClientTarget = false; |
| 1594 | |
| 1595 | mOutputLayer.applyDeviceLayerRequest(static_cast<Hwc2::IComposerClient::LayerRequest>(0)); |
| 1596 | |
| 1597 | EXPECT_FALSE(mOutputLayer.getState().clearClientTarget); |
| 1598 | } |
| 1599 | |
Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 1600 | /* |
| 1601 | * OutputLayer::needsFiltering() |
| 1602 | */ |
| 1603 | |
| 1604 | TEST_F(OutputLayerTest, needsFilteringReturnsFalseIfDisplaySizeSameAsSourceSize) { |
| 1605 | mOutputLayer.editState().displayFrame = Rect(100, 100, 200, 200); |
| 1606 | mOutputLayer.editState().sourceCrop = FloatRect{0.f, 0.f, 100.f, 100.f}; |
| 1607 | |
| 1608 | EXPECT_FALSE(mOutputLayer.needsFiltering()); |
| 1609 | } |
| 1610 | |
| 1611 | TEST_F(OutputLayerTest, needsFilteringReturnsTrueIfDisplaySizeDifferentFromSourceSize) { |
| 1612 | mOutputLayer.editState().displayFrame = Rect(100, 100, 200, 200); |
| 1613 | mOutputLayer.editState().sourceCrop = FloatRect{0.f, 0.f, 100.1f, 100.1f}; |
| 1614 | |
| 1615 | EXPECT_TRUE(mOutputLayer.needsFiltering()); |
| 1616 | } |
| 1617 | |
Alec Mouri | b6d7893 | 2023-09-20 16:05:42 +0000 | [diff] [blame] | 1618 | TEST_F(OutputLayerTest, needsFilteringReturnsFalseIfRotatedDisplaySizeSameAsSourceSize) { |
| 1619 | mOutputLayer.editState().displayFrame = Rect(100, 100, 300, 200); |
| 1620 | mOutputLayer.editState().sourceCrop = FloatRect{0.f, 0.f, 100.f, 200.f}; |
| 1621 | mOutputLayer.editState().bufferTransform = Hwc2::Transform::ROT_90; |
| 1622 | |
| 1623 | EXPECT_FALSE(mOutputLayer.needsFiltering()); |
| 1624 | } |
| 1625 | |
| 1626 | TEST_F(OutputLayerTest, needsFilteringReturnsTrueIfRotatedDisplaySizeDiffersFromSourceSize) { |
| 1627 | mOutputLayer.editState().displayFrame = Rect(100, 100, 300, 200); |
| 1628 | mOutputLayer.editState().sourceCrop = FloatRect{0.f, 0.f, 100.f, 200.f}; |
| 1629 | |
| 1630 | EXPECT_TRUE(mOutputLayer.needsFiltering()); |
| 1631 | } |
| 1632 | |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 1633 | } // namespace |
| 1634 | } // namespace android::compositionengine |