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