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> |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 18 | #include <com_android_graphics_surfaceflinger_flags.h> |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 19 | #include <compositionengine/LayerFECompositionState.h> |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 20 | #include <compositionengine/impl/Output.h> |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 21 | #include <compositionengine/impl/OutputCompositionState.h> |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 22 | #include <compositionengine/impl/OutputLayerCompositionState.h> |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 23 | #include <compositionengine/mock/CompositionEngine.h> |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 24 | #include <compositionengine/mock/DisplayColorProfile.h> |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 25 | #include <compositionengine/mock/LayerFE.h> |
| 26 | #include <compositionengine/mock/OutputLayer.h> |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 27 | #include <compositionengine/mock/RenderSurface.h> |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 28 | #include <ftl/future.h> |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 29 | #include <gtest/gtest.h> |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 30 | #include <renderengine/ExternalTexture.h> |
| 31 | #include <renderengine/impl/ExternalTexture.h> |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 32 | #include <renderengine/mock/FakeExternalTexture.h> |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 33 | #include <renderengine/mock/RenderEngine.h> |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 34 | #include <ui/Rect.h> |
| 35 | #include <ui/Region.h> |
| 36 | |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 37 | #include <cmath> |
Leon Scroggins III | e2ee040 | 2021-04-02 16:59:37 -0400 | [diff] [blame] | 38 | #include <cstdint> |
Leon Scroggins III | 2f60d73 | 2022-09-12 14:42:38 -0400 | [diff] [blame] | 39 | #include <variant> |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 40 | |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 41 | #include <common/FlagManager.h> |
| 42 | #include <common/test/FlagUtils.h> |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 43 | #include "CallOrderStateMachineHelper.h" |
Lloyd Pique | 07178e3 | 2019-11-19 19:15:26 -0800 | [diff] [blame] | 44 | #include "MockHWC2.h" |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 45 | #include "RegionMatcher.h" |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 46 | |
| 47 | namespace android::compositionengine { |
| 48 | namespace { |
| 49 | |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 50 | using namespace com::android::graphics::surfaceflinger; |
| 51 | |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 52 | using testing::_; |
Lloyd Pique | 03561a6 | 2019-11-19 18:34:52 -0800 | [diff] [blame] | 53 | using testing::ByMove; |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 54 | using testing::ByRef; |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 55 | using testing::DoAll; |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 56 | using testing::ElementsAre; |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 57 | using testing::ElementsAreArray; |
Lloyd Pique | 07178e3 | 2019-11-19 19:15:26 -0800 | [diff] [blame] | 58 | using testing::Eq; |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 59 | using testing::InSequence; |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 60 | using testing::Invoke; |
| 61 | using testing::IsEmpty; |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 62 | using testing::Mock; |
Leon Scroggins III | 2f60d73 | 2022-09-12 14:42:38 -0400 | [diff] [blame] | 63 | using testing::NiceMock; |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 64 | using testing::Pointee; |
Lloyd Pique | 07178e3 | 2019-11-19 19:15:26 -0800 | [diff] [blame] | 65 | using testing::Property; |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 66 | using testing::Ref; |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 67 | using testing::Return; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 68 | using testing::ReturnRef; |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 69 | using testing::SetArgPointee; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 70 | using testing::StrictMock; |
| 71 | |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 72 | constexpr auto TR_IDENT = 0u; |
| 73 | constexpr auto TR_ROT_90 = HAL_TRANSFORM_ROT_90; |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 74 | constexpr auto MAX_CLIENT_COMPOSITION_CACHE_SIZE = 3; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 75 | |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 76 | const mat4 kIdentity; |
Lloyd Pique | 0a45623 | 2020-01-16 17:51:13 -0800 | [diff] [blame] | 77 | const mat4 kNonIdentityHalf = mat4() * 0.5f; |
| 78 | const mat4 kNonIdentityQuarter = mat4() * 0.25f; |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 79 | |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 80 | constexpr OutputColorSetting kVendorSpecifiedOutputColorSetting = |
| 81 | static_cast<OutputColorSetting>(0x100); |
| 82 | |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 83 | using CompositionStrategyPredictionState = android::compositionengine::impl:: |
| 84 | OutputCompositionState::CompositionStrategyPredictionState; |
| 85 | |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 86 | struct OutputPartialMockBase : public impl::Output { |
| 87 | // compositionengine::Output overrides |
| 88 | const OutputCompositionState& getState() const override { return mState; } |
| 89 | OutputCompositionState& editState() override { return mState; } |
| 90 | |
| 91 | // Use mocks for all the remaining virtual functions |
| 92 | // not implemented by the base implementation class. |
| 93 | MOCK_CONST_METHOD0(getOutputLayerCount, size_t()); |
| 94 | MOCK_CONST_METHOD1(getOutputLayerOrderedByZByIndex, compositionengine::OutputLayer*(size_t)); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 95 | MOCK_METHOD2(ensureOutputLayer, |
| 96 | compositionengine::OutputLayer*(std::optional<size_t>, const sp<LayerFE>&)); |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 97 | MOCK_METHOD0(finalizePendingOutputLayers, void()); |
| 98 | MOCK_METHOD0(clearOutputLayers, void()); |
| 99 | MOCK_CONST_METHOD1(dumpState, void(std::string&)); |
| 100 | MOCK_CONST_METHOD0(getCompositionEngine, const CompositionEngine&()); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 101 | MOCK_METHOD1(injectOutputLayerForTest, compositionengine::OutputLayer*(const sp<LayerFE>&)); |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 102 | MOCK_METHOD1(injectOutputLayerForTest, void(std::unique_ptr<OutputLayer>)); |
| 103 | |
| 104 | impl::OutputCompositionState mState; |
| 105 | }; |
| 106 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 107 | struct InjectedLayer { |
| 108 | InjectedLayer() { |
| 109 | EXPECT_CALL(*outputLayer, getLayerFE()).WillRepeatedly(ReturnRef(*layerFE.get())); |
| 110 | EXPECT_CALL(*outputLayer, getState()).WillRepeatedly(ReturnRef(outputLayerState)); |
| 111 | EXPECT_CALL(*outputLayer, editState()).WillRepeatedly(ReturnRef(outputLayerState)); |
| 112 | |
| 113 | EXPECT_CALL(*layerFE, getCompositionState()).WillRepeatedly(Return(&layerFEState)); |
Dan Stoza | 269dc4d | 2021-01-15 15:07:43 -0800 | [diff] [blame] | 114 | EXPECT_CALL(*layerFE, getSequence()).WillRepeatedly(Return(0)); |
| 115 | EXPECT_CALL(*layerFE, getDebugName()).WillRepeatedly(Return("InjectedLayer")); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | mock::OutputLayer* outputLayer = {new StrictMock<mock::OutputLayer>}; |
Ady Abraham | e0eafa8 | 2022-02-02 19:30:47 -0800 | [diff] [blame] | 119 | sp<StrictMock<mock::LayerFE>> layerFE = sp<StrictMock<mock::LayerFE>>::make(); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 120 | LayerFECompositionState layerFEState; |
| 121 | impl::OutputLayerCompositionState outputLayerState; |
| 122 | }; |
| 123 | |
| 124 | struct NonInjectedLayer { |
| 125 | NonInjectedLayer() { |
| 126 | EXPECT_CALL(outputLayer, getLayerFE()).WillRepeatedly(ReturnRef(*layerFE.get())); |
| 127 | EXPECT_CALL(outputLayer, getState()).WillRepeatedly(ReturnRef(outputLayerState)); |
| 128 | EXPECT_CALL(outputLayer, editState()).WillRepeatedly(ReturnRef(outputLayerState)); |
| 129 | |
| 130 | EXPECT_CALL(*layerFE, getCompositionState()).WillRepeatedly(Return(&layerFEState)); |
Dan Stoza | 269dc4d | 2021-01-15 15:07:43 -0800 | [diff] [blame] | 131 | EXPECT_CALL(*layerFE, getSequence()).WillRepeatedly(Return(0)); |
| 132 | EXPECT_CALL(*layerFE, getDebugName()).WillRepeatedly(Return("NonInjectedLayer")); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | mock::OutputLayer outputLayer; |
Ady Abraham | e0eafa8 | 2022-02-02 19:30:47 -0800 | [diff] [blame] | 136 | sp<StrictMock<mock::LayerFE>> layerFE = sp<StrictMock<mock::LayerFE>>::make(); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 137 | LayerFECompositionState layerFEState; |
| 138 | impl::OutputLayerCompositionState outputLayerState; |
| 139 | }; |
| 140 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 141 | struct OutputTest : public testing::Test { |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 142 | class Output : public impl::Output { |
| 143 | public: |
| 144 | using impl::Output::injectOutputLayerForTest; |
| 145 | virtual void injectOutputLayerForTest(std::unique_ptr<compositionengine::OutputLayer>) = 0; |
| 146 | }; |
| 147 | |
| 148 | static std::shared_ptr<Output> createOutput( |
| 149 | const compositionengine::CompositionEngine& compositionEngine) { |
| 150 | return impl::createOutputTemplated<Output>(compositionEngine); |
| 151 | } |
| 152 | |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 153 | OutputTest() { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 154 | mOutput->setDisplayColorProfileForTest( |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 155 | std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile)); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 156 | mOutput->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface)); |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 157 | |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 158 | mOutput->editState().displaySpace.setBounds( |
| 159 | ui::Size(kDefaultDisplaySize.getWidth(), kDefaultDisplaySize.getHeight())); |
Alec Mouri | df6201b | 2021-06-01 16:20:42 -0700 | [diff] [blame] | 160 | EXPECT_CALL(mCompositionEngine, getRenderEngine()).WillRepeatedly(ReturnRef(mRenderEngine)); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 161 | } |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 162 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 163 | void injectOutputLayer(InjectedLayer& layer) { |
| 164 | mOutput->injectOutputLayerForTest(std::unique_ptr<OutputLayer>(layer.outputLayer)); |
| 165 | } |
| 166 | |
| 167 | void injectNullOutputLayer() { |
| 168 | mOutput->injectOutputLayerForTest(std::unique_ptr<OutputLayer>(nullptr)); |
| 169 | } |
| 170 | |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 171 | static const Rect kDefaultDisplaySize; |
| 172 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 173 | StrictMock<mock::CompositionEngine> mCompositionEngine; |
Alec Mouri | df6201b | 2021-06-01 16:20:42 -0700 | [diff] [blame] | 174 | StrictMock<renderengine::mock::RenderEngine> mRenderEngine; |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 175 | mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>(); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 176 | mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>(); |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 177 | std::shared_ptr<Output> mOutput = createOutput(mCompositionEngine); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 178 | }; |
| 179 | |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 180 | const Rect OutputTest::kDefaultDisplaySize{100, 200}; |
| 181 | |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 182 | using ColorProfile = compositionengine::Output::ColorProfile; |
| 183 | |
| 184 | void dumpColorProfile(ColorProfile profile, std::string& result, const char* name) { |
Alec Mouri | 88790f3 | 2023-07-21 01:25:14 +0000 | [diff] [blame] | 185 | android::base::StringAppendF(&result, "%s (%s[%d] %s[%d] %s[%d]) ", name, |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 186 | toString(profile.mode).c_str(), profile.mode, |
| 187 | toString(profile.dataspace).c_str(), profile.dataspace, |
Alec Mouri | 88790f3 | 2023-07-21 01:25:14 +0000 | [diff] [blame] | 188 | toString(profile.renderIntent).c_str(), profile.renderIntent); |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | // Checks for a ColorProfile match |
| 192 | MATCHER_P(ColorProfileEq, expected, "") { |
| 193 | std::string buf; |
| 194 | buf.append("ColorProfiles are not equal\n"); |
| 195 | dumpColorProfile(expected, buf, "expected value"); |
| 196 | dumpColorProfile(arg, buf, "actual value"); |
| 197 | *result_listener << buf; |
| 198 | |
| 199 | return (expected.mode == arg.mode) && (expected.dataspace == arg.dataspace) && |
Alec Mouri | 88790f3 | 2023-07-21 01:25:14 +0000 | [diff] [blame] | 200 | (expected.renderIntent == arg.renderIntent); |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 201 | } |
| 202 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 203 | /* |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 204 | * Basic construction |
| 205 | */ |
| 206 | |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 207 | TEST_F(OutputTest, canInstantiateOutput) { |
| 208 | // The validation check checks each required component. |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 209 | EXPECT_CALL(*mDisplayColorProfile, isValid()).WillOnce(Return(true)); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 210 | EXPECT_CALL(*mRenderSurface, isValid()).WillOnce(Return(true)); |
| 211 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 212 | EXPECT_TRUE(mOutput->isValid()); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 213 | |
| 214 | // If we take away the required components, it is no longer valid. |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 215 | mOutput->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>()); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 216 | |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 217 | EXPECT_CALL(*mDisplayColorProfile, isValid()).WillOnce(Return(true)); |
| 218 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 219 | EXPECT_FALSE(mOutput->isValid()); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 220 | } |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 221 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 222 | /* |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 223 | * Output::setCompositionEnabled() |
| 224 | */ |
| 225 | |
| 226 | TEST_F(OutputTest, setCompositionEnabledDoesNothingIfAlreadyEnabled) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 227 | mOutput->editState().isEnabled = true; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 228 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 229 | mOutput->setCompositionEnabled(true); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 230 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 231 | EXPECT_TRUE(mOutput->getState().isEnabled); |
| 232 | EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region())); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | TEST_F(OutputTest, setCompositionEnabledSetsEnabledAndDirtiesEntireOutput) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 236 | mOutput->editState().isEnabled = false; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 237 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 238 | mOutput->setCompositionEnabled(true); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 239 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 240 | EXPECT_TRUE(mOutput->getState().isEnabled); |
| 241 | EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize))); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | TEST_F(OutputTest, setCompositionEnabledSetsDisabledAndDirtiesEntireOutput) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 245 | mOutput->editState().isEnabled = true; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 246 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 247 | mOutput->setCompositionEnabled(false); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 248 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 249 | EXPECT_FALSE(mOutput->getState().isEnabled); |
| 250 | EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize))); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 251 | } |
| 252 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 253 | /* |
Alec Mouri | dda07d9 | 2022-04-25 22:39:25 +0000 | [diff] [blame] | 254 | * Output::setTreat170mAsSrgb() |
| 255 | */ |
| 256 | |
| 257 | TEST_F(OutputTest, setTreat170mAsSrgb) { |
| 258 | EXPECT_FALSE(mOutput->getState().treat170mAsSrgb); |
| 259 | |
| 260 | mOutput->setTreat170mAsSrgb(true); |
| 261 | EXPECT_TRUE(mOutput->getState().treat170mAsSrgb); |
| 262 | |
| 263 | mOutput->setTreat170mAsSrgb(false); |
| 264 | EXPECT_FALSE(mOutput->getState().treat170mAsSrgb); |
| 265 | } |
| 266 | |
| 267 | /* |
Alec Mouri | 023c188 | 2021-05-08 16:36:33 -0700 | [diff] [blame] | 268 | * Output::setLayerCachingEnabled() |
| 269 | */ |
| 270 | |
| 271 | TEST_F(OutputTest, setLayerCachingEnabled_enablesCaching) { |
| 272 | const auto kSize = ui::Size(1, 1); |
| 273 | EXPECT_CALL(*mRenderSurface, getSize()).WillRepeatedly(ReturnRef(kSize)); |
| 274 | mOutput->setLayerCachingEnabled(false); |
| 275 | mOutput->setLayerCachingEnabled(true); |
| 276 | |
| 277 | EXPECT_TRUE(mOutput->plannerEnabled()); |
| 278 | } |
| 279 | |
| 280 | TEST_F(OutputTest, setLayerCachingEnabled_disablesCaching) { |
| 281 | const auto kSize = ui::Size(1, 1); |
| 282 | EXPECT_CALL(*mRenderSurface, getSize()).WillRepeatedly(ReturnRef(kSize)); |
| 283 | mOutput->setLayerCachingEnabled(true); |
| 284 | mOutput->setLayerCachingEnabled(false); |
| 285 | |
| 286 | EXPECT_FALSE(mOutput->plannerEnabled()); |
| 287 | } |
| 288 | |
Alec Mouri | c773472b | 2021-05-19 14:29:05 -0700 | [diff] [blame] | 289 | TEST_F(OutputTest, setLayerCachingEnabled_disablesCachingAndResetsOverrideInfo) { |
| 290 | renderengine::mock::RenderEngine renderEngine; |
| 291 | const auto kSize = ui::Size(1, 1); |
| 292 | EXPECT_CALL(*mRenderSurface, getSize()).WillRepeatedly(ReturnRef(kSize)); |
| 293 | mOutput->setLayerCachingEnabled(true); |
| 294 | |
| 295 | // Inject some layers |
| 296 | InjectedLayer layer; |
| 297 | layer.outputLayerState.overrideInfo.buffer = std::make_shared< |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 298 | renderengine::impl:: |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 299 | ExternalTexture>(sp<GraphicBuffer>::make(), renderEngine, |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 300 | renderengine::impl::ExternalTexture::Usage::READABLE | |
| 301 | renderengine::impl::ExternalTexture::Usage::WRITEABLE); |
Alec Mouri | c773472b | 2021-05-19 14:29:05 -0700 | [diff] [blame] | 302 | injectOutputLayer(layer); |
| 303 | // inject a null layer to check for null exceptions |
| 304 | injectNullOutputLayer(); |
| 305 | |
| 306 | EXPECT_NE(nullptr, layer.outputLayerState.overrideInfo.buffer); |
| 307 | mOutput->setLayerCachingEnabled(false); |
| 308 | EXPECT_EQ(nullptr, layer.outputLayerState.overrideInfo.buffer); |
| 309 | } |
| 310 | |
Alec Mouri | 023c188 | 2021-05-08 16:36:33 -0700 | [diff] [blame] | 311 | /* |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 312 | * Output::setProjection() |
| 313 | */ |
| 314 | |
Marin Shalamanov | 209ae61 | 2020-10-01 00:17:39 +0200 | [diff] [blame] | 315 | TEST_F(OutputTest, setProjectionWorks) { |
| 316 | const Rect displayRect{0, 0, 1000, 2000}; |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 317 | mOutput->editState().displaySpace.setBounds( |
| 318 | ui::Size(displayRect.getWidth(), displayRect.getHeight())); |
| 319 | mOutput->editState().framebufferSpace.setBounds( |
| 320 | ui::Size(displayRect.getWidth(), displayRect.getHeight())); |
Marin Shalamanov | 209ae61 | 2020-10-01 00:17:39 +0200 | [diff] [blame] | 321 | |
Marin Shalamanov | 68933fb | 2020-09-10 17:58:12 +0200 | [diff] [blame] | 322 | const ui::Rotation orientation = ui::ROTATION_90; |
Marin Shalamanov | 209ae61 | 2020-10-01 00:17:39 +0200 | [diff] [blame] | 323 | const Rect frame{50, 60, 100, 100}; |
| 324 | const Rect viewport{10, 20, 30, 40}; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 325 | |
Marin Shalamanov | 68933fb | 2020-09-10 17:58:12 +0200 | [diff] [blame] | 326 | mOutput->setProjection(orientation, viewport, frame); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 327 | |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 328 | EXPECT_EQ(orientation, mOutput->getState().displaySpace.getOrientation()); |
| 329 | EXPECT_EQ(frame, mOutput->getState().orientedDisplaySpace.getContent()); |
| 330 | EXPECT_EQ(viewport, mOutput->getState().layerStackSpace.getContent()); |
Marin Shalamanov | 209ae61 | 2020-10-01 00:17:39 +0200 | [diff] [blame] | 331 | |
| 332 | const auto state = mOutput->getState(); |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 333 | EXPECT_EQ(ui::ROTATION_0, state.layerStackSpace.getOrientation()); |
| 334 | EXPECT_EQ(viewport, state.layerStackSpace.getContent()); |
| 335 | EXPECT_EQ(Rect(0, 0, 20, 20), state.layerStackSpace.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(ui::ROTATION_0, state.orientedDisplaySpace.getOrientation()); |
| 338 | EXPECT_EQ(frame, state.orientedDisplaySpace.getContent()); |
| 339 | EXPECT_EQ(Rect(0, 0, 2000, 1000), state.orientedDisplaySpace.getBoundsAsRect()); |
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.displaySpace.getBoundsAsRect()); |
| 342 | EXPECT_EQ(Rect(900, 50, 940, 100), state.displaySpace.getContent()); |
| 343 | EXPECT_EQ(orientation, state.displaySpace.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(displayRect, state.framebufferSpace.getBoundsAsRect()); |
| 346 | EXPECT_EQ(Rect(900, 50, 940, 100), state.framebufferSpace.getContent()); |
| 347 | EXPECT_EQ(orientation, state.framebufferSpace.getOrientation()); |
Marin Shalamanov | 209ae61 | 2020-10-01 00:17:39 +0200 | [diff] [blame] | 348 | |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 349 | EXPECT_EQ(state.displaySpace.getContent(), |
| 350 | state.transform.transform(state.layerStackSpace.getContent())); |
Garfield Tan | 54edd91 | 2020-10-21 16:31:41 -0700 | [diff] [blame] | 351 | |
| 352 | EXPECT_EQ(ui::Transform::ROT_90, mOutput->getTransformHint()); |
Marin Shalamanov | 209ae61 | 2020-10-01 00:17:39 +0200 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | TEST_F(OutputTest, setProjectionWithSmallFramebufferWorks) { |
| 356 | const Rect displayRect{0, 0, 1000, 2000}; |
| 357 | const Rect framebufferRect{0, 0, 500, 1000}; |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 358 | mOutput->editState().displaySpace.setBounds( |
| 359 | ui::Size(displayRect.getWidth(), displayRect.getHeight())); |
| 360 | mOutput->editState().framebufferSpace.setBounds( |
| 361 | ui::Size(framebufferRect.getWidth(), framebufferRect.getHeight())); |
Marin Shalamanov | 209ae61 | 2020-10-01 00:17:39 +0200 | [diff] [blame] | 362 | |
| 363 | const ui::Rotation orientation = ui::ROTATION_90; |
| 364 | const Rect frame{50, 60, 100, 100}; |
| 365 | const Rect viewport{10, 20, 30, 40}; |
| 366 | |
| 367 | mOutput->setProjection(orientation, viewport, frame); |
| 368 | |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 369 | EXPECT_EQ(orientation, mOutput->getState().displaySpace.getOrientation()); |
| 370 | EXPECT_EQ(frame, mOutput->getState().orientedDisplaySpace.getContent()); |
| 371 | EXPECT_EQ(viewport, mOutput->getState().layerStackSpace.getContent()); |
Marin Shalamanov | 209ae61 | 2020-10-01 00:17:39 +0200 | [diff] [blame] | 372 | |
| 373 | const auto state = mOutput->getState(); |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 374 | EXPECT_EQ(ui::ROTATION_0, state.layerStackSpace.getOrientation()); |
| 375 | EXPECT_EQ(viewport, state.layerStackSpace.getContent()); |
| 376 | EXPECT_EQ(Rect(0, 0, 20, 20), state.layerStackSpace.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(ui::ROTATION_0, state.orientedDisplaySpace.getOrientation()); |
| 379 | EXPECT_EQ(frame, state.orientedDisplaySpace.getContent()); |
| 380 | EXPECT_EQ(Rect(0, 0, 2000, 1000), state.orientedDisplaySpace.getBoundsAsRect()); |
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(displayRect, state.displaySpace.getBoundsAsRect()); |
| 383 | EXPECT_EQ(Rect(900, 50, 940, 100), state.displaySpace.getContent()); |
| 384 | EXPECT_EQ(orientation, state.displaySpace.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(framebufferRect, state.framebufferSpace.getBoundsAsRect()); |
| 387 | EXPECT_EQ(Rect(450, 25, 470, 50), state.framebufferSpace.getContent()); |
| 388 | EXPECT_EQ(orientation, state.framebufferSpace.getOrientation()); |
Marin Shalamanov | 209ae61 | 2020-10-01 00:17:39 +0200 | [diff] [blame] | 389 | |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 390 | EXPECT_EQ(state.displaySpace.getContent(), |
| 391 | state.transform.transform(state.layerStackSpace.getContent())); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 392 | } |
| 393 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 394 | /* |
Marin Shalamanov | b15d227 | 2020-09-17 21:41:52 +0200 | [diff] [blame] | 395 | * Output::setDisplaySize() |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 396 | */ |
| 397 | |
Marin Shalamanov | b15d227 | 2020-09-17 21:41:52 +0200 | [diff] [blame] | 398 | TEST_F(OutputTest, setDisplaySpaceSizeUpdatesOutputStateAndDirtiesEntireOutput) { |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 399 | mOutput->editState().layerStackSpace.setContent(Rect(0, 0, 2000, 1000)); |
| 400 | mOutput->editState().layerStackSpace.setBounds(ui::Size(2000, 1000)); |
| 401 | mOutput->editState().orientedDisplaySpace.setContent(Rect(0, 0, 1800, 900)); |
| 402 | mOutput->editState().orientedDisplaySpace.setBounds(ui::Size(2000, 1000)); |
| 403 | mOutput->editState().framebufferSpace.setContent(Rect(0, 0, 900, 1800)); |
| 404 | mOutput->editState().framebufferSpace.setBounds(ui::Size(1000, 2000)); |
| 405 | mOutput->editState().framebufferSpace.setOrientation(ui::ROTATION_90); |
| 406 | mOutput->editState().displaySpace.setContent(Rect(0, 0, 900, 1800)); |
| 407 | mOutput->editState().displaySpace.setBounds(ui::Size(1000, 2000)); |
| 408 | mOutput->editState().displaySpace.setOrientation(ui::ROTATION_90); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 409 | |
Marin Shalamanov | b15d227 | 2020-09-17 21:41:52 +0200 | [diff] [blame] | 410 | const ui::Size newDisplaySize{500, 1000}; |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 411 | |
Marin Shalamanov | b15d227 | 2020-09-17 21:41:52 +0200 | [diff] [blame] | 412 | EXPECT_CALL(*mRenderSurface, setDisplaySize(newDisplaySize)).Times(1); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 413 | |
Marin Shalamanov | b15d227 | 2020-09-17 21:41:52 +0200 | [diff] [blame] | 414 | mOutput->setDisplaySize(newDisplaySize); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 415 | |
Marin Shalamanov | b15d227 | 2020-09-17 21:41:52 +0200 | [diff] [blame] | 416 | const auto state = mOutput->getState(); |
| 417 | |
| 418 | const Rect displayRect(newDisplaySize); |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 419 | EXPECT_EQ(ui::ROTATION_0, state.layerStackSpace.getOrientation()); |
| 420 | EXPECT_EQ(Rect(0, 0, 2000, 1000), state.layerStackSpace.getContent()); |
| 421 | EXPECT_EQ(Rect(0, 0, 2000, 1000), state.layerStackSpace.getBoundsAsRect()); |
Marin Shalamanov | 209ae61 | 2020-10-01 00:17:39 +0200 | [diff] [blame] | 422 | |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 423 | EXPECT_EQ(ui::ROTATION_0, state.orientedDisplaySpace.getOrientation()); |
| 424 | EXPECT_EQ(Rect(0, 0, 1000, 500), state.orientedDisplaySpace.getBoundsAsRect()); |
Marin Shalamanov | 209ae61 | 2020-10-01 00:17:39 +0200 | [diff] [blame] | 425 | |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 426 | EXPECT_EQ(displayRect, state.displaySpace.getBoundsAsRect()); |
| 427 | EXPECT_EQ(ui::ROTATION_90, state.displaySpace.getOrientation()); |
Marin Shalamanov | 209ae61 | 2020-10-01 00:17:39 +0200 | [diff] [blame] | 428 | |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 429 | EXPECT_EQ(displayRect, state.framebufferSpace.getBoundsAsRect()); |
| 430 | EXPECT_EQ(ui::ROTATION_90, state.framebufferSpace.getOrientation()); |
Marin Shalamanov | b15d227 | 2020-09-17 21:41:52 +0200 | [diff] [blame] | 431 | |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 432 | EXPECT_EQ(state.displaySpace.getContent(), |
| 433 | state.transform.transform(state.layerStackSpace.getContent())); |
Marin Shalamanov | b15d227 | 2020-09-17 21:41:52 +0200 | [diff] [blame] | 434 | |
| 435 | EXPECT_THAT(state.dirtyRegion, RegionEq(Region(displayRect))); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 436 | } |
| 437 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 438 | /* |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 439 | * Output::setLayerFilter() |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 440 | */ |
| 441 | |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 442 | TEST_F(OutputTest, setLayerFilterSetsFilterAndDirtiesEntireOutput) { |
| 443 | constexpr ui::LayerFilter kFilter{ui::LayerStack{123u}, true}; |
| 444 | mOutput->setLayerFilter(kFilter); |
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 | const auto& state = mOutput->getState(); |
| 447 | EXPECT_EQ(kFilter.layerStack, state.layerFilter.layerStack); |
| 448 | EXPECT_TRUE(state.layerFilter.toInternalDisplay); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 449 | |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 450 | EXPECT_THAT(state.dirtyRegion, RegionEq(Region(kDefaultDisplaySize))); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 451 | } |
| 452 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 453 | /* |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 454 | * Output::setColorTransform |
| 455 | */ |
| 456 | |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 457 | TEST_F(OutputTest, setColorTransformWithNoChangeFlaggedSkipsUpdates) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 458 | mOutput->editState().colorTransformMatrix = kIdentity; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 459 | |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 460 | // If no colorTransformMatrix is set the update should be skipped. |
| 461 | CompositionRefreshArgs refreshArgs; |
| 462 | refreshArgs.colorTransformMatrix = std::nullopt; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 463 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 464 | mOutput->setColorTransform(refreshArgs); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 465 | |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 466 | // The internal state should be unchanged |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 467 | EXPECT_EQ(kIdentity, mOutput->getState().colorTransformMatrix); |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 468 | |
| 469 | // No dirty region should be set |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 470 | EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region())); |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 471 | } |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 472 | |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 473 | TEST_F(OutputTest, setColorTransformWithNoActualChangeSkipsUpdates) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 474 | mOutput->editState().colorTransformMatrix = kIdentity; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 475 | |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 476 | // Attempting to set the same colorTransformMatrix that is already set should |
| 477 | // also skip the update. |
| 478 | CompositionRefreshArgs refreshArgs; |
| 479 | refreshArgs.colorTransformMatrix = kIdentity; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 480 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 481 | mOutput->setColorTransform(refreshArgs); |
Lloyd Pique | 77f79a2 | 2019-04-29 15:55:40 -0700 | [diff] [blame] | 482 | |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 483 | // The internal state should be unchanged |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 484 | EXPECT_EQ(kIdentity, mOutput->getState().colorTransformMatrix); |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 485 | |
| 486 | // No dirty region should be set |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 487 | EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region())); |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 488 | } |
| 489 | |
| 490 | TEST_F(OutputTest, setColorTransformPerformsUpdateToIdentity) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 491 | mOutput->editState().colorTransformMatrix = kNonIdentityHalf; |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 492 | |
| 493 | // Setting a different colorTransformMatrix should perform the update. |
| 494 | CompositionRefreshArgs refreshArgs; |
| 495 | refreshArgs.colorTransformMatrix = kIdentity; |
| 496 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 497 | mOutput->setColorTransform(refreshArgs); |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 498 | |
| 499 | // The internal state should have been updated |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 500 | EXPECT_EQ(kIdentity, mOutput->getState().colorTransformMatrix); |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 501 | |
| 502 | // The dirtyRegion should be set to the full display size |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 503 | EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize))); |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 504 | } |
Lloyd Pique | 77f79a2 | 2019-04-29 15:55:40 -0700 | [diff] [blame] | 505 | |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 506 | TEST_F(OutputTest, setColorTransformPerformsUpdateForIdentityToHalf) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 507 | mOutput->editState().colorTransformMatrix = kIdentity; |
Lloyd Pique | 77f79a2 | 2019-04-29 15:55:40 -0700 | [diff] [blame] | 508 | |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 509 | // Setting a different colorTransformMatrix should perform the update. |
| 510 | CompositionRefreshArgs refreshArgs; |
| 511 | refreshArgs.colorTransformMatrix = kNonIdentityHalf; |
Lloyd Pique | 77f79a2 | 2019-04-29 15:55:40 -0700 | [diff] [blame] | 512 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 513 | mOutput->setColorTransform(refreshArgs); |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 514 | |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 515 | // The internal state should have been updated |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 516 | EXPECT_EQ(kNonIdentityHalf, mOutput->getState().colorTransformMatrix); |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 517 | |
| 518 | // The dirtyRegion should be set to the full display size |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 519 | EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize))); |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 520 | } |
| 521 | |
| 522 | TEST_F(OutputTest, setColorTransformPerformsUpdateForHalfToQuarter) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 523 | mOutput->editState().colorTransformMatrix = kNonIdentityHalf; |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 524 | |
| 525 | // Setting a different colorTransformMatrix should perform the update. |
| 526 | CompositionRefreshArgs refreshArgs; |
| 527 | refreshArgs.colorTransformMatrix = kNonIdentityQuarter; |
| 528 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 529 | mOutput->setColorTransform(refreshArgs); |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 530 | |
| 531 | // The internal state should have been updated |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 532 | EXPECT_EQ(kNonIdentityQuarter, mOutput->getState().colorTransformMatrix); |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 533 | |
| 534 | // The dirtyRegion should be set to the full display size |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 535 | EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize))); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 536 | } |
| 537 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 538 | /* |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 539 | * Output::setColorProfile |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 540 | */ |
| 541 | |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 542 | using OutputSetColorProfileTest = OutputTest; |
| 543 | |
| 544 | TEST_F(OutputSetColorProfileTest, setsStateAndDirtiesOutputIfChanged) { |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 545 | using ColorProfile = Output::ColorProfile; |
| 546 | |
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, |
Alec Mouri | 88790f3 | 2023-07-21 01:25:14 +0000 | [diff] [blame] | 550 | ui::RenderIntent::TONE_MAP_COLORIMETRIC}); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 551 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 552 | EXPECT_EQ(ui::ColorMode::DISPLAY_P3, mOutput->getState().colorMode); |
| 553 | EXPECT_EQ(ui::Dataspace::DISPLAY_P3, mOutput->getState().dataspace); |
| 554 | EXPECT_EQ(ui::RenderIntent::TONE_MAP_COLORIMETRIC, mOutput->getState().renderIntent); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 555 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 556 | EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize))); |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 557 | } |
| 558 | |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 559 | TEST_F(OutputSetColorProfileTest, doesNothingIfNoChange) { |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 560 | using ColorProfile = Output::ColorProfile; |
| 561 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 562 | mOutput->editState().colorMode = ui::ColorMode::DISPLAY_P3; |
| 563 | mOutput->editState().dataspace = ui::Dataspace::DISPLAY_P3; |
| 564 | mOutput->editState().renderIntent = ui::RenderIntent::TONE_MAP_COLORIMETRIC; |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 565 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 566 | mOutput->setColorProfile(ColorProfile{ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3, |
Alec Mouri | 88790f3 | 2023-07-21 01:25:14 +0000 | [diff] [blame] | 567 | ui::RenderIntent::TONE_MAP_COLORIMETRIC}); |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 568 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 569 | EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region())); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 570 | } |
| 571 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 572 | /* |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 573 | * Output::setRenderSurface() |
| 574 | */ |
| 575 | |
| 576 | TEST_F(OutputTest, setRenderSurfaceResetsBounds) { |
| 577 | const ui::Size newDisplaySize{640, 480}; |
| 578 | |
| 579 | mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>(); |
| 580 | EXPECT_CALL(*renderSurface, getSize()).WillOnce(ReturnRef(newDisplaySize)); |
| 581 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 582 | mOutput->setRenderSurface(std::unique_ptr<RenderSurface>(renderSurface)); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 583 | |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 584 | EXPECT_EQ(Rect(newDisplaySize), mOutput->getState().framebufferSpace.getBoundsAsRect()); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 585 | } |
| 586 | |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 587 | /** |
| 588 | * Output::setDisplayBrightness() |
| 589 | */ |
| 590 | |
| 591 | TEST_F(OutputTest, setNextBrightness) { |
| 592 | constexpr float kDisplayBrightness = 0.5f; |
| 593 | mOutput->setNextBrightness(kDisplayBrightness); |
| 594 | ASSERT_TRUE(mOutput->getState().displayBrightness.has_value()); |
| 595 | EXPECT_EQ(kDisplayBrightness, mOutput->getState().displayBrightness); |
| 596 | } |
| 597 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 598 | /* |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 599 | * Output::getDirtyRegion() |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 600 | */ |
| 601 | |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 602 | TEST_F(OutputTest, getDirtyRegion) { |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 603 | const Rect viewport{100, 200}; |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 604 | mOutput->editState().layerStackSpace.setContent(viewport); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 605 | mOutput->editState().dirtyRegion.set(50, 300); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 606 | |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 607 | // The dirty region should be clipped to the display bounds. |
| 608 | EXPECT_THAT(mOutput->getDirtyRegion(), RegionEq(Region(Rect(50, 200)))); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 609 | } |
| 610 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 611 | /* |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 612 | * Output::includesLayer() |
Lloyd Pique | ef36b00 | 2019-01-23 17:52:04 -0800 | [diff] [blame] | 613 | */ |
| 614 | |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 615 | TEST_F(OutputTest, layerFiltering) { |
| 616 | const ui::LayerStack layerStack1{123u}; |
| 617 | const ui::LayerStack layerStack2{456u}; |
Lloyd Pique | ef36b00 | 2019-01-23 17:52:04 -0800 | [diff] [blame] | 618 | |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 619 | // If the output is associated to layerStack1 and to an internal display... |
| 620 | mOutput->setLayerFilter({layerStack1, true}); |
Lloyd Pique | ef36b00 | 2019-01-23 17:52:04 -0800 | [diff] [blame] | 621 | |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 622 | // It excludes layers with no layer stack, internal-only or not. |
| 623 | EXPECT_FALSE(mOutput->includesLayer({ui::INVALID_LAYER_STACK, false})); |
| 624 | EXPECT_FALSE(mOutput->includesLayer({ui::INVALID_LAYER_STACK, true})); |
Lloyd Pique | c668734 | 2019-03-07 21:34:57 -0800 | [diff] [blame] | 625 | |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 626 | // It includes layers on layerStack1, internal-only or not. |
| 627 | EXPECT_TRUE(mOutput->includesLayer({layerStack1, false})); |
| 628 | EXPECT_TRUE(mOutput->includesLayer({layerStack1, true})); |
| 629 | EXPECT_FALSE(mOutput->includesLayer({layerStack2, true})); |
| 630 | EXPECT_FALSE(mOutput->includesLayer({layerStack2, false})); |
Lloyd Pique | ef36b00 | 2019-01-23 17:52:04 -0800 | [diff] [blame] | 631 | |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 632 | // If the output is associated to layerStack1 but not to an internal display... |
| 633 | mOutput->setLayerFilter({layerStack1, false}); |
Lloyd Pique | ef36b00 | 2019-01-23 17:52:04 -0800 | [diff] [blame] | 634 | |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 635 | // It includes layers on layerStack1, unless they are internal-only. |
| 636 | EXPECT_TRUE(mOutput->includesLayer({layerStack1, false})); |
| 637 | EXPECT_FALSE(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 | } |
| 641 | |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 642 | TEST_F(OutputTest, layerFilteringWithoutCompositionState) { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 643 | NonInjectedLayer layer; |
| 644 | sp<LayerFE> layerFE(layer.layerFE); |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 645 | |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 646 | // Layers without composition state are excluded. |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 647 | EXPECT_CALL(*layer.layerFE, getCompositionState).WillOnce(Return(nullptr)); |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 648 | EXPECT_FALSE(mOutput->includesLayer(layerFE)); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 649 | } |
| 650 | |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 651 | TEST_F(OutputTest, layerFilteringWithCompositionState) { |
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 | const ui::LayerStack layerStack1{123u}; |
| 656 | const ui::LayerStack layerStack2{456u}; |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 657 | |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 658 | // If the output is associated to layerStack1 and to an internal display... |
| 659 | mOutput->setLayerFilter({layerStack1, true}); |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 660 | |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 661 | // It excludes layers with no layer stack, internal-only or not. |
| 662 | layer.layerFEState.outputFilter = {ui::INVALID_LAYER_STACK, false}; |
| 663 | EXPECT_FALSE(mOutput->includesLayer(layerFE)); |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 664 | |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 665 | layer.layerFEState.outputFilter = {ui::INVALID_LAYER_STACK, true}; |
| 666 | EXPECT_FALSE(mOutput->includesLayer(layerFE)); |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 667 | |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 668 | // It includes layers on layerStack1, internal-only or not. |
| 669 | layer.layerFEState.outputFilter = {layerStack1, false}; |
| 670 | EXPECT_TRUE(mOutput->includesLayer(layerFE)); |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 671 | |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 672 | layer.layerFEState.outputFilter = {layerStack1, true}; |
| 673 | EXPECT_TRUE(mOutput->includesLayer(layerFE)); |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 674 | |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 675 | layer.layerFEState.outputFilter = {layerStack2, true}; |
| 676 | EXPECT_FALSE(mOutput->includesLayer(layerFE)); |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 677 | |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 678 | layer.layerFEState.outputFilter = {layerStack2, false}; |
| 679 | EXPECT_FALSE(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 | // If the output is associated to layerStack1 but not to an internal display... |
| 682 | mOutput->setLayerFilter({layerStack1, false}); |
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 | // It includes layers on layerStack1, unless they are internal-only. |
| 685 | layer.layerFEState.outputFilter = {layerStack1, false}; |
| 686 | EXPECT_TRUE(mOutput->includesLayer(layerFE)); |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 687 | |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 688 | layer.layerFEState.outputFilter = {layerStack1, true}; |
| 689 | EXPECT_FALSE(mOutput->includesLayer(layerFE)); |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 690 | |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 691 | layer.layerFEState.outputFilter = {layerStack2, true}; |
| 692 | EXPECT_FALSE(mOutput->includesLayer(layerFE)); |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 693 | |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 694 | layer.layerFEState.outputFilter = {layerStack2, false}; |
| 695 | EXPECT_FALSE(mOutput->includesLayer(layerFE)); |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 696 | } |
| 697 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 698 | /* |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 699 | * Output::getOutputLayerForLayer() |
| 700 | */ |
| 701 | |
| 702 | TEST_F(OutputTest, getOutputLayerForLayerWorks) { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 703 | InjectedLayer layer1; |
| 704 | InjectedLayer layer2; |
| 705 | NonInjectedLayer layer3; |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 706 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 707 | injectOutputLayer(layer1); |
| 708 | injectNullOutputLayer(); |
| 709 | injectOutputLayer(layer2); |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 710 | |
| 711 | // If the input layer matches the first OutputLayer, it will be returned. |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 712 | EXPECT_CALL(*layer1.outputLayer, getLayerFE()).WillOnce(ReturnRef(*layer1.layerFE.get())); |
| 713 | EXPECT_EQ(layer1.outputLayer, mOutput->getOutputLayerForLayer(layer1.layerFE)); |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 714 | |
| 715 | // If the input layer matches the second OutputLayer, it will be returned. |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 716 | EXPECT_CALL(*layer1.outputLayer, getLayerFE()).WillOnce(ReturnRef(*layer1.layerFE.get())); |
| 717 | EXPECT_CALL(*layer2.outputLayer, getLayerFE()).WillOnce(ReturnRef(*layer2.layerFE.get())); |
| 718 | EXPECT_EQ(layer2.outputLayer, mOutput->getOutputLayerForLayer(layer2.layerFE)); |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 719 | |
| 720 | // 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] | 721 | EXPECT_CALL(*layer1.outputLayer, getLayerFE()).WillOnce(ReturnRef(*layer1.layerFE.get())); |
| 722 | EXPECT_CALL(*layer2.outputLayer, getLayerFE()).WillOnce(ReturnRef(*layer2.layerFE.get())); |
| 723 | EXPECT_EQ(nullptr, mOutput->getOutputLayerForLayer(layer3.layerFE)); |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 724 | } |
| 725 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 726 | /* |
Lloyd Pique | c9e6003 | 2019-11-14 11:47:26 -0800 | [diff] [blame] | 727 | * Output::setReleasedLayers() |
| 728 | */ |
| 729 | |
| 730 | using OutputSetReleasedLayersTest = OutputTest; |
| 731 | |
| 732 | TEST_F(OutputSetReleasedLayersTest, setReleasedLayersTakesGivenLayers) { |
Ady Abraham | e0eafa8 | 2022-02-02 19:30:47 -0800 | [diff] [blame] | 733 | sp<StrictMock<mock::LayerFE>> layer1FE = sp<StrictMock<mock::LayerFE>>::make(); |
| 734 | sp<StrictMock<mock::LayerFE>> layer2FE = sp<StrictMock<mock::LayerFE>>::make(); |
| 735 | sp<StrictMock<mock::LayerFE>> layer3FE = sp<StrictMock<mock::LayerFE>>::make(); |
Lloyd Pique | c9e6003 | 2019-11-14 11:47:26 -0800 | [diff] [blame] | 736 | |
| 737 | Output::ReleasedLayers layers; |
| 738 | layers.push_back(layer1FE); |
| 739 | layers.push_back(layer2FE); |
| 740 | layers.push_back(layer3FE); |
| 741 | |
| 742 | mOutput->setReleasedLayers(std::move(layers)); |
| 743 | |
| 744 | const auto& setLayers = mOutput->getReleasedLayersForTest(); |
| 745 | ASSERT_EQ(3u, setLayers.size()); |
| 746 | ASSERT_EQ(layer1FE.get(), setLayers[0].promote().get()); |
| 747 | ASSERT_EQ(layer2FE.get(), setLayers[1].promote().get()); |
| 748 | ASSERT_EQ(layer3FE.get(), setLayers[2].promote().get()); |
| 749 | } |
| 750 | |
| 751 | /* |
Alec Mouri | f9a2a2c | 2019-11-12 12:46:02 -0800 | [diff] [blame] | 752 | * Output::updateAndWriteCompositionState() |
| 753 | */ |
| 754 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 755 | using OutputUpdateAndWriteCompositionStateTest = OutputTest; |
Lloyd Pique | ef63b61 | 2019-11-14 13:19:56 -0800 | [diff] [blame] | 756 | |
| 757 | TEST_F(OutputUpdateAndWriteCompositionStateTest, doesNothingIfLayers) { |
| 758 | mOutput->editState().isEnabled = true; |
Alec Mouri | f9a2a2c | 2019-11-12 12:46:02 -0800 | [diff] [blame] | 759 | |
| 760 | CompositionRefreshArgs args; |
Dan Stoza | 269dc4d | 2021-01-15 15:07:43 -0800 | [diff] [blame] | 761 | mOutput->updateCompositionState(args); |
| 762 | mOutput->planComposition(); |
| 763 | mOutput->writeCompositionState(args); |
Alec Mouri | f9a2a2c | 2019-11-12 12:46:02 -0800 | [diff] [blame] | 764 | } |
| 765 | |
Lloyd Pique | ef63b61 | 2019-11-14 13:19:56 -0800 | [diff] [blame] | 766 | TEST_F(OutputUpdateAndWriteCompositionStateTest, doesNothingIfOutputNotEnabled) { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 767 | InjectedLayer layer1; |
| 768 | InjectedLayer layer2; |
| 769 | InjectedLayer layer3; |
| 770 | |
Lloyd Pique | ef63b61 | 2019-11-14 13:19:56 -0800 | [diff] [blame] | 771 | mOutput->editState().isEnabled = false; |
Alec Mouri | f9a2a2c | 2019-11-12 12:46:02 -0800 | [diff] [blame] | 772 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 773 | injectOutputLayer(layer1); |
| 774 | injectOutputLayer(layer2); |
| 775 | injectOutputLayer(layer3); |
Lloyd Pique | ef63b61 | 2019-11-14 13:19:56 -0800 | [diff] [blame] | 776 | |
| 777 | CompositionRefreshArgs args; |
Dan Stoza | 269dc4d | 2021-01-15 15:07:43 -0800 | [diff] [blame] | 778 | mOutput->updateCompositionState(args); |
| 779 | mOutput->planComposition(); |
| 780 | mOutput->writeCompositionState(args); |
Lloyd Pique | ef63b61 | 2019-11-14 13:19:56 -0800 | [diff] [blame] | 781 | } |
| 782 | |
| 783 | TEST_F(OutputUpdateAndWriteCompositionStateTest, updatesLayerContentForAllLayers) { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 784 | InjectedLayer layer1; |
| 785 | InjectedLayer layer2; |
| 786 | InjectedLayer layer3; |
Lloyd Pique | ef63b61 | 2019-11-14 13:19:56 -0800 | [diff] [blame] | 787 | |
Leon Scroggins III | e2ee040 | 2021-04-02 16:59:37 -0400 | [diff] [blame] | 788 | uint32_t z = 0; |
Snild Dolkow | 9e217d6 | 2020-04-22 15:53:42 +0200 | [diff] [blame] | 789 | EXPECT_CALL(*layer1.outputLayer, updateCompositionState(false, false, ui::Transform::ROT_180)); |
Dan Stoza | 6166c31 | 2021-01-15 16:34:05 -0800 | [diff] [blame] | 790 | EXPECT_CALL(*layer1.outputLayer, |
Leon Scroggins III | 9aa25c2 | 2021-04-15 15:30:19 -0400 | [diff] [blame] | 791 | writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, z++, |
| 792 | /*zIsOverridden*/ false, /*isPeekingThrough*/ false)); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 793 | EXPECT_CALL(*layer1.outputLayer, requiresClientComposition()).WillRepeatedly(Return(false)); |
Snild Dolkow | 9e217d6 | 2020-04-22 15:53:42 +0200 | [diff] [blame] | 794 | EXPECT_CALL(*layer2.outputLayer, updateCompositionState(false, false, ui::Transform::ROT_180)); |
Dan Stoza | 6166c31 | 2021-01-15 16:34:05 -0800 | [diff] [blame] | 795 | EXPECT_CALL(*layer2.outputLayer, |
Leon Scroggins III | 9aa25c2 | 2021-04-15 15:30:19 -0400 | [diff] [blame] | 796 | writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, z++, |
| 797 | /*zIsOverridden*/ false, /*isPeekingThrough*/ false)); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 798 | EXPECT_CALL(*layer2.outputLayer, requiresClientComposition()).WillRepeatedly(Return(false)); |
Snild Dolkow | 9e217d6 | 2020-04-22 15:53:42 +0200 | [diff] [blame] | 799 | EXPECT_CALL(*layer3.outputLayer, updateCompositionState(false, false, ui::Transform::ROT_180)); |
Dan Stoza | 6166c31 | 2021-01-15 16:34:05 -0800 | [diff] [blame] | 800 | EXPECT_CALL(*layer3.outputLayer, |
Leon Scroggins III | 9aa25c2 | 2021-04-15 15:30:19 -0400 | [diff] [blame] | 801 | writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, z++, |
| 802 | /*zIsOverridden*/ false, /*isPeekingThrough*/ false)); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 803 | EXPECT_CALL(*layer3.outputLayer, requiresClientComposition()).WillRepeatedly(Return(false)); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 804 | |
| 805 | injectOutputLayer(layer1); |
| 806 | injectOutputLayer(layer2); |
| 807 | injectOutputLayer(layer3); |
Lloyd Pique | ef63b61 | 2019-11-14 13:19:56 -0800 | [diff] [blame] | 808 | |
| 809 | mOutput->editState().isEnabled = true; |
| 810 | |
| 811 | CompositionRefreshArgs args; |
| 812 | args.updatingGeometryThisFrame = false; |
| 813 | args.devOptForceClientComposition = false; |
Snild Dolkow | 9e217d6 | 2020-04-22 15:53:42 +0200 | [diff] [blame] | 814 | args.internalDisplayRotationFlags = ui::Transform::ROT_180; |
Dan Stoza | 269dc4d | 2021-01-15 15:07:43 -0800 | [diff] [blame] | 815 | mOutput->updateCompositionState(args); |
| 816 | mOutput->planComposition(); |
| 817 | mOutput->writeCompositionState(args); |
Lloyd Pique | ef63b61 | 2019-11-14 13:19:56 -0800 | [diff] [blame] | 818 | } |
| 819 | |
| 820 | TEST_F(OutputUpdateAndWriteCompositionStateTest, updatesLayerGeometryAndContentForAllLayers) { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 821 | InjectedLayer layer1; |
| 822 | InjectedLayer layer2; |
| 823 | InjectedLayer layer3; |
Lloyd Pique | ef63b61 | 2019-11-14 13:19:56 -0800 | [diff] [blame] | 824 | |
Leon Scroggins III | e2ee040 | 2021-04-02 16:59:37 -0400 | [diff] [blame] | 825 | uint32_t z = 0; |
Snild Dolkow | 9e217d6 | 2020-04-22 15:53:42 +0200 | [diff] [blame] | 826 | EXPECT_CALL(*layer1.outputLayer, updateCompositionState(true, false, ui::Transform::ROT_0)); |
Dan Stoza | 6166c31 | 2021-01-15 16:34:05 -0800 | [diff] [blame] | 827 | EXPECT_CALL(*layer1.outputLayer, |
Leon Scroggins III | 9aa25c2 | 2021-04-15 15:30:19 -0400 | [diff] [blame] | 828 | writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, z++, |
| 829 | /*zIsOverridden*/ false, /*isPeekingThrough*/ false)); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 830 | EXPECT_CALL(*layer1.outputLayer, requiresClientComposition()).WillRepeatedly(Return(false)); |
Snild Dolkow | 9e217d6 | 2020-04-22 15:53:42 +0200 | [diff] [blame] | 831 | EXPECT_CALL(*layer2.outputLayer, updateCompositionState(true, false, ui::Transform::ROT_0)); |
Dan Stoza | 6166c31 | 2021-01-15 16:34:05 -0800 | [diff] [blame] | 832 | EXPECT_CALL(*layer2.outputLayer, |
Leon Scroggins III | 9aa25c2 | 2021-04-15 15:30:19 -0400 | [diff] [blame] | 833 | writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, z++, |
| 834 | /*zIsOverridden*/ false, /*isPeekingThrough*/ false)); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 835 | EXPECT_CALL(*layer2.outputLayer, requiresClientComposition()).WillRepeatedly(Return(false)); |
Snild Dolkow | 9e217d6 | 2020-04-22 15:53:42 +0200 | [diff] [blame] | 836 | EXPECT_CALL(*layer3.outputLayer, updateCompositionState(true, false, ui::Transform::ROT_0)); |
Dan Stoza | 6166c31 | 2021-01-15 16:34:05 -0800 | [diff] [blame] | 837 | EXPECT_CALL(*layer3.outputLayer, |
Leon Scroggins III | 9aa25c2 | 2021-04-15 15:30:19 -0400 | [diff] [blame] | 838 | writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, z++, |
| 839 | /*zIsOverridden*/ false, /*isPeekingThrough*/ false)); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 840 | EXPECT_CALL(*layer3.outputLayer, requiresClientComposition()).WillRepeatedly(Return(false)); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 841 | |
| 842 | injectOutputLayer(layer1); |
| 843 | injectOutputLayer(layer2); |
| 844 | injectOutputLayer(layer3); |
Lloyd Pique | ef63b61 | 2019-11-14 13:19:56 -0800 | [diff] [blame] | 845 | |
| 846 | mOutput->editState().isEnabled = true; |
Alec Mouri | f9a2a2c | 2019-11-12 12:46:02 -0800 | [diff] [blame] | 847 | |
| 848 | CompositionRefreshArgs args; |
| 849 | args.updatingGeometryThisFrame = true; |
Lloyd Pique | ef63b61 | 2019-11-14 13:19:56 -0800 | [diff] [blame] | 850 | args.devOptForceClientComposition = false; |
Dan Stoza | 269dc4d | 2021-01-15 15:07:43 -0800 | [diff] [blame] | 851 | mOutput->updateCompositionState(args); |
| 852 | mOutput->planComposition(); |
| 853 | mOutput->writeCompositionState(args); |
Lloyd Pique | ef63b61 | 2019-11-14 13:19:56 -0800 | [diff] [blame] | 854 | } |
| 855 | |
| 856 | TEST_F(OutputUpdateAndWriteCompositionStateTest, forcesClientCompositionForAllLayers) { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 857 | InjectedLayer layer1; |
| 858 | InjectedLayer layer2; |
| 859 | InjectedLayer layer3; |
Lloyd Pique | ef63b61 | 2019-11-14 13:19:56 -0800 | [diff] [blame] | 860 | |
Leon Scroggins III | e2ee040 | 2021-04-02 16:59:37 -0400 | [diff] [blame] | 861 | uint32_t z = 0; |
Snild Dolkow | 9e217d6 | 2020-04-22 15:53:42 +0200 | [diff] [blame] | 862 | EXPECT_CALL(*layer1.outputLayer, updateCompositionState(false, true, ui::Transform::ROT_0)); |
Dan Stoza | 6166c31 | 2021-01-15 16:34:05 -0800 | [diff] [blame] | 863 | EXPECT_CALL(*layer1.outputLayer, |
Leon Scroggins III | 9aa25c2 | 2021-04-15 15:30:19 -0400 | [diff] [blame] | 864 | writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, z++, |
| 865 | /*zIsOverridden*/ false, /*isPeekingThrough*/ false)); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 866 | EXPECT_CALL(*layer1.outputLayer, requiresClientComposition()).WillRepeatedly(Return(false)); |
Snild Dolkow | 9e217d6 | 2020-04-22 15:53:42 +0200 | [diff] [blame] | 867 | EXPECT_CALL(*layer2.outputLayer, updateCompositionState(false, true, ui::Transform::ROT_0)); |
Dan Stoza | 6166c31 | 2021-01-15 16:34:05 -0800 | [diff] [blame] | 868 | EXPECT_CALL(*layer2.outputLayer, |
Leon Scroggins III | 9aa25c2 | 2021-04-15 15:30:19 -0400 | [diff] [blame] | 869 | writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, z++, |
| 870 | /*zIsOverridden*/ false, /*isPeekingThrough*/ false)); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 871 | EXPECT_CALL(*layer2.outputLayer, requiresClientComposition()).WillRepeatedly(Return(false)); |
Snild Dolkow | 9e217d6 | 2020-04-22 15:53:42 +0200 | [diff] [blame] | 872 | EXPECT_CALL(*layer3.outputLayer, updateCompositionState(false, true, ui::Transform::ROT_0)); |
Dan Stoza | 6166c31 | 2021-01-15 16:34:05 -0800 | [diff] [blame] | 873 | EXPECT_CALL(*layer3.outputLayer, |
Leon Scroggins III | 9aa25c2 | 2021-04-15 15:30:19 -0400 | [diff] [blame] | 874 | writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, z++, |
| 875 | /*zIsOverridden*/ false, /*isPeekingThrough*/ false)); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 876 | EXPECT_CALL(*layer3.outputLayer, requiresClientComposition()).WillRepeatedly(Return(false)); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 877 | |
| 878 | injectOutputLayer(layer1); |
| 879 | injectOutputLayer(layer2); |
| 880 | injectOutputLayer(layer3); |
Lloyd Pique | ef63b61 | 2019-11-14 13:19:56 -0800 | [diff] [blame] | 881 | |
| 882 | mOutput->editState().isEnabled = true; |
| 883 | |
| 884 | CompositionRefreshArgs args; |
| 885 | args.updatingGeometryThisFrame = false; |
Alec Mouri | f9a2a2c | 2019-11-12 12:46:02 -0800 | [diff] [blame] | 886 | args.devOptForceClientComposition = true; |
Dan Stoza | 269dc4d | 2021-01-15 15:07:43 -0800 | [diff] [blame] | 887 | mOutput->updateCompositionState(args); |
| 888 | mOutput->planComposition(); |
| 889 | mOutput->writeCompositionState(args); |
Alec Mouri | f9a2a2c | 2019-11-12 12:46:02 -0800 | [diff] [blame] | 890 | } |
| 891 | |
Leon Scroggins III | 2e74a4c | 2021-04-09 13:41:14 -0400 | [diff] [blame] | 892 | TEST_F(OutputUpdateAndWriteCompositionStateTest, peekThroughLayerChangesOrder) { |
| 893 | renderengine::mock::RenderEngine renderEngine; |
| 894 | InjectedLayer layer0; |
| 895 | InjectedLayer layer1; |
| 896 | InjectedLayer layer2; |
| 897 | InjectedLayer layer3; |
| 898 | |
| 899 | InSequence seq; |
| 900 | EXPECT_CALL(*layer0.outputLayer, updateCompositionState(true, false, ui::Transform::ROT_0)); |
| 901 | EXPECT_CALL(*layer1.outputLayer, updateCompositionState(true, false, ui::Transform::ROT_0)); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 902 | EXPECT_CALL(*layer1.outputLayer, requiresClientComposition()).WillRepeatedly(Return(false)); |
Leon Scroggins III | 2e74a4c | 2021-04-09 13:41:14 -0400 | [diff] [blame] | 903 | EXPECT_CALL(*layer2.outputLayer, updateCompositionState(true, false, ui::Transform::ROT_0)); |
| 904 | EXPECT_CALL(*layer3.outputLayer, updateCompositionState(true, false, ui::Transform::ROT_0)); |
| 905 | |
| 906 | uint32_t z = 0; |
| 907 | EXPECT_CALL(*layer0.outputLayer, |
| 908 | writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, z++, |
| 909 | /*zIsOverridden*/ false, /*isPeekingThrough*/ false)); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 910 | EXPECT_CALL(*layer0.outputLayer, requiresClientComposition()).WillRepeatedly(Return(false)); |
Leon Scroggins III | 2e74a4c | 2021-04-09 13:41:14 -0400 | [diff] [blame] | 911 | |
| 912 | // After calling planComposition (which clears overrideInfo), this test sets |
| 913 | // layer3 to be the peekThroughLayer for layer1 and layer2. As a result, it |
| 914 | // comes first, setting isPeekingThrough to true and zIsOverridden to true |
| 915 | // for it and the following layers. |
| 916 | EXPECT_CALL(*layer3.outputLayer, |
| 917 | writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, z++, |
| 918 | /*zIsOverridden*/ true, /*isPeekingThrough*/ |
| 919 | true)); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 920 | EXPECT_CALL(*layer3.outputLayer, requiresClientComposition()).WillRepeatedly(Return(false)); |
Leon Scroggins III | 2e74a4c | 2021-04-09 13:41:14 -0400 | [diff] [blame] | 921 | EXPECT_CALL(*layer1.outputLayer, |
| 922 | writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, z++, |
| 923 | /*zIsOverridden*/ true, /*isPeekingThrough*/ false)); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 924 | EXPECT_CALL(*layer1.outputLayer, requiresClientComposition()).WillRepeatedly(Return(false)); |
Leon Scroggins III | 2e74a4c | 2021-04-09 13:41:14 -0400 | [diff] [blame] | 925 | EXPECT_CALL(*layer2.outputLayer, |
| 926 | writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ true, z++, |
| 927 | /*zIsOverridden*/ true, /*isPeekingThrough*/ false)); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 928 | EXPECT_CALL(*layer2.outputLayer, requiresClientComposition()).WillRepeatedly(Return(false)); |
Leon Scroggins III | 2e74a4c | 2021-04-09 13:41:14 -0400 | [diff] [blame] | 929 | |
| 930 | injectOutputLayer(layer0); |
| 931 | injectOutputLayer(layer1); |
| 932 | injectOutputLayer(layer2); |
| 933 | injectOutputLayer(layer3); |
| 934 | |
| 935 | mOutput->editState().isEnabled = true; |
| 936 | |
| 937 | CompositionRefreshArgs args; |
| 938 | args.updatingGeometryThisFrame = true; |
| 939 | args.devOptForceClientComposition = false; |
| 940 | mOutput->updateCompositionState(args); |
| 941 | mOutput->planComposition(); |
| 942 | |
| 943 | std::shared_ptr<renderengine::ExternalTexture> buffer = std::make_shared< |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 944 | renderengine::impl:: |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 945 | ExternalTexture>(sp<GraphicBuffer>::make(), renderEngine, |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 946 | renderengine::impl::ExternalTexture::Usage::READABLE | |
| 947 | renderengine::impl::ExternalTexture::Usage::WRITEABLE); |
Leon Scroggins III | 2e74a4c | 2021-04-09 13:41:14 -0400 | [diff] [blame] | 948 | layer1.outputLayerState.overrideInfo.buffer = buffer; |
| 949 | layer2.outputLayerState.overrideInfo.buffer = buffer; |
| 950 | layer1.outputLayerState.overrideInfo.peekThroughLayer = layer3.outputLayer; |
| 951 | layer2.outputLayerState.overrideInfo.peekThroughLayer = layer3.outputLayer; |
| 952 | |
| 953 | mOutput->writeCompositionState(args); |
| 954 | } |
| 955 | |
Alec Mouri | f9a2a2c | 2019-11-12 12:46:02 -0800 | [diff] [blame] | 956 | /* |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 957 | * Output::prepareFrame() |
| 958 | */ |
| 959 | |
| 960 | struct OutputPrepareFrameTest : public testing::Test { |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 961 | struct OutputPartialMock : public OutputPartialMockBase { |
Lloyd Pique | 739afaf | 2019-11-21 16:40:05 -0800 | [diff] [blame] | 962 | // Sets up the helper functions called by the function under test to use |
| 963 | // mock implementations. |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 964 | MOCK_METHOD1(chooseCompositionStrategy, |
| 965 | bool(std::optional<android::HWComposer::DeviceRequestedChanges>*)); |
| 966 | MOCK_METHOD0(resetCompositionStrategy, void()); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 967 | }; |
| 968 | |
| 969 | OutputPrepareFrameTest() { |
| 970 | mOutput.setDisplayColorProfileForTest( |
| 971 | std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile)); |
| 972 | mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface)); |
| 973 | } |
| 974 | |
| 975 | StrictMock<mock::CompositionEngine> mCompositionEngine; |
| 976 | mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>(); |
| 977 | mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>(); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 978 | StrictMock<OutputPartialMock> mOutput; |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 979 | }; |
| 980 | |
| 981 | TEST_F(OutputPrepareFrameTest, takesEarlyOutIfNotEnabled) { |
| 982 | mOutput.editState().isEnabled = false; |
| 983 | |
| 984 | mOutput.prepareFrame(); |
| 985 | } |
| 986 | |
| 987 | TEST_F(OutputPrepareFrameTest, delegatesToChooseCompositionStrategyAndRenderSurface) { |
| 988 | mOutput.editState().isEnabled = true; |
| 989 | mOutput.editState().usesClientComposition = false; |
| 990 | mOutput.editState().usesDeviceComposition = true; |
| 991 | |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 992 | EXPECT_CALL(mOutput, chooseCompositionStrategy(_)).WillRepeatedly(Return(true)); |
| 993 | EXPECT_CALL(mOutput, resetCompositionStrategy()).Times(1); |
Alec Mouri | 023c188 | 2021-05-08 16:36:33 -0700 | [diff] [blame] | 994 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(0u)); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 995 | EXPECT_CALL(*mRenderSurface, prepareFrame(false, true)); |
| 996 | |
| 997 | mOutput.prepareFrame(); |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 998 | EXPECT_EQ(mOutput.getState().strategyPrediction, CompositionStrategyPredictionState::DISABLED); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 999 | } |
| 1000 | |
| 1001 | // Note: Use OutputTest and not OutputPrepareFrameTest, so the real |
| 1002 | // base chooseCompositionStrategy() is invoked. |
| 1003 | TEST_F(OutputTest, prepareFrameSetsClientCompositionOnlyByDefault) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 1004 | mOutput->editState().isEnabled = true; |
| 1005 | mOutput->editState().usesClientComposition = false; |
| 1006 | mOutput->editState().usesDeviceComposition = true; |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 1007 | |
| 1008 | EXPECT_CALL(*mRenderSurface, prepareFrame(true, false)); |
| 1009 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 1010 | mOutput->prepareFrame(); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 1011 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 1012 | EXPECT_TRUE(mOutput->getState().usesClientComposition); |
| 1013 | EXPECT_FALSE(mOutput->getState().usesDeviceComposition); |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 1014 | EXPECT_EQ(mOutput->getState().strategyPrediction, CompositionStrategyPredictionState::DISABLED); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 1015 | } |
| 1016 | |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 1017 | struct OutputPrepareFrameAsyncTest : public testing::Test { |
| 1018 | struct OutputPartialMock : public OutputPartialMockBase { |
| 1019 | // Sets up the helper functions called by the function under test to use |
| 1020 | // mock implementations. |
| 1021 | MOCK_METHOD1(chooseCompositionStrategy, |
| 1022 | bool(std::optional<android::HWComposer::DeviceRequestedChanges>*)); |
| 1023 | MOCK_METHOD0(updateProtectedContentState, void()); |
| 1024 | MOCK_METHOD2(dequeueRenderBuffer, |
| 1025 | bool(base::unique_fd*, std::shared_ptr<renderengine::ExternalTexture>*)); |
| 1026 | MOCK_METHOD1( |
| 1027 | chooseCompositionStrategyAsync, |
| 1028 | std::future<bool>(std::optional<android::HWComposer::DeviceRequestedChanges>*)); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 1029 | MOCK_METHOD3(composeSurfaces, |
| 1030 | std::optional<base::unique_fd>(const Region&, |
| 1031 | std::shared_ptr<renderengine::ExternalTexture>, |
| 1032 | base::unique_fd&)); |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 1033 | MOCK_METHOD0(resetCompositionStrategy, void()); |
| 1034 | }; |
| 1035 | |
| 1036 | OutputPrepareFrameAsyncTest() { |
| 1037 | mOutput.setDisplayColorProfileForTest( |
| 1038 | std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile)); |
| 1039 | mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface)); |
| 1040 | } |
| 1041 | |
| 1042 | StrictMock<mock::CompositionEngine> mCompositionEngine; |
| 1043 | mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>(); |
| 1044 | mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>(); |
| 1045 | StrictMock<OutputPartialMock> mOutput; |
| 1046 | CompositionRefreshArgs mRefreshArgs; |
| 1047 | }; |
| 1048 | |
| 1049 | TEST_F(OutputPrepareFrameAsyncTest, delegatesToChooseCompositionStrategyAndRenderSurface) { |
| 1050 | mOutput.editState().isEnabled = true; |
| 1051 | mOutput.editState().usesClientComposition = false; |
| 1052 | mOutput.editState().usesDeviceComposition = true; |
| 1053 | mOutput.editState().previousDeviceRequestedChanges = |
| 1054 | std::make_optional<android::HWComposer::DeviceRequestedChanges>({}); |
| 1055 | std::promise<bool> p; |
| 1056 | p.set_value(true); |
| 1057 | |
| 1058 | EXPECT_CALL(mOutput, resetCompositionStrategy()).Times(1); |
| 1059 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(0u)); |
| 1060 | EXPECT_CALL(mOutput, updateProtectedContentState()); |
| 1061 | EXPECT_CALL(mOutput, dequeueRenderBuffer(_, _)).WillOnce(Return(true)); |
| 1062 | EXPECT_CALL(*mRenderSurface, prepareFrame(false, true)).Times(1); |
| 1063 | EXPECT_CALL(mOutput, chooseCompositionStrategyAsync(_)) |
| 1064 | .WillOnce(DoAll(SetArgPointee<0>(mOutput.editState().previousDeviceRequestedChanges), |
| 1065 | Return(ByMove(p.get_future())))); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 1066 | EXPECT_CALL(mOutput, composeSurfaces(_, _, _)); |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 1067 | |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 1068 | impl::GpuCompositionResult result = mOutput.prepareFrameAsync(); |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 1069 | EXPECT_EQ(mOutput.getState().strategyPrediction, CompositionStrategyPredictionState::SUCCESS); |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 1070 | EXPECT_FALSE(result.bufferAvailable()); |
| 1071 | } |
| 1072 | |
| 1073 | TEST_F(OutputPrepareFrameAsyncTest, skipCompositionOnDequeueFailure) { |
| 1074 | mOutput.editState().isEnabled = true; |
| 1075 | mOutput.editState().usesClientComposition = false; |
| 1076 | mOutput.editState().usesDeviceComposition = true; |
| 1077 | mOutput.editState().previousDeviceRequestedChanges = |
| 1078 | std::make_optional<android::HWComposer::DeviceRequestedChanges>({}); |
| 1079 | std::promise<bool> p; |
| 1080 | p.set_value(true); |
| 1081 | |
| 1082 | EXPECT_CALL(mOutput, resetCompositionStrategy()).Times(2); |
| 1083 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(0u)); |
| 1084 | EXPECT_CALL(mOutput, updateProtectedContentState()); |
| 1085 | EXPECT_CALL(mOutput, dequeueRenderBuffer(_, _)).WillOnce(Return(false)); |
| 1086 | EXPECT_CALL(*mRenderSurface, prepareFrame(false, true)).Times(2); |
| 1087 | EXPECT_CALL(mOutput, chooseCompositionStrategyAsync(_)) |
| 1088 | .WillOnce(DoAll(SetArgPointee<0>(mOutput.editState().previousDeviceRequestedChanges), |
| 1089 | Return(ByMove(p.get_future())))); |
| 1090 | |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 1091 | impl::GpuCompositionResult result = mOutput.prepareFrameAsync(); |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 1092 | EXPECT_EQ(mOutput.getState().strategyPrediction, CompositionStrategyPredictionState::FAIL); |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 1093 | EXPECT_FALSE(result.bufferAvailable()); |
| 1094 | } |
| 1095 | |
| 1096 | // Tests that in the event of hwc error when choosing composition strategy, we would fall back |
| 1097 | // client composition |
| 1098 | TEST_F(OutputPrepareFrameAsyncTest, chooseCompositionStrategyFailureCallsPrepareFrame) { |
| 1099 | mOutput.editState().isEnabled = true; |
| 1100 | mOutput.editState().usesClientComposition = false; |
| 1101 | mOutput.editState().usesDeviceComposition = true; |
| 1102 | mOutput.editState().previousDeviceRequestedChanges = |
| 1103 | std::make_optional<android::HWComposer::DeviceRequestedChanges>({}); |
| 1104 | std::promise<bool> p; |
| 1105 | p.set_value(false); |
| 1106 | std::shared_ptr<renderengine::ExternalTexture> tex = |
| 1107 | std::make_shared<renderengine::mock::FakeExternalTexture>(1, 1, |
| 1108 | HAL_PIXEL_FORMAT_RGBA_8888, 1, |
| 1109 | 2); |
| 1110 | EXPECT_CALL(mOutput, resetCompositionStrategy()).Times(2); |
| 1111 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(0u)); |
| 1112 | EXPECT_CALL(mOutput, updateProtectedContentState()); |
| 1113 | EXPECT_CALL(mOutput, dequeueRenderBuffer(_, _)) |
| 1114 | .WillOnce(DoAll(SetArgPointee<1>(tex), Return(true))); |
| 1115 | EXPECT_CALL(*mRenderSurface, prepareFrame(false, true)).Times(2); |
| 1116 | EXPECT_CALL(mOutput, chooseCompositionStrategyAsync(_)).WillOnce([&] { |
| 1117 | return p.get_future(); |
| 1118 | }); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 1119 | EXPECT_CALL(mOutput, composeSurfaces(_, _, _)); |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 1120 | |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 1121 | impl::GpuCompositionResult result = mOutput.prepareFrameAsync(); |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 1122 | EXPECT_EQ(mOutput.getState().strategyPrediction, CompositionStrategyPredictionState::FAIL); |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 1123 | EXPECT_TRUE(result.bufferAvailable()); |
| 1124 | } |
| 1125 | |
| 1126 | TEST_F(OutputPrepareFrameAsyncTest, predictionMiss) { |
| 1127 | mOutput.editState().isEnabled = true; |
| 1128 | mOutput.editState().usesClientComposition = false; |
| 1129 | mOutput.editState().usesDeviceComposition = true; |
| 1130 | mOutput.editState().previousDeviceRequestedChanges = |
| 1131 | std::make_optional<android::HWComposer::DeviceRequestedChanges>({}); |
| 1132 | auto newDeviceRequestedChanges = |
| 1133 | std::make_optional<android::HWComposer::DeviceRequestedChanges>({}); |
| 1134 | newDeviceRequestedChanges->displayRequests = static_cast<hal::DisplayRequest>(0); |
| 1135 | std::promise<bool> p; |
| 1136 | p.set_value(false); |
| 1137 | std::shared_ptr<renderengine::ExternalTexture> tex = |
| 1138 | std::make_shared<renderengine::mock::FakeExternalTexture>(1, 1, |
| 1139 | HAL_PIXEL_FORMAT_RGBA_8888, 1, |
| 1140 | 2); |
| 1141 | |
| 1142 | EXPECT_CALL(mOutput, resetCompositionStrategy()).Times(2); |
| 1143 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(0u)); |
| 1144 | EXPECT_CALL(mOutput, updateProtectedContentState()); |
| 1145 | EXPECT_CALL(mOutput, dequeueRenderBuffer(_, _)) |
| 1146 | .WillOnce(DoAll(SetArgPointee<1>(tex), Return(true))); |
| 1147 | EXPECT_CALL(*mRenderSurface, prepareFrame(false, true)).Times(2); |
| 1148 | EXPECT_CALL(mOutput, chooseCompositionStrategyAsync(_)).WillOnce([&] { |
| 1149 | return p.get_future(); |
| 1150 | }); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 1151 | EXPECT_CALL(mOutput, composeSurfaces(_, _, _)); |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 1152 | |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 1153 | impl::GpuCompositionResult result = mOutput.prepareFrameAsync(); |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 1154 | EXPECT_EQ(mOutput.getState().strategyPrediction, CompositionStrategyPredictionState::FAIL); |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 1155 | EXPECT_TRUE(result.bufferAvailable()); |
| 1156 | } |
| 1157 | |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 1158 | /* |
Lloyd Pique | b62cebc | 2019-11-20 18:31:52 -0800 | [diff] [blame] | 1159 | * Output::prepare() |
| 1160 | */ |
| 1161 | |
| 1162 | struct OutputPrepareTest : public testing::Test { |
| 1163 | struct OutputPartialMock : public OutputPartialMockBase { |
| 1164 | // Sets up the helper functions called by the function under test to use |
| 1165 | // mock implementations. |
| 1166 | MOCK_METHOD2(rebuildLayerStacks, |
| 1167 | void(const compositionengine::CompositionRefreshArgs&, |
| 1168 | compositionengine::LayerFESet&)); |
| 1169 | }; |
| 1170 | |
Brian Lindahl | 439afad | 2022-11-14 11:16:55 -0700 | [diff] [blame] | 1171 | OutputPrepareTest() { |
| 1172 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(2u)); |
| 1173 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0)) |
| 1174 | .WillRepeatedly(Return(&mLayer1.outputLayer)); |
| 1175 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(1)) |
| 1176 | .WillRepeatedly(Return(&mLayer2.outputLayer)); |
| 1177 | |
| 1178 | mRefreshArgs.layers.push_back(mLayer1.layerFE); |
| 1179 | mRefreshArgs.layers.push_back(mLayer2.layerFE); |
| 1180 | } |
| 1181 | |
| 1182 | struct Layer { |
| 1183 | StrictMock<mock::OutputLayer> outputLayer; |
| 1184 | sp<StrictMock<mock::LayerFE>> layerFE = sp<StrictMock<mock::LayerFE>>::make(); |
| 1185 | }; |
| 1186 | |
Lloyd Pique | b62cebc | 2019-11-20 18:31:52 -0800 | [diff] [blame] | 1187 | StrictMock<OutputPartialMock> mOutput; |
| 1188 | CompositionRefreshArgs mRefreshArgs; |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1189 | LayerFESet mGeomSnapshots; |
Brian Lindahl | 439afad | 2022-11-14 11:16:55 -0700 | [diff] [blame] | 1190 | Layer mLayer1; |
| 1191 | Layer mLayer2; |
Lloyd Pique | b62cebc | 2019-11-20 18:31:52 -0800 | [diff] [blame] | 1192 | }; |
| 1193 | |
Brian Lindahl | 439afad | 2022-11-14 11:16:55 -0700 | [diff] [blame] | 1194 | TEST_F(OutputPrepareTest, callsUncacheBuffersOnEachOutputLayerAndThenRebuildsLayerStacks) { |
Lloyd Pique | b62cebc | 2019-11-20 18:31:52 -0800 | [diff] [blame] | 1195 | InSequence seq; |
Brian Lindahl | 439afad | 2022-11-14 11:16:55 -0700 | [diff] [blame] | 1196 | |
| 1197 | mRefreshArgs.bufferIdsToUncache = {1, 3, 5}; |
| 1198 | |
Lloyd Pique | b62cebc | 2019-11-20 18:31:52 -0800 | [diff] [blame] | 1199 | EXPECT_CALL(mOutput, rebuildLayerStacks(Ref(mRefreshArgs), Ref(mGeomSnapshots))); |
Brian Lindahl | 439afad | 2022-11-14 11:16:55 -0700 | [diff] [blame] | 1200 | EXPECT_CALL(mLayer1.outputLayer, uncacheBuffers(Ref(mRefreshArgs.bufferIdsToUncache))); |
| 1201 | EXPECT_CALL(mLayer2.outputLayer, uncacheBuffers(Ref(mRefreshArgs.bufferIdsToUncache))); |
| 1202 | |
| 1203 | mOutput.prepare(mRefreshArgs, mGeomSnapshots); |
| 1204 | } |
| 1205 | |
| 1206 | TEST_F(OutputPrepareTest, skipsUncacheBuffersIfEmptyAndThenRebuildsLayerStacks) { |
| 1207 | InSequence seq; |
| 1208 | |
| 1209 | mRefreshArgs.bufferIdsToUncache = {}; |
| 1210 | |
| 1211 | EXPECT_CALL(mOutput, rebuildLayerStacks(Ref(mRefreshArgs), Ref(mGeomSnapshots))); |
| 1212 | EXPECT_CALL(mLayer1.outputLayer, uncacheBuffers(_)).Times(0); |
| 1213 | EXPECT_CALL(mLayer2.outputLayer, uncacheBuffers(_)).Times(0); |
Lloyd Pique | b62cebc | 2019-11-20 18:31:52 -0800 | [diff] [blame] | 1214 | |
| 1215 | mOutput.prepare(mRefreshArgs, mGeomSnapshots); |
| 1216 | } |
| 1217 | |
| 1218 | /* |
| 1219 | * Output::rebuildLayerStacks() |
| 1220 | */ |
| 1221 | |
| 1222 | struct OutputRebuildLayerStacksTest : public testing::Test { |
| 1223 | struct OutputPartialMock : public OutputPartialMockBase { |
| 1224 | // Sets up the helper functions called by the function under test to use |
| 1225 | // mock implementations. |
| 1226 | MOCK_METHOD2(collectVisibleLayers, |
| 1227 | void(const compositionengine::CompositionRefreshArgs&, |
| 1228 | compositionengine::Output::CoverageState&)); |
| 1229 | }; |
| 1230 | |
| 1231 | OutputRebuildLayerStacksTest() { |
| 1232 | mOutput.mState.isEnabled = true; |
| 1233 | mOutput.mState.transform = kIdentityTransform; |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 1234 | mOutput.mState.displaySpace.setBounds( |
| 1235 | ui::Size(kOutputBounds.getWidth(), kOutputBounds.getHeight())); |
Lloyd Pique | b62cebc | 2019-11-20 18:31:52 -0800 | [diff] [blame] | 1236 | |
| 1237 | mRefreshArgs.updatingOutputGeometryThisFrame = true; |
| 1238 | |
| 1239 | mCoverageAboveCoveredLayersToSet = Region(Rect(0, 0, 10, 10)); |
| 1240 | |
| 1241 | EXPECT_CALL(mOutput, collectVisibleLayers(Ref(mRefreshArgs), _)) |
| 1242 | .WillRepeatedly(Invoke(this, &OutputRebuildLayerStacksTest::setTestCoverageValues)); |
| 1243 | } |
| 1244 | |
| 1245 | void setTestCoverageValues(const CompositionRefreshArgs&, |
| 1246 | compositionengine::Output::CoverageState& state) { |
| 1247 | state.aboveCoveredLayers = mCoverageAboveCoveredLayersToSet; |
| 1248 | state.aboveOpaqueLayers = mCoverageAboveOpaqueLayersToSet; |
| 1249 | state.dirtyRegion = mCoverageDirtyRegionToSet; |
| 1250 | } |
| 1251 | |
| 1252 | static const ui::Transform kIdentityTransform; |
| 1253 | static const ui::Transform kRotate90Transform; |
| 1254 | static const Rect kOutputBounds; |
| 1255 | |
| 1256 | StrictMock<OutputPartialMock> mOutput; |
| 1257 | CompositionRefreshArgs mRefreshArgs; |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1258 | LayerFESet mGeomSnapshots; |
Lloyd Pique | b62cebc | 2019-11-20 18:31:52 -0800 | [diff] [blame] | 1259 | Region mCoverageAboveCoveredLayersToSet; |
| 1260 | Region mCoverageAboveOpaqueLayersToSet; |
| 1261 | Region mCoverageDirtyRegionToSet; |
| 1262 | }; |
| 1263 | |
| 1264 | const ui::Transform OutputRebuildLayerStacksTest::kIdentityTransform{TR_IDENT, 1920, 1080}; |
| 1265 | const ui::Transform OutputRebuildLayerStacksTest::kRotate90Transform{TR_ROT_90, 1920, 1080}; |
| 1266 | const Rect OutputRebuildLayerStacksTest::kOutputBounds{0, 0, 1920, 1080}; |
| 1267 | |
| 1268 | TEST_F(OutputRebuildLayerStacksTest, doesNothingIfNotEnabled) { |
| 1269 | mOutput.mState.isEnabled = false; |
| 1270 | |
| 1271 | mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots); |
| 1272 | } |
| 1273 | |
| 1274 | TEST_F(OutputRebuildLayerStacksTest, doesNothingIfNotUpdatingGeometryThisFrame) { |
| 1275 | mRefreshArgs.updatingOutputGeometryThisFrame = false; |
| 1276 | |
| 1277 | mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots); |
| 1278 | } |
| 1279 | |
| 1280 | TEST_F(OutputRebuildLayerStacksTest, computesUndefinedRegionWithNoRotationAndFullCoverage) { |
| 1281 | mOutput.mState.transform = kIdentityTransform; |
| 1282 | |
| 1283 | mCoverageAboveOpaqueLayersToSet = Region(Rect(0, 0, 1920, 1080)); |
| 1284 | |
| 1285 | mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots); |
| 1286 | |
| 1287 | EXPECT_THAT(mOutput.mState.undefinedRegion, RegionEq(Region(Rect(0, 0, 0, 0)))); |
| 1288 | } |
| 1289 | |
| 1290 | TEST_F(OutputRebuildLayerStacksTest, computesUndefinedRegionWithNoRotationAndPartialCoverage) { |
| 1291 | mOutput.mState.transform = kIdentityTransform; |
| 1292 | |
| 1293 | mCoverageAboveOpaqueLayersToSet = Region(Rect(0, 0, 960, 1080)); |
| 1294 | |
| 1295 | mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots); |
| 1296 | |
| 1297 | EXPECT_THAT(mOutput.mState.undefinedRegion, RegionEq(Region(Rect(960, 0, 1920, 1080)))); |
| 1298 | } |
| 1299 | |
| 1300 | TEST_F(OutputRebuildLayerStacksTest, computesUndefinedRegionWith90RotationAndFullCoverage) { |
| 1301 | mOutput.mState.transform = kRotate90Transform; |
| 1302 | |
| 1303 | mCoverageAboveOpaqueLayersToSet = Region(Rect(0, 0, 1080, 1920)); |
| 1304 | |
| 1305 | mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots); |
| 1306 | |
| 1307 | EXPECT_THAT(mOutput.mState.undefinedRegion, RegionEq(Region(Rect(0, 0, 0, 0)))); |
| 1308 | } |
| 1309 | |
| 1310 | TEST_F(OutputRebuildLayerStacksTest, computesUndefinedRegionWith90RotationAndPartialCoverage) { |
| 1311 | mOutput.mState.transform = kRotate90Transform; |
| 1312 | |
| 1313 | mCoverageAboveOpaqueLayersToSet = Region(Rect(0, 0, 1080, 960)); |
| 1314 | |
| 1315 | mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots); |
| 1316 | |
| 1317 | EXPECT_THAT(mOutput.mState.undefinedRegion, RegionEq(Region(Rect(0, 0, 960, 1080)))); |
| 1318 | } |
| 1319 | |
| 1320 | TEST_F(OutputRebuildLayerStacksTest, addsToDirtyRegionWithNoRotation) { |
| 1321 | mOutput.mState.transform = kIdentityTransform; |
| 1322 | mOutput.mState.dirtyRegion = Region(Rect(960, 0, 1920, 1080)); |
| 1323 | |
| 1324 | mCoverageDirtyRegionToSet = Region(Rect(0, 0, 960, 1080)); |
| 1325 | |
| 1326 | mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots); |
| 1327 | |
| 1328 | EXPECT_THAT(mOutput.mState.dirtyRegion, RegionEq(Region(Rect(0, 0, 1920, 1080)))); |
| 1329 | } |
| 1330 | |
| 1331 | TEST_F(OutputRebuildLayerStacksTest, addsToDirtyRegionWith90Rotation) { |
| 1332 | mOutput.mState.transform = kRotate90Transform; |
| 1333 | mOutput.mState.dirtyRegion = Region(Rect(0, 960, 1080, 1920)); |
| 1334 | |
| 1335 | mCoverageDirtyRegionToSet = Region(Rect(0, 0, 1080, 960)); |
| 1336 | |
| 1337 | mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots); |
| 1338 | |
| 1339 | EXPECT_THAT(mOutput.mState.dirtyRegion, RegionEq(Region(Rect(0, 0, 1080, 1920)))); |
| 1340 | } |
| 1341 | |
| 1342 | /* |
| 1343 | * Output::collectVisibleLayers() |
| 1344 | */ |
| 1345 | |
Lloyd Pique | 1ef9322 | 2019-11-21 16:41:53 -0800 | [diff] [blame] | 1346 | struct OutputCollectVisibleLayersTest : public testing::Test { |
| 1347 | struct OutputPartialMock : public OutputPartialMockBase { |
| 1348 | // Sets up the helper functions called by the function under test to use |
| 1349 | // mock implementations. |
| 1350 | MOCK_METHOD2(ensureOutputLayerIfVisible, |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1351 | void(sp<compositionengine::LayerFE>&, |
Lloyd Pique | 1ef9322 | 2019-11-21 16:41:53 -0800 | [diff] [blame] | 1352 | compositionengine::Output::CoverageState&)); |
| 1353 | MOCK_METHOD1(setReleasedLayers, void(const compositionengine::CompositionRefreshArgs&)); |
| 1354 | MOCK_METHOD0(finalizePendingOutputLayers, void()); |
| 1355 | }; |
| 1356 | |
| 1357 | struct Layer { |
| 1358 | Layer() { |
| 1359 | EXPECT_CALL(outputLayer, getState()).WillRepeatedly(ReturnRef(outputLayerState)); |
| 1360 | EXPECT_CALL(outputLayer, editState()).WillRepeatedly(ReturnRef(outputLayerState)); |
| 1361 | } |
| 1362 | |
| 1363 | StrictMock<mock::OutputLayer> outputLayer; |
Lloyd Pique | 1ef9322 | 2019-11-21 16:41:53 -0800 | [diff] [blame] | 1364 | impl::OutputLayerCompositionState outputLayerState; |
Ady Abraham | e0eafa8 | 2022-02-02 19:30:47 -0800 | [diff] [blame] | 1365 | sp<StrictMock<mock::LayerFE>> layerFE = sp<StrictMock<mock::LayerFE>>::make(); |
Lloyd Pique | 1ef9322 | 2019-11-21 16:41:53 -0800 | [diff] [blame] | 1366 | }; |
| 1367 | |
| 1368 | OutputCollectVisibleLayersTest() { |
Lloyd Pique | 0a45623 | 2020-01-16 17:51:13 -0800 | [diff] [blame] | 1369 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(3u)); |
Lloyd Pique | 1ef9322 | 2019-11-21 16:41:53 -0800 | [diff] [blame] | 1370 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0)) |
| 1371 | .WillRepeatedly(Return(&mLayer1.outputLayer)); |
| 1372 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(1)) |
| 1373 | .WillRepeatedly(Return(&mLayer2.outputLayer)); |
| 1374 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(2)) |
| 1375 | .WillRepeatedly(Return(&mLayer3.outputLayer)); |
| 1376 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1377 | mRefreshArgs.layers.push_back(mLayer1.layerFE); |
| 1378 | mRefreshArgs.layers.push_back(mLayer2.layerFE); |
| 1379 | mRefreshArgs.layers.push_back(mLayer3.layerFE); |
Lloyd Pique | 1ef9322 | 2019-11-21 16:41:53 -0800 | [diff] [blame] | 1380 | } |
| 1381 | |
| 1382 | StrictMock<OutputPartialMock> mOutput; |
| 1383 | CompositionRefreshArgs mRefreshArgs; |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1384 | LayerFESet mGeomSnapshots; |
| 1385 | Output::CoverageState mCoverageState{mGeomSnapshots}; |
Lloyd Pique | 1ef9322 | 2019-11-21 16:41:53 -0800 | [diff] [blame] | 1386 | Layer mLayer1; |
| 1387 | Layer mLayer2; |
| 1388 | Layer mLayer3; |
| 1389 | }; |
| 1390 | |
| 1391 | TEST_F(OutputCollectVisibleLayersTest, doesMinimalWorkIfNoLayers) { |
| 1392 | mRefreshArgs.layers.clear(); |
Lloyd Pique | 0a45623 | 2020-01-16 17:51:13 -0800 | [diff] [blame] | 1393 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(0u)); |
Lloyd Pique | 1ef9322 | 2019-11-21 16:41:53 -0800 | [diff] [blame] | 1394 | |
| 1395 | EXPECT_CALL(mOutput, setReleasedLayers(Ref(mRefreshArgs))); |
| 1396 | EXPECT_CALL(mOutput, finalizePendingOutputLayers()); |
| 1397 | |
| 1398 | mOutput.collectVisibleLayers(mRefreshArgs, mCoverageState); |
| 1399 | } |
| 1400 | |
| 1401 | TEST_F(OutputCollectVisibleLayersTest, processesCandidateLayersReversedAndSetsOutputLayerZ) { |
| 1402 | // Enforce a call order sequence for this test. |
| 1403 | InSequence seq; |
| 1404 | |
| 1405 | // Layer coverage is evaluated from front to back! |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1406 | EXPECT_CALL(mOutput, ensureOutputLayerIfVisible(Eq(mLayer3.layerFE), Ref(mCoverageState))); |
| 1407 | EXPECT_CALL(mOutput, ensureOutputLayerIfVisible(Eq(mLayer2.layerFE), Ref(mCoverageState))); |
| 1408 | EXPECT_CALL(mOutput, ensureOutputLayerIfVisible(Eq(mLayer1.layerFE), Ref(mCoverageState))); |
Lloyd Pique | 1ef9322 | 2019-11-21 16:41:53 -0800 | [diff] [blame] | 1409 | |
| 1410 | EXPECT_CALL(mOutput, setReleasedLayers(Ref(mRefreshArgs))); |
| 1411 | EXPECT_CALL(mOutput, finalizePendingOutputLayers()); |
| 1412 | |
| 1413 | mOutput.collectVisibleLayers(mRefreshArgs, mCoverageState); |
Lloyd Pique | 1ef9322 | 2019-11-21 16:41:53 -0800 | [diff] [blame] | 1414 | } |
Lloyd Pique | b62cebc | 2019-11-20 18:31:52 -0800 | [diff] [blame] | 1415 | |
| 1416 | /* |
| 1417 | * Output::ensureOutputLayerIfVisible() |
| 1418 | */ |
| 1419 | |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1420 | struct OutputEnsureOutputLayerIfVisibleTest : public testing::Test { |
| 1421 | struct OutputPartialMock : public OutputPartialMockBase { |
| 1422 | // Sets up the helper functions called by the function under test to use |
| 1423 | // mock implementations. |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 1424 | MOCK_METHOD(bool, includesLayer, (const sp<compositionengine::LayerFE>&), |
| 1425 | (const, override)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1426 | MOCK_CONST_METHOD1(getOutputLayerOrderedByZByIndex, OutputLayer*(size_t)); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1427 | MOCK_METHOD2(ensureOutputLayer, |
| 1428 | compositionengine::OutputLayer*(std::optional<size_t>, const sp<LayerFE>&)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1429 | }; |
| 1430 | |
| 1431 | OutputEnsureOutputLayerIfVisibleTest() { |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 1432 | EXPECT_CALL(mOutput, includesLayer(sp<LayerFE>(mLayer.layerFE))) |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1433 | .WillRepeatedly(Return(true)); |
Lloyd Pique | 0a45623 | 2020-01-16 17:51:13 -0800 | [diff] [blame] | 1434 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(1u)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1435 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0u)) |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1436 | .WillRepeatedly(Return(&mLayer.outputLayer)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1437 | |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 1438 | mOutput.mState.displaySpace.setBounds(ui::Size(200, 300)); |
| 1439 | mOutput.mState.layerStackSpace.setContent(Rect(0, 0, 200, 300)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1440 | mOutput.mState.transform = ui::Transform(TR_IDENT, 200, 300); |
| 1441 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1442 | mLayer.layerFEState.isVisible = true; |
| 1443 | mLayer.layerFEState.isOpaque = true; |
| 1444 | mLayer.layerFEState.contentDirty = true; |
| 1445 | mLayer.layerFEState.geomLayerBounds = FloatRect{0, 0, 100, 200}; |
| 1446 | mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200); |
Leon Scroggins III | 9a0afda | 2022-01-11 16:53:09 -0500 | [diff] [blame] | 1447 | mLayer.layerFEState.transparentRegionHint = kTransparentRegionHint; |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1448 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1449 | mLayer.outputLayerState.visibleRegion = Region(Rect(0, 0, 50, 200)); |
| 1450 | mLayer.outputLayerState.coveredRegion = Region(Rect(50, 0, 100, 200)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1451 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1452 | mGeomSnapshots.insert(mLayer.layerFE); |
| 1453 | } |
| 1454 | |
| 1455 | void ensureOutputLayerIfVisible() { |
| 1456 | sp<LayerFE> layerFE(mLayer.layerFE); |
| 1457 | mOutput.ensureOutputLayerIfVisible(layerFE, mCoverageState); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1458 | } |
| 1459 | |
| 1460 | static const Region kEmptyRegion; |
| 1461 | static const Region kFullBoundsNoRotation; |
| 1462 | static const Region kRightHalfBoundsNoRotation; |
| 1463 | static const Region kLowerHalfBoundsNoRotation; |
| 1464 | static const Region kFullBounds90Rotation; |
Leon Scroggins III | 9a0afda | 2022-01-11 16:53:09 -0500 | [diff] [blame] | 1465 | static const Region kTransparentRegionHint; |
Leon Scroggins III | 81aff79 | 2022-03-21 13:51:34 -0400 | [diff] [blame] | 1466 | static const Region kTransparentRegionHintTwo; |
| 1467 | static const Region kTransparentRegionHintTwo90Rotation; |
Alec Mouri | e60f0b9 | 2022-06-10 19:15:20 +0000 | [diff] [blame] | 1468 | static const Region kTransparentRegionHintNegative; |
| 1469 | static const Region kTransparentRegionHintNegativeIntersectsBounds; |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1470 | |
| 1471 | StrictMock<OutputPartialMock> mOutput; |
| 1472 | LayerFESet mGeomSnapshots; |
| 1473 | Output::CoverageState mCoverageState{mGeomSnapshots}; |
| 1474 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1475 | NonInjectedLayer mLayer; |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1476 | }; |
| 1477 | |
| 1478 | const Region OutputEnsureOutputLayerIfVisibleTest::kEmptyRegion = Region(Rect(0, 0, 0, 0)); |
| 1479 | const Region OutputEnsureOutputLayerIfVisibleTest::kFullBoundsNoRotation = |
| 1480 | Region(Rect(0, 0, 100, 200)); |
| 1481 | const Region OutputEnsureOutputLayerIfVisibleTest::kRightHalfBoundsNoRotation = |
| 1482 | Region(Rect(0, 100, 100, 200)); |
| 1483 | const Region OutputEnsureOutputLayerIfVisibleTest::kLowerHalfBoundsNoRotation = |
| 1484 | Region(Rect(50, 0, 100, 200)); |
| 1485 | const Region OutputEnsureOutputLayerIfVisibleTest::kFullBounds90Rotation = |
| 1486 | Region(Rect(0, 0, 200, 100)); |
Leon Scroggins III | 9a0afda | 2022-01-11 16:53:09 -0500 | [diff] [blame] | 1487 | const Region OutputEnsureOutputLayerIfVisibleTest::kTransparentRegionHint = |
Leon Scroggins III | 81aff79 | 2022-03-21 13:51:34 -0400 | [diff] [blame] | 1488 | Region(Rect(0, 0, 100, 100)); |
| 1489 | const Region OutputEnsureOutputLayerIfVisibleTest::kTransparentRegionHintTwo = |
Leon Scroggins III | 7f7ad2c | 2022-03-17 17:06:20 -0400 | [diff] [blame] | 1490 | Region(Rect(25, 20, 50, 75)); |
Leon Scroggins III | 81aff79 | 2022-03-21 13:51:34 -0400 | [diff] [blame] | 1491 | const Region OutputEnsureOutputLayerIfVisibleTest::kTransparentRegionHintTwo90Rotation = |
Leon Scroggins III | 7f7ad2c | 2022-03-17 17:06:20 -0400 | [diff] [blame] | 1492 | Region(Rect(125, 25, 180, 50)); |
Alec Mouri | e60f0b9 | 2022-06-10 19:15:20 +0000 | [diff] [blame] | 1493 | const Region OutputEnsureOutputLayerIfVisibleTest::kTransparentRegionHintNegative = |
| 1494 | Region(Rect(INT32_MIN, INT32_MIN, INT32_MIN + 100, INT32_MIN + 200)); |
| 1495 | const Region OutputEnsureOutputLayerIfVisibleTest::kTransparentRegionHintNegativeIntersectsBounds = |
| 1496 | Region(Rect(INT32_MIN, INT32_MIN, 100, 100)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1497 | |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 1498 | TEST_F(OutputEnsureOutputLayerIfVisibleTest, performsGeomLatchBeforeCheckingIfLayerIncluded) { |
| 1499 | EXPECT_CALL(mOutput, includesLayer(sp<LayerFE>(mLayer.layerFE))).WillOnce(Return(false)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1500 | mGeomSnapshots.clear(); |
| 1501 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1502 | ensureOutputLayerIfVisible(); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1503 | } |
| 1504 | |
| 1505 | TEST_F(OutputEnsureOutputLayerIfVisibleTest, |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 1506 | skipsLatchIfAlreadyLatchedBeforeCheckingIfLayerIncluded) { |
| 1507 | EXPECT_CALL(mOutput, includesLayer(sp<LayerFE>(mLayer.layerFE))).WillOnce(Return(false)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1508 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1509 | ensureOutputLayerIfVisible(); |
| 1510 | } |
| 1511 | |
| 1512 | TEST_F(OutputEnsureOutputLayerIfVisibleTest, takesEarlyOutIfLayerHasNoCompositionState) { |
| 1513 | EXPECT_CALL(*mLayer.layerFE, getCompositionState()).WillOnce(Return(nullptr)); |
| 1514 | |
| 1515 | ensureOutputLayerIfVisible(); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1516 | } |
| 1517 | |
| 1518 | TEST_F(OutputEnsureOutputLayerIfVisibleTest, takesEarlyOutIfLayerNotVisible) { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1519 | mLayer.layerFEState.isVisible = false; |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1520 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1521 | ensureOutputLayerIfVisible(); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1522 | } |
| 1523 | |
| 1524 | TEST_F(OutputEnsureOutputLayerIfVisibleTest, takesEarlyOutIfLayerHasEmptyVisibleRegion) { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1525 | mLayer.layerFEState.geomLayerBounds = FloatRect{0, 0, 0, 0}; |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1526 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1527 | ensureOutputLayerIfVisible(); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1528 | } |
| 1529 | |
Marin Shalamanov | e67fcd0 | 2020-07-01 13:25:38 +0000 | [diff] [blame] | 1530 | TEST_F(OutputEnsureOutputLayerIfVisibleTest, takesNotSoEarlyOutifDrawRegionEmpty) { |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 1531 | mOutput.mState.displaySpace.setBounds(ui::Size(0, 0)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1532 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1533 | ensureOutputLayerIfVisible(); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1534 | } |
| 1535 | |
| 1536 | TEST_F(OutputEnsureOutputLayerIfVisibleTest, |
| 1537 | handlesCreatingOutputLayerForOpaqueDirtyNotRotatedLayer) { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1538 | mLayer.layerFEState.isOpaque = true; |
| 1539 | mLayer.layerFEState.contentDirty = true; |
| 1540 | mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1541 | |
| 1542 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u)); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1543 | EXPECT_CALL(mOutput, ensureOutputLayer(Eq(std::nullopt), Eq(mLayer.layerFE))) |
| 1544 | .WillOnce(Return(&mLayer.outputLayer)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1545 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1546 | ensureOutputLayerIfVisible(); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1547 | |
| 1548 | EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation)); |
| 1549 | EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation)); |
| 1550 | EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation)); |
| 1551 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1552 | EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation)); |
| 1553 | EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion, |
| 1554 | RegionEq(kFullBoundsNoRotation)); |
| 1555 | EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion)); |
| 1556 | EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1557 | } |
| 1558 | |
| 1559 | TEST_F(OutputEnsureOutputLayerIfVisibleTest, |
| 1560 | handlesUpdatingOutputLayerForOpaqueDirtyNotRotatedLayer) { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1561 | mLayer.layerFEState.isOpaque = true; |
| 1562 | mLayer.layerFEState.contentDirty = true; |
| 1563 | mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1564 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1565 | EXPECT_CALL(mOutput, ensureOutputLayer(Eq(0u), Eq(mLayer.layerFE))) |
| 1566 | .WillOnce(Return(&mLayer.outputLayer)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1567 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1568 | ensureOutputLayerIfVisible(); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1569 | |
| 1570 | EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation)); |
| 1571 | EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation)); |
| 1572 | EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation)); |
| 1573 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1574 | EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation)); |
| 1575 | EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion, |
| 1576 | RegionEq(kFullBoundsNoRotation)); |
| 1577 | EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion)); |
| 1578 | EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1579 | } |
| 1580 | |
| 1581 | TEST_F(OutputEnsureOutputLayerIfVisibleTest, |
| 1582 | handlesCreatingOutputLayerForTransparentDirtyNotRotatedLayer) { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1583 | mLayer.layerFEState.isOpaque = false; |
| 1584 | mLayer.layerFEState.contentDirty = true; |
| 1585 | mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1586 | |
| 1587 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u)); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1588 | EXPECT_CALL(mOutput, ensureOutputLayer(Eq(std::nullopt), Eq(mLayer.layerFE))) |
| 1589 | .WillOnce(Return(&mLayer.outputLayer)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1590 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1591 | ensureOutputLayerIfVisible(); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1592 | |
| 1593 | EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation)); |
| 1594 | EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation)); |
| 1595 | EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kEmptyRegion)); |
| 1596 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1597 | EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation)); |
| 1598 | EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion, |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1599 | RegionEq(kRightHalfBoundsNoRotation)); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1600 | EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion)); |
| 1601 | EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1602 | } |
| 1603 | |
| 1604 | TEST_F(OutputEnsureOutputLayerIfVisibleTest, |
| 1605 | handlesUpdatingOutputLayerForTransparentDirtyNotRotatedLayer) { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1606 | mLayer.layerFEState.isOpaque = false; |
| 1607 | mLayer.layerFEState.contentDirty = true; |
| 1608 | mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1609 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1610 | EXPECT_CALL(mOutput, ensureOutputLayer(Eq(0u), Eq(mLayer.layerFE))) |
| 1611 | .WillOnce(Return(&mLayer.outputLayer)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1612 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1613 | ensureOutputLayerIfVisible(); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1614 | |
| 1615 | EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation)); |
| 1616 | EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation)); |
| 1617 | EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kEmptyRegion)); |
| 1618 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1619 | EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation)); |
| 1620 | EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion, |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1621 | RegionEq(kRightHalfBoundsNoRotation)); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1622 | EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion)); |
| 1623 | EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1624 | } |
| 1625 | |
| 1626 | TEST_F(OutputEnsureOutputLayerIfVisibleTest, |
| 1627 | handlesCreatingOutputLayerForOpaqueNonDirtyNotRotatedLayer) { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1628 | mLayer.layerFEState.isOpaque = true; |
| 1629 | mLayer.layerFEState.contentDirty = false; |
| 1630 | mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1631 | |
| 1632 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u)); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1633 | EXPECT_CALL(mOutput, ensureOutputLayer(Eq(std::nullopt), Eq(mLayer.layerFE))) |
| 1634 | .WillOnce(Return(&mLayer.outputLayer)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1635 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1636 | ensureOutputLayerIfVisible(); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1637 | |
| 1638 | EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation)); |
| 1639 | EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation)); |
| 1640 | EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation)); |
| 1641 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1642 | EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation)); |
| 1643 | EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion, |
| 1644 | RegionEq(kFullBoundsNoRotation)); |
| 1645 | EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion)); |
| 1646 | EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1647 | } |
| 1648 | |
| 1649 | TEST_F(OutputEnsureOutputLayerIfVisibleTest, |
| 1650 | handlesUpdatingOutputLayerForOpaqueNonDirtyNotRotatedLayer) { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1651 | mLayer.layerFEState.isOpaque = true; |
| 1652 | mLayer.layerFEState.contentDirty = false; |
| 1653 | mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1654 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1655 | EXPECT_CALL(mOutput, ensureOutputLayer(Eq(0u), Eq(mLayer.layerFE))) |
| 1656 | .WillOnce(Return(&mLayer.outputLayer)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1657 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1658 | ensureOutputLayerIfVisible(); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1659 | |
| 1660 | EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kLowerHalfBoundsNoRotation)); |
| 1661 | EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation)); |
| 1662 | EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation)); |
| 1663 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1664 | EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation)); |
| 1665 | EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion, |
| 1666 | RegionEq(kFullBoundsNoRotation)); |
| 1667 | EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion)); |
| 1668 | EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1669 | } |
| 1670 | |
| 1671 | TEST_F(OutputEnsureOutputLayerIfVisibleTest, |
| 1672 | handlesCreatingOutputLayerForOpaqueDirtyRotated90Layer) { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1673 | mLayer.layerFEState.isOpaque = true; |
| 1674 | mLayer.layerFEState.contentDirty = true; |
| 1675 | mLayer.layerFEState.geomLayerBounds = FloatRect{0, 0, 200, 100}; |
| 1676 | mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_ROT_90, 100, 200); |
| 1677 | mLayer.outputLayerState.visibleRegion = Region(Rect(0, 0, 100, 100)); |
| 1678 | mLayer.outputLayerState.coveredRegion = Region(Rect(100, 0, 200, 100)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1679 | |
| 1680 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u)); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1681 | EXPECT_CALL(mOutput, ensureOutputLayer(Eq(std::nullopt), Eq(mLayer.layerFE))) |
| 1682 | .WillOnce(Return(&mLayer.outputLayer)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1683 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1684 | ensureOutputLayerIfVisible(); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1685 | |
| 1686 | EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation)); |
| 1687 | EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation)); |
| 1688 | EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation)); |
| 1689 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1690 | EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation)); |
| 1691 | EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion, |
| 1692 | RegionEq(kFullBoundsNoRotation)); |
| 1693 | EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion)); |
| 1694 | EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1695 | } |
| 1696 | |
| 1697 | TEST_F(OutputEnsureOutputLayerIfVisibleTest, |
| 1698 | handlesUpdatingOutputLayerForOpaqueDirtyRotated90Layer) { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1699 | mLayer.layerFEState.isOpaque = true; |
| 1700 | mLayer.layerFEState.contentDirty = true; |
| 1701 | mLayer.layerFEState.geomLayerBounds = FloatRect{0, 0, 200, 100}; |
| 1702 | mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_ROT_90, 100, 200); |
| 1703 | mLayer.outputLayerState.visibleRegion = Region(Rect(0, 0, 100, 100)); |
| 1704 | mLayer.outputLayerState.coveredRegion = Region(Rect(100, 0, 200, 100)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1705 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1706 | EXPECT_CALL(mOutput, ensureOutputLayer(Eq(0u), Eq(mLayer.layerFE))) |
| 1707 | .WillOnce(Return(&mLayer.outputLayer)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1708 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1709 | ensureOutputLayerIfVisible(); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1710 | |
| 1711 | EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation)); |
| 1712 | EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation)); |
| 1713 | EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation)); |
| 1714 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1715 | EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation)); |
| 1716 | EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion, |
| 1717 | RegionEq(kFullBoundsNoRotation)); |
| 1718 | EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion)); |
| 1719 | EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1720 | } |
| 1721 | |
| 1722 | TEST_F(OutputEnsureOutputLayerIfVisibleTest, |
| 1723 | handlesCreatingOutputLayerForOpaqueDirtyNotRotatedLayerRotatedOutput) { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1724 | mLayer.layerFEState.isOpaque = true; |
| 1725 | mLayer.layerFEState.contentDirty = true; |
| 1726 | mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1727 | |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 1728 | mOutput.mState.layerStackSpace.setContent(Rect(0, 0, 300, 200)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1729 | mOutput.mState.transform = ui::Transform(TR_ROT_90, 200, 300); |
| 1730 | |
| 1731 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u)); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1732 | EXPECT_CALL(mOutput, ensureOutputLayer(Eq(std::nullopt), Eq(mLayer.layerFE))) |
| 1733 | .WillOnce(Return(&mLayer.outputLayer)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1734 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1735 | ensureOutputLayerIfVisible(); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1736 | |
| 1737 | EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation)); |
| 1738 | EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation)); |
| 1739 | EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation)); |
| 1740 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1741 | EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation)); |
| 1742 | EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion, |
| 1743 | RegionEq(kFullBoundsNoRotation)); |
| 1744 | EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion)); |
| 1745 | EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBounds90Rotation)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1746 | } |
| 1747 | |
| 1748 | TEST_F(OutputEnsureOutputLayerIfVisibleTest, |
| 1749 | handlesUpdatingOutputLayerForOpaqueDirtyNotRotatedLayerRotatedOutput) { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1750 | mLayer.layerFEState.isOpaque = true; |
| 1751 | mLayer.layerFEState.contentDirty = true; |
| 1752 | mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1753 | |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 1754 | mOutput.mState.layerStackSpace.setContent(Rect(0, 0, 300, 200)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1755 | mOutput.mState.transform = ui::Transform(TR_ROT_90, 200, 300); |
| 1756 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1757 | EXPECT_CALL(mOutput, ensureOutputLayer(Eq(0u), Eq(mLayer.layerFE))) |
| 1758 | .WillOnce(Return(&mLayer.outputLayer)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1759 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1760 | ensureOutputLayerIfVisible(); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1761 | |
| 1762 | EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation)); |
| 1763 | EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation)); |
| 1764 | EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation)); |
| 1765 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1766 | EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation)); |
| 1767 | EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion, |
| 1768 | RegionEq(kFullBoundsNoRotation)); |
| 1769 | EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion)); |
| 1770 | EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBounds90Rotation)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1771 | } |
| 1772 | |
| 1773 | TEST_F(OutputEnsureOutputLayerIfVisibleTest, |
| 1774 | handlesCreatingOutputLayerForOpaqueDirtyArbitraryTransformLayer) { |
| 1775 | ui::Transform arbitraryTransform; |
| 1776 | arbitraryTransform.set(1, 1, -1, 1); |
| 1777 | arbitraryTransform.set(0, 100); |
| 1778 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1779 | mLayer.layerFEState.isOpaque = true; |
| 1780 | mLayer.layerFEState.contentDirty = true; |
| 1781 | mLayer.layerFEState.geomLayerBounds = FloatRect{0, 0, 100, 200}; |
| 1782 | mLayer.layerFEState.geomLayerTransform = arbitraryTransform; |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1783 | |
| 1784 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u)); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1785 | EXPECT_CALL(mOutput, ensureOutputLayer(Eq(std::nullopt), Eq(mLayer.layerFE))) |
| 1786 | .WillOnce(Return(&mLayer.outputLayer)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1787 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1788 | ensureOutputLayerIfVisible(); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1789 | |
| 1790 | const Region kRegion = Region(Rect(0, 0, 300, 300)); |
| 1791 | const Region kRegionClipped = Region(Rect(0, 0, 200, 300)); |
| 1792 | |
| 1793 | EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kRegion)); |
| 1794 | EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kRegion)); |
| 1795 | EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kEmptyRegion)); |
| 1796 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1797 | EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kRegion)); |
| 1798 | EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion, RegionEq(kRegion)); |
| 1799 | EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion)); |
| 1800 | EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kRegionClipped)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1801 | } |
| 1802 | |
| 1803 | TEST_F(OutputEnsureOutputLayerIfVisibleTest, coverageAccumulatesTest) { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1804 | mLayer.layerFEState.isOpaque = false; |
| 1805 | mLayer.layerFEState.contentDirty = true; |
| 1806 | mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1807 | |
| 1808 | mCoverageState.dirtyRegion = Region(Rect(0, 0, 500, 500)); |
| 1809 | mCoverageState.aboveCoveredLayers = Region(Rect(50, 0, 150, 200)); |
| 1810 | mCoverageState.aboveOpaqueLayers = Region(Rect(50, 0, 150, 200)); |
| 1811 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1812 | EXPECT_CALL(mOutput, ensureOutputLayer(Eq(0u), Eq(mLayer.layerFE))) |
| 1813 | .WillOnce(Return(&mLayer.outputLayer)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1814 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1815 | ensureOutputLayerIfVisible(); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1816 | |
| 1817 | const Region kExpectedDirtyRegion = Region(Rect(0, 0, 500, 500)); |
| 1818 | const Region kExpectedAboveCoveredRegion = Region(Rect(0, 0, 150, 200)); |
| 1819 | const Region kExpectedAboveOpaqueRegion = Region(Rect(50, 0, 150, 200)); |
| 1820 | const Region kExpectedLayerVisibleRegion = Region(Rect(0, 0, 50, 200)); |
| 1821 | const Region kExpectedLayerCoveredRegion = Region(Rect(50, 0, 100, 200)); |
| 1822 | const Region kExpectedLayerVisibleNonTransparentRegion = Region(Rect(0, 100, 50, 200)); |
| 1823 | |
| 1824 | EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kExpectedDirtyRegion)); |
| 1825 | EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kExpectedAboveCoveredRegion)); |
| 1826 | EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kExpectedAboveOpaqueRegion)); |
| 1827 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1828 | EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kExpectedLayerVisibleRegion)); |
| 1829 | EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion, |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1830 | RegionEq(kExpectedLayerVisibleNonTransparentRegion)); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1831 | EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kExpectedLayerCoveredRegion)); |
| 1832 | EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, |
| 1833 | RegionEq(kExpectedLayerVisibleRegion)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1834 | } |
Lloyd Pique | b62cebc | 2019-11-20 18:31:52 -0800 | [diff] [blame] | 1835 | |
Vishnu Nair | a483b4a | 2019-12-12 15:07:52 -0800 | [diff] [blame] | 1836 | TEST_F(OutputEnsureOutputLayerIfVisibleTest, coverageAccumulatesWithShadowsTest) { |
| 1837 | ui::Transform translate; |
| 1838 | translate.set(50, 50); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1839 | mLayer.layerFEState.geomLayerTransform = translate; |
Vishnu Nair | d9e4f46 | 2023-10-06 04:05:45 +0000 | [diff] [blame] | 1840 | mLayer.layerFEState.shadowSettings.length = 10.0f; |
Vishnu Nair | a483b4a | 2019-12-12 15:07:52 -0800 | [diff] [blame] | 1841 | |
| 1842 | mCoverageState.dirtyRegion = Region(Rect(0, 0, 500, 500)); |
| 1843 | // half of the layer including the casting shadow is covered and opaque |
| 1844 | mCoverageState.aboveCoveredLayers = Region(Rect(40, 40, 100, 260)); |
| 1845 | mCoverageState.aboveOpaqueLayers = Region(Rect(40, 40, 100, 260)); |
| 1846 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1847 | EXPECT_CALL(mOutput, ensureOutputLayer(Eq(0u), Eq(mLayer.layerFE))) |
| 1848 | .WillOnce(Return(&mLayer.outputLayer)); |
Vishnu Nair | a483b4a | 2019-12-12 15:07:52 -0800 | [diff] [blame] | 1849 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1850 | ensureOutputLayerIfVisible(); |
Vishnu Nair | a483b4a | 2019-12-12 15:07:52 -0800 | [diff] [blame] | 1851 | |
| 1852 | const Region kExpectedDirtyRegion = Region(Rect(0, 0, 500, 500)); |
| 1853 | const Region kExpectedAboveCoveredRegion = Region(Rect(40, 40, 160, 260)); |
| 1854 | // add starting opaque region to the opaque half of the casting layer bounds |
| 1855 | const Region kExpectedAboveOpaqueRegion = |
| 1856 | Region(Rect(40, 40, 100, 260)).orSelf(Rect(100, 50, 150, 250)); |
| 1857 | const Region kExpectedLayerVisibleRegion = Region(Rect(100, 40, 160, 260)); |
| 1858 | const Region kExpectedoutputSpaceLayerVisibleRegion = Region(Rect(100, 50, 150, 250)); |
| 1859 | const Region kExpectedLayerCoveredRegion = Region(Rect(40, 40, 100, 260)); |
| 1860 | const Region kExpectedLayerVisibleNonTransparentRegion = Region(Rect(100, 40, 160, 260)); |
| 1861 | const Region kExpectedLayerShadowRegion = |
| 1862 | Region(Rect(40, 40, 160, 260)).subtractSelf(Rect(50, 50, 150, 250)); |
| 1863 | |
| 1864 | EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kExpectedDirtyRegion)); |
| 1865 | EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kExpectedAboveCoveredRegion)); |
| 1866 | EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kExpectedAboveOpaqueRegion)); |
| 1867 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1868 | EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kExpectedLayerVisibleRegion)); |
| 1869 | EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion, |
Vishnu Nair | a483b4a | 2019-12-12 15:07:52 -0800 | [diff] [blame] | 1870 | RegionEq(kExpectedLayerVisibleNonTransparentRegion)); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1871 | EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kExpectedLayerCoveredRegion)); |
| 1872 | EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, |
Vishnu Nair | a483b4a | 2019-12-12 15:07:52 -0800 | [diff] [blame] | 1873 | RegionEq(kExpectedoutputSpaceLayerVisibleRegion)); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1874 | EXPECT_THAT(mLayer.outputLayerState.shadowRegion, RegionEq(kExpectedLayerShadowRegion)); |
Vishnu Nair | a483b4a | 2019-12-12 15:07:52 -0800 | [diff] [blame] | 1875 | EXPECT_FALSE(kExpectedLayerVisibleRegion.subtract(kExpectedLayerShadowRegion).isEmpty()); |
| 1876 | } |
| 1877 | |
| 1878 | TEST_F(OutputEnsureOutputLayerIfVisibleTest, shadowRegionOnlyTest) { |
| 1879 | ui::Transform translate; |
| 1880 | translate.set(50, 50); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1881 | mLayer.layerFEState.geomLayerTransform = translate; |
Vishnu Nair | d9e4f46 | 2023-10-06 04:05:45 +0000 | [diff] [blame] | 1882 | mLayer.layerFEState.shadowSettings.length = 10.0f; |
Vishnu Nair | a483b4a | 2019-12-12 15:07:52 -0800 | [diff] [blame] | 1883 | |
| 1884 | mCoverageState.dirtyRegion = Region(Rect(0, 0, 500, 500)); |
| 1885 | // Casting layer is covered by an opaque region leaving only part of its shadow to be drawn |
| 1886 | mCoverageState.aboveCoveredLayers = Region(Rect(40, 40, 150, 260)); |
| 1887 | mCoverageState.aboveOpaqueLayers = Region(Rect(40, 40, 150, 260)); |
| 1888 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1889 | EXPECT_CALL(mOutput, ensureOutputLayer(Eq(0u), Eq(mLayer.layerFE))) |
| 1890 | .WillOnce(Return(&mLayer.outputLayer)); |
Vishnu Nair | a483b4a | 2019-12-12 15:07:52 -0800 | [diff] [blame] | 1891 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1892 | ensureOutputLayerIfVisible(); |
Vishnu Nair | a483b4a | 2019-12-12 15:07:52 -0800 | [diff] [blame] | 1893 | |
| 1894 | const Region kExpectedLayerVisibleRegion = Region(Rect(150, 40, 160, 260)); |
| 1895 | const Region kExpectedLayerShadowRegion = |
| 1896 | Region(Rect(40, 40, 160, 260)).subtractSelf(Rect(50, 50, 150, 250)); |
| 1897 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1898 | EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kExpectedLayerVisibleRegion)); |
| 1899 | EXPECT_THAT(mLayer.outputLayerState.shadowRegion, RegionEq(kExpectedLayerShadowRegion)); |
Vishnu Nair | a483b4a | 2019-12-12 15:07:52 -0800 | [diff] [blame] | 1900 | EXPECT_TRUE(kExpectedLayerVisibleRegion.subtract(kExpectedLayerShadowRegion).isEmpty()); |
| 1901 | } |
| 1902 | |
Marin Shalamanov | e67fcd0 | 2020-07-01 13:25:38 +0000 | [diff] [blame] | 1903 | TEST_F(OutputEnsureOutputLayerIfVisibleTest, takesNotSoEarlyOutifLayerWithShadowIsCovered) { |
Vishnu Nair | a483b4a | 2019-12-12 15:07:52 -0800 | [diff] [blame] | 1904 | ui::Transform translate; |
| 1905 | translate.set(50, 50); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1906 | mLayer.layerFEState.geomLayerTransform = translate; |
Vishnu Nair | d9e4f46 | 2023-10-06 04:05:45 +0000 | [diff] [blame] | 1907 | mLayer.layerFEState.shadowSettings.length = 10.0f; |
Vishnu Nair | a483b4a | 2019-12-12 15:07:52 -0800 | [diff] [blame] | 1908 | |
| 1909 | mCoverageState.dirtyRegion = Region(Rect(0, 0, 500, 500)); |
| 1910 | // Casting layer and its shadows are covered by an opaque region |
| 1911 | mCoverageState.aboveCoveredLayers = Region(Rect(40, 40, 160, 260)); |
| 1912 | mCoverageState.aboveOpaqueLayers = Region(Rect(40, 40, 160, 260)); |
| 1913 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1914 | ensureOutputLayerIfVisible(); |
Vishnu Nair | a483b4a | 2019-12-12 15:07:52 -0800 | [diff] [blame] | 1915 | } |
| 1916 | |
Leon Scroggins III | 9a0afda | 2022-01-11 16:53:09 -0500 | [diff] [blame] | 1917 | TEST_F(OutputEnsureOutputLayerIfVisibleTest, displayDecorSetsBlockingFromTransparentRegion) { |
| 1918 | mLayer.layerFEState.isOpaque = false; |
| 1919 | mLayer.layerFEState.contentDirty = true; |
| 1920 | mLayer.layerFEState.compositionType = |
| 1921 | aidl::android::hardware::graphics::composer3::Composition::DISPLAY_DECORATION; |
| 1922 | |
| 1923 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u)); |
| 1924 | EXPECT_CALL(mOutput, ensureOutputLayer(Eq(std::nullopt), Eq(mLayer.layerFE))) |
| 1925 | .WillOnce(Return(&mLayer.outputLayer)); |
| 1926 | ensureOutputLayerIfVisible(); |
| 1927 | |
| 1928 | EXPECT_THAT(mLayer.outputLayerState.outputSpaceBlockingRegionHint, |
| 1929 | RegionEq(kTransparentRegionHint)); |
| 1930 | } |
| 1931 | |
| 1932 | TEST_F(OutputEnsureOutputLayerIfVisibleTest, normalLayersDoNotSetBlockingRegion) { |
| 1933 | mLayer.layerFEState.isOpaque = false; |
| 1934 | mLayer.layerFEState.contentDirty = true; |
| 1935 | |
| 1936 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u)); |
| 1937 | EXPECT_CALL(mOutput, ensureOutputLayer(Eq(std::nullopt), Eq(mLayer.layerFE))) |
| 1938 | .WillOnce(Return(&mLayer.outputLayer)); |
| 1939 | ensureOutputLayerIfVisible(); |
| 1940 | |
| 1941 | EXPECT_THAT(mLayer.outputLayerState.outputSpaceBlockingRegionHint, RegionEq(Region())); |
| 1942 | } |
| 1943 | |
Leon Scroggins III | 7f7ad2c | 2022-03-17 17:06:20 -0400 | [diff] [blame] | 1944 | TEST_F(OutputEnsureOutputLayerIfVisibleTest, blockingRegionIsInOutputSpace) { |
| 1945 | mLayer.layerFEState.isOpaque = false; |
| 1946 | mLayer.layerFEState.contentDirty = true; |
| 1947 | mLayer.layerFEState.compositionType = |
| 1948 | aidl::android::hardware::graphics::composer3::Composition::DISPLAY_DECORATION; |
Leon Scroggins III | 81aff79 | 2022-03-21 13:51:34 -0400 | [diff] [blame] | 1949 | mLayer.layerFEState.transparentRegionHint = kTransparentRegionHintTwo; |
Leon Scroggins III | 7f7ad2c | 2022-03-17 17:06:20 -0400 | [diff] [blame] | 1950 | |
| 1951 | mOutput.mState.layerStackSpace.setContent(Rect(0, 0, 300, 200)); |
| 1952 | mOutput.mState.transform = ui::Transform(TR_ROT_90, 200, 300); |
| 1953 | |
| 1954 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u)); |
| 1955 | EXPECT_CALL(mOutput, ensureOutputLayer(Eq(std::nullopt), Eq(mLayer.layerFE))) |
| 1956 | .WillOnce(Return(&mLayer.outputLayer)); |
| 1957 | ensureOutputLayerIfVisible(); |
| 1958 | |
| 1959 | EXPECT_THAT(mLayer.outputLayerState.outputSpaceBlockingRegionHint, |
Leon Scroggins III | 81aff79 | 2022-03-21 13:51:34 -0400 | [diff] [blame] | 1960 | RegionEq(kTransparentRegionHintTwo90Rotation)); |
Leon Scroggins III | 7f7ad2c | 2022-03-17 17:06:20 -0400 | [diff] [blame] | 1961 | } |
| 1962 | |
Alec Mouri | e60f0b9 | 2022-06-10 19:15:20 +0000 | [diff] [blame] | 1963 | TEST_F(OutputEnsureOutputLayerIfVisibleTest, transparentRegionExcludesOutputLayer) { |
| 1964 | mLayer.layerFEState.isOpaque = false; |
| 1965 | mLayer.layerFEState.contentDirty = true; |
| 1966 | mLayer.layerFEState.geomLayerBounds = kFullBoundsNoRotation.bounds().toFloatRect(); |
| 1967 | mLayer.layerFEState.transparentRegionHint = kFullBoundsNoRotation; |
| 1968 | |
| 1969 | EXPECT_CALL(mOutput, ensureOutputLayer(_, _)).Times(0); |
| 1970 | } |
| 1971 | |
| 1972 | TEST_F(OutputEnsureOutputLayerIfVisibleTest, transparentRegionIgnoredWhenOutsideBounds) { |
| 1973 | mLayer.layerFEState.isOpaque = false; |
| 1974 | mLayer.layerFEState.contentDirty = true; |
| 1975 | mLayer.layerFEState.geomLayerBounds = kFullBoundsNoRotation.bounds().toFloatRect(); |
| 1976 | mLayer.layerFEState.transparentRegionHint = kTransparentRegionHintNegative; |
| 1977 | |
| 1978 | EXPECT_CALL(mOutput, ensureOutputLayer(_, _)).Times(0); |
| 1979 | } |
| 1980 | |
| 1981 | TEST_F(OutputEnsureOutputLayerIfVisibleTest, transparentRegionClipsWhenOutsideBounds) { |
| 1982 | mLayer.layerFEState.isOpaque = false; |
| 1983 | mLayer.layerFEState.contentDirty = true; |
| 1984 | mLayer.layerFEState.compositionType = |
| 1985 | aidl::android::hardware::graphics::composer3::Composition::DISPLAY_DECORATION; |
| 1986 | mLayer.layerFEState.transparentRegionHint = kTransparentRegionHintNegativeIntersectsBounds; |
| 1987 | |
| 1988 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u)); |
| 1989 | EXPECT_CALL(mOutput, ensureOutputLayer(Eq(std::nullopt), Eq(mLayer.layerFE))) |
| 1990 | .WillOnce(Return(&mLayer.outputLayer)); |
| 1991 | ensureOutputLayerIfVisible(); |
| 1992 | |
| 1993 | // Check that the blocking region clips an out-of-bounds transparent region. |
| 1994 | EXPECT_THAT(mLayer.outputLayerState.outputSpaceBlockingRegionHint, |
| 1995 | RegionEq(kTransparentRegionHint)); |
| 1996 | } |
| 1997 | |
Lloyd Pique | b62cebc | 2019-11-20 18:31:52 -0800 | [diff] [blame] | 1998 | /* |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 1999 | * Output::present() |
| 2000 | */ |
| 2001 | |
| 2002 | struct OutputPresentTest : public testing::Test { |
| 2003 | struct OutputPartialMock : public OutputPartialMockBase { |
Lloyd Pique | 739afaf | 2019-11-21 16:40:05 -0800 | [diff] [blame] | 2004 | // Sets up the helper functions called by the function under test to use |
| 2005 | // mock implementations. |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 2006 | MOCK_METHOD1(updateColorProfile, void(const compositionengine::CompositionRefreshArgs&)); |
Dan Stoza | 269dc4d | 2021-01-15 15:07:43 -0800 | [diff] [blame] | 2007 | MOCK_METHOD1(updateCompositionState, |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 2008 | void(const compositionengine::CompositionRefreshArgs&)); |
Dan Stoza | 269dc4d | 2021-01-15 15:07:43 -0800 | [diff] [blame] | 2009 | MOCK_METHOD0(planComposition, void()); |
| 2010 | MOCK_METHOD1(writeCompositionState, void(const compositionengine::CompositionRefreshArgs&)); |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 2011 | MOCK_METHOD1(setColorTransform, void(const compositionengine::CompositionRefreshArgs&)); |
| 2012 | MOCK_METHOD0(beginFrame, void()); |
| 2013 | MOCK_METHOD0(prepareFrame, void()); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 2014 | MOCK_METHOD0(prepareFrameAsync, GpuCompositionResult()); |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 2015 | MOCK_METHOD1(devOptRepaintFlash, void(const compositionengine::CompositionRefreshArgs&)); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 2016 | MOCK_METHOD1(finishFrame, void(GpuCompositionResult&&)); |
Leon Scroggins III | c1623d1 | 2023-11-06 15:31:05 -0500 | [diff] [blame] | 2017 | MOCK_METHOD0(presentFrameAndReleaseLayers, void()); |
Alec Mouri | aa83158 | 2021-06-07 16:23:01 -0700 | [diff] [blame] | 2018 | MOCK_METHOD1(renderCachedSets, void(const compositionengine::CompositionRefreshArgs&)); |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 2019 | MOCK_METHOD1(canPredictCompositionStrategy, bool(const CompositionRefreshArgs&)); |
Xiang Wang | aab3116 | 2024-03-12 19:48:08 -0700 | [diff] [blame] | 2020 | MOCK_METHOD(void, setHintSessionRequiresRenderEngine, (bool requiresRenderEngine), |
| 2021 | (override)); |
| 2022 | MOCK_METHOD(bool, isPowerHintSessionEnabled, (), (override)); |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 2023 | }; |
| 2024 | |
Xiang Wang | aab3116 | 2024-03-12 19:48:08 -0700 | [diff] [blame] | 2025 | OutputPresentTest() { |
| 2026 | EXPECT_CALL(mOutput, isPowerHintSessionEnabled()).WillRepeatedly(Return(true)); |
| 2027 | } |
| 2028 | |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 2029 | StrictMock<OutputPartialMock> mOutput; |
| 2030 | }; |
| 2031 | |
| 2032 | TEST_F(OutputPresentTest, justInvokesChildFunctionsInSequence) { |
| 2033 | CompositionRefreshArgs args; |
| 2034 | |
| 2035 | InSequence seq; |
| 2036 | EXPECT_CALL(mOutput, updateColorProfile(Ref(args))); |
Dan Stoza | 269dc4d | 2021-01-15 15:07:43 -0800 | [diff] [blame] | 2037 | EXPECT_CALL(mOutput, updateCompositionState(Ref(args))); |
| 2038 | EXPECT_CALL(mOutput, planComposition()); |
| 2039 | EXPECT_CALL(mOutput, writeCompositionState(Ref(args))); |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 2040 | EXPECT_CALL(mOutput, setColorTransform(Ref(args))); |
| 2041 | EXPECT_CALL(mOutput, beginFrame()); |
Xiang Wang | aab3116 | 2024-03-12 19:48:08 -0700 | [diff] [blame] | 2042 | EXPECT_CALL(mOutput, setHintSessionRequiresRenderEngine(false)); |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 2043 | EXPECT_CALL(mOutput, canPredictCompositionStrategy(Ref(args))).WillOnce(Return(false)); |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 2044 | EXPECT_CALL(mOutput, prepareFrame()); |
| 2045 | EXPECT_CALL(mOutput, devOptRepaintFlash(Ref(args))); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 2046 | EXPECT_CALL(mOutput, finishFrame(_)); |
Leon Scroggins III | c1623d1 | 2023-11-06 15:31:05 -0500 | [diff] [blame] | 2047 | EXPECT_CALL(mOutput, presentFrameAndReleaseLayers()); |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 2048 | EXPECT_CALL(mOutput, renderCachedSets(Ref(args))); |
| 2049 | |
| 2050 | mOutput.present(args); |
| 2051 | } |
| 2052 | |
| 2053 | TEST_F(OutputPresentTest, predictingCompositionStrategyInvokesPrepareFrameAsync) { |
| 2054 | CompositionRefreshArgs args; |
| 2055 | |
| 2056 | InSequence seq; |
| 2057 | EXPECT_CALL(mOutput, updateColorProfile(Ref(args))); |
| 2058 | EXPECT_CALL(mOutput, updateCompositionState(Ref(args))); |
| 2059 | EXPECT_CALL(mOutput, planComposition()); |
| 2060 | EXPECT_CALL(mOutput, writeCompositionState(Ref(args))); |
| 2061 | EXPECT_CALL(mOutput, setColorTransform(Ref(args))); |
| 2062 | EXPECT_CALL(mOutput, beginFrame()); |
Xiang Wang | aab3116 | 2024-03-12 19:48:08 -0700 | [diff] [blame] | 2063 | EXPECT_CALL(mOutput, setHintSessionRequiresRenderEngine(false)); |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 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(_)); |
Leon Scroggins III | c1623d1 | 2023-11-06 15:31:05 -0500 | [diff] [blame] | 2068 | EXPECT_CALL(mOutput, presentFrameAndReleaseLayers()); |
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, |
Alec Mouri | 88790f3 | 2023-07-21 01:25:14 +0000 | [diff] [blame] | 2136 | setColorProfile( |
| 2137 | ColorProfileEq(ColorProfile{ui::ColorMode::NATIVE, ui::Dataspace::UNKNOWN, |
| 2138 | ui::RenderIntent::COLORIMETRIC}))); |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 2139 | |
| 2140 | mRefreshArgs.outputColorSetting = OutputColorSetting::kUnmanaged; |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 2141 | |
| 2142 | mOutput.updateColorProfile(mRefreshArgs); |
| 2143 | } |
| 2144 | |
| 2145 | struct OutputUpdateColorProfileTest_GetBestColorModeResultBecomesSetProfile |
| 2146 | : public OutputUpdateColorProfileTest { |
| 2147 | OutputUpdateColorProfileTest_GetBestColorModeResultBecomesSetProfile() { |
Lloyd Pique | 0a45623 | 2020-01-16 17:51:13 -0800 | [diff] [blame] | 2148 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(0u)); |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 2149 | mRefreshArgs.outputColorSetting = OutputColorSetting::kEnhanced; |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 2150 | } |
| 2151 | |
| 2152 | struct ExpectBestColorModeCallResultUsedToSetColorProfileState |
| 2153 | : public CallOrderStateMachineHelper< |
| 2154 | TestType, ExpectBestColorModeCallResultUsedToSetColorProfileState> { |
| 2155 | [[nodiscard]] auto expectBestColorModeCallResultUsedToSetColorProfile( |
| 2156 | ui::ColorMode colorMode, ui::Dataspace dataspace, ui::RenderIntent renderIntent) { |
| 2157 | EXPECT_CALL(*getInstance()->mDisplayColorProfile, |
| 2158 | getBestColorMode(ui::Dataspace::V0_SRGB, ui::RenderIntent::ENHANCE, _, _, |
| 2159 | _)) |
| 2160 | .WillOnce(DoAll(SetArgPointee<2>(dataspace), SetArgPointee<3>(colorMode), |
| 2161 | SetArgPointee<4>(renderIntent))); |
| 2162 | EXPECT_CALL(getInstance()->mOutput, |
| 2163 | setColorProfile( |
Alec Mouri | 88790f3 | 2023-07-21 01:25:14 +0000 | [diff] [blame] | 2164 | ColorProfileEq(ColorProfile{colorMode, dataspace, renderIntent}))); |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 2165 | return nextState<ExecuteState>(); |
| 2166 | } |
| 2167 | }; |
| 2168 | |
| 2169 | // Call this member function to start using the mini-DSL defined above. |
| 2170 | [[nodiscard]] auto verify() { |
| 2171 | return ExpectBestColorModeCallResultUsedToSetColorProfileState::make(this); |
| 2172 | } |
| 2173 | }; |
| 2174 | |
| 2175 | TEST_F(OutputUpdateColorProfileTest_GetBestColorModeResultBecomesSetProfile, |
| 2176 | Native_Unknown_Colorimetric_Set) { |
| 2177 | verify().expectBestColorModeCallResultUsedToSetColorProfile(ui::ColorMode::NATIVE, |
| 2178 | ui::Dataspace::UNKNOWN, |
| 2179 | ui::RenderIntent::COLORIMETRIC) |
| 2180 | .execute(); |
| 2181 | } |
| 2182 | |
| 2183 | TEST_F(OutputUpdateColorProfileTest_GetBestColorModeResultBecomesSetProfile, |
| 2184 | DisplayP3_DisplayP3_Enhance_Set) { |
| 2185 | verify().expectBestColorModeCallResultUsedToSetColorProfile(ui::ColorMode::DISPLAY_P3, |
| 2186 | ui::Dataspace::DISPLAY_P3, |
| 2187 | ui::RenderIntent::ENHANCE) |
| 2188 | .execute(); |
| 2189 | } |
| 2190 | |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 2191 | struct OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference |
| 2192 | : public OutputUpdateColorProfileTest { |
| 2193 | // Internally the implementation looks through the dataspaces of all the |
| 2194 | // visible layers. The topmost one that also has an actual dataspace |
| 2195 | // preference set is used to drive subsequent choices. |
| 2196 | |
| 2197 | OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference() { |
| 2198 | mRefreshArgs.outputColorSetting = OutputColorSetting::kEnhanced; |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 2199 | |
Lloyd Pique | 0a45623 | 2020-01-16 17:51:13 -0800 | [diff] [blame] | 2200 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(3u)); |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 2201 | EXPECT_CALL(mOutput, setColorProfile(_)).WillRepeatedly(Return()); |
| 2202 | } |
| 2203 | |
| 2204 | struct IfTopLayerDataspaceState |
| 2205 | : public CallOrderStateMachineHelper<TestType, IfTopLayerDataspaceState> { |
| 2206 | [[nodiscard]] auto ifTopLayerIs(ui::Dataspace dataspace) { |
| 2207 | getInstance()->mLayer3.mLayerFEState.dataspace = dataspace; |
| 2208 | return nextState<AndIfMiddleLayerDataspaceState>(); |
| 2209 | } |
| 2210 | [[nodiscard]] auto ifTopLayerHasNoPreference() { |
| 2211 | return ifTopLayerIs(ui::Dataspace::UNKNOWN); |
| 2212 | } |
| 2213 | }; |
| 2214 | |
| 2215 | struct AndIfMiddleLayerDataspaceState |
| 2216 | : public CallOrderStateMachineHelper<TestType, AndIfMiddleLayerDataspaceState> { |
| 2217 | [[nodiscard]] auto andIfMiddleLayerIs(ui::Dataspace dataspace) { |
| 2218 | getInstance()->mLayer2.mLayerFEState.dataspace = dataspace; |
| 2219 | return nextState<AndIfBottomLayerDataspaceState>(); |
| 2220 | } |
| 2221 | [[nodiscard]] auto andIfMiddleLayerHasNoPreference() { |
| 2222 | return andIfMiddleLayerIs(ui::Dataspace::UNKNOWN); |
| 2223 | } |
| 2224 | }; |
| 2225 | |
| 2226 | struct AndIfBottomLayerDataspaceState |
| 2227 | : public CallOrderStateMachineHelper<TestType, AndIfBottomLayerDataspaceState> { |
| 2228 | [[nodiscard]] auto andIfBottomLayerIs(ui::Dataspace dataspace) { |
| 2229 | getInstance()->mLayer1.mLayerFEState.dataspace = dataspace; |
| 2230 | return nextState<ThenExpectBestColorModeCallUsesState>(); |
| 2231 | } |
| 2232 | [[nodiscard]] auto andIfBottomLayerHasNoPreference() { |
| 2233 | return andIfBottomLayerIs(ui::Dataspace::UNKNOWN); |
| 2234 | } |
| 2235 | }; |
| 2236 | |
| 2237 | struct ThenExpectBestColorModeCallUsesState |
| 2238 | : public CallOrderStateMachineHelper<TestType, ThenExpectBestColorModeCallUsesState> { |
| 2239 | [[nodiscard]] auto thenExpectBestColorModeCallUses(ui::Dataspace dataspace) { |
| 2240 | EXPECT_CALL(*getInstance()->mDisplayColorProfile, |
| 2241 | getBestColorMode(dataspace, _, _, _, _)); |
| 2242 | return nextState<ExecuteState>(); |
| 2243 | } |
| 2244 | }; |
| 2245 | |
| 2246 | // Call this member function to start using the mini-DSL defined above. |
| 2247 | [[nodiscard]] auto verify() { return IfTopLayerDataspaceState::make(this); } |
| 2248 | }; |
| 2249 | |
| 2250 | TEST_F(OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference, |
| 2251 | noStrongLayerPrefenceUses_V0_SRGB) { |
| 2252 | // If none of the layers indicate a preference, then V0_SRGB is the |
| 2253 | // preferred choice (subject to additional checks). |
| 2254 | verify().ifTopLayerHasNoPreference() |
| 2255 | .andIfMiddleLayerHasNoPreference() |
| 2256 | .andIfBottomLayerHasNoPreference() |
| 2257 | .thenExpectBestColorModeCallUses(ui::Dataspace::V0_SRGB) |
| 2258 | .execute(); |
| 2259 | } |
| 2260 | |
| 2261 | TEST_F(OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference, |
| 2262 | ifTopmostUses_DisplayP3_Then_DisplayP3_Chosen) { |
| 2263 | // If only the topmost layer has a preference, then that is what is chosen. |
| 2264 | verify().ifTopLayerIs(ui::Dataspace::DISPLAY_P3) |
| 2265 | .andIfMiddleLayerHasNoPreference() |
| 2266 | .andIfBottomLayerHasNoPreference() |
| 2267 | .thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_P3) |
| 2268 | .execute(); |
| 2269 | } |
| 2270 | |
| 2271 | TEST_F(OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference, |
| 2272 | ifMiddleUses_DisplayP3_Then_DisplayP3_Chosen) { |
| 2273 | // If only the middle layer has a preference, that that is what is chosen. |
| 2274 | verify().ifTopLayerHasNoPreference() |
| 2275 | .andIfMiddleLayerIs(ui::Dataspace::DISPLAY_P3) |
| 2276 | .andIfBottomLayerHasNoPreference() |
| 2277 | .thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_P3) |
| 2278 | .execute(); |
| 2279 | } |
| 2280 | |
| 2281 | TEST_F(OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference, |
| 2282 | ifBottomUses_DisplayP3_Then_DisplayP3_Chosen) { |
| 2283 | // If only the middle layer has a preference, that that is what is chosen. |
| 2284 | verify().ifTopLayerHasNoPreference() |
| 2285 | .andIfMiddleLayerHasNoPreference() |
| 2286 | .andIfBottomLayerIs(ui::Dataspace::DISPLAY_P3) |
| 2287 | .thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_P3) |
| 2288 | .execute(); |
| 2289 | } |
| 2290 | |
| 2291 | TEST_F(OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference, |
| 2292 | ifTopUses_DisplayBT2020_AndBottomUses_DisplayP3_Then_DisplayBT2020_Chosen) { |
| 2293 | // If multiple layers have a preference, the topmost value is what is used. |
| 2294 | verify().ifTopLayerIs(ui::Dataspace::DISPLAY_BT2020) |
| 2295 | .andIfMiddleLayerHasNoPreference() |
| 2296 | .andIfBottomLayerIs(ui::Dataspace::DISPLAY_P3) |
| 2297 | .thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_BT2020) |
| 2298 | .execute(); |
| 2299 | } |
| 2300 | |
| 2301 | TEST_F(OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference, |
| 2302 | ifTopUses_DisplayP3_AndBottomUses_V0_SRGB_Then_DisplayP3_Chosen) { |
| 2303 | // If multiple layers have a preference, the topmost value is what is used. |
| 2304 | verify().ifTopLayerIs(ui::Dataspace::DISPLAY_P3) |
| 2305 | .andIfMiddleLayerHasNoPreference() |
| 2306 | .andIfBottomLayerIs(ui::Dataspace::DISPLAY_BT2020) |
| 2307 | .thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_P3) |
| 2308 | .execute(); |
| 2309 | } |
| 2310 | |
| 2311 | struct OutputUpdateColorProfileTest_ForceOutputColorOverrides |
| 2312 | : public OutputUpdateColorProfileTest { |
| 2313 | // If CompositionRefreshArgs::forceOutputColorMode is set to some specific |
| 2314 | // values, it overrides the layer dataspace choice. |
| 2315 | |
| 2316 | OutputUpdateColorProfileTest_ForceOutputColorOverrides() { |
| 2317 | mRefreshArgs.outputColorSetting = OutputColorSetting::kEnhanced; |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 2318 | |
| 2319 | mLayer1.mLayerFEState.dataspace = ui::Dataspace::DISPLAY_BT2020; |
| 2320 | |
Lloyd Pique | 0a45623 | 2020-01-16 17:51:13 -0800 | [diff] [blame] | 2321 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(1u)); |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 2322 | EXPECT_CALL(mOutput, setColorProfile(_)).WillRepeatedly(Return()); |
| 2323 | } |
| 2324 | |
| 2325 | struct IfForceOutputColorModeState |
| 2326 | : public CallOrderStateMachineHelper<TestType, IfForceOutputColorModeState> { |
| 2327 | [[nodiscard]] auto ifForceOutputColorMode(ui::ColorMode colorMode) { |
| 2328 | getInstance()->mRefreshArgs.forceOutputColorMode = colorMode; |
| 2329 | return nextState<ThenExpectBestColorModeCallUsesState>(); |
| 2330 | } |
| 2331 | [[nodiscard]] auto ifNoOverride() { return ifForceOutputColorMode(ui::ColorMode::NATIVE); } |
| 2332 | }; |
| 2333 | |
| 2334 | struct ThenExpectBestColorModeCallUsesState |
| 2335 | : public CallOrderStateMachineHelper<TestType, ThenExpectBestColorModeCallUsesState> { |
| 2336 | [[nodiscard]] auto thenExpectBestColorModeCallUses(ui::Dataspace dataspace) { |
| 2337 | EXPECT_CALL(*getInstance()->mDisplayColorProfile, |
| 2338 | getBestColorMode(dataspace, _, _, _, _)); |
| 2339 | return nextState<ExecuteState>(); |
| 2340 | } |
| 2341 | }; |
| 2342 | |
| 2343 | // Call this member function to start using the mini-DSL defined above. |
| 2344 | [[nodiscard]] auto verify() { return IfForceOutputColorModeState::make(this); } |
| 2345 | }; |
| 2346 | |
| 2347 | TEST_F(OutputUpdateColorProfileTest_ForceOutputColorOverrides, NoOverride_DoesNotOverride) { |
| 2348 | // By default the layer state is used to set the preferred dataspace |
| 2349 | verify().ifNoOverride() |
| 2350 | .thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_BT2020) |
| 2351 | .execute(); |
| 2352 | } |
| 2353 | |
| 2354 | TEST_F(OutputUpdateColorProfileTest_ForceOutputColorOverrides, SRGB_Override_USES_V0_SRGB) { |
| 2355 | // Setting ui::ColorMode::SRGB overrides it with ui::Dataspace::V0_SRGB |
| 2356 | verify().ifForceOutputColorMode(ui::ColorMode::SRGB) |
| 2357 | .thenExpectBestColorModeCallUses(ui::Dataspace::V0_SRGB) |
| 2358 | .execute(); |
| 2359 | } |
| 2360 | |
| 2361 | TEST_F(OutputUpdateColorProfileTest_ForceOutputColorOverrides, DisplayP3_Override_Uses_DisplayP3) { |
| 2362 | // Setting ui::ColorMode::DISPLAY_P3 overrides it with ui::Dataspace::DISPLAY_P3 |
| 2363 | verify().ifForceOutputColorMode(ui::ColorMode::DISPLAY_P3) |
| 2364 | .thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_P3) |
| 2365 | .execute(); |
| 2366 | } |
| 2367 | |
| 2368 | // HDR output requires all layers to be compatible with the chosen HDR |
| 2369 | // dataspace, along with there being proper support. |
| 2370 | struct OutputUpdateColorProfileTest_Hdr : public OutputUpdateColorProfileTest { |
| 2371 | OutputUpdateColorProfileTest_Hdr() { |
| 2372 | mRefreshArgs.outputColorSetting = OutputColorSetting::kEnhanced; |
Lloyd Pique | 0a45623 | 2020-01-16 17:51:13 -0800 | [diff] [blame] | 2373 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(2u)); |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 2374 | EXPECT_CALL(mOutput, setColorProfile(_)).WillRepeatedly(Return()); |
| 2375 | } |
| 2376 | |
| 2377 | static constexpr ui::Dataspace kNonHdrDataspace = ui::Dataspace::DISPLAY_P3; |
| 2378 | static constexpr ui::Dataspace BT2020_PQ = ui::Dataspace::BT2020_PQ; |
| 2379 | static constexpr ui::Dataspace BT2020_HLG = ui::Dataspace::BT2020_HLG; |
| 2380 | static constexpr ui::Dataspace DISPLAY_P3 = ui::Dataspace::DISPLAY_P3; |
| 2381 | |
| 2382 | struct IfTopLayerDataspaceState |
| 2383 | : public CallOrderStateMachineHelper<TestType, IfTopLayerDataspaceState> { |
| 2384 | [[nodiscard]] auto ifTopLayerIs(ui::Dataspace dataspace) { |
| 2385 | getInstance()->mLayer2.mLayerFEState.dataspace = dataspace; |
| 2386 | return nextState<AndTopLayerCompositionTypeState>(); |
| 2387 | } |
| 2388 | [[nodiscard]] auto ifTopLayerIsNotHdr() { return ifTopLayerIs(kNonHdrDataspace); } |
| 2389 | }; |
| 2390 | |
| 2391 | struct AndTopLayerCompositionTypeState |
| 2392 | : public CallOrderStateMachineHelper<TestType, AndTopLayerCompositionTypeState> { |
| 2393 | [[nodiscard]] auto andTopLayerIsREComposed(bool renderEngineComposed) { |
| 2394 | getInstance()->mLayer2.mLayerFEState.forceClientComposition = renderEngineComposed; |
| 2395 | return nextState<AndIfBottomLayerDataspaceState>(); |
| 2396 | } |
| 2397 | }; |
| 2398 | |
| 2399 | struct AndIfBottomLayerDataspaceState |
| 2400 | : public CallOrderStateMachineHelper<TestType, AndIfBottomLayerDataspaceState> { |
| 2401 | [[nodiscard]] auto andIfBottomLayerIs(ui::Dataspace dataspace) { |
| 2402 | getInstance()->mLayer1.mLayerFEState.dataspace = dataspace; |
| 2403 | return nextState<AndBottomLayerCompositionTypeState>(); |
| 2404 | } |
| 2405 | [[nodiscard]] auto andIfBottomLayerIsNotHdr() { |
| 2406 | return andIfBottomLayerIs(kNonHdrDataspace); |
| 2407 | } |
| 2408 | }; |
| 2409 | |
| 2410 | struct AndBottomLayerCompositionTypeState |
| 2411 | : public CallOrderStateMachineHelper<TestType, AndBottomLayerCompositionTypeState> { |
| 2412 | [[nodiscard]] auto andBottomLayerIsREComposed(bool renderEngineComposed) { |
| 2413 | getInstance()->mLayer1.mLayerFEState.forceClientComposition = renderEngineComposed; |
| 2414 | return nextState<AndIfHasLegacySupportState>(); |
| 2415 | } |
| 2416 | }; |
| 2417 | |
| 2418 | struct AndIfHasLegacySupportState |
| 2419 | : public CallOrderStateMachineHelper<TestType, AndIfHasLegacySupportState> { |
| 2420 | [[nodiscard]] auto andIfLegacySupportFor(ui::Dataspace dataspace, bool legacySupport) { |
| 2421 | EXPECT_CALL(*getInstance()->mDisplayColorProfile, hasLegacyHdrSupport(dataspace)) |
| 2422 | .WillOnce(Return(legacySupport)); |
| 2423 | return nextState<ThenExpectBestColorModeCallUsesState>(); |
| 2424 | } |
| 2425 | }; |
| 2426 | |
| 2427 | struct ThenExpectBestColorModeCallUsesState |
| 2428 | : public CallOrderStateMachineHelper<TestType, ThenExpectBestColorModeCallUsesState> { |
| 2429 | [[nodiscard]] auto thenExpectBestColorModeCallUses(ui::Dataspace dataspace) { |
| 2430 | EXPECT_CALL(*getInstance()->mDisplayColorProfile, |
| 2431 | getBestColorMode(dataspace, _, _, _, _)); |
| 2432 | return nextState<ExecuteState>(); |
| 2433 | } |
| 2434 | }; |
| 2435 | |
| 2436 | // Call this member function to start using the mini-DSL defined above. |
| 2437 | [[nodiscard]] auto verify() { return IfTopLayerDataspaceState::make(this); } |
| 2438 | }; |
| 2439 | |
| 2440 | TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_PQ_HW_Uses_PQ) { |
| 2441 | // If all layers use BT2020_PQ, and there are no other special conditions, |
| 2442 | // BT2020_PQ is used. |
| 2443 | verify().ifTopLayerIs(BT2020_PQ) |
| 2444 | .andTopLayerIsREComposed(false) |
| 2445 | .andIfBottomLayerIs(BT2020_PQ) |
| 2446 | .andBottomLayerIsREComposed(false) |
| 2447 | .andIfLegacySupportFor(BT2020_PQ, false) |
| 2448 | .thenExpectBestColorModeCallUses(BT2020_PQ) |
| 2449 | .execute(); |
| 2450 | } |
| 2451 | |
| 2452 | TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_PQ_HW_IfPQHasLegacySupport_Uses_DisplayP3) { |
| 2453 | // BT2020_PQ is not used if there is only legacy support for it. |
| 2454 | verify().ifTopLayerIs(BT2020_PQ) |
| 2455 | .andTopLayerIsREComposed(false) |
| 2456 | .andIfBottomLayerIs(BT2020_PQ) |
| 2457 | .andBottomLayerIsREComposed(false) |
| 2458 | .andIfLegacySupportFor(BT2020_PQ, true) |
| 2459 | .thenExpectBestColorModeCallUses(DISPLAY_P3) |
| 2460 | .execute(); |
| 2461 | } |
| 2462 | |
| 2463 | TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_PQ_RE_Uses_PQ) { |
| 2464 | // BT2020_PQ is still used if the bottom layer is RenderEngine composed. |
| 2465 | verify().ifTopLayerIs(BT2020_PQ) |
| 2466 | .andTopLayerIsREComposed(false) |
| 2467 | .andIfBottomLayerIs(BT2020_PQ) |
| 2468 | .andBottomLayerIsREComposed(true) |
| 2469 | .andIfLegacySupportFor(BT2020_PQ, false) |
| 2470 | .thenExpectBestColorModeCallUses(BT2020_PQ) |
| 2471 | .execute(); |
| 2472 | } |
| 2473 | |
| 2474 | TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_RE_On_PQ_HW_Uses_DisplayP3) { |
| 2475 | // BT2020_PQ is not used if the top layer is RenderEngine composed. |
| 2476 | verify().ifTopLayerIs(BT2020_PQ) |
| 2477 | .andTopLayerIsREComposed(true) |
| 2478 | .andIfBottomLayerIs(BT2020_PQ) |
| 2479 | .andBottomLayerIsREComposed(false) |
| 2480 | .andIfLegacySupportFor(BT2020_PQ, false) |
| 2481 | .thenExpectBestColorModeCallUses(DISPLAY_P3) |
| 2482 | .execute(); |
| 2483 | } |
| 2484 | |
| 2485 | TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_HLG_HW_Uses_PQ) { |
| 2486 | // If there is mixed HLG/PQ use, and the topmost layer is PQ, then PQ is used if there |
| 2487 | // are no other special conditions. |
| 2488 | verify().ifTopLayerIs(BT2020_PQ) |
| 2489 | .andTopLayerIsREComposed(false) |
| 2490 | .andIfBottomLayerIs(BT2020_HLG) |
| 2491 | .andBottomLayerIsREComposed(false) |
| 2492 | .andIfLegacySupportFor(BT2020_PQ, false) |
| 2493 | .thenExpectBestColorModeCallUses(BT2020_PQ) |
| 2494 | .execute(); |
| 2495 | } |
| 2496 | |
| 2497 | TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_HLG_HW_IfPQHasLegacySupport_Uses_DisplayP3) { |
| 2498 | // BT2020_PQ is not used if there is only legacy support for it. |
| 2499 | verify().ifTopLayerIs(BT2020_PQ) |
| 2500 | .andTopLayerIsREComposed(false) |
| 2501 | .andIfBottomLayerIs(BT2020_HLG) |
| 2502 | .andBottomLayerIsREComposed(false) |
| 2503 | .andIfLegacySupportFor(BT2020_PQ, true) |
| 2504 | .thenExpectBestColorModeCallUses(DISPLAY_P3) |
| 2505 | .execute(); |
| 2506 | } |
| 2507 | |
| 2508 | TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_HLG_RE_Uses_PQ) { |
| 2509 | // BT2020_PQ is used if the bottom HLG layer is RenderEngine composed. |
| 2510 | verify().ifTopLayerIs(BT2020_PQ) |
| 2511 | .andTopLayerIsREComposed(false) |
| 2512 | .andIfBottomLayerIs(BT2020_HLG) |
| 2513 | .andBottomLayerIsREComposed(true) |
| 2514 | .andIfLegacySupportFor(BT2020_PQ, false) |
| 2515 | .thenExpectBestColorModeCallUses(BT2020_PQ) |
| 2516 | .execute(); |
| 2517 | } |
| 2518 | |
| 2519 | TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_RE_On_HLG_HW_Uses_DisplayP3) { |
| 2520 | // BT2020_PQ is not used if the top PQ layer is RenderEngine composed. |
| 2521 | verify().ifTopLayerIs(BT2020_PQ) |
| 2522 | .andTopLayerIsREComposed(true) |
| 2523 | .andIfBottomLayerIs(BT2020_HLG) |
| 2524 | .andBottomLayerIsREComposed(false) |
| 2525 | .andIfLegacySupportFor(BT2020_PQ, false) |
| 2526 | .thenExpectBestColorModeCallUses(DISPLAY_P3) |
| 2527 | .execute(); |
| 2528 | } |
| 2529 | |
| 2530 | TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_PQ_HW_Uses_PQ) { |
| 2531 | // If there is mixed HLG/PQ use, and the topmost layer is HLG, then PQ is |
| 2532 | // used if there are no other special conditions. |
| 2533 | verify().ifTopLayerIs(BT2020_HLG) |
| 2534 | .andTopLayerIsREComposed(false) |
| 2535 | .andIfBottomLayerIs(BT2020_PQ) |
| 2536 | .andBottomLayerIsREComposed(false) |
| 2537 | .andIfLegacySupportFor(BT2020_PQ, false) |
| 2538 | .thenExpectBestColorModeCallUses(BT2020_PQ) |
| 2539 | .execute(); |
| 2540 | } |
| 2541 | |
| 2542 | TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_PQ_HW_IfPQHasLegacySupport_Uses_DisplayP3) { |
| 2543 | // BT2020_PQ is not used if there is only legacy support for it. |
| 2544 | verify().ifTopLayerIs(BT2020_HLG) |
| 2545 | .andTopLayerIsREComposed(false) |
| 2546 | .andIfBottomLayerIs(BT2020_PQ) |
| 2547 | .andBottomLayerIsREComposed(false) |
| 2548 | .andIfLegacySupportFor(BT2020_PQ, true) |
| 2549 | .thenExpectBestColorModeCallUses(DISPLAY_P3) |
| 2550 | .execute(); |
| 2551 | } |
| 2552 | |
| 2553 | TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_PQ_RE_Uses_DisplayP3) { |
| 2554 | // BT2020_PQ is not used if the bottom PQ layer is RenderEngine composed. |
| 2555 | verify().ifTopLayerIs(BT2020_HLG) |
| 2556 | .andTopLayerIsREComposed(false) |
| 2557 | .andIfBottomLayerIs(BT2020_PQ) |
| 2558 | .andBottomLayerIsREComposed(true) |
| 2559 | .andIfLegacySupportFor(BT2020_PQ, false) |
| 2560 | .thenExpectBestColorModeCallUses(DISPLAY_P3) |
| 2561 | .execute(); |
| 2562 | } |
| 2563 | |
| 2564 | TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_RE_On_PQ_HW_Uses_PQ) { |
| 2565 | // BT2020_PQ is still used if the top HLG layer is RenderEngine composed. |
| 2566 | verify().ifTopLayerIs(BT2020_HLG) |
| 2567 | .andTopLayerIsREComposed(true) |
| 2568 | .andIfBottomLayerIs(BT2020_PQ) |
| 2569 | .andBottomLayerIsREComposed(false) |
| 2570 | .andIfLegacySupportFor(BT2020_PQ, false) |
| 2571 | .thenExpectBestColorModeCallUses(BT2020_PQ) |
| 2572 | .execute(); |
| 2573 | } |
| 2574 | |
| 2575 | TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_HLG_HW_Uses_HLG) { |
| 2576 | // If all layers use HLG then HLG is used if there are no other special |
| 2577 | // conditions. |
| 2578 | verify().ifTopLayerIs(BT2020_HLG) |
| 2579 | .andTopLayerIsREComposed(false) |
| 2580 | .andIfBottomLayerIs(BT2020_HLG) |
| 2581 | .andBottomLayerIsREComposed(false) |
| 2582 | .andIfLegacySupportFor(BT2020_HLG, false) |
| 2583 | .thenExpectBestColorModeCallUses(BT2020_HLG) |
| 2584 | .execute(); |
| 2585 | } |
| 2586 | |
| 2587 | TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_HLG_HW_IfPQHasLegacySupport_Uses_DisplayP3) { |
| 2588 | // BT2020_HLG is not used if there is legacy support for it. |
| 2589 | verify().ifTopLayerIs(BT2020_HLG) |
| 2590 | .andTopLayerIsREComposed(false) |
| 2591 | .andIfBottomLayerIs(BT2020_HLG) |
| 2592 | .andBottomLayerIsREComposed(false) |
| 2593 | .andIfLegacySupportFor(BT2020_HLG, true) |
| 2594 | .thenExpectBestColorModeCallUses(DISPLAY_P3) |
| 2595 | .execute(); |
| 2596 | } |
| 2597 | |
| 2598 | TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_HLG_RE_Uses_HLG) { |
| 2599 | // BT2020_HLG is used even if the bottom layer is client composed. |
| 2600 | verify().ifTopLayerIs(BT2020_HLG) |
| 2601 | .andTopLayerIsREComposed(false) |
| 2602 | .andIfBottomLayerIs(BT2020_HLG) |
| 2603 | .andBottomLayerIsREComposed(true) |
| 2604 | .andIfLegacySupportFor(BT2020_HLG, false) |
| 2605 | .thenExpectBestColorModeCallUses(BT2020_HLG) |
| 2606 | .execute(); |
| 2607 | } |
| 2608 | |
| 2609 | TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_RE_On_HLG_HW_Uses_HLG) { |
| 2610 | // BT2020_HLG is used even if the top layer is client composed. |
| 2611 | verify().ifTopLayerIs(BT2020_HLG) |
| 2612 | .andTopLayerIsREComposed(true) |
| 2613 | .andIfBottomLayerIs(BT2020_HLG) |
| 2614 | .andBottomLayerIsREComposed(false) |
| 2615 | .andIfLegacySupportFor(BT2020_HLG, false) |
| 2616 | .thenExpectBestColorModeCallUses(BT2020_HLG) |
| 2617 | .execute(); |
| 2618 | } |
| 2619 | |
| 2620 | TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_NonHdr_HW_Uses_PQ) { |
| 2621 | // Even if there are non-HDR layers present, BT2020_PQ can still be used. |
| 2622 | verify().ifTopLayerIs(BT2020_PQ) |
| 2623 | .andTopLayerIsREComposed(false) |
| 2624 | .andIfBottomLayerIsNotHdr() |
| 2625 | .andBottomLayerIsREComposed(false) |
| 2626 | .andIfLegacySupportFor(BT2020_PQ, false) |
| 2627 | .thenExpectBestColorModeCallUses(BT2020_PQ) |
| 2628 | .execute(); |
| 2629 | } |
| 2630 | |
| 2631 | TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_NonHdr_RE_Uses_HLG) { |
| 2632 | // If all layers use HLG then HLG is used if there are no other special |
| 2633 | // conditions. |
| 2634 | verify().ifTopLayerIs(BT2020_HLG) |
| 2635 | .andTopLayerIsREComposed(false) |
| 2636 | .andIfBottomLayerIsNotHdr() |
| 2637 | .andBottomLayerIsREComposed(true) |
| 2638 | .andIfLegacySupportFor(BT2020_HLG, false) |
| 2639 | .thenExpectBestColorModeCallUses(BT2020_HLG) |
| 2640 | .execute(); |
| 2641 | } |
| 2642 | |
| 2643 | struct OutputUpdateColorProfile_AffectsChosenRenderIntentTest |
| 2644 | : public OutputUpdateColorProfileTest { |
| 2645 | // The various values for CompositionRefreshArgs::outputColorSetting affect |
| 2646 | // the chosen renderIntent, along with whether the preferred dataspace is an |
| 2647 | // HDR dataspace or not. |
| 2648 | |
| 2649 | OutputUpdateColorProfile_AffectsChosenRenderIntentTest() { |
| 2650 | mRefreshArgs.outputColorSetting = OutputColorSetting::kEnhanced; |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 2651 | mLayer1.mLayerFEState.dataspace = ui::Dataspace::BT2020_PQ; |
Lloyd Pique | 0a45623 | 2020-01-16 17:51:13 -0800 | [diff] [blame] | 2652 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(1u)); |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 2653 | EXPECT_CALL(mOutput, setColorProfile(_)).WillRepeatedly(Return()); |
| 2654 | EXPECT_CALL(*mDisplayColorProfile, hasLegacyHdrSupport(ui::Dataspace::BT2020_PQ)) |
| 2655 | .WillRepeatedly(Return(false)); |
| 2656 | } |
| 2657 | |
| 2658 | // The tests here involve enough state and GMock setup that using a mini-DSL |
| 2659 | // makes the tests much more readable, and allows the test to focus more on |
| 2660 | // the intent than on some of the details. |
| 2661 | |
| 2662 | static constexpr ui::Dataspace kNonHdrDataspace = ui::Dataspace::DISPLAY_P3; |
| 2663 | static constexpr ui::Dataspace kHdrDataspace = ui::Dataspace::BT2020_PQ; |
| 2664 | |
| 2665 | struct IfDataspaceChosenState |
| 2666 | : public CallOrderStateMachineHelper<TestType, IfDataspaceChosenState> { |
| 2667 | [[nodiscard]] auto ifDataspaceChosenIs(ui::Dataspace dataspace) { |
| 2668 | getInstance()->mLayer1.mLayerFEState.dataspace = dataspace; |
| 2669 | return nextState<AndOutputColorSettingState>(); |
| 2670 | } |
| 2671 | [[nodiscard]] auto ifDataspaceChosenIsNonHdr() { |
| 2672 | return ifDataspaceChosenIs(kNonHdrDataspace); |
| 2673 | } |
| 2674 | [[nodiscard]] auto ifDataspaceChosenIsHdr() { return ifDataspaceChosenIs(kHdrDataspace); } |
| 2675 | }; |
| 2676 | |
| 2677 | struct AndOutputColorSettingState |
| 2678 | : public CallOrderStateMachineHelper<TestType, AndOutputColorSettingState> { |
| 2679 | [[nodiscard]] auto andOutputColorSettingIs(OutputColorSetting setting) { |
| 2680 | getInstance()->mRefreshArgs.outputColorSetting = setting; |
| 2681 | return nextState<ThenExpectBestColorModeCallUsesState>(); |
| 2682 | } |
| 2683 | }; |
| 2684 | |
| 2685 | struct ThenExpectBestColorModeCallUsesState |
| 2686 | : public CallOrderStateMachineHelper<TestType, ThenExpectBestColorModeCallUsesState> { |
| 2687 | [[nodiscard]] auto thenExpectBestColorModeCallUses(ui::RenderIntent intent) { |
| 2688 | EXPECT_CALL(*getInstance()->mDisplayColorProfile, |
| 2689 | getBestColorMode(getInstance()->mLayer1.mLayerFEState.dataspace, intent, _, |
| 2690 | _, _)); |
| 2691 | return nextState<ExecuteState>(); |
| 2692 | } |
| 2693 | }; |
| 2694 | |
| 2695 | // Tests call one of these two helper member functions to start using the |
| 2696 | // mini-DSL defined above. |
| 2697 | [[nodiscard]] auto verify() { return IfDataspaceChosenState::make(this); } |
| 2698 | }; |
| 2699 | |
| 2700 | TEST_F(OutputUpdateColorProfile_AffectsChosenRenderIntentTest, |
| 2701 | Managed_NonHdr_Prefers_Colorimetric) { |
| 2702 | verify().ifDataspaceChosenIsNonHdr() |
| 2703 | .andOutputColorSettingIs(OutputColorSetting::kManaged) |
| 2704 | .thenExpectBestColorModeCallUses(ui::RenderIntent::COLORIMETRIC) |
| 2705 | .execute(); |
| 2706 | } |
| 2707 | |
| 2708 | TEST_F(OutputUpdateColorProfile_AffectsChosenRenderIntentTest, |
| 2709 | Managed_Hdr_Prefers_ToneMapColorimetric) { |
| 2710 | verify().ifDataspaceChosenIsHdr() |
| 2711 | .andOutputColorSettingIs(OutputColorSetting::kManaged) |
| 2712 | .thenExpectBestColorModeCallUses(ui::RenderIntent::TONE_MAP_COLORIMETRIC) |
| 2713 | .execute(); |
| 2714 | } |
| 2715 | |
| 2716 | TEST_F(OutputUpdateColorProfile_AffectsChosenRenderIntentTest, Enhanced_NonHdr_Prefers_Enhance) { |
| 2717 | verify().ifDataspaceChosenIsNonHdr() |
| 2718 | .andOutputColorSettingIs(OutputColorSetting::kEnhanced) |
| 2719 | .thenExpectBestColorModeCallUses(ui::RenderIntent::ENHANCE) |
| 2720 | .execute(); |
| 2721 | } |
| 2722 | |
| 2723 | TEST_F(OutputUpdateColorProfile_AffectsChosenRenderIntentTest, |
| 2724 | Enhanced_Hdr_Prefers_ToneMapEnhance) { |
| 2725 | verify().ifDataspaceChosenIsHdr() |
| 2726 | .andOutputColorSettingIs(OutputColorSetting::kEnhanced) |
| 2727 | .thenExpectBestColorModeCallUses(ui::RenderIntent::TONE_MAP_ENHANCE) |
| 2728 | .execute(); |
| 2729 | } |
| 2730 | |
| 2731 | TEST_F(OutputUpdateColorProfile_AffectsChosenRenderIntentTest, Vendor_NonHdr_Prefers_Vendor) { |
| 2732 | verify().ifDataspaceChosenIsNonHdr() |
| 2733 | .andOutputColorSettingIs(kVendorSpecifiedOutputColorSetting) |
| 2734 | .thenExpectBestColorModeCallUses( |
| 2735 | static_cast<ui::RenderIntent>(kVendorSpecifiedOutputColorSetting)) |
| 2736 | .execute(); |
| 2737 | } |
| 2738 | |
| 2739 | TEST_F(OutputUpdateColorProfile_AffectsChosenRenderIntentTest, Vendor_Hdr_Prefers_Vendor) { |
| 2740 | verify().ifDataspaceChosenIsHdr() |
| 2741 | .andOutputColorSettingIs(kVendorSpecifiedOutputColorSetting) |
| 2742 | .thenExpectBestColorModeCallUses( |
| 2743 | static_cast<ui::RenderIntent>(kVendorSpecifiedOutputColorSetting)) |
| 2744 | .execute(); |
| 2745 | } |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 2746 | |
| 2747 | /* |
| 2748 | * Output::beginFrame() |
| 2749 | */ |
| 2750 | |
Lloyd Pique | e596595 | 2019-11-18 16:16:32 -0800 | [diff] [blame] | 2751 | struct OutputBeginFrameTest : public ::testing::Test { |
| 2752 | using TestType = OutputBeginFrameTest; |
| 2753 | |
| 2754 | struct OutputPartialMock : public OutputPartialMockBase { |
Lloyd Pique | 739afaf | 2019-11-21 16:40:05 -0800 | [diff] [blame] | 2755 | // Sets up the helper functions called by the function under test to use |
| 2756 | // mock implementations. |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2757 | MOCK_METHOD(Region, getDirtyRegion, (), (const)); |
Lloyd Pique | e596595 | 2019-11-18 16:16:32 -0800 | [diff] [blame] | 2758 | }; |
| 2759 | |
| 2760 | OutputBeginFrameTest() { |
| 2761 | mOutput.setDisplayColorProfileForTest( |
| 2762 | std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile)); |
| 2763 | mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface)); |
| 2764 | } |
| 2765 | |
| 2766 | struct IfGetDirtyRegionExpectationState |
| 2767 | : public CallOrderStateMachineHelper<TestType, IfGetDirtyRegionExpectationState> { |
| 2768 | [[nodiscard]] auto ifGetDirtyRegionReturns(Region dirtyRegion) { |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2769 | EXPECT_CALL(getInstance()->mOutput, getDirtyRegion()).WillOnce(Return(dirtyRegion)); |
Lloyd Pique | e596595 | 2019-11-18 16:16:32 -0800 | [diff] [blame] | 2770 | return nextState<AndIfGetOutputLayerCountExpectationState>(); |
| 2771 | } |
| 2772 | }; |
| 2773 | |
| 2774 | struct AndIfGetOutputLayerCountExpectationState |
| 2775 | : public CallOrderStateMachineHelper<TestType, AndIfGetOutputLayerCountExpectationState> { |
| 2776 | [[nodiscard]] auto andIfGetOutputLayerCountReturns(size_t layerCount) { |
| 2777 | EXPECT_CALL(getInstance()->mOutput, getOutputLayerCount()).WillOnce(Return(layerCount)); |
| 2778 | return nextState<AndIfLastCompositionHadVisibleLayersState>(); |
| 2779 | } |
| 2780 | }; |
| 2781 | |
| 2782 | struct AndIfLastCompositionHadVisibleLayersState |
| 2783 | : public CallOrderStateMachineHelper<TestType, |
| 2784 | AndIfLastCompositionHadVisibleLayersState> { |
| 2785 | [[nodiscard]] auto andIfLastCompositionHadVisibleLayersIs(bool hadOutputLayers) { |
| 2786 | getInstance()->mOutput.mState.lastCompositionHadVisibleLayers = hadOutputLayers; |
| 2787 | return nextState<ThenExpectRenderSurfaceBeginFrameCallState>(); |
| 2788 | } |
| 2789 | }; |
| 2790 | |
| 2791 | struct ThenExpectRenderSurfaceBeginFrameCallState |
| 2792 | : public CallOrderStateMachineHelper<TestType, |
| 2793 | ThenExpectRenderSurfaceBeginFrameCallState> { |
| 2794 | [[nodiscard]] auto thenExpectRenderSurfaceBeginFrameCall(bool mustRecompose) { |
| 2795 | EXPECT_CALL(*getInstance()->mRenderSurface, beginFrame(mustRecompose)); |
| 2796 | return nextState<ExecuteState>(); |
| 2797 | } |
| 2798 | }; |
| 2799 | |
| 2800 | struct ExecuteState : public CallOrderStateMachineHelper<TestType, ExecuteState> { |
| 2801 | [[nodiscard]] auto execute() { |
| 2802 | getInstance()->mOutput.beginFrame(); |
| 2803 | return nextState<CheckPostconditionHadVisibleLayersState>(); |
| 2804 | } |
| 2805 | }; |
| 2806 | |
| 2807 | struct CheckPostconditionHadVisibleLayersState |
| 2808 | : public CallOrderStateMachineHelper<TestType, CheckPostconditionHadVisibleLayersState> { |
| 2809 | void checkPostconditionHadVisibleLayers(bool expected) { |
| 2810 | EXPECT_EQ(expected, getInstance()->mOutput.mState.lastCompositionHadVisibleLayers); |
| 2811 | } |
| 2812 | }; |
| 2813 | |
| 2814 | // Tests call one of these two helper member functions to start using the |
| 2815 | // mini-DSL defined above. |
| 2816 | [[nodiscard]] auto verify() { return IfGetDirtyRegionExpectationState::make(this); } |
| 2817 | |
| 2818 | static const Region kEmptyRegion; |
| 2819 | static const Region kNotEmptyRegion; |
| 2820 | |
| 2821 | mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>(); |
| 2822 | mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>(); |
| 2823 | StrictMock<OutputPartialMock> mOutput; |
| 2824 | }; |
| 2825 | |
| 2826 | const Region OutputBeginFrameTest::kEmptyRegion{Rect{0, 0, 0, 0}}; |
| 2827 | const Region OutputBeginFrameTest::kNotEmptyRegion{Rect{0, 0, 1, 1}}; |
| 2828 | |
| 2829 | TEST_F(OutputBeginFrameTest, hasDirtyHasLayersHadLayersLastFrame) { |
| 2830 | verify().ifGetDirtyRegionReturns(kNotEmptyRegion) |
| 2831 | .andIfGetOutputLayerCountReturns(1u) |
| 2832 | .andIfLastCompositionHadVisibleLayersIs(true) |
| 2833 | .thenExpectRenderSurfaceBeginFrameCall(true) |
| 2834 | .execute() |
| 2835 | .checkPostconditionHadVisibleLayers(true); |
| 2836 | } |
| 2837 | |
| 2838 | TEST_F(OutputBeginFrameTest, hasDirtyNotHasLayersHadLayersLastFrame) { |
| 2839 | verify().ifGetDirtyRegionReturns(kNotEmptyRegion) |
| 2840 | .andIfGetOutputLayerCountReturns(0u) |
| 2841 | .andIfLastCompositionHadVisibleLayersIs(true) |
| 2842 | .thenExpectRenderSurfaceBeginFrameCall(true) |
| 2843 | .execute() |
| 2844 | .checkPostconditionHadVisibleLayers(false); |
| 2845 | } |
| 2846 | |
| 2847 | TEST_F(OutputBeginFrameTest, hasDirtyHasLayersNotHadLayersLastFrame) { |
| 2848 | verify().ifGetDirtyRegionReturns(kNotEmptyRegion) |
| 2849 | .andIfGetOutputLayerCountReturns(1u) |
| 2850 | .andIfLastCompositionHadVisibleLayersIs(false) |
| 2851 | .thenExpectRenderSurfaceBeginFrameCall(true) |
| 2852 | .execute() |
| 2853 | .checkPostconditionHadVisibleLayers(true); |
| 2854 | } |
| 2855 | |
| 2856 | TEST_F(OutputBeginFrameTest, hasDirtyNotHasLayersNotHadLayersLastFrame) { |
| 2857 | verify().ifGetDirtyRegionReturns(kNotEmptyRegion) |
| 2858 | .andIfGetOutputLayerCountReturns(0u) |
| 2859 | .andIfLastCompositionHadVisibleLayersIs(false) |
| 2860 | .thenExpectRenderSurfaceBeginFrameCall(false) |
| 2861 | .execute() |
| 2862 | .checkPostconditionHadVisibleLayers(false); |
| 2863 | } |
| 2864 | |
| 2865 | TEST_F(OutputBeginFrameTest, notHasDirtyHasLayersHadLayersLastFrame) { |
| 2866 | verify().ifGetDirtyRegionReturns(kEmptyRegion) |
| 2867 | .andIfGetOutputLayerCountReturns(1u) |
| 2868 | .andIfLastCompositionHadVisibleLayersIs(true) |
| 2869 | .thenExpectRenderSurfaceBeginFrameCall(false) |
| 2870 | .execute() |
| 2871 | .checkPostconditionHadVisibleLayers(true); |
| 2872 | } |
| 2873 | |
| 2874 | TEST_F(OutputBeginFrameTest, notHasDirtyNotHasLayersHadLayersLastFrame) { |
| 2875 | verify().ifGetDirtyRegionReturns(kEmptyRegion) |
| 2876 | .andIfGetOutputLayerCountReturns(0u) |
| 2877 | .andIfLastCompositionHadVisibleLayersIs(true) |
| 2878 | .thenExpectRenderSurfaceBeginFrameCall(false) |
| 2879 | .execute() |
| 2880 | .checkPostconditionHadVisibleLayers(true); |
| 2881 | } |
| 2882 | |
| 2883 | TEST_F(OutputBeginFrameTest, notHasDirtyHasLayersNotHadLayersLastFrame) { |
| 2884 | verify().ifGetDirtyRegionReturns(kEmptyRegion) |
| 2885 | .andIfGetOutputLayerCountReturns(1u) |
| 2886 | .andIfLastCompositionHadVisibleLayersIs(false) |
| 2887 | .thenExpectRenderSurfaceBeginFrameCall(false) |
| 2888 | .execute() |
| 2889 | .checkPostconditionHadVisibleLayers(false); |
| 2890 | } |
| 2891 | |
| 2892 | TEST_F(OutputBeginFrameTest, notHasDirtyNotHasLayersNotHadLayersLastFrame) { |
| 2893 | verify().ifGetDirtyRegionReturns(kEmptyRegion) |
| 2894 | .andIfGetOutputLayerCountReturns(0u) |
| 2895 | .andIfLastCompositionHadVisibleLayersIs(false) |
| 2896 | .thenExpectRenderSurfaceBeginFrameCall(false) |
| 2897 | .execute() |
| 2898 | .checkPostconditionHadVisibleLayers(false); |
| 2899 | } |
| 2900 | |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 2901 | /* |
| 2902 | * Output::devOptRepaintFlash() |
| 2903 | */ |
| 2904 | |
Lloyd Pique | db462d8 | 2019-11-19 17:58:46 -0800 | [diff] [blame] | 2905 | struct OutputDevOptRepaintFlashTest : public testing::Test { |
| 2906 | struct OutputPartialMock : public OutputPartialMockBase { |
Lloyd Pique | 739afaf | 2019-11-21 16:40:05 -0800 | [diff] [blame] | 2907 | // Sets up the helper functions called by the function under test to use |
| 2908 | // mock implementations. |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2909 | MOCK_METHOD(Region, getDirtyRegion, (), (const)); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 2910 | MOCK_METHOD3(composeSurfaces, |
| 2911 | std::optional<base::unique_fd>(const Region&, |
| 2912 | std::shared_ptr<renderengine::ExternalTexture>, |
| 2913 | base::unique_fd&)); |
Leon Scroggins III | c1623d1 | 2023-11-06 15:31:05 -0500 | [diff] [blame] | 2914 | MOCK_METHOD0(presentFrameAndReleaseLayers, void()); |
Lloyd Pique | db462d8 | 2019-11-19 17:58:46 -0800 | [diff] [blame] | 2915 | MOCK_METHOD0(prepareFrame, void()); |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 2916 | MOCK_METHOD0(updateProtectedContentState, void()); |
| 2917 | MOCK_METHOD2(dequeueRenderBuffer, |
| 2918 | bool(base::unique_fd*, std::shared_ptr<renderengine::ExternalTexture>*)); |
Lloyd Pique | db462d8 | 2019-11-19 17:58:46 -0800 | [diff] [blame] | 2919 | }; |
| 2920 | |
| 2921 | OutputDevOptRepaintFlashTest() { |
| 2922 | mOutput.setDisplayColorProfileForTest( |
| 2923 | std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile)); |
| 2924 | mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface)); |
| 2925 | } |
| 2926 | |
| 2927 | static const Region kEmptyRegion; |
| 2928 | static const Region kNotEmptyRegion; |
| 2929 | |
| 2930 | StrictMock<OutputPartialMock> mOutput; |
| 2931 | mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>(); |
| 2932 | mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>(); |
| 2933 | CompositionRefreshArgs mRefreshArgs; |
| 2934 | }; |
| 2935 | |
| 2936 | const Region OutputDevOptRepaintFlashTest::kEmptyRegion{Rect{0, 0, 0, 0}}; |
| 2937 | const Region OutputDevOptRepaintFlashTest::kNotEmptyRegion{Rect{0, 0, 1, 1}}; |
| 2938 | |
| 2939 | TEST_F(OutputDevOptRepaintFlashTest, doesNothingIfFlashDelayNotSet) { |
| 2940 | mRefreshArgs.devOptFlashDirtyRegionsDelay = {}; |
Lloyd Pique | db462d8 | 2019-11-19 17:58:46 -0800 | [diff] [blame] | 2941 | mOutput.mState.isEnabled = true; |
| 2942 | |
| 2943 | mOutput.devOptRepaintFlash(mRefreshArgs); |
| 2944 | } |
| 2945 | |
| 2946 | TEST_F(OutputDevOptRepaintFlashTest, postsAndPreparesANewFrameIfNotEnabled) { |
| 2947 | mRefreshArgs.devOptFlashDirtyRegionsDelay = std::chrono::microseconds(1); |
Lloyd Pique | db462d8 | 2019-11-19 17:58:46 -0800 | [diff] [blame] | 2948 | mOutput.mState.isEnabled = false; |
| 2949 | |
| 2950 | InSequence seq; |
Leon Scroggins III | c1623d1 | 2023-11-06 15:31:05 -0500 | [diff] [blame] | 2951 | EXPECT_CALL(mOutput, presentFrameAndReleaseLayers()); |
Lloyd Pique | db462d8 | 2019-11-19 17:58:46 -0800 | [diff] [blame] | 2952 | EXPECT_CALL(mOutput, prepareFrame()); |
| 2953 | |
| 2954 | mOutput.devOptRepaintFlash(mRefreshArgs); |
| 2955 | } |
| 2956 | |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2957 | TEST_F(OutputDevOptRepaintFlashTest, postsAndPreparesANewFrameIfEnabled) { |
Lloyd Pique | db462d8 | 2019-11-19 17:58:46 -0800 | [diff] [blame] | 2958 | mRefreshArgs.devOptFlashDirtyRegionsDelay = std::chrono::microseconds(1); |
Lloyd Pique | db462d8 | 2019-11-19 17:58:46 -0800 | [diff] [blame] | 2959 | mOutput.mState.isEnabled = true; |
| 2960 | |
| 2961 | InSequence seq; |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2962 | EXPECT_CALL(mOutput, getDirtyRegion()).WillOnce(Return(kEmptyRegion)); |
Leon Scroggins III | c1623d1 | 2023-11-06 15:31:05 -0500 | [diff] [blame] | 2963 | EXPECT_CALL(mOutput, presentFrameAndReleaseLayers()); |
Lloyd Pique | db462d8 | 2019-11-19 17:58:46 -0800 | [diff] [blame] | 2964 | EXPECT_CALL(mOutput, prepareFrame()); |
| 2965 | |
| 2966 | mOutput.devOptRepaintFlash(mRefreshArgs); |
| 2967 | } |
| 2968 | |
| 2969 | TEST_F(OutputDevOptRepaintFlashTest, alsoComposesSurfacesAndQueuesABufferIfDirty) { |
| 2970 | mRefreshArgs.devOptFlashDirtyRegionsDelay = std::chrono::microseconds(1); |
Lloyd Pique | db462d8 | 2019-11-19 17:58:46 -0800 | [diff] [blame] | 2971 | mOutput.mState.isEnabled = true; |
| 2972 | |
| 2973 | InSequence seq; |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2974 | EXPECT_CALL(mOutput, getDirtyRegion()).WillOnce(Return(kNotEmptyRegion)); |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 2975 | EXPECT_CALL(mOutput, updateProtectedContentState()); |
| 2976 | EXPECT_CALL(mOutput, dequeueRenderBuffer(_, _)); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 2977 | EXPECT_CALL(mOutput, composeSurfaces(RegionEq(kNotEmptyRegion), _, _)); |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 2978 | EXPECT_CALL(*mRenderSurface, queueBuffer(_, 1.f)); |
Leon Scroggins III | c1623d1 | 2023-11-06 15:31:05 -0500 | [diff] [blame] | 2979 | EXPECT_CALL(mOutput, presentFrameAndReleaseLayers()); |
Lloyd Pique | db462d8 | 2019-11-19 17:58:46 -0800 | [diff] [blame] | 2980 | EXPECT_CALL(mOutput, prepareFrame()); |
| 2981 | |
| 2982 | mOutput.devOptRepaintFlash(mRefreshArgs); |
| 2983 | } |
| 2984 | |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 2985 | /* |
| 2986 | * Output::finishFrame() |
| 2987 | */ |
| 2988 | |
Lloyd Pique | 03561a6 | 2019-11-19 18:34:52 -0800 | [diff] [blame] | 2989 | struct OutputFinishFrameTest : public testing::Test { |
| 2990 | struct OutputPartialMock : public OutputPartialMockBase { |
Lloyd Pique | 739afaf | 2019-11-21 16:40:05 -0800 | [diff] [blame] | 2991 | // Sets up the helper functions called by the function under test to use |
| 2992 | // mock implementations. |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 2993 | MOCK_METHOD3(composeSurfaces, |
| 2994 | std::optional<base::unique_fd>(const Region&, |
| 2995 | std::shared_ptr<renderengine::ExternalTexture>, |
| 2996 | base::unique_fd&)); |
Leon Scroggins III | c1623d1 | 2023-11-06 15:31:05 -0500 | [diff] [blame] | 2997 | MOCK_METHOD0(presentFrameAndReleaseLayers, void()); |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 2998 | MOCK_METHOD0(updateProtectedContentState, void()); |
| 2999 | MOCK_METHOD2(dequeueRenderBuffer, |
| 3000 | bool(base::unique_fd*, std::shared_ptr<renderengine::ExternalTexture>*)); |
Xiang Wang | aab3116 | 2024-03-12 19:48:08 -0700 | [diff] [blame] | 3001 | MOCK_METHOD(void, setHintSessionGpuFence, (std::unique_ptr<FenceTime> && gpuFence), |
| 3002 | (override)); |
| 3003 | MOCK_METHOD(bool, isPowerHintSessionEnabled, (), (override)); |
Lloyd Pique | 03561a6 | 2019-11-19 18:34:52 -0800 | [diff] [blame] | 3004 | }; |
| 3005 | |
| 3006 | OutputFinishFrameTest() { |
| 3007 | mOutput.setDisplayColorProfileForTest( |
| 3008 | std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile)); |
| 3009 | mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface)); |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 3010 | EXPECT_CALL(mOutput, getCompositionEngine()).WillRepeatedly(ReturnRef(mCompositionEngine)); |
| 3011 | EXPECT_CALL(mCompositionEngine, getRenderEngine()).WillRepeatedly(ReturnRef(mRenderEngine)); |
Xiang Wang | aab3116 | 2024-03-12 19:48:08 -0700 | [diff] [blame] | 3012 | EXPECT_CALL(mOutput, isPowerHintSessionEnabled()).WillRepeatedly(Return(true)); |
Lloyd Pique | 03561a6 | 2019-11-19 18:34:52 -0800 | [diff] [blame] | 3013 | } |
| 3014 | |
| 3015 | StrictMock<OutputPartialMock> mOutput; |
| 3016 | mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>(); |
| 3017 | mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>(); |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 3018 | StrictMock<mock::CompositionEngine> mCompositionEngine; |
| 3019 | StrictMock<renderengine::mock::RenderEngine> mRenderEngine; |
Lloyd Pique | 03561a6 | 2019-11-19 18:34:52 -0800 | [diff] [blame] | 3020 | }; |
| 3021 | |
| 3022 | TEST_F(OutputFinishFrameTest, ifNotEnabledDoesNothing) { |
| 3023 | mOutput.mState.isEnabled = false; |
| 3024 | |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 3025 | impl::GpuCompositionResult result; |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 3026 | mOutput.finishFrame(std::move(result)); |
Lloyd Pique | 03561a6 | 2019-11-19 18:34:52 -0800 | [diff] [blame] | 3027 | } |
| 3028 | |
| 3029 | TEST_F(OutputFinishFrameTest, takesEarlyOutifComposeSurfacesReturnsNoFence) { |
Xiang Wang | cf61e73 | 2024-03-22 11:05:28 -0700 | [diff] [blame] | 3030 | SET_FLAG_FOR_TEST(flags::adpf_gpu_sf, true); |
Lloyd Pique | 03561a6 | 2019-11-19 18:34:52 -0800 | [diff] [blame] | 3031 | mOutput.mState.isEnabled = true; |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 3032 | EXPECT_CALL(mOutput, updateProtectedContentState()); |
| 3033 | EXPECT_CALL(mOutput, dequeueRenderBuffer(_, _)).WillOnce(Return(true)); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 3034 | EXPECT_CALL(mOutput, composeSurfaces(RegionEq(Region::INVALID_REGION), _, _)); |
Lloyd Pique | 03561a6 | 2019-11-19 18:34:52 -0800 | [diff] [blame] | 3035 | |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 3036 | impl::GpuCompositionResult result; |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 3037 | mOutput.finishFrame(std::move(result)); |
Lloyd Pique | 03561a6 | 2019-11-19 18:34:52 -0800 | [diff] [blame] | 3038 | } |
| 3039 | |
Xiang Wang | cf61e73 | 2024-03-22 11:05:28 -0700 | [diff] [blame] | 3040 | TEST_F(OutputFinishFrameTest, queuesBufferIfComposeSurfacesReturnsAFenceWithAdpfGpuOff) { |
| 3041 | SET_FLAG_FOR_TEST(flags::adpf_gpu_sf, false); |
Lloyd Pique | 03561a6 | 2019-11-19 18:34:52 -0800 | [diff] [blame] | 3042 | mOutput.mState.isEnabled = true; |
| 3043 | |
| 3044 | InSequence seq; |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 3045 | EXPECT_CALL(mOutput, updateProtectedContentState()); |
| 3046 | EXPECT_CALL(mOutput, dequeueRenderBuffer(_, _)).WillOnce(Return(true)); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 3047 | EXPECT_CALL(mOutput, composeSurfaces(RegionEq(Region::INVALID_REGION), _, _)) |
Lloyd Pique | 03561a6 | 2019-11-19 18:34:52 -0800 | [diff] [blame] | 3048 | .WillOnce(Return(ByMove(base::unique_fd()))); |
Xiang Wang | aab3116 | 2024-03-12 19:48:08 -0700 | [diff] [blame] | 3049 | EXPECT_CALL(mOutput, setHintSessionGpuFence(_)); |
| 3050 | EXPECT_CALL(*mRenderSurface, queueBuffer(_, 1.f)); |
| 3051 | |
| 3052 | impl::GpuCompositionResult result; |
| 3053 | mOutput.finishFrame(std::move(result)); |
| 3054 | } |
| 3055 | |
Xiang Wang | cf61e73 | 2024-03-22 11:05:28 -0700 | [diff] [blame] | 3056 | TEST_F(OutputFinishFrameTest, queuesBufferIfComposeSurfacesReturnsAFence) { |
Xiang Wang | aab3116 | 2024-03-12 19:48:08 -0700 | [diff] [blame] | 3057 | SET_FLAG_FOR_TEST(flags::adpf_gpu_sf, true); |
| 3058 | mOutput.mState.isEnabled = true; |
| 3059 | |
| 3060 | InSequence seq; |
| 3061 | EXPECT_CALL(mOutput, updateProtectedContentState()); |
| 3062 | EXPECT_CALL(mOutput, dequeueRenderBuffer(_, _)).WillOnce(Return(true)); |
| 3063 | EXPECT_CALL(mOutput, composeSurfaces(RegionEq(Region::INVALID_REGION), _, _)) |
| 3064 | .WillOnce(Return(ByMove(base::unique_fd()))); |
| 3065 | EXPECT_CALL(mOutput, setHintSessionGpuFence(_)).Times(0); |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 3066 | EXPECT_CALL(*mRenderSurface, queueBuffer(_, 1.f)); |
| 3067 | |
| 3068 | impl::GpuCompositionResult result; |
| 3069 | mOutput.finishFrame(std::move(result)); |
| 3070 | } |
| 3071 | |
| 3072 | TEST_F(OutputFinishFrameTest, queuesBufferWithHdrSdrRatio) { |
| 3073 | SET_FLAG_FOR_TEST(flags::fp16_client_target, true); |
Xiang Wang | cf61e73 | 2024-03-22 11:05:28 -0700 | [diff] [blame] | 3074 | SET_FLAG_FOR_TEST(flags::adpf_gpu_sf, true); |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 3075 | mOutput.mState.isEnabled = true; |
| 3076 | |
| 3077 | InSequence seq; |
| 3078 | auto texture = std::make_shared< |
| 3079 | renderengine::impl:: |
| 3080 | ExternalTexture>(sp<GraphicBuffer>::make(1u, 1u, PIXEL_FORMAT_RGBA_FP16, |
| 3081 | GRALLOC_USAGE_SW_WRITE_OFTEN | |
| 3082 | GRALLOC_USAGE_SW_READ_OFTEN), |
| 3083 | mRenderEngine, |
| 3084 | renderengine::impl::ExternalTexture::Usage::READABLE | |
| 3085 | renderengine::impl::ExternalTexture::Usage::WRITEABLE); |
| 3086 | mOutput.mState.displayBrightnessNits = 400.f; |
| 3087 | mOutput.mState.sdrWhitePointNits = 200.f; |
| 3088 | mOutput.mState.dataspace = ui::Dataspace::V0_SCRGB; |
| 3089 | EXPECT_CALL(mOutput, updateProtectedContentState()); |
| 3090 | EXPECT_CALL(mOutput, dequeueRenderBuffer(_, _)) |
| 3091 | .WillOnce(DoAll(SetArgPointee<1>(texture), Return(true))); |
| 3092 | EXPECT_CALL(mOutput, composeSurfaces(RegionEq(Region::INVALID_REGION), _, _)) |
| 3093 | .WillOnce(Return(ByMove(base::unique_fd()))); |
Xiang Wang | cf61e73 | 2024-03-22 11:05:28 -0700 | [diff] [blame] | 3094 | EXPECT_CALL(mOutput, setHintSessionGpuFence(_)).Times(0); |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 3095 | EXPECT_CALL(*mRenderSurface, queueBuffer(_, 2.f)); |
Lloyd Pique | 03561a6 | 2019-11-19 18:34:52 -0800 | [diff] [blame] | 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) { |
Xiang Wang | cf61e73 | 2024-03-22 11:05:28 -0700 | [diff] [blame] | 3102 | SET_FLAG_FOR_TEST(flags::adpf_gpu_sf, true); |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 3103 | mOutput.mState.isEnabled = true; |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 3104 | mOutput.mState.strategyPrediction = CompositionStrategyPredictionState::SUCCESS; |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 3105 | InSequence seq; |
Xiang Wang | cf61e73 | 2024-03-22 11:05:28 -0700 | [diff] [blame] | 3106 | EXPECT_CALL(mOutput, setHintSessionGpuFence(_)).Times(0); |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 3107 | EXPECT_CALL(*mRenderSurface, queueBuffer(_, 1.f)); |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 3108 | |
| 3109 | impl::GpuCompositionResult result; |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 3110 | mOutput.finishFrame(std::move(result)); |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 3111 | } |
| 3112 | |
| 3113 | TEST_F(OutputFinishFrameTest, predictionFailedAndBufferIsReused) { |
Xiang Wang | cf61e73 | 2024-03-22 11:05:28 -0700 | [diff] [blame] | 3114 | SET_FLAG_FOR_TEST(flags::adpf_gpu_sf, true); |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 3115 | mOutput.mState.isEnabled = true; |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 3116 | mOutput.mState.strategyPrediction = CompositionStrategyPredictionState::FAIL; |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 3117 | |
| 3118 | InSequence seq; |
| 3119 | |
| 3120 | impl::GpuCompositionResult result; |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 3121 | result.buffer = |
| 3122 | std::make_shared<renderengine::mock::FakeExternalTexture>(1, 1, |
| 3123 | HAL_PIXEL_FORMAT_RGBA_8888, 1, |
| 3124 | 2); |
| 3125 | |
| 3126 | EXPECT_CALL(mOutput, |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 3127 | composeSurfaces(RegionEq(Region::INVALID_REGION), result.buffer, |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 3128 | Eq(ByRef(result.fence)))) |
| 3129 | .WillOnce(Return(ByMove(base::unique_fd()))); |
Xiang Wang | cf61e73 | 2024-03-22 11:05:28 -0700 | [diff] [blame] | 3130 | EXPECT_CALL(mOutput, setHintSessionGpuFence(_)).Times(0); |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 3131 | EXPECT_CALL(*mRenderSurface, queueBuffer(_, 1.f)); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 3132 | mOutput.finishFrame(std::move(result)); |
Lloyd Pique | 03561a6 | 2019-11-19 18:34:52 -0800 | [diff] [blame] | 3133 | } |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 3134 | |
| 3135 | /* |
Leon Scroggins III | c1623d1 | 2023-11-06 15:31:05 -0500 | [diff] [blame] | 3136 | * Output::presentFrameAndReleaseLayers() |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 3137 | */ |
| 3138 | |
Lloyd Pique | 07178e3 | 2019-11-19 19:15:26 -0800 | [diff] [blame] | 3139 | struct OutputPostFramebufferTest : public testing::Test { |
| 3140 | struct OutputPartialMock : public OutputPartialMockBase { |
Lloyd Pique | 739afaf | 2019-11-21 16:40:05 -0800 | [diff] [blame] | 3141 | // Sets up the helper functions called by the function under test to use |
| 3142 | // mock implementations. |
Leon Scroggins III | c1623d1 | 2023-11-06 15:31:05 -0500 | [diff] [blame] | 3143 | MOCK_METHOD0(presentFrame, compositionengine::Output::FrameFences()); |
Lloyd Pique | 07178e3 | 2019-11-19 19:15:26 -0800 | [diff] [blame] | 3144 | }; |
| 3145 | |
| 3146 | struct Layer { |
| 3147 | Layer() { |
Ady Abraham | eca9d75 | 2021-03-03 12:20:00 -0800 | [diff] [blame] | 3148 | EXPECT_CALL(outputLayer, getLayerFE()).WillRepeatedly(ReturnRef(*layerFE)); |
Lloyd Pique | 07178e3 | 2019-11-19 19:15:26 -0800 | [diff] [blame] | 3149 | EXPECT_CALL(outputLayer, getHwcLayer()).WillRepeatedly(Return(&hwc2Layer)); |
| 3150 | } |
| 3151 | |
| 3152 | StrictMock<mock::OutputLayer> outputLayer; |
Ady Abraham | eca9d75 | 2021-03-03 12:20:00 -0800 | [diff] [blame] | 3153 | sp<StrictMock<mock::LayerFE>> layerFE = sp<StrictMock<mock::LayerFE>>::make(); |
Lloyd Pique | 07178e3 | 2019-11-19 19:15:26 -0800 | [diff] [blame] | 3154 | StrictMock<HWC2::mock::Layer> hwc2Layer; |
| 3155 | }; |
| 3156 | |
| 3157 | OutputPostFramebufferTest() { |
| 3158 | mOutput.setDisplayColorProfileForTest( |
| 3159 | std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile)); |
| 3160 | mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface)); |
| 3161 | |
| 3162 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(3u)); |
| 3163 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0u)) |
| 3164 | .WillRepeatedly(Return(&mLayer1.outputLayer)); |
| 3165 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(1u)) |
| 3166 | .WillRepeatedly(Return(&mLayer2.outputLayer)); |
| 3167 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(2u)) |
| 3168 | .WillRepeatedly(Return(&mLayer3.outputLayer)); |
| 3169 | } |
| 3170 | |
| 3171 | StrictMock<OutputPartialMock> mOutput; |
| 3172 | mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>(); |
| 3173 | mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>(); |
| 3174 | |
| 3175 | Layer mLayer1; |
| 3176 | Layer mLayer2; |
| 3177 | Layer mLayer3; |
| 3178 | }; |
| 3179 | |
| 3180 | TEST_F(OutputPostFramebufferTest, ifNotEnabledDoesNothing) { |
| 3181 | mOutput.mState.isEnabled = false; |
| 3182 | |
Leon Scroggins III | c1623d1 | 2023-11-06 15:31:05 -0500 | [diff] [blame] | 3183 | mOutput.presentFrameAndReleaseLayers(); |
Lloyd Pique | 07178e3 | 2019-11-19 19:15:26 -0800 | [diff] [blame] | 3184 | } |
| 3185 | |
| 3186 | TEST_F(OutputPostFramebufferTest, ifEnabledMustFlipThenPresentThenSendPresentCompleted) { |
| 3187 | mOutput.mState.isEnabled = true; |
| 3188 | |
| 3189 | compositionengine::Output::FrameFences frameFences; |
| 3190 | |
| 3191 | // This should happen even if there are no output layers. |
| 3192 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u)); |
| 3193 | |
| 3194 | // For this test in particular we want to make sure the call expectations |
| 3195 | // setup below are satisfied in the specific order. |
| 3196 | InSequence seq; |
| 3197 | |
Leon Scroggins III | c1623d1 | 2023-11-06 15:31:05 -0500 | [diff] [blame] | 3198 | EXPECT_CALL(mOutput, presentFrame()).WillOnce(Return(frameFences)); |
Lloyd Pique | 07178e3 | 2019-11-19 19:15:26 -0800 | [diff] [blame] | 3199 | EXPECT_CALL(*mRenderSurface, onPresentDisplayCompleted()); |
| 3200 | |
Leon Scroggins III | c1623d1 | 2023-11-06 15:31:05 -0500 | [diff] [blame] | 3201 | mOutput.presentFrameAndReleaseLayers(); |
Lloyd Pique | 07178e3 | 2019-11-19 19:15:26 -0800 | [diff] [blame] | 3202 | } |
| 3203 | |
| 3204 | TEST_F(OutputPostFramebufferTest, releaseFencesAreSentToLayerFE) { |
Melody Hsu | 793f836 | 2024-01-08 20:00:35 +0000 | [diff] [blame] | 3205 | SET_FLAG_FOR_TEST(com::android::graphics::surfaceflinger::flags::ce_fence_promise, false); |
| 3206 | ASSERT_FALSE(FlagManager::getInstance().ce_fence_promise()); |
Lloyd Pique | 07178e3 | 2019-11-19 19:15:26 -0800 | [diff] [blame] | 3207 | // Simulate getting release fences from each layer, and ensure they are passed to the |
| 3208 | // front-end layer interface for each layer correctly. |
| 3209 | |
| 3210 | mOutput.mState.isEnabled = true; |
| 3211 | |
| 3212 | // Create three unique fence instances |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 3213 | sp<Fence> layer1Fence = sp<Fence>::make(); |
| 3214 | sp<Fence> layer2Fence = sp<Fence>::make(); |
| 3215 | sp<Fence> layer3Fence = sp<Fence>::make(); |
Lloyd Pique | 07178e3 | 2019-11-19 19:15:26 -0800 | [diff] [blame] | 3216 | |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 3217 | Output::FrameFences frameFences; |
Lloyd Pique | 07178e3 | 2019-11-19 19:15:26 -0800 | [diff] [blame] | 3218 | frameFences.layerFences.emplace(&mLayer1.hwc2Layer, layer1Fence); |
| 3219 | frameFences.layerFences.emplace(&mLayer2.hwc2Layer, layer2Fence); |
| 3220 | frameFences.layerFences.emplace(&mLayer3.hwc2Layer, layer3Fence); |
| 3221 | |
Leon Scroggins III | c1623d1 | 2023-11-06 15:31:05 -0500 | [diff] [blame] | 3222 | EXPECT_CALL(mOutput, presentFrame()).WillOnce(Return(frameFences)); |
Lloyd Pique | 07178e3 | 2019-11-19 19:15:26 -0800 | [diff] [blame] | 3223 | EXPECT_CALL(*mRenderSurface, onPresentDisplayCompleted()); |
| 3224 | |
| 3225 | // Compare the pointers values of each fence to make sure the correct ones |
| 3226 | // are passed. This happens to work with the current implementation, but |
| 3227 | // would not survive certain calls like Fence::merge() which would return a |
| 3228 | // new instance. |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 3229 | EXPECT_CALL(*mLayer1.layerFE, onLayerDisplayed(_, _)) |
| 3230 | .WillOnce([&layer1Fence](ftl::SharedFuture<FenceResult> futureFenceResult, |
| 3231 | ui::LayerStack) { |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 3232 | EXPECT_EQ(FenceResult(layer1Fence), futureFenceResult.get()); |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 3233 | }); |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 3234 | EXPECT_CALL(*mLayer2.layerFE, onLayerDisplayed(_, _)) |
| 3235 | .WillOnce([&layer2Fence](ftl::SharedFuture<FenceResult> futureFenceResult, |
| 3236 | ui::LayerStack) { |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 3237 | EXPECT_EQ(FenceResult(layer2Fence), futureFenceResult.get()); |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 3238 | }); |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 3239 | EXPECT_CALL(*mLayer3.layerFE, onLayerDisplayed(_, _)) |
| 3240 | .WillOnce([&layer3Fence](ftl::SharedFuture<FenceResult> futureFenceResult, |
| 3241 | ui::LayerStack) { |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 3242 | EXPECT_EQ(FenceResult(layer3Fence), futureFenceResult.get()); |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 3243 | }); |
Lloyd Pique | 07178e3 | 2019-11-19 19:15:26 -0800 | [diff] [blame] | 3244 | |
Leon Scroggins III | c1623d1 | 2023-11-06 15:31:05 -0500 | [diff] [blame] | 3245 | mOutput.presentFrameAndReleaseLayers(); |
Lloyd Pique | 07178e3 | 2019-11-19 19:15:26 -0800 | [diff] [blame] | 3246 | } |
| 3247 | |
Melody Hsu | 793f836 | 2024-01-08 20:00:35 +0000 | [diff] [blame] | 3248 | TEST_F(OutputPostFramebufferTest, releaseFencesAreSetInLayerFE) { |
| 3249 | SET_FLAG_FOR_TEST(com::android::graphics::surfaceflinger::flags::ce_fence_promise, true); |
| 3250 | ASSERT_TRUE(FlagManager::getInstance().ce_fence_promise()); |
| 3251 | // Simulate getting release fences from each layer, and ensure they are passed to the |
| 3252 | // front-end layer interface for each layer correctly. |
| 3253 | |
| 3254 | mOutput.mState.isEnabled = true; |
| 3255 | |
| 3256 | // Create three unique fence instances |
| 3257 | sp<Fence> layer1Fence = sp<Fence>::make(); |
| 3258 | sp<Fence> layer2Fence = sp<Fence>::make(); |
| 3259 | sp<Fence> layer3Fence = sp<Fence>::make(); |
| 3260 | |
| 3261 | Output::FrameFences frameFences; |
| 3262 | frameFences.layerFences.emplace(&mLayer1.hwc2Layer, layer1Fence); |
| 3263 | frameFences.layerFences.emplace(&mLayer2.hwc2Layer, layer2Fence); |
| 3264 | frameFences.layerFences.emplace(&mLayer3.hwc2Layer, layer3Fence); |
| 3265 | |
| 3266 | EXPECT_CALL(mOutput, presentFrame()).WillOnce(Return(frameFences)); |
| 3267 | EXPECT_CALL(*mRenderSurface, onPresentDisplayCompleted()); |
| 3268 | |
| 3269 | // Compare the pointers values of each fence to make sure the correct ones |
| 3270 | // are passed. This happens to work with the current implementation, but |
| 3271 | // would not survive certain calls like Fence::merge() which would return a |
| 3272 | // new instance. |
| 3273 | EXPECT_CALL(*mLayer1.layerFE, setReleaseFence(_)) |
| 3274 | .WillOnce([&layer1Fence](FenceResult releaseFence) { |
| 3275 | EXPECT_EQ(FenceResult(layer1Fence), releaseFence); |
| 3276 | }); |
| 3277 | EXPECT_CALL(*mLayer2.layerFE, setReleaseFence(_)) |
| 3278 | .WillOnce([&layer2Fence](FenceResult releaseFence) { |
| 3279 | EXPECT_EQ(FenceResult(layer2Fence), releaseFence); |
| 3280 | }); |
| 3281 | EXPECT_CALL(*mLayer3.layerFE, setReleaseFence(_)) |
| 3282 | .WillOnce([&layer3Fence](FenceResult releaseFence) { |
| 3283 | EXPECT_EQ(FenceResult(layer3Fence), releaseFence); |
| 3284 | }); |
| 3285 | |
| 3286 | mOutput.presentFrameAndReleaseLayers(); |
| 3287 | } |
| 3288 | |
Lloyd Pique | 07178e3 | 2019-11-19 19:15:26 -0800 | [diff] [blame] | 3289 | TEST_F(OutputPostFramebufferTest, releaseFencesIncludeClientTargetAcquireFence) { |
Melody Hsu | 793f836 | 2024-01-08 20:00:35 +0000 | [diff] [blame] | 3290 | SET_FLAG_FOR_TEST(com::android::graphics::surfaceflinger::flags::ce_fence_promise, false); |
| 3291 | ASSERT_FALSE(FlagManager::getInstance().ce_fence_promise()); |
| 3292 | |
Lloyd Pique | 07178e3 | 2019-11-19 19:15:26 -0800 | [diff] [blame] | 3293 | mOutput.mState.isEnabled = true; |
| 3294 | mOutput.mState.usesClientComposition = true; |
| 3295 | |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 3296 | Output::FrameFences frameFences; |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 3297 | frameFences.clientTargetAcquireFence = sp<Fence>::make(); |
| 3298 | frameFences.layerFences.emplace(&mLayer1.hwc2Layer, sp<Fence>::make()); |
| 3299 | frameFences.layerFences.emplace(&mLayer2.hwc2Layer, sp<Fence>::make()); |
| 3300 | frameFences.layerFences.emplace(&mLayer3.hwc2Layer, sp<Fence>::make()); |
Lloyd Pique | 07178e3 | 2019-11-19 19:15:26 -0800 | [diff] [blame] | 3301 | |
Leon Scroggins III | c1623d1 | 2023-11-06 15:31:05 -0500 | [diff] [blame] | 3302 | EXPECT_CALL(mOutput, presentFrame()).WillOnce(Return(frameFences)); |
Lloyd Pique | 07178e3 | 2019-11-19 19:15:26 -0800 | [diff] [blame] | 3303 | EXPECT_CALL(*mRenderSurface, onPresentDisplayCompleted()); |
| 3304 | |
| 3305 | // Fence::merge is called, and since none of the fences are actually valid, |
| 3306 | // Fence::NO_FENCE is returned and passed to each onLayerDisplayed() call. |
| 3307 | // 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] | 3308 | EXPECT_CALL(*mLayer1.layerFE, onLayerDisplayed).WillOnce(Return()); |
| 3309 | EXPECT_CALL(*mLayer2.layerFE, onLayerDisplayed).WillOnce(Return()); |
| 3310 | EXPECT_CALL(*mLayer3.layerFE, onLayerDisplayed).WillOnce(Return()); |
Lloyd Pique | 07178e3 | 2019-11-19 19:15:26 -0800 | [diff] [blame] | 3311 | |
Leon Scroggins III | c1623d1 | 2023-11-06 15:31:05 -0500 | [diff] [blame] | 3312 | mOutput.presentFrameAndReleaseLayers(); |
Lloyd Pique | 07178e3 | 2019-11-19 19:15:26 -0800 | [diff] [blame] | 3313 | } |
| 3314 | |
Melody Hsu | 793f836 | 2024-01-08 20:00:35 +0000 | [diff] [blame] | 3315 | TEST_F(OutputPostFramebufferTest, setReleaseFencesIncludeClientTargetAcquireFence) { |
| 3316 | SET_FLAG_FOR_TEST(com::android::graphics::surfaceflinger::flags::ce_fence_promise, true); |
| 3317 | ASSERT_TRUE(FlagManager::getInstance().ce_fence_promise()); |
| 3318 | |
| 3319 | mOutput.mState.isEnabled = true; |
| 3320 | mOutput.mState.usesClientComposition = true; |
| 3321 | |
| 3322 | Output::FrameFences frameFences; |
| 3323 | frameFences.clientTargetAcquireFence = sp<Fence>::make(); |
| 3324 | frameFences.layerFences.emplace(&mLayer1.hwc2Layer, sp<Fence>::make()); |
| 3325 | frameFences.layerFences.emplace(&mLayer2.hwc2Layer, sp<Fence>::make()); |
| 3326 | frameFences.layerFences.emplace(&mLayer3.hwc2Layer, sp<Fence>::make()); |
| 3327 | |
| 3328 | EXPECT_CALL(mOutput, presentFrame()).WillOnce(Return(frameFences)); |
| 3329 | EXPECT_CALL(*mRenderSurface, onPresentDisplayCompleted()); |
| 3330 | |
| 3331 | // Fence::merge is called, and since none of the fences are actually valid, |
| 3332 | // Fence::NO_FENCE is returned and passed to each setReleaseFence() call. |
| 3333 | // This is the best we can do without creating a real kernel fence object. |
| 3334 | EXPECT_CALL(*mLayer1.layerFE, setReleaseFence).WillOnce(Return()); |
| 3335 | EXPECT_CALL(*mLayer2.layerFE, setReleaseFence).WillOnce(Return()); |
| 3336 | EXPECT_CALL(*mLayer3.layerFE, setReleaseFence).WillOnce(Return()); |
| 3337 | mOutput.presentFrameAndReleaseLayers(); |
| 3338 | } |
| 3339 | |
Lloyd Pique | 07178e3 | 2019-11-19 19:15:26 -0800 | [diff] [blame] | 3340 | TEST_F(OutputPostFramebufferTest, releasedLayersSentPresentFence) { |
Melody Hsu | 793f836 | 2024-01-08 20:00:35 +0000 | [diff] [blame] | 3341 | SET_FLAG_FOR_TEST(com::android::graphics::surfaceflinger::flags::ce_fence_promise, false); |
| 3342 | ASSERT_FALSE(FlagManager::getInstance().ce_fence_promise()); |
| 3343 | |
Lloyd Pique | 07178e3 | 2019-11-19 19:15:26 -0800 | [diff] [blame] | 3344 | mOutput.mState.isEnabled = true; |
| 3345 | mOutput.mState.usesClientComposition = true; |
| 3346 | |
| 3347 | // This should happen even if there are no (current) output layers. |
| 3348 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u)); |
| 3349 | |
| 3350 | // Load up the released layers with some mock instances |
Ady Abraham | e0eafa8 | 2022-02-02 19:30:47 -0800 | [diff] [blame] | 3351 | sp<StrictMock<mock::LayerFE>> releasedLayer1 = sp<StrictMock<mock::LayerFE>>::make(); |
| 3352 | sp<StrictMock<mock::LayerFE>> releasedLayer2 = sp<StrictMock<mock::LayerFE>>::make(); |
| 3353 | sp<StrictMock<mock::LayerFE>> releasedLayer3 = sp<StrictMock<mock::LayerFE>>::make(); |
Lloyd Pique | 07178e3 | 2019-11-19 19:15:26 -0800 | [diff] [blame] | 3354 | Output::ReleasedLayers layers; |
| 3355 | layers.push_back(releasedLayer1); |
| 3356 | layers.push_back(releasedLayer2); |
| 3357 | layers.push_back(releasedLayer3); |
| 3358 | mOutput.setReleasedLayers(std::move(layers)); |
| 3359 | |
| 3360 | // Set up a fake present fence |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 3361 | sp<Fence> presentFence = sp<Fence>::make(); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 3362 | Output::FrameFences frameFences; |
Lloyd Pique | 07178e3 | 2019-11-19 19:15:26 -0800 | [diff] [blame] | 3363 | frameFences.presentFence = presentFence; |
| 3364 | |
Leon Scroggins III | c1623d1 | 2023-11-06 15:31:05 -0500 | [diff] [blame] | 3365 | EXPECT_CALL(mOutput, presentFrame()).WillOnce(Return(frameFences)); |
Lloyd Pique | 07178e3 | 2019-11-19 19:15:26 -0800 | [diff] [blame] | 3366 | EXPECT_CALL(*mRenderSurface, onPresentDisplayCompleted()); |
| 3367 | |
| 3368 | // Each released layer should be given the presentFence. |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 3369 | EXPECT_CALL(*releasedLayer1, onLayerDisplayed(_, _)) |
| 3370 | .WillOnce([&presentFence](ftl::SharedFuture<FenceResult> futureFenceResult, |
| 3371 | ui::LayerStack) { |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 3372 | EXPECT_EQ(FenceResult(presentFence), futureFenceResult.get()); |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 3373 | }); |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 3374 | EXPECT_CALL(*releasedLayer2, onLayerDisplayed(_, _)) |
| 3375 | .WillOnce([&presentFence](ftl::SharedFuture<FenceResult> futureFenceResult, |
| 3376 | ui::LayerStack) { |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 3377 | EXPECT_EQ(FenceResult(presentFence), futureFenceResult.get()); |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 3378 | }); |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 3379 | EXPECT_CALL(*releasedLayer3, onLayerDisplayed(_, _)) |
| 3380 | .WillOnce([&presentFence](ftl::SharedFuture<FenceResult> futureFenceResult, |
| 3381 | ui::LayerStack) { |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 3382 | EXPECT_EQ(FenceResult(presentFence), futureFenceResult.get()); |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 3383 | }); |
Lloyd Pique | 07178e3 | 2019-11-19 19:15:26 -0800 | [diff] [blame] | 3384 | |
Leon Scroggins III | c1623d1 | 2023-11-06 15:31:05 -0500 | [diff] [blame] | 3385 | mOutput.presentFrameAndReleaseLayers(); |
Lloyd Pique | 07178e3 | 2019-11-19 19:15:26 -0800 | [diff] [blame] | 3386 | |
| 3387 | // After the call the list of released layers should have been cleared. |
| 3388 | EXPECT_TRUE(mOutput.getReleasedLayersForTest().empty()); |
| 3389 | } |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 3390 | |
Melody Hsu | 793f836 | 2024-01-08 20:00:35 +0000 | [diff] [blame] | 3391 | TEST_F(OutputPostFramebufferTest, setReleasedLayersSentPresentFence) { |
| 3392 | SET_FLAG_FOR_TEST(com::android::graphics::surfaceflinger::flags::ce_fence_promise, true); |
| 3393 | ASSERT_TRUE(FlagManager::getInstance().ce_fence_promise()); |
| 3394 | |
| 3395 | mOutput.mState.isEnabled = true; |
| 3396 | mOutput.mState.usesClientComposition = true; |
| 3397 | |
| 3398 | // This should happen even if there are no (current) output layers. |
| 3399 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u)); |
| 3400 | |
| 3401 | // Load up the released layers with some mock instances |
| 3402 | sp<StrictMock<mock::LayerFE>> releasedLayer1 = sp<StrictMock<mock::LayerFE>>::make(); |
| 3403 | sp<StrictMock<mock::LayerFE>> releasedLayer2 = sp<StrictMock<mock::LayerFE>>::make(); |
| 3404 | sp<StrictMock<mock::LayerFE>> releasedLayer3 = sp<StrictMock<mock::LayerFE>>::make(); |
| 3405 | Output::ReleasedLayers layers; |
| 3406 | layers.push_back(releasedLayer1); |
| 3407 | layers.push_back(releasedLayer2); |
| 3408 | layers.push_back(releasedLayer3); |
| 3409 | mOutput.setReleasedLayers(std::move(layers)); |
| 3410 | |
| 3411 | // Set up a fake present fence |
| 3412 | sp<Fence> presentFence = sp<Fence>::make(); |
| 3413 | Output::FrameFences frameFences; |
| 3414 | frameFences.presentFence = presentFence; |
| 3415 | |
| 3416 | EXPECT_CALL(mOutput, presentFrame()).WillOnce(Return(frameFences)); |
| 3417 | EXPECT_CALL(*mRenderSurface, onPresentDisplayCompleted()); |
| 3418 | |
| 3419 | // Each released layer should be given the presentFence. |
| 3420 | EXPECT_CALL(*releasedLayer1, setReleaseFence(_)) |
| 3421 | .WillOnce([&presentFence](FenceResult fenceResult) { |
| 3422 | EXPECT_EQ(FenceResult(presentFence), fenceResult); |
| 3423 | }); |
| 3424 | EXPECT_CALL(*releasedLayer2, setReleaseFence(_)) |
| 3425 | .WillOnce([&presentFence](FenceResult fenceResult) { |
| 3426 | EXPECT_EQ(FenceResult(presentFence), fenceResult); |
| 3427 | }); |
| 3428 | EXPECT_CALL(*releasedLayer3, setReleaseFence(_)) |
| 3429 | .WillOnce([&presentFence](FenceResult fenceResult) { |
| 3430 | EXPECT_EQ(FenceResult(presentFence), fenceResult); |
| 3431 | }); |
| 3432 | |
| 3433 | mOutput.presentFrameAndReleaseLayers(); |
| 3434 | |
| 3435 | // After the call the list of released layers should have been cleared. |
| 3436 | EXPECT_TRUE(mOutput.getReleasedLayersForTest().empty()); |
| 3437 | } |
| 3438 | |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 3439 | /* |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 3440 | * Output::composeSurfaces() |
| 3441 | */ |
| 3442 | |
| 3443 | struct OutputComposeSurfacesTest : public testing::Test { |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3444 | using TestType = OutputComposeSurfacesTest; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 3445 | |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 3446 | struct OutputPartialMock : public OutputPartialMockBase { |
Lloyd Pique | 739afaf | 2019-11-21 16:40:05 -0800 | [diff] [blame] | 3447 | // Sets up the helper functions called by the function under test to use |
| 3448 | // mock implementations. |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 3449 | MOCK_CONST_METHOD0(getSkipColorTransform, bool()); |
Robert Carr | ccab424 | 2021-09-28 16:53:03 -0700 | [diff] [blame] | 3450 | MOCK_METHOD3(generateClientCompositionRequests, |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 3451 | std::vector<LayerFE::LayerSettings>(bool, ui::Dataspace, |
| 3452 | std::vector<LayerFE*>&)); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 3453 | MOCK_METHOD2(appendRegionFlashRequests, |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 3454 | void(const Region&, std::vector<LayerFE::LayerSettings>&)); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 3455 | MOCK_METHOD1(setExpensiveRenderingExpected, void(bool)); |
Xiang Wang | aab3116 | 2024-03-12 19:48:08 -0700 | [diff] [blame] | 3456 | MOCK_METHOD(void, setHintSessionGpuStart, (TimePoint startTime), (override)); |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 3457 | MOCK_METHOD(void, setHintSessionGpuFence, (std::unique_ptr<FenceTime> && gpuFence), |
| 3458 | (override)); |
Xiang Wang | aab3116 | 2024-03-12 19:48:08 -0700 | [diff] [blame] | 3459 | MOCK_METHOD(void, setHintSessionRequiresRenderEngine, (bool), (override)); |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 3460 | MOCK_METHOD(bool, isPowerHintSessionEnabled, (), (override)); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 3461 | }; |
| 3462 | |
| 3463 | OutputComposeSurfacesTest() { |
| 3464 | mOutput.setDisplayColorProfileForTest( |
| 3465 | std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile)); |
| 3466 | mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface)); |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 3467 | mOutput.cacheClientCompositionRequests(MAX_CLIENT_COMPOSITION_CACHE_SIZE); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 3468 | |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 3469 | mOutput.mState.orientedDisplaySpace.setContent(kDefaultOutputFrame); |
| 3470 | mOutput.mState.layerStackSpace.setContent(kDefaultOutputViewport); |
| 3471 | mOutput.mState.framebufferSpace.setContent(kDefaultOutputDestinationClip); |
| 3472 | mOutput.mState.displaySpace.setContent(kDefaultOutputDestinationClip); |
| 3473 | mOutput.mState.displaySpace.setOrientation(kDefaultOutputOrientation); |
Marin Shalamanov | b15d227 | 2020-09-17 21:41:52 +0200 | [diff] [blame] | 3474 | mOutput.mState.transform = ui::Transform{kDefaultOutputOrientationFlags}; |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3475 | mOutput.mState.dataspace = kDefaultOutputDataspace; |
| 3476 | mOutput.mState.colorTransformMatrix = kDefaultColorTransformMat; |
| 3477 | mOutput.mState.isSecure = false; |
| 3478 | mOutput.mState.needsFiltering = false; |
| 3479 | mOutput.mState.usesClientComposition = true; |
| 3480 | mOutput.mState.usesDeviceComposition = false; |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 3481 | mOutput.mState.reusedClientComposition = false; |
Lloyd Pique | e9eff97 | 2020-05-05 12:36:44 -0700 | [diff] [blame] | 3482 | mOutput.mState.flipClientTarget = false; |
Alec Mouri | f8d093d | 2022-02-10 15:16:59 -0800 | [diff] [blame] | 3483 | mOutput.mState.clientTargetBrightness = kClientTargetBrightness; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 3484 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 3485 | EXPECT_CALL(mOutput, getCompositionEngine()).WillRepeatedly(ReturnRef(mCompositionEngine)); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 3486 | EXPECT_CALL(mCompositionEngine, getRenderEngine()).WillRepeatedly(ReturnRef(mRenderEngine)); |
Patrick Williams | 74c0bf6 | 2022-11-02 23:59:26 +0000 | [diff] [blame] | 3487 | EXPECT_CALL(mCompositionEngine, getTimeStats()).WillRepeatedly(Return(mTimeStats.get())); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3488 | EXPECT_CALL(*mDisplayColorProfile, getHdrCapabilities()) |
| 3489 | .WillRepeatedly(ReturnRef(kHdrCapabilities)); |
Xiang Wang | aab3116 | 2024-03-12 19:48:08 -0700 | [diff] [blame] | 3490 | EXPECT_CALL(mOutput, isPowerHintSessionEnabled()).WillRepeatedly(Return(true)); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 3491 | } |
| 3492 | |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3493 | struct ExecuteState : public CallOrderStateMachineHelper<TestType, ExecuteState> { |
| 3494 | auto execute() { |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 3495 | base::unique_fd fence; |
| 3496 | std::shared_ptr<renderengine::ExternalTexture> externalTexture; |
| 3497 | const bool success = |
| 3498 | getInstance()->mOutput.dequeueRenderBuffer(&fence, &externalTexture); |
| 3499 | if (success) { |
| 3500 | getInstance()->mReadyFence = |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 3501 | getInstance()->mOutput.composeSurfaces(kDebugRegion, externalTexture, |
| 3502 | fence); |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 3503 | } |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3504 | return nextState<FenceCheckState>(); |
| 3505 | } |
| 3506 | }; |
| 3507 | |
| 3508 | struct FenceCheckState : public CallOrderStateMachineHelper<TestType, FenceCheckState> { |
| 3509 | void expectNoFenceWasReturned() { EXPECT_FALSE(getInstance()->mReadyFence); } |
| 3510 | |
| 3511 | void expectAFenceWasReturned() { EXPECT_TRUE(getInstance()->mReadyFence); } |
| 3512 | }; |
| 3513 | |
| 3514 | // Call this member function to start using the mini-DSL defined above. |
| 3515 | [[nodiscard]] auto verify() { return ExecuteState::make(this); } |
| 3516 | |
Marin Shalamanov | 68933fb | 2020-09-10 17:58:12 +0200 | [diff] [blame] | 3517 | static constexpr ui::Rotation kDefaultOutputOrientation = ui::ROTATION_0; |
| 3518 | static constexpr uint32_t kDefaultOutputOrientationFlags = |
| 3519 | ui::Transform::toRotationFlags(kDefaultOutputOrientation); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3520 | static constexpr ui::Dataspace kDefaultOutputDataspace = ui::Dataspace::UNKNOWN; |
| 3521 | static constexpr ui::Dataspace kExpensiveOutputDataspace = ui::Dataspace::DISPLAY_P3; |
| 3522 | static constexpr float kDefaultMaxLuminance = 0.9f; |
| 3523 | static constexpr float kDefaultAvgLuminance = 0.7f; |
| 3524 | static constexpr float kDefaultMinLuminance = 0.1f; |
Alec Mouri | f8d093d | 2022-02-10 15:16:59 -0800 | [diff] [blame] | 3525 | static constexpr float kDisplayLuminance = 400.f; |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 3526 | static constexpr float kWhitePointLuminance = 300.f; |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 3527 | static constexpr float kClientTargetLuminanceNits = 200.f; |
Alec Mouri | f8d093d | 2022-02-10 15:16:59 -0800 | [diff] [blame] | 3528 | static constexpr float kClientTargetBrightness = 0.5f; |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3529 | |
| 3530 | static const Rect kDefaultOutputFrame; |
| 3531 | static const Rect kDefaultOutputViewport; |
Lloyd Pique | e8fe474 | 2020-01-21 15:26:18 -0800 | [diff] [blame] | 3532 | static const Rect kDefaultOutputDestinationClip; |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3533 | static const mat4 kDefaultColorTransformMat; |
| 3534 | |
| 3535 | static const Region kDebugRegion; |
| 3536 | static const HdrCapabilities kHdrCapabilities; |
| 3537 | |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 3538 | StrictMock<mock::CompositionEngine> mCompositionEngine; |
| 3539 | StrictMock<renderengine::mock::RenderEngine> mRenderEngine; |
Alec Mouri | e4034bb | 2019-11-19 12:45:54 -0800 | [diff] [blame] | 3540 | // TODO: make this is a proper mock. |
| 3541 | std::shared_ptr<TimeStats> mTimeStats = std::make_shared<android::impl::TimeStats>(); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 3542 | mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>(); |
| 3543 | mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>(); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 3544 | StrictMock<OutputPartialMock> mOutput; |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 3545 | std::shared_ptr<renderengine::ExternalTexture> mOutputBuffer = std::make_shared< |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 3546 | renderengine::impl:: |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 3547 | ExternalTexture>(sp<GraphicBuffer>::make(), mRenderEngine, |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 3548 | renderengine::impl::ExternalTexture::Usage::READABLE | |
| 3549 | renderengine::impl::ExternalTexture::Usage::WRITEABLE); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3550 | |
| 3551 | std::optional<base::unique_fd> mReadyFence; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 3552 | }; |
| 3553 | |
| 3554 | const Rect OutputComposeSurfacesTest::kDefaultOutputFrame{1001, 1002, 1003, 1004}; |
| 3555 | const Rect OutputComposeSurfacesTest::kDefaultOutputViewport{1005, 1006, 1007, 1008}; |
Lloyd Pique | e8fe474 | 2020-01-21 15:26:18 -0800 | [diff] [blame] | 3556 | const Rect OutputComposeSurfacesTest::kDefaultOutputDestinationClip{1013, 1014, 1015, 1016}; |
Lloyd Pique | 0a45623 | 2020-01-16 17:51:13 -0800 | [diff] [blame] | 3557 | const mat4 OutputComposeSurfacesTest::kDefaultColorTransformMat{mat4() * 0.5f}; |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3558 | const Region OutputComposeSurfacesTest::kDebugRegion{Rect{100, 101, 102, 103}}; |
Alec Mouri | b21d94e | 2022-01-13 17:44:10 -0800 | [diff] [blame] | 3559 | |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3560 | const HdrCapabilities OutputComposeSurfacesTest:: |
| 3561 | kHdrCapabilities{{}, |
| 3562 | OutputComposeSurfacesTest::kDefaultMaxLuminance, |
| 3563 | OutputComposeSurfacesTest::kDefaultAvgLuminance, |
| 3564 | OutputComposeSurfacesTest::kDefaultMinLuminance}; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 3565 | |
Lloyd Pique | a76ce46 | 2020-01-14 13:06:37 -0800 | [diff] [blame] | 3566 | TEST_F(OutputComposeSurfacesTest, doesNothingButSignalNoExpensiveRenderingIfNoClientComposition) { |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3567 | mOutput.mState.usesClientComposition = false; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 3568 | |
Lloyd Pique | e9eff97 | 2020-05-05 12:36:44 -0700 | [diff] [blame] | 3569 | EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false)); |
Peiyong Lin | 09f910f | 2020-09-25 10:54:13 -0700 | [diff] [blame] | 3570 | EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false)); |
Lloyd Pique | e9eff97 | 2020-05-05 12:36:44 -0700 | [diff] [blame] | 3571 | |
Lloyd Pique | a76ce46 | 2020-01-14 13:06:37 -0800 | [diff] [blame] | 3572 | EXPECT_CALL(mOutput, setExpensiveRenderingExpected(false)); |
| 3573 | |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3574 | verify().execute().expectAFenceWasReturned(); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 3575 | } |
| 3576 | |
Lloyd Pique | e9eff97 | 2020-05-05 12:36:44 -0700 | [diff] [blame] | 3577 | TEST_F(OutputComposeSurfacesTest, |
| 3578 | dequeuesABufferIfNoClientCompositionButFlipClientTargetRequested) { |
| 3579 | mOutput.mState.usesClientComposition = false; |
| 3580 | mOutput.mState.flipClientTarget = true; |
| 3581 | |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3582 | EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false)); |
Peiyong Lin | 09f910f | 2020-09-25 10:54:13 -0700 | [diff] [blame] | 3583 | EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false)); |
Lloyd Pique | e9eff97 | 2020-05-05 12:36:44 -0700 | [diff] [blame] | 3584 | |
| 3585 | EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillOnce(Return(mOutputBuffer)); |
| 3586 | EXPECT_CALL(mOutput, setExpensiveRenderingExpected(false)); |
| 3587 | |
| 3588 | verify().execute().expectAFenceWasReturned(); |
| 3589 | } |
| 3590 | |
| 3591 | TEST_F(OutputComposeSurfacesTest, doesMinimalWorkIfDequeueBufferFailsForClientComposition) { |
| 3592 | EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false)); |
Peiyong Lin | 09f910f | 2020-09-25 10:54:13 -0700 | [diff] [blame] | 3593 | EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false)); |
Lloyd Pique | e9eff97 | 2020-05-05 12:36:44 -0700 | [diff] [blame] | 3594 | |
| 3595 | EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillOnce(Return(nullptr)); |
| 3596 | |
| 3597 | verify().execute().expectNoFenceWasReturned(); |
| 3598 | } |
| 3599 | |
| 3600 | TEST_F(OutputComposeSurfacesTest, |
| 3601 | doesMinimalWorkIfDequeueBufferFailsForNoClientCompositionButFlipClientTargetRequested) { |
| 3602 | mOutput.mState.usesClientComposition = false; |
| 3603 | mOutput.mState.flipClientTarget = true; |
| 3604 | |
| 3605 | EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false)); |
Peiyong Lin | 09f910f | 2020-09-25 10:54:13 -0700 | [diff] [blame] | 3606 | EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false)); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 3607 | |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3608 | EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillOnce(Return(nullptr)); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 3609 | |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3610 | verify().execute().expectNoFenceWasReturned(); |
| 3611 | } |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 3612 | |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3613 | TEST_F(OutputComposeSurfacesTest, handlesZeroCompositionRequests) { |
| 3614 | EXPECT_CALL(mOutput, getSkipColorTransform()).WillRepeatedly(Return(false)); |
| 3615 | EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillRepeatedly(Return(true)); |
| 3616 | EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false)); |
Peiyong Lin | 09f910f | 2020-09-25 10:54:13 -0700 | [diff] [blame] | 3617 | EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false)); |
Robert Carr | ccab424 | 2021-09-28 16:53:03 -0700 | [diff] [blame] | 3618 | EXPECT_CALL(mOutput, generateClientCompositionRequests(_, kDefaultOutputDataspace, _)) |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 3619 | .WillRepeatedly(Return(std::vector<LayerFE::LayerSettings>{})); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3620 | EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _)) |
| 3621 | .WillRepeatedly(Return()); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 3622 | |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3623 | EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer)); |
Alec Mouri | f29700f | 2023-08-17 21:53:31 +0000 | [diff] [blame] | 3624 | EXPECT_CALL(mRenderEngine, drawLayers(_, IsEmpty(), _, _)) |
Sally Qi | 4cabdd0 | 2021-08-05 16:45:57 -0700 | [diff] [blame] | 3625 | .WillRepeatedly([&](const renderengine::DisplaySettings&, |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 3626 | const std::vector<renderengine::LayerSettings>&, |
Alec Mouri | f29700f | 2023-08-17 21:53:31 +0000 | [diff] [blame] | 3627 | const std::shared_ptr<renderengine::ExternalTexture>&, |
Patrick Williams | 2e9748f | 2022-08-09 22:48:18 +0000 | [diff] [blame] | 3628 | base::unique_fd&&) -> ftl::Future<FenceResult> { |
| 3629 | return ftl::yield<FenceResult>(Fence::NO_FENCE); |
Sally Qi | 4cabdd0 | 2021-08-05 16:45:57 -0700 | [diff] [blame] | 3630 | }); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3631 | verify().execute().expectAFenceWasReturned(); |
| 3632 | } |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 3633 | |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3634 | TEST_F(OutputComposeSurfacesTest, buildsAndRendersRequestList) { |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 3635 | LayerFE::LayerSettings r1; |
| 3636 | LayerFE::LayerSettings r2; |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3637 | |
| 3638 | r1.geometry.boundaries = FloatRect{1, 2, 3, 4}; |
| 3639 | r2.geometry.boundaries = FloatRect{5, 6, 7, 8}; |
| 3640 | |
| 3641 | EXPECT_CALL(mOutput, getSkipColorTransform()).WillRepeatedly(Return(false)); |
| 3642 | EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillRepeatedly(Return(true)); |
| 3643 | EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false)); |
Peiyong Lin | 09f910f | 2020-09-25 10:54:13 -0700 | [diff] [blame] | 3644 | EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false)); |
Robert Carr | ccab424 | 2021-09-28 16:53:03 -0700 | [diff] [blame] | 3645 | EXPECT_CALL(mOutput, generateClientCompositionRequests(_, kDefaultOutputDataspace, _)) |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 3646 | .WillRepeatedly(Return(std::vector<LayerFE::LayerSettings>{r1})); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3647 | EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _)) |
| 3648 | .WillRepeatedly( |
| 3649 | Invoke([&](const Region&, |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 3650 | std::vector<LayerFE::LayerSettings>& clientCompositionLayers) { |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3651 | clientCompositionLayers.emplace_back(r2); |
| 3652 | })); |
| 3653 | |
| 3654 | EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer)); |
Alec Mouri | f29700f | 2023-08-17 21:53:31 +0000 | [diff] [blame] | 3655 | EXPECT_CALL(mRenderEngine, drawLayers(_, ElementsAre(r1, r2), _, _)) |
Sally Qi | 4cabdd0 | 2021-08-05 16:45:57 -0700 | [diff] [blame] | 3656 | .WillRepeatedly([&](const renderengine::DisplaySettings&, |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 3657 | const std::vector<renderengine::LayerSettings>&, |
Alec Mouri | f29700f | 2023-08-17 21:53:31 +0000 | [diff] [blame] | 3658 | const std::shared_ptr<renderengine::ExternalTexture>&, |
Patrick Williams | 2e9748f | 2022-08-09 22:48:18 +0000 | [diff] [blame] | 3659 | base::unique_fd&&) -> ftl::Future<FenceResult> { |
| 3660 | return ftl::yield<FenceResult>(Fence::NO_FENCE); |
Sally Qi | 4cabdd0 | 2021-08-05 16:45:57 -0700 | [diff] [blame] | 3661 | }); |
Alec Mouri | 1684c70 | 2021-02-04 12:27:26 -0800 | [diff] [blame] | 3662 | |
| 3663 | verify().execute().expectAFenceWasReturned(); |
| 3664 | } |
| 3665 | |
| 3666 | TEST_F(OutputComposeSurfacesTest, |
| 3667 | buildsAndRendersRequestListAndCachesFramebufferForInternalLayers) { |
| 3668 | LayerFE::LayerSettings r1; |
| 3669 | LayerFE::LayerSettings r2; |
| 3670 | |
| 3671 | r1.geometry.boundaries = FloatRect{1, 2, 3, 4}; |
| 3672 | r2.geometry.boundaries = FloatRect{5, 6, 7, 8}; |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 3673 | mOutput.setLayerFilter({ui::LayerStack{1234u}, true}); |
Alec Mouri | 1684c70 | 2021-02-04 12:27:26 -0800 | [diff] [blame] | 3674 | |
| 3675 | EXPECT_CALL(mOutput, getSkipColorTransform()).WillRepeatedly(Return(false)); |
| 3676 | EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillRepeatedly(Return(true)); |
| 3677 | EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false)); |
| 3678 | EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false)); |
Robert Carr | ccab424 | 2021-09-28 16:53:03 -0700 | [diff] [blame] | 3679 | EXPECT_CALL(mOutput, generateClientCompositionRequests(_, kDefaultOutputDataspace, _)) |
Alec Mouri | 1684c70 | 2021-02-04 12:27:26 -0800 | [diff] [blame] | 3680 | .WillRepeatedly(Return(std::vector<LayerFE::LayerSettings>{r1})); |
| 3681 | EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _)) |
| 3682 | .WillRepeatedly( |
| 3683 | Invoke([&](const Region&, |
| 3684 | std::vector<LayerFE::LayerSettings>& clientCompositionLayers) { |
| 3685 | clientCompositionLayers.emplace_back(r2); |
| 3686 | })); |
| 3687 | |
| 3688 | EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer)); |
Alec Mouri | f29700f | 2023-08-17 21:53:31 +0000 | [diff] [blame] | 3689 | EXPECT_CALL(mRenderEngine, drawLayers(_, ElementsAre(r1, r2), _, _)) |
Sally Qi | 4cabdd0 | 2021-08-05 16:45:57 -0700 | [diff] [blame] | 3690 | .WillRepeatedly([&](const renderengine::DisplaySettings&, |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 3691 | const std::vector<renderengine::LayerSettings>&, |
Alec Mouri | f29700f | 2023-08-17 21:53:31 +0000 | [diff] [blame] | 3692 | const std::shared_ptr<renderengine::ExternalTexture>&, |
Patrick Williams | 2e9748f | 2022-08-09 22:48:18 +0000 | [diff] [blame] | 3693 | base::unique_fd&&) -> ftl::Future<FenceResult> { |
| 3694 | return ftl::yield<FenceResult>(Fence::NO_FENCE); |
Sally Qi | 4cabdd0 | 2021-08-05 16:45:57 -0700 | [diff] [blame] | 3695 | }); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3696 | |
| 3697 | verify().execute().expectAFenceWasReturned(); |
| 3698 | } |
| 3699 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 3700 | TEST_F(OutputComposeSurfacesTest, renderDuplicateClientCompositionRequestsWithoutCache) { |
| 3701 | mOutput.cacheClientCompositionRequests(0); |
| 3702 | LayerFE::LayerSettings r1; |
| 3703 | LayerFE::LayerSettings r2; |
| 3704 | |
| 3705 | r1.geometry.boundaries = FloatRect{1, 2, 3, 4}; |
| 3706 | r2.geometry.boundaries = FloatRect{5, 6, 7, 8}; |
| 3707 | |
| 3708 | EXPECT_CALL(mOutput, getSkipColorTransform()).WillRepeatedly(Return(false)); |
| 3709 | EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillRepeatedly(Return(true)); |
| 3710 | EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false)); |
Peiyong Lin | 09f910f | 2020-09-25 10:54:13 -0700 | [diff] [blame] | 3711 | EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false)); |
Robert Carr | ccab424 | 2021-09-28 16:53:03 -0700 | [diff] [blame] | 3712 | EXPECT_CALL(mOutput, generateClientCompositionRequests(_, kDefaultOutputDataspace, _)) |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 3713 | .WillRepeatedly(Return(std::vector<LayerFE::LayerSettings>{r1, r2})); |
| 3714 | EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _)) |
| 3715 | .WillRepeatedly(Return()); |
| 3716 | |
| 3717 | EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer)); |
Alec Mouri | f29700f | 2023-08-17 21:53:31 +0000 | [diff] [blame] | 3718 | EXPECT_CALL(mRenderEngine, drawLayers(_, ElementsAre(r1, r2), _, _)) |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 3719 | .Times(2) |
Patrick Williams | 2e9748f | 2022-08-09 22:48:18 +0000 | [diff] [blame] | 3720 | .WillOnce(Return(ByMove(ftl::yield<FenceResult>(Fence::NO_FENCE)))) |
| 3721 | .WillOnce(Return(ByMove(ftl::yield<FenceResult>(Fence::NO_FENCE)))); |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 3722 | |
| 3723 | verify().execute().expectAFenceWasReturned(); |
| 3724 | EXPECT_FALSE(mOutput.mState.reusedClientComposition); |
| 3725 | |
| 3726 | verify().execute().expectAFenceWasReturned(); |
| 3727 | EXPECT_FALSE(mOutput.mState.reusedClientComposition); |
| 3728 | } |
| 3729 | |
| 3730 | TEST_F(OutputComposeSurfacesTest, skipDuplicateClientCompositionRequests) { |
| 3731 | mOutput.cacheClientCompositionRequests(3); |
| 3732 | LayerFE::LayerSettings r1; |
| 3733 | LayerFE::LayerSettings r2; |
| 3734 | |
| 3735 | r1.geometry.boundaries = FloatRect{1, 2, 3, 4}; |
| 3736 | r2.geometry.boundaries = FloatRect{5, 6, 7, 8}; |
| 3737 | |
| 3738 | EXPECT_CALL(mOutput, getSkipColorTransform()).WillRepeatedly(Return(false)); |
| 3739 | EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillRepeatedly(Return(true)); |
| 3740 | EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false)); |
Peiyong Lin | 09f910f | 2020-09-25 10:54:13 -0700 | [diff] [blame] | 3741 | EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false)); |
Robert Carr | ccab424 | 2021-09-28 16:53:03 -0700 | [diff] [blame] | 3742 | EXPECT_CALL(mOutput, generateClientCompositionRequests(_, kDefaultOutputDataspace, _)) |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 3743 | .WillRepeatedly(Return(std::vector<LayerFE::LayerSettings>{r1, r2})); |
| 3744 | EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _)) |
| 3745 | .WillRepeatedly(Return()); |
| 3746 | |
| 3747 | EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer)); |
Alec Mouri | f29700f | 2023-08-17 21:53:31 +0000 | [diff] [blame] | 3748 | EXPECT_CALL(mRenderEngine, drawLayers(_, ElementsAre(r1, r2), _, _)) |
Patrick Williams | 2e9748f | 2022-08-09 22:48:18 +0000 | [diff] [blame] | 3749 | .WillOnce(Return(ByMove(ftl::yield<FenceResult>(Fence::NO_FENCE)))); |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 3750 | EXPECT_CALL(mOutput, setExpensiveRenderingExpected(false)); |
| 3751 | |
| 3752 | verify().execute().expectAFenceWasReturned(); |
| 3753 | EXPECT_FALSE(mOutput.mState.reusedClientComposition); |
| 3754 | |
| 3755 | // We do not expect another call to draw layers. |
Xiang Wang | aab3116 | 2024-03-12 19:48:08 -0700 | [diff] [blame] | 3756 | EXPECT_CALL(mOutput, setHintSessionRequiresRenderEngine(_)).Times(0); |
| 3757 | EXPECT_CALL(mOutput, setHintSessionGpuStart(_)).Times(0); |
| 3758 | EXPECT_CALL(mOutput, setHintSessionGpuFence(_)).Times(0); |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 3759 | verify().execute().expectAFenceWasReturned(); |
| 3760 | EXPECT_TRUE(mOutput.mState.reusedClientComposition); |
| 3761 | } |
| 3762 | |
Xiang Wang | cf61e73 | 2024-03-22 11:05:28 -0700 | [diff] [blame] | 3763 | TEST_F(OutputComposeSurfacesTest, clientCompositionIfBufferChangesWithAdpfGpuOff) { |
| 3764 | SET_FLAG_FOR_TEST(flags::adpf_gpu_sf, false); |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 3765 | LayerFE::LayerSettings r1; |
| 3766 | LayerFE::LayerSettings r2; |
| 3767 | |
| 3768 | r1.geometry.boundaries = FloatRect{1, 2, 3, 4}; |
| 3769 | r2.geometry.boundaries = FloatRect{5, 6, 7, 8}; |
| 3770 | |
| 3771 | EXPECT_CALL(mOutput, getSkipColorTransform()).WillRepeatedly(Return(false)); |
| 3772 | EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillRepeatedly(Return(true)); |
| 3773 | EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false)); |
Peiyong Lin | 09f910f | 2020-09-25 10:54:13 -0700 | [diff] [blame] | 3774 | EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false)); |
Robert Carr | ccab424 | 2021-09-28 16:53:03 -0700 | [diff] [blame] | 3775 | EXPECT_CALL(mOutput, generateClientCompositionRequests(_, kDefaultOutputDataspace, _)) |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 3776 | .WillRepeatedly(Return(std::vector<LayerFE::LayerSettings>{r1, r2})); |
| 3777 | EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _)) |
| 3778 | .WillRepeatedly(Return()); |
| 3779 | |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 3780 | const auto otherOutputBuffer = std::make_shared< |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 3781 | renderengine::impl:: |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 3782 | ExternalTexture>(sp<GraphicBuffer>::make(), mRenderEngine, |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 3783 | renderengine::impl::ExternalTexture::Usage::READABLE | |
| 3784 | renderengine::impl::ExternalTexture::Usage::WRITEABLE); |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 3785 | EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)) |
| 3786 | .WillOnce(Return(mOutputBuffer)) |
| 3787 | .WillOnce(Return(otherOutputBuffer)); |
Xiang Wang | aab3116 | 2024-03-12 19:48:08 -0700 | [diff] [blame] | 3788 | base::unique_fd fd(open("/dev/null", O_RDONLY)); |
Alec Mouri | f29700f | 2023-08-17 21:53:31 +0000 | [diff] [blame] | 3789 | EXPECT_CALL(mRenderEngine, drawLayers(_, ElementsAre(r1, r2), _, _)) |
Sally Qi | 4cabdd0 | 2021-08-05 16:45:57 -0700 | [diff] [blame] | 3790 | .WillRepeatedly([&](const renderengine::DisplaySettings&, |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 3791 | const std::vector<renderengine::LayerSettings>&, |
Alec Mouri | f29700f | 2023-08-17 21:53:31 +0000 | [diff] [blame] | 3792 | const std::shared_ptr<renderengine::ExternalTexture>&, |
Patrick Williams | 2e9748f | 2022-08-09 22:48:18 +0000 | [diff] [blame] | 3793 | base::unique_fd&&) -> ftl::Future<FenceResult> { |
Xiang Wang | aab3116 | 2024-03-12 19:48:08 -0700 | [diff] [blame] | 3794 | return ftl::yield<FenceResult>(sp<Fence>::make(std::move(fd))); |
Sally Qi | 4cabdd0 | 2021-08-05 16:45:57 -0700 | [diff] [blame] | 3795 | }); |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 3796 | |
Xiang Wang | aab3116 | 2024-03-12 19:48:08 -0700 | [diff] [blame] | 3797 | EXPECT_CALL(mOutput, setHintSessionRequiresRenderEngine(true)); |
| 3798 | EXPECT_CALL(mOutput, setHintSessionGpuStart(_)).Times(0); |
| 3799 | EXPECT_CALL(mOutput, setHintSessionGpuFence(_)).Times(0); |
| 3800 | verify().execute().expectAFenceWasReturned(); |
| 3801 | EXPECT_FALSE(mOutput.mState.reusedClientComposition); |
| 3802 | |
| 3803 | verify().execute().expectAFenceWasReturned(); |
| 3804 | EXPECT_FALSE(mOutput.mState.reusedClientComposition); |
| 3805 | } |
| 3806 | |
Xiang Wang | cf61e73 | 2024-03-22 11:05:28 -0700 | [diff] [blame] | 3807 | TEST_F(OutputComposeSurfacesTest, clientCompositionIfBufferChanges) { |
Xiang Wang | aab3116 | 2024-03-12 19:48:08 -0700 | [diff] [blame] | 3808 | SET_FLAG_FOR_TEST(flags::adpf_gpu_sf, true); |
| 3809 | LayerFE::LayerSettings r1; |
| 3810 | LayerFE::LayerSettings r2; |
| 3811 | |
| 3812 | r1.geometry.boundaries = FloatRect{1, 2, 3, 4}; |
| 3813 | r2.geometry.boundaries = FloatRect{5, 6, 7, 8}; |
| 3814 | |
| 3815 | EXPECT_CALL(mOutput, getSkipColorTransform()).WillRepeatedly(Return(false)); |
| 3816 | EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillRepeatedly(Return(true)); |
| 3817 | EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false)); |
| 3818 | EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false)); |
| 3819 | EXPECT_CALL(mOutput, generateClientCompositionRequests(_, kDefaultOutputDataspace, _)) |
| 3820 | .WillRepeatedly(Return(std::vector<LayerFE::LayerSettings>{r1, r2})); |
| 3821 | EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _)) |
| 3822 | .WillRepeatedly(Return()); |
| 3823 | |
| 3824 | const auto otherOutputBuffer = std::make_shared< |
| 3825 | renderengine::impl:: |
| 3826 | ExternalTexture>(sp<GraphicBuffer>::make(), mRenderEngine, |
| 3827 | renderengine::impl::ExternalTexture::Usage::READABLE | |
| 3828 | renderengine::impl::ExternalTexture::Usage::WRITEABLE); |
| 3829 | EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)) |
| 3830 | .WillOnce(Return(mOutputBuffer)) |
| 3831 | .WillOnce(Return(otherOutputBuffer)); |
| 3832 | base::unique_fd fd(open("/dev/null", O_RDONLY)); |
| 3833 | EXPECT_CALL(mRenderEngine, drawLayers(_, ElementsAre(r1, r2), _, _)) |
| 3834 | .WillRepeatedly([&](const renderengine::DisplaySettings&, |
| 3835 | const std::vector<renderengine::LayerSettings>&, |
| 3836 | const std::shared_ptr<renderengine::ExternalTexture>&, |
| 3837 | base::unique_fd&&) -> ftl::Future<FenceResult> { |
| 3838 | return ftl::yield<FenceResult>(sp<Fence>::make(std::move(fd))); |
| 3839 | }); |
| 3840 | |
| 3841 | EXPECT_CALL(mOutput, setHintSessionRequiresRenderEngine(true)); |
| 3842 | EXPECT_CALL(mOutput, setHintSessionGpuStart(_)); |
| 3843 | EXPECT_CALL(mOutput, setHintSessionGpuFence(_)); |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 3844 | verify().execute().expectAFenceWasReturned(); |
| 3845 | EXPECT_FALSE(mOutput.mState.reusedClientComposition); |
| 3846 | |
| 3847 | verify().execute().expectAFenceWasReturned(); |
| 3848 | EXPECT_FALSE(mOutput.mState.reusedClientComposition); |
| 3849 | } |
| 3850 | |
| 3851 | TEST_F(OutputComposeSurfacesTest, clientCompositionIfRequestChanges) { |
| 3852 | LayerFE::LayerSettings r1; |
| 3853 | LayerFE::LayerSettings r2; |
| 3854 | LayerFE::LayerSettings r3; |
| 3855 | |
| 3856 | r1.geometry.boundaries = FloatRect{1, 2, 3, 4}; |
| 3857 | r2.geometry.boundaries = FloatRect{5, 6, 7, 8}; |
| 3858 | r3.geometry.boundaries = FloatRect{5, 6, 7, 9}; |
| 3859 | |
| 3860 | EXPECT_CALL(mOutput, getSkipColorTransform()).WillRepeatedly(Return(false)); |
| 3861 | EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillRepeatedly(Return(true)); |
| 3862 | EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false)); |
Peiyong Lin | 09f910f | 2020-09-25 10:54:13 -0700 | [diff] [blame] | 3863 | EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false)); |
Robert Carr | ccab424 | 2021-09-28 16:53:03 -0700 | [diff] [blame] | 3864 | EXPECT_CALL(mOutput, generateClientCompositionRequests(_, kDefaultOutputDataspace, _)) |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 3865 | .WillOnce(Return(std::vector<LayerFE::LayerSettings>{r1, r2})) |
| 3866 | .WillOnce(Return(std::vector<LayerFE::LayerSettings>{r1, r3})); |
| 3867 | EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _)) |
| 3868 | .WillRepeatedly(Return()); |
| 3869 | |
| 3870 | EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer)); |
Alec Mouri | f29700f | 2023-08-17 21:53:31 +0000 | [diff] [blame] | 3871 | EXPECT_CALL(mRenderEngine, drawLayers(_, ElementsAre(r1, r2), _, _)) |
Patrick Williams | 2e9748f | 2022-08-09 22:48:18 +0000 | [diff] [blame] | 3872 | .WillOnce(Return(ByMove(ftl::yield<FenceResult>(Fence::NO_FENCE)))); |
Alec Mouri | f29700f | 2023-08-17 21:53:31 +0000 | [diff] [blame] | 3873 | EXPECT_CALL(mRenderEngine, drawLayers(_, ElementsAre(r1, r3), _, _)) |
Patrick Williams | 2e9748f | 2022-08-09 22:48:18 +0000 | [diff] [blame] | 3874 | .WillOnce(Return(ByMove(ftl::yield<FenceResult>(Fence::NO_FENCE)))); |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 3875 | |
| 3876 | verify().execute().expectAFenceWasReturned(); |
| 3877 | EXPECT_FALSE(mOutput.mState.reusedClientComposition); |
| 3878 | |
| 3879 | verify().execute().expectAFenceWasReturned(); |
| 3880 | EXPECT_FALSE(mOutput.mState.reusedClientComposition); |
| 3881 | } |
| 3882 | |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3883 | struct OutputComposeSurfacesTest_UsesExpectedDisplaySettings : public OutputComposeSurfacesTest { |
| 3884 | OutputComposeSurfacesTest_UsesExpectedDisplaySettings() { |
| 3885 | EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false)); |
Peiyong Lin | 09f910f | 2020-09-25 10:54:13 -0700 | [diff] [blame] | 3886 | EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false)); |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 3887 | EXPECT_CALL(mOutput, generateClientCompositionRequests(_, _, _)) |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 3888 | .WillRepeatedly(Return(std::vector<LayerFE::LayerSettings>{})); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3889 | EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _)) |
| 3890 | .WillRepeatedly(Return()); |
| 3891 | EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer)); |
| 3892 | } |
| 3893 | |
| 3894 | struct MixedCompositionState |
| 3895 | : public CallOrderStateMachineHelper<TestType, MixedCompositionState> { |
| 3896 | auto ifMixedCompositionIs(bool used) { |
| 3897 | getInstance()->mOutput.mState.usesDeviceComposition = used; |
| 3898 | return nextState<OutputUsesHdrState>(); |
| 3899 | } |
| 3900 | }; |
| 3901 | |
| 3902 | struct OutputUsesHdrState : public CallOrderStateMachineHelper<TestType, OutputUsesHdrState> { |
| 3903 | auto andIfUsesHdr(bool used) { |
| 3904 | EXPECT_CALL(*getInstance()->mDisplayColorProfile, hasWideColorGamut()) |
| 3905 | .WillOnce(Return(used)); |
Alec Mouri | b21d94e | 2022-01-13 17:44:10 -0800 | [diff] [blame] | 3906 | return nextState<OutputWithDisplayBrightnessNits>(); |
| 3907 | } |
| 3908 | }; |
| 3909 | |
| 3910 | struct OutputWithDisplayBrightnessNits |
| 3911 | : public CallOrderStateMachineHelper<TestType, OutputWithDisplayBrightnessNits> { |
| 3912 | auto withDisplayBrightnessNits(float nits) { |
| 3913 | getInstance()->mOutput.mState.displayBrightnessNits = nits; |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 3914 | return nextState<OutputWithSdrWhitePointNits>(); |
| 3915 | } |
| 3916 | }; |
| 3917 | |
| 3918 | struct OutputWithSdrWhitePointNits |
| 3919 | : public CallOrderStateMachineHelper<TestType, OutputWithSdrWhitePointNits> { |
| 3920 | auto withSdrWhitePointNits(float nits) { |
| 3921 | getInstance()->mOutput.mState.sdrWhitePointNits = nits; |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 3922 | return nextState<OutputWithDimmingStage>(); |
| 3923 | } |
| 3924 | }; |
| 3925 | |
| 3926 | struct OutputWithDimmingStage |
| 3927 | : public CallOrderStateMachineHelper<TestType, OutputWithDimmingStage> { |
| 3928 | auto withDimmingStage( |
| 3929 | aidl::android::hardware::graphics::composer3::DimmingStage dimmingStage) { |
| 3930 | getInstance()->mOutput.mState.clientTargetDimmingStage = dimmingStage; |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 3931 | return nextState<OutputWithRenderIntent>(); |
| 3932 | } |
| 3933 | }; |
| 3934 | |
| 3935 | struct OutputWithRenderIntent |
| 3936 | : public CallOrderStateMachineHelper<TestType, OutputWithRenderIntent> { |
| 3937 | auto withRenderIntent( |
| 3938 | aidl::android::hardware::graphics::composer3::RenderIntent renderIntent) { |
| 3939 | getInstance()->mOutput.mState.renderIntent = |
| 3940 | static_cast<ui::RenderIntent>(renderIntent); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3941 | return nextState<SkipColorTransformState>(); |
| 3942 | } |
| 3943 | }; |
| 3944 | |
| 3945 | struct SkipColorTransformState |
| 3946 | : public CallOrderStateMachineHelper<TestType, SkipColorTransformState> { |
| 3947 | auto andIfSkipColorTransform(bool skip) { |
| 3948 | // May be called zero or one times. |
| 3949 | EXPECT_CALL(getInstance()->mOutput, getSkipColorTransform()) |
| 3950 | .WillRepeatedly(Return(skip)); |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 3951 | return nextState<PixelFormatState>(); |
| 3952 | } |
| 3953 | }; |
| 3954 | |
| 3955 | struct PixelFormatState : public CallOrderStateMachineHelper<TestType, PixelFormatState> { |
| 3956 | auto withPixelFormat(std::optional<PixelFormat> format) { |
| 3957 | // May be called zero or one times. |
| 3958 | if (format) { |
| 3959 | auto outputBuffer = std::make_shared< |
| 3960 | renderengine::impl:: |
| 3961 | ExternalTexture>(sp<GraphicBuffer>:: |
| 3962 | make(1u, 1u, *format, |
| 3963 | GRALLOC_USAGE_SW_WRITE_OFTEN | |
| 3964 | GRALLOC_USAGE_SW_READ_OFTEN), |
| 3965 | getInstance()->mRenderEngine, |
| 3966 | renderengine::impl::ExternalTexture::Usage:: |
| 3967 | READABLE | |
| 3968 | renderengine::impl::ExternalTexture:: |
| 3969 | Usage::WRITEABLE); |
| 3970 | EXPECT_CALL(*getInstance()->mRenderSurface, dequeueBuffer(_)) |
| 3971 | .WillRepeatedly(Return(outputBuffer)); |
| 3972 | } |
| 3973 | return nextState<DataspaceState>(); |
| 3974 | } |
| 3975 | }; |
| 3976 | |
| 3977 | struct DataspaceState : public CallOrderStateMachineHelper<TestType, DataspaceState> { |
| 3978 | auto withDataspace(ui::Dataspace dataspace) { |
| 3979 | getInstance()->mOutput.mState.dataspace = dataspace; |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3980 | return nextState<ExpectDisplaySettingsState>(); |
| 3981 | } |
| 3982 | }; |
| 3983 | |
| 3984 | struct ExpectDisplaySettingsState |
| 3985 | : public CallOrderStateMachineHelper<TestType, ExpectDisplaySettingsState> { |
| 3986 | auto thenExpectDisplaySettingsUsed(renderengine::DisplaySettings settings) { |
Alec Mouri | f29700f | 2023-08-17 21:53:31 +0000 | [diff] [blame] | 3987 | EXPECT_CALL(getInstance()->mRenderEngine, drawLayers(settings, _, _, _)) |
Patrick Williams | 2e9748f | 2022-08-09 22:48:18 +0000 | [diff] [blame] | 3988 | .WillOnce(Return(ByMove(ftl::yield<FenceResult>(Fence::NO_FENCE)))); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3989 | return nextState<ExecuteState>(); |
| 3990 | } |
| 3991 | }; |
| 3992 | |
| 3993 | // Call this member function to start using the mini-DSL defined above. |
| 3994 | [[nodiscard]] auto verify() { return MixedCompositionState::make(this); } |
| 3995 | }; |
| 3996 | |
| 3997 | TEST_F(OutputComposeSurfacesTest_UsesExpectedDisplaySettings, forHdrMixedComposition) { |
| 3998 | verify().ifMixedCompositionIs(true) |
| 3999 | .andIfUsesHdr(true) |
Leon Scroggins III | f6280bb | 2022-05-04 13:20:32 -0400 | [diff] [blame] | 4000 | .withDisplayBrightnessNits(kDisplayLuminance) |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 4001 | .withSdrWhitePointNits(kWhitePointLuminance) |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 4002 | .withDimmingStage(aidl::android::hardware::graphics::composer3::DimmingStage::LINEAR) |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 4003 | .withRenderIntent( |
| 4004 | aidl::android::hardware::graphics::composer3::RenderIntent::COLORIMETRIC) |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4005 | .andIfSkipColorTransform(false) |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 4006 | .withPixelFormat(std::nullopt) |
| 4007 | .withDataspace(kDefaultOutputDataspace) |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 4008 | .thenExpectDisplaySettingsUsed( |
| 4009 | {.physicalDisplay = kDefaultOutputDestinationClip, |
| 4010 | .clip = kDefaultOutputViewport, |
| 4011 | .maxLuminance = kDefaultMaxLuminance, |
Leon Scroggins III | f6280bb | 2022-05-04 13:20:32 -0400 | [diff] [blame] | 4012 | .currentLuminanceNits = kDisplayLuminance, |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 4013 | .outputDataspace = kDefaultOutputDataspace, |
| 4014 | .colorTransform = kDefaultColorTransformMat, |
| 4015 | .deviceHandlesColorTransform = true, |
| 4016 | .orientation = kDefaultOutputOrientationFlags, |
| 4017 | .targetLuminanceNits = kClientTargetLuminanceNits, |
| 4018 | .dimmingStage = |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 4019 | aidl::android::hardware::graphics::composer3::DimmingStage::LINEAR, |
| 4020 | .renderIntent = aidl::android::hardware::graphics::composer3::RenderIntent:: |
| 4021 | COLORIMETRIC}) |
Alec Mouri | b21d94e | 2022-01-13 17:44:10 -0800 | [diff] [blame] | 4022 | .execute() |
| 4023 | .expectAFenceWasReturned(); |
| 4024 | } |
| 4025 | |
| 4026 | TEST_F(OutputComposeSurfacesTest_UsesExpectedDisplaySettings, |
| 4027 | forHdrMixedCompositionWithDisplayBrightness) { |
| 4028 | verify().ifMixedCompositionIs(true) |
| 4029 | .andIfUsesHdr(true) |
| 4030 | .withDisplayBrightnessNits(kDisplayLuminance) |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 4031 | .withSdrWhitePointNits(kWhitePointLuminance) |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 4032 | .withDimmingStage(aidl::android::hardware::graphics::composer3::DimmingStage::LINEAR) |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 4033 | .withRenderIntent( |
| 4034 | aidl::android::hardware::graphics::composer3::RenderIntent::COLORIMETRIC) |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 4035 | .andIfSkipColorTransform(false) |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 4036 | .withPixelFormat(std::nullopt) |
| 4037 | .withDataspace(kDefaultOutputDataspace) |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 4038 | .thenExpectDisplaySettingsUsed( |
| 4039 | {.physicalDisplay = kDefaultOutputDestinationClip, |
| 4040 | .clip = kDefaultOutputViewport, |
| 4041 | .maxLuminance = kDefaultMaxLuminance, |
| 4042 | .currentLuminanceNits = kDisplayLuminance, |
| 4043 | .outputDataspace = kDefaultOutputDataspace, |
| 4044 | .colorTransform = kDefaultColorTransformMat, |
| 4045 | .deviceHandlesColorTransform = true, |
| 4046 | .orientation = kDefaultOutputOrientationFlags, |
| 4047 | .targetLuminanceNits = kClientTargetLuminanceNits, |
| 4048 | .dimmingStage = |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 4049 | aidl::android::hardware::graphics::composer3::DimmingStage::LINEAR, |
| 4050 | .renderIntent = aidl::android::hardware::graphics::composer3::RenderIntent:: |
| 4051 | COLORIMETRIC}) |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 4052 | .execute() |
| 4053 | .expectAFenceWasReturned(); |
| 4054 | } |
| 4055 | |
| 4056 | TEST_F(OutputComposeSurfacesTest_UsesExpectedDisplaySettings, |
| 4057 | forHdrMixedCompositionWithDimmingStage) { |
| 4058 | verify().ifMixedCompositionIs(true) |
| 4059 | .andIfUsesHdr(true) |
Leon Scroggins III | f6280bb | 2022-05-04 13:20:32 -0400 | [diff] [blame] | 4060 | .withDisplayBrightnessNits(kDisplayLuminance) |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 4061 | .withSdrWhitePointNits(kWhitePointLuminance) |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 4062 | .withDimmingStage( |
| 4063 | aidl::android::hardware::graphics::composer3::DimmingStage::GAMMA_OETF) |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 4064 | .withRenderIntent( |
| 4065 | aidl::android::hardware::graphics::composer3::RenderIntent::COLORIMETRIC) |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4066 | .andIfSkipColorTransform(false) |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 4067 | .withPixelFormat(std::nullopt) |
| 4068 | .withDataspace(kDefaultOutputDataspace) |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 4069 | .thenExpectDisplaySettingsUsed( |
| 4070 | {.physicalDisplay = kDefaultOutputDestinationClip, |
| 4071 | .clip = kDefaultOutputViewport, |
| 4072 | .maxLuminance = kDefaultMaxLuminance, |
Leon Scroggins III | f6280bb | 2022-05-04 13:20:32 -0400 | [diff] [blame] | 4073 | .currentLuminanceNits = kDisplayLuminance, |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 4074 | .outputDataspace = kDefaultOutputDataspace, |
| 4075 | .colorTransform = kDefaultColorTransformMat, |
| 4076 | .deviceHandlesColorTransform = true, |
| 4077 | .orientation = kDefaultOutputOrientationFlags, |
| 4078 | .targetLuminanceNits = kClientTargetLuminanceNits, |
| 4079 | .dimmingStage = |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 4080 | aidl::android::hardware::graphics::composer3::DimmingStage::GAMMA_OETF, |
| 4081 | .renderIntent = aidl::android::hardware::graphics::composer3::RenderIntent:: |
| 4082 | COLORIMETRIC}) |
| 4083 | .execute() |
| 4084 | .expectAFenceWasReturned(); |
| 4085 | } |
| 4086 | |
| 4087 | TEST_F(OutputComposeSurfacesTest_UsesExpectedDisplaySettings, |
| 4088 | forHdrMixedCompositionWithRenderIntent) { |
| 4089 | verify().ifMixedCompositionIs(true) |
| 4090 | .andIfUsesHdr(true) |
Leon Scroggins III | f6280bb | 2022-05-04 13:20:32 -0400 | [diff] [blame] | 4091 | .withDisplayBrightnessNits(kDisplayLuminance) |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 4092 | .withSdrWhitePointNits(kWhitePointLuminance) |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 4093 | .withDimmingStage(aidl::android::hardware::graphics::composer3::DimmingStage::LINEAR) |
| 4094 | .withRenderIntent(aidl::android::hardware::graphics::composer3::RenderIntent::ENHANCE) |
| 4095 | .andIfSkipColorTransform(false) |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 4096 | .withPixelFormat(std::nullopt) |
| 4097 | .withDataspace(kDefaultOutputDataspace) |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 4098 | .thenExpectDisplaySettingsUsed( |
| 4099 | {.physicalDisplay = kDefaultOutputDestinationClip, |
| 4100 | .clip = kDefaultOutputViewport, |
| 4101 | .maxLuminance = kDefaultMaxLuminance, |
Leon Scroggins III | f6280bb | 2022-05-04 13:20:32 -0400 | [diff] [blame] | 4102 | .currentLuminanceNits = kDisplayLuminance, |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 4103 | .outputDataspace = kDefaultOutputDataspace, |
| 4104 | .colorTransform = kDefaultColorTransformMat, |
| 4105 | .deviceHandlesColorTransform = true, |
| 4106 | .orientation = kDefaultOutputOrientationFlags, |
| 4107 | .targetLuminanceNits = kClientTargetLuminanceNits, |
| 4108 | .dimmingStage = |
| 4109 | aidl::android::hardware::graphics::composer3::DimmingStage::LINEAR, |
| 4110 | .renderIntent = |
| 4111 | aidl::android::hardware::graphics::composer3::RenderIntent::ENHANCE}) |
| 4112 | .execute() |
| 4113 | .expectAFenceWasReturned(); |
| 4114 | } |
| 4115 | |
| 4116 | TEST_F(OutputComposeSurfacesTest_UsesExpectedDisplaySettings, forNonHdrMixedComposition) { |
| 4117 | verify().ifMixedCompositionIs(true) |
| 4118 | .andIfUsesHdr(false) |
Leon Scroggins III | f6280bb | 2022-05-04 13:20:32 -0400 | [diff] [blame] | 4119 | .withDisplayBrightnessNits(kDisplayLuminance) |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 4120 | .withSdrWhitePointNits(kWhitePointLuminance) |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 4121 | .withDimmingStage(aidl::android::hardware::graphics::composer3::DimmingStage::LINEAR) |
| 4122 | .withRenderIntent( |
| 4123 | aidl::android::hardware::graphics::composer3::RenderIntent::COLORIMETRIC) |
| 4124 | .andIfSkipColorTransform(false) |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 4125 | .withPixelFormat(std::nullopt) |
| 4126 | .withDataspace(kDefaultOutputDataspace) |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 4127 | .thenExpectDisplaySettingsUsed( |
| 4128 | {.physicalDisplay = kDefaultOutputDestinationClip, |
| 4129 | .clip = kDefaultOutputViewport, |
| 4130 | .maxLuminance = kDefaultMaxLuminance, |
Leon Scroggins III | f6280bb | 2022-05-04 13:20:32 -0400 | [diff] [blame] | 4131 | .currentLuminanceNits = kDisplayLuminance, |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 4132 | .outputDataspace = kDefaultOutputDataspace, |
| 4133 | .colorTransform = kDefaultColorTransformMat, |
| 4134 | .deviceHandlesColorTransform = true, |
| 4135 | .orientation = kDefaultOutputOrientationFlags, |
| 4136 | .targetLuminanceNits = kClientTargetLuminanceNits, |
| 4137 | .dimmingStage = |
| 4138 | aidl::android::hardware::graphics::composer3::DimmingStage::LINEAR, |
| 4139 | .renderIntent = aidl::android::hardware::graphics::composer3::RenderIntent:: |
| 4140 | COLORIMETRIC}) |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4141 | .execute() |
| 4142 | .expectAFenceWasReturned(); |
| 4143 | } |
| 4144 | |
| 4145 | TEST_F(OutputComposeSurfacesTest_UsesExpectedDisplaySettings, forHdrOnlyClientComposition) { |
| 4146 | verify().ifMixedCompositionIs(false) |
| 4147 | .andIfUsesHdr(true) |
Leon Scroggins III | f6280bb | 2022-05-04 13:20:32 -0400 | [diff] [blame] | 4148 | .withDisplayBrightnessNits(kDisplayLuminance) |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 4149 | .withSdrWhitePointNits(kWhitePointLuminance) |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 4150 | .withDimmingStage(aidl::android::hardware::graphics::composer3::DimmingStage::LINEAR) |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 4151 | .withRenderIntent( |
| 4152 | aidl::android::hardware::graphics::composer3::RenderIntent::COLORIMETRIC) |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4153 | .andIfSkipColorTransform(false) |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 4154 | .withPixelFormat(std::nullopt) |
| 4155 | .withDataspace(kDefaultOutputDataspace) |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 4156 | .thenExpectDisplaySettingsUsed( |
| 4157 | {.physicalDisplay = kDefaultOutputDestinationClip, |
| 4158 | .clip = kDefaultOutputViewport, |
| 4159 | .maxLuminance = kDefaultMaxLuminance, |
Leon Scroggins III | f6280bb | 2022-05-04 13:20:32 -0400 | [diff] [blame] | 4160 | .currentLuminanceNits = kDisplayLuminance, |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 4161 | .outputDataspace = kDefaultOutputDataspace, |
| 4162 | .colorTransform = kDefaultColorTransformMat, |
| 4163 | .deviceHandlesColorTransform = false, |
| 4164 | .orientation = kDefaultOutputOrientationFlags, |
| 4165 | .targetLuminanceNits = kClientTargetLuminanceNits, |
| 4166 | .dimmingStage = |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 4167 | aidl::android::hardware::graphics::composer3::DimmingStage::LINEAR, |
| 4168 | .renderIntent = aidl::android::hardware::graphics::composer3::RenderIntent:: |
| 4169 | COLORIMETRIC}) |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4170 | .execute() |
| 4171 | .expectAFenceWasReturned(); |
| 4172 | } |
| 4173 | |
| 4174 | TEST_F(OutputComposeSurfacesTest_UsesExpectedDisplaySettings, forNonHdrOnlyClientComposition) { |
| 4175 | verify().ifMixedCompositionIs(false) |
| 4176 | .andIfUsesHdr(false) |
Leon Scroggins III | f6280bb | 2022-05-04 13:20:32 -0400 | [diff] [blame] | 4177 | .withDisplayBrightnessNits(kDisplayLuminance) |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 4178 | .withSdrWhitePointNits(kWhitePointLuminance) |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 4179 | .withDimmingStage(aidl::android::hardware::graphics::composer3::DimmingStage::LINEAR) |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 4180 | .withRenderIntent( |
| 4181 | aidl::android::hardware::graphics::composer3::RenderIntent::COLORIMETRIC) |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4182 | .andIfSkipColorTransform(false) |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 4183 | .withPixelFormat(std::nullopt) |
| 4184 | .withDataspace(kDefaultOutputDataspace) |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 4185 | .thenExpectDisplaySettingsUsed( |
| 4186 | {.physicalDisplay = kDefaultOutputDestinationClip, |
| 4187 | .clip = kDefaultOutputViewport, |
| 4188 | .maxLuminance = kDefaultMaxLuminance, |
Leon Scroggins III | f6280bb | 2022-05-04 13:20:32 -0400 | [diff] [blame] | 4189 | .currentLuminanceNits = kDisplayLuminance, |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 4190 | .outputDataspace = kDefaultOutputDataspace, |
| 4191 | .colorTransform = kDefaultColorTransformMat, |
| 4192 | .deviceHandlesColorTransform = false, |
| 4193 | .orientation = kDefaultOutputOrientationFlags, |
| 4194 | .targetLuminanceNits = kClientTargetLuminanceNits, |
| 4195 | .dimmingStage = |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 4196 | aidl::android::hardware::graphics::composer3::DimmingStage::LINEAR, |
| 4197 | .renderIntent = aidl::android::hardware::graphics::composer3::RenderIntent:: |
| 4198 | COLORIMETRIC}) |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4199 | .execute() |
| 4200 | .expectAFenceWasReturned(); |
| 4201 | } |
| 4202 | |
| 4203 | TEST_F(OutputComposeSurfacesTest_UsesExpectedDisplaySettings, |
| 4204 | usesExpectedDisplaySettingsForHdrOnlyClientCompositionWithSkipClientTransform) { |
| 4205 | verify().ifMixedCompositionIs(false) |
| 4206 | .andIfUsesHdr(true) |
Leon Scroggins III | f6280bb | 2022-05-04 13:20:32 -0400 | [diff] [blame] | 4207 | .withDisplayBrightnessNits(kDisplayLuminance) |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 4208 | .withSdrWhitePointNits(kWhitePointLuminance) |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 4209 | .withDimmingStage(aidl::android::hardware::graphics::composer3::DimmingStage::LINEAR) |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 4210 | .withRenderIntent( |
| 4211 | aidl::android::hardware::graphics::composer3::RenderIntent::COLORIMETRIC) |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4212 | .andIfSkipColorTransform(true) |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 4213 | .withPixelFormat(std::nullopt) |
| 4214 | .withDataspace(kDefaultOutputDataspace) |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 4215 | .thenExpectDisplaySettingsUsed( |
| 4216 | {.physicalDisplay = kDefaultOutputDestinationClip, |
| 4217 | .clip = kDefaultOutputViewport, |
| 4218 | .maxLuminance = kDefaultMaxLuminance, |
Leon Scroggins III | f6280bb | 2022-05-04 13:20:32 -0400 | [diff] [blame] | 4219 | .currentLuminanceNits = kDisplayLuminance, |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 4220 | .outputDataspace = kDefaultOutputDataspace, |
| 4221 | .colorTransform = kDefaultColorTransformMat, |
| 4222 | .deviceHandlesColorTransform = true, |
| 4223 | .orientation = kDefaultOutputOrientationFlags, |
| 4224 | .targetLuminanceNits = kClientTargetLuminanceNits, |
| 4225 | .dimmingStage = |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 4226 | aidl::android::hardware::graphics::composer3::DimmingStage::LINEAR, |
| 4227 | .renderIntent = aidl::android::hardware::graphics::composer3::RenderIntent:: |
| 4228 | COLORIMETRIC}) |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4229 | .execute() |
| 4230 | .expectAFenceWasReturned(); |
| 4231 | } |
| 4232 | |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 4233 | TEST_F(OutputComposeSurfacesTest_UsesExpectedDisplaySettings, |
| 4234 | usesExpectedDisplaySettingsWithFp16Buffer) { |
| 4235 | SET_FLAG_FOR_TEST(flags::fp16_client_target, true); |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 4236 | verify().ifMixedCompositionIs(false) |
| 4237 | .andIfUsesHdr(true) |
| 4238 | .withDisplayBrightnessNits(kDisplayLuminance) |
| 4239 | .withSdrWhitePointNits(kWhitePointLuminance) |
| 4240 | .withDimmingStage(aidl::android::hardware::graphics::composer3::DimmingStage::LINEAR) |
| 4241 | .withRenderIntent( |
| 4242 | aidl::android::hardware::graphics::composer3::RenderIntent::COLORIMETRIC) |
| 4243 | .andIfSkipColorTransform(true) |
| 4244 | .withPixelFormat(PIXEL_FORMAT_RGBA_FP16) |
| 4245 | .withDataspace(ui::Dataspace::V0_SCRGB) |
| 4246 | .thenExpectDisplaySettingsUsed( |
| 4247 | {.physicalDisplay = kDefaultOutputDestinationClip, |
| 4248 | .clip = kDefaultOutputViewport, |
| 4249 | .maxLuminance = kDefaultMaxLuminance, |
| 4250 | .currentLuminanceNits = kDisplayLuminance, |
| 4251 | .outputDataspace = ui::Dataspace::V0_SCRGB, |
| 4252 | .colorTransform = kDefaultColorTransformMat, |
| 4253 | .deviceHandlesColorTransform = true, |
| 4254 | .orientation = kDefaultOutputOrientationFlags, |
| 4255 | .targetLuminanceNits = kClientTargetLuminanceNits * 0.75f, |
| 4256 | .dimmingStage = |
| 4257 | aidl::android::hardware::graphics::composer3::DimmingStage::LINEAR, |
| 4258 | .renderIntent = aidl::android::hardware::graphics::composer3::RenderIntent:: |
| 4259 | COLORIMETRIC}) |
| 4260 | .execute() |
| 4261 | .expectAFenceWasReturned(); |
| 4262 | } |
| 4263 | |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4264 | struct OutputComposeSurfacesTest_HandlesProtectedContent : public OutputComposeSurfacesTest { |
| 4265 | struct Layer { |
| 4266 | Layer() { |
Ady Abraham | eca9d75 | 2021-03-03 12:20:00 -0800 | [diff] [blame] | 4267 | EXPECT_CALL(*mLayerFE, getCompositionState()).WillRepeatedly(Return(&mLayerFEState)); |
| 4268 | EXPECT_CALL(mOutputLayer, getLayerFE()).WillRepeatedly(ReturnRef(*mLayerFE)); |
Eason Chiu | 4509966 | 2023-10-23 08:55:48 +0800 | [diff] [blame] | 4269 | EXPECT_CALL(mOutputLayer, requiresClientComposition()).WillRepeatedly(Return(true)); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4270 | } |
| 4271 | |
| 4272 | StrictMock<mock::OutputLayer> mOutputLayer; |
Ady Abraham | eca9d75 | 2021-03-03 12:20:00 -0800 | [diff] [blame] | 4273 | sp<StrictMock<mock::LayerFE>> mLayerFE = sp<StrictMock<mock::LayerFE>>::make(); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4274 | LayerFECompositionState mLayerFEState; |
| 4275 | }; |
| 4276 | |
| 4277 | OutputComposeSurfacesTest_HandlesProtectedContent() { |
| 4278 | mLayer1.mLayerFEState.hasProtectedContent = false; |
| 4279 | mLayer2.mLayerFEState.hasProtectedContent = false; |
| 4280 | |
| 4281 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(2u)); |
| 4282 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0u)) |
| 4283 | .WillRepeatedly(Return(&mLayer1.mOutputLayer)); |
| 4284 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(1u)) |
| 4285 | .WillRepeatedly(Return(&mLayer2.mOutputLayer)); |
| 4286 | |
| 4287 | EXPECT_CALL(mOutput, getSkipColorTransform()).WillRepeatedly(Return(false)); |
| 4288 | |
| 4289 | EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillRepeatedly(Return(true)); |
| 4290 | |
Robert Carr | ccab424 | 2021-09-28 16:53:03 -0700 | [diff] [blame] | 4291 | EXPECT_CALL(mOutput, generateClientCompositionRequests(_, _, _)) |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 4292 | .WillRepeatedly(Return(std::vector<LayerFE::LayerSettings>{})); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4293 | EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _)) |
| 4294 | .WillRepeatedly(Return()); |
| 4295 | EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer)); |
Alec Mouri | f29700f | 2023-08-17 21:53:31 +0000 | [diff] [blame] | 4296 | EXPECT_CALL(mRenderEngine, drawLayers(_, _, _, _)) |
Patrick Williams | 2e9748f | 2022-08-09 22:48:18 +0000 | [diff] [blame] | 4297 | .WillRepeatedly([&](const renderengine::DisplaySettings&, |
| 4298 | const std::vector<renderengine::LayerSettings>&, |
| 4299 | const std::shared_ptr<renderengine::ExternalTexture>&, |
Alec Mouri | f29700f | 2023-08-17 21:53:31 +0000 | [diff] [blame] | 4300 | base::unique_fd&&) -> ftl::Future<FenceResult> { |
Patrick Williams | 2e9748f | 2022-08-09 22:48:18 +0000 | [diff] [blame] | 4301 | return ftl::yield<FenceResult>(Fence::NO_FENCE); |
| 4302 | }); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4303 | } |
| 4304 | |
| 4305 | Layer mLayer1; |
| 4306 | Layer mLayer2; |
| 4307 | }; |
| 4308 | |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4309 | TEST_F(OutputComposeSurfacesTest_HandlesProtectedContent, ifNoProtectedContentLayers) { |
Eason Chiu | 4509966 | 2023-10-23 08:55:48 +0800 | [diff] [blame] | 4310 | SET_FLAG_FOR_TEST(flags::protected_if_client, true); |
Chavi Weingarten | cbec71d | 2023-12-14 20:53:25 +0000 | [diff] [blame] | 4311 | if (FlagManager::getInstance().display_protected()) { |
| 4312 | mOutput.mState.isProtected = true; |
| 4313 | } else { |
| 4314 | mOutput.mState.isSecure = true; |
| 4315 | } |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4316 | mLayer2.mLayerFEState.hasProtectedContent = false; |
| 4317 | EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(true)); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4318 | EXPECT_CALL(*mRenderSurface, isProtected).WillOnce(Return(true)); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4319 | EXPECT_CALL(*mRenderSurface, setProtected(false)); |
| 4320 | |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 4321 | base::unique_fd fd; |
| 4322 | std::shared_ptr<renderengine::ExternalTexture> tex; |
| 4323 | mOutput.updateProtectedContentState(); |
| 4324 | mOutput.dequeueRenderBuffer(&fd, &tex); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 4325 | mOutput.composeSurfaces(kDebugRegion, tex, fd); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4326 | } |
| 4327 | |
| 4328 | TEST_F(OutputComposeSurfacesTest_HandlesProtectedContent, ifNotEnabled) { |
Eason Chiu | 4509966 | 2023-10-23 08:55:48 +0800 | [diff] [blame] | 4329 | SET_FLAG_FOR_TEST(flags::protected_if_client, true); |
Chavi Weingarten | cbec71d | 2023-12-14 20:53:25 +0000 | [diff] [blame] | 4330 | if (FlagManager::getInstance().display_protected()) { |
| 4331 | mOutput.mState.isProtected = true; |
| 4332 | } else { |
| 4333 | mOutput.mState.isSecure = true; |
| 4334 | } |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4335 | mLayer2.mLayerFEState.hasProtectedContent = true; |
| 4336 | EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(true)); |
| 4337 | |
| 4338 | // For this test, we also check the call order of key functions. |
| 4339 | InSequence seq; |
| 4340 | |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4341 | EXPECT_CALL(*mRenderSurface, isProtected).WillOnce(Return(false)); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4342 | EXPECT_CALL(*mRenderSurface, setProtected(true)); |
| 4343 | // Must happen after setting the protected content state. |
| 4344 | EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer)); |
Alec Mouri | f29700f | 2023-08-17 21:53:31 +0000 | [diff] [blame] | 4345 | EXPECT_CALL(mRenderEngine, drawLayers(_, _, _, _)) |
Patrick Williams | 2e9748f | 2022-08-09 22:48:18 +0000 | [diff] [blame] | 4346 | .WillOnce(Return(ByMove(ftl::yield<FenceResult>(Fence::NO_FENCE)))); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4347 | |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 4348 | base::unique_fd fd; |
| 4349 | std::shared_ptr<renderengine::ExternalTexture> tex; |
| 4350 | mOutput.updateProtectedContentState(); |
| 4351 | mOutput.dequeueRenderBuffer(&fd, &tex); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 4352 | mOutput.composeSurfaces(kDebugRegion, tex, fd); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4353 | } |
| 4354 | |
| 4355 | TEST_F(OutputComposeSurfacesTest_HandlesProtectedContent, ifAlreadyEnabledEverywhere) { |
Eason Chiu | 4509966 | 2023-10-23 08:55:48 +0800 | [diff] [blame] | 4356 | SET_FLAG_FOR_TEST(flags::protected_if_client, true); |
Chavi Weingarten | cbec71d | 2023-12-14 20:53:25 +0000 | [diff] [blame] | 4357 | if (FlagManager::getInstance().display_protected()) { |
| 4358 | mOutput.mState.isProtected = true; |
| 4359 | } else { |
| 4360 | mOutput.mState.isSecure = true; |
| 4361 | } |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4362 | mLayer2.mLayerFEState.hasProtectedContent = true; |
| 4363 | EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(true)); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4364 | EXPECT_CALL(*mRenderSurface, isProtected).WillOnce(Return(true)); |
| 4365 | |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 4366 | base::unique_fd fd; |
| 4367 | std::shared_ptr<renderengine::ExternalTexture> tex; |
| 4368 | mOutput.updateProtectedContentState(); |
| 4369 | mOutput.dequeueRenderBuffer(&fd, &tex); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 4370 | mOutput.composeSurfaces(kDebugRegion, tex, fd); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4371 | } |
| 4372 | |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4373 | TEST_F(OutputComposeSurfacesTest_HandlesProtectedContent, ifAlreadyEnabledInRenderSurface) { |
Eason Chiu | 4509966 | 2023-10-23 08:55:48 +0800 | [diff] [blame] | 4374 | SET_FLAG_FOR_TEST(flags::protected_if_client, true); |
Chavi Weingarten | cbec71d | 2023-12-14 20:53:25 +0000 | [diff] [blame] | 4375 | if (FlagManager::getInstance().display_protected()) { |
| 4376 | mOutput.mState.isProtected = true; |
| 4377 | } else { |
| 4378 | mOutput.mState.isSecure = true; |
| 4379 | } |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4380 | mLayer2.mLayerFEState.hasProtectedContent = true; |
| 4381 | EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(true)); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4382 | EXPECT_CALL(*mRenderSurface, isProtected).WillOnce(Return(true)); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4383 | |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 4384 | base::unique_fd fd; |
| 4385 | std::shared_ptr<renderengine::ExternalTexture> tex; |
| 4386 | mOutput.updateProtectedContentState(); |
| 4387 | mOutput.dequeueRenderBuffer(&fd, &tex); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 4388 | mOutput.composeSurfaces(kDebugRegion, tex, fd); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4389 | } |
| 4390 | |
| 4391 | struct OutputComposeSurfacesTest_SetsExpensiveRendering : public OutputComposeSurfacesTest { |
| 4392 | OutputComposeSurfacesTest_SetsExpensiveRendering() { |
| 4393 | EXPECT_CALL(mOutput, getSkipColorTransform()).WillRepeatedly(Return(false)); |
| 4394 | EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillRepeatedly(Return(true)); |
| 4395 | EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false)); |
Peiyong Lin | 09f910f | 2020-09-25 10:54:13 -0700 | [diff] [blame] | 4396 | EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false)); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4397 | EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _)) |
| 4398 | .WillRepeatedly(Return()); |
| 4399 | EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer)); |
| 4400 | } |
| 4401 | }; |
| 4402 | |
| 4403 | TEST_F(OutputComposeSurfacesTest_SetsExpensiveRendering, IfExepensiveOutputDataspaceIsUsed) { |
| 4404 | mOutput.mState.dataspace = kExpensiveOutputDataspace; |
| 4405 | |
Leon Scroggins III | 7bdcceb | 2022-03-09 16:53:52 -0500 | [diff] [blame] | 4406 | LayerFE::LayerSettings layerSettings; |
Robert Carr | ccab424 | 2021-09-28 16:53:03 -0700 | [diff] [blame] | 4407 | EXPECT_CALL(mOutput, generateClientCompositionRequests(_, kExpensiveOutputDataspace, _)) |
Leon Scroggins III | 7bdcceb | 2022-03-09 16:53:52 -0500 | [diff] [blame] | 4408 | .WillOnce(Return(std::vector<LayerFE::LayerSettings>{layerSettings})); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4409 | |
| 4410 | // For this test, we also check the call order of key functions. |
| 4411 | InSequence seq; |
| 4412 | |
| 4413 | EXPECT_CALL(mOutput, setExpensiveRenderingExpected(true)); |
Alec Mouri | f29700f | 2023-08-17 21:53:31 +0000 | [diff] [blame] | 4414 | EXPECT_CALL(mRenderEngine, drawLayers(_, _, _, _)) |
Patrick Williams | 2e9748f | 2022-08-09 22:48:18 +0000 | [diff] [blame] | 4415 | .WillOnce(Return(ByMove(ftl::yield<FenceResult>(Fence::NO_FENCE)))); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4416 | |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 4417 | base::unique_fd fd; |
| 4418 | std::shared_ptr<renderengine::ExternalTexture> tex; |
| 4419 | mOutput.updateProtectedContentState(); |
| 4420 | mOutput.dequeueRenderBuffer(&fd, &tex); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 4421 | mOutput.composeSurfaces(kDebugRegion, tex, fd); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 4422 | } |
| 4423 | |
| 4424 | /* |
| 4425 | * Output::generateClientCompositionRequests() |
| 4426 | */ |
| 4427 | |
| 4428 | struct GenerateClientCompositionRequestsTest : public testing::Test { |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 4429 | struct OutputPartialMock : public OutputPartialMockBase { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 4430 | // compositionengine::Output overrides |
Robert Carr | ccab424 | 2021-09-28 16:53:03 -0700 | [diff] [blame] | 4431 | std::vector<LayerFE::LayerSettings> generateClientCompositionRequestsHelper( |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 4432 | bool supportsProtectedContent, ui::Dataspace dataspace) { |
Robert Carr | ccab424 | 2021-09-28 16:53:03 -0700 | [diff] [blame] | 4433 | std::vector<LayerFE*> ignore; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 4434 | return impl::Output::generateClientCompositionRequests(supportsProtectedContent, |
Robert Carr | ccab424 | 2021-09-28 16:53:03 -0700 | [diff] [blame] | 4435 | dataspace, ignore); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 4436 | } |
| 4437 | }; |
| 4438 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4439 | struct Layer { |
| 4440 | Layer() { |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 4441 | EXPECT_CALL(mOutputLayer, getOverrideCompositionSettings()) |
| 4442 | .WillRepeatedly(Return(std::nullopt)); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4443 | EXPECT_CALL(mOutputLayer, getState()).WillRepeatedly(ReturnRef(mOutputLayerState)); |
| 4444 | EXPECT_CALL(mOutputLayer, editState()).WillRepeatedly(ReturnRef(mOutputLayerState)); |
Ady Abraham | eca9d75 | 2021-03-03 12:20:00 -0800 | [diff] [blame] | 4445 | EXPECT_CALL(mOutputLayer, getLayerFE()).WillRepeatedly(ReturnRef(*mLayerFE)); |
| 4446 | EXPECT_CALL(*mLayerFE, getCompositionState()).WillRepeatedly(Return(&mLayerFEState)); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4447 | } |
| 4448 | |
| 4449 | StrictMock<mock::OutputLayer> mOutputLayer; |
Ady Abraham | eca9d75 | 2021-03-03 12:20:00 -0800 | [diff] [blame] | 4450 | sp<StrictMock<mock::LayerFE>> mLayerFE = sp<StrictMock<mock::LayerFE>>::make(); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4451 | LayerFECompositionState mLayerFEState; |
| 4452 | impl::OutputLayerCompositionState mOutputLayerState; |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 4453 | LayerFE::LayerSettings mLayerSettings; |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4454 | }; |
| 4455 | |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 4456 | GenerateClientCompositionRequestsTest() { |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4457 | mOutput.mState.needsFiltering = false; |
Chavi Weingarten | cbec71d | 2023-12-14 20:53:25 +0000 | [diff] [blame] | 4458 | mOutput.mState.isProtected = true; |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4459 | |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 4460 | mOutput.setDisplayColorProfileForTest( |
| 4461 | std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile)); |
| 4462 | mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface)); |
| 4463 | } |
| 4464 | |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 4465 | static constexpr float kLayerWhitePointNits = 200.f; |
| 4466 | |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 4467 | mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>(); |
| 4468 | mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>(); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 4469 | StrictMock<OutputPartialMock> mOutput; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 4470 | }; |
| 4471 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4472 | struct GenerateClientCompositionRequestsTest_ThreeLayers |
| 4473 | : public GenerateClientCompositionRequestsTest { |
| 4474 | GenerateClientCompositionRequestsTest_ThreeLayers() { |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 4475 | mOutput.mState.orientedDisplaySpace.setContent(kDisplayFrame); |
| 4476 | mOutput.mState.layerStackSpace.setContent(kDisplayViewport); |
| 4477 | mOutput.mState.displaySpace.setContent(kDisplayDestinationClip); |
Marin Shalamanov | 68933fb | 2020-09-10 17:58:12 +0200 | [diff] [blame] | 4478 | mOutput.mState.transform = |
| 4479 | ui::Transform{ui::Transform::toRotationFlags(kDisplayOrientation)}; |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 4480 | mOutput.mState.displaySpace.setOrientation(kDisplayOrientation); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4481 | mOutput.mState.needsFiltering = false; |
| 4482 | mOutput.mState.isSecure = false; |
Chavi Weingarten | cbec71d | 2023-12-14 20:53:25 +0000 | [diff] [blame] | 4483 | mOutput.mState.isProtected = true; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 4484 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4485 | for (size_t i = 0; i < mLayers.size(); i++) { |
| 4486 | mLayers[i].mOutputLayerState.clearClientTarget = false; |
| 4487 | mLayers[i].mOutputLayerState.visibleRegion = Region(kDisplayFrame); |
| 4488 | mLayers[i].mLayerFEState.isOpaque = true; |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 4489 | mLayers[i].mLayerSettings.geometry.boundaries = |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4490 | FloatRect{static_cast<float>(i + 1), 0.f, 0.f, 0.f}; |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 4491 | mLayers[i].mLayerSettings.source.solidColor = {1.0f, 1.0f, 1.0f}; |
| 4492 | mLayers[i].mLayerSettings.alpha = 1.0f; |
| 4493 | mLayers[i].mLayerSettings.disableBlending = false; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 4494 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4495 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(i)) |
| 4496 | .WillRepeatedly(Return(&mLayers[i].mOutputLayer)); |
| 4497 | EXPECT_CALL(mLayers[i].mOutputLayer, requiresClientComposition()) |
| 4498 | .WillRepeatedly(Return(true)); |
| 4499 | EXPECT_CALL(mLayers[i].mOutputLayer, needsFiltering()).WillRepeatedly(Return(false)); |
| 4500 | } |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 4501 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4502 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(mLayers.size())); |
| 4503 | } |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 4504 | |
Marin Shalamanov | 68933fb | 2020-09-10 17:58:12 +0200 | [diff] [blame] | 4505 | static constexpr ui::Rotation kDisplayOrientation = ui::ROTATION_0; |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4506 | static constexpr ui::Dataspace kDisplayDataspace = ui::Dataspace::UNKNOWN; |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 4507 | static constexpr float kLayerWhitePointNits = 200.f; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 4508 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4509 | static const Rect kDisplayFrame; |
| 4510 | static const Rect kDisplayViewport; |
Lloyd Pique | e8fe474 | 2020-01-21 15:26:18 -0800 | [diff] [blame] | 4511 | static const Rect kDisplayDestinationClip; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 4512 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4513 | std::array<Layer, 3> mLayers; |
| 4514 | }; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 4515 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4516 | const Rect GenerateClientCompositionRequestsTest_ThreeLayers::kDisplayFrame(0, 0, 100, 200); |
| 4517 | const Rect GenerateClientCompositionRequestsTest_ThreeLayers::kDisplayViewport(0, 0, 101, 201); |
Lloyd Pique | e8fe474 | 2020-01-21 15:26:18 -0800 | [diff] [blame] | 4518 | const Rect GenerateClientCompositionRequestsTest_ThreeLayers::kDisplayDestinationClip(0, 0, 103, |
| 4519 | 203); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 4520 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4521 | TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers, handlesNoClientCompostionLayers) { |
| 4522 | EXPECT_CALL(mLayers[0].mOutputLayer, requiresClientComposition()).WillOnce(Return(false)); |
| 4523 | EXPECT_CALL(mLayers[1].mOutputLayer, requiresClientComposition()).WillOnce(Return(false)); |
| 4524 | EXPECT_CALL(mLayers[2].mOutputLayer, requiresClientComposition()).WillOnce(Return(false)); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 4525 | |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 4526 | auto requests = |
| 4527 | mOutput.generateClientCompositionRequestsHelper(false /* supportsProtectedContent */, |
| 4528 | kDisplayDataspace); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 4529 | EXPECT_EQ(0u, requests.size()); |
| 4530 | } |
| 4531 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4532 | TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers, requiresVisibleRegionAfterViewportClip) { |
| 4533 | mLayers[0].mOutputLayerState.visibleRegion = Region(Rect(10, 10, 10, 10)); |
| 4534 | mLayers[1].mOutputLayerState.visibleRegion = Region(Rect(4000, 0, 4010, 10)); |
| 4535 | mLayers[2].mOutputLayerState.visibleRegion = Region(Rect(-10, -10, 0, 0)); |
| 4536 | |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 4537 | auto requests = |
| 4538 | mOutput.generateClientCompositionRequestsHelper(false /* supportsProtectedContent */, |
| 4539 | kDisplayDataspace); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4540 | EXPECT_EQ(0u, requests.size()); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4541 | } |
| 4542 | |
| 4543 | TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers, gathersClientCompositionRequests) { |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 4544 | EXPECT_CALL(*mLayers[0].mLayerFE, prepareClientComposition(_)) |
| 4545 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>())); |
| 4546 | EXPECT_CALL(*mLayers[1].mLayerFE, prepareClientComposition(_)) |
| 4547 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>(mLayers[1].mLayerSettings))); |
| 4548 | EXPECT_CALL(*mLayers[2].mLayerFE, prepareClientComposition(_)) |
| 4549 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>(mLayers[2].mLayerSettings))); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4550 | |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 4551 | auto requests = |
| 4552 | mOutput.generateClientCompositionRequestsHelper(false /* supportsProtectedContent */, |
| 4553 | kDisplayDataspace); |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 4554 | ASSERT_EQ(2u, requests.size()); |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 4555 | EXPECT_EQ(mLayers[1].mLayerSettings, requests[0]); |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 4556 | EXPECT_EQ(mLayers[2].mLayerSettings, requests[1]); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4557 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4558 | // Check that a timestamp was set for the layers that generated requests |
| 4559 | EXPECT_TRUE(0 == mLayers[0].mOutputLayerState.clientCompositionTimestamp); |
| 4560 | EXPECT_TRUE(0 != mLayers[1].mOutputLayerState.clientCompositionTimestamp); |
| 4561 | EXPECT_TRUE(0 != mLayers[2].mOutputLayerState.clientCompositionTimestamp); |
| 4562 | } |
| 4563 | |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 4564 | MATCHER_P(ClientCompositionTargetSettingsBlurSettingsEq, expectedBlurSetting, "") { |
| 4565 | *result_listener << "ClientCompositionTargetSettings' BlurSettings aren't equal \n"; |
| 4566 | *result_listener << "expected " << expectedBlurSetting << "\n"; |
| 4567 | *result_listener << "actual " << arg.blurSetting << "\n"; |
| 4568 | |
| 4569 | return expectedBlurSetting == arg.blurSetting; |
| 4570 | } |
| 4571 | |
| 4572 | TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers, overridesBlur) { |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 4573 | mLayers[2].mOutputLayerState.overrideInfo.disableBackgroundBlur = true; |
| 4574 | |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 4575 | EXPECT_CALL(*mLayers[0].mLayerFE, prepareClientComposition(_)) |
| 4576 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>())); |
| 4577 | EXPECT_CALL(*mLayers[1].mLayerFE, prepareClientComposition(_)) |
| 4578 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>(mLayers[1].mLayerSettings))); |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 4579 | EXPECT_CALL(*mLayers[2].mLayerFE, |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 4580 | prepareClientComposition(ClientCompositionTargetSettingsBlurSettingsEq( |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 4581 | LayerFE::ClientCompositionTargetSettings::BlurSetting::BlurRegionsOnly))) |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 4582 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>(mLayers[2].mLayerSettings))); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 4583 | auto requests = |
| 4584 | mOutput.generateClientCompositionRequestsHelper(false /* supportsProtectedContent */, |
| 4585 | kDisplayDataspace); |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 4586 | ASSERT_EQ(2u, requests.size()); |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 4587 | EXPECT_EQ(mLayers[1].mLayerSettings, requests[0]); |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 4588 | EXPECT_EQ(mLayers[2].mLayerSettings, requests[1]); |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 4589 | |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 4590 | // Check that a timestamp was set for the layers that generated requests |
| 4591 | EXPECT_TRUE(0 == mLayers[0].mOutputLayerState.clientCompositionTimestamp); |
| 4592 | EXPECT_TRUE(0 != mLayers[1].mOutputLayerState.clientCompositionTimestamp); |
| 4593 | EXPECT_TRUE(0 != mLayers[2].mOutputLayerState.clientCompositionTimestamp); |
| 4594 | } |
| 4595 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4596 | TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers, |
| 4597 | onlyClientComposesClientComposedLayersIfNoClearingNeeded) { |
| 4598 | EXPECT_CALL(mLayers[0].mOutputLayer, requiresClientComposition()).WillOnce(Return(false)); |
| 4599 | EXPECT_CALL(mLayers[1].mOutputLayer, requiresClientComposition()).WillOnce(Return(false)); |
| 4600 | EXPECT_CALL(mLayers[2].mOutputLayer, requiresClientComposition()).WillOnce(Return(true)); |
| 4601 | |
| 4602 | mLayers[0].mOutputLayerState.clearClientTarget = false; |
| 4603 | mLayers[1].mOutputLayerState.clearClientTarget = false; |
| 4604 | mLayers[2].mOutputLayerState.clearClientTarget = false; |
| 4605 | |
| 4606 | mLayers[0].mLayerFEState.isOpaque = true; |
| 4607 | mLayers[1].mLayerFEState.isOpaque = true; |
| 4608 | mLayers[2].mLayerFEState.isOpaque = true; |
| 4609 | |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 4610 | EXPECT_CALL(*mLayers[2].mLayerFE, prepareClientComposition(_)) |
| 4611 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>(mLayers[2].mLayerSettings))); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4612 | |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 4613 | auto requests = |
| 4614 | mOutput.generateClientCompositionRequestsHelper(false /* supportsProtectedContent */, |
| 4615 | kDisplayDataspace); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4616 | ASSERT_EQ(1u, requests.size()); |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 4617 | EXPECT_EQ(mLayers[2].mLayerSettings, requests[0]); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4618 | } |
| 4619 | |
| 4620 | TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers, |
| 4621 | onlyClientComposesClientComposedLayersIfOthersAreNotOpaque) { |
| 4622 | EXPECT_CALL(mLayers[0].mOutputLayer, requiresClientComposition()).WillOnce(Return(false)); |
| 4623 | EXPECT_CALL(mLayers[1].mOutputLayer, requiresClientComposition()).WillOnce(Return(false)); |
| 4624 | EXPECT_CALL(mLayers[2].mOutputLayer, requiresClientComposition()).WillOnce(Return(true)); |
| 4625 | |
| 4626 | mLayers[0].mOutputLayerState.clearClientTarget = true; |
| 4627 | mLayers[1].mOutputLayerState.clearClientTarget = true; |
| 4628 | mLayers[2].mOutputLayerState.clearClientTarget = true; |
| 4629 | |
| 4630 | mLayers[0].mLayerFEState.isOpaque = false; |
| 4631 | mLayers[1].mLayerFEState.isOpaque = false; |
| 4632 | mLayers[2].mLayerFEState.isOpaque = false; |
| 4633 | |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 4634 | EXPECT_CALL(*mLayers[2].mLayerFE, prepareClientComposition(_)) |
| 4635 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>(mLayers[2].mLayerSettings))); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4636 | |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 4637 | auto requests = |
| 4638 | mOutput.generateClientCompositionRequestsHelper(false /* supportsProtectedContent */, |
| 4639 | kDisplayDataspace); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4640 | ASSERT_EQ(1u, requests.size()); |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 4641 | EXPECT_EQ(mLayers[2].mLayerSettings, requests[0]); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4642 | } |
| 4643 | |
| 4644 | TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers, clearsHWCLayersIfOpaqueAndNotFirst) { |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 4645 | // If client composition is performed with some layers set to use device |
| 4646 | // composition, device layers after the first layer (device or client) will |
| 4647 | // clear the frame buffer if they are opaque and if that layer has a flag |
| 4648 | // set to do so. The first layer is skipped as the frame buffer is already |
| 4649 | // expected to be clear. |
| 4650 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4651 | EXPECT_CALL(mLayers[0].mOutputLayer, requiresClientComposition()).WillOnce(Return(false)); |
| 4652 | EXPECT_CALL(mLayers[1].mOutputLayer, requiresClientComposition()).WillOnce(Return(false)); |
| 4653 | EXPECT_CALL(mLayers[2].mOutputLayer, requiresClientComposition()).WillOnce(Return(true)); |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 4654 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4655 | mLayers[0].mOutputLayerState.clearClientTarget = true; |
| 4656 | mLayers[1].mOutputLayerState.clearClientTarget = true; |
| 4657 | mLayers[2].mOutputLayerState.clearClientTarget = true; |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 4658 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4659 | mLayers[0].mLayerFEState.isOpaque = true; |
| 4660 | mLayers[1].mLayerFEState.isOpaque = true; |
| 4661 | mLayers[2].mLayerFEState.isOpaque = true; |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 4662 | |
| 4663 | compositionengine::LayerFE::ClientCompositionTargetSettings layer1TargetSettings{ |
| 4664 | Region(kDisplayFrame), |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 4665 | false, /* needs filtering */ |
| 4666 | false, /* secure */ |
| 4667 | false, /* supports protected content */ |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 4668 | kDisplayViewport, |
| 4669 | kDisplayDataspace, |
| 4670 | false /* realContentIsVisible */, |
| 4671 | true /* clearContent */, |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 4672 | compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled, |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 4673 | kLayerWhitePointNits, |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 4674 | false /* treat170mAsSrgb */, |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 4675 | }; |
| 4676 | compositionengine::LayerFE::ClientCompositionTargetSettings layer2TargetSettings{ |
| 4677 | Region(kDisplayFrame), |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 4678 | false, /* needs filtering */ |
| 4679 | false, /* secure */ |
| 4680 | false, /* supports protected content */ |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 4681 | kDisplayViewport, |
| 4682 | kDisplayDataspace, |
| 4683 | true /* realContentIsVisible */, |
| 4684 | false /* clearContent */, |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 4685 | compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled, |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 4686 | kLayerWhitePointNits, |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 4687 | false /* treat170mAsSrgb */, |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 4688 | }; |
| 4689 | |
| 4690 | LayerFE::LayerSettings mBlackoutSettings = mLayers[1].mLayerSettings; |
| 4691 | mBlackoutSettings.source.buffer.buffer = nullptr; |
| 4692 | mBlackoutSettings.source.solidColor = {0.1f, 0.1f, 0.1f}; |
| 4693 | mBlackoutSettings.alpha = 0.f; |
| 4694 | mBlackoutSettings.disableBlending = true; |
| 4695 | |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 4696 | EXPECT_CALL(*mLayers[1].mLayerFE, prepareClientComposition(Eq(ByRef(layer1TargetSettings)))) |
| 4697 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>(mBlackoutSettings))); |
| 4698 | EXPECT_CALL(*mLayers[2].mLayerFE, prepareClientComposition(Eq(ByRef(layer2TargetSettings)))) |
| 4699 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>(mLayers[2].mLayerSettings))); |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 4700 | |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 4701 | auto requests = |
| 4702 | mOutput.generateClientCompositionRequestsHelper(false /* supportsProtectedContent */, |
| 4703 | kDisplayDataspace); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4704 | ASSERT_EQ(2u, requests.size()); |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 4705 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4706 | // 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] | 4707 | EXPECT_EQ(mBlackoutSettings, requests[0]); |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 4708 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 4709 | EXPECT_EQ(mLayers[2].mLayerSettings, requests[1]); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4710 | } |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 4711 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4712 | TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers, |
| 4713 | clippedVisibleRegionUsedToGenerateRequest) { |
| 4714 | mLayers[0].mOutputLayerState.visibleRegion = Region(Rect(10, 10, 20, 20)); |
| 4715 | mLayers[1].mOutputLayerState.visibleRegion = Region(Rect(-10, -10, 30, 30)); |
| 4716 | mLayers[2].mOutputLayerState.visibleRegion = Region(Rect(-10, 0, 40, 4000)); |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 4717 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4718 | compositionengine::LayerFE::ClientCompositionTargetSettings layer0TargetSettings{ |
| 4719 | Region(Rect(10, 10, 20, 20)), |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4720 | false, /* needs filtering */ |
| 4721 | false, /* secure */ |
| 4722 | false, /* supports protected content */ |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 4723 | kDisplayViewport, |
| 4724 | kDisplayDataspace, |
| 4725 | true /* realContentIsVisible */, |
| 4726 | false /* clearContent */, |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 4727 | compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled, |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 4728 | kLayerWhitePointNits, |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 4729 | false /* treat170mAsSrgb */, |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4730 | }; |
| 4731 | compositionengine::LayerFE::ClientCompositionTargetSettings layer1TargetSettings{ |
| 4732 | Region(Rect(0, 0, 30, 30)), |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4733 | false, /* needs filtering */ |
| 4734 | false, /* secure */ |
| 4735 | false, /* supports protected content */ |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 4736 | kDisplayViewport, |
| 4737 | kDisplayDataspace, |
| 4738 | true /* realContentIsVisible */, |
| 4739 | false /* clearContent */, |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 4740 | compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled, |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 4741 | kLayerWhitePointNits, |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 4742 | false /* treat170mAsSrgb */, |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4743 | }; |
| 4744 | compositionengine::LayerFE::ClientCompositionTargetSettings layer2TargetSettings{ |
| 4745 | Region(Rect(0, 0, 40, 201)), |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4746 | false, /* needs filtering */ |
| 4747 | false, /* secure */ |
| 4748 | false, /* supports protected content */ |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 4749 | kDisplayViewport, |
| 4750 | kDisplayDataspace, |
| 4751 | true /* realContentIsVisible */, |
| 4752 | false /* clearContent */, |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 4753 | compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled, |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 4754 | kLayerWhitePointNits, |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 4755 | false /* treat170mAsSrgb */, |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4756 | }; |
| 4757 | |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 4758 | EXPECT_CALL(*mLayers[0].mLayerFE, prepareClientComposition(Eq(ByRef(layer0TargetSettings)))) |
| 4759 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>())); |
| 4760 | EXPECT_CALL(*mLayers[1].mLayerFE, prepareClientComposition(Eq(ByRef(layer1TargetSettings)))) |
| 4761 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>())); |
| 4762 | EXPECT_CALL(*mLayers[2].mLayerFE, prepareClientComposition(Eq(ByRef(layer2TargetSettings)))) |
| 4763 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>())); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4764 | |
| 4765 | static_cast<void>( |
Robert Carr | ccab424 | 2021-09-28 16:53:03 -0700 | [diff] [blame] | 4766 | mOutput.generateClientCompositionRequestsHelper(false /* supportsProtectedContent */, |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 4767 | kDisplayDataspace)); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4768 | } |
| 4769 | |
| 4770 | TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers, |
| 4771 | perLayerNeedsFilteringUsedToGenerateRequests) { |
| 4772 | mOutput.mState.needsFiltering = false; |
| 4773 | EXPECT_CALL(mLayers[0].mOutputLayer, needsFiltering()).WillRepeatedly(Return(true)); |
| 4774 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4775 | compositionengine::LayerFE::ClientCompositionTargetSettings layer0TargetSettings{ |
| 4776 | Region(kDisplayFrame), |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4777 | true, /* needs filtering */ |
| 4778 | false, /* secure */ |
| 4779 | false, /* supports protected content */ |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 4780 | kDisplayViewport, |
| 4781 | kDisplayDataspace, |
| 4782 | true /* realContentIsVisible */, |
| 4783 | false /* clearContent */, |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 4784 | compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled, |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 4785 | kLayerWhitePointNits, |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 4786 | false /* treat170mAsSrgb */, |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4787 | }; |
| 4788 | compositionengine::LayerFE::ClientCompositionTargetSettings layer1TargetSettings{ |
| 4789 | Region(kDisplayFrame), |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4790 | false, /* needs filtering */ |
| 4791 | false, /* secure */ |
| 4792 | false, /* supports protected content */ |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 4793 | kDisplayViewport, |
| 4794 | kDisplayDataspace, |
| 4795 | true /* realContentIsVisible */, |
| 4796 | false /* clearContent */, |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 4797 | compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled, |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 4798 | kLayerWhitePointNits, |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 4799 | false /* treat170mAsSrgb */, |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4800 | }; |
| 4801 | compositionengine::LayerFE::ClientCompositionTargetSettings layer2TargetSettings{ |
| 4802 | Region(kDisplayFrame), |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4803 | false, /* needs filtering */ |
| 4804 | false, /* secure */ |
| 4805 | false, /* supports protected content */ |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 4806 | kDisplayViewport, |
| 4807 | kDisplayDataspace, |
| 4808 | true /* realContentIsVisible */, |
| 4809 | false /* clearContent */, |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 4810 | compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled, |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 4811 | kLayerWhitePointNits, |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 4812 | false /* treat170mAsSrgb */, |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4813 | }; |
| 4814 | |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 4815 | EXPECT_CALL(*mLayers[0].mLayerFE, prepareClientComposition(Eq(ByRef(layer0TargetSettings)))) |
| 4816 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>())); |
| 4817 | EXPECT_CALL(*mLayers[1].mLayerFE, prepareClientComposition(Eq(ByRef(layer1TargetSettings)))) |
| 4818 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>())); |
| 4819 | EXPECT_CALL(*mLayers[2].mLayerFE, prepareClientComposition(Eq(ByRef(layer2TargetSettings)))) |
| 4820 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>())); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4821 | |
| 4822 | static_cast<void>( |
Robert Carr | ccab424 | 2021-09-28 16:53:03 -0700 | [diff] [blame] | 4823 | mOutput.generateClientCompositionRequestsHelper(false /* supportsProtectedContent */, |
| 4824 | kDisplayDataspace)); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4825 | } |
| 4826 | |
| 4827 | TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers, |
| 4828 | wholeOutputNeedsFilteringUsedToGenerateRequests) { |
| 4829 | mOutput.mState.needsFiltering = true; |
| 4830 | EXPECT_CALL(mLayers[0].mOutputLayer, needsFiltering()).WillRepeatedly(Return(true)); |
| 4831 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4832 | compositionengine::LayerFE::ClientCompositionTargetSettings layer0TargetSettings{ |
| 4833 | Region(kDisplayFrame), |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4834 | true, /* needs filtering */ |
| 4835 | false, /* secure */ |
| 4836 | false, /* supports protected content */ |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 4837 | kDisplayViewport, |
| 4838 | kDisplayDataspace, |
| 4839 | true /* realContentIsVisible */, |
| 4840 | false /* clearContent */, |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 4841 | compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled, |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 4842 | kLayerWhitePointNits, |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 4843 | false /* treat170mAsSrgb */, |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4844 | }; |
| 4845 | compositionengine::LayerFE::ClientCompositionTargetSettings layer1TargetSettings{ |
| 4846 | Region(kDisplayFrame), |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4847 | true, /* needs filtering */ |
| 4848 | false, /* secure */ |
| 4849 | false, /* supports protected content */ |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 4850 | kDisplayViewport, |
| 4851 | kDisplayDataspace, |
| 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 | compositionengine::LayerFE::ClientCompositionTargetSettings layer2TargetSettings{ |
| 4859 | Region(kDisplayFrame), |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4860 | true, /* needs filtering */ |
| 4861 | false, /* secure */ |
| 4862 | false, /* supports protected content */ |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 4863 | kDisplayViewport, |
| 4864 | kDisplayDataspace, |
| 4865 | true /* realContentIsVisible */, |
| 4866 | false /* clearContent */, |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 4867 | compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled, |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 4868 | kLayerWhitePointNits, |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 4869 | false /* treat170mAsSrgb */, |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4870 | }; |
| 4871 | |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 4872 | EXPECT_CALL(*mLayers[0].mLayerFE, prepareClientComposition(Eq(ByRef(layer0TargetSettings)))) |
| 4873 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>())); |
| 4874 | EXPECT_CALL(*mLayers[1].mLayerFE, prepareClientComposition(Eq(ByRef(layer1TargetSettings)))) |
| 4875 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>())); |
| 4876 | EXPECT_CALL(*mLayers[2].mLayerFE, prepareClientComposition(Eq(ByRef(layer2TargetSettings)))) |
| 4877 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>())); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4878 | |
| 4879 | static_cast<void>( |
Robert Carr | ccab424 | 2021-09-28 16:53:03 -0700 | [diff] [blame] | 4880 | mOutput.generateClientCompositionRequestsHelper(false /* supportsProtectedContent */, |
| 4881 | kDisplayDataspace)); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4882 | } |
| 4883 | |
| 4884 | TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers, |
| 4885 | wholeOutputSecurityUsedToGenerateRequests) { |
| 4886 | mOutput.mState.isSecure = true; |
| 4887 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4888 | compositionengine::LayerFE::ClientCompositionTargetSettings layer0TargetSettings{ |
| 4889 | Region(kDisplayFrame), |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4890 | false, /* needs filtering */ |
| 4891 | true, /* secure */ |
| 4892 | false, /* supports protected content */ |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 4893 | kDisplayViewport, |
| 4894 | kDisplayDataspace, |
| 4895 | true /* realContentIsVisible */, |
| 4896 | false /* clearContent */, |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 4897 | compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled, |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 4898 | kLayerWhitePointNits, |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 4899 | false /* treat170mAsSrgb */, |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4900 | }; |
| 4901 | compositionengine::LayerFE::ClientCompositionTargetSettings layer1TargetSettings{ |
| 4902 | Region(kDisplayFrame), |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4903 | false, /* needs filtering */ |
| 4904 | true, /* secure */ |
| 4905 | false, /* supports protected content */ |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 4906 | kDisplayViewport, |
| 4907 | kDisplayDataspace, |
| 4908 | true /* realContentIsVisible */, |
| 4909 | false /* clearContent */, |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 4910 | compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled, |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 4911 | kLayerWhitePointNits, |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 4912 | false /* treat170mAsSrgb */, |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4913 | }; |
| 4914 | compositionengine::LayerFE::ClientCompositionTargetSettings layer2TargetSettings{ |
| 4915 | Region(kDisplayFrame), |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4916 | false, /* needs filtering */ |
| 4917 | true, /* secure */ |
| 4918 | false, /* supports protected content */ |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 4919 | kDisplayViewport, |
| 4920 | kDisplayDataspace, |
| 4921 | true /* realContentIsVisible */, |
| 4922 | false /* clearContent */, |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 4923 | compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled, |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 4924 | kLayerWhitePointNits, |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 4925 | false /* treat170mAsSrgb */, |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4926 | }; |
| 4927 | |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 4928 | EXPECT_CALL(*mLayers[0].mLayerFE, prepareClientComposition(Eq(ByRef(layer0TargetSettings)))) |
| 4929 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>())); |
| 4930 | EXPECT_CALL(*mLayers[1].mLayerFE, prepareClientComposition(Eq(ByRef(layer1TargetSettings)))) |
| 4931 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>())); |
| 4932 | EXPECT_CALL(*mLayers[2].mLayerFE, prepareClientComposition(Eq(ByRef(layer2TargetSettings)))) |
| 4933 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>())); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4934 | |
| 4935 | static_cast<void>( |
Robert Carr | ccab424 | 2021-09-28 16:53:03 -0700 | [diff] [blame] | 4936 | mOutput.generateClientCompositionRequestsHelper(false /* supportsProtectedContent */, |
| 4937 | kDisplayDataspace)); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4938 | } |
| 4939 | |
| 4940 | TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers, |
| 4941 | protectedContentSupportUsedToGenerateRequests) { |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4942 | compositionengine::LayerFE::ClientCompositionTargetSettings layer0TargetSettings{ |
| 4943 | Region(kDisplayFrame), |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4944 | false, /* needs filtering */ |
| 4945 | false, /* secure */ |
Chavi Weingarten | cbec71d | 2023-12-14 20:53:25 +0000 | [diff] [blame] | 4946 | true, /* isProtected */ |
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 */, |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4954 | }; |
| 4955 | compositionengine::LayerFE::ClientCompositionTargetSettings layer1TargetSettings{ |
| 4956 | Region(kDisplayFrame), |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4957 | false, /* needs filtering */ |
| 4958 | false, /* secure */ |
Chavi Weingarten | cbec71d | 2023-12-14 20:53:25 +0000 | [diff] [blame] | 4959 | true, /* isProtected */ |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 4960 | kDisplayViewport, |
| 4961 | kDisplayDataspace, |
| 4962 | true /* realContentIsVisible */, |
| 4963 | false /* clearContent */, |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 4964 | compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled, |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 4965 | kLayerWhitePointNits, |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 4966 | false /* treat170mAsSrgb */, |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4967 | }; |
| 4968 | compositionengine::LayerFE::ClientCompositionTargetSettings layer2TargetSettings{ |
| 4969 | Region(kDisplayFrame), |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4970 | false, /* needs filtering */ |
| 4971 | false, /* secure */ |
Chavi Weingarten | cbec71d | 2023-12-14 20:53:25 +0000 | [diff] [blame] | 4972 | true, /* isProtected */ |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 4973 | kDisplayViewport, |
| 4974 | kDisplayDataspace, |
| 4975 | true /* realContentIsVisible */, |
| 4976 | false /* clearContent */, |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 4977 | compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled, |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 4978 | kLayerWhitePointNits, |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 4979 | false /* treat170mAsSrgb */, |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4980 | }; |
| 4981 | |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 4982 | EXPECT_CALL(*mLayers[0].mLayerFE, prepareClientComposition(Eq(ByRef(layer0TargetSettings)))) |
| 4983 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>())); |
| 4984 | EXPECT_CALL(*mLayers[1].mLayerFE, prepareClientComposition(Eq(ByRef(layer1TargetSettings)))) |
| 4985 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>())); |
| 4986 | EXPECT_CALL(*mLayers[2].mLayerFE, prepareClientComposition(Eq(ByRef(layer2TargetSettings)))) |
| 4987 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>())); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4988 | |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 4989 | static_cast<void>( |
| 4990 | mOutput.generateClientCompositionRequestsHelper(true /* supportsProtectedContent */, |
| 4991 | kDisplayDataspace)); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4992 | } |
| 4993 | |
Lucas Dupin | 084a6d4 | 2021-08-26 22:10:29 +0000 | [diff] [blame] | 4994 | TEST_F(OutputUpdateAndWriteCompositionStateTest, noBackgroundBlurWhenOpaque) { |
| 4995 | InjectedLayer layer1; |
| 4996 | InjectedLayer layer2; |
| 4997 | |
| 4998 | uint32_t z = 0; |
| 4999 | // Layer requesting blur, or below, should request client composition, unless opaque. |
| 5000 | EXPECT_CALL(*layer1.outputLayer, updateCompositionState(false, false, ui::Transform::ROT_0)); |
| 5001 | EXPECT_CALL(*layer1.outputLayer, |
| 5002 | writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, z++, |
| 5003 | /*zIsOverridden*/ false, /*isPeekingThrough*/ false)); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 5004 | EXPECT_CALL(*layer1.outputLayer, requiresClientComposition()).WillRepeatedly(Return(false)); |
Lucas Dupin | 084a6d4 | 2021-08-26 22:10:29 +0000 | [diff] [blame] | 5005 | EXPECT_CALL(*layer2.outputLayer, updateCompositionState(false, false, ui::Transform::ROT_0)); |
| 5006 | EXPECT_CALL(*layer2.outputLayer, |
| 5007 | writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, z++, |
| 5008 | /*zIsOverridden*/ false, /*isPeekingThrough*/ false)); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 5009 | EXPECT_CALL(*layer2.outputLayer, requiresClientComposition()).WillRepeatedly(Return(false)); |
Lucas Dupin | 084a6d4 | 2021-08-26 22:10:29 +0000 | [diff] [blame] | 5010 | |
| 5011 | layer2.layerFEState.backgroundBlurRadius = 10; |
| 5012 | layer2.layerFEState.isOpaque = true; |
| 5013 | |
| 5014 | injectOutputLayer(layer1); |
| 5015 | injectOutputLayer(layer2); |
| 5016 | |
| 5017 | mOutput->editState().isEnabled = true; |
| 5018 | |
| 5019 | CompositionRefreshArgs args; |
| 5020 | args.updatingGeometryThisFrame = false; |
| 5021 | args.devOptForceClientComposition = false; |
| 5022 | mOutput->updateCompositionState(args); |
| 5023 | mOutput->planComposition(); |
| 5024 | mOutput->writeCompositionState(args); |
| 5025 | } |
| 5026 | |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 5027 | TEST_F(OutputUpdateAndWriteCompositionStateTest, handlesBackgroundBlurRequests) { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 5028 | InjectedLayer layer1; |
| 5029 | InjectedLayer layer2; |
| 5030 | InjectedLayer layer3; |
| 5031 | |
Leon Scroggins III | e2ee040 | 2021-04-02 16:59:37 -0400 | [diff] [blame] | 5032 | uint32_t z = 0; |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 5033 | // Layer requesting blur, or below, should request client composition. |
Snild Dolkow | 9e217d6 | 2020-04-22 15:53:42 +0200 | [diff] [blame] | 5034 | EXPECT_CALL(*layer1.outputLayer, updateCompositionState(false, true, ui::Transform::ROT_0)); |
Dan Stoza | 6166c31 | 2021-01-15 16:34:05 -0800 | [diff] [blame] | 5035 | EXPECT_CALL(*layer1.outputLayer, |
Leon Scroggins III | 9aa25c2 | 2021-04-15 15:30:19 -0400 | [diff] [blame] | 5036 | writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, z++, |
| 5037 | /*zIsOverridden*/ false, /*isPeekingThrough*/ false)); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 5038 | EXPECT_CALL(*layer1.outputLayer, requiresClientComposition()).WillRepeatedly(Return(false)); |
Snild Dolkow | 9e217d6 | 2020-04-22 15:53:42 +0200 | [diff] [blame] | 5039 | EXPECT_CALL(*layer2.outputLayer, updateCompositionState(false, true, ui::Transform::ROT_0)); |
Dan Stoza | 6166c31 | 2021-01-15 16:34:05 -0800 | [diff] [blame] | 5040 | EXPECT_CALL(*layer2.outputLayer, |
Leon Scroggins III | 9aa25c2 | 2021-04-15 15:30:19 -0400 | [diff] [blame] | 5041 | writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, z++, |
| 5042 | /*zIsOverridden*/ false, /*isPeekingThrough*/ false)); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 5043 | EXPECT_CALL(*layer2.outputLayer, requiresClientComposition()).WillRepeatedly(Return(false)); |
Snild Dolkow | 9e217d6 | 2020-04-22 15:53:42 +0200 | [diff] [blame] | 5044 | EXPECT_CALL(*layer3.outputLayer, updateCompositionState(false, false, ui::Transform::ROT_0)); |
Dan Stoza | 6166c31 | 2021-01-15 16:34:05 -0800 | [diff] [blame] | 5045 | EXPECT_CALL(*layer3.outputLayer, |
Leon Scroggins III | 9aa25c2 | 2021-04-15 15:30:19 -0400 | [diff] [blame] | 5046 | writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, z++, |
| 5047 | /*zIsOverridden*/ false, /*isPeekingThrough*/ false)); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 5048 | EXPECT_CALL(*layer3.outputLayer, requiresClientComposition()).WillRepeatedly(Return(false)); |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 5049 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 5050 | layer2.layerFEState.backgroundBlurRadius = 10; |
Lucas Dupin | 084a6d4 | 2021-08-26 22:10:29 +0000 | [diff] [blame] | 5051 | layer2.layerFEState.isOpaque = false; |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 5052 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 5053 | injectOutputLayer(layer1); |
| 5054 | injectOutputLayer(layer2); |
| 5055 | injectOutputLayer(layer3); |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 5056 | |
| 5057 | mOutput->editState().isEnabled = true; |
| 5058 | |
| 5059 | CompositionRefreshArgs args; |
| 5060 | args.updatingGeometryThisFrame = false; |
| 5061 | args.devOptForceClientComposition = false; |
Dan Stoza | 269dc4d | 2021-01-15 15:07:43 -0800 | [diff] [blame] | 5062 | mOutput->updateCompositionState(args); |
| 5063 | mOutput->planComposition(); |
| 5064 | mOutput->writeCompositionState(args); |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 5065 | } |
| 5066 | |
Lucas Dupin | c3800b8 | 2020-10-02 16:24:48 -0700 | [diff] [blame] | 5067 | TEST_F(OutputUpdateAndWriteCompositionStateTest, handlesBlurRegionRequests) { |
| 5068 | InjectedLayer layer1; |
| 5069 | InjectedLayer layer2; |
| 5070 | InjectedLayer layer3; |
| 5071 | |
Leon Scroggins III | e2ee040 | 2021-04-02 16:59:37 -0400 | [diff] [blame] | 5072 | uint32_t z = 0; |
Lucas Dupin | c3800b8 | 2020-10-02 16:24:48 -0700 | [diff] [blame] | 5073 | // Layer requesting blur, or below, should request client composition. |
| 5074 | EXPECT_CALL(*layer1.outputLayer, updateCompositionState(false, true, ui::Transform::ROT_0)); |
Dan Stoza | 6166c31 | 2021-01-15 16:34:05 -0800 | [diff] [blame] | 5075 | EXPECT_CALL(*layer1.outputLayer, |
Leon Scroggins III | 9aa25c2 | 2021-04-15 15:30:19 -0400 | [diff] [blame] | 5076 | writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, z++, |
| 5077 | /*zIsOverridden*/ false, /*isPeekingThrough*/ false)); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 5078 | EXPECT_CALL(*layer1.outputLayer, requiresClientComposition()).WillRepeatedly(Return(false)); |
Lucas Dupin | c3800b8 | 2020-10-02 16:24:48 -0700 | [diff] [blame] | 5079 | EXPECT_CALL(*layer2.outputLayer, updateCompositionState(false, true, ui::Transform::ROT_0)); |
Dan Stoza | 6166c31 | 2021-01-15 16:34:05 -0800 | [diff] [blame] | 5080 | EXPECT_CALL(*layer2.outputLayer, |
Leon Scroggins III | 9aa25c2 | 2021-04-15 15:30:19 -0400 | [diff] [blame] | 5081 | writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, z++, |
| 5082 | /*zIsOverridden*/ false, /*isPeekingThrough*/ false)); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 5083 | EXPECT_CALL(*layer2.outputLayer, requiresClientComposition()).WillRepeatedly(Return(false)); |
Lucas Dupin | c3800b8 | 2020-10-02 16:24:48 -0700 | [diff] [blame] | 5084 | EXPECT_CALL(*layer3.outputLayer, updateCompositionState(false, false, ui::Transform::ROT_0)); |
Dan Stoza | 6166c31 | 2021-01-15 16:34:05 -0800 | [diff] [blame] | 5085 | EXPECT_CALL(*layer3.outputLayer, |
Leon Scroggins III | 9aa25c2 | 2021-04-15 15:30:19 -0400 | [diff] [blame] | 5086 | writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, z++, |
| 5087 | /*zIsOverridden*/ false, /*isPeekingThrough*/ false)); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 5088 | EXPECT_CALL(*layer3.outputLayer, requiresClientComposition()).WillRepeatedly(Return(false)); |
Lucas Dupin | c3800b8 | 2020-10-02 16:24:48 -0700 | [diff] [blame] | 5089 | |
| 5090 | BlurRegion region; |
| 5091 | layer2.layerFEState.blurRegions.push_back(region); |
Lucas Dupin | 084a6d4 | 2021-08-26 22:10:29 +0000 | [diff] [blame] | 5092 | layer2.layerFEState.isOpaque = false; |
Lucas Dupin | c3800b8 | 2020-10-02 16:24:48 -0700 | [diff] [blame] | 5093 | |
| 5094 | injectOutputLayer(layer1); |
| 5095 | injectOutputLayer(layer2); |
| 5096 | injectOutputLayer(layer3); |
| 5097 | |
| 5098 | mOutput->editState().isEnabled = true; |
| 5099 | |
| 5100 | CompositionRefreshArgs args; |
| 5101 | args.updatingGeometryThisFrame = false; |
| 5102 | args.devOptForceClientComposition = false; |
Dan Stoza | 269dc4d | 2021-01-15 15:07:43 -0800 | [diff] [blame] | 5103 | mOutput->updateCompositionState(args); |
| 5104 | mOutput->planComposition(); |
| 5105 | mOutput->writeCompositionState(args); |
Lucas Dupin | c3800b8 | 2020-10-02 16:24:48 -0700 | [diff] [blame] | 5106 | } |
| 5107 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 5108 | TEST_F(GenerateClientCompositionRequestsTest, handlesLandscapeModeSplitScreenRequests) { |
| 5109 | // In split-screen landscape mode, the screen is rotated 90 degrees, with |
| 5110 | // one layer on the left covering the left side of the output, and one layer |
| 5111 | // on the right covering that side of the output. |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 5112 | |
| 5113 | const Rect kPortraitFrame(0, 0, 1000, 2000); |
| 5114 | const Rect kPortraitViewport(0, 0, 2000, 1000); |
Lloyd Pique | e8fe474 | 2020-01-21 15:26:18 -0800 | [diff] [blame] | 5115 | const Rect kPortraitDestinationClip(0, 0, 1000, 2000); |
Marin Shalamanov | 68933fb | 2020-09-10 17:58:12 +0200 | [diff] [blame] | 5116 | const ui::Rotation kPortraitOrientation = ui::ROTATION_90; |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 5117 | constexpr ui::Dataspace kOutputDataspace = ui::Dataspace::DISPLAY_P3; |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 5118 | |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 5119 | mOutput.mState.orientedDisplaySpace.setContent(kPortraitFrame); |
| 5120 | mOutput.mState.layerStackSpace.setContent(kPortraitViewport); |
| 5121 | mOutput.mState.displaySpace.setContent(kPortraitDestinationClip); |
Marin Shalamanov | 68933fb | 2020-09-10 17:58:12 +0200 | [diff] [blame] | 5122 | mOutput.mState.transform = ui::Transform{ui::Transform::toRotationFlags(kPortraitOrientation)}; |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 5123 | mOutput.mState.displaySpace.setOrientation(kPortraitOrientation); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 5124 | mOutput.mState.needsFiltering = false; |
| 5125 | mOutput.mState.isSecure = true; |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 5126 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 5127 | Layer leftLayer; |
| 5128 | Layer rightLayer; |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 5129 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 5130 | leftLayer.mOutputLayerState.clearClientTarget = false; |
| 5131 | leftLayer.mOutputLayerState.visibleRegion = Region(Rect(0, 0, 1000, 1000)); |
| 5132 | leftLayer.mLayerFEState.isOpaque = true; |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 5133 | leftLayer.mLayerSettings.source.solidColor = {1.f, 0.f, 0.f}; |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 5134 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 5135 | rightLayer.mOutputLayerState.clearClientTarget = false; |
| 5136 | rightLayer.mOutputLayerState.visibleRegion = Region(Rect(1000, 0, 2000, 1000)); |
| 5137 | rightLayer.mLayerFEState.isOpaque = true; |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 5138 | rightLayer.mLayerSettings.source.solidColor = {0.f, 1.f, 0.f}; |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 5139 | |
| 5140 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(2u)); |
| 5141 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0u)) |
| 5142 | .WillRepeatedly(Return(&leftLayer.mOutputLayer)); |
| 5143 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(1u)) |
| 5144 | .WillRepeatedly(Return(&rightLayer.mOutputLayer)); |
| 5145 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 5146 | compositionengine::LayerFE::ClientCompositionTargetSettings leftLayerSettings{ |
| 5147 | Region(Rect(0, 0, 1000, 1000)), |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 5148 | false, /* needs filtering */ |
| 5149 | true, /* secure */ |
Chavi Weingarten | cbec71d | 2023-12-14 20:53:25 +0000 | [diff] [blame] | 5150 | true, /* isProtected */ |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 5151 | kPortraitViewport, |
| 5152 | kOutputDataspace, |
| 5153 | true /* realContentIsVisible */, |
| 5154 | false /* clearContent */, |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 5155 | compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled, |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 5156 | kLayerWhitePointNits, |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 5157 | false /* treat170mAsSrgb */, |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 5158 | }; |
| 5159 | |
| 5160 | EXPECT_CALL(leftLayer.mOutputLayer, requiresClientComposition()).WillRepeatedly(Return(true)); |
| 5161 | EXPECT_CALL(leftLayer.mOutputLayer, needsFiltering()).WillRepeatedly(Return(false)); |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 5162 | EXPECT_CALL(*leftLayer.mLayerFE, prepareClientComposition(Eq(ByRef(leftLayerSettings)))) |
| 5163 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>(leftLayer.mLayerSettings))); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 5164 | |
| 5165 | compositionengine::LayerFE::ClientCompositionTargetSettings rightLayerSettings{ |
| 5166 | Region(Rect(1000, 0, 2000, 1000)), |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 5167 | false, /* needs filtering */ |
| 5168 | true, /* secure */ |
Chavi Weingarten | cbec71d | 2023-12-14 20:53:25 +0000 | [diff] [blame] | 5169 | true, /* isProtected */ |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 5170 | kPortraitViewport, |
| 5171 | kOutputDataspace, |
| 5172 | true /* realContentIsVisible */, |
| 5173 | false /* clearContent */, |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 5174 | compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled, |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 5175 | kLayerWhitePointNits, |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 5176 | false /* treat170mAsSrgb */, |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 5177 | }; |
| 5178 | |
| 5179 | EXPECT_CALL(rightLayer.mOutputLayer, requiresClientComposition()).WillRepeatedly(Return(true)); |
| 5180 | EXPECT_CALL(rightLayer.mOutputLayer, needsFiltering()).WillRepeatedly(Return(false)); |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 5181 | EXPECT_CALL(*rightLayer.mLayerFE, prepareClientComposition(Eq(ByRef(rightLayerSettings)))) |
| 5182 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>(rightLayer.mLayerSettings))); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 5183 | |
| 5184 | constexpr bool supportsProtectedContent = true; |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 5185 | auto requests = mOutput.generateClientCompositionRequestsHelper(supportsProtectedContent, |
| 5186 | kOutputDataspace); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 5187 | ASSERT_EQ(2u, requests.size()); |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 5188 | EXPECT_EQ(leftLayer.mLayerSettings, requests[0]); |
| 5189 | EXPECT_EQ(rightLayer.mLayerSettings, requests[1]); |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 5190 | } |
| 5191 | |
Vishnu Nair | a483b4a | 2019-12-12 15:07:52 -0800 | [diff] [blame] | 5192 | TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers, |
| 5193 | shadowRegionOnlyVisibleSkipsContentComposition) { |
| 5194 | const Rect kContentWithShadow(40, 40, 70, 90); |
| 5195 | const Rect kContent(50, 50, 60, 80); |
| 5196 | const Region kShadowRegion = Region(kContentWithShadow).subtract(kContent); |
| 5197 | const Region kPartialShadowRegion = Region(kContentWithShadow).subtract(Rect(40, 40, 60, 80)); |
| 5198 | |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 5199 | compositionengine::LayerFE::ClientCompositionTargetSettings layer2Settings{ |
| 5200 | 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] | 5201 | false, /* needs filtering */ |
| 5202 | false, /* secure */ |
| 5203 | false, /* supports protected content */ |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 5204 | kDisplayViewport, |
| 5205 | kDisplayDataspace, |
| 5206 | false /* realContentIsVisible */, |
| 5207 | false /* clearContent */, |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 5208 | compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled, |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 5209 | kLayerWhitePointNits, |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 5210 | false /* treat170mAsSrgb */, |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 5211 | }; |
| 5212 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 5213 | LayerFE::LayerSettings mShadowSettings; |
| 5214 | mShadowSettings.source.solidColor = {0.1f, 0.1f, 0.1f}; |
Vishnu Nair | a483b4a | 2019-12-12 15:07:52 -0800 | [diff] [blame] | 5215 | |
| 5216 | mLayers[2].mOutputLayerState.visibleRegion = kPartialShadowRegion; |
| 5217 | mLayers[2].mOutputLayerState.shadowRegion = kShadowRegion; |
| 5218 | |
| 5219 | EXPECT_CALL(mLayers[0].mOutputLayer, requiresClientComposition()).WillOnce(Return(false)); |
| 5220 | EXPECT_CALL(mLayers[1].mOutputLayer, requiresClientComposition()).WillOnce(Return(false)); |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 5221 | EXPECT_CALL(*mLayers[2].mLayerFE, prepareClientComposition(Eq(ByRef(layer2Settings)))) |
| 5222 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>(mShadowSettings))); |
Vishnu Nair | a483b4a | 2019-12-12 15:07:52 -0800 | [diff] [blame] | 5223 | |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 5224 | auto requests = |
| 5225 | mOutput.generateClientCompositionRequestsHelper(false /* supportsProtectedContent */, |
| 5226 | kDisplayDataspace); |
Vishnu Nair | a483b4a | 2019-12-12 15:07:52 -0800 | [diff] [blame] | 5227 | ASSERT_EQ(1u, requests.size()); |
| 5228 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 5229 | EXPECT_EQ(mShadowSettings, requests[0]); |
Vishnu Nair | a483b4a | 2019-12-12 15:07:52 -0800 | [diff] [blame] | 5230 | } |
| 5231 | |
| 5232 | TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers, |
| 5233 | shadowRegionWithContentVisibleRequestsContentAndShadowComposition) { |
| 5234 | const Rect kContentWithShadow(40, 40, 70, 90); |
| 5235 | const Rect kContent(50, 50, 60, 80); |
| 5236 | const Region kShadowRegion = Region(kContentWithShadow).subtract(kContent); |
| 5237 | const Region kPartialContentWithPartialShadowRegion = |
| 5238 | Region(kContentWithShadow).subtract(Rect(40, 40, 50, 80)); |
| 5239 | |
Vishnu Nair | a483b4a | 2019-12-12 15:07:52 -0800 | [diff] [blame] | 5240 | mLayers[2].mOutputLayerState.visibleRegion = kPartialContentWithPartialShadowRegion; |
| 5241 | mLayers[2].mOutputLayerState.shadowRegion = kShadowRegion; |
| 5242 | |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 5243 | compositionengine::LayerFE::ClientCompositionTargetSettings layer2Settings{ |
| 5244 | 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] | 5245 | false, /* needs filtering */ |
| 5246 | false, /* secure */ |
| 5247 | false, /* supports protected content */ |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 5248 | kDisplayViewport, |
| 5249 | kDisplayDataspace, |
| 5250 | true /* realContentIsVisible */, |
| 5251 | false /* clearContent */, |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 5252 | compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled, |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 5253 | kLayerWhitePointNits, |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 5254 | false /* treat170mAsSrgb */, |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 5255 | }; |
| 5256 | |
Vishnu Nair | a483b4a | 2019-12-12 15:07:52 -0800 | [diff] [blame] | 5257 | EXPECT_CALL(mLayers[0].mOutputLayer, requiresClientComposition()).WillOnce(Return(false)); |
| 5258 | EXPECT_CALL(mLayers[1].mOutputLayer, requiresClientComposition()).WillOnce(Return(false)); |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 5259 | EXPECT_CALL(*mLayers[2].mLayerFE, prepareClientComposition(Eq(ByRef(layer2Settings)))) |
| 5260 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>(mLayers[2].mLayerSettings))); |
Vishnu Nair | a483b4a | 2019-12-12 15:07:52 -0800 | [diff] [blame] | 5261 | |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 5262 | auto requests = |
| 5263 | mOutput.generateClientCompositionRequestsHelper(false /* supportsProtectedContent */, |
| 5264 | kDisplayDataspace); |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 5265 | ASSERT_EQ(1u, requests.size()); |
Vishnu Nair | a483b4a | 2019-12-12 15:07:52 -0800 | [diff] [blame] | 5266 | |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 5267 | EXPECT_EQ(mLayers[2].mLayerSettings, requests[0]); |
Vishnu Nair | a483b4a | 2019-12-12 15:07:52 -0800 | [diff] [blame] | 5268 | } |
| 5269 | |
Leon Scroggins III | 2f60d73 | 2022-09-12 14:42:38 -0400 | [diff] [blame] | 5270 | struct OutputPresentFrameAndReleaseLayersAsyncTest : public ::testing::Test { |
| 5271 | // Piggy-back on OutputPrepareFrameAsyncTest's version to avoid some boilerplate. |
| 5272 | struct OutputPartialMock : public OutputPrepareFrameAsyncTest::OutputPartialMock { |
| 5273 | // Set up the helper functions called by the function under test to use |
| 5274 | // mock implementations. |
| 5275 | MOCK_METHOD0(presentFrameAndReleaseLayers, void()); |
| 5276 | MOCK_METHOD0(presentFrameAndReleaseLayersAsync, ftl::Future<std::monostate>()); |
| 5277 | }; |
| 5278 | OutputPresentFrameAndReleaseLayersAsyncTest() { |
| 5279 | mOutput->setDisplayColorProfileForTest( |
| 5280 | std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile)); |
| 5281 | mOutput->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface)); |
| 5282 | mOutput->setCompositionEnabled(true); |
| 5283 | mRefreshArgs.outputs = {mOutput}; |
| 5284 | } |
| 5285 | |
| 5286 | mock::DisplayColorProfile* mDisplayColorProfile = new NiceMock<mock::DisplayColorProfile>(); |
| 5287 | mock::RenderSurface* mRenderSurface = new NiceMock<mock::RenderSurface>(); |
| 5288 | std::shared_ptr<OutputPartialMock> mOutput{std::make_shared<NiceMock<OutputPartialMock>>()}; |
| 5289 | CompositionRefreshArgs mRefreshArgs; |
| 5290 | }; |
| 5291 | |
| 5292 | TEST_F(OutputPresentFrameAndReleaseLayersAsyncTest, notCalledWhenNotRequested) { |
| 5293 | EXPECT_CALL(*mOutput, presentFrameAndReleaseLayersAsync()).Times(0); |
| 5294 | EXPECT_CALL(*mOutput, presentFrameAndReleaseLayers()).Times(1); |
| 5295 | |
| 5296 | mOutput->present(mRefreshArgs); |
| 5297 | } |
| 5298 | |
| 5299 | TEST_F(OutputPresentFrameAndReleaseLayersAsyncTest, calledWhenRequested) { |
| 5300 | EXPECT_CALL(*mOutput, presentFrameAndReleaseLayersAsync()) |
| 5301 | .WillOnce(Return(ftl::yield<std::monostate>({}))); |
| 5302 | EXPECT_CALL(*mOutput, presentFrameAndReleaseLayers()).Times(0); |
| 5303 | |
| 5304 | mOutput->offloadPresentNextFrame(); |
| 5305 | mOutput->present(mRefreshArgs); |
| 5306 | } |
| 5307 | |
| 5308 | TEST_F(OutputPresentFrameAndReleaseLayersAsyncTest, calledForOneFrame) { |
| 5309 | ::testing::InSequence inseq; |
| 5310 | EXPECT_CALL(*mOutput, presentFrameAndReleaseLayersAsync()) |
| 5311 | .WillOnce(Return(ftl::yield<std::monostate>({}))); |
| 5312 | EXPECT_CALL(*mOutput, presentFrameAndReleaseLayers()).Times(1); |
| 5313 | |
| 5314 | mOutput->offloadPresentNextFrame(); |
| 5315 | mOutput->present(mRefreshArgs); |
| 5316 | mOutput->present(mRefreshArgs); |
| 5317 | } |
| 5318 | |
Eason Chiu | 4509966 | 2023-10-23 08:55:48 +0800 | [diff] [blame] | 5319 | /* |
| 5320 | * Output::updateProtectedContentState() |
| 5321 | */ |
| 5322 | |
| 5323 | struct OutputUpdateProtectedContentStateTest : public testing::Test { |
| 5324 | struct OutputPartialMock : public OutputPartialMockBase { |
| 5325 | // Sets up the helper functions called by the function under test to use |
| 5326 | // mock implementations. |
| 5327 | MOCK_CONST_METHOD0(getCompositionEngine, const CompositionEngine&()); |
| 5328 | }; |
| 5329 | |
| 5330 | OutputUpdateProtectedContentStateTest() { |
| 5331 | mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface)); |
| 5332 | EXPECT_CALL(mOutput, getCompositionEngine()).WillRepeatedly(ReturnRef(mCompositionEngine)); |
| 5333 | EXPECT_CALL(mCompositionEngine, getRenderEngine()).WillRepeatedly(ReturnRef(mRenderEngine)); |
| 5334 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(2u)); |
| 5335 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0)) |
| 5336 | .WillRepeatedly(Return(&mLayer1.mOutputLayer)); |
| 5337 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(1)) |
| 5338 | .WillRepeatedly(Return(&mLayer2.mOutputLayer)); |
| 5339 | } |
| 5340 | |
| 5341 | struct Layer { |
| 5342 | Layer() { |
| 5343 | EXPECT_CALL(*mLayerFE, getCompositionState()).WillRepeatedly(Return(&mLayerFEState)); |
| 5344 | EXPECT_CALL(mOutputLayer, getLayerFE()).WillRepeatedly(ReturnRef(*mLayerFE)); |
| 5345 | } |
| 5346 | |
| 5347 | StrictMock<mock::OutputLayer> mOutputLayer; |
| 5348 | sp<StrictMock<mock::LayerFE>> mLayerFE = sp<StrictMock<mock::LayerFE>>::make(); |
| 5349 | LayerFECompositionState mLayerFEState; |
| 5350 | }; |
| 5351 | |
| 5352 | mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>(); |
| 5353 | StrictMock<OutputPartialMock> mOutput; |
| 5354 | StrictMock<mock::CompositionEngine> mCompositionEngine; |
| 5355 | StrictMock<renderengine::mock::RenderEngine> mRenderEngine; |
| 5356 | Layer mLayer1; |
| 5357 | Layer mLayer2; |
| 5358 | }; |
| 5359 | |
| 5360 | TEST_F(OutputUpdateProtectedContentStateTest, ifProtectedContentLayerComposeByHWC) { |
| 5361 | SET_FLAG_FOR_TEST(flags::protected_if_client, true); |
| 5362 | if (FlagManager::getInstance().display_protected()) { |
| 5363 | mOutput.mState.isProtected = true; |
| 5364 | } else { |
| 5365 | mOutput.mState.isSecure = true; |
| 5366 | } |
| 5367 | mLayer1.mLayerFEState.hasProtectedContent = false; |
| 5368 | mLayer2.mLayerFEState.hasProtectedContent = true; |
| 5369 | EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(true)); |
| 5370 | EXPECT_CALL(*mRenderSurface, isProtected).WillOnce(Return(false)); |
| 5371 | EXPECT_CALL(mLayer1.mOutputLayer, requiresClientComposition()).WillRepeatedly(Return(true)); |
| 5372 | EXPECT_CALL(mLayer2.mOutputLayer, requiresClientComposition()).WillRepeatedly(Return(false)); |
| 5373 | mOutput.updateProtectedContentState(); |
| 5374 | } |
| 5375 | |
| 5376 | TEST_F(OutputUpdateProtectedContentStateTest, ifProtectedContentLayerComposeByClient) { |
| 5377 | SET_FLAG_FOR_TEST(flags::protected_if_client, true); |
| 5378 | if (FlagManager::getInstance().display_protected()) { |
| 5379 | mOutput.mState.isProtected = true; |
| 5380 | } else { |
| 5381 | mOutput.mState.isSecure = true; |
| 5382 | } |
| 5383 | mLayer1.mLayerFEState.hasProtectedContent = false; |
| 5384 | mLayer2.mLayerFEState.hasProtectedContent = true; |
| 5385 | EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(true)); |
| 5386 | EXPECT_CALL(*mRenderSurface, isProtected).WillOnce(Return(false)); |
| 5387 | EXPECT_CALL(*mRenderSurface, setProtected(true)); |
| 5388 | EXPECT_CALL(mLayer1.mOutputLayer, requiresClientComposition()).WillRepeatedly(Return(true)); |
| 5389 | EXPECT_CALL(mLayer2.mOutputLayer, requiresClientComposition()).WillRepeatedly(Return(true)); |
| 5390 | mOutput.updateProtectedContentState(); |
| 5391 | } |
| 5392 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 5393 | } // namespace |
| 5394 | } // namespace android::compositionengine |