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 | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 54 | mOutput.setDisplayColorProfileForTest( |
| 55 | std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile)); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 56 | mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface)); |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 57 | |
| 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 | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 66 | impl::Output mOutput{mCompositionEngine}; |
| 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 | |
| 80 | EXPECT_TRUE(mOutput.isValid()); |
| 81 | |
| 82 | // If we take away the required components, it is no longer valid. |
| 83 | mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>()); |
| 84 | |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 85 | EXPECT_CALL(*mDisplayColorProfile, isValid()).WillOnce(Return(true)); |
| 86 | |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 87 | EXPECT_FALSE(mOutput.isValid()); |
| 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 | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 95 | mOutput.editState().isEnabled = true; |
| 96 | |
| 97 | mOutput.setCompositionEnabled(true); |
| 98 | |
| 99 | EXPECT_TRUE(mOutput.getState().isEnabled); |
| 100 | EXPECT_THAT(mOutput.getState().dirtyRegion, RegionEq(Region())); |
| 101 | } |
| 102 | |
| 103 | TEST_F(OutputTest, setCompositionEnabledSetsEnabledAndDirtiesEntireOutput) { |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 104 | mOutput.editState().isEnabled = false; |
| 105 | |
| 106 | mOutput.setCompositionEnabled(true); |
| 107 | |
| 108 | EXPECT_TRUE(mOutput.getState().isEnabled); |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 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 | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 113 | mOutput.editState().isEnabled = true; |
| 114 | |
| 115 | mOutput.setCompositionEnabled(false); |
| 116 | |
| 117 | EXPECT_FALSE(mOutput.getState().isEnabled); |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 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 | |
| 133 | mOutput.setProjection(transform, orientation, frame, viewport, scissor, needsFiltering); |
| 134 | |
| 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); |
| 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 | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 153 | mOutput.setBounds(displaySize); |
| 154 | |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -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 | 31cb294 | 2018-10-19 17:23:03 -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 | ef36b00 | 2019-01-23 17:52:04 -0800 | [diff] [blame] | 166 | mOutput.setLayerStackFilter(layerStack, true); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 167 | |
Lloyd Pique | ef36b00 | 2019-01-23 17:52:04 -0800 | [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 | ef95812 | 2019-02-05 18:00:12 -0800 | [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) { |
| 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 | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [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 |
| 188 | EXPECT_EQ(kIdentity, mOutput.getState().colorTransformMatrix); |
| 189 | |
| 190 | // No dirty region should be set |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [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) { |
| 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 | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [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 |
| 205 | EXPECT_EQ(kIdentity, mOutput.getState().colorTransformMatrix); |
| 206 | |
| 207 | // No dirty region should be set |
| 208 | EXPECT_THAT(mOutput.getState().dirtyRegion, RegionEq(Region())); |
| 209 | } |
| 210 | |
| 211 | TEST_F(OutputTest, setColorTransformPerformsUpdateToIdentity) { |
| 212 | mOutput.editState().colorTransformMatrix = kNonIdentityHalf; |
| 213 | |
| 214 | // Setting a different colorTransformMatrix should perform the update. |
| 215 | CompositionRefreshArgs refreshArgs; |
| 216 | refreshArgs.colorTransformMatrix = kIdentity; |
| 217 | |
| 218 | mOutput.setColorTransform(refreshArgs); |
| 219 | |
| 220 | // The internal state should have been updated |
| 221 | EXPECT_EQ(kIdentity, mOutput.getState().colorTransformMatrix); |
| 222 | |
| 223 | // The dirtyRegion should be set to the full display size |
Lloyd Pique | 77f79a2 | 2019-04-29 15:55:40 -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) { |
| 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 | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [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 |
| 237 | EXPECT_EQ(kNonIdentityHalf, mOutput.getState().colorTransformMatrix); |
| 238 | |
| 239 | // The dirtyRegion should be set to the full display size |
| 240 | EXPECT_THAT(mOutput.getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize))); |
| 241 | } |
| 242 | |
| 243 | TEST_F(OutputTest, setColorTransformPerformsUpdateForHalfToQuarter) { |
| 244 | mOutput.editState().colorTransformMatrix = kNonIdentityHalf; |
| 245 | |
| 246 | // Setting a different colorTransformMatrix should perform the update. |
| 247 | CompositionRefreshArgs refreshArgs; |
| 248 | refreshArgs.colorTransformMatrix = kNonIdentityQuarter; |
| 249 | |
| 250 | mOutput.setColorTransform(refreshArgs); |
| 251 | |
| 252 | // The internal state should have been updated |
| 253 | EXPECT_EQ(kNonIdentityQuarter, mOutput.getState().colorTransformMatrix); |
| 254 | |
| 255 | // The dirtyRegion should be set to the full display size |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [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 | 6a3b446 | 2019-03-07 20:58:12 -0800 | [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 | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 276 | EXPECT_EQ(ui::ColorMode::DISPLAY_P3, mOutput.getState().colorMode); |
| 277 | EXPECT_EQ(ui::Dataspace::DISPLAY_P3, mOutput.getState().dataspace); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 278 | EXPECT_EQ(ui::RenderIntent::TONE_MAP_COLORIMETRIC, mOutput.getState().renderIntent); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 279 | EXPECT_EQ(ui::Dataspace::UNKNOWN, mOutput.getState().targetDataspace); |
| 280 | |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 281 | EXPECT_THAT(mOutput.getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize))); |
| 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 | ef95812 | 2019-02-05 18:00:12 -0800 | [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; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 295 | mOutput.editState().targetDataspace = ui::Dataspace::UNKNOWN; |
Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 296 | |
Lloyd Pique | 6a3b446 | 2019-03-07 20:58:12 -0800 | [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 | |
| 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 | |
| 314 | mOutput.setRenderSurface(std::unique_ptr<RenderSurface>(renderSurface)); |
| 315 | |
| 316 | EXPECT_EQ(Rect(newDisplaySize), mOutput.getState().bounds); |
| 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}; |
| 325 | mOutput.editState().viewport = viewport; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 326 | mOutput.editState().dirtyRegion.set(50, 300); |
| 327 | |
| 328 | { |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [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}; |
| 337 | mOutput.editState().viewport = viewport; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 338 | mOutput.editState().dirtyRegion.set(50, 300); |
| 339 | |
| 340 | { |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [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.... |
| 357 | mOutput.setLayerStackFilter(layerStack1, true); |
| 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. |
| 360 | EXPECT_FALSE(mOutput.belongsInOutput(std::nullopt, false)); |
| 361 | EXPECT_FALSE(mOutput.belongsInOutput(std::nullopt, true)); |
| 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. |
| 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)); |
| 368 | |
| 369 | // If the output accepts layerStack21 but not internal-only layers... |
| 370 | mOutput.setLayerStackFilter(layerStack1, false); |
| 371 | |
| 372 | // Only non-internal layers with layerStack1 belong to it. |
| 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)); |
| 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.... |
| 389 | mOutput.setLayerStackFilter(layerStack1, true); |
| 390 | |
| 391 | // A null layer pointer does not belong to the output |
| 392 | EXPECT_FALSE(mOutput.belongsInOutput(nullptr)); |
| 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 | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 397 | EXPECT_FALSE(mOutput.belongsInOutput(&layer)); |
| 398 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame^] | 399 | layerFEState.layerStackId = std::nullopt; |
| 400 | layerFEState.internalOnly = true; |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 401 | EXPECT_FALSE(mOutput.belongsInOutput(&layer)); |
| 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 | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 406 | EXPECT_TRUE(mOutput.belongsInOutput(&layer)); |
| 407 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame^] | 408 | layerFEState.layerStackId = layerStack1; |
| 409 | layerFEState.internalOnly = true; |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 410 | EXPECT_TRUE(mOutput.belongsInOutput(&layer)); |
| 411 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame^] | 412 | layerFEState.layerStackId = layerStack2; |
| 413 | layerFEState.internalOnly = true; |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 414 | EXPECT_FALSE(mOutput.belongsInOutput(&layer)); |
| 415 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame^] | 416 | layerFEState.layerStackId = layerStack2; |
| 417 | layerFEState.internalOnly = false; |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 418 | EXPECT_FALSE(mOutput.belongsInOutput(&layer)); |
| 419 | |
| 420 | // If the output accepts layerStack1 but not internal-only layers... |
| 421 | mOutput.setLayerStackFilter(layerStack1, false); |
| 422 | |
| 423 | // A null layer pointer does not belong to the output |
| 424 | EXPECT_FALSE(mOutput.belongsInOutput(nullptr)); |
| 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 | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 429 | EXPECT_TRUE(mOutput.belongsInOutput(&layer)); |
| 430 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame^] | 431 | layerFEState.layerStackId = layerStack1; |
| 432 | layerFEState.internalOnly = true; |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 433 | EXPECT_FALSE(mOutput.belongsInOutput(&layer)); |
| 434 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame^] | 435 | layerFEState.layerStackId = layerStack2; |
| 436 | layerFEState.internalOnly = true; |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 437 | EXPECT_FALSE(mOutput.belongsInOutput(&layer)); |
| 438 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame^] | 439 | layerFEState.layerStackId = layerStack2; |
| 440 | layerFEState.internalOnly = false; |
Lloyd Pique | 66c20c4 | 2019-03-07 21:44:02 -0800 | [diff] [blame] | 441 | EXPECT_FALSE(mOutput.belongsInOutput(&layer)); |
| 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)); |
| 456 | mOutput.setOutputLayersOrderedByZ(std::move(outputLayers)); |
| 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)); |
| 463 | EXPECT_EQ(outputLayer1, mOutput.getOutputLayerForLayer(&layer)); |
| 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)); |
| 468 | EXPECT_EQ(outputLayer2, mOutput.getOutputLayerForLayer(&layer)); |
| 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)); |
| 473 | EXPECT_EQ(nullptr, mOutput.getOutputLayerForLayer(&layer)); |
| 474 | } |
| 475 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 476 | /* |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 477 | * Output::getOrCreateOutputLayer() |
| 478 | */ |
| 479 | |
| 480 | TEST_F(OutputTest, getOrCreateOutputLayerWorks) { |
| 481 | mock::OutputLayer* existingOutputLayer = new StrictMock<mock::OutputLayer>(); |
| 482 | |
| 483 | Output::OutputLayers outputLayers; |
| 484 | outputLayers.emplace_back(nullptr); |
| 485 | outputLayers.emplace_back(std::unique_ptr<OutputLayer>(existingOutputLayer)); |
| 486 | mOutput.setOutputLayersOrderedByZ(std::move(outputLayers)); |
| 487 | |
| 488 | std::shared_ptr<mock::Layer> layer{new StrictMock<mock::Layer>()}; |
| 489 | sp<LayerFE> layerFE{new StrictMock<mock::LayerFE>()}; |
| 490 | |
| 491 | StrictMock<mock::Layer> otherLayer; |
| 492 | |
| 493 | { |
| 494 | // If there is no OutputLayer corresponding to the input layer, a |
| 495 | // new OutputLayer is constructed and returned. |
| 496 | EXPECT_CALL(*existingOutputLayer, getLayer()).WillOnce(ReturnRef(otherLayer)); |
Lloyd Pique | df336d9 | 2019-03-07 21:38:42 -0800 | [diff] [blame] | 497 | auto result = mOutput.getOrCreateOutputLayer(layer, layerFE); |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 498 | EXPECT_NE(existingOutputLayer, result.get()); |
| 499 | EXPECT_TRUE(result.get() != nullptr); |
| 500 | EXPECT_EQ(layer.get(), &result->getLayer()); |
| 501 | EXPECT_EQ(layerFE.get(), &result->getLayerFE()); |
| 502 | |
| 503 | // The entries in the ordered array should be unchanged. |
| 504 | auto& outputLayers = mOutput.getOutputLayersOrderedByZ(); |
| 505 | EXPECT_EQ(nullptr, outputLayers[0].get()); |
| 506 | EXPECT_EQ(existingOutputLayer, outputLayers[1].get()); |
| 507 | } |
| 508 | |
| 509 | { |
| 510 | // If there is an existing OutputLayer for the requested layer, an owned |
| 511 | // pointer is returned |
| 512 | EXPECT_CALL(*existingOutputLayer, getLayer()).WillOnce(ReturnRef(*layer)); |
Lloyd Pique | df336d9 | 2019-03-07 21:38:42 -0800 | [diff] [blame] | 513 | auto result = mOutput.getOrCreateOutputLayer(layer, layerFE); |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 514 | EXPECT_EQ(existingOutputLayer, result.get()); |
| 515 | |
| 516 | // The corresponding entry in the ordered array should be cleared. |
| 517 | auto& outputLayers = mOutput.getOutputLayersOrderedByZ(); |
| 518 | EXPECT_EQ(nullptr, outputLayers[0].get()); |
| 519 | EXPECT_EQ(nullptr, outputLayers[1].get()); |
| 520 | } |
| 521 | } |
| 522 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 523 | /* |
| 524 | * Output::prepareFrame() |
| 525 | */ |
| 526 | |
| 527 | struct OutputPrepareFrameTest : public testing::Test { |
| 528 | struct OutputPartialMock : public impl::Output { |
| 529 | OutputPartialMock(const compositionengine::CompositionEngine& compositionEngine) |
| 530 | : impl::Output(compositionEngine) {} |
| 531 | |
| 532 | // Sets up the helper functions called by prepareFrame to use a mock |
| 533 | // implementations. |
| 534 | MOCK_METHOD0(chooseCompositionStrategy, void()); |
| 535 | }; |
| 536 | |
| 537 | OutputPrepareFrameTest() { |
| 538 | mOutput.setDisplayColorProfileForTest( |
| 539 | std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile)); |
| 540 | mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface)); |
| 541 | } |
| 542 | |
| 543 | StrictMock<mock::CompositionEngine> mCompositionEngine; |
| 544 | mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>(); |
| 545 | mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>(); |
| 546 | StrictMock<OutputPartialMock> mOutput{mCompositionEngine}; |
| 547 | }; |
| 548 | |
| 549 | TEST_F(OutputPrepareFrameTest, takesEarlyOutIfNotEnabled) { |
| 550 | mOutput.editState().isEnabled = false; |
| 551 | |
| 552 | mOutput.prepareFrame(); |
| 553 | } |
| 554 | |
| 555 | TEST_F(OutputPrepareFrameTest, delegatesToChooseCompositionStrategyAndRenderSurface) { |
| 556 | mOutput.editState().isEnabled = true; |
| 557 | mOutput.editState().usesClientComposition = false; |
| 558 | mOutput.editState().usesDeviceComposition = true; |
| 559 | |
| 560 | EXPECT_CALL(mOutput, chooseCompositionStrategy()).Times(1); |
| 561 | EXPECT_CALL(*mRenderSurface, prepareFrame(false, true)); |
| 562 | |
| 563 | mOutput.prepareFrame(); |
| 564 | } |
| 565 | |
| 566 | // Note: Use OutputTest and not OutputPrepareFrameTest, so the real |
| 567 | // base chooseCompositionStrategy() is invoked. |
| 568 | TEST_F(OutputTest, prepareFrameSetsClientCompositionOnlyByDefault) { |
| 569 | mOutput.editState().isEnabled = true; |
| 570 | mOutput.editState().usesClientComposition = false; |
| 571 | mOutput.editState().usesDeviceComposition = true; |
| 572 | |
| 573 | EXPECT_CALL(*mRenderSurface, prepareFrame(true, false)); |
| 574 | |
| 575 | mOutput.prepareFrame(); |
| 576 | |
| 577 | EXPECT_TRUE(mOutput.getState().usesClientComposition); |
| 578 | EXPECT_FALSE(mOutput.getState().usesDeviceComposition); |
| 579 | } |
| 580 | |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 581 | /* |
| 582 | * Output::composeSurfaces() |
| 583 | */ |
| 584 | |
| 585 | struct OutputComposeSurfacesTest : public testing::Test { |
| 586 | static constexpr uint32_t kDefaultOutputOrientation = TR_IDENT; |
| 587 | static constexpr ui::Dataspace kDefaultOutputDataspace = ui::Dataspace::DISPLAY_P3; |
| 588 | |
| 589 | static const Rect kDefaultOutputFrame; |
| 590 | static const Rect kDefaultOutputViewport; |
| 591 | static const Rect kDefaultOutputScissor; |
| 592 | static const mat4 kDefaultColorTransformMat; |
| 593 | |
| 594 | struct OutputPartialMock : public impl::Output { |
| 595 | OutputPartialMock(const compositionengine::CompositionEngine& compositionEngine) |
| 596 | : impl::Output(compositionEngine) {} |
| 597 | |
| 598 | // Sets up the helper functions called by composeSurfaces to use a mock |
| 599 | // implementations. |
| 600 | MOCK_CONST_METHOD0(getSkipColorTransform, bool()); |
| 601 | MOCK_METHOD2(generateClientCompositionRequests, |
| 602 | std::vector<renderengine::LayerSettings>(bool, Region&)); |
| 603 | MOCK_METHOD2(appendRegionFlashRequests, |
| 604 | void(const Region&, std::vector<renderengine::LayerSettings>&)); |
| 605 | MOCK_METHOD1(setExpensiveRenderingExpected, void(bool)); |
| 606 | }; |
| 607 | |
| 608 | OutputComposeSurfacesTest() { |
| 609 | mOutput.setDisplayColorProfileForTest( |
| 610 | std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile)); |
| 611 | mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface)); |
| 612 | |
| 613 | Output::OutputLayers outputLayers; |
| 614 | outputLayers.emplace_back(std::unique_ptr<OutputLayer>(mOutputLayer1)); |
| 615 | outputLayers.emplace_back(std::unique_ptr<OutputLayer>(mOutputLayer2)); |
| 616 | mOutput.setOutputLayersOrderedByZ(std::move(outputLayers)); |
| 617 | |
| 618 | mOutput.editState().frame = kDefaultOutputFrame; |
| 619 | mOutput.editState().viewport = kDefaultOutputViewport; |
| 620 | mOutput.editState().scissor = kDefaultOutputScissor; |
| 621 | mOutput.editState().transform = ui::Transform{kDefaultOutputOrientation}; |
| 622 | mOutput.editState().orientation = kDefaultOutputOrientation; |
| 623 | mOutput.editState().dataspace = kDefaultOutputDataspace; |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 624 | mOutput.editState().colorTransformMatrix = kDefaultColorTransformMat; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 625 | mOutput.editState().isSecure = true; |
| 626 | mOutput.editState().needsFiltering = false; |
| 627 | mOutput.editState().usesClientComposition = true; |
| 628 | mOutput.editState().usesDeviceComposition = false; |
| 629 | |
| 630 | EXPECT_CALL(mCompositionEngine, getRenderEngine()).WillRepeatedly(ReturnRef(mRenderEngine)); |
| 631 | } |
| 632 | |
| 633 | StrictMock<mock::CompositionEngine> mCompositionEngine; |
| 634 | StrictMock<renderengine::mock::RenderEngine> mRenderEngine; |
| 635 | mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>(); |
| 636 | mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>(); |
| 637 | mock::OutputLayer* mOutputLayer1 = new StrictMock<mock::OutputLayer>(); |
| 638 | mock::OutputLayer* mOutputLayer2 = new StrictMock<mock::OutputLayer>(); |
| 639 | StrictMock<OutputPartialMock> mOutput{mCompositionEngine}; |
| 640 | sp<GraphicBuffer> mOutputBuffer = new GraphicBuffer(); |
| 641 | }; |
| 642 | |
| 643 | const Rect OutputComposeSurfacesTest::kDefaultOutputFrame{1001, 1002, 1003, 1004}; |
| 644 | const Rect OutputComposeSurfacesTest::kDefaultOutputViewport{1005, 1006, 1007, 1008}; |
| 645 | const Rect OutputComposeSurfacesTest::kDefaultOutputScissor{1009, 1010, 1011, 1012}; |
| 646 | const mat4 OutputComposeSurfacesTest::kDefaultColorTransformMat{mat4() * 0.5}; |
| 647 | |
| 648 | // TODO(b/121291683): Expand unit test coverage for composeSurfaces beyond these |
| 649 | // basic tests. |
| 650 | |
| 651 | TEST_F(OutputComposeSurfacesTest, doesNothingIfNoClientComposition) { |
| 652 | mOutput.editState().usesClientComposition = false; |
| 653 | |
| 654 | Region debugRegion; |
Lloyd Pique | d3d6988 | 2019-02-28 16:03:46 -0800 | [diff] [blame] | 655 | std::optional<base::unique_fd> readyFence = mOutput.composeSurfaces(debugRegion); |
| 656 | EXPECT_TRUE(readyFence); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 657 | } |
| 658 | |
| 659 | TEST_F(OutputComposeSurfacesTest, worksIfNoClientLayersQueued) { |
| 660 | const Region kDebugRegion{Rect{100, 101, 102, 103}}; |
| 661 | |
| 662 | constexpr float kDefaultMaxLuminance = 1.0f; |
| 663 | constexpr float kDefaultAvgLuminance = 0.7f; |
| 664 | constexpr float kDefaultMinLuminance = 0.1f; |
| 665 | HdrCapabilities HdrCapabilities{{}, |
| 666 | kDefaultMaxLuminance, |
| 667 | kDefaultAvgLuminance, |
| 668 | kDefaultMinLuminance}; |
| 669 | |
| 670 | EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillOnce(Return(false)); |
| 671 | EXPECT_CALL(mRenderEngine, drawLayers(_, _, _, true, _, _)).Times(1); |
| 672 | |
| 673 | EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillOnce(Return(true)); |
| 674 | EXPECT_CALL(*mDisplayColorProfile, getHdrCapabilities()).WillOnce(ReturnRef(HdrCapabilities)); |
| 675 | |
| 676 | EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillOnce(Return(mOutputBuffer)); |
| 677 | |
| 678 | EXPECT_CALL(mOutput, getSkipColorTransform()).WillOnce(Return(false)); |
| 679 | EXPECT_CALL(mOutput, generateClientCompositionRequests(false, _)).Times(1); |
| 680 | EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _)).Times(1); |
| 681 | EXPECT_CALL(mOutput, setExpensiveRenderingExpected(true)).Times(1); |
| 682 | EXPECT_CALL(mOutput, setExpensiveRenderingExpected(false)).Times(1); |
| 683 | |
Lloyd Pique | d3d6988 | 2019-02-28 16:03:46 -0800 | [diff] [blame] | 684 | std::optional<base::unique_fd> readyFence = mOutput.composeSurfaces(kDebugRegion); |
| 685 | EXPECT_TRUE(readyFence); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 686 | } |
| 687 | |
| 688 | /* |
| 689 | * Output::generateClientCompositionRequests() |
| 690 | */ |
| 691 | |
| 692 | struct GenerateClientCompositionRequestsTest : public testing::Test { |
| 693 | struct OutputPartialMock : public impl::Output { |
| 694 | OutputPartialMock(const compositionengine::CompositionEngine& compositionEngine) |
| 695 | : impl::Output(compositionEngine) {} |
| 696 | |
| 697 | std::vector<renderengine::LayerSettings> generateClientCompositionRequests( |
| 698 | bool supportsProtectedContent, Region& clearRegion) override { |
| 699 | return impl::Output::generateClientCompositionRequests(supportsProtectedContent, |
| 700 | clearRegion); |
| 701 | } |
| 702 | }; |
| 703 | |
| 704 | GenerateClientCompositionRequestsTest() { |
| 705 | mOutput.setDisplayColorProfileForTest( |
| 706 | std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile)); |
| 707 | mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface)); |
| 708 | } |
| 709 | |
| 710 | StrictMock<mock::CompositionEngine> mCompositionEngine; |
| 711 | mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>(); |
| 712 | mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>(); |
| 713 | StrictMock<OutputPartialMock> mOutput{mCompositionEngine}; |
| 714 | }; |
| 715 | |
| 716 | // TODO(b/121291683): Add more unit test coverage for generateClientCompositionRequests |
| 717 | |
| 718 | TEST_F(GenerateClientCompositionRequestsTest, worksForLandscapeModeSplitScreen) { |
| 719 | // In split-screen landscape mode, the screen is rotated 90 degrees, with |
| 720 | // one layer on the left covering the left side of the output, and one layer |
| 721 | // on the right covering that side of the output. |
| 722 | |
| 723 | mock::OutputLayer* leftOutputLayer = new StrictMock<mock::OutputLayer>(); |
| 724 | mock::OutputLayer* rightOutputLayer = new StrictMock<mock::OutputLayer>(); |
| 725 | |
| 726 | StrictMock<mock::Layer> leftLayer; |
| 727 | StrictMock<mock::LayerFE> leftLayerFE; |
| 728 | StrictMock<mock::Layer> rightLayer; |
| 729 | StrictMock<mock::LayerFE> rightLayerFE; |
| 730 | |
| 731 | impl::OutputLayerCompositionState leftOutputLayerState; |
| 732 | leftOutputLayerState.clearClientTarget = false; |
Lloyd Pique | a246866 | 2019-03-07 21:31:06 -0800 | [diff] [blame] | 733 | leftOutputLayerState.visibleRegion = Region{Rect{0, 0, 1000, 1000}}; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 734 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame^] | 735 | LayerFECompositionState leftLayerFEState; |
| 736 | leftLayerFEState.isOpaque = true; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 737 | |
| 738 | const half3 leftLayerColor{1.f, 0.f, 0.f}; |
| 739 | renderengine::LayerSettings leftLayerRESettings; |
| 740 | leftLayerRESettings.source.solidColor = leftLayerColor; |
| 741 | |
| 742 | impl::OutputLayerCompositionState rightOutputLayerState; |
| 743 | rightOutputLayerState.clearClientTarget = false; |
Lloyd Pique | a246866 | 2019-03-07 21:31:06 -0800 | [diff] [blame] | 744 | rightOutputLayerState.visibleRegion = Region{Rect{1000, 0, 2000, 1000}}; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 745 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame^] | 746 | LayerFECompositionState rightLayerFEState; |
| 747 | rightLayerFEState.isOpaque = true; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 748 | |
| 749 | const half3 rightLayerColor{0.f, 1.f, 0.f}; |
| 750 | renderengine::LayerSettings rightLayerRESettings; |
| 751 | rightLayerRESettings.source.solidColor = rightLayerColor; |
| 752 | |
| 753 | EXPECT_CALL(*leftOutputLayer, getState()).WillRepeatedly(ReturnRef(leftOutputLayerState)); |
| 754 | EXPECT_CALL(*leftOutputLayer, getLayer()).WillRepeatedly(ReturnRef(leftLayer)); |
| 755 | EXPECT_CALL(*leftOutputLayer, getLayerFE()).WillRepeatedly(ReturnRef(leftLayerFE)); |
| 756 | EXPECT_CALL(*leftOutputLayer, requiresClientComposition()).WillRepeatedly(Return(true)); |
| 757 | EXPECT_CALL(*leftOutputLayer, needsFiltering()).WillRepeatedly(Return(false)); |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame^] | 758 | EXPECT_CALL(leftLayer, getFEState()).WillRepeatedly(ReturnRef(leftLayerFEState)); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 759 | EXPECT_CALL(leftLayerFE, prepareClientComposition(_)).WillOnce(Return(leftLayerRESettings)); |
| 760 | |
| 761 | EXPECT_CALL(*rightOutputLayer, getState()).WillRepeatedly(ReturnRef(rightOutputLayerState)); |
| 762 | EXPECT_CALL(*rightOutputLayer, getLayer()).WillRepeatedly(ReturnRef(rightLayer)); |
| 763 | EXPECT_CALL(*rightOutputLayer, getLayerFE()).WillRepeatedly(ReturnRef(rightLayerFE)); |
| 764 | EXPECT_CALL(*rightOutputLayer, requiresClientComposition()).WillRepeatedly(Return(true)); |
| 765 | EXPECT_CALL(*rightOutputLayer, needsFiltering()).WillRepeatedly(Return(false)); |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame^] | 766 | EXPECT_CALL(rightLayer, getFEState()).WillRepeatedly(ReturnRef(rightLayerFEState)); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 767 | EXPECT_CALL(rightLayerFE, prepareClientComposition(_)).WillOnce(Return(rightLayerRESettings)); |
| 768 | |
| 769 | Output::OutputLayers outputLayers; |
| 770 | outputLayers.emplace_back(std::unique_ptr<OutputLayer>(leftOutputLayer)); |
| 771 | outputLayers.emplace_back(std::unique_ptr<OutputLayer>(rightOutputLayer)); |
| 772 | mOutput.setOutputLayersOrderedByZ(std::move(outputLayers)); |
| 773 | |
| 774 | const Rect kPortraitFrame(0, 0, 1000, 2000); |
| 775 | const Rect kPortraitViewport(0, 0, 2000, 1000); |
| 776 | const Rect kPortraitScissor(0, 0, 1000, 2000); |
| 777 | const uint32_t kPortraitOrientation = TR_ROT_90; |
| 778 | |
| 779 | mOutput.editState().frame = kPortraitFrame; |
| 780 | mOutput.editState().viewport = kPortraitViewport; |
| 781 | mOutput.editState().scissor = kPortraitScissor; |
| 782 | mOutput.editState().transform = ui::Transform{kPortraitOrientation}; |
| 783 | mOutput.editState().orientation = kPortraitOrientation; |
| 784 | mOutput.editState().needsFiltering = true; |
| 785 | mOutput.editState().isSecure = false; |
| 786 | |
| 787 | constexpr bool supportsProtectedContent = false; |
| 788 | Region clearRegion; |
| 789 | auto requests = |
| 790 | mOutput.generateClientCompositionRequests(supportsProtectedContent, clearRegion); |
| 791 | |
| 792 | ASSERT_EQ(2u, requests.size()); |
| 793 | EXPECT_EQ(leftLayerColor, requests[0].source.solidColor); |
| 794 | EXPECT_EQ(rightLayerColor, requests[1].source.solidColor); |
| 795 | } |
| 796 | |
| 797 | TEST_F(GenerateClientCompositionRequestsTest, ignoresLayersThatDoNotIntersectWithViewport) { |
| 798 | // Layers whose visible region does not intersect with the viewport will be |
| 799 | // skipped when generating client composition request state. |
| 800 | |
| 801 | mock::OutputLayer* outputLayer = new StrictMock<mock::OutputLayer>(); |
| 802 | StrictMock<mock::Layer> layer; |
| 803 | StrictMock<mock::LayerFE> layerFE; |
| 804 | |
| 805 | impl::OutputLayerCompositionState outputLayerState; |
| 806 | outputLayerState.clearClientTarget = false; |
Lloyd Pique | a246866 | 2019-03-07 21:31:06 -0800 | [diff] [blame] | 807 | outputLayerState.visibleRegion = Region{Rect{3000, 0, 4000, 1000}}; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 808 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame^] | 809 | LayerFECompositionState layerFEState; |
| 810 | layerFEState.isOpaque = true; |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 811 | |
| 812 | EXPECT_CALL(*outputLayer, getState()).WillRepeatedly(ReturnRef(outputLayerState)); |
| 813 | EXPECT_CALL(*outputLayer, getLayer()).WillRepeatedly(ReturnRef(layer)); |
| 814 | EXPECT_CALL(*outputLayer, getLayerFE()).WillRepeatedly(ReturnRef(layerFE)); |
| 815 | EXPECT_CALL(*outputLayer, requiresClientComposition()).WillRepeatedly(Return(true)); |
| 816 | EXPECT_CALL(*outputLayer, needsFiltering()).WillRepeatedly(Return(false)); |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame^] | 817 | EXPECT_CALL(layer, getFEState()).WillRepeatedly(ReturnRef(layerFEState)); |
Lloyd Pique | 56eba80 | 2019-08-28 15:45:25 -0700 | [diff] [blame] | 818 | EXPECT_CALL(layerFE, prepareClientComposition(_)).Times(0); |
| 819 | |
| 820 | Output::OutputLayers outputLayers; |
| 821 | outputLayers.emplace_back(std::unique_ptr<OutputLayer>(outputLayer)); |
| 822 | mOutput.setOutputLayersOrderedByZ(std::move(outputLayers)); |
| 823 | |
| 824 | const Rect kPortraitFrame(0, 0, 1000, 2000); |
| 825 | const Rect kPortraitViewport(0, 0, 2000, 1000); |
| 826 | const Rect kPortraitScissor(0, 0, 1000, 2000); |
| 827 | const uint32_t kPortraitOrientation = TR_ROT_90; |
| 828 | |
| 829 | mOutput.editState().frame = kPortraitFrame; |
| 830 | mOutput.editState().viewport = kPortraitViewport; |
| 831 | mOutput.editState().scissor = kPortraitScissor; |
| 832 | mOutput.editState().transform = ui::Transform{kPortraitOrientation}; |
| 833 | mOutput.editState().orientation = kPortraitOrientation; |
| 834 | mOutput.editState().needsFiltering = true; |
| 835 | mOutput.editState().isSecure = false; |
| 836 | |
| 837 | constexpr bool supportsProtectedContent = false; |
| 838 | Region clearRegion; |
| 839 | auto requests = |
| 840 | mOutput.generateClientCompositionRequests(supportsProtectedContent, clearRegion); |
| 841 | |
| 842 | EXPECT_EQ(0u, requests.size()); |
| 843 | } |
| 844 | |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 845 | TEST_F(GenerateClientCompositionRequestsTest, clearsDeviceLayesAfterFirst) { |
| 846 | // If client composition is performed with some layers set to use device |
| 847 | // composition, device layers after the first layer (device or client) will |
| 848 | // clear the frame buffer if they are opaque and if that layer has a flag |
| 849 | // set to do so. The first layer is skipped as the frame buffer is already |
| 850 | // expected to be clear. |
| 851 | |
| 852 | mock::OutputLayer* leftOutputLayer = new StrictMock<mock::OutputLayer>(); |
| 853 | mock::OutputLayer* rightOutputLayer = new StrictMock<mock::OutputLayer>(); |
| 854 | |
| 855 | StrictMock<mock::Layer> leftLayer; |
| 856 | StrictMock<mock::LayerFE> leftLayerFE; |
| 857 | StrictMock<mock::Layer> rightLayer; |
| 858 | StrictMock<mock::LayerFE> rightLayerFE; |
| 859 | |
| 860 | impl::OutputLayerCompositionState leftOutputLayerState; |
| 861 | leftOutputLayerState.clearClientTarget = true; |
Lloyd Pique | a246866 | 2019-03-07 21:31:06 -0800 | [diff] [blame] | 862 | leftOutputLayerState.visibleRegion = Region{Rect{0, 0, 1000, 1000}}; |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 863 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame^] | 864 | LayerFECompositionState leftLayerFEState; |
| 865 | leftLayerFEState.isOpaque = true; |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 866 | |
| 867 | impl::OutputLayerCompositionState rightOutputLayerState; |
| 868 | rightOutputLayerState.clearClientTarget = true; |
Lloyd Pique | a246866 | 2019-03-07 21:31:06 -0800 | [diff] [blame] | 869 | rightOutputLayerState.visibleRegion = Region{Rect{1000, 0, 2000, 1000}}; |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 870 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame^] | 871 | LayerFECompositionState rightLayerFEState; |
| 872 | rightLayerFEState.isOpaque = true; |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 873 | |
| 874 | const half3 rightLayerColor{0.f, 1.f, 0.f}; |
| 875 | renderengine::LayerSettings rightLayerRESettings; |
| 876 | rightLayerRESettings.geometry.boundaries = FloatRect{456, 0, 0, 0}; |
| 877 | rightLayerRESettings.source.solidColor = rightLayerColor; |
| 878 | |
| 879 | EXPECT_CALL(*leftOutputLayer, getState()).WillRepeatedly(ReturnRef(leftOutputLayerState)); |
| 880 | EXPECT_CALL(*leftOutputLayer, getLayer()).WillRepeatedly(ReturnRef(leftLayer)); |
| 881 | EXPECT_CALL(*leftOutputLayer, getLayerFE()).WillRepeatedly(ReturnRef(leftLayerFE)); |
| 882 | EXPECT_CALL(*leftOutputLayer, requiresClientComposition()).WillRepeatedly(Return(false)); |
| 883 | EXPECT_CALL(*leftOutputLayer, needsFiltering()).WillRepeatedly(Return(false)); |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame^] | 884 | EXPECT_CALL(leftLayer, getFEState()).WillRepeatedly(ReturnRef(leftLayerFEState)); |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 885 | |
| 886 | EXPECT_CALL(*rightOutputLayer, getState()).WillRepeatedly(ReturnRef(rightOutputLayerState)); |
| 887 | EXPECT_CALL(*rightOutputLayer, getLayer()).WillRepeatedly(ReturnRef(rightLayer)); |
| 888 | EXPECT_CALL(*rightOutputLayer, getLayerFE()).WillRepeatedly(ReturnRef(rightLayerFE)); |
| 889 | EXPECT_CALL(*rightOutputLayer, requiresClientComposition()).WillRepeatedly(Return(false)); |
| 890 | EXPECT_CALL(*rightOutputLayer, needsFiltering()).WillRepeatedly(Return(false)); |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame^] | 891 | EXPECT_CALL(rightLayer, getFEState()).WillRepeatedly(ReturnRef(rightLayerFEState)); |
Lloyd Pique | c2d54d4 | 2019-08-28 18:04:21 -0700 | [diff] [blame] | 892 | EXPECT_CALL(rightLayerFE, prepareClientComposition(_)).WillOnce(Return(rightLayerRESettings)); |
| 893 | |
| 894 | Output::OutputLayers outputLayers; |
| 895 | outputLayers.emplace_back(std::unique_ptr<OutputLayer>(leftOutputLayer)); |
| 896 | outputLayers.emplace_back(std::unique_ptr<OutputLayer>(rightOutputLayer)); |
| 897 | mOutput.setOutputLayersOrderedByZ(std::move(outputLayers)); |
| 898 | |
| 899 | const Rect kPortraitFrame(0, 0, 1000, 2000); |
| 900 | const Rect kPortraitViewport(0, 0, 2000, 1000); |
| 901 | const Rect kPortraitScissor(0, 0, 1000, 2000); |
| 902 | const uint32_t kPortraitOrientation = TR_ROT_90; |
| 903 | |
| 904 | mOutput.editState().frame = kPortraitFrame; |
| 905 | mOutput.editState().viewport = kPortraitViewport; |
| 906 | mOutput.editState().scissor = kPortraitScissor; |
| 907 | mOutput.editState().transform = ui::Transform{kPortraitOrientation}; |
| 908 | mOutput.editState().orientation = kPortraitOrientation; |
| 909 | mOutput.editState().needsFiltering = true; |
| 910 | mOutput.editState().isSecure = false; |
| 911 | |
| 912 | constexpr bool supportsProtectedContent = false; |
| 913 | Region clearRegion; |
| 914 | auto requests = |
| 915 | mOutput.generateClientCompositionRequests(supportsProtectedContent, clearRegion); |
| 916 | |
| 917 | const half3 clearColor{0.f, 0.f, 0.f}; |
| 918 | |
| 919 | ASSERT_EQ(1u, requests.size()); |
| 920 | EXPECT_EQ(456.f, requests[0].geometry.boundaries.left); |
| 921 | EXPECT_EQ(clearColor, requests[0].source.solidColor); |
| 922 | } |
| 923 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 924 | } // namespace |
| 925 | } // namespace android::compositionengine |