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