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