1 /*
2 * Copyright 2018 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 // TODO(b/129481165): remove the #pragma below and fix conversion issues
18 #include "renderengine/ExternalTexture.h"
19 #pragma clang diagnostic push
20 #pragma clang diagnostic ignored "-Wconversion"
21 #pragma clang diagnostic ignored "-Wextra"
22
23 #undef LOG_TAG
24 #define LOG_TAG "CompositionTest"
25
26 #include <compositionengine/Display.h>
27 #include <compositionengine/mock/DisplaySurface.h>
28 #include <ftl/future.h>
29 #include <gmock/gmock.h>
30 #include <gtest/gtest.h>
31 #include <gui/IProducerListener.h>
32 #include <gui/LayerMetadata.h>
33 #include <log/log.h>
34 #include <renderengine/mock/FakeExternalTexture.h>
35 #include <renderengine/mock/RenderEngine.h>
36 #include <system/window.h>
37 #include <utils/String8.h>
38
39 #include "DisplayRenderArea.h"
40 #include "Layer.h"
41 #include "TestableSurfaceFlinger.h"
42 #include "mock/DisplayHardware/MockComposer.h"
43 #include "mock/DisplayHardware/MockPowerAdvisor.h"
44 #include "mock/MockEventThread.h"
45 #include "mock/MockTimeStats.h"
46 #include "mock/MockVsyncController.h"
47 #include "mock/system/window/MockNativeWindow.h"
48
49 namespace android {
50 namespace {
51
52 namespace hal = android::hardware::graphics::composer::hal;
53
54 using hal::Error;
55 using hal::IComposer;
56 using hal::IComposerClient;
57 using hal::PowerMode;
58 using hal::Transform;
59
60 using aidl::android::hardware::graphics::composer3::Capability;
61
62 using testing::_;
63 using testing::AtLeast;
64 using testing::DoAll;
65 using testing::IsNull;
66 using testing::Mock;
67 using testing::Return;
68 using testing::ReturnRef;
69 using testing::SetArgPointee;
70
71 using FakeHwcDisplayInjector = TestableSurfaceFlinger::FakeHwcDisplayInjector;
72 using FakeDisplayDeviceInjector = TestableSurfaceFlinger::FakeDisplayDeviceInjector;
73 using namespace ftl::flag_operators;
74
75 constexpr hal::HWDisplayId HWC_DISPLAY = FakeHwcDisplayInjector::DEFAULT_HWC_DISPLAY_ID;
76 constexpr hal::HWLayerId HWC_LAYER = 5000;
77 constexpr Transform DEFAULT_TRANSFORM = static_cast<Transform>(0);
78
79 constexpr PhysicalDisplayId DEFAULT_DISPLAY_ID = PhysicalDisplayId::fromPort(42u);
80 constexpr int DEFAULT_DISPLAY_WIDTH = 1920;
81 constexpr int DEFAULT_DISPLAY_HEIGHT = 1024;
82
83 constexpr int DEFAULT_TEXTURE_ID = 6000;
84 constexpr ui::LayerStack LAYER_STACK{7000u};
85
86 constexpr int DEFAULT_DISPLAY_MAX_LUMINANCE = 500;
87
88 constexpr int DEFAULT_SIDEBAND_STREAM = 51;
89
90 MATCHER(IsIdentityMatrix, "") {
91 constexpr auto kIdentity = mat4();
92 return (mat4(arg) == kIdentity);
93 }
94
95 class CompositionTest : public testing::Test {
96 public:
CompositionTest()97 CompositionTest() {
98 const ::testing::TestInfo* const test_info =
99 ::testing::UnitTest::GetInstance()->current_test_info();
100 ALOGD("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name());
101
102 mFlinger.setupMockScheduler({.displayId = DEFAULT_DISPLAY_ID});
103
104 EXPECT_CALL(*mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
105 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_WIDTH), Return(0)));
106 EXPECT_CALL(*mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
107 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_HEIGHT), Return(0)));
108
109 mFlinger.setupRenderEngine(std::unique_ptr<renderengine::RenderEngine>(mRenderEngine));
110 mFlinger.setupTimeStats(std::shared_ptr<TimeStats>(mTimeStats));
111
112 mComposer = new Hwc2::mock::Composer();
113 mPowerAdvisor = new Hwc2::mock::PowerAdvisor();
114 mFlinger.setupComposer(std::unique_ptr<Hwc2::Composer>(mComposer));
115 mFlinger.setupPowerAdvisor(std::unique_ptr<Hwc2::PowerAdvisor>(mPowerAdvisor));
116 mFlinger.mutableMaxRenderTargetSize() = 16384;
117 }
118
~CompositionTest()119 ~CompositionTest() {
120 const ::testing::TestInfo* const test_info =
121 ::testing::UnitTest::GetInstance()->current_test_info();
122 ALOGD("**** Tearing down after %s.%s\n", test_info->test_case_name(), test_info->name());
123 }
124
setupForceGeometryDirty()125 void setupForceGeometryDirty() {
126 // TODO: This requires the visible region and other related
127 // state to be set, and is problematic for BufferLayers since they are
128 // not visible without a buffer (and setting up a buffer looks like a
129 // pain)
130 // mFlinger.mutableVisibleRegionsDirty() = true;
131
132 mFlinger.mutableGeometryDirty() = true;
133 }
134
135 template <typename Case>
136 void displayRefreshCompositionDirtyGeometry();
137
138 template <typename Case>
139 void displayRefreshCompositionDirtyFrame();
140
141 template <typename Case>
142 void captureScreenComposition();
143
144 std::unordered_set<Capability> mDefaultCapabilities = {Capability::SIDEBAND_STREAM};
145
146 bool mDisplayOff = false;
147 TestableSurfaceFlinger mFlinger;
148 sp<DisplayDevice> mDisplay;
149 sp<compositionengine::mock::DisplaySurface> mDisplaySurface =
150 sp<compositionengine::mock::DisplaySurface>::make();
151 sp<mock::NativeWindow> mNativeWindow = sp<mock::NativeWindow>::make();
152 std::vector<sp<Layer>> mAuxiliaryLayers;
153
154 sp<GraphicBuffer> mBuffer =
155 sp<GraphicBuffer>::make(1u, 1u, PIXEL_FORMAT_RGBA_8888,
156 GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_SW_READ_OFTEN);
157 ANativeWindowBuffer* mNativeWindowBuffer = mBuffer->getNativeBuffer();
158
159 Hwc2::mock::Composer* mComposer = nullptr;
160 renderengine::mock::RenderEngine* mRenderEngine = new renderengine::mock::RenderEngine();
161 mock::TimeStats* mTimeStats = new mock::TimeStats();
162 Hwc2::mock::PowerAdvisor* mPowerAdvisor = nullptr;
163
164 sp<Fence> mClientTargetAcquireFence = Fence::NO_FENCE;
165
166 std::shared_ptr<renderengine::ExternalTexture> mCaptureScreenBuffer;
167 };
168
169 template <typename LayerCase>
displayRefreshCompositionDirtyGeometry()170 void CompositionTest::displayRefreshCompositionDirtyGeometry() {
171 setupForceGeometryDirty();
172 LayerCase::setupForDirtyGeometry(this);
173
174 // --------------------------------------------------------------------
175 // Invocation
176
177 mFlinger.commitAndComposite();
178
179 LayerCase::cleanup(this);
180 }
181
182 template <typename LayerCase>
displayRefreshCompositionDirtyFrame()183 void CompositionTest::displayRefreshCompositionDirtyFrame() {
184 LayerCase::setupForDirtyFrame(this);
185
186 // --------------------------------------------------------------------
187 // Invocation
188
189 mFlinger.commitAndComposite();
190
191 LayerCase::cleanup(this);
192 }
193
194 template <typename LayerCase>
captureScreenComposition()195 void CompositionTest::captureScreenComposition() {
196 LayerCase::setupForScreenCapture(this);
197
198 const Rect sourceCrop(0, 0, DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT);
199 constexpr bool regionSampling = false;
200
201 auto renderArea =
202 DisplayRenderArea::create(mDisplay, sourceCrop, sourceCrop.getSize(),
203 ui::Dataspace::V0_SRGB,
204 RenderArea::Options::CAPTURE_SECURE_LAYERS |
205 RenderArea::Options::HINT_FOR_SEAMLESS_TRANSITION);
206
207 auto traverseLayers = [this](const LayerVector::Visitor& visitor) {
208 return mFlinger.traverseLayersInLayerStack(mDisplay->getLayerStack(),
209 CaptureArgs::UNSET_UID, {}, visitor);
210 };
211
212 // TODO: Use SurfaceFlinger::getLayerSnapshotsForScreenshots instead of this legacy function
213 auto getLayerSnapshotsFn = RenderArea::fromTraverseLayersLambda(traverseLayers);
214
215 const uint32_t usage = GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN |
216 GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_TEXTURE;
217 mCaptureScreenBuffer =
218 std::make_shared<renderengine::mock::FakeExternalTexture>(renderArea->getReqWidth(),
219 renderArea->getReqHeight(),
220 HAL_PIXEL_FORMAT_RGBA_8888, 1,
221 usage);
222
223 auto future = mFlinger.renderScreenImpl(mDisplay, std::move(renderArea), getLayerSnapshotsFn,
224 mCaptureScreenBuffer, regionSampling);
225 ASSERT_TRUE(future.valid());
226 const auto fenceResult = future.get();
227
228 EXPECT_EQ(NO_ERROR, fenceStatus(fenceResult));
229 if (fenceResult.ok()) {
230 fenceResult.value()->waitForever(LOG_TAG);
231 }
232
233 LayerCase::cleanup(this);
234 }
235
236 /* ------------------------------------------------------------------------
237 * Variants for each display configuration which can be tested
238 */
239
240 template <typename Derived>
241 struct BaseDisplayVariant {
242 static constexpr bool IS_SECURE = true;
243 static constexpr hal::PowerMode INIT_POWER_MODE = hal::PowerMode::ON;
244
setupPreconditionsandroid::__anon4393af000111::BaseDisplayVariant245 static void setupPreconditions(CompositionTest* test) {
246 EXPECT_CALL(*test->mComposer, setPowerMode(HWC_DISPLAY, Derived::INIT_POWER_MODE))
247 .WillOnce(Return(Error::NONE));
248
249 FakeHwcDisplayInjector(DEFAULT_DISPLAY_ID, hal::DisplayType::PHYSICAL, true /* isPrimary */)
250 .setCapabilities(&test->mDefaultCapabilities)
251 .setPowerMode(Derived::INIT_POWER_MODE)
252 .inject(&test->mFlinger, test->mComposer);
253 Mock::VerifyAndClear(test->mComposer);
254
255 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
256 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_WIDTH), Return(0)));
257 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
258 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_HEIGHT), Return(0)));
259 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT)).Times(1);
260 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_API_CONNECT)).Times(1);
261 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_USAGE64)).Times(1);
262
263 const ::testing::TestInfo* const test_info =
264 ::testing::UnitTest::GetInstance()->current_test_info();
265
266 auto ceDisplayArgs = compositionengine::DisplayCreationArgsBuilder()
267 .setId(DEFAULT_DISPLAY_ID)
268 .setPixels({DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT})
269 .setIsSecure(Derived::IS_SECURE)
270 .setPowerAdvisor(test->mPowerAdvisor)
271 .setName(std::string("Injected display for ") +
272 test_info->test_case_name() + "." + test_info->name())
273 .build();
274
275 auto compositionDisplay =
276 compositionengine::impl::createDisplay(test->mFlinger.getCompositionEngine(),
277 ceDisplayArgs);
278
279 constexpr auto kDisplayConnectionType = ui::DisplayConnectionType::Internal;
280 constexpr bool kIsPrimary = true;
281
282 test->mDisplay =
283 FakeDisplayDeviceInjector(test->mFlinger, compositionDisplay,
284 kDisplayConnectionType, HWC_DISPLAY, kIsPrimary)
285 .setDisplaySurface(test->mDisplaySurface)
286 .setNativeWindow(test->mNativeWindow)
287 .setSecure(Derived::IS_SECURE)
288 .setPowerMode(Derived::INIT_POWER_MODE)
289 .setRefreshRateSelector(test->mFlinger.scheduler()->refreshRateSelector())
290 .skipSchedulerRegistration()
291 .inject();
292 Mock::VerifyAndClear(test->mNativeWindow.get());
293
294 constexpr bool kIsInternal = kDisplayConnectionType == ui::DisplayConnectionType::Internal;
295 test->mDisplay->setLayerFilter({LAYER_STACK, kIsInternal});
296 }
297
298 template <typename Case>
setupPreconditionCallExpectationsandroid::__anon4393af000111::BaseDisplayVariant299 static void setupPreconditionCallExpectations(CompositionTest* test) {
300 EXPECT_CALL(*test->mComposer, getDisplayCapabilities(HWC_DISPLAY, _))
301 .WillOnce(DoAll(SetArgPointee<1>(
302 std::vector<aidl::android::hardware::graphics::composer3::
303 DisplayCapability>({})),
304 Return(Error::NONE)));
305 }
306
307 template <typename Case>
setupCommonCompositionCallExpectationsandroid::__anon4393af000111::BaseDisplayVariant308 static void setupCommonCompositionCallExpectations(CompositionTest* test) {
309 EXPECT_CALL(*test->mComposer, setColorTransform(HWC_DISPLAY, IsIdentityMatrix())).Times(1);
310 EXPECT_CALL(*test->mComposer, getDisplayRequests(HWC_DISPLAY, _, _, _)).Times(1);
311 EXPECT_CALL(*test->mComposer, acceptDisplayChanges(HWC_DISPLAY)).Times(1);
312 EXPECT_CALL(*test->mComposer, presentDisplay(HWC_DISPLAY, _)).Times(1);
313 EXPECT_CALL(*test->mComposer, getReleaseFences(HWC_DISPLAY, _, _)).Times(1);
314
315 EXPECT_CALL(*test->mDisplaySurface, onFrameCommitted()).Times(1);
316 EXPECT_CALL(*test->mDisplaySurface, advanceFrame(_)).Times(1);
317
318 Case::CompositionType::setupHwcSetCallExpectations(test);
319 Case::CompositionType::setupHwcGetCallExpectations(test);
320 }
321
322 template <typename Case>
setupCommonScreensCaptureCallExpectationsandroid::__anon4393af000111::BaseDisplayVariant323 static void setupCommonScreensCaptureCallExpectations(CompositionTest* test) {
324 EXPECT_CALL(*test->mRenderEngine, drawLayers)
325 .WillRepeatedly([&](const renderengine::DisplaySettings& displaySettings,
326 const std::vector<renderengine::LayerSettings>&,
327 const std::shared_ptr<renderengine::ExternalTexture>&,
328 base::unique_fd&&) -> ftl::Future<FenceResult> {
329 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
330 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
331 displaySettings.physicalDisplay);
332 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
333 displaySettings.clip);
334 return ftl::yield<FenceResult>(Fence::NO_FENCE);
335 });
336 }
337
setupNonEmptyFrameCompositionCallExpectationsandroid::__anon4393af000111::BaseDisplayVariant338 static void setupNonEmptyFrameCompositionCallExpectations(CompositionTest* test) {
339 EXPECT_CALL(*test->mDisplaySurface, beginFrame(true)).Times(1);
340 }
341
setupEmptyFrameCompositionCallExpectationsandroid::__anon4393af000111::BaseDisplayVariant342 static void setupEmptyFrameCompositionCallExpectations(CompositionTest* test) {
343 EXPECT_CALL(*test->mDisplaySurface, beginFrame(false)).Times(1);
344 }
345
setupHwcCompositionCallExpectationsandroid::__anon4393af000111::BaseDisplayVariant346 static void setupHwcCompositionCallExpectations(CompositionTest* test) {
347 EXPECT_CALL(*test->mComposer, presentOrValidateDisplay(HWC_DISPLAY, _, _, _, _, _, _))
348 .Times(1);
349
350 EXPECT_CALL(*test->mDisplaySurface,
351 prepareFrame(compositionengine::DisplaySurface::CompositionType::Hwc))
352 .Times(1);
353 }
354
setupHwcClientCompositionCallExpectationsandroid::__anon4393af000111::BaseDisplayVariant355 static void setupHwcClientCompositionCallExpectations(CompositionTest* test) {
356 EXPECT_CALL(*test->mComposer, presentOrValidateDisplay(HWC_DISPLAY, _, _, _, _, _, _))
357 .Times(1);
358 }
359
setupHwcForcedClientCompositionCallExpectationsandroid::__anon4393af000111::BaseDisplayVariant360 static void setupHwcForcedClientCompositionCallExpectations(CompositionTest* test) {
361 EXPECT_CALL(*test->mComposer, validateDisplay(HWC_DISPLAY, _, _, _, _)).Times(1);
362 }
363
setupRECompositionCallExpectationsandroid::__anon4393af000111::BaseDisplayVariant364 static void setupRECompositionCallExpectations(CompositionTest* test) {
365 EXPECT_CALL(*test->mDisplaySurface,
366 prepareFrame(compositionengine::DisplaySurface::CompositionType::Gpu))
367 .Times(1);
368 EXPECT_CALL(*test->mDisplaySurface, getClientTargetAcquireFence())
369 .WillRepeatedly(ReturnRef(test->mClientTargetAcquireFence));
370
371 EXPECT_CALL(*test->mNativeWindow, queueBuffer(_, _)).WillOnce(Return(0));
372 EXPECT_CALL(*test->mNativeWindow, dequeueBuffer(_, _))
373 .WillOnce(DoAll(SetArgPointee<0>(test->mNativeWindowBuffer), SetArgPointee<1>(-1),
374 Return(0)));
375 EXPECT_CALL(*test->mRenderEngine, drawLayers)
376 .WillRepeatedly([&](const renderengine::DisplaySettings& displaySettings,
377 const std::vector<renderengine::LayerSettings>&,
378 const std::shared_ptr<renderengine::ExternalTexture>&,
379 base::unique_fd&&) -> ftl::Future<FenceResult> {
380 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
381 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
382 displaySettings.physicalDisplay);
383 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
384 displaySettings.clip);
385 EXPECT_EQ(ui::Dataspace::UNKNOWN, displaySettings.outputDataspace);
386 return ftl::yield<FenceResult>(Fence::NO_FENCE);
387 });
388 }
389
390 template <typename Case>
setupRELayerCompositionCallExpectationsandroid::__anon4393af000111::BaseDisplayVariant391 static void setupRELayerCompositionCallExpectations(CompositionTest* test) {
392 Case::Layer::setupRECompositionCallExpectations(test);
393 }
394
395 template <typename Case>
setupRELayerScreenshotCompositionCallExpectationsandroid::__anon4393af000111::BaseDisplayVariant396 static void setupRELayerScreenshotCompositionCallExpectations(CompositionTest* test) {
397 Case::Layer::setupREScreenshotCompositionCallExpectations(test);
398 }
399 };
400
401 struct DefaultDisplaySetupVariant : public BaseDisplayVariant<DefaultDisplaySetupVariant> {};
402
403 struct InsecureDisplaySetupVariant : public BaseDisplayVariant<InsecureDisplaySetupVariant> {
404 static constexpr bool IS_SECURE = false;
405
406 template <typename Case>
setupRELayerCompositionCallExpectationsandroid::__anon4393af000111::InsecureDisplaySetupVariant407 static void setupRELayerCompositionCallExpectations(CompositionTest* test) {
408 Case::Layer::setupInsecureRECompositionCallExpectations(test);
409 }
410
411 template <typename Case>
setupRELayerScreenshotCompositionCallExpectationsandroid::__anon4393af000111::InsecureDisplaySetupVariant412 static void setupRELayerScreenshotCompositionCallExpectations(CompositionTest* test) {
413 Case::Layer::setupInsecureREScreenshotCompositionCallExpectations(test);
414 }
415 };
416
417 struct PoweredOffDisplaySetupVariant : public BaseDisplayVariant<PoweredOffDisplaySetupVariant> {
418 static constexpr hal::PowerMode INIT_POWER_MODE = hal::PowerMode::OFF;
419
420 template <typename Case>
setupPreconditionCallExpectationsandroid::__anon4393af000111::PoweredOffDisplaySetupVariant421 static void setupPreconditionCallExpectations(CompositionTest*) {}
422
423 template <typename Case>
setupCommonCompositionCallExpectationsandroid::__anon4393af000111::PoweredOffDisplaySetupVariant424 static void setupCommonCompositionCallExpectations(CompositionTest* test) {
425 // TODO: This seems like an unnecessary call if display is powered off.
426 EXPECT_CALL(*test->mComposer, setColorTransform(HWC_DISPLAY, IsIdentityMatrix())).Times(1);
427
428 // TODO: This seems like an unnecessary call if display is powered off.
429 Case::CompositionType::setupHwcSetCallExpectations(test);
430 }
431
setupHwcCompositionCallExpectationsandroid::__anon4393af000111::PoweredOffDisplaySetupVariant432 static void setupHwcCompositionCallExpectations(CompositionTest*) {}
setupHwcClientCompositionCallExpectationsandroid::__anon4393af000111::PoweredOffDisplaySetupVariant433 static void setupHwcClientCompositionCallExpectations(CompositionTest*) {}
setupHwcForcedClientCompositionCallExpectationsandroid::__anon4393af000111::PoweredOffDisplaySetupVariant434 static void setupHwcForcedClientCompositionCallExpectations(CompositionTest*) {}
435
setupRECompositionCallExpectationsandroid::__anon4393af000111::PoweredOffDisplaySetupVariant436 static void setupRECompositionCallExpectations(CompositionTest* test) {
437 // TODO: This seems like an unnecessary call if display is powered off.
438 EXPECT_CALL(*test->mDisplaySurface, getClientTargetAcquireFence())
439 .WillRepeatedly(ReturnRef(test->mClientTargetAcquireFence));
440 }
441
442 template <typename Case>
setupRELayerCompositionCallExpectationsandroid::__anon4393af000111::PoweredOffDisplaySetupVariant443 static void setupRELayerCompositionCallExpectations(CompositionTest*) {}
444 };
445
446 /* ------------------------------------------------------------------------
447 * Variants for each layer configuration which can be tested
448 */
449
450 template <typename LayerProperties>
451 struct BaseLayerProperties {
452 static constexpr uint32_t WIDTH = 100;
453 static constexpr uint32_t HEIGHT = 100;
454 static constexpr PixelFormat FORMAT = PIXEL_FORMAT_RGBA_8888;
455 static constexpr uint64_t USAGE =
456 GraphicBuffer::USAGE_SW_READ_NEVER | GraphicBuffer::USAGE_SW_WRITE_NEVER;
457 static constexpr android_dataspace DATASPACE = HAL_DATASPACE_UNKNOWN;
458 static constexpr uint32_t SCALING_MODE = 0;
459 static constexpr uint32_t TRANSFORM = 0;
460 static constexpr uint32_t LAYER_FLAGS = 0;
461 static constexpr float COLOR[] = {1.f, 1.f, 1.f, 1.f};
462 static constexpr IComposerClient::BlendMode BLENDMODE =
463 IComposerClient::BlendMode::PREMULTIPLIED;
464
setupLatchedBufferandroid::__anon4393af000111::BaseLayerProperties465 static void setupLatchedBuffer(CompositionTest* test, sp<Layer> layer) {
466 Mock::VerifyAndClear(test->mRenderEngine);
467
468 const auto buffer = std::make_shared<
469 renderengine::mock::FakeExternalTexture>(LayerProperties::WIDTH,
470 LayerProperties::HEIGHT,
471 DEFAULT_TEXTURE_ID,
472 LayerProperties::FORMAT,
473 LayerProperties::USAGE |
474 GraphicBuffer::USAGE_HW_TEXTURE);
475
476 auto& layerDrawingState = test->mFlinger.mutableLayerDrawingState(layer);
477 layerDrawingState.crop = Rect(0, 0, LayerProperties::HEIGHT, LayerProperties::WIDTH);
478 layerDrawingState.buffer = buffer;
479 layerDrawingState.acquireFence = Fence::NO_FENCE;
480 layerDrawingState.dataspace = ui::Dataspace::UNKNOWN;
481 layer->setSurfaceDamageRegion(
482 Region(Rect(LayerProperties::HEIGHT, LayerProperties::WIDTH)));
483
484 bool ignoredRecomputeVisibleRegions;
485 layer->latchBuffer(ignoredRecomputeVisibleRegions, 0);
486 Mock::VerifyAndClear(test->mRenderEngine);
487 }
488
setupLayerStateandroid::__anon4393af000111::BaseLayerProperties489 static void setupLayerState(CompositionTest* test, sp<Layer> layer) {
490 setupLatchedBuffer(test, layer);
491 }
492
setupHwcSetGeometryCallExpectationsandroid::__anon4393af000111::BaseLayerProperties493 static void setupHwcSetGeometryCallExpectations(CompositionTest* test) {
494 if (!test->mDisplayOff) {
495 // TODO: Coverage of other values
496 EXPECT_CALL(*test->mComposer,
497 setLayerBlendMode(HWC_DISPLAY, HWC_LAYER, LayerProperties::BLENDMODE))
498 .Times(1);
499 // TODO: Coverage of other values for origin
500 EXPECT_CALL(*test->mComposer,
501 setLayerDisplayFrame(HWC_DISPLAY, HWC_LAYER,
502 IComposerClient::Rect({0, 0, LayerProperties::WIDTH,
503 LayerProperties::HEIGHT})))
504 .Times(1);
505 EXPECT_CALL(*test->mComposer,
506 setLayerPlaneAlpha(HWC_DISPLAY, HWC_LAYER, LayerProperties::COLOR[3]))
507 .Times(1);
508 // TODO: Coverage of other values
509 EXPECT_CALL(*test->mComposer, setLayerZOrder(HWC_DISPLAY, HWC_LAYER, 0u)).Times(1);
510
511 // These expectations retire on saturation as the code path these
512 // expectations are for appears to make an extra call to them.
513 // TODO: Investigate this extra call
514 EXPECT_CALL(*test->mComposer,
515 setLayerTransform(HWC_DISPLAY, HWC_LAYER, DEFAULT_TRANSFORM))
516 .Times(AtLeast(1))
517 .RetiresOnSaturation();
518 }
519 }
520
setupHwcSetSourceCropBufferCallExpectationsandroid::__anon4393af000111::BaseLayerProperties521 static void setupHwcSetSourceCropBufferCallExpectations(CompositionTest* test) {
522 if (!test->mDisplayOff) {
523 EXPECT_CALL(*test->mComposer,
524 setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER,
525 IComposerClient::FRect({0.f, 0.f, LayerProperties::WIDTH,
526 LayerProperties::HEIGHT})))
527 .Times(1);
528 }
529 }
530
setupHwcSetSourceCropColorCallExpectationsandroid::__anon4393af000111::BaseLayerProperties531 static void setupHwcSetSourceCropColorCallExpectations(CompositionTest* test) {
532 if (!test->mDisplayOff) {
533 EXPECT_CALL(*test->mComposer,
534 setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER,
535 IComposerClient::FRect({0.f, 0.f, 0.f, 0.f})))
536 .Times(1);
537 }
538 }
539
setupHwcSetPerFrameCallExpectationsandroid::__anon4393af000111::BaseLayerProperties540 static void setupHwcSetPerFrameCallExpectations(CompositionTest* test) {
541 if (!test->mDisplayOff) {
542 EXPECT_CALL(*test->mComposer,
543 setLayerVisibleRegion(HWC_DISPLAY, HWC_LAYER,
544 std::vector<IComposerClient::Rect>(
545 {IComposerClient::Rect(
546 {0, 0, LayerProperties::WIDTH,
547 LayerProperties::HEIGHT})})))
548 .Times(1);
549 }
550 }
551
setupHwcSetPerFrameColorCallExpectationsandroid::__anon4393af000111::BaseLayerProperties552 static void setupHwcSetPerFrameColorCallExpectations(CompositionTest* test) {
553 if (!test->mDisplayOff) {
554 EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _))
555 .Times(1);
556
557 // TODO: use COLOR
558 EXPECT_CALL(*test->mComposer,
559 setLayerColor(HWC_DISPLAY, HWC_LAYER,
560 aidl::android::hardware::graphics::composer3::Color(
561 {1.0f, 1.0f, 1.0f, 1.0f})))
562 .Times(1);
563 }
564 }
565
setupHwcSetPerFrameBufferCallExpectationsandroid::__anon4393af000111::BaseLayerProperties566 static void setupHwcSetPerFrameBufferCallExpectations(CompositionTest* test) {
567 if (!test->mDisplayOff) {
568 EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _))
569 .Times(1);
570 EXPECT_CALL(*test->mComposer, setLayerBuffer(HWC_DISPLAY, HWC_LAYER, _, _, _)).Times(1);
571 }
572 }
573
setupREBufferCompositionCommonCallExpectationsandroid::__anon4393af000111::BaseLayerProperties574 static void setupREBufferCompositionCommonCallExpectations(CompositionTest* test) {
575 EXPECT_CALL(*test->mRenderEngine, drawLayers)
576 .WillOnce([&](const renderengine::DisplaySettings& displaySettings,
577 const std::vector<renderengine::LayerSettings>& layerSettings,
578 const std::shared_ptr<renderengine::ExternalTexture>&,
579 base::unique_fd&&) -> ftl::Future<FenceResult> {
580 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
581 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
582 displaySettings.physicalDisplay);
583 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
584 displaySettings.clip);
585 // screen capture adds an additional color layer as an alpha
586 // prefill, so gtet the back layer.
587 ftl::Future<FenceResult> resultFuture =
588 ftl::yield<FenceResult>(Fence::NO_FENCE);
589 if (layerSettings.empty()) {
590 ADD_FAILURE() << "layerSettings was not expected to be empty in "
591 "setupREBufferCompositionCommonCallExpectations "
592 "verification lambda";
593 return resultFuture;
594 }
595 const renderengine::LayerSettings layer = layerSettings.back();
596 EXPECT_THAT(layer.source.buffer.buffer, Not(IsNull()));
597 EXPECT_THAT(layer.source.buffer.fence, Not(IsNull()));
598 EXPECT_EQ(true, layer.source.buffer.usePremultipliedAlpha);
599 EXPECT_EQ(false, layer.source.buffer.isOpaque);
600 EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius.x);
601 EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius.y);
602 EXPECT_EQ(ui::Dataspace::V0_SRGB, layer.sourceDataspace);
603 EXPECT_EQ(LayerProperties::COLOR[3], layer.alpha);
604 return resultFuture;
605 });
606 }
607
setupREBufferCompositionCallExpectationsandroid::__anon4393af000111::BaseLayerProperties608 static void setupREBufferCompositionCallExpectations(CompositionTest* test) {
609 LayerProperties::setupREBufferCompositionCommonCallExpectations(test);
610 }
611
setupInsecureREBufferCompositionCallExpectationsandroid::__anon4393af000111::BaseLayerProperties612 static void setupInsecureREBufferCompositionCallExpectations(CompositionTest* test) {
613 setupREBufferCompositionCallExpectations(test);
614 }
615
setupREBufferScreenshotCompositionCallExpectationsandroid::__anon4393af000111::BaseLayerProperties616 static void setupREBufferScreenshotCompositionCallExpectations(CompositionTest* test) {
617 LayerProperties::setupREBufferCompositionCommonCallExpectations(test);
618 }
619
setupInsecureREBufferScreenshotCompositionCallExpectationsandroid::__anon4393af000111::BaseLayerProperties620 static void setupInsecureREBufferScreenshotCompositionCallExpectations(CompositionTest* test) {
621 LayerProperties::setupREBufferCompositionCommonCallExpectations(test);
622 }
623
setupREColorCompositionCallExpectationsandroid::__anon4393af000111::BaseLayerProperties624 static void setupREColorCompositionCallExpectations(CompositionTest* test) {
625 EXPECT_CALL(*test->mRenderEngine, drawLayers)
626 .WillOnce([&](const renderengine::DisplaySettings& displaySettings,
627 const std::vector<renderengine::LayerSettings>& layerSettings,
628 const std::shared_ptr<renderengine::ExternalTexture>&,
629 base::unique_fd&&) -> ftl::Future<FenceResult> {
630 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
631 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
632 displaySettings.physicalDisplay);
633 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
634 displaySettings.clip);
635 // screen capture adds an additional color layer as an alpha
636 // prefill, so get the back layer.
637 ftl::Future<FenceResult> resultFuture =
638 ftl::yield<FenceResult>(Fence::NO_FENCE);
639 if (layerSettings.empty()) {
640 ADD_FAILURE()
641 << "layerSettings was not expected to be empty in "
642 "setupREColorCompositionCallExpectations verification lambda";
643 return resultFuture;
644 }
645 const renderengine::LayerSettings layer = layerSettings.back();
646 EXPECT_THAT(layer.source.buffer.buffer, IsNull());
647 EXPECT_EQ(half3(LayerProperties::COLOR[0], LayerProperties::COLOR[1],
648 LayerProperties::COLOR[2]),
649 layer.source.solidColor);
650 EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius.x);
651 EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius.y);
652 EXPECT_EQ(ui::Dataspace::V0_SRGB, layer.sourceDataspace);
653 EXPECT_EQ(LayerProperties::COLOR[3], layer.alpha);
654 return resultFuture;
655 });
656 }
657
setupREColorScreenshotCompositionCallExpectationsandroid::__anon4393af000111::BaseLayerProperties658 static void setupREColorScreenshotCompositionCallExpectations(CompositionTest* test) {
659 setupREColorCompositionCallExpectations(test);
660 }
661 };
662
663 struct DefaultLayerProperties : public BaseLayerProperties<DefaultLayerProperties> {};
664
665 struct EffectLayerProperties : public BaseLayerProperties<EffectLayerProperties> {
666 static constexpr IComposerClient::BlendMode BLENDMODE = IComposerClient::BlendMode::NONE;
667 };
668
669 struct SidebandLayerProperties : public BaseLayerProperties<SidebandLayerProperties> {
670 using Base = BaseLayerProperties<SidebandLayerProperties>;
671 static constexpr IComposerClient::BlendMode BLENDMODE = IComposerClient::BlendMode::NONE;
672
setupLayerStateandroid::__anon4393af000111::SidebandLayerProperties673 static void setupLayerState(CompositionTest* test, sp<Layer> layer) {
674 sp<NativeHandle> stream =
675 NativeHandle::create(reinterpret_cast<native_handle_t*>(DEFAULT_SIDEBAND_STREAM),
676 false);
677 test->mFlinger.setLayerSidebandStream(layer, stream);
678 auto& layerDrawingState = test->mFlinger.mutableLayerDrawingState(layer);
679 layerDrawingState.crop =
680 Rect(0, 0, SidebandLayerProperties::HEIGHT, SidebandLayerProperties::WIDTH);
681 }
682
setupHwcSetSourceCropBufferCallExpectationsandroid::__anon4393af000111::SidebandLayerProperties683 static void setupHwcSetSourceCropBufferCallExpectations(CompositionTest* test) {
684 EXPECT_CALL(*test->mComposer,
685 setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER,
686 IComposerClient::FRect({0.f, 0.f, -1.f, -1.f})))
687 .Times(1);
688 }
689
setupHwcSetPerFrameBufferCallExpectationsandroid::__anon4393af000111::SidebandLayerProperties690 static void setupHwcSetPerFrameBufferCallExpectations(CompositionTest* test) {
691 EXPECT_CALL(*test->mComposer,
692 setLayerSidebandStream(HWC_DISPLAY, HWC_LAYER,
693 reinterpret_cast<native_handle_t*>(
694 DEFAULT_SIDEBAND_STREAM)))
695 .WillOnce(Return(Error::NONE));
696
697 EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _)).Times(1);
698 }
699
setupREBufferCompositionCommonCallExpectationsandroid::__anon4393af000111::SidebandLayerProperties700 static void setupREBufferCompositionCommonCallExpectations(CompositionTest* /*test*/) {}
701 };
702
703 template <typename LayerProperties>
704 struct CommonSecureLayerProperties : public BaseLayerProperties<LayerProperties> {
705 using Base = BaseLayerProperties<LayerProperties>;
706
setupInsecureREBufferCompositionCommonCallExpectationsandroid::__anon4393af000111::CommonSecureLayerProperties707 static void setupInsecureREBufferCompositionCommonCallExpectations(CompositionTest* test) {
708 EXPECT_CALL(*test->mRenderEngine, drawLayers)
709 .WillOnce([&](const renderengine::DisplaySettings& displaySettings,
710 const std::vector<renderengine::LayerSettings>& layerSettings,
711 const std::shared_ptr<renderengine::ExternalTexture>&,
712 base::unique_fd&&) -> ftl::Future<FenceResult> {
713 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
714 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
715 displaySettings.physicalDisplay);
716 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
717 displaySettings.clip);
718 // screen capture adds an additional color layer as an alpha
719 // prefill, so get the back layer.
720 ftl::Future<FenceResult> resultFuture =
721 ftl::yield<FenceResult>(Fence::NO_FENCE);
722 if (layerSettings.empty()) {
723 ADD_FAILURE() << "layerSettings was not expected to be empty in "
724 "setupInsecureREBufferCompositionCommonCallExpectations "
725 "verification lambda";
726 return resultFuture;
727 }
728 const renderengine::LayerSettings layer = layerSettings.back();
729 EXPECT_THAT(layer.source.buffer.buffer, IsNull());
730 EXPECT_EQ(half3(0.0f, 0.0f, 0.0f), layer.source.solidColor);
731 EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius.x);
732 EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius.y);
733 EXPECT_EQ(ui::Dataspace::V0_SRGB, layer.sourceDataspace);
734 EXPECT_EQ(1.0f, layer.alpha);
735 return resultFuture;
736 });
737 }
738
setupInsecureREBufferCompositionCallExpectationsandroid::__anon4393af000111::CommonSecureLayerProperties739 static void setupInsecureREBufferCompositionCallExpectations(CompositionTest* test) {
740 setupInsecureREBufferCompositionCommonCallExpectations(test);
741 }
742
setupInsecureREBufferScreenshotCompositionCallExpectationsandroid::__anon4393af000111::CommonSecureLayerProperties743 static void setupInsecureREBufferScreenshotCompositionCallExpectations(CompositionTest* test) {
744 setupInsecureREBufferCompositionCommonCallExpectations(test);
745 }
746 };
747
748 struct ParentSecureLayerProperties
749 : public CommonSecureLayerProperties<ParentSecureLayerProperties> {};
750
751 struct SecureLayerProperties : public CommonSecureLayerProperties<SecureLayerProperties> {
752 static constexpr uint32_t LAYER_FLAGS = ISurfaceComposerClient::eSecure;
753 };
754
755 struct CursorLayerProperties : public BaseLayerProperties<CursorLayerProperties> {
756 using Base = BaseLayerProperties<CursorLayerProperties>;
757
setupLayerStateandroid::__anon4393af000111::CursorLayerProperties758 static void setupLayerState(CompositionTest* test, sp<Layer> layer) {
759 Base::setupLayerState(test, layer);
760 test->mFlinger.setLayerPotentialCursor(layer, true);
761 }
762 };
763
764 struct NoLayerVariant {
765 using FlingerLayerType = sp<Layer>;
766
createLayerandroid::__anon4393af000111::NoLayerVariant767 static FlingerLayerType createLayer(CompositionTest*) { return FlingerLayerType(); }
injectLayerandroid::__anon4393af000111::NoLayerVariant768 static void injectLayer(CompositionTest*, FlingerLayerType) {}
cleanupInjectedLayersandroid::__anon4393af000111::NoLayerVariant769 static void cleanupInjectedLayers(CompositionTest*) {}
770
setupCallExpectationsForDirtyGeometryandroid::__anon4393af000111::NoLayerVariant771 static void setupCallExpectationsForDirtyGeometry(CompositionTest*) {}
setupCallExpectationsForDirtyFrameandroid::__anon4393af000111::NoLayerVariant772 static void setupCallExpectationsForDirtyFrame(CompositionTest*) {}
773 };
774
775 template <typename LayerProperties>
776 struct BaseLayerVariant {
777 template <typename L, typename F>
createLayerWithFactoryandroid::__anon4393af000111::BaseLayerVariant778 static sp<L> createLayerWithFactory(CompositionTest* test, F factory) {
779 EXPECT_CALL(*test->mFlinger.scheduler(), postMessage(_)).Times(0);
780
781 sp<L> layer = factory();
782
783 // Layer should be registered with scheduler.
784 EXPECT_EQ(1u, test->mFlinger.scheduler()->layerHistorySize());
785
786 Mock::VerifyAndClear(test->mComposer);
787 Mock::VerifyAndClear(test->mRenderEngine);
788 Mock::VerifyAndClearExpectations(test->mFlinger.scheduler());
789
790 initLayerDrawingStateAndComputeBounds(test, layer);
791
792 return layer;
793 }
794
795 template <typename L>
initLayerDrawingStateAndComputeBoundsandroid::__anon4393af000111::BaseLayerVariant796 static void initLayerDrawingStateAndComputeBounds(CompositionTest* test, sp<L> layer) {
797 auto& layerDrawingState = test->mFlinger.mutableLayerDrawingState(layer);
798 layerDrawingState.layerStack = LAYER_STACK;
799 layerDrawingState.color = half4(LayerProperties::COLOR[0], LayerProperties::COLOR[1],
800 LayerProperties::COLOR[2], LayerProperties::COLOR[3]);
801 layer->computeBounds(FloatRect(0, 0, 100, 100), ui::Transform(), 0.f /* shadowRadius */);
802 }
803
injectLayerandroid::__anon4393af000111::BaseLayerVariant804 static void injectLayer(CompositionTest* test, sp<Layer> layer) {
805 EXPECT_CALL(*test->mComposer, createLayer(HWC_DISPLAY, _))
806 .WillOnce(DoAll(SetArgPointee<1>(HWC_LAYER), Return(Error::NONE)));
807
808 auto outputLayer = test->mDisplay->getCompositionDisplay()->injectOutputLayerForTest(
809 layer->getCompositionEngineLayerFE());
810 outputLayer->editState().visibleRegion = Region(Rect(0, 0, 100, 100));
811 outputLayer->editState().outputSpaceVisibleRegion = Region(Rect(0, 0, 100, 100));
812
813 Mock::VerifyAndClear(test->mComposer);
814
815 test->mFlinger.mutableDrawingState().layersSortedByZ.add(layer);
816 test->mFlinger.mutableVisibleRegionsDirty() = true;
817 }
818
cleanupInjectedLayersandroid::__anon4393af000111::BaseLayerVariant819 static void cleanupInjectedLayers(CompositionTest* test) {
820 EXPECT_CALL(*test->mComposer, destroyLayer(HWC_DISPLAY, HWC_LAYER))
821 .WillOnce(Return(Error::NONE));
822
823 test->mDisplay->getCompositionDisplay()->clearOutputLayers();
824 test->mFlinger.mutableDrawingState().layersSortedByZ.clear();
825 test->mFlinger.mutablePreviouslyComposedLayers().clear();
826
827 // Layer should be unregistered with scheduler.
828 test->mFlinger.commit();
829 EXPECT_EQ(0u, test->mFlinger.scheduler()->layerHistorySize());
830 }
831 };
832
833 template <typename LayerProperties>
834 struct EffectLayerVariant : public BaseLayerVariant<LayerProperties> {
835 using Base = BaseLayerVariant<LayerProperties>;
836 using FlingerLayerType = sp<Layer>;
837
createLayerandroid::__anon4393af000111::EffectLayerVariant838 static FlingerLayerType createLayer(CompositionTest* test) {
839 FlingerLayerType layer = Base::template createLayerWithFactory<Layer>(test, [test]() {
840 return sp<Layer>::make(LayerCreationArgs(test->mFlinger.flinger(), sp<Client>(),
841 "test-layer", LayerProperties::LAYER_FLAGS,
842 LayerMetadata()));
843 });
844
845 auto& layerDrawingState = test->mFlinger.mutableLayerDrawingState(layer);
846 layerDrawingState.crop = Rect(0, 0, LayerProperties::HEIGHT, LayerProperties::WIDTH);
847 return layer;
848 }
849
setupRECompositionCallExpectationsandroid::__anon4393af000111::EffectLayerVariant850 static void setupRECompositionCallExpectations(CompositionTest* test) {
851 LayerProperties::setupREColorCompositionCallExpectations(test);
852 }
853
setupREScreenshotCompositionCallExpectationsandroid::__anon4393af000111::EffectLayerVariant854 static void setupREScreenshotCompositionCallExpectations(CompositionTest* test) {
855 LayerProperties::setupREColorScreenshotCompositionCallExpectations(test);
856 }
857
setupCallExpectationsForDirtyGeometryandroid::__anon4393af000111::EffectLayerVariant858 static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) {
859 LayerProperties::setupHwcSetGeometryCallExpectations(test);
860 LayerProperties::setupHwcSetSourceCropColorCallExpectations(test);
861 }
862
setupCallExpectationsForDirtyFrameandroid::__anon4393af000111::EffectLayerVariant863 static void setupCallExpectationsForDirtyFrame(CompositionTest* test) {
864 LayerProperties::setupHwcSetPerFrameCallExpectations(test);
865 LayerProperties::setupHwcSetPerFrameColorCallExpectations(test);
866 }
867 };
868
869 template <typename LayerProperties>
870 struct BufferLayerVariant : public BaseLayerVariant<LayerProperties> {
871 using Base = BaseLayerVariant<LayerProperties>;
872 using FlingerLayerType = sp<Layer>;
873
createLayerandroid::__anon4393af000111::BufferLayerVariant874 static FlingerLayerType createLayer(CompositionTest* test) {
875 FlingerLayerType layer = Base::template createLayerWithFactory<Layer>(test, [test]() {
876 LayerCreationArgs args(test->mFlinger.flinger(), sp<Client>(), "test-layer",
877 LayerProperties::LAYER_FLAGS, LayerMetadata());
878 return sp<Layer>::make(args);
879 });
880
881 LayerProperties::setupLayerState(test, layer);
882
883 return layer;
884 }
885
cleanupInjectedLayersandroid::__anon4393af000111::BufferLayerVariant886 static void cleanupInjectedLayers(CompositionTest* test) {
887 Base::cleanupInjectedLayers(test);
888 }
889
setupCallExpectationsForDirtyGeometryandroid::__anon4393af000111::BufferLayerVariant890 static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) {
891 LayerProperties::setupHwcSetGeometryCallExpectations(test);
892 LayerProperties::setupHwcSetSourceCropBufferCallExpectations(test);
893 }
894
setupCallExpectationsForDirtyFrameandroid::__anon4393af000111::BufferLayerVariant895 static void setupCallExpectationsForDirtyFrame(CompositionTest* test) {
896 LayerProperties::setupHwcSetPerFrameCallExpectations(test);
897 LayerProperties::setupHwcSetPerFrameBufferCallExpectations(test);
898 }
899
setupRECompositionCallExpectationsandroid::__anon4393af000111::BufferLayerVariant900 static void setupRECompositionCallExpectations(CompositionTest* test) {
901 LayerProperties::setupREBufferCompositionCallExpectations(test);
902 }
903
setupInsecureRECompositionCallExpectationsandroid::__anon4393af000111::BufferLayerVariant904 static void setupInsecureRECompositionCallExpectations(CompositionTest* test) {
905 LayerProperties::setupInsecureREBufferCompositionCallExpectations(test);
906 }
907
setupREScreenshotCompositionCallExpectationsandroid::__anon4393af000111::BufferLayerVariant908 static void setupREScreenshotCompositionCallExpectations(CompositionTest* test) {
909 LayerProperties::setupREBufferScreenshotCompositionCallExpectations(test);
910 }
911
setupInsecureREScreenshotCompositionCallExpectationsandroid::__anon4393af000111::BufferLayerVariant912 static void setupInsecureREScreenshotCompositionCallExpectations(CompositionTest* test) {
913 LayerProperties::setupInsecureREBufferScreenshotCompositionCallExpectations(test);
914 }
915 };
916
917 template <typename LayerProperties>
918 struct ContainerLayerVariant : public BaseLayerVariant<LayerProperties> {
919 using Base = BaseLayerVariant<LayerProperties>;
920 using FlingerLayerType = sp<Layer>;
921
createLayerandroid::__anon4393af000111::ContainerLayerVariant922 static FlingerLayerType createLayer(CompositionTest* test) {
923 LayerCreationArgs args(test->mFlinger.flinger(), sp<Client>(), "test-container-layer",
924 LayerProperties::LAYER_FLAGS, LayerMetadata());
925 FlingerLayerType layer = sp<Layer>::make(args);
926 Base::template initLayerDrawingStateAndComputeBounds(test, layer);
927 return layer;
928 }
929 };
930
931 template <typename LayerVariant, typename ParentLayerVariant>
932 struct ChildLayerVariant : public LayerVariant {
933 using Base = LayerVariant;
934 using FlingerLayerType = typename LayerVariant::FlingerLayerType;
935 using ParentBase = ParentLayerVariant;
936
createLayerandroid::__anon4393af000111::ChildLayerVariant937 static FlingerLayerType createLayer(CompositionTest* test) {
938 // Need to create child layer first. Otherwise layer history size will be 2.
939 FlingerLayerType layer = Base::createLayer(test);
940
941 typename ParentBase::FlingerLayerType parentLayer = ParentBase::createLayer(test);
942 parentLayer->addChild(layer);
943 test->mFlinger.setLayerDrawingParent(layer, parentLayer);
944
945 test->mAuxiliaryLayers.push_back(parentLayer);
946
947 return layer;
948 }
949
cleanupInjectedLayersandroid::__anon4393af000111::ChildLayerVariant950 static void cleanupInjectedLayers(CompositionTest* test) {
951 // Clear auxiliary layers first so that child layer can be successfully destroyed in the
952 // following call.
953 test->mAuxiliaryLayers.clear();
954
955 Base::cleanupInjectedLayers(test);
956 }
957 };
958
959 /* ------------------------------------------------------------------------
960 * Variants to control how the composition type is changed
961 */
962
963 struct NoCompositionTypeVariant {
setupHwcSetCallExpectationsandroid::__anon4393af000111::NoCompositionTypeVariant964 static void setupHwcSetCallExpectations(CompositionTest*) {}
965
setupHwcGetCallExpectationsandroid::__anon4393af000111::NoCompositionTypeVariant966 static void setupHwcGetCallExpectations(CompositionTest* test) {
967 EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _)).Times(1);
968 }
969 };
970
971 template <aidl::android::hardware::graphics::composer3::Composition CompositionType>
972 struct KeepCompositionTypeVariant {
973 static constexpr aidl::android::hardware::graphics::composer3::Composition TYPE =
974 CompositionType;
975
setupHwcSetCallExpectationsandroid::__anon4393af000111::KeepCompositionTypeVariant976 static void setupHwcSetCallExpectations(CompositionTest* test) {
977 if (!test->mDisplayOff) {
978 EXPECT_CALL(*test->mComposer,
979 setLayerCompositionType(HWC_DISPLAY, HWC_LAYER, CompositionType))
980 .Times(1);
981 }
982 }
983
setupHwcGetCallExpectationsandroid::__anon4393af000111::KeepCompositionTypeVariant984 static void setupHwcGetCallExpectations(CompositionTest* test) {
985 EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _)).Times(1);
986 }
987 };
988
989 template <aidl::android::hardware::graphics::composer3::Composition InitialCompositionType,
990 aidl::android::hardware::graphics::composer3::Composition FinalCompositionType>
991 struct ChangeCompositionTypeVariant {
992 static constexpr aidl::android::hardware::graphics::composer3::Composition TYPE =
993 FinalCompositionType;
994
setupHwcSetCallExpectationsandroid::__anon4393af000111::ChangeCompositionTypeVariant995 static void setupHwcSetCallExpectations(CompositionTest* test) {
996 if (!test->mDisplayOff) {
997 EXPECT_CALL(*test->mComposer,
998 setLayerCompositionType(HWC_DISPLAY, HWC_LAYER, InitialCompositionType))
999 .Times(1);
1000 }
1001 }
1002
setupHwcGetCallExpectationsandroid::__anon4393af000111::ChangeCompositionTypeVariant1003 static void setupHwcGetCallExpectations(CompositionTest* test) {
1004 EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _))
1005 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::Layer>{
1006 static_cast<Hwc2::Layer>(HWC_LAYER)}),
1007 SetArgPointee<2>(
1008 std::vector<aidl::android::hardware::graphics::composer3::
1009 Composition>{FinalCompositionType}),
1010 Return(Error::NONE)));
1011 }
1012 };
1013
1014 /* ------------------------------------------------------------------------
1015 * Variants to select how the composition is expected to be handled
1016 */
1017
1018 struct CompositionResultBaseVariant {
setupLayerStateandroid::__anon4393af000111::CompositionResultBaseVariant1019 static void setupLayerState(CompositionTest*, sp<Layer>) {}
1020
1021 template <typename Case>
setupCallExpectationsForDirtyGeometryandroid::__anon4393af000111::CompositionResultBaseVariant1022 static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) {
1023 Case::Layer::setupCallExpectationsForDirtyGeometry(test);
1024 }
1025
1026 template <typename Case>
setupCallExpectationsForDirtyFrameandroid::__anon4393af000111::CompositionResultBaseVariant1027 static void setupCallExpectationsForDirtyFrame(CompositionTest* test) {
1028 Case::Layer::setupCallExpectationsForDirtyFrame(test);
1029 }
1030 };
1031
1032 struct NoCompositionResultVariant : public CompositionResultBaseVariant {
1033 template <typename Case>
setupCallExpectationsandroid::__anon4393af000111::NoCompositionResultVariant1034 static void setupCallExpectations(CompositionTest* test) {
1035 Case::Display::setupEmptyFrameCompositionCallExpectations(test);
1036 Case::Display::setupHwcCompositionCallExpectations(test);
1037 }
1038 };
1039
1040 struct HwcCompositionResultVariant : public CompositionResultBaseVariant {
1041 template <typename Case>
setupCallExpectationsandroid::__anon4393af000111::HwcCompositionResultVariant1042 static void setupCallExpectations(CompositionTest* test) {
1043 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
1044 Case::Display::setupHwcCompositionCallExpectations(test);
1045 }
1046 };
1047
1048 struct RECompositionResultVariant : public CompositionResultBaseVariant {
1049 template <typename Case>
setupCallExpectationsandroid::__anon4393af000111::RECompositionResultVariant1050 static void setupCallExpectations(CompositionTest* test) {
1051 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
1052 Case::Display::setupHwcClientCompositionCallExpectations(test);
1053 Case::Display::setupRECompositionCallExpectations(test);
1054 Case::Display::template setupRELayerCompositionCallExpectations<Case>(test);
1055 }
1056 };
1057
1058 struct ForcedClientCompositionResultVariant : public CompositionResultBaseVariant {
setupLayerStateandroid::__anon4393af000111::ForcedClientCompositionResultVariant1059 static void setupLayerState(CompositionTest* test, sp<Layer> layer) {
1060 const auto outputLayer =
1061 TestableSurfaceFlinger::findOutputLayerForDisplay(layer, test->mDisplay);
1062 LOG_FATAL_IF(!outputLayer);
1063 outputLayer->editState().forceClientComposition = true;
1064 }
1065
1066 template <typename Case>
setupCallExpectationsandroid::__anon4393af000111::ForcedClientCompositionResultVariant1067 static void setupCallExpectations(CompositionTest* test) {
1068 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
1069 Case::Display::setupHwcForcedClientCompositionCallExpectations(test);
1070 Case::Display::setupRECompositionCallExpectations(test);
1071 Case::Display::template setupRELayerCompositionCallExpectations<Case>(test);
1072 }
1073
1074 template <typename Case>
setupCallExpectationsForDirtyGeometryandroid::__anon4393af000111::ForcedClientCompositionResultVariant1075 static void setupCallExpectationsForDirtyGeometry(CompositionTest*) {}
1076
1077 template <typename Case>
setupCallExpectationsForDirtyFrameandroid::__anon4393af000111::ForcedClientCompositionResultVariant1078 static void setupCallExpectationsForDirtyFrame(CompositionTest*) {}
1079 };
1080
1081 struct ForcedClientCompositionViaDebugOptionResultVariant : public CompositionResultBaseVariant {
setupLayerStateandroid::__anon4393af000111::ForcedClientCompositionViaDebugOptionResultVariant1082 static void setupLayerState(CompositionTest* test, sp<Layer>) {
1083 test->mFlinger.mutableDebugDisableHWC() = true;
1084 }
1085
1086 template <typename Case>
setupCallExpectationsandroid::__anon4393af000111::ForcedClientCompositionViaDebugOptionResultVariant1087 static void setupCallExpectations(CompositionTest* test) {
1088 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
1089 Case::Display::setupHwcForcedClientCompositionCallExpectations(test);
1090 Case::Display::setupRECompositionCallExpectations(test);
1091 Case::Display::template setupRELayerCompositionCallExpectations<Case>(test);
1092 }
1093
1094 template <typename Case>
setupCallExpectationsForDirtyGeometryandroid::__anon4393af000111::ForcedClientCompositionViaDebugOptionResultVariant1095 static void setupCallExpectationsForDirtyGeometry(CompositionTest*) {}
1096
1097 template <typename Case>
setupCallExpectationsForDirtyFrameandroid::__anon4393af000111::ForcedClientCompositionViaDebugOptionResultVariant1098 static void setupCallExpectationsForDirtyFrame(CompositionTest*) {}
1099 };
1100
1101 struct EmptyScreenshotResultVariant {
setupLayerStateandroid::__anon4393af000111::EmptyScreenshotResultVariant1102 static void setupLayerState(CompositionTest*, sp<Layer>) {}
1103
1104 template <typename Case>
setupCallExpectationsandroid::__anon4393af000111::EmptyScreenshotResultVariant1105 static void setupCallExpectations(CompositionTest*) {}
1106 };
1107
1108 struct REScreenshotResultVariant : public EmptyScreenshotResultVariant {
1109 using Base = EmptyScreenshotResultVariant;
1110
1111 template <typename Case>
setupCallExpectationsandroid::__anon4393af000111::REScreenshotResultVariant1112 static void setupCallExpectations(CompositionTest* test) {
1113 Base::template setupCallExpectations<Case>(test);
1114 Case::Display::template setupRELayerScreenshotCompositionCallExpectations<Case>(test);
1115 }
1116 };
1117
1118 /* ------------------------------------------------------------------------
1119 * Composition test case, containing all the variants being tested
1120 */
1121
1122 template <typename DisplayCase, typename LayerCase, typename CompositionTypeCase,
1123 typename CompositionResultCase>
1124 struct CompositionCase {
1125 using ThisCase =
1126 CompositionCase<DisplayCase, LayerCase, CompositionTypeCase, CompositionResultCase>;
1127 using Display = DisplayCase;
1128 using Layer = LayerCase;
1129 using CompositionType = CompositionTypeCase;
1130 using CompositionResult = CompositionResultCase;
1131
setupCommonandroid::__anon4393af000111::CompositionCase1132 static void setupCommon(CompositionTest* test) {
1133 Display::template setupPreconditionCallExpectations<ThisCase>(test);
1134 Display::setupPreconditions(test);
1135
1136 auto layer = Layer::createLayer(test);
1137 Layer::injectLayer(test, layer);
1138 CompositionResult::setupLayerState(test, layer);
1139 }
1140
setupForDirtyGeometryandroid::__anon4393af000111::CompositionCase1141 static void setupForDirtyGeometry(CompositionTest* test) {
1142 setupCommon(test);
1143
1144 Display::template setupCommonCompositionCallExpectations<ThisCase>(test);
1145 CompositionResult::template setupCallExpectationsForDirtyGeometry<ThisCase>(test);
1146 CompositionResult::template setupCallExpectationsForDirtyFrame<ThisCase>(test);
1147 CompositionResult::template setupCallExpectations<ThisCase>(test);
1148 }
1149
setupForDirtyFrameandroid::__anon4393af000111::CompositionCase1150 static void setupForDirtyFrame(CompositionTest* test) {
1151 setupCommon(test);
1152
1153 Display::template setupCommonCompositionCallExpectations<ThisCase>(test);
1154 CompositionResult::template setupCallExpectationsForDirtyFrame<ThisCase>(test);
1155 CompositionResult::template setupCallExpectations<ThisCase>(test);
1156 }
1157
setupForScreenCaptureandroid::__anon4393af000111::CompositionCase1158 static void setupForScreenCapture(CompositionTest* test) {
1159 setupCommon(test);
1160
1161 Display::template setupCommonScreensCaptureCallExpectations<ThisCase>(test);
1162 CompositionResult::template setupCallExpectations<ThisCase>(test);
1163 }
1164
cleanupandroid::__anon4393af000111::CompositionCase1165 static void cleanup(CompositionTest* test) {
1166 Layer::cleanupInjectedLayers(test);
1167
1168 for (auto& displayData : test->mFlinger.mutableHwcDisplayData()) {
1169 static_cast<TestableSurfaceFlinger::HWC2Display*>(displayData.second.hwcDisplay.get())
1170 ->mutableLayers()
1171 .clear();
1172 }
1173 }
1174 };
1175
1176 /* ------------------------------------------------------------------------
1177 * Composition cases to test
1178 */
1179
TEST_F(CompositionTest,noLayersDoesMinimalWorkWithDirtyGeometry)1180 TEST_F(CompositionTest, noLayersDoesMinimalWorkWithDirtyGeometry) {
1181 displayRefreshCompositionDirtyGeometry<
1182 CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant,
1183 NoCompositionResultVariant>>();
1184 }
1185
TEST_F(CompositionTest,noLayersDoesMinimalWorkWithDirtyFrame)1186 TEST_F(CompositionTest, noLayersDoesMinimalWorkWithDirtyFrame) {
1187 displayRefreshCompositionDirtyFrame<
1188 CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant,
1189 NoCompositionResultVariant>>();
1190 }
1191
TEST_F(CompositionTest,noLayersDoesMinimalWorkToCaptureScreen)1192 TEST_F(CompositionTest, noLayersDoesMinimalWorkToCaptureScreen) {
1193 captureScreenComposition<
1194 CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant,
1195 EmptyScreenshotResultVariant>>();
1196 }
1197
1198 /* ------------------------------------------------------------------------
1199 * Simple buffer layers
1200 */
1201
TEST_F(CompositionTest,HWCComposedNormalBufferLayerWithDirtyGeometry)1202 TEST_F(CompositionTest, HWCComposedNormalBufferLayerWithDirtyGeometry) {
1203 displayRefreshCompositionDirtyGeometry<CompositionCase<
1204 DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1205 KeepCompositionTypeVariant<
1206 aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
1207 HwcCompositionResultVariant>>();
1208 }
1209
TEST_F(CompositionTest,HWCComposedNormalBufferLayerWithDirtyFrame)1210 TEST_F(CompositionTest, HWCComposedNormalBufferLayerWithDirtyFrame) {
1211 displayRefreshCompositionDirtyFrame<CompositionCase<
1212 DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1213 KeepCompositionTypeVariant<
1214 aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
1215 HwcCompositionResultVariant>>();
1216 }
1217
TEST_F(CompositionTest,REComposedNormalBufferLayer)1218 TEST_F(CompositionTest, REComposedNormalBufferLayer) {
1219 displayRefreshCompositionDirtyFrame<CompositionCase<
1220 DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1221 ChangeCompositionTypeVariant<
1222 aidl::android::hardware::graphics::composer3::Composition::DEVICE,
1223 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1224 RECompositionResultVariant>>();
1225 }
1226
TEST_F(CompositionTest,captureScreenNormalBufferLayer)1227 TEST_F(CompositionTest, captureScreenNormalBufferLayer) {
1228 captureScreenComposition<
1229 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1230 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1231 }
1232
1233 /* ------------------------------------------------------------------------
1234 * Single-color layers
1235 */
1236
TEST_F(CompositionTest,HWCComposedEffectLayerWithDirtyGeometry)1237 TEST_F(CompositionTest, HWCComposedEffectLayerWithDirtyGeometry) {
1238 displayRefreshCompositionDirtyGeometry<CompositionCase<
1239 DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
1240 KeepCompositionTypeVariant<
1241 aidl::android::hardware::graphics::composer3::Composition::SOLID_COLOR>,
1242 HwcCompositionResultVariant>>();
1243 }
1244
TEST_F(CompositionTest,HWCComposedEffectLayerWithDirtyFrame)1245 TEST_F(CompositionTest, HWCComposedEffectLayerWithDirtyFrame) {
1246 displayRefreshCompositionDirtyFrame<CompositionCase<
1247 DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
1248 KeepCompositionTypeVariant<
1249 aidl::android::hardware::graphics::composer3::Composition::SOLID_COLOR>,
1250 HwcCompositionResultVariant>>();
1251 }
1252
TEST_F(CompositionTest,REComposedEffectLayer)1253 TEST_F(CompositionTest, REComposedEffectLayer) {
1254 displayRefreshCompositionDirtyFrame<CompositionCase<
1255 DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
1256 ChangeCompositionTypeVariant<
1257 aidl::android::hardware::graphics::composer3::Composition::SOLID_COLOR,
1258 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1259 RECompositionResultVariant>>();
1260 }
1261
TEST_F(CompositionTest,captureScreenEffectLayer)1262 TEST_F(CompositionTest, captureScreenEffectLayer) {
1263 captureScreenComposition<
1264 CompositionCase<DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
1265 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1266 }
1267
1268 /* ------------------------------------------------------------------------
1269 * Layers with sideband buffers
1270 */
1271
TEST_F(CompositionTest,HWCComposedSidebandBufferLayerWithDirtyGeometry)1272 TEST_F(CompositionTest, HWCComposedSidebandBufferLayerWithDirtyGeometry) {
1273 displayRefreshCompositionDirtyGeometry<CompositionCase<
1274 DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1275 KeepCompositionTypeVariant<
1276 aidl::android::hardware::graphics::composer3::Composition::SIDEBAND>,
1277 HwcCompositionResultVariant>>();
1278 }
1279
TEST_F(CompositionTest,HWCComposedSidebandBufferLayerWithDirtyFrame)1280 TEST_F(CompositionTest, HWCComposedSidebandBufferLayerWithDirtyFrame) {
1281 displayRefreshCompositionDirtyFrame<CompositionCase<
1282 DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1283 KeepCompositionTypeVariant<
1284 aidl::android::hardware::graphics::composer3::Composition::SIDEBAND>,
1285 HwcCompositionResultVariant>>();
1286 }
1287
TEST_F(CompositionTest,REComposedSidebandBufferLayer)1288 TEST_F(CompositionTest, REComposedSidebandBufferLayer) {
1289 displayRefreshCompositionDirtyFrame<CompositionCase<
1290 DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1291 ChangeCompositionTypeVariant<
1292 aidl::android::hardware::graphics::composer3::Composition::SIDEBAND,
1293 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1294 RECompositionResultVariant>>();
1295 }
1296
TEST_F(CompositionTest,captureScreenSidebandBufferLayer)1297 TEST_F(CompositionTest, captureScreenSidebandBufferLayer) {
1298 captureScreenComposition<
1299 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1300 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1301 }
1302
1303 /* ------------------------------------------------------------------------
1304 * Layers with ISurfaceComposerClient::eSecure, on a secure display
1305 */
1306
TEST_F(CompositionTest,HWCComposedSecureBufferLayerWithDirtyGeometry)1307 TEST_F(CompositionTest, HWCComposedSecureBufferLayerWithDirtyGeometry) {
1308 displayRefreshCompositionDirtyGeometry<CompositionCase<
1309 DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1310 KeepCompositionTypeVariant<
1311 aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
1312 HwcCompositionResultVariant>>();
1313 }
1314
TEST_F(CompositionTest,HWCComposedSecureBufferLayerWithDirtyFrame)1315 TEST_F(CompositionTest, HWCComposedSecureBufferLayerWithDirtyFrame) {
1316 displayRefreshCompositionDirtyFrame<CompositionCase<
1317 DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1318 KeepCompositionTypeVariant<
1319 aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
1320 HwcCompositionResultVariant>>();
1321 }
1322
TEST_F(CompositionTest,REComposedSecureBufferLayer)1323 TEST_F(CompositionTest, REComposedSecureBufferLayer) {
1324 displayRefreshCompositionDirtyFrame<CompositionCase<
1325 DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1326 ChangeCompositionTypeVariant<
1327 aidl::android::hardware::graphics::composer3::Composition::DEVICE,
1328 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1329 RECompositionResultVariant>>();
1330 }
1331
TEST_F(CompositionTest,captureScreenSecureBufferLayerOnSecureDisplay)1332 TEST_F(CompositionTest, captureScreenSecureBufferLayerOnSecureDisplay) {
1333 captureScreenComposition<
1334 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1335 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1336 }
1337
1338 /* ------------------------------------------------------------------------
1339 * Layers with ISurfaceComposerClient::eSecure, on a non-secure display
1340 */
1341
TEST_F(CompositionTest,HWCComposedSecureBufferLayerOnInsecureDisplayWithDirtyGeometry)1342 TEST_F(CompositionTest, HWCComposedSecureBufferLayerOnInsecureDisplayWithDirtyGeometry) {
1343 displayRefreshCompositionDirtyGeometry<CompositionCase<
1344 InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1345 KeepCompositionTypeVariant<
1346 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1347 ForcedClientCompositionResultVariant>>();
1348 }
1349
TEST_F(CompositionTest,HWCComposedSecureBufferLayerOnInsecureDisplayWithDirtyFrame)1350 TEST_F(CompositionTest, HWCComposedSecureBufferLayerOnInsecureDisplayWithDirtyFrame) {
1351 displayRefreshCompositionDirtyFrame<CompositionCase<
1352 InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1353 KeepCompositionTypeVariant<
1354 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1355 ForcedClientCompositionResultVariant>>();
1356 }
1357
TEST_F(CompositionTest,captureScreenSecureBufferLayerOnInsecureDisplay)1358 TEST_F(CompositionTest, captureScreenSecureBufferLayerOnInsecureDisplay) {
1359 captureScreenComposition<
1360 CompositionCase<InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1361 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1362 }
1363
1364 /* ------------------------------------------------------------------------
1365 * Layers with a parent layer with ISurfaceComposerClient::eSecure, on a non-secure display
1366 */
1367
TEST_F(CompositionTest,HWCComposedBufferLayerWithSecureParentLayerOnInsecureDisplayWithDirtyGeometry)1368 TEST_F(CompositionTest,
1369 HWCComposedBufferLayerWithSecureParentLayerOnInsecureDisplayWithDirtyGeometry) {
1370 displayRefreshCompositionDirtyGeometry<CompositionCase<
1371 InsecureDisplaySetupVariant,
1372 ChildLayerVariant<BufferLayerVariant<ParentSecureLayerProperties>,
1373 ContainerLayerVariant<SecureLayerProperties>>,
1374 KeepCompositionTypeVariant<
1375 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1376 ForcedClientCompositionResultVariant>>();
1377 }
1378
TEST_F(CompositionTest,HWCComposedBufferLayerWithSecureParentLayerOnInsecureDisplayWithDirtyFrame)1379 TEST_F(CompositionTest,
1380 HWCComposedBufferLayerWithSecureParentLayerOnInsecureDisplayWithDirtyFrame) {
1381 displayRefreshCompositionDirtyFrame<CompositionCase<
1382 InsecureDisplaySetupVariant,
1383 ChildLayerVariant<BufferLayerVariant<ParentSecureLayerProperties>,
1384 ContainerLayerVariant<SecureLayerProperties>>,
1385 KeepCompositionTypeVariant<
1386 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1387 ForcedClientCompositionResultVariant>>();
1388 }
1389
TEST_F(CompositionTest,captureScreenBufferLayerWithSecureParentLayerOnInsecureDisplay)1390 TEST_F(CompositionTest, captureScreenBufferLayerWithSecureParentLayerOnInsecureDisplay) {
1391 captureScreenComposition<
1392 CompositionCase<InsecureDisplaySetupVariant,
1393 ChildLayerVariant<BufferLayerVariant<ParentSecureLayerProperties>,
1394 ContainerLayerVariant<SecureLayerProperties>>,
1395 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1396 }
1397
1398 /* ------------------------------------------------------------------------
1399 * Cursor layers
1400 */
1401
TEST_F(CompositionTest,HWCComposedCursorLayerWithDirtyGeometry)1402 TEST_F(CompositionTest, HWCComposedCursorLayerWithDirtyGeometry) {
1403 displayRefreshCompositionDirtyGeometry<CompositionCase<
1404 DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1405 KeepCompositionTypeVariant<
1406 aidl::android::hardware::graphics::composer3::Composition::CURSOR>,
1407 HwcCompositionResultVariant>>();
1408 }
1409
TEST_F(CompositionTest,HWCComposedCursorLayerWithDirtyFrame)1410 TEST_F(CompositionTest, HWCComposedCursorLayerWithDirtyFrame) {
1411 displayRefreshCompositionDirtyFrame<CompositionCase<
1412 DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1413 KeepCompositionTypeVariant<
1414 aidl::android::hardware::graphics::composer3::Composition::CURSOR>,
1415 HwcCompositionResultVariant>>();
1416 }
1417
TEST_F(CompositionTest,REComposedCursorLayer)1418 TEST_F(CompositionTest, REComposedCursorLayer) {
1419 displayRefreshCompositionDirtyFrame<CompositionCase<
1420 DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1421 ChangeCompositionTypeVariant<
1422 aidl::android::hardware::graphics::composer3::Composition::CURSOR,
1423 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1424 RECompositionResultVariant>>();
1425 }
1426
TEST_F(CompositionTest,captureScreenCursorLayer)1427 TEST_F(CompositionTest, captureScreenCursorLayer) {
1428 captureScreenComposition<
1429 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1430 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1431 }
1432
1433 /* ------------------------------------------------------------------------
1434 * Simple buffer layer on a display which is powered off.
1435 */
1436
TEST_F(CompositionTest,displayOffHWCComposedNormalBufferLayerWithDirtyGeometry)1437 TEST_F(CompositionTest, displayOffHWCComposedNormalBufferLayerWithDirtyGeometry) {
1438 mDisplayOff = true;
1439 displayRefreshCompositionDirtyGeometry<CompositionCase<
1440 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1441 KeepCompositionTypeVariant<
1442 aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
1443 HwcCompositionResultVariant>>();
1444 }
1445
TEST_F(CompositionTest,displayOffHWCComposedNormalBufferLayerWithDirtyFrame)1446 TEST_F(CompositionTest, displayOffHWCComposedNormalBufferLayerWithDirtyFrame) {
1447 mDisplayOff = true;
1448 displayRefreshCompositionDirtyFrame<CompositionCase<
1449 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1450 KeepCompositionTypeVariant<
1451 aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
1452 HwcCompositionResultVariant>>();
1453 }
1454
TEST_F(CompositionTest,displayOffREComposedNormalBufferLayer)1455 TEST_F(CompositionTest, displayOffREComposedNormalBufferLayer) {
1456 mDisplayOff = true;
1457 displayRefreshCompositionDirtyFrame<CompositionCase<
1458 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1459 ChangeCompositionTypeVariant<
1460 aidl::android::hardware::graphics::composer3::Composition::DEVICE,
1461 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1462 RECompositionResultVariant>>();
1463 }
1464
TEST_F(CompositionTest,captureScreenNormalBufferLayerOnPoweredOffDisplay)1465 TEST_F(CompositionTest, captureScreenNormalBufferLayerOnPoweredOffDisplay) {
1466 captureScreenComposition<CompositionCase<
1467 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1468 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1469 }
1470
1471 /* ------------------------------------------------------------------------
1472 * Client composition forced through debug/developer settings
1473 */
1474
TEST_F(CompositionTest,DebugOptionForcingClientCompositionOfBufferLayerWithDirtyGeometry)1475 TEST_F(CompositionTest, DebugOptionForcingClientCompositionOfBufferLayerWithDirtyGeometry) {
1476 displayRefreshCompositionDirtyGeometry<CompositionCase<
1477 DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1478 KeepCompositionTypeVariant<
1479 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1480 ForcedClientCompositionViaDebugOptionResultVariant>>();
1481 }
1482
TEST_F(CompositionTest,DebugOptionForcingClientCompositionOfBufferLayerWithDirtyFrame)1483 TEST_F(CompositionTest, DebugOptionForcingClientCompositionOfBufferLayerWithDirtyFrame) {
1484 displayRefreshCompositionDirtyFrame<CompositionCase<
1485 DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1486 KeepCompositionTypeVariant<
1487 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1488 ForcedClientCompositionViaDebugOptionResultVariant>>();
1489 }
1490
1491 } // namespace
1492 } // namespace android
1493
1494 // TODO(b/129481165): remove the #pragma below and fix conversion issues
1495 #pragma clang diagnostic pop // ignored "-Wconversion -Wextra"
1496