blob: 89a517ffad983784336e2ea8a4b7ed36b0961dc6 [file] [log] [blame]
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001/*
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
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -080017// TODO(b/129481165): remove the #pragma below and fix conversion issues
Alec Mouria90a5702021-04-16 16:36:21 +000018#include "renderengine/ExternalTexture.h"
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -080019#pragma clang diagnostic push
20#pragma clang diagnostic ignored "-Wconversion"
Marin Shalamanovbed7fd32020-12-21 20:02:20 +010021#pragma clang diagnostic ignored "-Wextra"
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -080022
Lloyd Piqued6b579f2018-04-06 15:29:10 -070023#undef LOG_TAG
24#define LOG_TAG "CompositionTest"
25
Lloyd Pique37c2c9b2018-12-04 17:25:10 -080026#include <compositionengine/Display.h>
Lloyd Pique542307f2018-10-19 13:24:08 -070027#include <compositionengine/mock/DisplaySurface.h>
Lloyd Piqued6b579f2018-04-06 15:29:10 -070028#include <gmock/gmock.h>
29#include <gtest/gtest.h>
Lloyd Piqued6b579f2018-04-06 15:29:10 -070030#include <gui/IProducerListener.h>
Evan Roskya1f1e152019-01-24 16:17:46 -080031#include <gui/LayerMetadata.h>
Lloyd Piqued6b579f2018-04-06 15:29:10 -070032#include <log/log.h>
Lloyd Pique3823e7b2018-10-18 16:58:10 -070033#include <renderengine/mock/Framebuffer.h>
34#include <renderengine/mock/Image.h>
35#include <renderengine/mock/RenderEngine.h>
Lloyd Piqued6b579f2018-04-06 15:29:10 -070036#include <system/window.h>
37#include <utils/String8.h>
38
39#include "BufferQueueLayer.h"
Garfield Tande619fa2020-10-02 17:13:53 -070040#include "ContainerLayer.h"
Marin Shalamanovf6b5d182020-06-12 02:08:51 +020041#include "DisplayRenderArea.h"
Vishnu Nairfa247b12020-02-11 08:58:26 -080042#include "EffectLayer.h"
Lloyd Piqued6b579f2018-04-06 15:29:10 -070043#include "Layer.h"
Lloyd Piqued6b579f2018-04-06 15:29:10 -070044#include "TestableSurfaceFlinger.h"
45#include "mock/DisplayHardware/MockComposer.h"
Lloyd Pique9370a482019-10-03 17:58:30 -070046#include "mock/DisplayHardware/MockPowerAdvisor.h"
Lloyd Piqued6b579f2018-04-06 15:29:10 -070047#include "mock/MockEventThread.h"
Alec Mourie4034bb2019-11-19 12:45:54 -080048#include "mock/MockTimeStats.h"
Ady Abraham8cb21882020-08-26 18:22:05 -070049#include "mock/MockVsyncController.h"
Alec Mouriba013fa2018-10-16 12:43:11 -070050#include "mock/system/window/MockNativeWindow.h"
Lloyd Piqued6b579f2018-04-06 15:29:10 -070051
52namespace android {
53namespace {
54
Peiyong Line9d809e2020-04-14 13:10:48 -070055namespace hal = android::hardware::graphics::composer::hal;
56
Peiyong Lin65248e02020-04-18 21:15:07 -070057using hal::Error;
58using hal::IComposer;
59using hal::IComposerClient;
60using hal::PowerMode;
61using hal::Transform;
62
Lloyd Piqued6b579f2018-04-06 15:29:10 -070063using testing::_;
David Sodman15094112018-10-11 09:39:37 -070064using testing::AtLeast;
Lloyd Piqued6b579f2018-04-06 15:29:10 -070065using testing::DoAll;
66using testing::IsNull;
67using testing::Mock;
Lloyd Piqued6b579f2018-04-06 15:29:10 -070068using testing::Return;
69using testing::ReturnRef;
70using testing::SetArgPointee;
71
Lloyd Piqued6b579f2018-04-06 15:29:10 -070072using FakeHwcDisplayInjector = TestableSurfaceFlinger::FakeHwcDisplayInjector;
73using FakeDisplayDeviceInjector = TestableSurfaceFlinger::FakeDisplayDeviceInjector;
74
Peiyong Line9d809e2020-04-14 13:10:48 -070075constexpr hal::HWDisplayId HWC_DISPLAY = FakeHwcDisplayInjector::DEFAULT_HWC_DISPLAY_ID;
76constexpr hal::HWLayerId HWC_LAYER = 5000;
Lloyd Piqued6b579f2018-04-06 15:29:10 -070077constexpr Transform DEFAULT_TRANSFORM = static_cast<Transform>(0);
78
Dominik Laskowskif1833852021-03-23 15:06:50 -070079constexpr PhysicalDisplayId DEFAULT_DISPLAY_ID = PhysicalDisplayId::fromPort(42u);
Lloyd Piqued6b579f2018-04-06 15:29:10 -070080constexpr int DEFAULT_DISPLAY_WIDTH = 1920;
81constexpr int DEFAULT_DISPLAY_HEIGHT = 1024;
82
Lloyd Piqued6b579f2018-04-06 15:29:10 -070083constexpr int DEFAULT_TEXTURE_ID = 6000;
Dominik Laskowski29fa1462021-04-27 15:51:50 -070084constexpr ui::LayerStack LAYER_STACK{7000u};
Lloyd Piqued6b579f2018-04-06 15:29:10 -070085
86constexpr int DEFAULT_DISPLAY_MAX_LUMINANCE = 500;
87
88constexpr int DEFAULT_SIDEBAND_STREAM = 51;
89
Ady Abrahamdc011a92021-12-21 14:06:44 -080090MATCHER(IsIdentityMatrix, "") {
91 constexpr auto kIdentity = mat4();
92 return (mat4(arg) == kIdentity);
93}
94
Lloyd Piqued6b579f2018-04-06 15:29:10 -070095class CompositionTest : public testing::Test {
96public:
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
Ana Krulecafb45842019-02-13 13:33:03 -0800102 setupScheduler();
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700103
Alec Mourif6fd29e2018-11-17 04:56:41 +0000104 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)));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700108
109 mFlinger.setupRenderEngine(std::unique_ptr<renderengine::RenderEngine>(mRenderEngine));
Alec Mourie4034bb2019-11-19 12:45:54 -0800110 mFlinger.setupTimeStats(std::shared_ptr<TimeStats>(mTimeStats));
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800111
112 mComposer = new Hwc2::mock::Composer();
113 mFlinger.setupComposer(std::unique_ptr<Hwc2::Composer>(mComposer));
Garfield Tan9c9c1912021-07-19 12:02:16 -0700114
115 mFlinger.mutableMaxRenderTargetSize() = 16384;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700116 }
117
118 ~CompositionTest() {
119 const ::testing::TestInfo* const test_info =
120 ::testing::UnitTest::GetInstance()->current_test_info();
121 ALOGD("**** Tearing down after %s.%s\n", test_info->test_case_name(), test_info->name());
122 }
123
Ana Krulecafb45842019-02-13 13:33:03 -0800124 void setupScheduler() {
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700125 auto eventThread = std::make_unique<mock::EventThread>();
126 auto sfEventThread = std::make_unique<mock::EventThread>();
Ana Krulecafb45842019-02-13 13:33:03 -0800127
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700128 EXPECT_CALL(*eventThread, registerDisplayEventConnection(_));
Dominik Laskowski98041832019-08-01 18:35:59 -0700129 EXPECT_CALL(*eventThread, createEventConnection(_, _))
Ady Abraham62f216c2020-10-13 19:07:23 -0700130 .WillOnce(Return(new EventThreadConnection(eventThread.get(), /*callingUid=*/0,
131 ResyncCallback())));
Dominik Laskowski98041832019-08-01 18:35:59 -0700132
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700133 EXPECT_CALL(*sfEventThread, registerDisplayEventConnection(_));
Dominik Laskowski98041832019-08-01 18:35:59 -0700134 EXPECT_CALL(*sfEventThread, createEventConnection(_, _))
Ady Abraham62f216c2020-10-13 19:07:23 -0700135 .WillOnce(Return(new EventThreadConnection(sfEventThread.get(), /*callingUid=*/0,
136 ResyncCallback())));
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700137
Ady Abraham8cb21882020-08-26 18:22:05 -0700138 auto vsyncController = std::make_unique<mock::VsyncController>();
139 auto vsyncTracker = std::make_unique<mock::VSyncTracker>();
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700140
Ady Abraham8cb21882020-08-26 18:22:05 -0700141 EXPECT_CALL(*vsyncTracker, nextAnticipatedVSyncTimeFrom(_)).WillRepeatedly(Return(0));
142 EXPECT_CALL(*vsyncTracker, currentPeriod())
Marin Shalamanov045b7002021-01-07 16:56:24 +0100143 .WillRepeatedly(Return(FakeHwcDisplayInjector::DEFAULT_VSYNC_PERIOD));
Ady Abraham8cb21882020-08-26 18:22:05 -0700144 EXPECT_CALL(*vsyncTracker, nextAnticipatedVSyncTimeFrom(_)).WillRepeatedly(Return(0));
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700145
Dominik Laskowski068173d2021-08-11 17:22:59 -0700146 constexpr scheduler::ISchedulerCallback* kCallback = nullptr;
Dominik Laskowski983f2b52020-06-25 16:54:06 -0700147 constexpr bool kHasMultipleConfigs = true;
Ady Abraham8cb21882020-08-26 18:22:05 -0700148 mFlinger.setupScheduler(std::move(vsyncController), std::move(vsyncTracker),
149 std::move(eventThread), std::move(sfEventThread), kCallback,
150 kHasMultipleConfigs);
Ana Krulecafb45842019-02-13 13:33:03 -0800151 }
152
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700153 void setupForceGeometryDirty() {
154 // TODO: This requires the visible region and other related
155 // state to be set, and is problematic for BufferLayers since they are
156 // not visible without a buffer (and setting up a buffer looks like a
157 // pain)
158 // mFlinger.mutableVisibleRegionsDirty() = true;
159
Dominik Laskowski8da6b0e2021-05-12 15:34:13 -0700160 mFlinger.mutableGeometryDirty() = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700161 }
162
163 template <typename Case>
164 void displayRefreshCompositionDirtyGeometry();
165
166 template <typename Case>
167 void displayRefreshCompositionDirtyFrame();
168
169 template <typename Case>
170 void captureScreenComposition();
171
Peiyong Line9d809e2020-04-14 13:10:48 -0700172 std::unordered_set<hal::Capability> mDefaultCapabilities = {hal::Capability::SIDEBAND_STREAM};
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700173
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800174 bool mDisplayOff = false;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700175 TestableSurfaceFlinger mFlinger;
176 sp<DisplayDevice> mDisplay;
177 sp<DisplayDevice> mExternalDisplay;
Lloyd Pique542307f2018-10-19 13:24:08 -0700178 sp<compositionengine::mock::DisplaySurface> mDisplaySurface =
179 new compositionengine::mock::DisplaySurface();
Alec Mouriba013fa2018-10-16 12:43:11 -0700180 mock::NativeWindow* mNativeWindow = new mock::NativeWindow();
Garfield Tande619fa2020-10-02 17:13:53 -0700181 std::vector<sp<Layer>> mAuxiliaryLayers;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700182
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800183 sp<GraphicBuffer> mBuffer = new GraphicBuffer();
184 ANativeWindowBuffer* mNativeWindowBuffer = mBuffer->getNativeBuffer();
185
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700186 Hwc2::mock::Composer* mComposer = nullptr;
187 renderengine::mock::RenderEngine* mRenderEngine = new renderengine::mock::RenderEngine();
Alec Mourie4034bb2019-11-19 12:45:54 -0800188 mock::TimeStats* mTimeStats = new mock::TimeStats();
Lloyd Pique9370a482019-10-03 17:58:30 -0700189 Hwc2::mock::PowerAdvisor mPowerAdvisor;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700190
191 sp<Fence> mClientTargetAcquireFence = Fence::NO_FENCE;
192
Alec Mouria90a5702021-04-16 16:36:21 +0000193 std::shared_ptr<renderengine::ExternalTexture> mCaptureScreenBuffer;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700194};
195
196template <typename LayerCase>
197void CompositionTest::displayRefreshCompositionDirtyGeometry() {
198 setupForceGeometryDirty();
199 LayerCase::setupForDirtyGeometry(this);
200
201 // --------------------------------------------------------------------
202 // Invocation
203
Dominik Laskowskie0e0cde2021-07-30 10:42:05 -0700204 mFlinger.commitAndComposite();
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700205
206 LayerCase::cleanup(this);
207}
208
209template <typename LayerCase>
210void CompositionTest::displayRefreshCompositionDirtyFrame() {
211 LayerCase::setupForDirtyFrame(this);
212
213 // --------------------------------------------------------------------
214 // Invocation
215
Dominik Laskowskie0e0cde2021-07-30 10:42:05 -0700216 mFlinger.commitAndComposite();
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700217
218 LayerCase::cleanup(this);
219}
220
221template <typename LayerCase>
222void CompositionTest::captureScreenComposition() {
223 LayerCase::setupForScreenCapture(this);
224
225 const Rect sourceCrop(0, 0, DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700226 constexpr bool forSystem = true;
Lucas Dupin9d763b72020-04-20 18:42:31 -0700227 constexpr bool regionSampling = false;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700228
Marin Shalamanov1c434292020-06-12 01:47:29 +0200229 auto renderArea = DisplayRenderArea::create(mDisplay, sourceCrop, sourceCrop.getSize(),
230 ui::Dataspace::V0_SRGB, ui::Transform::ROT_0);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700231
232 auto traverseLayers = [this](const LayerVector::Visitor& visitor) {
chaviw4b9d5e12020-08-04 18:30:35 -0700233 return mFlinger.traverseLayersInLayerStack(mDisplay->getLayerStack(),
234 CaptureArgs::UNSET_UID, visitor);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700235 };
236
237 // TODO: Eliminate expensive/real allocation if possible.
238 const uint32_t usage = GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN |
239 GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_TEXTURE;
Alec Mouria90a5702021-04-16 16:36:21 +0000240 mCaptureScreenBuffer = std::make_shared<
241 renderengine::ExternalTexture>(new GraphicBuffer(renderArea->getReqWidth(),
242 renderArea->getReqHeight(),
243 HAL_PIXEL_FORMAT_RGBA_8888, 1, usage,
244 "screenshot"),
245 *mRenderEngine, true);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700246
Sally Qi59a9f502021-10-12 18:53:23 +0000247 auto result = mFlinger.renderScreenImplLocked(*renderArea, traverseLayers, mCaptureScreenBuffer,
248 forSystem, regionSampling);
249 EXPECT_TRUE(result.valid());
250
251 auto& [status, drawFence] = result.get();
252
253 EXPECT_EQ(NO_ERROR, status);
254 if (drawFence.ok()) {
255 sync_wait(drawFence.get(), -1);
256 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700257
258 LayerCase::cleanup(this);
259}
260
Sally Qi4cabdd02021-08-05 16:45:57 -0700261template <class T>
262std::future<T> futureOf(T obj) {
263 std::promise<T> resultPromise;
264 std::future<T> resultFuture = resultPromise.get_future();
265 resultPromise.set_value(std::move(obj));
266 return resultFuture;
267}
268
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700269/* ------------------------------------------------------------------------
270 * Variants for each display configuration which can be tested
271 */
272
273template <typename Derived>
274struct BaseDisplayVariant {
275 static constexpr bool IS_SECURE = true;
Peiyong Lin65248e02020-04-18 21:15:07 -0700276 static constexpr hal::PowerMode INIT_POWER_MODE = hal::PowerMode::ON;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700277
278 static void setupPreconditions(CompositionTest* test) {
Peiyong Lin65248e02020-04-18 21:15:07 -0700279 EXPECT_CALL(*test->mComposer, setPowerMode(HWC_DISPLAY, Derived::INIT_POWER_MODE))
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700280 .WillOnce(Return(Error::NONE));
Alec Mouriba013fa2018-10-16 12:43:11 -0700281
Peiyong Line9d809e2020-04-14 13:10:48 -0700282 FakeHwcDisplayInjector(DEFAULT_DISPLAY_ID, hal::DisplayType::PHYSICAL, true /* isPrimary */)
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700283 .setCapabilities(&test->mDefaultCapabilities)
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700284 .setPowerMode(Derived::INIT_POWER_MODE)
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700285 .inject(&test->mFlinger, test->mComposer);
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800286 Mock::VerifyAndClear(test->mComposer);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700287
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800288 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
289 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_WIDTH), Return(0)));
290 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
291 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_HEIGHT), Return(0)));
292 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT)).Times(1);
293 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_API_CONNECT)).Times(1);
294 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_USAGE64)).Times(1);
Lloyd Pique9370a482019-10-03 17:58:30 -0700295
296 const ::testing::TestInfo* const test_info =
297 ::testing::UnitTest::GetInstance()->current_test_info();
298
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800299 auto ceDisplayArgs = compositionengine::DisplayCreationArgsBuilder()
300 .setId(DEFAULT_DISPLAY_ID)
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800301 .setPixels({DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT})
302 .setIsSecure(Derived::IS_SECURE)
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800303 .setPowerAdvisor(&test->mPowerAdvisor)
304 .setName(std::string("Injected display for ") +
305 test_info->test_case_name() + "." + test_info->name())
306 .build();
Lloyd Pique9370a482019-10-03 17:58:30 -0700307
308 auto compositionDisplay =
309 compositionengine::impl::createDisplay(test->mFlinger.getCompositionEngine(),
310 ceDisplayArgs);
311
Marin Shalamanov700e6392020-02-12 20:22:26 +0100312 test->mDisplay = FakeDisplayDeviceInjector(test->mFlinger, compositionDisplay,
Marin Shalamanov228f46b2021-01-28 21:11:45 +0100313 ui::DisplayConnectionType::Internal, HWC_DISPLAY,
Marin Shalamanov700e6392020-02-12 20:22:26 +0100314 true /* isPrimary */)
315 .setDisplaySurface(test->mDisplaySurface)
316 .setNativeWindow(test->mNativeWindow)
317 .setSecure(Derived::IS_SECURE)
318 .setPowerMode(Derived::INIT_POWER_MODE)
319 .inject();
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800320 Mock::VerifyAndClear(test->mNativeWindow);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700321 test->mDisplay->setLayerStack(LAYER_STACK);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700322 }
323
324 template <typename Case>
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700325 static void setupPreconditionCallExpectations(CompositionTest* test) {
326 EXPECT_CALL(*test->mComposer, getDisplayCapabilities(HWC_DISPLAY, _))
327 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::DisplayCapability>({})),
328 Return(Error::NONE)));
329 }
330
331 template <typename Case>
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700332 static void setupCommonCompositionCallExpectations(CompositionTest* test) {
Ady Abrahamdc011a92021-12-21 14:06:44 -0800333 EXPECT_CALL(*test->mComposer, setColorTransform(HWC_DISPLAY, IsIdentityMatrix())).Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700334 EXPECT_CALL(*test->mComposer, getDisplayRequests(HWC_DISPLAY, _, _, _)).Times(1);
335 EXPECT_CALL(*test->mComposer, acceptDisplayChanges(HWC_DISPLAY)).Times(1);
336 EXPECT_CALL(*test->mComposer, presentDisplay(HWC_DISPLAY, _)).Times(1);
337 EXPECT_CALL(*test->mComposer, getReleaseFences(HWC_DISPLAY, _, _)).Times(1);
338
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700339 EXPECT_CALL(*test->mDisplaySurface, onFrameCommitted()).Times(1);
340 EXPECT_CALL(*test->mDisplaySurface, advanceFrame()).Times(1);
341
342 Case::CompositionType::setupHwcSetCallExpectations(test);
343 Case::CompositionType::setupHwcGetCallExpectations(test);
344 }
345
346 template <typename Case>
347 static void setupCommonScreensCaptureCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000348 EXPECT_CALL(*test->mRenderEngine, drawLayers)
Sally Qi4cabdd02021-08-05 16:45:57 -0700349 .WillRepeatedly([&](const renderengine::DisplaySettings& displaySettings,
Sally Qi59a9f502021-10-12 18:53:23 +0000350 const std::vector<renderengine::LayerSettings>&,
Sally Qi4cabdd02021-08-05 16:45:57 -0700351 const std::shared_ptr<renderengine::ExternalTexture>&,
Sally Qi59a9f502021-10-12 18:53:23 +0000352 const bool, base::unique_fd&&)
Sally Qi4cabdd02021-08-05 16:45:57 -0700353 -> std::future<renderengine::RenderEngineResult> {
Lloyd Pique9370a482019-10-03 17:58:30 -0700354 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
355 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
356 displaySettings.physicalDisplay);
357 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
358 displaySettings.clip);
Sally Qi4cabdd02021-08-05 16:45:57 -0700359 return futureOf<renderengine::RenderEngineResult>(
360 {NO_ERROR, base::unique_fd()});
Lloyd Pique9370a482019-10-03 17:58:30 -0700361 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700362 }
363
364 static void setupNonEmptyFrameCompositionCallExpectations(CompositionTest* test) {
365 EXPECT_CALL(*test->mDisplaySurface, beginFrame(true)).Times(1);
366 }
367
368 static void setupEmptyFrameCompositionCallExpectations(CompositionTest* test) {
369 EXPECT_CALL(*test->mDisplaySurface, beginFrame(false)).Times(1);
370 }
371
372 static void setupHwcCompositionCallExpectations(CompositionTest* test) {
Ady Abraham43065bd2021-12-10 17:22:15 -0800373 EXPECT_CALL(*test->mComposer, presentOrValidateDisplay(HWC_DISPLAY, _, _, _, _, _))
374 .Times(1);
Lloyd Pique66d68602019-02-13 14:23:31 -0800375
Lloyd Pique542307f2018-10-19 13:24:08 -0700376 EXPECT_CALL(*test->mDisplaySurface,
Dominik Laskowskif5d0ea52021-09-26 17:27:01 -0700377 prepareFrame(compositionengine::DisplaySurface::CompositionType::Hwc))
Lloyd Pique542307f2018-10-19 13:24:08 -0700378 .Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700379 }
380
Lloyd Pique66d68602019-02-13 14:23:31 -0800381 static void setupHwcClientCompositionCallExpectations(CompositionTest* test) {
Ady Abraham43065bd2021-12-10 17:22:15 -0800382 EXPECT_CALL(*test->mComposer, presentOrValidateDisplay(HWC_DISPLAY, _, _, _, _, _))
383 .Times(1);
Lloyd Pique66d68602019-02-13 14:23:31 -0800384 }
385
386 static void setupHwcForcedClientCompositionCallExpectations(CompositionTest* test) {
Ady Abraham43065bd2021-12-10 17:22:15 -0800387 EXPECT_CALL(*test->mComposer, validateDisplay(HWC_DISPLAY, _, _, _)).Times(1);
Lloyd Pique66d68602019-02-13 14:23:31 -0800388 }
389
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700390 static void setupRECompositionCallExpectations(CompositionTest* test) {
Lloyd Pique542307f2018-10-19 13:24:08 -0700391 EXPECT_CALL(*test->mDisplaySurface,
Dominik Laskowskif5d0ea52021-09-26 17:27:01 -0700392 prepareFrame(compositionengine::DisplaySurface::CompositionType::Gpu))
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700393 .Times(1);
394 EXPECT_CALL(*test->mDisplaySurface, getClientTargetAcquireFence())
395 .WillRepeatedly(ReturnRef(test->mClientTargetAcquireFence));
396
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800397 EXPECT_CALL(*test->mNativeWindow, queueBuffer(_, _)).WillOnce(Return(0));
398 EXPECT_CALL(*test->mNativeWindow, dequeueBuffer(_, _))
399 .WillOnce(DoAll(SetArgPointee<0>(test->mNativeWindowBuffer), SetArgPointee<1>(-1),
400 Return(0)));
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000401 EXPECT_CALL(*test->mRenderEngine, drawLayers)
Sally Qi4cabdd02021-08-05 16:45:57 -0700402 .WillRepeatedly([&](const renderengine::DisplaySettings& displaySettings,
Sally Qi59a9f502021-10-12 18:53:23 +0000403 const std::vector<renderengine::LayerSettings>&,
Sally Qi4cabdd02021-08-05 16:45:57 -0700404 const std::shared_ptr<renderengine::ExternalTexture>&,
Sally Qi59a9f502021-10-12 18:53:23 +0000405 const bool, base::unique_fd&&)
Sally Qi4cabdd02021-08-05 16:45:57 -0700406 -> std::future<renderengine::RenderEngineResult> {
Lloyd Pique9370a482019-10-03 17:58:30 -0700407 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
408 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
409 displaySettings.physicalDisplay);
410 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
411 displaySettings.clip);
412 EXPECT_EQ(ui::Dataspace::UNKNOWN, displaySettings.outputDataspace);
Sally Qi4cabdd02021-08-05 16:45:57 -0700413 return futureOf<renderengine::RenderEngineResult>(
414 {NO_ERROR, base::unique_fd()});
Lloyd Pique9370a482019-10-03 17:58:30 -0700415 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700416 }
417
418 template <typename Case>
419 static void setupRELayerCompositionCallExpectations(CompositionTest* test) {
420 Case::Layer::setupRECompositionCallExpectations(test);
421 }
422
423 template <typename Case>
424 static void setupRELayerScreenshotCompositionCallExpectations(CompositionTest* test) {
425 Case::Layer::setupREScreenshotCompositionCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700426 }
427};
428
429struct DefaultDisplaySetupVariant : public BaseDisplayVariant<DefaultDisplaySetupVariant> {};
430
431struct InsecureDisplaySetupVariant : public BaseDisplayVariant<InsecureDisplaySetupVariant> {
432 static constexpr bool IS_SECURE = false;
433
434 template <typename Case>
435 static void setupRELayerCompositionCallExpectations(CompositionTest* test) {
436 Case::Layer::setupInsecureRECompositionCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700437 }
438
439 template <typename Case>
440 static void setupRELayerScreenshotCompositionCallExpectations(CompositionTest* test) {
441 Case::Layer::setupInsecureREScreenshotCompositionCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700442 }
443};
444
445struct PoweredOffDisplaySetupVariant : public BaseDisplayVariant<PoweredOffDisplaySetupVariant> {
Peiyong Lin65248e02020-04-18 21:15:07 -0700446 static constexpr hal::PowerMode INIT_POWER_MODE = hal::PowerMode::OFF;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700447
448 template <typename Case>
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700449 static void setupPreconditionCallExpectations(CompositionTest*) {}
450
451 template <typename Case>
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700452 static void setupCommonCompositionCallExpectations(CompositionTest* test) {
453 // TODO: This seems like an unnecessary call if display is powered off.
Ady Abrahamdc011a92021-12-21 14:06:44 -0800454 EXPECT_CALL(*test->mComposer, setColorTransform(HWC_DISPLAY, IsIdentityMatrix())).Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700455
456 // TODO: This seems like an unnecessary call if display is powered off.
457 Case::CompositionType::setupHwcSetCallExpectations(test);
458 }
459
460 static void setupHwcCompositionCallExpectations(CompositionTest*) {}
Lloyd Pique66d68602019-02-13 14:23:31 -0800461 static void setupHwcClientCompositionCallExpectations(CompositionTest*) {}
462 static void setupHwcForcedClientCompositionCallExpectations(CompositionTest*) {}
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700463
464 static void setupRECompositionCallExpectations(CompositionTest* test) {
465 // TODO: This seems like an unnecessary call if display is powered off.
466 EXPECT_CALL(*test->mDisplaySurface, getClientTargetAcquireFence())
467 .WillRepeatedly(ReturnRef(test->mClientTargetAcquireFence));
468 }
469
470 template <typename Case>
471 static void setupRELayerCompositionCallExpectations(CompositionTest*) {}
472};
473
474/* ------------------------------------------------------------------------
475 * Variants for each layer configuration which can be tested
476 */
477
478template <typename LayerProperties>
479struct BaseLayerProperties {
480 static constexpr uint32_t WIDTH = 100;
481 static constexpr uint32_t HEIGHT = 100;
482 static constexpr PixelFormat FORMAT = PIXEL_FORMAT_RGBA_8888;
483 static constexpr uint64_t USAGE =
484 GraphicBuffer::USAGE_SW_READ_NEVER | GraphicBuffer::USAGE_SW_WRITE_NEVER;
485 static constexpr android_dataspace DATASPACE = HAL_DATASPACE_UNKNOWN;
486 static constexpr uint32_t SCALING_MODE = 0;
487 static constexpr uint32_t TRANSFORM = 0;
488 static constexpr uint32_t LAYER_FLAGS = 0;
489 static constexpr float COLOR[] = {1.f, 1.f, 1.f, 1.f};
490 static constexpr IComposerClient::BlendMode BLENDMODE =
491 IComposerClient::BlendMode::PREMULTIPLIED;
492
493 static void enqueueBuffer(CompositionTest*, sp<BufferQueueLayer> layer) {
494 auto producer = layer->getProducer();
495
496 IGraphicBufferProducer::QueueBufferOutput qbo;
497 status_t result = producer->connect(nullptr, NATIVE_WINDOW_API_EGL, false, &qbo);
498 if (result != NO_ERROR) {
499 ALOGE("Failed to connect() (%d)", result);
500 return;
501 }
502
503 int slot;
504 sp<Fence> fence;
505 result = producer->dequeueBuffer(&slot, &fence, LayerProperties::WIDTH,
506 LayerProperties::HEIGHT, LayerProperties::FORMAT,
507 LayerProperties::USAGE, nullptr, nullptr);
508 if (result != IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION) {
509 ALOGE("Failed to dequeueBuffer() (%d)", result);
510 return;
511 }
512
513 sp<GraphicBuffer> buffer;
514 result = producer->requestBuffer(slot, &buffer);
515 if (result != NO_ERROR) {
516 ALOGE("Failed to requestBuffer() (%d)", result);
517 return;
518 }
519
520 IGraphicBufferProducer::QueueBufferInput qbi(systemTime(), false /* isAutoTimestamp */,
521 LayerProperties::DATASPACE,
522 Rect(LayerProperties::WIDTH,
523 LayerProperties::HEIGHT),
524 LayerProperties::SCALING_MODE,
525 LayerProperties::TRANSFORM, Fence::NO_FENCE);
526 result = producer->queueBuffer(slot, qbi, &qbo);
527 if (result != NO_ERROR) {
528 ALOGE("Failed to queueBuffer (%d)", result);
529 return;
530 }
531 }
532
533 static void setupLatchedBuffer(CompositionTest* test, sp<BufferQueueLayer> layer) {
534 // TODO: Eliminate the complexity of actually creating a buffer
Vishnu Nair7fb9e5a2021-11-08 12:44:05 -0800535 layer->setSizeForTest(LayerProperties::WIDTH, LayerProperties::HEIGHT);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700536 status_t err =
537 layer->setDefaultBufferProperties(LayerProperties::WIDTH, LayerProperties::HEIGHT,
538 LayerProperties::FORMAT);
539 ASSERT_EQ(NO_ERROR, err);
540 Mock::VerifyAndClear(test->mRenderEngine);
541
Dominik Laskowski46f3e3b2021-08-10 11:44:24 -0700542 EXPECT_CALL(*test->mFlinger.scheduler(), scheduleFrame()).Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700543 enqueueBuffer(test, layer);
Dominik Laskowski756b7892021-08-04 12:53:59 -0700544 Mock::VerifyAndClearExpectations(test->mFlinger.scheduler());
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700545
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700546 bool ignoredRecomputeVisibleRegions;
Dominik Laskowskia8955dd2019-07-10 10:19:09 -0700547 layer->latchBuffer(ignoredRecomputeVisibleRegions, 0, 0);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700548 Mock::VerifyAndClear(test->mRenderEngine);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700549 }
550
551 static void setupLayerState(CompositionTest* test, sp<BufferQueueLayer> layer) {
552 setupLatchedBuffer(test, layer);
553 }
554
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700555 static void setupHwcSetGeometryCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800556 if (!test->mDisplayOff) {
557 // TODO: Coverage of other values
558 EXPECT_CALL(*test->mComposer,
559 setLayerBlendMode(HWC_DISPLAY, HWC_LAYER, LayerProperties::BLENDMODE))
560 .Times(1);
561 // TODO: Coverage of other values for origin
562 EXPECT_CALL(*test->mComposer,
563 setLayerDisplayFrame(HWC_DISPLAY, HWC_LAYER,
564 IComposerClient::Rect({0, 0, LayerProperties::WIDTH,
565 LayerProperties::HEIGHT})))
566 .Times(1);
567 EXPECT_CALL(*test->mComposer,
568 setLayerPlaneAlpha(HWC_DISPLAY, HWC_LAYER, LayerProperties::COLOR[3]))
569 .Times(1);
570 // TODO: Coverage of other values
571 EXPECT_CALL(*test->mComposer, setLayerZOrder(HWC_DISPLAY, HWC_LAYER, 0u)).Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700572
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800573 // These expectations retire on saturation as the code path these
574 // expectations are for appears to make an extra call to them.
575 // TODO: Investigate this extra call
576 EXPECT_CALL(*test->mComposer,
577 setLayerTransform(HWC_DISPLAY, HWC_LAYER, DEFAULT_TRANSFORM))
578 .Times(AtLeast(1))
579 .RetiresOnSaturation();
580 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700581 }
582
583 static void setupHwcSetSourceCropBufferCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800584 if (!test->mDisplayOff) {
585 EXPECT_CALL(*test->mComposer,
586 setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER,
587 IComposerClient::FRect({0.f, 0.f, LayerProperties::WIDTH,
588 LayerProperties::HEIGHT})))
589 .Times(1);
590 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700591 }
592
593 static void setupHwcSetSourceCropColorCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800594 if (!test->mDisplayOff) {
595 EXPECT_CALL(*test->mComposer,
596 setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER,
597 IComposerClient::FRect({0.f, 0.f, 0.f, 0.f})))
598 .Times(1);
599 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700600 }
601
602 static void setupHwcSetPerFrameCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800603 if (!test->mDisplayOff) {
604 EXPECT_CALL(*test->mComposer,
605 setLayerVisibleRegion(HWC_DISPLAY, HWC_LAYER,
606 std::vector<IComposerClient::Rect>(
607 {IComposerClient::Rect(
608 {0, 0, LayerProperties::WIDTH,
609 LayerProperties::HEIGHT})})))
610 .Times(1);
611 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700612 }
613
614 static void setupHwcSetPerFrameColorCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800615 if (!test->mDisplayOff) {
616 EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _))
617 .Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700618
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800619 // TODO: use COLOR
620 EXPECT_CALL(*test->mComposer,
621 setLayerColor(HWC_DISPLAY, HWC_LAYER,
622 IComposerClient::Color({0xff, 0xff, 0xff, 0xff})))
623 .Times(1);
624 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700625 }
626
627 static void setupHwcSetPerFrameBufferCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800628 if (!test->mDisplayOff) {
629 EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _))
630 .Times(1);
631 EXPECT_CALL(*test->mComposer, setLayerBuffer(HWC_DISPLAY, HWC_LAYER, _, _, _)).Times(1);
632 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700633 }
634
635 static void setupREBufferCompositionCommonCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000636 EXPECT_CALL(*test->mRenderEngine, drawLayers)
Sally Qi4cabdd02021-08-05 16:45:57 -0700637 .WillOnce([&](const renderengine::DisplaySettings& displaySettings,
Sally Qi59a9f502021-10-12 18:53:23 +0000638 const std::vector<renderengine::LayerSettings>& layerSettings,
Sally Qi4cabdd02021-08-05 16:45:57 -0700639 const std::shared_ptr<renderengine::ExternalTexture>&, const bool,
Sally Qi59a9f502021-10-12 18:53:23 +0000640 base::unique_fd&&) -> std::future<renderengine::RenderEngineResult> {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000641 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
642 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
643 displaySettings.physicalDisplay);
644 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
645 displaySettings.clip);
646 // screen capture adds an additional color layer as an alpha
647 // prefill, so gtet the back layer.
Sally Qi4cabdd02021-08-05 16:45:57 -0700648 std::future<renderengine::RenderEngineResult> resultFuture =
649 futureOf<renderengine::RenderEngineResult>(
650 {NO_ERROR, base::unique_fd()});
Lloyd Piquea2468662019-03-07 21:31:06 -0800651 if (layerSettings.empty()) {
652 ADD_FAILURE() << "layerSettings was not expected to be empty in "
653 "setupREBufferCompositionCommonCallExpectations "
654 "verification lambda";
Sally Qi4cabdd02021-08-05 16:45:57 -0700655 return resultFuture;
Lloyd Piquea2468662019-03-07 21:31:06 -0800656 }
Sally Qi59a9f502021-10-12 18:53:23 +0000657 const renderengine::LayerSettings layer = layerSettings.back();
658 EXPECT_THAT(layer.source.buffer.buffer, Not(IsNull()));
659 EXPECT_THAT(layer.source.buffer.fence, Not(IsNull()));
660 EXPECT_EQ(DEFAULT_TEXTURE_ID, layer.source.buffer.textureName);
661 EXPECT_EQ(false, layer.source.buffer.isY410BT2020);
662 EXPECT_EQ(true, layer.source.buffer.usePremultipliedAlpha);
663 EXPECT_EQ(false, layer.source.buffer.isOpaque);
664 EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius);
665 EXPECT_EQ(ui::Dataspace::UNKNOWN, layer.sourceDataspace);
666 EXPECT_EQ(LayerProperties::COLOR[3], layer.alpha);
Sally Qi4cabdd02021-08-05 16:45:57 -0700667 return resultFuture;
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000668 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700669 }
670
671 static void setupREBufferCompositionCallExpectations(CompositionTest* test) {
672 LayerProperties::setupREBufferCompositionCommonCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700673 }
674
675 static void setupInsecureREBufferCompositionCallExpectations(CompositionTest* test) {
676 setupREBufferCompositionCallExpectations(test);
677 }
678
679 static void setupREBufferScreenshotCompositionCallExpectations(CompositionTest* test) {
680 LayerProperties::setupREBufferCompositionCommonCallExpectations(test);
681 }
682
683 static void setupInsecureREBufferScreenshotCompositionCallExpectations(CompositionTest* test) {
684 LayerProperties::setupREBufferCompositionCommonCallExpectations(test);
685 }
686
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700687 static void setupREColorCompositionCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000688 EXPECT_CALL(*test->mRenderEngine, drawLayers)
Sally Qi4cabdd02021-08-05 16:45:57 -0700689 .WillOnce([&](const renderengine::DisplaySettings& displaySettings,
Sally Qi59a9f502021-10-12 18:53:23 +0000690 const std::vector<renderengine::LayerSettings>& layerSettings,
Sally Qi4cabdd02021-08-05 16:45:57 -0700691 const std::shared_ptr<renderengine::ExternalTexture>&, const bool,
Sally Qi59a9f502021-10-12 18:53:23 +0000692 base::unique_fd&&) -> std::future<renderengine::RenderEngineResult> {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000693 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
694 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
695 displaySettings.physicalDisplay);
696 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
697 displaySettings.clip);
698 // screen capture adds an additional color layer as an alpha
699 // prefill, so get the back layer.
Sally Qi4cabdd02021-08-05 16:45:57 -0700700 std::future<renderengine::RenderEngineResult> resultFuture =
701 futureOf<renderengine::RenderEngineResult>(
702 {NO_ERROR, base::unique_fd()});
Lloyd Piquea2468662019-03-07 21:31:06 -0800703 if (layerSettings.empty()) {
704 ADD_FAILURE()
705 << "layerSettings was not expected to be empty in "
706 "setupREColorCompositionCallExpectations verification lambda";
Sally Qi4cabdd02021-08-05 16:45:57 -0700707 return resultFuture;
Lloyd Piquea2468662019-03-07 21:31:06 -0800708 }
Sally Qi59a9f502021-10-12 18:53:23 +0000709 const renderengine::LayerSettings layer = layerSettings.back();
710 EXPECT_THAT(layer.source.buffer.buffer, IsNull());
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000711 EXPECT_EQ(half3(LayerProperties::COLOR[0], LayerProperties::COLOR[1],
712 LayerProperties::COLOR[2]),
Sally Qi59a9f502021-10-12 18:53:23 +0000713 layer.source.solidColor);
714 EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius);
715 EXPECT_EQ(ui::Dataspace::UNKNOWN, layer.sourceDataspace);
716 EXPECT_EQ(LayerProperties::COLOR[3], layer.alpha);
Sally Qi4cabdd02021-08-05 16:45:57 -0700717 return resultFuture;
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000718 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700719 }
720
721 static void setupREColorScreenshotCompositionCallExpectations(CompositionTest* test) {
722 setupREColorCompositionCallExpectations(test);
723 }
724};
725
726struct DefaultLayerProperties : public BaseLayerProperties<DefaultLayerProperties> {};
727
Vishnu Nairfa247b12020-02-11 08:58:26 -0800728struct EffectLayerProperties : public BaseLayerProperties<EffectLayerProperties> {
Alec Mourida8a9d12020-01-30 20:00:31 -0800729 static constexpr IComposerClient::BlendMode BLENDMODE = IComposerClient::BlendMode::NONE;
730};
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700731
732struct SidebandLayerProperties : public BaseLayerProperties<SidebandLayerProperties> {
733 using Base = BaseLayerProperties<SidebandLayerProperties>;
734 static constexpr IComposerClient::BlendMode BLENDMODE = IComposerClient::BlendMode::NONE;
735
736 static void setupLayerState(CompositionTest* test, sp<BufferQueueLayer> layer) {
737 sp<NativeHandle> stream =
738 NativeHandle::create(reinterpret_cast<native_handle_t*>(DEFAULT_SIDEBAND_STREAM),
739 false);
740 test->mFlinger.setLayerSidebandStream(layer, stream);
741 }
742
743 static void setupHwcSetSourceCropBufferCallExpectations(CompositionTest* test) {
744 EXPECT_CALL(*test->mComposer,
745 setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER,
746 IComposerClient::FRect({0.f, 0.f, -1.f, -1.f})))
747 .Times(1);
748 }
749
750 static void setupHwcSetPerFrameBufferCallExpectations(CompositionTest* test) {
751 EXPECT_CALL(*test->mComposer,
752 setLayerSidebandStream(HWC_DISPLAY, HWC_LAYER,
753 reinterpret_cast<native_handle_t*>(
754 DEFAULT_SIDEBAND_STREAM)))
755 .WillOnce(Return(Error::NONE));
756
757 EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _)).Times(1);
758 }
759
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000760 static void setupREBufferCompositionCommonCallExpectations(CompositionTest* /*test*/) {}
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700761};
762
Garfield Tande619fa2020-10-02 17:13:53 -0700763template <typename LayerProperties>
764struct CommonSecureLayerProperties : public BaseLayerProperties<LayerProperties> {
765 using Base = BaseLayerProperties<LayerProperties>;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700766
767 static void setupInsecureREBufferCompositionCommonCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000768 EXPECT_CALL(*test->mRenderEngine, drawLayers)
Sally Qi4cabdd02021-08-05 16:45:57 -0700769 .WillOnce([&](const renderengine::DisplaySettings& displaySettings,
Sally Qi59a9f502021-10-12 18:53:23 +0000770 const std::vector<renderengine::LayerSettings>& layerSettings,
Sally Qi4cabdd02021-08-05 16:45:57 -0700771 const std::shared_ptr<renderengine::ExternalTexture>&, const bool,
Sally Qi59a9f502021-10-12 18:53:23 +0000772 base::unique_fd&&) -> std::future<renderengine::RenderEngineResult> {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000773 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
774 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
775 displaySettings.physicalDisplay);
776 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
777 displaySettings.clip);
778 // screen capture adds an additional color layer as an alpha
779 // prefill, so get the back layer.
Sally Qi4cabdd02021-08-05 16:45:57 -0700780 std::future<renderengine::RenderEngineResult> resultFuture =
781 futureOf<renderengine::RenderEngineResult>(
782 {NO_ERROR, base::unique_fd()});
Lloyd Piquea2468662019-03-07 21:31:06 -0800783 if (layerSettings.empty()) {
784 ADD_FAILURE() << "layerSettings was not expected to be empty in "
785 "setupInsecureREBufferCompositionCommonCallExpectations "
786 "verification lambda";
Sally Qi4cabdd02021-08-05 16:45:57 -0700787 return resultFuture;
Lloyd Piquea2468662019-03-07 21:31:06 -0800788 }
Sally Qi59a9f502021-10-12 18:53:23 +0000789 const renderengine::LayerSettings layer = layerSettings.back();
790 EXPECT_THAT(layer.source.buffer.buffer, IsNull());
791 EXPECT_EQ(half3(0.0f, 0.0f, 0.0f), layer.source.solidColor);
792 EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius);
793 EXPECT_EQ(ui::Dataspace::UNKNOWN, layer.sourceDataspace);
794 EXPECT_EQ(1.0f, layer.alpha);
Sally Qi4cabdd02021-08-05 16:45:57 -0700795 return resultFuture;
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000796 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700797 }
798
799 static void setupInsecureREBufferCompositionCallExpectations(CompositionTest* test) {
800 setupInsecureREBufferCompositionCommonCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700801 }
802
803 static void setupInsecureREBufferScreenshotCompositionCallExpectations(CompositionTest* test) {
804 setupInsecureREBufferCompositionCommonCallExpectations(test);
805 }
806};
807
Garfield Tande619fa2020-10-02 17:13:53 -0700808struct ParentSecureLayerProperties
809 : public CommonSecureLayerProperties<ParentSecureLayerProperties> {};
810
811struct SecureLayerProperties : public CommonSecureLayerProperties<SecureLayerProperties> {
812 static constexpr uint32_t LAYER_FLAGS = ISurfaceComposerClient::eSecure;
813};
814
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700815struct CursorLayerProperties : public BaseLayerProperties<CursorLayerProperties> {
816 using Base = BaseLayerProperties<CursorLayerProperties>;
817
818 static void setupLayerState(CompositionTest* test, sp<BufferQueueLayer> layer) {
819 Base::setupLayerState(test, layer);
820 test->mFlinger.setLayerPotentialCursor(layer, true);
821 }
822};
823
824struct NoLayerVariant {
825 using FlingerLayerType = sp<BufferQueueLayer>;
826
827 static FlingerLayerType createLayer(CompositionTest*) { return FlingerLayerType(); }
828 static void injectLayer(CompositionTest*, FlingerLayerType) {}
829 static void cleanupInjectedLayers(CompositionTest*) {}
830
831 static void setupCallExpectationsForDirtyGeometry(CompositionTest*) {}
832 static void setupCallExpectationsForDirtyFrame(CompositionTest*) {}
833};
834
835template <typename LayerProperties>
836struct BaseLayerVariant {
837 template <typename L, typename F>
838 static sp<L> createLayerWithFactory(CompositionTest* test, F factory) {
Dominik Laskowski756b7892021-08-04 12:53:59 -0700839 EXPECT_CALL(*test->mFlinger.scheduler(), postMessage(_)).Times(0);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700840
841 sp<L> layer = factory();
842
Dominik Laskowski49cea512019-11-12 14:13:23 -0800843 // Layer should be registered with scheduler.
Dominik Laskowski9c93d602021-10-07 19:38:26 -0700844 EXPECT_EQ(1u, test->mFlinger.scheduler()->layerHistorySize());
Dominik Laskowski49cea512019-11-12 14:13:23 -0800845
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700846 Mock::VerifyAndClear(test->mComposer);
847 Mock::VerifyAndClear(test->mRenderEngine);
Dominik Laskowski756b7892021-08-04 12:53:59 -0700848 Mock::VerifyAndClearExpectations(test->mFlinger.scheduler());
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700849
Garfield Tande619fa2020-10-02 17:13:53 -0700850 initLayerDrawingStateAndComputeBounds(test, layer);
851
852 return layer;
853 }
854
855 template <typename L>
856 static void initLayerDrawingStateAndComputeBounds(CompositionTest* test, sp<L> layer) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700857 auto& layerDrawingState = test->mFlinger.mutableLayerDrawingState(layer);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700858 layerDrawingState.layerStack = LAYER_STACK;
chaviw766c9c52021-02-10 17:36:47 -0800859 layerDrawingState.width = 100;
860 layerDrawingState.height = 100;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700861 layerDrawingState.color = half4(LayerProperties::COLOR[0], LayerProperties::COLOR[1],
862 LayerProperties::COLOR[2], LayerProperties::COLOR[3]);
Vishnu Nairc97b8db2019-10-29 18:19:35 -0700863 layer->computeBounds(FloatRect(0, 0, 100, 100), ui::Transform(), 0.f /* shadowRadius */);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700864 }
865
866 static void injectLayer(CompositionTest* test, sp<Layer> layer) {
867 EXPECT_CALL(*test->mComposer, createLayer(HWC_DISPLAY, _))
868 .WillOnce(DoAll(SetArgPointee<1>(HWC_LAYER), Return(Error::NONE)));
869
Lloyd Piquede196652020-01-22 17:29:58 -0800870 auto outputLayer = test->mDisplay->getCompositionDisplay()->injectOutputLayerForTest(
871 layer->getCompositionEngineLayerFE());
Lloyd Pique01c77c12019-04-17 12:48:32 -0700872 outputLayer->editState().visibleRegion = Region(Rect(0, 0, 100, 100));
873 outputLayer->editState().outputSpaceVisibleRegion = Region(Rect(0, 0, 100, 100));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700874
875 Mock::VerifyAndClear(test->mComposer);
876
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700877 test->mFlinger.mutableDrawingState().layersSortedByZ.add(layer);
878 }
879
880 static void cleanupInjectedLayers(CompositionTest* test) {
881 EXPECT_CALL(*test->mComposer, destroyLayer(HWC_DISPLAY, HWC_LAYER))
882 .WillOnce(Return(Error::NONE));
Lloyd Pique37c2c9b2018-12-04 17:25:10 -0800883
Lloyd Pique01c77c12019-04-17 12:48:32 -0700884 test->mDisplay->getCompositionDisplay()->clearOutputLayers();
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700885 test->mFlinger.mutableDrawingState().layersSortedByZ.clear();
Dominik Laskowski49cea512019-11-12 14:13:23 -0800886
887 // Layer should be unregistered with scheduler.
Dominik Laskowskie0e0cde2021-07-30 10:42:05 -0700888 test->mFlinger.commit();
Dominik Laskowski9c93d602021-10-07 19:38:26 -0700889 EXPECT_EQ(0u, test->mFlinger.scheduler()->layerHistorySize());
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700890 }
891};
892
893template <typename LayerProperties>
Vishnu Nairfa247b12020-02-11 08:58:26 -0800894struct EffectLayerVariant : public BaseLayerVariant<LayerProperties> {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700895 using Base = BaseLayerVariant<LayerProperties>;
Vishnu Nairfa247b12020-02-11 08:58:26 -0800896 using FlingerLayerType = sp<EffectLayer>;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700897
898 static FlingerLayerType createLayer(CompositionTest* test) {
Vishnu Nairfa247b12020-02-11 08:58:26 -0800899 FlingerLayerType layer = Base::template createLayerWithFactory<EffectLayer>(test, [test]() {
900 return new EffectLayer(
Dominik Laskowski8b01cc02020-07-14 19:02:41 -0700901 LayerCreationArgs(test->mFlinger.flinger(), sp<Client>(), "test-layer",
Vishnu Nairfa247b12020-02-11 08:58:26 -0800902 LayerProperties::LAYER_FLAGS, LayerMetadata()));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700903 });
Vishnu Nair60356342018-11-13 13:00:45 -0800904
905 auto& layerDrawingState = test->mFlinger.mutableLayerDrawingState(layer);
chaviw25714502021-02-11 10:01:08 -0800906 layerDrawingState.crop = Rect(0, 0, LayerProperties::HEIGHT, LayerProperties::WIDTH);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700907 return layer;
908 }
909
910 static void setupRECompositionCallExpectations(CompositionTest* test) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700911 LayerProperties::setupREColorCompositionCallExpectations(test);
912 }
913
914 static void setupREScreenshotCompositionCallExpectations(CompositionTest* test) {
915 LayerProperties::setupREColorScreenshotCompositionCallExpectations(test);
916 }
917
918 static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) {
919 LayerProperties::setupHwcSetGeometryCallExpectations(test);
920 LayerProperties::setupHwcSetSourceCropColorCallExpectations(test);
921 }
922
923 static void setupCallExpectationsForDirtyFrame(CompositionTest* test) {
924 LayerProperties::setupHwcSetPerFrameCallExpectations(test);
925 LayerProperties::setupHwcSetPerFrameColorCallExpectations(test);
926 }
927};
928
929template <typename LayerProperties>
930struct BufferLayerVariant : public BaseLayerVariant<LayerProperties> {
931 using Base = BaseLayerVariant<LayerProperties>;
932 using FlingerLayerType = sp<BufferQueueLayer>;
933
934 static FlingerLayerType createLayer(CompositionTest* test) {
935 test->mFlinger.mutableTexturePool().push_back(DEFAULT_TEXTURE_ID);
936
937 FlingerLayerType layer =
938 Base::template createLayerWithFactory<BufferQueueLayer>(test, [test]() {
Dominik Laskowski8b01cc02020-07-14 19:02:41 -0700939 LayerCreationArgs args(test->mFlinger.flinger(), sp<Client>(), "test-layer",
Dominik Laskowski87a07e42019-10-10 20:38:02 -0700940 LayerProperties::LAYER_FLAGS, LayerMetadata());
chaviwb4c6e582019-08-16 14:35:07 -0700941 args.textureName = test->mFlinger.mutableTexturePool().back();
942 return new BufferQueueLayer(args);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700943 });
944
945 LayerProperties::setupLayerState(test, layer);
946
947 return layer;
948 }
949
950 static void cleanupInjectedLayers(CompositionTest* test) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700951 Base::cleanupInjectedLayers(test);
952 }
953
954 static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) {
955 LayerProperties::setupHwcSetGeometryCallExpectations(test);
956 LayerProperties::setupHwcSetSourceCropBufferCallExpectations(test);
957 }
958
959 static void setupCallExpectationsForDirtyFrame(CompositionTest* test) {
960 LayerProperties::setupHwcSetPerFrameCallExpectations(test);
961 LayerProperties::setupHwcSetPerFrameBufferCallExpectations(test);
962 }
963
964 static void setupRECompositionCallExpectations(CompositionTest* test) {
965 LayerProperties::setupREBufferCompositionCallExpectations(test);
966 }
967
968 static void setupInsecureRECompositionCallExpectations(CompositionTest* test) {
969 LayerProperties::setupInsecureREBufferCompositionCallExpectations(test);
970 }
971
972 static void setupREScreenshotCompositionCallExpectations(CompositionTest* test) {
973 LayerProperties::setupREBufferScreenshotCompositionCallExpectations(test);
974 }
975
976 static void setupInsecureREScreenshotCompositionCallExpectations(CompositionTest* test) {
977 LayerProperties::setupInsecureREBufferScreenshotCompositionCallExpectations(test);
978 }
979};
980
Garfield Tande619fa2020-10-02 17:13:53 -0700981template <typename LayerProperties>
982struct ContainerLayerVariant : public BaseLayerVariant<LayerProperties> {
983 using Base = BaseLayerVariant<LayerProperties>;
984 using FlingerLayerType = sp<ContainerLayer>;
985
986 static FlingerLayerType createLayer(CompositionTest* test) {
987 LayerCreationArgs args(test->mFlinger.flinger(), sp<Client>(), "test-container-layer",
Garfield Tande619fa2020-10-02 17:13:53 -0700988 LayerProperties::LAYER_FLAGS, LayerMetadata());
989 FlingerLayerType layer = new ContainerLayer(args);
990 Base::template initLayerDrawingStateAndComputeBounds(test, layer);
991 return layer;
992 }
993};
994
995template <typename LayerVariant, typename ParentLayerVariant>
996struct ChildLayerVariant : public LayerVariant {
997 using Base = LayerVariant;
998 using FlingerLayerType = typename LayerVariant::FlingerLayerType;
999 using ParentBase = ParentLayerVariant;
1000
1001 static FlingerLayerType createLayer(CompositionTest* test) {
1002 // Need to create child layer first. Otherwise layer history size will be 2.
1003 FlingerLayerType layer = Base::createLayer(test);
1004
1005 typename ParentBase::FlingerLayerType parentLayer = ParentBase::createLayer(test);
1006 parentLayer->addChild(layer);
1007 test->mFlinger.setLayerDrawingParent(layer, parentLayer);
1008
1009 test->mAuxiliaryLayers.push_back(parentLayer);
1010
1011 return layer;
1012 }
1013
1014 static void cleanupInjectedLayers(CompositionTest* test) {
1015 // Clear auxiliary layers first so that child layer can be successfully destroyed in the
1016 // following call.
1017 test->mAuxiliaryLayers.clear();
1018
1019 Base::cleanupInjectedLayers(test);
1020 }
1021};
1022
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001023/* ------------------------------------------------------------------------
1024 * Variants to control how the composition type is changed
1025 */
1026
1027struct NoCompositionTypeVariant {
1028 static void setupHwcSetCallExpectations(CompositionTest*) {}
1029
1030 static void setupHwcGetCallExpectations(CompositionTest* test) {
1031 EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _)).Times(1);
1032 }
1033};
1034
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001035template <aidl::android::hardware::graphics::composer3::Composition CompositionType>
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001036struct KeepCompositionTypeVariant {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001037 static constexpr aidl::android::hardware::graphics::composer3::Composition TYPE =
1038 CompositionType;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001039
1040 static void setupHwcSetCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001041 if (!test->mDisplayOff) {
1042 EXPECT_CALL(*test->mComposer,
1043 setLayerCompositionType(HWC_DISPLAY, HWC_LAYER, CompositionType))
1044 .Times(1);
1045 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001046 }
1047
1048 static void setupHwcGetCallExpectations(CompositionTest* test) {
1049 EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _)).Times(1);
1050 }
1051};
1052
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001053template <aidl::android::hardware::graphics::composer3::Composition InitialCompositionType,
1054 aidl::android::hardware::graphics::composer3::Composition FinalCompositionType>
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001055struct ChangeCompositionTypeVariant {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001056 static constexpr aidl::android::hardware::graphics::composer3::Composition TYPE =
1057 FinalCompositionType;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001058
1059 static void setupHwcSetCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001060 if (!test->mDisplayOff) {
1061 EXPECT_CALL(*test->mComposer,
1062 setLayerCompositionType(HWC_DISPLAY, HWC_LAYER, InitialCompositionType))
1063 .Times(1);
1064 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001065 }
1066
1067 static void setupHwcGetCallExpectations(CompositionTest* test) {
1068 EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _))
1069 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::Layer>{
1070 static_cast<Hwc2::Layer>(HWC_LAYER)}),
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001071 SetArgPointee<2>(
1072 std::vector<aidl::android::hardware::graphics::composer3::
1073 Composition>{FinalCompositionType}),
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001074 Return(Error::NONE)));
1075 }
1076};
1077
1078/* ------------------------------------------------------------------------
1079 * Variants to select how the composition is expected to be handled
1080 */
1081
1082struct CompositionResultBaseVariant {
1083 static void setupLayerState(CompositionTest*, sp<Layer>) {}
1084
1085 template <typename Case>
1086 static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) {
1087 Case::Layer::setupCallExpectationsForDirtyGeometry(test);
1088 }
1089
1090 template <typename Case>
1091 static void setupCallExpectationsForDirtyFrame(CompositionTest* test) {
1092 Case::Layer::setupCallExpectationsForDirtyFrame(test);
1093 }
1094};
1095
1096struct NoCompositionResultVariant : public CompositionResultBaseVariant {
1097 template <typename Case>
1098 static void setupCallExpectations(CompositionTest* test) {
1099 Case::Display::setupEmptyFrameCompositionCallExpectations(test);
1100 Case::Display::setupHwcCompositionCallExpectations(test);
1101 }
1102};
1103
1104struct HwcCompositionResultVariant : public CompositionResultBaseVariant {
1105 template <typename Case>
1106 static void setupCallExpectations(CompositionTest* test) {
1107 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
1108 Case::Display::setupHwcCompositionCallExpectations(test);
1109 }
1110};
1111
1112struct RECompositionResultVariant : public CompositionResultBaseVariant {
1113 template <typename Case>
1114 static void setupCallExpectations(CompositionTest* test) {
1115 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
Lloyd Pique66d68602019-02-13 14:23:31 -08001116 Case::Display::setupHwcClientCompositionCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001117 Case::Display::setupRECompositionCallExpectations(test);
1118 Case::Display::template setupRELayerCompositionCallExpectations<Case>(test);
1119 }
1120};
1121
Lloyd Pique66d68602019-02-13 14:23:31 -08001122struct ForcedClientCompositionResultVariant : public CompositionResultBaseVariant {
Lloyd Pique37c2c9b2018-12-04 17:25:10 -08001123 static void setupLayerState(CompositionTest* test, sp<Layer> layer) {
Dominik Laskowskib7251f42020-04-20 17:42:59 -07001124 const auto outputLayer =
1125 TestableSurfaceFlinger::findOutputLayerForDisplay(layer, test->mDisplay);
Lloyd Piquef5275482019-01-29 18:42:42 -08001126 LOG_FATAL_IF(!outputLayer);
1127 outputLayer->editState().forceClientComposition = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001128 }
1129
1130 template <typename Case>
Lloyd Pique66d68602019-02-13 14:23:31 -08001131 static void setupCallExpectations(CompositionTest* test) {
1132 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
1133 Case::Display::setupHwcForcedClientCompositionCallExpectations(test);
1134 Case::Display::setupRECompositionCallExpectations(test);
1135 Case::Display::template setupRELayerCompositionCallExpectations<Case>(test);
1136 }
1137
1138 template <typename Case>
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001139 static void setupCallExpectationsForDirtyGeometry(CompositionTest*) {}
1140
1141 template <typename Case>
1142 static void setupCallExpectationsForDirtyFrame(CompositionTest*) {}
1143};
1144
Lloyd Pique4fe29402019-08-12 16:51:24 -07001145struct ForcedClientCompositionViaDebugOptionResultVariant : public CompositionResultBaseVariant {
1146 static void setupLayerState(CompositionTest* test, sp<Layer>) {
1147 test->mFlinger.mutableDebugDisableHWC() = true;
1148 }
1149
1150 template <typename Case>
1151 static void setupCallExpectations(CompositionTest* test) {
1152 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
1153 Case::Display::setupHwcForcedClientCompositionCallExpectations(test);
1154 Case::Display::setupRECompositionCallExpectations(test);
1155 Case::Display::template setupRELayerCompositionCallExpectations<Case>(test);
1156 }
1157
1158 template <typename Case>
1159 static void setupCallExpectationsForDirtyGeometry(CompositionTest*) {}
1160
1161 template <typename Case>
1162 static void setupCallExpectationsForDirtyFrame(CompositionTest*) {}
1163};
1164
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001165struct EmptyScreenshotResultVariant {
1166 static void setupLayerState(CompositionTest*, sp<Layer>) {}
1167
1168 template <typename Case>
1169 static void setupCallExpectations(CompositionTest*) {}
1170};
1171
1172struct REScreenshotResultVariant : public EmptyScreenshotResultVariant {
1173 using Base = EmptyScreenshotResultVariant;
1174
1175 template <typename Case>
1176 static void setupCallExpectations(CompositionTest* test) {
1177 Base::template setupCallExpectations<Case>(test);
1178 Case::Display::template setupRELayerScreenshotCompositionCallExpectations<Case>(test);
1179 }
1180};
1181
1182/* ------------------------------------------------------------------------
1183 * Composition test case, containing all the variants being tested
1184 */
1185
1186template <typename DisplayCase, typename LayerCase, typename CompositionTypeCase,
1187 typename CompositionResultCase>
1188struct CompositionCase {
1189 using ThisCase =
1190 CompositionCase<DisplayCase, LayerCase, CompositionTypeCase, CompositionResultCase>;
1191 using Display = DisplayCase;
1192 using Layer = LayerCase;
1193 using CompositionType = CompositionTypeCase;
1194 using CompositionResult = CompositionResultCase;
1195
1196 static void setupCommon(CompositionTest* test) {
Peiyong Lin1336e6e2019-05-28 09:23:50 -07001197 Display::template setupPreconditionCallExpectations<ThisCase>(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001198 Display::setupPreconditions(test);
1199
1200 auto layer = Layer::createLayer(test);
1201 Layer::injectLayer(test, layer);
1202 CompositionResult::setupLayerState(test, layer);
1203 }
1204
1205 static void setupForDirtyGeometry(CompositionTest* test) {
1206 setupCommon(test);
1207
1208 Display::template setupCommonCompositionCallExpectations<ThisCase>(test);
1209 CompositionResult::template setupCallExpectationsForDirtyGeometry<ThisCase>(test);
1210 CompositionResult::template setupCallExpectationsForDirtyFrame<ThisCase>(test);
1211 CompositionResult::template setupCallExpectations<ThisCase>(test);
1212 }
1213
1214 static void setupForDirtyFrame(CompositionTest* test) {
1215 setupCommon(test);
1216
1217 Display::template setupCommonCompositionCallExpectations<ThisCase>(test);
1218 CompositionResult::template setupCallExpectationsForDirtyFrame<ThisCase>(test);
1219 CompositionResult::template setupCallExpectations<ThisCase>(test);
1220 }
1221
1222 static void setupForScreenCapture(CompositionTest* test) {
1223 setupCommon(test);
1224
1225 Display::template setupCommonScreensCaptureCallExpectations<ThisCase>(test);
1226 CompositionResult::template setupCallExpectations<ThisCase>(test);
1227 }
1228
1229 static void cleanup(CompositionTest* test) {
1230 Layer::cleanupInjectedLayers(test);
1231
Peiyong Linbdd08cc2019-12-17 21:35:14 -08001232 for (auto& displayData : test->mFlinger.mutableHwcDisplayData()) {
1233 static_cast<TestableSurfaceFlinger::HWC2Display*>(displayData.second.hwcDisplay.get())
1234 ->mutableLayers()
1235 .clear();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001236 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001237 }
1238};
1239
1240/* ------------------------------------------------------------------------
1241 * Composition cases to test
1242 */
1243
1244TEST_F(CompositionTest, noLayersDoesMinimalWorkWithDirtyGeometry) {
1245 displayRefreshCompositionDirtyGeometry<
1246 CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant,
1247 NoCompositionResultVariant>>();
1248}
1249
1250TEST_F(CompositionTest, noLayersDoesMinimalWorkWithDirtyFrame) {
1251 displayRefreshCompositionDirtyFrame<
1252 CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant,
1253 NoCompositionResultVariant>>();
1254}
1255
1256TEST_F(CompositionTest, noLayersDoesMinimalWorkToCaptureScreen) {
1257 captureScreenComposition<
1258 CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant,
1259 EmptyScreenshotResultVariant>>();
1260}
1261
1262/* ------------------------------------------------------------------------
1263 * Simple buffer layers
1264 */
1265
1266TEST_F(CompositionTest, HWCComposedNormalBufferLayerWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001267 displayRefreshCompositionDirtyGeometry<CompositionCase<
1268 DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1269 KeepCompositionTypeVariant<
1270 aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
1271 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001272}
1273
1274TEST_F(CompositionTest, HWCComposedNormalBufferLayerWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001275 displayRefreshCompositionDirtyFrame<CompositionCase<
1276 DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1277 KeepCompositionTypeVariant<
1278 aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
1279 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001280}
1281
1282TEST_F(CompositionTest, REComposedNormalBufferLayer) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001283 displayRefreshCompositionDirtyFrame<CompositionCase<
1284 DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1285 ChangeCompositionTypeVariant<
1286 aidl::android::hardware::graphics::composer3::Composition::DEVICE,
1287 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1288 RECompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001289}
1290
1291TEST_F(CompositionTest, captureScreenNormalBufferLayer) {
1292 captureScreenComposition<
1293 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1294 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1295}
1296
1297/* ------------------------------------------------------------------------
1298 * Single-color layers
1299 */
1300
Vishnu Nairfa247b12020-02-11 08:58:26 -08001301TEST_F(CompositionTest, HWCComposedEffectLayerWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001302 displayRefreshCompositionDirtyGeometry<CompositionCase<
1303 DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
1304 KeepCompositionTypeVariant<
1305 aidl::android::hardware::graphics::composer3::Composition::SOLID_COLOR>,
1306 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001307}
1308
Vishnu Nairfa247b12020-02-11 08:58:26 -08001309TEST_F(CompositionTest, HWCComposedEffectLayerWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001310 displayRefreshCompositionDirtyFrame<CompositionCase<
1311 DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
1312 KeepCompositionTypeVariant<
1313 aidl::android::hardware::graphics::composer3::Composition::SOLID_COLOR>,
1314 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001315}
1316
Vishnu Nairfa247b12020-02-11 08:58:26 -08001317TEST_F(CompositionTest, REComposedEffectLayer) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001318 displayRefreshCompositionDirtyFrame<CompositionCase<
1319 DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
1320 ChangeCompositionTypeVariant<
1321 aidl::android::hardware::graphics::composer3::Composition::SOLID_COLOR,
1322 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1323 RECompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001324}
1325
Vishnu Nairfa247b12020-02-11 08:58:26 -08001326TEST_F(CompositionTest, captureScreenEffectLayer) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001327 captureScreenComposition<
Vishnu Nairfa247b12020-02-11 08:58:26 -08001328 CompositionCase<DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001329 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1330}
1331
1332/* ------------------------------------------------------------------------
1333 * Layers with sideband buffers
1334 */
1335
1336TEST_F(CompositionTest, HWCComposedSidebandBufferLayerWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001337 displayRefreshCompositionDirtyGeometry<CompositionCase<
1338 DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1339 KeepCompositionTypeVariant<
1340 aidl::android::hardware::graphics::composer3::Composition::SIDEBAND>,
1341 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001342}
1343
1344TEST_F(CompositionTest, HWCComposedSidebandBufferLayerWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001345 displayRefreshCompositionDirtyFrame<CompositionCase<
1346 DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1347 KeepCompositionTypeVariant<
1348 aidl::android::hardware::graphics::composer3::Composition::SIDEBAND>,
1349 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001350}
1351
1352TEST_F(CompositionTest, REComposedSidebandBufferLayer) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001353 displayRefreshCompositionDirtyFrame<CompositionCase<
1354 DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1355 ChangeCompositionTypeVariant<
1356 aidl::android::hardware::graphics::composer3::Composition::SIDEBAND,
1357 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1358 RECompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001359}
1360
1361TEST_F(CompositionTest, captureScreenSidebandBufferLayer) {
1362 captureScreenComposition<
1363 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1364 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1365}
1366
1367/* ------------------------------------------------------------------------
1368 * Layers with ISurfaceComposerClient::eSecure, on a secure display
1369 */
1370
1371TEST_F(CompositionTest, HWCComposedSecureBufferLayerWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001372 displayRefreshCompositionDirtyGeometry<CompositionCase<
1373 DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1374 KeepCompositionTypeVariant<
1375 aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
1376 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001377}
1378
1379TEST_F(CompositionTest, HWCComposedSecureBufferLayerWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001380 displayRefreshCompositionDirtyFrame<CompositionCase<
1381 DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1382 KeepCompositionTypeVariant<
1383 aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
1384 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001385}
1386
1387TEST_F(CompositionTest, REComposedSecureBufferLayer) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001388 displayRefreshCompositionDirtyFrame<CompositionCase<
1389 DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1390 ChangeCompositionTypeVariant<
1391 aidl::android::hardware::graphics::composer3::Composition::DEVICE,
1392 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1393 RECompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001394}
1395
1396TEST_F(CompositionTest, captureScreenSecureBufferLayerOnSecureDisplay) {
1397 captureScreenComposition<
1398 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1399 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1400}
1401
1402/* ------------------------------------------------------------------------
1403 * Layers with ISurfaceComposerClient::eSecure, on a non-secure display
1404 */
1405
1406TEST_F(CompositionTest, HWCComposedSecureBufferLayerOnInsecureDisplayWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001407 displayRefreshCompositionDirtyGeometry<CompositionCase<
1408 InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1409 KeepCompositionTypeVariant<
1410 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1411 ForcedClientCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001412}
1413
1414TEST_F(CompositionTest, HWCComposedSecureBufferLayerOnInsecureDisplayWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001415 displayRefreshCompositionDirtyFrame<CompositionCase<
1416 InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1417 KeepCompositionTypeVariant<
1418 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1419 ForcedClientCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001420}
1421
1422TEST_F(CompositionTest, captureScreenSecureBufferLayerOnInsecureDisplay) {
1423 captureScreenComposition<
1424 CompositionCase<InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1425 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1426}
1427
1428/* ------------------------------------------------------------------------
Garfield Tande619fa2020-10-02 17:13:53 -07001429 * Layers with a parent layer with ISurfaceComposerClient::eSecure, on a non-secure display
1430 */
1431
1432TEST_F(CompositionTest,
1433 HWCComposedBufferLayerWithSecureParentLayerOnInsecureDisplayWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001434 displayRefreshCompositionDirtyGeometry<CompositionCase<
1435 InsecureDisplaySetupVariant,
1436 ChildLayerVariant<BufferLayerVariant<ParentSecureLayerProperties>,
1437 ContainerLayerVariant<SecureLayerProperties>>,
1438 KeepCompositionTypeVariant<
1439 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1440 ForcedClientCompositionResultVariant>>();
Garfield Tande619fa2020-10-02 17:13:53 -07001441}
1442
1443TEST_F(CompositionTest,
1444 HWCComposedBufferLayerWithSecureParentLayerOnInsecureDisplayWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001445 displayRefreshCompositionDirtyFrame<CompositionCase<
1446 InsecureDisplaySetupVariant,
1447 ChildLayerVariant<BufferLayerVariant<ParentSecureLayerProperties>,
1448 ContainerLayerVariant<SecureLayerProperties>>,
1449 KeepCompositionTypeVariant<
1450 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1451 ForcedClientCompositionResultVariant>>();
Garfield Tande619fa2020-10-02 17:13:53 -07001452}
1453
1454TEST_F(CompositionTest, captureScreenBufferLayerWithSecureParentLayerOnInsecureDisplay) {
1455 captureScreenComposition<
1456 CompositionCase<InsecureDisplaySetupVariant,
1457 ChildLayerVariant<BufferLayerVariant<ParentSecureLayerProperties>,
1458 ContainerLayerVariant<SecureLayerProperties>>,
1459 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1460}
1461
1462/* ------------------------------------------------------------------------
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001463 * Cursor layers
1464 */
1465
1466TEST_F(CompositionTest, HWCComposedCursorLayerWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001467 displayRefreshCompositionDirtyGeometry<CompositionCase<
1468 DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1469 KeepCompositionTypeVariant<
1470 aidl::android::hardware::graphics::composer3::Composition::CURSOR>,
1471 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001472}
1473
1474TEST_F(CompositionTest, HWCComposedCursorLayerWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001475 displayRefreshCompositionDirtyFrame<CompositionCase<
1476 DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1477 KeepCompositionTypeVariant<
1478 aidl::android::hardware::graphics::composer3::Composition::CURSOR>,
1479 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001480}
1481
1482TEST_F(CompositionTest, REComposedCursorLayer) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001483 displayRefreshCompositionDirtyFrame<CompositionCase<
1484 DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1485 ChangeCompositionTypeVariant<
1486 aidl::android::hardware::graphics::composer3::Composition::CURSOR,
1487 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1488 RECompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001489}
1490
1491TEST_F(CompositionTest, captureScreenCursorLayer) {
1492 captureScreenComposition<
1493 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1494 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1495}
1496
1497/* ------------------------------------------------------------------------
1498 * Simple buffer layer on a display which is powered off.
1499 */
1500
1501TEST_F(CompositionTest, displayOffHWCComposedNormalBufferLayerWithDirtyGeometry) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001502 mDisplayOff = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001503 displayRefreshCompositionDirtyGeometry<CompositionCase<
1504 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001505 KeepCompositionTypeVariant<
1506 aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001507 HwcCompositionResultVariant>>();
1508}
1509
1510TEST_F(CompositionTest, displayOffHWCComposedNormalBufferLayerWithDirtyFrame) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001511 mDisplayOff = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001512 displayRefreshCompositionDirtyFrame<CompositionCase<
1513 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001514 KeepCompositionTypeVariant<
1515 aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001516 HwcCompositionResultVariant>>();
1517}
1518
1519TEST_F(CompositionTest, displayOffREComposedNormalBufferLayer) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001520 mDisplayOff = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001521 displayRefreshCompositionDirtyFrame<CompositionCase<
1522 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001523 ChangeCompositionTypeVariant<
1524 aidl::android::hardware::graphics::composer3::Composition::DEVICE,
1525 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001526 RECompositionResultVariant>>();
1527}
1528
1529TEST_F(CompositionTest, captureScreenNormalBufferLayerOnPoweredOffDisplay) {
1530 captureScreenComposition<CompositionCase<
1531 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1532 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1533}
1534
Lloyd Pique4fe29402019-08-12 16:51:24 -07001535/* ------------------------------------------------------------------------
1536 * Client composition forced through debug/developer settings
1537 */
1538
1539TEST_F(CompositionTest, DebugOptionForcingClientCompositionOfBufferLayerWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001540 displayRefreshCompositionDirtyGeometry<CompositionCase<
1541 DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1542 KeepCompositionTypeVariant<
1543 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1544 ForcedClientCompositionViaDebugOptionResultVariant>>();
Lloyd Pique4fe29402019-08-12 16:51:24 -07001545}
1546
1547TEST_F(CompositionTest, DebugOptionForcingClientCompositionOfBufferLayerWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001548 displayRefreshCompositionDirtyFrame<CompositionCase<
1549 DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1550 KeepCompositionTypeVariant<
1551 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1552 ForcedClientCompositionViaDebugOptionResultVariant>>();
Lloyd Pique4fe29402019-08-12 16:51:24 -07001553}
1554
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001555} // namespace
1556} // namespace android
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -08001557
1558// TODO(b/129481165): remove the #pragma below and fix conversion issues
Marin Shalamanovbed7fd32020-12-21 20:02:20 +01001559#pragma clang diagnostic pop // ignored "-Wconversion -Wextra"