Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -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 | |
| 17 | #include <cmath> |
| 18 | |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 19 | #include <android-base/stringprintf.h> |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 20 | #include <compositionengine/LayerFECompositionState.h> |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 21 | #include <compositionengine/impl/Output.h> |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 22 | #include <compositionengine/impl/OutputCompositionState.h> |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 23 | #include <compositionengine/impl/OutputLayerCompositionState.h> |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 24 | #include <compositionengine/mock/CompositionEngine.h> |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 25 | #include <compositionengine/mock/DisplayColorProfile.h> |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 26 | #include <compositionengine/mock/Layer.h> |
| 27 | #include <compositionengine/mock/LayerFE.h> |
| 28 | #include <compositionengine/mock/OutputLayer.h> |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 29 | #include <compositionengine/mock/RenderSurface.h> |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 30 | #include <gtest/gtest.h> |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 31 | #include <renderengine/mock/RenderEngine.h> |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 32 | #include <ui/Rect.h> |
| 33 | #include <ui/Region.h> |
| 34 | |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 35 | #include "CallOrderStateMachineHelper.h" |
Lloyd Pique | 07178e3 | 2019-11-19 19:15:26 -0800 | [diff] [blame] | 36 | #include "MockHWC2.h" |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 37 | #include "RegionMatcher.h" |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 38 | |
| 39 | namespace android::compositionengine { |
| 40 | namespace { |
| 41 | |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 42 | using testing::_; |
Lloyd Pique | 03561a6 | 2019-11-19 18:34:52 -0800 | [diff] [blame] | 43 | using testing::ByMove; |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 44 | using testing::DoAll; |
Lloyd Pique | 07178e3 | 2019-11-19 19:15:26 -0800 | [diff] [blame] | 45 | using testing::Eq; |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 46 | using testing::InSequence; |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 47 | using testing::Mock; |
Lloyd Pique | 07178e3 | 2019-11-19 19:15:26 -0800 | [diff] [blame] | 48 | using testing::Property; |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 49 | using testing::Ref; |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 50 | using testing::Return; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 51 | using testing::ReturnRef; |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 52 | using testing::SetArgPointee; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 53 | using testing::StrictMock; |
| 54 | |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 55 | constexpr auto TR_IDENT = 0u; |
| 56 | constexpr auto TR_ROT_90 = HAL_TRANSFORM_ROT_90; |
| 57 | |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 58 | const mat4 kIdentity; |
| 59 | const mat4 kNonIdentityHalf = mat4() * 0.5; |
| 60 | const mat4 kNonIdentityQuarter = mat4() * 0.25; |
| 61 | |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 62 | constexpr OutputColorSetting kVendorSpecifiedOutputColorSetting = |
| 63 | static_cast<OutputColorSetting>(0x100); |
| 64 | |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 65 | struct OutputPartialMockBase : public impl::Output { |
| 66 | // compositionengine::Output overrides |
| 67 | const OutputCompositionState& getState() const override { return mState; } |
| 68 | OutputCompositionState& editState() override { return mState; } |
| 69 | |
| 70 | // Use mocks for all the remaining virtual functions |
| 71 | // not implemented by the base implementation class. |
| 72 | MOCK_CONST_METHOD0(getOutputLayerCount, size_t()); |
| 73 | MOCK_CONST_METHOD1(getOutputLayerOrderedByZByIndex, compositionengine::OutputLayer*(size_t)); |
| 74 | MOCK_METHOD3(ensureOutputLayer, |
| 75 | compositionengine::OutputLayer*(std::optional<size_t>, |
| 76 | const std::shared_ptr<compositionengine::Layer>&, |
| 77 | const sp<LayerFE>&)); |
| 78 | MOCK_METHOD0(finalizePendingOutputLayers, void()); |
| 79 | MOCK_METHOD0(clearOutputLayers, void()); |
| 80 | MOCK_CONST_METHOD1(dumpState, void(std::string&)); |
| 81 | MOCK_CONST_METHOD0(getCompositionEngine, const CompositionEngine&()); |
| 82 | MOCK_METHOD2(injectOutputLayerForTest, |
| 83 | compositionengine::OutputLayer*(const std::shared_ptr<compositionengine::Layer>&, |
| 84 | const sp<LayerFE>&)); |
| 85 | MOCK_METHOD1(injectOutputLayerForTest, void(std::unique_ptr<OutputLayer>)); |
| 86 | |
| 87 | impl::OutputCompositionState mState; |
| 88 | }; |
| 89 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 90 | struct OutputTest : public testing::Test { |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 91 | class Output : public impl::Output { |
| 92 | public: |
| 93 | using impl::Output::injectOutputLayerForTest; |
| 94 | virtual void injectOutputLayerForTest(std::unique_ptr<compositionengine::OutputLayer>) = 0; |
| 95 | }; |
| 96 | |
| 97 | static std::shared_ptr<Output> createOutput( |
| 98 | const compositionengine::CompositionEngine& compositionEngine) { |
| 99 | return impl::createOutputTemplated<Output>(compositionEngine); |
| 100 | } |
| 101 | |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 102 | OutputTest() { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 103 | mOutput->setDisplayColorProfileForTest( |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 104 | std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile)); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 105 | mOutput->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface)); |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 106 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 107 | mOutput->editState().bounds = kDefaultDisplaySize; |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 108 | } |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 109 | |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 110 | static const Rect kDefaultDisplaySize; |
| 111 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 112 | StrictMock<mock::CompositionEngine> mCompositionEngine; |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 113 | mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>(); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 114 | mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>(); |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 115 | std::shared_ptr<Output> mOutput = createOutput(mCompositionEngine); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 116 | }; |
| 117 | |
Lloyd Pique | c0ee6ba | 2019-11-14 12:55:53 -0800 | [diff] [blame] | 118 | // Extension of the base test useful for checking interactions with the LayerFE |
| 119 | // functions to latch composition state. |
| 120 | struct OutputLatchFEStateTest : public OutputTest { |
| 121 | OutputLatchFEStateTest() { |
| 122 | EXPECT_CALL(*mOutputLayer1, getLayer()).WillRepeatedly(ReturnRef(mLayer1)); |
| 123 | EXPECT_CALL(*mOutputLayer2, getLayer()).WillRepeatedly(ReturnRef(mLayer2)); |
| 124 | EXPECT_CALL(*mOutputLayer3, getLayer()).WillRepeatedly(ReturnRef(mLayer3)); |
| 125 | |
| 126 | EXPECT_CALL(*mOutputLayer1, getLayerFE()).WillRepeatedly(ReturnRef(mLayer1FE)); |
| 127 | EXPECT_CALL(*mOutputLayer2, getLayerFE()).WillRepeatedly(ReturnRef(mLayer2FE)); |
| 128 | EXPECT_CALL(*mOutputLayer3, getLayerFE()).WillRepeatedly(ReturnRef(mLayer3FE)); |
| 129 | |
| 130 | EXPECT_CALL(mLayer1, editFEState()).WillRepeatedly(ReturnRef(mLayer1FEState)); |
| 131 | EXPECT_CALL(mLayer2, editFEState()).WillRepeatedly(ReturnRef(mLayer2FEState)); |
| 132 | EXPECT_CALL(mLayer3, editFEState()).WillRepeatedly(ReturnRef(mLayer3FEState)); |
| 133 | } |
| 134 | |
| 135 | void injectLayer(std::unique_ptr<mock::OutputLayer> layer) { |
| 136 | mOutput->injectOutputLayerForTest(std::unique_ptr<OutputLayer>(layer.release())); |
| 137 | } |
| 138 | |
| 139 | std::unique_ptr<mock::OutputLayer> mOutputLayer1{new StrictMock<mock::OutputLayer>}; |
| 140 | std::unique_ptr<mock::OutputLayer> mOutputLayer2{new StrictMock<mock::OutputLayer>}; |
| 141 | std::unique_ptr<mock::OutputLayer> mOutputLayer3{new StrictMock<mock::OutputLayer>}; |
| 142 | |
| 143 | StrictMock<mock::Layer> mLayer1; |
| 144 | StrictMock<mock::Layer> mLayer2; |
| 145 | StrictMock<mock::Layer> mLayer3; |
| 146 | |
| 147 | StrictMock<mock::LayerFE> mLayer1FE; |
| 148 | StrictMock<mock::LayerFE> mLayer2FE; |
| 149 | StrictMock<mock::LayerFE> mLayer3FE; |
| 150 | |
| 151 | LayerFECompositionState mLayer1FEState; |
| 152 | LayerFECompositionState mLayer2FEState; |
| 153 | LayerFECompositionState mLayer3FEState; |
| 154 | }; |
| 155 | |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 156 | const Rect OutputTest::kDefaultDisplaySize{100, 200}; |
| 157 | |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 158 | using ColorProfile = compositionengine::Output::ColorProfile; |
| 159 | |
| 160 | void dumpColorProfile(ColorProfile profile, std::string& result, const char* name) { |
| 161 | android::base::StringAppendF(&result, "%s (%s[%d] %s[%d] %s[%d] %s[%d]) ", name, |
| 162 | toString(profile.mode).c_str(), profile.mode, |
| 163 | toString(profile.dataspace).c_str(), profile.dataspace, |
| 164 | toString(profile.renderIntent).c_str(), profile.renderIntent, |
| 165 | toString(profile.colorSpaceAgnosticDataspace).c_str(), |
| 166 | profile.colorSpaceAgnosticDataspace); |
| 167 | } |
| 168 | |
| 169 | // Checks for a ColorProfile match |
| 170 | MATCHER_P(ColorProfileEq, expected, "") { |
| 171 | std::string buf; |
| 172 | buf.append("ColorProfiles are not equal\n"); |
| 173 | dumpColorProfile(expected, buf, "expected value"); |
| 174 | dumpColorProfile(arg, buf, "actual value"); |
| 175 | *result_listener << buf; |
| 176 | |
| 177 | return (expected.mode == arg.mode) && (expected.dataspace == arg.dataspace) && |
| 178 | (expected.renderIntent == arg.renderIntent) && |
| 179 | (expected.colorSpaceAgnosticDataspace == arg.colorSpaceAgnosticDataspace); |
| 180 | } |
| 181 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 182 | /* |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 183 | * Basic construction |
| 184 | */ |
| 185 | |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 186 | TEST_F(OutputTest, canInstantiateOutput) { |
| 187 | // The validation check checks each required component. |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 188 | EXPECT_CALL(*mDisplayColorProfile, isValid()).WillOnce(Return(true)); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 189 | EXPECT_CALL(*mRenderSurface, isValid()).WillOnce(Return(true)); |
| 190 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 191 | EXPECT_TRUE(mOutput->isValid()); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 192 | |
| 193 | // If we take away the required components, it is no longer valid. |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 194 | mOutput->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>()); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 195 | |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 196 | EXPECT_CALL(*mDisplayColorProfile, isValid()).WillOnce(Return(true)); |
| 197 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 198 | EXPECT_FALSE(mOutput->isValid()); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 199 | } |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 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 | * Output::setCompositionEnabled() |
| 203 | */ |
| 204 | |
| 205 | TEST_F(OutputTest, setCompositionEnabledDoesNothingIfAlreadyEnabled) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 206 | mOutput->editState().isEnabled = true; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 207 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 208 | mOutput->setCompositionEnabled(true); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 209 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 210 | EXPECT_TRUE(mOutput->getState().isEnabled); |
| 211 | EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region())); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | TEST_F(OutputTest, setCompositionEnabledSetsEnabledAndDirtiesEntireOutput) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 215 | mOutput->editState().isEnabled = false; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 216 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 217 | mOutput->setCompositionEnabled(true); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 218 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 219 | EXPECT_TRUE(mOutput->getState().isEnabled); |
| 220 | EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize))); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | TEST_F(OutputTest, setCompositionEnabledSetsDisabledAndDirtiesEntireOutput) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 224 | mOutput->editState().isEnabled = true; |
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 | mOutput->setCompositionEnabled(false); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 227 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 228 | EXPECT_FALSE(mOutput->getState().isEnabled); |
| 229 | EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize))); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 230 | } |
| 231 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 232 | /* |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 233 | * Output::setProjection() |
| 234 | */ |
| 235 | |
| 236 | TEST_F(OutputTest, setProjectionTriviallyWorks) { |
| 237 | const ui::Transform transform{ui::Transform::ROT_180}; |
| 238 | const int32_t orientation = 123; |
| 239 | const Rect frame{1, 2, 3, 4}; |
| 240 | const Rect viewport{5, 6, 7, 8}; |
| 241 | const Rect scissor{9, 10, 11, 12}; |
| 242 | const bool needsFiltering = true; |
| 243 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 244 | mOutput->setProjection(transform, orientation, frame, viewport, scissor, needsFiltering); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 245 | |
Lloyd Pique | ea62928 | 2019-12-03 15:57:10 -0800 | [diff] [blame^] | 246 | EXPECT_THAT(mOutput->getState().transform, transform); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 247 | EXPECT_EQ(orientation, mOutput->getState().orientation); |
| 248 | EXPECT_EQ(frame, mOutput->getState().frame); |
| 249 | EXPECT_EQ(viewport, mOutput->getState().viewport); |
| 250 | EXPECT_EQ(scissor, mOutput->getState().scissor); |
| 251 | EXPECT_EQ(needsFiltering, mOutput->getState().needsFiltering); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 252 | } |
| 253 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 254 | /* |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 255 | * Output::setBounds() |
| 256 | */ |
| 257 | |
| 258 | TEST_F(OutputTest, setBoundsSetsSizeAndDirtiesEntireOutput) { |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 259 | const ui::Size displaySize{200, 400}; |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 260 | |
| 261 | EXPECT_CALL(*mRenderSurface, setDisplaySize(displaySize)).Times(1); |
| 262 | EXPECT_CALL(*mRenderSurface, getSize()).WillOnce(ReturnRef(displaySize)); |
| 263 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 264 | mOutput->setBounds(displaySize); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 265 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 266 | EXPECT_EQ(Rect(displaySize), mOutput->getState().bounds); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 267 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 268 | EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(Rect(displaySize)))); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 269 | } |
| 270 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 271 | /* |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 272 | * Output::setLayerStackFilter() |
| 273 | */ |
| 274 | |
| 275 | TEST_F(OutputTest, setLayerStackFilterSetsFilterAndDirtiesEntireOutput) { |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 276 | const uint32_t layerStack = 123u; |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 277 | mOutput->setLayerStackFilter(layerStack, true); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 278 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 279 | EXPECT_TRUE(mOutput->getState().layerStackInternal); |
| 280 | EXPECT_EQ(layerStack, mOutput->getState().layerStackId); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 281 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 282 | EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize))); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 283 | } |
| 284 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 285 | /* |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 286 | * Output::setColorTransform |
| 287 | */ |
| 288 | |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 289 | TEST_F(OutputTest, setColorTransformWithNoChangeFlaggedSkipsUpdates) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 290 | mOutput->editState().colorTransformMatrix = kIdentity; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 291 | |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 292 | // If no colorTransformMatrix is set the update should be skipped. |
| 293 | CompositionRefreshArgs refreshArgs; |
| 294 | refreshArgs.colorTransformMatrix = std::nullopt; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 295 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 296 | mOutput->setColorTransform(refreshArgs); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 297 | |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 298 | // The internal state should be unchanged |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 299 | EXPECT_EQ(kIdentity, mOutput->getState().colorTransformMatrix); |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 300 | |
| 301 | // No dirty region should be set |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 302 | EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region())); |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 303 | } |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 304 | |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 305 | TEST_F(OutputTest, setColorTransformWithNoActualChangeSkipsUpdates) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 306 | mOutput->editState().colorTransformMatrix = kIdentity; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 307 | |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 308 | // Attempting to set the same colorTransformMatrix that is already set should |
| 309 | // also skip the update. |
| 310 | CompositionRefreshArgs refreshArgs; |
| 311 | refreshArgs.colorTransformMatrix = kIdentity; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 312 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 313 | mOutput->setColorTransform(refreshArgs); |
Lloyd Pique | 77f79a2 | 2019-04-29 15:55:40 -0700 | [diff] [blame] | 314 | |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 315 | // The internal state should be unchanged |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 316 | EXPECT_EQ(kIdentity, mOutput->getState().colorTransformMatrix); |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 317 | |
| 318 | // No dirty region should be set |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 319 | EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region())); |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | TEST_F(OutputTest, setColorTransformPerformsUpdateToIdentity) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 323 | mOutput->editState().colorTransformMatrix = kNonIdentityHalf; |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 324 | |
| 325 | // Setting a different colorTransformMatrix should perform the update. |
| 326 | CompositionRefreshArgs refreshArgs; |
| 327 | refreshArgs.colorTransformMatrix = kIdentity; |
| 328 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 329 | mOutput->setColorTransform(refreshArgs); |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 330 | |
| 331 | // The internal state should have been updated |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 332 | EXPECT_EQ(kIdentity, mOutput->getState().colorTransformMatrix); |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 333 | |
| 334 | // The dirtyRegion should be set to the full display size |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 335 | EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize))); |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 336 | } |
Lloyd Pique | 77f79a2 | 2019-04-29 15:55:40 -0700 | [diff] [blame] | 337 | |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 338 | TEST_F(OutputTest, setColorTransformPerformsUpdateForIdentityToHalf) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 339 | mOutput->editState().colorTransformMatrix = kIdentity; |
Lloyd Pique | 77f79a2 | 2019-04-29 15:55:40 -0700 | [diff] [blame] | 340 | |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 341 | // Setting a different colorTransformMatrix should perform the update. |
| 342 | CompositionRefreshArgs refreshArgs; |
| 343 | refreshArgs.colorTransformMatrix = kNonIdentityHalf; |
Lloyd Pique | 77f79a2 | 2019-04-29 15:55:40 -0700 | [diff] [blame] | 344 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 345 | mOutput->setColorTransform(refreshArgs); |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 346 | |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 347 | // The internal state should have been updated |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 348 | EXPECT_EQ(kNonIdentityHalf, mOutput->getState().colorTransformMatrix); |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 349 | |
| 350 | // The dirtyRegion should be set to the full display size |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 351 | EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize))); |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 352 | } |
| 353 | |
| 354 | TEST_F(OutputTest, setColorTransformPerformsUpdateForHalfToQuarter) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 355 | mOutput->editState().colorTransformMatrix = kNonIdentityHalf; |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 356 | |
| 357 | // Setting a different colorTransformMatrix should perform the update. |
| 358 | CompositionRefreshArgs refreshArgs; |
| 359 | refreshArgs.colorTransformMatrix = kNonIdentityQuarter; |
| 360 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 361 | mOutput->setColorTransform(refreshArgs); |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 362 | |
| 363 | // The internal state should have been updated |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 364 | EXPECT_EQ(kNonIdentityQuarter, mOutput->getState().colorTransformMatrix); |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 365 | |
| 366 | // The dirtyRegion should be set to the full display size |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 367 | EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize))); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 368 | } |
| 369 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 370 | /* |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 371 | * Output::setColorProfile |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 372 | */ |
| 373 | |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 374 | using OutputSetColorProfileTest = OutputTest; |
| 375 | |
| 376 | TEST_F(OutputSetColorProfileTest, setsStateAndDirtiesOutputIfChanged) { |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 377 | using ColorProfile = Output::ColorProfile; |
| 378 | |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 379 | EXPECT_CALL(*mDisplayColorProfile, |
| 380 | getTargetDataspace(ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3, |
| 381 | ui::Dataspace::UNKNOWN)) |
| 382 | .WillOnce(Return(ui::Dataspace::UNKNOWN)); |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 383 | EXPECT_CALL(*mRenderSurface, setBufferDataspace(ui::Dataspace::DISPLAY_P3)).Times(1); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 384 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 385 | mOutput->setColorProfile(ColorProfile{ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3, |
| 386 | ui::RenderIntent::TONE_MAP_COLORIMETRIC, |
| 387 | ui::Dataspace::UNKNOWN}); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 388 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 389 | EXPECT_EQ(ui::ColorMode::DISPLAY_P3, mOutput->getState().colorMode); |
| 390 | EXPECT_EQ(ui::Dataspace::DISPLAY_P3, mOutput->getState().dataspace); |
| 391 | EXPECT_EQ(ui::RenderIntent::TONE_MAP_COLORIMETRIC, mOutput->getState().renderIntent); |
| 392 | EXPECT_EQ(ui::Dataspace::UNKNOWN, mOutput->getState().targetDataspace); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 393 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 394 | EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize))); |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 395 | } |
| 396 | |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 397 | TEST_F(OutputSetColorProfileTest, doesNothingIfNoChange) { |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 398 | using ColorProfile = Output::ColorProfile; |
| 399 | |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 400 | EXPECT_CALL(*mDisplayColorProfile, |
| 401 | getTargetDataspace(ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3, |
| 402 | ui::Dataspace::UNKNOWN)) |
| 403 | .WillOnce(Return(ui::Dataspace::UNKNOWN)); |
| 404 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 405 | mOutput->editState().colorMode = ui::ColorMode::DISPLAY_P3; |
| 406 | mOutput->editState().dataspace = ui::Dataspace::DISPLAY_P3; |
| 407 | mOutput->editState().renderIntent = ui::RenderIntent::TONE_MAP_COLORIMETRIC; |
| 408 | mOutput->editState().targetDataspace = ui::Dataspace::UNKNOWN; |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 409 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 410 | mOutput->setColorProfile(ColorProfile{ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3, |
| 411 | ui::RenderIntent::TONE_MAP_COLORIMETRIC, |
| 412 | ui::Dataspace::UNKNOWN}); |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 413 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 414 | EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region())); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 415 | } |
| 416 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 417 | /* |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 418 | * Output::setRenderSurface() |
| 419 | */ |
| 420 | |
| 421 | TEST_F(OutputTest, setRenderSurfaceResetsBounds) { |
| 422 | const ui::Size newDisplaySize{640, 480}; |
| 423 | |
| 424 | mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>(); |
| 425 | EXPECT_CALL(*renderSurface, getSize()).WillOnce(ReturnRef(newDisplaySize)); |
| 426 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 427 | mOutput->setRenderSurface(std::unique_ptr<RenderSurface>(renderSurface)); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 428 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 429 | EXPECT_EQ(Rect(newDisplaySize), mOutput->getState().bounds); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 430 | } |
| 431 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 432 | /* |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 433 | * Output::getDirtyRegion() |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 434 | */ |
| 435 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 436 | TEST_F(OutputTest, getDirtyRegionWithRepaintEverythingTrue) { |
| 437 | const Rect viewport{100, 200}; |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 438 | mOutput->editState().viewport = viewport; |
| 439 | mOutput->editState().dirtyRegion.set(50, 300); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 440 | |
| 441 | { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 442 | Region result = mOutput->getDirtyRegion(true); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 443 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 444 | EXPECT_THAT(result, RegionEq(Region(viewport))); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 445 | } |
| 446 | } |
| 447 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 448 | TEST_F(OutputTest, getDirtyRegionWithRepaintEverythingFalse) { |
| 449 | const Rect viewport{100, 200}; |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 450 | mOutput->editState().viewport = viewport; |
| 451 | mOutput->editState().dirtyRegion.set(50, 300); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 452 | |
| 453 | { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 454 | Region result = mOutput->getDirtyRegion(false); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 455 | |
| 456 | // The dirtyRegion should be clipped to the display bounds. |
| 457 | EXPECT_THAT(result, RegionEq(Region(Rect(50, 200)))); |
| 458 | } |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 459 | } |
| 460 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 461 | /* |
Lloyd Pique | ef36b00 | 2019-01-23 17:52:04 -0800 | [diff] [blame] | 462 | * Output::belongsInOutput() |
| 463 | */ |
| 464 | |
| 465 | TEST_F(OutputTest, belongsInOutputFiltersAsExpected) { |
| 466 | const uint32_t layerStack1 = 123u; |
| 467 | const uint32_t layerStack2 = 456u; |
| 468 | |
| 469 | // If the output accepts layerStack1 and internal-only layers.... |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 470 | mOutput->setLayerStackFilter(layerStack1, true); |
Lloyd Pique | ef36b00 | 2019-01-23 17:52:04 -0800 | [diff] [blame] | 471 | |
Lloyd Pique | c668734 | 2019-03-07 21:34:57 -0800 | [diff] [blame] | 472 | // A layer with no layerStack does not belong to it, internal-only or not. |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 473 | EXPECT_FALSE(mOutput->belongsInOutput(std::nullopt, false)); |
| 474 | EXPECT_FALSE(mOutput->belongsInOutput(std::nullopt, true)); |
Lloyd Pique | c668734 | 2019-03-07 21:34:57 -0800 | [diff] [blame] | 475 | |
Lloyd Pique | ef36b00 | 2019-01-23 17:52:04 -0800 | [diff] [blame] | 476 | // Any layer with layerStack1 belongs to it, internal-only or not. |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 477 | EXPECT_TRUE(mOutput->belongsInOutput(layerStack1, false)); |
| 478 | EXPECT_TRUE(mOutput->belongsInOutput(layerStack1, true)); |
| 479 | EXPECT_FALSE(mOutput->belongsInOutput(layerStack2, true)); |
| 480 | EXPECT_FALSE(mOutput->belongsInOutput(layerStack2, false)); |
Lloyd Pique | ef36b00 | 2019-01-23 17:52:04 -0800 | [diff] [blame] | 481 | |
| 482 | // If the output accepts layerStack21 but not internal-only layers... |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 483 | mOutput->setLayerStackFilter(layerStack1, false); |
Lloyd Pique | ef36b00 | 2019-01-23 17:52:04 -0800 | [diff] [blame] | 484 | |
| 485 | // Only non-internal layers with layerStack1 belong to it. |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 486 | EXPECT_TRUE(mOutput->belongsInOutput(layerStack1, false)); |
| 487 | EXPECT_FALSE(mOutput->belongsInOutput(layerStack1, true)); |
| 488 | EXPECT_FALSE(mOutput->belongsInOutput(layerStack2, true)); |
| 489 | EXPECT_FALSE(mOutput->belongsInOutput(layerStack2, false)); |
Lloyd Pique | ef36b00 | 2019-01-23 17:52:04 -0800 | [diff] [blame] | 490 | } |
| 491 | |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 492 | TEST_F(OutputTest, belongsInOutputFiltersLayersAsExpected) { |
| 493 | StrictMock<mock::Layer> layer; |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 494 | LayerFECompositionState layerFEState; |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 495 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 496 | EXPECT_CALL(layer, getFEState()).WillRepeatedly(ReturnRef(layerFEState)); |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 497 | |
| 498 | const uint32_t layerStack1 = 123u; |
| 499 | const uint32_t layerStack2 = 456u; |
| 500 | |
| 501 | // If the output accepts layerStack1 and internal-only layers.... |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 502 | mOutput->setLayerStackFilter(layerStack1, true); |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 503 | |
| 504 | // A null layer pointer does not belong to the output |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 505 | EXPECT_FALSE(mOutput->belongsInOutput(nullptr)); |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 506 | |
| 507 | // A layer with no layerStack does not belong to it, internal-only or not. |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 508 | layerFEState.layerStackId = std::nullopt; |
| 509 | layerFEState.internalOnly = false; |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 510 | EXPECT_FALSE(mOutput->belongsInOutput(&layer)); |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 511 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 512 | layerFEState.layerStackId = std::nullopt; |
| 513 | layerFEState.internalOnly = true; |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 514 | EXPECT_FALSE(mOutput->belongsInOutput(&layer)); |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 515 | |
| 516 | // Any layer with layerStack1 belongs to it, internal-only or not. |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 517 | layerFEState.layerStackId = layerStack1; |
| 518 | layerFEState.internalOnly = false; |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 519 | EXPECT_TRUE(mOutput->belongsInOutput(&layer)); |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 520 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 521 | layerFEState.layerStackId = layerStack1; |
| 522 | layerFEState.internalOnly = true; |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 523 | EXPECT_TRUE(mOutput->belongsInOutput(&layer)); |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 524 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 525 | layerFEState.layerStackId = layerStack2; |
| 526 | layerFEState.internalOnly = true; |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 527 | EXPECT_FALSE(mOutput->belongsInOutput(&layer)); |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 528 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 529 | layerFEState.layerStackId = layerStack2; |
| 530 | layerFEState.internalOnly = false; |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 531 | EXPECT_FALSE(mOutput->belongsInOutput(&layer)); |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 532 | |
| 533 | // If the output accepts layerStack1 but not internal-only layers... |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 534 | mOutput->setLayerStackFilter(layerStack1, false); |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 535 | |
| 536 | // A null layer pointer does not belong to the output |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 537 | EXPECT_FALSE(mOutput->belongsInOutput(nullptr)); |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 538 | |
| 539 | // Only non-internal layers with layerStack1 belong to it. |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 540 | layerFEState.layerStackId = layerStack1; |
| 541 | layerFEState.internalOnly = false; |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 542 | EXPECT_TRUE(mOutput->belongsInOutput(&layer)); |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 543 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 544 | layerFEState.layerStackId = layerStack1; |
| 545 | layerFEState.internalOnly = true; |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 546 | EXPECT_FALSE(mOutput->belongsInOutput(&layer)); |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 547 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 548 | layerFEState.layerStackId = layerStack2; |
| 549 | layerFEState.internalOnly = true; |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 550 | EXPECT_FALSE(mOutput->belongsInOutput(&layer)); |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 551 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 552 | layerFEState.layerStackId = layerStack2; |
| 553 | layerFEState.internalOnly = false; |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 554 | EXPECT_FALSE(mOutput->belongsInOutput(&layer)); |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 555 | } |
| 556 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 557 | /* |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 558 | * Output::getOutputLayerForLayer() |
| 559 | */ |
| 560 | |
| 561 | TEST_F(OutputTest, getOutputLayerForLayerWorks) { |
| 562 | mock::OutputLayer* outputLayer1 = new StrictMock<mock::OutputLayer>(); |
| 563 | mock::OutputLayer* outputLayer2 = new StrictMock<mock::OutputLayer>(); |
| 564 | |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 565 | mOutput->injectOutputLayerForTest(std::unique_ptr<OutputLayer>(outputLayer1)); |
| 566 | mOutput->injectOutputLayerForTest(nullptr); |
| 567 | mOutput->injectOutputLayerForTest(std::unique_ptr<OutputLayer>(outputLayer2)); |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 568 | |
| 569 | StrictMock<mock::Layer> layer; |
| 570 | StrictMock<mock::Layer> otherLayer; |
| 571 | |
| 572 | // If the input layer matches the first OutputLayer, it will be returned. |
| 573 | EXPECT_CALL(*outputLayer1, getLayer()).WillOnce(ReturnRef(layer)); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 574 | EXPECT_EQ(outputLayer1, mOutput->getOutputLayerForLayer(&layer)); |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 575 | |
| 576 | // If the input layer matches the second OutputLayer, it will be returned. |
| 577 | EXPECT_CALL(*outputLayer1, getLayer()).WillOnce(ReturnRef(otherLayer)); |
| 578 | EXPECT_CALL(*outputLayer2, getLayer()).WillOnce(ReturnRef(layer)); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 579 | EXPECT_EQ(outputLayer2, mOutput->getOutputLayerForLayer(&layer)); |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 580 | |
| 581 | // If the input layer does not match an output layer, null will be returned. |
| 582 | EXPECT_CALL(*outputLayer1, getLayer()).WillOnce(ReturnRef(otherLayer)); |
| 583 | EXPECT_CALL(*outputLayer2, getLayer()).WillOnce(ReturnRef(otherLayer)); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 584 | EXPECT_EQ(nullptr, mOutput->getOutputLayerForLayer(&layer)); |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 585 | } |
| 586 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 587 | /* |
Lloyd Pique | c9e6003 | 2019-11-14 11:47:26 -0800 | [diff] [blame] | 588 | * Output::setReleasedLayers() |
| 589 | */ |
| 590 | |
| 591 | using OutputSetReleasedLayersTest = OutputTest; |
| 592 | |
| 593 | TEST_F(OutputSetReleasedLayersTest, setReleasedLayersTakesGivenLayers) { |
| 594 | sp<StrictMock<mock::LayerFE>> layer1FE{new StrictMock<mock::LayerFE>()}; |
| 595 | sp<StrictMock<mock::LayerFE>> layer2FE{new StrictMock<mock::LayerFE>()}; |
| 596 | sp<StrictMock<mock::LayerFE>> layer3FE{new StrictMock<mock::LayerFE>()}; |
| 597 | |
| 598 | Output::ReleasedLayers layers; |
| 599 | layers.push_back(layer1FE); |
| 600 | layers.push_back(layer2FE); |
| 601 | layers.push_back(layer3FE); |
| 602 | |
| 603 | mOutput->setReleasedLayers(std::move(layers)); |
| 604 | |
| 605 | const auto& setLayers = mOutput->getReleasedLayersForTest(); |
| 606 | ASSERT_EQ(3u, setLayers.size()); |
| 607 | ASSERT_EQ(layer1FE.get(), setLayers[0].promote().get()); |
| 608 | ASSERT_EQ(layer2FE.get(), setLayers[1].promote().get()); |
| 609 | ASSERT_EQ(layer3FE.get(), setLayers[2].promote().get()); |
| 610 | } |
| 611 | |
| 612 | /* |
Lloyd Pique | c0ee6ba | 2019-11-14 12:55:53 -0800 | [diff] [blame] | 613 | * Output::updateLayerStateFromFE() |
| 614 | */ |
| 615 | |
| 616 | using OutputUpdateLayerStateFromFETest = OutputLatchFEStateTest; |
| 617 | |
| 618 | TEST_F(OutputUpdateLayerStateFromFETest, handlesNoOutputLayerCase) { |
| 619 | CompositionRefreshArgs refreshArgs; |
| 620 | |
| 621 | mOutput->updateLayerStateFromFE(refreshArgs); |
| 622 | } |
| 623 | |
| 624 | TEST_F(OutputUpdateLayerStateFromFETest, latchesContentStateForAllContainedLayers) { |
| 625 | EXPECT_CALL(mLayer1FE, |
| 626 | latchCompositionState(Ref(mLayer1FEState), LayerFE::StateSubset::Content)); |
| 627 | EXPECT_CALL(mLayer2FE, |
| 628 | latchCompositionState(Ref(mLayer2FEState), LayerFE::StateSubset::Content)); |
| 629 | EXPECT_CALL(mLayer3FE, |
| 630 | latchCompositionState(Ref(mLayer3FEState), LayerFE::StateSubset::Content)); |
| 631 | |
| 632 | // Note: Must be performed after any expectations on these mocks |
| 633 | injectLayer(std::move(mOutputLayer1)); |
| 634 | injectLayer(std::move(mOutputLayer2)); |
| 635 | injectLayer(std::move(mOutputLayer3)); |
| 636 | |
| 637 | CompositionRefreshArgs refreshArgs; |
| 638 | refreshArgs.updatingGeometryThisFrame = false; |
| 639 | |
| 640 | mOutput->updateLayerStateFromFE(refreshArgs); |
| 641 | } |
| 642 | |
| 643 | TEST_F(OutputUpdateLayerStateFromFETest, latchesGeometryAndContentStateForAllContainedLayers) { |
| 644 | EXPECT_CALL(mLayer1FE, |
| 645 | latchCompositionState(Ref(mLayer1FEState), |
| 646 | LayerFE::StateSubset::GeometryAndContent)); |
| 647 | EXPECT_CALL(mLayer2FE, |
| 648 | latchCompositionState(Ref(mLayer2FEState), |
| 649 | LayerFE::StateSubset::GeometryAndContent)); |
| 650 | EXPECT_CALL(mLayer3FE, |
| 651 | latchCompositionState(Ref(mLayer3FEState), |
| 652 | LayerFE::StateSubset::GeometryAndContent)); |
| 653 | |
| 654 | // Note: Must be performed after any expectations on these mocks |
| 655 | injectLayer(std::move(mOutputLayer1)); |
| 656 | injectLayer(std::move(mOutputLayer2)); |
| 657 | injectLayer(std::move(mOutputLayer3)); |
| 658 | |
| 659 | CompositionRefreshArgs refreshArgs; |
| 660 | refreshArgs.updatingGeometryThisFrame = true; |
| 661 | |
| 662 | mOutput->updateLayerStateFromFE(refreshArgs); |
| 663 | } |
| 664 | |
| 665 | /* |
Alec Mouri | f9a2a2c | 2019-11-12 12:46:02 -0800 | [diff] [blame] | 666 | * Output::updateAndWriteCompositionState() |
| 667 | */ |
| 668 | |
Lloyd Pique | ef63b61 | 2019-11-14 13:19:56 -0800 | [diff] [blame] | 669 | using OutputUpdateAndWriteCompositionStateTest = OutputLatchFEStateTest; |
| 670 | |
| 671 | TEST_F(OutputUpdateAndWriteCompositionStateTest, doesNothingIfLayers) { |
| 672 | mOutput->editState().isEnabled = true; |
Alec Mouri | f9a2a2c | 2019-11-12 12:46:02 -0800 | [diff] [blame] | 673 | |
| 674 | CompositionRefreshArgs args; |
| 675 | mOutput->updateAndWriteCompositionState(args); |
| 676 | } |
| 677 | |
Lloyd Pique | ef63b61 | 2019-11-14 13:19:56 -0800 | [diff] [blame] | 678 | TEST_F(OutputUpdateAndWriteCompositionStateTest, doesNothingIfOutputNotEnabled) { |
| 679 | mOutput->editState().isEnabled = false; |
Alec Mouri | f9a2a2c | 2019-11-12 12:46:02 -0800 | [diff] [blame] | 680 | |
Lloyd Pique | ef63b61 | 2019-11-14 13:19:56 -0800 | [diff] [blame] | 681 | injectLayer(std::move(mOutputLayer1)); |
| 682 | injectLayer(std::move(mOutputLayer2)); |
| 683 | injectLayer(std::move(mOutputLayer3)); |
| 684 | |
| 685 | CompositionRefreshArgs args; |
| 686 | mOutput->updateAndWriteCompositionState(args); |
| 687 | } |
| 688 | |
| 689 | TEST_F(OutputUpdateAndWriteCompositionStateTest, updatesLayerContentForAllLayers) { |
| 690 | EXPECT_CALL(*mOutputLayer1, updateCompositionState(false, false)); |
| 691 | EXPECT_CALL(*mOutputLayer1, writeStateToHWC(false)); |
| 692 | EXPECT_CALL(*mOutputLayer2, updateCompositionState(false, false)); |
| 693 | EXPECT_CALL(*mOutputLayer2, writeStateToHWC(false)); |
| 694 | EXPECT_CALL(*mOutputLayer3, updateCompositionState(false, false)); |
| 695 | EXPECT_CALL(*mOutputLayer3, writeStateToHWC(false)); |
| 696 | |
| 697 | injectLayer(std::move(mOutputLayer1)); |
| 698 | injectLayer(std::move(mOutputLayer2)); |
| 699 | injectLayer(std::move(mOutputLayer3)); |
| 700 | |
| 701 | mOutput->editState().isEnabled = true; |
| 702 | |
| 703 | CompositionRefreshArgs args; |
| 704 | args.updatingGeometryThisFrame = false; |
| 705 | args.devOptForceClientComposition = false; |
| 706 | mOutput->updateAndWriteCompositionState(args); |
| 707 | } |
| 708 | |
| 709 | TEST_F(OutputUpdateAndWriteCompositionStateTest, updatesLayerGeometryAndContentForAllLayers) { |
| 710 | EXPECT_CALL(*mOutputLayer1, updateCompositionState(true, false)); |
| 711 | EXPECT_CALL(*mOutputLayer1, writeStateToHWC(true)); |
| 712 | EXPECT_CALL(*mOutputLayer2, updateCompositionState(true, false)); |
| 713 | EXPECT_CALL(*mOutputLayer2, writeStateToHWC(true)); |
| 714 | EXPECT_CALL(*mOutputLayer3, updateCompositionState(true, false)); |
| 715 | EXPECT_CALL(*mOutputLayer3, writeStateToHWC(true)); |
| 716 | |
| 717 | injectLayer(std::move(mOutputLayer1)); |
| 718 | injectLayer(std::move(mOutputLayer2)); |
| 719 | injectLayer(std::move(mOutputLayer3)); |
| 720 | |
| 721 | mOutput->editState().isEnabled = true; |
Alec Mouri | f9a2a2c | 2019-11-12 12:46:02 -0800 | [diff] [blame] | 722 | |
| 723 | CompositionRefreshArgs args; |
| 724 | args.updatingGeometryThisFrame = true; |
Lloyd Pique | ef63b61 | 2019-11-14 13:19:56 -0800 | [diff] [blame] | 725 | args.devOptForceClientComposition = false; |
| 726 | mOutput->updateAndWriteCompositionState(args); |
| 727 | } |
| 728 | |
| 729 | TEST_F(OutputUpdateAndWriteCompositionStateTest, forcesClientCompositionForAllLayers) { |
| 730 | EXPECT_CALL(*mOutputLayer1, updateCompositionState(false, true)); |
| 731 | EXPECT_CALL(*mOutputLayer1, writeStateToHWC(false)); |
| 732 | EXPECT_CALL(*mOutputLayer2, updateCompositionState(false, true)); |
| 733 | EXPECT_CALL(*mOutputLayer2, writeStateToHWC(false)); |
| 734 | EXPECT_CALL(*mOutputLayer3, updateCompositionState(false, true)); |
| 735 | EXPECT_CALL(*mOutputLayer3, writeStateToHWC(false)); |
| 736 | |
| 737 | injectLayer(std::move(mOutputLayer1)); |
| 738 | injectLayer(std::move(mOutputLayer2)); |
| 739 | injectLayer(std::move(mOutputLayer3)); |
| 740 | |
| 741 | mOutput->editState().isEnabled = true; |
| 742 | |
| 743 | CompositionRefreshArgs args; |
| 744 | args.updatingGeometryThisFrame = false; |
Alec Mouri | f9a2a2c | 2019-11-12 12:46:02 -0800 | [diff] [blame] | 745 | args.devOptForceClientComposition = true; |
| 746 | mOutput->updateAndWriteCompositionState(args); |
| 747 | } |
| 748 | |
| 749 | /* |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 750 | * Output::prepareFrame() |
| 751 | */ |
| 752 | |
| 753 | struct OutputPrepareFrameTest : public testing::Test { |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 754 | struct OutputPartialMock : public OutputPartialMockBase { |
Lloyd Pique | 739afaf | 2019-11-21 16:40:05 -0800 | [diff] [blame] | 755 | // Sets up the helper functions called by the function under test to use |
| 756 | // mock implementations. |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 757 | MOCK_METHOD0(chooseCompositionStrategy, void()); |
| 758 | }; |
| 759 | |
| 760 | OutputPrepareFrameTest() { |
| 761 | mOutput.setDisplayColorProfileForTest( |
| 762 | std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile)); |
| 763 | mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface)); |
| 764 | } |
| 765 | |
| 766 | StrictMock<mock::CompositionEngine> mCompositionEngine; |
| 767 | mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>(); |
| 768 | mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>(); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 769 | StrictMock<OutputPartialMock> mOutput; |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 770 | }; |
| 771 | |
| 772 | TEST_F(OutputPrepareFrameTest, takesEarlyOutIfNotEnabled) { |
| 773 | mOutput.editState().isEnabled = false; |
| 774 | |
| 775 | mOutput.prepareFrame(); |
| 776 | } |
| 777 | |
| 778 | TEST_F(OutputPrepareFrameTest, delegatesToChooseCompositionStrategyAndRenderSurface) { |
| 779 | mOutput.editState().isEnabled = true; |
| 780 | mOutput.editState().usesClientComposition = false; |
| 781 | mOutput.editState().usesDeviceComposition = true; |
| 782 | |
| 783 | EXPECT_CALL(mOutput, chooseCompositionStrategy()).Times(1); |
| 784 | EXPECT_CALL(*mRenderSurface, prepareFrame(false, true)); |
| 785 | |
| 786 | mOutput.prepareFrame(); |
| 787 | } |
| 788 | |
| 789 | // Note: Use OutputTest and not OutputPrepareFrameTest, so the real |
| 790 | // base chooseCompositionStrategy() is invoked. |
| 791 | TEST_F(OutputTest, prepareFrameSetsClientCompositionOnlyByDefault) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 792 | mOutput->editState().isEnabled = true; |
| 793 | mOutput->editState().usesClientComposition = false; |
| 794 | mOutput->editState().usesDeviceComposition = true; |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 795 | |
| 796 | EXPECT_CALL(*mRenderSurface, prepareFrame(true, false)); |
| 797 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 798 | mOutput->prepareFrame(); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 799 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 800 | EXPECT_TRUE(mOutput->getState().usesClientComposition); |
| 801 | EXPECT_FALSE(mOutput->getState().usesDeviceComposition); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 802 | } |
| 803 | |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 804 | /* |
Lloyd Pique | b62cebc | 2019-11-20 18:31:52 -0800 | [diff] [blame] | 805 | * Output::prepare() |
| 806 | */ |
| 807 | |
| 808 | struct OutputPrepareTest : public testing::Test { |
| 809 | struct OutputPartialMock : public OutputPartialMockBase { |
| 810 | // Sets up the helper functions called by the function under test to use |
| 811 | // mock implementations. |
| 812 | MOCK_METHOD2(rebuildLayerStacks, |
| 813 | void(const compositionengine::CompositionRefreshArgs&, |
| 814 | compositionengine::LayerFESet&)); |
| 815 | }; |
| 816 | |
| 817 | StrictMock<OutputPartialMock> mOutput; |
| 818 | CompositionRefreshArgs mRefreshArgs; |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 819 | LayerFESet mGeomSnapshots; |
Lloyd Pique | b62cebc | 2019-11-20 18:31:52 -0800 | [diff] [blame] | 820 | }; |
| 821 | |
| 822 | TEST_F(OutputPrepareTest, justInvokesRebuildLayerStacks) { |
| 823 | InSequence seq; |
| 824 | EXPECT_CALL(mOutput, rebuildLayerStacks(Ref(mRefreshArgs), Ref(mGeomSnapshots))); |
| 825 | |
| 826 | mOutput.prepare(mRefreshArgs, mGeomSnapshots); |
| 827 | } |
| 828 | |
| 829 | /* |
| 830 | * Output::rebuildLayerStacks() |
| 831 | */ |
| 832 | |
| 833 | struct OutputRebuildLayerStacksTest : public testing::Test { |
| 834 | struct OutputPartialMock : public OutputPartialMockBase { |
| 835 | // Sets up the helper functions called by the function under test to use |
| 836 | // mock implementations. |
| 837 | MOCK_METHOD2(collectVisibleLayers, |
| 838 | void(const compositionengine::CompositionRefreshArgs&, |
| 839 | compositionengine::Output::CoverageState&)); |
| 840 | }; |
| 841 | |
| 842 | OutputRebuildLayerStacksTest() { |
| 843 | mOutput.mState.isEnabled = true; |
| 844 | mOutput.mState.transform = kIdentityTransform; |
| 845 | mOutput.mState.bounds = kOutputBounds; |
| 846 | |
| 847 | mRefreshArgs.updatingOutputGeometryThisFrame = true; |
| 848 | |
| 849 | mCoverageAboveCoveredLayersToSet = Region(Rect(0, 0, 10, 10)); |
| 850 | |
| 851 | EXPECT_CALL(mOutput, collectVisibleLayers(Ref(mRefreshArgs), _)) |
| 852 | .WillRepeatedly(Invoke(this, &OutputRebuildLayerStacksTest::setTestCoverageValues)); |
| 853 | } |
| 854 | |
| 855 | void setTestCoverageValues(const CompositionRefreshArgs&, |
| 856 | compositionengine::Output::CoverageState& state) { |
| 857 | state.aboveCoveredLayers = mCoverageAboveCoveredLayersToSet; |
| 858 | state.aboveOpaqueLayers = mCoverageAboveOpaqueLayersToSet; |
| 859 | state.dirtyRegion = mCoverageDirtyRegionToSet; |
| 860 | } |
| 861 | |
| 862 | static const ui::Transform kIdentityTransform; |
| 863 | static const ui::Transform kRotate90Transform; |
| 864 | static const Rect kOutputBounds; |
| 865 | |
| 866 | StrictMock<OutputPartialMock> mOutput; |
| 867 | CompositionRefreshArgs mRefreshArgs; |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 868 | LayerFESet mGeomSnapshots; |
Lloyd Pique | b62cebc | 2019-11-20 18:31:52 -0800 | [diff] [blame] | 869 | Region mCoverageAboveCoveredLayersToSet; |
| 870 | Region mCoverageAboveOpaqueLayersToSet; |
| 871 | Region mCoverageDirtyRegionToSet; |
| 872 | }; |
| 873 | |
| 874 | const ui::Transform OutputRebuildLayerStacksTest::kIdentityTransform{TR_IDENT, 1920, 1080}; |
| 875 | const ui::Transform OutputRebuildLayerStacksTest::kRotate90Transform{TR_ROT_90, 1920, 1080}; |
| 876 | const Rect OutputRebuildLayerStacksTest::kOutputBounds{0, 0, 1920, 1080}; |
| 877 | |
| 878 | TEST_F(OutputRebuildLayerStacksTest, doesNothingIfNotEnabled) { |
| 879 | mOutput.mState.isEnabled = false; |
| 880 | |
| 881 | mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots); |
| 882 | } |
| 883 | |
| 884 | TEST_F(OutputRebuildLayerStacksTest, doesNothingIfNotUpdatingGeometryThisFrame) { |
| 885 | mRefreshArgs.updatingOutputGeometryThisFrame = false; |
| 886 | |
| 887 | mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots); |
| 888 | } |
| 889 | |
| 890 | TEST_F(OutputRebuildLayerStacksTest, computesUndefinedRegionWithNoRotationAndFullCoverage) { |
| 891 | mOutput.mState.transform = kIdentityTransform; |
| 892 | |
| 893 | mCoverageAboveOpaqueLayersToSet = Region(Rect(0, 0, 1920, 1080)); |
| 894 | |
| 895 | mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots); |
| 896 | |
| 897 | EXPECT_THAT(mOutput.mState.undefinedRegion, RegionEq(Region(Rect(0, 0, 0, 0)))); |
| 898 | } |
| 899 | |
| 900 | TEST_F(OutputRebuildLayerStacksTest, computesUndefinedRegionWithNoRotationAndPartialCoverage) { |
| 901 | mOutput.mState.transform = kIdentityTransform; |
| 902 | |
| 903 | mCoverageAboveOpaqueLayersToSet = Region(Rect(0, 0, 960, 1080)); |
| 904 | |
| 905 | mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots); |
| 906 | |
| 907 | EXPECT_THAT(mOutput.mState.undefinedRegion, RegionEq(Region(Rect(960, 0, 1920, 1080)))); |
| 908 | } |
| 909 | |
| 910 | TEST_F(OutputRebuildLayerStacksTest, computesUndefinedRegionWith90RotationAndFullCoverage) { |
| 911 | mOutput.mState.transform = kRotate90Transform; |
| 912 | |
| 913 | mCoverageAboveOpaqueLayersToSet = Region(Rect(0, 0, 1080, 1920)); |
| 914 | |
| 915 | mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots); |
| 916 | |
| 917 | EXPECT_THAT(mOutput.mState.undefinedRegion, RegionEq(Region(Rect(0, 0, 0, 0)))); |
| 918 | } |
| 919 | |
| 920 | TEST_F(OutputRebuildLayerStacksTest, computesUndefinedRegionWith90RotationAndPartialCoverage) { |
| 921 | mOutput.mState.transform = kRotate90Transform; |
| 922 | |
| 923 | mCoverageAboveOpaqueLayersToSet = Region(Rect(0, 0, 1080, 960)); |
| 924 | |
| 925 | mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots); |
| 926 | |
| 927 | EXPECT_THAT(mOutput.mState.undefinedRegion, RegionEq(Region(Rect(0, 0, 960, 1080)))); |
| 928 | } |
| 929 | |
| 930 | TEST_F(OutputRebuildLayerStacksTest, addsToDirtyRegionWithNoRotation) { |
| 931 | mOutput.mState.transform = kIdentityTransform; |
| 932 | mOutput.mState.dirtyRegion = Region(Rect(960, 0, 1920, 1080)); |
| 933 | |
| 934 | mCoverageDirtyRegionToSet = Region(Rect(0, 0, 960, 1080)); |
| 935 | |
| 936 | mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots); |
| 937 | |
| 938 | EXPECT_THAT(mOutput.mState.dirtyRegion, RegionEq(Region(Rect(0, 0, 1920, 1080)))); |
| 939 | } |
| 940 | |
| 941 | TEST_F(OutputRebuildLayerStacksTest, addsToDirtyRegionWith90Rotation) { |
| 942 | mOutput.mState.transform = kRotate90Transform; |
| 943 | mOutput.mState.dirtyRegion = Region(Rect(0, 960, 1080, 1920)); |
| 944 | |
| 945 | mCoverageDirtyRegionToSet = Region(Rect(0, 0, 1080, 960)); |
| 946 | |
| 947 | mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots); |
| 948 | |
| 949 | EXPECT_THAT(mOutput.mState.dirtyRegion, RegionEq(Region(Rect(0, 0, 1080, 1920)))); |
| 950 | } |
| 951 | |
| 952 | /* |
| 953 | * Output::collectVisibleLayers() |
| 954 | */ |
| 955 | |
Lloyd Pique | 1ef9322 | 2019-11-21 16:41:53 -0800 | [diff] [blame] | 956 | struct OutputCollectVisibleLayersTest : public testing::Test { |
| 957 | struct OutputPartialMock : public OutputPartialMockBase { |
| 958 | // Sets up the helper functions called by the function under test to use |
| 959 | // mock implementations. |
| 960 | MOCK_METHOD2(ensureOutputLayerIfVisible, |
| 961 | void(std::shared_ptr<compositionengine::Layer>, |
| 962 | compositionengine::Output::CoverageState&)); |
| 963 | MOCK_METHOD1(setReleasedLayers, void(const compositionengine::CompositionRefreshArgs&)); |
| 964 | MOCK_METHOD0(finalizePendingOutputLayers, void()); |
| 965 | }; |
| 966 | |
| 967 | struct Layer { |
| 968 | Layer() { |
| 969 | EXPECT_CALL(outputLayer, getState()).WillRepeatedly(ReturnRef(outputLayerState)); |
| 970 | EXPECT_CALL(outputLayer, editState()).WillRepeatedly(ReturnRef(outputLayerState)); |
| 971 | } |
| 972 | |
| 973 | StrictMock<mock::OutputLayer> outputLayer; |
| 974 | std::shared_ptr<StrictMock<mock::Layer>> layer{new StrictMock<mock::Layer>()}; |
| 975 | impl::OutputLayerCompositionState outputLayerState; |
| 976 | }; |
| 977 | |
| 978 | OutputCollectVisibleLayersTest() { |
| 979 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(3)); |
| 980 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0)) |
| 981 | .WillRepeatedly(Return(&mLayer1.outputLayer)); |
| 982 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(1)) |
| 983 | .WillRepeatedly(Return(&mLayer2.outputLayer)); |
| 984 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(2)) |
| 985 | .WillRepeatedly(Return(&mLayer3.outputLayer)); |
| 986 | |
| 987 | mRefreshArgs.layers.push_back(mLayer1.layer); |
| 988 | mRefreshArgs.layers.push_back(mLayer2.layer); |
| 989 | mRefreshArgs.layers.push_back(mLayer3.layer); |
| 990 | } |
| 991 | |
| 992 | StrictMock<OutputPartialMock> mOutput; |
| 993 | CompositionRefreshArgs mRefreshArgs; |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 994 | LayerFESet mGeomSnapshots; |
| 995 | Output::CoverageState mCoverageState{mGeomSnapshots}; |
Lloyd Pique | 1ef9322 | 2019-11-21 16:41:53 -0800 | [diff] [blame] | 996 | Layer mLayer1; |
| 997 | Layer mLayer2; |
| 998 | Layer mLayer3; |
| 999 | }; |
| 1000 | |
| 1001 | TEST_F(OutputCollectVisibleLayersTest, doesMinimalWorkIfNoLayers) { |
| 1002 | mRefreshArgs.layers.clear(); |
| 1003 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(0)); |
| 1004 | |
| 1005 | EXPECT_CALL(mOutput, setReleasedLayers(Ref(mRefreshArgs))); |
| 1006 | EXPECT_CALL(mOutput, finalizePendingOutputLayers()); |
| 1007 | |
| 1008 | mOutput.collectVisibleLayers(mRefreshArgs, mCoverageState); |
| 1009 | } |
| 1010 | |
| 1011 | TEST_F(OutputCollectVisibleLayersTest, processesCandidateLayersReversedAndSetsOutputLayerZ) { |
| 1012 | // Enforce a call order sequence for this test. |
| 1013 | InSequence seq; |
| 1014 | |
| 1015 | // Layer coverage is evaluated from front to back! |
| 1016 | EXPECT_CALL(mOutput, ensureOutputLayerIfVisible(Eq(mLayer3.layer), Ref(mCoverageState))); |
| 1017 | EXPECT_CALL(mOutput, ensureOutputLayerIfVisible(Eq(mLayer2.layer), Ref(mCoverageState))); |
| 1018 | EXPECT_CALL(mOutput, ensureOutputLayerIfVisible(Eq(mLayer1.layer), Ref(mCoverageState))); |
| 1019 | |
| 1020 | EXPECT_CALL(mOutput, setReleasedLayers(Ref(mRefreshArgs))); |
| 1021 | EXPECT_CALL(mOutput, finalizePendingOutputLayers()); |
| 1022 | |
| 1023 | mOutput.collectVisibleLayers(mRefreshArgs, mCoverageState); |
| 1024 | |
| 1025 | // Ensure all output layers have been assigned a simple/flattened z-order. |
| 1026 | EXPECT_EQ(0u, mLayer1.outputLayerState.z); |
| 1027 | EXPECT_EQ(1u, mLayer2.outputLayerState.z); |
| 1028 | EXPECT_EQ(2u, mLayer3.outputLayerState.z); |
| 1029 | } |
Lloyd Pique | b62cebc | 2019-11-20 18:31:52 -0800 | [diff] [blame] | 1030 | |
| 1031 | /* |
| 1032 | * Output::ensureOutputLayerIfVisible() |
| 1033 | */ |
| 1034 | |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1035 | struct OutputEnsureOutputLayerIfVisibleTest : public testing::Test { |
| 1036 | struct OutputPartialMock : public OutputPartialMockBase { |
| 1037 | // Sets up the helper functions called by the function under test to use |
| 1038 | // mock implementations. |
| 1039 | MOCK_CONST_METHOD1(belongsInOutput, bool(const compositionengine::Layer*)); |
| 1040 | MOCK_CONST_METHOD1(getOutputLayerOrderedByZByIndex, OutputLayer*(size_t)); |
| 1041 | MOCK_METHOD3(ensureOutputLayer, |
| 1042 | compositionengine::OutputLayer*( |
| 1043 | std::optional<size_t>, |
| 1044 | const std::shared_ptr<compositionengine::Layer>&, const sp<LayerFE>&)); |
| 1045 | }; |
| 1046 | |
| 1047 | OutputEnsureOutputLayerIfVisibleTest() { |
| 1048 | EXPECT_CALL(*mLayer, getLayerFE()).WillRepeatedly(Return(mLayerFE)); |
| 1049 | EXPECT_CALL(*mLayer, getFEState()).WillRepeatedly(ReturnRef(mLayerFEState)); |
| 1050 | EXPECT_CALL(*mLayer, editFEState()).WillRepeatedly(ReturnRef(mLayerFEState)); |
| 1051 | |
| 1052 | EXPECT_CALL(mOutput, belongsInOutput(mLayer.get())).WillRepeatedly(Return(true)); |
| 1053 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(1)); |
| 1054 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0u)) |
| 1055 | .WillRepeatedly(Return(&mOutputLayer)); |
| 1056 | |
| 1057 | EXPECT_CALL(mOutputLayer, getState()).WillRepeatedly(ReturnRef(mOutputLayerState)); |
| 1058 | EXPECT_CALL(mOutputLayer, editState()).WillRepeatedly(ReturnRef(mOutputLayerState)); |
| 1059 | EXPECT_CALL(mOutputLayer, getLayer()).WillRepeatedly(ReturnRef(*mLayer.get())); |
| 1060 | |
| 1061 | mOutput.mState.bounds = Rect(0, 0, 200, 300); |
| 1062 | mOutput.mState.viewport = Rect(0, 0, 200, 300); |
| 1063 | mOutput.mState.transform = ui::Transform(TR_IDENT, 200, 300); |
| 1064 | |
| 1065 | mLayerFEState.isVisible = true; |
| 1066 | mLayerFEState.isOpaque = true; |
| 1067 | mLayerFEState.contentDirty = true; |
| 1068 | mLayerFEState.geomLayerBounds = FloatRect{0, 0, 100, 200}; |
| 1069 | mLayerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200); |
| 1070 | mLayerFEState.transparentRegionHint = Region(Rect(0, 0, 100, 100)); |
| 1071 | |
| 1072 | mOutputLayerState.visibleRegion = Region(Rect(0, 0, 50, 200)); |
| 1073 | mOutputLayerState.coveredRegion = Region(Rect(50, 0, 100, 200)); |
| 1074 | |
| 1075 | mGeomSnapshots.insert(mLayerFE); |
| 1076 | } |
| 1077 | |
| 1078 | static const Region kEmptyRegion; |
| 1079 | static const Region kFullBoundsNoRotation; |
| 1080 | static const Region kRightHalfBoundsNoRotation; |
| 1081 | static const Region kLowerHalfBoundsNoRotation; |
| 1082 | static const Region kFullBounds90Rotation; |
| 1083 | |
| 1084 | StrictMock<OutputPartialMock> mOutput; |
| 1085 | LayerFESet mGeomSnapshots; |
| 1086 | Output::CoverageState mCoverageState{mGeomSnapshots}; |
| 1087 | |
| 1088 | std::shared_ptr<mock::Layer> mLayer{new StrictMock<mock::Layer>()}; |
| 1089 | sp<StrictMock<mock::LayerFE>> mLayerFE{new StrictMock<mock::LayerFE>()}; |
| 1090 | LayerFECompositionState mLayerFEState; |
| 1091 | mock::OutputLayer mOutputLayer; |
| 1092 | impl::OutputLayerCompositionState mOutputLayerState; |
| 1093 | }; |
| 1094 | |
| 1095 | const Region OutputEnsureOutputLayerIfVisibleTest::kEmptyRegion = Region(Rect(0, 0, 0, 0)); |
| 1096 | const Region OutputEnsureOutputLayerIfVisibleTest::kFullBoundsNoRotation = |
| 1097 | Region(Rect(0, 0, 100, 200)); |
| 1098 | const Region OutputEnsureOutputLayerIfVisibleTest::kRightHalfBoundsNoRotation = |
| 1099 | Region(Rect(0, 100, 100, 200)); |
| 1100 | const Region OutputEnsureOutputLayerIfVisibleTest::kLowerHalfBoundsNoRotation = |
| 1101 | Region(Rect(50, 0, 100, 200)); |
| 1102 | const Region OutputEnsureOutputLayerIfVisibleTest::kFullBounds90Rotation = |
| 1103 | Region(Rect(0, 0, 200, 100)); |
| 1104 | |
| 1105 | TEST_F(OutputEnsureOutputLayerIfVisibleTest, doesNothingIfNoLayerFE) { |
| 1106 | EXPECT_CALL(*mLayer, getLayerFE).WillOnce(Return(sp<LayerFE>())); |
| 1107 | |
| 1108 | mOutput.ensureOutputLayerIfVisible(mLayer, mCoverageState); |
| 1109 | } |
| 1110 | |
| 1111 | TEST_F(OutputEnsureOutputLayerIfVisibleTest, performsGeomLatchBeforeCheckingIfLayerBelongs) { |
| 1112 | EXPECT_CALL(mOutput, belongsInOutput(mLayer.get())).WillOnce(Return(false)); |
| 1113 | EXPECT_CALL(*mLayerFE.get(), |
| 1114 | latchCompositionState(Ref(mLayerFEState), |
| 1115 | compositionengine::LayerFE::StateSubset::BasicGeometry)); |
| 1116 | |
| 1117 | mGeomSnapshots.clear(); |
| 1118 | |
| 1119 | mOutput.ensureOutputLayerIfVisible(mLayer, mCoverageState); |
| 1120 | } |
| 1121 | |
| 1122 | TEST_F(OutputEnsureOutputLayerIfVisibleTest, |
| 1123 | skipsLatchIfAlreadyLatchedBeforeCheckingIfLayerBelongs) { |
| 1124 | EXPECT_CALL(mOutput, belongsInOutput(mLayer.get())).WillOnce(Return(false)); |
| 1125 | |
| 1126 | mOutput.ensureOutputLayerIfVisible(mLayer, mCoverageState); |
| 1127 | } |
| 1128 | |
| 1129 | TEST_F(OutputEnsureOutputLayerIfVisibleTest, takesEarlyOutIfLayerNotVisible) { |
| 1130 | mLayerFEState.isVisible = false; |
| 1131 | |
| 1132 | mOutput.ensureOutputLayerIfVisible(mLayer, mCoverageState); |
| 1133 | } |
| 1134 | |
| 1135 | TEST_F(OutputEnsureOutputLayerIfVisibleTest, takesEarlyOutIfLayerHasEmptyVisibleRegion) { |
| 1136 | mLayerFEState.geomLayerBounds = FloatRect{0, 0, 0, 0}; |
| 1137 | |
| 1138 | mOutput.ensureOutputLayerIfVisible(mLayer, mCoverageState); |
| 1139 | } |
| 1140 | |
| 1141 | TEST_F(OutputEnsureOutputLayerIfVisibleTest, takesNotSoEarlyOutifDrawRegionEmpty) { |
| 1142 | mOutput.mState.bounds = Rect(0, 0, 0, 0); |
| 1143 | |
| 1144 | mOutput.ensureOutputLayerIfVisible(mLayer, mCoverageState); |
| 1145 | } |
| 1146 | |
| 1147 | TEST_F(OutputEnsureOutputLayerIfVisibleTest, |
| 1148 | handlesCreatingOutputLayerForOpaqueDirtyNotRotatedLayer) { |
| 1149 | mLayerFEState.isOpaque = true; |
| 1150 | mLayerFEState.contentDirty = true; |
| 1151 | mLayerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200); |
| 1152 | |
| 1153 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u)); |
| 1154 | EXPECT_CALL(mOutput, ensureOutputLayer(Eq(std::nullopt), Eq(mLayer), Eq(mLayerFE))) |
| 1155 | .WillOnce(Return(&mOutputLayer)); |
| 1156 | |
| 1157 | mOutput.ensureOutputLayerIfVisible(mLayer, mCoverageState); |
| 1158 | |
| 1159 | EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation)); |
| 1160 | EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation)); |
| 1161 | EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation)); |
| 1162 | |
| 1163 | EXPECT_THAT(mOutputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation)); |
| 1164 | EXPECT_THAT(mOutputLayerState.visibleNonTransparentRegion, RegionEq(kFullBoundsNoRotation)); |
| 1165 | EXPECT_THAT(mOutputLayerState.coveredRegion, RegionEq(kEmptyRegion)); |
| 1166 | EXPECT_THAT(mOutputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation)); |
| 1167 | } |
| 1168 | |
| 1169 | TEST_F(OutputEnsureOutputLayerIfVisibleTest, |
| 1170 | handlesUpdatingOutputLayerForOpaqueDirtyNotRotatedLayer) { |
| 1171 | mLayerFEState.isOpaque = true; |
| 1172 | mLayerFEState.contentDirty = true; |
| 1173 | mLayerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200); |
| 1174 | |
| 1175 | EXPECT_CALL(mOutput, ensureOutputLayer(Eq(0u), Eq(mLayer), Eq(mLayerFE))) |
| 1176 | .WillOnce(Return(&mOutputLayer)); |
| 1177 | |
| 1178 | mOutput.ensureOutputLayerIfVisible(mLayer, mCoverageState); |
| 1179 | |
| 1180 | EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation)); |
| 1181 | EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation)); |
| 1182 | EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation)); |
| 1183 | |
| 1184 | EXPECT_THAT(mOutputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation)); |
| 1185 | EXPECT_THAT(mOutputLayerState.visibleNonTransparentRegion, RegionEq(kFullBoundsNoRotation)); |
| 1186 | EXPECT_THAT(mOutputLayerState.coveredRegion, RegionEq(kEmptyRegion)); |
| 1187 | EXPECT_THAT(mOutputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation)); |
| 1188 | } |
| 1189 | |
| 1190 | TEST_F(OutputEnsureOutputLayerIfVisibleTest, |
| 1191 | handlesCreatingOutputLayerForTransparentDirtyNotRotatedLayer) { |
| 1192 | mLayerFEState.isOpaque = false; |
| 1193 | mLayerFEState.contentDirty = true; |
| 1194 | mLayerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200); |
| 1195 | |
| 1196 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u)); |
| 1197 | EXPECT_CALL(mOutput, ensureOutputLayer(Eq(std::nullopt), Eq(mLayer), Eq(mLayerFE))) |
| 1198 | .WillOnce(Return(&mOutputLayer)); |
| 1199 | |
| 1200 | mOutput.ensureOutputLayerIfVisible(mLayer, mCoverageState); |
| 1201 | |
| 1202 | EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation)); |
| 1203 | EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation)); |
| 1204 | EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kEmptyRegion)); |
| 1205 | |
| 1206 | EXPECT_THAT(mOutputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation)); |
| 1207 | EXPECT_THAT(mOutputLayerState.visibleNonTransparentRegion, |
| 1208 | RegionEq(kRightHalfBoundsNoRotation)); |
| 1209 | EXPECT_THAT(mOutputLayerState.coveredRegion, RegionEq(kEmptyRegion)); |
| 1210 | EXPECT_THAT(mOutputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation)); |
| 1211 | } |
| 1212 | |
| 1213 | TEST_F(OutputEnsureOutputLayerIfVisibleTest, |
| 1214 | handlesUpdatingOutputLayerForTransparentDirtyNotRotatedLayer) { |
| 1215 | mLayerFEState.isOpaque = false; |
| 1216 | mLayerFEState.contentDirty = true; |
| 1217 | mLayerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200); |
| 1218 | |
| 1219 | EXPECT_CALL(mOutput, ensureOutputLayer(Eq(0u), Eq(mLayer), Eq(mLayerFE))) |
| 1220 | .WillOnce(Return(&mOutputLayer)); |
| 1221 | |
| 1222 | mOutput.ensureOutputLayerIfVisible(mLayer, mCoverageState); |
| 1223 | |
| 1224 | EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation)); |
| 1225 | EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation)); |
| 1226 | EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kEmptyRegion)); |
| 1227 | |
| 1228 | EXPECT_THAT(mOutputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation)); |
| 1229 | EXPECT_THAT(mOutputLayerState.visibleNonTransparentRegion, |
| 1230 | RegionEq(kRightHalfBoundsNoRotation)); |
| 1231 | EXPECT_THAT(mOutputLayerState.coveredRegion, RegionEq(kEmptyRegion)); |
| 1232 | EXPECT_THAT(mOutputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation)); |
| 1233 | } |
| 1234 | |
| 1235 | TEST_F(OutputEnsureOutputLayerIfVisibleTest, |
| 1236 | handlesCreatingOutputLayerForOpaqueNonDirtyNotRotatedLayer) { |
| 1237 | mLayerFEState.isOpaque = true; |
| 1238 | mLayerFEState.contentDirty = false; |
| 1239 | mLayerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200); |
| 1240 | |
| 1241 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u)); |
| 1242 | EXPECT_CALL(mOutput, ensureOutputLayer(Eq(std::nullopt), Eq(mLayer), Eq(mLayerFE))) |
| 1243 | .WillOnce(Return(&mOutputLayer)); |
| 1244 | |
| 1245 | mOutput.ensureOutputLayerIfVisible(mLayer, mCoverageState); |
| 1246 | |
| 1247 | EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation)); |
| 1248 | EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation)); |
| 1249 | EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation)); |
| 1250 | |
| 1251 | EXPECT_THAT(mOutputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation)); |
| 1252 | EXPECT_THAT(mOutputLayerState.visibleNonTransparentRegion, RegionEq(kFullBoundsNoRotation)); |
| 1253 | EXPECT_THAT(mOutputLayerState.coveredRegion, RegionEq(kEmptyRegion)); |
| 1254 | EXPECT_THAT(mOutputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation)); |
| 1255 | } |
| 1256 | |
| 1257 | TEST_F(OutputEnsureOutputLayerIfVisibleTest, |
| 1258 | handlesUpdatingOutputLayerForOpaqueNonDirtyNotRotatedLayer) { |
| 1259 | mLayerFEState.isOpaque = true; |
| 1260 | mLayerFEState.contentDirty = false; |
| 1261 | mLayerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200); |
| 1262 | |
| 1263 | EXPECT_CALL(mOutput, ensureOutputLayer(Eq(0u), Eq(mLayer), Eq(mLayerFE))) |
| 1264 | .WillOnce(Return(&mOutputLayer)); |
| 1265 | |
| 1266 | mOutput.ensureOutputLayerIfVisible(mLayer, mCoverageState); |
| 1267 | |
| 1268 | EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kLowerHalfBoundsNoRotation)); |
| 1269 | EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation)); |
| 1270 | EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation)); |
| 1271 | |
| 1272 | EXPECT_THAT(mOutputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation)); |
| 1273 | EXPECT_THAT(mOutputLayerState.visibleNonTransparentRegion, RegionEq(kFullBoundsNoRotation)); |
| 1274 | EXPECT_THAT(mOutputLayerState.coveredRegion, RegionEq(kEmptyRegion)); |
| 1275 | EXPECT_THAT(mOutputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation)); |
| 1276 | } |
| 1277 | |
| 1278 | TEST_F(OutputEnsureOutputLayerIfVisibleTest, |
| 1279 | handlesCreatingOutputLayerForOpaqueDirtyRotated90Layer) { |
| 1280 | mLayerFEState.isOpaque = true; |
| 1281 | mLayerFEState.contentDirty = true; |
| 1282 | mLayerFEState.geomLayerBounds = FloatRect{0, 0, 200, 100}; |
| 1283 | mLayerFEState.geomLayerTransform = ui::Transform(TR_ROT_90, 100, 200); |
| 1284 | mOutputLayerState.visibleRegion = Region(Rect(0, 0, 100, 100)); |
| 1285 | mOutputLayerState.coveredRegion = Region(Rect(100, 0, 200, 100)); |
| 1286 | |
| 1287 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u)); |
| 1288 | EXPECT_CALL(mOutput, ensureOutputLayer(Eq(std::nullopt), Eq(mLayer), Eq(mLayerFE))) |
| 1289 | .WillOnce(Return(&mOutputLayer)); |
| 1290 | |
| 1291 | mOutput.ensureOutputLayerIfVisible(mLayer, mCoverageState); |
| 1292 | |
| 1293 | EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation)); |
| 1294 | EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation)); |
| 1295 | EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation)); |
| 1296 | |
| 1297 | EXPECT_THAT(mOutputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation)); |
| 1298 | EXPECT_THAT(mOutputLayerState.visibleNonTransparentRegion, RegionEq(kFullBoundsNoRotation)); |
| 1299 | EXPECT_THAT(mOutputLayerState.coveredRegion, RegionEq(kEmptyRegion)); |
| 1300 | EXPECT_THAT(mOutputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation)); |
| 1301 | } |
| 1302 | |
| 1303 | TEST_F(OutputEnsureOutputLayerIfVisibleTest, |
| 1304 | handlesUpdatingOutputLayerForOpaqueDirtyRotated90Layer) { |
| 1305 | mLayerFEState.isOpaque = true; |
| 1306 | mLayerFEState.contentDirty = true; |
| 1307 | mLayerFEState.geomLayerBounds = FloatRect{0, 0, 200, 100}; |
| 1308 | mLayerFEState.geomLayerTransform = ui::Transform(TR_ROT_90, 100, 200); |
| 1309 | mOutputLayerState.visibleRegion = Region(Rect(0, 0, 100, 100)); |
| 1310 | mOutputLayerState.coveredRegion = Region(Rect(100, 0, 200, 100)); |
| 1311 | |
| 1312 | EXPECT_CALL(mOutput, ensureOutputLayer(Eq(0u), Eq(mLayer), Eq(mLayerFE))) |
| 1313 | .WillOnce(Return(&mOutputLayer)); |
| 1314 | |
| 1315 | mOutput.ensureOutputLayerIfVisible(mLayer, mCoverageState); |
| 1316 | |
| 1317 | EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation)); |
| 1318 | EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation)); |
| 1319 | EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation)); |
| 1320 | |
| 1321 | EXPECT_THAT(mOutputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation)); |
| 1322 | EXPECT_THAT(mOutputLayerState.visibleNonTransparentRegion, RegionEq(kFullBoundsNoRotation)); |
| 1323 | EXPECT_THAT(mOutputLayerState.coveredRegion, RegionEq(kEmptyRegion)); |
| 1324 | EXPECT_THAT(mOutputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation)); |
| 1325 | } |
| 1326 | |
| 1327 | TEST_F(OutputEnsureOutputLayerIfVisibleTest, |
| 1328 | handlesCreatingOutputLayerForOpaqueDirtyNotRotatedLayerRotatedOutput) { |
| 1329 | mLayerFEState.isOpaque = true; |
| 1330 | mLayerFEState.contentDirty = true; |
| 1331 | mLayerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200); |
| 1332 | |
| 1333 | mOutput.mState.viewport = Rect(0, 0, 300, 200); |
| 1334 | mOutput.mState.transform = ui::Transform(TR_ROT_90, 200, 300); |
| 1335 | |
| 1336 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u)); |
| 1337 | EXPECT_CALL(mOutput, ensureOutputLayer(Eq(std::nullopt), Eq(mLayer), Eq(mLayerFE))) |
| 1338 | .WillOnce(Return(&mOutputLayer)); |
| 1339 | |
| 1340 | mOutput.ensureOutputLayerIfVisible(mLayer, mCoverageState); |
| 1341 | |
| 1342 | EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation)); |
| 1343 | EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation)); |
| 1344 | EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation)); |
| 1345 | |
| 1346 | EXPECT_THAT(mOutputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation)); |
| 1347 | EXPECT_THAT(mOutputLayerState.visibleNonTransparentRegion, RegionEq(kFullBoundsNoRotation)); |
| 1348 | EXPECT_THAT(mOutputLayerState.coveredRegion, RegionEq(kEmptyRegion)); |
| 1349 | EXPECT_THAT(mOutputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBounds90Rotation)); |
| 1350 | } |
| 1351 | |
| 1352 | TEST_F(OutputEnsureOutputLayerIfVisibleTest, |
| 1353 | handlesUpdatingOutputLayerForOpaqueDirtyNotRotatedLayerRotatedOutput) { |
| 1354 | mLayerFEState.isOpaque = true; |
| 1355 | mLayerFEState.contentDirty = true; |
| 1356 | mLayerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200); |
| 1357 | |
| 1358 | mOutput.mState.viewport = Rect(0, 0, 300, 200); |
| 1359 | mOutput.mState.transform = ui::Transform(TR_ROT_90, 200, 300); |
| 1360 | |
| 1361 | EXPECT_CALL(mOutput, ensureOutputLayer(Eq(0u), Eq(mLayer), Eq(mLayerFE))) |
| 1362 | .WillOnce(Return(&mOutputLayer)); |
| 1363 | |
| 1364 | mOutput.ensureOutputLayerIfVisible(mLayer, mCoverageState); |
| 1365 | |
| 1366 | EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation)); |
| 1367 | EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation)); |
| 1368 | EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation)); |
| 1369 | |
| 1370 | EXPECT_THAT(mOutputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation)); |
| 1371 | EXPECT_THAT(mOutputLayerState.visibleNonTransparentRegion, RegionEq(kFullBoundsNoRotation)); |
| 1372 | EXPECT_THAT(mOutputLayerState.coveredRegion, RegionEq(kEmptyRegion)); |
| 1373 | EXPECT_THAT(mOutputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBounds90Rotation)); |
| 1374 | } |
| 1375 | |
| 1376 | TEST_F(OutputEnsureOutputLayerIfVisibleTest, |
| 1377 | handlesCreatingOutputLayerForOpaqueDirtyArbitraryTransformLayer) { |
| 1378 | ui::Transform arbitraryTransform; |
| 1379 | arbitraryTransform.set(1, 1, -1, 1); |
| 1380 | arbitraryTransform.set(0, 100); |
| 1381 | |
| 1382 | mLayerFEState.isOpaque = true; |
| 1383 | mLayerFEState.contentDirty = true; |
| 1384 | mLayerFEState.geomLayerBounds = FloatRect{0, 0, 100, 200}; |
| 1385 | mLayerFEState.geomLayerTransform = arbitraryTransform; |
| 1386 | |
| 1387 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u)); |
| 1388 | EXPECT_CALL(mOutput, ensureOutputLayer(Eq(std::nullopt), Eq(mLayer), Eq(mLayerFE))) |
| 1389 | .WillOnce(Return(&mOutputLayer)); |
| 1390 | |
| 1391 | mOutput.ensureOutputLayerIfVisible(mLayer, mCoverageState); |
| 1392 | |
| 1393 | const Region kRegion = Region(Rect(0, 0, 300, 300)); |
| 1394 | const Region kRegionClipped = Region(Rect(0, 0, 200, 300)); |
| 1395 | |
| 1396 | EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kRegion)); |
| 1397 | EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kRegion)); |
| 1398 | EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kEmptyRegion)); |
| 1399 | |
| 1400 | EXPECT_THAT(mOutputLayerState.visibleRegion, RegionEq(kRegion)); |
| 1401 | EXPECT_THAT(mOutputLayerState.visibleNonTransparentRegion, RegionEq(kRegion)); |
| 1402 | EXPECT_THAT(mOutputLayerState.coveredRegion, RegionEq(kEmptyRegion)); |
| 1403 | EXPECT_THAT(mOutputLayerState.outputSpaceVisibleRegion, RegionEq(kRegionClipped)); |
| 1404 | } |
| 1405 | |
| 1406 | TEST_F(OutputEnsureOutputLayerIfVisibleTest, coverageAccumulatesTest) { |
| 1407 | mLayerFEState.isOpaque = false; |
| 1408 | mLayerFEState.contentDirty = true; |
| 1409 | mLayerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200); |
| 1410 | |
| 1411 | mCoverageState.dirtyRegion = Region(Rect(0, 0, 500, 500)); |
| 1412 | mCoverageState.aboveCoveredLayers = Region(Rect(50, 0, 150, 200)); |
| 1413 | mCoverageState.aboveOpaqueLayers = Region(Rect(50, 0, 150, 200)); |
| 1414 | |
| 1415 | EXPECT_CALL(mOutput, ensureOutputLayer(Eq(0u), Eq(mLayer), Eq(mLayerFE))) |
| 1416 | .WillOnce(Return(&mOutputLayer)); |
| 1417 | |
| 1418 | mOutput.ensureOutputLayerIfVisible(mLayer, mCoverageState); |
| 1419 | |
| 1420 | const Region kExpectedDirtyRegion = Region(Rect(0, 0, 500, 500)); |
| 1421 | const Region kExpectedAboveCoveredRegion = Region(Rect(0, 0, 150, 200)); |
| 1422 | const Region kExpectedAboveOpaqueRegion = Region(Rect(50, 0, 150, 200)); |
| 1423 | const Region kExpectedLayerVisibleRegion = Region(Rect(0, 0, 50, 200)); |
| 1424 | const Region kExpectedLayerCoveredRegion = Region(Rect(50, 0, 100, 200)); |
| 1425 | const Region kExpectedLayerVisibleNonTransparentRegion = Region(Rect(0, 100, 50, 200)); |
| 1426 | |
| 1427 | EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kExpectedDirtyRegion)); |
| 1428 | EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kExpectedAboveCoveredRegion)); |
| 1429 | EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kExpectedAboveOpaqueRegion)); |
| 1430 | |
| 1431 | EXPECT_THAT(mOutputLayerState.visibleRegion, RegionEq(kExpectedLayerVisibleRegion)); |
| 1432 | EXPECT_THAT(mOutputLayerState.visibleNonTransparentRegion, |
| 1433 | RegionEq(kExpectedLayerVisibleNonTransparentRegion)); |
| 1434 | EXPECT_THAT(mOutputLayerState.coveredRegion, RegionEq(kExpectedLayerCoveredRegion)); |
| 1435 | EXPECT_THAT(mOutputLayerState.outputSpaceVisibleRegion, RegionEq(kExpectedLayerVisibleRegion)); |
| 1436 | } |
Lloyd Pique | b62cebc | 2019-11-20 18:31:52 -0800 | [diff] [blame] | 1437 | |
| 1438 | /* |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 1439 | * Output::present() |
| 1440 | */ |
| 1441 | |
| 1442 | struct OutputPresentTest : public testing::Test { |
| 1443 | struct OutputPartialMock : public OutputPartialMockBase { |
Lloyd Pique | 739afaf | 2019-11-21 16:40:05 -0800 | [diff] [blame] | 1444 | // Sets up the helper functions called by the function under test to use |
| 1445 | // mock implementations. |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 1446 | MOCK_METHOD1(updateColorProfile, void(const compositionengine::CompositionRefreshArgs&)); |
| 1447 | MOCK_METHOD1(updateAndWriteCompositionState, |
| 1448 | void(const compositionengine::CompositionRefreshArgs&)); |
| 1449 | MOCK_METHOD1(setColorTransform, void(const compositionengine::CompositionRefreshArgs&)); |
| 1450 | MOCK_METHOD0(beginFrame, void()); |
| 1451 | MOCK_METHOD0(prepareFrame, void()); |
| 1452 | MOCK_METHOD1(devOptRepaintFlash, void(const compositionengine::CompositionRefreshArgs&)); |
| 1453 | MOCK_METHOD1(finishFrame, void(const compositionengine::CompositionRefreshArgs&)); |
| 1454 | MOCK_METHOD0(postFramebuffer, void()); |
| 1455 | }; |
| 1456 | |
| 1457 | StrictMock<OutputPartialMock> mOutput; |
| 1458 | }; |
| 1459 | |
| 1460 | TEST_F(OutputPresentTest, justInvokesChildFunctionsInSequence) { |
| 1461 | CompositionRefreshArgs args; |
| 1462 | |
| 1463 | InSequence seq; |
| 1464 | EXPECT_CALL(mOutput, updateColorProfile(Ref(args))); |
| 1465 | EXPECT_CALL(mOutput, updateAndWriteCompositionState(Ref(args))); |
| 1466 | EXPECT_CALL(mOutput, setColorTransform(Ref(args))); |
| 1467 | EXPECT_CALL(mOutput, beginFrame()); |
| 1468 | EXPECT_CALL(mOutput, prepareFrame()); |
| 1469 | EXPECT_CALL(mOutput, devOptRepaintFlash(Ref(args))); |
| 1470 | EXPECT_CALL(mOutput, finishFrame(Ref(args))); |
| 1471 | EXPECT_CALL(mOutput, postFramebuffer()); |
| 1472 | |
| 1473 | mOutput.present(args); |
| 1474 | } |
| 1475 | |
| 1476 | /* |
| 1477 | * Output::updateColorProfile() |
| 1478 | */ |
| 1479 | |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 1480 | struct OutputUpdateColorProfileTest : public testing::Test { |
| 1481 | using TestType = OutputUpdateColorProfileTest; |
| 1482 | |
| 1483 | struct OutputPartialMock : public OutputPartialMockBase { |
Lloyd Pique | 739afaf | 2019-11-21 16:40:05 -0800 | [diff] [blame] | 1484 | // Sets up the helper functions called by the function under test to use |
| 1485 | // mock implementations. |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 1486 | MOCK_METHOD1(setColorProfile, void(const ColorProfile&)); |
| 1487 | }; |
| 1488 | |
| 1489 | struct Layer { |
| 1490 | Layer() { |
| 1491 | EXPECT_CALL(mOutputLayer, getLayer()).WillRepeatedly(ReturnRef(mLayer)); |
| 1492 | EXPECT_CALL(mOutputLayer, getLayerFE()).WillRepeatedly(ReturnRef(mLayerFE)); |
| 1493 | EXPECT_CALL(mLayer, getFEState()).WillRepeatedly(ReturnRef(mLayerFEState)); |
| 1494 | } |
| 1495 | |
| 1496 | StrictMock<mock::OutputLayer> mOutputLayer; |
| 1497 | StrictMock<mock::Layer> mLayer; |
| 1498 | StrictMock<mock::LayerFE> mLayerFE; |
| 1499 | LayerFECompositionState mLayerFEState; |
| 1500 | }; |
| 1501 | |
| 1502 | OutputUpdateColorProfileTest() { |
| 1503 | mOutput.setDisplayColorProfileForTest( |
| 1504 | std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile)); |
| 1505 | mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface)); |
| 1506 | |
| 1507 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0)) |
| 1508 | .WillRepeatedly(Return(&mLayer1.mOutputLayer)); |
| 1509 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(1)) |
| 1510 | .WillRepeatedly(Return(&mLayer2.mOutputLayer)); |
| 1511 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(2)) |
| 1512 | .WillRepeatedly(Return(&mLayer3.mOutputLayer)); |
| 1513 | } |
| 1514 | |
| 1515 | struct ExecuteState : public CallOrderStateMachineHelper<TestType, ExecuteState> { |
| 1516 | void execute() { getInstance()->mOutput.updateColorProfile(getInstance()->mRefreshArgs); } |
| 1517 | }; |
| 1518 | |
| 1519 | mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>(); |
| 1520 | mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>(); |
| 1521 | StrictMock<OutputPartialMock> mOutput; |
| 1522 | |
| 1523 | Layer mLayer1; |
| 1524 | Layer mLayer2; |
| 1525 | Layer mLayer3; |
| 1526 | |
| 1527 | CompositionRefreshArgs mRefreshArgs; |
| 1528 | }; |
| 1529 | |
| 1530 | // TODO(b/144522012): Refactor Output::updateColorProfile and the related code |
| 1531 | // to make it easier to write unit tests. |
| 1532 | |
| 1533 | TEST_F(OutputUpdateColorProfileTest, setsAColorProfileWhenUnmanaged) { |
| 1534 | // When the outputColorSetting is set to kUnmanaged, the implementation sets |
| 1535 | // a simple default color profile without looking at anything else. |
| 1536 | |
| 1537 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(3)); |
| 1538 | EXPECT_CALL(mOutput, |
| 1539 | setColorProfile(ColorProfileEq( |
| 1540 | ColorProfile{ui::ColorMode::NATIVE, ui::Dataspace::UNKNOWN, |
| 1541 | ui::RenderIntent::COLORIMETRIC, ui::Dataspace::UNKNOWN}))); |
| 1542 | |
| 1543 | mRefreshArgs.outputColorSetting = OutputColorSetting::kUnmanaged; |
| 1544 | mRefreshArgs.colorSpaceAgnosticDataspace = ui::Dataspace::UNKNOWN; |
| 1545 | |
| 1546 | mOutput.updateColorProfile(mRefreshArgs); |
| 1547 | } |
| 1548 | |
| 1549 | struct OutputUpdateColorProfileTest_GetBestColorModeResultBecomesSetProfile |
| 1550 | : public OutputUpdateColorProfileTest { |
| 1551 | OutputUpdateColorProfileTest_GetBestColorModeResultBecomesSetProfile() { |
| 1552 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(0)); |
| 1553 | mRefreshArgs.outputColorSetting = OutputColorSetting::kEnhanced; |
| 1554 | mRefreshArgs.colorSpaceAgnosticDataspace = ui::Dataspace::UNKNOWN; |
| 1555 | } |
| 1556 | |
| 1557 | struct ExpectBestColorModeCallResultUsedToSetColorProfileState |
| 1558 | : public CallOrderStateMachineHelper< |
| 1559 | TestType, ExpectBestColorModeCallResultUsedToSetColorProfileState> { |
| 1560 | [[nodiscard]] auto expectBestColorModeCallResultUsedToSetColorProfile( |
| 1561 | ui::ColorMode colorMode, ui::Dataspace dataspace, ui::RenderIntent renderIntent) { |
| 1562 | EXPECT_CALL(*getInstance()->mDisplayColorProfile, |
| 1563 | getBestColorMode(ui::Dataspace::V0_SRGB, ui::RenderIntent::ENHANCE, _, _, |
| 1564 | _)) |
| 1565 | .WillOnce(DoAll(SetArgPointee<2>(dataspace), SetArgPointee<3>(colorMode), |
| 1566 | SetArgPointee<4>(renderIntent))); |
| 1567 | EXPECT_CALL(getInstance()->mOutput, |
| 1568 | setColorProfile( |
| 1569 | ColorProfileEq(ColorProfile{colorMode, dataspace, renderIntent, |
| 1570 | ui::Dataspace::UNKNOWN}))); |
| 1571 | return nextState<ExecuteState>(); |
| 1572 | } |
| 1573 | }; |
| 1574 | |
| 1575 | // Call this member function to start using the mini-DSL defined above. |
| 1576 | [[nodiscard]] auto verify() { |
| 1577 | return ExpectBestColorModeCallResultUsedToSetColorProfileState::make(this); |
| 1578 | } |
| 1579 | }; |
| 1580 | |
| 1581 | TEST_F(OutputUpdateColorProfileTest_GetBestColorModeResultBecomesSetProfile, |
| 1582 | Native_Unknown_Colorimetric_Set) { |
| 1583 | verify().expectBestColorModeCallResultUsedToSetColorProfile(ui::ColorMode::NATIVE, |
| 1584 | ui::Dataspace::UNKNOWN, |
| 1585 | ui::RenderIntent::COLORIMETRIC) |
| 1586 | .execute(); |
| 1587 | } |
| 1588 | |
| 1589 | TEST_F(OutputUpdateColorProfileTest_GetBestColorModeResultBecomesSetProfile, |
| 1590 | DisplayP3_DisplayP3_Enhance_Set) { |
| 1591 | verify().expectBestColorModeCallResultUsedToSetColorProfile(ui::ColorMode::DISPLAY_P3, |
| 1592 | ui::Dataspace::DISPLAY_P3, |
| 1593 | ui::RenderIntent::ENHANCE) |
| 1594 | .execute(); |
| 1595 | } |
| 1596 | |
| 1597 | struct OutputUpdateColorProfileTest_ColorSpaceAgnosticeDataspaceAffectsSetColorProfile |
| 1598 | : public OutputUpdateColorProfileTest { |
| 1599 | OutputUpdateColorProfileTest_ColorSpaceAgnosticeDataspaceAffectsSetColorProfile() { |
| 1600 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(0)); |
| 1601 | EXPECT_CALL(*mDisplayColorProfile, |
| 1602 | getBestColorMode(ui::Dataspace::V0_SRGB, ui::RenderIntent::ENHANCE, _, _, _)) |
| 1603 | .WillRepeatedly(DoAll(SetArgPointee<2>(ui::Dataspace::UNKNOWN), |
| 1604 | SetArgPointee<3>(ui::ColorMode::NATIVE), |
| 1605 | SetArgPointee<4>(ui::RenderIntent::COLORIMETRIC))); |
| 1606 | mRefreshArgs.outputColorSetting = OutputColorSetting::kEnhanced; |
| 1607 | } |
| 1608 | |
| 1609 | struct IfColorSpaceAgnosticDataspaceSetToState |
| 1610 | : public CallOrderStateMachineHelper<TestType, IfColorSpaceAgnosticDataspaceSetToState> { |
| 1611 | [[nodiscard]] auto ifColorSpaceAgnosticDataspaceSetTo(ui::Dataspace dataspace) { |
| 1612 | getInstance()->mRefreshArgs.colorSpaceAgnosticDataspace = dataspace; |
| 1613 | return nextState<ThenExpectSetColorProfileCallUsesColorSpaceAgnosticDataspaceState>(); |
| 1614 | } |
| 1615 | }; |
| 1616 | |
| 1617 | struct ThenExpectSetColorProfileCallUsesColorSpaceAgnosticDataspaceState |
| 1618 | : public CallOrderStateMachineHelper< |
| 1619 | TestType, ThenExpectSetColorProfileCallUsesColorSpaceAgnosticDataspaceState> { |
| 1620 | [[nodiscard]] auto thenExpectSetColorProfileCallUsesColorSpaceAgnosticDataspace( |
| 1621 | ui::Dataspace dataspace) { |
| 1622 | EXPECT_CALL(getInstance()->mOutput, |
| 1623 | setColorProfile(ColorProfileEq( |
| 1624 | ColorProfile{ui::ColorMode::NATIVE, ui::Dataspace::UNKNOWN, |
| 1625 | ui::RenderIntent::COLORIMETRIC, dataspace}))); |
| 1626 | return nextState<ExecuteState>(); |
| 1627 | } |
| 1628 | }; |
| 1629 | |
| 1630 | // Call this member function to start using the mini-DSL defined above. |
| 1631 | [[nodiscard]] auto verify() { return IfColorSpaceAgnosticDataspaceSetToState::make(this); } |
| 1632 | }; |
| 1633 | |
| 1634 | TEST_F(OutputUpdateColorProfileTest_ColorSpaceAgnosticeDataspaceAffectsSetColorProfile, DisplayP3) { |
| 1635 | verify().ifColorSpaceAgnosticDataspaceSetTo(ui::Dataspace::DISPLAY_P3) |
| 1636 | .thenExpectSetColorProfileCallUsesColorSpaceAgnosticDataspace(ui::Dataspace::DISPLAY_P3) |
| 1637 | .execute(); |
| 1638 | } |
| 1639 | |
| 1640 | TEST_F(OutputUpdateColorProfileTest_ColorSpaceAgnosticeDataspaceAffectsSetColorProfile, V0_SRGB) { |
| 1641 | verify().ifColorSpaceAgnosticDataspaceSetTo(ui::Dataspace::V0_SRGB) |
| 1642 | .thenExpectSetColorProfileCallUsesColorSpaceAgnosticDataspace(ui::Dataspace::V0_SRGB) |
| 1643 | .execute(); |
| 1644 | } |
| 1645 | |
| 1646 | struct OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference |
| 1647 | : public OutputUpdateColorProfileTest { |
| 1648 | // Internally the implementation looks through the dataspaces of all the |
| 1649 | // visible layers. The topmost one that also has an actual dataspace |
| 1650 | // preference set is used to drive subsequent choices. |
| 1651 | |
| 1652 | OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference() { |
| 1653 | mRefreshArgs.outputColorSetting = OutputColorSetting::kEnhanced; |
| 1654 | mRefreshArgs.colorSpaceAgnosticDataspace = ui::Dataspace::UNKNOWN; |
| 1655 | |
| 1656 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(3)); |
| 1657 | EXPECT_CALL(mOutput, setColorProfile(_)).WillRepeatedly(Return()); |
| 1658 | } |
| 1659 | |
| 1660 | struct IfTopLayerDataspaceState |
| 1661 | : public CallOrderStateMachineHelper<TestType, IfTopLayerDataspaceState> { |
| 1662 | [[nodiscard]] auto ifTopLayerIs(ui::Dataspace dataspace) { |
| 1663 | getInstance()->mLayer3.mLayerFEState.dataspace = dataspace; |
| 1664 | return nextState<AndIfMiddleLayerDataspaceState>(); |
| 1665 | } |
| 1666 | [[nodiscard]] auto ifTopLayerHasNoPreference() { |
| 1667 | return ifTopLayerIs(ui::Dataspace::UNKNOWN); |
| 1668 | } |
| 1669 | }; |
| 1670 | |
| 1671 | struct AndIfMiddleLayerDataspaceState |
| 1672 | : public CallOrderStateMachineHelper<TestType, AndIfMiddleLayerDataspaceState> { |
| 1673 | [[nodiscard]] auto andIfMiddleLayerIs(ui::Dataspace dataspace) { |
| 1674 | getInstance()->mLayer2.mLayerFEState.dataspace = dataspace; |
| 1675 | return nextState<AndIfBottomLayerDataspaceState>(); |
| 1676 | } |
| 1677 | [[nodiscard]] auto andIfMiddleLayerHasNoPreference() { |
| 1678 | return andIfMiddleLayerIs(ui::Dataspace::UNKNOWN); |
| 1679 | } |
| 1680 | }; |
| 1681 | |
| 1682 | struct AndIfBottomLayerDataspaceState |
| 1683 | : public CallOrderStateMachineHelper<TestType, AndIfBottomLayerDataspaceState> { |
| 1684 | [[nodiscard]] auto andIfBottomLayerIs(ui::Dataspace dataspace) { |
| 1685 | getInstance()->mLayer1.mLayerFEState.dataspace = dataspace; |
| 1686 | return nextState<ThenExpectBestColorModeCallUsesState>(); |
| 1687 | } |
| 1688 | [[nodiscard]] auto andIfBottomLayerHasNoPreference() { |
| 1689 | return andIfBottomLayerIs(ui::Dataspace::UNKNOWN); |
| 1690 | } |
| 1691 | }; |
| 1692 | |
| 1693 | struct ThenExpectBestColorModeCallUsesState |
| 1694 | : public CallOrderStateMachineHelper<TestType, ThenExpectBestColorModeCallUsesState> { |
| 1695 | [[nodiscard]] auto thenExpectBestColorModeCallUses(ui::Dataspace dataspace) { |
| 1696 | EXPECT_CALL(*getInstance()->mDisplayColorProfile, |
| 1697 | getBestColorMode(dataspace, _, _, _, _)); |
| 1698 | return nextState<ExecuteState>(); |
| 1699 | } |
| 1700 | }; |
| 1701 | |
| 1702 | // Call this member function to start using the mini-DSL defined above. |
| 1703 | [[nodiscard]] auto verify() { return IfTopLayerDataspaceState::make(this); } |
| 1704 | }; |
| 1705 | |
| 1706 | TEST_F(OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference, |
| 1707 | noStrongLayerPrefenceUses_V0_SRGB) { |
| 1708 | // If none of the layers indicate a preference, then V0_SRGB is the |
| 1709 | // preferred choice (subject to additional checks). |
| 1710 | verify().ifTopLayerHasNoPreference() |
| 1711 | .andIfMiddleLayerHasNoPreference() |
| 1712 | .andIfBottomLayerHasNoPreference() |
| 1713 | .thenExpectBestColorModeCallUses(ui::Dataspace::V0_SRGB) |
| 1714 | .execute(); |
| 1715 | } |
| 1716 | |
| 1717 | TEST_F(OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference, |
| 1718 | ifTopmostUses_DisplayP3_Then_DisplayP3_Chosen) { |
| 1719 | // If only the topmost layer has a preference, then that is what is chosen. |
| 1720 | verify().ifTopLayerIs(ui::Dataspace::DISPLAY_P3) |
| 1721 | .andIfMiddleLayerHasNoPreference() |
| 1722 | .andIfBottomLayerHasNoPreference() |
| 1723 | .thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_P3) |
| 1724 | .execute(); |
| 1725 | } |
| 1726 | |
| 1727 | TEST_F(OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference, |
| 1728 | ifMiddleUses_DisplayP3_Then_DisplayP3_Chosen) { |
| 1729 | // If only the middle layer has a preference, that that is what is chosen. |
| 1730 | verify().ifTopLayerHasNoPreference() |
| 1731 | .andIfMiddleLayerIs(ui::Dataspace::DISPLAY_P3) |
| 1732 | .andIfBottomLayerHasNoPreference() |
| 1733 | .thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_P3) |
| 1734 | .execute(); |
| 1735 | } |
| 1736 | |
| 1737 | TEST_F(OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference, |
| 1738 | ifBottomUses_DisplayP3_Then_DisplayP3_Chosen) { |
| 1739 | // If only the middle layer has a preference, that that is what is chosen. |
| 1740 | verify().ifTopLayerHasNoPreference() |
| 1741 | .andIfMiddleLayerHasNoPreference() |
| 1742 | .andIfBottomLayerIs(ui::Dataspace::DISPLAY_P3) |
| 1743 | .thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_P3) |
| 1744 | .execute(); |
| 1745 | } |
| 1746 | |
| 1747 | TEST_F(OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference, |
| 1748 | ifTopUses_DisplayBT2020_AndBottomUses_DisplayP3_Then_DisplayBT2020_Chosen) { |
| 1749 | // If multiple layers have a preference, the topmost value is what is used. |
| 1750 | verify().ifTopLayerIs(ui::Dataspace::DISPLAY_BT2020) |
| 1751 | .andIfMiddleLayerHasNoPreference() |
| 1752 | .andIfBottomLayerIs(ui::Dataspace::DISPLAY_P3) |
| 1753 | .thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_BT2020) |
| 1754 | .execute(); |
| 1755 | } |
| 1756 | |
| 1757 | TEST_F(OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference, |
| 1758 | ifTopUses_DisplayP3_AndBottomUses_V0_SRGB_Then_DisplayP3_Chosen) { |
| 1759 | // If multiple layers have a preference, the topmost value is what is used. |
| 1760 | verify().ifTopLayerIs(ui::Dataspace::DISPLAY_P3) |
| 1761 | .andIfMiddleLayerHasNoPreference() |
| 1762 | .andIfBottomLayerIs(ui::Dataspace::DISPLAY_BT2020) |
| 1763 | .thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_P3) |
| 1764 | .execute(); |
| 1765 | } |
| 1766 | |
| 1767 | struct OutputUpdateColorProfileTest_ForceOutputColorOverrides |
| 1768 | : public OutputUpdateColorProfileTest { |
| 1769 | // If CompositionRefreshArgs::forceOutputColorMode is set to some specific |
| 1770 | // values, it overrides the layer dataspace choice. |
| 1771 | |
| 1772 | OutputUpdateColorProfileTest_ForceOutputColorOverrides() { |
| 1773 | mRefreshArgs.outputColorSetting = OutputColorSetting::kEnhanced; |
| 1774 | mRefreshArgs.colorSpaceAgnosticDataspace = ui::Dataspace::UNKNOWN; |
| 1775 | |
| 1776 | mLayer1.mLayerFEState.dataspace = ui::Dataspace::DISPLAY_BT2020; |
| 1777 | |
| 1778 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(1)); |
| 1779 | EXPECT_CALL(mOutput, setColorProfile(_)).WillRepeatedly(Return()); |
| 1780 | } |
| 1781 | |
| 1782 | struct IfForceOutputColorModeState |
| 1783 | : public CallOrderStateMachineHelper<TestType, IfForceOutputColorModeState> { |
| 1784 | [[nodiscard]] auto ifForceOutputColorMode(ui::ColorMode colorMode) { |
| 1785 | getInstance()->mRefreshArgs.forceOutputColorMode = colorMode; |
| 1786 | return nextState<ThenExpectBestColorModeCallUsesState>(); |
| 1787 | } |
| 1788 | [[nodiscard]] auto ifNoOverride() { return ifForceOutputColorMode(ui::ColorMode::NATIVE); } |
| 1789 | }; |
| 1790 | |
| 1791 | struct ThenExpectBestColorModeCallUsesState |
| 1792 | : public CallOrderStateMachineHelper<TestType, ThenExpectBestColorModeCallUsesState> { |
| 1793 | [[nodiscard]] auto thenExpectBestColorModeCallUses(ui::Dataspace dataspace) { |
| 1794 | EXPECT_CALL(*getInstance()->mDisplayColorProfile, |
| 1795 | getBestColorMode(dataspace, _, _, _, _)); |
| 1796 | return nextState<ExecuteState>(); |
| 1797 | } |
| 1798 | }; |
| 1799 | |
| 1800 | // Call this member function to start using the mini-DSL defined above. |
| 1801 | [[nodiscard]] auto verify() { return IfForceOutputColorModeState::make(this); } |
| 1802 | }; |
| 1803 | |
| 1804 | TEST_F(OutputUpdateColorProfileTest_ForceOutputColorOverrides, NoOverride_DoesNotOverride) { |
| 1805 | // By default the layer state is used to set the preferred dataspace |
| 1806 | verify().ifNoOverride() |
| 1807 | .thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_BT2020) |
| 1808 | .execute(); |
| 1809 | } |
| 1810 | |
| 1811 | TEST_F(OutputUpdateColorProfileTest_ForceOutputColorOverrides, SRGB_Override_USES_V0_SRGB) { |
| 1812 | // Setting ui::ColorMode::SRGB overrides it with ui::Dataspace::V0_SRGB |
| 1813 | verify().ifForceOutputColorMode(ui::ColorMode::SRGB) |
| 1814 | .thenExpectBestColorModeCallUses(ui::Dataspace::V0_SRGB) |
| 1815 | .execute(); |
| 1816 | } |
| 1817 | |
| 1818 | TEST_F(OutputUpdateColorProfileTest_ForceOutputColorOverrides, DisplayP3_Override_Uses_DisplayP3) { |
| 1819 | // Setting ui::ColorMode::DISPLAY_P3 overrides it with ui::Dataspace::DISPLAY_P3 |
| 1820 | verify().ifForceOutputColorMode(ui::ColorMode::DISPLAY_P3) |
| 1821 | .thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_P3) |
| 1822 | .execute(); |
| 1823 | } |
| 1824 | |
| 1825 | // HDR output requires all layers to be compatible with the chosen HDR |
| 1826 | // dataspace, along with there being proper support. |
| 1827 | struct OutputUpdateColorProfileTest_Hdr : public OutputUpdateColorProfileTest { |
| 1828 | OutputUpdateColorProfileTest_Hdr() { |
| 1829 | mRefreshArgs.outputColorSetting = OutputColorSetting::kEnhanced; |
| 1830 | mRefreshArgs.colorSpaceAgnosticDataspace = ui::Dataspace::UNKNOWN; |
| 1831 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(2)); |
| 1832 | EXPECT_CALL(mOutput, setColorProfile(_)).WillRepeatedly(Return()); |
| 1833 | } |
| 1834 | |
| 1835 | static constexpr ui::Dataspace kNonHdrDataspace = ui::Dataspace::DISPLAY_P3; |
| 1836 | static constexpr ui::Dataspace BT2020_PQ = ui::Dataspace::BT2020_PQ; |
| 1837 | static constexpr ui::Dataspace BT2020_HLG = ui::Dataspace::BT2020_HLG; |
| 1838 | static constexpr ui::Dataspace DISPLAY_P3 = ui::Dataspace::DISPLAY_P3; |
| 1839 | |
| 1840 | struct IfTopLayerDataspaceState |
| 1841 | : public CallOrderStateMachineHelper<TestType, IfTopLayerDataspaceState> { |
| 1842 | [[nodiscard]] auto ifTopLayerIs(ui::Dataspace dataspace) { |
| 1843 | getInstance()->mLayer2.mLayerFEState.dataspace = dataspace; |
| 1844 | return nextState<AndTopLayerCompositionTypeState>(); |
| 1845 | } |
| 1846 | [[nodiscard]] auto ifTopLayerIsNotHdr() { return ifTopLayerIs(kNonHdrDataspace); } |
| 1847 | }; |
| 1848 | |
| 1849 | struct AndTopLayerCompositionTypeState |
| 1850 | : public CallOrderStateMachineHelper<TestType, AndTopLayerCompositionTypeState> { |
| 1851 | [[nodiscard]] auto andTopLayerIsREComposed(bool renderEngineComposed) { |
| 1852 | getInstance()->mLayer2.mLayerFEState.forceClientComposition = renderEngineComposed; |
| 1853 | return nextState<AndIfBottomLayerDataspaceState>(); |
| 1854 | } |
| 1855 | }; |
| 1856 | |
| 1857 | struct AndIfBottomLayerDataspaceState |
| 1858 | : public CallOrderStateMachineHelper<TestType, AndIfBottomLayerDataspaceState> { |
| 1859 | [[nodiscard]] auto andIfBottomLayerIs(ui::Dataspace dataspace) { |
| 1860 | getInstance()->mLayer1.mLayerFEState.dataspace = dataspace; |
| 1861 | return nextState<AndBottomLayerCompositionTypeState>(); |
| 1862 | } |
| 1863 | [[nodiscard]] auto andIfBottomLayerIsNotHdr() { |
| 1864 | return andIfBottomLayerIs(kNonHdrDataspace); |
| 1865 | } |
| 1866 | }; |
| 1867 | |
| 1868 | struct AndBottomLayerCompositionTypeState |
| 1869 | : public CallOrderStateMachineHelper<TestType, AndBottomLayerCompositionTypeState> { |
| 1870 | [[nodiscard]] auto andBottomLayerIsREComposed(bool renderEngineComposed) { |
| 1871 | getInstance()->mLayer1.mLayerFEState.forceClientComposition = renderEngineComposed; |
| 1872 | return nextState<AndIfHasLegacySupportState>(); |
| 1873 | } |
| 1874 | }; |
| 1875 | |
| 1876 | struct AndIfHasLegacySupportState |
| 1877 | : public CallOrderStateMachineHelper<TestType, AndIfHasLegacySupportState> { |
| 1878 | [[nodiscard]] auto andIfLegacySupportFor(ui::Dataspace dataspace, bool legacySupport) { |
| 1879 | EXPECT_CALL(*getInstance()->mDisplayColorProfile, hasLegacyHdrSupport(dataspace)) |
| 1880 | .WillOnce(Return(legacySupport)); |
| 1881 | return nextState<ThenExpectBestColorModeCallUsesState>(); |
| 1882 | } |
| 1883 | }; |
| 1884 | |
| 1885 | struct ThenExpectBestColorModeCallUsesState |
| 1886 | : public CallOrderStateMachineHelper<TestType, ThenExpectBestColorModeCallUsesState> { |
| 1887 | [[nodiscard]] auto thenExpectBestColorModeCallUses(ui::Dataspace dataspace) { |
| 1888 | EXPECT_CALL(*getInstance()->mDisplayColorProfile, |
| 1889 | getBestColorMode(dataspace, _, _, _, _)); |
| 1890 | return nextState<ExecuteState>(); |
| 1891 | } |
| 1892 | }; |
| 1893 | |
| 1894 | // Call this member function to start using the mini-DSL defined above. |
| 1895 | [[nodiscard]] auto verify() { return IfTopLayerDataspaceState::make(this); } |
| 1896 | }; |
| 1897 | |
| 1898 | TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_PQ_HW_Uses_PQ) { |
| 1899 | // If all layers use BT2020_PQ, and there are no other special conditions, |
| 1900 | // BT2020_PQ is used. |
| 1901 | verify().ifTopLayerIs(BT2020_PQ) |
| 1902 | .andTopLayerIsREComposed(false) |
| 1903 | .andIfBottomLayerIs(BT2020_PQ) |
| 1904 | .andBottomLayerIsREComposed(false) |
| 1905 | .andIfLegacySupportFor(BT2020_PQ, false) |
| 1906 | .thenExpectBestColorModeCallUses(BT2020_PQ) |
| 1907 | .execute(); |
| 1908 | } |
| 1909 | |
| 1910 | TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_PQ_HW_IfPQHasLegacySupport_Uses_DisplayP3) { |
| 1911 | // BT2020_PQ is not used if there is only legacy support for it. |
| 1912 | verify().ifTopLayerIs(BT2020_PQ) |
| 1913 | .andTopLayerIsREComposed(false) |
| 1914 | .andIfBottomLayerIs(BT2020_PQ) |
| 1915 | .andBottomLayerIsREComposed(false) |
| 1916 | .andIfLegacySupportFor(BT2020_PQ, true) |
| 1917 | .thenExpectBestColorModeCallUses(DISPLAY_P3) |
| 1918 | .execute(); |
| 1919 | } |
| 1920 | |
| 1921 | TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_PQ_RE_Uses_PQ) { |
| 1922 | // BT2020_PQ is still used if the bottom layer is RenderEngine composed. |
| 1923 | verify().ifTopLayerIs(BT2020_PQ) |
| 1924 | .andTopLayerIsREComposed(false) |
| 1925 | .andIfBottomLayerIs(BT2020_PQ) |
| 1926 | .andBottomLayerIsREComposed(true) |
| 1927 | .andIfLegacySupportFor(BT2020_PQ, false) |
| 1928 | .thenExpectBestColorModeCallUses(BT2020_PQ) |
| 1929 | .execute(); |
| 1930 | } |
| 1931 | |
| 1932 | TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_RE_On_PQ_HW_Uses_DisplayP3) { |
| 1933 | // BT2020_PQ is not used if the top layer is RenderEngine composed. |
| 1934 | verify().ifTopLayerIs(BT2020_PQ) |
| 1935 | .andTopLayerIsREComposed(true) |
| 1936 | .andIfBottomLayerIs(BT2020_PQ) |
| 1937 | .andBottomLayerIsREComposed(false) |
| 1938 | .andIfLegacySupportFor(BT2020_PQ, false) |
| 1939 | .thenExpectBestColorModeCallUses(DISPLAY_P3) |
| 1940 | .execute(); |
| 1941 | } |
| 1942 | |
| 1943 | TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_HLG_HW_Uses_PQ) { |
| 1944 | // If there is mixed HLG/PQ use, and the topmost layer is PQ, then PQ is used if there |
| 1945 | // are no other special conditions. |
| 1946 | verify().ifTopLayerIs(BT2020_PQ) |
| 1947 | .andTopLayerIsREComposed(false) |
| 1948 | .andIfBottomLayerIs(BT2020_HLG) |
| 1949 | .andBottomLayerIsREComposed(false) |
| 1950 | .andIfLegacySupportFor(BT2020_PQ, false) |
| 1951 | .thenExpectBestColorModeCallUses(BT2020_PQ) |
| 1952 | .execute(); |
| 1953 | } |
| 1954 | |
| 1955 | TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_HLG_HW_IfPQHasLegacySupport_Uses_DisplayP3) { |
| 1956 | // BT2020_PQ is not used if there is only legacy support for it. |
| 1957 | verify().ifTopLayerIs(BT2020_PQ) |
| 1958 | .andTopLayerIsREComposed(false) |
| 1959 | .andIfBottomLayerIs(BT2020_HLG) |
| 1960 | .andBottomLayerIsREComposed(false) |
| 1961 | .andIfLegacySupportFor(BT2020_PQ, true) |
| 1962 | .thenExpectBestColorModeCallUses(DISPLAY_P3) |
| 1963 | .execute(); |
| 1964 | } |
| 1965 | |
| 1966 | TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_HLG_RE_Uses_PQ) { |
| 1967 | // BT2020_PQ is used if the bottom HLG layer is RenderEngine composed. |
| 1968 | verify().ifTopLayerIs(BT2020_PQ) |
| 1969 | .andTopLayerIsREComposed(false) |
| 1970 | .andIfBottomLayerIs(BT2020_HLG) |
| 1971 | .andBottomLayerIsREComposed(true) |
| 1972 | .andIfLegacySupportFor(BT2020_PQ, false) |
| 1973 | .thenExpectBestColorModeCallUses(BT2020_PQ) |
| 1974 | .execute(); |
| 1975 | } |
| 1976 | |
| 1977 | TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_RE_On_HLG_HW_Uses_DisplayP3) { |
| 1978 | // BT2020_PQ is not used if the top PQ layer is RenderEngine composed. |
| 1979 | verify().ifTopLayerIs(BT2020_PQ) |
| 1980 | .andTopLayerIsREComposed(true) |
| 1981 | .andIfBottomLayerIs(BT2020_HLG) |
| 1982 | .andBottomLayerIsREComposed(false) |
| 1983 | .andIfLegacySupportFor(BT2020_PQ, false) |
| 1984 | .thenExpectBestColorModeCallUses(DISPLAY_P3) |
| 1985 | .execute(); |
| 1986 | } |
| 1987 | |
| 1988 | TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_PQ_HW_Uses_PQ) { |
| 1989 | // If there is mixed HLG/PQ use, and the topmost layer is HLG, then PQ is |
| 1990 | // used if there are no other special conditions. |
| 1991 | verify().ifTopLayerIs(BT2020_HLG) |
| 1992 | .andTopLayerIsREComposed(false) |
| 1993 | .andIfBottomLayerIs(BT2020_PQ) |
| 1994 | .andBottomLayerIsREComposed(false) |
| 1995 | .andIfLegacySupportFor(BT2020_PQ, false) |
| 1996 | .thenExpectBestColorModeCallUses(BT2020_PQ) |
| 1997 | .execute(); |
| 1998 | } |
| 1999 | |
| 2000 | TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_PQ_HW_IfPQHasLegacySupport_Uses_DisplayP3) { |
| 2001 | // BT2020_PQ is not used if there is only legacy support for it. |
| 2002 | verify().ifTopLayerIs(BT2020_HLG) |
| 2003 | .andTopLayerIsREComposed(false) |
| 2004 | .andIfBottomLayerIs(BT2020_PQ) |
| 2005 | .andBottomLayerIsREComposed(false) |
| 2006 | .andIfLegacySupportFor(BT2020_PQ, true) |
| 2007 | .thenExpectBestColorModeCallUses(DISPLAY_P3) |
| 2008 | .execute(); |
| 2009 | } |
| 2010 | |
| 2011 | TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_PQ_RE_Uses_DisplayP3) { |
| 2012 | // BT2020_PQ is not used if the bottom PQ layer is RenderEngine composed. |
| 2013 | verify().ifTopLayerIs(BT2020_HLG) |
| 2014 | .andTopLayerIsREComposed(false) |
| 2015 | .andIfBottomLayerIs(BT2020_PQ) |
| 2016 | .andBottomLayerIsREComposed(true) |
| 2017 | .andIfLegacySupportFor(BT2020_PQ, false) |
| 2018 | .thenExpectBestColorModeCallUses(DISPLAY_P3) |
| 2019 | .execute(); |
| 2020 | } |
| 2021 | |
| 2022 | TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_RE_On_PQ_HW_Uses_PQ) { |
| 2023 | // BT2020_PQ is still used if the top HLG layer is RenderEngine composed. |
| 2024 | verify().ifTopLayerIs(BT2020_HLG) |
| 2025 | .andTopLayerIsREComposed(true) |
| 2026 | .andIfBottomLayerIs(BT2020_PQ) |
| 2027 | .andBottomLayerIsREComposed(false) |
| 2028 | .andIfLegacySupportFor(BT2020_PQ, false) |
| 2029 | .thenExpectBestColorModeCallUses(BT2020_PQ) |
| 2030 | .execute(); |
| 2031 | } |
| 2032 | |
| 2033 | TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_HLG_HW_Uses_HLG) { |
| 2034 | // If all layers use HLG then HLG is used if there are no other special |
| 2035 | // conditions. |
| 2036 | verify().ifTopLayerIs(BT2020_HLG) |
| 2037 | .andTopLayerIsREComposed(false) |
| 2038 | .andIfBottomLayerIs(BT2020_HLG) |
| 2039 | .andBottomLayerIsREComposed(false) |
| 2040 | .andIfLegacySupportFor(BT2020_HLG, false) |
| 2041 | .thenExpectBestColorModeCallUses(BT2020_HLG) |
| 2042 | .execute(); |
| 2043 | } |
| 2044 | |
| 2045 | TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_HLG_HW_IfPQHasLegacySupport_Uses_DisplayP3) { |
| 2046 | // BT2020_HLG is not used if there is legacy support for it. |
| 2047 | verify().ifTopLayerIs(BT2020_HLG) |
| 2048 | .andTopLayerIsREComposed(false) |
| 2049 | .andIfBottomLayerIs(BT2020_HLG) |
| 2050 | .andBottomLayerIsREComposed(false) |
| 2051 | .andIfLegacySupportFor(BT2020_HLG, true) |
| 2052 | .thenExpectBestColorModeCallUses(DISPLAY_P3) |
| 2053 | .execute(); |
| 2054 | } |
| 2055 | |
| 2056 | TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_HLG_RE_Uses_HLG) { |
| 2057 | // BT2020_HLG is used even if the bottom layer is client composed. |
| 2058 | verify().ifTopLayerIs(BT2020_HLG) |
| 2059 | .andTopLayerIsREComposed(false) |
| 2060 | .andIfBottomLayerIs(BT2020_HLG) |
| 2061 | .andBottomLayerIsREComposed(true) |
| 2062 | .andIfLegacySupportFor(BT2020_HLG, false) |
| 2063 | .thenExpectBestColorModeCallUses(BT2020_HLG) |
| 2064 | .execute(); |
| 2065 | } |
| 2066 | |
| 2067 | TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_RE_On_HLG_HW_Uses_HLG) { |
| 2068 | // BT2020_HLG is used even if the top layer is client composed. |
| 2069 | verify().ifTopLayerIs(BT2020_HLG) |
| 2070 | .andTopLayerIsREComposed(true) |
| 2071 | .andIfBottomLayerIs(BT2020_HLG) |
| 2072 | .andBottomLayerIsREComposed(false) |
| 2073 | .andIfLegacySupportFor(BT2020_HLG, false) |
| 2074 | .thenExpectBestColorModeCallUses(BT2020_HLG) |
| 2075 | .execute(); |
| 2076 | } |
| 2077 | |
| 2078 | TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_NonHdr_HW_Uses_PQ) { |
| 2079 | // Even if there are non-HDR layers present, BT2020_PQ can still be used. |
| 2080 | verify().ifTopLayerIs(BT2020_PQ) |
| 2081 | .andTopLayerIsREComposed(false) |
| 2082 | .andIfBottomLayerIsNotHdr() |
| 2083 | .andBottomLayerIsREComposed(false) |
| 2084 | .andIfLegacySupportFor(BT2020_PQ, false) |
| 2085 | .thenExpectBestColorModeCallUses(BT2020_PQ) |
| 2086 | .execute(); |
| 2087 | } |
| 2088 | |
| 2089 | TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_NonHdr_RE_Uses_HLG) { |
| 2090 | // If all layers use HLG then HLG is used if there are no other special |
| 2091 | // conditions. |
| 2092 | verify().ifTopLayerIs(BT2020_HLG) |
| 2093 | .andTopLayerIsREComposed(false) |
| 2094 | .andIfBottomLayerIsNotHdr() |
| 2095 | .andBottomLayerIsREComposed(true) |
| 2096 | .andIfLegacySupportFor(BT2020_HLG, false) |
| 2097 | .thenExpectBestColorModeCallUses(BT2020_HLG) |
| 2098 | .execute(); |
| 2099 | } |
| 2100 | |
| 2101 | struct OutputUpdateColorProfile_AffectsChosenRenderIntentTest |
| 2102 | : public OutputUpdateColorProfileTest { |
| 2103 | // The various values for CompositionRefreshArgs::outputColorSetting affect |
| 2104 | // the chosen renderIntent, along with whether the preferred dataspace is an |
| 2105 | // HDR dataspace or not. |
| 2106 | |
| 2107 | OutputUpdateColorProfile_AffectsChosenRenderIntentTest() { |
| 2108 | mRefreshArgs.outputColorSetting = OutputColorSetting::kEnhanced; |
| 2109 | mRefreshArgs.colorSpaceAgnosticDataspace = ui::Dataspace::UNKNOWN; |
| 2110 | mLayer1.mLayerFEState.dataspace = ui::Dataspace::BT2020_PQ; |
| 2111 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(1)); |
| 2112 | EXPECT_CALL(mOutput, setColorProfile(_)).WillRepeatedly(Return()); |
| 2113 | EXPECT_CALL(*mDisplayColorProfile, hasLegacyHdrSupport(ui::Dataspace::BT2020_PQ)) |
| 2114 | .WillRepeatedly(Return(false)); |
| 2115 | } |
| 2116 | |
| 2117 | // The tests here involve enough state and GMock setup that using a mini-DSL |
| 2118 | // makes the tests much more readable, and allows the test to focus more on |
| 2119 | // the intent than on some of the details. |
| 2120 | |
| 2121 | static constexpr ui::Dataspace kNonHdrDataspace = ui::Dataspace::DISPLAY_P3; |
| 2122 | static constexpr ui::Dataspace kHdrDataspace = ui::Dataspace::BT2020_PQ; |
| 2123 | |
| 2124 | struct IfDataspaceChosenState |
| 2125 | : public CallOrderStateMachineHelper<TestType, IfDataspaceChosenState> { |
| 2126 | [[nodiscard]] auto ifDataspaceChosenIs(ui::Dataspace dataspace) { |
| 2127 | getInstance()->mLayer1.mLayerFEState.dataspace = dataspace; |
| 2128 | return nextState<AndOutputColorSettingState>(); |
| 2129 | } |
| 2130 | [[nodiscard]] auto ifDataspaceChosenIsNonHdr() { |
| 2131 | return ifDataspaceChosenIs(kNonHdrDataspace); |
| 2132 | } |
| 2133 | [[nodiscard]] auto ifDataspaceChosenIsHdr() { return ifDataspaceChosenIs(kHdrDataspace); } |
| 2134 | }; |
| 2135 | |
| 2136 | struct AndOutputColorSettingState |
| 2137 | : public CallOrderStateMachineHelper<TestType, AndOutputColorSettingState> { |
| 2138 | [[nodiscard]] auto andOutputColorSettingIs(OutputColorSetting setting) { |
| 2139 | getInstance()->mRefreshArgs.outputColorSetting = setting; |
| 2140 | return nextState<ThenExpectBestColorModeCallUsesState>(); |
| 2141 | } |
| 2142 | }; |
| 2143 | |
| 2144 | struct ThenExpectBestColorModeCallUsesState |
| 2145 | : public CallOrderStateMachineHelper<TestType, ThenExpectBestColorModeCallUsesState> { |
| 2146 | [[nodiscard]] auto thenExpectBestColorModeCallUses(ui::RenderIntent intent) { |
| 2147 | EXPECT_CALL(*getInstance()->mDisplayColorProfile, |
| 2148 | getBestColorMode(getInstance()->mLayer1.mLayerFEState.dataspace, intent, _, |
| 2149 | _, _)); |
| 2150 | return nextState<ExecuteState>(); |
| 2151 | } |
| 2152 | }; |
| 2153 | |
| 2154 | // Tests call one of these two helper member functions to start using the |
| 2155 | // mini-DSL defined above. |
| 2156 | [[nodiscard]] auto verify() { return IfDataspaceChosenState::make(this); } |
| 2157 | }; |
| 2158 | |
| 2159 | TEST_F(OutputUpdateColorProfile_AffectsChosenRenderIntentTest, |
| 2160 | Managed_NonHdr_Prefers_Colorimetric) { |
| 2161 | verify().ifDataspaceChosenIsNonHdr() |
| 2162 | .andOutputColorSettingIs(OutputColorSetting::kManaged) |
| 2163 | .thenExpectBestColorModeCallUses(ui::RenderIntent::COLORIMETRIC) |
| 2164 | .execute(); |
| 2165 | } |
| 2166 | |
| 2167 | TEST_F(OutputUpdateColorProfile_AffectsChosenRenderIntentTest, |
| 2168 | Managed_Hdr_Prefers_ToneMapColorimetric) { |
| 2169 | verify().ifDataspaceChosenIsHdr() |
| 2170 | .andOutputColorSettingIs(OutputColorSetting::kManaged) |
| 2171 | .thenExpectBestColorModeCallUses(ui::RenderIntent::TONE_MAP_COLORIMETRIC) |
| 2172 | .execute(); |
| 2173 | } |
| 2174 | |
| 2175 | TEST_F(OutputUpdateColorProfile_AffectsChosenRenderIntentTest, Enhanced_NonHdr_Prefers_Enhance) { |
| 2176 | verify().ifDataspaceChosenIsNonHdr() |
| 2177 | .andOutputColorSettingIs(OutputColorSetting::kEnhanced) |
| 2178 | .thenExpectBestColorModeCallUses(ui::RenderIntent::ENHANCE) |
| 2179 | .execute(); |
| 2180 | } |
| 2181 | |
| 2182 | TEST_F(OutputUpdateColorProfile_AffectsChosenRenderIntentTest, |
| 2183 | Enhanced_Hdr_Prefers_ToneMapEnhance) { |
| 2184 | verify().ifDataspaceChosenIsHdr() |
| 2185 | .andOutputColorSettingIs(OutputColorSetting::kEnhanced) |
| 2186 | .thenExpectBestColorModeCallUses(ui::RenderIntent::TONE_MAP_ENHANCE) |
| 2187 | .execute(); |
| 2188 | } |
| 2189 | |
| 2190 | TEST_F(OutputUpdateColorProfile_AffectsChosenRenderIntentTest, Vendor_NonHdr_Prefers_Vendor) { |
| 2191 | verify().ifDataspaceChosenIsNonHdr() |
| 2192 | .andOutputColorSettingIs(kVendorSpecifiedOutputColorSetting) |
| 2193 | .thenExpectBestColorModeCallUses( |
| 2194 | static_cast<ui::RenderIntent>(kVendorSpecifiedOutputColorSetting)) |
| 2195 | .execute(); |
| 2196 | } |
| 2197 | |
| 2198 | TEST_F(OutputUpdateColorProfile_AffectsChosenRenderIntentTest, Vendor_Hdr_Prefers_Vendor) { |
| 2199 | verify().ifDataspaceChosenIsHdr() |
| 2200 | .andOutputColorSettingIs(kVendorSpecifiedOutputColorSetting) |
| 2201 | .thenExpectBestColorModeCallUses( |
| 2202 | static_cast<ui::RenderIntent>(kVendorSpecifiedOutputColorSetting)) |
| 2203 | .execute(); |
| 2204 | } |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 2205 | |
| 2206 | /* |
| 2207 | * Output::beginFrame() |
| 2208 | */ |
| 2209 | |
Lloyd Pique | e596595 | 2019-11-18 16:16:32 -0800 | [diff] [blame] | 2210 | struct OutputBeginFrameTest : public ::testing::Test { |
| 2211 | using TestType = OutputBeginFrameTest; |
| 2212 | |
| 2213 | struct OutputPartialMock : public OutputPartialMockBase { |
Lloyd Pique | 739afaf | 2019-11-21 16:40:05 -0800 | [diff] [blame] | 2214 | // Sets up the helper functions called by the function under test to use |
| 2215 | // mock implementations. |
Lloyd Pique | e596595 | 2019-11-18 16:16:32 -0800 | [diff] [blame] | 2216 | MOCK_CONST_METHOD1(getDirtyRegion, Region(bool)); |
| 2217 | }; |
| 2218 | |
| 2219 | OutputBeginFrameTest() { |
| 2220 | mOutput.setDisplayColorProfileForTest( |
| 2221 | std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile)); |
| 2222 | mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface)); |
| 2223 | } |
| 2224 | |
| 2225 | struct IfGetDirtyRegionExpectationState |
| 2226 | : public CallOrderStateMachineHelper<TestType, IfGetDirtyRegionExpectationState> { |
| 2227 | [[nodiscard]] auto ifGetDirtyRegionReturns(Region dirtyRegion) { |
| 2228 | EXPECT_CALL(getInstance()->mOutput, getDirtyRegion(false)) |
| 2229 | .WillOnce(Return(dirtyRegion)); |
| 2230 | return nextState<AndIfGetOutputLayerCountExpectationState>(); |
| 2231 | } |
| 2232 | }; |
| 2233 | |
| 2234 | struct AndIfGetOutputLayerCountExpectationState |
| 2235 | : public CallOrderStateMachineHelper<TestType, AndIfGetOutputLayerCountExpectationState> { |
| 2236 | [[nodiscard]] auto andIfGetOutputLayerCountReturns(size_t layerCount) { |
| 2237 | EXPECT_CALL(getInstance()->mOutput, getOutputLayerCount()).WillOnce(Return(layerCount)); |
| 2238 | return nextState<AndIfLastCompositionHadVisibleLayersState>(); |
| 2239 | } |
| 2240 | }; |
| 2241 | |
| 2242 | struct AndIfLastCompositionHadVisibleLayersState |
| 2243 | : public CallOrderStateMachineHelper<TestType, |
| 2244 | AndIfLastCompositionHadVisibleLayersState> { |
| 2245 | [[nodiscard]] auto andIfLastCompositionHadVisibleLayersIs(bool hadOutputLayers) { |
| 2246 | getInstance()->mOutput.mState.lastCompositionHadVisibleLayers = hadOutputLayers; |
| 2247 | return nextState<ThenExpectRenderSurfaceBeginFrameCallState>(); |
| 2248 | } |
| 2249 | }; |
| 2250 | |
| 2251 | struct ThenExpectRenderSurfaceBeginFrameCallState |
| 2252 | : public CallOrderStateMachineHelper<TestType, |
| 2253 | ThenExpectRenderSurfaceBeginFrameCallState> { |
| 2254 | [[nodiscard]] auto thenExpectRenderSurfaceBeginFrameCall(bool mustRecompose) { |
| 2255 | EXPECT_CALL(*getInstance()->mRenderSurface, beginFrame(mustRecompose)); |
| 2256 | return nextState<ExecuteState>(); |
| 2257 | } |
| 2258 | }; |
| 2259 | |
| 2260 | struct ExecuteState : public CallOrderStateMachineHelper<TestType, ExecuteState> { |
| 2261 | [[nodiscard]] auto execute() { |
| 2262 | getInstance()->mOutput.beginFrame(); |
| 2263 | return nextState<CheckPostconditionHadVisibleLayersState>(); |
| 2264 | } |
| 2265 | }; |
| 2266 | |
| 2267 | struct CheckPostconditionHadVisibleLayersState |
| 2268 | : public CallOrderStateMachineHelper<TestType, CheckPostconditionHadVisibleLayersState> { |
| 2269 | void checkPostconditionHadVisibleLayers(bool expected) { |
| 2270 | EXPECT_EQ(expected, getInstance()->mOutput.mState.lastCompositionHadVisibleLayers); |
| 2271 | } |
| 2272 | }; |
| 2273 | |
| 2274 | // Tests call one of these two helper member functions to start using the |
| 2275 | // mini-DSL defined above. |
| 2276 | [[nodiscard]] auto verify() { return IfGetDirtyRegionExpectationState::make(this); } |
| 2277 | |
| 2278 | static const Region kEmptyRegion; |
| 2279 | static const Region kNotEmptyRegion; |
| 2280 | |
| 2281 | mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>(); |
| 2282 | mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>(); |
| 2283 | StrictMock<OutputPartialMock> mOutput; |
| 2284 | }; |
| 2285 | |
| 2286 | const Region OutputBeginFrameTest::kEmptyRegion{Rect{0, 0, 0, 0}}; |
| 2287 | const Region OutputBeginFrameTest::kNotEmptyRegion{Rect{0, 0, 1, 1}}; |
| 2288 | |
| 2289 | TEST_F(OutputBeginFrameTest, hasDirtyHasLayersHadLayersLastFrame) { |
| 2290 | verify().ifGetDirtyRegionReturns(kNotEmptyRegion) |
| 2291 | .andIfGetOutputLayerCountReturns(1u) |
| 2292 | .andIfLastCompositionHadVisibleLayersIs(true) |
| 2293 | .thenExpectRenderSurfaceBeginFrameCall(true) |
| 2294 | .execute() |
| 2295 | .checkPostconditionHadVisibleLayers(true); |
| 2296 | } |
| 2297 | |
| 2298 | TEST_F(OutputBeginFrameTest, hasDirtyNotHasLayersHadLayersLastFrame) { |
| 2299 | verify().ifGetDirtyRegionReturns(kNotEmptyRegion) |
| 2300 | .andIfGetOutputLayerCountReturns(0u) |
| 2301 | .andIfLastCompositionHadVisibleLayersIs(true) |
| 2302 | .thenExpectRenderSurfaceBeginFrameCall(true) |
| 2303 | .execute() |
| 2304 | .checkPostconditionHadVisibleLayers(false); |
| 2305 | } |
| 2306 | |
| 2307 | TEST_F(OutputBeginFrameTest, hasDirtyHasLayersNotHadLayersLastFrame) { |
| 2308 | verify().ifGetDirtyRegionReturns(kNotEmptyRegion) |
| 2309 | .andIfGetOutputLayerCountReturns(1u) |
| 2310 | .andIfLastCompositionHadVisibleLayersIs(false) |
| 2311 | .thenExpectRenderSurfaceBeginFrameCall(true) |
| 2312 | .execute() |
| 2313 | .checkPostconditionHadVisibleLayers(true); |
| 2314 | } |
| 2315 | |
| 2316 | TEST_F(OutputBeginFrameTest, hasDirtyNotHasLayersNotHadLayersLastFrame) { |
| 2317 | verify().ifGetDirtyRegionReturns(kNotEmptyRegion) |
| 2318 | .andIfGetOutputLayerCountReturns(0u) |
| 2319 | .andIfLastCompositionHadVisibleLayersIs(false) |
| 2320 | .thenExpectRenderSurfaceBeginFrameCall(false) |
| 2321 | .execute() |
| 2322 | .checkPostconditionHadVisibleLayers(false); |
| 2323 | } |
| 2324 | |
| 2325 | TEST_F(OutputBeginFrameTest, notHasDirtyHasLayersHadLayersLastFrame) { |
| 2326 | verify().ifGetDirtyRegionReturns(kEmptyRegion) |
| 2327 | .andIfGetOutputLayerCountReturns(1u) |
| 2328 | .andIfLastCompositionHadVisibleLayersIs(true) |
| 2329 | .thenExpectRenderSurfaceBeginFrameCall(false) |
| 2330 | .execute() |
| 2331 | .checkPostconditionHadVisibleLayers(true); |
| 2332 | } |
| 2333 | |
| 2334 | TEST_F(OutputBeginFrameTest, notHasDirtyNotHasLayersHadLayersLastFrame) { |
| 2335 | verify().ifGetDirtyRegionReturns(kEmptyRegion) |
| 2336 | .andIfGetOutputLayerCountReturns(0u) |
| 2337 | .andIfLastCompositionHadVisibleLayersIs(true) |
| 2338 | .thenExpectRenderSurfaceBeginFrameCall(false) |
| 2339 | .execute() |
| 2340 | .checkPostconditionHadVisibleLayers(true); |
| 2341 | } |
| 2342 | |
| 2343 | TEST_F(OutputBeginFrameTest, notHasDirtyHasLayersNotHadLayersLastFrame) { |
| 2344 | verify().ifGetDirtyRegionReturns(kEmptyRegion) |
| 2345 | .andIfGetOutputLayerCountReturns(1u) |
| 2346 | .andIfLastCompositionHadVisibleLayersIs(false) |
| 2347 | .thenExpectRenderSurfaceBeginFrameCall(false) |
| 2348 | .execute() |
| 2349 | .checkPostconditionHadVisibleLayers(false); |
| 2350 | } |
| 2351 | |
| 2352 | TEST_F(OutputBeginFrameTest, notHasDirtyNotHasLayersNotHadLayersLastFrame) { |
| 2353 | verify().ifGetDirtyRegionReturns(kEmptyRegion) |
| 2354 | .andIfGetOutputLayerCountReturns(0u) |
| 2355 | .andIfLastCompositionHadVisibleLayersIs(false) |
| 2356 | .thenExpectRenderSurfaceBeginFrameCall(false) |
| 2357 | .execute() |
| 2358 | .checkPostconditionHadVisibleLayers(false); |
| 2359 | } |
| 2360 | |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 2361 | /* |
| 2362 | * Output::devOptRepaintFlash() |
| 2363 | */ |
| 2364 | |
Lloyd Pique | db462d8 | 2019-11-19 17:58:46 -0800 | [diff] [blame] | 2365 | struct OutputDevOptRepaintFlashTest : public testing::Test { |
| 2366 | struct OutputPartialMock : public OutputPartialMockBase { |
Lloyd Pique | 739afaf | 2019-11-21 16:40:05 -0800 | [diff] [blame] | 2367 | // Sets up the helper functions called by the function under test to use |
| 2368 | // mock implementations. |
Lloyd Pique | db462d8 | 2019-11-19 17:58:46 -0800 | [diff] [blame] | 2369 | MOCK_CONST_METHOD1(getDirtyRegion, Region(bool)); |
| 2370 | MOCK_METHOD1(composeSurfaces, std::optional<base::unique_fd>(const Region&)); |
| 2371 | MOCK_METHOD0(postFramebuffer, void()); |
| 2372 | MOCK_METHOD0(prepareFrame, void()); |
| 2373 | }; |
| 2374 | |
| 2375 | OutputDevOptRepaintFlashTest() { |
| 2376 | mOutput.setDisplayColorProfileForTest( |
| 2377 | std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile)); |
| 2378 | mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface)); |
| 2379 | } |
| 2380 | |
| 2381 | static const Region kEmptyRegion; |
| 2382 | static const Region kNotEmptyRegion; |
| 2383 | |
| 2384 | StrictMock<OutputPartialMock> mOutput; |
| 2385 | mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>(); |
| 2386 | mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>(); |
| 2387 | CompositionRefreshArgs mRefreshArgs; |
| 2388 | }; |
| 2389 | |
| 2390 | const Region OutputDevOptRepaintFlashTest::kEmptyRegion{Rect{0, 0, 0, 0}}; |
| 2391 | const Region OutputDevOptRepaintFlashTest::kNotEmptyRegion{Rect{0, 0, 1, 1}}; |
| 2392 | |
| 2393 | TEST_F(OutputDevOptRepaintFlashTest, doesNothingIfFlashDelayNotSet) { |
| 2394 | mRefreshArgs.devOptFlashDirtyRegionsDelay = {}; |
| 2395 | mRefreshArgs.repaintEverything = true; |
| 2396 | mOutput.mState.isEnabled = true; |
| 2397 | |
| 2398 | mOutput.devOptRepaintFlash(mRefreshArgs); |
| 2399 | } |
| 2400 | |
| 2401 | TEST_F(OutputDevOptRepaintFlashTest, postsAndPreparesANewFrameIfNotEnabled) { |
| 2402 | mRefreshArgs.devOptFlashDirtyRegionsDelay = std::chrono::microseconds(1); |
| 2403 | mRefreshArgs.repaintEverything = true; |
| 2404 | mOutput.mState.isEnabled = false; |
| 2405 | |
| 2406 | InSequence seq; |
| 2407 | EXPECT_CALL(mOutput, postFramebuffer()); |
| 2408 | EXPECT_CALL(mOutput, prepareFrame()); |
| 2409 | |
| 2410 | mOutput.devOptRepaintFlash(mRefreshArgs); |
| 2411 | } |
| 2412 | |
| 2413 | TEST_F(OutputDevOptRepaintFlashTest, postsAndPreparesANewFrameIfNotDirty) { |
| 2414 | mRefreshArgs.devOptFlashDirtyRegionsDelay = std::chrono::microseconds(1); |
| 2415 | mRefreshArgs.repaintEverything = true; |
| 2416 | mOutput.mState.isEnabled = true; |
| 2417 | |
| 2418 | InSequence seq; |
| 2419 | EXPECT_CALL(mOutput, getDirtyRegion(true)).WillOnce(Return(kEmptyRegion)); |
| 2420 | EXPECT_CALL(mOutput, postFramebuffer()); |
| 2421 | EXPECT_CALL(mOutput, prepareFrame()); |
| 2422 | |
| 2423 | mOutput.devOptRepaintFlash(mRefreshArgs); |
| 2424 | } |
| 2425 | |
| 2426 | TEST_F(OutputDevOptRepaintFlashTest, alsoComposesSurfacesAndQueuesABufferIfDirty) { |
| 2427 | mRefreshArgs.devOptFlashDirtyRegionsDelay = std::chrono::microseconds(1); |
| 2428 | mRefreshArgs.repaintEverything = false; |
| 2429 | mOutput.mState.isEnabled = true; |
| 2430 | |
| 2431 | InSequence seq; |
| 2432 | EXPECT_CALL(mOutput, getDirtyRegion(false)).WillOnce(Return(kNotEmptyRegion)); |
| 2433 | EXPECT_CALL(mOutput, composeSurfaces(RegionEq(kNotEmptyRegion))); |
| 2434 | EXPECT_CALL(*mRenderSurface, queueBuffer(_)); |
| 2435 | EXPECT_CALL(mOutput, postFramebuffer()); |
| 2436 | EXPECT_CALL(mOutput, prepareFrame()); |
| 2437 | |
| 2438 | mOutput.devOptRepaintFlash(mRefreshArgs); |
| 2439 | } |
| 2440 | |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 2441 | // TODO(b/144060211) - Add coverage |
| 2442 | |
| 2443 | /* |
| 2444 | * Output::finishFrame() |
| 2445 | */ |
| 2446 | |
Lloyd Pique | 03561a6 | 2019-11-19 18:34:52 -0800 | [diff] [blame] | 2447 | struct OutputFinishFrameTest : public testing::Test { |
| 2448 | struct OutputPartialMock : public OutputPartialMockBase { |
Lloyd Pique | 739afaf | 2019-11-21 16:40:05 -0800 | [diff] [blame] | 2449 | // Sets up the helper functions called by the function under test to use |
| 2450 | // mock implementations. |
Lloyd Pique | 03561a6 | 2019-11-19 18:34:52 -0800 | [diff] [blame] | 2451 | MOCK_METHOD1(composeSurfaces, std::optional<base::unique_fd>(const Region&)); |
| 2452 | MOCK_METHOD0(postFramebuffer, void()); |
| 2453 | }; |
| 2454 | |
| 2455 | OutputFinishFrameTest() { |
| 2456 | mOutput.setDisplayColorProfileForTest( |
| 2457 | std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile)); |
| 2458 | mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface)); |
| 2459 | } |
| 2460 | |
| 2461 | StrictMock<OutputPartialMock> mOutput; |
| 2462 | mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>(); |
| 2463 | mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>(); |
| 2464 | CompositionRefreshArgs mRefreshArgs; |
| 2465 | }; |
| 2466 | |
| 2467 | TEST_F(OutputFinishFrameTest, ifNotEnabledDoesNothing) { |
| 2468 | mOutput.mState.isEnabled = false; |
| 2469 | |
| 2470 | mOutput.finishFrame(mRefreshArgs); |
| 2471 | } |
| 2472 | |
| 2473 | TEST_F(OutputFinishFrameTest, takesEarlyOutifComposeSurfacesReturnsNoFence) { |
| 2474 | mOutput.mState.isEnabled = true; |
| 2475 | |
| 2476 | InSequence seq; |
| 2477 | EXPECT_CALL(mOutput, composeSurfaces(RegionEq(Region::INVALID_REGION))); |
| 2478 | |
| 2479 | mOutput.finishFrame(mRefreshArgs); |
| 2480 | } |
| 2481 | |
| 2482 | TEST_F(OutputFinishFrameTest, queuesBufferIfComposeSurfacesReturnsAFence) { |
| 2483 | mOutput.mState.isEnabled = true; |
| 2484 | |
| 2485 | InSequence seq; |
| 2486 | EXPECT_CALL(mOutput, composeSurfaces(RegionEq(Region::INVALID_REGION))) |
| 2487 | .WillOnce(Return(ByMove(base::unique_fd()))); |
| 2488 | EXPECT_CALL(*mRenderSurface, queueBuffer(_)); |
| 2489 | |
| 2490 | mOutput.finishFrame(mRefreshArgs); |
| 2491 | } |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 2492 | |
| 2493 | /* |
| 2494 | * Output::postFramebuffer() |
| 2495 | */ |
| 2496 | |
Lloyd Pique | 07178e3 | 2019-11-19 19:15:26 -0800 | [diff] [blame] | 2497 | struct OutputPostFramebufferTest : public testing::Test { |
| 2498 | struct OutputPartialMock : public OutputPartialMockBase { |
Lloyd Pique | 739afaf | 2019-11-21 16:40:05 -0800 | [diff] [blame] | 2499 | // Sets up the helper functions called by the function under test to use |
| 2500 | // mock implementations. |
Lloyd Pique | 07178e3 | 2019-11-19 19:15:26 -0800 | [diff] [blame] | 2501 | MOCK_METHOD0(presentAndGetFrameFences, compositionengine::Output::FrameFences()); |
| 2502 | }; |
| 2503 | |
| 2504 | struct Layer { |
| 2505 | Layer() { |
| 2506 | EXPECT_CALL(outputLayer, getLayerFE()).WillRepeatedly(ReturnRef(layerFE)); |
| 2507 | EXPECT_CALL(outputLayer, getHwcLayer()).WillRepeatedly(Return(&hwc2Layer)); |
| 2508 | } |
| 2509 | |
| 2510 | StrictMock<mock::OutputLayer> outputLayer; |
| 2511 | StrictMock<mock::LayerFE> layerFE; |
| 2512 | StrictMock<HWC2::mock::Layer> hwc2Layer; |
| 2513 | }; |
| 2514 | |
| 2515 | OutputPostFramebufferTest() { |
| 2516 | mOutput.setDisplayColorProfileForTest( |
| 2517 | std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile)); |
| 2518 | mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface)); |
| 2519 | |
| 2520 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(3u)); |
| 2521 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0u)) |
| 2522 | .WillRepeatedly(Return(&mLayer1.outputLayer)); |
| 2523 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(1u)) |
| 2524 | .WillRepeatedly(Return(&mLayer2.outputLayer)); |
| 2525 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(2u)) |
| 2526 | .WillRepeatedly(Return(&mLayer3.outputLayer)); |
| 2527 | } |
| 2528 | |
| 2529 | StrictMock<OutputPartialMock> mOutput; |
| 2530 | mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>(); |
| 2531 | mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>(); |
| 2532 | |
| 2533 | Layer mLayer1; |
| 2534 | Layer mLayer2; |
| 2535 | Layer mLayer3; |
| 2536 | }; |
| 2537 | |
| 2538 | TEST_F(OutputPostFramebufferTest, ifNotEnabledDoesNothing) { |
| 2539 | mOutput.mState.isEnabled = false; |
| 2540 | |
| 2541 | mOutput.postFramebuffer(); |
| 2542 | } |
| 2543 | |
| 2544 | TEST_F(OutputPostFramebufferTest, ifEnabledMustFlipThenPresentThenSendPresentCompleted) { |
| 2545 | mOutput.mState.isEnabled = true; |
| 2546 | |
| 2547 | compositionengine::Output::FrameFences frameFences; |
| 2548 | |
| 2549 | // This should happen even if there are no output layers. |
| 2550 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u)); |
| 2551 | |
| 2552 | // For this test in particular we want to make sure the call expectations |
| 2553 | // setup below are satisfied in the specific order. |
| 2554 | InSequence seq; |
| 2555 | |
| 2556 | EXPECT_CALL(*mRenderSurface, flip()); |
| 2557 | EXPECT_CALL(mOutput, presentAndGetFrameFences()).WillOnce(Return(frameFences)); |
| 2558 | EXPECT_CALL(*mRenderSurface, onPresentDisplayCompleted()); |
| 2559 | |
| 2560 | mOutput.postFramebuffer(); |
| 2561 | } |
| 2562 | |
| 2563 | TEST_F(OutputPostFramebufferTest, releaseFencesAreSentToLayerFE) { |
| 2564 | // Simulate getting release fences from each layer, and ensure they are passed to the |
| 2565 | // front-end layer interface for each layer correctly. |
| 2566 | |
| 2567 | mOutput.mState.isEnabled = true; |
| 2568 | |
| 2569 | // Create three unique fence instances |
| 2570 | sp<Fence> layer1Fence = new Fence(); |
| 2571 | sp<Fence> layer2Fence = new Fence(); |
| 2572 | sp<Fence> layer3Fence = new Fence(); |
| 2573 | |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 2574 | Output::FrameFences frameFences; |
Lloyd Pique | 07178e3 | 2019-11-19 19:15:26 -0800 | [diff] [blame] | 2575 | frameFences.layerFences.emplace(&mLayer1.hwc2Layer, layer1Fence); |
| 2576 | frameFences.layerFences.emplace(&mLayer2.hwc2Layer, layer2Fence); |
| 2577 | frameFences.layerFences.emplace(&mLayer3.hwc2Layer, layer3Fence); |
| 2578 | |
| 2579 | EXPECT_CALL(*mRenderSurface, flip()); |
| 2580 | EXPECT_CALL(mOutput, presentAndGetFrameFences()).WillOnce(Return(frameFences)); |
| 2581 | EXPECT_CALL(*mRenderSurface, onPresentDisplayCompleted()); |
| 2582 | |
| 2583 | // Compare the pointers values of each fence to make sure the correct ones |
| 2584 | // are passed. This happens to work with the current implementation, but |
| 2585 | // would not survive certain calls like Fence::merge() which would return a |
| 2586 | // new instance. |
| 2587 | EXPECT_CALL(mLayer1.layerFE, |
| 2588 | onLayerDisplayed(Property(&sp<Fence>::get, Eq(layer1Fence.get())))); |
| 2589 | EXPECT_CALL(mLayer2.layerFE, |
| 2590 | onLayerDisplayed(Property(&sp<Fence>::get, Eq(layer2Fence.get())))); |
| 2591 | EXPECT_CALL(mLayer3.layerFE, |
| 2592 | onLayerDisplayed(Property(&sp<Fence>::get, Eq(layer3Fence.get())))); |
| 2593 | |
| 2594 | mOutput.postFramebuffer(); |
| 2595 | } |
| 2596 | |
| 2597 | TEST_F(OutputPostFramebufferTest, releaseFencesIncludeClientTargetAcquireFence) { |
| 2598 | mOutput.mState.isEnabled = true; |
| 2599 | mOutput.mState.usesClientComposition = true; |
| 2600 | |
| 2601 | sp<Fence> clientTargetAcquireFence = new Fence(); |
| 2602 | sp<Fence> layer1Fence = new Fence(); |
| 2603 | sp<Fence> layer2Fence = new Fence(); |
| 2604 | sp<Fence> layer3Fence = new Fence(); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 2605 | Output::FrameFences frameFences; |
Lloyd Pique | 07178e3 | 2019-11-19 19:15:26 -0800 | [diff] [blame] | 2606 | frameFences.clientTargetAcquireFence = clientTargetAcquireFence; |
| 2607 | frameFences.layerFences.emplace(&mLayer1.hwc2Layer, layer1Fence); |
| 2608 | frameFences.layerFences.emplace(&mLayer2.hwc2Layer, layer2Fence); |
| 2609 | frameFences.layerFences.emplace(&mLayer3.hwc2Layer, layer3Fence); |
| 2610 | |
| 2611 | EXPECT_CALL(*mRenderSurface, flip()); |
| 2612 | EXPECT_CALL(mOutput, presentAndGetFrameFences()).WillOnce(Return(frameFences)); |
| 2613 | EXPECT_CALL(*mRenderSurface, onPresentDisplayCompleted()); |
| 2614 | |
| 2615 | // Fence::merge is called, and since none of the fences are actually valid, |
| 2616 | // Fence::NO_FENCE is returned and passed to each onLayerDisplayed() call. |
| 2617 | // This is the best we can do without creating a real kernel fence object. |
| 2618 | EXPECT_CALL(mLayer1.layerFE, onLayerDisplayed(Fence::NO_FENCE)); |
| 2619 | EXPECT_CALL(mLayer2.layerFE, onLayerDisplayed(Fence::NO_FENCE)); |
| 2620 | EXPECT_CALL(mLayer3.layerFE, onLayerDisplayed(Fence::NO_FENCE)); |
| 2621 | |
| 2622 | mOutput.postFramebuffer(); |
| 2623 | } |
| 2624 | |
| 2625 | TEST_F(OutputPostFramebufferTest, releasedLayersSentPresentFence) { |
| 2626 | mOutput.mState.isEnabled = true; |
| 2627 | mOutput.mState.usesClientComposition = true; |
| 2628 | |
| 2629 | // This should happen even if there are no (current) output layers. |
| 2630 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u)); |
| 2631 | |
| 2632 | // Load up the released layers with some mock instances |
| 2633 | sp<StrictMock<mock::LayerFE>> releasedLayer1{new StrictMock<mock::LayerFE>()}; |
| 2634 | sp<StrictMock<mock::LayerFE>> releasedLayer2{new StrictMock<mock::LayerFE>()}; |
| 2635 | sp<StrictMock<mock::LayerFE>> releasedLayer3{new StrictMock<mock::LayerFE>()}; |
| 2636 | Output::ReleasedLayers layers; |
| 2637 | layers.push_back(releasedLayer1); |
| 2638 | layers.push_back(releasedLayer2); |
| 2639 | layers.push_back(releasedLayer3); |
| 2640 | mOutput.setReleasedLayers(std::move(layers)); |
| 2641 | |
| 2642 | // Set up a fake present fence |
| 2643 | sp<Fence> presentFence = new Fence(); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 2644 | Output::FrameFences frameFences; |
Lloyd Pique | 07178e3 | 2019-11-19 19:15:26 -0800 | [diff] [blame] | 2645 | frameFences.presentFence = presentFence; |
| 2646 | |
| 2647 | EXPECT_CALL(*mRenderSurface, flip()); |
| 2648 | EXPECT_CALL(mOutput, presentAndGetFrameFences()).WillOnce(Return(frameFences)); |
| 2649 | EXPECT_CALL(*mRenderSurface, onPresentDisplayCompleted()); |
| 2650 | |
| 2651 | // Each released layer should be given the presentFence. |
| 2652 | EXPECT_CALL(*releasedLayer1, |
| 2653 | onLayerDisplayed(Property(&sp<Fence>::get, Eq(presentFence.get())))); |
| 2654 | EXPECT_CALL(*releasedLayer2, |
| 2655 | onLayerDisplayed(Property(&sp<Fence>::get, Eq(presentFence.get())))); |
| 2656 | EXPECT_CALL(*releasedLayer3, |
| 2657 | onLayerDisplayed(Property(&sp<Fence>::get, Eq(presentFence.get())))); |
| 2658 | |
| 2659 | mOutput.postFramebuffer(); |
| 2660 | |
| 2661 | // After the call the list of released layers should have been cleared. |
| 2662 | EXPECT_TRUE(mOutput.getReleasedLayersForTest().empty()); |
| 2663 | } |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 2664 | |
| 2665 | /* |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 2666 | * Output::composeSurfaces() |
| 2667 | */ |
| 2668 | |
| 2669 | struct OutputComposeSurfacesTest : public testing::Test { |
| 2670 | static constexpr uint32_t kDefaultOutputOrientation = TR_IDENT; |
| 2671 | static constexpr ui::Dataspace kDefaultOutputDataspace = ui::Dataspace::DISPLAY_P3; |
| 2672 | |
| 2673 | static const Rect kDefaultOutputFrame; |
| 2674 | static const Rect kDefaultOutputViewport; |
| 2675 | static const Rect kDefaultOutputScissor; |
| 2676 | static const mat4 kDefaultColorTransformMat; |
| 2677 | |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 2678 | struct OutputPartialMock : public OutputPartialMockBase { |
Lloyd Pique | 739afaf | 2019-11-21 16:40:05 -0800 | [diff] [blame] | 2679 | // Sets up the helper functions called by the function under test to use |
| 2680 | // mock implementations. |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 2681 | MOCK_CONST_METHOD0(getSkipColorTransform, bool()); |
Vishnu Nair | 3a7346c | 2019-12-04 08:09:09 -0800 | [diff] [blame] | 2682 | MOCK_METHOD3(generateClientCompositionRequests, |
| 2683 | std::vector<renderengine::LayerSettings>(bool, Region&, ui::Dataspace)); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 2684 | MOCK_METHOD2(appendRegionFlashRequests, |
| 2685 | void(const Region&, std::vector<renderengine::LayerSettings>&)); |
| 2686 | MOCK_METHOD1(setExpensiveRenderingExpected, void(bool)); |
| 2687 | }; |
| 2688 | |
| 2689 | OutputComposeSurfacesTest() { |
| 2690 | mOutput.setDisplayColorProfileForTest( |
| 2691 | std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile)); |
| 2692 | mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface)); |
| 2693 | |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 2694 | mOutput.editState().frame = kDefaultOutputFrame; |
| 2695 | mOutput.editState().viewport = kDefaultOutputViewport; |
| 2696 | mOutput.editState().scissor = kDefaultOutputScissor; |
| 2697 | mOutput.editState().transform = ui::Transform{kDefaultOutputOrientation}; |
| 2698 | mOutput.editState().orientation = kDefaultOutputOrientation; |
| 2699 | mOutput.editState().dataspace = kDefaultOutputDataspace; |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 2700 | mOutput.editState().colorTransformMatrix = kDefaultColorTransformMat; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 2701 | mOutput.editState().isSecure = true; |
| 2702 | mOutput.editState().needsFiltering = false; |
| 2703 | mOutput.editState().usesClientComposition = true; |
| 2704 | mOutput.editState().usesDeviceComposition = false; |
| 2705 | |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 2706 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(2u)); |
| 2707 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0u)) |
| 2708 | .WillRepeatedly(Return(&mOutputLayer1)); |
| 2709 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(1u)) |
| 2710 | .WillRepeatedly(Return(&mOutputLayer2)); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 2711 | EXPECT_CALL(mOutput, getCompositionEngine()).WillRepeatedly(ReturnRef(mCompositionEngine)); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 2712 | EXPECT_CALL(mCompositionEngine, getRenderEngine()).WillRepeatedly(ReturnRef(mRenderEngine)); |
Alec Mouri | e4034bb | 2019-11-19 12:45:54 -0800 | [diff] [blame] | 2713 | EXPECT_CALL(mCompositionEngine, getTimeStats()) |
| 2714 | .WillRepeatedly(ReturnRef(*mTimeStats.get())); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 2715 | } |
| 2716 | |
| 2717 | StrictMock<mock::CompositionEngine> mCompositionEngine; |
| 2718 | StrictMock<renderengine::mock::RenderEngine> mRenderEngine; |
Alec Mouri | e4034bb | 2019-11-19 12:45:54 -0800 | [diff] [blame] | 2719 | // TODO: make this is a proper mock. |
| 2720 | std::shared_ptr<TimeStats> mTimeStats = std::make_shared<android::impl::TimeStats>(); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 2721 | mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>(); |
| 2722 | mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>(); |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 2723 | StrictMock<mock::OutputLayer> mOutputLayer1; |
| 2724 | StrictMock<mock::OutputLayer> mOutputLayer2; |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 2725 | StrictMock<OutputPartialMock> mOutput; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 2726 | sp<GraphicBuffer> mOutputBuffer = new GraphicBuffer(); |
| 2727 | }; |
| 2728 | |
| 2729 | const Rect OutputComposeSurfacesTest::kDefaultOutputFrame{1001, 1002, 1003, 1004}; |
| 2730 | const Rect OutputComposeSurfacesTest::kDefaultOutputViewport{1005, 1006, 1007, 1008}; |
| 2731 | const Rect OutputComposeSurfacesTest::kDefaultOutputScissor{1009, 1010, 1011, 1012}; |
| 2732 | const mat4 OutputComposeSurfacesTest::kDefaultColorTransformMat{mat4() * 0.5}; |
| 2733 | |
| 2734 | // TODO(b/121291683): Expand unit test coverage for composeSurfaces beyond these |
| 2735 | // basic tests. |
| 2736 | |
| 2737 | TEST_F(OutputComposeSurfacesTest, doesNothingIfNoClientComposition) { |
| 2738 | mOutput.editState().usesClientComposition = false; |
| 2739 | |
| 2740 | Region debugRegion; |
Lloyd Pique | d3d6988 | 2019-02-28 16:03:46 -0800 | [diff] [blame] | 2741 | std::optional<base::unique_fd> readyFence = mOutput.composeSurfaces(debugRegion); |
| 2742 | EXPECT_TRUE(readyFence); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 2743 | } |
| 2744 | |
| 2745 | TEST_F(OutputComposeSurfacesTest, worksIfNoClientLayersQueued) { |
| 2746 | const Region kDebugRegion{Rect{100, 101, 102, 103}}; |
| 2747 | |
| 2748 | constexpr float kDefaultMaxLuminance = 1.0f; |
| 2749 | constexpr float kDefaultAvgLuminance = 0.7f; |
| 2750 | constexpr float kDefaultMinLuminance = 0.1f; |
| 2751 | HdrCapabilities HdrCapabilities{{}, |
| 2752 | kDefaultMaxLuminance, |
| 2753 | kDefaultAvgLuminance, |
| 2754 | kDefaultMinLuminance}; |
| 2755 | |
| 2756 | EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillOnce(Return(false)); |
| 2757 | EXPECT_CALL(mRenderEngine, drawLayers(_, _, _, true, _, _)).Times(1); |
| 2758 | |
| 2759 | EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillOnce(Return(true)); |
| 2760 | EXPECT_CALL(*mDisplayColorProfile, getHdrCapabilities()).WillOnce(ReturnRef(HdrCapabilities)); |
| 2761 | |
| 2762 | EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillOnce(Return(mOutputBuffer)); |
| 2763 | |
| 2764 | EXPECT_CALL(mOutput, getSkipColorTransform()).WillOnce(Return(false)); |
Vishnu Nair | 3a7346c | 2019-12-04 08:09:09 -0800 | [diff] [blame] | 2765 | EXPECT_CALL(mOutput, generateClientCompositionRequests(false, _, _)).Times(1); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 2766 | EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _)).Times(1); |
| 2767 | EXPECT_CALL(mOutput, setExpensiveRenderingExpected(true)).Times(1); |
| 2768 | EXPECT_CALL(mOutput, setExpensiveRenderingExpected(false)).Times(1); |
| 2769 | |
Lloyd Pique | d3d6988 | 2019-02-28 16:03:46 -0800 | [diff] [blame] | 2770 | std::optional<base::unique_fd> readyFence = mOutput.composeSurfaces(kDebugRegion); |
| 2771 | EXPECT_TRUE(readyFence); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 2772 | } |
| 2773 | |
| 2774 | /* |
| 2775 | * Output::generateClientCompositionRequests() |
| 2776 | */ |
| 2777 | |
| 2778 | struct GenerateClientCompositionRequestsTest : public testing::Test { |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 2779 | struct OutputPartialMock : public OutputPartialMockBase { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 2780 | // compositionengine::Output overrides |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 2781 | std::vector<renderengine::LayerSettings> generateClientCompositionRequests( |
Vishnu Nair | 3a7346c | 2019-12-04 08:09:09 -0800 | [diff] [blame] | 2782 | bool supportsProtectedContent, Region& clearRegion, |
| 2783 | ui::Dataspace dataspace) override { |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 2784 | return impl::Output::generateClientCompositionRequests(supportsProtectedContent, |
Vishnu Nair | 3a7346c | 2019-12-04 08:09:09 -0800 | [diff] [blame] | 2785 | clearRegion, dataspace); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 2786 | } |
| 2787 | }; |
| 2788 | |
| 2789 | GenerateClientCompositionRequestsTest() { |
| 2790 | mOutput.setDisplayColorProfileForTest( |
| 2791 | std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile)); |
| 2792 | mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface)); |
| 2793 | } |
| 2794 | |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 2795 | mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>(); |
| 2796 | mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>(); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 2797 | StrictMock<OutputPartialMock> mOutput; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 2798 | }; |
| 2799 | |
| 2800 | // TODO(b/121291683): Add more unit test coverage for generateClientCompositionRequests |
| 2801 | |
| 2802 | TEST_F(GenerateClientCompositionRequestsTest, worksForLandscapeModeSplitScreen) { |
| 2803 | // In split-screen landscape mode, the screen is rotated 90 degrees, with |
| 2804 | // one layer on the left covering the left side of the output, and one layer |
| 2805 | // on the right covering that side of the output. |
| 2806 | |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 2807 | StrictMock<mock::OutputLayer> leftOutputLayer; |
| 2808 | StrictMock<mock::OutputLayer> rightOutputLayer; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 2809 | |
| 2810 | StrictMock<mock::Layer> leftLayer; |
| 2811 | StrictMock<mock::LayerFE> leftLayerFE; |
| 2812 | StrictMock<mock::Layer> rightLayer; |
| 2813 | StrictMock<mock::LayerFE> rightLayerFE; |
| 2814 | |
| 2815 | impl::OutputLayerCompositionState leftOutputLayerState; |
| 2816 | leftOutputLayerState.clearClientTarget = false; |
Lloyd Pique | a246866 | 2019-03-07 21:31:06 -0800 | [diff] [blame] | 2817 | leftOutputLayerState.visibleRegion = Region{Rect{0, 0, 1000, 1000}}; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 2818 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 2819 | LayerFECompositionState leftLayerFEState; |
| 2820 | leftLayerFEState.isOpaque = true; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 2821 | |
| 2822 | const half3 leftLayerColor{1.f, 0.f, 0.f}; |
| 2823 | renderengine::LayerSettings leftLayerRESettings; |
| 2824 | leftLayerRESettings.source.solidColor = leftLayerColor; |
| 2825 | |
| 2826 | impl::OutputLayerCompositionState rightOutputLayerState; |
| 2827 | rightOutputLayerState.clearClientTarget = false; |
Lloyd Pique | a246866 | 2019-03-07 21:31:06 -0800 | [diff] [blame] | 2828 | rightOutputLayerState.visibleRegion = Region{Rect{1000, 0, 2000, 1000}}; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 2829 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 2830 | LayerFECompositionState rightLayerFEState; |
| 2831 | rightLayerFEState.isOpaque = true; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 2832 | |
| 2833 | const half3 rightLayerColor{0.f, 1.f, 0.f}; |
| 2834 | renderengine::LayerSettings rightLayerRESettings; |
| 2835 | rightLayerRESettings.source.solidColor = rightLayerColor; |
| 2836 | |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 2837 | EXPECT_CALL(leftOutputLayer, getState()).WillRepeatedly(ReturnRef(leftOutputLayerState)); |
| 2838 | EXPECT_CALL(leftOutputLayer, getLayer()).WillRepeatedly(ReturnRef(leftLayer)); |
| 2839 | EXPECT_CALL(leftOutputLayer, getLayerFE()).WillRepeatedly(ReturnRef(leftLayerFE)); |
| 2840 | EXPECT_CALL(leftOutputLayer, requiresClientComposition()).WillRepeatedly(Return(true)); |
| 2841 | EXPECT_CALL(leftOutputLayer, needsFiltering()).WillRepeatedly(Return(false)); |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 2842 | EXPECT_CALL(leftLayer, getFEState()).WillRepeatedly(ReturnRef(leftLayerFEState)); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 2843 | EXPECT_CALL(leftLayerFE, prepareClientComposition(_)).WillOnce(Return(leftLayerRESettings)); |
Vishnu Nair | 3a7346c | 2019-12-04 08:09:09 -0800 | [diff] [blame] | 2844 | EXPECT_CALL(leftLayerFE, prepareShadowClientComposition(_, _, _)) |
| 2845 | .WillOnce(Return(std::optional<renderengine::LayerSettings>())); |
Adithya Srinivasan | b69e076 | 2019-11-11 18:39:53 -0800 | [diff] [blame] | 2846 | EXPECT_CALL(leftOutputLayer, editState()).WillRepeatedly(ReturnRef(leftOutputLayerState)); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 2847 | |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 2848 | EXPECT_CALL(rightOutputLayer, getState()).WillRepeatedly(ReturnRef(rightOutputLayerState)); |
| 2849 | EXPECT_CALL(rightOutputLayer, getLayer()).WillRepeatedly(ReturnRef(rightLayer)); |
| 2850 | EXPECT_CALL(rightOutputLayer, getLayerFE()).WillRepeatedly(ReturnRef(rightLayerFE)); |
| 2851 | EXPECT_CALL(rightOutputLayer, requiresClientComposition()).WillRepeatedly(Return(true)); |
| 2852 | EXPECT_CALL(rightOutputLayer, needsFiltering()).WillRepeatedly(Return(false)); |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 2853 | EXPECT_CALL(rightLayer, getFEState()).WillRepeatedly(ReturnRef(rightLayerFEState)); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 2854 | EXPECT_CALL(rightLayerFE, prepareClientComposition(_)).WillOnce(Return(rightLayerRESettings)); |
Vishnu Nair | 3a7346c | 2019-12-04 08:09:09 -0800 | [diff] [blame] | 2855 | EXPECT_CALL(rightLayerFE, prepareShadowClientComposition(_, _, _)) |
| 2856 | .WillOnce(Return(std::optional<renderengine::LayerSettings>())); |
Adithya Srinivasan | b69e076 | 2019-11-11 18:39:53 -0800 | [diff] [blame] | 2857 | EXPECT_CALL(rightOutputLayer, editState()).WillRepeatedly(ReturnRef(rightOutputLayerState)); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 2858 | |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 2859 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(2u)); |
| 2860 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0u)) |
| 2861 | .WillRepeatedly(Return(&leftOutputLayer)); |
| 2862 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(1u)) |
| 2863 | .WillRepeatedly(Return(&rightOutputLayer)); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 2864 | |
| 2865 | const Rect kPortraitFrame(0, 0, 1000, 2000); |
| 2866 | const Rect kPortraitViewport(0, 0, 2000, 1000); |
| 2867 | const Rect kPortraitScissor(0, 0, 1000, 2000); |
| 2868 | const uint32_t kPortraitOrientation = TR_ROT_90; |
| 2869 | |
| 2870 | mOutput.editState().frame = kPortraitFrame; |
| 2871 | mOutput.editState().viewport = kPortraitViewport; |
| 2872 | mOutput.editState().scissor = kPortraitScissor; |
| 2873 | mOutput.editState().transform = ui::Transform{kPortraitOrientation}; |
| 2874 | mOutput.editState().orientation = kPortraitOrientation; |
| 2875 | mOutput.editState().needsFiltering = true; |
| 2876 | mOutput.editState().isSecure = false; |
| 2877 | |
| 2878 | constexpr bool supportsProtectedContent = false; |
| 2879 | Region clearRegion; |
Vishnu Nair | 3a7346c | 2019-12-04 08:09:09 -0800 | [diff] [blame] | 2880 | auto requests = mOutput.generateClientCompositionRequests(supportsProtectedContent, clearRegion, |
| 2881 | mOutput.getState().targetDataspace); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 2882 | |
| 2883 | ASSERT_EQ(2u, requests.size()); |
| 2884 | EXPECT_EQ(leftLayerColor, requests[0].source.solidColor); |
| 2885 | EXPECT_EQ(rightLayerColor, requests[1].source.solidColor); |
| 2886 | } |
| 2887 | |
| 2888 | TEST_F(GenerateClientCompositionRequestsTest, ignoresLayersThatDoNotIntersectWithViewport) { |
| 2889 | // Layers whose visible region does not intersect with the viewport will be |
| 2890 | // skipped when generating client composition request state. |
| 2891 | |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 2892 | StrictMock<mock::OutputLayer> outputLayer; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 2893 | StrictMock<mock::Layer> layer; |
| 2894 | StrictMock<mock::LayerFE> layerFE; |
| 2895 | |
| 2896 | impl::OutputLayerCompositionState outputLayerState; |
| 2897 | outputLayerState.clearClientTarget = false; |
Lloyd Pique | a246866 | 2019-03-07 21:31:06 -0800 | [diff] [blame] | 2898 | outputLayerState.visibleRegion = Region{Rect{3000, 0, 4000, 1000}}; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 2899 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 2900 | LayerFECompositionState layerFEState; |
| 2901 | layerFEState.isOpaque = true; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 2902 | |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 2903 | EXPECT_CALL(outputLayer, getState()).WillRepeatedly(ReturnRef(outputLayerState)); |
| 2904 | EXPECT_CALL(outputLayer, getLayer()).WillRepeatedly(ReturnRef(layer)); |
| 2905 | EXPECT_CALL(outputLayer, getLayerFE()).WillRepeatedly(ReturnRef(layerFE)); |
| 2906 | EXPECT_CALL(outputLayer, requiresClientComposition()).WillRepeatedly(Return(true)); |
| 2907 | EXPECT_CALL(outputLayer, needsFiltering()).WillRepeatedly(Return(false)); |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 2908 | EXPECT_CALL(layer, getFEState()).WillRepeatedly(ReturnRef(layerFEState)); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 2909 | EXPECT_CALL(layerFE, prepareClientComposition(_)).Times(0); |
Adithya Srinivasan | b69e076 | 2019-11-11 18:39:53 -0800 | [diff] [blame] | 2910 | EXPECT_CALL(outputLayer, editState()).WillRepeatedly(ReturnRef(outputLayerState)); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 2911 | |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 2912 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(1u)); |
| 2913 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0u)).WillRepeatedly(Return(&outputLayer)); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 2914 | |
| 2915 | const Rect kPortraitFrame(0, 0, 1000, 2000); |
| 2916 | const Rect kPortraitViewport(0, 0, 2000, 1000); |
| 2917 | const Rect kPortraitScissor(0, 0, 1000, 2000); |
| 2918 | const uint32_t kPortraitOrientation = TR_ROT_90; |
| 2919 | |
| 2920 | mOutput.editState().frame = kPortraitFrame; |
| 2921 | mOutput.editState().viewport = kPortraitViewport; |
| 2922 | mOutput.editState().scissor = kPortraitScissor; |
| 2923 | mOutput.editState().transform = ui::Transform{kPortraitOrientation}; |
| 2924 | mOutput.editState().orientation = kPortraitOrientation; |
| 2925 | mOutput.editState().needsFiltering = true; |
| 2926 | mOutput.editState().isSecure = false; |
| 2927 | |
| 2928 | constexpr bool supportsProtectedContent = false; |
| 2929 | Region clearRegion; |
Vishnu Nair | 3a7346c | 2019-12-04 08:09:09 -0800 | [diff] [blame] | 2930 | auto requests = mOutput.generateClientCompositionRequests(supportsProtectedContent, clearRegion, |
| 2931 | mOutput.getState().targetDataspace); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 2932 | |
| 2933 | EXPECT_EQ(0u, requests.size()); |
| 2934 | } |
| 2935 | |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 2936 | TEST_F(GenerateClientCompositionRequestsTest, clearsDeviceLayesAfterFirst) { |
| 2937 | // If client composition is performed with some layers set to use device |
| 2938 | // composition, device layers after the first layer (device or client) will |
| 2939 | // clear the frame buffer if they are opaque and if that layer has a flag |
| 2940 | // set to do so. The first layer is skipped as the frame buffer is already |
| 2941 | // expected to be clear. |
| 2942 | |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 2943 | StrictMock<mock::OutputLayer> leftOutputLayer; |
| 2944 | StrictMock<mock::OutputLayer> rightOutputLayer; |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 2945 | |
| 2946 | StrictMock<mock::Layer> leftLayer; |
| 2947 | StrictMock<mock::LayerFE> leftLayerFE; |
| 2948 | StrictMock<mock::Layer> rightLayer; |
| 2949 | StrictMock<mock::LayerFE> rightLayerFE; |
| 2950 | |
| 2951 | impl::OutputLayerCompositionState leftOutputLayerState; |
| 2952 | leftOutputLayerState.clearClientTarget = true; |
Lloyd Pique | a246866 | 2019-03-07 21:31:06 -0800 | [diff] [blame] | 2953 | leftOutputLayerState.visibleRegion = Region{Rect{0, 0, 1000, 1000}}; |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 2954 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 2955 | LayerFECompositionState leftLayerFEState; |
| 2956 | leftLayerFEState.isOpaque = true; |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 2957 | |
| 2958 | impl::OutputLayerCompositionState rightOutputLayerState; |
| 2959 | rightOutputLayerState.clearClientTarget = true; |
Lloyd Pique | a246866 | 2019-03-07 21:31:06 -0800 | [diff] [blame] | 2960 | rightOutputLayerState.visibleRegion = Region{Rect{1000, 0, 2000, 1000}}; |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 2961 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 2962 | LayerFECompositionState rightLayerFEState; |
| 2963 | rightLayerFEState.isOpaque = true; |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 2964 | |
| 2965 | const half3 rightLayerColor{0.f, 1.f, 0.f}; |
| 2966 | renderengine::LayerSettings rightLayerRESettings; |
| 2967 | rightLayerRESettings.geometry.boundaries = FloatRect{456, 0, 0, 0}; |
| 2968 | rightLayerRESettings.source.solidColor = rightLayerColor; |
| 2969 | |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 2970 | EXPECT_CALL(leftOutputLayer, getState()).WillRepeatedly(ReturnRef(leftOutputLayerState)); |
| 2971 | EXPECT_CALL(leftOutputLayer, getLayer()).WillRepeatedly(ReturnRef(leftLayer)); |
| 2972 | EXPECT_CALL(leftOutputLayer, getLayerFE()).WillRepeatedly(ReturnRef(leftLayerFE)); |
| 2973 | EXPECT_CALL(leftOutputLayer, requiresClientComposition()).WillRepeatedly(Return(false)); |
| 2974 | EXPECT_CALL(leftOutputLayer, needsFiltering()).WillRepeatedly(Return(false)); |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 2975 | EXPECT_CALL(leftLayer, getFEState()).WillRepeatedly(ReturnRef(leftLayerFEState)); |
Adithya Srinivasan | b69e076 | 2019-11-11 18:39:53 -0800 | [diff] [blame] | 2976 | EXPECT_CALL(leftOutputLayer, editState()).WillRepeatedly(ReturnRef(leftOutputLayerState)); |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 2977 | |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 2978 | EXPECT_CALL(rightOutputLayer, getState()).WillRepeatedly(ReturnRef(rightOutputLayerState)); |
| 2979 | EXPECT_CALL(rightOutputLayer, getLayer()).WillRepeatedly(ReturnRef(rightLayer)); |
| 2980 | EXPECT_CALL(rightOutputLayer, getLayerFE()).WillRepeatedly(ReturnRef(rightLayerFE)); |
| 2981 | EXPECT_CALL(rightOutputLayer, requiresClientComposition()).WillRepeatedly(Return(false)); |
| 2982 | EXPECT_CALL(rightOutputLayer, needsFiltering()).WillRepeatedly(Return(false)); |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 2983 | EXPECT_CALL(rightLayer, getFEState()).WillRepeatedly(ReturnRef(rightLayerFEState)); |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 2984 | EXPECT_CALL(rightLayerFE, prepareClientComposition(_)).WillOnce(Return(rightLayerRESettings)); |
Adithya Srinivasan | b69e076 | 2019-11-11 18:39:53 -0800 | [diff] [blame] | 2985 | EXPECT_CALL(rightOutputLayer, editState()).WillRepeatedly(ReturnRef(rightOutputLayerState)); |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 2986 | |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 2987 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(2u)); |
| 2988 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0u)) |
| 2989 | .WillRepeatedly(Return(&leftOutputLayer)); |
| 2990 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(1u)) |
| 2991 | .WillRepeatedly(Return(&rightOutputLayer)); |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 2992 | |
| 2993 | const Rect kPortraitFrame(0, 0, 1000, 2000); |
| 2994 | const Rect kPortraitViewport(0, 0, 2000, 1000); |
| 2995 | const Rect kPortraitScissor(0, 0, 1000, 2000); |
| 2996 | const uint32_t kPortraitOrientation = TR_ROT_90; |
| 2997 | |
| 2998 | mOutput.editState().frame = kPortraitFrame; |
| 2999 | mOutput.editState().viewport = kPortraitViewport; |
| 3000 | mOutput.editState().scissor = kPortraitScissor; |
| 3001 | mOutput.editState().transform = ui::Transform{kPortraitOrientation}; |
| 3002 | mOutput.editState().orientation = kPortraitOrientation; |
| 3003 | mOutput.editState().needsFiltering = true; |
| 3004 | mOutput.editState().isSecure = false; |
| 3005 | |
| 3006 | constexpr bool supportsProtectedContent = false; |
| 3007 | Region clearRegion; |
Vishnu Nair | 3a7346c | 2019-12-04 08:09:09 -0800 | [diff] [blame] | 3008 | auto requests = mOutput.generateClientCompositionRequests(supportsProtectedContent, clearRegion, |
| 3009 | mOutput.getState().targetDataspace); |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 3010 | |
| 3011 | const half3 clearColor{0.f, 0.f, 0.f}; |
| 3012 | |
| 3013 | ASSERT_EQ(1u, requests.size()); |
| 3014 | EXPECT_EQ(456.f, requests[0].geometry.boundaries.left); |
| 3015 | EXPECT_EQ(clearColor, requests[0].source.solidColor); |
| 3016 | } |
| 3017 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 3018 | } // namespace |
| 3019 | } // namespace android::compositionengine |