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