Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include <compositionengine/impl/OutputLayer.h> |
Lloyd Pique | 07e3321 | 2018-12-18 16:33:37 -0800 | [diff] [blame] | 18 | #include <compositionengine/mock/CompositionEngine.h> |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 19 | #include <compositionengine/mock/DisplayColorProfile.h> |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 20 | #include <compositionengine/mock/Layer.h> |
| 21 | #include <compositionengine/mock/LayerFE.h> |
| 22 | #include <compositionengine/mock/Output.h> |
| 23 | #include <gtest/gtest.h> |
| 24 | |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 25 | #include "FloatRectMatcher.h" |
Lloyd Pique | 07e3321 | 2018-12-18 16:33:37 -0800 | [diff] [blame] | 26 | #include "MockHWC2.h" |
| 27 | #include "MockHWComposer.h" |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 28 | #include "RectMatcher.h" |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 29 | #include "RegionMatcher.h" |
Lloyd Pique | 07e3321 | 2018-12-18 16:33:37 -0800 | [diff] [blame] | 30 | |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 31 | namespace android::compositionengine { |
| 32 | namespace { |
| 33 | |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 34 | using testing::_; |
| 35 | using testing::Return; |
| 36 | using testing::ReturnRef; |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 37 | using testing::StrictMock; |
| 38 | |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 39 | constexpr auto TR_IDENT = 0u; |
| 40 | constexpr auto TR_FLP_H = HAL_TRANSFORM_FLIP_H; |
| 41 | constexpr auto TR_FLP_V = HAL_TRANSFORM_FLIP_V; |
| 42 | constexpr auto TR_ROT_90 = HAL_TRANSFORM_ROT_90; |
| 43 | constexpr auto TR_ROT_180 = TR_FLP_H | TR_FLP_V; |
| 44 | constexpr auto TR_ROT_270 = TR_ROT_90 | TR_ROT_180; |
| 45 | |
| 46 | const std::string kOutputName{"Test Output"}; |
| 47 | |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 48 | MATCHER_P(ColorEq, expected, "") { |
| 49 | *result_listener << "Colors are not equal\n"; |
| 50 | *result_listener << "expected " << expected.r << " " << expected.g << " " << expected.b << " " |
| 51 | << expected.a << "\n"; |
| 52 | *result_listener << "actual " << arg.r << " " << arg.g << " " << arg.b << " " << arg.a << "\n"; |
| 53 | |
| 54 | return expected.r == arg.r && expected.g == arg.g && expected.b == arg.b && expected.a == arg.a; |
| 55 | } |
| 56 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 57 | struct OutputLayerTest : public testing::Test { |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 58 | OutputLayerTest() { |
| 59 | EXPECT_CALL(*mLayerFE, getDebugName()).WillRepeatedly(Return("Test LayerFE")); |
| 60 | EXPECT_CALL(mOutput, getName()).WillRepeatedly(ReturnRef(kOutputName)); |
| 61 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 62 | EXPECT_CALL(*mLayer, getFEState()).WillRepeatedly(ReturnRef(mLayerFEState)); |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 63 | EXPECT_CALL(mOutput, getState()).WillRepeatedly(ReturnRef(mOutputState)); |
| 64 | } |
| 65 | |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 66 | compositionengine::mock::Output mOutput; |
| 67 | std::shared_ptr<compositionengine::mock::Layer> mLayer{ |
| 68 | new StrictMock<compositionengine::mock::Layer>()}; |
| 69 | sp<compositionengine::mock::LayerFE> mLayerFE{ |
| 70 | new StrictMock<compositionengine::mock::LayerFE>()}; |
| 71 | impl::OutputLayer mOutputLayer{mOutput, mLayer, mLayerFE}; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 72 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 73 | LayerFECompositionState mLayerFEState; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 74 | impl::OutputCompositionState mOutputState; |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 75 | }; |
| 76 | |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 77 | /* |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 78 | * Basic construction |
| 79 | */ |
| 80 | |
| 81 | TEST_F(OutputLayerTest, canInstantiateOutputLayer) {} |
| 82 | |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 83 | /* |
Lloyd Pique | df336d9 | 2019-03-07 21:38:42 -0800 | [diff] [blame] | 84 | * OutputLayer::setHwcLayer() |
Lloyd Pique | 07e3321 | 2018-12-18 16:33:37 -0800 | [diff] [blame] | 85 | */ |
| 86 | |
Lloyd Pique | df336d9 | 2019-03-07 21:38:42 -0800 | [diff] [blame] | 87 | TEST_F(OutputLayerTest, settingNullHwcLayerSetsEmptyHwcState) { |
Lloyd Pique | 07e3321 | 2018-12-18 16:33:37 -0800 | [diff] [blame] | 88 | StrictMock<compositionengine::mock::CompositionEngine> compositionEngine; |
| 89 | |
Lloyd Pique | df336d9 | 2019-03-07 21:38:42 -0800 | [diff] [blame] | 90 | mOutputLayer.setHwcLayer(nullptr); |
Lloyd Pique | 07e3321 | 2018-12-18 16:33:37 -0800 | [diff] [blame] | 91 | |
| 92 | EXPECT_FALSE(mOutputLayer.getState().hwc); |
| 93 | } |
| 94 | |
Lloyd Pique | df336d9 | 2019-03-07 21:38:42 -0800 | [diff] [blame] | 95 | TEST_F(OutputLayerTest, settingHwcLayerSetsHwcState) { |
| 96 | auto hwcLayer = std::make_shared<StrictMock<HWC2::mock::Layer>>(); |
Lloyd Pique | 07e3321 | 2018-12-18 16:33:37 -0800 | [diff] [blame] | 97 | |
Lloyd Pique | df336d9 | 2019-03-07 21:38:42 -0800 | [diff] [blame] | 98 | mOutputLayer.setHwcLayer(hwcLayer); |
Lloyd Pique | 07e3321 | 2018-12-18 16:33:37 -0800 | [diff] [blame] | 99 | |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 100 | const auto& outputLayerState = mOutputLayer.getState(); |
| 101 | ASSERT_TRUE(outputLayerState.hwc); |
Lloyd Pique | 07e3321 | 2018-12-18 16:33:37 -0800 | [diff] [blame] | 102 | |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 103 | const auto& hwcState = *outputLayerState.hwc; |
Lloyd Pique | df336d9 | 2019-03-07 21:38:42 -0800 | [diff] [blame] | 104 | EXPECT_EQ(hwcLayer, hwcState.hwcLayer); |
Lloyd Pique | 07e3321 | 2018-12-18 16:33:37 -0800 | [diff] [blame] | 105 | } |
| 106 | |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 107 | /* |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 108 | * OutputLayer::calculateOutputSourceCrop() |
| 109 | */ |
| 110 | |
| 111 | struct OutputLayerSourceCropTest : public OutputLayerTest { |
| 112 | OutputLayerSourceCropTest() { |
| 113 | // Set reasonable default values for a simple case. Each test will |
| 114 | // set one specific value to something different. |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 115 | mLayerFEState.geomUsesSourceCrop = true; |
| 116 | mLayerFEState.geomContentCrop = Rect{0, 0, 1920, 1080}; |
| 117 | mLayerFEState.transparentRegionHint = Region{}; |
| 118 | mLayerFEState.geomLayerBounds = FloatRect{0.f, 0.f, 1920.f, 1080.f}; |
| 119 | mLayerFEState.geomLayerTransform = ui::Transform{TR_IDENT}; |
| 120 | mLayerFEState.geomBufferSize = Rect{0, 0, 1920, 1080}; |
| 121 | mLayerFEState.geomBufferTransform = TR_IDENT; |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 122 | |
| 123 | mOutputState.viewport = Rect{0, 0, 1920, 1080}; |
| 124 | } |
| 125 | |
| 126 | FloatRect calculateOutputSourceCrop() { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 127 | mLayerFEState.geomInverseLayerTransform = mLayerFEState.geomLayerTransform.inverse(); |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 128 | |
| 129 | return mOutputLayer.calculateOutputSourceCrop(); |
| 130 | } |
| 131 | }; |
| 132 | |
| 133 | TEST_F(OutputLayerSourceCropTest, computesEmptyIfSourceCropNotUsed) { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 134 | mLayerFEState.geomUsesSourceCrop = false; |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 135 | |
| 136 | const FloatRect expected{}; |
| 137 | EXPECT_THAT(calculateOutputSourceCrop(), FloatRectEq(expected)); |
| 138 | } |
| 139 | |
| 140 | TEST_F(OutputLayerSourceCropTest, correctForSimpleDefaultCase) { |
| 141 | const FloatRect expected{0.f, 0.f, 1920.f, 1080.f}; |
| 142 | EXPECT_THAT(calculateOutputSourceCrop(), FloatRectEq(expected)); |
| 143 | } |
| 144 | |
| 145 | TEST_F(OutputLayerSourceCropTest, handlesBoundsOutsideViewport) { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 146 | mLayerFEState.geomLayerBounds = FloatRect{-2000.f, -2000.f, 2000.f, 2000.f}; |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 147 | |
| 148 | const FloatRect expected{0.f, 0.f, 1920.f, 1080.f}; |
| 149 | EXPECT_THAT(calculateOutputSourceCrop(), FloatRectEq(expected)); |
| 150 | } |
| 151 | |
| 152 | TEST_F(OutputLayerSourceCropTest, handlesBoundsOutsideViewportRotated) { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 153 | mLayerFEState.geomLayerBounds = FloatRect{-2000.f, -2000.f, 2000.f, 2000.f}; |
| 154 | mLayerFEState.geomLayerTransform.set(HAL_TRANSFORM_ROT_90, 1920, 1080); |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 155 | |
| 156 | const FloatRect expected{0.f, 0.f, 1080.f, 1080.f}; |
| 157 | EXPECT_THAT(calculateOutputSourceCrop(), FloatRectEq(expected)); |
| 158 | } |
| 159 | |
| 160 | TEST_F(OutputLayerSourceCropTest, calculateOutputSourceCropWorksWithATransformedBuffer) { |
| 161 | struct Entry { |
| 162 | uint32_t bufferInvDisplay; |
| 163 | uint32_t buffer; |
| 164 | uint32_t display; |
| 165 | FloatRect expected; |
| 166 | }; |
| 167 | // Not an exhaustive list of cases, but hopefully enough. |
| 168 | const std::array<Entry, 12> testData = { |
| 169 | // clang-format off |
| 170 | // inv buffer display expected |
| 171 | /* 0 */ Entry{false, TR_IDENT, TR_IDENT, FloatRect{0.f, 0.f, 1920.f, 1080.f}}, |
| 172 | /* 1 */ Entry{false, TR_IDENT, TR_ROT_90, FloatRect{0.f, 0.f, 1920.f, 1080.f}}, |
| 173 | /* 2 */ Entry{false, TR_IDENT, TR_ROT_180, FloatRect{0.f, 0.f, 1920.f, 1080.f}}, |
| 174 | /* 3 */ Entry{false, TR_IDENT, TR_ROT_270, FloatRect{0.f, 0.f, 1920.f, 1080.f}}, |
| 175 | |
| 176 | /* 4 */ Entry{true, TR_IDENT, TR_IDENT, FloatRect{0.f, 0.f, 1920.f, 1080.f}}, |
| 177 | /* 5 */ Entry{true, TR_IDENT, TR_ROT_90, FloatRect{0.f, 0.f, 1920.f, 1080.f}}, |
| 178 | /* 6 */ Entry{true, TR_IDENT, TR_ROT_180, FloatRect{0.f, 0.f, 1920.f, 1080.f}}, |
| 179 | /* 7 */ Entry{true, TR_IDENT, TR_ROT_270, FloatRect{0.f, 0.f, 1920.f, 1080.f}}, |
| 180 | |
| 181 | /* 8 */ Entry{false, TR_IDENT, TR_IDENT, FloatRect{0.f, 0.f, 1920.f, 1080.f}}, |
| 182 | /* 9 */ Entry{false, TR_ROT_90, TR_ROT_90, FloatRect{0.f, 0.f, 1920.f, 1080.f}}, |
| 183 | /* 10 */ Entry{false, TR_ROT_180, TR_ROT_180, FloatRect{0.f, 0.f, 1920.f, 1080.f}}, |
| 184 | /* 11 */ Entry{false, TR_ROT_270, TR_ROT_270, FloatRect{0.f, 0.f, 1920.f, 1080.f}}, |
| 185 | |
| 186 | // clang-format on |
| 187 | }; |
| 188 | |
| 189 | for (size_t i = 0; i < testData.size(); i++) { |
| 190 | const auto& entry = testData[i]; |
| 191 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 192 | mLayerFEState.geomBufferUsesDisplayInverseTransform = entry.bufferInvDisplay; |
| 193 | mLayerFEState.geomBufferTransform = entry.buffer; |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 194 | mOutputState.orientation = entry.display; |
| 195 | |
| 196 | EXPECT_THAT(calculateOutputSourceCrop(), FloatRectEq(entry.expected)) << "entry " << i; |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | TEST_F(OutputLayerSourceCropTest, geomContentCropAffectsCrop) { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 201 | mLayerFEState.geomContentCrop = Rect{0, 0, 960, 540}; |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 202 | |
| 203 | const FloatRect expected{0.f, 0.f, 960.f, 540.f}; |
| 204 | EXPECT_THAT(calculateOutputSourceCrop(), FloatRectEq(expected)); |
| 205 | } |
| 206 | |
| 207 | TEST_F(OutputLayerSourceCropTest, viewportAffectsCrop) { |
| 208 | mOutputState.viewport = Rect{0, 0, 960, 540}; |
| 209 | |
| 210 | const FloatRect expected{0.f, 0.f, 960.f, 540.f}; |
| 211 | EXPECT_THAT(calculateOutputSourceCrop(), FloatRectEq(expected)); |
| 212 | } |
| 213 | |
| 214 | /* |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 215 | * OutputLayer::calculateOutputDisplayFrame() |
| 216 | */ |
| 217 | |
| 218 | struct OutputLayerDisplayFrameTest : public OutputLayerTest { |
| 219 | OutputLayerDisplayFrameTest() { |
| 220 | // Set reasonable default values for a simple case. Each test will |
| 221 | // set one specific value to something different. |
| 222 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 223 | mLayerFEState.transparentRegionHint = Region{}; |
| 224 | mLayerFEState.geomLayerTransform = ui::Transform{TR_IDENT}; |
| 225 | mLayerFEState.geomBufferSize = Rect{0, 0, 1920, 1080}; |
| 226 | mLayerFEState.geomBufferUsesDisplayInverseTransform = false; |
| 227 | mLayerFEState.geomCrop = Rect{0, 0, 1920, 1080}; |
| 228 | mLayerFEState.geomLayerBounds = FloatRect{0.f, 0.f, 1920.f, 1080.f}; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 229 | |
| 230 | mOutputState.viewport = Rect{0, 0, 1920, 1080}; |
| 231 | mOutputState.transform = ui::Transform{TR_IDENT}; |
| 232 | } |
| 233 | |
| 234 | Rect calculateOutputDisplayFrame() { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 235 | mLayerFEState.geomInverseLayerTransform = mLayerFEState.geomLayerTransform.inverse(); |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 236 | |
| 237 | return mOutputLayer.calculateOutputDisplayFrame(); |
| 238 | } |
| 239 | }; |
| 240 | |
| 241 | TEST_F(OutputLayerDisplayFrameTest, correctForSimpleDefaultCase) { |
| 242 | const Rect expected{0, 0, 1920, 1080}; |
| 243 | EXPECT_THAT(calculateOutputDisplayFrame(), RectEq(expected)); |
| 244 | } |
| 245 | |
| 246 | TEST_F(OutputLayerDisplayFrameTest, fullActiveTransparentRegionReturnsEmptyFrame) { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 247 | mLayerFEState.transparentRegionHint = Region{Rect{0, 0, 1920, 1080}}; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 248 | const Rect expected{0, 0, 0, 0}; |
| 249 | EXPECT_THAT(calculateOutputDisplayFrame(), RectEq(expected)); |
| 250 | } |
| 251 | |
| 252 | TEST_F(OutputLayerDisplayFrameTest, cropAffectsDisplayFrame) { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 253 | mLayerFEState.geomCrop = Rect{100, 200, 300, 500}; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 254 | const Rect expected{100, 200, 300, 500}; |
| 255 | EXPECT_THAT(calculateOutputDisplayFrame(), RectEq(expected)); |
| 256 | } |
| 257 | |
| 258 | TEST_F(OutputLayerDisplayFrameTest, cropAffectsDisplayFrameRotated) { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 259 | mLayerFEState.geomCrop = Rect{100, 200, 300, 500}; |
| 260 | mLayerFEState.geomLayerTransform.set(HAL_TRANSFORM_ROT_90, 1920, 1080); |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 261 | const Rect expected{1420, 100, 1720, 300}; |
| 262 | EXPECT_THAT(calculateOutputDisplayFrame(), RectEq(expected)); |
| 263 | } |
| 264 | |
| 265 | TEST_F(OutputLayerDisplayFrameTest, emptyGeomCropIsNotUsedToComputeFrame) { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 266 | mLayerFEState.geomCrop = Rect{}; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 267 | const Rect expected{0, 0, 1920, 1080}; |
| 268 | EXPECT_THAT(calculateOutputDisplayFrame(), RectEq(expected)); |
| 269 | } |
| 270 | |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 271 | TEST_F(OutputLayerDisplayFrameTest, geomLayerBoundsAffectsFrame) { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 272 | mLayerFEState.geomLayerBounds = FloatRect{0.f, 0.f, 960.f, 540.f}; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 273 | const Rect expected{0, 0, 960, 540}; |
| 274 | EXPECT_THAT(calculateOutputDisplayFrame(), RectEq(expected)); |
| 275 | } |
| 276 | |
| 277 | TEST_F(OutputLayerDisplayFrameTest, viewportAffectsFrame) { |
| 278 | mOutputState.viewport = Rect{0, 0, 960, 540}; |
| 279 | const Rect expected{0, 0, 960, 540}; |
| 280 | EXPECT_THAT(calculateOutputDisplayFrame(), RectEq(expected)); |
| 281 | } |
| 282 | |
| 283 | TEST_F(OutputLayerDisplayFrameTest, outputTransformAffectsDisplayFrame) { |
| 284 | mOutputState.transform = ui::Transform{HAL_TRANSFORM_ROT_90}; |
| 285 | const Rect expected{-1080, 0, 0, 1920}; |
| 286 | EXPECT_THAT(calculateOutputDisplayFrame(), RectEq(expected)); |
| 287 | } |
| 288 | |
| 289 | /* |
| 290 | * OutputLayer::calculateOutputRelativeBufferTransform() |
| 291 | */ |
| 292 | |
| 293 | TEST_F(OutputLayerTest, calculateOutputRelativeBufferTransformTestsNeeded) { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 294 | mLayerFEState.geomBufferUsesDisplayInverseTransform = false; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 295 | |
| 296 | struct Entry { |
| 297 | uint32_t layer; |
| 298 | uint32_t buffer; |
| 299 | uint32_t display; |
| 300 | uint32_t expected; |
| 301 | }; |
| 302 | // Not an exhaustive list of cases, but hopefully enough. |
| 303 | const std::array<Entry, 24> testData = { |
| 304 | // clang-format off |
| 305 | // layer buffer display expected |
| 306 | /* 0 */ Entry{TR_IDENT, TR_IDENT, TR_IDENT, TR_IDENT}, |
| 307 | /* 1 */ Entry{TR_IDENT, TR_IDENT, TR_ROT_90, TR_ROT_90}, |
| 308 | /* 2 */ Entry{TR_IDENT, TR_IDENT, TR_ROT_180, TR_ROT_180}, |
| 309 | /* 3 */ Entry{TR_IDENT, TR_IDENT, TR_ROT_270, TR_ROT_270}, |
| 310 | |
| 311 | /* 4 */ Entry{TR_IDENT, TR_FLP_H, TR_IDENT, TR_FLP_H ^ TR_IDENT}, |
| 312 | /* 5 */ Entry{TR_IDENT, TR_FLP_H, TR_ROT_90, TR_FLP_H ^ TR_ROT_90}, |
| 313 | /* 6 */ Entry{TR_IDENT, TR_FLP_H, TR_ROT_180, TR_FLP_H ^ TR_ROT_180}, |
| 314 | /* 7 */ Entry{TR_IDENT, TR_FLP_H, TR_ROT_270, TR_FLP_H ^ TR_ROT_270}, |
| 315 | |
| 316 | /* 8 */ Entry{TR_IDENT, TR_FLP_V, TR_IDENT, TR_FLP_V}, |
| 317 | /* 9 */ Entry{TR_IDENT, TR_ROT_90, TR_ROT_90, TR_ROT_180}, |
| 318 | /* 10 */ Entry{TR_IDENT, TR_ROT_180, TR_ROT_180, TR_IDENT}, |
| 319 | /* 11 */ Entry{TR_IDENT, TR_ROT_270, TR_ROT_270, TR_ROT_180}, |
| 320 | |
| 321 | /* 12 */ Entry{TR_ROT_90, TR_IDENT, TR_IDENT, TR_IDENT ^ TR_ROT_90}, |
| 322 | /* 13 */ Entry{TR_ROT_90, TR_FLP_H, TR_ROT_90, TR_FLP_H ^ TR_ROT_180}, |
| 323 | /* 14 */ Entry{TR_ROT_90, TR_IDENT, TR_ROT_180, TR_IDENT ^ TR_ROT_270}, |
| 324 | /* 15 */ Entry{TR_ROT_90, TR_FLP_H, TR_ROT_270, TR_FLP_H ^ TR_IDENT}, |
| 325 | |
| 326 | /* 16 */ Entry{TR_ROT_180, TR_FLP_H, TR_IDENT, TR_FLP_H ^ TR_ROT_180}, |
| 327 | /* 17 */ Entry{TR_ROT_180, TR_IDENT, TR_ROT_90, TR_IDENT ^ TR_ROT_270}, |
| 328 | /* 18 */ Entry{TR_ROT_180, TR_FLP_H, TR_ROT_180, TR_FLP_H ^ TR_IDENT}, |
| 329 | /* 19 */ Entry{TR_ROT_180, TR_IDENT, TR_ROT_270, TR_IDENT ^ TR_ROT_90}, |
| 330 | |
| 331 | /* 20 */ Entry{TR_ROT_270, TR_IDENT, TR_IDENT, TR_IDENT ^ TR_ROT_270}, |
| 332 | /* 21 */ Entry{TR_ROT_270, TR_FLP_H, TR_ROT_90, TR_FLP_H ^ TR_IDENT}, |
| 333 | /* 22 */ Entry{TR_ROT_270, TR_FLP_H, TR_ROT_180, TR_FLP_H ^ TR_ROT_90}, |
| 334 | /* 23 */ Entry{TR_ROT_270, TR_IDENT, TR_ROT_270, TR_IDENT ^ TR_ROT_180}, |
| 335 | // clang-format on |
| 336 | }; |
| 337 | |
| 338 | for (size_t i = 0; i < testData.size(); i++) { |
| 339 | const auto& entry = testData[i]; |
| 340 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 341 | mLayerFEState.geomLayerTransform.set(entry.layer, 1920, 1080); |
| 342 | mLayerFEState.geomBufferTransform = entry.buffer; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 343 | mOutputState.orientation = entry.display; |
| 344 | |
| 345 | auto actual = mOutputLayer.calculateOutputRelativeBufferTransform(); |
| 346 | EXPECT_EQ(entry.expected, actual) << "entry " << i; |
| 347 | } |
| 348 | } |
| 349 | |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 350 | TEST_F(OutputLayerTest, |
| 351 | calculateOutputRelativeBufferTransformTestWithOfBufferUsesDisplayInverseTransform) { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 352 | mLayerFEState.geomBufferUsesDisplayInverseTransform = true; |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 353 | |
| 354 | struct Entry { |
| 355 | uint32_t layer; |
| 356 | uint32_t buffer; |
| 357 | uint32_t display; |
| 358 | uint32_t expected; |
| 359 | }; |
| 360 | // Not an exhaustive list of cases, but hopefully enough. |
| 361 | const std::array<Entry, 24> testData = { |
| 362 | // clang-format off |
| 363 | // layer buffer display expected |
| 364 | /* 0 */ Entry{TR_IDENT, TR_IDENT, TR_IDENT, TR_IDENT}, |
| 365 | /* 1 */ Entry{TR_IDENT, TR_IDENT, TR_ROT_90, TR_IDENT}, |
| 366 | /* 2 */ Entry{TR_IDENT, TR_IDENT, TR_ROT_180, TR_IDENT}, |
| 367 | /* 3 */ Entry{TR_IDENT, TR_IDENT, TR_ROT_270, TR_IDENT}, |
| 368 | |
| 369 | /* 4 */ Entry{TR_IDENT, TR_FLP_H, TR_IDENT, TR_FLP_H}, |
| 370 | /* 5 */ Entry{TR_IDENT, TR_FLP_H, TR_ROT_90, TR_FLP_H}, |
| 371 | /* 6 */ Entry{TR_IDENT, TR_FLP_H, TR_ROT_180, TR_FLP_H}, |
| 372 | /* 7 */ Entry{TR_IDENT, TR_FLP_H, TR_ROT_270, TR_FLP_H}, |
| 373 | |
| 374 | /* 8 */ Entry{TR_IDENT, TR_FLP_V, TR_IDENT, TR_FLP_V}, |
| 375 | /* 9 */ Entry{TR_IDENT, TR_ROT_90, TR_ROT_90, TR_ROT_90}, |
| 376 | /* 10 */ Entry{TR_IDENT, TR_ROT_180, TR_ROT_180, TR_ROT_180}, |
| 377 | /* 11 */ Entry{TR_IDENT, TR_ROT_270, TR_ROT_270, TR_ROT_270}, |
| 378 | |
| 379 | /* 12 */ Entry{TR_ROT_90, TR_IDENT, TR_IDENT, TR_IDENT}, |
| 380 | /* 13 */ Entry{TR_ROT_90, TR_FLP_H, TR_ROT_90, TR_FLP_H}, |
| 381 | /* 14 */ Entry{TR_ROT_90, TR_IDENT, TR_ROT_180, TR_IDENT}, |
| 382 | /* 15 */ Entry{TR_ROT_90, TR_FLP_H, TR_ROT_270, TR_FLP_H}, |
| 383 | |
| 384 | /* 16 */ Entry{TR_ROT_180, TR_FLP_H, TR_IDENT, TR_FLP_H}, |
| 385 | /* 17 */ Entry{TR_ROT_180, TR_IDENT, TR_ROT_90, TR_IDENT}, |
| 386 | /* 18 */ Entry{TR_ROT_180, TR_FLP_H, TR_ROT_180, TR_FLP_H}, |
| 387 | /* 19 */ Entry{TR_ROT_180, TR_IDENT, TR_ROT_270, TR_IDENT}, |
| 388 | |
| 389 | /* 20 */ Entry{TR_ROT_270, TR_IDENT, TR_IDENT, TR_IDENT}, |
| 390 | /* 21 */ Entry{TR_ROT_270, TR_FLP_H, TR_ROT_90, TR_FLP_H}, |
| 391 | /* 22 */ Entry{TR_ROT_270, TR_FLP_H, TR_ROT_180, TR_FLP_H}, |
| 392 | /* 23 */ Entry{TR_ROT_270, TR_IDENT, TR_ROT_270, TR_IDENT}, |
| 393 | // clang-format on |
| 394 | }; |
| 395 | |
| 396 | for (size_t i = 0; i < testData.size(); i++) { |
| 397 | const auto& entry = testData[i]; |
| 398 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 399 | mLayerFEState.geomLayerTransform = ui::Transform{entry.layer}; |
| 400 | mLayerFEState.geomBufferTransform = entry.buffer; |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 401 | mOutputState.orientation = entry.display; |
| 402 | |
| 403 | auto actual = mOutputLayer.calculateOutputRelativeBufferTransform(); |
| 404 | EXPECT_EQ(entry.expected, actual) << "entry " << i; |
| 405 | } |
| 406 | } |
| 407 | |
| 408 | /* |
| 409 | * OutputLayer::updateCompositionState() |
| 410 | */ |
| 411 | |
| 412 | struct OutputLayerPartialMockForUpdateCompositionState : public impl::OutputLayer { |
| 413 | OutputLayerPartialMockForUpdateCompositionState(const compositionengine::Output& output, |
| 414 | std::shared_ptr<compositionengine::Layer> layer, |
| 415 | sp<compositionengine::LayerFE> layerFE) |
| 416 | : impl::OutputLayer(output, layer, layerFE) {} |
| 417 | // Mock everything called by updateCompositionState to simplify testing it. |
| 418 | MOCK_CONST_METHOD0(calculateOutputSourceCrop, FloatRect()); |
| 419 | MOCK_CONST_METHOD0(calculateOutputDisplayFrame, Rect()); |
| 420 | MOCK_CONST_METHOD0(calculateOutputRelativeBufferTransform, uint32_t()); |
| 421 | }; |
| 422 | |
| 423 | struct OutputLayerUpdateCompositionStateTest : public OutputLayerTest { |
| 424 | public: |
| 425 | OutputLayerUpdateCompositionStateTest() { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 426 | EXPECT_CALL(*mLayer, getFEState()).WillRepeatedly(ReturnRef(mLayerFEState)); |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 427 | EXPECT_CALL(mOutput, getState()).WillRepeatedly(ReturnRef(mOutputState)); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 428 | EXPECT_CALL(mOutput, getDisplayColorProfile()) |
| 429 | .WillRepeatedly(Return(&mDisplayColorProfile)); |
| 430 | EXPECT_CALL(mDisplayColorProfile, isDataspaceSupported(_)).WillRepeatedly(Return(true)); |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | ~OutputLayerUpdateCompositionStateTest() = default; |
| 434 | |
| 435 | void setupGeometryChildCallValues() { |
| 436 | EXPECT_CALL(mOutputLayer, calculateOutputSourceCrop()).WillOnce(Return(kSourceCrop)); |
| 437 | EXPECT_CALL(mOutputLayer, calculateOutputDisplayFrame()).WillOnce(Return(kDisplayFrame)); |
| 438 | EXPECT_CALL(mOutputLayer, calculateOutputRelativeBufferTransform()) |
| 439 | .WillOnce(Return(mBufferTransform)); |
| 440 | } |
| 441 | |
| 442 | void validateComputedGeometryState() { |
| 443 | const auto& state = mOutputLayer.getState(); |
| 444 | EXPECT_EQ(kSourceCrop, state.sourceCrop); |
| 445 | EXPECT_EQ(kDisplayFrame, state.displayFrame); |
| 446 | EXPECT_EQ(static_cast<Hwc2::Transform>(mBufferTransform), state.bufferTransform); |
| 447 | } |
| 448 | |
| 449 | const FloatRect kSourceCrop{1.f, 2.f, 3.f, 4.f}; |
| 450 | const Rect kDisplayFrame{11, 12, 13, 14}; |
| 451 | uint32_t mBufferTransform{21}; |
| 452 | |
| 453 | using OutputLayer = OutputLayerPartialMockForUpdateCompositionState; |
| 454 | StrictMock<OutputLayer> mOutputLayer{mOutput, mLayer, mLayerFE}; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 455 | StrictMock<mock::DisplayColorProfile> mDisplayColorProfile; |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 456 | }; |
| 457 | |
| 458 | TEST_F(OutputLayerUpdateCompositionStateTest, setsStateNormally) { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 459 | mLayerFEState.isSecure = true; |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 460 | mOutputState.isSecure = true; |
| 461 | |
| 462 | setupGeometryChildCallValues(); |
| 463 | |
| 464 | mOutputLayer.updateCompositionState(true); |
| 465 | |
| 466 | validateComputedGeometryState(); |
| 467 | |
| 468 | EXPECT_EQ(false, mOutputLayer.getState().forceClientComposition); |
| 469 | } |
| 470 | |
| 471 | TEST_F(OutputLayerUpdateCompositionStateTest, |
| 472 | alsoSetsForceCompositionIfSecureLayerOnNonsecureOutput) { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 473 | mLayerFEState.isSecure = true; |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 474 | mOutputState.isSecure = false; |
| 475 | |
| 476 | setupGeometryChildCallValues(); |
| 477 | |
| 478 | mOutputLayer.updateCompositionState(true); |
| 479 | |
| 480 | validateComputedGeometryState(); |
| 481 | |
| 482 | EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition); |
| 483 | } |
| 484 | |
| 485 | TEST_F(OutputLayerUpdateCompositionStateTest, |
| 486 | alsoSetsForceCompositionIfUnsupportedBufferTransform) { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 487 | mLayerFEState.isSecure = true; |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 488 | mOutputState.isSecure = true; |
| 489 | |
| 490 | mBufferTransform = ui::Transform::ROT_INVALID; |
| 491 | |
| 492 | setupGeometryChildCallValues(); |
| 493 | |
| 494 | mOutputLayer.updateCompositionState(true); |
| 495 | |
| 496 | validateComputedGeometryState(); |
| 497 | |
| 498 | EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition); |
| 499 | } |
| 500 | |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 501 | TEST_F(OutputLayerUpdateCompositionStateTest, setsOutputLayerColorspaceCorrectly) { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 502 | mLayerFEState.dataspace = ui::Dataspace::DISPLAY_P3; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 503 | mOutputState.targetDataspace = ui::Dataspace::V0_SCRGB; |
| 504 | |
| 505 | // If the layer is not colorspace agnostic, the output layer dataspace |
| 506 | // should use the layers requested colorspace. |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 507 | mLayerFEState.isColorspaceAgnostic = false; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 508 | |
| 509 | mOutputLayer.updateCompositionState(false); |
| 510 | |
| 511 | EXPECT_EQ(ui::Dataspace::DISPLAY_P3, mOutputLayer.getState().dataspace); |
| 512 | |
| 513 | // If the layer is colorspace agnostic, the output layer dataspace |
| 514 | // should use the colorspace chosen for the whole output. |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 515 | mLayerFEState.isColorspaceAgnostic = true; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 516 | |
| 517 | mOutputLayer.updateCompositionState(false); |
| 518 | |
| 519 | EXPECT_EQ(ui::Dataspace::V0_SCRGB, mOutputLayer.getState().dataspace); |
| 520 | } |
| 521 | |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 522 | TEST_F(OutputLayerUpdateCompositionStateTest, doesNotRecomputeGeometryIfNotRequested) { |
| 523 | mOutputLayer.updateCompositionState(false); |
| 524 | |
| 525 | EXPECT_EQ(false, mOutputLayer.getState().forceClientComposition); |
| 526 | } |
| 527 | |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 528 | TEST_F(OutputLayerUpdateCompositionStateTest, clientCompositionForcedFromFrontEndFlagAtAnyTime) { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 529 | mLayerFEState.forceClientComposition = true; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 530 | |
| 531 | mOutputLayer.updateCompositionState(false); |
| 532 | |
| 533 | EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition); |
| 534 | } |
| 535 | |
| 536 | TEST_F(OutputLayerUpdateCompositionStateTest, |
| 537 | clientCompositionForcedFromUnsupportedDataspaceAtAnyTime) { |
| 538 | EXPECT_CALL(mDisplayColorProfile, isDataspaceSupported(_)).WillRepeatedly(Return(false)); |
| 539 | |
| 540 | mOutputLayer.updateCompositionState(false); |
| 541 | |
| 542 | EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition); |
| 543 | } |
| 544 | |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 545 | /* |
| 546 | * OutputLayer::writeStateToHWC() |
| 547 | */ |
| 548 | |
| 549 | struct OutputLayerWriteStateToHWCTest : public OutputLayerTest { |
| 550 | static constexpr HWC2::Error kError = HWC2::Error::Unsupported; |
| 551 | static constexpr FloatRect kSourceCrop{11.f, 12.f, 13.f, 14.f}; |
| 552 | static constexpr uint32_t kZOrder = 21u; |
| 553 | static constexpr Hwc2::Transform kBufferTransform = static_cast<Hwc2::Transform>(31); |
| 554 | static constexpr Hwc2::IComposerClient::BlendMode kBlendMode = |
| 555 | static_cast<Hwc2::IComposerClient::BlendMode>(41); |
| 556 | static constexpr float kAlpha = 51.f; |
| 557 | static constexpr uint32_t kType = 61u; |
| 558 | static constexpr uint32_t kAppId = 62u; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 559 | static constexpr ui::Dataspace kDataspace = static_cast<ui::Dataspace>(71); |
| 560 | static constexpr int kSupportedPerFrameMetadata = 101; |
| 561 | static constexpr int kExpectedHwcSlot = 0; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 562 | |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 563 | static const half4 kColor; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 564 | static const Rect kDisplayFrame; |
Lloyd Pique | a246866 | 2019-03-07 21:31:06 -0800 | [diff] [blame] | 565 | static const Region kOutputSpaceVisibleRegion; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 566 | static const mat4 kColorTransform; |
| 567 | static const Region kSurfaceDamage; |
| 568 | static const HdrMetadata kHdrMetadata; |
| 569 | static native_handle_t* kSidebandStreamHandle; |
| 570 | static const sp<GraphicBuffer> kBuffer; |
| 571 | static const sp<Fence> kFence; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 572 | |
| 573 | OutputLayerWriteStateToHWCTest() { |
| 574 | auto& outputLayerState = mOutputLayer.editState(); |
| 575 | outputLayerState.hwc = impl::OutputLayerCompositionState::Hwc(mHwcLayer); |
| 576 | |
| 577 | outputLayerState.displayFrame = kDisplayFrame; |
| 578 | outputLayerState.sourceCrop = kSourceCrop; |
| 579 | outputLayerState.z = kZOrder; |
| 580 | outputLayerState.bufferTransform = static_cast<Hwc2::Transform>(kBufferTransform); |
Lloyd Pique | a246866 | 2019-03-07 21:31:06 -0800 | [diff] [blame] | 581 | outputLayerState.outputSpaceVisibleRegion = kOutputSpaceVisibleRegion; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 582 | outputLayerState.dataspace = kDataspace; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 583 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 584 | mLayerFEState.blendMode = kBlendMode; |
| 585 | mLayerFEState.alpha = kAlpha; |
| 586 | mLayerFEState.type = kType; |
| 587 | mLayerFEState.appId = kAppId; |
| 588 | mLayerFEState.colorTransform = kColorTransform; |
| 589 | mLayerFEState.color = kColor; |
| 590 | mLayerFEState.surfaceDamage = kSurfaceDamage; |
| 591 | mLayerFEState.hdrMetadata = kHdrMetadata; |
| 592 | mLayerFEState.sidebandStream = NativeHandle::create(kSidebandStreamHandle, false); |
| 593 | mLayerFEState.buffer = kBuffer; |
| 594 | mLayerFEState.bufferSlot = BufferQueue::INVALID_BUFFER_SLOT; |
| 595 | mLayerFEState.acquireFence = kFence; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 596 | |
| 597 | EXPECT_CALL(mOutput, getDisplayColorProfile()) |
| 598 | .WillRepeatedly(Return(&mDisplayColorProfile)); |
| 599 | EXPECT_CALL(mDisplayColorProfile, getSupportedPerFrameMetadata()) |
| 600 | .WillRepeatedly(Return(kSupportedPerFrameMetadata)); |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 601 | } |
| 602 | |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 603 | // Some tests may need to simulate unsupported HWC calls |
| 604 | enum class SimulateUnsupported { None, ColorTransform }; |
| 605 | |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 606 | void expectGeometryCommonCalls() { |
| 607 | EXPECT_CALL(*mHwcLayer, setDisplayFrame(kDisplayFrame)).WillOnce(Return(kError)); |
| 608 | EXPECT_CALL(*mHwcLayer, setSourceCrop(kSourceCrop)).WillOnce(Return(kError)); |
| 609 | EXPECT_CALL(*mHwcLayer, setZOrder(kZOrder)).WillOnce(Return(kError)); |
| 610 | EXPECT_CALL(*mHwcLayer, setTransform(static_cast<HWC2::Transform>(kBufferTransform))) |
| 611 | .WillOnce(Return(kError)); |
| 612 | |
| 613 | EXPECT_CALL(*mHwcLayer, setBlendMode(static_cast<HWC2::BlendMode>(kBlendMode))) |
| 614 | .WillOnce(Return(kError)); |
| 615 | EXPECT_CALL(*mHwcLayer, setPlaneAlpha(kAlpha)).WillOnce(Return(kError)); |
| 616 | EXPECT_CALL(*mHwcLayer, setInfo(kType, kAppId)).WillOnce(Return(kError)); |
| 617 | } |
| 618 | |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 619 | void expectPerFrameCommonCalls(SimulateUnsupported unsupported = SimulateUnsupported::None) { |
Lloyd Pique | a246866 | 2019-03-07 21:31:06 -0800 | [diff] [blame] | 620 | EXPECT_CALL(*mHwcLayer, setVisibleRegion(RegionEq(kOutputSpaceVisibleRegion))) |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 621 | .WillOnce(Return(kError)); |
| 622 | EXPECT_CALL(*mHwcLayer, setDataspace(kDataspace)).WillOnce(Return(kError)); |
| 623 | EXPECT_CALL(*mHwcLayer, setColorTransform(kColorTransform)) |
| 624 | .WillOnce(Return(unsupported == SimulateUnsupported::ColorTransform |
| 625 | ? HWC2::Error::Unsupported |
| 626 | : HWC2::Error::None)); |
| 627 | EXPECT_CALL(*mHwcLayer, setSurfaceDamage(RegionEq(kSurfaceDamage))) |
| 628 | .WillOnce(Return(kError)); |
| 629 | } |
| 630 | |
| 631 | void expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition compositionType) { |
| 632 | EXPECT_CALL(*mHwcLayer, setCompositionType(static_cast<HWC2::Composition>(compositionType))) |
| 633 | .WillOnce(Return(kError)); |
| 634 | } |
| 635 | |
| 636 | void expectNoSetCompositionTypeCall() { |
| 637 | EXPECT_CALL(*mHwcLayer, setCompositionType(_)).Times(0); |
| 638 | } |
| 639 | |
| 640 | void expectSetColorCall() { |
| 641 | hwc_color_t color = {static_cast<uint8_t>(std::round(kColor.r * 255)), |
| 642 | static_cast<uint8_t>(std::round(kColor.g * 255)), |
| 643 | static_cast<uint8_t>(std::round(kColor.b * 255)), 255}; |
| 644 | |
| 645 | EXPECT_CALL(*mHwcLayer, setColor(ColorEq(color))).WillOnce(Return(kError)); |
| 646 | } |
| 647 | |
| 648 | void expectSetSidebandHandleCall() { |
| 649 | EXPECT_CALL(*mHwcLayer, setSidebandStream(kSidebandStreamHandle)); |
| 650 | } |
| 651 | |
| 652 | void expectSetHdrMetadataAndBufferCalls() { |
| 653 | EXPECT_CALL(*mHwcLayer, setPerFrameMetadata(kSupportedPerFrameMetadata, kHdrMetadata)); |
| 654 | EXPECT_CALL(*mHwcLayer, setBuffer(kExpectedHwcSlot, kBuffer, kFence)); |
| 655 | } |
| 656 | |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 657 | 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] | 658 | StrictMock<mock::DisplayColorProfile> mDisplayColorProfile; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 659 | }; |
| 660 | |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 661 | const half4 OutputLayerWriteStateToHWCTest::kColor{81.f / 255.f, 82.f / 255.f, 83.f / 255.f, |
| 662 | 84.f / 255.f}; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 663 | const Rect OutputLayerWriteStateToHWCTest::kDisplayFrame{1001, 1002, 1003, 10044}; |
Lloyd Pique | a246866 | 2019-03-07 21:31:06 -0800 | [diff] [blame] | 664 | const Region OutputLayerWriteStateToHWCTest::kOutputSpaceVisibleRegion{ |
| 665 | Rect{1005, 1006, 1007, 1008}}; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 666 | const mat4 OutputLayerWriteStateToHWCTest::kColorTransform{ |
| 667 | 1009, 1010, 1011, 1012, 1013, 1014, 1015, 1016, |
| 668 | 1017, 1018, 1019, 1020, 1021, 1022, 1023, 1024, |
| 669 | }; |
| 670 | const Region OutputLayerWriteStateToHWCTest::kSurfaceDamage{Rect{1025, 1026, 1027, 1028}}; |
| 671 | const HdrMetadata OutputLayerWriteStateToHWCTest::kHdrMetadata{{/* LightFlattenable */}, 1029}; |
| 672 | native_handle_t* OutputLayerWriteStateToHWCTest::kSidebandStreamHandle = |
| 673 | reinterpret_cast<native_handle_t*>(1031); |
| 674 | const sp<GraphicBuffer> OutputLayerWriteStateToHWCTest::kBuffer; |
| 675 | const sp<Fence> OutputLayerWriteStateToHWCTest::kFence; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 676 | |
| 677 | TEST_F(OutputLayerWriteStateToHWCTest, doesNothingIfNoHWCState) { |
| 678 | mOutputLayer.editState().hwc.reset(); |
| 679 | |
| 680 | mOutputLayer.writeStateToHWC(true); |
| 681 | } |
| 682 | |
| 683 | TEST_F(OutputLayerWriteStateToHWCTest, doesNothingIfNoHWCLayer) { |
| 684 | mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc(nullptr); |
| 685 | |
| 686 | mOutputLayer.writeStateToHWC(true); |
| 687 | } |
| 688 | |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 689 | TEST_F(OutputLayerWriteStateToHWCTest, canSetAllState) { |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 690 | expectGeometryCommonCalls(); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 691 | expectPerFrameCommonCalls(); |
| 692 | |
| 693 | expectNoSetCompositionTypeCall(); |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 694 | |
| 695 | mOutputLayer.writeStateToHWC(true); |
| 696 | } |
| 697 | |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 698 | TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForSolidColor) { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 699 | mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::SOLID_COLOR; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 700 | |
| 701 | expectPerFrameCommonCalls(); |
| 702 | expectSetColorCall(); |
| 703 | expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::SOLID_COLOR); |
| 704 | |
| 705 | mOutputLayer.writeStateToHWC(false); |
| 706 | } |
| 707 | |
| 708 | TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForSideband) { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 709 | mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::SIDEBAND; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 710 | |
| 711 | expectPerFrameCommonCalls(); |
| 712 | expectSetSidebandHandleCall(); |
| 713 | expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::SIDEBAND); |
| 714 | |
| 715 | mOutputLayer.writeStateToHWC(false); |
| 716 | } |
| 717 | |
| 718 | TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForCursor) { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 719 | mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::CURSOR; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 720 | |
| 721 | expectPerFrameCommonCalls(); |
| 722 | expectSetHdrMetadataAndBufferCalls(); |
| 723 | expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::CURSOR); |
| 724 | |
| 725 | mOutputLayer.writeStateToHWC(false); |
| 726 | } |
| 727 | |
| 728 | TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForDevice) { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 729 | mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::DEVICE; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 730 | |
| 731 | expectPerFrameCommonCalls(); |
| 732 | expectSetHdrMetadataAndBufferCalls(); |
| 733 | expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::DEVICE); |
| 734 | |
| 735 | mOutputLayer.writeStateToHWC(false); |
| 736 | } |
| 737 | |
| 738 | TEST_F(OutputLayerWriteStateToHWCTest, compositionTypeIsNotSetIfUnchanged) { |
| 739 | (*mOutputLayer.editState().hwc).hwcCompositionType = |
| 740 | Hwc2::IComposerClient::Composition::SOLID_COLOR; |
| 741 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 742 | mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::SOLID_COLOR; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 743 | |
| 744 | expectPerFrameCommonCalls(); |
| 745 | expectSetColorCall(); |
| 746 | expectNoSetCompositionTypeCall(); |
| 747 | |
| 748 | mOutputLayer.writeStateToHWC(false); |
| 749 | } |
| 750 | |
| 751 | TEST_F(OutputLayerWriteStateToHWCTest, compositionTypeIsSetToClientIfColorTransformNotSupported) { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 752 | mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::SOLID_COLOR; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 753 | |
| 754 | expectPerFrameCommonCalls(SimulateUnsupported::ColorTransform); |
| 755 | expectSetColorCall(); |
| 756 | expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::CLIENT); |
| 757 | |
| 758 | mOutputLayer.writeStateToHWC(false); |
| 759 | } |
| 760 | |
| 761 | TEST_F(OutputLayerWriteStateToHWCTest, compositionTypeIsSetToClientIfClientCompositionForced) { |
| 762 | mOutputLayer.editState().forceClientComposition = true; |
| 763 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 764 | mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::SOLID_COLOR; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 765 | |
| 766 | expectPerFrameCommonCalls(); |
| 767 | expectSetColorCall(); |
| 768 | expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::CLIENT); |
| 769 | |
| 770 | mOutputLayer.writeStateToHWC(false); |
| 771 | } |
| 772 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 773 | /* |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 774 | * OutputLayer::writeCursorPositionToHWC() |
| 775 | */ |
| 776 | |
| 777 | struct OutputLayerWriteCursorPositionToHWCTest : public OutputLayerTest { |
| 778 | static constexpr int kDefaultTransform = TR_IDENT; |
| 779 | static constexpr HWC2::Error kDefaultError = HWC2::Error::Unsupported; |
| 780 | |
| 781 | static const Rect kDefaultDisplayViewport; |
| 782 | static const Rect kDefaultCursorFrame; |
| 783 | |
| 784 | OutputLayerWriteCursorPositionToHWCTest() { |
| 785 | auto& outputLayerState = mOutputLayer.editState(); |
| 786 | outputLayerState.hwc = impl::OutputLayerCompositionState::Hwc(mHwcLayer); |
| 787 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 788 | mLayerFEState.cursorFrame = kDefaultCursorFrame; |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 789 | |
| 790 | mOutputState.viewport = kDefaultDisplayViewport; |
| 791 | mOutputState.transform = ui::Transform{kDefaultTransform}; |
| 792 | } |
| 793 | |
| 794 | std::shared_ptr<HWC2::mock::Layer> mHwcLayer{std::make_shared<StrictMock<HWC2::mock::Layer>>()}; |
| 795 | }; |
| 796 | |
| 797 | const Rect OutputLayerWriteCursorPositionToHWCTest::kDefaultDisplayViewport{0, 0, 1920, 1080}; |
| 798 | const Rect OutputLayerWriteCursorPositionToHWCTest::kDefaultCursorFrame{1, 2, 3, 4}; |
| 799 | |
| 800 | TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCHandlesNoHwcState) { |
| 801 | mOutputLayer.editState().hwc.reset(); |
| 802 | |
| 803 | mOutputLayer.writeCursorPositionToHWC(); |
| 804 | } |
| 805 | |
| 806 | TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCWritesStateToHWC) { |
| 807 | EXPECT_CALL(*mHwcLayer, setCursorPosition(1, 2)).WillOnce(Return(kDefaultError)); |
| 808 | |
| 809 | mOutputLayer.writeCursorPositionToHWC(); |
| 810 | } |
| 811 | |
| 812 | TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCIntersectedWithViewport) { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 813 | mLayerFEState.cursorFrame = Rect{3000, 3000, 3016, 3016}; |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 814 | |
| 815 | EXPECT_CALL(*mHwcLayer, setCursorPosition(1920, 1080)).WillOnce(Return(kDefaultError)); |
| 816 | |
| 817 | mOutputLayer.writeCursorPositionToHWC(); |
| 818 | } |
| 819 | |
| 820 | TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCRotatedByTransform) { |
| 821 | mOutputState.transform = ui::Transform{TR_ROT_90}; |
| 822 | |
| 823 | EXPECT_CALL(*mHwcLayer, setCursorPosition(-4, 1)).WillOnce(Return(kDefaultError)); |
| 824 | |
| 825 | mOutputLayer.writeCursorPositionToHWC(); |
| 826 | } |
| 827 | |
| 828 | /* |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 829 | * OutputLayer::getHwcLayer() |
| 830 | */ |
| 831 | |
| 832 | TEST_F(OutputLayerTest, getHwcLayerHandlesNoHwcState) { |
| 833 | mOutputLayer.editState().hwc.reset(); |
| 834 | |
| 835 | EXPECT_TRUE(mOutputLayer.getHwcLayer() == nullptr); |
| 836 | } |
| 837 | |
| 838 | TEST_F(OutputLayerTest, getHwcLayerHandlesNoHwcLayer) { |
| 839 | mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr}; |
| 840 | |
| 841 | EXPECT_TRUE(mOutputLayer.getHwcLayer() == nullptr); |
| 842 | } |
| 843 | |
| 844 | TEST_F(OutputLayerTest, getHwcLayerReturnsHwcLayer) { |
| 845 | auto hwcLayer = std::make_shared<StrictMock<HWC2::mock::Layer>>(); |
| 846 | mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{hwcLayer}; |
| 847 | |
| 848 | EXPECT_EQ(hwcLayer.get(), mOutputLayer.getHwcLayer()); |
| 849 | } |
| 850 | |
| 851 | /* |
| 852 | * OutputLayer::requiresClientComposition() |
| 853 | */ |
| 854 | |
| 855 | TEST_F(OutputLayerTest, requiresClientCompositionReturnsTrueIfNoHWC2State) { |
| 856 | mOutputLayer.editState().hwc.reset(); |
| 857 | |
| 858 | EXPECT_TRUE(mOutputLayer.requiresClientComposition()); |
| 859 | } |
| 860 | |
| 861 | TEST_F(OutputLayerTest, requiresClientCompositionReturnsTrueIfSetToClientComposition) { |
| 862 | mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr}; |
| 863 | mOutputLayer.editState().hwc->hwcCompositionType = Hwc2::IComposerClient::Composition::CLIENT; |
| 864 | |
| 865 | EXPECT_TRUE(mOutputLayer.requiresClientComposition()); |
| 866 | } |
| 867 | |
| 868 | TEST_F(OutputLayerTest, requiresClientCompositionReturnsFalseIfSetToDeviceComposition) { |
| 869 | mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr}; |
| 870 | mOutputLayer.editState().hwc->hwcCompositionType = Hwc2::IComposerClient::Composition::DEVICE; |
| 871 | |
| 872 | EXPECT_FALSE(mOutputLayer.requiresClientComposition()); |
| 873 | } |
| 874 | |
| 875 | /* |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 876 | * OutputLayer::isHardwareCursor() |
| 877 | */ |
| 878 | |
| 879 | TEST_F(OutputLayerTest, isHardwareCursorReturnsFalseIfNoHWC2State) { |
| 880 | mOutputLayer.editState().hwc.reset(); |
| 881 | |
| 882 | EXPECT_FALSE(mOutputLayer.isHardwareCursor()); |
| 883 | } |
| 884 | |
| 885 | TEST_F(OutputLayerTest, isHardwareCursorReturnsTrueIfSetToCursorComposition) { |
| 886 | mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr}; |
| 887 | mOutputLayer.editState().hwc->hwcCompositionType = Hwc2::IComposerClient::Composition::CURSOR; |
| 888 | |
| 889 | EXPECT_TRUE(mOutputLayer.isHardwareCursor()); |
| 890 | } |
| 891 | |
| 892 | TEST_F(OutputLayerTest, isHardwareCursorReturnsFalseIfSetToDeviceComposition) { |
| 893 | mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr}; |
| 894 | mOutputLayer.editState().hwc->hwcCompositionType = Hwc2::IComposerClient::Composition::DEVICE; |
| 895 | |
| 896 | EXPECT_FALSE(mOutputLayer.isHardwareCursor()); |
| 897 | } |
| 898 | |
| 899 | /* |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 900 | * OutputLayer::applyDeviceCompositionTypeChange() |
| 901 | */ |
| 902 | |
| 903 | TEST_F(OutputLayerTest, applyDeviceCompositionTypeChangeSetsNewType) { |
| 904 | mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr}; |
| 905 | mOutputLayer.editState().hwc->hwcCompositionType = Hwc2::IComposerClient::Composition::DEVICE; |
| 906 | |
| 907 | mOutputLayer.applyDeviceCompositionTypeChange(Hwc2::IComposerClient::Composition::CLIENT); |
| 908 | |
| 909 | ASSERT_TRUE(mOutputLayer.getState().hwc); |
| 910 | EXPECT_EQ(Hwc2::IComposerClient::Composition::CLIENT, |
| 911 | mOutputLayer.getState().hwc->hwcCompositionType); |
| 912 | } |
| 913 | |
| 914 | /* |
| 915 | * OutputLayer::prepareForDeviceLayerRequests() |
| 916 | */ |
| 917 | |
| 918 | TEST_F(OutputLayerTest, prepareForDeviceLayerRequestsResetsRequestState) { |
| 919 | mOutputLayer.editState().clearClientTarget = true; |
| 920 | |
| 921 | mOutputLayer.prepareForDeviceLayerRequests(); |
| 922 | |
| 923 | EXPECT_FALSE(mOutputLayer.getState().clearClientTarget); |
| 924 | } |
| 925 | |
| 926 | /* |
| 927 | * OutputLayer::applyDeviceLayerRequest() |
| 928 | */ |
| 929 | |
| 930 | TEST_F(OutputLayerTest, applyDeviceLayerRequestHandlesClearClientTarget) { |
| 931 | mOutputLayer.editState().clearClientTarget = false; |
| 932 | |
| 933 | mOutputLayer.applyDeviceLayerRequest(Hwc2::IComposerClient::LayerRequest::CLEAR_CLIENT_TARGET); |
| 934 | |
| 935 | EXPECT_TRUE(mOutputLayer.getState().clearClientTarget); |
| 936 | } |
| 937 | |
| 938 | TEST_F(OutputLayerTest, applyDeviceLayerRequestHandlesUnknownRequest) { |
| 939 | mOutputLayer.editState().clearClientTarget = false; |
| 940 | |
| 941 | mOutputLayer.applyDeviceLayerRequest(static_cast<Hwc2::IComposerClient::LayerRequest>(0)); |
| 942 | |
| 943 | EXPECT_FALSE(mOutputLayer.getState().clearClientTarget); |
| 944 | } |
| 945 | |
Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 946 | /* |
| 947 | * OutputLayer::needsFiltering() |
| 948 | */ |
| 949 | |
| 950 | TEST_F(OutputLayerTest, needsFilteringReturnsFalseIfDisplaySizeSameAsSourceSize) { |
| 951 | mOutputLayer.editState().displayFrame = Rect(100, 100, 200, 200); |
| 952 | mOutputLayer.editState().sourceCrop = FloatRect{0.f, 0.f, 100.f, 100.f}; |
| 953 | |
| 954 | EXPECT_FALSE(mOutputLayer.needsFiltering()); |
| 955 | } |
| 956 | |
| 957 | TEST_F(OutputLayerTest, needsFilteringReturnsTrueIfDisplaySizeDifferentFromSourceSize) { |
| 958 | mOutputLayer.editState().displayFrame = Rect(100, 100, 200, 200); |
| 959 | mOutputLayer.editState().sourceCrop = FloatRect{0.f, 0.f, 100.1f, 100.1f}; |
| 960 | |
| 961 | EXPECT_TRUE(mOutputLayer.needsFiltering()); |
| 962 | } |
| 963 | |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 964 | } // namespace |
| 965 | } // namespace android::compositionengine |