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> |
Lloyd Pique | c660755 | 2019-12-02 17:57:39 -0800 | [diff] [blame] | 24 | #include <compositionengine/impl/RenderSurface.h> |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 25 | #include <compositionengine/mock/CompositionEngine.h> |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 26 | #include <compositionengine/mock/DisplayColorProfile.h> |
Lloyd Pique | c660755 | 2019-12-02 17:57:39 -0800 | [diff] [blame] | 27 | #include <compositionengine/mock/DisplaySurface.h> |
Lloyd Pique | df336d9 | 2019-03-07 21:38:42 -0800 | [diff] [blame] | 28 | #include <compositionengine/mock/LayerFE.h> |
chaviw | 8beb414 | 2019-04-11 13:09:05 -0700 | [diff] [blame] | 29 | #include <compositionengine/mock/NativeWindow.h> |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 30 | #include <compositionengine/mock/OutputLayer.h> |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 31 | #include <compositionengine/mock/RenderSurface.h> |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 32 | #include <gtest/gtest.h> |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 33 | #include <ui/DisplayInfo.h> |
| 34 | #include <ui/Rect.h> |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 35 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 36 | #include "MockHWC2.h" |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 37 | #include "MockHWComposer.h" |
Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 38 | #include "MockPowerAdvisor.h" |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 39 | |
| 40 | namespace android::compositionengine { |
| 41 | namespace { |
| 42 | |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 43 | using testing::_; |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 44 | using testing::DoAll; |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 45 | using testing::Eq; |
Lloyd Pique | c660755 | 2019-12-02 17:57:39 -0800 | [diff] [blame] | 46 | using testing::InSequence; |
| 47 | using testing::NiceMock; |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 48 | using testing::Pointee; |
| 49 | using testing::Ref; |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 50 | using testing::Return; |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 51 | using testing::ReturnRef; |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 52 | using testing::Sequence; |
| 53 | using testing::SetArgPointee; |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 54 | using testing::StrictMock; |
| 55 | |
| 56 | constexpr DisplayId DEFAULT_DISPLAY_ID = DisplayId{42}; |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 57 | constexpr DisplayId VIRTUAL_DISPLAY_ID = DisplayId{43}; |
Lloyd Pique | c660755 | 2019-12-02 17:57:39 -0800 | [diff] [blame] | 58 | constexpr int32_t DEFAULT_DISPLAY_WIDTH = 1920; |
| 59 | constexpr int32_t DEFAULT_DISPLAY_HEIGHT = 1080; |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 60 | constexpr int32_t DEFAULT_LAYER_STACK = 123; |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 61 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 62 | struct Layer { |
| 63 | Layer() { |
| 64 | EXPECT_CALL(*outputLayer, getLayerFE()).WillRepeatedly(ReturnRef(*layerFE)); |
| 65 | EXPECT_CALL(*outputLayer, getHwcLayer()).WillRepeatedly(Return(&hwc2Layer)); |
| 66 | } |
| 67 | |
| 68 | sp<mock::LayerFE> layerFE = new StrictMock<mock::LayerFE>(); |
| 69 | StrictMock<mock::OutputLayer>* outputLayer = new StrictMock<mock::OutputLayer>(); |
| 70 | StrictMock<HWC2::mock::Layer> hwc2Layer; |
| 71 | }; |
| 72 | |
| 73 | struct LayerNoHWC2Layer { |
| 74 | LayerNoHWC2Layer() { |
| 75 | EXPECT_CALL(*outputLayer, getLayerFE()).WillRepeatedly(ReturnRef(*layerFE)); |
| 76 | EXPECT_CALL(*outputLayer, getHwcLayer()).WillRepeatedly(Return(nullptr)); |
| 77 | } |
| 78 | |
| 79 | sp<mock::LayerFE> layerFE = new StrictMock<mock::LayerFE>(); |
| 80 | StrictMock<mock::OutputLayer>* outputLayer = new StrictMock<mock::OutputLayer>(); |
| 81 | }; |
| 82 | |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 83 | struct DisplayTestCommon : public testing::Test { |
| 84 | // Uses the full implementation of a display |
| 85 | class FullImplDisplay : public impl::Display { |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 86 | public: |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 87 | using impl::Display::injectOutputLayerForTest; |
| 88 | virtual void injectOutputLayerForTest(std::unique_ptr<compositionengine::OutputLayer>) = 0; |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 89 | |
| 90 | using impl::Display::maybeAllocateDisplayIdForVirtualDisplay; |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 91 | }; |
| 92 | |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 93 | // Uses a special implementation with key internal member functions set up |
| 94 | // as mock implementations, to allow for easier testing. |
| 95 | struct PartialMockDisplay : public impl::Display { |
| 96 | PartialMockDisplay(const compositionengine::CompositionEngine& compositionEngine) |
| 97 | : mCompositionEngine(compositionEngine) {} |
| 98 | |
| 99 | // compositionengine::Output overrides |
| 100 | const OutputCompositionState& getState() const override { return mState; } |
| 101 | OutputCompositionState& editState() override { return mState; } |
| 102 | |
| 103 | // compositionengine::impl::Output overrides |
| 104 | const CompositionEngine& getCompositionEngine() const override { |
| 105 | return mCompositionEngine; |
| 106 | }; |
| 107 | |
| 108 | // Mock implementation overrides |
| 109 | MOCK_CONST_METHOD0(getOutputLayerCount, size_t()); |
| 110 | MOCK_CONST_METHOD1(getOutputLayerOrderedByZByIndex, |
| 111 | compositionengine::OutputLayer*(size_t)); |
| 112 | MOCK_METHOD2(ensureOutputLayer, |
| 113 | compositionengine::OutputLayer*(std::optional<size_t>, const sp<LayerFE>&)); |
| 114 | MOCK_METHOD0(finalizePendingOutputLayers, void()); |
| 115 | MOCK_METHOD0(clearOutputLayers, void()); |
| 116 | MOCK_CONST_METHOD1(dumpState, void(std::string&)); |
| 117 | MOCK_METHOD1(injectOutputLayerForTest, compositionengine::OutputLayer*(const sp<LayerFE>&)); |
| 118 | MOCK_METHOD1(injectOutputLayerForTest, void(std::unique_ptr<OutputLayer>)); |
| 119 | MOCK_CONST_METHOD0(anyLayersRequireClientComposition, bool()); |
| 120 | MOCK_CONST_METHOD0(allLayersRequireClientComposition, bool()); |
| 121 | MOCK_METHOD1(applyChangedTypesToLayers, void(const impl::Display::ChangedTypes&)); |
| 122 | MOCK_METHOD1(applyDisplayRequests, void(const impl::Display::DisplayRequests&)); |
| 123 | MOCK_METHOD1(applyLayerRequestsToLayers, void(const impl::Display::LayerRequests&)); |
| 124 | |
| 125 | const compositionengine::CompositionEngine& mCompositionEngine; |
| 126 | impl::OutputCompositionState mState; |
| 127 | }; |
| 128 | |
| 129 | static std::string getDisplayNameFromCurrentTest() { |
| 130 | const ::testing::TestInfo* const test_info = |
| 131 | ::testing::UnitTest::GetInstance()->current_test_info(); |
| 132 | return std::string("display for ") + test_info->test_case_name() + "." + test_info->name(); |
| 133 | } |
| 134 | |
| 135 | template <typename Display> |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 136 | static std::shared_ptr<Display> createDisplay( |
| 137 | const compositionengine::CompositionEngine& compositionEngine, |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 138 | compositionengine::DisplayCreationArgs args) { |
| 139 | args.name = getDisplayNameFromCurrentTest(); |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 140 | return impl::createDisplayTemplated<Display>(compositionEngine, args); |
| 141 | } |
| 142 | |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 143 | template <typename Display> |
| 144 | static std::shared_ptr<StrictMock<Display>> createPartialMockDisplay( |
| 145 | const compositionengine::CompositionEngine& compositionEngine, |
| 146 | compositionengine::DisplayCreationArgs args) { |
| 147 | args.name = getDisplayNameFromCurrentTest(); |
| 148 | auto display = std::make_shared<StrictMock<Display>>(compositionEngine); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 149 | |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 150 | display->setConfiguration(args); |
| 151 | |
| 152 | return display; |
| 153 | } |
| 154 | |
| 155 | DisplayTestCommon() { |
| 156 | EXPECT_CALL(mCompositionEngine, getHwComposer()).WillRepeatedly(ReturnRef(mHwComposer)); |
| 157 | } |
| 158 | |
| 159 | DisplayCreationArgs getDisplayCreationArgsForPhysicalHWCDisplay() { |
| 160 | return DisplayCreationArgsBuilder() |
| 161 | .setPhysical({DEFAULT_DISPLAY_ID, DisplayConnectionType::Internal}) |
| 162 | .setPixels({DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT}) |
| 163 | .setPixelFormat(static_cast<ui::PixelFormat>(PIXEL_FORMAT_RGBA_8888)) |
| 164 | .setIsSecure(true) |
| 165 | .setLayerStackId(DEFAULT_LAYER_STACK) |
| 166 | .setPowerAdvisor(&mPowerAdvisor) |
| 167 | .build(); |
| 168 | } |
| 169 | |
| 170 | DisplayCreationArgs getDisplayCreationArgsForNonHWCVirtualDisplay() { |
| 171 | return DisplayCreationArgsBuilder() |
| 172 | .setUseHwcVirtualDisplays(false) |
| 173 | .setPixels({DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT}) |
| 174 | .setPixelFormat(static_cast<ui::PixelFormat>(PIXEL_FORMAT_RGBA_8888)) |
| 175 | .setIsSecure(false) |
| 176 | .setLayerStackId(DEFAULT_LAYER_STACK) |
| 177 | .setPowerAdvisor(&mPowerAdvisor) |
| 178 | .build(); |
| 179 | } |
| 180 | |
| 181 | StrictMock<android::mock::HWComposer> mHwComposer; |
| 182 | StrictMock<Hwc2::mock::PowerAdvisor> mPowerAdvisor; |
| 183 | StrictMock<mock::CompositionEngine> mCompositionEngine; |
| 184 | sp<mock::NativeWindow> mNativeWindow = new StrictMock<mock::NativeWindow>(); |
| 185 | }; |
| 186 | |
| 187 | struct PartialMockDisplayTestCommon : public DisplayTestCommon { |
| 188 | using Display = DisplayTestCommon::PartialMockDisplay; |
| 189 | std::shared_ptr<Display> mDisplay = |
| 190 | createPartialMockDisplay<Display>(mCompositionEngine, |
| 191 | getDisplayCreationArgsForPhysicalHWCDisplay()); |
| 192 | }; |
| 193 | |
| 194 | struct FullDisplayImplTestCommon : public DisplayTestCommon { |
| 195 | using Display = DisplayTestCommon::FullImplDisplay; |
| 196 | std::shared_ptr<Display> mDisplay = |
| 197 | createDisplay<Display>(mCompositionEngine, |
| 198 | getDisplayCreationArgsForPhysicalHWCDisplay()); |
| 199 | }; |
| 200 | |
| 201 | struct DisplayWithLayersTestCommon : public FullDisplayImplTestCommon { |
| 202 | DisplayWithLayersTestCommon() { |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 203 | mDisplay->injectOutputLayerForTest( |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 204 | std::unique_ptr<compositionengine::OutputLayer>(mLayer1.outputLayer)); |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 205 | mDisplay->injectOutputLayerForTest( |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 206 | std::unique_ptr<compositionengine::OutputLayer>(mLayer2.outputLayer)); |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 207 | mDisplay->injectOutputLayerForTest( |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 208 | std::unique_ptr<compositionengine::OutputLayer>(mLayer3.outputLayer)); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 209 | } |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 210 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 211 | Layer mLayer1; |
| 212 | Layer mLayer2; |
| 213 | LayerNoHWC2Layer mLayer3; |
| 214 | StrictMock<HWC2::mock::Layer> hwc2LayerUnknown; |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 215 | std::shared_ptr<Display> mDisplay = |
| 216 | createDisplay<Display>(mCompositionEngine, |
| 217 | getDisplayCreationArgsForPhysicalHWCDisplay()); |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 218 | }; |
| 219 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 220 | /* |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 221 | * Basic construction |
| 222 | */ |
| 223 | |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 224 | struct DisplayCreationTest : public DisplayTestCommon { |
| 225 | using Display = DisplayTestCommon::FullImplDisplay; |
| 226 | }; |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 227 | |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 228 | TEST_F(DisplayCreationTest, createPhysicalInternalDisplay) { |
| 229 | auto display = |
| 230 | impl::createDisplay(mCompositionEngine, getDisplayCreationArgsForPhysicalHWCDisplay()); |
| 231 | EXPECT_TRUE(display->isSecure()); |
| 232 | EXPECT_FALSE(display->isVirtual()); |
| 233 | EXPECT_EQ(DEFAULT_DISPLAY_ID, display->getId()); |
| 234 | } |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 235 | |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 236 | TEST_F(DisplayCreationTest, createNonHwcVirtualDisplay) { |
| 237 | auto display = impl::createDisplay(mCompositionEngine, |
| 238 | getDisplayCreationArgsForNonHWCVirtualDisplay()); |
| 239 | EXPECT_FALSE(display->isSecure()); |
| 240 | EXPECT_TRUE(display->isVirtual()); |
| 241 | EXPECT_EQ(std::nullopt, display->getId()); |
| 242 | } |
| 243 | |
| 244 | /* |
| 245 | * Display::setConfiguration() |
| 246 | */ |
| 247 | |
| 248 | using DisplaySetConfigurationTest = PartialMockDisplayTestCommon; |
| 249 | |
| 250 | TEST_F(DisplaySetConfigurationTest, configuresInternalSecurePhysicalDisplay) { |
| 251 | mDisplay->setConfiguration( |
| 252 | DisplayCreationArgsBuilder() |
| 253 | .setUseHwcVirtualDisplays(true) |
| 254 | .setPhysical({DEFAULT_DISPLAY_ID, DisplayConnectionType::Internal}) |
| 255 | .setPixels(ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_WIDTH)) |
| 256 | .setPixelFormat(static_cast<ui::PixelFormat>(PIXEL_FORMAT_RGBA_8888)) |
| 257 | .setIsSecure(true) |
| 258 | .setLayerStackId(DEFAULT_LAYER_STACK) |
| 259 | .setPowerAdvisor(&mPowerAdvisor) |
| 260 | .setName(getDisplayNameFromCurrentTest()) |
| 261 | .build()); |
| 262 | |
| 263 | EXPECT_EQ(DEFAULT_DISPLAY_ID, mDisplay->getId()); |
| 264 | EXPECT_TRUE(mDisplay->isSecure()); |
| 265 | EXPECT_FALSE(mDisplay->isVirtual()); |
| 266 | EXPECT_EQ(DEFAULT_LAYER_STACK, mDisplay->getState().layerStackId); |
| 267 | EXPECT_TRUE(mDisplay->getState().layerStackInternal); |
| 268 | EXPECT_FALSE(mDisplay->isValid()); |
| 269 | } |
| 270 | |
| 271 | TEST_F(DisplaySetConfigurationTest, configuresExternalInsecurePhysicalDisplay) { |
| 272 | mDisplay->setConfiguration( |
| 273 | DisplayCreationArgsBuilder() |
| 274 | .setUseHwcVirtualDisplays(true) |
| 275 | .setPhysical({DEFAULT_DISPLAY_ID, DisplayConnectionType::External}) |
| 276 | .setPixels(ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_WIDTH)) |
| 277 | .setPixelFormat(static_cast<ui::PixelFormat>(PIXEL_FORMAT_RGBA_8888)) |
| 278 | .setIsSecure(false) |
| 279 | .setLayerStackId(DEFAULT_LAYER_STACK) |
| 280 | .setPowerAdvisor(&mPowerAdvisor) |
| 281 | .setName(getDisplayNameFromCurrentTest()) |
| 282 | .build()); |
| 283 | |
| 284 | EXPECT_EQ(DEFAULT_DISPLAY_ID, mDisplay->getId()); |
| 285 | EXPECT_FALSE(mDisplay->isSecure()); |
| 286 | EXPECT_FALSE(mDisplay->isVirtual()); |
| 287 | EXPECT_EQ(DEFAULT_LAYER_STACK, mDisplay->getState().layerStackId); |
| 288 | EXPECT_FALSE(mDisplay->getState().layerStackInternal); |
| 289 | EXPECT_FALSE(mDisplay->isValid()); |
| 290 | } |
| 291 | |
| 292 | TEST_F(DisplaySetConfigurationTest, configuresHwcBackedVirtualDisplay) { |
| 293 | EXPECT_CALL(mHwComposer, |
| 294 | allocateVirtualDisplay(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_WIDTH, |
| 295 | Pointee(Eq(static_cast<ui::PixelFormat>( |
| 296 | PIXEL_FORMAT_RGBA_8888))))) |
| 297 | .WillOnce(Return(VIRTUAL_DISPLAY_ID)); |
| 298 | |
| 299 | mDisplay->setConfiguration( |
| 300 | DisplayCreationArgsBuilder() |
| 301 | .setUseHwcVirtualDisplays(true) |
| 302 | .setPixels(ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_WIDTH)) |
| 303 | .setPixelFormat(static_cast<ui::PixelFormat>(PIXEL_FORMAT_RGBA_8888)) |
| 304 | .setIsSecure(false) |
| 305 | .setLayerStackId(DEFAULT_LAYER_STACK) |
| 306 | .setPowerAdvisor(&mPowerAdvisor) |
| 307 | .setName(getDisplayNameFromCurrentTest()) |
| 308 | .build()); |
| 309 | |
| 310 | EXPECT_EQ(VIRTUAL_DISPLAY_ID, mDisplay->getId()); |
| 311 | EXPECT_FALSE(mDisplay->isSecure()); |
| 312 | EXPECT_TRUE(mDisplay->isVirtual()); |
| 313 | EXPECT_EQ(DEFAULT_LAYER_STACK, mDisplay->getState().layerStackId); |
| 314 | EXPECT_FALSE(mDisplay->getState().layerStackInternal); |
| 315 | EXPECT_FALSE(mDisplay->isValid()); |
| 316 | } |
| 317 | |
| 318 | TEST_F(DisplaySetConfigurationTest, configuresNonHwcBackedVirtualDisplayIfHwcAllocationFails) { |
| 319 | EXPECT_CALL(mHwComposer, |
| 320 | allocateVirtualDisplay(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_WIDTH, |
| 321 | Pointee(Eq(static_cast<ui::PixelFormat>( |
| 322 | PIXEL_FORMAT_RGBA_8888))))) |
| 323 | .WillOnce(Return(std::nullopt)); |
| 324 | |
| 325 | mDisplay->setConfiguration( |
| 326 | DisplayCreationArgsBuilder() |
| 327 | .setUseHwcVirtualDisplays(true) |
| 328 | .setPixels(ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_WIDTH)) |
| 329 | .setPixelFormat(static_cast<ui::PixelFormat>(PIXEL_FORMAT_RGBA_8888)) |
| 330 | .setIsSecure(false) |
| 331 | .setLayerStackId(DEFAULT_LAYER_STACK) |
| 332 | .setPowerAdvisor(&mPowerAdvisor) |
| 333 | .setName(getDisplayNameFromCurrentTest()) |
| 334 | .build()); |
| 335 | |
| 336 | EXPECT_EQ(std::nullopt, mDisplay->getId()); |
| 337 | EXPECT_FALSE(mDisplay->isSecure()); |
| 338 | EXPECT_TRUE(mDisplay->isVirtual()); |
| 339 | EXPECT_EQ(DEFAULT_LAYER_STACK, mDisplay->getState().layerStackId); |
| 340 | EXPECT_FALSE(mDisplay->getState().layerStackInternal); |
| 341 | EXPECT_FALSE(mDisplay->isValid()); |
| 342 | } |
| 343 | |
| 344 | TEST_F(DisplaySetConfigurationTest, configuresNonHwcBackedVirtualDisplayIfShouldNotUseHwc) { |
| 345 | mDisplay->setConfiguration( |
| 346 | DisplayCreationArgsBuilder() |
| 347 | .setUseHwcVirtualDisplays(false) |
| 348 | .setPixels(ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_WIDTH)) |
| 349 | .setPixelFormat(static_cast<ui::PixelFormat>(PIXEL_FORMAT_RGBA_8888)) |
| 350 | .setIsSecure(false) |
| 351 | .setLayerStackId(DEFAULT_LAYER_STACK) |
| 352 | .setPowerAdvisor(&mPowerAdvisor) |
| 353 | .setName(getDisplayNameFromCurrentTest()) |
| 354 | .build()); |
| 355 | |
| 356 | EXPECT_EQ(std::nullopt, mDisplay->getId()); |
| 357 | EXPECT_FALSE(mDisplay->isSecure()); |
| 358 | EXPECT_TRUE(mDisplay->isVirtual()); |
| 359 | EXPECT_EQ(DEFAULT_LAYER_STACK, mDisplay->getState().layerStackId); |
| 360 | EXPECT_FALSE(mDisplay->getState().layerStackInternal); |
| 361 | EXPECT_FALSE(mDisplay->isValid()); |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 362 | } |
| 363 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 364 | /* |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 365 | * Display::disconnect() |
| 366 | */ |
| 367 | |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 368 | using DisplayDisconnectTest = PartialMockDisplayTestCommon; |
| 369 | |
| 370 | TEST_F(DisplayDisconnectTest, disconnectsDisplay) { |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 371 | // The first call to disconnect will disconnect the display with the HWC and |
| 372 | // set mHwcId to -1. |
| 373 | EXPECT_CALL(mHwComposer, disconnectDisplay(DEFAULT_DISPLAY_ID)).Times(1); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 374 | mDisplay->disconnect(); |
| 375 | EXPECT_FALSE(mDisplay->getId()); |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 376 | |
| 377 | // Subsequent calls will do nothing, |
| 378 | EXPECT_CALL(mHwComposer, disconnectDisplay(DEFAULT_DISPLAY_ID)).Times(0); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 379 | mDisplay->disconnect(); |
| 380 | EXPECT_FALSE(mDisplay->getId()); |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 381 | } |
| 382 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 383 | /* |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 384 | * Display::setColorTransform() |
| 385 | */ |
| 386 | |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 387 | using DisplaySetColorTransformTest = PartialMockDisplayTestCommon; |
| 388 | |
| 389 | TEST_F(DisplaySetColorTransformTest, setsTransform) { |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 390 | // No change does nothing |
| 391 | CompositionRefreshArgs refreshArgs; |
| 392 | refreshArgs.colorTransformMatrix = std::nullopt; |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 393 | mDisplay->setColorTransform(refreshArgs); |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 394 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 395 | // Identity matrix sets an identity state value |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 396 | const mat4 kIdentity; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 397 | |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 398 | EXPECT_CALL(mHwComposer, setColorTransform(DEFAULT_DISPLAY_ID, kIdentity)).Times(1); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 399 | |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 400 | refreshArgs.colorTransformMatrix = kIdentity; |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 401 | mDisplay->setColorTransform(refreshArgs); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 402 | |
| 403 | // Non-identity matrix sets a non-identity state value |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 404 | const mat4 kNonIdentity = mat4() * 2; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 405 | |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 406 | EXPECT_CALL(mHwComposer, setColorTransform(DEFAULT_DISPLAY_ID, kNonIdentity)).Times(1); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 407 | |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 408 | refreshArgs.colorTransformMatrix = kNonIdentity; |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 409 | mDisplay->setColorTransform(refreshArgs); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 410 | } |
| 411 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 412 | /* |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 413 | * Display::setColorMode() |
| 414 | */ |
| 415 | |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 416 | using DisplaySetColorModeTest = PartialMockDisplayTestCommon; |
| 417 | |
| 418 | TEST_F(DisplaySetColorModeTest, setsModeUnlessNoChange) { |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 419 | using ColorProfile = Output::ColorProfile; |
| 420 | |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 421 | mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>(); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 422 | mDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface)); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 423 | mock::DisplayColorProfile* colorProfile = new StrictMock<mock::DisplayColorProfile>(); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 424 | mDisplay->setDisplayColorProfileForTest(std::unique_ptr<DisplayColorProfile>(colorProfile)); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 425 | |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 426 | EXPECT_CALL(*colorProfile, getTargetDataspace(_, _, _)) |
| 427 | .WillRepeatedly(Return(ui::Dataspace::UNKNOWN)); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 428 | |
| 429 | // These values are expected to be the initial state. |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 430 | ASSERT_EQ(ui::ColorMode::NATIVE, mDisplay->getState().colorMode); |
| 431 | ASSERT_EQ(ui::Dataspace::UNKNOWN, mDisplay->getState().dataspace); |
| 432 | ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mDisplay->getState().renderIntent); |
| 433 | ASSERT_EQ(ui::Dataspace::UNKNOWN, mDisplay->getState().targetDataspace); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 434 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 435 | // Otherwise if the values are unchanged, nothing happens |
| 436 | mDisplay->setColorProfile(ColorProfile{ui::ColorMode::NATIVE, ui::Dataspace::UNKNOWN, |
| 437 | ui::RenderIntent::COLORIMETRIC, ui::Dataspace::UNKNOWN}); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 438 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 439 | EXPECT_EQ(ui::ColorMode::NATIVE, mDisplay->getState().colorMode); |
| 440 | EXPECT_EQ(ui::Dataspace::UNKNOWN, mDisplay->getState().dataspace); |
| 441 | EXPECT_EQ(ui::RenderIntent::COLORIMETRIC, mDisplay->getState().renderIntent); |
| 442 | EXPECT_EQ(ui::Dataspace::UNKNOWN, mDisplay->getState().targetDataspace); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 443 | |
| 444 | // Otherwise if the values are different, updates happen |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 445 | EXPECT_CALL(*renderSurface, setBufferDataspace(ui::Dataspace::DISPLAY_P3)).Times(1); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 446 | EXPECT_CALL(mHwComposer, |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 447 | setActiveColorMode(DEFAULT_DISPLAY_ID, ui::ColorMode::DISPLAY_P3, |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 448 | ui::RenderIntent::TONE_MAP_COLORIMETRIC)) |
| 449 | .Times(1); |
| 450 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 451 | mDisplay->setColorProfile(ColorProfile{ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3, |
| 452 | ui::RenderIntent::TONE_MAP_COLORIMETRIC, |
| 453 | ui::Dataspace::UNKNOWN}); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 454 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 455 | EXPECT_EQ(ui::ColorMode::DISPLAY_P3, mDisplay->getState().colorMode); |
| 456 | EXPECT_EQ(ui::Dataspace::DISPLAY_P3, mDisplay->getState().dataspace); |
| 457 | EXPECT_EQ(ui::RenderIntent::TONE_MAP_COLORIMETRIC, mDisplay->getState().renderIntent); |
| 458 | EXPECT_EQ(ui::Dataspace::UNKNOWN, mDisplay->getState().targetDataspace); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 459 | } |
| 460 | |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 461 | TEST_F(DisplaySetColorModeTest, doesNothingForVirtualDisplay) { |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 462 | using ColorProfile = Output::ColorProfile; |
| 463 | |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 464 | auto args = getDisplayCreationArgsForNonHWCVirtualDisplay(); |
| 465 | std::shared_ptr<impl::Display> virtualDisplay = impl::createDisplay(mCompositionEngine, args); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 466 | |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 467 | mock::DisplayColorProfile* colorProfile = new StrictMock<mock::DisplayColorProfile>(); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 468 | virtualDisplay->setDisplayColorProfileForTest( |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 469 | std::unique_ptr<DisplayColorProfile>(colorProfile)); |
| 470 | |
| 471 | EXPECT_CALL(*colorProfile, |
| 472 | getTargetDataspace(ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3, |
| 473 | ui::Dataspace::UNKNOWN)) |
| 474 | .WillOnce(Return(ui::Dataspace::UNKNOWN)); |
| 475 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 476 | virtualDisplay->setColorProfile( |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 477 | ColorProfile{ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3, |
| 478 | ui::RenderIntent::TONE_MAP_COLORIMETRIC, ui::Dataspace::UNKNOWN}); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 479 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 480 | EXPECT_EQ(ui::ColorMode::NATIVE, virtualDisplay->getState().colorMode); |
| 481 | EXPECT_EQ(ui::Dataspace::UNKNOWN, virtualDisplay->getState().dataspace); |
| 482 | EXPECT_EQ(ui::RenderIntent::COLORIMETRIC, virtualDisplay->getState().renderIntent); |
| 483 | EXPECT_EQ(ui::Dataspace::UNKNOWN, virtualDisplay->getState().targetDataspace); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 484 | } |
| 485 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 486 | /* |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 487 | * Display::createDisplayColorProfile() |
| 488 | */ |
| 489 | |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 490 | using DisplayCreateColorProfileTest = PartialMockDisplayTestCommon; |
| 491 | |
| 492 | TEST_F(DisplayCreateColorProfileTest, setsDisplayColorProfile) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 493 | EXPECT_TRUE(mDisplay->getDisplayColorProfile() == nullptr); |
| 494 | mDisplay->createDisplayColorProfile( |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 495 | DisplayColorProfileCreationArgs{false, HdrCapabilities(), 0, |
| 496 | DisplayColorProfileCreationArgs::HwcColorModes()}); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 497 | EXPECT_TRUE(mDisplay->getDisplayColorProfile() != nullptr); |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 498 | } |
| 499 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 500 | /* |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 501 | * Display::createRenderSurface() |
| 502 | */ |
| 503 | |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 504 | using DisplayCreateRenderSurfaceTest = PartialMockDisplayTestCommon; |
| 505 | |
| 506 | TEST_F(DisplayCreateRenderSurfaceTest, setsRenderSurface) { |
chaviw | 8beb414 | 2019-04-11 13:09:05 -0700 | [diff] [blame] | 507 | EXPECT_CALL(*mNativeWindow, disconnect(NATIVE_WINDOW_API_EGL)).WillRepeatedly(Return(NO_ERROR)); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 508 | EXPECT_TRUE(mDisplay->getRenderSurface() == nullptr); |
| 509 | mDisplay->createRenderSurface(RenderSurfaceCreationArgs{640, 480, mNativeWindow, nullptr}); |
| 510 | EXPECT_TRUE(mDisplay->getRenderSurface() != nullptr); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 511 | } |
| 512 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 513 | /* |
Lloyd Pique | df336d9 | 2019-03-07 21:38:42 -0800 | [diff] [blame] | 514 | * Display::createOutputLayer() |
| 515 | */ |
| 516 | |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 517 | using DisplayCreateOutputLayerTest = FullDisplayImplTestCommon; |
| 518 | |
| 519 | TEST_F(DisplayCreateOutputLayerTest, setsHwcLayer) { |
Lloyd Pique | df336d9 | 2019-03-07 21:38:42 -0800 | [diff] [blame] | 520 | sp<mock::LayerFE> layerFE = new StrictMock<mock::LayerFE>(); |
Lloyd Pique | df336d9 | 2019-03-07 21:38:42 -0800 | [diff] [blame] | 521 | StrictMock<HWC2::mock::Layer> hwcLayer; |
| 522 | |
| 523 | EXPECT_CALL(mHwComposer, createLayer(DEFAULT_DISPLAY_ID)).WillOnce(Return(&hwcLayer)); |
| 524 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 525 | auto outputLayer = mDisplay->createOutputLayer(layerFE); |
Lloyd Pique | df336d9 | 2019-03-07 21:38:42 -0800 | [diff] [blame] | 526 | |
| 527 | EXPECT_EQ(&hwcLayer, outputLayer->getHwcLayer()); |
| 528 | |
| 529 | EXPECT_CALL(mHwComposer, destroyLayer(DEFAULT_DISPLAY_ID, &hwcLayer)); |
| 530 | outputLayer.reset(); |
| 531 | } |
| 532 | |
| 533 | /* |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 534 | * Display::setReleasedLayers() |
| 535 | */ |
| 536 | |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 537 | using DisplaySetReleasedLayersTest = DisplayWithLayersTestCommon; |
| 538 | |
| 539 | TEST_F(DisplaySetReleasedLayersTest, doesNothingIfNotHwcDisplay) { |
| 540 | auto args = getDisplayCreationArgsForNonHWCVirtualDisplay(); |
| 541 | std::shared_ptr<impl::Display> nonHwcDisplay = impl::createDisplay(mCompositionEngine, args); |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 542 | |
| 543 | sp<mock::LayerFE> layerXLayerFE = new StrictMock<mock::LayerFE>(); |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 544 | |
| 545 | { |
| 546 | Output::ReleasedLayers releasedLayers; |
| 547 | releasedLayers.emplace_back(layerXLayerFE); |
| 548 | nonHwcDisplay->setReleasedLayers(std::move(releasedLayers)); |
| 549 | } |
| 550 | |
| 551 | CompositionRefreshArgs refreshArgs; |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 552 | refreshArgs.layersWithQueuedFrames.push_back(layerXLayerFE); |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 553 | |
| 554 | nonHwcDisplay->setReleasedLayers(refreshArgs); |
| 555 | |
| 556 | const auto& releasedLayers = nonHwcDisplay->getReleasedLayersForTest(); |
| 557 | ASSERT_EQ(1, releasedLayers.size()); |
| 558 | } |
| 559 | |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 560 | TEST_F(DisplaySetReleasedLayersTest, doesNothingIfNoLayersWithQueuedFrames) { |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 561 | sp<mock::LayerFE> layerXLayerFE = new StrictMock<mock::LayerFE>(); |
| 562 | |
| 563 | { |
| 564 | Output::ReleasedLayers releasedLayers; |
| 565 | releasedLayers.emplace_back(layerXLayerFE); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 566 | mDisplay->setReleasedLayers(std::move(releasedLayers)); |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 567 | } |
| 568 | |
| 569 | CompositionRefreshArgs refreshArgs; |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 570 | mDisplay->setReleasedLayers(refreshArgs); |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 571 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 572 | const auto& releasedLayers = mDisplay->getReleasedLayersForTest(); |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 573 | ASSERT_EQ(1, releasedLayers.size()); |
| 574 | } |
| 575 | |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 576 | TEST_F(DisplaySetReleasedLayersTest, setReleasedLayers) { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 577 | sp<mock::LayerFE> unknownLayer = new StrictMock<mock::LayerFE>(); |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 578 | |
| 579 | CompositionRefreshArgs refreshArgs; |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 580 | refreshArgs.layersWithQueuedFrames.push_back(mLayer1.layerFE); |
| 581 | refreshArgs.layersWithQueuedFrames.push_back(mLayer2.layerFE); |
| 582 | refreshArgs.layersWithQueuedFrames.push_back(unknownLayer); |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 583 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 584 | mDisplay->setReleasedLayers(refreshArgs); |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 585 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 586 | const auto& releasedLayers = mDisplay->getReleasedLayersForTest(); |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 587 | ASSERT_EQ(2, releasedLayers.size()); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 588 | ASSERT_EQ(mLayer1.layerFE.get(), releasedLayers[0].promote().get()); |
| 589 | ASSERT_EQ(mLayer2.layerFE.get(), releasedLayers[1].promote().get()); |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 590 | } |
| 591 | |
| 592 | /* |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 593 | * Display::chooseCompositionStrategy() |
| 594 | */ |
| 595 | |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 596 | using DisplayChooseCompositionStrategyTest = PartialMockDisplayTestCommon; |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 597 | |
| 598 | TEST_F(DisplayChooseCompositionStrategyTest, takesEarlyOutIfNotAHwcDisplay) { |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 599 | auto args = getDisplayCreationArgsForNonHWCVirtualDisplay(); |
| 600 | std::shared_ptr<Display> nonHwcDisplay = |
| 601 | createPartialMockDisplay<Display>(mCompositionEngine, args); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 602 | EXPECT_FALSE(nonHwcDisplay->getId()); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 603 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 604 | nonHwcDisplay->chooseCompositionStrategy(); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 605 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 606 | auto& state = nonHwcDisplay->getState(); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 607 | EXPECT_TRUE(state.usesClientComposition); |
| 608 | EXPECT_FALSE(state.usesDeviceComposition); |
| 609 | } |
| 610 | |
| 611 | TEST_F(DisplayChooseCompositionStrategyTest, takesEarlyOutOnHwcError) { |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 612 | EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition()).WillOnce(Return(false)); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 613 | EXPECT_CALL(mHwComposer, getDeviceCompositionChanges(DEFAULT_DISPLAY_ID, false, _)) |
| 614 | .WillOnce(Return(INVALID_OPERATION)); |
| 615 | |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 616 | mDisplay->chooseCompositionStrategy(); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 617 | |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 618 | auto& state = mDisplay->getState(); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 619 | EXPECT_TRUE(state.usesClientComposition); |
| 620 | EXPECT_FALSE(state.usesDeviceComposition); |
| 621 | } |
| 622 | |
| 623 | TEST_F(DisplayChooseCompositionStrategyTest, normalOperation) { |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 624 | // Since two calls are made to anyLayersRequireClientComposition with different return |
| 625 | // values, use a Sequence to control the matching so the values are returned in a known |
| 626 | // order. |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 627 | Sequence s; |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 628 | EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition()) |
| 629 | .InSequence(s) |
| 630 | .WillOnce(Return(true)); |
| 631 | EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition()) |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 632 | .InSequence(s) |
| 633 | .WillOnce(Return(false)); |
| 634 | |
| 635 | EXPECT_CALL(mHwComposer, getDeviceCompositionChanges(DEFAULT_DISPLAY_ID, true, _)) |
| 636 | .WillOnce(Return(NO_ERROR)); |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 637 | EXPECT_CALL(*mDisplay, allLayersRequireClientComposition()).WillOnce(Return(false)); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 638 | |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 639 | mDisplay->chooseCompositionStrategy(); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 640 | |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 641 | auto& state = mDisplay->getState(); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 642 | EXPECT_FALSE(state.usesClientComposition); |
| 643 | EXPECT_TRUE(state.usesDeviceComposition); |
| 644 | } |
| 645 | |
| 646 | TEST_F(DisplayChooseCompositionStrategyTest, normalOperationWithChanges) { |
| 647 | android::HWComposer::DeviceRequestedChanges changes{ |
| 648 | {{nullptr, HWC2::Composition::Client}}, |
| 649 | HWC2::DisplayRequest::FlipClientTarget, |
| 650 | {{nullptr, HWC2::LayerRequest::ClearClientTarget}}, |
| 651 | }; |
| 652 | |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 653 | // Since two calls are made to anyLayersRequireClientComposition with different return |
| 654 | // values, use a Sequence to control the matching so the values are returned in a known |
| 655 | // order. |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 656 | Sequence s; |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 657 | EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition()) |
| 658 | .InSequence(s) |
| 659 | .WillOnce(Return(true)); |
| 660 | EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition()) |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 661 | .InSequence(s) |
| 662 | .WillOnce(Return(false)); |
| 663 | |
| 664 | EXPECT_CALL(mHwComposer, getDeviceCompositionChanges(DEFAULT_DISPLAY_ID, true, _)) |
| 665 | .WillOnce(DoAll(SetArgPointee<2>(changes), Return(NO_ERROR))); |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 666 | EXPECT_CALL(*mDisplay, applyChangedTypesToLayers(changes.changedTypes)).Times(1); |
| 667 | EXPECT_CALL(*mDisplay, applyDisplayRequests(changes.displayRequests)).Times(1); |
| 668 | EXPECT_CALL(*mDisplay, applyLayerRequestsToLayers(changes.layerRequests)).Times(1); |
| 669 | EXPECT_CALL(*mDisplay, allLayersRequireClientComposition()).WillOnce(Return(false)); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 670 | |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 671 | mDisplay->chooseCompositionStrategy(); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 672 | |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 673 | auto& state = mDisplay->getState(); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 674 | EXPECT_FALSE(state.usesClientComposition); |
| 675 | EXPECT_TRUE(state.usesDeviceComposition); |
| 676 | } |
| 677 | |
| 678 | /* |
Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 679 | * Display::getSkipColorTransform() |
| 680 | */ |
| 681 | |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 682 | using DisplayGetSkipColorTransformTest = DisplayWithLayersTestCommon; |
| 683 | |
Dominik Laskowski | 1162e47 | 2020-04-02 19:02:47 -0700 | [diff] [blame^] | 684 | TEST_F(DisplayGetSkipColorTransformTest, checksCapabilityIfNonHwcDisplay) { |
| 685 | EXPECT_CALL(mHwComposer, hasCapability(HWC2::Capability::SkipClientColorTransform)) |
| 686 | .WillOnce(Return(true)); |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 687 | auto args = getDisplayCreationArgsForNonHWCVirtualDisplay(); |
| 688 | auto nonHwcDisplay{impl::createDisplay(mCompositionEngine, args)}; |
Dominik Laskowski | 1162e47 | 2020-04-02 19:02:47 -0700 | [diff] [blame^] | 689 | EXPECT_TRUE(nonHwcDisplay->getSkipColorTransform()); |
Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 690 | } |
| 691 | |
Dominik Laskowski | 1162e47 | 2020-04-02 19:02:47 -0700 | [diff] [blame^] | 692 | TEST_F(DisplayGetSkipColorTransformTest, checksDisplayCapability) { |
Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 693 | EXPECT_CALL(mHwComposer, |
Dominik Laskowski | 1162e47 | 2020-04-02 19:02:47 -0700 | [diff] [blame^] | 694 | hasDisplayCapability(DEFAULT_DISPLAY_ID, |
Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 695 | HWC2::DisplayCapability::SkipClientColorTransform)) |
| 696 | .WillOnce(Return(true)); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 697 | EXPECT_TRUE(mDisplay->getSkipColorTransform()); |
Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 698 | } |
| 699 | |
| 700 | /* |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 701 | * Display::anyLayersRequireClientComposition() |
| 702 | */ |
| 703 | |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 704 | using DisplayAnyLayersRequireClientCompositionTest = DisplayWithLayersTestCommon; |
| 705 | |
| 706 | TEST_F(DisplayAnyLayersRequireClientCompositionTest, returnsFalse) { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 707 | EXPECT_CALL(*mLayer1.outputLayer, requiresClientComposition()).WillOnce(Return(false)); |
| 708 | EXPECT_CALL(*mLayer2.outputLayer, requiresClientComposition()).WillOnce(Return(false)); |
| 709 | EXPECT_CALL(*mLayer3.outputLayer, requiresClientComposition()).WillOnce(Return(false)); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 710 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 711 | EXPECT_FALSE(mDisplay->anyLayersRequireClientComposition()); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 712 | } |
| 713 | |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 714 | TEST_F(DisplayAnyLayersRequireClientCompositionTest, returnsTrue) { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 715 | EXPECT_CALL(*mLayer1.outputLayer, requiresClientComposition()).WillOnce(Return(false)); |
| 716 | EXPECT_CALL(*mLayer2.outputLayer, requiresClientComposition()).WillOnce(Return(true)); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 717 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 718 | EXPECT_TRUE(mDisplay->anyLayersRequireClientComposition()); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 719 | } |
| 720 | |
| 721 | /* |
| 722 | * Display::allLayersRequireClientComposition() |
| 723 | */ |
| 724 | |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 725 | using DisplayAllLayersRequireClientCompositionTest = DisplayWithLayersTestCommon; |
| 726 | |
| 727 | TEST_F(DisplayAllLayersRequireClientCompositionTest, returnsTrue) { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 728 | EXPECT_CALL(*mLayer1.outputLayer, requiresClientComposition()).WillOnce(Return(true)); |
| 729 | EXPECT_CALL(*mLayer2.outputLayer, requiresClientComposition()).WillOnce(Return(true)); |
| 730 | EXPECT_CALL(*mLayer3.outputLayer, requiresClientComposition()).WillOnce(Return(true)); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 731 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 732 | EXPECT_TRUE(mDisplay->allLayersRequireClientComposition()); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 733 | } |
| 734 | |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 735 | TEST_F(DisplayAllLayersRequireClientCompositionTest, returnsFalse) { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 736 | EXPECT_CALL(*mLayer1.outputLayer, requiresClientComposition()).WillOnce(Return(true)); |
| 737 | EXPECT_CALL(*mLayer2.outputLayer, requiresClientComposition()).WillOnce(Return(false)); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 738 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 739 | EXPECT_FALSE(mDisplay->allLayersRequireClientComposition()); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 740 | } |
| 741 | |
| 742 | /* |
| 743 | * Display::applyChangedTypesToLayers() |
| 744 | */ |
| 745 | |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 746 | using DisplayApplyChangedTypesToLayersTest = DisplayWithLayersTestCommon; |
| 747 | |
| 748 | TEST_F(DisplayApplyChangedTypesToLayersTest, takesEarlyOutIfNoChangedLayers) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 749 | mDisplay->applyChangedTypesToLayers(impl::Display::ChangedTypes()); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 750 | } |
| 751 | |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 752 | TEST_F(DisplayApplyChangedTypesToLayersTest, appliesChanges) { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 753 | EXPECT_CALL(*mLayer1.outputLayer, |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 754 | applyDeviceCompositionTypeChange(Hwc2::IComposerClient::Composition::CLIENT)) |
| 755 | .Times(1); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 756 | EXPECT_CALL(*mLayer2.outputLayer, |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 757 | applyDeviceCompositionTypeChange(Hwc2::IComposerClient::Composition::DEVICE)) |
| 758 | .Times(1); |
| 759 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 760 | mDisplay->applyChangedTypesToLayers(impl::Display::ChangedTypes{ |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 761 | {&mLayer1.hwc2Layer, HWC2::Composition::Client}, |
| 762 | {&mLayer2.hwc2Layer, HWC2::Composition::Device}, |
| 763 | {&hwc2LayerUnknown, HWC2::Composition::SolidColor}, |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 764 | }); |
| 765 | } |
| 766 | |
| 767 | /* |
| 768 | * Display::applyDisplayRequests() |
| 769 | */ |
| 770 | |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 771 | using DisplayApplyDisplayRequestsTest = DisplayWithLayersTestCommon; |
| 772 | |
| 773 | TEST_F(DisplayApplyDisplayRequestsTest, handlesNoRequests) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 774 | mDisplay->applyDisplayRequests(static_cast<HWC2::DisplayRequest>(0)); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 775 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 776 | auto& state = mDisplay->getState(); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 777 | EXPECT_FALSE(state.flipClientTarget); |
| 778 | } |
| 779 | |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 780 | TEST_F(DisplayApplyDisplayRequestsTest, handlesFlipClientTarget) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 781 | mDisplay->applyDisplayRequests(HWC2::DisplayRequest::FlipClientTarget); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 782 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 783 | auto& state = mDisplay->getState(); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 784 | EXPECT_TRUE(state.flipClientTarget); |
| 785 | } |
| 786 | |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 787 | TEST_F(DisplayApplyDisplayRequestsTest, handlesWriteClientTargetToOutput) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 788 | mDisplay->applyDisplayRequests(HWC2::DisplayRequest::WriteClientTargetToOutput); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 789 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 790 | auto& state = mDisplay->getState(); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 791 | EXPECT_FALSE(state.flipClientTarget); |
| 792 | } |
| 793 | |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 794 | TEST_F(DisplayApplyDisplayRequestsTest, handlesAllRequestFlagsSet) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 795 | mDisplay->applyDisplayRequests(static_cast<HWC2::DisplayRequest>(~0)); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 796 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 797 | auto& state = mDisplay->getState(); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 798 | EXPECT_TRUE(state.flipClientTarget); |
| 799 | } |
| 800 | |
| 801 | /* |
| 802 | * Display::applyLayerRequestsToLayers() |
| 803 | */ |
| 804 | |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 805 | using DisplayApplyLayerRequestsToLayersTest = DisplayWithLayersTestCommon; |
| 806 | |
| 807 | TEST_F(DisplayApplyLayerRequestsToLayersTest, preparesAllLayers) { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 808 | EXPECT_CALL(*mLayer1.outputLayer, prepareForDeviceLayerRequests()).Times(1); |
| 809 | EXPECT_CALL(*mLayer2.outputLayer, prepareForDeviceLayerRequests()).Times(1); |
| 810 | EXPECT_CALL(*mLayer3.outputLayer, prepareForDeviceLayerRequests()).Times(1); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 811 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 812 | mDisplay->applyLayerRequestsToLayers(impl::Display::LayerRequests()); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 813 | } |
| 814 | |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 815 | TEST_F(DisplayApplyLayerRequestsToLayersTest, appliesDeviceLayerRequests) { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 816 | EXPECT_CALL(*mLayer1.outputLayer, prepareForDeviceLayerRequests()).Times(1); |
| 817 | EXPECT_CALL(*mLayer2.outputLayer, prepareForDeviceLayerRequests()).Times(1); |
| 818 | EXPECT_CALL(*mLayer3.outputLayer, prepareForDeviceLayerRequests()).Times(1); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 819 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 820 | EXPECT_CALL(*mLayer1.outputLayer, |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 821 | applyDeviceLayerRequest(Hwc2::IComposerClient::LayerRequest::CLEAR_CLIENT_TARGET)) |
| 822 | .Times(1); |
| 823 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 824 | mDisplay->applyLayerRequestsToLayers(impl::Display::LayerRequests{ |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 825 | {&mLayer1.hwc2Layer, HWC2::LayerRequest::ClearClientTarget}, |
| 826 | {&hwc2LayerUnknown, HWC2::LayerRequest::ClearClientTarget}, |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 827 | }); |
| 828 | } |
| 829 | |
Lloyd Pique | 35fca9d | 2019-02-13 14:24:11 -0800 | [diff] [blame] | 830 | /* |
| 831 | * Display::presentAndGetFrameFences() |
| 832 | */ |
| 833 | |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 834 | using DisplayPresentAndGetFrameFencesTest = DisplayWithLayersTestCommon; |
| 835 | |
| 836 | TEST_F(DisplayPresentAndGetFrameFencesTest, returnsNoFencesOnNonHwcDisplay) { |
| 837 | auto args = getDisplayCreationArgsForNonHWCVirtualDisplay(); |
| 838 | auto nonHwcDisplay{impl::createDisplay(mCompositionEngine, args)}; |
Lloyd Pique | 35fca9d | 2019-02-13 14:24:11 -0800 | [diff] [blame] | 839 | |
| 840 | auto result = nonHwcDisplay->presentAndGetFrameFences(); |
| 841 | |
| 842 | ASSERT_TRUE(result.presentFence.get()); |
| 843 | EXPECT_FALSE(result.presentFence->isValid()); |
| 844 | EXPECT_EQ(0u, result.layerFences.size()); |
| 845 | } |
| 846 | |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 847 | TEST_F(DisplayPresentAndGetFrameFencesTest, returnsPresentAndLayerFences) { |
Lloyd Pique | 35fca9d | 2019-02-13 14:24:11 -0800 | [diff] [blame] | 848 | sp<Fence> presentFence = new Fence(); |
| 849 | sp<Fence> layer1Fence = new Fence(); |
| 850 | sp<Fence> layer2Fence = new Fence(); |
| 851 | |
| 852 | EXPECT_CALL(mHwComposer, presentAndGetReleaseFences(DEFAULT_DISPLAY_ID)).Times(1); |
| 853 | EXPECT_CALL(mHwComposer, getPresentFence(DEFAULT_DISPLAY_ID)).WillOnce(Return(presentFence)); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 854 | EXPECT_CALL(mHwComposer, getLayerReleaseFence(DEFAULT_DISPLAY_ID, &mLayer1.hwc2Layer)) |
Lloyd Pique | 35fca9d | 2019-02-13 14:24:11 -0800 | [diff] [blame] | 855 | .WillOnce(Return(layer1Fence)); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 856 | EXPECT_CALL(mHwComposer, getLayerReleaseFence(DEFAULT_DISPLAY_ID, &mLayer2.hwc2Layer)) |
Lloyd Pique | 35fca9d | 2019-02-13 14:24:11 -0800 | [diff] [blame] | 857 | .WillOnce(Return(layer2Fence)); |
| 858 | EXPECT_CALL(mHwComposer, clearReleaseFences(DEFAULT_DISPLAY_ID)).Times(1); |
| 859 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 860 | auto result = mDisplay->presentAndGetFrameFences(); |
Lloyd Pique | 35fca9d | 2019-02-13 14:24:11 -0800 | [diff] [blame] | 861 | |
| 862 | EXPECT_EQ(presentFence, result.presentFence); |
| 863 | |
| 864 | EXPECT_EQ(2u, result.layerFences.size()); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 865 | ASSERT_EQ(1, result.layerFences.count(&mLayer1.hwc2Layer)); |
| 866 | EXPECT_EQ(layer1Fence, result.layerFences[&mLayer1.hwc2Layer]); |
| 867 | ASSERT_EQ(1, result.layerFences.count(&mLayer2.hwc2Layer)); |
| 868 | EXPECT_EQ(layer2Fence, result.layerFences[&mLayer2.hwc2Layer]); |
Lloyd Pique | 35fca9d | 2019-02-13 14:24:11 -0800 | [diff] [blame] | 869 | } |
| 870 | |
Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 871 | /* |
| 872 | * Display::setExpensiveRenderingExpected() |
| 873 | */ |
| 874 | |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 875 | using DisplaySetExpensiveRenderingExpectedTest = DisplayWithLayersTestCommon; |
| 876 | |
| 877 | TEST_F(DisplaySetExpensiveRenderingExpectedTest, forwardsToPowerAdvisor) { |
Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 878 | EXPECT_CALL(mPowerAdvisor, setExpensiveRenderingExpected(DEFAULT_DISPLAY_ID, true)).Times(1); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 879 | mDisplay->setExpensiveRenderingExpected(true); |
Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 880 | |
| 881 | EXPECT_CALL(mPowerAdvisor, setExpensiveRenderingExpected(DEFAULT_DISPLAY_ID, false)).Times(1); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 882 | mDisplay->setExpensiveRenderingExpected(false); |
Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 883 | } |
| 884 | |
Lloyd Pique | d3d6988 | 2019-02-28 16:03:46 -0800 | [diff] [blame] | 885 | /* |
| 886 | * Display::finishFrame() |
| 887 | */ |
| 888 | |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 889 | using DisplayFinishFrameTest = DisplayWithLayersTestCommon; |
| 890 | |
| 891 | TEST_F(DisplayFinishFrameTest, doesNotSkipCompositionIfNotDirtyOnHwcDisplay) { |
Lloyd Pique | d3d6988 | 2019-02-28 16:03:46 -0800 | [diff] [blame] | 892 | mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>(); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 893 | mDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface)); |
Lloyd Pique | d3d6988 | 2019-02-28 16:03:46 -0800 | [diff] [blame] | 894 | |
| 895 | // We expect no calls to queueBuffer if composition was skipped. |
| 896 | EXPECT_CALL(*renderSurface, queueBuffer(_)).Times(1); |
| 897 | |
Lloyd Pique | a76ce46 | 2020-01-14 13:06:37 -0800 | [diff] [blame] | 898 | // Expect a call to signal no expensive rendering since there is no client composition. |
| 899 | EXPECT_CALL(mPowerAdvisor, setExpensiveRenderingExpected(DEFAULT_DISPLAY_ID, false)); |
| 900 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 901 | mDisplay->editState().isEnabled = true; |
| 902 | mDisplay->editState().usesClientComposition = false; |
| 903 | mDisplay->editState().viewport = Rect(0, 0, 1, 1); |
| 904 | mDisplay->editState().dirtyRegion = Region::INVALID_REGION; |
Lloyd Pique | d3d6988 | 2019-02-28 16:03:46 -0800 | [diff] [blame] | 905 | |
| 906 | CompositionRefreshArgs refreshArgs; |
| 907 | refreshArgs.repaintEverything = false; |
| 908 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 909 | mDisplay->finishFrame(refreshArgs); |
Lloyd Pique | d3d6988 | 2019-02-28 16:03:46 -0800 | [diff] [blame] | 910 | } |
| 911 | |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 912 | TEST_F(DisplayFinishFrameTest, skipsCompositionIfNotDirty) { |
| 913 | auto args = getDisplayCreationArgsForNonHWCVirtualDisplay(); |
| 914 | std::shared_ptr<impl::Display> nonHwcDisplay = impl::createDisplay(mCompositionEngine, args); |
Lloyd Pique | d3d6988 | 2019-02-28 16:03:46 -0800 | [diff] [blame] | 915 | |
| 916 | mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>(); |
| 917 | nonHwcDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface)); |
| 918 | |
| 919 | // We expect no calls to queueBuffer if composition was skipped. |
| 920 | EXPECT_CALL(*renderSurface, queueBuffer(_)).Times(0); |
| 921 | |
| 922 | nonHwcDisplay->editState().isEnabled = true; |
| 923 | nonHwcDisplay->editState().usesClientComposition = false; |
| 924 | nonHwcDisplay->editState().viewport = Rect(0, 0, 1, 1); |
| 925 | nonHwcDisplay->editState().dirtyRegion = Region::INVALID_REGION; |
| 926 | |
| 927 | CompositionRefreshArgs refreshArgs; |
| 928 | refreshArgs.repaintEverything = false; |
| 929 | |
| 930 | nonHwcDisplay->finishFrame(refreshArgs); |
| 931 | } |
| 932 | |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 933 | TEST_F(DisplayFinishFrameTest, performsCompositionIfDirty) { |
| 934 | auto args = getDisplayCreationArgsForNonHWCVirtualDisplay(); |
| 935 | std::shared_ptr<impl::Display> nonHwcDisplay = impl::createDisplay(mCompositionEngine, args); |
Lloyd Pique | d3d6988 | 2019-02-28 16:03:46 -0800 | [diff] [blame] | 936 | |
| 937 | mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>(); |
| 938 | nonHwcDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface)); |
| 939 | |
| 940 | // We expect a single call to queueBuffer when composition is not skipped. |
| 941 | EXPECT_CALL(*renderSurface, queueBuffer(_)).Times(1); |
| 942 | |
| 943 | nonHwcDisplay->editState().isEnabled = true; |
| 944 | nonHwcDisplay->editState().usesClientComposition = false; |
| 945 | nonHwcDisplay->editState().viewport = Rect(0, 0, 1, 1); |
| 946 | nonHwcDisplay->editState().dirtyRegion = Region(Rect(0, 0, 1, 1)); |
| 947 | |
| 948 | CompositionRefreshArgs refreshArgs; |
| 949 | refreshArgs.repaintEverything = false; |
| 950 | |
| 951 | nonHwcDisplay->finishFrame(refreshArgs); |
| 952 | } |
| 953 | |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 954 | TEST_F(DisplayFinishFrameTest, performsCompositionIfRepaintEverything) { |
| 955 | auto args = getDisplayCreationArgsForNonHWCVirtualDisplay(); |
| 956 | std::shared_ptr<impl::Display> nonHwcDisplay = impl::createDisplay(mCompositionEngine, args); |
Lloyd Pique | d3d6988 | 2019-02-28 16:03:46 -0800 | [diff] [blame] | 957 | |
| 958 | mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>(); |
| 959 | nonHwcDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface)); |
| 960 | |
| 961 | // We expect a single call to queueBuffer when composition is not skipped. |
| 962 | EXPECT_CALL(*renderSurface, queueBuffer(_)).Times(1); |
| 963 | |
| 964 | nonHwcDisplay->editState().isEnabled = true; |
| 965 | nonHwcDisplay->editState().usesClientComposition = false; |
| 966 | nonHwcDisplay->editState().viewport = Rect(0, 0, 1, 1); |
| 967 | nonHwcDisplay->editState().dirtyRegion = Region::INVALID_REGION; |
| 968 | |
| 969 | CompositionRefreshArgs refreshArgs; |
| 970 | refreshArgs.repaintEverything = true; |
| 971 | |
| 972 | nonHwcDisplay->finishFrame(refreshArgs); |
| 973 | } |
| 974 | |
Lloyd Pique | c660755 | 2019-12-02 17:57:39 -0800 | [diff] [blame] | 975 | /* |
| 976 | * Display functional tests |
| 977 | */ |
| 978 | |
| 979 | struct DisplayFunctionalTest : public testing::Test { |
| 980 | class Display : public impl::Display { |
| 981 | public: |
Lloyd Pique | c660755 | 2019-12-02 17:57:39 -0800 | [diff] [blame] | 982 | using impl::Display::injectOutputLayerForTest; |
| 983 | virtual void injectOutputLayerForTest(std::unique_ptr<compositionengine::OutputLayer>) = 0; |
| 984 | }; |
| 985 | |
Lloyd Pique | c660755 | 2019-12-02 17:57:39 -0800 | [diff] [blame] | 986 | DisplayFunctionalTest() { |
| 987 | EXPECT_CALL(mCompositionEngine, getHwComposer()).WillRepeatedly(ReturnRef(mHwComposer)); |
| 988 | |
| 989 | mDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface)); |
| 990 | } |
| 991 | |
| 992 | NiceMock<android::mock::HWComposer> mHwComposer; |
| 993 | NiceMock<Hwc2::mock::PowerAdvisor> mPowerAdvisor; |
| 994 | NiceMock<mock::CompositionEngine> mCompositionEngine; |
| 995 | sp<mock::NativeWindow> mNativeWindow = new NiceMock<mock::NativeWindow>(); |
| 996 | sp<mock::DisplaySurface> mDisplaySurface = new NiceMock<mock::DisplaySurface>(); |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 997 | std::shared_ptr<Display> mDisplay = impl::createDisplayTemplated< |
| 998 | Display>(mCompositionEngine, |
| 999 | DisplayCreationArgsBuilder() |
| 1000 | .setPhysical({DEFAULT_DISPLAY_ID, DisplayConnectionType::Internal}) |
| 1001 | .setPixels({DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT}) |
| 1002 | .setPixelFormat(static_cast<ui::PixelFormat>(PIXEL_FORMAT_RGBA_8888)) |
| 1003 | .setIsSecure(true) |
| 1004 | .setLayerStackId(DEFAULT_LAYER_STACK) |
| 1005 | .setPowerAdvisor(&mPowerAdvisor) |
| 1006 | .build() |
| 1007 | |
| 1008 | ); |
Lloyd Pique | c660755 | 2019-12-02 17:57:39 -0800 | [diff] [blame] | 1009 | impl::RenderSurface* mRenderSurface = |
| 1010 | new impl::RenderSurface{mCompositionEngine, *mDisplay, |
| 1011 | RenderSurfaceCreationArgs{DEFAULT_DISPLAY_WIDTH, |
| 1012 | DEFAULT_DISPLAY_HEIGHT, mNativeWindow, |
| 1013 | mDisplaySurface}}; |
| 1014 | }; |
| 1015 | |
| 1016 | TEST_F(DisplayFunctionalTest, postFramebufferCriticalCallsAreOrdered) { |
| 1017 | InSequence seq; |
| 1018 | |
| 1019 | mDisplay->editState().isEnabled = true; |
| 1020 | |
| 1021 | EXPECT_CALL(mHwComposer, presentAndGetReleaseFences(_)); |
| 1022 | EXPECT_CALL(*mDisplaySurface, onFrameCommitted()); |
| 1023 | |
| 1024 | mDisplay->postFramebuffer(); |
| 1025 | } |
| 1026 | |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 1027 | } // namespace |
| 1028 | } // namespace android::compositionengine |