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/Layer.h> |
| 29 | #include <compositionengine/mock/LayerFE.h> |
chaviw | 8beb414 | 2019-04-11 13:09:05 -0700 | [diff] [blame] | 30 | #include <compositionengine/mock/NativeWindow.h> |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 31 | #include <compositionengine/mock/OutputLayer.h> |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 32 | #include <compositionengine/mock/RenderSurface.h> |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 33 | #include <gtest/gtest.h> |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 34 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 35 | #include "MockHWC2.h" |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 36 | #include "MockHWComposer.h" |
Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 37 | #include "MockPowerAdvisor.h" |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 38 | |
| 39 | namespace android::compositionengine { |
| 40 | namespace { |
| 41 | |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 42 | using testing::_; |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 43 | using testing::DoAll; |
Lloyd Pique | c660755 | 2019-12-02 17:57:39 -0800 | [diff] [blame] | 44 | using testing::InSequence; |
| 45 | using testing::NiceMock; |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 46 | using testing::Return; |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 47 | using testing::ReturnRef; |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 48 | using testing::Sequence; |
| 49 | using testing::SetArgPointee; |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 50 | using testing::StrictMock; |
| 51 | |
| 52 | constexpr DisplayId DEFAULT_DISPLAY_ID = DisplayId{42}; |
Lloyd Pique | c660755 | 2019-12-02 17:57:39 -0800 | [diff] [blame] | 53 | constexpr int32_t DEFAULT_DISPLAY_WIDTH = 1920; |
| 54 | constexpr int32_t DEFAULT_DISPLAY_HEIGHT = 1080; |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 55 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 56 | struct DisplayTest : public testing::Test { |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 57 | class Display : public impl::Display { |
| 58 | public: |
| 59 | explicit Display(const compositionengine::DisplayCreationArgs& args) |
| 60 | : impl::Display(args) {} |
| 61 | |
| 62 | using impl::Display::injectOutputLayerForTest; |
| 63 | virtual void injectOutputLayerForTest(std::unique_ptr<compositionengine::OutputLayer>) = 0; |
| 64 | }; |
| 65 | |
| 66 | static std::shared_ptr<Display> createDisplay( |
| 67 | const compositionengine::CompositionEngine& compositionEngine, |
| 68 | compositionengine::DisplayCreationArgs&& args) { |
| 69 | return impl::createDisplayTemplated<Display>(compositionEngine, args); |
| 70 | } |
| 71 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 72 | DisplayTest() { |
| 73 | EXPECT_CALL(mCompositionEngine, getHwComposer()).WillRepeatedly(ReturnRef(mHwComposer)); |
| 74 | EXPECT_CALL(*mLayer1, getHwcLayer()).WillRepeatedly(Return(&mHWC2Layer1)); |
| 75 | EXPECT_CALL(*mLayer2, getHwcLayer()).WillRepeatedly(Return(&mHWC2Layer2)); |
| 76 | EXPECT_CALL(*mLayer3, getHwcLayer()).WillRepeatedly(Return(nullptr)); |
| 77 | |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 78 | mDisplay->injectOutputLayerForTest( |
| 79 | std::unique_ptr<compositionengine::OutputLayer>(mLayer1)); |
| 80 | mDisplay->injectOutputLayerForTest( |
| 81 | std::unique_ptr<compositionengine::OutputLayer>(mLayer2)); |
| 82 | mDisplay->injectOutputLayerForTest( |
| 83 | std::unique_ptr<compositionengine::OutputLayer>(mLayer3)); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 84 | } |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 85 | |
| 86 | StrictMock<android::mock::HWComposer> mHwComposer; |
Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 87 | StrictMock<Hwc2::mock::PowerAdvisor> mPowerAdvisor; |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 88 | StrictMock<mock::CompositionEngine> mCompositionEngine; |
chaviw | 8beb414 | 2019-04-11 13:09:05 -0700 | [diff] [blame] | 89 | sp<mock::NativeWindow> mNativeWindow = new StrictMock<mock::NativeWindow>(); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 90 | StrictMock<HWC2::mock::Layer> mHWC2Layer1; |
| 91 | StrictMock<HWC2::mock::Layer> mHWC2Layer2; |
| 92 | StrictMock<HWC2::mock::Layer> mHWC2LayerUnknown; |
| 93 | mock::OutputLayer* mLayer1 = new StrictMock<mock::OutputLayer>(); |
| 94 | mock::OutputLayer* mLayer2 = new StrictMock<mock::OutputLayer>(); |
| 95 | mock::OutputLayer* mLayer3 = new StrictMock<mock::OutputLayer>(); |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 96 | std::shared_ptr<Display> mDisplay = createDisplay(mCompositionEngine, |
| 97 | DisplayCreationArgsBuilder() |
| 98 | .setDisplayId(DEFAULT_DISPLAY_ID) |
| 99 | .setPowerAdvisor(&mPowerAdvisor) |
| 100 | .build()); |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 101 | }; |
| 102 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 103 | /* |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 104 | * Basic construction |
| 105 | */ |
| 106 | |
| 107 | TEST_F(DisplayTest, canInstantiateDisplay) { |
| 108 | { |
| 109 | constexpr DisplayId display1 = DisplayId{123u}; |
| 110 | auto display = |
| 111 | impl::createDisplay(mCompositionEngine, |
| 112 | DisplayCreationArgsBuilder().setDisplayId(display1).build()); |
| 113 | EXPECT_FALSE(display->isSecure()); |
| 114 | EXPECT_FALSE(display->isVirtual()); |
| 115 | EXPECT_EQ(display1, display->getId()); |
| 116 | } |
| 117 | |
| 118 | { |
| 119 | constexpr DisplayId display2 = DisplayId{546u}; |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 120 | auto display = |
| 121 | impl::createDisplay(mCompositionEngine, |
| 122 | DisplayCreationArgsBuilder().setDisplayId(display2).build()); |
| 123 | EXPECT_FALSE(display->isSecure()); |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 124 | EXPECT_FALSE(display->isVirtual()); |
| 125 | EXPECT_EQ(display2, display->getId()); |
| 126 | } |
| 127 | |
| 128 | { |
| 129 | constexpr DisplayId display3 = DisplayId{789u}; |
| 130 | auto display = impl::createDisplay(mCompositionEngine, |
| 131 | DisplayCreationArgsBuilder() |
| 132 | .setIsVirtual(true) |
| 133 | .setDisplayId(display3) |
| 134 | .build()); |
| 135 | EXPECT_FALSE(display->isSecure()); |
| 136 | EXPECT_TRUE(display->isVirtual()); |
| 137 | EXPECT_EQ(display3, display->getId()); |
| 138 | } |
| 139 | } |
| 140 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 141 | /* |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 142 | * Display::disconnect() |
| 143 | */ |
| 144 | |
| 145 | TEST_F(DisplayTest, disconnectDisconnectsDisplay) { |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 146 | // The first call to disconnect will disconnect the display with the HWC and |
| 147 | // set mHwcId to -1. |
| 148 | EXPECT_CALL(mHwComposer, disconnectDisplay(DEFAULT_DISPLAY_ID)).Times(1); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 149 | mDisplay->disconnect(); |
| 150 | EXPECT_FALSE(mDisplay->getId()); |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 151 | |
| 152 | // Subsequent calls will do nothing, |
| 153 | EXPECT_CALL(mHwComposer, disconnectDisplay(DEFAULT_DISPLAY_ID)).Times(0); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 154 | mDisplay->disconnect(); |
| 155 | EXPECT_FALSE(mDisplay->getId()); |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 156 | } |
| 157 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 158 | /* |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 159 | * Display::setColorTransform() |
| 160 | */ |
| 161 | |
| 162 | TEST_F(DisplayTest, setColorTransformSetsTransform) { |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 163 | // No change does nothing |
| 164 | CompositionRefreshArgs refreshArgs; |
| 165 | refreshArgs.colorTransformMatrix = std::nullopt; |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 166 | mDisplay->setColorTransform(refreshArgs); |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 167 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 168 | // Identity matrix sets an identity state value |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 169 | const mat4 kIdentity; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 170 | |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 171 | EXPECT_CALL(mHwComposer, setColorTransform(DEFAULT_DISPLAY_ID, kIdentity)).Times(1); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 172 | |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 173 | refreshArgs.colorTransformMatrix = kIdentity; |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 174 | mDisplay->setColorTransform(refreshArgs); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 175 | |
| 176 | // Non-identity matrix sets a non-identity state value |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 177 | const mat4 kNonIdentity = mat4() * 2; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 178 | |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 179 | EXPECT_CALL(mHwComposer, setColorTransform(DEFAULT_DISPLAY_ID, kNonIdentity)).Times(1); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 180 | |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 181 | refreshArgs.colorTransformMatrix = kNonIdentity; |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 182 | mDisplay->setColorTransform(refreshArgs); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 183 | } |
| 184 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 185 | /* |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 186 | * Display::setColorMode() |
| 187 | */ |
| 188 | |
| 189 | TEST_F(DisplayTest, setColorModeSetsModeUnlessNoChange) { |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 190 | using ColorProfile = Output::ColorProfile; |
| 191 | |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 192 | mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>(); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 193 | mDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface)); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 194 | mock::DisplayColorProfile* colorProfile = new StrictMock<mock::DisplayColorProfile>(); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 195 | mDisplay->setDisplayColorProfileForTest(std::unique_ptr<DisplayColorProfile>(colorProfile)); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 196 | |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 197 | EXPECT_CALL(*colorProfile, getTargetDataspace(_, _, _)) |
| 198 | .WillRepeatedly(Return(ui::Dataspace::UNKNOWN)); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 199 | |
| 200 | // These values are expected to be the initial state. |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 201 | ASSERT_EQ(ui::ColorMode::NATIVE, mDisplay->getState().colorMode); |
| 202 | ASSERT_EQ(ui::Dataspace::UNKNOWN, mDisplay->getState().dataspace); |
| 203 | ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mDisplay->getState().renderIntent); |
| 204 | ASSERT_EQ(ui::Dataspace::UNKNOWN, mDisplay->getState().targetDataspace); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 205 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 206 | // Otherwise if the values are unchanged, nothing happens |
| 207 | mDisplay->setColorProfile(ColorProfile{ui::ColorMode::NATIVE, ui::Dataspace::UNKNOWN, |
| 208 | ui::RenderIntent::COLORIMETRIC, ui::Dataspace::UNKNOWN}); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 209 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 210 | EXPECT_EQ(ui::ColorMode::NATIVE, mDisplay->getState().colorMode); |
| 211 | EXPECT_EQ(ui::Dataspace::UNKNOWN, mDisplay->getState().dataspace); |
| 212 | EXPECT_EQ(ui::RenderIntent::COLORIMETRIC, mDisplay->getState().renderIntent); |
| 213 | EXPECT_EQ(ui::Dataspace::UNKNOWN, mDisplay->getState().targetDataspace); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 214 | |
| 215 | // Otherwise if the values are different, updates happen |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 216 | EXPECT_CALL(*renderSurface, setBufferDataspace(ui::Dataspace::DISPLAY_P3)).Times(1); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 217 | EXPECT_CALL(mHwComposer, |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 218 | setActiveColorMode(DEFAULT_DISPLAY_ID, ui::ColorMode::DISPLAY_P3, |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 219 | ui::RenderIntent::TONE_MAP_COLORIMETRIC)) |
| 220 | .Times(1); |
| 221 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 222 | mDisplay->setColorProfile(ColorProfile{ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3, |
| 223 | ui::RenderIntent::TONE_MAP_COLORIMETRIC, |
| 224 | ui::Dataspace::UNKNOWN}); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 225 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 226 | EXPECT_EQ(ui::ColorMode::DISPLAY_P3, mDisplay->getState().colorMode); |
| 227 | EXPECT_EQ(ui::Dataspace::DISPLAY_P3, mDisplay->getState().dataspace); |
| 228 | EXPECT_EQ(ui::RenderIntent::TONE_MAP_COLORIMETRIC, mDisplay->getState().renderIntent); |
| 229 | EXPECT_EQ(ui::Dataspace::UNKNOWN, mDisplay->getState().targetDataspace); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | TEST_F(DisplayTest, setColorModeDoesNothingForVirtualDisplay) { |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 233 | using ColorProfile = Output::ColorProfile; |
| 234 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 235 | std::shared_ptr<impl::Display> virtualDisplay{ |
| 236 | impl::createDisplay(mCompositionEngine, DisplayCreationArgs{true, DEFAULT_DISPLAY_ID})}; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 237 | |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 238 | mock::DisplayColorProfile* colorProfile = new StrictMock<mock::DisplayColorProfile>(); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 239 | virtualDisplay->setDisplayColorProfileForTest( |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 240 | std::unique_ptr<DisplayColorProfile>(colorProfile)); |
| 241 | |
| 242 | EXPECT_CALL(*colorProfile, |
| 243 | getTargetDataspace(ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3, |
| 244 | ui::Dataspace::UNKNOWN)) |
| 245 | .WillOnce(Return(ui::Dataspace::UNKNOWN)); |
| 246 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 247 | virtualDisplay->setColorProfile( |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 248 | ColorProfile{ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3, |
| 249 | ui::RenderIntent::TONE_MAP_COLORIMETRIC, ui::Dataspace::UNKNOWN}); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 250 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 251 | EXPECT_EQ(ui::ColorMode::NATIVE, virtualDisplay->getState().colorMode); |
| 252 | EXPECT_EQ(ui::Dataspace::UNKNOWN, virtualDisplay->getState().dataspace); |
| 253 | EXPECT_EQ(ui::RenderIntent::COLORIMETRIC, virtualDisplay->getState().renderIntent); |
| 254 | EXPECT_EQ(ui::Dataspace::UNKNOWN, virtualDisplay->getState().targetDataspace); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 255 | } |
| 256 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 257 | /* |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 258 | * Display::createDisplayColorProfile() |
| 259 | */ |
| 260 | |
| 261 | TEST_F(DisplayTest, createDisplayColorProfileSetsDisplayColorProfile) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 262 | EXPECT_TRUE(mDisplay->getDisplayColorProfile() == nullptr); |
| 263 | mDisplay->createDisplayColorProfile( |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 264 | DisplayColorProfileCreationArgs{false, HdrCapabilities(), 0, |
| 265 | DisplayColorProfileCreationArgs::HwcColorModes()}); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 266 | EXPECT_TRUE(mDisplay->getDisplayColorProfile() != nullptr); |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 267 | } |
| 268 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 269 | /* |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 270 | * Display::createRenderSurface() |
| 271 | */ |
| 272 | |
| 273 | TEST_F(DisplayTest, createRenderSurfaceSetsRenderSurface) { |
chaviw | 8beb414 | 2019-04-11 13:09:05 -0700 | [diff] [blame] | 274 | EXPECT_CALL(*mNativeWindow, disconnect(NATIVE_WINDOW_API_EGL)).WillRepeatedly(Return(NO_ERROR)); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 275 | EXPECT_TRUE(mDisplay->getRenderSurface() == nullptr); |
| 276 | mDisplay->createRenderSurface(RenderSurfaceCreationArgs{640, 480, mNativeWindow, nullptr}); |
| 277 | EXPECT_TRUE(mDisplay->getRenderSurface() != nullptr); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 278 | } |
| 279 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 280 | /* |
Lloyd Pique | df336d9 | 2019-03-07 21:38:42 -0800 | [diff] [blame] | 281 | * Display::createOutputLayer() |
| 282 | */ |
| 283 | |
| 284 | TEST_F(DisplayTest, createOutputLayerSetsHwcLayer) { |
| 285 | sp<mock::LayerFE> layerFE = new StrictMock<mock::LayerFE>(); |
| 286 | auto layer = std::make_shared<StrictMock<mock::Layer>>(); |
| 287 | StrictMock<HWC2::mock::Layer> hwcLayer; |
| 288 | |
| 289 | EXPECT_CALL(mHwComposer, createLayer(DEFAULT_DISPLAY_ID)).WillOnce(Return(&hwcLayer)); |
| 290 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 291 | auto outputLayer = mDisplay->createOutputLayer(layer, layerFE); |
Lloyd Pique | df336d9 | 2019-03-07 21:38:42 -0800 | [diff] [blame] | 292 | |
| 293 | EXPECT_EQ(&hwcLayer, outputLayer->getHwcLayer()); |
| 294 | |
| 295 | EXPECT_CALL(mHwComposer, destroyLayer(DEFAULT_DISPLAY_ID, &hwcLayer)); |
| 296 | outputLayer.reset(); |
| 297 | } |
| 298 | |
| 299 | /* |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 300 | * Display::setReleasedLayers() |
| 301 | */ |
| 302 | |
| 303 | TEST_F(DisplayTest, setReleasedLayersDoesNothingIfNotHwcDisplay) { |
| 304 | std::shared_ptr<impl::Display> nonHwcDisplay{ |
| 305 | impl::createDisplay(mCompositionEngine, DisplayCreationArgsBuilder().build())}; |
| 306 | |
| 307 | sp<mock::LayerFE> layerXLayerFE = new StrictMock<mock::LayerFE>(); |
| 308 | mock::Layer layerXLayer; |
| 309 | |
| 310 | { |
| 311 | Output::ReleasedLayers releasedLayers; |
| 312 | releasedLayers.emplace_back(layerXLayerFE); |
| 313 | nonHwcDisplay->setReleasedLayers(std::move(releasedLayers)); |
| 314 | } |
| 315 | |
| 316 | CompositionRefreshArgs refreshArgs; |
| 317 | refreshArgs.layersWithQueuedFrames.push_back(&layerXLayer); |
| 318 | |
| 319 | nonHwcDisplay->setReleasedLayers(refreshArgs); |
| 320 | |
| 321 | const auto& releasedLayers = nonHwcDisplay->getReleasedLayersForTest(); |
| 322 | ASSERT_EQ(1, releasedLayers.size()); |
| 323 | } |
| 324 | |
| 325 | TEST_F(DisplayTest, setReleasedLayersDoesNothingIfNoLayersWithQueuedFrames) { |
| 326 | sp<mock::LayerFE> layerXLayerFE = new StrictMock<mock::LayerFE>(); |
| 327 | |
| 328 | { |
| 329 | Output::ReleasedLayers releasedLayers; |
| 330 | releasedLayers.emplace_back(layerXLayerFE); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 331 | mDisplay->setReleasedLayers(std::move(releasedLayers)); |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | CompositionRefreshArgs refreshArgs; |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 335 | mDisplay->setReleasedLayers(refreshArgs); |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 336 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 337 | const auto& releasedLayers = mDisplay->getReleasedLayersForTest(); |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 338 | ASSERT_EQ(1, releasedLayers.size()); |
| 339 | } |
| 340 | |
| 341 | TEST_F(DisplayTest, setReleasedLayers) { |
| 342 | sp<mock::LayerFE> layer1LayerFE = new StrictMock<mock::LayerFE>(); |
| 343 | sp<mock::LayerFE> layer2LayerFE = new StrictMock<mock::LayerFE>(); |
| 344 | sp<mock::LayerFE> layer3LayerFE = new StrictMock<mock::LayerFE>(); |
| 345 | sp<mock::LayerFE> layerXLayerFE = new StrictMock<mock::LayerFE>(); |
| 346 | mock::Layer layer1Layer; |
| 347 | mock::Layer layer2Layer; |
| 348 | mock::Layer layer3Layer; |
| 349 | mock::Layer layerXLayer; |
| 350 | |
| 351 | EXPECT_CALL(*mLayer1, getLayer()).WillRepeatedly(ReturnRef(layer1Layer)); |
| 352 | EXPECT_CALL(*mLayer1, getLayerFE()).WillRepeatedly(ReturnRef(*layer1LayerFE.get())); |
| 353 | EXPECT_CALL(*mLayer2, getLayer()).WillRepeatedly(ReturnRef(layer2Layer)); |
| 354 | EXPECT_CALL(*mLayer2, getLayerFE()).WillRepeatedly(ReturnRef(*layer2LayerFE.get())); |
| 355 | EXPECT_CALL(*mLayer3, getLayer()).WillRepeatedly(ReturnRef(layer3Layer)); |
| 356 | EXPECT_CALL(*mLayer3, getLayerFE()).WillRepeatedly(ReturnRef(*layer3LayerFE.get())); |
| 357 | |
| 358 | CompositionRefreshArgs refreshArgs; |
| 359 | refreshArgs.layersWithQueuedFrames.push_back(&layer1Layer); |
| 360 | refreshArgs.layersWithQueuedFrames.push_back(&layer2Layer); |
| 361 | refreshArgs.layersWithQueuedFrames.push_back(&layerXLayer); |
| 362 | refreshArgs.layersWithQueuedFrames.push_back(nullptr); |
| 363 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 364 | mDisplay->setReleasedLayers(refreshArgs); |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 365 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 366 | const auto& releasedLayers = mDisplay->getReleasedLayersForTest(); |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 367 | ASSERT_EQ(2, releasedLayers.size()); |
| 368 | ASSERT_EQ(layer1LayerFE.get(), releasedLayers[0].promote().get()); |
| 369 | ASSERT_EQ(layer2LayerFE.get(), releasedLayers[1].promote().get()); |
| 370 | } |
| 371 | |
| 372 | /* |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 373 | * Display::chooseCompositionStrategy() |
| 374 | */ |
| 375 | |
| 376 | struct DisplayChooseCompositionStrategyTest : public testing::Test { |
| 377 | struct DisplayPartialMock : public impl::Display { |
| 378 | DisplayPartialMock(const compositionengine::CompositionEngine& compositionEngine, |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 379 | const compositionengine::DisplayCreationArgs& args) |
| 380 | : impl::Display(args), mCompositionEngine(compositionEngine) {} |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 381 | |
| 382 | // Sets up the helper functions called by chooseCompositionStrategy to |
| 383 | // use a mock implementations. |
| 384 | MOCK_CONST_METHOD0(anyLayersRequireClientComposition, bool()); |
| 385 | MOCK_CONST_METHOD0(allLayersRequireClientComposition, bool()); |
| 386 | MOCK_METHOD1(applyChangedTypesToLayers, void(const impl::Display::ChangedTypes&)); |
| 387 | MOCK_METHOD1(applyDisplayRequests, void(const impl::Display::DisplayRequests&)); |
| 388 | MOCK_METHOD1(applyLayerRequestsToLayers, void(const impl::Display::LayerRequests&)); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 389 | |
| 390 | // compositionengine::Output overrides |
| 391 | const OutputCompositionState& getState() const override { return mState; } |
| 392 | OutputCompositionState& editState() override { return mState; } |
| 393 | |
| 394 | // compositionengine::impl::Output overrides |
| 395 | const CompositionEngine& getCompositionEngine() const override { |
| 396 | return mCompositionEngine; |
| 397 | }; |
| 398 | |
| 399 | // These need implementations though are not expected to be called. |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 400 | MOCK_CONST_METHOD0(getOutputLayerCount, size_t()); |
| 401 | MOCK_CONST_METHOD1(getOutputLayerOrderedByZByIndex, |
| 402 | compositionengine::OutputLayer*(size_t)); |
| 403 | MOCK_METHOD3(ensureOutputLayer, |
| 404 | compositionengine::OutputLayer*( |
| 405 | std::optional<size_t>, |
| 406 | const std::shared_ptr<compositionengine::Layer>&, const sp<LayerFE>&)); |
| 407 | MOCK_METHOD0(finalizePendingOutputLayers, void()); |
| 408 | MOCK_METHOD0(clearOutputLayers, void()); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 409 | MOCK_CONST_METHOD1(dumpState, void(std::string&)); |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 410 | MOCK_METHOD2(injectOutputLayerForTest, |
| 411 | compositionengine::OutputLayer*( |
| 412 | const std::shared_ptr<compositionengine::Layer>&, const sp<LayerFE>&)); |
| 413 | MOCK_METHOD1(injectOutputLayerForTest, void(std::unique_ptr<OutputLayer>)); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 414 | |
| 415 | const compositionengine::CompositionEngine& mCompositionEngine; |
| 416 | impl::OutputCompositionState mState; |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 417 | }; |
| 418 | |
| 419 | DisplayChooseCompositionStrategyTest() { |
| 420 | EXPECT_CALL(mCompositionEngine, getHwComposer()).WillRepeatedly(ReturnRef(mHwComposer)); |
| 421 | } |
| 422 | |
| 423 | StrictMock<android::mock::HWComposer> mHwComposer; |
| 424 | StrictMock<mock::CompositionEngine> mCompositionEngine; |
| 425 | StrictMock<DisplayPartialMock> |
| 426 | mDisplay{mCompositionEngine, |
| 427 | DisplayCreationArgsBuilder().setDisplayId(DEFAULT_DISPLAY_ID).build()}; |
| 428 | }; |
| 429 | |
| 430 | TEST_F(DisplayChooseCompositionStrategyTest, takesEarlyOutIfNotAHwcDisplay) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 431 | std::shared_ptr<impl::Display> nonHwcDisplay{ |
| 432 | impl::createDisplay(mCompositionEngine, DisplayCreationArgsBuilder().build())}; |
| 433 | EXPECT_FALSE(nonHwcDisplay->getId()); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 434 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 435 | nonHwcDisplay->chooseCompositionStrategy(); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 436 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 437 | auto& state = nonHwcDisplay->getState(); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 438 | EXPECT_TRUE(state.usesClientComposition); |
| 439 | EXPECT_FALSE(state.usesDeviceComposition); |
| 440 | } |
| 441 | |
| 442 | TEST_F(DisplayChooseCompositionStrategyTest, takesEarlyOutOnHwcError) { |
| 443 | EXPECT_CALL(mDisplay, anyLayersRequireClientComposition()).WillOnce(Return(false)); |
| 444 | EXPECT_CALL(mHwComposer, getDeviceCompositionChanges(DEFAULT_DISPLAY_ID, false, _)) |
| 445 | .WillOnce(Return(INVALID_OPERATION)); |
| 446 | |
| 447 | mDisplay.chooseCompositionStrategy(); |
| 448 | |
| 449 | auto& state = mDisplay.getState(); |
| 450 | EXPECT_TRUE(state.usesClientComposition); |
| 451 | EXPECT_FALSE(state.usesDeviceComposition); |
| 452 | } |
| 453 | |
| 454 | TEST_F(DisplayChooseCompositionStrategyTest, normalOperation) { |
| 455 | // Since two calls are made to anyLayersRequireClientComposition with different return values, |
| 456 | // use a Sequence to control the matching so the values are returned in a known order. |
| 457 | Sequence s; |
| 458 | EXPECT_CALL(mDisplay, anyLayersRequireClientComposition()).InSequence(s).WillOnce(Return(true)); |
| 459 | EXPECT_CALL(mDisplay, anyLayersRequireClientComposition()) |
| 460 | .InSequence(s) |
| 461 | .WillOnce(Return(false)); |
| 462 | |
| 463 | EXPECT_CALL(mHwComposer, getDeviceCompositionChanges(DEFAULT_DISPLAY_ID, true, _)) |
| 464 | .WillOnce(Return(NO_ERROR)); |
| 465 | EXPECT_CALL(mDisplay, allLayersRequireClientComposition()).WillOnce(Return(false)); |
| 466 | |
| 467 | mDisplay.chooseCompositionStrategy(); |
| 468 | |
| 469 | auto& state = mDisplay.getState(); |
| 470 | EXPECT_FALSE(state.usesClientComposition); |
| 471 | EXPECT_TRUE(state.usesDeviceComposition); |
| 472 | } |
| 473 | |
| 474 | TEST_F(DisplayChooseCompositionStrategyTest, normalOperationWithChanges) { |
| 475 | android::HWComposer::DeviceRequestedChanges changes{ |
| 476 | {{nullptr, HWC2::Composition::Client}}, |
| 477 | HWC2::DisplayRequest::FlipClientTarget, |
| 478 | {{nullptr, HWC2::LayerRequest::ClearClientTarget}}, |
| 479 | }; |
| 480 | |
| 481 | // Since two calls are made to anyLayersRequireClientComposition with different return values, |
| 482 | // use a Sequence to control the matching so the values are returned in a known order. |
| 483 | Sequence s; |
| 484 | EXPECT_CALL(mDisplay, anyLayersRequireClientComposition()).InSequence(s).WillOnce(Return(true)); |
| 485 | EXPECT_CALL(mDisplay, anyLayersRequireClientComposition()) |
| 486 | .InSequence(s) |
| 487 | .WillOnce(Return(false)); |
| 488 | |
| 489 | EXPECT_CALL(mHwComposer, getDeviceCompositionChanges(DEFAULT_DISPLAY_ID, true, _)) |
| 490 | .WillOnce(DoAll(SetArgPointee<2>(changes), Return(NO_ERROR))); |
| 491 | EXPECT_CALL(mDisplay, applyChangedTypesToLayers(changes.changedTypes)).Times(1); |
| 492 | EXPECT_CALL(mDisplay, applyDisplayRequests(changes.displayRequests)).Times(1); |
| 493 | EXPECT_CALL(mDisplay, applyLayerRequestsToLayers(changes.layerRequests)).Times(1); |
| 494 | EXPECT_CALL(mDisplay, allLayersRequireClientComposition()).WillOnce(Return(false)); |
| 495 | |
| 496 | mDisplay.chooseCompositionStrategy(); |
| 497 | |
| 498 | auto& state = mDisplay.getState(); |
| 499 | EXPECT_FALSE(state.usesClientComposition); |
| 500 | EXPECT_TRUE(state.usesDeviceComposition); |
| 501 | } |
| 502 | |
| 503 | /* |
Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 504 | * Display::getSkipColorTransform() |
| 505 | */ |
| 506 | |
| 507 | TEST_F(DisplayTest, getSkipColorTransformDoesNothingIfNonHwcDisplay) { |
| 508 | auto nonHwcDisplay{ |
| 509 | impl::createDisplay(mCompositionEngine, DisplayCreationArgsBuilder().build())}; |
| 510 | EXPECT_FALSE(nonHwcDisplay->getSkipColorTransform()); |
| 511 | } |
| 512 | |
| 513 | TEST_F(DisplayTest, getSkipColorTransformChecksHwcCapability) { |
| 514 | EXPECT_CALL(mHwComposer, |
| 515 | hasDisplayCapability(std::make_optional(DEFAULT_DISPLAY_ID), |
| 516 | HWC2::DisplayCapability::SkipClientColorTransform)) |
| 517 | .WillOnce(Return(true)); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 518 | EXPECT_TRUE(mDisplay->getSkipColorTransform()); |
Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 519 | } |
| 520 | |
| 521 | /* |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 522 | * Display::anyLayersRequireClientComposition() |
| 523 | */ |
| 524 | |
| 525 | TEST_F(DisplayTest, anyLayersRequireClientCompositionReturnsFalse) { |
| 526 | EXPECT_CALL(*mLayer1, requiresClientComposition()).WillOnce(Return(false)); |
| 527 | EXPECT_CALL(*mLayer2, requiresClientComposition()).WillOnce(Return(false)); |
| 528 | EXPECT_CALL(*mLayer3, requiresClientComposition()).WillOnce(Return(false)); |
| 529 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 530 | EXPECT_FALSE(mDisplay->anyLayersRequireClientComposition()); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 531 | } |
| 532 | |
| 533 | TEST_F(DisplayTest, anyLayersRequireClientCompositionReturnsTrue) { |
| 534 | EXPECT_CALL(*mLayer1, requiresClientComposition()).WillOnce(Return(false)); |
| 535 | EXPECT_CALL(*mLayer2, requiresClientComposition()).WillOnce(Return(true)); |
| 536 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 537 | EXPECT_TRUE(mDisplay->anyLayersRequireClientComposition()); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 538 | } |
| 539 | |
| 540 | /* |
| 541 | * Display::allLayersRequireClientComposition() |
| 542 | */ |
| 543 | |
| 544 | TEST_F(DisplayTest, allLayersRequireClientCompositionReturnsTrue) { |
| 545 | EXPECT_CALL(*mLayer1, requiresClientComposition()).WillOnce(Return(true)); |
| 546 | EXPECT_CALL(*mLayer2, requiresClientComposition()).WillOnce(Return(true)); |
| 547 | EXPECT_CALL(*mLayer3, requiresClientComposition()).WillOnce(Return(true)); |
| 548 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 549 | EXPECT_TRUE(mDisplay->allLayersRequireClientComposition()); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 550 | } |
| 551 | |
| 552 | TEST_F(DisplayTest, allLayersRequireClientCompositionReturnsFalse) { |
| 553 | EXPECT_CALL(*mLayer1, requiresClientComposition()).WillOnce(Return(true)); |
| 554 | EXPECT_CALL(*mLayer2, requiresClientComposition()).WillOnce(Return(false)); |
| 555 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 556 | EXPECT_FALSE(mDisplay->allLayersRequireClientComposition()); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 557 | } |
| 558 | |
| 559 | /* |
| 560 | * Display::applyChangedTypesToLayers() |
| 561 | */ |
| 562 | |
| 563 | TEST_F(DisplayTest, applyChangedTypesToLayersTakesEarlyOutIfNoChangedLayers) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 564 | mDisplay->applyChangedTypesToLayers(impl::Display::ChangedTypes()); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 565 | } |
| 566 | |
| 567 | TEST_F(DisplayTest, applyChangedTypesToLayersAppliesChanges) { |
| 568 | EXPECT_CALL(*mLayer1, |
| 569 | applyDeviceCompositionTypeChange(Hwc2::IComposerClient::Composition::CLIENT)) |
| 570 | .Times(1); |
| 571 | EXPECT_CALL(*mLayer2, |
| 572 | applyDeviceCompositionTypeChange(Hwc2::IComposerClient::Composition::DEVICE)) |
| 573 | .Times(1); |
| 574 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 575 | mDisplay->applyChangedTypesToLayers(impl::Display::ChangedTypes{ |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 576 | {&mHWC2Layer1, HWC2::Composition::Client}, |
| 577 | {&mHWC2Layer2, HWC2::Composition::Device}, |
| 578 | {&mHWC2LayerUnknown, HWC2::Composition::SolidColor}, |
| 579 | }); |
| 580 | } |
| 581 | |
| 582 | /* |
| 583 | * Display::applyDisplayRequests() |
| 584 | */ |
| 585 | |
| 586 | TEST_F(DisplayTest, applyDisplayRequestsToLayersHandlesNoRequests) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 587 | mDisplay->applyDisplayRequests(static_cast<HWC2::DisplayRequest>(0)); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 588 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 589 | auto& state = mDisplay->getState(); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 590 | EXPECT_FALSE(state.flipClientTarget); |
| 591 | } |
| 592 | |
| 593 | TEST_F(DisplayTest, applyDisplayRequestsToLayersHandlesFlipClientTarget) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 594 | mDisplay->applyDisplayRequests(HWC2::DisplayRequest::FlipClientTarget); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 595 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 596 | auto& state = mDisplay->getState(); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 597 | EXPECT_TRUE(state.flipClientTarget); |
| 598 | } |
| 599 | |
| 600 | TEST_F(DisplayTest, applyDisplayRequestsToLayersHandlesWriteClientTargetToOutput) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 601 | mDisplay->applyDisplayRequests(HWC2::DisplayRequest::WriteClientTargetToOutput); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 602 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 603 | auto& state = mDisplay->getState(); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 604 | EXPECT_FALSE(state.flipClientTarget); |
| 605 | } |
| 606 | |
| 607 | TEST_F(DisplayTest, applyDisplayRequestsToLayersHandlesAllRequestFlagsSet) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 608 | mDisplay->applyDisplayRequests(static_cast<HWC2::DisplayRequest>(~0)); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 609 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 610 | auto& state = mDisplay->getState(); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 611 | EXPECT_TRUE(state.flipClientTarget); |
| 612 | } |
| 613 | |
| 614 | /* |
| 615 | * Display::applyLayerRequestsToLayers() |
| 616 | */ |
| 617 | |
| 618 | TEST_F(DisplayTest, applyLayerRequestsToLayersPreparesAllLayers) { |
| 619 | EXPECT_CALL(*mLayer1, prepareForDeviceLayerRequests()).Times(1); |
| 620 | EXPECT_CALL(*mLayer2, prepareForDeviceLayerRequests()).Times(1); |
| 621 | EXPECT_CALL(*mLayer3, prepareForDeviceLayerRequests()).Times(1); |
| 622 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 623 | mDisplay->applyLayerRequestsToLayers(impl::Display::LayerRequests()); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 624 | } |
| 625 | |
| 626 | TEST_F(DisplayTest, applyLayerRequestsToLayers2) { |
| 627 | EXPECT_CALL(*mLayer1, prepareForDeviceLayerRequests()).Times(1); |
| 628 | EXPECT_CALL(*mLayer2, prepareForDeviceLayerRequests()).Times(1); |
| 629 | EXPECT_CALL(*mLayer3, prepareForDeviceLayerRequests()).Times(1); |
| 630 | |
| 631 | EXPECT_CALL(*mLayer1, |
| 632 | applyDeviceLayerRequest(Hwc2::IComposerClient::LayerRequest::CLEAR_CLIENT_TARGET)) |
| 633 | .Times(1); |
| 634 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 635 | mDisplay->applyLayerRequestsToLayers(impl::Display::LayerRequests{ |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 636 | {&mHWC2Layer1, HWC2::LayerRequest::ClearClientTarget}, |
| 637 | {&mHWC2LayerUnknown, HWC2::LayerRequest::ClearClientTarget}, |
| 638 | }); |
| 639 | } |
| 640 | |
Lloyd Pique | 35fca9d | 2019-02-13 14:24:11 -0800 | [diff] [blame] | 641 | /* |
| 642 | * Display::presentAndGetFrameFences() |
| 643 | */ |
| 644 | |
| 645 | TEST_F(DisplayTest, presentAndGetFrameFencesReturnsNoFencesOnNonHwcDisplay) { |
| 646 | auto nonHwcDisplay{ |
| 647 | impl::createDisplay(mCompositionEngine, DisplayCreationArgsBuilder().build())}; |
| 648 | |
| 649 | auto result = nonHwcDisplay->presentAndGetFrameFences(); |
| 650 | |
| 651 | ASSERT_TRUE(result.presentFence.get()); |
| 652 | EXPECT_FALSE(result.presentFence->isValid()); |
| 653 | EXPECT_EQ(0u, result.layerFences.size()); |
| 654 | } |
| 655 | |
| 656 | TEST_F(DisplayTest, presentAndGetFrameFencesReturnsPresentAndLayerFences) { |
| 657 | sp<Fence> presentFence = new Fence(); |
| 658 | sp<Fence> layer1Fence = new Fence(); |
| 659 | sp<Fence> layer2Fence = new Fence(); |
| 660 | |
| 661 | EXPECT_CALL(mHwComposer, presentAndGetReleaseFences(DEFAULT_DISPLAY_ID)).Times(1); |
| 662 | EXPECT_CALL(mHwComposer, getPresentFence(DEFAULT_DISPLAY_ID)).WillOnce(Return(presentFence)); |
| 663 | EXPECT_CALL(mHwComposer, getLayerReleaseFence(DEFAULT_DISPLAY_ID, &mHWC2Layer1)) |
| 664 | .WillOnce(Return(layer1Fence)); |
| 665 | EXPECT_CALL(mHwComposer, getLayerReleaseFence(DEFAULT_DISPLAY_ID, &mHWC2Layer2)) |
| 666 | .WillOnce(Return(layer2Fence)); |
| 667 | EXPECT_CALL(mHwComposer, clearReleaseFences(DEFAULT_DISPLAY_ID)).Times(1); |
| 668 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 669 | auto result = mDisplay->presentAndGetFrameFences(); |
Lloyd Pique | 35fca9d | 2019-02-13 14:24:11 -0800 | [diff] [blame] | 670 | |
| 671 | EXPECT_EQ(presentFence, result.presentFence); |
| 672 | |
| 673 | EXPECT_EQ(2u, result.layerFences.size()); |
| 674 | ASSERT_EQ(1, result.layerFences.count(&mHWC2Layer1)); |
| 675 | EXPECT_EQ(layer1Fence, result.layerFences[&mHWC2Layer1]); |
| 676 | ASSERT_EQ(1, result.layerFences.count(&mHWC2Layer2)); |
| 677 | EXPECT_EQ(layer2Fence, result.layerFences[&mHWC2Layer2]); |
| 678 | } |
| 679 | |
Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 680 | /* |
| 681 | * Display::setExpensiveRenderingExpected() |
| 682 | */ |
| 683 | |
| 684 | TEST_F(DisplayTest, setExpensiveRenderingExpectedForwardsToPowerAdvisor) { |
| 685 | EXPECT_CALL(mPowerAdvisor, setExpensiveRenderingExpected(DEFAULT_DISPLAY_ID, true)).Times(1); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 686 | mDisplay->setExpensiveRenderingExpected(true); |
Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 687 | |
| 688 | EXPECT_CALL(mPowerAdvisor, setExpensiveRenderingExpected(DEFAULT_DISPLAY_ID, false)).Times(1); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 689 | mDisplay->setExpensiveRenderingExpected(false); |
Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 690 | } |
| 691 | |
Lloyd Pique | d3d6988 | 2019-02-28 16:03:46 -0800 | [diff] [blame] | 692 | /* |
| 693 | * Display::finishFrame() |
| 694 | */ |
| 695 | |
| 696 | TEST_F(DisplayTest, finishFrameDoesNotSkipCompositionIfNotDirtyOnHwcDisplay) { |
| 697 | mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>(); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 698 | mDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface)); |
Lloyd Pique | d3d6988 | 2019-02-28 16:03:46 -0800 | [diff] [blame] | 699 | |
| 700 | // We expect no calls to queueBuffer if composition was skipped. |
| 701 | EXPECT_CALL(*renderSurface, queueBuffer(_)).Times(1); |
| 702 | |
Lloyd Pique | a76ce46 | 2020-01-14 13:06:37 -0800 | [diff] [blame^] | 703 | // Expect a call to signal no expensive rendering since there is no client composition. |
| 704 | EXPECT_CALL(mPowerAdvisor, setExpensiveRenderingExpected(DEFAULT_DISPLAY_ID, false)); |
| 705 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 706 | mDisplay->editState().isEnabled = true; |
| 707 | mDisplay->editState().usesClientComposition = false; |
| 708 | mDisplay->editState().viewport = Rect(0, 0, 1, 1); |
| 709 | mDisplay->editState().dirtyRegion = Region::INVALID_REGION; |
Lloyd Pique | d3d6988 | 2019-02-28 16:03:46 -0800 | [diff] [blame] | 710 | |
| 711 | CompositionRefreshArgs refreshArgs; |
| 712 | refreshArgs.repaintEverything = false; |
| 713 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 714 | mDisplay->finishFrame(refreshArgs); |
Lloyd Pique | d3d6988 | 2019-02-28 16:03:46 -0800 | [diff] [blame] | 715 | } |
| 716 | |
| 717 | TEST_F(DisplayTest, finishFrameSkipsCompositionIfNotDirty) { |
| 718 | std::shared_ptr<impl::Display> nonHwcDisplay{ |
| 719 | impl::createDisplay(mCompositionEngine, DisplayCreationArgsBuilder().build())}; |
| 720 | |
| 721 | mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>(); |
| 722 | nonHwcDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface)); |
| 723 | |
| 724 | // We expect no calls to queueBuffer if composition was skipped. |
| 725 | EXPECT_CALL(*renderSurface, queueBuffer(_)).Times(0); |
| 726 | |
| 727 | nonHwcDisplay->editState().isEnabled = true; |
| 728 | nonHwcDisplay->editState().usesClientComposition = false; |
| 729 | nonHwcDisplay->editState().viewport = Rect(0, 0, 1, 1); |
| 730 | nonHwcDisplay->editState().dirtyRegion = Region::INVALID_REGION; |
| 731 | |
| 732 | CompositionRefreshArgs refreshArgs; |
| 733 | refreshArgs.repaintEverything = false; |
| 734 | |
| 735 | nonHwcDisplay->finishFrame(refreshArgs); |
| 736 | } |
| 737 | |
| 738 | TEST_F(DisplayTest, finishFramePerformsCompositionIfDirty) { |
| 739 | std::shared_ptr<impl::Display> nonHwcDisplay{ |
| 740 | impl::createDisplay(mCompositionEngine, DisplayCreationArgsBuilder().build())}; |
| 741 | |
| 742 | mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>(); |
| 743 | nonHwcDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface)); |
| 744 | |
| 745 | // We expect a single call to queueBuffer when composition is not skipped. |
| 746 | EXPECT_CALL(*renderSurface, queueBuffer(_)).Times(1); |
| 747 | |
| 748 | nonHwcDisplay->editState().isEnabled = true; |
| 749 | nonHwcDisplay->editState().usesClientComposition = false; |
| 750 | nonHwcDisplay->editState().viewport = Rect(0, 0, 1, 1); |
| 751 | nonHwcDisplay->editState().dirtyRegion = Region(Rect(0, 0, 1, 1)); |
| 752 | |
| 753 | CompositionRefreshArgs refreshArgs; |
| 754 | refreshArgs.repaintEverything = false; |
| 755 | |
| 756 | nonHwcDisplay->finishFrame(refreshArgs); |
| 757 | } |
| 758 | |
| 759 | TEST_F(DisplayTest, finishFramePerformsCompositionIfRepaintEverything) { |
| 760 | std::shared_ptr<impl::Display> nonHwcDisplay{ |
| 761 | impl::createDisplay(mCompositionEngine, DisplayCreationArgsBuilder().build())}; |
| 762 | |
| 763 | mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>(); |
| 764 | nonHwcDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface)); |
| 765 | |
| 766 | // We expect a single call to queueBuffer when composition is not skipped. |
| 767 | EXPECT_CALL(*renderSurface, queueBuffer(_)).Times(1); |
| 768 | |
| 769 | nonHwcDisplay->editState().isEnabled = true; |
| 770 | nonHwcDisplay->editState().usesClientComposition = false; |
| 771 | nonHwcDisplay->editState().viewport = Rect(0, 0, 1, 1); |
| 772 | nonHwcDisplay->editState().dirtyRegion = Region::INVALID_REGION; |
| 773 | |
| 774 | CompositionRefreshArgs refreshArgs; |
| 775 | refreshArgs.repaintEverything = true; |
| 776 | |
| 777 | nonHwcDisplay->finishFrame(refreshArgs); |
| 778 | } |
| 779 | |
Lloyd Pique | c660755 | 2019-12-02 17:57:39 -0800 | [diff] [blame] | 780 | /* |
| 781 | * Display functional tests |
| 782 | */ |
| 783 | |
| 784 | struct DisplayFunctionalTest : public testing::Test { |
| 785 | class Display : public impl::Display { |
| 786 | public: |
| 787 | explicit Display(const compositionengine::DisplayCreationArgs& args) |
| 788 | : impl::Display(args) {} |
| 789 | |
| 790 | using impl::Display::injectOutputLayerForTest; |
| 791 | virtual void injectOutputLayerForTest(std::unique_ptr<compositionengine::OutputLayer>) = 0; |
| 792 | }; |
| 793 | |
| 794 | static std::shared_ptr<Display> createDisplay( |
| 795 | const compositionengine::CompositionEngine& compositionEngine, |
| 796 | compositionengine::DisplayCreationArgs&& args) { |
| 797 | return impl::createDisplayTemplated<Display>(compositionEngine, args); |
| 798 | } |
| 799 | |
| 800 | DisplayFunctionalTest() { |
| 801 | EXPECT_CALL(mCompositionEngine, getHwComposer()).WillRepeatedly(ReturnRef(mHwComposer)); |
| 802 | |
| 803 | mDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface)); |
| 804 | } |
| 805 | |
| 806 | NiceMock<android::mock::HWComposer> mHwComposer; |
| 807 | NiceMock<Hwc2::mock::PowerAdvisor> mPowerAdvisor; |
| 808 | NiceMock<mock::CompositionEngine> mCompositionEngine; |
| 809 | sp<mock::NativeWindow> mNativeWindow = new NiceMock<mock::NativeWindow>(); |
| 810 | sp<mock::DisplaySurface> mDisplaySurface = new NiceMock<mock::DisplaySurface>(); |
| 811 | std::shared_ptr<Display> mDisplay = createDisplay(mCompositionEngine, |
| 812 | DisplayCreationArgsBuilder() |
| 813 | .setDisplayId(DEFAULT_DISPLAY_ID) |
| 814 | .setPowerAdvisor(&mPowerAdvisor) |
| 815 | .build()); |
| 816 | impl::RenderSurface* mRenderSurface = |
| 817 | new impl::RenderSurface{mCompositionEngine, *mDisplay, |
| 818 | RenderSurfaceCreationArgs{DEFAULT_DISPLAY_WIDTH, |
| 819 | DEFAULT_DISPLAY_HEIGHT, mNativeWindow, |
| 820 | mDisplaySurface}}; |
| 821 | }; |
| 822 | |
| 823 | TEST_F(DisplayFunctionalTest, postFramebufferCriticalCallsAreOrdered) { |
| 824 | InSequence seq; |
| 825 | |
| 826 | mDisplay->editState().isEnabled = true; |
| 827 | |
| 828 | EXPECT_CALL(mHwComposer, presentAndGetReleaseFences(_)); |
| 829 | EXPECT_CALL(*mDisplaySurface, onFrameCommitted()); |
| 830 | |
| 831 | mDisplay->postFramebuffer(); |
| 832 | } |
| 833 | |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 834 | } // namespace |
| 835 | } // namespace android::compositionengine |