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 | |
Leon Scroggins III | e2ee040 | 2021-04-02 16:59:37 -0400 | [diff] [blame] | 37 | #include <cstdint> |
Leon Scroggins III | 2f60d73 | 2022-09-12 14:42:38 -0400 | [diff] [blame] | 38 | #include <variant> |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 39 | |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 40 | #include <common/FlagManager.h> |
| 41 | #include <common/test/FlagUtils.h> |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 42 | #include "CallOrderStateMachineHelper.h" |
Lloyd Pique | 07178e3 | 2019-11-19 19:15:26 -0800 | [diff] [blame] | 43 | #include "MockHWC2.h" |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 44 | #include "RegionMatcher.h" |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 45 | |
| 46 | namespace android::compositionengine { |
| 47 | namespace { |
| 48 | |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 49 | using namespace com::android::graphics::surfaceflinger; |
| 50 | |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 51 | using testing::_; |
Lloyd Pique | 03561a6 | 2019-11-19 18:34:52 -0800 | [diff] [blame] | 52 | using testing::ByMove; |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 53 | using testing::ByRef; |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 54 | using testing::DoAll; |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 55 | using testing::ElementsAre; |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 56 | using testing::ElementsAreArray; |
Lloyd Pique | 07178e3 | 2019-11-19 19:15:26 -0800 | [diff] [blame] | 57 | using testing::Eq; |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 58 | using testing::InSequence; |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 59 | using testing::Invoke; |
| 60 | using testing::IsEmpty; |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 61 | using testing::Mock; |
Leon Scroggins III | 2f60d73 | 2022-09-12 14:42:38 -0400 | [diff] [blame] | 62 | using testing::NiceMock; |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 63 | using testing::Pointee; |
Lloyd Pique | 07178e3 | 2019-11-19 19:15:26 -0800 | [diff] [blame] | 64 | using testing::Property; |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 65 | using testing::Ref; |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 66 | using testing::Return; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 67 | using testing::ReturnRef; |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 68 | using testing::SetArgPointee; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 69 | using testing::StrictMock; |
| 70 | |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 71 | constexpr auto TR_IDENT = 0u; |
| 72 | constexpr auto TR_ROT_90 = HAL_TRANSFORM_ROT_90; |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 73 | constexpr auto MAX_CLIENT_COMPOSITION_CACHE_SIZE = 3; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 74 | |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 75 | const mat4 kIdentity; |
Lloyd Pique | 0a45623 | 2020-01-16 17:51:13 -0800 | [diff] [blame] | 76 | const mat4 kNonIdentityHalf = mat4() * 0.5f; |
| 77 | const mat4 kNonIdentityQuarter = mat4() * 0.25f; |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 78 | |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 79 | constexpr OutputColorSetting kVendorSpecifiedOutputColorSetting = |
| 80 | static_cast<OutputColorSetting>(0x100); |
| 81 | |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 82 | using CompositionStrategyPredictionState = android::compositionengine::impl:: |
| 83 | OutputCompositionState::CompositionStrategyPredictionState; |
| 84 | |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 85 | struct OutputPartialMockBase : public impl::Output { |
| 86 | // compositionengine::Output overrides |
| 87 | const OutputCompositionState& getState() const override { return mState; } |
| 88 | OutputCompositionState& editState() override { return mState; } |
| 89 | |
| 90 | // Use mocks for all the remaining virtual functions |
| 91 | // not implemented by the base implementation class. |
| 92 | MOCK_CONST_METHOD0(getOutputLayerCount, size_t()); |
| 93 | MOCK_CONST_METHOD1(getOutputLayerOrderedByZByIndex, compositionengine::OutputLayer*(size_t)); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 94 | MOCK_METHOD2(ensureOutputLayer, |
| 95 | compositionengine::OutputLayer*(std::optional<size_t>, const sp<LayerFE>&)); |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 96 | MOCK_METHOD0(finalizePendingOutputLayers, void()); |
| 97 | MOCK_METHOD0(clearOutputLayers, void()); |
| 98 | MOCK_CONST_METHOD1(dumpState, void(std::string&)); |
| 99 | MOCK_CONST_METHOD0(getCompositionEngine, const CompositionEngine&()); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 100 | MOCK_METHOD1(injectOutputLayerForTest, compositionengine::OutputLayer*(const sp<LayerFE>&)); |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 101 | MOCK_METHOD1(injectOutputLayerForTest, void(std::unique_ptr<OutputLayer>)); |
| 102 | |
| 103 | impl::OutputCompositionState mState; |
| 104 | }; |
| 105 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 106 | struct InjectedLayer { |
| 107 | InjectedLayer() { |
| 108 | EXPECT_CALL(*outputLayer, getLayerFE()).WillRepeatedly(ReturnRef(*layerFE.get())); |
| 109 | EXPECT_CALL(*outputLayer, getState()).WillRepeatedly(ReturnRef(outputLayerState)); |
| 110 | EXPECT_CALL(*outputLayer, editState()).WillRepeatedly(ReturnRef(outputLayerState)); |
| 111 | |
| 112 | EXPECT_CALL(*layerFE, getCompositionState()).WillRepeatedly(Return(&layerFEState)); |
Dan Stoza | 269dc4d | 2021-01-15 15:07:43 -0800 | [diff] [blame] | 113 | EXPECT_CALL(*layerFE, getSequence()).WillRepeatedly(Return(0)); |
| 114 | EXPECT_CALL(*layerFE, getDebugName()).WillRepeatedly(Return("InjectedLayer")); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | mock::OutputLayer* outputLayer = {new StrictMock<mock::OutputLayer>}; |
Ady Abraham | e0eafa8 | 2022-02-02 19:30:47 -0800 | [diff] [blame] | 118 | sp<StrictMock<mock::LayerFE>> layerFE = sp<StrictMock<mock::LayerFE>>::make(); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 119 | LayerFECompositionState layerFEState; |
| 120 | impl::OutputLayerCompositionState outputLayerState; |
| 121 | }; |
| 122 | |
| 123 | struct NonInjectedLayer { |
| 124 | NonInjectedLayer() { |
| 125 | EXPECT_CALL(outputLayer, getLayerFE()).WillRepeatedly(ReturnRef(*layerFE.get())); |
| 126 | EXPECT_CALL(outputLayer, getState()).WillRepeatedly(ReturnRef(outputLayerState)); |
| 127 | EXPECT_CALL(outputLayer, editState()).WillRepeatedly(ReturnRef(outputLayerState)); |
| 128 | |
| 129 | EXPECT_CALL(*layerFE, getCompositionState()).WillRepeatedly(Return(&layerFEState)); |
Dan Stoza | 269dc4d | 2021-01-15 15:07:43 -0800 | [diff] [blame] | 130 | EXPECT_CALL(*layerFE, getSequence()).WillRepeatedly(Return(0)); |
| 131 | EXPECT_CALL(*layerFE, getDebugName()).WillRepeatedly(Return("NonInjectedLayer")); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | mock::OutputLayer outputLayer; |
Ady Abraham | e0eafa8 | 2022-02-02 19:30:47 -0800 | [diff] [blame] | 135 | sp<StrictMock<mock::LayerFE>> layerFE = sp<StrictMock<mock::LayerFE>>::make(); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 136 | LayerFECompositionState layerFEState; |
| 137 | impl::OutputLayerCompositionState outputLayerState; |
| 138 | }; |
| 139 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 140 | struct OutputTest : public testing::Test { |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 141 | class Output : public impl::Output { |
| 142 | public: |
| 143 | using impl::Output::injectOutputLayerForTest; |
| 144 | virtual void injectOutputLayerForTest(std::unique_ptr<compositionengine::OutputLayer>) = 0; |
| 145 | }; |
| 146 | |
| 147 | static std::shared_ptr<Output> createOutput( |
| 148 | const compositionengine::CompositionEngine& compositionEngine) { |
| 149 | return impl::createOutputTemplated<Output>(compositionEngine); |
| 150 | } |
| 151 | |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 152 | OutputTest() { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 153 | mOutput->setDisplayColorProfileForTest( |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 154 | std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile)); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 155 | mOutput->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface)); |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 156 | |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 157 | mOutput->editState().displaySpace.setBounds( |
| 158 | ui::Size(kDefaultDisplaySize.getWidth(), kDefaultDisplaySize.getHeight())); |
Alec Mouri | df6201b | 2021-06-01 16:20:42 -0700 | [diff] [blame] | 159 | EXPECT_CALL(mCompositionEngine, getRenderEngine()).WillRepeatedly(ReturnRef(mRenderEngine)); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 160 | } |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 161 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 162 | void injectOutputLayer(InjectedLayer& layer) { |
| 163 | mOutput->injectOutputLayerForTest(std::unique_ptr<OutputLayer>(layer.outputLayer)); |
| 164 | } |
| 165 | |
| 166 | void injectNullOutputLayer() { |
| 167 | mOutput->injectOutputLayerForTest(std::unique_ptr<OutputLayer>(nullptr)); |
| 168 | } |
| 169 | |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 170 | static const Rect kDefaultDisplaySize; |
| 171 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 172 | StrictMock<mock::CompositionEngine> mCompositionEngine; |
Alec Mouri | df6201b | 2021-06-01 16:20:42 -0700 | [diff] [blame] | 173 | StrictMock<renderengine::mock::RenderEngine> mRenderEngine; |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 174 | mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>(); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 175 | mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>(); |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 176 | std::shared_ptr<Output> mOutput = createOutput(mCompositionEngine); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 177 | }; |
| 178 | |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 179 | const Rect OutputTest::kDefaultDisplaySize{100, 200}; |
| 180 | |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 181 | using ColorProfile = compositionengine::Output::ColorProfile; |
| 182 | |
| 183 | void dumpColorProfile(ColorProfile profile, std::string& result, const char* name) { |
Alec Mouri | 88790f3 | 2023-07-21 01:25:14 +0000 | [diff] [blame] | 184 | android::base::StringAppendF(&result, "%s (%s[%d] %s[%d] %s[%d]) ", name, |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 185 | toString(profile.mode).c_str(), profile.mode, |
| 186 | toString(profile.dataspace).c_str(), profile.dataspace, |
Alec Mouri | 88790f3 | 2023-07-21 01:25:14 +0000 | [diff] [blame] | 187 | toString(profile.renderIntent).c_str(), profile.renderIntent); |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | // Checks for a ColorProfile match |
| 191 | MATCHER_P(ColorProfileEq, expected, "") { |
| 192 | std::string buf; |
| 193 | buf.append("ColorProfiles are not equal\n"); |
| 194 | dumpColorProfile(expected, buf, "expected value"); |
| 195 | dumpColorProfile(arg, buf, "actual value"); |
| 196 | *result_listener << buf; |
| 197 | |
| 198 | return (expected.mode == arg.mode) && (expected.dataspace == arg.dataspace) && |
Alec Mouri | 88790f3 | 2023-07-21 01:25:14 +0000 | [diff] [blame] | 199 | (expected.renderIntent == arg.renderIntent); |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 200 | } |
| 201 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 202 | /* |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 203 | * Basic construction |
| 204 | */ |
| 205 | |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 206 | TEST_F(OutputTest, canInstantiateOutput) { |
| 207 | // The validation check checks each required component. |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 208 | EXPECT_CALL(*mDisplayColorProfile, isValid()).WillOnce(Return(true)); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 209 | EXPECT_CALL(*mRenderSurface, isValid()).WillOnce(Return(true)); |
| 210 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 211 | EXPECT_TRUE(mOutput->isValid()); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 212 | |
| 213 | // If we take away the required components, it is no longer valid. |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 214 | mOutput->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>()); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 215 | |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 216 | EXPECT_CALL(*mDisplayColorProfile, isValid()).WillOnce(Return(true)); |
| 217 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 218 | EXPECT_FALSE(mOutput->isValid()); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 219 | } |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 220 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 221 | /* |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 222 | * Output::setCompositionEnabled() |
| 223 | */ |
| 224 | |
| 225 | TEST_F(OutputTest, setCompositionEnabledDoesNothingIfAlreadyEnabled) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 226 | mOutput->editState().isEnabled = true; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 227 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 228 | mOutput->setCompositionEnabled(true); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 229 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 230 | EXPECT_TRUE(mOutput->getState().isEnabled); |
| 231 | EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region())); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | TEST_F(OutputTest, setCompositionEnabledSetsEnabledAndDirtiesEntireOutput) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 235 | mOutput->editState().isEnabled = false; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 236 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 237 | mOutput->setCompositionEnabled(true); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 238 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 239 | EXPECT_TRUE(mOutput->getState().isEnabled); |
| 240 | EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize))); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | TEST_F(OutputTest, setCompositionEnabledSetsDisabledAndDirtiesEntireOutput) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 244 | mOutput->editState().isEnabled = true; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 245 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 246 | mOutput->setCompositionEnabled(false); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 247 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 248 | EXPECT_FALSE(mOutput->getState().isEnabled); |
| 249 | EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize))); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 250 | } |
| 251 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 252 | /* |
Alec Mouri | dda07d9 | 2022-04-25 22:39:25 +0000 | [diff] [blame] | 253 | * Output::setTreat170mAsSrgb() |
| 254 | */ |
| 255 | |
| 256 | TEST_F(OutputTest, setTreat170mAsSrgb) { |
| 257 | EXPECT_FALSE(mOutput->getState().treat170mAsSrgb); |
| 258 | |
| 259 | mOutput->setTreat170mAsSrgb(true); |
| 260 | EXPECT_TRUE(mOutput->getState().treat170mAsSrgb); |
| 261 | |
| 262 | mOutput->setTreat170mAsSrgb(false); |
| 263 | EXPECT_FALSE(mOutput->getState().treat170mAsSrgb); |
| 264 | } |
| 265 | |
| 266 | /* |
Alec Mouri | 023c188 | 2021-05-08 16:36:33 -0700 | [diff] [blame] | 267 | * Output::setLayerCachingEnabled() |
| 268 | */ |
| 269 | |
| 270 | TEST_F(OutputTest, setLayerCachingEnabled_enablesCaching) { |
| 271 | const auto kSize = ui::Size(1, 1); |
| 272 | EXPECT_CALL(*mRenderSurface, getSize()).WillRepeatedly(ReturnRef(kSize)); |
| 273 | mOutput->setLayerCachingEnabled(false); |
| 274 | mOutput->setLayerCachingEnabled(true); |
| 275 | |
| 276 | EXPECT_TRUE(mOutput->plannerEnabled()); |
| 277 | } |
| 278 | |
| 279 | TEST_F(OutputTest, setLayerCachingEnabled_disablesCaching) { |
| 280 | const auto kSize = ui::Size(1, 1); |
| 281 | EXPECT_CALL(*mRenderSurface, getSize()).WillRepeatedly(ReturnRef(kSize)); |
| 282 | mOutput->setLayerCachingEnabled(true); |
| 283 | mOutput->setLayerCachingEnabled(false); |
| 284 | |
| 285 | EXPECT_FALSE(mOutput->plannerEnabled()); |
| 286 | } |
| 287 | |
Alec Mouri | c773472b | 2021-05-19 14:29:05 -0700 | [diff] [blame] | 288 | TEST_F(OutputTest, setLayerCachingEnabled_disablesCachingAndResetsOverrideInfo) { |
| 289 | renderengine::mock::RenderEngine renderEngine; |
| 290 | const auto kSize = ui::Size(1, 1); |
| 291 | EXPECT_CALL(*mRenderSurface, getSize()).WillRepeatedly(ReturnRef(kSize)); |
| 292 | mOutput->setLayerCachingEnabled(true); |
| 293 | |
| 294 | // Inject some layers |
| 295 | InjectedLayer layer; |
| 296 | layer.outputLayerState.overrideInfo.buffer = std::make_shared< |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 297 | renderengine::impl:: |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 298 | ExternalTexture>(sp<GraphicBuffer>::make(), renderEngine, |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 299 | renderengine::impl::ExternalTexture::Usage::READABLE | |
| 300 | renderengine::impl::ExternalTexture::Usage::WRITEABLE); |
Alec Mouri | c773472b | 2021-05-19 14:29:05 -0700 | [diff] [blame] | 301 | injectOutputLayer(layer); |
| 302 | // inject a null layer to check for null exceptions |
| 303 | injectNullOutputLayer(); |
| 304 | |
| 305 | EXPECT_NE(nullptr, layer.outputLayerState.overrideInfo.buffer); |
| 306 | mOutput->setLayerCachingEnabled(false); |
| 307 | EXPECT_EQ(nullptr, layer.outputLayerState.overrideInfo.buffer); |
| 308 | } |
| 309 | |
Alec Mouri | 023c188 | 2021-05-08 16:36:33 -0700 | [diff] [blame] | 310 | /* |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 311 | * Output::setProjection() |
| 312 | */ |
| 313 | |
Marin Shalamanov | 209ae61 | 2020-10-01 00:17:39 +0200 | [diff] [blame] | 314 | TEST_F(OutputTest, setProjectionWorks) { |
| 315 | const Rect displayRect{0, 0, 1000, 2000}; |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 316 | mOutput->editState().displaySpace.setBounds( |
| 317 | ui::Size(displayRect.getWidth(), displayRect.getHeight())); |
| 318 | mOutput->editState().framebufferSpace.setBounds( |
| 319 | ui::Size(displayRect.getWidth(), displayRect.getHeight())); |
Marin Shalamanov | 209ae61 | 2020-10-01 00:17:39 +0200 | [diff] [blame] | 320 | |
Marin Shalamanov | 68933fb | 2020-09-10 17:58:12 +0200 | [diff] [blame] | 321 | const ui::Rotation orientation = ui::ROTATION_90; |
Marin Shalamanov | 209ae61 | 2020-10-01 00:17:39 +0200 | [diff] [blame] | 322 | const Rect frame{50, 60, 100, 100}; |
| 323 | const Rect viewport{10, 20, 30, 40}; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 324 | |
Marin Shalamanov | 68933fb | 2020-09-10 17:58:12 +0200 | [diff] [blame] | 325 | mOutput->setProjection(orientation, viewport, frame); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 326 | |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 327 | EXPECT_EQ(orientation, mOutput->getState().displaySpace.getOrientation()); |
| 328 | EXPECT_EQ(frame, mOutput->getState().orientedDisplaySpace.getContent()); |
| 329 | EXPECT_EQ(viewport, mOutput->getState().layerStackSpace.getContent()); |
Marin Shalamanov | 209ae61 | 2020-10-01 00:17:39 +0200 | [diff] [blame] | 330 | |
| 331 | const auto state = mOutput->getState(); |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 332 | EXPECT_EQ(ui::ROTATION_0, state.layerStackSpace.getOrientation()); |
| 333 | EXPECT_EQ(viewport, state.layerStackSpace.getContent()); |
| 334 | EXPECT_EQ(Rect(0, 0, 20, 20), state.layerStackSpace.getBoundsAsRect()); |
Marin Shalamanov | 209ae61 | 2020-10-01 00:17:39 +0200 | [diff] [blame] | 335 | |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 336 | EXPECT_EQ(ui::ROTATION_0, state.orientedDisplaySpace.getOrientation()); |
| 337 | EXPECT_EQ(frame, state.orientedDisplaySpace.getContent()); |
| 338 | EXPECT_EQ(Rect(0, 0, 2000, 1000), state.orientedDisplaySpace.getBoundsAsRect()); |
Marin Shalamanov | 209ae61 | 2020-10-01 00:17:39 +0200 | [diff] [blame] | 339 | |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 340 | EXPECT_EQ(displayRect, state.displaySpace.getBoundsAsRect()); |
| 341 | EXPECT_EQ(Rect(900, 50, 940, 100), state.displaySpace.getContent()); |
| 342 | EXPECT_EQ(orientation, state.displaySpace.getOrientation()); |
Marin Shalamanov | 209ae61 | 2020-10-01 00:17:39 +0200 | [diff] [blame] | 343 | |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 344 | EXPECT_EQ(displayRect, state.framebufferSpace.getBoundsAsRect()); |
| 345 | EXPECT_EQ(Rect(900, 50, 940, 100), state.framebufferSpace.getContent()); |
| 346 | EXPECT_EQ(orientation, state.framebufferSpace.getOrientation()); |
Marin Shalamanov | 209ae61 | 2020-10-01 00:17:39 +0200 | [diff] [blame] | 347 | |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 348 | EXPECT_EQ(state.displaySpace.getContent(), |
| 349 | state.transform.transform(state.layerStackSpace.getContent())); |
Garfield Tan | 54edd91 | 2020-10-21 16:31:41 -0700 | [diff] [blame] | 350 | |
| 351 | EXPECT_EQ(ui::Transform::ROT_90, mOutput->getTransformHint()); |
Marin Shalamanov | 209ae61 | 2020-10-01 00:17:39 +0200 | [diff] [blame] | 352 | } |
| 353 | |
| 354 | TEST_F(OutputTest, setProjectionWithSmallFramebufferWorks) { |
| 355 | const Rect displayRect{0, 0, 1000, 2000}; |
| 356 | const Rect framebufferRect{0, 0, 500, 1000}; |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 357 | mOutput->editState().displaySpace.setBounds( |
| 358 | ui::Size(displayRect.getWidth(), displayRect.getHeight())); |
| 359 | mOutput->editState().framebufferSpace.setBounds( |
| 360 | ui::Size(framebufferRect.getWidth(), framebufferRect.getHeight())); |
Marin Shalamanov | 209ae61 | 2020-10-01 00:17:39 +0200 | [diff] [blame] | 361 | |
| 362 | const ui::Rotation orientation = ui::ROTATION_90; |
| 363 | const Rect frame{50, 60, 100, 100}; |
| 364 | const Rect viewport{10, 20, 30, 40}; |
| 365 | |
| 366 | mOutput->setProjection(orientation, viewport, frame); |
| 367 | |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 368 | EXPECT_EQ(orientation, mOutput->getState().displaySpace.getOrientation()); |
| 369 | EXPECT_EQ(frame, mOutput->getState().orientedDisplaySpace.getContent()); |
| 370 | EXPECT_EQ(viewport, mOutput->getState().layerStackSpace.getContent()); |
Marin Shalamanov | 209ae61 | 2020-10-01 00:17:39 +0200 | [diff] [blame] | 371 | |
| 372 | const auto state = mOutput->getState(); |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 373 | EXPECT_EQ(ui::ROTATION_0, state.layerStackSpace.getOrientation()); |
| 374 | EXPECT_EQ(viewport, state.layerStackSpace.getContent()); |
| 375 | EXPECT_EQ(Rect(0, 0, 20, 20), state.layerStackSpace.getBoundsAsRect()); |
Marin Shalamanov | 209ae61 | 2020-10-01 00:17:39 +0200 | [diff] [blame] | 376 | |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 377 | EXPECT_EQ(ui::ROTATION_0, state.orientedDisplaySpace.getOrientation()); |
| 378 | EXPECT_EQ(frame, state.orientedDisplaySpace.getContent()); |
| 379 | EXPECT_EQ(Rect(0, 0, 2000, 1000), state.orientedDisplaySpace.getBoundsAsRect()); |
Marin Shalamanov | 209ae61 | 2020-10-01 00:17:39 +0200 | [diff] [blame] | 380 | |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 381 | EXPECT_EQ(displayRect, state.displaySpace.getBoundsAsRect()); |
| 382 | EXPECT_EQ(Rect(900, 50, 940, 100), state.displaySpace.getContent()); |
| 383 | EXPECT_EQ(orientation, state.displaySpace.getOrientation()); |
Marin Shalamanov | 209ae61 | 2020-10-01 00:17:39 +0200 | [diff] [blame] | 384 | |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 385 | EXPECT_EQ(framebufferRect, state.framebufferSpace.getBoundsAsRect()); |
| 386 | EXPECT_EQ(Rect(450, 25, 470, 50), state.framebufferSpace.getContent()); |
| 387 | EXPECT_EQ(orientation, state.framebufferSpace.getOrientation()); |
Marin Shalamanov | 209ae61 | 2020-10-01 00:17:39 +0200 | [diff] [blame] | 388 | |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 389 | EXPECT_EQ(state.displaySpace.getContent(), |
| 390 | state.transform.transform(state.layerStackSpace.getContent())); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 391 | } |
| 392 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 393 | /* |
Marin Shalamanov | b15d227 | 2020-09-17 21:41:52 +0200 | [diff] [blame] | 394 | * Output::setDisplaySize() |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 395 | */ |
| 396 | |
Marin Shalamanov | b15d227 | 2020-09-17 21:41:52 +0200 | [diff] [blame] | 397 | TEST_F(OutputTest, setDisplaySpaceSizeUpdatesOutputStateAndDirtiesEntireOutput) { |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 398 | mOutput->editState().layerStackSpace.setContent(Rect(0, 0, 2000, 1000)); |
| 399 | mOutput->editState().layerStackSpace.setBounds(ui::Size(2000, 1000)); |
| 400 | mOutput->editState().orientedDisplaySpace.setContent(Rect(0, 0, 1800, 900)); |
| 401 | mOutput->editState().orientedDisplaySpace.setBounds(ui::Size(2000, 1000)); |
| 402 | mOutput->editState().framebufferSpace.setContent(Rect(0, 0, 900, 1800)); |
| 403 | mOutput->editState().framebufferSpace.setBounds(ui::Size(1000, 2000)); |
| 404 | mOutput->editState().framebufferSpace.setOrientation(ui::ROTATION_90); |
| 405 | mOutput->editState().displaySpace.setContent(Rect(0, 0, 900, 1800)); |
| 406 | mOutput->editState().displaySpace.setBounds(ui::Size(1000, 2000)); |
| 407 | mOutput->editState().displaySpace.setOrientation(ui::ROTATION_90); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 408 | |
Marin Shalamanov | b15d227 | 2020-09-17 21:41:52 +0200 | [diff] [blame] | 409 | const ui::Size newDisplaySize{500, 1000}; |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 410 | |
Marin Shalamanov | b15d227 | 2020-09-17 21:41:52 +0200 | [diff] [blame] | 411 | EXPECT_CALL(*mRenderSurface, setDisplaySize(newDisplaySize)).Times(1); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 412 | |
Marin Shalamanov | b15d227 | 2020-09-17 21:41:52 +0200 | [diff] [blame] | 413 | mOutput->setDisplaySize(newDisplaySize); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 414 | |
Marin Shalamanov | b15d227 | 2020-09-17 21:41:52 +0200 | [diff] [blame] | 415 | const auto state = mOutput->getState(); |
| 416 | |
| 417 | const Rect displayRect(newDisplaySize); |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 418 | EXPECT_EQ(ui::ROTATION_0, state.layerStackSpace.getOrientation()); |
| 419 | EXPECT_EQ(Rect(0, 0, 2000, 1000), state.layerStackSpace.getContent()); |
| 420 | EXPECT_EQ(Rect(0, 0, 2000, 1000), state.layerStackSpace.getBoundsAsRect()); |
Marin Shalamanov | 209ae61 | 2020-10-01 00:17:39 +0200 | [diff] [blame] | 421 | |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 422 | EXPECT_EQ(ui::ROTATION_0, state.orientedDisplaySpace.getOrientation()); |
| 423 | EXPECT_EQ(Rect(0, 0, 1000, 500), state.orientedDisplaySpace.getBoundsAsRect()); |
Marin Shalamanov | 209ae61 | 2020-10-01 00:17:39 +0200 | [diff] [blame] | 424 | |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 425 | EXPECT_EQ(displayRect, state.displaySpace.getBoundsAsRect()); |
| 426 | EXPECT_EQ(ui::ROTATION_90, state.displaySpace.getOrientation()); |
Marin Shalamanov | 209ae61 | 2020-10-01 00:17:39 +0200 | [diff] [blame] | 427 | |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 428 | EXPECT_EQ(displayRect, state.framebufferSpace.getBoundsAsRect()); |
| 429 | EXPECT_EQ(ui::ROTATION_90, state.framebufferSpace.getOrientation()); |
Marin Shalamanov | b15d227 | 2020-09-17 21:41:52 +0200 | [diff] [blame] | 430 | |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 431 | EXPECT_EQ(state.displaySpace.getContent(), |
| 432 | state.transform.transform(state.layerStackSpace.getContent())); |
Marin Shalamanov | b15d227 | 2020-09-17 21:41:52 +0200 | [diff] [blame] | 433 | |
| 434 | EXPECT_THAT(state.dirtyRegion, RegionEq(Region(displayRect))); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 435 | } |
| 436 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 437 | /* |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 438 | * Output::setLayerFilter() |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 439 | */ |
| 440 | |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 441 | TEST_F(OutputTest, setLayerFilterSetsFilterAndDirtiesEntireOutput) { |
| 442 | constexpr ui::LayerFilter kFilter{ui::LayerStack{123u}, true}; |
| 443 | mOutput->setLayerFilter(kFilter); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 444 | |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 445 | const auto& state = mOutput->getState(); |
| 446 | EXPECT_EQ(kFilter.layerStack, state.layerFilter.layerStack); |
| 447 | EXPECT_TRUE(state.layerFilter.toInternalDisplay); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 448 | |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 449 | EXPECT_THAT(state.dirtyRegion, RegionEq(Region(kDefaultDisplaySize))); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 450 | } |
| 451 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 452 | /* |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 453 | * Output::setColorTransform |
| 454 | */ |
| 455 | |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 456 | TEST_F(OutputTest, setColorTransformWithNoChangeFlaggedSkipsUpdates) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 457 | mOutput->editState().colorTransformMatrix = kIdentity; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 458 | |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 459 | // If no colorTransformMatrix is set the update should be skipped. |
| 460 | CompositionRefreshArgs refreshArgs; |
| 461 | refreshArgs.colorTransformMatrix = std::nullopt; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 462 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 463 | mOutput->setColorTransform(refreshArgs); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 464 | |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 465 | // The internal state should be unchanged |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 466 | EXPECT_EQ(kIdentity, mOutput->getState().colorTransformMatrix); |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 467 | |
| 468 | // No dirty region should be set |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 469 | EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region())); |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 470 | } |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 471 | |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 472 | TEST_F(OutputTest, setColorTransformWithNoActualChangeSkipsUpdates) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 473 | mOutput->editState().colorTransformMatrix = kIdentity; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 474 | |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 475 | // Attempting to set the same colorTransformMatrix that is already set should |
| 476 | // also skip the update. |
| 477 | CompositionRefreshArgs refreshArgs; |
| 478 | refreshArgs.colorTransformMatrix = kIdentity; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 479 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 480 | mOutput->setColorTransform(refreshArgs); |
Lloyd Pique | 77f79a2 | 2019-04-29 15:55:40 -0700 | [diff] [blame] | 481 | |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 482 | // The internal state should be unchanged |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 483 | EXPECT_EQ(kIdentity, mOutput->getState().colorTransformMatrix); |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 484 | |
| 485 | // No dirty region should be set |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 486 | EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region())); |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | TEST_F(OutputTest, setColorTransformPerformsUpdateToIdentity) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 490 | mOutput->editState().colorTransformMatrix = kNonIdentityHalf; |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 491 | |
| 492 | // Setting a different colorTransformMatrix should perform the update. |
| 493 | CompositionRefreshArgs refreshArgs; |
| 494 | refreshArgs.colorTransformMatrix = kIdentity; |
| 495 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 496 | mOutput->setColorTransform(refreshArgs); |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 497 | |
| 498 | // The internal state should have been updated |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 499 | EXPECT_EQ(kIdentity, mOutput->getState().colorTransformMatrix); |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 500 | |
| 501 | // The dirtyRegion should be set to the full display size |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 502 | EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize))); |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 503 | } |
Lloyd Pique | 77f79a2 | 2019-04-29 15:55:40 -0700 | [diff] [blame] | 504 | |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 505 | TEST_F(OutputTest, setColorTransformPerformsUpdateForIdentityToHalf) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 506 | mOutput->editState().colorTransformMatrix = kIdentity; |
Lloyd Pique | 77f79a2 | 2019-04-29 15:55:40 -0700 | [diff] [blame] | 507 | |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 508 | // Setting a different colorTransformMatrix should perform the update. |
| 509 | CompositionRefreshArgs refreshArgs; |
| 510 | refreshArgs.colorTransformMatrix = kNonIdentityHalf; |
Lloyd Pique | 77f79a2 | 2019-04-29 15:55:40 -0700 | [diff] [blame] | 511 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 512 | mOutput->setColorTransform(refreshArgs); |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 513 | |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 514 | // The internal state should have been updated |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 515 | EXPECT_EQ(kNonIdentityHalf, mOutput->getState().colorTransformMatrix); |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 516 | |
| 517 | // The dirtyRegion should be set to the full display size |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 518 | EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize))); |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 519 | } |
| 520 | |
| 521 | TEST_F(OutputTest, setColorTransformPerformsUpdateForHalfToQuarter) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 522 | mOutput->editState().colorTransformMatrix = kNonIdentityHalf; |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 523 | |
| 524 | // Setting a different colorTransformMatrix should perform the update. |
| 525 | CompositionRefreshArgs refreshArgs; |
| 526 | refreshArgs.colorTransformMatrix = kNonIdentityQuarter; |
| 527 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 528 | mOutput->setColorTransform(refreshArgs); |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 529 | |
| 530 | // The internal state should have been updated |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 531 | EXPECT_EQ(kNonIdentityQuarter, mOutput->getState().colorTransformMatrix); |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 532 | |
| 533 | // The dirtyRegion should be set to the full display size |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 534 | EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize))); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 535 | } |
| 536 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 537 | /* |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 538 | * Output::setColorProfile |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 539 | */ |
| 540 | |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 541 | using OutputSetColorProfileTest = OutputTest; |
| 542 | |
| 543 | TEST_F(OutputSetColorProfileTest, setsStateAndDirtiesOutputIfChanged) { |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 544 | using ColorProfile = Output::ColorProfile; |
| 545 | |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 546 | EXPECT_CALL(*mRenderSurface, setBufferDataspace(ui::Dataspace::DISPLAY_P3)).Times(1); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 547 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 548 | mOutput->setColorProfile(ColorProfile{ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3, |
Alec Mouri | 88790f3 | 2023-07-21 01:25:14 +0000 | [diff] [blame] | 549 | ui::RenderIntent::TONE_MAP_COLORIMETRIC}); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 550 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 551 | EXPECT_EQ(ui::ColorMode::DISPLAY_P3, mOutput->getState().colorMode); |
| 552 | EXPECT_EQ(ui::Dataspace::DISPLAY_P3, mOutput->getState().dataspace); |
| 553 | EXPECT_EQ(ui::RenderIntent::TONE_MAP_COLORIMETRIC, mOutput->getState().renderIntent); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 554 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 555 | EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize))); |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 556 | } |
| 557 | |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 558 | TEST_F(OutputSetColorProfileTest, doesNothingIfNoChange) { |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 559 | using ColorProfile = Output::ColorProfile; |
| 560 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 561 | mOutput->editState().colorMode = ui::ColorMode::DISPLAY_P3; |
| 562 | mOutput->editState().dataspace = ui::Dataspace::DISPLAY_P3; |
| 563 | mOutput->editState().renderIntent = ui::RenderIntent::TONE_MAP_COLORIMETRIC; |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 564 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 565 | mOutput->setColorProfile(ColorProfile{ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3, |
Alec Mouri | 88790f3 | 2023-07-21 01:25:14 +0000 | [diff] [blame] | 566 | ui::RenderIntent::TONE_MAP_COLORIMETRIC}); |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 567 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 568 | EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region())); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 569 | } |
| 570 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 571 | /* |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 572 | * Output::setRenderSurface() |
| 573 | */ |
| 574 | |
| 575 | TEST_F(OutputTest, setRenderSurfaceResetsBounds) { |
| 576 | const ui::Size newDisplaySize{640, 480}; |
| 577 | |
| 578 | mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>(); |
| 579 | EXPECT_CALL(*renderSurface, getSize()).WillOnce(ReturnRef(newDisplaySize)); |
| 580 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 581 | mOutput->setRenderSurface(std::unique_ptr<RenderSurface>(renderSurface)); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 582 | |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 583 | EXPECT_EQ(Rect(newDisplaySize), mOutput->getState().framebufferSpace.getBoundsAsRect()); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 584 | } |
| 585 | |
Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 586 | /** |
| 587 | * Output::setDisplayBrightness() |
| 588 | */ |
| 589 | |
| 590 | TEST_F(OutputTest, setNextBrightness) { |
| 591 | constexpr float kDisplayBrightness = 0.5f; |
| 592 | mOutput->setNextBrightness(kDisplayBrightness); |
| 593 | ASSERT_TRUE(mOutput->getState().displayBrightness.has_value()); |
| 594 | EXPECT_EQ(kDisplayBrightness, mOutput->getState().displayBrightness); |
| 595 | } |
| 596 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 597 | /* |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 598 | * Output::getDirtyRegion() |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 599 | */ |
| 600 | |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 601 | TEST_F(OutputTest, getDirtyRegion) { |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 602 | const Rect viewport{100, 200}; |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 603 | mOutput->editState().layerStackSpace.setContent(viewport); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 604 | mOutput->editState().dirtyRegion.set(50, 300); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 605 | |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 606 | // The dirty region should be clipped to the display bounds. |
| 607 | EXPECT_THAT(mOutput->getDirtyRegion(), RegionEq(Region(Rect(50, 200)))); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 608 | } |
| 609 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 610 | /* |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 611 | * Output::includesLayer() |
Lloyd Pique | ef36b00 | 2019-01-23 17:52:04 -0800 | [diff] [blame] | 612 | */ |
| 613 | |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 614 | TEST_F(OutputTest, layerFiltering) { |
| 615 | const ui::LayerStack layerStack1{123u}; |
| 616 | const ui::LayerStack layerStack2{456u}; |
Lloyd Pique | ef36b00 | 2019-01-23 17:52:04 -0800 | [diff] [blame] | 617 | |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 618 | // If the output is associated to layerStack1 and to an internal display... |
| 619 | mOutput->setLayerFilter({layerStack1, true}); |
Lloyd Pique | ef36b00 | 2019-01-23 17:52:04 -0800 | [diff] [blame] | 620 | |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 621 | // It excludes layers with no layer stack, internal-only or not. |
| 622 | EXPECT_FALSE(mOutput->includesLayer({ui::INVALID_LAYER_STACK, false})); |
| 623 | EXPECT_FALSE(mOutput->includesLayer({ui::INVALID_LAYER_STACK, true})); |
Lloyd Pique | c668734 | 2019-03-07 21:34:57 -0800 | [diff] [blame] | 624 | |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 625 | // It includes layers on layerStack1, internal-only or not. |
| 626 | EXPECT_TRUE(mOutput->includesLayer({layerStack1, false})); |
| 627 | EXPECT_TRUE(mOutput->includesLayer({layerStack1, true})); |
| 628 | EXPECT_FALSE(mOutput->includesLayer({layerStack2, true})); |
| 629 | EXPECT_FALSE(mOutput->includesLayer({layerStack2, false})); |
Lloyd Pique | ef36b00 | 2019-01-23 17:52:04 -0800 | [diff] [blame] | 630 | |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 631 | // If the output is associated to layerStack1 but not to an internal display... |
| 632 | mOutput->setLayerFilter({layerStack1, false}); |
Lloyd Pique | ef36b00 | 2019-01-23 17:52:04 -0800 | [diff] [blame] | 633 | |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 634 | // It includes layers on layerStack1, unless they are internal-only. |
| 635 | EXPECT_TRUE(mOutput->includesLayer({layerStack1, false})); |
| 636 | EXPECT_FALSE(mOutput->includesLayer({layerStack1, true})); |
| 637 | EXPECT_FALSE(mOutput->includesLayer({layerStack2, true})); |
| 638 | EXPECT_FALSE(mOutput->includesLayer({layerStack2, false})); |
Lloyd Pique | ef36b00 | 2019-01-23 17:52:04 -0800 | [diff] [blame] | 639 | } |
| 640 | |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 641 | TEST_F(OutputTest, layerFilteringWithoutCompositionState) { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 642 | NonInjectedLayer layer; |
| 643 | sp<LayerFE> layerFE(layer.layerFE); |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 644 | |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 645 | // Layers without composition state are excluded. |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 646 | EXPECT_CALL(*layer.layerFE, getCompositionState).WillOnce(Return(nullptr)); |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 647 | EXPECT_FALSE(mOutput->includesLayer(layerFE)); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 648 | } |
| 649 | |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 650 | TEST_F(OutputTest, layerFilteringWithCompositionState) { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 651 | NonInjectedLayer layer; |
| 652 | sp<LayerFE> layerFE(layer.layerFE); |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 653 | |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 654 | const ui::LayerStack layerStack1{123u}; |
| 655 | const ui::LayerStack layerStack2{456u}; |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 656 | |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 657 | // If the output is associated to layerStack1 and to an internal display... |
| 658 | mOutput->setLayerFilter({layerStack1, true}); |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 659 | |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 660 | // It excludes layers with no layer stack, internal-only or not. |
| 661 | layer.layerFEState.outputFilter = {ui::INVALID_LAYER_STACK, false}; |
| 662 | EXPECT_FALSE(mOutput->includesLayer(layerFE)); |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 663 | |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 664 | layer.layerFEState.outputFilter = {ui::INVALID_LAYER_STACK, true}; |
| 665 | EXPECT_FALSE(mOutput->includesLayer(layerFE)); |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 666 | |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 667 | // It includes layers on layerStack1, internal-only or not. |
| 668 | layer.layerFEState.outputFilter = {layerStack1, false}; |
| 669 | EXPECT_TRUE(mOutput->includesLayer(layerFE)); |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 670 | |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 671 | layer.layerFEState.outputFilter = {layerStack1, true}; |
| 672 | EXPECT_TRUE(mOutput->includesLayer(layerFE)); |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 673 | |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 674 | layer.layerFEState.outputFilter = {layerStack2, true}; |
| 675 | EXPECT_FALSE(mOutput->includesLayer(layerFE)); |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 676 | |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 677 | layer.layerFEState.outputFilter = {layerStack2, false}; |
| 678 | EXPECT_FALSE(mOutput->includesLayer(layerFE)); |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 679 | |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 680 | // If the output is associated to layerStack1 but not to an internal display... |
| 681 | mOutput->setLayerFilter({layerStack1, false}); |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 682 | |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 683 | // It includes layers on layerStack1, unless they are internal-only. |
| 684 | layer.layerFEState.outputFilter = {layerStack1, false}; |
| 685 | EXPECT_TRUE(mOutput->includesLayer(layerFE)); |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 686 | |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 687 | layer.layerFEState.outputFilter = {layerStack1, true}; |
| 688 | EXPECT_FALSE(mOutput->includesLayer(layerFE)); |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 689 | |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 690 | layer.layerFEState.outputFilter = {layerStack2, true}; |
| 691 | EXPECT_FALSE(mOutput->includesLayer(layerFE)); |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 692 | |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 693 | layer.layerFEState.outputFilter = {layerStack2, false}; |
| 694 | EXPECT_FALSE(mOutput->includesLayer(layerFE)); |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 695 | } |
| 696 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 697 | /* |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 698 | * Output::getOutputLayerForLayer() |
| 699 | */ |
| 700 | |
| 701 | TEST_F(OutputTest, getOutputLayerForLayerWorks) { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 702 | InjectedLayer layer1; |
| 703 | InjectedLayer layer2; |
| 704 | NonInjectedLayer layer3; |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 705 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 706 | injectOutputLayer(layer1); |
| 707 | injectNullOutputLayer(); |
| 708 | injectOutputLayer(layer2); |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 709 | |
| 710 | // If the input layer matches the first OutputLayer, it will be returned. |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 711 | EXPECT_CALL(*layer1.outputLayer, getLayerFE()).WillOnce(ReturnRef(*layer1.layerFE.get())); |
| 712 | EXPECT_EQ(layer1.outputLayer, mOutput->getOutputLayerForLayer(layer1.layerFE)); |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 713 | |
| 714 | // If the input layer matches the second OutputLayer, it will be returned. |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 715 | EXPECT_CALL(*layer1.outputLayer, getLayerFE()).WillOnce(ReturnRef(*layer1.layerFE.get())); |
| 716 | EXPECT_CALL(*layer2.outputLayer, getLayerFE()).WillOnce(ReturnRef(*layer2.layerFE.get())); |
| 717 | EXPECT_EQ(layer2.outputLayer, mOutput->getOutputLayerForLayer(layer2.layerFE)); |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 718 | |
| 719 | // 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] | 720 | EXPECT_CALL(*layer1.outputLayer, getLayerFE()).WillOnce(ReturnRef(*layer1.layerFE.get())); |
| 721 | EXPECT_CALL(*layer2.outputLayer, getLayerFE()).WillOnce(ReturnRef(*layer2.layerFE.get())); |
| 722 | EXPECT_EQ(nullptr, mOutput->getOutputLayerForLayer(layer3.layerFE)); |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 723 | } |
| 724 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 725 | /* |
Lloyd Pique | c9e6003 | 2019-11-14 11:47:26 -0800 | [diff] [blame] | 726 | * Output::setReleasedLayers() |
| 727 | */ |
| 728 | |
| 729 | using OutputSetReleasedLayersTest = OutputTest; |
| 730 | |
| 731 | TEST_F(OutputSetReleasedLayersTest, setReleasedLayersTakesGivenLayers) { |
Ady Abraham | e0eafa8 | 2022-02-02 19:30:47 -0800 | [diff] [blame] | 732 | sp<StrictMock<mock::LayerFE>> layer1FE = sp<StrictMock<mock::LayerFE>>::make(); |
| 733 | sp<StrictMock<mock::LayerFE>> layer2FE = sp<StrictMock<mock::LayerFE>>::make(); |
| 734 | sp<StrictMock<mock::LayerFE>> layer3FE = sp<StrictMock<mock::LayerFE>>::make(); |
Lloyd Pique | c9e6003 | 2019-11-14 11:47:26 -0800 | [diff] [blame] | 735 | |
| 736 | Output::ReleasedLayers layers; |
| 737 | layers.push_back(layer1FE); |
| 738 | layers.push_back(layer2FE); |
| 739 | layers.push_back(layer3FE); |
| 740 | |
| 741 | mOutput->setReleasedLayers(std::move(layers)); |
| 742 | |
| 743 | const auto& setLayers = mOutput->getReleasedLayersForTest(); |
| 744 | ASSERT_EQ(3u, setLayers.size()); |
| 745 | ASSERT_EQ(layer1FE.get(), setLayers[0].promote().get()); |
| 746 | ASSERT_EQ(layer2FE.get(), setLayers[1].promote().get()); |
| 747 | ASSERT_EQ(layer3FE.get(), setLayers[2].promote().get()); |
| 748 | } |
| 749 | |
| 750 | /* |
Alec Mouri | f9a2a2c | 2019-11-12 12:46:02 -0800 | [diff] [blame] | 751 | * Output::updateAndWriteCompositionState() |
| 752 | */ |
| 753 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 754 | using OutputUpdateAndWriteCompositionStateTest = OutputTest; |
Lloyd Pique | ef63b61 | 2019-11-14 13:19:56 -0800 | [diff] [blame] | 755 | |
| 756 | TEST_F(OutputUpdateAndWriteCompositionStateTest, doesNothingIfLayers) { |
| 757 | mOutput->editState().isEnabled = true; |
Alec Mouri | f9a2a2c | 2019-11-12 12:46:02 -0800 | [diff] [blame] | 758 | |
| 759 | CompositionRefreshArgs args; |
Dan Stoza | 269dc4d | 2021-01-15 15:07:43 -0800 | [diff] [blame] | 760 | mOutput->updateCompositionState(args); |
| 761 | mOutput->planComposition(); |
| 762 | mOutput->writeCompositionState(args); |
Alec Mouri | f9a2a2c | 2019-11-12 12:46:02 -0800 | [diff] [blame] | 763 | } |
| 764 | |
Lloyd Pique | ef63b61 | 2019-11-14 13:19:56 -0800 | [diff] [blame] | 765 | TEST_F(OutputUpdateAndWriteCompositionStateTest, doesNothingIfOutputNotEnabled) { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 766 | InjectedLayer layer1; |
| 767 | InjectedLayer layer2; |
| 768 | InjectedLayer layer3; |
| 769 | |
Lloyd Pique | ef63b61 | 2019-11-14 13:19:56 -0800 | [diff] [blame] | 770 | mOutput->editState().isEnabled = false; |
Alec Mouri | f9a2a2c | 2019-11-12 12:46:02 -0800 | [diff] [blame] | 771 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 772 | injectOutputLayer(layer1); |
| 773 | injectOutputLayer(layer2); |
| 774 | injectOutputLayer(layer3); |
Lloyd Pique | ef63b61 | 2019-11-14 13:19:56 -0800 | [diff] [blame] | 775 | |
| 776 | CompositionRefreshArgs args; |
Dan Stoza | 269dc4d | 2021-01-15 15:07:43 -0800 | [diff] [blame] | 777 | mOutput->updateCompositionState(args); |
| 778 | mOutput->planComposition(); |
| 779 | mOutput->writeCompositionState(args); |
Lloyd Pique | ef63b61 | 2019-11-14 13:19:56 -0800 | [diff] [blame] | 780 | } |
| 781 | |
| 782 | TEST_F(OutputUpdateAndWriteCompositionStateTest, updatesLayerContentForAllLayers) { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 783 | InjectedLayer layer1; |
| 784 | InjectedLayer layer2; |
| 785 | InjectedLayer layer3; |
Lloyd Pique | ef63b61 | 2019-11-14 13:19:56 -0800 | [diff] [blame] | 786 | |
Leon Scroggins III | e2ee040 | 2021-04-02 16:59:37 -0400 | [diff] [blame] | 787 | uint32_t z = 0; |
Snild Dolkow | 9e217d6 | 2020-04-22 15:53:42 +0200 | [diff] [blame] | 788 | EXPECT_CALL(*layer1.outputLayer, updateCompositionState(false, false, ui::Transform::ROT_180)); |
Dan Stoza | 6166c31 | 2021-01-15 16:34:05 -0800 | [diff] [blame] | 789 | EXPECT_CALL(*layer1.outputLayer, |
Leon Scroggins III | 9aa25c2 | 2021-04-15 15:30:19 -0400 | [diff] [blame] | 790 | writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, z++, |
| 791 | /*zIsOverridden*/ false, /*isPeekingThrough*/ false)); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 792 | EXPECT_CALL(*layer1.outputLayer, requiresClientComposition()).WillRepeatedly(Return(false)); |
Snild Dolkow | 9e217d6 | 2020-04-22 15:53:42 +0200 | [diff] [blame] | 793 | EXPECT_CALL(*layer2.outputLayer, updateCompositionState(false, false, ui::Transform::ROT_180)); |
Dan Stoza | 6166c31 | 2021-01-15 16:34:05 -0800 | [diff] [blame] | 794 | EXPECT_CALL(*layer2.outputLayer, |
Leon Scroggins III | 9aa25c2 | 2021-04-15 15:30:19 -0400 | [diff] [blame] | 795 | writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, z++, |
| 796 | /*zIsOverridden*/ false, /*isPeekingThrough*/ false)); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 797 | EXPECT_CALL(*layer2.outputLayer, requiresClientComposition()).WillRepeatedly(Return(false)); |
Snild Dolkow | 9e217d6 | 2020-04-22 15:53:42 +0200 | [diff] [blame] | 798 | EXPECT_CALL(*layer3.outputLayer, updateCompositionState(false, false, ui::Transform::ROT_180)); |
Dan Stoza | 6166c31 | 2021-01-15 16:34:05 -0800 | [diff] [blame] | 799 | EXPECT_CALL(*layer3.outputLayer, |
Leon Scroggins III | 9aa25c2 | 2021-04-15 15:30:19 -0400 | [diff] [blame] | 800 | writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, z++, |
| 801 | /*zIsOverridden*/ false, /*isPeekingThrough*/ false)); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 802 | EXPECT_CALL(*layer3.outputLayer, requiresClientComposition()).WillRepeatedly(Return(false)); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 803 | |
| 804 | injectOutputLayer(layer1); |
| 805 | injectOutputLayer(layer2); |
| 806 | injectOutputLayer(layer3); |
Lloyd Pique | ef63b61 | 2019-11-14 13:19:56 -0800 | [diff] [blame] | 807 | |
| 808 | mOutput->editState().isEnabled = true; |
| 809 | |
| 810 | CompositionRefreshArgs args; |
| 811 | args.updatingGeometryThisFrame = false; |
| 812 | args.devOptForceClientComposition = false; |
Snild Dolkow | 9e217d6 | 2020-04-22 15:53:42 +0200 | [diff] [blame] | 813 | args.internalDisplayRotationFlags = ui::Transform::ROT_180; |
Dan Stoza | 269dc4d | 2021-01-15 15:07:43 -0800 | [diff] [blame] | 814 | mOutput->updateCompositionState(args); |
| 815 | mOutput->planComposition(); |
| 816 | mOutput->writeCompositionState(args); |
Lloyd Pique | ef63b61 | 2019-11-14 13:19:56 -0800 | [diff] [blame] | 817 | } |
| 818 | |
| 819 | TEST_F(OutputUpdateAndWriteCompositionStateTest, updatesLayerGeometryAndContentForAllLayers) { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 820 | InjectedLayer layer1; |
| 821 | InjectedLayer layer2; |
| 822 | InjectedLayer layer3; |
Lloyd Pique | ef63b61 | 2019-11-14 13:19:56 -0800 | [diff] [blame] | 823 | |
Leon Scroggins III | e2ee040 | 2021-04-02 16:59:37 -0400 | [diff] [blame] | 824 | uint32_t z = 0; |
Snild Dolkow | 9e217d6 | 2020-04-22 15:53:42 +0200 | [diff] [blame] | 825 | EXPECT_CALL(*layer1.outputLayer, updateCompositionState(true, false, ui::Transform::ROT_0)); |
Dan Stoza | 6166c31 | 2021-01-15 16:34:05 -0800 | [diff] [blame] | 826 | EXPECT_CALL(*layer1.outputLayer, |
Leon Scroggins III | 9aa25c2 | 2021-04-15 15:30:19 -0400 | [diff] [blame] | 827 | writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, z++, |
| 828 | /*zIsOverridden*/ false, /*isPeekingThrough*/ false)); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 829 | EXPECT_CALL(*layer1.outputLayer, requiresClientComposition()).WillRepeatedly(Return(false)); |
Snild Dolkow | 9e217d6 | 2020-04-22 15:53:42 +0200 | [diff] [blame] | 830 | EXPECT_CALL(*layer2.outputLayer, updateCompositionState(true, false, ui::Transform::ROT_0)); |
Dan Stoza | 6166c31 | 2021-01-15 16:34:05 -0800 | [diff] [blame] | 831 | EXPECT_CALL(*layer2.outputLayer, |
Leon Scroggins III | 9aa25c2 | 2021-04-15 15:30:19 -0400 | [diff] [blame] | 832 | writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, z++, |
| 833 | /*zIsOverridden*/ false, /*isPeekingThrough*/ false)); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 834 | EXPECT_CALL(*layer2.outputLayer, requiresClientComposition()).WillRepeatedly(Return(false)); |
Snild Dolkow | 9e217d6 | 2020-04-22 15:53:42 +0200 | [diff] [blame] | 835 | EXPECT_CALL(*layer3.outputLayer, updateCompositionState(true, false, ui::Transform::ROT_0)); |
Dan Stoza | 6166c31 | 2021-01-15 16:34:05 -0800 | [diff] [blame] | 836 | EXPECT_CALL(*layer3.outputLayer, |
Leon Scroggins III | 9aa25c2 | 2021-04-15 15:30:19 -0400 | [diff] [blame] | 837 | writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, z++, |
| 838 | /*zIsOverridden*/ false, /*isPeekingThrough*/ false)); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 839 | EXPECT_CALL(*layer3.outputLayer, requiresClientComposition()).WillRepeatedly(Return(false)); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 840 | |
| 841 | injectOutputLayer(layer1); |
| 842 | injectOutputLayer(layer2); |
| 843 | injectOutputLayer(layer3); |
Lloyd Pique | ef63b61 | 2019-11-14 13:19:56 -0800 | [diff] [blame] | 844 | |
| 845 | mOutput->editState().isEnabled = true; |
Alec Mouri | f9a2a2c | 2019-11-12 12:46:02 -0800 | [diff] [blame] | 846 | |
| 847 | CompositionRefreshArgs args; |
| 848 | args.updatingGeometryThisFrame = true; |
Lloyd Pique | ef63b61 | 2019-11-14 13:19:56 -0800 | [diff] [blame] | 849 | args.devOptForceClientComposition = false; |
Dan Stoza | 269dc4d | 2021-01-15 15:07:43 -0800 | [diff] [blame] | 850 | mOutput->updateCompositionState(args); |
| 851 | mOutput->planComposition(); |
| 852 | mOutput->writeCompositionState(args); |
Lloyd Pique | ef63b61 | 2019-11-14 13:19:56 -0800 | [diff] [blame] | 853 | } |
| 854 | |
| 855 | TEST_F(OutputUpdateAndWriteCompositionStateTest, forcesClientCompositionForAllLayers) { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 856 | InjectedLayer layer1; |
| 857 | InjectedLayer layer2; |
| 858 | InjectedLayer layer3; |
Lloyd Pique | ef63b61 | 2019-11-14 13:19:56 -0800 | [diff] [blame] | 859 | |
Leon Scroggins III | e2ee040 | 2021-04-02 16:59:37 -0400 | [diff] [blame] | 860 | uint32_t z = 0; |
Snild Dolkow | 9e217d6 | 2020-04-22 15:53:42 +0200 | [diff] [blame] | 861 | EXPECT_CALL(*layer1.outputLayer, updateCompositionState(false, true, ui::Transform::ROT_0)); |
Dan Stoza | 6166c31 | 2021-01-15 16:34:05 -0800 | [diff] [blame] | 862 | EXPECT_CALL(*layer1.outputLayer, |
Leon Scroggins III | 9aa25c2 | 2021-04-15 15:30:19 -0400 | [diff] [blame] | 863 | writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, z++, |
| 864 | /*zIsOverridden*/ false, /*isPeekingThrough*/ false)); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 865 | EXPECT_CALL(*layer1.outputLayer, requiresClientComposition()).WillRepeatedly(Return(false)); |
Snild Dolkow | 9e217d6 | 2020-04-22 15:53:42 +0200 | [diff] [blame] | 866 | EXPECT_CALL(*layer2.outputLayer, updateCompositionState(false, true, ui::Transform::ROT_0)); |
Dan Stoza | 6166c31 | 2021-01-15 16:34:05 -0800 | [diff] [blame] | 867 | EXPECT_CALL(*layer2.outputLayer, |
Leon Scroggins III | 9aa25c2 | 2021-04-15 15:30:19 -0400 | [diff] [blame] | 868 | writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, z++, |
| 869 | /*zIsOverridden*/ false, /*isPeekingThrough*/ false)); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 870 | EXPECT_CALL(*layer2.outputLayer, requiresClientComposition()).WillRepeatedly(Return(false)); |
Snild Dolkow | 9e217d6 | 2020-04-22 15:53:42 +0200 | [diff] [blame] | 871 | EXPECT_CALL(*layer3.outputLayer, updateCompositionState(false, true, ui::Transform::ROT_0)); |
Dan Stoza | 6166c31 | 2021-01-15 16:34:05 -0800 | [diff] [blame] | 872 | EXPECT_CALL(*layer3.outputLayer, |
Leon Scroggins III | 9aa25c2 | 2021-04-15 15:30:19 -0400 | [diff] [blame] | 873 | writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, z++, |
| 874 | /*zIsOverridden*/ false, /*isPeekingThrough*/ false)); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 875 | EXPECT_CALL(*layer3.outputLayer, requiresClientComposition()).WillRepeatedly(Return(false)); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 876 | |
| 877 | injectOutputLayer(layer1); |
| 878 | injectOutputLayer(layer2); |
| 879 | injectOutputLayer(layer3); |
Lloyd Pique | ef63b61 | 2019-11-14 13:19:56 -0800 | [diff] [blame] | 880 | |
| 881 | mOutput->editState().isEnabled = true; |
| 882 | |
| 883 | CompositionRefreshArgs args; |
| 884 | args.updatingGeometryThisFrame = false; |
Alec Mouri | f9a2a2c | 2019-11-12 12:46:02 -0800 | [diff] [blame] | 885 | args.devOptForceClientComposition = true; |
Dan Stoza | 269dc4d | 2021-01-15 15:07:43 -0800 | [diff] [blame] | 886 | mOutput->updateCompositionState(args); |
| 887 | mOutput->planComposition(); |
| 888 | mOutput->writeCompositionState(args); |
Alec Mouri | f9a2a2c | 2019-11-12 12:46:02 -0800 | [diff] [blame] | 889 | } |
| 890 | |
Leon Scroggins III | 2e74a4c | 2021-04-09 13:41:14 -0400 | [diff] [blame] | 891 | TEST_F(OutputUpdateAndWriteCompositionStateTest, peekThroughLayerChangesOrder) { |
| 892 | renderengine::mock::RenderEngine renderEngine; |
| 893 | InjectedLayer layer0; |
| 894 | InjectedLayer layer1; |
| 895 | InjectedLayer layer2; |
| 896 | InjectedLayer layer3; |
| 897 | |
| 898 | InSequence seq; |
| 899 | EXPECT_CALL(*layer0.outputLayer, updateCompositionState(true, false, ui::Transform::ROT_0)); |
| 900 | EXPECT_CALL(*layer1.outputLayer, updateCompositionState(true, false, ui::Transform::ROT_0)); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 901 | EXPECT_CALL(*layer1.outputLayer, requiresClientComposition()).WillRepeatedly(Return(false)); |
Leon Scroggins III | 2e74a4c | 2021-04-09 13:41:14 -0400 | [diff] [blame] | 902 | EXPECT_CALL(*layer2.outputLayer, updateCompositionState(true, false, ui::Transform::ROT_0)); |
| 903 | EXPECT_CALL(*layer3.outputLayer, updateCompositionState(true, false, ui::Transform::ROT_0)); |
| 904 | |
| 905 | uint32_t z = 0; |
| 906 | EXPECT_CALL(*layer0.outputLayer, |
| 907 | writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, z++, |
| 908 | /*zIsOverridden*/ false, /*isPeekingThrough*/ false)); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 909 | EXPECT_CALL(*layer0.outputLayer, requiresClientComposition()).WillRepeatedly(Return(false)); |
Leon Scroggins III | 2e74a4c | 2021-04-09 13:41:14 -0400 | [diff] [blame] | 910 | |
| 911 | // After calling planComposition (which clears overrideInfo), this test sets |
| 912 | // layer3 to be the peekThroughLayer for layer1 and layer2. As a result, it |
| 913 | // comes first, setting isPeekingThrough to true and zIsOverridden to true |
| 914 | // for it and the following layers. |
| 915 | EXPECT_CALL(*layer3.outputLayer, |
| 916 | writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, z++, |
| 917 | /*zIsOverridden*/ true, /*isPeekingThrough*/ |
| 918 | true)); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 919 | EXPECT_CALL(*layer3.outputLayer, requiresClientComposition()).WillRepeatedly(Return(false)); |
Leon Scroggins III | 2e74a4c | 2021-04-09 13:41:14 -0400 | [diff] [blame] | 920 | EXPECT_CALL(*layer1.outputLayer, |
| 921 | writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, z++, |
| 922 | /*zIsOverridden*/ true, /*isPeekingThrough*/ false)); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 923 | EXPECT_CALL(*layer1.outputLayer, requiresClientComposition()).WillRepeatedly(Return(false)); |
Leon Scroggins III | 2e74a4c | 2021-04-09 13:41:14 -0400 | [diff] [blame] | 924 | EXPECT_CALL(*layer2.outputLayer, |
| 925 | writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ true, z++, |
| 926 | /*zIsOverridden*/ true, /*isPeekingThrough*/ false)); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 927 | EXPECT_CALL(*layer2.outputLayer, requiresClientComposition()).WillRepeatedly(Return(false)); |
Leon Scroggins III | 2e74a4c | 2021-04-09 13:41:14 -0400 | [diff] [blame] | 928 | |
| 929 | injectOutputLayer(layer0); |
| 930 | injectOutputLayer(layer1); |
| 931 | injectOutputLayer(layer2); |
| 932 | injectOutputLayer(layer3); |
| 933 | |
| 934 | mOutput->editState().isEnabled = true; |
| 935 | |
| 936 | CompositionRefreshArgs args; |
| 937 | args.updatingGeometryThisFrame = true; |
| 938 | args.devOptForceClientComposition = false; |
| 939 | mOutput->updateCompositionState(args); |
| 940 | mOutput->planComposition(); |
| 941 | |
| 942 | std::shared_ptr<renderengine::ExternalTexture> buffer = std::make_shared< |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 943 | renderengine::impl:: |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 944 | ExternalTexture>(sp<GraphicBuffer>::make(), renderEngine, |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 945 | renderengine::impl::ExternalTexture::Usage::READABLE | |
| 946 | renderengine::impl::ExternalTexture::Usage::WRITEABLE); |
Leon Scroggins III | 2e74a4c | 2021-04-09 13:41:14 -0400 | [diff] [blame] | 947 | layer1.outputLayerState.overrideInfo.buffer = buffer; |
| 948 | layer2.outputLayerState.overrideInfo.buffer = buffer; |
| 949 | layer1.outputLayerState.overrideInfo.peekThroughLayer = layer3.outputLayer; |
| 950 | layer2.outputLayerState.overrideInfo.peekThroughLayer = layer3.outputLayer; |
| 951 | |
| 952 | mOutput->writeCompositionState(args); |
| 953 | } |
| 954 | |
Alec Mouri | f9a2a2c | 2019-11-12 12:46:02 -0800 | [diff] [blame] | 955 | /* |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 956 | * Output::prepareFrame() |
| 957 | */ |
| 958 | |
| 959 | struct OutputPrepareFrameTest : public testing::Test { |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 960 | struct OutputPartialMock : public OutputPartialMockBase { |
Lloyd Pique | 739afaf | 2019-11-21 16:40:05 -0800 | [diff] [blame] | 961 | // Sets up the helper functions called by the function under test to use |
| 962 | // mock implementations. |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 963 | MOCK_METHOD1(chooseCompositionStrategy, |
| 964 | bool(std::optional<android::HWComposer::DeviceRequestedChanges>*)); |
| 965 | MOCK_METHOD0(resetCompositionStrategy, void()); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 966 | }; |
| 967 | |
| 968 | OutputPrepareFrameTest() { |
| 969 | mOutput.setDisplayColorProfileForTest( |
| 970 | std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile)); |
| 971 | mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface)); |
| 972 | } |
| 973 | |
| 974 | StrictMock<mock::CompositionEngine> mCompositionEngine; |
| 975 | mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>(); |
| 976 | mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>(); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 977 | StrictMock<OutputPartialMock> mOutput; |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 978 | }; |
| 979 | |
| 980 | TEST_F(OutputPrepareFrameTest, takesEarlyOutIfNotEnabled) { |
| 981 | mOutput.editState().isEnabled = false; |
| 982 | |
| 983 | mOutput.prepareFrame(); |
| 984 | } |
| 985 | |
| 986 | TEST_F(OutputPrepareFrameTest, delegatesToChooseCompositionStrategyAndRenderSurface) { |
| 987 | mOutput.editState().isEnabled = true; |
| 988 | mOutput.editState().usesClientComposition = false; |
| 989 | mOutput.editState().usesDeviceComposition = true; |
| 990 | |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 991 | EXPECT_CALL(mOutput, chooseCompositionStrategy(_)).WillRepeatedly(Return(true)); |
| 992 | EXPECT_CALL(mOutput, resetCompositionStrategy()).Times(1); |
Alec Mouri | 023c188 | 2021-05-08 16:36:33 -0700 | [diff] [blame] | 993 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(0u)); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 994 | EXPECT_CALL(*mRenderSurface, prepareFrame(false, true)); |
| 995 | |
| 996 | mOutput.prepareFrame(); |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 997 | EXPECT_EQ(mOutput.getState().strategyPrediction, CompositionStrategyPredictionState::DISABLED); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 998 | } |
| 999 | |
| 1000 | // Note: Use OutputTest and not OutputPrepareFrameTest, so the real |
| 1001 | // base chooseCompositionStrategy() is invoked. |
| 1002 | TEST_F(OutputTest, prepareFrameSetsClientCompositionOnlyByDefault) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 1003 | mOutput->editState().isEnabled = true; |
| 1004 | mOutput->editState().usesClientComposition = false; |
| 1005 | mOutput->editState().usesDeviceComposition = true; |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 1006 | |
| 1007 | EXPECT_CALL(*mRenderSurface, prepareFrame(true, false)); |
| 1008 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 1009 | mOutput->prepareFrame(); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 1010 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 1011 | EXPECT_TRUE(mOutput->getState().usesClientComposition); |
| 1012 | EXPECT_FALSE(mOutput->getState().usesDeviceComposition); |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 1013 | EXPECT_EQ(mOutput->getState().strategyPrediction, CompositionStrategyPredictionState::DISABLED); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 1014 | } |
| 1015 | |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 1016 | struct OutputPrepareFrameAsyncTest : public testing::Test { |
| 1017 | struct OutputPartialMock : public OutputPartialMockBase { |
| 1018 | // Sets up the helper functions called by the function under test to use |
| 1019 | // mock implementations. |
| 1020 | MOCK_METHOD1(chooseCompositionStrategy, |
| 1021 | bool(std::optional<android::HWComposer::DeviceRequestedChanges>*)); |
| 1022 | MOCK_METHOD0(updateProtectedContentState, void()); |
| 1023 | MOCK_METHOD2(dequeueRenderBuffer, |
| 1024 | bool(base::unique_fd*, std::shared_ptr<renderengine::ExternalTexture>*)); |
| 1025 | MOCK_METHOD1( |
| 1026 | chooseCompositionStrategyAsync, |
| 1027 | std::future<bool>(std::optional<android::HWComposer::DeviceRequestedChanges>*)); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 1028 | MOCK_METHOD3(composeSurfaces, |
| 1029 | std::optional<base::unique_fd>(const Region&, |
| 1030 | std::shared_ptr<renderengine::ExternalTexture>, |
| 1031 | base::unique_fd&)); |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 1032 | MOCK_METHOD0(resetCompositionStrategy, void()); |
| 1033 | }; |
| 1034 | |
| 1035 | OutputPrepareFrameAsyncTest() { |
| 1036 | mOutput.setDisplayColorProfileForTest( |
| 1037 | std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile)); |
| 1038 | mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface)); |
| 1039 | } |
| 1040 | |
| 1041 | StrictMock<mock::CompositionEngine> mCompositionEngine; |
| 1042 | mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>(); |
| 1043 | mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>(); |
| 1044 | StrictMock<OutputPartialMock> mOutput; |
| 1045 | CompositionRefreshArgs mRefreshArgs; |
| 1046 | }; |
| 1047 | |
| 1048 | TEST_F(OutputPrepareFrameAsyncTest, delegatesToChooseCompositionStrategyAndRenderSurface) { |
| 1049 | mOutput.editState().isEnabled = true; |
| 1050 | mOutput.editState().usesClientComposition = false; |
| 1051 | mOutput.editState().usesDeviceComposition = true; |
| 1052 | mOutput.editState().previousDeviceRequestedChanges = |
| 1053 | std::make_optional<android::HWComposer::DeviceRequestedChanges>({}); |
| 1054 | std::promise<bool> p; |
| 1055 | p.set_value(true); |
| 1056 | |
| 1057 | EXPECT_CALL(mOutput, resetCompositionStrategy()).Times(1); |
| 1058 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(0u)); |
| 1059 | EXPECT_CALL(mOutput, updateProtectedContentState()); |
| 1060 | EXPECT_CALL(mOutput, dequeueRenderBuffer(_, _)).WillOnce(Return(true)); |
| 1061 | EXPECT_CALL(*mRenderSurface, prepareFrame(false, true)).Times(1); |
| 1062 | EXPECT_CALL(mOutput, chooseCompositionStrategyAsync(_)) |
| 1063 | .WillOnce(DoAll(SetArgPointee<0>(mOutput.editState().previousDeviceRequestedChanges), |
| 1064 | Return(ByMove(p.get_future())))); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 1065 | EXPECT_CALL(mOutput, composeSurfaces(_, _, _)); |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 1066 | |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 1067 | impl::GpuCompositionResult result = mOutput.prepareFrameAsync(); |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 1068 | EXPECT_EQ(mOutput.getState().strategyPrediction, CompositionStrategyPredictionState::SUCCESS); |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 1069 | EXPECT_FALSE(result.bufferAvailable()); |
| 1070 | } |
| 1071 | |
| 1072 | TEST_F(OutputPrepareFrameAsyncTest, skipCompositionOnDequeueFailure) { |
| 1073 | mOutput.editState().isEnabled = true; |
| 1074 | mOutput.editState().usesClientComposition = false; |
| 1075 | mOutput.editState().usesDeviceComposition = true; |
| 1076 | mOutput.editState().previousDeviceRequestedChanges = |
| 1077 | std::make_optional<android::HWComposer::DeviceRequestedChanges>({}); |
| 1078 | std::promise<bool> p; |
| 1079 | p.set_value(true); |
| 1080 | |
| 1081 | EXPECT_CALL(mOutput, resetCompositionStrategy()).Times(2); |
| 1082 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(0u)); |
| 1083 | EXPECT_CALL(mOutput, updateProtectedContentState()); |
| 1084 | EXPECT_CALL(mOutput, dequeueRenderBuffer(_, _)).WillOnce(Return(false)); |
| 1085 | EXPECT_CALL(*mRenderSurface, prepareFrame(false, true)).Times(2); |
| 1086 | EXPECT_CALL(mOutput, chooseCompositionStrategyAsync(_)) |
| 1087 | .WillOnce(DoAll(SetArgPointee<0>(mOutput.editState().previousDeviceRequestedChanges), |
| 1088 | Return(ByMove(p.get_future())))); |
| 1089 | |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 1090 | impl::GpuCompositionResult result = mOutput.prepareFrameAsync(); |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 1091 | EXPECT_EQ(mOutput.getState().strategyPrediction, CompositionStrategyPredictionState::FAIL); |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 1092 | EXPECT_FALSE(result.bufferAvailable()); |
| 1093 | } |
| 1094 | |
| 1095 | // Tests that in the event of hwc error when choosing composition strategy, we would fall back |
| 1096 | // client composition |
| 1097 | TEST_F(OutputPrepareFrameAsyncTest, chooseCompositionStrategyFailureCallsPrepareFrame) { |
| 1098 | mOutput.editState().isEnabled = true; |
| 1099 | mOutput.editState().usesClientComposition = false; |
| 1100 | mOutput.editState().usesDeviceComposition = true; |
| 1101 | mOutput.editState().previousDeviceRequestedChanges = |
| 1102 | std::make_optional<android::HWComposer::DeviceRequestedChanges>({}); |
| 1103 | std::promise<bool> p; |
| 1104 | p.set_value(false); |
| 1105 | std::shared_ptr<renderengine::ExternalTexture> tex = |
| 1106 | std::make_shared<renderengine::mock::FakeExternalTexture>(1, 1, |
| 1107 | HAL_PIXEL_FORMAT_RGBA_8888, 1, |
| 1108 | 2); |
| 1109 | EXPECT_CALL(mOutput, resetCompositionStrategy()).Times(2); |
| 1110 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(0u)); |
| 1111 | EXPECT_CALL(mOutput, updateProtectedContentState()); |
| 1112 | EXPECT_CALL(mOutput, dequeueRenderBuffer(_, _)) |
| 1113 | .WillOnce(DoAll(SetArgPointee<1>(tex), Return(true))); |
| 1114 | EXPECT_CALL(*mRenderSurface, prepareFrame(false, true)).Times(2); |
| 1115 | EXPECT_CALL(mOutput, chooseCompositionStrategyAsync(_)).WillOnce([&] { |
| 1116 | return p.get_future(); |
| 1117 | }); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 1118 | EXPECT_CALL(mOutput, composeSurfaces(_, _, _)); |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 1119 | |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 1120 | impl::GpuCompositionResult result = mOutput.prepareFrameAsync(); |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 1121 | EXPECT_EQ(mOutput.getState().strategyPrediction, CompositionStrategyPredictionState::FAIL); |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 1122 | EXPECT_TRUE(result.bufferAvailable()); |
| 1123 | } |
| 1124 | |
| 1125 | TEST_F(OutputPrepareFrameAsyncTest, predictionMiss) { |
| 1126 | mOutput.editState().isEnabled = true; |
| 1127 | mOutput.editState().usesClientComposition = false; |
| 1128 | mOutput.editState().usesDeviceComposition = true; |
| 1129 | mOutput.editState().previousDeviceRequestedChanges = |
| 1130 | std::make_optional<android::HWComposer::DeviceRequestedChanges>({}); |
| 1131 | auto newDeviceRequestedChanges = |
| 1132 | std::make_optional<android::HWComposer::DeviceRequestedChanges>({}); |
| 1133 | newDeviceRequestedChanges->displayRequests = static_cast<hal::DisplayRequest>(0); |
| 1134 | std::promise<bool> p; |
| 1135 | p.set_value(false); |
| 1136 | std::shared_ptr<renderengine::ExternalTexture> tex = |
| 1137 | std::make_shared<renderengine::mock::FakeExternalTexture>(1, 1, |
| 1138 | HAL_PIXEL_FORMAT_RGBA_8888, 1, |
| 1139 | 2); |
| 1140 | |
| 1141 | EXPECT_CALL(mOutput, resetCompositionStrategy()).Times(2); |
| 1142 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(0u)); |
| 1143 | EXPECT_CALL(mOutput, updateProtectedContentState()); |
| 1144 | EXPECT_CALL(mOutput, dequeueRenderBuffer(_, _)) |
| 1145 | .WillOnce(DoAll(SetArgPointee<1>(tex), Return(true))); |
| 1146 | EXPECT_CALL(*mRenderSurface, prepareFrame(false, true)).Times(2); |
| 1147 | EXPECT_CALL(mOutput, chooseCompositionStrategyAsync(_)).WillOnce([&] { |
| 1148 | return p.get_future(); |
| 1149 | }); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 1150 | EXPECT_CALL(mOutput, composeSurfaces(_, _, _)); |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 1151 | |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 1152 | impl::GpuCompositionResult result = mOutput.prepareFrameAsync(); |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 1153 | EXPECT_EQ(mOutput.getState().strategyPrediction, CompositionStrategyPredictionState::FAIL); |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 1154 | EXPECT_TRUE(result.bufferAvailable()); |
| 1155 | } |
| 1156 | |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 1157 | /* |
Lloyd Pique | b62cebc | 2019-11-20 18:31:52 -0800 | [diff] [blame] | 1158 | * Output::prepare() |
| 1159 | */ |
| 1160 | |
| 1161 | struct OutputPrepareTest : public testing::Test { |
| 1162 | struct OutputPartialMock : public OutputPartialMockBase { |
| 1163 | // Sets up the helper functions called by the function under test to use |
| 1164 | // mock implementations. |
| 1165 | MOCK_METHOD2(rebuildLayerStacks, |
| 1166 | void(const compositionengine::CompositionRefreshArgs&, |
| 1167 | compositionengine::LayerFESet&)); |
| 1168 | }; |
| 1169 | |
Brian Lindahl | 439afad | 2022-11-14 11:16:55 -0700 | [diff] [blame] | 1170 | OutputPrepareTest() { |
| 1171 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(2u)); |
| 1172 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0)) |
| 1173 | .WillRepeatedly(Return(&mLayer1.outputLayer)); |
| 1174 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(1)) |
| 1175 | .WillRepeatedly(Return(&mLayer2.outputLayer)); |
| 1176 | |
| 1177 | mRefreshArgs.layers.push_back(mLayer1.layerFE); |
| 1178 | mRefreshArgs.layers.push_back(mLayer2.layerFE); |
| 1179 | } |
| 1180 | |
| 1181 | struct Layer { |
| 1182 | StrictMock<mock::OutputLayer> outputLayer; |
| 1183 | sp<StrictMock<mock::LayerFE>> layerFE = sp<StrictMock<mock::LayerFE>>::make(); |
| 1184 | }; |
| 1185 | |
Lloyd Pique | b62cebc | 2019-11-20 18:31:52 -0800 | [diff] [blame] | 1186 | StrictMock<OutputPartialMock> mOutput; |
| 1187 | CompositionRefreshArgs mRefreshArgs; |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1188 | LayerFESet mGeomSnapshots; |
Brian Lindahl | 439afad | 2022-11-14 11:16:55 -0700 | [diff] [blame] | 1189 | Layer mLayer1; |
| 1190 | Layer mLayer2; |
Lloyd Pique | b62cebc | 2019-11-20 18:31:52 -0800 | [diff] [blame] | 1191 | }; |
| 1192 | |
Brian Lindahl | 439afad | 2022-11-14 11:16:55 -0700 | [diff] [blame] | 1193 | TEST_F(OutputPrepareTest, callsUncacheBuffersOnEachOutputLayerAndThenRebuildsLayerStacks) { |
Lloyd Pique | b62cebc | 2019-11-20 18:31:52 -0800 | [diff] [blame] | 1194 | InSequence seq; |
Brian Lindahl | 439afad | 2022-11-14 11:16:55 -0700 | [diff] [blame] | 1195 | |
| 1196 | mRefreshArgs.bufferIdsToUncache = {1, 3, 5}; |
| 1197 | |
Lloyd Pique | b62cebc | 2019-11-20 18:31:52 -0800 | [diff] [blame] | 1198 | EXPECT_CALL(mOutput, rebuildLayerStacks(Ref(mRefreshArgs), Ref(mGeomSnapshots))); |
Brian Lindahl | 439afad | 2022-11-14 11:16:55 -0700 | [diff] [blame] | 1199 | EXPECT_CALL(mLayer1.outputLayer, uncacheBuffers(Ref(mRefreshArgs.bufferIdsToUncache))); |
| 1200 | EXPECT_CALL(mLayer2.outputLayer, uncacheBuffers(Ref(mRefreshArgs.bufferIdsToUncache))); |
| 1201 | |
| 1202 | mOutput.prepare(mRefreshArgs, mGeomSnapshots); |
| 1203 | } |
| 1204 | |
| 1205 | TEST_F(OutputPrepareTest, skipsUncacheBuffersIfEmptyAndThenRebuildsLayerStacks) { |
| 1206 | InSequence seq; |
| 1207 | |
| 1208 | mRefreshArgs.bufferIdsToUncache = {}; |
| 1209 | |
| 1210 | EXPECT_CALL(mOutput, rebuildLayerStacks(Ref(mRefreshArgs), Ref(mGeomSnapshots))); |
| 1211 | EXPECT_CALL(mLayer1.outputLayer, uncacheBuffers(_)).Times(0); |
| 1212 | EXPECT_CALL(mLayer2.outputLayer, uncacheBuffers(_)).Times(0); |
Lloyd Pique | b62cebc | 2019-11-20 18:31:52 -0800 | [diff] [blame] | 1213 | |
| 1214 | mOutput.prepare(mRefreshArgs, mGeomSnapshots); |
| 1215 | } |
| 1216 | |
| 1217 | /* |
| 1218 | * Output::rebuildLayerStacks() |
| 1219 | */ |
| 1220 | |
| 1221 | struct OutputRebuildLayerStacksTest : public testing::Test { |
| 1222 | struct OutputPartialMock : public OutputPartialMockBase { |
| 1223 | // Sets up the helper functions called by the function under test to use |
| 1224 | // mock implementations. |
| 1225 | MOCK_METHOD2(collectVisibleLayers, |
| 1226 | void(const compositionengine::CompositionRefreshArgs&, |
| 1227 | compositionengine::Output::CoverageState&)); |
| 1228 | }; |
| 1229 | |
| 1230 | OutputRebuildLayerStacksTest() { |
| 1231 | mOutput.mState.isEnabled = true; |
| 1232 | mOutput.mState.transform = kIdentityTransform; |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 1233 | mOutput.mState.displaySpace.setBounds( |
| 1234 | ui::Size(kOutputBounds.getWidth(), kOutputBounds.getHeight())); |
Lloyd Pique | b62cebc | 2019-11-20 18:31:52 -0800 | [diff] [blame] | 1235 | |
| 1236 | mRefreshArgs.updatingOutputGeometryThisFrame = true; |
| 1237 | |
| 1238 | mCoverageAboveCoveredLayersToSet = Region(Rect(0, 0, 10, 10)); |
| 1239 | |
| 1240 | EXPECT_CALL(mOutput, collectVisibleLayers(Ref(mRefreshArgs), _)) |
| 1241 | .WillRepeatedly(Invoke(this, &OutputRebuildLayerStacksTest::setTestCoverageValues)); |
| 1242 | } |
| 1243 | |
| 1244 | void setTestCoverageValues(const CompositionRefreshArgs&, |
| 1245 | compositionengine::Output::CoverageState& state) { |
| 1246 | state.aboveCoveredLayers = mCoverageAboveCoveredLayersToSet; |
| 1247 | state.aboveOpaqueLayers = mCoverageAboveOpaqueLayersToSet; |
| 1248 | state.dirtyRegion = mCoverageDirtyRegionToSet; |
| 1249 | } |
| 1250 | |
| 1251 | static const ui::Transform kIdentityTransform; |
| 1252 | static const ui::Transform kRotate90Transform; |
| 1253 | static const Rect kOutputBounds; |
| 1254 | |
| 1255 | StrictMock<OutputPartialMock> mOutput; |
| 1256 | CompositionRefreshArgs mRefreshArgs; |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1257 | LayerFESet mGeomSnapshots; |
Lloyd Pique | b62cebc | 2019-11-20 18:31:52 -0800 | [diff] [blame] | 1258 | Region mCoverageAboveCoveredLayersToSet; |
| 1259 | Region mCoverageAboveOpaqueLayersToSet; |
| 1260 | Region mCoverageDirtyRegionToSet; |
| 1261 | }; |
| 1262 | |
| 1263 | const ui::Transform OutputRebuildLayerStacksTest::kIdentityTransform{TR_IDENT, 1920, 1080}; |
| 1264 | const ui::Transform OutputRebuildLayerStacksTest::kRotate90Transform{TR_ROT_90, 1920, 1080}; |
| 1265 | const Rect OutputRebuildLayerStacksTest::kOutputBounds{0, 0, 1920, 1080}; |
| 1266 | |
| 1267 | TEST_F(OutputRebuildLayerStacksTest, doesNothingIfNotEnabled) { |
| 1268 | mOutput.mState.isEnabled = false; |
| 1269 | |
| 1270 | mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots); |
| 1271 | } |
| 1272 | |
| 1273 | TEST_F(OutputRebuildLayerStacksTest, doesNothingIfNotUpdatingGeometryThisFrame) { |
| 1274 | mRefreshArgs.updatingOutputGeometryThisFrame = false; |
| 1275 | |
| 1276 | mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots); |
| 1277 | } |
| 1278 | |
| 1279 | TEST_F(OutputRebuildLayerStacksTest, computesUndefinedRegionWithNoRotationAndFullCoverage) { |
| 1280 | mOutput.mState.transform = kIdentityTransform; |
| 1281 | |
| 1282 | mCoverageAboveOpaqueLayersToSet = Region(Rect(0, 0, 1920, 1080)); |
| 1283 | |
| 1284 | mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots); |
| 1285 | |
| 1286 | EXPECT_THAT(mOutput.mState.undefinedRegion, RegionEq(Region(Rect(0, 0, 0, 0)))); |
| 1287 | } |
| 1288 | |
| 1289 | TEST_F(OutputRebuildLayerStacksTest, computesUndefinedRegionWithNoRotationAndPartialCoverage) { |
| 1290 | mOutput.mState.transform = kIdentityTransform; |
| 1291 | |
| 1292 | mCoverageAboveOpaqueLayersToSet = Region(Rect(0, 0, 960, 1080)); |
| 1293 | |
| 1294 | mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots); |
| 1295 | |
| 1296 | EXPECT_THAT(mOutput.mState.undefinedRegion, RegionEq(Region(Rect(960, 0, 1920, 1080)))); |
| 1297 | } |
| 1298 | |
| 1299 | TEST_F(OutputRebuildLayerStacksTest, computesUndefinedRegionWith90RotationAndFullCoverage) { |
| 1300 | mOutput.mState.transform = kRotate90Transform; |
| 1301 | |
| 1302 | mCoverageAboveOpaqueLayersToSet = Region(Rect(0, 0, 1080, 1920)); |
| 1303 | |
| 1304 | mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots); |
| 1305 | |
| 1306 | EXPECT_THAT(mOutput.mState.undefinedRegion, RegionEq(Region(Rect(0, 0, 0, 0)))); |
| 1307 | } |
| 1308 | |
| 1309 | TEST_F(OutputRebuildLayerStacksTest, computesUndefinedRegionWith90RotationAndPartialCoverage) { |
| 1310 | mOutput.mState.transform = kRotate90Transform; |
| 1311 | |
| 1312 | mCoverageAboveOpaqueLayersToSet = Region(Rect(0, 0, 1080, 960)); |
| 1313 | |
| 1314 | mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots); |
| 1315 | |
| 1316 | EXPECT_THAT(mOutput.mState.undefinedRegion, RegionEq(Region(Rect(0, 0, 960, 1080)))); |
| 1317 | } |
| 1318 | |
| 1319 | TEST_F(OutputRebuildLayerStacksTest, addsToDirtyRegionWithNoRotation) { |
| 1320 | mOutput.mState.transform = kIdentityTransform; |
| 1321 | mOutput.mState.dirtyRegion = Region(Rect(960, 0, 1920, 1080)); |
| 1322 | |
| 1323 | mCoverageDirtyRegionToSet = Region(Rect(0, 0, 960, 1080)); |
| 1324 | |
| 1325 | mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots); |
| 1326 | |
| 1327 | EXPECT_THAT(mOutput.mState.dirtyRegion, RegionEq(Region(Rect(0, 0, 1920, 1080)))); |
| 1328 | } |
| 1329 | |
| 1330 | TEST_F(OutputRebuildLayerStacksTest, addsToDirtyRegionWith90Rotation) { |
| 1331 | mOutput.mState.transform = kRotate90Transform; |
| 1332 | mOutput.mState.dirtyRegion = Region(Rect(0, 960, 1080, 1920)); |
| 1333 | |
| 1334 | mCoverageDirtyRegionToSet = Region(Rect(0, 0, 1080, 960)); |
| 1335 | |
| 1336 | mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots); |
| 1337 | |
| 1338 | EXPECT_THAT(mOutput.mState.dirtyRegion, RegionEq(Region(Rect(0, 0, 1080, 1920)))); |
| 1339 | } |
| 1340 | |
| 1341 | /* |
| 1342 | * Output::collectVisibleLayers() |
| 1343 | */ |
| 1344 | |
Lloyd Pique | 1ef9322 | 2019-11-21 16:41:53 -0800 | [diff] [blame] | 1345 | struct OutputCollectVisibleLayersTest : public testing::Test { |
| 1346 | struct OutputPartialMock : public OutputPartialMockBase { |
| 1347 | // Sets up the helper functions called by the function under test to use |
| 1348 | // mock implementations. |
| 1349 | MOCK_METHOD2(ensureOutputLayerIfVisible, |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1350 | void(sp<compositionengine::LayerFE>&, |
Lloyd Pique | 1ef9322 | 2019-11-21 16:41:53 -0800 | [diff] [blame] | 1351 | compositionengine::Output::CoverageState&)); |
| 1352 | MOCK_METHOD1(setReleasedLayers, void(const compositionengine::CompositionRefreshArgs&)); |
| 1353 | MOCK_METHOD0(finalizePendingOutputLayers, void()); |
| 1354 | }; |
| 1355 | |
| 1356 | struct Layer { |
| 1357 | Layer() { |
| 1358 | EXPECT_CALL(outputLayer, getState()).WillRepeatedly(ReturnRef(outputLayerState)); |
| 1359 | EXPECT_CALL(outputLayer, editState()).WillRepeatedly(ReturnRef(outputLayerState)); |
| 1360 | } |
| 1361 | |
| 1362 | StrictMock<mock::OutputLayer> outputLayer; |
Lloyd Pique | 1ef9322 | 2019-11-21 16:41:53 -0800 | [diff] [blame] | 1363 | impl::OutputLayerCompositionState outputLayerState; |
Ady Abraham | e0eafa8 | 2022-02-02 19:30:47 -0800 | [diff] [blame] | 1364 | sp<StrictMock<mock::LayerFE>> layerFE = sp<StrictMock<mock::LayerFE>>::make(); |
Lloyd Pique | 1ef9322 | 2019-11-21 16:41:53 -0800 | [diff] [blame] | 1365 | }; |
| 1366 | |
| 1367 | OutputCollectVisibleLayersTest() { |
Lloyd Pique | 0a45623 | 2020-01-16 17:51:13 -0800 | [diff] [blame] | 1368 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(3u)); |
Lloyd Pique | 1ef9322 | 2019-11-21 16:41:53 -0800 | [diff] [blame] | 1369 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0)) |
| 1370 | .WillRepeatedly(Return(&mLayer1.outputLayer)); |
| 1371 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(1)) |
| 1372 | .WillRepeatedly(Return(&mLayer2.outputLayer)); |
| 1373 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(2)) |
| 1374 | .WillRepeatedly(Return(&mLayer3.outputLayer)); |
| 1375 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1376 | mRefreshArgs.layers.push_back(mLayer1.layerFE); |
| 1377 | mRefreshArgs.layers.push_back(mLayer2.layerFE); |
| 1378 | mRefreshArgs.layers.push_back(mLayer3.layerFE); |
Lloyd Pique | 1ef9322 | 2019-11-21 16:41:53 -0800 | [diff] [blame] | 1379 | } |
| 1380 | |
| 1381 | StrictMock<OutputPartialMock> mOutput; |
| 1382 | CompositionRefreshArgs mRefreshArgs; |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1383 | LayerFESet mGeomSnapshots; |
| 1384 | Output::CoverageState mCoverageState{mGeomSnapshots}; |
Lloyd Pique | 1ef9322 | 2019-11-21 16:41:53 -0800 | [diff] [blame] | 1385 | Layer mLayer1; |
| 1386 | Layer mLayer2; |
| 1387 | Layer mLayer3; |
| 1388 | }; |
| 1389 | |
| 1390 | TEST_F(OutputCollectVisibleLayersTest, doesMinimalWorkIfNoLayers) { |
| 1391 | mRefreshArgs.layers.clear(); |
Lloyd Pique | 0a45623 | 2020-01-16 17:51:13 -0800 | [diff] [blame] | 1392 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(0u)); |
Lloyd Pique | 1ef9322 | 2019-11-21 16:41:53 -0800 | [diff] [blame] | 1393 | |
| 1394 | EXPECT_CALL(mOutput, setReleasedLayers(Ref(mRefreshArgs))); |
| 1395 | EXPECT_CALL(mOutput, finalizePendingOutputLayers()); |
| 1396 | |
| 1397 | mOutput.collectVisibleLayers(mRefreshArgs, mCoverageState); |
| 1398 | } |
| 1399 | |
| 1400 | TEST_F(OutputCollectVisibleLayersTest, processesCandidateLayersReversedAndSetsOutputLayerZ) { |
| 1401 | // Enforce a call order sequence for this test. |
| 1402 | InSequence seq; |
| 1403 | |
| 1404 | // Layer coverage is evaluated from front to back! |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1405 | EXPECT_CALL(mOutput, ensureOutputLayerIfVisible(Eq(mLayer3.layerFE), Ref(mCoverageState))); |
| 1406 | EXPECT_CALL(mOutput, ensureOutputLayerIfVisible(Eq(mLayer2.layerFE), Ref(mCoverageState))); |
| 1407 | EXPECT_CALL(mOutput, ensureOutputLayerIfVisible(Eq(mLayer1.layerFE), Ref(mCoverageState))); |
Lloyd Pique | 1ef9322 | 2019-11-21 16:41:53 -0800 | [diff] [blame] | 1408 | |
| 1409 | EXPECT_CALL(mOutput, setReleasedLayers(Ref(mRefreshArgs))); |
| 1410 | EXPECT_CALL(mOutput, finalizePendingOutputLayers()); |
| 1411 | |
| 1412 | mOutput.collectVisibleLayers(mRefreshArgs, mCoverageState); |
Lloyd Pique | 1ef9322 | 2019-11-21 16:41:53 -0800 | [diff] [blame] | 1413 | } |
Lloyd Pique | b62cebc | 2019-11-20 18:31:52 -0800 | [diff] [blame] | 1414 | |
| 1415 | /* |
| 1416 | * Output::ensureOutputLayerIfVisible() |
| 1417 | */ |
| 1418 | |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1419 | struct OutputEnsureOutputLayerIfVisibleTest : public testing::Test { |
| 1420 | struct OutputPartialMock : public OutputPartialMockBase { |
| 1421 | // Sets up the helper functions called by the function under test to use |
| 1422 | // mock implementations. |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 1423 | MOCK_METHOD(bool, includesLayer, (const sp<compositionengine::LayerFE>&), |
| 1424 | (const, override)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1425 | MOCK_CONST_METHOD1(getOutputLayerOrderedByZByIndex, OutputLayer*(size_t)); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1426 | MOCK_METHOD2(ensureOutputLayer, |
| 1427 | compositionengine::OutputLayer*(std::optional<size_t>, const sp<LayerFE>&)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1428 | }; |
| 1429 | |
| 1430 | OutputEnsureOutputLayerIfVisibleTest() { |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 1431 | EXPECT_CALL(mOutput, includesLayer(sp<LayerFE>(mLayer.layerFE))) |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1432 | .WillRepeatedly(Return(true)); |
Lloyd Pique | 0a45623 | 2020-01-16 17:51:13 -0800 | [diff] [blame] | 1433 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(1u)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1434 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0u)) |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1435 | .WillRepeatedly(Return(&mLayer.outputLayer)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1436 | |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 1437 | mOutput.mState.displaySpace.setBounds(ui::Size(200, 300)); |
| 1438 | mOutput.mState.layerStackSpace.setContent(Rect(0, 0, 200, 300)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1439 | mOutput.mState.transform = ui::Transform(TR_IDENT, 200, 300); |
| 1440 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1441 | mLayer.layerFEState.isVisible = true; |
| 1442 | mLayer.layerFEState.isOpaque = true; |
| 1443 | mLayer.layerFEState.contentDirty = true; |
| 1444 | mLayer.layerFEState.geomLayerBounds = FloatRect{0, 0, 100, 200}; |
| 1445 | mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200); |
Leon Scroggins III | 9a0afda | 2022-01-11 16:53:09 -0500 | [diff] [blame] | 1446 | mLayer.layerFEState.transparentRegionHint = kTransparentRegionHint; |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1447 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1448 | mLayer.outputLayerState.visibleRegion = Region(Rect(0, 0, 50, 200)); |
| 1449 | mLayer.outputLayerState.coveredRegion = Region(Rect(50, 0, 100, 200)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1450 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1451 | mGeomSnapshots.insert(mLayer.layerFE); |
| 1452 | } |
| 1453 | |
| 1454 | void ensureOutputLayerIfVisible() { |
| 1455 | sp<LayerFE> layerFE(mLayer.layerFE); |
| 1456 | mOutput.ensureOutputLayerIfVisible(layerFE, mCoverageState); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1457 | } |
| 1458 | |
| 1459 | static const Region kEmptyRegion; |
| 1460 | static const Region kFullBoundsNoRotation; |
| 1461 | static const Region kRightHalfBoundsNoRotation; |
| 1462 | static const Region kLowerHalfBoundsNoRotation; |
| 1463 | static const Region kFullBounds90Rotation; |
Leon Scroggins III | 9a0afda | 2022-01-11 16:53:09 -0500 | [diff] [blame] | 1464 | static const Region kTransparentRegionHint; |
Leon Scroggins III | 81aff79 | 2022-03-21 13:51:34 -0400 | [diff] [blame] | 1465 | static const Region kTransparentRegionHintTwo; |
| 1466 | static const Region kTransparentRegionHintTwo90Rotation; |
Alec Mouri | e60f0b9 | 2022-06-10 19:15:20 +0000 | [diff] [blame] | 1467 | static const Region kTransparentRegionHintNegative; |
| 1468 | static const Region kTransparentRegionHintNegativeIntersectsBounds; |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1469 | |
| 1470 | StrictMock<OutputPartialMock> mOutput; |
| 1471 | LayerFESet mGeomSnapshots; |
| 1472 | Output::CoverageState mCoverageState{mGeomSnapshots}; |
| 1473 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1474 | NonInjectedLayer mLayer; |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1475 | }; |
| 1476 | |
| 1477 | const Region OutputEnsureOutputLayerIfVisibleTest::kEmptyRegion = Region(Rect(0, 0, 0, 0)); |
| 1478 | const Region OutputEnsureOutputLayerIfVisibleTest::kFullBoundsNoRotation = |
| 1479 | Region(Rect(0, 0, 100, 200)); |
| 1480 | const Region OutputEnsureOutputLayerIfVisibleTest::kRightHalfBoundsNoRotation = |
| 1481 | Region(Rect(0, 100, 100, 200)); |
| 1482 | const Region OutputEnsureOutputLayerIfVisibleTest::kLowerHalfBoundsNoRotation = |
| 1483 | Region(Rect(50, 0, 100, 200)); |
| 1484 | const Region OutputEnsureOutputLayerIfVisibleTest::kFullBounds90Rotation = |
| 1485 | Region(Rect(0, 0, 200, 100)); |
Leon Scroggins III | 9a0afda | 2022-01-11 16:53:09 -0500 | [diff] [blame] | 1486 | const Region OutputEnsureOutputLayerIfVisibleTest::kTransparentRegionHint = |
Leon Scroggins III | 81aff79 | 2022-03-21 13:51:34 -0400 | [diff] [blame] | 1487 | Region(Rect(0, 0, 100, 100)); |
| 1488 | const Region OutputEnsureOutputLayerIfVisibleTest::kTransparentRegionHintTwo = |
Leon Scroggins III | 7f7ad2c | 2022-03-17 17:06:20 -0400 | [diff] [blame] | 1489 | Region(Rect(25, 20, 50, 75)); |
Leon Scroggins III | 81aff79 | 2022-03-21 13:51:34 -0400 | [diff] [blame] | 1490 | const Region OutputEnsureOutputLayerIfVisibleTest::kTransparentRegionHintTwo90Rotation = |
Leon Scroggins III | 7f7ad2c | 2022-03-17 17:06:20 -0400 | [diff] [blame] | 1491 | Region(Rect(125, 25, 180, 50)); |
Alec Mouri | e60f0b9 | 2022-06-10 19:15:20 +0000 | [diff] [blame] | 1492 | const Region OutputEnsureOutputLayerIfVisibleTest::kTransparentRegionHintNegative = |
| 1493 | Region(Rect(INT32_MIN, INT32_MIN, INT32_MIN + 100, INT32_MIN + 200)); |
| 1494 | const Region OutputEnsureOutputLayerIfVisibleTest::kTransparentRegionHintNegativeIntersectsBounds = |
| 1495 | Region(Rect(INT32_MIN, INT32_MIN, 100, 100)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1496 | |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 1497 | TEST_F(OutputEnsureOutputLayerIfVisibleTest, performsGeomLatchBeforeCheckingIfLayerIncluded) { |
| 1498 | EXPECT_CALL(mOutput, includesLayer(sp<LayerFE>(mLayer.layerFE))).WillOnce(Return(false)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1499 | mGeomSnapshots.clear(); |
| 1500 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1501 | ensureOutputLayerIfVisible(); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1502 | } |
| 1503 | |
| 1504 | TEST_F(OutputEnsureOutputLayerIfVisibleTest, |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 1505 | skipsLatchIfAlreadyLatchedBeforeCheckingIfLayerIncluded) { |
| 1506 | EXPECT_CALL(mOutput, includesLayer(sp<LayerFE>(mLayer.layerFE))).WillOnce(Return(false)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1507 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1508 | ensureOutputLayerIfVisible(); |
| 1509 | } |
| 1510 | |
| 1511 | TEST_F(OutputEnsureOutputLayerIfVisibleTest, takesEarlyOutIfLayerHasNoCompositionState) { |
| 1512 | EXPECT_CALL(*mLayer.layerFE, getCompositionState()).WillOnce(Return(nullptr)); |
| 1513 | |
| 1514 | ensureOutputLayerIfVisible(); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1515 | } |
| 1516 | |
| 1517 | TEST_F(OutputEnsureOutputLayerIfVisibleTest, takesEarlyOutIfLayerNotVisible) { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1518 | mLayer.layerFEState.isVisible = false; |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1519 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1520 | ensureOutputLayerIfVisible(); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1521 | } |
| 1522 | |
| 1523 | TEST_F(OutputEnsureOutputLayerIfVisibleTest, takesEarlyOutIfLayerHasEmptyVisibleRegion) { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1524 | mLayer.layerFEState.geomLayerBounds = FloatRect{0, 0, 0, 0}; |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1525 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1526 | ensureOutputLayerIfVisible(); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1527 | } |
| 1528 | |
Marin Shalamanov | e67fcd0 | 2020-07-01 13:25:38 +0000 | [diff] [blame] | 1529 | TEST_F(OutputEnsureOutputLayerIfVisibleTest, takesNotSoEarlyOutifDrawRegionEmpty) { |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 1530 | mOutput.mState.displaySpace.setBounds(ui::Size(0, 0)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1531 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1532 | ensureOutputLayerIfVisible(); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1533 | } |
| 1534 | |
| 1535 | TEST_F(OutputEnsureOutputLayerIfVisibleTest, |
| 1536 | handlesCreatingOutputLayerForOpaqueDirtyNotRotatedLayer) { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1537 | mLayer.layerFEState.isOpaque = true; |
| 1538 | mLayer.layerFEState.contentDirty = true; |
| 1539 | mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1540 | |
| 1541 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u)); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1542 | EXPECT_CALL(mOutput, ensureOutputLayer(Eq(std::nullopt), Eq(mLayer.layerFE))) |
| 1543 | .WillOnce(Return(&mLayer.outputLayer)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1544 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1545 | ensureOutputLayerIfVisible(); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1546 | |
| 1547 | EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation)); |
| 1548 | EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation)); |
| 1549 | EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation)); |
| 1550 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1551 | EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation)); |
| 1552 | EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion, |
| 1553 | RegionEq(kFullBoundsNoRotation)); |
| 1554 | EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion)); |
| 1555 | EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1556 | } |
| 1557 | |
| 1558 | TEST_F(OutputEnsureOutputLayerIfVisibleTest, |
| 1559 | handlesUpdatingOutputLayerForOpaqueDirtyNotRotatedLayer) { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1560 | mLayer.layerFEState.isOpaque = true; |
| 1561 | mLayer.layerFEState.contentDirty = true; |
| 1562 | mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1563 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1564 | EXPECT_CALL(mOutput, ensureOutputLayer(Eq(0u), Eq(mLayer.layerFE))) |
| 1565 | .WillOnce(Return(&mLayer.outputLayer)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1566 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1567 | ensureOutputLayerIfVisible(); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1568 | |
| 1569 | EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation)); |
| 1570 | EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation)); |
| 1571 | EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation)); |
| 1572 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1573 | EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation)); |
| 1574 | EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion, |
| 1575 | RegionEq(kFullBoundsNoRotation)); |
| 1576 | EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion)); |
| 1577 | EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1578 | } |
| 1579 | |
| 1580 | TEST_F(OutputEnsureOutputLayerIfVisibleTest, |
| 1581 | handlesCreatingOutputLayerForTransparentDirtyNotRotatedLayer) { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1582 | mLayer.layerFEState.isOpaque = false; |
| 1583 | mLayer.layerFEState.contentDirty = true; |
| 1584 | mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1585 | |
| 1586 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u)); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1587 | EXPECT_CALL(mOutput, ensureOutputLayer(Eq(std::nullopt), Eq(mLayer.layerFE))) |
| 1588 | .WillOnce(Return(&mLayer.outputLayer)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1589 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1590 | ensureOutputLayerIfVisible(); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1591 | |
| 1592 | EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation)); |
| 1593 | EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation)); |
| 1594 | EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kEmptyRegion)); |
| 1595 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1596 | EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation)); |
| 1597 | EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion, |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1598 | RegionEq(kRightHalfBoundsNoRotation)); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1599 | EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion)); |
| 1600 | EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1601 | } |
| 1602 | |
| 1603 | TEST_F(OutputEnsureOutputLayerIfVisibleTest, |
| 1604 | handlesUpdatingOutputLayerForTransparentDirtyNotRotatedLayer) { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1605 | mLayer.layerFEState.isOpaque = false; |
| 1606 | mLayer.layerFEState.contentDirty = true; |
| 1607 | mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1608 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1609 | EXPECT_CALL(mOutput, ensureOutputLayer(Eq(0u), Eq(mLayer.layerFE))) |
| 1610 | .WillOnce(Return(&mLayer.outputLayer)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1611 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1612 | ensureOutputLayerIfVisible(); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1613 | |
| 1614 | EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation)); |
| 1615 | EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation)); |
| 1616 | EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kEmptyRegion)); |
| 1617 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1618 | EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation)); |
| 1619 | EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion, |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1620 | RegionEq(kRightHalfBoundsNoRotation)); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1621 | EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion)); |
| 1622 | EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1623 | } |
| 1624 | |
| 1625 | TEST_F(OutputEnsureOutputLayerIfVisibleTest, |
| 1626 | handlesCreatingOutputLayerForOpaqueNonDirtyNotRotatedLayer) { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1627 | mLayer.layerFEState.isOpaque = true; |
| 1628 | mLayer.layerFEState.contentDirty = false; |
| 1629 | mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1630 | |
| 1631 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u)); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1632 | EXPECT_CALL(mOutput, ensureOutputLayer(Eq(std::nullopt), Eq(mLayer.layerFE))) |
| 1633 | .WillOnce(Return(&mLayer.outputLayer)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1634 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1635 | ensureOutputLayerIfVisible(); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1636 | |
| 1637 | EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation)); |
| 1638 | EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation)); |
| 1639 | EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation)); |
| 1640 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1641 | EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation)); |
| 1642 | EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion, |
| 1643 | RegionEq(kFullBoundsNoRotation)); |
| 1644 | EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion)); |
| 1645 | EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1646 | } |
| 1647 | |
| 1648 | TEST_F(OutputEnsureOutputLayerIfVisibleTest, |
| 1649 | handlesUpdatingOutputLayerForOpaqueNonDirtyNotRotatedLayer) { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1650 | mLayer.layerFEState.isOpaque = true; |
| 1651 | mLayer.layerFEState.contentDirty = false; |
| 1652 | mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1653 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1654 | EXPECT_CALL(mOutput, ensureOutputLayer(Eq(0u), Eq(mLayer.layerFE))) |
| 1655 | .WillOnce(Return(&mLayer.outputLayer)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1656 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1657 | ensureOutputLayerIfVisible(); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1658 | |
| 1659 | EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kLowerHalfBoundsNoRotation)); |
| 1660 | EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation)); |
| 1661 | EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation)); |
| 1662 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1663 | EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation)); |
| 1664 | EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion, |
| 1665 | RegionEq(kFullBoundsNoRotation)); |
| 1666 | EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion)); |
| 1667 | EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1668 | } |
| 1669 | |
| 1670 | TEST_F(OutputEnsureOutputLayerIfVisibleTest, |
| 1671 | handlesCreatingOutputLayerForOpaqueDirtyRotated90Layer) { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1672 | mLayer.layerFEState.isOpaque = true; |
| 1673 | mLayer.layerFEState.contentDirty = true; |
| 1674 | mLayer.layerFEState.geomLayerBounds = FloatRect{0, 0, 200, 100}; |
| 1675 | mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_ROT_90, 100, 200); |
| 1676 | mLayer.outputLayerState.visibleRegion = Region(Rect(0, 0, 100, 100)); |
| 1677 | mLayer.outputLayerState.coveredRegion = Region(Rect(100, 0, 200, 100)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1678 | |
| 1679 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u)); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1680 | EXPECT_CALL(mOutput, ensureOutputLayer(Eq(std::nullopt), Eq(mLayer.layerFE))) |
| 1681 | .WillOnce(Return(&mLayer.outputLayer)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1682 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1683 | ensureOutputLayerIfVisible(); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1684 | |
| 1685 | EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation)); |
| 1686 | EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation)); |
| 1687 | EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation)); |
| 1688 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1689 | EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation)); |
| 1690 | EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion, |
| 1691 | RegionEq(kFullBoundsNoRotation)); |
| 1692 | EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion)); |
| 1693 | EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1694 | } |
| 1695 | |
| 1696 | TEST_F(OutputEnsureOutputLayerIfVisibleTest, |
| 1697 | handlesUpdatingOutputLayerForOpaqueDirtyRotated90Layer) { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1698 | mLayer.layerFEState.isOpaque = true; |
| 1699 | mLayer.layerFEState.contentDirty = true; |
| 1700 | mLayer.layerFEState.geomLayerBounds = FloatRect{0, 0, 200, 100}; |
| 1701 | mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_ROT_90, 100, 200); |
| 1702 | mLayer.outputLayerState.visibleRegion = Region(Rect(0, 0, 100, 100)); |
| 1703 | mLayer.outputLayerState.coveredRegion = Region(Rect(100, 0, 200, 100)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1704 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1705 | EXPECT_CALL(mOutput, ensureOutputLayer(Eq(0u), Eq(mLayer.layerFE))) |
| 1706 | .WillOnce(Return(&mLayer.outputLayer)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1707 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1708 | ensureOutputLayerIfVisible(); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1709 | |
| 1710 | EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation)); |
| 1711 | EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation)); |
| 1712 | EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation)); |
| 1713 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1714 | EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation)); |
| 1715 | EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion, |
| 1716 | RegionEq(kFullBoundsNoRotation)); |
| 1717 | EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion)); |
| 1718 | EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1719 | } |
| 1720 | |
| 1721 | TEST_F(OutputEnsureOutputLayerIfVisibleTest, |
| 1722 | handlesCreatingOutputLayerForOpaqueDirtyNotRotatedLayerRotatedOutput) { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1723 | mLayer.layerFEState.isOpaque = true; |
| 1724 | mLayer.layerFEState.contentDirty = true; |
| 1725 | mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1726 | |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 1727 | mOutput.mState.layerStackSpace.setContent(Rect(0, 0, 300, 200)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1728 | mOutput.mState.transform = ui::Transform(TR_ROT_90, 200, 300); |
| 1729 | |
| 1730 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u)); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1731 | EXPECT_CALL(mOutput, ensureOutputLayer(Eq(std::nullopt), Eq(mLayer.layerFE))) |
| 1732 | .WillOnce(Return(&mLayer.outputLayer)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1733 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1734 | ensureOutputLayerIfVisible(); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1735 | |
| 1736 | EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation)); |
| 1737 | EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation)); |
| 1738 | EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation)); |
| 1739 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1740 | EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation)); |
| 1741 | EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion, |
| 1742 | RegionEq(kFullBoundsNoRotation)); |
| 1743 | EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion)); |
| 1744 | EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBounds90Rotation)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1745 | } |
| 1746 | |
| 1747 | TEST_F(OutputEnsureOutputLayerIfVisibleTest, |
| 1748 | handlesUpdatingOutputLayerForOpaqueDirtyNotRotatedLayerRotatedOutput) { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1749 | mLayer.layerFEState.isOpaque = true; |
| 1750 | mLayer.layerFEState.contentDirty = true; |
| 1751 | mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1752 | |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 1753 | mOutput.mState.layerStackSpace.setContent(Rect(0, 0, 300, 200)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1754 | mOutput.mState.transform = ui::Transform(TR_ROT_90, 200, 300); |
| 1755 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1756 | EXPECT_CALL(mOutput, ensureOutputLayer(Eq(0u), Eq(mLayer.layerFE))) |
| 1757 | .WillOnce(Return(&mLayer.outputLayer)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1758 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1759 | ensureOutputLayerIfVisible(); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1760 | |
| 1761 | EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation)); |
| 1762 | EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation)); |
| 1763 | EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation)); |
| 1764 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1765 | EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation)); |
| 1766 | EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion, |
| 1767 | RegionEq(kFullBoundsNoRotation)); |
| 1768 | EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion)); |
| 1769 | EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBounds90Rotation)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1770 | } |
| 1771 | |
| 1772 | TEST_F(OutputEnsureOutputLayerIfVisibleTest, |
| 1773 | handlesCreatingOutputLayerForOpaqueDirtyArbitraryTransformLayer) { |
| 1774 | ui::Transform arbitraryTransform; |
| 1775 | arbitraryTransform.set(1, 1, -1, 1); |
| 1776 | arbitraryTransform.set(0, 100); |
| 1777 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1778 | mLayer.layerFEState.isOpaque = true; |
| 1779 | mLayer.layerFEState.contentDirty = true; |
| 1780 | mLayer.layerFEState.geomLayerBounds = FloatRect{0, 0, 100, 200}; |
| 1781 | mLayer.layerFEState.geomLayerTransform = arbitraryTransform; |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1782 | |
| 1783 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u)); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1784 | EXPECT_CALL(mOutput, ensureOutputLayer(Eq(std::nullopt), Eq(mLayer.layerFE))) |
| 1785 | .WillOnce(Return(&mLayer.outputLayer)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1786 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1787 | ensureOutputLayerIfVisible(); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1788 | |
| 1789 | const Region kRegion = Region(Rect(0, 0, 300, 300)); |
| 1790 | const Region kRegionClipped = Region(Rect(0, 0, 200, 300)); |
| 1791 | |
| 1792 | EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kRegion)); |
| 1793 | EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kRegion)); |
| 1794 | EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kEmptyRegion)); |
| 1795 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1796 | EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kRegion)); |
| 1797 | EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion, RegionEq(kRegion)); |
| 1798 | EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion)); |
| 1799 | EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kRegionClipped)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1800 | } |
| 1801 | |
| 1802 | TEST_F(OutputEnsureOutputLayerIfVisibleTest, coverageAccumulatesTest) { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1803 | mLayer.layerFEState.isOpaque = false; |
| 1804 | mLayer.layerFEState.contentDirty = true; |
| 1805 | mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1806 | |
| 1807 | mCoverageState.dirtyRegion = Region(Rect(0, 0, 500, 500)); |
| 1808 | mCoverageState.aboveCoveredLayers = Region(Rect(50, 0, 150, 200)); |
| 1809 | mCoverageState.aboveOpaqueLayers = Region(Rect(50, 0, 150, 200)); |
| 1810 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1811 | EXPECT_CALL(mOutput, ensureOutputLayer(Eq(0u), Eq(mLayer.layerFE))) |
| 1812 | .WillOnce(Return(&mLayer.outputLayer)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1813 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1814 | ensureOutputLayerIfVisible(); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1815 | |
| 1816 | const Region kExpectedDirtyRegion = Region(Rect(0, 0, 500, 500)); |
| 1817 | const Region kExpectedAboveCoveredRegion = Region(Rect(0, 0, 150, 200)); |
| 1818 | const Region kExpectedAboveOpaqueRegion = Region(Rect(50, 0, 150, 200)); |
| 1819 | const Region kExpectedLayerVisibleRegion = Region(Rect(0, 0, 50, 200)); |
| 1820 | const Region kExpectedLayerCoveredRegion = Region(Rect(50, 0, 100, 200)); |
| 1821 | const Region kExpectedLayerVisibleNonTransparentRegion = Region(Rect(0, 100, 50, 200)); |
| 1822 | |
| 1823 | EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kExpectedDirtyRegion)); |
| 1824 | EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kExpectedAboveCoveredRegion)); |
| 1825 | EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kExpectedAboveOpaqueRegion)); |
| 1826 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1827 | EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kExpectedLayerVisibleRegion)); |
| 1828 | EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion, |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1829 | RegionEq(kExpectedLayerVisibleNonTransparentRegion)); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1830 | EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kExpectedLayerCoveredRegion)); |
| 1831 | EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, |
| 1832 | RegionEq(kExpectedLayerVisibleRegion)); |
Lloyd Pique | fe0ee9e | 2019-11-22 16:30:30 -0800 | [diff] [blame] | 1833 | } |
Lloyd Pique | b62cebc | 2019-11-20 18:31:52 -0800 | [diff] [blame] | 1834 | |
Vishnu Nair | a483b4a | 2019-12-12 15:07:52 -0800 | [diff] [blame] | 1835 | TEST_F(OutputEnsureOutputLayerIfVisibleTest, coverageAccumulatesWithShadowsTest) { |
| 1836 | ui::Transform translate; |
| 1837 | translate.set(50, 50); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1838 | mLayer.layerFEState.geomLayerTransform = translate; |
Vishnu Nair | d9e4f46 | 2023-10-06 04:05:45 +0000 | [diff] [blame] | 1839 | mLayer.layerFEState.shadowSettings.length = 10.0f; |
Vishnu Nair | a483b4a | 2019-12-12 15:07:52 -0800 | [diff] [blame] | 1840 | |
| 1841 | mCoverageState.dirtyRegion = Region(Rect(0, 0, 500, 500)); |
| 1842 | // half of the layer including the casting shadow is covered and opaque |
| 1843 | mCoverageState.aboveCoveredLayers = Region(Rect(40, 40, 100, 260)); |
| 1844 | mCoverageState.aboveOpaqueLayers = Region(Rect(40, 40, 100, 260)); |
| 1845 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1846 | EXPECT_CALL(mOutput, ensureOutputLayer(Eq(0u), Eq(mLayer.layerFE))) |
| 1847 | .WillOnce(Return(&mLayer.outputLayer)); |
Vishnu Nair | a483b4a | 2019-12-12 15:07:52 -0800 | [diff] [blame] | 1848 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1849 | ensureOutputLayerIfVisible(); |
Vishnu Nair | a483b4a | 2019-12-12 15:07:52 -0800 | [diff] [blame] | 1850 | |
| 1851 | const Region kExpectedDirtyRegion = Region(Rect(0, 0, 500, 500)); |
| 1852 | const Region kExpectedAboveCoveredRegion = Region(Rect(40, 40, 160, 260)); |
| 1853 | // add starting opaque region to the opaque half of the casting layer bounds |
| 1854 | const Region kExpectedAboveOpaqueRegion = |
| 1855 | Region(Rect(40, 40, 100, 260)).orSelf(Rect(100, 50, 150, 250)); |
| 1856 | const Region kExpectedLayerVisibleRegion = Region(Rect(100, 40, 160, 260)); |
| 1857 | const Region kExpectedoutputSpaceLayerVisibleRegion = Region(Rect(100, 50, 150, 250)); |
| 1858 | const Region kExpectedLayerCoveredRegion = Region(Rect(40, 40, 100, 260)); |
| 1859 | const Region kExpectedLayerVisibleNonTransparentRegion = Region(Rect(100, 40, 160, 260)); |
| 1860 | const Region kExpectedLayerShadowRegion = |
| 1861 | Region(Rect(40, 40, 160, 260)).subtractSelf(Rect(50, 50, 150, 250)); |
| 1862 | |
| 1863 | EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kExpectedDirtyRegion)); |
| 1864 | EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kExpectedAboveCoveredRegion)); |
| 1865 | EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kExpectedAboveOpaqueRegion)); |
| 1866 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1867 | EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kExpectedLayerVisibleRegion)); |
| 1868 | EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion, |
Vishnu Nair | a483b4a | 2019-12-12 15:07:52 -0800 | [diff] [blame] | 1869 | RegionEq(kExpectedLayerVisibleNonTransparentRegion)); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1870 | EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kExpectedLayerCoveredRegion)); |
| 1871 | EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, |
Vishnu Nair | a483b4a | 2019-12-12 15:07:52 -0800 | [diff] [blame] | 1872 | RegionEq(kExpectedoutputSpaceLayerVisibleRegion)); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1873 | EXPECT_THAT(mLayer.outputLayerState.shadowRegion, RegionEq(kExpectedLayerShadowRegion)); |
Vishnu Nair | a483b4a | 2019-12-12 15:07:52 -0800 | [diff] [blame] | 1874 | EXPECT_FALSE(kExpectedLayerVisibleRegion.subtract(kExpectedLayerShadowRegion).isEmpty()); |
| 1875 | } |
| 1876 | |
| 1877 | TEST_F(OutputEnsureOutputLayerIfVisibleTest, shadowRegionOnlyTest) { |
| 1878 | ui::Transform translate; |
| 1879 | translate.set(50, 50); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1880 | mLayer.layerFEState.geomLayerTransform = translate; |
Vishnu Nair | d9e4f46 | 2023-10-06 04:05:45 +0000 | [diff] [blame] | 1881 | mLayer.layerFEState.shadowSettings.length = 10.0f; |
Vishnu Nair | a483b4a | 2019-12-12 15:07:52 -0800 | [diff] [blame] | 1882 | |
| 1883 | mCoverageState.dirtyRegion = Region(Rect(0, 0, 500, 500)); |
| 1884 | // Casting layer is covered by an opaque region leaving only part of its shadow to be drawn |
| 1885 | mCoverageState.aboveCoveredLayers = Region(Rect(40, 40, 150, 260)); |
| 1886 | mCoverageState.aboveOpaqueLayers = Region(Rect(40, 40, 150, 260)); |
| 1887 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1888 | EXPECT_CALL(mOutput, ensureOutputLayer(Eq(0u), Eq(mLayer.layerFE))) |
| 1889 | .WillOnce(Return(&mLayer.outputLayer)); |
Vishnu Nair | a483b4a | 2019-12-12 15:07:52 -0800 | [diff] [blame] | 1890 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1891 | ensureOutputLayerIfVisible(); |
Vishnu Nair | a483b4a | 2019-12-12 15:07:52 -0800 | [diff] [blame] | 1892 | |
| 1893 | const Region kExpectedLayerVisibleRegion = Region(Rect(150, 40, 160, 260)); |
| 1894 | const Region kExpectedLayerShadowRegion = |
| 1895 | Region(Rect(40, 40, 160, 260)).subtractSelf(Rect(50, 50, 150, 250)); |
| 1896 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1897 | EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kExpectedLayerVisibleRegion)); |
| 1898 | EXPECT_THAT(mLayer.outputLayerState.shadowRegion, RegionEq(kExpectedLayerShadowRegion)); |
Vishnu Nair | a483b4a | 2019-12-12 15:07:52 -0800 | [diff] [blame] | 1899 | EXPECT_TRUE(kExpectedLayerVisibleRegion.subtract(kExpectedLayerShadowRegion).isEmpty()); |
| 1900 | } |
| 1901 | |
Marin Shalamanov | e67fcd0 | 2020-07-01 13:25:38 +0000 | [diff] [blame] | 1902 | TEST_F(OutputEnsureOutputLayerIfVisibleTest, takesNotSoEarlyOutifLayerWithShadowIsCovered) { |
Vishnu Nair | a483b4a | 2019-12-12 15:07:52 -0800 | [diff] [blame] | 1903 | ui::Transform translate; |
| 1904 | translate.set(50, 50); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1905 | mLayer.layerFEState.geomLayerTransform = translate; |
Vishnu Nair | d9e4f46 | 2023-10-06 04:05:45 +0000 | [diff] [blame] | 1906 | mLayer.layerFEState.shadowSettings.length = 10.0f; |
Vishnu Nair | a483b4a | 2019-12-12 15:07:52 -0800 | [diff] [blame] | 1907 | |
| 1908 | mCoverageState.dirtyRegion = Region(Rect(0, 0, 500, 500)); |
| 1909 | // Casting layer and its shadows are covered by an opaque region |
| 1910 | mCoverageState.aboveCoveredLayers = Region(Rect(40, 40, 160, 260)); |
| 1911 | mCoverageState.aboveOpaqueLayers = Region(Rect(40, 40, 160, 260)); |
| 1912 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1913 | ensureOutputLayerIfVisible(); |
Vishnu Nair | a483b4a | 2019-12-12 15:07:52 -0800 | [diff] [blame] | 1914 | } |
| 1915 | |
Leon Scroggins III | 9a0afda | 2022-01-11 16:53:09 -0500 | [diff] [blame] | 1916 | TEST_F(OutputEnsureOutputLayerIfVisibleTest, displayDecorSetsBlockingFromTransparentRegion) { |
| 1917 | mLayer.layerFEState.isOpaque = false; |
| 1918 | mLayer.layerFEState.contentDirty = true; |
| 1919 | mLayer.layerFEState.compositionType = |
| 1920 | aidl::android::hardware::graphics::composer3::Composition::DISPLAY_DECORATION; |
| 1921 | |
| 1922 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u)); |
| 1923 | EXPECT_CALL(mOutput, ensureOutputLayer(Eq(std::nullopt), Eq(mLayer.layerFE))) |
| 1924 | .WillOnce(Return(&mLayer.outputLayer)); |
| 1925 | ensureOutputLayerIfVisible(); |
| 1926 | |
| 1927 | EXPECT_THAT(mLayer.outputLayerState.outputSpaceBlockingRegionHint, |
| 1928 | RegionEq(kTransparentRegionHint)); |
| 1929 | } |
| 1930 | |
| 1931 | TEST_F(OutputEnsureOutputLayerIfVisibleTest, normalLayersDoNotSetBlockingRegion) { |
| 1932 | mLayer.layerFEState.isOpaque = false; |
| 1933 | mLayer.layerFEState.contentDirty = true; |
| 1934 | |
| 1935 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u)); |
| 1936 | EXPECT_CALL(mOutput, ensureOutputLayer(Eq(std::nullopt), Eq(mLayer.layerFE))) |
| 1937 | .WillOnce(Return(&mLayer.outputLayer)); |
| 1938 | ensureOutputLayerIfVisible(); |
| 1939 | |
| 1940 | EXPECT_THAT(mLayer.outputLayerState.outputSpaceBlockingRegionHint, RegionEq(Region())); |
| 1941 | } |
| 1942 | |
Leon Scroggins III | 7f7ad2c | 2022-03-17 17:06:20 -0400 | [diff] [blame] | 1943 | TEST_F(OutputEnsureOutputLayerIfVisibleTest, blockingRegionIsInOutputSpace) { |
| 1944 | mLayer.layerFEState.isOpaque = false; |
| 1945 | mLayer.layerFEState.contentDirty = true; |
| 1946 | mLayer.layerFEState.compositionType = |
| 1947 | aidl::android::hardware::graphics::composer3::Composition::DISPLAY_DECORATION; |
Leon Scroggins III | 81aff79 | 2022-03-21 13:51:34 -0400 | [diff] [blame] | 1948 | mLayer.layerFEState.transparentRegionHint = kTransparentRegionHintTwo; |
Leon Scroggins III | 7f7ad2c | 2022-03-17 17:06:20 -0400 | [diff] [blame] | 1949 | |
| 1950 | mOutput.mState.layerStackSpace.setContent(Rect(0, 0, 300, 200)); |
| 1951 | mOutput.mState.transform = ui::Transform(TR_ROT_90, 200, 300); |
| 1952 | |
| 1953 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u)); |
| 1954 | EXPECT_CALL(mOutput, ensureOutputLayer(Eq(std::nullopt), Eq(mLayer.layerFE))) |
| 1955 | .WillOnce(Return(&mLayer.outputLayer)); |
| 1956 | ensureOutputLayerIfVisible(); |
| 1957 | |
| 1958 | EXPECT_THAT(mLayer.outputLayerState.outputSpaceBlockingRegionHint, |
Leon Scroggins III | 81aff79 | 2022-03-21 13:51:34 -0400 | [diff] [blame] | 1959 | RegionEq(kTransparentRegionHintTwo90Rotation)); |
Leon Scroggins III | 7f7ad2c | 2022-03-17 17:06:20 -0400 | [diff] [blame] | 1960 | } |
| 1961 | |
Alec Mouri | e60f0b9 | 2022-06-10 19:15:20 +0000 | [diff] [blame] | 1962 | TEST_F(OutputEnsureOutputLayerIfVisibleTest, transparentRegionExcludesOutputLayer) { |
| 1963 | mLayer.layerFEState.isOpaque = false; |
| 1964 | mLayer.layerFEState.contentDirty = true; |
| 1965 | mLayer.layerFEState.geomLayerBounds = kFullBoundsNoRotation.bounds().toFloatRect(); |
| 1966 | mLayer.layerFEState.transparentRegionHint = kFullBoundsNoRotation; |
| 1967 | |
| 1968 | EXPECT_CALL(mOutput, ensureOutputLayer(_, _)).Times(0); |
| 1969 | } |
| 1970 | |
| 1971 | TEST_F(OutputEnsureOutputLayerIfVisibleTest, transparentRegionIgnoredWhenOutsideBounds) { |
| 1972 | mLayer.layerFEState.isOpaque = false; |
| 1973 | mLayer.layerFEState.contentDirty = true; |
| 1974 | mLayer.layerFEState.geomLayerBounds = kFullBoundsNoRotation.bounds().toFloatRect(); |
| 1975 | mLayer.layerFEState.transparentRegionHint = kTransparentRegionHintNegative; |
| 1976 | |
| 1977 | EXPECT_CALL(mOutput, ensureOutputLayer(_, _)).Times(0); |
| 1978 | } |
| 1979 | |
| 1980 | TEST_F(OutputEnsureOutputLayerIfVisibleTest, transparentRegionClipsWhenOutsideBounds) { |
| 1981 | mLayer.layerFEState.isOpaque = false; |
| 1982 | mLayer.layerFEState.contentDirty = true; |
| 1983 | mLayer.layerFEState.compositionType = |
| 1984 | aidl::android::hardware::graphics::composer3::Composition::DISPLAY_DECORATION; |
| 1985 | mLayer.layerFEState.transparentRegionHint = kTransparentRegionHintNegativeIntersectsBounds; |
| 1986 | |
| 1987 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u)); |
| 1988 | EXPECT_CALL(mOutput, ensureOutputLayer(Eq(std::nullopt), Eq(mLayer.layerFE))) |
| 1989 | .WillOnce(Return(&mLayer.outputLayer)); |
| 1990 | ensureOutputLayerIfVisible(); |
| 1991 | |
| 1992 | // Check that the blocking region clips an out-of-bounds transparent region. |
| 1993 | EXPECT_THAT(mLayer.outputLayerState.outputSpaceBlockingRegionHint, |
| 1994 | RegionEq(kTransparentRegionHint)); |
| 1995 | } |
| 1996 | |
Lloyd Pique | b62cebc | 2019-11-20 18:31:52 -0800 | [diff] [blame] | 1997 | /* |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 1998 | * Output::present() |
| 1999 | */ |
| 2000 | |
| 2001 | struct OutputPresentTest : public testing::Test { |
| 2002 | struct OutputPartialMock : public OutputPartialMockBase { |
Lloyd Pique | 739afaf | 2019-11-21 16:40:05 -0800 | [diff] [blame] | 2003 | // Sets up the helper functions called by the function under test to use |
| 2004 | // mock implementations. |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 2005 | MOCK_METHOD1(updateColorProfile, void(const compositionengine::CompositionRefreshArgs&)); |
Dan Stoza | 269dc4d | 2021-01-15 15:07:43 -0800 | [diff] [blame] | 2006 | MOCK_METHOD1(updateCompositionState, |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 2007 | void(const compositionengine::CompositionRefreshArgs&)); |
Dan Stoza | 269dc4d | 2021-01-15 15:07:43 -0800 | [diff] [blame] | 2008 | MOCK_METHOD0(planComposition, void()); |
| 2009 | MOCK_METHOD1(writeCompositionState, void(const compositionengine::CompositionRefreshArgs&)); |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 2010 | MOCK_METHOD1(setColorTransform, void(const compositionengine::CompositionRefreshArgs&)); |
| 2011 | MOCK_METHOD0(beginFrame, void()); |
| 2012 | MOCK_METHOD0(prepareFrame, void()); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 2013 | MOCK_METHOD0(prepareFrameAsync, GpuCompositionResult()); |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 2014 | MOCK_METHOD1(devOptRepaintFlash, void(const compositionengine::CompositionRefreshArgs&)); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 2015 | MOCK_METHOD1(finishFrame, void(GpuCompositionResult&&)); |
Leon Scroggins III | a3ba7fa | 2024-05-22 16:34:52 -0400 | [diff] [blame] | 2016 | MOCK_METHOD(void, presentFrameAndReleaseLayers, (bool flushEvenWhenDisabled), (override)); |
Alec Mouri | aa83158 | 2021-06-07 16:23:01 -0700 | [diff] [blame] | 2017 | MOCK_METHOD1(renderCachedSets, void(const compositionengine::CompositionRefreshArgs&)); |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 2018 | MOCK_METHOD1(canPredictCompositionStrategy, bool(const CompositionRefreshArgs&)); |
Xiang Wang | aab3116 | 2024-03-12 19:48:08 -0700 | [diff] [blame] | 2019 | MOCK_METHOD(void, setHintSessionRequiresRenderEngine, (bool requiresRenderEngine), |
| 2020 | (override)); |
| 2021 | MOCK_METHOD(bool, isPowerHintSessionEnabled, (), (override)); |
Xiang Wang | cb50bbd | 2024-04-18 16:57:54 -0700 | [diff] [blame] | 2022 | MOCK_METHOD(bool, isPowerHintSessionGpuReportingEnabled, (), (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)); |
Xiang Wang | cb50bbd | 2024-04-18 16:57:54 -0700 | [diff] [blame] | 2027 | EXPECT_CALL(mOutput, isPowerHintSessionGpuReportingEnabled()).WillRepeatedly(Return(true)); |
Xiang Wang | aab3116 | 2024-03-12 19:48:08 -0700 | [diff] [blame] | 2028 | } |
| 2029 | |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 2030 | StrictMock<OutputPartialMock> mOutput; |
| 2031 | }; |
| 2032 | |
| 2033 | TEST_F(OutputPresentTest, justInvokesChildFunctionsInSequence) { |
| 2034 | CompositionRefreshArgs args; |
| 2035 | |
| 2036 | InSequence seq; |
| 2037 | EXPECT_CALL(mOutput, updateColorProfile(Ref(args))); |
Dan Stoza | 269dc4d | 2021-01-15 15:07:43 -0800 | [diff] [blame] | 2038 | EXPECT_CALL(mOutput, updateCompositionState(Ref(args))); |
| 2039 | EXPECT_CALL(mOutput, planComposition()); |
| 2040 | EXPECT_CALL(mOutput, writeCompositionState(Ref(args))); |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 2041 | EXPECT_CALL(mOutput, setColorTransform(Ref(args))); |
| 2042 | EXPECT_CALL(mOutput, beginFrame()); |
Xiang Wang | aab3116 | 2024-03-12 19:48:08 -0700 | [diff] [blame] | 2043 | EXPECT_CALL(mOutput, setHintSessionRequiresRenderEngine(false)); |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 2044 | EXPECT_CALL(mOutput, canPredictCompositionStrategy(Ref(args))).WillOnce(Return(false)); |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 2045 | EXPECT_CALL(mOutput, prepareFrame()); |
| 2046 | EXPECT_CALL(mOutput, devOptRepaintFlash(Ref(args))); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 2047 | EXPECT_CALL(mOutput, finishFrame(_)); |
Leon Scroggins III | a3ba7fa | 2024-05-22 16:34:52 -0400 | [diff] [blame] | 2048 | EXPECT_CALL(mOutput, presentFrameAndReleaseLayers(false)); |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 2049 | EXPECT_CALL(mOutput, renderCachedSets(Ref(args))); |
| 2050 | |
| 2051 | mOutput.present(args); |
| 2052 | } |
| 2053 | |
| 2054 | TEST_F(OutputPresentTest, predictingCompositionStrategyInvokesPrepareFrameAsync) { |
| 2055 | CompositionRefreshArgs args; |
| 2056 | |
| 2057 | InSequence seq; |
| 2058 | EXPECT_CALL(mOutput, updateColorProfile(Ref(args))); |
| 2059 | EXPECT_CALL(mOutput, updateCompositionState(Ref(args))); |
| 2060 | EXPECT_CALL(mOutput, planComposition()); |
| 2061 | EXPECT_CALL(mOutput, writeCompositionState(Ref(args))); |
| 2062 | EXPECT_CALL(mOutput, setColorTransform(Ref(args))); |
| 2063 | EXPECT_CALL(mOutput, beginFrame()); |
Xiang Wang | aab3116 | 2024-03-12 19:48:08 -0700 | [diff] [blame] | 2064 | EXPECT_CALL(mOutput, setHintSessionRequiresRenderEngine(false)); |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 2065 | EXPECT_CALL(mOutput, canPredictCompositionStrategy(Ref(args))).WillOnce(Return(true)); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 2066 | EXPECT_CALL(mOutput, prepareFrameAsync()); |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 2067 | EXPECT_CALL(mOutput, devOptRepaintFlash(Ref(args))); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 2068 | EXPECT_CALL(mOutput, finishFrame(_)); |
Leon Scroggins III | a3ba7fa | 2024-05-22 16:34:52 -0400 | [diff] [blame] | 2069 | EXPECT_CALL(mOutput, presentFrameAndReleaseLayers(false)); |
Alec Mouri | aa83158 | 2021-06-07 16:23:01 -0700 | [diff] [blame] | 2070 | EXPECT_CALL(mOutput, renderCachedSets(Ref(args))); |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 2071 | |
| 2072 | mOutput.present(args); |
| 2073 | } |
| 2074 | |
| 2075 | /* |
| 2076 | * Output::updateColorProfile() |
| 2077 | */ |
| 2078 | |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 2079 | struct OutputUpdateColorProfileTest : public testing::Test { |
| 2080 | using TestType = OutputUpdateColorProfileTest; |
| 2081 | |
| 2082 | struct OutputPartialMock : public OutputPartialMockBase { |
Lloyd Pique | 739afaf | 2019-11-21 16:40:05 -0800 | [diff] [blame] | 2083 | // Sets up the helper functions called by the function under test to use |
| 2084 | // mock implementations. |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 2085 | MOCK_METHOD1(setColorProfile, void(const ColorProfile&)); |
| 2086 | }; |
| 2087 | |
| 2088 | struct Layer { |
| 2089 | Layer() { |
Ady Abraham | eca9d75 | 2021-03-03 12:20:00 -0800 | [diff] [blame] | 2090 | EXPECT_CALL(mOutputLayer, getLayerFE()).WillRepeatedly(ReturnRef(*mLayerFE)); |
| 2091 | EXPECT_CALL(*mLayerFE, getCompositionState()).WillRepeatedly(Return(&mLayerFEState)); |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 2092 | } |
| 2093 | |
| 2094 | StrictMock<mock::OutputLayer> mOutputLayer; |
Ady Abraham | eca9d75 | 2021-03-03 12:20:00 -0800 | [diff] [blame] | 2095 | sp<StrictMock<mock::LayerFE>> mLayerFE = sp<StrictMock<mock::LayerFE>>::make(); |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 2096 | LayerFECompositionState mLayerFEState; |
| 2097 | }; |
| 2098 | |
| 2099 | OutputUpdateColorProfileTest() { |
| 2100 | mOutput.setDisplayColorProfileForTest( |
| 2101 | std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile)); |
| 2102 | mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface)); |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 2103 | mOutput.editState().isEnabled = true; |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 2104 | |
| 2105 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0)) |
| 2106 | .WillRepeatedly(Return(&mLayer1.mOutputLayer)); |
| 2107 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(1)) |
| 2108 | .WillRepeatedly(Return(&mLayer2.mOutputLayer)); |
| 2109 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(2)) |
| 2110 | .WillRepeatedly(Return(&mLayer3.mOutputLayer)); |
| 2111 | } |
| 2112 | |
| 2113 | struct ExecuteState : public CallOrderStateMachineHelper<TestType, ExecuteState> { |
| 2114 | void execute() { getInstance()->mOutput.updateColorProfile(getInstance()->mRefreshArgs); } |
| 2115 | }; |
| 2116 | |
| 2117 | mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>(); |
| 2118 | mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>(); |
| 2119 | StrictMock<OutputPartialMock> mOutput; |
| 2120 | |
| 2121 | Layer mLayer1; |
| 2122 | Layer mLayer2; |
| 2123 | Layer mLayer3; |
| 2124 | |
| 2125 | CompositionRefreshArgs mRefreshArgs; |
| 2126 | }; |
| 2127 | |
| 2128 | // TODO(b/144522012): Refactor Output::updateColorProfile and the related code |
| 2129 | // to make it easier to write unit tests. |
| 2130 | |
| 2131 | TEST_F(OutputUpdateColorProfileTest, setsAColorProfileWhenUnmanaged) { |
| 2132 | // When the outputColorSetting is set to kUnmanaged, the implementation sets |
| 2133 | // a simple default color profile without looking at anything else. |
| 2134 | |
Lloyd Pique | 0a45623 | 2020-01-16 17:51:13 -0800 | [diff] [blame] | 2135 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(3u)); |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 2136 | EXPECT_CALL(mOutput, |
Alec Mouri | 88790f3 | 2023-07-21 01:25:14 +0000 | [diff] [blame] | 2137 | setColorProfile( |
| 2138 | ColorProfileEq(ColorProfile{ui::ColorMode::NATIVE, ui::Dataspace::UNKNOWN, |
| 2139 | ui::RenderIntent::COLORIMETRIC}))); |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 2140 | |
| 2141 | mRefreshArgs.outputColorSetting = OutputColorSetting::kUnmanaged; |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 2142 | |
| 2143 | mOutput.updateColorProfile(mRefreshArgs); |
| 2144 | } |
| 2145 | |
| 2146 | struct OutputUpdateColorProfileTest_GetBestColorModeResultBecomesSetProfile |
| 2147 | : public OutputUpdateColorProfileTest { |
| 2148 | OutputUpdateColorProfileTest_GetBestColorModeResultBecomesSetProfile() { |
Lloyd Pique | 0a45623 | 2020-01-16 17:51:13 -0800 | [diff] [blame] | 2149 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(0u)); |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 2150 | mRefreshArgs.outputColorSetting = OutputColorSetting::kEnhanced; |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 2151 | } |
| 2152 | |
| 2153 | struct ExpectBestColorModeCallResultUsedToSetColorProfileState |
| 2154 | : public CallOrderStateMachineHelper< |
| 2155 | TestType, ExpectBestColorModeCallResultUsedToSetColorProfileState> { |
| 2156 | [[nodiscard]] auto expectBestColorModeCallResultUsedToSetColorProfile( |
| 2157 | ui::ColorMode colorMode, ui::Dataspace dataspace, ui::RenderIntent renderIntent) { |
| 2158 | EXPECT_CALL(*getInstance()->mDisplayColorProfile, |
| 2159 | getBestColorMode(ui::Dataspace::V0_SRGB, ui::RenderIntent::ENHANCE, _, _, |
| 2160 | _)) |
| 2161 | .WillOnce(DoAll(SetArgPointee<2>(dataspace), SetArgPointee<3>(colorMode), |
| 2162 | SetArgPointee<4>(renderIntent))); |
| 2163 | EXPECT_CALL(getInstance()->mOutput, |
| 2164 | setColorProfile( |
Alec Mouri | 88790f3 | 2023-07-21 01:25:14 +0000 | [diff] [blame] | 2165 | ColorProfileEq(ColorProfile{colorMode, dataspace, renderIntent}))); |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 2166 | return nextState<ExecuteState>(); |
| 2167 | } |
| 2168 | }; |
| 2169 | |
| 2170 | // Call this member function to start using the mini-DSL defined above. |
| 2171 | [[nodiscard]] auto verify() { |
| 2172 | return ExpectBestColorModeCallResultUsedToSetColorProfileState::make(this); |
| 2173 | } |
| 2174 | }; |
| 2175 | |
| 2176 | TEST_F(OutputUpdateColorProfileTest_GetBestColorModeResultBecomesSetProfile, |
| 2177 | Native_Unknown_Colorimetric_Set) { |
| 2178 | verify().expectBestColorModeCallResultUsedToSetColorProfile(ui::ColorMode::NATIVE, |
| 2179 | ui::Dataspace::UNKNOWN, |
| 2180 | ui::RenderIntent::COLORIMETRIC) |
| 2181 | .execute(); |
| 2182 | } |
| 2183 | |
| 2184 | TEST_F(OutputUpdateColorProfileTest_GetBestColorModeResultBecomesSetProfile, |
| 2185 | DisplayP3_DisplayP3_Enhance_Set) { |
| 2186 | verify().expectBestColorModeCallResultUsedToSetColorProfile(ui::ColorMode::DISPLAY_P3, |
| 2187 | ui::Dataspace::DISPLAY_P3, |
| 2188 | ui::RenderIntent::ENHANCE) |
| 2189 | .execute(); |
| 2190 | } |
| 2191 | |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 2192 | struct OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference |
| 2193 | : public OutputUpdateColorProfileTest { |
| 2194 | // Internally the implementation looks through the dataspaces of all the |
| 2195 | // visible layers. The topmost one that also has an actual dataspace |
| 2196 | // preference set is used to drive subsequent choices. |
| 2197 | |
| 2198 | OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference() { |
| 2199 | mRefreshArgs.outputColorSetting = OutputColorSetting::kEnhanced; |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 2200 | |
Lloyd Pique | 0a45623 | 2020-01-16 17:51:13 -0800 | [diff] [blame] | 2201 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(3u)); |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 2202 | EXPECT_CALL(mOutput, setColorProfile(_)).WillRepeatedly(Return()); |
| 2203 | } |
| 2204 | |
| 2205 | struct IfTopLayerDataspaceState |
| 2206 | : public CallOrderStateMachineHelper<TestType, IfTopLayerDataspaceState> { |
| 2207 | [[nodiscard]] auto ifTopLayerIs(ui::Dataspace dataspace) { |
| 2208 | getInstance()->mLayer3.mLayerFEState.dataspace = dataspace; |
| 2209 | return nextState<AndIfMiddleLayerDataspaceState>(); |
| 2210 | } |
| 2211 | [[nodiscard]] auto ifTopLayerHasNoPreference() { |
| 2212 | return ifTopLayerIs(ui::Dataspace::UNKNOWN); |
| 2213 | } |
| 2214 | }; |
| 2215 | |
| 2216 | struct AndIfMiddleLayerDataspaceState |
| 2217 | : public CallOrderStateMachineHelper<TestType, AndIfMiddleLayerDataspaceState> { |
| 2218 | [[nodiscard]] auto andIfMiddleLayerIs(ui::Dataspace dataspace) { |
| 2219 | getInstance()->mLayer2.mLayerFEState.dataspace = dataspace; |
| 2220 | return nextState<AndIfBottomLayerDataspaceState>(); |
| 2221 | } |
| 2222 | [[nodiscard]] auto andIfMiddleLayerHasNoPreference() { |
| 2223 | return andIfMiddleLayerIs(ui::Dataspace::UNKNOWN); |
| 2224 | } |
| 2225 | }; |
| 2226 | |
| 2227 | struct AndIfBottomLayerDataspaceState |
| 2228 | : public CallOrderStateMachineHelper<TestType, AndIfBottomLayerDataspaceState> { |
| 2229 | [[nodiscard]] auto andIfBottomLayerIs(ui::Dataspace dataspace) { |
| 2230 | getInstance()->mLayer1.mLayerFEState.dataspace = dataspace; |
| 2231 | return nextState<ThenExpectBestColorModeCallUsesState>(); |
| 2232 | } |
| 2233 | [[nodiscard]] auto andIfBottomLayerHasNoPreference() { |
| 2234 | return andIfBottomLayerIs(ui::Dataspace::UNKNOWN); |
| 2235 | } |
| 2236 | }; |
| 2237 | |
| 2238 | struct ThenExpectBestColorModeCallUsesState |
| 2239 | : public CallOrderStateMachineHelper<TestType, ThenExpectBestColorModeCallUsesState> { |
| 2240 | [[nodiscard]] auto thenExpectBestColorModeCallUses(ui::Dataspace dataspace) { |
| 2241 | EXPECT_CALL(*getInstance()->mDisplayColorProfile, |
| 2242 | getBestColorMode(dataspace, _, _, _, _)); |
| 2243 | return nextState<ExecuteState>(); |
| 2244 | } |
| 2245 | }; |
| 2246 | |
| 2247 | // Call this member function to start using the mini-DSL defined above. |
| 2248 | [[nodiscard]] auto verify() { return IfTopLayerDataspaceState::make(this); } |
| 2249 | }; |
| 2250 | |
| 2251 | TEST_F(OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference, |
| 2252 | noStrongLayerPrefenceUses_V0_SRGB) { |
| 2253 | // If none of the layers indicate a preference, then V0_SRGB is the |
| 2254 | // preferred choice (subject to additional checks). |
| 2255 | verify().ifTopLayerHasNoPreference() |
| 2256 | .andIfMiddleLayerHasNoPreference() |
| 2257 | .andIfBottomLayerHasNoPreference() |
| 2258 | .thenExpectBestColorModeCallUses(ui::Dataspace::V0_SRGB) |
| 2259 | .execute(); |
| 2260 | } |
| 2261 | |
| 2262 | TEST_F(OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference, |
| 2263 | ifTopmostUses_DisplayP3_Then_DisplayP3_Chosen) { |
| 2264 | // If only the topmost layer has a preference, then that is what is chosen. |
| 2265 | verify().ifTopLayerIs(ui::Dataspace::DISPLAY_P3) |
| 2266 | .andIfMiddleLayerHasNoPreference() |
| 2267 | .andIfBottomLayerHasNoPreference() |
| 2268 | .thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_P3) |
| 2269 | .execute(); |
| 2270 | } |
| 2271 | |
| 2272 | TEST_F(OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference, |
| 2273 | ifMiddleUses_DisplayP3_Then_DisplayP3_Chosen) { |
| 2274 | // If only the middle layer has a preference, that that is what is chosen. |
| 2275 | verify().ifTopLayerHasNoPreference() |
| 2276 | .andIfMiddleLayerIs(ui::Dataspace::DISPLAY_P3) |
| 2277 | .andIfBottomLayerHasNoPreference() |
| 2278 | .thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_P3) |
| 2279 | .execute(); |
| 2280 | } |
| 2281 | |
| 2282 | TEST_F(OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference, |
| 2283 | ifBottomUses_DisplayP3_Then_DisplayP3_Chosen) { |
| 2284 | // If only the middle layer has a preference, that that is what is chosen. |
| 2285 | verify().ifTopLayerHasNoPreference() |
| 2286 | .andIfMiddleLayerHasNoPreference() |
| 2287 | .andIfBottomLayerIs(ui::Dataspace::DISPLAY_P3) |
| 2288 | .thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_P3) |
| 2289 | .execute(); |
| 2290 | } |
| 2291 | |
| 2292 | TEST_F(OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference, |
| 2293 | ifTopUses_DisplayBT2020_AndBottomUses_DisplayP3_Then_DisplayBT2020_Chosen) { |
| 2294 | // If multiple layers have a preference, the topmost value is what is used. |
| 2295 | verify().ifTopLayerIs(ui::Dataspace::DISPLAY_BT2020) |
| 2296 | .andIfMiddleLayerHasNoPreference() |
| 2297 | .andIfBottomLayerIs(ui::Dataspace::DISPLAY_P3) |
| 2298 | .thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_BT2020) |
| 2299 | .execute(); |
| 2300 | } |
| 2301 | |
| 2302 | TEST_F(OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference, |
| 2303 | ifTopUses_DisplayP3_AndBottomUses_V0_SRGB_Then_DisplayP3_Chosen) { |
| 2304 | // If multiple layers have a preference, the topmost value is what is used. |
| 2305 | verify().ifTopLayerIs(ui::Dataspace::DISPLAY_P3) |
| 2306 | .andIfMiddleLayerHasNoPreference() |
| 2307 | .andIfBottomLayerIs(ui::Dataspace::DISPLAY_BT2020) |
| 2308 | .thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_P3) |
| 2309 | .execute(); |
| 2310 | } |
| 2311 | |
| 2312 | struct OutputUpdateColorProfileTest_ForceOutputColorOverrides |
| 2313 | : public OutputUpdateColorProfileTest { |
| 2314 | // If CompositionRefreshArgs::forceOutputColorMode is set to some specific |
| 2315 | // values, it overrides the layer dataspace choice. |
| 2316 | |
| 2317 | OutputUpdateColorProfileTest_ForceOutputColorOverrides() { |
| 2318 | mRefreshArgs.outputColorSetting = OutputColorSetting::kEnhanced; |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 2319 | |
| 2320 | mLayer1.mLayerFEState.dataspace = ui::Dataspace::DISPLAY_BT2020; |
| 2321 | |
Lloyd Pique | 0a45623 | 2020-01-16 17:51:13 -0800 | [diff] [blame] | 2322 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(1u)); |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 2323 | EXPECT_CALL(mOutput, setColorProfile(_)).WillRepeatedly(Return()); |
| 2324 | } |
| 2325 | |
| 2326 | struct IfForceOutputColorModeState |
| 2327 | : public CallOrderStateMachineHelper<TestType, IfForceOutputColorModeState> { |
| 2328 | [[nodiscard]] auto ifForceOutputColorMode(ui::ColorMode colorMode) { |
| 2329 | getInstance()->mRefreshArgs.forceOutputColorMode = colorMode; |
| 2330 | return nextState<ThenExpectBestColorModeCallUsesState>(); |
| 2331 | } |
| 2332 | [[nodiscard]] auto ifNoOverride() { return ifForceOutputColorMode(ui::ColorMode::NATIVE); } |
| 2333 | }; |
| 2334 | |
| 2335 | struct ThenExpectBestColorModeCallUsesState |
| 2336 | : public CallOrderStateMachineHelper<TestType, ThenExpectBestColorModeCallUsesState> { |
| 2337 | [[nodiscard]] auto thenExpectBestColorModeCallUses(ui::Dataspace dataspace) { |
| 2338 | EXPECT_CALL(*getInstance()->mDisplayColorProfile, |
| 2339 | getBestColorMode(dataspace, _, _, _, _)); |
| 2340 | return nextState<ExecuteState>(); |
| 2341 | } |
| 2342 | }; |
| 2343 | |
| 2344 | // Call this member function to start using the mini-DSL defined above. |
| 2345 | [[nodiscard]] auto verify() { return IfForceOutputColorModeState::make(this); } |
| 2346 | }; |
| 2347 | |
| 2348 | TEST_F(OutputUpdateColorProfileTest_ForceOutputColorOverrides, NoOverride_DoesNotOverride) { |
| 2349 | // By default the layer state is used to set the preferred dataspace |
| 2350 | verify().ifNoOverride() |
| 2351 | .thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_BT2020) |
| 2352 | .execute(); |
| 2353 | } |
| 2354 | |
| 2355 | TEST_F(OutputUpdateColorProfileTest_ForceOutputColorOverrides, SRGB_Override_USES_V0_SRGB) { |
| 2356 | // Setting ui::ColorMode::SRGB overrides it with ui::Dataspace::V0_SRGB |
| 2357 | verify().ifForceOutputColorMode(ui::ColorMode::SRGB) |
| 2358 | .thenExpectBestColorModeCallUses(ui::Dataspace::V0_SRGB) |
| 2359 | .execute(); |
| 2360 | } |
| 2361 | |
| 2362 | TEST_F(OutputUpdateColorProfileTest_ForceOutputColorOverrides, DisplayP3_Override_Uses_DisplayP3) { |
| 2363 | // Setting ui::ColorMode::DISPLAY_P3 overrides it with ui::Dataspace::DISPLAY_P3 |
| 2364 | verify().ifForceOutputColorMode(ui::ColorMode::DISPLAY_P3) |
| 2365 | .thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_P3) |
| 2366 | .execute(); |
| 2367 | } |
| 2368 | |
| 2369 | // HDR output requires all layers to be compatible with the chosen HDR |
| 2370 | // dataspace, along with there being proper support. |
| 2371 | struct OutputUpdateColorProfileTest_Hdr : public OutputUpdateColorProfileTest { |
| 2372 | OutputUpdateColorProfileTest_Hdr() { |
| 2373 | mRefreshArgs.outputColorSetting = OutputColorSetting::kEnhanced; |
Lloyd Pique | 0a45623 | 2020-01-16 17:51:13 -0800 | [diff] [blame] | 2374 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(2u)); |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 2375 | EXPECT_CALL(mOutput, setColorProfile(_)).WillRepeatedly(Return()); |
| 2376 | } |
| 2377 | |
| 2378 | static constexpr ui::Dataspace kNonHdrDataspace = ui::Dataspace::DISPLAY_P3; |
| 2379 | static constexpr ui::Dataspace BT2020_PQ = ui::Dataspace::BT2020_PQ; |
| 2380 | static constexpr ui::Dataspace BT2020_HLG = ui::Dataspace::BT2020_HLG; |
| 2381 | static constexpr ui::Dataspace DISPLAY_P3 = ui::Dataspace::DISPLAY_P3; |
| 2382 | |
| 2383 | struct IfTopLayerDataspaceState |
| 2384 | : public CallOrderStateMachineHelper<TestType, IfTopLayerDataspaceState> { |
| 2385 | [[nodiscard]] auto ifTopLayerIs(ui::Dataspace dataspace) { |
| 2386 | getInstance()->mLayer2.mLayerFEState.dataspace = dataspace; |
| 2387 | return nextState<AndTopLayerCompositionTypeState>(); |
| 2388 | } |
| 2389 | [[nodiscard]] auto ifTopLayerIsNotHdr() { return ifTopLayerIs(kNonHdrDataspace); } |
| 2390 | }; |
| 2391 | |
| 2392 | struct AndTopLayerCompositionTypeState |
| 2393 | : public CallOrderStateMachineHelper<TestType, AndTopLayerCompositionTypeState> { |
| 2394 | [[nodiscard]] auto andTopLayerIsREComposed(bool renderEngineComposed) { |
| 2395 | getInstance()->mLayer2.mLayerFEState.forceClientComposition = renderEngineComposed; |
| 2396 | return nextState<AndIfBottomLayerDataspaceState>(); |
| 2397 | } |
| 2398 | }; |
| 2399 | |
| 2400 | struct AndIfBottomLayerDataspaceState |
| 2401 | : public CallOrderStateMachineHelper<TestType, AndIfBottomLayerDataspaceState> { |
| 2402 | [[nodiscard]] auto andIfBottomLayerIs(ui::Dataspace dataspace) { |
| 2403 | getInstance()->mLayer1.mLayerFEState.dataspace = dataspace; |
| 2404 | return nextState<AndBottomLayerCompositionTypeState>(); |
| 2405 | } |
| 2406 | [[nodiscard]] auto andIfBottomLayerIsNotHdr() { |
| 2407 | return andIfBottomLayerIs(kNonHdrDataspace); |
| 2408 | } |
| 2409 | }; |
| 2410 | |
| 2411 | struct AndBottomLayerCompositionTypeState |
| 2412 | : public CallOrderStateMachineHelper<TestType, AndBottomLayerCompositionTypeState> { |
| 2413 | [[nodiscard]] auto andBottomLayerIsREComposed(bool renderEngineComposed) { |
| 2414 | getInstance()->mLayer1.mLayerFEState.forceClientComposition = renderEngineComposed; |
| 2415 | return nextState<AndIfHasLegacySupportState>(); |
| 2416 | } |
| 2417 | }; |
| 2418 | |
| 2419 | struct AndIfHasLegacySupportState |
| 2420 | : public CallOrderStateMachineHelper<TestType, AndIfHasLegacySupportState> { |
| 2421 | [[nodiscard]] auto andIfLegacySupportFor(ui::Dataspace dataspace, bool legacySupport) { |
| 2422 | EXPECT_CALL(*getInstance()->mDisplayColorProfile, hasLegacyHdrSupport(dataspace)) |
| 2423 | .WillOnce(Return(legacySupport)); |
| 2424 | return nextState<ThenExpectBestColorModeCallUsesState>(); |
| 2425 | } |
| 2426 | }; |
| 2427 | |
| 2428 | struct ThenExpectBestColorModeCallUsesState |
| 2429 | : public CallOrderStateMachineHelper<TestType, ThenExpectBestColorModeCallUsesState> { |
| 2430 | [[nodiscard]] auto thenExpectBestColorModeCallUses(ui::Dataspace dataspace) { |
| 2431 | EXPECT_CALL(*getInstance()->mDisplayColorProfile, |
| 2432 | getBestColorMode(dataspace, _, _, _, _)); |
| 2433 | return nextState<ExecuteState>(); |
| 2434 | } |
| 2435 | }; |
| 2436 | |
| 2437 | // Call this member function to start using the mini-DSL defined above. |
| 2438 | [[nodiscard]] auto verify() { return IfTopLayerDataspaceState::make(this); } |
| 2439 | }; |
| 2440 | |
| 2441 | TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_PQ_HW_Uses_PQ) { |
| 2442 | // If all layers use BT2020_PQ, and there are no other special conditions, |
| 2443 | // BT2020_PQ is used. |
| 2444 | verify().ifTopLayerIs(BT2020_PQ) |
| 2445 | .andTopLayerIsREComposed(false) |
| 2446 | .andIfBottomLayerIs(BT2020_PQ) |
| 2447 | .andBottomLayerIsREComposed(false) |
| 2448 | .andIfLegacySupportFor(BT2020_PQ, false) |
| 2449 | .thenExpectBestColorModeCallUses(BT2020_PQ) |
| 2450 | .execute(); |
| 2451 | } |
| 2452 | |
| 2453 | TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_PQ_HW_IfPQHasLegacySupport_Uses_DisplayP3) { |
| 2454 | // BT2020_PQ is not used if there is only legacy support for it. |
| 2455 | verify().ifTopLayerIs(BT2020_PQ) |
| 2456 | .andTopLayerIsREComposed(false) |
| 2457 | .andIfBottomLayerIs(BT2020_PQ) |
| 2458 | .andBottomLayerIsREComposed(false) |
| 2459 | .andIfLegacySupportFor(BT2020_PQ, true) |
| 2460 | .thenExpectBestColorModeCallUses(DISPLAY_P3) |
| 2461 | .execute(); |
| 2462 | } |
| 2463 | |
| 2464 | TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_PQ_RE_Uses_PQ) { |
| 2465 | // BT2020_PQ is still used if the bottom layer is RenderEngine composed. |
| 2466 | verify().ifTopLayerIs(BT2020_PQ) |
| 2467 | .andTopLayerIsREComposed(false) |
| 2468 | .andIfBottomLayerIs(BT2020_PQ) |
| 2469 | .andBottomLayerIsREComposed(true) |
| 2470 | .andIfLegacySupportFor(BT2020_PQ, false) |
| 2471 | .thenExpectBestColorModeCallUses(BT2020_PQ) |
| 2472 | .execute(); |
| 2473 | } |
| 2474 | |
| 2475 | TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_RE_On_PQ_HW_Uses_DisplayP3) { |
| 2476 | // BT2020_PQ is not used if the top layer is RenderEngine composed. |
| 2477 | verify().ifTopLayerIs(BT2020_PQ) |
| 2478 | .andTopLayerIsREComposed(true) |
| 2479 | .andIfBottomLayerIs(BT2020_PQ) |
| 2480 | .andBottomLayerIsREComposed(false) |
| 2481 | .andIfLegacySupportFor(BT2020_PQ, false) |
| 2482 | .thenExpectBestColorModeCallUses(DISPLAY_P3) |
| 2483 | .execute(); |
| 2484 | } |
| 2485 | |
| 2486 | TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_HLG_HW_Uses_PQ) { |
| 2487 | // If there is mixed HLG/PQ use, and the topmost layer is PQ, then PQ is used if there |
| 2488 | // are no other special conditions. |
| 2489 | verify().ifTopLayerIs(BT2020_PQ) |
| 2490 | .andTopLayerIsREComposed(false) |
| 2491 | .andIfBottomLayerIs(BT2020_HLG) |
| 2492 | .andBottomLayerIsREComposed(false) |
| 2493 | .andIfLegacySupportFor(BT2020_PQ, false) |
| 2494 | .thenExpectBestColorModeCallUses(BT2020_PQ) |
| 2495 | .execute(); |
| 2496 | } |
| 2497 | |
| 2498 | TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_HLG_HW_IfPQHasLegacySupport_Uses_DisplayP3) { |
| 2499 | // BT2020_PQ is not used if there is only legacy support for it. |
| 2500 | verify().ifTopLayerIs(BT2020_PQ) |
| 2501 | .andTopLayerIsREComposed(false) |
| 2502 | .andIfBottomLayerIs(BT2020_HLG) |
| 2503 | .andBottomLayerIsREComposed(false) |
| 2504 | .andIfLegacySupportFor(BT2020_PQ, true) |
| 2505 | .thenExpectBestColorModeCallUses(DISPLAY_P3) |
| 2506 | .execute(); |
| 2507 | } |
| 2508 | |
| 2509 | TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_HLG_RE_Uses_PQ) { |
| 2510 | // BT2020_PQ is used if the bottom HLG layer is RenderEngine composed. |
| 2511 | verify().ifTopLayerIs(BT2020_PQ) |
| 2512 | .andTopLayerIsREComposed(false) |
| 2513 | .andIfBottomLayerIs(BT2020_HLG) |
| 2514 | .andBottomLayerIsREComposed(true) |
| 2515 | .andIfLegacySupportFor(BT2020_PQ, false) |
| 2516 | .thenExpectBestColorModeCallUses(BT2020_PQ) |
| 2517 | .execute(); |
| 2518 | } |
| 2519 | |
| 2520 | TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_RE_On_HLG_HW_Uses_DisplayP3) { |
| 2521 | // BT2020_PQ is not used if the top PQ layer is RenderEngine composed. |
| 2522 | verify().ifTopLayerIs(BT2020_PQ) |
| 2523 | .andTopLayerIsREComposed(true) |
| 2524 | .andIfBottomLayerIs(BT2020_HLG) |
| 2525 | .andBottomLayerIsREComposed(false) |
| 2526 | .andIfLegacySupportFor(BT2020_PQ, false) |
| 2527 | .thenExpectBestColorModeCallUses(DISPLAY_P3) |
| 2528 | .execute(); |
| 2529 | } |
| 2530 | |
| 2531 | TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_PQ_HW_Uses_PQ) { |
| 2532 | // If there is mixed HLG/PQ use, and the topmost layer is HLG, then PQ is |
| 2533 | // used if there are no other special conditions. |
| 2534 | verify().ifTopLayerIs(BT2020_HLG) |
| 2535 | .andTopLayerIsREComposed(false) |
| 2536 | .andIfBottomLayerIs(BT2020_PQ) |
| 2537 | .andBottomLayerIsREComposed(false) |
| 2538 | .andIfLegacySupportFor(BT2020_PQ, false) |
| 2539 | .thenExpectBestColorModeCallUses(BT2020_PQ) |
| 2540 | .execute(); |
| 2541 | } |
| 2542 | |
| 2543 | TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_PQ_HW_IfPQHasLegacySupport_Uses_DisplayP3) { |
| 2544 | // BT2020_PQ is not used if there is only legacy support for it. |
| 2545 | verify().ifTopLayerIs(BT2020_HLG) |
| 2546 | .andTopLayerIsREComposed(false) |
| 2547 | .andIfBottomLayerIs(BT2020_PQ) |
| 2548 | .andBottomLayerIsREComposed(false) |
| 2549 | .andIfLegacySupportFor(BT2020_PQ, true) |
| 2550 | .thenExpectBestColorModeCallUses(DISPLAY_P3) |
| 2551 | .execute(); |
| 2552 | } |
| 2553 | |
| 2554 | TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_PQ_RE_Uses_DisplayP3) { |
| 2555 | // BT2020_PQ is not used if the bottom PQ layer is RenderEngine composed. |
| 2556 | verify().ifTopLayerIs(BT2020_HLG) |
| 2557 | .andTopLayerIsREComposed(false) |
| 2558 | .andIfBottomLayerIs(BT2020_PQ) |
| 2559 | .andBottomLayerIsREComposed(true) |
| 2560 | .andIfLegacySupportFor(BT2020_PQ, false) |
| 2561 | .thenExpectBestColorModeCallUses(DISPLAY_P3) |
| 2562 | .execute(); |
| 2563 | } |
| 2564 | |
| 2565 | TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_RE_On_PQ_HW_Uses_PQ) { |
| 2566 | // BT2020_PQ is still used if the top HLG layer is RenderEngine composed. |
| 2567 | verify().ifTopLayerIs(BT2020_HLG) |
| 2568 | .andTopLayerIsREComposed(true) |
| 2569 | .andIfBottomLayerIs(BT2020_PQ) |
| 2570 | .andBottomLayerIsREComposed(false) |
| 2571 | .andIfLegacySupportFor(BT2020_PQ, false) |
| 2572 | .thenExpectBestColorModeCallUses(BT2020_PQ) |
| 2573 | .execute(); |
| 2574 | } |
| 2575 | |
| 2576 | TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_HLG_HW_Uses_HLG) { |
| 2577 | // If all layers use HLG then HLG is used if there are no other special |
| 2578 | // conditions. |
| 2579 | verify().ifTopLayerIs(BT2020_HLG) |
| 2580 | .andTopLayerIsREComposed(false) |
| 2581 | .andIfBottomLayerIs(BT2020_HLG) |
| 2582 | .andBottomLayerIsREComposed(false) |
| 2583 | .andIfLegacySupportFor(BT2020_HLG, false) |
| 2584 | .thenExpectBestColorModeCallUses(BT2020_HLG) |
| 2585 | .execute(); |
| 2586 | } |
| 2587 | |
| 2588 | TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_HLG_HW_IfPQHasLegacySupport_Uses_DisplayP3) { |
| 2589 | // BT2020_HLG is not used if there is legacy support for it. |
| 2590 | verify().ifTopLayerIs(BT2020_HLG) |
| 2591 | .andTopLayerIsREComposed(false) |
| 2592 | .andIfBottomLayerIs(BT2020_HLG) |
| 2593 | .andBottomLayerIsREComposed(false) |
| 2594 | .andIfLegacySupportFor(BT2020_HLG, true) |
| 2595 | .thenExpectBestColorModeCallUses(DISPLAY_P3) |
| 2596 | .execute(); |
| 2597 | } |
| 2598 | |
| 2599 | TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_HLG_RE_Uses_HLG) { |
| 2600 | // BT2020_HLG is used even if the bottom layer is client composed. |
| 2601 | verify().ifTopLayerIs(BT2020_HLG) |
| 2602 | .andTopLayerIsREComposed(false) |
| 2603 | .andIfBottomLayerIs(BT2020_HLG) |
| 2604 | .andBottomLayerIsREComposed(true) |
| 2605 | .andIfLegacySupportFor(BT2020_HLG, false) |
| 2606 | .thenExpectBestColorModeCallUses(BT2020_HLG) |
| 2607 | .execute(); |
| 2608 | } |
| 2609 | |
| 2610 | TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_RE_On_HLG_HW_Uses_HLG) { |
| 2611 | // BT2020_HLG is used even if the top layer is client composed. |
| 2612 | verify().ifTopLayerIs(BT2020_HLG) |
| 2613 | .andTopLayerIsREComposed(true) |
| 2614 | .andIfBottomLayerIs(BT2020_HLG) |
| 2615 | .andBottomLayerIsREComposed(false) |
| 2616 | .andIfLegacySupportFor(BT2020_HLG, false) |
| 2617 | .thenExpectBestColorModeCallUses(BT2020_HLG) |
| 2618 | .execute(); |
| 2619 | } |
| 2620 | |
| 2621 | TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_NonHdr_HW_Uses_PQ) { |
| 2622 | // Even if there are non-HDR layers present, BT2020_PQ can still be used. |
| 2623 | verify().ifTopLayerIs(BT2020_PQ) |
| 2624 | .andTopLayerIsREComposed(false) |
| 2625 | .andIfBottomLayerIsNotHdr() |
| 2626 | .andBottomLayerIsREComposed(false) |
| 2627 | .andIfLegacySupportFor(BT2020_PQ, false) |
| 2628 | .thenExpectBestColorModeCallUses(BT2020_PQ) |
| 2629 | .execute(); |
| 2630 | } |
| 2631 | |
| 2632 | TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_NonHdr_RE_Uses_HLG) { |
| 2633 | // If all layers use HLG then HLG is used if there are no other special |
| 2634 | // conditions. |
| 2635 | verify().ifTopLayerIs(BT2020_HLG) |
| 2636 | .andTopLayerIsREComposed(false) |
| 2637 | .andIfBottomLayerIsNotHdr() |
| 2638 | .andBottomLayerIsREComposed(true) |
| 2639 | .andIfLegacySupportFor(BT2020_HLG, false) |
| 2640 | .thenExpectBestColorModeCallUses(BT2020_HLG) |
| 2641 | .execute(); |
| 2642 | } |
| 2643 | |
| 2644 | struct OutputUpdateColorProfile_AffectsChosenRenderIntentTest |
| 2645 | : public OutputUpdateColorProfileTest { |
| 2646 | // The various values for CompositionRefreshArgs::outputColorSetting affect |
| 2647 | // the chosen renderIntent, along with whether the preferred dataspace is an |
| 2648 | // HDR dataspace or not. |
| 2649 | |
| 2650 | OutputUpdateColorProfile_AffectsChosenRenderIntentTest() { |
| 2651 | mRefreshArgs.outputColorSetting = OutputColorSetting::kEnhanced; |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 2652 | mLayer1.mLayerFEState.dataspace = ui::Dataspace::BT2020_PQ; |
Lloyd Pique | 0a45623 | 2020-01-16 17:51:13 -0800 | [diff] [blame] | 2653 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(1u)); |
Lloyd Pique | 17ca742 | 2019-11-14 14:24:10 -0800 | [diff] [blame] | 2654 | EXPECT_CALL(mOutput, setColorProfile(_)).WillRepeatedly(Return()); |
| 2655 | EXPECT_CALL(*mDisplayColorProfile, hasLegacyHdrSupport(ui::Dataspace::BT2020_PQ)) |
| 2656 | .WillRepeatedly(Return(false)); |
| 2657 | } |
| 2658 | |
| 2659 | // The tests here involve enough state and GMock setup that using a mini-DSL |
| 2660 | // makes the tests much more readable, and allows the test to focus more on |
| 2661 | // the intent than on some of the details. |
| 2662 | |
| 2663 | static constexpr ui::Dataspace kNonHdrDataspace = ui::Dataspace::DISPLAY_P3; |
| 2664 | static constexpr ui::Dataspace kHdrDataspace = ui::Dataspace::BT2020_PQ; |
| 2665 | |
| 2666 | struct IfDataspaceChosenState |
| 2667 | : public CallOrderStateMachineHelper<TestType, IfDataspaceChosenState> { |
| 2668 | [[nodiscard]] auto ifDataspaceChosenIs(ui::Dataspace dataspace) { |
| 2669 | getInstance()->mLayer1.mLayerFEState.dataspace = dataspace; |
| 2670 | return nextState<AndOutputColorSettingState>(); |
| 2671 | } |
| 2672 | [[nodiscard]] auto ifDataspaceChosenIsNonHdr() { |
| 2673 | return ifDataspaceChosenIs(kNonHdrDataspace); |
| 2674 | } |
| 2675 | [[nodiscard]] auto ifDataspaceChosenIsHdr() { return ifDataspaceChosenIs(kHdrDataspace); } |
| 2676 | }; |
| 2677 | |
| 2678 | struct AndOutputColorSettingState |
| 2679 | : public CallOrderStateMachineHelper<TestType, AndOutputColorSettingState> { |
| 2680 | [[nodiscard]] auto andOutputColorSettingIs(OutputColorSetting setting) { |
| 2681 | getInstance()->mRefreshArgs.outputColorSetting = setting; |
| 2682 | return nextState<ThenExpectBestColorModeCallUsesState>(); |
| 2683 | } |
| 2684 | }; |
| 2685 | |
| 2686 | struct ThenExpectBestColorModeCallUsesState |
| 2687 | : public CallOrderStateMachineHelper<TestType, ThenExpectBestColorModeCallUsesState> { |
| 2688 | [[nodiscard]] auto thenExpectBestColorModeCallUses(ui::RenderIntent intent) { |
| 2689 | EXPECT_CALL(*getInstance()->mDisplayColorProfile, |
| 2690 | getBestColorMode(getInstance()->mLayer1.mLayerFEState.dataspace, intent, _, |
| 2691 | _, _)); |
| 2692 | return nextState<ExecuteState>(); |
| 2693 | } |
| 2694 | }; |
| 2695 | |
| 2696 | // Tests call one of these two helper member functions to start using the |
| 2697 | // mini-DSL defined above. |
| 2698 | [[nodiscard]] auto verify() { return IfDataspaceChosenState::make(this); } |
| 2699 | }; |
| 2700 | |
| 2701 | TEST_F(OutputUpdateColorProfile_AffectsChosenRenderIntentTest, |
| 2702 | Managed_NonHdr_Prefers_Colorimetric) { |
| 2703 | verify().ifDataspaceChosenIsNonHdr() |
| 2704 | .andOutputColorSettingIs(OutputColorSetting::kManaged) |
| 2705 | .thenExpectBestColorModeCallUses(ui::RenderIntent::COLORIMETRIC) |
| 2706 | .execute(); |
| 2707 | } |
| 2708 | |
| 2709 | TEST_F(OutputUpdateColorProfile_AffectsChosenRenderIntentTest, |
| 2710 | Managed_Hdr_Prefers_ToneMapColorimetric) { |
| 2711 | verify().ifDataspaceChosenIsHdr() |
| 2712 | .andOutputColorSettingIs(OutputColorSetting::kManaged) |
| 2713 | .thenExpectBestColorModeCallUses(ui::RenderIntent::TONE_MAP_COLORIMETRIC) |
| 2714 | .execute(); |
| 2715 | } |
| 2716 | |
| 2717 | TEST_F(OutputUpdateColorProfile_AffectsChosenRenderIntentTest, Enhanced_NonHdr_Prefers_Enhance) { |
| 2718 | verify().ifDataspaceChosenIsNonHdr() |
| 2719 | .andOutputColorSettingIs(OutputColorSetting::kEnhanced) |
| 2720 | .thenExpectBestColorModeCallUses(ui::RenderIntent::ENHANCE) |
| 2721 | .execute(); |
| 2722 | } |
| 2723 | |
| 2724 | TEST_F(OutputUpdateColorProfile_AffectsChosenRenderIntentTest, |
| 2725 | Enhanced_Hdr_Prefers_ToneMapEnhance) { |
| 2726 | verify().ifDataspaceChosenIsHdr() |
| 2727 | .andOutputColorSettingIs(OutputColorSetting::kEnhanced) |
| 2728 | .thenExpectBestColorModeCallUses(ui::RenderIntent::TONE_MAP_ENHANCE) |
| 2729 | .execute(); |
| 2730 | } |
| 2731 | |
| 2732 | TEST_F(OutputUpdateColorProfile_AffectsChosenRenderIntentTest, Vendor_NonHdr_Prefers_Vendor) { |
| 2733 | verify().ifDataspaceChosenIsNonHdr() |
| 2734 | .andOutputColorSettingIs(kVendorSpecifiedOutputColorSetting) |
| 2735 | .thenExpectBestColorModeCallUses( |
| 2736 | static_cast<ui::RenderIntent>(kVendorSpecifiedOutputColorSetting)) |
| 2737 | .execute(); |
| 2738 | } |
| 2739 | |
| 2740 | TEST_F(OutputUpdateColorProfile_AffectsChosenRenderIntentTest, Vendor_Hdr_Prefers_Vendor) { |
| 2741 | verify().ifDataspaceChosenIsHdr() |
| 2742 | .andOutputColorSettingIs(kVendorSpecifiedOutputColorSetting) |
| 2743 | .thenExpectBestColorModeCallUses( |
| 2744 | static_cast<ui::RenderIntent>(kVendorSpecifiedOutputColorSetting)) |
| 2745 | .execute(); |
| 2746 | } |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 2747 | |
| 2748 | /* |
| 2749 | * Output::beginFrame() |
| 2750 | */ |
| 2751 | |
Lloyd Pique | e596595 | 2019-11-18 16:16:32 -0800 | [diff] [blame] | 2752 | struct OutputBeginFrameTest : public ::testing::Test { |
| 2753 | using TestType = OutputBeginFrameTest; |
| 2754 | |
| 2755 | struct OutputPartialMock : public OutputPartialMockBase { |
Lloyd Pique | 739afaf | 2019-11-21 16:40:05 -0800 | [diff] [blame] | 2756 | // Sets up the helper functions called by the function under test to use |
| 2757 | // mock implementations. |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2758 | MOCK_METHOD(Region, getDirtyRegion, (), (const)); |
Lloyd Pique | e596595 | 2019-11-18 16:16:32 -0800 | [diff] [blame] | 2759 | }; |
| 2760 | |
| 2761 | OutputBeginFrameTest() { |
| 2762 | mOutput.setDisplayColorProfileForTest( |
| 2763 | std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile)); |
| 2764 | mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface)); |
| 2765 | } |
| 2766 | |
| 2767 | struct IfGetDirtyRegionExpectationState |
| 2768 | : public CallOrderStateMachineHelper<TestType, IfGetDirtyRegionExpectationState> { |
| 2769 | [[nodiscard]] auto ifGetDirtyRegionReturns(Region dirtyRegion) { |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2770 | EXPECT_CALL(getInstance()->mOutput, getDirtyRegion()).WillOnce(Return(dirtyRegion)); |
Lloyd Pique | e596595 | 2019-11-18 16:16:32 -0800 | [diff] [blame] | 2771 | return nextState<AndIfGetOutputLayerCountExpectationState>(); |
| 2772 | } |
| 2773 | }; |
| 2774 | |
| 2775 | struct AndIfGetOutputLayerCountExpectationState |
| 2776 | : public CallOrderStateMachineHelper<TestType, AndIfGetOutputLayerCountExpectationState> { |
| 2777 | [[nodiscard]] auto andIfGetOutputLayerCountReturns(size_t layerCount) { |
| 2778 | EXPECT_CALL(getInstance()->mOutput, getOutputLayerCount()).WillOnce(Return(layerCount)); |
| 2779 | return nextState<AndIfLastCompositionHadVisibleLayersState>(); |
| 2780 | } |
| 2781 | }; |
| 2782 | |
| 2783 | struct AndIfLastCompositionHadVisibleLayersState |
| 2784 | : public CallOrderStateMachineHelper<TestType, |
| 2785 | AndIfLastCompositionHadVisibleLayersState> { |
| 2786 | [[nodiscard]] auto andIfLastCompositionHadVisibleLayersIs(bool hadOutputLayers) { |
| 2787 | getInstance()->mOutput.mState.lastCompositionHadVisibleLayers = hadOutputLayers; |
| 2788 | return nextState<ThenExpectRenderSurfaceBeginFrameCallState>(); |
| 2789 | } |
| 2790 | }; |
| 2791 | |
| 2792 | struct ThenExpectRenderSurfaceBeginFrameCallState |
| 2793 | : public CallOrderStateMachineHelper<TestType, |
| 2794 | ThenExpectRenderSurfaceBeginFrameCallState> { |
| 2795 | [[nodiscard]] auto thenExpectRenderSurfaceBeginFrameCall(bool mustRecompose) { |
| 2796 | EXPECT_CALL(*getInstance()->mRenderSurface, beginFrame(mustRecompose)); |
| 2797 | return nextState<ExecuteState>(); |
| 2798 | } |
| 2799 | }; |
| 2800 | |
| 2801 | struct ExecuteState : public CallOrderStateMachineHelper<TestType, ExecuteState> { |
| 2802 | [[nodiscard]] auto execute() { |
| 2803 | getInstance()->mOutput.beginFrame(); |
| 2804 | return nextState<CheckPostconditionHadVisibleLayersState>(); |
| 2805 | } |
| 2806 | }; |
| 2807 | |
| 2808 | struct CheckPostconditionHadVisibleLayersState |
| 2809 | : public CallOrderStateMachineHelper<TestType, CheckPostconditionHadVisibleLayersState> { |
| 2810 | void checkPostconditionHadVisibleLayers(bool expected) { |
| 2811 | EXPECT_EQ(expected, getInstance()->mOutput.mState.lastCompositionHadVisibleLayers); |
| 2812 | } |
| 2813 | }; |
| 2814 | |
| 2815 | // Tests call one of these two helper member functions to start using the |
| 2816 | // mini-DSL defined above. |
| 2817 | [[nodiscard]] auto verify() { return IfGetDirtyRegionExpectationState::make(this); } |
| 2818 | |
| 2819 | static const Region kEmptyRegion; |
| 2820 | static const Region kNotEmptyRegion; |
| 2821 | |
| 2822 | mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>(); |
| 2823 | mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>(); |
| 2824 | StrictMock<OutputPartialMock> mOutput; |
| 2825 | }; |
| 2826 | |
| 2827 | const Region OutputBeginFrameTest::kEmptyRegion{Rect{0, 0, 0, 0}}; |
| 2828 | const Region OutputBeginFrameTest::kNotEmptyRegion{Rect{0, 0, 1, 1}}; |
| 2829 | |
| 2830 | TEST_F(OutputBeginFrameTest, hasDirtyHasLayersHadLayersLastFrame) { |
| 2831 | verify().ifGetDirtyRegionReturns(kNotEmptyRegion) |
| 2832 | .andIfGetOutputLayerCountReturns(1u) |
| 2833 | .andIfLastCompositionHadVisibleLayersIs(true) |
| 2834 | .thenExpectRenderSurfaceBeginFrameCall(true) |
| 2835 | .execute() |
| 2836 | .checkPostconditionHadVisibleLayers(true); |
| 2837 | } |
| 2838 | |
| 2839 | TEST_F(OutputBeginFrameTest, hasDirtyNotHasLayersHadLayersLastFrame) { |
| 2840 | verify().ifGetDirtyRegionReturns(kNotEmptyRegion) |
| 2841 | .andIfGetOutputLayerCountReturns(0u) |
| 2842 | .andIfLastCompositionHadVisibleLayersIs(true) |
| 2843 | .thenExpectRenderSurfaceBeginFrameCall(true) |
| 2844 | .execute() |
| 2845 | .checkPostconditionHadVisibleLayers(false); |
| 2846 | } |
| 2847 | |
| 2848 | TEST_F(OutputBeginFrameTest, hasDirtyHasLayersNotHadLayersLastFrame) { |
| 2849 | verify().ifGetDirtyRegionReturns(kNotEmptyRegion) |
| 2850 | .andIfGetOutputLayerCountReturns(1u) |
| 2851 | .andIfLastCompositionHadVisibleLayersIs(false) |
| 2852 | .thenExpectRenderSurfaceBeginFrameCall(true) |
| 2853 | .execute() |
| 2854 | .checkPostconditionHadVisibleLayers(true); |
| 2855 | } |
| 2856 | |
| 2857 | TEST_F(OutputBeginFrameTest, hasDirtyNotHasLayersNotHadLayersLastFrame) { |
| 2858 | verify().ifGetDirtyRegionReturns(kNotEmptyRegion) |
| 2859 | .andIfGetOutputLayerCountReturns(0u) |
| 2860 | .andIfLastCompositionHadVisibleLayersIs(false) |
| 2861 | .thenExpectRenderSurfaceBeginFrameCall(false) |
| 2862 | .execute() |
| 2863 | .checkPostconditionHadVisibleLayers(false); |
| 2864 | } |
| 2865 | |
| 2866 | TEST_F(OutputBeginFrameTest, notHasDirtyHasLayersHadLayersLastFrame) { |
| 2867 | verify().ifGetDirtyRegionReturns(kEmptyRegion) |
| 2868 | .andIfGetOutputLayerCountReturns(1u) |
| 2869 | .andIfLastCompositionHadVisibleLayersIs(true) |
| 2870 | .thenExpectRenderSurfaceBeginFrameCall(false) |
| 2871 | .execute() |
| 2872 | .checkPostconditionHadVisibleLayers(true); |
| 2873 | } |
| 2874 | |
| 2875 | TEST_F(OutputBeginFrameTest, notHasDirtyNotHasLayersHadLayersLastFrame) { |
| 2876 | verify().ifGetDirtyRegionReturns(kEmptyRegion) |
| 2877 | .andIfGetOutputLayerCountReturns(0u) |
| 2878 | .andIfLastCompositionHadVisibleLayersIs(true) |
| 2879 | .thenExpectRenderSurfaceBeginFrameCall(false) |
| 2880 | .execute() |
| 2881 | .checkPostconditionHadVisibleLayers(true); |
| 2882 | } |
| 2883 | |
| 2884 | TEST_F(OutputBeginFrameTest, notHasDirtyHasLayersNotHadLayersLastFrame) { |
| 2885 | verify().ifGetDirtyRegionReturns(kEmptyRegion) |
| 2886 | .andIfGetOutputLayerCountReturns(1u) |
| 2887 | .andIfLastCompositionHadVisibleLayersIs(false) |
| 2888 | .thenExpectRenderSurfaceBeginFrameCall(false) |
| 2889 | .execute() |
| 2890 | .checkPostconditionHadVisibleLayers(false); |
| 2891 | } |
| 2892 | |
| 2893 | TEST_F(OutputBeginFrameTest, notHasDirtyNotHasLayersNotHadLayersLastFrame) { |
| 2894 | verify().ifGetDirtyRegionReturns(kEmptyRegion) |
| 2895 | .andIfGetOutputLayerCountReturns(0u) |
| 2896 | .andIfLastCompositionHadVisibleLayersIs(false) |
| 2897 | .thenExpectRenderSurfaceBeginFrameCall(false) |
| 2898 | .execute() |
| 2899 | .checkPostconditionHadVisibleLayers(false); |
| 2900 | } |
| 2901 | |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 2902 | /* |
| 2903 | * Output::devOptRepaintFlash() |
| 2904 | */ |
| 2905 | |
Lloyd Pique | db462d8 | 2019-11-19 17:58:46 -0800 | [diff] [blame] | 2906 | struct OutputDevOptRepaintFlashTest : public testing::Test { |
| 2907 | struct OutputPartialMock : public OutputPartialMockBase { |
Lloyd Pique | 739afaf | 2019-11-21 16:40:05 -0800 | [diff] [blame] | 2908 | // Sets up the helper functions called by the function under test to use |
| 2909 | // mock implementations. |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2910 | MOCK_METHOD(Region, getDirtyRegion, (), (const)); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 2911 | MOCK_METHOD3(composeSurfaces, |
| 2912 | std::optional<base::unique_fd>(const Region&, |
| 2913 | std::shared_ptr<renderengine::ExternalTexture>, |
| 2914 | base::unique_fd&)); |
Leon Scroggins III | a3ba7fa | 2024-05-22 16:34:52 -0400 | [diff] [blame] | 2915 | MOCK_METHOD(void, presentFrameAndReleaseLayers, (bool flushEvenWhenDisabled)); |
Lloyd Pique | db462d8 | 2019-11-19 17:58:46 -0800 | [diff] [blame] | 2916 | MOCK_METHOD0(prepareFrame, void()); |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 2917 | MOCK_METHOD0(updateProtectedContentState, void()); |
| 2918 | MOCK_METHOD2(dequeueRenderBuffer, |
| 2919 | bool(base::unique_fd*, std::shared_ptr<renderengine::ExternalTexture>*)); |
Lloyd Pique | db462d8 | 2019-11-19 17:58:46 -0800 | [diff] [blame] | 2920 | }; |
| 2921 | |
| 2922 | OutputDevOptRepaintFlashTest() { |
| 2923 | mOutput.setDisplayColorProfileForTest( |
| 2924 | std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile)); |
| 2925 | mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface)); |
| 2926 | } |
| 2927 | |
| 2928 | static const Region kEmptyRegion; |
| 2929 | static const Region kNotEmptyRegion; |
| 2930 | |
| 2931 | StrictMock<OutputPartialMock> mOutput; |
| 2932 | mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>(); |
| 2933 | mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>(); |
| 2934 | CompositionRefreshArgs mRefreshArgs; |
| 2935 | }; |
| 2936 | |
| 2937 | const Region OutputDevOptRepaintFlashTest::kEmptyRegion{Rect{0, 0, 0, 0}}; |
| 2938 | const Region OutputDevOptRepaintFlashTest::kNotEmptyRegion{Rect{0, 0, 1, 1}}; |
| 2939 | |
| 2940 | TEST_F(OutputDevOptRepaintFlashTest, doesNothingIfFlashDelayNotSet) { |
| 2941 | mRefreshArgs.devOptFlashDirtyRegionsDelay = {}; |
Lloyd Pique | db462d8 | 2019-11-19 17:58:46 -0800 | [diff] [blame] | 2942 | mOutput.mState.isEnabled = true; |
| 2943 | |
| 2944 | mOutput.devOptRepaintFlash(mRefreshArgs); |
| 2945 | } |
| 2946 | |
| 2947 | TEST_F(OutputDevOptRepaintFlashTest, postsAndPreparesANewFrameIfNotEnabled) { |
| 2948 | mRefreshArgs.devOptFlashDirtyRegionsDelay = std::chrono::microseconds(1); |
Lloyd Pique | db462d8 | 2019-11-19 17:58:46 -0800 | [diff] [blame] | 2949 | mOutput.mState.isEnabled = false; |
| 2950 | |
| 2951 | InSequence seq; |
Leon Scroggins III | a3ba7fa | 2024-05-22 16:34:52 -0400 | [diff] [blame] | 2952 | constexpr bool kFlushEvenWhenDisabled = false; |
| 2953 | EXPECT_CALL(mOutput, presentFrameAndReleaseLayers(kFlushEvenWhenDisabled)); |
Lloyd Pique | db462d8 | 2019-11-19 17:58:46 -0800 | [diff] [blame] | 2954 | EXPECT_CALL(mOutput, prepareFrame()); |
| 2955 | |
| 2956 | mOutput.devOptRepaintFlash(mRefreshArgs); |
| 2957 | } |
| 2958 | |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2959 | TEST_F(OutputDevOptRepaintFlashTest, postsAndPreparesANewFrameIfEnabled) { |
Lloyd Pique | db462d8 | 2019-11-19 17:58:46 -0800 | [diff] [blame] | 2960 | mRefreshArgs.devOptFlashDirtyRegionsDelay = std::chrono::microseconds(1); |
Lloyd Pique | db462d8 | 2019-11-19 17:58:46 -0800 | [diff] [blame] | 2961 | mOutput.mState.isEnabled = true; |
| 2962 | |
| 2963 | InSequence seq; |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2964 | EXPECT_CALL(mOutput, getDirtyRegion()).WillOnce(Return(kEmptyRegion)); |
Leon Scroggins III | a3ba7fa | 2024-05-22 16:34:52 -0400 | [diff] [blame] | 2965 | constexpr bool kFlushEvenWhenDisabled = false; |
| 2966 | EXPECT_CALL(mOutput, presentFrameAndReleaseLayers(kFlushEvenWhenDisabled)); |
Lloyd Pique | db462d8 | 2019-11-19 17:58:46 -0800 | [diff] [blame] | 2967 | EXPECT_CALL(mOutput, prepareFrame()); |
| 2968 | |
| 2969 | mOutput.devOptRepaintFlash(mRefreshArgs); |
| 2970 | } |
| 2971 | |
| 2972 | TEST_F(OutputDevOptRepaintFlashTest, alsoComposesSurfacesAndQueuesABufferIfDirty) { |
| 2973 | mRefreshArgs.devOptFlashDirtyRegionsDelay = std::chrono::microseconds(1); |
Lloyd Pique | db462d8 | 2019-11-19 17:58:46 -0800 | [diff] [blame] | 2974 | mOutput.mState.isEnabled = true; |
| 2975 | |
| 2976 | InSequence seq; |
Dominik Laskowski | 8da6b0e | 2021-05-12 15:34:13 -0700 | [diff] [blame] | 2977 | EXPECT_CALL(mOutput, getDirtyRegion()).WillOnce(Return(kNotEmptyRegion)); |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 2978 | EXPECT_CALL(mOutput, updateProtectedContentState()); |
| 2979 | EXPECT_CALL(mOutput, dequeueRenderBuffer(_, _)); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 2980 | EXPECT_CALL(mOutput, composeSurfaces(RegionEq(kNotEmptyRegion), _, _)); |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 2981 | EXPECT_CALL(*mRenderSurface, queueBuffer(_, 1.f)); |
Leon Scroggins III | a3ba7fa | 2024-05-22 16:34:52 -0400 | [diff] [blame] | 2982 | constexpr bool kFlushEvenWhenDisabled = false; |
| 2983 | EXPECT_CALL(mOutput, presentFrameAndReleaseLayers(kFlushEvenWhenDisabled)); |
Lloyd Pique | db462d8 | 2019-11-19 17:58:46 -0800 | [diff] [blame] | 2984 | EXPECT_CALL(mOutput, prepareFrame()); |
| 2985 | |
| 2986 | mOutput.devOptRepaintFlash(mRefreshArgs); |
| 2987 | } |
| 2988 | |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 2989 | /* |
| 2990 | * Output::finishFrame() |
| 2991 | */ |
| 2992 | |
Lloyd Pique | 03561a6 | 2019-11-19 18:34:52 -0800 | [diff] [blame] | 2993 | struct OutputFinishFrameTest : public testing::Test { |
| 2994 | struct OutputPartialMock : public OutputPartialMockBase { |
Lloyd Pique | 739afaf | 2019-11-21 16:40:05 -0800 | [diff] [blame] | 2995 | // Sets up the helper functions called by the function under test to use |
| 2996 | // mock implementations. |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 2997 | MOCK_METHOD3(composeSurfaces, |
| 2998 | std::optional<base::unique_fd>(const Region&, |
| 2999 | std::shared_ptr<renderengine::ExternalTexture>, |
| 3000 | base::unique_fd&)); |
Leon Scroggins III | a3ba7fa | 2024-05-22 16:34:52 -0400 | [diff] [blame] | 3001 | MOCK_METHOD(void, presentFrameAndReleaseLayers, (bool flushEvenWhenDisabled), (override)); |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 3002 | MOCK_METHOD0(updateProtectedContentState, void()); |
| 3003 | MOCK_METHOD2(dequeueRenderBuffer, |
| 3004 | bool(base::unique_fd*, std::shared_ptr<renderengine::ExternalTexture>*)); |
Xiang Wang | aab3116 | 2024-03-12 19:48:08 -0700 | [diff] [blame] | 3005 | MOCK_METHOD(void, setHintSessionGpuFence, (std::unique_ptr<FenceTime> && gpuFence), |
| 3006 | (override)); |
| 3007 | MOCK_METHOD(bool, isPowerHintSessionEnabled, (), (override)); |
Xiang Wang | cb50bbd | 2024-04-18 16:57:54 -0700 | [diff] [blame] | 3008 | MOCK_METHOD(bool, isPowerHintSessionGpuReportingEnabled, (), (override)); |
Lloyd Pique | 03561a6 | 2019-11-19 18:34:52 -0800 | [diff] [blame] | 3009 | }; |
| 3010 | |
| 3011 | OutputFinishFrameTest() { |
| 3012 | mOutput.setDisplayColorProfileForTest( |
| 3013 | std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile)); |
| 3014 | mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface)); |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 3015 | EXPECT_CALL(mOutput, getCompositionEngine()).WillRepeatedly(ReturnRef(mCompositionEngine)); |
| 3016 | EXPECT_CALL(mCompositionEngine, getRenderEngine()).WillRepeatedly(ReturnRef(mRenderEngine)); |
Xiang Wang | aab3116 | 2024-03-12 19:48:08 -0700 | [diff] [blame] | 3017 | EXPECT_CALL(mOutput, isPowerHintSessionEnabled()).WillRepeatedly(Return(true)); |
Xiang Wang | cb50bbd | 2024-04-18 16:57:54 -0700 | [diff] [blame] | 3018 | EXPECT_CALL(mOutput, isPowerHintSessionGpuReportingEnabled()).WillRepeatedly(Return(true)); |
Lloyd Pique | 03561a6 | 2019-11-19 18:34:52 -0800 | [diff] [blame] | 3019 | } |
| 3020 | |
| 3021 | StrictMock<OutputPartialMock> mOutput; |
| 3022 | mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>(); |
| 3023 | mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>(); |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 3024 | StrictMock<mock::CompositionEngine> mCompositionEngine; |
| 3025 | StrictMock<renderengine::mock::RenderEngine> mRenderEngine; |
Lloyd Pique | 03561a6 | 2019-11-19 18:34:52 -0800 | [diff] [blame] | 3026 | }; |
| 3027 | |
| 3028 | TEST_F(OutputFinishFrameTest, ifNotEnabledDoesNothing) { |
| 3029 | mOutput.mState.isEnabled = false; |
| 3030 | |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 3031 | impl::GpuCompositionResult result; |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 3032 | mOutput.finishFrame(std::move(result)); |
Lloyd Pique | 03561a6 | 2019-11-19 18:34:52 -0800 | [diff] [blame] | 3033 | } |
| 3034 | |
| 3035 | TEST_F(OutputFinishFrameTest, takesEarlyOutifComposeSurfacesReturnsNoFence) { |
| 3036 | mOutput.mState.isEnabled = true; |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 3037 | EXPECT_CALL(mOutput, updateProtectedContentState()); |
| 3038 | EXPECT_CALL(mOutput, dequeueRenderBuffer(_, _)).WillOnce(Return(true)); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 3039 | EXPECT_CALL(mOutput, composeSurfaces(RegionEq(Region::INVALID_REGION), _, _)); |
Lloyd Pique | 03561a6 | 2019-11-19 18:34:52 -0800 | [diff] [blame] | 3040 | |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 3041 | impl::GpuCompositionResult result; |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 3042 | mOutput.finishFrame(std::move(result)); |
Lloyd Pique | 03561a6 | 2019-11-19 18:34:52 -0800 | [diff] [blame] | 3043 | } |
| 3044 | |
Xiang Wang | cf61e73 | 2024-03-22 11:05:28 -0700 | [diff] [blame] | 3045 | TEST_F(OutputFinishFrameTest, queuesBufferIfComposeSurfacesReturnsAFenceWithAdpfGpuOff) { |
Xiang Wang | cb50bbd | 2024-04-18 16:57:54 -0700 | [diff] [blame] | 3046 | EXPECT_CALL(mOutput, isPowerHintSessionGpuReportingEnabled()).WillOnce(Return(false)); |
Lloyd Pique | 03561a6 | 2019-11-19 18:34:52 -0800 | [diff] [blame] | 3047 | mOutput.mState.isEnabled = true; |
| 3048 | |
| 3049 | InSequence seq; |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 3050 | EXPECT_CALL(mOutput, updateProtectedContentState()); |
| 3051 | EXPECT_CALL(mOutput, dequeueRenderBuffer(_, _)).WillOnce(Return(true)); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 3052 | EXPECT_CALL(mOutput, composeSurfaces(RegionEq(Region::INVALID_REGION), _, _)) |
Lloyd Pique | 03561a6 | 2019-11-19 18:34:52 -0800 | [diff] [blame] | 3053 | .WillOnce(Return(ByMove(base::unique_fd()))); |
Xiang Wang | aab3116 | 2024-03-12 19:48:08 -0700 | [diff] [blame] | 3054 | EXPECT_CALL(mOutput, setHintSessionGpuFence(_)); |
| 3055 | EXPECT_CALL(*mRenderSurface, queueBuffer(_, 1.f)); |
| 3056 | |
| 3057 | impl::GpuCompositionResult result; |
| 3058 | mOutput.finishFrame(std::move(result)); |
| 3059 | } |
| 3060 | |
Xiang Wang | cf61e73 | 2024-03-22 11:05:28 -0700 | [diff] [blame] | 3061 | TEST_F(OutputFinishFrameTest, queuesBufferIfComposeSurfacesReturnsAFence) { |
Xiang Wang | aab3116 | 2024-03-12 19:48:08 -0700 | [diff] [blame] | 3062 | mOutput.mState.isEnabled = true; |
| 3063 | |
| 3064 | InSequence seq; |
| 3065 | EXPECT_CALL(mOutput, updateProtectedContentState()); |
| 3066 | EXPECT_CALL(mOutput, dequeueRenderBuffer(_, _)).WillOnce(Return(true)); |
| 3067 | EXPECT_CALL(mOutput, composeSurfaces(RegionEq(Region::INVALID_REGION), _, _)) |
| 3068 | .WillOnce(Return(ByMove(base::unique_fd()))); |
| 3069 | EXPECT_CALL(mOutput, setHintSessionGpuFence(_)).Times(0); |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 3070 | EXPECT_CALL(*mRenderSurface, queueBuffer(_, 1.f)); |
| 3071 | |
| 3072 | impl::GpuCompositionResult result; |
| 3073 | mOutput.finishFrame(std::move(result)); |
| 3074 | } |
| 3075 | |
| 3076 | TEST_F(OutputFinishFrameTest, queuesBufferWithHdrSdrRatio) { |
| 3077 | SET_FLAG_FOR_TEST(flags::fp16_client_target, true); |
| 3078 | mOutput.mState.isEnabled = true; |
| 3079 | |
| 3080 | InSequence seq; |
| 3081 | auto texture = std::make_shared< |
| 3082 | renderengine::impl:: |
| 3083 | ExternalTexture>(sp<GraphicBuffer>::make(1u, 1u, PIXEL_FORMAT_RGBA_FP16, |
| 3084 | GRALLOC_USAGE_SW_WRITE_OFTEN | |
| 3085 | GRALLOC_USAGE_SW_READ_OFTEN), |
| 3086 | mRenderEngine, |
| 3087 | renderengine::impl::ExternalTexture::Usage::READABLE | |
| 3088 | renderengine::impl::ExternalTexture::Usage::WRITEABLE); |
| 3089 | mOutput.mState.displayBrightnessNits = 400.f; |
| 3090 | mOutput.mState.sdrWhitePointNits = 200.f; |
| 3091 | mOutput.mState.dataspace = ui::Dataspace::V0_SCRGB; |
| 3092 | EXPECT_CALL(mOutput, updateProtectedContentState()); |
| 3093 | EXPECT_CALL(mOutput, dequeueRenderBuffer(_, _)) |
| 3094 | .WillOnce(DoAll(SetArgPointee<1>(texture), Return(true))); |
| 3095 | EXPECT_CALL(mOutput, composeSurfaces(RegionEq(Region::INVALID_REGION), _, _)) |
| 3096 | .WillOnce(Return(ByMove(base::unique_fd()))); |
Xiang Wang | cf61e73 | 2024-03-22 11:05:28 -0700 | [diff] [blame] | 3097 | EXPECT_CALL(mOutput, setHintSessionGpuFence(_)).Times(0); |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 3098 | EXPECT_CALL(*mRenderSurface, queueBuffer(_, 2.f)); |
Lloyd Pique | 03561a6 | 2019-11-19 18:34:52 -0800 | [diff] [blame] | 3099 | |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 3100 | impl::GpuCompositionResult result; |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 3101 | mOutput.finishFrame(std::move(result)); |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 3102 | } |
| 3103 | |
| 3104 | TEST_F(OutputFinishFrameTest, predictionSucceeded) { |
| 3105 | mOutput.mState.isEnabled = true; |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 3106 | mOutput.mState.strategyPrediction = CompositionStrategyPredictionState::SUCCESS; |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 3107 | InSequence seq; |
Xiang Wang | cf61e73 | 2024-03-22 11:05:28 -0700 | [diff] [blame] | 3108 | EXPECT_CALL(mOutput, setHintSessionGpuFence(_)).Times(0); |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 3109 | EXPECT_CALL(*mRenderSurface, queueBuffer(_, 1.f)); |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 3110 | |
| 3111 | impl::GpuCompositionResult result; |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 3112 | mOutput.finishFrame(std::move(result)); |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 3113 | } |
| 3114 | |
| 3115 | TEST_F(OutputFinishFrameTest, predictionFailedAndBufferIsReused) { |
| 3116 | mOutput.mState.isEnabled = true; |
Vishnu Nair | 9cf8926 | 2022-02-26 09:17:49 -0800 | [diff] [blame] | 3117 | mOutput.mState.strategyPrediction = CompositionStrategyPredictionState::FAIL; |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 3118 | |
| 3119 | InSequence seq; |
| 3120 | |
| 3121 | impl::GpuCompositionResult result; |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 3122 | result.buffer = |
| 3123 | std::make_shared<renderengine::mock::FakeExternalTexture>(1, 1, |
| 3124 | HAL_PIXEL_FORMAT_RGBA_8888, 1, |
| 3125 | 2); |
| 3126 | |
| 3127 | EXPECT_CALL(mOutput, |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 3128 | composeSurfaces(RegionEq(Region::INVALID_REGION), result.buffer, |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 3129 | Eq(ByRef(result.fence)))) |
| 3130 | .WillOnce(Return(ByMove(base::unique_fd()))); |
Xiang Wang | cf61e73 | 2024-03-22 11:05:28 -0700 | [diff] [blame] | 3131 | EXPECT_CALL(mOutput, setHintSessionGpuFence(_)).Times(0); |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 3132 | EXPECT_CALL(*mRenderSurface, queueBuffer(_, 1.f)); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 3133 | mOutput.finishFrame(std::move(result)); |
Lloyd Pique | 03561a6 | 2019-11-19 18:34:52 -0800 | [diff] [blame] | 3134 | } |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 3135 | |
| 3136 | /* |
Leon Scroggins III | c1623d1 | 2023-11-06 15:31:05 -0500 | [diff] [blame] | 3137 | * Output::presentFrameAndReleaseLayers() |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 3138 | */ |
| 3139 | |
Lloyd Pique | 07178e3 | 2019-11-19 19:15:26 -0800 | [diff] [blame] | 3140 | struct OutputPostFramebufferTest : public testing::Test { |
| 3141 | struct OutputPartialMock : public OutputPartialMockBase { |
Lloyd Pique | 739afaf | 2019-11-21 16:40:05 -0800 | [diff] [blame] | 3142 | // Sets up the helper functions called by the function under test to use |
| 3143 | // mock implementations. |
Leon Scroggins III | a3ba7fa | 2024-05-22 16:34:52 -0400 | [diff] [blame] | 3144 | MOCK_METHOD(compositionengine::Output::FrameFences, presentFrame, ()); |
| 3145 | MOCK_METHOD(void, executeCommands, ()); |
Lloyd Pique | 07178e3 | 2019-11-19 19:15:26 -0800 | [diff] [blame] | 3146 | }; |
| 3147 | |
| 3148 | struct Layer { |
| 3149 | Layer() { |
Ady Abraham | eca9d75 | 2021-03-03 12:20:00 -0800 | [diff] [blame] | 3150 | EXPECT_CALL(outputLayer, getLayerFE()).WillRepeatedly(ReturnRef(*layerFE)); |
Lloyd Pique | 07178e3 | 2019-11-19 19:15:26 -0800 | [diff] [blame] | 3151 | EXPECT_CALL(outputLayer, getHwcLayer()).WillRepeatedly(Return(&hwc2Layer)); |
| 3152 | } |
| 3153 | |
| 3154 | StrictMock<mock::OutputLayer> outputLayer; |
Ady Abraham | eca9d75 | 2021-03-03 12:20:00 -0800 | [diff] [blame] | 3155 | sp<StrictMock<mock::LayerFE>> layerFE = sp<StrictMock<mock::LayerFE>>::make(); |
Lloyd Pique | 07178e3 | 2019-11-19 19:15:26 -0800 | [diff] [blame] | 3156 | StrictMock<HWC2::mock::Layer> hwc2Layer; |
| 3157 | }; |
| 3158 | |
| 3159 | OutputPostFramebufferTest() { |
| 3160 | mOutput.setDisplayColorProfileForTest( |
| 3161 | std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile)); |
| 3162 | mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface)); |
| 3163 | |
| 3164 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(3u)); |
| 3165 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0u)) |
| 3166 | .WillRepeatedly(Return(&mLayer1.outputLayer)); |
| 3167 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(1u)) |
| 3168 | .WillRepeatedly(Return(&mLayer2.outputLayer)); |
| 3169 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(2u)) |
| 3170 | .WillRepeatedly(Return(&mLayer3.outputLayer)); |
| 3171 | } |
| 3172 | |
| 3173 | StrictMock<OutputPartialMock> mOutput; |
| 3174 | mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>(); |
| 3175 | mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>(); |
| 3176 | |
| 3177 | Layer mLayer1; |
| 3178 | Layer mLayer2; |
| 3179 | Layer mLayer3; |
| 3180 | }; |
| 3181 | |
| 3182 | TEST_F(OutputPostFramebufferTest, ifNotEnabledDoesNothing) { |
Leon Scroggins III | a3ba7fa | 2024-05-22 16:34:52 -0400 | [diff] [blame] | 3183 | SET_FLAG_FOR_TEST(com::android::graphics::surfaceflinger::flags::flush_buffer_slots_to_uncache, |
| 3184 | true); |
Lloyd Pique | 07178e3 | 2019-11-19 19:15:26 -0800 | [diff] [blame] | 3185 | mOutput.mState.isEnabled = false; |
Leon Scroggins III | a3ba7fa | 2024-05-22 16:34:52 -0400 | [diff] [blame] | 3186 | EXPECT_CALL(mOutput, executeCommands()).Times(0); |
| 3187 | EXPECT_CALL(mOutput, presentFrame()).Times(0); |
Lloyd Pique | 07178e3 | 2019-11-19 19:15:26 -0800 | [diff] [blame] | 3188 | |
Leon Scroggins III | a3ba7fa | 2024-05-22 16:34:52 -0400 | [diff] [blame] | 3189 | constexpr bool kFlushEvenWhenDisabled = false; |
| 3190 | mOutput.presentFrameAndReleaseLayers(kFlushEvenWhenDisabled); |
| 3191 | } |
| 3192 | |
| 3193 | TEST_F(OutputPostFramebufferTest, ifNotEnabledExecutesCommandsIfFlush) { |
| 3194 | SET_FLAG_FOR_TEST(com::android::graphics::surfaceflinger::flags::flush_buffer_slots_to_uncache, |
| 3195 | true); |
| 3196 | mOutput.mState.isEnabled = false; |
| 3197 | EXPECT_CALL(mOutput, executeCommands()); |
| 3198 | EXPECT_CALL(mOutput, presentFrame()).Times(0); |
| 3199 | |
| 3200 | constexpr bool kFlushEvenWhenDisabled = true; |
| 3201 | mOutput.presentFrameAndReleaseLayers(kFlushEvenWhenDisabled); |
| 3202 | } |
| 3203 | |
| 3204 | TEST_F(OutputPostFramebufferTest, ifEnabledDoNotExecuteCommands) { |
| 3205 | SET_FLAG_FOR_TEST(com::android::graphics::surfaceflinger::flags::flush_buffer_slots_to_uncache, |
| 3206 | true); |
| 3207 | mOutput.mState.isEnabled = true; |
| 3208 | |
| 3209 | compositionengine::Output::FrameFences frameFences; |
| 3210 | |
| 3211 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u)); |
| 3212 | |
| 3213 | // This should only be called for disabled outputs. This test's goal is to verify this line; |
| 3214 | // the other expectations help satisfy the StrictMocks. |
| 3215 | EXPECT_CALL(mOutput, executeCommands()).Times(0); |
| 3216 | |
| 3217 | EXPECT_CALL(mOutput, presentFrame()).WillOnce(Return(frameFences)); |
| 3218 | EXPECT_CALL(*mRenderSurface, onPresentDisplayCompleted()); |
| 3219 | |
| 3220 | constexpr bool kFlushEvenWhenDisabled = true; |
| 3221 | mOutput.presentFrameAndReleaseLayers(kFlushEvenWhenDisabled); |
| 3222 | } |
| 3223 | |
| 3224 | TEST_F(OutputPostFramebufferTest, ifEnabledDoNotExecuteCommands2) { |
| 3225 | // Same test as ifEnabledDoNotExecuteCommands, but with this variable set to false. |
| 3226 | constexpr bool kFlushEvenWhenDisabled = false; |
| 3227 | |
| 3228 | SET_FLAG_FOR_TEST(com::android::graphics::surfaceflinger::flags::flush_buffer_slots_to_uncache, |
| 3229 | true); |
| 3230 | mOutput.mState.isEnabled = true; |
| 3231 | |
| 3232 | compositionengine::Output::FrameFences frameFences; |
| 3233 | |
| 3234 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u)); |
| 3235 | |
| 3236 | // This should only be called for disabled outputs. This test's goal is to verify this line; |
| 3237 | // the other expectations help satisfy the StrictMocks. |
| 3238 | EXPECT_CALL(mOutput, executeCommands()).Times(0); |
| 3239 | |
| 3240 | EXPECT_CALL(mOutput, presentFrame()).WillOnce(Return(frameFences)); |
| 3241 | EXPECT_CALL(*mRenderSurface, onPresentDisplayCompleted()); |
| 3242 | |
| 3243 | mOutput.presentFrameAndReleaseLayers(kFlushEvenWhenDisabled); |
Lloyd Pique | 07178e3 | 2019-11-19 19:15:26 -0800 | [diff] [blame] | 3244 | } |
| 3245 | |
| 3246 | TEST_F(OutputPostFramebufferTest, ifEnabledMustFlipThenPresentThenSendPresentCompleted) { |
| 3247 | mOutput.mState.isEnabled = true; |
| 3248 | |
| 3249 | compositionengine::Output::FrameFences frameFences; |
| 3250 | |
| 3251 | // This should happen even if there are no output layers. |
| 3252 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u)); |
| 3253 | |
| 3254 | // For this test in particular we want to make sure the call expectations |
| 3255 | // setup below are satisfied in the specific order. |
| 3256 | InSequence seq; |
| 3257 | |
Leon Scroggins III | c1623d1 | 2023-11-06 15:31:05 -0500 | [diff] [blame] | 3258 | EXPECT_CALL(mOutput, presentFrame()).WillOnce(Return(frameFences)); |
Lloyd Pique | 07178e3 | 2019-11-19 19:15:26 -0800 | [diff] [blame] | 3259 | EXPECT_CALL(*mRenderSurface, onPresentDisplayCompleted()); |
| 3260 | |
Leon Scroggins III | a3ba7fa | 2024-05-22 16:34:52 -0400 | [diff] [blame] | 3261 | constexpr bool kFlushEvenWhenDisabled = true; |
| 3262 | mOutput.presentFrameAndReleaseLayers(kFlushEvenWhenDisabled); |
Lloyd Pique | 07178e3 | 2019-11-19 19:15:26 -0800 | [diff] [blame] | 3263 | } |
| 3264 | |
Melody Hsu | 793f836 | 2024-01-08 20:00:35 +0000 | [diff] [blame] | 3265 | TEST_F(OutputPostFramebufferTest, releaseFencesAreSetInLayerFE) { |
Melody Hsu | 793f836 | 2024-01-08 20:00:35 +0000 | [diff] [blame] | 3266 | // Simulate getting release fences from each layer, and ensure they are passed to the |
| 3267 | // front-end layer interface for each layer correctly. |
Melody Hsu | 793f836 | 2024-01-08 20:00:35 +0000 | [diff] [blame] | 3268 | mOutput.mState.isEnabled = true; |
| 3269 | |
| 3270 | // Create three unique fence instances |
| 3271 | sp<Fence> layer1Fence = sp<Fence>::make(); |
| 3272 | sp<Fence> layer2Fence = sp<Fence>::make(); |
| 3273 | sp<Fence> layer3Fence = sp<Fence>::make(); |
| 3274 | |
| 3275 | Output::FrameFences frameFences; |
| 3276 | frameFences.layerFences.emplace(&mLayer1.hwc2Layer, layer1Fence); |
| 3277 | frameFences.layerFences.emplace(&mLayer2.hwc2Layer, layer2Fence); |
| 3278 | frameFences.layerFences.emplace(&mLayer3.hwc2Layer, layer3Fence); |
| 3279 | |
| 3280 | EXPECT_CALL(mOutput, presentFrame()).WillOnce(Return(frameFences)); |
| 3281 | EXPECT_CALL(*mRenderSurface, onPresentDisplayCompleted()); |
| 3282 | |
| 3283 | // Compare the pointers values of each fence to make sure the correct ones |
| 3284 | // are passed. This happens to work with the current implementation, but |
| 3285 | // would not survive certain calls like Fence::merge() which would return a |
| 3286 | // new instance. |
| 3287 | EXPECT_CALL(*mLayer1.layerFE, setReleaseFence(_)) |
| 3288 | .WillOnce([&layer1Fence](FenceResult releaseFence) { |
| 3289 | EXPECT_EQ(FenceResult(layer1Fence), releaseFence); |
| 3290 | }); |
| 3291 | EXPECT_CALL(*mLayer2.layerFE, setReleaseFence(_)) |
| 3292 | .WillOnce([&layer2Fence](FenceResult releaseFence) { |
| 3293 | EXPECT_EQ(FenceResult(layer2Fence), releaseFence); |
| 3294 | }); |
| 3295 | EXPECT_CALL(*mLayer3.layerFE, setReleaseFence(_)) |
| 3296 | .WillOnce([&layer3Fence](FenceResult releaseFence) { |
| 3297 | EXPECT_EQ(FenceResult(layer3Fence), releaseFence); |
| 3298 | }); |
| 3299 | |
Leon Scroggins III | a3ba7fa | 2024-05-22 16:34:52 -0400 | [diff] [blame] | 3300 | constexpr bool kFlushEvenWhenDisabled = false; |
| 3301 | mOutput.presentFrameAndReleaseLayers(kFlushEvenWhenDisabled); |
Melody Hsu | 793f836 | 2024-01-08 20:00:35 +0000 | [diff] [blame] | 3302 | } |
| 3303 | |
Melody Hsu | 793f836 | 2024-01-08 20:00:35 +0000 | [diff] [blame] | 3304 | TEST_F(OutputPostFramebufferTest, setReleaseFencesIncludeClientTargetAcquireFence) { |
Melody Hsu | 793f836 | 2024-01-08 20:00:35 +0000 | [diff] [blame] | 3305 | mOutput.mState.isEnabled = true; |
| 3306 | mOutput.mState.usesClientComposition = true; |
| 3307 | |
| 3308 | Output::FrameFences frameFences; |
| 3309 | frameFences.clientTargetAcquireFence = sp<Fence>::make(); |
| 3310 | frameFences.layerFences.emplace(&mLayer1.hwc2Layer, sp<Fence>::make()); |
| 3311 | frameFences.layerFences.emplace(&mLayer2.hwc2Layer, sp<Fence>::make()); |
| 3312 | frameFences.layerFences.emplace(&mLayer3.hwc2Layer, sp<Fence>::make()); |
| 3313 | |
| 3314 | EXPECT_CALL(mOutput, presentFrame()).WillOnce(Return(frameFences)); |
| 3315 | EXPECT_CALL(*mRenderSurface, onPresentDisplayCompleted()); |
| 3316 | |
| 3317 | // Fence::merge is called, and since none of the fences are actually valid, |
| 3318 | // Fence::NO_FENCE is returned and passed to each setReleaseFence() call. |
| 3319 | // This is the best we can do without creating a real kernel fence object. |
| 3320 | EXPECT_CALL(*mLayer1.layerFE, setReleaseFence).WillOnce(Return()); |
| 3321 | EXPECT_CALL(*mLayer2.layerFE, setReleaseFence).WillOnce(Return()); |
| 3322 | EXPECT_CALL(*mLayer3.layerFE, setReleaseFence).WillOnce(Return()); |
Leon Scroggins III | a3ba7fa | 2024-05-22 16:34:52 -0400 | [diff] [blame] | 3323 | constexpr bool kFlushEvenWhenDisabled = false; |
| 3324 | mOutput.presentFrameAndReleaseLayers(kFlushEvenWhenDisabled); |
Melody Hsu | 793f836 | 2024-01-08 20:00:35 +0000 | [diff] [blame] | 3325 | } |
| 3326 | |
Melody Hsu | 793f836 | 2024-01-08 20:00:35 +0000 | [diff] [blame] | 3327 | TEST_F(OutputPostFramebufferTest, setReleasedLayersSentPresentFence) { |
Melody Hsu | 793f836 | 2024-01-08 20:00:35 +0000 | [diff] [blame] | 3328 | mOutput.mState.isEnabled = true; |
| 3329 | mOutput.mState.usesClientComposition = true; |
| 3330 | |
| 3331 | // This should happen even if there are no (current) output layers. |
| 3332 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u)); |
| 3333 | |
| 3334 | // Load up the released layers with some mock instances |
| 3335 | sp<StrictMock<mock::LayerFE>> releasedLayer1 = sp<StrictMock<mock::LayerFE>>::make(); |
| 3336 | sp<StrictMock<mock::LayerFE>> releasedLayer2 = sp<StrictMock<mock::LayerFE>>::make(); |
| 3337 | sp<StrictMock<mock::LayerFE>> releasedLayer3 = sp<StrictMock<mock::LayerFE>>::make(); |
| 3338 | Output::ReleasedLayers layers; |
| 3339 | layers.push_back(releasedLayer1); |
| 3340 | layers.push_back(releasedLayer2); |
| 3341 | layers.push_back(releasedLayer3); |
| 3342 | mOutput.setReleasedLayers(std::move(layers)); |
| 3343 | |
| 3344 | // Set up a fake present fence |
| 3345 | sp<Fence> presentFence = sp<Fence>::make(); |
| 3346 | Output::FrameFences frameFences; |
| 3347 | frameFences.presentFence = presentFence; |
| 3348 | |
| 3349 | EXPECT_CALL(mOutput, presentFrame()).WillOnce(Return(frameFences)); |
| 3350 | EXPECT_CALL(*mRenderSurface, onPresentDisplayCompleted()); |
| 3351 | |
| 3352 | // Each released layer should be given the presentFence. |
| 3353 | EXPECT_CALL(*releasedLayer1, setReleaseFence(_)) |
| 3354 | .WillOnce([&presentFence](FenceResult fenceResult) { |
| 3355 | EXPECT_EQ(FenceResult(presentFence), fenceResult); |
| 3356 | }); |
| 3357 | EXPECT_CALL(*releasedLayer2, setReleaseFence(_)) |
| 3358 | .WillOnce([&presentFence](FenceResult fenceResult) { |
| 3359 | EXPECT_EQ(FenceResult(presentFence), fenceResult); |
| 3360 | }); |
| 3361 | EXPECT_CALL(*releasedLayer3, setReleaseFence(_)) |
| 3362 | .WillOnce([&presentFence](FenceResult fenceResult) { |
| 3363 | EXPECT_EQ(FenceResult(presentFence), fenceResult); |
| 3364 | }); |
| 3365 | |
Leon Scroggins III | a3ba7fa | 2024-05-22 16:34:52 -0400 | [diff] [blame] | 3366 | constexpr bool kFlushEvenWhenDisabled = false; |
| 3367 | mOutput.presentFrameAndReleaseLayers(kFlushEvenWhenDisabled); |
Melody Hsu | 793f836 | 2024-01-08 20:00:35 +0000 | [diff] [blame] | 3368 | |
| 3369 | // After the call the list of released layers should have been cleared. |
| 3370 | EXPECT_TRUE(mOutput.getReleasedLayersForTest().empty()); |
| 3371 | } |
| 3372 | |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 3373 | /* |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 3374 | * Output::composeSurfaces() |
| 3375 | */ |
| 3376 | |
| 3377 | struct OutputComposeSurfacesTest : public testing::Test { |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3378 | using TestType = OutputComposeSurfacesTest; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 3379 | |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 3380 | struct OutputPartialMock : public OutputPartialMockBase { |
Lloyd Pique | 739afaf | 2019-11-21 16:40:05 -0800 | [diff] [blame] | 3381 | // Sets up the helper functions called by the function under test to use |
| 3382 | // mock implementations. |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 3383 | MOCK_CONST_METHOD0(getSkipColorTransform, bool()); |
Robert Carr | ccab424 | 2021-09-28 16:53:03 -0700 | [diff] [blame] | 3384 | MOCK_METHOD3(generateClientCompositionRequests, |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 3385 | std::vector<LayerFE::LayerSettings>(bool, ui::Dataspace, |
| 3386 | std::vector<LayerFE*>&)); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 3387 | MOCK_METHOD2(appendRegionFlashRequests, |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 3388 | void(const Region&, std::vector<LayerFE::LayerSettings>&)); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 3389 | MOCK_METHOD1(setExpensiveRenderingExpected, void(bool)); |
Xiang Wang | aab3116 | 2024-03-12 19:48:08 -0700 | [diff] [blame] | 3390 | MOCK_METHOD(void, setHintSessionGpuStart, (TimePoint startTime), (override)); |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 3391 | MOCK_METHOD(void, setHintSessionGpuFence, (std::unique_ptr<FenceTime> && gpuFence), |
| 3392 | (override)); |
Xiang Wang | aab3116 | 2024-03-12 19:48:08 -0700 | [diff] [blame] | 3393 | MOCK_METHOD(void, setHintSessionRequiresRenderEngine, (bool), (override)); |
Matt Buckley | 50c4406 | 2022-01-17 20:48:10 +0000 | [diff] [blame] | 3394 | MOCK_METHOD(bool, isPowerHintSessionEnabled, (), (override)); |
Xiang Wang | cb50bbd | 2024-04-18 16:57:54 -0700 | [diff] [blame] | 3395 | MOCK_METHOD(bool, isPowerHintSessionGpuReportingEnabled, (), (override)); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 3396 | }; |
| 3397 | |
| 3398 | OutputComposeSurfacesTest() { |
| 3399 | mOutput.setDisplayColorProfileForTest( |
| 3400 | std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile)); |
| 3401 | mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface)); |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 3402 | mOutput.cacheClientCompositionRequests(MAX_CLIENT_COMPOSITION_CACHE_SIZE); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 3403 | |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 3404 | mOutput.mState.orientedDisplaySpace.setContent(kDefaultOutputFrame); |
| 3405 | mOutput.mState.layerStackSpace.setContent(kDefaultOutputViewport); |
| 3406 | mOutput.mState.framebufferSpace.setContent(kDefaultOutputDestinationClip); |
| 3407 | mOutput.mState.displaySpace.setContent(kDefaultOutputDestinationClip); |
| 3408 | mOutput.mState.displaySpace.setOrientation(kDefaultOutputOrientation); |
Marin Shalamanov | b15d227 | 2020-09-17 21:41:52 +0200 | [diff] [blame] | 3409 | mOutput.mState.transform = ui::Transform{kDefaultOutputOrientationFlags}; |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3410 | mOutput.mState.dataspace = kDefaultOutputDataspace; |
| 3411 | mOutput.mState.colorTransformMatrix = kDefaultColorTransformMat; |
| 3412 | mOutput.mState.isSecure = false; |
| 3413 | mOutput.mState.needsFiltering = false; |
| 3414 | mOutput.mState.usesClientComposition = true; |
| 3415 | mOutput.mState.usesDeviceComposition = false; |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 3416 | mOutput.mState.reusedClientComposition = false; |
Lloyd Pique | e9eff97 | 2020-05-05 12:36:44 -0700 | [diff] [blame] | 3417 | mOutput.mState.flipClientTarget = false; |
Alec Mouri | f8d093d | 2022-02-10 15:16:59 -0800 | [diff] [blame] | 3418 | mOutput.mState.clientTargetBrightness = kClientTargetBrightness; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 3419 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 3420 | EXPECT_CALL(mOutput, getCompositionEngine()).WillRepeatedly(ReturnRef(mCompositionEngine)); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 3421 | EXPECT_CALL(mCompositionEngine, getRenderEngine()).WillRepeatedly(ReturnRef(mRenderEngine)); |
Patrick Williams | 74c0bf6 | 2022-11-02 23:59:26 +0000 | [diff] [blame] | 3422 | EXPECT_CALL(mCompositionEngine, getTimeStats()).WillRepeatedly(Return(mTimeStats.get())); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3423 | EXPECT_CALL(*mDisplayColorProfile, getHdrCapabilities()) |
| 3424 | .WillRepeatedly(ReturnRef(kHdrCapabilities)); |
Xiang Wang | aab3116 | 2024-03-12 19:48:08 -0700 | [diff] [blame] | 3425 | EXPECT_CALL(mOutput, isPowerHintSessionEnabled()).WillRepeatedly(Return(true)); |
Xiang Wang | cb50bbd | 2024-04-18 16:57:54 -0700 | [diff] [blame] | 3426 | EXPECT_CALL(mOutput, isPowerHintSessionGpuReportingEnabled()).WillRepeatedly(Return(true)); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 3427 | } |
| 3428 | |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3429 | struct ExecuteState : public CallOrderStateMachineHelper<TestType, ExecuteState> { |
| 3430 | auto execute() { |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 3431 | base::unique_fd fence; |
| 3432 | std::shared_ptr<renderengine::ExternalTexture> externalTexture; |
| 3433 | const bool success = |
| 3434 | getInstance()->mOutput.dequeueRenderBuffer(&fence, &externalTexture); |
| 3435 | if (success) { |
| 3436 | getInstance()->mReadyFence = |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 3437 | getInstance()->mOutput.composeSurfaces(kDebugRegion, externalTexture, |
| 3438 | fence); |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 3439 | } |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3440 | return nextState<FenceCheckState>(); |
| 3441 | } |
| 3442 | }; |
| 3443 | |
| 3444 | struct FenceCheckState : public CallOrderStateMachineHelper<TestType, FenceCheckState> { |
| 3445 | void expectNoFenceWasReturned() { EXPECT_FALSE(getInstance()->mReadyFence); } |
| 3446 | |
| 3447 | void expectAFenceWasReturned() { EXPECT_TRUE(getInstance()->mReadyFence); } |
| 3448 | }; |
| 3449 | |
| 3450 | // Call this member function to start using the mini-DSL defined above. |
| 3451 | [[nodiscard]] auto verify() { return ExecuteState::make(this); } |
| 3452 | |
Marin Shalamanov | 68933fb | 2020-09-10 17:58:12 +0200 | [diff] [blame] | 3453 | static constexpr ui::Rotation kDefaultOutputOrientation = ui::ROTATION_0; |
| 3454 | static constexpr uint32_t kDefaultOutputOrientationFlags = |
| 3455 | ui::Transform::toRotationFlags(kDefaultOutputOrientation); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3456 | static constexpr ui::Dataspace kDefaultOutputDataspace = ui::Dataspace::UNKNOWN; |
| 3457 | static constexpr ui::Dataspace kExpensiveOutputDataspace = ui::Dataspace::DISPLAY_P3; |
| 3458 | static constexpr float kDefaultMaxLuminance = 0.9f; |
| 3459 | static constexpr float kDefaultAvgLuminance = 0.7f; |
| 3460 | static constexpr float kDefaultMinLuminance = 0.1f; |
Alec Mouri | f8d093d | 2022-02-10 15:16:59 -0800 | [diff] [blame] | 3461 | static constexpr float kDisplayLuminance = 400.f; |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 3462 | static constexpr float kWhitePointLuminance = 300.f; |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 3463 | static constexpr float kClientTargetLuminanceNits = 200.f; |
Alec Mouri | f8d093d | 2022-02-10 15:16:59 -0800 | [diff] [blame] | 3464 | static constexpr float kClientTargetBrightness = 0.5f; |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3465 | |
| 3466 | static const Rect kDefaultOutputFrame; |
| 3467 | static const Rect kDefaultOutputViewport; |
Lloyd Pique | e8fe474 | 2020-01-21 15:26:18 -0800 | [diff] [blame] | 3468 | static const Rect kDefaultOutputDestinationClip; |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3469 | static const mat4 kDefaultColorTransformMat; |
| 3470 | |
| 3471 | static const Region kDebugRegion; |
| 3472 | static const HdrCapabilities kHdrCapabilities; |
| 3473 | |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 3474 | StrictMock<mock::CompositionEngine> mCompositionEngine; |
| 3475 | StrictMock<renderengine::mock::RenderEngine> mRenderEngine; |
Alec Mouri | e4034bb | 2019-11-19 12:45:54 -0800 | [diff] [blame] | 3476 | // TODO: make this is a proper mock. |
| 3477 | std::shared_ptr<TimeStats> mTimeStats = std::make_shared<android::impl::TimeStats>(); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 3478 | mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>(); |
| 3479 | mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>(); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 3480 | StrictMock<OutputPartialMock> mOutput; |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 3481 | std::shared_ptr<renderengine::ExternalTexture> mOutputBuffer = std::make_shared< |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 3482 | renderengine::impl:: |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 3483 | ExternalTexture>(sp<GraphicBuffer>::make(), mRenderEngine, |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 3484 | renderengine::impl::ExternalTexture::Usage::READABLE | |
| 3485 | renderengine::impl::ExternalTexture::Usage::WRITEABLE); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3486 | |
| 3487 | std::optional<base::unique_fd> mReadyFence; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 3488 | }; |
| 3489 | |
| 3490 | const Rect OutputComposeSurfacesTest::kDefaultOutputFrame{1001, 1002, 1003, 1004}; |
| 3491 | const Rect OutputComposeSurfacesTest::kDefaultOutputViewport{1005, 1006, 1007, 1008}; |
Lloyd Pique | e8fe474 | 2020-01-21 15:26:18 -0800 | [diff] [blame] | 3492 | const Rect OutputComposeSurfacesTest::kDefaultOutputDestinationClip{1013, 1014, 1015, 1016}; |
Lloyd Pique | 0a45623 | 2020-01-16 17:51:13 -0800 | [diff] [blame] | 3493 | const mat4 OutputComposeSurfacesTest::kDefaultColorTransformMat{mat4() * 0.5f}; |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3494 | const Region OutputComposeSurfacesTest::kDebugRegion{Rect{100, 101, 102, 103}}; |
Alec Mouri | b21d94e | 2022-01-13 17:44:10 -0800 | [diff] [blame] | 3495 | |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3496 | const HdrCapabilities OutputComposeSurfacesTest:: |
| 3497 | kHdrCapabilities{{}, |
| 3498 | OutputComposeSurfacesTest::kDefaultMaxLuminance, |
| 3499 | OutputComposeSurfacesTest::kDefaultAvgLuminance, |
| 3500 | OutputComposeSurfacesTest::kDefaultMinLuminance}; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 3501 | |
Lloyd Pique | a76ce46 | 2020-01-14 13:06:37 -0800 | [diff] [blame] | 3502 | TEST_F(OutputComposeSurfacesTest, doesNothingButSignalNoExpensiveRenderingIfNoClientComposition) { |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3503 | mOutput.mState.usesClientComposition = false; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 3504 | |
Lloyd Pique | e9eff97 | 2020-05-05 12:36:44 -0700 | [diff] [blame] | 3505 | EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false)); |
Peiyong Lin | 09f910f | 2020-09-25 10:54:13 -0700 | [diff] [blame] | 3506 | EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false)); |
Lloyd Pique | e9eff97 | 2020-05-05 12:36:44 -0700 | [diff] [blame] | 3507 | |
Lloyd Pique | a76ce46 | 2020-01-14 13:06:37 -0800 | [diff] [blame] | 3508 | EXPECT_CALL(mOutput, setExpensiveRenderingExpected(false)); |
| 3509 | |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3510 | verify().execute().expectAFenceWasReturned(); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 3511 | } |
| 3512 | |
Lloyd Pique | e9eff97 | 2020-05-05 12:36:44 -0700 | [diff] [blame] | 3513 | TEST_F(OutputComposeSurfacesTest, |
| 3514 | dequeuesABufferIfNoClientCompositionButFlipClientTargetRequested) { |
| 3515 | mOutput.mState.usesClientComposition = false; |
| 3516 | mOutput.mState.flipClientTarget = true; |
| 3517 | |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3518 | EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false)); |
Peiyong Lin | 09f910f | 2020-09-25 10:54:13 -0700 | [diff] [blame] | 3519 | EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false)); |
Lloyd Pique | e9eff97 | 2020-05-05 12:36:44 -0700 | [diff] [blame] | 3520 | |
| 3521 | EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillOnce(Return(mOutputBuffer)); |
| 3522 | EXPECT_CALL(mOutput, setExpensiveRenderingExpected(false)); |
| 3523 | |
| 3524 | verify().execute().expectAFenceWasReturned(); |
| 3525 | } |
| 3526 | |
| 3527 | TEST_F(OutputComposeSurfacesTest, doesMinimalWorkIfDequeueBufferFailsForClientComposition) { |
| 3528 | EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false)); |
Peiyong Lin | 09f910f | 2020-09-25 10:54:13 -0700 | [diff] [blame] | 3529 | EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false)); |
Lloyd Pique | e9eff97 | 2020-05-05 12:36:44 -0700 | [diff] [blame] | 3530 | |
| 3531 | EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillOnce(Return(nullptr)); |
| 3532 | |
| 3533 | verify().execute().expectNoFenceWasReturned(); |
| 3534 | } |
| 3535 | |
| 3536 | TEST_F(OutputComposeSurfacesTest, |
| 3537 | doesMinimalWorkIfDequeueBufferFailsForNoClientCompositionButFlipClientTargetRequested) { |
| 3538 | mOutput.mState.usesClientComposition = false; |
| 3539 | mOutput.mState.flipClientTarget = true; |
| 3540 | |
| 3541 | EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false)); |
Peiyong Lin | 09f910f | 2020-09-25 10:54:13 -0700 | [diff] [blame] | 3542 | EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false)); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 3543 | |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3544 | EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillOnce(Return(nullptr)); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 3545 | |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3546 | verify().execute().expectNoFenceWasReturned(); |
| 3547 | } |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 3548 | |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3549 | TEST_F(OutputComposeSurfacesTest, handlesZeroCompositionRequests) { |
| 3550 | EXPECT_CALL(mOutput, getSkipColorTransform()).WillRepeatedly(Return(false)); |
| 3551 | EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillRepeatedly(Return(true)); |
| 3552 | EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false)); |
Peiyong Lin | 09f910f | 2020-09-25 10:54:13 -0700 | [diff] [blame] | 3553 | EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false)); |
Robert Carr | ccab424 | 2021-09-28 16:53:03 -0700 | [diff] [blame] | 3554 | EXPECT_CALL(mOutput, generateClientCompositionRequests(_, kDefaultOutputDataspace, _)) |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 3555 | .WillRepeatedly(Return(std::vector<LayerFE::LayerSettings>{})); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3556 | EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _)) |
| 3557 | .WillRepeatedly(Return()); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 3558 | |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3559 | EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer)); |
Alec Mouri | f29700f | 2023-08-17 21:53:31 +0000 | [diff] [blame] | 3560 | EXPECT_CALL(mRenderEngine, drawLayers(_, IsEmpty(), _, _)) |
Sally Qi | 4cabdd0 | 2021-08-05 16:45:57 -0700 | [diff] [blame] | 3561 | .WillRepeatedly([&](const renderengine::DisplaySettings&, |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 3562 | const std::vector<renderengine::LayerSettings>&, |
Alec Mouri | f29700f | 2023-08-17 21:53:31 +0000 | [diff] [blame] | 3563 | const std::shared_ptr<renderengine::ExternalTexture>&, |
Patrick Williams | 2e9748f | 2022-08-09 22:48:18 +0000 | [diff] [blame] | 3564 | base::unique_fd&&) -> ftl::Future<FenceResult> { |
| 3565 | return ftl::yield<FenceResult>(Fence::NO_FENCE); |
Sally Qi | 4cabdd0 | 2021-08-05 16:45:57 -0700 | [diff] [blame] | 3566 | }); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3567 | verify().execute().expectAFenceWasReturned(); |
| 3568 | } |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 3569 | |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3570 | TEST_F(OutputComposeSurfacesTest, buildsAndRendersRequestList) { |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 3571 | LayerFE::LayerSettings r1; |
| 3572 | LayerFE::LayerSettings r2; |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3573 | |
| 3574 | r1.geometry.boundaries = FloatRect{1, 2, 3, 4}; |
| 3575 | r2.geometry.boundaries = FloatRect{5, 6, 7, 8}; |
| 3576 | |
| 3577 | EXPECT_CALL(mOutput, getSkipColorTransform()).WillRepeatedly(Return(false)); |
| 3578 | EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillRepeatedly(Return(true)); |
| 3579 | EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false)); |
Peiyong Lin | 09f910f | 2020-09-25 10:54:13 -0700 | [diff] [blame] | 3580 | EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false)); |
Robert Carr | ccab424 | 2021-09-28 16:53:03 -0700 | [diff] [blame] | 3581 | EXPECT_CALL(mOutput, generateClientCompositionRequests(_, kDefaultOutputDataspace, _)) |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 3582 | .WillRepeatedly(Return(std::vector<LayerFE::LayerSettings>{r1})); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3583 | EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _)) |
| 3584 | .WillRepeatedly( |
| 3585 | Invoke([&](const Region&, |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 3586 | std::vector<LayerFE::LayerSettings>& clientCompositionLayers) { |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3587 | clientCompositionLayers.emplace_back(r2); |
| 3588 | })); |
| 3589 | |
| 3590 | EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer)); |
Alec Mouri | f29700f | 2023-08-17 21:53:31 +0000 | [diff] [blame] | 3591 | EXPECT_CALL(mRenderEngine, drawLayers(_, ElementsAre(r1, r2), _, _)) |
Sally Qi | 4cabdd0 | 2021-08-05 16:45:57 -0700 | [diff] [blame] | 3592 | .WillRepeatedly([&](const renderengine::DisplaySettings&, |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 3593 | const std::vector<renderengine::LayerSettings>&, |
Alec Mouri | f29700f | 2023-08-17 21:53:31 +0000 | [diff] [blame] | 3594 | const std::shared_ptr<renderengine::ExternalTexture>&, |
Patrick Williams | 2e9748f | 2022-08-09 22:48:18 +0000 | [diff] [blame] | 3595 | base::unique_fd&&) -> ftl::Future<FenceResult> { |
| 3596 | return ftl::yield<FenceResult>(Fence::NO_FENCE); |
Sally Qi | 4cabdd0 | 2021-08-05 16:45:57 -0700 | [diff] [blame] | 3597 | }); |
Alec Mouri | 1684c70 | 2021-02-04 12:27:26 -0800 | [diff] [blame] | 3598 | |
| 3599 | verify().execute().expectAFenceWasReturned(); |
| 3600 | } |
| 3601 | |
| 3602 | TEST_F(OutputComposeSurfacesTest, |
| 3603 | buildsAndRendersRequestListAndCachesFramebufferForInternalLayers) { |
| 3604 | LayerFE::LayerSettings r1; |
| 3605 | LayerFE::LayerSettings r2; |
| 3606 | |
| 3607 | r1.geometry.boundaries = FloatRect{1, 2, 3, 4}; |
| 3608 | r2.geometry.boundaries = FloatRect{5, 6, 7, 8}; |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 3609 | mOutput.setLayerFilter({ui::LayerStack{1234u}, true}); |
Alec Mouri | 1684c70 | 2021-02-04 12:27:26 -0800 | [diff] [blame] | 3610 | |
| 3611 | EXPECT_CALL(mOutput, getSkipColorTransform()).WillRepeatedly(Return(false)); |
| 3612 | EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillRepeatedly(Return(true)); |
| 3613 | EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false)); |
| 3614 | EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false)); |
Robert Carr | ccab424 | 2021-09-28 16:53:03 -0700 | [diff] [blame] | 3615 | EXPECT_CALL(mOutput, generateClientCompositionRequests(_, kDefaultOutputDataspace, _)) |
Alec Mouri | 1684c70 | 2021-02-04 12:27:26 -0800 | [diff] [blame] | 3616 | .WillRepeatedly(Return(std::vector<LayerFE::LayerSettings>{r1})); |
| 3617 | EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _)) |
| 3618 | .WillRepeatedly( |
| 3619 | Invoke([&](const Region&, |
| 3620 | std::vector<LayerFE::LayerSettings>& clientCompositionLayers) { |
| 3621 | clientCompositionLayers.emplace_back(r2); |
| 3622 | })); |
| 3623 | |
| 3624 | EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer)); |
Alec Mouri | f29700f | 2023-08-17 21:53:31 +0000 | [diff] [blame] | 3625 | EXPECT_CALL(mRenderEngine, drawLayers(_, ElementsAre(r1, r2), _, _)) |
Sally Qi | 4cabdd0 | 2021-08-05 16:45:57 -0700 | [diff] [blame] | 3626 | .WillRepeatedly([&](const renderengine::DisplaySettings&, |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 3627 | const std::vector<renderengine::LayerSettings>&, |
Alec Mouri | f29700f | 2023-08-17 21:53:31 +0000 | [diff] [blame] | 3628 | const std::shared_ptr<renderengine::ExternalTexture>&, |
Patrick Williams | 2e9748f | 2022-08-09 22:48:18 +0000 | [diff] [blame] | 3629 | base::unique_fd&&) -> ftl::Future<FenceResult> { |
| 3630 | return ftl::yield<FenceResult>(Fence::NO_FENCE); |
Sally Qi | 4cabdd0 | 2021-08-05 16:45:57 -0700 | [diff] [blame] | 3631 | }); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3632 | |
| 3633 | verify().execute().expectAFenceWasReturned(); |
| 3634 | } |
| 3635 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 3636 | TEST_F(OutputComposeSurfacesTest, renderDuplicateClientCompositionRequestsWithoutCache) { |
| 3637 | mOutput.cacheClientCompositionRequests(0); |
| 3638 | LayerFE::LayerSettings r1; |
| 3639 | LayerFE::LayerSettings r2; |
| 3640 | |
| 3641 | r1.geometry.boundaries = FloatRect{1, 2, 3, 4}; |
| 3642 | r2.geometry.boundaries = FloatRect{5, 6, 7, 8}; |
| 3643 | |
| 3644 | EXPECT_CALL(mOutput, getSkipColorTransform()).WillRepeatedly(Return(false)); |
| 3645 | EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillRepeatedly(Return(true)); |
| 3646 | EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false)); |
Peiyong Lin | 09f910f | 2020-09-25 10:54:13 -0700 | [diff] [blame] | 3647 | EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false)); |
Robert Carr | ccab424 | 2021-09-28 16:53:03 -0700 | [diff] [blame] | 3648 | EXPECT_CALL(mOutput, generateClientCompositionRequests(_, kDefaultOutputDataspace, _)) |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 3649 | .WillRepeatedly(Return(std::vector<LayerFE::LayerSettings>{r1, r2})); |
| 3650 | EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _)) |
| 3651 | .WillRepeatedly(Return()); |
| 3652 | |
| 3653 | EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer)); |
Alec Mouri | f29700f | 2023-08-17 21:53:31 +0000 | [diff] [blame] | 3654 | EXPECT_CALL(mRenderEngine, drawLayers(_, ElementsAre(r1, r2), _, _)) |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 3655 | .Times(2) |
Patrick Williams | 2e9748f | 2022-08-09 22:48:18 +0000 | [diff] [blame] | 3656 | .WillOnce(Return(ByMove(ftl::yield<FenceResult>(Fence::NO_FENCE)))) |
| 3657 | .WillOnce(Return(ByMove(ftl::yield<FenceResult>(Fence::NO_FENCE)))); |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 3658 | |
| 3659 | verify().execute().expectAFenceWasReturned(); |
| 3660 | EXPECT_FALSE(mOutput.mState.reusedClientComposition); |
| 3661 | |
| 3662 | verify().execute().expectAFenceWasReturned(); |
| 3663 | EXPECT_FALSE(mOutput.mState.reusedClientComposition); |
| 3664 | } |
| 3665 | |
| 3666 | TEST_F(OutputComposeSurfacesTest, skipDuplicateClientCompositionRequests) { |
| 3667 | mOutput.cacheClientCompositionRequests(3); |
| 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}; |
| 3673 | |
| 3674 | EXPECT_CALL(mOutput, getSkipColorTransform()).WillRepeatedly(Return(false)); |
| 3675 | EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillRepeatedly(Return(true)); |
| 3676 | EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false)); |
Peiyong Lin | 09f910f | 2020-09-25 10:54:13 -0700 | [diff] [blame] | 3677 | EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false)); |
Robert Carr | ccab424 | 2021-09-28 16:53:03 -0700 | [diff] [blame] | 3678 | EXPECT_CALL(mOutput, generateClientCompositionRequests(_, kDefaultOutputDataspace, _)) |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 3679 | .WillRepeatedly(Return(std::vector<LayerFE::LayerSettings>{r1, r2})); |
| 3680 | EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _)) |
| 3681 | .WillRepeatedly(Return()); |
| 3682 | |
| 3683 | EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer)); |
Alec Mouri | f29700f | 2023-08-17 21:53:31 +0000 | [diff] [blame] | 3684 | EXPECT_CALL(mRenderEngine, drawLayers(_, ElementsAre(r1, r2), _, _)) |
Patrick Williams | 2e9748f | 2022-08-09 22:48:18 +0000 | [diff] [blame] | 3685 | .WillOnce(Return(ByMove(ftl::yield<FenceResult>(Fence::NO_FENCE)))); |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 3686 | EXPECT_CALL(mOutput, setExpensiveRenderingExpected(false)); |
| 3687 | |
| 3688 | verify().execute().expectAFenceWasReturned(); |
| 3689 | EXPECT_FALSE(mOutput.mState.reusedClientComposition); |
| 3690 | |
| 3691 | // We do not expect another call to draw layers. |
Xiang Wang | aab3116 | 2024-03-12 19:48:08 -0700 | [diff] [blame] | 3692 | EXPECT_CALL(mOutput, setHintSessionRequiresRenderEngine(_)).Times(0); |
| 3693 | EXPECT_CALL(mOutput, setHintSessionGpuStart(_)).Times(0); |
| 3694 | EXPECT_CALL(mOutput, setHintSessionGpuFence(_)).Times(0); |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 3695 | verify().execute().expectAFenceWasReturned(); |
| 3696 | EXPECT_TRUE(mOutput.mState.reusedClientComposition); |
| 3697 | } |
| 3698 | |
Xiang Wang | cf61e73 | 2024-03-22 11:05:28 -0700 | [diff] [blame] | 3699 | TEST_F(OutputComposeSurfacesTest, clientCompositionIfBufferChangesWithAdpfGpuOff) { |
Xiang Wang | cb50bbd | 2024-04-18 16:57:54 -0700 | [diff] [blame] | 3700 | EXPECT_CALL(mOutput, isPowerHintSessionGpuReportingEnabled()).WillOnce(Return(false)); |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 3701 | LayerFE::LayerSettings r1; |
| 3702 | LayerFE::LayerSettings r2; |
| 3703 | |
| 3704 | r1.geometry.boundaries = FloatRect{1, 2, 3, 4}; |
| 3705 | r2.geometry.boundaries = FloatRect{5, 6, 7, 8}; |
| 3706 | |
| 3707 | EXPECT_CALL(mOutput, getSkipColorTransform()).WillRepeatedly(Return(false)); |
| 3708 | EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillRepeatedly(Return(true)); |
| 3709 | EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false)); |
Peiyong Lin | 09f910f | 2020-09-25 10:54:13 -0700 | [diff] [blame] | 3710 | EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false)); |
Robert Carr | ccab424 | 2021-09-28 16:53:03 -0700 | [diff] [blame] | 3711 | EXPECT_CALL(mOutput, generateClientCompositionRequests(_, kDefaultOutputDataspace, _)) |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 3712 | .WillRepeatedly(Return(std::vector<LayerFE::LayerSettings>{r1, r2})); |
| 3713 | EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _)) |
| 3714 | .WillRepeatedly(Return()); |
| 3715 | |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 3716 | const auto otherOutputBuffer = std::make_shared< |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 3717 | renderengine::impl:: |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 3718 | ExternalTexture>(sp<GraphicBuffer>::make(), mRenderEngine, |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 3719 | renderengine::impl::ExternalTexture::Usage::READABLE | |
| 3720 | renderengine::impl::ExternalTexture::Usage::WRITEABLE); |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 3721 | EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)) |
| 3722 | .WillOnce(Return(mOutputBuffer)) |
| 3723 | .WillOnce(Return(otherOutputBuffer)); |
Xiang Wang | aab3116 | 2024-03-12 19:48:08 -0700 | [diff] [blame] | 3724 | base::unique_fd fd(open("/dev/null", O_RDONLY)); |
Alec Mouri | f29700f | 2023-08-17 21:53:31 +0000 | [diff] [blame] | 3725 | EXPECT_CALL(mRenderEngine, drawLayers(_, ElementsAre(r1, r2), _, _)) |
Sally Qi | 4cabdd0 | 2021-08-05 16:45:57 -0700 | [diff] [blame] | 3726 | .WillRepeatedly([&](const renderengine::DisplaySettings&, |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 3727 | const std::vector<renderengine::LayerSettings>&, |
Alec Mouri | f29700f | 2023-08-17 21:53:31 +0000 | [diff] [blame] | 3728 | const std::shared_ptr<renderengine::ExternalTexture>&, |
Patrick Williams | 2e9748f | 2022-08-09 22:48:18 +0000 | [diff] [blame] | 3729 | base::unique_fd&&) -> ftl::Future<FenceResult> { |
Xiang Wang | aab3116 | 2024-03-12 19:48:08 -0700 | [diff] [blame] | 3730 | return ftl::yield<FenceResult>(sp<Fence>::make(std::move(fd))); |
Sally Qi | 4cabdd0 | 2021-08-05 16:45:57 -0700 | [diff] [blame] | 3731 | }); |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 3732 | |
Xiang Wang | aab3116 | 2024-03-12 19:48:08 -0700 | [diff] [blame] | 3733 | EXPECT_CALL(mOutput, setHintSessionRequiresRenderEngine(true)); |
| 3734 | EXPECT_CALL(mOutput, setHintSessionGpuStart(_)).Times(0); |
| 3735 | EXPECT_CALL(mOutput, setHintSessionGpuFence(_)).Times(0); |
| 3736 | verify().execute().expectAFenceWasReturned(); |
| 3737 | EXPECT_FALSE(mOutput.mState.reusedClientComposition); |
| 3738 | |
| 3739 | verify().execute().expectAFenceWasReturned(); |
| 3740 | EXPECT_FALSE(mOutput.mState.reusedClientComposition); |
| 3741 | } |
| 3742 | |
Xiang Wang | cf61e73 | 2024-03-22 11:05:28 -0700 | [diff] [blame] | 3743 | TEST_F(OutputComposeSurfacesTest, clientCompositionIfBufferChanges) { |
Xiang Wang | aab3116 | 2024-03-12 19:48:08 -0700 | [diff] [blame] | 3744 | LayerFE::LayerSettings r1; |
| 3745 | LayerFE::LayerSettings r2; |
| 3746 | |
| 3747 | r1.geometry.boundaries = FloatRect{1, 2, 3, 4}; |
| 3748 | r2.geometry.boundaries = FloatRect{5, 6, 7, 8}; |
| 3749 | |
| 3750 | EXPECT_CALL(mOutput, getSkipColorTransform()).WillRepeatedly(Return(false)); |
| 3751 | EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillRepeatedly(Return(true)); |
| 3752 | EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false)); |
| 3753 | EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false)); |
| 3754 | EXPECT_CALL(mOutput, generateClientCompositionRequests(_, kDefaultOutputDataspace, _)) |
| 3755 | .WillRepeatedly(Return(std::vector<LayerFE::LayerSettings>{r1, r2})); |
| 3756 | EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _)) |
| 3757 | .WillRepeatedly(Return()); |
| 3758 | |
| 3759 | const auto otherOutputBuffer = std::make_shared< |
| 3760 | renderengine::impl:: |
| 3761 | ExternalTexture>(sp<GraphicBuffer>::make(), mRenderEngine, |
| 3762 | renderengine::impl::ExternalTexture::Usage::READABLE | |
| 3763 | renderengine::impl::ExternalTexture::Usage::WRITEABLE); |
| 3764 | EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)) |
| 3765 | .WillOnce(Return(mOutputBuffer)) |
| 3766 | .WillOnce(Return(otherOutputBuffer)); |
| 3767 | base::unique_fd fd(open("/dev/null", O_RDONLY)); |
| 3768 | EXPECT_CALL(mRenderEngine, drawLayers(_, ElementsAre(r1, r2), _, _)) |
| 3769 | .WillRepeatedly([&](const renderengine::DisplaySettings&, |
| 3770 | const std::vector<renderengine::LayerSettings>&, |
| 3771 | const std::shared_ptr<renderengine::ExternalTexture>&, |
| 3772 | base::unique_fd&&) -> ftl::Future<FenceResult> { |
| 3773 | return ftl::yield<FenceResult>(sp<Fence>::make(std::move(fd))); |
| 3774 | }); |
| 3775 | |
| 3776 | EXPECT_CALL(mOutput, setHintSessionRequiresRenderEngine(true)); |
| 3777 | EXPECT_CALL(mOutput, setHintSessionGpuStart(_)); |
| 3778 | EXPECT_CALL(mOutput, setHintSessionGpuFence(_)); |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 3779 | verify().execute().expectAFenceWasReturned(); |
| 3780 | EXPECT_FALSE(mOutput.mState.reusedClientComposition); |
| 3781 | |
| 3782 | verify().execute().expectAFenceWasReturned(); |
| 3783 | EXPECT_FALSE(mOutput.mState.reusedClientComposition); |
| 3784 | } |
| 3785 | |
| 3786 | TEST_F(OutputComposeSurfacesTest, clientCompositionIfRequestChanges) { |
| 3787 | LayerFE::LayerSettings r1; |
| 3788 | LayerFE::LayerSettings r2; |
| 3789 | LayerFE::LayerSettings r3; |
| 3790 | |
| 3791 | r1.geometry.boundaries = FloatRect{1, 2, 3, 4}; |
| 3792 | r2.geometry.boundaries = FloatRect{5, 6, 7, 8}; |
| 3793 | r3.geometry.boundaries = FloatRect{5, 6, 7, 9}; |
| 3794 | |
| 3795 | EXPECT_CALL(mOutput, getSkipColorTransform()).WillRepeatedly(Return(false)); |
| 3796 | EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillRepeatedly(Return(true)); |
| 3797 | EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false)); |
Peiyong Lin | 09f910f | 2020-09-25 10:54:13 -0700 | [diff] [blame] | 3798 | EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false)); |
Robert Carr | ccab424 | 2021-09-28 16:53:03 -0700 | [diff] [blame] | 3799 | EXPECT_CALL(mOutput, generateClientCompositionRequests(_, kDefaultOutputDataspace, _)) |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 3800 | .WillOnce(Return(std::vector<LayerFE::LayerSettings>{r1, r2})) |
| 3801 | .WillOnce(Return(std::vector<LayerFE::LayerSettings>{r1, r3})); |
| 3802 | EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _)) |
| 3803 | .WillRepeatedly(Return()); |
| 3804 | |
| 3805 | EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer)); |
Alec Mouri | f29700f | 2023-08-17 21:53:31 +0000 | [diff] [blame] | 3806 | EXPECT_CALL(mRenderEngine, drawLayers(_, ElementsAre(r1, r2), _, _)) |
Patrick Williams | 2e9748f | 2022-08-09 22:48:18 +0000 | [diff] [blame] | 3807 | .WillOnce(Return(ByMove(ftl::yield<FenceResult>(Fence::NO_FENCE)))); |
Alec Mouri | f29700f | 2023-08-17 21:53:31 +0000 | [diff] [blame] | 3808 | EXPECT_CALL(mRenderEngine, drawLayers(_, ElementsAre(r1, r3), _, _)) |
Patrick Williams | 2e9748f | 2022-08-09 22:48:18 +0000 | [diff] [blame] | 3809 | .WillOnce(Return(ByMove(ftl::yield<FenceResult>(Fence::NO_FENCE)))); |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 3810 | |
| 3811 | verify().execute().expectAFenceWasReturned(); |
| 3812 | EXPECT_FALSE(mOutput.mState.reusedClientComposition); |
| 3813 | |
| 3814 | verify().execute().expectAFenceWasReturned(); |
| 3815 | EXPECT_FALSE(mOutput.mState.reusedClientComposition); |
| 3816 | } |
| 3817 | |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3818 | struct OutputComposeSurfacesTest_UsesExpectedDisplaySettings : public OutputComposeSurfacesTest { |
| 3819 | OutputComposeSurfacesTest_UsesExpectedDisplaySettings() { |
| 3820 | EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false)); |
Peiyong Lin | 09f910f | 2020-09-25 10:54:13 -0700 | [diff] [blame] | 3821 | EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false)); |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 3822 | EXPECT_CALL(mOutput, generateClientCompositionRequests(_, _, _)) |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 3823 | .WillRepeatedly(Return(std::vector<LayerFE::LayerSettings>{})); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3824 | EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _)) |
| 3825 | .WillRepeatedly(Return()); |
| 3826 | EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer)); |
| 3827 | } |
| 3828 | |
| 3829 | struct MixedCompositionState |
| 3830 | : public CallOrderStateMachineHelper<TestType, MixedCompositionState> { |
| 3831 | auto ifMixedCompositionIs(bool used) { |
| 3832 | getInstance()->mOutput.mState.usesDeviceComposition = used; |
| 3833 | return nextState<OutputUsesHdrState>(); |
| 3834 | } |
| 3835 | }; |
| 3836 | |
| 3837 | struct OutputUsesHdrState : public CallOrderStateMachineHelper<TestType, OutputUsesHdrState> { |
| 3838 | auto andIfUsesHdr(bool used) { |
| 3839 | EXPECT_CALL(*getInstance()->mDisplayColorProfile, hasWideColorGamut()) |
| 3840 | .WillOnce(Return(used)); |
Alec Mouri | b21d94e | 2022-01-13 17:44:10 -0800 | [diff] [blame] | 3841 | return nextState<OutputWithDisplayBrightnessNits>(); |
| 3842 | } |
| 3843 | }; |
| 3844 | |
| 3845 | struct OutputWithDisplayBrightnessNits |
| 3846 | : public CallOrderStateMachineHelper<TestType, OutputWithDisplayBrightnessNits> { |
| 3847 | auto withDisplayBrightnessNits(float nits) { |
| 3848 | getInstance()->mOutput.mState.displayBrightnessNits = nits; |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 3849 | return nextState<OutputWithSdrWhitePointNits>(); |
| 3850 | } |
| 3851 | }; |
| 3852 | |
| 3853 | struct OutputWithSdrWhitePointNits |
| 3854 | : public CallOrderStateMachineHelper<TestType, OutputWithSdrWhitePointNits> { |
| 3855 | auto withSdrWhitePointNits(float nits) { |
| 3856 | getInstance()->mOutput.mState.sdrWhitePointNits = nits; |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 3857 | return nextState<OutputWithDimmingStage>(); |
| 3858 | } |
| 3859 | }; |
| 3860 | |
| 3861 | struct OutputWithDimmingStage |
| 3862 | : public CallOrderStateMachineHelper<TestType, OutputWithDimmingStage> { |
| 3863 | auto withDimmingStage( |
| 3864 | aidl::android::hardware::graphics::composer3::DimmingStage dimmingStage) { |
| 3865 | getInstance()->mOutput.mState.clientTargetDimmingStage = dimmingStage; |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 3866 | return nextState<OutputWithRenderIntent>(); |
| 3867 | } |
| 3868 | }; |
| 3869 | |
| 3870 | struct OutputWithRenderIntent |
| 3871 | : public CallOrderStateMachineHelper<TestType, OutputWithRenderIntent> { |
| 3872 | auto withRenderIntent( |
| 3873 | aidl::android::hardware::graphics::composer3::RenderIntent renderIntent) { |
| 3874 | getInstance()->mOutput.mState.renderIntent = |
| 3875 | static_cast<ui::RenderIntent>(renderIntent); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3876 | return nextState<SkipColorTransformState>(); |
| 3877 | } |
| 3878 | }; |
| 3879 | |
| 3880 | struct SkipColorTransformState |
| 3881 | : public CallOrderStateMachineHelper<TestType, SkipColorTransformState> { |
| 3882 | auto andIfSkipColorTransform(bool skip) { |
| 3883 | // May be called zero or one times. |
| 3884 | EXPECT_CALL(getInstance()->mOutput, getSkipColorTransform()) |
| 3885 | .WillRepeatedly(Return(skip)); |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 3886 | return nextState<PixelFormatState>(); |
| 3887 | } |
| 3888 | }; |
| 3889 | |
| 3890 | struct PixelFormatState : public CallOrderStateMachineHelper<TestType, PixelFormatState> { |
| 3891 | auto withPixelFormat(std::optional<PixelFormat> format) { |
| 3892 | // May be called zero or one times. |
| 3893 | if (format) { |
| 3894 | auto outputBuffer = std::make_shared< |
| 3895 | renderengine::impl:: |
| 3896 | ExternalTexture>(sp<GraphicBuffer>:: |
| 3897 | make(1u, 1u, *format, |
| 3898 | GRALLOC_USAGE_SW_WRITE_OFTEN | |
| 3899 | GRALLOC_USAGE_SW_READ_OFTEN), |
| 3900 | getInstance()->mRenderEngine, |
| 3901 | renderengine::impl::ExternalTexture::Usage:: |
| 3902 | READABLE | |
| 3903 | renderengine::impl::ExternalTexture:: |
| 3904 | Usage::WRITEABLE); |
| 3905 | EXPECT_CALL(*getInstance()->mRenderSurface, dequeueBuffer(_)) |
| 3906 | .WillRepeatedly(Return(outputBuffer)); |
| 3907 | } |
| 3908 | return nextState<DataspaceState>(); |
| 3909 | } |
| 3910 | }; |
| 3911 | |
| 3912 | struct DataspaceState : public CallOrderStateMachineHelper<TestType, DataspaceState> { |
| 3913 | auto withDataspace(ui::Dataspace dataspace) { |
| 3914 | getInstance()->mOutput.mState.dataspace = dataspace; |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3915 | return nextState<ExpectDisplaySettingsState>(); |
| 3916 | } |
| 3917 | }; |
| 3918 | |
| 3919 | struct ExpectDisplaySettingsState |
| 3920 | : public CallOrderStateMachineHelper<TestType, ExpectDisplaySettingsState> { |
| 3921 | auto thenExpectDisplaySettingsUsed(renderengine::DisplaySettings settings) { |
Alec Mouri | f29700f | 2023-08-17 21:53:31 +0000 | [diff] [blame] | 3922 | EXPECT_CALL(getInstance()->mRenderEngine, drawLayers(settings, _, _, _)) |
Patrick Williams | 2e9748f | 2022-08-09 22:48:18 +0000 | [diff] [blame] | 3923 | .WillOnce(Return(ByMove(ftl::yield<FenceResult>(Fence::NO_FENCE)))); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3924 | return nextState<ExecuteState>(); |
| 3925 | } |
| 3926 | }; |
| 3927 | |
| 3928 | // Call this member function to start using the mini-DSL defined above. |
| 3929 | [[nodiscard]] auto verify() { return MixedCompositionState::make(this); } |
| 3930 | }; |
| 3931 | |
| 3932 | TEST_F(OutputComposeSurfacesTest_UsesExpectedDisplaySettings, forHdrMixedComposition) { |
| 3933 | verify().ifMixedCompositionIs(true) |
| 3934 | .andIfUsesHdr(true) |
Leon Scroggins III | f6280bb | 2022-05-04 13:20:32 -0400 | [diff] [blame] | 3935 | .withDisplayBrightnessNits(kDisplayLuminance) |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 3936 | .withSdrWhitePointNits(kWhitePointLuminance) |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 3937 | .withDimmingStage(aidl::android::hardware::graphics::composer3::DimmingStage::LINEAR) |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 3938 | .withRenderIntent( |
| 3939 | aidl::android::hardware::graphics::composer3::RenderIntent::COLORIMETRIC) |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 3940 | .andIfSkipColorTransform(false) |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 3941 | .withPixelFormat(std::nullopt) |
| 3942 | .withDataspace(kDefaultOutputDataspace) |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 3943 | .thenExpectDisplaySettingsUsed( |
| 3944 | {.physicalDisplay = kDefaultOutputDestinationClip, |
| 3945 | .clip = kDefaultOutputViewport, |
| 3946 | .maxLuminance = kDefaultMaxLuminance, |
Leon Scroggins III | f6280bb | 2022-05-04 13:20:32 -0400 | [diff] [blame] | 3947 | .currentLuminanceNits = kDisplayLuminance, |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 3948 | .outputDataspace = kDefaultOutputDataspace, |
| 3949 | .colorTransform = kDefaultColorTransformMat, |
| 3950 | .deviceHandlesColorTransform = true, |
| 3951 | .orientation = kDefaultOutputOrientationFlags, |
| 3952 | .targetLuminanceNits = kClientTargetLuminanceNits, |
| 3953 | .dimmingStage = |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 3954 | aidl::android::hardware::graphics::composer3::DimmingStage::LINEAR, |
| 3955 | .renderIntent = aidl::android::hardware::graphics::composer3::RenderIntent:: |
| 3956 | COLORIMETRIC}) |
Alec Mouri | b21d94e | 2022-01-13 17:44:10 -0800 | [diff] [blame] | 3957 | .execute() |
| 3958 | .expectAFenceWasReturned(); |
| 3959 | } |
| 3960 | |
| 3961 | TEST_F(OutputComposeSurfacesTest_UsesExpectedDisplaySettings, |
| 3962 | forHdrMixedCompositionWithDisplayBrightness) { |
| 3963 | verify().ifMixedCompositionIs(true) |
| 3964 | .andIfUsesHdr(true) |
| 3965 | .withDisplayBrightnessNits(kDisplayLuminance) |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 3966 | .withSdrWhitePointNits(kWhitePointLuminance) |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 3967 | .withDimmingStage(aidl::android::hardware::graphics::composer3::DimmingStage::LINEAR) |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 3968 | .withRenderIntent( |
| 3969 | aidl::android::hardware::graphics::composer3::RenderIntent::COLORIMETRIC) |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 3970 | .andIfSkipColorTransform(false) |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 3971 | .withPixelFormat(std::nullopt) |
| 3972 | .withDataspace(kDefaultOutputDataspace) |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 3973 | .thenExpectDisplaySettingsUsed( |
| 3974 | {.physicalDisplay = kDefaultOutputDestinationClip, |
| 3975 | .clip = kDefaultOutputViewport, |
| 3976 | .maxLuminance = kDefaultMaxLuminance, |
| 3977 | .currentLuminanceNits = kDisplayLuminance, |
| 3978 | .outputDataspace = kDefaultOutputDataspace, |
| 3979 | .colorTransform = kDefaultColorTransformMat, |
| 3980 | .deviceHandlesColorTransform = true, |
| 3981 | .orientation = kDefaultOutputOrientationFlags, |
| 3982 | .targetLuminanceNits = kClientTargetLuminanceNits, |
| 3983 | .dimmingStage = |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 3984 | aidl::android::hardware::graphics::composer3::DimmingStage::LINEAR, |
| 3985 | .renderIntent = aidl::android::hardware::graphics::composer3::RenderIntent:: |
| 3986 | COLORIMETRIC}) |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 3987 | .execute() |
| 3988 | .expectAFenceWasReturned(); |
| 3989 | } |
| 3990 | |
| 3991 | TEST_F(OutputComposeSurfacesTest_UsesExpectedDisplaySettings, |
| 3992 | forHdrMixedCompositionWithDimmingStage) { |
| 3993 | verify().ifMixedCompositionIs(true) |
| 3994 | .andIfUsesHdr(true) |
Leon Scroggins III | f6280bb | 2022-05-04 13:20:32 -0400 | [diff] [blame] | 3995 | .withDisplayBrightnessNits(kDisplayLuminance) |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 3996 | .withSdrWhitePointNits(kWhitePointLuminance) |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 3997 | .withDimmingStage( |
| 3998 | aidl::android::hardware::graphics::composer3::DimmingStage::GAMMA_OETF) |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 3999 | .withRenderIntent( |
| 4000 | aidl::android::hardware::graphics::composer3::RenderIntent::COLORIMETRIC) |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4001 | .andIfSkipColorTransform(false) |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 4002 | .withPixelFormat(std::nullopt) |
| 4003 | .withDataspace(kDefaultOutputDataspace) |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 4004 | .thenExpectDisplaySettingsUsed( |
| 4005 | {.physicalDisplay = kDefaultOutputDestinationClip, |
| 4006 | .clip = kDefaultOutputViewport, |
| 4007 | .maxLuminance = kDefaultMaxLuminance, |
Leon Scroggins III | f6280bb | 2022-05-04 13:20:32 -0400 | [diff] [blame] | 4008 | .currentLuminanceNits = kDisplayLuminance, |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 4009 | .outputDataspace = kDefaultOutputDataspace, |
| 4010 | .colorTransform = kDefaultColorTransformMat, |
| 4011 | .deviceHandlesColorTransform = true, |
| 4012 | .orientation = kDefaultOutputOrientationFlags, |
| 4013 | .targetLuminanceNits = kClientTargetLuminanceNits, |
| 4014 | .dimmingStage = |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 4015 | aidl::android::hardware::graphics::composer3::DimmingStage::GAMMA_OETF, |
| 4016 | .renderIntent = aidl::android::hardware::graphics::composer3::RenderIntent:: |
| 4017 | COLORIMETRIC}) |
| 4018 | .execute() |
| 4019 | .expectAFenceWasReturned(); |
| 4020 | } |
| 4021 | |
| 4022 | TEST_F(OutputComposeSurfacesTest_UsesExpectedDisplaySettings, |
| 4023 | forHdrMixedCompositionWithRenderIntent) { |
| 4024 | verify().ifMixedCompositionIs(true) |
| 4025 | .andIfUsesHdr(true) |
Leon Scroggins III | f6280bb | 2022-05-04 13:20:32 -0400 | [diff] [blame] | 4026 | .withDisplayBrightnessNits(kDisplayLuminance) |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 4027 | .withSdrWhitePointNits(kWhitePointLuminance) |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 4028 | .withDimmingStage(aidl::android::hardware::graphics::composer3::DimmingStage::LINEAR) |
| 4029 | .withRenderIntent(aidl::android::hardware::graphics::composer3::RenderIntent::ENHANCE) |
| 4030 | .andIfSkipColorTransform(false) |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 4031 | .withPixelFormat(std::nullopt) |
| 4032 | .withDataspace(kDefaultOutputDataspace) |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 4033 | .thenExpectDisplaySettingsUsed( |
| 4034 | {.physicalDisplay = kDefaultOutputDestinationClip, |
| 4035 | .clip = kDefaultOutputViewport, |
| 4036 | .maxLuminance = kDefaultMaxLuminance, |
Leon Scroggins III | f6280bb | 2022-05-04 13:20:32 -0400 | [diff] [blame] | 4037 | .currentLuminanceNits = kDisplayLuminance, |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 4038 | .outputDataspace = kDefaultOutputDataspace, |
| 4039 | .colorTransform = kDefaultColorTransformMat, |
| 4040 | .deviceHandlesColorTransform = true, |
| 4041 | .orientation = kDefaultOutputOrientationFlags, |
| 4042 | .targetLuminanceNits = kClientTargetLuminanceNits, |
| 4043 | .dimmingStage = |
| 4044 | aidl::android::hardware::graphics::composer3::DimmingStage::LINEAR, |
| 4045 | .renderIntent = |
| 4046 | aidl::android::hardware::graphics::composer3::RenderIntent::ENHANCE}) |
| 4047 | .execute() |
| 4048 | .expectAFenceWasReturned(); |
| 4049 | } |
| 4050 | |
| 4051 | TEST_F(OutputComposeSurfacesTest_UsesExpectedDisplaySettings, forNonHdrMixedComposition) { |
| 4052 | verify().ifMixedCompositionIs(true) |
| 4053 | .andIfUsesHdr(false) |
Leon Scroggins III | f6280bb | 2022-05-04 13:20:32 -0400 | [diff] [blame] | 4054 | .withDisplayBrightnessNits(kDisplayLuminance) |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 4055 | .withSdrWhitePointNits(kWhitePointLuminance) |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 4056 | .withDimmingStage(aidl::android::hardware::graphics::composer3::DimmingStage::LINEAR) |
| 4057 | .withRenderIntent( |
| 4058 | aidl::android::hardware::graphics::composer3::RenderIntent::COLORIMETRIC) |
| 4059 | .andIfSkipColorTransform(false) |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 4060 | .withPixelFormat(std::nullopt) |
| 4061 | .withDataspace(kDefaultOutputDataspace) |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 4062 | .thenExpectDisplaySettingsUsed( |
| 4063 | {.physicalDisplay = kDefaultOutputDestinationClip, |
| 4064 | .clip = kDefaultOutputViewport, |
| 4065 | .maxLuminance = kDefaultMaxLuminance, |
Leon Scroggins III | f6280bb | 2022-05-04 13:20:32 -0400 | [diff] [blame] | 4066 | .currentLuminanceNits = kDisplayLuminance, |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 4067 | .outputDataspace = kDefaultOutputDataspace, |
| 4068 | .colorTransform = kDefaultColorTransformMat, |
| 4069 | .deviceHandlesColorTransform = true, |
| 4070 | .orientation = kDefaultOutputOrientationFlags, |
| 4071 | .targetLuminanceNits = kClientTargetLuminanceNits, |
| 4072 | .dimmingStage = |
| 4073 | aidl::android::hardware::graphics::composer3::DimmingStage::LINEAR, |
| 4074 | .renderIntent = aidl::android::hardware::graphics::composer3::RenderIntent:: |
| 4075 | COLORIMETRIC}) |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4076 | .execute() |
| 4077 | .expectAFenceWasReturned(); |
| 4078 | } |
| 4079 | |
| 4080 | TEST_F(OutputComposeSurfacesTest_UsesExpectedDisplaySettings, forHdrOnlyClientComposition) { |
| 4081 | verify().ifMixedCompositionIs(false) |
| 4082 | .andIfUsesHdr(true) |
Leon Scroggins III | f6280bb | 2022-05-04 13:20:32 -0400 | [diff] [blame] | 4083 | .withDisplayBrightnessNits(kDisplayLuminance) |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 4084 | .withSdrWhitePointNits(kWhitePointLuminance) |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 4085 | .withDimmingStage(aidl::android::hardware::graphics::composer3::DimmingStage::LINEAR) |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 4086 | .withRenderIntent( |
| 4087 | aidl::android::hardware::graphics::composer3::RenderIntent::COLORIMETRIC) |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4088 | .andIfSkipColorTransform(false) |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 4089 | .withPixelFormat(std::nullopt) |
| 4090 | .withDataspace(kDefaultOutputDataspace) |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 4091 | .thenExpectDisplaySettingsUsed( |
| 4092 | {.physicalDisplay = kDefaultOutputDestinationClip, |
| 4093 | .clip = kDefaultOutputViewport, |
| 4094 | .maxLuminance = kDefaultMaxLuminance, |
Leon Scroggins III | f6280bb | 2022-05-04 13:20:32 -0400 | [diff] [blame] | 4095 | .currentLuminanceNits = kDisplayLuminance, |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 4096 | .outputDataspace = kDefaultOutputDataspace, |
| 4097 | .colorTransform = kDefaultColorTransformMat, |
| 4098 | .deviceHandlesColorTransform = false, |
| 4099 | .orientation = kDefaultOutputOrientationFlags, |
| 4100 | .targetLuminanceNits = kClientTargetLuminanceNits, |
| 4101 | .dimmingStage = |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 4102 | aidl::android::hardware::graphics::composer3::DimmingStage::LINEAR, |
| 4103 | .renderIntent = aidl::android::hardware::graphics::composer3::RenderIntent:: |
| 4104 | COLORIMETRIC}) |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4105 | .execute() |
| 4106 | .expectAFenceWasReturned(); |
| 4107 | } |
| 4108 | |
| 4109 | TEST_F(OutputComposeSurfacesTest_UsesExpectedDisplaySettings, forNonHdrOnlyClientComposition) { |
| 4110 | verify().ifMixedCompositionIs(false) |
| 4111 | .andIfUsesHdr(false) |
Leon Scroggins III | f6280bb | 2022-05-04 13:20:32 -0400 | [diff] [blame] | 4112 | .withDisplayBrightnessNits(kDisplayLuminance) |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 4113 | .withSdrWhitePointNits(kWhitePointLuminance) |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 4114 | .withDimmingStage(aidl::android::hardware::graphics::composer3::DimmingStage::LINEAR) |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 4115 | .withRenderIntent( |
| 4116 | aidl::android::hardware::graphics::composer3::RenderIntent::COLORIMETRIC) |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4117 | .andIfSkipColorTransform(false) |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 4118 | .withPixelFormat(std::nullopt) |
| 4119 | .withDataspace(kDefaultOutputDataspace) |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 4120 | .thenExpectDisplaySettingsUsed( |
| 4121 | {.physicalDisplay = kDefaultOutputDestinationClip, |
| 4122 | .clip = kDefaultOutputViewport, |
| 4123 | .maxLuminance = kDefaultMaxLuminance, |
Leon Scroggins III | f6280bb | 2022-05-04 13:20:32 -0400 | [diff] [blame] | 4124 | .currentLuminanceNits = kDisplayLuminance, |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 4125 | .outputDataspace = kDefaultOutputDataspace, |
| 4126 | .colorTransform = kDefaultColorTransformMat, |
| 4127 | .deviceHandlesColorTransform = false, |
| 4128 | .orientation = kDefaultOutputOrientationFlags, |
| 4129 | .targetLuminanceNits = kClientTargetLuminanceNits, |
| 4130 | .dimmingStage = |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 4131 | aidl::android::hardware::graphics::composer3::DimmingStage::LINEAR, |
| 4132 | .renderIntent = aidl::android::hardware::graphics::composer3::RenderIntent:: |
| 4133 | COLORIMETRIC}) |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4134 | .execute() |
| 4135 | .expectAFenceWasReturned(); |
| 4136 | } |
| 4137 | |
| 4138 | TEST_F(OutputComposeSurfacesTest_UsesExpectedDisplaySettings, |
| 4139 | usesExpectedDisplaySettingsForHdrOnlyClientCompositionWithSkipClientTransform) { |
| 4140 | verify().ifMixedCompositionIs(false) |
| 4141 | .andIfUsesHdr(true) |
Leon Scroggins III | f6280bb | 2022-05-04 13:20:32 -0400 | [diff] [blame] | 4142 | .withDisplayBrightnessNits(kDisplayLuminance) |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 4143 | .withSdrWhitePointNits(kWhitePointLuminance) |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 4144 | .withDimmingStage(aidl::android::hardware::graphics::composer3::DimmingStage::LINEAR) |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 4145 | .withRenderIntent( |
| 4146 | aidl::android::hardware::graphics::composer3::RenderIntent::COLORIMETRIC) |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4147 | .andIfSkipColorTransform(true) |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 4148 | .withPixelFormat(std::nullopt) |
| 4149 | .withDataspace(kDefaultOutputDataspace) |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 4150 | .thenExpectDisplaySettingsUsed( |
| 4151 | {.physicalDisplay = kDefaultOutputDestinationClip, |
| 4152 | .clip = kDefaultOutputViewport, |
| 4153 | .maxLuminance = kDefaultMaxLuminance, |
Leon Scroggins III | f6280bb | 2022-05-04 13:20:32 -0400 | [diff] [blame] | 4154 | .currentLuminanceNits = kDisplayLuminance, |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 4155 | .outputDataspace = kDefaultOutputDataspace, |
| 4156 | .colorTransform = kDefaultColorTransformMat, |
| 4157 | .deviceHandlesColorTransform = true, |
| 4158 | .orientation = kDefaultOutputOrientationFlags, |
| 4159 | .targetLuminanceNits = kClientTargetLuminanceNits, |
| 4160 | .dimmingStage = |
Alec Mouri | fcedb9c | 2022-04-11 20:02:17 +0000 | [diff] [blame] | 4161 | aidl::android::hardware::graphics::composer3::DimmingStage::LINEAR, |
| 4162 | .renderIntent = aidl::android::hardware::graphics::composer3::RenderIntent:: |
| 4163 | COLORIMETRIC}) |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4164 | .execute() |
| 4165 | .expectAFenceWasReturned(); |
| 4166 | } |
| 4167 | |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 4168 | TEST_F(OutputComposeSurfacesTest_UsesExpectedDisplaySettings, |
| 4169 | usesExpectedDisplaySettingsWithFp16Buffer) { |
| 4170 | SET_FLAG_FOR_TEST(flags::fp16_client_target, true); |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 4171 | verify().ifMixedCompositionIs(false) |
| 4172 | .andIfUsesHdr(true) |
| 4173 | .withDisplayBrightnessNits(kDisplayLuminance) |
| 4174 | .withSdrWhitePointNits(kWhitePointLuminance) |
| 4175 | .withDimmingStage(aidl::android::hardware::graphics::composer3::DimmingStage::LINEAR) |
| 4176 | .withRenderIntent( |
| 4177 | aidl::android::hardware::graphics::composer3::RenderIntent::COLORIMETRIC) |
| 4178 | .andIfSkipColorTransform(true) |
| 4179 | .withPixelFormat(PIXEL_FORMAT_RGBA_FP16) |
| 4180 | .withDataspace(ui::Dataspace::V0_SCRGB) |
| 4181 | .thenExpectDisplaySettingsUsed( |
| 4182 | {.physicalDisplay = kDefaultOutputDestinationClip, |
| 4183 | .clip = kDefaultOutputViewport, |
| 4184 | .maxLuminance = kDefaultMaxLuminance, |
| 4185 | .currentLuminanceNits = kDisplayLuminance, |
| 4186 | .outputDataspace = ui::Dataspace::V0_SCRGB, |
| 4187 | .colorTransform = kDefaultColorTransformMat, |
| 4188 | .deviceHandlesColorTransform = true, |
| 4189 | .orientation = kDefaultOutputOrientationFlags, |
| 4190 | .targetLuminanceNits = kClientTargetLuminanceNits * 0.75f, |
| 4191 | .dimmingStage = |
| 4192 | aidl::android::hardware::graphics::composer3::DimmingStage::LINEAR, |
| 4193 | .renderIntent = aidl::android::hardware::graphics::composer3::RenderIntent:: |
| 4194 | COLORIMETRIC}) |
| 4195 | .execute() |
| 4196 | .expectAFenceWasReturned(); |
| 4197 | } |
| 4198 | |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4199 | struct OutputComposeSurfacesTest_HandlesProtectedContent : public OutputComposeSurfacesTest { |
| 4200 | struct Layer { |
| 4201 | Layer() { |
Ady Abraham | eca9d75 | 2021-03-03 12:20:00 -0800 | [diff] [blame] | 4202 | EXPECT_CALL(*mLayerFE, getCompositionState()).WillRepeatedly(Return(&mLayerFEState)); |
| 4203 | EXPECT_CALL(mOutputLayer, getLayerFE()).WillRepeatedly(ReturnRef(*mLayerFE)); |
Eason Chiu | 4509966 | 2023-10-23 08:55:48 +0800 | [diff] [blame] | 4204 | EXPECT_CALL(mOutputLayer, requiresClientComposition()).WillRepeatedly(Return(true)); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4205 | } |
| 4206 | |
| 4207 | StrictMock<mock::OutputLayer> mOutputLayer; |
Ady Abraham | eca9d75 | 2021-03-03 12:20:00 -0800 | [diff] [blame] | 4208 | sp<StrictMock<mock::LayerFE>> mLayerFE = sp<StrictMock<mock::LayerFE>>::make(); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4209 | LayerFECompositionState mLayerFEState; |
| 4210 | }; |
| 4211 | |
| 4212 | OutputComposeSurfacesTest_HandlesProtectedContent() { |
| 4213 | mLayer1.mLayerFEState.hasProtectedContent = false; |
| 4214 | mLayer2.mLayerFEState.hasProtectedContent = false; |
| 4215 | |
| 4216 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(2u)); |
| 4217 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0u)) |
| 4218 | .WillRepeatedly(Return(&mLayer1.mOutputLayer)); |
| 4219 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(1u)) |
| 4220 | .WillRepeatedly(Return(&mLayer2.mOutputLayer)); |
| 4221 | |
| 4222 | EXPECT_CALL(mOutput, getSkipColorTransform()).WillRepeatedly(Return(false)); |
| 4223 | |
| 4224 | EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillRepeatedly(Return(true)); |
| 4225 | |
Robert Carr | ccab424 | 2021-09-28 16:53:03 -0700 | [diff] [blame] | 4226 | EXPECT_CALL(mOutput, generateClientCompositionRequests(_, _, _)) |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 4227 | .WillRepeatedly(Return(std::vector<LayerFE::LayerSettings>{})); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4228 | EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _)) |
| 4229 | .WillRepeatedly(Return()); |
| 4230 | EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer)); |
Alec Mouri | f29700f | 2023-08-17 21:53:31 +0000 | [diff] [blame] | 4231 | EXPECT_CALL(mRenderEngine, drawLayers(_, _, _, _)) |
Patrick Williams | 2e9748f | 2022-08-09 22:48:18 +0000 | [diff] [blame] | 4232 | .WillRepeatedly([&](const renderengine::DisplaySettings&, |
| 4233 | const std::vector<renderengine::LayerSettings>&, |
| 4234 | const std::shared_ptr<renderengine::ExternalTexture>&, |
Alec Mouri | f29700f | 2023-08-17 21:53:31 +0000 | [diff] [blame] | 4235 | base::unique_fd&&) -> ftl::Future<FenceResult> { |
Patrick Williams | 2e9748f | 2022-08-09 22:48:18 +0000 | [diff] [blame] | 4236 | return ftl::yield<FenceResult>(Fence::NO_FENCE); |
| 4237 | }); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4238 | } |
| 4239 | |
| 4240 | Layer mLayer1; |
| 4241 | Layer mLayer2; |
| 4242 | }; |
| 4243 | |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4244 | TEST_F(OutputComposeSurfacesTest_HandlesProtectedContent, ifNoProtectedContentLayers) { |
Eason Chiu | 4509966 | 2023-10-23 08:55:48 +0800 | [diff] [blame] | 4245 | SET_FLAG_FOR_TEST(flags::protected_if_client, true); |
Chavi Weingarten | cbec71d | 2023-12-14 20:53:25 +0000 | [diff] [blame] | 4246 | if (FlagManager::getInstance().display_protected()) { |
| 4247 | mOutput.mState.isProtected = true; |
| 4248 | } else { |
| 4249 | mOutput.mState.isSecure = true; |
| 4250 | } |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4251 | mLayer2.mLayerFEState.hasProtectedContent = false; |
| 4252 | EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(true)); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4253 | EXPECT_CALL(*mRenderSurface, isProtected).WillOnce(Return(true)); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4254 | EXPECT_CALL(*mRenderSurface, setProtected(false)); |
| 4255 | |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 4256 | base::unique_fd fd; |
| 4257 | std::shared_ptr<renderengine::ExternalTexture> tex; |
| 4258 | mOutput.updateProtectedContentState(); |
| 4259 | mOutput.dequeueRenderBuffer(&fd, &tex); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 4260 | mOutput.composeSurfaces(kDebugRegion, tex, fd); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4261 | } |
| 4262 | |
| 4263 | TEST_F(OutputComposeSurfacesTest_HandlesProtectedContent, ifNotEnabled) { |
Eason Chiu | 4509966 | 2023-10-23 08:55:48 +0800 | [diff] [blame] | 4264 | SET_FLAG_FOR_TEST(flags::protected_if_client, true); |
Chavi Weingarten | cbec71d | 2023-12-14 20:53:25 +0000 | [diff] [blame] | 4265 | if (FlagManager::getInstance().display_protected()) { |
| 4266 | mOutput.mState.isProtected = true; |
| 4267 | } else { |
| 4268 | mOutput.mState.isSecure = true; |
| 4269 | } |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4270 | mLayer2.mLayerFEState.hasProtectedContent = true; |
| 4271 | EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(true)); |
| 4272 | |
| 4273 | // For this test, we also check the call order of key functions. |
| 4274 | InSequence seq; |
| 4275 | |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4276 | EXPECT_CALL(*mRenderSurface, isProtected).WillOnce(Return(false)); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4277 | EXPECT_CALL(*mRenderSurface, setProtected(true)); |
| 4278 | // Must happen after setting the protected content state. |
| 4279 | EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer)); |
Alec Mouri | f29700f | 2023-08-17 21:53:31 +0000 | [diff] [blame] | 4280 | EXPECT_CALL(mRenderEngine, drawLayers(_, _, _, _)) |
Patrick Williams | 2e9748f | 2022-08-09 22:48:18 +0000 | [diff] [blame] | 4281 | .WillOnce(Return(ByMove(ftl::yield<FenceResult>(Fence::NO_FENCE)))); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4282 | |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 4283 | base::unique_fd fd; |
| 4284 | std::shared_ptr<renderengine::ExternalTexture> tex; |
| 4285 | mOutput.updateProtectedContentState(); |
| 4286 | mOutput.dequeueRenderBuffer(&fd, &tex); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 4287 | mOutput.composeSurfaces(kDebugRegion, tex, fd); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4288 | } |
| 4289 | |
| 4290 | TEST_F(OutputComposeSurfacesTest_HandlesProtectedContent, ifAlreadyEnabledEverywhere) { |
Eason Chiu | 4509966 | 2023-10-23 08:55:48 +0800 | [diff] [blame] | 4291 | SET_FLAG_FOR_TEST(flags::protected_if_client, true); |
Chavi Weingarten | cbec71d | 2023-12-14 20:53:25 +0000 | [diff] [blame] | 4292 | if (FlagManager::getInstance().display_protected()) { |
| 4293 | mOutput.mState.isProtected = true; |
| 4294 | } else { |
| 4295 | mOutput.mState.isSecure = true; |
| 4296 | } |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4297 | mLayer2.mLayerFEState.hasProtectedContent = true; |
| 4298 | EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(true)); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4299 | EXPECT_CALL(*mRenderSurface, isProtected).WillOnce(Return(true)); |
| 4300 | |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 4301 | base::unique_fd fd; |
| 4302 | std::shared_ptr<renderengine::ExternalTexture> tex; |
| 4303 | mOutput.updateProtectedContentState(); |
| 4304 | mOutput.dequeueRenderBuffer(&fd, &tex); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 4305 | mOutput.composeSurfaces(kDebugRegion, tex, fd); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4306 | } |
| 4307 | |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4308 | TEST_F(OutputComposeSurfacesTest_HandlesProtectedContent, ifAlreadyEnabledInRenderSurface) { |
Eason Chiu | 4509966 | 2023-10-23 08:55:48 +0800 | [diff] [blame] | 4309 | SET_FLAG_FOR_TEST(flags::protected_if_client, true); |
Chavi Weingarten | cbec71d | 2023-12-14 20:53:25 +0000 | [diff] [blame] | 4310 | if (FlagManager::getInstance().display_protected()) { |
| 4311 | mOutput.mState.isProtected = true; |
| 4312 | } else { |
| 4313 | mOutput.mState.isSecure = true; |
| 4314 | } |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4315 | mLayer2.mLayerFEState.hasProtectedContent = true; |
| 4316 | EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(true)); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4317 | EXPECT_CALL(*mRenderSurface, isProtected).WillOnce(Return(true)); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4318 | |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 4319 | base::unique_fd fd; |
| 4320 | std::shared_ptr<renderengine::ExternalTexture> tex; |
| 4321 | mOutput.updateProtectedContentState(); |
| 4322 | mOutput.dequeueRenderBuffer(&fd, &tex); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 4323 | mOutput.composeSurfaces(kDebugRegion, tex, fd); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4324 | } |
| 4325 | |
| 4326 | struct OutputComposeSurfacesTest_SetsExpensiveRendering : public OutputComposeSurfacesTest { |
| 4327 | OutputComposeSurfacesTest_SetsExpensiveRendering() { |
| 4328 | EXPECT_CALL(mOutput, getSkipColorTransform()).WillRepeatedly(Return(false)); |
| 4329 | EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillRepeatedly(Return(true)); |
| 4330 | EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false)); |
Peiyong Lin | 09f910f | 2020-09-25 10:54:13 -0700 | [diff] [blame] | 4331 | EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false)); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4332 | EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _)) |
| 4333 | .WillRepeatedly(Return()); |
| 4334 | EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer)); |
| 4335 | } |
| 4336 | }; |
| 4337 | |
| 4338 | TEST_F(OutputComposeSurfacesTest_SetsExpensiveRendering, IfExepensiveOutputDataspaceIsUsed) { |
| 4339 | mOutput.mState.dataspace = kExpensiveOutputDataspace; |
| 4340 | |
Leon Scroggins III | 7bdcceb | 2022-03-09 16:53:52 -0500 | [diff] [blame] | 4341 | LayerFE::LayerSettings layerSettings; |
Robert Carr | ccab424 | 2021-09-28 16:53:03 -0700 | [diff] [blame] | 4342 | EXPECT_CALL(mOutput, generateClientCompositionRequests(_, kExpensiveOutputDataspace, _)) |
Leon Scroggins III | 7bdcceb | 2022-03-09 16:53:52 -0500 | [diff] [blame] | 4343 | .WillOnce(Return(std::vector<LayerFE::LayerSettings>{layerSettings})); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4344 | |
| 4345 | // For this test, we also check the call order of key functions. |
| 4346 | InSequence seq; |
| 4347 | |
| 4348 | EXPECT_CALL(mOutput, setExpensiveRenderingExpected(true)); |
Alec Mouri | f29700f | 2023-08-17 21:53:31 +0000 | [diff] [blame] | 4349 | EXPECT_CALL(mRenderEngine, drawLayers(_, _, _, _)) |
Patrick Williams | 2e9748f | 2022-08-09 22:48:18 +0000 | [diff] [blame] | 4350 | .WillOnce(Return(ByMove(ftl::yield<FenceResult>(Fence::NO_FENCE)))); |
Lloyd Pique | 6818fa5 | 2019-12-03 12:32:13 -0800 | [diff] [blame] | 4351 | |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 4352 | base::unique_fd fd; |
| 4353 | std::shared_ptr<renderengine::ExternalTexture> tex; |
| 4354 | mOutput.updateProtectedContentState(); |
| 4355 | mOutput.dequeueRenderBuffer(&fd, &tex); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 4356 | mOutput.composeSurfaces(kDebugRegion, tex, fd); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 4357 | } |
| 4358 | |
| 4359 | /* |
| 4360 | * Output::generateClientCompositionRequests() |
| 4361 | */ |
| 4362 | |
| 4363 | struct GenerateClientCompositionRequestsTest : public testing::Test { |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 4364 | struct OutputPartialMock : public OutputPartialMockBase { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 4365 | // compositionengine::Output overrides |
Robert Carr | ccab424 | 2021-09-28 16:53:03 -0700 | [diff] [blame] | 4366 | std::vector<LayerFE::LayerSettings> generateClientCompositionRequestsHelper( |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 4367 | bool supportsProtectedContent, ui::Dataspace dataspace) { |
Robert Carr | ccab424 | 2021-09-28 16:53:03 -0700 | [diff] [blame] | 4368 | std::vector<LayerFE*> ignore; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 4369 | return impl::Output::generateClientCompositionRequests(supportsProtectedContent, |
Robert Carr | ccab424 | 2021-09-28 16:53:03 -0700 | [diff] [blame] | 4370 | dataspace, ignore); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 4371 | } |
| 4372 | }; |
| 4373 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4374 | struct Layer { |
| 4375 | Layer() { |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 4376 | EXPECT_CALL(mOutputLayer, getOverrideCompositionSettings()) |
| 4377 | .WillRepeatedly(Return(std::nullopt)); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4378 | EXPECT_CALL(mOutputLayer, getState()).WillRepeatedly(ReturnRef(mOutputLayerState)); |
| 4379 | EXPECT_CALL(mOutputLayer, editState()).WillRepeatedly(ReturnRef(mOutputLayerState)); |
Ady Abraham | eca9d75 | 2021-03-03 12:20:00 -0800 | [diff] [blame] | 4380 | EXPECT_CALL(mOutputLayer, getLayerFE()).WillRepeatedly(ReturnRef(*mLayerFE)); |
| 4381 | EXPECT_CALL(*mLayerFE, getCompositionState()).WillRepeatedly(Return(&mLayerFEState)); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4382 | } |
| 4383 | |
| 4384 | StrictMock<mock::OutputLayer> mOutputLayer; |
Ady Abraham | eca9d75 | 2021-03-03 12:20:00 -0800 | [diff] [blame] | 4385 | sp<StrictMock<mock::LayerFE>> mLayerFE = sp<StrictMock<mock::LayerFE>>::make(); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4386 | LayerFECompositionState mLayerFEState; |
| 4387 | impl::OutputLayerCompositionState mOutputLayerState; |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 4388 | LayerFE::LayerSettings mLayerSettings; |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4389 | }; |
| 4390 | |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 4391 | GenerateClientCompositionRequestsTest() { |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4392 | mOutput.mState.needsFiltering = false; |
Chavi Weingarten | cbec71d | 2023-12-14 20:53:25 +0000 | [diff] [blame] | 4393 | mOutput.mState.isProtected = true; |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4394 | |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 4395 | mOutput.setDisplayColorProfileForTest( |
| 4396 | std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile)); |
| 4397 | mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface)); |
| 4398 | } |
| 4399 | |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 4400 | static constexpr float kLayerWhitePointNits = 200.f; |
| 4401 | |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 4402 | mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>(); |
| 4403 | mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>(); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 4404 | StrictMock<OutputPartialMock> mOutput; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 4405 | }; |
| 4406 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4407 | struct GenerateClientCompositionRequestsTest_ThreeLayers |
| 4408 | : public GenerateClientCompositionRequestsTest { |
| 4409 | GenerateClientCompositionRequestsTest_ThreeLayers() { |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 4410 | mOutput.mState.orientedDisplaySpace.setContent(kDisplayFrame); |
| 4411 | mOutput.mState.layerStackSpace.setContent(kDisplayViewport); |
| 4412 | mOutput.mState.displaySpace.setContent(kDisplayDestinationClip); |
Marin Shalamanov | 68933fb | 2020-09-10 17:58:12 +0200 | [diff] [blame] | 4413 | mOutput.mState.transform = |
| 4414 | ui::Transform{ui::Transform::toRotationFlags(kDisplayOrientation)}; |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 4415 | mOutput.mState.displaySpace.setOrientation(kDisplayOrientation); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4416 | mOutput.mState.needsFiltering = false; |
| 4417 | mOutput.mState.isSecure = false; |
Chavi Weingarten | cbec71d | 2023-12-14 20:53:25 +0000 | [diff] [blame] | 4418 | mOutput.mState.isProtected = true; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 4419 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4420 | for (size_t i = 0; i < mLayers.size(); i++) { |
| 4421 | mLayers[i].mOutputLayerState.clearClientTarget = false; |
| 4422 | mLayers[i].mOutputLayerState.visibleRegion = Region(kDisplayFrame); |
| 4423 | mLayers[i].mLayerFEState.isOpaque = true; |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 4424 | mLayers[i].mLayerSettings.geometry.boundaries = |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4425 | FloatRect{static_cast<float>(i + 1), 0.f, 0.f, 0.f}; |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 4426 | mLayers[i].mLayerSettings.source.solidColor = {1.0f, 1.0f, 1.0f}; |
| 4427 | mLayers[i].mLayerSettings.alpha = 1.0f; |
| 4428 | mLayers[i].mLayerSettings.disableBlending = false; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 4429 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4430 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(i)) |
| 4431 | .WillRepeatedly(Return(&mLayers[i].mOutputLayer)); |
| 4432 | EXPECT_CALL(mLayers[i].mOutputLayer, requiresClientComposition()) |
| 4433 | .WillRepeatedly(Return(true)); |
| 4434 | EXPECT_CALL(mLayers[i].mOutputLayer, needsFiltering()).WillRepeatedly(Return(false)); |
| 4435 | } |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 4436 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4437 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(mLayers.size())); |
| 4438 | } |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 4439 | |
Marin Shalamanov | 68933fb | 2020-09-10 17:58:12 +0200 | [diff] [blame] | 4440 | static constexpr ui::Rotation kDisplayOrientation = ui::ROTATION_0; |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4441 | static constexpr ui::Dataspace kDisplayDataspace = ui::Dataspace::UNKNOWN; |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 4442 | static constexpr float kLayerWhitePointNits = 200.f; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 4443 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4444 | static const Rect kDisplayFrame; |
| 4445 | static const Rect kDisplayViewport; |
Lloyd Pique | e8fe474 | 2020-01-21 15:26:18 -0800 | [diff] [blame] | 4446 | static const Rect kDisplayDestinationClip; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 4447 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4448 | std::array<Layer, 3> mLayers; |
| 4449 | }; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 4450 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4451 | const Rect GenerateClientCompositionRequestsTest_ThreeLayers::kDisplayFrame(0, 0, 100, 200); |
| 4452 | const Rect GenerateClientCompositionRequestsTest_ThreeLayers::kDisplayViewport(0, 0, 101, 201); |
Lloyd Pique | e8fe474 | 2020-01-21 15:26:18 -0800 | [diff] [blame] | 4453 | const Rect GenerateClientCompositionRequestsTest_ThreeLayers::kDisplayDestinationClip(0, 0, 103, |
| 4454 | 203); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 4455 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4456 | TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers, handlesNoClientCompostionLayers) { |
| 4457 | EXPECT_CALL(mLayers[0].mOutputLayer, requiresClientComposition()).WillOnce(Return(false)); |
| 4458 | EXPECT_CALL(mLayers[1].mOutputLayer, requiresClientComposition()).WillOnce(Return(false)); |
| 4459 | EXPECT_CALL(mLayers[2].mOutputLayer, requiresClientComposition()).WillOnce(Return(false)); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 4460 | |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 4461 | auto requests = |
| 4462 | mOutput.generateClientCompositionRequestsHelper(false /* supportsProtectedContent */, |
| 4463 | kDisplayDataspace); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 4464 | EXPECT_EQ(0u, requests.size()); |
| 4465 | } |
| 4466 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4467 | TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers, requiresVisibleRegionAfterViewportClip) { |
| 4468 | mLayers[0].mOutputLayerState.visibleRegion = Region(Rect(10, 10, 10, 10)); |
| 4469 | mLayers[1].mOutputLayerState.visibleRegion = Region(Rect(4000, 0, 4010, 10)); |
| 4470 | mLayers[2].mOutputLayerState.visibleRegion = Region(Rect(-10, -10, 0, 0)); |
| 4471 | |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 4472 | auto requests = |
| 4473 | mOutput.generateClientCompositionRequestsHelper(false /* supportsProtectedContent */, |
| 4474 | kDisplayDataspace); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4475 | EXPECT_EQ(0u, requests.size()); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4476 | } |
| 4477 | |
| 4478 | TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers, gathersClientCompositionRequests) { |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 4479 | EXPECT_CALL(*mLayers[0].mLayerFE, prepareClientComposition(_)) |
| 4480 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>())); |
| 4481 | EXPECT_CALL(*mLayers[1].mLayerFE, prepareClientComposition(_)) |
| 4482 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>(mLayers[1].mLayerSettings))); |
| 4483 | EXPECT_CALL(*mLayers[2].mLayerFE, prepareClientComposition(_)) |
| 4484 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>(mLayers[2].mLayerSettings))); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4485 | |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 4486 | auto requests = |
| 4487 | mOutput.generateClientCompositionRequestsHelper(false /* supportsProtectedContent */, |
| 4488 | kDisplayDataspace); |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 4489 | ASSERT_EQ(2u, requests.size()); |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 4490 | EXPECT_EQ(mLayers[1].mLayerSettings, requests[0]); |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 4491 | EXPECT_EQ(mLayers[2].mLayerSettings, requests[1]); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4492 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4493 | // Check that a timestamp was set for the layers that generated requests |
| 4494 | EXPECT_TRUE(0 == mLayers[0].mOutputLayerState.clientCompositionTimestamp); |
| 4495 | EXPECT_TRUE(0 != mLayers[1].mOutputLayerState.clientCompositionTimestamp); |
| 4496 | EXPECT_TRUE(0 != mLayers[2].mOutputLayerState.clientCompositionTimestamp); |
| 4497 | } |
| 4498 | |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 4499 | MATCHER_P(ClientCompositionTargetSettingsBlurSettingsEq, expectedBlurSetting, "") { |
| 4500 | *result_listener << "ClientCompositionTargetSettings' BlurSettings aren't equal \n"; |
| 4501 | *result_listener << "expected " << expectedBlurSetting << "\n"; |
| 4502 | *result_listener << "actual " << arg.blurSetting << "\n"; |
| 4503 | |
| 4504 | return expectedBlurSetting == arg.blurSetting; |
| 4505 | } |
| 4506 | |
| 4507 | TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers, overridesBlur) { |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 4508 | mLayers[2].mOutputLayerState.overrideInfo.disableBackgroundBlur = true; |
| 4509 | |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 4510 | EXPECT_CALL(*mLayers[0].mLayerFE, prepareClientComposition(_)) |
| 4511 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>())); |
| 4512 | EXPECT_CALL(*mLayers[1].mLayerFE, prepareClientComposition(_)) |
| 4513 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>(mLayers[1].mLayerSettings))); |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 4514 | EXPECT_CALL(*mLayers[2].mLayerFE, |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 4515 | prepareClientComposition(ClientCompositionTargetSettingsBlurSettingsEq( |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 4516 | LayerFE::ClientCompositionTargetSettings::BlurSetting::BlurRegionsOnly))) |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 4517 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>(mLayers[2].mLayerSettings))); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 4518 | auto requests = |
| 4519 | mOutput.generateClientCompositionRequestsHelper(false /* supportsProtectedContent */, |
| 4520 | kDisplayDataspace); |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 4521 | ASSERT_EQ(2u, requests.size()); |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 4522 | EXPECT_EQ(mLayers[1].mLayerSettings, requests[0]); |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 4523 | EXPECT_EQ(mLayers[2].mLayerSettings, requests[1]); |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 4524 | |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 4525 | // Check that a timestamp was set for the layers that generated requests |
| 4526 | EXPECT_TRUE(0 == mLayers[0].mOutputLayerState.clientCompositionTimestamp); |
| 4527 | EXPECT_TRUE(0 != mLayers[1].mOutputLayerState.clientCompositionTimestamp); |
| 4528 | EXPECT_TRUE(0 != mLayers[2].mOutputLayerState.clientCompositionTimestamp); |
| 4529 | } |
| 4530 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4531 | TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers, |
| 4532 | onlyClientComposesClientComposedLayersIfNoClearingNeeded) { |
| 4533 | EXPECT_CALL(mLayers[0].mOutputLayer, requiresClientComposition()).WillOnce(Return(false)); |
| 4534 | EXPECT_CALL(mLayers[1].mOutputLayer, requiresClientComposition()).WillOnce(Return(false)); |
| 4535 | EXPECT_CALL(mLayers[2].mOutputLayer, requiresClientComposition()).WillOnce(Return(true)); |
| 4536 | |
| 4537 | mLayers[0].mOutputLayerState.clearClientTarget = false; |
| 4538 | mLayers[1].mOutputLayerState.clearClientTarget = false; |
| 4539 | mLayers[2].mOutputLayerState.clearClientTarget = false; |
| 4540 | |
| 4541 | mLayers[0].mLayerFEState.isOpaque = true; |
| 4542 | mLayers[1].mLayerFEState.isOpaque = true; |
| 4543 | mLayers[2].mLayerFEState.isOpaque = true; |
| 4544 | |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 4545 | EXPECT_CALL(*mLayers[2].mLayerFE, prepareClientComposition(_)) |
| 4546 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>(mLayers[2].mLayerSettings))); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4547 | |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 4548 | auto requests = |
| 4549 | mOutput.generateClientCompositionRequestsHelper(false /* supportsProtectedContent */, |
| 4550 | kDisplayDataspace); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4551 | ASSERT_EQ(1u, requests.size()); |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 4552 | EXPECT_EQ(mLayers[2].mLayerSettings, requests[0]); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4553 | } |
| 4554 | |
| 4555 | TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers, |
| 4556 | onlyClientComposesClientComposedLayersIfOthersAreNotOpaque) { |
| 4557 | EXPECT_CALL(mLayers[0].mOutputLayer, requiresClientComposition()).WillOnce(Return(false)); |
| 4558 | EXPECT_CALL(mLayers[1].mOutputLayer, requiresClientComposition()).WillOnce(Return(false)); |
| 4559 | EXPECT_CALL(mLayers[2].mOutputLayer, requiresClientComposition()).WillOnce(Return(true)); |
| 4560 | |
| 4561 | mLayers[0].mOutputLayerState.clearClientTarget = true; |
| 4562 | mLayers[1].mOutputLayerState.clearClientTarget = true; |
| 4563 | mLayers[2].mOutputLayerState.clearClientTarget = true; |
| 4564 | |
| 4565 | mLayers[0].mLayerFEState.isOpaque = false; |
| 4566 | mLayers[1].mLayerFEState.isOpaque = false; |
| 4567 | mLayers[2].mLayerFEState.isOpaque = false; |
| 4568 | |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 4569 | EXPECT_CALL(*mLayers[2].mLayerFE, prepareClientComposition(_)) |
| 4570 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>(mLayers[2].mLayerSettings))); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4571 | |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 4572 | auto requests = |
| 4573 | mOutput.generateClientCompositionRequestsHelper(false /* supportsProtectedContent */, |
| 4574 | kDisplayDataspace); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4575 | ASSERT_EQ(1u, requests.size()); |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 4576 | EXPECT_EQ(mLayers[2].mLayerSettings, requests[0]); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4577 | } |
| 4578 | |
| 4579 | TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers, clearsHWCLayersIfOpaqueAndNotFirst) { |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 4580 | // If client composition is performed with some layers set to use device |
| 4581 | // composition, device layers after the first layer (device or client) will |
| 4582 | // clear the frame buffer if they are opaque and if that layer has a flag |
| 4583 | // set to do so. The first layer is skipped as the frame buffer is already |
| 4584 | // expected to be clear. |
| 4585 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4586 | EXPECT_CALL(mLayers[0].mOutputLayer, requiresClientComposition()).WillOnce(Return(false)); |
| 4587 | EXPECT_CALL(mLayers[1].mOutputLayer, requiresClientComposition()).WillOnce(Return(false)); |
| 4588 | EXPECT_CALL(mLayers[2].mOutputLayer, requiresClientComposition()).WillOnce(Return(true)); |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 4589 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4590 | mLayers[0].mOutputLayerState.clearClientTarget = true; |
| 4591 | mLayers[1].mOutputLayerState.clearClientTarget = true; |
| 4592 | mLayers[2].mOutputLayerState.clearClientTarget = true; |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 4593 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4594 | mLayers[0].mLayerFEState.isOpaque = true; |
| 4595 | mLayers[1].mLayerFEState.isOpaque = true; |
| 4596 | mLayers[2].mLayerFEState.isOpaque = true; |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 4597 | |
| 4598 | compositionengine::LayerFE::ClientCompositionTargetSettings layer1TargetSettings{ |
| 4599 | Region(kDisplayFrame), |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 4600 | false, /* needs filtering */ |
| 4601 | false, /* secure */ |
| 4602 | false, /* supports protected content */ |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 4603 | kDisplayViewport, |
| 4604 | kDisplayDataspace, |
| 4605 | false /* realContentIsVisible */, |
| 4606 | true /* clearContent */, |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 4607 | compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled, |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 4608 | kLayerWhitePointNits, |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 4609 | false /* treat170mAsSrgb */, |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 4610 | }; |
| 4611 | compositionengine::LayerFE::ClientCompositionTargetSettings layer2TargetSettings{ |
| 4612 | Region(kDisplayFrame), |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 4613 | false, /* needs filtering */ |
| 4614 | false, /* secure */ |
| 4615 | false, /* supports protected content */ |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 4616 | kDisplayViewport, |
| 4617 | kDisplayDataspace, |
| 4618 | true /* realContentIsVisible */, |
| 4619 | false /* clearContent */, |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 4620 | compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled, |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 4621 | kLayerWhitePointNits, |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 4622 | false /* treat170mAsSrgb */, |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 4623 | }; |
| 4624 | |
| 4625 | LayerFE::LayerSettings mBlackoutSettings = mLayers[1].mLayerSettings; |
| 4626 | mBlackoutSettings.source.buffer.buffer = nullptr; |
| 4627 | mBlackoutSettings.source.solidColor = {0.1f, 0.1f, 0.1f}; |
| 4628 | mBlackoutSettings.alpha = 0.f; |
| 4629 | mBlackoutSettings.disableBlending = true; |
| 4630 | |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 4631 | EXPECT_CALL(*mLayers[1].mLayerFE, prepareClientComposition(Eq(ByRef(layer1TargetSettings)))) |
| 4632 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>(mBlackoutSettings))); |
| 4633 | EXPECT_CALL(*mLayers[2].mLayerFE, prepareClientComposition(Eq(ByRef(layer2TargetSettings)))) |
| 4634 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>(mLayers[2].mLayerSettings))); |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 4635 | |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 4636 | auto requests = |
| 4637 | mOutput.generateClientCompositionRequestsHelper(false /* supportsProtectedContent */, |
| 4638 | kDisplayDataspace); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4639 | ASSERT_EQ(2u, requests.size()); |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 4640 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4641 | // 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] | 4642 | EXPECT_EQ(mBlackoutSettings, requests[0]); |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 4643 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 4644 | EXPECT_EQ(mLayers[2].mLayerSettings, requests[1]); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4645 | } |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 4646 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4647 | TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers, |
| 4648 | clippedVisibleRegionUsedToGenerateRequest) { |
| 4649 | mLayers[0].mOutputLayerState.visibleRegion = Region(Rect(10, 10, 20, 20)); |
| 4650 | mLayers[1].mOutputLayerState.visibleRegion = Region(Rect(-10, -10, 30, 30)); |
| 4651 | mLayers[2].mOutputLayerState.visibleRegion = Region(Rect(-10, 0, 40, 4000)); |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 4652 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4653 | compositionengine::LayerFE::ClientCompositionTargetSettings layer0TargetSettings{ |
| 4654 | Region(Rect(10, 10, 20, 20)), |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4655 | false, /* needs filtering */ |
| 4656 | false, /* secure */ |
| 4657 | false, /* supports protected content */ |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 4658 | kDisplayViewport, |
| 4659 | kDisplayDataspace, |
| 4660 | true /* realContentIsVisible */, |
| 4661 | false /* clearContent */, |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 4662 | compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled, |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 4663 | kLayerWhitePointNits, |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 4664 | false /* treat170mAsSrgb */, |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4665 | }; |
| 4666 | compositionengine::LayerFE::ClientCompositionTargetSettings layer1TargetSettings{ |
| 4667 | Region(Rect(0, 0, 30, 30)), |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4668 | false, /* needs filtering */ |
| 4669 | false, /* secure */ |
| 4670 | false, /* supports protected content */ |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 4671 | kDisplayViewport, |
| 4672 | kDisplayDataspace, |
| 4673 | true /* realContentIsVisible */, |
| 4674 | false /* clearContent */, |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 4675 | compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled, |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 4676 | kLayerWhitePointNits, |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 4677 | false /* treat170mAsSrgb */, |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4678 | }; |
| 4679 | compositionengine::LayerFE::ClientCompositionTargetSettings layer2TargetSettings{ |
| 4680 | Region(Rect(0, 0, 40, 201)), |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4681 | false, /* needs filtering */ |
| 4682 | false, /* secure */ |
| 4683 | false, /* supports protected content */ |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 4684 | kDisplayViewport, |
| 4685 | kDisplayDataspace, |
| 4686 | true /* realContentIsVisible */, |
| 4687 | false /* clearContent */, |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 4688 | compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled, |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 4689 | kLayerWhitePointNits, |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 4690 | false /* treat170mAsSrgb */, |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4691 | }; |
| 4692 | |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 4693 | EXPECT_CALL(*mLayers[0].mLayerFE, prepareClientComposition(Eq(ByRef(layer0TargetSettings)))) |
| 4694 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>())); |
| 4695 | EXPECT_CALL(*mLayers[1].mLayerFE, prepareClientComposition(Eq(ByRef(layer1TargetSettings)))) |
| 4696 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>())); |
| 4697 | EXPECT_CALL(*mLayers[2].mLayerFE, prepareClientComposition(Eq(ByRef(layer2TargetSettings)))) |
| 4698 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>())); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4699 | |
| 4700 | static_cast<void>( |
Robert Carr | ccab424 | 2021-09-28 16:53:03 -0700 | [diff] [blame] | 4701 | mOutput.generateClientCompositionRequestsHelper(false /* supportsProtectedContent */, |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 4702 | kDisplayDataspace)); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4703 | } |
| 4704 | |
| 4705 | TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers, |
| 4706 | perLayerNeedsFilteringUsedToGenerateRequests) { |
| 4707 | mOutput.mState.needsFiltering = false; |
| 4708 | EXPECT_CALL(mLayers[0].mOutputLayer, needsFiltering()).WillRepeatedly(Return(true)); |
| 4709 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4710 | compositionengine::LayerFE::ClientCompositionTargetSettings layer0TargetSettings{ |
| 4711 | Region(kDisplayFrame), |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4712 | true, /* needs filtering */ |
| 4713 | false, /* secure */ |
| 4714 | false, /* supports protected content */ |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 4715 | kDisplayViewport, |
| 4716 | kDisplayDataspace, |
| 4717 | true /* realContentIsVisible */, |
| 4718 | false /* clearContent */, |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 4719 | compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled, |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 4720 | kLayerWhitePointNits, |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 4721 | false /* treat170mAsSrgb */, |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4722 | }; |
| 4723 | compositionengine::LayerFE::ClientCompositionTargetSettings layer1TargetSettings{ |
| 4724 | Region(kDisplayFrame), |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4725 | false, /* needs filtering */ |
| 4726 | false, /* secure */ |
| 4727 | false, /* supports protected content */ |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 4728 | kDisplayViewport, |
| 4729 | kDisplayDataspace, |
| 4730 | true /* realContentIsVisible */, |
| 4731 | false /* clearContent */, |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 4732 | compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled, |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 4733 | kLayerWhitePointNits, |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 4734 | false /* treat170mAsSrgb */, |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4735 | }; |
| 4736 | compositionengine::LayerFE::ClientCompositionTargetSettings layer2TargetSettings{ |
| 4737 | Region(kDisplayFrame), |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4738 | false, /* needs filtering */ |
| 4739 | false, /* secure */ |
| 4740 | false, /* supports protected content */ |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 4741 | kDisplayViewport, |
| 4742 | kDisplayDataspace, |
| 4743 | true /* realContentIsVisible */, |
| 4744 | false /* clearContent */, |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 4745 | compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled, |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 4746 | kLayerWhitePointNits, |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 4747 | false /* treat170mAsSrgb */, |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4748 | }; |
| 4749 | |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 4750 | EXPECT_CALL(*mLayers[0].mLayerFE, prepareClientComposition(Eq(ByRef(layer0TargetSettings)))) |
| 4751 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>())); |
| 4752 | EXPECT_CALL(*mLayers[1].mLayerFE, prepareClientComposition(Eq(ByRef(layer1TargetSettings)))) |
| 4753 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>())); |
| 4754 | EXPECT_CALL(*mLayers[2].mLayerFE, prepareClientComposition(Eq(ByRef(layer2TargetSettings)))) |
| 4755 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>())); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4756 | |
| 4757 | static_cast<void>( |
Robert Carr | ccab424 | 2021-09-28 16:53:03 -0700 | [diff] [blame] | 4758 | mOutput.generateClientCompositionRequestsHelper(false /* supportsProtectedContent */, |
| 4759 | kDisplayDataspace)); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4760 | } |
| 4761 | |
| 4762 | TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers, |
| 4763 | wholeOutputNeedsFilteringUsedToGenerateRequests) { |
| 4764 | mOutput.mState.needsFiltering = true; |
| 4765 | EXPECT_CALL(mLayers[0].mOutputLayer, needsFiltering()).WillRepeatedly(Return(true)); |
| 4766 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4767 | compositionengine::LayerFE::ClientCompositionTargetSettings layer0TargetSettings{ |
| 4768 | Region(kDisplayFrame), |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4769 | true, /* needs filtering */ |
| 4770 | false, /* secure */ |
| 4771 | false, /* supports protected content */ |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 4772 | kDisplayViewport, |
| 4773 | kDisplayDataspace, |
| 4774 | true /* realContentIsVisible */, |
| 4775 | false /* clearContent */, |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 4776 | compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled, |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 4777 | kLayerWhitePointNits, |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 4778 | false /* treat170mAsSrgb */, |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4779 | }; |
| 4780 | compositionengine::LayerFE::ClientCompositionTargetSettings layer1TargetSettings{ |
| 4781 | Region(kDisplayFrame), |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4782 | true, /* needs filtering */ |
| 4783 | false, /* secure */ |
| 4784 | false, /* supports protected content */ |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 4785 | kDisplayViewport, |
| 4786 | kDisplayDataspace, |
| 4787 | true /* realContentIsVisible */, |
| 4788 | false /* clearContent */, |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 4789 | compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled, |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 4790 | kLayerWhitePointNits, |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 4791 | false /* treat170mAsSrgb */, |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4792 | }; |
| 4793 | compositionengine::LayerFE::ClientCompositionTargetSettings layer2TargetSettings{ |
| 4794 | Region(kDisplayFrame), |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4795 | true, /* needs filtering */ |
| 4796 | false, /* secure */ |
| 4797 | false, /* supports protected content */ |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 4798 | kDisplayViewport, |
| 4799 | kDisplayDataspace, |
| 4800 | true /* realContentIsVisible */, |
| 4801 | false /* clearContent */, |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 4802 | compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled, |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 4803 | kLayerWhitePointNits, |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 4804 | false /* treat170mAsSrgb */, |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4805 | }; |
| 4806 | |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 4807 | EXPECT_CALL(*mLayers[0].mLayerFE, prepareClientComposition(Eq(ByRef(layer0TargetSettings)))) |
| 4808 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>())); |
| 4809 | EXPECT_CALL(*mLayers[1].mLayerFE, prepareClientComposition(Eq(ByRef(layer1TargetSettings)))) |
| 4810 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>())); |
| 4811 | EXPECT_CALL(*mLayers[2].mLayerFE, prepareClientComposition(Eq(ByRef(layer2TargetSettings)))) |
| 4812 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>())); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4813 | |
| 4814 | static_cast<void>( |
Robert Carr | ccab424 | 2021-09-28 16:53:03 -0700 | [diff] [blame] | 4815 | mOutput.generateClientCompositionRequestsHelper(false /* supportsProtectedContent */, |
| 4816 | kDisplayDataspace)); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4817 | } |
| 4818 | |
| 4819 | TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers, |
| 4820 | wholeOutputSecurityUsedToGenerateRequests) { |
| 4821 | mOutput.mState.isSecure = true; |
| 4822 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4823 | compositionengine::LayerFE::ClientCompositionTargetSettings layer0TargetSettings{ |
| 4824 | Region(kDisplayFrame), |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4825 | false, /* needs filtering */ |
| 4826 | true, /* secure */ |
| 4827 | false, /* supports protected content */ |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 4828 | kDisplayViewport, |
| 4829 | kDisplayDataspace, |
| 4830 | true /* realContentIsVisible */, |
| 4831 | false /* clearContent */, |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 4832 | compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled, |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 4833 | kLayerWhitePointNits, |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 4834 | false /* treat170mAsSrgb */, |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4835 | }; |
| 4836 | compositionengine::LayerFE::ClientCompositionTargetSettings layer1TargetSettings{ |
| 4837 | Region(kDisplayFrame), |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4838 | false, /* needs filtering */ |
| 4839 | true, /* secure */ |
| 4840 | false, /* supports protected content */ |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 4841 | kDisplayViewport, |
| 4842 | kDisplayDataspace, |
| 4843 | true /* realContentIsVisible */, |
| 4844 | false /* clearContent */, |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 4845 | compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled, |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 4846 | kLayerWhitePointNits, |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 4847 | false /* treat170mAsSrgb */, |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4848 | }; |
| 4849 | compositionengine::LayerFE::ClientCompositionTargetSettings layer2TargetSettings{ |
| 4850 | Region(kDisplayFrame), |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4851 | false, /* needs filtering */ |
| 4852 | true, /* secure */ |
| 4853 | false, /* supports protected content */ |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 4854 | kDisplayViewport, |
| 4855 | kDisplayDataspace, |
| 4856 | true /* realContentIsVisible */, |
| 4857 | false /* clearContent */, |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 4858 | compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled, |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 4859 | kLayerWhitePointNits, |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 4860 | false /* treat170mAsSrgb */, |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4861 | }; |
| 4862 | |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 4863 | EXPECT_CALL(*mLayers[0].mLayerFE, prepareClientComposition(Eq(ByRef(layer0TargetSettings)))) |
| 4864 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>())); |
| 4865 | EXPECT_CALL(*mLayers[1].mLayerFE, prepareClientComposition(Eq(ByRef(layer1TargetSettings)))) |
| 4866 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>())); |
| 4867 | EXPECT_CALL(*mLayers[2].mLayerFE, prepareClientComposition(Eq(ByRef(layer2TargetSettings)))) |
| 4868 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>())); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4869 | |
| 4870 | static_cast<void>( |
Robert Carr | ccab424 | 2021-09-28 16:53:03 -0700 | [diff] [blame] | 4871 | mOutput.generateClientCompositionRequestsHelper(false /* supportsProtectedContent */, |
| 4872 | kDisplayDataspace)); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4873 | } |
| 4874 | |
| 4875 | TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers, |
| 4876 | protectedContentSupportUsedToGenerateRequests) { |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4877 | compositionengine::LayerFE::ClientCompositionTargetSettings layer0TargetSettings{ |
| 4878 | Region(kDisplayFrame), |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4879 | false, /* needs filtering */ |
| 4880 | false, /* secure */ |
Chavi Weingarten | cbec71d | 2023-12-14 20:53:25 +0000 | [diff] [blame] | 4881 | true, /* isProtected */ |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 4882 | kDisplayViewport, |
| 4883 | kDisplayDataspace, |
| 4884 | true /* realContentIsVisible */, |
| 4885 | false /* clearContent */, |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 4886 | compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled, |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 4887 | kLayerWhitePointNits, |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 4888 | false /* treat170mAsSrgb */, |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4889 | }; |
| 4890 | compositionengine::LayerFE::ClientCompositionTargetSettings layer1TargetSettings{ |
| 4891 | Region(kDisplayFrame), |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4892 | false, /* needs filtering */ |
| 4893 | false, /* secure */ |
Chavi Weingarten | cbec71d | 2023-12-14 20:53:25 +0000 | [diff] [blame] | 4894 | true, /* isProtected */ |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 4895 | kDisplayViewport, |
| 4896 | kDisplayDataspace, |
| 4897 | true /* realContentIsVisible */, |
| 4898 | false /* clearContent */, |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 4899 | compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled, |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 4900 | kLayerWhitePointNits, |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 4901 | false /* treat170mAsSrgb */, |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4902 | }; |
| 4903 | compositionengine::LayerFE::ClientCompositionTargetSettings layer2TargetSettings{ |
| 4904 | Region(kDisplayFrame), |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4905 | false, /* needs filtering */ |
| 4906 | false, /* secure */ |
Chavi Weingarten | cbec71d | 2023-12-14 20:53:25 +0000 | [diff] [blame] | 4907 | true, /* isProtected */ |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 4908 | kDisplayViewport, |
| 4909 | kDisplayDataspace, |
| 4910 | true /* realContentIsVisible */, |
| 4911 | false /* clearContent */, |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 4912 | compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled, |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 4913 | kLayerWhitePointNits, |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 4914 | false /* treat170mAsSrgb */, |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4915 | }; |
| 4916 | |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 4917 | EXPECT_CALL(*mLayers[0].mLayerFE, prepareClientComposition(Eq(ByRef(layer0TargetSettings)))) |
| 4918 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>())); |
| 4919 | EXPECT_CALL(*mLayers[1].mLayerFE, prepareClientComposition(Eq(ByRef(layer1TargetSettings)))) |
| 4920 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>())); |
| 4921 | EXPECT_CALL(*mLayers[2].mLayerFE, prepareClientComposition(Eq(ByRef(layer2TargetSettings)))) |
| 4922 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>())); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4923 | |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 4924 | static_cast<void>( |
| 4925 | mOutput.generateClientCompositionRequestsHelper(true /* supportsProtectedContent */, |
| 4926 | kDisplayDataspace)); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 4927 | } |
| 4928 | |
Lucas Dupin | 084a6d4 | 2021-08-26 22:10:29 +0000 | [diff] [blame] | 4929 | TEST_F(OutputUpdateAndWriteCompositionStateTest, noBackgroundBlurWhenOpaque) { |
| 4930 | InjectedLayer layer1; |
| 4931 | InjectedLayer layer2; |
| 4932 | |
| 4933 | uint32_t z = 0; |
| 4934 | // Layer requesting blur, or below, should request client composition, unless opaque. |
| 4935 | EXPECT_CALL(*layer1.outputLayer, updateCompositionState(false, false, ui::Transform::ROT_0)); |
| 4936 | EXPECT_CALL(*layer1.outputLayer, |
| 4937 | writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, z++, |
| 4938 | /*zIsOverridden*/ false, /*isPeekingThrough*/ false)); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 4939 | EXPECT_CALL(*layer1.outputLayer, requiresClientComposition()).WillRepeatedly(Return(false)); |
Lucas Dupin | 084a6d4 | 2021-08-26 22:10:29 +0000 | [diff] [blame] | 4940 | EXPECT_CALL(*layer2.outputLayer, updateCompositionState(false, false, ui::Transform::ROT_0)); |
| 4941 | EXPECT_CALL(*layer2.outputLayer, |
| 4942 | writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, z++, |
| 4943 | /*zIsOverridden*/ false, /*isPeekingThrough*/ false)); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 4944 | EXPECT_CALL(*layer2.outputLayer, requiresClientComposition()).WillRepeatedly(Return(false)); |
Lucas Dupin | 084a6d4 | 2021-08-26 22:10:29 +0000 | [diff] [blame] | 4945 | |
| 4946 | layer2.layerFEState.backgroundBlurRadius = 10; |
| 4947 | layer2.layerFEState.isOpaque = true; |
| 4948 | |
| 4949 | injectOutputLayer(layer1); |
| 4950 | injectOutputLayer(layer2); |
| 4951 | |
| 4952 | mOutput->editState().isEnabled = true; |
| 4953 | |
| 4954 | CompositionRefreshArgs args; |
| 4955 | args.updatingGeometryThisFrame = false; |
| 4956 | args.devOptForceClientComposition = false; |
| 4957 | mOutput->updateCompositionState(args); |
| 4958 | mOutput->planComposition(); |
| 4959 | mOutput->writeCompositionState(args); |
| 4960 | } |
| 4961 | |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 4962 | TEST_F(OutputUpdateAndWriteCompositionStateTest, handlesBackgroundBlurRequests) { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 4963 | InjectedLayer layer1; |
| 4964 | InjectedLayer layer2; |
| 4965 | InjectedLayer layer3; |
| 4966 | |
Leon Scroggins III | e2ee040 | 2021-04-02 16:59:37 -0400 | [diff] [blame] | 4967 | uint32_t z = 0; |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 4968 | // Layer requesting blur, or below, should request client composition. |
Snild Dolkow | 9e217d6 | 2020-04-22 15:53:42 +0200 | [diff] [blame] | 4969 | EXPECT_CALL(*layer1.outputLayer, updateCompositionState(false, true, ui::Transform::ROT_0)); |
Dan Stoza | 6166c31 | 2021-01-15 16:34:05 -0800 | [diff] [blame] | 4970 | EXPECT_CALL(*layer1.outputLayer, |
Leon Scroggins III | 9aa25c2 | 2021-04-15 15:30:19 -0400 | [diff] [blame] | 4971 | writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, z++, |
| 4972 | /*zIsOverridden*/ false, /*isPeekingThrough*/ false)); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 4973 | EXPECT_CALL(*layer1.outputLayer, requiresClientComposition()).WillRepeatedly(Return(false)); |
Snild Dolkow | 9e217d6 | 2020-04-22 15:53:42 +0200 | [diff] [blame] | 4974 | EXPECT_CALL(*layer2.outputLayer, updateCompositionState(false, true, ui::Transform::ROT_0)); |
Dan Stoza | 6166c31 | 2021-01-15 16:34:05 -0800 | [diff] [blame] | 4975 | EXPECT_CALL(*layer2.outputLayer, |
Leon Scroggins III | 9aa25c2 | 2021-04-15 15:30:19 -0400 | [diff] [blame] | 4976 | writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, z++, |
| 4977 | /*zIsOverridden*/ false, /*isPeekingThrough*/ false)); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 4978 | EXPECT_CALL(*layer2.outputLayer, requiresClientComposition()).WillRepeatedly(Return(false)); |
Snild Dolkow | 9e217d6 | 2020-04-22 15:53:42 +0200 | [diff] [blame] | 4979 | EXPECT_CALL(*layer3.outputLayer, updateCompositionState(false, false, ui::Transform::ROT_0)); |
Dan Stoza | 6166c31 | 2021-01-15 16:34:05 -0800 | [diff] [blame] | 4980 | EXPECT_CALL(*layer3.outputLayer, |
Leon Scroggins III | 9aa25c2 | 2021-04-15 15:30:19 -0400 | [diff] [blame] | 4981 | writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, z++, |
| 4982 | /*zIsOverridden*/ false, /*isPeekingThrough*/ false)); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 4983 | EXPECT_CALL(*layer3.outputLayer, requiresClientComposition()).WillRepeatedly(Return(false)); |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 4984 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 4985 | layer2.layerFEState.backgroundBlurRadius = 10; |
Lucas Dupin | 084a6d4 | 2021-08-26 22:10:29 +0000 | [diff] [blame] | 4986 | layer2.layerFEState.isOpaque = false; |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 4987 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 4988 | injectOutputLayer(layer1); |
| 4989 | injectOutputLayer(layer2); |
| 4990 | injectOutputLayer(layer3); |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 4991 | |
| 4992 | mOutput->editState().isEnabled = true; |
| 4993 | |
| 4994 | CompositionRefreshArgs args; |
| 4995 | args.updatingGeometryThisFrame = false; |
| 4996 | args.devOptForceClientComposition = false; |
Dan Stoza | 269dc4d | 2021-01-15 15:07:43 -0800 | [diff] [blame] | 4997 | mOutput->updateCompositionState(args); |
| 4998 | mOutput->planComposition(); |
| 4999 | mOutput->writeCompositionState(args); |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 5000 | } |
| 5001 | |
Lucas Dupin | c3800b8 | 2020-10-02 16:24:48 -0700 | [diff] [blame] | 5002 | TEST_F(OutputUpdateAndWriteCompositionStateTest, handlesBlurRegionRequests) { |
| 5003 | InjectedLayer layer1; |
| 5004 | InjectedLayer layer2; |
| 5005 | InjectedLayer layer3; |
| 5006 | |
Leon Scroggins III | e2ee040 | 2021-04-02 16:59:37 -0400 | [diff] [blame] | 5007 | uint32_t z = 0; |
Lucas Dupin | c3800b8 | 2020-10-02 16:24:48 -0700 | [diff] [blame] | 5008 | // Layer requesting blur, or below, should request client composition. |
| 5009 | EXPECT_CALL(*layer1.outputLayer, updateCompositionState(false, true, ui::Transform::ROT_0)); |
Dan Stoza | 6166c31 | 2021-01-15 16:34:05 -0800 | [diff] [blame] | 5010 | EXPECT_CALL(*layer1.outputLayer, |
Leon Scroggins III | 9aa25c2 | 2021-04-15 15:30:19 -0400 | [diff] [blame] | 5011 | writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, z++, |
| 5012 | /*zIsOverridden*/ false, /*isPeekingThrough*/ false)); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 5013 | EXPECT_CALL(*layer1.outputLayer, requiresClientComposition()).WillRepeatedly(Return(false)); |
Lucas Dupin | c3800b8 | 2020-10-02 16:24:48 -0700 | [diff] [blame] | 5014 | EXPECT_CALL(*layer2.outputLayer, updateCompositionState(false, true, ui::Transform::ROT_0)); |
Dan Stoza | 6166c31 | 2021-01-15 16:34:05 -0800 | [diff] [blame] | 5015 | EXPECT_CALL(*layer2.outputLayer, |
Leon Scroggins III | 9aa25c2 | 2021-04-15 15:30:19 -0400 | [diff] [blame] | 5016 | writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, z++, |
| 5017 | /*zIsOverridden*/ false, /*isPeekingThrough*/ false)); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 5018 | EXPECT_CALL(*layer2.outputLayer, requiresClientComposition()).WillRepeatedly(Return(false)); |
Lucas Dupin | c3800b8 | 2020-10-02 16:24:48 -0700 | [diff] [blame] | 5019 | EXPECT_CALL(*layer3.outputLayer, updateCompositionState(false, false, ui::Transform::ROT_0)); |
Dan Stoza | 6166c31 | 2021-01-15 16:34:05 -0800 | [diff] [blame] | 5020 | EXPECT_CALL(*layer3.outputLayer, |
Leon Scroggins III | 9aa25c2 | 2021-04-15 15:30:19 -0400 | [diff] [blame] | 5021 | writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, z++, |
| 5022 | /*zIsOverridden*/ false, /*isPeekingThrough*/ false)); |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 5023 | EXPECT_CALL(*layer3.outputLayer, requiresClientComposition()).WillRepeatedly(Return(false)); |
Lucas Dupin | c3800b8 | 2020-10-02 16:24:48 -0700 | [diff] [blame] | 5024 | |
| 5025 | BlurRegion region; |
| 5026 | layer2.layerFEState.blurRegions.push_back(region); |
Lucas Dupin | 084a6d4 | 2021-08-26 22:10:29 +0000 | [diff] [blame] | 5027 | layer2.layerFEState.isOpaque = false; |
Lucas Dupin | c3800b8 | 2020-10-02 16:24:48 -0700 | [diff] [blame] | 5028 | |
| 5029 | injectOutputLayer(layer1); |
| 5030 | injectOutputLayer(layer2); |
| 5031 | injectOutputLayer(layer3); |
| 5032 | |
| 5033 | mOutput->editState().isEnabled = true; |
| 5034 | |
| 5035 | CompositionRefreshArgs args; |
| 5036 | args.updatingGeometryThisFrame = false; |
| 5037 | args.devOptForceClientComposition = false; |
Dan Stoza | 269dc4d | 2021-01-15 15:07:43 -0800 | [diff] [blame] | 5038 | mOutput->updateCompositionState(args); |
| 5039 | mOutput->planComposition(); |
| 5040 | mOutput->writeCompositionState(args); |
Lucas Dupin | c3800b8 | 2020-10-02 16:24:48 -0700 | [diff] [blame] | 5041 | } |
| 5042 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 5043 | TEST_F(GenerateClientCompositionRequestsTest, handlesLandscapeModeSplitScreenRequests) { |
| 5044 | // In split-screen landscape mode, the screen is rotated 90 degrees, with |
| 5045 | // one layer on the left covering the left side of the output, and one layer |
| 5046 | // on the right covering that side of the output. |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 5047 | |
| 5048 | const Rect kPortraitFrame(0, 0, 1000, 2000); |
| 5049 | const Rect kPortraitViewport(0, 0, 2000, 1000); |
Lloyd Pique | e8fe474 | 2020-01-21 15:26:18 -0800 | [diff] [blame] | 5050 | const Rect kPortraitDestinationClip(0, 0, 1000, 2000); |
Marin Shalamanov | 68933fb | 2020-09-10 17:58:12 +0200 | [diff] [blame] | 5051 | const ui::Rotation kPortraitOrientation = ui::ROTATION_90; |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 5052 | constexpr ui::Dataspace kOutputDataspace = ui::Dataspace::DISPLAY_P3; |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 5053 | |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 5054 | mOutput.mState.orientedDisplaySpace.setContent(kPortraitFrame); |
| 5055 | mOutput.mState.layerStackSpace.setContent(kPortraitViewport); |
| 5056 | mOutput.mState.displaySpace.setContent(kPortraitDestinationClip); |
Marin Shalamanov | 68933fb | 2020-09-10 17:58:12 +0200 | [diff] [blame] | 5057 | mOutput.mState.transform = ui::Transform{ui::Transform::toRotationFlags(kPortraitOrientation)}; |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 5058 | mOutput.mState.displaySpace.setOrientation(kPortraitOrientation); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 5059 | mOutput.mState.needsFiltering = false; |
| 5060 | mOutput.mState.isSecure = true; |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 5061 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 5062 | Layer leftLayer; |
| 5063 | Layer rightLayer; |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 5064 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 5065 | leftLayer.mOutputLayerState.clearClientTarget = false; |
| 5066 | leftLayer.mOutputLayerState.visibleRegion = Region(Rect(0, 0, 1000, 1000)); |
| 5067 | leftLayer.mLayerFEState.isOpaque = true; |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 5068 | leftLayer.mLayerSettings.source.solidColor = {1.f, 0.f, 0.f}; |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 5069 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 5070 | rightLayer.mOutputLayerState.clearClientTarget = false; |
| 5071 | rightLayer.mOutputLayerState.visibleRegion = Region(Rect(1000, 0, 2000, 1000)); |
| 5072 | rightLayer.mLayerFEState.isOpaque = true; |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 5073 | rightLayer.mLayerSettings.source.solidColor = {0.f, 1.f, 0.f}; |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 5074 | |
| 5075 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(2u)); |
| 5076 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0u)) |
| 5077 | .WillRepeatedly(Return(&leftLayer.mOutputLayer)); |
| 5078 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(1u)) |
| 5079 | .WillRepeatedly(Return(&rightLayer.mOutputLayer)); |
| 5080 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 5081 | compositionengine::LayerFE::ClientCompositionTargetSettings leftLayerSettings{ |
| 5082 | Region(Rect(0, 0, 1000, 1000)), |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 5083 | false, /* needs filtering */ |
| 5084 | true, /* secure */ |
Chavi Weingarten | cbec71d | 2023-12-14 20:53:25 +0000 | [diff] [blame] | 5085 | true, /* isProtected */ |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 5086 | kPortraitViewport, |
| 5087 | kOutputDataspace, |
| 5088 | true /* realContentIsVisible */, |
| 5089 | false /* clearContent */, |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 5090 | compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled, |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 5091 | kLayerWhitePointNits, |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 5092 | false /* treat170mAsSrgb */, |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 5093 | }; |
| 5094 | |
| 5095 | EXPECT_CALL(leftLayer.mOutputLayer, requiresClientComposition()).WillRepeatedly(Return(true)); |
| 5096 | EXPECT_CALL(leftLayer.mOutputLayer, needsFiltering()).WillRepeatedly(Return(false)); |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 5097 | EXPECT_CALL(*leftLayer.mLayerFE, prepareClientComposition(Eq(ByRef(leftLayerSettings)))) |
| 5098 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>(leftLayer.mLayerSettings))); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 5099 | |
| 5100 | compositionengine::LayerFE::ClientCompositionTargetSettings rightLayerSettings{ |
| 5101 | Region(Rect(1000, 0, 2000, 1000)), |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 5102 | false, /* needs filtering */ |
| 5103 | true, /* secure */ |
Chavi Weingarten | cbec71d | 2023-12-14 20:53:25 +0000 | [diff] [blame] | 5104 | true, /* isProtected */ |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 5105 | kPortraitViewport, |
| 5106 | kOutputDataspace, |
| 5107 | true /* realContentIsVisible */, |
| 5108 | false /* clearContent */, |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 5109 | compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled, |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 5110 | kLayerWhitePointNits, |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 5111 | false /* treat170mAsSrgb */, |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 5112 | }; |
| 5113 | |
| 5114 | EXPECT_CALL(rightLayer.mOutputLayer, requiresClientComposition()).WillRepeatedly(Return(true)); |
| 5115 | EXPECT_CALL(rightLayer.mOutputLayer, needsFiltering()).WillRepeatedly(Return(false)); |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 5116 | EXPECT_CALL(*rightLayer.mLayerFE, prepareClientComposition(Eq(ByRef(rightLayerSettings)))) |
| 5117 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>(rightLayer.mLayerSettings))); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 5118 | |
| 5119 | constexpr bool supportsProtectedContent = true; |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 5120 | auto requests = mOutput.generateClientCompositionRequestsHelper(supportsProtectedContent, |
| 5121 | kOutputDataspace); |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 5122 | ASSERT_EQ(2u, requests.size()); |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 5123 | EXPECT_EQ(leftLayer.mLayerSettings, requests[0]); |
| 5124 | EXPECT_EQ(rightLayer.mLayerSettings, requests[1]); |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 5125 | } |
| 5126 | |
Vishnu Nair | a483b4a | 2019-12-12 15:07:52 -0800 | [diff] [blame] | 5127 | TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers, |
| 5128 | shadowRegionOnlyVisibleSkipsContentComposition) { |
| 5129 | const Rect kContentWithShadow(40, 40, 70, 90); |
| 5130 | const Rect kContent(50, 50, 60, 80); |
| 5131 | const Region kShadowRegion = Region(kContentWithShadow).subtract(kContent); |
| 5132 | const Region kPartialShadowRegion = Region(kContentWithShadow).subtract(Rect(40, 40, 60, 80)); |
| 5133 | |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 5134 | compositionengine::LayerFE::ClientCompositionTargetSettings layer2Settings{ |
| 5135 | 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] | 5136 | false, /* needs filtering */ |
| 5137 | false, /* secure */ |
| 5138 | false, /* supports protected content */ |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 5139 | kDisplayViewport, |
| 5140 | kDisplayDataspace, |
| 5141 | false /* realContentIsVisible */, |
| 5142 | false /* clearContent */, |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 5143 | compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled, |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 5144 | kLayerWhitePointNits, |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 5145 | false /* treat170mAsSrgb */, |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 5146 | }; |
| 5147 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 5148 | LayerFE::LayerSettings mShadowSettings; |
| 5149 | mShadowSettings.source.solidColor = {0.1f, 0.1f, 0.1f}; |
Vishnu Nair | a483b4a | 2019-12-12 15:07:52 -0800 | [diff] [blame] | 5150 | |
| 5151 | mLayers[2].mOutputLayerState.visibleRegion = kPartialShadowRegion; |
| 5152 | mLayers[2].mOutputLayerState.shadowRegion = kShadowRegion; |
| 5153 | |
| 5154 | EXPECT_CALL(mLayers[0].mOutputLayer, requiresClientComposition()).WillOnce(Return(false)); |
| 5155 | EXPECT_CALL(mLayers[1].mOutputLayer, requiresClientComposition()).WillOnce(Return(false)); |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 5156 | EXPECT_CALL(*mLayers[2].mLayerFE, prepareClientComposition(Eq(ByRef(layer2Settings)))) |
| 5157 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>(mShadowSettings))); |
Vishnu Nair | a483b4a | 2019-12-12 15:07:52 -0800 | [diff] [blame] | 5158 | |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 5159 | auto requests = |
| 5160 | mOutput.generateClientCompositionRequestsHelper(false /* supportsProtectedContent */, |
| 5161 | kDisplayDataspace); |
Vishnu Nair | a483b4a | 2019-12-12 15:07:52 -0800 | [diff] [blame] | 5162 | ASSERT_EQ(1u, requests.size()); |
| 5163 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 5164 | EXPECT_EQ(mShadowSettings, requests[0]); |
Vishnu Nair | a483b4a | 2019-12-12 15:07:52 -0800 | [diff] [blame] | 5165 | } |
| 5166 | |
| 5167 | TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers, |
| 5168 | shadowRegionWithContentVisibleRequestsContentAndShadowComposition) { |
| 5169 | const Rect kContentWithShadow(40, 40, 70, 90); |
| 5170 | const Rect kContent(50, 50, 60, 80); |
| 5171 | const Region kShadowRegion = Region(kContentWithShadow).subtract(kContent); |
| 5172 | const Region kPartialContentWithPartialShadowRegion = |
| 5173 | Region(kContentWithShadow).subtract(Rect(40, 40, 50, 80)); |
| 5174 | |
Vishnu Nair | a483b4a | 2019-12-12 15:07:52 -0800 | [diff] [blame] | 5175 | mLayers[2].mOutputLayerState.visibleRegion = kPartialContentWithPartialShadowRegion; |
| 5176 | mLayers[2].mOutputLayerState.shadowRegion = kShadowRegion; |
| 5177 | |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 5178 | compositionengine::LayerFE::ClientCompositionTargetSettings layer2Settings{ |
| 5179 | 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] | 5180 | false, /* needs filtering */ |
| 5181 | false, /* secure */ |
| 5182 | false, /* supports protected content */ |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 5183 | kDisplayViewport, |
| 5184 | kDisplayDataspace, |
| 5185 | true /* realContentIsVisible */, |
| 5186 | false /* clearContent */, |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 5187 | compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled, |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 5188 | kLayerWhitePointNits, |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 5189 | false /* treat170mAsSrgb */, |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 5190 | }; |
| 5191 | |
Vishnu Nair | a483b4a | 2019-12-12 15:07:52 -0800 | [diff] [blame] | 5192 | EXPECT_CALL(mLayers[0].mOutputLayer, requiresClientComposition()).WillOnce(Return(false)); |
| 5193 | EXPECT_CALL(mLayers[1].mOutputLayer, requiresClientComposition()).WillOnce(Return(false)); |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 5194 | EXPECT_CALL(*mLayers[2].mLayerFE, prepareClientComposition(Eq(ByRef(layer2Settings)))) |
| 5195 | .WillOnce(Return(std::optional<LayerFE::LayerSettings>(mLayers[2].mLayerSettings))); |
Vishnu Nair | a483b4a | 2019-12-12 15:07:52 -0800 | [diff] [blame] | 5196 | |
Carlos Martinez Romero | e5d57ea | 2022-11-15 19:14:36 +0000 | [diff] [blame] | 5197 | auto requests = |
| 5198 | mOutput.generateClientCompositionRequestsHelper(false /* supportsProtectedContent */, |
| 5199 | kDisplayDataspace); |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 5200 | ASSERT_EQ(1u, requests.size()); |
Vishnu Nair | a483b4a | 2019-12-12 15:07:52 -0800 | [diff] [blame] | 5201 | |
Patrick Williams | 16d8b2c | 2022-08-08 17:29:05 +0000 | [diff] [blame] | 5202 | EXPECT_EQ(mLayers[2].mLayerSettings, requests[0]); |
Vishnu Nair | a483b4a | 2019-12-12 15:07:52 -0800 | [diff] [blame] | 5203 | } |
| 5204 | |
Leon Scroggins III | 2f60d73 | 2022-09-12 14:42:38 -0400 | [diff] [blame] | 5205 | struct OutputPresentFrameAndReleaseLayersAsyncTest : public ::testing::Test { |
| 5206 | // Piggy-back on OutputPrepareFrameAsyncTest's version to avoid some boilerplate. |
| 5207 | struct OutputPartialMock : public OutputPrepareFrameAsyncTest::OutputPartialMock { |
| 5208 | // Set up the helper functions called by the function under test to use |
| 5209 | // mock implementations. |
Leon Scroggins III | a3ba7fa | 2024-05-22 16:34:52 -0400 | [diff] [blame] | 5210 | MOCK_METHOD(void, presentFrameAndReleaseLayers, (bool flushEvenWhenDisabled)); |
| 5211 | MOCK_METHOD(ftl::Future<std::monostate>, presentFrameAndReleaseLayersAsync, |
| 5212 | (bool flushEvenWhenDisabled)); |
Leon Scroggins III | 2f60d73 | 2022-09-12 14:42:38 -0400 | [diff] [blame] | 5213 | }; |
| 5214 | OutputPresentFrameAndReleaseLayersAsyncTest() { |
| 5215 | mOutput->setDisplayColorProfileForTest( |
| 5216 | std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile)); |
| 5217 | mOutput->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface)); |
| 5218 | mOutput->setCompositionEnabled(true); |
| 5219 | mRefreshArgs.outputs = {mOutput}; |
| 5220 | } |
| 5221 | |
| 5222 | mock::DisplayColorProfile* mDisplayColorProfile = new NiceMock<mock::DisplayColorProfile>(); |
| 5223 | mock::RenderSurface* mRenderSurface = new NiceMock<mock::RenderSurface>(); |
| 5224 | std::shared_ptr<OutputPartialMock> mOutput{std::make_shared<NiceMock<OutputPartialMock>>()}; |
| 5225 | CompositionRefreshArgs mRefreshArgs; |
| 5226 | }; |
| 5227 | |
| 5228 | TEST_F(OutputPresentFrameAndReleaseLayersAsyncTest, notCalledWhenNotRequested) { |
Leon Scroggins III | a3ba7fa | 2024-05-22 16:34:52 -0400 | [diff] [blame] | 5229 | EXPECT_CALL(*mOutput, presentFrameAndReleaseLayersAsync(_)).Times(0); |
| 5230 | EXPECT_CALL(*mOutput, presentFrameAndReleaseLayers(_)).Times(1); |
Leon Scroggins III | 2f60d73 | 2022-09-12 14:42:38 -0400 | [diff] [blame] | 5231 | |
| 5232 | mOutput->present(mRefreshArgs); |
| 5233 | } |
| 5234 | |
| 5235 | TEST_F(OutputPresentFrameAndReleaseLayersAsyncTest, calledWhenRequested) { |
Leon Scroggins III | a3ba7fa | 2024-05-22 16:34:52 -0400 | [diff] [blame] | 5236 | EXPECT_CALL(*mOutput, presentFrameAndReleaseLayersAsync(false)) |
Leon Scroggins III | 2f60d73 | 2022-09-12 14:42:38 -0400 | [diff] [blame] | 5237 | .WillOnce(Return(ftl::yield<std::monostate>({}))); |
Leon Scroggins III | a3ba7fa | 2024-05-22 16:34:52 -0400 | [diff] [blame] | 5238 | EXPECT_CALL(*mOutput, presentFrameAndReleaseLayers(_)).Times(0); |
Leon Scroggins III | 2f60d73 | 2022-09-12 14:42:38 -0400 | [diff] [blame] | 5239 | |
| 5240 | mOutput->offloadPresentNextFrame(); |
| 5241 | mOutput->present(mRefreshArgs); |
| 5242 | } |
| 5243 | |
| 5244 | TEST_F(OutputPresentFrameAndReleaseLayersAsyncTest, calledForOneFrame) { |
| 5245 | ::testing::InSequence inseq; |
Leon Scroggins III | a3ba7fa | 2024-05-22 16:34:52 -0400 | [diff] [blame] | 5246 | constexpr bool kFlushEvenWhenDisabled = false; |
| 5247 | EXPECT_CALL(*mOutput, presentFrameAndReleaseLayersAsync(kFlushEvenWhenDisabled)) |
Leon Scroggins III | 2f60d73 | 2022-09-12 14:42:38 -0400 | [diff] [blame] | 5248 | .WillOnce(Return(ftl::yield<std::monostate>({}))); |
Leon Scroggins III | a3ba7fa | 2024-05-22 16:34:52 -0400 | [diff] [blame] | 5249 | EXPECT_CALL(*mOutput, presentFrameAndReleaseLayers(kFlushEvenWhenDisabled)).Times(1); |
Leon Scroggins III | 2f60d73 | 2022-09-12 14:42:38 -0400 | [diff] [blame] | 5250 | |
| 5251 | mOutput->offloadPresentNextFrame(); |
| 5252 | mOutput->present(mRefreshArgs); |
| 5253 | mOutput->present(mRefreshArgs); |
| 5254 | } |
| 5255 | |
Eason Chiu | 4509966 | 2023-10-23 08:55:48 +0800 | [diff] [blame] | 5256 | /* |
| 5257 | * Output::updateProtectedContentState() |
| 5258 | */ |
| 5259 | |
| 5260 | struct OutputUpdateProtectedContentStateTest : public testing::Test { |
| 5261 | struct OutputPartialMock : public OutputPartialMockBase { |
| 5262 | // Sets up the helper functions called by the function under test to use |
| 5263 | // mock implementations. |
| 5264 | MOCK_CONST_METHOD0(getCompositionEngine, const CompositionEngine&()); |
| 5265 | }; |
| 5266 | |
| 5267 | OutputUpdateProtectedContentStateTest() { |
| 5268 | mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface)); |
| 5269 | EXPECT_CALL(mOutput, getCompositionEngine()).WillRepeatedly(ReturnRef(mCompositionEngine)); |
| 5270 | EXPECT_CALL(mCompositionEngine, getRenderEngine()).WillRepeatedly(ReturnRef(mRenderEngine)); |
| 5271 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(2u)); |
| 5272 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0)) |
| 5273 | .WillRepeatedly(Return(&mLayer1.mOutputLayer)); |
| 5274 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(1)) |
| 5275 | .WillRepeatedly(Return(&mLayer2.mOutputLayer)); |
| 5276 | } |
| 5277 | |
| 5278 | struct Layer { |
| 5279 | Layer() { |
| 5280 | EXPECT_CALL(*mLayerFE, getCompositionState()).WillRepeatedly(Return(&mLayerFEState)); |
| 5281 | EXPECT_CALL(mOutputLayer, getLayerFE()).WillRepeatedly(ReturnRef(*mLayerFE)); |
| 5282 | } |
| 5283 | |
| 5284 | StrictMock<mock::OutputLayer> mOutputLayer; |
| 5285 | sp<StrictMock<mock::LayerFE>> mLayerFE = sp<StrictMock<mock::LayerFE>>::make(); |
| 5286 | LayerFECompositionState mLayerFEState; |
| 5287 | }; |
| 5288 | |
| 5289 | mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>(); |
| 5290 | StrictMock<OutputPartialMock> mOutput; |
| 5291 | StrictMock<mock::CompositionEngine> mCompositionEngine; |
| 5292 | StrictMock<renderengine::mock::RenderEngine> mRenderEngine; |
| 5293 | Layer mLayer1; |
| 5294 | Layer mLayer2; |
| 5295 | }; |
| 5296 | |
| 5297 | TEST_F(OutputUpdateProtectedContentStateTest, ifProtectedContentLayerComposeByHWC) { |
| 5298 | SET_FLAG_FOR_TEST(flags::protected_if_client, true); |
| 5299 | if (FlagManager::getInstance().display_protected()) { |
| 5300 | mOutput.mState.isProtected = true; |
| 5301 | } else { |
| 5302 | mOutput.mState.isSecure = true; |
| 5303 | } |
| 5304 | mLayer1.mLayerFEState.hasProtectedContent = false; |
| 5305 | mLayer2.mLayerFEState.hasProtectedContent = true; |
| 5306 | EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(true)); |
| 5307 | EXPECT_CALL(*mRenderSurface, isProtected).WillOnce(Return(false)); |
| 5308 | EXPECT_CALL(mLayer1.mOutputLayer, requiresClientComposition()).WillRepeatedly(Return(true)); |
| 5309 | EXPECT_CALL(mLayer2.mOutputLayer, requiresClientComposition()).WillRepeatedly(Return(false)); |
| 5310 | mOutput.updateProtectedContentState(); |
| 5311 | } |
| 5312 | |
| 5313 | TEST_F(OutputUpdateProtectedContentStateTest, ifProtectedContentLayerComposeByClient) { |
| 5314 | SET_FLAG_FOR_TEST(flags::protected_if_client, true); |
| 5315 | if (FlagManager::getInstance().display_protected()) { |
| 5316 | mOutput.mState.isProtected = true; |
| 5317 | } else { |
| 5318 | mOutput.mState.isSecure = true; |
| 5319 | } |
| 5320 | mLayer1.mLayerFEState.hasProtectedContent = false; |
| 5321 | mLayer2.mLayerFEState.hasProtectedContent = true; |
| 5322 | EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(true)); |
| 5323 | EXPECT_CALL(*mRenderSurface, isProtected).WillOnce(Return(false)); |
| 5324 | EXPECT_CALL(*mRenderSurface, setProtected(true)); |
| 5325 | EXPECT_CALL(mLayer1.mOutputLayer, requiresClientComposition()).WillRepeatedly(Return(true)); |
| 5326 | EXPECT_CALL(mLayer2.mOutputLayer, requiresClientComposition()).WillRepeatedly(Return(true)); |
| 5327 | mOutput.updateProtectedContentState(); |
| 5328 | } |
| 5329 | |
Leon Scroggins III | a3ba7fa | 2024-05-22 16:34:52 -0400 | [diff] [blame] | 5330 | struct OutputPresentFrameAndReleaseLayersTest : public testing::Test { |
| 5331 | struct OutputPartialMock : public OutputPartialMockBase { |
| 5332 | // Sets up the helper functions called by the function under test (and functions we can |
| 5333 | // ignore) to use mock implementations. |
| 5334 | MOCK_METHOD1(updateColorProfile, void(const compositionengine::CompositionRefreshArgs&)); |
| 5335 | MOCK_METHOD1(updateCompositionState, |
| 5336 | void(const compositionengine::CompositionRefreshArgs&)); |
| 5337 | MOCK_METHOD0(planComposition, void()); |
| 5338 | MOCK_METHOD1(writeCompositionState, void(const compositionengine::CompositionRefreshArgs&)); |
| 5339 | MOCK_METHOD1(setColorTransform, void(const compositionengine::CompositionRefreshArgs&)); |
| 5340 | MOCK_METHOD0(beginFrame, void()); |
| 5341 | MOCK_METHOD0(prepareFrame, void()); |
| 5342 | MOCK_METHOD0(prepareFrameAsync, GpuCompositionResult()); |
| 5343 | MOCK_METHOD1(devOptRepaintFlash, void(const compositionengine::CompositionRefreshArgs&)); |
| 5344 | MOCK_METHOD1(finishFrame, void(GpuCompositionResult&&)); |
| 5345 | MOCK_METHOD(void, presentFrameAndReleaseLayers, (bool flushEvenWhenDisabled), (override)); |
| 5346 | MOCK_METHOD1(renderCachedSets, void(const compositionengine::CompositionRefreshArgs&)); |
| 5347 | MOCK_METHOD1(canPredictCompositionStrategy, bool(const CompositionRefreshArgs&)); |
| 5348 | MOCK_METHOD(void, setHintSessionRequiresRenderEngine, (bool requiresRenderEngine), |
| 5349 | (override)); |
| 5350 | MOCK_METHOD(bool, isPowerHintSessionEnabled, (), (override)); |
| 5351 | MOCK_METHOD(bool, isPowerHintSessionGpuReportingEnabled, (), (override)); |
| 5352 | }; |
| 5353 | |
| 5354 | OutputPresentFrameAndReleaseLayersTest() { |
| 5355 | EXPECT_CALL(mOutput, isPowerHintSessionEnabled()).WillRepeatedly(Return(true)); |
| 5356 | EXPECT_CALL(mOutput, isPowerHintSessionGpuReportingEnabled()).WillRepeatedly(Return(true)); |
| 5357 | } |
| 5358 | |
| 5359 | NiceMock<OutputPartialMock> mOutput; |
| 5360 | }; |
| 5361 | |
| 5362 | TEST_F(OutputPresentFrameAndReleaseLayersTest, noBuffersToUncache) { |
| 5363 | CompositionRefreshArgs args; |
| 5364 | ASSERT_TRUE(args.bufferIdsToUncache.empty()); |
| 5365 | mOutput.editState().isEnabled = false; |
| 5366 | |
| 5367 | constexpr bool kFlushEvenWhenDisabled = false; |
| 5368 | EXPECT_CALL(mOutput, presentFrameAndReleaseLayers(kFlushEvenWhenDisabled)); |
| 5369 | |
| 5370 | mOutput.present(args); |
| 5371 | } |
| 5372 | |
| 5373 | TEST_F(OutputPresentFrameAndReleaseLayersTest, buffersToUncache) { |
| 5374 | CompositionRefreshArgs args; |
| 5375 | args.bufferIdsToUncache.push_back(1); |
| 5376 | mOutput.editState().isEnabled = false; |
| 5377 | |
| 5378 | constexpr bool kFlushEvenWhenDisabled = true; |
| 5379 | EXPECT_CALL(mOutput, presentFrameAndReleaseLayers(kFlushEvenWhenDisabled)); |
| 5380 | |
| 5381 | mOutput.present(args); |
| 5382 | } |
| 5383 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 5384 | } // namespace |
| 5385 | } // namespace android::compositionengine |