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