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