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