blob: 0666561642bb2f8b78ed9e341c6bbddc19fb8328 [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>&,
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
Vishnu Nairf8a873a2022-06-15 17:34:34 +0000495 static void setupLatchedBuffer(CompositionTest* test, sp<BufferStateLayer> layer) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700496 Mock::VerifyAndClear(test->mRenderEngine);
497
Vishnu Nairf8a873a2022-06-15 17:34:34 +0000498 const auto buffer = std::make_shared<
499 renderengine::mock::FakeExternalTexture>(LayerProperties::WIDTH,
500 LayerProperties::HEIGHT,
501 DEFAULT_TEXTURE_ID,
502 LayerProperties::FORMAT,
503 LayerProperties::USAGE |
504 GraphicBuffer::USAGE_HW_TEXTURE);
505
506 auto& layerDrawingState = test->mFlinger.mutableLayerDrawingState(layer);
507 layerDrawingState.crop = Rect(0, 0, LayerProperties::HEIGHT, LayerProperties::WIDTH);
508 layerDrawingState.buffer = buffer;
509 layerDrawingState.acquireFence = Fence::NO_FENCE;
510 layerDrawingState.dataspace = ui::Dataspace::UNKNOWN;
511 layer->setSurfaceDamageRegion(
512 Region(Rect(LayerProperties::HEIGHT, LayerProperties::WIDTH)));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700513
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700514 bool ignoredRecomputeVisibleRegions;
Vishnu Nair397a0e32022-07-26 00:01:48 +0000515 layer->latchBuffer(ignoredRecomputeVisibleRegions, 0);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700516 Mock::VerifyAndClear(test->mRenderEngine);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700517 }
518
Vishnu Nairf8a873a2022-06-15 17:34:34 +0000519 static void setupLayerState(CompositionTest* test, sp<BufferStateLayer> layer) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700520 setupLatchedBuffer(test, layer);
521 }
522
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700523 static void setupHwcSetGeometryCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800524 if (!test->mDisplayOff) {
525 // TODO: Coverage of other values
526 EXPECT_CALL(*test->mComposer,
527 setLayerBlendMode(HWC_DISPLAY, HWC_LAYER, LayerProperties::BLENDMODE))
528 .Times(1);
529 // TODO: Coverage of other values for origin
530 EXPECT_CALL(*test->mComposer,
531 setLayerDisplayFrame(HWC_DISPLAY, HWC_LAYER,
532 IComposerClient::Rect({0, 0, LayerProperties::WIDTH,
533 LayerProperties::HEIGHT})))
534 .Times(1);
535 EXPECT_CALL(*test->mComposer,
536 setLayerPlaneAlpha(HWC_DISPLAY, HWC_LAYER, LayerProperties::COLOR[3]))
537 .Times(1);
538 // TODO: Coverage of other values
539 EXPECT_CALL(*test->mComposer, setLayerZOrder(HWC_DISPLAY, HWC_LAYER, 0u)).Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700540
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800541 // These expectations retire on saturation as the code path these
542 // expectations are for appears to make an extra call to them.
543 // TODO: Investigate this extra call
544 EXPECT_CALL(*test->mComposer,
545 setLayerTransform(HWC_DISPLAY, HWC_LAYER, DEFAULT_TRANSFORM))
546 .Times(AtLeast(1))
547 .RetiresOnSaturation();
548 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700549 }
550
551 static void setupHwcSetSourceCropBufferCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800552 if (!test->mDisplayOff) {
553 EXPECT_CALL(*test->mComposer,
554 setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER,
555 IComposerClient::FRect({0.f, 0.f, LayerProperties::WIDTH,
556 LayerProperties::HEIGHT})))
557 .Times(1);
558 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700559 }
560
561 static void setupHwcSetSourceCropColorCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800562 if (!test->mDisplayOff) {
563 EXPECT_CALL(*test->mComposer,
564 setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER,
565 IComposerClient::FRect({0.f, 0.f, 0.f, 0.f})))
566 .Times(1);
567 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700568 }
569
570 static void setupHwcSetPerFrameCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800571 if (!test->mDisplayOff) {
572 EXPECT_CALL(*test->mComposer,
573 setLayerVisibleRegion(HWC_DISPLAY, HWC_LAYER,
574 std::vector<IComposerClient::Rect>(
575 {IComposerClient::Rect(
576 {0, 0, LayerProperties::WIDTH,
577 LayerProperties::HEIGHT})})))
578 .Times(1);
579 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700580 }
581
582 static void setupHwcSetPerFrameColorCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800583 if (!test->mDisplayOff) {
584 EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _))
585 .Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700586
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800587 // TODO: use COLOR
588 EXPECT_CALL(*test->mComposer,
589 setLayerColor(HWC_DISPLAY, HWC_LAYER,
Ady Abraham6e60b142022-01-06 18:10:35 -0800590 aidl::android::hardware::graphics::composer3::Color(
591 {1.0f, 1.0f, 1.0f, 1.0f})))
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800592 .Times(1);
593 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700594 }
595
596 static void setupHwcSetPerFrameBufferCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800597 if (!test->mDisplayOff) {
598 EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _))
599 .Times(1);
600 EXPECT_CALL(*test->mComposer, setLayerBuffer(HWC_DISPLAY, HWC_LAYER, _, _, _)).Times(1);
601 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700602 }
603
604 static void setupREBufferCompositionCommonCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000605 EXPECT_CALL(*test->mRenderEngine, drawLayers)
Sally Qi4cabdd02021-08-05 16:45:57 -0700606 .WillOnce([&](const renderengine::DisplaySettings& displaySettings,
Sally Qi59a9f502021-10-12 18:53:23 +0000607 const std::vector<renderengine::LayerSettings>& layerSettings,
Sally Qi4cabdd02021-08-05 16:45:57 -0700608 const std::shared_ptr<renderengine::ExternalTexture>&, const bool,
Sally Qi59a9f502021-10-12 18:53:23 +0000609 base::unique_fd&&) -> std::future<renderengine::RenderEngineResult> {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000610 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
611 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
612 displaySettings.physicalDisplay);
613 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
614 displaySettings.clip);
615 // screen capture adds an additional color layer as an alpha
616 // prefill, so gtet the back layer.
Sally Qi4cabdd02021-08-05 16:45:57 -0700617 std::future<renderengine::RenderEngineResult> resultFuture =
618 futureOf<renderengine::RenderEngineResult>(
619 {NO_ERROR, base::unique_fd()});
Lloyd Piquea2468662019-03-07 21:31:06 -0800620 if (layerSettings.empty()) {
621 ADD_FAILURE() << "layerSettings was not expected to be empty in "
622 "setupREBufferCompositionCommonCallExpectations "
623 "verification lambda";
Sally Qi4cabdd02021-08-05 16:45:57 -0700624 return resultFuture;
Lloyd Piquea2468662019-03-07 21:31:06 -0800625 }
Sally Qi59a9f502021-10-12 18:53:23 +0000626 const renderengine::LayerSettings layer = layerSettings.back();
627 EXPECT_THAT(layer.source.buffer.buffer, Not(IsNull()));
628 EXPECT_THAT(layer.source.buffer.fence, Not(IsNull()));
629 EXPECT_EQ(DEFAULT_TEXTURE_ID, layer.source.buffer.textureName);
630 EXPECT_EQ(false, layer.source.buffer.isY410BT2020);
631 EXPECT_EQ(true, layer.source.buffer.usePremultipliedAlpha);
632 EXPECT_EQ(false, layer.source.buffer.isOpaque);
Vishnu Nair50c0afe2022-07-11 15:04:07 -0700633 EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius.x);
634 EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius.y);
Sally Qi59a9f502021-10-12 18:53:23 +0000635 EXPECT_EQ(ui::Dataspace::UNKNOWN, layer.sourceDataspace);
636 EXPECT_EQ(LayerProperties::COLOR[3], layer.alpha);
Sally Qi4cabdd02021-08-05 16:45:57 -0700637 return resultFuture;
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000638 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700639 }
640
641 static void setupREBufferCompositionCallExpectations(CompositionTest* test) {
642 LayerProperties::setupREBufferCompositionCommonCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700643 }
644
645 static void setupInsecureREBufferCompositionCallExpectations(CompositionTest* test) {
646 setupREBufferCompositionCallExpectations(test);
647 }
648
649 static void setupREBufferScreenshotCompositionCallExpectations(CompositionTest* test) {
650 LayerProperties::setupREBufferCompositionCommonCallExpectations(test);
651 }
652
653 static void setupInsecureREBufferScreenshotCompositionCallExpectations(CompositionTest* test) {
654 LayerProperties::setupREBufferCompositionCommonCallExpectations(test);
655 }
656
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700657 static void setupREColorCompositionCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000658 EXPECT_CALL(*test->mRenderEngine, drawLayers)
Sally Qi4cabdd02021-08-05 16:45:57 -0700659 .WillOnce([&](const renderengine::DisplaySettings& displaySettings,
Sally Qi59a9f502021-10-12 18:53:23 +0000660 const std::vector<renderengine::LayerSettings>& layerSettings,
Sally Qi4cabdd02021-08-05 16:45:57 -0700661 const std::shared_ptr<renderengine::ExternalTexture>&, const bool,
Sally Qi59a9f502021-10-12 18:53:23 +0000662 base::unique_fd&&) -> std::future<renderengine::RenderEngineResult> {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000663 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
664 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
665 displaySettings.physicalDisplay);
666 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
667 displaySettings.clip);
668 // screen capture adds an additional color layer as an alpha
669 // prefill, so get the back layer.
Sally Qi4cabdd02021-08-05 16:45:57 -0700670 std::future<renderengine::RenderEngineResult> resultFuture =
671 futureOf<renderengine::RenderEngineResult>(
672 {NO_ERROR, base::unique_fd()});
Lloyd Piquea2468662019-03-07 21:31:06 -0800673 if (layerSettings.empty()) {
674 ADD_FAILURE()
675 << "layerSettings was not expected to be empty in "
676 "setupREColorCompositionCallExpectations verification lambda";
Sally Qi4cabdd02021-08-05 16:45:57 -0700677 return resultFuture;
Lloyd Piquea2468662019-03-07 21:31:06 -0800678 }
Sally Qi59a9f502021-10-12 18:53:23 +0000679 const renderengine::LayerSettings layer = layerSettings.back();
680 EXPECT_THAT(layer.source.buffer.buffer, IsNull());
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000681 EXPECT_EQ(half3(LayerProperties::COLOR[0], LayerProperties::COLOR[1],
682 LayerProperties::COLOR[2]),
Sally Qi59a9f502021-10-12 18:53:23 +0000683 layer.source.solidColor);
Vishnu Nair50c0afe2022-07-11 15:04:07 -0700684 EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius.x);
685 EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius.y);
Sally Qi59a9f502021-10-12 18:53:23 +0000686 EXPECT_EQ(ui::Dataspace::UNKNOWN, layer.sourceDataspace);
687 EXPECT_EQ(LayerProperties::COLOR[3], layer.alpha);
Sally Qi4cabdd02021-08-05 16:45:57 -0700688 return resultFuture;
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000689 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700690 }
691
692 static void setupREColorScreenshotCompositionCallExpectations(CompositionTest* test) {
693 setupREColorCompositionCallExpectations(test);
694 }
695};
696
697struct DefaultLayerProperties : public BaseLayerProperties<DefaultLayerProperties> {};
698
Vishnu Nairfa247b12020-02-11 08:58:26 -0800699struct EffectLayerProperties : public BaseLayerProperties<EffectLayerProperties> {
Alec Mourida8a9d12020-01-30 20:00:31 -0800700 static constexpr IComposerClient::BlendMode BLENDMODE = IComposerClient::BlendMode::NONE;
701};
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700702
703struct SidebandLayerProperties : public BaseLayerProperties<SidebandLayerProperties> {
704 using Base = BaseLayerProperties<SidebandLayerProperties>;
705 static constexpr IComposerClient::BlendMode BLENDMODE = IComposerClient::BlendMode::NONE;
706
Vishnu Nairf8a873a2022-06-15 17:34:34 +0000707 static void setupLayerState(CompositionTest* test, sp<BufferStateLayer> layer) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700708 sp<NativeHandle> stream =
709 NativeHandle::create(reinterpret_cast<native_handle_t*>(DEFAULT_SIDEBAND_STREAM),
710 false);
711 test->mFlinger.setLayerSidebandStream(layer, stream);
712 }
713
714 static void setupHwcSetSourceCropBufferCallExpectations(CompositionTest* test) {
715 EXPECT_CALL(*test->mComposer,
716 setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER,
717 IComposerClient::FRect({0.f, 0.f, -1.f, -1.f})))
718 .Times(1);
719 }
720
721 static void setupHwcSetPerFrameBufferCallExpectations(CompositionTest* test) {
722 EXPECT_CALL(*test->mComposer,
723 setLayerSidebandStream(HWC_DISPLAY, HWC_LAYER,
724 reinterpret_cast<native_handle_t*>(
725 DEFAULT_SIDEBAND_STREAM)))
726 .WillOnce(Return(Error::NONE));
727
728 EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _)).Times(1);
729 }
730
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000731 static void setupREBufferCompositionCommonCallExpectations(CompositionTest* /*test*/) {}
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700732};
733
Garfield Tande619fa2020-10-02 17:13:53 -0700734template <typename LayerProperties>
735struct CommonSecureLayerProperties : public BaseLayerProperties<LayerProperties> {
736 using Base = BaseLayerProperties<LayerProperties>;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700737
738 static void setupInsecureREBufferCompositionCommonCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000739 EXPECT_CALL(*test->mRenderEngine, drawLayers)
Sally Qi4cabdd02021-08-05 16:45:57 -0700740 .WillOnce([&](const renderengine::DisplaySettings& displaySettings,
Sally Qi59a9f502021-10-12 18:53:23 +0000741 const std::vector<renderengine::LayerSettings>& layerSettings,
Sally Qi4cabdd02021-08-05 16:45:57 -0700742 const std::shared_ptr<renderengine::ExternalTexture>&, const bool,
Sally Qi59a9f502021-10-12 18:53:23 +0000743 base::unique_fd&&) -> std::future<renderengine::RenderEngineResult> {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000744 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
745 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
746 displaySettings.physicalDisplay);
747 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
748 displaySettings.clip);
749 // screen capture adds an additional color layer as an alpha
750 // prefill, so get the back layer.
Sally Qi4cabdd02021-08-05 16:45:57 -0700751 std::future<renderengine::RenderEngineResult> resultFuture =
752 futureOf<renderengine::RenderEngineResult>(
753 {NO_ERROR, base::unique_fd()});
Lloyd Piquea2468662019-03-07 21:31:06 -0800754 if (layerSettings.empty()) {
755 ADD_FAILURE() << "layerSettings was not expected to be empty in "
756 "setupInsecureREBufferCompositionCommonCallExpectations "
757 "verification lambda";
Sally Qi4cabdd02021-08-05 16:45:57 -0700758 return resultFuture;
Lloyd Piquea2468662019-03-07 21:31:06 -0800759 }
Sally Qi59a9f502021-10-12 18:53:23 +0000760 const renderengine::LayerSettings layer = layerSettings.back();
761 EXPECT_THAT(layer.source.buffer.buffer, IsNull());
762 EXPECT_EQ(half3(0.0f, 0.0f, 0.0f), layer.source.solidColor);
Vishnu Nair50c0afe2022-07-11 15:04:07 -0700763 EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius.x);
764 EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius.y);
Sally Qi59a9f502021-10-12 18:53:23 +0000765 EXPECT_EQ(ui::Dataspace::UNKNOWN, layer.sourceDataspace);
766 EXPECT_EQ(1.0f, layer.alpha);
Sally Qi4cabdd02021-08-05 16:45:57 -0700767 return resultFuture;
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000768 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700769 }
770
771 static void setupInsecureREBufferCompositionCallExpectations(CompositionTest* test) {
772 setupInsecureREBufferCompositionCommonCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700773 }
774
775 static void setupInsecureREBufferScreenshotCompositionCallExpectations(CompositionTest* test) {
776 setupInsecureREBufferCompositionCommonCallExpectations(test);
777 }
778};
779
Garfield Tande619fa2020-10-02 17:13:53 -0700780struct ParentSecureLayerProperties
781 : public CommonSecureLayerProperties<ParentSecureLayerProperties> {};
782
783struct SecureLayerProperties : public CommonSecureLayerProperties<SecureLayerProperties> {
784 static constexpr uint32_t LAYER_FLAGS = ISurfaceComposerClient::eSecure;
785};
786
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700787struct CursorLayerProperties : public BaseLayerProperties<CursorLayerProperties> {
788 using Base = BaseLayerProperties<CursorLayerProperties>;
789
Vishnu Nairf8a873a2022-06-15 17:34:34 +0000790 static void setupLayerState(CompositionTest* test, sp<BufferStateLayer> layer) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700791 Base::setupLayerState(test, layer);
792 test->mFlinger.setLayerPotentialCursor(layer, true);
793 }
794};
795
796struct NoLayerVariant {
Vishnu Nairf8a873a2022-06-15 17:34:34 +0000797 using FlingerLayerType = sp<BufferStateLayer>;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700798
799 static FlingerLayerType createLayer(CompositionTest*) { return FlingerLayerType(); }
800 static void injectLayer(CompositionTest*, FlingerLayerType) {}
801 static void cleanupInjectedLayers(CompositionTest*) {}
802
803 static void setupCallExpectationsForDirtyGeometry(CompositionTest*) {}
804 static void setupCallExpectationsForDirtyFrame(CompositionTest*) {}
805};
806
807template <typename LayerProperties>
808struct BaseLayerVariant {
809 template <typename L, typename F>
810 static sp<L> createLayerWithFactory(CompositionTest* test, F factory) {
Dominik Laskowski756b7892021-08-04 12:53:59 -0700811 EXPECT_CALL(*test->mFlinger.scheduler(), postMessage(_)).Times(0);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700812
813 sp<L> layer = factory();
814
Dominik Laskowski49cea512019-11-12 14:13:23 -0800815 // Layer should be registered with scheduler.
Dominik Laskowski9c93d602021-10-07 19:38:26 -0700816 EXPECT_EQ(1u, test->mFlinger.scheduler()->layerHistorySize());
Dominik Laskowski49cea512019-11-12 14:13:23 -0800817
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700818 Mock::VerifyAndClear(test->mComposer);
819 Mock::VerifyAndClear(test->mRenderEngine);
Dominik Laskowski756b7892021-08-04 12:53:59 -0700820 Mock::VerifyAndClearExpectations(test->mFlinger.scheduler());
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700821
Garfield Tande619fa2020-10-02 17:13:53 -0700822 initLayerDrawingStateAndComputeBounds(test, layer);
823
824 return layer;
825 }
826
827 template <typename L>
828 static void initLayerDrawingStateAndComputeBounds(CompositionTest* test, sp<L> layer) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700829 auto& layerDrawingState = test->mFlinger.mutableLayerDrawingState(layer);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700830 layerDrawingState.layerStack = LAYER_STACK;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700831 layerDrawingState.color = half4(LayerProperties::COLOR[0], LayerProperties::COLOR[1],
832 LayerProperties::COLOR[2], LayerProperties::COLOR[3]);
Vishnu Nairc97b8db2019-10-29 18:19:35 -0700833 layer->computeBounds(FloatRect(0, 0, 100, 100), ui::Transform(), 0.f /* shadowRadius */);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700834 }
835
836 static void injectLayer(CompositionTest* test, sp<Layer> layer) {
837 EXPECT_CALL(*test->mComposer, createLayer(HWC_DISPLAY, _))
838 .WillOnce(DoAll(SetArgPointee<1>(HWC_LAYER), Return(Error::NONE)));
839
Lloyd Piquede196652020-01-22 17:29:58 -0800840 auto outputLayer = test->mDisplay->getCompositionDisplay()->injectOutputLayerForTest(
841 layer->getCompositionEngineLayerFE());
Lloyd Pique01c77c12019-04-17 12:48:32 -0700842 outputLayer->editState().visibleRegion = Region(Rect(0, 0, 100, 100));
843 outputLayer->editState().outputSpaceVisibleRegion = Region(Rect(0, 0, 100, 100));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700844
845 Mock::VerifyAndClear(test->mComposer);
846
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700847 test->mFlinger.mutableDrawingState().layersSortedByZ.add(layer);
848 }
849
850 static void cleanupInjectedLayers(CompositionTest* test) {
851 EXPECT_CALL(*test->mComposer, destroyLayer(HWC_DISPLAY, HWC_LAYER))
852 .WillOnce(Return(Error::NONE));
Lloyd Pique37c2c9b2018-12-04 17:25:10 -0800853
Lloyd Pique01c77c12019-04-17 12:48:32 -0700854 test->mDisplay->getCompositionDisplay()->clearOutputLayers();
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700855 test->mFlinger.mutableDrawingState().layersSortedByZ.clear();
Dominik Laskowski49cea512019-11-12 14:13:23 -0800856
857 // Layer should be unregistered with scheduler.
Dominik Laskowskie0e0cde2021-07-30 10:42:05 -0700858 test->mFlinger.commit();
Dominik Laskowski9c93d602021-10-07 19:38:26 -0700859 EXPECT_EQ(0u, test->mFlinger.scheduler()->layerHistorySize());
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700860 }
861};
862
863template <typename LayerProperties>
Vishnu Nairfa247b12020-02-11 08:58:26 -0800864struct EffectLayerVariant : public BaseLayerVariant<LayerProperties> {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700865 using Base = BaseLayerVariant<LayerProperties>;
Vishnu Nairfa247b12020-02-11 08:58:26 -0800866 using FlingerLayerType = sp<EffectLayer>;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700867
868 static FlingerLayerType createLayer(CompositionTest* test) {
Vishnu Nairfa247b12020-02-11 08:58:26 -0800869 FlingerLayerType layer = Base::template createLayerWithFactory<EffectLayer>(test, [test]() {
Ady Abrahamd11bade2022-08-01 16:18:03 -0700870 return sp<EffectLayer>::make(
Dominik Laskowski8b01cc02020-07-14 19:02:41 -0700871 LayerCreationArgs(test->mFlinger.flinger(), sp<Client>(), "test-layer",
Vishnu Nairfa247b12020-02-11 08:58:26 -0800872 LayerProperties::LAYER_FLAGS, LayerMetadata()));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700873 });
Vishnu Nair60356342018-11-13 13:00:45 -0800874
875 auto& layerDrawingState = test->mFlinger.mutableLayerDrawingState(layer);
chaviw25714502021-02-11 10:01:08 -0800876 layerDrawingState.crop = Rect(0, 0, LayerProperties::HEIGHT, LayerProperties::WIDTH);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700877 return layer;
878 }
879
880 static void setupRECompositionCallExpectations(CompositionTest* test) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700881 LayerProperties::setupREColorCompositionCallExpectations(test);
882 }
883
884 static void setupREScreenshotCompositionCallExpectations(CompositionTest* test) {
885 LayerProperties::setupREColorScreenshotCompositionCallExpectations(test);
886 }
887
888 static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) {
889 LayerProperties::setupHwcSetGeometryCallExpectations(test);
890 LayerProperties::setupHwcSetSourceCropColorCallExpectations(test);
891 }
892
893 static void setupCallExpectationsForDirtyFrame(CompositionTest* test) {
894 LayerProperties::setupHwcSetPerFrameCallExpectations(test);
895 LayerProperties::setupHwcSetPerFrameColorCallExpectations(test);
896 }
897};
898
899template <typename LayerProperties>
900struct BufferLayerVariant : public BaseLayerVariant<LayerProperties> {
901 using Base = BaseLayerVariant<LayerProperties>;
Vishnu Nairf8a873a2022-06-15 17:34:34 +0000902 using FlingerLayerType = sp<BufferStateLayer>;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700903
904 static FlingerLayerType createLayer(CompositionTest* test) {
905 test->mFlinger.mutableTexturePool().push_back(DEFAULT_TEXTURE_ID);
906
907 FlingerLayerType layer =
Vishnu Nairf8a873a2022-06-15 17:34:34 +0000908 Base::template createLayerWithFactory<BufferStateLayer>(test, [test]() {
Dominik Laskowski8b01cc02020-07-14 19:02:41 -0700909 LayerCreationArgs args(test->mFlinger.flinger(), sp<Client>(), "test-layer",
Dominik Laskowski87a07e42019-10-10 20:38:02 -0700910 LayerProperties::LAYER_FLAGS, LayerMetadata());
chaviwb4c6e582019-08-16 14:35:07 -0700911 args.textureName = test->mFlinger.mutableTexturePool().back();
Ady Abrahamd11bade2022-08-01 16:18:03 -0700912 return sp<BufferStateLayer>::make(args);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700913 });
914
915 LayerProperties::setupLayerState(test, layer);
916
917 return layer;
918 }
919
920 static void cleanupInjectedLayers(CompositionTest* test) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700921 Base::cleanupInjectedLayers(test);
922 }
923
924 static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) {
925 LayerProperties::setupHwcSetGeometryCallExpectations(test);
926 LayerProperties::setupHwcSetSourceCropBufferCallExpectations(test);
927 }
928
929 static void setupCallExpectationsForDirtyFrame(CompositionTest* test) {
930 LayerProperties::setupHwcSetPerFrameCallExpectations(test);
931 LayerProperties::setupHwcSetPerFrameBufferCallExpectations(test);
932 }
933
934 static void setupRECompositionCallExpectations(CompositionTest* test) {
935 LayerProperties::setupREBufferCompositionCallExpectations(test);
936 }
937
938 static void setupInsecureRECompositionCallExpectations(CompositionTest* test) {
939 LayerProperties::setupInsecureREBufferCompositionCallExpectations(test);
940 }
941
942 static void setupREScreenshotCompositionCallExpectations(CompositionTest* test) {
943 LayerProperties::setupREBufferScreenshotCompositionCallExpectations(test);
944 }
945
946 static void setupInsecureREScreenshotCompositionCallExpectations(CompositionTest* test) {
947 LayerProperties::setupInsecureREBufferScreenshotCompositionCallExpectations(test);
948 }
949};
950
Garfield Tande619fa2020-10-02 17:13:53 -0700951template <typename LayerProperties>
952struct ContainerLayerVariant : public BaseLayerVariant<LayerProperties> {
953 using Base = BaseLayerVariant<LayerProperties>;
Vishnu Nairb21272e2022-07-01 22:47:33 +0000954 using FlingerLayerType = sp<EffectLayer>;
Garfield Tande619fa2020-10-02 17:13:53 -0700955
956 static FlingerLayerType createLayer(CompositionTest* test) {
957 LayerCreationArgs args(test->mFlinger.flinger(), sp<Client>(), "test-container-layer",
Garfield Tande619fa2020-10-02 17:13:53 -0700958 LayerProperties::LAYER_FLAGS, LayerMetadata());
Ady Abrahamd11bade2022-08-01 16:18:03 -0700959 FlingerLayerType layer = sp<EffectLayer>::make(args);
Garfield Tande619fa2020-10-02 17:13:53 -0700960 Base::template initLayerDrawingStateAndComputeBounds(test, layer);
961 return layer;
962 }
963};
964
965template <typename LayerVariant, typename ParentLayerVariant>
966struct ChildLayerVariant : public LayerVariant {
967 using Base = LayerVariant;
968 using FlingerLayerType = typename LayerVariant::FlingerLayerType;
969 using ParentBase = ParentLayerVariant;
970
971 static FlingerLayerType createLayer(CompositionTest* test) {
972 // Need to create child layer first. Otherwise layer history size will be 2.
973 FlingerLayerType layer = Base::createLayer(test);
974
975 typename ParentBase::FlingerLayerType parentLayer = ParentBase::createLayer(test);
976 parentLayer->addChild(layer);
977 test->mFlinger.setLayerDrawingParent(layer, parentLayer);
978
979 test->mAuxiliaryLayers.push_back(parentLayer);
980
981 return layer;
982 }
983
984 static void cleanupInjectedLayers(CompositionTest* test) {
985 // Clear auxiliary layers first so that child layer can be successfully destroyed in the
986 // following call.
987 test->mAuxiliaryLayers.clear();
988
989 Base::cleanupInjectedLayers(test);
990 }
991};
992
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700993/* ------------------------------------------------------------------------
994 * Variants to control how the composition type is changed
995 */
996
997struct NoCompositionTypeVariant {
998 static void setupHwcSetCallExpectations(CompositionTest*) {}
999
1000 static void setupHwcGetCallExpectations(CompositionTest* test) {
1001 EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _)).Times(1);
1002 }
1003};
1004
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001005template <aidl::android::hardware::graphics::composer3::Composition CompositionType>
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001006struct KeepCompositionTypeVariant {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001007 static constexpr aidl::android::hardware::graphics::composer3::Composition TYPE =
1008 CompositionType;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001009
1010 static void setupHwcSetCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001011 if (!test->mDisplayOff) {
1012 EXPECT_CALL(*test->mComposer,
1013 setLayerCompositionType(HWC_DISPLAY, HWC_LAYER, CompositionType))
1014 .Times(1);
1015 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001016 }
1017
1018 static void setupHwcGetCallExpectations(CompositionTest* test) {
1019 EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _)).Times(1);
1020 }
1021};
1022
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001023template <aidl::android::hardware::graphics::composer3::Composition InitialCompositionType,
1024 aidl::android::hardware::graphics::composer3::Composition FinalCompositionType>
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001025struct ChangeCompositionTypeVariant {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001026 static constexpr aidl::android::hardware::graphics::composer3::Composition TYPE =
1027 FinalCompositionType;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001028
1029 static void setupHwcSetCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001030 if (!test->mDisplayOff) {
1031 EXPECT_CALL(*test->mComposer,
1032 setLayerCompositionType(HWC_DISPLAY, HWC_LAYER, InitialCompositionType))
1033 .Times(1);
1034 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001035 }
1036
1037 static void setupHwcGetCallExpectations(CompositionTest* test) {
1038 EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _))
1039 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::Layer>{
1040 static_cast<Hwc2::Layer>(HWC_LAYER)}),
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001041 SetArgPointee<2>(
1042 std::vector<aidl::android::hardware::graphics::composer3::
1043 Composition>{FinalCompositionType}),
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001044 Return(Error::NONE)));
1045 }
1046};
1047
1048/* ------------------------------------------------------------------------
1049 * Variants to select how the composition is expected to be handled
1050 */
1051
1052struct CompositionResultBaseVariant {
1053 static void setupLayerState(CompositionTest*, sp<Layer>) {}
1054
1055 template <typename Case>
1056 static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) {
1057 Case::Layer::setupCallExpectationsForDirtyGeometry(test);
1058 }
1059
1060 template <typename Case>
1061 static void setupCallExpectationsForDirtyFrame(CompositionTest* test) {
1062 Case::Layer::setupCallExpectationsForDirtyFrame(test);
1063 }
1064};
1065
1066struct NoCompositionResultVariant : public CompositionResultBaseVariant {
1067 template <typename Case>
1068 static void setupCallExpectations(CompositionTest* test) {
1069 Case::Display::setupEmptyFrameCompositionCallExpectations(test);
1070 Case::Display::setupHwcCompositionCallExpectations(test);
1071 }
1072};
1073
1074struct HwcCompositionResultVariant : public CompositionResultBaseVariant {
1075 template <typename Case>
1076 static void setupCallExpectations(CompositionTest* test) {
1077 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
1078 Case::Display::setupHwcCompositionCallExpectations(test);
1079 }
1080};
1081
1082struct RECompositionResultVariant : public CompositionResultBaseVariant {
1083 template <typename Case>
1084 static void setupCallExpectations(CompositionTest* test) {
1085 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
Lloyd Pique66d68602019-02-13 14:23:31 -08001086 Case::Display::setupHwcClientCompositionCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001087 Case::Display::setupRECompositionCallExpectations(test);
1088 Case::Display::template setupRELayerCompositionCallExpectations<Case>(test);
1089 }
1090};
1091
Lloyd Pique66d68602019-02-13 14:23:31 -08001092struct ForcedClientCompositionResultVariant : public CompositionResultBaseVariant {
Lloyd Pique37c2c9b2018-12-04 17:25:10 -08001093 static void setupLayerState(CompositionTest* test, sp<Layer> layer) {
Dominik Laskowskib7251f42020-04-20 17:42:59 -07001094 const auto outputLayer =
1095 TestableSurfaceFlinger::findOutputLayerForDisplay(layer, test->mDisplay);
Lloyd Piquef5275482019-01-29 18:42:42 -08001096 LOG_FATAL_IF(!outputLayer);
1097 outputLayer->editState().forceClientComposition = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001098 }
1099
1100 template <typename Case>
Lloyd Pique66d68602019-02-13 14:23:31 -08001101 static void setupCallExpectations(CompositionTest* test) {
1102 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
1103 Case::Display::setupHwcForcedClientCompositionCallExpectations(test);
1104 Case::Display::setupRECompositionCallExpectations(test);
1105 Case::Display::template setupRELayerCompositionCallExpectations<Case>(test);
1106 }
1107
1108 template <typename Case>
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001109 static void setupCallExpectationsForDirtyGeometry(CompositionTest*) {}
1110
1111 template <typename Case>
1112 static void setupCallExpectationsForDirtyFrame(CompositionTest*) {}
1113};
1114
Lloyd Pique4fe29402019-08-12 16:51:24 -07001115struct ForcedClientCompositionViaDebugOptionResultVariant : public CompositionResultBaseVariant {
1116 static void setupLayerState(CompositionTest* test, sp<Layer>) {
1117 test->mFlinger.mutableDebugDisableHWC() = true;
1118 }
1119
1120 template <typename Case>
1121 static void setupCallExpectations(CompositionTest* test) {
1122 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
1123 Case::Display::setupHwcForcedClientCompositionCallExpectations(test);
1124 Case::Display::setupRECompositionCallExpectations(test);
1125 Case::Display::template setupRELayerCompositionCallExpectations<Case>(test);
1126 }
1127
1128 template <typename Case>
1129 static void setupCallExpectationsForDirtyGeometry(CompositionTest*) {}
1130
1131 template <typename Case>
1132 static void setupCallExpectationsForDirtyFrame(CompositionTest*) {}
1133};
1134
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001135struct EmptyScreenshotResultVariant {
1136 static void setupLayerState(CompositionTest*, sp<Layer>) {}
1137
1138 template <typename Case>
1139 static void setupCallExpectations(CompositionTest*) {}
1140};
1141
1142struct REScreenshotResultVariant : public EmptyScreenshotResultVariant {
1143 using Base = EmptyScreenshotResultVariant;
1144
1145 template <typename Case>
1146 static void setupCallExpectations(CompositionTest* test) {
1147 Base::template setupCallExpectations<Case>(test);
1148 Case::Display::template setupRELayerScreenshotCompositionCallExpectations<Case>(test);
1149 }
1150};
1151
1152/* ------------------------------------------------------------------------
1153 * Composition test case, containing all the variants being tested
1154 */
1155
1156template <typename DisplayCase, typename LayerCase, typename CompositionTypeCase,
1157 typename CompositionResultCase>
1158struct CompositionCase {
1159 using ThisCase =
1160 CompositionCase<DisplayCase, LayerCase, CompositionTypeCase, CompositionResultCase>;
1161 using Display = DisplayCase;
1162 using Layer = LayerCase;
1163 using CompositionType = CompositionTypeCase;
1164 using CompositionResult = CompositionResultCase;
1165
1166 static void setupCommon(CompositionTest* test) {
Peiyong Lin1336e6e2019-05-28 09:23:50 -07001167 Display::template setupPreconditionCallExpectations<ThisCase>(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001168 Display::setupPreconditions(test);
1169
1170 auto layer = Layer::createLayer(test);
1171 Layer::injectLayer(test, layer);
1172 CompositionResult::setupLayerState(test, layer);
1173 }
1174
1175 static void setupForDirtyGeometry(CompositionTest* test) {
1176 setupCommon(test);
1177
1178 Display::template setupCommonCompositionCallExpectations<ThisCase>(test);
1179 CompositionResult::template setupCallExpectationsForDirtyGeometry<ThisCase>(test);
1180 CompositionResult::template setupCallExpectationsForDirtyFrame<ThisCase>(test);
1181 CompositionResult::template setupCallExpectations<ThisCase>(test);
1182 }
1183
1184 static void setupForDirtyFrame(CompositionTest* test) {
1185 setupCommon(test);
1186
1187 Display::template setupCommonCompositionCallExpectations<ThisCase>(test);
1188 CompositionResult::template setupCallExpectationsForDirtyFrame<ThisCase>(test);
1189 CompositionResult::template setupCallExpectations<ThisCase>(test);
1190 }
1191
1192 static void setupForScreenCapture(CompositionTest* test) {
1193 setupCommon(test);
1194
1195 Display::template setupCommonScreensCaptureCallExpectations<ThisCase>(test);
1196 CompositionResult::template setupCallExpectations<ThisCase>(test);
1197 }
1198
1199 static void cleanup(CompositionTest* test) {
1200 Layer::cleanupInjectedLayers(test);
1201
Peiyong Linbdd08cc2019-12-17 21:35:14 -08001202 for (auto& displayData : test->mFlinger.mutableHwcDisplayData()) {
1203 static_cast<TestableSurfaceFlinger::HWC2Display*>(displayData.second.hwcDisplay.get())
1204 ->mutableLayers()
1205 .clear();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001206 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001207 }
1208};
1209
1210/* ------------------------------------------------------------------------
1211 * Composition cases to test
1212 */
1213
1214TEST_F(CompositionTest, noLayersDoesMinimalWorkWithDirtyGeometry) {
1215 displayRefreshCompositionDirtyGeometry<
1216 CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant,
1217 NoCompositionResultVariant>>();
1218}
1219
1220TEST_F(CompositionTest, noLayersDoesMinimalWorkWithDirtyFrame) {
1221 displayRefreshCompositionDirtyFrame<
1222 CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant,
1223 NoCompositionResultVariant>>();
1224}
1225
1226TEST_F(CompositionTest, noLayersDoesMinimalWorkToCaptureScreen) {
1227 captureScreenComposition<
1228 CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant,
1229 EmptyScreenshotResultVariant>>();
1230}
1231
1232/* ------------------------------------------------------------------------
1233 * Simple buffer layers
1234 */
1235
1236TEST_F(CompositionTest, HWCComposedNormalBufferLayerWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001237 displayRefreshCompositionDirtyGeometry<CompositionCase<
1238 DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1239 KeepCompositionTypeVariant<
1240 aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
1241 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001242}
1243
1244TEST_F(CompositionTest, HWCComposedNormalBufferLayerWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001245 displayRefreshCompositionDirtyFrame<CompositionCase<
1246 DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1247 KeepCompositionTypeVariant<
1248 aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
1249 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001250}
1251
1252TEST_F(CompositionTest, REComposedNormalBufferLayer) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001253 displayRefreshCompositionDirtyFrame<CompositionCase<
1254 DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1255 ChangeCompositionTypeVariant<
1256 aidl::android::hardware::graphics::composer3::Composition::DEVICE,
1257 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1258 RECompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001259}
1260
1261TEST_F(CompositionTest, captureScreenNormalBufferLayer) {
1262 captureScreenComposition<
1263 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1264 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1265}
1266
1267/* ------------------------------------------------------------------------
1268 * Single-color layers
1269 */
1270
Vishnu Nairfa247b12020-02-11 08:58:26 -08001271TEST_F(CompositionTest, HWCComposedEffectLayerWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001272 displayRefreshCompositionDirtyGeometry<CompositionCase<
1273 DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
1274 KeepCompositionTypeVariant<
1275 aidl::android::hardware::graphics::composer3::Composition::SOLID_COLOR>,
1276 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001277}
1278
Vishnu Nairfa247b12020-02-11 08:58:26 -08001279TEST_F(CompositionTest, HWCComposedEffectLayerWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001280 displayRefreshCompositionDirtyFrame<CompositionCase<
1281 DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
1282 KeepCompositionTypeVariant<
1283 aidl::android::hardware::graphics::composer3::Composition::SOLID_COLOR>,
1284 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001285}
1286
Vishnu Nairfa247b12020-02-11 08:58:26 -08001287TEST_F(CompositionTest, REComposedEffectLayer) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001288 displayRefreshCompositionDirtyFrame<CompositionCase<
1289 DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
1290 ChangeCompositionTypeVariant<
1291 aidl::android::hardware::graphics::composer3::Composition::SOLID_COLOR,
1292 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1293 RECompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001294}
1295
Vishnu Nairfa247b12020-02-11 08:58:26 -08001296TEST_F(CompositionTest, captureScreenEffectLayer) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001297 captureScreenComposition<
Vishnu Nairfa247b12020-02-11 08:58:26 -08001298 CompositionCase<DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001299 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1300}
1301
1302/* ------------------------------------------------------------------------
1303 * Layers with sideband buffers
1304 */
1305
1306TEST_F(CompositionTest, HWCComposedSidebandBufferLayerWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001307 displayRefreshCompositionDirtyGeometry<CompositionCase<
1308 DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1309 KeepCompositionTypeVariant<
1310 aidl::android::hardware::graphics::composer3::Composition::SIDEBAND>,
1311 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001312}
1313
1314TEST_F(CompositionTest, HWCComposedSidebandBufferLayerWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001315 displayRefreshCompositionDirtyFrame<CompositionCase<
1316 DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1317 KeepCompositionTypeVariant<
1318 aidl::android::hardware::graphics::composer3::Composition::SIDEBAND>,
1319 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001320}
1321
1322TEST_F(CompositionTest, REComposedSidebandBufferLayer) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001323 displayRefreshCompositionDirtyFrame<CompositionCase<
1324 DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1325 ChangeCompositionTypeVariant<
1326 aidl::android::hardware::graphics::composer3::Composition::SIDEBAND,
1327 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1328 RECompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001329}
1330
1331TEST_F(CompositionTest, captureScreenSidebandBufferLayer) {
1332 captureScreenComposition<
1333 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1334 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1335}
1336
1337/* ------------------------------------------------------------------------
1338 * Layers with ISurfaceComposerClient::eSecure, on a secure display
1339 */
1340
1341TEST_F(CompositionTest, HWCComposedSecureBufferLayerWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001342 displayRefreshCompositionDirtyGeometry<CompositionCase<
1343 DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1344 KeepCompositionTypeVariant<
1345 aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
1346 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001347}
1348
1349TEST_F(CompositionTest, HWCComposedSecureBufferLayerWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001350 displayRefreshCompositionDirtyFrame<CompositionCase<
1351 DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1352 KeepCompositionTypeVariant<
1353 aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
1354 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001355}
1356
1357TEST_F(CompositionTest, REComposedSecureBufferLayer) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001358 displayRefreshCompositionDirtyFrame<CompositionCase<
1359 DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1360 ChangeCompositionTypeVariant<
1361 aidl::android::hardware::graphics::composer3::Composition::DEVICE,
1362 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1363 RECompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001364}
1365
1366TEST_F(CompositionTest, captureScreenSecureBufferLayerOnSecureDisplay) {
1367 captureScreenComposition<
1368 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1369 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1370}
1371
1372/* ------------------------------------------------------------------------
1373 * Layers with ISurfaceComposerClient::eSecure, on a non-secure display
1374 */
1375
1376TEST_F(CompositionTest, HWCComposedSecureBufferLayerOnInsecureDisplayWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001377 displayRefreshCompositionDirtyGeometry<CompositionCase<
1378 InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1379 KeepCompositionTypeVariant<
1380 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1381 ForcedClientCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001382}
1383
1384TEST_F(CompositionTest, HWCComposedSecureBufferLayerOnInsecureDisplayWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001385 displayRefreshCompositionDirtyFrame<CompositionCase<
1386 InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1387 KeepCompositionTypeVariant<
1388 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1389 ForcedClientCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001390}
1391
1392TEST_F(CompositionTest, captureScreenSecureBufferLayerOnInsecureDisplay) {
1393 captureScreenComposition<
1394 CompositionCase<InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1395 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1396}
1397
1398/* ------------------------------------------------------------------------
Garfield Tande619fa2020-10-02 17:13:53 -07001399 * Layers with a parent layer with ISurfaceComposerClient::eSecure, on a non-secure display
1400 */
1401
1402TEST_F(CompositionTest,
1403 HWCComposedBufferLayerWithSecureParentLayerOnInsecureDisplayWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001404 displayRefreshCompositionDirtyGeometry<CompositionCase<
1405 InsecureDisplaySetupVariant,
1406 ChildLayerVariant<BufferLayerVariant<ParentSecureLayerProperties>,
1407 ContainerLayerVariant<SecureLayerProperties>>,
1408 KeepCompositionTypeVariant<
1409 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1410 ForcedClientCompositionResultVariant>>();
Garfield Tande619fa2020-10-02 17:13:53 -07001411}
1412
1413TEST_F(CompositionTest,
1414 HWCComposedBufferLayerWithSecureParentLayerOnInsecureDisplayWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001415 displayRefreshCompositionDirtyFrame<CompositionCase<
1416 InsecureDisplaySetupVariant,
1417 ChildLayerVariant<BufferLayerVariant<ParentSecureLayerProperties>,
1418 ContainerLayerVariant<SecureLayerProperties>>,
1419 KeepCompositionTypeVariant<
1420 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1421 ForcedClientCompositionResultVariant>>();
Garfield Tande619fa2020-10-02 17:13:53 -07001422}
1423
1424TEST_F(CompositionTest, captureScreenBufferLayerWithSecureParentLayerOnInsecureDisplay) {
1425 captureScreenComposition<
1426 CompositionCase<InsecureDisplaySetupVariant,
1427 ChildLayerVariant<BufferLayerVariant<ParentSecureLayerProperties>,
1428 ContainerLayerVariant<SecureLayerProperties>>,
1429 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1430}
1431
1432/* ------------------------------------------------------------------------
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001433 * Cursor layers
1434 */
1435
1436TEST_F(CompositionTest, HWCComposedCursorLayerWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001437 displayRefreshCompositionDirtyGeometry<CompositionCase<
1438 DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1439 KeepCompositionTypeVariant<
1440 aidl::android::hardware::graphics::composer3::Composition::CURSOR>,
1441 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001442}
1443
1444TEST_F(CompositionTest, HWCComposedCursorLayerWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001445 displayRefreshCompositionDirtyFrame<CompositionCase<
1446 DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1447 KeepCompositionTypeVariant<
1448 aidl::android::hardware::graphics::composer3::Composition::CURSOR>,
1449 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001450}
1451
1452TEST_F(CompositionTest, REComposedCursorLayer) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001453 displayRefreshCompositionDirtyFrame<CompositionCase<
1454 DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1455 ChangeCompositionTypeVariant<
1456 aidl::android::hardware::graphics::composer3::Composition::CURSOR,
1457 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1458 RECompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001459}
1460
1461TEST_F(CompositionTest, captureScreenCursorLayer) {
1462 captureScreenComposition<
1463 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1464 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1465}
1466
1467/* ------------------------------------------------------------------------
1468 * Simple buffer layer on a display which is powered off.
1469 */
1470
1471TEST_F(CompositionTest, displayOffHWCComposedNormalBufferLayerWithDirtyGeometry) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001472 mDisplayOff = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001473 displayRefreshCompositionDirtyGeometry<CompositionCase<
1474 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001475 KeepCompositionTypeVariant<
1476 aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001477 HwcCompositionResultVariant>>();
1478}
1479
1480TEST_F(CompositionTest, displayOffHWCComposedNormalBufferLayerWithDirtyFrame) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001481 mDisplayOff = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001482 displayRefreshCompositionDirtyFrame<CompositionCase<
1483 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001484 KeepCompositionTypeVariant<
1485 aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001486 HwcCompositionResultVariant>>();
1487}
1488
1489TEST_F(CompositionTest, displayOffREComposedNormalBufferLayer) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001490 mDisplayOff = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001491 displayRefreshCompositionDirtyFrame<CompositionCase<
1492 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001493 ChangeCompositionTypeVariant<
1494 aidl::android::hardware::graphics::composer3::Composition::DEVICE,
1495 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001496 RECompositionResultVariant>>();
1497}
1498
1499TEST_F(CompositionTest, captureScreenNormalBufferLayerOnPoweredOffDisplay) {
1500 captureScreenComposition<CompositionCase<
1501 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1502 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1503}
1504
Lloyd Pique4fe29402019-08-12 16:51:24 -07001505/* ------------------------------------------------------------------------
1506 * Client composition forced through debug/developer settings
1507 */
1508
1509TEST_F(CompositionTest, DebugOptionForcingClientCompositionOfBufferLayerWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001510 displayRefreshCompositionDirtyGeometry<CompositionCase<
1511 DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1512 KeepCompositionTypeVariant<
1513 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1514 ForcedClientCompositionViaDebugOptionResultVariant>>();
Lloyd Pique4fe29402019-08-12 16:51:24 -07001515}
1516
1517TEST_F(CompositionTest, DebugOptionForcingClientCompositionOfBufferLayerWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001518 displayRefreshCompositionDirtyFrame<CompositionCase<
1519 DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1520 KeepCompositionTypeVariant<
1521 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1522 ForcedClientCompositionViaDebugOptionResultVariant>>();
Lloyd Pique4fe29402019-08-12 16:51:24 -07001523}
1524
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001525} // namespace
1526} // namespace android
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -08001527
1528// TODO(b/129481165): remove the #pragma below and fix conversion issues
Marin Shalamanovbed7fd32020-12-21 20:02:20 +01001529#pragma clang diagnostic pop // ignored "-Wconversion -Wextra"