blob: 77625b36ef5c05d7a253653d8bdaa622da34a097 [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>
Vishnu Nairdbbe3852022-01-12 20:22:11 -080033#include <renderengine/mock/FakeExternalTexture.h>
Lloyd Pique3823e7b2018-10-18 16:58:10 -070034#include <renderengine/mock/Framebuffer.h>
35#include <renderengine/mock/Image.h>
36#include <renderengine/mock/RenderEngine.h>
Lloyd Piqued6b579f2018-04-06 15:29:10 -070037#include <system/window.h>
38#include <utils/String8.h>
39
Marin Shalamanovf6b5d182020-06-12 02:08:51 +020040#include "DisplayRenderArea.h"
Vishnu Nairfa247b12020-02-11 08:58:26 -080041#include "EffectLayer.h"
Lloyd Piqued6b579f2018-04-06 15:29:10 -070042#include "Layer.h"
Lloyd Piqued6b579f2018-04-06 15:29:10 -070043#include "TestableSurfaceFlinger.h"
44#include "mock/DisplayHardware/MockComposer.h"
Lloyd Pique9370a482019-10-03 17:58:30 -070045#include "mock/DisplayHardware/MockPowerAdvisor.h"
Lloyd Piqued6b579f2018-04-06 15:29:10 -070046#include "mock/MockEventThread.h"
Alec Mourie4034bb2019-11-19 12:45:54 -080047#include "mock/MockTimeStats.h"
Ady Abraham8cb21882020-08-26 18:22:05 -070048#include "mock/MockVsyncController.h"
Alec Mouriba013fa2018-10-16 12:43:11 -070049#include "mock/system/window/MockNativeWindow.h"
Lloyd Piqued6b579f2018-04-06 15:29:10 -070050
51namespace android {
52namespace {
53
Peiyong Line9d809e2020-04-14 13:10:48 -070054namespace hal = android::hardware::graphics::composer::hal;
55
Peiyong Lin65248e02020-04-18 21:15:07 -070056using hal::Error;
57using hal::IComposer;
58using hal::IComposerClient;
59using hal::PowerMode;
60using hal::Transform;
61
Ady Abrahamde549d42022-01-26 19:19:17 -080062using aidl::android::hardware::graphics::composer3::Capability;
63
Lloyd Piqued6b579f2018-04-06 15:29:10 -070064using testing::_;
David Sodman15094112018-10-11 09:39:37 -070065using testing::AtLeast;
Lloyd Piqued6b579f2018-04-06 15:29:10 -070066using testing::DoAll;
67using testing::IsNull;
68using testing::Mock;
Lloyd Piqued6b579f2018-04-06 15:29:10 -070069using testing::Return;
70using testing::ReturnRef;
71using testing::SetArgPointee;
72
Lloyd Piqued6b579f2018-04-06 15:29:10 -070073using FakeHwcDisplayInjector = TestableSurfaceFlinger::FakeHwcDisplayInjector;
74using FakeDisplayDeviceInjector = TestableSurfaceFlinger::FakeDisplayDeviceInjector;
75
Peiyong Line9d809e2020-04-14 13:10:48 -070076constexpr hal::HWDisplayId HWC_DISPLAY = FakeHwcDisplayInjector::DEFAULT_HWC_DISPLAY_ID;
77constexpr hal::HWLayerId HWC_LAYER = 5000;
Lloyd Piqued6b579f2018-04-06 15:29:10 -070078constexpr Transform DEFAULT_TRANSFORM = static_cast<Transform>(0);
79
Dominik Laskowskif1833852021-03-23 15:06:50 -070080constexpr PhysicalDisplayId DEFAULT_DISPLAY_ID = PhysicalDisplayId::fromPort(42u);
Lloyd Piqued6b579f2018-04-06 15:29:10 -070081constexpr int DEFAULT_DISPLAY_WIDTH = 1920;
82constexpr int DEFAULT_DISPLAY_HEIGHT = 1024;
83
Lloyd Piqued6b579f2018-04-06 15:29:10 -070084constexpr int DEFAULT_TEXTURE_ID = 6000;
Dominik Laskowski29fa1462021-04-27 15:51:50 -070085constexpr ui::LayerStack LAYER_STACK{7000u};
Lloyd Piqued6b579f2018-04-06 15:29:10 -070086
87constexpr int DEFAULT_DISPLAY_MAX_LUMINANCE = 500;
88
89constexpr int DEFAULT_SIDEBAND_STREAM = 51;
90
Ady Abrahamdc011a92021-12-21 14:06:44 -080091MATCHER(IsIdentityMatrix, "") {
92 constexpr auto kIdentity = mat4();
93 return (mat4(arg) == kIdentity);
94}
95
Lloyd Piqued6b579f2018-04-06 15:29:10 -070096class CompositionTest : public testing::Test {
97public:
98 CompositionTest() {
99 const ::testing::TestInfo* const test_info =
100 ::testing::UnitTest::GetInstance()->current_test_info();
101 ALOGD("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name());
102
Ana Krulecafb45842019-02-13 13:33:03 -0800103 setupScheduler();
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700104
Alec Mourif6fd29e2018-11-17 04:56:41 +0000105 EXPECT_CALL(*mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
106 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_WIDTH), Return(0)));
107 EXPECT_CALL(*mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
108 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_HEIGHT), Return(0)));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700109
110 mFlinger.setupRenderEngine(std::unique_ptr<renderengine::RenderEngine>(mRenderEngine));
Alec Mourie4034bb2019-11-19 12:45:54 -0800111 mFlinger.setupTimeStats(std::shared_ptr<TimeStats>(mTimeStats));
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800112
113 mComposer = new Hwc2::mock::Composer();
Xiang Wang839fe5b2022-04-04 17:39:38 +0000114 mPowerAdvisor = new Hwc2::mock::PowerAdvisor();
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800115 mFlinger.setupComposer(std::unique_ptr<Hwc2::Composer>(mComposer));
Xiang Wang839fe5b2022-04-04 17:39:38 +0000116 mFlinger.setupPowerAdvisor(std::unique_ptr<Hwc2::PowerAdvisor>(mPowerAdvisor));
Garfield Tan9c9c1912021-07-19 12:02:16 -0700117 mFlinger.mutableMaxRenderTargetSize() = 16384;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700118 }
119
120 ~CompositionTest() {
121 const ::testing::TestInfo* const test_info =
122 ::testing::UnitTest::GetInstance()->current_test_info();
123 ALOGD("**** Tearing down after %s.%s\n", test_info->test_case_name(), test_info->name());
124 }
125
Ana Krulecafb45842019-02-13 13:33:03 -0800126 void setupScheduler() {
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700127 auto eventThread = std::make_unique<mock::EventThread>();
128 auto sfEventThread = std::make_unique<mock::EventThread>();
Ana Krulecafb45842019-02-13 13:33:03 -0800129
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700130 EXPECT_CALL(*eventThread, registerDisplayEventConnection(_));
Dominik Laskowski98041832019-08-01 18:35:59 -0700131 EXPECT_CALL(*eventThread, createEventConnection(_, _))
Ady Abrahamd11bade2022-08-01 16:18:03 -0700132 .WillOnce(Return(sp<EventThreadConnection>::make(eventThread.get(),
133 mock::EventThread::kCallingUid,
134 ResyncCallback())));
Dominik Laskowski98041832019-08-01 18:35:59 -0700135
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700136 EXPECT_CALL(*sfEventThread, registerDisplayEventConnection(_));
Dominik Laskowski98041832019-08-01 18:35:59 -0700137 EXPECT_CALL(*sfEventThread, createEventConnection(_, _))
Ady Abrahamd11bade2022-08-01 16:18:03 -0700138 .WillOnce(Return(sp<EventThreadConnection>::make(sfEventThread.get(),
139 mock::EventThread::kCallingUid,
140 ResyncCallback())));
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700141
Ady Abraham8cb21882020-08-26 18:22:05 -0700142 auto vsyncController = std::make_unique<mock::VsyncController>();
143 auto vsyncTracker = std::make_unique<mock::VSyncTracker>();
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700144
Ady Abraham8cb21882020-08-26 18:22:05 -0700145 EXPECT_CALL(*vsyncTracker, nextAnticipatedVSyncTimeFrom(_)).WillRepeatedly(Return(0));
146 EXPECT_CALL(*vsyncTracker, currentPeriod())
Marin Shalamanov045b7002021-01-07 16:56:24 +0100147 .WillRepeatedly(Return(FakeHwcDisplayInjector::DEFAULT_VSYNC_PERIOD));
Ady Abraham8cb21882020-08-26 18:22:05 -0700148 EXPECT_CALL(*vsyncTracker, nextAnticipatedVSyncTimeFrom(_)).WillRepeatedly(Return(0));
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700149
Ady Abraham8cb21882020-08-26 18:22:05 -0700150 mFlinger.setupScheduler(std::move(vsyncController), std::move(vsyncTracker),
Dominik Laskowski83bd7712022-01-07 14:30:53 -0800151 std::move(eventThread), std::move(sfEventThread),
152 TestableSurfaceFlinger::SchedulerCallbackImpl::kNoOp,
153 TestableSurfaceFlinger::kTwoDisplayModes);
Ana Krulecafb45842019-02-13 13:33:03 -0800154 }
155
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700156 void setupForceGeometryDirty() {
157 // TODO: This requires the visible region and other related
158 // state to be set, and is problematic for BufferLayers since they are
159 // not visible without a buffer (and setting up a buffer looks like a
160 // pain)
161 // mFlinger.mutableVisibleRegionsDirty() = true;
162
Dominik Laskowski8da6b0e2021-05-12 15:34:13 -0700163 mFlinger.mutableGeometryDirty() = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700164 }
165
166 template <typename Case>
167 void displayRefreshCompositionDirtyGeometry();
168
169 template <typename Case>
170 void displayRefreshCompositionDirtyFrame();
171
172 template <typename Case>
173 void captureScreenComposition();
174
Ady Abrahamde549d42022-01-26 19:19:17 -0800175 std::unordered_set<Capability> mDefaultCapabilities = {Capability::SIDEBAND_STREAM};
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700176
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800177 bool mDisplayOff = false;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700178 TestableSurfaceFlinger mFlinger;
179 sp<DisplayDevice> mDisplay;
180 sp<DisplayDevice> mExternalDisplay;
Lloyd Pique542307f2018-10-19 13:24:08 -0700181 sp<compositionengine::mock::DisplaySurface> mDisplaySurface =
Ady Abrahamd11bade2022-08-01 16:18:03 -0700182 sp<compositionengine::mock::DisplaySurface>::make();
183 sp<mock::NativeWindow> mNativeWindow = sp<mock::NativeWindow>::make();
Garfield Tande619fa2020-10-02 17:13:53 -0700184 std::vector<sp<Layer>> mAuxiliaryLayers;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700185
Ady Abrahamd11bade2022-08-01 16:18:03 -0700186 sp<GraphicBuffer> mBuffer = sp<GraphicBuffer>::make();
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800187 ANativeWindowBuffer* mNativeWindowBuffer = mBuffer->getNativeBuffer();
188
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700189 Hwc2::mock::Composer* mComposer = nullptr;
190 renderengine::mock::RenderEngine* mRenderEngine = new renderengine::mock::RenderEngine();
Alec Mourie4034bb2019-11-19 12:45:54 -0800191 mock::TimeStats* mTimeStats = new mock::TimeStats();
Xiang Wang839fe5b2022-04-04 17:39:38 +0000192 Hwc2::mock::PowerAdvisor* mPowerAdvisor = nullptr;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700193
194 sp<Fence> mClientTargetAcquireFence = Fence::NO_FENCE;
195
Alec Mouria90a5702021-04-16 16:36:21 +0000196 std::shared_ptr<renderengine::ExternalTexture> mCaptureScreenBuffer;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700197};
198
199template <typename LayerCase>
200void CompositionTest::displayRefreshCompositionDirtyGeometry() {
201 setupForceGeometryDirty();
202 LayerCase::setupForDirtyGeometry(this);
203
204 // --------------------------------------------------------------------
205 // Invocation
206
Dominik Laskowskie0e0cde2021-07-30 10:42:05 -0700207 mFlinger.commitAndComposite();
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700208
209 LayerCase::cleanup(this);
210}
211
212template <typename LayerCase>
213void CompositionTest::displayRefreshCompositionDirtyFrame() {
214 LayerCase::setupForDirtyFrame(this);
215
216 // --------------------------------------------------------------------
217 // Invocation
218
Dominik Laskowskie0e0cde2021-07-30 10:42:05 -0700219 mFlinger.commitAndComposite();
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700220
221 LayerCase::cleanup(this);
222}
223
224template <typename LayerCase>
225void CompositionTest::captureScreenComposition() {
226 LayerCase::setupForScreenCapture(this);
227
228 const Rect sourceCrop(0, 0, DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700229 constexpr bool forSystem = true;
Lucas Dupin9d763b72020-04-20 18:42:31 -0700230 constexpr bool regionSampling = false;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700231
Marin Shalamanov1c434292020-06-12 01:47:29 +0200232 auto renderArea = DisplayRenderArea::create(mDisplay, sourceCrop, sourceCrop.getSize(),
233 ui::Dataspace::V0_SRGB, ui::Transform::ROT_0);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700234
235 auto traverseLayers = [this](const LayerVector::Visitor& visitor) {
chaviw4b9d5e12020-08-04 18:30:35 -0700236 return mFlinger.traverseLayersInLayerStack(mDisplay->getLayerStack(),
237 CaptureArgs::UNSET_UID, visitor);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700238 };
239
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700240 const uint32_t usage = GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN |
241 GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_TEXTURE;
Vishnu Nairdbbe3852022-01-12 20:22:11 -0800242 mCaptureScreenBuffer =
243 std::make_shared<renderengine::mock::FakeExternalTexture>(renderArea->getReqWidth(),
244 renderArea->getReqHeight(),
245 HAL_PIXEL_FORMAT_RGBA_8888, 1,
246 usage);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700247
Dominik Laskowskibb448ce2022-05-07 15:52:55 -0700248 auto future = mFlinger.renderScreenImpl(*renderArea, traverseLayers, mCaptureScreenBuffer,
Robert Carr12a3b9b2022-03-10 09:55:29 -0800249 forSystem, regionSampling);
Dominik Laskowskibb448ce2022-05-07 15:52:55 -0700250 ASSERT_TRUE(future.valid());
251 const auto fenceResult = future.get();
Sally Qi59a9f502021-10-12 18:53:23 +0000252
Dominik Laskowskibb448ce2022-05-07 15:52:55 -0700253 EXPECT_EQ(NO_ERROR, fenceStatus(fenceResult));
254 if (fenceResult.ok()) {
255 fenceResult.value()->waitForever(LOG_TAG);
Sally Qi59a9f502021-10-12 18:53:23 +0000256 }
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)
Xiang Wang839fe5b2022-04-04 17:39:38 +0000303 .setPowerAdvisor(test->mPowerAdvisor)
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800304 .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();
Ady Abrahamd11bade2022-08-01 16:18:03 -0700320 Mock::VerifyAndClear(test->mNativeWindow.get());
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>&,
Patrick Williams2e9748f2022-08-09 22:48:18 +0000354 const bool, base::unique_fd&&) -> std::future<FenceResult> {
Lloyd Pique9370a482019-10-03 17:58:30 -0700355 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
356 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
357 displaySettings.physicalDisplay);
358 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
359 displaySettings.clip);
Patrick Williams2e9748f2022-08-09 22:48:18 +0000360 return futureOf<FenceResult>(Fence::NO_FENCE);
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>&,
Patrick Williams2e9748f2022-08-09 22:48:18 +0000405 const bool, base::unique_fd&&) -> std::future<FenceResult> {
Lloyd Pique9370a482019-10-03 17:58:30 -0700406 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
407 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
408 displaySettings.physicalDisplay);
409 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
410 displaySettings.clip);
411 EXPECT_EQ(ui::Dataspace::UNKNOWN, displaySettings.outputDataspace);
Patrick Williams2e9748f2022-08-09 22:48:18 +0000412 return futureOf<FenceResult>(Fence::NO_FENCE);
Lloyd Pique9370a482019-10-03 17:58:30 -0700413 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700414 }
415
416 template <typename Case>
417 static void setupRELayerCompositionCallExpectations(CompositionTest* test) {
418 Case::Layer::setupRECompositionCallExpectations(test);
419 }
420
421 template <typename Case>
422 static void setupRELayerScreenshotCompositionCallExpectations(CompositionTest* test) {
423 Case::Layer::setupREScreenshotCompositionCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700424 }
425};
426
427struct DefaultDisplaySetupVariant : public BaseDisplayVariant<DefaultDisplaySetupVariant> {};
428
429struct InsecureDisplaySetupVariant : public BaseDisplayVariant<InsecureDisplaySetupVariant> {
430 static constexpr bool IS_SECURE = false;
431
432 template <typename Case>
433 static void setupRELayerCompositionCallExpectations(CompositionTest* test) {
434 Case::Layer::setupInsecureRECompositionCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700435 }
436
437 template <typename Case>
438 static void setupRELayerScreenshotCompositionCallExpectations(CompositionTest* test) {
439 Case::Layer::setupInsecureREScreenshotCompositionCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700440 }
441};
442
443struct PoweredOffDisplaySetupVariant : public BaseDisplayVariant<PoweredOffDisplaySetupVariant> {
Peiyong Lin65248e02020-04-18 21:15:07 -0700444 static constexpr hal::PowerMode INIT_POWER_MODE = hal::PowerMode::OFF;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700445
446 template <typename Case>
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700447 static void setupPreconditionCallExpectations(CompositionTest*) {}
448
449 template <typename Case>
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700450 static void setupCommonCompositionCallExpectations(CompositionTest* test) {
451 // TODO: This seems like an unnecessary call if display is powered off.
Ady Abrahamdc011a92021-12-21 14:06:44 -0800452 EXPECT_CALL(*test->mComposer, setColorTransform(HWC_DISPLAY, IsIdentityMatrix())).Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700453
454 // TODO: This seems like an unnecessary call if display is powered off.
455 Case::CompositionType::setupHwcSetCallExpectations(test);
456 }
457
458 static void setupHwcCompositionCallExpectations(CompositionTest*) {}
Lloyd Pique66d68602019-02-13 14:23:31 -0800459 static void setupHwcClientCompositionCallExpectations(CompositionTest*) {}
460 static void setupHwcForcedClientCompositionCallExpectations(CompositionTest*) {}
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700461
462 static void setupRECompositionCallExpectations(CompositionTest* test) {
463 // TODO: This seems like an unnecessary call if display is powered off.
464 EXPECT_CALL(*test->mDisplaySurface, getClientTargetAcquireFence())
465 .WillRepeatedly(ReturnRef(test->mClientTargetAcquireFence));
466 }
467
468 template <typename Case>
469 static void setupRELayerCompositionCallExpectations(CompositionTest*) {}
470};
471
472/* ------------------------------------------------------------------------
473 * Variants for each layer configuration which can be tested
474 */
475
476template <typename LayerProperties>
477struct BaseLayerProperties {
478 static constexpr uint32_t WIDTH = 100;
479 static constexpr uint32_t HEIGHT = 100;
480 static constexpr PixelFormat FORMAT = PIXEL_FORMAT_RGBA_8888;
481 static constexpr uint64_t USAGE =
482 GraphicBuffer::USAGE_SW_READ_NEVER | GraphicBuffer::USAGE_SW_WRITE_NEVER;
483 static constexpr android_dataspace DATASPACE = HAL_DATASPACE_UNKNOWN;
484 static constexpr uint32_t SCALING_MODE = 0;
485 static constexpr uint32_t TRANSFORM = 0;
486 static constexpr uint32_t LAYER_FLAGS = 0;
487 static constexpr float COLOR[] = {1.f, 1.f, 1.f, 1.f};
488 static constexpr IComposerClient::BlendMode BLENDMODE =
489 IComposerClient::BlendMode::PREMULTIPLIED;
490
Vishnu Nairf8a873a2022-06-15 17:34:34 +0000491 static void setupLatchedBuffer(CompositionTest* test, sp<BufferStateLayer> layer) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700492 Mock::VerifyAndClear(test->mRenderEngine);
493
Vishnu Nairf8a873a2022-06-15 17:34:34 +0000494 const auto buffer = std::make_shared<
495 renderengine::mock::FakeExternalTexture>(LayerProperties::WIDTH,
496 LayerProperties::HEIGHT,
497 DEFAULT_TEXTURE_ID,
498 LayerProperties::FORMAT,
499 LayerProperties::USAGE |
500 GraphicBuffer::USAGE_HW_TEXTURE);
501
502 auto& layerDrawingState = test->mFlinger.mutableLayerDrawingState(layer);
503 layerDrawingState.crop = Rect(0, 0, LayerProperties::HEIGHT, LayerProperties::WIDTH);
504 layerDrawingState.buffer = buffer;
505 layerDrawingState.acquireFence = Fence::NO_FENCE;
506 layerDrawingState.dataspace = ui::Dataspace::UNKNOWN;
507 layer->setSurfaceDamageRegion(
508 Region(Rect(LayerProperties::HEIGHT, LayerProperties::WIDTH)));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700509
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700510 bool ignoredRecomputeVisibleRegions;
Vishnu Nair397a0e32022-07-26 00:01:48 +0000511 layer->latchBuffer(ignoredRecomputeVisibleRegions, 0);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700512 Mock::VerifyAndClear(test->mRenderEngine);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700513 }
514
Vishnu Nairf8a873a2022-06-15 17:34:34 +0000515 static void setupLayerState(CompositionTest* test, sp<BufferStateLayer> layer) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700516 setupLatchedBuffer(test, layer);
517 }
518
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700519 static void setupHwcSetGeometryCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800520 if (!test->mDisplayOff) {
521 // TODO: Coverage of other values
522 EXPECT_CALL(*test->mComposer,
523 setLayerBlendMode(HWC_DISPLAY, HWC_LAYER, LayerProperties::BLENDMODE))
524 .Times(1);
525 // TODO: Coverage of other values for origin
526 EXPECT_CALL(*test->mComposer,
527 setLayerDisplayFrame(HWC_DISPLAY, HWC_LAYER,
528 IComposerClient::Rect({0, 0, LayerProperties::WIDTH,
529 LayerProperties::HEIGHT})))
530 .Times(1);
531 EXPECT_CALL(*test->mComposer,
532 setLayerPlaneAlpha(HWC_DISPLAY, HWC_LAYER, LayerProperties::COLOR[3]))
533 .Times(1);
534 // TODO: Coverage of other values
535 EXPECT_CALL(*test->mComposer, setLayerZOrder(HWC_DISPLAY, HWC_LAYER, 0u)).Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700536
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800537 // These expectations retire on saturation as the code path these
538 // expectations are for appears to make an extra call to them.
539 // TODO: Investigate this extra call
540 EXPECT_CALL(*test->mComposer,
541 setLayerTransform(HWC_DISPLAY, HWC_LAYER, DEFAULT_TRANSFORM))
542 .Times(AtLeast(1))
543 .RetiresOnSaturation();
544 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700545 }
546
547 static void setupHwcSetSourceCropBufferCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800548 if (!test->mDisplayOff) {
549 EXPECT_CALL(*test->mComposer,
550 setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER,
551 IComposerClient::FRect({0.f, 0.f, LayerProperties::WIDTH,
552 LayerProperties::HEIGHT})))
553 .Times(1);
554 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700555 }
556
557 static void setupHwcSetSourceCropColorCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800558 if (!test->mDisplayOff) {
559 EXPECT_CALL(*test->mComposer,
560 setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER,
561 IComposerClient::FRect({0.f, 0.f, 0.f, 0.f})))
562 .Times(1);
563 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700564 }
565
566 static void setupHwcSetPerFrameCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800567 if (!test->mDisplayOff) {
568 EXPECT_CALL(*test->mComposer,
569 setLayerVisibleRegion(HWC_DISPLAY, HWC_LAYER,
570 std::vector<IComposerClient::Rect>(
571 {IComposerClient::Rect(
572 {0, 0, LayerProperties::WIDTH,
573 LayerProperties::HEIGHT})})))
574 .Times(1);
575 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700576 }
577
578 static void setupHwcSetPerFrameColorCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800579 if (!test->mDisplayOff) {
580 EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _))
581 .Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700582
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800583 // TODO: use COLOR
584 EXPECT_CALL(*test->mComposer,
585 setLayerColor(HWC_DISPLAY, HWC_LAYER,
Ady Abraham6e60b142022-01-06 18:10:35 -0800586 aidl::android::hardware::graphics::composer3::Color(
587 {1.0f, 1.0f, 1.0f, 1.0f})))
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800588 .Times(1);
589 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700590 }
591
592 static void setupHwcSetPerFrameBufferCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800593 if (!test->mDisplayOff) {
594 EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _))
595 .Times(1);
596 EXPECT_CALL(*test->mComposer, setLayerBuffer(HWC_DISPLAY, HWC_LAYER, _, _, _)).Times(1);
597 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700598 }
599
600 static void setupREBufferCompositionCommonCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000601 EXPECT_CALL(*test->mRenderEngine, drawLayers)
Sally Qi4cabdd02021-08-05 16:45:57 -0700602 .WillOnce([&](const renderengine::DisplaySettings& displaySettings,
Sally Qi59a9f502021-10-12 18:53:23 +0000603 const std::vector<renderengine::LayerSettings>& layerSettings,
Sally Qi4cabdd02021-08-05 16:45:57 -0700604 const std::shared_ptr<renderengine::ExternalTexture>&, const bool,
Patrick Williams2e9748f2022-08-09 22:48:18 +0000605 base::unique_fd&&) -> std::future<FenceResult> {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000606 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
607 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
608 displaySettings.physicalDisplay);
609 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
610 displaySettings.clip);
611 // screen capture adds an additional color layer as an alpha
612 // prefill, so gtet the back layer.
Patrick Williams2e9748f2022-08-09 22:48:18 +0000613 std::future<FenceResult> resultFuture = futureOf<FenceResult>(Fence::NO_FENCE);
Lloyd Piquea2468662019-03-07 21:31:06 -0800614 if (layerSettings.empty()) {
615 ADD_FAILURE() << "layerSettings was not expected to be empty in "
616 "setupREBufferCompositionCommonCallExpectations "
617 "verification lambda";
Sally Qi4cabdd02021-08-05 16:45:57 -0700618 return resultFuture;
Lloyd Piquea2468662019-03-07 21:31:06 -0800619 }
Sally Qi59a9f502021-10-12 18:53:23 +0000620 const renderengine::LayerSettings layer = layerSettings.back();
621 EXPECT_THAT(layer.source.buffer.buffer, Not(IsNull()));
622 EXPECT_THAT(layer.source.buffer.fence, Not(IsNull()));
623 EXPECT_EQ(DEFAULT_TEXTURE_ID, layer.source.buffer.textureName);
624 EXPECT_EQ(false, layer.source.buffer.isY410BT2020);
625 EXPECT_EQ(true, layer.source.buffer.usePremultipliedAlpha);
626 EXPECT_EQ(false, layer.source.buffer.isOpaque);
Vishnu Nair50c0afe2022-07-11 15:04:07 -0700627 EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius.x);
628 EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius.y);
Sally Qi59a9f502021-10-12 18:53:23 +0000629 EXPECT_EQ(ui::Dataspace::UNKNOWN, layer.sourceDataspace);
630 EXPECT_EQ(LayerProperties::COLOR[3], layer.alpha);
Sally Qi4cabdd02021-08-05 16:45:57 -0700631 return resultFuture;
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000632 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700633 }
634
635 static void setupREBufferCompositionCallExpectations(CompositionTest* test) {
636 LayerProperties::setupREBufferCompositionCommonCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700637 }
638
639 static void setupInsecureREBufferCompositionCallExpectations(CompositionTest* test) {
640 setupREBufferCompositionCallExpectations(test);
641 }
642
643 static void setupREBufferScreenshotCompositionCallExpectations(CompositionTest* test) {
644 LayerProperties::setupREBufferCompositionCommonCallExpectations(test);
645 }
646
647 static void setupInsecureREBufferScreenshotCompositionCallExpectations(CompositionTest* test) {
648 LayerProperties::setupREBufferCompositionCommonCallExpectations(test);
649 }
650
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700651 static void setupREColorCompositionCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000652 EXPECT_CALL(*test->mRenderEngine, drawLayers)
Sally Qi4cabdd02021-08-05 16:45:57 -0700653 .WillOnce([&](const renderengine::DisplaySettings& displaySettings,
Sally Qi59a9f502021-10-12 18:53:23 +0000654 const std::vector<renderengine::LayerSettings>& layerSettings,
Sally Qi4cabdd02021-08-05 16:45:57 -0700655 const std::shared_ptr<renderengine::ExternalTexture>&, const bool,
Patrick Williams2e9748f2022-08-09 22:48:18 +0000656 base::unique_fd&&) -> std::future<FenceResult> {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000657 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
658 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
659 displaySettings.physicalDisplay);
660 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
661 displaySettings.clip);
662 // screen capture adds an additional color layer as an alpha
663 // prefill, so get the back layer.
Patrick Williams2e9748f2022-08-09 22:48:18 +0000664 std::future<FenceResult> resultFuture = futureOf<FenceResult>(Fence::NO_FENCE);
Lloyd Piquea2468662019-03-07 21:31:06 -0800665 if (layerSettings.empty()) {
666 ADD_FAILURE()
667 << "layerSettings was not expected to be empty in "
668 "setupREColorCompositionCallExpectations verification lambda";
Sally Qi4cabdd02021-08-05 16:45:57 -0700669 return resultFuture;
Lloyd Piquea2468662019-03-07 21:31:06 -0800670 }
Sally Qi59a9f502021-10-12 18:53:23 +0000671 const renderengine::LayerSettings layer = layerSettings.back();
672 EXPECT_THAT(layer.source.buffer.buffer, IsNull());
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000673 EXPECT_EQ(half3(LayerProperties::COLOR[0], LayerProperties::COLOR[1],
674 LayerProperties::COLOR[2]),
Sally Qi59a9f502021-10-12 18:53:23 +0000675 layer.source.solidColor);
Vishnu Nair50c0afe2022-07-11 15:04:07 -0700676 EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius.x);
677 EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius.y);
Sally Qi59a9f502021-10-12 18:53:23 +0000678 EXPECT_EQ(ui::Dataspace::UNKNOWN, layer.sourceDataspace);
679 EXPECT_EQ(LayerProperties::COLOR[3], layer.alpha);
Sally Qi4cabdd02021-08-05 16:45:57 -0700680 return resultFuture;
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000681 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700682 }
683
684 static void setupREColorScreenshotCompositionCallExpectations(CompositionTest* test) {
685 setupREColorCompositionCallExpectations(test);
686 }
687};
688
689struct DefaultLayerProperties : public BaseLayerProperties<DefaultLayerProperties> {};
690
Vishnu Nairfa247b12020-02-11 08:58:26 -0800691struct EffectLayerProperties : public BaseLayerProperties<EffectLayerProperties> {
Alec Mourida8a9d12020-01-30 20:00:31 -0800692 static constexpr IComposerClient::BlendMode BLENDMODE = IComposerClient::BlendMode::NONE;
693};
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700694
695struct SidebandLayerProperties : public BaseLayerProperties<SidebandLayerProperties> {
696 using Base = BaseLayerProperties<SidebandLayerProperties>;
697 static constexpr IComposerClient::BlendMode BLENDMODE = IComposerClient::BlendMode::NONE;
698
Vishnu Nairf8a873a2022-06-15 17:34:34 +0000699 static void setupLayerState(CompositionTest* test, sp<BufferStateLayer> layer) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700700 sp<NativeHandle> stream =
701 NativeHandle::create(reinterpret_cast<native_handle_t*>(DEFAULT_SIDEBAND_STREAM),
702 false);
703 test->mFlinger.setLayerSidebandStream(layer, stream);
704 }
705
706 static void setupHwcSetSourceCropBufferCallExpectations(CompositionTest* test) {
707 EXPECT_CALL(*test->mComposer,
708 setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER,
709 IComposerClient::FRect({0.f, 0.f, -1.f, -1.f})))
710 .Times(1);
711 }
712
713 static void setupHwcSetPerFrameBufferCallExpectations(CompositionTest* test) {
714 EXPECT_CALL(*test->mComposer,
715 setLayerSidebandStream(HWC_DISPLAY, HWC_LAYER,
716 reinterpret_cast<native_handle_t*>(
717 DEFAULT_SIDEBAND_STREAM)))
718 .WillOnce(Return(Error::NONE));
719
720 EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _)).Times(1);
721 }
722
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000723 static void setupREBufferCompositionCommonCallExpectations(CompositionTest* /*test*/) {}
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700724};
725
Garfield Tande619fa2020-10-02 17:13:53 -0700726template <typename LayerProperties>
727struct CommonSecureLayerProperties : public BaseLayerProperties<LayerProperties> {
728 using Base = BaseLayerProperties<LayerProperties>;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700729
730 static void setupInsecureREBufferCompositionCommonCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000731 EXPECT_CALL(*test->mRenderEngine, drawLayers)
Sally Qi4cabdd02021-08-05 16:45:57 -0700732 .WillOnce([&](const renderengine::DisplaySettings& displaySettings,
Sally Qi59a9f502021-10-12 18:53:23 +0000733 const std::vector<renderengine::LayerSettings>& layerSettings,
Sally Qi4cabdd02021-08-05 16:45:57 -0700734 const std::shared_ptr<renderengine::ExternalTexture>&, const bool,
Patrick Williams2e9748f2022-08-09 22:48:18 +0000735 base::unique_fd&&) -> std::future<FenceResult> {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000736 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
737 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
738 displaySettings.physicalDisplay);
739 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
740 displaySettings.clip);
741 // screen capture adds an additional color layer as an alpha
742 // prefill, so get the back layer.
Patrick Williams2e9748f2022-08-09 22:48:18 +0000743 std::future<FenceResult> resultFuture = futureOf<FenceResult>(Fence::NO_FENCE);
Lloyd Piquea2468662019-03-07 21:31:06 -0800744 if (layerSettings.empty()) {
745 ADD_FAILURE() << "layerSettings was not expected to be empty in "
746 "setupInsecureREBufferCompositionCommonCallExpectations "
747 "verification lambda";
Sally Qi4cabdd02021-08-05 16:45:57 -0700748 return resultFuture;
Lloyd Piquea2468662019-03-07 21:31:06 -0800749 }
Sally Qi59a9f502021-10-12 18:53:23 +0000750 const renderengine::LayerSettings layer = layerSettings.back();
751 EXPECT_THAT(layer.source.buffer.buffer, IsNull());
752 EXPECT_EQ(half3(0.0f, 0.0f, 0.0f), layer.source.solidColor);
Vishnu Nair50c0afe2022-07-11 15:04:07 -0700753 EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius.x);
754 EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius.y);
Sally Qi59a9f502021-10-12 18:53:23 +0000755 EXPECT_EQ(ui::Dataspace::UNKNOWN, layer.sourceDataspace);
756 EXPECT_EQ(1.0f, layer.alpha);
Sally Qi4cabdd02021-08-05 16:45:57 -0700757 return resultFuture;
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000758 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700759 }
760
761 static void setupInsecureREBufferCompositionCallExpectations(CompositionTest* test) {
762 setupInsecureREBufferCompositionCommonCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700763 }
764
765 static void setupInsecureREBufferScreenshotCompositionCallExpectations(CompositionTest* test) {
766 setupInsecureREBufferCompositionCommonCallExpectations(test);
767 }
768};
769
Garfield Tande619fa2020-10-02 17:13:53 -0700770struct ParentSecureLayerProperties
771 : public CommonSecureLayerProperties<ParentSecureLayerProperties> {};
772
773struct SecureLayerProperties : public CommonSecureLayerProperties<SecureLayerProperties> {
774 static constexpr uint32_t LAYER_FLAGS = ISurfaceComposerClient::eSecure;
775};
776
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700777struct CursorLayerProperties : public BaseLayerProperties<CursorLayerProperties> {
778 using Base = BaseLayerProperties<CursorLayerProperties>;
779
Vishnu Nairf8a873a2022-06-15 17:34:34 +0000780 static void setupLayerState(CompositionTest* test, sp<BufferStateLayer> layer) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700781 Base::setupLayerState(test, layer);
782 test->mFlinger.setLayerPotentialCursor(layer, true);
783 }
784};
785
786struct NoLayerVariant {
Vishnu Nairf8a873a2022-06-15 17:34:34 +0000787 using FlingerLayerType = sp<BufferStateLayer>;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700788
789 static FlingerLayerType createLayer(CompositionTest*) { return FlingerLayerType(); }
790 static void injectLayer(CompositionTest*, FlingerLayerType) {}
791 static void cleanupInjectedLayers(CompositionTest*) {}
792
793 static void setupCallExpectationsForDirtyGeometry(CompositionTest*) {}
794 static void setupCallExpectationsForDirtyFrame(CompositionTest*) {}
795};
796
797template <typename LayerProperties>
798struct BaseLayerVariant {
799 template <typename L, typename F>
800 static sp<L> createLayerWithFactory(CompositionTest* test, F factory) {
Dominik Laskowski756b7892021-08-04 12:53:59 -0700801 EXPECT_CALL(*test->mFlinger.scheduler(), postMessage(_)).Times(0);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700802
803 sp<L> layer = factory();
804
Dominik Laskowski49cea512019-11-12 14:13:23 -0800805 // Layer should be registered with scheduler.
Dominik Laskowski9c93d602021-10-07 19:38:26 -0700806 EXPECT_EQ(1u, test->mFlinger.scheduler()->layerHistorySize());
Dominik Laskowski49cea512019-11-12 14:13:23 -0800807
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700808 Mock::VerifyAndClear(test->mComposer);
809 Mock::VerifyAndClear(test->mRenderEngine);
Dominik Laskowski756b7892021-08-04 12:53:59 -0700810 Mock::VerifyAndClearExpectations(test->mFlinger.scheduler());
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700811
Garfield Tande619fa2020-10-02 17:13:53 -0700812 initLayerDrawingStateAndComputeBounds(test, layer);
813
814 return layer;
815 }
816
817 template <typename L>
818 static void initLayerDrawingStateAndComputeBounds(CompositionTest* test, sp<L> layer) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700819 auto& layerDrawingState = test->mFlinger.mutableLayerDrawingState(layer);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700820 layerDrawingState.layerStack = LAYER_STACK;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700821 layerDrawingState.color = half4(LayerProperties::COLOR[0], LayerProperties::COLOR[1],
822 LayerProperties::COLOR[2], LayerProperties::COLOR[3]);
Vishnu Nairc97b8db2019-10-29 18:19:35 -0700823 layer->computeBounds(FloatRect(0, 0, 100, 100), ui::Transform(), 0.f /* shadowRadius */);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700824 }
825
826 static void injectLayer(CompositionTest* test, sp<Layer> layer) {
827 EXPECT_CALL(*test->mComposer, createLayer(HWC_DISPLAY, _))
828 .WillOnce(DoAll(SetArgPointee<1>(HWC_LAYER), Return(Error::NONE)));
829
Lloyd Piquede196652020-01-22 17:29:58 -0800830 auto outputLayer = test->mDisplay->getCompositionDisplay()->injectOutputLayerForTest(
831 layer->getCompositionEngineLayerFE());
Lloyd Pique01c77c12019-04-17 12:48:32 -0700832 outputLayer->editState().visibleRegion = Region(Rect(0, 0, 100, 100));
833 outputLayer->editState().outputSpaceVisibleRegion = Region(Rect(0, 0, 100, 100));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700834
835 Mock::VerifyAndClear(test->mComposer);
836
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700837 test->mFlinger.mutableDrawingState().layersSortedByZ.add(layer);
838 }
839
840 static void cleanupInjectedLayers(CompositionTest* test) {
841 EXPECT_CALL(*test->mComposer, destroyLayer(HWC_DISPLAY, HWC_LAYER))
842 .WillOnce(Return(Error::NONE));
Lloyd Pique37c2c9b2018-12-04 17:25:10 -0800843
Lloyd Pique01c77c12019-04-17 12:48:32 -0700844 test->mDisplay->getCompositionDisplay()->clearOutputLayers();
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700845 test->mFlinger.mutableDrawingState().layersSortedByZ.clear();
Dominik Laskowski49cea512019-11-12 14:13:23 -0800846
847 // Layer should be unregistered with scheduler.
Dominik Laskowskie0e0cde2021-07-30 10:42:05 -0700848 test->mFlinger.commit();
Dominik Laskowski9c93d602021-10-07 19:38:26 -0700849 EXPECT_EQ(0u, test->mFlinger.scheduler()->layerHistorySize());
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700850 }
851};
852
853template <typename LayerProperties>
Vishnu Nairfa247b12020-02-11 08:58:26 -0800854struct EffectLayerVariant : public BaseLayerVariant<LayerProperties> {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700855 using Base = BaseLayerVariant<LayerProperties>;
Vishnu Nairfa247b12020-02-11 08:58:26 -0800856 using FlingerLayerType = sp<EffectLayer>;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700857
858 static FlingerLayerType createLayer(CompositionTest* test) {
Vishnu Nairfa247b12020-02-11 08:58:26 -0800859 FlingerLayerType layer = Base::template createLayerWithFactory<EffectLayer>(test, [test]() {
Ady Abrahamd11bade2022-08-01 16:18:03 -0700860 return sp<EffectLayer>::make(
Dominik Laskowski8b01cc02020-07-14 19:02:41 -0700861 LayerCreationArgs(test->mFlinger.flinger(), sp<Client>(), "test-layer",
Vishnu Nairfa247b12020-02-11 08:58:26 -0800862 LayerProperties::LAYER_FLAGS, LayerMetadata()));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700863 });
Vishnu Nair60356342018-11-13 13:00:45 -0800864
865 auto& layerDrawingState = test->mFlinger.mutableLayerDrawingState(layer);
chaviw25714502021-02-11 10:01:08 -0800866 layerDrawingState.crop = Rect(0, 0, LayerProperties::HEIGHT, LayerProperties::WIDTH);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700867 return layer;
868 }
869
870 static void setupRECompositionCallExpectations(CompositionTest* test) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700871 LayerProperties::setupREColorCompositionCallExpectations(test);
872 }
873
874 static void setupREScreenshotCompositionCallExpectations(CompositionTest* test) {
875 LayerProperties::setupREColorScreenshotCompositionCallExpectations(test);
876 }
877
878 static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) {
879 LayerProperties::setupHwcSetGeometryCallExpectations(test);
880 LayerProperties::setupHwcSetSourceCropColorCallExpectations(test);
881 }
882
883 static void setupCallExpectationsForDirtyFrame(CompositionTest* test) {
884 LayerProperties::setupHwcSetPerFrameCallExpectations(test);
885 LayerProperties::setupHwcSetPerFrameColorCallExpectations(test);
886 }
887};
888
889template <typename LayerProperties>
890struct BufferLayerVariant : public BaseLayerVariant<LayerProperties> {
891 using Base = BaseLayerVariant<LayerProperties>;
Vishnu Nairf8a873a2022-06-15 17:34:34 +0000892 using FlingerLayerType = sp<BufferStateLayer>;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700893
894 static FlingerLayerType createLayer(CompositionTest* test) {
895 test->mFlinger.mutableTexturePool().push_back(DEFAULT_TEXTURE_ID);
896
897 FlingerLayerType layer =
Vishnu Nairf8a873a2022-06-15 17:34:34 +0000898 Base::template createLayerWithFactory<BufferStateLayer>(test, [test]() {
Dominik Laskowski8b01cc02020-07-14 19:02:41 -0700899 LayerCreationArgs args(test->mFlinger.flinger(), sp<Client>(), "test-layer",
Dominik Laskowski87a07e42019-10-10 20:38:02 -0700900 LayerProperties::LAYER_FLAGS, LayerMetadata());
chaviwb4c6e582019-08-16 14:35:07 -0700901 args.textureName = test->mFlinger.mutableTexturePool().back();
Ady Abrahamd11bade2022-08-01 16:18:03 -0700902 return sp<BufferStateLayer>::make(args);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700903 });
904
905 LayerProperties::setupLayerState(test, layer);
906
907 return layer;
908 }
909
910 static void cleanupInjectedLayers(CompositionTest* test) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700911 Base::cleanupInjectedLayers(test);
912 }
913
914 static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) {
915 LayerProperties::setupHwcSetGeometryCallExpectations(test);
916 LayerProperties::setupHwcSetSourceCropBufferCallExpectations(test);
917 }
918
919 static void setupCallExpectationsForDirtyFrame(CompositionTest* test) {
920 LayerProperties::setupHwcSetPerFrameCallExpectations(test);
921 LayerProperties::setupHwcSetPerFrameBufferCallExpectations(test);
922 }
923
924 static void setupRECompositionCallExpectations(CompositionTest* test) {
925 LayerProperties::setupREBufferCompositionCallExpectations(test);
926 }
927
928 static void setupInsecureRECompositionCallExpectations(CompositionTest* test) {
929 LayerProperties::setupInsecureREBufferCompositionCallExpectations(test);
930 }
931
932 static void setupREScreenshotCompositionCallExpectations(CompositionTest* test) {
933 LayerProperties::setupREBufferScreenshotCompositionCallExpectations(test);
934 }
935
936 static void setupInsecureREScreenshotCompositionCallExpectations(CompositionTest* test) {
937 LayerProperties::setupInsecureREBufferScreenshotCompositionCallExpectations(test);
938 }
939};
940
Garfield Tande619fa2020-10-02 17:13:53 -0700941template <typename LayerProperties>
942struct ContainerLayerVariant : public BaseLayerVariant<LayerProperties> {
943 using Base = BaseLayerVariant<LayerProperties>;
Vishnu Nairb21272e2022-07-01 22:47:33 +0000944 using FlingerLayerType = sp<EffectLayer>;
Garfield Tande619fa2020-10-02 17:13:53 -0700945
946 static FlingerLayerType createLayer(CompositionTest* test) {
947 LayerCreationArgs args(test->mFlinger.flinger(), sp<Client>(), "test-container-layer",
Garfield Tande619fa2020-10-02 17:13:53 -0700948 LayerProperties::LAYER_FLAGS, LayerMetadata());
Ady Abrahamd11bade2022-08-01 16:18:03 -0700949 FlingerLayerType layer = sp<EffectLayer>::make(args);
Garfield Tande619fa2020-10-02 17:13:53 -0700950 Base::template initLayerDrawingStateAndComputeBounds(test, layer);
951 return layer;
952 }
953};
954
955template <typename LayerVariant, typename ParentLayerVariant>
956struct ChildLayerVariant : public LayerVariant {
957 using Base = LayerVariant;
958 using FlingerLayerType = typename LayerVariant::FlingerLayerType;
959 using ParentBase = ParentLayerVariant;
960
961 static FlingerLayerType createLayer(CompositionTest* test) {
962 // Need to create child layer first. Otherwise layer history size will be 2.
963 FlingerLayerType layer = Base::createLayer(test);
964
965 typename ParentBase::FlingerLayerType parentLayer = ParentBase::createLayer(test);
966 parentLayer->addChild(layer);
967 test->mFlinger.setLayerDrawingParent(layer, parentLayer);
968
969 test->mAuxiliaryLayers.push_back(parentLayer);
970
971 return layer;
972 }
973
974 static void cleanupInjectedLayers(CompositionTest* test) {
975 // Clear auxiliary layers first so that child layer can be successfully destroyed in the
976 // following call.
977 test->mAuxiliaryLayers.clear();
978
979 Base::cleanupInjectedLayers(test);
980 }
981};
982
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700983/* ------------------------------------------------------------------------
984 * Variants to control how the composition type is changed
985 */
986
987struct NoCompositionTypeVariant {
988 static void setupHwcSetCallExpectations(CompositionTest*) {}
989
990 static void setupHwcGetCallExpectations(CompositionTest* test) {
991 EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _)).Times(1);
992 }
993};
994
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500995template <aidl::android::hardware::graphics::composer3::Composition CompositionType>
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700996struct KeepCompositionTypeVariant {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500997 static constexpr aidl::android::hardware::graphics::composer3::Composition TYPE =
998 CompositionType;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700999
1000 static void setupHwcSetCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001001 if (!test->mDisplayOff) {
1002 EXPECT_CALL(*test->mComposer,
1003 setLayerCompositionType(HWC_DISPLAY, HWC_LAYER, CompositionType))
1004 .Times(1);
1005 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001006 }
1007
1008 static void setupHwcGetCallExpectations(CompositionTest* test) {
1009 EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _)).Times(1);
1010 }
1011};
1012
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001013template <aidl::android::hardware::graphics::composer3::Composition InitialCompositionType,
1014 aidl::android::hardware::graphics::composer3::Composition FinalCompositionType>
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001015struct ChangeCompositionTypeVariant {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001016 static constexpr aidl::android::hardware::graphics::composer3::Composition TYPE =
1017 FinalCompositionType;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001018
1019 static void setupHwcSetCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001020 if (!test->mDisplayOff) {
1021 EXPECT_CALL(*test->mComposer,
1022 setLayerCompositionType(HWC_DISPLAY, HWC_LAYER, InitialCompositionType))
1023 .Times(1);
1024 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001025 }
1026
1027 static void setupHwcGetCallExpectations(CompositionTest* test) {
1028 EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _))
1029 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::Layer>{
1030 static_cast<Hwc2::Layer>(HWC_LAYER)}),
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001031 SetArgPointee<2>(
1032 std::vector<aidl::android::hardware::graphics::composer3::
1033 Composition>{FinalCompositionType}),
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001034 Return(Error::NONE)));
1035 }
1036};
1037
1038/* ------------------------------------------------------------------------
1039 * Variants to select how the composition is expected to be handled
1040 */
1041
1042struct CompositionResultBaseVariant {
1043 static void setupLayerState(CompositionTest*, sp<Layer>) {}
1044
1045 template <typename Case>
1046 static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) {
1047 Case::Layer::setupCallExpectationsForDirtyGeometry(test);
1048 }
1049
1050 template <typename Case>
1051 static void setupCallExpectationsForDirtyFrame(CompositionTest* test) {
1052 Case::Layer::setupCallExpectationsForDirtyFrame(test);
1053 }
1054};
1055
1056struct NoCompositionResultVariant : public CompositionResultBaseVariant {
1057 template <typename Case>
1058 static void setupCallExpectations(CompositionTest* test) {
1059 Case::Display::setupEmptyFrameCompositionCallExpectations(test);
1060 Case::Display::setupHwcCompositionCallExpectations(test);
1061 }
1062};
1063
1064struct HwcCompositionResultVariant : public CompositionResultBaseVariant {
1065 template <typename Case>
1066 static void setupCallExpectations(CompositionTest* test) {
1067 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
1068 Case::Display::setupHwcCompositionCallExpectations(test);
1069 }
1070};
1071
1072struct RECompositionResultVariant : public CompositionResultBaseVariant {
1073 template <typename Case>
1074 static void setupCallExpectations(CompositionTest* test) {
1075 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
Lloyd Pique66d68602019-02-13 14:23:31 -08001076 Case::Display::setupHwcClientCompositionCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001077 Case::Display::setupRECompositionCallExpectations(test);
1078 Case::Display::template setupRELayerCompositionCallExpectations<Case>(test);
1079 }
1080};
1081
Lloyd Pique66d68602019-02-13 14:23:31 -08001082struct ForcedClientCompositionResultVariant : public CompositionResultBaseVariant {
Lloyd Pique37c2c9b2018-12-04 17:25:10 -08001083 static void setupLayerState(CompositionTest* test, sp<Layer> layer) {
Dominik Laskowskib7251f42020-04-20 17:42:59 -07001084 const auto outputLayer =
1085 TestableSurfaceFlinger::findOutputLayerForDisplay(layer, test->mDisplay);
Lloyd Piquef5275482019-01-29 18:42:42 -08001086 LOG_FATAL_IF(!outputLayer);
1087 outputLayer->editState().forceClientComposition = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001088 }
1089
1090 template <typename Case>
Lloyd Pique66d68602019-02-13 14:23:31 -08001091 static void setupCallExpectations(CompositionTest* test) {
1092 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
1093 Case::Display::setupHwcForcedClientCompositionCallExpectations(test);
1094 Case::Display::setupRECompositionCallExpectations(test);
1095 Case::Display::template setupRELayerCompositionCallExpectations<Case>(test);
1096 }
1097
1098 template <typename Case>
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001099 static void setupCallExpectationsForDirtyGeometry(CompositionTest*) {}
1100
1101 template <typename Case>
1102 static void setupCallExpectationsForDirtyFrame(CompositionTest*) {}
1103};
1104
Lloyd Pique4fe29402019-08-12 16:51:24 -07001105struct ForcedClientCompositionViaDebugOptionResultVariant : public CompositionResultBaseVariant {
1106 static void setupLayerState(CompositionTest* test, sp<Layer>) {
1107 test->mFlinger.mutableDebugDisableHWC() = true;
1108 }
1109
1110 template <typename Case>
1111 static void setupCallExpectations(CompositionTest* test) {
1112 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
1113 Case::Display::setupHwcForcedClientCompositionCallExpectations(test);
1114 Case::Display::setupRECompositionCallExpectations(test);
1115 Case::Display::template setupRELayerCompositionCallExpectations<Case>(test);
1116 }
1117
1118 template <typename Case>
1119 static void setupCallExpectationsForDirtyGeometry(CompositionTest*) {}
1120
1121 template <typename Case>
1122 static void setupCallExpectationsForDirtyFrame(CompositionTest*) {}
1123};
1124
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001125struct EmptyScreenshotResultVariant {
1126 static void setupLayerState(CompositionTest*, sp<Layer>) {}
1127
1128 template <typename Case>
1129 static void setupCallExpectations(CompositionTest*) {}
1130};
1131
1132struct REScreenshotResultVariant : public EmptyScreenshotResultVariant {
1133 using Base = EmptyScreenshotResultVariant;
1134
1135 template <typename Case>
1136 static void setupCallExpectations(CompositionTest* test) {
1137 Base::template setupCallExpectations<Case>(test);
1138 Case::Display::template setupRELayerScreenshotCompositionCallExpectations<Case>(test);
1139 }
1140};
1141
1142/* ------------------------------------------------------------------------
1143 * Composition test case, containing all the variants being tested
1144 */
1145
1146template <typename DisplayCase, typename LayerCase, typename CompositionTypeCase,
1147 typename CompositionResultCase>
1148struct CompositionCase {
1149 using ThisCase =
1150 CompositionCase<DisplayCase, LayerCase, CompositionTypeCase, CompositionResultCase>;
1151 using Display = DisplayCase;
1152 using Layer = LayerCase;
1153 using CompositionType = CompositionTypeCase;
1154 using CompositionResult = CompositionResultCase;
1155
1156 static void setupCommon(CompositionTest* test) {
Peiyong Lin1336e6e2019-05-28 09:23:50 -07001157 Display::template setupPreconditionCallExpectations<ThisCase>(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001158 Display::setupPreconditions(test);
1159
1160 auto layer = Layer::createLayer(test);
1161 Layer::injectLayer(test, layer);
1162 CompositionResult::setupLayerState(test, layer);
1163 }
1164
1165 static void setupForDirtyGeometry(CompositionTest* test) {
1166 setupCommon(test);
1167
1168 Display::template setupCommonCompositionCallExpectations<ThisCase>(test);
1169 CompositionResult::template setupCallExpectationsForDirtyGeometry<ThisCase>(test);
1170 CompositionResult::template setupCallExpectationsForDirtyFrame<ThisCase>(test);
1171 CompositionResult::template setupCallExpectations<ThisCase>(test);
1172 }
1173
1174 static void setupForDirtyFrame(CompositionTest* test) {
1175 setupCommon(test);
1176
1177 Display::template setupCommonCompositionCallExpectations<ThisCase>(test);
1178 CompositionResult::template setupCallExpectationsForDirtyFrame<ThisCase>(test);
1179 CompositionResult::template setupCallExpectations<ThisCase>(test);
1180 }
1181
1182 static void setupForScreenCapture(CompositionTest* test) {
1183 setupCommon(test);
1184
1185 Display::template setupCommonScreensCaptureCallExpectations<ThisCase>(test);
1186 CompositionResult::template setupCallExpectations<ThisCase>(test);
1187 }
1188
1189 static void cleanup(CompositionTest* test) {
1190 Layer::cleanupInjectedLayers(test);
1191
Peiyong Linbdd08cc2019-12-17 21:35:14 -08001192 for (auto& displayData : test->mFlinger.mutableHwcDisplayData()) {
1193 static_cast<TestableSurfaceFlinger::HWC2Display*>(displayData.second.hwcDisplay.get())
1194 ->mutableLayers()
1195 .clear();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001196 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001197 }
1198};
1199
1200/* ------------------------------------------------------------------------
1201 * Composition cases to test
1202 */
1203
1204TEST_F(CompositionTest, noLayersDoesMinimalWorkWithDirtyGeometry) {
1205 displayRefreshCompositionDirtyGeometry<
1206 CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant,
1207 NoCompositionResultVariant>>();
1208}
1209
1210TEST_F(CompositionTest, noLayersDoesMinimalWorkWithDirtyFrame) {
1211 displayRefreshCompositionDirtyFrame<
1212 CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant,
1213 NoCompositionResultVariant>>();
1214}
1215
1216TEST_F(CompositionTest, noLayersDoesMinimalWorkToCaptureScreen) {
1217 captureScreenComposition<
1218 CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant,
1219 EmptyScreenshotResultVariant>>();
1220}
1221
1222/* ------------------------------------------------------------------------
1223 * Simple buffer layers
1224 */
1225
1226TEST_F(CompositionTest, HWCComposedNormalBufferLayerWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001227 displayRefreshCompositionDirtyGeometry<CompositionCase<
1228 DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1229 KeepCompositionTypeVariant<
1230 aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
1231 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001232}
1233
1234TEST_F(CompositionTest, HWCComposedNormalBufferLayerWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001235 displayRefreshCompositionDirtyFrame<CompositionCase<
1236 DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1237 KeepCompositionTypeVariant<
1238 aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
1239 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001240}
1241
1242TEST_F(CompositionTest, REComposedNormalBufferLayer) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001243 displayRefreshCompositionDirtyFrame<CompositionCase<
1244 DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1245 ChangeCompositionTypeVariant<
1246 aidl::android::hardware::graphics::composer3::Composition::DEVICE,
1247 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1248 RECompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001249}
1250
1251TEST_F(CompositionTest, captureScreenNormalBufferLayer) {
1252 captureScreenComposition<
1253 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1254 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1255}
1256
1257/* ------------------------------------------------------------------------
1258 * Single-color layers
1259 */
1260
Vishnu Nairfa247b12020-02-11 08:58:26 -08001261TEST_F(CompositionTest, HWCComposedEffectLayerWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001262 displayRefreshCompositionDirtyGeometry<CompositionCase<
1263 DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
1264 KeepCompositionTypeVariant<
1265 aidl::android::hardware::graphics::composer3::Composition::SOLID_COLOR>,
1266 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001267}
1268
Vishnu Nairfa247b12020-02-11 08:58:26 -08001269TEST_F(CompositionTest, HWCComposedEffectLayerWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001270 displayRefreshCompositionDirtyFrame<CompositionCase<
1271 DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
1272 KeepCompositionTypeVariant<
1273 aidl::android::hardware::graphics::composer3::Composition::SOLID_COLOR>,
1274 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001275}
1276
Vishnu Nairfa247b12020-02-11 08:58:26 -08001277TEST_F(CompositionTest, REComposedEffectLayer) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001278 displayRefreshCompositionDirtyFrame<CompositionCase<
1279 DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
1280 ChangeCompositionTypeVariant<
1281 aidl::android::hardware::graphics::composer3::Composition::SOLID_COLOR,
1282 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1283 RECompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001284}
1285
Vishnu Nairfa247b12020-02-11 08:58:26 -08001286TEST_F(CompositionTest, captureScreenEffectLayer) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001287 captureScreenComposition<
Vishnu Nairfa247b12020-02-11 08:58:26 -08001288 CompositionCase<DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001289 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1290}
1291
1292/* ------------------------------------------------------------------------
1293 * Layers with sideband buffers
1294 */
1295
1296TEST_F(CompositionTest, HWCComposedSidebandBufferLayerWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001297 displayRefreshCompositionDirtyGeometry<CompositionCase<
1298 DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1299 KeepCompositionTypeVariant<
1300 aidl::android::hardware::graphics::composer3::Composition::SIDEBAND>,
1301 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001302}
1303
1304TEST_F(CompositionTest, HWCComposedSidebandBufferLayerWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001305 displayRefreshCompositionDirtyFrame<CompositionCase<
1306 DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1307 KeepCompositionTypeVariant<
1308 aidl::android::hardware::graphics::composer3::Composition::SIDEBAND>,
1309 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001310}
1311
1312TEST_F(CompositionTest, REComposedSidebandBufferLayer) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001313 displayRefreshCompositionDirtyFrame<CompositionCase<
1314 DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1315 ChangeCompositionTypeVariant<
1316 aidl::android::hardware::graphics::composer3::Composition::SIDEBAND,
1317 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1318 RECompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001319}
1320
1321TEST_F(CompositionTest, captureScreenSidebandBufferLayer) {
1322 captureScreenComposition<
1323 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1324 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1325}
1326
1327/* ------------------------------------------------------------------------
1328 * Layers with ISurfaceComposerClient::eSecure, on a secure display
1329 */
1330
1331TEST_F(CompositionTest, HWCComposedSecureBufferLayerWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001332 displayRefreshCompositionDirtyGeometry<CompositionCase<
1333 DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1334 KeepCompositionTypeVariant<
1335 aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
1336 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001337}
1338
1339TEST_F(CompositionTest, HWCComposedSecureBufferLayerWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001340 displayRefreshCompositionDirtyFrame<CompositionCase<
1341 DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1342 KeepCompositionTypeVariant<
1343 aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
1344 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001345}
1346
1347TEST_F(CompositionTest, REComposedSecureBufferLayer) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001348 displayRefreshCompositionDirtyFrame<CompositionCase<
1349 DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1350 ChangeCompositionTypeVariant<
1351 aidl::android::hardware::graphics::composer3::Composition::DEVICE,
1352 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1353 RECompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001354}
1355
1356TEST_F(CompositionTest, captureScreenSecureBufferLayerOnSecureDisplay) {
1357 captureScreenComposition<
1358 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1359 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1360}
1361
1362/* ------------------------------------------------------------------------
1363 * Layers with ISurfaceComposerClient::eSecure, on a non-secure display
1364 */
1365
1366TEST_F(CompositionTest, HWCComposedSecureBufferLayerOnInsecureDisplayWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001367 displayRefreshCompositionDirtyGeometry<CompositionCase<
1368 InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1369 KeepCompositionTypeVariant<
1370 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1371 ForcedClientCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001372}
1373
1374TEST_F(CompositionTest, HWCComposedSecureBufferLayerOnInsecureDisplayWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001375 displayRefreshCompositionDirtyFrame<CompositionCase<
1376 InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1377 KeepCompositionTypeVariant<
1378 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1379 ForcedClientCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001380}
1381
1382TEST_F(CompositionTest, captureScreenSecureBufferLayerOnInsecureDisplay) {
1383 captureScreenComposition<
1384 CompositionCase<InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1385 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1386}
1387
1388/* ------------------------------------------------------------------------
Garfield Tande619fa2020-10-02 17:13:53 -07001389 * Layers with a parent layer with ISurfaceComposerClient::eSecure, on a non-secure display
1390 */
1391
1392TEST_F(CompositionTest,
1393 HWCComposedBufferLayerWithSecureParentLayerOnInsecureDisplayWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001394 displayRefreshCompositionDirtyGeometry<CompositionCase<
1395 InsecureDisplaySetupVariant,
1396 ChildLayerVariant<BufferLayerVariant<ParentSecureLayerProperties>,
1397 ContainerLayerVariant<SecureLayerProperties>>,
1398 KeepCompositionTypeVariant<
1399 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1400 ForcedClientCompositionResultVariant>>();
Garfield Tande619fa2020-10-02 17:13:53 -07001401}
1402
1403TEST_F(CompositionTest,
1404 HWCComposedBufferLayerWithSecureParentLayerOnInsecureDisplayWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001405 displayRefreshCompositionDirtyFrame<CompositionCase<
1406 InsecureDisplaySetupVariant,
1407 ChildLayerVariant<BufferLayerVariant<ParentSecureLayerProperties>,
1408 ContainerLayerVariant<SecureLayerProperties>>,
1409 KeepCompositionTypeVariant<
1410 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1411 ForcedClientCompositionResultVariant>>();
Garfield Tande619fa2020-10-02 17:13:53 -07001412}
1413
1414TEST_F(CompositionTest, captureScreenBufferLayerWithSecureParentLayerOnInsecureDisplay) {
1415 captureScreenComposition<
1416 CompositionCase<InsecureDisplaySetupVariant,
1417 ChildLayerVariant<BufferLayerVariant<ParentSecureLayerProperties>,
1418 ContainerLayerVariant<SecureLayerProperties>>,
1419 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1420}
1421
1422/* ------------------------------------------------------------------------
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001423 * Cursor layers
1424 */
1425
1426TEST_F(CompositionTest, HWCComposedCursorLayerWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001427 displayRefreshCompositionDirtyGeometry<CompositionCase<
1428 DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1429 KeepCompositionTypeVariant<
1430 aidl::android::hardware::graphics::composer3::Composition::CURSOR>,
1431 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001432}
1433
1434TEST_F(CompositionTest, HWCComposedCursorLayerWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001435 displayRefreshCompositionDirtyFrame<CompositionCase<
1436 DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1437 KeepCompositionTypeVariant<
1438 aidl::android::hardware::graphics::composer3::Composition::CURSOR>,
1439 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001440}
1441
1442TEST_F(CompositionTest, REComposedCursorLayer) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001443 displayRefreshCompositionDirtyFrame<CompositionCase<
1444 DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1445 ChangeCompositionTypeVariant<
1446 aidl::android::hardware::graphics::composer3::Composition::CURSOR,
1447 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1448 RECompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001449}
1450
1451TEST_F(CompositionTest, captureScreenCursorLayer) {
1452 captureScreenComposition<
1453 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1454 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1455}
1456
1457/* ------------------------------------------------------------------------
1458 * Simple buffer layer on a display which is powered off.
1459 */
1460
1461TEST_F(CompositionTest, displayOffHWCComposedNormalBufferLayerWithDirtyGeometry) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001462 mDisplayOff = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001463 displayRefreshCompositionDirtyGeometry<CompositionCase<
1464 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001465 KeepCompositionTypeVariant<
1466 aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001467 HwcCompositionResultVariant>>();
1468}
1469
1470TEST_F(CompositionTest, displayOffHWCComposedNormalBufferLayerWithDirtyFrame) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001471 mDisplayOff = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001472 displayRefreshCompositionDirtyFrame<CompositionCase<
1473 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001474 KeepCompositionTypeVariant<
1475 aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001476 HwcCompositionResultVariant>>();
1477}
1478
1479TEST_F(CompositionTest, displayOffREComposedNormalBufferLayer) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001480 mDisplayOff = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001481 displayRefreshCompositionDirtyFrame<CompositionCase<
1482 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001483 ChangeCompositionTypeVariant<
1484 aidl::android::hardware::graphics::composer3::Composition::DEVICE,
1485 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001486 RECompositionResultVariant>>();
1487}
1488
1489TEST_F(CompositionTest, captureScreenNormalBufferLayerOnPoweredOffDisplay) {
1490 captureScreenComposition<CompositionCase<
1491 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1492 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1493}
1494
Lloyd Pique4fe29402019-08-12 16:51:24 -07001495/* ------------------------------------------------------------------------
1496 * Client composition forced through debug/developer settings
1497 */
1498
1499TEST_F(CompositionTest, DebugOptionForcingClientCompositionOfBufferLayerWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001500 displayRefreshCompositionDirtyGeometry<CompositionCase<
1501 DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1502 KeepCompositionTypeVariant<
1503 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1504 ForcedClientCompositionViaDebugOptionResultVariant>>();
Lloyd Pique4fe29402019-08-12 16:51:24 -07001505}
1506
1507TEST_F(CompositionTest, DebugOptionForcingClientCompositionOfBufferLayerWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001508 displayRefreshCompositionDirtyFrame<CompositionCase<
1509 DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1510 KeepCompositionTypeVariant<
1511 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1512 ForcedClientCompositionViaDebugOptionResultVariant>>();
Lloyd Pique4fe29402019-08-12 16:51:24 -07001513}
1514
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001515} // namespace
1516} // namespace android
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -08001517
1518// TODO(b/129481165): remove the #pragma below and fix conversion issues
Marin Shalamanovbed7fd32020-12-21 20:02:20 +01001519#pragma clang diagnostic pop // ignored "-Wconversion -Wextra"