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