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