blob: 9c16e4cba87a2ec64b1283d8c4d519eeced2a4a4 [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
Garfield Tande619fa2020-10-02 17:13:53 -070040#include "ContainerLayer.h"
Marin Shalamanovf6b5d182020-06-12 02:08:51 +020041#include "DisplayRenderArea.h"
Vishnu Nairfa247b12020-02-11 08:58:26 -080042#include "EffectLayer.h"
Lloyd Piqued6b579f2018-04-06 15:29:10 -070043#include "Layer.h"
Lloyd Piqued6b579f2018-04-06 15:29:10 -070044#include "TestableSurfaceFlinger.h"
45#include "mock/DisplayHardware/MockComposer.h"
Lloyd Pique9370a482019-10-03 17:58:30 -070046#include "mock/DisplayHardware/MockPowerAdvisor.h"
Lloyd Piqued6b579f2018-04-06 15:29:10 -070047#include "mock/MockEventThread.h"
Alec Mourie4034bb2019-11-19 12:45:54 -080048#include "mock/MockTimeStats.h"
Ady Abraham8cb21882020-08-26 18:22:05 -070049#include "mock/MockVsyncController.h"
Alec Mouriba013fa2018-10-16 12:43:11 -070050#include "mock/system/window/MockNativeWindow.h"
Lloyd Piqued6b579f2018-04-06 15:29:10 -070051
52namespace android {
53namespace {
54
Peiyong Line9d809e2020-04-14 13:10:48 -070055namespace hal = android::hardware::graphics::composer::hal;
56
Peiyong Lin65248e02020-04-18 21:15:07 -070057using hal::Error;
58using hal::IComposer;
59using hal::IComposerClient;
60using hal::PowerMode;
61using hal::Transform;
62
Ady Abrahamde549d42022-01-26 19:19:17 -080063using aidl::android::hardware::graphics::composer3::Capability;
64
Lloyd Piqued6b579f2018-04-06 15:29:10 -070065using testing::_;
David Sodman15094112018-10-11 09:39:37 -070066using testing::AtLeast;
Lloyd Piqued6b579f2018-04-06 15:29:10 -070067using testing::DoAll;
68using testing::IsNull;
69using testing::Mock;
Lloyd Piqued6b579f2018-04-06 15:29:10 -070070using testing::Return;
71using testing::ReturnRef;
72using testing::SetArgPointee;
73
Lloyd Piqued6b579f2018-04-06 15:29:10 -070074using FakeHwcDisplayInjector = TestableSurfaceFlinger::FakeHwcDisplayInjector;
75using FakeDisplayDeviceInjector = TestableSurfaceFlinger::FakeDisplayDeviceInjector;
76
Peiyong Line9d809e2020-04-14 13:10:48 -070077constexpr hal::HWDisplayId HWC_DISPLAY = FakeHwcDisplayInjector::DEFAULT_HWC_DISPLAY_ID;
78constexpr hal::HWLayerId HWC_LAYER = 5000;
Lloyd Piqued6b579f2018-04-06 15:29:10 -070079constexpr Transform DEFAULT_TRANSFORM = static_cast<Transform>(0);
80
Dominik Laskowskif1833852021-03-23 15:06:50 -070081constexpr PhysicalDisplayId DEFAULT_DISPLAY_ID = PhysicalDisplayId::fromPort(42u);
Lloyd Piqued6b579f2018-04-06 15:29:10 -070082constexpr int DEFAULT_DISPLAY_WIDTH = 1920;
83constexpr int DEFAULT_DISPLAY_HEIGHT = 1024;
84
Lloyd Piqued6b579f2018-04-06 15:29:10 -070085constexpr int DEFAULT_TEXTURE_ID = 6000;
Dominik Laskowski29fa1462021-04-27 15:51:50 -070086constexpr ui::LayerStack LAYER_STACK{7000u};
Lloyd Piqued6b579f2018-04-06 15:29:10 -070087
88constexpr int DEFAULT_DISPLAY_MAX_LUMINANCE = 500;
89
90constexpr int DEFAULT_SIDEBAND_STREAM = 51;
91
Ady Abrahamdc011a92021-12-21 14:06:44 -080092MATCHER(IsIdentityMatrix, "") {
93 constexpr auto kIdentity = mat4();
94 return (mat4(arg) == kIdentity);
95}
96
Lloyd Piqued6b579f2018-04-06 15:29:10 -070097class CompositionTest : public testing::Test {
98public:
99 CompositionTest() {
100 const ::testing::TestInfo* const test_info =
101 ::testing::UnitTest::GetInstance()->current_test_info();
102 ALOGD("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name());
103
Ana Krulecafb45842019-02-13 13:33:03 -0800104 setupScheduler();
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700105
Alec Mourif6fd29e2018-11-17 04:56:41 +0000106 EXPECT_CALL(*mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
107 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_WIDTH), Return(0)));
108 EXPECT_CALL(*mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
109 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_HEIGHT), Return(0)));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700110
111 mFlinger.setupRenderEngine(std::unique_ptr<renderengine::RenderEngine>(mRenderEngine));
Alec Mourie4034bb2019-11-19 12:45:54 -0800112 mFlinger.setupTimeStats(std::shared_ptr<TimeStats>(mTimeStats));
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800113
114 mComposer = new Hwc2::mock::Composer();
Xiang Wang839fe5b2022-04-04 17:39:38 +0000115 mPowerAdvisor = new Hwc2::mock::PowerAdvisor();
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800116 mFlinger.setupComposer(std::unique_ptr<Hwc2::Composer>(mComposer));
Xiang Wang839fe5b2022-04-04 17:39:38 +0000117 mFlinger.setupPowerAdvisor(std::unique_ptr<Hwc2::PowerAdvisor>(mPowerAdvisor));
Garfield Tan9c9c1912021-07-19 12:02:16 -0700118 mFlinger.mutableMaxRenderTargetSize() = 16384;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700119 }
120
121 ~CompositionTest() {
122 const ::testing::TestInfo* const test_info =
123 ::testing::UnitTest::GetInstance()->current_test_info();
124 ALOGD("**** Tearing down after %s.%s\n", test_info->test_case_name(), test_info->name());
125 }
126
Ana Krulecafb45842019-02-13 13:33:03 -0800127 void setupScheduler() {
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700128 auto eventThread = std::make_unique<mock::EventThread>();
129 auto sfEventThread = std::make_unique<mock::EventThread>();
Ana Krulecafb45842019-02-13 13:33:03 -0800130
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700131 EXPECT_CALL(*eventThread, registerDisplayEventConnection(_));
Dominik Laskowski98041832019-08-01 18:35:59 -0700132 EXPECT_CALL(*eventThread, createEventConnection(_, _))
Ady Abraham62f216c2020-10-13 19:07:23 -0700133 .WillOnce(Return(new EventThreadConnection(eventThread.get(), /*callingUid=*/0,
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 Abraham62f216c2020-10-13 19:07:23 -0700138 .WillOnce(Return(new EventThreadConnection(sfEventThread.get(), /*callingUid=*/0,
139 ResyncCallback())));
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700140
Ady Abraham8cb21882020-08-26 18:22:05 -0700141 auto vsyncController = std::make_unique<mock::VsyncController>();
142 auto vsyncTracker = std::make_unique<mock::VSyncTracker>();
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700143
Ady Abraham8cb21882020-08-26 18:22:05 -0700144 EXPECT_CALL(*vsyncTracker, nextAnticipatedVSyncTimeFrom(_)).WillRepeatedly(Return(0));
145 EXPECT_CALL(*vsyncTracker, currentPeriod())
Marin Shalamanov045b7002021-01-07 16:56:24 +0100146 .WillRepeatedly(Return(FakeHwcDisplayInjector::DEFAULT_VSYNC_PERIOD));
Ady Abraham8cb21882020-08-26 18:22:05 -0700147 EXPECT_CALL(*vsyncTracker, nextAnticipatedVSyncTimeFrom(_)).WillRepeatedly(Return(0));
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -0700148
Ady Abraham8cb21882020-08-26 18:22:05 -0700149 mFlinger.setupScheduler(std::move(vsyncController), std::move(vsyncTracker),
Dominik Laskowski83bd7712022-01-07 14:30:53 -0800150 std::move(eventThread), std::move(sfEventThread),
151 TestableSurfaceFlinger::SchedulerCallbackImpl::kNoOp,
152 TestableSurfaceFlinger::kTwoDisplayModes);
Ana Krulecafb45842019-02-13 13:33:03 -0800153 }
154
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700155 void setupForceGeometryDirty() {
156 // TODO: This requires the visible region and other related
157 // state to be set, and is problematic for BufferLayers since they are
158 // not visible without a buffer (and setting up a buffer looks like a
159 // pain)
160 // mFlinger.mutableVisibleRegionsDirty() = true;
161
Dominik Laskowski8da6b0e2021-05-12 15:34:13 -0700162 mFlinger.mutableGeometryDirty() = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700163 }
164
165 template <typename Case>
166 void displayRefreshCompositionDirtyGeometry();
167
168 template <typename Case>
169 void displayRefreshCompositionDirtyFrame();
170
171 template <typename Case>
172 void captureScreenComposition();
173
Ady Abrahamde549d42022-01-26 19:19:17 -0800174 std::unordered_set<Capability> mDefaultCapabilities = {Capability::SIDEBAND_STREAM};
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700175
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800176 bool mDisplayOff = false;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700177 TestableSurfaceFlinger mFlinger;
178 sp<DisplayDevice> mDisplay;
179 sp<DisplayDevice> mExternalDisplay;
Lloyd Pique542307f2018-10-19 13:24:08 -0700180 sp<compositionengine::mock::DisplaySurface> mDisplaySurface =
181 new compositionengine::mock::DisplaySurface();
Alec Mouriba013fa2018-10-16 12:43:11 -0700182 mock::NativeWindow* mNativeWindow = new mock::NativeWindow();
Garfield Tande619fa2020-10-02 17:13:53 -0700183 std::vector<sp<Layer>> mAuxiliaryLayers;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700184
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800185 sp<GraphicBuffer> mBuffer = new GraphicBuffer();
186 ANativeWindowBuffer* mNativeWindowBuffer = mBuffer->getNativeBuffer();
187
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700188 Hwc2::mock::Composer* mComposer = nullptr;
189 renderengine::mock::RenderEngine* mRenderEngine = new renderengine::mock::RenderEngine();
Alec Mourie4034bb2019-11-19 12:45:54 -0800190 mock::TimeStats* mTimeStats = new mock::TimeStats();
Xiang Wang839fe5b2022-04-04 17:39:38 +0000191 Hwc2::mock::PowerAdvisor* mPowerAdvisor = nullptr;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700192
193 sp<Fence> mClientTargetAcquireFence = Fence::NO_FENCE;
194
Alec Mouria90a5702021-04-16 16:36:21 +0000195 std::shared_ptr<renderengine::ExternalTexture> mCaptureScreenBuffer;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700196};
197
198template <typename LayerCase>
199void CompositionTest::displayRefreshCompositionDirtyGeometry() {
200 setupForceGeometryDirty();
201 LayerCase::setupForDirtyGeometry(this);
202
203 // --------------------------------------------------------------------
204 // Invocation
205
Dominik Laskowskie0e0cde2021-07-30 10:42:05 -0700206 mFlinger.commitAndComposite();
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700207
208 LayerCase::cleanup(this);
209}
210
211template <typename LayerCase>
212void CompositionTest::displayRefreshCompositionDirtyFrame() {
213 LayerCase::setupForDirtyFrame(this);
214
215 // --------------------------------------------------------------------
216 // Invocation
217
Dominik Laskowskie0e0cde2021-07-30 10:42:05 -0700218 mFlinger.commitAndComposite();
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700219
220 LayerCase::cleanup(this);
221}
222
223template <typename LayerCase>
224void CompositionTest::captureScreenComposition() {
225 LayerCase::setupForScreenCapture(this);
226
227 const Rect sourceCrop(0, 0, DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700228 constexpr bool forSystem = true;
Lucas Dupin9d763b72020-04-20 18:42:31 -0700229 constexpr bool regionSampling = false;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700230
Marin Shalamanov1c434292020-06-12 01:47:29 +0200231 auto renderArea = DisplayRenderArea::create(mDisplay, sourceCrop, sourceCrop.getSize(),
232 ui::Dataspace::V0_SRGB, ui::Transform::ROT_0);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700233
234 auto traverseLayers = [this](const LayerVector::Visitor& visitor) {
chaviw4b9d5e12020-08-04 18:30:35 -0700235 return mFlinger.traverseLayersInLayerStack(mDisplay->getLayerStack(),
236 CaptureArgs::UNSET_UID, visitor);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700237 };
238
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700239 const uint32_t usage = GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN |
240 GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_TEXTURE;
Vishnu Nairdbbe3852022-01-12 20:22:11 -0800241 mCaptureScreenBuffer =
242 std::make_shared<renderengine::mock::FakeExternalTexture>(renderArea->getReqWidth(),
243 renderArea->getReqHeight(),
244 HAL_PIXEL_FORMAT_RGBA_8888, 1,
245 usage);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700246
Dominik Laskowskibb448ce2022-05-07 15:52:55 -0700247 auto future = mFlinger.renderScreenImpl(*renderArea, traverseLayers, mCaptureScreenBuffer,
Robert Carr12a3b9b2022-03-10 09:55:29 -0800248 forSystem, regionSampling);
Dominik Laskowskibb448ce2022-05-07 15:52:55 -0700249 ASSERT_TRUE(future.valid());
250 const auto fenceResult = future.get();
Sally Qi59a9f502021-10-12 18:53:23 +0000251
Dominik Laskowskibb448ce2022-05-07 15:52:55 -0700252 EXPECT_EQ(NO_ERROR, fenceStatus(fenceResult));
253 if (fenceResult.ok()) {
254 fenceResult.value()->waitForever(LOG_TAG);
Sally Qi59a9f502021-10-12 18:53:23 +0000255 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700256
257 LayerCase::cleanup(this);
258}
259
Sally Qi4cabdd02021-08-05 16:45:57 -0700260template <class T>
261std::future<T> futureOf(T obj) {
262 std::promise<T> resultPromise;
263 std::future<T> resultFuture = resultPromise.get_future();
264 resultPromise.set_value(std::move(obj));
265 return resultFuture;
266}
267
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700268/* ------------------------------------------------------------------------
269 * Variants for each display configuration which can be tested
270 */
271
272template <typename Derived>
273struct BaseDisplayVariant {
274 static constexpr bool IS_SECURE = true;
Peiyong Lin65248e02020-04-18 21:15:07 -0700275 static constexpr hal::PowerMode INIT_POWER_MODE = hal::PowerMode::ON;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700276
277 static void setupPreconditions(CompositionTest* test) {
Peiyong Lin65248e02020-04-18 21:15:07 -0700278 EXPECT_CALL(*test->mComposer, setPowerMode(HWC_DISPLAY, Derived::INIT_POWER_MODE))
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700279 .WillOnce(Return(Error::NONE));
Alec Mouriba013fa2018-10-16 12:43:11 -0700280
Peiyong Line9d809e2020-04-14 13:10:48 -0700281 FakeHwcDisplayInjector(DEFAULT_DISPLAY_ID, hal::DisplayType::PHYSICAL, true /* isPrimary */)
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700282 .setCapabilities(&test->mDefaultCapabilities)
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700283 .setPowerMode(Derived::INIT_POWER_MODE)
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700284 .inject(&test->mFlinger, test->mComposer);
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800285 Mock::VerifyAndClear(test->mComposer);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700286
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800287 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
288 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_WIDTH), Return(0)));
289 EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
290 .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_HEIGHT), Return(0)));
291 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT)).Times(1);
292 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_API_CONNECT)).Times(1);
293 EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_USAGE64)).Times(1);
Lloyd Pique9370a482019-10-03 17:58:30 -0700294
295 const ::testing::TestInfo* const test_info =
296 ::testing::UnitTest::GetInstance()->current_test_info();
297
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800298 auto ceDisplayArgs = compositionengine::DisplayCreationArgsBuilder()
299 .setId(DEFAULT_DISPLAY_ID)
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800300 .setPixels({DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT})
301 .setIsSecure(Derived::IS_SECURE)
Xiang Wang839fe5b2022-04-04 17:39:38 +0000302 .setPowerAdvisor(test->mPowerAdvisor)
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800303 .setName(std::string("Injected display for ") +
304 test_info->test_case_name() + "." + test_info->name())
305 .build();
Lloyd Pique9370a482019-10-03 17:58:30 -0700306
307 auto compositionDisplay =
308 compositionengine::impl::createDisplay(test->mFlinger.getCompositionEngine(),
309 ceDisplayArgs);
310
Marin Shalamanov700e6392020-02-12 20:22:26 +0100311 test->mDisplay = FakeDisplayDeviceInjector(test->mFlinger, compositionDisplay,
Marin Shalamanov228f46b2021-01-28 21:11:45 +0100312 ui::DisplayConnectionType::Internal, HWC_DISPLAY,
Marin Shalamanov700e6392020-02-12 20:22:26 +0100313 true /* isPrimary */)
314 .setDisplaySurface(test->mDisplaySurface)
315 .setNativeWindow(test->mNativeWindow)
316 .setSecure(Derived::IS_SECURE)
317 .setPowerMode(Derived::INIT_POWER_MODE)
318 .inject();
Lloyd Pique86fa3db2019-02-04 18:46:01 -0800319 Mock::VerifyAndClear(test->mNativeWindow);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700320 test->mDisplay->setLayerStack(LAYER_STACK);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700321 }
322
323 template <typename Case>
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700324 static void setupPreconditionCallExpectations(CompositionTest* test) {
325 EXPECT_CALL(*test->mComposer, getDisplayCapabilities(HWC_DISPLAY, _))
Leon Scroggins III5967aec2021-12-29 11:14:22 -0500326 .WillOnce(DoAll(SetArgPointee<1>(
327 std::vector<aidl::android::hardware::graphics::composer3::
328 DisplayCapability>({})),
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700329 Return(Error::NONE)));
330 }
331
332 template <typename Case>
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700333 static void setupCommonCompositionCallExpectations(CompositionTest* test) {
Ady Abrahamdc011a92021-12-21 14:06:44 -0800334 EXPECT_CALL(*test->mComposer, setColorTransform(HWC_DISPLAY, IsIdentityMatrix())).Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700335 EXPECT_CALL(*test->mComposer, getDisplayRequests(HWC_DISPLAY, _, _, _)).Times(1);
336 EXPECT_CALL(*test->mComposer, acceptDisplayChanges(HWC_DISPLAY)).Times(1);
337 EXPECT_CALL(*test->mComposer, presentDisplay(HWC_DISPLAY, _)).Times(1);
338 EXPECT_CALL(*test->mComposer, getReleaseFences(HWC_DISPLAY, _, _)).Times(1);
339
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700340 EXPECT_CALL(*test->mDisplaySurface, onFrameCommitted()).Times(1);
341 EXPECT_CALL(*test->mDisplaySurface, advanceFrame()).Times(1);
342
343 Case::CompositionType::setupHwcSetCallExpectations(test);
344 Case::CompositionType::setupHwcGetCallExpectations(test);
345 }
346
347 template <typename Case>
348 static void setupCommonScreensCaptureCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000349 EXPECT_CALL(*test->mRenderEngine, drawLayers)
Sally Qi4cabdd02021-08-05 16:45:57 -0700350 .WillRepeatedly([&](const renderengine::DisplaySettings& displaySettings,
Sally Qi59a9f502021-10-12 18:53:23 +0000351 const std::vector<renderengine::LayerSettings>&,
Sally Qi4cabdd02021-08-05 16:45:57 -0700352 const std::shared_ptr<renderengine::ExternalTexture>&,
Sally Qi59a9f502021-10-12 18:53:23 +0000353 const bool, base::unique_fd&&)
Sally Qi4cabdd02021-08-05 16:45:57 -0700354 -> std::future<renderengine::RenderEngineResult> {
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);
Sally Qi4cabdd02021-08-05 16:45:57 -0700360 return futureOf<renderengine::RenderEngineResult>(
361 {NO_ERROR, base::unique_fd()});
Lloyd Pique9370a482019-10-03 17:58:30 -0700362 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700363 }
364
365 static void setupNonEmptyFrameCompositionCallExpectations(CompositionTest* test) {
366 EXPECT_CALL(*test->mDisplaySurface, beginFrame(true)).Times(1);
367 }
368
369 static void setupEmptyFrameCompositionCallExpectations(CompositionTest* test) {
370 EXPECT_CALL(*test->mDisplaySurface, beginFrame(false)).Times(1);
371 }
372
373 static void setupHwcCompositionCallExpectations(CompositionTest* test) {
Ady Abraham43065bd2021-12-10 17:22:15 -0800374 EXPECT_CALL(*test->mComposer, presentOrValidateDisplay(HWC_DISPLAY, _, _, _, _, _))
375 .Times(1);
Lloyd Pique66d68602019-02-13 14:23:31 -0800376
Lloyd Pique542307f2018-10-19 13:24:08 -0700377 EXPECT_CALL(*test->mDisplaySurface,
Dominik Laskowskif5d0ea52021-09-26 17:27:01 -0700378 prepareFrame(compositionengine::DisplaySurface::CompositionType::Hwc))
Lloyd Pique542307f2018-10-19 13:24:08 -0700379 .Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700380 }
381
Lloyd Pique66d68602019-02-13 14:23:31 -0800382 static void setupHwcClientCompositionCallExpectations(CompositionTest* test) {
Ady Abraham43065bd2021-12-10 17:22:15 -0800383 EXPECT_CALL(*test->mComposer, presentOrValidateDisplay(HWC_DISPLAY, _, _, _, _, _))
384 .Times(1);
Lloyd Pique66d68602019-02-13 14:23:31 -0800385 }
386
387 static void setupHwcForcedClientCompositionCallExpectations(CompositionTest* test) {
Ady Abraham43065bd2021-12-10 17:22:15 -0800388 EXPECT_CALL(*test->mComposer, validateDisplay(HWC_DISPLAY, _, _, _)).Times(1);
Lloyd Pique66d68602019-02-13 14:23:31 -0800389 }
390
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700391 static void setupRECompositionCallExpectations(CompositionTest* test) {
Lloyd Pique542307f2018-10-19 13:24:08 -0700392 EXPECT_CALL(*test->mDisplaySurface,
Dominik Laskowskif5d0ea52021-09-26 17:27:01 -0700393 prepareFrame(compositionengine::DisplaySurface::CompositionType::Gpu))
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700394 .Times(1);
395 EXPECT_CALL(*test->mDisplaySurface, getClientTargetAcquireFence())
396 .WillRepeatedly(ReturnRef(test->mClientTargetAcquireFence));
397
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800398 EXPECT_CALL(*test->mNativeWindow, queueBuffer(_, _)).WillOnce(Return(0));
399 EXPECT_CALL(*test->mNativeWindow, dequeueBuffer(_, _))
400 .WillOnce(DoAll(SetArgPointee<0>(test->mNativeWindowBuffer), SetArgPointee<1>(-1),
401 Return(0)));
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000402 EXPECT_CALL(*test->mRenderEngine, drawLayers)
Sally Qi4cabdd02021-08-05 16:45:57 -0700403 .WillRepeatedly([&](const renderengine::DisplaySettings& displaySettings,
Sally Qi59a9f502021-10-12 18:53:23 +0000404 const std::vector<renderengine::LayerSettings>&,
Sally Qi4cabdd02021-08-05 16:45:57 -0700405 const std::shared_ptr<renderengine::ExternalTexture>&,
Sally Qi59a9f502021-10-12 18:53:23 +0000406 const bool, base::unique_fd&&)
Sally Qi4cabdd02021-08-05 16:45:57 -0700407 -> std::future<renderengine::RenderEngineResult> {
Lloyd Pique9370a482019-10-03 17:58:30 -0700408 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
409 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
410 displaySettings.physicalDisplay);
411 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
412 displaySettings.clip);
413 EXPECT_EQ(ui::Dataspace::UNKNOWN, displaySettings.outputDataspace);
Sally Qi4cabdd02021-08-05 16:45:57 -0700414 return futureOf<renderengine::RenderEngineResult>(
415 {NO_ERROR, base::unique_fd()});
Lloyd Pique9370a482019-10-03 17:58:30 -0700416 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700417 }
418
419 template <typename Case>
420 static void setupRELayerCompositionCallExpectations(CompositionTest* test) {
421 Case::Layer::setupRECompositionCallExpectations(test);
422 }
423
424 template <typename Case>
425 static void setupRELayerScreenshotCompositionCallExpectations(CompositionTest* test) {
426 Case::Layer::setupREScreenshotCompositionCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700427 }
428};
429
430struct DefaultDisplaySetupVariant : public BaseDisplayVariant<DefaultDisplaySetupVariant> {};
431
432struct InsecureDisplaySetupVariant : public BaseDisplayVariant<InsecureDisplaySetupVariant> {
433 static constexpr bool IS_SECURE = false;
434
435 template <typename Case>
436 static void setupRELayerCompositionCallExpectations(CompositionTest* test) {
437 Case::Layer::setupInsecureRECompositionCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700438 }
439
440 template <typename Case>
441 static void setupRELayerScreenshotCompositionCallExpectations(CompositionTest* test) {
442 Case::Layer::setupInsecureREScreenshotCompositionCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700443 }
444};
445
446struct PoweredOffDisplaySetupVariant : public BaseDisplayVariant<PoweredOffDisplaySetupVariant> {
Peiyong Lin65248e02020-04-18 21:15:07 -0700447 static constexpr hal::PowerMode INIT_POWER_MODE = hal::PowerMode::OFF;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700448
449 template <typename Case>
Peiyong Lin1336e6e2019-05-28 09:23:50 -0700450 static void setupPreconditionCallExpectations(CompositionTest*) {}
451
452 template <typename Case>
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700453 static void setupCommonCompositionCallExpectations(CompositionTest* test) {
454 // TODO: This seems like an unnecessary call if display is powered off.
Ady Abrahamdc011a92021-12-21 14:06:44 -0800455 EXPECT_CALL(*test->mComposer, setColorTransform(HWC_DISPLAY, IsIdentityMatrix())).Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700456
457 // TODO: This seems like an unnecessary call if display is powered off.
458 Case::CompositionType::setupHwcSetCallExpectations(test);
459 }
460
461 static void setupHwcCompositionCallExpectations(CompositionTest*) {}
Lloyd Pique66d68602019-02-13 14:23:31 -0800462 static void setupHwcClientCompositionCallExpectations(CompositionTest*) {}
463 static void setupHwcForcedClientCompositionCallExpectations(CompositionTest*) {}
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700464
465 static void setupRECompositionCallExpectations(CompositionTest* test) {
466 // TODO: This seems like an unnecessary call if display is powered off.
467 EXPECT_CALL(*test->mDisplaySurface, getClientTargetAcquireFence())
468 .WillRepeatedly(ReturnRef(test->mClientTargetAcquireFence));
469 }
470
471 template <typename Case>
472 static void setupRELayerCompositionCallExpectations(CompositionTest*) {}
473};
474
475/* ------------------------------------------------------------------------
476 * Variants for each layer configuration which can be tested
477 */
478
479template <typename LayerProperties>
480struct BaseLayerProperties {
481 static constexpr uint32_t WIDTH = 100;
482 static constexpr uint32_t HEIGHT = 100;
483 static constexpr PixelFormat FORMAT = PIXEL_FORMAT_RGBA_8888;
484 static constexpr uint64_t USAGE =
485 GraphicBuffer::USAGE_SW_READ_NEVER | GraphicBuffer::USAGE_SW_WRITE_NEVER;
486 static constexpr android_dataspace DATASPACE = HAL_DATASPACE_UNKNOWN;
487 static constexpr uint32_t SCALING_MODE = 0;
488 static constexpr uint32_t TRANSFORM = 0;
489 static constexpr uint32_t LAYER_FLAGS = 0;
490 static constexpr float COLOR[] = {1.f, 1.f, 1.f, 1.f};
491 static constexpr IComposerClient::BlendMode BLENDMODE =
492 IComposerClient::BlendMode::PREMULTIPLIED;
493
Vishnu Nairf8a873a2022-06-15 17:34:34 +0000494 static void setupLatchedBuffer(CompositionTest* test, sp<BufferStateLayer> layer) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700495 Mock::VerifyAndClear(test->mRenderEngine);
496
Vishnu Nairf8a873a2022-06-15 17:34:34 +0000497 const auto buffer = std::make_shared<
498 renderengine::mock::FakeExternalTexture>(LayerProperties::WIDTH,
499 LayerProperties::HEIGHT,
500 DEFAULT_TEXTURE_ID,
501 LayerProperties::FORMAT,
502 LayerProperties::USAGE |
503 GraphicBuffer::USAGE_HW_TEXTURE);
504
505 auto& layerDrawingState = test->mFlinger.mutableLayerDrawingState(layer);
506 layerDrawingState.crop = Rect(0, 0, LayerProperties::HEIGHT, LayerProperties::WIDTH);
507 layerDrawingState.buffer = buffer;
508 layerDrawingState.acquireFence = Fence::NO_FENCE;
509 layerDrawingState.dataspace = ui::Dataspace::UNKNOWN;
510 layer->setSurfaceDamageRegion(
511 Region(Rect(LayerProperties::HEIGHT, LayerProperties::WIDTH)));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700512
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700513 bool ignoredRecomputeVisibleRegions;
Vishnu Nair397a0e32022-07-26 00:01:48 +0000514 layer->latchBuffer(ignoredRecomputeVisibleRegions, 0);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700515 Mock::VerifyAndClear(test->mRenderEngine);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700516 }
517
Vishnu Nairf8a873a2022-06-15 17:34:34 +0000518 static void setupLayerState(CompositionTest* test, sp<BufferStateLayer> layer) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700519 setupLatchedBuffer(test, layer);
520 }
521
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700522 static void setupHwcSetGeometryCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800523 if (!test->mDisplayOff) {
524 // TODO: Coverage of other values
525 EXPECT_CALL(*test->mComposer,
526 setLayerBlendMode(HWC_DISPLAY, HWC_LAYER, LayerProperties::BLENDMODE))
527 .Times(1);
528 // TODO: Coverage of other values for origin
529 EXPECT_CALL(*test->mComposer,
530 setLayerDisplayFrame(HWC_DISPLAY, HWC_LAYER,
531 IComposerClient::Rect({0, 0, LayerProperties::WIDTH,
532 LayerProperties::HEIGHT})))
533 .Times(1);
534 EXPECT_CALL(*test->mComposer,
535 setLayerPlaneAlpha(HWC_DISPLAY, HWC_LAYER, LayerProperties::COLOR[3]))
536 .Times(1);
537 // TODO: Coverage of other values
538 EXPECT_CALL(*test->mComposer, setLayerZOrder(HWC_DISPLAY, HWC_LAYER, 0u)).Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700539
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800540 // These expectations retire on saturation as the code path these
541 // expectations are for appears to make an extra call to them.
542 // TODO: Investigate this extra call
543 EXPECT_CALL(*test->mComposer,
544 setLayerTransform(HWC_DISPLAY, HWC_LAYER, DEFAULT_TRANSFORM))
545 .Times(AtLeast(1))
546 .RetiresOnSaturation();
547 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700548 }
549
550 static void setupHwcSetSourceCropBufferCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800551 if (!test->mDisplayOff) {
552 EXPECT_CALL(*test->mComposer,
553 setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER,
554 IComposerClient::FRect({0.f, 0.f, LayerProperties::WIDTH,
555 LayerProperties::HEIGHT})))
556 .Times(1);
557 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700558 }
559
560 static void setupHwcSetSourceCropColorCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800561 if (!test->mDisplayOff) {
562 EXPECT_CALL(*test->mComposer,
563 setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER,
564 IComposerClient::FRect({0.f, 0.f, 0.f, 0.f})))
565 .Times(1);
566 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700567 }
568
569 static void setupHwcSetPerFrameCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800570 if (!test->mDisplayOff) {
571 EXPECT_CALL(*test->mComposer,
572 setLayerVisibleRegion(HWC_DISPLAY, HWC_LAYER,
573 std::vector<IComposerClient::Rect>(
574 {IComposerClient::Rect(
575 {0, 0, LayerProperties::WIDTH,
576 LayerProperties::HEIGHT})})))
577 .Times(1);
578 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700579 }
580
581 static void setupHwcSetPerFrameColorCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800582 if (!test->mDisplayOff) {
583 EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _))
584 .Times(1);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700585
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800586 // TODO: use COLOR
587 EXPECT_CALL(*test->mComposer,
588 setLayerColor(HWC_DISPLAY, HWC_LAYER,
Ady Abraham6e60b142022-01-06 18:10:35 -0800589 aidl::android::hardware::graphics::composer3::Color(
590 {1.0f, 1.0f, 1.0f, 1.0f})))
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800591 .Times(1);
592 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700593 }
594
595 static void setupHwcSetPerFrameBufferCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800596 if (!test->mDisplayOff) {
597 EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _))
598 .Times(1);
599 EXPECT_CALL(*test->mComposer, setLayerBuffer(HWC_DISPLAY, HWC_LAYER, _, _, _)).Times(1);
600 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700601 }
602
603 static void setupREBufferCompositionCommonCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000604 EXPECT_CALL(*test->mRenderEngine, drawLayers)
Sally Qi4cabdd02021-08-05 16:45:57 -0700605 .WillOnce([&](const renderengine::DisplaySettings& displaySettings,
Sally Qi59a9f502021-10-12 18:53:23 +0000606 const std::vector<renderengine::LayerSettings>& layerSettings,
Sally Qi4cabdd02021-08-05 16:45:57 -0700607 const std::shared_ptr<renderengine::ExternalTexture>&, const bool,
Sally Qi59a9f502021-10-12 18:53:23 +0000608 base::unique_fd&&) -> std::future<renderengine::RenderEngineResult> {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000609 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
610 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
611 displaySettings.physicalDisplay);
612 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
613 displaySettings.clip);
614 // screen capture adds an additional color layer as an alpha
615 // prefill, so gtet the back layer.
Sally Qi4cabdd02021-08-05 16:45:57 -0700616 std::future<renderengine::RenderEngineResult> resultFuture =
617 futureOf<renderengine::RenderEngineResult>(
618 {NO_ERROR, base::unique_fd()});
Lloyd Piquea2468662019-03-07 21:31:06 -0800619 if (layerSettings.empty()) {
620 ADD_FAILURE() << "layerSettings was not expected to be empty in "
621 "setupREBufferCompositionCommonCallExpectations "
622 "verification lambda";
Sally Qi4cabdd02021-08-05 16:45:57 -0700623 return resultFuture;
Lloyd Piquea2468662019-03-07 21:31:06 -0800624 }
Sally Qi59a9f502021-10-12 18:53:23 +0000625 const renderengine::LayerSettings layer = layerSettings.back();
626 EXPECT_THAT(layer.source.buffer.buffer, Not(IsNull()));
627 EXPECT_THAT(layer.source.buffer.fence, Not(IsNull()));
628 EXPECT_EQ(DEFAULT_TEXTURE_ID, layer.source.buffer.textureName);
629 EXPECT_EQ(false, layer.source.buffer.isY410BT2020);
630 EXPECT_EQ(true, layer.source.buffer.usePremultipliedAlpha);
631 EXPECT_EQ(false, layer.source.buffer.isOpaque);
Vishnu Nair50c0afe2022-07-11 15:04:07 -0700632 EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius.x);
633 EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius.y);
Sally Qi59a9f502021-10-12 18:53:23 +0000634 EXPECT_EQ(ui::Dataspace::UNKNOWN, layer.sourceDataspace);
635 EXPECT_EQ(LayerProperties::COLOR[3], layer.alpha);
Sally Qi4cabdd02021-08-05 16:45:57 -0700636 return resultFuture;
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000637 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700638 }
639
640 static void setupREBufferCompositionCallExpectations(CompositionTest* test) {
641 LayerProperties::setupREBufferCompositionCommonCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700642 }
643
644 static void setupInsecureREBufferCompositionCallExpectations(CompositionTest* test) {
645 setupREBufferCompositionCallExpectations(test);
646 }
647
648 static void setupREBufferScreenshotCompositionCallExpectations(CompositionTest* test) {
649 LayerProperties::setupREBufferCompositionCommonCallExpectations(test);
650 }
651
652 static void setupInsecureREBufferScreenshotCompositionCallExpectations(CompositionTest* test) {
653 LayerProperties::setupREBufferCompositionCommonCallExpectations(test);
654 }
655
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700656 static void setupREColorCompositionCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000657 EXPECT_CALL(*test->mRenderEngine, drawLayers)
Sally Qi4cabdd02021-08-05 16:45:57 -0700658 .WillOnce([&](const renderengine::DisplaySettings& displaySettings,
Sally Qi59a9f502021-10-12 18:53:23 +0000659 const std::vector<renderengine::LayerSettings>& layerSettings,
Sally Qi4cabdd02021-08-05 16:45:57 -0700660 const std::shared_ptr<renderengine::ExternalTexture>&, const bool,
Sally Qi59a9f502021-10-12 18:53:23 +0000661 base::unique_fd&&) -> std::future<renderengine::RenderEngineResult> {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000662 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
663 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
664 displaySettings.physicalDisplay);
665 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
666 displaySettings.clip);
667 // screen capture adds an additional color layer as an alpha
668 // prefill, so get the back layer.
Sally Qi4cabdd02021-08-05 16:45:57 -0700669 std::future<renderengine::RenderEngineResult> resultFuture =
670 futureOf<renderengine::RenderEngineResult>(
671 {NO_ERROR, base::unique_fd()});
Lloyd Piquea2468662019-03-07 21:31:06 -0800672 if (layerSettings.empty()) {
673 ADD_FAILURE()
674 << "layerSettings was not expected to be empty in "
675 "setupREColorCompositionCallExpectations verification lambda";
Sally Qi4cabdd02021-08-05 16:45:57 -0700676 return resultFuture;
Lloyd Piquea2468662019-03-07 21:31:06 -0800677 }
Sally Qi59a9f502021-10-12 18:53:23 +0000678 const renderengine::LayerSettings layer = layerSettings.back();
679 EXPECT_THAT(layer.source.buffer.buffer, IsNull());
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000680 EXPECT_EQ(half3(LayerProperties::COLOR[0], LayerProperties::COLOR[1],
681 LayerProperties::COLOR[2]),
Sally Qi59a9f502021-10-12 18:53:23 +0000682 layer.source.solidColor);
Vishnu Nair50c0afe2022-07-11 15:04:07 -0700683 EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius.x);
684 EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius.y);
Sally Qi59a9f502021-10-12 18:53:23 +0000685 EXPECT_EQ(ui::Dataspace::UNKNOWN, layer.sourceDataspace);
686 EXPECT_EQ(LayerProperties::COLOR[3], layer.alpha);
Sally Qi4cabdd02021-08-05 16:45:57 -0700687 return resultFuture;
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000688 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700689 }
690
691 static void setupREColorScreenshotCompositionCallExpectations(CompositionTest* test) {
692 setupREColorCompositionCallExpectations(test);
693 }
694};
695
696struct DefaultLayerProperties : public BaseLayerProperties<DefaultLayerProperties> {};
697
Vishnu Nairfa247b12020-02-11 08:58:26 -0800698struct EffectLayerProperties : public BaseLayerProperties<EffectLayerProperties> {
Alec Mourida8a9d12020-01-30 20:00:31 -0800699 static constexpr IComposerClient::BlendMode BLENDMODE = IComposerClient::BlendMode::NONE;
700};
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700701
702struct SidebandLayerProperties : public BaseLayerProperties<SidebandLayerProperties> {
703 using Base = BaseLayerProperties<SidebandLayerProperties>;
704 static constexpr IComposerClient::BlendMode BLENDMODE = IComposerClient::BlendMode::NONE;
705
Vishnu Nairf8a873a2022-06-15 17:34:34 +0000706 static void setupLayerState(CompositionTest* test, sp<BufferStateLayer> layer) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700707 sp<NativeHandle> stream =
708 NativeHandle::create(reinterpret_cast<native_handle_t*>(DEFAULT_SIDEBAND_STREAM),
709 false);
710 test->mFlinger.setLayerSidebandStream(layer, stream);
711 }
712
713 static void setupHwcSetSourceCropBufferCallExpectations(CompositionTest* test) {
714 EXPECT_CALL(*test->mComposer,
715 setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER,
716 IComposerClient::FRect({0.f, 0.f, -1.f, -1.f})))
717 .Times(1);
718 }
719
720 static void setupHwcSetPerFrameBufferCallExpectations(CompositionTest* test) {
721 EXPECT_CALL(*test->mComposer,
722 setLayerSidebandStream(HWC_DISPLAY, HWC_LAYER,
723 reinterpret_cast<native_handle_t*>(
724 DEFAULT_SIDEBAND_STREAM)))
725 .WillOnce(Return(Error::NONE));
726
727 EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _)).Times(1);
728 }
729
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000730 static void setupREBufferCompositionCommonCallExpectations(CompositionTest* /*test*/) {}
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700731};
732
Garfield Tande619fa2020-10-02 17:13:53 -0700733template <typename LayerProperties>
734struct CommonSecureLayerProperties : public BaseLayerProperties<LayerProperties> {
735 using Base = BaseLayerProperties<LayerProperties>;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700736
737 static void setupInsecureREBufferCompositionCommonCallExpectations(CompositionTest* test) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000738 EXPECT_CALL(*test->mRenderEngine, drawLayers)
Sally Qi4cabdd02021-08-05 16:45:57 -0700739 .WillOnce([&](const renderengine::DisplaySettings& displaySettings,
Sally Qi59a9f502021-10-12 18:53:23 +0000740 const std::vector<renderengine::LayerSettings>& layerSettings,
Sally Qi4cabdd02021-08-05 16:45:57 -0700741 const std::shared_ptr<renderengine::ExternalTexture>&, const bool,
Sally Qi59a9f502021-10-12 18:53:23 +0000742 base::unique_fd&&) -> std::future<renderengine::RenderEngineResult> {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000743 EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance);
744 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
745 displaySettings.physicalDisplay);
746 EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
747 displaySettings.clip);
748 // screen capture adds an additional color layer as an alpha
749 // prefill, so get the back layer.
Sally Qi4cabdd02021-08-05 16:45:57 -0700750 std::future<renderengine::RenderEngineResult> resultFuture =
751 futureOf<renderengine::RenderEngineResult>(
752 {NO_ERROR, base::unique_fd()});
Lloyd Piquea2468662019-03-07 21:31:06 -0800753 if (layerSettings.empty()) {
754 ADD_FAILURE() << "layerSettings was not expected to be empty in "
755 "setupInsecureREBufferCompositionCommonCallExpectations "
756 "verification lambda";
Sally Qi4cabdd02021-08-05 16:45:57 -0700757 return resultFuture;
Lloyd Piquea2468662019-03-07 21:31:06 -0800758 }
Sally Qi59a9f502021-10-12 18:53:23 +0000759 const renderengine::LayerSettings layer = layerSettings.back();
760 EXPECT_THAT(layer.source.buffer.buffer, IsNull());
761 EXPECT_EQ(half3(0.0f, 0.0f, 0.0f), layer.source.solidColor);
Vishnu Nair50c0afe2022-07-11 15:04:07 -0700762 EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius.x);
763 EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius.y);
Sally Qi59a9f502021-10-12 18:53:23 +0000764 EXPECT_EQ(ui::Dataspace::UNKNOWN, layer.sourceDataspace);
765 EXPECT_EQ(1.0f, layer.alpha);
Sally Qi4cabdd02021-08-05 16:45:57 -0700766 return resultFuture;
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000767 });
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700768 }
769
770 static void setupInsecureREBufferCompositionCallExpectations(CompositionTest* test) {
771 setupInsecureREBufferCompositionCommonCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700772 }
773
774 static void setupInsecureREBufferScreenshotCompositionCallExpectations(CompositionTest* test) {
775 setupInsecureREBufferCompositionCommonCallExpectations(test);
776 }
777};
778
Garfield Tande619fa2020-10-02 17:13:53 -0700779struct ParentSecureLayerProperties
780 : public CommonSecureLayerProperties<ParentSecureLayerProperties> {};
781
782struct SecureLayerProperties : public CommonSecureLayerProperties<SecureLayerProperties> {
783 static constexpr uint32_t LAYER_FLAGS = ISurfaceComposerClient::eSecure;
784};
785
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700786struct CursorLayerProperties : public BaseLayerProperties<CursorLayerProperties> {
787 using Base = BaseLayerProperties<CursorLayerProperties>;
788
Vishnu Nairf8a873a2022-06-15 17:34:34 +0000789 static void setupLayerState(CompositionTest* test, sp<BufferStateLayer> layer) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700790 Base::setupLayerState(test, layer);
791 test->mFlinger.setLayerPotentialCursor(layer, true);
792 }
793};
794
795struct NoLayerVariant {
Vishnu Nairf8a873a2022-06-15 17:34:34 +0000796 using FlingerLayerType = sp<BufferStateLayer>;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700797
798 static FlingerLayerType createLayer(CompositionTest*) { return FlingerLayerType(); }
799 static void injectLayer(CompositionTest*, FlingerLayerType) {}
800 static void cleanupInjectedLayers(CompositionTest*) {}
801
802 static void setupCallExpectationsForDirtyGeometry(CompositionTest*) {}
803 static void setupCallExpectationsForDirtyFrame(CompositionTest*) {}
804};
805
806template <typename LayerProperties>
807struct BaseLayerVariant {
808 template <typename L, typename F>
809 static sp<L> createLayerWithFactory(CompositionTest* test, F factory) {
Dominik Laskowski756b7892021-08-04 12:53:59 -0700810 EXPECT_CALL(*test->mFlinger.scheduler(), postMessage(_)).Times(0);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700811
812 sp<L> layer = factory();
813
Dominik Laskowski49cea512019-11-12 14:13:23 -0800814 // Layer should be registered with scheduler.
Dominik Laskowski9c93d602021-10-07 19:38:26 -0700815 EXPECT_EQ(1u, test->mFlinger.scheduler()->layerHistorySize());
Dominik Laskowski49cea512019-11-12 14:13:23 -0800816
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700817 Mock::VerifyAndClear(test->mComposer);
818 Mock::VerifyAndClear(test->mRenderEngine);
Dominik Laskowski756b7892021-08-04 12:53:59 -0700819 Mock::VerifyAndClearExpectations(test->mFlinger.scheduler());
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700820
Garfield Tande619fa2020-10-02 17:13:53 -0700821 initLayerDrawingStateAndComputeBounds(test, layer);
822
823 return layer;
824 }
825
826 template <typename L>
827 static void initLayerDrawingStateAndComputeBounds(CompositionTest* test, sp<L> layer) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700828 auto& layerDrawingState = test->mFlinger.mutableLayerDrawingState(layer);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700829 layerDrawingState.layerStack = LAYER_STACK;
chaviw766c9c52021-02-10 17:36:47 -0800830 layerDrawingState.width = 100;
831 layerDrawingState.height = 100;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700832 layerDrawingState.color = half4(LayerProperties::COLOR[0], LayerProperties::COLOR[1],
833 LayerProperties::COLOR[2], LayerProperties::COLOR[3]);
Vishnu Nairc97b8db2019-10-29 18:19:35 -0700834 layer->computeBounds(FloatRect(0, 0, 100, 100), ui::Transform(), 0.f /* shadowRadius */);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700835 }
836
837 static void injectLayer(CompositionTest* test, sp<Layer> layer) {
838 EXPECT_CALL(*test->mComposer, createLayer(HWC_DISPLAY, _))
839 .WillOnce(DoAll(SetArgPointee<1>(HWC_LAYER), Return(Error::NONE)));
840
Lloyd Piquede196652020-01-22 17:29:58 -0800841 auto outputLayer = test->mDisplay->getCompositionDisplay()->injectOutputLayerForTest(
842 layer->getCompositionEngineLayerFE());
Lloyd Pique01c77c12019-04-17 12:48:32 -0700843 outputLayer->editState().visibleRegion = Region(Rect(0, 0, 100, 100));
844 outputLayer->editState().outputSpaceVisibleRegion = Region(Rect(0, 0, 100, 100));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700845
846 Mock::VerifyAndClear(test->mComposer);
847
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700848 test->mFlinger.mutableDrawingState().layersSortedByZ.add(layer);
849 }
850
851 static void cleanupInjectedLayers(CompositionTest* test) {
852 EXPECT_CALL(*test->mComposer, destroyLayer(HWC_DISPLAY, HWC_LAYER))
853 .WillOnce(Return(Error::NONE));
Lloyd Pique37c2c9b2018-12-04 17:25:10 -0800854
Lloyd Pique01c77c12019-04-17 12:48:32 -0700855 test->mDisplay->getCompositionDisplay()->clearOutputLayers();
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700856 test->mFlinger.mutableDrawingState().layersSortedByZ.clear();
Dominik Laskowski49cea512019-11-12 14:13:23 -0800857
858 // Layer should be unregistered with scheduler.
Dominik Laskowskie0e0cde2021-07-30 10:42:05 -0700859 test->mFlinger.commit();
Dominik Laskowski9c93d602021-10-07 19:38:26 -0700860 EXPECT_EQ(0u, test->mFlinger.scheduler()->layerHistorySize());
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700861 }
862};
863
864template <typename LayerProperties>
Vishnu Nairfa247b12020-02-11 08:58:26 -0800865struct EffectLayerVariant : public BaseLayerVariant<LayerProperties> {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700866 using Base = BaseLayerVariant<LayerProperties>;
Vishnu Nairfa247b12020-02-11 08:58:26 -0800867 using FlingerLayerType = sp<EffectLayer>;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700868
869 static FlingerLayerType createLayer(CompositionTest* test) {
Vishnu Nairfa247b12020-02-11 08:58:26 -0800870 FlingerLayerType layer = Base::template createLayerWithFactory<EffectLayer>(test, [test]() {
871 return new EffectLayer(
Dominik Laskowski8b01cc02020-07-14 19:02:41 -0700872 LayerCreationArgs(test->mFlinger.flinger(), sp<Client>(), "test-layer",
Vishnu Nairfa247b12020-02-11 08:58:26 -0800873 LayerProperties::LAYER_FLAGS, LayerMetadata()));
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700874 });
Vishnu Nair60356342018-11-13 13:00:45 -0800875
876 auto& layerDrawingState = test->mFlinger.mutableLayerDrawingState(layer);
chaviw25714502021-02-11 10:01:08 -0800877 layerDrawingState.crop = Rect(0, 0, LayerProperties::HEIGHT, LayerProperties::WIDTH);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700878 return layer;
879 }
880
881 static void setupRECompositionCallExpectations(CompositionTest* test) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700882 LayerProperties::setupREColorCompositionCallExpectations(test);
883 }
884
885 static void setupREScreenshotCompositionCallExpectations(CompositionTest* test) {
886 LayerProperties::setupREColorScreenshotCompositionCallExpectations(test);
887 }
888
889 static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) {
890 LayerProperties::setupHwcSetGeometryCallExpectations(test);
891 LayerProperties::setupHwcSetSourceCropColorCallExpectations(test);
892 }
893
894 static void setupCallExpectationsForDirtyFrame(CompositionTest* test) {
895 LayerProperties::setupHwcSetPerFrameCallExpectations(test);
896 LayerProperties::setupHwcSetPerFrameColorCallExpectations(test);
897 }
898};
899
900template <typename LayerProperties>
901struct BufferLayerVariant : public BaseLayerVariant<LayerProperties> {
902 using Base = BaseLayerVariant<LayerProperties>;
Vishnu Nairf8a873a2022-06-15 17:34:34 +0000903 using FlingerLayerType = sp<BufferStateLayer>;
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700904
905 static FlingerLayerType createLayer(CompositionTest* test) {
906 test->mFlinger.mutableTexturePool().push_back(DEFAULT_TEXTURE_ID);
907
908 FlingerLayerType layer =
Vishnu Nairf8a873a2022-06-15 17:34:34 +0000909 Base::template createLayerWithFactory<BufferStateLayer>(test, [test]() {
Dominik Laskowski8b01cc02020-07-14 19:02:41 -0700910 LayerCreationArgs args(test->mFlinger.flinger(), sp<Client>(), "test-layer",
Dominik Laskowski87a07e42019-10-10 20:38:02 -0700911 LayerProperties::LAYER_FLAGS, LayerMetadata());
chaviwb4c6e582019-08-16 14:35:07 -0700912 args.textureName = test->mFlinger.mutableTexturePool().back();
Vishnu Nairf8a873a2022-06-15 17:34:34 +0000913 return new BufferStateLayer(args);
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700914 });
915
916 LayerProperties::setupLayerState(test, layer);
917
918 return layer;
919 }
920
921 static void cleanupInjectedLayers(CompositionTest* test) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700922 Base::cleanupInjectedLayers(test);
923 }
924
925 static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) {
926 LayerProperties::setupHwcSetGeometryCallExpectations(test);
927 LayerProperties::setupHwcSetSourceCropBufferCallExpectations(test);
928 }
929
930 static void setupCallExpectationsForDirtyFrame(CompositionTest* test) {
931 LayerProperties::setupHwcSetPerFrameCallExpectations(test);
932 LayerProperties::setupHwcSetPerFrameBufferCallExpectations(test);
933 }
934
935 static void setupRECompositionCallExpectations(CompositionTest* test) {
936 LayerProperties::setupREBufferCompositionCallExpectations(test);
937 }
938
939 static void setupInsecureRECompositionCallExpectations(CompositionTest* test) {
940 LayerProperties::setupInsecureREBufferCompositionCallExpectations(test);
941 }
942
943 static void setupREScreenshotCompositionCallExpectations(CompositionTest* test) {
944 LayerProperties::setupREBufferScreenshotCompositionCallExpectations(test);
945 }
946
947 static void setupInsecureREScreenshotCompositionCallExpectations(CompositionTest* test) {
948 LayerProperties::setupInsecureREBufferScreenshotCompositionCallExpectations(test);
949 }
950};
951
Garfield Tande619fa2020-10-02 17:13:53 -0700952template <typename LayerProperties>
953struct ContainerLayerVariant : public BaseLayerVariant<LayerProperties> {
954 using Base = BaseLayerVariant<LayerProperties>;
955 using FlingerLayerType = sp<ContainerLayer>;
956
957 static FlingerLayerType createLayer(CompositionTest* test) {
958 LayerCreationArgs args(test->mFlinger.flinger(), sp<Client>(), "test-container-layer",
Garfield Tande619fa2020-10-02 17:13:53 -0700959 LayerProperties::LAYER_FLAGS, LayerMetadata());
960 FlingerLayerType layer = new ContainerLayer(args);
961 Base::template initLayerDrawingStateAndComputeBounds(test, layer);
962 return layer;
963 }
964};
965
966template <typename LayerVariant, typename ParentLayerVariant>
967struct ChildLayerVariant : public LayerVariant {
968 using Base = LayerVariant;
969 using FlingerLayerType = typename LayerVariant::FlingerLayerType;
970 using ParentBase = ParentLayerVariant;
971
972 static FlingerLayerType createLayer(CompositionTest* test) {
973 // Need to create child layer first. Otherwise layer history size will be 2.
974 FlingerLayerType layer = Base::createLayer(test);
975
976 typename ParentBase::FlingerLayerType parentLayer = ParentBase::createLayer(test);
977 parentLayer->addChild(layer);
978 test->mFlinger.setLayerDrawingParent(layer, parentLayer);
979
980 test->mAuxiliaryLayers.push_back(parentLayer);
981
982 return layer;
983 }
984
985 static void cleanupInjectedLayers(CompositionTest* test) {
986 // Clear auxiliary layers first so that child layer can be successfully destroyed in the
987 // following call.
988 test->mAuxiliaryLayers.clear();
989
990 Base::cleanupInjectedLayers(test);
991 }
992};
993
Lloyd Piqued6b579f2018-04-06 15:29:10 -0700994/* ------------------------------------------------------------------------
995 * Variants to control how the composition type is changed
996 */
997
998struct NoCompositionTypeVariant {
999 static void setupHwcSetCallExpectations(CompositionTest*) {}
1000
1001 static void setupHwcGetCallExpectations(CompositionTest* test) {
1002 EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _)).Times(1);
1003 }
1004};
1005
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001006template <aidl::android::hardware::graphics::composer3::Composition CompositionType>
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001007struct KeepCompositionTypeVariant {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001008 static constexpr aidl::android::hardware::graphics::composer3::Composition TYPE =
1009 CompositionType;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001010
1011 static void setupHwcSetCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001012 if (!test->mDisplayOff) {
1013 EXPECT_CALL(*test->mComposer,
1014 setLayerCompositionType(HWC_DISPLAY, HWC_LAYER, CompositionType))
1015 .Times(1);
1016 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001017 }
1018
1019 static void setupHwcGetCallExpectations(CompositionTest* test) {
1020 EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _)).Times(1);
1021 }
1022};
1023
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001024template <aidl::android::hardware::graphics::composer3::Composition InitialCompositionType,
1025 aidl::android::hardware::graphics::composer3::Composition FinalCompositionType>
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001026struct ChangeCompositionTypeVariant {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001027 static constexpr aidl::android::hardware::graphics::composer3::Composition TYPE =
1028 FinalCompositionType;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001029
1030 static void setupHwcSetCallExpectations(CompositionTest* test) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001031 if (!test->mDisplayOff) {
1032 EXPECT_CALL(*test->mComposer,
1033 setLayerCompositionType(HWC_DISPLAY, HWC_LAYER, InitialCompositionType))
1034 .Times(1);
1035 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001036 }
1037
1038 static void setupHwcGetCallExpectations(CompositionTest* test) {
1039 EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _))
1040 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::Layer>{
1041 static_cast<Hwc2::Layer>(HWC_LAYER)}),
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001042 SetArgPointee<2>(
1043 std::vector<aidl::android::hardware::graphics::composer3::
1044 Composition>{FinalCompositionType}),
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001045 Return(Error::NONE)));
1046 }
1047};
1048
1049/* ------------------------------------------------------------------------
1050 * Variants to select how the composition is expected to be handled
1051 */
1052
1053struct CompositionResultBaseVariant {
1054 static void setupLayerState(CompositionTest*, sp<Layer>) {}
1055
1056 template <typename Case>
1057 static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) {
1058 Case::Layer::setupCallExpectationsForDirtyGeometry(test);
1059 }
1060
1061 template <typename Case>
1062 static void setupCallExpectationsForDirtyFrame(CompositionTest* test) {
1063 Case::Layer::setupCallExpectationsForDirtyFrame(test);
1064 }
1065};
1066
1067struct NoCompositionResultVariant : public CompositionResultBaseVariant {
1068 template <typename Case>
1069 static void setupCallExpectations(CompositionTest* test) {
1070 Case::Display::setupEmptyFrameCompositionCallExpectations(test);
1071 Case::Display::setupHwcCompositionCallExpectations(test);
1072 }
1073};
1074
1075struct HwcCompositionResultVariant : public CompositionResultBaseVariant {
1076 template <typename Case>
1077 static void setupCallExpectations(CompositionTest* test) {
1078 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
1079 Case::Display::setupHwcCompositionCallExpectations(test);
1080 }
1081};
1082
1083struct RECompositionResultVariant : public CompositionResultBaseVariant {
1084 template <typename Case>
1085 static void setupCallExpectations(CompositionTest* test) {
1086 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
Lloyd Pique66d68602019-02-13 14:23:31 -08001087 Case::Display::setupHwcClientCompositionCallExpectations(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001088 Case::Display::setupRECompositionCallExpectations(test);
1089 Case::Display::template setupRELayerCompositionCallExpectations<Case>(test);
1090 }
1091};
1092
Lloyd Pique66d68602019-02-13 14:23:31 -08001093struct ForcedClientCompositionResultVariant : public CompositionResultBaseVariant {
Lloyd Pique37c2c9b2018-12-04 17:25:10 -08001094 static void setupLayerState(CompositionTest* test, sp<Layer> layer) {
Dominik Laskowskib7251f42020-04-20 17:42:59 -07001095 const auto outputLayer =
1096 TestableSurfaceFlinger::findOutputLayerForDisplay(layer, test->mDisplay);
Lloyd Piquef5275482019-01-29 18:42:42 -08001097 LOG_FATAL_IF(!outputLayer);
1098 outputLayer->editState().forceClientComposition = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001099 }
1100
1101 template <typename Case>
Lloyd Pique66d68602019-02-13 14:23:31 -08001102 static void setupCallExpectations(CompositionTest* test) {
1103 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
1104 Case::Display::setupHwcForcedClientCompositionCallExpectations(test);
1105 Case::Display::setupRECompositionCallExpectations(test);
1106 Case::Display::template setupRELayerCompositionCallExpectations<Case>(test);
1107 }
1108
1109 template <typename Case>
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001110 static void setupCallExpectationsForDirtyGeometry(CompositionTest*) {}
1111
1112 template <typename Case>
1113 static void setupCallExpectationsForDirtyFrame(CompositionTest*) {}
1114};
1115
Lloyd Pique4fe29402019-08-12 16:51:24 -07001116struct ForcedClientCompositionViaDebugOptionResultVariant : public CompositionResultBaseVariant {
1117 static void setupLayerState(CompositionTest* test, sp<Layer>) {
1118 test->mFlinger.mutableDebugDisableHWC() = true;
1119 }
1120
1121 template <typename Case>
1122 static void setupCallExpectations(CompositionTest* test) {
1123 Case::Display::setupNonEmptyFrameCompositionCallExpectations(test);
1124 Case::Display::setupHwcForcedClientCompositionCallExpectations(test);
1125 Case::Display::setupRECompositionCallExpectations(test);
1126 Case::Display::template setupRELayerCompositionCallExpectations<Case>(test);
1127 }
1128
1129 template <typename Case>
1130 static void setupCallExpectationsForDirtyGeometry(CompositionTest*) {}
1131
1132 template <typename Case>
1133 static void setupCallExpectationsForDirtyFrame(CompositionTest*) {}
1134};
1135
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001136struct EmptyScreenshotResultVariant {
1137 static void setupLayerState(CompositionTest*, sp<Layer>) {}
1138
1139 template <typename Case>
1140 static void setupCallExpectations(CompositionTest*) {}
1141};
1142
1143struct REScreenshotResultVariant : public EmptyScreenshotResultVariant {
1144 using Base = EmptyScreenshotResultVariant;
1145
1146 template <typename Case>
1147 static void setupCallExpectations(CompositionTest* test) {
1148 Base::template setupCallExpectations<Case>(test);
1149 Case::Display::template setupRELayerScreenshotCompositionCallExpectations<Case>(test);
1150 }
1151};
1152
1153/* ------------------------------------------------------------------------
1154 * Composition test case, containing all the variants being tested
1155 */
1156
1157template <typename DisplayCase, typename LayerCase, typename CompositionTypeCase,
1158 typename CompositionResultCase>
1159struct CompositionCase {
1160 using ThisCase =
1161 CompositionCase<DisplayCase, LayerCase, CompositionTypeCase, CompositionResultCase>;
1162 using Display = DisplayCase;
1163 using Layer = LayerCase;
1164 using CompositionType = CompositionTypeCase;
1165 using CompositionResult = CompositionResultCase;
1166
1167 static void setupCommon(CompositionTest* test) {
Peiyong Lin1336e6e2019-05-28 09:23:50 -07001168 Display::template setupPreconditionCallExpectations<ThisCase>(test);
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001169 Display::setupPreconditions(test);
1170
1171 auto layer = Layer::createLayer(test);
1172 Layer::injectLayer(test, layer);
1173 CompositionResult::setupLayerState(test, layer);
1174 }
1175
1176 static void setupForDirtyGeometry(CompositionTest* test) {
1177 setupCommon(test);
1178
1179 Display::template setupCommonCompositionCallExpectations<ThisCase>(test);
1180 CompositionResult::template setupCallExpectationsForDirtyGeometry<ThisCase>(test);
1181 CompositionResult::template setupCallExpectationsForDirtyFrame<ThisCase>(test);
1182 CompositionResult::template setupCallExpectations<ThisCase>(test);
1183 }
1184
1185 static void setupForDirtyFrame(CompositionTest* test) {
1186 setupCommon(test);
1187
1188 Display::template setupCommonCompositionCallExpectations<ThisCase>(test);
1189 CompositionResult::template setupCallExpectationsForDirtyFrame<ThisCase>(test);
1190 CompositionResult::template setupCallExpectations<ThisCase>(test);
1191 }
1192
1193 static void setupForScreenCapture(CompositionTest* test) {
1194 setupCommon(test);
1195
1196 Display::template setupCommonScreensCaptureCallExpectations<ThisCase>(test);
1197 CompositionResult::template setupCallExpectations<ThisCase>(test);
1198 }
1199
1200 static void cleanup(CompositionTest* test) {
1201 Layer::cleanupInjectedLayers(test);
1202
Peiyong Linbdd08cc2019-12-17 21:35:14 -08001203 for (auto& displayData : test->mFlinger.mutableHwcDisplayData()) {
1204 static_cast<TestableSurfaceFlinger::HWC2Display*>(displayData.second.hwcDisplay.get())
1205 ->mutableLayers()
1206 .clear();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001207 }
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001208 }
1209};
1210
1211/* ------------------------------------------------------------------------
1212 * Composition cases to test
1213 */
1214
1215TEST_F(CompositionTest, noLayersDoesMinimalWorkWithDirtyGeometry) {
1216 displayRefreshCompositionDirtyGeometry<
1217 CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant,
1218 NoCompositionResultVariant>>();
1219}
1220
1221TEST_F(CompositionTest, noLayersDoesMinimalWorkWithDirtyFrame) {
1222 displayRefreshCompositionDirtyFrame<
1223 CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant,
1224 NoCompositionResultVariant>>();
1225}
1226
1227TEST_F(CompositionTest, noLayersDoesMinimalWorkToCaptureScreen) {
1228 captureScreenComposition<
1229 CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant,
1230 EmptyScreenshotResultVariant>>();
1231}
1232
1233/* ------------------------------------------------------------------------
1234 * Simple buffer layers
1235 */
1236
1237TEST_F(CompositionTest, HWCComposedNormalBufferLayerWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001238 displayRefreshCompositionDirtyGeometry<CompositionCase<
1239 DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1240 KeepCompositionTypeVariant<
1241 aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
1242 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001243}
1244
1245TEST_F(CompositionTest, HWCComposedNormalBufferLayerWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001246 displayRefreshCompositionDirtyFrame<CompositionCase<
1247 DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1248 KeepCompositionTypeVariant<
1249 aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
1250 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001251}
1252
1253TEST_F(CompositionTest, REComposedNormalBufferLayer) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001254 displayRefreshCompositionDirtyFrame<CompositionCase<
1255 DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1256 ChangeCompositionTypeVariant<
1257 aidl::android::hardware::graphics::composer3::Composition::DEVICE,
1258 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1259 RECompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001260}
1261
1262TEST_F(CompositionTest, captureScreenNormalBufferLayer) {
1263 captureScreenComposition<
1264 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1265 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1266}
1267
1268/* ------------------------------------------------------------------------
1269 * Single-color layers
1270 */
1271
Vishnu Nairfa247b12020-02-11 08:58:26 -08001272TEST_F(CompositionTest, HWCComposedEffectLayerWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001273 displayRefreshCompositionDirtyGeometry<CompositionCase<
1274 DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
1275 KeepCompositionTypeVariant<
1276 aidl::android::hardware::graphics::composer3::Composition::SOLID_COLOR>,
1277 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001278}
1279
Vishnu Nairfa247b12020-02-11 08:58:26 -08001280TEST_F(CompositionTest, HWCComposedEffectLayerWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001281 displayRefreshCompositionDirtyFrame<CompositionCase<
1282 DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
1283 KeepCompositionTypeVariant<
1284 aidl::android::hardware::graphics::composer3::Composition::SOLID_COLOR>,
1285 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001286}
1287
Vishnu Nairfa247b12020-02-11 08:58:26 -08001288TEST_F(CompositionTest, REComposedEffectLayer) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001289 displayRefreshCompositionDirtyFrame<CompositionCase<
1290 DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
1291 ChangeCompositionTypeVariant<
1292 aidl::android::hardware::graphics::composer3::Composition::SOLID_COLOR,
1293 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1294 RECompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001295}
1296
Vishnu Nairfa247b12020-02-11 08:58:26 -08001297TEST_F(CompositionTest, captureScreenEffectLayer) {
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001298 captureScreenComposition<
Vishnu Nairfa247b12020-02-11 08:58:26 -08001299 CompositionCase<DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>,
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001300 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1301}
1302
1303/* ------------------------------------------------------------------------
1304 * Layers with sideband buffers
1305 */
1306
1307TEST_F(CompositionTest, HWCComposedSidebandBufferLayerWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001308 displayRefreshCompositionDirtyGeometry<CompositionCase<
1309 DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1310 KeepCompositionTypeVariant<
1311 aidl::android::hardware::graphics::composer3::Composition::SIDEBAND>,
1312 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001313}
1314
1315TEST_F(CompositionTest, HWCComposedSidebandBufferLayerWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001316 displayRefreshCompositionDirtyFrame<CompositionCase<
1317 DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1318 KeepCompositionTypeVariant<
1319 aidl::android::hardware::graphics::composer3::Composition::SIDEBAND>,
1320 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001321}
1322
1323TEST_F(CompositionTest, REComposedSidebandBufferLayer) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001324 displayRefreshCompositionDirtyFrame<CompositionCase<
1325 DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1326 ChangeCompositionTypeVariant<
1327 aidl::android::hardware::graphics::composer3::Composition::SIDEBAND,
1328 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1329 RECompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001330}
1331
1332TEST_F(CompositionTest, captureScreenSidebandBufferLayer) {
1333 captureScreenComposition<
1334 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>,
1335 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1336}
1337
1338/* ------------------------------------------------------------------------
1339 * Layers with ISurfaceComposerClient::eSecure, on a secure display
1340 */
1341
1342TEST_F(CompositionTest, HWCComposedSecureBufferLayerWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001343 displayRefreshCompositionDirtyGeometry<CompositionCase<
1344 DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1345 KeepCompositionTypeVariant<
1346 aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
1347 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001348}
1349
1350TEST_F(CompositionTest, HWCComposedSecureBufferLayerWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001351 displayRefreshCompositionDirtyFrame<CompositionCase<
1352 DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1353 KeepCompositionTypeVariant<
1354 aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
1355 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001356}
1357
1358TEST_F(CompositionTest, REComposedSecureBufferLayer) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001359 displayRefreshCompositionDirtyFrame<CompositionCase<
1360 DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1361 ChangeCompositionTypeVariant<
1362 aidl::android::hardware::graphics::composer3::Composition::DEVICE,
1363 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1364 RECompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001365}
1366
1367TEST_F(CompositionTest, captureScreenSecureBufferLayerOnSecureDisplay) {
1368 captureScreenComposition<
1369 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1370 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1371}
1372
1373/* ------------------------------------------------------------------------
1374 * Layers with ISurfaceComposerClient::eSecure, on a non-secure display
1375 */
1376
1377TEST_F(CompositionTest, HWCComposedSecureBufferLayerOnInsecureDisplayWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001378 displayRefreshCompositionDirtyGeometry<CompositionCase<
1379 InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1380 KeepCompositionTypeVariant<
1381 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1382 ForcedClientCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001383}
1384
1385TEST_F(CompositionTest, HWCComposedSecureBufferLayerOnInsecureDisplayWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001386 displayRefreshCompositionDirtyFrame<CompositionCase<
1387 InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1388 KeepCompositionTypeVariant<
1389 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1390 ForcedClientCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001391}
1392
1393TEST_F(CompositionTest, captureScreenSecureBufferLayerOnInsecureDisplay) {
1394 captureScreenComposition<
1395 CompositionCase<InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>,
1396 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1397}
1398
1399/* ------------------------------------------------------------------------
Garfield Tande619fa2020-10-02 17:13:53 -07001400 * Layers with a parent layer with ISurfaceComposerClient::eSecure, on a non-secure display
1401 */
1402
1403TEST_F(CompositionTest,
1404 HWCComposedBufferLayerWithSecureParentLayerOnInsecureDisplayWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001405 displayRefreshCompositionDirtyGeometry<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,
1415 HWCComposedBufferLayerWithSecureParentLayerOnInsecureDisplayWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001416 displayRefreshCompositionDirtyFrame<CompositionCase<
1417 InsecureDisplaySetupVariant,
1418 ChildLayerVariant<BufferLayerVariant<ParentSecureLayerProperties>,
1419 ContainerLayerVariant<SecureLayerProperties>>,
1420 KeepCompositionTypeVariant<
1421 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1422 ForcedClientCompositionResultVariant>>();
Garfield Tande619fa2020-10-02 17:13:53 -07001423}
1424
1425TEST_F(CompositionTest, captureScreenBufferLayerWithSecureParentLayerOnInsecureDisplay) {
1426 captureScreenComposition<
1427 CompositionCase<InsecureDisplaySetupVariant,
1428 ChildLayerVariant<BufferLayerVariant<ParentSecureLayerProperties>,
1429 ContainerLayerVariant<SecureLayerProperties>>,
1430 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1431}
1432
1433/* ------------------------------------------------------------------------
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001434 * Cursor layers
1435 */
1436
1437TEST_F(CompositionTest, HWCComposedCursorLayerWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001438 displayRefreshCompositionDirtyGeometry<CompositionCase<
1439 DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1440 KeepCompositionTypeVariant<
1441 aidl::android::hardware::graphics::composer3::Composition::CURSOR>,
1442 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001443}
1444
1445TEST_F(CompositionTest, HWCComposedCursorLayerWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001446 displayRefreshCompositionDirtyFrame<CompositionCase<
1447 DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1448 KeepCompositionTypeVariant<
1449 aidl::android::hardware::graphics::composer3::Composition::CURSOR>,
1450 HwcCompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001451}
1452
1453TEST_F(CompositionTest, REComposedCursorLayer) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001454 displayRefreshCompositionDirtyFrame<CompositionCase<
1455 DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1456 ChangeCompositionTypeVariant<
1457 aidl::android::hardware::graphics::composer3::Composition::CURSOR,
1458 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1459 RECompositionResultVariant>>();
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001460}
1461
1462TEST_F(CompositionTest, captureScreenCursorLayer) {
1463 captureScreenComposition<
1464 CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>,
1465 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1466}
1467
1468/* ------------------------------------------------------------------------
1469 * Simple buffer layer on a display which is powered off.
1470 */
1471
1472TEST_F(CompositionTest, displayOffHWCComposedNormalBufferLayerWithDirtyGeometry) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001473 mDisplayOff = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001474 displayRefreshCompositionDirtyGeometry<CompositionCase<
1475 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001476 KeepCompositionTypeVariant<
1477 aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001478 HwcCompositionResultVariant>>();
1479}
1480
1481TEST_F(CompositionTest, displayOffHWCComposedNormalBufferLayerWithDirtyFrame) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001482 mDisplayOff = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001483 displayRefreshCompositionDirtyFrame<CompositionCase<
1484 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001485 KeepCompositionTypeVariant<
1486 aidl::android::hardware::graphics::composer3::Composition::DEVICE>,
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001487 HwcCompositionResultVariant>>();
1488}
1489
1490TEST_F(CompositionTest, displayOffREComposedNormalBufferLayer) {
Alec Mourif9a2a2c2019-11-12 12:46:02 -08001491 mDisplayOff = true;
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001492 displayRefreshCompositionDirtyFrame<CompositionCase<
1493 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001494 ChangeCompositionTypeVariant<
1495 aidl::android::hardware::graphics::composer3::Composition::DEVICE,
1496 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001497 RECompositionResultVariant>>();
1498}
1499
1500TEST_F(CompositionTest, captureScreenNormalBufferLayerOnPoweredOffDisplay) {
1501 captureScreenComposition<CompositionCase<
1502 PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1503 NoCompositionTypeVariant, REScreenshotResultVariant>>();
1504}
1505
Lloyd Pique4fe29402019-08-12 16:51:24 -07001506/* ------------------------------------------------------------------------
1507 * Client composition forced through debug/developer settings
1508 */
1509
1510TEST_F(CompositionTest, DebugOptionForcingClientCompositionOfBufferLayerWithDirtyGeometry) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001511 displayRefreshCompositionDirtyGeometry<CompositionCase<
1512 DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1513 KeepCompositionTypeVariant<
1514 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1515 ForcedClientCompositionViaDebugOptionResultVariant>>();
Lloyd Pique4fe29402019-08-12 16:51:24 -07001516}
1517
1518TEST_F(CompositionTest, DebugOptionForcingClientCompositionOfBufferLayerWithDirtyFrame) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -05001519 displayRefreshCompositionDirtyFrame<CompositionCase<
1520 DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>,
1521 KeepCompositionTypeVariant<
1522 aidl::android::hardware::graphics::composer3::Composition::CLIENT>,
1523 ForcedClientCompositionViaDebugOptionResultVariant>>();
Lloyd Pique4fe29402019-08-12 16:51:24 -07001524}
1525
Lloyd Piqued6b579f2018-04-06 15:29:10 -07001526} // namespace
1527} // namespace android
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -08001528
1529// TODO(b/129481165): remove the #pragma below and fix conversion issues
Marin Shalamanovbed7fd32020-12-21 20:02:20 +01001530#pragma clang diagnostic pop // ignored "-Wconversion -Wextra"