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