• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <gmock/gmock.h>
29 #include <gtest/gtest.h>
30 #include <gui/IProducerListener.h>
31 #include <gui/LayerMetadata.h>
32 #include <log/log.h>
33 #include <renderengine/mock/FakeExternalTexture.h>
34 #include <renderengine/mock/Framebuffer.h>
35 #include <renderengine/mock/Image.h>
36 #include <renderengine/mock/RenderEngine.h>
37 #include <system/window.h>
38 #include <utils/String8.h>
39 
40 #include "DisplayRenderArea.h"
41 #include "Layer.h"
42 #include "TestableSurfaceFlinger.h"
43 #include "mock/DisplayHardware/MockComposer.h"
44 #include "mock/DisplayHardware/MockPowerAdvisor.h"
45 #include "mock/MockEventThread.h"
46 #include "mock/MockTimeStats.h"
47 #include "mock/MockVsyncController.h"
48 #include "mock/system/window/MockNativeWindow.h"
49 
50 namespace android {
51 namespace {
52 
53 namespace hal = android::hardware::graphics::composer::hal;
54 
55 using hal::Error;
56 using hal::IComposer;
57 using hal::IComposerClient;
58 using hal::PowerMode;
59 using hal::Transform;
60 
61 using aidl::android::hardware::graphics::composer3::Capability;
62 
63 using testing::_;
64 using testing::AtLeast;
65 using testing::DoAll;
66 using testing::IsNull;
67 using testing::Mock;
68 using testing::Return;
69 using testing::ReturnRef;
70 using testing::SetArgPointee;
71 
72 using FakeHwcDisplayInjector = TestableSurfaceFlinger::FakeHwcDisplayInjector;
73 using FakeDisplayDeviceInjector = TestableSurfaceFlinger::FakeDisplayDeviceInjector;
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 forSystem = true;
200     constexpr bool regionSampling = false;
201 
202     auto renderArea = DisplayRenderArea::create(mDisplay, sourceCrop, sourceCrop.getSize(),
203                                                 ui::Dataspace::V0_SRGB, true, true);
204 
205     auto traverseLayers = [this](const LayerVector::Visitor& visitor) {
206         return mFlinger.traverseLayersInLayerStack(mDisplay->getLayerStack(),
207                                                    CaptureArgs::UNSET_UID, {}, visitor);
208     };
209 
210     auto getLayerSnapshots = RenderArea::fromTraverseLayersLambda(traverseLayers);
211 
212     const uint32_t usage = GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN |
213             GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_TEXTURE;
214     mCaptureScreenBuffer =
215             std::make_shared<renderengine::mock::FakeExternalTexture>(renderArea->getReqWidth(),
216                                                                       renderArea->getReqHeight(),
217                                                                       HAL_PIXEL_FORMAT_RGBA_8888, 1,
218                                                                       usage);
219 
220     auto future = mFlinger.renderScreenImpl(std::move(renderArea), getLayerSnapshots,
221                                             mCaptureScreenBuffer, forSystem, regionSampling);
222     ASSERT_TRUE(future.valid());
223     const auto fenceResult = future.get();
224 
225     EXPECT_EQ(NO_ERROR, fenceStatus(fenceResult));
226     if (fenceResult.ok()) {
227         fenceResult.value()->waitForever(LOG_TAG);
228     }
229 
230     LayerCase::cleanup(this);
231 }
232 
233 template <class T>
futureOf(T obj)234 std::future<T> futureOf(T obj) {
235     std::promise<T> resultPromise;
236     std::future<T> resultFuture = resultPromise.get_future();
237     resultPromise.set_value(std::move(obj));
238     return resultFuture;
239 }
240 
241 /* ------------------------------------------------------------------------
242  * Variants for each display configuration which can be tested
243  */
244 
245 template <typename Derived>
246 struct BaseDisplayVariant {
247     static constexpr bool IS_SECURE = true;
248     static constexpr hal::PowerMode INIT_POWER_MODE = hal::PowerMode::ON;
249 
setupPreconditionsandroid::__anon9d22d9a50111::BaseDisplayVariant250     static void setupPreconditions(CompositionTest* test) {
251         EXPECT_CALL(*test->mComposer, setPowerMode(HWC_DISPLAY, Derived::INIT_POWER_MODE))
252                 .WillOnce(Return(Error::NONE));
253 
254         FakeHwcDisplayInjector(DEFAULT_DISPLAY_ID, hal::DisplayType::PHYSICAL, true /* isPrimary */)
255                 .setCapabilities(&test->mDefaultCapabilities)
256                 .setPowerMode(Derived::INIT_POWER_MODE)
257                 .inject(&test->mFlinger, test->mComposer);
258         Mock::VerifyAndClear(test->mComposer);
259 
260         EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
261                 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_WIDTH), Return(0)));
262         EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
263                 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_HEIGHT), Return(0)));
264         EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT)).Times(1);
265         EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_API_CONNECT)).Times(1);
266         EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_USAGE64)).Times(1);
267 
268         const ::testing::TestInfo* const test_info =
269                 ::testing::UnitTest::GetInstance()->current_test_info();
270 
271         auto ceDisplayArgs = compositionengine::DisplayCreationArgsBuilder()
272                                      .setId(DEFAULT_DISPLAY_ID)
273                                      .setPixels({DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT})
274                                      .setIsSecure(Derived::IS_SECURE)
275                                      .setPowerAdvisor(test->mPowerAdvisor)
276                                      .setName(std::string("Injected display for ") +
277                                               test_info->test_case_name() + "." + test_info->name())
278                                      .build();
279 
280         auto compositionDisplay =
281                 compositionengine::impl::createDisplay(test->mFlinger.getCompositionEngine(),
282                                                        ceDisplayArgs);
283 
284         constexpr auto kDisplayConnectionType = ui::DisplayConnectionType::Internal;
285         constexpr bool kIsPrimary = true;
286 
287         test->mDisplay =
288                 FakeDisplayDeviceInjector(test->mFlinger, compositionDisplay,
289                                           kDisplayConnectionType, HWC_DISPLAY, kIsPrimary)
290                         .setDisplaySurface(test->mDisplaySurface)
291                         .setNativeWindow(test->mNativeWindow)
292                         .setSecure(Derived::IS_SECURE)
293                         .setPowerMode(Derived::INIT_POWER_MODE)
294                         .setRefreshRateSelector(test->mFlinger.scheduler()->refreshRateSelector())
295                         .skipRegisterDisplay()
296                         .inject();
297         Mock::VerifyAndClear(test->mNativeWindow.get());
298 
299         constexpr bool kIsInternal = kDisplayConnectionType == ui::DisplayConnectionType::Internal;
300         test->mDisplay->setLayerFilter({LAYER_STACK, kIsInternal});
301     }
302 
303     template <typename Case>
setupPreconditionCallExpectationsandroid::__anon9d22d9a50111::BaseDisplayVariant304     static void setupPreconditionCallExpectations(CompositionTest* test) {
305         EXPECT_CALL(*test->mComposer, getDisplayCapabilities(HWC_DISPLAY, _))
306                 .WillOnce(DoAll(SetArgPointee<1>(
307                                         std::vector<aidl::android::hardware::graphics::composer3::
308                                                             DisplayCapability>({})),
309                                 Return(Error::NONE)));
310     }
311 
312     template <typename Case>
setupCommonCompositionCallExpectationsandroid::__anon9d22d9a50111::BaseDisplayVariant313     static void setupCommonCompositionCallExpectations(CompositionTest* test) {
314         EXPECT_CALL(*test->mComposer, setColorTransform(HWC_DISPLAY, IsIdentityMatrix())).Times(1);
315         EXPECT_CALL(*test->mComposer, getDisplayRequests(HWC_DISPLAY, _, _, _)).Times(1);
316         EXPECT_CALL(*test->mComposer, acceptDisplayChanges(HWC_DISPLAY)).Times(1);
317         EXPECT_CALL(*test->mComposer, presentDisplay(HWC_DISPLAY, _)).Times(1);
318         EXPECT_CALL(*test->mComposer, getReleaseFences(HWC_DISPLAY, _, _)).Times(1);
319 
320         EXPECT_CALL(*test->mDisplaySurface, onFrameCommitted()).Times(1);
321         EXPECT_CALL(*test->mDisplaySurface, advanceFrame()).Times(1);
322 
323         Case::CompositionType::setupHwcSetCallExpectations(test);
324         Case::CompositionType::setupHwcGetCallExpectations(test);
325     }
326 
327     template <typename Case>
setupCommonScreensCaptureCallExpectationsandroid::__anon9d22d9a50111::BaseDisplayVariant328     static void setupCommonScreensCaptureCallExpectations(CompositionTest* test) {
329         EXPECT_CALL(*test->mRenderEngine, drawLayers)
330                 .WillRepeatedly([&](const renderengine::DisplaySettings& displaySettings,
331                                     const std::vector<renderengine::LayerSettings>&,
332                                     const std::shared_ptr<renderengine::ExternalTexture>&,
333                                     const bool, base::unique_fd&&) -> std::future<FenceResult> {
334                     EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
335                     EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
336                               displaySettings.physicalDisplay);
337                     EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
338                               displaySettings.clip);
339                     return futureOf<FenceResult>(Fence::NO_FENCE);
340                 });
341     }
342 
setupNonEmptyFrameCompositionCallExpectationsandroid::__anon9d22d9a50111::BaseDisplayVariant343     static void setupNonEmptyFrameCompositionCallExpectations(CompositionTest* test) {
344         EXPECT_CALL(*test->mDisplaySurface, beginFrame(true)).Times(1);
345     }
346 
setupEmptyFrameCompositionCallExpectationsandroid::__anon9d22d9a50111::BaseDisplayVariant347     static void setupEmptyFrameCompositionCallExpectations(CompositionTest* test) {
348         EXPECT_CALL(*test->mDisplaySurface, beginFrame(false)).Times(1);
349     }
350 
setupHwcCompositionCallExpectationsandroid::__anon9d22d9a50111::BaseDisplayVariant351     static void setupHwcCompositionCallExpectations(CompositionTest* test) {
352         EXPECT_CALL(*test->mComposer, presentOrValidateDisplay(HWC_DISPLAY, _, _, _, _, _))
353                 .Times(1);
354 
355         EXPECT_CALL(*test->mDisplaySurface,
356                     prepareFrame(compositionengine::DisplaySurface::CompositionType::Hwc))
357                 .Times(1);
358     }
359 
setupHwcClientCompositionCallExpectationsandroid::__anon9d22d9a50111::BaseDisplayVariant360     static void setupHwcClientCompositionCallExpectations(CompositionTest* test) {
361         EXPECT_CALL(*test->mComposer, presentOrValidateDisplay(HWC_DISPLAY, _, _, _, _, _))
362                 .Times(1);
363     }
364 
setupHwcForcedClientCompositionCallExpectationsandroid::__anon9d22d9a50111::BaseDisplayVariant365     static void setupHwcForcedClientCompositionCallExpectations(CompositionTest* test) {
366         EXPECT_CALL(*test->mComposer, validateDisplay(HWC_DISPLAY, _, _, _)).Times(1);
367     }
368 
setupRECompositionCallExpectationsandroid::__anon9d22d9a50111::BaseDisplayVariant369     static void setupRECompositionCallExpectations(CompositionTest* test) {
370         EXPECT_CALL(*test->mDisplaySurface,
371                     prepareFrame(compositionengine::DisplaySurface::CompositionType::Gpu))
372                 .Times(1);
373         EXPECT_CALL(*test->mDisplaySurface, getClientTargetAcquireFence())
374                 .WillRepeatedly(ReturnRef(test->mClientTargetAcquireFence));
375 
376         EXPECT_CALL(*test->mNativeWindow, queueBuffer(_, _)).WillOnce(Return(0));
377         EXPECT_CALL(*test->mNativeWindow, dequeueBuffer(_, _))
378                 .WillOnce(DoAll(SetArgPointee<0>(test->mNativeWindowBuffer), SetArgPointee<1>(-1),
379                                 Return(0)));
380         EXPECT_CALL(*test->mRenderEngine, drawLayers)
381                 .WillRepeatedly([&](const renderengine::DisplaySettings& displaySettings,
382                                     const std::vector<renderengine::LayerSettings>&,
383                                     const std::shared_ptr<renderengine::ExternalTexture>&,
384                                     const bool, base::unique_fd&&) -> std::future<FenceResult> {
385                     EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
386                     EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
387                               displaySettings.physicalDisplay);
388                     EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
389                               displaySettings.clip);
390                     EXPECT_EQ(ui::Dataspace::UNKNOWN, displaySettings.outputDataspace);
391                     return futureOf<FenceResult>(Fence::NO_FENCE);
392                 });
393     }
394 
395     template <typename Case>
setupRELayerCompositionCallExpectationsandroid::__anon9d22d9a50111::BaseDisplayVariant396     static void setupRELayerCompositionCallExpectations(CompositionTest* test) {
397         Case::Layer::setupRECompositionCallExpectations(test);
398     }
399 
400     template <typename Case>
setupRELayerScreenshotCompositionCallExpectationsandroid::__anon9d22d9a50111::BaseDisplayVariant401     static void setupRELayerScreenshotCompositionCallExpectations(CompositionTest* test) {
402         Case::Layer::setupREScreenshotCompositionCallExpectations(test);
403     }
404 };
405 
406 struct DefaultDisplaySetupVariant : public BaseDisplayVariant<DefaultDisplaySetupVariant> {};
407 
408 struct InsecureDisplaySetupVariant : public BaseDisplayVariant<InsecureDisplaySetupVariant> {
409     static constexpr bool IS_SECURE = false;
410 
411     template <typename Case>
setupRELayerCompositionCallExpectationsandroid::__anon9d22d9a50111::InsecureDisplaySetupVariant412     static void setupRELayerCompositionCallExpectations(CompositionTest* test) {
413         Case::Layer::setupInsecureRECompositionCallExpectations(test);
414     }
415 
416     template <typename Case>
setupRELayerScreenshotCompositionCallExpectationsandroid::__anon9d22d9a50111::InsecureDisplaySetupVariant417     static void setupRELayerScreenshotCompositionCallExpectations(CompositionTest* test) {
418         Case::Layer::setupInsecureREScreenshotCompositionCallExpectations(test);
419     }
420 };
421 
422 struct PoweredOffDisplaySetupVariant : public BaseDisplayVariant<PoweredOffDisplaySetupVariant> {
423     static constexpr hal::PowerMode INIT_POWER_MODE = hal::PowerMode::OFF;
424 
425     template <typename Case>
setupPreconditionCallExpectationsandroid::__anon9d22d9a50111::PoweredOffDisplaySetupVariant426     static void setupPreconditionCallExpectations(CompositionTest*) {}
427 
428     template <typename Case>
setupCommonCompositionCallExpectationsandroid::__anon9d22d9a50111::PoweredOffDisplaySetupVariant429     static void setupCommonCompositionCallExpectations(CompositionTest* test) {
430         // TODO: This seems like an unnecessary call if display is powered off.
431         EXPECT_CALL(*test->mComposer, setColorTransform(HWC_DISPLAY, IsIdentityMatrix())).Times(1);
432 
433         // TODO: This seems like an unnecessary call if display is powered off.
434         Case::CompositionType::setupHwcSetCallExpectations(test);
435     }
436 
setupHwcCompositionCallExpectationsandroid::__anon9d22d9a50111::PoweredOffDisplaySetupVariant437     static void setupHwcCompositionCallExpectations(CompositionTest*) {}
setupHwcClientCompositionCallExpectationsandroid::__anon9d22d9a50111::PoweredOffDisplaySetupVariant438     static void setupHwcClientCompositionCallExpectations(CompositionTest*) {}
setupHwcForcedClientCompositionCallExpectationsandroid::__anon9d22d9a50111::PoweredOffDisplaySetupVariant439     static void setupHwcForcedClientCompositionCallExpectations(CompositionTest*) {}
440 
setupRECompositionCallExpectationsandroid::__anon9d22d9a50111::PoweredOffDisplaySetupVariant441     static void setupRECompositionCallExpectations(CompositionTest* test) {
442         // TODO: This seems like an unnecessary call if display is powered off.
443         EXPECT_CALL(*test->mDisplaySurface, getClientTargetAcquireFence())
444                 .WillRepeatedly(ReturnRef(test->mClientTargetAcquireFence));
445     }
446 
447     template <typename Case>
setupRELayerCompositionCallExpectationsandroid::__anon9d22d9a50111::PoweredOffDisplaySetupVariant448     static void setupRELayerCompositionCallExpectations(CompositionTest*) {}
449 };
450 
451 /* ------------------------------------------------------------------------
452  * Variants for each layer configuration which can be tested
453  */
454 
455 template <typename LayerProperties>
456 struct BaseLayerProperties {
457     static constexpr uint32_t WIDTH = 100;
458     static constexpr uint32_t HEIGHT = 100;
459     static constexpr PixelFormat FORMAT = PIXEL_FORMAT_RGBA_8888;
460     static constexpr uint64_t USAGE =
461             GraphicBuffer::USAGE_SW_READ_NEVER | GraphicBuffer::USAGE_SW_WRITE_NEVER;
462     static constexpr android_dataspace DATASPACE = HAL_DATASPACE_UNKNOWN;
463     static constexpr uint32_t SCALING_MODE = 0;
464     static constexpr uint32_t TRANSFORM = 0;
465     static constexpr uint32_t LAYER_FLAGS = 0;
466     static constexpr float COLOR[] = {1.f, 1.f, 1.f, 1.f};
467     static constexpr IComposerClient::BlendMode BLENDMODE =
468             IComposerClient::BlendMode::PREMULTIPLIED;
469 
setupLatchedBufferandroid::__anon9d22d9a50111::BaseLayerProperties470     static void setupLatchedBuffer(CompositionTest* test, sp<Layer> layer) {
471         Mock::VerifyAndClear(test->mRenderEngine);
472 
473         const auto buffer = std::make_shared<
474                 renderengine::mock::FakeExternalTexture>(LayerProperties::WIDTH,
475                                                          LayerProperties::HEIGHT,
476                                                          DEFAULT_TEXTURE_ID,
477                                                          LayerProperties::FORMAT,
478                                                          LayerProperties::USAGE |
479                                                                  GraphicBuffer::USAGE_HW_TEXTURE);
480 
481         auto& layerDrawingState = test->mFlinger.mutableLayerDrawingState(layer);
482         layerDrawingState.crop = Rect(0, 0, LayerProperties::HEIGHT, LayerProperties::WIDTH);
483         layerDrawingState.buffer = buffer;
484         layerDrawingState.acquireFence = Fence::NO_FENCE;
485         layerDrawingState.dataspace = ui::Dataspace::UNKNOWN;
486         layer->setSurfaceDamageRegion(
487                 Region(Rect(LayerProperties::HEIGHT, LayerProperties::WIDTH)));
488 
489         bool ignoredRecomputeVisibleRegions;
490         layer->latchBuffer(ignoredRecomputeVisibleRegions, 0);
491         Mock::VerifyAndClear(test->mRenderEngine);
492     }
493 
setupLayerStateandroid::__anon9d22d9a50111::BaseLayerProperties494     static void setupLayerState(CompositionTest* test, sp<Layer> layer) {
495         setupLatchedBuffer(test, layer);
496     }
497 
setupHwcSetGeometryCallExpectationsandroid::__anon9d22d9a50111::BaseLayerProperties498     static void setupHwcSetGeometryCallExpectations(CompositionTest* test) {
499         if (!test->mDisplayOff) {
500             // TODO: Coverage of other values
501             EXPECT_CALL(*test->mComposer,
502                         setLayerBlendMode(HWC_DISPLAY, HWC_LAYER, LayerProperties::BLENDMODE))
503                     .Times(1);
504             // TODO: Coverage of other values for origin
505             EXPECT_CALL(*test->mComposer,
506                         setLayerDisplayFrame(HWC_DISPLAY, HWC_LAYER,
507                                              IComposerClient::Rect({0, 0, LayerProperties::WIDTH,
508                                                                     LayerProperties::HEIGHT})))
509                     .Times(1);
510             EXPECT_CALL(*test->mComposer,
511                         setLayerPlaneAlpha(HWC_DISPLAY, HWC_LAYER, LayerProperties::COLOR[3]))
512                     .Times(1);
513             // TODO: Coverage of other values
514             EXPECT_CALL(*test->mComposer, setLayerZOrder(HWC_DISPLAY, HWC_LAYER, 0u)).Times(1);
515 
516             // These expectations retire on saturation as the code path these
517             // expectations are for appears to make an extra call to them.
518             // TODO: Investigate this extra call
519             EXPECT_CALL(*test->mComposer,
520                         setLayerTransform(HWC_DISPLAY, HWC_LAYER, DEFAULT_TRANSFORM))
521                     .Times(AtLeast(1))
522                     .RetiresOnSaturation();
523         }
524     }
525 
setupHwcSetSourceCropBufferCallExpectationsandroid::__anon9d22d9a50111::BaseLayerProperties526     static void setupHwcSetSourceCropBufferCallExpectations(CompositionTest* test) {
527         if (!test->mDisplayOff) {
528             EXPECT_CALL(*test->mComposer,
529                         setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER,
530                                            IComposerClient::FRect({0.f, 0.f, LayerProperties::WIDTH,
531                                                                    LayerProperties::HEIGHT})))
532                     .Times(1);
533         }
534     }
535 
setupHwcSetSourceCropColorCallExpectationsandroid::__anon9d22d9a50111::BaseLayerProperties536     static void setupHwcSetSourceCropColorCallExpectations(CompositionTest* test) {
537         if (!test->mDisplayOff) {
538             EXPECT_CALL(*test->mComposer,
539                         setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER,
540                                            IComposerClient::FRect({0.f, 0.f, 0.f, 0.f})))
541                     .Times(1);
542         }
543     }
544 
setupHwcSetPerFrameCallExpectationsandroid::__anon9d22d9a50111::BaseLayerProperties545     static void setupHwcSetPerFrameCallExpectations(CompositionTest* test) {
546         if (!test->mDisplayOff) {
547             EXPECT_CALL(*test->mComposer,
548                         setLayerVisibleRegion(HWC_DISPLAY, HWC_LAYER,
549                                               std::vector<IComposerClient::Rect>(
550                                                       {IComposerClient::Rect(
551                                                               {0, 0, LayerProperties::WIDTH,
552                                                                LayerProperties::HEIGHT})})))
553                     .Times(1);
554         }
555     }
556 
setupHwcSetPerFrameColorCallExpectationsandroid::__anon9d22d9a50111::BaseLayerProperties557     static void setupHwcSetPerFrameColorCallExpectations(CompositionTest* test) {
558         if (!test->mDisplayOff) {
559             EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _))
560                     .Times(1);
561 
562             // TODO: use COLOR
563             EXPECT_CALL(*test->mComposer,
564                         setLayerColor(HWC_DISPLAY, HWC_LAYER,
565                                       aidl::android::hardware::graphics::composer3::Color(
566                                               {1.0f, 1.0f, 1.0f, 1.0f})))
567                     .Times(1);
568         }
569     }
570 
setupHwcSetPerFrameBufferCallExpectationsandroid::__anon9d22d9a50111::BaseLayerProperties571     static void setupHwcSetPerFrameBufferCallExpectations(CompositionTest* test) {
572         if (!test->mDisplayOff) {
573             EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _))
574                     .Times(1);
575             EXPECT_CALL(*test->mComposer, setLayerBuffer(HWC_DISPLAY, HWC_LAYER, _, _, _)).Times(1);
576         }
577     }
578 
setupREBufferCompositionCommonCallExpectationsandroid::__anon9d22d9a50111::BaseLayerProperties579     static void setupREBufferCompositionCommonCallExpectations(CompositionTest* test) {
580         EXPECT_CALL(*test->mRenderEngine, drawLayers)
581                 .WillOnce([&](const renderengine::DisplaySettings& displaySettings,
582                               const std::vector<renderengine::LayerSettings>& layerSettings,
583                               const std::shared_ptr<renderengine::ExternalTexture>&, const bool,
584                               base::unique_fd&&) -> std::future<FenceResult> {
585                     EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
586                     EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
587                               displaySettings.physicalDisplay);
588                     EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
589                               displaySettings.clip);
590                     // screen capture adds an additional color layer as an alpha
591                     // prefill, so gtet the back layer.
592                     std::future<FenceResult> resultFuture = futureOf<FenceResult>(Fence::NO_FENCE);
593                     if (layerSettings.empty()) {
594                         ADD_FAILURE() << "layerSettings was not expected to be empty in "
595                                          "setupREBufferCompositionCommonCallExpectations "
596                                          "verification lambda";
597                         return resultFuture;
598                     }
599                     const renderengine::LayerSettings layer = layerSettings.back();
600                     EXPECT_THAT(layer.source.buffer.buffer, Not(IsNull()));
601                     EXPECT_THAT(layer.source.buffer.fence, Not(IsNull()));
602                     EXPECT_EQ(DEFAULT_TEXTURE_ID, layer.source.buffer.textureName);
603                     EXPECT_EQ(false, layer.source.buffer.isY410BT2020);
604                     EXPECT_EQ(true, layer.source.buffer.usePremultipliedAlpha);
605                     EXPECT_EQ(false, layer.source.buffer.isOpaque);
606                     EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius.x);
607                     EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius.y);
608                     EXPECT_EQ(ui::Dataspace::V0_SRGB, layer.sourceDataspace);
609                     EXPECT_EQ(LayerProperties::COLOR[3], layer.alpha);
610                     return resultFuture;
611                 });
612     }
613 
setupREBufferCompositionCallExpectationsandroid::__anon9d22d9a50111::BaseLayerProperties614     static void setupREBufferCompositionCallExpectations(CompositionTest* test) {
615         LayerProperties::setupREBufferCompositionCommonCallExpectations(test);
616     }
617 
setupInsecureREBufferCompositionCallExpectationsandroid::__anon9d22d9a50111::BaseLayerProperties618     static void setupInsecureREBufferCompositionCallExpectations(CompositionTest* test) {
619         setupREBufferCompositionCallExpectations(test);
620     }
621 
setupREBufferScreenshotCompositionCallExpectationsandroid::__anon9d22d9a50111::BaseLayerProperties622     static void setupREBufferScreenshotCompositionCallExpectations(CompositionTest* test) {
623         LayerProperties::setupREBufferCompositionCommonCallExpectations(test);
624     }
625 
setupInsecureREBufferScreenshotCompositionCallExpectationsandroid::__anon9d22d9a50111::BaseLayerProperties626     static void setupInsecureREBufferScreenshotCompositionCallExpectations(CompositionTest* test) {
627         LayerProperties::setupREBufferCompositionCommonCallExpectations(test);
628     }
629 
setupREColorCompositionCallExpectationsandroid::__anon9d22d9a50111::BaseLayerProperties630     static void setupREColorCompositionCallExpectations(CompositionTest* test) {
631         EXPECT_CALL(*test->mRenderEngine, drawLayers)
632                 .WillOnce([&](const renderengine::DisplaySettings& displaySettings,
633                               const std::vector<renderengine::LayerSettings>& layerSettings,
634                               const std::shared_ptr<renderengine::ExternalTexture>&, const bool,
635                               base::unique_fd&&) -> std::future<FenceResult> {
636                     EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
637                     EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
638                               displaySettings.physicalDisplay);
639                     EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
640                               displaySettings.clip);
641                     // screen capture adds an additional color layer as an alpha
642                     // prefill, so get the back layer.
643                     std::future<FenceResult> resultFuture = futureOf<FenceResult>(Fence::NO_FENCE);
644                     if (layerSettings.empty()) {
645                         ADD_FAILURE()
646                                 << "layerSettings was not expected to be empty in "
647                                    "setupREColorCompositionCallExpectations verification lambda";
648                         return resultFuture;
649                     }
650                     const renderengine::LayerSettings layer = layerSettings.back();
651                     EXPECT_THAT(layer.source.buffer.buffer, IsNull());
652                     EXPECT_EQ(half3(LayerProperties::COLOR[0], LayerProperties::COLOR[1],
653                                     LayerProperties::COLOR[2]),
654                               layer.source.solidColor);
655                     EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius.x);
656                     EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius.y);
657                     EXPECT_EQ(ui::Dataspace::V0_SRGB, layer.sourceDataspace);
658                     EXPECT_EQ(LayerProperties::COLOR[3], layer.alpha);
659                     return resultFuture;
660                 });
661     }
662 
setupREColorScreenshotCompositionCallExpectationsandroid::__anon9d22d9a50111::BaseLayerProperties663     static void setupREColorScreenshotCompositionCallExpectations(CompositionTest* test) {
664         setupREColorCompositionCallExpectations(test);
665     }
666 };
667 
668 struct DefaultLayerProperties : public BaseLayerProperties<DefaultLayerProperties> {};
669 
670 struct EffectLayerProperties : public BaseLayerProperties<EffectLayerProperties> {
671     static constexpr IComposerClient::BlendMode BLENDMODE = IComposerClient::BlendMode::NONE;
672 };
673 
674 struct SidebandLayerProperties : public BaseLayerProperties<SidebandLayerProperties> {
675     using Base = BaseLayerProperties<SidebandLayerProperties>;
676     static constexpr IComposerClient::BlendMode BLENDMODE = IComposerClient::BlendMode::NONE;
677 
setupLayerStateandroid::__anon9d22d9a50111::SidebandLayerProperties678     static void setupLayerState(CompositionTest* test, sp<Layer> layer) {
679         sp<NativeHandle> stream =
680                 NativeHandle::create(reinterpret_cast<native_handle_t*>(DEFAULT_SIDEBAND_STREAM),
681                                      false);
682         test->mFlinger.setLayerSidebandStream(layer, stream);
683         auto& layerDrawingState = test->mFlinger.mutableLayerDrawingState(layer);
684         layerDrawingState.crop =
685                 Rect(0, 0, SidebandLayerProperties::HEIGHT, SidebandLayerProperties::WIDTH);
686     }
687 
setupHwcSetSourceCropBufferCallExpectationsandroid::__anon9d22d9a50111::SidebandLayerProperties688     static void setupHwcSetSourceCropBufferCallExpectations(CompositionTest* test) {
689         EXPECT_CALL(*test->mComposer,
690                     setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER,
691                                        IComposerClient::FRect({0.f, 0.f, -1.f, -1.f})))
692                 .Times(1);
693     }
694 
setupHwcSetPerFrameBufferCallExpectationsandroid::__anon9d22d9a50111::SidebandLayerProperties695     static void setupHwcSetPerFrameBufferCallExpectations(CompositionTest* test) {
696         EXPECT_CALL(*test->mComposer,
697                     setLayerSidebandStream(HWC_DISPLAY, HWC_LAYER,
698                                            reinterpret_cast<native_handle_t*>(
699                                                    DEFAULT_SIDEBAND_STREAM)))
700                 .WillOnce(Return(Error::NONE));
701 
702         EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _)).Times(1);
703     }
704 
setupREBufferCompositionCommonCallExpectationsandroid::__anon9d22d9a50111::SidebandLayerProperties705     static void setupREBufferCompositionCommonCallExpectations(CompositionTest* /*test*/) {}
706 };
707 
708 template <typename LayerProperties>
709 struct CommonSecureLayerProperties : public BaseLayerProperties<LayerProperties> {
710     using Base = BaseLayerProperties<LayerProperties>;
711 
setupInsecureREBufferCompositionCommonCallExpectationsandroid::__anon9d22d9a50111::CommonSecureLayerProperties712     static void setupInsecureREBufferCompositionCommonCallExpectations(CompositionTest* test) {
713         EXPECT_CALL(*test->mRenderEngine, drawLayers)
714                 .WillOnce([&](const renderengine::DisplaySettings& displaySettings,
715                               const std::vector<renderengine::LayerSettings>& layerSettings,
716                               const std::shared_ptr<renderengine::ExternalTexture>&, const bool,
717                               base::unique_fd&&) -> std::future<FenceResult> {
718                     EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
719                     EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
720                               displaySettings.physicalDisplay);
721                     EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
722                               displaySettings.clip);
723                     // screen capture adds an additional color layer as an alpha
724                     // prefill, so get the back layer.
725                     std::future<FenceResult> resultFuture = futureOf<FenceResult>(Fence::NO_FENCE);
726                     if (layerSettings.empty()) {
727                         ADD_FAILURE() << "layerSettings was not expected to be empty in "
728                                          "setupInsecureREBufferCompositionCommonCallExpectations "
729                                          "verification lambda";
730                         return resultFuture;
731                     }
732                     const renderengine::LayerSettings layer = layerSettings.back();
733                     EXPECT_THAT(layer.source.buffer.buffer, IsNull());
734                     EXPECT_EQ(half3(0.0f, 0.0f, 0.0f), layer.source.solidColor);
735                     EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius.x);
736                     EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius.y);
737                     EXPECT_EQ(ui::Dataspace::V0_SRGB, layer.sourceDataspace);
738                     EXPECT_EQ(1.0f, layer.alpha);
739                     return resultFuture;
740                 });
741     }
742 
setupInsecureREBufferCompositionCallExpectationsandroid::__anon9d22d9a50111::CommonSecureLayerProperties743     static void setupInsecureREBufferCompositionCallExpectations(CompositionTest* test) {
744         setupInsecureREBufferCompositionCommonCallExpectations(test);
745     }
746 
setupInsecureREBufferScreenshotCompositionCallExpectationsandroid::__anon9d22d9a50111::CommonSecureLayerProperties747     static void setupInsecureREBufferScreenshotCompositionCallExpectations(CompositionTest* test) {
748         setupInsecureREBufferCompositionCommonCallExpectations(test);
749     }
750 };
751 
752 struct ParentSecureLayerProperties
753       : public CommonSecureLayerProperties<ParentSecureLayerProperties> {};
754 
755 struct SecureLayerProperties : public CommonSecureLayerProperties<SecureLayerProperties> {
756     static constexpr uint32_t LAYER_FLAGS = ISurfaceComposerClient::eSecure;
757 };
758 
759 struct CursorLayerProperties : public BaseLayerProperties<CursorLayerProperties> {
760     using Base = BaseLayerProperties<CursorLayerProperties>;
761 
setupLayerStateandroid::__anon9d22d9a50111::CursorLayerProperties762     static void setupLayerState(CompositionTest* test, sp<Layer> layer) {
763         Base::setupLayerState(test, layer);
764         test->mFlinger.setLayerPotentialCursor(layer, true);
765     }
766 };
767 
768 struct NoLayerVariant {
769     using FlingerLayerType = sp<Layer>;
770 
createLayerandroid::__anon9d22d9a50111::NoLayerVariant771     static FlingerLayerType createLayer(CompositionTest*) { return FlingerLayerType(); }
injectLayerandroid::__anon9d22d9a50111::NoLayerVariant772     static void injectLayer(CompositionTest*, FlingerLayerType) {}
cleanupInjectedLayersandroid::__anon9d22d9a50111::NoLayerVariant773     static void cleanupInjectedLayers(CompositionTest*) {}
774 
setupCallExpectationsForDirtyGeometryandroid::__anon9d22d9a50111::NoLayerVariant775     static void setupCallExpectationsForDirtyGeometry(CompositionTest*) {}
setupCallExpectationsForDirtyFrameandroid::__anon9d22d9a50111::NoLayerVariant776     static void setupCallExpectationsForDirtyFrame(CompositionTest*) {}
777 };
778 
779 template <typename LayerProperties>
780 struct BaseLayerVariant {
781     template <typename L, typename F>
createLayerWithFactoryandroid::__anon9d22d9a50111::BaseLayerVariant782     static sp<L> createLayerWithFactory(CompositionTest* test, F factory) {
783         EXPECT_CALL(*test->mFlinger.scheduler(), postMessage(_)).Times(0);
784 
785         sp<L> layer = factory();
786 
787         // Layer should be registered with scheduler.
788         EXPECT_EQ(1u, test->mFlinger.scheduler()->layerHistorySize());
789 
790         Mock::VerifyAndClear(test->mComposer);
791         Mock::VerifyAndClear(test->mRenderEngine);
792         Mock::VerifyAndClearExpectations(test->mFlinger.scheduler());
793 
794         initLayerDrawingStateAndComputeBounds(test, layer);
795 
796         return layer;
797     }
798 
799     template <typename L>
initLayerDrawingStateAndComputeBoundsandroid::__anon9d22d9a50111::BaseLayerVariant800     static void initLayerDrawingStateAndComputeBounds(CompositionTest* test, sp<L> layer) {
801         auto& layerDrawingState = test->mFlinger.mutableLayerDrawingState(layer);
802         layerDrawingState.layerStack = LAYER_STACK;
803         layerDrawingState.color = half4(LayerProperties::COLOR[0], LayerProperties::COLOR[1],
804                                         LayerProperties::COLOR[2], LayerProperties::COLOR[3]);
805         layer->computeBounds(FloatRect(0, 0, 100, 100), ui::Transform(), 0.f /* shadowRadius */);
806     }
807 
injectLayerandroid::__anon9d22d9a50111::BaseLayerVariant808     static void injectLayer(CompositionTest* test, sp<Layer> layer) {
809         EXPECT_CALL(*test->mComposer, createLayer(HWC_DISPLAY, _))
810                 .WillOnce(DoAll(SetArgPointee<1>(HWC_LAYER), Return(Error::NONE)));
811 
812         auto outputLayer = test->mDisplay->getCompositionDisplay()->injectOutputLayerForTest(
813                 layer->getCompositionEngineLayerFE());
814         outputLayer->editState().visibleRegion = Region(Rect(0, 0, 100, 100));
815         outputLayer->editState().outputSpaceVisibleRegion = Region(Rect(0, 0, 100, 100));
816 
817         Mock::VerifyAndClear(test->mComposer);
818 
819         test->mFlinger.mutableDrawingState().layersSortedByZ.add(layer);
820         test->mFlinger.mutableVisibleRegionsDirty() = true;
821     }
822 
cleanupInjectedLayersandroid::__anon9d22d9a50111::BaseLayerVariant823     static void cleanupInjectedLayers(CompositionTest* test) {
824         EXPECT_CALL(*test->mComposer, destroyLayer(HWC_DISPLAY, HWC_LAYER))
825                 .WillOnce(Return(Error::NONE));
826 
827         test->mDisplay->getCompositionDisplay()->clearOutputLayers();
828         test->mFlinger.mutableDrawingState().layersSortedByZ.clear();
829         test->mFlinger.mutablePreviouslyComposedLayers().clear();
830 
831         // Layer should be unregistered with scheduler.
832         test->mFlinger.commit();
833         EXPECT_EQ(0u, test->mFlinger.scheduler()->layerHistorySize());
834     }
835 };
836 
837 template <typename LayerProperties>
838 struct EffectLayerVariant : public BaseLayerVariant<LayerProperties> {
839     using Base = BaseLayerVariant<LayerProperties>;
840     using FlingerLayerType = sp<Layer>;
841 
createLayerandroid::__anon9d22d9a50111::EffectLayerVariant842     static FlingerLayerType createLayer(CompositionTest* test) {
843         FlingerLayerType layer = Base::template createLayerWithFactory<Layer>(test, [test]() {
844             return sp<Layer>::make(LayerCreationArgs(test->mFlinger.flinger(), sp<Client>(),
845                                                      "test-layer", LayerProperties::LAYER_FLAGS,
846                                                      LayerMetadata()));
847         });
848 
849         auto& layerDrawingState = test->mFlinger.mutableLayerDrawingState(layer);
850         layerDrawingState.crop = Rect(0, 0, LayerProperties::HEIGHT, LayerProperties::WIDTH);
851         return layer;
852     }
853 
setupRECompositionCallExpectationsandroid::__anon9d22d9a50111::EffectLayerVariant854     static void setupRECompositionCallExpectations(CompositionTest* test) {
855         LayerProperties::setupREColorCompositionCallExpectations(test);
856     }
857 
setupREScreenshotCompositionCallExpectationsandroid::__anon9d22d9a50111::EffectLayerVariant858     static void setupREScreenshotCompositionCallExpectations(CompositionTest* test) {
859         LayerProperties::setupREColorScreenshotCompositionCallExpectations(test);
860     }
861 
setupCallExpectationsForDirtyGeometryandroid::__anon9d22d9a50111::EffectLayerVariant862     static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) {
863         LayerProperties::setupHwcSetGeometryCallExpectations(test);
864         LayerProperties::setupHwcSetSourceCropColorCallExpectations(test);
865     }
866 
setupCallExpectationsForDirtyFrameandroid::__anon9d22d9a50111::EffectLayerVariant867     static void setupCallExpectationsForDirtyFrame(CompositionTest* test) {
868         LayerProperties::setupHwcSetPerFrameCallExpectations(test);
869         LayerProperties::setupHwcSetPerFrameColorCallExpectations(test);
870     }
871 };
872 
873 template <typename LayerProperties>
874 struct BufferLayerVariant : public BaseLayerVariant<LayerProperties> {
875     using Base = BaseLayerVariant<LayerProperties>;
876     using FlingerLayerType = sp<Layer>;
877 
createLayerandroid::__anon9d22d9a50111::BufferLayerVariant878     static FlingerLayerType createLayer(CompositionTest* test) {
879         test->mFlinger.mutableTexturePool().push_back(DEFAULT_TEXTURE_ID);
880 
881         FlingerLayerType layer =
882                 Base::template createLayerWithFactory<Layer>(test, [test]() {
883                     LayerCreationArgs args(test->mFlinger.flinger(), sp<Client>(), "test-layer",
884                                            LayerProperties::LAYER_FLAGS, LayerMetadata());
885                     args.textureName = test->mFlinger.mutableTexturePool().back();
886                     return sp<Layer>::make(args);
887                 });
888 
889         LayerProperties::setupLayerState(test, layer);
890 
891         return layer;
892     }
893 
cleanupInjectedLayersandroid::__anon9d22d9a50111::BufferLayerVariant894     static void cleanupInjectedLayers(CompositionTest* test) {
895         Base::cleanupInjectedLayers(test);
896     }
897 
setupCallExpectationsForDirtyGeometryandroid::__anon9d22d9a50111::BufferLayerVariant898     static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) {
899         LayerProperties::setupHwcSetGeometryCallExpectations(test);
900         LayerProperties::setupHwcSetSourceCropBufferCallExpectations(test);
901     }
902 
setupCallExpectationsForDirtyFrameandroid::__anon9d22d9a50111::BufferLayerVariant903     static void setupCallExpectationsForDirtyFrame(CompositionTest* test) {
904         LayerProperties::setupHwcSetPerFrameCallExpectations(test);
905         LayerProperties::setupHwcSetPerFrameBufferCallExpectations(test);
906     }
907 
setupRECompositionCallExpectationsandroid::__anon9d22d9a50111::BufferLayerVariant908     static void setupRECompositionCallExpectations(CompositionTest* test) {
909         LayerProperties::setupREBufferCompositionCallExpectations(test);
910     }
911 
setupInsecureRECompositionCallExpectationsandroid::__anon9d22d9a50111::BufferLayerVariant912     static void setupInsecureRECompositionCallExpectations(CompositionTest* test) {
913         LayerProperties::setupInsecureREBufferCompositionCallExpectations(test);
914     }
915 
setupREScreenshotCompositionCallExpectationsandroid::__anon9d22d9a50111::BufferLayerVariant916     static void setupREScreenshotCompositionCallExpectations(CompositionTest* test) {
917         LayerProperties::setupREBufferScreenshotCompositionCallExpectations(test);
918     }
919 
setupInsecureREScreenshotCompositionCallExpectationsandroid::__anon9d22d9a50111::BufferLayerVariant920     static void setupInsecureREScreenshotCompositionCallExpectations(CompositionTest* test) {
921         LayerProperties::setupInsecureREBufferScreenshotCompositionCallExpectations(test);
922     }
923 };
924 
925 template <typename LayerProperties>
926 struct ContainerLayerVariant : public BaseLayerVariant<LayerProperties> {
927     using Base = BaseLayerVariant<LayerProperties>;
928     using FlingerLayerType = sp<Layer>;
929 
createLayerandroid::__anon9d22d9a50111::ContainerLayerVariant930     static FlingerLayerType createLayer(CompositionTest* test) {
931         LayerCreationArgs args(test->mFlinger.flinger(), sp<Client>(), "test-container-layer",
932                                LayerProperties::LAYER_FLAGS, LayerMetadata());
933         FlingerLayerType layer = sp<Layer>::make(args);
934         Base::template initLayerDrawingStateAndComputeBounds(test, layer);
935         return layer;
936     }
937 };
938 
939 template <typename LayerVariant, typename ParentLayerVariant>
940 struct ChildLayerVariant : public LayerVariant {
941     using Base = LayerVariant;
942     using FlingerLayerType = typename LayerVariant::FlingerLayerType;
943     using ParentBase = ParentLayerVariant;
944 
createLayerandroid::__anon9d22d9a50111::ChildLayerVariant945     static FlingerLayerType createLayer(CompositionTest* test) {
946         // Need to create child layer first. Otherwise layer history size will be 2.
947         FlingerLayerType layer = Base::createLayer(test);
948 
949         typename ParentBase::FlingerLayerType parentLayer = ParentBase::createLayer(test);
950         parentLayer->addChild(layer);
951         test->mFlinger.setLayerDrawingParent(layer, parentLayer);
952 
953         test->mAuxiliaryLayers.push_back(parentLayer);
954 
955         return layer;
956     }
957 
cleanupInjectedLayersandroid::__anon9d22d9a50111::ChildLayerVariant958     static void cleanupInjectedLayers(CompositionTest* test) {
959         // Clear auxiliary layers first so that child layer can be successfully destroyed in the
960         // following call.
961         test->mAuxiliaryLayers.clear();
962 
963         Base::cleanupInjectedLayers(test);
964     }
965 };
966 
967 /* ------------------------------------------------------------------------
968  * Variants to control how the composition type is changed
969  */
970 
971 struct NoCompositionTypeVariant {
setupHwcSetCallExpectationsandroid::__anon9d22d9a50111::NoCompositionTypeVariant972     static void setupHwcSetCallExpectations(CompositionTest*) {}
973 
setupHwcGetCallExpectationsandroid::__anon9d22d9a50111::NoCompositionTypeVariant974     static void setupHwcGetCallExpectations(CompositionTest* test) {
975         EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _)).Times(1);
976     }
977 };
978 
979 template <aidl::android::hardware::graphics::composer3::Composition CompositionType>
980 struct KeepCompositionTypeVariant {
981     static constexpr aidl::android::hardware::graphics::composer3::Composition TYPE =
982             CompositionType;
983 
setupHwcSetCallExpectationsandroid::__anon9d22d9a50111::KeepCompositionTypeVariant984     static void setupHwcSetCallExpectations(CompositionTest* test) {
985         if (!test->mDisplayOff) {
986             EXPECT_CALL(*test->mComposer,
987                         setLayerCompositionType(HWC_DISPLAY, HWC_LAYER, CompositionType))
988                     .Times(1);
989         }
990     }
991 
setupHwcGetCallExpectationsandroid::__anon9d22d9a50111::KeepCompositionTypeVariant992     static void setupHwcGetCallExpectations(CompositionTest* test) {
993         EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _)).Times(1);
994     }
995 };
996 
997 template <aidl::android::hardware::graphics::composer3::Composition InitialCompositionType,
998           aidl::android::hardware::graphics::composer3::Composition FinalCompositionType>
999 struct ChangeCompositionTypeVariant {
1000     static constexpr aidl::android::hardware::graphics::composer3::Composition TYPE =
1001             FinalCompositionType;
1002 
setupHwcSetCallExpectationsandroid::__anon9d22d9a50111::ChangeCompositionTypeVariant1003     static void setupHwcSetCallExpectations(CompositionTest* test) {
1004         if (!test->mDisplayOff) {
1005             EXPECT_CALL(*test->mComposer,
1006                         setLayerCompositionType(HWC_DISPLAY, HWC_LAYER, InitialCompositionType))
1007                     .Times(1);
1008         }
1009     }
1010 
setupHwcGetCallExpectationsandroid::__anon9d22d9a50111::ChangeCompositionTypeVariant1011     static void setupHwcGetCallExpectations(CompositionTest* test) {
1012         EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _))
1013                 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::Layer>{
1014                                         static_cast<Hwc2::Layer>(HWC_LAYER)}),
1015                                 SetArgPointee<2>(
1016                                         std::vector<aidl::android::hardware::graphics::composer3::
1017                                                             Composition>{FinalCompositionType}),
1018                                 Return(Error::NONE)));
1019     }
1020 };
1021 
1022 /* ------------------------------------------------------------------------
1023  * Variants to select how the composition is expected to be handled
1024  */
1025 
1026 struct CompositionResultBaseVariant {
setupLayerStateandroid::__anon9d22d9a50111::CompositionResultBaseVariant1027     static void setupLayerState(CompositionTest*, sp<Layer>) {}
1028 
1029     template <typename Case>
setupCallExpectationsForDirtyGeometryandroid::__anon9d22d9a50111::CompositionResultBaseVariant1030     static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) {
1031         Case::Layer::setupCallExpectationsForDirtyGeometry(test);
1032     }
1033 
1034     template <typename Case>
setupCallExpectationsForDirtyFrameandroid::__anon9d22d9a50111::CompositionResultBaseVariant1035     static void setupCallExpectationsForDirtyFrame(CompositionTest* test) {
1036         Case::Layer::setupCallExpectationsForDirtyFrame(test);
1037     }
1038 };
1039 
1040 struct NoCompositionResultVariant : public CompositionResultBaseVariant {
1041     template <typename Case>
setupCallExpectationsandroid::__anon9d22d9a50111::NoCompositionResultVariant1042     static void setupCallExpectations(CompositionTest* test) {
1043         Case::Display::setupEmptyFrameCompositionCallExpectations(test);
1044         Case::Display::setupHwcCompositionCallExpectations(test);
1045     }
1046 };
1047 
1048 struct HwcCompositionResultVariant : public CompositionResultBaseVariant {
1049     template <typename Case>
setupCallExpectationsandroid::__anon9d22d9a50111::HwcCompositionResultVariant1050     static void setupCallExpectations(CompositionTest* test) {
1051         Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
1052         Case::Display::setupHwcCompositionCallExpectations(test);
1053     }
1054 };
1055 
1056 struct RECompositionResultVariant : public CompositionResultBaseVariant {
1057     template <typename Case>
setupCallExpectationsandroid::__anon9d22d9a50111::RECompositionResultVariant1058     static void setupCallExpectations(CompositionTest* test) {
1059         Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
1060         Case::Display::setupHwcClientCompositionCallExpectations(test);
1061         Case::Display::setupRECompositionCallExpectations(test);
1062         Case::Display::template setupRELayerCompositionCallExpectations<Case>(test);
1063     }
1064 };
1065 
1066 struct ForcedClientCompositionResultVariant : public CompositionResultBaseVariant {
setupLayerStateandroid::__anon9d22d9a50111::ForcedClientCompositionResultVariant1067     static void setupLayerState(CompositionTest* test, sp<Layer> layer) {
1068         const auto outputLayer =
1069                 TestableSurfaceFlinger::findOutputLayerForDisplay(layer, test->mDisplay);
1070         LOG_FATAL_IF(!outputLayer);
1071         outputLayer->editState().forceClientComposition = true;
1072     }
1073 
1074     template <typename Case>
setupCallExpectationsandroid::__anon9d22d9a50111::ForcedClientCompositionResultVariant1075     static void setupCallExpectations(CompositionTest* test) {
1076         Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
1077         Case::Display::setupHwcForcedClientCompositionCallExpectations(test);
1078         Case::Display::setupRECompositionCallExpectations(test);
1079         Case::Display::template setupRELayerCompositionCallExpectations<Case>(test);
1080     }
1081 
1082     template <typename Case>
setupCallExpectationsForDirtyGeometryandroid::__anon9d22d9a50111::ForcedClientCompositionResultVariant1083     static void setupCallExpectationsForDirtyGeometry(CompositionTest*) {}
1084 
1085     template <typename Case>
setupCallExpectationsForDirtyFrameandroid::__anon9d22d9a50111::ForcedClientCompositionResultVariant1086     static void setupCallExpectationsForDirtyFrame(CompositionTest*) {}
1087 };
1088 
1089 struct ForcedClientCompositionViaDebugOptionResultVariant : public CompositionResultBaseVariant {
setupLayerStateandroid::__anon9d22d9a50111::ForcedClientCompositionViaDebugOptionResultVariant1090     static void setupLayerState(CompositionTest* test, sp<Layer>) {
1091         test->mFlinger.mutableDebugDisableHWC() = true;
1092     }
1093 
1094     template <typename Case>
setupCallExpectationsandroid::__anon9d22d9a50111::ForcedClientCompositionViaDebugOptionResultVariant1095     static void setupCallExpectations(CompositionTest* test) {
1096         Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
1097         Case::Display::setupHwcForcedClientCompositionCallExpectations(test);
1098         Case::Display::setupRECompositionCallExpectations(test);
1099         Case::Display::template setupRELayerCompositionCallExpectations<Case>(test);
1100     }
1101 
1102     template <typename Case>
setupCallExpectationsForDirtyGeometryandroid::__anon9d22d9a50111::ForcedClientCompositionViaDebugOptionResultVariant1103     static void setupCallExpectationsForDirtyGeometry(CompositionTest*) {}
1104 
1105     template <typename Case>
setupCallExpectationsForDirtyFrameandroid::__anon9d22d9a50111::ForcedClientCompositionViaDebugOptionResultVariant1106     static void setupCallExpectationsForDirtyFrame(CompositionTest*) {}
1107 };
1108 
1109 struct EmptyScreenshotResultVariant {
setupLayerStateandroid::__anon9d22d9a50111::EmptyScreenshotResultVariant1110     static void setupLayerState(CompositionTest*, sp<Layer>) {}
1111 
1112     template <typename Case>
setupCallExpectationsandroid::__anon9d22d9a50111::EmptyScreenshotResultVariant1113     static void setupCallExpectations(CompositionTest*) {}
1114 };
1115 
1116 struct REScreenshotResultVariant : public EmptyScreenshotResultVariant {
1117     using Base = EmptyScreenshotResultVariant;
1118 
1119     template <typename Case>
setupCallExpectationsandroid::__anon9d22d9a50111::REScreenshotResultVariant1120     static void setupCallExpectations(CompositionTest* test) {
1121         Base::template setupCallExpectations<Case>(test);
1122         Case::Display::template setupRELayerScreenshotCompositionCallExpectations<Case>(test);
1123     }
1124 };
1125 
1126 /* ------------------------------------------------------------------------
1127  * Composition test case, containing all the variants being tested
1128  */
1129 
1130 template <typename DisplayCase, typename LayerCase, typename CompositionTypeCase,
1131           typename CompositionResultCase>
1132 struct CompositionCase {
1133     using ThisCase =
1134             CompositionCase<DisplayCase, LayerCase, CompositionTypeCase, CompositionResultCase>;
1135     using Display = DisplayCase;
1136     using Layer = LayerCase;
1137     using CompositionType = CompositionTypeCase;
1138     using CompositionResult = CompositionResultCase;
1139 
setupCommonandroid::__anon9d22d9a50111::CompositionCase1140     static void setupCommon(CompositionTest* test) {
1141         Display::template setupPreconditionCallExpectations<ThisCase>(test);
1142         Display::setupPreconditions(test);
1143 
1144         auto layer = Layer::createLayer(test);
1145         Layer::injectLayer(test, layer);
1146         CompositionResult::setupLayerState(test, layer);
1147     }
1148 
setupForDirtyGeometryandroid::__anon9d22d9a50111::CompositionCase1149     static void setupForDirtyGeometry(CompositionTest* test) {
1150         setupCommon(test);
1151 
1152         Display::template setupCommonCompositionCallExpectations<ThisCase>(test);
1153         CompositionResult::template setupCallExpectationsForDirtyGeometry<ThisCase>(test);
1154         CompositionResult::template setupCallExpectationsForDirtyFrame<ThisCase>(test);
1155         CompositionResult::template setupCallExpectations<ThisCase>(test);
1156     }
1157 
setupForDirtyFrameandroid::__anon9d22d9a50111::CompositionCase1158     static void setupForDirtyFrame(CompositionTest* test) {
1159         setupCommon(test);
1160 
1161         Display::template setupCommonCompositionCallExpectations<ThisCase>(test);
1162         CompositionResult::template setupCallExpectationsForDirtyFrame<ThisCase>(test);
1163         CompositionResult::template setupCallExpectations<ThisCase>(test);
1164     }
1165 
setupForScreenCaptureandroid::__anon9d22d9a50111::CompositionCase1166     static void setupForScreenCapture(CompositionTest* test) {
1167         setupCommon(test);
1168 
1169         Display::template setupCommonScreensCaptureCallExpectations<ThisCase>(test);
1170         CompositionResult::template setupCallExpectations<ThisCase>(test);
1171     }
1172 
cleanupandroid::__anon9d22d9a50111::CompositionCase1173     static void cleanup(CompositionTest* test) {
1174         Layer::cleanupInjectedLayers(test);
1175 
1176         for (auto& displayData : test->mFlinger.mutableHwcDisplayData()) {
1177             static_cast<TestableSurfaceFlinger::HWC2Display*>(displayData.second.hwcDisplay.get())
1178                     ->mutableLayers()
1179                     .clear();
1180         }
1181     }
1182 };
1183 
1184 /* ------------------------------------------------------------------------
1185  * Composition cases to test
1186  */
1187 
TEST_F(CompositionTest,noLayersDoesMinimalWorkWithDirtyGeometry)1188 TEST_F(CompositionTest, noLayersDoesMinimalWorkWithDirtyGeometry) {
1189     displayRefreshCompositionDirtyGeometry<
1190             CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant,
1191                             NoCompositionResultVariant>>();
1192 }
1193 
TEST_F(CompositionTest,noLayersDoesMinimalWorkWithDirtyFrame)1194 TEST_F(CompositionTest, noLayersDoesMinimalWorkWithDirtyFrame) {
1195     displayRefreshCompositionDirtyFrame<
1196             CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant,
1197                             NoCompositionResultVariant>>();
1198 }
1199 
TEST_F(CompositionTest,noLayersDoesMinimalWorkToCaptureScreen)1200 TEST_F(CompositionTest, noLayersDoesMinimalWorkToCaptureScreen) {
1201     captureScreenComposition<
1202             CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant,
1203                             EmptyScreenshotResultVariant>>();
1204 }
1205 
1206 /* ------------------------------------------------------------------------
1207  *  Simple buffer layers
1208  */
1209 
TEST_F(CompositionTest,HWCComposedNormalBufferLayerWithDirtyGeometry)1210 TEST_F(CompositionTest, HWCComposedNormalBufferLayerWithDirtyGeometry) {
1211     displayRefreshCompositionDirtyGeometry<CompositionCase<
1212             DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1213             KeepCompositionTypeVariant<
1214                     aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
1215             HwcCompositionResultVariant>>();
1216 }
1217 
TEST_F(CompositionTest,HWCComposedNormalBufferLayerWithDirtyFrame)1218 TEST_F(CompositionTest, HWCComposedNormalBufferLayerWithDirtyFrame) {
1219     displayRefreshCompositionDirtyFrame<CompositionCase<
1220             DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1221             KeepCompositionTypeVariant<
1222                     aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
1223             HwcCompositionResultVariant>>();
1224 }
1225 
TEST_F(CompositionTest,REComposedNormalBufferLayer)1226 TEST_F(CompositionTest, REComposedNormalBufferLayer) {
1227     displayRefreshCompositionDirtyFrame<CompositionCase<
1228             DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1229             ChangeCompositionTypeVariant<
1230                     aidl::android::hardware::graphics::composer3::Composition::DEVICE,
1231                     aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1232             RECompositionResultVariant>>();
1233 }
1234 
TEST_F(CompositionTest,captureScreenNormalBufferLayer)1235 TEST_F(CompositionTest, captureScreenNormalBufferLayer) {
1236     captureScreenComposition<
1237             CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1238                             NoCompositionTypeVariant, REScreenshotResultVariant>>();
1239 }
1240 
1241 /* ------------------------------------------------------------------------
1242  *  Single-color layers
1243  */
1244 
TEST_F(CompositionTest,HWCComposedEffectLayerWithDirtyGeometry)1245 TEST_F(CompositionTest, HWCComposedEffectLayerWithDirtyGeometry) {
1246     displayRefreshCompositionDirtyGeometry<CompositionCase<
1247             DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
1248             KeepCompositionTypeVariant<
1249                     aidl::android::hardware::graphics::composer3::Composition::SOLID_COLOR>,
1250             HwcCompositionResultVariant>>();
1251 }
1252 
TEST_F(CompositionTest,HWCComposedEffectLayerWithDirtyFrame)1253 TEST_F(CompositionTest, HWCComposedEffectLayerWithDirtyFrame) {
1254     displayRefreshCompositionDirtyFrame<CompositionCase<
1255             DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
1256             KeepCompositionTypeVariant<
1257                     aidl::android::hardware::graphics::composer3::Composition::SOLID_COLOR>,
1258             HwcCompositionResultVariant>>();
1259 }
1260 
TEST_F(CompositionTest,REComposedEffectLayer)1261 TEST_F(CompositionTest, REComposedEffectLayer) {
1262     displayRefreshCompositionDirtyFrame<CompositionCase<
1263             DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
1264             ChangeCompositionTypeVariant<
1265                     aidl::android::hardware::graphics::composer3::Composition::SOLID_COLOR,
1266                     aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1267             RECompositionResultVariant>>();
1268 }
1269 
TEST_F(CompositionTest,captureScreenEffectLayer)1270 TEST_F(CompositionTest, captureScreenEffectLayer) {
1271     captureScreenComposition<
1272             CompositionCase<DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
1273                             NoCompositionTypeVariant, REScreenshotResultVariant>>();
1274 }
1275 
1276 /* ------------------------------------------------------------------------
1277  *  Layers with sideband buffers
1278  */
1279 
TEST_F(CompositionTest,HWCComposedSidebandBufferLayerWithDirtyGeometry)1280 TEST_F(CompositionTest, HWCComposedSidebandBufferLayerWithDirtyGeometry) {
1281     displayRefreshCompositionDirtyGeometry<CompositionCase<
1282             DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1283             KeepCompositionTypeVariant<
1284                     aidl::android::hardware::graphics::composer3::Composition::SIDEBAND>,
1285             HwcCompositionResultVariant>>();
1286 }
1287 
TEST_F(CompositionTest,HWCComposedSidebandBufferLayerWithDirtyFrame)1288 TEST_F(CompositionTest, HWCComposedSidebandBufferLayerWithDirtyFrame) {
1289     displayRefreshCompositionDirtyFrame<CompositionCase<
1290             DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1291             KeepCompositionTypeVariant<
1292                     aidl::android::hardware::graphics::composer3::Composition::SIDEBAND>,
1293             HwcCompositionResultVariant>>();
1294 }
1295 
TEST_F(CompositionTest,REComposedSidebandBufferLayer)1296 TEST_F(CompositionTest, REComposedSidebandBufferLayer) {
1297     displayRefreshCompositionDirtyFrame<CompositionCase<
1298             DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1299             ChangeCompositionTypeVariant<
1300                     aidl::android::hardware::graphics::composer3::Composition::SIDEBAND,
1301                     aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1302             RECompositionResultVariant>>();
1303 }
1304 
TEST_F(CompositionTest,captureScreenSidebandBufferLayer)1305 TEST_F(CompositionTest, captureScreenSidebandBufferLayer) {
1306     captureScreenComposition<
1307             CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1308                             NoCompositionTypeVariant, REScreenshotResultVariant>>();
1309 }
1310 
1311 /* ------------------------------------------------------------------------
1312  *  Layers with ISurfaceComposerClient::eSecure, on a secure display
1313  */
1314 
TEST_F(CompositionTest,HWCComposedSecureBufferLayerWithDirtyGeometry)1315 TEST_F(CompositionTest, HWCComposedSecureBufferLayerWithDirtyGeometry) {
1316     displayRefreshCompositionDirtyGeometry<CompositionCase<
1317             DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1318             KeepCompositionTypeVariant<
1319                     aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
1320             HwcCompositionResultVariant>>();
1321 }
1322 
TEST_F(CompositionTest,HWCComposedSecureBufferLayerWithDirtyFrame)1323 TEST_F(CompositionTest, HWCComposedSecureBufferLayerWithDirtyFrame) {
1324     displayRefreshCompositionDirtyFrame<CompositionCase<
1325             DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1326             KeepCompositionTypeVariant<
1327                     aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
1328             HwcCompositionResultVariant>>();
1329 }
1330 
TEST_F(CompositionTest,REComposedSecureBufferLayer)1331 TEST_F(CompositionTest, REComposedSecureBufferLayer) {
1332     displayRefreshCompositionDirtyFrame<CompositionCase<
1333             DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1334             ChangeCompositionTypeVariant<
1335                     aidl::android::hardware::graphics::composer3::Composition::DEVICE,
1336                     aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1337             RECompositionResultVariant>>();
1338 }
1339 
TEST_F(CompositionTest,captureScreenSecureBufferLayerOnSecureDisplay)1340 TEST_F(CompositionTest, captureScreenSecureBufferLayerOnSecureDisplay) {
1341     captureScreenComposition<
1342             CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1343                             NoCompositionTypeVariant, REScreenshotResultVariant>>();
1344 }
1345 
1346 /* ------------------------------------------------------------------------
1347  *  Layers with ISurfaceComposerClient::eSecure, on a non-secure display
1348  */
1349 
TEST_F(CompositionTest,HWCComposedSecureBufferLayerOnInsecureDisplayWithDirtyGeometry)1350 TEST_F(CompositionTest, HWCComposedSecureBufferLayerOnInsecureDisplayWithDirtyGeometry) {
1351     displayRefreshCompositionDirtyGeometry<CompositionCase<
1352             InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1353             KeepCompositionTypeVariant<
1354                     aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1355             ForcedClientCompositionResultVariant>>();
1356 }
1357 
TEST_F(CompositionTest,HWCComposedSecureBufferLayerOnInsecureDisplayWithDirtyFrame)1358 TEST_F(CompositionTest, HWCComposedSecureBufferLayerOnInsecureDisplayWithDirtyFrame) {
1359     displayRefreshCompositionDirtyFrame<CompositionCase<
1360             InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1361             KeepCompositionTypeVariant<
1362                     aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1363             ForcedClientCompositionResultVariant>>();
1364 }
1365 
TEST_F(CompositionTest,captureScreenSecureBufferLayerOnInsecureDisplay)1366 TEST_F(CompositionTest, captureScreenSecureBufferLayerOnInsecureDisplay) {
1367     captureScreenComposition<
1368             CompositionCase<InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1369                             NoCompositionTypeVariant, REScreenshotResultVariant>>();
1370 }
1371 
1372 /* ------------------------------------------------------------------------
1373  *  Layers with a parent layer with ISurfaceComposerClient::eSecure, on a non-secure display
1374  */
1375 
TEST_F(CompositionTest,HWCComposedBufferLayerWithSecureParentLayerOnInsecureDisplayWithDirtyGeometry)1376 TEST_F(CompositionTest,
1377        HWCComposedBufferLayerWithSecureParentLayerOnInsecureDisplayWithDirtyGeometry) {
1378     displayRefreshCompositionDirtyGeometry<CompositionCase<
1379             InsecureDisplaySetupVariant,
1380             ChildLayerVariant<BufferLayerVariant<ParentSecureLayerProperties>,
1381                               ContainerLayerVariant<SecureLayerProperties>>,
1382             KeepCompositionTypeVariant<
1383                     aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1384             ForcedClientCompositionResultVariant>>();
1385 }
1386 
TEST_F(CompositionTest,HWCComposedBufferLayerWithSecureParentLayerOnInsecureDisplayWithDirtyFrame)1387 TEST_F(CompositionTest,
1388        HWCComposedBufferLayerWithSecureParentLayerOnInsecureDisplayWithDirtyFrame) {
1389     displayRefreshCompositionDirtyFrame<CompositionCase<
1390             InsecureDisplaySetupVariant,
1391             ChildLayerVariant<BufferLayerVariant<ParentSecureLayerProperties>,
1392                               ContainerLayerVariant<SecureLayerProperties>>,
1393             KeepCompositionTypeVariant<
1394                     aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1395             ForcedClientCompositionResultVariant>>();
1396 }
1397 
TEST_F(CompositionTest,captureScreenBufferLayerWithSecureParentLayerOnInsecureDisplay)1398 TEST_F(CompositionTest, captureScreenBufferLayerWithSecureParentLayerOnInsecureDisplay) {
1399     captureScreenComposition<
1400             CompositionCase<InsecureDisplaySetupVariant,
1401                             ChildLayerVariant<BufferLayerVariant<ParentSecureLayerProperties>,
1402                                               ContainerLayerVariant<SecureLayerProperties>>,
1403                             NoCompositionTypeVariant, REScreenshotResultVariant>>();
1404 }
1405 
1406 /* ------------------------------------------------------------------------
1407  *  Cursor layers
1408  */
1409 
TEST_F(CompositionTest,HWCComposedCursorLayerWithDirtyGeometry)1410 TEST_F(CompositionTest, HWCComposedCursorLayerWithDirtyGeometry) {
1411     displayRefreshCompositionDirtyGeometry<CompositionCase<
1412             DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1413             KeepCompositionTypeVariant<
1414                     aidl::android::hardware::graphics::composer3::Composition::CURSOR>,
1415             HwcCompositionResultVariant>>();
1416 }
1417 
TEST_F(CompositionTest,HWCComposedCursorLayerWithDirtyFrame)1418 TEST_F(CompositionTest, HWCComposedCursorLayerWithDirtyFrame) {
1419     displayRefreshCompositionDirtyFrame<CompositionCase<
1420             DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1421             KeepCompositionTypeVariant<
1422                     aidl::android::hardware::graphics::composer3::Composition::CURSOR>,
1423             HwcCompositionResultVariant>>();
1424 }
1425 
TEST_F(CompositionTest,REComposedCursorLayer)1426 TEST_F(CompositionTest, REComposedCursorLayer) {
1427     displayRefreshCompositionDirtyFrame<CompositionCase<
1428             DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1429             ChangeCompositionTypeVariant<
1430                     aidl::android::hardware::graphics::composer3::Composition::CURSOR,
1431                     aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1432             RECompositionResultVariant>>();
1433 }
1434 
TEST_F(CompositionTest,captureScreenCursorLayer)1435 TEST_F(CompositionTest, captureScreenCursorLayer) {
1436     captureScreenComposition<
1437             CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1438                             NoCompositionTypeVariant, REScreenshotResultVariant>>();
1439 }
1440 
1441 /* ------------------------------------------------------------------------
1442  *  Simple buffer layer on a display which is powered off.
1443  */
1444 
TEST_F(CompositionTest,displayOffHWCComposedNormalBufferLayerWithDirtyGeometry)1445 TEST_F(CompositionTest, displayOffHWCComposedNormalBufferLayerWithDirtyGeometry) {
1446     mDisplayOff = true;
1447     displayRefreshCompositionDirtyGeometry<CompositionCase<
1448             PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1449             KeepCompositionTypeVariant<
1450                     aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
1451             HwcCompositionResultVariant>>();
1452 }
1453 
TEST_F(CompositionTest,displayOffHWCComposedNormalBufferLayerWithDirtyFrame)1454 TEST_F(CompositionTest, displayOffHWCComposedNormalBufferLayerWithDirtyFrame) {
1455     mDisplayOff = true;
1456     displayRefreshCompositionDirtyFrame<CompositionCase<
1457             PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1458             KeepCompositionTypeVariant<
1459                     aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
1460             HwcCompositionResultVariant>>();
1461 }
1462 
TEST_F(CompositionTest,displayOffREComposedNormalBufferLayer)1463 TEST_F(CompositionTest, displayOffREComposedNormalBufferLayer) {
1464     mDisplayOff = true;
1465     displayRefreshCompositionDirtyFrame<CompositionCase<
1466             PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1467             ChangeCompositionTypeVariant<
1468                     aidl::android::hardware::graphics::composer3::Composition::DEVICE,
1469                     aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1470             RECompositionResultVariant>>();
1471 }
1472 
TEST_F(CompositionTest,captureScreenNormalBufferLayerOnPoweredOffDisplay)1473 TEST_F(CompositionTest, captureScreenNormalBufferLayerOnPoweredOffDisplay) {
1474     captureScreenComposition<CompositionCase<
1475             PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1476             NoCompositionTypeVariant, REScreenshotResultVariant>>();
1477 }
1478 
1479 /* ------------------------------------------------------------------------
1480  *  Client composition forced through debug/developer settings
1481  */
1482 
TEST_F(CompositionTest,DebugOptionForcingClientCompositionOfBufferLayerWithDirtyGeometry)1483 TEST_F(CompositionTest, DebugOptionForcingClientCompositionOfBufferLayerWithDirtyGeometry) {
1484     displayRefreshCompositionDirtyGeometry<CompositionCase<
1485             DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1486             KeepCompositionTypeVariant<
1487                     aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1488             ForcedClientCompositionViaDebugOptionResultVariant>>();
1489 }
1490 
TEST_F(CompositionTest,DebugOptionForcingClientCompositionOfBufferLayerWithDirtyFrame)1491 TEST_F(CompositionTest, DebugOptionForcingClientCompositionOfBufferLayerWithDirtyFrame) {
1492     displayRefreshCompositionDirtyFrame<CompositionCase<
1493             DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1494             KeepCompositionTypeVariant<
1495                     aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1496             ForcedClientCompositionViaDebugOptionResultVariant>>();
1497 }
1498 
1499 } // namespace
1500 } // namespace android
1501 
1502 // TODO(b/129481165): remove the #pragma below and fix conversion issues
1503 #pragma clang diagnostic pop // ignored "-Wconversion -Wextra"
1504