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 | /* |
| 486 | * Output::prepareFrame() |
| 487 | */ |
| 488 | |
| 489 | struct OutputPrepareFrameTest : public testing::Test { |
| 490 | struct OutputPartialMock : public impl::Output { |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 491 | // Sets up the helper functions called by prepareFrame to use a mock |
| 492 | // implementations. |
| 493 | MOCK_METHOD0(chooseCompositionStrategy, void()); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 494 | |
| 495 | // compositionengine::Output overrides |
| 496 | const OutputCompositionState& getState() const override { return mState; } |
| 497 | OutputCompositionState& editState() override { return mState; } |
| 498 | |
| 499 | // These need implementations though are not expected to be called. |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame^] | 500 | MOCK_CONST_METHOD0(getOutputLayerCount, size_t()); |
| 501 | MOCK_CONST_METHOD1(getOutputLayerOrderedByZByIndex, |
| 502 | compositionengine::OutputLayer*(size_t)); |
| 503 | MOCK_METHOD3(ensureOutputLayer, |
| 504 | compositionengine::OutputLayer*( |
| 505 | std::optional<size_t>, |
| 506 | const std::shared_ptr<compositionengine::Layer>&, const sp<LayerFE>&)); |
| 507 | MOCK_METHOD0(finalizePendingOutputLayers, void()); |
| 508 | MOCK_METHOD0(clearOutputLayers, void()); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 509 | MOCK_CONST_METHOD1(dumpState, void(std::string&)); |
| 510 | MOCK_CONST_METHOD0(getCompositionEngine, const CompositionEngine&()); |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame^] | 511 | MOCK_METHOD2(injectOutputLayerForTest, |
| 512 | compositionengine::OutputLayer*( |
| 513 | const std::shared_ptr<compositionengine::Layer>&, const sp<LayerFE>&)); |
| 514 | MOCK_METHOD1(injectOutputLayerForTest, void(std::unique_ptr<OutputLayer>)); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 515 | |
| 516 | impl::OutputCompositionState mState; |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 517 | }; |
| 518 | |
| 519 | OutputPrepareFrameTest() { |
| 520 | mOutput.setDisplayColorProfileForTest( |
| 521 | std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile)); |
| 522 | mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface)); |
| 523 | } |
| 524 | |
| 525 | StrictMock<mock::CompositionEngine> mCompositionEngine; |
| 526 | mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>(); |
| 527 | mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>(); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 528 | StrictMock<OutputPartialMock> mOutput; |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 529 | }; |
| 530 | |
| 531 | TEST_F(OutputPrepareFrameTest, takesEarlyOutIfNotEnabled) { |
| 532 | mOutput.editState().isEnabled = false; |
| 533 | |
| 534 | mOutput.prepareFrame(); |
| 535 | } |
| 536 | |
| 537 | TEST_F(OutputPrepareFrameTest, delegatesToChooseCompositionStrategyAndRenderSurface) { |
| 538 | mOutput.editState().isEnabled = true; |
| 539 | mOutput.editState().usesClientComposition = false; |
| 540 | mOutput.editState().usesDeviceComposition = true; |
| 541 | |
| 542 | EXPECT_CALL(mOutput, chooseCompositionStrategy()).Times(1); |
| 543 | EXPECT_CALL(*mRenderSurface, prepareFrame(false, true)); |
| 544 | |
| 545 | mOutput.prepareFrame(); |
| 546 | } |
| 547 | |
| 548 | // Note: Use OutputTest and not OutputPrepareFrameTest, so the real |
| 549 | // base chooseCompositionStrategy() is invoked. |
| 550 | TEST_F(OutputTest, prepareFrameSetsClientCompositionOnlyByDefault) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 551 | mOutput->editState().isEnabled = true; |
| 552 | mOutput->editState().usesClientComposition = false; |
| 553 | mOutput->editState().usesDeviceComposition = true; |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 554 | |
| 555 | EXPECT_CALL(*mRenderSurface, prepareFrame(true, false)); |
| 556 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 557 | mOutput->prepareFrame(); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 558 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 559 | EXPECT_TRUE(mOutput->getState().usesClientComposition); |
| 560 | EXPECT_FALSE(mOutput->getState().usesDeviceComposition); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 561 | } |
| 562 | |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 563 | /* |
| 564 | * Output::composeSurfaces() |
| 565 | */ |
| 566 | |
| 567 | struct OutputComposeSurfacesTest : public testing::Test { |
| 568 | static constexpr uint32_t kDefaultOutputOrientation = TR_IDENT; |
| 569 | static constexpr ui::Dataspace kDefaultOutputDataspace = ui::Dataspace::DISPLAY_P3; |
| 570 | |
| 571 | static const Rect kDefaultOutputFrame; |
| 572 | static const Rect kDefaultOutputViewport; |
| 573 | static const Rect kDefaultOutputScissor; |
| 574 | static const mat4 kDefaultColorTransformMat; |
| 575 | |
| 576 | struct OutputPartialMock : public impl::Output { |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 577 | // Sets up the helper functions called by composeSurfaces to use a mock |
| 578 | // implementations. |
| 579 | MOCK_CONST_METHOD0(getSkipColorTransform, bool()); |
| 580 | MOCK_METHOD2(generateClientCompositionRequests, |
| 581 | std::vector<renderengine::LayerSettings>(bool, Region&)); |
| 582 | MOCK_METHOD2(appendRegionFlashRequests, |
| 583 | void(const Region&, std::vector<renderengine::LayerSettings>&)); |
| 584 | MOCK_METHOD1(setExpensiveRenderingExpected, void(bool)); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 585 | |
| 586 | // compositionengine::Output overrides |
| 587 | const OutputCompositionState& getState() const override { return mState; } |
| 588 | OutputCompositionState& editState() override { return mState; } |
| 589 | |
| 590 | // These need implementations though are not expected to be called. |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame^] | 591 | MOCK_CONST_METHOD0(getOutputLayerCount, size_t()); |
| 592 | MOCK_CONST_METHOD1(getOutputLayerOrderedByZByIndex, |
| 593 | compositionengine::OutputLayer*(size_t)); |
| 594 | MOCK_METHOD3(ensureOutputLayer, |
| 595 | compositionengine::OutputLayer*( |
| 596 | std::optional<size_t>, |
| 597 | const std::shared_ptr<compositionengine::Layer>&, const sp<LayerFE>&)); |
| 598 | MOCK_METHOD0(finalizePendingOutputLayers, void()); |
| 599 | MOCK_METHOD0(clearOutputLayers, void()); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 600 | MOCK_CONST_METHOD1(dumpState, void(std::string&)); |
| 601 | MOCK_CONST_METHOD0(getCompositionEngine, const CompositionEngine&()); |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame^] | 602 | MOCK_METHOD2(injectOutputLayerForTest, |
| 603 | compositionengine::OutputLayer*( |
| 604 | const std::shared_ptr<compositionengine::Layer>&, const sp<LayerFE>&)); |
| 605 | MOCK_METHOD1(injectOutputLayerForTest, void(std::unique_ptr<OutputLayer>)); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 606 | |
| 607 | impl::OutputCompositionState mState; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 608 | }; |
| 609 | |
| 610 | OutputComposeSurfacesTest() { |
| 611 | mOutput.setDisplayColorProfileForTest( |
| 612 | std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile)); |
| 613 | mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface)); |
| 614 | |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 615 | mOutput.editState().frame = kDefaultOutputFrame; |
| 616 | mOutput.editState().viewport = kDefaultOutputViewport; |
| 617 | mOutput.editState().scissor = kDefaultOutputScissor; |
| 618 | mOutput.editState().transform = ui::Transform{kDefaultOutputOrientation}; |
| 619 | mOutput.editState().orientation = kDefaultOutputOrientation; |
| 620 | mOutput.editState().dataspace = kDefaultOutputDataspace; |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 621 | mOutput.editState().colorTransformMatrix = kDefaultColorTransformMat; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 622 | mOutput.editState().isSecure = true; |
| 623 | mOutput.editState().needsFiltering = false; |
| 624 | mOutput.editState().usesClientComposition = true; |
| 625 | mOutput.editState().usesDeviceComposition = false; |
| 626 | |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame^] | 627 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(2u)); |
| 628 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0u)) |
| 629 | .WillRepeatedly(Return(&mOutputLayer1)); |
| 630 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(1u)) |
| 631 | .WillRepeatedly(Return(&mOutputLayer2)); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 632 | EXPECT_CALL(mOutput, getCompositionEngine()).WillRepeatedly(ReturnRef(mCompositionEngine)); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 633 | EXPECT_CALL(mCompositionEngine, getRenderEngine()).WillRepeatedly(ReturnRef(mRenderEngine)); |
| 634 | } |
| 635 | |
| 636 | StrictMock<mock::CompositionEngine> mCompositionEngine; |
| 637 | StrictMock<renderengine::mock::RenderEngine> mRenderEngine; |
| 638 | mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>(); |
| 639 | mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>(); |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame^] | 640 | StrictMock<mock::OutputLayer> mOutputLayer1; |
| 641 | StrictMock<mock::OutputLayer> mOutputLayer2; |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 642 | StrictMock<OutputPartialMock> mOutput; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 643 | sp<GraphicBuffer> mOutputBuffer = new GraphicBuffer(); |
| 644 | }; |
| 645 | |
| 646 | const Rect OutputComposeSurfacesTest::kDefaultOutputFrame{1001, 1002, 1003, 1004}; |
| 647 | const Rect OutputComposeSurfacesTest::kDefaultOutputViewport{1005, 1006, 1007, 1008}; |
| 648 | const Rect OutputComposeSurfacesTest::kDefaultOutputScissor{1009, 1010, 1011, 1012}; |
| 649 | const mat4 OutputComposeSurfacesTest::kDefaultColorTransformMat{mat4() * 0.5}; |
| 650 | |
| 651 | // TODO(b/121291683): Expand unit test coverage for composeSurfaces beyond these |
| 652 | // basic tests. |
| 653 | |
| 654 | TEST_F(OutputComposeSurfacesTest, doesNothingIfNoClientComposition) { |
| 655 | mOutput.editState().usesClientComposition = false; |
| 656 | |
| 657 | Region debugRegion; |
Lloyd Pique | d3d6988 | 2019-02-28 16:03:46 -0800 | [diff] [blame] | 658 | std::optional<base::unique_fd> readyFence = mOutput.composeSurfaces(debugRegion); |
| 659 | EXPECT_TRUE(readyFence); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 660 | } |
| 661 | |
| 662 | TEST_F(OutputComposeSurfacesTest, worksIfNoClientLayersQueued) { |
| 663 | const Region kDebugRegion{Rect{100, 101, 102, 103}}; |
| 664 | |
| 665 | constexpr float kDefaultMaxLuminance = 1.0f; |
| 666 | constexpr float kDefaultAvgLuminance = 0.7f; |
| 667 | constexpr float kDefaultMinLuminance = 0.1f; |
| 668 | HdrCapabilities HdrCapabilities{{}, |
| 669 | kDefaultMaxLuminance, |
| 670 | kDefaultAvgLuminance, |
| 671 | kDefaultMinLuminance}; |
| 672 | |
| 673 | EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillOnce(Return(false)); |
| 674 | EXPECT_CALL(mRenderEngine, drawLayers(_, _, _, true, _, _)).Times(1); |
| 675 | |
| 676 | EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillOnce(Return(true)); |
| 677 | EXPECT_CALL(*mDisplayColorProfile, getHdrCapabilities()).WillOnce(ReturnRef(HdrCapabilities)); |
| 678 | |
| 679 | EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillOnce(Return(mOutputBuffer)); |
| 680 | |
| 681 | EXPECT_CALL(mOutput, getSkipColorTransform()).WillOnce(Return(false)); |
| 682 | EXPECT_CALL(mOutput, generateClientCompositionRequests(false, _)).Times(1); |
| 683 | EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _)).Times(1); |
| 684 | EXPECT_CALL(mOutput, setExpensiveRenderingExpected(true)).Times(1); |
| 685 | EXPECT_CALL(mOutput, setExpensiveRenderingExpected(false)).Times(1); |
| 686 | |
Lloyd Pique | d3d6988 | 2019-02-28 16:03:46 -0800 | [diff] [blame] | 687 | std::optional<base::unique_fd> readyFence = mOutput.composeSurfaces(kDebugRegion); |
| 688 | EXPECT_TRUE(readyFence); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 689 | } |
| 690 | |
| 691 | /* |
| 692 | * Output::generateClientCompositionRequests() |
| 693 | */ |
| 694 | |
| 695 | struct GenerateClientCompositionRequestsTest : public testing::Test { |
| 696 | struct OutputPartialMock : public impl::Output { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 697 | // compositionengine::Output overrides |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 698 | |
| 699 | std::vector<renderengine::LayerSettings> generateClientCompositionRequests( |
| 700 | bool supportsProtectedContent, Region& clearRegion) override { |
| 701 | return impl::Output::generateClientCompositionRequests(supportsProtectedContent, |
| 702 | clearRegion); |
| 703 | } |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 704 | |
| 705 | const OutputCompositionState& getState() const override { return mState; } |
| 706 | OutputCompositionState& editState() override { return mState; } |
| 707 | |
| 708 | // These need implementations though are not expected to be called. |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame^] | 709 | MOCK_CONST_METHOD0(getOutputLayerCount, size_t()); |
| 710 | MOCK_CONST_METHOD1(getOutputLayerOrderedByZByIndex, |
| 711 | compositionengine::OutputLayer*(size_t)); |
| 712 | MOCK_METHOD3(ensureOutputLayer, |
| 713 | compositionengine::OutputLayer*( |
| 714 | std::optional<size_t>, |
| 715 | const std::shared_ptr<compositionengine::Layer>&, const sp<LayerFE>&)); |
| 716 | MOCK_METHOD0(finalizePendingOutputLayers, void()); |
| 717 | MOCK_METHOD0(clearOutputLayers, void()); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 718 | MOCK_CONST_METHOD1(dumpState, void(std::string&)); |
| 719 | MOCK_CONST_METHOD0(getCompositionEngine, const CompositionEngine&()); |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame^] | 720 | MOCK_METHOD2(injectOutputLayerForTest, |
| 721 | compositionengine::OutputLayer*( |
| 722 | const std::shared_ptr<compositionengine::Layer>&, const sp<LayerFE>&)); |
| 723 | MOCK_METHOD1(injectOutputLayerForTest, void(std::unique_ptr<OutputLayer>)); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 724 | |
| 725 | impl::OutputCompositionState mState; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 726 | }; |
| 727 | |
| 728 | GenerateClientCompositionRequestsTest() { |
| 729 | mOutput.setDisplayColorProfileForTest( |
| 730 | std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile)); |
| 731 | mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface)); |
| 732 | } |
| 733 | |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 734 | mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>(); |
| 735 | mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>(); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 736 | StrictMock<OutputPartialMock> mOutput; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 737 | }; |
| 738 | |
| 739 | // TODO(b/121291683): Add more unit test coverage for generateClientCompositionRequests |
| 740 | |
| 741 | TEST_F(GenerateClientCompositionRequestsTest, worksForLandscapeModeSplitScreen) { |
| 742 | // In split-screen landscape mode, the screen is rotated 90 degrees, with |
| 743 | // one layer on the left covering the left side of the output, and one layer |
| 744 | // on the right covering that side of the output. |
| 745 | |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame^] | 746 | StrictMock<mock::OutputLayer> leftOutputLayer; |
| 747 | StrictMock<mock::OutputLayer> rightOutputLayer; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 748 | |
| 749 | StrictMock<mock::Layer> leftLayer; |
| 750 | StrictMock<mock::LayerFE> leftLayerFE; |
| 751 | StrictMock<mock::Layer> rightLayer; |
| 752 | StrictMock<mock::LayerFE> rightLayerFE; |
| 753 | |
| 754 | impl::OutputLayerCompositionState leftOutputLayerState; |
| 755 | leftOutputLayerState.clearClientTarget = false; |
Lloyd Pique | a246866 | 2019-03-07 21:31:06 -0800 | [diff] [blame] | 756 | leftOutputLayerState.visibleRegion = Region{Rect{0, 0, 1000, 1000}}; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 757 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 758 | LayerFECompositionState leftLayerFEState; |
| 759 | leftLayerFEState.isOpaque = true; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 760 | |
| 761 | const half3 leftLayerColor{1.f, 0.f, 0.f}; |
| 762 | renderengine::LayerSettings leftLayerRESettings; |
| 763 | leftLayerRESettings.source.solidColor = leftLayerColor; |
| 764 | |
| 765 | impl::OutputLayerCompositionState rightOutputLayerState; |
| 766 | rightOutputLayerState.clearClientTarget = false; |
Lloyd Pique | a246866 | 2019-03-07 21:31:06 -0800 | [diff] [blame] | 767 | rightOutputLayerState.visibleRegion = Region{Rect{1000, 0, 2000, 1000}}; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 768 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 769 | LayerFECompositionState rightLayerFEState; |
| 770 | rightLayerFEState.isOpaque = true; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 771 | |
| 772 | const half3 rightLayerColor{0.f, 1.f, 0.f}; |
| 773 | renderengine::LayerSettings rightLayerRESettings; |
| 774 | rightLayerRESettings.source.solidColor = rightLayerColor; |
| 775 | |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame^] | 776 | EXPECT_CALL(leftOutputLayer, getState()).WillRepeatedly(ReturnRef(leftOutputLayerState)); |
| 777 | EXPECT_CALL(leftOutputLayer, getLayer()).WillRepeatedly(ReturnRef(leftLayer)); |
| 778 | EXPECT_CALL(leftOutputLayer, getLayerFE()).WillRepeatedly(ReturnRef(leftLayerFE)); |
| 779 | EXPECT_CALL(leftOutputLayer, requiresClientComposition()).WillRepeatedly(Return(true)); |
| 780 | EXPECT_CALL(leftOutputLayer, needsFiltering()).WillRepeatedly(Return(false)); |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 781 | EXPECT_CALL(leftLayer, getFEState()).WillRepeatedly(ReturnRef(leftLayerFEState)); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 782 | EXPECT_CALL(leftLayerFE, prepareClientComposition(_)).WillOnce(Return(leftLayerRESettings)); |
| 783 | |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame^] | 784 | EXPECT_CALL(rightOutputLayer, getState()).WillRepeatedly(ReturnRef(rightOutputLayerState)); |
| 785 | EXPECT_CALL(rightOutputLayer, getLayer()).WillRepeatedly(ReturnRef(rightLayer)); |
| 786 | EXPECT_CALL(rightOutputLayer, getLayerFE()).WillRepeatedly(ReturnRef(rightLayerFE)); |
| 787 | EXPECT_CALL(rightOutputLayer, requiresClientComposition()).WillRepeatedly(Return(true)); |
| 788 | EXPECT_CALL(rightOutputLayer, needsFiltering()).WillRepeatedly(Return(false)); |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 789 | EXPECT_CALL(rightLayer, getFEState()).WillRepeatedly(ReturnRef(rightLayerFEState)); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 790 | EXPECT_CALL(rightLayerFE, prepareClientComposition(_)).WillOnce(Return(rightLayerRESettings)); |
| 791 | |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame^] | 792 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(2u)); |
| 793 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0u)) |
| 794 | .WillRepeatedly(Return(&leftOutputLayer)); |
| 795 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(1u)) |
| 796 | .WillRepeatedly(Return(&rightOutputLayer)); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 797 | |
| 798 | const Rect kPortraitFrame(0, 0, 1000, 2000); |
| 799 | const Rect kPortraitViewport(0, 0, 2000, 1000); |
| 800 | const Rect kPortraitScissor(0, 0, 1000, 2000); |
| 801 | const uint32_t kPortraitOrientation = TR_ROT_90; |
| 802 | |
| 803 | mOutput.editState().frame = kPortraitFrame; |
| 804 | mOutput.editState().viewport = kPortraitViewport; |
| 805 | mOutput.editState().scissor = kPortraitScissor; |
| 806 | mOutput.editState().transform = ui::Transform{kPortraitOrientation}; |
| 807 | mOutput.editState().orientation = kPortraitOrientation; |
| 808 | mOutput.editState().needsFiltering = true; |
| 809 | mOutput.editState().isSecure = false; |
| 810 | |
| 811 | constexpr bool supportsProtectedContent = false; |
| 812 | Region clearRegion; |
| 813 | auto requests = |
| 814 | mOutput.generateClientCompositionRequests(supportsProtectedContent, clearRegion); |
| 815 | |
| 816 | ASSERT_EQ(2u, requests.size()); |
| 817 | EXPECT_EQ(leftLayerColor, requests[0].source.solidColor); |
| 818 | EXPECT_EQ(rightLayerColor, requests[1].source.solidColor); |
| 819 | } |
| 820 | |
| 821 | TEST_F(GenerateClientCompositionRequestsTest, ignoresLayersThatDoNotIntersectWithViewport) { |
| 822 | // Layers whose visible region does not intersect with the viewport will be |
| 823 | // skipped when generating client composition request state. |
| 824 | |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame^] | 825 | StrictMock<mock::OutputLayer> outputLayer; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 826 | StrictMock<mock::Layer> layer; |
| 827 | StrictMock<mock::LayerFE> layerFE; |
| 828 | |
| 829 | impl::OutputLayerCompositionState outputLayerState; |
| 830 | outputLayerState.clearClientTarget = false; |
Lloyd Pique | a246866 | 2019-03-07 21:31:06 -0800 | [diff] [blame] | 831 | outputLayerState.visibleRegion = Region{Rect{3000, 0, 4000, 1000}}; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 832 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 833 | LayerFECompositionState layerFEState; |
| 834 | layerFEState.isOpaque = true; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 835 | |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame^] | 836 | EXPECT_CALL(outputLayer, getState()).WillRepeatedly(ReturnRef(outputLayerState)); |
| 837 | EXPECT_CALL(outputLayer, getLayer()).WillRepeatedly(ReturnRef(layer)); |
| 838 | EXPECT_CALL(outputLayer, getLayerFE()).WillRepeatedly(ReturnRef(layerFE)); |
| 839 | EXPECT_CALL(outputLayer, requiresClientComposition()).WillRepeatedly(Return(true)); |
| 840 | EXPECT_CALL(outputLayer, needsFiltering()).WillRepeatedly(Return(false)); |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 841 | EXPECT_CALL(layer, getFEState()).WillRepeatedly(ReturnRef(layerFEState)); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 842 | EXPECT_CALL(layerFE, prepareClientComposition(_)).Times(0); |
| 843 | |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame^] | 844 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(1u)); |
| 845 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0u)).WillRepeatedly(Return(&outputLayer)); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 846 | |
| 847 | const Rect kPortraitFrame(0, 0, 1000, 2000); |
| 848 | const Rect kPortraitViewport(0, 0, 2000, 1000); |
| 849 | const Rect kPortraitScissor(0, 0, 1000, 2000); |
| 850 | const uint32_t kPortraitOrientation = TR_ROT_90; |
| 851 | |
| 852 | mOutput.editState().frame = kPortraitFrame; |
| 853 | mOutput.editState().viewport = kPortraitViewport; |
| 854 | mOutput.editState().scissor = kPortraitScissor; |
| 855 | mOutput.editState().transform = ui::Transform{kPortraitOrientation}; |
| 856 | mOutput.editState().orientation = kPortraitOrientation; |
| 857 | mOutput.editState().needsFiltering = true; |
| 858 | mOutput.editState().isSecure = false; |
| 859 | |
| 860 | constexpr bool supportsProtectedContent = false; |
| 861 | Region clearRegion; |
| 862 | auto requests = |
| 863 | mOutput.generateClientCompositionRequests(supportsProtectedContent, clearRegion); |
| 864 | |
| 865 | EXPECT_EQ(0u, requests.size()); |
| 866 | } |
| 867 | |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 868 | TEST_F(GenerateClientCompositionRequestsTest, clearsDeviceLayesAfterFirst) { |
| 869 | // If client composition is performed with some layers set to use device |
| 870 | // composition, device layers after the first layer (device or client) will |
| 871 | // clear the frame buffer if they are opaque and if that layer has a flag |
| 872 | // set to do so. The first layer is skipped as the frame buffer is already |
| 873 | // expected to be clear. |
| 874 | |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame^] | 875 | StrictMock<mock::OutputLayer> leftOutputLayer; |
| 876 | StrictMock<mock::OutputLayer> rightOutputLayer; |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 877 | |
| 878 | StrictMock<mock::Layer> leftLayer; |
| 879 | StrictMock<mock::LayerFE> leftLayerFE; |
| 880 | StrictMock<mock::Layer> rightLayer; |
| 881 | StrictMock<mock::LayerFE> rightLayerFE; |
| 882 | |
| 883 | impl::OutputLayerCompositionState leftOutputLayerState; |
| 884 | leftOutputLayerState.clearClientTarget = true; |
Lloyd Pique | a246866 | 2019-03-07 21:31:06 -0800 | [diff] [blame] | 885 | leftOutputLayerState.visibleRegion = Region{Rect{0, 0, 1000, 1000}}; |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 886 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 887 | LayerFECompositionState leftLayerFEState; |
| 888 | leftLayerFEState.isOpaque = true; |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 889 | |
| 890 | impl::OutputLayerCompositionState rightOutputLayerState; |
| 891 | rightOutputLayerState.clearClientTarget = true; |
Lloyd Pique | a246866 | 2019-03-07 21:31:06 -0800 | [diff] [blame] | 892 | rightOutputLayerState.visibleRegion = Region{Rect{1000, 0, 2000, 1000}}; |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 893 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 894 | LayerFECompositionState rightLayerFEState; |
| 895 | rightLayerFEState.isOpaque = true; |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 896 | |
| 897 | const half3 rightLayerColor{0.f, 1.f, 0.f}; |
| 898 | renderengine::LayerSettings rightLayerRESettings; |
| 899 | rightLayerRESettings.geometry.boundaries = FloatRect{456, 0, 0, 0}; |
| 900 | rightLayerRESettings.source.solidColor = rightLayerColor; |
| 901 | |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame^] | 902 | EXPECT_CALL(leftOutputLayer, getState()).WillRepeatedly(ReturnRef(leftOutputLayerState)); |
| 903 | EXPECT_CALL(leftOutputLayer, getLayer()).WillRepeatedly(ReturnRef(leftLayer)); |
| 904 | EXPECT_CALL(leftOutputLayer, getLayerFE()).WillRepeatedly(ReturnRef(leftLayerFE)); |
| 905 | EXPECT_CALL(leftOutputLayer, requiresClientComposition()).WillRepeatedly(Return(false)); |
| 906 | EXPECT_CALL(leftOutputLayer, needsFiltering()).WillRepeatedly(Return(false)); |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 907 | EXPECT_CALL(leftLayer, getFEState()).WillRepeatedly(ReturnRef(leftLayerFEState)); |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 908 | |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame^] | 909 | EXPECT_CALL(rightOutputLayer, getState()).WillRepeatedly(ReturnRef(rightOutputLayerState)); |
| 910 | EXPECT_CALL(rightOutputLayer, getLayer()).WillRepeatedly(ReturnRef(rightLayer)); |
| 911 | EXPECT_CALL(rightOutputLayer, getLayerFE()).WillRepeatedly(ReturnRef(rightLayerFE)); |
| 912 | EXPECT_CALL(rightOutputLayer, requiresClientComposition()).WillRepeatedly(Return(false)); |
| 913 | EXPECT_CALL(rightOutputLayer, needsFiltering()).WillRepeatedly(Return(false)); |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 914 | EXPECT_CALL(rightLayer, getFEState()).WillRepeatedly(ReturnRef(rightLayerFEState)); |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 915 | EXPECT_CALL(rightLayerFE, prepareClientComposition(_)).WillOnce(Return(rightLayerRESettings)); |
| 916 | |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame^] | 917 | EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(2u)); |
| 918 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0u)) |
| 919 | .WillRepeatedly(Return(&leftOutputLayer)); |
| 920 | EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(1u)) |
| 921 | .WillRepeatedly(Return(&rightOutputLayer)); |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 922 | |
| 923 | const Rect kPortraitFrame(0, 0, 1000, 2000); |
| 924 | const Rect kPortraitViewport(0, 0, 2000, 1000); |
| 925 | const Rect kPortraitScissor(0, 0, 1000, 2000); |
| 926 | const uint32_t kPortraitOrientation = TR_ROT_90; |
| 927 | |
| 928 | mOutput.editState().frame = kPortraitFrame; |
| 929 | mOutput.editState().viewport = kPortraitViewport; |
| 930 | mOutput.editState().scissor = kPortraitScissor; |
| 931 | mOutput.editState().transform = ui::Transform{kPortraitOrientation}; |
| 932 | mOutput.editState().orientation = kPortraitOrientation; |
| 933 | mOutput.editState().needsFiltering = true; |
| 934 | mOutput.editState().isSecure = false; |
| 935 | |
| 936 | constexpr bool supportsProtectedContent = false; |
| 937 | Region clearRegion; |
| 938 | auto requests = |
| 939 | mOutput.generateClientCompositionRequests(supportsProtectedContent, clearRegion); |
| 940 | |
| 941 | const half3 clearColor{0.f, 0.f, 0.f}; |
| 942 | |
| 943 | ASSERT_EQ(1u, requests.size()); |
| 944 | EXPECT_EQ(456.f, requests[0].geometry.boundaries.left); |
| 945 | EXPECT_EQ(clearColor, requests[0].source.solidColor); |
| 946 | } |
| 947 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 948 | } // namespace |
| 949 | } // namespace android::compositionengine |