blob: f1e9b314d8999821c6f6dab5e6b80e76d79ac2cb [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, _))
Leon Scroggins III5967aec2021-12-29 11:14:22 -0500327 .WillOnce(DoAll(SetArgPointee<1>(
328 std::vector<aidl::android::hardware::graphics::composer3::
329 DisplayCapability>({})),
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700330 Return(Error::NONE)));
331 }
332
333 template <typename Case>
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700334 static void setupCommonCompositionCallExpectations(CompositionTest* test) {
Ady Abrahamdc011a92021-12-21 14:06:44 -0800335 EXPECT_CALL(*test->mComposer, setColorTransform(HWC_DISPLAY, IsIdentityMatrix())).Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700336 EXPECT_CALL(*test->mComposer, getDisplayRequests(HWC_DISPLAY, _, _, _)).Times(1);
337 EXPECT_CALL(*test->mComposer, acceptDisplayChanges(HWC_DISPLAY)).Times(1);
338 EXPECT_CALL(*test->mComposer, presentDisplay(HWC_DISPLAY, _)).Times(1);
339 EXPECT_CALL(*test->mComposer, getReleaseFences(HWC_DISPLAY, _, _)).Times(1);
340
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700341 EXPECT_CALL(*test->mDisplaySurface, onFrameCommitted()).Times(1);
342 EXPECT_CALL(*test->mDisplaySurface, advanceFrame()).Times(1);
343
344 Case::CompositionType::setupHwcSetCallExpectations(test);
345 Case::CompositionType::setupHwcGetCallExpectations(test);
346 }
347
348 template <typename Case>
349 static void setupCommonScreensCaptureCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000350 EXPECT_CALL(*test->mRenderEngine, drawLayers)
Sally Qi4cabdd02021-08-05 16:45:57 -0700351 .WillRepeatedly([&](const renderengine::DisplaySettings& displaySettings,
Sally Qi59a9f502021-10-12 18:53:23 +0000352 const std::vector<renderengine::LayerSettings>&,
Sally Qi4cabdd02021-08-05 16:45:57 -0700353 const std::shared_ptr<renderengine::ExternalTexture>&,
Sally Qi59a9f502021-10-12 18:53:23 +0000354 const bool, base::unique_fd&&)
Sally Qi4cabdd02021-08-05 16:45:57 -0700355 -> std::future<renderengine::RenderEngineResult> {
Lloyd Pique9370a482019-10-03 17:58:30 -0700356 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
357 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
358 displaySettings.physicalDisplay);
359 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
360 displaySettings.clip);
Sally Qi4cabdd02021-08-05 16:45:57 -0700361 return futureOf<renderengine::RenderEngineResult>(
362 {NO_ERROR, base::unique_fd()});
Lloyd Pique9370a482019-10-03 17:58:30 -0700363 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700364 }
365
366 static void setupNonEmptyFrameCompositionCallExpectations(CompositionTest* test) {
367 EXPECT_CALL(*test->mDisplaySurface, beginFrame(true)).Times(1);
368 }
369
370 static void setupEmptyFrameCompositionCallExpectations(CompositionTest* test) {
371 EXPECT_CALL(*test->mDisplaySurface, beginFrame(false)).Times(1);
372 }
373
374 static void setupHwcCompositionCallExpectations(CompositionTest* test) {
Ady Abraham43065bd2021-12-10 17:22:15 -0800375 EXPECT_CALL(*test->mComposer, presentOrValidateDisplay(HWC_DISPLAY, _, _, _, _, _))
376 .Times(1);
Lloyd Pique66d68602019-02-13 14:23:31 -0800377
Lloyd Pique542307f2018-10-19 13:24:08 -0700378 EXPECT_CALL(*test->mDisplaySurface,
Dominik Laskowskif5d0ea52021-09-26 17:27:01 -0700379 prepareFrame(compositionengine::DisplaySurface::CompositionType::Hwc))
Lloyd Pique542307f2018-10-19 13:24:08 -0700380 .Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700381 }
382
Lloyd Pique66d68602019-02-13 14:23:31 -0800383 static void setupHwcClientCompositionCallExpectations(CompositionTest* test) {
Ady Abraham43065bd2021-12-10 17:22:15 -0800384 EXPECT_CALL(*test->mComposer, presentOrValidateDisplay(HWC_DISPLAY, _, _, _, _, _))
385 .Times(1);
Lloyd Pique66d68602019-02-13 14:23:31 -0800386 }
387
388 static void setupHwcForcedClientCompositionCallExpectations(CompositionTest* test) {
Ady Abraham43065bd2021-12-10 17:22:15 -0800389 EXPECT_CALL(*test->mComposer, validateDisplay(HWC_DISPLAY, _, _, _)).Times(1);
Lloyd Pique66d68602019-02-13 14:23:31 -0800390 }
391
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700392 static void setupRECompositionCallExpectations(CompositionTest* test) {
Lloyd Pique542307f2018-10-19 13:24:08 -0700393 EXPECT_CALL(*test->mDisplaySurface,
Dominik Laskowskif5d0ea52021-09-26 17:27:01 -0700394 prepareFrame(compositionengine::DisplaySurface::CompositionType::Gpu))
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700395 .Times(1);
396 EXPECT_CALL(*test->mDisplaySurface, getClientTargetAcquireFence())
397 .WillRepeatedly(ReturnRef(test->mClientTargetAcquireFence));
398
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800399 EXPECT_CALL(*test->mNativeWindow, queueBuffer(_, _)).WillOnce(Return(0));
400 EXPECT_CALL(*test->mNativeWindow, dequeueBuffer(_, _))
401 .WillOnce(DoAll(SetArgPointee<0>(test->mNativeWindowBuffer), SetArgPointee<1>(-1),
402 Return(0)));
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000403 EXPECT_CALL(*test->mRenderEngine, drawLayers)
Sally Qi4cabdd02021-08-05 16:45:57 -0700404 .WillRepeatedly([&](const renderengine::DisplaySettings& displaySettings,
Sally Qi59a9f502021-10-12 18:53:23 +0000405 const std::vector<renderengine::LayerSettings>&,
Sally Qi4cabdd02021-08-05 16:45:57 -0700406 const std::shared_ptr<renderengine::ExternalTexture>&,
Sally Qi59a9f502021-10-12 18:53:23 +0000407 const bool, base::unique_fd&&)
Sally Qi4cabdd02021-08-05 16:45:57 -0700408 -> std::future<renderengine::RenderEngineResult> {
Lloyd Pique9370a482019-10-03 17:58:30 -0700409 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
410 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
411 displaySettings.physicalDisplay);
412 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
413 displaySettings.clip);
414 EXPECT_EQ(ui::Dataspace::UNKNOWN, displaySettings.outputDataspace);
Sally Qi4cabdd02021-08-05 16:45:57 -0700415 return futureOf<renderengine::RenderEngineResult>(
416 {NO_ERROR, base::unique_fd()});
Lloyd Pique9370a482019-10-03 17:58:30 -0700417 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700418 }
419
420 template <typename Case>
421 static void setupRELayerCompositionCallExpectations(CompositionTest* test) {
422 Case::Layer::setupRECompositionCallExpectations(test);
423 }
424
425 template <typename Case>
426 static void setupRELayerScreenshotCompositionCallExpectations(CompositionTest* test) {
427 Case::Layer::setupREScreenshotCompositionCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700428 }
429};
430
431struct DefaultDisplaySetupVariant : public BaseDisplayVariant<DefaultDisplaySetupVariant> {};
432
433struct InsecureDisplaySetupVariant : public BaseDisplayVariant<InsecureDisplaySetupVariant> {
434 static constexpr bool IS_SECURE = false;
435
436 template <typename Case>
437 static void setupRELayerCompositionCallExpectations(CompositionTest* test) {
438 Case::Layer::setupInsecureRECompositionCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700439 }
440
441 template <typename Case>
442 static void setupRELayerScreenshotCompositionCallExpectations(CompositionTest* test) {
443 Case::Layer::setupInsecureREScreenshotCompositionCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700444 }
445};
446
447struct PoweredOffDisplaySetupVariant : public BaseDisplayVariant<PoweredOffDisplaySetupVariant> {
Peiyong Lin65248e02020-04-18 21:15:07 -0700448 static constexpr hal::PowerMode INIT_POWER_MODE = hal::PowerMode::OFF;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700449
450 template <typename Case>
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700451 static void setupPreconditionCallExpectations(CompositionTest*) {}
452
453 template <typename Case>
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700454 static void setupCommonCompositionCallExpectations(CompositionTest* test) {
455 // TODO: This seems like an unnecessary call if display is powered off.
Ady Abrahamdc011a92021-12-21 14:06:44 -0800456 EXPECT_CALL(*test->mComposer, setColorTransform(HWC_DISPLAY, IsIdentityMatrix())).Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700457
458 // TODO: This seems like an unnecessary call if display is powered off.
459 Case::CompositionType::setupHwcSetCallExpectations(test);
460 }
461
462 static void setupHwcCompositionCallExpectations(CompositionTest*) {}
Lloyd Pique66d68602019-02-13 14:23:31 -0800463 static void setupHwcClientCompositionCallExpectations(CompositionTest*) {}
464 static void setupHwcForcedClientCompositionCallExpectations(CompositionTest*) {}
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700465
466 static void setupRECompositionCallExpectations(CompositionTest* test) {
467 // TODO: This seems like an unnecessary call if display is powered off.
468 EXPECT_CALL(*test->mDisplaySurface, getClientTargetAcquireFence())
469 .WillRepeatedly(ReturnRef(test->mClientTargetAcquireFence));
470 }
471
472 template <typename Case>
473 static void setupRELayerCompositionCallExpectations(CompositionTest*) {}
474};
475
476/* ------------------------------------------------------------------------
477 * Variants for each layer configuration which can be tested
478 */
479
480template <typename LayerProperties>
481struct BaseLayerProperties {
482 static constexpr uint32_t WIDTH = 100;
483 static constexpr uint32_t HEIGHT = 100;
484 static constexpr PixelFormat FORMAT = PIXEL_FORMAT_RGBA_8888;
485 static constexpr uint64_t USAGE =
486 GraphicBuffer::USAGE_SW_READ_NEVER | GraphicBuffer::USAGE_SW_WRITE_NEVER;
487 static constexpr android_dataspace DATASPACE = HAL_DATASPACE_UNKNOWN;
488 static constexpr uint32_t SCALING_MODE = 0;
489 static constexpr uint32_t TRANSFORM = 0;
490 static constexpr uint32_t LAYER_FLAGS = 0;
491 static constexpr float COLOR[] = {1.f, 1.f, 1.f, 1.f};
492 static constexpr IComposerClient::BlendMode BLENDMODE =
493 IComposerClient::BlendMode::PREMULTIPLIED;
494
495 static void enqueueBuffer(CompositionTest*, sp<BufferQueueLayer> layer) {
496 auto producer = layer->getProducer();
497
498 IGraphicBufferProducer::QueueBufferOutput qbo;
499 status_t result = producer->connect(nullptr, NATIVE_WINDOW_API_EGL, false, &qbo);
500 if (result != NO_ERROR) {
501 ALOGE("Failed to connect() (%d)", result);
502 return;
503 }
504
505 int slot;
506 sp<Fence> fence;
507 result = producer->dequeueBuffer(&slot, &fence, LayerProperties::WIDTH,
508 LayerProperties::HEIGHT, LayerProperties::FORMAT,
509 LayerProperties::USAGE, nullptr, nullptr);
510 if (result != IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION) {
511 ALOGE("Failed to dequeueBuffer() (%d)", result);
512 return;
513 }
514
515 sp<GraphicBuffer> buffer;
516 result = producer->requestBuffer(slot, &buffer);
517 if (result != NO_ERROR) {
518 ALOGE("Failed to requestBuffer() (%d)", result);
519 return;
520 }
521
522 IGraphicBufferProducer::QueueBufferInput qbi(systemTime(), false /* isAutoTimestamp */,
523 LayerProperties::DATASPACE,
524 Rect(LayerProperties::WIDTH,
525 LayerProperties::HEIGHT),
526 LayerProperties::SCALING_MODE,
527 LayerProperties::TRANSFORM, Fence::NO_FENCE);
528 result = producer->queueBuffer(slot, qbi, &qbo);
529 if (result != NO_ERROR) {
530 ALOGE("Failed to queueBuffer (%d)", result);
531 return;
532 }
533 }
534
535 static void setupLatchedBuffer(CompositionTest* test, sp<BufferQueueLayer> layer) {
536 // TODO: Eliminate the complexity of actually creating a buffer
Vishnu Nair7fb9e5a2021-11-08 12:44:05 -0800537 layer->setSizeForTest(LayerProperties::WIDTH, LayerProperties::HEIGHT);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700538 status_t err =
539 layer->setDefaultBufferProperties(LayerProperties::WIDTH, LayerProperties::HEIGHT,
540 LayerProperties::FORMAT);
541 ASSERT_EQ(NO_ERROR, err);
542 Mock::VerifyAndClear(test->mRenderEngine);
543
Dominik Laskowski46f3e3b2021-08-10 11:44:24 -0700544 EXPECT_CALL(*test->mFlinger.scheduler(), scheduleFrame()).Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700545 enqueueBuffer(test, layer);
Dominik Laskowski756b7892021-08-04 12:53:59 -0700546 Mock::VerifyAndClearExpectations(test->mFlinger.scheduler());
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700547
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700548 bool ignoredRecomputeVisibleRegions;
Dominik Laskowskia8955dd2019-07-10 10:19:09 -0700549 layer->latchBuffer(ignoredRecomputeVisibleRegions, 0, 0);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700550 Mock::VerifyAndClear(test->mRenderEngine);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700551 }
552
553 static void setupLayerState(CompositionTest* test, sp<BufferQueueLayer> layer) {
554 setupLatchedBuffer(test, layer);
555 }
556
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700557 static void setupHwcSetGeometryCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800558 if (!test->mDisplayOff) {
559 // TODO: Coverage of other values
560 EXPECT_CALL(*test->mComposer,
561 setLayerBlendMode(HWC_DISPLAY, HWC_LAYER, LayerProperties::BLENDMODE))
562 .Times(1);
563 // TODO: Coverage of other values for origin
564 EXPECT_CALL(*test->mComposer,
565 setLayerDisplayFrame(HWC_DISPLAY, HWC_LAYER,
566 IComposerClient::Rect({0, 0, LayerProperties::WIDTH,
567 LayerProperties::HEIGHT})))
568 .Times(1);
569 EXPECT_CALL(*test->mComposer,
570 setLayerPlaneAlpha(HWC_DISPLAY, HWC_LAYER, LayerProperties::COLOR[3]))
571 .Times(1);
572 // TODO: Coverage of other values
573 EXPECT_CALL(*test->mComposer, setLayerZOrder(HWC_DISPLAY, HWC_LAYER, 0u)).Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700574
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800575 // These expectations retire on saturation as the code path these
576 // expectations are for appears to make an extra call to them.
577 // TODO: Investigate this extra call
578 EXPECT_CALL(*test->mComposer,
579 setLayerTransform(HWC_DISPLAY, HWC_LAYER, DEFAULT_TRANSFORM))
580 .Times(AtLeast(1))
581 .RetiresOnSaturation();
582 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700583 }
584
585 static void setupHwcSetSourceCropBufferCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800586 if (!test->mDisplayOff) {
587 EXPECT_CALL(*test->mComposer,
588 setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER,
589 IComposerClient::FRect({0.f, 0.f, LayerProperties::WIDTH,
590 LayerProperties::HEIGHT})))
591 .Times(1);
592 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700593 }
594
595 static void setupHwcSetSourceCropColorCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800596 if (!test->mDisplayOff) {
597 EXPECT_CALL(*test->mComposer,
598 setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER,
599 IComposerClient::FRect({0.f, 0.f, 0.f, 0.f})))
600 .Times(1);
601 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700602 }
603
604 static void setupHwcSetPerFrameCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800605 if (!test->mDisplayOff) {
606 EXPECT_CALL(*test->mComposer,
607 setLayerVisibleRegion(HWC_DISPLAY, HWC_LAYER,
608 std::vector<IComposerClient::Rect>(
609 {IComposerClient::Rect(
610 {0, 0, LayerProperties::WIDTH,
611 LayerProperties::HEIGHT})})))
612 .Times(1);
613 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700614 }
615
616 static void setupHwcSetPerFrameColorCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800617 if (!test->mDisplayOff) {
618 EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _))
619 .Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700620
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800621 // TODO: use COLOR
622 EXPECT_CALL(*test->mComposer,
623 setLayerColor(HWC_DISPLAY, HWC_LAYER,
624 IComposerClient::Color({0xff, 0xff, 0xff, 0xff})))
625 .Times(1);
626 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700627 }
628
629 static void setupHwcSetPerFrameBufferCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800630 if (!test->mDisplayOff) {
631 EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _))
632 .Times(1);
633 EXPECT_CALL(*test->mComposer, setLayerBuffer(HWC_DISPLAY, HWC_LAYER, _, _, _)).Times(1);
634 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700635 }
636
637 static void setupREBufferCompositionCommonCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000638 EXPECT_CALL(*test->mRenderEngine, drawLayers)
Sally Qi4cabdd02021-08-05 16:45:57 -0700639 .WillOnce([&](const renderengine::DisplaySettings& displaySettings,
Sally Qi59a9f502021-10-12 18:53:23 +0000640 const std::vector<renderengine::LayerSettings>& layerSettings,
Sally Qi4cabdd02021-08-05 16:45:57 -0700641 const std::shared_ptr<renderengine::ExternalTexture>&, const bool,
Sally Qi59a9f502021-10-12 18:53:23 +0000642 base::unique_fd&&) -> std::future<renderengine::RenderEngineResult> {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000643 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
644 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
645 displaySettings.physicalDisplay);
646 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
647 displaySettings.clip);
648 // screen capture adds an additional color layer as an alpha
649 // prefill, so gtet the back layer.
Sally Qi4cabdd02021-08-05 16:45:57 -0700650 std::future<renderengine::RenderEngineResult> resultFuture =
651 futureOf<renderengine::RenderEngineResult>(
652 {NO_ERROR, base::unique_fd()});
Lloyd Piquea2468662019-03-07 21:31:06 -0800653 if (layerSettings.empty()) {
654 ADD_FAILURE() << "layerSettings was not expected to be empty in "
655 "setupREBufferCompositionCommonCallExpectations "
656 "verification lambda";
Sally Qi4cabdd02021-08-05 16:45:57 -0700657 return resultFuture;
Lloyd Piquea2468662019-03-07 21:31:06 -0800658 }
Sally Qi59a9f502021-10-12 18:53:23 +0000659 const renderengine::LayerSettings layer = layerSettings.back();
660 EXPECT_THAT(layer.source.buffer.buffer, Not(IsNull()));
661 EXPECT_THAT(layer.source.buffer.fence, Not(IsNull()));
662 EXPECT_EQ(DEFAULT_TEXTURE_ID, layer.source.buffer.textureName);
663 EXPECT_EQ(false, layer.source.buffer.isY410BT2020);
664 EXPECT_EQ(true, layer.source.buffer.usePremultipliedAlpha);
665 EXPECT_EQ(false, layer.source.buffer.isOpaque);
666 EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius);
667 EXPECT_EQ(ui::Dataspace::UNKNOWN, layer.sourceDataspace);
668 EXPECT_EQ(LayerProperties::COLOR[3], layer.alpha);
Sally Qi4cabdd02021-08-05 16:45:57 -0700669 return resultFuture;
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000670 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700671 }
672
673 static void setupREBufferCompositionCallExpectations(CompositionTest* test) {
674 LayerProperties::setupREBufferCompositionCommonCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700675 }
676
677 static void setupInsecureREBufferCompositionCallExpectations(CompositionTest* test) {
678 setupREBufferCompositionCallExpectations(test);
679 }
680
681 static void setupREBufferScreenshotCompositionCallExpectations(CompositionTest* test) {
682 LayerProperties::setupREBufferCompositionCommonCallExpectations(test);
683 }
684
685 static void setupInsecureREBufferScreenshotCompositionCallExpectations(CompositionTest* test) {
686 LayerProperties::setupREBufferCompositionCommonCallExpectations(test);
687 }
688
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700689 static void setupREColorCompositionCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000690 EXPECT_CALL(*test->mRenderEngine, drawLayers)
Sally Qi4cabdd02021-08-05 16:45:57 -0700691 .WillOnce([&](const renderengine::DisplaySettings& displaySettings,
Sally Qi59a9f502021-10-12 18:53:23 +0000692 const std::vector<renderengine::LayerSettings>& layerSettings,
Sally Qi4cabdd02021-08-05 16:45:57 -0700693 const std::shared_ptr<renderengine::ExternalTexture>&, const bool,
Sally Qi59a9f502021-10-12 18:53:23 +0000694 base::unique_fd&&) -> std::future<renderengine::RenderEngineResult> {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000695 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
696 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
697 displaySettings.physicalDisplay);
698 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
699 displaySettings.clip);
700 // screen capture adds an additional color layer as an alpha
701 // prefill, so get the back layer.
Sally Qi4cabdd02021-08-05 16:45:57 -0700702 std::future<renderengine::RenderEngineResult> resultFuture =
703 futureOf<renderengine::RenderEngineResult>(
704 {NO_ERROR, base::unique_fd()});
Lloyd Piquea2468662019-03-07 21:31:06 -0800705 if (layerSettings.empty()) {
706 ADD_FAILURE()
707 << "layerSettings was not expected to be empty in "
708 "setupREColorCompositionCallExpectations verification lambda";
Sally Qi4cabdd02021-08-05 16:45:57 -0700709 return resultFuture;
Lloyd Piquea2468662019-03-07 21:31:06 -0800710 }
Sally Qi59a9f502021-10-12 18:53:23 +0000711 const renderengine::LayerSettings layer = layerSettings.back();
712 EXPECT_THAT(layer.source.buffer.buffer, IsNull());
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000713 EXPECT_EQ(half3(LayerProperties::COLOR[0], LayerProperties::COLOR[1],
714 LayerProperties::COLOR[2]),
Sally Qi59a9f502021-10-12 18:53:23 +0000715 layer.source.solidColor);
716 EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius);
717 EXPECT_EQ(ui::Dataspace::UNKNOWN, layer.sourceDataspace);
718 EXPECT_EQ(LayerProperties::COLOR[3], layer.alpha);
Sally Qi4cabdd02021-08-05 16:45:57 -0700719 return resultFuture;
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000720 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700721 }
722
723 static void setupREColorScreenshotCompositionCallExpectations(CompositionTest* test) {
724 setupREColorCompositionCallExpectations(test);
725 }
726};
727
728struct DefaultLayerProperties : public BaseLayerProperties<DefaultLayerProperties> {};
729
Vishnu Nairfa247b12020-02-11 08:58:26 -0800730struct EffectLayerProperties : public BaseLayerProperties<EffectLayerProperties> {
Alec Mourida8a9d12020-01-30 20:00:31 -0800731 static constexpr IComposerClient::BlendMode BLENDMODE = IComposerClient::BlendMode::NONE;
732};
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700733
734struct SidebandLayerProperties : public BaseLayerProperties<SidebandLayerProperties> {
735 using Base = BaseLayerProperties<SidebandLayerProperties>;
736 static constexpr IComposerClient::BlendMode BLENDMODE = IComposerClient::BlendMode::NONE;
737
738 static void setupLayerState(CompositionTest* test, sp<BufferQueueLayer> layer) {
739 sp<NativeHandle> stream =
740 NativeHandle::create(reinterpret_cast<native_handle_t*>(DEFAULT_SIDEBAND_STREAM),
741 false);
742 test->mFlinger.setLayerSidebandStream(layer, stream);
743 }
744
745 static void setupHwcSetSourceCropBufferCallExpectations(CompositionTest* test) {
746 EXPECT_CALL(*test->mComposer,
747 setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER,
748 IComposerClient::FRect({0.f, 0.f, -1.f, -1.f})))
749 .Times(1);
750 }
751
752 static void setupHwcSetPerFrameBufferCallExpectations(CompositionTest* test) {
753 EXPECT_CALL(*test->mComposer,
754 setLayerSidebandStream(HWC_DISPLAY, HWC_LAYER,
755 reinterpret_cast<native_handle_t*>(
756 DEFAULT_SIDEBAND_STREAM)))
757 .WillOnce(Return(Error::NONE));
758
759 EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _)).Times(1);
760 }
761
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000762 static void setupREBufferCompositionCommonCallExpectations(CompositionTest* /*test*/) {}
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700763};
764
Garfield Tande619fa2020-10-02 17:13:53 -0700765template <typename LayerProperties>
766struct CommonSecureLayerProperties : public BaseLayerProperties<LayerProperties> {
767 using Base = BaseLayerProperties<LayerProperties>;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700768
769 static void setupInsecureREBufferCompositionCommonCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000770 EXPECT_CALL(*test->mRenderEngine, drawLayers)
Sally Qi4cabdd02021-08-05 16:45:57 -0700771 .WillOnce([&](const renderengine::DisplaySettings& displaySettings,
Sally Qi59a9f502021-10-12 18:53:23 +0000772 const std::vector<renderengine::LayerSettings>& layerSettings,
Sally Qi4cabdd02021-08-05 16:45:57 -0700773 const std::shared_ptr<renderengine::ExternalTexture>&, const bool,
Sally Qi59a9f502021-10-12 18:53:23 +0000774 base::unique_fd&&) -> std::future<renderengine::RenderEngineResult> {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000775 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
776 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
777 displaySettings.physicalDisplay);
778 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
779 displaySettings.clip);
780 // screen capture adds an additional color layer as an alpha
781 // prefill, so get the back layer.
Sally Qi4cabdd02021-08-05 16:45:57 -0700782 std::future<renderengine::RenderEngineResult> resultFuture =
783 futureOf<renderengine::RenderEngineResult>(
784 {NO_ERROR, base::unique_fd()});
Lloyd Piquea2468662019-03-07 21:31:06 -0800785 if (layerSettings.empty()) {
786 ADD_FAILURE() << "layerSettings was not expected to be empty in "
787 "setupInsecureREBufferCompositionCommonCallExpectations "
788 "verification lambda";
Sally Qi4cabdd02021-08-05 16:45:57 -0700789 return resultFuture;
Lloyd Piquea2468662019-03-07 21:31:06 -0800790 }
Sally Qi59a9f502021-10-12 18:53:23 +0000791 const renderengine::LayerSettings layer = layerSettings.back();
792 EXPECT_THAT(layer.source.buffer.buffer, IsNull());
793 EXPECT_EQ(half3(0.0f, 0.0f, 0.0f), layer.source.solidColor);
794 EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius);
795 EXPECT_EQ(ui::Dataspace::UNKNOWN, layer.sourceDataspace);
796 EXPECT_EQ(1.0f, layer.alpha);
Sally Qi4cabdd02021-08-05 16:45:57 -0700797 return resultFuture;
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000798 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700799 }
800
801 static void setupInsecureREBufferCompositionCallExpectations(CompositionTest* test) {
802 setupInsecureREBufferCompositionCommonCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700803 }
804
805 static void setupInsecureREBufferScreenshotCompositionCallExpectations(CompositionTest* test) {
806 setupInsecureREBufferCompositionCommonCallExpectations(test);
807 }
808};
809
Garfield Tande619fa2020-10-02 17:13:53 -0700810struct ParentSecureLayerProperties
811 : public CommonSecureLayerProperties<ParentSecureLayerProperties> {};
812
813struct SecureLayerProperties : public CommonSecureLayerProperties<SecureLayerProperties> {
814 static constexpr uint32_t LAYER_FLAGS = ISurfaceComposerClient::eSecure;
815};
816
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700817struct CursorLayerProperties : public BaseLayerProperties<CursorLayerProperties> {
818 using Base = BaseLayerProperties<CursorLayerProperties>;
819
820 static void setupLayerState(CompositionTest* test, sp<BufferQueueLayer> layer) {
821 Base::setupLayerState(test, layer);
822 test->mFlinger.setLayerPotentialCursor(layer, true);
823 }
824};
825
826struct NoLayerVariant {
827 using FlingerLayerType = sp<BufferQueueLayer>;
828
829 static FlingerLayerType createLayer(CompositionTest*) { return FlingerLayerType(); }
830 static void injectLayer(CompositionTest*, FlingerLayerType) {}
831 static void cleanupInjectedLayers(CompositionTest*) {}
832
833 static void setupCallExpectationsForDirtyGeometry(CompositionTest*) {}
834 static void setupCallExpectationsForDirtyFrame(CompositionTest*) {}
835};
836
837template <typename LayerProperties>
838struct BaseLayerVariant {
839 template <typename L, typename F>
840 static sp<L> createLayerWithFactory(CompositionTest* test, F factory) {
Dominik Laskowski756b7892021-08-04 12:53:59 -0700841 EXPECT_CALL(*test->mFlinger.scheduler(), postMessage(_)).Times(0);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700842
843 sp<L> layer = factory();
844
Dominik Laskowski49cea512019-11-12 14:13:23 -0800845 // Layer should be registered with scheduler.
Dominik Laskowski9c93d602021-10-07 19:38:26 -0700846 EXPECT_EQ(1u, test->mFlinger.scheduler()->layerHistorySize());
Dominik Laskowski49cea512019-11-12 14:13:23 -0800847
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700848 Mock::VerifyAndClear(test->mComposer);
849 Mock::VerifyAndClear(test->mRenderEngine);
Dominik Laskowski756b7892021-08-04 12:53:59 -0700850 Mock::VerifyAndClearExpectations(test->mFlinger.scheduler());
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700851
Garfield Tande619fa2020-10-02 17:13:53 -0700852 initLayerDrawingStateAndComputeBounds(test, layer);
853
854 return layer;
855 }
856
857 template <typename L>
858 static void initLayerDrawingStateAndComputeBounds(CompositionTest* test, sp<L> layer) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700859 auto& layerDrawingState = test->mFlinger.mutableLayerDrawingState(layer);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700860 layerDrawingState.layerStack = LAYER_STACK;
chaviw766c9c52021-02-10 17:36:47 -0800861 layerDrawingState.width = 100;
862 layerDrawingState.height = 100;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700863 layerDrawingState.color = half4(LayerProperties::COLOR[0], LayerProperties::COLOR[1],
864 LayerProperties::COLOR[2], LayerProperties::COLOR[3]);
Vishnu Nairc97b8db2019-10-29 18:19:35 -0700865 layer->computeBounds(FloatRect(0, 0, 100, 100), ui::Transform(), 0.f /* shadowRadius */);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700866 }
867
868 static void injectLayer(CompositionTest* test, sp<Layer> layer) {
869 EXPECT_CALL(*test->mComposer, createLayer(HWC_DISPLAY, _))
870 .WillOnce(DoAll(SetArgPointee<1>(HWC_LAYER), Return(Error::NONE)));
871
Lloyd Piquede196652020-01-22 17:29:58 -0800872 auto outputLayer = test->mDisplay->getCompositionDisplay()->injectOutputLayerForTest(
873 layer->getCompositionEngineLayerFE());
Lloyd Pique01c77c12019-04-17 12:48:32 -0700874 outputLayer->editState().visibleRegion = Region(Rect(0, 0, 100, 100));
875 outputLayer->editState().outputSpaceVisibleRegion = Region(Rect(0, 0, 100, 100));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700876
877 Mock::VerifyAndClear(test->mComposer);
878
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700879 test->mFlinger.mutableDrawingState().layersSortedByZ.add(layer);
880 }
881
882 static void cleanupInjectedLayers(CompositionTest* test) {
883 EXPECT_CALL(*test->mComposer, destroyLayer(HWC_DISPLAY, HWC_LAYER))
884 .WillOnce(Return(Error::NONE));
Lloyd Pique37c2c9b2018-12-04 17:25:10 -0800885
Lloyd Pique01c77c12019-04-17 12:48:32 -0700886 test->mDisplay->getCompositionDisplay()->clearOutputLayers();
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700887 test->mFlinger.mutableDrawingState().layersSortedByZ.clear();
Dominik Laskowski49cea512019-11-12 14:13:23 -0800888
889 // Layer should be unregistered with scheduler.
Dominik Laskowskie0e0cde2021-07-30 10:42:05 -0700890 test->mFlinger.commit();
Dominik Laskowski9c93d602021-10-07 19:38:26 -0700891 EXPECT_EQ(0u, test->mFlinger.scheduler()->layerHistorySize());
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700892 }
893};
894
895template <typename LayerProperties>
Vishnu Nairfa247b12020-02-11 08:58:26 -0800896struct EffectLayerVariant : public BaseLayerVariant<LayerProperties> {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700897 using Base = BaseLayerVariant<LayerProperties>;
Vishnu Nairfa247b12020-02-11 08:58:26 -0800898 using FlingerLayerType = sp<EffectLayer>;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700899
900 static FlingerLayerType createLayer(CompositionTest* test) {
Vishnu Nairfa247b12020-02-11 08:58:26 -0800901 FlingerLayerType layer = Base::template createLayerWithFactory<EffectLayer>(test, [test]() {
902 return new EffectLayer(
Dominik Laskowski8b01cc02020-07-14 19:02:41 -0700903 LayerCreationArgs(test->mFlinger.flinger(), sp<Client>(), "test-layer",
Vishnu Nairfa247b12020-02-11 08:58:26 -0800904 LayerProperties::LAYER_FLAGS, LayerMetadata()));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700905 });
Vishnu Nair60356342018-11-13 13:00:45 -0800906
907 auto& layerDrawingState = test->mFlinger.mutableLayerDrawingState(layer);
chaviw25714502021-02-11 10:01:08 -0800908 layerDrawingState.crop = Rect(0, 0, LayerProperties::HEIGHT, LayerProperties::WIDTH);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700909 return layer;
910 }
911
912 static void setupRECompositionCallExpectations(CompositionTest* test) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700913 LayerProperties::setupREColorCompositionCallExpectations(test);
914 }
915
916 static void setupREScreenshotCompositionCallExpectations(CompositionTest* test) {
917 LayerProperties::setupREColorScreenshotCompositionCallExpectations(test);
918 }
919
920 static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) {
921 LayerProperties::setupHwcSetGeometryCallExpectations(test);
922 LayerProperties::setupHwcSetSourceCropColorCallExpectations(test);
923 }
924
925 static void setupCallExpectationsForDirtyFrame(CompositionTest* test) {
926 LayerProperties::setupHwcSetPerFrameCallExpectations(test);
927 LayerProperties::setupHwcSetPerFrameColorCallExpectations(test);
928 }
929};
930
931template <typename LayerProperties>
932struct BufferLayerVariant : public BaseLayerVariant<LayerProperties> {
933 using Base = BaseLayerVariant<LayerProperties>;
934 using FlingerLayerType = sp<BufferQueueLayer>;
935
936 static FlingerLayerType createLayer(CompositionTest* test) {
937 test->mFlinger.mutableTexturePool().push_back(DEFAULT_TEXTURE_ID);
938
939 FlingerLayerType layer =
940 Base::template createLayerWithFactory<BufferQueueLayer>(test, [test]() {
Dominik Laskowski8b01cc02020-07-14 19:02:41 -0700941 LayerCreationArgs args(test->mFlinger.flinger(), sp<Client>(), "test-layer",
Dominik Laskowski87a07e42019-10-10 20:38:02 -0700942 LayerProperties::LAYER_FLAGS, LayerMetadata());
chaviwb4c6e582019-08-16 14:35:07 -0700943 args.textureName = test->mFlinger.mutableTexturePool().back();
944 return new BufferQueueLayer(args);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700945 });
946
947 LayerProperties::setupLayerState(test, layer);
948
949 return layer;
950 }
951
952 static void cleanupInjectedLayers(CompositionTest* test) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700953 Base::cleanupInjectedLayers(test);
954 }
955
956 static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) {
957 LayerProperties::setupHwcSetGeometryCallExpectations(test);
958 LayerProperties::setupHwcSetSourceCropBufferCallExpectations(test);
959 }
960
961 static void setupCallExpectationsForDirtyFrame(CompositionTest* test) {
962 LayerProperties::setupHwcSetPerFrameCallExpectations(test);
963 LayerProperties::setupHwcSetPerFrameBufferCallExpectations(test);
964 }
965
966 static void setupRECompositionCallExpectations(CompositionTest* test) {
967 LayerProperties::setupREBufferCompositionCallExpectations(test);
968 }
969
970 static void setupInsecureRECompositionCallExpectations(CompositionTest* test) {
971 LayerProperties::setupInsecureREBufferCompositionCallExpectations(test);
972 }
973
974 static void setupREScreenshotCompositionCallExpectations(CompositionTest* test) {
975 LayerProperties::setupREBufferScreenshotCompositionCallExpectations(test);
976 }
977
978 static void setupInsecureREScreenshotCompositionCallExpectations(CompositionTest* test) {
979 LayerProperties::setupInsecureREBufferScreenshotCompositionCallExpectations(test);
980 }
981};
982
Garfield Tande619fa2020-10-02 17:13:53 -0700983template <typename LayerProperties>
984struct ContainerLayerVariant : public BaseLayerVariant<LayerProperties> {
985 using Base = BaseLayerVariant<LayerProperties>;
986 using FlingerLayerType = sp<ContainerLayer>;
987
988 static FlingerLayerType createLayer(CompositionTest* test) {
989 LayerCreationArgs args(test->mFlinger.flinger(), sp<Client>(), "test-container-layer",
Garfield Tande619fa2020-10-02 17:13:53 -0700990 LayerProperties::LAYER_FLAGS, LayerMetadata());
991 FlingerLayerType layer = new ContainerLayer(args);
992 Base::template initLayerDrawingStateAndComputeBounds(test, layer);
993 return layer;
994 }
995};
996
997template <typename LayerVariant, typename ParentLayerVariant>
998struct ChildLayerVariant : public LayerVariant {
999 using Base = LayerVariant;
1000 using FlingerLayerType = typename LayerVariant::FlingerLayerType;
1001 using ParentBase = ParentLayerVariant;
1002
1003 static FlingerLayerType createLayer(CompositionTest* test) {
1004 // Need to create child layer first. Otherwise layer history size will be 2.
1005 FlingerLayerType layer = Base::createLayer(test);
1006
1007 typename ParentBase::FlingerLayerType parentLayer = ParentBase::createLayer(test);
1008 parentLayer->addChild(layer);
1009 test->mFlinger.setLayerDrawingParent(layer, parentLayer);
1010
1011 test->mAuxiliaryLayers.push_back(parentLayer);
1012
1013 return layer;
1014 }
1015
1016 static void cleanupInjectedLayers(CompositionTest* test) {
1017 // Clear auxiliary layers first so that child layer can be successfully destroyed in the
1018 // following call.
1019 test->mAuxiliaryLayers.clear();
1020
1021 Base::cleanupInjectedLayers(test);
1022 }
1023};
1024
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001025/* ------------------------------------------------------------------------
1026 * Variants to control how the composition type is changed
1027 */
1028
1029struct NoCompositionTypeVariant {
1030 static void setupHwcSetCallExpectations(CompositionTest*) {}
1031
1032 static void setupHwcGetCallExpectations(CompositionTest* test) {
1033 EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _)).Times(1);
1034 }
1035};
1036
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001037template <aidl::android::hardware::graphics::composer3::Composition CompositionType>
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001038struct KeepCompositionTypeVariant {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001039 static constexpr aidl::android::hardware::graphics::composer3::Composition TYPE =
1040 CompositionType;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001041
1042 static void setupHwcSetCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001043 if (!test->mDisplayOff) {
1044 EXPECT_CALL(*test->mComposer,
1045 setLayerCompositionType(HWC_DISPLAY, HWC_LAYER, CompositionType))
1046 .Times(1);
1047 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001048 }
1049
1050 static void setupHwcGetCallExpectations(CompositionTest* test) {
1051 EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _)).Times(1);
1052 }
1053};
1054
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001055template <aidl::android::hardware::graphics::composer3::Composition InitialCompositionType,
1056 aidl::android::hardware::graphics::composer3::Composition FinalCompositionType>
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001057struct ChangeCompositionTypeVariant {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001058 static constexpr aidl::android::hardware::graphics::composer3::Composition TYPE =
1059 FinalCompositionType;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001060
1061 static void setupHwcSetCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001062 if (!test->mDisplayOff) {
1063 EXPECT_CALL(*test->mComposer,
1064 setLayerCompositionType(HWC_DISPLAY, HWC_LAYER, InitialCompositionType))
1065 .Times(1);
1066 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001067 }
1068
1069 static void setupHwcGetCallExpectations(CompositionTest* test) {
1070 EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _))
1071 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::Layer>{
1072 static_cast<Hwc2::Layer>(HWC_LAYER)}),
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001073 SetArgPointee<2>(
1074 std::vector<aidl::android::hardware::graphics::composer3::
1075 Composition>{FinalCompositionType}),
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001076 Return(Error::NONE)));
1077 }
1078};
1079
1080/* ------------------------------------------------------------------------
1081 * Variants to select how the composition is expected to be handled
1082 */
1083
1084struct CompositionResultBaseVariant {
1085 static void setupLayerState(CompositionTest*, sp<Layer>) {}
1086
1087 template <typename Case>
1088 static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) {
1089 Case::Layer::setupCallExpectationsForDirtyGeometry(test);
1090 }
1091
1092 template <typename Case>
1093 static void setupCallExpectationsForDirtyFrame(CompositionTest* test) {
1094 Case::Layer::setupCallExpectationsForDirtyFrame(test);
1095 }
1096};
1097
1098struct NoCompositionResultVariant : public CompositionResultBaseVariant {
1099 template <typename Case>
1100 static void setupCallExpectations(CompositionTest* test) {
1101 Case::Display::setupEmptyFrameCompositionCallExpectations(test);
1102 Case::Display::setupHwcCompositionCallExpectations(test);
1103 }
1104};
1105
1106struct HwcCompositionResultVariant : public CompositionResultBaseVariant {
1107 template <typename Case>
1108 static void setupCallExpectations(CompositionTest* test) {
1109 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
1110 Case::Display::setupHwcCompositionCallExpectations(test);
1111 }
1112};
1113
1114struct RECompositionResultVariant : public CompositionResultBaseVariant {
1115 template <typename Case>
1116 static void setupCallExpectations(CompositionTest* test) {
1117 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
Lloyd Pique66d68602019-02-13 14:23:31 -08001118 Case::Display::setupHwcClientCompositionCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001119 Case::Display::setupRECompositionCallExpectations(test);
1120 Case::Display::template setupRELayerCompositionCallExpectations<Case>(test);
1121 }
1122};
1123
Lloyd Pique66d68602019-02-13 14:23:31 -08001124struct ForcedClientCompositionResultVariant : public CompositionResultBaseVariant {
Lloyd Pique37c2c9b2018-12-04 17:25:10 -08001125 static void setupLayerState(CompositionTest* test, sp<Layer> layer) {
Dominik Laskowskib7251f42020-04-20 17:42:59 -07001126 const auto outputLayer =
1127 TestableSurfaceFlinger::findOutputLayerForDisplay(layer, test->mDisplay);
Lloyd Piquef5275482019-01-29 18:42:42 -08001128 LOG_FATAL_IF(!outputLayer);
1129 outputLayer->editState().forceClientComposition = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001130 }
1131
1132 template <typename Case>
Lloyd Pique66d68602019-02-13 14:23:31 -08001133 static void setupCallExpectations(CompositionTest* test) {
1134 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
1135 Case::Display::setupHwcForcedClientCompositionCallExpectations(test);
1136 Case::Display::setupRECompositionCallExpectations(test);
1137 Case::Display::template setupRELayerCompositionCallExpectations<Case>(test);
1138 }
1139
1140 template <typename Case>
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001141 static void setupCallExpectationsForDirtyGeometry(CompositionTest*) {}
1142
1143 template <typename Case>
1144 static void setupCallExpectationsForDirtyFrame(CompositionTest*) {}
1145};
1146
Lloyd Pique4fe29402019-08-12 16:51:24 -07001147struct ForcedClientCompositionViaDebugOptionResultVariant : public CompositionResultBaseVariant {
1148 static void setupLayerState(CompositionTest* test, sp<Layer>) {
1149 test->mFlinger.mutableDebugDisableHWC() = true;
1150 }
1151
1152 template <typename Case>
1153 static void setupCallExpectations(CompositionTest* test) {
1154 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
1155 Case::Display::setupHwcForcedClientCompositionCallExpectations(test);
1156 Case::Display::setupRECompositionCallExpectations(test);
1157 Case::Display::template setupRELayerCompositionCallExpectations<Case>(test);
1158 }
1159
1160 template <typename Case>
1161 static void setupCallExpectationsForDirtyGeometry(CompositionTest*) {}
1162
1163 template <typename Case>
1164 static void setupCallExpectationsForDirtyFrame(CompositionTest*) {}
1165};
1166
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001167struct EmptyScreenshotResultVariant {
1168 static void setupLayerState(CompositionTest*, sp<Layer>) {}
1169
1170 template <typename Case>
1171 static void setupCallExpectations(CompositionTest*) {}
1172};
1173
1174struct REScreenshotResultVariant : public EmptyScreenshotResultVariant {
1175 using Base = EmptyScreenshotResultVariant;
1176
1177 template <typename Case>
1178 static void setupCallExpectations(CompositionTest* test) {
1179 Base::template setupCallExpectations<Case>(test);
1180 Case::Display::template setupRELayerScreenshotCompositionCallExpectations<Case>(test);
1181 }
1182};
1183
1184/* ------------------------------------------------------------------------
1185 * Composition test case, containing all the variants being tested
1186 */
1187
1188template <typename DisplayCase, typename LayerCase, typename CompositionTypeCase,
1189 typename CompositionResultCase>
1190struct CompositionCase {
1191 using ThisCase =
1192 CompositionCase<DisplayCase, LayerCase, CompositionTypeCase, CompositionResultCase>;
1193 using Display = DisplayCase;
1194 using Layer = LayerCase;
1195 using CompositionType = CompositionTypeCase;
1196 using CompositionResult = CompositionResultCase;
1197
1198 static void setupCommon(CompositionTest* test) {
Peiyong Lin1336e6e2019-05-28 09:23:50 -07001199 Display::template setupPreconditionCallExpectations<ThisCase>(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001200 Display::setupPreconditions(test);
1201
1202 auto layer = Layer::createLayer(test);
1203 Layer::injectLayer(test, layer);
1204 CompositionResult::setupLayerState(test, layer);
1205 }
1206
1207 static void setupForDirtyGeometry(CompositionTest* test) {
1208 setupCommon(test);
1209
1210 Display::template setupCommonCompositionCallExpectations<ThisCase>(test);
1211 CompositionResult::template setupCallExpectationsForDirtyGeometry<ThisCase>(test);
1212 CompositionResult::template setupCallExpectationsForDirtyFrame<ThisCase>(test);
1213 CompositionResult::template setupCallExpectations<ThisCase>(test);
1214 }
1215
1216 static void setupForDirtyFrame(CompositionTest* test) {
1217 setupCommon(test);
1218
1219 Display::template setupCommonCompositionCallExpectations<ThisCase>(test);
1220 CompositionResult::template setupCallExpectationsForDirtyFrame<ThisCase>(test);
1221 CompositionResult::template setupCallExpectations<ThisCase>(test);
1222 }
1223
1224 static void setupForScreenCapture(CompositionTest* test) {
1225 setupCommon(test);
1226
1227 Display::template setupCommonScreensCaptureCallExpectations<ThisCase>(test);
1228 CompositionResult::template setupCallExpectations<ThisCase>(test);
1229 }
1230
1231 static void cleanup(CompositionTest* test) {
1232 Layer::cleanupInjectedLayers(test);
1233
Peiyong Linbdd08cc2019-12-17 21:35:14 -08001234 for (auto& displayData : test->mFlinger.mutableHwcDisplayData()) {
1235 static_cast<TestableSurfaceFlinger::HWC2Display*>(displayData.second.hwcDisplay.get())
1236 ->mutableLayers()
1237 .clear();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001238 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001239 }
1240};
1241
1242/* ------------------------------------------------------------------------
1243 * Composition cases to test
1244 */
1245
1246TEST_F(CompositionTest, noLayersDoesMinimalWorkWithDirtyGeometry) {
1247 displayRefreshCompositionDirtyGeometry<
1248 CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant,
1249 NoCompositionResultVariant>>();
1250}
1251
1252TEST_F(CompositionTest, noLayersDoesMinimalWorkWithDirtyFrame) {
1253 displayRefreshCompositionDirtyFrame<
1254 CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant,
1255 NoCompositionResultVariant>>();
1256}
1257
1258TEST_F(CompositionTest, noLayersDoesMinimalWorkToCaptureScreen) {
1259 captureScreenComposition<
1260 CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant,
1261 EmptyScreenshotResultVariant>>();
1262}
1263
1264/* ------------------------------------------------------------------------
1265 * Simple buffer layers
1266 */
1267
1268TEST_F(CompositionTest, HWCComposedNormalBufferLayerWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001269 displayRefreshCompositionDirtyGeometry<CompositionCase<
1270 DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1271 KeepCompositionTypeVariant<
1272 aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
1273 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001274}
1275
1276TEST_F(CompositionTest, HWCComposedNormalBufferLayerWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001277 displayRefreshCompositionDirtyFrame<CompositionCase<
1278 DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1279 KeepCompositionTypeVariant<
1280 aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
1281 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001282}
1283
1284TEST_F(CompositionTest, REComposedNormalBufferLayer) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001285 displayRefreshCompositionDirtyFrame<CompositionCase<
1286 DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1287 ChangeCompositionTypeVariant<
1288 aidl::android::hardware::graphics::composer3::Composition::DEVICE,
1289 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1290 RECompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001291}
1292
1293TEST_F(CompositionTest, captureScreenNormalBufferLayer) {
1294 captureScreenComposition<
1295 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1296 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1297}
1298
1299/* ------------------------------------------------------------------------
1300 * Single-color layers
1301 */
1302
Vishnu Nairfa247b12020-02-11 08:58:26 -08001303TEST_F(CompositionTest, HWCComposedEffectLayerWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001304 displayRefreshCompositionDirtyGeometry<CompositionCase<
1305 DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
1306 KeepCompositionTypeVariant<
1307 aidl::android::hardware::graphics::composer3::Composition::SOLID_COLOR>,
1308 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001309}
1310
Vishnu Nairfa247b12020-02-11 08:58:26 -08001311TEST_F(CompositionTest, HWCComposedEffectLayerWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001312 displayRefreshCompositionDirtyFrame<CompositionCase<
1313 DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
1314 KeepCompositionTypeVariant<
1315 aidl::android::hardware::graphics::composer3::Composition::SOLID_COLOR>,
1316 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001317}
1318
Vishnu Nairfa247b12020-02-11 08:58:26 -08001319TEST_F(CompositionTest, REComposedEffectLayer) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001320 displayRefreshCompositionDirtyFrame<CompositionCase<
1321 DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
1322 ChangeCompositionTypeVariant<
1323 aidl::android::hardware::graphics::composer3::Composition::SOLID_COLOR,
1324 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1325 RECompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001326}
1327
Vishnu Nairfa247b12020-02-11 08:58:26 -08001328TEST_F(CompositionTest, captureScreenEffectLayer) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001329 captureScreenComposition<
Vishnu Nairfa247b12020-02-11 08:58:26 -08001330 CompositionCase<DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001331 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1332}
1333
1334/* ------------------------------------------------------------------------
1335 * Layers with sideband buffers
1336 */
1337
1338TEST_F(CompositionTest, HWCComposedSidebandBufferLayerWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001339 displayRefreshCompositionDirtyGeometry<CompositionCase<
1340 DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1341 KeepCompositionTypeVariant<
1342 aidl::android::hardware::graphics::composer3::Composition::SIDEBAND>,
1343 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001344}
1345
1346TEST_F(CompositionTest, HWCComposedSidebandBufferLayerWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001347 displayRefreshCompositionDirtyFrame<CompositionCase<
1348 DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1349 KeepCompositionTypeVariant<
1350 aidl::android::hardware::graphics::composer3::Composition::SIDEBAND>,
1351 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001352}
1353
1354TEST_F(CompositionTest, REComposedSidebandBufferLayer) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001355 displayRefreshCompositionDirtyFrame<CompositionCase<
1356 DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1357 ChangeCompositionTypeVariant<
1358 aidl::android::hardware::graphics::composer3::Composition::SIDEBAND,
1359 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1360 RECompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001361}
1362
1363TEST_F(CompositionTest, captureScreenSidebandBufferLayer) {
1364 captureScreenComposition<
1365 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1366 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1367}
1368
1369/* ------------------------------------------------------------------------
1370 * Layers with ISurfaceComposerClient::eSecure, on a secure display
1371 */
1372
1373TEST_F(CompositionTest, HWCComposedSecureBufferLayerWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001374 displayRefreshCompositionDirtyGeometry<CompositionCase<
1375 DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1376 KeepCompositionTypeVariant<
1377 aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
1378 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001379}
1380
1381TEST_F(CompositionTest, HWCComposedSecureBufferLayerWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001382 displayRefreshCompositionDirtyFrame<CompositionCase<
1383 DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1384 KeepCompositionTypeVariant<
1385 aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
1386 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001387}
1388
1389TEST_F(CompositionTest, REComposedSecureBufferLayer) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001390 displayRefreshCompositionDirtyFrame<CompositionCase<
1391 DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1392 ChangeCompositionTypeVariant<
1393 aidl::android::hardware::graphics::composer3::Composition::DEVICE,
1394 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1395 RECompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001396}
1397
1398TEST_F(CompositionTest, captureScreenSecureBufferLayerOnSecureDisplay) {
1399 captureScreenComposition<
1400 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1401 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1402}
1403
1404/* ------------------------------------------------------------------------
1405 * Layers with ISurfaceComposerClient::eSecure, on a non-secure display
1406 */
1407
1408TEST_F(CompositionTest, HWCComposedSecureBufferLayerOnInsecureDisplayWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001409 displayRefreshCompositionDirtyGeometry<CompositionCase<
1410 InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1411 KeepCompositionTypeVariant<
1412 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1413 ForcedClientCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001414}
1415
1416TEST_F(CompositionTest, HWCComposedSecureBufferLayerOnInsecureDisplayWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001417 displayRefreshCompositionDirtyFrame<CompositionCase<
1418 InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1419 KeepCompositionTypeVariant<
1420 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1421 ForcedClientCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001422}
1423
1424TEST_F(CompositionTest, captureScreenSecureBufferLayerOnInsecureDisplay) {
1425 captureScreenComposition<
1426 CompositionCase<InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1427 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1428}
1429
1430/* ------------------------------------------------------------------------
Garfield Tande619fa2020-10-02 17:13:53 -07001431 * Layers with a parent layer with ISurfaceComposerClient::eSecure, on a non-secure display
1432 */
1433
1434TEST_F(CompositionTest,
1435 HWCComposedBufferLayerWithSecureParentLayerOnInsecureDisplayWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001436 displayRefreshCompositionDirtyGeometry<CompositionCase<
1437 InsecureDisplaySetupVariant,
1438 ChildLayerVariant<BufferLayerVariant<ParentSecureLayerProperties>,
1439 ContainerLayerVariant<SecureLayerProperties>>,
1440 KeepCompositionTypeVariant<
1441 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1442 ForcedClientCompositionResultVariant>>();
Garfield Tande619fa2020-10-02 17:13:53 -07001443}
1444
1445TEST_F(CompositionTest,
1446 HWCComposedBufferLayerWithSecureParentLayerOnInsecureDisplayWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001447 displayRefreshCompositionDirtyFrame<CompositionCase<
1448 InsecureDisplaySetupVariant,
1449 ChildLayerVariant<BufferLayerVariant<ParentSecureLayerProperties>,
1450 ContainerLayerVariant<SecureLayerProperties>>,
1451 KeepCompositionTypeVariant<
1452 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1453 ForcedClientCompositionResultVariant>>();
Garfield Tande619fa2020-10-02 17:13:53 -07001454}
1455
1456TEST_F(CompositionTest, captureScreenBufferLayerWithSecureParentLayerOnInsecureDisplay) {
1457 captureScreenComposition<
1458 CompositionCase<InsecureDisplaySetupVariant,
1459 ChildLayerVariant<BufferLayerVariant<ParentSecureLayerProperties>,
1460 ContainerLayerVariant<SecureLayerProperties>>,
1461 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1462}
1463
1464/* ------------------------------------------------------------------------
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001465 * Cursor layers
1466 */
1467
1468TEST_F(CompositionTest, HWCComposedCursorLayerWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001469 displayRefreshCompositionDirtyGeometry<CompositionCase<
1470 DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1471 KeepCompositionTypeVariant<
1472 aidl::android::hardware::graphics::composer3::Composition::CURSOR>,
1473 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001474}
1475
1476TEST_F(CompositionTest, HWCComposedCursorLayerWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001477 displayRefreshCompositionDirtyFrame<CompositionCase<
1478 DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1479 KeepCompositionTypeVariant<
1480 aidl::android::hardware::graphics::composer3::Composition::CURSOR>,
1481 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001482}
1483
1484TEST_F(CompositionTest, REComposedCursorLayer) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001485 displayRefreshCompositionDirtyFrame<CompositionCase<
1486 DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1487 ChangeCompositionTypeVariant<
1488 aidl::android::hardware::graphics::composer3::Composition::CURSOR,
1489 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1490 RECompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001491}
1492
1493TEST_F(CompositionTest, captureScreenCursorLayer) {
1494 captureScreenComposition<
1495 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1496 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1497}
1498
1499/* ------------------------------------------------------------------------
1500 * Simple buffer layer on a display which is powered off.
1501 */
1502
1503TEST_F(CompositionTest, displayOffHWCComposedNormalBufferLayerWithDirtyGeometry) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001504 mDisplayOff = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001505 displayRefreshCompositionDirtyGeometry<CompositionCase<
1506 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001507 KeepCompositionTypeVariant<
1508 aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001509 HwcCompositionResultVariant>>();
1510}
1511
1512TEST_F(CompositionTest, displayOffHWCComposedNormalBufferLayerWithDirtyFrame) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001513 mDisplayOff = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001514 displayRefreshCompositionDirtyFrame<CompositionCase<
1515 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001516 KeepCompositionTypeVariant<
1517 aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001518 HwcCompositionResultVariant>>();
1519}
1520
1521TEST_F(CompositionTest, displayOffREComposedNormalBufferLayer) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001522 mDisplayOff = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001523 displayRefreshCompositionDirtyFrame<CompositionCase<
1524 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001525 ChangeCompositionTypeVariant<
1526 aidl::android::hardware::graphics::composer3::Composition::DEVICE,
1527 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001528 RECompositionResultVariant>>();
1529}
1530
1531TEST_F(CompositionTest, captureScreenNormalBufferLayerOnPoweredOffDisplay) {
1532 captureScreenComposition<CompositionCase<
1533 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1534 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1535}
1536
Lloyd Pique4fe29402019-08-12 16:51:24 -07001537/* ------------------------------------------------------------------------
1538 * Client composition forced through debug/developer settings
1539 */
1540
1541TEST_F(CompositionTest, DebugOptionForcingClientCompositionOfBufferLayerWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001542 displayRefreshCompositionDirtyGeometry<CompositionCase<
1543 DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1544 KeepCompositionTypeVariant<
1545 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1546 ForcedClientCompositionViaDebugOptionResultVariant>>();
Lloyd Pique4fe29402019-08-12 16:51:24 -07001547}
1548
1549TEST_F(CompositionTest, DebugOptionForcingClientCompositionOfBufferLayerWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001550 displayRefreshCompositionDirtyFrame<CompositionCase<
1551 DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1552 KeepCompositionTypeVariant<
1553 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1554 ForcedClientCompositionViaDebugOptionResultVariant>>();
Lloyd Pique4fe29402019-08-12 16:51:24 -07001555}
1556
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001557} // namespace
1558} // namespace android
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -08001559
1560// TODO(b/129481165): remove the #pragma below and fix conversion issues
Marin Shalamanovbed7fd32020-12-21 20:02:20 +01001561#pragma clang diagnostic pop // ignored "-Wconversion -Wextra"