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