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