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