| 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 |  | 
|  | 19 | #include <compositionengine/impl/Output.h> | 
|  | 20 | #include <compositionengine/mock/CompositionEngine.h> | 
| Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 21 | #include <compositionengine/mock/DisplayColorProfile.h> | 
| Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 22 | #include <compositionengine/mock/Layer.h> | 
|  | 23 | #include <compositionengine/mock/LayerFE.h> | 
|  | 24 | #include <compositionengine/mock/OutputLayer.h> | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 25 | #include <compositionengine/mock/RenderSurface.h> | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 26 | #include <gtest/gtest.h> | 
|  | 27 | #include <ui/Rect.h> | 
|  | 28 | #include <ui/Region.h> | 
|  | 29 |  | 
|  | 30 | #include "RegionMatcher.h" | 
|  | 31 | #include "TransformMatcher.h" | 
|  | 32 |  | 
|  | 33 | namespace android::compositionengine { | 
|  | 34 | namespace { | 
|  | 35 |  | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 36 | using testing::Return; | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 37 | using testing::ReturnRef; | 
|  | 38 | using testing::StrictMock; | 
|  | 39 |  | 
|  | 40 | class OutputTest : public testing::Test { | 
|  | 41 | public: | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 42 | OutputTest() { | 
| Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 43 | mOutput.setDisplayColorProfileForTest( | 
|  | 44 | std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile)); | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 45 | mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface)); | 
| Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 46 |  | 
|  | 47 | mOutput.editState().bounds = kDefaultDisplaySize; | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 48 | } | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 49 | ~OutputTest() override = default; | 
|  | 50 |  | 
| Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 51 | static const Rect kDefaultDisplaySize; | 
|  | 52 |  | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 53 | StrictMock<mock::CompositionEngine> mCompositionEngine; | 
| Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 54 | mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>(); | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 55 | mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>(); | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 56 | impl::Output mOutput{mCompositionEngine}; | 
|  | 57 | }; | 
|  | 58 |  | 
| Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 59 | const Rect OutputTest::kDefaultDisplaySize{100, 200}; | 
|  | 60 |  | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 61 | /* ------------------------------------------------------------------------ | 
|  | 62 | * Basic construction | 
|  | 63 | */ | 
|  | 64 |  | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 65 | TEST_F(OutputTest, canInstantiateOutput) { | 
|  | 66 | // The validation check checks each required component. | 
| Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 67 | EXPECT_CALL(*mDisplayColorProfile, isValid()).WillOnce(Return(true)); | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 68 | EXPECT_CALL(*mRenderSurface, isValid()).WillOnce(Return(true)); | 
|  | 69 |  | 
|  | 70 | EXPECT_TRUE(mOutput.isValid()); | 
|  | 71 |  | 
|  | 72 | // If we take away the required components, it is no longer valid. | 
|  | 73 | mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>()); | 
|  | 74 |  | 
| Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 75 | EXPECT_CALL(*mDisplayColorProfile, isValid()).WillOnce(Return(true)); | 
|  | 76 |  | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 77 | EXPECT_FALSE(mOutput.isValid()); | 
|  | 78 | } | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 79 |  | 
|  | 80 | /* ------------------------------------------------------------------------ | 
|  | 81 | * Output::setCompositionEnabled() | 
|  | 82 | */ | 
|  | 83 |  | 
|  | 84 | TEST_F(OutputTest, setCompositionEnabledDoesNothingIfAlreadyEnabled) { | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 85 | mOutput.editState().isEnabled = true; | 
|  | 86 |  | 
|  | 87 | mOutput.setCompositionEnabled(true); | 
|  | 88 |  | 
|  | 89 | EXPECT_TRUE(mOutput.getState().isEnabled); | 
|  | 90 | EXPECT_THAT(mOutput.getState().dirtyRegion, RegionEq(Region())); | 
|  | 91 | } | 
|  | 92 |  | 
|  | 93 | TEST_F(OutputTest, setCompositionEnabledSetsEnabledAndDirtiesEntireOutput) { | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 94 | mOutput.editState().isEnabled = false; | 
|  | 95 |  | 
|  | 96 | mOutput.setCompositionEnabled(true); | 
|  | 97 |  | 
|  | 98 | EXPECT_TRUE(mOutput.getState().isEnabled); | 
| Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 99 | EXPECT_THAT(mOutput.getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize))); | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 100 | } | 
|  | 101 |  | 
|  | 102 | TEST_F(OutputTest, setCompositionEnabledSetsDisabledAndDirtiesEntireOutput) { | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 103 | mOutput.editState().isEnabled = true; | 
|  | 104 |  | 
|  | 105 | mOutput.setCompositionEnabled(false); | 
|  | 106 |  | 
|  | 107 | EXPECT_FALSE(mOutput.getState().isEnabled); | 
| Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 108 | EXPECT_THAT(mOutput.getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize))); | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 109 | } | 
|  | 110 |  | 
|  | 111 | /* ------------------------------------------------------------------------ | 
|  | 112 | * Output::setProjection() | 
|  | 113 | */ | 
|  | 114 |  | 
|  | 115 | TEST_F(OutputTest, setProjectionTriviallyWorks) { | 
|  | 116 | const ui::Transform transform{ui::Transform::ROT_180}; | 
|  | 117 | const int32_t orientation = 123; | 
|  | 118 | const Rect frame{1, 2, 3, 4}; | 
|  | 119 | const Rect viewport{5, 6, 7, 8}; | 
|  | 120 | const Rect scissor{9, 10, 11, 12}; | 
|  | 121 | const bool needsFiltering = true; | 
|  | 122 |  | 
|  | 123 | mOutput.setProjection(transform, orientation, frame, viewport, scissor, needsFiltering); | 
|  | 124 |  | 
|  | 125 | EXPECT_THAT(mOutput.getState().transform, TransformEq(transform)); | 
|  | 126 | EXPECT_EQ(orientation, mOutput.getState().orientation); | 
|  | 127 | EXPECT_EQ(frame, mOutput.getState().frame); | 
|  | 128 | EXPECT_EQ(viewport, mOutput.getState().viewport); | 
|  | 129 | EXPECT_EQ(scissor, mOutput.getState().scissor); | 
|  | 130 | EXPECT_EQ(needsFiltering, mOutput.getState().needsFiltering); | 
|  | 131 | } | 
|  | 132 |  | 
|  | 133 | /* ------------------------------------------------------------------------ | 
|  | 134 | * Output::setBounds() | 
|  | 135 | */ | 
|  | 136 |  | 
|  | 137 | TEST_F(OutputTest, setBoundsSetsSizeAndDirtiesEntireOutput) { | 
| Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 138 | const ui::Size displaySize{200, 400}; | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 139 |  | 
|  | 140 | EXPECT_CALL(*mRenderSurface, setDisplaySize(displaySize)).Times(1); | 
|  | 141 | EXPECT_CALL(*mRenderSurface, getSize()).WillOnce(ReturnRef(displaySize)); | 
|  | 142 |  | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 143 | mOutput.setBounds(displaySize); | 
|  | 144 |  | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 145 | EXPECT_EQ(Rect(displaySize), mOutput.getState().bounds); | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 146 |  | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 147 | EXPECT_THAT(mOutput.getState().dirtyRegion, RegionEq(Region(Rect(displaySize)))); | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 148 | } | 
|  | 149 |  | 
|  | 150 | /* ------------------------------------------------------------------------ | 
|  | 151 | * Output::setLayerStackFilter() | 
|  | 152 | */ | 
|  | 153 |  | 
|  | 154 | TEST_F(OutputTest, setLayerStackFilterSetsFilterAndDirtiesEntireOutput) { | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 155 | const uint32_t layerStack = 123u; | 
| Lloyd Pique | ef36b00 | 2019-01-23 17:52:04 -0800 | [diff] [blame] | 156 | mOutput.setLayerStackFilter(layerStack, true); | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 157 |  | 
| Lloyd Pique | ef36b00 | 2019-01-23 17:52:04 -0800 | [diff] [blame] | 158 | EXPECT_TRUE(mOutput.getState().layerStackInternal); | 
|  | 159 | EXPECT_EQ(layerStack, mOutput.getState().layerStackId); | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 160 |  | 
| Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 161 | EXPECT_THAT(mOutput.getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize))); | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 162 | } | 
|  | 163 |  | 
|  | 164 | /* ------------------------------------------------------------------------ | 
|  | 165 | * Output::setColorTransform | 
|  | 166 | */ | 
|  | 167 |  | 
|  | 168 | TEST_F(OutputTest, setColorTransformSetsTransform) { | 
|  | 169 | // Identity matrix sets an identity state value | 
|  | 170 | const mat4 identity; | 
|  | 171 |  | 
|  | 172 | mOutput.setColorTransform(identity); | 
|  | 173 |  | 
|  | 174 | EXPECT_EQ(HAL_COLOR_TRANSFORM_IDENTITY, mOutput.getState().colorTransform); | 
| Lloyd Pique | 77f79a2 | 2019-04-29 15:55:40 -0700 | [diff] [blame] | 175 | EXPECT_EQ(identity, mOutput.getState().colorTransformMat); | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 176 |  | 
| Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 177 | // Since identity is the default, the dirty region should be unchanged (empty) | 
|  | 178 | EXPECT_THAT(mOutput.getState().dirtyRegion, RegionEq(Region())); | 
|  | 179 |  | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 180 | // Non-identity matrix sets a non-identity state value | 
| Lloyd Pique | 77f79a2 | 2019-04-29 15:55:40 -0700 | [diff] [blame] | 181 | const mat4 nonIdentityHalf = mat4() * 0.5; | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 182 |  | 
| Lloyd Pique | 77f79a2 | 2019-04-29 15:55:40 -0700 | [diff] [blame] | 183 | mOutput.setColorTransform(nonIdentityHalf); | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 184 |  | 
|  | 185 | EXPECT_EQ(HAL_COLOR_TRANSFORM_ARBITRARY_MATRIX, mOutput.getState().colorTransform); | 
| Lloyd Pique | 77f79a2 | 2019-04-29 15:55:40 -0700 | [diff] [blame] | 186 | EXPECT_EQ(nonIdentityHalf, mOutput.getState().colorTransformMat); | 
|  | 187 |  | 
|  | 188 | // Since this is a state change, the entire output should now be dirty. | 
|  | 189 | EXPECT_THAT(mOutput.getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize))); | 
|  | 190 |  | 
|  | 191 | // Non-identity matrix sets a non-identity state value | 
|  | 192 | const mat4 nonIdentityQuarter = mat4() * 0.25; | 
|  | 193 |  | 
|  | 194 | mOutput.setColorTransform(nonIdentityQuarter); | 
|  | 195 |  | 
|  | 196 | EXPECT_EQ(HAL_COLOR_TRANSFORM_ARBITRARY_MATRIX, mOutput.getState().colorTransform); | 
|  | 197 | EXPECT_EQ(nonIdentityQuarter, mOutput.getState().colorTransformMat); | 
| Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 198 |  | 
|  | 199 | // Since this is a state change, the entire output should now be dirty. | 
|  | 200 | EXPECT_THAT(mOutput.getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize))); | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 201 | } | 
|  | 202 |  | 
|  | 203 | /* ------------------------------------------------------------------------ | 
|  | 204 | * Output::setColorMode | 
|  | 205 | */ | 
|  | 206 |  | 
| Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 207 | TEST_F(OutputTest, setColorModeSetsStateAndDirtiesOutputIfChanged) { | 
| Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 208 | EXPECT_CALL(*mDisplayColorProfile, | 
|  | 209 | getTargetDataspace(ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3, | 
|  | 210 | ui::Dataspace::UNKNOWN)) | 
|  | 211 | .WillOnce(Return(ui::Dataspace::UNKNOWN)); | 
| Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 212 | EXPECT_CALL(*mRenderSurface, setBufferDataspace(ui::Dataspace::DISPLAY_P3)).Times(1); | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 213 |  | 
| Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 214 | mOutput.setColorMode(ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3, | 
| Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 215 | ui::RenderIntent::TONE_MAP_COLORIMETRIC, ui::Dataspace::UNKNOWN); | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 216 |  | 
| Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 217 | EXPECT_EQ(ui::ColorMode::DISPLAY_P3, mOutput.getState().colorMode); | 
|  | 218 | EXPECT_EQ(ui::Dataspace::DISPLAY_P3, mOutput.getState().dataspace); | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 219 | EXPECT_EQ(ui::RenderIntent::TONE_MAP_COLORIMETRIC, mOutput.getState().renderIntent); | 
| Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 220 | EXPECT_EQ(ui::Dataspace::UNKNOWN, mOutput.getState().targetDataspace); | 
|  | 221 |  | 
| Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 222 | EXPECT_THAT(mOutput.getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize))); | 
|  | 223 | } | 
|  | 224 |  | 
|  | 225 | TEST_F(OutputTest, setColorModeDoesNothingIfNoChange) { | 
| Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 226 | EXPECT_CALL(*mDisplayColorProfile, | 
|  | 227 | getTargetDataspace(ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3, | 
|  | 228 | ui::Dataspace::UNKNOWN)) | 
|  | 229 | .WillOnce(Return(ui::Dataspace::UNKNOWN)); | 
|  | 230 |  | 
| Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 231 | mOutput.editState().colorMode = ui::ColorMode::DISPLAY_P3; | 
|  | 232 | mOutput.editState().dataspace = ui::Dataspace::DISPLAY_P3; | 
|  | 233 | mOutput.editState().renderIntent = ui::RenderIntent::TONE_MAP_COLORIMETRIC; | 
| Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 234 | mOutput.editState().targetDataspace = ui::Dataspace::UNKNOWN; | 
| Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 235 |  | 
|  | 236 | mOutput.setColorMode(ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3, | 
| Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 237 | ui::RenderIntent::TONE_MAP_COLORIMETRIC, ui::Dataspace::UNKNOWN); | 
| Lloyd Pique | ef95812 | 2019-02-05 18:00:12 -0800 | [diff] [blame] | 238 |  | 
|  | 239 | EXPECT_THAT(mOutput.getState().dirtyRegion, RegionEq(Region())); | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 240 | } | 
|  | 241 |  | 
|  | 242 | /* ------------------------------------------------------------------------ | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 243 | * Output::setRenderSurface() | 
|  | 244 | */ | 
|  | 245 |  | 
|  | 246 | TEST_F(OutputTest, setRenderSurfaceResetsBounds) { | 
|  | 247 | const ui::Size newDisplaySize{640, 480}; | 
|  | 248 |  | 
|  | 249 | mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>(); | 
|  | 250 | EXPECT_CALL(*renderSurface, getSize()).WillOnce(ReturnRef(newDisplaySize)); | 
|  | 251 |  | 
|  | 252 | mOutput.setRenderSurface(std::unique_ptr<RenderSurface>(renderSurface)); | 
|  | 253 |  | 
|  | 254 | EXPECT_EQ(Rect(newDisplaySize), mOutput.getState().bounds); | 
|  | 255 | } | 
|  | 256 |  | 
|  | 257 | /* ------------------------------------------------------------------------ | 
| Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 258 | * Output::getDirtyRegion() | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 259 | */ | 
|  | 260 |  | 
| Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 261 | TEST_F(OutputTest, getDirtyRegionWithRepaintEverythingTrue) { | 
|  | 262 | const Rect viewport{100, 200}; | 
|  | 263 | mOutput.editState().viewport = viewport; | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 264 | mOutput.editState().dirtyRegion.set(50, 300); | 
|  | 265 |  | 
|  | 266 | { | 
| Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 267 | Region result = mOutput.getDirtyRegion(true); | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 268 |  | 
| Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 269 | EXPECT_THAT(result, RegionEq(Region(viewport))); | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 270 | } | 
|  | 271 | } | 
|  | 272 |  | 
| Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 273 | TEST_F(OutputTest, getDirtyRegionWithRepaintEverythingFalse) { | 
|  | 274 | const Rect viewport{100, 200}; | 
|  | 275 | mOutput.editState().viewport = viewport; | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 276 | mOutput.editState().dirtyRegion.set(50, 300); | 
|  | 277 |  | 
|  | 278 | { | 
| Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 279 | Region result = mOutput.getDirtyRegion(false); | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 280 |  | 
|  | 281 | // The dirtyRegion should be clipped to the display bounds. | 
|  | 282 | EXPECT_THAT(result, RegionEq(Region(Rect(50, 200)))); | 
|  | 283 | } | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 284 | } | 
|  | 285 |  | 
| Lloyd Pique | ef36b00 | 2019-01-23 17:52:04 -0800 | [diff] [blame] | 286 | /* ------------------------------------------------------------------------ | 
|  | 287 | * Output::belongsInOutput() | 
|  | 288 | */ | 
|  | 289 |  | 
|  | 290 | TEST_F(OutputTest, belongsInOutputFiltersAsExpected) { | 
|  | 291 | const uint32_t layerStack1 = 123u; | 
|  | 292 | const uint32_t layerStack2 = 456u; | 
|  | 293 |  | 
|  | 294 | // If the output accepts layerStack1 and internal-only layers.... | 
|  | 295 | mOutput.setLayerStackFilter(layerStack1, true); | 
|  | 296 |  | 
|  | 297 | // Any layer with layerStack1 belongs to it, internal-only or not. | 
|  | 298 | EXPECT_TRUE(mOutput.belongsInOutput(layerStack1, false)); | 
|  | 299 | EXPECT_TRUE(mOutput.belongsInOutput(layerStack1, true)); | 
|  | 300 | EXPECT_FALSE(mOutput.belongsInOutput(layerStack2, true)); | 
|  | 301 | EXPECT_FALSE(mOutput.belongsInOutput(layerStack2, false)); | 
|  | 302 |  | 
|  | 303 | // If the output accepts layerStack21 but not internal-only layers... | 
|  | 304 | mOutput.setLayerStackFilter(layerStack1, false); | 
|  | 305 |  | 
|  | 306 | // Only non-internal layers with layerStack1 belong to it. | 
|  | 307 | EXPECT_TRUE(mOutput.belongsInOutput(layerStack1, false)); | 
|  | 308 | EXPECT_FALSE(mOutput.belongsInOutput(layerStack1, true)); | 
|  | 309 | EXPECT_FALSE(mOutput.belongsInOutput(layerStack2, true)); | 
|  | 310 | EXPECT_FALSE(mOutput.belongsInOutput(layerStack2, false)); | 
|  | 311 | } | 
|  | 312 |  | 
| Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 313 | /* ------------------------------------------------------------------------ | 
|  | 314 | * Output::getOutputLayerForLayer() | 
|  | 315 | */ | 
|  | 316 |  | 
|  | 317 | TEST_F(OutputTest, getOutputLayerForLayerWorks) { | 
|  | 318 | mock::OutputLayer* outputLayer1 = new StrictMock<mock::OutputLayer>(); | 
|  | 319 | mock::OutputLayer* outputLayer2 = new StrictMock<mock::OutputLayer>(); | 
|  | 320 |  | 
|  | 321 | Output::OutputLayers outputLayers; | 
|  | 322 | outputLayers.emplace_back(std::unique_ptr<OutputLayer>(outputLayer1)); | 
|  | 323 | outputLayers.emplace_back(nullptr); | 
|  | 324 | outputLayers.emplace_back(std::unique_ptr<OutputLayer>(outputLayer2)); | 
|  | 325 | mOutput.setOutputLayersOrderedByZ(std::move(outputLayers)); | 
|  | 326 |  | 
|  | 327 | StrictMock<mock::Layer> layer; | 
|  | 328 | StrictMock<mock::Layer> otherLayer; | 
|  | 329 |  | 
|  | 330 | // If the input layer matches the first OutputLayer, it will be returned. | 
|  | 331 | EXPECT_CALL(*outputLayer1, getLayer()).WillOnce(ReturnRef(layer)); | 
|  | 332 | EXPECT_EQ(outputLayer1, mOutput.getOutputLayerForLayer(&layer)); | 
|  | 333 |  | 
|  | 334 | // If the input layer matches the second OutputLayer, it will be returned. | 
|  | 335 | EXPECT_CALL(*outputLayer1, getLayer()).WillOnce(ReturnRef(otherLayer)); | 
|  | 336 | EXPECT_CALL(*outputLayer2, getLayer()).WillOnce(ReturnRef(layer)); | 
|  | 337 | EXPECT_EQ(outputLayer2, mOutput.getOutputLayerForLayer(&layer)); | 
|  | 338 |  | 
|  | 339 | // If the input layer does not match an output layer, null will be returned. | 
|  | 340 | EXPECT_CALL(*outputLayer1, getLayer()).WillOnce(ReturnRef(otherLayer)); | 
|  | 341 | EXPECT_CALL(*outputLayer2, getLayer()).WillOnce(ReturnRef(otherLayer)); | 
|  | 342 | EXPECT_EQ(nullptr, mOutput.getOutputLayerForLayer(&layer)); | 
|  | 343 | } | 
|  | 344 |  | 
|  | 345 | /* ------------------------------------------------------------------------ | 
|  | 346 | * Output::getOrCreateOutputLayer() | 
|  | 347 | */ | 
|  | 348 |  | 
|  | 349 | TEST_F(OutputTest, getOrCreateOutputLayerWorks) { | 
|  | 350 | mock::OutputLayer* existingOutputLayer = new StrictMock<mock::OutputLayer>(); | 
|  | 351 |  | 
|  | 352 | Output::OutputLayers outputLayers; | 
|  | 353 | outputLayers.emplace_back(nullptr); | 
|  | 354 | outputLayers.emplace_back(std::unique_ptr<OutputLayer>(existingOutputLayer)); | 
|  | 355 | mOutput.setOutputLayersOrderedByZ(std::move(outputLayers)); | 
|  | 356 |  | 
|  | 357 | std::shared_ptr<mock::Layer> layer{new StrictMock<mock::Layer>()}; | 
|  | 358 | sp<LayerFE> layerFE{new StrictMock<mock::LayerFE>()}; | 
|  | 359 |  | 
|  | 360 | StrictMock<mock::Layer> otherLayer; | 
|  | 361 |  | 
|  | 362 | { | 
|  | 363 | // If there is no OutputLayer corresponding to the input layer, a | 
|  | 364 | // new OutputLayer is constructed and returned. | 
|  | 365 | EXPECT_CALL(*existingOutputLayer, getLayer()).WillOnce(ReturnRef(otherLayer)); | 
| Lloyd Pique | 07e3321 | 2018-12-18 16:33:37 -0800 | [diff] [blame] | 366 | auto result = mOutput.getOrCreateOutputLayer(std::nullopt, layer, layerFE); | 
| Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 367 | EXPECT_NE(existingOutputLayer, result.get()); | 
|  | 368 | EXPECT_TRUE(result.get() != nullptr); | 
|  | 369 | EXPECT_EQ(layer.get(), &result->getLayer()); | 
|  | 370 | EXPECT_EQ(layerFE.get(), &result->getLayerFE()); | 
|  | 371 |  | 
|  | 372 | // The entries in the ordered array should be unchanged. | 
|  | 373 | auto& outputLayers = mOutput.getOutputLayersOrderedByZ(); | 
|  | 374 | EXPECT_EQ(nullptr, outputLayers[0].get()); | 
|  | 375 | EXPECT_EQ(existingOutputLayer, outputLayers[1].get()); | 
|  | 376 | } | 
|  | 377 |  | 
|  | 378 | { | 
|  | 379 | // If there is an existing OutputLayer for the requested layer, an owned | 
|  | 380 | // pointer is returned | 
|  | 381 | EXPECT_CALL(*existingOutputLayer, getLayer()).WillOnce(ReturnRef(*layer)); | 
| Lloyd Pique | 07e3321 | 2018-12-18 16:33:37 -0800 | [diff] [blame] | 382 | auto result = mOutput.getOrCreateOutputLayer(std::nullopt, layer, layerFE); | 
| Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 383 | EXPECT_EQ(existingOutputLayer, result.get()); | 
|  | 384 |  | 
|  | 385 | // The corresponding entry in the ordered array should be cleared. | 
|  | 386 | auto& outputLayers = mOutput.getOutputLayersOrderedByZ(); | 
|  | 387 | EXPECT_EQ(nullptr, outputLayers[0].get()); | 
|  | 388 | EXPECT_EQ(nullptr, outputLayers[1].get()); | 
|  | 389 | } | 
|  | 390 | } | 
|  | 391 |  | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 392 | } // namespace | 
|  | 393 | } // namespace android::compositionengine |