Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [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 | |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 17 | #include <cmath> |
| 18 | |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 19 | #include <compositionengine/DisplayColorProfileCreationArgs.h> |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 20 | #include <compositionengine/DisplayCreationArgs.h> |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 21 | #include <compositionengine/DisplaySurface.h> |
| 22 | #include <compositionengine/RenderSurfaceCreationArgs.h> |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 23 | #include <compositionengine/impl/Display.h> |
| 24 | #include <compositionengine/mock/CompositionEngine.h> |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 25 | #include <compositionengine/mock/DisplayColorProfile.h> |
chaviw | 8beb414 | 2019-04-11 13:09:05 -0700 | [diff] [blame] | 26 | #include <compositionengine/mock/NativeWindow.h> |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame^] | 27 | #include <compositionengine/mock/OutputLayer.h> |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 28 | #include <compositionengine/mock/RenderSurface.h> |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 29 | #include <gtest/gtest.h> |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 30 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame^] | 31 | #include "MockHWC2.h" |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 32 | #include "MockHWComposer.h" |
| 33 | |
| 34 | namespace android::compositionengine { |
| 35 | namespace { |
| 36 | |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 37 | using testing::_; |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame^] | 38 | using testing::DoAll; |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 39 | using testing::Return; |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 40 | using testing::ReturnRef; |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame^] | 41 | using testing::Sequence; |
| 42 | using testing::SetArgPointee; |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 43 | using testing::StrictMock; |
| 44 | |
| 45 | constexpr DisplayId DEFAULT_DISPLAY_ID = DisplayId{42}; |
| 46 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame^] | 47 | struct DisplayTest : public testing::Test { |
| 48 | DisplayTest() { |
| 49 | EXPECT_CALL(mCompositionEngine, getHwComposer()).WillRepeatedly(ReturnRef(mHwComposer)); |
| 50 | EXPECT_CALL(*mLayer1, getHwcLayer()).WillRepeatedly(Return(&mHWC2Layer1)); |
| 51 | EXPECT_CALL(*mLayer2, getHwcLayer()).WillRepeatedly(Return(&mHWC2Layer2)); |
| 52 | EXPECT_CALL(*mLayer3, getHwcLayer()).WillRepeatedly(Return(nullptr)); |
| 53 | |
| 54 | std::vector<std::unique_ptr<OutputLayer>> layers; |
| 55 | layers.emplace_back(mLayer1); |
| 56 | layers.emplace_back(mLayer2); |
| 57 | layers.emplace_back(mLayer3); |
| 58 | mDisplay.setOutputLayersOrderedByZ(std::move(layers)); |
| 59 | } |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 60 | |
| 61 | StrictMock<android::mock::HWComposer> mHwComposer; |
| 62 | StrictMock<mock::CompositionEngine> mCompositionEngine; |
chaviw | 8beb414 | 2019-04-11 13:09:05 -0700 | [diff] [blame] | 63 | sp<mock::NativeWindow> mNativeWindow = new StrictMock<mock::NativeWindow>(); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame^] | 64 | StrictMock<HWC2::mock::Layer> mHWC2Layer1; |
| 65 | StrictMock<HWC2::mock::Layer> mHWC2Layer2; |
| 66 | StrictMock<HWC2::mock::Layer> mHWC2LayerUnknown; |
| 67 | mock::OutputLayer* mLayer1 = new StrictMock<mock::OutputLayer>(); |
| 68 | mock::OutputLayer* mLayer2 = new StrictMock<mock::OutputLayer>(); |
| 69 | mock::OutputLayer* mLayer3 = new StrictMock<mock::OutputLayer>(); |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 70 | impl::Display mDisplay{mCompositionEngine, |
| 71 | DisplayCreationArgsBuilder().setDisplayId(DEFAULT_DISPLAY_ID).build()}; |
| 72 | }; |
| 73 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame^] | 74 | /* |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 75 | * Basic construction |
| 76 | */ |
| 77 | |
| 78 | TEST_F(DisplayTest, canInstantiateDisplay) { |
| 79 | { |
| 80 | constexpr DisplayId display1 = DisplayId{123u}; |
| 81 | auto display = |
| 82 | impl::createDisplay(mCompositionEngine, |
| 83 | DisplayCreationArgsBuilder().setDisplayId(display1).build()); |
| 84 | EXPECT_FALSE(display->isSecure()); |
| 85 | EXPECT_FALSE(display->isVirtual()); |
| 86 | EXPECT_EQ(display1, display->getId()); |
| 87 | } |
| 88 | |
| 89 | { |
| 90 | constexpr DisplayId display2 = DisplayId{546u}; |
| 91 | auto display = impl::createDisplay(mCompositionEngine, |
| 92 | DisplayCreationArgsBuilder() |
| 93 | .setIsSecure(true) |
| 94 | .setDisplayId(display2) |
| 95 | .build()); |
| 96 | EXPECT_TRUE(display->isSecure()); |
| 97 | EXPECT_FALSE(display->isVirtual()); |
| 98 | EXPECT_EQ(display2, display->getId()); |
| 99 | } |
| 100 | |
| 101 | { |
| 102 | constexpr DisplayId display3 = DisplayId{789u}; |
| 103 | auto display = impl::createDisplay(mCompositionEngine, |
| 104 | DisplayCreationArgsBuilder() |
| 105 | .setIsVirtual(true) |
| 106 | .setDisplayId(display3) |
| 107 | .build()); |
| 108 | EXPECT_FALSE(display->isSecure()); |
| 109 | EXPECT_TRUE(display->isVirtual()); |
| 110 | EXPECT_EQ(display3, display->getId()); |
| 111 | } |
| 112 | } |
| 113 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame^] | 114 | /* |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 115 | * Display::disconnect() |
| 116 | */ |
| 117 | |
| 118 | TEST_F(DisplayTest, disconnectDisconnectsDisplay) { |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 119 | // The first call to disconnect will disconnect the display with the HWC and |
| 120 | // set mHwcId to -1. |
| 121 | EXPECT_CALL(mHwComposer, disconnectDisplay(DEFAULT_DISPLAY_ID)).Times(1); |
| 122 | mDisplay.disconnect(); |
| 123 | EXPECT_FALSE(mDisplay.getId()); |
| 124 | |
| 125 | // Subsequent calls will do nothing, |
| 126 | EXPECT_CALL(mHwComposer, disconnectDisplay(DEFAULT_DISPLAY_ID)).Times(0); |
| 127 | mDisplay.disconnect(); |
| 128 | EXPECT_FALSE(mDisplay.getId()); |
| 129 | } |
| 130 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame^] | 131 | /* |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 132 | * Display::setColorTransform() |
| 133 | */ |
| 134 | |
| 135 | TEST_F(DisplayTest, setColorTransformSetsTransform) { |
| 136 | // Identity matrix sets an identity state value |
| 137 | const mat4 identity; |
| 138 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 139 | EXPECT_CALL(mHwComposer, setColorTransform(DEFAULT_DISPLAY_ID, identity)).Times(1); |
| 140 | |
| 141 | mDisplay.setColorTransform(identity); |
| 142 | |
| 143 | EXPECT_EQ(HAL_COLOR_TRANSFORM_IDENTITY, mDisplay.getState().colorTransform); |
| 144 | |
| 145 | // Non-identity matrix sets a non-identity state value |
| 146 | const mat4 nonIdentity = mat4() * 2; |
| 147 | |
| 148 | EXPECT_CALL(mHwComposer, setColorTransform(DEFAULT_DISPLAY_ID, nonIdentity)).Times(1); |
| 149 | |
| 150 | mDisplay.setColorTransform(nonIdentity); |
| 151 | |
| 152 | EXPECT_EQ(HAL_COLOR_TRANSFORM_ARBITRARY_MATRIX, mDisplay.getState().colorTransform); |
| 153 | } |
| 154 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame^] | 155 | /* |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 156 | * Display::setColorMode() |
| 157 | */ |
| 158 | |
| 159 | TEST_F(DisplayTest, setColorModeSetsModeUnlessNoChange) { |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 160 | mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>(); |
| 161 | mDisplay.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface)); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 162 | mock::DisplayColorProfile* colorProfile = new StrictMock<mock::DisplayColorProfile>(); |
| 163 | mDisplay.setDisplayColorProfileForTest(std::unique_ptr<DisplayColorProfile>(colorProfile)); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 164 | |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 165 | EXPECT_CALL(*colorProfile, getTargetDataspace(_, _, _)) |
| 166 | .WillRepeatedly(Return(ui::Dataspace::UNKNOWN)); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 167 | |
| 168 | // These values are expected to be the initial state. |
| 169 | ASSERT_EQ(ui::ColorMode::NATIVE, mDisplay.getState().colorMode); |
| 170 | ASSERT_EQ(ui::Dataspace::UNKNOWN, mDisplay.getState().dataspace); |
| 171 | ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mDisplay.getState().renderIntent); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 172 | ASSERT_EQ(ui::Dataspace::UNKNOWN, mDisplay.getState().targetDataspace); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 173 | |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 174 | // If the set values are unchanged, nothing happens |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 175 | mDisplay.setColorMode(ui::ColorMode::NATIVE, ui::Dataspace::UNKNOWN, |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 176 | ui::RenderIntent::COLORIMETRIC, ui::Dataspace::UNKNOWN); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 177 | |
| 178 | EXPECT_EQ(ui::ColorMode::NATIVE, mDisplay.getState().colorMode); |
| 179 | EXPECT_EQ(ui::Dataspace::UNKNOWN, mDisplay.getState().dataspace); |
| 180 | EXPECT_EQ(ui::RenderIntent::COLORIMETRIC, mDisplay.getState().renderIntent); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 181 | EXPECT_EQ(ui::Dataspace::UNKNOWN, mDisplay.getState().targetDataspace); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 182 | |
| 183 | // Otherwise if the values are different, updates happen |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 184 | EXPECT_CALL(*renderSurface, setBufferDataspace(ui::Dataspace::DISPLAY_P3)).Times(1); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 185 | EXPECT_CALL(mHwComposer, |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 186 | setActiveColorMode(DEFAULT_DISPLAY_ID, ui::ColorMode::DISPLAY_P3, |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 187 | ui::RenderIntent::TONE_MAP_COLORIMETRIC)) |
| 188 | .Times(1); |
| 189 | |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 190 | mDisplay.setColorMode(ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3, |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 191 | ui::RenderIntent::TONE_MAP_COLORIMETRIC, ui::Dataspace::UNKNOWN); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 192 | |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 193 | EXPECT_EQ(ui::ColorMode::DISPLAY_P3, mDisplay.getState().colorMode); |
| 194 | EXPECT_EQ(ui::Dataspace::DISPLAY_P3, mDisplay.getState().dataspace); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 195 | EXPECT_EQ(ui::RenderIntent::TONE_MAP_COLORIMETRIC, mDisplay.getState().renderIntent); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 196 | EXPECT_EQ(ui::Dataspace::UNKNOWN, mDisplay.getState().targetDataspace); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | TEST_F(DisplayTest, setColorModeDoesNothingForVirtualDisplay) { |
| 200 | impl::Display virtualDisplay{mCompositionEngine, |
| 201 | DisplayCreationArgs{false, true, DEFAULT_DISPLAY_ID}}; |
| 202 | |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 203 | mock::DisplayColorProfile* colorProfile = new StrictMock<mock::DisplayColorProfile>(); |
| 204 | virtualDisplay.setDisplayColorProfileForTest( |
| 205 | std::unique_ptr<DisplayColorProfile>(colorProfile)); |
| 206 | |
| 207 | EXPECT_CALL(*colorProfile, |
| 208 | getTargetDataspace(ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3, |
| 209 | ui::Dataspace::UNKNOWN)) |
| 210 | .WillOnce(Return(ui::Dataspace::UNKNOWN)); |
| 211 | |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 212 | virtualDisplay.setColorMode(ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3, |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 213 | ui::RenderIntent::TONE_MAP_COLORIMETRIC, ui::Dataspace::UNKNOWN); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 214 | |
| 215 | EXPECT_EQ(ui::ColorMode::NATIVE, virtualDisplay.getState().colorMode); |
| 216 | EXPECT_EQ(ui::Dataspace::UNKNOWN, virtualDisplay.getState().dataspace); |
| 217 | EXPECT_EQ(ui::RenderIntent::COLORIMETRIC, virtualDisplay.getState().renderIntent); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 218 | EXPECT_EQ(ui::Dataspace::UNKNOWN, mDisplay.getState().targetDataspace); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 219 | } |
| 220 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame^] | 221 | /* |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 222 | * Display::createDisplayColorProfile() |
| 223 | */ |
| 224 | |
| 225 | TEST_F(DisplayTest, createDisplayColorProfileSetsDisplayColorProfile) { |
| 226 | EXPECT_TRUE(mDisplay.getDisplayColorProfile() == nullptr); |
| 227 | mDisplay.createDisplayColorProfile( |
| 228 | DisplayColorProfileCreationArgs{false, HdrCapabilities(), 0, |
| 229 | DisplayColorProfileCreationArgs::HwcColorModes()}); |
| 230 | EXPECT_TRUE(mDisplay.getDisplayColorProfile() != nullptr); |
| 231 | } |
| 232 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame^] | 233 | /* |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 234 | * Display::createRenderSurface() |
| 235 | */ |
| 236 | |
| 237 | TEST_F(DisplayTest, createRenderSurfaceSetsRenderSurface) { |
chaviw | 8beb414 | 2019-04-11 13:09:05 -0700 | [diff] [blame] | 238 | EXPECT_CALL(*mNativeWindow, disconnect(NATIVE_WINDOW_API_EGL)).WillRepeatedly(Return(NO_ERROR)); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 239 | EXPECT_TRUE(mDisplay.getRenderSurface() == nullptr); |
chaviw | 8beb414 | 2019-04-11 13:09:05 -0700 | [diff] [blame] | 240 | mDisplay.createRenderSurface(RenderSurfaceCreationArgs{640, 480, mNativeWindow, nullptr}); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 241 | EXPECT_TRUE(mDisplay.getRenderSurface() != nullptr); |
| 242 | } |
| 243 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame^] | 244 | /* |
| 245 | * Display::chooseCompositionStrategy() |
| 246 | */ |
| 247 | |
| 248 | struct DisplayChooseCompositionStrategyTest : public testing::Test { |
| 249 | struct DisplayPartialMock : public impl::Display { |
| 250 | DisplayPartialMock(const compositionengine::CompositionEngine& compositionEngine, |
| 251 | compositionengine::DisplayCreationArgs&& args) |
| 252 | : impl::Display(compositionEngine, std::move(args)) {} |
| 253 | |
| 254 | // Sets up the helper functions called by chooseCompositionStrategy to |
| 255 | // use a mock implementations. |
| 256 | MOCK_CONST_METHOD0(anyLayersRequireClientComposition, bool()); |
| 257 | MOCK_CONST_METHOD0(allLayersRequireClientComposition, bool()); |
| 258 | MOCK_METHOD1(applyChangedTypesToLayers, void(const impl::Display::ChangedTypes&)); |
| 259 | MOCK_METHOD1(applyDisplayRequests, void(const impl::Display::DisplayRequests&)); |
| 260 | MOCK_METHOD1(applyLayerRequestsToLayers, void(const impl::Display::LayerRequests&)); |
| 261 | }; |
| 262 | |
| 263 | DisplayChooseCompositionStrategyTest() { |
| 264 | EXPECT_CALL(mCompositionEngine, getHwComposer()).WillRepeatedly(ReturnRef(mHwComposer)); |
| 265 | } |
| 266 | |
| 267 | StrictMock<android::mock::HWComposer> mHwComposer; |
| 268 | StrictMock<mock::CompositionEngine> mCompositionEngine; |
| 269 | StrictMock<DisplayPartialMock> |
| 270 | mDisplay{mCompositionEngine, |
| 271 | DisplayCreationArgsBuilder().setDisplayId(DEFAULT_DISPLAY_ID).build()}; |
| 272 | }; |
| 273 | |
| 274 | TEST_F(DisplayChooseCompositionStrategyTest, takesEarlyOutIfNotAHwcDisplay) { |
| 275 | impl::Display nonHwcDisplay{mCompositionEngine, DisplayCreationArgsBuilder().build()}; |
| 276 | EXPECT_FALSE(nonHwcDisplay.getId()); |
| 277 | |
| 278 | nonHwcDisplay.chooseCompositionStrategy(); |
| 279 | |
| 280 | auto& state = nonHwcDisplay.getState(); |
| 281 | EXPECT_TRUE(state.usesClientComposition); |
| 282 | EXPECT_FALSE(state.usesDeviceComposition); |
| 283 | } |
| 284 | |
| 285 | TEST_F(DisplayChooseCompositionStrategyTest, takesEarlyOutOnHwcError) { |
| 286 | EXPECT_CALL(mDisplay, anyLayersRequireClientComposition()).WillOnce(Return(false)); |
| 287 | EXPECT_CALL(mHwComposer, getDeviceCompositionChanges(DEFAULT_DISPLAY_ID, false, _)) |
| 288 | .WillOnce(Return(INVALID_OPERATION)); |
| 289 | |
| 290 | mDisplay.chooseCompositionStrategy(); |
| 291 | |
| 292 | auto& state = mDisplay.getState(); |
| 293 | EXPECT_TRUE(state.usesClientComposition); |
| 294 | EXPECT_FALSE(state.usesDeviceComposition); |
| 295 | } |
| 296 | |
| 297 | TEST_F(DisplayChooseCompositionStrategyTest, normalOperation) { |
| 298 | // Since two calls are made to anyLayersRequireClientComposition with different return values, |
| 299 | // use a Sequence to control the matching so the values are returned in a known order. |
| 300 | Sequence s; |
| 301 | EXPECT_CALL(mDisplay, anyLayersRequireClientComposition()).InSequence(s).WillOnce(Return(true)); |
| 302 | EXPECT_CALL(mDisplay, anyLayersRequireClientComposition()) |
| 303 | .InSequence(s) |
| 304 | .WillOnce(Return(false)); |
| 305 | |
| 306 | EXPECT_CALL(mHwComposer, getDeviceCompositionChanges(DEFAULT_DISPLAY_ID, true, _)) |
| 307 | .WillOnce(Return(NO_ERROR)); |
| 308 | EXPECT_CALL(mDisplay, allLayersRequireClientComposition()).WillOnce(Return(false)); |
| 309 | |
| 310 | mDisplay.chooseCompositionStrategy(); |
| 311 | |
| 312 | auto& state = mDisplay.getState(); |
| 313 | EXPECT_FALSE(state.usesClientComposition); |
| 314 | EXPECT_TRUE(state.usesDeviceComposition); |
| 315 | } |
| 316 | |
| 317 | TEST_F(DisplayChooseCompositionStrategyTest, normalOperationWithChanges) { |
| 318 | android::HWComposer::DeviceRequestedChanges changes{ |
| 319 | {{nullptr, HWC2::Composition::Client}}, |
| 320 | HWC2::DisplayRequest::FlipClientTarget, |
| 321 | {{nullptr, HWC2::LayerRequest::ClearClientTarget}}, |
| 322 | }; |
| 323 | |
| 324 | // Since two calls are made to anyLayersRequireClientComposition with different return values, |
| 325 | // use a Sequence to control the matching so the values are returned in a known order. |
| 326 | Sequence s; |
| 327 | EXPECT_CALL(mDisplay, anyLayersRequireClientComposition()).InSequence(s).WillOnce(Return(true)); |
| 328 | EXPECT_CALL(mDisplay, anyLayersRequireClientComposition()) |
| 329 | .InSequence(s) |
| 330 | .WillOnce(Return(false)); |
| 331 | |
| 332 | EXPECT_CALL(mHwComposer, getDeviceCompositionChanges(DEFAULT_DISPLAY_ID, true, _)) |
| 333 | .WillOnce(DoAll(SetArgPointee<2>(changes), Return(NO_ERROR))); |
| 334 | EXPECT_CALL(mDisplay, applyChangedTypesToLayers(changes.changedTypes)).Times(1); |
| 335 | EXPECT_CALL(mDisplay, applyDisplayRequests(changes.displayRequests)).Times(1); |
| 336 | EXPECT_CALL(mDisplay, applyLayerRequestsToLayers(changes.layerRequests)).Times(1); |
| 337 | EXPECT_CALL(mDisplay, allLayersRequireClientComposition()).WillOnce(Return(false)); |
| 338 | |
| 339 | mDisplay.chooseCompositionStrategy(); |
| 340 | |
| 341 | auto& state = mDisplay.getState(); |
| 342 | EXPECT_FALSE(state.usesClientComposition); |
| 343 | EXPECT_TRUE(state.usesDeviceComposition); |
| 344 | } |
| 345 | |
| 346 | /* |
| 347 | * Display::anyLayersRequireClientComposition() |
| 348 | */ |
| 349 | |
| 350 | TEST_F(DisplayTest, anyLayersRequireClientCompositionReturnsFalse) { |
| 351 | EXPECT_CALL(*mLayer1, requiresClientComposition()).WillOnce(Return(false)); |
| 352 | EXPECT_CALL(*mLayer2, requiresClientComposition()).WillOnce(Return(false)); |
| 353 | EXPECT_CALL(*mLayer3, requiresClientComposition()).WillOnce(Return(false)); |
| 354 | |
| 355 | EXPECT_FALSE(mDisplay.anyLayersRequireClientComposition()); |
| 356 | } |
| 357 | |
| 358 | TEST_F(DisplayTest, anyLayersRequireClientCompositionReturnsTrue) { |
| 359 | EXPECT_CALL(*mLayer1, requiresClientComposition()).WillOnce(Return(false)); |
| 360 | EXPECT_CALL(*mLayer2, requiresClientComposition()).WillOnce(Return(true)); |
| 361 | |
| 362 | EXPECT_TRUE(mDisplay.anyLayersRequireClientComposition()); |
| 363 | } |
| 364 | |
| 365 | /* |
| 366 | * Display::allLayersRequireClientComposition() |
| 367 | */ |
| 368 | |
| 369 | TEST_F(DisplayTest, allLayersRequireClientCompositionReturnsTrue) { |
| 370 | EXPECT_CALL(*mLayer1, requiresClientComposition()).WillOnce(Return(true)); |
| 371 | EXPECT_CALL(*mLayer2, requiresClientComposition()).WillOnce(Return(true)); |
| 372 | EXPECT_CALL(*mLayer3, requiresClientComposition()).WillOnce(Return(true)); |
| 373 | |
| 374 | EXPECT_TRUE(mDisplay.allLayersRequireClientComposition()); |
| 375 | } |
| 376 | |
| 377 | TEST_F(DisplayTest, allLayersRequireClientCompositionReturnsFalse) { |
| 378 | EXPECT_CALL(*mLayer1, requiresClientComposition()).WillOnce(Return(true)); |
| 379 | EXPECT_CALL(*mLayer2, requiresClientComposition()).WillOnce(Return(false)); |
| 380 | |
| 381 | EXPECT_FALSE(mDisplay.allLayersRequireClientComposition()); |
| 382 | } |
| 383 | |
| 384 | /* |
| 385 | * Display::applyChangedTypesToLayers() |
| 386 | */ |
| 387 | |
| 388 | TEST_F(DisplayTest, applyChangedTypesToLayersTakesEarlyOutIfNoChangedLayers) { |
| 389 | mDisplay.applyChangedTypesToLayers(impl::Display::ChangedTypes()); |
| 390 | } |
| 391 | |
| 392 | TEST_F(DisplayTest, applyChangedTypesToLayersAppliesChanges) { |
| 393 | EXPECT_CALL(*mLayer1, |
| 394 | applyDeviceCompositionTypeChange(Hwc2::IComposerClient::Composition::CLIENT)) |
| 395 | .Times(1); |
| 396 | EXPECT_CALL(*mLayer2, |
| 397 | applyDeviceCompositionTypeChange(Hwc2::IComposerClient::Composition::DEVICE)) |
| 398 | .Times(1); |
| 399 | |
| 400 | mDisplay.applyChangedTypesToLayers(impl::Display::ChangedTypes{ |
| 401 | {&mHWC2Layer1, HWC2::Composition::Client}, |
| 402 | {&mHWC2Layer2, HWC2::Composition::Device}, |
| 403 | {&mHWC2LayerUnknown, HWC2::Composition::SolidColor}, |
| 404 | }); |
| 405 | } |
| 406 | |
| 407 | /* |
| 408 | * Display::applyDisplayRequests() |
| 409 | */ |
| 410 | |
| 411 | TEST_F(DisplayTest, applyDisplayRequestsToLayersHandlesNoRequests) { |
| 412 | mDisplay.applyDisplayRequests(static_cast<HWC2::DisplayRequest>(0)); |
| 413 | |
| 414 | auto& state = mDisplay.getState(); |
| 415 | EXPECT_FALSE(state.flipClientTarget); |
| 416 | } |
| 417 | |
| 418 | TEST_F(DisplayTest, applyDisplayRequestsToLayersHandlesFlipClientTarget) { |
| 419 | mDisplay.applyDisplayRequests(HWC2::DisplayRequest::FlipClientTarget); |
| 420 | |
| 421 | auto& state = mDisplay.getState(); |
| 422 | EXPECT_TRUE(state.flipClientTarget); |
| 423 | } |
| 424 | |
| 425 | TEST_F(DisplayTest, applyDisplayRequestsToLayersHandlesWriteClientTargetToOutput) { |
| 426 | mDisplay.applyDisplayRequests(HWC2::DisplayRequest::WriteClientTargetToOutput); |
| 427 | |
| 428 | auto& state = mDisplay.getState(); |
| 429 | EXPECT_FALSE(state.flipClientTarget); |
| 430 | } |
| 431 | |
| 432 | TEST_F(DisplayTest, applyDisplayRequestsToLayersHandlesAllRequestFlagsSet) { |
| 433 | mDisplay.applyDisplayRequests(static_cast<HWC2::DisplayRequest>(~0)); |
| 434 | |
| 435 | auto& state = mDisplay.getState(); |
| 436 | EXPECT_TRUE(state.flipClientTarget); |
| 437 | } |
| 438 | |
| 439 | /* |
| 440 | * Display::applyLayerRequestsToLayers() |
| 441 | */ |
| 442 | |
| 443 | TEST_F(DisplayTest, applyLayerRequestsToLayersPreparesAllLayers) { |
| 444 | EXPECT_CALL(*mLayer1, prepareForDeviceLayerRequests()).Times(1); |
| 445 | EXPECT_CALL(*mLayer2, prepareForDeviceLayerRequests()).Times(1); |
| 446 | EXPECT_CALL(*mLayer3, prepareForDeviceLayerRequests()).Times(1); |
| 447 | |
| 448 | mDisplay.applyLayerRequestsToLayers(impl::Display::LayerRequests()); |
| 449 | } |
| 450 | |
| 451 | TEST_F(DisplayTest, applyLayerRequestsToLayers2) { |
| 452 | EXPECT_CALL(*mLayer1, prepareForDeviceLayerRequests()).Times(1); |
| 453 | EXPECT_CALL(*mLayer2, prepareForDeviceLayerRequests()).Times(1); |
| 454 | EXPECT_CALL(*mLayer3, prepareForDeviceLayerRequests()).Times(1); |
| 455 | |
| 456 | EXPECT_CALL(*mLayer1, |
| 457 | applyDeviceLayerRequest(Hwc2::IComposerClient::LayerRequest::CLEAR_CLIENT_TARGET)) |
| 458 | .Times(1); |
| 459 | |
| 460 | mDisplay.applyLayerRequestsToLayers(impl::Display::LayerRequests{ |
| 461 | {&mHWC2Layer1, HWC2::LayerRequest::ClearClientTarget}, |
| 462 | {&mHWC2LayerUnknown, HWC2::LayerRequest::ClearClientTarget}, |
| 463 | }); |
| 464 | } |
| 465 | |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 466 | } // namespace |
| 467 | } // namespace android::compositionengine |