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