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