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; |
Lloyd Pique | fe67102 | 2019-09-24 10:43:03 -0700 | [diff] [blame] | 461 | mOutputLayer.editState().forceClientComposition = true; |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 462 | |
| 463 | setupGeometryChildCallValues(); |
| 464 | |
| 465 | mOutputLayer.updateCompositionState(true); |
| 466 | |
| 467 | validateComputedGeometryState(); |
| 468 | |
| 469 | EXPECT_EQ(false, mOutputLayer.getState().forceClientComposition); |
| 470 | } |
| 471 | |
| 472 | TEST_F(OutputLayerUpdateCompositionStateTest, |
| 473 | alsoSetsForceCompositionIfSecureLayerOnNonsecureOutput) { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 474 | mLayerFEState.isSecure = true; |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 475 | mOutputState.isSecure = false; |
| 476 | |
| 477 | setupGeometryChildCallValues(); |
| 478 | |
| 479 | mOutputLayer.updateCompositionState(true); |
| 480 | |
| 481 | validateComputedGeometryState(); |
| 482 | |
| 483 | EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition); |
| 484 | } |
| 485 | |
| 486 | TEST_F(OutputLayerUpdateCompositionStateTest, |
| 487 | alsoSetsForceCompositionIfUnsupportedBufferTransform) { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 488 | mLayerFEState.isSecure = true; |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 489 | mOutputState.isSecure = true; |
| 490 | |
| 491 | mBufferTransform = ui::Transform::ROT_INVALID; |
| 492 | |
| 493 | setupGeometryChildCallValues(); |
| 494 | |
| 495 | mOutputLayer.updateCompositionState(true); |
| 496 | |
| 497 | validateComputedGeometryState(); |
| 498 | |
| 499 | EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition); |
| 500 | } |
| 501 | |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 502 | TEST_F(OutputLayerUpdateCompositionStateTest, setsOutputLayerColorspaceCorrectly) { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 503 | mLayerFEState.dataspace = ui::Dataspace::DISPLAY_P3; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 504 | mOutputState.targetDataspace = ui::Dataspace::V0_SCRGB; |
| 505 | |
| 506 | // If the layer is not colorspace agnostic, the output layer dataspace |
| 507 | // should use the layers requested colorspace. |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 508 | mLayerFEState.isColorspaceAgnostic = false; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 509 | |
| 510 | mOutputLayer.updateCompositionState(false); |
| 511 | |
| 512 | EXPECT_EQ(ui::Dataspace::DISPLAY_P3, mOutputLayer.getState().dataspace); |
| 513 | |
| 514 | // If the layer is colorspace agnostic, the output layer dataspace |
| 515 | // should use the colorspace chosen for the whole output. |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 516 | mLayerFEState.isColorspaceAgnostic = true; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 517 | |
| 518 | mOutputLayer.updateCompositionState(false); |
| 519 | |
| 520 | EXPECT_EQ(ui::Dataspace::V0_SCRGB, mOutputLayer.getState().dataspace); |
| 521 | } |
| 522 | |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 523 | TEST_F(OutputLayerUpdateCompositionStateTest, doesNotRecomputeGeometryIfNotRequested) { |
Lloyd Pique | fe67102 | 2019-09-24 10:43:03 -0700 | [diff] [blame] | 524 | mOutputLayer.editState().forceClientComposition = false; |
| 525 | |
Lloyd Pique | 67e3d9b | 2019-03-22 23:09:28 +0000 | [diff] [blame] | 526 | mOutputLayer.updateCompositionState(false); |
| 527 | |
| 528 | EXPECT_EQ(false, mOutputLayer.getState().forceClientComposition); |
| 529 | } |
| 530 | |
Lloyd Pique | fe67102 | 2019-09-24 10:43:03 -0700 | [diff] [blame] | 531 | TEST_F(OutputLayerUpdateCompositionStateTest, |
| 532 | doesNotClearForceClientCompositionIfNotDoingGeometry) { |
| 533 | mOutputLayer.editState().forceClientComposition = true; |
| 534 | |
| 535 | mOutputLayer.updateCompositionState(false); |
| 536 | |
| 537 | EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition); |
| 538 | } |
| 539 | |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 540 | TEST_F(OutputLayerUpdateCompositionStateTest, clientCompositionForcedFromFrontEndFlagAtAnyTime) { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 541 | mLayerFEState.forceClientComposition = true; |
Lloyd Pique | fe67102 | 2019-09-24 10:43:03 -0700 | [diff] [blame] | 542 | mOutputLayer.editState().forceClientComposition = false; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 543 | |
| 544 | mOutputLayer.updateCompositionState(false); |
| 545 | |
| 546 | EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition); |
| 547 | } |
| 548 | |
| 549 | TEST_F(OutputLayerUpdateCompositionStateTest, |
| 550 | clientCompositionForcedFromUnsupportedDataspaceAtAnyTime) { |
Lloyd Pique | fe67102 | 2019-09-24 10:43:03 -0700 | [diff] [blame] | 551 | mOutputLayer.editState().forceClientComposition = false; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 552 | EXPECT_CALL(mDisplayColorProfile, isDataspaceSupported(_)).WillRepeatedly(Return(false)); |
| 553 | |
| 554 | mOutputLayer.updateCompositionState(false); |
| 555 | |
| 556 | EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition); |
| 557 | } |
| 558 | |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 559 | /* |
| 560 | * OutputLayer::writeStateToHWC() |
| 561 | */ |
| 562 | |
| 563 | struct OutputLayerWriteStateToHWCTest : public OutputLayerTest { |
| 564 | static constexpr HWC2::Error kError = HWC2::Error::Unsupported; |
| 565 | static constexpr FloatRect kSourceCrop{11.f, 12.f, 13.f, 14.f}; |
| 566 | static constexpr uint32_t kZOrder = 21u; |
| 567 | static constexpr Hwc2::Transform kBufferTransform = static_cast<Hwc2::Transform>(31); |
| 568 | static constexpr Hwc2::IComposerClient::BlendMode kBlendMode = |
| 569 | static_cast<Hwc2::IComposerClient::BlendMode>(41); |
| 570 | static constexpr float kAlpha = 51.f; |
| 571 | static constexpr uint32_t kType = 61u; |
| 572 | static constexpr uint32_t kAppId = 62u; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 573 | static constexpr ui::Dataspace kDataspace = static_cast<ui::Dataspace>(71); |
| 574 | static constexpr int kSupportedPerFrameMetadata = 101; |
| 575 | static constexpr int kExpectedHwcSlot = 0; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 576 | |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 577 | static const half4 kColor; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 578 | static const Rect kDisplayFrame; |
Lloyd Pique | a246866 | 2019-03-07 21:31:06 -0800 | [diff] [blame] | 579 | static const Region kOutputSpaceVisibleRegion; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 580 | static const mat4 kColorTransform; |
| 581 | static const Region kSurfaceDamage; |
| 582 | static const HdrMetadata kHdrMetadata; |
| 583 | static native_handle_t* kSidebandStreamHandle; |
| 584 | static const sp<GraphicBuffer> kBuffer; |
| 585 | static const sp<Fence> kFence; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 586 | |
| 587 | OutputLayerWriteStateToHWCTest() { |
| 588 | auto& outputLayerState = mOutputLayer.editState(); |
| 589 | outputLayerState.hwc = impl::OutputLayerCompositionState::Hwc(mHwcLayer); |
| 590 | |
| 591 | outputLayerState.displayFrame = kDisplayFrame; |
| 592 | outputLayerState.sourceCrop = kSourceCrop; |
| 593 | outputLayerState.z = kZOrder; |
| 594 | outputLayerState.bufferTransform = static_cast<Hwc2::Transform>(kBufferTransform); |
Lloyd Pique | a246866 | 2019-03-07 21:31:06 -0800 | [diff] [blame] | 595 | outputLayerState.outputSpaceVisibleRegion = kOutputSpaceVisibleRegion; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 596 | outputLayerState.dataspace = kDataspace; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 597 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 598 | mLayerFEState.blendMode = kBlendMode; |
| 599 | mLayerFEState.alpha = kAlpha; |
| 600 | mLayerFEState.type = kType; |
| 601 | mLayerFEState.appId = kAppId; |
| 602 | mLayerFEState.colorTransform = kColorTransform; |
| 603 | mLayerFEState.color = kColor; |
| 604 | mLayerFEState.surfaceDamage = kSurfaceDamage; |
| 605 | mLayerFEState.hdrMetadata = kHdrMetadata; |
| 606 | mLayerFEState.sidebandStream = NativeHandle::create(kSidebandStreamHandle, false); |
| 607 | mLayerFEState.buffer = kBuffer; |
| 608 | mLayerFEState.bufferSlot = BufferQueue::INVALID_BUFFER_SLOT; |
| 609 | mLayerFEState.acquireFence = kFence; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 610 | |
| 611 | EXPECT_CALL(mOutput, getDisplayColorProfile()) |
| 612 | .WillRepeatedly(Return(&mDisplayColorProfile)); |
| 613 | EXPECT_CALL(mDisplayColorProfile, getSupportedPerFrameMetadata()) |
| 614 | .WillRepeatedly(Return(kSupportedPerFrameMetadata)); |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 615 | } |
| 616 | |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 617 | // Some tests may need to simulate unsupported HWC calls |
| 618 | enum class SimulateUnsupported { None, ColorTransform }; |
| 619 | |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 620 | void expectGeometryCommonCalls() { |
| 621 | EXPECT_CALL(*mHwcLayer, setDisplayFrame(kDisplayFrame)).WillOnce(Return(kError)); |
| 622 | EXPECT_CALL(*mHwcLayer, setSourceCrop(kSourceCrop)).WillOnce(Return(kError)); |
| 623 | EXPECT_CALL(*mHwcLayer, setZOrder(kZOrder)).WillOnce(Return(kError)); |
| 624 | EXPECT_CALL(*mHwcLayer, setTransform(static_cast<HWC2::Transform>(kBufferTransform))) |
| 625 | .WillOnce(Return(kError)); |
| 626 | |
| 627 | EXPECT_CALL(*mHwcLayer, setBlendMode(static_cast<HWC2::BlendMode>(kBlendMode))) |
| 628 | .WillOnce(Return(kError)); |
| 629 | EXPECT_CALL(*mHwcLayer, setPlaneAlpha(kAlpha)).WillOnce(Return(kError)); |
| 630 | EXPECT_CALL(*mHwcLayer, setInfo(kType, kAppId)).WillOnce(Return(kError)); |
| 631 | } |
| 632 | |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 633 | void expectPerFrameCommonCalls(SimulateUnsupported unsupported = SimulateUnsupported::None) { |
Lloyd Pique | a246866 | 2019-03-07 21:31:06 -0800 | [diff] [blame] | 634 | EXPECT_CALL(*mHwcLayer, setVisibleRegion(RegionEq(kOutputSpaceVisibleRegion))) |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 635 | .WillOnce(Return(kError)); |
| 636 | EXPECT_CALL(*mHwcLayer, setDataspace(kDataspace)).WillOnce(Return(kError)); |
| 637 | EXPECT_CALL(*mHwcLayer, setColorTransform(kColorTransform)) |
| 638 | .WillOnce(Return(unsupported == SimulateUnsupported::ColorTransform |
| 639 | ? HWC2::Error::Unsupported |
| 640 | : HWC2::Error::None)); |
| 641 | EXPECT_CALL(*mHwcLayer, setSurfaceDamage(RegionEq(kSurfaceDamage))) |
| 642 | .WillOnce(Return(kError)); |
| 643 | } |
| 644 | |
| 645 | void expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition compositionType) { |
| 646 | EXPECT_CALL(*mHwcLayer, setCompositionType(static_cast<HWC2::Composition>(compositionType))) |
| 647 | .WillOnce(Return(kError)); |
| 648 | } |
| 649 | |
| 650 | void expectNoSetCompositionTypeCall() { |
| 651 | EXPECT_CALL(*mHwcLayer, setCompositionType(_)).Times(0); |
| 652 | } |
| 653 | |
| 654 | void expectSetColorCall() { |
| 655 | hwc_color_t color = {static_cast<uint8_t>(std::round(kColor.r * 255)), |
| 656 | static_cast<uint8_t>(std::round(kColor.g * 255)), |
| 657 | static_cast<uint8_t>(std::round(kColor.b * 255)), 255}; |
| 658 | |
| 659 | EXPECT_CALL(*mHwcLayer, setColor(ColorEq(color))).WillOnce(Return(kError)); |
| 660 | } |
| 661 | |
| 662 | void expectSetSidebandHandleCall() { |
| 663 | EXPECT_CALL(*mHwcLayer, setSidebandStream(kSidebandStreamHandle)); |
| 664 | } |
| 665 | |
| 666 | void expectSetHdrMetadataAndBufferCalls() { |
| 667 | EXPECT_CALL(*mHwcLayer, setPerFrameMetadata(kSupportedPerFrameMetadata, kHdrMetadata)); |
| 668 | EXPECT_CALL(*mHwcLayer, setBuffer(kExpectedHwcSlot, kBuffer, kFence)); |
| 669 | } |
| 670 | |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 671 | 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] | 672 | StrictMock<mock::DisplayColorProfile> mDisplayColorProfile; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 673 | }; |
| 674 | |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 675 | const half4 OutputLayerWriteStateToHWCTest::kColor{81.f / 255.f, 82.f / 255.f, 83.f / 255.f, |
| 676 | 84.f / 255.f}; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 677 | const Rect OutputLayerWriteStateToHWCTest::kDisplayFrame{1001, 1002, 1003, 10044}; |
Lloyd Pique | a246866 | 2019-03-07 21:31:06 -0800 | [diff] [blame] | 678 | const Region OutputLayerWriteStateToHWCTest::kOutputSpaceVisibleRegion{ |
| 679 | Rect{1005, 1006, 1007, 1008}}; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 680 | const mat4 OutputLayerWriteStateToHWCTest::kColorTransform{ |
| 681 | 1009, 1010, 1011, 1012, 1013, 1014, 1015, 1016, |
| 682 | 1017, 1018, 1019, 1020, 1021, 1022, 1023, 1024, |
| 683 | }; |
| 684 | const Region OutputLayerWriteStateToHWCTest::kSurfaceDamage{Rect{1025, 1026, 1027, 1028}}; |
| 685 | const HdrMetadata OutputLayerWriteStateToHWCTest::kHdrMetadata{{/* LightFlattenable */}, 1029}; |
| 686 | native_handle_t* OutputLayerWriteStateToHWCTest::kSidebandStreamHandle = |
| 687 | reinterpret_cast<native_handle_t*>(1031); |
| 688 | const sp<GraphicBuffer> OutputLayerWriteStateToHWCTest::kBuffer; |
| 689 | const sp<Fence> OutputLayerWriteStateToHWCTest::kFence; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 690 | |
| 691 | TEST_F(OutputLayerWriteStateToHWCTest, doesNothingIfNoHWCState) { |
| 692 | mOutputLayer.editState().hwc.reset(); |
| 693 | |
| 694 | mOutputLayer.writeStateToHWC(true); |
| 695 | } |
| 696 | |
| 697 | TEST_F(OutputLayerWriteStateToHWCTest, doesNothingIfNoHWCLayer) { |
| 698 | mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc(nullptr); |
| 699 | |
| 700 | mOutputLayer.writeStateToHWC(true); |
| 701 | } |
| 702 | |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 703 | TEST_F(OutputLayerWriteStateToHWCTest, canSetAllState) { |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 704 | expectGeometryCommonCalls(); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 705 | expectPerFrameCommonCalls(); |
| 706 | |
| 707 | expectNoSetCompositionTypeCall(); |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 708 | |
| 709 | mOutputLayer.writeStateToHWC(true); |
| 710 | } |
| 711 | |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 712 | TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForSolidColor) { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 713 | mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::SOLID_COLOR; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 714 | |
| 715 | expectPerFrameCommonCalls(); |
| 716 | expectSetColorCall(); |
| 717 | expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::SOLID_COLOR); |
| 718 | |
| 719 | mOutputLayer.writeStateToHWC(false); |
| 720 | } |
| 721 | |
| 722 | TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForSideband) { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 723 | mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::SIDEBAND; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 724 | |
| 725 | expectPerFrameCommonCalls(); |
| 726 | expectSetSidebandHandleCall(); |
| 727 | expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::SIDEBAND); |
| 728 | |
| 729 | mOutputLayer.writeStateToHWC(false); |
| 730 | } |
| 731 | |
| 732 | TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForCursor) { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 733 | mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::CURSOR; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 734 | |
| 735 | expectPerFrameCommonCalls(); |
| 736 | expectSetHdrMetadataAndBufferCalls(); |
| 737 | expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::CURSOR); |
| 738 | |
| 739 | mOutputLayer.writeStateToHWC(false); |
| 740 | } |
| 741 | |
| 742 | TEST_F(OutputLayerWriteStateToHWCTest, canSetPerFrameStateForDevice) { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 743 | mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::DEVICE; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 744 | |
| 745 | expectPerFrameCommonCalls(); |
| 746 | expectSetHdrMetadataAndBufferCalls(); |
| 747 | expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::DEVICE); |
| 748 | |
| 749 | mOutputLayer.writeStateToHWC(false); |
| 750 | } |
| 751 | |
| 752 | TEST_F(OutputLayerWriteStateToHWCTest, compositionTypeIsNotSetIfUnchanged) { |
| 753 | (*mOutputLayer.editState().hwc).hwcCompositionType = |
| 754 | Hwc2::IComposerClient::Composition::SOLID_COLOR; |
| 755 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 756 | mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::SOLID_COLOR; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 757 | |
| 758 | expectPerFrameCommonCalls(); |
| 759 | expectSetColorCall(); |
| 760 | expectNoSetCompositionTypeCall(); |
| 761 | |
| 762 | mOutputLayer.writeStateToHWC(false); |
| 763 | } |
| 764 | |
| 765 | TEST_F(OutputLayerWriteStateToHWCTest, compositionTypeIsSetToClientIfColorTransformNotSupported) { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 766 | mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::SOLID_COLOR; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 767 | |
| 768 | expectPerFrameCommonCalls(SimulateUnsupported::ColorTransform); |
| 769 | expectSetColorCall(); |
| 770 | expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::CLIENT); |
| 771 | |
| 772 | mOutputLayer.writeStateToHWC(false); |
| 773 | } |
| 774 | |
| 775 | TEST_F(OutputLayerWriteStateToHWCTest, compositionTypeIsSetToClientIfClientCompositionForced) { |
| 776 | mOutputLayer.editState().forceClientComposition = true; |
| 777 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 778 | mLayerFEState.compositionType = Hwc2::IComposerClient::Composition::SOLID_COLOR; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 779 | |
| 780 | expectPerFrameCommonCalls(); |
| 781 | expectSetColorCall(); |
| 782 | expectSetCompositionTypeCall(Hwc2::IComposerClient::Composition::CLIENT); |
| 783 | |
| 784 | mOutputLayer.writeStateToHWC(false); |
| 785 | } |
| 786 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 787 | /* |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 788 | * OutputLayer::writeCursorPositionToHWC() |
| 789 | */ |
| 790 | |
| 791 | struct OutputLayerWriteCursorPositionToHWCTest : public OutputLayerTest { |
| 792 | static constexpr int kDefaultTransform = TR_IDENT; |
| 793 | static constexpr HWC2::Error kDefaultError = HWC2::Error::Unsupported; |
| 794 | |
| 795 | static const Rect kDefaultDisplayViewport; |
| 796 | static const Rect kDefaultCursorFrame; |
| 797 | |
| 798 | OutputLayerWriteCursorPositionToHWCTest() { |
| 799 | auto& outputLayerState = mOutputLayer.editState(); |
| 800 | outputLayerState.hwc = impl::OutputLayerCompositionState::Hwc(mHwcLayer); |
| 801 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 802 | mLayerFEState.cursorFrame = kDefaultCursorFrame; |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 803 | |
| 804 | mOutputState.viewport = kDefaultDisplayViewport; |
| 805 | mOutputState.transform = ui::Transform{kDefaultTransform}; |
| 806 | } |
| 807 | |
| 808 | std::shared_ptr<HWC2::mock::Layer> mHwcLayer{std::make_shared<StrictMock<HWC2::mock::Layer>>()}; |
| 809 | }; |
| 810 | |
| 811 | const Rect OutputLayerWriteCursorPositionToHWCTest::kDefaultDisplayViewport{0, 0, 1920, 1080}; |
| 812 | const Rect OutputLayerWriteCursorPositionToHWCTest::kDefaultCursorFrame{1, 2, 3, 4}; |
| 813 | |
| 814 | TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCHandlesNoHwcState) { |
| 815 | mOutputLayer.editState().hwc.reset(); |
| 816 | |
| 817 | mOutputLayer.writeCursorPositionToHWC(); |
| 818 | } |
| 819 | |
| 820 | TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCWritesStateToHWC) { |
| 821 | EXPECT_CALL(*mHwcLayer, setCursorPosition(1, 2)).WillOnce(Return(kDefaultError)); |
| 822 | |
| 823 | mOutputLayer.writeCursorPositionToHWC(); |
| 824 | } |
| 825 | |
| 826 | TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCIntersectedWithViewport) { |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 827 | mLayerFEState.cursorFrame = Rect{3000, 3000, 3016, 3016}; |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 828 | |
| 829 | EXPECT_CALL(*mHwcLayer, setCursorPosition(1920, 1080)).WillOnce(Return(kDefaultError)); |
| 830 | |
| 831 | mOutputLayer.writeCursorPositionToHWC(); |
| 832 | } |
| 833 | |
| 834 | TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCRotatedByTransform) { |
| 835 | mOutputState.transform = ui::Transform{TR_ROT_90}; |
| 836 | |
| 837 | EXPECT_CALL(*mHwcLayer, setCursorPosition(-4, 1)).WillOnce(Return(kDefaultError)); |
| 838 | |
| 839 | mOutputLayer.writeCursorPositionToHWC(); |
| 840 | } |
| 841 | |
| 842 | /* |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 843 | * OutputLayer::getHwcLayer() |
| 844 | */ |
| 845 | |
| 846 | TEST_F(OutputLayerTest, getHwcLayerHandlesNoHwcState) { |
| 847 | mOutputLayer.editState().hwc.reset(); |
| 848 | |
| 849 | EXPECT_TRUE(mOutputLayer.getHwcLayer() == nullptr); |
| 850 | } |
| 851 | |
| 852 | TEST_F(OutputLayerTest, getHwcLayerHandlesNoHwcLayer) { |
| 853 | mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr}; |
| 854 | |
| 855 | EXPECT_TRUE(mOutputLayer.getHwcLayer() == nullptr); |
| 856 | } |
| 857 | |
| 858 | TEST_F(OutputLayerTest, getHwcLayerReturnsHwcLayer) { |
| 859 | auto hwcLayer = std::make_shared<StrictMock<HWC2::mock::Layer>>(); |
| 860 | mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{hwcLayer}; |
| 861 | |
| 862 | EXPECT_EQ(hwcLayer.get(), mOutputLayer.getHwcLayer()); |
| 863 | } |
| 864 | |
| 865 | /* |
| 866 | * OutputLayer::requiresClientComposition() |
| 867 | */ |
| 868 | |
| 869 | TEST_F(OutputLayerTest, requiresClientCompositionReturnsTrueIfNoHWC2State) { |
| 870 | mOutputLayer.editState().hwc.reset(); |
| 871 | |
| 872 | EXPECT_TRUE(mOutputLayer.requiresClientComposition()); |
| 873 | } |
| 874 | |
| 875 | TEST_F(OutputLayerTest, requiresClientCompositionReturnsTrueIfSetToClientComposition) { |
| 876 | mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr}; |
| 877 | mOutputLayer.editState().hwc->hwcCompositionType = Hwc2::IComposerClient::Composition::CLIENT; |
| 878 | |
| 879 | EXPECT_TRUE(mOutputLayer.requiresClientComposition()); |
| 880 | } |
| 881 | |
| 882 | TEST_F(OutputLayerTest, requiresClientCompositionReturnsFalseIfSetToDeviceComposition) { |
| 883 | mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr}; |
| 884 | mOutputLayer.editState().hwc->hwcCompositionType = Hwc2::IComposerClient::Composition::DEVICE; |
| 885 | |
| 886 | EXPECT_FALSE(mOutputLayer.requiresClientComposition()); |
| 887 | } |
| 888 | |
| 889 | /* |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 890 | * OutputLayer::isHardwareCursor() |
| 891 | */ |
| 892 | |
| 893 | TEST_F(OutputLayerTest, isHardwareCursorReturnsFalseIfNoHWC2State) { |
| 894 | mOutputLayer.editState().hwc.reset(); |
| 895 | |
| 896 | EXPECT_FALSE(mOutputLayer.isHardwareCursor()); |
| 897 | } |
| 898 | |
| 899 | TEST_F(OutputLayerTest, isHardwareCursorReturnsTrueIfSetToCursorComposition) { |
| 900 | mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr}; |
| 901 | mOutputLayer.editState().hwc->hwcCompositionType = Hwc2::IComposerClient::Composition::CURSOR; |
| 902 | |
| 903 | EXPECT_TRUE(mOutputLayer.isHardwareCursor()); |
| 904 | } |
| 905 | |
| 906 | TEST_F(OutputLayerTest, isHardwareCursorReturnsFalseIfSetToDeviceComposition) { |
| 907 | mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr}; |
| 908 | mOutputLayer.editState().hwc->hwcCompositionType = Hwc2::IComposerClient::Composition::DEVICE; |
| 909 | |
| 910 | EXPECT_FALSE(mOutputLayer.isHardwareCursor()); |
| 911 | } |
| 912 | |
| 913 | /* |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 914 | * OutputLayer::applyDeviceCompositionTypeChange() |
| 915 | */ |
| 916 | |
| 917 | TEST_F(OutputLayerTest, applyDeviceCompositionTypeChangeSetsNewType) { |
| 918 | mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr}; |
| 919 | mOutputLayer.editState().hwc->hwcCompositionType = Hwc2::IComposerClient::Composition::DEVICE; |
| 920 | |
| 921 | mOutputLayer.applyDeviceCompositionTypeChange(Hwc2::IComposerClient::Composition::CLIENT); |
| 922 | |
| 923 | ASSERT_TRUE(mOutputLayer.getState().hwc); |
| 924 | EXPECT_EQ(Hwc2::IComposerClient::Composition::CLIENT, |
| 925 | mOutputLayer.getState().hwc->hwcCompositionType); |
| 926 | } |
| 927 | |
| 928 | /* |
| 929 | * OutputLayer::prepareForDeviceLayerRequests() |
| 930 | */ |
| 931 | |
| 932 | TEST_F(OutputLayerTest, prepareForDeviceLayerRequestsResetsRequestState) { |
| 933 | mOutputLayer.editState().clearClientTarget = true; |
| 934 | |
| 935 | mOutputLayer.prepareForDeviceLayerRequests(); |
| 936 | |
| 937 | EXPECT_FALSE(mOutputLayer.getState().clearClientTarget); |
| 938 | } |
| 939 | |
| 940 | /* |
| 941 | * OutputLayer::applyDeviceLayerRequest() |
| 942 | */ |
| 943 | |
| 944 | TEST_F(OutputLayerTest, applyDeviceLayerRequestHandlesClearClientTarget) { |
| 945 | mOutputLayer.editState().clearClientTarget = false; |
| 946 | |
| 947 | mOutputLayer.applyDeviceLayerRequest(Hwc2::IComposerClient::LayerRequest::CLEAR_CLIENT_TARGET); |
| 948 | |
| 949 | EXPECT_TRUE(mOutputLayer.getState().clearClientTarget); |
| 950 | } |
| 951 | |
| 952 | TEST_F(OutputLayerTest, applyDeviceLayerRequestHandlesUnknownRequest) { |
| 953 | mOutputLayer.editState().clearClientTarget = false; |
| 954 | |
| 955 | mOutputLayer.applyDeviceLayerRequest(static_cast<Hwc2::IComposerClient::LayerRequest>(0)); |
| 956 | |
| 957 | EXPECT_FALSE(mOutputLayer.getState().clearClientTarget); |
| 958 | } |
| 959 | |
Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 960 | /* |
| 961 | * OutputLayer::needsFiltering() |
| 962 | */ |
| 963 | |
| 964 | TEST_F(OutputLayerTest, needsFilteringReturnsFalseIfDisplaySizeSameAsSourceSize) { |
| 965 | mOutputLayer.editState().displayFrame = Rect(100, 100, 200, 200); |
| 966 | mOutputLayer.editState().sourceCrop = FloatRect{0.f, 0.f, 100.f, 100.f}; |
| 967 | |
| 968 | EXPECT_FALSE(mOutputLayer.needsFiltering()); |
| 969 | } |
| 970 | |
| 971 | TEST_F(OutputLayerTest, needsFilteringReturnsTrueIfDisplaySizeDifferentFromSourceSize) { |
| 972 | mOutputLayer.editState().displayFrame = Rect(100, 100, 200, 200); |
| 973 | mOutputLayer.editState().sourceCrop = FloatRect{0.f, 0.f, 100.1f, 100.1f}; |
| 974 | |
| 975 | EXPECT_TRUE(mOutputLayer.needsFiltering()); |
| 976 | } |
| 977 | |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 978 | } // namespace |
| 979 | } // namespace android::compositionengine |