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