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