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 | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 19 | #include <compositionengine/LayerFECompositionState.h> |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 20 | #include <compositionengine/impl/Output.h> |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 21 | #include <compositionengine/impl/OutputCompositionState.h> |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 22 | #include <compositionengine/impl/OutputLayerCompositionState.h> |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 23 | #include <compositionengine/mock/CompositionEngine.h> |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 24 | #include <compositionengine/mock/DisplayColorProfile.h> |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 25 | #include <compositionengine/mock/Layer.h> |
| 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 | |
| 34 | #include "RegionMatcher.h" |
| 35 | #include "TransformMatcher.h" |
| 36 | |
| 37 | namespace android::compositionengine { |
| 38 | namespace { |
| 39 | |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 40 | using testing::_; |
Lloyd Pique | 03561a6 | 2019-11-19 18:34:52 -0800 | [diff] [blame] | 41 | using testing::ByMove; |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 42 | using testing::InSequence; |
| 43 | using testing::Ref; |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 44 | using testing::Return; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 45 | using testing::ReturnRef; |
| 46 | using testing::StrictMock; |
| 47 | |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 48 | constexpr auto TR_IDENT = 0u; |
| 49 | constexpr auto TR_ROT_90 = HAL_TRANSFORM_ROT_90; |
| 50 | |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 51 | const mat4 kIdentity; |
| 52 | const mat4 kNonIdentityHalf = mat4() * 0.5; |
| 53 | const mat4 kNonIdentityQuarter = mat4() * 0.25; |
| 54 | |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 55 | struct OutputPartialMockBase : public impl::Output { |
| 56 | // compositionengine::Output overrides |
| 57 | const OutputCompositionState& getState() const override { return mState; } |
| 58 | OutputCompositionState& editState() override { return mState; } |
| 59 | |
| 60 | // Use mocks for all the remaining virtual functions |
| 61 | // not implemented by the base implementation class. |
| 62 | MOCK_CONST_METHOD0(getOutputLayerCount, size_t()); |
| 63 | MOCK_CONST_METHOD1(getOutputLayerOrderedByZByIndex, compositionengine::OutputLayer*(size_t)); |
| 64 | MOCK_METHOD3(ensureOutputLayer, |
| 65 | compositionengine::OutputLayer*(std::optional<size_t>, |
| 66 | const std::shared_ptr<compositionengine::Layer>&, |
| 67 | const sp<LayerFE>&)); |
| 68 | MOCK_METHOD0(finalizePendingOutputLayers, void()); |
| 69 | MOCK_METHOD0(clearOutputLayers, void()); |
| 70 | MOCK_CONST_METHOD1(dumpState, void(std::string&)); |
| 71 | MOCK_CONST_METHOD0(getCompositionEngine, const CompositionEngine&()); |
| 72 | MOCK_METHOD2(injectOutputLayerForTest, |
| 73 | compositionengine::OutputLayer*(const std::shared_ptr<compositionengine::Layer>&, |
| 74 | const sp<LayerFE>&)); |
| 75 | MOCK_METHOD1(injectOutputLayerForTest, void(std::unique_ptr<OutputLayer>)); |
| 76 | |
| 77 | impl::OutputCompositionState mState; |
| 78 | }; |
| 79 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 80 | struct OutputTest : public testing::Test { |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 81 | class Output : public impl::Output { |
| 82 | public: |
| 83 | using impl::Output::injectOutputLayerForTest; |
| 84 | virtual void injectOutputLayerForTest(std::unique_ptr<compositionengine::OutputLayer>) = 0; |
| 85 | }; |
| 86 | |
| 87 | static std::shared_ptr<Output> createOutput( |
| 88 | const compositionengine::CompositionEngine& compositionEngine) { |
| 89 | return impl::createOutputTemplated<Output>(compositionEngine); |
| 90 | } |
| 91 | |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 92 | OutputTest() { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 93 | mOutput->setDisplayColorProfileForTest( |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 94 | std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile)); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 95 | mOutput->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface)); |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 96 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 97 | mOutput->editState().bounds = kDefaultDisplaySize; |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 98 | } |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 99 | |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 100 | static const Rect kDefaultDisplaySize; |
| 101 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 102 | StrictMock<mock::CompositionEngine> mCompositionEngine; |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 103 | mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>(); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 104 | mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>(); |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 105 | std::shared_ptr<Output> mOutput = createOutput(mCompositionEngine); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 106 | }; |
| 107 | |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 108 | const Rect OutputTest::kDefaultDisplaySize{100, 200}; |
| 109 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 110 | /* |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 111 | * Basic construction |
| 112 | */ |
| 113 | |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 114 | TEST_F(OutputTest, canInstantiateOutput) { |
| 115 | // The validation check checks each required component. |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 116 | EXPECT_CALL(*mDisplayColorProfile, isValid()).WillOnce(Return(true)); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 117 | EXPECT_CALL(*mRenderSurface, isValid()).WillOnce(Return(true)); |
| 118 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 119 | EXPECT_TRUE(mOutput->isValid()); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 120 | |
| 121 | // If we take away the required components, it is no longer valid. |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 122 | mOutput->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>()); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 123 | |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 124 | EXPECT_CALL(*mDisplayColorProfile, isValid()).WillOnce(Return(true)); |
| 125 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 126 | EXPECT_FALSE(mOutput->isValid()); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 127 | } |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 128 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 129 | /* |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 130 | * Output::setCompositionEnabled() |
| 131 | */ |
| 132 | |
| 133 | TEST_F(OutputTest, setCompositionEnabledDoesNothingIfAlreadyEnabled) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 134 | mOutput->editState().isEnabled = true; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 135 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 136 | mOutput->setCompositionEnabled(true); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 137 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 138 | EXPECT_TRUE(mOutput->getState().isEnabled); |
| 139 | EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region())); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | TEST_F(OutputTest, setCompositionEnabledSetsEnabledAndDirtiesEntireOutput) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 143 | mOutput->editState().isEnabled = false; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 144 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 145 | mOutput->setCompositionEnabled(true); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 146 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 147 | EXPECT_TRUE(mOutput->getState().isEnabled); |
| 148 | EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize))); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | TEST_F(OutputTest, setCompositionEnabledSetsDisabledAndDirtiesEntireOutput) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 152 | mOutput->editState().isEnabled = true; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 153 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 154 | mOutput->setCompositionEnabled(false); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 155 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 156 | EXPECT_FALSE(mOutput->getState().isEnabled); |
| 157 | EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize))); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 158 | } |
| 159 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 160 | /* |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 161 | * Output::setProjection() |
| 162 | */ |
| 163 | |
| 164 | TEST_F(OutputTest, setProjectionTriviallyWorks) { |
| 165 | const ui::Transform transform{ui::Transform::ROT_180}; |
| 166 | const int32_t orientation = 123; |
| 167 | const Rect frame{1, 2, 3, 4}; |
| 168 | const Rect viewport{5, 6, 7, 8}; |
| 169 | const Rect scissor{9, 10, 11, 12}; |
| 170 | const bool needsFiltering = true; |
| 171 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 172 | mOutput->setProjection(transform, orientation, frame, viewport, scissor, needsFiltering); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 173 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 174 | EXPECT_THAT(mOutput->getState().transform, TransformEq(transform)); |
| 175 | EXPECT_EQ(orientation, mOutput->getState().orientation); |
| 176 | EXPECT_EQ(frame, mOutput->getState().frame); |
| 177 | EXPECT_EQ(viewport, mOutput->getState().viewport); |
| 178 | EXPECT_EQ(scissor, mOutput->getState().scissor); |
| 179 | EXPECT_EQ(needsFiltering, mOutput->getState().needsFiltering); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 180 | } |
| 181 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 182 | /* |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 183 | * Output::setBounds() |
| 184 | */ |
| 185 | |
| 186 | TEST_F(OutputTest, setBoundsSetsSizeAndDirtiesEntireOutput) { |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 187 | const ui::Size displaySize{200, 400}; |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 188 | |
| 189 | EXPECT_CALL(*mRenderSurface, setDisplaySize(displaySize)).Times(1); |
| 190 | EXPECT_CALL(*mRenderSurface, getSize()).WillOnce(ReturnRef(displaySize)); |
| 191 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 192 | mOutput->setBounds(displaySize); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 193 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 194 | EXPECT_EQ(Rect(displaySize), mOutput->getState().bounds); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 195 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 196 | EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(Rect(displaySize)))); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 197 | } |
| 198 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 199 | /* |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 200 | * Output::setLayerStackFilter() |
| 201 | */ |
| 202 | |
| 203 | TEST_F(OutputTest, setLayerStackFilterSetsFilterAndDirtiesEntireOutput) { |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 204 | const uint32_t layerStack = 123u; |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 205 | mOutput->setLayerStackFilter(layerStack, true); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 206 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 207 | EXPECT_TRUE(mOutput->getState().layerStackInternal); |
| 208 | EXPECT_EQ(layerStack, mOutput->getState().layerStackId); |
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 | EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize))); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 211 | } |
| 212 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 213 | /* |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 214 | * Output::setColorTransform |
| 215 | */ |
| 216 | |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 217 | TEST_F(OutputTest, setColorTransformWithNoChangeFlaggedSkipsUpdates) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 218 | mOutput->editState().colorTransformMatrix = kIdentity; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 219 | |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 220 | // If no colorTransformMatrix is set the update should be skipped. |
| 221 | CompositionRefreshArgs refreshArgs; |
| 222 | refreshArgs.colorTransformMatrix = std::nullopt; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 223 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 224 | mOutput->setColorTransform(refreshArgs); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 225 | |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 226 | // The internal state should be unchanged |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 227 | EXPECT_EQ(kIdentity, mOutput->getState().colorTransformMatrix); |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 228 | |
| 229 | // No dirty region should be set |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 230 | EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region())); |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 231 | } |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 232 | |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 233 | TEST_F(OutputTest, setColorTransformWithNoActualChangeSkipsUpdates) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 234 | mOutput->editState().colorTransformMatrix = kIdentity; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 235 | |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 236 | // Attempting to set the same colorTransformMatrix that is already set should |
| 237 | // also skip the update. |
| 238 | CompositionRefreshArgs refreshArgs; |
| 239 | refreshArgs.colorTransformMatrix = kIdentity; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 240 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 241 | mOutput->setColorTransform(refreshArgs); |
Lloyd Pique | 77f79a2 | 2019-04-29 15:55:40 -0700 | [diff] [blame] | 242 | |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 243 | // The internal state should be unchanged |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 244 | EXPECT_EQ(kIdentity, mOutput->getState().colorTransformMatrix); |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 245 | |
| 246 | // No dirty region should be set |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 247 | EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region())); |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | TEST_F(OutputTest, setColorTransformPerformsUpdateToIdentity) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 251 | mOutput->editState().colorTransformMatrix = kNonIdentityHalf; |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 252 | |
| 253 | // Setting a different colorTransformMatrix should perform the update. |
| 254 | CompositionRefreshArgs refreshArgs; |
| 255 | refreshArgs.colorTransformMatrix = kIdentity; |
| 256 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 257 | mOutput->setColorTransform(refreshArgs); |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 258 | |
| 259 | // The internal state should have been updated |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 260 | EXPECT_EQ(kIdentity, mOutput->getState().colorTransformMatrix); |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 261 | |
| 262 | // The dirtyRegion should be set to the full display size |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 263 | EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize))); |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 264 | } |
Lloyd Pique | 77f79a2 | 2019-04-29 15:55:40 -0700 | [diff] [blame] | 265 | |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 266 | TEST_F(OutputTest, setColorTransformPerformsUpdateForIdentityToHalf) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 267 | mOutput->editState().colorTransformMatrix = kIdentity; |
Lloyd Pique | 77f79a2 | 2019-04-29 15:55:40 -0700 | [diff] [blame] | 268 | |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 269 | // Setting a different colorTransformMatrix should perform the update. |
| 270 | CompositionRefreshArgs refreshArgs; |
| 271 | refreshArgs.colorTransformMatrix = kNonIdentityHalf; |
Lloyd Pique | 77f79a2 | 2019-04-29 15:55:40 -0700 | [diff] [blame] | 272 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 273 | mOutput->setColorTransform(refreshArgs); |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 274 | |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 275 | // The internal state should have been updated |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 276 | EXPECT_EQ(kNonIdentityHalf, mOutput->getState().colorTransformMatrix); |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 277 | |
| 278 | // The dirtyRegion should be set to the full display size |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 279 | EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize))); |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | TEST_F(OutputTest, setColorTransformPerformsUpdateForHalfToQuarter) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 283 | mOutput->editState().colorTransformMatrix = kNonIdentityHalf; |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 284 | |
| 285 | // Setting a different colorTransformMatrix should perform the update. |
| 286 | CompositionRefreshArgs refreshArgs; |
| 287 | refreshArgs.colorTransformMatrix = kNonIdentityQuarter; |
| 288 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 289 | mOutput->setColorTransform(refreshArgs); |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 290 | |
| 291 | // The internal state should have been updated |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 292 | EXPECT_EQ(kNonIdentityQuarter, mOutput->getState().colorTransformMatrix); |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 293 | |
| 294 | // The dirtyRegion should be set to the full display size |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 295 | EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize))); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 296 | } |
| 297 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 298 | /* |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 299 | * Output::setColorMode |
| 300 | */ |
| 301 | |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 302 | TEST_F(OutputTest, setColorModeSetsStateAndDirtiesOutputIfChanged) { |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 303 | using ColorProfile = Output::ColorProfile; |
| 304 | |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 305 | EXPECT_CALL(*mDisplayColorProfile, |
| 306 | getTargetDataspace(ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3, |
| 307 | ui::Dataspace::UNKNOWN)) |
| 308 | .WillOnce(Return(ui::Dataspace::UNKNOWN)); |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 309 | EXPECT_CALL(*mRenderSurface, setBufferDataspace(ui::Dataspace::DISPLAY_P3)).Times(1); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 310 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 311 | mOutput->setColorProfile(ColorProfile{ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3, |
| 312 | ui::RenderIntent::TONE_MAP_COLORIMETRIC, |
| 313 | ui::Dataspace::UNKNOWN}); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 314 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 315 | EXPECT_EQ(ui::ColorMode::DISPLAY_P3, mOutput->getState().colorMode); |
| 316 | EXPECT_EQ(ui::Dataspace::DISPLAY_P3, mOutput->getState().dataspace); |
| 317 | EXPECT_EQ(ui::RenderIntent::TONE_MAP_COLORIMETRIC, mOutput->getState().renderIntent); |
| 318 | EXPECT_EQ(ui::Dataspace::UNKNOWN, mOutput->getState().targetDataspace); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 319 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 320 | EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize))); |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | TEST_F(OutputTest, setColorModeDoesNothingIfNoChange) { |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [diff] [blame] | 324 | using ColorProfile = Output::ColorProfile; |
| 325 | |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 326 | EXPECT_CALL(*mDisplayColorProfile, |
| 327 | getTargetDataspace(ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3, |
| 328 | ui::Dataspace::UNKNOWN)) |
| 329 | .WillOnce(Return(ui::Dataspace::UNKNOWN)); |
| 330 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 331 | mOutput->editState().colorMode = ui::ColorMode::DISPLAY_P3; |
| 332 | mOutput->editState().dataspace = ui::Dataspace::DISPLAY_P3; |
| 333 | mOutput->editState().renderIntent = ui::RenderIntent::TONE_MAP_COLORIMETRIC; |
| 334 | mOutput->editState().targetDataspace = ui::Dataspace::UNKNOWN; |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 335 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 336 | mOutput->setColorProfile(ColorProfile{ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3, |
| 337 | ui::RenderIntent::TONE_MAP_COLORIMETRIC, |
| 338 | ui::Dataspace::UNKNOWN}); |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 339 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 340 | EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region())); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 341 | } |
| 342 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 343 | /* |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 344 | * Output::setRenderSurface() |
| 345 | */ |
| 346 | |
| 347 | TEST_F(OutputTest, setRenderSurfaceResetsBounds) { |
| 348 | const ui::Size newDisplaySize{640, 480}; |
| 349 | |
| 350 | mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>(); |
| 351 | EXPECT_CALL(*renderSurface, getSize()).WillOnce(ReturnRef(newDisplaySize)); |
| 352 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 353 | mOutput->setRenderSurface(std::unique_ptr<RenderSurface>(renderSurface)); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 354 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 355 | EXPECT_EQ(Rect(newDisplaySize), mOutput->getState().bounds); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 356 | } |
| 357 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 358 | /* |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 359 | * Output::getDirtyRegion() |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 360 | */ |
| 361 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 362 | TEST_F(OutputTest, getDirtyRegionWithRepaintEverythingTrue) { |
| 363 | const Rect viewport{100, 200}; |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 364 | mOutput->editState().viewport = viewport; |
| 365 | mOutput->editState().dirtyRegion.set(50, 300); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 366 | |
| 367 | { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 368 | Region result = mOutput->getDirtyRegion(true); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 369 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 370 | EXPECT_THAT(result, RegionEq(Region(viewport))); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 371 | } |
| 372 | } |
| 373 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 374 | TEST_F(OutputTest, getDirtyRegionWithRepaintEverythingFalse) { |
| 375 | const Rect viewport{100, 200}; |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 376 | mOutput->editState().viewport = viewport; |
| 377 | mOutput->editState().dirtyRegion.set(50, 300); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 378 | |
| 379 | { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 380 | Region result = mOutput->getDirtyRegion(false); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 381 | |
| 382 | // The dirtyRegion should be clipped to the display bounds. |
| 383 | EXPECT_THAT(result, RegionEq(Region(Rect(50, 200)))); |
| 384 | } |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 385 | } |
| 386 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 387 | /* |
Lloyd Pique | ef36b00 | 2019-01-23 17:52:04 -0800 | [diff] [blame] | 388 | * Output::belongsInOutput() |
| 389 | */ |
| 390 | |
| 391 | TEST_F(OutputTest, belongsInOutputFiltersAsExpected) { |
| 392 | const uint32_t layerStack1 = 123u; |
| 393 | const uint32_t layerStack2 = 456u; |
| 394 | |
| 395 | // If the output accepts layerStack1 and internal-only layers.... |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 396 | mOutput->setLayerStackFilter(layerStack1, true); |
Lloyd Pique | ef36b00 | 2019-01-23 17:52:04 -0800 | [diff] [blame] | 397 | |
Lloyd Pique | c668734 | 2019-03-07 21:34:57 -0800 | [diff] [blame] | 398 | // 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] | 399 | EXPECT_FALSE(mOutput->belongsInOutput(std::nullopt, false)); |
| 400 | EXPECT_FALSE(mOutput->belongsInOutput(std::nullopt, true)); |
Lloyd Pique | c668734 | 2019-03-07 21:34:57 -0800 | [diff] [blame] | 401 | |
Lloyd Pique | ef36b00 | 2019-01-23 17:52:04 -0800 | [diff] [blame] | 402 | // Any layer with layerStack1 belongs to it, internal-only or not. |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 403 | EXPECT_TRUE(mOutput->belongsInOutput(layerStack1, false)); |
| 404 | EXPECT_TRUE(mOutput->belongsInOutput(layerStack1, true)); |
| 405 | EXPECT_FALSE(mOutput->belongsInOutput(layerStack2, true)); |
| 406 | EXPECT_FALSE(mOutput->belongsInOutput(layerStack2, false)); |
Lloyd Pique | ef36b00 | 2019-01-23 17:52:04 -0800 | [diff] [blame] | 407 | |
| 408 | // If the output accepts layerStack21 but not internal-only layers... |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 409 | mOutput->setLayerStackFilter(layerStack1, false); |
Lloyd Pique | ef36b00 | 2019-01-23 17:52:04 -0800 | [diff] [blame] | 410 | |
| 411 | // Only non-internal layers with layerStack1 belong to it. |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 412 | EXPECT_TRUE(mOutput->belongsInOutput(layerStack1, false)); |
| 413 | EXPECT_FALSE(mOutput->belongsInOutput(layerStack1, true)); |
| 414 | EXPECT_FALSE(mOutput->belongsInOutput(layerStack2, true)); |
| 415 | EXPECT_FALSE(mOutput->belongsInOutput(layerStack2, false)); |
Lloyd Pique | ef36b00 | 2019-01-23 17:52:04 -0800 | [diff] [blame] | 416 | } |
| 417 | |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 418 | TEST_F(OutputTest, belongsInOutputFiltersLayersAsExpected) { |
| 419 | StrictMock<mock::Layer> layer; |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 420 | LayerFECompositionState layerFEState; |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 421 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 422 | EXPECT_CALL(layer, getFEState()).WillRepeatedly(ReturnRef(layerFEState)); |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 423 | |
| 424 | const uint32_t layerStack1 = 123u; |
| 425 | const uint32_t layerStack2 = 456u; |
| 426 | |
| 427 | // If the output accepts layerStack1 and internal-only layers.... |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 428 | mOutput->setLayerStackFilter(layerStack1, true); |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 429 | |
| 430 | // A null layer pointer does not belong to the output |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 431 | EXPECT_FALSE(mOutput->belongsInOutput(nullptr)); |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 432 | |
| 433 | // A layer with no layerStack does not belong to it, internal-only or not. |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 434 | layerFEState.layerStackId = std::nullopt; |
| 435 | layerFEState.internalOnly = false; |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 436 | EXPECT_FALSE(mOutput->belongsInOutput(&layer)); |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 437 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 438 | layerFEState.layerStackId = std::nullopt; |
| 439 | layerFEState.internalOnly = true; |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 440 | EXPECT_FALSE(mOutput->belongsInOutput(&layer)); |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 441 | |
| 442 | // Any layer with layerStack1 belongs to it, internal-only or not. |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 443 | layerFEState.layerStackId = layerStack1; |
| 444 | layerFEState.internalOnly = false; |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 445 | EXPECT_TRUE(mOutput->belongsInOutput(&layer)); |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 446 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 447 | layerFEState.layerStackId = layerStack1; |
| 448 | layerFEState.internalOnly = true; |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 449 | EXPECT_TRUE(mOutput->belongsInOutput(&layer)); |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 450 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 451 | layerFEState.layerStackId = layerStack2; |
| 452 | layerFEState.internalOnly = true; |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 453 | EXPECT_FALSE(mOutput->belongsInOutput(&layer)); |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 454 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 455 | layerFEState.layerStackId = layerStack2; |
| 456 | layerFEState.internalOnly = false; |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 457 | EXPECT_FALSE(mOutput->belongsInOutput(&layer)); |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 458 | |
| 459 | // If the output accepts layerStack1 but not internal-only layers... |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 460 | mOutput->setLayerStackFilter(layerStack1, false); |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 461 | |
| 462 | // A null layer pointer does not belong to the output |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 463 | EXPECT_FALSE(mOutput->belongsInOutput(nullptr)); |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 464 | |
| 465 | // Only non-internal layers with layerStack1 belong to it. |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 466 | layerFEState.layerStackId = layerStack1; |
| 467 | layerFEState.internalOnly = false; |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 468 | EXPECT_TRUE(mOutput->belongsInOutput(&layer)); |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 469 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 470 | layerFEState.layerStackId = layerStack1; |
| 471 | layerFEState.internalOnly = true; |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 472 | EXPECT_FALSE(mOutput->belongsInOutput(&layer)); |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 473 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 474 | layerFEState.layerStackId = layerStack2; |
| 475 | layerFEState.internalOnly = true; |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 476 | EXPECT_FALSE(mOutput->belongsInOutput(&layer)); |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 477 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 478 | layerFEState.layerStackId = layerStack2; |
| 479 | layerFEState.internalOnly = false; |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 480 | EXPECT_FALSE(mOutput->belongsInOutput(&layer)); |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 481 | } |
| 482 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 483 | /* |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 484 | * Output::getOutputLayerForLayer() |
| 485 | */ |
| 486 | |
| 487 | TEST_F(OutputTest, getOutputLayerForLayerWorks) { |
| 488 | mock::OutputLayer* outputLayer1 = new StrictMock<mock::OutputLayer>(); |
| 489 | mock::OutputLayer* outputLayer2 = new StrictMock<mock::OutputLayer>(); |
| 490 | |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 491 | mOutput->injectOutputLayerForTest(std::unique_ptr<OutputLayer>(outputLayer1)); |
| 492 | mOutput->injectOutputLayerForTest(nullptr); |
| 493 | mOutput->injectOutputLayerForTest(std::unique_ptr<OutputLayer>(outputLayer2)); |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 494 | |
| 495 | StrictMock<mock::Layer> layer; |
| 496 | StrictMock<mock::Layer> otherLayer; |
| 497 | |
| 498 | // If the input layer matches the first OutputLayer, it will be returned. |
| 499 | EXPECT_CALL(*outputLayer1, getLayer()).WillOnce(ReturnRef(layer)); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 500 | EXPECT_EQ(outputLayer1, mOutput->getOutputLayerForLayer(&layer)); |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 501 | |
| 502 | // If the input layer matches the second OutputLayer, it will be returned. |
| 503 | EXPECT_CALL(*outputLayer1, getLayer()).WillOnce(ReturnRef(otherLayer)); |
| 504 | EXPECT_CALL(*outputLayer2, getLayer()).WillOnce(ReturnRef(layer)); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 505 | EXPECT_EQ(outputLayer2, mOutput->getOutputLayerForLayer(&layer)); |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 506 | |
| 507 | // If the input layer does not match an output layer, null will be returned. |
| 508 | EXPECT_CALL(*outputLayer1, getLayer()).WillOnce(ReturnRef(otherLayer)); |
| 509 | EXPECT_CALL(*outputLayer2, getLayer()).WillOnce(ReturnRef(otherLayer)); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 510 | EXPECT_EQ(nullptr, mOutput->getOutputLayerForLayer(&layer)); |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 511 | } |
| 512 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 513 | /* |
Lloyd Pique | c9e6003 | 2019-11-14 11:47:26 -0800 | [diff] [blame] | 514 | * Output::setReleasedLayers() |
| 515 | */ |
| 516 | |
| 517 | using OutputSetReleasedLayersTest = OutputTest; |
| 518 | |
| 519 | TEST_F(OutputSetReleasedLayersTest, setReleasedLayersTakesGivenLayers) { |
| 520 | sp<StrictMock<mock::LayerFE>> layer1FE{new StrictMock<mock::LayerFE>()}; |
| 521 | sp<StrictMock<mock::LayerFE>> layer2FE{new StrictMock<mock::LayerFE>()}; |
| 522 | sp<StrictMock<mock::LayerFE>> layer3FE{new StrictMock<mock::LayerFE>()}; |
| 523 | |
| 524 | Output::ReleasedLayers layers; |
| 525 | layers.push_back(layer1FE); |
| 526 | layers.push_back(layer2FE); |
| 527 | layers.push_back(layer3FE); |
| 528 | |
| 529 | mOutput->setReleasedLayers(std::move(layers)); |
| 530 | |
| 531 | const auto& setLayers = mOutput->getReleasedLayersForTest(); |
| 532 | ASSERT_EQ(3u, setLayers.size()); |
| 533 | ASSERT_EQ(layer1FE.get(), setLayers[0].promote().get()); |
| 534 | ASSERT_EQ(layer2FE.get(), setLayers[1].promote().get()); |
| 535 | ASSERT_EQ(layer3FE.get(), setLayers[2].promote().get()); |
| 536 | } |
| 537 | |
| 538 | /* |
Alec Mouri | f9a2a2c | 2019-11-12 12:46:02 -0800 | [diff] [blame] | 539 | * Output::updateAndWriteCompositionState() |
| 540 | */ |
| 541 | |
| 542 | TEST_F(OutputTest, updateAndWriteCompositionState_takesEarlyOutIfNotEnabled) { |
| 543 | mOutput->editState().isEnabled = false; |
| 544 | |
| 545 | CompositionRefreshArgs args; |
| 546 | mOutput->updateAndWriteCompositionState(args); |
| 547 | } |
| 548 | |
| 549 | TEST_F(OutputTest, updateAndWriteCompositionState_updatesLayers) { |
| 550 | mOutput->editState().isEnabled = true; |
| 551 | mock::OutputLayer* outputLayer = new StrictMock<mock::OutputLayer>(); |
| 552 | mOutput->injectOutputLayerForTest(std::unique_ptr<OutputLayer>(outputLayer)); |
| 553 | |
| 554 | EXPECT_CALL(*outputLayer, updateCompositionState(true, true)).Times(1); |
| 555 | EXPECT_CALL(*outputLayer, writeStateToHWC(true)).Times(1); |
| 556 | |
| 557 | CompositionRefreshArgs args; |
| 558 | args.updatingGeometryThisFrame = true; |
| 559 | args.devOptForceClientComposition = true; |
| 560 | mOutput->updateAndWriteCompositionState(args); |
| 561 | } |
| 562 | |
| 563 | /* |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 564 | * Output::prepareFrame() |
| 565 | */ |
| 566 | |
| 567 | struct OutputPrepareFrameTest : public testing::Test { |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 568 | struct OutputPartialMock : public OutputPartialMockBase { |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 569 | // Sets up the helper functions called by prepareFrame to use a mock |
| 570 | // implementations. |
| 571 | MOCK_METHOD0(chooseCompositionStrategy, void()); |
| 572 | }; |
| 573 | |
| 574 | OutputPrepareFrameTest() { |
| 575 | mOutput.setDisplayColorProfileForTest( |
| 576 | std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile)); |
| 577 | mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface)); |
| 578 | } |
| 579 | |
| 580 | StrictMock<mock::CompositionEngine> mCompositionEngine; |
| 581 | mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>(); |
| 582 | mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>(); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 583 | StrictMock<OutputPartialMock> mOutput; |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 584 | }; |
| 585 | |
| 586 | TEST_F(OutputPrepareFrameTest, takesEarlyOutIfNotEnabled) { |
| 587 | mOutput.editState().isEnabled = false; |
| 588 | |
| 589 | mOutput.prepareFrame(); |
| 590 | } |
| 591 | |
| 592 | TEST_F(OutputPrepareFrameTest, delegatesToChooseCompositionStrategyAndRenderSurface) { |
| 593 | mOutput.editState().isEnabled = true; |
| 594 | mOutput.editState().usesClientComposition = false; |
| 595 | mOutput.editState().usesDeviceComposition = true; |
| 596 | |
| 597 | EXPECT_CALL(mOutput, chooseCompositionStrategy()).Times(1); |
| 598 | EXPECT_CALL(*mRenderSurface, prepareFrame(false, true)); |
| 599 | |
| 600 | mOutput.prepareFrame(); |
| 601 | } |
| 602 | |
| 603 | // Note: Use OutputTest and not OutputPrepareFrameTest, so the real |
| 604 | // base chooseCompositionStrategy() is invoked. |
| 605 | TEST_F(OutputTest, prepareFrameSetsClientCompositionOnlyByDefault) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 606 | mOutput->editState().isEnabled = true; |
| 607 | mOutput->editState().usesClientComposition = false; |
| 608 | mOutput->editState().usesDeviceComposition = true; |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 609 | |
| 610 | EXPECT_CALL(*mRenderSurface, prepareFrame(true, false)); |
| 611 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 612 | mOutput->prepareFrame(); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 613 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 614 | EXPECT_TRUE(mOutput->getState().usesClientComposition); |
| 615 | EXPECT_FALSE(mOutput->getState().usesDeviceComposition); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 616 | } |
| 617 | |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 618 | /* |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 619 | * Output::present() |
| 620 | */ |
| 621 | |
| 622 | struct OutputPresentTest : public testing::Test { |
| 623 | struct OutputPartialMock : public OutputPartialMockBase { |
| 624 | // All child helper functions Output::present() are defined as mocks, |
| 625 | // and those are tested separately, allowing the present() test to |
| 626 | // just cover the high level flow. |
| 627 | MOCK_METHOD1(updateColorProfile, void(const compositionengine::CompositionRefreshArgs&)); |
| 628 | MOCK_METHOD1(updateAndWriteCompositionState, |
| 629 | void(const compositionengine::CompositionRefreshArgs&)); |
| 630 | MOCK_METHOD1(setColorTransform, void(const compositionengine::CompositionRefreshArgs&)); |
| 631 | MOCK_METHOD0(beginFrame, void()); |
| 632 | MOCK_METHOD0(prepareFrame, void()); |
| 633 | MOCK_METHOD1(devOptRepaintFlash, void(const compositionengine::CompositionRefreshArgs&)); |
| 634 | MOCK_METHOD1(finishFrame, void(const compositionengine::CompositionRefreshArgs&)); |
| 635 | MOCK_METHOD0(postFramebuffer, void()); |
| 636 | }; |
| 637 | |
| 638 | StrictMock<OutputPartialMock> mOutput; |
| 639 | }; |
| 640 | |
| 641 | TEST_F(OutputPresentTest, justInvokesChildFunctionsInSequence) { |
| 642 | CompositionRefreshArgs args; |
| 643 | |
| 644 | InSequence seq; |
| 645 | EXPECT_CALL(mOutput, updateColorProfile(Ref(args))); |
| 646 | EXPECT_CALL(mOutput, updateAndWriteCompositionState(Ref(args))); |
| 647 | EXPECT_CALL(mOutput, setColorTransform(Ref(args))); |
| 648 | EXPECT_CALL(mOutput, beginFrame()); |
| 649 | EXPECT_CALL(mOutput, prepareFrame()); |
| 650 | EXPECT_CALL(mOutput, devOptRepaintFlash(Ref(args))); |
| 651 | EXPECT_CALL(mOutput, finishFrame(Ref(args))); |
| 652 | EXPECT_CALL(mOutput, postFramebuffer()); |
| 653 | |
| 654 | mOutput.present(args); |
| 655 | } |
| 656 | |
| 657 | /* |
| 658 | * Output::updateColorProfile() |
| 659 | */ |
| 660 | |
| 661 | // TODO(b/144060211) - Add coverage |
| 662 | |
| 663 | /* |
| 664 | * Output::beginFrame() |
| 665 | */ |
| 666 | |
| 667 | /* |
| 668 | * Output::devOptRepaintFlash() |
| 669 | */ |
| 670 | |
Lloyd Pique | db462d8 | 2019-11-19 17:58:46 -0800 | [diff] [blame] | 671 | struct OutputDevOptRepaintFlashTest : public testing::Test { |
| 672 | struct OutputPartialMock : public OutputPartialMockBase { |
| 673 | // Sets up the helper functions called by composeSurfaces to use a mock |
| 674 | // implementations. |
| 675 | MOCK_CONST_METHOD1(getDirtyRegion, Region(bool)); |
| 676 | MOCK_METHOD1(composeSurfaces, std::optional<base::unique_fd>(const Region&)); |
| 677 | MOCK_METHOD0(postFramebuffer, void()); |
| 678 | MOCK_METHOD0(prepareFrame, void()); |
| 679 | }; |
| 680 | |
| 681 | OutputDevOptRepaintFlashTest() { |
| 682 | mOutput.setDisplayColorProfileForTest( |
| 683 | std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile)); |
| 684 | mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface)); |
| 685 | } |
| 686 | |
| 687 | static const Region kEmptyRegion; |
| 688 | static const Region kNotEmptyRegion; |
| 689 | |
| 690 | StrictMock<OutputPartialMock> mOutput; |
| 691 | mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>(); |
| 692 | mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>(); |
| 693 | CompositionRefreshArgs mRefreshArgs; |
| 694 | }; |
| 695 | |
| 696 | const Region OutputDevOptRepaintFlashTest::kEmptyRegion{Rect{0, 0, 0, 0}}; |
| 697 | const Region OutputDevOptRepaintFlashTest::kNotEmptyRegion{Rect{0, 0, 1, 1}}; |
| 698 | |
| 699 | TEST_F(OutputDevOptRepaintFlashTest, doesNothingIfFlashDelayNotSet) { |
| 700 | mRefreshArgs.devOptFlashDirtyRegionsDelay = {}; |
| 701 | mRefreshArgs.repaintEverything = true; |
| 702 | mOutput.mState.isEnabled = true; |
| 703 | |
| 704 | mOutput.devOptRepaintFlash(mRefreshArgs); |
| 705 | } |
| 706 | |
| 707 | TEST_F(OutputDevOptRepaintFlashTest, postsAndPreparesANewFrameIfNotEnabled) { |
| 708 | mRefreshArgs.devOptFlashDirtyRegionsDelay = std::chrono::microseconds(1); |
| 709 | mRefreshArgs.repaintEverything = true; |
| 710 | mOutput.mState.isEnabled = false; |
| 711 | |
| 712 | InSequence seq; |
| 713 | EXPECT_CALL(mOutput, postFramebuffer()); |
| 714 | EXPECT_CALL(mOutput, prepareFrame()); |
| 715 | |
| 716 | mOutput.devOptRepaintFlash(mRefreshArgs); |
| 717 | } |
| 718 | |
| 719 | TEST_F(OutputDevOptRepaintFlashTest, postsAndPreparesANewFrameIfNotDirty) { |
| 720 | mRefreshArgs.devOptFlashDirtyRegionsDelay = std::chrono::microseconds(1); |
| 721 | mRefreshArgs.repaintEverything = true; |
| 722 | mOutput.mState.isEnabled = true; |
| 723 | |
| 724 | InSequence seq; |
| 725 | EXPECT_CALL(mOutput, getDirtyRegion(true)).WillOnce(Return(kEmptyRegion)); |
| 726 | EXPECT_CALL(mOutput, postFramebuffer()); |
| 727 | EXPECT_CALL(mOutput, prepareFrame()); |
| 728 | |
| 729 | mOutput.devOptRepaintFlash(mRefreshArgs); |
| 730 | } |
| 731 | |
| 732 | TEST_F(OutputDevOptRepaintFlashTest, alsoComposesSurfacesAndQueuesABufferIfDirty) { |
| 733 | mRefreshArgs.devOptFlashDirtyRegionsDelay = std::chrono::microseconds(1); |
| 734 | mRefreshArgs.repaintEverything = false; |
| 735 | mOutput.mState.isEnabled = true; |
| 736 | |
| 737 | InSequence seq; |
| 738 | EXPECT_CALL(mOutput, getDirtyRegion(false)).WillOnce(Return(kNotEmptyRegion)); |
| 739 | EXPECT_CALL(mOutput, composeSurfaces(RegionEq(kNotEmptyRegion))); |
| 740 | EXPECT_CALL(*mRenderSurface, queueBuffer(_)); |
| 741 | EXPECT_CALL(mOutput, postFramebuffer()); |
| 742 | EXPECT_CALL(mOutput, prepareFrame()); |
| 743 | |
| 744 | mOutput.devOptRepaintFlash(mRefreshArgs); |
| 745 | } |
| 746 | |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 747 | // TODO(b/144060211) - Add coverage |
| 748 | |
| 749 | /* |
| 750 | * Output::finishFrame() |
| 751 | */ |
| 752 | |
Lloyd Pique | 03561a6 | 2019-11-19 18:34:52 -0800 | [diff] [blame] | 753 | struct OutputFinishFrameTest : public testing::Test { |
| 754 | struct OutputPartialMock : public OutputPartialMockBase { |
| 755 | // Sets up the helper functions called by composeSurfaces to use a mock |
| 756 | // implementations. |
| 757 | MOCK_METHOD1(composeSurfaces, std::optional<base::unique_fd>(const Region&)); |
| 758 | MOCK_METHOD0(postFramebuffer, void()); |
| 759 | }; |
| 760 | |
| 761 | OutputFinishFrameTest() { |
| 762 | mOutput.setDisplayColorProfileForTest( |
| 763 | std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile)); |
| 764 | mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface)); |
| 765 | } |
| 766 | |
| 767 | StrictMock<OutputPartialMock> mOutput; |
| 768 | mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>(); |
| 769 | mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>(); |
| 770 | CompositionRefreshArgs mRefreshArgs; |
| 771 | }; |
| 772 | |
| 773 | TEST_F(OutputFinishFrameTest, ifNotEnabledDoesNothing) { |
| 774 | mOutput.mState.isEnabled = false; |
| 775 | |
| 776 | mOutput.finishFrame(mRefreshArgs); |
| 777 | } |
| 778 | |
| 779 | TEST_F(OutputFinishFrameTest, takesEarlyOutifComposeSurfacesReturnsNoFence) { |
| 780 | mOutput.mState.isEnabled = true; |
| 781 | |
| 782 | InSequence seq; |
| 783 | EXPECT_CALL(mOutput, composeSurfaces(RegionEq(Region::INVALID_REGION))); |
| 784 | |
| 785 | mOutput.finishFrame(mRefreshArgs); |
| 786 | } |
| 787 | |
| 788 | TEST_F(OutputFinishFrameTest, queuesBufferIfComposeSurfacesReturnsAFence) { |
| 789 | mOutput.mState.isEnabled = true; |
| 790 | |
| 791 | InSequence seq; |
| 792 | EXPECT_CALL(mOutput, composeSurfaces(RegionEq(Region::INVALID_REGION))) |
| 793 | .WillOnce(Return(ByMove(base::unique_fd()))); |
| 794 | EXPECT_CALL(*mRenderSurface, queueBuffer(_)); |
| 795 | |
| 796 | mOutput.finishFrame(mRefreshArgs); |
| 797 | } |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 798 | |
| 799 | /* |
| 800 | * Output::postFramebuffer() |
| 801 | */ |
| 802 | |
| 803 | // TODO(b/144060211) - Add coverage |
| 804 | |
| 805 | /* |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 806 | * Output::composeSurfaces() |
| 807 | */ |
| 808 | |
| 809 | struct OutputComposeSurfacesTest : public testing::Test { |
| 810 | static constexpr uint32_t kDefaultOutputOrientation = TR_IDENT; |
| 811 | static constexpr ui::Dataspace kDefaultOutputDataspace = ui::Dataspace::DISPLAY_P3; |
| 812 | |
| 813 | static const Rect kDefaultOutputFrame; |
| 814 | static const Rect kDefaultOutputViewport; |
| 815 | static const Rect kDefaultOutputScissor; |
| 816 | static const mat4 kDefaultColorTransformMat; |
| 817 | |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 818 | struct OutputPartialMock : public OutputPartialMockBase { |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 819 | // Sets up the helper functions called by composeSurfaces to use a mock |
| 820 | // implementations. |
| 821 | MOCK_CONST_METHOD0(getSkipColorTransform, bool()); |
| 822 | MOCK_METHOD2(generateClientCompositionRequests, |
| 823 | std::vector<renderengine::LayerSettings>(bool, Region&)); |
| 824 | MOCK_METHOD2(appendRegionFlashRequests, |
| 825 | void(const Region&, std::vector<renderengine::LayerSettings>&)); |
| 826 | MOCK_METHOD1(setExpensiveRenderingExpected, void(bool)); |
| 827 | }; |
| 828 | |
| 829 | OutputComposeSurfacesTest() { |
| 830 | mOutput.setDisplayColorProfileForTest( |
| 831 | std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile)); |
| 832 | mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface)); |
| 833 | |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 834 | mOutput.editState().frame = kDefaultOutputFrame; |
| 835 | mOutput.editState().viewport = kDefaultOutputViewport; |
| 836 | mOutput.editState().scissor = kDefaultOutputScissor; |
| 837 | mOutput.editState().transform = ui::Transform{kDefaultOutputOrientation}; |
| 838 | mOutput.editState().orientation = kDefaultOutputOrientation; |
| 839 | mOutput.editState().dataspace = kDefaultOutputDataspace; |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 840 | mOutput.editState().colorTransformMatrix = kDefaultColorTransformMat; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 841 | mOutput.editState().isSecure = true; |
| 842 | mOutput.editState().needsFiltering = false; |
| 843 | mOutput.editState().usesClientComposition = true; |
| 844 | mOutput.editState().usesDeviceComposition = false; |
| 845 | |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 846 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(2u)); |
| 847 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0u)) |
| 848 | .WillRepeatedly(Return(&mOutputLayer1)); |
| 849 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(1u)) |
| 850 | .WillRepeatedly(Return(&mOutputLayer2)); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 851 | EXPECT_CALL(mOutput, getCompositionEngine()).WillRepeatedly(ReturnRef(mCompositionEngine)); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 852 | EXPECT_CALL(mCompositionEngine, getRenderEngine()).WillRepeatedly(ReturnRef(mRenderEngine)); |
| 853 | } |
| 854 | |
| 855 | StrictMock<mock::CompositionEngine> mCompositionEngine; |
| 856 | StrictMock<renderengine::mock::RenderEngine> mRenderEngine; |
| 857 | mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>(); |
| 858 | mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>(); |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 859 | StrictMock<mock::OutputLayer> mOutputLayer1; |
| 860 | StrictMock<mock::OutputLayer> mOutputLayer2; |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 861 | StrictMock<OutputPartialMock> mOutput; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 862 | sp<GraphicBuffer> mOutputBuffer = new GraphicBuffer(); |
| 863 | }; |
| 864 | |
| 865 | const Rect OutputComposeSurfacesTest::kDefaultOutputFrame{1001, 1002, 1003, 1004}; |
| 866 | const Rect OutputComposeSurfacesTest::kDefaultOutputViewport{1005, 1006, 1007, 1008}; |
| 867 | const Rect OutputComposeSurfacesTest::kDefaultOutputScissor{1009, 1010, 1011, 1012}; |
| 868 | const mat4 OutputComposeSurfacesTest::kDefaultColorTransformMat{mat4() * 0.5}; |
| 869 | |
| 870 | // TODO(b/121291683): Expand unit test coverage for composeSurfaces beyond these |
| 871 | // basic tests. |
| 872 | |
| 873 | TEST_F(OutputComposeSurfacesTest, doesNothingIfNoClientComposition) { |
| 874 | mOutput.editState().usesClientComposition = false; |
| 875 | |
| 876 | Region debugRegion; |
Lloyd Pique | d3d6988 | 2019-02-28 16:03:46 -0800 | [diff] [blame] | 877 | std::optional<base::unique_fd> readyFence = mOutput.composeSurfaces(debugRegion); |
| 878 | EXPECT_TRUE(readyFence); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 879 | } |
| 880 | |
| 881 | TEST_F(OutputComposeSurfacesTest, worksIfNoClientLayersQueued) { |
| 882 | const Region kDebugRegion{Rect{100, 101, 102, 103}}; |
| 883 | |
| 884 | constexpr float kDefaultMaxLuminance = 1.0f; |
| 885 | constexpr float kDefaultAvgLuminance = 0.7f; |
| 886 | constexpr float kDefaultMinLuminance = 0.1f; |
| 887 | HdrCapabilities HdrCapabilities{{}, |
| 888 | kDefaultMaxLuminance, |
| 889 | kDefaultAvgLuminance, |
| 890 | kDefaultMinLuminance}; |
| 891 | |
| 892 | EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillOnce(Return(false)); |
| 893 | EXPECT_CALL(mRenderEngine, drawLayers(_, _, _, true, _, _)).Times(1); |
| 894 | |
| 895 | EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillOnce(Return(true)); |
| 896 | EXPECT_CALL(*mDisplayColorProfile, getHdrCapabilities()).WillOnce(ReturnRef(HdrCapabilities)); |
| 897 | |
| 898 | EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillOnce(Return(mOutputBuffer)); |
| 899 | |
| 900 | EXPECT_CALL(mOutput, getSkipColorTransform()).WillOnce(Return(false)); |
| 901 | EXPECT_CALL(mOutput, generateClientCompositionRequests(false, _)).Times(1); |
| 902 | EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _)).Times(1); |
| 903 | EXPECT_CALL(mOutput, setExpensiveRenderingExpected(true)).Times(1); |
| 904 | EXPECT_CALL(mOutput, setExpensiveRenderingExpected(false)).Times(1); |
| 905 | |
Lloyd Pique | d3d6988 | 2019-02-28 16:03:46 -0800 | [diff] [blame] | 906 | std::optional<base::unique_fd> readyFence = mOutput.composeSurfaces(kDebugRegion); |
| 907 | EXPECT_TRUE(readyFence); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 908 | } |
| 909 | |
| 910 | /* |
| 911 | * Output::generateClientCompositionRequests() |
| 912 | */ |
| 913 | |
| 914 | struct GenerateClientCompositionRequestsTest : public testing::Test { |
Lloyd Pique | faa3f19 | 2019-11-14 14:05:09 -0800 | [diff] [blame] | 915 | struct OutputPartialMock : public OutputPartialMockBase { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 916 | // compositionengine::Output overrides |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 917 | std::vector<renderengine::LayerSettings> generateClientCompositionRequests( |
| 918 | bool supportsProtectedContent, Region& clearRegion) override { |
| 919 | return impl::Output::generateClientCompositionRequests(supportsProtectedContent, |
| 920 | clearRegion); |
| 921 | } |
| 922 | }; |
| 923 | |
| 924 | GenerateClientCompositionRequestsTest() { |
| 925 | mOutput.setDisplayColorProfileForTest( |
| 926 | std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile)); |
| 927 | mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface)); |
| 928 | } |
| 929 | |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 930 | mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>(); |
| 931 | mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>(); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 932 | StrictMock<OutputPartialMock> mOutput; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 933 | }; |
| 934 | |
| 935 | // TODO(b/121291683): Add more unit test coverage for generateClientCompositionRequests |
| 936 | |
| 937 | TEST_F(GenerateClientCompositionRequestsTest, worksForLandscapeModeSplitScreen) { |
| 938 | // In split-screen landscape mode, the screen is rotated 90 degrees, with |
| 939 | // one layer on the left covering the left side of the output, and one layer |
| 940 | // on the right covering that side of the output. |
| 941 | |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 942 | StrictMock<mock::OutputLayer> leftOutputLayer; |
| 943 | StrictMock<mock::OutputLayer> rightOutputLayer; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 944 | |
| 945 | StrictMock<mock::Layer> leftLayer; |
| 946 | StrictMock<mock::LayerFE> leftLayerFE; |
| 947 | StrictMock<mock::Layer> rightLayer; |
| 948 | StrictMock<mock::LayerFE> rightLayerFE; |
| 949 | |
| 950 | impl::OutputLayerCompositionState leftOutputLayerState; |
| 951 | leftOutputLayerState.clearClientTarget = false; |
Lloyd Pique | a246866 | 2019-03-07 21:31:06 -0800 | [diff] [blame] | 952 | leftOutputLayerState.visibleRegion = Region{Rect{0, 0, 1000, 1000}}; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 953 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 954 | LayerFECompositionState leftLayerFEState; |
| 955 | leftLayerFEState.isOpaque = true; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 956 | |
| 957 | const half3 leftLayerColor{1.f, 0.f, 0.f}; |
| 958 | renderengine::LayerSettings leftLayerRESettings; |
| 959 | leftLayerRESettings.source.solidColor = leftLayerColor; |
| 960 | |
| 961 | impl::OutputLayerCompositionState rightOutputLayerState; |
| 962 | rightOutputLayerState.clearClientTarget = false; |
Lloyd Pique | a246866 | 2019-03-07 21:31:06 -0800 | [diff] [blame] | 963 | rightOutputLayerState.visibleRegion = Region{Rect{1000, 0, 2000, 1000}}; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 964 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 965 | LayerFECompositionState rightLayerFEState; |
| 966 | rightLayerFEState.isOpaque = true; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 967 | |
| 968 | const half3 rightLayerColor{0.f, 1.f, 0.f}; |
| 969 | renderengine::LayerSettings rightLayerRESettings; |
| 970 | rightLayerRESettings.source.solidColor = rightLayerColor; |
| 971 | |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 972 | EXPECT_CALL(leftOutputLayer, getState()).WillRepeatedly(ReturnRef(leftOutputLayerState)); |
| 973 | EXPECT_CALL(leftOutputLayer, getLayer()).WillRepeatedly(ReturnRef(leftLayer)); |
| 974 | EXPECT_CALL(leftOutputLayer, getLayerFE()).WillRepeatedly(ReturnRef(leftLayerFE)); |
| 975 | EXPECT_CALL(leftOutputLayer, requiresClientComposition()).WillRepeatedly(Return(true)); |
| 976 | EXPECT_CALL(leftOutputLayer, needsFiltering()).WillRepeatedly(Return(false)); |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 977 | EXPECT_CALL(leftLayer, getFEState()).WillRepeatedly(ReturnRef(leftLayerFEState)); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 978 | EXPECT_CALL(leftLayerFE, prepareClientComposition(_)).WillOnce(Return(leftLayerRESettings)); |
Adithya Srinivasan | b69e076 | 2019-11-11 18:39:53 -0800 | [diff] [blame] | 979 | EXPECT_CALL(leftOutputLayer, editState()).WillRepeatedly(ReturnRef(leftOutputLayerState)); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 980 | |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 981 | EXPECT_CALL(rightOutputLayer, getState()).WillRepeatedly(ReturnRef(rightOutputLayerState)); |
| 982 | EXPECT_CALL(rightOutputLayer, getLayer()).WillRepeatedly(ReturnRef(rightLayer)); |
| 983 | EXPECT_CALL(rightOutputLayer, getLayerFE()).WillRepeatedly(ReturnRef(rightLayerFE)); |
| 984 | EXPECT_CALL(rightOutputLayer, requiresClientComposition()).WillRepeatedly(Return(true)); |
| 985 | EXPECT_CALL(rightOutputLayer, needsFiltering()).WillRepeatedly(Return(false)); |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 986 | EXPECT_CALL(rightLayer, getFEState()).WillRepeatedly(ReturnRef(rightLayerFEState)); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 987 | EXPECT_CALL(rightLayerFE, prepareClientComposition(_)).WillOnce(Return(rightLayerRESettings)); |
Adithya Srinivasan | b69e076 | 2019-11-11 18:39:53 -0800 | [diff] [blame] | 988 | EXPECT_CALL(rightOutputLayer, editState()).WillRepeatedly(ReturnRef(rightOutputLayerState)); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 989 | |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 990 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(2u)); |
| 991 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0u)) |
| 992 | .WillRepeatedly(Return(&leftOutputLayer)); |
| 993 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(1u)) |
| 994 | .WillRepeatedly(Return(&rightOutputLayer)); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 995 | |
| 996 | const Rect kPortraitFrame(0, 0, 1000, 2000); |
| 997 | const Rect kPortraitViewport(0, 0, 2000, 1000); |
| 998 | const Rect kPortraitScissor(0, 0, 1000, 2000); |
| 999 | const uint32_t kPortraitOrientation = TR_ROT_90; |
| 1000 | |
| 1001 | mOutput.editState().frame = kPortraitFrame; |
| 1002 | mOutput.editState().viewport = kPortraitViewport; |
| 1003 | mOutput.editState().scissor = kPortraitScissor; |
| 1004 | mOutput.editState().transform = ui::Transform{kPortraitOrientation}; |
| 1005 | mOutput.editState().orientation = kPortraitOrientation; |
| 1006 | mOutput.editState().needsFiltering = true; |
| 1007 | mOutput.editState().isSecure = false; |
| 1008 | |
| 1009 | constexpr bool supportsProtectedContent = false; |
| 1010 | Region clearRegion; |
| 1011 | auto requests = |
| 1012 | mOutput.generateClientCompositionRequests(supportsProtectedContent, clearRegion); |
| 1013 | |
| 1014 | ASSERT_EQ(2u, requests.size()); |
| 1015 | EXPECT_EQ(leftLayerColor, requests[0].source.solidColor); |
| 1016 | EXPECT_EQ(rightLayerColor, requests[1].source.solidColor); |
| 1017 | } |
| 1018 | |
| 1019 | TEST_F(GenerateClientCompositionRequestsTest, ignoresLayersThatDoNotIntersectWithViewport) { |
| 1020 | // Layers whose visible region does not intersect with the viewport will be |
| 1021 | // skipped when generating client composition request state. |
| 1022 | |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 1023 | StrictMock<mock::OutputLayer> outputLayer; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 1024 | StrictMock<mock::Layer> layer; |
| 1025 | StrictMock<mock::LayerFE> layerFE; |
| 1026 | |
| 1027 | impl::OutputLayerCompositionState outputLayerState; |
| 1028 | outputLayerState.clearClientTarget = false; |
Lloyd Pique | a246866 | 2019-03-07 21:31:06 -0800 | [diff] [blame] | 1029 | outputLayerState.visibleRegion = Region{Rect{3000, 0, 4000, 1000}}; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 1030 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 1031 | LayerFECompositionState layerFEState; |
| 1032 | layerFEState.isOpaque = true; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 1033 | |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 1034 | EXPECT_CALL(outputLayer, getState()).WillRepeatedly(ReturnRef(outputLayerState)); |
| 1035 | EXPECT_CALL(outputLayer, getLayer()).WillRepeatedly(ReturnRef(layer)); |
| 1036 | EXPECT_CALL(outputLayer, getLayerFE()).WillRepeatedly(ReturnRef(layerFE)); |
| 1037 | EXPECT_CALL(outputLayer, requiresClientComposition()).WillRepeatedly(Return(true)); |
| 1038 | EXPECT_CALL(outputLayer, needsFiltering()).WillRepeatedly(Return(false)); |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 1039 | EXPECT_CALL(layer, getFEState()).WillRepeatedly(ReturnRef(layerFEState)); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 1040 | EXPECT_CALL(layerFE, prepareClientComposition(_)).Times(0); |
Adithya Srinivasan | b69e076 | 2019-11-11 18:39:53 -0800 | [diff] [blame] | 1041 | EXPECT_CALL(outputLayer, editState()).WillRepeatedly(ReturnRef(outputLayerState)); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 1042 | |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 1043 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(1u)); |
| 1044 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0u)).WillRepeatedly(Return(&outputLayer)); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 1045 | |
| 1046 | const Rect kPortraitFrame(0, 0, 1000, 2000); |
| 1047 | const Rect kPortraitViewport(0, 0, 2000, 1000); |
| 1048 | const Rect kPortraitScissor(0, 0, 1000, 2000); |
| 1049 | const uint32_t kPortraitOrientation = TR_ROT_90; |
| 1050 | |
| 1051 | mOutput.editState().frame = kPortraitFrame; |
| 1052 | mOutput.editState().viewport = kPortraitViewport; |
| 1053 | mOutput.editState().scissor = kPortraitScissor; |
| 1054 | mOutput.editState().transform = ui::Transform{kPortraitOrientation}; |
| 1055 | mOutput.editState().orientation = kPortraitOrientation; |
| 1056 | mOutput.editState().needsFiltering = true; |
| 1057 | mOutput.editState().isSecure = false; |
| 1058 | |
| 1059 | constexpr bool supportsProtectedContent = false; |
| 1060 | Region clearRegion; |
| 1061 | auto requests = |
| 1062 | mOutput.generateClientCompositionRequests(supportsProtectedContent, clearRegion); |
| 1063 | |
| 1064 | EXPECT_EQ(0u, requests.size()); |
| 1065 | } |
| 1066 | |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 1067 | TEST_F(GenerateClientCompositionRequestsTest, clearsDeviceLayesAfterFirst) { |
| 1068 | // If client composition is performed with some layers set to use device |
| 1069 | // composition, device layers after the first layer (device or client) will |
| 1070 | // clear the frame buffer if they are opaque and if that layer has a flag |
| 1071 | // set to do so. The first layer is skipped as the frame buffer is already |
| 1072 | // expected to be clear. |
| 1073 | |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 1074 | StrictMock<mock::OutputLayer> leftOutputLayer; |
| 1075 | StrictMock<mock::OutputLayer> rightOutputLayer; |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 1076 | |
| 1077 | StrictMock<mock::Layer> leftLayer; |
| 1078 | StrictMock<mock::LayerFE> leftLayerFE; |
| 1079 | StrictMock<mock::Layer> rightLayer; |
| 1080 | StrictMock<mock::LayerFE> rightLayerFE; |
| 1081 | |
| 1082 | impl::OutputLayerCompositionState leftOutputLayerState; |
| 1083 | leftOutputLayerState.clearClientTarget = true; |
Lloyd Pique | a246866 | 2019-03-07 21:31:06 -0800 | [diff] [blame] | 1084 | leftOutputLayerState.visibleRegion = Region{Rect{0, 0, 1000, 1000}}; |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 1085 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 1086 | LayerFECompositionState leftLayerFEState; |
| 1087 | leftLayerFEState.isOpaque = true; |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 1088 | |
| 1089 | impl::OutputLayerCompositionState rightOutputLayerState; |
| 1090 | rightOutputLayerState.clearClientTarget = true; |
Lloyd Pique | a246866 | 2019-03-07 21:31:06 -0800 | [diff] [blame] | 1091 | rightOutputLayerState.visibleRegion = Region{Rect{1000, 0, 2000, 1000}}; |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 1092 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 1093 | LayerFECompositionState rightLayerFEState; |
| 1094 | rightLayerFEState.isOpaque = true; |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 1095 | |
| 1096 | const half3 rightLayerColor{0.f, 1.f, 0.f}; |
| 1097 | renderengine::LayerSettings rightLayerRESettings; |
| 1098 | rightLayerRESettings.geometry.boundaries = FloatRect{456, 0, 0, 0}; |
| 1099 | rightLayerRESettings.source.solidColor = rightLayerColor; |
| 1100 | |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 1101 | EXPECT_CALL(leftOutputLayer, getState()).WillRepeatedly(ReturnRef(leftOutputLayerState)); |
| 1102 | EXPECT_CALL(leftOutputLayer, getLayer()).WillRepeatedly(ReturnRef(leftLayer)); |
| 1103 | EXPECT_CALL(leftOutputLayer, getLayerFE()).WillRepeatedly(ReturnRef(leftLayerFE)); |
| 1104 | EXPECT_CALL(leftOutputLayer, requiresClientComposition()).WillRepeatedly(Return(false)); |
| 1105 | EXPECT_CALL(leftOutputLayer, needsFiltering()).WillRepeatedly(Return(false)); |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 1106 | EXPECT_CALL(leftLayer, getFEState()).WillRepeatedly(ReturnRef(leftLayerFEState)); |
Adithya Srinivasan | b69e076 | 2019-11-11 18:39:53 -0800 | [diff] [blame] | 1107 | EXPECT_CALL(leftOutputLayer, editState()).WillRepeatedly(ReturnRef(leftOutputLayerState)); |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 1108 | |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 1109 | EXPECT_CALL(rightOutputLayer, getState()).WillRepeatedly(ReturnRef(rightOutputLayerState)); |
| 1110 | EXPECT_CALL(rightOutputLayer, getLayer()).WillRepeatedly(ReturnRef(rightLayer)); |
| 1111 | EXPECT_CALL(rightOutputLayer, getLayerFE()).WillRepeatedly(ReturnRef(rightLayerFE)); |
| 1112 | EXPECT_CALL(rightOutputLayer, requiresClientComposition()).WillRepeatedly(Return(false)); |
| 1113 | EXPECT_CALL(rightOutputLayer, needsFiltering()).WillRepeatedly(Return(false)); |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 1114 | EXPECT_CALL(rightLayer, getFEState()).WillRepeatedly(ReturnRef(rightLayerFEState)); |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 1115 | EXPECT_CALL(rightLayerFE, prepareClientComposition(_)).WillOnce(Return(rightLayerRESettings)); |
Adithya Srinivasan | b69e076 | 2019-11-11 18:39:53 -0800 | [diff] [blame] | 1116 | EXPECT_CALL(rightOutputLayer, editState()).WillRepeatedly(ReturnRef(rightOutputLayerState)); |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 1117 | |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 1118 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(2u)); |
| 1119 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0u)) |
| 1120 | .WillRepeatedly(Return(&leftOutputLayer)); |
| 1121 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(1u)) |
| 1122 | .WillRepeatedly(Return(&rightOutputLayer)); |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 1123 | |
| 1124 | const Rect kPortraitFrame(0, 0, 1000, 2000); |
| 1125 | const Rect kPortraitViewport(0, 0, 2000, 1000); |
| 1126 | const Rect kPortraitScissor(0, 0, 1000, 2000); |
| 1127 | const uint32_t kPortraitOrientation = TR_ROT_90; |
| 1128 | |
| 1129 | mOutput.editState().frame = kPortraitFrame; |
| 1130 | mOutput.editState().viewport = kPortraitViewport; |
| 1131 | mOutput.editState().scissor = kPortraitScissor; |
| 1132 | mOutput.editState().transform = ui::Transform{kPortraitOrientation}; |
| 1133 | mOutput.editState().orientation = kPortraitOrientation; |
| 1134 | mOutput.editState().needsFiltering = true; |
| 1135 | mOutput.editState().isSecure = false; |
| 1136 | |
| 1137 | constexpr bool supportsProtectedContent = false; |
| 1138 | Region clearRegion; |
| 1139 | auto requests = |
| 1140 | mOutput.generateClientCompositionRequests(supportsProtectedContent, clearRegion); |
| 1141 | |
| 1142 | const half3 clearColor{0.f, 0.f, 0.f}; |
| 1143 | |
| 1144 | ASSERT_EQ(1u, requests.size()); |
| 1145 | EXPECT_EQ(456.f, requests[0].geometry.boundaries.left); |
| 1146 | EXPECT_EQ(clearColor, requests[0].source.solidColor); |
| 1147 | } |
| 1148 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 1149 | } // namespace |
| 1150 | } // namespace android::compositionengine |