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