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