Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include <cmath> |
| 18 | |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 19 | #include <android-base/stringprintf.h> |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 20 | #include <compositionengine/LayerFECompositionState.h> |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 21 | #include <compositionengine/impl/Output.h> |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 22 | #include <compositionengine/impl/OutputCompositionState.h> |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 23 | #include <compositionengine/impl/OutputLayerCompositionState.h> |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 24 | #include <compositionengine/mock/CompositionEngine.h> |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 25 | #include <compositionengine/mock/DisplayColorProfile.h> |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 26 | #include <compositionengine/mock/Layer.h> |
| 27 | #include <compositionengine/mock/LayerFE.h> |
| 28 | #include <compositionengine/mock/OutputLayer.h> |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 29 | #include <compositionengine/mock/RenderSurface.h> |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 30 | #include <gtest/gtest.h> |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 31 | #include <renderengine/mock/RenderEngine.h> |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 32 | #include <ui/Rect.h> |
| 33 | #include <ui/Region.h> |
| 34 | |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 35 | #include "CallOrderStateMachineHelper.h" |
Lloyd Pique | 07178e3 | 2019-11-19 19:15:26 -0800 | [diff] [blame^] | 36 | #include "MockHWC2.h" |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 37 | #include "RegionMatcher.h" |
| 38 | #include "TransformMatcher.h" |
| 39 | |
| 40 | namespace android::compositionengine { |
| 41 | namespace { |
| 42 | |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 43 | using testing::_; |
Lloyd Pique | 03561a6 | 2019-11-19 18:34:52 -0800 | [diff] [blame] | 44 | using testing::ByMove; |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 45 | using testing::DoAll; |
Lloyd Pique | 07178e3 | 2019-11-19 19:15:26 -0800 | [diff] [blame^] | 46 | using testing::Eq; |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 47 | using testing::InSequence; |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 48 | using testing::Mock; |
Lloyd Pique | 07178e3 | 2019-11-19 19:15:26 -0800 | [diff] [blame^] | 49 | using testing::Property; |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 50 | using testing::Ref; |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 51 | using testing::Return; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 52 | using testing::ReturnRef; |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 53 | using testing::SetArgPointee; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 54 | using testing::StrictMock; |
| 55 | |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 56 | constexpr auto TR_IDENT = 0u; |
| 57 | constexpr auto TR_ROT_90 = HAL_TRANSFORM_ROT_90; |
| 58 | |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 59 | const mat4 kIdentity; |
| 60 | const mat4 kNonIdentityHalf = mat4() * 0.5; |
| 61 | const mat4 kNonIdentityQuarter = mat4() * 0.25; |
| 62 | |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 63 | constexpr OutputColorSetting kVendorSpecifiedOutputColorSetting = |
| 64 | static_cast<OutputColorSetting>(0x100); |
| 65 | |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 66 | struct OutputPartialMockBase : public impl::Output { |
| 67 | // compositionengine::Output overrides |
| 68 | const OutputCompositionState& getState() const override { return mState; } |
| 69 | OutputCompositionState& editState() override { return mState; } |
| 70 | |
| 71 | // Use mocks for all the remaining virtual functions |
| 72 | // not implemented by the base implementation class. |
| 73 | MOCK_CONST_METHOD0(getOutputLayerCount, size_t()); |
| 74 | MOCK_CONST_METHOD1(getOutputLayerOrderedByZByIndex, compositionengine::OutputLayer*(size_t)); |
| 75 | MOCK_METHOD3(ensureOutputLayer, |
| 76 | compositionengine::OutputLayer*(std::optional<size_t>, |
| 77 | const std::shared_ptr<compositionengine::Layer>&, |
| 78 | const sp<LayerFE>&)); |
| 79 | MOCK_METHOD0(finalizePendingOutputLayers, void()); |
| 80 | MOCK_METHOD0(clearOutputLayers, void()); |
| 81 | MOCK_CONST_METHOD1(dumpState, void(std::string&)); |
| 82 | MOCK_CONST_METHOD0(getCompositionEngine, const CompositionEngine&()); |
| 83 | MOCK_METHOD2(injectOutputLayerForTest, |
| 84 | compositionengine::OutputLayer*(const std::shared_ptr<compositionengine::Layer>&, |
| 85 | const sp<LayerFE>&)); |
| 86 | MOCK_METHOD1(injectOutputLayerForTest, void(std::unique_ptr<OutputLayer>)); |
| 87 | |
| 88 | impl::OutputCompositionState mState; |
| 89 | }; |
| 90 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 91 | struct OutputTest : public testing::Test { |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 92 | class Output : public impl::Output { |
| 93 | public: |
| 94 | using impl::Output::injectOutputLayerForTest; |
| 95 | virtual void injectOutputLayerForTest(std::unique_ptr<compositionengine::OutputLayer>) = 0; |
| 96 | }; |
| 97 | |
| 98 | static std::shared_ptr<Output> createOutput( |
| 99 | const compositionengine::CompositionEngine& compositionEngine) { |
| 100 | return impl::createOutputTemplated<Output>(compositionEngine); |
| 101 | } |
| 102 | |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 103 | OutputTest() { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 104 | mOutput->setDisplayColorProfileForTest( |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 105 | std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile)); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 106 | mOutput->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface)); |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 107 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 108 | mOutput->editState().bounds = kDefaultDisplaySize; |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 109 | } |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 110 | |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 111 | static const Rect kDefaultDisplaySize; |
| 112 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 113 | StrictMock<mock::CompositionEngine> mCompositionEngine; |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 114 | mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>(); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 115 | mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>(); |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 116 | std::shared_ptr<Output> mOutput = createOutput(mCompositionEngine); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 117 | }; |
| 118 | |
Lloyd Pique | c0ee6ba | 2019-11-14 12:55:53 -0800 | [diff] [blame] | 119 | // Extension of the base test useful for checking interactions with the LayerFE |
| 120 | // functions to latch composition state. |
| 121 | struct OutputLatchFEStateTest : public OutputTest { |
| 122 | OutputLatchFEStateTest() { |
| 123 | EXPECT_CALL(*mOutputLayer1, getLayer()).WillRepeatedly(ReturnRef(mLayer1)); |
| 124 | EXPECT_CALL(*mOutputLayer2, getLayer()).WillRepeatedly(ReturnRef(mLayer2)); |
| 125 | EXPECT_CALL(*mOutputLayer3, getLayer()).WillRepeatedly(ReturnRef(mLayer3)); |
| 126 | |
| 127 | EXPECT_CALL(*mOutputLayer1, getLayerFE()).WillRepeatedly(ReturnRef(mLayer1FE)); |
| 128 | EXPECT_CALL(*mOutputLayer2, getLayerFE()).WillRepeatedly(ReturnRef(mLayer2FE)); |
| 129 | EXPECT_CALL(*mOutputLayer3, getLayerFE()).WillRepeatedly(ReturnRef(mLayer3FE)); |
| 130 | |
| 131 | EXPECT_CALL(mLayer1, editFEState()).WillRepeatedly(ReturnRef(mLayer1FEState)); |
| 132 | EXPECT_CALL(mLayer2, editFEState()).WillRepeatedly(ReturnRef(mLayer2FEState)); |
| 133 | EXPECT_CALL(mLayer3, editFEState()).WillRepeatedly(ReturnRef(mLayer3FEState)); |
| 134 | } |
| 135 | |
| 136 | void injectLayer(std::unique_ptr<mock::OutputLayer> layer) { |
| 137 | mOutput->injectOutputLayerForTest(std::unique_ptr<OutputLayer>(layer.release())); |
| 138 | } |
| 139 | |
| 140 | std::unique_ptr<mock::OutputLayer> mOutputLayer1{new StrictMock<mock::OutputLayer>}; |
| 141 | std::unique_ptr<mock::OutputLayer> mOutputLayer2{new StrictMock<mock::OutputLayer>}; |
| 142 | std::unique_ptr<mock::OutputLayer> mOutputLayer3{new StrictMock<mock::OutputLayer>}; |
| 143 | |
| 144 | StrictMock<mock::Layer> mLayer1; |
| 145 | StrictMock<mock::Layer> mLayer2; |
| 146 | StrictMock<mock::Layer> mLayer3; |
| 147 | |
| 148 | StrictMock<mock::LayerFE> mLayer1FE; |
| 149 | StrictMock<mock::LayerFE> mLayer2FE; |
| 150 | StrictMock<mock::LayerFE> mLayer3FE; |
| 151 | |
| 152 | LayerFECompositionState mLayer1FEState; |
| 153 | LayerFECompositionState mLayer2FEState; |
| 154 | LayerFECompositionState mLayer3FEState; |
| 155 | }; |
| 156 | |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 157 | const Rect OutputTest::kDefaultDisplaySize{100, 200}; |
| 158 | |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 159 | using ColorProfile = compositionengine::Output::ColorProfile; |
| 160 | |
| 161 | void dumpColorProfile(ColorProfile profile, std::string& result, const char* name) { |
| 162 | android::base::StringAppendF(&result, "%s (%s[%d] %s[%d] %s[%d] %s[%d]) ", name, |
| 163 | toString(profile.mode).c_str(), profile.mode, |
| 164 | toString(profile.dataspace).c_str(), profile.dataspace, |
| 165 | toString(profile.renderIntent).c_str(), profile.renderIntent, |
| 166 | toString(profile.colorSpaceAgnosticDataspace).c_str(), |
| 167 | profile.colorSpaceAgnosticDataspace); |
| 168 | } |
| 169 | |
| 170 | // Checks for a ColorProfile match |
| 171 | MATCHER_P(ColorProfileEq, expected, "") { |
| 172 | std::string buf; |
| 173 | buf.append("ColorProfiles are not equal\n"); |
| 174 | dumpColorProfile(expected, buf, "expected value"); |
| 175 | dumpColorProfile(arg, buf, "actual value"); |
| 176 | *result_listener << buf; |
| 177 | |
| 178 | return (expected.mode == arg.mode) && (expected.dataspace == arg.dataspace) && |
| 179 | (expected.renderIntent == arg.renderIntent) && |
| 180 | (expected.colorSpaceAgnosticDataspace == arg.colorSpaceAgnosticDataspace); |
| 181 | } |
| 182 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 183 | /* |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 184 | * Basic construction |
| 185 | */ |
| 186 | |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 187 | TEST_F(OutputTest, canInstantiateOutput) { |
| 188 | // The validation check checks each required component. |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 189 | EXPECT_CALL(*mDisplayColorProfile, isValid()).WillOnce(Return(true)); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 190 | EXPECT_CALL(*mRenderSurface, isValid()).WillOnce(Return(true)); |
| 191 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 192 | EXPECT_TRUE(mOutput->isValid()); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 193 | |
| 194 | // If we take away the required components, it is no longer valid. |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 195 | mOutput->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>()); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 196 | |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 197 | EXPECT_CALL(*mDisplayColorProfile, isValid()).WillOnce(Return(true)); |
| 198 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 199 | EXPECT_FALSE(mOutput->isValid()); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 200 | } |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 201 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 202 | /* |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 203 | * Output::setCompositionEnabled() |
| 204 | */ |
| 205 | |
| 206 | TEST_F(OutputTest, setCompositionEnabledDoesNothingIfAlreadyEnabled) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 207 | mOutput->editState().isEnabled = true; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 208 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 209 | mOutput->setCompositionEnabled(true); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 210 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 211 | EXPECT_TRUE(mOutput->getState().isEnabled); |
| 212 | EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region())); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | TEST_F(OutputTest, setCompositionEnabledSetsEnabledAndDirtiesEntireOutput) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 216 | mOutput->editState().isEnabled = false; |
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 | mOutput->setCompositionEnabled(true); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 219 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 220 | EXPECT_TRUE(mOutput->getState().isEnabled); |
| 221 | EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize))); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | TEST_F(OutputTest, setCompositionEnabledSetsDisabledAndDirtiesEntireOutput) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 225 | mOutput->editState().isEnabled = 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 | mOutput->setCompositionEnabled(false); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 228 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 229 | EXPECT_FALSE(mOutput->getState().isEnabled); |
| 230 | EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize))); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 231 | } |
| 232 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 233 | /* |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 234 | * Output::setProjection() |
| 235 | */ |
| 236 | |
| 237 | TEST_F(OutputTest, setProjectionTriviallyWorks) { |
| 238 | const ui::Transform transform{ui::Transform::ROT_180}; |
| 239 | const int32_t orientation = 123; |
| 240 | const Rect frame{1, 2, 3, 4}; |
| 241 | const Rect viewport{5, 6, 7, 8}; |
| 242 | const Rect scissor{9, 10, 11, 12}; |
| 243 | const bool needsFiltering = true; |
| 244 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 245 | mOutput->setProjection(transform, orientation, frame, viewport, scissor, needsFiltering); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 246 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 247 | EXPECT_THAT(mOutput->getState().transform, TransformEq(transform)); |
| 248 | EXPECT_EQ(orientation, mOutput->getState().orientation); |
| 249 | EXPECT_EQ(frame, mOutput->getState().frame); |
| 250 | EXPECT_EQ(viewport, mOutput->getState().viewport); |
| 251 | EXPECT_EQ(scissor, mOutput->getState().scissor); |
| 252 | EXPECT_EQ(needsFiltering, mOutput->getState().needsFiltering); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 253 | } |
| 254 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 255 | /* |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 256 | * Output::setBounds() |
| 257 | */ |
| 258 | |
| 259 | TEST_F(OutputTest, setBoundsSetsSizeAndDirtiesEntireOutput) { |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 260 | const ui::Size displaySize{200, 400}; |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 261 | |
| 262 | EXPECT_CALL(*mRenderSurface, setDisplaySize(displaySize)).Times(1); |
| 263 | EXPECT_CALL(*mRenderSurface, getSize()).WillOnce(ReturnRef(displaySize)); |
| 264 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 265 | mOutput->setBounds(displaySize); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 266 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 267 | EXPECT_EQ(Rect(displaySize), mOutput->getState().bounds); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 268 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 269 | EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(Rect(displaySize)))); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 270 | } |
| 271 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 272 | /* |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 273 | * Output::setLayerStackFilter() |
| 274 | */ |
| 275 | |
| 276 | TEST_F(OutputTest, setLayerStackFilterSetsFilterAndDirtiesEntireOutput) { |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 277 | const uint32_t layerStack = 123u; |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 278 | mOutput->setLayerStackFilter(layerStack, true); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 279 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 280 | EXPECT_TRUE(mOutput->getState().layerStackInternal); |
| 281 | EXPECT_EQ(layerStack, mOutput->getState().layerStackId); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 282 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 283 | EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize))); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 284 | } |
| 285 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 286 | /* |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 287 | * Output::setColorTransform |
| 288 | */ |
| 289 | |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 290 | TEST_F(OutputTest, setColorTransformWithNoChangeFlaggedSkipsUpdates) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 291 | mOutput->editState().colorTransformMatrix = kIdentity; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 292 | |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 293 | // If no colorTransformMatrix is set the update should be skipped. |
| 294 | CompositionRefreshArgs refreshArgs; |
| 295 | refreshArgs.colorTransformMatrix = std::nullopt; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 296 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 297 | mOutput->setColorTransform(refreshArgs); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 298 | |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 299 | // The internal state should be unchanged |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 300 | EXPECT_EQ(kIdentity, mOutput->getState().colorTransformMatrix); |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 301 | |
| 302 | // No dirty region should be set |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 303 | EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region())); |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 304 | } |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 305 | |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 306 | TEST_F(OutputTest, setColorTransformWithNoActualChangeSkipsUpdates) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 307 | mOutput->editState().colorTransformMatrix = kIdentity; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 308 | |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 309 | // Attempting to set the same colorTransformMatrix that is already set should |
| 310 | // also skip the update. |
| 311 | CompositionRefreshArgs refreshArgs; |
| 312 | refreshArgs.colorTransformMatrix = kIdentity; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 313 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 314 | mOutput->setColorTransform(refreshArgs); |
Lloyd Pique | 77f79a2 | 2019-04-29 15:55:40 -0700 | [diff] [blame] | 315 | |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 316 | // The internal state should be unchanged |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 317 | EXPECT_EQ(kIdentity, mOutput->getState().colorTransformMatrix); |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 318 | |
| 319 | // No dirty region should be set |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 320 | EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region())); |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | TEST_F(OutputTest, setColorTransformPerformsUpdateToIdentity) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 324 | mOutput->editState().colorTransformMatrix = kNonIdentityHalf; |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 325 | |
| 326 | // Setting a different colorTransformMatrix should perform the update. |
| 327 | CompositionRefreshArgs refreshArgs; |
| 328 | refreshArgs.colorTransformMatrix = kIdentity; |
| 329 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 330 | mOutput->setColorTransform(refreshArgs); |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 331 | |
| 332 | // The internal state should have been updated |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 333 | EXPECT_EQ(kIdentity, mOutput->getState().colorTransformMatrix); |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 334 | |
| 335 | // The dirtyRegion should be set to the full display size |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 336 | EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize))); |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 337 | } |
Lloyd Pique | 77f79a2 | 2019-04-29 15:55:40 -0700 | [diff] [blame] | 338 | |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 339 | TEST_F(OutputTest, setColorTransformPerformsUpdateForIdentityToHalf) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 340 | mOutput->editState().colorTransformMatrix = kIdentity; |
Lloyd Pique | 77f79a2 | 2019-04-29 15:55:40 -0700 | [diff] [blame] | 341 | |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 342 | // Setting a different colorTransformMatrix should perform the update. |
| 343 | CompositionRefreshArgs refreshArgs; |
| 344 | refreshArgs.colorTransformMatrix = kNonIdentityHalf; |
Lloyd Pique | 77f79a2 | 2019-04-29 15:55:40 -0700 | [diff] [blame] | 345 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 346 | mOutput->setColorTransform(refreshArgs); |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 347 | |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 348 | // The internal state should have been updated |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 349 | EXPECT_EQ(kNonIdentityHalf, mOutput->getState().colorTransformMatrix); |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 350 | |
| 351 | // The dirtyRegion should be set to the full display size |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 352 | EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize))); |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | TEST_F(OutputTest, setColorTransformPerformsUpdateForHalfToQuarter) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 356 | mOutput->editState().colorTransformMatrix = kNonIdentityHalf; |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 357 | |
| 358 | // Setting a different colorTransformMatrix should perform the update. |
| 359 | CompositionRefreshArgs refreshArgs; |
| 360 | refreshArgs.colorTransformMatrix = kNonIdentityQuarter; |
| 361 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 362 | mOutput->setColorTransform(refreshArgs); |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 363 | |
| 364 | // The internal state should have been updated |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 365 | EXPECT_EQ(kNonIdentityQuarter, mOutput->getState().colorTransformMatrix); |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 366 | |
| 367 | // The dirtyRegion should be set to the full display size |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 368 | EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize))); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 369 | } |
| 370 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 371 | /* |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 372 | * Output::setColorProfile |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 373 | */ |
| 374 | |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 375 | using OutputSetColorProfileTest = OutputTest; |
| 376 | |
| 377 | TEST_F(OutputSetColorProfileTest, setsStateAndDirtiesOutputIfChanged) { |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 378 | using ColorProfile = Output::ColorProfile; |
| 379 | |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 380 | EXPECT_CALL(*mDisplayColorProfile, |
| 381 | getTargetDataspace(ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3, |
| 382 | ui::Dataspace::UNKNOWN)) |
| 383 | .WillOnce(Return(ui::Dataspace::UNKNOWN)); |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 384 | EXPECT_CALL(*mRenderSurface, setBufferDataspace(ui::Dataspace::DISPLAY_P3)).Times(1); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 385 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 386 | mOutput->setColorProfile(ColorProfile{ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3, |
| 387 | ui::RenderIntent::TONE_MAP_COLORIMETRIC, |
| 388 | ui::Dataspace::UNKNOWN}); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 389 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 390 | EXPECT_EQ(ui::ColorMode::DISPLAY_P3, mOutput->getState().colorMode); |
| 391 | EXPECT_EQ(ui::Dataspace::DISPLAY_P3, mOutput->getState().dataspace); |
| 392 | EXPECT_EQ(ui::RenderIntent::TONE_MAP_COLORIMETRIC, mOutput->getState().renderIntent); |
| 393 | EXPECT_EQ(ui::Dataspace::UNKNOWN, mOutput->getState().targetDataspace); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 394 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 395 | EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize))); |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 396 | } |
| 397 | |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 398 | TEST_F(OutputSetColorProfileTest, doesNothingIfNoChange) { |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 399 | using ColorProfile = Output::ColorProfile; |
| 400 | |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 401 | EXPECT_CALL(*mDisplayColorProfile, |
| 402 | getTargetDataspace(ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3, |
| 403 | ui::Dataspace::UNKNOWN)) |
| 404 | .WillOnce(Return(ui::Dataspace::UNKNOWN)); |
| 405 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 406 | mOutput->editState().colorMode = ui::ColorMode::DISPLAY_P3; |
| 407 | mOutput->editState().dataspace = ui::Dataspace::DISPLAY_P3; |
| 408 | mOutput->editState().renderIntent = ui::RenderIntent::TONE_MAP_COLORIMETRIC; |
| 409 | mOutput->editState().targetDataspace = ui::Dataspace::UNKNOWN; |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 410 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 411 | mOutput->setColorProfile(ColorProfile{ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3, |
| 412 | ui::RenderIntent::TONE_MAP_COLORIMETRIC, |
| 413 | ui::Dataspace::UNKNOWN}); |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 414 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 415 | EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region())); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 416 | } |
| 417 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 418 | /* |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 419 | * Output::setRenderSurface() |
| 420 | */ |
| 421 | |
| 422 | TEST_F(OutputTest, setRenderSurfaceResetsBounds) { |
| 423 | const ui::Size newDisplaySize{640, 480}; |
| 424 | |
| 425 | mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>(); |
| 426 | EXPECT_CALL(*renderSurface, getSize()).WillOnce(ReturnRef(newDisplaySize)); |
| 427 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 428 | mOutput->setRenderSurface(std::unique_ptr<RenderSurface>(renderSurface)); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 429 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 430 | EXPECT_EQ(Rect(newDisplaySize), mOutput->getState().bounds); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 431 | } |
| 432 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 433 | /* |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 434 | * Output::getDirtyRegion() |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 435 | */ |
| 436 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 437 | TEST_F(OutputTest, getDirtyRegionWithRepaintEverythingTrue) { |
| 438 | const Rect viewport{100, 200}; |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 439 | mOutput->editState().viewport = viewport; |
| 440 | mOutput->editState().dirtyRegion.set(50, 300); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 441 | |
| 442 | { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 443 | Region result = mOutput->getDirtyRegion(true); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 444 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 445 | EXPECT_THAT(result, RegionEq(Region(viewport))); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 446 | } |
| 447 | } |
| 448 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 449 | TEST_F(OutputTest, getDirtyRegionWithRepaintEverythingFalse) { |
| 450 | const Rect viewport{100, 200}; |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 451 | mOutput->editState().viewport = viewport; |
| 452 | mOutput->editState().dirtyRegion.set(50, 300); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 453 | |
| 454 | { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 455 | Region result = mOutput->getDirtyRegion(false); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 456 | |
| 457 | // The dirtyRegion should be clipped to the display bounds. |
| 458 | EXPECT_THAT(result, RegionEq(Region(Rect(50, 200)))); |
| 459 | } |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 460 | } |
| 461 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 462 | /* |
Lloyd Pique | ef36b00 | 2019-01-23 17:52:04 -0800 | [diff] [blame] | 463 | * Output::belongsInOutput() |
| 464 | */ |
| 465 | |
| 466 | TEST_F(OutputTest, belongsInOutputFiltersAsExpected) { |
| 467 | const uint32_t layerStack1 = 123u; |
| 468 | const uint32_t layerStack2 = 456u; |
| 469 | |
| 470 | // If the output accepts layerStack1 and internal-only layers.... |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 471 | mOutput->setLayerStackFilter(layerStack1, true); |
Lloyd Pique | ef36b00 | 2019-01-23 17:52:04 -0800 | [diff] [blame] | 472 | |
Lloyd Pique | c668734 | 2019-03-07 21:34:57 -0800 | [diff] [blame] | 473 | // 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] | 474 | EXPECT_FALSE(mOutput->belongsInOutput(std::nullopt, false)); |
| 475 | EXPECT_FALSE(mOutput->belongsInOutput(std::nullopt, true)); |
Lloyd Pique | c668734 | 2019-03-07 21:34:57 -0800 | [diff] [blame] | 476 | |
Lloyd Pique | ef36b00 | 2019-01-23 17:52:04 -0800 | [diff] [blame] | 477 | // Any layer with layerStack1 belongs to it, internal-only or not. |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 478 | EXPECT_TRUE(mOutput->belongsInOutput(layerStack1, false)); |
| 479 | EXPECT_TRUE(mOutput->belongsInOutput(layerStack1, true)); |
| 480 | EXPECT_FALSE(mOutput->belongsInOutput(layerStack2, true)); |
| 481 | EXPECT_FALSE(mOutput->belongsInOutput(layerStack2, false)); |
Lloyd Pique | ef36b00 | 2019-01-23 17:52:04 -0800 | [diff] [blame] | 482 | |
| 483 | // If the output accepts layerStack21 but not internal-only layers... |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 484 | mOutput->setLayerStackFilter(layerStack1, false); |
Lloyd Pique | ef36b00 | 2019-01-23 17:52:04 -0800 | [diff] [blame] | 485 | |
| 486 | // Only non-internal layers with layerStack1 belong to it. |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 487 | EXPECT_TRUE(mOutput->belongsInOutput(layerStack1, false)); |
| 488 | EXPECT_FALSE(mOutput->belongsInOutput(layerStack1, true)); |
| 489 | EXPECT_FALSE(mOutput->belongsInOutput(layerStack2, true)); |
| 490 | EXPECT_FALSE(mOutput->belongsInOutput(layerStack2, false)); |
Lloyd Pique | ef36b00 | 2019-01-23 17:52:04 -0800 | [diff] [blame] | 491 | } |
| 492 | |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 493 | TEST_F(OutputTest, belongsInOutputFiltersLayersAsExpected) { |
| 494 | StrictMock<mock::Layer> layer; |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 495 | LayerFECompositionState layerFEState; |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 496 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 497 | EXPECT_CALL(layer, getFEState()).WillRepeatedly(ReturnRef(layerFEState)); |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 498 | |
| 499 | const uint32_t layerStack1 = 123u; |
| 500 | const uint32_t layerStack2 = 456u; |
| 501 | |
| 502 | // If the output accepts layerStack1 and internal-only layers.... |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 503 | mOutput->setLayerStackFilter(layerStack1, true); |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 504 | |
| 505 | // A null layer pointer does not belong to the output |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 506 | EXPECT_FALSE(mOutput->belongsInOutput(nullptr)); |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 507 | |
| 508 | // 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] | 509 | layerFEState.layerStackId = std::nullopt; |
| 510 | layerFEState.internalOnly = false; |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 511 | EXPECT_FALSE(mOutput->belongsInOutput(&layer)); |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 512 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 513 | layerFEState.layerStackId = std::nullopt; |
| 514 | layerFEState.internalOnly = true; |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 515 | EXPECT_FALSE(mOutput->belongsInOutput(&layer)); |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 516 | |
| 517 | // Any layer with layerStack1 belongs to it, internal-only or not. |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 518 | layerFEState.layerStackId = layerStack1; |
| 519 | layerFEState.internalOnly = false; |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 520 | EXPECT_TRUE(mOutput->belongsInOutput(&layer)); |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 521 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 522 | layerFEState.layerStackId = layerStack1; |
| 523 | layerFEState.internalOnly = true; |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 524 | EXPECT_TRUE(mOutput->belongsInOutput(&layer)); |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 525 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 526 | layerFEState.layerStackId = layerStack2; |
| 527 | layerFEState.internalOnly = true; |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 528 | EXPECT_FALSE(mOutput->belongsInOutput(&layer)); |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 529 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 530 | layerFEState.layerStackId = layerStack2; |
| 531 | layerFEState.internalOnly = false; |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 532 | EXPECT_FALSE(mOutput->belongsInOutput(&layer)); |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 533 | |
| 534 | // If the output accepts layerStack1 but not internal-only layers... |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 535 | mOutput->setLayerStackFilter(layerStack1, false); |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 536 | |
| 537 | // A null layer pointer does not belong to the output |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 538 | EXPECT_FALSE(mOutput->belongsInOutput(nullptr)); |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 539 | |
| 540 | // Only non-internal layers with layerStack1 belong to it. |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 541 | layerFEState.layerStackId = layerStack1; |
| 542 | layerFEState.internalOnly = false; |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 543 | EXPECT_TRUE(mOutput->belongsInOutput(&layer)); |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 544 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 545 | layerFEState.layerStackId = layerStack1; |
| 546 | layerFEState.internalOnly = true; |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 547 | EXPECT_FALSE(mOutput->belongsInOutput(&layer)); |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 548 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 549 | layerFEState.layerStackId = layerStack2; |
| 550 | layerFEState.internalOnly = true; |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 551 | EXPECT_FALSE(mOutput->belongsInOutput(&layer)); |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 552 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 553 | layerFEState.layerStackId = layerStack2; |
| 554 | layerFEState.internalOnly = false; |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 555 | EXPECT_FALSE(mOutput->belongsInOutput(&layer)); |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 556 | } |
| 557 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 558 | /* |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 559 | * Output::getOutputLayerForLayer() |
| 560 | */ |
| 561 | |
| 562 | TEST_F(OutputTest, getOutputLayerForLayerWorks) { |
| 563 | mock::OutputLayer* outputLayer1 = new StrictMock<mock::OutputLayer>(); |
| 564 | mock::OutputLayer* outputLayer2 = new StrictMock<mock::OutputLayer>(); |
| 565 | |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 566 | mOutput->injectOutputLayerForTest(std::unique_ptr<OutputLayer>(outputLayer1)); |
| 567 | mOutput->injectOutputLayerForTest(nullptr); |
| 568 | mOutput->injectOutputLayerForTest(std::unique_ptr<OutputLayer>(outputLayer2)); |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 569 | |
| 570 | StrictMock<mock::Layer> layer; |
| 571 | StrictMock<mock::Layer> otherLayer; |
| 572 | |
| 573 | // If the input layer matches the first OutputLayer, it will be returned. |
| 574 | EXPECT_CALL(*outputLayer1, getLayer()).WillOnce(ReturnRef(layer)); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 575 | EXPECT_EQ(outputLayer1, mOutput->getOutputLayerForLayer(&layer)); |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 576 | |
| 577 | // If the input layer matches the second OutputLayer, it will be returned. |
| 578 | EXPECT_CALL(*outputLayer1, getLayer()).WillOnce(ReturnRef(otherLayer)); |
| 579 | EXPECT_CALL(*outputLayer2, getLayer()).WillOnce(ReturnRef(layer)); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 580 | EXPECT_EQ(outputLayer2, mOutput->getOutputLayerForLayer(&layer)); |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 581 | |
| 582 | // If the input layer does not match an output layer, null will be returned. |
| 583 | EXPECT_CALL(*outputLayer1, getLayer()).WillOnce(ReturnRef(otherLayer)); |
| 584 | EXPECT_CALL(*outputLayer2, getLayer()).WillOnce(ReturnRef(otherLayer)); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 585 | EXPECT_EQ(nullptr, mOutput->getOutputLayerForLayer(&layer)); |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 586 | } |
| 587 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 588 | /* |
Lloyd Pique | c9e6003 | 2019-11-14 11:47:26 -0800 | [diff] [blame] | 589 | * Output::setReleasedLayers() |
| 590 | */ |
| 591 | |
| 592 | using OutputSetReleasedLayersTest = OutputTest; |
| 593 | |
| 594 | TEST_F(OutputSetReleasedLayersTest, setReleasedLayersTakesGivenLayers) { |
| 595 | sp<StrictMock<mock::LayerFE>> layer1FE{new StrictMock<mock::LayerFE>()}; |
| 596 | sp<StrictMock<mock::LayerFE>> layer2FE{new StrictMock<mock::LayerFE>()}; |
| 597 | sp<StrictMock<mock::LayerFE>> layer3FE{new StrictMock<mock::LayerFE>()}; |
| 598 | |
| 599 | Output::ReleasedLayers layers; |
| 600 | layers.push_back(layer1FE); |
| 601 | layers.push_back(layer2FE); |
| 602 | layers.push_back(layer3FE); |
| 603 | |
| 604 | mOutput->setReleasedLayers(std::move(layers)); |
| 605 | |
| 606 | const auto& setLayers = mOutput->getReleasedLayersForTest(); |
| 607 | ASSERT_EQ(3u, setLayers.size()); |
| 608 | ASSERT_EQ(layer1FE.get(), setLayers[0].promote().get()); |
| 609 | ASSERT_EQ(layer2FE.get(), setLayers[1].promote().get()); |
| 610 | ASSERT_EQ(layer3FE.get(), setLayers[2].promote().get()); |
| 611 | } |
| 612 | |
| 613 | /* |
Lloyd Pique | c0ee6ba | 2019-11-14 12:55:53 -0800 | [diff] [blame] | 614 | * Output::updateLayerStateFromFE() |
| 615 | */ |
| 616 | |
| 617 | using OutputUpdateLayerStateFromFETest = OutputLatchFEStateTest; |
| 618 | |
| 619 | TEST_F(OutputUpdateLayerStateFromFETest, handlesNoOutputLayerCase) { |
| 620 | CompositionRefreshArgs refreshArgs; |
| 621 | |
| 622 | mOutput->updateLayerStateFromFE(refreshArgs); |
| 623 | } |
| 624 | |
| 625 | TEST_F(OutputUpdateLayerStateFromFETest, latchesContentStateForAllContainedLayers) { |
| 626 | EXPECT_CALL(mLayer1FE, |
| 627 | latchCompositionState(Ref(mLayer1FEState), LayerFE::StateSubset::Content)); |
| 628 | EXPECT_CALL(mLayer2FE, |
| 629 | latchCompositionState(Ref(mLayer2FEState), LayerFE::StateSubset::Content)); |
| 630 | EXPECT_CALL(mLayer3FE, |
| 631 | latchCompositionState(Ref(mLayer3FEState), LayerFE::StateSubset::Content)); |
| 632 | |
| 633 | // Note: Must be performed after any expectations on these mocks |
| 634 | injectLayer(std::move(mOutputLayer1)); |
| 635 | injectLayer(std::move(mOutputLayer2)); |
| 636 | injectLayer(std::move(mOutputLayer3)); |
| 637 | |
| 638 | CompositionRefreshArgs refreshArgs; |
| 639 | refreshArgs.updatingGeometryThisFrame = false; |
| 640 | |
| 641 | mOutput->updateLayerStateFromFE(refreshArgs); |
| 642 | } |
| 643 | |
| 644 | TEST_F(OutputUpdateLayerStateFromFETest, latchesGeometryAndContentStateForAllContainedLayers) { |
| 645 | EXPECT_CALL(mLayer1FE, |
| 646 | latchCompositionState(Ref(mLayer1FEState), |
| 647 | LayerFE::StateSubset::GeometryAndContent)); |
| 648 | EXPECT_CALL(mLayer2FE, |
| 649 | latchCompositionState(Ref(mLayer2FEState), |
| 650 | LayerFE::StateSubset::GeometryAndContent)); |
| 651 | EXPECT_CALL(mLayer3FE, |
| 652 | latchCompositionState(Ref(mLayer3FEState), |
| 653 | LayerFE::StateSubset::GeometryAndContent)); |
| 654 | |
| 655 | // Note: Must be performed after any expectations on these mocks |
| 656 | injectLayer(std::move(mOutputLayer1)); |
| 657 | injectLayer(std::move(mOutputLayer2)); |
| 658 | injectLayer(std::move(mOutputLayer3)); |
| 659 | |
| 660 | CompositionRefreshArgs refreshArgs; |
| 661 | refreshArgs.updatingGeometryThisFrame = true; |
| 662 | |
| 663 | mOutput->updateLayerStateFromFE(refreshArgs); |
| 664 | } |
| 665 | |
| 666 | /* |
Alec Mouri | f9a2a2c | 2019-11-12 12:46:02 -0800 | [diff] [blame] | 667 | * Output::updateAndWriteCompositionState() |
| 668 | */ |
| 669 | |
| 670 | TEST_F(OutputTest, updateAndWriteCompositionState_takesEarlyOutIfNotEnabled) { |
| 671 | mOutput->editState().isEnabled = false; |
| 672 | |
| 673 | CompositionRefreshArgs args; |
| 674 | mOutput->updateAndWriteCompositionState(args); |
| 675 | } |
| 676 | |
| 677 | TEST_F(OutputTest, updateAndWriteCompositionState_updatesLayers) { |
| 678 | mOutput->editState().isEnabled = true; |
| 679 | mock::OutputLayer* outputLayer = new StrictMock<mock::OutputLayer>(); |
| 680 | mOutput->injectOutputLayerForTest(std::unique_ptr<OutputLayer>(outputLayer)); |
| 681 | |
| 682 | EXPECT_CALL(*outputLayer, updateCompositionState(true, true)).Times(1); |
| 683 | EXPECT_CALL(*outputLayer, writeStateToHWC(true)).Times(1); |
| 684 | |
| 685 | CompositionRefreshArgs args; |
| 686 | args.updatingGeometryThisFrame = true; |
| 687 | args.devOptForceClientComposition = true; |
| 688 | mOutput->updateAndWriteCompositionState(args); |
| 689 | } |
| 690 | |
| 691 | /* |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 692 | * Output::prepareFrame() |
| 693 | */ |
| 694 | |
| 695 | struct OutputPrepareFrameTest : public testing::Test { |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 696 | struct OutputPartialMock : public OutputPartialMockBase { |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 697 | // Sets up the helper functions called by prepareFrame to use a mock |
| 698 | // implementations. |
| 699 | MOCK_METHOD0(chooseCompositionStrategy, void()); |
| 700 | }; |
| 701 | |
| 702 | OutputPrepareFrameTest() { |
| 703 | mOutput.setDisplayColorProfileForTest( |
| 704 | std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile)); |
| 705 | mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface)); |
| 706 | } |
| 707 | |
| 708 | StrictMock<mock::CompositionEngine> mCompositionEngine; |
| 709 | mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>(); |
| 710 | mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>(); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 711 | StrictMock<OutputPartialMock> mOutput; |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 712 | }; |
| 713 | |
| 714 | TEST_F(OutputPrepareFrameTest, takesEarlyOutIfNotEnabled) { |
| 715 | mOutput.editState().isEnabled = false; |
| 716 | |
| 717 | mOutput.prepareFrame(); |
| 718 | } |
| 719 | |
| 720 | TEST_F(OutputPrepareFrameTest, delegatesToChooseCompositionStrategyAndRenderSurface) { |
| 721 | mOutput.editState().isEnabled = true; |
| 722 | mOutput.editState().usesClientComposition = false; |
| 723 | mOutput.editState().usesDeviceComposition = true; |
| 724 | |
| 725 | EXPECT_CALL(mOutput, chooseCompositionStrategy()).Times(1); |
| 726 | EXPECT_CALL(*mRenderSurface, prepareFrame(false, true)); |
| 727 | |
| 728 | mOutput.prepareFrame(); |
| 729 | } |
| 730 | |
| 731 | // Note: Use OutputTest and not OutputPrepareFrameTest, so the real |
| 732 | // base chooseCompositionStrategy() is invoked. |
| 733 | TEST_F(OutputTest, prepareFrameSetsClientCompositionOnlyByDefault) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 734 | mOutput->editState().isEnabled = true; |
| 735 | mOutput->editState().usesClientComposition = false; |
| 736 | mOutput->editState().usesDeviceComposition = true; |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 737 | |
| 738 | EXPECT_CALL(*mRenderSurface, prepareFrame(true, false)); |
| 739 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 740 | mOutput->prepareFrame(); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 741 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 742 | EXPECT_TRUE(mOutput->getState().usesClientComposition); |
| 743 | EXPECT_FALSE(mOutput->getState().usesDeviceComposition); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 744 | } |
| 745 | |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 746 | /* |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 747 | * Output::present() |
| 748 | */ |
| 749 | |
| 750 | struct OutputPresentTest : public testing::Test { |
| 751 | struct OutputPartialMock : public OutputPartialMockBase { |
| 752 | // All child helper functions Output::present() are defined as mocks, |
| 753 | // and those are tested separately, allowing the present() test to |
| 754 | // just cover the high level flow. |
| 755 | MOCK_METHOD1(updateColorProfile, void(const compositionengine::CompositionRefreshArgs&)); |
| 756 | MOCK_METHOD1(updateAndWriteCompositionState, |
| 757 | void(const compositionengine::CompositionRefreshArgs&)); |
| 758 | MOCK_METHOD1(setColorTransform, void(const compositionengine::CompositionRefreshArgs&)); |
| 759 | MOCK_METHOD0(beginFrame, void()); |
| 760 | MOCK_METHOD0(prepareFrame, void()); |
| 761 | MOCK_METHOD1(devOptRepaintFlash, void(const compositionengine::CompositionRefreshArgs&)); |
| 762 | MOCK_METHOD1(finishFrame, void(const compositionengine::CompositionRefreshArgs&)); |
| 763 | MOCK_METHOD0(postFramebuffer, void()); |
| 764 | }; |
| 765 | |
| 766 | StrictMock<OutputPartialMock> mOutput; |
| 767 | }; |
| 768 | |
| 769 | TEST_F(OutputPresentTest, justInvokesChildFunctionsInSequence) { |
| 770 | CompositionRefreshArgs args; |
| 771 | |
| 772 | InSequence seq; |
| 773 | EXPECT_CALL(mOutput, updateColorProfile(Ref(args))); |
| 774 | EXPECT_CALL(mOutput, updateAndWriteCompositionState(Ref(args))); |
| 775 | EXPECT_CALL(mOutput, setColorTransform(Ref(args))); |
| 776 | EXPECT_CALL(mOutput, beginFrame()); |
| 777 | EXPECT_CALL(mOutput, prepareFrame()); |
| 778 | EXPECT_CALL(mOutput, devOptRepaintFlash(Ref(args))); |
| 779 | EXPECT_CALL(mOutput, finishFrame(Ref(args))); |
| 780 | EXPECT_CALL(mOutput, postFramebuffer()); |
| 781 | |
| 782 | mOutput.present(args); |
| 783 | } |
| 784 | |
| 785 | /* |
| 786 | * Output::updateColorProfile() |
| 787 | */ |
| 788 | |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 789 | struct OutputUpdateColorProfileTest : public testing::Test { |
| 790 | using TestType = OutputUpdateColorProfileTest; |
| 791 | |
| 792 | struct OutputPartialMock : public OutputPartialMockBase { |
| 793 | // All child helper functions Output::present() are defined as mocks, |
| 794 | // and those are tested separately, allowing the present() test to |
| 795 | // just cover the high level flow. |
| 796 | MOCK_METHOD1(setColorProfile, void(const ColorProfile&)); |
| 797 | }; |
| 798 | |
| 799 | struct Layer { |
| 800 | Layer() { |
| 801 | EXPECT_CALL(mOutputLayer, getLayer()).WillRepeatedly(ReturnRef(mLayer)); |
| 802 | EXPECT_CALL(mOutputLayer, getLayerFE()).WillRepeatedly(ReturnRef(mLayerFE)); |
| 803 | EXPECT_CALL(mLayer, getFEState()).WillRepeatedly(ReturnRef(mLayerFEState)); |
| 804 | } |
| 805 | |
| 806 | StrictMock<mock::OutputLayer> mOutputLayer; |
| 807 | StrictMock<mock::Layer> mLayer; |
| 808 | StrictMock<mock::LayerFE> mLayerFE; |
| 809 | LayerFECompositionState mLayerFEState; |
| 810 | }; |
| 811 | |
| 812 | OutputUpdateColorProfileTest() { |
| 813 | mOutput.setDisplayColorProfileForTest( |
| 814 | std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile)); |
| 815 | mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface)); |
| 816 | |
| 817 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0)) |
| 818 | .WillRepeatedly(Return(&mLayer1.mOutputLayer)); |
| 819 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(1)) |
| 820 | .WillRepeatedly(Return(&mLayer2.mOutputLayer)); |
| 821 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(2)) |
| 822 | .WillRepeatedly(Return(&mLayer3.mOutputLayer)); |
| 823 | } |
| 824 | |
| 825 | struct ExecuteState : public CallOrderStateMachineHelper<TestType, ExecuteState> { |
| 826 | void execute() { getInstance()->mOutput.updateColorProfile(getInstance()->mRefreshArgs); } |
| 827 | }; |
| 828 | |
| 829 | mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>(); |
| 830 | mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>(); |
| 831 | StrictMock<OutputPartialMock> mOutput; |
| 832 | |
| 833 | Layer mLayer1; |
| 834 | Layer mLayer2; |
| 835 | Layer mLayer3; |
| 836 | |
| 837 | CompositionRefreshArgs mRefreshArgs; |
| 838 | }; |
| 839 | |
| 840 | // TODO(b/144522012): Refactor Output::updateColorProfile and the related code |
| 841 | // to make it easier to write unit tests. |
| 842 | |
| 843 | TEST_F(OutputUpdateColorProfileTest, setsAColorProfileWhenUnmanaged) { |
| 844 | // When the outputColorSetting is set to kUnmanaged, the implementation sets |
| 845 | // a simple default color profile without looking at anything else. |
| 846 | |
| 847 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(3)); |
| 848 | EXPECT_CALL(mOutput, |
| 849 | setColorProfile(ColorProfileEq( |
| 850 | ColorProfile{ui::ColorMode::NATIVE, ui::Dataspace::UNKNOWN, |
| 851 | ui::RenderIntent::COLORIMETRIC, ui::Dataspace::UNKNOWN}))); |
| 852 | |
| 853 | mRefreshArgs.outputColorSetting = OutputColorSetting::kUnmanaged; |
| 854 | mRefreshArgs.colorSpaceAgnosticDataspace = ui::Dataspace::UNKNOWN; |
| 855 | |
| 856 | mOutput.updateColorProfile(mRefreshArgs); |
| 857 | } |
| 858 | |
| 859 | struct OutputUpdateColorProfileTest_GetBestColorModeResultBecomesSetProfile |
| 860 | : public OutputUpdateColorProfileTest { |
| 861 | OutputUpdateColorProfileTest_GetBestColorModeResultBecomesSetProfile() { |
| 862 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(0)); |
| 863 | mRefreshArgs.outputColorSetting = OutputColorSetting::kEnhanced; |
| 864 | mRefreshArgs.colorSpaceAgnosticDataspace = ui::Dataspace::UNKNOWN; |
| 865 | } |
| 866 | |
| 867 | struct ExpectBestColorModeCallResultUsedToSetColorProfileState |
| 868 | : public CallOrderStateMachineHelper< |
| 869 | TestType, ExpectBestColorModeCallResultUsedToSetColorProfileState> { |
| 870 | [[nodiscard]] auto expectBestColorModeCallResultUsedToSetColorProfile( |
| 871 | ui::ColorMode colorMode, ui::Dataspace dataspace, ui::RenderIntent renderIntent) { |
| 872 | EXPECT_CALL(*getInstance()->mDisplayColorProfile, |
| 873 | getBestColorMode(ui::Dataspace::V0_SRGB, ui::RenderIntent::ENHANCE, _, _, |
| 874 | _)) |
| 875 | .WillOnce(DoAll(SetArgPointee<2>(dataspace), SetArgPointee<3>(colorMode), |
| 876 | SetArgPointee<4>(renderIntent))); |
| 877 | EXPECT_CALL(getInstance()->mOutput, |
| 878 | setColorProfile( |
| 879 | ColorProfileEq(ColorProfile{colorMode, dataspace, renderIntent, |
| 880 | ui::Dataspace::UNKNOWN}))); |
| 881 | return nextState<ExecuteState>(); |
| 882 | } |
| 883 | }; |
| 884 | |
| 885 | // Call this member function to start using the mini-DSL defined above. |
| 886 | [[nodiscard]] auto verify() { |
| 887 | return ExpectBestColorModeCallResultUsedToSetColorProfileState::make(this); |
| 888 | } |
| 889 | }; |
| 890 | |
| 891 | TEST_F(OutputUpdateColorProfileTest_GetBestColorModeResultBecomesSetProfile, |
| 892 | Native_Unknown_Colorimetric_Set) { |
| 893 | verify().expectBestColorModeCallResultUsedToSetColorProfile(ui::ColorMode::NATIVE, |
| 894 | ui::Dataspace::UNKNOWN, |
| 895 | ui::RenderIntent::COLORIMETRIC) |
| 896 | .execute(); |
| 897 | } |
| 898 | |
| 899 | TEST_F(OutputUpdateColorProfileTest_GetBestColorModeResultBecomesSetProfile, |
| 900 | DisplayP3_DisplayP3_Enhance_Set) { |
| 901 | verify().expectBestColorModeCallResultUsedToSetColorProfile(ui::ColorMode::DISPLAY_P3, |
| 902 | ui::Dataspace::DISPLAY_P3, |
| 903 | ui::RenderIntent::ENHANCE) |
| 904 | .execute(); |
| 905 | } |
| 906 | |
| 907 | struct OutputUpdateColorProfileTest_ColorSpaceAgnosticeDataspaceAffectsSetColorProfile |
| 908 | : public OutputUpdateColorProfileTest { |
| 909 | OutputUpdateColorProfileTest_ColorSpaceAgnosticeDataspaceAffectsSetColorProfile() { |
| 910 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(0)); |
| 911 | EXPECT_CALL(*mDisplayColorProfile, |
| 912 | getBestColorMode(ui::Dataspace::V0_SRGB, ui::RenderIntent::ENHANCE, _, _, _)) |
| 913 | .WillRepeatedly(DoAll(SetArgPointee<2>(ui::Dataspace::UNKNOWN), |
| 914 | SetArgPointee<3>(ui::ColorMode::NATIVE), |
| 915 | SetArgPointee<4>(ui::RenderIntent::COLORIMETRIC))); |
| 916 | mRefreshArgs.outputColorSetting = OutputColorSetting::kEnhanced; |
| 917 | } |
| 918 | |
| 919 | struct IfColorSpaceAgnosticDataspaceSetToState |
| 920 | : public CallOrderStateMachineHelper<TestType, IfColorSpaceAgnosticDataspaceSetToState> { |
| 921 | [[nodiscard]] auto ifColorSpaceAgnosticDataspaceSetTo(ui::Dataspace dataspace) { |
| 922 | getInstance()->mRefreshArgs.colorSpaceAgnosticDataspace = dataspace; |
| 923 | return nextState<ThenExpectSetColorProfileCallUsesColorSpaceAgnosticDataspaceState>(); |
| 924 | } |
| 925 | }; |
| 926 | |
| 927 | struct ThenExpectSetColorProfileCallUsesColorSpaceAgnosticDataspaceState |
| 928 | : public CallOrderStateMachineHelper< |
| 929 | TestType, ThenExpectSetColorProfileCallUsesColorSpaceAgnosticDataspaceState> { |
| 930 | [[nodiscard]] auto thenExpectSetColorProfileCallUsesColorSpaceAgnosticDataspace( |
| 931 | ui::Dataspace dataspace) { |
| 932 | EXPECT_CALL(getInstance()->mOutput, |
| 933 | setColorProfile(ColorProfileEq( |
| 934 | ColorProfile{ui::ColorMode::NATIVE, ui::Dataspace::UNKNOWN, |
| 935 | ui::RenderIntent::COLORIMETRIC, dataspace}))); |
| 936 | return nextState<ExecuteState>(); |
| 937 | } |
| 938 | }; |
| 939 | |
| 940 | // Call this member function to start using the mini-DSL defined above. |
| 941 | [[nodiscard]] auto verify() { return IfColorSpaceAgnosticDataspaceSetToState::make(this); } |
| 942 | }; |
| 943 | |
| 944 | TEST_F(OutputUpdateColorProfileTest_ColorSpaceAgnosticeDataspaceAffectsSetColorProfile, DisplayP3) { |
| 945 | verify().ifColorSpaceAgnosticDataspaceSetTo(ui::Dataspace::DISPLAY_P3) |
| 946 | .thenExpectSetColorProfileCallUsesColorSpaceAgnosticDataspace(ui::Dataspace::DISPLAY_P3) |
| 947 | .execute(); |
| 948 | } |
| 949 | |
| 950 | TEST_F(OutputUpdateColorProfileTest_ColorSpaceAgnosticeDataspaceAffectsSetColorProfile, V0_SRGB) { |
| 951 | verify().ifColorSpaceAgnosticDataspaceSetTo(ui::Dataspace::V0_SRGB) |
| 952 | .thenExpectSetColorProfileCallUsesColorSpaceAgnosticDataspace(ui::Dataspace::V0_SRGB) |
| 953 | .execute(); |
| 954 | } |
| 955 | |
| 956 | struct OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference |
| 957 | : public OutputUpdateColorProfileTest { |
| 958 | // Internally the implementation looks through the dataspaces of all the |
| 959 | // visible layers. The topmost one that also has an actual dataspace |
| 960 | // preference set is used to drive subsequent choices. |
| 961 | |
| 962 | OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference() { |
| 963 | mRefreshArgs.outputColorSetting = OutputColorSetting::kEnhanced; |
| 964 | mRefreshArgs.colorSpaceAgnosticDataspace = ui::Dataspace::UNKNOWN; |
| 965 | |
| 966 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(3)); |
| 967 | EXPECT_CALL(mOutput, setColorProfile(_)).WillRepeatedly(Return()); |
| 968 | } |
| 969 | |
| 970 | struct IfTopLayerDataspaceState |
| 971 | : public CallOrderStateMachineHelper<TestType, IfTopLayerDataspaceState> { |
| 972 | [[nodiscard]] auto ifTopLayerIs(ui::Dataspace dataspace) { |
| 973 | getInstance()->mLayer3.mLayerFEState.dataspace = dataspace; |
| 974 | return nextState<AndIfMiddleLayerDataspaceState>(); |
| 975 | } |
| 976 | [[nodiscard]] auto ifTopLayerHasNoPreference() { |
| 977 | return ifTopLayerIs(ui::Dataspace::UNKNOWN); |
| 978 | } |
| 979 | }; |
| 980 | |
| 981 | struct AndIfMiddleLayerDataspaceState |
| 982 | : public CallOrderStateMachineHelper<TestType, AndIfMiddleLayerDataspaceState> { |
| 983 | [[nodiscard]] auto andIfMiddleLayerIs(ui::Dataspace dataspace) { |
| 984 | getInstance()->mLayer2.mLayerFEState.dataspace = dataspace; |
| 985 | return nextState<AndIfBottomLayerDataspaceState>(); |
| 986 | } |
| 987 | [[nodiscard]] auto andIfMiddleLayerHasNoPreference() { |
| 988 | return andIfMiddleLayerIs(ui::Dataspace::UNKNOWN); |
| 989 | } |
| 990 | }; |
| 991 | |
| 992 | struct AndIfBottomLayerDataspaceState |
| 993 | : public CallOrderStateMachineHelper<TestType, AndIfBottomLayerDataspaceState> { |
| 994 | [[nodiscard]] auto andIfBottomLayerIs(ui::Dataspace dataspace) { |
| 995 | getInstance()->mLayer1.mLayerFEState.dataspace = dataspace; |
| 996 | return nextState<ThenExpectBestColorModeCallUsesState>(); |
| 997 | } |
| 998 | [[nodiscard]] auto andIfBottomLayerHasNoPreference() { |
| 999 | return andIfBottomLayerIs(ui::Dataspace::UNKNOWN); |
| 1000 | } |
| 1001 | }; |
| 1002 | |
| 1003 | struct ThenExpectBestColorModeCallUsesState |
| 1004 | : public CallOrderStateMachineHelper<TestType, ThenExpectBestColorModeCallUsesState> { |
| 1005 | [[nodiscard]] auto thenExpectBestColorModeCallUses(ui::Dataspace dataspace) { |
| 1006 | EXPECT_CALL(*getInstance()->mDisplayColorProfile, |
| 1007 | getBestColorMode(dataspace, _, _, _, _)); |
| 1008 | return nextState<ExecuteState>(); |
| 1009 | } |
| 1010 | }; |
| 1011 | |
| 1012 | // Call this member function to start using the mini-DSL defined above. |
| 1013 | [[nodiscard]] auto verify() { return IfTopLayerDataspaceState::make(this); } |
| 1014 | }; |
| 1015 | |
| 1016 | TEST_F(OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference, |
| 1017 | noStrongLayerPrefenceUses_V0_SRGB) { |
| 1018 | // If none of the layers indicate a preference, then V0_SRGB is the |
| 1019 | // preferred choice (subject to additional checks). |
| 1020 | verify().ifTopLayerHasNoPreference() |
| 1021 | .andIfMiddleLayerHasNoPreference() |
| 1022 | .andIfBottomLayerHasNoPreference() |
| 1023 | .thenExpectBestColorModeCallUses(ui::Dataspace::V0_SRGB) |
| 1024 | .execute(); |
| 1025 | } |
| 1026 | |
| 1027 | TEST_F(OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference, |
| 1028 | ifTopmostUses_DisplayP3_Then_DisplayP3_Chosen) { |
| 1029 | // If only the topmost layer has a preference, then that is what is chosen. |
| 1030 | verify().ifTopLayerIs(ui::Dataspace::DISPLAY_P3) |
| 1031 | .andIfMiddleLayerHasNoPreference() |
| 1032 | .andIfBottomLayerHasNoPreference() |
| 1033 | .thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_P3) |
| 1034 | .execute(); |
| 1035 | } |
| 1036 | |
| 1037 | TEST_F(OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference, |
| 1038 | ifMiddleUses_DisplayP3_Then_DisplayP3_Chosen) { |
| 1039 | // If only the middle layer has a preference, that that is what is chosen. |
| 1040 | verify().ifTopLayerHasNoPreference() |
| 1041 | .andIfMiddleLayerIs(ui::Dataspace::DISPLAY_P3) |
| 1042 | .andIfBottomLayerHasNoPreference() |
| 1043 | .thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_P3) |
| 1044 | .execute(); |
| 1045 | } |
| 1046 | |
| 1047 | TEST_F(OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference, |
| 1048 | ifBottomUses_DisplayP3_Then_DisplayP3_Chosen) { |
| 1049 | // If only the middle layer has a preference, that that is what is chosen. |
| 1050 | verify().ifTopLayerHasNoPreference() |
| 1051 | .andIfMiddleLayerHasNoPreference() |
| 1052 | .andIfBottomLayerIs(ui::Dataspace::DISPLAY_P3) |
| 1053 | .thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_P3) |
| 1054 | .execute(); |
| 1055 | } |
| 1056 | |
| 1057 | TEST_F(OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference, |
| 1058 | ifTopUses_DisplayBT2020_AndBottomUses_DisplayP3_Then_DisplayBT2020_Chosen) { |
| 1059 | // If multiple layers have a preference, the topmost value is what is used. |
| 1060 | verify().ifTopLayerIs(ui::Dataspace::DISPLAY_BT2020) |
| 1061 | .andIfMiddleLayerHasNoPreference() |
| 1062 | .andIfBottomLayerIs(ui::Dataspace::DISPLAY_P3) |
| 1063 | .thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_BT2020) |
| 1064 | .execute(); |
| 1065 | } |
| 1066 | |
| 1067 | TEST_F(OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference, |
| 1068 | ifTopUses_DisplayP3_AndBottomUses_V0_SRGB_Then_DisplayP3_Chosen) { |
| 1069 | // If multiple layers have a preference, the topmost value is what is used. |
| 1070 | verify().ifTopLayerIs(ui::Dataspace::DISPLAY_P3) |
| 1071 | .andIfMiddleLayerHasNoPreference() |
| 1072 | .andIfBottomLayerIs(ui::Dataspace::DISPLAY_BT2020) |
| 1073 | .thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_P3) |
| 1074 | .execute(); |
| 1075 | } |
| 1076 | |
| 1077 | struct OutputUpdateColorProfileTest_ForceOutputColorOverrides |
| 1078 | : public OutputUpdateColorProfileTest { |
| 1079 | // If CompositionRefreshArgs::forceOutputColorMode is set to some specific |
| 1080 | // values, it overrides the layer dataspace choice. |
| 1081 | |
| 1082 | OutputUpdateColorProfileTest_ForceOutputColorOverrides() { |
| 1083 | mRefreshArgs.outputColorSetting = OutputColorSetting::kEnhanced; |
| 1084 | mRefreshArgs.colorSpaceAgnosticDataspace = ui::Dataspace::UNKNOWN; |
| 1085 | |
| 1086 | mLayer1.mLayerFEState.dataspace = ui::Dataspace::DISPLAY_BT2020; |
| 1087 | |
| 1088 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(1)); |
| 1089 | EXPECT_CALL(mOutput, setColorProfile(_)).WillRepeatedly(Return()); |
| 1090 | } |
| 1091 | |
| 1092 | struct IfForceOutputColorModeState |
| 1093 | : public CallOrderStateMachineHelper<TestType, IfForceOutputColorModeState> { |
| 1094 | [[nodiscard]] auto ifForceOutputColorMode(ui::ColorMode colorMode) { |
| 1095 | getInstance()->mRefreshArgs.forceOutputColorMode = colorMode; |
| 1096 | return nextState<ThenExpectBestColorModeCallUsesState>(); |
| 1097 | } |
| 1098 | [[nodiscard]] auto ifNoOverride() { return ifForceOutputColorMode(ui::ColorMode::NATIVE); } |
| 1099 | }; |
| 1100 | |
| 1101 | struct ThenExpectBestColorModeCallUsesState |
| 1102 | : public CallOrderStateMachineHelper<TestType, ThenExpectBestColorModeCallUsesState> { |
| 1103 | [[nodiscard]] auto thenExpectBestColorModeCallUses(ui::Dataspace dataspace) { |
| 1104 | EXPECT_CALL(*getInstance()->mDisplayColorProfile, |
| 1105 | getBestColorMode(dataspace, _, _, _, _)); |
| 1106 | return nextState<ExecuteState>(); |
| 1107 | } |
| 1108 | }; |
| 1109 | |
| 1110 | // Call this member function to start using the mini-DSL defined above. |
| 1111 | [[nodiscard]] auto verify() { return IfForceOutputColorModeState::make(this); } |
| 1112 | }; |
| 1113 | |
| 1114 | TEST_F(OutputUpdateColorProfileTest_ForceOutputColorOverrides, NoOverride_DoesNotOverride) { |
| 1115 | // By default the layer state is used to set the preferred dataspace |
| 1116 | verify().ifNoOverride() |
| 1117 | .thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_BT2020) |
| 1118 | .execute(); |
| 1119 | } |
| 1120 | |
| 1121 | TEST_F(OutputUpdateColorProfileTest_ForceOutputColorOverrides, SRGB_Override_USES_V0_SRGB) { |
| 1122 | // Setting ui::ColorMode::SRGB overrides it with ui::Dataspace::V0_SRGB |
| 1123 | verify().ifForceOutputColorMode(ui::ColorMode::SRGB) |
| 1124 | .thenExpectBestColorModeCallUses(ui::Dataspace::V0_SRGB) |
| 1125 | .execute(); |
| 1126 | } |
| 1127 | |
| 1128 | TEST_F(OutputUpdateColorProfileTest_ForceOutputColorOverrides, DisplayP3_Override_Uses_DisplayP3) { |
| 1129 | // Setting ui::ColorMode::DISPLAY_P3 overrides it with ui::Dataspace::DISPLAY_P3 |
| 1130 | verify().ifForceOutputColorMode(ui::ColorMode::DISPLAY_P3) |
| 1131 | .thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_P3) |
| 1132 | .execute(); |
| 1133 | } |
| 1134 | |
| 1135 | // HDR output requires all layers to be compatible with the chosen HDR |
| 1136 | // dataspace, along with there being proper support. |
| 1137 | struct OutputUpdateColorProfileTest_Hdr : public OutputUpdateColorProfileTest { |
| 1138 | OutputUpdateColorProfileTest_Hdr() { |
| 1139 | mRefreshArgs.outputColorSetting = OutputColorSetting::kEnhanced; |
| 1140 | mRefreshArgs.colorSpaceAgnosticDataspace = ui::Dataspace::UNKNOWN; |
| 1141 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(2)); |
| 1142 | EXPECT_CALL(mOutput, setColorProfile(_)).WillRepeatedly(Return()); |
| 1143 | } |
| 1144 | |
| 1145 | static constexpr ui::Dataspace kNonHdrDataspace = ui::Dataspace::DISPLAY_P3; |
| 1146 | static constexpr ui::Dataspace BT2020_PQ = ui::Dataspace::BT2020_PQ; |
| 1147 | static constexpr ui::Dataspace BT2020_HLG = ui::Dataspace::BT2020_HLG; |
| 1148 | static constexpr ui::Dataspace DISPLAY_P3 = ui::Dataspace::DISPLAY_P3; |
| 1149 | |
| 1150 | struct IfTopLayerDataspaceState |
| 1151 | : public CallOrderStateMachineHelper<TestType, IfTopLayerDataspaceState> { |
| 1152 | [[nodiscard]] auto ifTopLayerIs(ui::Dataspace dataspace) { |
| 1153 | getInstance()->mLayer2.mLayerFEState.dataspace = dataspace; |
| 1154 | return nextState<AndTopLayerCompositionTypeState>(); |
| 1155 | } |
| 1156 | [[nodiscard]] auto ifTopLayerIsNotHdr() { return ifTopLayerIs(kNonHdrDataspace); } |
| 1157 | }; |
| 1158 | |
| 1159 | struct AndTopLayerCompositionTypeState |
| 1160 | : public CallOrderStateMachineHelper<TestType, AndTopLayerCompositionTypeState> { |
| 1161 | [[nodiscard]] auto andTopLayerIsREComposed(bool renderEngineComposed) { |
| 1162 | getInstance()->mLayer2.mLayerFEState.forceClientComposition = renderEngineComposed; |
| 1163 | return nextState<AndIfBottomLayerDataspaceState>(); |
| 1164 | } |
| 1165 | }; |
| 1166 | |
| 1167 | struct AndIfBottomLayerDataspaceState |
| 1168 | : public CallOrderStateMachineHelper<TestType, AndIfBottomLayerDataspaceState> { |
| 1169 | [[nodiscard]] auto andIfBottomLayerIs(ui::Dataspace dataspace) { |
| 1170 | getInstance()->mLayer1.mLayerFEState.dataspace = dataspace; |
| 1171 | return nextState<AndBottomLayerCompositionTypeState>(); |
| 1172 | } |
| 1173 | [[nodiscard]] auto andIfBottomLayerIsNotHdr() { |
| 1174 | return andIfBottomLayerIs(kNonHdrDataspace); |
| 1175 | } |
| 1176 | }; |
| 1177 | |
| 1178 | struct AndBottomLayerCompositionTypeState |
| 1179 | : public CallOrderStateMachineHelper<TestType, AndBottomLayerCompositionTypeState> { |
| 1180 | [[nodiscard]] auto andBottomLayerIsREComposed(bool renderEngineComposed) { |
| 1181 | getInstance()->mLayer1.mLayerFEState.forceClientComposition = renderEngineComposed; |
| 1182 | return nextState<AndIfHasLegacySupportState>(); |
| 1183 | } |
| 1184 | }; |
| 1185 | |
| 1186 | struct AndIfHasLegacySupportState |
| 1187 | : public CallOrderStateMachineHelper<TestType, AndIfHasLegacySupportState> { |
| 1188 | [[nodiscard]] auto andIfLegacySupportFor(ui::Dataspace dataspace, bool legacySupport) { |
| 1189 | EXPECT_CALL(*getInstance()->mDisplayColorProfile, hasLegacyHdrSupport(dataspace)) |
| 1190 | .WillOnce(Return(legacySupport)); |
| 1191 | return nextState<ThenExpectBestColorModeCallUsesState>(); |
| 1192 | } |
| 1193 | }; |
| 1194 | |
| 1195 | struct ThenExpectBestColorModeCallUsesState |
| 1196 | : public CallOrderStateMachineHelper<TestType, ThenExpectBestColorModeCallUsesState> { |
| 1197 | [[nodiscard]] auto thenExpectBestColorModeCallUses(ui::Dataspace dataspace) { |
| 1198 | EXPECT_CALL(*getInstance()->mDisplayColorProfile, |
| 1199 | getBestColorMode(dataspace, _, _, _, _)); |
| 1200 | return nextState<ExecuteState>(); |
| 1201 | } |
| 1202 | }; |
| 1203 | |
| 1204 | // Call this member function to start using the mini-DSL defined above. |
| 1205 | [[nodiscard]] auto verify() { return IfTopLayerDataspaceState::make(this); } |
| 1206 | }; |
| 1207 | |
| 1208 | TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_PQ_HW_Uses_PQ) { |
| 1209 | // If all layers use BT2020_PQ, and there are no other special conditions, |
| 1210 | // BT2020_PQ is used. |
| 1211 | verify().ifTopLayerIs(BT2020_PQ) |
| 1212 | .andTopLayerIsREComposed(false) |
| 1213 | .andIfBottomLayerIs(BT2020_PQ) |
| 1214 | .andBottomLayerIsREComposed(false) |
| 1215 | .andIfLegacySupportFor(BT2020_PQ, false) |
| 1216 | .thenExpectBestColorModeCallUses(BT2020_PQ) |
| 1217 | .execute(); |
| 1218 | } |
| 1219 | |
| 1220 | TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_PQ_HW_IfPQHasLegacySupport_Uses_DisplayP3) { |
| 1221 | // BT2020_PQ is not used if there is only legacy support for it. |
| 1222 | verify().ifTopLayerIs(BT2020_PQ) |
| 1223 | .andTopLayerIsREComposed(false) |
| 1224 | .andIfBottomLayerIs(BT2020_PQ) |
| 1225 | .andBottomLayerIsREComposed(false) |
| 1226 | .andIfLegacySupportFor(BT2020_PQ, true) |
| 1227 | .thenExpectBestColorModeCallUses(DISPLAY_P3) |
| 1228 | .execute(); |
| 1229 | } |
| 1230 | |
| 1231 | TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_PQ_RE_Uses_PQ) { |
| 1232 | // BT2020_PQ is still used if the bottom layer is RenderEngine composed. |
| 1233 | verify().ifTopLayerIs(BT2020_PQ) |
| 1234 | .andTopLayerIsREComposed(false) |
| 1235 | .andIfBottomLayerIs(BT2020_PQ) |
| 1236 | .andBottomLayerIsREComposed(true) |
| 1237 | .andIfLegacySupportFor(BT2020_PQ, false) |
| 1238 | .thenExpectBestColorModeCallUses(BT2020_PQ) |
| 1239 | .execute(); |
| 1240 | } |
| 1241 | |
| 1242 | TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_RE_On_PQ_HW_Uses_DisplayP3) { |
| 1243 | // BT2020_PQ is not used if the top layer is RenderEngine composed. |
| 1244 | verify().ifTopLayerIs(BT2020_PQ) |
| 1245 | .andTopLayerIsREComposed(true) |
| 1246 | .andIfBottomLayerIs(BT2020_PQ) |
| 1247 | .andBottomLayerIsREComposed(false) |
| 1248 | .andIfLegacySupportFor(BT2020_PQ, false) |
| 1249 | .thenExpectBestColorModeCallUses(DISPLAY_P3) |
| 1250 | .execute(); |
| 1251 | } |
| 1252 | |
| 1253 | TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_HLG_HW_Uses_PQ) { |
| 1254 | // If there is mixed HLG/PQ use, and the topmost layer is PQ, then PQ is used if there |
| 1255 | // are no other special conditions. |
| 1256 | verify().ifTopLayerIs(BT2020_PQ) |
| 1257 | .andTopLayerIsREComposed(false) |
| 1258 | .andIfBottomLayerIs(BT2020_HLG) |
| 1259 | .andBottomLayerIsREComposed(false) |
| 1260 | .andIfLegacySupportFor(BT2020_PQ, false) |
| 1261 | .thenExpectBestColorModeCallUses(BT2020_PQ) |
| 1262 | .execute(); |
| 1263 | } |
| 1264 | |
| 1265 | TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_HLG_HW_IfPQHasLegacySupport_Uses_DisplayP3) { |
| 1266 | // BT2020_PQ is not used if there is only legacy support for it. |
| 1267 | verify().ifTopLayerIs(BT2020_PQ) |
| 1268 | .andTopLayerIsREComposed(false) |
| 1269 | .andIfBottomLayerIs(BT2020_HLG) |
| 1270 | .andBottomLayerIsREComposed(false) |
| 1271 | .andIfLegacySupportFor(BT2020_PQ, true) |
| 1272 | .thenExpectBestColorModeCallUses(DISPLAY_P3) |
| 1273 | .execute(); |
| 1274 | } |
| 1275 | |
| 1276 | TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_HLG_RE_Uses_PQ) { |
| 1277 | // BT2020_PQ is used if the bottom HLG layer is RenderEngine composed. |
| 1278 | verify().ifTopLayerIs(BT2020_PQ) |
| 1279 | .andTopLayerIsREComposed(false) |
| 1280 | .andIfBottomLayerIs(BT2020_HLG) |
| 1281 | .andBottomLayerIsREComposed(true) |
| 1282 | .andIfLegacySupportFor(BT2020_PQ, false) |
| 1283 | .thenExpectBestColorModeCallUses(BT2020_PQ) |
| 1284 | .execute(); |
| 1285 | } |
| 1286 | |
| 1287 | TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_RE_On_HLG_HW_Uses_DisplayP3) { |
| 1288 | // BT2020_PQ is not used if the top PQ layer is RenderEngine composed. |
| 1289 | verify().ifTopLayerIs(BT2020_PQ) |
| 1290 | .andTopLayerIsREComposed(true) |
| 1291 | .andIfBottomLayerIs(BT2020_HLG) |
| 1292 | .andBottomLayerIsREComposed(false) |
| 1293 | .andIfLegacySupportFor(BT2020_PQ, false) |
| 1294 | .thenExpectBestColorModeCallUses(DISPLAY_P3) |
| 1295 | .execute(); |
| 1296 | } |
| 1297 | |
| 1298 | TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_PQ_HW_Uses_PQ) { |
| 1299 | // If there is mixed HLG/PQ use, and the topmost layer is HLG, then PQ is |
| 1300 | // used if there are no other special conditions. |
| 1301 | verify().ifTopLayerIs(BT2020_HLG) |
| 1302 | .andTopLayerIsREComposed(false) |
| 1303 | .andIfBottomLayerIs(BT2020_PQ) |
| 1304 | .andBottomLayerIsREComposed(false) |
| 1305 | .andIfLegacySupportFor(BT2020_PQ, false) |
| 1306 | .thenExpectBestColorModeCallUses(BT2020_PQ) |
| 1307 | .execute(); |
| 1308 | } |
| 1309 | |
| 1310 | TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_PQ_HW_IfPQHasLegacySupport_Uses_DisplayP3) { |
| 1311 | // BT2020_PQ is not used if there is only legacy support for it. |
| 1312 | verify().ifTopLayerIs(BT2020_HLG) |
| 1313 | .andTopLayerIsREComposed(false) |
| 1314 | .andIfBottomLayerIs(BT2020_PQ) |
| 1315 | .andBottomLayerIsREComposed(false) |
| 1316 | .andIfLegacySupportFor(BT2020_PQ, true) |
| 1317 | .thenExpectBestColorModeCallUses(DISPLAY_P3) |
| 1318 | .execute(); |
| 1319 | } |
| 1320 | |
| 1321 | TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_PQ_RE_Uses_DisplayP3) { |
| 1322 | // BT2020_PQ is not used if the bottom PQ layer is RenderEngine composed. |
| 1323 | verify().ifTopLayerIs(BT2020_HLG) |
| 1324 | .andTopLayerIsREComposed(false) |
| 1325 | .andIfBottomLayerIs(BT2020_PQ) |
| 1326 | .andBottomLayerIsREComposed(true) |
| 1327 | .andIfLegacySupportFor(BT2020_PQ, false) |
| 1328 | .thenExpectBestColorModeCallUses(DISPLAY_P3) |
| 1329 | .execute(); |
| 1330 | } |
| 1331 | |
| 1332 | TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_RE_On_PQ_HW_Uses_PQ) { |
| 1333 | // BT2020_PQ is still used if the top HLG layer is RenderEngine composed. |
| 1334 | verify().ifTopLayerIs(BT2020_HLG) |
| 1335 | .andTopLayerIsREComposed(true) |
| 1336 | .andIfBottomLayerIs(BT2020_PQ) |
| 1337 | .andBottomLayerIsREComposed(false) |
| 1338 | .andIfLegacySupportFor(BT2020_PQ, false) |
| 1339 | .thenExpectBestColorModeCallUses(BT2020_PQ) |
| 1340 | .execute(); |
| 1341 | } |
| 1342 | |
| 1343 | TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_HLG_HW_Uses_HLG) { |
| 1344 | // If all layers use HLG then HLG is used if there are no other special |
| 1345 | // conditions. |
| 1346 | verify().ifTopLayerIs(BT2020_HLG) |
| 1347 | .andTopLayerIsREComposed(false) |
| 1348 | .andIfBottomLayerIs(BT2020_HLG) |
| 1349 | .andBottomLayerIsREComposed(false) |
| 1350 | .andIfLegacySupportFor(BT2020_HLG, false) |
| 1351 | .thenExpectBestColorModeCallUses(BT2020_HLG) |
| 1352 | .execute(); |
| 1353 | } |
| 1354 | |
| 1355 | TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_HLG_HW_IfPQHasLegacySupport_Uses_DisplayP3) { |
| 1356 | // BT2020_HLG is not used if there is legacy support for it. |
| 1357 | verify().ifTopLayerIs(BT2020_HLG) |
| 1358 | .andTopLayerIsREComposed(false) |
| 1359 | .andIfBottomLayerIs(BT2020_HLG) |
| 1360 | .andBottomLayerIsREComposed(false) |
| 1361 | .andIfLegacySupportFor(BT2020_HLG, true) |
| 1362 | .thenExpectBestColorModeCallUses(DISPLAY_P3) |
| 1363 | .execute(); |
| 1364 | } |
| 1365 | |
| 1366 | TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_HLG_RE_Uses_HLG) { |
| 1367 | // BT2020_HLG is used even if the bottom layer is client composed. |
| 1368 | verify().ifTopLayerIs(BT2020_HLG) |
| 1369 | .andTopLayerIsREComposed(false) |
| 1370 | .andIfBottomLayerIs(BT2020_HLG) |
| 1371 | .andBottomLayerIsREComposed(true) |
| 1372 | .andIfLegacySupportFor(BT2020_HLG, false) |
| 1373 | .thenExpectBestColorModeCallUses(BT2020_HLG) |
| 1374 | .execute(); |
| 1375 | } |
| 1376 | |
| 1377 | TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_RE_On_HLG_HW_Uses_HLG) { |
| 1378 | // BT2020_HLG is used even if the top layer is client composed. |
| 1379 | verify().ifTopLayerIs(BT2020_HLG) |
| 1380 | .andTopLayerIsREComposed(true) |
| 1381 | .andIfBottomLayerIs(BT2020_HLG) |
| 1382 | .andBottomLayerIsREComposed(false) |
| 1383 | .andIfLegacySupportFor(BT2020_HLG, false) |
| 1384 | .thenExpectBestColorModeCallUses(BT2020_HLG) |
| 1385 | .execute(); |
| 1386 | } |
| 1387 | |
| 1388 | TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_NonHdr_HW_Uses_PQ) { |
| 1389 | // Even if there are non-HDR layers present, BT2020_PQ can still be used. |
| 1390 | verify().ifTopLayerIs(BT2020_PQ) |
| 1391 | .andTopLayerIsREComposed(false) |
| 1392 | .andIfBottomLayerIsNotHdr() |
| 1393 | .andBottomLayerIsREComposed(false) |
| 1394 | .andIfLegacySupportFor(BT2020_PQ, false) |
| 1395 | .thenExpectBestColorModeCallUses(BT2020_PQ) |
| 1396 | .execute(); |
| 1397 | } |
| 1398 | |
| 1399 | TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_NonHdr_RE_Uses_HLG) { |
| 1400 | // If all layers use HLG then HLG is used if there are no other special |
| 1401 | // conditions. |
| 1402 | verify().ifTopLayerIs(BT2020_HLG) |
| 1403 | .andTopLayerIsREComposed(false) |
| 1404 | .andIfBottomLayerIsNotHdr() |
| 1405 | .andBottomLayerIsREComposed(true) |
| 1406 | .andIfLegacySupportFor(BT2020_HLG, false) |
| 1407 | .thenExpectBestColorModeCallUses(BT2020_HLG) |
| 1408 | .execute(); |
| 1409 | } |
| 1410 | |
| 1411 | struct OutputUpdateColorProfile_AffectsChosenRenderIntentTest |
| 1412 | : public OutputUpdateColorProfileTest { |
| 1413 | // The various values for CompositionRefreshArgs::outputColorSetting affect |
| 1414 | // the chosen renderIntent, along with whether the preferred dataspace is an |
| 1415 | // HDR dataspace or not. |
| 1416 | |
| 1417 | OutputUpdateColorProfile_AffectsChosenRenderIntentTest() { |
| 1418 | mRefreshArgs.outputColorSetting = OutputColorSetting::kEnhanced; |
| 1419 | mRefreshArgs.colorSpaceAgnosticDataspace = ui::Dataspace::UNKNOWN; |
| 1420 | mLayer1.mLayerFEState.dataspace = ui::Dataspace::BT2020_PQ; |
| 1421 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(1)); |
| 1422 | EXPECT_CALL(mOutput, setColorProfile(_)).WillRepeatedly(Return()); |
| 1423 | EXPECT_CALL(*mDisplayColorProfile, hasLegacyHdrSupport(ui::Dataspace::BT2020_PQ)) |
| 1424 | .WillRepeatedly(Return(false)); |
| 1425 | } |
| 1426 | |
| 1427 | // The tests here involve enough state and GMock setup that using a mini-DSL |
| 1428 | // makes the tests much more readable, and allows the test to focus more on |
| 1429 | // the intent than on some of the details. |
| 1430 | |
| 1431 | static constexpr ui::Dataspace kNonHdrDataspace = ui::Dataspace::DISPLAY_P3; |
| 1432 | static constexpr ui::Dataspace kHdrDataspace = ui::Dataspace::BT2020_PQ; |
| 1433 | |
| 1434 | struct IfDataspaceChosenState |
| 1435 | : public CallOrderStateMachineHelper<TestType, IfDataspaceChosenState> { |
| 1436 | [[nodiscard]] auto ifDataspaceChosenIs(ui::Dataspace dataspace) { |
| 1437 | getInstance()->mLayer1.mLayerFEState.dataspace = dataspace; |
| 1438 | return nextState<AndOutputColorSettingState>(); |
| 1439 | } |
| 1440 | [[nodiscard]] auto ifDataspaceChosenIsNonHdr() { |
| 1441 | return ifDataspaceChosenIs(kNonHdrDataspace); |
| 1442 | } |
| 1443 | [[nodiscard]] auto ifDataspaceChosenIsHdr() { return ifDataspaceChosenIs(kHdrDataspace); } |
| 1444 | }; |
| 1445 | |
| 1446 | struct AndOutputColorSettingState |
| 1447 | : public CallOrderStateMachineHelper<TestType, AndOutputColorSettingState> { |
| 1448 | [[nodiscard]] auto andOutputColorSettingIs(OutputColorSetting setting) { |
| 1449 | getInstance()->mRefreshArgs.outputColorSetting = setting; |
| 1450 | return nextState<ThenExpectBestColorModeCallUsesState>(); |
| 1451 | } |
| 1452 | }; |
| 1453 | |
| 1454 | struct ThenExpectBestColorModeCallUsesState |
| 1455 | : public CallOrderStateMachineHelper<TestType, ThenExpectBestColorModeCallUsesState> { |
| 1456 | [[nodiscard]] auto thenExpectBestColorModeCallUses(ui::RenderIntent intent) { |
| 1457 | EXPECT_CALL(*getInstance()->mDisplayColorProfile, |
| 1458 | getBestColorMode(getInstance()->mLayer1.mLayerFEState.dataspace, intent, _, |
| 1459 | _, _)); |
| 1460 | return nextState<ExecuteState>(); |
| 1461 | } |
| 1462 | }; |
| 1463 | |
| 1464 | // Tests call one of these two helper member functions to start using the |
| 1465 | // mini-DSL defined above. |
| 1466 | [[nodiscard]] auto verify() { return IfDataspaceChosenState::make(this); } |
| 1467 | }; |
| 1468 | |
| 1469 | TEST_F(OutputUpdateColorProfile_AffectsChosenRenderIntentTest, |
| 1470 | Managed_NonHdr_Prefers_Colorimetric) { |
| 1471 | verify().ifDataspaceChosenIsNonHdr() |
| 1472 | .andOutputColorSettingIs(OutputColorSetting::kManaged) |
| 1473 | .thenExpectBestColorModeCallUses(ui::RenderIntent::COLORIMETRIC) |
| 1474 | .execute(); |
| 1475 | } |
| 1476 | |
| 1477 | TEST_F(OutputUpdateColorProfile_AffectsChosenRenderIntentTest, |
| 1478 | Managed_Hdr_Prefers_ToneMapColorimetric) { |
| 1479 | verify().ifDataspaceChosenIsHdr() |
| 1480 | .andOutputColorSettingIs(OutputColorSetting::kManaged) |
| 1481 | .thenExpectBestColorModeCallUses(ui::RenderIntent::TONE_MAP_COLORIMETRIC) |
| 1482 | .execute(); |
| 1483 | } |
| 1484 | |
| 1485 | TEST_F(OutputUpdateColorProfile_AffectsChosenRenderIntentTest, Enhanced_NonHdr_Prefers_Enhance) { |
| 1486 | verify().ifDataspaceChosenIsNonHdr() |
| 1487 | .andOutputColorSettingIs(OutputColorSetting::kEnhanced) |
| 1488 | .thenExpectBestColorModeCallUses(ui::RenderIntent::ENHANCE) |
| 1489 | .execute(); |
| 1490 | } |
| 1491 | |
| 1492 | TEST_F(OutputUpdateColorProfile_AffectsChosenRenderIntentTest, |
| 1493 | Enhanced_Hdr_Prefers_ToneMapEnhance) { |
| 1494 | verify().ifDataspaceChosenIsHdr() |
| 1495 | .andOutputColorSettingIs(OutputColorSetting::kEnhanced) |
| 1496 | .thenExpectBestColorModeCallUses(ui::RenderIntent::TONE_MAP_ENHANCE) |
| 1497 | .execute(); |
| 1498 | } |
| 1499 | |
| 1500 | TEST_F(OutputUpdateColorProfile_AffectsChosenRenderIntentTest, Vendor_NonHdr_Prefers_Vendor) { |
| 1501 | verify().ifDataspaceChosenIsNonHdr() |
| 1502 | .andOutputColorSettingIs(kVendorSpecifiedOutputColorSetting) |
| 1503 | .thenExpectBestColorModeCallUses( |
| 1504 | static_cast<ui::RenderIntent>(kVendorSpecifiedOutputColorSetting)) |
| 1505 | .execute(); |
| 1506 | } |
| 1507 | |
| 1508 | TEST_F(OutputUpdateColorProfile_AffectsChosenRenderIntentTest, Vendor_Hdr_Prefers_Vendor) { |
| 1509 | verify().ifDataspaceChosenIsHdr() |
| 1510 | .andOutputColorSettingIs(kVendorSpecifiedOutputColorSetting) |
| 1511 | .thenExpectBestColorModeCallUses( |
| 1512 | static_cast<ui::RenderIntent>(kVendorSpecifiedOutputColorSetting)) |
| 1513 | .execute(); |
| 1514 | } |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 1515 | |
| 1516 | /* |
| 1517 | * Output::beginFrame() |
| 1518 | */ |
| 1519 | |
| 1520 | /* |
| 1521 | * Output::devOptRepaintFlash() |
| 1522 | */ |
| 1523 | |
Lloyd Pique | db462d8 | 2019-11-19 17:58:46 -0800 | [diff] [blame] | 1524 | struct OutputDevOptRepaintFlashTest : public testing::Test { |
| 1525 | struct OutputPartialMock : public OutputPartialMockBase { |
| 1526 | // Sets up the helper functions called by composeSurfaces to use a mock |
| 1527 | // implementations. |
| 1528 | MOCK_CONST_METHOD1(getDirtyRegion, Region(bool)); |
| 1529 | MOCK_METHOD1(composeSurfaces, std::optional<base::unique_fd>(const Region&)); |
| 1530 | MOCK_METHOD0(postFramebuffer, void()); |
| 1531 | MOCK_METHOD0(prepareFrame, void()); |
| 1532 | }; |
| 1533 | |
| 1534 | OutputDevOptRepaintFlashTest() { |
| 1535 | mOutput.setDisplayColorProfileForTest( |
| 1536 | std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile)); |
| 1537 | mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface)); |
| 1538 | } |
| 1539 | |
| 1540 | static const Region kEmptyRegion; |
| 1541 | static const Region kNotEmptyRegion; |
| 1542 | |
| 1543 | StrictMock<OutputPartialMock> mOutput; |
| 1544 | mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>(); |
| 1545 | mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>(); |
| 1546 | CompositionRefreshArgs mRefreshArgs; |
| 1547 | }; |
| 1548 | |
| 1549 | const Region OutputDevOptRepaintFlashTest::kEmptyRegion{Rect{0, 0, 0, 0}}; |
| 1550 | const Region OutputDevOptRepaintFlashTest::kNotEmptyRegion{Rect{0, 0, 1, 1}}; |
| 1551 | |
| 1552 | TEST_F(OutputDevOptRepaintFlashTest, doesNothingIfFlashDelayNotSet) { |
| 1553 | mRefreshArgs.devOptFlashDirtyRegionsDelay = {}; |
| 1554 | mRefreshArgs.repaintEverything = true; |
| 1555 | mOutput.mState.isEnabled = true; |
| 1556 | |
| 1557 | mOutput.devOptRepaintFlash(mRefreshArgs); |
| 1558 | } |
| 1559 | |
| 1560 | TEST_F(OutputDevOptRepaintFlashTest, postsAndPreparesANewFrameIfNotEnabled) { |
| 1561 | mRefreshArgs.devOptFlashDirtyRegionsDelay = std::chrono::microseconds(1); |
| 1562 | mRefreshArgs.repaintEverything = true; |
| 1563 | mOutput.mState.isEnabled = false; |
| 1564 | |
| 1565 | InSequence seq; |
| 1566 | EXPECT_CALL(mOutput, postFramebuffer()); |
| 1567 | EXPECT_CALL(mOutput, prepareFrame()); |
| 1568 | |
| 1569 | mOutput.devOptRepaintFlash(mRefreshArgs); |
| 1570 | } |
| 1571 | |
| 1572 | TEST_F(OutputDevOptRepaintFlashTest, postsAndPreparesANewFrameIfNotDirty) { |
| 1573 | mRefreshArgs.devOptFlashDirtyRegionsDelay = std::chrono::microseconds(1); |
| 1574 | mRefreshArgs.repaintEverything = true; |
| 1575 | mOutput.mState.isEnabled = true; |
| 1576 | |
| 1577 | InSequence seq; |
| 1578 | EXPECT_CALL(mOutput, getDirtyRegion(true)).WillOnce(Return(kEmptyRegion)); |
| 1579 | EXPECT_CALL(mOutput, postFramebuffer()); |
| 1580 | EXPECT_CALL(mOutput, prepareFrame()); |
| 1581 | |
| 1582 | mOutput.devOptRepaintFlash(mRefreshArgs); |
| 1583 | } |
| 1584 | |
| 1585 | TEST_F(OutputDevOptRepaintFlashTest, alsoComposesSurfacesAndQueuesABufferIfDirty) { |
| 1586 | mRefreshArgs.devOptFlashDirtyRegionsDelay = std::chrono::microseconds(1); |
| 1587 | mRefreshArgs.repaintEverything = false; |
| 1588 | mOutput.mState.isEnabled = true; |
| 1589 | |
| 1590 | InSequence seq; |
| 1591 | EXPECT_CALL(mOutput, getDirtyRegion(false)).WillOnce(Return(kNotEmptyRegion)); |
| 1592 | EXPECT_CALL(mOutput, composeSurfaces(RegionEq(kNotEmptyRegion))); |
| 1593 | EXPECT_CALL(*mRenderSurface, queueBuffer(_)); |
| 1594 | EXPECT_CALL(mOutput, postFramebuffer()); |
| 1595 | EXPECT_CALL(mOutput, prepareFrame()); |
| 1596 | |
| 1597 | mOutput.devOptRepaintFlash(mRefreshArgs); |
| 1598 | } |
| 1599 | |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 1600 | // TODO(b/144060211) - Add coverage |
| 1601 | |
| 1602 | /* |
| 1603 | * Output::finishFrame() |
| 1604 | */ |
| 1605 | |
Lloyd Pique | 03561a6 | 2019-11-19 18:34:52 -0800 | [diff] [blame] | 1606 | struct OutputFinishFrameTest : public testing::Test { |
| 1607 | struct OutputPartialMock : public OutputPartialMockBase { |
| 1608 | // Sets up the helper functions called by composeSurfaces to use a mock |
| 1609 | // implementations. |
| 1610 | MOCK_METHOD1(composeSurfaces, std::optional<base::unique_fd>(const Region&)); |
| 1611 | MOCK_METHOD0(postFramebuffer, void()); |
| 1612 | }; |
| 1613 | |
| 1614 | OutputFinishFrameTest() { |
| 1615 | mOutput.setDisplayColorProfileForTest( |
| 1616 | std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile)); |
| 1617 | mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface)); |
| 1618 | } |
| 1619 | |
| 1620 | StrictMock<OutputPartialMock> mOutput; |
| 1621 | mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>(); |
| 1622 | mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>(); |
| 1623 | CompositionRefreshArgs mRefreshArgs; |
| 1624 | }; |
| 1625 | |
| 1626 | TEST_F(OutputFinishFrameTest, ifNotEnabledDoesNothing) { |
| 1627 | mOutput.mState.isEnabled = false; |
| 1628 | |
| 1629 | mOutput.finishFrame(mRefreshArgs); |
| 1630 | } |
| 1631 | |
| 1632 | TEST_F(OutputFinishFrameTest, takesEarlyOutifComposeSurfacesReturnsNoFence) { |
| 1633 | mOutput.mState.isEnabled = true; |
| 1634 | |
| 1635 | InSequence seq; |
| 1636 | EXPECT_CALL(mOutput, composeSurfaces(RegionEq(Region::INVALID_REGION))); |
| 1637 | |
| 1638 | mOutput.finishFrame(mRefreshArgs); |
| 1639 | } |
| 1640 | |
| 1641 | TEST_F(OutputFinishFrameTest, queuesBufferIfComposeSurfacesReturnsAFence) { |
| 1642 | mOutput.mState.isEnabled = true; |
| 1643 | |
| 1644 | InSequence seq; |
| 1645 | EXPECT_CALL(mOutput, composeSurfaces(RegionEq(Region::INVALID_REGION))) |
| 1646 | .WillOnce(Return(ByMove(base::unique_fd()))); |
| 1647 | EXPECT_CALL(*mRenderSurface, queueBuffer(_)); |
| 1648 | |
| 1649 | mOutput.finishFrame(mRefreshArgs); |
| 1650 | } |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 1651 | |
| 1652 | /* |
| 1653 | * Output::postFramebuffer() |
| 1654 | */ |
| 1655 | |
Lloyd Pique | 07178e3 | 2019-11-19 19:15:26 -0800 | [diff] [blame^] | 1656 | struct OutputPostFramebufferTest : public testing::Test { |
| 1657 | struct OutputPartialMock : public OutputPartialMockBase { |
| 1658 | // Sets up the helper functions called by composeSurfaces to use a mock |
| 1659 | // implementations. |
| 1660 | MOCK_METHOD0(presentAndGetFrameFences, compositionengine::Output::FrameFences()); |
| 1661 | }; |
| 1662 | |
| 1663 | struct Layer { |
| 1664 | Layer() { |
| 1665 | EXPECT_CALL(outputLayer, getLayerFE()).WillRepeatedly(ReturnRef(layerFE)); |
| 1666 | EXPECT_CALL(outputLayer, getHwcLayer()).WillRepeatedly(Return(&hwc2Layer)); |
| 1667 | } |
| 1668 | |
| 1669 | StrictMock<mock::OutputLayer> outputLayer; |
| 1670 | StrictMock<mock::LayerFE> layerFE; |
| 1671 | StrictMock<HWC2::mock::Layer> hwc2Layer; |
| 1672 | }; |
| 1673 | |
| 1674 | OutputPostFramebufferTest() { |
| 1675 | mOutput.setDisplayColorProfileForTest( |
| 1676 | std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile)); |
| 1677 | mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface)); |
| 1678 | |
| 1679 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(3u)); |
| 1680 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0u)) |
| 1681 | .WillRepeatedly(Return(&mLayer1.outputLayer)); |
| 1682 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(1u)) |
| 1683 | .WillRepeatedly(Return(&mLayer2.outputLayer)); |
| 1684 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(2u)) |
| 1685 | .WillRepeatedly(Return(&mLayer3.outputLayer)); |
| 1686 | } |
| 1687 | |
| 1688 | StrictMock<OutputPartialMock> mOutput; |
| 1689 | mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>(); |
| 1690 | mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>(); |
| 1691 | |
| 1692 | Layer mLayer1; |
| 1693 | Layer mLayer2; |
| 1694 | Layer mLayer3; |
| 1695 | }; |
| 1696 | |
| 1697 | TEST_F(OutputPostFramebufferTest, ifNotEnabledDoesNothing) { |
| 1698 | mOutput.mState.isEnabled = false; |
| 1699 | |
| 1700 | mOutput.postFramebuffer(); |
| 1701 | } |
| 1702 | |
| 1703 | TEST_F(OutputPostFramebufferTest, ifEnabledMustFlipThenPresentThenSendPresentCompleted) { |
| 1704 | mOutput.mState.isEnabled = true; |
| 1705 | |
| 1706 | compositionengine::Output::FrameFences frameFences; |
| 1707 | |
| 1708 | // This should happen even if there are no output layers. |
| 1709 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u)); |
| 1710 | |
| 1711 | // For this test in particular we want to make sure the call expectations |
| 1712 | // setup below are satisfied in the specific order. |
| 1713 | InSequence seq; |
| 1714 | |
| 1715 | EXPECT_CALL(*mRenderSurface, flip()); |
| 1716 | EXPECT_CALL(mOutput, presentAndGetFrameFences()).WillOnce(Return(frameFences)); |
| 1717 | EXPECT_CALL(*mRenderSurface, onPresentDisplayCompleted()); |
| 1718 | |
| 1719 | mOutput.postFramebuffer(); |
| 1720 | } |
| 1721 | |
| 1722 | TEST_F(OutputPostFramebufferTest, releaseFencesAreSentToLayerFE) { |
| 1723 | // Simulate getting release fences from each layer, and ensure they are passed to the |
| 1724 | // front-end layer interface for each layer correctly. |
| 1725 | |
| 1726 | mOutput.mState.isEnabled = true; |
| 1727 | |
| 1728 | // Create three unique fence instances |
| 1729 | sp<Fence> layer1Fence = new Fence(); |
| 1730 | sp<Fence> layer2Fence = new Fence(); |
| 1731 | sp<Fence> layer3Fence = new Fence(); |
| 1732 | |
| 1733 | compositionengine::Output::FrameFences frameFences; |
| 1734 | frameFences.layerFences.emplace(&mLayer1.hwc2Layer, layer1Fence); |
| 1735 | frameFences.layerFences.emplace(&mLayer2.hwc2Layer, layer2Fence); |
| 1736 | frameFences.layerFences.emplace(&mLayer3.hwc2Layer, layer3Fence); |
| 1737 | |
| 1738 | EXPECT_CALL(*mRenderSurface, flip()); |
| 1739 | EXPECT_CALL(mOutput, presentAndGetFrameFences()).WillOnce(Return(frameFences)); |
| 1740 | EXPECT_CALL(*mRenderSurface, onPresentDisplayCompleted()); |
| 1741 | |
| 1742 | // Compare the pointers values of each fence to make sure the correct ones |
| 1743 | // are passed. This happens to work with the current implementation, but |
| 1744 | // would not survive certain calls like Fence::merge() which would return a |
| 1745 | // new instance. |
| 1746 | EXPECT_CALL(mLayer1.layerFE, |
| 1747 | onLayerDisplayed(Property(&sp<Fence>::get, Eq(layer1Fence.get())))); |
| 1748 | EXPECT_CALL(mLayer2.layerFE, |
| 1749 | onLayerDisplayed(Property(&sp<Fence>::get, Eq(layer2Fence.get())))); |
| 1750 | EXPECT_CALL(mLayer3.layerFE, |
| 1751 | onLayerDisplayed(Property(&sp<Fence>::get, Eq(layer3Fence.get())))); |
| 1752 | |
| 1753 | mOutput.postFramebuffer(); |
| 1754 | } |
| 1755 | |
| 1756 | TEST_F(OutputPostFramebufferTest, releaseFencesIncludeClientTargetAcquireFence) { |
| 1757 | mOutput.mState.isEnabled = true; |
| 1758 | mOutput.mState.usesClientComposition = true; |
| 1759 | |
| 1760 | sp<Fence> clientTargetAcquireFence = new Fence(); |
| 1761 | sp<Fence> layer1Fence = new Fence(); |
| 1762 | sp<Fence> layer2Fence = new Fence(); |
| 1763 | sp<Fence> layer3Fence = new Fence(); |
| 1764 | compositionengine::Output::FrameFences frameFences; |
| 1765 | frameFences.clientTargetAcquireFence = clientTargetAcquireFence; |
| 1766 | frameFences.layerFences.emplace(&mLayer1.hwc2Layer, layer1Fence); |
| 1767 | frameFences.layerFences.emplace(&mLayer2.hwc2Layer, layer2Fence); |
| 1768 | frameFences.layerFences.emplace(&mLayer3.hwc2Layer, layer3Fence); |
| 1769 | |
| 1770 | EXPECT_CALL(*mRenderSurface, flip()); |
| 1771 | EXPECT_CALL(mOutput, presentAndGetFrameFences()).WillOnce(Return(frameFences)); |
| 1772 | EXPECT_CALL(*mRenderSurface, onPresentDisplayCompleted()); |
| 1773 | |
| 1774 | // Fence::merge is called, and since none of the fences are actually valid, |
| 1775 | // Fence::NO_FENCE is returned and passed to each onLayerDisplayed() call. |
| 1776 | // This is the best we can do without creating a real kernel fence object. |
| 1777 | EXPECT_CALL(mLayer1.layerFE, onLayerDisplayed(Fence::NO_FENCE)); |
| 1778 | EXPECT_CALL(mLayer2.layerFE, onLayerDisplayed(Fence::NO_FENCE)); |
| 1779 | EXPECT_CALL(mLayer3.layerFE, onLayerDisplayed(Fence::NO_FENCE)); |
| 1780 | |
| 1781 | mOutput.postFramebuffer(); |
| 1782 | } |
| 1783 | |
| 1784 | TEST_F(OutputPostFramebufferTest, releasedLayersSentPresentFence) { |
| 1785 | mOutput.mState.isEnabled = true; |
| 1786 | mOutput.mState.usesClientComposition = true; |
| 1787 | |
| 1788 | // This should happen even if there are no (current) output layers. |
| 1789 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u)); |
| 1790 | |
| 1791 | // Load up the released layers with some mock instances |
| 1792 | sp<StrictMock<mock::LayerFE>> releasedLayer1{new StrictMock<mock::LayerFE>()}; |
| 1793 | sp<StrictMock<mock::LayerFE>> releasedLayer2{new StrictMock<mock::LayerFE>()}; |
| 1794 | sp<StrictMock<mock::LayerFE>> releasedLayer3{new StrictMock<mock::LayerFE>()}; |
| 1795 | Output::ReleasedLayers layers; |
| 1796 | layers.push_back(releasedLayer1); |
| 1797 | layers.push_back(releasedLayer2); |
| 1798 | layers.push_back(releasedLayer3); |
| 1799 | mOutput.setReleasedLayers(std::move(layers)); |
| 1800 | |
| 1801 | // Set up a fake present fence |
| 1802 | sp<Fence> presentFence = new Fence(); |
| 1803 | compositionengine::Output::FrameFences frameFences; |
| 1804 | frameFences.presentFence = presentFence; |
| 1805 | |
| 1806 | EXPECT_CALL(*mRenderSurface, flip()); |
| 1807 | EXPECT_CALL(mOutput, presentAndGetFrameFences()).WillOnce(Return(frameFences)); |
| 1808 | EXPECT_CALL(*mRenderSurface, onPresentDisplayCompleted()); |
| 1809 | |
| 1810 | // Each released layer should be given the presentFence. |
| 1811 | EXPECT_CALL(*releasedLayer1, |
| 1812 | onLayerDisplayed(Property(&sp<Fence>::get, Eq(presentFence.get())))); |
| 1813 | EXPECT_CALL(*releasedLayer2, |
| 1814 | onLayerDisplayed(Property(&sp<Fence>::get, Eq(presentFence.get())))); |
| 1815 | EXPECT_CALL(*releasedLayer3, |
| 1816 | onLayerDisplayed(Property(&sp<Fence>::get, Eq(presentFence.get())))); |
| 1817 | |
| 1818 | mOutput.postFramebuffer(); |
| 1819 | |
| 1820 | // After the call the list of released layers should have been cleared. |
| 1821 | EXPECT_TRUE(mOutput.getReleasedLayersForTest().empty()); |
| 1822 | } |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 1823 | |
| 1824 | /* |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 1825 | * Output::composeSurfaces() |
| 1826 | */ |
| 1827 | |
| 1828 | struct OutputComposeSurfacesTest : public testing::Test { |
| 1829 | static constexpr uint32_t kDefaultOutputOrientation = TR_IDENT; |
| 1830 | static constexpr ui::Dataspace kDefaultOutputDataspace = ui::Dataspace::DISPLAY_P3; |
| 1831 | |
| 1832 | static const Rect kDefaultOutputFrame; |
| 1833 | static const Rect kDefaultOutputViewport; |
| 1834 | static const Rect kDefaultOutputScissor; |
| 1835 | static const mat4 kDefaultColorTransformMat; |
| 1836 | |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 1837 | struct OutputPartialMock : public OutputPartialMockBase { |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 1838 | // Sets up the helper functions called by composeSurfaces to use a mock |
| 1839 | // implementations. |
| 1840 | MOCK_CONST_METHOD0(getSkipColorTransform, bool()); |
| 1841 | MOCK_METHOD2(generateClientCompositionRequests, |
| 1842 | std::vector<renderengine::LayerSettings>(bool, Region&)); |
| 1843 | MOCK_METHOD2(appendRegionFlashRequests, |
| 1844 | void(const Region&, std::vector<renderengine::LayerSettings>&)); |
| 1845 | MOCK_METHOD1(setExpensiveRenderingExpected, void(bool)); |
| 1846 | }; |
| 1847 | |
| 1848 | OutputComposeSurfacesTest() { |
| 1849 | mOutput.setDisplayColorProfileForTest( |
| 1850 | std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile)); |
| 1851 | mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface)); |
| 1852 | |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 1853 | mOutput.editState().frame = kDefaultOutputFrame; |
| 1854 | mOutput.editState().viewport = kDefaultOutputViewport; |
| 1855 | mOutput.editState().scissor = kDefaultOutputScissor; |
| 1856 | mOutput.editState().transform = ui::Transform{kDefaultOutputOrientation}; |
| 1857 | mOutput.editState().orientation = kDefaultOutputOrientation; |
| 1858 | mOutput.editState().dataspace = kDefaultOutputDataspace; |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 1859 | mOutput.editState().colorTransformMatrix = kDefaultColorTransformMat; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 1860 | mOutput.editState().isSecure = true; |
| 1861 | mOutput.editState().needsFiltering = false; |
| 1862 | mOutput.editState().usesClientComposition = true; |
| 1863 | mOutput.editState().usesDeviceComposition = false; |
| 1864 | |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 1865 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(2u)); |
| 1866 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0u)) |
| 1867 | .WillRepeatedly(Return(&mOutputLayer1)); |
| 1868 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(1u)) |
| 1869 | .WillRepeatedly(Return(&mOutputLayer2)); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 1870 | EXPECT_CALL(mOutput, getCompositionEngine()).WillRepeatedly(ReturnRef(mCompositionEngine)); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 1871 | EXPECT_CALL(mCompositionEngine, getRenderEngine()).WillRepeatedly(ReturnRef(mRenderEngine)); |
| 1872 | } |
| 1873 | |
| 1874 | StrictMock<mock::CompositionEngine> mCompositionEngine; |
| 1875 | StrictMock<renderengine::mock::RenderEngine> mRenderEngine; |
| 1876 | mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>(); |
| 1877 | mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>(); |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 1878 | StrictMock<mock::OutputLayer> mOutputLayer1; |
| 1879 | StrictMock<mock::OutputLayer> mOutputLayer2; |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 1880 | StrictMock<OutputPartialMock> mOutput; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 1881 | sp<GraphicBuffer> mOutputBuffer = new GraphicBuffer(); |
| 1882 | }; |
| 1883 | |
| 1884 | const Rect OutputComposeSurfacesTest::kDefaultOutputFrame{1001, 1002, 1003, 1004}; |
| 1885 | const Rect OutputComposeSurfacesTest::kDefaultOutputViewport{1005, 1006, 1007, 1008}; |
| 1886 | const Rect OutputComposeSurfacesTest::kDefaultOutputScissor{1009, 1010, 1011, 1012}; |
| 1887 | const mat4 OutputComposeSurfacesTest::kDefaultColorTransformMat{mat4() * 0.5}; |
| 1888 | |
| 1889 | // TODO(b/121291683): Expand unit test coverage for composeSurfaces beyond these |
| 1890 | // basic tests. |
| 1891 | |
| 1892 | TEST_F(OutputComposeSurfacesTest, doesNothingIfNoClientComposition) { |
| 1893 | mOutput.editState().usesClientComposition = false; |
| 1894 | |
| 1895 | Region debugRegion; |
Lloyd Pique | d3d6988 | 2019-02-28 16:03:46 -0800 | [diff] [blame] | 1896 | std::optional<base::unique_fd> readyFence = mOutput.composeSurfaces(debugRegion); |
| 1897 | EXPECT_TRUE(readyFence); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 1898 | } |
| 1899 | |
| 1900 | TEST_F(OutputComposeSurfacesTest, worksIfNoClientLayersQueued) { |
| 1901 | const Region kDebugRegion{Rect{100, 101, 102, 103}}; |
| 1902 | |
| 1903 | constexpr float kDefaultMaxLuminance = 1.0f; |
| 1904 | constexpr float kDefaultAvgLuminance = 0.7f; |
| 1905 | constexpr float kDefaultMinLuminance = 0.1f; |
| 1906 | HdrCapabilities HdrCapabilities{{}, |
| 1907 | kDefaultMaxLuminance, |
| 1908 | kDefaultAvgLuminance, |
| 1909 | kDefaultMinLuminance}; |
| 1910 | |
| 1911 | EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillOnce(Return(false)); |
| 1912 | EXPECT_CALL(mRenderEngine, drawLayers(_, _, _, true, _, _)).Times(1); |
| 1913 | |
| 1914 | EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillOnce(Return(true)); |
| 1915 | EXPECT_CALL(*mDisplayColorProfile, getHdrCapabilities()).WillOnce(ReturnRef(HdrCapabilities)); |
| 1916 | |
| 1917 | EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillOnce(Return(mOutputBuffer)); |
| 1918 | |
| 1919 | EXPECT_CALL(mOutput, getSkipColorTransform()).WillOnce(Return(false)); |
| 1920 | EXPECT_CALL(mOutput, generateClientCompositionRequests(false, _)).Times(1); |
| 1921 | EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _)).Times(1); |
| 1922 | EXPECT_CALL(mOutput, setExpensiveRenderingExpected(true)).Times(1); |
| 1923 | EXPECT_CALL(mOutput, setExpensiveRenderingExpected(false)).Times(1); |
| 1924 | |
Lloyd Pique | d3d6988 | 2019-02-28 16:03:46 -0800 | [diff] [blame] | 1925 | std::optional<base::unique_fd> readyFence = mOutput.composeSurfaces(kDebugRegion); |
| 1926 | EXPECT_TRUE(readyFence); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 1927 | } |
| 1928 | |
| 1929 | /* |
| 1930 | * Output::generateClientCompositionRequests() |
| 1931 | */ |
| 1932 | |
| 1933 | struct GenerateClientCompositionRequestsTest : public testing::Test { |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 1934 | struct OutputPartialMock : public OutputPartialMockBase { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 1935 | // compositionengine::Output overrides |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 1936 | std::vector<renderengine::LayerSettings> generateClientCompositionRequests( |
| 1937 | bool supportsProtectedContent, Region& clearRegion) override { |
| 1938 | return impl::Output::generateClientCompositionRequests(supportsProtectedContent, |
| 1939 | clearRegion); |
| 1940 | } |
| 1941 | }; |
| 1942 | |
| 1943 | GenerateClientCompositionRequestsTest() { |
| 1944 | mOutput.setDisplayColorProfileForTest( |
| 1945 | std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile)); |
| 1946 | mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface)); |
| 1947 | } |
| 1948 | |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 1949 | mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>(); |
| 1950 | mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>(); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 1951 | StrictMock<OutputPartialMock> mOutput; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 1952 | }; |
| 1953 | |
| 1954 | // TODO(b/121291683): Add more unit test coverage for generateClientCompositionRequests |
| 1955 | |
| 1956 | TEST_F(GenerateClientCompositionRequestsTest, worksForLandscapeModeSplitScreen) { |
| 1957 | // In split-screen landscape mode, the screen is rotated 90 degrees, with |
| 1958 | // one layer on the left covering the left side of the output, and one layer |
| 1959 | // on the right covering that side of the output. |
| 1960 | |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 1961 | StrictMock<mock::OutputLayer> leftOutputLayer; |
| 1962 | StrictMock<mock::OutputLayer> rightOutputLayer; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 1963 | |
| 1964 | StrictMock<mock::Layer> leftLayer; |
| 1965 | StrictMock<mock::LayerFE> leftLayerFE; |
| 1966 | StrictMock<mock::Layer> rightLayer; |
| 1967 | StrictMock<mock::LayerFE> rightLayerFE; |
| 1968 | |
| 1969 | impl::OutputLayerCompositionState leftOutputLayerState; |
| 1970 | leftOutputLayerState.clearClientTarget = false; |
Lloyd Pique | a246866 | 2019-03-07 21:31:06 -0800 | [diff] [blame] | 1971 | leftOutputLayerState.visibleRegion = Region{Rect{0, 0, 1000, 1000}}; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 1972 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 1973 | LayerFECompositionState leftLayerFEState; |
| 1974 | leftLayerFEState.isOpaque = true; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 1975 | |
| 1976 | const half3 leftLayerColor{1.f, 0.f, 0.f}; |
| 1977 | renderengine::LayerSettings leftLayerRESettings; |
| 1978 | leftLayerRESettings.source.solidColor = leftLayerColor; |
| 1979 | |
| 1980 | impl::OutputLayerCompositionState rightOutputLayerState; |
| 1981 | rightOutputLayerState.clearClientTarget = false; |
Lloyd Pique | a246866 | 2019-03-07 21:31:06 -0800 | [diff] [blame] | 1982 | rightOutputLayerState.visibleRegion = Region{Rect{1000, 0, 2000, 1000}}; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 1983 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 1984 | LayerFECompositionState rightLayerFEState; |
| 1985 | rightLayerFEState.isOpaque = true; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 1986 | |
| 1987 | const half3 rightLayerColor{0.f, 1.f, 0.f}; |
| 1988 | renderengine::LayerSettings rightLayerRESettings; |
| 1989 | rightLayerRESettings.source.solidColor = rightLayerColor; |
| 1990 | |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 1991 | EXPECT_CALL(leftOutputLayer, getState()).WillRepeatedly(ReturnRef(leftOutputLayerState)); |
| 1992 | EXPECT_CALL(leftOutputLayer, getLayer()).WillRepeatedly(ReturnRef(leftLayer)); |
| 1993 | EXPECT_CALL(leftOutputLayer, getLayerFE()).WillRepeatedly(ReturnRef(leftLayerFE)); |
| 1994 | EXPECT_CALL(leftOutputLayer, requiresClientComposition()).WillRepeatedly(Return(true)); |
| 1995 | EXPECT_CALL(leftOutputLayer, needsFiltering()).WillRepeatedly(Return(false)); |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 1996 | EXPECT_CALL(leftLayer, getFEState()).WillRepeatedly(ReturnRef(leftLayerFEState)); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 1997 | EXPECT_CALL(leftLayerFE, prepareClientComposition(_)).WillOnce(Return(leftLayerRESettings)); |
Adithya Srinivasan | b69e076 | 2019-11-11 18:39:53 -0800 | [diff] [blame] | 1998 | EXPECT_CALL(leftOutputLayer, editState()).WillRepeatedly(ReturnRef(leftOutputLayerState)); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 1999 | |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 2000 | EXPECT_CALL(rightOutputLayer, getState()).WillRepeatedly(ReturnRef(rightOutputLayerState)); |
| 2001 | EXPECT_CALL(rightOutputLayer, getLayer()).WillRepeatedly(ReturnRef(rightLayer)); |
| 2002 | EXPECT_CALL(rightOutputLayer, getLayerFE()).WillRepeatedly(ReturnRef(rightLayerFE)); |
| 2003 | EXPECT_CALL(rightOutputLayer, requiresClientComposition()).WillRepeatedly(Return(true)); |
| 2004 | EXPECT_CALL(rightOutputLayer, needsFiltering()).WillRepeatedly(Return(false)); |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 2005 | EXPECT_CALL(rightLayer, getFEState()).WillRepeatedly(ReturnRef(rightLayerFEState)); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 2006 | EXPECT_CALL(rightLayerFE, prepareClientComposition(_)).WillOnce(Return(rightLayerRESettings)); |
Adithya Srinivasan | b69e076 | 2019-11-11 18:39:53 -0800 | [diff] [blame] | 2007 | EXPECT_CALL(rightOutputLayer, editState()).WillRepeatedly(ReturnRef(rightOutputLayerState)); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 2008 | |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 2009 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(2u)); |
| 2010 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0u)) |
| 2011 | .WillRepeatedly(Return(&leftOutputLayer)); |
| 2012 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(1u)) |
| 2013 | .WillRepeatedly(Return(&rightOutputLayer)); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 2014 | |
| 2015 | const Rect kPortraitFrame(0, 0, 1000, 2000); |
| 2016 | const Rect kPortraitViewport(0, 0, 2000, 1000); |
| 2017 | const Rect kPortraitScissor(0, 0, 1000, 2000); |
| 2018 | const uint32_t kPortraitOrientation = TR_ROT_90; |
| 2019 | |
| 2020 | mOutput.editState().frame = kPortraitFrame; |
| 2021 | mOutput.editState().viewport = kPortraitViewport; |
| 2022 | mOutput.editState().scissor = kPortraitScissor; |
| 2023 | mOutput.editState().transform = ui::Transform{kPortraitOrientation}; |
| 2024 | mOutput.editState().orientation = kPortraitOrientation; |
| 2025 | mOutput.editState().needsFiltering = true; |
| 2026 | mOutput.editState().isSecure = false; |
| 2027 | |
| 2028 | constexpr bool supportsProtectedContent = false; |
| 2029 | Region clearRegion; |
| 2030 | auto requests = |
| 2031 | mOutput.generateClientCompositionRequests(supportsProtectedContent, clearRegion); |
| 2032 | |
| 2033 | ASSERT_EQ(2u, requests.size()); |
| 2034 | EXPECT_EQ(leftLayerColor, requests[0].source.solidColor); |
| 2035 | EXPECT_EQ(rightLayerColor, requests[1].source.solidColor); |
| 2036 | } |
| 2037 | |
| 2038 | TEST_F(GenerateClientCompositionRequestsTest, ignoresLayersThatDoNotIntersectWithViewport) { |
| 2039 | // Layers whose visible region does not intersect with the viewport will be |
| 2040 | // skipped when generating client composition request state. |
| 2041 | |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 2042 | StrictMock<mock::OutputLayer> outputLayer; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 2043 | StrictMock<mock::Layer> layer; |
| 2044 | StrictMock<mock::LayerFE> layerFE; |
| 2045 | |
| 2046 | impl::OutputLayerCompositionState outputLayerState; |
| 2047 | outputLayerState.clearClientTarget = false; |
Lloyd Pique | a246866 | 2019-03-07 21:31:06 -0800 | [diff] [blame] | 2048 | outputLayerState.visibleRegion = Region{Rect{3000, 0, 4000, 1000}}; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 2049 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 2050 | LayerFECompositionState layerFEState; |
| 2051 | layerFEState.isOpaque = true; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 2052 | |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 2053 | EXPECT_CALL(outputLayer, getState()).WillRepeatedly(ReturnRef(outputLayerState)); |
| 2054 | EXPECT_CALL(outputLayer, getLayer()).WillRepeatedly(ReturnRef(layer)); |
| 2055 | EXPECT_CALL(outputLayer, getLayerFE()).WillRepeatedly(ReturnRef(layerFE)); |
| 2056 | EXPECT_CALL(outputLayer, requiresClientComposition()).WillRepeatedly(Return(true)); |
| 2057 | EXPECT_CALL(outputLayer, needsFiltering()).WillRepeatedly(Return(false)); |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 2058 | EXPECT_CALL(layer, getFEState()).WillRepeatedly(ReturnRef(layerFEState)); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 2059 | EXPECT_CALL(layerFE, prepareClientComposition(_)).Times(0); |
Adithya Srinivasan | b69e076 | 2019-11-11 18:39:53 -0800 | [diff] [blame] | 2060 | EXPECT_CALL(outputLayer, editState()).WillRepeatedly(ReturnRef(outputLayerState)); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 2061 | |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 2062 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(1u)); |
| 2063 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0u)).WillRepeatedly(Return(&outputLayer)); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 2064 | |
| 2065 | const Rect kPortraitFrame(0, 0, 1000, 2000); |
| 2066 | const Rect kPortraitViewport(0, 0, 2000, 1000); |
| 2067 | const Rect kPortraitScissor(0, 0, 1000, 2000); |
| 2068 | const uint32_t kPortraitOrientation = TR_ROT_90; |
| 2069 | |
| 2070 | mOutput.editState().frame = kPortraitFrame; |
| 2071 | mOutput.editState().viewport = kPortraitViewport; |
| 2072 | mOutput.editState().scissor = kPortraitScissor; |
| 2073 | mOutput.editState().transform = ui::Transform{kPortraitOrientation}; |
| 2074 | mOutput.editState().orientation = kPortraitOrientation; |
| 2075 | mOutput.editState().needsFiltering = true; |
| 2076 | mOutput.editState().isSecure = false; |
| 2077 | |
| 2078 | constexpr bool supportsProtectedContent = false; |
| 2079 | Region clearRegion; |
| 2080 | auto requests = |
| 2081 | mOutput.generateClientCompositionRequests(supportsProtectedContent, clearRegion); |
| 2082 | |
| 2083 | EXPECT_EQ(0u, requests.size()); |
| 2084 | } |
| 2085 | |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 2086 | TEST_F(GenerateClientCompositionRequestsTest, clearsDeviceLayesAfterFirst) { |
| 2087 | // If client composition is performed with some layers set to use device |
| 2088 | // composition, device layers after the first layer (device or client) will |
| 2089 | // clear the frame buffer if they are opaque and if that layer has a flag |
| 2090 | // set to do so. The first layer is skipped as the frame buffer is already |
| 2091 | // expected to be clear. |
| 2092 | |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 2093 | StrictMock<mock::OutputLayer> leftOutputLayer; |
| 2094 | StrictMock<mock::OutputLayer> rightOutputLayer; |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 2095 | |
| 2096 | StrictMock<mock::Layer> leftLayer; |
| 2097 | StrictMock<mock::LayerFE> leftLayerFE; |
| 2098 | StrictMock<mock::Layer> rightLayer; |
| 2099 | StrictMock<mock::LayerFE> rightLayerFE; |
| 2100 | |
| 2101 | impl::OutputLayerCompositionState leftOutputLayerState; |
| 2102 | leftOutputLayerState.clearClientTarget = true; |
Lloyd Pique | a246866 | 2019-03-07 21:31:06 -0800 | [diff] [blame] | 2103 | leftOutputLayerState.visibleRegion = Region{Rect{0, 0, 1000, 1000}}; |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 2104 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 2105 | LayerFECompositionState leftLayerFEState; |
| 2106 | leftLayerFEState.isOpaque = true; |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 2107 | |
| 2108 | impl::OutputLayerCompositionState rightOutputLayerState; |
| 2109 | rightOutputLayerState.clearClientTarget = true; |
Lloyd Pique | a246866 | 2019-03-07 21:31:06 -0800 | [diff] [blame] | 2110 | rightOutputLayerState.visibleRegion = Region{Rect{1000, 0, 2000, 1000}}; |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 2111 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 2112 | LayerFECompositionState rightLayerFEState; |
| 2113 | rightLayerFEState.isOpaque = true; |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 2114 | |
| 2115 | const half3 rightLayerColor{0.f, 1.f, 0.f}; |
| 2116 | renderengine::LayerSettings rightLayerRESettings; |
| 2117 | rightLayerRESettings.geometry.boundaries = FloatRect{456, 0, 0, 0}; |
| 2118 | rightLayerRESettings.source.solidColor = rightLayerColor; |
| 2119 | |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 2120 | EXPECT_CALL(leftOutputLayer, getState()).WillRepeatedly(ReturnRef(leftOutputLayerState)); |
| 2121 | EXPECT_CALL(leftOutputLayer, getLayer()).WillRepeatedly(ReturnRef(leftLayer)); |
| 2122 | EXPECT_CALL(leftOutputLayer, getLayerFE()).WillRepeatedly(ReturnRef(leftLayerFE)); |
| 2123 | EXPECT_CALL(leftOutputLayer, requiresClientComposition()).WillRepeatedly(Return(false)); |
| 2124 | EXPECT_CALL(leftOutputLayer, needsFiltering()).WillRepeatedly(Return(false)); |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 2125 | EXPECT_CALL(leftLayer, getFEState()).WillRepeatedly(ReturnRef(leftLayerFEState)); |
Adithya Srinivasan | b69e076 | 2019-11-11 18:39:53 -0800 | [diff] [blame] | 2126 | EXPECT_CALL(leftOutputLayer, editState()).WillRepeatedly(ReturnRef(leftOutputLayerState)); |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 2127 | |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 2128 | EXPECT_CALL(rightOutputLayer, getState()).WillRepeatedly(ReturnRef(rightOutputLayerState)); |
| 2129 | EXPECT_CALL(rightOutputLayer, getLayer()).WillRepeatedly(ReturnRef(rightLayer)); |
| 2130 | EXPECT_CALL(rightOutputLayer, getLayerFE()).WillRepeatedly(ReturnRef(rightLayerFE)); |
| 2131 | EXPECT_CALL(rightOutputLayer, requiresClientComposition()).WillRepeatedly(Return(false)); |
| 2132 | EXPECT_CALL(rightOutputLayer, needsFiltering()).WillRepeatedly(Return(false)); |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 2133 | EXPECT_CALL(rightLayer, getFEState()).WillRepeatedly(ReturnRef(rightLayerFEState)); |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 2134 | EXPECT_CALL(rightLayerFE, prepareClientComposition(_)).WillOnce(Return(rightLayerRESettings)); |
Adithya Srinivasan | b69e076 | 2019-11-11 18:39:53 -0800 | [diff] [blame] | 2135 | EXPECT_CALL(rightOutputLayer, editState()).WillRepeatedly(ReturnRef(rightOutputLayerState)); |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 2136 | |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 2137 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(2u)); |
| 2138 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0u)) |
| 2139 | .WillRepeatedly(Return(&leftOutputLayer)); |
| 2140 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(1u)) |
| 2141 | .WillRepeatedly(Return(&rightOutputLayer)); |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 2142 | |
| 2143 | const Rect kPortraitFrame(0, 0, 1000, 2000); |
| 2144 | const Rect kPortraitViewport(0, 0, 2000, 1000); |
| 2145 | const Rect kPortraitScissor(0, 0, 1000, 2000); |
| 2146 | const uint32_t kPortraitOrientation = TR_ROT_90; |
| 2147 | |
| 2148 | mOutput.editState().frame = kPortraitFrame; |
| 2149 | mOutput.editState().viewport = kPortraitViewport; |
| 2150 | mOutput.editState().scissor = kPortraitScissor; |
| 2151 | mOutput.editState().transform = ui::Transform{kPortraitOrientation}; |
| 2152 | mOutput.editState().orientation = kPortraitOrientation; |
| 2153 | mOutput.editState().needsFiltering = true; |
| 2154 | mOutput.editState().isSecure = false; |
| 2155 | |
| 2156 | constexpr bool supportsProtectedContent = false; |
| 2157 | Region clearRegion; |
| 2158 | auto requests = |
| 2159 | mOutput.generateClientCompositionRequests(supportsProtectedContent, clearRegion); |
| 2160 | |
| 2161 | const half3 clearColor{0.f, 0.f, 0.f}; |
| 2162 | |
| 2163 | ASSERT_EQ(1u, requests.size()); |
| 2164 | EXPECT_EQ(456.f, requests[0].geometry.boundaries.left); |
| 2165 | EXPECT_EQ(clearColor, requests[0].source.solidColor); |
| 2166 | } |
| 2167 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 2168 | } // namespace |
| 2169 | } // namespace android::compositionengine |