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