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