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