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