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