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