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