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 | |
| 17 | #include <compositionengine/impl/OutputLayer.h> |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 18 | #include <compositionengine/impl/OutputLayerCompositionState.h> |
Lloyd Pique | 07e3321 | 2018-12-18 16:33:37 -0800 | [diff] [blame] | 19 | #include <compositionengine/mock/CompositionEngine.h> |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 20 | #include <compositionengine/mock/DisplayColorProfile.h> |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 21 | #include <compositionengine/mock/LayerFE.h> |
| 22 | #include <compositionengine/mock/Output.h> |
| 23 | #include <gtest/gtest.h> |
| 24 | |
Lloyd Pique | 07e3321 | 2018-12-18 16:33:37 -0800 | [diff] [blame] | 25 | #include "MockHWC2.h" |
| 26 | #include "MockHWComposer.h" |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 27 | #include "RegionMatcher.h" |
Lloyd Pique | 07e3321 | 2018-12-18 16:33:37 -0800 | [diff] [blame] | 28 | |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 29 | namespace android::compositionengine { |
| 30 | namespace { |
| 31 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame^] | 32 | namespace hal = android::hardware::graphics::composer::hal; |
| 33 | |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 34 | using testing::_; |
Lloyd Pique | 46b72df | 2019-10-29 13:19:27 -0700 | [diff] [blame] | 35 | using testing::InSequence; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 36 | using testing::Return; |
| 37 | using testing::ReturnRef; |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 38 | using testing::StrictMock; |
| 39 | |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 40 | constexpr auto TR_IDENT = 0u; |
| 41 | constexpr auto TR_FLP_H = HAL_TRANSFORM_FLIP_H; |
| 42 | constexpr auto TR_FLP_V = HAL_TRANSFORM_FLIP_V; |
| 43 | constexpr auto TR_ROT_90 = HAL_TRANSFORM_ROT_90; |
| 44 | constexpr auto TR_ROT_180 = TR_FLP_H | TR_FLP_V; |
| 45 | constexpr auto TR_ROT_270 = TR_ROT_90 | TR_ROT_180; |
| 46 | |
| 47 | const std::string kOutputName{"Test Output"}; |
| 48 | |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 49 | MATCHER_P(ColorEq, expected, "") { |
| 50 | *result_listener << "Colors are not equal\n"; |
| 51 | *result_listener << "expected " << expected.r << " " << expected.g << " " << expected.b << " " |
| 52 | << expected.a << "\n"; |
| 53 | *result_listener << "actual " << arg.r << " " << arg.g << " " << arg.b << " " << arg.a << "\n"; |
| 54 | |
| 55 | return expected.r == arg.r && expected.g == arg.g && expected.b == arg.b && expected.a == arg.a; |
| 56 | } |
| 57 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 58 | struct OutputLayerTest : public testing::Test { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 59 | struct OutputLayer final : public impl::OutputLayer { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 60 | OutputLayer(const compositionengine::Output& output, sp<compositionengine::LayerFE> layerFE) |
| 61 | : mOutput(output), mLayerFE(layerFE) {} |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 62 | ~OutputLayer() override = default; |
| 63 | |
| 64 | // compositionengine::OutputLayer overrides |
| 65 | const compositionengine::Output& getOutput() const override { return mOutput; } |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 66 | compositionengine::LayerFE& getLayerFE() const override { return *mLayerFE; } |
| 67 | const impl::OutputLayerCompositionState& getState() const override { return mState; } |
| 68 | impl::OutputLayerCompositionState& editState() override { return mState; } |
| 69 | |
| 70 | // compositionengine::impl::OutputLayer overrides |
| 71 | void dumpState(std::string& out) const override { mState.dump(out); } |
| 72 | |
| 73 | const compositionengine::Output& mOutput; |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 74 | sp<compositionengine::LayerFE> mLayerFE; |
| 75 | impl::OutputLayerCompositionState mState; |
| 76 | }; |
| 77 | |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 78 | OutputLayerTest() { |
| 79 | EXPECT_CALL(*mLayerFE, getDebugName()).WillRepeatedly(Return("Test LayerFE")); |
| 80 | EXPECT_CALL(mOutput, getName()).WillRepeatedly(ReturnRef(kOutputName)); |
| 81 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 82 | EXPECT_CALL(*mLayerFE, getCompositionState()).WillRepeatedly(Return(&mLayerFEState)); |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 83 | EXPECT_CALL(mOutput, getState()).WillRepeatedly(ReturnRef(mOutputState)); |
| 84 | } |
| 85 | |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 86 | compositionengine::mock::Output mOutput; |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 87 | sp<compositionengine::mock::LayerFE> mLayerFE{ |
| 88 | new StrictMock<compositionengine::mock::LayerFE>()}; |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 89 | OutputLayer mOutputLayer{mOutput, mLayerFE}; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 90 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 91 | LayerFECompositionState mLayerFEState; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 92 | impl::OutputCompositionState mOutputState; |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 93 | }; |
| 94 | |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 95 | /* |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 96 | * Basic construction |
| 97 | */ |
| 98 | |
| 99 | TEST_F(OutputLayerTest, canInstantiateOutputLayer) {} |
| 100 | |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 101 | /* |
Lloyd Pique | df336d9 | 2019-03-07 21:38:42 -0800 | [diff] [blame] | 102 | * OutputLayer::setHwcLayer() |
Lloyd Pique | 07e3321 | 2018-12-18 16:33:37 -0800 | [diff] [blame] | 103 | */ |
| 104 | |
Lloyd Pique | df336d9 | 2019-03-07 21:38:42 -0800 | [diff] [blame] | 105 | TEST_F(OutputLayerTest, settingNullHwcLayerSetsEmptyHwcState) { |
Lloyd Pique | 07e3321 | 2018-12-18 16:33:37 -0800 | [diff] [blame] | 106 | StrictMock<compositionengine::mock::CompositionEngine> compositionEngine; |
| 107 | |
Lloyd Pique | df336d9 | 2019-03-07 21:38:42 -0800 | [diff] [blame] | 108 | mOutputLayer.setHwcLayer(nullptr); |
Lloyd Pique | 07e3321 | 2018-12-18 16:33:37 -0800 | [diff] [blame] | 109 | |
| 110 | EXPECT_FALSE(mOutputLayer.getState().hwc); |
| 111 | } |
| 112 | |
Lloyd Pique | df336d9 | 2019-03-07 21:38:42 -0800 | [diff] [blame] | 113 | TEST_F(OutputLayerTest, settingHwcLayerSetsHwcState) { |
| 114 | auto hwcLayer = std::make_shared<StrictMock<HWC2::mock::Layer>>(); |
Lloyd Pique | 07e3321 | 2018-12-18 16:33:37 -0800 | [diff] [blame] | 115 | |
Lloyd Pique | df336d9 | 2019-03-07 21:38:42 -0800 | [diff] [blame] | 116 | mOutputLayer.setHwcLayer(hwcLayer); |
Lloyd Pique | 07e3321 | 2018-12-18 16:33:37 -0800 | [diff] [blame] | 117 | |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 118 | const auto& outputLayerState = mOutputLayer.getState(); |
| 119 | ASSERT_TRUE(outputLayerState.hwc); |
Lloyd Pique | 07e3321 | 2018-12-18 16:33:37 -0800 | [diff] [blame] | 120 | |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 121 | const auto& hwcState = *outputLayerState.hwc; |
Lloyd Pique | df336d9 | 2019-03-07 21:38:42 -0800 | [diff] [blame] | 122 | EXPECT_EQ(hwcLayer, hwcState.hwcLayer); |
Lloyd Pique | 07e3321 | 2018-12-18 16:33:37 -0800 | [diff] [blame] | 123 | } |
| 124 | |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 125 | /* |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 126 | * OutputLayer::calculateOutputSourceCrop() |
| 127 | */ |
| 128 | |
| 129 | struct OutputLayerSourceCropTest : public OutputLayerTest { |
| 130 | OutputLayerSourceCropTest() { |
| 131 | // Set reasonable default values for a simple case. Each test will |
| 132 | // set one specific value to something different. |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 133 | mLayerFEState.geomUsesSourceCrop = true; |
| 134 | mLayerFEState.geomContentCrop = Rect{0, 0, 1920, 1080}; |
| 135 | mLayerFEState.transparentRegionHint = Region{}; |
| 136 | mLayerFEState.geomLayerBounds = FloatRect{0.f, 0.f, 1920.f, 1080.f}; |
| 137 | mLayerFEState.geomLayerTransform = ui::Transform{TR_IDENT}; |
| 138 | mLayerFEState.geomBufferSize = Rect{0, 0, 1920, 1080}; |
| 139 | mLayerFEState.geomBufferTransform = TR_IDENT; |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 140 | |
| 141 | mOutputState.viewport = Rect{0, 0, 1920, 1080}; |
| 142 | } |
| 143 | |
| 144 | FloatRect calculateOutputSourceCrop() { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 145 | mLayerFEState.geomInverseLayerTransform = mLayerFEState.geomLayerTransform.inverse(); |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 146 | |
| 147 | return mOutputLayer.calculateOutputSourceCrop(); |
| 148 | } |
| 149 | }; |
| 150 | |
| 151 | TEST_F(OutputLayerSourceCropTest, computesEmptyIfSourceCropNotUsed) { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 152 | mLayerFEState.geomUsesSourceCrop = false; |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 153 | |
| 154 | const FloatRect expected{}; |
Lloyd Pique | ea62928 | 2019-12-03 15:57:10 -0800 | [diff] [blame] | 155 | EXPECT_THAT(calculateOutputSourceCrop(), expected); |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | TEST_F(OutputLayerSourceCropTest, correctForSimpleDefaultCase) { |
| 159 | const FloatRect expected{0.f, 0.f, 1920.f, 1080.f}; |
Lloyd Pique | ea62928 | 2019-12-03 15:57:10 -0800 | [diff] [blame] | 160 | EXPECT_THAT(calculateOutputSourceCrop(), expected); |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | TEST_F(OutputLayerSourceCropTest, handlesBoundsOutsideViewport) { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 164 | mLayerFEState.geomLayerBounds = FloatRect{-2000.f, -2000.f, 2000.f, 2000.f}; |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 165 | |
| 166 | const FloatRect expected{0.f, 0.f, 1920.f, 1080.f}; |
Lloyd Pique | ea62928 | 2019-12-03 15:57:10 -0800 | [diff] [blame] | 167 | EXPECT_THAT(calculateOutputSourceCrop(), expected); |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | TEST_F(OutputLayerSourceCropTest, handlesBoundsOutsideViewportRotated) { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 171 | mLayerFEState.geomLayerBounds = FloatRect{-2000.f, -2000.f, 2000.f, 2000.f}; |
| 172 | mLayerFEState.geomLayerTransform.set(HAL_TRANSFORM_ROT_90, 1920, 1080); |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 173 | |
| 174 | const FloatRect expected{0.f, 0.f, 1080.f, 1080.f}; |
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, calculateOutputSourceCropWorksWithATransformedBuffer) { |
| 179 | struct Entry { |
| 180 | uint32_t bufferInvDisplay; |
| 181 | uint32_t buffer; |
| 182 | uint32_t display; |
| 183 | FloatRect expected; |
| 184 | }; |
| 185 | // Not an exhaustive list of cases, but hopefully enough. |
| 186 | const std::array<Entry, 12> testData = { |
| 187 | // clang-format off |
| 188 | // inv buffer display expected |
| 189 | /* 0 */ Entry{false, TR_IDENT, TR_IDENT, FloatRect{0.f, 0.f, 1920.f, 1080.f}}, |
| 190 | /* 1 */ Entry{false, TR_IDENT, TR_ROT_90, FloatRect{0.f, 0.f, 1920.f, 1080.f}}, |
| 191 | /* 2 */ Entry{false, TR_IDENT, TR_ROT_180, FloatRect{0.f, 0.f, 1920.f, 1080.f}}, |
| 192 | /* 3 */ Entry{false, TR_IDENT, TR_ROT_270, FloatRect{0.f, 0.f, 1920.f, 1080.f}}, |
| 193 | |
| 194 | /* 4 */ Entry{true, TR_IDENT, TR_IDENT, FloatRect{0.f, 0.f, 1920.f, 1080.f}}, |
| 195 | /* 5 */ Entry{true, TR_IDENT, TR_ROT_90, FloatRect{0.f, 0.f, 1920.f, 1080.f}}, |
| 196 | /* 6 */ Entry{true, TR_IDENT, TR_ROT_180, FloatRect{0.f, 0.f, 1920.f, 1080.f}}, |
| 197 | /* 7 */ Entry{true, TR_IDENT, TR_ROT_270, FloatRect{0.f, 0.f, 1920.f, 1080.f}}, |
| 198 | |
| 199 | /* 8 */ Entry{false, TR_IDENT, TR_IDENT, FloatRect{0.f, 0.f, 1920.f, 1080.f}}, |
| 200 | /* 9 */ Entry{false, TR_ROT_90, TR_ROT_90, FloatRect{0.f, 0.f, 1920.f, 1080.f}}, |
| 201 | /* 10 */ Entry{false, TR_ROT_180, TR_ROT_180, FloatRect{0.f, 0.f, 1920.f, 1080.f}}, |
| 202 | /* 11 */ Entry{false, TR_ROT_270, TR_ROT_270, FloatRect{0.f, 0.f, 1920.f, 1080.f}}, |
| 203 | |
| 204 | // clang-format on |
| 205 | }; |
| 206 | |
| 207 | for (size_t i = 0; i < testData.size(); i++) { |
| 208 | const auto& entry = testData[i]; |
| 209 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 210 | mLayerFEState.geomBufferUsesDisplayInverseTransform = entry.bufferInvDisplay; |
| 211 | mLayerFEState.geomBufferTransform = entry.buffer; |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 212 | mOutputState.orientation = entry.display; |
| 213 | |
Lloyd Pique | ea62928 | 2019-12-03 15:57:10 -0800 | [diff] [blame] | 214 | EXPECT_THAT(calculateOutputSourceCrop(), entry.expected) << "entry " << i; |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 215 | } |
| 216 | } |
| 217 | |
| 218 | TEST_F(OutputLayerSourceCropTest, geomContentCropAffectsCrop) { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 219 | mLayerFEState.geomContentCrop = Rect{0, 0, 960, 540}; |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 220 | |
| 221 | const FloatRect expected{0.f, 0.f, 960.f, 540.f}; |
Lloyd Pique | ea62928 | 2019-12-03 15:57:10 -0800 | [diff] [blame] | 222 | EXPECT_THAT(calculateOutputSourceCrop(), expected); |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | TEST_F(OutputLayerSourceCropTest, viewportAffectsCrop) { |
| 226 | mOutputState.viewport = Rect{0, 0, 960, 540}; |
| 227 | |
| 228 | const FloatRect expected{0.f, 0.f, 960.f, 540.f}; |
Lloyd Pique | ea62928 | 2019-12-03 15:57:10 -0800 | [diff] [blame] | 229 | EXPECT_THAT(calculateOutputSourceCrop(), expected); |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | /* |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 233 | * OutputLayer::calculateOutputDisplayFrame() |
| 234 | */ |
| 235 | |
| 236 | struct OutputLayerDisplayFrameTest : public OutputLayerTest { |
| 237 | OutputLayerDisplayFrameTest() { |
| 238 | // Set reasonable default values for a simple case. Each test will |
| 239 | // set one specific value to something different. |
| 240 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 241 | mLayerFEState.transparentRegionHint = Region{}; |
| 242 | mLayerFEState.geomLayerTransform = ui::Transform{TR_IDENT}; |
| 243 | mLayerFEState.geomBufferSize = Rect{0, 0, 1920, 1080}; |
| 244 | mLayerFEState.geomBufferUsesDisplayInverseTransform = false; |
| 245 | mLayerFEState.geomCrop = Rect{0, 0, 1920, 1080}; |
| 246 | mLayerFEState.geomLayerBounds = FloatRect{0.f, 0.f, 1920.f, 1080.f}; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 247 | |
| 248 | mOutputState.viewport = Rect{0, 0, 1920, 1080}; |
| 249 | mOutputState.transform = ui::Transform{TR_IDENT}; |
| 250 | } |
| 251 | |
| 252 | Rect calculateOutputDisplayFrame() { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 253 | mLayerFEState.geomInverseLayerTransform = mLayerFEState.geomLayerTransform.inverse(); |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 254 | |
| 255 | return mOutputLayer.calculateOutputDisplayFrame(); |
| 256 | } |
| 257 | }; |
| 258 | |
| 259 | TEST_F(OutputLayerDisplayFrameTest, correctForSimpleDefaultCase) { |
| 260 | const Rect expected{0, 0, 1920, 1080}; |
Lloyd Pique | ea62928 | 2019-12-03 15:57:10 -0800 | [diff] [blame] | 261 | EXPECT_THAT(calculateOutputDisplayFrame(), expected); |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | TEST_F(OutputLayerDisplayFrameTest, fullActiveTransparentRegionReturnsEmptyFrame) { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 265 | mLayerFEState.transparentRegionHint = Region{Rect{0, 0, 1920, 1080}}; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 266 | const Rect expected{0, 0, 0, 0}; |
Lloyd Pique | ea62928 | 2019-12-03 15:57:10 -0800 | [diff] [blame] | 267 | EXPECT_THAT(calculateOutputDisplayFrame(), expected); |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | TEST_F(OutputLayerDisplayFrameTest, cropAffectsDisplayFrame) { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 271 | mLayerFEState.geomCrop = Rect{100, 200, 300, 500}; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 272 | const Rect expected{100, 200, 300, 500}; |
Lloyd Pique | ea62928 | 2019-12-03 15:57:10 -0800 | [diff] [blame] | 273 | EXPECT_THAT(calculateOutputDisplayFrame(), expected); |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | TEST_F(OutputLayerDisplayFrameTest, cropAffectsDisplayFrameRotated) { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 277 | mLayerFEState.geomCrop = Rect{100, 200, 300, 500}; |
| 278 | mLayerFEState.geomLayerTransform.set(HAL_TRANSFORM_ROT_90, 1920, 1080); |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 279 | const Rect expected{1420, 100, 1720, 300}; |
Lloyd Pique | ea62928 | 2019-12-03 15:57:10 -0800 | [diff] [blame] | 280 | EXPECT_THAT(calculateOutputDisplayFrame(), expected); |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | TEST_F(OutputLayerDisplayFrameTest, emptyGeomCropIsNotUsedToComputeFrame) { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 284 | mLayerFEState.geomCrop = Rect{}; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 285 | const Rect expected{0, 0, 1920, 1080}; |
Lloyd Pique | ea62928 | 2019-12-03 15:57:10 -0800 | [diff] [blame] | 286 | EXPECT_THAT(calculateOutputDisplayFrame(), expected); |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 287 | } |
| 288 | |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 289 | TEST_F(OutputLayerDisplayFrameTest, geomLayerBoundsAffectsFrame) { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 290 | mLayerFEState.geomLayerBounds = FloatRect{0.f, 0.f, 960.f, 540.f}; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 291 | const Rect expected{0, 0, 960, 540}; |
Lloyd Pique | ea62928 | 2019-12-03 15:57:10 -0800 | [diff] [blame] | 292 | EXPECT_THAT(calculateOutputDisplayFrame(), expected); |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | TEST_F(OutputLayerDisplayFrameTest, viewportAffectsFrame) { |
| 296 | mOutputState.viewport = Rect{0, 0, 960, 540}; |
| 297 | const Rect expected{0, 0, 960, 540}; |
Lloyd Pique | ea62928 | 2019-12-03 15:57:10 -0800 | [diff] [blame] | 298 | EXPECT_THAT(calculateOutputDisplayFrame(), expected); |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | TEST_F(OutputLayerDisplayFrameTest, outputTransformAffectsDisplayFrame) { |
| 302 | mOutputState.transform = ui::Transform{HAL_TRANSFORM_ROT_90}; |
| 303 | const Rect expected{-1080, 0, 0, 1920}; |
Lloyd Pique | ea62928 | 2019-12-03 15:57:10 -0800 | [diff] [blame] | 304 | EXPECT_THAT(calculateOutputDisplayFrame(), expected); |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | /* |
| 308 | * OutputLayer::calculateOutputRelativeBufferTransform() |
| 309 | */ |
| 310 | |
| 311 | TEST_F(OutputLayerTest, calculateOutputRelativeBufferTransformTestsNeeded) { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 312 | mLayerFEState.geomBufferUsesDisplayInverseTransform = false; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 313 | |
| 314 | struct Entry { |
| 315 | uint32_t layer; |
| 316 | uint32_t buffer; |
| 317 | uint32_t display; |
| 318 | uint32_t expected; |
| 319 | }; |
| 320 | // Not an exhaustive list of cases, but hopefully enough. |
| 321 | const std::array<Entry, 24> testData = { |
| 322 | // clang-format off |
| 323 | // layer buffer display expected |
| 324 | /* 0 */ Entry{TR_IDENT, TR_IDENT, TR_IDENT, TR_IDENT}, |
| 325 | /* 1 */ Entry{TR_IDENT, TR_IDENT, TR_ROT_90, TR_ROT_90}, |
| 326 | /* 2 */ Entry{TR_IDENT, TR_IDENT, TR_ROT_180, TR_ROT_180}, |
| 327 | /* 3 */ Entry{TR_IDENT, TR_IDENT, TR_ROT_270, TR_ROT_270}, |
| 328 | |
| 329 | /* 4 */ Entry{TR_IDENT, TR_FLP_H, TR_IDENT, TR_FLP_H ^ TR_IDENT}, |
| 330 | /* 5 */ Entry{TR_IDENT, TR_FLP_H, TR_ROT_90, TR_FLP_H ^ TR_ROT_90}, |
| 331 | /* 6 */ Entry{TR_IDENT, TR_FLP_H, TR_ROT_180, TR_FLP_H ^ TR_ROT_180}, |
| 332 | /* 7 */ Entry{TR_IDENT, TR_FLP_H, TR_ROT_270, TR_FLP_H ^ TR_ROT_270}, |
| 333 | |
| 334 | /* 8 */ Entry{TR_IDENT, TR_FLP_V, TR_IDENT, TR_FLP_V}, |
| 335 | /* 9 */ Entry{TR_IDENT, TR_ROT_90, TR_ROT_90, TR_ROT_180}, |
| 336 | /* 10 */ Entry{TR_IDENT, TR_ROT_180, TR_ROT_180, TR_IDENT}, |
| 337 | /* 11 */ Entry{TR_IDENT, TR_ROT_270, TR_ROT_270, TR_ROT_180}, |
| 338 | |
| 339 | /* 12 */ Entry{TR_ROT_90, TR_IDENT, TR_IDENT, TR_IDENT ^ TR_ROT_90}, |
| 340 | /* 13 */ Entry{TR_ROT_90, TR_FLP_H, TR_ROT_90, TR_FLP_H ^ TR_ROT_180}, |
| 341 | /* 14 */ Entry{TR_ROT_90, TR_IDENT, TR_ROT_180, TR_IDENT ^ TR_ROT_270}, |
| 342 | /* 15 */ Entry{TR_ROT_90, TR_FLP_H, TR_ROT_270, TR_FLP_H ^ TR_IDENT}, |
| 343 | |
| 344 | /* 16 */ Entry{TR_ROT_180, TR_FLP_H, TR_IDENT, TR_FLP_H ^ TR_ROT_180}, |
| 345 | /* 17 */ Entry{TR_ROT_180, TR_IDENT, TR_ROT_90, TR_IDENT ^ TR_ROT_270}, |
| 346 | /* 18 */ Entry{TR_ROT_180, TR_FLP_H, TR_ROT_180, TR_FLP_H ^ TR_IDENT}, |
| 347 | /* 19 */ Entry{TR_ROT_180, TR_IDENT, TR_ROT_270, TR_IDENT ^ TR_ROT_90}, |
| 348 | |
| 349 | /* 20 */ Entry{TR_ROT_270, TR_IDENT, TR_IDENT, TR_IDENT ^ TR_ROT_270}, |
| 350 | /* 21 */ Entry{TR_ROT_270, TR_FLP_H, TR_ROT_90, TR_FLP_H ^ TR_IDENT}, |
| 351 | /* 22 */ Entry{TR_ROT_270, TR_FLP_H, TR_ROT_180, TR_FLP_H ^ TR_ROT_90}, |
| 352 | /* 23 */ Entry{TR_ROT_270, TR_IDENT, TR_ROT_270, TR_IDENT ^ TR_ROT_180}, |
| 353 | // clang-format on |
| 354 | }; |
| 355 | |
| 356 | for (size_t i = 0; i < testData.size(); i++) { |
| 357 | const auto& entry = testData[i]; |
| 358 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 359 | mLayerFEState.geomLayerTransform.set(entry.layer, 1920, 1080); |
| 360 | mLayerFEState.geomBufferTransform = entry.buffer; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 361 | mOutputState.orientation = entry.display; |
Rashed Abdel-Tawab | 6643cd8 | 2019-10-29 10:01:56 -0700 | [diff] [blame] | 362 | mOutputState.transform = ui::Transform{entry.display}; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 363 | |
| 364 | auto actual = mOutputLayer.calculateOutputRelativeBufferTransform(); |
| 365 | EXPECT_EQ(entry.expected, actual) << "entry " << i; |
| 366 | } |
| 367 | } |
| 368 | |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 369 | TEST_F(OutputLayerTest, |
| 370 | calculateOutputRelativeBufferTransformTestWithOfBufferUsesDisplayInverseTransform) { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 371 | mLayerFEState.geomBufferUsesDisplayInverseTransform = true; |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 372 | |
| 373 | struct Entry { |
| 374 | uint32_t layer; |
| 375 | uint32_t buffer; |
| 376 | uint32_t display; |
| 377 | uint32_t expected; |
| 378 | }; |
| 379 | // Not an exhaustive list of cases, but hopefully enough. |
| 380 | const std::array<Entry, 24> testData = { |
| 381 | // clang-format off |
| 382 | // layer buffer display expected |
| 383 | /* 0 */ Entry{TR_IDENT, TR_IDENT, TR_IDENT, TR_IDENT}, |
| 384 | /* 1 */ Entry{TR_IDENT, TR_IDENT, TR_ROT_90, TR_IDENT}, |
| 385 | /* 2 */ Entry{TR_IDENT, TR_IDENT, TR_ROT_180, TR_IDENT}, |
| 386 | /* 3 */ Entry{TR_IDENT, TR_IDENT, TR_ROT_270, TR_IDENT}, |
| 387 | |
| 388 | /* 4 */ Entry{TR_IDENT, TR_FLP_H, TR_IDENT, TR_FLP_H}, |
| 389 | /* 5 */ Entry{TR_IDENT, TR_FLP_H, TR_ROT_90, TR_FLP_H}, |
| 390 | /* 6 */ Entry{TR_IDENT, TR_FLP_H, TR_ROT_180, TR_FLP_H}, |
| 391 | /* 7 */ Entry{TR_IDENT, TR_FLP_H, TR_ROT_270, TR_FLP_H}, |
| 392 | |
| 393 | /* 8 */ Entry{TR_IDENT, TR_FLP_V, TR_IDENT, TR_FLP_V}, |
| 394 | /* 9 */ Entry{TR_IDENT, TR_ROT_90, TR_ROT_90, TR_ROT_90}, |
| 395 | /* 10 */ Entry{TR_IDENT, TR_ROT_180, TR_ROT_180, TR_ROT_180}, |
| 396 | /* 11 */ Entry{TR_IDENT, TR_ROT_270, TR_ROT_270, TR_ROT_270}, |
| 397 | |
| 398 | /* 12 */ Entry{TR_ROT_90, TR_IDENT, TR_IDENT, TR_IDENT}, |
| 399 | /* 13 */ Entry{TR_ROT_90, TR_FLP_H, TR_ROT_90, TR_FLP_H}, |
| 400 | /* 14 */ Entry{TR_ROT_90, TR_IDENT, TR_ROT_180, TR_IDENT}, |
| 401 | /* 15 */ Entry{TR_ROT_90, TR_FLP_H, TR_ROT_270, TR_FLP_H}, |
| 402 | |
| 403 | /* 16 */ Entry{TR_ROT_180, TR_FLP_H, TR_IDENT, TR_FLP_H}, |
| 404 | /* 17 */ Entry{TR_ROT_180, TR_IDENT, TR_ROT_90, TR_IDENT}, |
| 405 | /* 18 */ Entry{TR_ROT_180, TR_FLP_H, TR_ROT_180, TR_FLP_H}, |
| 406 | /* 19 */ Entry{TR_ROT_180, TR_IDENT, TR_ROT_270, TR_IDENT}, |
| 407 | |
| 408 | /* 20 */ Entry{TR_ROT_270, TR_IDENT, TR_IDENT, TR_IDENT}, |
| 409 | /* 21 */ Entry{TR_ROT_270, TR_FLP_H, TR_ROT_90, TR_FLP_H}, |
| 410 | /* 22 */ Entry{TR_ROT_270, TR_FLP_H, TR_ROT_180, TR_FLP_H}, |
| 411 | /* 23 */ Entry{TR_ROT_270, TR_IDENT, TR_ROT_270, TR_IDENT}, |
| 412 | // clang-format on |
| 413 | }; |
| 414 | |
| 415 | for (size_t i = 0; i < testData.size(); i++) { |
| 416 | const auto& entry = testData[i]; |
| 417 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 418 | mLayerFEState.geomLayerTransform = ui::Transform{entry.layer}; |
| 419 | mLayerFEState.geomBufferTransform = entry.buffer; |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 420 | mOutputState.orientation = entry.display; |
Rashed Abdel-Tawab | 6643cd8 | 2019-10-29 10:01:56 -0700 | [diff] [blame] | 421 | mOutputState.transform = ui::Transform{entry.display}; |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 422 | |
| 423 | auto actual = mOutputLayer.calculateOutputRelativeBufferTransform(); |
| 424 | EXPECT_EQ(entry.expected, actual) << "entry " << i; |
| 425 | } |
| 426 | } |
| 427 | |
| 428 | /* |
| 429 | * OutputLayer::updateCompositionState() |
| 430 | */ |
| 431 | |
| 432 | struct OutputLayerPartialMockForUpdateCompositionState : public impl::OutputLayer { |
| 433 | OutputLayerPartialMockForUpdateCompositionState(const compositionengine::Output& output, |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 434 | sp<compositionengine::LayerFE> layerFE) |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 435 | : mOutput(output), mLayerFE(layerFE) {} |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 436 | // Mock everything called by updateCompositionState to simplify testing it. |
| 437 | MOCK_CONST_METHOD0(calculateOutputSourceCrop, FloatRect()); |
| 438 | MOCK_CONST_METHOD0(calculateOutputDisplayFrame, Rect()); |
| 439 | MOCK_CONST_METHOD0(calculateOutputRelativeBufferTransform, uint32_t()); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 440 | |
| 441 | // compositionengine::OutputLayer overrides |
| 442 | const compositionengine::Output& getOutput() const override { return mOutput; } |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 443 | compositionengine::LayerFE& getLayerFE() const override { return *mLayerFE; } |
| 444 | const impl::OutputLayerCompositionState& getState() const override { return mState; } |
| 445 | impl::OutputLayerCompositionState& editState() override { return mState; } |
| 446 | |
| 447 | // These need implementations though are not expected to be called. |
| 448 | MOCK_CONST_METHOD1(dumpState, void(std::string&)); |
| 449 | |
| 450 | const compositionengine::Output& mOutput; |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 451 | sp<compositionengine::LayerFE> mLayerFE; |
| 452 | impl::OutputLayerCompositionState mState; |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 453 | }; |
| 454 | |
| 455 | struct OutputLayerUpdateCompositionStateTest : public OutputLayerTest { |
| 456 | public: |
| 457 | OutputLayerUpdateCompositionStateTest() { |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 458 | EXPECT_CALL(mOutput, getState()).WillRepeatedly(ReturnRef(mOutputState)); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 459 | EXPECT_CALL(mOutput, getDisplayColorProfile()) |
| 460 | .WillRepeatedly(Return(&mDisplayColorProfile)); |
| 461 | EXPECT_CALL(mDisplayColorProfile, isDataspaceSupported(_)).WillRepeatedly(Return(true)); |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 462 | } |
| 463 | |
| 464 | ~OutputLayerUpdateCompositionStateTest() = default; |
| 465 | |
| 466 | void setupGeometryChildCallValues() { |
| 467 | EXPECT_CALL(mOutputLayer, calculateOutputSourceCrop()).WillOnce(Return(kSourceCrop)); |
| 468 | EXPECT_CALL(mOutputLayer, calculateOutputDisplayFrame()).WillOnce(Return(kDisplayFrame)); |
| 469 | EXPECT_CALL(mOutputLayer, calculateOutputRelativeBufferTransform()) |
| 470 | .WillOnce(Return(mBufferTransform)); |
| 471 | } |
| 472 | |
| 473 | void validateComputedGeometryState() { |
| 474 | const auto& state = mOutputLayer.getState(); |
| 475 | EXPECT_EQ(kSourceCrop, state.sourceCrop); |
| 476 | EXPECT_EQ(kDisplayFrame, state.displayFrame); |
| 477 | EXPECT_EQ(static_cast<Hwc2::Transform>(mBufferTransform), state.bufferTransform); |
| 478 | } |
| 479 | |
| 480 | const FloatRect kSourceCrop{1.f, 2.f, 3.f, 4.f}; |
| 481 | const Rect kDisplayFrame{11, 12, 13, 14}; |
| 482 | uint32_t mBufferTransform{21}; |
| 483 | |
| 484 | using OutputLayer = OutputLayerPartialMockForUpdateCompositionState; |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 485 | StrictMock<OutputLayer> mOutputLayer{mOutput, mLayerFE}; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 486 | StrictMock<mock::DisplayColorProfile> mDisplayColorProfile; |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 487 | }; |
| 488 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 489 | TEST_F(OutputLayerUpdateCompositionStateTest, doesNothingIfNoFECompositionState) { |
| 490 | EXPECT_CALL(*mLayerFE, getCompositionState()).WillOnce(Return(nullptr)); |
| 491 | |
| 492 | mOutputLayer.updateCompositionState(true, false); |
| 493 | } |
| 494 | |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 495 | TEST_F(OutputLayerUpdateCompositionStateTest, setsStateNormally) { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 496 | mLayerFEState.isSecure = true; |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 497 | mOutputState.isSecure = true; |
Lloyd Pique | fe67102 | 2019-09-24 10:43:03 -0700 | [diff] [blame] | 498 | mOutputLayer.editState().forceClientComposition = true; |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 499 | |
| 500 | setupGeometryChildCallValues(); |
| 501 | |
Lloyd Pique | 7a23491 | 2019-10-03 11:54:27 -0700 | [diff] [blame] | 502 | mOutputLayer.updateCompositionState(true, false); |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 503 | |
| 504 | validateComputedGeometryState(); |
| 505 | |
| 506 | EXPECT_EQ(false, mOutputLayer.getState().forceClientComposition); |
| 507 | } |
| 508 | |
| 509 | TEST_F(OutputLayerUpdateCompositionStateTest, |
| 510 | alsoSetsForceCompositionIfSecureLayerOnNonsecureOutput) { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 511 | mLayerFEState.isSecure = true; |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 512 | mOutputState.isSecure = false; |
| 513 | |
| 514 | setupGeometryChildCallValues(); |
| 515 | |
Lloyd Pique | 7a23491 | 2019-10-03 11:54:27 -0700 | [diff] [blame] | 516 | mOutputLayer.updateCompositionState(true, false); |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 517 | |
| 518 | validateComputedGeometryState(); |
| 519 | |
| 520 | EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition); |
| 521 | } |
| 522 | |
| 523 | TEST_F(OutputLayerUpdateCompositionStateTest, |
| 524 | alsoSetsForceCompositionIfUnsupportedBufferTransform) { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 525 | mLayerFEState.isSecure = true; |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 526 | mOutputState.isSecure = true; |
| 527 | |
| 528 | mBufferTransform = ui::Transform::ROT_INVALID; |
| 529 | |
| 530 | setupGeometryChildCallValues(); |
| 531 | |
Lloyd Pique | 7a23491 | 2019-10-03 11:54:27 -0700 | [diff] [blame] | 532 | mOutputLayer.updateCompositionState(true, false); |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 533 | |
| 534 | validateComputedGeometryState(); |
| 535 | |
| 536 | EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition); |
| 537 | } |
| 538 | |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 539 | TEST_F(OutputLayerUpdateCompositionStateTest, setsOutputLayerColorspaceCorrectly) { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 540 | mLayerFEState.dataspace = ui::Dataspace::DISPLAY_P3; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 541 | mOutputState.targetDataspace = ui::Dataspace::V0_SCRGB; |
| 542 | |
| 543 | // If the layer is not colorspace agnostic, the output layer dataspace |
| 544 | // should use the layers requested colorspace. |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 545 | mLayerFEState.isColorspaceAgnostic = false; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 546 | |
Lloyd Pique | 7a23491 | 2019-10-03 11:54:27 -0700 | [diff] [blame] | 547 | mOutputLayer.updateCompositionState(false, false); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 548 | |
| 549 | EXPECT_EQ(ui::Dataspace::DISPLAY_P3, mOutputLayer.getState().dataspace); |
| 550 | |
| 551 | // If the layer is colorspace agnostic, the output layer dataspace |
| 552 | // should use the colorspace chosen for the whole output. |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 553 | mLayerFEState.isColorspaceAgnostic = true; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 554 | |
Lloyd Pique | 7a23491 | 2019-10-03 11:54:27 -0700 | [diff] [blame] | 555 | mOutputLayer.updateCompositionState(false, false); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 556 | |
| 557 | EXPECT_EQ(ui::Dataspace::V0_SCRGB, mOutputLayer.getState().dataspace); |
| 558 | } |
| 559 | |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 560 | TEST_F(OutputLayerUpdateCompositionStateTest, doesNotRecomputeGeometryIfNotRequested) { |
Lloyd Pique | fe67102 | 2019-09-24 10:43:03 -0700 | [diff] [blame] | 561 | mOutputLayer.editState().forceClientComposition = false; |
| 562 | |
Lloyd Pique | 7a23491 | 2019-10-03 11:54:27 -0700 | [diff] [blame] | 563 | mOutputLayer.updateCompositionState(false, false); |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 564 | |
| 565 | EXPECT_EQ(false, mOutputLayer.getState().forceClientComposition); |
| 566 | } |
| 567 | |
Lloyd Pique | fe67102 | 2019-09-24 10:43:03 -0700 | [diff] [blame] | 568 | TEST_F(OutputLayerUpdateCompositionStateTest, |
| 569 | doesNotClearForceClientCompositionIfNotDoingGeometry) { |
| 570 | mOutputLayer.editState().forceClientComposition = true; |
| 571 | |
Lloyd Pique | 7a23491 | 2019-10-03 11:54:27 -0700 | [diff] [blame] | 572 | mOutputLayer.updateCompositionState(false, false); |
Lloyd Pique | fe67102 | 2019-09-24 10:43:03 -0700 | [diff] [blame] | 573 | |
| 574 | EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition); |
| 575 | } |
| 576 | |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 577 | TEST_F(OutputLayerUpdateCompositionStateTest, clientCompositionForcedFromFrontEndFlagAtAnyTime) { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 578 | mLayerFEState.forceClientComposition = true; |
Lloyd Pique | fe67102 | 2019-09-24 10:43:03 -0700 | [diff] [blame] | 579 | mOutputLayer.editState().forceClientComposition = false; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 580 | |
Lloyd Pique | 7a23491 | 2019-10-03 11:54:27 -0700 | [diff] [blame] | 581 | mOutputLayer.updateCompositionState(false, false); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 582 | |
| 583 | EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition); |
| 584 | } |
| 585 | |
| 586 | TEST_F(OutputLayerUpdateCompositionStateTest, |
| 587 | clientCompositionForcedFromUnsupportedDataspaceAtAnyTime) { |
Lloyd Pique | fe67102 | 2019-09-24 10:43:03 -0700 | [diff] [blame] | 588 | mOutputLayer.editState().forceClientComposition = false; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 589 | EXPECT_CALL(mDisplayColorProfile, isDataspaceSupported(_)).WillRepeatedly(Return(false)); |
| 590 | |
Lloyd Pique | 7a23491 | 2019-10-03 11:54:27 -0700 | [diff] [blame] | 591 | mOutputLayer.updateCompositionState(false, false); |
| 592 | |
| 593 | EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition); |
| 594 | } |
| 595 | |
| 596 | TEST_F(OutputLayerUpdateCompositionStateTest, clientCompositionForcedFromArgumentFlag) { |
| 597 | mLayerFEState.forceClientComposition = false; |
| 598 | mOutputLayer.editState().forceClientComposition = false; |
| 599 | |
| 600 | mOutputLayer.updateCompositionState(false, true); |
| 601 | |
| 602 | EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition); |
| 603 | |
| 604 | mOutputLayer.editState().forceClientComposition = false; |
| 605 | |
| 606 | setupGeometryChildCallValues(); |
| 607 | |
| 608 | mOutputLayer.updateCompositionState(true, true); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 609 | |
| 610 | EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition); |
| 611 | } |
| 612 | |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 613 | /* |
| 614 | * OutputLayer::writeStateToHWC() |
| 615 | */ |
| 616 | |
| 617 | struct OutputLayerWriteStateToHWCTest : public OutputLayerTest { |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame^] | 618 | static constexpr hal::Error kError = hal::Error::UNSUPPORTED; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 619 | static constexpr FloatRect kSourceCrop{11.f, 12.f, 13.f, 14.f}; |
| 620 | static constexpr uint32_t kZOrder = 21u; |
| 621 | static constexpr Hwc2::Transform kBufferTransform = static_cast<Hwc2::Transform>(31); |
| 622 | static constexpr Hwc2::IComposerClient::BlendMode kBlendMode = |
| 623 | static_cast<Hwc2::IComposerClient::BlendMode>(41); |
| 624 | static constexpr float kAlpha = 51.f; |
| 625 | static constexpr uint32_t kType = 61u; |
| 626 | static constexpr uint32_t kAppId = 62u; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 627 | static constexpr ui::Dataspace kDataspace = static_cast<ui::Dataspace>(71); |
| 628 | static constexpr int kSupportedPerFrameMetadata = 101; |
| 629 | static constexpr int kExpectedHwcSlot = 0; |
Lloyd Pique | 8d9f836 | 2020-02-11 19:13:09 -0800 | [diff] [blame] | 630 | static constexpr bool kLayerGenericMetadata1Mandatory = true; |
| 631 | static constexpr bool kLayerGenericMetadata2Mandatory = true; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 632 | |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 633 | static const half4 kColor; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 634 | static const Rect kDisplayFrame; |
Lloyd Pique | a246866 | 2019-03-07 21:31:06 -0800 | [diff] [blame] | 635 | static const Region kOutputSpaceVisibleRegion; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 636 | static const mat4 kColorTransform; |
| 637 | static const Region kSurfaceDamage; |
| 638 | static const HdrMetadata kHdrMetadata; |
| 639 | static native_handle_t* kSidebandStreamHandle; |
| 640 | static const sp<GraphicBuffer> kBuffer; |
| 641 | static const sp<Fence> kFence; |
Lloyd Pique | 8d9f836 | 2020-02-11 19:13:09 -0800 | [diff] [blame] | 642 | static const std::string kLayerGenericMetadata1Key; |
| 643 | static const std::vector<uint8_t> kLayerGenericMetadata1Value; |
| 644 | static const std::string kLayerGenericMetadata2Key; |
| 645 | static const std::vector<uint8_t> kLayerGenericMetadata2Value; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 646 | |
| 647 | OutputLayerWriteStateToHWCTest() { |
| 648 | auto& outputLayerState = mOutputLayer.editState(); |
| 649 | outputLayerState.hwc = impl::OutputLayerCompositionState::Hwc(mHwcLayer); |
| 650 | |
| 651 | outputLayerState.displayFrame = kDisplayFrame; |
| 652 | outputLayerState.sourceCrop = kSourceCrop; |
| 653 | outputLayerState.z = kZOrder; |
| 654 | outputLayerState.bufferTransform = static_cast<Hwc2::Transform>(kBufferTransform); |
Lloyd Pique | a246866 | 2019-03-07 21:31:06 -0800 | [diff] [blame] | 655 | outputLayerState.outputSpaceVisibleRegion = kOutputSpaceVisibleRegion; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 656 | outputLayerState.dataspace = kDataspace; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 657 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 658 | mLayerFEState.blendMode = kBlendMode; |
| 659 | mLayerFEState.alpha = kAlpha; |
| 660 | mLayerFEState.type = kType; |
| 661 | mLayerFEState.appId = kAppId; |
| 662 | mLayerFEState.colorTransform = kColorTransform; |
| 663 | mLayerFEState.color = kColor; |
| 664 | mLayerFEState.surfaceDamage = kSurfaceDamage; |
| 665 | mLayerFEState.hdrMetadata = kHdrMetadata; |
| 666 | mLayerFEState.sidebandStream = NativeHandle::create(kSidebandStreamHandle, false); |
| 667 | mLayerFEState.buffer = kBuffer; |
| 668 | mLayerFEState.bufferSlot = BufferQueue::INVALID_BUFFER_SLOT; |
| 669 | mLayerFEState.acquireFence = kFence; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 670 | |
| 671 | EXPECT_CALL(mOutput, getDisplayColorProfile()) |
| 672 | .WillRepeatedly(Return(&mDisplayColorProfile)); |
| 673 | EXPECT_CALL(mDisplayColorProfile, getSupportedPerFrameMetadata()) |
| 674 | .WillRepeatedly(Return(kSupportedPerFrameMetadata)); |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 675 | } |
| 676 | |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 677 | // Some tests may need to simulate unsupported HWC calls |
| 678 | enum class SimulateUnsupported { None, ColorTransform }; |
| 679 | |
Lloyd Pique | 8d9f836 | 2020-02-11 19:13:09 -0800 | [diff] [blame] | 680 | void includeGenericLayerMetadataInState() { |
| 681 | mLayerFEState.metadata[kLayerGenericMetadata1Key] = {kLayerGenericMetadata1Mandatory, |
| 682 | kLayerGenericMetadata1Value}; |
| 683 | mLayerFEState.metadata[kLayerGenericMetadata2Key] = {kLayerGenericMetadata2Mandatory, |
| 684 | kLayerGenericMetadata2Value}; |
| 685 | } |
| 686 | |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 687 | void expectGeometryCommonCalls() { |
| 688 | EXPECT_CALL(*mHwcLayer, setDisplayFrame(kDisplayFrame)).WillOnce(Return(kError)); |
| 689 | EXPECT_CALL(*mHwcLayer, setSourceCrop(kSourceCrop)).WillOnce(Return(kError)); |
| 690 | EXPECT_CALL(*mHwcLayer, setZOrder(kZOrder)).WillOnce(Return(kError)); |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame^] | 691 | EXPECT_CALL(*mHwcLayer, setTransform(kBufferTransform)).WillOnce(Return(kError)); |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 692 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame^] | 693 | EXPECT_CALL(*mHwcLayer, setBlendMode(kBlendMode)).WillOnce(Return(kError)); |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 694 | EXPECT_CALL(*mHwcLayer, setPlaneAlpha(kAlpha)).WillOnce(Return(kError)); |
| 695 | EXPECT_CALL(*mHwcLayer, setInfo(kType, kAppId)).WillOnce(Return(kError)); |
| 696 | } |
| 697 | |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 698 | void expectPerFrameCommonCalls(SimulateUnsupported unsupported = SimulateUnsupported::None) { |
Lloyd Pique | a246866 | 2019-03-07 21:31:06 -0800 | [diff] [blame] | 699 | EXPECT_CALL(*mHwcLayer, setVisibleRegion(RegionEq(kOutputSpaceVisibleRegion))) |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 700 | .WillOnce(Return(kError)); |
| 701 | EXPECT_CALL(*mHwcLayer, setDataspace(kDataspace)).WillOnce(Return(kError)); |
| 702 | EXPECT_CALL(*mHwcLayer, setColorTransform(kColorTransform)) |
| 703 | .WillOnce(Return(unsupported == SimulateUnsupported::ColorTransform |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame^] | 704 | ? hal::Error::UNSUPPORTED |
| 705 | : hal::Error::NONE)); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 706 | EXPECT_CALL(*mHwcLayer, setSurfaceDamage(RegionEq(kSurfaceDamage))) |
| 707 | .WillOnce(Return(kError)); |
| 708 | } |
| 709 | |
| 710 | void expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition compositionType) { |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame^] | 711 | EXPECT_CALL(*mHwcLayer, setCompositionType(compositionType)).WillOnce(Return(kError)); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 712 | } |
| 713 | |
| 714 | void expectNoSetCompositionTypeCall() { |
| 715 | EXPECT_CALL(*mHwcLayer, setCompositionType(_)).Times(0); |
| 716 | } |
| 717 | |
| 718 | void expectSetColorCall() { |
| 719 | hwc_color_t color = {static_cast<uint8_t>(std::round(kColor.r * 255)), |
| 720 | static_cast<uint8_t>(std::round(kColor.g * 255)), |
| 721 | static_cast<uint8_t>(std::round(kColor.b * 255)), 255}; |
| 722 | |
| 723 | EXPECT_CALL(*mHwcLayer, setColor(ColorEq(color))).WillOnce(Return(kError)); |
| 724 | } |
| 725 | |
| 726 | void expectSetSidebandHandleCall() { |
| 727 | EXPECT_CALL(*mHwcLayer, setSidebandStream(kSidebandStreamHandle)); |
| 728 | } |
| 729 | |
| 730 | void expectSetHdrMetadataAndBufferCalls() { |
| 731 | EXPECT_CALL(*mHwcLayer, setPerFrameMetadata(kSupportedPerFrameMetadata, kHdrMetadata)); |
| 732 | EXPECT_CALL(*mHwcLayer, setBuffer(kExpectedHwcSlot, kBuffer, kFence)); |
| 733 | } |
| 734 | |
Lloyd Pique | 8d9f836 | 2020-02-11 19:13:09 -0800 | [diff] [blame] | 735 | void expectGenericLayerMetadataCalls() { |
| 736 | // Note: Can be in any order. |
| 737 | EXPECT_CALL(*mHwcLayer, |
| 738 | setLayerGenericMetadata(kLayerGenericMetadata1Key, |
| 739 | kLayerGenericMetadata1Mandatory, |
| 740 | kLayerGenericMetadata1Value)); |
| 741 | EXPECT_CALL(*mHwcLayer, |
| 742 | setLayerGenericMetadata(kLayerGenericMetadata2Key, |
| 743 | kLayerGenericMetadata2Mandatory, |
| 744 | kLayerGenericMetadata2Value)); |
| 745 | } |
| 746 | |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 747 | 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] | 748 | StrictMock<mock::DisplayColorProfile> mDisplayColorProfile; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 749 | }; |
| 750 | |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 751 | const half4 OutputLayerWriteStateToHWCTest::kColor{81.f / 255.f, 82.f / 255.f, 83.f / 255.f, |
| 752 | 84.f / 255.f}; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 753 | const Rect OutputLayerWriteStateToHWCTest::kDisplayFrame{1001, 1002, 1003, 10044}; |
Lloyd Pique | a246866 | 2019-03-07 21:31:06 -0800 | [diff] [blame] | 754 | const Region OutputLayerWriteStateToHWCTest::kOutputSpaceVisibleRegion{ |
| 755 | Rect{1005, 1006, 1007, 1008}}; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 756 | const mat4 OutputLayerWriteStateToHWCTest::kColorTransform{ |
| 757 | 1009, 1010, 1011, 1012, 1013, 1014, 1015, 1016, |
| 758 | 1017, 1018, 1019, 1020, 1021, 1022, 1023, 1024, |
| 759 | }; |
| 760 | const Region OutputLayerWriteStateToHWCTest::kSurfaceDamage{Rect{1025, 1026, 1027, 1028}}; |
| 761 | const HdrMetadata OutputLayerWriteStateToHWCTest::kHdrMetadata{{/* LightFlattenable */}, 1029}; |
| 762 | native_handle_t* OutputLayerWriteStateToHWCTest::kSidebandStreamHandle = |
| 763 | reinterpret_cast<native_handle_t*>(1031); |
| 764 | const sp<GraphicBuffer> OutputLayerWriteStateToHWCTest::kBuffer; |
| 765 | const sp<Fence> OutputLayerWriteStateToHWCTest::kFence; |
Lloyd Pique | 8d9f836 | 2020-02-11 19:13:09 -0800 | [diff] [blame] | 766 | const std::string OutputLayerWriteStateToHWCTest::kLayerGenericMetadata1Key = |
| 767 | "com.example.metadata.1"; |
| 768 | const std::vector<uint8_t> OutputLayerWriteStateToHWCTest::kLayerGenericMetadata1Value{{1, 2, 3}}; |
| 769 | const std::string OutputLayerWriteStateToHWCTest::kLayerGenericMetadata2Key = |
| 770 | "com.example.metadata.2"; |
| 771 | const std::vector<uint8_t> OutputLayerWriteStateToHWCTest::kLayerGenericMetadata2Value{ |
| 772 | {4, 5, 6, 7}}; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 773 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 774 | TEST_F(OutputLayerWriteStateToHWCTest, doesNothingIfNoFECompositionState) { |
| 775 | EXPECT_CALL(*mLayerFE, getCompositionState()).WillOnce(Return(nullptr)); |
| 776 | |
| 777 | mOutputLayer.writeStateToHWC(true); |
| 778 | } |
| 779 | |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 780 | TEST_F(OutputLayerWriteStateToHWCTest, doesNothingIfNoHWCState) { |
| 781 | mOutputLayer.editState().hwc.reset(); |
| 782 | |
| 783 | mOutputLayer.writeStateToHWC(true); |
| 784 | } |
| 785 | |
| 786 | TEST_F(OutputLayerWriteStateToHWCTest, doesNothingIfNoHWCLayer) { |
| 787 | mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc(nullptr); |
| 788 | |
| 789 | mOutputLayer.writeStateToHWC(true); |
| 790 | } |
| 791 | |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 792 | TEST_F(OutputLayerWriteStateToHWCTest, canSetAllState) { |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 793 | expectGeometryCommonCalls(); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 794 | expectPerFrameCommonCalls(); |
| 795 | |
| 796 | expectNoSetCompositionTypeCall(); |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 797 | |
| 798 | mOutputLayer.writeStateToHWC(true); |
| 799 | } |
| 800 | |
Rashed Abdel-Tawab | 6643cd8 | 2019-10-29 10:01:56 -0700 | [diff] [blame] | 801 | TEST_F(OutputLayerTest, displayInstallOrientationBufferTransformSetTo90) { |
| 802 | mLayerFEState.geomBufferUsesDisplayInverseTransform = false; |
| 803 | mLayerFEState.geomLayerTransform = ui::Transform{TR_IDENT}; |
| 804 | // This test simulates a scenario where displayInstallOrientation is set to |
| 805 | // ROT_90. This only has an effect on the transform; orientation stays 0 (see |
| 806 | // DisplayDevice::setProjection). |
| 807 | mOutputState.orientation = TR_IDENT; |
| 808 | mOutputState.transform = ui::Transform{TR_ROT_90}; |
| 809 | // Buffers are pre-rotated based on the transform hint (ROT_90); their |
| 810 | // geomBufferTransform is set to the inverse transform. |
| 811 | mLayerFEState.geomBufferTransform = TR_ROT_270; |
| 812 | |
| 813 | EXPECT_EQ(TR_IDENT, mOutputLayer.calculateOutputRelativeBufferTransform()); |
| 814 | } |
| 815 | |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 816 | TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForSolidColor) { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 817 | mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::SOLID_COLOR; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 818 | |
| 819 | expectPerFrameCommonCalls(); |
Lloyd Pique | 46b72df | 2019-10-29 13:19:27 -0700 | [diff] [blame] | 820 | |
| 821 | // Setting the composition type should happen before setting the color. We |
| 822 | // check this in this test only by setting up an testing::InSeqeuence |
| 823 | // instance before setting up the two expectations. |
| 824 | InSequence s; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 825 | expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::SOLID_COLOR); |
Lloyd Pique | 46b72df | 2019-10-29 13:19:27 -0700 | [diff] [blame] | 826 | expectSetColorCall(); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 827 | |
| 828 | mOutputLayer.writeStateToHWC(false); |
| 829 | } |
| 830 | |
| 831 | TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForSideband) { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 832 | mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::SIDEBAND; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 833 | |
| 834 | expectPerFrameCommonCalls(); |
| 835 | expectSetSidebandHandleCall(); |
| 836 | expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::SIDEBAND); |
| 837 | |
| 838 | mOutputLayer.writeStateToHWC(false); |
| 839 | } |
| 840 | |
| 841 | TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForCursor) { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 842 | mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::CURSOR; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 843 | |
| 844 | expectPerFrameCommonCalls(); |
| 845 | expectSetHdrMetadataAndBufferCalls(); |
| 846 | expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::CURSOR); |
| 847 | |
| 848 | mOutputLayer.writeStateToHWC(false); |
| 849 | } |
| 850 | |
| 851 | TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForDevice) { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 852 | mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::DEVICE; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 853 | |
| 854 | expectPerFrameCommonCalls(); |
| 855 | expectSetHdrMetadataAndBufferCalls(); |
| 856 | expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::DEVICE); |
| 857 | |
| 858 | mOutputLayer.writeStateToHWC(false); |
| 859 | } |
| 860 | |
| 861 | TEST_F(OutputLayerWriteStateToHWCTest, compositionTypeIsNotSetIfUnchanged) { |
| 862 | (*mOutputLayer.editState().hwc).hwcCompositionType = |
| 863 | Hwc2::IComposerClient::Composition::SOLID_COLOR; |
| 864 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 865 | mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::SOLID_COLOR; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 866 | |
| 867 | expectPerFrameCommonCalls(); |
| 868 | expectSetColorCall(); |
| 869 | expectNoSetCompositionTypeCall(); |
| 870 | |
| 871 | mOutputLayer.writeStateToHWC(false); |
| 872 | } |
| 873 | |
| 874 | TEST_F(OutputLayerWriteStateToHWCTest, compositionTypeIsSetToClientIfColorTransformNotSupported) { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 875 | mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::SOLID_COLOR; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 876 | |
| 877 | expectPerFrameCommonCalls(SimulateUnsupported::ColorTransform); |
| 878 | expectSetColorCall(); |
| 879 | expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::CLIENT); |
| 880 | |
| 881 | mOutputLayer.writeStateToHWC(false); |
| 882 | } |
| 883 | |
| 884 | TEST_F(OutputLayerWriteStateToHWCTest, compositionTypeIsSetToClientIfClientCompositionForced) { |
| 885 | mOutputLayer.editState().forceClientComposition = true; |
| 886 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 887 | mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::SOLID_COLOR; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 888 | |
| 889 | expectPerFrameCommonCalls(); |
| 890 | expectSetColorCall(); |
| 891 | expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::CLIENT); |
| 892 | |
| 893 | mOutputLayer.writeStateToHWC(false); |
| 894 | } |
| 895 | |
Lloyd Pique | 8d9f836 | 2020-02-11 19:13:09 -0800 | [diff] [blame] | 896 | TEST_F(OutputLayerWriteStateToHWCTest, allStateIncludesMetadataIfPresent) { |
| 897 | mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::DEVICE; |
| 898 | includeGenericLayerMetadataInState(); |
| 899 | |
| 900 | expectGeometryCommonCalls(); |
| 901 | expectPerFrameCommonCalls(); |
| 902 | expectSetHdrMetadataAndBufferCalls(); |
| 903 | expectGenericLayerMetadataCalls(); |
| 904 | expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::DEVICE); |
| 905 | |
| 906 | mOutputLayer.writeStateToHWC(true); |
| 907 | } |
| 908 | |
| 909 | TEST_F(OutputLayerWriteStateToHWCTest, perFrameStateDoesNotIncludeMetadataIfPresent) { |
| 910 | mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::DEVICE; |
| 911 | includeGenericLayerMetadataInState(); |
| 912 | |
| 913 | expectPerFrameCommonCalls(); |
| 914 | expectSetHdrMetadataAndBufferCalls(); |
| 915 | expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::DEVICE); |
| 916 | |
| 917 | mOutputLayer.writeStateToHWC(false); |
| 918 | } |
| 919 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 920 | /* |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 921 | * OutputLayer::writeCursorPositionToHWC() |
| 922 | */ |
| 923 | |
| 924 | struct OutputLayerWriteCursorPositionToHWCTest : public OutputLayerTest { |
| 925 | static constexpr int kDefaultTransform = TR_IDENT; |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame^] | 926 | static constexpr hal::Error kDefaultError = hal::Error::UNSUPPORTED; |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 927 | |
| 928 | static const Rect kDefaultDisplayViewport; |
| 929 | static const Rect kDefaultCursorFrame; |
| 930 | |
| 931 | OutputLayerWriteCursorPositionToHWCTest() { |
| 932 | auto& outputLayerState = mOutputLayer.editState(); |
| 933 | outputLayerState.hwc = impl::OutputLayerCompositionState::Hwc(mHwcLayer); |
| 934 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 935 | mLayerFEState.cursorFrame = kDefaultCursorFrame; |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 936 | |
| 937 | mOutputState.viewport = kDefaultDisplayViewport; |
| 938 | mOutputState.transform = ui::Transform{kDefaultTransform}; |
| 939 | } |
| 940 | |
| 941 | std::shared_ptr<HWC2::mock::Layer> mHwcLayer{std::make_shared<StrictMock<HWC2::mock::Layer>>()}; |
| 942 | }; |
| 943 | |
| 944 | const Rect OutputLayerWriteCursorPositionToHWCTest::kDefaultDisplayViewport{0, 0, 1920, 1080}; |
| 945 | const Rect OutputLayerWriteCursorPositionToHWCTest::kDefaultCursorFrame{1, 2, 3, 4}; |
| 946 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 947 | TEST_F(OutputLayerWriteCursorPositionToHWCTest, doesNothingIfNoFECompositionState) { |
| 948 | EXPECT_CALL(*mLayerFE, getCompositionState()).WillOnce(Return(nullptr)); |
| 949 | |
| 950 | mOutputLayer.writeCursorPositionToHWC(); |
| 951 | } |
| 952 | |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 953 | TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCHandlesNoHwcState) { |
| 954 | mOutputLayer.editState().hwc.reset(); |
| 955 | |
| 956 | mOutputLayer.writeCursorPositionToHWC(); |
| 957 | } |
| 958 | |
| 959 | TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCWritesStateToHWC) { |
| 960 | EXPECT_CALL(*mHwcLayer, setCursorPosition(1, 2)).WillOnce(Return(kDefaultError)); |
| 961 | |
| 962 | mOutputLayer.writeCursorPositionToHWC(); |
| 963 | } |
| 964 | |
| 965 | TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCIntersectedWithViewport) { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 966 | mLayerFEState.cursorFrame = Rect{3000, 3000, 3016, 3016}; |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 967 | |
| 968 | EXPECT_CALL(*mHwcLayer, setCursorPosition(1920, 1080)).WillOnce(Return(kDefaultError)); |
| 969 | |
| 970 | mOutputLayer.writeCursorPositionToHWC(); |
| 971 | } |
| 972 | |
| 973 | TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCRotatedByTransform) { |
| 974 | mOutputState.transform = ui::Transform{TR_ROT_90}; |
| 975 | |
| 976 | EXPECT_CALL(*mHwcLayer, setCursorPosition(-4, 1)).WillOnce(Return(kDefaultError)); |
| 977 | |
| 978 | mOutputLayer.writeCursorPositionToHWC(); |
| 979 | } |
| 980 | |
| 981 | /* |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 982 | * OutputLayer::getHwcLayer() |
| 983 | */ |
| 984 | |
| 985 | TEST_F(OutputLayerTest, getHwcLayerHandlesNoHwcState) { |
| 986 | mOutputLayer.editState().hwc.reset(); |
| 987 | |
| 988 | EXPECT_TRUE(mOutputLayer.getHwcLayer() == nullptr); |
| 989 | } |
| 990 | |
| 991 | TEST_F(OutputLayerTest, getHwcLayerHandlesNoHwcLayer) { |
| 992 | mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr}; |
| 993 | |
| 994 | EXPECT_TRUE(mOutputLayer.getHwcLayer() == nullptr); |
| 995 | } |
| 996 | |
| 997 | TEST_F(OutputLayerTest, getHwcLayerReturnsHwcLayer) { |
| 998 | auto hwcLayer = std::make_shared<StrictMock<HWC2::mock::Layer>>(); |
| 999 | mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{hwcLayer}; |
| 1000 | |
| 1001 | EXPECT_EQ(hwcLayer.get(), mOutputLayer.getHwcLayer()); |
| 1002 | } |
| 1003 | |
| 1004 | /* |
| 1005 | * OutputLayer::requiresClientComposition() |
| 1006 | */ |
| 1007 | |
| 1008 | TEST_F(OutputLayerTest, requiresClientCompositionReturnsTrueIfNoHWC2State) { |
| 1009 | mOutputLayer.editState().hwc.reset(); |
| 1010 | |
| 1011 | EXPECT_TRUE(mOutputLayer.requiresClientComposition()); |
| 1012 | } |
| 1013 | |
| 1014 | TEST_F(OutputLayerTest, requiresClientCompositionReturnsTrueIfSetToClientComposition) { |
| 1015 | mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr}; |
| 1016 | mOutputLayer.editState().hwc->hwcCompositionType = Hwc2::IComposerClient::Composition::CLIENT; |
| 1017 | |
| 1018 | EXPECT_TRUE(mOutputLayer.requiresClientComposition()); |
| 1019 | } |
| 1020 | |
| 1021 | TEST_F(OutputLayerTest, requiresClientCompositionReturnsFalseIfSetToDeviceComposition) { |
| 1022 | mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr}; |
| 1023 | mOutputLayer.editState().hwc->hwcCompositionType = Hwc2::IComposerClient::Composition::DEVICE; |
| 1024 | |
| 1025 | EXPECT_FALSE(mOutputLayer.requiresClientComposition()); |
| 1026 | } |
| 1027 | |
| 1028 | /* |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 1029 | * OutputLayer::isHardwareCursor() |
| 1030 | */ |
| 1031 | |
| 1032 | TEST_F(OutputLayerTest, isHardwareCursorReturnsFalseIfNoHWC2State) { |
| 1033 | mOutputLayer.editState().hwc.reset(); |
| 1034 | |
| 1035 | EXPECT_FALSE(mOutputLayer.isHardwareCursor()); |
| 1036 | } |
| 1037 | |
| 1038 | TEST_F(OutputLayerTest, isHardwareCursorReturnsTrueIfSetToCursorComposition) { |
| 1039 | mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr}; |
| 1040 | mOutputLayer.editState().hwc->hwcCompositionType = Hwc2::IComposerClient::Composition::CURSOR; |
| 1041 | |
| 1042 | EXPECT_TRUE(mOutputLayer.isHardwareCursor()); |
| 1043 | } |
| 1044 | |
| 1045 | TEST_F(OutputLayerTest, isHardwareCursorReturnsFalseIfSetToDeviceComposition) { |
| 1046 | mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr}; |
| 1047 | mOutputLayer.editState().hwc->hwcCompositionType = Hwc2::IComposerClient::Composition::DEVICE; |
| 1048 | |
| 1049 | EXPECT_FALSE(mOutputLayer.isHardwareCursor()); |
| 1050 | } |
| 1051 | |
| 1052 | /* |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 1053 | * OutputLayer::applyDeviceCompositionTypeChange() |
| 1054 | */ |
| 1055 | |
| 1056 | TEST_F(OutputLayerTest, applyDeviceCompositionTypeChangeSetsNewType) { |
| 1057 | mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr}; |
| 1058 | mOutputLayer.editState().hwc->hwcCompositionType = Hwc2::IComposerClient::Composition::DEVICE; |
| 1059 | |
| 1060 | mOutputLayer.applyDeviceCompositionTypeChange(Hwc2::IComposerClient::Composition::CLIENT); |
| 1061 | |
| 1062 | ASSERT_TRUE(mOutputLayer.getState().hwc); |
| 1063 | EXPECT_EQ(Hwc2::IComposerClient::Composition::CLIENT, |
| 1064 | mOutputLayer.getState().hwc->hwcCompositionType); |
| 1065 | } |
| 1066 | |
| 1067 | /* |
| 1068 | * OutputLayer::prepareForDeviceLayerRequests() |
| 1069 | */ |
| 1070 | |
| 1071 | TEST_F(OutputLayerTest, prepareForDeviceLayerRequestsResetsRequestState) { |
| 1072 | mOutputLayer.editState().clearClientTarget = true; |
| 1073 | |
| 1074 | mOutputLayer.prepareForDeviceLayerRequests(); |
| 1075 | |
| 1076 | EXPECT_FALSE(mOutputLayer.getState().clearClientTarget); |
| 1077 | } |
| 1078 | |
| 1079 | /* |
| 1080 | * OutputLayer::applyDeviceLayerRequest() |
| 1081 | */ |
| 1082 | |
| 1083 | TEST_F(OutputLayerTest, applyDeviceLayerRequestHandlesClearClientTarget) { |
| 1084 | mOutputLayer.editState().clearClientTarget = false; |
| 1085 | |
| 1086 | mOutputLayer.applyDeviceLayerRequest(Hwc2::IComposerClient::LayerRequest::CLEAR_CLIENT_TARGET); |
| 1087 | |
| 1088 | EXPECT_TRUE(mOutputLayer.getState().clearClientTarget); |
| 1089 | } |
| 1090 | |
| 1091 | TEST_F(OutputLayerTest, applyDeviceLayerRequestHandlesUnknownRequest) { |
| 1092 | mOutputLayer.editState().clearClientTarget = false; |
| 1093 | |
| 1094 | mOutputLayer.applyDeviceLayerRequest(static_cast<Hwc2::IComposerClient::LayerRequest>(0)); |
| 1095 | |
| 1096 | EXPECT_FALSE(mOutputLayer.getState().clearClientTarget); |
| 1097 | } |
| 1098 | |
Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 1099 | /* |
| 1100 | * OutputLayer::needsFiltering() |
| 1101 | */ |
| 1102 | |
| 1103 | TEST_F(OutputLayerTest, needsFilteringReturnsFalseIfDisplaySizeSameAsSourceSize) { |
| 1104 | mOutputLayer.editState().displayFrame = Rect(100, 100, 200, 200); |
| 1105 | mOutputLayer.editState().sourceCrop = FloatRect{0.f, 0.f, 100.f, 100.f}; |
| 1106 | |
| 1107 | EXPECT_FALSE(mOutputLayer.needsFiltering()); |
| 1108 | } |
| 1109 | |
| 1110 | TEST_F(OutputLayerTest, needsFilteringReturnsTrueIfDisplaySizeDifferentFromSourceSize) { |
| 1111 | mOutputLayer.editState().displayFrame = Rect(100, 100, 200, 200); |
| 1112 | mOutputLayer.editState().sourceCrop = FloatRect{0.f, 0.f, 100.1f, 100.1f}; |
| 1113 | |
| 1114 | EXPECT_TRUE(mOutputLayer.needsFiltering()); |
| 1115 | } |
| 1116 | |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 1117 | } // namespace |
| 1118 | } // namespace android::compositionengine |