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