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