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