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