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