blob: 5f0b0eea1539d05df281fc3e1e99d12913e5a3c5 [file] [log] [blame]
Lloyd Pique32cbe282018-10-19 13:09:22 -07001/*
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
Alec Mouri617752f2021-04-15 16:27:01 +000017#include <cmath>
18
Lloyd Pique17ca7422019-11-14 14:24:10 -080019#include <android-base/stringprintf.h>
Lloyd Pique9755fb72019-03-26 14:44:40 -070020#include <compositionengine/LayerFECompositionState.h>
Lloyd Pique32cbe282018-10-19 13:09:22 -070021#include <compositionengine/impl/Output.h>
Lloyd Pique66d68602019-02-13 14:23:31 -080022#include <compositionengine/impl/OutputCompositionState.h>
Lloyd Pique56eba802019-08-28 15:45:25 -070023#include <compositionengine/impl/OutputLayerCompositionState.h>
Lloyd Pique32cbe282018-10-19 13:09:22 -070024#include <compositionengine/mock/CompositionEngine.h>
Lloyd Pique3d0c02e2018-10-19 18:38:12 -070025#include <compositionengine/mock/DisplayColorProfile.h>
Lloyd Piquecc01a452018-12-04 17:24:00 -080026#include <compositionengine/mock/LayerFE.h>
27#include <compositionengine/mock/OutputLayer.h>
Lloyd Pique31cb2942018-10-19 17:23:03 -070028#include <compositionengine/mock/RenderSurface.h>
Lloyd Pique32cbe282018-10-19 13:09:22 -070029#include <gtest/gtest.h>
Lloyd Pique56eba802019-08-28 15:45:25 -070030#include <renderengine/mock/RenderEngine.h>
Lloyd Pique32cbe282018-10-19 13:09:22 -070031#include <ui/Rect.h>
32#include <ui/Region.h>
33
Lloyd Pique17ca7422019-11-14 14:24:10 -080034#include "CallOrderStateMachineHelper.h"
Lloyd Pique07178e32019-11-19 19:15:26 -080035#include "MockHWC2.h"
Lloyd Pique32cbe282018-10-19 13:09:22 -070036#include "RegionMatcher.h"
Lloyd Pique32cbe282018-10-19 13:09:22 -070037
38namespace android::compositionengine {
39namespace {
40
Lloyd Pique56eba802019-08-28 15:45:25 -070041using testing::_;
Lloyd Pique03561a62019-11-19 18:34:52 -080042using testing::ByMove;
Lloyd Piquea4863342019-12-04 18:45:02 -080043using testing::ByRef;
Lloyd Pique17ca7422019-11-14 14:24:10 -080044using testing::DoAll;
Vishnu Nair9b079a22020-01-21 14:36:08 -080045using testing::ElementsAre;
Lloyd Pique6818fa52019-12-03 12:32:13 -080046using testing::ElementsAreArray;
Lloyd Pique07178e32019-11-19 19:15:26 -080047using testing::Eq;
Lloyd Piquefaa3f192019-11-14 14:05:09 -080048using testing::InSequence;
Lloyd Pique6818fa52019-12-03 12:32:13 -080049using testing::Invoke;
50using testing::IsEmpty;
Lloyd Pique17ca7422019-11-14 14:24:10 -080051using testing::Mock;
Vishnu Nair9b079a22020-01-21 14:36:08 -080052using testing::Pointee;
Lloyd Pique07178e32019-11-19 19:15:26 -080053using testing::Property;
Lloyd Piquefaa3f192019-11-14 14:05:09 -080054using testing::Ref;
Lloyd Pique31cb2942018-10-19 17:23:03 -070055using testing::Return;
Lloyd Pique32cbe282018-10-19 13:09:22 -070056using testing::ReturnRef;
Lloyd Pique17ca7422019-11-14 14:24:10 -080057using testing::SetArgPointee;
Lloyd Pique32cbe282018-10-19 13:09:22 -070058using testing::StrictMock;
59
Lloyd Pique56eba802019-08-28 15:45:25 -070060constexpr auto TR_IDENT = 0u;
61constexpr auto TR_ROT_90 = HAL_TRANSFORM_ROT_90;
Vishnu Nair9b079a22020-01-21 14:36:08 -080062constexpr auto MAX_CLIENT_COMPOSITION_CACHE_SIZE = 3;
Lloyd Pique56eba802019-08-28 15:45:25 -070063
Lloyd Pique3eb1b212019-03-07 21:15:40 -080064const mat4 kIdentity;
Lloyd Pique0a456232020-01-16 17:51:13 -080065const mat4 kNonIdentityHalf = mat4() * 0.5f;
66const mat4 kNonIdentityQuarter = mat4() * 0.25f;
Lloyd Pique3eb1b212019-03-07 21:15:40 -080067
Lloyd Pique17ca7422019-11-14 14:24:10 -080068constexpr OutputColorSetting kVendorSpecifiedOutputColorSetting =
69 static_cast<OutputColorSetting>(0x100);
70
Lloyd Piquefaa3f192019-11-14 14:05:09 -080071struct OutputPartialMockBase : public impl::Output {
72 // compositionengine::Output overrides
73 const OutputCompositionState& getState() const override { return mState; }
74 OutputCompositionState& editState() override { return mState; }
75
76 // Use mocks for all the remaining virtual functions
77 // not implemented by the base implementation class.
78 MOCK_CONST_METHOD0(getOutputLayerCount, size_t());
79 MOCK_CONST_METHOD1(getOutputLayerOrderedByZByIndex, compositionengine::OutputLayer*(size_t));
Lloyd Piquede196652020-01-22 17:29:58 -080080 MOCK_METHOD2(ensureOutputLayer,
81 compositionengine::OutputLayer*(std::optional<size_t>, const sp<LayerFE>&));
Lloyd Piquefaa3f192019-11-14 14:05:09 -080082 MOCK_METHOD0(finalizePendingOutputLayers, void());
83 MOCK_METHOD0(clearOutputLayers, void());
84 MOCK_CONST_METHOD1(dumpState, void(std::string&));
85 MOCK_CONST_METHOD0(getCompositionEngine, const CompositionEngine&());
Lloyd Piquede196652020-01-22 17:29:58 -080086 MOCK_METHOD1(injectOutputLayerForTest, compositionengine::OutputLayer*(const sp<LayerFE>&));
Lloyd Piquefaa3f192019-11-14 14:05:09 -080087 MOCK_METHOD1(injectOutputLayerForTest, void(std::unique_ptr<OutputLayer>));
88
89 impl::OutputCompositionState mState;
90};
91
Lloyd Piquede196652020-01-22 17:29:58 -080092struct InjectedLayer {
93 InjectedLayer() {
94 EXPECT_CALL(*outputLayer, getLayerFE()).WillRepeatedly(ReturnRef(*layerFE.get()));
95 EXPECT_CALL(*outputLayer, getState()).WillRepeatedly(ReturnRef(outputLayerState));
96 EXPECT_CALL(*outputLayer, editState()).WillRepeatedly(ReturnRef(outputLayerState));
97
98 EXPECT_CALL(*layerFE, getCompositionState()).WillRepeatedly(Return(&layerFEState));
Dan Stoza269dc4d2021-01-15 15:07:43 -080099 EXPECT_CALL(*layerFE, getSequence()).WillRepeatedly(Return(0));
100 EXPECT_CALL(*layerFE, getDebugName()).WillRepeatedly(Return("InjectedLayer"));
Lloyd Piquede196652020-01-22 17:29:58 -0800101 }
102
103 mock::OutputLayer* outputLayer = {new StrictMock<mock::OutputLayer>};
104 sp<StrictMock<mock::LayerFE>> layerFE = new StrictMock<mock::LayerFE>();
105 LayerFECompositionState layerFEState;
106 impl::OutputLayerCompositionState outputLayerState;
107};
108
109struct NonInjectedLayer {
110 NonInjectedLayer() {
111 EXPECT_CALL(outputLayer, getLayerFE()).WillRepeatedly(ReturnRef(*layerFE.get()));
112 EXPECT_CALL(outputLayer, getState()).WillRepeatedly(ReturnRef(outputLayerState));
113 EXPECT_CALL(outputLayer, editState()).WillRepeatedly(ReturnRef(outputLayerState));
114
115 EXPECT_CALL(*layerFE, getCompositionState()).WillRepeatedly(Return(&layerFEState));
Dan Stoza269dc4d2021-01-15 15:07:43 -0800116 EXPECT_CALL(*layerFE, getSequence()).WillRepeatedly(Return(0));
117 EXPECT_CALL(*layerFE, getDebugName()).WillRepeatedly(Return("NonInjectedLayer"));
Lloyd Piquede196652020-01-22 17:29:58 -0800118 }
119
120 mock::OutputLayer outputLayer;
121 sp<StrictMock<mock::LayerFE>> layerFE = new StrictMock<mock::LayerFE>();
122 LayerFECompositionState layerFEState;
123 impl::OutputLayerCompositionState outputLayerState;
124};
125
Lloyd Pique66d68602019-02-13 14:23:31 -0800126struct OutputTest : public testing::Test {
Lloyd Pique01c77c12019-04-17 12:48:32 -0700127 class Output : public impl::Output {
128 public:
129 using impl::Output::injectOutputLayerForTest;
130 virtual void injectOutputLayerForTest(std::unique_ptr<compositionengine::OutputLayer>) = 0;
131 };
132
133 static std::shared_ptr<Output> createOutput(
134 const compositionengine::CompositionEngine& compositionEngine) {
135 return impl::createOutputTemplated<Output>(compositionEngine);
136 }
137
Lloyd Pique31cb2942018-10-19 17:23:03 -0700138 OutputTest() {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700139 mOutput->setDisplayColorProfileForTest(
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700140 std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile));
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700141 mOutput->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
Lloyd Piqueef958122019-02-05 18:00:12 -0800142
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200143 mOutput->editState().displaySpace.bounds = kDefaultDisplaySize;
Lloyd Pique31cb2942018-10-19 17:23:03 -0700144 }
Lloyd Pique32cbe282018-10-19 13:09:22 -0700145
Lloyd Piquede196652020-01-22 17:29:58 -0800146 void injectOutputLayer(InjectedLayer& layer) {
147 mOutput->injectOutputLayerForTest(std::unique_ptr<OutputLayer>(layer.outputLayer));
148 }
149
150 void injectNullOutputLayer() {
151 mOutput->injectOutputLayerForTest(std::unique_ptr<OutputLayer>(nullptr));
152 }
153
Lloyd Piqueef958122019-02-05 18:00:12 -0800154 static const Rect kDefaultDisplaySize;
155
Lloyd Pique32cbe282018-10-19 13:09:22 -0700156 StrictMock<mock::CompositionEngine> mCompositionEngine;
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700157 mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>();
Lloyd Pique31cb2942018-10-19 17:23:03 -0700158 mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>();
Lloyd Pique01c77c12019-04-17 12:48:32 -0700159 std::shared_ptr<Output> mOutput = createOutput(mCompositionEngine);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700160};
161
Lloyd Piqueef958122019-02-05 18:00:12 -0800162const Rect OutputTest::kDefaultDisplaySize{100, 200};
163
Lloyd Pique17ca7422019-11-14 14:24:10 -0800164using ColorProfile = compositionengine::Output::ColorProfile;
165
166void dumpColorProfile(ColorProfile profile, std::string& result, const char* name) {
167 android::base::StringAppendF(&result, "%s (%s[%d] %s[%d] %s[%d] %s[%d]) ", name,
168 toString(profile.mode).c_str(), profile.mode,
169 toString(profile.dataspace).c_str(), profile.dataspace,
170 toString(profile.renderIntent).c_str(), profile.renderIntent,
171 toString(profile.colorSpaceAgnosticDataspace).c_str(),
172 profile.colorSpaceAgnosticDataspace);
173}
174
175// Checks for a ColorProfile match
176MATCHER_P(ColorProfileEq, expected, "") {
177 std::string buf;
178 buf.append("ColorProfiles are not equal\n");
179 dumpColorProfile(expected, buf, "expected value");
180 dumpColorProfile(arg, buf, "actual value");
181 *result_listener << buf;
182
183 return (expected.mode == arg.mode) && (expected.dataspace == arg.dataspace) &&
184 (expected.renderIntent == arg.renderIntent) &&
185 (expected.colorSpaceAgnosticDataspace == arg.colorSpaceAgnosticDataspace);
186}
187
Lloyd Pique66d68602019-02-13 14:23:31 -0800188/*
Lloyd Pique32cbe282018-10-19 13:09:22 -0700189 * Basic construction
190 */
191
Lloyd Pique31cb2942018-10-19 17:23:03 -0700192TEST_F(OutputTest, canInstantiateOutput) {
193 // The validation check checks each required component.
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700194 EXPECT_CALL(*mDisplayColorProfile, isValid()).WillOnce(Return(true));
Lloyd Pique31cb2942018-10-19 17:23:03 -0700195 EXPECT_CALL(*mRenderSurface, isValid()).WillOnce(Return(true));
196
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700197 EXPECT_TRUE(mOutput->isValid());
Lloyd Pique31cb2942018-10-19 17:23:03 -0700198
199 // If we take away the required components, it is no longer valid.
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700200 mOutput->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>());
Lloyd Pique31cb2942018-10-19 17:23:03 -0700201
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700202 EXPECT_CALL(*mDisplayColorProfile, isValid()).WillOnce(Return(true));
203
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700204 EXPECT_FALSE(mOutput->isValid());
Lloyd Pique31cb2942018-10-19 17:23:03 -0700205}
Lloyd Pique32cbe282018-10-19 13:09:22 -0700206
Lloyd Pique66d68602019-02-13 14:23:31 -0800207/*
Lloyd Pique32cbe282018-10-19 13:09:22 -0700208 * Output::setCompositionEnabled()
209 */
210
211TEST_F(OutputTest, setCompositionEnabledDoesNothingIfAlreadyEnabled) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700212 mOutput->editState().isEnabled = true;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700213
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700214 mOutput->setCompositionEnabled(true);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700215
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700216 EXPECT_TRUE(mOutput->getState().isEnabled);
217 EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region()));
Lloyd Pique32cbe282018-10-19 13:09:22 -0700218}
219
220TEST_F(OutputTest, setCompositionEnabledSetsEnabledAndDirtiesEntireOutput) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700221 mOutput->editState().isEnabled = false;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700222
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700223 mOutput->setCompositionEnabled(true);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700224
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700225 EXPECT_TRUE(mOutput->getState().isEnabled);
226 EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize)));
Lloyd Pique32cbe282018-10-19 13:09:22 -0700227}
228
229TEST_F(OutputTest, setCompositionEnabledSetsDisabledAndDirtiesEntireOutput) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700230 mOutput->editState().isEnabled = true;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700231
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700232 mOutput->setCompositionEnabled(false);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700233
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700234 EXPECT_FALSE(mOutput->getState().isEnabled);
235 EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize)));
Lloyd Pique32cbe282018-10-19 13:09:22 -0700236}
237
Lloyd Pique66d68602019-02-13 14:23:31 -0800238/*
Lloyd Pique32cbe282018-10-19 13:09:22 -0700239 * Output::setProjection()
240 */
241
Marin Shalamanov209ae612020-10-01 00:17:39 +0200242TEST_F(OutputTest, setProjectionWorks) {
243 const Rect displayRect{0, 0, 1000, 2000};
244 mOutput->editState().displaySpace.bounds = displayRect;
245 mOutput->editState().framebufferSpace.bounds = displayRect;
246
Marin Shalamanov68933fb2020-09-10 17:58:12 +0200247 const ui::Rotation orientation = ui::ROTATION_90;
Marin Shalamanov209ae612020-10-01 00:17:39 +0200248 const Rect frame{50, 60, 100, 100};
249 const Rect viewport{10, 20, 30, 40};
Lloyd Pique32cbe282018-10-19 13:09:22 -0700250
Marin Shalamanov68933fb2020-09-10 17:58:12 +0200251 mOutput->setProjection(orientation, viewport, frame);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700252
Marin Shalamanov68933fb2020-09-10 17:58:12 +0200253 EXPECT_EQ(orientation, mOutput->getState().displaySpace.orientation);
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200254 EXPECT_EQ(frame, mOutput->getState().orientedDisplaySpace.content);
255 EXPECT_EQ(viewport, mOutput->getState().layerStackSpace.content);
Marin Shalamanov209ae612020-10-01 00:17:39 +0200256
257 const auto state = mOutput->getState();
258 EXPECT_EQ(ui::ROTATION_0, state.layerStackSpace.orientation);
259 EXPECT_EQ(viewport, state.layerStackSpace.content);
260 EXPECT_EQ(viewport, state.layerStackSpace.bounds);
261
262 EXPECT_EQ(ui::ROTATION_0, state.orientedDisplaySpace.orientation);
263 EXPECT_EQ(frame, state.orientedDisplaySpace.content);
264 EXPECT_EQ(Rect(0, 0, 2000, 1000), state.orientedDisplaySpace.bounds);
265
266 EXPECT_EQ(displayRect, state.displaySpace.bounds);
267 EXPECT_EQ(Rect(900, 50, 940, 100), state.displaySpace.content);
268 EXPECT_EQ(orientation, state.displaySpace.orientation);
269
270 EXPECT_EQ(displayRect, state.framebufferSpace.bounds);
271 EXPECT_EQ(Rect(900, 50, 940, 100), state.framebufferSpace.content);
272 EXPECT_EQ(orientation, state.framebufferSpace.orientation);
273
274 EXPECT_EQ(state.displaySpace.content, state.transform.transform(state.layerStackSpace.content));
Garfield Tan54edd912020-10-21 16:31:41 -0700275
276 EXPECT_EQ(ui::Transform::ROT_90, mOutput->getTransformHint());
Marin Shalamanov209ae612020-10-01 00:17:39 +0200277}
278
279TEST_F(OutputTest, setProjectionWithSmallFramebufferWorks) {
280 const Rect displayRect{0, 0, 1000, 2000};
281 const Rect framebufferRect{0, 0, 500, 1000};
282 mOutput->editState().displaySpace.bounds = displayRect;
283 mOutput->editState().framebufferSpace.bounds = framebufferRect;
284
285 const ui::Rotation orientation = ui::ROTATION_90;
286 const Rect frame{50, 60, 100, 100};
287 const Rect viewport{10, 20, 30, 40};
288
289 mOutput->setProjection(orientation, viewport, frame);
290
291 EXPECT_EQ(orientation, mOutput->getState().displaySpace.orientation);
292 EXPECT_EQ(frame, mOutput->getState().orientedDisplaySpace.content);
293 EXPECT_EQ(viewport, mOutput->getState().layerStackSpace.content);
294
295 const auto state = mOutput->getState();
296 EXPECT_EQ(ui::ROTATION_0, state.layerStackSpace.orientation);
297 EXPECT_EQ(viewport, state.layerStackSpace.content);
298 EXPECT_EQ(viewport, state.layerStackSpace.bounds);
299
300 EXPECT_EQ(ui::ROTATION_0, state.orientedDisplaySpace.orientation);
301 EXPECT_EQ(frame, state.orientedDisplaySpace.content);
302 EXPECT_EQ(Rect(0, 0, 2000, 1000), state.orientedDisplaySpace.bounds);
303
304 EXPECT_EQ(displayRect, state.displaySpace.bounds);
305 EXPECT_EQ(Rect(900, 50, 940, 100), state.displaySpace.content);
306 EXPECT_EQ(orientation, state.displaySpace.orientation);
307
308 EXPECT_EQ(framebufferRect, state.framebufferSpace.bounds);
309 EXPECT_EQ(Rect(450, 25, 470, 50), state.framebufferSpace.content);
310 EXPECT_EQ(orientation, state.framebufferSpace.orientation);
311
312 EXPECT_EQ(state.displaySpace.content, state.transform.transform(state.layerStackSpace.content));
Lloyd Pique32cbe282018-10-19 13:09:22 -0700313}
314
Lloyd Pique66d68602019-02-13 14:23:31 -0800315/*
Marin Shalamanovb15d2272020-09-17 21:41:52 +0200316 * Output::setDisplaySize()
Lloyd Pique32cbe282018-10-19 13:09:22 -0700317 */
318
Marin Shalamanovb15d2272020-09-17 21:41:52 +0200319TEST_F(OutputTest, setDisplaySpaceSizeUpdatesOutputStateAndDirtiesEntireOutput) {
320 mOutput->editState().layerStackSpace.content = Rect(0, 0, 2000, 1000);
321 mOutput->editState().layerStackSpace.bounds = Rect(0, 0, 2000, 1000);
322 mOutput->editState().orientedDisplaySpace.content = Rect(0, 0, 1800, 900);
323 mOutput->editState().orientedDisplaySpace.bounds = Rect(0, 0, 2000, 1000);
324 mOutput->editState().framebufferSpace.content = Rect(0, 0, 900, 1800);
325 mOutput->editState().framebufferSpace.bounds = Rect(0, 0, 1000, 2000);
326 mOutput->editState().framebufferSpace.orientation = ui::ROTATION_90;
327 mOutput->editState().displaySpace.content = Rect(0, 0, 900, 1800);
328 mOutput->editState().displaySpace.bounds = Rect(0, 0, 1000, 2000);
329 mOutput->editState().displaySpace.orientation = ui::ROTATION_90;
Lloyd Pique31cb2942018-10-19 17:23:03 -0700330
Marin Shalamanovb15d2272020-09-17 21:41:52 +0200331 const ui::Size newDisplaySize{500, 1000};
Lloyd Pique31cb2942018-10-19 17:23:03 -0700332
Marin Shalamanovb15d2272020-09-17 21:41:52 +0200333 EXPECT_CALL(*mRenderSurface, setDisplaySize(newDisplaySize)).Times(1);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700334
Marin Shalamanovb15d2272020-09-17 21:41:52 +0200335 mOutput->setDisplaySize(newDisplaySize);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700336
Marin Shalamanovb15d2272020-09-17 21:41:52 +0200337 const auto state = mOutput->getState();
338
339 const Rect displayRect(newDisplaySize);
340 EXPECT_EQ(ui::ROTATION_0, state.layerStackSpace.orientation);
341 EXPECT_EQ(Rect(0, 0, 2000, 1000), state.layerStackSpace.content);
342 EXPECT_EQ(Rect(0, 0, 2000, 1000), state.layerStackSpace.bounds);
Marin Shalamanov209ae612020-10-01 00:17:39 +0200343
Marin Shalamanovb15d2272020-09-17 21:41:52 +0200344 EXPECT_EQ(ui::ROTATION_0, state.orientedDisplaySpace.orientation);
Marin Shalamanovb15d2272020-09-17 21:41:52 +0200345 EXPECT_EQ(Rect(0, 0, 1000, 500), state.orientedDisplaySpace.bounds);
Marin Shalamanov209ae612020-10-01 00:17:39 +0200346
Marin Shalamanovb15d2272020-09-17 21:41:52 +0200347 EXPECT_EQ(displayRect, state.displaySpace.bounds);
Marin Shalamanovb15d2272020-09-17 21:41:52 +0200348 EXPECT_EQ(ui::ROTATION_90, state.displaySpace.orientation);
Marin Shalamanov209ae612020-10-01 00:17:39 +0200349
Marin Shalamanovb15d2272020-09-17 21:41:52 +0200350 EXPECT_EQ(displayRect, state.framebufferSpace.bounds);
Marin Shalamanovb15d2272020-09-17 21:41:52 +0200351 EXPECT_EQ(ui::ROTATION_90, state.framebufferSpace.orientation);
352
353 EXPECT_EQ(state.displaySpace.content, state.transform.transform(state.layerStackSpace.content));
354
355 EXPECT_THAT(state.dirtyRegion, RegionEq(Region(displayRect)));
Lloyd Pique32cbe282018-10-19 13:09:22 -0700356}
357
Lloyd Pique66d68602019-02-13 14:23:31 -0800358/*
Lloyd Pique32cbe282018-10-19 13:09:22 -0700359 * Output::setLayerStackFilter()
360 */
361
362TEST_F(OutputTest, setLayerStackFilterSetsFilterAndDirtiesEntireOutput) {
Lloyd Pique32cbe282018-10-19 13:09:22 -0700363 const uint32_t layerStack = 123u;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700364 mOutput->setLayerStackFilter(layerStack, true);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700365
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700366 EXPECT_TRUE(mOutput->getState().layerStackInternal);
367 EXPECT_EQ(layerStack, mOutput->getState().layerStackId);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700368
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700369 EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize)));
Lloyd Pique32cbe282018-10-19 13:09:22 -0700370}
371
Lloyd Pique66d68602019-02-13 14:23:31 -0800372/*
Lloyd Pique32cbe282018-10-19 13:09:22 -0700373 * Output::setColorTransform
374 */
375
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800376TEST_F(OutputTest, setColorTransformWithNoChangeFlaggedSkipsUpdates) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700377 mOutput->editState().colorTransformMatrix = kIdentity;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700378
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800379 // If no colorTransformMatrix is set the update should be skipped.
380 CompositionRefreshArgs refreshArgs;
381 refreshArgs.colorTransformMatrix = std::nullopt;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700382
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700383 mOutput->setColorTransform(refreshArgs);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700384
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800385 // The internal state should be unchanged
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700386 EXPECT_EQ(kIdentity, mOutput->getState().colorTransformMatrix);
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800387
388 // No dirty region should be set
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700389 EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region()));
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800390}
Lloyd Piqueef958122019-02-05 18:00:12 -0800391
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800392TEST_F(OutputTest, setColorTransformWithNoActualChangeSkipsUpdates) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700393 mOutput->editState().colorTransformMatrix = kIdentity;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700394
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800395 // Attempting to set the same colorTransformMatrix that is already set should
396 // also skip the update.
397 CompositionRefreshArgs refreshArgs;
398 refreshArgs.colorTransformMatrix = kIdentity;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700399
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700400 mOutput->setColorTransform(refreshArgs);
Lloyd Pique77f79a22019-04-29 15:55:40 -0700401
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800402 // The internal state should be unchanged
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700403 EXPECT_EQ(kIdentity, mOutput->getState().colorTransformMatrix);
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800404
405 // No dirty region should be set
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700406 EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region()));
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800407}
408
409TEST_F(OutputTest, setColorTransformPerformsUpdateToIdentity) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700410 mOutput->editState().colorTransformMatrix = kNonIdentityHalf;
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800411
412 // Setting a different colorTransformMatrix should perform the update.
413 CompositionRefreshArgs refreshArgs;
414 refreshArgs.colorTransformMatrix = kIdentity;
415
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700416 mOutput->setColorTransform(refreshArgs);
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800417
418 // The internal state should have been updated
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700419 EXPECT_EQ(kIdentity, mOutput->getState().colorTransformMatrix);
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800420
421 // The dirtyRegion should be set to the full display size
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700422 EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize)));
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800423}
Lloyd Pique77f79a22019-04-29 15:55:40 -0700424
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800425TEST_F(OutputTest, setColorTransformPerformsUpdateForIdentityToHalf) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700426 mOutput->editState().colorTransformMatrix = kIdentity;
Lloyd Pique77f79a22019-04-29 15:55:40 -0700427
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800428 // Setting a different colorTransformMatrix should perform the update.
429 CompositionRefreshArgs refreshArgs;
430 refreshArgs.colorTransformMatrix = kNonIdentityHalf;
Lloyd Pique77f79a22019-04-29 15:55:40 -0700431
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700432 mOutput->setColorTransform(refreshArgs);
Lloyd Piqueef958122019-02-05 18:00:12 -0800433
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800434 // The internal state should have been updated
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700435 EXPECT_EQ(kNonIdentityHalf, mOutput->getState().colorTransformMatrix);
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800436
437 // The dirtyRegion should be set to the full display size
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700438 EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize)));
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800439}
440
441TEST_F(OutputTest, setColorTransformPerformsUpdateForHalfToQuarter) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700442 mOutput->editState().colorTransformMatrix = kNonIdentityHalf;
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800443
444 // Setting a different colorTransformMatrix should perform the update.
445 CompositionRefreshArgs refreshArgs;
446 refreshArgs.colorTransformMatrix = kNonIdentityQuarter;
447
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700448 mOutput->setColorTransform(refreshArgs);
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800449
450 // The internal state should have been updated
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700451 EXPECT_EQ(kNonIdentityQuarter, mOutput->getState().colorTransformMatrix);
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800452
453 // The dirtyRegion should be set to the full display size
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700454 EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize)));
Lloyd Pique32cbe282018-10-19 13:09:22 -0700455}
456
Lloyd Pique66d68602019-02-13 14:23:31 -0800457/*
Lloyd Pique17ca7422019-11-14 14:24:10 -0800458 * Output::setColorProfile
Lloyd Pique32cbe282018-10-19 13:09:22 -0700459 */
460
Lloyd Pique17ca7422019-11-14 14:24:10 -0800461using OutputSetColorProfileTest = OutputTest;
462
463TEST_F(OutputSetColorProfileTest, setsStateAndDirtiesOutputIfChanged) {
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800464 using ColorProfile = Output::ColorProfile;
465
Lloyd Piquef5275482019-01-29 18:42:42 -0800466 EXPECT_CALL(*mDisplayColorProfile,
467 getTargetDataspace(ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
468 ui::Dataspace::UNKNOWN))
469 .WillOnce(Return(ui::Dataspace::UNKNOWN));
Lloyd Piqueef958122019-02-05 18:00:12 -0800470 EXPECT_CALL(*mRenderSurface, setBufferDataspace(ui::Dataspace::DISPLAY_P3)).Times(1);
Lloyd Pique31cb2942018-10-19 17:23:03 -0700471
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700472 mOutput->setColorProfile(ColorProfile{ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
473 ui::RenderIntent::TONE_MAP_COLORIMETRIC,
474 ui::Dataspace::UNKNOWN});
Lloyd Pique32cbe282018-10-19 13:09:22 -0700475
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700476 EXPECT_EQ(ui::ColorMode::DISPLAY_P3, mOutput->getState().colorMode);
477 EXPECT_EQ(ui::Dataspace::DISPLAY_P3, mOutput->getState().dataspace);
478 EXPECT_EQ(ui::RenderIntent::TONE_MAP_COLORIMETRIC, mOutput->getState().renderIntent);
479 EXPECT_EQ(ui::Dataspace::UNKNOWN, mOutput->getState().targetDataspace);
Lloyd Piquef5275482019-01-29 18:42:42 -0800480
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700481 EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize)));
Lloyd Piqueef958122019-02-05 18:00:12 -0800482}
483
Lloyd Pique17ca7422019-11-14 14:24:10 -0800484TEST_F(OutputSetColorProfileTest, doesNothingIfNoChange) {
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800485 using ColorProfile = Output::ColorProfile;
486
Lloyd Piquef5275482019-01-29 18:42:42 -0800487 EXPECT_CALL(*mDisplayColorProfile,
488 getTargetDataspace(ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
489 ui::Dataspace::UNKNOWN))
490 .WillOnce(Return(ui::Dataspace::UNKNOWN));
491
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700492 mOutput->editState().colorMode = ui::ColorMode::DISPLAY_P3;
493 mOutput->editState().dataspace = ui::Dataspace::DISPLAY_P3;
494 mOutput->editState().renderIntent = ui::RenderIntent::TONE_MAP_COLORIMETRIC;
495 mOutput->editState().targetDataspace = ui::Dataspace::UNKNOWN;
Lloyd Piqueef958122019-02-05 18:00:12 -0800496
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700497 mOutput->setColorProfile(ColorProfile{ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
498 ui::RenderIntent::TONE_MAP_COLORIMETRIC,
499 ui::Dataspace::UNKNOWN});
Lloyd Piqueef958122019-02-05 18:00:12 -0800500
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700501 EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region()));
Lloyd Pique32cbe282018-10-19 13:09:22 -0700502}
503
Lloyd Pique66d68602019-02-13 14:23:31 -0800504/*
Lloyd Pique31cb2942018-10-19 17:23:03 -0700505 * Output::setRenderSurface()
506 */
507
508TEST_F(OutputTest, setRenderSurfaceResetsBounds) {
509 const ui::Size newDisplaySize{640, 480};
510
511 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
512 EXPECT_CALL(*renderSurface, getSize()).WillOnce(ReturnRef(newDisplaySize));
513
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700514 mOutput->setRenderSurface(std::unique_ptr<RenderSurface>(renderSurface));
Lloyd Pique31cb2942018-10-19 17:23:03 -0700515
Marin Shalamanovb15d2272020-09-17 21:41:52 +0200516 EXPECT_EQ(Rect(newDisplaySize), mOutput->getState().framebufferSpace.bounds);
Lloyd Pique31cb2942018-10-19 17:23:03 -0700517}
518
Lloyd Pique66d68602019-02-13 14:23:31 -0800519/*
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000520 * Output::getDirtyRegion()
Lloyd Pique32cbe282018-10-19 13:09:22 -0700521 */
522
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000523TEST_F(OutputTest, getDirtyRegionWithRepaintEverythingTrue) {
524 const Rect viewport{100, 200};
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200525 mOutput->editState().layerStackSpace.content = viewport;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700526 mOutput->editState().dirtyRegion.set(50, 300);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700527
528 {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700529 Region result = mOutput->getDirtyRegion(true);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700530
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000531 EXPECT_THAT(result, RegionEq(Region(viewport)));
Lloyd Pique32cbe282018-10-19 13:09:22 -0700532 }
533}
534
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000535TEST_F(OutputTest, getDirtyRegionWithRepaintEverythingFalse) {
536 const Rect viewport{100, 200};
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200537 mOutput->editState().layerStackSpace.content = viewport;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700538 mOutput->editState().dirtyRegion.set(50, 300);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700539
540 {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700541 Region result = mOutput->getDirtyRegion(false);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700542
543 // The dirtyRegion should be clipped to the display bounds.
544 EXPECT_THAT(result, RegionEq(Region(Rect(50, 200))));
545 }
Lloyd Pique32cbe282018-10-19 13:09:22 -0700546}
547
Lloyd Pique66d68602019-02-13 14:23:31 -0800548/*
Lloyd Piqueef36b002019-01-23 17:52:04 -0800549 * Output::belongsInOutput()
550 */
551
552TEST_F(OutputTest, belongsInOutputFiltersAsExpected) {
553 const uint32_t layerStack1 = 123u;
554 const uint32_t layerStack2 = 456u;
555
556 // If the output accepts layerStack1 and internal-only layers....
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700557 mOutput->setLayerStackFilter(layerStack1, true);
Lloyd Piqueef36b002019-01-23 17:52:04 -0800558
Lloyd Piquec6687342019-03-07 21:34:57 -0800559 // A layer with no layerStack does not belong to it, internal-only or not.
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700560 EXPECT_FALSE(mOutput->belongsInOutput(std::nullopt, false));
561 EXPECT_FALSE(mOutput->belongsInOutput(std::nullopt, true));
Lloyd Piquec6687342019-03-07 21:34:57 -0800562
Lloyd Piqueef36b002019-01-23 17:52:04 -0800563 // Any layer with layerStack1 belongs to it, internal-only or not.
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700564 EXPECT_TRUE(mOutput->belongsInOutput(layerStack1, false));
565 EXPECT_TRUE(mOutput->belongsInOutput(layerStack1, true));
566 EXPECT_FALSE(mOutput->belongsInOutput(layerStack2, true));
567 EXPECT_FALSE(mOutput->belongsInOutput(layerStack2, false));
Lloyd Piqueef36b002019-01-23 17:52:04 -0800568
569 // If the output accepts layerStack21 but not internal-only layers...
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700570 mOutput->setLayerStackFilter(layerStack1, false);
Lloyd Piqueef36b002019-01-23 17:52:04 -0800571
572 // Only non-internal layers with layerStack1 belong to it.
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700573 EXPECT_TRUE(mOutput->belongsInOutput(layerStack1, false));
574 EXPECT_FALSE(mOutput->belongsInOutput(layerStack1, true));
575 EXPECT_FALSE(mOutput->belongsInOutput(layerStack2, true));
576 EXPECT_FALSE(mOutput->belongsInOutput(layerStack2, false));
Lloyd Piqueef36b002019-01-23 17:52:04 -0800577}
578
Lloyd Piquede196652020-01-22 17:29:58 -0800579TEST_F(OutputTest, belongsInOutputHandlesLayerWithNoCompositionState) {
580 NonInjectedLayer layer;
581 sp<LayerFE> layerFE(layer.layerFE);
Lloyd Pique66c20c42019-03-07 21:44:02 -0800582
Lloyd Piquede196652020-01-22 17:29:58 -0800583 // If the layer has no composition state, it does not belong to any output.
584 EXPECT_CALL(*layer.layerFE, getCompositionState).WillOnce(Return(nullptr));
585 EXPECT_FALSE(mOutput->belongsInOutput(layerFE));
586}
587
588TEST_F(OutputTest, belongsInOutputFiltersLayersAsExpected) {
589 NonInjectedLayer layer;
590 sp<LayerFE> layerFE(layer.layerFE);
Lloyd Pique66c20c42019-03-07 21:44:02 -0800591
592 const uint32_t layerStack1 = 123u;
593 const uint32_t layerStack2 = 456u;
594
595 // If the output accepts layerStack1 and internal-only layers....
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700596 mOutput->setLayerStackFilter(layerStack1, true);
Lloyd Pique66c20c42019-03-07 21:44:02 -0800597
Lloyd Pique66c20c42019-03-07 21:44:02 -0800598 // A layer with no layerStack does not belong to it, internal-only or not.
Lloyd Piquede196652020-01-22 17:29:58 -0800599 layer.layerFEState.layerStackId = std::nullopt;
600 layer.layerFEState.internalOnly = false;
601 EXPECT_FALSE(mOutput->belongsInOutput(layerFE));
Lloyd Pique66c20c42019-03-07 21:44:02 -0800602
Lloyd Piquede196652020-01-22 17:29:58 -0800603 layer.layerFEState.layerStackId = std::nullopt;
604 layer.layerFEState.internalOnly = true;
605 EXPECT_FALSE(mOutput->belongsInOutput(layerFE));
Lloyd Pique66c20c42019-03-07 21:44:02 -0800606
607 // Any layer with layerStack1 belongs to it, internal-only or not.
Lloyd Piquede196652020-01-22 17:29:58 -0800608 layer.layerFEState.layerStackId = layerStack1;
609 layer.layerFEState.internalOnly = false;
610 EXPECT_TRUE(mOutput->belongsInOutput(layerFE));
Lloyd Pique66c20c42019-03-07 21:44:02 -0800611
Lloyd Piquede196652020-01-22 17:29:58 -0800612 layer.layerFEState.layerStackId = layerStack1;
613 layer.layerFEState.internalOnly = true;
614 EXPECT_TRUE(mOutput->belongsInOutput(layerFE));
Lloyd Pique66c20c42019-03-07 21:44:02 -0800615
Lloyd Piquede196652020-01-22 17:29:58 -0800616 layer.layerFEState.layerStackId = layerStack2;
617 layer.layerFEState.internalOnly = true;
618 EXPECT_FALSE(mOutput->belongsInOutput(layerFE));
Lloyd Pique66c20c42019-03-07 21:44:02 -0800619
Lloyd Piquede196652020-01-22 17:29:58 -0800620 layer.layerFEState.layerStackId = layerStack2;
621 layer.layerFEState.internalOnly = false;
622 EXPECT_FALSE(mOutput->belongsInOutput(layerFE));
Lloyd Pique66c20c42019-03-07 21:44:02 -0800623
624 // If the output accepts layerStack1 but not internal-only layers...
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700625 mOutput->setLayerStackFilter(layerStack1, false);
Lloyd Pique66c20c42019-03-07 21:44:02 -0800626
Lloyd Pique66c20c42019-03-07 21:44:02 -0800627 // Only non-internal layers with layerStack1 belong to it.
Lloyd Piquede196652020-01-22 17:29:58 -0800628 layer.layerFEState.layerStackId = layerStack1;
629 layer.layerFEState.internalOnly = false;
630 EXPECT_TRUE(mOutput->belongsInOutput(layerFE));
Lloyd Pique66c20c42019-03-07 21:44:02 -0800631
Lloyd Piquede196652020-01-22 17:29:58 -0800632 layer.layerFEState.layerStackId = layerStack1;
633 layer.layerFEState.internalOnly = true;
634 EXPECT_FALSE(mOutput->belongsInOutput(layerFE));
Lloyd Pique66c20c42019-03-07 21:44:02 -0800635
Lloyd Piquede196652020-01-22 17:29:58 -0800636 layer.layerFEState.layerStackId = layerStack2;
637 layer.layerFEState.internalOnly = true;
638 EXPECT_FALSE(mOutput->belongsInOutput(layerFE));
Lloyd Pique66c20c42019-03-07 21:44:02 -0800639
Lloyd Piquede196652020-01-22 17:29:58 -0800640 layer.layerFEState.layerStackId = layerStack2;
641 layer.layerFEState.internalOnly = false;
642 EXPECT_FALSE(mOutput->belongsInOutput(layerFE));
Lloyd Pique66c20c42019-03-07 21:44:02 -0800643}
644
Lloyd Pique66d68602019-02-13 14:23:31 -0800645/*
Lloyd Piquecc01a452018-12-04 17:24:00 -0800646 * Output::getOutputLayerForLayer()
647 */
648
649TEST_F(OutputTest, getOutputLayerForLayerWorks) {
Lloyd Piquede196652020-01-22 17:29:58 -0800650 InjectedLayer layer1;
651 InjectedLayer layer2;
652 NonInjectedLayer layer3;
Lloyd Piquecc01a452018-12-04 17:24:00 -0800653
Lloyd Piquede196652020-01-22 17:29:58 -0800654 injectOutputLayer(layer1);
655 injectNullOutputLayer();
656 injectOutputLayer(layer2);
Lloyd Piquecc01a452018-12-04 17:24:00 -0800657
658 // If the input layer matches the first OutputLayer, it will be returned.
Lloyd Piquede196652020-01-22 17:29:58 -0800659 EXPECT_CALL(*layer1.outputLayer, getLayerFE()).WillOnce(ReturnRef(*layer1.layerFE.get()));
660 EXPECT_EQ(layer1.outputLayer, mOutput->getOutputLayerForLayer(layer1.layerFE));
Lloyd Piquecc01a452018-12-04 17:24:00 -0800661
662 // If the input layer matches the second OutputLayer, it will be returned.
Lloyd Piquede196652020-01-22 17:29:58 -0800663 EXPECT_CALL(*layer1.outputLayer, getLayerFE()).WillOnce(ReturnRef(*layer1.layerFE.get()));
664 EXPECT_CALL(*layer2.outputLayer, getLayerFE()).WillOnce(ReturnRef(*layer2.layerFE.get()));
665 EXPECT_EQ(layer2.outputLayer, mOutput->getOutputLayerForLayer(layer2.layerFE));
Lloyd Piquecc01a452018-12-04 17:24:00 -0800666
667 // If the input layer does not match an output layer, null will be returned.
Lloyd Piquede196652020-01-22 17:29:58 -0800668 EXPECT_CALL(*layer1.outputLayer, getLayerFE()).WillOnce(ReturnRef(*layer1.layerFE.get()));
669 EXPECT_CALL(*layer2.outputLayer, getLayerFE()).WillOnce(ReturnRef(*layer2.layerFE.get()));
670 EXPECT_EQ(nullptr, mOutput->getOutputLayerForLayer(layer3.layerFE));
Lloyd Piquecc01a452018-12-04 17:24:00 -0800671}
672
Lloyd Pique66d68602019-02-13 14:23:31 -0800673/*
Lloyd Piquec9e60032019-11-14 11:47:26 -0800674 * Output::setReleasedLayers()
675 */
676
677using OutputSetReleasedLayersTest = OutputTest;
678
679TEST_F(OutputSetReleasedLayersTest, setReleasedLayersTakesGivenLayers) {
680 sp<StrictMock<mock::LayerFE>> layer1FE{new StrictMock<mock::LayerFE>()};
681 sp<StrictMock<mock::LayerFE>> layer2FE{new StrictMock<mock::LayerFE>()};
682 sp<StrictMock<mock::LayerFE>> layer3FE{new StrictMock<mock::LayerFE>()};
683
684 Output::ReleasedLayers layers;
685 layers.push_back(layer1FE);
686 layers.push_back(layer2FE);
687 layers.push_back(layer3FE);
688
689 mOutput->setReleasedLayers(std::move(layers));
690
691 const auto& setLayers = mOutput->getReleasedLayersForTest();
692 ASSERT_EQ(3u, setLayers.size());
693 ASSERT_EQ(layer1FE.get(), setLayers[0].promote().get());
694 ASSERT_EQ(layer2FE.get(), setLayers[1].promote().get());
695 ASSERT_EQ(layer3FE.get(), setLayers[2].promote().get());
696}
697
698/*
Lloyd Piquec0ee6ba2019-11-14 12:55:53 -0800699 * Output::updateLayerStateFromFE()
700 */
701
Lloyd Piquede196652020-01-22 17:29:58 -0800702using OutputUpdateLayerStateFromFETest = OutputTest;
Lloyd Piquec0ee6ba2019-11-14 12:55:53 -0800703
704TEST_F(OutputUpdateLayerStateFromFETest, handlesNoOutputLayerCase) {
705 CompositionRefreshArgs refreshArgs;
706
707 mOutput->updateLayerStateFromFE(refreshArgs);
708}
709
Lloyd Piquede196652020-01-22 17:29:58 -0800710TEST_F(OutputUpdateLayerStateFromFETest, preparesContentStateForAllContainedLayers) {
711 InjectedLayer layer1;
712 InjectedLayer layer2;
713 InjectedLayer layer3;
Lloyd Piquec0ee6ba2019-11-14 12:55:53 -0800714
Lloyd Piquede196652020-01-22 17:29:58 -0800715 EXPECT_CALL(*layer1.layerFE.get(), prepareCompositionState(LayerFE::StateSubset::Content));
716 EXPECT_CALL(*layer2.layerFE.get(), prepareCompositionState(LayerFE::StateSubset::Content));
717 EXPECT_CALL(*layer3.layerFE.get(), prepareCompositionState(LayerFE::StateSubset::Content));
718
719 injectOutputLayer(layer1);
720 injectOutputLayer(layer2);
721 injectOutputLayer(layer3);
Lloyd Piquec0ee6ba2019-11-14 12:55:53 -0800722
723 CompositionRefreshArgs refreshArgs;
724 refreshArgs.updatingGeometryThisFrame = false;
725
726 mOutput->updateLayerStateFromFE(refreshArgs);
727}
728
Lloyd Piquede196652020-01-22 17:29:58 -0800729TEST_F(OutputUpdateLayerStateFromFETest, preparesGeometryAndContentStateForAllContainedLayers) {
730 InjectedLayer layer1;
731 InjectedLayer layer2;
732 InjectedLayer layer3;
Lloyd Piquec0ee6ba2019-11-14 12:55:53 -0800733
Lloyd Piquede196652020-01-22 17:29:58 -0800734 EXPECT_CALL(*layer1.layerFE, prepareCompositionState(LayerFE::StateSubset::GeometryAndContent));
735 EXPECT_CALL(*layer2.layerFE, prepareCompositionState(LayerFE::StateSubset::GeometryAndContent));
736 EXPECT_CALL(*layer3.layerFE, prepareCompositionState(LayerFE::StateSubset::GeometryAndContent));
737
738 injectOutputLayer(layer1);
739 injectOutputLayer(layer2);
740 injectOutputLayer(layer3);
Lloyd Piquec0ee6ba2019-11-14 12:55:53 -0800741
742 CompositionRefreshArgs refreshArgs;
743 refreshArgs.updatingGeometryThisFrame = true;
744
745 mOutput->updateLayerStateFromFE(refreshArgs);
746}
747
748/*
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800749 * Output::updateAndWriteCompositionState()
750 */
751
Lloyd Piquede196652020-01-22 17:29:58 -0800752using OutputUpdateAndWriteCompositionStateTest = OutputTest;
Lloyd Piqueef63b612019-11-14 13:19:56 -0800753
754TEST_F(OutputUpdateAndWriteCompositionStateTest, doesNothingIfLayers) {
755 mOutput->editState().isEnabled = true;
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800756
757 CompositionRefreshArgs args;
Dan Stoza269dc4d2021-01-15 15:07:43 -0800758 mOutput->updateCompositionState(args);
759 mOutput->planComposition();
760 mOutput->writeCompositionState(args);
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800761}
762
Lloyd Piqueef63b612019-11-14 13:19:56 -0800763TEST_F(OutputUpdateAndWriteCompositionStateTest, doesNothingIfOutputNotEnabled) {
Lloyd Piquede196652020-01-22 17:29:58 -0800764 InjectedLayer layer1;
765 InjectedLayer layer2;
766 InjectedLayer layer3;
767
Lloyd Piqueef63b612019-11-14 13:19:56 -0800768 mOutput->editState().isEnabled = false;
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800769
Lloyd Piquede196652020-01-22 17:29:58 -0800770 injectOutputLayer(layer1);
771 injectOutputLayer(layer2);
772 injectOutputLayer(layer3);
Lloyd Piqueef63b612019-11-14 13:19:56 -0800773
774 CompositionRefreshArgs args;
Dan Stoza269dc4d2021-01-15 15:07:43 -0800775 mOutput->updateCompositionState(args);
776 mOutput->planComposition();
777 mOutput->writeCompositionState(args);
Lloyd Piqueef63b612019-11-14 13:19:56 -0800778}
779
780TEST_F(OutputUpdateAndWriteCompositionStateTest, updatesLayerContentForAllLayers) {
Lloyd Piquede196652020-01-22 17:29:58 -0800781 InjectedLayer layer1;
782 InjectedLayer layer2;
783 InjectedLayer layer3;
Lloyd Piqueef63b612019-11-14 13:19:56 -0800784
Snild Dolkow9e217d62020-04-22 15:53:42 +0200785 EXPECT_CALL(*layer1.outputLayer, updateCompositionState(false, false, ui::Transform::ROT_180));
Dan Stoza6166c312021-01-15 16:34:05 -0800786 EXPECT_CALL(*layer1.outputLayer,
787 writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false));
Snild Dolkow9e217d62020-04-22 15:53:42 +0200788 EXPECT_CALL(*layer2.outputLayer, updateCompositionState(false, false, ui::Transform::ROT_180));
Dan Stoza6166c312021-01-15 16:34:05 -0800789 EXPECT_CALL(*layer2.outputLayer,
790 writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false));
Snild Dolkow9e217d62020-04-22 15:53:42 +0200791 EXPECT_CALL(*layer3.outputLayer, updateCompositionState(false, false, ui::Transform::ROT_180));
Dan Stoza6166c312021-01-15 16:34:05 -0800792 EXPECT_CALL(*layer3.outputLayer,
793 writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false));
Lloyd Piquede196652020-01-22 17:29:58 -0800794
795 injectOutputLayer(layer1);
796 injectOutputLayer(layer2);
797 injectOutputLayer(layer3);
Lloyd Piqueef63b612019-11-14 13:19:56 -0800798
799 mOutput->editState().isEnabled = true;
800
801 CompositionRefreshArgs args;
802 args.updatingGeometryThisFrame = false;
803 args.devOptForceClientComposition = false;
Snild Dolkow9e217d62020-04-22 15:53:42 +0200804 args.internalDisplayRotationFlags = ui::Transform::ROT_180;
Dan Stoza269dc4d2021-01-15 15:07:43 -0800805 mOutput->updateCompositionState(args);
806 mOutput->planComposition();
807 mOutput->writeCompositionState(args);
Lloyd Piqueef63b612019-11-14 13:19:56 -0800808}
809
810TEST_F(OutputUpdateAndWriteCompositionStateTest, updatesLayerGeometryAndContentForAllLayers) {
Lloyd Piquede196652020-01-22 17:29:58 -0800811 InjectedLayer layer1;
812 InjectedLayer layer2;
813 InjectedLayer layer3;
Lloyd Piqueef63b612019-11-14 13:19:56 -0800814
Snild Dolkow9e217d62020-04-22 15:53:42 +0200815 EXPECT_CALL(*layer1.outputLayer, updateCompositionState(true, false, ui::Transform::ROT_0));
Dan Stoza6166c312021-01-15 16:34:05 -0800816 EXPECT_CALL(*layer1.outputLayer,
817 writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false));
Snild Dolkow9e217d62020-04-22 15:53:42 +0200818 EXPECT_CALL(*layer2.outputLayer, updateCompositionState(true, false, ui::Transform::ROT_0));
Dan Stoza6166c312021-01-15 16:34:05 -0800819 EXPECT_CALL(*layer2.outputLayer,
820 writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false));
Snild Dolkow9e217d62020-04-22 15:53:42 +0200821 EXPECT_CALL(*layer3.outputLayer, updateCompositionState(true, false, ui::Transform::ROT_0));
Dan Stoza6166c312021-01-15 16:34:05 -0800822 EXPECT_CALL(*layer3.outputLayer,
823 writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false));
Lloyd Piquede196652020-01-22 17:29:58 -0800824
825 injectOutputLayer(layer1);
826 injectOutputLayer(layer2);
827 injectOutputLayer(layer3);
Lloyd Piqueef63b612019-11-14 13:19:56 -0800828
829 mOutput->editState().isEnabled = true;
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800830
831 CompositionRefreshArgs args;
832 args.updatingGeometryThisFrame = true;
Lloyd Piqueef63b612019-11-14 13:19:56 -0800833 args.devOptForceClientComposition = false;
Dan Stoza269dc4d2021-01-15 15:07:43 -0800834 mOutput->updateCompositionState(args);
835 mOutput->planComposition();
836 mOutput->writeCompositionState(args);
Lloyd Piqueef63b612019-11-14 13:19:56 -0800837}
838
839TEST_F(OutputUpdateAndWriteCompositionStateTest, forcesClientCompositionForAllLayers) {
Lloyd Piquede196652020-01-22 17:29:58 -0800840 InjectedLayer layer1;
841 InjectedLayer layer2;
842 InjectedLayer layer3;
Lloyd Piqueef63b612019-11-14 13:19:56 -0800843
Snild Dolkow9e217d62020-04-22 15:53:42 +0200844 EXPECT_CALL(*layer1.outputLayer, updateCompositionState(false, true, ui::Transform::ROT_0));
Dan Stoza6166c312021-01-15 16:34:05 -0800845 EXPECT_CALL(*layer1.outputLayer,
846 writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false));
Snild Dolkow9e217d62020-04-22 15:53:42 +0200847 EXPECT_CALL(*layer2.outputLayer, updateCompositionState(false, true, ui::Transform::ROT_0));
Dan Stoza6166c312021-01-15 16:34:05 -0800848 EXPECT_CALL(*layer2.outputLayer,
849 writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false));
Snild Dolkow9e217d62020-04-22 15:53:42 +0200850 EXPECT_CALL(*layer3.outputLayer, updateCompositionState(false, true, ui::Transform::ROT_0));
Dan Stoza6166c312021-01-15 16:34:05 -0800851 EXPECT_CALL(*layer3.outputLayer,
852 writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false));
Lloyd Piquede196652020-01-22 17:29:58 -0800853
854 injectOutputLayer(layer1);
855 injectOutputLayer(layer2);
856 injectOutputLayer(layer3);
Lloyd Piqueef63b612019-11-14 13:19:56 -0800857
858 mOutput->editState().isEnabled = true;
859
860 CompositionRefreshArgs args;
861 args.updatingGeometryThisFrame = false;
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800862 args.devOptForceClientComposition = true;
Dan Stoza269dc4d2021-01-15 15:07:43 -0800863 mOutput->updateCompositionState(args);
864 mOutput->planComposition();
865 mOutput->writeCompositionState(args);
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800866}
867
868/*
Lloyd Pique66d68602019-02-13 14:23:31 -0800869 * Output::prepareFrame()
870 */
871
872struct OutputPrepareFrameTest : public testing::Test {
Lloyd Piquefaa3f192019-11-14 14:05:09 -0800873 struct OutputPartialMock : public OutputPartialMockBase {
Lloyd Pique739afaf2019-11-21 16:40:05 -0800874 // Sets up the helper functions called by the function under test to use
875 // mock implementations.
Lloyd Pique66d68602019-02-13 14:23:31 -0800876 MOCK_METHOD0(chooseCompositionStrategy, void());
877 };
878
879 OutputPrepareFrameTest() {
880 mOutput.setDisplayColorProfileForTest(
881 std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile));
882 mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
883 }
884
885 StrictMock<mock::CompositionEngine> mCompositionEngine;
886 mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>();
887 mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>();
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700888 StrictMock<OutputPartialMock> mOutput;
Lloyd Pique66d68602019-02-13 14:23:31 -0800889};
890
891TEST_F(OutputPrepareFrameTest, takesEarlyOutIfNotEnabled) {
892 mOutput.editState().isEnabled = false;
893
894 mOutput.prepareFrame();
895}
896
897TEST_F(OutputPrepareFrameTest, delegatesToChooseCompositionStrategyAndRenderSurface) {
898 mOutput.editState().isEnabled = true;
899 mOutput.editState().usesClientComposition = false;
900 mOutput.editState().usesDeviceComposition = true;
901
902 EXPECT_CALL(mOutput, chooseCompositionStrategy()).Times(1);
Dan Stoza47437bb2021-01-15 16:21:07 -0800903 if (mOutput.plannerEnabled()) {
904 EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u));
905 }
Lloyd Pique66d68602019-02-13 14:23:31 -0800906 EXPECT_CALL(*mRenderSurface, prepareFrame(false, true));
907
908 mOutput.prepareFrame();
909}
910
911// Note: Use OutputTest and not OutputPrepareFrameTest, so the real
912// base chooseCompositionStrategy() is invoked.
913TEST_F(OutputTest, prepareFrameSetsClientCompositionOnlyByDefault) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700914 mOutput->editState().isEnabled = true;
915 mOutput->editState().usesClientComposition = false;
916 mOutput->editState().usesDeviceComposition = true;
Lloyd Pique66d68602019-02-13 14:23:31 -0800917
918 EXPECT_CALL(*mRenderSurface, prepareFrame(true, false));
919
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700920 mOutput->prepareFrame();
Lloyd Pique66d68602019-02-13 14:23:31 -0800921
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700922 EXPECT_TRUE(mOutput->getState().usesClientComposition);
923 EXPECT_FALSE(mOutput->getState().usesDeviceComposition);
Lloyd Pique66d68602019-02-13 14:23:31 -0800924}
925
Lloyd Pique56eba802019-08-28 15:45:25 -0700926/*
Lloyd Piqueb62cebc2019-11-20 18:31:52 -0800927 * Output::prepare()
928 */
929
930struct OutputPrepareTest : public testing::Test {
931 struct OutputPartialMock : public OutputPartialMockBase {
932 // Sets up the helper functions called by the function under test to use
933 // mock implementations.
934 MOCK_METHOD2(rebuildLayerStacks,
935 void(const compositionengine::CompositionRefreshArgs&,
936 compositionengine::LayerFESet&));
937 };
938
939 StrictMock<OutputPartialMock> mOutput;
940 CompositionRefreshArgs mRefreshArgs;
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -0800941 LayerFESet mGeomSnapshots;
Lloyd Piqueb62cebc2019-11-20 18:31:52 -0800942};
943
944TEST_F(OutputPrepareTest, justInvokesRebuildLayerStacks) {
945 InSequence seq;
946 EXPECT_CALL(mOutput, rebuildLayerStacks(Ref(mRefreshArgs), Ref(mGeomSnapshots)));
947
948 mOutput.prepare(mRefreshArgs, mGeomSnapshots);
949}
950
951/*
952 * Output::rebuildLayerStacks()
953 */
954
955struct OutputRebuildLayerStacksTest : public testing::Test {
956 struct OutputPartialMock : public OutputPartialMockBase {
957 // Sets up the helper functions called by the function under test to use
958 // mock implementations.
959 MOCK_METHOD2(collectVisibleLayers,
960 void(const compositionengine::CompositionRefreshArgs&,
961 compositionengine::Output::CoverageState&));
962 };
963
964 OutputRebuildLayerStacksTest() {
965 mOutput.mState.isEnabled = true;
966 mOutput.mState.transform = kIdentityTransform;
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200967 mOutput.mState.displaySpace.bounds = kOutputBounds;
Lloyd Piqueb62cebc2019-11-20 18:31:52 -0800968
969 mRefreshArgs.updatingOutputGeometryThisFrame = true;
970
971 mCoverageAboveCoveredLayersToSet = Region(Rect(0, 0, 10, 10));
972
973 EXPECT_CALL(mOutput, collectVisibleLayers(Ref(mRefreshArgs), _))
974 .WillRepeatedly(Invoke(this, &OutputRebuildLayerStacksTest::setTestCoverageValues));
975 }
976
977 void setTestCoverageValues(const CompositionRefreshArgs&,
978 compositionengine::Output::CoverageState& state) {
979 state.aboveCoveredLayers = mCoverageAboveCoveredLayersToSet;
980 state.aboveOpaqueLayers = mCoverageAboveOpaqueLayersToSet;
981 state.dirtyRegion = mCoverageDirtyRegionToSet;
982 }
983
984 static const ui::Transform kIdentityTransform;
985 static const ui::Transform kRotate90Transform;
986 static const Rect kOutputBounds;
987
988 StrictMock<OutputPartialMock> mOutput;
989 CompositionRefreshArgs mRefreshArgs;
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -0800990 LayerFESet mGeomSnapshots;
Lloyd Piqueb62cebc2019-11-20 18:31:52 -0800991 Region mCoverageAboveCoveredLayersToSet;
992 Region mCoverageAboveOpaqueLayersToSet;
993 Region mCoverageDirtyRegionToSet;
994};
995
996const ui::Transform OutputRebuildLayerStacksTest::kIdentityTransform{TR_IDENT, 1920, 1080};
997const ui::Transform OutputRebuildLayerStacksTest::kRotate90Transform{TR_ROT_90, 1920, 1080};
998const Rect OutputRebuildLayerStacksTest::kOutputBounds{0, 0, 1920, 1080};
999
1000TEST_F(OutputRebuildLayerStacksTest, doesNothingIfNotEnabled) {
1001 mOutput.mState.isEnabled = false;
1002
1003 mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots);
1004}
1005
1006TEST_F(OutputRebuildLayerStacksTest, doesNothingIfNotUpdatingGeometryThisFrame) {
1007 mRefreshArgs.updatingOutputGeometryThisFrame = false;
1008
1009 mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots);
1010}
1011
1012TEST_F(OutputRebuildLayerStacksTest, computesUndefinedRegionWithNoRotationAndFullCoverage) {
1013 mOutput.mState.transform = kIdentityTransform;
1014
1015 mCoverageAboveOpaqueLayersToSet = Region(Rect(0, 0, 1920, 1080));
1016
1017 mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots);
1018
1019 EXPECT_THAT(mOutput.mState.undefinedRegion, RegionEq(Region(Rect(0, 0, 0, 0))));
1020}
1021
1022TEST_F(OutputRebuildLayerStacksTest, computesUndefinedRegionWithNoRotationAndPartialCoverage) {
1023 mOutput.mState.transform = kIdentityTransform;
1024
1025 mCoverageAboveOpaqueLayersToSet = Region(Rect(0, 0, 960, 1080));
1026
1027 mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots);
1028
1029 EXPECT_THAT(mOutput.mState.undefinedRegion, RegionEq(Region(Rect(960, 0, 1920, 1080))));
1030}
1031
1032TEST_F(OutputRebuildLayerStacksTest, computesUndefinedRegionWith90RotationAndFullCoverage) {
1033 mOutput.mState.transform = kRotate90Transform;
1034
1035 mCoverageAboveOpaqueLayersToSet = Region(Rect(0, 0, 1080, 1920));
1036
1037 mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots);
1038
1039 EXPECT_THAT(mOutput.mState.undefinedRegion, RegionEq(Region(Rect(0, 0, 0, 0))));
1040}
1041
1042TEST_F(OutputRebuildLayerStacksTest, computesUndefinedRegionWith90RotationAndPartialCoverage) {
1043 mOutput.mState.transform = kRotate90Transform;
1044
1045 mCoverageAboveOpaqueLayersToSet = Region(Rect(0, 0, 1080, 960));
1046
1047 mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots);
1048
1049 EXPECT_THAT(mOutput.mState.undefinedRegion, RegionEq(Region(Rect(0, 0, 960, 1080))));
1050}
1051
1052TEST_F(OutputRebuildLayerStacksTest, addsToDirtyRegionWithNoRotation) {
1053 mOutput.mState.transform = kIdentityTransform;
1054 mOutput.mState.dirtyRegion = Region(Rect(960, 0, 1920, 1080));
1055
1056 mCoverageDirtyRegionToSet = Region(Rect(0, 0, 960, 1080));
1057
1058 mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots);
1059
1060 EXPECT_THAT(mOutput.mState.dirtyRegion, RegionEq(Region(Rect(0, 0, 1920, 1080))));
1061}
1062
1063TEST_F(OutputRebuildLayerStacksTest, addsToDirtyRegionWith90Rotation) {
1064 mOutput.mState.transform = kRotate90Transform;
1065 mOutput.mState.dirtyRegion = Region(Rect(0, 960, 1080, 1920));
1066
1067 mCoverageDirtyRegionToSet = Region(Rect(0, 0, 1080, 960));
1068
1069 mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots);
1070
1071 EXPECT_THAT(mOutput.mState.dirtyRegion, RegionEq(Region(Rect(0, 0, 1080, 1920))));
1072}
1073
1074/*
1075 * Output::collectVisibleLayers()
1076 */
1077
Lloyd Pique1ef93222019-11-21 16:41:53 -08001078struct OutputCollectVisibleLayersTest : public testing::Test {
1079 struct OutputPartialMock : public OutputPartialMockBase {
1080 // Sets up the helper functions called by the function under test to use
1081 // mock implementations.
1082 MOCK_METHOD2(ensureOutputLayerIfVisible,
Lloyd Piquede196652020-01-22 17:29:58 -08001083 void(sp<compositionengine::LayerFE>&,
Lloyd Pique1ef93222019-11-21 16:41:53 -08001084 compositionengine::Output::CoverageState&));
1085 MOCK_METHOD1(setReleasedLayers, void(const compositionengine::CompositionRefreshArgs&));
1086 MOCK_METHOD0(finalizePendingOutputLayers, void());
1087 };
1088
1089 struct Layer {
1090 Layer() {
1091 EXPECT_CALL(outputLayer, getState()).WillRepeatedly(ReturnRef(outputLayerState));
1092 EXPECT_CALL(outputLayer, editState()).WillRepeatedly(ReturnRef(outputLayerState));
1093 }
1094
1095 StrictMock<mock::OutputLayer> outputLayer;
Lloyd Pique1ef93222019-11-21 16:41:53 -08001096 impl::OutputLayerCompositionState outputLayerState;
Lloyd Piquede196652020-01-22 17:29:58 -08001097 sp<StrictMock<mock::LayerFE>> layerFE{new StrictMock<mock::LayerFE>()};
Lloyd Pique1ef93222019-11-21 16:41:53 -08001098 };
1099
1100 OutputCollectVisibleLayersTest() {
Lloyd Pique0a456232020-01-16 17:51:13 -08001101 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(3u));
Lloyd Pique1ef93222019-11-21 16:41:53 -08001102 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0))
1103 .WillRepeatedly(Return(&mLayer1.outputLayer));
1104 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(1))
1105 .WillRepeatedly(Return(&mLayer2.outputLayer));
1106 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(2))
1107 .WillRepeatedly(Return(&mLayer3.outputLayer));
1108
Lloyd Piquede196652020-01-22 17:29:58 -08001109 mRefreshArgs.layers.push_back(mLayer1.layerFE);
1110 mRefreshArgs.layers.push_back(mLayer2.layerFE);
1111 mRefreshArgs.layers.push_back(mLayer3.layerFE);
Lloyd Pique1ef93222019-11-21 16:41:53 -08001112 }
1113
1114 StrictMock<OutputPartialMock> mOutput;
1115 CompositionRefreshArgs mRefreshArgs;
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001116 LayerFESet mGeomSnapshots;
1117 Output::CoverageState mCoverageState{mGeomSnapshots};
Lloyd Pique1ef93222019-11-21 16:41:53 -08001118 Layer mLayer1;
1119 Layer mLayer2;
1120 Layer mLayer3;
1121};
1122
1123TEST_F(OutputCollectVisibleLayersTest, doesMinimalWorkIfNoLayers) {
1124 mRefreshArgs.layers.clear();
Lloyd Pique0a456232020-01-16 17:51:13 -08001125 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(0u));
Lloyd Pique1ef93222019-11-21 16:41:53 -08001126
1127 EXPECT_CALL(mOutput, setReleasedLayers(Ref(mRefreshArgs)));
1128 EXPECT_CALL(mOutput, finalizePendingOutputLayers());
1129
1130 mOutput.collectVisibleLayers(mRefreshArgs, mCoverageState);
1131}
1132
1133TEST_F(OutputCollectVisibleLayersTest, processesCandidateLayersReversedAndSetsOutputLayerZ) {
1134 // Enforce a call order sequence for this test.
1135 InSequence seq;
1136
1137 // Layer coverage is evaluated from front to back!
Lloyd Piquede196652020-01-22 17:29:58 -08001138 EXPECT_CALL(mOutput, ensureOutputLayerIfVisible(Eq(mLayer3.layerFE), Ref(mCoverageState)));
1139 EXPECT_CALL(mOutput, ensureOutputLayerIfVisible(Eq(mLayer2.layerFE), Ref(mCoverageState)));
1140 EXPECT_CALL(mOutput, ensureOutputLayerIfVisible(Eq(mLayer1.layerFE), Ref(mCoverageState)));
Lloyd Pique1ef93222019-11-21 16:41:53 -08001141
1142 EXPECT_CALL(mOutput, setReleasedLayers(Ref(mRefreshArgs)));
1143 EXPECT_CALL(mOutput, finalizePendingOutputLayers());
1144
1145 mOutput.collectVisibleLayers(mRefreshArgs, mCoverageState);
1146
1147 // Ensure all output layers have been assigned a simple/flattened z-order.
1148 EXPECT_EQ(0u, mLayer1.outputLayerState.z);
1149 EXPECT_EQ(1u, mLayer2.outputLayerState.z);
1150 EXPECT_EQ(2u, mLayer3.outputLayerState.z);
1151}
Lloyd Piqueb62cebc2019-11-20 18:31:52 -08001152
1153/*
1154 * Output::ensureOutputLayerIfVisible()
1155 */
1156
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001157struct OutputEnsureOutputLayerIfVisibleTest : public testing::Test {
1158 struct OutputPartialMock : public OutputPartialMockBase {
1159 // Sets up the helper functions called by the function under test to use
1160 // mock implementations.
Lloyd Piquede196652020-01-22 17:29:58 -08001161 MOCK_CONST_METHOD1(belongsInOutput, bool(const sp<compositionengine::LayerFE>&));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001162 MOCK_CONST_METHOD1(getOutputLayerOrderedByZByIndex, OutputLayer*(size_t));
Lloyd Piquede196652020-01-22 17:29:58 -08001163 MOCK_METHOD2(ensureOutputLayer,
1164 compositionengine::OutputLayer*(std::optional<size_t>, const sp<LayerFE>&));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001165 };
1166
1167 OutputEnsureOutputLayerIfVisibleTest() {
Lloyd Piquede196652020-01-22 17:29:58 -08001168 EXPECT_CALL(mOutput, belongsInOutput(sp<LayerFE>(mLayer.layerFE)))
1169 .WillRepeatedly(Return(true));
Lloyd Pique0a456232020-01-16 17:51:13 -08001170 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(1u));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001171 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0u))
Lloyd Piquede196652020-01-22 17:29:58 -08001172 .WillRepeatedly(Return(&mLayer.outputLayer));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001173
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02001174 mOutput.mState.displaySpace.bounds = Rect(0, 0, 200, 300);
1175 mOutput.mState.layerStackSpace.content = Rect(0, 0, 200, 300);
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001176 mOutput.mState.transform = ui::Transform(TR_IDENT, 200, 300);
1177
Lloyd Piquede196652020-01-22 17:29:58 -08001178 mLayer.layerFEState.isVisible = true;
1179 mLayer.layerFEState.isOpaque = true;
1180 mLayer.layerFEState.contentDirty = true;
1181 mLayer.layerFEState.geomLayerBounds = FloatRect{0, 0, 100, 200};
1182 mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200);
1183 mLayer.layerFEState.transparentRegionHint = Region(Rect(0, 0, 100, 100));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001184
Lloyd Piquede196652020-01-22 17:29:58 -08001185 mLayer.outputLayerState.visibleRegion = Region(Rect(0, 0, 50, 200));
1186 mLayer.outputLayerState.coveredRegion = Region(Rect(50, 0, 100, 200));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001187
Lloyd Piquede196652020-01-22 17:29:58 -08001188 mGeomSnapshots.insert(mLayer.layerFE);
1189 }
1190
1191 void ensureOutputLayerIfVisible() {
1192 sp<LayerFE> layerFE(mLayer.layerFE);
1193 mOutput.ensureOutputLayerIfVisible(layerFE, mCoverageState);
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001194 }
1195
1196 static const Region kEmptyRegion;
1197 static const Region kFullBoundsNoRotation;
1198 static const Region kRightHalfBoundsNoRotation;
1199 static const Region kLowerHalfBoundsNoRotation;
1200 static const Region kFullBounds90Rotation;
1201
1202 StrictMock<OutputPartialMock> mOutput;
1203 LayerFESet mGeomSnapshots;
1204 Output::CoverageState mCoverageState{mGeomSnapshots};
1205
Lloyd Piquede196652020-01-22 17:29:58 -08001206 NonInjectedLayer mLayer;
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001207};
1208
1209const Region OutputEnsureOutputLayerIfVisibleTest::kEmptyRegion = Region(Rect(0, 0, 0, 0));
1210const Region OutputEnsureOutputLayerIfVisibleTest::kFullBoundsNoRotation =
1211 Region(Rect(0, 0, 100, 200));
1212const Region OutputEnsureOutputLayerIfVisibleTest::kRightHalfBoundsNoRotation =
1213 Region(Rect(0, 100, 100, 200));
1214const Region OutputEnsureOutputLayerIfVisibleTest::kLowerHalfBoundsNoRotation =
1215 Region(Rect(50, 0, 100, 200));
1216const Region OutputEnsureOutputLayerIfVisibleTest::kFullBounds90Rotation =
1217 Region(Rect(0, 0, 200, 100));
1218
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001219TEST_F(OutputEnsureOutputLayerIfVisibleTest, performsGeomLatchBeforeCheckingIfLayerBelongs) {
Lloyd Piquede196652020-01-22 17:29:58 -08001220 EXPECT_CALL(mOutput, belongsInOutput(sp<LayerFE>(mLayer.layerFE))).WillOnce(Return(false));
1221 EXPECT_CALL(*mLayer.layerFE,
1222 prepareCompositionState(compositionengine::LayerFE::StateSubset::BasicGeometry));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001223
1224 mGeomSnapshots.clear();
1225
Lloyd Piquede196652020-01-22 17:29:58 -08001226 ensureOutputLayerIfVisible();
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001227}
1228
1229TEST_F(OutputEnsureOutputLayerIfVisibleTest,
1230 skipsLatchIfAlreadyLatchedBeforeCheckingIfLayerBelongs) {
Lloyd Piquede196652020-01-22 17:29:58 -08001231 EXPECT_CALL(mOutput, belongsInOutput(sp<LayerFE>(mLayer.layerFE))).WillOnce(Return(false));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001232
Lloyd Piquede196652020-01-22 17:29:58 -08001233 ensureOutputLayerIfVisible();
1234}
1235
1236TEST_F(OutputEnsureOutputLayerIfVisibleTest, takesEarlyOutIfLayerHasNoCompositionState) {
1237 EXPECT_CALL(*mLayer.layerFE, getCompositionState()).WillOnce(Return(nullptr));
1238
1239 ensureOutputLayerIfVisible();
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001240}
1241
1242TEST_F(OutputEnsureOutputLayerIfVisibleTest, takesEarlyOutIfLayerNotVisible) {
Lloyd Piquede196652020-01-22 17:29:58 -08001243 mLayer.layerFEState.isVisible = false;
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001244
Lloyd Piquede196652020-01-22 17:29:58 -08001245 ensureOutputLayerIfVisible();
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001246}
1247
1248TEST_F(OutputEnsureOutputLayerIfVisibleTest, takesEarlyOutIfLayerHasEmptyVisibleRegion) {
Lloyd Piquede196652020-01-22 17:29:58 -08001249 mLayer.layerFEState.geomLayerBounds = FloatRect{0, 0, 0, 0};
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001250
Lloyd Piquede196652020-01-22 17:29:58 -08001251 ensureOutputLayerIfVisible();
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001252}
1253
Marin Shalamanove67fcd02020-07-01 13:25:38 +00001254TEST_F(OutputEnsureOutputLayerIfVisibleTest, takesNotSoEarlyOutifDrawRegionEmpty) {
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02001255 mOutput.mState.displaySpace.bounds = Rect(0, 0, 0, 0);
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001256
Lloyd Piquede196652020-01-22 17:29:58 -08001257 ensureOutputLayerIfVisible();
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001258}
1259
1260TEST_F(OutputEnsureOutputLayerIfVisibleTest,
1261 handlesCreatingOutputLayerForOpaqueDirtyNotRotatedLayer) {
Lloyd Piquede196652020-01-22 17:29:58 -08001262 mLayer.layerFEState.isOpaque = true;
1263 mLayer.layerFEState.contentDirty = true;
1264 mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200);
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001265
1266 EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u));
Lloyd Piquede196652020-01-22 17:29:58 -08001267 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(std::nullopt), Eq(mLayer.layerFE)))
1268 .WillOnce(Return(&mLayer.outputLayer));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001269
Lloyd Piquede196652020-01-22 17:29:58 -08001270 ensureOutputLayerIfVisible();
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001271
1272 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation));
1273 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation));
1274 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation));
1275
Lloyd Piquede196652020-01-22 17:29:58 -08001276 EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation));
1277 EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion,
1278 RegionEq(kFullBoundsNoRotation));
1279 EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion));
1280 EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001281}
1282
1283TEST_F(OutputEnsureOutputLayerIfVisibleTest,
1284 handlesUpdatingOutputLayerForOpaqueDirtyNotRotatedLayer) {
Lloyd Piquede196652020-01-22 17:29:58 -08001285 mLayer.layerFEState.isOpaque = true;
1286 mLayer.layerFEState.contentDirty = true;
1287 mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200);
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001288
Lloyd Piquede196652020-01-22 17:29:58 -08001289 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(0u), Eq(mLayer.layerFE)))
1290 .WillOnce(Return(&mLayer.outputLayer));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001291
Lloyd Piquede196652020-01-22 17:29:58 -08001292 ensureOutputLayerIfVisible();
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001293
1294 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation));
1295 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation));
1296 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation));
1297
Lloyd Piquede196652020-01-22 17:29:58 -08001298 EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation));
1299 EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion,
1300 RegionEq(kFullBoundsNoRotation));
1301 EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion));
1302 EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001303}
1304
1305TEST_F(OutputEnsureOutputLayerIfVisibleTest,
1306 handlesCreatingOutputLayerForTransparentDirtyNotRotatedLayer) {
Lloyd Piquede196652020-01-22 17:29:58 -08001307 mLayer.layerFEState.isOpaque = false;
1308 mLayer.layerFEState.contentDirty = true;
1309 mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200);
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001310
1311 EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u));
Lloyd Piquede196652020-01-22 17:29:58 -08001312 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(std::nullopt), Eq(mLayer.layerFE)))
1313 .WillOnce(Return(&mLayer.outputLayer));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001314
Lloyd Piquede196652020-01-22 17:29:58 -08001315 ensureOutputLayerIfVisible();
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001316
1317 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation));
1318 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation));
1319 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kEmptyRegion));
1320
Lloyd Piquede196652020-01-22 17:29:58 -08001321 EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation));
1322 EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion,
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001323 RegionEq(kRightHalfBoundsNoRotation));
Lloyd Piquede196652020-01-22 17:29:58 -08001324 EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion));
1325 EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001326}
1327
1328TEST_F(OutputEnsureOutputLayerIfVisibleTest,
1329 handlesUpdatingOutputLayerForTransparentDirtyNotRotatedLayer) {
Lloyd Piquede196652020-01-22 17:29:58 -08001330 mLayer.layerFEState.isOpaque = false;
1331 mLayer.layerFEState.contentDirty = true;
1332 mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200);
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001333
Lloyd Piquede196652020-01-22 17:29:58 -08001334 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(0u), Eq(mLayer.layerFE)))
1335 .WillOnce(Return(&mLayer.outputLayer));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001336
Lloyd Piquede196652020-01-22 17:29:58 -08001337 ensureOutputLayerIfVisible();
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001338
1339 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation));
1340 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation));
1341 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kEmptyRegion));
1342
Lloyd Piquede196652020-01-22 17:29:58 -08001343 EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation));
1344 EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion,
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001345 RegionEq(kRightHalfBoundsNoRotation));
Lloyd Piquede196652020-01-22 17:29:58 -08001346 EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion));
1347 EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001348}
1349
1350TEST_F(OutputEnsureOutputLayerIfVisibleTest,
1351 handlesCreatingOutputLayerForOpaqueNonDirtyNotRotatedLayer) {
Lloyd Piquede196652020-01-22 17:29:58 -08001352 mLayer.layerFEState.isOpaque = true;
1353 mLayer.layerFEState.contentDirty = false;
1354 mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200);
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001355
1356 EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u));
Lloyd Piquede196652020-01-22 17:29:58 -08001357 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(std::nullopt), Eq(mLayer.layerFE)))
1358 .WillOnce(Return(&mLayer.outputLayer));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001359
Lloyd Piquede196652020-01-22 17:29:58 -08001360 ensureOutputLayerIfVisible();
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001361
1362 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation));
1363 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation));
1364 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation));
1365
Lloyd Piquede196652020-01-22 17:29:58 -08001366 EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation));
1367 EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion,
1368 RegionEq(kFullBoundsNoRotation));
1369 EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion));
1370 EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001371}
1372
1373TEST_F(OutputEnsureOutputLayerIfVisibleTest,
1374 handlesUpdatingOutputLayerForOpaqueNonDirtyNotRotatedLayer) {
Lloyd Piquede196652020-01-22 17:29:58 -08001375 mLayer.layerFEState.isOpaque = true;
1376 mLayer.layerFEState.contentDirty = false;
1377 mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200);
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001378
Lloyd Piquede196652020-01-22 17:29:58 -08001379 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(0u), Eq(mLayer.layerFE)))
1380 .WillOnce(Return(&mLayer.outputLayer));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001381
Lloyd Piquede196652020-01-22 17:29:58 -08001382 ensureOutputLayerIfVisible();
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001383
1384 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kLowerHalfBoundsNoRotation));
1385 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation));
1386 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation));
1387
Lloyd Piquede196652020-01-22 17:29:58 -08001388 EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation));
1389 EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion,
1390 RegionEq(kFullBoundsNoRotation));
1391 EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion));
1392 EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001393}
1394
1395TEST_F(OutputEnsureOutputLayerIfVisibleTest,
1396 handlesCreatingOutputLayerForOpaqueDirtyRotated90Layer) {
Lloyd Piquede196652020-01-22 17:29:58 -08001397 mLayer.layerFEState.isOpaque = true;
1398 mLayer.layerFEState.contentDirty = true;
1399 mLayer.layerFEState.geomLayerBounds = FloatRect{0, 0, 200, 100};
1400 mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_ROT_90, 100, 200);
1401 mLayer.outputLayerState.visibleRegion = Region(Rect(0, 0, 100, 100));
1402 mLayer.outputLayerState.coveredRegion = Region(Rect(100, 0, 200, 100));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001403
1404 EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u));
Lloyd Piquede196652020-01-22 17:29:58 -08001405 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(std::nullopt), Eq(mLayer.layerFE)))
1406 .WillOnce(Return(&mLayer.outputLayer));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001407
Lloyd Piquede196652020-01-22 17:29:58 -08001408 ensureOutputLayerIfVisible();
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001409
1410 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation));
1411 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation));
1412 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation));
1413
Lloyd Piquede196652020-01-22 17:29:58 -08001414 EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation));
1415 EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion,
1416 RegionEq(kFullBoundsNoRotation));
1417 EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion));
1418 EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001419}
1420
1421TEST_F(OutputEnsureOutputLayerIfVisibleTest,
1422 handlesUpdatingOutputLayerForOpaqueDirtyRotated90Layer) {
Lloyd Piquede196652020-01-22 17:29:58 -08001423 mLayer.layerFEState.isOpaque = true;
1424 mLayer.layerFEState.contentDirty = true;
1425 mLayer.layerFEState.geomLayerBounds = FloatRect{0, 0, 200, 100};
1426 mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_ROT_90, 100, 200);
1427 mLayer.outputLayerState.visibleRegion = Region(Rect(0, 0, 100, 100));
1428 mLayer.outputLayerState.coveredRegion = Region(Rect(100, 0, 200, 100));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001429
Lloyd Piquede196652020-01-22 17:29:58 -08001430 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(0u), Eq(mLayer.layerFE)))
1431 .WillOnce(Return(&mLayer.outputLayer));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001432
Lloyd Piquede196652020-01-22 17:29:58 -08001433 ensureOutputLayerIfVisible();
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001434
1435 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation));
1436 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation));
1437 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation));
1438
Lloyd Piquede196652020-01-22 17:29:58 -08001439 EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation));
1440 EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion,
1441 RegionEq(kFullBoundsNoRotation));
1442 EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion));
1443 EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001444}
1445
1446TEST_F(OutputEnsureOutputLayerIfVisibleTest,
1447 handlesCreatingOutputLayerForOpaqueDirtyNotRotatedLayerRotatedOutput) {
Lloyd Piquede196652020-01-22 17:29:58 -08001448 mLayer.layerFEState.isOpaque = true;
1449 mLayer.layerFEState.contentDirty = true;
1450 mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200);
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001451
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02001452 mOutput.mState.layerStackSpace.content = Rect(0, 0, 300, 200);
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001453 mOutput.mState.transform = ui::Transform(TR_ROT_90, 200, 300);
1454
1455 EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u));
Lloyd Piquede196652020-01-22 17:29:58 -08001456 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(std::nullopt), Eq(mLayer.layerFE)))
1457 .WillOnce(Return(&mLayer.outputLayer));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001458
Lloyd Piquede196652020-01-22 17:29:58 -08001459 ensureOutputLayerIfVisible();
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001460
1461 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation));
1462 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation));
1463 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation));
1464
Lloyd Piquede196652020-01-22 17:29:58 -08001465 EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation));
1466 EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion,
1467 RegionEq(kFullBoundsNoRotation));
1468 EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion));
1469 EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBounds90Rotation));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001470}
1471
1472TEST_F(OutputEnsureOutputLayerIfVisibleTest,
1473 handlesUpdatingOutputLayerForOpaqueDirtyNotRotatedLayerRotatedOutput) {
Lloyd Piquede196652020-01-22 17:29:58 -08001474 mLayer.layerFEState.isOpaque = true;
1475 mLayer.layerFEState.contentDirty = true;
1476 mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200);
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001477
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02001478 mOutput.mState.layerStackSpace.content = Rect(0, 0, 300, 200);
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001479 mOutput.mState.transform = ui::Transform(TR_ROT_90, 200, 300);
1480
Lloyd Piquede196652020-01-22 17:29:58 -08001481 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(0u), Eq(mLayer.layerFE)))
1482 .WillOnce(Return(&mLayer.outputLayer));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001483
Lloyd Piquede196652020-01-22 17:29:58 -08001484 ensureOutputLayerIfVisible();
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001485
1486 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation));
1487 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation));
1488 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation));
1489
Lloyd Piquede196652020-01-22 17:29:58 -08001490 EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation));
1491 EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion,
1492 RegionEq(kFullBoundsNoRotation));
1493 EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion));
1494 EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBounds90Rotation));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001495}
1496
1497TEST_F(OutputEnsureOutputLayerIfVisibleTest,
1498 handlesCreatingOutputLayerForOpaqueDirtyArbitraryTransformLayer) {
1499 ui::Transform arbitraryTransform;
1500 arbitraryTransform.set(1, 1, -1, 1);
1501 arbitraryTransform.set(0, 100);
1502
Lloyd Piquede196652020-01-22 17:29:58 -08001503 mLayer.layerFEState.isOpaque = true;
1504 mLayer.layerFEState.contentDirty = true;
1505 mLayer.layerFEState.geomLayerBounds = FloatRect{0, 0, 100, 200};
1506 mLayer.layerFEState.geomLayerTransform = arbitraryTransform;
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001507
1508 EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u));
Lloyd Piquede196652020-01-22 17:29:58 -08001509 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(std::nullopt), Eq(mLayer.layerFE)))
1510 .WillOnce(Return(&mLayer.outputLayer));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001511
Lloyd Piquede196652020-01-22 17:29:58 -08001512 ensureOutputLayerIfVisible();
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001513
1514 const Region kRegion = Region(Rect(0, 0, 300, 300));
1515 const Region kRegionClipped = Region(Rect(0, 0, 200, 300));
1516
1517 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kRegion));
1518 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kRegion));
1519 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kEmptyRegion));
1520
Lloyd Piquede196652020-01-22 17:29:58 -08001521 EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kRegion));
1522 EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion, RegionEq(kRegion));
1523 EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion));
1524 EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kRegionClipped));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001525}
1526
1527TEST_F(OutputEnsureOutputLayerIfVisibleTest, coverageAccumulatesTest) {
Lloyd Piquede196652020-01-22 17:29:58 -08001528 mLayer.layerFEState.isOpaque = false;
1529 mLayer.layerFEState.contentDirty = true;
1530 mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200);
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001531
1532 mCoverageState.dirtyRegion = Region(Rect(0, 0, 500, 500));
1533 mCoverageState.aboveCoveredLayers = Region(Rect(50, 0, 150, 200));
1534 mCoverageState.aboveOpaqueLayers = Region(Rect(50, 0, 150, 200));
1535
Lloyd Piquede196652020-01-22 17:29:58 -08001536 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(0u), Eq(mLayer.layerFE)))
1537 .WillOnce(Return(&mLayer.outputLayer));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001538
Lloyd Piquede196652020-01-22 17:29:58 -08001539 ensureOutputLayerIfVisible();
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001540
1541 const Region kExpectedDirtyRegion = Region(Rect(0, 0, 500, 500));
1542 const Region kExpectedAboveCoveredRegion = Region(Rect(0, 0, 150, 200));
1543 const Region kExpectedAboveOpaqueRegion = Region(Rect(50, 0, 150, 200));
1544 const Region kExpectedLayerVisibleRegion = Region(Rect(0, 0, 50, 200));
1545 const Region kExpectedLayerCoveredRegion = Region(Rect(50, 0, 100, 200));
1546 const Region kExpectedLayerVisibleNonTransparentRegion = Region(Rect(0, 100, 50, 200));
1547
1548 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kExpectedDirtyRegion));
1549 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kExpectedAboveCoveredRegion));
1550 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kExpectedAboveOpaqueRegion));
1551
Lloyd Piquede196652020-01-22 17:29:58 -08001552 EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kExpectedLayerVisibleRegion));
1553 EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion,
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001554 RegionEq(kExpectedLayerVisibleNonTransparentRegion));
Lloyd Piquede196652020-01-22 17:29:58 -08001555 EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kExpectedLayerCoveredRegion));
1556 EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion,
1557 RegionEq(kExpectedLayerVisibleRegion));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001558}
Lloyd Piqueb62cebc2019-11-20 18:31:52 -08001559
Vishnu Naira483b4a2019-12-12 15:07:52 -08001560TEST_F(OutputEnsureOutputLayerIfVisibleTest, coverageAccumulatesWithShadowsTest) {
1561 ui::Transform translate;
1562 translate.set(50, 50);
Lloyd Piquede196652020-01-22 17:29:58 -08001563 mLayer.layerFEState.geomLayerTransform = translate;
1564 mLayer.layerFEState.shadowRadius = 10.0f;
Vishnu Naira483b4a2019-12-12 15:07:52 -08001565
1566 mCoverageState.dirtyRegion = Region(Rect(0, 0, 500, 500));
1567 // half of the layer including the casting shadow is covered and opaque
1568 mCoverageState.aboveCoveredLayers = Region(Rect(40, 40, 100, 260));
1569 mCoverageState.aboveOpaqueLayers = Region(Rect(40, 40, 100, 260));
1570
Lloyd Piquede196652020-01-22 17:29:58 -08001571 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(0u), Eq(mLayer.layerFE)))
1572 .WillOnce(Return(&mLayer.outputLayer));
Vishnu Naira483b4a2019-12-12 15:07:52 -08001573
Lloyd Piquede196652020-01-22 17:29:58 -08001574 ensureOutputLayerIfVisible();
Vishnu Naira483b4a2019-12-12 15:07:52 -08001575
1576 const Region kExpectedDirtyRegion = Region(Rect(0, 0, 500, 500));
1577 const Region kExpectedAboveCoveredRegion = Region(Rect(40, 40, 160, 260));
1578 // add starting opaque region to the opaque half of the casting layer bounds
1579 const Region kExpectedAboveOpaqueRegion =
1580 Region(Rect(40, 40, 100, 260)).orSelf(Rect(100, 50, 150, 250));
1581 const Region kExpectedLayerVisibleRegion = Region(Rect(100, 40, 160, 260));
1582 const Region kExpectedoutputSpaceLayerVisibleRegion = Region(Rect(100, 50, 150, 250));
1583 const Region kExpectedLayerCoveredRegion = Region(Rect(40, 40, 100, 260));
1584 const Region kExpectedLayerVisibleNonTransparentRegion = Region(Rect(100, 40, 160, 260));
1585 const Region kExpectedLayerShadowRegion =
1586 Region(Rect(40, 40, 160, 260)).subtractSelf(Rect(50, 50, 150, 250));
1587
1588 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kExpectedDirtyRegion));
1589 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kExpectedAboveCoveredRegion));
1590 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kExpectedAboveOpaqueRegion));
1591
Lloyd Piquede196652020-01-22 17:29:58 -08001592 EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kExpectedLayerVisibleRegion));
1593 EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion,
Vishnu Naira483b4a2019-12-12 15:07:52 -08001594 RegionEq(kExpectedLayerVisibleNonTransparentRegion));
Lloyd Piquede196652020-01-22 17:29:58 -08001595 EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kExpectedLayerCoveredRegion));
1596 EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion,
Vishnu Naira483b4a2019-12-12 15:07:52 -08001597 RegionEq(kExpectedoutputSpaceLayerVisibleRegion));
Lloyd Piquede196652020-01-22 17:29:58 -08001598 EXPECT_THAT(mLayer.outputLayerState.shadowRegion, RegionEq(kExpectedLayerShadowRegion));
Vishnu Naira483b4a2019-12-12 15:07:52 -08001599 EXPECT_FALSE(kExpectedLayerVisibleRegion.subtract(kExpectedLayerShadowRegion).isEmpty());
1600}
1601
1602TEST_F(OutputEnsureOutputLayerIfVisibleTest, shadowRegionOnlyTest) {
1603 ui::Transform translate;
1604 translate.set(50, 50);
Lloyd Piquede196652020-01-22 17:29:58 -08001605 mLayer.layerFEState.geomLayerTransform = translate;
1606 mLayer.layerFEState.shadowRadius = 10.0f;
Vishnu Naira483b4a2019-12-12 15:07:52 -08001607
1608 mCoverageState.dirtyRegion = Region(Rect(0, 0, 500, 500));
1609 // Casting layer is covered by an opaque region leaving only part of its shadow to be drawn
1610 mCoverageState.aboveCoveredLayers = Region(Rect(40, 40, 150, 260));
1611 mCoverageState.aboveOpaqueLayers = Region(Rect(40, 40, 150, 260));
1612
Lloyd Piquede196652020-01-22 17:29:58 -08001613 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(0u), Eq(mLayer.layerFE)))
1614 .WillOnce(Return(&mLayer.outputLayer));
Vishnu Naira483b4a2019-12-12 15:07:52 -08001615
Lloyd Piquede196652020-01-22 17:29:58 -08001616 ensureOutputLayerIfVisible();
Vishnu Naira483b4a2019-12-12 15:07:52 -08001617
1618 const Region kExpectedLayerVisibleRegion = Region(Rect(150, 40, 160, 260));
1619 const Region kExpectedLayerShadowRegion =
1620 Region(Rect(40, 40, 160, 260)).subtractSelf(Rect(50, 50, 150, 250));
1621
Lloyd Piquede196652020-01-22 17:29:58 -08001622 EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kExpectedLayerVisibleRegion));
1623 EXPECT_THAT(mLayer.outputLayerState.shadowRegion, RegionEq(kExpectedLayerShadowRegion));
Vishnu Naira483b4a2019-12-12 15:07:52 -08001624 EXPECT_TRUE(kExpectedLayerVisibleRegion.subtract(kExpectedLayerShadowRegion).isEmpty());
1625}
1626
Marin Shalamanove67fcd02020-07-01 13:25:38 +00001627TEST_F(OutputEnsureOutputLayerIfVisibleTest, takesNotSoEarlyOutifLayerWithShadowIsCovered) {
Vishnu Naira483b4a2019-12-12 15:07:52 -08001628 ui::Transform translate;
1629 translate.set(50, 50);
Lloyd Piquede196652020-01-22 17:29:58 -08001630 mLayer.layerFEState.geomLayerTransform = translate;
1631 mLayer.layerFEState.shadowRadius = 10.0f;
Vishnu Naira483b4a2019-12-12 15:07:52 -08001632
1633 mCoverageState.dirtyRegion = Region(Rect(0, 0, 500, 500));
1634 // Casting layer and its shadows are covered by an opaque region
1635 mCoverageState.aboveCoveredLayers = Region(Rect(40, 40, 160, 260));
1636 mCoverageState.aboveOpaqueLayers = Region(Rect(40, 40, 160, 260));
1637
Lloyd Piquede196652020-01-22 17:29:58 -08001638 ensureOutputLayerIfVisible();
Vishnu Naira483b4a2019-12-12 15:07:52 -08001639}
1640
Lloyd Piqueb62cebc2019-11-20 18:31:52 -08001641/*
Lloyd Piquefaa3f192019-11-14 14:05:09 -08001642 * Output::present()
1643 */
1644
1645struct OutputPresentTest : public testing::Test {
1646 struct OutputPartialMock : public OutputPartialMockBase {
Lloyd Pique739afaf2019-11-21 16:40:05 -08001647 // Sets up the helper functions called by the function under test to use
1648 // mock implementations.
Lloyd Piquefaa3f192019-11-14 14:05:09 -08001649 MOCK_METHOD1(updateColorProfile, void(const compositionengine::CompositionRefreshArgs&));
Dan Stoza269dc4d2021-01-15 15:07:43 -08001650 MOCK_METHOD1(updateCompositionState,
Lloyd Piquefaa3f192019-11-14 14:05:09 -08001651 void(const compositionengine::CompositionRefreshArgs&));
Dan Stoza269dc4d2021-01-15 15:07:43 -08001652 MOCK_METHOD0(planComposition, void());
1653 MOCK_METHOD1(writeCompositionState, void(const compositionengine::CompositionRefreshArgs&));
Lloyd Piquefaa3f192019-11-14 14:05:09 -08001654 MOCK_METHOD1(setColorTransform, void(const compositionengine::CompositionRefreshArgs&));
1655 MOCK_METHOD0(beginFrame, void());
1656 MOCK_METHOD0(prepareFrame, void());
1657 MOCK_METHOD1(devOptRepaintFlash, void(const compositionengine::CompositionRefreshArgs&));
1658 MOCK_METHOD1(finishFrame, void(const compositionengine::CompositionRefreshArgs&));
1659 MOCK_METHOD0(postFramebuffer, void());
Dan Stoza6166c312021-01-15 16:34:05 -08001660 MOCK_METHOD0(renderCachedSets, void());
Lloyd Piquefaa3f192019-11-14 14:05:09 -08001661 };
1662
1663 StrictMock<OutputPartialMock> mOutput;
1664};
1665
1666TEST_F(OutputPresentTest, justInvokesChildFunctionsInSequence) {
1667 CompositionRefreshArgs args;
1668
1669 InSequence seq;
1670 EXPECT_CALL(mOutput, updateColorProfile(Ref(args)));
Dan Stoza269dc4d2021-01-15 15:07:43 -08001671 EXPECT_CALL(mOutput, updateCompositionState(Ref(args)));
1672 EXPECT_CALL(mOutput, planComposition());
1673 EXPECT_CALL(mOutput, writeCompositionState(Ref(args)));
Lloyd Piquefaa3f192019-11-14 14:05:09 -08001674 EXPECT_CALL(mOutput, setColorTransform(Ref(args)));
1675 EXPECT_CALL(mOutput, beginFrame());
1676 EXPECT_CALL(mOutput, prepareFrame());
1677 EXPECT_CALL(mOutput, devOptRepaintFlash(Ref(args)));
1678 EXPECT_CALL(mOutput, finishFrame(Ref(args)));
1679 EXPECT_CALL(mOutput, postFramebuffer());
Dan Stoza6166c312021-01-15 16:34:05 -08001680 EXPECT_CALL(mOutput, renderCachedSets());
Lloyd Piquefaa3f192019-11-14 14:05:09 -08001681
1682 mOutput.present(args);
1683}
1684
1685/*
1686 * Output::updateColorProfile()
1687 */
1688
Lloyd Pique17ca7422019-11-14 14:24:10 -08001689struct OutputUpdateColorProfileTest : public testing::Test {
1690 using TestType = OutputUpdateColorProfileTest;
1691
1692 struct OutputPartialMock : public OutputPartialMockBase {
Lloyd Pique739afaf2019-11-21 16:40:05 -08001693 // Sets up the helper functions called by the function under test to use
1694 // mock implementations.
Lloyd Pique17ca7422019-11-14 14:24:10 -08001695 MOCK_METHOD1(setColorProfile, void(const ColorProfile&));
1696 };
1697
1698 struct Layer {
1699 Layer() {
Ady Abrahameca9d752021-03-03 12:20:00 -08001700 EXPECT_CALL(mOutputLayer, getLayerFE()).WillRepeatedly(ReturnRef(*mLayerFE));
1701 EXPECT_CALL(*mLayerFE, getCompositionState()).WillRepeatedly(Return(&mLayerFEState));
Lloyd Pique17ca7422019-11-14 14:24:10 -08001702 }
1703
1704 StrictMock<mock::OutputLayer> mOutputLayer;
Ady Abrahameca9d752021-03-03 12:20:00 -08001705 sp<StrictMock<mock::LayerFE>> mLayerFE = sp<StrictMock<mock::LayerFE>>::make();
Lloyd Pique17ca7422019-11-14 14:24:10 -08001706 LayerFECompositionState mLayerFEState;
1707 };
1708
1709 OutputUpdateColorProfileTest() {
1710 mOutput.setDisplayColorProfileForTest(
1711 std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile));
1712 mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
1713
1714 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0))
1715 .WillRepeatedly(Return(&mLayer1.mOutputLayer));
1716 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(1))
1717 .WillRepeatedly(Return(&mLayer2.mOutputLayer));
1718 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(2))
1719 .WillRepeatedly(Return(&mLayer3.mOutputLayer));
1720 }
1721
1722 struct ExecuteState : public CallOrderStateMachineHelper<TestType, ExecuteState> {
1723 void execute() { getInstance()->mOutput.updateColorProfile(getInstance()->mRefreshArgs); }
1724 };
1725
1726 mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>();
1727 mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>();
1728 StrictMock<OutputPartialMock> mOutput;
1729
1730 Layer mLayer1;
1731 Layer mLayer2;
1732 Layer mLayer3;
1733
1734 CompositionRefreshArgs mRefreshArgs;
1735};
1736
1737// TODO(b/144522012): Refactor Output::updateColorProfile and the related code
1738// to make it easier to write unit tests.
1739
1740TEST_F(OutputUpdateColorProfileTest, setsAColorProfileWhenUnmanaged) {
1741 // When the outputColorSetting is set to kUnmanaged, the implementation sets
1742 // a simple default color profile without looking at anything else.
1743
Lloyd Pique0a456232020-01-16 17:51:13 -08001744 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(3u));
Lloyd Pique17ca7422019-11-14 14:24:10 -08001745 EXPECT_CALL(mOutput,
1746 setColorProfile(ColorProfileEq(
1747 ColorProfile{ui::ColorMode::NATIVE, ui::Dataspace::UNKNOWN,
1748 ui::RenderIntent::COLORIMETRIC, ui::Dataspace::UNKNOWN})));
1749
1750 mRefreshArgs.outputColorSetting = OutputColorSetting::kUnmanaged;
1751 mRefreshArgs.colorSpaceAgnosticDataspace = ui::Dataspace::UNKNOWN;
1752
1753 mOutput.updateColorProfile(mRefreshArgs);
1754}
1755
1756struct OutputUpdateColorProfileTest_GetBestColorModeResultBecomesSetProfile
1757 : public OutputUpdateColorProfileTest {
1758 OutputUpdateColorProfileTest_GetBestColorModeResultBecomesSetProfile() {
Lloyd Pique0a456232020-01-16 17:51:13 -08001759 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(0u));
Lloyd Pique17ca7422019-11-14 14:24:10 -08001760 mRefreshArgs.outputColorSetting = OutputColorSetting::kEnhanced;
1761 mRefreshArgs.colorSpaceAgnosticDataspace = ui::Dataspace::UNKNOWN;
1762 }
1763
1764 struct ExpectBestColorModeCallResultUsedToSetColorProfileState
1765 : public CallOrderStateMachineHelper<
1766 TestType, ExpectBestColorModeCallResultUsedToSetColorProfileState> {
1767 [[nodiscard]] auto expectBestColorModeCallResultUsedToSetColorProfile(
1768 ui::ColorMode colorMode, ui::Dataspace dataspace, ui::RenderIntent renderIntent) {
1769 EXPECT_CALL(*getInstance()->mDisplayColorProfile,
1770 getBestColorMode(ui::Dataspace::V0_SRGB, ui::RenderIntent::ENHANCE, _, _,
1771 _))
1772 .WillOnce(DoAll(SetArgPointee<2>(dataspace), SetArgPointee<3>(colorMode),
1773 SetArgPointee<4>(renderIntent)));
1774 EXPECT_CALL(getInstance()->mOutput,
1775 setColorProfile(
1776 ColorProfileEq(ColorProfile{colorMode, dataspace, renderIntent,
1777 ui::Dataspace::UNKNOWN})));
1778 return nextState<ExecuteState>();
1779 }
1780 };
1781
1782 // Call this member function to start using the mini-DSL defined above.
1783 [[nodiscard]] auto verify() {
1784 return ExpectBestColorModeCallResultUsedToSetColorProfileState::make(this);
1785 }
1786};
1787
1788TEST_F(OutputUpdateColorProfileTest_GetBestColorModeResultBecomesSetProfile,
1789 Native_Unknown_Colorimetric_Set) {
1790 verify().expectBestColorModeCallResultUsedToSetColorProfile(ui::ColorMode::NATIVE,
1791 ui::Dataspace::UNKNOWN,
1792 ui::RenderIntent::COLORIMETRIC)
1793 .execute();
1794}
1795
1796TEST_F(OutputUpdateColorProfileTest_GetBestColorModeResultBecomesSetProfile,
1797 DisplayP3_DisplayP3_Enhance_Set) {
1798 verify().expectBestColorModeCallResultUsedToSetColorProfile(ui::ColorMode::DISPLAY_P3,
1799 ui::Dataspace::DISPLAY_P3,
1800 ui::RenderIntent::ENHANCE)
1801 .execute();
1802}
1803
1804struct OutputUpdateColorProfileTest_ColorSpaceAgnosticeDataspaceAffectsSetColorProfile
1805 : public OutputUpdateColorProfileTest {
1806 OutputUpdateColorProfileTest_ColorSpaceAgnosticeDataspaceAffectsSetColorProfile() {
Lloyd Pique0a456232020-01-16 17:51:13 -08001807 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(0u));
Lloyd Pique17ca7422019-11-14 14:24:10 -08001808 EXPECT_CALL(*mDisplayColorProfile,
1809 getBestColorMode(ui::Dataspace::V0_SRGB, ui::RenderIntent::ENHANCE, _, _, _))
1810 .WillRepeatedly(DoAll(SetArgPointee<2>(ui::Dataspace::UNKNOWN),
1811 SetArgPointee<3>(ui::ColorMode::NATIVE),
1812 SetArgPointee<4>(ui::RenderIntent::COLORIMETRIC)));
1813 mRefreshArgs.outputColorSetting = OutputColorSetting::kEnhanced;
1814 }
1815
1816 struct IfColorSpaceAgnosticDataspaceSetToState
1817 : public CallOrderStateMachineHelper<TestType, IfColorSpaceAgnosticDataspaceSetToState> {
1818 [[nodiscard]] auto ifColorSpaceAgnosticDataspaceSetTo(ui::Dataspace dataspace) {
1819 getInstance()->mRefreshArgs.colorSpaceAgnosticDataspace = dataspace;
1820 return nextState<ThenExpectSetColorProfileCallUsesColorSpaceAgnosticDataspaceState>();
1821 }
1822 };
1823
1824 struct ThenExpectSetColorProfileCallUsesColorSpaceAgnosticDataspaceState
1825 : public CallOrderStateMachineHelper<
1826 TestType, ThenExpectSetColorProfileCallUsesColorSpaceAgnosticDataspaceState> {
1827 [[nodiscard]] auto thenExpectSetColorProfileCallUsesColorSpaceAgnosticDataspace(
1828 ui::Dataspace dataspace) {
1829 EXPECT_CALL(getInstance()->mOutput,
1830 setColorProfile(ColorProfileEq(
1831 ColorProfile{ui::ColorMode::NATIVE, ui::Dataspace::UNKNOWN,
1832 ui::RenderIntent::COLORIMETRIC, dataspace})));
1833 return nextState<ExecuteState>();
1834 }
1835 };
1836
1837 // Call this member function to start using the mini-DSL defined above.
1838 [[nodiscard]] auto verify() { return IfColorSpaceAgnosticDataspaceSetToState::make(this); }
1839};
1840
1841TEST_F(OutputUpdateColorProfileTest_ColorSpaceAgnosticeDataspaceAffectsSetColorProfile, DisplayP3) {
1842 verify().ifColorSpaceAgnosticDataspaceSetTo(ui::Dataspace::DISPLAY_P3)
1843 .thenExpectSetColorProfileCallUsesColorSpaceAgnosticDataspace(ui::Dataspace::DISPLAY_P3)
1844 .execute();
1845}
1846
1847TEST_F(OutputUpdateColorProfileTest_ColorSpaceAgnosticeDataspaceAffectsSetColorProfile, V0_SRGB) {
1848 verify().ifColorSpaceAgnosticDataspaceSetTo(ui::Dataspace::V0_SRGB)
1849 .thenExpectSetColorProfileCallUsesColorSpaceAgnosticDataspace(ui::Dataspace::V0_SRGB)
1850 .execute();
1851}
1852
1853struct OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference
1854 : public OutputUpdateColorProfileTest {
1855 // Internally the implementation looks through the dataspaces of all the
1856 // visible layers. The topmost one that also has an actual dataspace
1857 // preference set is used to drive subsequent choices.
1858
1859 OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference() {
1860 mRefreshArgs.outputColorSetting = OutputColorSetting::kEnhanced;
1861 mRefreshArgs.colorSpaceAgnosticDataspace = ui::Dataspace::UNKNOWN;
1862
Lloyd Pique0a456232020-01-16 17:51:13 -08001863 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(3u));
Lloyd Pique17ca7422019-11-14 14:24:10 -08001864 EXPECT_CALL(mOutput, setColorProfile(_)).WillRepeatedly(Return());
1865 }
1866
1867 struct IfTopLayerDataspaceState
1868 : public CallOrderStateMachineHelper<TestType, IfTopLayerDataspaceState> {
1869 [[nodiscard]] auto ifTopLayerIs(ui::Dataspace dataspace) {
1870 getInstance()->mLayer3.mLayerFEState.dataspace = dataspace;
1871 return nextState<AndIfMiddleLayerDataspaceState>();
1872 }
1873 [[nodiscard]] auto ifTopLayerHasNoPreference() {
1874 return ifTopLayerIs(ui::Dataspace::UNKNOWN);
1875 }
1876 };
1877
1878 struct AndIfMiddleLayerDataspaceState
1879 : public CallOrderStateMachineHelper<TestType, AndIfMiddleLayerDataspaceState> {
1880 [[nodiscard]] auto andIfMiddleLayerIs(ui::Dataspace dataspace) {
1881 getInstance()->mLayer2.mLayerFEState.dataspace = dataspace;
1882 return nextState<AndIfBottomLayerDataspaceState>();
1883 }
1884 [[nodiscard]] auto andIfMiddleLayerHasNoPreference() {
1885 return andIfMiddleLayerIs(ui::Dataspace::UNKNOWN);
1886 }
1887 };
1888
1889 struct AndIfBottomLayerDataspaceState
1890 : public CallOrderStateMachineHelper<TestType, AndIfBottomLayerDataspaceState> {
1891 [[nodiscard]] auto andIfBottomLayerIs(ui::Dataspace dataspace) {
1892 getInstance()->mLayer1.mLayerFEState.dataspace = dataspace;
1893 return nextState<ThenExpectBestColorModeCallUsesState>();
1894 }
1895 [[nodiscard]] auto andIfBottomLayerHasNoPreference() {
1896 return andIfBottomLayerIs(ui::Dataspace::UNKNOWN);
1897 }
1898 };
1899
1900 struct ThenExpectBestColorModeCallUsesState
1901 : public CallOrderStateMachineHelper<TestType, ThenExpectBestColorModeCallUsesState> {
1902 [[nodiscard]] auto thenExpectBestColorModeCallUses(ui::Dataspace dataspace) {
1903 EXPECT_CALL(*getInstance()->mDisplayColorProfile,
1904 getBestColorMode(dataspace, _, _, _, _));
1905 return nextState<ExecuteState>();
1906 }
1907 };
1908
1909 // Call this member function to start using the mini-DSL defined above.
1910 [[nodiscard]] auto verify() { return IfTopLayerDataspaceState::make(this); }
1911};
1912
1913TEST_F(OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference,
1914 noStrongLayerPrefenceUses_V0_SRGB) {
1915 // If none of the layers indicate a preference, then V0_SRGB is the
1916 // preferred choice (subject to additional checks).
1917 verify().ifTopLayerHasNoPreference()
1918 .andIfMiddleLayerHasNoPreference()
1919 .andIfBottomLayerHasNoPreference()
1920 .thenExpectBestColorModeCallUses(ui::Dataspace::V0_SRGB)
1921 .execute();
1922}
1923
1924TEST_F(OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference,
1925 ifTopmostUses_DisplayP3_Then_DisplayP3_Chosen) {
1926 // If only the topmost layer has a preference, then that is what is chosen.
1927 verify().ifTopLayerIs(ui::Dataspace::DISPLAY_P3)
1928 .andIfMiddleLayerHasNoPreference()
1929 .andIfBottomLayerHasNoPreference()
1930 .thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_P3)
1931 .execute();
1932}
1933
1934TEST_F(OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference,
1935 ifMiddleUses_DisplayP3_Then_DisplayP3_Chosen) {
1936 // If only the middle layer has a preference, that that is what is chosen.
1937 verify().ifTopLayerHasNoPreference()
1938 .andIfMiddleLayerIs(ui::Dataspace::DISPLAY_P3)
1939 .andIfBottomLayerHasNoPreference()
1940 .thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_P3)
1941 .execute();
1942}
1943
1944TEST_F(OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference,
1945 ifBottomUses_DisplayP3_Then_DisplayP3_Chosen) {
1946 // If only the middle layer has a preference, that that is what is chosen.
1947 verify().ifTopLayerHasNoPreference()
1948 .andIfMiddleLayerHasNoPreference()
1949 .andIfBottomLayerIs(ui::Dataspace::DISPLAY_P3)
1950 .thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_P3)
1951 .execute();
1952}
1953
1954TEST_F(OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference,
1955 ifTopUses_DisplayBT2020_AndBottomUses_DisplayP3_Then_DisplayBT2020_Chosen) {
1956 // If multiple layers have a preference, the topmost value is what is used.
1957 verify().ifTopLayerIs(ui::Dataspace::DISPLAY_BT2020)
1958 .andIfMiddleLayerHasNoPreference()
1959 .andIfBottomLayerIs(ui::Dataspace::DISPLAY_P3)
1960 .thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_BT2020)
1961 .execute();
1962}
1963
1964TEST_F(OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference,
1965 ifTopUses_DisplayP3_AndBottomUses_V0_SRGB_Then_DisplayP3_Chosen) {
1966 // If multiple layers have a preference, the topmost value is what is used.
1967 verify().ifTopLayerIs(ui::Dataspace::DISPLAY_P3)
1968 .andIfMiddleLayerHasNoPreference()
1969 .andIfBottomLayerIs(ui::Dataspace::DISPLAY_BT2020)
1970 .thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_P3)
1971 .execute();
1972}
1973
1974struct OutputUpdateColorProfileTest_ForceOutputColorOverrides
1975 : public OutputUpdateColorProfileTest {
1976 // If CompositionRefreshArgs::forceOutputColorMode is set to some specific
1977 // values, it overrides the layer dataspace choice.
1978
1979 OutputUpdateColorProfileTest_ForceOutputColorOverrides() {
1980 mRefreshArgs.outputColorSetting = OutputColorSetting::kEnhanced;
1981 mRefreshArgs.colorSpaceAgnosticDataspace = ui::Dataspace::UNKNOWN;
1982
1983 mLayer1.mLayerFEState.dataspace = ui::Dataspace::DISPLAY_BT2020;
1984
Lloyd Pique0a456232020-01-16 17:51:13 -08001985 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(1u));
Lloyd Pique17ca7422019-11-14 14:24:10 -08001986 EXPECT_CALL(mOutput, setColorProfile(_)).WillRepeatedly(Return());
1987 }
1988
1989 struct IfForceOutputColorModeState
1990 : public CallOrderStateMachineHelper<TestType, IfForceOutputColorModeState> {
1991 [[nodiscard]] auto ifForceOutputColorMode(ui::ColorMode colorMode) {
1992 getInstance()->mRefreshArgs.forceOutputColorMode = colorMode;
1993 return nextState<ThenExpectBestColorModeCallUsesState>();
1994 }
1995 [[nodiscard]] auto ifNoOverride() { return ifForceOutputColorMode(ui::ColorMode::NATIVE); }
1996 };
1997
1998 struct ThenExpectBestColorModeCallUsesState
1999 : public CallOrderStateMachineHelper<TestType, ThenExpectBestColorModeCallUsesState> {
2000 [[nodiscard]] auto thenExpectBestColorModeCallUses(ui::Dataspace dataspace) {
2001 EXPECT_CALL(*getInstance()->mDisplayColorProfile,
2002 getBestColorMode(dataspace, _, _, _, _));
2003 return nextState<ExecuteState>();
2004 }
2005 };
2006
2007 // Call this member function to start using the mini-DSL defined above.
2008 [[nodiscard]] auto verify() { return IfForceOutputColorModeState::make(this); }
2009};
2010
2011TEST_F(OutputUpdateColorProfileTest_ForceOutputColorOverrides, NoOverride_DoesNotOverride) {
2012 // By default the layer state is used to set the preferred dataspace
2013 verify().ifNoOverride()
2014 .thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_BT2020)
2015 .execute();
2016}
2017
2018TEST_F(OutputUpdateColorProfileTest_ForceOutputColorOverrides, SRGB_Override_USES_V0_SRGB) {
2019 // Setting ui::ColorMode::SRGB overrides it with ui::Dataspace::V0_SRGB
2020 verify().ifForceOutputColorMode(ui::ColorMode::SRGB)
2021 .thenExpectBestColorModeCallUses(ui::Dataspace::V0_SRGB)
2022 .execute();
2023}
2024
2025TEST_F(OutputUpdateColorProfileTest_ForceOutputColorOverrides, DisplayP3_Override_Uses_DisplayP3) {
2026 // Setting ui::ColorMode::DISPLAY_P3 overrides it with ui::Dataspace::DISPLAY_P3
2027 verify().ifForceOutputColorMode(ui::ColorMode::DISPLAY_P3)
2028 .thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_P3)
2029 .execute();
2030}
2031
2032// HDR output requires all layers to be compatible with the chosen HDR
2033// dataspace, along with there being proper support.
2034struct OutputUpdateColorProfileTest_Hdr : public OutputUpdateColorProfileTest {
2035 OutputUpdateColorProfileTest_Hdr() {
2036 mRefreshArgs.outputColorSetting = OutputColorSetting::kEnhanced;
2037 mRefreshArgs.colorSpaceAgnosticDataspace = ui::Dataspace::UNKNOWN;
Lloyd Pique0a456232020-01-16 17:51:13 -08002038 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(2u));
Lloyd Pique17ca7422019-11-14 14:24:10 -08002039 EXPECT_CALL(mOutput, setColorProfile(_)).WillRepeatedly(Return());
2040 }
2041
2042 static constexpr ui::Dataspace kNonHdrDataspace = ui::Dataspace::DISPLAY_P3;
2043 static constexpr ui::Dataspace BT2020_PQ = ui::Dataspace::BT2020_PQ;
2044 static constexpr ui::Dataspace BT2020_HLG = ui::Dataspace::BT2020_HLG;
2045 static constexpr ui::Dataspace DISPLAY_P3 = ui::Dataspace::DISPLAY_P3;
2046
2047 struct IfTopLayerDataspaceState
2048 : public CallOrderStateMachineHelper<TestType, IfTopLayerDataspaceState> {
2049 [[nodiscard]] auto ifTopLayerIs(ui::Dataspace dataspace) {
2050 getInstance()->mLayer2.mLayerFEState.dataspace = dataspace;
2051 return nextState<AndTopLayerCompositionTypeState>();
2052 }
2053 [[nodiscard]] auto ifTopLayerIsNotHdr() { return ifTopLayerIs(kNonHdrDataspace); }
2054 };
2055
2056 struct AndTopLayerCompositionTypeState
2057 : public CallOrderStateMachineHelper<TestType, AndTopLayerCompositionTypeState> {
2058 [[nodiscard]] auto andTopLayerIsREComposed(bool renderEngineComposed) {
2059 getInstance()->mLayer2.mLayerFEState.forceClientComposition = renderEngineComposed;
2060 return nextState<AndIfBottomLayerDataspaceState>();
2061 }
2062 };
2063
2064 struct AndIfBottomLayerDataspaceState
2065 : public CallOrderStateMachineHelper<TestType, AndIfBottomLayerDataspaceState> {
2066 [[nodiscard]] auto andIfBottomLayerIs(ui::Dataspace dataspace) {
2067 getInstance()->mLayer1.mLayerFEState.dataspace = dataspace;
2068 return nextState<AndBottomLayerCompositionTypeState>();
2069 }
2070 [[nodiscard]] auto andIfBottomLayerIsNotHdr() {
2071 return andIfBottomLayerIs(kNonHdrDataspace);
2072 }
2073 };
2074
2075 struct AndBottomLayerCompositionTypeState
2076 : public CallOrderStateMachineHelper<TestType, AndBottomLayerCompositionTypeState> {
2077 [[nodiscard]] auto andBottomLayerIsREComposed(bool renderEngineComposed) {
2078 getInstance()->mLayer1.mLayerFEState.forceClientComposition = renderEngineComposed;
2079 return nextState<AndIfHasLegacySupportState>();
2080 }
2081 };
2082
2083 struct AndIfHasLegacySupportState
2084 : public CallOrderStateMachineHelper<TestType, AndIfHasLegacySupportState> {
2085 [[nodiscard]] auto andIfLegacySupportFor(ui::Dataspace dataspace, bool legacySupport) {
2086 EXPECT_CALL(*getInstance()->mDisplayColorProfile, hasLegacyHdrSupport(dataspace))
2087 .WillOnce(Return(legacySupport));
2088 return nextState<ThenExpectBestColorModeCallUsesState>();
2089 }
2090 };
2091
2092 struct ThenExpectBestColorModeCallUsesState
2093 : public CallOrderStateMachineHelper<TestType, ThenExpectBestColorModeCallUsesState> {
2094 [[nodiscard]] auto thenExpectBestColorModeCallUses(ui::Dataspace dataspace) {
2095 EXPECT_CALL(*getInstance()->mDisplayColorProfile,
2096 getBestColorMode(dataspace, _, _, _, _));
2097 return nextState<ExecuteState>();
2098 }
2099 };
2100
2101 // Call this member function to start using the mini-DSL defined above.
2102 [[nodiscard]] auto verify() { return IfTopLayerDataspaceState::make(this); }
2103};
2104
2105TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_PQ_HW_Uses_PQ) {
2106 // If all layers use BT2020_PQ, and there are no other special conditions,
2107 // BT2020_PQ is used.
2108 verify().ifTopLayerIs(BT2020_PQ)
2109 .andTopLayerIsREComposed(false)
2110 .andIfBottomLayerIs(BT2020_PQ)
2111 .andBottomLayerIsREComposed(false)
2112 .andIfLegacySupportFor(BT2020_PQ, false)
2113 .thenExpectBestColorModeCallUses(BT2020_PQ)
2114 .execute();
2115}
2116
2117TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_PQ_HW_IfPQHasLegacySupport_Uses_DisplayP3) {
2118 // BT2020_PQ is not used if there is only legacy support for it.
2119 verify().ifTopLayerIs(BT2020_PQ)
2120 .andTopLayerIsREComposed(false)
2121 .andIfBottomLayerIs(BT2020_PQ)
2122 .andBottomLayerIsREComposed(false)
2123 .andIfLegacySupportFor(BT2020_PQ, true)
2124 .thenExpectBestColorModeCallUses(DISPLAY_P3)
2125 .execute();
2126}
2127
2128TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_PQ_RE_Uses_PQ) {
2129 // BT2020_PQ is still used if the bottom layer is RenderEngine composed.
2130 verify().ifTopLayerIs(BT2020_PQ)
2131 .andTopLayerIsREComposed(false)
2132 .andIfBottomLayerIs(BT2020_PQ)
2133 .andBottomLayerIsREComposed(true)
2134 .andIfLegacySupportFor(BT2020_PQ, false)
2135 .thenExpectBestColorModeCallUses(BT2020_PQ)
2136 .execute();
2137}
2138
2139TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_RE_On_PQ_HW_Uses_DisplayP3) {
2140 // BT2020_PQ is not used if the top layer is RenderEngine composed.
2141 verify().ifTopLayerIs(BT2020_PQ)
2142 .andTopLayerIsREComposed(true)
2143 .andIfBottomLayerIs(BT2020_PQ)
2144 .andBottomLayerIsREComposed(false)
2145 .andIfLegacySupportFor(BT2020_PQ, false)
2146 .thenExpectBestColorModeCallUses(DISPLAY_P3)
2147 .execute();
2148}
2149
2150TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_HLG_HW_Uses_PQ) {
2151 // If there is mixed HLG/PQ use, and the topmost layer is PQ, then PQ is used if there
2152 // are no other special conditions.
2153 verify().ifTopLayerIs(BT2020_PQ)
2154 .andTopLayerIsREComposed(false)
2155 .andIfBottomLayerIs(BT2020_HLG)
2156 .andBottomLayerIsREComposed(false)
2157 .andIfLegacySupportFor(BT2020_PQ, false)
2158 .thenExpectBestColorModeCallUses(BT2020_PQ)
2159 .execute();
2160}
2161
2162TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_HLG_HW_IfPQHasLegacySupport_Uses_DisplayP3) {
2163 // BT2020_PQ is not used if there is only legacy support for it.
2164 verify().ifTopLayerIs(BT2020_PQ)
2165 .andTopLayerIsREComposed(false)
2166 .andIfBottomLayerIs(BT2020_HLG)
2167 .andBottomLayerIsREComposed(false)
2168 .andIfLegacySupportFor(BT2020_PQ, true)
2169 .thenExpectBestColorModeCallUses(DISPLAY_P3)
2170 .execute();
2171}
2172
2173TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_HLG_RE_Uses_PQ) {
2174 // BT2020_PQ is used if the bottom HLG layer is RenderEngine composed.
2175 verify().ifTopLayerIs(BT2020_PQ)
2176 .andTopLayerIsREComposed(false)
2177 .andIfBottomLayerIs(BT2020_HLG)
2178 .andBottomLayerIsREComposed(true)
2179 .andIfLegacySupportFor(BT2020_PQ, false)
2180 .thenExpectBestColorModeCallUses(BT2020_PQ)
2181 .execute();
2182}
2183
2184TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_RE_On_HLG_HW_Uses_DisplayP3) {
2185 // BT2020_PQ is not used if the top PQ layer is RenderEngine composed.
2186 verify().ifTopLayerIs(BT2020_PQ)
2187 .andTopLayerIsREComposed(true)
2188 .andIfBottomLayerIs(BT2020_HLG)
2189 .andBottomLayerIsREComposed(false)
2190 .andIfLegacySupportFor(BT2020_PQ, false)
2191 .thenExpectBestColorModeCallUses(DISPLAY_P3)
2192 .execute();
2193}
2194
2195TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_PQ_HW_Uses_PQ) {
2196 // If there is mixed HLG/PQ use, and the topmost layer is HLG, then PQ is
2197 // used if there are no other special conditions.
2198 verify().ifTopLayerIs(BT2020_HLG)
2199 .andTopLayerIsREComposed(false)
2200 .andIfBottomLayerIs(BT2020_PQ)
2201 .andBottomLayerIsREComposed(false)
2202 .andIfLegacySupportFor(BT2020_PQ, false)
2203 .thenExpectBestColorModeCallUses(BT2020_PQ)
2204 .execute();
2205}
2206
2207TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_PQ_HW_IfPQHasLegacySupport_Uses_DisplayP3) {
2208 // BT2020_PQ is not used if there is only legacy support for it.
2209 verify().ifTopLayerIs(BT2020_HLG)
2210 .andTopLayerIsREComposed(false)
2211 .andIfBottomLayerIs(BT2020_PQ)
2212 .andBottomLayerIsREComposed(false)
2213 .andIfLegacySupportFor(BT2020_PQ, true)
2214 .thenExpectBestColorModeCallUses(DISPLAY_P3)
2215 .execute();
2216}
2217
2218TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_PQ_RE_Uses_DisplayP3) {
2219 // BT2020_PQ is not used if the bottom PQ layer is RenderEngine composed.
2220 verify().ifTopLayerIs(BT2020_HLG)
2221 .andTopLayerIsREComposed(false)
2222 .andIfBottomLayerIs(BT2020_PQ)
2223 .andBottomLayerIsREComposed(true)
2224 .andIfLegacySupportFor(BT2020_PQ, false)
2225 .thenExpectBestColorModeCallUses(DISPLAY_P3)
2226 .execute();
2227}
2228
2229TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_RE_On_PQ_HW_Uses_PQ) {
2230 // BT2020_PQ is still used if the top HLG layer is RenderEngine composed.
2231 verify().ifTopLayerIs(BT2020_HLG)
2232 .andTopLayerIsREComposed(true)
2233 .andIfBottomLayerIs(BT2020_PQ)
2234 .andBottomLayerIsREComposed(false)
2235 .andIfLegacySupportFor(BT2020_PQ, false)
2236 .thenExpectBestColorModeCallUses(BT2020_PQ)
2237 .execute();
2238}
2239
2240TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_HLG_HW_Uses_HLG) {
2241 // If all layers use HLG then HLG is used if there are no other special
2242 // conditions.
2243 verify().ifTopLayerIs(BT2020_HLG)
2244 .andTopLayerIsREComposed(false)
2245 .andIfBottomLayerIs(BT2020_HLG)
2246 .andBottomLayerIsREComposed(false)
2247 .andIfLegacySupportFor(BT2020_HLG, false)
2248 .thenExpectBestColorModeCallUses(BT2020_HLG)
2249 .execute();
2250}
2251
2252TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_HLG_HW_IfPQHasLegacySupport_Uses_DisplayP3) {
2253 // BT2020_HLG is not used if there is legacy support for it.
2254 verify().ifTopLayerIs(BT2020_HLG)
2255 .andTopLayerIsREComposed(false)
2256 .andIfBottomLayerIs(BT2020_HLG)
2257 .andBottomLayerIsREComposed(false)
2258 .andIfLegacySupportFor(BT2020_HLG, true)
2259 .thenExpectBestColorModeCallUses(DISPLAY_P3)
2260 .execute();
2261}
2262
2263TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_HLG_RE_Uses_HLG) {
2264 // BT2020_HLG is used even if the bottom layer is client composed.
2265 verify().ifTopLayerIs(BT2020_HLG)
2266 .andTopLayerIsREComposed(false)
2267 .andIfBottomLayerIs(BT2020_HLG)
2268 .andBottomLayerIsREComposed(true)
2269 .andIfLegacySupportFor(BT2020_HLG, false)
2270 .thenExpectBestColorModeCallUses(BT2020_HLG)
2271 .execute();
2272}
2273
2274TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_RE_On_HLG_HW_Uses_HLG) {
2275 // BT2020_HLG is used even if the top layer is client composed.
2276 verify().ifTopLayerIs(BT2020_HLG)
2277 .andTopLayerIsREComposed(true)
2278 .andIfBottomLayerIs(BT2020_HLG)
2279 .andBottomLayerIsREComposed(false)
2280 .andIfLegacySupportFor(BT2020_HLG, false)
2281 .thenExpectBestColorModeCallUses(BT2020_HLG)
2282 .execute();
2283}
2284
2285TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_NonHdr_HW_Uses_PQ) {
2286 // Even if there are non-HDR layers present, BT2020_PQ can still be used.
2287 verify().ifTopLayerIs(BT2020_PQ)
2288 .andTopLayerIsREComposed(false)
2289 .andIfBottomLayerIsNotHdr()
2290 .andBottomLayerIsREComposed(false)
2291 .andIfLegacySupportFor(BT2020_PQ, false)
2292 .thenExpectBestColorModeCallUses(BT2020_PQ)
2293 .execute();
2294}
2295
2296TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_NonHdr_RE_Uses_HLG) {
2297 // If all layers use HLG then HLG is used if there are no other special
2298 // conditions.
2299 verify().ifTopLayerIs(BT2020_HLG)
2300 .andTopLayerIsREComposed(false)
2301 .andIfBottomLayerIsNotHdr()
2302 .andBottomLayerIsREComposed(true)
2303 .andIfLegacySupportFor(BT2020_HLG, false)
2304 .thenExpectBestColorModeCallUses(BT2020_HLG)
2305 .execute();
2306}
2307
2308struct OutputUpdateColorProfile_AffectsChosenRenderIntentTest
2309 : public OutputUpdateColorProfileTest {
2310 // The various values for CompositionRefreshArgs::outputColorSetting affect
2311 // the chosen renderIntent, along with whether the preferred dataspace is an
2312 // HDR dataspace or not.
2313
2314 OutputUpdateColorProfile_AffectsChosenRenderIntentTest() {
2315 mRefreshArgs.outputColorSetting = OutputColorSetting::kEnhanced;
2316 mRefreshArgs.colorSpaceAgnosticDataspace = ui::Dataspace::UNKNOWN;
2317 mLayer1.mLayerFEState.dataspace = ui::Dataspace::BT2020_PQ;
Lloyd Pique0a456232020-01-16 17:51:13 -08002318 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(1u));
Lloyd Pique17ca7422019-11-14 14:24:10 -08002319 EXPECT_CALL(mOutput, setColorProfile(_)).WillRepeatedly(Return());
2320 EXPECT_CALL(*mDisplayColorProfile, hasLegacyHdrSupport(ui::Dataspace::BT2020_PQ))
2321 .WillRepeatedly(Return(false));
2322 }
2323
2324 // The tests here involve enough state and GMock setup that using a mini-DSL
2325 // makes the tests much more readable, and allows the test to focus more on
2326 // the intent than on some of the details.
2327
2328 static constexpr ui::Dataspace kNonHdrDataspace = ui::Dataspace::DISPLAY_P3;
2329 static constexpr ui::Dataspace kHdrDataspace = ui::Dataspace::BT2020_PQ;
2330
2331 struct IfDataspaceChosenState
2332 : public CallOrderStateMachineHelper<TestType, IfDataspaceChosenState> {
2333 [[nodiscard]] auto ifDataspaceChosenIs(ui::Dataspace dataspace) {
2334 getInstance()->mLayer1.mLayerFEState.dataspace = dataspace;
2335 return nextState<AndOutputColorSettingState>();
2336 }
2337 [[nodiscard]] auto ifDataspaceChosenIsNonHdr() {
2338 return ifDataspaceChosenIs(kNonHdrDataspace);
2339 }
2340 [[nodiscard]] auto ifDataspaceChosenIsHdr() { return ifDataspaceChosenIs(kHdrDataspace); }
2341 };
2342
2343 struct AndOutputColorSettingState
2344 : public CallOrderStateMachineHelper<TestType, AndOutputColorSettingState> {
2345 [[nodiscard]] auto andOutputColorSettingIs(OutputColorSetting setting) {
2346 getInstance()->mRefreshArgs.outputColorSetting = setting;
2347 return nextState<ThenExpectBestColorModeCallUsesState>();
2348 }
2349 };
2350
2351 struct ThenExpectBestColorModeCallUsesState
2352 : public CallOrderStateMachineHelper<TestType, ThenExpectBestColorModeCallUsesState> {
2353 [[nodiscard]] auto thenExpectBestColorModeCallUses(ui::RenderIntent intent) {
2354 EXPECT_CALL(*getInstance()->mDisplayColorProfile,
2355 getBestColorMode(getInstance()->mLayer1.mLayerFEState.dataspace, intent, _,
2356 _, _));
2357 return nextState<ExecuteState>();
2358 }
2359 };
2360
2361 // Tests call one of these two helper member functions to start using the
2362 // mini-DSL defined above.
2363 [[nodiscard]] auto verify() { return IfDataspaceChosenState::make(this); }
2364};
2365
2366TEST_F(OutputUpdateColorProfile_AffectsChosenRenderIntentTest,
2367 Managed_NonHdr_Prefers_Colorimetric) {
2368 verify().ifDataspaceChosenIsNonHdr()
2369 .andOutputColorSettingIs(OutputColorSetting::kManaged)
2370 .thenExpectBestColorModeCallUses(ui::RenderIntent::COLORIMETRIC)
2371 .execute();
2372}
2373
2374TEST_F(OutputUpdateColorProfile_AffectsChosenRenderIntentTest,
2375 Managed_Hdr_Prefers_ToneMapColorimetric) {
2376 verify().ifDataspaceChosenIsHdr()
2377 .andOutputColorSettingIs(OutputColorSetting::kManaged)
2378 .thenExpectBestColorModeCallUses(ui::RenderIntent::TONE_MAP_COLORIMETRIC)
2379 .execute();
2380}
2381
2382TEST_F(OutputUpdateColorProfile_AffectsChosenRenderIntentTest, Enhanced_NonHdr_Prefers_Enhance) {
2383 verify().ifDataspaceChosenIsNonHdr()
2384 .andOutputColorSettingIs(OutputColorSetting::kEnhanced)
2385 .thenExpectBestColorModeCallUses(ui::RenderIntent::ENHANCE)
2386 .execute();
2387}
2388
2389TEST_F(OutputUpdateColorProfile_AffectsChosenRenderIntentTest,
2390 Enhanced_Hdr_Prefers_ToneMapEnhance) {
2391 verify().ifDataspaceChosenIsHdr()
2392 .andOutputColorSettingIs(OutputColorSetting::kEnhanced)
2393 .thenExpectBestColorModeCallUses(ui::RenderIntent::TONE_MAP_ENHANCE)
2394 .execute();
2395}
2396
2397TEST_F(OutputUpdateColorProfile_AffectsChosenRenderIntentTest, Vendor_NonHdr_Prefers_Vendor) {
2398 verify().ifDataspaceChosenIsNonHdr()
2399 .andOutputColorSettingIs(kVendorSpecifiedOutputColorSetting)
2400 .thenExpectBestColorModeCallUses(
2401 static_cast<ui::RenderIntent>(kVendorSpecifiedOutputColorSetting))
2402 .execute();
2403}
2404
2405TEST_F(OutputUpdateColorProfile_AffectsChosenRenderIntentTest, Vendor_Hdr_Prefers_Vendor) {
2406 verify().ifDataspaceChosenIsHdr()
2407 .andOutputColorSettingIs(kVendorSpecifiedOutputColorSetting)
2408 .thenExpectBestColorModeCallUses(
2409 static_cast<ui::RenderIntent>(kVendorSpecifiedOutputColorSetting))
2410 .execute();
2411}
Lloyd Piquefaa3f192019-11-14 14:05:09 -08002412
2413/*
2414 * Output::beginFrame()
2415 */
2416
Lloyd Piquee5965952019-11-18 16:16:32 -08002417struct OutputBeginFrameTest : public ::testing::Test {
2418 using TestType = OutputBeginFrameTest;
2419
2420 struct OutputPartialMock : public OutputPartialMockBase {
Lloyd Pique739afaf2019-11-21 16:40:05 -08002421 // Sets up the helper functions called by the function under test to use
2422 // mock implementations.
Lloyd Piquee5965952019-11-18 16:16:32 -08002423 MOCK_CONST_METHOD1(getDirtyRegion, Region(bool));
2424 };
2425
2426 OutputBeginFrameTest() {
2427 mOutput.setDisplayColorProfileForTest(
2428 std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile));
2429 mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
2430 }
2431
2432 struct IfGetDirtyRegionExpectationState
2433 : public CallOrderStateMachineHelper<TestType, IfGetDirtyRegionExpectationState> {
2434 [[nodiscard]] auto ifGetDirtyRegionReturns(Region dirtyRegion) {
2435 EXPECT_CALL(getInstance()->mOutput, getDirtyRegion(false))
2436 .WillOnce(Return(dirtyRegion));
2437 return nextState<AndIfGetOutputLayerCountExpectationState>();
2438 }
2439 };
2440
2441 struct AndIfGetOutputLayerCountExpectationState
2442 : public CallOrderStateMachineHelper<TestType, AndIfGetOutputLayerCountExpectationState> {
2443 [[nodiscard]] auto andIfGetOutputLayerCountReturns(size_t layerCount) {
2444 EXPECT_CALL(getInstance()->mOutput, getOutputLayerCount()).WillOnce(Return(layerCount));
2445 return nextState<AndIfLastCompositionHadVisibleLayersState>();
2446 }
2447 };
2448
2449 struct AndIfLastCompositionHadVisibleLayersState
2450 : public CallOrderStateMachineHelper<TestType,
2451 AndIfLastCompositionHadVisibleLayersState> {
2452 [[nodiscard]] auto andIfLastCompositionHadVisibleLayersIs(bool hadOutputLayers) {
2453 getInstance()->mOutput.mState.lastCompositionHadVisibleLayers = hadOutputLayers;
2454 return nextState<ThenExpectRenderSurfaceBeginFrameCallState>();
2455 }
2456 };
2457
2458 struct ThenExpectRenderSurfaceBeginFrameCallState
2459 : public CallOrderStateMachineHelper<TestType,
2460 ThenExpectRenderSurfaceBeginFrameCallState> {
2461 [[nodiscard]] auto thenExpectRenderSurfaceBeginFrameCall(bool mustRecompose) {
2462 EXPECT_CALL(*getInstance()->mRenderSurface, beginFrame(mustRecompose));
2463 return nextState<ExecuteState>();
2464 }
2465 };
2466
2467 struct ExecuteState : public CallOrderStateMachineHelper<TestType, ExecuteState> {
2468 [[nodiscard]] auto execute() {
2469 getInstance()->mOutput.beginFrame();
2470 return nextState<CheckPostconditionHadVisibleLayersState>();
2471 }
2472 };
2473
2474 struct CheckPostconditionHadVisibleLayersState
2475 : public CallOrderStateMachineHelper<TestType, CheckPostconditionHadVisibleLayersState> {
2476 void checkPostconditionHadVisibleLayers(bool expected) {
2477 EXPECT_EQ(expected, getInstance()->mOutput.mState.lastCompositionHadVisibleLayers);
2478 }
2479 };
2480
2481 // Tests call one of these two helper member functions to start using the
2482 // mini-DSL defined above.
2483 [[nodiscard]] auto verify() { return IfGetDirtyRegionExpectationState::make(this); }
2484
2485 static const Region kEmptyRegion;
2486 static const Region kNotEmptyRegion;
2487
2488 mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>();
2489 mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>();
2490 StrictMock<OutputPartialMock> mOutput;
2491};
2492
2493const Region OutputBeginFrameTest::kEmptyRegion{Rect{0, 0, 0, 0}};
2494const Region OutputBeginFrameTest::kNotEmptyRegion{Rect{0, 0, 1, 1}};
2495
2496TEST_F(OutputBeginFrameTest, hasDirtyHasLayersHadLayersLastFrame) {
2497 verify().ifGetDirtyRegionReturns(kNotEmptyRegion)
2498 .andIfGetOutputLayerCountReturns(1u)
2499 .andIfLastCompositionHadVisibleLayersIs(true)
2500 .thenExpectRenderSurfaceBeginFrameCall(true)
2501 .execute()
2502 .checkPostconditionHadVisibleLayers(true);
2503}
2504
2505TEST_F(OutputBeginFrameTest, hasDirtyNotHasLayersHadLayersLastFrame) {
2506 verify().ifGetDirtyRegionReturns(kNotEmptyRegion)
2507 .andIfGetOutputLayerCountReturns(0u)
2508 .andIfLastCompositionHadVisibleLayersIs(true)
2509 .thenExpectRenderSurfaceBeginFrameCall(true)
2510 .execute()
2511 .checkPostconditionHadVisibleLayers(false);
2512}
2513
2514TEST_F(OutputBeginFrameTest, hasDirtyHasLayersNotHadLayersLastFrame) {
2515 verify().ifGetDirtyRegionReturns(kNotEmptyRegion)
2516 .andIfGetOutputLayerCountReturns(1u)
2517 .andIfLastCompositionHadVisibleLayersIs(false)
2518 .thenExpectRenderSurfaceBeginFrameCall(true)
2519 .execute()
2520 .checkPostconditionHadVisibleLayers(true);
2521}
2522
2523TEST_F(OutputBeginFrameTest, hasDirtyNotHasLayersNotHadLayersLastFrame) {
2524 verify().ifGetDirtyRegionReturns(kNotEmptyRegion)
2525 .andIfGetOutputLayerCountReturns(0u)
2526 .andIfLastCompositionHadVisibleLayersIs(false)
2527 .thenExpectRenderSurfaceBeginFrameCall(false)
2528 .execute()
2529 .checkPostconditionHadVisibleLayers(false);
2530}
2531
2532TEST_F(OutputBeginFrameTest, notHasDirtyHasLayersHadLayersLastFrame) {
2533 verify().ifGetDirtyRegionReturns(kEmptyRegion)
2534 .andIfGetOutputLayerCountReturns(1u)
2535 .andIfLastCompositionHadVisibleLayersIs(true)
2536 .thenExpectRenderSurfaceBeginFrameCall(false)
2537 .execute()
2538 .checkPostconditionHadVisibleLayers(true);
2539}
2540
2541TEST_F(OutputBeginFrameTest, notHasDirtyNotHasLayersHadLayersLastFrame) {
2542 verify().ifGetDirtyRegionReturns(kEmptyRegion)
2543 .andIfGetOutputLayerCountReturns(0u)
2544 .andIfLastCompositionHadVisibleLayersIs(true)
2545 .thenExpectRenderSurfaceBeginFrameCall(false)
2546 .execute()
2547 .checkPostconditionHadVisibleLayers(true);
2548}
2549
2550TEST_F(OutputBeginFrameTest, notHasDirtyHasLayersNotHadLayersLastFrame) {
2551 verify().ifGetDirtyRegionReturns(kEmptyRegion)
2552 .andIfGetOutputLayerCountReturns(1u)
2553 .andIfLastCompositionHadVisibleLayersIs(false)
2554 .thenExpectRenderSurfaceBeginFrameCall(false)
2555 .execute()
2556 .checkPostconditionHadVisibleLayers(false);
2557}
2558
2559TEST_F(OutputBeginFrameTest, notHasDirtyNotHasLayersNotHadLayersLastFrame) {
2560 verify().ifGetDirtyRegionReturns(kEmptyRegion)
2561 .andIfGetOutputLayerCountReturns(0u)
2562 .andIfLastCompositionHadVisibleLayersIs(false)
2563 .thenExpectRenderSurfaceBeginFrameCall(false)
2564 .execute()
2565 .checkPostconditionHadVisibleLayers(false);
2566}
2567
Lloyd Piquefaa3f192019-11-14 14:05:09 -08002568/*
2569 * Output::devOptRepaintFlash()
2570 */
2571
Lloyd Piquedb462d82019-11-19 17:58:46 -08002572struct OutputDevOptRepaintFlashTest : public testing::Test {
2573 struct OutputPartialMock : public OutputPartialMockBase {
Lloyd Pique739afaf2019-11-21 16:40:05 -08002574 // Sets up the helper functions called by the function under test to use
2575 // mock implementations.
Lloyd Piquedb462d82019-11-19 17:58:46 -08002576 MOCK_CONST_METHOD1(getDirtyRegion, Region(bool));
Lucas Dupin2dd6f392020-02-18 17:43:36 -08002577 MOCK_METHOD2(composeSurfaces,
2578 std::optional<base::unique_fd>(
2579 const Region&, const compositionengine::CompositionRefreshArgs&));
Lloyd Piquedb462d82019-11-19 17:58:46 -08002580 MOCK_METHOD0(postFramebuffer, void());
2581 MOCK_METHOD0(prepareFrame, void());
2582 };
2583
2584 OutputDevOptRepaintFlashTest() {
2585 mOutput.setDisplayColorProfileForTest(
2586 std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile));
2587 mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
2588 }
2589
2590 static const Region kEmptyRegion;
2591 static const Region kNotEmptyRegion;
2592
2593 StrictMock<OutputPartialMock> mOutput;
2594 mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>();
2595 mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>();
2596 CompositionRefreshArgs mRefreshArgs;
2597};
2598
2599const Region OutputDevOptRepaintFlashTest::kEmptyRegion{Rect{0, 0, 0, 0}};
2600const Region OutputDevOptRepaintFlashTest::kNotEmptyRegion{Rect{0, 0, 1, 1}};
2601
2602TEST_F(OutputDevOptRepaintFlashTest, doesNothingIfFlashDelayNotSet) {
2603 mRefreshArgs.devOptFlashDirtyRegionsDelay = {};
2604 mRefreshArgs.repaintEverything = true;
2605 mOutput.mState.isEnabled = true;
2606
2607 mOutput.devOptRepaintFlash(mRefreshArgs);
2608}
2609
2610TEST_F(OutputDevOptRepaintFlashTest, postsAndPreparesANewFrameIfNotEnabled) {
2611 mRefreshArgs.devOptFlashDirtyRegionsDelay = std::chrono::microseconds(1);
2612 mRefreshArgs.repaintEverything = true;
2613 mOutput.mState.isEnabled = false;
2614
2615 InSequence seq;
2616 EXPECT_CALL(mOutput, postFramebuffer());
2617 EXPECT_CALL(mOutput, prepareFrame());
2618
2619 mOutput.devOptRepaintFlash(mRefreshArgs);
2620}
2621
2622TEST_F(OutputDevOptRepaintFlashTest, postsAndPreparesANewFrameIfNotDirty) {
2623 mRefreshArgs.devOptFlashDirtyRegionsDelay = std::chrono::microseconds(1);
2624 mRefreshArgs.repaintEverything = true;
2625 mOutput.mState.isEnabled = true;
2626
2627 InSequence seq;
2628 EXPECT_CALL(mOutput, getDirtyRegion(true)).WillOnce(Return(kEmptyRegion));
2629 EXPECT_CALL(mOutput, postFramebuffer());
2630 EXPECT_CALL(mOutput, prepareFrame());
2631
2632 mOutput.devOptRepaintFlash(mRefreshArgs);
2633}
2634
2635TEST_F(OutputDevOptRepaintFlashTest, alsoComposesSurfacesAndQueuesABufferIfDirty) {
2636 mRefreshArgs.devOptFlashDirtyRegionsDelay = std::chrono::microseconds(1);
2637 mRefreshArgs.repaintEverything = false;
2638 mOutput.mState.isEnabled = true;
2639
2640 InSequence seq;
2641 EXPECT_CALL(mOutput, getDirtyRegion(false)).WillOnce(Return(kNotEmptyRegion));
Lucas Dupin2dd6f392020-02-18 17:43:36 -08002642 EXPECT_CALL(mOutput, composeSurfaces(RegionEq(kNotEmptyRegion), Ref(mRefreshArgs)));
Lloyd Piquedb462d82019-11-19 17:58:46 -08002643 EXPECT_CALL(*mRenderSurface, queueBuffer(_));
2644 EXPECT_CALL(mOutput, postFramebuffer());
2645 EXPECT_CALL(mOutput, prepareFrame());
2646
2647 mOutput.devOptRepaintFlash(mRefreshArgs);
2648}
2649
Lloyd Piquefaa3f192019-11-14 14:05:09 -08002650/*
2651 * Output::finishFrame()
2652 */
2653
Lloyd Pique03561a62019-11-19 18:34:52 -08002654struct OutputFinishFrameTest : public testing::Test {
2655 struct OutputPartialMock : public OutputPartialMockBase {
Lloyd Pique739afaf2019-11-21 16:40:05 -08002656 // Sets up the helper functions called by the function under test to use
2657 // mock implementations.
Lucas Dupin2dd6f392020-02-18 17:43:36 -08002658 MOCK_METHOD2(composeSurfaces,
2659 std::optional<base::unique_fd>(
2660 const Region&, const compositionengine::CompositionRefreshArgs&));
Lloyd Pique03561a62019-11-19 18:34:52 -08002661 MOCK_METHOD0(postFramebuffer, void());
2662 };
2663
2664 OutputFinishFrameTest() {
2665 mOutput.setDisplayColorProfileForTest(
2666 std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile));
2667 mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
2668 }
2669
2670 StrictMock<OutputPartialMock> mOutput;
2671 mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>();
2672 mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>();
2673 CompositionRefreshArgs mRefreshArgs;
2674};
2675
2676TEST_F(OutputFinishFrameTest, ifNotEnabledDoesNothing) {
2677 mOutput.mState.isEnabled = false;
2678
2679 mOutput.finishFrame(mRefreshArgs);
2680}
2681
2682TEST_F(OutputFinishFrameTest, takesEarlyOutifComposeSurfacesReturnsNoFence) {
2683 mOutput.mState.isEnabled = true;
2684
2685 InSequence seq;
Lucas Dupin2dd6f392020-02-18 17:43:36 -08002686 EXPECT_CALL(mOutput, composeSurfaces(RegionEq(Region::INVALID_REGION), _));
Lloyd Pique03561a62019-11-19 18:34:52 -08002687
2688 mOutput.finishFrame(mRefreshArgs);
2689}
2690
2691TEST_F(OutputFinishFrameTest, queuesBufferIfComposeSurfacesReturnsAFence) {
2692 mOutput.mState.isEnabled = true;
2693
2694 InSequence seq;
Lucas Dupin2dd6f392020-02-18 17:43:36 -08002695 EXPECT_CALL(mOutput, composeSurfaces(RegionEq(Region::INVALID_REGION), _))
Lloyd Pique03561a62019-11-19 18:34:52 -08002696 .WillOnce(Return(ByMove(base::unique_fd())));
2697 EXPECT_CALL(*mRenderSurface, queueBuffer(_));
2698
2699 mOutput.finishFrame(mRefreshArgs);
2700}
Lloyd Piquefaa3f192019-11-14 14:05:09 -08002701
2702/*
2703 * Output::postFramebuffer()
2704 */
2705
Lloyd Pique07178e32019-11-19 19:15:26 -08002706struct OutputPostFramebufferTest : public testing::Test {
2707 struct OutputPartialMock : public OutputPartialMockBase {
Lloyd Pique739afaf2019-11-21 16:40:05 -08002708 // Sets up the helper functions called by the function under test to use
2709 // mock implementations.
Lloyd Pique07178e32019-11-19 19:15:26 -08002710 MOCK_METHOD0(presentAndGetFrameFences, compositionengine::Output::FrameFences());
2711 };
2712
2713 struct Layer {
2714 Layer() {
Ady Abrahameca9d752021-03-03 12:20:00 -08002715 EXPECT_CALL(outputLayer, getLayerFE()).WillRepeatedly(ReturnRef(*layerFE));
Lloyd Pique07178e32019-11-19 19:15:26 -08002716 EXPECT_CALL(outputLayer, getHwcLayer()).WillRepeatedly(Return(&hwc2Layer));
2717 }
2718
2719 StrictMock<mock::OutputLayer> outputLayer;
Ady Abrahameca9d752021-03-03 12:20:00 -08002720 sp<StrictMock<mock::LayerFE>> layerFE = sp<StrictMock<mock::LayerFE>>::make();
Lloyd Pique07178e32019-11-19 19:15:26 -08002721 StrictMock<HWC2::mock::Layer> hwc2Layer;
2722 };
2723
2724 OutputPostFramebufferTest() {
2725 mOutput.setDisplayColorProfileForTest(
2726 std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile));
2727 mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
2728
2729 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(3u));
2730 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0u))
2731 .WillRepeatedly(Return(&mLayer1.outputLayer));
2732 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(1u))
2733 .WillRepeatedly(Return(&mLayer2.outputLayer));
2734 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(2u))
2735 .WillRepeatedly(Return(&mLayer3.outputLayer));
2736 }
2737
2738 StrictMock<OutputPartialMock> mOutput;
2739 mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>();
2740 mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>();
2741
2742 Layer mLayer1;
2743 Layer mLayer2;
2744 Layer mLayer3;
2745};
2746
2747TEST_F(OutputPostFramebufferTest, ifNotEnabledDoesNothing) {
2748 mOutput.mState.isEnabled = false;
2749
2750 mOutput.postFramebuffer();
2751}
2752
2753TEST_F(OutputPostFramebufferTest, ifEnabledMustFlipThenPresentThenSendPresentCompleted) {
2754 mOutput.mState.isEnabled = true;
2755
2756 compositionengine::Output::FrameFences frameFences;
2757
2758 // This should happen even if there are no output layers.
2759 EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u));
2760
2761 // For this test in particular we want to make sure the call expectations
2762 // setup below are satisfied in the specific order.
2763 InSequence seq;
2764
2765 EXPECT_CALL(*mRenderSurface, flip());
2766 EXPECT_CALL(mOutput, presentAndGetFrameFences()).WillOnce(Return(frameFences));
2767 EXPECT_CALL(*mRenderSurface, onPresentDisplayCompleted());
2768
2769 mOutput.postFramebuffer();
2770}
2771
2772TEST_F(OutputPostFramebufferTest, releaseFencesAreSentToLayerFE) {
2773 // Simulate getting release fences from each layer, and ensure they are passed to the
2774 // front-end layer interface for each layer correctly.
2775
2776 mOutput.mState.isEnabled = true;
2777
2778 // Create three unique fence instances
2779 sp<Fence> layer1Fence = new Fence();
2780 sp<Fence> layer2Fence = new Fence();
2781 sp<Fence> layer3Fence = new Fence();
2782
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08002783 Output::FrameFences frameFences;
Lloyd Pique07178e32019-11-19 19:15:26 -08002784 frameFences.layerFences.emplace(&mLayer1.hwc2Layer, layer1Fence);
2785 frameFences.layerFences.emplace(&mLayer2.hwc2Layer, layer2Fence);
2786 frameFences.layerFences.emplace(&mLayer3.hwc2Layer, layer3Fence);
2787
2788 EXPECT_CALL(*mRenderSurface, flip());
2789 EXPECT_CALL(mOutput, presentAndGetFrameFences()).WillOnce(Return(frameFences));
2790 EXPECT_CALL(*mRenderSurface, onPresentDisplayCompleted());
2791
2792 // Compare the pointers values of each fence to make sure the correct ones
2793 // are passed. This happens to work with the current implementation, but
2794 // would not survive certain calls like Fence::merge() which would return a
2795 // new instance.
Ady Abrahameca9d752021-03-03 12:20:00 -08002796 EXPECT_CALL(*mLayer1.layerFE,
Lloyd Pique07178e32019-11-19 19:15:26 -08002797 onLayerDisplayed(Property(&sp<Fence>::get, Eq(layer1Fence.get()))));
Ady Abrahameca9d752021-03-03 12:20:00 -08002798 EXPECT_CALL(*mLayer2.layerFE,
Lloyd Pique07178e32019-11-19 19:15:26 -08002799 onLayerDisplayed(Property(&sp<Fence>::get, Eq(layer2Fence.get()))));
Ady Abrahameca9d752021-03-03 12:20:00 -08002800 EXPECT_CALL(*mLayer3.layerFE,
Lloyd Pique07178e32019-11-19 19:15:26 -08002801 onLayerDisplayed(Property(&sp<Fence>::get, Eq(layer3Fence.get()))));
2802
2803 mOutput.postFramebuffer();
2804}
2805
2806TEST_F(OutputPostFramebufferTest, releaseFencesIncludeClientTargetAcquireFence) {
2807 mOutput.mState.isEnabled = true;
2808 mOutput.mState.usesClientComposition = true;
2809
2810 sp<Fence> clientTargetAcquireFence = new Fence();
2811 sp<Fence> layer1Fence = new Fence();
2812 sp<Fence> layer2Fence = new Fence();
2813 sp<Fence> layer3Fence = new Fence();
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08002814 Output::FrameFences frameFences;
Lloyd Pique07178e32019-11-19 19:15:26 -08002815 frameFences.clientTargetAcquireFence = clientTargetAcquireFence;
2816 frameFences.layerFences.emplace(&mLayer1.hwc2Layer, layer1Fence);
2817 frameFences.layerFences.emplace(&mLayer2.hwc2Layer, layer2Fence);
2818 frameFences.layerFences.emplace(&mLayer3.hwc2Layer, layer3Fence);
2819
2820 EXPECT_CALL(*mRenderSurface, flip());
2821 EXPECT_CALL(mOutput, presentAndGetFrameFences()).WillOnce(Return(frameFences));
2822 EXPECT_CALL(*mRenderSurface, onPresentDisplayCompleted());
2823
2824 // Fence::merge is called, and since none of the fences are actually valid,
2825 // Fence::NO_FENCE is returned and passed to each onLayerDisplayed() call.
2826 // This is the best we can do without creating a real kernel fence object.
Ady Abrahameca9d752021-03-03 12:20:00 -08002827 EXPECT_CALL(*mLayer1.layerFE, onLayerDisplayed(Fence::NO_FENCE));
2828 EXPECT_CALL(*mLayer2.layerFE, onLayerDisplayed(Fence::NO_FENCE));
2829 EXPECT_CALL(*mLayer3.layerFE, onLayerDisplayed(Fence::NO_FENCE));
Lloyd Pique07178e32019-11-19 19:15:26 -08002830
2831 mOutput.postFramebuffer();
2832}
2833
2834TEST_F(OutputPostFramebufferTest, releasedLayersSentPresentFence) {
2835 mOutput.mState.isEnabled = true;
2836 mOutput.mState.usesClientComposition = true;
2837
2838 // This should happen even if there are no (current) output layers.
2839 EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u));
2840
2841 // Load up the released layers with some mock instances
2842 sp<StrictMock<mock::LayerFE>> releasedLayer1{new StrictMock<mock::LayerFE>()};
2843 sp<StrictMock<mock::LayerFE>> releasedLayer2{new StrictMock<mock::LayerFE>()};
2844 sp<StrictMock<mock::LayerFE>> releasedLayer3{new StrictMock<mock::LayerFE>()};
2845 Output::ReleasedLayers layers;
2846 layers.push_back(releasedLayer1);
2847 layers.push_back(releasedLayer2);
2848 layers.push_back(releasedLayer3);
2849 mOutput.setReleasedLayers(std::move(layers));
2850
2851 // Set up a fake present fence
2852 sp<Fence> presentFence = new Fence();
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08002853 Output::FrameFences frameFences;
Lloyd Pique07178e32019-11-19 19:15:26 -08002854 frameFences.presentFence = presentFence;
2855
2856 EXPECT_CALL(*mRenderSurface, flip());
2857 EXPECT_CALL(mOutput, presentAndGetFrameFences()).WillOnce(Return(frameFences));
2858 EXPECT_CALL(*mRenderSurface, onPresentDisplayCompleted());
2859
2860 // Each released layer should be given the presentFence.
2861 EXPECT_CALL(*releasedLayer1,
2862 onLayerDisplayed(Property(&sp<Fence>::get, Eq(presentFence.get()))));
2863 EXPECT_CALL(*releasedLayer2,
2864 onLayerDisplayed(Property(&sp<Fence>::get, Eq(presentFence.get()))));
2865 EXPECT_CALL(*releasedLayer3,
2866 onLayerDisplayed(Property(&sp<Fence>::get, Eq(presentFence.get()))));
2867
2868 mOutput.postFramebuffer();
2869
2870 // After the call the list of released layers should have been cleared.
2871 EXPECT_TRUE(mOutput.getReleasedLayersForTest().empty());
2872}
Lloyd Piquefaa3f192019-11-14 14:05:09 -08002873
2874/*
Lloyd Pique56eba802019-08-28 15:45:25 -07002875 * Output::composeSurfaces()
2876 */
2877
2878struct OutputComposeSurfacesTest : public testing::Test {
Lloyd Pique6818fa52019-12-03 12:32:13 -08002879 using TestType = OutputComposeSurfacesTest;
Lloyd Pique56eba802019-08-28 15:45:25 -07002880
Lloyd Piquefaa3f192019-11-14 14:05:09 -08002881 struct OutputPartialMock : public OutputPartialMockBase {
Lloyd Pique739afaf2019-11-21 16:40:05 -08002882 // Sets up the helper functions called by the function under test to use
2883 // mock implementations.
Lloyd Pique56eba802019-08-28 15:45:25 -07002884 MOCK_CONST_METHOD0(getSkipColorTransform, bool());
Vishnu Nair3a7346c2019-12-04 08:09:09 -08002885 MOCK_METHOD3(generateClientCompositionRequests,
Vishnu Nair9b079a22020-01-21 14:36:08 -08002886 std::vector<LayerFE::LayerSettings>(bool, Region&, ui::Dataspace));
Lloyd Pique56eba802019-08-28 15:45:25 -07002887 MOCK_METHOD2(appendRegionFlashRequests,
Vishnu Nair9b079a22020-01-21 14:36:08 -08002888 void(const Region&, std::vector<LayerFE::LayerSettings>&));
Lloyd Pique56eba802019-08-28 15:45:25 -07002889 MOCK_METHOD1(setExpensiveRenderingExpected, void(bool));
2890 };
2891
2892 OutputComposeSurfacesTest() {
2893 mOutput.setDisplayColorProfileForTest(
2894 std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile));
2895 mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
Vishnu Nair9b079a22020-01-21 14:36:08 -08002896 mOutput.cacheClientCompositionRequests(MAX_CLIENT_COMPOSITION_CACHE_SIZE);
Lloyd Pique56eba802019-08-28 15:45:25 -07002897
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02002898 mOutput.mState.orientedDisplaySpace.content = kDefaultOutputFrame;
2899 mOutput.mState.layerStackSpace.content = kDefaultOutputViewport;
Marin Shalamanovb15d2272020-09-17 21:41:52 +02002900 mOutput.mState.framebufferSpace.content = kDefaultOutputDestinationClip;
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02002901 mOutput.mState.displaySpace.content = kDefaultOutputDestinationClip;
Marin Shalamanov68933fb2020-09-10 17:58:12 +02002902 mOutput.mState.displaySpace.orientation = kDefaultOutputOrientation;
Marin Shalamanovb15d2272020-09-17 21:41:52 +02002903 mOutput.mState.transform = ui::Transform{kDefaultOutputOrientationFlags};
Lloyd Pique6818fa52019-12-03 12:32:13 -08002904 mOutput.mState.dataspace = kDefaultOutputDataspace;
2905 mOutput.mState.colorTransformMatrix = kDefaultColorTransformMat;
2906 mOutput.mState.isSecure = false;
2907 mOutput.mState.needsFiltering = false;
2908 mOutput.mState.usesClientComposition = true;
2909 mOutput.mState.usesDeviceComposition = false;
Vishnu Nair9b079a22020-01-21 14:36:08 -08002910 mOutput.mState.reusedClientComposition = false;
Lloyd Piquee9eff972020-05-05 12:36:44 -07002911 mOutput.mState.flipClientTarget = false;
Lloyd Pique56eba802019-08-28 15:45:25 -07002912
Lloyd Piquea38ea7e2019-04-16 18:10:26 -07002913 EXPECT_CALL(mOutput, getCompositionEngine()).WillRepeatedly(ReturnRef(mCompositionEngine));
Lloyd Pique56eba802019-08-28 15:45:25 -07002914 EXPECT_CALL(mCompositionEngine, getRenderEngine()).WillRepeatedly(ReturnRef(mRenderEngine));
Alec Mourie4034bb2019-11-19 12:45:54 -08002915 EXPECT_CALL(mCompositionEngine, getTimeStats())
2916 .WillRepeatedly(ReturnRef(*mTimeStats.get()));
Lloyd Pique6818fa52019-12-03 12:32:13 -08002917 EXPECT_CALL(*mDisplayColorProfile, getHdrCapabilities())
2918 .WillRepeatedly(ReturnRef(kHdrCapabilities));
Lloyd Pique56eba802019-08-28 15:45:25 -07002919 }
2920
Lloyd Pique6818fa52019-12-03 12:32:13 -08002921 struct ExecuteState : public CallOrderStateMachineHelper<TestType, ExecuteState> {
2922 auto execute() {
Lucas Dupin2dd6f392020-02-18 17:43:36 -08002923 getInstance()->mReadyFence =
2924 getInstance()->mOutput.composeSurfaces(kDebugRegion, kDefaultRefreshArgs);
Lloyd Pique6818fa52019-12-03 12:32:13 -08002925 return nextState<FenceCheckState>();
2926 }
2927 };
2928
2929 struct FenceCheckState : public CallOrderStateMachineHelper<TestType, FenceCheckState> {
2930 void expectNoFenceWasReturned() { EXPECT_FALSE(getInstance()->mReadyFence); }
2931
2932 void expectAFenceWasReturned() { EXPECT_TRUE(getInstance()->mReadyFence); }
2933 };
2934
2935 // Call this member function to start using the mini-DSL defined above.
2936 [[nodiscard]] auto verify() { return ExecuteState::make(this); }
2937
Marin Shalamanov68933fb2020-09-10 17:58:12 +02002938 static constexpr ui::Rotation kDefaultOutputOrientation = ui::ROTATION_0;
2939 static constexpr uint32_t kDefaultOutputOrientationFlags =
2940 ui::Transform::toRotationFlags(kDefaultOutputOrientation);
Lloyd Pique6818fa52019-12-03 12:32:13 -08002941 static constexpr ui::Dataspace kDefaultOutputDataspace = ui::Dataspace::UNKNOWN;
2942 static constexpr ui::Dataspace kExpensiveOutputDataspace = ui::Dataspace::DISPLAY_P3;
2943 static constexpr float kDefaultMaxLuminance = 0.9f;
2944 static constexpr float kDefaultAvgLuminance = 0.7f;
2945 static constexpr float kDefaultMinLuminance = 0.1f;
2946
2947 static const Rect kDefaultOutputFrame;
2948 static const Rect kDefaultOutputViewport;
Lloyd Piquee8fe4742020-01-21 15:26:18 -08002949 static const Rect kDefaultOutputDestinationClip;
Lloyd Pique6818fa52019-12-03 12:32:13 -08002950 static const mat4 kDefaultColorTransformMat;
2951
2952 static const Region kDebugRegion;
Lucas Dupin2dd6f392020-02-18 17:43:36 -08002953 static const compositionengine::CompositionRefreshArgs kDefaultRefreshArgs;
Lloyd Pique6818fa52019-12-03 12:32:13 -08002954 static const HdrCapabilities kHdrCapabilities;
2955
Lloyd Pique56eba802019-08-28 15:45:25 -07002956 StrictMock<mock::CompositionEngine> mCompositionEngine;
2957 StrictMock<renderengine::mock::RenderEngine> mRenderEngine;
Alec Mourie4034bb2019-11-19 12:45:54 -08002958 // TODO: make this is a proper mock.
2959 std::shared_ptr<TimeStats> mTimeStats = std::make_shared<android::impl::TimeStats>();
Lloyd Pique56eba802019-08-28 15:45:25 -07002960 mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>();
2961 mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>();
Lloyd Piquea38ea7e2019-04-16 18:10:26 -07002962 StrictMock<OutputPartialMock> mOutput;
Alec Mouri617752f2021-04-15 16:27:01 +00002963 sp<GraphicBuffer> mOutputBuffer = new GraphicBuffer();
Lloyd Pique6818fa52019-12-03 12:32:13 -08002964
2965 std::optional<base::unique_fd> mReadyFence;
Lloyd Pique56eba802019-08-28 15:45:25 -07002966};
2967
2968const Rect OutputComposeSurfacesTest::kDefaultOutputFrame{1001, 1002, 1003, 1004};
2969const Rect OutputComposeSurfacesTest::kDefaultOutputViewport{1005, 1006, 1007, 1008};
Lloyd Piquee8fe4742020-01-21 15:26:18 -08002970const Rect OutputComposeSurfacesTest::kDefaultOutputDestinationClip{1013, 1014, 1015, 1016};
Lloyd Pique0a456232020-01-16 17:51:13 -08002971const mat4 OutputComposeSurfacesTest::kDefaultColorTransformMat{mat4() * 0.5f};
Lucas Dupin2dd6f392020-02-18 17:43:36 -08002972const compositionengine::CompositionRefreshArgs OutputComposeSurfacesTest::kDefaultRefreshArgs;
Lloyd Pique6818fa52019-12-03 12:32:13 -08002973const Region OutputComposeSurfacesTest::kDebugRegion{Rect{100, 101, 102, 103}};
2974const HdrCapabilities OutputComposeSurfacesTest::
2975 kHdrCapabilities{{},
2976 OutputComposeSurfacesTest::kDefaultMaxLuminance,
2977 OutputComposeSurfacesTest::kDefaultAvgLuminance,
2978 OutputComposeSurfacesTest::kDefaultMinLuminance};
Lloyd Pique56eba802019-08-28 15:45:25 -07002979
Lloyd Piquea76ce462020-01-14 13:06:37 -08002980TEST_F(OutputComposeSurfacesTest, doesNothingButSignalNoExpensiveRenderingIfNoClientComposition) {
Lloyd Pique6818fa52019-12-03 12:32:13 -08002981 mOutput.mState.usesClientComposition = false;
Lloyd Pique56eba802019-08-28 15:45:25 -07002982
Lloyd Piquee9eff972020-05-05 12:36:44 -07002983 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false));
Peiyong Lin09f910f2020-09-25 10:54:13 -07002984 EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false));
Lloyd Piquee9eff972020-05-05 12:36:44 -07002985
Lloyd Piquea76ce462020-01-14 13:06:37 -08002986 EXPECT_CALL(mOutput, setExpensiveRenderingExpected(false));
2987
Lloyd Pique6818fa52019-12-03 12:32:13 -08002988 verify().execute().expectAFenceWasReturned();
Lloyd Pique56eba802019-08-28 15:45:25 -07002989}
2990
Lloyd Piquee9eff972020-05-05 12:36:44 -07002991TEST_F(OutputComposeSurfacesTest,
2992 dequeuesABufferIfNoClientCompositionButFlipClientTargetRequested) {
2993 mOutput.mState.usesClientComposition = false;
2994 mOutput.mState.flipClientTarget = true;
2995
Lloyd Pique6818fa52019-12-03 12:32:13 -08002996 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false));
Peiyong Lin09f910f2020-09-25 10:54:13 -07002997 EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false));
Lloyd Piquee9eff972020-05-05 12:36:44 -07002998
2999 EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillOnce(Return(mOutputBuffer));
3000 EXPECT_CALL(mOutput, setExpensiveRenderingExpected(false));
3001
3002 verify().execute().expectAFenceWasReturned();
3003}
3004
3005TEST_F(OutputComposeSurfacesTest, doesMinimalWorkIfDequeueBufferFailsForClientComposition) {
3006 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false));
Peiyong Lin09f910f2020-09-25 10:54:13 -07003007 EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false));
Lloyd Piquee9eff972020-05-05 12:36:44 -07003008
3009 EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillOnce(Return(nullptr));
3010
3011 verify().execute().expectNoFenceWasReturned();
3012}
3013
3014TEST_F(OutputComposeSurfacesTest,
3015 doesMinimalWorkIfDequeueBufferFailsForNoClientCompositionButFlipClientTargetRequested) {
3016 mOutput.mState.usesClientComposition = false;
3017 mOutput.mState.flipClientTarget = true;
3018
3019 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false));
Peiyong Lin09f910f2020-09-25 10:54:13 -07003020 EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false));
Lloyd Pique56eba802019-08-28 15:45:25 -07003021
Lloyd Pique6818fa52019-12-03 12:32:13 -08003022 EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillOnce(Return(nullptr));
Lloyd Pique56eba802019-08-28 15:45:25 -07003023
Lloyd Pique6818fa52019-12-03 12:32:13 -08003024 verify().execute().expectNoFenceWasReturned();
3025}
Lloyd Pique56eba802019-08-28 15:45:25 -07003026
Lloyd Pique6818fa52019-12-03 12:32:13 -08003027TEST_F(OutputComposeSurfacesTest, handlesZeroCompositionRequests) {
3028 EXPECT_CALL(mOutput, getSkipColorTransform()).WillRepeatedly(Return(false));
3029 EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillRepeatedly(Return(true));
3030 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false));
Peiyong Lin09f910f2020-09-25 10:54:13 -07003031 EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false));
Lloyd Pique6818fa52019-12-03 12:32:13 -08003032 EXPECT_CALL(mOutput, generateClientCompositionRequests(_, _, kDefaultOutputDataspace))
Vishnu Nair9b079a22020-01-21 14:36:08 -08003033 .WillRepeatedly(Return(std::vector<LayerFE::LayerSettings>{}));
Lloyd Pique6818fa52019-12-03 12:32:13 -08003034 EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _))
3035 .WillRepeatedly(Return());
Lloyd Pique56eba802019-08-28 15:45:25 -07003036
Lloyd Pique6818fa52019-12-03 12:32:13 -08003037 EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer));
Alec Mouri1684c702021-02-04 12:27:26 -08003038 EXPECT_CALL(mRenderEngine, drawLayers(_, IsEmpty(), _, false, _, _))
Lloyd Pique6818fa52019-12-03 12:32:13 -08003039 .WillRepeatedly(Return(NO_ERROR));
Lloyd Pique56eba802019-08-28 15:45:25 -07003040
Lloyd Pique6818fa52019-12-03 12:32:13 -08003041 verify().execute().expectAFenceWasReturned();
3042}
Lloyd Pique56eba802019-08-28 15:45:25 -07003043
Lloyd Pique6818fa52019-12-03 12:32:13 -08003044TEST_F(OutputComposeSurfacesTest, buildsAndRendersRequestList) {
Vishnu Nair9b079a22020-01-21 14:36:08 -08003045 LayerFE::LayerSettings r1;
3046 LayerFE::LayerSettings r2;
Lloyd Pique6818fa52019-12-03 12:32:13 -08003047
3048 r1.geometry.boundaries = FloatRect{1, 2, 3, 4};
3049 r2.geometry.boundaries = FloatRect{5, 6, 7, 8};
3050
3051 EXPECT_CALL(mOutput, getSkipColorTransform()).WillRepeatedly(Return(false));
3052 EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillRepeatedly(Return(true));
3053 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false));
Peiyong Lin09f910f2020-09-25 10:54:13 -07003054 EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false));
Lloyd Pique6818fa52019-12-03 12:32:13 -08003055 EXPECT_CALL(mOutput, generateClientCompositionRequests(_, _, kDefaultOutputDataspace))
Vishnu Nair9b079a22020-01-21 14:36:08 -08003056 .WillRepeatedly(Return(std::vector<LayerFE::LayerSettings>{r1}));
Lloyd Pique6818fa52019-12-03 12:32:13 -08003057 EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _))
3058 .WillRepeatedly(
3059 Invoke([&](const Region&,
Vishnu Nair9b079a22020-01-21 14:36:08 -08003060 std::vector<LayerFE::LayerSettings>& clientCompositionLayers) {
Lloyd Pique6818fa52019-12-03 12:32:13 -08003061 clientCompositionLayers.emplace_back(r2);
3062 }));
3063
3064 EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer));
Alec Mouri1684c702021-02-04 12:27:26 -08003065 EXPECT_CALL(mRenderEngine, drawLayers(_, ElementsAre(Pointee(r1), Pointee(r2)), _, false, _, _))
3066 .WillRepeatedly(Return(NO_ERROR));
3067
3068 verify().execute().expectAFenceWasReturned();
3069}
3070
3071TEST_F(OutputComposeSurfacesTest,
3072 buildsAndRendersRequestListAndCachesFramebufferForInternalLayers) {
3073 LayerFE::LayerSettings r1;
3074 LayerFE::LayerSettings r2;
3075
3076 r1.geometry.boundaries = FloatRect{1, 2, 3, 4};
3077 r2.geometry.boundaries = FloatRect{5, 6, 7, 8};
3078 const constexpr uint32_t kInternalLayerStack = 1234;
3079 mOutput.setLayerStackFilter(kInternalLayerStack, true);
3080
3081 EXPECT_CALL(mOutput, getSkipColorTransform()).WillRepeatedly(Return(false));
3082 EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillRepeatedly(Return(true));
3083 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false));
3084 EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false));
3085 EXPECT_CALL(mOutput, generateClientCompositionRequests(_, _, kDefaultOutputDataspace))
3086 .WillRepeatedly(Return(std::vector<LayerFE::LayerSettings>{r1}));
3087 EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _))
3088 .WillRepeatedly(
3089 Invoke([&](const Region&,
3090 std::vector<LayerFE::LayerSettings>& clientCompositionLayers) {
3091 clientCompositionLayers.emplace_back(r2);
3092 }));
3093
3094 EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer));
Vishnu Nair9b079a22020-01-21 14:36:08 -08003095 EXPECT_CALL(mRenderEngine, drawLayers(_, ElementsAre(Pointee(r1), Pointee(r2)), _, true, _, _))
Lloyd Pique6818fa52019-12-03 12:32:13 -08003096 .WillRepeatedly(Return(NO_ERROR));
3097
3098 verify().execute().expectAFenceWasReturned();
3099}
3100
Vishnu Nair9b079a22020-01-21 14:36:08 -08003101TEST_F(OutputComposeSurfacesTest, renderDuplicateClientCompositionRequestsWithoutCache) {
3102 mOutput.cacheClientCompositionRequests(0);
3103 LayerFE::LayerSettings r1;
3104 LayerFE::LayerSettings r2;
3105
3106 r1.geometry.boundaries = FloatRect{1, 2, 3, 4};
3107 r2.geometry.boundaries = FloatRect{5, 6, 7, 8};
3108
3109 EXPECT_CALL(mOutput, getSkipColorTransform()).WillRepeatedly(Return(false));
3110 EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillRepeatedly(Return(true));
3111 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false));
Peiyong Lin09f910f2020-09-25 10:54:13 -07003112 EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false));
Vishnu Nair9b079a22020-01-21 14:36:08 -08003113 EXPECT_CALL(mOutput, generateClientCompositionRequests(_, _, kDefaultOutputDataspace))
3114 .WillRepeatedly(Return(std::vector<LayerFE::LayerSettings>{r1, r2}));
3115 EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _))
3116 .WillRepeatedly(Return());
3117
3118 EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer));
Alec Mouri1684c702021-02-04 12:27:26 -08003119 EXPECT_CALL(mRenderEngine, drawLayers(_, ElementsAre(Pointee(r1), Pointee(r2)), _, false, _, _))
Vishnu Nair9b079a22020-01-21 14:36:08 -08003120 .Times(2)
3121 .WillOnce(Return(NO_ERROR));
3122
3123 verify().execute().expectAFenceWasReturned();
3124 EXPECT_FALSE(mOutput.mState.reusedClientComposition);
3125
3126 verify().execute().expectAFenceWasReturned();
3127 EXPECT_FALSE(mOutput.mState.reusedClientComposition);
3128}
3129
3130TEST_F(OutputComposeSurfacesTest, skipDuplicateClientCompositionRequests) {
3131 mOutput.cacheClientCompositionRequests(3);
3132 LayerFE::LayerSettings r1;
3133 LayerFE::LayerSettings r2;
3134
3135 r1.geometry.boundaries = FloatRect{1, 2, 3, 4};
3136 r2.geometry.boundaries = FloatRect{5, 6, 7, 8};
3137
3138 EXPECT_CALL(mOutput, getSkipColorTransform()).WillRepeatedly(Return(false));
3139 EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillRepeatedly(Return(true));
3140 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false));
Peiyong Lin09f910f2020-09-25 10:54:13 -07003141 EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false));
Vishnu Nair9b079a22020-01-21 14:36:08 -08003142 EXPECT_CALL(mOutput, generateClientCompositionRequests(_, _, kDefaultOutputDataspace))
3143 .WillRepeatedly(Return(std::vector<LayerFE::LayerSettings>{r1, r2}));
3144 EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _))
3145 .WillRepeatedly(Return());
3146
3147 EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer));
Alec Mouri1684c702021-02-04 12:27:26 -08003148 EXPECT_CALL(mRenderEngine, drawLayers(_, ElementsAre(Pointee(r1), Pointee(r2)), _, false, _, _))
Vishnu Nair9b079a22020-01-21 14:36:08 -08003149 .WillOnce(Return(NO_ERROR));
3150 EXPECT_CALL(mOutput, setExpensiveRenderingExpected(false));
3151
3152 verify().execute().expectAFenceWasReturned();
3153 EXPECT_FALSE(mOutput.mState.reusedClientComposition);
3154
3155 // We do not expect another call to draw layers.
3156 verify().execute().expectAFenceWasReturned();
3157 EXPECT_TRUE(mOutput.mState.reusedClientComposition);
3158}
3159
3160TEST_F(OutputComposeSurfacesTest, clientCompositionIfBufferChanges) {
3161 LayerFE::LayerSettings r1;
3162 LayerFE::LayerSettings r2;
3163
3164 r1.geometry.boundaries = FloatRect{1, 2, 3, 4};
3165 r2.geometry.boundaries = FloatRect{5, 6, 7, 8};
3166
3167 EXPECT_CALL(mOutput, getSkipColorTransform()).WillRepeatedly(Return(false));
3168 EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillRepeatedly(Return(true));
3169 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false));
Peiyong Lin09f910f2020-09-25 10:54:13 -07003170 EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false));
Vishnu Nair9b079a22020-01-21 14:36:08 -08003171 EXPECT_CALL(mOutput, generateClientCompositionRequests(_, _, kDefaultOutputDataspace))
3172 .WillRepeatedly(Return(std::vector<LayerFE::LayerSettings>{r1, r2}));
3173 EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _))
3174 .WillRepeatedly(Return());
3175
Alec Mouri617752f2021-04-15 16:27:01 +00003176 sp<GraphicBuffer> otherOutputBuffer = new GraphicBuffer();
Vishnu Nair9b079a22020-01-21 14:36:08 -08003177 EXPECT_CALL(*mRenderSurface, dequeueBuffer(_))
3178 .WillOnce(Return(mOutputBuffer))
3179 .WillOnce(Return(otherOutputBuffer));
Alec Mouri1684c702021-02-04 12:27:26 -08003180 EXPECT_CALL(mRenderEngine, drawLayers(_, ElementsAre(Pointee(r1), Pointee(r2)), _, false, _, _))
Vishnu Nair9b079a22020-01-21 14:36:08 -08003181 .WillRepeatedly(Return(NO_ERROR));
3182
3183 verify().execute().expectAFenceWasReturned();
3184 EXPECT_FALSE(mOutput.mState.reusedClientComposition);
3185
3186 verify().execute().expectAFenceWasReturned();
3187 EXPECT_FALSE(mOutput.mState.reusedClientComposition);
3188}
3189
3190TEST_F(OutputComposeSurfacesTest, clientCompositionIfRequestChanges) {
3191 LayerFE::LayerSettings r1;
3192 LayerFE::LayerSettings r2;
3193 LayerFE::LayerSettings r3;
3194
3195 r1.geometry.boundaries = FloatRect{1, 2, 3, 4};
3196 r2.geometry.boundaries = FloatRect{5, 6, 7, 8};
3197 r3.geometry.boundaries = FloatRect{5, 6, 7, 9};
3198
3199 EXPECT_CALL(mOutput, getSkipColorTransform()).WillRepeatedly(Return(false));
3200 EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillRepeatedly(Return(true));
3201 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false));
Peiyong Lin09f910f2020-09-25 10:54:13 -07003202 EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false));
Vishnu Nair9b079a22020-01-21 14:36:08 -08003203 EXPECT_CALL(mOutput, generateClientCompositionRequests(_, _, kDefaultOutputDataspace))
3204 .WillOnce(Return(std::vector<LayerFE::LayerSettings>{r1, r2}))
3205 .WillOnce(Return(std::vector<LayerFE::LayerSettings>{r1, r3}));
3206 EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _))
3207 .WillRepeatedly(Return());
3208
3209 EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer));
Alec Mouri1684c702021-02-04 12:27:26 -08003210 EXPECT_CALL(mRenderEngine, drawLayers(_, ElementsAre(Pointee(r1), Pointee(r2)), _, false, _, _))
Vishnu Nair9b079a22020-01-21 14:36:08 -08003211 .WillOnce(Return(NO_ERROR));
Alec Mouri1684c702021-02-04 12:27:26 -08003212 EXPECT_CALL(mRenderEngine, drawLayers(_, ElementsAre(Pointee(r1), Pointee(r3)), _, false, _, _))
Vishnu Nair9b079a22020-01-21 14:36:08 -08003213 .WillOnce(Return(NO_ERROR));
3214
3215 verify().execute().expectAFenceWasReturned();
3216 EXPECT_FALSE(mOutput.mState.reusedClientComposition);
3217
3218 verify().execute().expectAFenceWasReturned();
3219 EXPECT_FALSE(mOutput.mState.reusedClientComposition);
3220}
3221
Lloyd Pique6818fa52019-12-03 12:32:13 -08003222struct OutputComposeSurfacesTest_UsesExpectedDisplaySettings : public OutputComposeSurfacesTest {
3223 OutputComposeSurfacesTest_UsesExpectedDisplaySettings() {
3224 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false));
Peiyong Lin09f910f2020-09-25 10:54:13 -07003225 EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false));
Lloyd Pique6818fa52019-12-03 12:32:13 -08003226 EXPECT_CALL(mOutput, generateClientCompositionRequests(_, _, kDefaultOutputDataspace))
Vishnu Nair9b079a22020-01-21 14:36:08 -08003227 .WillRepeatedly(Return(std::vector<LayerFE::LayerSettings>{}));
Lloyd Pique6818fa52019-12-03 12:32:13 -08003228 EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _))
3229 .WillRepeatedly(Return());
3230 EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer));
3231 }
3232
3233 struct MixedCompositionState
3234 : public CallOrderStateMachineHelper<TestType, MixedCompositionState> {
3235 auto ifMixedCompositionIs(bool used) {
3236 getInstance()->mOutput.mState.usesDeviceComposition = used;
3237 return nextState<OutputUsesHdrState>();
3238 }
3239 };
3240
3241 struct OutputUsesHdrState : public CallOrderStateMachineHelper<TestType, OutputUsesHdrState> {
3242 auto andIfUsesHdr(bool used) {
3243 EXPECT_CALL(*getInstance()->mDisplayColorProfile, hasWideColorGamut())
3244 .WillOnce(Return(used));
3245 return nextState<SkipColorTransformState>();
3246 }
3247 };
3248
3249 struct SkipColorTransformState
3250 : public CallOrderStateMachineHelper<TestType, SkipColorTransformState> {
3251 auto andIfSkipColorTransform(bool skip) {
3252 // May be called zero or one times.
3253 EXPECT_CALL(getInstance()->mOutput, getSkipColorTransform())
3254 .WillRepeatedly(Return(skip));
3255 return nextState<ExpectDisplaySettingsState>();
3256 }
3257 };
3258
3259 struct ExpectDisplaySettingsState
3260 : public CallOrderStateMachineHelper<TestType, ExpectDisplaySettingsState> {
3261 auto thenExpectDisplaySettingsUsed(renderengine::DisplaySettings settings) {
Alec Mouri1684c702021-02-04 12:27:26 -08003262 EXPECT_CALL(getInstance()->mRenderEngine, drawLayers(settings, _, _, false, _, _))
Lloyd Pique6818fa52019-12-03 12:32:13 -08003263 .WillOnce(Return(NO_ERROR));
3264 return nextState<ExecuteState>();
3265 }
3266 };
3267
3268 // Call this member function to start using the mini-DSL defined above.
3269 [[nodiscard]] auto verify() { return MixedCompositionState::make(this); }
3270};
3271
3272TEST_F(OutputComposeSurfacesTest_UsesExpectedDisplaySettings, forHdrMixedComposition) {
3273 verify().ifMixedCompositionIs(true)
3274 .andIfUsesHdr(true)
3275 .andIfSkipColorTransform(false)
Marin Shalamanov06ca1632020-07-28 12:32:01 +02003276 .thenExpectDisplaySettingsUsed({kDefaultOutputDestinationClip, kDefaultOutputViewport,
Alec Mourid4bf7952020-04-06 20:28:16 -07003277 kDefaultMaxLuminance, kDefaultOutputDataspace, mat4(),
Marin Shalamanov68933fb2020-09-10 17:58:12 +02003278 Region::INVALID_REGION, kDefaultOutputOrientationFlags})
Lloyd Pique6818fa52019-12-03 12:32:13 -08003279 .execute()
3280 .expectAFenceWasReturned();
3281}
3282
3283TEST_F(OutputComposeSurfacesTest_UsesExpectedDisplaySettings, forNonHdrMixedComposition) {
3284 verify().ifMixedCompositionIs(true)
3285 .andIfUsesHdr(false)
3286 .andIfSkipColorTransform(false)
Marin Shalamanov06ca1632020-07-28 12:32:01 +02003287 .thenExpectDisplaySettingsUsed({kDefaultOutputDestinationClip, kDefaultOutputViewport,
Alec Mourid4bf7952020-04-06 20:28:16 -07003288 kDefaultMaxLuminance, kDefaultOutputDataspace, mat4(),
Marin Shalamanov68933fb2020-09-10 17:58:12 +02003289 Region::INVALID_REGION, kDefaultOutputOrientationFlags})
Lloyd Pique6818fa52019-12-03 12:32:13 -08003290 .execute()
3291 .expectAFenceWasReturned();
3292}
3293
3294TEST_F(OutputComposeSurfacesTest_UsesExpectedDisplaySettings, forHdrOnlyClientComposition) {
3295 verify().ifMixedCompositionIs(false)
3296 .andIfUsesHdr(true)
3297 .andIfSkipColorTransform(false)
Marin Shalamanov06ca1632020-07-28 12:32:01 +02003298 .thenExpectDisplaySettingsUsed({kDefaultOutputDestinationClip, kDefaultOutputViewport,
Alec Mourid4bf7952020-04-06 20:28:16 -07003299 kDefaultMaxLuminance, kDefaultOutputDataspace,
Lloyd Pique6818fa52019-12-03 12:32:13 -08003300 kDefaultColorTransformMat, Region::INVALID_REGION,
Marin Shalamanov68933fb2020-09-10 17:58:12 +02003301 kDefaultOutputOrientationFlags})
Lloyd Pique6818fa52019-12-03 12:32:13 -08003302 .execute()
3303 .expectAFenceWasReturned();
3304}
3305
3306TEST_F(OutputComposeSurfacesTest_UsesExpectedDisplaySettings, forNonHdrOnlyClientComposition) {
3307 verify().ifMixedCompositionIs(false)
3308 .andIfUsesHdr(false)
3309 .andIfSkipColorTransform(false)
Marin Shalamanov06ca1632020-07-28 12:32:01 +02003310 .thenExpectDisplaySettingsUsed({kDefaultOutputDestinationClip, kDefaultOutputViewport,
Alec Mourid4bf7952020-04-06 20:28:16 -07003311 kDefaultMaxLuminance, kDefaultOutputDataspace,
Lloyd Pique6818fa52019-12-03 12:32:13 -08003312 kDefaultColorTransformMat, Region::INVALID_REGION,
Marin Shalamanov68933fb2020-09-10 17:58:12 +02003313 kDefaultOutputOrientationFlags})
Lloyd Pique6818fa52019-12-03 12:32:13 -08003314 .execute()
3315 .expectAFenceWasReturned();
3316}
3317
3318TEST_F(OutputComposeSurfacesTest_UsesExpectedDisplaySettings,
3319 usesExpectedDisplaySettingsForHdrOnlyClientCompositionWithSkipClientTransform) {
3320 verify().ifMixedCompositionIs(false)
3321 .andIfUsesHdr(true)
3322 .andIfSkipColorTransform(true)
Marin Shalamanov06ca1632020-07-28 12:32:01 +02003323 .thenExpectDisplaySettingsUsed({kDefaultOutputDestinationClip, kDefaultOutputViewport,
Alec Mourid4bf7952020-04-06 20:28:16 -07003324 kDefaultMaxLuminance, kDefaultOutputDataspace, mat4(),
Marin Shalamanov68933fb2020-09-10 17:58:12 +02003325 Region::INVALID_REGION, kDefaultOutputOrientationFlags})
Lloyd Pique6818fa52019-12-03 12:32:13 -08003326 .execute()
3327 .expectAFenceWasReturned();
3328}
3329
3330struct OutputComposeSurfacesTest_HandlesProtectedContent : public OutputComposeSurfacesTest {
3331 struct Layer {
3332 Layer() {
Ady Abrahameca9d752021-03-03 12:20:00 -08003333 EXPECT_CALL(*mLayerFE, getCompositionState()).WillRepeatedly(Return(&mLayerFEState));
3334 EXPECT_CALL(mOutputLayer, getLayerFE()).WillRepeatedly(ReturnRef(*mLayerFE));
Lloyd Pique6818fa52019-12-03 12:32:13 -08003335 }
3336
3337 StrictMock<mock::OutputLayer> mOutputLayer;
Ady Abrahameca9d752021-03-03 12:20:00 -08003338 sp<StrictMock<mock::LayerFE>> mLayerFE = sp<StrictMock<mock::LayerFE>>::make();
Lloyd Pique6818fa52019-12-03 12:32:13 -08003339 LayerFECompositionState mLayerFEState;
3340 };
3341
3342 OutputComposeSurfacesTest_HandlesProtectedContent() {
3343 mLayer1.mLayerFEState.hasProtectedContent = false;
3344 mLayer2.mLayerFEState.hasProtectedContent = false;
3345
3346 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(2u));
3347 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0u))
3348 .WillRepeatedly(Return(&mLayer1.mOutputLayer));
3349 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(1u))
3350 .WillRepeatedly(Return(&mLayer2.mOutputLayer));
3351
3352 EXPECT_CALL(mOutput, getSkipColorTransform()).WillRepeatedly(Return(false));
3353
3354 EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillRepeatedly(Return(true));
3355
3356 EXPECT_CALL(mOutput, generateClientCompositionRequests(_, _, _))
Vishnu Nair9b079a22020-01-21 14:36:08 -08003357 .WillRepeatedly(Return(std::vector<LayerFE::LayerSettings>{}));
Lloyd Pique6818fa52019-12-03 12:32:13 -08003358 EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _))
3359 .WillRepeatedly(Return());
3360 EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer));
Alec Mouri1684c702021-02-04 12:27:26 -08003361 EXPECT_CALL(mRenderEngine, drawLayers(_, _, _, false, _, _))
Lloyd Pique6818fa52019-12-03 12:32:13 -08003362 .WillRepeatedly(Return(NO_ERROR));
3363 }
3364
3365 Layer mLayer1;
3366 Layer mLayer2;
3367};
3368
3369TEST_F(OutputComposeSurfacesTest_HandlesProtectedContent, ifDisplayIsNotSecure) {
3370 mOutput.mState.isSecure = false;
3371 mLayer2.mLayerFEState.hasProtectedContent = true;
3372 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(true));
Peiyong Lin09f910f2020-09-25 10:54:13 -07003373 EXPECT_CALL(mRenderEngine, isProtected).WillOnce(Return(true));
3374 EXPECT_CALL(mRenderEngine, useProtectedContext(false)).WillOnce(Return(true));
Lloyd Pique6818fa52019-12-03 12:32:13 -08003375
Lucas Dupin2dd6f392020-02-18 17:43:36 -08003376 mOutput.composeSurfaces(kDebugRegion, kDefaultRefreshArgs);
Lloyd Pique6818fa52019-12-03 12:32:13 -08003377}
3378
3379TEST_F(OutputComposeSurfacesTest_HandlesProtectedContent, ifRenderEngineDoesNotSupportIt) {
3380 mOutput.mState.isSecure = true;
3381 mLayer2.mLayerFEState.hasProtectedContent = true;
3382 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false));
3383
Lucas Dupin2dd6f392020-02-18 17:43:36 -08003384 mOutput.composeSurfaces(kDebugRegion, kDefaultRefreshArgs);
Lloyd Pique6818fa52019-12-03 12:32:13 -08003385}
3386
3387TEST_F(OutputComposeSurfacesTest_HandlesProtectedContent, ifNoProtectedContentLayers) {
3388 mOutput.mState.isSecure = true;
3389 mLayer2.mLayerFEState.hasProtectedContent = false;
3390 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(true));
3391 EXPECT_CALL(mRenderEngine, isProtected).WillOnce(Return(true)).WillOnce(Return(false));
3392 EXPECT_CALL(*mRenderSurface, isProtected).WillOnce(Return(true));
3393 EXPECT_CALL(mRenderEngine, useProtectedContext(false));
3394 EXPECT_CALL(*mRenderSurface, setProtected(false));
3395
Lucas Dupin2dd6f392020-02-18 17:43:36 -08003396 mOutput.composeSurfaces(kDebugRegion, kDefaultRefreshArgs);
Lloyd Pique6818fa52019-12-03 12:32:13 -08003397}
3398
3399TEST_F(OutputComposeSurfacesTest_HandlesProtectedContent, ifNotEnabled) {
3400 mOutput.mState.isSecure = true;
3401 mLayer2.mLayerFEState.hasProtectedContent = true;
3402 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(true));
3403
3404 // For this test, we also check the call order of key functions.
3405 InSequence seq;
3406
3407 EXPECT_CALL(mRenderEngine, isProtected).WillOnce(Return(false));
3408 EXPECT_CALL(mRenderEngine, useProtectedContext(true));
3409 EXPECT_CALL(*mRenderSurface, isProtected).WillOnce(Return(false));
3410 EXPECT_CALL(mRenderEngine, isProtected).WillOnce(Return(true));
3411 EXPECT_CALL(*mRenderSurface, setProtected(true));
3412 // Must happen after setting the protected content state.
3413 EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer));
Alec Mouri1684c702021-02-04 12:27:26 -08003414 EXPECT_CALL(mRenderEngine, drawLayers(_, _, _, false, _, _)).WillOnce(Return(NO_ERROR));
Lloyd Pique6818fa52019-12-03 12:32:13 -08003415
Lucas Dupin2dd6f392020-02-18 17:43:36 -08003416 mOutput.composeSurfaces(kDebugRegion, kDefaultRefreshArgs);
Lloyd Pique6818fa52019-12-03 12:32:13 -08003417}
3418
3419TEST_F(OutputComposeSurfacesTest_HandlesProtectedContent, ifAlreadyEnabledEverywhere) {
3420 mOutput.mState.isSecure = true;
3421 mLayer2.mLayerFEState.hasProtectedContent = true;
3422 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(true));
3423 EXPECT_CALL(mRenderEngine, isProtected).WillOnce(Return(true));
3424 EXPECT_CALL(*mRenderSurface, isProtected).WillOnce(Return(true));
3425
Lucas Dupin2dd6f392020-02-18 17:43:36 -08003426 mOutput.composeSurfaces(kDebugRegion, kDefaultRefreshArgs);
Lloyd Pique6818fa52019-12-03 12:32:13 -08003427}
3428
3429TEST_F(OutputComposeSurfacesTest_HandlesProtectedContent, ifFailsToEnableInRenderEngine) {
3430 mOutput.mState.isSecure = true;
3431 mLayer2.mLayerFEState.hasProtectedContent = true;
3432 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(true));
3433 EXPECT_CALL(mRenderEngine, isProtected).WillOnce(Return(false)).WillOnce(Return(false));
3434 EXPECT_CALL(*mRenderSurface, isProtected).WillOnce(Return(false));
3435 EXPECT_CALL(mRenderEngine, useProtectedContext(true));
3436
Lucas Dupin2dd6f392020-02-18 17:43:36 -08003437 mOutput.composeSurfaces(kDebugRegion, kDefaultRefreshArgs);
Lloyd Pique6818fa52019-12-03 12:32:13 -08003438}
3439
3440TEST_F(OutputComposeSurfacesTest_HandlesProtectedContent, ifAlreadyEnabledInRenderEngine) {
3441 mOutput.mState.isSecure = true;
3442 mLayer2.mLayerFEState.hasProtectedContent = true;
3443 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(true));
3444 EXPECT_CALL(mRenderEngine, isProtected).WillOnce(Return(true)).WillOnce(Return(true));
3445 EXPECT_CALL(*mRenderSurface, isProtected).WillOnce(Return(false));
3446 EXPECT_CALL(*mRenderSurface, setProtected(true));
3447
Lucas Dupin2dd6f392020-02-18 17:43:36 -08003448 mOutput.composeSurfaces(kDebugRegion, kDefaultRefreshArgs);
Lloyd Pique6818fa52019-12-03 12:32:13 -08003449}
3450
3451TEST_F(OutputComposeSurfacesTest_HandlesProtectedContent, ifAlreadyEnabledInRenderSurface) {
3452 mOutput.mState.isSecure = true;
3453 mLayer2.mLayerFEState.hasProtectedContent = true;
3454 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(true));
3455 EXPECT_CALL(mRenderEngine, isProtected).WillOnce(Return(false));
3456 EXPECT_CALL(*mRenderSurface, isProtected).WillOnce(Return(true));
3457 EXPECT_CALL(mRenderEngine, useProtectedContext(true));
3458
Lucas Dupin2dd6f392020-02-18 17:43:36 -08003459 mOutput.composeSurfaces(kDebugRegion, kDefaultRefreshArgs);
Lloyd Pique6818fa52019-12-03 12:32:13 -08003460}
3461
3462struct OutputComposeSurfacesTest_SetsExpensiveRendering : public OutputComposeSurfacesTest {
3463 OutputComposeSurfacesTest_SetsExpensiveRendering() {
3464 EXPECT_CALL(mOutput, getSkipColorTransform()).WillRepeatedly(Return(false));
3465 EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillRepeatedly(Return(true));
3466 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false));
Peiyong Lin09f910f2020-09-25 10:54:13 -07003467 EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false));
Lloyd Pique6818fa52019-12-03 12:32:13 -08003468 EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _))
3469 .WillRepeatedly(Return());
3470 EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer));
3471 }
3472};
3473
3474TEST_F(OutputComposeSurfacesTest_SetsExpensiveRendering, IfExepensiveOutputDataspaceIsUsed) {
3475 mOutput.mState.dataspace = kExpensiveOutputDataspace;
3476
3477 EXPECT_CALL(mOutput, generateClientCompositionRequests(_, _, kExpensiveOutputDataspace))
Vishnu Nair9b079a22020-01-21 14:36:08 -08003478 .WillOnce(Return(std::vector<LayerFE::LayerSettings>{}));
Lloyd Pique6818fa52019-12-03 12:32:13 -08003479
3480 // For this test, we also check the call order of key functions.
3481 InSequence seq;
3482
3483 EXPECT_CALL(mOutput, setExpensiveRenderingExpected(true));
Alec Mouri1684c702021-02-04 12:27:26 -08003484 EXPECT_CALL(mRenderEngine, drawLayers(_, _, _, false, _, _)).WillOnce(Return(NO_ERROR));
Lloyd Pique6818fa52019-12-03 12:32:13 -08003485
Lucas Dupin2dd6f392020-02-18 17:43:36 -08003486 mOutput.composeSurfaces(kDebugRegion, kDefaultRefreshArgs);
3487}
3488
3489struct OutputComposeSurfacesTest_SetsExpensiveRendering_ForBlur
3490 : public OutputComposeSurfacesTest_SetsExpensiveRendering {
3491 OutputComposeSurfacesTest_SetsExpensiveRendering_ForBlur() {
3492 mLayer.layerFEState.backgroundBlurRadius = 10;
3493 mOutput.editState().isEnabled = true;
3494
Snild Dolkow9e217d62020-04-22 15:53:42 +02003495 EXPECT_CALL(mLayer.outputLayer, updateCompositionState(false, true, ui::Transform::ROT_0));
Dan Stoza6166c312021-01-15 16:34:05 -08003496 EXPECT_CALL(mLayer.outputLayer,
3497 writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false));
Lucas Dupin2dd6f392020-02-18 17:43:36 -08003498 EXPECT_CALL(mOutput, generateClientCompositionRequests(_, _, kDefaultOutputDataspace))
3499 .WillOnce(Return(std::vector<LayerFE::LayerSettings>{}));
Alec Mouri1684c702021-02-04 12:27:26 -08003500 EXPECT_CALL(mRenderEngine, drawLayers(_, _, _, false, _, _)).WillOnce(Return(NO_ERROR));
Lucas Dupin2dd6f392020-02-18 17:43:36 -08003501 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(1u));
3502 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0u))
3503 .WillRepeatedly(Return(&mLayer.outputLayer));
3504 }
3505
3506 NonInjectedLayer mLayer;
3507 compositionengine::CompositionRefreshArgs mRefreshArgs;
3508};
3509
3510TEST_F(OutputComposeSurfacesTest_SetsExpensiveRendering_ForBlur, IfBlursAreExpensive) {
3511 mRefreshArgs.blursAreExpensive = true;
Dan Stoza269dc4d2021-01-15 15:07:43 -08003512 mOutput.updateCompositionState(mRefreshArgs);
3513 mOutput.planComposition();
3514 mOutput.writeCompositionState(mRefreshArgs);
Lucas Dupin2dd6f392020-02-18 17:43:36 -08003515
3516 EXPECT_CALL(mOutput, setExpensiveRenderingExpected(true));
3517 mOutput.composeSurfaces(kDebugRegion, mRefreshArgs);
3518}
3519
3520TEST_F(OutputComposeSurfacesTest_SetsExpensiveRendering_ForBlur, IfBlursAreNotExpensive) {
3521 mRefreshArgs.blursAreExpensive = false;
Dan Stoza269dc4d2021-01-15 15:07:43 -08003522 mOutput.updateCompositionState(mRefreshArgs);
3523 mOutput.planComposition();
3524 mOutput.writeCompositionState(mRefreshArgs);
Lucas Dupin2dd6f392020-02-18 17:43:36 -08003525
3526 EXPECT_CALL(mOutput, setExpensiveRenderingExpected(true)).Times(0);
3527 mOutput.composeSurfaces(kDebugRegion, mRefreshArgs);
Lloyd Pique56eba802019-08-28 15:45:25 -07003528}
3529
3530/*
3531 * Output::generateClientCompositionRequests()
3532 */
3533
3534struct GenerateClientCompositionRequestsTest : public testing::Test {
Lloyd Piquefaa3f192019-11-14 14:05:09 -08003535 struct OutputPartialMock : public OutputPartialMockBase {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -07003536 // compositionengine::Output overrides
Vishnu Nair9b079a22020-01-21 14:36:08 -08003537 std::vector<LayerFE::LayerSettings> generateClientCompositionRequests(
Vishnu Nair3a7346c2019-12-04 08:09:09 -08003538 bool supportsProtectedContent, Region& clearRegion,
3539 ui::Dataspace dataspace) override {
Lloyd Pique56eba802019-08-28 15:45:25 -07003540 return impl::Output::generateClientCompositionRequests(supportsProtectedContent,
Vishnu Nair3a7346c2019-12-04 08:09:09 -08003541 clearRegion, dataspace);
Lloyd Pique56eba802019-08-28 15:45:25 -07003542 }
3543 };
3544
Lloyd Piquea4863342019-12-04 18:45:02 -08003545 struct Layer {
3546 Layer() {
3547 EXPECT_CALL(mOutputLayer, getState()).WillRepeatedly(ReturnRef(mOutputLayerState));
3548 EXPECT_CALL(mOutputLayer, editState()).WillRepeatedly(ReturnRef(mOutputLayerState));
Ady Abrahameca9d752021-03-03 12:20:00 -08003549 EXPECT_CALL(mOutputLayer, getLayerFE()).WillRepeatedly(ReturnRef(*mLayerFE));
3550 EXPECT_CALL(*mLayerFE, getCompositionState()).WillRepeatedly(Return(&mLayerFEState));
Lloyd Piquea4863342019-12-04 18:45:02 -08003551 }
3552
3553 StrictMock<mock::OutputLayer> mOutputLayer;
Ady Abrahameca9d752021-03-03 12:20:00 -08003554 sp<StrictMock<mock::LayerFE>> mLayerFE = sp<StrictMock<mock::LayerFE>>::make();
Lloyd Piquea4863342019-12-04 18:45:02 -08003555 LayerFECompositionState mLayerFEState;
3556 impl::OutputLayerCompositionState mOutputLayerState;
Vishnu Nair9b079a22020-01-21 14:36:08 -08003557 LayerFE::LayerSettings mLayerSettings;
Lloyd Piquea4863342019-12-04 18:45:02 -08003558 };
3559
Lloyd Pique56eba802019-08-28 15:45:25 -07003560 GenerateClientCompositionRequestsTest() {
Lloyd Piquea4863342019-12-04 18:45:02 -08003561 mOutput.mState.needsFiltering = false;
3562
Lloyd Pique56eba802019-08-28 15:45:25 -07003563 mOutput.setDisplayColorProfileForTest(
3564 std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile));
3565 mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
3566 }
3567
Lloyd Pique56eba802019-08-28 15:45:25 -07003568 mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>();
3569 mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>();
Lloyd Piquea38ea7e2019-04-16 18:10:26 -07003570 StrictMock<OutputPartialMock> mOutput;
Lloyd Pique56eba802019-08-28 15:45:25 -07003571};
3572
Lloyd Piquea4863342019-12-04 18:45:02 -08003573struct GenerateClientCompositionRequestsTest_ThreeLayers
3574 : public GenerateClientCompositionRequestsTest {
3575 GenerateClientCompositionRequestsTest_ThreeLayers() {
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02003576 mOutput.mState.orientedDisplaySpace.content = kDisplayFrame;
3577 mOutput.mState.layerStackSpace.content = kDisplayViewport;
3578 mOutput.mState.displaySpace.content = kDisplayDestinationClip;
Marin Shalamanov68933fb2020-09-10 17:58:12 +02003579 mOutput.mState.transform =
3580 ui::Transform{ui::Transform::toRotationFlags(kDisplayOrientation)};
3581 mOutput.mState.displaySpace.orientation = kDisplayOrientation;
Lloyd Piquea4863342019-12-04 18:45:02 -08003582 mOutput.mState.needsFiltering = false;
3583 mOutput.mState.isSecure = false;
Lloyd Pique56eba802019-08-28 15:45:25 -07003584
Lloyd Piquea4863342019-12-04 18:45:02 -08003585 for (size_t i = 0; i < mLayers.size(); i++) {
3586 mLayers[i].mOutputLayerState.clearClientTarget = false;
3587 mLayers[i].mOutputLayerState.visibleRegion = Region(kDisplayFrame);
3588 mLayers[i].mLayerFEState.isOpaque = true;
Vishnu Nair9b079a22020-01-21 14:36:08 -08003589 mLayers[i].mLayerSettings.geometry.boundaries =
Lloyd Piquea4863342019-12-04 18:45:02 -08003590 FloatRect{static_cast<float>(i + 1), 0.f, 0.f, 0.f};
Vishnu Nair9b079a22020-01-21 14:36:08 -08003591 mLayers[i].mLayerSettings.source.solidColor = {1.0f, 1.0f, 1.0f};
3592 mLayers[i].mLayerSettings.alpha = 1.0f;
3593 mLayers[i].mLayerSettings.disableBlending = false;
Lloyd Pique56eba802019-08-28 15:45:25 -07003594
Lloyd Piquea4863342019-12-04 18:45:02 -08003595 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(i))
3596 .WillRepeatedly(Return(&mLayers[i].mOutputLayer));
3597 EXPECT_CALL(mLayers[i].mOutputLayer, requiresClientComposition())
3598 .WillRepeatedly(Return(true));
3599 EXPECT_CALL(mLayers[i].mOutputLayer, needsFiltering()).WillRepeatedly(Return(false));
3600 }
Lloyd Pique56eba802019-08-28 15:45:25 -07003601
Lloyd Piquea4863342019-12-04 18:45:02 -08003602 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(mLayers.size()));
3603 }
Lloyd Pique56eba802019-08-28 15:45:25 -07003604
Marin Shalamanov68933fb2020-09-10 17:58:12 +02003605 static constexpr ui::Rotation kDisplayOrientation = ui::ROTATION_0;
Lloyd Piquea4863342019-12-04 18:45:02 -08003606 static constexpr ui::Dataspace kDisplayDataspace = ui::Dataspace::UNKNOWN;
Lloyd Pique56eba802019-08-28 15:45:25 -07003607
Lloyd Piquea4863342019-12-04 18:45:02 -08003608 static const Rect kDisplayFrame;
3609 static const Rect kDisplayViewport;
Lloyd Piquee8fe4742020-01-21 15:26:18 -08003610 static const Rect kDisplayDestinationClip;
Lloyd Pique56eba802019-08-28 15:45:25 -07003611
Lloyd Piquea4863342019-12-04 18:45:02 -08003612 std::array<Layer, 3> mLayers;
3613};
Lloyd Pique56eba802019-08-28 15:45:25 -07003614
Lloyd Piquea4863342019-12-04 18:45:02 -08003615const Rect GenerateClientCompositionRequestsTest_ThreeLayers::kDisplayFrame(0, 0, 100, 200);
3616const Rect GenerateClientCompositionRequestsTest_ThreeLayers::kDisplayViewport(0, 0, 101, 201);
Lloyd Piquee8fe4742020-01-21 15:26:18 -08003617const Rect GenerateClientCompositionRequestsTest_ThreeLayers::kDisplayDestinationClip(0, 0, 103,
3618 203);
Lloyd Pique56eba802019-08-28 15:45:25 -07003619
Lloyd Piquea4863342019-12-04 18:45:02 -08003620TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers, handlesNoClientCompostionLayers) {
3621 EXPECT_CALL(mLayers[0].mOutputLayer, requiresClientComposition()).WillOnce(Return(false));
3622 EXPECT_CALL(mLayers[1].mOutputLayer, requiresClientComposition()).WillOnce(Return(false));
3623 EXPECT_CALL(mLayers[2].mOutputLayer, requiresClientComposition()).WillOnce(Return(false));
Lloyd Pique56eba802019-08-28 15:45:25 -07003624
Lloyd Piquea4863342019-12-04 18:45:02 -08003625 Region accumClearRegion(Rect(10, 11, 12, 13));
3626 auto requests = mOutput.generateClientCompositionRequests(false /* supportsProtectedContent */,
3627 accumClearRegion, kDisplayDataspace);
Lloyd Pique56eba802019-08-28 15:45:25 -07003628 EXPECT_EQ(0u, requests.size());
Lloyd Piquea4863342019-12-04 18:45:02 -08003629 EXPECT_THAT(accumClearRegion, RegionEq(Region(Rect(10, 11, 12, 13))));
Lloyd Pique56eba802019-08-28 15:45:25 -07003630}
3631
Lloyd Piquea4863342019-12-04 18:45:02 -08003632TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers, requiresVisibleRegionAfterViewportClip) {
3633 mLayers[0].mOutputLayerState.visibleRegion = Region(Rect(10, 10, 10, 10));
3634 mLayers[1].mOutputLayerState.visibleRegion = Region(Rect(4000, 0, 4010, 10));
3635 mLayers[2].mOutputLayerState.visibleRegion = Region(Rect(-10, -10, 0, 0));
3636
3637 Region accumClearRegion(Rect(10, 11, 12, 13));
3638 auto requests = mOutput.generateClientCompositionRequests(false /* supportsProtectedContent */,
3639 accumClearRegion, kDisplayDataspace);
3640 EXPECT_EQ(0u, requests.size());
3641 EXPECT_THAT(accumClearRegion, RegionEq(Region(Rect(10, 11, 12, 13))));
3642}
3643
3644TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers, gathersClientCompositionRequests) {
Vishnu Nair9b079a22020-01-21 14:36:08 -08003645 LayerFE::LayerSettings mShadowSettings;
3646 mShadowSettings.source.solidColor = {0.1f, 0.1f, 0.1f};
Lloyd Piquea4863342019-12-04 18:45:02 -08003647
Ady Abrahameca9d752021-03-03 12:20:00 -08003648 EXPECT_CALL(*mLayers[0].mLayerFE, prepareClientCompositionList(_))
Vishnu Nairb87d94f2020-02-13 09:17:36 -08003649 .WillOnce(Return(std::vector<LayerFE::LayerSettings>()));
Ady Abrahameca9d752021-03-03 12:20:00 -08003650 EXPECT_CALL(*mLayers[1].mLayerFE, prepareClientCompositionList(_))
Vishnu Nairb87d94f2020-02-13 09:17:36 -08003651 .WillOnce(Return(std::vector<LayerFE::LayerSettings>({mLayers[1].mLayerSettings})));
Ady Abrahameca9d752021-03-03 12:20:00 -08003652 EXPECT_CALL(*mLayers[2].mLayerFE, prepareClientCompositionList(_))
Vishnu Nairb87d94f2020-02-13 09:17:36 -08003653 .WillOnce(Return(std::vector<LayerFE::LayerSettings>(
3654 {mShadowSettings, mLayers[2].mLayerSettings})));
Lloyd Piquea4863342019-12-04 18:45:02 -08003655
3656 Region accumClearRegion(Rect(10, 11, 12, 13));
3657 auto requests = mOutput.generateClientCompositionRequests(false /* supportsProtectedContent */,
3658 accumClearRegion, kDisplayDataspace);
3659 ASSERT_EQ(3u, requests.size());
Vishnu Nair9b079a22020-01-21 14:36:08 -08003660 EXPECT_EQ(mLayers[1].mLayerSettings, requests[0]);
3661 EXPECT_EQ(mShadowSettings, requests[1]);
3662 EXPECT_EQ(mLayers[2].mLayerSettings, requests[2]);
Lloyd Piquea4863342019-12-04 18:45:02 -08003663
3664 EXPECT_THAT(accumClearRegion, RegionEq(Region(Rect(10, 11, 12, 13))));
3665
3666 // Check that a timestamp was set for the layers that generated requests
3667 EXPECT_TRUE(0 == mLayers[0].mOutputLayerState.clientCompositionTimestamp);
3668 EXPECT_TRUE(0 != mLayers[1].mOutputLayerState.clientCompositionTimestamp);
3669 EXPECT_TRUE(0 != mLayers[2].mOutputLayerState.clientCompositionTimestamp);
3670}
3671
3672TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers,
3673 onlyClientComposesClientComposedLayersIfNoClearingNeeded) {
3674 EXPECT_CALL(mLayers[0].mOutputLayer, requiresClientComposition()).WillOnce(Return(false));
3675 EXPECT_CALL(mLayers[1].mOutputLayer, requiresClientComposition()).WillOnce(Return(false));
3676 EXPECT_CALL(mLayers[2].mOutputLayer, requiresClientComposition()).WillOnce(Return(true));
3677
3678 mLayers[0].mOutputLayerState.clearClientTarget = false;
3679 mLayers[1].mOutputLayerState.clearClientTarget = false;
3680 mLayers[2].mOutputLayerState.clearClientTarget = false;
3681
3682 mLayers[0].mLayerFEState.isOpaque = true;
3683 mLayers[1].mLayerFEState.isOpaque = true;
3684 mLayers[2].mLayerFEState.isOpaque = true;
3685
Ady Abrahameca9d752021-03-03 12:20:00 -08003686 EXPECT_CALL(*mLayers[2].mLayerFE, prepareClientCompositionList(_))
Vishnu Nairb87d94f2020-02-13 09:17:36 -08003687 .WillOnce(Return(std::vector<LayerFE::LayerSettings>({mLayers[2].mLayerSettings})));
Lloyd Piquea4863342019-12-04 18:45:02 -08003688
3689 Region accumClearRegion(Rect(10, 11, 12, 13));
3690 auto requests = mOutput.generateClientCompositionRequests(false /* supportsProtectedContent */,
3691 accumClearRegion, kDisplayDataspace);
3692 ASSERT_EQ(1u, requests.size());
Vishnu Nair9b079a22020-01-21 14:36:08 -08003693 EXPECT_EQ(mLayers[2].mLayerSettings, requests[0]);
Lloyd Piquea4863342019-12-04 18:45:02 -08003694
3695 EXPECT_THAT(accumClearRegion, RegionEq(Region(Rect(10, 11, 12, 13))));
3696}
3697
3698TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers,
3699 onlyClientComposesClientComposedLayersIfOthersAreNotOpaque) {
3700 EXPECT_CALL(mLayers[0].mOutputLayer, requiresClientComposition()).WillOnce(Return(false));
3701 EXPECT_CALL(mLayers[1].mOutputLayer, requiresClientComposition()).WillOnce(Return(false));
3702 EXPECT_CALL(mLayers[2].mOutputLayer, requiresClientComposition()).WillOnce(Return(true));
3703
3704 mLayers[0].mOutputLayerState.clearClientTarget = true;
3705 mLayers[1].mOutputLayerState.clearClientTarget = true;
3706 mLayers[2].mOutputLayerState.clearClientTarget = true;
3707
3708 mLayers[0].mLayerFEState.isOpaque = false;
3709 mLayers[1].mLayerFEState.isOpaque = false;
3710 mLayers[2].mLayerFEState.isOpaque = false;
3711
Ady Abrahameca9d752021-03-03 12:20:00 -08003712 EXPECT_CALL(*mLayers[2].mLayerFE, prepareClientCompositionList(_))
Vishnu Nairb87d94f2020-02-13 09:17:36 -08003713 .WillOnce(Return(std::vector<LayerFE::LayerSettings>({mLayers[2].mLayerSettings})));
Lloyd Piquea4863342019-12-04 18:45:02 -08003714
3715 Region accumClearRegion(Rect(10, 11, 12, 13));
3716 auto requests = mOutput.generateClientCompositionRequests(false /* supportsProtectedContent */,
3717 accumClearRegion, kDisplayDataspace);
3718 ASSERT_EQ(1u, requests.size());
Vishnu Nair9b079a22020-01-21 14:36:08 -08003719 EXPECT_EQ(mLayers[2].mLayerSettings, requests[0]);
Lloyd Piquea4863342019-12-04 18:45:02 -08003720
3721 EXPECT_THAT(accumClearRegion, RegionEq(Region(Rect(10, 11, 12, 13))));
3722}
3723
3724TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers, clearsHWCLayersIfOpaqueAndNotFirst) {
Lloyd Piquec2d54d42019-08-28 18:04:21 -07003725 // If client composition is performed with some layers set to use device
3726 // composition, device layers after the first layer (device or client) will
3727 // clear the frame buffer if they are opaque and if that layer has a flag
3728 // set to do so. The first layer is skipped as the frame buffer is already
3729 // expected to be clear.
3730
Lloyd Piquea4863342019-12-04 18:45:02 -08003731 EXPECT_CALL(mLayers[0].mOutputLayer, requiresClientComposition()).WillOnce(Return(false));
3732 EXPECT_CALL(mLayers[1].mOutputLayer, requiresClientComposition()).WillOnce(Return(false));
3733 EXPECT_CALL(mLayers[2].mOutputLayer, requiresClientComposition()).WillOnce(Return(true));
Lloyd Piquec2d54d42019-08-28 18:04:21 -07003734
Lloyd Piquea4863342019-12-04 18:45:02 -08003735 mLayers[0].mOutputLayerState.clearClientTarget = true;
3736 mLayers[1].mOutputLayerState.clearClientTarget = true;
3737 mLayers[2].mOutputLayerState.clearClientTarget = true;
Lloyd Piquec2d54d42019-08-28 18:04:21 -07003738
Lloyd Piquea4863342019-12-04 18:45:02 -08003739 mLayers[0].mLayerFEState.isOpaque = true;
3740 mLayers[1].mLayerFEState.isOpaque = true;
3741 mLayers[2].mLayerFEState.isOpaque = true;
Lloyd Piquea4863342019-12-04 18:45:02 -08003742 Region accumClearRegion(Rect(10, 11, 12, 13));
Peiyong Lind8460c82020-07-28 16:04:22 -07003743 Region stubRegion;
Vishnu Nairb87d94f2020-02-13 09:17:36 -08003744
3745 compositionengine::LayerFE::ClientCompositionTargetSettings layer1TargetSettings{
3746 Region(kDisplayFrame),
Peiyong Lind8460c82020-07-28 16:04:22 -07003747 false, /* needs filtering */
3748 false, /* secure */
3749 false, /* supports protected content */
3750 stubRegion, /* clear region */
Vishnu Nairb87d94f2020-02-13 09:17:36 -08003751 kDisplayViewport,
3752 kDisplayDataspace,
3753 false /* realContentIsVisible */,
3754 true /* clearContent */,
Galia Peycheva66eaf4a2020-11-09 13:17:57 +01003755 false /* disabledBlurs */,
Vishnu Nairb87d94f2020-02-13 09:17:36 -08003756 };
3757 compositionengine::LayerFE::ClientCompositionTargetSettings layer2TargetSettings{
3758 Region(kDisplayFrame),
Vishnu Nairb87d94f2020-02-13 09:17:36 -08003759 false, /* needs filtering */
3760 false, /* secure */
3761 false, /* supports protected content */
3762 accumClearRegion,
3763 kDisplayViewport,
3764 kDisplayDataspace,
3765 true /* realContentIsVisible */,
3766 false /* clearContent */,
Galia Peycheva66eaf4a2020-11-09 13:17:57 +01003767 false /* disabledBlurs */,
Vishnu Nairb87d94f2020-02-13 09:17:36 -08003768 };
3769
3770 LayerFE::LayerSettings mBlackoutSettings = mLayers[1].mLayerSettings;
3771 mBlackoutSettings.source.buffer.buffer = nullptr;
3772 mBlackoutSettings.source.solidColor = {0.1f, 0.1f, 0.1f};
3773 mBlackoutSettings.alpha = 0.f;
3774 mBlackoutSettings.disableBlending = true;
3775
Ady Abrahameca9d752021-03-03 12:20:00 -08003776 EXPECT_CALL(*mLayers[1].mLayerFE, prepareClientCompositionList(Eq(ByRef(layer1TargetSettings))))
Vishnu Nairb87d94f2020-02-13 09:17:36 -08003777 .WillOnce(Return(std::vector<LayerFE::LayerSettings>({mBlackoutSettings})));
Ady Abrahameca9d752021-03-03 12:20:00 -08003778 EXPECT_CALL(*mLayers[2].mLayerFE, prepareClientCompositionList(Eq(ByRef(layer2TargetSettings))))
Vishnu Nairb87d94f2020-02-13 09:17:36 -08003779 .WillOnce(Return(std::vector<LayerFE::LayerSettings>({mLayers[2].mLayerSettings})));
3780
Lloyd Piquea4863342019-12-04 18:45:02 -08003781 auto requests = mOutput.generateClientCompositionRequests(false /* supportsProtectedContent */,
3782 accumClearRegion, kDisplayDataspace);
3783 ASSERT_EQ(2u, requests.size());
Lloyd Piquec2d54d42019-08-28 18:04:21 -07003784
Lloyd Piquea4863342019-12-04 18:45:02 -08003785 // The second layer is expected to be rendered as alpha=0 black with no blending
Vishnu Nairb87d94f2020-02-13 09:17:36 -08003786 EXPECT_EQ(mBlackoutSettings, requests[0]);
Lloyd Piquec2d54d42019-08-28 18:04:21 -07003787
Vishnu Nair9b079a22020-01-21 14:36:08 -08003788 EXPECT_EQ(mLayers[2].mLayerSettings, requests[1]);
Lloyd Piquec2d54d42019-08-28 18:04:21 -07003789
Lloyd Piquea4863342019-12-04 18:45:02 -08003790 EXPECT_THAT(accumClearRegion, RegionEq(Region(Rect(10, 11, 12, 13))));
3791}
Lloyd Piquec2d54d42019-08-28 18:04:21 -07003792
Lloyd Piquea4863342019-12-04 18:45:02 -08003793TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers,
3794 clippedVisibleRegionUsedToGenerateRequest) {
3795 mLayers[0].mOutputLayerState.visibleRegion = Region(Rect(10, 10, 20, 20));
3796 mLayers[1].mOutputLayerState.visibleRegion = Region(Rect(-10, -10, 30, 30));
3797 mLayers[2].mOutputLayerState.visibleRegion = Region(Rect(-10, 0, 40, 4000));
Lloyd Piquec2d54d42019-08-28 18:04:21 -07003798
Lloyd Piquea4863342019-12-04 18:45:02 -08003799 Region accumClearRegion(Rect(10, 11, 12, 13));
3800
3801 compositionengine::LayerFE::ClientCompositionTargetSettings layer0TargetSettings{
3802 Region(Rect(10, 10, 20, 20)),
Lloyd Piquea4863342019-12-04 18:45:02 -08003803 false, /* needs filtering */
3804 false, /* secure */
3805 false, /* supports protected content */
3806 accumClearRegion,
Vishnu Nairb87d94f2020-02-13 09:17:36 -08003807 kDisplayViewport,
3808 kDisplayDataspace,
3809 true /* realContentIsVisible */,
3810 false /* clearContent */,
Galia Peycheva66eaf4a2020-11-09 13:17:57 +01003811 false /* disabledBlurs */,
Lloyd Piquea4863342019-12-04 18:45:02 -08003812 };
3813 compositionengine::LayerFE::ClientCompositionTargetSettings layer1TargetSettings{
3814 Region(Rect(0, 0, 30, 30)),
Lloyd Piquea4863342019-12-04 18:45:02 -08003815 false, /* needs filtering */
3816 false, /* secure */
3817 false, /* supports protected content */
3818 accumClearRegion,
Vishnu Nairb87d94f2020-02-13 09:17:36 -08003819 kDisplayViewport,
3820 kDisplayDataspace,
3821 true /* realContentIsVisible */,
3822 false /* clearContent */,
Galia Peycheva66eaf4a2020-11-09 13:17:57 +01003823 false /* disabledBlurs */,
Lloyd Piquea4863342019-12-04 18:45:02 -08003824 };
3825 compositionengine::LayerFE::ClientCompositionTargetSettings layer2TargetSettings{
3826 Region(Rect(0, 0, 40, 201)),
Lloyd Piquea4863342019-12-04 18:45:02 -08003827 false, /* needs filtering */
3828 false, /* secure */
3829 false, /* supports protected content */
3830 accumClearRegion,
Vishnu Nairb87d94f2020-02-13 09:17:36 -08003831 kDisplayViewport,
3832 kDisplayDataspace,
3833 true /* realContentIsVisible */,
3834 false /* clearContent */,
Galia Peycheva66eaf4a2020-11-09 13:17:57 +01003835 false /* disabledBlurs */,
Lloyd Piquea4863342019-12-04 18:45:02 -08003836 };
3837
Ady Abrahameca9d752021-03-03 12:20:00 -08003838 EXPECT_CALL(*mLayers[0].mLayerFE, prepareClientCompositionList(Eq(ByRef(layer0TargetSettings))))
Vishnu Nairb87d94f2020-02-13 09:17:36 -08003839 .WillOnce(Return(std::vector<LayerFE::LayerSettings>()));
Ady Abrahameca9d752021-03-03 12:20:00 -08003840 EXPECT_CALL(*mLayers[1].mLayerFE, prepareClientCompositionList(Eq(ByRef(layer1TargetSettings))))
Vishnu Nairb87d94f2020-02-13 09:17:36 -08003841 .WillOnce(Return(std::vector<LayerFE::LayerSettings>()));
Ady Abrahameca9d752021-03-03 12:20:00 -08003842 EXPECT_CALL(*mLayers[2].mLayerFE, prepareClientCompositionList(Eq(ByRef(layer2TargetSettings))))
Vishnu Nairb87d94f2020-02-13 09:17:36 -08003843 .WillOnce(Return(std::vector<LayerFE::LayerSettings>()));
Lloyd Piquea4863342019-12-04 18:45:02 -08003844
3845 static_cast<void>(
3846 mOutput.generateClientCompositionRequests(false /* supportsProtectedContent */,
3847 accumClearRegion, kDisplayDataspace));
3848}
3849
3850TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers,
3851 perLayerNeedsFilteringUsedToGenerateRequests) {
3852 mOutput.mState.needsFiltering = false;
3853 EXPECT_CALL(mLayers[0].mOutputLayer, needsFiltering()).WillRepeatedly(Return(true));
3854
3855 Region accumClearRegion(Rect(10, 11, 12, 13));
3856
3857 compositionengine::LayerFE::ClientCompositionTargetSettings layer0TargetSettings{
3858 Region(kDisplayFrame),
Lloyd Piquea4863342019-12-04 18:45:02 -08003859 true, /* needs filtering */
3860 false, /* secure */
3861 false, /* supports protected content */
3862 accumClearRegion,
Vishnu Nairb87d94f2020-02-13 09:17:36 -08003863 kDisplayViewport,
3864 kDisplayDataspace,
3865 true /* realContentIsVisible */,
3866 false /* clearContent */,
Galia Peycheva66eaf4a2020-11-09 13:17:57 +01003867 false /* disabledBlurs */,
Lloyd Piquea4863342019-12-04 18:45:02 -08003868 };
3869 compositionengine::LayerFE::ClientCompositionTargetSettings layer1TargetSettings{
3870 Region(kDisplayFrame),
Lloyd Piquea4863342019-12-04 18:45:02 -08003871 false, /* needs filtering */
3872 false, /* secure */
3873 false, /* supports protected content */
3874 accumClearRegion,
Vishnu Nairb87d94f2020-02-13 09:17:36 -08003875 kDisplayViewport,
3876 kDisplayDataspace,
3877 true /* realContentIsVisible */,
3878 false /* clearContent */,
Galia Peycheva66eaf4a2020-11-09 13:17:57 +01003879 false /* disabledBlurs */,
Lloyd Piquea4863342019-12-04 18:45:02 -08003880 };
3881 compositionengine::LayerFE::ClientCompositionTargetSettings layer2TargetSettings{
3882 Region(kDisplayFrame),
Lloyd Piquea4863342019-12-04 18:45:02 -08003883 false, /* needs filtering */
3884 false, /* secure */
3885 false, /* supports protected content */
3886 accumClearRegion,
Vishnu Nairb87d94f2020-02-13 09:17:36 -08003887 kDisplayViewport,
3888 kDisplayDataspace,
3889 true /* realContentIsVisible */,
3890 false /* clearContent */,
Galia Peycheva66eaf4a2020-11-09 13:17:57 +01003891 false /* disabledBlurs */,
Lloyd Piquea4863342019-12-04 18:45:02 -08003892 };
3893
Ady Abrahameca9d752021-03-03 12:20:00 -08003894 EXPECT_CALL(*mLayers[0].mLayerFE, prepareClientCompositionList(Eq(ByRef(layer0TargetSettings))))
Vishnu Nairb87d94f2020-02-13 09:17:36 -08003895 .WillOnce(Return(std::vector<LayerFE::LayerSettings>()));
Ady Abrahameca9d752021-03-03 12:20:00 -08003896 EXPECT_CALL(*mLayers[1].mLayerFE, prepareClientCompositionList(Eq(ByRef(layer1TargetSettings))))
Vishnu Nairb87d94f2020-02-13 09:17:36 -08003897 .WillOnce(Return(std::vector<LayerFE::LayerSettings>()));
Ady Abrahameca9d752021-03-03 12:20:00 -08003898 EXPECT_CALL(*mLayers[2].mLayerFE, prepareClientCompositionList(Eq(ByRef(layer2TargetSettings))))
Vishnu Nairb87d94f2020-02-13 09:17:36 -08003899 .WillOnce(Return(std::vector<LayerFE::LayerSettings>()));
Lloyd Piquea4863342019-12-04 18:45:02 -08003900
3901 static_cast<void>(
3902 mOutput.generateClientCompositionRequests(false /* supportsProtectedContent */,
3903 accumClearRegion, kDisplayDataspace));
3904}
3905
3906TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers,
3907 wholeOutputNeedsFilteringUsedToGenerateRequests) {
3908 mOutput.mState.needsFiltering = true;
3909 EXPECT_CALL(mLayers[0].mOutputLayer, needsFiltering()).WillRepeatedly(Return(true));
3910
3911 Region accumClearRegion(Rect(10, 11, 12, 13));
3912
3913 compositionengine::LayerFE::ClientCompositionTargetSettings layer0TargetSettings{
3914 Region(kDisplayFrame),
Lloyd Piquea4863342019-12-04 18:45:02 -08003915 true, /* needs filtering */
3916 false, /* secure */
3917 false, /* supports protected content */
3918 accumClearRegion,
Vishnu Nairb87d94f2020-02-13 09:17:36 -08003919 kDisplayViewport,
3920 kDisplayDataspace,
3921 true /* realContentIsVisible */,
3922 false /* clearContent */,
Galia Peycheva66eaf4a2020-11-09 13:17:57 +01003923 false /* disabledBlurs */,
Vishnu Nairb87d94f2020-02-13 09:17:36 -08003924
Lloyd Piquea4863342019-12-04 18:45:02 -08003925 };
3926 compositionengine::LayerFE::ClientCompositionTargetSettings layer1TargetSettings{
3927 Region(kDisplayFrame),
Lloyd Piquea4863342019-12-04 18:45:02 -08003928 true, /* needs filtering */
3929 false, /* secure */
3930 false, /* supports protected content */
3931 accumClearRegion,
Vishnu Nairb87d94f2020-02-13 09:17:36 -08003932 kDisplayViewport,
3933 kDisplayDataspace,
3934 true /* realContentIsVisible */,
3935 false /* clearContent */,
Galia Peycheva66eaf4a2020-11-09 13:17:57 +01003936 false /* disabledBlurs */,
Lloyd Piquea4863342019-12-04 18:45:02 -08003937 };
3938 compositionengine::LayerFE::ClientCompositionTargetSettings layer2TargetSettings{
3939 Region(kDisplayFrame),
Lloyd Piquea4863342019-12-04 18:45:02 -08003940 true, /* needs filtering */
3941 false, /* secure */
3942 false, /* supports protected content */
3943 accumClearRegion,
Vishnu Nairb87d94f2020-02-13 09:17:36 -08003944 kDisplayViewport,
3945 kDisplayDataspace,
3946 true /* realContentIsVisible */,
3947 false /* clearContent */,
Galia Peycheva66eaf4a2020-11-09 13:17:57 +01003948 false /* disabledBlurs */,
Lloyd Piquea4863342019-12-04 18:45:02 -08003949 };
3950
Ady Abrahameca9d752021-03-03 12:20:00 -08003951 EXPECT_CALL(*mLayers[0].mLayerFE, prepareClientCompositionList(Eq(ByRef(layer0TargetSettings))))
Vishnu Nairb87d94f2020-02-13 09:17:36 -08003952 .WillOnce(Return(std::vector<LayerFE::LayerSettings>()));
Ady Abrahameca9d752021-03-03 12:20:00 -08003953 EXPECT_CALL(*mLayers[1].mLayerFE, prepareClientCompositionList(Eq(ByRef(layer1TargetSettings))))
Vishnu Nairb87d94f2020-02-13 09:17:36 -08003954 .WillOnce(Return(std::vector<LayerFE::LayerSettings>()));
Ady Abrahameca9d752021-03-03 12:20:00 -08003955 EXPECT_CALL(*mLayers[2].mLayerFE, prepareClientCompositionList(Eq(ByRef(layer2TargetSettings))))
Vishnu Nairb87d94f2020-02-13 09:17:36 -08003956 .WillOnce(Return(std::vector<LayerFE::LayerSettings>()));
Lloyd Piquea4863342019-12-04 18:45:02 -08003957
3958 static_cast<void>(
3959 mOutput.generateClientCompositionRequests(false /* supportsProtectedContent */,
3960 accumClearRegion, kDisplayDataspace));
3961}
3962
3963TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers,
3964 wholeOutputSecurityUsedToGenerateRequests) {
3965 mOutput.mState.isSecure = true;
3966
3967 Region accumClearRegion(Rect(10, 11, 12, 13));
3968
3969 compositionengine::LayerFE::ClientCompositionTargetSettings layer0TargetSettings{
3970 Region(kDisplayFrame),
Lloyd Piquea4863342019-12-04 18:45:02 -08003971 false, /* needs filtering */
3972 true, /* secure */
3973 false, /* supports protected content */
3974 accumClearRegion,
Vishnu Nairb87d94f2020-02-13 09:17:36 -08003975 kDisplayViewport,
3976 kDisplayDataspace,
3977 true /* realContentIsVisible */,
3978 false /* clearContent */,
Galia Peycheva66eaf4a2020-11-09 13:17:57 +01003979 false /* disabledBlurs */,
Lloyd Piquea4863342019-12-04 18:45:02 -08003980 };
3981 compositionengine::LayerFE::ClientCompositionTargetSettings layer1TargetSettings{
3982 Region(kDisplayFrame),
Lloyd Piquea4863342019-12-04 18:45:02 -08003983 false, /* needs filtering */
3984 true, /* secure */
3985 false, /* supports protected content */
3986 accumClearRegion,
Vishnu Nairb87d94f2020-02-13 09:17:36 -08003987 kDisplayViewport,
3988 kDisplayDataspace,
3989 true /* realContentIsVisible */,
3990 false /* clearContent */,
Galia Peycheva66eaf4a2020-11-09 13:17:57 +01003991 false /* disabledBlurs */,
Lloyd Piquea4863342019-12-04 18:45:02 -08003992 };
3993 compositionengine::LayerFE::ClientCompositionTargetSettings layer2TargetSettings{
3994 Region(kDisplayFrame),
Lloyd Piquea4863342019-12-04 18:45:02 -08003995 false, /* needs filtering */
3996 true, /* secure */
3997 false, /* supports protected content */
3998 accumClearRegion,
Vishnu Nairb87d94f2020-02-13 09:17:36 -08003999 kDisplayViewport,
4000 kDisplayDataspace,
4001 true /* realContentIsVisible */,
4002 false /* clearContent */,
Galia Peycheva66eaf4a2020-11-09 13:17:57 +01004003 false /* disabledBlurs */,
Lloyd Piquea4863342019-12-04 18:45:02 -08004004 };
4005
Ady Abrahameca9d752021-03-03 12:20:00 -08004006 EXPECT_CALL(*mLayers[0].mLayerFE, prepareClientCompositionList(Eq(ByRef(layer0TargetSettings))))
Vishnu Nairb87d94f2020-02-13 09:17:36 -08004007 .WillOnce(Return(std::vector<LayerFE::LayerSettings>()));
Ady Abrahameca9d752021-03-03 12:20:00 -08004008 EXPECT_CALL(*mLayers[1].mLayerFE, prepareClientCompositionList(Eq(ByRef(layer1TargetSettings))))
Vishnu Nairb87d94f2020-02-13 09:17:36 -08004009 .WillOnce(Return(std::vector<LayerFE::LayerSettings>()));
Ady Abrahameca9d752021-03-03 12:20:00 -08004010 EXPECT_CALL(*mLayers[2].mLayerFE, prepareClientCompositionList(Eq(ByRef(layer2TargetSettings))))
Vishnu Nairb87d94f2020-02-13 09:17:36 -08004011 .WillOnce(Return(std::vector<LayerFE::LayerSettings>()));
Lloyd Piquea4863342019-12-04 18:45:02 -08004012
4013 static_cast<void>(
4014 mOutput.generateClientCompositionRequests(false /* supportsProtectedContent */,
4015 accumClearRegion, kDisplayDataspace));
4016}
4017
4018TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers,
4019 protectedContentSupportUsedToGenerateRequests) {
4020 Region accumClearRegion(Rect(10, 11, 12, 13));
4021
4022 compositionengine::LayerFE::ClientCompositionTargetSettings layer0TargetSettings{
4023 Region(kDisplayFrame),
Lloyd Piquea4863342019-12-04 18:45:02 -08004024 false, /* needs filtering */
4025 false, /* secure */
4026 true, /* supports protected content */
4027 accumClearRegion,
Vishnu Nairb87d94f2020-02-13 09:17:36 -08004028 kDisplayViewport,
4029 kDisplayDataspace,
4030 true /* realContentIsVisible */,
4031 false /* clearContent */,
Galia Peycheva66eaf4a2020-11-09 13:17:57 +01004032 false /* disabledBlurs */,
Lloyd Piquea4863342019-12-04 18:45:02 -08004033 };
4034 compositionengine::LayerFE::ClientCompositionTargetSettings layer1TargetSettings{
4035 Region(kDisplayFrame),
Lloyd Piquea4863342019-12-04 18:45:02 -08004036 false, /* needs filtering */
4037 false, /* secure */
4038 true, /* supports protected content */
4039 accumClearRegion,
Vishnu Nairb87d94f2020-02-13 09:17:36 -08004040 kDisplayViewport,
4041 kDisplayDataspace,
4042 true /* realContentIsVisible */,
4043 false /* clearContent */,
Galia Peycheva66eaf4a2020-11-09 13:17:57 +01004044 false /* disabledBlurs */,
Lloyd Piquea4863342019-12-04 18:45:02 -08004045 };
4046 compositionengine::LayerFE::ClientCompositionTargetSettings layer2TargetSettings{
4047 Region(kDisplayFrame),
Lloyd Piquea4863342019-12-04 18:45:02 -08004048 false, /* needs filtering */
4049 false, /* secure */
4050 true, /* supports protected content */
4051 accumClearRegion,
Vishnu Nairb87d94f2020-02-13 09:17:36 -08004052 kDisplayViewport,
4053 kDisplayDataspace,
4054 true /* realContentIsVisible */,
4055 false /* clearContent */,
Galia Peycheva66eaf4a2020-11-09 13:17:57 +01004056 false /* disabledBlurs */,
Lloyd Piquea4863342019-12-04 18:45:02 -08004057 };
4058
Ady Abrahameca9d752021-03-03 12:20:00 -08004059 EXPECT_CALL(*mLayers[0].mLayerFE, prepareClientCompositionList(Eq(ByRef(layer0TargetSettings))))
Vishnu Nairb87d94f2020-02-13 09:17:36 -08004060 .WillOnce(Return(std::vector<LayerFE::LayerSettings>()));
Ady Abrahameca9d752021-03-03 12:20:00 -08004061 EXPECT_CALL(*mLayers[1].mLayerFE, prepareClientCompositionList(Eq(ByRef(layer1TargetSettings))))
Vishnu Nairb87d94f2020-02-13 09:17:36 -08004062 .WillOnce(Return(std::vector<LayerFE::LayerSettings>()));
Ady Abrahameca9d752021-03-03 12:20:00 -08004063 EXPECT_CALL(*mLayers[2].mLayerFE, prepareClientCompositionList(Eq(ByRef(layer2TargetSettings))))
Vishnu Nairb87d94f2020-02-13 09:17:36 -08004064 .WillOnce(Return(std::vector<LayerFE::LayerSettings>()));
Lloyd Piquea4863342019-12-04 18:45:02 -08004065
4066 static_cast<void>(mOutput.generateClientCompositionRequests(true /* supportsProtectedContent */,
4067 accumClearRegion,
4068 kDisplayDataspace));
4069}
4070
Lucas Dupin19c8f0e2019-11-25 17:55:44 -08004071TEST_F(OutputUpdateAndWriteCompositionStateTest, handlesBackgroundBlurRequests) {
Lloyd Piquede196652020-01-22 17:29:58 -08004072 InjectedLayer layer1;
4073 InjectedLayer layer2;
4074 InjectedLayer layer3;
4075
Lucas Dupin19c8f0e2019-11-25 17:55:44 -08004076 // Layer requesting blur, or below, should request client composition.
Snild Dolkow9e217d62020-04-22 15:53:42 +02004077 EXPECT_CALL(*layer1.outputLayer, updateCompositionState(false, true, ui::Transform::ROT_0));
Dan Stoza6166c312021-01-15 16:34:05 -08004078 EXPECT_CALL(*layer1.outputLayer,
4079 writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false));
Snild Dolkow9e217d62020-04-22 15:53:42 +02004080 EXPECT_CALL(*layer2.outputLayer, updateCompositionState(false, true, ui::Transform::ROT_0));
Dan Stoza6166c312021-01-15 16:34:05 -08004081 EXPECT_CALL(*layer2.outputLayer,
4082 writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false));
Snild Dolkow9e217d62020-04-22 15:53:42 +02004083 EXPECT_CALL(*layer3.outputLayer, updateCompositionState(false, false, ui::Transform::ROT_0));
Dan Stoza6166c312021-01-15 16:34:05 -08004084 EXPECT_CALL(*layer3.outputLayer,
4085 writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false));
Lucas Dupin19c8f0e2019-11-25 17:55:44 -08004086
Lloyd Piquede196652020-01-22 17:29:58 -08004087 layer2.layerFEState.backgroundBlurRadius = 10;
Lucas Dupin19c8f0e2019-11-25 17:55:44 -08004088
Lloyd Piquede196652020-01-22 17:29:58 -08004089 injectOutputLayer(layer1);
4090 injectOutputLayer(layer2);
4091 injectOutputLayer(layer3);
Lucas Dupin19c8f0e2019-11-25 17:55:44 -08004092
4093 mOutput->editState().isEnabled = true;
4094
4095 CompositionRefreshArgs args;
4096 args.updatingGeometryThisFrame = false;
4097 args.devOptForceClientComposition = false;
Dan Stoza269dc4d2021-01-15 15:07:43 -08004098 mOutput->updateCompositionState(args);
4099 mOutput->planComposition();
4100 mOutput->writeCompositionState(args);
Lucas Dupin19c8f0e2019-11-25 17:55:44 -08004101}
4102
Lucas Dupinc3800b82020-10-02 16:24:48 -07004103TEST_F(OutputUpdateAndWriteCompositionStateTest, handlesBlurRegionRequests) {
4104 InjectedLayer layer1;
4105 InjectedLayer layer2;
4106 InjectedLayer layer3;
4107
4108 // Layer requesting blur, or below, should request client composition.
4109 EXPECT_CALL(*layer1.outputLayer, updateCompositionState(false, true, ui::Transform::ROT_0));
Dan Stoza6166c312021-01-15 16:34:05 -08004110 EXPECT_CALL(*layer1.outputLayer,
4111 writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false));
Lucas Dupinc3800b82020-10-02 16:24:48 -07004112 EXPECT_CALL(*layer2.outputLayer, updateCompositionState(false, true, ui::Transform::ROT_0));
Dan Stoza6166c312021-01-15 16:34:05 -08004113 EXPECT_CALL(*layer2.outputLayer,
4114 writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false));
Lucas Dupinc3800b82020-10-02 16:24:48 -07004115 EXPECT_CALL(*layer3.outputLayer, updateCompositionState(false, false, ui::Transform::ROT_0));
Dan Stoza6166c312021-01-15 16:34:05 -08004116 EXPECT_CALL(*layer3.outputLayer,
4117 writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false));
Lucas Dupinc3800b82020-10-02 16:24:48 -07004118
4119 BlurRegion region;
4120 layer2.layerFEState.blurRegions.push_back(region);
4121
4122 injectOutputLayer(layer1);
4123 injectOutputLayer(layer2);
4124 injectOutputLayer(layer3);
4125
4126 mOutput->editState().isEnabled = true;
4127
4128 CompositionRefreshArgs args;
4129 args.updatingGeometryThisFrame = false;
4130 args.devOptForceClientComposition = false;
Dan Stoza269dc4d2021-01-15 15:07:43 -08004131 mOutput->updateCompositionState(args);
4132 mOutput->planComposition();
4133 mOutput->writeCompositionState(args);
Lucas Dupinc3800b82020-10-02 16:24:48 -07004134}
4135
Lloyd Piquea4863342019-12-04 18:45:02 -08004136TEST_F(GenerateClientCompositionRequestsTest, handlesLandscapeModeSplitScreenRequests) {
4137 // In split-screen landscape mode, the screen is rotated 90 degrees, with
4138 // one layer on the left covering the left side of the output, and one layer
4139 // on the right covering that side of the output.
Lloyd Piquec2d54d42019-08-28 18:04:21 -07004140
4141 const Rect kPortraitFrame(0, 0, 1000, 2000);
4142 const Rect kPortraitViewport(0, 0, 2000, 1000);
Lloyd Piquee8fe4742020-01-21 15:26:18 -08004143 const Rect kPortraitDestinationClip(0, 0, 1000, 2000);
Marin Shalamanov68933fb2020-09-10 17:58:12 +02004144 const ui::Rotation kPortraitOrientation = ui::ROTATION_90;
Lloyd Piquea4863342019-12-04 18:45:02 -08004145 constexpr ui::Dataspace kOutputDataspace = ui::Dataspace::DISPLAY_P3;
Lloyd Piquec2d54d42019-08-28 18:04:21 -07004146
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02004147 mOutput.mState.orientedDisplaySpace.content = kPortraitFrame;
4148 mOutput.mState.layerStackSpace.content = kPortraitViewport;
4149 mOutput.mState.displaySpace.content = kPortraitDestinationClip;
Marin Shalamanov68933fb2020-09-10 17:58:12 +02004150 mOutput.mState.transform = ui::Transform{ui::Transform::toRotationFlags(kPortraitOrientation)};
4151 mOutput.mState.displaySpace.orientation = kPortraitOrientation;
Lloyd Piquea4863342019-12-04 18:45:02 -08004152 mOutput.mState.needsFiltering = false;
4153 mOutput.mState.isSecure = true;
Lloyd Piquec2d54d42019-08-28 18:04:21 -07004154
Lloyd Piquea4863342019-12-04 18:45:02 -08004155 Layer leftLayer;
4156 Layer rightLayer;
Lloyd Piquec2d54d42019-08-28 18:04:21 -07004157
Lloyd Piquea4863342019-12-04 18:45:02 -08004158 leftLayer.mOutputLayerState.clearClientTarget = false;
4159 leftLayer.mOutputLayerState.visibleRegion = Region(Rect(0, 0, 1000, 1000));
4160 leftLayer.mLayerFEState.isOpaque = true;
Vishnu Nair9b079a22020-01-21 14:36:08 -08004161 leftLayer.mLayerSettings.source.solidColor = {1.f, 0.f, 0.f};
Lloyd Piquec2d54d42019-08-28 18:04:21 -07004162
Lloyd Piquea4863342019-12-04 18:45:02 -08004163 rightLayer.mOutputLayerState.clearClientTarget = false;
4164 rightLayer.mOutputLayerState.visibleRegion = Region(Rect(1000, 0, 2000, 1000));
4165 rightLayer.mLayerFEState.isOpaque = true;
Vishnu Nair9b079a22020-01-21 14:36:08 -08004166 rightLayer.mLayerSettings.source.solidColor = {0.f, 1.f, 0.f};
Lloyd Piquea4863342019-12-04 18:45:02 -08004167
4168 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(2u));
4169 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0u))
4170 .WillRepeatedly(Return(&leftLayer.mOutputLayer));
4171 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(1u))
4172 .WillRepeatedly(Return(&rightLayer.mOutputLayer));
4173
4174 Region accumClearRegion(Rect(10, 11, 12, 13));
4175
4176 compositionengine::LayerFE::ClientCompositionTargetSettings leftLayerSettings{
4177 Region(Rect(0, 0, 1000, 1000)),
Lloyd Piquea4863342019-12-04 18:45:02 -08004178 false, /* needs filtering */
4179 true, /* secure */
4180 true, /* supports protected content */
4181 accumClearRegion,
Vishnu Nairb87d94f2020-02-13 09:17:36 -08004182 kPortraitViewport,
4183 kOutputDataspace,
4184 true /* realContentIsVisible */,
4185 false /* clearContent */,
Galia Peycheva66eaf4a2020-11-09 13:17:57 +01004186 false /* disabledBlurs */,
Lloyd Piquea4863342019-12-04 18:45:02 -08004187 };
4188
4189 EXPECT_CALL(leftLayer.mOutputLayer, requiresClientComposition()).WillRepeatedly(Return(true));
4190 EXPECT_CALL(leftLayer.mOutputLayer, needsFiltering()).WillRepeatedly(Return(false));
Ady Abrahameca9d752021-03-03 12:20:00 -08004191 EXPECT_CALL(*leftLayer.mLayerFE, prepareClientCompositionList(Eq(ByRef(leftLayerSettings))))
Vishnu Nairb87d94f2020-02-13 09:17:36 -08004192 .WillOnce(Return(std::vector<LayerFE::LayerSettings>({leftLayer.mLayerSettings})));
Lloyd Piquea4863342019-12-04 18:45:02 -08004193
4194 compositionengine::LayerFE::ClientCompositionTargetSettings rightLayerSettings{
4195 Region(Rect(1000, 0, 2000, 1000)),
Lloyd Piquea4863342019-12-04 18:45:02 -08004196 false, /* needs filtering */
4197 true, /* secure */
4198 true, /* supports protected content */
4199 accumClearRegion,
Vishnu Nairb87d94f2020-02-13 09:17:36 -08004200 kPortraitViewport,
4201 kOutputDataspace,
4202 true /* realContentIsVisible */,
4203 false /* clearContent */,
Galia Peycheva66eaf4a2020-11-09 13:17:57 +01004204 false /* disabledBlurs */,
Lloyd Piquea4863342019-12-04 18:45:02 -08004205 };
4206
4207 EXPECT_CALL(rightLayer.mOutputLayer, requiresClientComposition()).WillRepeatedly(Return(true));
4208 EXPECT_CALL(rightLayer.mOutputLayer, needsFiltering()).WillRepeatedly(Return(false));
Ady Abrahameca9d752021-03-03 12:20:00 -08004209 EXPECT_CALL(*rightLayer.mLayerFE, prepareClientCompositionList(Eq(ByRef(rightLayerSettings))))
Vishnu Nairb87d94f2020-02-13 09:17:36 -08004210 .WillOnce(Return(std::vector<LayerFE::LayerSettings>({rightLayer.mLayerSettings})));
Lloyd Piquea4863342019-12-04 18:45:02 -08004211
4212 constexpr bool supportsProtectedContent = true;
4213 auto requests = mOutput.generateClientCompositionRequests(supportsProtectedContent,
4214 accumClearRegion, kOutputDataspace);
4215 ASSERT_EQ(2u, requests.size());
Vishnu Nair9b079a22020-01-21 14:36:08 -08004216 EXPECT_EQ(leftLayer.mLayerSettings, requests[0]);
4217 EXPECT_EQ(rightLayer.mLayerSettings, requests[1]);
Lloyd Piquec2d54d42019-08-28 18:04:21 -07004218}
4219
Vishnu Naira483b4a2019-12-12 15:07:52 -08004220TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers,
4221 shadowRegionOnlyVisibleSkipsContentComposition) {
4222 const Rect kContentWithShadow(40, 40, 70, 90);
4223 const Rect kContent(50, 50, 60, 80);
4224 const Region kShadowRegion = Region(kContentWithShadow).subtract(kContent);
4225 const Region kPartialShadowRegion = Region(kContentWithShadow).subtract(Rect(40, 40, 60, 80));
4226
Vishnu Nairb87d94f2020-02-13 09:17:36 -08004227 Region accumClearRegion(Rect(10, 11, 12, 13));
4228 compositionengine::LayerFE::ClientCompositionTargetSettings layer2Settings{
4229 Region(Rect(60, 40, 70, 80)).merge(Rect(40, 80, 70, 90)), /* visible region */
Vishnu Nairb87d94f2020-02-13 09:17:36 -08004230 false, /* needs filtering */
4231 false, /* secure */
4232 false, /* supports protected content */
4233 accumClearRegion,
4234 kDisplayViewport,
4235 kDisplayDataspace,
4236 false /* realContentIsVisible */,
4237 false /* clearContent */,
Galia Peycheva66eaf4a2020-11-09 13:17:57 +01004238 false /* disabledBlurs */,
Vishnu Nairb87d94f2020-02-13 09:17:36 -08004239 };
4240
Vishnu Nair9b079a22020-01-21 14:36:08 -08004241 LayerFE::LayerSettings mShadowSettings;
4242 mShadowSettings.source.solidColor = {0.1f, 0.1f, 0.1f};
Vishnu Naira483b4a2019-12-12 15:07:52 -08004243
4244 mLayers[2].mOutputLayerState.visibleRegion = kPartialShadowRegion;
4245 mLayers[2].mOutputLayerState.shadowRegion = kShadowRegion;
4246
4247 EXPECT_CALL(mLayers[0].mOutputLayer, requiresClientComposition()).WillOnce(Return(false));
4248 EXPECT_CALL(mLayers[1].mOutputLayer, requiresClientComposition()).WillOnce(Return(false));
Ady Abrahameca9d752021-03-03 12:20:00 -08004249 EXPECT_CALL(*mLayers[2].mLayerFE, prepareClientCompositionList(Eq(ByRef(layer2Settings))))
Vishnu Nairb87d94f2020-02-13 09:17:36 -08004250 .WillOnce(Return(std::vector<LayerFE::LayerSettings>({mShadowSettings})));
Vishnu Naira483b4a2019-12-12 15:07:52 -08004251
Vishnu Naira483b4a2019-12-12 15:07:52 -08004252 auto requests = mOutput.generateClientCompositionRequests(false /* supportsProtectedContent */,
4253 accumClearRegion, kDisplayDataspace);
4254 ASSERT_EQ(1u, requests.size());
4255
Vishnu Nair9b079a22020-01-21 14:36:08 -08004256 EXPECT_EQ(mShadowSettings, requests[0]);
Vishnu Naira483b4a2019-12-12 15:07:52 -08004257}
4258
4259TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers,
4260 shadowRegionWithContentVisibleRequestsContentAndShadowComposition) {
4261 const Rect kContentWithShadow(40, 40, 70, 90);
4262 const Rect kContent(50, 50, 60, 80);
4263 const Region kShadowRegion = Region(kContentWithShadow).subtract(kContent);
4264 const Region kPartialContentWithPartialShadowRegion =
4265 Region(kContentWithShadow).subtract(Rect(40, 40, 50, 80));
4266
Vishnu Nair9b079a22020-01-21 14:36:08 -08004267 LayerFE::LayerSettings mShadowSettings;
4268 mShadowSettings.source.solidColor = {0.1f, 0.1f, 0.1f};
Vishnu Naira483b4a2019-12-12 15:07:52 -08004269
4270 mLayers[2].mOutputLayerState.visibleRegion = kPartialContentWithPartialShadowRegion;
4271 mLayers[2].mOutputLayerState.shadowRegion = kShadowRegion;
4272
Vishnu Nairb87d94f2020-02-13 09:17:36 -08004273 Region accumClearRegion(Rect(10, 11, 12, 13));
4274 compositionengine::LayerFE::ClientCompositionTargetSettings layer2Settings{
4275 Region(Rect(50, 40, 70, 80)).merge(Rect(40, 80, 70, 90)), /* visible region */
Vishnu Nairb87d94f2020-02-13 09:17:36 -08004276 false, /* needs filtering */
4277 false, /* secure */
4278 false, /* supports protected content */
4279 accumClearRegion,
4280 kDisplayViewport,
4281 kDisplayDataspace,
4282 true /* realContentIsVisible */,
4283 false /* clearContent */,
Galia Peycheva66eaf4a2020-11-09 13:17:57 +01004284 false /* disabledBlurs */,
Vishnu Nairb87d94f2020-02-13 09:17:36 -08004285 };
4286
Vishnu Naira483b4a2019-12-12 15:07:52 -08004287 EXPECT_CALL(mLayers[0].mOutputLayer, requiresClientComposition()).WillOnce(Return(false));
4288 EXPECT_CALL(mLayers[1].mOutputLayer, requiresClientComposition()).WillOnce(Return(false));
Ady Abrahameca9d752021-03-03 12:20:00 -08004289 EXPECT_CALL(*mLayers[2].mLayerFE, prepareClientCompositionList(Eq(ByRef(layer2Settings))))
Vishnu Nairb87d94f2020-02-13 09:17:36 -08004290 .WillOnce(Return(std::vector<LayerFE::LayerSettings>(
4291 {mShadowSettings, mLayers[2].mLayerSettings})));
Vishnu Naira483b4a2019-12-12 15:07:52 -08004292
Vishnu Naira483b4a2019-12-12 15:07:52 -08004293 auto requests = mOutput.generateClientCompositionRequests(false /* supportsProtectedContent */,
4294 accumClearRegion, kDisplayDataspace);
4295 ASSERT_EQ(2u, requests.size());
4296
Vishnu Nair9b079a22020-01-21 14:36:08 -08004297 EXPECT_EQ(mShadowSettings, requests[0]);
4298 EXPECT_EQ(mLayers[2].mLayerSettings, requests[1]);
Vishnu Naira483b4a2019-12-12 15:07:52 -08004299}
4300
Lloyd Pique32cbe282018-10-19 13:09:22 -07004301} // namespace
4302} // namespace android::compositionengine