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