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