1 /*
2 * Copyright 2019 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <android-base/stringprintf.h>
18 #include <compositionengine/LayerFECompositionState.h>
19 #include <compositionengine/impl/Output.h>
20 #include <compositionengine/impl/OutputCompositionState.h>
21 #include <compositionengine/impl/OutputLayerCompositionState.h>
22 #include <compositionengine/mock/CompositionEngine.h>
23 #include <compositionengine/mock/DisplayColorProfile.h>
24 #include <compositionengine/mock/LayerFE.h>
25 #include <compositionengine/mock/OutputLayer.h>
26 #include <compositionengine/mock/RenderSurface.h>
27 #include <gtest/gtest.h>
28 #include <renderengine/mock/RenderEngine.h>
29 #include <ui/Rect.h>
30 #include <ui/Region.h>
31
32 #include <cmath>
33 #include <cstdint>
34
35 #include "CallOrderStateMachineHelper.h"
36 #include "MockHWC2.h"
37 #include "RegionMatcher.h"
38 #include "renderengine/ExternalTexture.h"
39
40 namespace android::compositionengine {
41 namespace {
42
43 using testing::_;
44 using testing::ByMove;
45 using testing::ByRef;
46 using testing::DoAll;
47 using testing::ElementsAre;
48 using testing::ElementsAreArray;
49 using testing::Eq;
50 using testing::InSequence;
51 using testing::Invoke;
52 using testing::IsEmpty;
53 using testing::Mock;
54 using testing::Pointee;
55 using testing::Property;
56 using testing::Ref;
57 using testing::Return;
58 using testing::ReturnRef;
59 using testing::SetArgPointee;
60 using testing::StrictMock;
61
62 constexpr auto TR_IDENT = 0u;
63 constexpr auto TR_ROT_90 = HAL_TRANSFORM_ROT_90;
64 constexpr auto MAX_CLIENT_COMPOSITION_CACHE_SIZE = 3;
65
66 const mat4 kIdentity;
67 const mat4 kNonIdentityHalf = mat4() * 0.5f;
68 const mat4 kNonIdentityQuarter = mat4() * 0.25f;
69
70 constexpr OutputColorSetting kVendorSpecifiedOutputColorSetting =
71 static_cast<OutputColorSetting>(0x100);
72
73 struct OutputPartialMockBase : public impl::Output {
74 // compositionengine::Output overrides
getStateandroid::compositionengine::__anon470a6e800110::OutputPartialMockBase75 const OutputCompositionState& getState() const override { return mState; }
editStateandroid::compositionengine::__anon470a6e800110::OutputPartialMockBase76 OutputCompositionState& editState() override { return mState; }
77
78 // Use mocks for all the remaining virtual functions
79 // not implemented by the base implementation class.
80 MOCK_CONST_METHOD0(getOutputLayerCount, size_t());
81 MOCK_CONST_METHOD1(getOutputLayerOrderedByZByIndex, compositionengine::OutputLayer*(size_t));
82 MOCK_METHOD2(ensureOutputLayer,
83 compositionengine::OutputLayer*(std::optional<size_t>, const sp<LayerFE>&));
84 MOCK_METHOD0(finalizePendingOutputLayers, void());
85 MOCK_METHOD0(clearOutputLayers, void());
86 MOCK_CONST_METHOD1(dumpState, void(std::string&));
87 MOCK_CONST_METHOD0(getCompositionEngine, const CompositionEngine&());
88 MOCK_METHOD1(injectOutputLayerForTest, compositionengine::OutputLayer*(const sp<LayerFE>&));
89 MOCK_METHOD1(injectOutputLayerForTest, void(std::unique_ptr<OutputLayer>));
90
91 impl::OutputCompositionState mState;
92 };
93
94 struct InjectedLayer {
InjectedLayerandroid::compositionengine::__anon470a6e800110::InjectedLayer95 InjectedLayer() {
96 EXPECT_CALL(*outputLayer, getLayerFE()).WillRepeatedly(ReturnRef(*layerFE.get()));
97 EXPECT_CALL(*outputLayer, getState()).WillRepeatedly(ReturnRef(outputLayerState));
98 EXPECT_CALL(*outputLayer, editState()).WillRepeatedly(ReturnRef(outputLayerState));
99
100 EXPECT_CALL(*layerFE, getCompositionState()).WillRepeatedly(Return(&layerFEState));
101 EXPECT_CALL(*layerFE, getSequence()).WillRepeatedly(Return(0));
102 EXPECT_CALL(*layerFE, getDebugName()).WillRepeatedly(Return("InjectedLayer"));
103 }
104
105 mock::OutputLayer* outputLayer = {new StrictMock<mock::OutputLayer>};
106 sp<StrictMock<mock::LayerFE>> layerFE = new StrictMock<mock::LayerFE>();
107 LayerFECompositionState layerFEState;
108 impl::OutputLayerCompositionState outputLayerState;
109 };
110
111 struct NonInjectedLayer {
NonInjectedLayerandroid::compositionengine::__anon470a6e800110::NonInjectedLayer112 NonInjectedLayer() {
113 EXPECT_CALL(outputLayer, getLayerFE()).WillRepeatedly(ReturnRef(*layerFE.get()));
114 EXPECT_CALL(outputLayer, getState()).WillRepeatedly(ReturnRef(outputLayerState));
115 EXPECT_CALL(outputLayer, editState()).WillRepeatedly(ReturnRef(outputLayerState));
116
117 EXPECT_CALL(*layerFE, getCompositionState()).WillRepeatedly(Return(&layerFEState));
118 EXPECT_CALL(*layerFE, getSequence()).WillRepeatedly(Return(0));
119 EXPECT_CALL(*layerFE, getDebugName()).WillRepeatedly(Return("NonInjectedLayer"));
120 }
121
122 mock::OutputLayer outputLayer;
123 sp<StrictMock<mock::LayerFE>> layerFE = new StrictMock<mock::LayerFE>();
124 LayerFECompositionState layerFEState;
125 impl::OutputLayerCompositionState outputLayerState;
126 };
127
128 struct OutputTest : public testing::Test {
129 class Output : public impl::Output {
130 public:
131 using impl::Output::injectOutputLayerForTest;
132 virtual void injectOutputLayerForTest(std::unique_ptr<compositionengine::OutputLayer>) = 0;
133 };
134
createOutputandroid::compositionengine::__anon470a6e800110::OutputTest135 static std::shared_ptr<Output> createOutput(
136 const compositionengine::CompositionEngine& compositionEngine) {
137 return impl::createOutputTemplated<Output>(compositionEngine);
138 }
139
OutputTestandroid::compositionengine::__anon470a6e800110::OutputTest140 OutputTest() {
141 mOutput->setDisplayColorProfileForTest(
142 std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile));
143 mOutput->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
144
145 mOutput->editState().displaySpace.bounds = kDefaultDisplaySize;
146 EXPECT_CALL(mCompositionEngine, getRenderEngine()).WillRepeatedly(ReturnRef(mRenderEngine));
147 }
148
injectOutputLayerandroid::compositionengine::__anon470a6e800110::OutputTest149 void injectOutputLayer(InjectedLayer& layer) {
150 mOutput->injectOutputLayerForTest(std::unique_ptr<OutputLayer>(layer.outputLayer));
151 }
152
injectNullOutputLayerandroid::compositionengine::__anon470a6e800110::OutputTest153 void injectNullOutputLayer() {
154 mOutput->injectOutputLayerForTest(std::unique_ptr<OutputLayer>(nullptr));
155 }
156
157 static const Rect kDefaultDisplaySize;
158
159 StrictMock<mock::CompositionEngine> mCompositionEngine;
160 StrictMock<renderengine::mock::RenderEngine> mRenderEngine;
161 mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>();
162 mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>();
163 std::shared_ptr<Output> mOutput = createOutput(mCompositionEngine);
164 };
165
166 const Rect OutputTest::kDefaultDisplaySize{100, 200};
167
168 using ColorProfile = compositionengine::Output::ColorProfile;
169
dumpColorProfile(ColorProfile profile,std::string & result,const char * name)170 void dumpColorProfile(ColorProfile profile, std::string& result, const char* name) {
171 android::base::StringAppendF(&result, "%s (%s[%d] %s[%d] %s[%d] %s[%d]) ", name,
172 toString(profile.mode).c_str(), profile.mode,
173 toString(profile.dataspace).c_str(), profile.dataspace,
174 toString(profile.renderIntent).c_str(), profile.renderIntent,
175 toString(profile.colorSpaceAgnosticDataspace).c_str(),
176 profile.colorSpaceAgnosticDataspace);
177 }
178
179 // Checks for a ColorProfile match
180 MATCHER_P(ColorProfileEq, expected, "") {
181 std::string buf;
182 buf.append("ColorProfiles are not equal\n");
183 dumpColorProfile(expected, buf, "expected value");
184 dumpColorProfile(arg, buf, "actual value");
185 *result_listener << buf;
186
187 return (expected.mode == arg.mode) && (expected.dataspace == arg.dataspace) &&
188 (expected.renderIntent == arg.renderIntent) &&
189 (expected.colorSpaceAgnosticDataspace == arg.colorSpaceAgnosticDataspace);
190 }
191
192 /*
193 * Basic construction
194 */
195
TEST_F(OutputTest,canInstantiateOutput)196 TEST_F(OutputTest, canInstantiateOutput) {
197 // The validation check checks each required component.
198 EXPECT_CALL(*mDisplayColorProfile, isValid()).WillOnce(Return(true));
199 EXPECT_CALL(*mRenderSurface, isValid()).WillOnce(Return(true));
200
201 EXPECT_TRUE(mOutput->isValid());
202
203 // If we take away the required components, it is no longer valid.
204 mOutput->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>());
205
206 EXPECT_CALL(*mDisplayColorProfile, isValid()).WillOnce(Return(true));
207
208 EXPECT_FALSE(mOutput->isValid());
209 }
210
211 /*
212 * Output::setCompositionEnabled()
213 */
214
TEST_F(OutputTest,setCompositionEnabledDoesNothingIfAlreadyEnabled)215 TEST_F(OutputTest, setCompositionEnabledDoesNothingIfAlreadyEnabled) {
216 mOutput->editState().isEnabled = true;
217
218 mOutput->setCompositionEnabled(true);
219
220 EXPECT_TRUE(mOutput->getState().isEnabled);
221 EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region()));
222 }
223
TEST_F(OutputTest,setCompositionEnabledSetsEnabledAndDirtiesEntireOutput)224 TEST_F(OutputTest, setCompositionEnabledSetsEnabledAndDirtiesEntireOutput) {
225 mOutput->editState().isEnabled = false;
226
227 mOutput->setCompositionEnabled(true);
228
229 EXPECT_TRUE(mOutput->getState().isEnabled);
230 EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize)));
231 }
232
TEST_F(OutputTest,setCompositionEnabledSetsDisabledAndDirtiesEntireOutput)233 TEST_F(OutputTest, setCompositionEnabledSetsDisabledAndDirtiesEntireOutput) {
234 mOutput->editState().isEnabled = true;
235
236 mOutput->setCompositionEnabled(false);
237
238 EXPECT_FALSE(mOutput->getState().isEnabled);
239 EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize)));
240 }
241
242 /*
243 * Output::setLayerCachingEnabled()
244 */
245
TEST_F(OutputTest,setLayerCachingEnabled_enablesCaching)246 TEST_F(OutputTest, setLayerCachingEnabled_enablesCaching) {
247 const auto kSize = ui::Size(1, 1);
248 EXPECT_CALL(*mRenderSurface, getSize()).WillRepeatedly(ReturnRef(kSize));
249 mOutput->setLayerCachingEnabled(false);
250 mOutput->setLayerCachingEnabled(true);
251
252 EXPECT_TRUE(mOutput->plannerEnabled());
253 }
254
TEST_F(OutputTest,setLayerCachingEnabled_disablesCaching)255 TEST_F(OutputTest, setLayerCachingEnabled_disablesCaching) {
256 const auto kSize = ui::Size(1, 1);
257 EXPECT_CALL(*mRenderSurface, getSize()).WillRepeatedly(ReturnRef(kSize));
258 mOutput->setLayerCachingEnabled(true);
259 mOutput->setLayerCachingEnabled(false);
260
261 EXPECT_FALSE(mOutput->plannerEnabled());
262 }
263
TEST_F(OutputTest,setLayerCachingEnabled_disablesCachingAndResetsOverrideInfo)264 TEST_F(OutputTest, setLayerCachingEnabled_disablesCachingAndResetsOverrideInfo) {
265 renderengine::mock::RenderEngine renderEngine;
266 const auto kSize = ui::Size(1, 1);
267 EXPECT_CALL(*mRenderSurface, getSize()).WillRepeatedly(ReturnRef(kSize));
268 mOutput->setLayerCachingEnabled(true);
269
270 // Inject some layers
271 InjectedLayer layer;
272 layer.outputLayerState.overrideInfo.buffer = std::make_shared<
273 renderengine::ExternalTexture>(new GraphicBuffer(), renderEngine,
274 renderengine::ExternalTexture::Usage::READABLE |
275 renderengine::ExternalTexture::Usage::WRITEABLE);
276 injectOutputLayer(layer);
277 // inject a null layer to check for null exceptions
278 injectNullOutputLayer();
279
280 EXPECT_NE(nullptr, layer.outputLayerState.overrideInfo.buffer);
281 mOutput->setLayerCachingEnabled(false);
282 EXPECT_EQ(nullptr, layer.outputLayerState.overrideInfo.buffer);
283 }
284
285 /*
286 * Output::setProjection()
287 */
288
TEST_F(OutputTest,setProjectionWorks)289 TEST_F(OutputTest, setProjectionWorks) {
290 const Rect displayRect{0, 0, 1000, 2000};
291 mOutput->editState().displaySpace.bounds = displayRect;
292 mOutput->editState().framebufferSpace.bounds = displayRect;
293
294 const ui::Rotation orientation = ui::ROTATION_90;
295 const Rect frame{50, 60, 100, 100};
296 const Rect viewport{10, 20, 30, 40};
297
298 mOutput->setProjection(orientation, viewport, frame);
299
300 EXPECT_EQ(orientation, mOutput->getState().displaySpace.orientation);
301 EXPECT_EQ(frame, mOutput->getState().orientedDisplaySpace.content);
302 EXPECT_EQ(viewport, mOutput->getState().layerStackSpace.content);
303
304 const auto state = mOutput->getState();
305 EXPECT_EQ(ui::ROTATION_0, state.layerStackSpace.orientation);
306 EXPECT_EQ(viewport, state.layerStackSpace.content);
307 EXPECT_EQ(viewport, state.layerStackSpace.bounds);
308
309 EXPECT_EQ(ui::ROTATION_0, state.orientedDisplaySpace.orientation);
310 EXPECT_EQ(frame, state.orientedDisplaySpace.content);
311 EXPECT_EQ(Rect(0, 0, 2000, 1000), state.orientedDisplaySpace.bounds);
312
313 EXPECT_EQ(displayRect, state.displaySpace.bounds);
314 EXPECT_EQ(Rect(900, 50, 940, 100), state.displaySpace.content);
315 EXPECT_EQ(orientation, state.displaySpace.orientation);
316
317 EXPECT_EQ(displayRect, state.framebufferSpace.bounds);
318 EXPECT_EQ(Rect(900, 50, 940, 100), state.framebufferSpace.content);
319 EXPECT_EQ(orientation, state.framebufferSpace.orientation);
320
321 EXPECT_EQ(state.displaySpace.content, state.transform.transform(state.layerStackSpace.content));
322
323 EXPECT_EQ(ui::Transform::ROT_90, mOutput->getTransformHint());
324 }
325
TEST_F(OutputTest,setProjectionWithSmallFramebufferWorks)326 TEST_F(OutputTest, setProjectionWithSmallFramebufferWorks) {
327 const Rect displayRect{0, 0, 1000, 2000};
328 const Rect framebufferRect{0, 0, 500, 1000};
329 mOutput->editState().displaySpace.bounds = displayRect;
330 mOutput->editState().framebufferSpace.bounds = framebufferRect;
331
332 const ui::Rotation orientation = ui::ROTATION_90;
333 const Rect frame{50, 60, 100, 100};
334 const Rect viewport{10, 20, 30, 40};
335
336 mOutput->setProjection(orientation, viewport, frame);
337
338 EXPECT_EQ(orientation, mOutput->getState().displaySpace.orientation);
339 EXPECT_EQ(frame, mOutput->getState().orientedDisplaySpace.content);
340 EXPECT_EQ(viewport, mOutput->getState().layerStackSpace.content);
341
342 const auto state = mOutput->getState();
343 EXPECT_EQ(ui::ROTATION_0, state.layerStackSpace.orientation);
344 EXPECT_EQ(viewport, state.layerStackSpace.content);
345 EXPECT_EQ(viewport, state.layerStackSpace.bounds);
346
347 EXPECT_EQ(ui::ROTATION_0, state.orientedDisplaySpace.orientation);
348 EXPECT_EQ(frame, state.orientedDisplaySpace.content);
349 EXPECT_EQ(Rect(0, 0, 2000, 1000), state.orientedDisplaySpace.bounds);
350
351 EXPECT_EQ(displayRect, state.displaySpace.bounds);
352 EXPECT_EQ(Rect(900, 50, 940, 100), state.displaySpace.content);
353 EXPECT_EQ(orientation, state.displaySpace.orientation);
354
355 EXPECT_EQ(framebufferRect, state.framebufferSpace.bounds);
356 EXPECT_EQ(Rect(450, 25, 470, 50), state.framebufferSpace.content);
357 EXPECT_EQ(orientation, state.framebufferSpace.orientation);
358
359 EXPECT_EQ(state.displaySpace.content, state.transform.transform(state.layerStackSpace.content));
360 }
361
362 /*
363 * Output::setDisplaySize()
364 */
365
TEST_F(OutputTest,setDisplaySpaceSizeUpdatesOutputStateAndDirtiesEntireOutput)366 TEST_F(OutputTest, setDisplaySpaceSizeUpdatesOutputStateAndDirtiesEntireOutput) {
367 mOutput->editState().layerStackSpace.content = Rect(0, 0, 2000, 1000);
368 mOutput->editState().layerStackSpace.bounds = Rect(0, 0, 2000, 1000);
369 mOutput->editState().orientedDisplaySpace.content = Rect(0, 0, 1800, 900);
370 mOutput->editState().orientedDisplaySpace.bounds = Rect(0, 0, 2000, 1000);
371 mOutput->editState().framebufferSpace.content = Rect(0, 0, 900, 1800);
372 mOutput->editState().framebufferSpace.bounds = Rect(0, 0, 1000, 2000);
373 mOutput->editState().framebufferSpace.orientation = ui::ROTATION_90;
374 mOutput->editState().displaySpace.content = Rect(0, 0, 900, 1800);
375 mOutput->editState().displaySpace.bounds = Rect(0, 0, 1000, 2000);
376 mOutput->editState().displaySpace.orientation = ui::ROTATION_90;
377
378 const ui::Size newDisplaySize{500, 1000};
379
380 EXPECT_CALL(*mRenderSurface, setDisplaySize(newDisplaySize)).Times(1);
381
382 mOutput->setDisplaySize(newDisplaySize);
383
384 const auto state = mOutput->getState();
385
386 const Rect displayRect(newDisplaySize);
387 EXPECT_EQ(ui::ROTATION_0, state.layerStackSpace.orientation);
388 EXPECT_EQ(Rect(0, 0, 2000, 1000), state.layerStackSpace.content);
389 EXPECT_EQ(Rect(0, 0, 2000, 1000), state.layerStackSpace.bounds);
390
391 EXPECT_EQ(ui::ROTATION_0, state.orientedDisplaySpace.orientation);
392 EXPECT_EQ(Rect(0, 0, 1000, 500), state.orientedDisplaySpace.bounds);
393
394 EXPECT_EQ(displayRect, state.displaySpace.bounds);
395 EXPECT_EQ(ui::ROTATION_90, state.displaySpace.orientation);
396
397 EXPECT_EQ(displayRect, state.framebufferSpace.bounds);
398 EXPECT_EQ(ui::ROTATION_90, state.framebufferSpace.orientation);
399
400 EXPECT_EQ(state.displaySpace.content, state.transform.transform(state.layerStackSpace.content));
401
402 EXPECT_THAT(state.dirtyRegion, RegionEq(Region(displayRect)));
403 }
404
405 /*
406 * Output::setLayerStackFilter()
407 */
408
TEST_F(OutputTest,setLayerStackFilterSetsFilterAndDirtiesEntireOutput)409 TEST_F(OutputTest, setLayerStackFilterSetsFilterAndDirtiesEntireOutput) {
410 const uint32_t layerStack = 123u;
411 mOutput->setLayerStackFilter(layerStack, true);
412
413 EXPECT_TRUE(mOutput->getState().layerStackInternal);
414 EXPECT_EQ(layerStack, mOutput->getState().layerStackId);
415
416 EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize)));
417 }
418
419 /*
420 * Output::setColorTransform
421 */
422
TEST_F(OutputTest,setColorTransformWithNoChangeFlaggedSkipsUpdates)423 TEST_F(OutputTest, setColorTransformWithNoChangeFlaggedSkipsUpdates) {
424 mOutput->editState().colorTransformMatrix = kIdentity;
425
426 // If no colorTransformMatrix is set the update should be skipped.
427 CompositionRefreshArgs refreshArgs;
428 refreshArgs.colorTransformMatrix = std::nullopt;
429
430 mOutput->setColorTransform(refreshArgs);
431
432 // The internal state should be unchanged
433 EXPECT_EQ(kIdentity, mOutput->getState().colorTransformMatrix);
434
435 // No dirty region should be set
436 EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region()));
437 }
438
TEST_F(OutputTest,setColorTransformWithNoActualChangeSkipsUpdates)439 TEST_F(OutputTest, setColorTransformWithNoActualChangeSkipsUpdates) {
440 mOutput->editState().colorTransformMatrix = kIdentity;
441
442 // Attempting to set the same colorTransformMatrix that is already set should
443 // also skip the update.
444 CompositionRefreshArgs refreshArgs;
445 refreshArgs.colorTransformMatrix = kIdentity;
446
447 mOutput->setColorTransform(refreshArgs);
448
449 // The internal state should be unchanged
450 EXPECT_EQ(kIdentity, mOutput->getState().colorTransformMatrix);
451
452 // No dirty region should be set
453 EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region()));
454 }
455
TEST_F(OutputTest,setColorTransformPerformsUpdateToIdentity)456 TEST_F(OutputTest, setColorTransformPerformsUpdateToIdentity) {
457 mOutput->editState().colorTransformMatrix = kNonIdentityHalf;
458
459 // Setting a different colorTransformMatrix should perform the update.
460 CompositionRefreshArgs refreshArgs;
461 refreshArgs.colorTransformMatrix = kIdentity;
462
463 mOutput->setColorTransform(refreshArgs);
464
465 // The internal state should have been updated
466 EXPECT_EQ(kIdentity, mOutput->getState().colorTransformMatrix);
467
468 // The dirtyRegion should be set to the full display size
469 EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize)));
470 }
471
TEST_F(OutputTest,setColorTransformPerformsUpdateForIdentityToHalf)472 TEST_F(OutputTest, setColorTransformPerformsUpdateForIdentityToHalf) {
473 mOutput->editState().colorTransformMatrix = kIdentity;
474
475 // Setting a different colorTransformMatrix should perform the update.
476 CompositionRefreshArgs refreshArgs;
477 refreshArgs.colorTransformMatrix = kNonIdentityHalf;
478
479 mOutput->setColorTransform(refreshArgs);
480
481 // The internal state should have been updated
482 EXPECT_EQ(kNonIdentityHalf, mOutput->getState().colorTransformMatrix);
483
484 // The dirtyRegion should be set to the full display size
485 EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize)));
486 }
487
TEST_F(OutputTest,setColorTransformPerformsUpdateForHalfToQuarter)488 TEST_F(OutputTest, setColorTransformPerformsUpdateForHalfToQuarter) {
489 mOutput->editState().colorTransformMatrix = kNonIdentityHalf;
490
491 // Setting a different colorTransformMatrix should perform the update.
492 CompositionRefreshArgs refreshArgs;
493 refreshArgs.colorTransformMatrix = kNonIdentityQuarter;
494
495 mOutput->setColorTransform(refreshArgs);
496
497 // The internal state should have been updated
498 EXPECT_EQ(kNonIdentityQuarter, mOutput->getState().colorTransformMatrix);
499
500 // The dirtyRegion should be set to the full display size
501 EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize)));
502 }
503
504 /*
505 * Output::setColorProfile
506 */
507
508 using OutputSetColorProfileTest = OutputTest;
509
TEST_F(OutputSetColorProfileTest,setsStateAndDirtiesOutputIfChanged)510 TEST_F(OutputSetColorProfileTest, setsStateAndDirtiesOutputIfChanged) {
511 using ColorProfile = Output::ColorProfile;
512
513 EXPECT_CALL(*mDisplayColorProfile,
514 getTargetDataspace(ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
515 ui::Dataspace::UNKNOWN))
516 .WillOnce(Return(ui::Dataspace::UNKNOWN));
517 EXPECT_CALL(*mRenderSurface, setBufferDataspace(ui::Dataspace::DISPLAY_P3)).Times(1);
518
519 mOutput->setColorProfile(ColorProfile{ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
520 ui::RenderIntent::TONE_MAP_COLORIMETRIC,
521 ui::Dataspace::UNKNOWN});
522
523 EXPECT_EQ(ui::ColorMode::DISPLAY_P3, mOutput->getState().colorMode);
524 EXPECT_EQ(ui::Dataspace::DISPLAY_P3, mOutput->getState().dataspace);
525 EXPECT_EQ(ui::RenderIntent::TONE_MAP_COLORIMETRIC, mOutput->getState().renderIntent);
526 EXPECT_EQ(ui::Dataspace::UNKNOWN, mOutput->getState().targetDataspace);
527
528 EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize)));
529 }
530
TEST_F(OutputSetColorProfileTest,doesNothingIfNoChange)531 TEST_F(OutputSetColorProfileTest, doesNothingIfNoChange) {
532 using ColorProfile = Output::ColorProfile;
533
534 EXPECT_CALL(*mDisplayColorProfile,
535 getTargetDataspace(ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
536 ui::Dataspace::UNKNOWN))
537 .WillOnce(Return(ui::Dataspace::UNKNOWN));
538
539 mOutput->editState().colorMode = ui::ColorMode::DISPLAY_P3;
540 mOutput->editState().dataspace = ui::Dataspace::DISPLAY_P3;
541 mOutput->editState().renderIntent = ui::RenderIntent::TONE_MAP_COLORIMETRIC;
542 mOutput->editState().targetDataspace = ui::Dataspace::UNKNOWN;
543
544 mOutput->setColorProfile(ColorProfile{ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
545 ui::RenderIntent::TONE_MAP_COLORIMETRIC,
546 ui::Dataspace::UNKNOWN});
547
548 EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region()));
549 }
550
551 /*
552 * Output::setRenderSurface()
553 */
554
TEST_F(OutputTest,setRenderSurfaceResetsBounds)555 TEST_F(OutputTest, setRenderSurfaceResetsBounds) {
556 const ui::Size newDisplaySize{640, 480};
557
558 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
559 EXPECT_CALL(*renderSurface, getSize()).WillOnce(ReturnRef(newDisplaySize));
560
561 mOutput->setRenderSurface(std::unique_ptr<RenderSurface>(renderSurface));
562
563 EXPECT_EQ(Rect(newDisplaySize), mOutput->getState().framebufferSpace.bounds);
564 }
565
566 /*
567 * Output::getDirtyRegion()
568 */
569
TEST_F(OutputTest,getDirtyRegionWithRepaintEverythingTrue)570 TEST_F(OutputTest, getDirtyRegionWithRepaintEverythingTrue) {
571 const Rect viewport{100, 200};
572 mOutput->editState().layerStackSpace.content = viewport;
573 mOutput->editState().dirtyRegion.set(50, 300);
574
575 {
576 Region result = mOutput->getDirtyRegion(true);
577
578 EXPECT_THAT(result, RegionEq(Region(viewport)));
579 }
580 }
581
TEST_F(OutputTest,getDirtyRegionWithRepaintEverythingFalse)582 TEST_F(OutputTest, getDirtyRegionWithRepaintEverythingFalse) {
583 const Rect viewport{100, 200};
584 mOutput->editState().layerStackSpace.content = viewport;
585 mOutput->editState().dirtyRegion.set(50, 300);
586
587 {
588 Region result = mOutput->getDirtyRegion(false);
589
590 // The dirtyRegion should be clipped to the display bounds.
591 EXPECT_THAT(result, RegionEq(Region(Rect(50, 200))));
592 }
593 }
594
595 /*
596 * Output::belongsInOutput()
597 */
598
TEST_F(OutputTest,belongsInOutputFiltersAsExpected)599 TEST_F(OutputTest, belongsInOutputFiltersAsExpected) {
600 const uint32_t layerStack1 = 123u;
601 const uint32_t layerStack2 = 456u;
602
603 // If the output accepts layerStack1 and internal-only layers....
604 mOutput->setLayerStackFilter(layerStack1, true);
605
606 // A layer with no layerStack does not belong to it, internal-only or not.
607 EXPECT_FALSE(mOutput->belongsInOutput(std::nullopt, false));
608 EXPECT_FALSE(mOutput->belongsInOutput(std::nullopt, true));
609
610 // Any layer with layerStack1 belongs to it, internal-only or not.
611 EXPECT_TRUE(mOutput->belongsInOutput(layerStack1, false));
612 EXPECT_TRUE(mOutput->belongsInOutput(layerStack1, true));
613 EXPECT_FALSE(mOutput->belongsInOutput(layerStack2, true));
614 EXPECT_FALSE(mOutput->belongsInOutput(layerStack2, false));
615
616 // If the output accepts layerStack21 but not internal-only layers...
617 mOutput->setLayerStackFilter(layerStack1, false);
618
619 // Only non-internal layers with layerStack1 belong to it.
620 EXPECT_TRUE(mOutput->belongsInOutput(layerStack1, false));
621 EXPECT_FALSE(mOutput->belongsInOutput(layerStack1, true));
622 EXPECT_FALSE(mOutput->belongsInOutput(layerStack2, true));
623 EXPECT_FALSE(mOutput->belongsInOutput(layerStack2, false));
624 }
625
TEST_F(OutputTest,belongsInOutputHandlesLayerWithNoCompositionState)626 TEST_F(OutputTest, belongsInOutputHandlesLayerWithNoCompositionState) {
627 NonInjectedLayer layer;
628 sp<LayerFE> layerFE(layer.layerFE);
629
630 // If the layer has no composition state, it does not belong to any output.
631 EXPECT_CALL(*layer.layerFE, getCompositionState).WillOnce(Return(nullptr));
632 EXPECT_FALSE(mOutput->belongsInOutput(layerFE));
633 }
634
TEST_F(OutputTest,belongsInOutputFiltersLayersAsExpected)635 TEST_F(OutputTest, belongsInOutputFiltersLayersAsExpected) {
636 NonInjectedLayer layer;
637 sp<LayerFE> layerFE(layer.layerFE);
638
639 const uint32_t layerStack1 = 123u;
640 const uint32_t layerStack2 = 456u;
641
642 // If the output accepts layerStack1 and internal-only layers....
643 mOutput->setLayerStackFilter(layerStack1, true);
644
645 // A layer with no layerStack does not belong to it, internal-only or not.
646 layer.layerFEState.layerStackId = std::nullopt;
647 layer.layerFEState.internalOnly = false;
648 EXPECT_FALSE(mOutput->belongsInOutput(layerFE));
649
650 layer.layerFEState.layerStackId = std::nullopt;
651 layer.layerFEState.internalOnly = true;
652 EXPECT_FALSE(mOutput->belongsInOutput(layerFE));
653
654 // Any layer with layerStack1 belongs to it, internal-only or not.
655 layer.layerFEState.layerStackId = layerStack1;
656 layer.layerFEState.internalOnly = false;
657 EXPECT_TRUE(mOutput->belongsInOutput(layerFE));
658
659 layer.layerFEState.layerStackId = layerStack1;
660 layer.layerFEState.internalOnly = true;
661 EXPECT_TRUE(mOutput->belongsInOutput(layerFE));
662
663 layer.layerFEState.layerStackId = layerStack2;
664 layer.layerFEState.internalOnly = true;
665 EXPECT_FALSE(mOutput->belongsInOutput(layerFE));
666
667 layer.layerFEState.layerStackId = layerStack2;
668 layer.layerFEState.internalOnly = false;
669 EXPECT_FALSE(mOutput->belongsInOutput(layerFE));
670
671 // If the output accepts layerStack1 but not internal-only layers...
672 mOutput->setLayerStackFilter(layerStack1, false);
673
674 // Only non-internal layers with layerStack1 belong to it.
675 layer.layerFEState.layerStackId = layerStack1;
676 layer.layerFEState.internalOnly = false;
677 EXPECT_TRUE(mOutput->belongsInOutput(layerFE));
678
679 layer.layerFEState.layerStackId = layerStack1;
680 layer.layerFEState.internalOnly = true;
681 EXPECT_FALSE(mOutput->belongsInOutput(layerFE));
682
683 layer.layerFEState.layerStackId = layerStack2;
684 layer.layerFEState.internalOnly = true;
685 EXPECT_FALSE(mOutput->belongsInOutput(layerFE));
686
687 layer.layerFEState.layerStackId = layerStack2;
688 layer.layerFEState.internalOnly = false;
689 EXPECT_FALSE(mOutput->belongsInOutput(layerFE));
690 }
691
692 /*
693 * Output::getOutputLayerForLayer()
694 */
695
TEST_F(OutputTest,getOutputLayerForLayerWorks)696 TEST_F(OutputTest, getOutputLayerForLayerWorks) {
697 InjectedLayer layer1;
698 InjectedLayer layer2;
699 NonInjectedLayer layer3;
700
701 injectOutputLayer(layer1);
702 injectNullOutputLayer();
703 injectOutputLayer(layer2);
704
705 // If the input layer matches the first OutputLayer, it will be returned.
706 EXPECT_CALL(*layer1.outputLayer, getLayerFE()).WillOnce(ReturnRef(*layer1.layerFE.get()));
707 EXPECT_EQ(layer1.outputLayer, mOutput->getOutputLayerForLayer(layer1.layerFE));
708
709 // If the input layer matches the second OutputLayer, it will be returned.
710 EXPECT_CALL(*layer1.outputLayer, getLayerFE()).WillOnce(ReturnRef(*layer1.layerFE.get()));
711 EXPECT_CALL(*layer2.outputLayer, getLayerFE()).WillOnce(ReturnRef(*layer2.layerFE.get()));
712 EXPECT_EQ(layer2.outputLayer, mOutput->getOutputLayerForLayer(layer2.layerFE));
713
714 // If the input layer does not match an output layer, null will be returned.
715 EXPECT_CALL(*layer1.outputLayer, getLayerFE()).WillOnce(ReturnRef(*layer1.layerFE.get()));
716 EXPECT_CALL(*layer2.outputLayer, getLayerFE()).WillOnce(ReturnRef(*layer2.layerFE.get()));
717 EXPECT_EQ(nullptr, mOutput->getOutputLayerForLayer(layer3.layerFE));
718 }
719
720 /*
721 * Output::setReleasedLayers()
722 */
723
724 using OutputSetReleasedLayersTest = OutputTest;
725
TEST_F(OutputSetReleasedLayersTest,setReleasedLayersTakesGivenLayers)726 TEST_F(OutputSetReleasedLayersTest, setReleasedLayersTakesGivenLayers) {
727 sp<StrictMock<mock::LayerFE>> layer1FE{new StrictMock<mock::LayerFE>()};
728 sp<StrictMock<mock::LayerFE>> layer2FE{new StrictMock<mock::LayerFE>()};
729 sp<StrictMock<mock::LayerFE>> layer3FE{new StrictMock<mock::LayerFE>()};
730
731 Output::ReleasedLayers layers;
732 layers.push_back(layer1FE);
733 layers.push_back(layer2FE);
734 layers.push_back(layer3FE);
735
736 mOutput->setReleasedLayers(std::move(layers));
737
738 const auto& setLayers = mOutput->getReleasedLayersForTest();
739 ASSERT_EQ(3u, setLayers.size());
740 ASSERT_EQ(layer1FE.get(), setLayers[0].promote().get());
741 ASSERT_EQ(layer2FE.get(), setLayers[1].promote().get());
742 ASSERT_EQ(layer3FE.get(), setLayers[2].promote().get());
743 }
744
745 /*
746 * Output::updateLayerStateFromFE()
747 */
748
749 using OutputUpdateLayerStateFromFETest = OutputTest;
750
TEST_F(OutputUpdateLayerStateFromFETest,handlesNoOutputLayerCase)751 TEST_F(OutputUpdateLayerStateFromFETest, handlesNoOutputLayerCase) {
752 CompositionRefreshArgs refreshArgs;
753
754 mOutput->updateLayerStateFromFE(refreshArgs);
755 }
756
TEST_F(OutputUpdateLayerStateFromFETest,preparesContentStateForAllContainedLayers)757 TEST_F(OutputUpdateLayerStateFromFETest, preparesContentStateForAllContainedLayers) {
758 InjectedLayer layer1;
759 InjectedLayer layer2;
760 InjectedLayer layer3;
761
762 EXPECT_CALL(*layer1.layerFE.get(), prepareCompositionState(LayerFE::StateSubset::Content));
763 EXPECT_CALL(*layer2.layerFE.get(), prepareCompositionState(LayerFE::StateSubset::Content));
764 EXPECT_CALL(*layer3.layerFE.get(), prepareCompositionState(LayerFE::StateSubset::Content));
765
766 injectOutputLayer(layer1);
767 injectOutputLayer(layer2);
768 injectOutputLayer(layer3);
769
770 CompositionRefreshArgs refreshArgs;
771 refreshArgs.updatingGeometryThisFrame = false;
772
773 mOutput->updateLayerStateFromFE(refreshArgs);
774 }
775
TEST_F(OutputUpdateLayerStateFromFETest,preparesGeometryAndContentStateForAllContainedLayers)776 TEST_F(OutputUpdateLayerStateFromFETest, preparesGeometryAndContentStateForAllContainedLayers) {
777 InjectedLayer layer1;
778 InjectedLayer layer2;
779 InjectedLayer layer3;
780
781 EXPECT_CALL(*layer1.layerFE, prepareCompositionState(LayerFE::StateSubset::GeometryAndContent));
782 EXPECT_CALL(*layer2.layerFE, prepareCompositionState(LayerFE::StateSubset::GeometryAndContent));
783 EXPECT_CALL(*layer3.layerFE, prepareCompositionState(LayerFE::StateSubset::GeometryAndContent));
784
785 injectOutputLayer(layer1);
786 injectOutputLayer(layer2);
787 injectOutputLayer(layer3);
788
789 CompositionRefreshArgs refreshArgs;
790 refreshArgs.updatingGeometryThisFrame = true;
791
792 mOutput->updateLayerStateFromFE(refreshArgs);
793 }
794
795 /*
796 * Output::updateAndWriteCompositionState()
797 */
798
799 using OutputUpdateAndWriteCompositionStateTest = OutputTest;
800
TEST_F(OutputUpdateAndWriteCompositionStateTest,doesNothingIfLayers)801 TEST_F(OutputUpdateAndWriteCompositionStateTest, doesNothingIfLayers) {
802 mOutput->editState().isEnabled = true;
803
804 CompositionRefreshArgs args;
805 mOutput->updateCompositionState(args);
806 mOutput->planComposition();
807 mOutput->writeCompositionState(args);
808 }
809
TEST_F(OutputUpdateAndWriteCompositionStateTest,doesNothingIfOutputNotEnabled)810 TEST_F(OutputUpdateAndWriteCompositionStateTest, doesNothingIfOutputNotEnabled) {
811 InjectedLayer layer1;
812 InjectedLayer layer2;
813 InjectedLayer layer3;
814
815 mOutput->editState().isEnabled = false;
816
817 injectOutputLayer(layer1);
818 injectOutputLayer(layer2);
819 injectOutputLayer(layer3);
820
821 CompositionRefreshArgs args;
822 mOutput->updateCompositionState(args);
823 mOutput->planComposition();
824 mOutput->writeCompositionState(args);
825 }
826
TEST_F(OutputUpdateAndWriteCompositionStateTest,updatesLayerContentForAllLayers)827 TEST_F(OutputUpdateAndWriteCompositionStateTest, updatesLayerContentForAllLayers) {
828 InjectedLayer layer1;
829 InjectedLayer layer2;
830 InjectedLayer layer3;
831
832 uint32_t z = 0;
833 EXPECT_CALL(*layer1.outputLayer, updateCompositionState(false, false, ui::Transform::ROT_180));
834 EXPECT_CALL(*layer1.outputLayer,
835 writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, z++,
836 /*zIsOverridden*/ false, /*isPeekingThrough*/ false));
837 EXPECT_CALL(*layer2.outputLayer, updateCompositionState(false, false, ui::Transform::ROT_180));
838 EXPECT_CALL(*layer2.outputLayer,
839 writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, z++,
840 /*zIsOverridden*/ false, /*isPeekingThrough*/ false));
841 EXPECT_CALL(*layer3.outputLayer, updateCompositionState(false, false, ui::Transform::ROT_180));
842 EXPECT_CALL(*layer3.outputLayer,
843 writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, z++,
844 /*zIsOverridden*/ false, /*isPeekingThrough*/ false));
845
846 injectOutputLayer(layer1);
847 injectOutputLayer(layer2);
848 injectOutputLayer(layer3);
849
850 mOutput->editState().isEnabled = true;
851
852 CompositionRefreshArgs args;
853 args.updatingGeometryThisFrame = false;
854 args.devOptForceClientComposition = false;
855 args.internalDisplayRotationFlags = ui::Transform::ROT_180;
856 mOutput->updateCompositionState(args);
857 mOutput->planComposition();
858 mOutput->writeCompositionState(args);
859 }
860
TEST_F(OutputUpdateAndWriteCompositionStateTest,updatesLayerGeometryAndContentForAllLayers)861 TEST_F(OutputUpdateAndWriteCompositionStateTest, updatesLayerGeometryAndContentForAllLayers) {
862 InjectedLayer layer1;
863 InjectedLayer layer2;
864 InjectedLayer layer3;
865
866 uint32_t z = 0;
867 EXPECT_CALL(*layer1.outputLayer, updateCompositionState(true, false, ui::Transform::ROT_0));
868 EXPECT_CALL(*layer1.outputLayer,
869 writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, z++,
870 /*zIsOverridden*/ false, /*isPeekingThrough*/ false));
871 EXPECT_CALL(*layer2.outputLayer, updateCompositionState(true, false, ui::Transform::ROT_0));
872 EXPECT_CALL(*layer2.outputLayer,
873 writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, z++,
874 /*zIsOverridden*/ false, /*isPeekingThrough*/ false));
875 EXPECT_CALL(*layer3.outputLayer, updateCompositionState(true, false, ui::Transform::ROT_0));
876 EXPECT_CALL(*layer3.outputLayer,
877 writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, z++,
878 /*zIsOverridden*/ false, /*isPeekingThrough*/ false));
879
880 injectOutputLayer(layer1);
881 injectOutputLayer(layer2);
882 injectOutputLayer(layer3);
883
884 mOutput->editState().isEnabled = true;
885
886 CompositionRefreshArgs args;
887 args.updatingGeometryThisFrame = true;
888 args.devOptForceClientComposition = false;
889 mOutput->updateCompositionState(args);
890 mOutput->planComposition();
891 mOutput->writeCompositionState(args);
892 }
893
TEST_F(OutputUpdateAndWriteCompositionStateTest,forcesClientCompositionForAllLayers)894 TEST_F(OutputUpdateAndWriteCompositionStateTest, forcesClientCompositionForAllLayers) {
895 InjectedLayer layer1;
896 InjectedLayer layer2;
897 InjectedLayer layer3;
898
899 uint32_t z = 0;
900 EXPECT_CALL(*layer1.outputLayer, updateCompositionState(false, true, ui::Transform::ROT_0));
901 EXPECT_CALL(*layer1.outputLayer,
902 writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, z++,
903 /*zIsOverridden*/ false, /*isPeekingThrough*/ false));
904 EXPECT_CALL(*layer2.outputLayer, updateCompositionState(false, true, ui::Transform::ROT_0));
905 EXPECT_CALL(*layer2.outputLayer,
906 writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, z++,
907 /*zIsOverridden*/ false, /*isPeekingThrough*/ false));
908 EXPECT_CALL(*layer3.outputLayer, updateCompositionState(false, true, ui::Transform::ROT_0));
909 EXPECT_CALL(*layer3.outputLayer,
910 writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, z++,
911 /*zIsOverridden*/ false, /*isPeekingThrough*/ false));
912
913 injectOutputLayer(layer1);
914 injectOutputLayer(layer2);
915 injectOutputLayer(layer3);
916
917 mOutput->editState().isEnabled = true;
918
919 CompositionRefreshArgs args;
920 args.updatingGeometryThisFrame = false;
921 args.devOptForceClientComposition = true;
922 mOutput->updateCompositionState(args);
923 mOutput->planComposition();
924 mOutput->writeCompositionState(args);
925 }
926
TEST_F(OutputUpdateAndWriteCompositionStateTest,peekThroughLayerChangesOrder)927 TEST_F(OutputUpdateAndWriteCompositionStateTest, peekThroughLayerChangesOrder) {
928 renderengine::mock::RenderEngine renderEngine;
929 InjectedLayer layer0;
930 InjectedLayer layer1;
931 InjectedLayer layer2;
932 InjectedLayer layer3;
933
934 InSequence seq;
935 EXPECT_CALL(*layer0.outputLayer, updateCompositionState(true, false, ui::Transform::ROT_0));
936 EXPECT_CALL(*layer1.outputLayer, updateCompositionState(true, false, ui::Transform::ROT_0));
937 EXPECT_CALL(*layer2.outputLayer, updateCompositionState(true, false, ui::Transform::ROT_0));
938 EXPECT_CALL(*layer3.outputLayer, updateCompositionState(true, false, ui::Transform::ROT_0));
939
940 uint32_t z = 0;
941 EXPECT_CALL(*layer0.outputLayer,
942 writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, z++,
943 /*zIsOverridden*/ false, /*isPeekingThrough*/ false));
944
945 // After calling planComposition (which clears overrideInfo), this test sets
946 // layer3 to be the peekThroughLayer for layer1 and layer2. As a result, it
947 // comes first, setting isPeekingThrough to true and zIsOverridden to true
948 // for it and the following layers.
949 EXPECT_CALL(*layer3.outputLayer,
950 writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, z++,
951 /*zIsOverridden*/ true, /*isPeekingThrough*/
952 true));
953 EXPECT_CALL(*layer1.outputLayer,
954 writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, z++,
955 /*zIsOverridden*/ true, /*isPeekingThrough*/ false));
956 EXPECT_CALL(*layer2.outputLayer,
957 writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ true, z++,
958 /*zIsOverridden*/ true, /*isPeekingThrough*/ false));
959
960 injectOutputLayer(layer0);
961 injectOutputLayer(layer1);
962 injectOutputLayer(layer2);
963 injectOutputLayer(layer3);
964
965 mOutput->editState().isEnabled = true;
966
967 CompositionRefreshArgs args;
968 args.updatingGeometryThisFrame = true;
969 args.devOptForceClientComposition = false;
970 mOutput->updateCompositionState(args);
971 mOutput->planComposition();
972
973 std::shared_ptr<renderengine::ExternalTexture> buffer = std::make_shared<
974 renderengine::ExternalTexture>(new GraphicBuffer(), renderEngine,
975 renderengine::ExternalTexture::Usage::READABLE |
976 renderengine::ExternalTexture::Usage::WRITEABLE);
977 layer1.outputLayerState.overrideInfo.buffer = buffer;
978 layer2.outputLayerState.overrideInfo.buffer = buffer;
979 layer1.outputLayerState.overrideInfo.peekThroughLayer = layer3.outputLayer;
980 layer2.outputLayerState.overrideInfo.peekThroughLayer = layer3.outputLayer;
981
982 mOutput->writeCompositionState(args);
983 }
984
985 /*
986 * Output::prepareFrame()
987 */
988
989 struct OutputPrepareFrameTest : public testing::Test {
990 struct OutputPartialMock : public OutputPartialMockBase {
991 // Sets up the helper functions called by the function under test to use
992 // mock implementations.
993 MOCK_METHOD0(chooseCompositionStrategy, void());
994 };
995
OutputPrepareFrameTestandroid::compositionengine::__anon470a6e800110::OutputPrepareFrameTest996 OutputPrepareFrameTest() {
997 mOutput.setDisplayColorProfileForTest(
998 std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile));
999 mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
1000 }
1001
1002 StrictMock<mock::CompositionEngine> mCompositionEngine;
1003 mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>();
1004 mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>();
1005 StrictMock<OutputPartialMock> mOutput;
1006 };
1007
TEST_F(OutputPrepareFrameTest,takesEarlyOutIfNotEnabled)1008 TEST_F(OutputPrepareFrameTest, takesEarlyOutIfNotEnabled) {
1009 mOutput.editState().isEnabled = false;
1010
1011 mOutput.prepareFrame();
1012 }
1013
TEST_F(OutputPrepareFrameTest,delegatesToChooseCompositionStrategyAndRenderSurface)1014 TEST_F(OutputPrepareFrameTest, delegatesToChooseCompositionStrategyAndRenderSurface) {
1015 mOutput.editState().isEnabled = true;
1016 mOutput.editState().usesClientComposition = false;
1017 mOutput.editState().usesDeviceComposition = true;
1018
1019 EXPECT_CALL(mOutput, chooseCompositionStrategy()).Times(1);
1020 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(0u));
1021 EXPECT_CALL(*mRenderSurface, prepareFrame(false, true));
1022
1023 mOutput.prepareFrame();
1024 }
1025
1026 // Note: Use OutputTest and not OutputPrepareFrameTest, so the real
1027 // base chooseCompositionStrategy() is invoked.
TEST_F(OutputTest,prepareFrameSetsClientCompositionOnlyByDefault)1028 TEST_F(OutputTest, prepareFrameSetsClientCompositionOnlyByDefault) {
1029 mOutput->editState().isEnabled = true;
1030 mOutput->editState().usesClientComposition = false;
1031 mOutput->editState().usesDeviceComposition = true;
1032
1033 EXPECT_CALL(*mRenderSurface, prepareFrame(true, false));
1034
1035 mOutput->prepareFrame();
1036
1037 EXPECT_TRUE(mOutput->getState().usesClientComposition);
1038 EXPECT_FALSE(mOutput->getState().usesDeviceComposition);
1039 }
1040
1041 /*
1042 * Output::prepare()
1043 */
1044
1045 struct OutputPrepareTest : public testing::Test {
1046 struct OutputPartialMock : public OutputPartialMockBase {
1047 // Sets up the helper functions called by the function under test to use
1048 // mock implementations.
1049 MOCK_METHOD2(rebuildLayerStacks,
1050 void(const compositionengine::CompositionRefreshArgs&,
1051 compositionengine::LayerFESet&));
1052 };
1053
1054 StrictMock<OutputPartialMock> mOutput;
1055 CompositionRefreshArgs mRefreshArgs;
1056 LayerFESet mGeomSnapshots;
1057 };
1058
TEST_F(OutputPrepareTest,justInvokesRebuildLayerStacks)1059 TEST_F(OutputPrepareTest, justInvokesRebuildLayerStacks) {
1060 InSequence seq;
1061 EXPECT_CALL(mOutput, rebuildLayerStacks(Ref(mRefreshArgs), Ref(mGeomSnapshots)));
1062
1063 mOutput.prepare(mRefreshArgs, mGeomSnapshots);
1064 }
1065
1066 /*
1067 * Output::rebuildLayerStacks()
1068 */
1069
1070 struct OutputRebuildLayerStacksTest : public testing::Test {
1071 struct OutputPartialMock : public OutputPartialMockBase {
1072 // Sets up the helper functions called by the function under test to use
1073 // mock implementations.
1074 MOCK_METHOD2(collectVisibleLayers,
1075 void(const compositionengine::CompositionRefreshArgs&,
1076 compositionengine::Output::CoverageState&));
1077 };
1078
OutputRebuildLayerStacksTestandroid::compositionengine::__anon470a6e800110::OutputRebuildLayerStacksTest1079 OutputRebuildLayerStacksTest() {
1080 mOutput.mState.isEnabled = true;
1081 mOutput.mState.transform = kIdentityTransform;
1082 mOutput.mState.displaySpace.bounds = kOutputBounds;
1083
1084 mRefreshArgs.updatingOutputGeometryThisFrame = true;
1085
1086 mCoverageAboveCoveredLayersToSet = Region(Rect(0, 0, 10, 10));
1087
1088 EXPECT_CALL(mOutput, collectVisibleLayers(Ref(mRefreshArgs), _))
1089 .WillRepeatedly(Invoke(this, &OutputRebuildLayerStacksTest::setTestCoverageValues));
1090 }
1091
setTestCoverageValuesandroid::compositionengine::__anon470a6e800110::OutputRebuildLayerStacksTest1092 void setTestCoverageValues(const CompositionRefreshArgs&,
1093 compositionengine::Output::CoverageState& state) {
1094 state.aboveCoveredLayers = mCoverageAboveCoveredLayersToSet;
1095 state.aboveOpaqueLayers = mCoverageAboveOpaqueLayersToSet;
1096 state.dirtyRegion = mCoverageDirtyRegionToSet;
1097 }
1098
1099 static const ui::Transform kIdentityTransform;
1100 static const ui::Transform kRotate90Transform;
1101 static const Rect kOutputBounds;
1102
1103 StrictMock<OutputPartialMock> mOutput;
1104 CompositionRefreshArgs mRefreshArgs;
1105 LayerFESet mGeomSnapshots;
1106 Region mCoverageAboveCoveredLayersToSet;
1107 Region mCoverageAboveOpaqueLayersToSet;
1108 Region mCoverageDirtyRegionToSet;
1109 };
1110
1111 const ui::Transform OutputRebuildLayerStacksTest::kIdentityTransform{TR_IDENT, 1920, 1080};
1112 const ui::Transform OutputRebuildLayerStacksTest::kRotate90Transform{TR_ROT_90, 1920, 1080};
1113 const Rect OutputRebuildLayerStacksTest::kOutputBounds{0, 0, 1920, 1080};
1114
TEST_F(OutputRebuildLayerStacksTest,doesNothingIfNotEnabled)1115 TEST_F(OutputRebuildLayerStacksTest, doesNothingIfNotEnabled) {
1116 mOutput.mState.isEnabled = false;
1117
1118 mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots);
1119 }
1120
TEST_F(OutputRebuildLayerStacksTest,doesNothingIfNotUpdatingGeometryThisFrame)1121 TEST_F(OutputRebuildLayerStacksTest, doesNothingIfNotUpdatingGeometryThisFrame) {
1122 mRefreshArgs.updatingOutputGeometryThisFrame = false;
1123
1124 mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots);
1125 }
1126
TEST_F(OutputRebuildLayerStacksTest,computesUndefinedRegionWithNoRotationAndFullCoverage)1127 TEST_F(OutputRebuildLayerStacksTest, computesUndefinedRegionWithNoRotationAndFullCoverage) {
1128 mOutput.mState.transform = kIdentityTransform;
1129
1130 mCoverageAboveOpaqueLayersToSet = Region(Rect(0, 0, 1920, 1080));
1131
1132 mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots);
1133
1134 EXPECT_THAT(mOutput.mState.undefinedRegion, RegionEq(Region(Rect(0, 0, 0, 0))));
1135 }
1136
TEST_F(OutputRebuildLayerStacksTest,computesUndefinedRegionWithNoRotationAndPartialCoverage)1137 TEST_F(OutputRebuildLayerStacksTest, computesUndefinedRegionWithNoRotationAndPartialCoverage) {
1138 mOutput.mState.transform = kIdentityTransform;
1139
1140 mCoverageAboveOpaqueLayersToSet = Region(Rect(0, 0, 960, 1080));
1141
1142 mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots);
1143
1144 EXPECT_THAT(mOutput.mState.undefinedRegion, RegionEq(Region(Rect(960, 0, 1920, 1080))));
1145 }
1146
TEST_F(OutputRebuildLayerStacksTest,computesUndefinedRegionWith90RotationAndFullCoverage)1147 TEST_F(OutputRebuildLayerStacksTest, computesUndefinedRegionWith90RotationAndFullCoverage) {
1148 mOutput.mState.transform = kRotate90Transform;
1149
1150 mCoverageAboveOpaqueLayersToSet = Region(Rect(0, 0, 1080, 1920));
1151
1152 mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots);
1153
1154 EXPECT_THAT(mOutput.mState.undefinedRegion, RegionEq(Region(Rect(0, 0, 0, 0))));
1155 }
1156
TEST_F(OutputRebuildLayerStacksTest,computesUndefinedRegionWith90RotationAndPartialCoverage)1157 TEST_F(OutputRebuildLayerStacksTest, computesUndefinedRegionWith90RotationAndPartialCoverage) {
1158 mOutput.mState.transform = kRotate90Transform;
1159
1160 mCoverageAboveOpaqueLayersToSet = Region(Rect(0, 0, 1080, 960));
1161
1162 mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots);
1163
1164 EXPECT_THAT(mOutput.mState.undefinedRegion, RegionEq(Region(Rect(0, 0, 960, 1080))));
1165 }
1166
TEST_F(OutputRebuildLayerStacksTest,addsToDirtyRegionWithNoRotation)1167 TEST_F(OutputRebuildLayerStacksTest, addsToDirtyRegionWithNoRotation) {
1168 mOutput.mState.transform = kIdentityTransform;
1169 mOutput.mState.dirtyRegion = Region(Rect(960, 0, 1920, 1080));
1170
1171 mCoverageDirtyRegionToSet = Region(Rect(0, 0, 960, 1080));
1172
1173 mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots);
1174
1175 EXPECT_THAT(mOutput.mState.dirtyRegion, RegionEq(Region(Rect(0, 0, 1920, 1080))));
1176 }
1177
TEST_F(OutputRebuildLayerStacksTest,addsToDirtyRegionWith90Rotation)1178 TEST_F(OutputRebuildLayerStacksTest, addsToDirtyRegionWith90Rotation) {
1179 mOutput.mState.transform = kRotate90Transform;
1180 mOutput.mState.dirtyRegion = Region(Rect(0, 960, 1080, 1920));
1181
1182 mCoverageDirtyRegionToSet = Region(Rect(0, 0, 1080, 960));
1183
1184 mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots);
1185
1186 EXPECT_THAT(mOutput.mState.dirtyRegion, RegionEq(Region(Rect(0, 0, 1080, 1920))));
1187 }
1188
1189 /*
1190 * Output::collectVisibleLayers()
1191 */
1192
1193 struct OutputCollectVisibleLayersTest : public testing::Test {
1194 struct OutputPartialMock : public OutputPartialMockBase {
1195 // Sets up the helper functions called by the function under test to use
1196 // mock implementations.
1197 MOCK_METHOD2(ensureOutputLayerIfVisible,
1198 void(sp<compositionengine::LayerFE>&,
1199 compositionengine::Output::CoverageState&));
1200 MOCK_METHOD1(setReleasedLayers, void(const compositionengine::CompositionRefreshArgs&));
1201 MOCK_METHOD0(finalizePendingOutputLayers, void());
1202 };
1203
1204 struct Layer {
Layerandroid::compositionengine::__anon470a6e800110::OutputCollectVisibleLayersTest::Layer1205 Layer() {
1206 EXPECT_CALL(outputLayer, getState()).WillRepeatedly(ReturnRef(outputLayerState));
1207 EXPECT_CALL(outputLayer, editState()).WillRepeatedly(ReturnRef(outputLayerState));
1208 }
1209
1210 StrictMock<mock::OutputLayer> outputLayer;
1211 impl::OutputLayerCompositionState outputLayerState;
1212 sp<StrictMock<mock::LayerFE>> layerFE{new StrictMock<mock::LayerFE>()};
1213 };
1214
OutputCollectVisibleLayersTestandroid::compositionengine::__anon470a6e800110::OutputCollectVisibleLayersTest1215 OutputCollectVisibleLayersTest() {
1216 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(3u));
1217 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0))
1218 .WillRepeatedly(Return(&mLayer1.outputLayer));
1219 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(1))
1220 .WillRepeatedly(Return(&mLayer2.outputLayer));
1221 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(2))
1222 .WillRepeatedly(Return(&mLayer3.outputLayer));
1223
1224 mRefreshArgs.layers.push_back(mLayer1.layerFE);
1225 mRefreshArgs.layers.push_back(mLayer2.layerFE);
1226 mRefreshArgs.layers.push_back(mLayer3.layerFE);
1227 }
1228
1229 StrictMock<OutputPartialMock> mOutput;
1230 CompositionRefreshArgs mRefreshArgs;
1231 LayerFESet mGeomSnapshots;
1232 Output::CoverageState mCoverageState{mGeomSnapshots};
1233 Layer mLayer1;
1234 Layer mLayer2;
1235 Layer mLayer3;
1236 };
1237
TEST_F(OutputCollectVisibleLayersTest,doesMinimalWorkIfNoLayers)1238 TEST_F(OutputCollectVisibleLayersTest, doesMinimalWorkIfNoLayers) {
1239 mRefreshArgs.layers.clear();
1240 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(0u));
1241
1242 EXPECT_CALL(mOutput, setReleasedLayers(Ref(mRefreshArgs)));
1243 EXPECT_CALL(mOutput, finalizePendingOutputLayers());
1244
1245 mOutput.collectVisibleLayers(mRefreshArgs, mCoverageState);
1246 }
1247
TEST_F(OutputCollectVisibleLayersTest,processesCandidateLayersReversedAndSetsOutputLayerZ)1248 TEST_F(OutputCollectVisibleLayersTest, processesCandidateLayersReversedAndSetsOutputLayerZ) {
1249 // Enforce a call order sequence for this test.
1250 InSequence seq;
1251
1252 // Layer coverage is evaluated from front to back!
1253 EXPECT_CALL(mOutput, ensureOutputLayerIfVisible(Eq(mLayer3.layerFE), Ref(mCoverageState)));
1254 EXPECT_CALL(mOutput, ensureOutputLayerIfVisible(Eq(mLayer2.layerFE), Ref(mCoverageState)));
1255 EXPECT_CALL(mOutput, ensureOutputLayerIfVisible(Eq(mLayer1.layerFE), Ref(mCoverageState)));
1256
1257 EXPECT_CALL(mOutput, setReleasedLayers(Ref(mRefreshArgs)));
1258 EXPECT_CALL(mOutput, finalizePendingOutputLayers());
1259
1260 mOutput.collectVisibleLayers(mRefreshArgs, mCoverageState);
1261 }
1262
1263 /*
1264 * Output::ensureOutputLayerIfVisible()
1265 */
1266
1267 struct OutputEnsureOutputLayerIfVisibleTest : public testing::Test {
1268 struct OutputPartialMock : public OutputPartialMockBase {
1269 // Sets up the helper functions called by the function under test to use
1270 // mock implementations.
1271 MOCK_CONST_METHOD1(belongsInOutput, bool(const sp<compositionengine::LayerFE>&));
1272 MOCK_CONST_METHOD1(getOutputLayerOrderedByZByIndex, OutputLayer*(size_t));
1273 MOCK_METHOD2(ensureOutputLayer,
1274 compositionengine::OutputLayer*(std::optional<size_t>, const sp<LayerFE>&));
1275 };
1276
OutputEnsureOutputLayerIfVisibleTestandroid::compositionengine::__anon470a6e800110::OutputEnsureOutputLayerIfVisibleTest1277 OutputEnsureOutputLayerIfVisibleTest() {
1278 EXPECT_CALL(mOutput, belongsInOutput(sp<LayerFE>(mLayer.layerFE)))
1279 .WillRepeatedly(Return(true));
1280 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(1u));
1281 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0u))
1282 .WillRepeatedly(Return(&mLayer.outputLayer));
1283
1284 mOutput.mState.displaySpace.bounds = Rect(0, 0, 200, 300);
1285 mOutput.mState.layerStackSpace.content = Rect(0, 0, 200, 300);
1286 mOutput.mState.transform = ui::Transform(TR_IDENT, 200, 300);
1287
1288 mLayer.layerFEState.isVisible = true;
1289 mLayer.layerFEState.isOpaque = true;
1290 mLayer.layerFEState.contentDirty = true;
1291 mLayer.layerFEState.geomLayerBounds = FloatRect{0, 0, 100, 200};
1292 mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200);
1293 mLayer.layerFEState.transparentRegionHint = Region(Rect(0, 0, 100, 100));
1294
1295 mLayer.outputLayerState.visibleRegion = Region(Rect(0, 0, 50, 200));
1296 mLayer.outputLayerState.coveredRegion = Region(Rect(50, 0, 100, 200));
1297
1298 mGeomSnapshots.insert(mLayer.layerFE);
1299 }
1300
ensureOutputLayerIfVisibleandroid::compositionengine::__anon470a6e800110::OutputEnsureOutputLayerIfVisibleTest1301 void ensureOutputLayerIfVisible() {
1302 sp<LayerFE> layerFE(mLayer.layerFE);
1303 mOutput.ensureOutputLayerIfVisible(layerFE, mCoverageState);
1304 }
1305
1306 static const Region kEmptyRegion;
1307 static const Region kFullBoundsNoRotation;
1308 static const Region kRightHalfBoundsNoRotation;
1309 static const Region kLowerHalfBoundsNoRotation;
1310 static const Region kFullBounds90Rotation;
1311
1312 StrictMock<OutputPartialMock> mOutput;
1313 LayerFESet mGeomSnapshots;
1314 Output::CoverageState mCoverageState{mGeomSnapshots};
1315
1316 NonInjectedLayer mLayer;
1317 };
1318
1319 const Region OutputEnsureOutputLayerIfVisibleTest::kEmptyRegion = Region(Rect(0, 0, 0, 0));
1320 const Region OutputEnsureOutputLayerIfVisibleTest::kFullBoundsNoRotation =
1321 Region(Rect(0, 0, 100, 200));
1322 const Region OutputEnsureOutputLayerIfVisibleTest::kRightHalfBoundsNoRotation =
1323 Region(Rect(0, 100, 100, 200));
1324 const Region OutputEnsureOutputLayerIfVisibleTest::kLowerHalfBoundsNoRotation =
1325 Region(Rect(50, 0, 100, 200));
1326 const Region OutputEnsureOutputLayerIfVisibleTest::kFullBounds90Rotation =
1327 Region(Rect(0, 0, 200, 100));
1328
TEST_F(OutputEnsureOutputLayerIfVisibleTest,performsGeomLatchBeforeCheckingIfLayerBelongs)1329 TEST_F(OutputEnsureOutputLayerIfVisibleTest, performsGeomLatchBeforeCheckingIfLayerBelongs) {
1330 EXPECT_CALL(mOutput, belongsInOutput(sp<LayerFE>(mLayer.layerFE))).WillOnce(Return(false));
1331 EXPECT_CALL(*mLayer.layerFE,
1332 prepareCompositionState(compositionengine::LayerFE::StateSubset::BasicGeometry));
1333
1334 mGeomSnapshots.clear();
1335
1336 ensureOutputLayerIfVisible();
1337 }
1338
TEST_F(OutputEnsureOutputLayerIfVisibleTest,skipsLatchIfAlreadyLatchedBeforeCheckingIfLayerBelongs)1339 TEST_F(OutputEnsureOutputLayerIfVisibleTest,
1340 skipsLatchIfAlreadyLatchedBeforeCheckingIfLayerBelongs) {
1341 EXPECT_CALL(mOutput, belongsInOutput(sp<LayerFE>(mLayer.layerFE))).WillOnce(Return(false));
1342
1343 ensureOutputLayerIfVisible();
1344 }
1345
TEST_F(OutputEnsureOutputLayerIfVisibleTest,takesEarlyOutIfLayerHasNoCompositionState)1346 TEST_F(OutputEnsureOutputLayerIfVisibleTest, takesEarlyOutIfLayerHasNoCompositionState) {
1347 EXPECT_CALL(*mLayer.layerFE, getCompositionState()).WillOnce(Return(nullptr));
1348
1349 ensureOutputLayerIfVisible();
1350 }
1351
TEST_F(OutputEnsureOutputLayerIfVisibleTest,takesEarlyOutIfLayerNotVisible)1352 TEST_F(OutputEnsureOutputLayerIfVisibleTest, takesEarlyOutIfLayerNotVisible) {
1353 mLayer.layerFEState.isVisible = false;
1354
1355 ensureOutputLayerIfVisible();
1356 }
1357
TEST_F(OutputEnsureOutputLayerIfVisibleTest,takesEarlyOutIfLayerHasEmptyVisibleRegion)1358 TEST_F(OutputEnsureOutputLayerIfVisibleTest, takesEarlyOutIfLayerHasEmptyVisibleRegion) {
1359 mLayer.layerFEState.geomLayerBounds = FloatRect{0, 0, 0, 0};
1360
1361 ensureOutputLayerIfVisible();
1362 }
1363
TEST_F(OutputEnsureOutputLayerIfVisibleTest,takesNotSoEarlyOutifDrawRegionEmpty)1364 TEST_F(OutputEnsureOutputLayerIfVisibleTest, takesNotSoEarlyOutifDrawRegionEmpty) {
1365 mOutput.mState.displaySpace.bounds = Rect(0, 0, 0, 0);
1366
1367 ensureOutputLayerIfVisible();
1368 }
1369
TEST_F(OutputEnsureOutputLayerIfVisibleTest,handlesCreatingOutputLayerForOpaqueDirtyNotRotatedLayer)1370 TEST_F(OutputEnsureOutputLayerIfVisibleTest,
1371 handlesCreatingOutputLayerForOpaqueDirtyNotRotatedLayer) {
1372 mLayer.layerFEState.isOpaque = true;
1373 mLayer.layerFEState.contentDirty = true;
1374 mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200);
1375
1376 EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u));
1377 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(std::nullopt), Eq(mLayer.layerFE)))
1378 .WillOnce(Return(&mLayer.outputLayer));
1379
1380 ensureOutputLayerIfVisible();
1381
1382 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation));
1383 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation));
1384 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation));
1385
1386 EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation));
1387 EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion,
1388 RegionEq(kFullBoundsNoRotation));
1389 EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion));
1390 EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation));
1391 }
1392
TEST_F(OutputEnsureOutputLayerIfVisibleTest,handlesUpdatingOutputLayerForOpaqueDirtyNotRotatedLayer)1393 TEST_F(OutputEnsureOutputLayerIfVisibleTest,
1394 handlesUpdatingOutputLayerForOpaqueDirtyNotRotatedLayer) {
1395 mLayer.layerFEState.isOpaque = true;
1396 mLayer.layerFEState.contentDirty = true;
1397 mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200);
1398
1399 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(0u), Eq(mLayer.layerFE)))
1400 .WillOnce(Return(&mLayer.outputLayer));
1401
1402 ensureOutputLayerIfVisible();
1403
1404 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation));
1405 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation));
1406 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation));
1407
1408 EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation));
1409 EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion,
1410 RegionEq(kFullBoundsNoRotation));
1411 EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion));
1412 EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation));
1413 }
1414
TEST_F(OutputEnsureOutputLayerIfVisibleTest,handlesCreatingOutputLayerForTransparentDirtyNotRotatedLayer)1415 TEST_F(OutputEnsureOutputLayerIfVisibleTest,
1416 handlesCreatingOutputLayerForTransparentDirtyNotRotatedLayer) {
1417 mLayer.layerFEState.isOpaque = false;
1418 mLayer.layerFEState.contentDirty = true;
1419 mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200);
1420
1421 EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u));
1422 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(std::nullopt), Eq(mLayer.layerFE)))
1423 .WillOnce(Return(&mLayer.outputLayer));
1424
1425 ensureOutputLayerIfVisible();
1426
1427 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation));
1428 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation));
1429 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kEmptyRegion));
1430
1431 EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation));
1432 EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion,
1433 RegionEq(kRightHalfBoundsNoRotation));
1434 EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion));
1435 EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation));
1436 }
1437
TEST_F(OutputEnsureOutputLayerIfVisibleTest,handlesUpdatingOutputLayerForTransparentDirtyNotRotatedLayer)1438 TEST_F(OutputEnsureOutputLayerIfVisibleTest,
1439 handlesUpdatingOutputLayerForTransparentDirtyNotRotatedLayer) {
1440 mLayer.layerFEState.isOpaque = false;
1441 mLayer.layerFEState.contentDirty = true;
1442 mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200);
1443
1444 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(0u), Eq(mLayer.layerFE)))
1445 .WillOnce(Return(&mLayer.outputLayer));
1446
1447 ensureOutputLayerIfVisible();
1448
1449 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation));
1450 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation));
1451 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kEmptyRegion));
1452
1453 EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation));
1454 EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion,
1455 RegionEq(kRightHalfBoundsNoRotation));
1456 EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion));
1457 EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation));
1458 }
1459
TEST_F(OutputEnsureOutputLayerIfVisibleTest,handlesCreatingOutputLayerForOpaqueNonDirtyNotRotatedLayer)1460 TEST_F(OutputEnsureOutputLayerIfVisibleTest,
1461 handlesCreatingOutputLayerForOpaqueNonDirtyNotRotatedLayer) {
1462 mLayer.layerFEState.isOpaque = true;
1463 mLayer.layerFEState.contentDirty = false;
1464 mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200);
1465
1466 EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u));
1467 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(std::nullopt), Eq(mLayer.layerFE)))
1468 .WillOnce(Return(&mLayer.outputLayer));
1469
1470 ensureOutputLayerIfVisible();
1471
1472 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation));
1473 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation));
1474 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation));
1475
1476 EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation));
1477 EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion,
1478 RegionEq(kFullBoundsNoRotation));
1479 EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion));
1480 EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation));
1481 }
1482
TEST_F(OutputEnsureOutputLayerIfVisibleTest,handlesUpdatingOutputLayerForOpaqueNonDirtyNotRotatedLayer)1483 TEST_F(OutputEnsureOutputLayerIfVisibleTest,
1484 handlesUpdatingOutputLayerForOpaqueNonDirtyNotRotatedLayer) {
1485 mLayer.layerFEState.isOpaque = true;
1486 mLayer.layerFEState.contentDirty = false;
1487 mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200);
1488
1489 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(0u), Eq(mLayer.layerFE)))
1490 .WillOnce(Return(&mLayer.outputLayer));
1491
1492 ensureOutputLayerIfVisible();
1493
1494 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kLowerHalfBoundsNoRotation));
1495 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation));
1496 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation));
1497
1498 EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation));
1499 EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion,
1500 RegionEq(kFullBoundsNoRotation));
1501 EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion));
1502 EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation));
1503 }
1504
TEST_F(OutputEnsureOutputLayerIfVisibleTest,handlesCreatingOutputLayerForOpaqueDirtyRotated90Layer)1505 TEST_F(OutputEnsureOutputLayerIfVisibleTest,
1506 handlesCreatingOutputLayerForOpaqueDirtyRotated90Layer) {
1507 mLayer.layerFEState.isOpaque = true;
1508 mLayer.layerFEState.contentDirty = true;
1509 mLayer.layerFEState.geomLayerBounds = FloatRect{0, 0, 200, 100};
1510 mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_ROT_90, 100, 200);
1511 mLayer.outputLayerState.visibleRegion = Region(Rect(0, 0, 100, 100));
1512 mLayer.outputLayerState.coveredRegion = Region(Rect(100, 0, 200, 100));
1513
1514 EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u));
1515 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(std::nullopt), Eq(mLayer.layerFE)))
1516 .WillOnce(Return(&mLayer.outputLayer));
1517
1518 ensureOutputLayerIfVisible();
1519
1520 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation));
1521 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation));
1522 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation));
1523
1524 EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation));
1525 EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion,
1526 RegionEq(kFullBoundsNoRotation));
1527 EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion));
1528 EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation));
1529 }
1530
TEST_F(OutputEnsureOutputLayerIfVisibleTest,handlesUpdatingOutputLayerForOpaqueDirtyRotated90Layer)1531 TEST_F(OutputEnsureOutputLayerIfVisibleTest,
1532 handlesUpdatingOutputLayerForOpaqueDirtyRotated90Layer) {
1533 mLayer.layerFEState.isOpaque = true;
1534 mLayer.layerFEState.contentDirty = true;
1535 mLayer.layerFEState.geomLayerBounds = FloatRect{0, 0, 200, 100};
1536 mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_ROT_90, 100, 200);
1537 mLayer.outputLayerState.visibleRegion = Region(Rect(0, 0, 100, 100));
1538 mLayer.outputLayerState.coveredRegion = Region(Rect(100, 0, 200, 100));
1539
1540 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(0u), Eq(mLayer.layerFE)))
1541 .WillOnce(Return(&mLayer.outputLayer));
1542
1543 ensureOutputLayerIfVisible();
1544
1545 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation));
1546 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation));
1547 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation));
1548
1549 EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation));
1550 EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion,
1551 RegionEq(kFullBoundsNoRotation));
1552 EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion));
1553 EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation));
1554 }
1555
TEST_F(OutputEnsureOutputLayerIfVisibleTest,handlesCreatingOutputLayerForOpaqueDirtyNotRotatedLayerRotatedOutput)1556 TEST_F(OutputEnsureOutputLayerIfVisibleTest,
1557 handlesCreatingOutputLayerForOpaqueDirtyNotRotatedLayerRotatedOutput) {
1558 mLayer.layerFEState.isOpaque = true;
1559 mLayer.layerFEState.contentDirty = true;
1560 mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200);
1561
1562 mOutput.mState.layerStackSpace.content = Rect(0, 0, 300, 200);
1563 mOutput.mState.transform = ui::Transform(TR_ROT_90, 200, 300);
1564
1565 EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u));
1566 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(std::nullopt), Eq(mLayer.layerFE)))
1567 .WillOnce(Return(&mLayer.outputLayer));
1568
1569 ensureOutputLayerIfVisible();
1570
1571 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation));
1572 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation));
1573 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation));
1574
1575 EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation));
1576 EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion,
1577 RegionEq(kFullBoundsNoRotation));
1578 EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion));
1579 EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBounds90Rotation));
1580 }
1581
TEST_F(OutputEnsureOutputLayerIfVisibleTest,handlesUpdatingOutputLayerForOpaqueDirtyNotRotatedLayerRotatedOutput)1582 TEST_F(OutputEnsureOutputLayerIfVisibleTest,
1583 handlesUpdatingOutputLayerForOpaqueDirtyNotRotatedLayerRotatedOutput) {
1584 mLayer.layerFEState.isOpaque = true;
1585 mLayer.layerFEState.contentDirty = true;
1586 mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200);
1587
1588 mOutput.mState.layerStackSpace.content = Rect(0, 0, 300, 200);
1589 mOutput.mState.transform = ui::Transform(TR_ROT_90, 200, 300);
1590
1591 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(0u), Eq(mLayer.layerFE)))
1592 .WillOnce(Return(&mLayer.outputLayer));
1593
1594 ensureOutputLayerIfVisible();
1595
1596 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation));
1597 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation));
1598 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation));
1599
1600 EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation));
1601 EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion,
1602 RegionEq(kFullBoundsNoRotation));
1603 EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion));
1604 EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBounds90Rotation));
1605 }
1606
TEST_F(OutputEnsureOutputLayerIfVisibleTest,handlesCreatingOutputLayerForOpaqueDirtyArbitraryTransformLayer)1607 TEST_F(OutputEnsureOutputLayerIfVisibleTest,
1608 handlesCreatingOutputLayerForOpaqueDirtyArbitraryTransformLayer) {
1609 ui::Transform arbitraryTransform;
1610 arbitraryTransform.set(1, 1, -1, 1);
1611 arbitraryTransform.set(0, 100);
1612
1613 mLayer.layerFEState.isOpaque = true;
1614 mLayer.layerFEState.contentDirty = true;
1615 mLayer.layerFEState.geomLayerBounds = FloatRect{0, 0, 100, 200};
1616 mLayer.layerFEState.geomLayerTransform = arbitraryTransform;
1617
1618 EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u));
1619 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(std::nullopt), Eq(mLayer.layerFE)))
1620 .WillOnce(Return(&mLayer.outputLayer));
1621
1622 ensureOutputLayerIfVisible();
1623
1624 const Region kRegion = Region(Rect(0, 0, 300, 300));
1625 const Region kRegionClipped = Region(Rect(0, 0, 200, 300));
1626
1627 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kRegion));
1628 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kRegion));
1629 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kEmptyRegion));
1630
1631 EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kRegion));
1632 EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion, RegionEq(kRegion));
1633 EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion));
1634 EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kRegionClipped));
1635 }
1636
TEST_F(OutputEnsureOutputLayerIfVisibleTest,coverageAccumulatesTest)1637 TEST_F(OutputEnsureOutputLayerIfVisibleTest, coverageAccumulatesTest) {
1638 mLayer.layerFEState.isOpaque = false;
1639 mLayer.layerFEState.contentDirty = true;
1640 mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200);
1641
1642 mCoverageState.dirtyRegion = Region(Rect(0, 0, 500, 500));
1643 mCoverageState.aboveCoveredLayers = Region(Rect(50, 0, 150, 200));
1644 mCoverageState.aboveOpaqueLayers = Region(Rect(50, 0, 150, 200));
1645
1646 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(0u), Eq(mLayer.layerFE)))
1647 .WillOnce(Return(&mLayer.outputLayer));
1648
1649 ensureOutputLayerIfVisible();
1650
1651 const Region kExpectedDirtyRegion = Region(Rect(0, 0, 500, 500));
1652 const Region kExpectedAboveCoveredRegion = Region(Rect(0, 0, 150, 200));
1653 const Region kExpectedAboveOpaqueRegion = Region(Rect(50, 0, 150, 200));
1654 const Region kExpectedLayerVisibleRegion = Region(Rect(0, 0, 50, 200));
1655 const Region kExpectedLayerCoveredRegion = Region(Rect(50, 0, 100, 200));
1656 const Region kExpectedLayerVisibleNonTransparentRegion = Region(Rect(0, 100, 50, 200));
1657
1658 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kExpectedDirtyRegion));
1659 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kExpectedAboveCoveredRegion));
1660 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kExpectedAboveOpaqueRegion));
1661
1662 EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kExpectedLayerVisibleRegion));
1663 EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion,
1664 RegionEq(kExpectedLayerVisibleNonTransparentRegion));
1665 EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kExpectedLayerCoveredRegion));
1666 EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion,
1667 RegionEq(kExpectedLayerVisibleRegion));
1668 }
1669
TEST_F(OutputEnsureOutputLayerIfVisibleTest,coverageAccumulatesWithShadowsTest)1670 TEST_F(OutputEnsureOutputLayerIfVisibleTest, coverageAccumulatesWithShadowsTest) {
1671 ui::Transform translate;
1672 translate.set(50, 50);
1673 mLayer.layerFEState.geomLayerTransform = translate;
1674 mLayer.layerFEState.shadowRadius = 10.0f;
1675
1676 mCoverageState.dirtyRegion = Region(Rect(0, 0, 500, 500));
1677 // half of the layer including the casting shadow is covered and opaque
1678 mCoverageState.aboveCoveredLayers = Region(Rect(40, 40, 100, 260));
1679 mCoverageState.aboveOpaqueLayers = Region(Rect(40, 40, 100, 260));
1680
1681 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(0u), Eq(mLayer.layerFE)))
1682 .WillOnce(Return(&mLayer.outputLayer));
1683
1684 ensureOutputLayerIfVisible();
1685
1686 const Region kExpectedDirtyRegion = Region(Rect(0, 0, 500, 500));
1687 const Region kExpectedAboveCoveredRegion = Region(Rect(40, 40, 160, 260));
1688 // add starting opaque region to the opaque half of the casting layer bounds
1689 const Region kExpectedAboveOpaqueRegion =
1690 Region(Rect(40, 40, 100, 260)).orSelf(Rect(100, 50, 150, 250));
1691 const Region kExpectedLayerVisibleRegion = Region(Rect(100, 40, 160, 260));
1692 const Region kExpectedoutputSpaceLayerVisibleRegion = Region(Rect(100, 50, 150, 250));
1693 const Region kExpectedLayerCoveredRegion = Region(Rect(40, 40, 100, 260));
1694 const Region kExpectedLayerVisibleNonTransparentRegion = Region(Rect(100, 40, 160, 260));
1695 const Region kExpectedLayerShadowRegion =
1696 Region(Rect(40, 40, 160, 260)).subtractSelf(Rect(50, 50, 150, 250));
1697
1698 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kExpectedDirtyRegion));
1699 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kExpectedAboveCoveredRegion));
1700 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kExpectedAboveOpaqueRegion));
1701
1702 EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kExpectedLayerVisibleRegion));
1703 EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion,
1704 RegionEq(kExpectedLayerVisibleNonTransparentRegion));
1705 EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kExpectedLayerCoveredRegion));
1706 EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion,
1707 RegionEq(kExpectedoutputSpaceLayerVisibleRegion));
1708 EXPECT_THAT(mLayer.outputLayerState.shadowRegion, RegionEq(kExpectedLayerShadowRegion));
1709 EXPECT_FALSE(kExpectedLayerVisibleRegion.subtract(kExpectedLayerShadowRegion).isEmpty());
1710 }
1711
TEST_F(OutputEnsureOutputLayerIfVisibleTest,shadowRegionOnlyTest)1712 TEST_F(OutputEnsureOutputLayerIfVisibleTest, shadowRegionOnlyTest) {
1713 ui::Transform translate;
1714 translate.set(50, 50);
1715 mLayer.layerFEState.geomLayerTransform = translate;
1716 mLayer.layerFEState.shadowRadius = 10.0f;
1717
1718 mCoverageState.dirtyRegion = Region(Rect(0, 0, 500, 500));
1719 // Casting layer is covered by an opaque region leaving only part of its shadow to be drawn
1720 mCoverageState.aboveCoveredLayers = Region(Rect(40, 40, 150, 260));
1721 mCoverageState.aboveOpaqueLayers = Region(Rect(40, 40, 150, 260));
1722
1723 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(0u), Eq(mLayer.layerFE)))
1724 .WillOnce(Return(&mLayer.outputLayer));
1725
1726 ensureOutputLayerIfVisible();
1727
1728 const Region kExpectedLayerVisibleRegion = Region(Rect(150, 40, 160, 260));
1729 const Region kExpectedLayerShadowRegion =
1730 Region(Rect(40, 40, 160, 260)).subtractSelf(Rect(50, 50, 150, 250));
1731
1732 EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kExpectedLayerVisibleRegion));
1733 EXPECT_THAT(mLayer.outputLayerState.shadowRegion, RegionEq(kExpectedLayerShadowRegion));
1734 EXPECT_TRUE(kExpectedLayerVisibleRegion.subtract(kExpectedLayerShadowRegion).isEmpty());
1735 }
1736
TEST_F(OutputEnsureOutputLayerIfVisibleTest,takesNotSoEarlyOutifLayerWithShadowIsCovered)1737 TEST_F(OutputEnsureOutputLayerIfVisibleTest, takesNotSoEarlyOutifLayerWithShadowIsCovered) {
1738 ui::Transform translate;
1739 translate.set(50, 50);
1740 mLayer.layerFEState.geomLayerTransform = translate;
1741 mLayer.layerFEState.shadowRadius = 10.0f;
1742
1743 mCoverageState.dirtyRegion = Region(Rect(0, 0, 500, 500));
1744 // Casting layer and its shadows are covered by an opaque region
1745 mCoverageState.aboveCoveredLayers = Region(Rect(40, 40, 160, 260));
1746 mCoverageState.aboveOpaqueLayers = Region(Rect(40, 40, 160, 260));
1747
1748 ensureOutputLayerIfVisible();
1749 }
1750
1751 /*
1752 * Output::present()
1753 */
1754
1755 struct OutputPresentTest : public testing::Test {
1756 struct OutputPartialMock : public OutputPartialMockBase {
1757 // Sets up the helper functions called by the function under test to use
1758 // mock implementations.
1759 MOCK_METHOD1(updateColorProfile, void(const compositionengine::CompositionRefreshArgs&));
1760 MOCK_METHOD1(updateCompositionState,
1761 void(const compositionengine::CompositionRefreshArgs&));
1762 MOCK_METHOD0(planComposition, void());
1763 MOCK_METHOD1(writeCompositionState, void(const compositionengine::CompositionRefreshArgs&));
1764 MOCK_METHOD1(setColorTransform, void(const compositionengine::CompositionRefreshArgs&));
1765 MOCK_METHOD0(beginFrame, void());
1766 MOCK_METHOD0(prepareFrame, void());
1767 MOCK_METHOD1(devOptRepaintFlash, void(const compositionengine::CompositionRefreshArgs&));
1768 MOCK_METHOD1(finishFrame, void(const compositionengine::CompositionRefreshArgs&));
1769 MOCK_METHOD0(postFramebuffer, void());
1770 MOCK_METHOD1(renderCachedSets, void(const compositionengine::CompositionRefreshArgs&));
1771 };
1772
1773 StrictMock<OutputPartialMock> mOutput;
1774 };
1775
TEST_F(OutputPresentTest,justInvokesChildFunctionsInSequence)1776 TEST_F(OutputPresentTest, justInvokesChildFunctionsInSequence) {
1777 CompositionRefreshArgs args;
1778
1779 InSequence seq;
1780 EXPECT_CALL(mOutput, updateColorProfile(Ref(args)));
1781 EXPECT_CALL(mOutput, updateCompositionState(Ref(args)));
1782 EXPECT_CALL(mOutput, planComposition());
1783 EXPECT_CALL(mOutput, writeCompositionState(Ref(args)));
1784 EXPECT_CALL(mOutput, setColorTransform(Ref(args)));
1785 EXPECT_CALL(mOutput, beginFrame());
1786 EXPECT_CALL(mOutput, prepareFrame());
1787 EXPECT_CALL(mOutput, devOptRepaintFlash(Ref(args)));
1788 EXPECT_CALL(mOutput, finishFrame(Ref(args)));
1789 EXPECT_CALL(mOutput, postFramebuffer());
1790 EXPECT_CALL(mOutput, renderCachedSets(Ref(args)));
1791
1792 mOutput.present(args);
1793 }
1794
1795 /*
1796 * Output::updateColorProfile()
1797 */
1798
1799 struct OutputUpdateColorProfileTest : public testing::Test {
1800 using TestType = OutputUpdateColorProfileTest;
1801
1802 struct OutputPartialMock : public OutputPartialMockBase {
1803 // Sets up the helper functions called by the function under test to use
1804 // mock implementations.
1805 MOCK_METHOD1(setColorProfile, void(const ColorProfile&));
1806 };
1807
1808 struct Layer {
Layerandroid::compositionengine::__anon470a6e800110::OutputUpdateColorProfileTest::Layer1809 Layer() {
1810 EXPECT_CALL(mOutputLayer, getLayerFE()).WillRepeatedly(ReturnRef(*mLayerFE));
1811 EXPECT_CALL(*mLayerFE, getCompositionState()).WillRepeatedly(Return(&mLayerFEState));
1812 }
1813
1814 StrictMock<mock::OutputLayer> mOutputLayer;
1815 sp<StrictMock<mock::LayerFE>> mLayerFE = sp<StrictMock<mock::LayerFE>>::make();
1816 LayerFECompositionState mLayerFEState;
1817 };
1818
OutputUpdateColorProfileTestandroid::compositionengine::__anon470a6e800110::OutputUpdateColorProfileTest1819 OutputUpdateColorProfileTest() {
1820 mOutput.setDisplayColorProfileForTest(
1821 std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile));
1822 mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
1823
1824 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0))
1825 .WillRepeatedly(Return(&mLayer1.mOutputLayer));
1826 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(1))
1827 .WillRepeatedly(Return(&mLayer2.mOutputLayer));
1828 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(2))
1829 .WillRepeatedly(Return(&mLayer3.mOutputLayer));
1830 }
1831
1832 struct ExecuteState : public CallOrderStateMachineHelper<TestType, ExecuteState> {
executeandroid::compositionengine::__anon470a6e800110::OutputUpdateColorProfileTest::ExecuteState1833 void execute() { getInstance()->mOutput.updateColorProfile(getInstance()->mRefreshArgs); }
1834 };
1835
1836 mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>();
1837 mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>();
1838 StrictMock<OutputPartialMock> mOutput;
1839
1840 Layer mLayer1;
1841 Layer mLayer2;
1842 Layer mLayer3;
1843
1844 CompositionRefreshArgs mRefreshArgs;
1845 };
1846
1847 // TODO(b/144522012): Refactor Output::updateColorProfile and the related code
1848 // to make it easier to write unit tests.
1849
TEST_F(OutputUpdateColorProfileTest,setsAColorProfileWhenUnmanaged)1850 TEST_F(OutputUpdateColorProfileTest, setsAColorProfileWhenUnmanaged) {
1851 // When the outputColorSetting is set to kUnmanaged, the implementation sets
1852 // a simple default color profile without looking at anything else.
1853
1854 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(3u));
1855 EXPECT_CALL(mOutput,
1856 setColorProfile(ColorProfileEq(
1857 ColorProfile{ui::ColorMode::NATIVE, ui::Dataspace::UNKNOWN,
1858 ui::RenderIntent::COLORIMETRIC, ui::Dataspace::UNKNOWN})));
1859
1860 mRefreshArgs.outputColorSetting = OutputColorSetting::kUnmanaged;
1861 mRefreshArgs.colorSpaceAgnosticDataspace = ui::Dataspace::UNKNOWN;
1862
1863 mOutput.updateColorProfile(mRefreshArgs);
1864 }
1865
1866 struct OutputUpdateColorProfileTest_GetBestColorModeResultBecomesSetProfile
1867 : public OutputUpdateColorProfileTest {
OutputUpdateColorProfileTest_GetBestColorModeResultBecomesSetProfileandroid::compositionengine::__anon470a6e800110::OutputUpdateColorProfileTest_GetBestColorModeResultBecomesSetProfile1868 OutputUpdateColorProfileTest_GetBestColorModeResultBecomesSetProfile() {
1869 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(0u));
1870 mRefreshArgs.outputColorSetting = OutputColorSetting::kEnhanced;
1871 mRefreshArgs.colorSpaceAgnosticDataspace = ui::Dataspace::UNKNOWN;
1872 }
1873
1874 struct ExpectBestColorModeCallResultUsedToSetColorProfileState
1875 : public CallOrderStateMachineHelper<
1876 TestType, ExpectBestColorModeCallResultUsedToSetColorProfileState> {
expectBestColorModeCallResultUsedToSetColorProfileandroid::compositionengine::__anon470a6e800110::OutputUpdateColorProfileTest_GetBestColorModeResultBecomesSetProfile::ExpectBestColorModeCallResultUsedToSetColorProfileState1877 [[nodiscard]] auto expectBestColorModeCallResultUsedToSetColorProfile(
1878 ui::ColorMode colorMode, ui::Dataspace dataspace, ui::RenderIntent renderIntent) {
1879 EXPECT_CALL(*getInstance()->mDisplayColorProfile,
1880 getBestColorMode(ui::Dataspace::V0_SRGB, ui::RenderIntent::ENHANCE, _, _,
1881 _))
1882 .WillOnce(DoAll(SetArgPointee<2>(dataspace), SetArgPointee<3>(colorMode),
1883 SetArgPointee<4>(renderIntent)));
1884 EXPECT_CALL(getInstance()->mOutput,
1885 setColorProfile(
1886 ColorProfileEq(ColorProfile{colorMode, dataspace, renderIntent,
1887 ui::Dataspace::UNKNOWN})));
1888 return nextState<ExecuteState>();
1889 }
1890 };
1891
1892 // Call this member function to start using the mini-DSL defined above.
verifyandroid::compositionengine::__anon470a6e800110::OutputUpdateColorProfileTest_GetBestColorModeResultBecomesSetProfile1893 [[nodiscard]] auto verify() {
1894 return ExpectBestColorModeCallResultUsedToSetColorProfileState::make(this);
1895 }
1896 };
1897
TEST_F(OutputUpdateColorProfileTest_GetBestColorModeResultBecomesSetProfile,Native_Unknown_Colorimetric_Set)1898 TEST_F(OutputUpdateColorProfileTest_GetBestColorModeResultBecomesSetProfile,
1899 Native_Unknown_Colorimetric_Set) {
1900 verify().expectBestColorModeCallResultUsedToSetColorProfile(ui::ColorMode::NATIVE,
1901 ui::Dataspace::UNKNOWN,
1902 ui::RenderIntent::COLORIMETRIC)
1903 .execute();
1904 }
1905
TEST_F(OutputUpdateColorProfileTest_GetBestColorModeResultBecomesSetProfile,DisplayP3_DisplayP3_Enhance_Set)1906 TEST_F(OutputUpdateColorProfileTest_GetBestColorModeResultBecomesSetProfile,
1907 DisplayP3_DisplayP3_Enhance_Set) {
1908 verify().expectBestColorModeCallResultUsedToSetColorProfile(ui::ColorMode::DISPLAY_P3,
1909 ui::Dataspace::DISPLAY_P3,
1910 ui::RenderIntent::ENHANCE)
1911 .execute();
1912 }
1913
1914 struct OutputUpdateColorProfileTest_ColorSpaceAgnosticeDataspaceAffectsSetColorProfile
1915 : public OutputUpdateColorProfileTest {
OutputUpdateColorProfileTest_ColorSpaceAgnosticeDataspaceAffectsSetColorProfileandroid::compositionengine::__anon470a6e800110::OutputUpdateColorProfileTest_ColorSpaceAgnosticeDataspaceAffectsSetColorProfile1916 OutputUpdateColorProfileTest_ColorSpaceAgnosticeDataspaceAffectsSetColorProfile() {
1917 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(0u));
1918 EXPECT_CALL(*mDisplayColorProfile,
1919 getBestColorMode(ui::Dataspace::V0_SRGB, ui::RenderIntent::ENHANCE, _, _, _))
1920 .WillRepeatedly(DoAll(SetArgPointee<2>(ui::Dataspace::UNKNOWN),
1921 SetArgPointee<3>(ui::ColorMode::NATIVE),
1922 SetArgPointee<4>(ui::RenderIntent::COLORIMETRIC)));
1923 mRefreshArgs.outputColorSetting = OutputColorSetting::kEnhanced;
1924 }
1925
1926 struct IfColorSpaceAgnosticDataspaceSetToState
1927 : public CallOrderStateMachineHelper<TestType, IfColorSpaceAgnosticDataspaceSetToState> {
ifColorSpaceAgnosticDataspaceSetToandroid::compositionengine::__anon470a6e800110::OutputUpdateColorProfileTest_ColorSpaceAgnosticeDataspaceAffectsSetColorProfile::IfColorSpaceAgnosticDataspaceSetToState1928 [[nodiscard]] auto ifColorSpaceAgnosticDataspaceSetTo(ui::Dataspace dataspace) {
1929 getInstance()->mRefreshArgs.colorSpaceAgnosticDataspace = dataspace;
1930 return nextState<ThenExpectSetColorProfileCallUsesColorSpaceAgnosticDataspaceState>();
1931 }
1932 };
1933
1934 struct ThenExpectSetColorProfileCallUsesColorSpaceAgnosticDataspaceState
1935 : public CallOrderStateMachineHelper<
1936 TestType, ThenExpectSetColorProfileCallUsesColorSpaceAgnosticDataspaceState> {
thenExpectSetColorProfileCallUsesColorSpaceAgnosticDataspaceandroid::compositionengine::__anon470a6e800110::OutputUpdateColorProfileTest_ColorSpaceAgnosticeDataspaceAffectsSetColorProfile::ThenExpectSetColorProfileCallUsesColorSpaceAgnosticDataspaceState1937 [[nodiscard]] auto thenExpectSetColorProfileCallUsesColorSpaceAgnosticDataspace(
1938 ui::Dataspace dataspace) {
1939 EXPECT_CALL(getInstance()->mOutput,
1940 setColorProfile(ColorProfileEq(
1941 ColorProfile{ui::ColorMode::NATIVE, ui::Dataspace::UNKNOWN,
1942 ui::RenderIntent::COLORIMETRIC, dataspace})));
1943 return nextState<ExecuteState>();
1944 }
1945 };
1946
1947 // Call this member function to start using the mini-DSL defined above.
verifyandroid::compositionengine::__anon470a6e800110::OutputUpdateColorProfileTest_ColorSpaceAgnosticeDataspaceAffectsSetColorProfile1948 [[nodiscard]] auto verify() { return IfColorSpaceAgnosticDataspaceSetToState::make(this); }
1949 };
1950
TEST_F(OutputUpdateColorProfileTest_ColorSpaceAgnosticeDataspaceAffectsSetColorProfile,DisplayP3)1951 TEST_F(OutputUpdateColorProfileTest_ColorSpaceAgnosticeDataspaceAffectsSetColorProfile, DisplayP3) {
1952 verify().ifColorSpaceAgnosticDataspaceSetTo(ui::Dataspace::DISPLAY_P3)
1953 .thenExpectSetColorProfileCallUsesColorSpaceAgnosticDataspace(ui::Dataspace::DISPLAY_P3)
1954 .execute();
1955 }
1956
TEST_F(OutputUpdateColorProfileTest_ColorSpaceAgnosticeDataspaceAffectsSetColorProfile,V0_SRGB)1957 TEST_F(OutputUpdateColorProfileTest_ColorSpaceAgnosticeDataspaceAffectsSetColorProfile, V0_SRGB) {
1958 verify().ifColorSpaceAgnosticDataspaceSetTo(ui::Dataspace::V0_SRGB)
1959 .thenExpectSetColorProfileCallUsesColorSpaceAgnosticDataspace(ui::Dataspace::V0_SRGB)
1960 .execute();
1961 }
1962
1963 struct OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference
1964 : public OutputUpdateColorProfileTest {
1965 // Internally the implementation looks through the dataspaces of all the
1966 // visible layers. The topmost one that also has an actual dataspace
1967 // preference set is used to drive subsequent choices.
1968
OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreferenceandroid::compositionengine::__anon470a6e800110::OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference1969 OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference() {
1970 mRefreshArgs.outputColorSetting = OutputColorSetting::kEnhanced;
1971 mRefreshArgs.colorSpaceAgnosticDataspace = ui::Dataspace::UNKNOWN;
1972
1973 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(3u));
1974 EXPECT_CALL(mOutput, setColorProfile(_)).WillRepeatedly(Return());
1975 }
1976
1977 struct IfTopLayerDataspaceState
1978 : public CallOrderStateMachineHelper<TestType, IfTopLayerDataspaceState> {
ifTopLayerIsandroid::compositionengine::__anon470a6e800110::OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference::IfTopLayerDataspaceState1979 [[nodiscard]] auto ifTopLayerIs(ui::Dataspace dataspace) {
1980 getInstance()->mLayer3.mLayerFEState.dataspace = dataspace;
1981 return nextState<AndIfMiddleLayerDataspaceState>();
1982 }
ifTopLayerHasNoPreferenceandroid::compositionengine::__anon470a6e800110::OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference::IfTopLayerDataspaceState1983 [[nodiscard]] auto ifTopLayerHasNoPreference() {
1984 return ifTopLayerIs(ui::Dataspace::UNKNOWN);
1985 }
1986 };
1987
1988 struct AndIfMiddleLayerDataspaceState
1989 : public CallOrderStateMachineHelper<TestType, AndIfMiddleLayerDataspaceState> {
andIfMiddleLayerIsandroid::compositionengine::__anon470a6e800110::OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference::AndIfMiddleLayerDataspaceState1990 [[nodiscard]] auto andIfMiddleLayerIs(ui::Dataspace dataspace) {
1991 getInstance()->mLayer2.mLayerFEState.dataspace = dataspace;
1992 return nextState<AndIfBottomLayerDataspaceState>();
1993 }
andIfMiddleLayerHasNoPreferenceandroid::compositionengine::__anon470a6e800110::OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference::AndIfMiddleLayerDataspaceState1994 [[nodiscard]] auto andIfMiddleLayerHasNoPreference() {
1995 return andIfMiddleLayerIs(ui::Dataspace::UNKNOWN);
1996 }
1997 };
1998
1999 struct AndIfBottomLayerDataspaceState
2000 : public CallOrderStateMachineHelper<TestType, AndIfBottomLayerDataspaceState> {
andIfBottomLayerIsandroid::compositionengine::__anon470a6e800110::OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference::AndIfBottomLayerDataspaceState2001 [[nodiscard]] auto andIfBottomLayerIs(ui::Dataspace dataspace) {
2002 getInstance()->mLayer1.mLayerFEState.dataspace = dataspace;
2003 return nextState<ThenExpectBestColorModeCallUsesState>();
2004 }
andIfBottomLayerHasNoPreferenceandroid::compositionengine::__anon470a6e800110::OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference::AndIfBottomLayerDataspaceState2005 [[nodiscard]] auto andIfBottomLayerHasNoPreference() {
2006 return andIfBottomLayerIs(ui::Dataspace::UNKNOWN);
2007 }
2008 };
2009
2010 struct ThenExpectBestColorModeCallUsesState
2011 : public CallOrderStateMachineHelper<TestType, ThenExpectBestColorModeCallUsesState> {
thenExpectBestColorModeCallUsesandroid::compositionengine::__anon470a6e800110::OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference::ThenExpectBestColorModeCallUsesState2012 [[nodiscard]] auto thenExpectBestColorModeCallUses(ui::Dataspace dataspace) {
2013 EXPECT_CALL(*getInstance()->mDisplayColorProfile,
2014 getBestColorMode(dataspace, _, _, _, _));
2015 return nextState<ExecuteState>();
2016 }
2017 };
2018
2019 // Call this member function to start using the mini-DSL defined above.
verifyandroid::compositionengine::__anon470a6e800110::OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference2020 [[nodiscard]] auto verify() { return IfTopLayerDataspaceState::make(this); }
2021 };
2022
TEST_F(OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference,noStrongLayerPrefenceUses_V0_SRGB)2023 TEST_F(OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference,
2024 noStrongLayerPrefenceUses_V0_SRGB) {
2025 // If none of the layers indicate a preference, then V0_SRGB is the
2026 // preferred choice (subject to additional checks).
2027 verify().ifTopLayerHasNoPreference()
2028 .andIfMiddleLayerHasNoPreference()
2029 .andIfBottomLayerHasNoPreference()
2030 .thenExpectBestColorModeCallUses(ui::Dataspace::V0_SRGB)
2031 .execute();
2032 }
2033
TEST_F(OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference,ifTopmostUses_DisplayP3_Then_DisplayP3_Chosen)2034 TEST_F(OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference,
2035 ifTopmostUses_DisplayP3_Then_DisplayP3_Chosen) {
2036 // If only the topmost layer has a preference, then that is what is chosen.
2037 verify().ifTopLayerIs(ui::Dataspace::DISPLAY_P3)
2038 .andIfMiddleLayerHasNoPreference()
2039 .andIfBottomLayerHasNoPreference()
2040 .thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_P3)
2041 .execute();
2042 }
2043
TEST_F(OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference,ifMiddleUses_DisplayP3_Then_DisplayP3_Chosen)2044 TEST_F(OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference,
2045 ifMiddleUses_DisplayP3_Then_DisplayP3_Chosen) {
2046 // If only the middle layer has a preference, that that is what is chosen.
2047 verify().ifTopLayerHasNoPreference()
2048 .andIfMiddleLayerIs(ui::Dataspace::DISPLAY_P3)
2049 .andIfBottomLayerHasNoPreference()
2050 .thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_P3)
2051 .execute();
2052 }
2053
TEST_F(OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference,ifBottomUses_DisplayP3_Then_DisplayP3_Chosen)2054 TEST_F(OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference,
2055 ifBottomUses_DisplayP3_Then_DisplayP3_Chosen) {
2056 // If only the middle layer has a preference, that that is what is chosen.
2057 verify().ifTopLayerHasNoPreference()
2058 .andIfMiddleLayerHasNoPreference()
2059 .andIfBottomLayerIs(ui::Dataspace::DISPLAY_P3)
2060 .thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_P3)
2061 .execute();
2062 }
2063
TEST_F(OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference,ifTopUses_DisplayBT2020_AndBottomUses_DisplayP3_Then_DisplayBT2020_Chosen)2064 TEST_F(OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference,
2065 ifTopUses_DisplayBT2020_AndBottomUses_DisplayP3_Then_DisplayBT2020_Chosen) {
2066 // If multiple layers have a preference, the topmost value is what is used.
2067 verify().ifTopLayerIs(ui::Dataspace::DISPLAY_BT2020)
2068 .andIfMiddleLayerHasNoPreference()
2069 .andIfBottomLayerIs(ui::Dataspace::DISPLAY_P3)
2070 .thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_BT2020)
2071 .execute();
2072 }
2073
TEST_F(OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference,ifTopUses_DisplayP3_AndBottomUses_V0_SRGB_Then_DisplayP3_Chosen)2074 TEST_F(OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference,
2075 ifTopUses_DisplayP3_AndBottomUses_V0_SRGB_Then_DisplayP3_Chosen) {
2076 // If multiple layers have a preference, the topmost value is what is used.
2077 verify().ifTopLayerIs(ui::Dataspace::DISPLAY_P3)
2078 .andIfMiddleLayerHasNoPreference()
2079 .andIfBottomLayerIs(ui::Dataspace::DISPLAY_BT2020)
2080 .thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_P3)
2081 .execute();
2082 }
2083
2084 struct OutputUpdateColorProfileTest_ForceOutputColorOverrides
2085 : public OutputUpdateColorProfileTest {
2086 // If CompositionRefreshArgs::forceOutputColorMode is set to some specific
2087 // values, it overrides the layer dataspace choice.
2088
OutputUpdateColorProfileTest_ForceOutputColorOverridesandroid::compositionengine::__anon470a6e800110::OutputUpdateColorProfileTest_ForceOutputColorOverrides2089 OutputUpdateColorProfileTest_ForceOutputColorOverrides() {
2090 mRefreshArgs.outputColorSetting = OutputColorSetting::kEnhanced;
2091 mRefreshArgs.colorSpaceAgnosticDataspace = ui::Dataspace::UNKNOWN;
2092
2093 mLayer1.mLayerFEState.dataspace = ui::Dataspace::DISPLAY_BT2020;
2094
2095 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(1u));
2096 EXPECT_CALL(mOutput, setColorProfile(_)).WillRepeatedly(Return());
2097 }
2098
2099 struct IfForceOutputColorModeState
2100 : public CallOrderStateMachineHelper<TestType, IfForceOutputColorModeState> {
ifForceOutputColorModeandroid::compositionengine::__anon470a6e800110::OutputUpdateColorProfileTest_ForceOutputColorOverrides::IfForceOutputColorModeState2101 [[nodiscard]] auto ifForceOutputColorMode(ui::ColorMode colorMode) {
2102 getInstance()->mRefreshArgs.forceOutputColorMode = colorMode;
2103 return nextState<ThenExpectBestColorModeCallUsesState>();
2104 }
ifNoOverrideandroid::compositionengine::__anon470a6e800110::OutputUpdateColorProfileTest_ForceOutputColorOverrides::IfForceOutputColorModeState2105 [[nodiscard]] auto ifNoOverride() { return ifForceOutputColorMode(ui::ColorMode::NATIVE); }
2106 };
2107
2108 struct ThenExpectBestColorModeCallUsesState
2109 : public CallOrderStateMachineHelper<TestType, ThenExpectBestColorModeCallUsesState> {
thenExpectBestColorModeCallUsesandroid::compositionengine::__anon470a6e800110::OutputUpdateColorProfileTest_ForceOutputColorOverrides::ThenExpectBestColorModeCallUsesState2110 [[nodiscard]] auto thenExpectBestColorModeCallUses(ui::Dataspace dataspace) {
2111 EXPECT_CALL(*getInstance()->mDisplayColorProfile,
2112 getBestColorMode(dataspace, _, _, _, _));
2113 return nextState<ExecuteState>();
2114 }
2115 };
2116
2117 // Call this member function to start using the mini-DSL defined above.
verifyandroid::compositionengine::__anon470a6e800110::OutputUpdateColorProfileTest_ForceOutputColorOverrides2118 [[nodiscard]] auto verify() { return IfForceOutputColorModeState::make(this); }
2119 };
2120
TEST_F(OutputUpdateColorProfileTest_ForceOutputColorOverrides,NoOverride_DoesNotOverride)2121 TEST_F(OutputUpdateColorProfileTest_ForceOutputColorOverrides, NoOverride_DoesNotOverride) {
2122 // By default the layer state is used to set the preferred dataspace
2123 verify().ifNoOverride()
2124 .thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_BT2020)
2125 .execute();
2126 }
2127
TEST_F(OutputUpdateColorProfileTest_ForceOutputColorOverrides,SRGB_Override_USES_V0_SRGB)2128 TEST_F(OutputUpdateColorProfileTest_ForceOutputColorOverrides, SRGB_Override_USES_V0_SRGB) {
2129 // Setting ui::ColorMode::SRGB overrides it with ui::Dataspace::V0_SRGB
2130 verify().ifForceOutputColorMode(ui::ColorMode::SRGB)
2131 .thenExpectBestColorModeCallUses(ui::Dataspace::V0_SRGB)
2132 .execute();
2133 }
2134
TEST_F(OutputUpdateColorProfileTest_ForceOutputColorOverrides,DisplayP3_Override_Uses_DisplayP3)2135 TEST_F(OutputUpdateColorProfileTest_ForceOutputColorOverrides, DisplayP3_Override_Uses_DisplayP3) {
2136 // Setting ui::ColorMode::DISPLAY_P3 overrides it with ui::Dataspace::DISPLAY_P3
2137 verify().ifForceOutputColorMode(ui::ColorMode::DISPLAY_P3)
2138 .thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_P3)
2139 .execute();
2140 }
2141
2142 // HDR output requires all layers to be compatible with the chosen HDR
2143 // dataspace, along with there being proper support.
2144 struct OutputUpdateColorProfileTest_Hdr : public OutputUpdateColorProfileTest {
OutputUpdateColorProfileTest_Hdrandroid::compositionengine::__anon470a6e800110::OutputUpdateColorProfileTest_Hdr2145 OutputUpdateColorProfileTest_Hdr() {
2146 mRefreshArgs.outputColorSetting = OutputColorSetting::kEnhanced;
2147 mRefreshArgs.colorSpaceAgnosticDataspace = ui::Dataspace::UNKNOWN;
2148 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(2u));
2149 EXPECT_CALL(mOutput, setColorProfile(_)).WillRepeatedly(Return());
2150 }
2151
2152 static constexpr ui::Dataspace kNonHdrDataspace = ui::Dataspace::DISPLAY_P3;
2153 static constexpr ui::Dataspace BT2020_PQ = ui::Dataspace::BT2020_PQ;
2154 static constexpr ui::Dataspace BT2020_HLG = ui::Dataspace::BT2020_HLG;
2155 static constexpr ui::Dataspace DISPLAY_P3 = ui::Dataspace::DISPLAY_P3;
2156
2157 struct IfTopLayerDataspaceState
2158 : public CallOrderStateMachineHelper<TestType, IfTopLayerDataspaceState> {
ifTopLayerIsandroid::compositionengine::__anon470a6e800110::OutputUpdateColorProfileTest_Hdr::IfTopLayerDataspaceState2159 [[nodiscard]] auto ifTopLayerIs(ui::Dataspace dataspace) {
2160 getInstance()->mLayer2.mLayerFEState.dataspace = dataspace;
2161 return nextState<AndTopLayerCompositionTypeState>();
2162 }
ifTopLayerIsNotHdrandroid::compositionengine::__anon470a6e800110::OutputUpdateColorProfileTest_Hdr::IfTopLayerDataspaceState2163 [[nodiscard]] auto ifTopLayerIsNotHdr() { return ifTopLayerIs(kNonHdrDataspace); }
2164 };
2165
2166 struct AndTopLayerCompositionTypeState
2167 : public CallOrderStateMachineHelper<TestType, AndTopLayerCompositionTypeState> {
andTopLayerIsREComposedandroid::compositionengine::__anon470a6e800110::OutputUpdateColorProfileTest_Hdr::AndTopLayerCompositionTypeState2168 [[nodiscard]] auto andTopLayerIsREComposed(bool renderEngineComposed) {
2169 getInstance()->mLayer2.mLayerFEState.forceClientComposition = renderEngineComposed;
2170 return nextState<AndIfBottomLayerDataspaceState>();
2171 }
2172 };
2173
2174 struct AndIfBottomLayerDataspaceState
2175 : public CallOrderStateMachineHelper<TestType, AndIfBottomLayerDataspaceState> {
andIfBottomLayerIsandroid::compositionengine::__anon470a6e800110::OutputUpdateColorProfileTest_Hdr::AndIfBottomLayerDataspaceState2176 [[nodiscard]] auto andIfBottomLayerIs(ui::Dataspace dataspace) {
2177 getInstance()->mLayer1.mLayerFEState.dataspace = dataspace;
2178 return nextState<AndBottomLayerCompositionTypeState>();
2179 }
andIfBottomLayerIsNotHdrandroid::compositionengine::__anon470a6e800110::OutputUpdateColorProfileTest_Hdr::AndIfBottomLayerDataspaceState2180 [[nodiscard]] auto andIfBottomLayerIsNotHdr() {
2181 return andIfBottomLayerIs(kNonHdrDataspace);
2182 }
2183 };
2184
2185 struct AndBottomLayerCompositionTypeState
2186 : public CallOrderStateMachineHelper<TestType, AndBottomLayerCompositionTypeState> {
andBottomLayerIsREComposedandroid::compositionengine::__anon470a6e800110::OutputUpdateColorProfileTest_Hdr::AndBottomLayerCompositionTypeState2187 [[nodiscard]] auto andBottomLayerIsREComposed(bool renderEngineComposed) {
2188 getInstance()->mLayer1.mLayerFEState.forceClientComposition = renderEngineComposed;
2189 return nextState<AndIfHasLegacySupportState>();
2190 }
2191 };
2192
2193 struct AndIfHasLegacySupportState
2194 : public CallOrderStateMachineHelper<TestType, AndIfHasLegacySupportState> {
andIfLegacySupportForandroid::compositionengine::__anon470a6e800110::OutputUpdateColorProfileTest_Hdr::AndIfHasLegacySupportState2195 [[nodiscard]] auto andIfLegacySupportFor(ui::Dataspace dataspace, bool legacySupport) {
2196 EXPECT_CALL(*getInstance()->mDisplayColorProfile, hasLegacyHdrSupport(dataspace))
2197 .WillOnce(Return(legacySupport));
2198 return nextState<ThenExpectBestColorModeCallUsesState>();
2199 }
2200 };
2201
2202 struct ThenExpectBestColorModeCallUsesState
2203 : public CallOrderStateMachineHelper<TestType, ThenExpectBestColorModeCallUsesState> {
thenExpectBestColorModeCallUsesandroid::compositionengine::__anon470a6e800110::OutputUpdateColorProfileTest_Hdr::ThenExpectBestColorModeCallUsesState2204 [[nodiscard]] auto thenExpectBestColorModeCallUses(ui::Dataspace dataspace) {
2205 EXPECT_CALL(*getInstance()->mDisplayColorProfile,
2206 getBestColorMode(dataspace, _, _, _, _));
2207 return nextState<ExecuteState>();
2208 }
2209 };
2210
2211 // Call this member function to start using the mini-DSL defined above.
verifyandroid::compositionengine::__anon470a6e800110::OutputUpdateColorProfileTest_Hdr2212 [[nodiscard]] auto verify() { return IfTopLayerDataspaceState::make(this); }
2213 };
2214
TEST_F(OutputUpdateColorProfileTest_Hdr,PQ_HW_On_PQ_HW_Uses_PQ)2215 TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_PQ_HW_Uses_PQ) {
2216 // If all layers use BT2020_PQ, and there are no other special conditions,
2217 // BT2020_PQ is used.
2218 verify().ifTopLayerIs(BT2020_PQ)
2219 .andTopLayerIsREComposed(false)
2220 .andIfBottomLayerIs(BT2020_PQ)
2221 .andBottomLayerIsREComposed(false)
2222 .andIfLegacySupportFor(BT2020_PQ, false)
2223 .thenExpectBestColorModeCallUses(BT2020_PQ)
2224 .execute();
2225 }
2226
TEST_F(OutputUpdateColorProfileTest_Hdr,PQ_HW_On_PQ_HW_IfPQHasLegacySupport_Uses_DisplayP3)2227 TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_PQ_HW_IfPQHasLegacySupport_Uses_DisplayP3) {
2228 // BT2020_PQ is not used if there is only legacy support for it.
2229 verify().ifTopLayerIs(BT2020_PQ)
2230 .andTopLayerIsREComposed(false)
2231 .andIfBottomLayerIs(BT2020_PQ)
2232 .andBottomLayerIsREComposed(false)
2233 .andIfLegacySupportFor(BT2020_PQ, true)
2234 .thenExpectBestColorModeCallUses(DISPLAY_P3)
2235 .execute();
2236 }
2237
TEST_F(OutputUpdateColorProfileTest_Hdr,PQ_HW_On_PQ_RE_Uses_PQ)2238 TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_PQ_RE_Uses_PQ) {
2239 // BT2020_PQ is still used if the bottom layer is RenderEngine composed.
2240 verify().ifTopLayerIs(BT2020_PQ)
2241 .andTopLayerIsREComposed(false)
2242 .andIfBottomLayerIs(BT2020_PQ)
2243 .andBottomLayerIsREComposed(true)
2244 .andIfLegacySupportFor(BT2020_PQ, false)
2245 .thenExpectBestColorModeCallUses(BT2020_PQ)
2246 .execute();
2247 }
2248
TEST_F(OutputUpdateColorProfileTest_Hdr,PQ_RE_On_PQ_HW_Uses_DisplayP3)2249 TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_RE_On_PQ_HW_Uses_DisplayP3) {
2250 // BT2020_PQ is not used if the top layer is RenderEngine composed.
2251 verify().ifTopLayerIs(BT2020_PQ)
2252 .andTopLayerIsREComposed(true)
2253 .andIfBottomLayerIs(BT2020_PQ)
2254 .andBottomLayerIsREComposed(false)
2255 .andIfLegacySupportFor(BT2020_PQ, false)
2256 .thenExpectBestColorModeCallUses(DISPLAY_P3)
2257 .execute();
2258 }
2259
TEST_F(OutputUpdateColorProfileTest_Hdr,PQ_HW_On_HLG_HW_Uses_PQ)2260 TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_HLG_HW_Uses_PQ) {
2261 // If there is mixed HLG/PQ use, and the topmost layer is PQ, then PQ is used if there
2262 // are no other special conditions.
2263 verify().ifTopLayerIs(BT2020_PQ)
2264 .andTopLayerIsREComposed(false)
2265 .andIfBottomLayerIs(BT2020_HLG)
2266 .andBottomLayerIsREComposed(false)
2267 .andIfLegacySupportFor(BT2020_PQ, false)
2268 .thenExpectBestColorModeCallUses(BT2020_PQ)
2269 .execute();
2270 }
2271
TEST_F(OutputUpdateColorProfileTest_Hdr,PQ_HW_On_HLG_HW_IfPQHasLegacySupport_Uses_DisplayP3)2272 TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_HLG_HW_IfPQHasLegacySupport_Uses_DisplayP3) {
2273 // BT2020_PQ is not used if there is only legacy support for it.
2274 verify().ifTopLayerIs(BT2020_PQ)
2275 .andTopLayerIsREComposed(false)
2276 .andIfBottomLayerIs(BT2020_HLG)
2277 .andBottomLayerIsREComposed(false)
2278 .andIfLegacySupportFor(BT2020_PQ, true)
2279 .thenExpectBestColorModeCallUses(DISPLAY_P3)
2280 .execute();
2281 }
2282
TEST_F(OutputUpdateColorProfileTest_Hdr,PQ_HW_On_HLG_RE_Uses_PQ)2283 TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_HLG_RE_Uses_PQ) {
2284 // BT2020_PQ is used if the bottom HLG layer is RenderEngine composed.
2285 verify().ifTopLayerIs(BT2020_PQ)
2286 .andTopLayerIsREComposed(false)
2287 .andIfBottomLayerIs(BT2020_HLG)
2288 .andBottomLayerIsREComposed(true)
2289 .andIfLegacySupportFor(BT2020_PQ, false)
2290 .thenExpectBestColorModeCallUses(BT2020_PQ)
2291 .execute();
2292 }
2293
TEST_F(OutputUpdateColorProfileTest_Hdr,PQ_RE_On_HLG_HW_Uses_DisplayP3)2294 TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_RE_On_HLG_HW_Uses_DisplayP3) {
2295 // BT2020_PQ is not used if the top PQ layer is RenderEngine composed.
2296 verify().ifTopLayerIs(BT2020_PQ)
2297 .andTopLayerIsREComposed(true)
2298 .andIfBottomLayerIs(BT2020_HLG)
2299 .andBottomLayerIsREComposed(false)
2300 .andIfLegacySupportFor(BT2020_PQ, false)
2301 .thenExpectBestColorModeCallUses(DISPLAY_P3)
2302 .execute();
2303 }
2304
TEST_F(OutputUpdateColorProfileTest_Hdr,HLG_HW_On_PQ_HW_Uses_PQ)2305 TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_PQ_HW_Uses_PQ) {
2306 // If there is mixed HLG/PQ use, and the topmost layer is HLG, then PQ is
2307 // used if there are no other special conditions.
2308 verify().ifTopLayerIs(BT2020_HLG)
2309 .andTopLayerIsREComposed(false)
2310 .andIfBottomLayerIs(BT2020_PQ)
2311 .andBottomLayerIsREComposed(false)
2312 .andIfLegacySupportFor(BT2020_PQ, false)
2313 .thenExpectBestColorModeCallUses(BT2020_PQ)
2314 .execute();
2315 }
2316
TEST_F(OutputUpdateColorProfileTest_Hdr,HLG_HW_On_PQ_HW_IfPQHasLegacySupport_Uses_DisplayP3)2317 TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_PQ_HW_IfPQHasLegacySupport_Uses_DisplayP3) {
2318 // BT2020_PQ is not used if there is only legacy support for it.
2319 verify().ifTopLayerIs(BT2020_HLG)
2320 .andTopLayerIsREComposed(false)
2321 .andIfBottomLayerIs(BT2020_PQ)
2322 .andBottomLayerIsREComposed(false)
2323 .andIfLegacySupportFor(BT2020_PQ, true)
2324 .thenExpectBestColorModeCallUses(DISPLAY_P3)
2325 .execute();
2326 }
2327
TEST_F(OutputUpdateColorProfileTest_Hdr,HLG_HW_On_PQ_RE_Uses_DisplayP3)2328 TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_PQ_RE_Uses_DisplayP3) {
2329 // BT2020_PQ is not used if the bottom PQ layer is RenderEngine composed.
2330 verify().ifTopLayerIs(BT2020_HLG)
2331 .andTopLayerIsREComposed(false)
2332 .andIfBottomLayerIs(BT2020_PQ)
2333 .andBottomLayerIsREComposed(true)
2334 .andIfLegacySupportFor(BT2020_PQ, false)
2335 .thenExpectBestColorModeCallUses(DISPLAY_P3)
2336 .execute();
2337 }
2338
TEST_F(OutputUpdateColorProfileTest_Hdr,HLG_RE_On_PQ_HW_Uses_PQ)2339 TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_RE_On_PQ_HW_Uses_PQ) {
2340 // BT2020_PQ is still used if the top HLG layer is RenderEngine composed.
2341 verify().ifTopLayerIs(BT2020_HLG)
2342 .andTopLayerIsREComposed(true)
2343 .andIfBottomLayerIs(BT2020_PQ)
2344 .andBottomLayerIsREComposed(false)
2345 .andIfLegacySupportFor(BT2020_PQ, false)
2346 .thenExpectBestColorModeCallUses(BT2020_PQ)
2347 .execute();
2348 }
2349
TEST_F(OutputUpdateColorProfileTest_Hdr,HLG_HW_On_HLG_HW_Uses_HLG)2350 TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_HLG_HW_Uses_HLG) {
2351 // If all layers use HLG then HLG is used if there are no other special
2352 // conditions.
2353 verify().ifTopLayerIs(BT2020_HLG)
2354 .andTopLayerIsREComposed(false)
2355 .andIfBottomLayerIs(BT2020_HLG)
2356 .andBottomLayerIsREComposed(false)
2357 .andIfLegacySupportFor(BT2020_HLG, false)
2358 .thenExpectBestColorModeCallUses(BT2020_HLG)
2359 .execute();
2360 }
2361
TEST_F(OutputUpdateColorProfileTest_Hdr,HLG_HW_On_HLG_HW_IfPQHasLegacySupport_Uses_DisplayP3)2362 TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_HLG_HW_IfPQHasLegacySupport_Uses_DisplayP3) {
2363 // BT2020_HLG is not used if there is legacy support for it.
2364 verify().ifTopLayerIs(BT2020_HLG)
2365 .andTopLayerIsREComposed(false)
2366 .andIfBottomLayerIs(BT2020_HLG)
2367 .andBottomLayerIsREComposed(false)
2368 .andIfLegacySupportFor(BT2020_HLG, true)
2369 .thenExpectBestColorModeCallUses(DISPLAY_P3)
2370 .execute();
2371 }
2372
TEST_F(OutputUpdateColorProfileTest_Hdr,HLG_HW_On_HLG_RE_Uses_HLG)2373 TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_HLG_RE_Uses_HLG) {
2374 // BT2020_HLG is used even if the bottom layer is client composed.
2375 verify().ifTopLayerIs(BT2020_HLG)
2376 .andTopLayerIsREComposed(false)
2377 .andIfBottomLayerIs(BT2020_HLG)
2378 .andBottomLayerIsREComposed(true)
2379 .andIfLegacySupportFor(BT2020_HLG, false)
2380 .thenExpectBestColorModeCallUses(BT2020_HLG)
2381 .execute();
2382 }
2383
TEST_F(OutputUpdateColorProfileTest_Hdr,HLG_RE_On_HLG_HW_Uses_HLG)2384 TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_RE_On_HLG_HW_Uses_HLG) {
2385 // BT2020_HLG is used even if the top layer is client composed.
2386 verify().ifTopLayerIs(BT2020_HLG)
2387 .andTopLayerIsREComposed(true)
2388 .andIfBottomLayerIs(BT2020_HLG)
2389 .andBottomLayerIsREComposed(false)
2390 .andIfLegacySupportFor(BT2020_HLG, false)
2391 .thenExpectBestColorModeCallUses(BT2020_HLG)
2392 .execute();
2393 }
2394
TEST_F(OutputUpdateColorProfileTest_Hdr,PQ_HW_On_NonHdr_HW_Uses_PQ)2395 TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_NonHdr_HW_Uses_PQ) {
2396 // Even if there are non-HDR layers present, BT2020_PQ can still be used.
2397 verify().ifTopLayerIs(BT2020_PQ)
2398 .andTopLayerIsREComposed(false)
2399 .andIfBottomLayerIsNotHdr()
2400 .andBottomLayerIsREComposed(false)
2401 .andIfLegacySupportFor(BT2020_PQ, false)
2402 .thenExpectBestColorModeCallUses(BT2020_PQ)
2403 .execute();
2404 }
2405
TEST_F(OutputUpdateColorProfileTest_Hdr,HLG_HW_On_NonHdr_RE_Uses_HLG)2406 TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_NonHdr_RE_Uses_HLG) {
2407 // If all layers use HLG then HLG is used if there are no other special
2408 // conditions.
2409 verify().ifTopLayerIs(BT2020_HLG)
2410 .andTopLayerIsREComposed(false)
2411 .andIfBottomLayerIsNotHdr()
2412 .andBottomLayerIsREComposed(true)
2413 .andIfLegacySupportFor(BT2020_HLG, false)
2414 .thenExpectBestColorModeCallUses(BT2020_HLG)
2415 .execute();
2416 }
2417
2418 struct OutputUpdateColorProfile_AffectsChosenRenderIntentTest
2419 : public OutputUpdateColorProfileTest {
2420 // The various values for CompositionRefreshArgs::outputColorSetting affect
2421 // the chosen renderIntent, along with whether the preferred dataspace is an
2422 // HDR dataspace or not.
2423
OutputUpdateColorProfile_AffectsChosenRenderIntentTestandroid::compositionengine::__anon470a6e800110::OutputUpdateColorProfile_AffectsChosenRenderIntentTest2424 OutputUpdateColorProfile_AffectsChosenRenderIntentTest() {
2425 mRefreshArgs.outputColorSetting = OutputColorSetting::kEnhanced;
2426 mRefreshArgs.colorSpaceAgnosticDataspace = ui::Dataspace::UNKNOWN;
2427 mLayer1.mLayerFEState.dataspace = ui::Dataspace::BT2020_PQ;
2428 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(1u));
2429 EXPECT_CALL(mOutput, setColorProfile(_)).WillRepeatedly(Return());
2430 EXPECT_CALL(*mDisplayColorProfile, hasLegacyHdrSupport(ui::Dataspace::BT2020_PQ))
2431 .WillRepeatedly(Return(false));
2432 }
2433
2434 // The tests here involve enough state and GMock setup that using a mini-DSL
2435 // makes the tests much more readable, and allows the test to focus more on
2436 // the intent than on some of the details.
2437
2438 static constexpr ui::Dataspace kNonHdrDataspace = ui::Dataspace::DISPLAY_P3;
2439 static constexpr ui::Dataspace kHdrDataspace = ui::Dataspace::BT2020_PQ;
2440
2441 struct IfDataspaceChosenState
2442 : public CallOrderStateMachineHelper<TestType, IfDataspaceChosenState> {
ifDataspaceChosenIsandroid::compositionengine::__anon470a6e800110::OutputUpdateColorProfile_AffectsChosenRenderIntentTest::IfDataspaceChosenState2443 [[nodiscard]] auto ifDataspaceChosenIs(ui::Dataspace dataspace) {
2444 getInstance()->mLayer1.mLayerFEState.dataspace = dataspace;
2445 return nextState<AndOutputColorSettingState>();
2446 }
ifDataspaceChosenIsNonHdrandroid::compositionengine::__anon470a6e800110::OutputUpdateColorProfile_AffectsChosenRenderIntentTest::IfDataspaceChosenState2447 [[nodiscard]] auto ifDataspaceChosenIsNonHdr() {
2448 return ifDataspaceChosenIs(kNonHdrDataspace);
2449 }
ifDataspaceChosenIsHdrandroid::compositionengine::__anon470a6e800110::OutputUpdateColorProfile_AffectsChosenRenderIntentTest::IfDataspaceChosenState2450 [[nodiscard]] auto ifDataspaceChosenIsHdr() { return ifDataspaceChosenIs(kHdrDataspace); }
2451 };
2452
2453 struct AndOutputColorSettingState
2454 : public CallOrderStateMachineHelper<TestType, AndOutputColorSettingState> {
andOutputColorSettingIsandroid::compositionengine::__anon470a6e800110::OutputUpdateColorProfile_AffectsChosenRenderIntentTest::AndOutputColorSettingState2455 [[nodiscard]] auto andOutputColorSettingIs(OutputColorSetting setting) {
2456 getInstance()->mRefreshArgs.outputColorSetting = setting;
2457 return nextState<ThenExpectBestColorModeCallUsesState>();
2458 }
2459 };
2460
2461 struct ThenExpectBestColorModeCallUsesState
2462 : public CallOrderStateMachineHelper<TestType, ThenExpectBestColorModeCallUsesState> {
thenExpectBestColorModeCallUsesandroid::compositionengine::__anon470a6e800110::OutputUpdateColorProfile_AffectsChosenRenderIntentTest::ThenExpectBestColorModeCallUsesState2463 [[nodiscard]] auto thenExpectBestColorModeCallUses(ui::RenderIntent intent) {
2464 EXPECT_CALL(*getInstance()->mDisplayColorProfile,
2465 getBestColorMode(getInstance()->mLayer1.mLayerFEState.dataspace, intent, _,
2466 _, _));
2467 return nextState<ExecuteState>();
2468 }
2469 };
2470
2471 // Tests call one of these two helper member functions to start using the
2472 // mini-DSL defined above.
verifyandroid::compositionengine::__anon470a6e800110::OutputUpdateColorProfile_AffectsChosenRenderIntentTest2473 [[nodiscard]] auto verify() { return IfDataspaceChosenState::make(this); }
2474 };
2475
TEST_F(OutputUpdateColorProfile_AffectsChosenRenderIntentTest,Managed_NonHdr_Prefers_Colorimetric)2476 TEST_F(OutputUpdateColorProfile_AffectsChosenRenderIntentTest,
2477 Managed_NonHdr_Prefers_Colorimetric) {
2478 verify().ifDataspaceChosenIsNonHdr()
2479 .andOutputColorSettingIs(OutputColorSetting::kManaged)
2480 .thenExpectBestColorModeCallUses(ui::RenderIntent::COLORIMETRIC)
2481 .execute();
2482 }
2483
TEST_F(OutputUpdateColorProfile_AffectsChosenRenderIntentTest,Managed_Hdr_Prefers_ToneMapColorimetric)2484 TEST_F(OutputUpdateColorProfile_AffectsChosenRenderIntentTest,
2485 Managed_Hdr_Prefers_ToneMapColorimetric) {
2486 verify().ifDataspaceChosenIsHdr()
2487 .andOutputColorSettingIs(OutputColorSetting::kManaged)
2488 .thenExpectBestColorModeCallUses(ui::RenderIntent::TONE_MAP_COLORIMETRIC)
2489 .execute();
2490 }
2491
TEST_F(OutputUpdateColorProfile_AffectsChosenRenderIntentTest,Enhanced_NonHdr_Prefers_Enhance)2492 TEST_F(OutputUpdateColorProfile_AffectsChosenRenderIntentTest, Enhanced_NonHdr_Prefers_Enhance) {
2493 verify().ifDataspaceChosenIsNonHdr()
2494 .andOutputColorSettingIs(OutputColorSetting::kEnhanced)
2495 .thenExpectBestColorModeCallUses(ui::RenderIntent::ENHANCE)
2496 .execute();
2497 }
2498
TEST_F(OutputUpdateColorProfile_AffectsChosenRenderIntentTest,Enhanced_Hdr_Prefers_ToneMapEnhance)2499 TEST_F(OutputUpdateColorProfile_AffectsChosenRenderIntentTest,
2500 Enhanced_Hdr_Prefers_ToneMapEnhance) {
2501 verify().ifDataspaceChosenIsHdr()
2502 .andOutputColorSettingIs(OutputColorSetting::kEnhanced)
2503 .thenExpectBestColorModeCallUses(ui::RenderIntent::TONE_MAP_ENHANCE)
2504 .execute();
2505 }
2506
TEST_F(OutputUpdateColorProfile_AffectsChosenRenderIntentTest,Vendor_NonHdr_Prefers_Vendor)2507 TEST_F(OutputUpdateColorProfile_AffectsChosenRenderIntentTest, Vendor_NonHdr_Prefers_Vendor) {
2508 verify().ifDataspaceChosenIsNonHdr()
2509 .andOutputColorSettingIs(kVendorSpecifiedOutputColorSetting)
2510 .thenExpectBestColorModeCallUses(
2511 static_cast<ui::RenderIntent>(kVendorSpecifiedOutputColorSetting))
2512 .execute();
2513 }
2514
TEST_F(OutputUpdateColorProfile_AffectsChosenRenderIntentTest,Vendor_Hdr_Prefers_Vendor)2515 TEST_F(OutputUpdateColorProfile_AffectsChosenRenderIntentTest, Vendor_Hdr_Prefers_Vendor) {
2516 verify().ifDataspaceChosenIsHdr()
2517 .andOutputColorSettingIs(kVendorSpecifiedOutputColorSetting)
2518 .thenExpectBestColorModeCallUses(
2519 static_cast<ui::RenderIntent>(kVendorSpecifiedOutputColorSetting))
2520 .execute();
2521 }
2522
2523 /*
2524 * Output::beginFrame()
2525 */
2526
2527 struct OutputBeginFrameTest : public ::testing::Test {
2528 using TestType = OutputBeginFrameTest;
2529
2530 struct OutputPartialMock : public OutputPartialMockBase {
2531 // Sets up the helper functions called by the function under test to use
2532 // mock implementations.
2533 MOCK_CONST_METHOD1(getDirtyRegion, Region(bool));
2534 };
2535
OutputBeginFrameTestandroid::compositionengine::__anon470a6e800110::OutputBeginFrameTest2536 OutputBeginFrameTest() {
2537 mOutput.setDisplayColorProfileForTest(
2538 std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile));
2539 mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
2540 }
2541
2542 struct IfGetDirtyRegionExpectationState
2543 : public CallOrderStateMachineHelper<TestType, IfGetDirtyRegionExpectationState> {
ifGetDirtyRegionReturnsandroid::compositionengine::__anon470a6e800110::OutputBeginFrameTest::IfGetDirtyRegionExpectationState2544 [[nodiscard]] auto ifGetDirtyRegionReturns(Region dirtyRegion) {
2545 EXPECT_CALL(getInstance()->mOutput, getDirtyRegion(false))
2546 .WillOnce(Return(dirtyRegion));
2547 return nextState<AndIfGetOutputLayerCountExpectationState>();
2548 }
2549 };
2550
2551 struct AndIfGetOutputLayerCountExpectationState
2552 : public CallOrderStateMachineHelper<TestType, AndIfGetOutputLayerCountExpectationState> {
andIfGetOutputLayerCountReturnsandroid::compositionengine::__anon470a6e800110::OutputBeginFrameTest::AndIfGetOutputLayerCountExpectationState2553 [[nodiscard]] auto andIfGetOutputLayerCountReturns(size_t layerCount) {
2554 EXPECT_CALL(getInstance()->mOutput, getOutputLayerCount()).WillOnce(Return(layerCount));
2555 return nextState<AndIfLastCompositionHadVisibleLayersState>();
2556 }
2557 };
2558
2559 struct AndIfLastCompositionHadVisibleLayersState
2560 : public CallOrderStateMachineHelper<TestType,
2561 AndIfLastCompositionHadVisibleLayersState> {
andIfLastCompositionHadVisibleLayersIsandroid::compositionengine::__anon470a6e800110::OutputBeginFrameTest::AndIfLastCompositionHadVisibleLayersState2562 [[nodiscard]] auto andIfLastCompositionHadVisibleLayersIs(bool hadOutputLayers) {
2563 getInstance()->mOutput.mState.lastCompositionHadVisibleLayers = hadOutputLayers;
2564 return nextState<ThenExpectRenderSurfaceBeginFrameCallState>();
2565 }
2566 };
2567
2568 struct ThenExpectRenderSurfaceBeginFrameCallState
2569 : public CallOrderStateMachineHelper<TestType,
2570 ThenExpectRenderSurfaceBeginFrameCallState> {
thenExpectRenderSurfaceBeginFrameCallandroid::compositionengine::__anon470a6e800110::OutputBeginFrameTest::ThenExpectRenderSurfaceBeginFrameCallState2571 [[nodiscard]] auto thenExpectRenderSurfaceBeginFrameCall(bool mustRecompose) {
2572 EXPECT_CALL(*getInstance()->mRenderSurface, beginFrame(mustRecompose));
2573 return nextState<ExecuteState>();
2574 }
2575 };
2576
2577 struct ExecuteState : public CallOrderStateMachineHelper<TestType, ExecuteState> {
executeandroid::compositionengine::__anon470a6e800110::OutputBeginFrameTest::ExecuteState2578 [[nodiscard]] auto execute() {
2579 getInstance()->mOutput.beginFrame();
2580 return nextState<CheckPostconditionHadVisibleLayersState>();
2581 }
2582 };
2583
2584 struct CheckPostconditionHadVisibleLayersState
2585 : public CallOrderStateMachineHelper<TestType, CheckPostconditionHadVisibleLayersState> {
checkPostconditionHadVisibleLayersandroid::compositionengine::__anon470a6e800110::OutputBeginFrameTest::CheckPostconditionHadVisibleLayersState2586 void checkPostconditionHadVisibleLayers(bool expected) {
2587 EXPECT_EQ(expected, getInstance()->mOutput.mState.lastCompositionHadVisibleLayers);
2588 }
2589 };
2590
2591 // Tests call one of these two helper member functions to start using the
2592 // mini-DSL defined above.
verifyandroid::compositionengine::__anon470a6e800110::OutputBeginFrameTest2593 [[nodiscard]] auto verify() { return IfGetDirtyRegionExpectationState::make(this); }
2594
2595 static const Region kEmptyRegion;
2596 static const Region kNotEmptyRegion;
2597
2598 mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>();
2599 mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>();
2600 StrictMock<OutputPartialMock> mOutput;
2601 };
2602
2603 const Region OutputBeginFrameTest::kEmptyRegion{Rect{0, 0, 0, 0}};
2604 const Region OutputBeginFrameTest::kNotEmptyRegion{Rect{0, 0, 1, 1}};
2605
TEST_F(OutputBeginFrameTest,hasDirtyHasLayersHadLayersLastFrame)2606 TEST_F(OutputBeginFrameTest, hasDirtyHasLayersHadLayersLastFrame) {
2607 verify().ifGetDirtyRegionReturns(kNotEmptyRegion)
2608 .andIfGetOutputLayerCountReturns(1u)
2609 .andIfLastCompositionHadVisibleLayersIs(true)
2610 .thenExpectRenderSurfaceBeginFrameCall(true)
2611 .execute()
2612 .checkPostconditionHadVisibleLayers(true);
2613 }
2614
TEST_F(OutputBeginFrameTest,hasDirtyNotHasLayersHadLayersLastFrame)2615 TEST_F(OutputBeginFrameTest, hasDirtyNotHasLayersHadLayersLastFrame) {
2616 verify().ifGetDirtyRegionReturns(kNotEmptyRegion)
2617 .andIfGetOutputLayerCountReturns(0u)
2618 .andIfLastCompositionHadVisibleLayersIs(true)
2619 .thenExpectRenderSurfaceBeginFrameCall(true)
2620 .execute()
2621 .checkPostconditionHadVisibleLayers(false);
2622 }
2623
TEST_F(OutputBeginFrameTest,hasDirtyHasLayersNotHadLayersLastFrame)2624 TEST_F(OutputBeginFrameTest, hasDirtyHasLayersNotHadLayersLastFrame) {
2625 verify().ifGetDirtyRegionReturns(kNotEmptyRegion)
2626 .andIfGetOutputLayerCountReturns(1u)
2627 .andIfLastCompositionHadVisibleLayersIs(false)
2628 .thenExpectRenderSurfaceBeginFrameCall(true)
2629 .execute()
2630 .checkPostconditionHadVisibleLayers(true);
2631 }
2632
TEST_F(OutputBeginFrameTest,hasDirtyNotHasLayersNotHadLayersLastFrame)2633 TEST_F(OutputBeginFrameTest, hasDirtyNotHasLayersNotHadLayersLastFrame) {
2634 verify().ifGetDirtyRegionReturns(kNotEmptyRegion)
2635 .andIfGetOutputLayerCountReturns(0u)
2636 .andIfLastCompositionHadVisibleLayersIs(false)
2637 .thenExpectRenderSurfaceBeginFrameCall(false)
2638 .execute()
2639 .checkPostconditionHadVisibleLayers(false);
2640 }
2641
TEST_F(OutputBeginFrameTest,notHasDirtyHasLayersHadLayersLastFrame)2642 TEST_F(OutputBeginFrameTest, notHasDirtyHasLayersHadLayersLastFrame) {
2643 verify().ifGetDirtyRegionReturns(kEmptyRegion)
2644 .andIfGetOutputLayerCountReturns(1u)
2645 .andIfLastCompositionHadVisibleLayersIs(true)
2646 .thenExpectRenderSurfaceBeginFrameCall(false)
2647 .execute()
2648 .checkPostconditionHadVisibleLayers(true);
2649 }
2650
TEST_F(OutputBeginFrameTest,notHasDirtyNotHasLayersHadLayersLastFrame)2651 TEST_F(OutputBeginFrameTest, notHasDirtyNotHasLayersHadLayersLastFrame) {
2652 verify().ifGetDirtyRegionReturns(kEmptyRegion)
2653 .andIfGetOutputLayerCountReturns(0u)
2654 .andIfLastCompositionHadVisibleLayersIs(true)
2655 .thenExpectRenderSurfaceBeginFrameCall(false)
2656 .execute()
2657 .checkPostconditionHadVisibleLayers(true);
2658 }
2659
TEST_F(OutputBeginFrameTest,notHasDirtyHasLayersNotHadLayersLastFrame)2660 TEST_F(OutputBeginFrameTest, notHasDirtyHasLayersNotHadLayersLastFrame) {
2661 verify().ifGetDirtyRegionReturns(kEmptyRegion)
2662 .andIfGetOutputLayerCountReturns(1u)
2663 .andIfLastCompositionHadVisibleLayersIs(false)
2664 .thenExpectRenderSurfaceBeginFrameCall(false)
2665 .execute()
2666 .checkPostconditionHadVisibleLayers(false);
2667 }
2668
TEST_F(OutputBeginFrameTest,notHasDirtyNotHasLayersNotHadLayersLastFrame)2669 TEST_F(OutputBeginFrameTest, notHasDirtyNotHasLayersNotHadLayersLastFrame) {
2670 verify().ifGetDirtyRegionReturns(kEmptyRegion)
2671 .andIfGetOutputLayerCountReturns(0u)
2672 .andIfLastCompositionHadVisibleLayersIs(false)
2673 .thenExpectRenderSurfaceBeginFrameCall(false)
2674 .execute()
2675 .checkPostconditionHadVisibleLayers(false);
2676 }
2677
2678 /*
2679 * Output::devOptRepaintFlash()
2680 */
2681
2682 struct OutputDevOptRepaintFlashTest : public testing::Test {
2683 struct OutputPartialMock : public OutputPartialMockBase {
2684 // Sets up the helper functions called by the function under test to use
2685 // mock implementations.
2686 MOCK_CONST_METHOD1(getDirtyRegion, Region(bool));
2687 MOCK_METHOD2(composeSurfaces,
2688 std::optional<base::unique_fd>(
2689 const Region&, const compositionengine::CompositionRefreshArgs&));
2690 MOCK_METHOD0(postFramebuffer, void());
2691 MOCK_METHOD0(prepareFrame, void());
2692 };
2693
OutputDevOptRepaintFlashTestandroid::compositionengine::__anon470a6e800110::OutputDevOptRepaintFlashTest2694 OutputDevOptRepaintFlashTest() {
2695 mOutput.setDisplayColorProfileForTest(
2696 std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile));
2697 mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
2698 }
2699
2700 static const Region kEmptyRegion;
2701 static const Region kNotEmptyRegion;
2702
2703 StrictMock<OutputPartialMock> mOutput;
2704 mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>();
2705 mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>();
2706 CompositionRefreshArgs mRefreshArgs;
2707 };
2708
2709 const Region OutputDevOptRepaintFlashTest::kEmptyRegion{Rect{0, 0, 0, 0}};
2710 const Region OutputDevOptRepaintFlashTest::kNotEmptyRegion{Rect{0, 0, 1, 1}};
2711
TEST_F(OutputDevOptRepaintFlashTest,doesNothingIfFlashDelayNotSet)2712 TEST_F(OutputDevOptRepaintFlashTest, doesNothingIfFlashDelayNotSet) {
2713 mRefreshArgs.devOptFlashDirtyRegionsDelay = {};
2714 mRefreshArgs.repaintEverything = true;
2715 mOutput.mState.isEnabled = true;
2716
2717 mOutput.devOptRepaintFlash(mRefreshArgs);
2718 }
2719
TEST_F(OutputDevOptRepaintFlashTest,postsAndPreparesANewFrameIfNotEnabled)2720 TEST_F(OutputDevOptRepaintFlashTest, postsAndPreparesANewFrameIfNotEnabled) {
2721 mRefreshArgs.devOptFlashDirtyRegionsDelay = std::chrono::microseconds(1);
2722 mRefreshArgs.repaintEverything = true;
2723 mOutput.mState.isEnabled = false;
2724
2725 InSequence seq;
2726 EXPECT_CALL(mOutput, postFramebuffer());
2727 EXPECT_CALL(mOutput, prepareFrame());
2728
2729 mOutput.devOptRepaintFlash(mRefreshArgs);
2730 }
2731
TEST_F(OutputDevOptRepaintFlashTest,postsAndPreparesANewFrameIfNotDirty)2732 TEST_F(OutputDevOptRepaintFlashTest, postsAndPreparesANewFrameIfNotDirty) {
2733 mRefreshArgs.devOptFlashDirtyRegionsDelay = std::chrono::microseconds(1);
2734 mRefreshArgs.repaintEverything = true;
2735 mOutput.mState.isEnabled = true;
2736
2737 InSequence seq;
2738 EXPECT_CALL(mOutput, getDirtyRegion(true)).WillOnce(Return(kEmptyRegion));
2739 EXPECT_CALL(mOutput, postFramebuffer());
2740 EXPECT_CALL(mOutput, prepareFrame());
2741
2742 mOutput.devOptRepaintFlash(mRefreshArgs);
2743 }
2744
TEST_F(OutputDevOptRepaintFlashTest,alsoComposesSurfacesAndQueuesABufferIfDirty)2745 TEST_F(OutputDevOptRepaintFlashTest, alsoComposesSurfacesAndQueuesABufferIfDirty) {
2746 mRefreshArgs.devOptFlashDirtyRegionsDelay = std::chrono::microseconds(1);
2747 mRefreshArgs.repaintEverything = false;
2748 mOutput.mState.isEnabled = true;
2749
2750 InSequence seq;
2751 EXPECT_CALL(mOutput, getDirtyRegion(false)).WillOnce(Return(kNotEmptyRegion));
2752 EXPECT_CALL(mOutput, composeSurfaces(RegionEq(kNotEmptyRegion), Ref(mRefreshArgs)));
2753 EXPECT_CALL(*mRenderSurface, queueBuffer(_));
2754 EXPECT_CALL(mOutput, postFramebuffer());
2755 EXPECT_CALL(mOutput, prepareFrame());
2756
2757 mOutput.devOptRepaintFlash(mRefreshArgs);
2758 }
2759
2760 /*
2761 * Output::finishFrame()
2762 */
2763
2764 struct OutputFinishFrameTest : public testing::Test {
2765 struct OutputPartialMock : public OutputPartialMockBase {
2766 // Sets up the helper functions called by the function under test to use
2767 // mock implementations.
2768 MOCK_METHOD2(composeSurfaces,
2769 std::optional<base::unique_fd>(
2770 const Region&, const compositionengine::CompositionRefreshArgs&));
2771 MOCK_METHOD0(postFramebuffer, void());
2772 };
2773
OutputFinishFrameTestandroid::compositionengine::__anon470a6e800110::OutputFinishFrameTest2774 OutputFinishFrameTest() {
2775 mOutput.setDisplayColorProfileForTest(
2776 std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile));
2777 mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
2778 }
2779
2780 StrictMock<OutputPartialMock> mOutput;
2781 mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>();
2782 mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>();
2783 CompositionRefreshArgs mRefreshArgs;
2784 };
2785
TEST_F(OutputFinishFrameTest,ifNotEnabledDoesNothing)2786 TEST_F(OutputFinishFrameTest, ifNotEnabledDoesNothing) {
2787 mOutput.mState.isEnabled = false;
2788
2789 mOutput.finishFrame(mRefreshArgs);
2790 }
2791
TEST_F(OutputFinishFrameTest,takesEarlyOutifComposeSurfacesReturnsNoFence)2792 TEST_F(OutputFinishFrameTest, takesEarlyOutifComposeSurfacesReturnsNoFence) {
2793 mOutput.mState.isEnabled = true;
2794
2795 InSequence seq;
2796 EXPECT_CALL(mOutput, composeSurfaces(RegionEq(Region::INVALID_REGION), _));
2797
2798 mOutput.finishFrame(mRefreshArgs);
2799 }
2800
TEST_F(OutputFinishFrameTest,queuesBufferIfComposeSurfacesReturnsAFence)2801 TEST_F(OutputFinishFrameTest, queuesBufferIfComposeSurfacesReturnsAFence) {
2802 mOutput.mState.isEnabled = true;
2803
2804 InSequence seq;
2805 EXPECT_CALL(mOutput, composeSurfaces(RegionEq(Region::INVALID_REGION), _))
2806 .WillOnce(Return(ByMove(base::unique_fd())));
2807 EXPECT_CALL(*mRenderSurface, queueBuffer(_));
2808
2809 mOutput.finishFrame(mRefreshArgs);
2810 }
2811
2812 /*
2813 * Output::postFramebuffer()
2814 */
2815
2816 struct OutputPostFramebufferTest : public testing::Test {
2817 struct OutputPartialMock : public OutputPartialMockBase {
2818 // Sets up the helper functions called by the function under test to use
2819 // mock implementations.
2820 MOCK_METHOD0(presentAndGetFrameFences, compositionengine::Output::FrameFences());
2821 };
2822
2823 struct Layer {
Layerandroid::compositionengine::__anon470a6e800110::OutputPostFramebufferTest::Layer2824 Layer() {
2825 EXPECT_CALL(outputLayer, getLayerFE()).WillRepeatedly(ReturnRef(*layerFE));
2826 EXPECT_CALL(outputLayer, getHwcLayer()).WillRepeatedly(Return(&hwc2Layer));
2827 }
2828
2829 StrictMock<mock::OutputLayer> outputLayer;
2830 sp<StrictMock<mock::LayerFE>> layerFE = sp<StrictMock<mock::LayerFE>>::make();
2831 StrictMock<HWC2::mock::Layer> hwc2Layer;
2832 };
2833
OutputPostFramebufferTestandroid::compositionengine::__anon470a6e800110::OutputPostFramebufferTest2834 OutputPostFramebufferTest() {
2835 mOutput.setDisplayColorProfileForTest(
2836 std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile));
2837 mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
2838
2839 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(3u));
2840 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0u))
2841 .WillRepeatedly(Return(&mLayer1.outputLayer));
2842 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(1u))
2843 .WillRepeatedly(Return(&mLayer2.outputLayer));
2844 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(2u))
2845 .WillRepeatedly(Return(&mLayer3.outputLayer));
2846 }
2847
2848 StrictMock<OutputPartialMock> mOutput;
2849 mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>();
2850 mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>();
2851
2852 Layer mLayer1;
2853 Layer mLayer2;
2854 Layer mLayer3;
2855 };
2856
TEST_F(OutputPostFramebufferTest,ifNotEnabledDoesNothing)2857 TEST_F(OutputPostFramebufferTest, ifNotEnabledDoesNothing) {
2858 mOutput.mState.isEnabled = false;
2859
2860 mOutput.postFramebuffer();
2861 }
2862
TEST_F(OutputPostFramebufferTest,ifEnabledMustFlipThenPresentThenSendPresentCompleted)2863 TEST_F(OutputPostFramebufferTest, ifEnabledMustFlipThenPresentThenSendPresentCompleted) {
2864 mOutput.mState.isEnabled = true;
2865
2866 compositionengine::Output::FrameFences frameFences;
2867
2868 // This should happen even if there are no output layers.
2869 EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u));
2870
2871 // For this test in particular we want to make sure the call expectations
2872 // setup below are satisfied in the specific order.
2873 InSequence seq;
2874
2875 EXPECT_CALL(*mRenderSurface, flip());
2876 EXPECT_CALL(mOutput, presentAndGetFrameFences()).WillOnce(Return(frameFences));
2877 EXPECT_CALL(*mRenderSurface, onPresentDisplayCompleted());
2878
2879 mOutput.postFramebuffer();
2880 }
2881
TEST_F(OutputPostFramebufferTest,releaseFencesAreSentToLayerFE)2882 TEST_F(OutputPostFramebufferTest, releaseFencesAreSentToLayerFE) {
2883 // Simulate getting release fences from each layer, and ensure they are passed to the
2884 // front-end layer interface for each layer correctly.
2885
2886 mOutput.mState.isEnabled = true;
2887
2888 // Create three unique fence instances
2889 sp<Fence> layer1Fence = new Fence();
2890 sp<Fence> layer2Fence = new Fence();
2891 sp<Fence> layer3Fence = new Fence();
2892
2893 Output::FrameFences frameFences;
2894 frameFences.layerFences.emplace(&mLayer1.hwc2Layer, layer1Fence);
2895 frameFences.layerFences.emplace(&mLayer2.hwc2Layer, layer2Fence);
2896 frameFences.layerFences.emplace(&mLayer3.hwc2Layer, layer3Fence);
2897
2898 EXPECT_CALL(*mRenderSurface, flip());
2899 EXPECT_CALL(mOutput, presentAndGetFrameFences()).WillOnce(Return(frameFences));
2900 EXPECT_CALL(*mRenderSurface, onPresentDisplayCompleted());
2901
2902 // Compare the pointers values of each fence to make sure the correct ones
2903 // are passed. This happens to work with the current implementation, but
2904 // would not survive certain calls like Fence::merge() which would return a
2905 // new instance.
2906 EXPECT_CALL(*mLayer1.layerFE,
2907 onLayerDisplayed(Property(&sp<Fence>::get, Eq(layer1Fence.get()))));
2908 EXPECT_CALL(*mLayer2.layerFE,
2909 onLayerDisplayed(Property(&sp<Fence>::get, Eq(layer2Fence.get()))));
2910 EXPECT_CALL(*mLayer3.layerFE,
2911 onLayerDisplayed(Property(&sp<Fence>::get, Eq(layer3Fence.get()))));
2912
2913 mOutput.postFramebuffer();
2914 }
2915
TEST_F(OutputPostFramebufferTest,releaseFencesIncludeClientTargetAcquireFence)2916 TEST_F(OutputPostFramebufferTest, releaseFencesIncludeClientTargetAcquireFence) {
2917 mOutput.mState.isEnabled = true;
2918 mOutput.mState.usesClientComposition = true;
2919
2920 sp<Fence> clientTargetAcquireFence = new Fence();
2921 sp<Fence> layer1Fence = new Fence();
2922 sp<Fence> layer2Fence = new Fence();
2923 sp<Fence> layer3Fence = new Fence();
2924 Output::FrameFences frameFences;
2925 frameFences.clientTargetAcquireFence = clientTargetAcquireFence;
2926 frameFences.layerFences.emplace(&mLayer1.hwc2Layer, layer1Fence);
2927 frameFences.layerFences.emplace(&mLayer2.hwc2Layer, layer2Fence);
2928 frameFences.layerFences.emplace(&mLayer3.hwc2Layer, layer3Fence);
2929
2930 EXPECT_CALL(*mRenderSurface, flip());
2931 EXPECT_CALL(mOutput, presentAndGetFrameFences()).WillOnce(Return(frameFences));
2932 EXPECT_CALL(*mRenderSurface, onPresentDisplayCompleted());
2933
2934 // Fence::merge is called, and since none of the fences are actually valid,
2935 // Fence::NO_FENCE is returned and passed to each onLayerDisplayed() call.
2936 // This is the best we can do without creating a real kernel fence object.
2937 EXPECT_CALL(*mLayer1.layerFE, onLayerDisplayed(Fence::NO_FENCE));
2938 EXPECT_CALL(*mLayer2.layerFE, onLayerDisplayed(Fence::NO_FENCE));
2939 EXPECT_CALL(*mLayer3.layerFE, onLayerDisplayed(Fence::NO_FENCE));
2940
2941 mOutput.postFramebuffer();
2942 }
2943
TEST_F(OutputPostFramebufferTest,releasedLayersSentPresentFence)2944 TEST_F(OutputPostFramebufferTest, releasedLayersSentPresentFence) {
2945 mOutput.mState.isEnabled = true;
2946 mOutput.mState.usesClientComposition = true;
2947
2948 // This should happen even if there are no (current) output layers.
2949 EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u));
2950
2951 // Load up the released layers with some mock instances
2952 sp<StrictMock<mock::LayerFE>> releasedLayer1{new StrictMock<mock::LayerFE>()};
2953 sp<StrictMock<mock::LayerFE>> releasedLayer2{new StrictMock<mock::LayerFE>()};
2954 sp<StrictMock<mock::LayerFE>> releasedLayer3{new StrictMock<mock::LayerFE>()};
2955 Output::ReleasedLayers layers;
2956 layers.push_back(releasedLayer1);
2957 layers.push_back(releasedLayer2);
2958 layers.push_back(releasedLayer3);
2959 mOutput.setReleasedLayers(std::move(layers));
2960
2961 // Set up a fake present fence
2962 sp<Fence> presentFence = new Fence();
2963 Output::FrameFences frameFences;
2964 frameFences.presentFence = presentFence;
2965
2966 EXPECT_CALL(*mRenderSurface, flip());
2967 EXPECT_CALL(mOutput, presentAndGetFrameFences()).WillOnce(Return(frameFences));
2968 EXPECT_CALL(*mRenderSurface, onPresentDisplayCompleted());
2969
2970 // Each released layer should be given the presentFence.
2971 EXPECT_CALL(*releasedLayer1,
2972 onLayerDisplayed(Property(&sp<Fence>::get, Eq(presentFence.get()))));
2973 EXPECT_CALL(*releasedLayer2,
2974 onLayerDisplayed(Property(&sp<Fence>::get, Eq(presentFence.get()))));
2975 EXPECT_CALL(*releasedLayer3,
2976 onLayerDisplayed(Property(&sp<Fence>::get, Eq(presentFence.get()))));
2977
2978 mOutput.postFramebuffer();
2979
2980 // After the call the list of released layers should have been cleared.
2981 EXPECT_TRUE(mOutput.getReleasedLayersForTest().empty());
2982 }
2983
2984 /*
2985 * Output::composeSurfaces()
2986 */
2987
2988 struct OutputComposeSurfacesTest : public testing::Test {
2989 using TestType = OutputComposeSurfacesTest;
2990
2991 struct OutputPartialMock : public OutputPartialMockBase {
2992 // Sets up the helper functions called by the function under test to use
2993 // mock implementations.
2994 MOCK_CONST_METHOD0(getSkipColorTransform, bool());
2995 MOCK_METHOD3(generateClientCompositionRequests,
2996 std::vector<LayerFE::LayerSettings>(bool, Region&, ui::Dataspace));
2997 MOCK_METHOD2(appendRegionFlashRequests,
2998 void(const Region&, std::vector<LayerFE::LayerSettings>&));
2999 MOCK_METHOD1(setExpensiveRenderingExpected, void(bool));
3000 };
3001
OutputComposeSurfacesTestandroid::compositionengine::__anon470a6e800110::OutputComposeSurfacesTest3002 OutputComposeSurfacesTest() {
3003 mOutput.setDisplayColorProfileForTest(
3004 std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile));
3005 mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
3006 mOutput.cacheClientCompositionRequests(MAX_CLIENT_COMPOSITION_CACHE_SIZE);
3007
3008 mOutput.mState.orientedDisplaySpace.content = kDefaultOutputFrame;
3009 mOutput.mState.layerStackSpace.content = kDefaultOutputViewport;
3010 mOutput.mState.framebufferSpace.content = kDefaultOutputDestinationClip;
3011 mOutput.mState.displaySpace.content = kDefaultOutputDestinationClip;
3012 mOutput.mState.displaySpace.orientation = kDefaultOutputOrientation;
3013 mOutput.mState.transform = ui::Transform{kDefaultOutputOrientationFlags};
3014 mOutput.mState.dataspace = kDefaultOutputDataspace;
3015 mOutput.mState.colorTransformMatrix = kDefaultColorTransformMat;
3016 mOutput.mState.isSecure = false;
3017 mOutput.mState.needsFiltering = false;
3018 mOutput.mState.usesClientComposition = true;
3019 mOutput.mState.usesDeviceComposition = false;
3020 mOutput.mState.reusedClientComposition = false;
3021 mOutput.mState.flipClientTarget = false;
3022
3023 EXPECT_CALL(mOutput, getCompositionEngine()).WillRepeatedly(ReturnRef(mCompositionEngine));
3024 EXPECT_CALL(mCompositionEngine, getRenderEngine()).WillRepeatedly(ReturnRef(mRenderEngine));
3025 EXPECT_CALL(mCompositionEngine, getTimeStats())
3026 .WillRepeatedly(ReturnRef(*mTimeStats.get()));
3027 EXPECT_CALL(*mDisplayColorProfile, getHdrCapabilities())
3028 .WillRepeatedly(ReturnRef(kHdrCapabilities));
3029 }
3030
3031 struct ExecuteState : public CallOrderStateMachineHelper<TestType, ExecuteState> {
executeandroid::compositionengine::__anon470a6e800110::OutputComposeSurfacesTest::ExecuteState3032 auto execute() {
3033 getInstance()->mReadyFence =
3034 getInstance()->mOutput.composeSurfaces(kDebugRegion, kDefaultRefreshArgs);
3035 return nextState<FenceCheckState>();
3036 }
3037 };
3038
3039 struct FenceCheckState : public CallOrderStateMachineHelper<TestType, FenceCheckState> {
expectNoFenceWasReturnedandroid::compositionengine::__anon470a6e800110::OutputComposeSurfacesTest::FenceCheckState3040 void expectNoFenceWasReturned() { EXPECT_FALSE(getInstance()->mReadyFence); }
3041
expectAFenceWasReturnedandroid::compositionengine::__anon470a6e800110::OutputComposeSurfacesTest::FenceCheckState3042 void expectAFenceWasReturned() { EXPECT_TRUE(getInstance()->mReadyFence); }
3043 };
3044
3045 // Call this member function to start using the mini-DSL defined above.
verifyandroid::compositionengine::__anon470a6e800110::OutputComposeSurfacesTest3046 [[nodiscard]] auto verify() { return ExecuteState::make(this); }
3047
3048 static constexpr ui::Rotation kDefaultOutputOrientation = ui::ROTATION_0;
3049 static constexpr uint32_t kDefaultOutputOrientationFlags =
3050 ui::Transform::toRotationFlags(kDefaultOutputOrientation);
3051 static constexpr ui::Dataspace kDefaultOutputDataspace = ui::Dataspace::UNKNOWN;
3052 static constexpr ui::Dataspace kExpensiveOutputDataspace = ui::Dataspace::DISPLAY_P3;
3053 static constexpr float kDefaultMaxLuminance = 0.9f;
3054 static constexpr float kDefaultAvgLuminance = 0.7f;
3055 static constexpr float kDefaultMinLuminance = 0.1f;
3056
3057 static const Rect kDefaultOutputFrame;
3058 static const Rect kDefaultOutputViewport;
3059 static const Rect kDefaultOutputDestinationClip;
3060 static const mat4 kDefaultColorTransformMat;
3061
3062 static const Region kDebugRegion;
3063 static const compositionengine::CompositionRefreshArgs kDefaultRefreshArgs;
3064 static const HdrCapabilities kHdrCapabilities;
3065
3066 StrictMock<mock::CompositionEngine> mCompositionEngine;
3067 StrictMock<renderengine::mock::RenderEngine> mRenderEngine;
3068 // TODO: make this is a proper mock.
3069 std::shared_ptr<TimeStats> mTimeStats = std::make_shared<android::impl::TimeStats>();
3070 mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>();
3071 mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>();
3072 StrictMock<OutputPartialMock> mOutput;
3073 std::shared_ptr<renderengine::ExternalTexture> mOutputBuffer = std::make_shared<
3074 renderengine::ExternalTexture>(new GraphicBuffer(), mRenderEngine,
3075 renderengine::ExternalTexture::Usage::READABLE |
3076 renderengine::ExternalTexture::Usage::WRITEABLE);
3077
3078 std::optional<base::unique_fd> mReadyFence;
3079 };
3080
3081 const Rect OutputComposeSurfacesTest::kDefaultOutputFrame{1001, 1002, 1003, 1004};
3082 const Rect OutputComposeSurfacesTest::kDefaultOutputViewport{1005, 1006, 1007, 1008};
3083 const Rect OutputComposeSurfacesTest::kDefaultOutputDestinationClip{1013, 1014, 1015, 1016};
3084 const mat4 OutputComposeSurfacesTest::kDefaultColorTransformMat{mat4() * 0.5f};
3085 const compositionengine::CompositionRefreshArgs OutputComposeSurfacesTest::kDefaultRefreshArgs;
3086 const Region OutputComposeSurfacesTest::kDebugRegion{Rect{100, 101, 102, 103}};
3087 const HdrCapabilities OutputComposeSurfacesTest::
3088 kHdrCapabilities{{},
3089 OutputComposeSurfacesTest::kDefaultMaxLuminance,
3090 OutputComposeSurfacesTest::kDefaultAvgLuminance,
3091 OutputComposeSurfacesTest::kDefaultMinLuminance};
3092
TEST_F(OutputComposeSurfacesTest,doesNothingButSignalNoExpensiveRenderingIfNoClientComposition)3093 TEST_F(OutputComposeSurfacesTest, doesNothingButSignalNoExpensiveRenderingIfNoClientComposition) {
3094 mOutput.mState.usesClientComposition = false;
3095
3096 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false));
3097 EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false));
3098
3099 EXPECT_CALL(mOutput, setExpensiveRenderingExpected(false));
3100
3101 verify().execute().expectAFenceWasReturned();
3102 }
3103
TEST_F(OutputComposeSurfacesTest,dequeuesABufferIfNoClientCompositionButFlipClientTargetRequested)3104 TEST_F(OutputComposeSurfacesTest,
3105 dequeuesABufferIfNoClientCompositionButFlipClientTargetRequested) {
3106 mOutput.mState.usesClientComposition = false;
3107 mOutput.mState.flipClientTarget = true;
3108
3109 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false));
3110 EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false));
3111
3112 EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillOnce(Return(mOutputBuffer));
3113 EXPECT_CALL(mOutput, setExpensiveRenderingExpected(false));
3114
3115 verify().execute().expectAFenceWasReturned();
3116 }
3117
TEST_F(OutputComposeSurfacesTest,doesMinimalWorkIfDequeueBufferFailsForClientComposition)3118 TEST_F(OutputComposeSurfacesTest, doesMinimalWorkIfDequeueBufferFailsForClientComposition) {
3119 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false));
3120 EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false));
3121
3122 EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillOnce(Return(nullptr));
3123
3124 verify().execute().expectNoFenceWasReturned();
3125 }
3126
TEST_F(OutputComposeSurfacesTest,doesMinimalWorkIfDequeueBufferFailsForNoClientCompositionButFlipClientTargetRequested)3127 TEST_F(OutputComposeSurfacesTest,
3128 doesMinimalWorkIfDequeueBufferFailsForNoClientCompositionButFlipClientTargetRequested) {
3129 mOutput.mState.usesClientComposition = false;
3130 mOutput.mState.flipClientTarget = true;
3131
3132 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false));
3133 EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false));
3134
3135 EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillOnce(Return(nullptr));
3136
3137 verify().execute().expectNoFenceWasReturned();
3138 }
3139
TEST_F(OutputComposeSurfacesTest,handlesZeroCompositionRequests)3140 TEST_F(OutputComposeSurfacesTest, handlesZeroCompositionRequests) {
3141 EXPECT_CALL(mOutput, getSkipColorTransform()).WillRepeatedly(Return(false));
3142 EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillRepeatedly(Return(true));
3143 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false));
3144 EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false));
3145 EXPECT_CALL(mOutput, generateClientCompositionRequests(_, _, kDefaultOutputDataspace))
3146 .WillRepeatedly(Return(std::vector<LayerFE::LayerSettings>{}));
3147 EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _))
3148 .WillRepeatedly(Return());
3149
3150 EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer));
3151 EXPECT_CALL(mRenderEngine, drawLayers(_, IsEmpty(), _, false, _, _))
3152 .WillRepeatedly(Return(NO_ERROR));
3153
3154 verify().execute().expectAFenceWasReturned();
3155 }
3156
TEST_F(OutputComposeSurfacesTest,buildsAndRendersRequestList)3157 TEST_F(OutputComposeSurfacesTest, buildsAndRendersRequestList) {
3158 LayerFE::LayerSettings r1;
3159 LayerFE::LayerSettings r2;
3160
3161 r1.geometry.boundaries = FloatRect{1, 2, 3, 4};
3162 r2.geometry.boundaries = FloatRect{5, 6, 7, 8};
3163
3164 EXPECT_CALL(mOutput, getSkipColorTransform()).WillRepeatedly(Return(false));
3165 EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillRepeatedly(Return(true));
3166 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false));
3167 EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false));
3168 EXPECT_CALL(mOutput, generateClientCompositionRequests(_, _, kDefaultOutputDataspace))
3169 .WillRepeatedly(Return(std::vector<LayerFE::LayerSettings>{r1}));
3170 EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _))
3171 .WillRepeatedly(
3172 Invoke([&](const Region&,
3173 std::vector<LayerFE::LayerSettings>& clientCompositionLayers) {
3174 clientCompositionLayers.emplace_back(r2);
3175 }));
3176
3177 EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer));
3178 EXPECT_CALL(mRenderEngine, drawLayers(_, ElementsAre(Pointee(r1), Pointee(r2)), _, false, _, _))
3179 .WillRepeatedly(Return(NO_ERROR));
3180
3181 verify().execute().expectAFenceWasReturned();
3182 }
3183
TEST_F(OutputComposeSurfacesTest,buildsAndRendersRequestListAndCachesFramebufferForInternalLayers)3184 TEST_F(OutputComposeSurfacesTest,
3185 buildsAndRendersRequestListAndCachesFramebufferForInternalLayers) {
3186 LayerFE::LayerSettings r1;
3187 LayerFE::LayerSettings r2;
3188
3189 r1.geometry.boundaries = FloatRect{1, 2, 3, 4};
3190 r2.geometry.boundaries = FloatRect{5, 6, 7, 8};
3191 const constexpr uint32_t kInternalLayerStack = 1234;
3192 mOutput.setLayerStackFilter(kInternalLayerStack, true);
3193
3194 EXPECT_CALL(mOutput, getSkipColorTransform()).WillRepeatedly(Return(false));
3195 EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillRepeatedly(Return(true));
3196 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false));
3197 EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false));
3198 EXPECT_CALL(mOutput, generateClientCompositionRequests(_, _, kDefaultOutputDataspace))
3199 .WillRepeatedly(Return(std::vector<LayerFE::LayerSettings>{r1}));
3200 EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _))
3201 .WillRepeatedly(
3202 Invoke([&](const Region&,
3203 std::vector<LayerFE::LayerSettings>& clientCompositionLayers) {
3204 clientCompositionLayers.emplace_back(r2);
3205 }));
3206
3207 EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer));
3208 EXPECT_CALL(mRenderEngine, drawLayers(_, ElementsAre(Pointee(r1), Pointee(r2)), _, true, _, _))
3209 .WillRepeatedly(Return(NO_ERROR));
3210
3211 verify().execute().expectAFenceWasReturned();
3212 }
3213
TEST_F(OutputComposeSurfacesTest,renderDuplicateClientCompositionRequestsWithoutCache)3214 TEST_F(OutputComposeSurfacesTest, renderDuplicateClientCompositionRequestsWithoutCache) {
3215 mOutput.cacheClientCompositionRequests(0);
3216 LayerFE::LayerSettings r1;
3217 LayerFE::LayerSettings r2;
3218
3219 r1.geometry.boundaries = FloatRect{1, 2, 3, 4};
3220 r2.geometry.boundaries = FloatRect{5, 6, 7, 8};
3221
3222 EXPECT_CALL(mOutput, getSkipColorTransform()).WillRepeatedly(Return(false));
3223 EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillRepeatedly(Return(true));
3224 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false));
3225 EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false));
3226 EXPECT_CALL(mOutput, generateClientCompositionRequests(_, _, kDefaultOutputDataspace))
3227 .WillRepeatedly(Return(std::vector<LayerFE::LayerSettings>{r1, r2}));
3228 EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _))
3229 .WillRepeatedly(Return());
3230
3231 EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer));
3232 EXPECT_CALL(mRenderEngine, drawLayers(_, ElementsAre(Pointee(r1), Pointee(r2)), _, false, _, _))
3233 .Times(2)
3234 .WillOnce(Return(NO_ERROR));
3235
3236 verify().execute().expectAFenceWasReturned();
3237 EXPECT_FALSE(mOutput.mState.reusedClientComposition);
3238
3239 verify().execute().expectAFenceWasReturned();
3240 EXPECT_FALSE(mOutput.mState.reusedClientComposition);
3241 }
3242
TEST_F(OutputComposeSurfacesTest,skipDuplicateClientCompositionRequests)3243 TEST_F(OutputComposeSurfacesTest, skipDuplicateClientCompositionRequests) {
3244 mOutput.cacheClientCompositionRequests(3);
3245 LayerFE::LayerSettings r1;
3246 LayerFE::LayerSettings r2;
3247
3248 r1.geometry.boundaries = FloatRect{1, 2, 3, 4};
3249 r2.geometry.boundaries = FloatRect{5, 6, 7, 8};
3250
3251 EXPECT_CALL(mOutput, getSkipColorTransform()).WillRepeatedly(Return(false));
3252 EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillRepeatedly(Return(true));
3253 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false));
3254 EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false));
3255 EXPECT_CALL(mOutput, generateClientCompositionRequests(_, _, kDefaultOutputDataspace))
3256 .WillRepeatedly(Return(std::vector<LayerFE::LayerSettings>{r1, r2}));
3257 EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _))
3258 .WillRepeatedly(Return());
3259
3260 EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer));
3261 EXPECT_CALL(mRenderEngine, drawLayers(_, ElementsAre(Pointee(r1), Pointee(r2)), _, false, _, _))
3262 .WillOnce(Return(NO_ERROR));
3263 EXPECT_CALL(mOutput, setExpensiveRenderingExpected(false));
3264
3265 verify().execute().expectAFenceWasReturned();
3266 EXPECT_FALSE(mOutput.mState.reusedClientComposition);
3267
3268 // We do not expect another call to draw layers.
3269 verify().execute().expectAFenceWasReturned();
3270 EXPECT_TRUE(mOutput.mState.reusedClientComposition);
3271 }
3272
TEST_F(OutputComposeSurfacesTest,clientCompositionIfBufferChanges)3273 TEST_F(OutputComposeSurfacesTest, clientCompositionIfBufferChanges) {
3274 LayerFE::LayerSettings r1;
3275 LayerFE::LayerSettings r2;
3276
3277 r1.geometry.boundaries = FloatRect{1, 2, 3, 4};
3278 r2.geometry.boundaries = FloatRect{5, 6, 7, 8};
3279
3280 EXPECT_CALL(mOutput, getSkipColorTransform()).WillRepeatedly(Return(false));
3281 EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillRepeatedly(Return(true));
3282 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false));
3283 EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false));
3284 EXPECT_CALL(mOutput, generateClientCompositionRequests(_, _, kDefaultOutputDataspace))
3285 .WillRepeatedly(Return(std::vector<LayerFE::LayerSettings>{r1, r2}));
3286 EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _))
3287 .WillRepeatedly(Return());
3288
3289 const auto otherOutputBuffer = std::make_shared<
3290 renderengine::ExternalTexture>(new GraphicBuffer(), mRenderEngine,
3291 renderengine::ExternalTexture::Usage::READABLE |
3292 renderengine::ExternalTexture::Usage::WRITEABLE);
3293 EXPECT_CALL(*mRenderSurface, dequeueBuffer(_))
3294 .WillOnce(Return(mOutputBuffer))
3295 .WillOnce(Return(otherOutputBuffer));
3296 EXPECT_CALL(mRenderEngine, drawLayers(_, ElementsAre(Pointee(r1), Pointee(r2)), _, false, _, _))
3297 .WillRepeatedly(Return(NO_ERROR));
3298
3299 verify().execute().expectAFenceWasReturned();
3300 EXPECT_FALSE(mOutput.mState.reusedClientComposition);
3301
3302 verify().execute().expectAFenceWasReturned();
3303 EXPECT_FALSE(mOutput.mState.reusedClientComposition);
3304 }
3305
TEST_F(OutputComposeSurfacesTest,clientCompositionIfRequestChanges)3306 TEST_F(OutputComposeSurfacesTest, clientCompositionIfRequestChanges) {
3307 LayerFE::LayerSettings r1;
3308 LayerFE::LayerSettings r2;
3309 LayerFE::LayerSettings r3;
3310
3311 r1.geometry.boundaries = FloatRect{1, 2, 3, 4};
3312 r2.geometry.boundaries = FloatRect{5, 6, 7, 8};
3313 r3.geometry.boundaries = FloatRect{5, 6, 7, 9};
3314
3315 EXPECT_CALL(mOutput, getSkipColorTransform()).WillRepeatedly(Return(false));
3316 EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillRepeatedly(Return(true));
3317 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false));
3318 EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false));
3319 EXPECT_CALL(mOutput, generateClientCompositionRequests(_, _, kDefaultOutputDataspace))
3320 .WillOnce(Return(std::vector<LayerFE::LayerSettings>{r1, r2}))
3321 .WillOnce(Return(std::vector<LayerFE::LayerSettings>{r1, r3}));
3322 EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _))
3323 .WillRepeatedly(Return());
3324
3325 EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer));
3326 EXPECT_CALL(mRenderEngine, drawLayers(_, ElementsAre(Pointee(r1), Pointee(r2)), _, false, _, _))
3327 .WillOnce(Return(NO_ERROR));
3328 EXPECT_CALL(mRenderEngine, drawLayers(_, ElementsAre(Pointee(r1), Pointee(r3)), _, false, _, _))
3329 .WillOnce(Return(NO_ERROR));
3330
3331 verify().execute().expectAFenceWasReturned();
3332 EXPECT_FALSE(mOutput.mState.reusedClientComposition);
3333
3334 verify().execute().expectAFenceWasReturned();
3335 EXPECT_FALSE(mOutput.mState.reusedClientComposition);
3336 }
3337
3338 struct OutputComposeSurfacesTest_UsesExpectedDisplaySettings : public OutputComposeSurfacesTest {
OutputComposeSurfacesTest_UsesExpectedDisplaySettingsandroid::compositionengine::__anon470a6e800110::OutputComposeSurfacesTest_UsesExpectedDisplaySettings3339 OutputComposeSurfacesTest_UsesExpectedDisplaySettings() {
3340 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false));
3341 EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false));
3342 EXPECT_CALL(mOutput, generateClientCompositionRequests(_, _, kDefaultOutputDataspace))
3343 .WillRepeatedly(Return(std::vector<LayerFE::LayerSettings>{}));
3344 EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _))
3345 .WillRepeatedly(Return());
3346 EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer));
3347 }
3348
3349 struct MixedCompositionState
3350 : public CallOrderStateMachineHelper<TestType, MixedCompositionState> {
ifMixedCompositionIsandroid::compositionengine::__anon470a6e800110::OutputComposeSurfacesTest_UsesExpectedDisplaySettings::MixedCompositionState3351 auto ifMixedCompositionIs(bool used) {
3352 getInstance()->mOutput.mState.usesDeviceComposition = used;
3353 return nextState<OutputUsesHdrState>();
3354 }
3355 };
3356
3357 struct OutputUsesHdrState : public CallOrderStateMachineHelper<TestType, OutputUsesHdrState> {
andIfUsesHdrandroid::compositionengine::__anon470a6e800110::OutputComposeSurfacesTest_UsesExpectedDisplaySettings::OutputUsesHdrState3358 auto andIfUsesHdr(bool used) {
3359 EXPECT_CALL(*getInstance()->mDisplayColorProfile, hasWideColorGamut())
3360 .WillOnce(Return(used));
3361 return nextState<SkipColorTransformState>();
3362 }
3363 };
3364
3365 struct SkipColorTransformState
3366 : public CallOrderStateMachineHelper<TestType, SkipColorTransformState> {
andIfSkipColorTransformandroid::compositionengine::__anon470a6e800110::OutputComposeSurfacesTest_UsesExpectedDisplaySettings::SkipColorTransformState3367 auto andIfSkipColorTransform(bool skip) {
3368 // May be called zero or one times.
3369 EXPECT_CALL(getInstance()->mOutput, getSkipColorTransform())
3370 .WillRepeatedly(Return(skip));
3371 return nextState<ExpectDisplaySettingsState>();
3372 }
3373 };
3374
3375 struct ExpectDisplaySettingsState
3376 : public CallOrderStateMachineHelper<TestType, ExpectDisplaySettingsState> {
thenExpectDisplaySettingsUsedandroid::compositionengine::__anon470a6e800110::OutputComposeSurfacesTest_UsesExpectedDisplaySettings::ExpectDisplaySettingsState3377 auto thenExpectDisplaySettingsUsed(renderengine::DisplaySettings settings) {
3378 EXPECT_CALL(getInstance()->mRenderEngine, drawLayers(settings, _, _, false, _, _))
3379 .WillOnce(Return(NO_ERROR));
3380 return nextState<ExecuteState>();
3381 }
3382 };
3383
3384 // Call this member function to start using the mini-DSL defined above.
verifyandroid::compositionengine::__anon470a6e800110::OutputComposeSurfacesTest_UsesExpectedDisplaySettings3385 [[nodiscard]] auto verify() { return MixedCompositionState::make(this); }
3386 };
3387
TEST_F(OutputComposeSurfacesTest_UsesExpectedDisplaySettings,forHdrMixedComposition)3388 TEST_F(OutputComposeSurfacesTest_UsesExpectedDisplaySettings, forHdrMixedComposition) {
3389 verify().ifMixedCompositionIs(true)
3390 .andIfUsesHdr(true)
3391 .andIfSkipColorTransform(false)
3392 .thenExpectDisplaySettingsUsed({kDefaultOutputDestinationClip, kDefaultOutputViewport,
3393 kDefaultMaxLuminance, kDefaultOutputDataspace, mat4(),
3394 Region::INVALID_REGION, kDefaultOutputOrientationFlags})
3395 .execute()
3396 .expectAFenceWasReturned();
3397 }
3398
TEST_F(OutputComposeSurfacesTest_UsesExpectedDisplaySettings,forNonHdrMixedComposition)3399 TEST_F(OutputComposeSurfacesTest_UsesExpectedDisplaySettings, forNonHdrMixedComposition) {
3400 verify().ifMixedCompositionIs(true)
3401 .andIfUsesHdr(false)
3402 .andIfSkipColorTransform(false)
3403 .thenExpectDisplaySettingsUsed({kDefaultOutputDestinationClip, kDefaultOutputViewport,
3404 kDefaultMaxLuminance, kDefaultOutputDataspace, mat4(),
3405 Region::INVALID_REGION, kDefaultOutputOrientationFlags})
3406 .execute()
3407 .expectAFenceWasReturned();
3408 }
3409
TEST_F(OutputComposeSurfacesTest_UsesExpectedDisplaySettings,forHdrOnlyClientComposition)3410 TEST_F(OutputComposeSurfacesTest_UsesExpectedDisplaySettings, forHdrOnlyClientComposition) {
3411 verify().ifMixedCompositionIs(false)
3412 .andIfUsesHdr(true)
3413 .andIfSkipColorTransform(false)
3414 .thenExpectDisplaySettingsUsed({kDefaultOutputDestinationClip, kDefaultOutputViewport,
3415 kDefaultMaxLuminance, kDefaultOutputDataspace,
3416 kDefaultColorTransformMat, Region::INVALID_REGION,
3417 kDefaultOutputOrientationFlags})
3418 .execute()
3419 .expectAFenceWasReturned();
3420 }
3421
TEST_F(OutputComposeSurfacesTest_UsesExpectedDisplaySettings,forNonHdrOnlyClientComposition)3422 TEST_F(OutputComposeSurfacesTest_UsesExpectedDisplaySettings, forNonHdrOnlyClientComposition) {
3423 verify().ifMixedCompositionIs(false)
3424 .andIfUsesHdr(false)
3425 .andIfSkipColorTransform(false)
3426 .thenExpectDisplaySettingsUsed({kDefaultOutputDestinationClip, kDefaultOutputViewport,
3427 kDefaultMaxLuminance, kDefaultOutputDataspace,
3428 kDefaultColorTransformMat, Region::INVALID_REGION,
3429 kDefaultOutputOrientationFlags})
3430 .execute()
3431 .expectAFenceWasReturned();
3432 }
3433
TEST_F(OutputComposeSurfacesTest_UsesExpectedDisplaySettings,usesExpectedDisplaySettingsForHdrOnlyClientCompositionWithSkipClientTransform)3434 TEST_F(OutputComposeSurfacesTest_UsesExpectedDisplaySettings,
3435 usesExpectedDisplaySettingsForHdrOnlyClientCompositionWithSkipClientTransform) {
3436 verify().ifMixedCompositionIs(false)
3437 .andIfUsesHdr(true)
3438 .andIfSkipColorTransform(true)
3439 .thenExpectDisplaySettingsUsed({kDefaultOutputDestinationClip, kDefaultOutputViewport,
3440 kDefaultMaxLuminance, kDefaultOutputDataspace, mat4(),
3441 Region::INVALID_REGION, kDefaultOutputOrientationFlags})
3442 .execute()
3443 .expectAFenceWasReturned();
3444 }
3445
3446 struct OutputComposeSurfacesTest_HandlesProtectedContent : public OutputComposeSurfacesTest {
3447 struct Layer {
Layerandroid::compositionengine::__anon470a6e800110::OutputComposeSurfacesTest_HandlesProtectedContent::Layer3448 Layer() {
3449 EXPECT_CALL(*mLayerFE, getCompositionState()).WillRepeatedly(Return(&mLayerFEState));
3450 EXPECT_CALL(mOutputLayer, getLayerFE()).WillRepeatedly(ReturnRef(*mLayerFE));
3451 }
3452
3453 StrictMock<mock::OutputLayer> mOutputLayer;
3454 sp<StrictMock<mock::LayerFE>> mLayerFE = sp<StrictMock<mock::LayerFE>>::make();
3455 LayerFECompositionState mLayerFEState;
3456 };
3457
OutputComposeSurfacesTest_HandlesProtectedContentandroid::compositionengine::__anon470a6e800110::OutputComposeSurfacesTest_HandlesProtectedContent3458 OutputComposeSurfacesTest_HandlesProtectedContent() {
3459 mLayer1.mLayerFEState.hasProtectedContent = false;
3460 mLayer2.mLayerFEState.hasProtectedContent = false;
3461
3462 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(2u));
3463 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0u))
3464 .WillRepeatedly(Return(&mLayer1.mOutputLayer));
3465 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(1u))
3466 .WillRepeatedly(Return(&mLayer2.mOutputLayer));
3467
3468 EXPECT_CALL(mOutput, getSkipColorTransform()).WillRepeatedly(Return(false));
3469
3470 EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillRepeatedly(Return(true));
3471
3472 EXPECT_CALL(mOutput, generateClientCompositionRequests(_, _, _))
3473 .WillRepeatedly(Return(std::vector<LayerFE::LayerSettings>{}));
3474 EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _))
3475 .WillRepeatedly(Return());
3476 EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer));
3477 EXPECT_CALL(mRenderEngine, drawLayers(_, _, _, false, _, _))
3478 .WillRepeatedly(Return(NO_ERROR));
3479 }
3480
3481 Layer mLayer1;
3482 Layer mLayer2;
3483 };
3484
TEST_F(OutputComposeSurfacesTest_HandlesProtectedContent,ifDisplayIsNotSecure)3485 TEST_F(OutputComposeSurfacesTest_HandlesProtectedContent, ifDisplayIsNotSecure) {
3486 mOutput.mState.isSecure = false;
3487 mLayer2.mLayerFEState.hasProtectedContent = true;
3488 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(true));
3489 EXPECT_CALL(mRenderEngine, isProtected).WillOnce(Return(true));
3490 EXPECT_CALL(mRenderEngine, useProtectedContext(false));
3491
3492 mOutput.composeSurfaces(kDebugRegion, kDefaultRefreshArgs);
3493 }
3494
TEST_F(OutputComposeSurfacesTest_HandlesProtectedContent,ifRenderEngineDoesNotSupportIt)3495 TEST_F(OutputComposeSurfacesTest_HandlesProtectedContent, ifRenderEngineDoesNotSupportIt) {
3496 mOutput.mState.isSecure = true;
3497 mLayer2.mLayerFEState.hasProtectedContent = true;
3498 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false));
3499
3500 mOutput.composeSurfaces(kDebugRegion, kDefaultRefreshArgs);
3501 }
3502
TEST_F(OutputComposeSurfacesTest_HandlesProtectedContent,ifNoProtectedContentLayers)3503 TEST_F(OutputComposeSurfacesTest_HandlesProtectedContent, ifNoProtectedContentLayers) {
3504 mOutput.mState.isSecure = true;
3505 mLayer2.mLayerFEState.hasProtectedContent = false;
3506 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(true));
3507 EXPECT_CALL(mRenderEngine, isProtected).WillOnce(Return(true)).WillOnce(Return(false));
3508 EXPECT_CALL(*mRenderSurface, isProtected).WillOnce(Return(true));
3509 EXPECT_CALL(mRenderEngine, useProtectedContext(false));
3510 EXPECT_CALL(*mRenderSurface, setProtected(false));
3511
3512 mOutput.composeSurfaces(kDebugRegion, kDefaultRefreshArgs);
3513 }
3514
TEST_F(OutputComposeSurfacesTest_HandlesProtectedContent,ifNotEnabled)3515 TEST_F(OutputComposeSurfacesTest_HandlesProtectedContent, ifNotEnabled) {
3516 mOutput.mState.isSecure = true;
3517 mLayer2.mLayerFEState.hasProtectedContent = true;
3518 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(true));
3519
3520 // For this test, we also check the call order of key functions.
3521 InSequence seq;
3522
3523 EXPECT_CALL(mRenderEngine, isProtected).WillOnce(Return(false));
3524 EXPECT_CALL(mRenderEngine, useProtectedContext(true));
3525 EXPECT_CALL(*mRenderSurface, isProtected).WillOnce(Return(false));
3526 EXPECT_CALL(mRenderEngine, isProtected).WillOnce(Return(true));
3527 EXPECT_CALL(*mRenderSurface, setProtected(true));
3528 // Must happen after setting the protected content state.
3529 EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer));
3530 EXPECT_CALL(mRenderEngine, drawLayers(_, _, _, false, _, _)).WillOnce(Return(NO_ERROR));
3531
3532 mOutput.composeSurfaces(kDebugRegion, kDefaultRefreshArgs);
3533 }
3534
TEST_F(OutputComposeSurfacesTest_HandlesProtectedContent,ifAlreadyEnabledEverywhere)3535 TEST_F(OutputComposeSurfacesTest_HandlesProtectedContent, ifAlreadyEnabledEverywhere) {
3536 mOutput.mState.isSecure = true;
3537 mLayer2.mLayerFEState.hasProtectedContent = true;
3538 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(true));
3539 EXPECT_CALL(mRenderEngine, isProtected).WillOnce(Return(true));
3540 EXPECT_CALL(*mRenderSurface, isProtected).WillOnce(Return(true));
3541
3542 mOutput.composeSurfaces(kDebugRegion, kDefaultRefreshArgs);
3543 }
3544
TEST_F(OutputComposeSurfacesTest_HandlesProtectedContent,ifFailsToEnableInRenderEngine)3545 TEST_F(OutputComposeSurfacesTest_HandlesProtectedContent, ifFailsToEnableInRenderEngine) {
3546 mOutput.mState.isSecure = true;
3547 mLayer2.mLayerFEState.hasProtectedContent = true;
3548 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(true));
3549 EXPECT_CALL(mRenderEngine, isProtected).WillOnce(Return(false)).WillOnce(Return(false));
3550 EXPECT_CALL(*mRenderSurface, isProtected).WillOnce(Return(false));
3551 EXPECT_CALL(mRenderEngine, useProtectedContext(true));
3552
3553 mOutput.composeSurfaces(kDebugRegion, kDefaultRefreshArgs);
3554 }
3555
TEST_F(OutputComposeSurfacesTest_HandlesProtectedContent,ifAlreadyEnabledInRenderEngine)3556 TEST_F(OutputComposeSurfacesTest_HandlesProtectedContent, ifAlreadyEnabledInRenderEngine) {
3557 mOutput.mState.isSecure = true;
3558 mLayer2.mLayerFEState.hasProtectedContent = true;
3559 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(true));
3560 EXPECT_CALL(mRenderEngine, isProtected).WillOnce(Return(true)).WillOnce(Return(true));
3561 EXPECT_CALL(*mRenderSurface, isProtected).WillOnce(Return(false));
3562 EXPECT_CALL(*mRenderSurface, setProtected(true));
3563
3564 mOutput.composeSurfaces(kDebugRegion, kDefaultRefreshArgs);
3565 }
3566
TEST_F(OutputComposeSurfacesTest_HandlesProtectedContent,ifAlreadyEnabledInRenderSurface)3567 TEST_F(OutputComposeSurfacesTest_HandlesProtectedContent, ifAlreadyEnabledInRenderSurface) {
3568 mOutput.mState.isSecure = true;
3569 mLayer2.mLayerFEState.hasProtectedContent = true;
3570 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(true));
3571 EXPECT_CALL(mRenderEngine, isProtected).WillOnce(Return(false));
3572 EXPECT_CALL(*mRenderSurface, isProtected).WillOnce(Return(true));
3573 EXPECT_CALL(mRenderEngine, useProtectedContext(true));
3574
3575 mOutput.composeSurfaces(kDebugRegion, kDefaultRefreshArgs);
3576 }
3577
3578 struct OutputComposeSurfacesTest_SetsExpensiveRendering : public OutputComposeSurfacesTest {
OutputComposeSurfacesTest_SetsExpensiveRenderingandroid::compositionengine::__anon470a6e800110::OutputComposeSurfacesTest_SetsExpensiveRendering3579 OutputComposeSurfacesTest_SetsExpensiveRendering() {
3580 EXPECT_CALL(mOutput, getSkipColorTransform()).WillRepeatedly(Return(false));
3581 EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillRepeatedly(Return(true));
3582 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false));
3583 EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false));
3584 EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _))
3585 .WillRepeatedly(Return());
3586 EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer));
3587 }
3588 };
3589
TEST_F(OutputComposeSurfacesTest_SetsExpensiveRendering,IfExepensiveOutputDataspaceIsUsed)3590 TEST_F(OutputComposeSurfacesTest_SetsExpensiveRendering, IfExepensiveOutputDataspaceIsUsed) {
3591 mOutput.mState.dataspace = kExpensiveOutputDataspace;
3592
3593 EXPECT_CALL(mOutput, generateClientCompositionRequests(_, _, kExpensiveOutputDataspace))
3594 .WillOnce(Return(std::vector<LayerFE::LayerSettings>{}));
3595
3596 // For this test, we also check the call order of key functions.
3597 InSequence seq;
3598
3599 EXPECT_CALL(mOutput, setExpensiveRenderingExpected(true));
3600 EXPECT_CALL(mRenderEngine, drawLayers(_, _, _, false, _, _)).WillOnce(Return(NO_ERROR));
3601
3602 mOutput.composeSurfaces(kDebugRegion, kDefaultRefreshArgs);
3603 }
3604
3605 struct OutputComposeSurfacesTest_SetsExpensiveRendering_ForBlur
3606 : public OutputComposeSurfacesTest_SetsExpensiveRendering {
OutputComposeSurfacesTest_SetsExpensiveRendering_ForBlurandroid::compositionengine::__anon470a6e800110::OutputComposeSurfacesTest_SetsExpensiveRendering_ForBlur3607 OutputComposeSurfacesTest_SetsExpensiveRendering_ForBlur() {
3608 mLayer.layerFEState.backgroundBlurRadius = 10;
3609 mLayer.layerFEState.isOpaque = false;
3610 mOutput.editState().isEnabled = true;
3611
3612 EXPECT_CALL(mLayer.outputLayer, updateCompositionState(false, true, ui::Transform::ROT_0));
3613 EXPECT_CALL(mLayer.outputLayer,
3614 writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, 0,
3615 /*zIsOverridden*/ false, /*isPeekingThrough*/ false));
3616 EXPECT_CALL(mOutput, generateClientCompositionRequests(_, _, kDefaultOutputDataspace))
3617 .WillOnce(Return(std::vector<LayerFE::LayerSettings>{}));
3618 EXPECT_CALL(mRenderEngine, drawLayers(_, _, _, false, _, _)).WillOnce(Return(NO_ERROR));
3619 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(1u));
3620 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0u))
3621 .WillRepeatedly(Return(&mLayer.outputLayer));
3622 }
3623
3624 NonInjectedLayer mLayer;
3625 compositionengine::CompositionRefreshArgs mRefreshArgs;
3626 };
3627
TEST_F(OutputComposeSurfacesTest_SetsExpensiveRendering_ForBlur,IfBlursAreExpensive)3628 TEST_F(OutputComposeSurfacesTest_SetsExpensiveRendering_ForBlur, IfBlursAreExpensive) {
3629 mRefreshArgs.blursAreExpensive = true;
3630 mOutput.updateCompositionState(mRefreshArgs);
3631 mOutput.planComposition();
3632 mOutput.writeCompositionState(mRefreshArgs);
3633
3634 EXPECT_CALL(mOutput, setExpensiveRenderingExpected(true));
3635 mOutput.composeSurfaces(kDebugRegion, mRefreshArgs);
3636 }
3637
TEST_F(OutputComposeSurfacesTest_SetsExpensiveRendering_ForBlur,IfBlursAreNotExpensive)3638 TEST_F(OutputComposeSurfacesTest_SetsExpensiveRendering_ForBlur, IfBlursAreNotExpensive) {
3639 mRefreshArgs.blursAreExpensive = false;
3640 mOutput.updateCompositionState(mRefreshArgs);
3641 mOutput.planComposition();
3642 mOutput.writeCompositionState(mRefreshArgs);
3643
3644 EXPECT_CALL(mOutput, setExpensiveRenderingExpected(true)).Times(0);
3645 mOutput.composeSurfaces(kDebugRegion, mRefreshArgs);
3646 }
3647
3648 /*
3649 * Output::generateClientCompositionRequests()
3650 */
3651
3652 struct GenerateClientCompositionRequestsTest : public testing::Test {
3653 struct OutputPartialMock : public OutputPartialMockBase {
3654 // compositionengine::Output overrides
generateClientCompositionRequestsandroid::compositionengine::__anon470a6e800110::GenerateClientCompositionRequestsTest::OutputPartialMock3655 std::vector<LayerFE::LayerSettings> generateClientCompositionRequests(
3656 bool supportsProtectedContent, Region& clearRegion,
3657 ui::Dataspace dataspace) override {
3658 return impl::Output::generateClientCompositionRequests(supportsProtectedContent,
3659 clearRegion, dataspace);
3660 }
3661 };
3662
3663 struct Layer {
Layerandroid::compositionengine::__anon470a6e800110::GenerateClientCompositionRequestsTest::Layer3664 Layer() {
3665 EXPECT_CALL(mOutputLayer, getState()).WillRepeatedly(ReturnRef(mOutputLayerState));
3666 EXPECT_CALL(mOutputLayer, editState()).WillRepeatedly(ReturnRef(mOutputLayerState));
3667 EXPECT_CALL(mOutputLayer, getLayerFE()).WillRepeatedly(ReturnRef(*mLayerFE));
3668 EXPECT_CALL(*mLayerFE, getCompositionState()).WillRepeatedly(Return(&mLayerFEState));
3669 }
3670
3671 StrictMock<mock::OutputLayer> mOutputLayer;
3672 sp<StrictMock<mock::LayerFE>> mLayerFE = sp<StrictMock<mock::LayerFE>>::make();
3673 LayerFECompositionState mLayerFEState;
3674 impl::OutputLayerCompositionState mOutputLayerState;
3675 LayerFE::LayerSettings mLayerSettings;
3676 };
3677
GenerateClientCompositionRequestsTestandroid::compositionengine::__anon470a6e800110::GenerateClientCompositionRequestsTest3678 GenerateClientCompositionRequestsTest() {
3679 mOutput.mState.needsFiltering = false;
3680
3681 mOutput.setDisplayColorProfileForTest(
3682 std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile));
3683 mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
3684 }
3685
3686 mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>();
3687 mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>();
3688 StrictMock<OutputPartialMock> mOutput;
3689 };
3690
3691 struct GenerateClientCompositionRequestsTest_ThreeLayers
3692 : public GenerateClientCompositionRequestsTest {
GenerateClientCompositionRequestsTest_ThreeLayersandroid::compositionengine::__anon470a6e800110::GenerateClientCompositionRequestsTest_ThreeLayers3693 GenerateClientCompositionRequestsTest_ThreeLayers() {
3694 mOutput.mState.orientedDisplaySpace.content = kDisplayFrame;
3695 mOutput.mState.layerStackSpace.content = kDisplayViewport;
3696 mOutput.mState.displaySpace.content = kDisplayDestinationClip;
3697 mOutput.mState.transform =
3698 ui::Transform{ui::Transform::toRotationFlags(kDisplayOrientation)};
3699 mOutput.mState.displaySpace.orientation = kDisplayOrientation;
3700 mOutput.mState.needsFiltering = false;
3701 mOutput.mState.isSecure = false;
3702
3703 for (size_t i = 0; i < mLayers.size(); i++) {
3704 mLayers[i].mOutputLayerState.clearClientTarget = false;
3705 mLayers[i].mOutputLayerState.visibleRegion = Region(kDisplayFrame);
3706 mLayers[i].mLayerFEState.isOpaque = true;
3707 mLayers[i].mLayerSettings.geometry.boundaries =
3708 FloatRect{static_cast<float>(i + 1), 0.f, 0.f, 0.f};
3709 mLayers[i].mLayerSettings.source.solidColor = {1.0f, 1.0f, 1.0f};
3710 mLayers[i].mLayerSettings.alpha = 1.0f;
3711 mLayers[i].mLayerSettings.disableBlending = false;
3712
3713 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(i))
3714 .WillRepeatedly(Return(&mLayers[i].mOutputLayer));
3715 EXPECT_CALL(mLayers[i].mOutputLayer, requiresClientComposition())
3716 .WillRepeatedly(Return(true));
3717 EXPECT_CALL(mLayers[i].mOutputLayer, needsFiltering()).WillRepeatedly(Return(false));
3718 }
3719
3720 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(mLayers.size()));
3721 }
3722
3723 static constexpr ui::Rotation kDisplayOrientation = ui::ROTATION_0;
3724 static constexpr ui::Dataspace kDisplayDataspace = ui::Dataspace::UNKNOWN;
3725
3726 static const Rect kDisplayFrame;
3727 static const Rect kDisplayViewport;
3728 static const Rect kDisplayDestinationClip;
3729
3730 std::array<Layer, 3> mLayers;
3731 };
3732
3733 const Rect GenerateClientCompositionRequestsTest_ThreeLayers::kDisplayFrame(0, 0, 100, 200);
3734 const Rect GenerateClientCompositionRequestsTest_ThreeLayers::kDisplayViewport(0, 0, 101, 201);
3735 const Rect GenerateClientCompositionRequestsTest_ThreeLayers::kDisplayDestinationClip(0, 0, 103,
3736 203);
3737
TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers,handlesNoClientCompostionLayers)3738 TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers, handlesNoClientCompostionLayers) {
3739 EXPECT_CALL(mLayers[0].mOutputLayer, requiresClientComposition()).WillOnce(Return(false));
3740 EXPECT_CALL(mLayers[1].mOutputLayer, requiresClientComposition()).WillOnce(Return(false));
3741 EXPECT_CALL(mLayers[2].mOutputLayer, requiresClientComposition()).WillOnce(Return(false));
3742
3743 Region accumClearRegion(Rect(10, 11, 12, 13));
3744 auto requests = mOutput.generateClientCompositionRequests(false /* supportsProtectedContent */,
3745 accumClearRegion, kDisplayDataspace);
3746 EXPECT_EQ(0u, requests.size());
3747 EXPECT_THAT(accumClearRegion, RegionEq(Region(Rect(10, 11, 12, 13))));
3748 }
3749
TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers,requiresVisibleRegionAfterViewportClip)3750 TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers, requiresVisibleRegionAfterViewportClip) {
3751 mLayers[0].mOutputLayerState.visibleRegion = Region(Rect(10, 10, 10, 10));
3752 mLayers[1].mOutputLayerState.visibleRegion = Region(Rect(4000, 0, 4010, 10));
3753 mLayers[2].mOutputLayerState.visibleRegion = Region(Rect(-10, -10, 0, 0));
3754
3755 Region accumClearRegion(Rect(10, 11, 12, 13));
3756 auto requests = mOutput.generateClientCompositionRequests(false /* supportsProtectedContent */,
3757 accumClearRegion, kDisplayDataspace);
3758 EXPECT_EQ(0u, requests.size());
3759 EXPECT_THAT(accumClearRegion, RegionEq(Region(Rect(10, 11, 12, 13))));
3760 }
3761
TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers,gathersClientCompositionRequests)3762 TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers, gathersClientCompositionRequests) {
3763 LayerFE::LayerSettings mShadowSettings;
3764 mShadowSettings.source.solidColor = {0.1f, 0.1f, 0.1f};
3765
3766 EXPECT_CALL(*mLayers[0].mLayerFE, prepareClientCompositionList(_))
3767 .WillOnce(Return(std::vector<LayerFE::LayerSettings>()));
3768 EXPECT_CALL(*mLayers[1].mLayerFE, prepareClientCompositionList(_))
3769 .WillOnce(Return(std::vector<LayerFE::LayerSettings>({mLayers[1].mLayerSettings})));
3770 EXPECT_CALL(*mLayers[2].mLayerFE, prepareClientCompositionList(_))
3771 .WillOnce(Return(std::vector<LayerFE::LayerSettings>(
3772 {mShadowSettings, mLayers[2].mLayerSettings})));
3773
3774 Region accumClearRegion(Rect(10, 11, 12, 13));
3775 auto requests = mOutput.generateClientCompositionRequests(false /* supportsProtectedContent */,
3776 accumClearRegion, kDisplayDataspace);
3777 ASSERT_EQ(3u, requests.size());
3778 EXPECT_EQ(mLayers[1].mLayerSettings, requests[0]);
3779 EXPECT_EQ(mShadowSettings, requests[1]);
3780 EXPECT_EQ(mLayers[2].mLayerSettings, requests[2]);
3781
3782 EXPECT_THAT(accumClearRegion, RegionEq(Region(Rect(10, 11, 12, 13))));
3783
3784 // Check that a timestamp was set for the layers that generated requests
3785 EXPECT_TRUE(0 == mLayers[0].mOutputLayerState.clientCompositionTimestamp);
3786 EXPECT_TRUE(0 != mLayers[1].mOutputLayerState.clientCompositionTimestamp);
3787 EXPECT_TRUE(0 != mLayers[2].mOutputLayerState.clientCompositionTimestamp);
3788 }
3789
3790 MATCHER_P(ClientCompositionTargetSettingsBlurSettingsEq, expectedBlurSetting, "") {
3791 *result_listener << "ClientCompositionTargetSettings' BlurSettings aren't equal \n";
3792 *result_listener << "expected " << expectedBlurSetting << "\n";
3793 *result_listener << "actual " << arg.blurSetting << "\n";
3794
3795 return expectedBlurSetting == arg.blurSetting;
3796 }
3797
TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers,overridesBlur)3798 TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers, overridesBlur) {
3799 LayerFE::LayerSettings mShadowSettings;
3800 mShadowSettings.source.solidColor = {0.1f, 0.1f, 0.1f};
3801
3802 mLayers[2].mOutputLayerState.overrideInfo.disableBackgroundBlur = true;
3803
3804 EXPECT_CALL(*mLayers[0].mLayerFE, prepareClientCompositionList(_))
3805 .WillOnce(Return(std::vector<LayerFE::LayerSettings>()));
3806 EXPECT_CALL(*mLayers[1].mLayerFE, prepareClientCompositionList(_))
3807 .WillOnce(Return(std::vector<LayerFE::LayerSettings>({mLayers[1].mLayerSettings})));
3808 EXPECT_CALL(*mLayers[2].mLayerFE,
3809 prepareClientCompositionList(ClientCompositionTargetSettingsBlurSettingsEq(
3810 LayerFE::ClientCompositionTargetSettings::BlurSetting::BlurRegionsOnly)))
3811 .WillOnce(Return(std::vector<LayerFE::LayerSettings>(
3812 {mShadowSettings, mLayers[2].mLayerSettings})));
3813
3814 Region accumClearRegion(Rect(10, 11, 12, 13));
3815 auto requests = mOutput.generateClientCompositionRequests(false /* supportsProtectedContent */,
3816 accumClearRegion, kDisplayDataspace);
3817 ASSERT_EQ(3u, requests.size());
3818 EXPECT_EQ(mLayers[1].mLayerSettings, requests[0]);
3819 EXPECT_EQ(mShadowSettings, requests[1]);
3820 EXPECT_EQ(mLayers[2].mLayerSettings, requests[2]);
3821
3822 EXPECT_THAT(accumClearRegion, RegionEq(Region(Rect(10, 11, 12, 13))));
3823
3824 // Check that a timestamp was set for the layers that generated requests
3825 EXPECT_TRUE(0 == mLayers[0].mOutputLayerState.clientCompositionTimestamp);
3826 EXPECT_TRUE(0 != mLayers[1].mOutputLayerState.clientCompositionTimestamp);
3827 EXPECT_TRUE(0 != mLayers[2].mOutputLayerState.clientCompositionTimestamp);
3828 }
3829
TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers,onlyClientComposesClientComposedLayersIfNoClearingNeeded)3830 TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers,
3831 onlyClientComposesClientComposedLayersIfNoClearingNeeded) {
3832 EXPECT_CALL(mLayers[0].mOutputLayer, requiresClientComposition()).WillOnce(Return(false));
3833 EXPECT_CALL(mLayers[1].mOutputLayer, requiresClientComposition()).WillOnce(Return(false));
3834 EXPECT_CALL(mLayers[2].mOutputLayer, requiresClientComposition()).WillOnce(Return(true));
3835
3836 mLayers[0].mOutputLayerState.clearClientTarget = false;
3837 mLayers[1].mOutputLayerState.clearClientTarget = false;
3838 mLayers[2].mOutputLayerState.clearClientTarget = false;
3839
3840 mLayers[0].mLayerFEState.isOpaque = true;
3841 mLayers[1].mLayerFEState.isOpaque = true;
3842 mLayers[2].mLayerFEState.isOpaque = true;
3843
3844 EXPECT_CALL(*mLayers[2].mLayerFE, prepareClientCompositionList(_))
3845 .WillOnce(Return(std::vector<LayerFE::LayerSettings>({mLayers[2].mLayerSettings})));
3846
3847 Region accumClearRegion(Rect(10, 11, 12, 13));
3848 auto requests = mOutput.generateClientCompositionRequests(false /* supportsProtectedContent */,
3849 accumClearRegion, kDisplayDataspace);
3850 ASSERT_EQ(1u, requests.size());
3851 EXPECT_EQ(mLayers[2].mLayerSettings, requests[0]);
3852
3853 EXPECT_THAT(accumClearRegion, RegionEq(Region(Rect(10, 11, 12, 13))));
3854 }
3855
TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers,onlyClientComposesClientComposedLayersIfOthersAreNotOpaque)3856 TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers,
3857 onlyClientComposesClientComposedLayersIfOthersAreNotOpaque) {
3858 EXPECT_CALL(mLayers[0].mOutputLayer, requiresClientComposition()).WillOnce(Return(false));
3859 EXPECT_CALL(mLayers[1].mOutputLayer, requiresClientComposition()).WillOnce(Return(false));
3860 EXPECT_CALL(mLayers[2].mOutputLayer, requiresClientComposition()).WillOnce(Return(true));
3861
3862 mLayers[0].mOutputLayerState.clearClientTarget = true;
3863 mLayers[1].mOutputLayerState.clearClientTarget = true;
3864 mLayers[2].mOutputLayerState.clearClientTarget = true;
3865
3866 mLayers[0].mLayerFEState.isOpaque = false;
3867 mLayers[1].mLayerFEState.isOpaque = false;
3868 mLayers[2].mLayerFEState.isOpaque = false;
3869
3870 EXPECT_CALL(*mLayers[2].mLayerFE, prepareClientCompositionList(_))
3871 .WillOnce(Return(std::vector<LayerFE::LayerSettings>({mLayers[2].mLayerSettings})));
3872
3873 Region accumClearRegion(Rect(10, 11, 12, 13));
3874 auto requests = mOutput.generateClientCompositionRequests(false /* supportsProtectedContent */,
3875 accumClearRegion, kDisplayDataspace);
3876 ASSERT_EQ(1u, requests.size());
3877 EXPECT_EQ(mLayers[2].mLayerSettings, requests[0]);
3878
3879 EXPECT_THAT(accumClearRegion, RegionEq(Region(Rect(10, 11, 12, 13))));
3880 }
3881
TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers,clearsHWCLayersIfOpaqueAndNotFirst)3882 TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers, clearsHWCLayersIfOpaqueAndNotFirst) {
3883 // If client composition is performed with some layers set to use device
3884 // composition, device layers after the first layer (device or client) will
3885 // clear the frame buffer if they are opaque and if that layer has a flag
3886 // set to do so. The first layer is skipped as the frame buffer is already
3887 // expected to be clear.
3888
3889 EXPECT_CALL(mLayers[0].mOutputLayer, requiresClientComposition()).WillOnce(Return(false));
3890 EXPECT_CALL(mLayers[1].mOutputLayer, requiresClientComposition()).WillOnce(Return(false));
3891 EXPECT_CALL(mLayers[2].mOutputLayer, requiresClientComposition()).WillOnce(Return(true));
3892
3893 mLayers[0].mOutputLayerState.clearClientTarget = true;
3894 mLayers[1].mOutputLayerState.clearClientTarget = true;
3895 mLayers[2].mOutputLayerState.clearClientTarget = true;
3896
3897 mLayers[0].mLayerFEState.isOpaque = true;
3898 mLayers[1].mLayerFEState.isOpaque = true;
3899 mLayers[2].mLayerFEState.isOpaque = true;
3900 Region accumClearRegion(Rect(10, 11, 12, 13));
3901 Region stubRegion;
3902
3903 compositionengine::LayerFE::ClientCompositionTargetSettings layer1TargetSettings{
3904 Region(kDisplayFrame),
3905 false, /* needs filtering */
3906 false, /* secure */
3907 false, /* supports protected content */
3908 stubRegion, /* clear region */
3909 kDisplayViewport,
3910 kDisplayDataspace,
3911 false /* realContentIsVisible */,
3912 true /* clearContent */,
3913 compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled,
3914 };
3915 compositionengine::LayerFE::ClientCompositionTargetSettings layer2TargetSettings{
3916 Region(kDisplayFrame),
3917 false, /* needs filtering */
3918 false, /* secure */
3919 false, /* supports protected content */
3920 accumClearRegion,
3921 kDisplayViewport,
3922 kDisplayDataspace,
3923 true /* realContentIsVisible */,
3924 false /* clearContent */,
3925 compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled,
3926 };
3927
3928 LayerFE::LayerSettings mBlackoutSettings = mLayers[1].mLayerSettings;
3929 mBlackoutSettings.source.buffer.buffer = nullptr;
3930 mBlackoutSettings.source.solidColor = {0.1f, 0.1f, 0.1f};
3931 mBlackoutSettings.alpha = 0.f;
3932 mBlackoutSettings.disableBlending = true;
3933
3934 EXPECT_CALL(*mLayers[1].mLayerFE, prepareClientCompositionList(Eq(ByRef(layer1TargetSettings))))
3935 .WillOnce(Return(std::vector<LayerFE::LayerSettings>({mBlackoutSettings})));
3936 EXPECT_CALL(*mLayers[2].mLayerFE, prepareClientCompositionList(Eq(ByRef(layer2TargetSettings))))
3937 .WillOnce(Return(std::vector<LayerFE::LayerSettings>({mLayers[2].mLayerSettings})));
3938
3939 auto requests = mOutput.generateClientCompositionRequests(false /* supportsProtectedContent */,
3940 accumClearRegion, kDisplayDataspace);
3941 ASSERT_EQ(2u, requests.size());
3942
3943 // The second layer is expected to be rendered as alpha=0 black with no blending
3944 EXPECT_EQ(mBlackoutSettings, requests[0]);
3945
3946 EXPECT_EQ(mLayers[2].mLayerSettings, requests[1]);
3947
3948 EXPECT_THAT(accumClearRegion, RegionEq(Region(Rect(10, 11, 12, 13))));
3949 }
3950
TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers,clippedVisibleRegionUsedToGenerateRequest)3951 TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers,
3952 clippedVisibleRegionUsedToGenerateRequest) {
3953 mLayers[0].mOutputLayerState.visibleRegion = Region(Rect(10, 10, 20, 20));
3954 mLayers[1].mOutputLayerState.visibleRegion = Region(Rect(-10, -10, 30, 30));
3955 mLayers[2].mOutputLayerState.visibleRegion = Region(Rect(-10, 0, 40, 4000));
3956
3957 Region accumClearRegion(Rect(10, 11, 12, 13));
3958
3959 compositionengine::LayerFE::ClientCompositionTargetSettings layer0TargetSettings{
3960 Region(Rect(10, 10, 20, 20)),
3961 false, /* needs filtering */
3962 false, /* secure */
3963 false, /* supports protected content */
3964 accumClearRegion,
3965 kDisplayViewport,
3966 kDisplayDataspace,
3967 true /* realContentIsVisible */,
3968 false /* clearContent */,
3969 compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled,
3970 };
3971 compositionengine::LayerFE::ClientCompositionTargetSettings layer1TargetSettings{
3972 Region(Rect(0, 0, 30, 30)),
3973 false, /* needs filtering */
3974 false, /* secure */
3975 false, /* supports protected content */
3976 accumClearRegion,
3977 kDisplayViewport,
3978 kDisplayDataspace,
3979 true /* realContentIsVisible */,
3980 false /* clearContent */,
3981 compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled,
3982 };
3983 compositionengine::LayerFE::ClientCompositionTargetSettings layer2TargetSettings{
3984 Region(Rect(0, 0, 40, 201)),
3985 false, /* needs filtering */
3986 false, /* secure */
3987 false, /* supports protected content */
3988 accumClearRegion,
3989 kDisplayViewport,
3990 kDisplayDataspace,
3991 true /* realContentIsVisible */,
3992 false /* clearContent */,
3993 compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled,
3994 };
3995
3996 EXPECT_CALL(*mLayers[0].mLayerFE, prepareClientCompositionList(Eq(ByRef(layer0TargetSettings))))
3997 .WillOnce(Return(std::vector<LayerFE::LayerSettings>()));
3998 EXPECT_CALL(*mLayers[1].mLayerFE, prepareClientCompositionList(Eq(ByRef(layer1TargetSettings))))
3999 .WillOnce(Return(std::vector<LayerFE::LayerSettings>()));
4000 EXPECT_CALL(*mLayers[2].mLayerFE, prepareClientCompositionList(Eq(ByRef(layer2TargetSettings))))
4001 .WillOnce(Return(std::vector<LayerFE::LayerSettings>()));
4002
4003 static_cast<void>(
4004 mOutput.generateClientCompositionRequests(false /* supportsProtectedContent */,
4005 accumClearRegion, kDisplayDataspace));
4006 }
4007
TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers,perLayerNeedsFilteringUsedToGenerateRequests)4008 TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers,
4009 perLayerNeedsFilteringUsedToGenerateRequests) {
4010 mOutput.mState.needsFiltering = false;
4011 EXPECT_CALL(mLayers[0].mOutputLayer, needsFiltering()).WillRepeatedly(Return(true));
4012
4013 Region accumClearRegion(Rect(10, 11, 12, 13));
4014
4015 compositionengine::LayerFE::ClientCompositionTargetSettings layer0TargetSettings{
4016 Region(kDisplayFrame),
4017 true, /* needs filtering */
4018 false, /* secure */
4019 false, /* supports protected content */
4020 accumClearRegion,
4021 kDisplayViewport,
4022 kDisplayDataspace,
4023 true /* realContentIsVisible */,
4024 false /* clearContent */,
4025 compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled,
4026 };
4027 compositionengine::LayerFE::ClientCompositionTargetSettings layer1TargetSettings{
4028 Region(kDisplayFrame),
4029 false, /* needs filtering */
4030 false, /* secure */
4031 false, /* supports protected content */
4032 accumClearRegion,
4033 kDisplayViewport,
4034 kDisplayDataspace,
4035 true /* realContentIsVisible */,
4036 false /* clearContent */,
4037 compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled,
4038 };
4039 compositionengine::LayerFE::ClientCompositionTargetSettings layer2TargetSettings{
4040 Region(kDisplayFrame),
4041 false, /* needs filtering */
4042 false, /* secure */
4043 false, /* supports protected content */
4044 accumClearRegion,
4045 kDisplayViewport,
4046 kDisplayDataspace,
4047 true /* realContentIsVisible */,
4048 false /* clearContent */,
4049 compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled,
4050 };
4051
4052 EXPECT_CALL(*mLayers[0].mLayerFE, prepareClientCompositionList(Eq(ByRef(layer0TargetSettings))))
4053 .WillOnce(Return(std::vector<LayerFE::LayerSettings>()));
4054 EXPECT_CALL(*mLayers[1].mLayerFE, prepareClientCompositionList(Eq(ByRef(layer1TargetSettings))))
4055 .WillOnce(Return(std::vector<LayerFE::LayerSettings>()));
4056 EXPECT_CALL(*mLayers[2].mLayerFE, prepareClientCompositionList(Eq(ByRef(layer2TargetSettings))))
4057 .WillOnce(Return(std::vector<LayerFE::LayerSettings>()));
4058
4059 static_cast<void>(
4060 mOutput.generateClientCompositionRequests(false /* supportsProtectedContent */,
4061 accumClearRegion, kDisplayDataspace));
4062 }
4063
TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers,wholeOutputNeedsFilteringUsedToGenerateRequests)4064 TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers,
4065 wholeOutputNeedsFilteringUsedToGenerateRequests) {
4066 mOutput.mState.needsFiltering = true;
4067 EXPECT_CALL(mLayers[0].mOutputLayer, needsFiltering()).WillRepeatedly(Return(true));
4068
4069 Region accumClearRegion(Rect(10, 11, 12, 13));
4070
4071 compositionengine::LayerFE::ClientCompositionTargetSettings layer0TargetSettings{
4072 Region(kDisplayFrame),
4073 true, /* needs filtering */
4074 false, /* secure */
4075 false, /* supports protected content */
4076 accumClearRegion,
4077 kDisplayViewport,
4078 kDisplayDataspace,
4079 true /* realContentIsVisible */,
4080 false /* clearContent */,
4081 compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled,
4082
4083 };
4084 compositionengine::LayerFE::ClientCompositionTargetSettings layer1TargetSettings{
4085 Region(kDisplayFrame),
4086 true, /* needs filtering */
4087 false, /* secure */
4088 false, /* supports protected content */
4089 accumClearRegion,
4090 kDisplayViewport,
4091 kDisplayDataspace,
4092 true /* realContentIsVisible */,
4093 false /* clearContent */,
4094 compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled,
4095 };
4096 compositionengine::LayerFE::ClientCompositionTargetSettings layer2TargetSettings{
4097 Region(kDisplayFrame),
4098 true, /* needs filtering */
4099 false, /* secure */
4100 false, /* supports protected content */
4101 accumClearRegion,
4102 kDisplayViewport,
4103 kDisplayDataspace,
4104 true /* realContentIsVisible */,
4105 false /* clearContent */,
4106 compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled,
4107 };
4108
4109 EXPECT_CALL(*mLayers[0].mLayerFE, prepareClientCompositionList(Eq(ByRef(layer0TargetSettings))))
4110 .WillOnce(Return(std::vector<LayerFE::LayerSettings>()));
4111 EXPECT_CALL(*mLayers[1].mLayerFE, prepareClientCompositionList(Eq(ByRef(layer1TargetSettings))))
4112 .WillOnce(Return(std::vector<LayerFE::LayerSettings>()));
4113 EXPECT_CALL(*mLayers[2].mLayerFE, prepareClientCompositionList(Eq(ByRef(layer2TargetSettings))))
4114 .WillOnce(Return(std::vector<LayerFE::LayerSettings>()));
4115
4116 static_cast<void>(
4117 mOutput.generateClientCompositionRequests(false /* supportsProtectedContent */,
4118 accumClearRegion, kDisplayDataspace));
4119 }
4120
TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers,wholeOutputSecurityUsedToGenerateRequests)4121 TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers,
4122 wholeOutputSecurityUsedToGenerateRequests) {
4123 mOutput.mState.isSecure = true;
4124
4125 Region accumClearRegion(Rect(10, 11, 12, 13));
4126
4127 compositionengine::LayerFE::ClientCompositionTargetSettings layer0TargetSettings{
4128 Region(kDisplayFrame),
4129 false, /* needs filtering */
4130 true, /* secure */
4131 false, /* supports protected content */
4132 accumClearRegion,
4133 kDisplayViewport,
4134 kDisplayDataspace,
4135 true /* realContentIsVisible */,
4136 false /* clearContent */,
4137 compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled,
4138 };
4139 compositionengine::LayerFE::ClientCompositionTargetSettings layer1TargetSettings{
4140 Region(kDisplayFrame),
4141 false, /* needs filtering */
4142 true, /* secure */
4143 false, /* supports protected content */
4144 accumClearRegion,
4145 kDisplayViewport,
4146 kDisplayDataspace,
4147 true /* realContentIsVisible */,
4148 false /* clearContent */,
4149 compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled,
4150 };
4151 compositionengine::LayerFE::ClientCompositionTargetSettings layer2TargetSettings{
4152 Region(kDisplayFrame),
4153 false, /* needs filtering */
4154 true, /* secure */
4155 false, /* supports protected content */
4156 accumClearRegion,
4157 kDisplayViewport,
4158 kDisplayDataspace,
4159 true /* realContentIsVisible */,
4160 false /* clearContent */,
4161 compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled,
4162 };
4163
4164 EXPECT_CALL(*mLayers[0].mLayerFE, prepareClientCompositionList(Eq(ByRef(layer0TargetSettings))))
4165 .WillOnce(Return(std::vector<LayerFE::LayerSettings>()));
4166 EXPECT_CALL(*mLayers[1].mLayerFE, prepareClientCompositionList(Eq(ByRef(layer1TargetSettings))))
4167 .WillOnce(Return(std::vector<LayerFE::LayerSettings>()));
4168 EXPECT_CALL(*mLayers[2].mLayerFE, prepareClientCompositionList(Eq(ByRef(layer2TargetSettings))))
4169 .WillOnce(Return(std::vector<LayerFE::LayerSettings>()));
4170
4171 static_cast<void>(
4172 mOutput.generateClientCompositionRequests(false /* supportsProtectedContent */,
4173 accumClearRegion, kDisplayDataspace));
4174 }
4175
TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers,protectedContentSupportUsedToGenerateRequests)4176 TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers,
4177 protectedContentSupportUsedToGenerateRequests) {
4178 Region accumClearRegion(Rect(10, 11, 12, 13));
4179
4180 compositionengine::LayerFE::ClientCompositionTargetSettings layer0TargetSettings{
4181 Region(kDisplayFrame),
4182 false, /* needs filtering */
4183 false, /* secure */
4184 true, /* supports protected content */
4185 accumClearRegion,
4186 kDisplayViewport,
4187 kDisplayDataspace,
4188 true /* realContentIsVisible */,
4189 false /* clearContent */,
4190 compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled,
4191 };
4192 compositionengine::LayerFE::ClientCompositionTargetSettings layer1TargetSettings{
4193 Region(kDisplayFrame),
4194 false, /* needs filtering */
4195 false, /* secure */
4196 true, /* supports protected content */
4197 accumClearRegion,
4198 kDisplayViewport,
4199 kDisplayDataspace,
4200 true /* realContentIsVisible */,
4201 false /* clearContent */,
4202 compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled,
4203 };
4204 compositionengine::LayerFE::ClientCompositionTargetSettings layer2TargetSettings{
4205 Region(kDisplayFrame),
4206 false, /* needs filtering */
4207 false, /* secure */
4208 true, /* supports protected content */
4209 accumClearRegion,
4210 kDisplayViewport,
4211 kDisplayDataspace,
4212 true /* realContentIsVisible */,
4213 false /* clearContent */,
4214 compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled,
4215 };
4216
4217 EXPECT_CALL(*mLayers[0].mLayerFE, prepareClientCompositionList(Eq(ByRef(layer0TargetSettings))))
4218 .WillOnce(Return(std::vector<LayerFE::LayerSettings>()));
4219 EXPECT_CALL(*mLayers[1].mLayerFE, prepareClientCompositionList(Eq(ByRef(layer1TargetSettings))))
4220 .WillOnce(Return(std::vector<LayerFE::LayerSettings>()));
4221 EXPECT_CALL(*mLayers[2].mLayerFE, prepareClientCompositionList(Eq(ByRef(layer2TargetSettings))))
4222 .WillOnce(Return(std::vector<LayerFE::LayerSettings>()));
4223
4224 static_cast<void>(mOutput.generateClientCompositionRequests(true /* supportsProtectedContent */,
4225 accumClearRegion,
4226 kDisplayDataspace));
4227 }
4228
TEST_F(OutputUpdateAndWriteCompositionStateTest,noBackgroundBlurWhenOpaque)4229 TEST_F(OutputUpdateAndWriteCompositionStateTest, noBackgroundBlurWhenOpaque) {
4230 InjectedLayer layer1;
4231 InjectedLayer layer2;
4232
4233 uint32_t z = 0;
4234 // Layer requesting blur, or below, should request client composition, unless opaque.
4235 EXPECT_CALL(*layer1.outputLayer, updateCompositionState(false, false, ui::Transform::ROT_0));
4236 EXPECT_CALL(*layer1.outputLayer,
4237 writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, z++,
4238 /*zIsOverridden*/ false, /*isPeekingThrough*/ false));
4239 EXPECT_CALL(*layer2.outputLayer, updateCompositionState(false, false, ui::Transform::ROT_0));
4240 EXPECT_CALL(*layer2.outputLayer,
4241 writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, z++,
4242 /*zIsOverridden*/ false, /*isPeekingThrough*/ false));
4243
4244 layer2.layerFEState.backgroundBlurRadius = 10;
4245 layer2.layerFEState.isOpaque = true;
4246
4247 injectOutputLayer(layer1);
4248 injectOutputLayer(layer2);
4249
4250 mOutput->editState().isEnabled = true;
4251
4252 CompositionRefreshArgs args;
4253 args.updatingGeometryThisFrame = false;
4254 args.devOptForceClientComposition = false;
4255 mOutput->updateCompositionState(args);
4256 mOutput->planComposition();
4257 mOutput->writeCompositionState(args);
4258 }
4259
TEST_F(OutputUpdateAndWriteCompositionStateTest,handlesBackgroundBlurRequests)4260 TEST_F(OutputUpdateAndWriteCompositionStateTest, handlesBackgroundBlurRequests) {
4261 InjectedLayer layer1;
4262 InjectedLayer layer2;
4263 InjectedLayer layer3;
4264
4265 uint32_t z = 0;
4266 // Layer requesting blur, or below, should request client composition.
4267 EXPECT_CALL(*layer1.outputLayer, updateCompositionState(false, true, ui::Transform::ROT_0));
4268 EXPECT_CALL(*layer1.outputLayer,
4269 writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, z++,
4270 /*zIsOverridden*/ false, /*isPeekingThrough*/ false));
4271 EXPECT_CALL(*layer2.outputLayer, updateCompositionState(false, true, ui::Transform::ROT_0));
4272 EXPECT_CALL(*layer2.outputLayer,
4273 writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, z++,
4274 /*zIsOverridden*/ false, /*isPeekingThrough*/ false));
4275 EXPECT_CALL(*layer3.outputLayer, updateCompositionState(false, false, ui::Transform::ROT_0));
4276 EXPECT_CALL(*layer3.outputLayer,
4277 writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, z++,
4278 /*zIsOverridden*/ false, /*isPeekingThrough*/ false));
4279
4280 layer2.layerFEState.backgroundBlurRadius = 10;
4281 layer2.layerFEState.isOpaque = false;
4282
4283 injectOutputLayer(layer1);
4284 injectOutputLayer(layer2);
4285 injectOutputLayer(layer3);
4286
4287 mOutput->editState().isEnabled = true;
4288
4289 CompositionRefreshArgs args;
4290 args.updatingGeometryThisFrame = false;
4291 args.devOptForceClientComposition = false;
4292 mOutput->updateCompositionState(args);
4293 mOutput->planComposition();
4294 mOutput->writeCompositionState(args);
4295 }
4296
TEST_F(OutputUpdateAndWriteCompositionStateTest,handlesBlurRegionRequests)4297 TEST_F(OutputUpdateAndWriteCompositionStateTest, handlesBlurRegionRequests) {
4298 InjectedLayer layer1;
4299 InjectedLayer layer2;
4300 InjectedLayer layer3;
4301
4302 uint32_t z = 0;
4303 // Layer requesting blur, or below, should request client composition.
4304 EXPECT_CALL(*layer1.outputLayer, updateCompositionState(false, true, ui::Transform::ROT_0));
4305 EXPECT_CALL(*layer1.outputLayer,
4306 writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, z++,
4307 /*zIsOverridden*/ false, /*isPeekingThrough*/ false));
4308 EXPECT_CALL(*layer2.outputLayer, updateCompositionState(false, true, ui::Transform::ROT_0));
4309 EXPECT_CALL(*layer2.outputLayer,
4310 writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, z++,
4311 /*zIsOverridden*/ false, /*isPeekingThrough*/ false));
4312 EXPECT_CALL(*layer3.outputLayer, updateCompositionState(false, false, ui::Transform::ROT_0));
4313 EXPECT_CALL(*layer3.outputLayer,
4314 writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, z++,
4315 /*zIsOverridden*/ false, /*isPeekingThrough*/ false));
4316
4317 BlurRegion region;
4318 layer2.layerFEState.blurRegions.push_back(region);
4319 layer2.layerFEState.isOpaque = false;
4320
4321 injectOutputLayer(layer1);
4322 injectOutputLayer(layer2);
4323 injectOutputLayer(layer3);
4324
4325 mOutput->editState().isEnabled = true;
4326
4327 CompositionRefreshArgs args;
4328 args.updatingGeometryThisFrame = false;
4329 args.devOptForceClientComposition = false;
4330 mOutput->updateCompositionState(args);
4331 mOutput->planComposition();
4332 mOutput->writeCompositionState(args);
4333 }
4334
TEST_F(GenerateClientCompositionRequestsTest,handlesLandscapeModeSplitScreenRequests)4335 TEST_F(GenerateClientCompositionRequestsTest, handlesLandscapeModeSplitScreenRequests) {
4336 // In split-screen landscape mode, the screen is rotated 90 degrees, with
4337 // one layer on the left covering the left side of the output, and one layer
4338 // on the right covering that side of the output.
4339
4340 const Rect kPortraitFrame(0, 0, 1000, 2000);
4341 const Rect kPortraitViewport(0, 0, 2000, 1000);
4342 const Rect kPortraitDestinationClip(0, 0, 1000, 2000);
4343 const ui::Rotation kPortraitOrientation = ui::ROTATION_90;
4344 constexpr ui::Dataspace kOutputDataspace = ui::Dataspace::DISPLAY_P3;
4345
4346 mOutput.mState.orientedDisplaySpace.content = kPortraitFrame;
4347 mOutput.mState.layerStackSpace.content = kPortraitViewport;
4348 mOutput.mState.displaySpace.content = kPortraitDestinationClip;
4349 mOutput.mState.transform = ui::Transform{ui::Transform::toRotationFlags(kPortraitOrientation)};
4350 mOutput.mState.displaySpace.orientation = kPortraitOrientation;
4351 mOutput.mState.needsFiltering = false;
4352 mOutput.mState.isSecure = true;
4353
4354 Layer leftLayer;
4355 Layer rightLayer;
4356
4357 leftLayer.mOutputLayerState.clearClientTarget = false;
4358 leftLayer.mOutputLayerState.visibleRegion = Region(Rect(0, 0, 1000, 1000));
4359 leftLayer.mLayerFEState.isOpaque = true;
4360 leftLayer.mLayerSettings.source.solidColor = {1.f, 0.f, 0.f};
4361
4362 rightLayer.mOutputLayerState.clearClientTarget = false;
4363 rightLayer.mOutputLayerState.visibleRegion = Region(Rect(1000, 0, 2000, 1000));
4364 rightLayer.mLayerFEState.isOpaque = true;
4365 rightLayer.mLayerSettings.source.solidColor = {0.f, 1.f, 0.f};
4366
4367 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(2u));
4368 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0u))
4369 .WillRepeatedly(Return(&leftLayer.mOutputLayer));
4370 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(1u))
4371 .WillRepeatedly(Return(&rightLayer.mOutputLayer));
4372
4373 Region accumClearRegion(Rect(10, 11, 12, 13));
4374
4375 compositionengine::LayerFE::ClientCompositionTargetSettings leftLayerSettings{
4376 Region(Rect(0, 0, 1000, 1000)),
4377 false, /* needs filtering */
4378 true, /* secure */
4379 true, /* supports protected content */
4380 accumClearRegion,
4381 kPortraitViewport,
4382 kOutputDataspace,
4383 true /* realContentIsVisible */,
4384 false /* clearContent */,
4385 compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled,
4386 };
4387
4388 EXPECT_CALL(leftLayer.mOutputLayer, requiresClientComposition()).WillRepeatedly(Return(true));
4389 EXPECT_CALL(leftLayer.mOutputLayer, needsFiltering()).WillRepeatedly(Return(false));
4390 EXPECT_CALL(*leftLayer.mLayerFE, prepareClientCompositionList(Eq(ByRef(leftLayerSettings))))
4391 .WillOnce(Return(std::vector<LayerFE::LayerSettings>({leftLayer.mLayerSettings})));
4392
4393 compositionengine::LayerFE::ClientCompositionTargetSettings rightLayerSettings{
4394 Region(Rect(1000, 0, 2000, 1000)),
4395 false, /* needs filtering */
4396 true, /* secure */
4397 true, /* supports protected content */
4398 accumClearRegion,
4399 kPortraitViewport,
4400 kOutputDataspace,
4401 true /* realContentIsVisible */,
4402 false /* clearContent */,
4403 compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled,
4404 };
4405
4406 EXPECT_CALL(rightLayer.mOutputLayer, requiresClientComposition()).WillRepeatedly(Return(true));
4407 EXPECT_CALL(rightLayer.mOutputLayer, needsFiltering()).WillRepeatedly(Return(false));
4408 EXPECT_CALL(*rightLayer.mLayerFE, prepareClientCompositionList(Eq(ByRef(rightLayerSettings))))
4409 .WillOnce(Return(std::vector<LayerFE::LayerSettings>({rightLayer.mLayerSettings})));
4410
4411 constexpr bool supportsProtectedContent = true;
4412 auto requests = mOutput.generateClientCompositionRequests(supportsProtectedContent,
4413 accumClearRegion, kOutputDataspace);
4414 ASSERT_EQ(2u, requests.size());
4415 EXPECT_EQ(leftLayer.mLayerSettings, requests[0]);
4416 EXPECT_EQ(rightLayer.mLayerSettings, requests[1]);
4417 }
4418
TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers,shadowRegionOnlyVisibleSkipsContentComposition)4419 TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers,
4420 shadowRegionOnlyVisibleSkipsContentComposition) {
4421 const Rect kContentWithShadow(40, 40, 70, 90);
4422 const Rect kContent(50, 50, 60, 80);
4423 const Region kShadowRegion = Region(kContentWithShadow).subtract(kContent);
4424 const Region kPartialShadowRegion = Region(kContentWithShadow).subtract(Rect(40, 40, 60, 80));
4425
4426 Region accumClearRegion(Rect(10, 11, 12, 13));
4427 compositionengine::LayerFE::ClientCompositionTargetSettings layer2Settings{
4428 Region(Rect(60, 40, 70, 80)).merge(Rect(40, 80, 70, 90)), /* visible region */
4429 false, /* needs filtering */
4430 false, /* secure */
4431 false, /* supports protected content */
4432 accumClearRegion,
4433 kDisplayViewport,
4434 kDisplayDataspace,
4435 false /* realContentIsVisible */,
4436 false /* clearContent */,
4437 compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled,
4438 };
4439
4440 LayerFE::LayerSettings mShadowSettings;
4441 mShadowSettings.source.solidColor = {0.1f, 0.1f, 0.1f};
4442
4443 mLayers[2].mOutputLayerState.visibleRegion = kPartialShadowRegion;
4444 mLayers[2].mOutputLayerState.shadowRegion = kShadowRegion;
4445
4446 EXPECT_CALL(mLayers[0].mOutputLayer, requiresClientComposition()).WillOnce(Return(false));
4447 EXPECT_CALL(mLayers[1].mOutputLayer, requiresClientComposition()).WillOnce(Return(false));
4448 EXPECT_CALL(*mLayers[2].mLayerFE, prepareClientCompositionList(Eq(ByRef(layer2Settings))))
4449 .WillOnce(Return(std::vector<LayerFE::LayerSettings>({mShadowSettings})));
4450
4451 auto requests = mOutput.generateClientCompositionRequests(false /* supportsProtectedContent */,
4452 accumClearRegion, kDisplayDataspace);
4453 ASSERT_EQ(1u, requests.size());
4454
4455 EXPECT_EQ(mShadowSettings, requests[0]);
4456 }
4457
TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers,shadowRegionWithContentVisibleRequestsContentAndShadowComposition)4458 TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers,
4459 shadowRegionWithContentVisibleRequestsContentAndShadowComposition) {
4460 const Rect kContentWithShadow(40, 40, 70, 90);
4461 const Rect kContent(50, 50, 60, 80);
4462 const Region kShadowRegion = Region(kContentWithShadow).subtract(kContent);
4463 const Region kPartialContentWithPartialShadowRegion =
4464 Region(kContentWithShadow).subtract(Rect(40, 40, 50, 80));
4465
4466 LayerFE::LayerSettings mShadowSettings;
4467 mShadowSettings.source.solidColor = {0.1f, 0.1f, 0.1f};
4468
4469 mLayers[2].mOutputLayerState.visibleRegion = kPartialContentWithPartialShadowRegion;
4470 mLayers[2].mOutputLayerState.shadowRegion = kShadowRegion;
4471
4472 Region accumClearRegion(Rect(10, 11, 12, 13));
4473 compositionengine::LayerFE::ClientCompositionTargetSettings layer2Settings{
4474 Region(Rect(50, 40, 70, 80)).merge(Rect(40, 80, 70, 90)), /* visible region */
4475 false, /* needs filtering */
4476 false, /* secure */
4477 false, /* supports protected content */
4478 accumClearRegion,
4479 kDisplayViewport,
4480 kDisplayDataspace,
4481 true /* realContentIsVisible */,
4482 false /* clearContent */,
4483 compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled,
4484 };
4485
4486 EXPECT_CALL(mLayers[0].mOutputLayer, requiresClientComposition()).WillOnce(Return(false));
4487 EXPECT_CALL(mLayers[1].mOutputLayer, requiresClientComposition()).WillOnce(Return(false));
4488 EXPECT_CALL(*mLayers[2].mLayerFE, prepareClientCompositionList(Eq(ByRef(layer2Settings))))
4489 .WillOnce(Return(std::vector<LayerFE::LayerSettings>(
4490 {mShadowSettings, mLayers[2].mLayerSettings})));
4491
4492 auto requests = mOutput.generateClientCompositionRequests(false /* supportsProtectedContent */,
4493 accumClearRegion, kDisplayDataspace);
4494 ASSERT_EQ(2u, requests.size());
4495
4496 EXPECT_EQ(mShadowSettings, requests[0]);
4497 EXPECT_EQ(mLayers[2].mLayerSettings, requests[1]);
4498 }
4499
4500 } // namespace
4501 } // namespace android::compositionengine
4502