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