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