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