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