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