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