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. |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 3223 | EXPECT_CALL(*mLayer1.layerFE, onLayerDisplayed(_)) |
Dominik Laskowski | b17c621 | 2022-05-09 09:36:19 -0700 | [diff] [blame] | 3224 | .WillOnce([&layer1Fence](ftl::SharedFuture<FenceResult> futureFenceResult) { |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 3225 | EXPECT_EQ(FenceResult(layer1Fence), futureFenceResult.get()); |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 3226 | }); |
| 3227 | EXPECT_CALL(*mLayer2.layerFE, onLayerDisplayed(_)) |
Dominik Laskowski | b17c621 | 2022-05-09 09:36:19 -0700 | [diff] [blame] | 3228 | .WillOnce([&layer2Fence](ftl::SharedFuture<FenceResult> futureFenceResult) { |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 3229 | EXPECT_EQ(FenceResult(layer2Fence), futureFenceResult.get()); |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 3230 | }); |
| 3231 | EXPECT_CALL(*mLayer3.layerFE, onLayerDisplayed(_)) |
Dominik Laskowski | b17c621 | 2022-05-09 09:36:19 -0700 | [diff] [blame] | 3232 | .WillOnce([&layer3Fence](ftl::SharedFuture<FenceResult> futureFenceResult) { |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 3233 | EXPECT_EQ(FenceResult(layer3Fence), futureFenceResult.get()); |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 3234 | }); |
Lloyd Pique | 07178e3 | 2019-11-19 19:15:26 -0800 | [diff] [blame] | 3235 | |
| 3236 | mOutput.postFramebuffer(); |
| 3237 | } |
| 3238 | |
| 3239 | TEST_F(OutputPostFramebufferTest, releaseFencesIncludeClientTargetAcquireFence) { |
| 3240 | mOutput.mState.isEnabled = true; |
| 3241 | mOutput.mState.usesClientComposition = true; |
| 3242 | |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 3243 | Output::FrameFences frameFences; |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 3244 | frameFences.clientTargetAcquireFence = sp<Fence>::make(); |
| 3245 | frameFences.layerFences.emplace(&mLayer1.hwc2Layer, sp<Fence>::make()); |
| 3246 | frameFences.layerFences.emplace(&mLayer2.hwc2Layer, sp<Fence>::make()); |
| 3247 | frameFences.layerFences.emplace(&mLayer3.hwc2Layer, sp<Fence>::make()); |
Lloyd Pique | 07178e3 | 2019-11-19 19:15:26 -0800 | [diff] [blame] | 3248 | |
Lloyd Pique | 07178e3 | 2019-11-19 19:15:26 -0800 | [diff] [blame] | 3249 | EXPECT_CALL(mOutput, presentAndGetFrameFences()).WillOnce(Return(frameFences)); |
| 3250 | EXPECT_CALL(*mRenderSurface, onPresentDisplayCompleted()); |
| 3251 | |
| 3252 | // Fence::merge is called, and since none of the fences are actually valid, |
| 3253 | // Fence::NO_FENCE is returned and passed to each onLayerDisplayed() call. |
| 3254 | // 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] | 3255 | EXPECT_CALL(*mLayer1.layerFE, onLayerDisplayed).WillOnce(Return()); |
| 3256 | EXPECT_CALL(*mLayer2.layerFE, onLayerDisplayed).WillOnce(Return()); |
| 3257 | EXPECT_CALL(*mLayer3.layerFE, onLayerDisplayed).WillOnce(Return()); |
Lloyd Pique | 07178e3 | 2019-11-19 19:15:26 -0800 | [diff] [blame] | 3258 | |
| 3259 | mOutput.postFramebuffer(); |
| 3260 | } |
| 3261 | |
| 3262 | TEST_F(OutputPostFramebufferTest, releasedLayersSentPresentFence) { |
| 3263 | mOutput.mState.isEnabled = true; |
| 3264 | mOutput.mState.usesClientComposition = true; |
| 3265 | |
| 3266 | // This should happen even if there are no (current) output layers. |
| 3267 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u)); |
| 3268 | |
| 3269 | // Load up the released layers with some mock instances |
Ady Abraham | e0eafa8 | 2022-02-02 19:30:47 -0800 | [diff] [blame] | 3270 | sp<StrictMock<mock::LayerFE>> releasedLayer1 = sp<StrictMock<mock::LayerFE>>::make(); |
| 3271 | sp<StrictMock<mock::LayerFE>> releasedLayer2 = sp<StrictMock<mock::LayerFE>>::make(); |
| 3272 | sp<StrictMock<mock::LayerFE>> releasedLayer3 = sp<StrictMock<mock::LayerFE>>::make(); |
Lloyd Pique | 07178e3 | 2019-11-19 19:15:26 -0800 | [diff] [blame] | 3273 | Output::ReleasedLayers layers; |
| 3274 | layers.push_back(releasedLayer1); |
| 3275 | layers.push_back(releasedLayer2); |
| 3276 | layers.push_back(releasedLayer3); |
| 3277 | mOutput.setReleasedLayers(std::move(layers)); |
| 3278 | |
| 3279 | // Set up a fake present fence |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 3280 | sp<Fence> presentFence = sp<Fence>::make(); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 3281 | Output::FrameFences frameFences; |
Lloyd Pique | 07178e3 | 2019-11-19 19:15:26 -0800 | [diff] [blame] | 3282 | frameFences.presentFence = presentFence; |
| 3283 | |
Lloyd Pique | 07178e3 | 2019-11-19 19:15:26 -0800 | [diff] [blame] | 3284 | EXPECT_CALL(mOutput, presentAndGetFrameFences()).WillOnce(Return(frameFences)); |
| 3285 | EXPECT_CALL(*mRenderSurface, onPresentDisplayCompleted()); |
| 3286 | |
| 3287 | // Each released layer should be given the presentFence. |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 3288 | EXPECT_CALL(*releasedLayer1, onLayerDisplayed(_)) |
Dominik Laskowski | b17c621 | 2022-05-09 09:36:19 -0700 | [diff] [blame] | 3289 | .WillOnce([&presentFence](ftl::SharedFuture<FenceResult> futureFenceResult) { |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 3290 | EXPECT_EQ(FenceResult(presentFence), futureFenceResult.get()); |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 3291 | }); |
| 3292 | EXPECT_CALL(*releasedLayer2, onLayerDisplayed(_)) |
Dominik Laskowski | b17c621 | 2022-05-09 09:36:19 -0700 | [diff] [blame] | 3293 | .WillOnce([&presentFence](ftl::SharedFuture<FenceResult> futureFenceResult) { |
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 | }); |
| 3296 | EXPECT_CALL(*releasedLayer3, onLayerDisplayed(_)) |
Dominik Laskowski | b17c621 | 2022-05-09 09:36:19 -0700 | [diff] [blame] | 3297 | .WillOnce([&presentFence](ftl::SharedFuture<FenceResult> futureFenceResult) { |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 3298 | EXPECT_EQ(FenceResult(presentFence), futureFenceResult.get()); |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 3299 | }); |
Lloyd Pique | 07178e3 | 2019-11-19 19:15:26 -0800 | [diff] [blame] | 3300 | |
| 3301 | mOutput.postFramebuffer(); |
| 3302 | |
| 3303 | // After the call the list of released layers should have been cleared. |
| 3304 | EXPECT_TRUE(mOutput.getReleasedLayersForTest().empty()); |
| 3305 | } |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 3306 | |
| 3307 | /* |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 3308 | * Output::composeSurfaces() |
| 3309 | */ |
| 3310 | |
| 3311 | struct OutputComposeSurfacesTest : public testing::Test { |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3312 | using TestType = OutputComposeSurfacesTest; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 3313 | |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 3314 | struct OutputPartialMock : public OutputPartialMockBase { |
Lloyd Pique | 739afaf | 2019-11-21 16:40:05 -0800 | [diff] [blame] | 3315 | // Sets up the helper functions called by the function under test to use |
| 3316 | // mock implementations. |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 3317 | MOCK_CONST_METHOD0(getSkipColorTransform, bool()); |
Robert Carr | ccab424 | 2021-09-28 16:53:03 -0700 | [diff] [blame] | 3318 | MOCK_METHOD3(generateClientCompositionRequests, |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 3319 | std::vector<LayerFE::LayerSettings>(bool, ui::Dataspace, |
| 3320 | std::vector<LayerFE*>&)); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 3321 | MOCK_METHOD2(appendRegionFlashRequests, |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 3322 | void(const Region&, std::vector<LayerFE::LayerSettings>&)); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 3323 | MOCK_METHOD1(setExpensiveRenderingExpected, void(bool)); |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 3324 | MOCK_METHOD(void, setHintSessionGpuFence, (std::unique_ptr<FenceTime> && gpuFence), |
| 3325 | (override)); |
| 3326 | MOCK_METHOD(bool, isPowerHintSessionEnabled, (), (override)); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 3327 | }; |
| 3328 | |
| 3329 | OutputComposeSurfacesTest() { |
| 3330 | mOutput.setDisplayColorProfileForTest( |
| 3331 | std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile)); |
| 3332 | mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface)); |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 3333 | mOutput.cacheClientCompositionRequests(MAX_CLIENT_COMPOSITION_CACHE_SIZE); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 3334 | |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 3335 | mOutput.mState.orientedDisplaySpace.setContent(kDefaultOutputFrame); |
| 3336 | mOutput.mState.layerStackSpace.setContent(kDefaultOutputViewport); |
| 3337 | mOutput.mState.framebufferSpace.setContent(kDefaultOutputDestinationClip); |
| 3338 | mOutput.mState.displaySpace.setContent(kDefaultOutputDestinationClip); |
| 3339 | mOutput.mState.displaySpace.setOrientation(kDefaultOutputOrientation); |
Marin Shalamanov | b15d227 | 2020-09-17 21:41:52 +0200 | [diff] [blame] | 3340 | mOutput.mState.transform = ui::Transform{kDefaultOutputOrientationFlags}; |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3341 | mOutput.mState.dataspace = kDefaultOutputDataspace; |
| 3342 | mOutput.mState.colorTransformMatrix = kDefaultColorTransformMat; |
| 3343 | mOutput.mState.isSecure = false; |
| 3344 | mOutput.mState.needsFiltering = false; |
| 3345 | mOutput.mState.usesClientComposition = true; |
| 3346 | mOutput.mState.usesDeviceComposition = false; |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 3347 | mOutput.mState.reusedClientComposition = false; |
Lloyd Pique | e9eff97 | 2020-05-05 12:36:44 -0700 | [diff] [blame] | 3348 | mOutput.mState.flipClientTarget = false; |
Alec Mouri | f8d093d | 2022-02-10 15:16:59 -0800 | [diff] [blame] | 3349 | mOutput.mState.clientTargetBrightness = kClientTargetBrightness; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 3350 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 3351 | EXPECT_CALL(mOutput, getCompositionEngine()).WillRepeatedly(ReturnRef(mCompositionEngine)); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 3352 | EXPECT_CALL(mCompositionEngine, getRenderEngine()).WillRepeatedly(ReturnRef(mRenderEngine)); |
Patrick Williams | 74c0bf6 | 2022-11-02 23:59:26 +0000 | [diff] [blame] | 3353 | EXPECT_CALL(mCompositionEngine, getTimeStats()).WillRepeatedly(Return(mTimeStats.get())); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3354 | EXPECT_CALL(*mDisplayColorProfile, getHdrCapabilities()) |
| 3355 | .WillRepeatedly(ReturnRef(kHdrCapabilities)); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 3356 | } |
| 3357 | |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3358 | struct ExecuteState : public CallOrderStateMachineHelper<TestType, ExecuteState> { |
| 3359 | auto execute() { |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 3360 | base::unique_fd fence; |
| 3361 | std::shared_ptr<renderengine::ExternalTexture> externalTexture; |
| 3362 | const bool success = |
| 3363 | getInstance()->mOutput.dequeueRenderBuffer(&fence, &externalTexture); |
| 3364 | if (success) { |
| 3365 | getInstance()->mReadyFence = |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 3366 | getInstance()->mOutput.composeSurfaces(kDebugRegion, externalTexture, |
| 3367 | fence); |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 3368 | } |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3369 | return nextState<FenceCheckState>(); |
| 3370 | } |
| 3371 | }; |
| 3372 | |
| 3373 | struct FenceCheckState : public CallOrderStateMachineHelper<TestType, FenceCheckState> { |
| 3374 | void expectNoFenceWasReturned() { EXPECT_FALSE(getInstance()->mReadyFence); } |
| 3375 | |
| 3376 | void expectAFenceWasReturned() { EXPECT_TRUE(getInstance()->mReadyFence); } |
| 3377 | }; |
| 3378 | |
| 3379 | // Call this member function to start using the mini-DSL defined above. |
| 3380 | [[nodiscard]] auto verify() { return ExecuteState::make(this); } |
| 3381 | |
Marin Shalamanov | 68933fb | 2020-09-10 17:58:12 +0200 | [diff] [blame] | 3382 | static constexpr ui::Rotation kDefaultOutputOrientation = ui::ROTATION_0; |
| 3383 | static constexpr uint32_t kDefaultOutputOrientationFlags = |
| 3384 | ui::Transform::toRotationFlags(kDefaultOutputOrientation); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3385 | static constexpr ui::Dataspace kDefaultOutputDataspace = ui::Dataspace::UNKNOWN; |
| 3386 | static constexpr ui::Dataspace kExpensiveOutputDataspace = ui::Dataspace::DISPLAY_P3; |
| 3387 | static constexpr float kDefaultMaxLuminance = 0.9f; |
| 3388 | static constexpr float kDefaultAvgLuminance = 0.7f; |
| 3389 | static constexpr float kDefaultMinLuminance = 0.1f; |
Alec Mouri | f8d093d | 2022-02-10 15:16:59 -0800 | [diff] [blame] | 3390 | static constexpr float kDisplayLuminance = 400.f; |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 3391 | static constexpr float kClientTargetLuminanceNits = 200.f; |
Alec Mouri | f8d093d | 2022-02-10 15:16:59 -0800 | [diff] [blame] | 3392 | static constexpr float kClientTargetBrightness = 0.5f; |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3393 | |
| 3394 | static const Rect kDefaultOutputFrame; |
| 3395 | static const Rect kDefaultOutputViewport; |
Lloyd Pique | e8fe474 | 2020-01-21 15:26:18 -0800 | [diff] [blame] | 3396 | static const Rect kDefaultOutputDestinationClip; |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3397 | static const mat4 kDefaultColorTransformMat; |
| 3398 | |
| 3399 | static const Region kDebugRegion; |
Lucas Dupin | 2dd6f39 | 2020-02-18 17:43:36 -0800 | [diff] [blame] | 3400 | static const compositionengine::CompositionRefreshArgs kDefaultRefreshArgs; |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3401 | static const HdrCapabilities kHdrCapabilities; |
| 3402 | |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 3403 | StrictMock<mock::CompositionEngine> mCompositionEngine; |
| 3404 | StrictMock<renderengine::mock::RenderEngine> mRenderEngine; |
Alec Mouri | e4034bb | 2019-11-19 12:45:54 -0800 | [diff] [blame] | 3405 | // TODO: make this is a proper mock. |
| 3406 | std::shared_ptr<TimeStats> mTimeStats = std::make_shared<android::impl::TimeStats>(); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 3407 | mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>(); |
| 3408 | mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>(); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 3409 | StrictMock<OutputPartialMock> mOutput; |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 3410 | std::shared_ptr<renderengine::ExternalTexture> mOutputBuffer = std::make_shared< |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 3411 | renderengine::impl:: |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 3412 | ExternalTexture>(sp<GraphicBuffer>::make(), mRenderEngine, |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 3413 | renderengine::impl::ExternalTexture::Usage::READABLE | |
| 3414 | renderengine::impl::ExternalTexture::Usage::WRITEABLE); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3415 | |
| 3416 | std::optional<base::unique_fd> mReadyFence; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 3417 | }; |
| 3418 | |
| 3419 | const Rect OutputComposeSurfacesTest::kDefaultOutputFrame{1001, 1002, 1003, 1004}; |
| 3420 | const Rect OutputComposeSurfacesTest::kDefaultOutputViewport{1005, 1006, 1007, 1008}; |
Lloyd Pique | e8fe474 | 2020-01-21 15:26:18 -0800 | [diff] [blame] | 3421 | const Rect OutputComposeSurfacesTest::kDefaultOutputDestinationClip{1013, 1014, 1015, 1016}; |
Lloyd Pique | 0a45623 | 2020-01-16 17:51:13 -0800 | [diff] [blame] | 3422 | const mat4 OutputComposeSurfacesTest::kDefaultColorTransformMat{mat4() * 0.5f}; |
Lucas Dupin | 2dd6f39 | 2020-02-18 17:43:36 -0800 | [diff] [blame] | 3423 | const compositionengine::CompositionRefreshArgs OutputComposeSurfacesTest::kDefaultRefreshArgs; |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3424 | const Region OutputComposeSurfacesTest::kDebugRegion{Rect{100, 101, 102, 103}}; |
Alec Mouri | b21d94e | 2022-01-13 17:44:10 -0800 | [diff] [blame] | 3425 | |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3426 | const HdrCapabilities OutputComposeSurfacesTest:: |
| 3427 | kHdrCapabilities{{}, |
| 3428 | OutputComposeSurfacesTest::kDefaultMaxLuminance, |
| 3429 | OutputComposeSurfacesTest::kDefaultAvgLuminance, |
| 3430 | OutputComposeSurfacesTest::kDefaultMinLuminance}; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 3431 | |
Lloyd Pique | a76ce46 | 2020-01-14 13:06:37 -0800 | [diff] [blame] | 3432 | TEST_F(OutputComposeSurfacesTest, doesNothingButSignalNoExpensiveRenderingIfNoClientComposition) { |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3433 | mOutput.mState.usesClientComposition = false; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 3434 | |
Lloyd Pique | e9eff97 | 2020-05-05 12:36:44 -0700 | [diff] [blame] | 3435 | EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false)); |
Peiyong Lin | 09f910f | 2020-09-25 10:54:13 -0700 | [diff] [blame] | 3436 | EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false)); |
Lloyd Pique | e9eff97 | 2020-05-05 12:36:44 -0700 | [diff] [blame] | 3437 | |
Lloyd Pique | a76ce46 | 2020-01-14 13:06:37 -0800 | [diff] [blame] | 3438 | EXPECT_CALL(mOutput, setExpensiveRenderingExpected(false)); |
| 3439 | |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3440 | verify().execute().expectAFenceWasReturned(); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 3441 | } |
| 3442 | |
Lloyd Pique | e9eff97 | 2020-05-05 12:36:44 -0700 | [diff] [blame] | 3443 | TEST_F(OutputComposeSurfacesTest, |
| 3444 | dequeuesABufferIfNoClientCompositionButFlipClientTargetRequested) { |
| 3445 | mOutput.mState.usesClientComposition = false; |
| 3446 | mOutput.mState.flipClientTarget = true; |
| 3447 | |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3448 | EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false)); |
Peiyong Lin | 09f910f | 2020-09-25 10:54:13 -0700 | [diff] [blame] | 3449 | EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false)); |
Lloyd Pique | e9eff97 | 2020-05-05 12:36:44 -0700 | [diff] [blame] | 3450 | |
| 3451 | EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillOnce(Return(mOutputBuffer)); |
| 3452 | EXPECT_CALL(mOutput, setExpensiveRenderingExpected(false)); |
| 3453 | |
| 3454 | verify().execute().expectAFenceWasReturned(); |
| 3455 | } |
| 3456 | |
| 3457 | TEST_F(OutputComposeSurfacesTest, doesMinimalWorkIfDequeueBufferFailsForClientComposition) { |
| 3458 | EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false)); |
Peiyong Lin | 09f910f | 2020-09-25 10:54:13 -0700 | [diff] [blame] | 3459 | EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false)); |
Lloyd Pique | e9eff97 | 2020-05-05 12:36:44 -0700 | [diff] [blame] | 3460 | |
| 3461 | EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillOnce(Return(nullptr)); |
| 3462 | |
| 3463 | verify().execute().expectNoFenceWasReturned(); |
| 3464 | } |
| 3465 | |
| 3466 | TEST_F(OutputComposeSurfacesTest, |
| 3467 | doesMinimalWorkIfDequeueBufferFailsForNoClientCompositionButFlipClientTargetRequested) { |
| 3468 | mOutput.mState.usesClientComposition = false; |
| 3469 | mOutput.mState.flipClientTarget = true; |
| 3470 | |
| 3471 | EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false)); |
Peiyong Lin | 09f910f | 2020-09-25 10:54:13 -0700 | [diff] [blame] | 3472 | EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false)); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 3473 | |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3474 | EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillOnce(Return(nullptr)); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 3475 | |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3476 | verify().execute().expectNoFenceWasReturned(); |
| 3477 | } |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 3478 | |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3479 | TEST_F(OutputComposeSurfacesTest, handlesZeroCompositionRequests) { |
| 3480 | EXPECT_CALL(mOutput, getSkipColorTransform()).WillRepeatedly(Return(false)); |
| 3481 | EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillRepeatedly(Return(true)); |
| 3482 | EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false)); |
Peiyong Lin | 09f910f | 2020-09-25 10:54:13 -0700 | [diff] [blame] | 3483 | EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false)); |
Robert Carr | ccab424 | 2021-09-28 16:53:03 -0700 | [diff] [blame] | 3484 | EXPECT_CALL(mOutput, generateClientCompositionRequests(_, kDefaultOutputDataspace, _)) |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 3485 | .WillRepeatedly(Return(std::vector<LayerFE::LayerSettings>{})); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3486 | EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _)) |
| 3487 | .WillRepeatedly(Return()); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 3488 | |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3489 | EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer)); |
Sally Qi | 4cabdd0 | 2021-08-05 16:45:57 -0700 | [diff] [blame] | 3490 | EXPECT_CALL(mRenderEngine, drawLayers(_, IsEmpty(), _, false, _)) |
| 3491 | .WillRepeatedly([&](const renderengine::DisplaySettings&, |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 3492 | const std::vector<renderengine::LayerSettings>&, |
Sally Qi | 4cabdd0 | 2021-08-05 16:45:57 -0700 | [diff] [blame] | 3493 | const std::shared_ptr<renderengine::ExternalTexture>&, const bool, |
Patrick Williams | 2e9748f | 2022-08-09 22:48:18 +0000 | [diff] [blame] | 3494 | base::unique_fd&&) -> ftl::Future<FenceResult> { |
| 3495 | return ftl::yield<FenceResult>(Fence::NO_FENCE); |
Sally Qi | 4cabdd0 | 2021-08-05 16:45:57 -0700 | [diff] [blame] | 3496 | }); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3497 | verify().execute().expectAFenceWasReturned(); |
| 3498 | } |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 3499 | |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3500 | TEST_F(OutputComposeSurfacesTest, buildsAndRendersRequestList) { |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 3501 | LayerFE::LayerSettings r1; |
| 3502 | LayerFE::LayerSettings r2; |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3503 | |
| 3504 | r1.geometry.boundaries = FloatRect{1, 2, 3, 4}; |
| 3505 | r2.geometry.boundaries = FloatRect{5, 6, 7, 8}; |
| 3506 | |
| 3507 | EXPECT_CALL(mOutput, getSkipColorTransform()).WillRepeatedly(Return(false)); |
| 3508 | EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillRepeatedly(Return(true)); |
| 3509 | EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false)); |
Peiyong Lin | 09f910f | 2020-09-25 10:54:13 -0700 | [diff] [blame] | 3510 | EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false)); |
Robert Carr | ccab424 | 2021-09-28 16:53:03 -0700 | [diff] [blame] | 3511 | EXPECT_CALL(mOutput, generateClientCompositionRequests(_, kDefaultOutputDataspace, _)) |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 3512 | .WillRepeatedly(Return(std::vector<LayerFE::LayerSettings>{r1})); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3513 | EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _)) |
| 3514 | .WillRepeatedly( |
| 3515 | Invoke([&](const Region&, |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 3516 | std::vector<LayerFE::LayerSettings>& clientCompositionLayers) { |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3517 | clientCompositionLayers.emplace_back(r2); |
| 3518 | })); |
| 3519 | |
| 3520 | EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer)); |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 3521 | EXPECT_CALL(mRenderEngine, drawLayers(_, ElementsAre(r1, r2), _, false, _)) |
Sally Qi | 4cabdd0 | 2021-08-05 16:45:57 -0700 | [diff] [blame] | 3522 | .WillRepeatedly([&](const renderengine::DisplaySettings&, |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 3523 | const std::vector<renderengine::LayerSettings>&, |
Sally Qi | 4cabdd0 | 2021-08-05 16:45:57 -0700 | [diff] [blame] | 3524 | const std::shared_ptr<renderengine::ExternalTexture>&, const bool, |
Patrick Williams | 2e9748f | 2022-08-09 22:48:18 +0000 | [diff] [blame] | 3525 | base::unique_fd&&) -> ftl::Future<FenceResult> { |
| 3526 | return ftl::yield<FenceResult>(Fence::NO_FENCE); |
Sally Qi | 4cabdd0 | 2021-08-05 16:45:57 -0700 | [diff] [blame] | 3527 | }); |
Alec Mouri | 1684c70 | 2021-02-04 12:27:26 -0800 | [diff] [blame] | 3528 | |
| 3529 | verify().execute().expectAFenceWasReturned(); |
| 3530 | } |
| 3531 | |
| 3532 | TEST_F(OutputComposeSurfacesTest, |
| 3533 | buildsAndRendersRequestListAndCachesFramebufferForInternalLayers) { |
| 3534 | LayerFE::LayerSettings r1; |
| 3535 | LayerFE::LayerSettings r2; |
| 3536 | |
| 3537 | r1.geometry.boundaries = FloatRect{1, 2, 3, 4}; |
| 3538 | r2.geometry.boundaries = FloatRect{5, 6, 7, 8}; |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 3539 | mOutput.setLayerFilter({ui::LayerStack{1234u}, true}); |
Alec Mouri | 1684c70 | 2021-02-04 12:27:26 -0800 | [diff] [blame] | 3540 | |
| 3541 | EXPECT_CALL(mOutput, getSkipColorTransform()).WillRepeatedly(Return(false)); |
| 3542 | EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillRepeatedly(Return(true)); |
| 3543 | EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false)); |
| 3544 | EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false)); |
Robert Carr | ccab424 | 2021-09-28 16:53:03 -0700 | [diff] [blame] | 3545 | EXPECT_CALL(mOutput, generateClientCompositionRequests(_, kDefaultOutputDataspace, _)) |
Alec Mouri | 1684c70 | 2021-02-04 12:27:26 -0800 | [diff] [blame] | 3546 | .WillRepeatedly(Return(std::vector<LayerFE::LayerSettings>{r1})); |
| 3547 | EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _)) |
| 3548 | .WillRepeatedly( |
| 3549 | Invoke([&](const Region&, |
| 3550 | std::vector<LayerFE::LayerSettings>& clientCompositionLayers) { |
| 3551 | clientCompositionLayers.emplace_back(r2); |
| 3552 | })); |
| 3553 | |
| 3554 | EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer)); |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 3555 | EXPECT_CALL(mRenderEngine, drawLayers(_, ElementsAre(r1, r2), _, true, _)) |
Sally Qi | 4cabdd0 | 2021-08-05 16:45:57 -0700 | [diff] [blame] | 3556 | .WillRepeatedly([&](const renderengine::DisplaySettings&, |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 3557 | const std::vector<renderengine::LayerSettings>&, |
Sally Qi | 4cabdd0 | 2021-08-05 16:45:57 -0700 | [diff] [blame] | 3558 | const std::shared_ptr<renderengine::ExternalTexture>&, const bool, |
Patrick Williams | 2e9748f | 2022-08-09 22:48:18 +0000 | [diff] [blame] | 3559 | base::unique_fd&&) -> ftl::Future<FenceResult> { |
| 3560 | return ftl::yield<FenceResult>(Fence::NO_FENCE); |
Sally Qi | 4cabdd0 | 2021-08-05 16:45:57 -0700 | [diff] [blame] | 3561 | }); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3562 | |
| 3563 | verify().execute().expectAFenceWasReturned(); |
| 3564 | } |
| 3565 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 3566 | TEST_F(OutputComposeSurfacesTest, renderDuplicateClientCompositionRequestsWithoutCache) { |
| 3567 | mOutput.cacheClientCompositionRequests(0); |
| 3568 | LayerFE::LayerSettings r1; |
| 3569 | LayerFE::LayerSettings r2; |
| 3570 | |
| 3571 | r1.geometry.boundaries = FloatRect{1, 2, 3, 4}; |
| 3572 | r2.geometry.boundaries = FloatRect{5, 6, 7, 8}; |
| 3573 | |
| 3574 | EXPECT_CALL(mOutput, getSkipColorTransform()).WillRepeatedly(Return(false)); |
| 3575 | EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillRepeatedly(Return(true)); |
| 3576 | EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false)); |
Peiyong Lin | 09f910f | 2020-09-25 10:54:13 -0700 | [diff] [blame] | 3577 | EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false)); |
Robert Carr | ccab424 | 2021-09-28 16:53:03 -0700 | [diff] [blame] | 3578 | EXPECT_CALL(mOutput, generateClientCompositionRequests(_, kDefaultOutputDataspace, _)) |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 3579 | .WillRepeatedly(Return(std::vector<LayerFE::LayerSettings>{r1, r2})); |
| 3580 | EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _)) |
| 3581 | .WillRepeatedly(Return()); |
| 3582 | |
| 3583 | EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer)); |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 3584 | EXPECT_CALL(mRenderEngine, drawLayers(_, ElementsAre(r1, r2), _, false, _)) |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 3585 | .Times(2) |
Patrick Williams | 2e9748f | 2022-08-09 22:48:18 +0000 | [diff] [blame] | 3586 | .WillOnce(Return(ByMove(ftl::yield<FenceResult>(Fence::NO_FENCE)))) |
| 3587 | .WillOnce(Return(ByMove(ftl::yield<FenceResult>(Fence::NO_FENCE)))); |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 3588 | |
| 3589 | verify().execute().expectAFenceWasReturned(); |
| 3590 | EXPECT_FALSE(mOutput.mState.reusedClientComposition); |
| 3591 | |
| 3592 | verify().execute().expectAFenceWasReturned(); |
| 3593 | EXPECT_FALSE(mOutput.mState.reusedClientComposition); |
| 3594 | } |
| 3595 | |
| 3596 | TEST_F(OutputComposeSurfacesTest, skipDuplicateClientCompositionRequests) { |
| 3597 | mOutput.cacheClientCompositionRequests(3); |
| 3598 | LayerFE::LayerSettings r1; |
| 3599 | LayerFE::LayerSettings r2; |
| 3600 | |
| 3601 | r1.geometry.boundaries = FloatRect{1, 2, 3, 4}; |
| 3602 | r2.geometry.boundaries = FloatRect{5, 6, 7, 8}; |
| 3603 | |
| 3604 | EXPECT_CALL(mOutput, getSkipColorTransform()).WillRepeatedly(Return(false)); |
| 3605 | EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillRepeatedly(Return(true)); |
| 3606 | EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false)); |
Peiyong Lin | 09f910f | 2020-09-25 10:54:13 -0700 | [diff] [blame] | 3607 | EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false)); |
Robert Carr | ccab424 | 2021-09-28 16:53:03 -0700 | [diff] [blame] | 3608 | EXPECT_CALL(mOutput, generateClientCompositionRequests(_, kDefaultOutputDataspace, _)) |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 3609 | .WillRepeatedly(Return(std::vector<LayerFE::LayerSettings>{r1, r2})); |
| 3610 | EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _)) |
| 3611 | .WillRepeatedly(Return()); |
| 3612 | |
| 3613 | EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer)); |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 3614 | EXPECT_CALL(mRenderEngine, drawLayers(_, ElementsAre(r1, r2), _, false, _)) |
Patrick Williams | 2e9748f | 2022-08-09 22:48:18 +0000 | [diff] [blame] | 3615 | .WillOnce(Return(ByMove(ftl::yield<FenceResult>(Fence::NO_FENCE)))); |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 3616 | EXPECT_CALL(mOutput, setExpensiveRenderingExpected(false)); |
| 3617 | |
| 3618 | verify().execute().expectAFenceWasReturned(); |
| 3619 | EXPECT_FALSE(mOutput.mState.reusedClientComposition); |
| 3620 | |
| 3621 | // We do not expect another call to draw layers. |
| 3622 | verify().execute().expectAFenceWasReturned(); |
| 3623 | EXPECT_TRUE(mOutput.mState.reusedClientComposition); |
| 3624 | } |
| 3625 | |
| 3626 | TEST_F(OutputComposeSurfacesTest, clientCompositionIfBufferChanges) { |
| 3627 | LayerFE::LayerSettings r1; |
| 3628 | LayerFE::LayerSettings r2; |
| 3629 | |
| 3630 | r1.geometry.boundaries = FloatRect{1, 2, 3, 4}; |
| 3631 | r2.geometry.boundaries = FloatRect{5, 6, 7, 8}; |
| 3632 | |
| 3633 | EXPECT_CALL(mOutput, getSkipColorTransform()).WillRepeatedly(Return(false)); |
| 3634 | EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillRepeatedly(Return(true)); |
| 3635 | EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false)); |
Peiyong Lin | 09f910f | 2020-09-25 10:54:13 -0700 | [diff] [blame] | 3636 | EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false)); |
Robert Carr | ccab424 | 2021-09-28 16:53:03 -0700 | [diff] [blame] | 3637 | EXPECT_CALL(mOutput, generateClientCompositionRequests(_, kDefaultOutputDataspace, _)) |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 3638 | .WillRepeatedly(Return(std::vector<LayerFE::LayerSettings>{r1, r2})); |
| 3639 | EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _)) |
| 3640 | .WillRepeatedly(Return()); |
| 3641 | |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 3642 | const auto otherOutputBuffer = std::make_shared< |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 3643 | renderengine::impl:: |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 3644 | ExternalTexture>(sp<GraphicBuffer>::make(), mRenderEngine, |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 3645 | renderengine::impl::ExternalTexture::Usage::READABLE | |
| 3646 | renderengine::impl::ExternalTexture::Usage::WRITEABLE); |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 3647 | EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)) |
| 3648 | .WillOnce(Return(mOutputBuffer)) |
| 3649 | .WillOnce(Return(otherOutputBuffer)); |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 3650 | EXPECT_CALL(mRenderEngine, drawLayers(_, ElementsAre(r1, r2), _, false, _)) |
Sally Qi | 4cabdd0 | 2021-08-05 16:45:57 -0700 | [diff] [blame] | 3651 | .WillRepeatedly([&](const renderengine::DisplaySettings&, |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 3652 | const std::vector<renderengine::LayerSettings>&, |
Sally Qi | 4cabdd0 | 2021-08-05 16:45:57 -0700 | [diff] [blame] | 3653 | const std::shared_ptr<renderengine::ExternalTexture>&, const bool, |
Patrick Williams | 2e9748f | 2022-08-09 22:48:18 +0000 | [diff] [blame] | 3654 | base::unique_fd&&) -> ftl::Future<FenceResult> { |
| 3655 | return ftl::yield<FenceResult>(Fence::NO_FENCE); |
Sally Qi | 4cabdd0 | 2021-08-05 16:45:57 -0700 | [diff] [blame] | 3656 | }); |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 3657 | |
| 3658 | verify().execute().expectAFenceWasReturned(); |
| 3659 | EXPECT_FALSE(mOutput.mState.reusedClientComposition); |
| 3660 | |
| 3661 | verify().execute().expectAFenceWasReturned(); |
| 3662 | EXPECT_FALSE(mOutput.mState.reusedClientComposition); |
| 3663 | } |
| 3664 | |
| 3665 | TEST_F(OutputComposeSurfacesTest, clientCompositionIfRequestChanges) { |
| 3666 | LayerFE::LayerSettings r1; |
| 3667 | LayerFE::LayerSettings r2; |
| 3668 | LayerFE::LayerSettings r3; |
| 3669 | |
| 3670 | r1.geometry.boundaries = FloatRect{1, 2, 3, 4}; |
| 3671 | r2.geometry.boundaries = FloatRect{5, 6, 7, 8}; |
| 3672 | r3.geometry.boundaries = FloatRect{5, 6, 7, 9}; |
| 3673 | |
| 3674 | EXPECT_CALL(mOutput, getSkipColorTransform()).WillRepeatedly(Return(false)); |
| 3675 | EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillRepeatedly(Return(true)); |
| 3676 | EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false)); |
Peiyong Lin | 09f910f | 2020-09-25 10:54:13 -0700 | [diff] [blame] | 3677 | EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false)); |
Robert Carr | ccab424 | 2021-09-28 16:53:03 -0700 | [diff] [blame] | 3678 | EXPECT_CALL(mOutput, generateClientCompositionRequests(_, kDefaultOutputDataspace, _)) |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 3679 | .WillOnce(Return(std::vector<LayerFE::LayerSettings>{r1, r2})) |
| 3680 | .WillOnce(Return(std::vector<LayerFE::LayerSettings>{r1, r3})); |
| 3681 | EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _)) |
| 3682 | .WillRepeatedly(Return()); |
| 3683 | |
| 3684 | EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer)); |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 3685 | EXPECT_CALL(mRenderEngine, drawLayers(_, ElementsAre(r1, r2), _, false, _)) |
Patrick Williams | 2e9748f | 2022-08-09 22:48:18 +0000 | [diff] [blame] | 3686 | .WillOnce(Return(ByMove(ftl::yield<FenceResult>(Fence::NO_FENCE)))); |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 3687 | EXPECT_CALL(mRenderEngine, drawLayers(_, ElementsAre(r1, r3), _, false, _)) |
Patrick Williams | 2e9748f | 2022-08-09 22:48:18 +0000 | [diff] [blame] | 3688 | .WillOnce(Return(ByMove(ftl::yield<FenceResult>(Fence::NO_FENCE)))); |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 3689 | |
| 3690 | verify().execute().expectAFenceWasReturned(); |
| 3691 | EXPECT_FALSE(mOutput.mState.reusedClientComposition); |
| 3692 | |
| 3693 | verify().execute().expectAFenceWasReturned(); |
| 3694 | EXPECT_FALSE(mOutput.mState.reusedClientComposition); |
| 3695 | } |
| 3696 | |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3697 | struct OutputComposeSurfacesTest_UsesExpectedDisplaySettings : public OutputComposeSurfacesTest { |
| 3698 | OutputComposeSurfacesTest_UsesExpectedDisplaySettings() { |
| 3699 | EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false)); |
Peiyong Lin | 09f910f | 2020-09-25 10:54:13 -0700 | [diff] [blame] | 3700 | EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false)); |
Robert Carr | ccab424 | 2021-09-28 16:53:03 -0700 | [diff] [blame] | 3701 | EXPECT_CALL(mOutput, generateClientCompositionRequests(_, kDefaultOutputDataspace, _)) |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 3702 | .WillRepeatedly(Return(std::vector<LayerFE::LayerSettings>{})); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3703 | EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _)) |
| 3704 | .WillRepeatedly(Return()); |
| 3705 | EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer)); |
| 3706 | } |
| 3707 | |
| 3708 | struct MixedCompositionState |
| 3709 | : public CallOrderStateMachineHelper<TestType, MixedCompositionState> { |
| 3710 | auto ifMixedCompositionIs(bool used) { |
| 3711 | getInstance()->mOutput.mState.usesDeviceComposition = used; |
| 3712 | return nextState<OutputUsesHdrState>(); |
| 3713 | } |
| 3714 | }; |
| 3715 | |
| 3716 | struct OutputUsesHdrState : public CallOrderStateMachineHelper<TestType, OutputUsesHdrState> { |
| 3717 | auto andIfUsesHdr(bool used) { |
| 3718 | EXPECT_CALL(*getInstance()->mDisplayColorProfile, hasWideColorGamut()) |
| 3719 | .WillOnce(Return(used)); |
Alec Mouri | b21d94e | 2022-01-13 17:44:10 -0800 | [diff] [blame] | 3720 | return nextState<OutputWithDisplayBrightnessNits>(); |
| 3721 | } |
| 3722 | }; |
| 3723 | |
| 3724 | struct OutputWithDisplayBrightnessNits |
| 3725 | : public CallOrderStateMachineHelper<TestType, OutputWithDisplayBrightnessNits> { |
| 3726 | auto withDisplayBrightnessNits(float nits) { |
| 3727 | getInstance()->mOutput.mState.displayBrightnessNits = nits; |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 3728 | return nextState<OutputWithDimmingStage>(); |
| 3729 | } |
| 3730 | }; |
| 3731 | |
| 3732 | struct OutputWithDimmingStage |
| 3733 | : public CallOrderStateMachineHelper<TestType, OutputWithDimmingStage> { |
| 3734 | auto withDimmingStage( |
| 3735 | aidl::android::hardware::graphics::composer3::DimmingStage dimmingStage) { |
| 3736 | getInstance()->mOutput.mState.clientTargetDimmingStage = dimmingStage; |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 3737 | return nextState<OutputWithRenderIntent>(); |
| 3738 | } |
| 3739 | }; |
| 3740 | |
| 3741 | struct OutputWithRenderIntent |
| 3742 | : public CallOrderStateMachineHelper<TestType, OutputWithRenderIntent> { |
| 3743 | auto withRenderIntent( |
| 3744 | aidl::android::hardware::graphics::composer3::RenderIntent renderIntent) { |
| 3745 | getInstance()->mOutput.mState.renderIntent = |
| 3746 | static_cast<ui::RenderIntent>(renderIntent); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3747 | return nextState<SkipColorTransformState>(); |
| 3748 | } |
| 3749 | }; |
| 3750 | |
| 3751 | struct SkipColorTransformState |
| 3752 | : public CallOrderStateMachineHelper<TestType, SkipColorTransformState> { |
| 3753 | auto andIfSkipColorTransform(bool skip) { |
| 3754 | // May be called zero or one times. |
| 3755 | EXPECT_CALL(getInstance()->mOutput, getSkipColorTransform()) |
| 3756 | .WillRepeatedly(Return(skip)); |
| 3757 | return nextState<ExpectDisplaySettingsState>(); |
| 3758 | } |
| 3759 | }; |
| 3760 | |
| 3761 | struct ExpectDisplaySettingsState |
| 3762 | : public CallOrderStateMachineHelper<TestType, ExpectDisplaySettingsState> { |
| 3763 | auto thenExpectDisplaySettingsUsed(renderengine::DisplaySettings settings) { |
Sally Qi | 4cabdd0 | 2021-08-05 16:45:57 -0700 | [diff] [blame] | 3764 | EXPECT_CALL(getInstance()->mRenderEngine, drawLayers(settings, _, _, false, _)) |
Patrick Williams | 2e9748f | 2022-08-09 22:48:18 +0000 | [diff] [blame] | 3765 | .WillOnce(Return(ByMove(ftl::yield<FenceResult>(Fence::NO_FENCE)))); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3766 | return nextState<ExecuteState>(); |
| 3767 | } |
| 3768 | }; |
| 3769 | |
| 3770 | // Call this member function to start using the mini-DSL defined above. |
| 3771 | [[nodiscard]] auto verify() { return MixedCompositionState::make(this); } |
| 3772 | }; |
| 3773 | |
| 3774 | TEST_F(OutputComposeSurfacesTest_UsesExpectedDisplaySettings, forHdrMixedComposition) { |
| 3775 | verify().ifMixedCompositionIs(true) |
| 3776 | .andIfUsesHdr(true) |
Leon Scroggins III | f6280bb | 2022-05-04 13:20:32 -0400 | [diff] [blame] | 3777 | .withDisplayBrightnessNits(kDisplayLuminance) |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 3778 | .withDimmingStage(aidl::android::hardware::graphics::composer3::DimmingStage::LINEAR) |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 3779 | .withRenderIntent( |
| 3780 | aidl::android::hardware::graphics::composer3::RenderIntent::COLORIMETRIC) |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3781 | .andIfSkipColorTransform(false) |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 3782 | .thenExpectDisplaySettingsUsed( |
| 3783 | {.physicalDisplay = kDefaultOutputDestinationClip, |
| 3784 | .clip = kDefaultOutputViewport, |
| 3785 | .maxLuminance = kDefaultMaxLuminance, |
Leon Scroggins III | f6280bb | 2022-05-04 13:20:32 -0400 | [diff] [blame] | 3786 | .currentLuminanceNits = kDisplayLuminance, |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 3787 | .outputDataspace = kDefaultOutputDataspace, |
| 3788 | .colorTransform = kDefaultColorTransformMat, |
| 3789 | .deviceHandlesColorTransform = true, |
| 3790 | .orientation = kDefaultOutputOrientationFlags, |
| 3791 | .targetLuminanceNits = kClientTargetLuminanceNits, |
| 3792 | .dimmingStage = |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 3793 | aidl::android::hardware::graphics::composer3::DimmingStage::LINEAR, |
| 3794 | .renderIntent = aidl::android::hardware::graphics::composer3::RenderIntent:: |
| 3795 | COLORIMETRIC}) |
Alec Mouri | b21d94e | 2022-01-13 17:44:10 -0800 | [diff] [blame] | 3796 | .execute() |
| 3797 | .expectAFenceWasReturned(); |
| 3798 | } |
| 3799 | |
| 3800 | TEST_F(OutputComposeSurfacesTest_UsesExpectedDisplaySettings, |
| 3801 | forHdrMixedCompositionWithDisplayBrightness) { |
| 3802 | verify().ifMixedCompositionIs(true) |
| 3803 | .andIfUsesHdr(true) |
| 3804 | .withDisplayBrightnessNits(kDisplayLuminance) |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 3805 | .withDimmingStage(aidl::android::hardware::graphics::composer3::DimmingStage::LINEAR) |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 3806 | .withRenderIntent( |
| 3807 | aidl::android::hardware::graphics::composer3::RenderIntent::COLORIMETRIC) |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 3808 | .andIfSkipColorTransform(false) |
| 3809 | .thenExpectDisplaySettingsUsed( |
| 3810 | {.physicalDisplay = kDefaultOutputDestinationClip, |
| 3811 | .clip = kDefaultOutputViewport, |
| 3812 | .maxLuminance = kDefaultMaxLuminance, |
| 3813 | .currentLuminanceNits = kDisplayLuminance, |
| 3814 | .outputDataspace = kDefaultOutputDataspace, |
| 3815 | .colorTransform = kDefaultColorTransformMat, |
| 3816 | .deviceHandlesColorTransform = true, |
| 3817 | .orientation = kDefaultOutputOrientationFlags, |
| 3818 | .targetLuminanceNits = kClientTargetLuminanceNits, |
| 3819 | .dimmingStage = |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 3820 | aidl::android::hardware::graphics::composer3::DimmingStage::LINEAR, |
| 3821 | .renderIntent = aidl::android::hardware::graphics::composer3::RenderIntent:: |
| 3822 | COLORIMETRIC}) |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 3823 | .execute() |
| 3824 | .expectAFenceWasReturned(); |
| 3825 | } |
| 3826 | |
| 3827 | TEST_F(OutputComposeSurfacesTest_UsesExpectedDisplaySettings, |
| 3828 | forHdrMixedCompositionWithDimmingStage) { |
| 3829 | verify().ifMixedCompositionIs(true) |
| 3830 | .andIfUsesHdr(true) |
Leon Scroggins III | f6280bb | 2022-05-04 13:20:32 -0400 | [diff] [blame] | 3831 | .withDisplayBrightnessNits(kDisplayLuminance) |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 3832 | .withDimmingStage( |
| 3833 | aidl::android::hardware::graphics::composer3::DimmingStage::GAMMA_OETF) |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 3834 | .withRenderIntent( |
| 3835 | aidl::android::hardware::graphics::composer3::RenderIntent::COLORIMETRIC) |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3836 | .andIfSkipColorTransform(false) |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 3837 | .thenExpectDisplaySettingsUsed( |
| 3838 | {.physicalDisplay = kDefaultOutputDestinationClip, |
| 3839 | .clip = kDefaultOutputViewport, |
| 3840 | .maxLuminance = kDefaultMaxLuminance, |
Leon Scroggins III | f6280bb | 2022-05-04 13:20:32 -0400 | [diff] [blame] | 3841 | .currentLuminanceNits = kDisplayLuminance, |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 3842 | .outputDataspace = kDefaultOutputDataspace, |
| 3843 | .colorTransform = kDefaultColorTransformMat, |
| 3844 | .deviceHandlesColorTransform = true, |
| 3845 | .orientation = kDefaultOutputOrientationFlags, |
| 3846 | .targetLuminanceNits = kClientTargetLuminanceNits, |
| 3847 | .dimmingStage = |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 3848 | aidl::android::hardware::graphics::composer3::DimmingStage::GAMMA_OETF, |
| 3849 | .renderIntent = aidl::android::hardware::graphics::composer3::RenderIntent:: |
| 3850 | COLORIMETRIC}) |
| 3851 | .execute() |
| 3852 | .expectAFenceWasReturned(); |
| 3853 | } |
| 3854 | |
| 3855 | TEST_F(OutputComposeSurfacesTest_UsesExpectedDisplaySettings, |
| 3856 | forHdrMixedCompositionWithRenderIntent) { |
| 3857 | verify().ifMixedCompositionIs(true) |
| 3858 | .andIfUsesHdr(true) |
Leon Scroggins III | f6280bb | 2022-05-04 13:20:32 -0400 | [diff] [blame] | 3859 | .withDisplayBrightnessNits(kDisplayLuminance) |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 3860 | .withDimmingStage(aidl::android::hardware::graphics::composer3::DimmingStage::LINEAR) |
| 3861 | .withRenderIntent(aidl::android::hardware::graphics::composer3::RenderIntent::ENHANCE) |
| 3862 | .andIfSkipColorTransform(false) |
| 3863 | .thenExpectDisplaySettingsUsed( |
| 3864 | {.physicalDisplay = kDefaultOutputDestinationClip, |
| 3865 | .clip = kDefaultOutputViewport, |
| 3866 | .maxLuminance = kDefaultMaxLuminance, |
Leon Scroggins III | f6280bb | 2022-05-04 13:20:32 -0400 | [diff] [blame] | 3867 | .currentLuminanceNits = kDisplayLuminance, |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 3868 | .outputDataspace = kDefaultOutputDataspace, |
| 3869 | .colorTransform = kDefaultColorTransformMat, |
| 3870 | .deviceHandlesColorTransform = true, |
| 3871 | .orientation = kDefaultOutputOrientationFlags, |
| 3872 | .targetLuminanceNits = kClientTargetLuminanceNits, |
| 3873 | .dimmingStage = |
| 3874 | aidl::android::hardware::graphics::composer3::DimmingStage::LINEAR, |
| 3875 | .renderIntent = |
| 3876 | aidl::android::hardware::graphics::composer3::RenderIntent::ENHANCE}) |
| 3877 | .execute() |
| 3878 | .expectAFenceWasReturned(); |
| 3879 | } |
| 3880 | |
| 3881 | TEST_F(OutputComposeSurfacesTest_UsesExpectedDisplaySettings, forNonHdrMixedComposition) { |
| 3882 | verify().ifMixedCompositionIs(true) |
| 3883 | .andIfUsesHdr(false) |
Leon Scroggins III | f6280bb | 2022-05-04 13:20:32 -0400 | [diff] [blame] | 3884 | .withDisplayBrightnessNits(kDisplayLuminance) |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 3885 | .withDimmingStage(aidl::android::hardware::graphics::composer3::DimmingStage::LINEAR) |
| 3886 | .withRenderIntent( |
| 3887 | aidl::android::hardware::graphics::composer3::RenderIntent::COLORIMETRIC) |
| 3888 | .andIfSkipColorTransform(false) |
| 3889 | .thenExpectDisplaySettingsUsed( |
| 3890 | {.physicalDisplay = kDefaultOutputDestinationClip, |
| 3891 | .clip = kDefaultOutputViewport, |
| 3892 | .maxLuminance = kDefaultMaxLuminance, |
Leon Scroggins III | f6280bb | 2022-05-04 13:20:32 -0400 | [diff] [blame] | 3893 | .currentLuminanceNits = kDisplayLuminance, |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 3894 | .outputDataspace = kDefaultOutputDataspace, |
| 3895 | .colorTransform = kDefaultColorTransformMat, |
| 3896 | .deviceHandlesColorTransform = true, |
| 3897 | .orientation = kDefaultOutputOrientationFlags, |
| 3898 | .targetLuminanceNits = kClientTargetLuminanceNits, |
| 3899 | .dimmingStage = |
| 3900 | aidl::android::hardware::graphics::composer3::DimmingStage::LINEAR, |
| 3901 | .renderIntent = aidl::android::hardware::graphics::composer3::RenderIntent:: |
| 3902 | COLORIMETRIC}) |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3903 | .execute() |
| 3904 | .expectAFenceWasReturned(); |
| 3905 | } |
| 3906 | |
| 3907 | TEST_F(OutputComposeSurfacesTest_UsesExpectedDisplaySettings, forHdrOnlyClientComposition) { |
| 3908 | verify().ifMixedCompositionIs(false) |
| 3909 | .andIfUsesHdr(true) |
Leon Scroggins III | f6280bb | 2022-05-04 13:20:32 -0400 | [diff] [blame] | 3910 | .withDisplayBrightnessNits(kDisplayLuminance) |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 3911 | .withDimmingStage(aidl::android::hardware::graphics::composer3::DimmingStage::LINEAR) |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 3912 | .withRenderIntent( |
| 3913 | aidl::android::hardware::graphics::composer3::RenderIntent::COLORIMETRIC) |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3914 | .andIfSkipColorTransform(false) |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 3915 | .thenExpectDisplaySettingsUsed( |
| 3916 | {.physicalDisplay = kDefaultOutputDestinationClip, |
| 3917 | .clip = kDefaultOutputViewport, |
| 3918 | .maxLuminance = kDefaultMaxLuminance, |
Leon Scroggins III | f6280bb | 2022-05-04 13:20:32 -0400 | [diff] [blame] | 3919 | .currentLuminanceNits = kDisplayLuminance, |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 3920 | .outputDataspace = kDefaultOutputDataspace, |
| 3921 | .colorTransform = kDefaultColorTransformMat, |
| 3922 | .deviceHandlesColorTransform = false, |
| 3923 | .orientation = kDefaultOutputOrientationFlags, |
| 3924 | .targetLuminanceNits = kClientTargetLuminanceNits, |
| 3925 | .dimmingStage = |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 3926 | aidl::android::hardware::graphics::composer3::DimmingStage::LINEAR, |
| 3927 | .renderIntent = aidl::android::hardware::graphics::composer3::RenderIntent:: |
| 3928 | COLORIMETRIC}) |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3929 | .execute() |
| 3930 | .expectAFenceWasReturned(); |
| 3931 | } |
| 3932 | |
| 3933 | TEST_F(OutputComposeSurfacesTest_UsesExpectedDisplaySettings, forNonHdrOnlyClientComposition) { |
| 3934 | verify().ifMixedCompositionIs(false) |
| 3935 | .andIfUsesHdr(false) |
Leon Scroggins III | f6280bb | 2022-05-04 13:20:32 -0400 | [diff] [blame] | 3936 | .withDisplayBrightnessNits(kDisplayLuminance) |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 3937 | .withDimmingStage(aidl::android::hardware::graphics::composer3::DimmingStage::LINEAR) |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 3938 | .withRenderIntent( |
| 3939 | aidl::android::hardware::graphics::composer3::RenderIntent::COLORIMETRIC) |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3940 | .andIfSkipColorTransform(false) |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 3941 | .thenExpectDisplaySettingsUsed( |
| 3942 | {.physicalDisplay = kDefaultOutputDestinationClip, |
| 3943 | .clip = kDefaultOutputViewport, |
| 3944 | .maxLuminance = kDefaultMaxLuminance, |
Leon Scroggins III | f6280bb | 2022-05-04 13:20:32 -0400 | [diff] [blame] | 3945 | .currentLuminanceNits = kDisplayLuminance, |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 3946 | .outputDataspace = kDefaultOutputDataspace, |
| 3947 | .colorTransform = kDefaultColorTransformMat, |
| 3948 | .deviceHandlesColorTransform = false, |
| 3949 | .orientation = kDefaultOutputOrientationFlags, |
| 3950 | .targetLuminanceNits = kClientTargetLuminanceNits, |
| 3951 | .dimmingStage = |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 3952 | aidl::android::hardware::graphics::composer3::DimmingStage::LINEAR, |
| 3953 | .renderIntent = aidl::android::hardware::graphics::composer3::RenderIntent:: |
| 3954 | COLORIMETRIC}) |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3955 | .execute() |
| 3956 | .expectAFenceWasReturned(); |
| 3957 | } |
| 3958 | |
| 3959 | TEST_F(OutputComposeSurfacesTest_UsesExpectedDisplaySettings, |
| 3960 | usesExpectedDisplaySettingsForHdrOnlyClientCompositionWithSkipClientTransform) { |
| 3961 | verify().ifMixedCompositionIs(false) |
| 3962 | .andIfUsesHdr(true) |
Leon Scroggins III | f6280bb | 2022-05-04 13:20:32 -0400 | [diff] [blame] | 3963 | .withDisplayBrightnessNits(kDisplayLuminance) |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 3964 | .withDimmingStage(aidl::android::hardware::graphics::composer3::DimmingStage::LINEAR) |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 3965 | .withRenderIntent( |
| 3966 | aidl::android::hardware::graphics::composer3::RenderIntent::COLORIMETRIC) |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3967 | .andIfSkipColorTransform(true) |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 3968 | .thenExpectDisplaySettingsUsed( |
| 3969 | {.physicalDisplay = kDefaultOutputDestinationClip, |
| 3970 | .clip = kDefaultOutputViewport, |
| 3971 | .maxLuminance = kDefaultMaxLuminance, |
Leon Scroggins III | f6280bb | 2022-05-04 13:20:32 -0400 | [diff] [blame] | 3972 | .currentLuminanceNits = kDisplayLuminance, |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 3973 | .outputDataspace = kDefaultOutputDataspace, |
| 3974 | .colorTransform = kDefaultColorTransformMat, |
| 3975 | .deviceHandlesColorTransform = true, |
| 3976 | .orientation = kDefaultOutputOrientationFlags, |
| 3977 | .targetLuminanceNits = kClientTargetLuminanceNits, |
| 3978 | .dimmingStage = |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 3979 | aidl::android::hardware::graphics::composer3::DimmingStage::LINEAR, |
| 3980 | .renderIntent = aidl::android::hardware::graphics::composer3::RenderIntent:: |
| 3981 | COLORIMETRIC}) |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3982 | .execute() |
| 3983 | .expectAFenceWasReturned(); |
| 3984 | } |
| 3985 | |
| 3986 | struct OutputComposeSurfacesTest_HandlesProtectedContent : public OutputComposeSurfacesTest { |
| 3987 | struct Layer { |
| 3988 | Layer() { |
Ady Abraham | eca9d75 | 2021-03-03 12:20:00 -0800 | [diff] [blame] | 3989 | EXPECT_CALL(*mLayerFE, getCompositionState()).WillRepeatedly(Return(&mLayerFEState)); |
| 3990 | EXPECT_CALL(mOutputLayer, getLayerFE()).WillRepeatedly(ReturnRef(*mLayerFE)); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3991 | } |
| 3992 | |
| 3993 | StrictMock<mock::OutputLayer> mOutputLayer; |
Ady Abraham | eca9d75 | 2021-03-03 12:20:00 -0800 | [diff] [blame] | 3994 | sp<StrictMock<mock::LayerFE>> mLayerFE = sp<StrictMock<mock::LayerFE>>::make(); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3995 | LayerFECompositionState mLayerFEState; |
| 3996 | }; |
| 3997 | |
| 3998 | OutputComposeSurfacesTest_HandlesProtectedContent() { |
| 3999 | mLayer1.mLayerFEState.hasProtectedContent = false; |
| 4000 | mLayer2.mLayerFEState.hasProtectedContent = false; |
| 4001 | |
| 4002 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(2u)); |
| 4003 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0u)) |
| 4004 | .WillRepeatedly(Return(&mLayer1.mOutputLayer)); |
| 4005 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(1u)) |
| 4006 | .WillRepeatedly(Return(&mLayer2.mOutputLayer)); |
| 4007 | |
| 4008 | EXPECT_CALL(mOutput, getSkipColorTransform()).WillRepeatedly(Return(false)); |
| 4009 | |
| 4010 | EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillRepeatedly(Return(true)); |
| 4011 | |
Robert Carr | ccab424 | 2021-09-28 16:53:03 -0700 | [diff] [blame] | 4012 | EXPECT_CALL(mOutput, generateClientCompositionRequests(_, _, _)) |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 4013 | .WillRepeatedly(Return(std::vector<LayerFE::LayerSettings>{})); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4014 | EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _)) |
| 4015 | .WillRepeatedly(Return()); |
| 4016 | EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer)); |
Sally Qi | 4cabdd0 | 2021-08-05 16:45:57 -0700 | [diff] [blame] | 4017 | EXPECT_CALL(mRenderEngine, drawLayers(_, _, _, false, _)) |
Patrick Williams | 2e9748f | 2022-08-09 22:48:18 +0000 | [diff] [blame] | 4018 | .WillRepeatedly([&](const renderengine::DisplaySettings&, |
| 4019 | const std::vector<renderengine::LayerSettings>&, |
| 4020 | const std::shared_ptr<renderengine::ExternalTexture>&, |
| 4021 | const bool, base::unique_fd&&) -> ftl::Future<FenceResult> { |
| 4022 | return ftl::yield<FenceResult>(Fence::NO_FENCE); |
| 4023 | }); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4024 | } |
| 4025 | |
| 4026 | Layer mLayer1; |
| 4027 | Layer mLayer2; |
| 4028 | }; |
| 4029 | |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4030 | TEST_F(OutputComposeSurfacesTest_HandlesProtectedContent, ifNoProtectedContentLayers) { |
| 4031 | mOutput.mState.isSecure = true; |
| 4032 | mLayer2.mLayerFEState.hasProtectedContent = false; |
| 4033 | EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(true)); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4034 | EXPECT_CALL(*mRenderSurface, isProtected).WillOnce(Return(true)); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4035 | EXPECT_CALL(*mRenderSurface, setProtected(false)); |
| 4036 | |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 4037 | base::unique_fd fd; |
| 4038 | std::shared_ptr<renderengine::ExternalTexture> tex; |
| 4039 | mOutput.updateProtectedContentState(); |
| 4040 | mOutput.dequeueRenderBuffer(&fd, &tex); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 4041 | mOutput.composeSurfaces(kDebugRegion, tex, fd); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4042 | } |
| 4043 | |
| 4044 | TEST_F(OutputComposeSurfacesTest_HandlesProtectedContent, ifNotEnabled) { |
| 4045 | mOutput.mState.isSecure = true; |
| 4046 | mLayer2.mLayerFEState.hasProtectedContent = true; |
| 4047 | EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(true)); |
| 4048 | |
| 4049 | // For this test, we also check the call order of key functions. |
| 4050 | InSequence seq; |
| 4051 | |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4052 | EXPECT_CALL(*mRenderSurface, isProtected).WillOnce(Return(false)); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4053 | EXPECT_CALL(*mRenderSurface, setProtected(true)); |
| 4054 | // Must happen after setting the protected content state. |
| 4055 | EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer)); |
Sally Qi | 4cabdd0 | 2021-08-05 16:45:57 -0700 | [diff] [blame] | 4056 | EXPECT_CALL(mRenderEngine, drawLayers(_, _, _, false, _)) |
Patrick Williams | 2e9748f | 2022-08-09 22:48:18 +0000 | [diff] [blame] | 4057 | .WillOnce(Return(ByMove(ftl::yield<FenceResult>(Fence::NO_FENCE)))); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4058 | |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 4059 | base::unique_fd fd; |
| 4060 | std::shared_ptr<renderengine::ExternalTexture> tex; |
| 4061 | mOutput.updateProtectedContentState(); |
| 4062 | mOutput.dequeueRenderBuffer(&fd, &tex); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 4063 | mOutput.composeSurfaces(kDebugRegion, tex, fd); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4064 | } |
| 4065 | |
| 4066 | TEST_F(OutputComposeSurfacesTest_HandlesProtectedContent, ifAlreadyEnabledEverywhere) { |
| 4067 | mOutput.mState.isSecure = true; |
| 4068 | mLayer2.mLayerFEState.hasProtectedContent = true; |
| 4069 | EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(true)); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4070 | EXPECT_CALL(*mRenderSurface, isProtected).WillOnce(Return(true)); |
| 4071 | |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 4072 | base::unique_fd fd; |
| 4073 | std::shared_ptr<renderengine::ExternalTexture> tex; |
| 4074 | mOutput.updateProtectedContentState(); |
| 4075 | mOutput.dequeueRenderBuffer(&fd, &tex); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 4076 | mOutput.composeSurfaces(kDebugRegion, tex, fd); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4077 | } |
| 4078 | |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4079 | TEST_F(OutputComposeSurfacesTest_HandlesProtectedContent, ifAlreadyEnabledInRenderSurface) { |
| 4080 | mOutput.mState.isSecure = true; |
| 4081 | mLayer2.mLayerFEState.hasProtectedContent = true; |
| 4082 | EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(true)); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4083 | EXPECT_CALL(*mRenderSurface, isProtected).WillOnce(Return(true)); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4084 | |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 4085 | base::unique_fd fd; |
| 4086 | std::shared_ptr<renderengine::ExternalTexture> tex; |
| 4087 | mOutput.updateProtectedContentState(); |
| 4088 | mOutput.dequeueRenderBuffer(&fd, &tex); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 4089 | mOutput.composeSurfaces(kDebugRegion, tex, fd); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4090 | } |
| 4091 | |
| 4092 | struct OutputComposeSurfacesTest_SetsExpensiveRendering : public OutputComposeSurfacesTest { |
| 4093 | OutputComposeSurfacesTest_SetsExpensiveRendering() { |
| 4094 | EXPECT_CALL(mOutput, getSkipColorTransform()).WillRepeatedly(Return(false)); |
| 4095 | EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillRepeatedly(Return(true)); |
| 4096 | EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false)); |
Peiyong Lin | 09f910f | 2020-09-25 10:54:13 -0700 | [diff] [blame] | 4097 | EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false)); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4098 | EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _)) |
| 4099 | .WillRepeatedly(Return()); |
| 4100 | EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer)); |
| 4101 | } |
| 4102 | }; |
| 4103 | |
| 4104 | TEST_F(OutputComposeSurfacesTest_SetsExpensiveRendering, IfExepensiveOutputDataspaceIsUsed) { |
| 4105 | mOutput.mState.dataspace = kExpensiveOutputDataspace; |
| 4106 | |
Leon Scroggins III | 7bdcceb | 2022-03-09 16:53:52 -0500 | [diff] [blame] | 4107 | LayerFE::LayerSettings layerSettings; |
Robert Carr | ccab424 | 2021-09-28 16:53:03 -0700 | [diff] [blame] | 4108 | EXPECT_CALL(mOutput, generateClientCompositionRequests(_, kExpensiveOutputDataspace, _)) |
Leon Scroggins III | 7bdcceb | 2022-03-09 16:53:52 -0500 | [diff] [blame] | 4109 | .WillOnce(Return(std::vector<LayerFE::LayerSettings>{layerSettings})); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4110 | |
| 4111 | // For this test, we also check the call order of key functions. |
| 4112 | InSequence seq; |
| 4113 | |
| 4114 | EXPECT_CALL(mOutput, setExpensiveRenderingExpected(true)); |
Sally Qi | 4cabdd0 | 2021-08-05 16:45:57 -0700 | [diff] [blame] | 4115 | EXPECT_CALL(mRenderEngine, drawLayers(_, _, _, false, _)) |
Patrick Williams | 2e9748f | 2022-08-09 22:48:18 +0000 | [diff] [blame] | 4116 | .WillOnce(Return(ByMove(ftl::yield<FenceResult>(Fence::NO_FENCE)))); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4117 | |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 4118 | base::unique_fd fd; |
| 4119 | std::shared_ptr<renderengine::ExternalTexture> tex; |
| 4120 | mOutput.updateProtectedContentState(); |
| 4121 | mOutput.dequeueRenderBuffer(&fd, &tex); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 4122 | mOutput.composeSurfaces(kDebugRegion, tex, fd); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 4123 | } |
| 4124 | |
| 4125 | /* |
| 4126 | * Output::generateClientCompositionRequests() |
| 4127 | */ |
| 4128 | |
| 4129 | struct GenerateClientCompositionRequestsTest : public testing::Test { |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 4130 | struct OutputPartialMock : public OutputPartialMockBase { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 4131 | // compositionengine::Output overrides |
Robert Carr | ccab424 | 2021-09-28 16:53:03 -0700 | [diff] [blame] | 4132 | std::vector<LayerFE::LayerSettings> generateClientCompositionRequestsHelper( |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 4133 | bool supportsProtectedContent, ui::Dataspace dataspace) { |
Robert Carr | ccab424 | 2021-09-28 16:53:03 -0700 | [diff] [blame] | 4134 | std::vector<LayerFE*> ignore; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 4135 | return impl::Output::generateClientCompositionRequests(supportsProtectedContent, |
Robert Carr | ccab424 | 2021-09-28 16:53:03 -0700 | [diff] [blame] | 4136 | dataspace, ignore); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 4137 | } |
| 4138 | }; |
| 4139 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4140 | struct Layer { |
| 4141 | Layer() { |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 4142 | EXPECT_CALL(mOutputLayer, getOverrideCompositionSettings()) |
| 4143 | .WillRepeatedly(Return(std::nullopt)); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4144 | EXPECT_CALL(mOutputLayer, getState()).WillRepeatedly(ReturnRef(mOutputLayerState)); |
| 4145 | EXPECT_CALL(mOutputLayer, editState()).WillRepeatedly(ReturnRef(mOutputLayerState)); |
Ady Abraham | eca9d75 | 2021-03-03 12:20:00 -0800 | [diff] [blame] | 4146 | EXPECT_CALL(mOutputLayer, getLayerFE()).WillRepeatedly(ReturnRef(*mLayerFE)); |
| 4147 | EXPECT_CALL(*mLayerFE, getCompositionState()).WillRepeatedly(Return(&mLayerFEState)); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4148 | } |
| 4149 | |
| 4150 | StrictMock<mock::OutputLayer> mOutputLayer; |
Ady Abraham | eca9d75 | 2021-03-03 12:20:00 -0800 | [diff] [blame] | 4151 | sp<StrictMock<mock::LayerFE>> mLayerFE = sp<StrictMock<mock::LayerFE>>::make(); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4152 | LayerFECompositionState mLayerFEState; |
| 4153 | impl::OutputLayerCompositionState mOutputLayerState; |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 4154 | LayerFE::LayerSettings mLayerSettings; |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4155 | }; |
| 4156 | |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 4157 | GenerateClientCompositionRequestsTest() { |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4158 | mOutput.mState.needsFiltering = false; |
| 4159 | |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 4160 | mOutput.setDisplayColorProfileForTest( |
| 4161 | std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile)); |
| 4162 | mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface)); |
| 4163 | } |
| 4164 | |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 4165 | static constexpr float kLayerWhitePointNits = 200.f; |
| 4166 | |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 4167 | mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>(); |
| 4168 | mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>(); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 4169 | StrictMock<OutputPartialMock> mOutput; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 4170 | }; |
| 4171 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4172 | struct GenerateClientCompositionRequestsTest_ThreeLayers |
| 4173 | : public GenerateClientCompositionRequestsTest { |
| 4174 | GenerateClientCompositionRequestsTest_ThreeLayers() { |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 4175 | mOutput.mState.orientedDisplaySpace.setContent(kDisplayFrame); |
| 4176 | mOutput.mState.layerStackSpace.setContent(kDisplayViewport); |
| 4177 | mOutput.mState.displaySpace.setContent(kDisplayDestinationClip); |
Marin Shalamanov | 68933fb | 2020-09-10 17:58:12 +0200 | [diff] [blame] | 4178 | mOutput.mState.transform = |
| 4179 | ui::Transform{ui::Transform::toRotationFlags(kDisplayOrientation)}; |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 4180 | mOutput.mState.displaySpace.setOrientation(kDisplayOrientation); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4181 | mOutput.mState.needsFiltering = false; |
| 4182 | mOutput.mState.isSecure = false; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 4183 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4184 | for (size_t i = 0; i < mLayers.size(); i++) { |
| 4185 | mLayers[i].mOutputLayerState.clearClientTarget = false; |
| 4186 | mLayers[i].mOutputLayerState.visibleRegion = Region(kDisplayFrame); |
| 4187 | mLayers[i].mLayerFEState.isOpaque = true; |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 4188 | mLayers[i].mLayerSettings.geometry.boundaries = |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4189 | FloatRect{static_cast<float>(i + 1), 0.f, 0.f, 0.f}; |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 4190 | mLayers[i].mLayerSettings.source.solidColor = {1.0f, 1.0f, 1.0f}; |
| 4191 | mLayers[i].mLayerSettings.alpha = 1.0f; |
| 4192 | mLayers[i].mLayerSettings.disableBlending = false; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 4193 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4194 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(i)) |
| 4195 | .WillRepeatedly(Return(&mLayers[i].mOutputLayer)); |
| 4196 | EXPECT_CALL(mLayers[i].mOutputLayer, requiresClientComposition()) |
| 4197 | .WillRepeatedly(Return(true)); |
| 4198 | EXPECT_CALL(mLayers[i].mOutputLayer, needsFiltering()).WillRepeatedly(Return(false)); |
| 4199 | } |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 4200 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4201 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(mLayers.size())); |
| 4202 | } |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 4203 | |
Marin Shalamanov | 68933fb | 2020-09-10 17:58:12 +0200 | [diff] [blame] | 4204 | static constexpr ui::Rotation kDisplayOrientation = ui::ROTATION_0; |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4205 | static constexpr ui::Dataspace kDisplayDataspace = ui::Dataspace::UNKNOWN; |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 4206 | static constexpr float kLayerWhitePointNits = 200.f; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 4207 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4208 | static const Rect kDisplayFrame; |
| 4209 | static const Rect kDisplayViewport; |
Lloyd Pique | e8fe474 | 2020-01-21 15:26:18 -0800 | [diff] [blame] | 4210 | static const Rect kDisplayDestinationClip; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 4211 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4212 | std::array<Layer, 3> mLayers; |
| 4213 | }; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 4214 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4215 | const Rect GenerateClientCompositionRequestsTest_ThreeLayers::kDisplayFrame(0, 0, 100, 200); |
| 4216 | const Rect GenerateClientCompositionRequestsTest_ThreeLayers::kDisplayViewport(0, 0, 101, 201); |
Lloyd Pique | e8fe474 | 2020-01-21 15:26:18 -0800 | [diff] [blame] | 4217 | const Rect GenerateClientCompositionRequestsTest_ThreeLayers::kDisplayDestinationClip(0, 0, 103, |
| 4218 | 203); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 4219 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4220 | TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers, handlesNoClientCompostionLayers) { |
| 4221 | EXPECT_CALL(mLayers[0].mOutputLayer, requiresClientComposition()).WillOnce(Return(false)); |
| 4222 | EXPECT_CALL(mLayers[1].mOutputLayer, requiresClientComposition()).WillOnce(Return(false)); |
| 4223 | EXPECT_CALL(mLayers[2].mOutputLayer, requiresClientComposition()).WillOnce(Return(false)); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 4224 | |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 4225 | auto requests = |
| 4226 | mOutput.generateClientCompositionRequestsHelper(false /* supportsProtectedContent */, |
| 4227 | kDisplayDataspace); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 4228 | EXPECT_EQ(0u, requests.size()); |
| 4229 | } |
| 4230 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4231 | TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers, requiresVisibleRegionAfterViewportClip) { |
| 4232 | mLayers[0].mOutputLayerState.visibleRegion = Region(Rect(10, 10, 10, 10)); |
| 4233 | mLayers[1].mOutputLayerState.visibleRegion = Region(Rect(4000, 0, 4010, 10)); |
| 4234 | mLayers[2].mOutputLayerState.visibleRegion = Region(Rect(-10, -10, 0, 0)); |
| 4235 | |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 4236 | auto requests = |
| 4237 | mOutput.generateClientCompositionRequestsHelper(false /* supportsProtectedContent */, |
| 4238 | kDisplayDataspace); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4239 | EXPECT_EQ(0u, requests.size()); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4240 | } |
| 4241 | |
| 4242 | TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers, gathersClientCompositionRequests) { |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 4243 | EXPECT_CALL(*mLayers[0].mLayerFE, prepareClientComposition(_)) |
| 4244 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>())); |
| 4245 | EXPECT_CALL(*mLayers[1].mLayerFE, prepareClientComposition(_)) |
| 4246 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>(mLayers[1].mLayerSettings))); |
| 4247 | EXPECT_CALL(*mLayers[2].mLayerFE, prepareClientComposition(_)) |
| 4248 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>(mLayers[2].mLayerSettings))); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4249 | |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 4250 | auto requests = |
| 4251 | mOutput.generateClientCompositionRequestsHelper(false /* supportsProtectedContent */, |
| 4252 | kDisplayDataspace); |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 4253 | ASSERT_EQ(2u, requests.size()); |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 4254 | EXPECT_EQ(mLayers[1].mLayerSettings, requests[0]); |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 4255 | EXPECT_EQ(mLayers[2].mLayerSettings, requests[1]); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4256 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4257 | // Check that a timestamp was set for the layers that generated requests |
| 4258 | EXPECT_TRUE(0 == mLayers[0].mOutputLayerState.clientCompositionTimestamp); |
| 4259 | EXPECT_TRUE(0 != mLayers[1].mOutputLayerState.clientCompositionTimestamp); |
| 4260 | EXPECT_TRUE(0 != mLayers[2].mOutputLayerState.clientCompositionTimestamp); |
| 4261 | } |
| 4262 | |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 4263 | MATCHER_P(ClientCompositionTargetSettingsBlurSettingsEq, expectedBlurSetting, "") { |
| 4264 | *result_listener << "ClientCompositionTargetSettings' BlurSettings aren't equal \n"; |
| 4265 | *result_listener << "expected " << expectedBlurSetting << "\n"; |
| 4266 | *result_listener << "actual " << arg.blurSetting << "\n"; |
| 4267 | |
| 4268 | return expectedBlurSetting == arg.blurSetting; |
| 4269 | } |
| 4270 | |
| 4271 | TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers, overridesBlur) { |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 4272 | mLayers[2].mOutputLayerState.overrideInfo.disableBackgroundBlur = true; |
| 4273 | |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 4274 | EXPECT_CALL(*mLayers[0].mLayerFE, prepareClientComposition(_)) |
| 4275 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>())); |
| 4276 | EXPECT_CALL(*mLayers[1].mLayerFE, prepareClientComposition(_)) |
| 4277 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>(mLayers[1].mLayerSettings))); |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 4278 | EXPECT_CALL(*mLayers[2].mLayerFE, |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 4279 | prepareClientComposition(ClientCompositionTargetSettingsBlurSettingsEq( |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 4280 | LayerFE::ClientCompositionTargetSettings::BlurSetting::BlurRegionsOnly))) |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 4281 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>(mLayers[2].mLayerSettings))); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 4282 | auto requests = |
| 4283 | mOutput.generateClientCompositionRequestsHelper(false /* supportsProtectedContent */, |
| 4284 | kDisplayDataspace); |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 4285 | ASSERT_EQ(2u, requests.size()); |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 4286 | EXPECT_EQ(mLayers[1].mLayerSettings, requests[0]); |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 4287 | EXPECT_EQ(mLayers[2].mLayerSettings, requests[1]); |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 4288 | |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 4289 | // Check that a timestamp was set for the layers that generated requests |
| 4290 | EXPECT_TRUE(0 == mLayers[0].mOutputLayerState.clientCompositionTimestamp); |
| 4291 | EXPECT_TRUE(0 != mLayers[1].mOutputLayerState.clientCompositionTimestamp); |
| 4292 | EXPECT_TRUE(0 != mLayers[2].mOutputLayerState.clientCompositionTimestamp); |
| 4293 | } |
| 4294 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4295 | TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers, |
| 4296 | onlyClientComposesClientComposedLayersIfNoClearingNeeded) { |
| 4297 | EXPECT_CALL(mLayers[0].mOutputLayer, requiresClientComposition()).WillOnce(Return(false)); |
| 4298 | EXPECT_CALL(mLayers[1].mOutputLayer, requiresClientComposition()).WillOnce(Return(false)); |
| 4299 | EXPECT_CALL(mLayers[2].mOutputLayer, requiresClientComposition()).WillOnce(Return(true)); |
| 4300 | |
| 4301 | mLayers[0].mOutputLayerState.clearClientTarget = false; |
| 4302 | mLayers[1].mOutputLayerState.clearClientTarget = false; |
| 4303 | mLayers[2].mOutputLayerState.clearClientTarget = false; |
| 4304 | |
| 4305 | mLayers[0].mLayerFEState.isOpaque = true; |
| 4306 | mLayers[1].mLayerFEState.isOpaque = true; |
| 4307 | mLayers[2].mLayerFEState.isOpaque = true; |
| 4308 | |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 4309 | EXPECT_CALL(*mLayers[2].mLayerFE, prepareClientComposition(_)) |
| 4310 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>(mLayers[2].mLayerSettings))); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4311 | |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 4312 | auto requests = |
| 4313 | mOutput.generateClientCompositionRequestsHelper(false /* supportsProtectedContent */, |
| 4314 | kDisplayDataspace); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4315 | ASSERT_EQ(1u, requests.size()); |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 4316 | EXPECT_EQ(mLayers[2].mLayerSettings, requests[0]); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4317 | } |
| 4318 | |
| 4319 | TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers, |
| 4320 | onlyClientComposesClientComposedLayersIfOthersAreNotOpaque) { |
| 4321 | EXPECT_CALL(mLayers[0].mOutputLayer, requiresClientComposition()).WillOnce(Return(false)); |
| 4322 | EXPECT_CALL(mLayers[1].mOutputLayer, requiresClientComposition()).WillOnce(Return(false)); |
| 4323 | EXPECT_CALL(mLayers[2].mOutputLayer, requiresClientComposition()).WillOnce(Return(true)); |
| 4324 | |
| 4325 | mLayers[0].mOutputLayerState.clearClientTarget = true; |
| 4326 | mLayers[1].mOutputLayerState.clearClientTarget = true; |
| 4327 | mLayers[2].mOutputLayerState.clearClientTarget = true; |
| 4328 | |
| 4329 | mLayers[0].mLayerFEState.isOpaque = false; |
| 4330 | mLayers[1].mLayerFEState.isOpaque = false; |
| 4331 | mLayers[2].mLayerFEState.isOpaque = false; |
| 4332 | |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 4333 | EXPECT_CALL(*mLayers[2].mLayerFE, prepareClientComposition(_)) |
| 4334 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>(mLayers[2].mLayerSettings))); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4335 | |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 4336 | auto requests = |
| 4337 | mOutput.generateClientCompositionRequestsHelper(false /* supportsProtectedContent */, |
| 4338 | kDisplayDataspace); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4339 | ASSERT_EQ(1u, requests.size()); |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 4340 | EXPECT_EQ(mLayers[2].mLayerSettings, requests[0]); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4341 | } |
| 4342 | |
| 4343 | TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers, clearsHWCLayersIfOpaqueAndNotFirst) { |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 4344 | // If client composition is performed with some layers set to use device |
| 4345 | // composition, device layers after the first layer (device or client) will |
| 4346 | // clear the frame buffer if they are opaque and if that layer has a flag |
| 4347 | // set to do so. The first layer is skipped as the frame buffer is already |
| 4348 | // expected to be clear. |
| 4349 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4350 | EXPECT_CALL(mLayers[0].mOutputLayer, requiresClientComposition()).WillOnce(Return(false)); |
| 4351 | EXPECT_CALL(mLayers[1].mOutputLayer, requiresClientComposition()).WillOnce(Return(false)); |
| 4352 | EXPECT_CALL(mLayers[2].mOutputLayer, requiresClientComposition()).WillOnce(Return(true)); |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 4353 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4354 | mLayers[0].mOutputLayerState.clearClientTarget = true; |
| 4355 | mLayers[1].mOutputLayerState.clearClientTarget = true; |
| 4356 | mLayers[2].mOutputLayerState.clearClientTarget = true; |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 4357 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4358 | mLayers[0].mLayerFEState.isOpaque = true; |
| 4359 | mLayers[1].mLayerFEState.isOpaque = true; |
| 4360 | mLayers[2].mLayerFEState.isOpaque = true; |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 4361 | |
| 4362 | compositionengine::LayerFE::ClientCompositionTargetSettings layer1TargetSettings{ |
| 4363 | Region(kDisplayFrame), |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 4364 | false, /* needs filtering */ |
| 4365 | false, /* secure */ |
| 4366 | false, /* supports protected content */ |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 4367 | kDisplayViewport, |
| 4368 | kDisplayDataspace, |
| 4369 | false /* realContentIsVisible */, |
| 4370 | true /* clearContent */, |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 4371 | compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled, |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 4372 | kLayerWhitePointNits, |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 4373 | false /* treat170mAsSrgb */, |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 4374 | }; |
| 4375 | compositionengine::LayerFE::ClientCompositionTargetSettings layer2TargetSettings{ |
| 4376 | Region(kDisplayFrame), |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 4377 | false, /* needs filtering */ |
| 4378 | false, /* secure */ |
| 4379 | false, /* supports protected content */ |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 4380 | kDisplayViewport, |
| 4381 | kDisplayDataspace, |
| 4382 | true /* realContentIsVisible */, |
| 4383 | false /* clearContent */, |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 4384 | compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled, |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 4385 | kLayerWhitePointNits, |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 4386 | false /* treat170mAsSrgb */, |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 4387 | }; |
| 4388 | |
| 4389 | LayerFE::LayerSettings mBlackoutSettings = mLayers[1].mLayerSettings; |
| 4390 | mBlackoutSettings.source.buffer.buffer = nullptr; |
| 4391 | mBlackoutSettings.source.solidColor = {0.1f, 0.1f, 0.1f}; |
| 4392 | mBlackoutSettings.alpha = 0.f; |
| 4393 | mBlackoutSettings.disableBlending = true; |
| 4394 | |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 4395 | EXPECT_CALL(*mLayers[1].mLayerFE, prepareClientComposition(Eq(ByRef(layer1TargetSettings)))) |
| 4396 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>(mBlackoutSettings))); |
| 4397 | EXPECT_CALL(*mLayers[2].mLayerFE, prepareClientComposition(Eq(ByRef(layer2TargetSettings)))) |
| 4398 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>(mLayers[2].mLayerSettings))); |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 4399 | |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 4400 | auto requests = |
| 4401 | mOutput.generateClientCompositionRequestsHelper(false /* supportsProtectedContent */, |
| 4402 | kDisplayDataspace); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4403 | ASSERT_EQ(2u, requests.size()); |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 4404 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4405 | // 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] | 4406 | EXPECT_EQ(mBlackoutSettings, requests[0]); |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 4407 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 4408 | EXPECT_EQ(mLayers[2].mLayerSettings, requests[1]); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4409 | } |
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 | TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers, |
| 4412 | clippedVisibleRegionUsedToGenerateRequest) { |
| 4413 | mLayers[0].mOutputLayerState.visibleRegion = Region(Rect(10, 10, 20, 20)); |
| 4414 | mLayers[1].mOutputLayerState.visibleRegion = Region(Rect(-10, -10, 30, 30)); |
| 4415 | mLayers[2].mOutputLayerState.visibleRegion = Region(Rect(-10, 0, 40, 4000)); |
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 | compositionengine::LayerFE::ClientCompositionTargetSettings layer0TargetSettings{ |
| 4418 | Region(Rect(10, 10, 20, 20)), |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4419 | false, /* needs filtering */ |
| 4420 | false, /* secure */ |
| 4421 | false, /* supports protected content */ |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 4422 | kDisplayViewport, |
| 4423 | kDisplayDataspace, |
| 4424 | true /* realContentIsVisible */, |
| 4425 | false /* clearContent */, |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 4426 | compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled, |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 4427 | kLayerWhitePointNits, |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 4428 | false /* treat170mAsSrgb */, |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4429 | }; |
| 4430 | compositionengine::LayerFE::ClientCompositionTargetSettings layer1TargetSettings{ |
| 4431 | Region(Rect(0, 0, 30, 30)), |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4432 | false, /* needs filtering */ |
| 4433 | false, /* secure */ |
| 4434 | false, /* supports protected content */ |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 4435 | kDisplayViewport, |
| 4436 | kDisplayDataspace, |
| 4437 | true /* realContentIsVisible */, |
| 4438 | false /* clearContent */, |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 4439 | compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled, |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 4440 | kLayerWhitePointNits, |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 4441 | false /* treat170mAsSrgb */, |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4442 | }; |
| 4443 | compositionengine::LayerFE::ClientCompositionTargetSettings layer2TargetSettings{ |
| 4444 | Region(Rect(0, 0, 40, 201)), |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4445 | false, /* needs filtering */ |
| 4446 | false, /* secure */ |
| 4447 | false, /* supports protected content */ |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 4448 | kDisplayViewport, |
| 4449 | kDisplayDataspace, |
| 4450 | true /* realContentIsVisible */, |
| 4451 | false /* clearContent */, |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 4452 | compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled, |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 4453 | kLayerWhitePointNits, |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 4454 | false /* treat170mAsSrgb */, |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4455 | }; |
| 4456 | |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 4457 | EXPECT_CALL(*mLayers[0].mLayerFE, prepareClientComposition(Eq(ByRef(layer0TargetSettings)))) |
| 4458 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>())); |
| 4459 | EXPECT_CALL(*mLayers[1].mLayerFE, prepareClientComposition(Eq(ByRef(layer1TargetSettings)))) |
| 4460 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>())); |
| 4461 | EXPECT_CALL(*mLayers[2].mLayerFE, prepareClientComposition(Eq(ByRef(layer2TargetSettings)))) |
| 4462 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>())); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4463 | |
| 4464 | static_cast<void>( |
Robert Carr | ccab424 | 2021-09-28 16:53:03 -0700 | [diff] [blame] | 4465 | mOutput.generateClientCompositionRequestsHelper(false /* supportsProtectedContent */, |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 4466 | kDisplayDataspace)); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4467 | } |
| 4468 | |
| 4469 | TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers, |
| 4470 | perLayerNeedsFilteringUsedToGenerateRequests) { |
| 4471 | mOutput.mState.needsFiltering = false; |
| 4472 | EXPECT_CALL(mLayers[0].mOutputLayer, needsFiltering()).WillRepeatedly(Return(true)); |
| 4473 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4474 | compositionengine::LayerFE::ClientCompositionTargetSettings layer0TargetSettings{ |
| 4475 | Region(kDisplayFrame), |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4476 | true, /* needs filtering */ |
| 4477 | false, /* secure */ |
| 4478 | false, /* supports protected content */ |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 4479 | kDisplayViewport, |
| 4480 | kDisplayDataspace, |
| 4481 | true /* realContentIsVisible */, |
| 4482 | false /* clearContent */, |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 4483 | compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled, |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 4484 | kLayerWhitePointNits, |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 4485 | false /* treat170mAsSrgb */, |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4486 | }; |
| 4487 | compositionengine::LayerFE::ClientCompositionTargetSettings layer1TargetSettings{ |
| 4488 | Region(kDisplayFrame), |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4489 | false, /* needs filtering */ |
| 4490 | false, /* secure */ |
| 4491 | false, /* supports protected content */ |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 4492 | kDisplayViewport, |
| 4493 | kDisplayDataspace, |
| 4494 | true /* realContentIsVisible */, |
| 4495 | false /* clearContent */, |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 4496 | compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled, |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 4497 | kLayerWhitePointNits, |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 4498 | false /* treat170mAsSrgb */, |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4499 | }; |
| 4500 | compositionengine::LayerFE::ClientCompositionTargetSettings layer2TargetSettings{ |
| 4501 | Region(kDisplayFrame), |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4502 | false, /* needs filtering */ |
| 4503 | false, /* secure */ |
| 4504 | false, /* supports protected content */ |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 4505 | kDisplayViewport, |
| 4506 | kDisplayDataspace, |
| 4507 | true /* realContentIsVisible */, |
| 4508 | false /* clearContent */, |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 4509 | compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled, |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 4510 | kLayerWhitePointNits, |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 4511 | false /* treat170mAsSrgb */, |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4512 | }; |
| 4513 | |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 4514 | EXPECT_CALL(*mLayers[0].mLayerFE, prepareClientComposition(Eq(ByRef(layer0TargetSettings)))) |
| 4515 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>())); |
| 4516 | EXPECT_CALL(*mLayers[1].mLayerFE, prepareClientComposition(Eq(ByRef(layer1TargetSettings)))) |
| 4517 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>())); |
| 4518 | EXPECT_CALL(*mLayers[2].mLayerFE, prepareClientComposition(Eq(ByRef(layer2TargetSettings)))) |
| 4519 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>())); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4520 | |
| 4521 | static_cast<void>( |
Robert Carr | ccab424 | 2021-09-28 16:53:03 -0700 | [diff] [blame] | 4522 | mOutput.generateClientCompositionRequestsHelper(false /* supportsProtectedContent */, |
| 4523 | kDisplayDataspace)); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4524 | } |
| 4525 | |
| 4526 | TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers, |
| 4527 | wholeOutputNeedsFilteringUsedToGenerateRequests) { |
| 4528 | mOutput.mState.needsFiltering = true; |
| 4529 | EXPECT_CALL(mLayers[0].mOutputLayer, needsFiltering()).WillRepeatedly(Return(true)); |
| 4530 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4531 | compositionengine::LayerFE::ClientCompositionTargetSettings layer0TargetSettings{ |
| 4532 | Region(kDisplayFrame), |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4533 | true, /* needs filtering */ |
| 4534 | false, /* secure */ |
| 4535 | false, /* supports protected content */ |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 4536 | kDisplayViewport, |
| 4537 | kDisplayDataspace, |
| 4538 | true /* realContentIsVisible */, |
| 4539 | false /* clearContent */, |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 4540 | compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled, |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 4541 | kLayerWhitePointNits, |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 4542 | false /* treat170mAsSrgb */, |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4543 | }; |
| 4544 | compositionengine::LayerFE::ClientCompositionTargetSettings layer1TargetSettings{ |
| 4545 | Region(kDisplayFrame), |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4546 | true, /* needs filtering */ |
| 4547 | false, /* secure */ |
| 4548 | false, /* supports protected content */ |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 4549 | kDisplayViewport, |
| 4550 | kDisplayDataspace, |
| 4551 | true /* realContentIsVisible */, |
| 4552 | false /* clearContent */, |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 4553 | compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled, |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 4554 | kLayerWhitePointNits, |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 4555 | false /* treat170mAsSrgb */, |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4556 | }; |
| 4557 | compositionengine::LayerFE::ClientCompositionTargetSettings layer2TargetSettings{ |
| 4558 | Region(kDisplayFrame), |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4559 | true, /* needs filtering */ |
| 4560 | false, /* secure */ |
| 4561 | false, /* supports protected content */ |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 4562 | kDisplayViewport, |
| 4563 | kDisplayDataspace, |
| 4564 | true /* realContentIsVisible */, |
| 4565 | false /* clearContent */, |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 4566 | compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled, |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 4567 | kLayerWhitePointNits, |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 4568 | false /* treat170mAsSrgb */, |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4569 | }; |
| 4570 | |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 4571 | EXPECT_CALL(*mLayers[0].mLayerFE, prepareClientComposition(Eq(ByRef(layer0TargetSettings)))) |
| 4572 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>())); |
| 4573 | EXPECT_CALL(*mLayers[1].mLayerFE, prepareClientComposition(Eq(ByRef(layer1TargetSettings)))) |
| 4574 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>())); |
| 4575 | EXPECT_CALL(*mLayers[2].mLayerFE, prepareClientComposition(Eq(ByRef(layer2TargetSettings)))) |
| 4576 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>())); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4577 | |
| 4578 | static_cast<void>( |
Robert Carr | ccab424 | 2021-09-28 16:53:03 -0700 | [diff] [blame] | 4579 | mOutput.generateClientCompositionRequestsHelper(false /* supportsProtectedContent */, |
| 4580 | kDisplayDataspace)); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4581 | } |
| 4582 | |
| 4583 | TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers, |
| 4584 | wholeOutputSecurityUsedToGenerateRequests) { |
| 4585 | mOutput.mState.isSecure = true; |
| 4586 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4587 | compositionengine::LayerFE::ClientCompositionTargetSettings layer0TargetSettings{ |
| 4588 | Region(kDisplayFrame), |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4589 | false, /* needs filtering */ |
| 4590 | true, /* secure */ |
| 4591 | false, /* supports protected content */ |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 4592 | kDisplayViewport, |
| 4593 | kDisplayDataspace, |
| 4594 | true /* realContentIsVisible */, |
| 4595 | false /* clearContent */, |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 4596 | compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled, |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 4597 | kLayerWhitePointNits, |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 4598 | false /* treat170mAsSrgb */, |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4599 | }; |
| 4600 | compositionengine::LayerFE::ClientCompositionTargetSettings layer1TargetSettings{ |
| 4601 | Region(kDisplayFrame), |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4602 | false, /* needs filtering */ |
| 4603 | true, /* secure */ |
| 4604 | false, /* supports protected content */ |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 4605 | kDisplayViewport, |
| 4606 | kDisplayDataspace, |
| 4607 | true /* realContentIsVisible */, |
| 4608 | false /* clearContent */, |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 4609 | compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled, |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 4610 | kLayerWhitePointNits, |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 4611 | false /* treat170mAsSrgb */, |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4612 | }; |
| 4613 | compositionengine::LayerFE::ClientCompositionTargetSettings layer2TargetSettings{ |
| 4614 | Region(kDisplayFrame), |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4615 | false, /* needs filtering */ |
| 4616 | true, /* secure */ |
| 4617 | false, /* supports protected content */ |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 4618 | kDisplayViewport, |
| 4619 | kDisplayDataspace, |
| 4620 | true /* realContentIsVisible */, |
| 4621 | false /* clearContent */, |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 4622 | compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled, |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 4623 | kLayerWhitePointNits, |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 4624 | false /* treat170mAsSrgb */, |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4625 | }; |
| 4626 | |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 4627 | EXPECT_CALL(*mLayers[0].mLayerFE, prepareClientComposition(Eq(ByRef(layer0TargetSettings)))) |
| 4628 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>())); |
| 4629 | EXPECT_CALL(*mLayers[1].mLayerFE, prepareClientComposition(Eq(ByRef(layer1TargetSettings)))) |
| 4630 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>())); |
| 4631 | EXPECT_CALL(*mLayers[2].mLayerFE, prepareClientComposition(Eq(ByRef(layer2TargetSettings)))) |
| 4632 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>())); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4633 | |
| 4634 | static_cast<void>( |
Robert Carr | ccab424 | 2021-09-28 16:53:03 -0700 | [diff] [blame] | 4635 | mOutput.generateClientCompositionRequestsHelper(false /* supportsProtectedContent */, |
| 4636 | kDisplayDataspace)); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4637 | } |
| 4638 | |
| 4639 | TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers, |
| 4640 | protectedContentSupportUsedToGenerateRequests) { |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4641 | compositionengine::LayerFE::ClientCompositionTargetSettings layer0TargetSettings{ |
| 4642 | Region(kDisplayFrame), |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4643 | false, /* needs filtering */ |
| 4644 | false, /* secure */ |
| 4645 | true, /* supports protected content */ |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 4646 | kDisplayViewport, |
| 4647 | kDisplayDataspace, |
| 4648 | true /* realContentIsVisible */, |
| 4649 | false /* clearContent */, |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 4650 | compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled, |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 4651 | kLayerWhitePointNits, |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 4652 | false /* treat170mAsSrgb */, |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4653 | }; |
| 4654 | compositionengine::LayerFE::ClientCompositionTargetSettings layer1TargetSettings{ |
| 4655 | Region(kDisplayFrame), |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4656 | false, /* needs filtering */ |
| 4657 | false, /* secure */ |
| 4658 | true, /* supports protected content */ |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 4659 | kDisplayViewport, |
| 4660 | kDisplayDataspace, |
| 4661 | true /* realContentIsVisible */, |
| 4662 | false /* clearContent */, |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 4663 | compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled, |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 4664 | kLayerWhitePointNits, |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 4665 | false /* treat170mAsSrgb */, |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4666 | }; |
| 4667 | compositionengine::LayerFE::ClientCompositionTargetSettings layer2TargetSettings{ |
| 4668 | Region(kDisplayFrame), |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4669 | false, /* needs filtering */ |
| 4670 | false, /* secure */ |
| 4671 | true, /* supports protected content */ |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 4672 | kDisplayViewport, |
| 4673 | kDisplayDataspace, |
| 4674 | true /* realContentIsVisible */, |
| 4675 | false /* clearContent */, |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 4676 | compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled, |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 4677 | kLayerWhitePointNits, |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 4678 | false /* treat170mAsSrgb */, |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4679 | }; |
| 4680 | |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 4681 | EXPECT_CALL(*mLayers[0].mLayerFE, prepareClientComposition(Eq(ByRef(layer0TargetSettings)))) |
| 4682 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>())); |
| 4683 | EXPECT_CALL(*mLayers[1].mLayerFE, prepareClientComposition(Eq(ByRef(layer1TargetSettings)))) |
| 4684 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>())); |
| 4685 | EXPECT_CALL(*mLayers[2].mLayerFE, prepareClientComposition(Eq(ByRef(layer2TargetSettings)))) |
| 4686 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>())); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4687 | |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 4688 | static_cast<void>( |
| 4689 | mOutput.generateClientCompositionRequestsHelper(true /* supportsProtectedContent */, |
| 4690 | kDisplayDataspace)); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4691 | } |
| 4692 | |
Lucas Dupin | 084a6d4 | 2021-08-26 22:10:29 +0000 | [diff] [blame] | 4693 | TEST_F(OutputUpdateAndWriteCompositionStateTest, noBackgroundBlurWhenOpaque) { |
| 4694 | InjectedLayer layer1; |
| 4695 | InjectedLayer layer2; |
| 4696 | |
| 4697 | uint32_t z = 0; |
| 4698 | // Layer requesting blur, or below, should request client composition, unless opaque. |
| 4699 | EXPECT_CALL(*layer1.outputLayer, updateCompositionState(false, false, ui::Transform::ROT_0)); |
| 4700 | EXPECT_CALL(*layer1.outputLayer, |
| 4701 | writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, z++, |
| 4702 | /*zIsOverridden*/ false, /*isPeekingThrough*/ false)); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 4703 | EXPECT_CALL(*layer1.outputLayer, requiresClientComposition()).WillRepeatedly(Return(false)); |
Lucas Dupin | 084a6d4 | 2021-08-26 22:10:29 +0000 | [diff] [blame] | 4704 | EXPECT_CALL(*layer2.outputLayer, updateCompositionState(false, false, ui::Transform::ROT_0)); |
| 4705 | EXPECT_CALL(*layer2.outputLayer, |
| 4706 | writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, z++, |
| 4707 | /*zIsOverridden*/ false, /*isPeekingThrough*/ false)); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 4708 | EXPECT_CALL(*layer2.outputLayer, requiresClientComposition()).WillRepeatedly(Return(false)); |
Lucas Dupin | 084a6d4 | 2021-08-26 22:10:29 +0000 | [diff] [blame] | 4709 | |
| 4710 | layer2.layerFEState.backgroundBlurRadius = 10; |
| 4711 | layer2.layerFEState.isOpaque = true; |
| 4712 | |
| 4713 | injectOutputLayer(layer1); |
| 4714 | injectOutputLayer(layer2); |
| 4715 | |
| 4716 | mOutput->editState().isEnabled = true; |
| 4717 | |
| 4718 | CompositionRefreshArgs args; |
| 4719 | args.updatingGeometryThisFrame = false; |
| 4720 | args.devOptForceClientComposition = false; |
| 4721 | mOutput->updateCompositionState(args); |
| 4722 | mOutput->planComposition(); |
| 4723 | mOutput->writeCompositionState(args); |
| 4724 | } |
| 4725 | |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 4726 | TEST_F(OutputUpdateAndWriteCompositionStateTest, handlesBackgroundBlurRequests) { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 4727 | InjectedLayer layer1; |
| 4728 | InjectedLayer layer2; |
| 4729 | InjectedLayer layer3; |
| 4730 | |
Leon Scroggins III | e2ee040 | 2021-04-02 16:59:37 -0400 | [diff] [blame] | 4731 | uint32_t z = 0; |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 4732 | // Layer requesting blur, or below, should request client composition. |
Snild Dolkow | 9e217d6 | 2020-04-22 15:53:42 +0200 | [diff] [blame] | 4733 | EXPECT_CALL(*layer1.outputLayer, updateCompositionState(false, true, ui::Transform::ROT_0)); |
Dan Stoza | 6166c31 | 2021-01-15 16:34:05 -0800 | [diff] [blame] | 4734 | EXPECT_CALL(*layer1.outputLayer, |
Leon Scroggins III | 9aa25c2 | 2021-04-15 15:30:19 -0400 | [diff] [blame] | 4735 | writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, z++, |
| 4736 | /*zIsOverridden*/ false, /*isPeekingThrough*/ false)); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 4737 | EXPECT_CALL(*layer1.outputLayer, requiresClientComposition()).WillRepeatedly(Return(false)); |
Snild Dolkow | 9e217d6 | 2020-04-22 15:53:42 +0200 | [diff] [blame] | 4738 | EXPECT_CALL(*layer2.outputLayer, updateCompositionState(false, true, ui::Transform::ROT_0)); |
Dan Stoza | 6166c31 | 2021-01-15 16:34:05 -0800 | [diff] [blame] | 4739 | EXPECT_CALL(*layer2.outputLayer, |
Leon Scroggins III | 9aa25c2 | 2021-04-15 15:30:19 -0400 | [diff] [blame] | 4740 | writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, z++, |
| 4741 | /*zIsOverridden*/ false, /*isPeekingThrough*/ false)); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 4742 | EXPECT_CALL(*layer2.outputLayer, requiresClientComposition()).WillRepeatedly(Return(false)); |
Snild Dolkow | 9e217d6 | 2020-04-22 15:53:42 +0200 | [diff] [blame] | 4743 | EXPECT_CALL(*layer3.outputLayer, updateCompositionState(false, false, ui::Transform::ROT_0)); |
Dan Stoza | 6166c31 | 2021-01-15 16:34:05 -0800 | [diff] [blame] | 4744 | EXPECT_CALL(*layer3.outputLayer, |
Leon Scroggins III | 9aa25c2 | 2021-04-15 15:30:19 -0400 | [diff] [blame] | 4745 | writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, z++, |
| 4746 | /*zIsOverridden*/ false, /*isPeekingThrough*/ false)); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 4747 | EXPECT_CALL(*layer3.outputLayer, requiresClientComposition()).WillRepeatedly(Return(false)); |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 4748 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 4749 | layer2.layerFEState.backgroundBlurRadius = 10; |
Lucas Dupin | 084a6d4 | 2021-08-26 22:10:29 +0000 | [diff] [blame] | 4750 | layer2.layerFEState.isOpaque = false; |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 4751 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 4752 | injectOutputLayer(layer1); |
| 4753 | injectOutputLayer(layer2); |
| 4754 | injectOutputLayer(layer3); |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 4755 | |
| 4756 | mOutput->editState().isEnabled = true; |
| 4757 | |
| 4758 | CompositionRefreshArgs args; |
| 4759 | args.updatingGeometryThisFrame = false; |
| 4760 | args.devOptForceClientComposition = false; |
Dan Stoza | 269dc4d | 2021-01-15 15:07:43 -0800 | [diff] [blame] | 4761 | mOutput->updateCompositionState(args); |
| 4762 | mOutput->planComposition(); |
| 4763 | mOutput->writeCompositionState(args); |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 4764 | } |
| 4765 | |
Lucas Dupin | c3800b8 | 2020-10-02 16:24:48 -0700 | [diff] [blame] | 4766 | TEST_F(OutputUpdateAndWriteCompositionStateTest, handlesBlurRegionRequests) { |
| 4767 | InjectedLayer layer1; |
| 4768 | InjectedLayer layer2; |
| 4769 | InjectedLayer layer3; |
| 4770 | |
Leon Scroggins III | e2ee040 | 2021-04-02 16:59:37 -0400 | [diff] [blame] | 4771 | uint32_t z = 0; |
Lucas Dupin | c3800b8 | 2020-10-02 16:24:48 -0700 | [diff] [blame] | 4772 | // Layer requesting blur, or below, should request client composition. |
| 4773 | EXPECT_CALL(*layer1.outputLayer, updateCompositionState(false, true, ui::Transform::ROT_0)); |
Dan Stoza | 6166c31 | 2021-01-15 16:34:05 -0800 | [diff] [blame] | 4774 | EXPECT_CALL(*layer1.outputLayer, |
Leon Scroggins III | 9aa25c2 | 2021-04-15 15:30:19 -0400 | [diff] [blame] | 4775 | writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, z++, |
| 4776 | /*zIsOverridden*/ false, /*isPeekingThrough*/ false)); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 4777 | EXPECT_CALL(*layer1.outputLayer, requiresClientComposition()).WillRepeatedly(Return(false)); |
Lucas Dupin | c3800b8 | 2020-10-02 16:24:48 -0700 | [diff] [blame] | 4778 | EXPECT_CALL(*layer2.outputLayer, updateCompositionState(false, true, ui::Transform::ROT_0)); |
Dan Stoza | 6166c31 | 2021-01-15 16:34:05 -0800 | [diff] [blame] | 4779 | EXPECT_CALL(*layer2.outputLayer, |
Leon Scroggins III | 9aa25c2 | 2021-04-15 15:30:19 -0400 | [diff] [blame] | 4780 | writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, z++, |
| 4781 | /*zIsOverridden*/ false, /*isPeekingThrough*/ false)); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 4782 | EXPECT_CALL(*layer2.outputLayer, requiresClientComposition()).WillRepeatedly(Return(false)); |
Lucas Dupin | c3800b8 | 2020-10-02 16:24:48 -0700 | [diff] [blame] | 4783 | EXPECT_CALL(*layer3.outputLayer, updateCompositionState(false, false, ui::Transform::ROT_0)); |
Dan Stoza | 6166c31 | 2021-01-15 16:34:05 -0800 | [diff] [blame] | 4784 | EXPECT_CALL(*layer3.outputLayer, |
Leon Scroggins III | 9aa25c2 | 2021-04-15 15:30:19 -0400 | [diff] [blame] | 4785 | writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, z++, |
| 4786 | /*zIsOverridden*/ false, /*isPeekingThrough*/ false)); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 4787 | EXPECT_CALL(*layer3.outputLayer, requiresClientComposition()).WillRepeatedly(Return(false)); |
Lucas Dupin | c3800b8 | 2020-10-02 16:24:48 -0700 | [diff] [blame] | 4788 | |
| 4789 | BlurRegion region; |
| 4790 | layer2.layerFEState.blurRegions.push_back(region); |
Lucas Dupin | 084a6d4 | 2021-08-26 22:10:29 +0000 | [diff] [blame] | 4791 | layer2.layerFEState.isOpaque = false; |
Lucas Dupin | c3800b8 | 2020-10-02 16:24:48 -0700 | [diff] [blame] | 4792 | |
| 4793 | injectOutputLayer(layer1); |
| 4794 | injectOutputLayer(layer2); |
| 4795 | injectOutputLayer(layer3); |
| 4796 | |
| 4797 | mOutput->editState().isEnabled = true; |
| 4798 | |
| 4799 | CompositionRefreshArgs args; |
| 4800 | args.updatingGeometryThisFrame = false; |
| 4801 | args.devOptForceClientComposition = false; |
Dan Stoza | 269dc4d | 2021-01-15 15:07:43 -0800 | [diff] [blame] | 4802 | mOutput->updateCompositionState(args); |
| 4803 | mOutput->planComposition(); |
| 4804 | mOutput->writeCompositionState(args); |
Lucas Dupin | c3800b8 | 2020-10-02 16:24:48 -0700 | [diff] [blame] | 4805 | } |
| 4806 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4807 | TEST_F(GenerateClientCompositionRequestsTest, handlesLandscapeModeSplitScreenRequests) { |
| 4808 | // In split-screen landscape mode, the screen is rotated 90 degrees, with |
| 4809 | // one layer on the left covering the left side of the output, and one layer |
| 4810 | // on the right covering that side of the output. |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 4811 | |
| 4812 | const Rect kPortraitFrame(0, 0, 1000, 2000); |
| 4813 | const Rect kPortraitViewport(0, 0, 2000, 1000); |
Lloyd Pique | e8fe474 | 2020-01-21 15:26:18 -0800 | [diff] [blame] | 4814 | const Rect kPortraitDestinationClip(0, 0, 1000, 2000); |
Marin Shalamanov | 68933fb | 2020-09-10 17:58:12 +0200 | [diff] [blame] | 4815 | const ui::Rotation kPortraitOrientation = ui::ROTATION_90; |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4816 | constexpr ui::Dataspace kOutputDataspace = ui::Dataspace::DISPLAY_P3; |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 4817 | |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 4818 | mOutput.mState.orientedDisplaySpace.setContent(kPortraitFrame); |
| 4819 | mOutput.mState.layerStackSpace.setContent(kPortraitViewport); |
| 4820 | mOutput.mState.displaySpace.setContent(kPortraitDestinationClip); |
Marin Shalamanov | 68933fb | 2020-09-10 17:58:12 +0200 | [diff] [blame] | 4821 | mOutput.mState.transform = ui::Transform{ui::Transform::toRotationFlags(kPortraitOrientation)}; |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 4822 | mOutput.mState.displaySpace.setOrientation(kPortraitOrientation); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4823 | mOutput.mState.needsFiltering = false; |
| 4824 | mOutput.mState.isSecure = true; |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 4825 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4826 | Layer leftLayer; |
| 4827 | Layer rightLayer; |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 4828 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4829 | leftLayer.mOutputLayerState.clearClientTarget = false; |
| 4830 | leftLayer.mOutputLayerState.visibleRegion = Region(Rect(0, 0, 1000, 1000)); |
| 4831 | leftLayer.mLayerFEState.isOpaque = true; |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 4832 | leftLayer.mLayerSettings.source.solidColor = {1.f, 0.f, 0.f}; |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 4833 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4834 | rightLayer.mOutputLayerState.clearClientTarget = false; |
| 4835 | rightLayer.mOutputLayerState.visibleRegion = Region(Rect(1000, 0, 2000, 1000)); |
| 4836 | rightLayer.mLayerFEState.isOpaque = true; |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 4837 | rightLayer.mLayerSettings.source.solidColor = {0.f, 1.f, 0.f}; |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4838 | |
| 4839 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(2u)); |
| 4840 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0u)) |
| 4841 | .WillRepeatedly(Return(&leftLayer.mOutputLayer)); |
| 4842 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(1u)) |
| 4843 | .WillRepeatedly(Return(&rightLayer.mOutputLayer)); |
| 4844 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4845 | compositionengine::LayerFE::ClientCompositionTargetSettings leftLayerSettings{ |
| 4846 | Region(Rect(0, 0, 1000, 1000)), |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4847 | false, /* needs filtering */ |
| 4848 | true, /* secure */ |
| 4849 | true, /* supports protected content */ |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 4850 | kPortraitViewport, |
| 4851 | kOutputDataspace, |
| 4852 | true /* realContentIsVisible */, |
| 4853 | false /* clearContent */, |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 4854 | compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled, |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 4855 | kLayerWhitePointNits, |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 4856 | false /* treat170mAsSrgb */, |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4857 | }; |
| 4858 | |
| 4859 | EXPECT_CALL(leftLayer.mOutputLayer, requiresClientComposition()).WillRepeatedly(Return(true)); |
| 4860 | EXPECT_CALL(leftLayer.mOutputLayer, needsFiltering()).WillRepeatedly(Return(false)); |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 4861 | EXPECT_CALL(*leftLayer.mLayerFE, prepareClientComposition(Eq(ByRef(leftLayerSettings)))) |
| 4862 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>(leftLayer.mLayerSettings))); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4863 | |
| 4864 | compositionengine::LayerFE::ClientCompositionTargetSettings rightLayerSettings{ |
| 4865 | Region(Rect(1000, 0, 2000, 1000)), |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4866 | false, /* needs filtering */ |
| 4867 | true, /* secure */ |
| 4868 | true, /* supports protected content */ |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 4869 | kPortraitViewport, |
| 4870 | kOutputDataspace, |
| 4871 | true /* realContentIsVisible */, |
| 4872 | false /* clearContent */, |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 4873 | compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled, |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 4874 | kLayerWhitePointNits, |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 4875 | false /* treat170mAsSrgb */, |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4876 | }; |
| 4877 | |
| 4878 | EXPECT_CALL(rightLayer.mOutputLayer, requiresClientComposition()).WillRepeatedly(Return(true)); |
| 4879 | EXPECT_CALL(rightLayer.mOutputLayer, needsFiltering()).WillRepeatedly(Return(false)); |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 4880 | EXPECT_CALL(*rightLayer.mLayerFE, prepareClientComposition(Eq(ByRef(rightLayerSettings)))) |
| 4881 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>(rightLayer.mLayerSettings))); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4882 | |
| 4883 | constexpr bool supportsProtectedContent = true; |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 4884 | auto requests = mOutput.generateClientCompositionRequestsHelper(supportsProtectedContent, |
| 4885 | kOutputDataspace); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4886 | ASSERT_EQ(2u, requests.size()); |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 4887 | EXPECT_EQ(leftLayer.mLayerSettings, requests[0]); |
| 4888 | EXPECT_EQ(rightLayer.mLayerSettings, requests[1]); |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 4889 | } |
| 4890 | |
Vishnu Nair | a483b4a | 2019-12-12 15:07:52 -0800 | [diff] [blame] | 4891 | TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers, |
| 4892 | shadowRegionOnlyVisibleSkipsContentComposition) { |
| 4893 | const Rect kContentWithShadow(40, 40, 70, 90); |
| 4894 | const Rect kContent(50, 50, 60, 80); |
| 4895 | const Region kShadowRegion = Region(kContentWithShadow).subtract(kContent); |
| 4896 | const Region kPartialShadowRegion = Region(kContentWithShadow).subtract(Rect(40, 40, 60, 80)); |
| 4897 | |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 4898 | compositionengine::LayerFE::ClientCompositionTargetSettings layer2Settings{ |
| 4899 | 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] | 4900 | false, /* needs filtering */ |
| 4901 | false, /* secure */ |
| 4902 | false, /* supports protected content */ |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 4903 | kDisplayViewport, |
| 4904 | kDisplayDataspace, |
| 4905 | false /* realContentIsVisible */, |
| 4906 | false /* clearContent */, |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 4907 | compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled, |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 4908 | kLayerWhitePointNits, |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 4909 | false /* treat170mAsSrgb */, |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 4910 | }; |
| 4911 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 4912 | LayerFE::LayerSettings mShadowSettings; |
| 4913 | mShadowSettings.source.solidColor = {0.1f, 0.1f, 0.1f}; |
Vishnu Nair | a483b4a | 2019-12-12 15:07:52 -0800 | [diff] [blame] | 4914 | |
| 4915 | mLayers[2].mOutputLayerState.visibleRegion = kPartialShadowRegion; |
| 4916 | mLayers[2].mOutputLayerState.shadowRegion = kShadowRegion; |
| 4917 | |
| 4918 | EXPECT_CALL(mLayers[0].mOutputLayer, requiresClientComposition()).WillOnce(Return(false)); |
| 4919 | EXPECT_CALL(mLayers[1].mOutputLayer, requiresClientComposition()).WillOnce(Return(false)); |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 4920 | EXPECT_CALL(*mLayers[2].mLayerFE, prepareClientComposition(Eq(ByRef(layer2Settings)))) |
| 4921 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>(mShadowSettings))); |
Vishnu Nair | a483b4a | 2019-12-12 15:07:52 -0800 | [diff] [blame] | 4922 | |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 4923 | auto requests = |
| 4924 | mOutput.generateClientCompositionRequestsHelper(false /* supportsProtectedContent */, |
| 4925 | kDisplayDataspace); |
Vishnu Nair | a483b4a | 2019-12-12 15:07:52 -0800 | [diff] [blame] | 4926 | ASSERT_EQ(1u, requests.size()); |
| 4927 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 4928 | EXPECT_EQ(mShadowSettings, requests[0]); |
Vishnu Nair | a483b4a | 2019-12-12 15:07:52 -0800 | [diff] [blame] | 4929 | } |
| 4930 | |
| 4931 | TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers, |
| 4932 | shadowRegionWithContentVisibleRequestsContentAndShadowComposition) { |
| 4933 | const Rect kContentWithShadow(40, 40, 70, 90); |
| 4934 | const Rect kContent(50, 50, 60, 80); |
| 4935 | const Region kShadowRegion = Region(kContentWithShadow).subtract(kContent); |
| 4936 | const Region kPartialContentWithPartialShadowRegion = |
| 4937 | Region(kContentWithShadow).subtract(Rect(40, 40, 50, 80)); |
| 4938 | |
Vishnu Nair | a483b4a | 2019-12-12 15:07:52 -0800 | [diff] [blame] | 4939 | mLayers[2].mOutputLayerState.visibleRegion = kPartialContentWithPartialShadowRegion; |
| 4940 | mLayers[2].mOutputLayerState.shadowRegion = kShadowRegion; |
| 4941 | |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 4942 | compositionengine::LayerFE::ClientCompositionTargetSettings layer2Settings{ |
| 4943 | 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] | 4944 | false, /* needs filtering */ |
| 4945 | false, /* secure */ |
| 4946 | false, /* supports protected content */ |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 4947 | kDisplayViewport, |
| 4948 | kDisplayDataspace, |
| 4949 | true /* realContentIsVisible */, |
| 4950 | false /* clearContent */, |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 4951 | compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled, |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 4952 | kLayerWhitePointNits, |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 4953 | false /* treat170mAsSrgb */, |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 4954 | }; |
| 4955 | |
Vishnu Nair | a483b4a | 2019-12-12 15:07:52 -0800 | [diff] [blame] | 4956 | EXPECT_CALL(mLayers[0].mOutputLayer, requiresClientComposition()).WillOnce(Return(false)); |
| 4957 | EXPECT_CALL(mLayers[1].mOutputLayer, requiresClientComposition()).WillOnce(Return(false)); |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 4958 | EXPECT_CALL(*mLayers[2].mLayerFE, prepareClientComposition(Eq(ByRef(layer2Settings)))) |
| 4959 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>(mLayers[2].mLayerSettings))); |
Vishnu Nair | a483b4a | 2019-12-12 15:07:52 -0800 | [diff] [blame] | 4960 | |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 4961 | auto requests = |
| 4962 | mOutput.generateClientCompositionRequestsHelper(false /* supportsProtectedContent */, |
| 4963 | kDisplayDataspace); |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 4964 | ASSERT_EQ(1u, requests.size()); |
Vishnu Nair | a483b4a | 2019-12-12 15:07:52 -0800 | [diff] [blame] | 4965 | |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 4966 | EXPECT_EQ(mLayers[2].mLayerSettings, requests[0]); |
Vishnu Nair | a483b4a | 2019-12-12 15:07:52 -0800 | [diff] [blame] | 4967 | } |
| 4968 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 4969 | } // namespace |
| 4970 | } // namespace android::compositionengine |